{"componentChunkName":"component---src-templates-docs-js","path":"/docs/js-tips/import/","result":{"data":{"sitePage":{"id":"SitePage /docs/js-tips/import/"}},"pageContext":{"url":"/docs/js-tips/import/","relativePath":"docs/js-tips/import.md","relativeDir":"docs/js-tips","base":"import.md","name":"import","frontmatter":{"title":"import","weight":0,"excerpt":null,"seo":{"title":"import","description":"The static import statement is used to import read only live bindings which are exported by another module.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>import</h1>\n<p>The static <code class=\"language-text\">import</code> statement is used to import read only live bindings which are <a href=\"export\">exported</a> by another module.</p>\n<p>Imported modules are in <a href=\"../strict_mode\"><code class=\"language-text\">strict mode</code></a> whether you declare them as such or not. The <code class=\"language-text\">import</code> statement cannot be used in embedded scripts unless such script has a <code class=\"language-text\">type=\"module\"</code>. Bindings imported are called live bindings because they are updated by the module that exported the binding.</p>\n<p>There is also a function-like dynamic <code class=\"language-text\">import()</code>, which does not require scripts of <code class=\"language-text\">type=\"module\"</code>.</p>\n<p>Backward compatibility can be ensured using attribute <code class=\"language-text\">nomodule</code> on the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script\"><code class=\"language-text\">&lt;script></code></a> tag.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">import</span> defaultExport <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> name <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token keyword\">as</span> alias1 <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token punctuation\">,</span> export2 <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> foo <span class=\"token punctuation\">,</span> bar <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name/path/to/specific/un-exported/file\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token punctuation\">,</span> export2 <span class=\"token keyword\">as</span> alias2 <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> defaultExport<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token punctuation\">[</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> defaultExport<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> name <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">import</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">defaultExport</code>\nName that will refer to the default export from the module.</p>\n<p><code class=\"language-text\">module-name</code>\nThe module to import from. This is often a relative or absolute path name to the <code class=\"language-text\">.js</code> file containing the module. Certain bundlers may permit or require the use of the extension; check your environment. Only single quoted and double quoted Strings are allowed.</p>\n<p><code class=\"language-text\">name</code>\nName of the module object that will be used as a kind of namespace when referring to the imports.</p>\n<p><code class=\"language-text\">exportN</code>\nName of the exports to be imported.</p>\n<p><code class=\"language-text\">aliasN</code>\nNames that will refer to the named imports.</p>\n<h2>Description</h2>\n<p>The <code class=\"language-text\">name</code> parameter is the name of the \"module object\" which will be used as a kind of namespace to refer to the exports. The <code class=\"language-text\">export</code> parameters specify individual named exports, while the <code class=\"language-text\">import * as name</code> syntax imports all of them. Below are examples to clarify the syntax.</p>\n<h3>Import an entire module's contents</h3>\n<p>This inserts <code class=\"language-text\">myModule</code> into the current scope, containing all the exports from the module in the file located in <code class=\"language-text\">/modules/my-module.js</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import * as myModule from '/modules/my-module.js';</code></pre></div>\n<p>Here, accessing the exports means using the module name (\"myModule\" in this case) as a namespace. For example, if the module imported above includes an export <code class=\"language-text\">doAllTheAmazingThings()</code>, you would call it like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">myModule.doAllTheAmazingThings();</code></pre></div>\n<h3>Import a single export from a module</h3>\n<p>Given an object or value named <code class=\"language-text\">myExport</code> which has been exported from the module <code class=\"language-text\">my-module</code> either implicitly (because the entire module is exported, for example using <code class=\"language-text\">export * from 'another.js'</code>) or explicitly (using the <a href=\"export\"><code class=\"language-text\">export</code></a> statement), this inserts <code class=\"language-text\">myExport</code> into the current scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import {myExport} from '/modules/my-module.js';</code></pre></div>\n<h3>Import multiple exports from module</h3>\n<p>This inserts both <code class=\"language-text\">foo</code> and <code class=\"language-text\">bar</code> into the current scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import {foo, bar} from '/modules/my-module.js';</code></pre></div>\n<h3>Import an export with a more convenient alias</h3>\n<p>You can rename an export when importing it. For example, this inserts <code class=\"language-text\">shortName</code> into the current scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import {reallyReallyLongModuleExportName as shortName}\n  from '/modules/my-module.js';</code></pre></div>\n<h3>Rename multiple exports during import</h3>\n<p>Import multiple exports from a module with convenient aliases.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import {\n  reallyReallyLongModuleExportName as shortName,\n  anotherLongModuleName as short\n} from '/modules/my-module.js';</code></pre></div>\n<h3>Import a module for its side effects only</h3>\n<p>Import an entire module for side effects only, without importing anything. This runs the module's global code, but doesn't actually import any values.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import '/modules/my-module.js';</code></pre></div>\n<p>This works with <a href=\"#dynamic_imports\">dynamic imports</a> as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(async () => {\n  if (somethingIsTrue) {\n    // import module for side effects\n    await import('/modules/my-module.js');\n  }\n})();</code></pre></div>\n<p>If your project uses packages that export ESM, you can also import them for side effects only. This will run the code in the package entry point file (and any files it imports) only.</p>\n<h3>Importing defaults</h3>\n<p>It is possible to have a default <a href=\"export\"><code class=\"language-text\">export</code></a> (whether it is an object, a function, a class, etc.). The <code class=\"language-text\">import</code> statement may then be used to import such defaults.</p>\n<p>The simplest version directly imports the default:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import myDefault from '/modules/my-module.js';</code></pre></div>\n<p>It is also possible to use the default syntax with the ones seen above (namespace imports or named imports). In such cases, the default import will have to be declared first. For instance:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import myDefault, * as myModule from '/modules/my-module.js';\n// myModule used as a namespace</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import myDefault, {foo, bar} from '/modules/my-module.js';\n// specific, named imports</code></pre></div>\n<p>When importing a default export with <a href=\"#dynamic_imports\">dynamic imports</a>, it works a bit differently. You need to destructure and rename the \"default\" key from the returned object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(async () => {\n  if (somethingIsTrue) {\n    const { default: myDefault, foo, bar } = await import('/modules/my-module.js');\n  }\n})();</code></pre></div>\n<h3>Dynamic Imports</h3>\n<p>The standard import syntax is static and will always result in all code in the imported module being evaluated at load time. In situations where you wish to load a module conditionally or on demand, you can use a dynamic import instead. The following are some reasons why you might need to use dynamic import:</p>\n<ul>\n<li>When importing statically significantly slows the loading of your code and there is a low likelihood that you will need the code you are importing, or you will not need it until a later time.</li>\n<li>When importing statically significantly increases your program's memory usage and there is a low likelihood that you will need the code you are importing.</li>\n<li>When the module you are importing does not exist at load time</li>\n<li>When the import specifier string needs to be constructed dynamically. (Static import only supports static specifiers.)</li>\n<li>When the module being imported has side effects, and you do not want those side effects unless some condition is true. (It is recommended not to have any side effects in a module, but you sometimes cannot control this in your module dependencies.)</li>\n</ul>\n<p>Use dynamic import only when necessary. The static form is preferable for loading initial dependencies, and can benefit more readily from static analysis tools and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking\">tree shaking</a>.</p>\n<p>To dynamically import a module, the <code class=\"language-text\">import</code> keyword may be called as a function. When used this way, it returns a promise.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import('/modules/my-module.js')\n  .then((module) => {\n    // Do something with the module.\n  });</code></pre></div>\n<p>This form also supports the <code class=\"language-text\">await</code> keyword.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let module = await import('/modules/my-module.js');</code></pre></div>\n<h2>Examples</h2>\n<h3>Standard Import</h3>\n<p>The code below shows how to import from a secondary module to assist in processing an AJAX JSON request.</p>\n<h4>The module: file.js</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function getJSON(url, callback) {\n  let xhr = new XMLHttpRequest();\n  xhr.onload = function () {\n    callback(this.responseText)\n  };\n  xhr.open('GET', url, true);\n  xhr.send();\n}\n\nexport function getUsefulContents(url, callback) {\n  getJSON(url, data => callback(JSON.parse(data)));\n}</code></pre></div>\n<h4>The main program: main.js</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { getUsefulContents } from '/modules/file.js';\n\ngetUsefulContents('http://www.example.com',\n    data => { doSomethingUseful(data); });</code></pre></div>\n<h3>Dynamic Import</h3>\n<p>This example shows how to load functionality on to a page based on a user action, in this case a button click, and then call a function within that module. This is not the only way to implement this functionality. The <code class=\"language-text\">import()</code> function also supports <code class=\"language-text\">await</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const main = document.querySelector(\"main\");\nfor (const link of document.querySelectorAll(\"nav > a\")) {\n  link.addEventListener(\"click\", e => {\n    e.preventDefault();\n\n    import('/modules/my-module.js')\n      .then(module => {\n        module.loadPageInto(main);\n      })\n      .catch(err => {\n        main.textContent = err.message;\n      });\n  });\n}</code></pre></div>","pages":[{"url":"/","relativePath":"index.md","relativeDir":"","base":"index.md","name":"index","frontmatter":{"title":"Web Dev Hub Home","sections":[{"section_id":"Intro","type":"section_hero","title":"I am a musician, electrical engineer & web developer","image":"images/dtw-slideshow.gif","content":"\n\n**Please note that this website is in development and is often broken!**\n\n[![email](https://img.icons8.com/color/96/000000/gmail.png)](mailto:bryan.guner@gmail.com)[![facebook](https://img.icons8.com/color/96/000000/facebook.png)](https://www.facebook.com/bryan.guner/)[![twitter](https://img.icons8.com/color/96/000000/twitter-squared.png)](https://twitter.com/bgooonz)[![youtube](https://img.icons8.com/color/96/000000/youtube.png)](https://www.youtube.com/channel/UC9-rYyUMsnEBK8G8fCyrXXA/videos)[![instagram](https://img.icons8.com/color/96/000000/instagram-new.png)](https://www.instagram.com/bgoonz/?hl=en)[![pinterest](https://img.icons8.com/color/96/000000/pinterest--v1.png)](https://www.pinterest.com/bryanguner/_saved/)[![linkedin](https://img.icons8.com/color/96/000000/linkedin.png)](https://www.linkedin.com/in/bryan-guner-046199128/)\n\n[](https://webpack.js.org/)[ ](https://www.adobe.com/products/xd.html)\n\n[![NetlifyStatus](https://api.netlify.com/api/v1/badges/a1b7ee1a-11a7-4bd2-a341-2260656e216f/deploy-status)](https://app.netlify.com/sites/bgoonz-blog/deploys)\n\n![Jokes](https://readme-jokes.vercel.app/api)\n\n![Python](https://img.shields.io/badge/-Python-05122A?style=flat\\&logo=python)![HTML](https://img.shields.io/badge/-HTML-05122A?style=flat\\&logo=HTML5)![CSS](https://img.shields.io/badge/-CSS-05122A?style=flat\\&logo=CSS3\\&logoColor=1572B6)![JavaScript](https://img.shields.io/badge/-JavaScript-05122A?style=flat\\&logo=javascript)![React](https://img.shields.io/badge/-React-05122A?style=flat\\&logo=react)![Node.js](https://img.shields.io/badge/-Node.js-05122A?style=flat\\&logo=node.js)\n\n![VisualStudioCode](https://img.shields.io/badge/-Visual%20Studio%20Code-05122A?style=flat\\&logo=visual-studio-code\\&logoColor=007ACC)![Docker](https://img.shields.io/badge/-Docker-05122A?style=flat\\&logo=Docker)![MongoDB](https://img.shields.io/badge/-MongoDB-05122A?style=flat\\&logo=mongodb)![PostgreSQL](https://img.shields.io/badge/-PostgreSQL-05122A?style=flat\\&logo=postgresql)\n\n![Git](https://img.shields.io/badge/-Git-05122A?style=flat\\&logo=git)![GitHub](https://img.shields.io/badge/-GitHub-05122A?style=flat\\&logo=github)![GitLab](https://img.shields.io/badge/-GitLab-05122A?style=flat\\&logo=gitlab)\n\n![Markdown](https://img.shields.io/badge/-Markdown-05122A?style=flat\\&logo=markdown)","actions":[{"label":"Contact","url":"https://sidebar-blog.netlify.app/contact/","style":"secondary","icon_class":"linkedin","new_window":true,"no_follow":false,"type":"action"}]},{"section_id":"features","type":"section_grid","col_number":"three","grid_items":[{"content":"Memoization, Tabulation, and Sorting Algorithms by Example\nWhy is looking at runtime not a reliable method of calculating time\ncomplexity?\n","actions":[{"label":"View Post","url":"/docs/ds-algo/big-o/","style":"secondary"}],"title":"A Quick Guide To Big O","image":"images/bigo.jpg","title_url":"https://bgoonz-blog.netlify.app/docs/ds-algo/big-o/"},{"content":"*Python has a built in help function that let's you see a description\nof the source code without having to navigate to it… \"-SickNasty …\nAutor Unknown\"  .*\n","actions":[{"label":"View Posts","url":"https://bgoonz-blog.netlify.app/docs/python/python-ds","style":"secondary"}],"image_alt":"python","title":"Python Guide","title_url":"https://bgoonz-blog.netlify.app/docs/python/python-ds","image":"images/python-language.jpg"},{"content":"","actions":[{"label":"Learn More","url":"/docs/tools","style":"secondary"}],"title":"Guitar Effects Triggering w DTW","title_url":"https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering","image":"images/dtw-algo.jpg"},{"title_url":"https://bgoonz-blog.netlify.app/docs/react/react2/","image_alt":"img of dtw","content":"As I learn to build web applications in React I will blog about it in\nthis series in an attempt to capture the questions that a complete\nbeginner might encounter that a more seasoned developer would take for\ngranted!\n","actions":[],"type":"grid_item","title":"Beginner Guide React","image":"images/react.gif"},{"title_url":"https://dev.to/bgoonz/scope-and-context-in-javascript-5cma","image_alt":"img of react","content":"Scope & Context in JS\n\nThe **scope** of a program in JavaScript is the set of variables that are available for use within the program. \n","actions":[],"type":"grid_item","image":"images/pleasant-birch.png","title":"Scope & Closure"},{"image_alt":"scope and closure","content":"PostgreSQL Cheat Sheet, Everything You Need to View Post With VSCode\n+ Extensions & Resources, Super Simple Intro To HTML,  Understanding\nGit... etc....\n","actions":[],"type":"grid_item","title":"Web Audio Daw","image":"images/dtw-slideshow.gif"}]},{"title":"Current Interests","section_id":"interests","subtitle":"From github repositories to existential questions.","col_number":"three","grid_items":[{"title":"Angolia","title_url":"angolia","image_alt":"angolia","content":"## Full Text Search\n[Full Text Search](https://www.algolia.com/)\n## &#xA;\n","actions":[],"type":"grid_item","image":"images/algolia.png"},{"title":"Convolutional Neural Networks","title_url":"neural networks","image_alt":"neural networks","content":"Artificial neural networks, usually simply called neural networks, are computing systems vaguely inspired by the biological [neural networks](https://github.com/tensorflow/tensorflow)![neurl networks](/\\_static/app-assets/neural.PNG)\n","actions":[],"type":"grid_item","image":"images/neural.PNG"},{"title":"Jamstack","title_url":"jamstack","image_alt":"jamstack","content":"##### Why Jamstack Jamstack is the new standard architecture for the\nweb. Using Git workflows and modern build tools, pre-rendered content\nis served to a CDN and made dynamic through APIs and serverless\nfunctions. Technologies in the stack include JavaScript frameworks,\nStatic Site Generators, Headless CMSs, and CDNs.\n","actions":[],"type":"grid_item","image":"images/jamstack.png"},{"title":"Asynchronous JavaScript","title_url":"/docs/","image_alt":"event loop","content":"The term **asynchronous** refers to two or more objects or events **not** existing or happening at the same time (or multiple related things happening without waiting for the previous one to complete). In computing, the word \"asynchronous\" is used in two major contexts.\n\n","actions":[{"label":"Learn More","url":"https://www.allaboutthejersey.com/","style":"secondary","icon_class":"dev","new_window":false,"no_follow":false}],"type":"grid_item","image":"images/eventloop.gif"},{"title":"NJ Devils","image_alt":"nj-devils","content":"# New Jersey Devils Hockey Team\n\n### (Hockey in general)\n\n## Team identity\n\n[ ![image](https://upload.wikimedia.org/wikipedia/en/thumb/d/da/OldDevils.png/300px-OldDevils.png)](https://en.wikipedia.org/wiki/File:OldDevils.png)\n\nThe old green style jerseys used from 1982 to 1992The jerseys used from 1992 to 2017[Sean Avery](https://en.wikipedia.org/wiki/Sean_Avery) of the [New York Rangers](https://en.wikipedia.org/wiki/New_York_Rangers) attempts to distract Brodeur during the [2008 Stanley Cup playoffs](https://en.wikipedia.org/wiki/2008\\_Stanley_Cup_playoffs). The playoff series was the fifth to feature the [Devils-Rangers rivalry](https://en.wikipedia.org/wiki/Devils%E2%80%93Rangers_rivalry).\n","actions":[{"label":"Learn More","url":"https://www.iter.org/","style":"secondary","icon_class":"dev","new_window":false,"no_follow":false}],"type":"grid_item","image":"images/njdev-219301cd.jpg","title_url":"https://www.allaboutthejersey.com/"},{"title":"ITER Fusion Reactor Experiment (Southern France)","title_url":"https://www.iter.org/","image_alt":"ITER Reactor","content":"# Break Even Nuclear Fusion Candidate\nIn December, researchers at the Joint European Torus (JET) started\nconducting fusion experiments with tritium — a rare and radioactive\nisotope of hydrogen. The facility is a one-tenth-volume mock-up of the\nUS$22-billion ITER project and has the same doughnut-shaped 'tokamak'\ndesign — the world's most developed approach to fusion energy. It is\nthe first time since 1997 that researchers have done experiments in a\ntokamak with any significant amount of tritium.\n","actions":[],"type":"grid_item","image":"images/iter.jpg"}],"type":"section_grid"},{"section_id":"features-two-col","type":"section_grid","title":"Resume & Portfolio","col_number":"two","grid_items":[{"title":"Resume","actions":[{"label":"View In One Drive","url":"https://1drv.ms/b/s!AkGiZ9n9CRDSpLsZsnPtiN7p77vq6A","style":"secondary"},{"label":"Web Version","url":"#","style":"link","icon_class":"dev","new_window":false,"no_follow":false},{"label":"Download PDF","url":"https://github.com/bgoonz/bgoonz/raw/master/bryan_guner_resume_2021_V9.pdf","style":"secondary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"}],"image":"images/image-of-resume.png","title_url":"https://github.com/bgoonz/resume-cv-portfolio-samples/raw/master/2021-resume/bryan-guner-resume-2021.pdf"},{"title":"Showcase","content":"![My Projects](/\\_static/app-assets/lambda-demo1.gif)My Projects!\n","actions":[{"label":"Learn More","url":"/showcase","style":"secondary"}],"image_alt":"portfolio of websites","image":"images/portfolio.jpg"}]},{"title":"Blog-Archive-And-Mini-Projects","section_id":"Mini Projects","image_alt":"showcase","image_position":"left","content":"","actions":[],"type":"section_content"},{"title":"Latest & Greatest","section_id":"new content","image_alt":"animated gif","image_position":"right","content":"## Web Dev Utilitiy Tools\n<iframe class=\"block-content\" width=\"100%  width=\"1200px!important\"\nheight=\"1000px!important\"\n  src=\"https://web-dev-utility-tools-bgoonz.netlify.app/\"\n  clipboard-write;\n  encrypted-media; gyroscope; ></iframe>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://random-static-html-deploys.netlify.app\" class=\"block-content\" width=\"100%  width=\"1200px!important\" height=\"1000px!important\" ></iframe>\n","actions":[],"type":"section_content","image":null},{"section_id":"tools","image_alt":"tools","image_position":"left","content":"<iframe class=\"block-content\" width=\"100%  width=\"1200px!important\"  height=\"1000px!important\" src=\"https://bgoonz.github.io/BGOONZ_BLOG_2.0/\" ></iframe>\n<iframe class=\"block-content\" width=\"100%  width=\"1200px!important\" height=\"1000px!important\"  src=\"https://cheatsheets-42.netlify.app/\" ></iframe>\n","actions":[],"type":"section_content","title":"Tools Showcase"},{"section_id":"Web Audio DAW","image_alt":"medium","image_position":"left","actions":[{"label":"Go To Web Audio Daw","url":"https://mihirbegmusiclab.netlify.app/","style":"primary","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}],"type":"section_content","title":"Web Audio DA","image":"images/goals.jpg"},{"title":"Quick Links","section_id":"navigate from the home page","col_number":"two","type":"section_docs","subtitle":"quick links home"},{"title":"Contact","section_id":"contact","actions":[{"label":"Contact","url":"/docs/faq/contact","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"}],"type":"section_cta","subtitle":"get in touch! +1 (551) - 254 - 5505"}],"seo":{"title":"Web-Dev-Hub","description":"bigO, Python, Javascript, Audio, Processing, Learning, Blog, React,\nPostgreSQL, Scope, Closure, Web Development, Embed, API, Website, Design,\nMusic, Search","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Web-Dev-Hub","keyName":"property"},{"name":"og:description","value":"my resource sharing and blog site ... centered mostly on web development\nand just a bit of audio production / generally nerdy things I find\ninteresting.","keyName":"property"},{"name":"og:image","value":"images/code.png","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"Web-Dev-Hub"},{"name":"twitter:description","value":"Web-Dev-Hub"},{"name":"twitter:image","value":"images/4.jpg","relativeUrl":true}]},"template":"advanced"},"html":""},{"url":"/showcase/","relativePath":"showcase.md","relativeDir":"","base":"showcase.md","name":"showcase","frontmatter":{"title":"Showcase","sections":[{"section_id":"hero","type":"section_hero","title":"Showcase","image":"images/spin-cube.gif","content":"Some of my more engaging projects!\n"},{"section_id":"showcase","type":"section_grid","col_number":"three","grid_items":[{"title":"Git HTML PREVIEW","title_url":"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL","image":"images/git-preview.gif","content":"Preview html files by pasting their url into the search bar **Access-Control-Allow-Origin Header When Site A tries to fetch content from Site B**\n","actions":[{"label":"Live Site","url":"/https://ds-algo-official-c3dw6uapg-bgoonz.vercel.app/","style":"icon","icon_class":"github","new_window":true,"no_follow":false,"type":"action"}],"image_alt":"git html preview"},{"title":"Guitar Effects Automation Using Subsequence Dynamic Time Warping","title_url":"https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering","image":"images/dtw-slideshow.gif","content":"**Modified subsequence dynamic time warping feature detection using pure data implemented in python**\n","actions":[{"label":"Slide Show","url":"https://1drv.ms/p/s!AkGiZ9n9CRDSpY88x407JwfEKNrDxg?e=faHSx9","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}]},{"title":"Data Structures Interactive Learning Hub","title_url":"https://ds-algo-official-c3dw6uapg-bgoonz.vercel.app/","image":"images/ds-algo.gif","content":"**Big O notation is the language we use for talking about how long an algorithm takes to run. It's how we compare the efficiency of different approaches to a problem.**\n","actions":[{"label":"Live Site","url":"https://github.com/bgoonz/DS-ALGO-OFFICIAL","style":"icon","icon_class":"github","new_window":true,"no_follow":false,"type":"action"}]},{"title":"Learning Redux","title_url":"https://learning-redux42.netlify.app/","image_alt":"image of","content":"***React Redux provides a pair of custom React hooks that allow your React components to interact with the Redux store.***\n","actions":[{"label":"Website","url":"https://learning-redux42.netlify.app/","style":"icon","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}],"type":"grid_item","image":"images/redux-state.gif"},{"title":"Mihir-Beg-Music.com","title_url":"https://panoramic-eggplant-452e4.netlify.app/","image":"images/mihir.png","content":"Artist Showcase & Podcasting Site\n","actions":[{"label":"Live Site","url":"https://panoramic-eggplant-452e4.netlify.app/","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}]},{"title":"Aux Blog w NextJS","title_url":"https://bgoonz-blog-v3-0.netlify.app/","image_alt":"get in touch","content":"**Here lives my alternate/backup blog site!**\n","actions":[{"label":"git repo","url":"https://github.com/bgoonz/alternate-blog-theme","style":"icon","icon_class":"github","new_window":true,"no_follow":false,"type":"action"}],"type":"grid_item","image":"images/blog-form.png"},{"title":"Potluck Planner","title_url":"https://potluck-landing.netlify.app/","image_alt":"image of","content":"## Potluck Planner If you have ever tried to organize a potluck through text messages, online to-do lists or spreadsheets, you'll understand why this app is essential.In the world of social gatherings and potlucks the \"Potluck Planner\" is king. This is your place for all things pot luck.\n","actions":[],"type":"grid_item","image":"images/potluck-planner.jpg"},{"title":"Zumzi Video Conferencing","title_url":"https://github.com/bgoonz/zumzi-chat-messenger","image_alt":"video chat","content":"**Features:   Live Streaming, Screen Sharing, Fine control over all video & audio parameters and user permissions, Supports video streaming at various resolutions: Standard, HD, FHD and 4K, Group Chat, One-to-One chat, Invite Participants**\n","actions":[{"label":"Live Site","url":"https://goofy-perlman-0f61df.netlify.app/","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}],"type":"grid_item","image":"images/zumzi-video-chat.png"},{"title":"Web Audio Workstation","title_url":"lorem-ipsum","image_alt":"image of","content":"Made using jQuery and Vanilla JS\n","actions":[{"label":"Go To Live Site","url":"https://mihirbegmusiclab.netlify.app/","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"},{"label":"Github Repo","url":"https://github.com/bgoonz/MihirBegMusicLab","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}],"type":"grid_item","image":"images/royal-kangaroo.jpg"}]}],"seo":{"title":"Showcase","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Showcase","keyName":"property"},{"name":"og:description","value":"project showcase","keyName":"property"},{"name":"og:image","value":"images/My Post-4ecb169f.png","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"Showcase"},{"name":"twitter:description","value":"This is the showcase page"},{"name":"twitter:image","value":"images/5.jpg","relativeUrl":true}],"description":"Git HTML PREVIEW, Guitar Effects, Data Structures, Redux, Podcast Blog, Contact Form, Potluck Planner, Video Conferencing, Web Audio Workstation"},"template":"advanced"},"html":""},{"url":"/blog/accessibility/","relativePath":"blog/accessibility.md","relativeDir":"blog","base":"accessibility.md","name":"accessibility","frontmatter":{"title":"Accessibility","template":"post","subtitle":"Our products should be accessible to all","excerpt":"Making our products accessible benefits everyone, not just people with disabilities","date":"2022-05-29T17:38:20.581Z","image":"https://www.esri.com/arcgis-blog/wp-content/uploads/2020/07/building-web-accessibility-barriers-guidelines-standards_01.jpg","thumb_image":"https://www.esri.com/arcgis-blog/wp-content/uploads/2020/07/building-web-accessibility-barriers-guidelines-standards_01.jpg","image_position":"right","author":"src/data/authors/backup.yaml","categories":["src/data/categories/css.yaml","src/data/categories/html.yaml","src/data/categories/javascript.yaml"],"tags":["src/data/tags/career.yaml","src/data/tags/javascript.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/awesome-resources.md","src/pages/blog/adding-css-to-your-html.md"],"cmseditable":true},"html":"<p>Accessibility is everyone’s responsibility, and the purpose of this document is to provide general accessibility guidelines to developers and designers.</p>\n<h2>Overview</h2>\n<p>Our products should be accessible to all. At minimum, features should comply to the requirements listed in <a href=\"https://www.access-board.gov/guidelines-and-standards/communications-and-it/about-the-section-508-standards/guide-to-the-section-508-standards/web-based-intranet-and-internet-information-and-applications-1194-22\">508 Reference Guide - 1194.22</a> from the US Access Board, and conform to <a href=\"https://www.w3.org/TR/WCAG20/#conformance\">Web Content Accessibility Guidelines 2.0</a> at Level AA.</p>\n<p>Making our products accessible benefits everyone, not just people with disabilities. Below are some examples of use cases in which accessibility is important:</p>\n<ul>\n<li><strong>Visual</strong>: blindness, low vision, color blindness, using a screen reader or related assistive tech for lifestyle reasons (e.g. long car commute), machine readability and screen scraping technologies</li>\n<li><strong>Hearing</strong>: deafness, hearing impairment, speech impairment, using closed captioning or other assistive features for lifestyle reasons (e.g. coworking in a loud coffee shop)</li>\n<li><strong>Cognitive</strong>: including short-term memory issues, dyslexia, learning disabilities, trying to work or consume content while distracted or multitasking, etc.</li>\n<li><strong>Mobility</strong>: mobility impairments, repetitive stress injuries, power users who love keyboard shortcuts, busy parents holding a sleeping child while trying to operate a computer with one hand, etc.</li>\n</ul>\n<h2>General guidelines</h2>\n<h3>Semantic markup</h3>\n<p>Always use semantic HTML elements, like <code class=\"language-text\">button</code>, <code class=\"language-text\">ul</code>, <code class=\"language-text\">nav</code>. Most modern browsers implement the accessibility features outlined in the specs for these elements; without them, elements will need additional <a href=\"https://www.w3.org/WAI/PF/aria\">ARIA attributes and roles</a> to be recognized by assistive technologies.</p>\n<p>Elements like <code class=\"language-text\">h1</code>-<code class=\"language-text\">h6</code>, <code class=\"language-text\">nav</code>, <code class=\"language-text\">footer</code>, <code class=\"language-text\">header</code> have <a href=\"https://www.w3.org/WAI/PF/aria/roles\">meaningful roles</a> assigned, so use them carefully. This can help assistive technologies read the page better and help users find information quicker.</p>\n<p>Only use a <code class=\"language-text\">div</code> or a <code class=\"language-text\">span</code> to markup up content when there isn't another HTML element that would semantically be more appropriate, or when an element is needed exclusively for applying CSS styles or JS behaviors.</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- Do: Button can be focused and tabbed to. --></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>btn<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>Send<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- Don't: Button can't be focused and tabbed to. --></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>span</span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>btn<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>Send<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>span</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<blockquote>\n<p>More on semantic markup:</p>\n<ul>\n<li><a href=\"https://webaim.org/techniques/semanticstructure/\">Semantic Structure – WebAIM</a></li>\n</ul>\n</blockquote>\n<h3>Keyboard accessibility</h3>\n<p>Make sure elements can be reached via tabbing, and actions can be triggered with a keyboard. Using semantic markup is especially important in this case as it ensures that actionable elements are tabbable and triggerable without a mouse. Note that elements positioned off-screen are still tabbable, but those hidden with <code class=\"language-text\">display: none</code> or <code class=\"language-text\">visibility: hidden</code> are effectively removed from content since they are neither read by screen readers nor reachable by keyboard.</p>\n<p>Tab order is determined by the order of elements in the DOM, and not by their visual positioning on the page after CSS is applied. CSS properties <code class=\"language-text\">float</code> and <code class=\"language-text\">order</code> for flex items are two common sources for disconnection between visual and DOM order.</p>\n<p>The <code class=\"language-text\">tabindex</code> attribute should only be used when absolutely necessary.</p>\n<ul>\n<li><code class=\"language-text\">tabindex=0/-1</code> makes an element focusable, while <code class=\"language-text\">tabindex=0</code> also includes the element in the normal tab order. In both cases, keyboard triggers of the element still require scripting, so where possible, use <a href=\"https://w3c.github.io/html/dom.html#kinds-of-content-interactive-content\">interactive content</a> instead.</li>\n<li><code class=\"language-text\">tabindex=1+</code> takes an element to the very front of the default tab order. When it's applied, the element's visual positioning is no longer indicative of its tab order, and the only way to find out where an element is would be by tabbing through the page. Therefore, unless a page is carefully designed around elements with positive tabindex, it is very error-proned, and thus currently prohibited in github.com.</li>\n</ul>\n<p>Finally, bear in mind that some assistive technologies have keyboard combinations of their own that will override the combination on the web page, so don't rely on keyboard shortcuts as the only alternative to mouse actions.</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- Do: Tab order can be guessed. --></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>btn<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>1<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>btn<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>2<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>btn<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>3<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- Don't: The second button's tab order is unexpected. --></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>btn<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>1<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>btn<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">tabindex</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>1<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>2<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>btn<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>3<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<blockquote>\n<p>More on keyboard accessibility:</p>\n<ul>\n<li><a href=\"https://www.w3.org/TR/UNDERSTANDING-WCAG20/navigation-mechanisms-focus-order.html\">Focus Order – Understanding WCAG 2.0</a></li>\n<li><a href=\"https://tink.uk/time-to-revisit-accesskey/\">Time to revisit accesskey? by Léonie Watson</a></li>\n<li><a href=\"https://tink.uk/flexbox-the-keyboard-navigation-disconnect/\">Flexbox &#x26; the keyboard navigation disconnect by Léonie Watson</a></li>\n</ul>\n</blockquote>\n<h3>Visual accessibility</h3>\n<p>Be mindful when using small font size, thin font weight, low contrast colors in designs as it can severely affect usability.</p>\n<p>Instead of relying solely on color to communicate information, always combine color with another factor, like shape or position change. This is important because some colors can be hard to tell apart due to color blindness or weak eyesight.</p>\n<blockquote>\n<p>More on visual accessibility:</p>\n<ul>\n<li><a href=\"https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-without-color.html\">Use of Color – Understanding WCAG 2.0</a></li>\n<li><a href=\"https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html\">Contrast – Understanding WCAG 2.0</a></li>\n</ul>\n</blockquote>\n<h3>Text and labels</h3>\n<p>Make sure text-based alternative is always available when using icons, images, and graphs, and that the text by itself presents meaningful information.</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- Do: Link text communicates destination. --></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>p</span><span class=\"token punctuation\">></span></span>Find out more about <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>a</span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>#url<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>GitHub Enterprise pricing<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>a</span><span class=\"token punctuation\">></span></span>.<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>br</span> <span class=\"token punctuation\">/></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>p</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- Don't: \"Click here\" is not meaningful. --></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>p</span><span class=\"token punctuation\">></span></span>\n    To find out more about GitHub Enterprise pricing,\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>a</span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>#url<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>click here<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>a</span><span class=\"token punctuation\">></span></span>.\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>p</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>Use <code class=\"language-text\">aria-label</code> when there is no text.</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>a</span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://help.github.com/<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>&lt;%= octicon(\"question\", :\"aria-label\" => \"Help\") %><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>a</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h3>Link responsibly</h3>\n<p>Navigating from a list of all the links on a given web page is very common for assistive technology users. We should make sure that the link text itself is meaningful and unique, and there should be as few duplicated references as possible.</p>\n<blockquote>\n<p>More on link responsibly:</p>\n<ul>\n<li><a href=\"https://www.w3.org/TR/UNDERSTANDING-WCAG20/navigation-mechanisms-refs.html\">Link Purpose – Understanding WCAG 2.0</a></li>\n</ul>\n</blockquote>\n<h3>Dynamic content</h3>\n<p>When using JavaScript to change the content on the page, always make sure that screen reader users are informed about the change. This can be done with <code class=\"language-text\">aria-live</code>, or focus management.</p>\n<blockquote>\n<p>More on dynamic content:</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions\">ARIA Live Regions – MDN</a></li>\n</ul>\n</blockquote>\n<h3>Focus management</h3>\n<p>Focus management is useful for informing users about updated content, and for making sure users land on the next useful section after performing an action. This means using scripts to change user’s currently focused element, and when focus changes, screen readers will read out change.</p>\n<h3>Accessible forms</h3>\n<p>It is common for assistive technology users to jump straight to a form when using a website, so make sure most relevant information is in the form and is labelled properly. Labels and inputs should be associated with the <code class=\"language-text\">label[for]</code> and <code class=\"language-text\">input[id]</code>, and help texts should either be part of the label or be associated with <code class=\"language-text\">aria-describedby</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- Do: Click \"Email\" label to focus on the input, and help text is read out by screen readers when focusing on the input. --></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>label</span> <span class=\"token attr-name\">for</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>test_input<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>Email<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>label</span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>br</span> <span class=\"token punctuation\">/></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>input</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>test_input<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">aria-describedby</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>test_input_help_good<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>width-full my-1<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>email<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>test_input_help_good<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>f6<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>Please enter an email ending with @github.com.<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- Don't: Input and label are not associated, and help text is not read out by screen reader when focusing on the input. --></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>label</span><span class=\"token punctuation\">></span></span>Email<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>label</span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>br</span> <span class=\"token punctuation\">/></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>input</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>email<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>width-full my-1<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>test_input_help_bad<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>f6<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>Please enter an email ending with @github.com.<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h2>Development tools</h2>\n<h3>Linting</h3>\n<p>We currently run basic linting <a href=\"https://github.com/github/github/blob/8546895623677abc70f61951642f32c16de231a1/test/fast/linting/accessible_tabindex_test.rb\">against positive <code class=\"language-text\">tabindex</code></a> and <a href=\"https://github.com/github/github/blob/8546895623677abc70f61951642f32c16de231a1/test/rubocop/cop/rails/link_href.rb\">anchor links with <code class=\"language-text\">href=\"#\"</code></a>.</p>\n<p>We do client side scanning of inaccessible elements in development environment. The inaccessible elements will be styled with red borders with an onclick alert and console warnings.</p>\n<h3>External tools</h3>\n<ul>\n<li>Google Chrome provides an <a href=\"https://chrome.google.com/webstore/detail/accessibility-developer-t/fpkknkljclfencbdbgkenhalefipecmb\">Accessibility Developer Tools extension</a>. Once installed, go to Audits tab in developer tools, tick Accessibility. It scans the page for violations and suggests solutions.</li>\n<li>If you're working on a design that uses color to communicate something, grab the <a href=\"https://itunes.apple.com/tw/app/chromatic-vision-simulator/id389310222?mt=8\">Chromatic Vision Simulator app</a>, this will let you use your iPhone camera to see what a colorblind person would see.</li>\n<li>Check out <a href=\"https://github.com/showcases/web-accessibility\">the Web Accessibility showcase on GitHub</a>. GitHubbers are free to add more projects to the showcase.</li>\n</ul>\n<h2>Manual testing</h2>\n<h3>Screen reader</h3>\n<p>To use VoiceOver, the built-in screen reader for Mac, just hit <kbd>⌘</kbd> + <kbd>F5</kbd>. This will start voice narration and display most of the spoken information in a text box.</p>\n<p>Use <kbd>alt</kbd> + <kbd>control</kbd> + <kbd>left/right</kbd> to navigate a web page. <kbd>alt</kbd> + <kbd>control</kbd> + <kbd>space</kbd> to click on an element. For more help with VoiceOver, check out the built-in tutorial in <code class=\"language-text\">System Preferences > Accessibility > VoiceOver > Open VoiceOver Training</code>.</p>\n<p>Keep in mind that behaviors in different screen readers can differ when navigating the same web page; just like designing for different browsers, when it comes to accessibility, it is not just the implementation of the browsers that can be different, but also the ones of assistive softwares.</p>\n<h2>Internal resources</h2>\n<ol>\n<li>You can mention these teams when looking for help:</li>\n<li><a href=\"https://github.com/orgs/github/teams/accessibility\">@github/accessibility</a>: GitHubbers interested in accessibility related topics and work on website accessibility issues.</li>\n<li><a href=\"https://github.com/orgs/github/teams/colorblind\">@github/colorblind</a>: GitHubbers who are interested in accessibility for colorblindness.</li>\n<li>Go to #accessibility Slack channel to ask questions or discuss accessibility issues.</li>\n<li>Check <a href=\"https://github.com/github/accessibility\">github/accessibility repository</a> for information on events or learning resources.</li>\n</ol>\n<h2>User support</h2>\n<p>Accessibility is a priority for us, if you ever encounter accessibility related issues when using github.com, please don’t hesitate to reach out to us via <a href=\"https://github.com/contact\">the contact page</a> or email us at <a href=\"mailto:support@github.com\">support@github.com</a>, we will try our best to assist.</p>\n<p>For information about the accessibility compliance of GitHub products, please refer to our <a href=\"https://government.github.com/accessibility/\">VPAT report, outlining §508 accessibility information for GitHub.com, GitHub Enterprise, and GitHub Desktop</a>.</p>"},{"url":"/blog/10-essential-react-interview-questions/","relativePath":"blog/10-essential-react-interview-questions.md","relativeDir":"blog","base":"10-essential-react-interview-questions.md","name":"10-essential-react-interview-questions","frontmatter":{"title":"10 Essential React Interview Questions","template":"post","subtitle":"For Aspiring Frontend Developers","excerpt":"Comprehensive React Cheatsheet included at the bottom of this article!","date":"2022-05-08T18:44:35.533Z","image":"https://d585tldpucybw.cloudfront.net/sfimages/default-source/blogs/templates/social/reactt-light_1200x628.png?sfvrsn=43eb5f2a_2","thumb_image":"https://d585tldpucybw.cloudfront.net/sfimages/default-source/blogs/templates/social/reactt-light_1200x628.png?sfvrsn=43eb5f2a_2","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/react.yaml","src/data/categories/js.yaml"],"tags":["src/data/tags/react.yaml","src/data/tags/javascript.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/react-semantics.md","src/pages/blog/react-state.md"],"cmseditable":true},"html":"<h1>10 Essential React Interview Questions For Aspiring Frontend Developers</h1>\n<p>Comprehensive React Cheatsheet included at the bottom of this article!</p>\n<hr>\n<h3>10 Essential React Interview Questions For Aspiring Frontend Developers</h3>\n<h4>Comprehensive React Cheatsheet included at the bottom of this article!</h4>\n<h3>Resources:</h3>\n<a href=\"https://javascript.plainenglish.io/introduction-to-react-for-complete-beginners-8021738aa1ad\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://javascript.plainenglish.io/introduction-to-react-for-complete-beginners-8021738aa1ad\">\n<strong>Introduction to React for Complete Beginners</strong>\n<br/>\n<p><em>All of the code examples below will be included a second time at the bottom of this article as an embedded gist.</em>javascript.plainenglish.io</a>\n<a href=\"https://javascript.plainenglish.io/introduction-to-react-for-complete-beginners-8021738aa1ad\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<a href=\"https://bgoonz-blog.netlify.app/docs/react/react2/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonz-blog.netlify.app/docs/react/react2/\">\n<strong>Beginner's Guide To React Part 2</strong>\n<br/>\n<p><em>As I learn to build web applications in React I will blog about it in this series in an attempt to capture the…</em>\n<a href=\"https://bgoonz-blog.netlify.app/docs/react/react2/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<a href=\"https://github.com/bgoonz/React_Notes_V3\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/React_Notes_V3\">\n<strong>bgoonz/React_Notes_V3</strong>\n<br/>\n<p><em>A JavaScript library for building user interfaces Declarative React makes it painless to create interactive UIs. Design…</em>github.com</a>\n<a href=\"https://github.com/bgoonz/React_Notes_V3\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<a href=\"https://reactjs.org/docs\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://reactjs.org/docs\">\n<strong>Getting Started - React</strong>\n<br/>\n<p><em>A JavaScript library for building user interfaces</em>reactjs.org</a>\n<a href=\"https://reactjs.org/docs\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<h3>Also … here is my brand new blog site… built with react and a static site generator called GatsbyJS!</h3>\n<h4>It's a work in progress</h4>\n<p><a href=\"https://bgoonz-blog.netlify.app/\" class=\"markup--anchor markup--p-anchor\">https://bgoonz-blog.netlify.app/</a></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*t3UQh848ndt4rgr_fDToaw.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*39weCjnVdDf0Kuzj\" alt=\"Photo by Ferenc Almasi on Unsplash\" class=\"graf-image\" />\n<figcaption>Photo by <a href=\"https://unsplash.com/@flowforfrank?utm_source=medium&amp;utm_medium=referral\" class=\"markup--anchor markup--figure-anchor\">Ferenc Almasi</a> on <a href=\"https://unsplash.com?utm_source=medium&amp;utm_medium=referral\" class=\"markup--anchor markup--figure-anchor\">Unsplash</a>\n</figcaption>\n</figure>### Beginning of the Article:\n<p><strong>Pros</strong></p>\n<ol>\n<li><span id=\"156e\">Easy to learn</span></li>\n<li><span id=\"859a\">HTML-like syntax allows templating and highly detailed documentation</span></li>\n<li><span id=\"5b3a\">Supports server-side rendering</span></li>\n<li><span id=\"cb03\">Easy migrating between different versions of React</span></li>\n<li><span id=\"7332\">Uses JavaScript rather than framework-specific code</span></li>\n</ol>\n<p><strong>Cons</strong></p>\n<ol>\n<li><span id=\"e1f7\">Poor documentation</span></li>\n<li><span id=\"db68\">Limited to only view part of MVC</span></li>\n<li><span id=\"814a\">New developers might see JSC as a barrier</span></li>\n</ol>\n<h3>Where to Use React</h3>\n<ol>\n<li><span id=\"fa3e\">For apps that have multiple events</span></li>\n<li><span id=\"f46a\">When your app development team excels in CSS, JavaScript and HTML</span></li>\n<li><span id=\"2d25\">You want to create sharable components on your app</span></li>\n<li><span id=\"9729\">When you need a personalized app solution</span></li>\n</ol>\n<h3>Misconceptions about React</h3>\n<h4><a href=\"https://aglowiditsolutions.com/blog/react-vs-angular/\" class=\"markup--anchor markup--h4-anchor\">React is a framework</a>:</h4>\n<p><a href=\"https://aglowiditsolutions.com/blog/react-vs-angular/\" class=\"markup--anchor markup--p-anchor\">Many developers an</a>d aspiring students misinterpret React to be a fully functional framework. It is because we often compare React with major frameworks such as Angular and Ember. This comparison is not to compare the best frameworks but to focus on the differences and similarities of React and Angular's approach that makes their offerings worth studying. Angular works on <strong>the MVC model</strong> to support the Model, View, and Controller layers of an app. React focuses only on the 'V,' which is the <strong>view layer</strong> of an application and how to make handling it easier to integrate smoothly into a project.</p>\n<h4>React's Virtual DOM is faster than DOM.</h4>\n<p>React uses a <strong>Virtual DOM</strong>, which is essentially a tree of JavaScript objects representing the actual browser DOM. The advantage of using this for the developers is that they don't manipulate the DOM directly as developers do with jQuery when they write React apps. Instead, they would tell React how they want the DOM to make changes to the state object and allow React to make the necessary updates to the browser DOM. This helps create a comprehensive development model for developers as they don't need to track all DOM changes. They can modify the state object, and React would use its algorithms to understand what part of UI changed compared to the previous DOM. Using this information updates the actual browser DOM. Virtual DOM provides an excellent API for creating UI and minimizes the update count to be made on the browser DOM.</p>\n<p>However, it is <strong>not faster</strong> than the actual DOM. You just read that it needs to pull extra strings to figure out what part of UI needs to be updated before actually performing those updates. Hence, Virtual DOM is beneficial for many things, but it <strong><em>isn't faster than DOM.</em></strong></p>\n<hr>\n<h3><strong>1. Explain how React uses a tree data structure called the virtual DOM to model the DOM</strong></h3>\n<blockquote>\n<p>The virtual DOM is a copy of the actual DOM tree. Updates in React are made to the virtual DOM. React uses a diffing algorithm to reconcile the changes and send the to the DOM to commit and paint.</p>\n</blockquote>\n<h3><strong>2. Create virtual DOM nodes using JSX</strong> To create a React virtual DOM node using JSX, define HTML syntax in a JavaScript file.</h3>\n<blockquote>\n<p>Here, the JavaScript hello variable is set to a React virtual DOM h1 element with the text \"Hello World!\".</p>\n</blockquote>\n<blockquote>\n<p>You can also nest virtual DOM nodes in each other just like how you do it in HTML with the real DOM.</p>\n</blockquote>\n<h3><strong>3. Use debugging tools to determine when a component is rendering</strong></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*jf3yl4GKDHpxmPJk.gif\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/0*hBOo6hfwhKwS5UDM.jpg\" class=\"graf-image\" />\n</figure>#### We use the React DevTools extension as an extension in our Browser DevTools to debug and view when a component is rendering\n<h3><strong>4. Describe how JSX transforms into actual DOM nodes</strong></h3>\n<ul>\n<li><span id=\"358b\">To transfer JSX into DOM nodes, we use the ReactDOM.render method. It takes a React virtual DOM node's changes allows Babel to transpile it and sends the JS changes to commit to the DOM.</span></li>\n</ul>\n<h3><strong>5. Use the</strong> <code class=\"language-text\">ReactDOM.render</code> <strong>method to have React render your virtual DOM nodes under an actual DOM node</strong></h3>\n<hr>\n<h3><strong>6. Attach an event listener to an actual DOM node using a virtual node</strong></h3>\n<p>The virtual DOM (VDOM) is a programming concept where an ideal, or \"virtual\", representation of a UI is kept in memory and synced with the \"real\" DOM by a library such as ReactDOM. This process is called <a href=\"https://reactjs.org/docs/reconciliation.html\" class=\"markup--anchor markup--p-anchor\">reconciliation</a>.</p>\n<p>This approach enables the declarative API of React: You tell React what state you want the UI to be in, and it makes sure the DOM matches that state. This abstracts out the attribute manipulation, event handling, and manual DOM updating that you would otherwise have to use to build your app.</p>\n<p>Since \"virtual DOM\" is more of a pattern than a specific technology, people sometimes say it to mean different things. In React world, the term \"virtual DOM\" is usually associated with <a href=\"https://reactjs.org/docs/rendering-elements.html\" class=\"markup--anchor markup--p-anchor\">React elements</a> since they are the objects representing the user interface. React, however, also uses internal objects called \"fibers\" to hold additional information about the component tree. They may also be considered a part of \"virtual DOM\" implementation in React.</p>\n<h3>Is the Shadow DOM the same as the Virtual DOM?</h3>\n<p>No, they are different. The Shadow DOM is a browser technology designed primarily for scoping variables and CSS in web components. The virtual DOM is a concept implemented by libraries in JavaScript on top of browser APIs.</p>\n<ul>\n<li><span id=\"8534\">To add an event listener to an element, define a method to handle the event and associate that method with the element event you want to listen for:</span></li>\n</ul>\n<h3><strong>7. Use</strong> <code class=\"language-text\">create-react-app</code> <strong>to initialize a new React app and import required dependencies</strong></h3>\n<ul>\n<li><span id=\"6d60\">Create the default create-react-application by typing in our terminal</span></li>\n</ul>\n<h4><a href=\"https://www.freecodecamp.org/news/npm-vs-npx-whats-the-difference/\" class=\"markup--anchor markup--h4-anchor\">Explanation of npm vs npx from Free Code Camp:</a></h4>\n<p><strong>npm</strong> (node package manager) is the dependency/package manager you get out of the box when you install Node.js. It provides a way for developers to install packages both globally and locally.</p>\n<p>Sometimes you might want to take a look at a specific package and try out some commands. But you cannot do that without installing the dependencies in your local <code class=\"language-text\">node_modules</code> folder.</p>\n<h3>npm the package manager</h3>\n<p>npm is a couple of things. First and foremost, it is an online repository for the publishing of open-source Node.js projects.</p>\n<p>Second, it is a CLI tool that aids you to install those packages and manage their versions and dependencies. There are hundreds of thousands of Node.js libraries and applications on npm and many more are added every day.</p>\n<p>npm by itself doesn't run any packages. If you want to run a package using npm, you must specify that package in your <code class=\"language-text\">package.json</code> file.</p>\n<p>When executables are installed via npm packages, npm creates links to them:</p>\n<ul>\n<li><span id=\"7798\"><strong>local</strong> installs have links created at the <code class=\"language-text\">./node_modules/.bin/</code> directory</span></li>\n<li><span id=\"a534\"><strong>global</strong> installs have links created from the global <code class=\"language-text\">bin/</code> directory (for example: <code class=\"language-text\">/usr/local/bin</code> on Linux or at <code class=\"language-text\">%AppData%/npm</code> on Windows)</span></li>\n</ul>\n<p>To execute a package with npm you either have to type the local path, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ ./node_modules/.bin/your-package</code></pre></div>\n<p>or you can run a locally installed package by adding it into your <code class=\"language-text\">package.json</code> file in the scripts section, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"name\": \"your-application\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"your-package\": \"your-package\"\n  }\n}</code></pre></div>\n<p>Then you can run the script using <code class=\"language-text\">npm run</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm run your-package</code></pre></div>\n<p>You can see that running a package with plain npm requires quite a bit of ceremony.</p>\n<p>Fortunately, this is where <strong>npx</strong> comes in handy.</p>\n<h3>npx the package runner</h3>\n<p>Since npm version <a href=\"https://github.com/npm/npm/releases/tag/v5.2.0\" class=\"markup--anchor markup--p-anchor\">5.2.0</a> npx is pre-bundled with npm. So it's pretty much a standard nowadays.</p>\n<p><strong>npx</strong> is also a CLI tool whose purpose is to make it easy to install and manage dependencies hosted in the npm registry.</p>\n<p>It's now very easy to run any sort of Node.js-based executable that you would normally install via npm.</p>\n<p>You can run the following command to see if it is already installed for your current npm version:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ which npx</code></pre></div>\n<p>If it's not, you can install it like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ npm install -g npx</code></pre></div>\n<p>Once you make sure you have it installed, let's see a few of the use cases that make <strong>npx</strong> extremely helpful.</p>\n<h3>Run a locally installed package easily</h3>\n<p>If you wish to execute a locally installed package, all you need to do is type:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ npx your-package</code></pre></div>\n<p>npx will check whether <code class=\"language-text\">&lt;command></code> or <code class=\"language-text\">&lt;package></code> exists in <code class=\"language-text\">$PATH</code>, or in the local project binaries, and if so it will execute it.</p>\n<h3>Execute packages that are not previously installed</h3>\n<p>Another major advantage is the ability to execute a package that wasn't previously installed.</p>\n<p>Sometimes you just want to use some CLI tools but you don't want to install them globally just to test them out. This means you can save some disk space and simply run them only when you need them. This also means your global variables will be less polluted.</p>\n<blockquote>\n<p>Now, where were we?</p>\n</blockquote>\n<p><code class=\"language-text\">npx create-react-app &lt;name of app> --use-npm</code></p>\n<ul>\n<li><span id=\"e1cb\">npx gives us the latest version. <code class=\"language-text\">--use-npm</code> just means to use npm instead of yarn or some other package manager</span></li>\n</ul>\n<h3><strong>8. Pass props into a React component</strong></h3>\n<ul>\n<li><span id=\"9111\"><code class=\"language-text\">props</code> is an object that gets passed down from the parent component to the child component. The values can be of any data structure including a function (which is an object)</span></li>\n</ul>\n<!-- -->\n<ul>\n<li><span id=\"7a12\">You can also <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals\" class=\"markup--anchor markup--li-anchor\">interpolate values</a> into JSX.</span></li>\n<li><span id=\"f405\">Set a variable to the string, \"world\", and replace the string of \"world\" in the NavLinks JSX element with the variable wrapped in curly braces:</span></li>\n</ul>\n<blockquote>\n<p><strong>Accessing props:</strong></p>\n</blockquote>\n<p>To access our props object in another component we pass it the props argument and React will invoke the functional component with the props object.</p>\n<h3>Reminder:</h3>\n<p>Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called \"props\") and return React elements describing what should appear on the screen.</p>\n<h3>Function and Class Components</h3>\n<p>The simplest way to define a component is to write a JavaScript function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Welcome(props) {\n  return &lt;h1>Hello, {props.name}&lt;/h1>;\n}</code></pre></div>\n<p>This function is a valid React component because it accepts a single \"props\" (which stands for properties) object argument with data and returns a React element. We call such components \"function components\" because they are literally JavaScript functions.</p>\n<p>You can also use an <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes\" class=\"markup--anchor markup--p-anchor\">ES6 class</a> to define a component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Welcome extends React.Component {\n  render() {\n    return &lt;h1>Hello, {this.props.name}&lt;/h1>;\n  }\n}</code></pre></div>\n<p>The above two components are equivalent from React's point of view.</p>\n<ul>\n<li><span id=\"99d5\">You can pass down <strong>as many props keys as you want</strong>.</span></li>\n</ul>\n<h3><strong>9. Destructure props</strong></h3>\n<blockquote>\n<p>You can destructure the props object in the function component's parameter.</p>\n</blockquote>\n<h3><strong>10. Create routes using components from the react-router-dom package</strong></h3>\n<p>a. Import the react-router-dom package:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm i react-router-dom</code></pre></div>\n<blockquote>\n<p>In your index.js:</p>\n</blockquote>\n<ol>\n<li><span id=\"46f3\">Above you import your BrowserRouter with which you can wrap your entire route hierarchy. This makes routing information from React Router available to all its descendent components.</span></li>\n<li><span id=\"f675\">Then in the component of your choosing, usually top tier such as App.js, you can create your routes using the Route and Switch Components</span></li>\n</ol>\n<hr>\n<h3>Discover More:</h3>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonz-blog.netlify.app/\">\n<strong>Web-Dev-Hub</strong>\n<br/>\n<p><em>Memoization, Tabulation, and Sorting Algorithms by Example Why is looking at runtime not a reliable method of…</em>bgoonz-blog.netlify.app</a>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<h3>REACT CHEAT SHEET:</h3>\n<p><em>More content at</em> <a href=\"http://plainenglish.io/\" class=\"markup--anchor markup--p-anchor\">\n<em>plainenglish.io</em>\n</a></p>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/cbaafb31765d\">June 11, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/react-md-cbaafb31765d\" class=\"p-canonical\">Canonical link</a></p>\n<p>August 31, 2021.</p>"},{"url":"/blog/adding-css-to-your-html/","relativePath":"blog/adding-css-to-your-html.md","relativeDir":"blog","base":"adding-css-to-your-html.md","name":"adding-css-to-your-html","frontmatter":{"title":"Adding CSS to your Html","template":"post","subtitle":"Html &Css for beginners ","excerpt":"Add css to your html","date":"2022-04-10T11:11:00.257Z","image":"https://imgs.search.brave.com/cehHw-ilYRSegAPhZiwKPGsYmFyN_HiDBO9xjfzxlTM/rs:fit:1200:720:1/g:ce/aHR0cHM6Ly9zYWJl/LmlvL2NsYXNzZXMv/Y3NzL2hlcm8ucG5n","thumb_image":"https://imgs.search.brave.com/cehHw-ilYRSegAPhZiwKPGsYmFyN_HiDBO9xjfzxlTM/rs:fit:1200:720:1/g:ce/aHR0cHM6Ly9zYWJl/LmlvL2NsYXNzZXMv/Y3NzL2hlcm8ucG5n","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/html.yaml","src/data/categories/css.yaml"],"tags":["src/data/tags/resources.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/adding-css-to-your-html.md","src/pages/blog/using-the-dom.md","src/pages/blog/front-end-interview-questions-part-2.md"],"cmseditable":true},"html":"<h1>Adding CSS To Your HTML</h1>\n<p>For beginners … very picture heavy since CSS is such a visual discipline!</p>\n<hr>\n<h3>Adding CSS To Your HTML</h3>\n<h4>For beginners … very picture heavy since CSS is such a visual discipline</h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*3hnCIyXstRSHgYO5-z-51g.png\" class=\"graf-image\" />\n</figure>### Getting CSS Into Your HTML\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;!-- example.html -->\n&lt;!DOCTYPE html>\n&lt;html>\n  &lt;head>\n    &lt;link\n      rel=\"stylesheet\"\n      href=\"https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css\"\n    />\n    &lt;link rel=\"stylesheet\" href=\"/styles/site.css\" />\n  &lt;/head>\n  &lt;body></code></pre></div>\n</body>\n    </html>\n<ul>\n<li><span id=\"36f1\"><em>To connect your CSS sheet to your HTML page, use the link tag like so.</em></span></li>\n<li><span id=\"f743\">Many developers use External pre-written CSS stylesheets for consistent design.</span></li>\n<li><span id=\"af3f\">You can connect multiple stylesheets.</span></li>\n</ul>\n<h3>CSS Selectors</h3>\n<ul>\n<li><span id=\"2d5b\"><code class=\"language-text\">CSS Selector</code> : Applies styles to a specific DOM element(s), there are various types:</span></li>\n<li><span id=\"29cd\"><code class=\"language-text\">Type Selectors</code> : Matches by node name.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*GOzh0U_yFtsOo9Hq\" class=\"graf-image\" />\n</figure>-   <span id=\"e624\">`Class Selectors` : Matches by class name.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*WMQXdyBA2MeUYoVvY0Kjew.png\" class=\"graf-image\" />\n</figure>-   <span id=\"8c31\">`ID Selectors` : Matches by ID name.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*uyRa6tM8Jlg648Rl\" class=\"graf-image\" />\n</figure>-   <span id=\"d011\">`Universal Selectors` : Selects all HTML elements on a page.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*LfKazZMelOZrcOsp.jpg\" class=\"graf-image\" />\n</figure>-   <span id=\"e143\">`Attribute Selectors` : Matches elements based on the prescence or value of a given attribute. (i.e. a\\[title\\] will match all a elements with a title attribute)</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/* Type selector */\ndiv {\n  background-color: #000000;\n}\n\n/* Class selector */\n.active {\n  color: #ffffff;\n}\n\n/* ID selector */\n#list-1 {\n  border: 1px solid gray;\n}\n\n/* Universal selector */\n* {\n  padding: 10px;\n}\n\n/* Attribute selector */\na[title] {\n  font-size: 2em;\n}</code></pre></div>\n<h4><strong>Class Selectors</strong></h4>\n<ul>\n<li><span id=\"45c5\">Used to select all elements of a certain class denoted with a <code class=\"language-text\">.[class name]</code></span></li>\n<li><span id=\"f9e4\">You can assign multiple classes to a DOM element by separating them with a space.</span></li>\n</ul>\n<h4><strong>Compound Class Selectors</strong></h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*iIOiP-ML_k6g0yTxZQyQ4A.png\" class=\"graf-image\" />\n</figure>-   <span id=\"bcf1\">To get around accidentally selecting elements with multiple classes beyond what we want to grab we can chain dots.</span>\n-   <span id=\"a54c\">TO use a compound class selector just append the classes together when referencing them in the CSS.</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"box yellow\"></code></pre></div>\n</div>\n    <div class=\"box orange\">\n</div>\n    <div class=\"circle orange\">\n</div>\n<ul>\n<li><span id=\"e8ca\">i.e. .box.yellow will select only the first element.</span></li>\n<li><span id=\"34a4\"><strong>KEEP IN MIND</strong> that if you do include a space it will make the selector into a <em>descendant selector</em>.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">h1#heading,\nh2.subheading {\n  font-style: italic;\n}</code></pre></div>\n<ul>\n<li><span id=\"b382\">When we want to target all <code class=\"language-text\">h1</code> tags with the id of <code class=\"language-text\">heading</code>.</span></li>\n</ul>\n<h4><strong>CSS Combinators</strong></h4>\n<ul>\n<li><span id=\"383a\">CSS Combinators are used to combine other selectors into more complex or targeted selectors — they are very powerful!</span></li>\n<li><span id=\"2805\">Be careful not to use too many of them as they will make your CSS far too complex.</span></li>\n</ul>\n<h4><code class=\"language-text\">Descendant Selectors</code></h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*YPkGcUc4gf2WtJYdf6Yvmg.png\" class=\"graf-image\" />\n</figure>-   <span id=\"5e1b\">Separated by a space.</span>\n-   <span id=\"5d0b\">Selects all descendants of a parent container.</span>\n<h4><code class=\"language-text\">Direct Child Selectors</code></h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*SByLFbio2RGGnFHj.jpg\" class=\"graf-image\" />\n</figure>-   <span id=\"47ef\">Indicated with a `>`.</span>\n-   <span id=\"eff3\">Different from descendants because it only affects the direct children of an element.</span>\n<h4>CSS</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.menu > .is-active { background-color: #ffe0b2; }</code></pre></div>\n<h4>HTML</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;body> &lt;div class=\"menu\"> &lt;div class=\"is-active\">Belka&lt;/div> &lt;div> &lt;div class=\"is-active\">Strelka&lt;/div> &lt;/div> &lt;/div> &lt;/body> &lt;div class=\"is-active\"> Laika &lt;/div> &lt;/body></code></pre></div>\n<ul>\n<li><span id=\"b452\">Belka would be the only element selected.</span></li>\n</ul>\n<h4><code class=\"language-text\">Adjacent Sibling Selectors</code></h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*m0yPz3xJPeP3br2C.png\" class=\"graf-image\" />\n</figure>-   <span id=\"5dca\">Uses the `+` symbol.</span>\n-   <span id=\"9063\">Used for elements that directly follow one another and who both have the same parent.</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">h1 + h2 { font-style: italic;   }\n\n//HTML:\n\n&lt;h1>Big header&lt;/h1> &lt;h2>This one is styled because it is directly adjacent to the H1&lt;/h2> &lt;h2>This one is NOT styled because there is no H1 right before it&lt;/h2>\n\nh1 + h2 { font-style: italic;   }\n\n&lt;h1>Big header&lt;/h1> &lt;h2>This one is styled because it is directly adjacent to the H1&lt;/h2> &lt;h2>This one is NOT styled because there is no H1 right before it&lt;/h2></code></pre></div>\n<h4><strong>Pseudo-Classes</strong></h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*XfxhRpW1_nd02miTi4s_PA.png\" alt=\"courtesy of Pseudo-classes — CSS: Cascading Style Sheets | MDN (mozilla.org)\" class=\"graf-image\" />\n<figcaption>courtesy of <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes\" class=\"markup--anchor markup--figure-anchor\">Pseudo-classes — CSS: Cascading Style Sheets | MDN (mozilla.org)</a>\n</figcaption>\n</figure>-   <span id=\"0b5c\">`Pseudo-Class` : Specifies a special state of the seleted element(s) and does not refer to any elements or attributes contained in the DOM.</span>\n-   <span id=\"1c1d\">Format is a `Selector:Pseudo-Class Name` or `A:B`</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a:hover {\nfont-family: \"Roboto Condensed\", sans-serif;\ncolor: #4fc3f7;\ntext-decoration: none;\nborder-bottom: 2px solid #4fc3f7;\n}</code></pre></div>\n<blockquote>\n<p>Some common pseudo-classes that are frequently used are:</p>\n</blockquote>\n<ul>\n<li><span id=\"1aac\"><code class=\"language-text\">active</code> : 'push down', when elements are activated.</span></li>\n<li><span id=\"587a\"><code class=\"language-text\">checked</code> : applies to things like radio buttons or checkbox inputs.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*wg0YeoQ2mZKHWXaa.gif\" class=\"graf-image\" />\n</figure>-   <span id=\"cf58\">`disabled` : any disabled element.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*KmzLwGMr_FsbHF4u.gif\" class=\"graf-image\" />\n</figure>-   <span id=\"1b81\">`first-child` : first element in a group of children/siblings.</span>\n-   <span id=\"eefb\">`focus` : elements that have current focus.</span>\n-   <span id=\"c1da\">`hover` : elements that have cursor hovering over it.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*X7-ym7Relt83npDe.gif\" class=\"graf-image\" />\n</figure>-   <span id=\"128b\">`invalid` : any form elements in an invalid state from client-side form validation.</span>\n-   <span id=\"8fe0\">`last-child` : last element in a group of children/siblings.</span>\n-   <span id=\"fac8\">`not(selector)` : elements that do not match the provided selector.</span>\n-   <span id=\"037a\">`required` : form elements that are required.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Cs9Jf4O0FHQB7Okc.gif\" class=\"graf-image\" />\n</figure>-   <span id=\"2d63\">`valid` : form elements in a valid state.</span>\n-   <span id=\"7eaf\">`visited` : anchor tags of which the user has already visited the URL that the href points to.</span>\n<h4><code class=\"language-text\">Pseudo-Selectors</code></h4>\n<ul>\n<li><span id=\"571c\">Used to create pseudo-elements as children of the elements to which the property applies.</span></li>\n<li><span id=\"8995\"><code class=\"language-text\">::after</code></span></li>\n<li><span id=\"9e9b\"><code class=\"language-text\">::before</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;style>\n  p::before {\n    background-color: lightblue;\n    border-right: 4px solid violet;\n    content: \":-) \";\n    margin-right: 4px;\n    padding-left: 4px;\n  }\n&lt;/style>\n&lt;p>This is the first paragraph&lt;/p>\n&lt;p>This is the second paragraph&lt;/p>\n&lt;p>This is the third paragraph&lt;/p></code></pre></div>\n<ul>\n<li><span id=\"22c4\">Will add some blue smiley faces before the p tag elements.</span></li>\n</ul>\n<h4><strong>CSS Rules</strong></h4>\n<ul>\n<li><span id=\"66b6\"><code class=\"language-text\">CSS Rule</code> : Collection of single or compound selectors, a curly brace, zero or more properties</span></li>\n<li><span id=\"9ec3\"><code class=\"language-text\">CSS Rule Specificity</code> : Sometimes CSS rules will contain multiple elements and may have overlapping properties rules for those same elements - there is an algorithm in CSS that calculates which rule takes precedence.</span></li>\n<li><span id=\"bc57\"><code class=\"language-text\">The Four Number Calculation</code><strong>: listed in increasing order of importance.</strong></span></li>\n<li><span id=\"c45f\">Who has the most IDs? If no one, continue.</span></li>\n<li><span id=\"3aff\">Who has the most classes? If no one, continue.</span></li>\n<li><span id=\"b70b\">Who has the most tags? If no one, continue.</span></li>\n<li><span id=\"59f0\">Last Read in the browser wins.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Z0iSQ0bhAiK5gYhk.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*RpC3i4EQM_HDRyUS.png\" class=\"graf-image\" />\n</figure>\n<style>\n      .box {\n        width: 50px;\n        height: 50px;\n        border: 1px solid black;\n      }\n      .orange {\n        background-color: orange;\n      }\n      .yellow {\n        background-color: yellow;\n        border: 1px solid purple;\n      }\n    </style>\n    <div class=\"box yellow\">\n</div>\n    <div class=\"box orange\">\n</div>\n<ul>\n<li><span id=\"2b20\">Coming back to our example where all the CSS Rules have tied, the last step 4 wins out so our element will have a <code class=\"language-text\">purple border</code>.</span></li>\n</ul>\n<h3>CSS: Type, Properties, and Imports</h3>\n<h4><strong>Typography</strong></h4>\n<ul>\n<li><span id=\"af08\"><code class=\"language-text\">font-family</code> : change the font.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*8298p-Vlu15C-pdw.png\" class=\"graf-image\" />\n</figure>-   <span id=\"9771\">Remember that not all computers have the same fonts on them.</span>\n-   <span id=\"d248\">You can import web fonts via an api by using</span>\n-   <span id=\"8578\">`@import url('https://fonts.googleapis.com/css2?family=Liu+Jian+Mao+Cao&display=swap');` and pasting it st the top of your CSS file.</span>\n-   <span id=\"82b1\">And then reference it in your font-family.</span>\n-   <span id=\"c651\">`font-size` : Changes the size of your font.</span>\n-   <span id=\"a7dc\">Keep in mind the two kind of units CSS uses:</span>\n-   <span id=\"c034\">`Absolute` : `Pixels`, Points, Inches, Centimeters.</span>\n-   <span id=\"7221\">`Relative` : Em, Rem.</span>\n-   <span id=\"80e1\">Em: Calculating the size relative to the previous div (bubbles down)</span>\n-   <span id=\"6c9e\">Rem: Calculates relative to the parent element always.</span>\n-   <span id=\"0f35\">`font-style` : Used to set a font to italics.</span>\n-   <span id=\"20a3\">`font-weight` : Used to make a font bold.</span>\n-   <span id=\"ba17\">`text-align` : Used to align your text to the left, center, or right.</span>\n-   <span id=\"e694\">`text-decoration` : Use to put lines above, through, or under text. Lines can be solid, dashed, or wavy!</span>\n-   <span id=\"0777\">`text-transform` : Used to set text to all lowercase, uppercase, or capitalize all words.</span>\n<h4><strong>Background-Images</strong></h4>\n<ul>\n<li><span id=\"a7cc\">You can use the background-image property to set a background image for an element.</span></li>\n</ul>\n<h3>CSS: Colors, Borders, and Shadows</h3>\n<h4><strong>Colors</strong></h4>\n<ul>\n<li><span id=\"6887\">You can set colors in CSS in three popular ways: by name, by hexadecimal RGB value, and by their decimal RGB value.</span></li>\n<li><span id=\"1d78\">rgba() is used to make an rbg value more transparent, the <code class=\"language-text\">a</code> is used to specify the <code class=\"language-text\">alpha channel</code>.</span></li>\n<li><span id=\"a422\"><strong>Color</strong> : Property used to change the color of text.</span></li>\n<li><span id=\"6bcb\"><strong>Background-Color</strong> : Property to change the backgrounf color of an element.</span></li>\n</ul>\n<h4><strong>Borders</strong></h4>\n<ul>\n<li><span id=\"cce0\">Borders take three values: The width of the border, the style (i.e. solid, dotted, dashed), color of the border.</span></li>\n</ul>\n<h4><strong>Shadows</strong></h4>\n<ul>\n<li><span id=\"6391\">There are two kinds of shadows in CSS: <code class=\"language-text\">box shadows</code> and <code class=\"language-text\">text shadows</code>.</span></li>\n<li><span id=\"7fc1\">Box refers to HTML elements.</span></li>\n<li><span id=\"8c59\">Text refers to text.</span></li>\n<li><span id=\"266d\">Shadows take values such as, the horizontal &#x26; vertical offsets of the shadow, the blur radius of the shadow, the spread radius, and of course the colors.</span></li>\n</ul>\n<h3>My Blog</h3>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonz-blog.netlify.app/\">\n<strong>Web-Dev-Hub</strong>\n<br/>\n<p><em>my resource sharing and blog site ... centered mostly on web development and just a bit of audio production / generally…</em>bgoonz-blog.netlify.app</a>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<h3>Grid Cheat Sheet</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*8cBZz0yj-ND3af2uh7J-dw.png\" class=\"graf-image\" />\n</figure>"},{"url":"/blog/beginners-guide-to-python/","relativePath":"blog/beginners-guide-to-python.md","relativeDir":"blog","base":"beginners-guide-to-python.md","name":"beginners-guide-to-python","frontmatter":{"title":"Beginners Guide To Python","template":"post","subtitle":"It has simple, clean syntax, object encapsulation, good library support","excerpt":"Article on basic web development setup… ","date":"2022-05-11T00:02:02.952Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-language.jpg?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-language.jpg?raw=true","image_position":"right","author":"src/data/authors/im.yaml","categories":["src/data/categories/py.yaml"],"tags":["src/data/tags/🖇-🖇-🖇-🖇.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/webdev-setup.md","src/pages/blog/beginners-guide-to-python.md","src/pages/blog/data-structures-algorithms-resources.md"],"cmseditable":true},"html":"<h1>Beginners Guide To Python</h1>\n<p>My favorite language for maintainability is Python. It has simple, clean syntax, object encapsulation, good library support, and optional…</p>\n<hr>\n<h3>Beginners Guide To Python</h3>\n<h4>My favorite language for maintainability is Python. It has simple, clean syntax, object encapsulation, good library support, and optional named parameters.</h4>\n<blockquote>\n<p>Bram Cohen</p>\n</blockquote>\n<h4>Article on basic web development setup… it is geared towards web but VSCode is an incredibly versatile editor and this stack really could suit just about anyone working in the field of computer science.</h4>\n<p><strong>A list of all of my articles to link to future posts</strong>\n<br/></p>\n<p><em>You should probably skip this one… seriously it's just for internal use!</em>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<a href=\"https://golden-lobe-519.notion.site/PYTHON-cb857bd3fa4b4940928842a94dce856d\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://golden-lobe-519.notion.site/PYTHON-cb857bd3fa4b4940928842a94dce856d\">\n<strong>PYTHON</strong>\n<br/>\n<p><em>Keywords: ***and del for is raise assert elif from lambda return break else global not try class except if or while…</em>golden-lobe-519.notion.site</a>\n<a href=\"https://golden-lobe-519.notion.site/PYTHON-cb857bd3fa4b4940928842a94dce856d\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*per3wJrNyChrgJtUBySo1Q.png\" class=\"graf-image\" />\n</figure>\n<a href=\"https://levelup.gitconnected.com/basic-web-development-environment-setup-9f36c3f15afe\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://levelup.gitconnected.com/basic-web-development-environment-setup-9f36c3f15afe\">\n<strong>Basic Web Development Environment Setup</strong>\n<br/>\n<p><em>Windows Subsystem for Linux (WSL) and Ubuntu</em>levelup.gitconnected.com</a>\n<a href=\"https://levelup.gitconnected.com/basic-web-development-environment-setup-9f36c3f15afe\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<h3>Related Articles:</h3>\n<a href=\"https://levelup.gitconnected.com/beginner-python-problems-solutions-dd631e9c3a9f\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://levelup.gitconnected.com/beginner-python-problems-solutions-dd631e9c3a9f\">\n<strong>Python Problems &amp; Solutions For Beginners</strong>\n<br/>\n<p><em>Introduction to python taught through example problems. Solutions are included in embedded repl.it at the bottom of…</em>levelup.gitconnected.com</a>\n<a href=\"https://levelup.gitconnected.com/beginner-python-problems-solutions-dd631e9c3a9f\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<a href=\"https://medium.com/webdevhub/notes-i-wish-i-had-when-i-started-learning-python-16ce4244be12\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://medium.com/webdevhub/notes-i-wish-i-had-when-i-started-learning-python-16ce4244be12\">\n<strong>Notes I Wish I Had When I Started Learning Python</strong>\n<br/>\n<p><em>Plus resources for learning data structures and algorithms in python at the bottom of this article!</em>medium.com</a>\n<a href=\"https://medium.com/webdevhub/notes-i-wish-i-had-when-i-started-learning-python-16ce4244be12\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<a href=\"https://bryanguner.medium.com/getting-comfortable-with-python-1371581a4971\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bryanguner.medium.com/getting-comfortable-with-python-1371581a4971\">\n<strong>Getting Comfortable With Python:</strong>\n<br/>\n<p><em>An introduction by example</em>\n<a href=\"https://bryanguner.medium.com/getting-comfortable-with-python-1371581a4971\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<a href=\"https://levelup.gitconnected.com/python-study-guide-for-a-native-javascript-developer-5cfdf3d2bdfb\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://levelup.gitconnected.com/python-study-guide-for-a-native-javascript-developer-5cfdf3d2bdfb\">\n<strong>Python Study Guide for a JavaScript Programmer</strong>\n<br/>\n<p><em>A guide to commands in Python from what you know in JavaScript</em>levelup.gitconnected.com</a>\n<a href=\"https://levelup.gitconnected.com/python-study-guide-for-a-native-javascript-developer-5cfdf3d2bdfb\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<h3>The Repository &#x26; Live Site Behind This Article:</h3>\n<h3>About Python(Taken From Tutorial Page Of Docs):</h3>\n<p><a href=\"https://docs.python.org/3/tutorial/appetite.html\" class=\"markup--anchor markup--p-anchor\">Python enables programs to be written compactly and readably. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for several reasons:</a></p>\n<ul>\n<li><span id=\"894d\">the high-level data types allow you to express complex operations in a single statement;</span></li>\n<li><span id=\"48ef\">statement grouping is done by indentation instead of beginning and ending brackets;</span></li>\n<li><span id=\"f361\">no variable or argument declarations are necessary.</span></li>\n</ul>\n<h3>Installing Python:</h3>\n<h3>Windows</h3>\n<p>To determine if your Windows computer already has Python 3:</p>\n<ol>\n<li><span id=\"4838\">Open a command prompt by entering command prompt in the Windows 10 search box and selecting the Command Prompt App in the Best match section of the results.</span></li>\n<li><span id=\"f6bc\">Enter the following command and then select the Enter key:</span></li>\n<li><span id=\"24ec\">ConsoleCopy</span></li>\n</ol>\n<p><code class=\"language-text\">python --version</code></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*59V2ZNbyJfsdGR2N20PM7w.png\" class=\"graf-image\" />\n</figure>1.  <span id=\"e87f\">Running `python --version` may not return a value, or may return an error message stating *'python' is not recognized as an internal or external command, operable program or batch file.* This indicates Python is not installed on your Windows system.</span>\n2.  <span id=\"7c04\">If you see the word `Python` with a set of numbers separated by `.` characters, some version of Python is installed.</span>\n<h4>i.e.</h4>\n<blockquote>\n<p><code class=\"language-text\">Python 3.8.0</code></p>\n</blockquote>\n<p><strong>As long as the first number is</strong> <code class=\"language-text\">3</code>, you have Python 3 installed.</p>\n<blockquote>\n<p>Download Page: <a href=\"https://www.python.org/downloads/release/python-395/\" class=\"markup--anchor markup--blockquote-anchor\">https://www.python.org/downloads/release/python-395/</a></p>\n</blockquote>\n<blockquote>\n<p>Download Link: <a href=\"https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe\" class=\"markup--anchor markup--blockquote-anchor\">https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe</a></p>\n</blockquote>\n<hr>\n<h3>Python</h3>\n<ul>\n<li><span id=\"c462\">Python is an interpreted, high-level and general-purpose, dynamically typed programming language</span></li>\n<li><span id=\"74e1\">It is also Object oriented, modular oriented and a scripting language.</span></li>\n<li><span id=\"6e0e\">In Python, everything is considered as an Object.</span></li>\n<li><span id=\"490d\">A python file has an extension of .py</span></li>\n<li><span id=\"2bd5\">Python follows Indentation to separate code blocks instead of flower brackets({}).</span></li>\n<li><span id=\"6434\">We can run a python file by the following command in cmd(Windows) or shell(mac/linux).</span></li>\n<li><span id=\"b76b\"><code class=\"language-text\">python &lt;filename.py></code></span></li>\n</ul>\n<h4>By default, the python doesn't require any imports to run a python file.</h4>\n<h3>Create and execute a program</h3>\n<ol>\n<li><span id=\"d7b7\">Open up a terminal/cmd</span></li>\n<li><span id=\"a7a7\">Create the program: nano/cat > <a href=\"http://nameprogram.py/\" class=\"markup--anchor markup--li-anchor\">nameProgram.py</a>\n</span></li>\n<li><span id=\"aace\">Write the program and save it</span></li>\n<li><span id=\"b439\">python <a href=\"http://nameprogram.py/\" class=\"markup--anchor markup--li-anchor\">nameProgram.py</a>\n</span></li>\n</ol>\n<h3>Basic Datatypes</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*LDLNGnpgmyeWojLU_mKKJw.png\" class=\"graf-image\" />\n</figure>### Keywords\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*rMzTksSg1jUZm2ECvvzO_g.png\" class=\"graf-image\" />\n</figure>### Operators\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*3ud99ZpJ20AhhApKhjvlqQ.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*_Chk6-fWKs-i52q2Zx0ZTw.png\" class=\"graf-image\" />\n</figure>### Basic Data Structures\n<h3>List</h3>\n<ul>\n<li><span id=\"a311\">List is a collection which is ordered and changeable. Allows duplicate members.</span></li>\n<li><span id=\"cd75\">Lists are created using square brackets:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thislist = [\"apple\", \"banana\", \"cherry\"]</code></pre></div>\n<ul>\n<li><span id=\"8afd\">List items are ordered, changeable, and allow duplicate values.</span></li>\n<li><span id=\"668d\">List items are indexed, the first item has index <code class=\"language-text\">[0]</code>, the second item has index <code class=\"language-text\">[1]</code> etc.</span></li>\n<li><span id=\"b8c7\">The list is changeable, meaning that we can change, add, and remove items in a list after it has been created.</span></li>\n<li><span id=\"b5f4\">To determine how many items a list has, use the <code class=\"language-text\">len()</code> function.</span></li>\n<li><span id=\"7dff\">A list can contain different data types:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">list1 = [\"abc\", 34, True, 40, \"male\"]</code></pre></div>\n<ul>\n<li><span id=\"9e81\">It is also possible to use the list() constructor when creating a new list</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thislist = list((\"apple\", \"banana\", \"cherry\"))  # note the double round-brackets</code></pre></div>\n<h3>Tuple</h3>\n<ul>\n<li><span id=\"50ea\">Tuple is a collection which is ordered and unchangeable. Allows duplicate members.</span></li>\n<li><span id=\"14ac\">A tuple is a collection which is ordered and unchangeable.</span></li>\n<li><span id=\"8cde\">Tuples are written with round brackets.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thistuple = (\"apple\", \"banana\", \"cherry\")</code></pre></div>\n<ul>\n<li><span id=\"3e58\">Tuple items are ordered, unchangeable, and allow duplicate values.</span></li>\n<li><span id=\"2f5a\">Tuple items are indexed, the first item has index <code class=\"language-text\">[0]</code>, the second item has index <code class=\"language-text\">[1]</code> etc.</span></li>\n<li><span id=\"6f87\">When we say that tuples are ordered, it means that the items have a defined order, and that order will not change.</span></li>\n<li><span id=\"709a\">Tuples are unchangeable, meaning that we cannot change, add or remove items after the tuple has been created.</span></li>\n<li><span id=\"134b\">Since tuple are indexed, tuples can have items with the same value:</span></li>\n<li><span id=\"2720\">Tuples allow duplicate values:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thistuple = (\"apple\", \"banana\", \"cherry\", \"apple\", \"cherry\")</code></pre></div>\n<ul>\n<li><span id=\"ddae\">To determine how many items a tuple has, use the <code class=\"language-text\">len()</code>function:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thistuple = (\"apple\", \"banana\", \"cherry\")\nprint(len(thistuple))</code></pre></div>\n<ul>\n<li><span id=\"2723\">To create a tuple with only one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thistuple = (\"apple\",)\nprint(type(thistuple))\n\n#NOT a tuple\nthistuple = (\"apple\")\nprint(type(thistuple))</code></pre></div>\n<ul>\n<li><span id=\"4556\">It is also possible to use the tuple() constructor to make a tuple.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thistuple = tuple((\"apple\", \"banana\", \"cherry\")) # note the double round-brackets\nprint(thistuple)</code></pre></div>\n<h3>Set</h3>\n<ul>\n<li><span id=\"1991\">Set is a collection which is unordered and unindexed. No duplicate members.</span></li>\n<li><span id=\"d108\">A set is a collection which is both unordered and unindexed.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thisset = {\"apple\", \"banana\", \"cherry\"}</code></pre></div>\n<ul>\n<li><span id=\"4098\">Set items are unordered, unchangeable, and do not allow duplicate values.</span></li>\n<li><span id=\"b4d0\">Unordered means that the items in a set do not have a defined order.</span></li>\n<li><span id=\"d081\">Set items can appear in a different order every time you use them, and cannot be referred to by index or key.</span></li>\n<li><span id=\"4f53\">Sets are unchangeable, meaning that we cannot change the items after the set has been created.</span></li>\n<li><span id=\"812b\">Duplicate values will be ignored.</span></li>\n<li><span id=\"3ac9\">To determine how many items a set has, use the <code class=\"language-text\">len()</code> method.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thisset = {\"apple\", \"banana\", \"cherry\"}\n\nprint(len(thisset))</code></pre></div>\n<ul>\n<li><span id=\"b34e\">Set items can be of any data type:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">set1 = {\"apple\", \"banana\", \"cherry\"}\nset2 = {1, 5, 7, 9, 3}\nset3 = {True, False, False}\nset4 = {\"abc\", 34, True, 40, \"male\"}</code></pre></div>\n<ul>\n<li><span id=\"2a23\">It is also possible to use the <code class=\"language-text\">set()</code> constructor to make a set.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thisset = set((\"apple\", \"banana\", \"cherry\")) # note the double round-brackets</code></pre></div>\n<h3>Dictionary</h3>\n<ul>\n<li><span id=\"3c14\">Dictionary is a collection which is unordered and changeable. No duplicate members.</span></li>\n<li><span id=\"cf8a\">Dictionaries are used to store data values in key:value pairs.</span></li>\n<li><span id=\"bbb2\">Dictionaries are written with curly brackets, and have keys and values:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thisdict = {\n  \"brand\": \"Ford\",\n  \"model\": \"Mustang\",\n  \"year\": 1964\n}</code></pre></div>\n<ul>\n<li><span id=\"7f11\">Dictionary items are presented in key:value pairs, and can be referred to by using the key name.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thisdict = {\n  \"brand\": \"Ford\",\n  \"model\": \"Mustang\",\n  \"year\": 1964\n}\nprint(thisdict[\"brand\"])</code></pre></div>\n<ul>\n<li><span id=\"8700\">Dictionaries are changeable, meaning that we can change, add or remove items after the dictionary has been created.</span></li>\n<li><span id=\"ea7e\">Dictionaries cannot have two items with the same key.</span></li>\n<li><span id=\"1ad4\">Duplicate values will overwrite existing values.</span></li>\n<li><span id=\"7582\">To determine how many items a dictionary has, use the <code class=\"language-text\">len()</code> function.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(len(thisdict))</code></pre></div>\n<ul>\n<li><span id=\"305d\">The values in dictionary items can be of any data type</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">thisdict = {\n  \"brand\": \"Ford\",\n  \"electric\": False,\n  \"year\": 1964,\n  \"colors\": [\"red\", \"white\", \"blue\"]\n}</code></pre></div>\n<h3>Conditional branching</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if condition:\n        pass\n    elif condition2:\n        pass\n    else:\n        pass</code></pre></div>\n<h3>Loops</h3>\n<p>Python has two primitive loop commands:</p>\n<ol>\n<li><span id=\"cd2b\">while loops</span></li>\n<li><span id=\"f858\">for loops</span></li>\n</ol>\n<h4>While loop</h4>\n<ul>\n<li><span id=\"e9e1\">With the <code class=\"language-text\">while</code> loop we can execute a set of statements as long as a condition is true.</span></li>\n<li><span id=\"ef71\">Example: Print i as long as i is less than 6</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">i = 1\nwhile i &lt; 6:\n  print(i)\n  i += 1</code></pre></div>\n<ul>\n<li><span id=\"5f4a\">The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1.</span></li>\n<li><span id=\"2dce\">With the <code class=\"language-text\">break</code> statement we can stop the loop even if the while condition is true</span></li>\n<li><span id=\"371e\">With the continue statement we can stop the current iteration, and continue with the next.</span></li>\n<li><span id=\"3dcf\">With the else statement we can run a block of code once when the condition no longer is true.</span></li>\n</ul>\n<h4>For loop</h4>\n<ul>\n<li><span id=\"0fa5\">A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).</span></li>\n<li><span id=\"871e\">This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.</span></li>\n<li><span id=\"ca9c\">With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fruits = [\"apple\", \"banana\", \"cherry\"]\nfor x in fruits:\n  print(x)</code></pre></div>\n<ul>\n<li><span id=\"19c1\">The for loop does not require an indexing variable to set beforehand.</span></li>\n<li><span id=\"fb47\">To loop through a set of code a specified number of times, we can use the range() function.</span></li>\n<li><span id=\"f32d\">The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.</span></li>\n<li><span id=\"b8d4\">The range() function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: range(2, 30, 3).</span></li>\n<li><span id=\"cca5\">The else keyword in a for loop specifies a block of code to be executed when the loop is finished.\nA nested loop is a loop inside a loop.</span></li>\n<li><span id=\"acbb\">The \"inner loop\" will be executed one time for each iteration of the \"outer loop\":</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">adj = [\"red\", \"big\", \"tasty\"]\nfruits = [\"apple\", \"banana\", \"cherry\"]\n\nfor x in adj:\n  for y in fruits:\n    print(x, y)</code></pre></div>\n<ul>\n<li><span id=\"1bdd\">for loops cannot be empty, but if you for some reason have a for loop with no content, put in the pass statement to avoid getting an error.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for x in [0, 1, 2]:\n  pass</code></pre></div>\n<h3>Function definition</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def function_name():\n    return</code></pre></div>\n<h3>Function call</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function_name()</code></pre></div>\n<ul>\n<li><span id=\"a1ca\">We need not to specify the return type of the function.</span></li>\n<li><span id=\"89e4\">Functions by default return <code class=\"language-text\">None</code></span></li>\n<li><span id=\"7041\">We can return any datatype.</span></li>\n</ul>\n<hr>\n<h3>Python Syntax</h3>\n<p>Python syntax was made for readability, and easy editing. For example, the python language uses a <code class=\"language-text\">:</code> and indented code, while javascript and others generally use <code class=\"language-text\">{}</code> and indented code.</p>\n<h3>First Program</h3>\n<p>Lets create a <a href=\"https://repl.it/languages/python3\" class=\"markup--anchor markup--p-anchor\">python 3</a> repl, and call it <em>Hello World</em>. Now you have a blank file called <em>main.py</em>. Now let us write our first line of code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print('Hello world!')</code></pre></div>\n<blockquote>\n<p><em>Brian Kernighan actually wrote the first \"Hello, World!\" program as part of the documentation for the BCPL programming language developed by Martin Richards.</em></p>\n</blockquote>\n<p>Now, press the run button, which obviously runs the code. If you are not using replit, this will not work. You should research how to run a file with your text editor.</p>\n<h3>Command Line</h3>\n<p>If you look to your left at the console where hello world was just printed, you can see a <code class=\"language-text\">></code>, <code class=\"language-text\">>>></code>, or <code class=\"language-text\">$</code> depending on what you are using. After the prompt, try typing a line of code.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Python 3.6.1 (default, Jun 21 2017, 18:48:35)\n[GCC 4.9.2] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n> print('Testing command line')\nTesting command line\n> print('Are you sure this works?')\nAre you sure this works?\n></code></pre></div>\n<p>The command line allows you to execute single lines of code at a time. It is often used when trying out a new function or method in the language.</p>\n<h3>New: Comments!</h3>\n<p>Another cool thing that you can generally do with all languages, are comments. In python, a comment starts with a <code class=\"language-text\">#</code>. The computer ignores all text starting after the <code class=\"language-text\">#</code>.</p>\n<p><code class=\"language-text\"># Write some comments!</code></p>\n<p>If you have a huge comment, do <strong>not</strong> comment all the 350 lines, just put <code class=\"language-text\">'''</code> before it, and <code class=\"language-text\">'''</code> at the end. Technically, this is not a comment but a string, but the computer still ignores it, so we will use it.</p>\n<h3>New: Variables!</h3>\n<p>Unlike many other languages, there is no <code class=\"language-text\">var</code>, <code class=\"language-text\">let</code>, or <code class=\"language-text\">const</code> to declare a variable in python. You simply go <code class=\"language-text\">name = 'value'</code>.</p>\n<p>Remember, there is a difference between integers and strings. <em>Remember: String =</em> <code class=\"language-text\">\"\"</code><em>.</em> To convert between these two, you can put an int in a <code class=\"language-text\">str()</code> function, and a string in a <code class=\"language-text\">int()</code> function. There is also a less used one, called a float. Mainly, these are integers with decimals. Change them using the <code class=\"language-text\">float()</code> command.</p>\n<p><a href=\"https://repl.it/@bgoonz/second-scr?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com\" class=\"markup--anchor markup--p-anchor\">https://repl.it/@bgoonz/second-scr?lite=true&#x26;amp;referrer=https%3A%2F%2F</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">x = 5\nx = str(x)\nb = '5'\nb = int(b)\nprint('x = ', x, '; b = ', str(b), ';') # => x = 5; b = 5;</code></pre></div>\n<p>Instead of using the <code class=\"language-text\">,</code> in the print function, you can put a <code class=\"language-text\">+</code> to combine the variables and string.</p>\n<h3>Operators</h3>\n<p>There are many operators in python:</p>\n<ul>\n<li><span id=\"d553\"><code class=\"language-text\">+</code></span></li>\n<li><span id=\"a1b3\"><code class=\"language-text\">-</code></span></li>\n<li><span id=\"f09c\"><code class=\"language-text\">/</code></span></li>\n<li><span id=\"cd1e\"><code class=\"language-text\">*</code>\nThese operators are the same in most languages, and allow for addition, subtraction, division, and multiplicaiton.\nNow, we can look at a few more complicated ones:</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*oVIDxWdgJXoIt7CI.jpg\" class=\"graf-image\" />\n</figure>*simpleops.py*\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">x = 4\na = x + 1\na = x - 1\na = x * 2\na = x / 2</code></pre></div>\n<p>You should already know everything shown above, as it is similar to other languages. If you continue down, you will see more complicated ones.</p>\n<p><em>complexop.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a += 1\na -= 1\na *= 2\na /= 2</code></pre></div>\n<p>The ones above are to edit the current value of the variable.\nSorry to JS users, as there is no <code class=\"language-text\">i++;</code> or anything.</p>\n<h3>Fun Fact: The python language was named after Monty Python.</h3>\n<p>If you really want to know about the others, view <a href=\"https://www.tutorialspoint.com/python/python_basic_operators.htm\" class=\"markup--anchor markup--p-anchor\">Py Operators</a></p>\n<h3>More Things With Strings</h3>\n<p>Like the title?\nAnyways, a <code class=\"language-text\">'</code> and a <code class=\"language-text\">\"</code> both indicate a string, but <strong>do not combine them!</strong></p>\n<p><em>quotes.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">x = 'hello' # Good\nx = \"hello\" # Good\nx = \"hello' # ERRORRR!!!</code></pre></div>\n<p><em>slicing.py</em></p>\n<h3>String Slicing</h3>\n<p>You can look at only certain parts of the string by slicing it, using <code class=\"language-text\">[num:num]</code>.\nThe first number stands for how far in you go from the front, and the second stands for how far in you go from the back.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">x = 'Hello everybody!'\nx[1] # 'e'\nx[-1] # '!'\nx[5] # ' '\nx[1:] # 'ello everybody!'\nx[:-1] # 'Hello everybod'\nx[2:-3] # 'llo everyb'</code></pre></div>\n<h3>Methods and Functions</h3>\n<p>Here is a list of functions/methods we will go over:</p>\n<ul>\n<li><span id=\"aaaa\"><code class=\"language-text\">.strip()</code></span></li>\n<li><span id=\"b3ee\"><code class=\"language-text\">len()</code></span></li>\n<li><span id=\"c5cc\"><code class=\"language-text\">.lower()</code></span></li>\n<li><span id=\"3466\"><code class=\"language-text\">.upper()</code></span></li>\n<li><span id=\"a06d\"><code class=\"language-text\">.replace()</code></span></li>\n<li><span id=\"57b6\"><code class=\"language-text\">.split()</code></span></li>\n</ul>\n<a href=\"https://trinket.io/python3/2b693977e7\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://trinket.io/python3/2b693977e7\">\n<strong>Put Python Anywhere on the Web</strong>\n<br/>\n<p><em>Python in the browser. No installation required.</em>trinket.io</a>\n<a href=\"https://trinket.io/python3/2b693977e7\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a></p>\n<h3>New: Input()</h3>\n<p>Input is a function that gathers input entered from the user in the command line. It takes one optional parameter, which is the users prompt.</p>\n<p><em>inp.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print('Type something: ')\nx = input()\nprint('Here is what you said: ', x)</code></pre></div>\n<p>If you wanted to make it smaller, and look neater to the user, you could do…</p>\n<p><em>inp2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print('Here is what you said: ', input('Type something: '))</code></pre></div>\n<p>Running:\n<em>inp.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Type something:\nHello World\nHere is what you said: Hello World</code></pre></div>\n<p><em>inp2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Type something: Hello World\nHere is what you said: Hello World</code></pre></div>\n<h3>New: Importing Modules</h3>\n<p>Python has created a lot of functions that are located in other .py files. You need to import these <strong>modules</strong> to gain access to the,, You may wonder why python did this. The purpose of separate modules is to make python faster. Instead of storing millions and millions of functions, , it only needs a few basic ones. To import a module, you must write <code class=\"language-text\">input &lt;modulename></code>. Do not add the .py extension to the file name. In this example , we will be using a python created module named random.</p>\n<p><em>module.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random</code></pre></div>\n<p>Now, I have access to all functions in the random.py file. To access a specific function in the module, you would do <code class=\"language-text\">&lt;module>.&lt;function></code>. For example:</p>\n<p><em>module2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random\nprint(random.randint(3,5)) # Prints a random number between 3 and 5</code></pre></div>\n<blockquote>\n<p><em>Pro Tip:\nDo</em> <code class=\"language-text\">from random import randint</code> <em>to not have to do</em> <code class=\"language-text\">random.randint()</code><em>, just</em> <code class=\"language-text\">randint()</code>_\nTo import all functions from a module, you could do_ <code class=\"language-text\">from random import *</code></p>\n</blockquote>\n<h3>New: Loops!</h3>\n<p>Loops allow you to repeat code over and over again. This is useful if you want to print Hi with a delay of one second 100 times.</p>\n<h4><code class=\"language-text\">for</code> Loop</h4>\n<p>The for loop goes through a list of variables, making a seperate variable equal one of the list every time.\nLet's say we wanted to create the example above.</p>\n<p><em>loop.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from time import sleep\nfor i in range(100):\n     print('Hello')\n     sleep(.3)</code></pre></div>\n<p>This will print Hello with a .3 second delay 100 times. This is just one way to use it, but it is usually used like this:</p>\n<p><em>loop2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import time\nfor number in range(100):\n     print(number)\n     time.sleep(.1)</code></pre></div>\n<p><a href=\"https://storage.googleapis.com/replit/images/1539649280875_37d22e6d49e8e8fbc453631def345387.pn\" class=\"markup--anchor markup--p-anchor\">https://storage.googleapis.com/replit/images/1539649280875_37d22e6d49e8e8fbc453631def345387.pn</a></p>\n<h4><code class=\"language-text\">while</code> Loop</h4>\n<p>The while loop runs the code while something stays true. You would put <code class=\"language-text\">while &lt;expression></code>. Every time the loop runs, it evaluates if the expression is True. It it is, it runs the code, if not it continues outside of the loop. For example:</p>\n<p><em>while.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">while True: # Runs forever\n     print('Hello World!')</code></pre></div>\n<p>Or you could do:</p>\n<p><em>while2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random\nposition = '&lt;placeholder>'\nwhile position != 1: # will run at least once\n    position = random.randint(1, 10)\n    print(position)</code></pre></div>\n<h3>New: <code class=\"language-text\">if</code> Statement</h3>\n<p>The if statement allows you to check if something is True. If so, it runs the code, if not, it continues on. It is kind of like a while loop, but it executes <strong>only once</strong>. An if statement is written:</p>\n<p><em>if.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random\nnum = random.randint(1, 10)\nif num == 3:\n     print('num is 3. Hooray!!!')\nif num > 5:\n     print('Num is greater than 5')\nif num == 12:\n     print('Num is 12, which means that there is a problem with the python language, see if you can figure it out. Extra credit if you can figure it out!')</code></pre></div>\n<p>Now, you may think that it would be better if you could make it print only one message. Not as many that are True. You can do that with an <code class=\"language-text\">elif</code> statement:</p>\n<p><em>elif.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random\nnum = random.randint(1, 10)\nif num == 3:\n    print('Num is three, this is the only msg you will see.')\nelif num > 2:\n    print('Num is not three, but is greater than 1')</code></pre></div>\n<p>Now, you may wonder how to run code if none work. Well, there is a simple statement called <code class=\"language-text\">else:</code></p>\n<p><em>else.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random\nnum = random.randint(1, 10)\nif num == 3:\n    print('Num is three, this is the only msg you will see.')\nelif num > 2:\n    print('Num is not three, but is greater than 1')\nelse:\n    print('No category')</code></pre></div>\n<h3>New: Functions (<code class=\"language-text\">def</code>)</h3>\n<p>So far, you have only seen how to use functions other people have made. Let use the example that you want to print the a random number between 1 and 9, and print different text every time.\nIt is quite tiring to type:</p>\n<p>Characters: 389</p>\n<p><em>nofunc.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random\nprint(random.randint(1, 9))\nprint('Wow that was interesting.')\nprint(random.randint(1, 9))\nprint('Look at the number above ^')\nprint(random.randint(1, 9))\nprint('All of these have been interesting numbers.')\nprint(random.randint(1, 9))\nprint(\"these random.randint's are getting annoying to type\")\nprint(random.randint(1, 9))\nprint('Hi')\nprint(random.randint(1, 9))\nprint('j')</code></pre></div>\n<p>Now with functions, you can seriously lower the amount of characters:</p>\n<p>Characters: 254</p>\n<p><em>functions.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random\ndef r(t):\n     print(random.randint(1, 9))\n     print(t)\nr('Wow that was interesting.')\nr('Look at the number above ^')\nr('All of these have been interesting numbers.')\nr(\"these random.randint's are getting annoying to type\")\nr('Hi')\nr('j')</code></pre></div>\n<hr>\n<h3>Project Based Learning:</h3>\n<p>The following is a modified version of a tutorial posted By: <a href=\"https://replit.com/@InvisibleOne\" class=\"markup--anchor markup--p-anchor\">InvisibleOne</a></p>\n<p>I would cite the original tutorial it's self but at the time of this writing I can no longer find it on his repl.it profile and so the only reference I have are my own notes from following the tutorial when I first found it.</p>\n<h3>1. Adventure Story</h3>\n<p>The first thing you need with an adventure story is a great storyline, something that is exciting and fun. The idea is, that at each pivotal point in the story, you give the player the opportunity to make a choice.\nFirst things first, let's import the stuff that we need, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import os   #very useful for clearing the screen\nimport random</code></pre></div>\n<p>Now, we need some variables to hold some of the player data.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">name = input(\"Name Please:  \") #We'll use this to get the name from the user\nnickname = input(\"Nickname: \")</code></pre></div>\n<p>Ok, now we have the player's name and nickname, let's welcome them to the game</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Hello and welcome \" + name)</code></pre></div>\n<p>Now for the story. The most important part of all stories is the introduction, so let's print our introduction</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Long ago, there was a magical meal known as Summuh and Spich Atip\") #We can drop a line by making a new print statement, or we can use the escape code \\n\nprint(\"It was said that this meal had the power to save lives, restore peace, and stop evil\\nBecuase it was so powerful, it was hidden away on a mountain that could not be climbed\\nBut it's power brought unwanted attention, and a great war broke out.\\nFinally, the leaders of the good side chose a single hero to go and find the Summah and Spich Atip, that hero was \" + name + \"\\n so \" + nickname + ' headed out to find this great power, and stop the war…')</code></pre></div>\n<p>Now, we'll give the player their first choice</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"After hiking through the wastelands for a long time, you come to a massive ravine, there is only a single way across\\nA rickety old bridge, taking that could be very dangerous, but… maybe you could jump across?\")\nchoice1 = input(\"[1]  Take the bridge     [2] Try and jump over\")\n#Now we check to see what the player chose\nIf choice1 == '1':\n  print(\"You slowly walk across the bride, it creakes ominously, then suddenly breaks! You flail through the air before hitting the ground a thousand feet below. Judging by the fact that you hit the ground with the equivalent force of being hit by a cement truck moving at 125 miles an hour, you are dead…\")\n  #The player lost, so now we'll boot them out of the program with the exit command\n  exit()\n#Then we check to see if they made the other choice, we can do with with else if, written as elif\nelif choice1 == '2':\n  print(\"You make the jump! You see a feather hit the bridge, the weight breakes it and sends it to the bottom of the ravine\\nGood thing you didn't use that bridge.\")\n#Now we can continue the story\nprint(\"A few more hours of travel and you come to the unclimbable mountain.\")\nchoice2 == input(\"[1]   Give up    [2]    Try and climb the mountain\")\nif choice2 == '1':\n  print(\"You gave up and lost…\")\n  #now we exit them again\n  exit()\nelif choice2 == '1':\n  print(\"you continue up the mountain. Climbing is hard, but finally you reach the top.\\nTo your surprise there is a man standing at the top of the mountain, he is very old.\")\n  print(\"Old Man: Hey \" + nickname)\n  print(\"You: How do you know my name!?!\")\n  print(\"Old Man: Because you have a name tag on…\")\n  print(\"You: Oh, well, were is the Summuh and Spich Atip?\")\n  print(\"Old Man: Summuh and Spich Atip? You must mean the Pita Chips and Hummus\")\n  print(\"You: Pita…chips…humus, what power do those have?\")\n  print(\"Old Man: Pretty simple kid, their organic…\")\n  #Now let's clear the screen\n  os.system('clear')\n  print(\"YOU WON!!!\")</code></pre></div>\n<p>There you have it, a pretty simple choose your own ending story. You can make it as complex or uncomplex as you like.</p>\n<h3>2. TEXT ENCODER</h3>\n<p>Ever make secret messages as a kid? I used to. Anyways, here's the way you can make a program to encode messages! It's pretty simple. First things first, let's get the message the user wants to encode, we'll use input() for that:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">message = input(\"Message you would like encoded: \")</code></pre></div>\n<p>Now we need to split that string into a list of characters, this part is a bit more complicated.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#We'll make a function, so we can use it later\ndef split(x):\n  return (char for char in x)\n#now we'll call this function with our text\nL_message = message.lower() #This way we can lower any of their input\nencode = split(l_message)</code></pre></div>\n<p>Now we need to convert the characters into code, well do this with a for loop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">out = []\nfor x in encode:\n  if x == 'a':\n    out.append('1')\n  elif x == 'b':\n    out.append('2')\n#And we'll continue on though this with each letter of the alphabet</code></pre></div>\n<p>Once we've encoded the text, we'll print it back for the user</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">x = ' '.join(out)\n#this will turn out into a string that we can print\nprint(x)</code></pre></div>\n<p>And if you want to decode something, it is this same process but in reverse!</p>\n<h3>3. Guess my Number</h3>\n<p>Number guessing games are fun and pretty simple, all you need are a few loops. To start, we need to import random.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random</code></pre></div>\n<p>That is pretty simple. Now we'll make a list with the numbers were want available for the game</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">num_list = [1,2,3,4,5,6,7,8,9,10]</code></pre></div>\n<p>Next, we get a random number from the list</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">num = random.choice(num_list)</code></pre></div>\n<p>Now, we need to ask the user for input, we'll to this with a while loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">while True:\n  # We could use guess = input(\"What do you think my number is?   \"), but that would produce a string, and numbers are integers, so we'll convert the input into an integer\n  guess = int(input(\"What do you think my number is?   \"))\n  #Next, we'll check if that number is equal to the number we picked\n  if guess == num:\n    break   #this will remove us from the loop, so we can display the win message\n  else:\n    print(\"Nope, that isn't it\")\n#outside our loop, we'll have the win message that is displayed if the player gets the correct number.\nprint(\"You won!\")</code></pre></div>\n<p>Have fun with this!</p>\n<h3>4. Notes</h3>\n<p>Here is a more advanced project, but still pretty easy. This will be using a txt file to save some notes. The first thing we need to do is to create a txt file in your repl, name it 'notes.txt'\nNow, to open a file in python we use open('filename', type) The type can be 'r' for read, or 'w' for write. There is another option, but we won't be using that here. Now, the first thing we are going to do is get what the user would like to save:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">message = input(\"What would you like to save?\")</code></pre></div>\n<p>Now we'll open our file and save that text</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">o = open('notes.txt', 'w')\no.write(message)\n#this next part is very important, you need to always remember to close your file or what you wrote to it won't be saved\no.close()</code></pre></div>\n<p>There we go, now the information is in the file. Next, we'll retrieve it</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">read = open('notes.txt', 'r')\nout = read.read()\n# now we need to close the file\nread.close()\n# and now print what we read\nprint(out)</code></pre></div>\n<p>There we go, that's how you can open files and close files with python</p>\n<h3>5. Random Dare Generator</h3>\n<p>Who doesn't love a good dare? Here is a program that can generate random dares. The first thing we'll need to do is as always, import random. Then we'll make some lists of dares</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import random\nlist1 = ['jump on', 'sit on', 'rick roll on', 'stop on', 'swing on']\nlist2 = ['your cat', 'your neighbor', 'a dog', 'a tree', 'a house']\nlist3 = ['your mom', 'your best friend', 'your dad', 'your teacher']\n#now we'll generate a dare\nwhile True:\n  if input() == '': #this will trigger if they hit enter\n    print(\"I dare you to \" + random.choice(list1) + ' ' + random.choice(list2) + ' in front of '  + random.choice(list3)</code></pre></div>"},{"url":"/blog/awesome-resources/","relativePath":"blog/awesome-resources.md","relativeDir":"blog","base":"awesome-resources.md","name":"awesome-resources","frontmatter":{"title":"Awesome Resources","template":"post","subtitle":"Table of Contents","excerpt":"Table of Contents","date":"2022-05-29T14:27:34.209Z","image":"https://github.com/bgoonz/bgoonz/blob/master/circle-small-sharp.png?raw=true?raw=true","thumb_image":"https://github.com/bgoonz/bgoonz/blob/master/circle-small-sharp.png?raw=true?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/awesome-lists.yaml"],"tags":["src/data/tags/cms.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/10-essential-react-interview-questions.md","src/pages/blog/beginners-guide-to-python.md","src/pages/blog/data-structures-algorithms-resources.md","src/pages/blog/embedding-media-in-html.md","src/pages/blog/intro-to-markdown.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h2>Table of Contents</h2>\n<ul>\n<li>\n<p><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#apps\">Apps</a></p>\n<ul>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#sshconfig\"><code class=\"language-text\">.ssh/config</code></a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#tools-using-the-ssh-protocol\">Tools using the <em>SSH</em> protocol</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#servers\">Servers</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#network\">Network</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#multiplexers\">Multiplexers</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#ssh-keys--authentication\">SSH Keys / Authentication</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#ssh-agent\">SSH agent</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#tools\">Tools</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#automation\">Automation</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#web\">Web</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#testing--honeypots\">Testing / Honeypots</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#alternatives-to-ssh\">Alternatives to SSH</a></li>\n</ul>\n</li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#libraries\">Libraries</a></li>\n<li>\n<p><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#resources\">Resources</a></p>\n<ul>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#tutorials\">Tutorials</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#security\">Security</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#documentation\">Documentation</a></li>\n<li><a href=\"https://search-awesome.vercel.app/readme-HTMLS/html/README%20%28228%29.html#community\">Community</a></li>\n</ul>\n</li>\n</ul>\n<h2>Apps</h2>\n<h3><code class=\"language-text\">.ssh/config</code></h3>\n<ul>\n<li><a href=\"https://github.com/moul/assh\"><code class=\"language-text\">assh</code></a> <a href=\"https://github.com/moul/advanced-ssh-config\"><img src=\"https://img.shields.io/github/stars/moul/advanced-ssh-config.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Transparent wrapper (ProxyCommand) that adds regex, aliases, gateways, includes, dynamic hostnames to <em>SSH</em> and <code class=\"language-text\">ssh-config</code>. <em>Previously: <code class=\"language-text\">advanced-ssh-config</code></em></li>\n<li><a href=\"https://github.com/emre/storm\">storm</a> <a href=\"https://github.com/emre/storm\"><img src=\"https://img.shields.io/github/stars/emre/storm.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Manage your <em>SSH</em> like a boss.</li>\n<li><a href=\"https://github.com/gaqzi/ansible-ssh-config\">ansible-ssh-config</a> <a href=\"https://github.com/gaqzi/ansible-ssh-config\"><img src=\"https://img.shields.io/github/stars/gaqzi/ansible-ssh-config.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Letting <em>Ansible</em> manage <code class=\"language-text\">ssh_config</code>.</li>\n<li><a href=\"https://github.com/mirakui/ec2ssh\">ec2ssh</a> <a href=\"https://github.com/mirakui/ec2ssh\"><img src=\"https://img.shields.io/github/stars/mirakui/ec2ssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - A <code class=\"language-text\">ssh_config</code> manager for <em>AWS EC2</em>.</li>\n<li><a href=\"https://github.com/dbrady/ssh-config\">ssh-config</a> <a href=\"https://github.com/dbrady/ssh-config\"><img src=\"https://img.shields.io/github/stars/dbrady/ssh-config.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - A tool to help manage your <code class=\"language-text\">.ssh/config</code> file.</li>\n</ul>\n<h3>Tools using the <em>SSH</em> protocol</h3>\n<ul>\n<li><a href=\"https://linux.die.net/man/1/scp\">scp</a> - Secure remote file copy utility over <em>SSH</em>.</li>\n<li><a href=\"https://rsync.samba.org/\">rsync</a> - Fast incremental transfer utility that supports <em>SSH</em>.</li>\n<li><a href=\"https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol\">sftp</a> - File transfer protocol over <em>SSH</em>.</li>\n<li><a href=\"https://curl.haxx.se/\">curl</a> - Command line tool and library to transfer data (support <code class=\"language-text\">sftp</code>).</li>\n</ul>\n<h3>Servers</h3>\n<ul>\n<li><a href=\"https://github.com/moul/sshportal\">sshportal</a> <a href=\"https://github.com/moul/sshportal\"><img src=\"https://img.shields.io/github/stars/moul/sshportal.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - simple, fun, and transparent SSH (&#x26; Telnet) Bastion Server</li>\n<li><a href=\"https://github.com/moul/ssh2docker\">ssh2docker</a> <a href=\"https://github.com/moul/ssh2docker\"><img src=\"https://img.shields.io/github/stars/moul/ssh2docker.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH</em> server to Docker containers.</li>\n<li><a href=\"https://github.com/ml-tooling/ssh-proxy\">ssh-proxy</a> <a href=\"https://github.com/ml-tooling/ssh-proxy\"><img src=\"https://img.shields.io/github/stars/ml-tooling/ssh-proxy.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Dockerized SSH bastion to proxy SSH connections to arbitrary containers.</li>\n<li><a href=\"https://github.com/FiloSottile/whosthere\">whosthere</a> <a href=\"https://github.com/FiloSottile/whosthere\"><img src=\"https://img.shields.io/github/stars/FiloSottile/whosthere.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - A <em>SSH</em> server that knows who you are. <code class=\"language-text\">$ ssh whoami.filippo.io</code>.</li>\n<li><a href=\"https://github.com/gliderlabs/sshfront\">sshfront</a> <a href=\"https://github.com/gliderlabs/sshfront\"><img src=\"https://img.shields.io/github/stars/gliderlabs/sshfront.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Programmable <em>SSH</em> frontend.</li>\n<li><a href=\"https://github.com/shazow/ssh-chat\">ssh-chat</a> <a href=\"https://github.com/shazow/ssh-chat\"><img src=\"https://img.shields.io/github/stars/shazow/ssh-chat.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Chat over <em>SSH</em>.</li>\n<li><a href=\"https://github.com/dokku/sshcommand\">sshcommand</a> <a href=\"https://github.com/dokku/sshcommand\"><img src=\"https://img.shields.io/github/stars/dokku/sshcommand.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Turn <em>SSH</em> into a thin client specifically for your app.</li>\n<li><a href=\"https://github.com/joushou/sshmuxd\">sshmuxd</a> <a href=\"https://github.com/joushou/sshmuxd\"><img src=\"https://img.shields.io/github/stars/joushou/sshmuxd.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <code class=\"language-text\">sshmux</code> frontend.</li>\n<li><a href=\"https://github.com/jquast/x84\">x84</a> <a href=\"https://github.com/jquast/x84\"><img src=\"https://img.shields.io/github/stars/jquast/x84.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - A <em>python</em> <code class=\"language-text\">telnet</code>/<code class=\"language-text\">ssh</code> server for modern <em>UTF-8</em> and classic <em>cp437</em> network virtual terminals. In spirit of classic software such as <em>ami/x</em>, <em>teleguard</em>, <em>renegade</em>, <em>iniquity</em>.</li>\n<li><a href=\"https://github.com/gravitational/teleport\">teleport</a> <a href=\"https://github.com/gravitational/teleport\"><img src=\"https://img.shields.io/github/stars/gravitational/teleport.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Modern <em>SSH</em> server for clusters and teams.</li>\n<li><a href=\"https://github.com/shellhub-io/shellhub\">ShellHub</a> <a href=\"https://github.com/shellhub-io/shellhub\"><img src=\"https://img.shields.io/github/stars/shellhub-io/shellhub.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - A <em>SSH</em> gateway for remotely accessing any Linux device behind firewall and NAT.</li>\n</ul>\n<h3>Network</h3>\n<ul>\n<li><a href=\"https://mosh.mit.edu/\">Mosh</a> - The mobile shell.</li>\n<li><a href=\"https://github.com/libfuse/sshfs\">sshfs</a> <a href=\"https://github.com/libfuse/sshfs\"><img src=\"https://img.shields.io/github/stars/libfuse/sshfs.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Filesystem client based on the <em>SSH</em> File Transfer Protocol.</li>\n<li><a href=\"https://github.com/inconshreveable/ngrok\">ngrok</a> <a href=\"https://github.com/inconshreveable/ngrok\"><img src=\"https://img.shields.io/github/stars/inconshreveable/ngrok.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Introspected tunnels to localhost.</li>\n<li><a href=\"https://github.com/progrium/localtunnel\">localtunnel</a> <a href=\"https://github.com/progrium/localtunnel\"><img src=\"https://img.shields.io/github/stars/progrium/localtunnel.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Expose localhost servers to the Internet.</li>\n<li><a href=\"https://github.com/sshuttle/sshuttle\">sshuttle</a> <a href=\"https://github.com/sshuttle/sshuttle\"><img src=\"https://img.shields.io/github/stars/sshuttle/sshuttle.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Transparent proxy server that works as a poor man’s <em>VPN</em>. Forwards over <code class=\"language-text\">ssh</code>. Doesn’t require admin. Works with <em>Linux</em> and <em>MacOS</em>. Supports <em>DNS tunneling</em>.</li>\n<li><a href=\"https://github.com/stealth/sshttp\">sshttp</a> <a href=\"https://github.com/stealth/sshttp\"><img src=\"https://img.shields.io/github/stars/stealth/sshttp.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH</em>/<em>HTTP(S)</em> multiplexer. Run a webserver and a <code class=\"language-text\">sshd</code> on the same port w/o changes.</li>\n<li><a href=\"https://github.com/jamescun/switcher\">switcher</a> <a href=\"https://github.com/jamescun/switcher\"><img src=\"https://img.shields.io/github/stars/jamescun/switcher.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Run <em>SSH</em> and <em>HTTP(S)</em> on the same port.</li>\n<li><a href=\"https://github.com/yrutschle/sslh\">sslh</a> <a href=\"https://github.com/yrutschle/sslh\"><img src=\"https://img.shields.io/github/stars/yrutschle/sslh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Applicative Protocol Multiplexer (i.e: <em>SSH</em> + <em>HTTPS</em>).</li>\n<li><a href=\"https://github.com/aphyr/tund\">tund</a> <a href=\"https://github.com/aphyr/tund\"><img src=\"https://img.shields.io/github/stars/aphyr/tund.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH</em> reverse tunnel daemon.</li>\n<li><a href=\"https://www.harding.motd.ca/autossh/\">autossh</a> - Automatically respawn <em>SSH</em> session after network interruption.</li>\n<li><a href=\"https://github.com/aluzzardi/wssh\">wssh</a> <a href=\"https://github.com/aluzzardi/wssh\"><img src=\"https://img.shields.io/github/stars/aluzzardi/wssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH</em> to WebSockets Bridge.</li>\n<li><a href=\"https://github.com/vieux/docker-volume-sshfs\">docker-volume-sshfs</a> <a href=\"https://github.com/vieux/docker-volume-sshfs\"><img src=\"https://img.shields.io/github/stars/vieux/docker-volume-sshfs.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <code class=\"language-text\">sshfs</code> docker volume plugin.</li>\n<li><a href=\"https://github.com/moul/quicssh\">quicssh</a> <a href=\"https://github.com/moul/quicssh\"><img src=\"https://img.shields.io/github/stars/moul/quicssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - QUIC proxy for SSH</li>\n<li><a href=\"https://github.com/tg123/sshpiper\">sshpiper</a> <a href=\"https://github.com/tg123/sshpiper\"><img src=\"https://img.shields.io/github/stars/tg123/sshpiper.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - The missing reverse proxy for ssh scp.</li>\n<li><a href=\"https://sshhub.de/\">sshhub</a> - Web Service: access your SSH servers behind firewalls (ssh-teamviewer).</li>\n</ul>\n<h3>Multiplexers</h3>\n<ul>\n<li><a href=\"https://tmux.github.io/\">tmux</a> - Terminal multiplexer.</li>\n<li><a href=\"https://github.com/duncs/clusterssh\">clusterssh</a> <a href=\"https://github.com/duncs/clusterssh\"><img src=\"https://img.shields.io/github/stars/duncs/clusterssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Cluster admin via <em>SSH</em>.</li>\n<li><a href=\"https://github.com/dennishafemann/tmux-cssh\">tmux-cssh</a> <a href=\"https://github.com/dennishafemann/tmux-cssh\"><img src=\"https://img.shields.io/github/stars/dennishafemann/tmux-cssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <code class=\"language-text\">tmux</code> with a <em>ClusterSSH</em>-like behavior.</li>\n<li><a href=\"https://github.com/Ganneff/tm\">tm</a> <a href=\"https://github.com/Ganneff/tm\"><img src=\"https://img.shields.io/github/stars/Ganneff/tm.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <code class=\"language-text\">tmux</code> manager / helper.</li>\n<li><a href=\"https://github.com/wouterdebie/i2cssh\">i2cssh</a> <a href=\"https://github.com/wouterdebie/i2cssh\"><img src=\"https://img.shields.io/github/stars/wouterdebie/i2cssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <code class=\"language-text\">csshX</code> like <em>SSH</em> tool for <em>iTerm2</em>.</li>\n<li><a href=\"https://sourceforge.net/projects/clusterssh/\">ClusterSSH</a> - Controls a number of <code class=\"language-text\">xterm</code> windows via a single graphical console.</li>\n</ul>\n<h3><em>SSH</em> keys / Authentication</h3>\n<ul>\n<li><a href=\"https://github.com/authy/authy-ssh\">authy-ssh</a> <a href=\"https://github.com/authy/authy-ssh\"><img src=\"https://img.shields.io/github/stars/authy/authy-ssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Easy <em>two-factor</em> authentication for <em>SSH</em> servers.</li>\n<li><a href=\"https://github.com/chrishunt/github-auth\">github-auth</a> <a href=\"https://github.com/chrishunt/github-auth\"><img src=\"https://img.shields.io/github/stars/chrishunt/github-auth.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH</em> key management for GitHub users.</li>\n<li><a href=\"https://github.com/substack/cipherhub\">cipherhub</a> <a href=\"https://github.com/substack/cipherhub\"><img src=\"https://img.shields.io/github/stars/substack/cipherhub.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Encrypt messages based on <em>SSH</em> public keys with easy import from GitHub.</li>\n<li><a href=\"https://www.ryanbrink.com/slack-ssh-session-notifications/\">Slack notifications</a> (<a href=\"https://web.archive.org/web/20160505202303/http://www.ryanbrink.com/slack-ssh-session-notifications/\">archived version</a>) - Guide to setup Slack notifications (can be modified for other services).</li>\n<li><a href=\"https://github.com/benjojo/totp-ssh-fluxer\">totp-ssh-fluxer</a> <a href=\"https://github.com/benjojo/totp-ssh-fluxer\"><img src=\"https://img.shields.io/github/stars/benjojo/totp-ssh-fluxer.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - A way to make sure your <code class=\"language-text\">sshd</code> port changes every 30 seconds.</li>\n<li><a href=\"https://github.com/dolmen/github-keygen\">github-keygen</a> <a href=\"https://github.com/dolmen/github-keygen\"><img src=\"https://img.shields.io/github/stars/dolmen/github-keygen.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Easy creation of secure <em>SSH</em> configuration for your GitHub account(s).</li>\n<li><a href=\"https://github.com/KryptCo/kr\">kr</a> <a href=\"https://github.com/KryptCo/kr\"><img src=\"https://img.shields.io/github/stars/dolmen/github-keygen.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Kr agent that route access request to the paired mobile phone where Kryptonite is installed.</li>\n<li><a href=\"https://serverauth.com/\">ServerAuth</a> - Automatically sync SSH access across servers</li>\n</ul>\n<h3><em>SSH</em> agent</h3>\n<ul>\n<li><a href=\"https://github.com/ccontavalli/ssh-ident\">ssh-ident</a> <a href=\"https://github.com/ccontavalli/ssh-ident\"><img src=\"https://img.shields.io/github/stars/ccontavalli/ssh-ident.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Different agents and different keys for different projects, with <code class=\"language-text\">ssh</code>.</li>\n<li><a href=\"https://github.com/robbyrussell/oh-my-zsh\">oh-my-zsh/plugins/ssh-agent</a> <a href=\"https://github.com/robbyrussell/oh-my-zsh\"><img src=\"https://img.shields.io/github/stars/robbyrussell/oh-my-zsh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <code class=\"language-text\">ssh-agent</code> plugin for <code class=\"language-text\">zsh</code>.</li>\n<li><a href=\"https://github.com/thcipriani/sshecret\">sshecret</a> - Automatically create and manage multiple agents for multiple keys.</li>\n</ul>\n<h3>Tools</h3>\n<ul>\n<li><a href=\"https://github.com/xxh/xxh\">xxh</a> <a href=\"https://github.com/xxh/xxh\"><img src=\"https://img.shields.io/github/stars/xxh/xxh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Bring your favorite shell wherever you go through the ssh.</li>\n<li><a href=\"https://github.com/danrabinowitz/sshrc\">sshrc</a> <a href=\"https://github.com/danrabinowitz/sshrc\"><img src=\"https://img.shields.io/github/stars/danrabinowitz/sshrc.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Bring your <code class=\"language-text\">.bashrc</code>, <code class=\"language-text\">.vimrc</code>, etc. with you when you <code class=\"language-text\">ssh</code>.</li>\n<li><a href=\"https://github.com/fsquillace/kyrat\">kyrat</a> <a href=\"https://github.com/fsquillace/kyrat\"><img src=\"https://img.shields.io/github/stars/fsquillace/kyrat.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - SSH wrapper script that brings your dotfiles always with you on Linux and OSX.</li>\n<li><a href=\"https://github.com/ssh-vault/ssh-vault\">ssh-vault</a> <a href=\"https://github.com/ssh-vault/ssh-vault\"><img src=\"https://img.shields.io/github/stars/ssh-vault/ssh-vault.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - encrypt/decrypt files using ssh keys</li>\n<li><a href=\"https://github.com/vaporup/ssh-tools\">ssh-ping</a> <a href=\"https://github.com/vaporup/ssh-tools\"><img src=\"https://img.shields.io/github/stars/vaporup/ssh-tools.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - check if host is reachable using ssh_config</li>\n<li><a href=\"https://github.com/nopernik/SSHPry2.0\">SSHPry v2</a> <a href=\"https://github.com/nopernik/SSHPry2.0\"><img src=\"https://img.shields.io/github/stars/nopernik/SSHPry2.0.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Spy &#x26; Control os SSH Connected client’s TTY</li>\n<li><a href=\"https://github.com/taypo/redial\">redial</a> <a href=\"https://github.com/taypo/redial\"><img src=\"https://img.shields.io/github/stars/taypo/redial?style=social\" alt=\"stars\"></a> - Terminal Based SSH Session Manager for Unix Systems</li>\n</ul>\n<h3>Automation</h3>\n<ul>\n<li><a href=\"https://github.com/ansible/ansible\">Ansible</a> <a href=\"https://github.com/ansible/ansible\"><img src=\"https://img.shields.io/github/stars/ansible/ansible.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - App deployment, configuration management and orchestration over <em>SSH</em>.</li>\n<li><a href=\"https://github.com/rapidloop/rtop\">rtop</a> <a href=\"https://github.com/rapidloop/rtop\"><img src=\"https://img.shields.io/github/stars/rapidloop/rtop.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Interactive, remote system monitoring tool based on <em>SSH</em>.</li>\n<li><a href=\"https://www.netfort.gr.jp/~dancer/software/dsh.html.en\">DSH - Dancer’s shell / distributed shell</a> - Wrapper for executing multiple remote shell commands from one command line.</li>\n<li><a href=\"https://github.com/ParallelSSH/parallel-ssh\">parallel-ssh</a> <a href=\"https://github.com/ParallelSSH/parallel-ssh\"><img src=\"https://img.shields.io/github/stars/ParallelSSH/parallel-ssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Provides parallel versions of OpenSSH and related tools.</li>\n<li><a href=\"https://code.google.com/p/sshpt/\">SSH Power Tool</a> - Execute commands and upload files to many servers simultaneously without using pre-shared keys.</li>\n</ul>\n<h3>Web</h3>\n<ul>\n<li><a href=\"https://chrome.google.com/webstore/detail/secure-shell/pnhechapfaindjhompbnflcldabbghjo?hl=en\">Secure Shell chrome extension</a></li>\n<li><a href=\"https://github.com/liftoff/GateOne\">GateOne</a> <a href=\"https://github.com/liftoff/GateOne\"><img src=\"https://img.shields.io/github/stars/liftoff/GateOne.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - HTML5-powered terminal emulator and <em>SSH</em> client.</li>\n<li><a href=\"https://github.com/skavanagh/KeyBox\">KeyBox</a> <a href=\"https://github.com/skavanagh/KeyBox\"><img src=\"https://img.shields.io/github/stars/skavanagh/KeyBox.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Web-based <em>SSH</em> console that centrally manages administrative access to systems.</li>\n<li><a href=\"https://guacamole.incubator.apache.org/\">Apache Guacamole</a> - Apache Guacamole is a HTML5 based clientless remote desktop gateway. It supports standard protocols like VNC, RDP, and SSH.</li>\n<li><a href=\"https://github.com/hpello/sshmon\">SSHmon</a> <a href=\"https://github.com/hpello/sshmon\"><img src=\"https://img.shields.io/github/stars/hpello/sshmon.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Real-time GUI to monitor SSH connections and establish port forwardings.</li>\n</ul>\n<h3>Testing / Honeypots</h3>\n<ul>\n<li><a href=\"https://github.com/shazow/ssh-hammer\">ssh-hammer</a> <a href=\"https://github.com/shazow/ssh-hammer\"><img src=\"https://img.shields.io/github/stars/shazow/ssh-hammer.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH</em> load testing tool.</li>\n<li><a href=\"https://github.com/desaster/kippo\">kippo</a> <a href=\"https://github.com/desaster/kippo\"><img src=\"https://img.shields.io/github/stars/desaster/kippo.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH</em> Honeypot.</li>\n<li><a href=\"https://github.com/micheloosterhof/cowrie\">cowrie</a> <a href=\"https://github.com/micheloosterhof/cowrie\"><img src=\"https://img.shields.io/github/stars/micheloosterhof/cowrie.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH</em> Honeypot (based on kippo).</li>\n<li><a href=\"https://linux.die.net/man/8/sshmitm\">sshmitm</a> - <em>SSH</em> monkey-in-the-middle.</li>\n<li><a href=\"https://github.com/arthepsy/ssh-audit\">ssh-audit</a> <a href=\"https://github.com/arthepsy/ssh-audit\"><img src=\"https://img.shields.io/github/stars/arthepsy/ssh-audit.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - A tool for <em>SSH</em> server auditing.</li>\n<li><a href=\"https://github.com/jaksi/sshesame\">sshesame</a> <a href=\"https://github.com/jaksi/sshesame\"><img src=\"https://img.shields.io/github/stars/jaksi/sshesame.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - A fake SSH server that lets everyone in and logs their activity.</li>\n</ul>\n<h3>Alternatives to <em>SSH</em></h3>\n<ul>\n<li><a href=\"https://github.com/yudai/gotty\">GoTTY</a> <a href=\"https://github.com/yudai/gotty\"><img src=\"https://img.shields.io/github/stars/yudai/gotty.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Share your terminal as web application.</li>\n<li><a href=\"https://www.telnet.org/htm/faq.htm\">telnet</a> - An unencrypted network protocol and an application used to connect to remote computers and issue commands.</li>\n<li><a href=\"https://github.com/tsl0922/ttyd\">ttyd</a> <a href=\"https://github.com/tsl0922/ttyd\"><img src=\"https://img.shields.io/github/stars/tsl0922/ttyd.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Share your terminal over the web.</li>\n<li><a href=\"https://en.wikipedia.org/wiki/Remote_Shell\">rsh</a> - An unencrypted network protocol and application used to connect to remote computers and issue commands.</li>\n</ul>\n<h2>Libraries</h2>\n<ul>\n<li>\n<p>C/C++</p>\n<ul>\n<li><a href=\"https://www.libssh.org/\">libssh</a> - The <em>SSH</em> library.</li>\n</ul>\n</li>\n<li>\n<p>Golang</p>\n<ul>\n<li><a href=\"https://godoc.org/golang.org/x/crypto/ssh\">crypto/ssh</a> - Built-in <em>SSH</em> client and server library.</li>\n<li><a href=\"https://github.com/pkg/sftp\">sftp</a> <a href=\"https://github.com/pkg/sftp\"><img src=\"https://img.shields.io/github/stars/pkg/sftp.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SFTP</em> support for the go.crypto/ssh package.</li>\n<li><a href=\"https://github.com/shazow/go-sshkit\">go-sshkit</a> <a href=\"https://github.com/shazow/go-sshkit\"><img src=\"https://img.shields.io/github/stars/shazow/go-sshkit.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Toolkit for building <em>SSH</em> servers and clients in Go.</li>\n<li><a href=\"https://github.com/cosiner/socker\">Socker</a> <a href=\"https://github.com/cosiner/socker\"><img src=\"https://img.shields.io/github/stars/cosiner/socker.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Library for Go to simplify the use of <em>SSH</em>.</li>\n<li><a href=\"https://github.com/moul/go-sshkeys\">go-sshkeys</a> - Golang SSH Keys manipulation library</li>\n</ul>\n</li>\n<li>\n<p>Java</p>\n<ul>\n<li><a href=\"https://www.jcraft.com/jsch/\">jsch</a> - Pure <em>java</em>, <em>BSD</em> licensed, <em>SSH2</em> client library.</li>\n</ul>\n</li>\n<li>\n<p>Javascript/Node.js</p>\n<ul>\n<li><a href=\"https://github.com/mscdex/ssh2\">ssh2</a> <a href=\"https://github.com/mscdex/ssh2\"><img src=\"https://img.shields.io/github/stars/mscdex/ssh2.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <em>SSH2</em> client and server modules written in pure <em>JavaScript</em> for <em>node.js</em>.</li>\n</ul>\n</li>\n<li>\n<p>Python</p>\n<ul>\n<li><a href=\"https://github.com/paramiko/paramiko\">paramiko</a> <a href=\"https://github.com/paramiko/paramiko\"><img src=\"https://img.shields.io/github/stars/paramiko/paramiko.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Native <em>Python</em> <em>SSHv2</em> protocol library.</li>\n</ul>\n</li>\n<li>\n<p>Ruby</p>\n<ul>\n<li><a href=\"https://github.com/net-ssh/net-ssh\">net-ssh</a> <a href=\"https://github.com/net-ssh/net-ssh\"><img src=\"https://img.shields.io/github/stars/net-ssh/net-ssh.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - Pure <em>Ruby</em> implementation of an <em>SSH</em> (protocol 2) client.</li>\n</ul>\n</li>\n</ul>\n<h2>Resources</h2>\n<h3>Tutorials</h3>\n<ul>\n<li><a href=\"https://www.digitalocean.com/community/tutorials/how-to-use-ssh-to-connect-to-a-remote-server-in-ubuntu\">How to use <em>SSH</em> to Connect to a Remote Server</a></li>\n<li><a href=\"https://blog.0xbadc0de.be/archives/300\">Best practices</a></li>\n<li><a href=\"https://linux-audit.com/granting-temporary-access-to-servers-using-signed-ssh-keys/\">Granting Temporary Access to Your Servers (Using Signed <em>SSH</em> Keys)</a></li>\n<li><a href=\"https://www.rosehosting.com/blog/ssh-login-without-password-using-ssh-keys/\">How to SSH login without a password</a></li>\n<li><a href=\"https://gist.github.com/mjalajel/beaa91a5f8d04ebb464c2c28da01406a\">Gist: SSH Recipes</a> - Collection of recipes for writing awesome ssh config files.</li>\n</ul>\n<h3>Security</h3>\n<ul>\n<li><a href=\"https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2016-0777\">01/14/2016</a> - Integer Overflow <code class=\"language-text\">CVE 2016 077[7-8]</code>.</li>\n<li><a href=\"https://wiki.mozilla.org/Security/Guidelines/OpenSSH\">Security/Guidelines/OpenSSH - MozillaWiki</a> - <code class=\"language-text\">sshd\\_config</code> for <code class=\"language-text\">6.7+</code>, <code class=\"language-text\">5.3</code>.</li>\n<li><a href=\"https://github.com/BetterCrypto/Applied-Crypto-Hardening\">Applied-Crypto-Hardening</a> <a href=\"https://github.com/BetterCrypto/Applied-Crypto-Hardening\"><img src=\"https://img.shields.io/github/stars/BetterCrypto/Applied-Crypto-Hardening.svg?style=social&#x26;label=stars\" alt=\"stars\"></a> - <code class=\"language-text\">sshd\\_config</code> for <code class=\"language-text\">6.X</code></li>\n</ul>\n<h3>Documentation</h3>\n<ul>\n<li><a href=\"https://linux.die.net/man/1/ssh\">man page</a></li>\n<li><a href=\"https://www.openssh.com/specs.html\">Specifications (OpenSSH)</a></li>\n<li><a href=\"https://en.wikipedia.org/wiki/Secure_Shell\">Wikipedia article</a></li>\n</ul>\n<!--EndFragment-->"},{"url":"/blog/blog-archive/","relativePath":"blog/blog-archive.md","relativeDir":"blog","base":"blog-archive.md","name":"blog-archive","frontmatter":{"title":"Blog Archive","subtitle":"Blog Archive","date":"2021-07-26","thumb_image_alt":"Blog page animation","excerpt":"Blog Archive","seo":{"title":"Blog Archive","description":"Google Blogger Site Archive","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"post","thumb_image":"images/dense-js-code.jpg"},"html":"<h2>Blog Archive</h2>\n <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  width=\"100%\" height=\"100%\" src=\"https://bgoonz.blogspot.com/\"\n            clipboard-write;\n            allowfullscreen>\n</iframe>\n<br>"},{"url":"/blog/awesome-graphql/","relativePath":"blog/awesome-graphql.md","relativeDir":"blog","base":"awesome-graphql.md","name":"awesome-graphql","frontmatter":{"title":"Awesome GraphQL","subtitle":"The Death Of REST","date":"2021-09-30","thumb_image_alt":"image of","excerpt":"Working Draft of the Specification for GraphQL created by Facebook","seo":{"title":"Awesome GraphQL","description":"Awesome GraphQL","robots":[],"extra":[]},"template":"post","thumb_image":"images/https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/GraphQL_Logo.svg/225px-GraphQL_Logo.svg.png","image":"images/https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/GraphQL_Logo.svg/225px-GraphQL_Logo.svg.png"},"html":"<h2>Table of Contents\n\n</h2>\n<ul>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#spec\">Specification</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#community\">Community</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#meetups\">GraphQL Meetups</a></li>\n<li>\n<p><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib\">Libraries</a></p>\n<ul>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-js\">Javascript</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-ts\">Typescript</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-rb\">Ruby</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-php\">PHP</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-py\">Python</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-java\">Java</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-c\">C/C++</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-go\">Go</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-scala\">Scala</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-perl\">Perl</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-dotnet\">.NET</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-erlang\">Erlang</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-elixir\">Elixir</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-haskell\">Haskell</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-sql\">SQL</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-lua\">Lua</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-elm\">Elm</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-clojure\">Clojure</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-clojurescript\">ClojureScript</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-swift\">Swift</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-ocaml\">OCaml</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-rust\">Rust</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-r\">R</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-julia\">Julia</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-kotlin\">Kotlin</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-unity\">Unity</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#lib-crystal\">Crystal</a></li>\n</ul>\n</li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#tools\">Tools</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#services\">Services</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#databases\">Databases</a></li>\n<li>\n<p><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example\">Examples</a></p>\n<ul>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-js\">Javascript</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-ts\">Typescript</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-rb\">Ruby</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-go\">Go</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-scala\">Scala</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-python\">Python</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-elixir\">Elixir</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-php\">PHP</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#example-reasonml\">ReasonML</a></li>\n</ul>\n</li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#video\">Videos</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#blogs\">Blogs</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#post\">Posts</a></li>\n<li><a href=\"https://github.com/dhruv-kumar-jha/awesome-graphql#workshopper\">Workshoppers</a></li>\n</ul>\n<h2>Specification</h2>\n<ul>\n<li><a href=\"https://facebook.github.io/graphql/\">facebook/graphql</a> - Working Draft of the Specification for GraphQL created by Facebook.</li>\n</ul>\n<h2>Community</h2>\n<ul>\n<li><a href=\"https://graphql.slack.com/messages/general\">Slack</a> - Share and help people on the chat. Get your invite <a href=\"https://graphql-slack.herokuapp.com/\">here</a></li>\n<li>-</li>\n<li><a href=\"https://webchat.freenode.net/?channels=#graphql\">#graphql on Freenode</a> - The official IRC channel for GraphQL</li>\n<li>-</li>\n<li><a href=\"https://www.facebook.com/groups/795330550572866/\">Facebook</a> - Group for discussions, articles and knowledge sharing</li>\n<li>-</li>\n<li><a href=\"https://twitter.com/search?q=%23GraphQL\">Twitter</a> - Use the hashtag <a href=\"https://twitter.com/search?q=%23GraphQL\">#graphql</a></li>\n<li><a href=\"https://stackoverflow.com/questions/tagged/graphql\">StackOverflow</a> - Questions and answers. Use the tag <a href=\"https://stackoverflow.com/questions/tagged/graphql\">graphql</a></li>\n<li><a href=\"https://github.com/APIs-guru/graphql-apis\">GraphQL APIs</a> - A collective list of public GraphQL APIs</li>\n<li><a href=\"https://graphql-world.com/\">GraphQL World</a> - The fastest growing community of GraphQL developers</li>\n</ul>\n<h2>GraphQL Meetups</h2>\n<ul>\n<li><a href=\"https://www.meetup.com/graphql-berlin/\">Berlin</a></li>\n<li>-</li>\n<li><a href=\"https://www.meetup.com/es-ES/GraphQL-BA/\">Buenos Aires</a></li>\n<li>-</li>\n<li>[Dallas-Fort Worth](<a href=\"https://www.meetup.com/DFW-Gra\">https://www.meetup.com/DFW-Gra</a></li>\n<li>-</li>\n<li>[Istanbul](<a href=\"https://www.meetup.com/GraphQL-Istanbul\">https://www.meetup.com/GraphQL-Istanbul</a></li>\n<li>-</li>\n<li><a href=\"https://www.meetup.com/GraphQL-London/\">London</a></li>\n<li>-</li>\n<li>[Melbourne](<a href=\"https://www.meetup.com/GraphQL-Melbou\">https://www.meetup.com/GraphQL-Melbou</a></li>\n<li>-</li>\n<li><a href=\"https://www.meetup.com/GraphQL-Munich/\">Munich</a></li>\n<li><a href=\"https://www.meetup.com/GraphQL-NYC/\">New York City</a></li>\n<li><a href=\"https://www.meetup.com/GraphQL-SF/\">San Francisco</a></li>\n<li><a href=\"https://www.meetup.com/GraphQL-Sydney/\">Sydney</a></li>\n<li><a href=\"https://www.meetup.com/GraphQL-TLV/\">Tel Aviv</a></li>\n<li><a href=\"https://www.meetup.com/GraphQL-Toronto/\">Toronto</a></li>\n</ul>\n<h2>Libraries</h2>\n<h3>JavaScript Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/graphql/graphql-js\">GraphQL.js</a> - A reference implementation of GraphQL for JavaScript.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql/express-graphql\">express-graphql</a> - GraphQL Express Midd</li>\n<li>-</li>\n<li><a href=\"https://github.com/chentsulin/koa-graphql\">koa-graphql</a> - GraphQL Koa Middleware.</li>\n<li>-</li>\n<li><a href=\"https://github.com/SimonDegraeve/hapi-graphql\">hapi-graphql</a> - Create a GraphQL HTTP server with Hapi.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql/codemirror-graphql\">codemirror-graphql</a> - GraphQ</li>\n<li>-</li>\n<li><a href=\"https://github.com/devknoll/graphql-schema\">graphql-schema</a> - Create GraphQL schemas with a fluent/chainable interface.</li>\n<li>-</li>\n<li><a href=\"https://github.com/mickhansen/graphql-sequelize\">graphql-sequelize</a> - Sequelize helpers for GraphQL.</li>\n<li>-</li>\n<li><a href=\"https://github.com/Glavin001/graphql-sequelize-crud\">graphql-sequelize-crud</a> - Automatically generate queries and mutations from</li>\n<li>-</li>\n<li><a href=\"https://github.com/RisingStack/graffiti\">graffiti</a> - Node.js GraphQL ORM.</li>\n<li>-</li>\n<li><a href=\"https://github.com/RisingStack/graffiti-mongoose\">graffiti-mongoose</a> - Mongoo</li>\n<li>-</li>\n<li><a href=\"https://github.com/ooflorent/babel-plugin-graphql\">babel-plugin-graphql</a> - Babel plugin that compile GraphQL tagged template strings.</li>\n<li>-</li>\n<li><a href=\"https://github.com/gyzerok/adrenaline\">adrenaline</a> - React bindings for Redux with Relay in mind.</li>\n<li>-</li>\n<li><a href=\"https://github.com/brysgo/graphql-bookshelf\">graphql-bookshelf</a> - Some help defining GraphQL schema around BookshelfJS models</li>\n<li>-</li>\n<li><a href=\"https://github.com/weyoss/graphql-bookshelfjs\">graphql-bookshelfjs</a> - A simple br</li>\n<li>-</li>\n<li><a href=\"https://github.com/matthewmueller/graph.ql\">graph.ql</a> - Faster and simpler technique for creating and querying GraphQL schemas.</li>\n<li>-</li>\n<li><a href=\"https://github.com/kennetpostigo/react-reach\">react-reach</a> - A library to communicate with Graphql through Redux</li>\n<li>-</li>\n<li><a href=\"https://github.com/kadirahq/lokka\">Lokka</a> - Simple JavaScript client for GraphQL, which you can use anywhere.</li>\n<li>-</li>\n<li><a href=\"https://strapi.io/documentation/graphql\">Strapi</a> - Open-source Node.js framework that supports \"GraphQL\" out of the box.</li>\n<li>-</li>\n<li><a href=\"https://github.com/larsbs/graysql\">GraysQL</a> - A GraphQL manager and loader.</li>\n<li>-</li>\n<li><a href=\"https://github.com/larsbs/graysql-orm-loader\">graysql-orm-loader</a> - A GraysQL extension to load a GraphQL schema from an ORM.</li>\n<li>-</li>\n<li><a href=\"https://github.com/almilo/annotated-graphql\">Annotated GraphQL</a> - Proof of Concept for</li>\n<li>-</li>\n<li><a href=\"https://github.com/apollographql/apollo-client\">Apollo Client</a> - A well-documented GraphQL client. Has React and An</li>\n<li>-</li>\n<li><a href=\"https://github.com/apollographql/graphql-tools\">graphql-tools</a> - Tool library for building and maintaining GraphQL-JS serve</li>\n<li>-</li>\n<li><a href=\"https://github.com/apollographql/graphql-anywhere\">graphql-anywhere</a> - Run a GraphQL query anywhere, against any data, w</li>\n<li>-</li>\n<li><a href=\"https://github.com/apollographql/graphql-tag\">graphql-tag</a> - A JavaScript template literal tag that parses GraphQL queries</li>\n<li>-</li>\n<li><a href=\"https://github.com/julienvincent/modelizr\">modelizr</a> - A library for simplifying the process of writing GraphQL queries</li>\n<li>-</li>\n<li><a href=\"https://github.com/Akryum/vue-apollo\">vue-apollo</a> - Vue integration for apollo.</li>\n<li>-</li>\n<li><a href=\"https://github.com/fenos/graphql-thinky\">graphql-thinky</a> - Build an optimized GraphQL schema from Thinky RethinkDB models.</li>\n<li>-</li>\n<li><a href=\"https://github.com/MikeBild/graphql-pouch\">graphql-pouch</a> - A GraphQL-API runtime on top of PouchDB created by GraphQL shorthand notation as a self contained service with CouchDB synchronization.</li>\n<li><a href=\"https://github.com/almilo/gql-tools\">gql-tools</a> - Tool library with CLI for schema generation and manipulation.</li>\n<li><a href=\"https://github.com/excitement-engineer/graphql-iso-date\">graphql-iso-date</a> - A GraphQL date scalar type to be used with GraphQL.js. This scalar represents a date in the ISO 8601 format YYYY-MM-DD.</li>\n<li><a href=\"https://github.com/nodkz/graphql-compose\">graphql-compose</a> - Tool which allows you to construct flexible graphql schema from different data sources via plugins.</li>\n<li><a href=\"https://github.com/mwilliamson/node-graphjoiner\">node-graphjoiner</a> - Create GraphQL APIs using joins, SQL or otherwise.</li>\n<li><a href=\"https://github.com/gucheen/FetchQL\">FetchQL</a> - GraphQL query client with Fetch</li>\n<li><a href=\"https://github.com/stems/join-monster\">Join Monster</a> - A GraphQL-to-SQL query execution layer for batch data fetching.</li>\n<li><a href=\"https://github.com/graphql-community/create-graphql\">Create-GraphQL</a> - Command-line utility to build production-ready servers with GraphQL.</li>\n<li><a href=\"https://github.com/lucasbento/graphql-pokemon\">GraphQL-Pokémon</a> - Get information of a Pokémon with GraphQL!</li>\n<li><a href=\"https://github.com/graphql-factory\">graphql-factory</a> - Create GraphQL types from JSON definitions</li>\n<li><a href=\"https://chrome.google.com/webstore/detail/chromeiql/fkkiamalmpiidkljmicmjfbieiclmeij\">ChromeiQL</a> - Chrome extension to use GraphiQL anywhere</li>\n<li><a href=\"https://github.com/ejoebstl/graphql-auto-mutation\">graphql-auto-mutation</a> - Automatically generates functions for mutations specified in a GraphQL schema.</li>\n<li><a href=\"https://github.com/graphitejs/graphitejs\">GraphiteJS</a> - Full stack GraphQL framework.</li>\n<li><a href=\"https://github.com/tallyb/loopback-graphql\">loopback-graphql</a> - GraphQL Server for Loopback.</li>\n<li><a href=\"https://github.com/octet-stream/parasprite\">parasprite</a> - Describe your GraphQL schema using chainable interface.</li>\n<li><a href=\"https://github.com/f/graphql.js\">GraphQL.js</a> - JavaScript GraphQL Client for Browser and Node.js Usage</li>\n<li><a href=\"https://github.com/arangodb/graphql-sync\">graphql-sync</a> - Promise-free wrapper to GraphQL.js for synchronous environments</li>\n<li><a href=\"https://github.com/apollographql/apollo-fetch\">apollo-fetch</a> - Lightweight GraphQL client that supports custom fetch functions, middleware, and afterware</li>\n<li><a href=\"https://github.com/spikenail/spikenail\">Spikenail</a> - Node.js framework for building GraphQL API almost without coding.</li>\n<li><a href=\"https://github.com/AEB-labs/graphql-weaver\">graphql-weaver</a> - A tool to combine, link and transform GraphQL schemas; combine multiple GraphQL servers into one API.</li>\n<li><a href=\"https://github.com/APIs-guru/graphql-lodash\">graphql-lodash</a> - Data manipulation for GraphQL queries with lodash syntax.</li>\n<li><a href=\"https://github.com/apollographql/apollo-angular\">apollo-angular</a> - Angular integration for Apollo.</li>\n<li><a href=\"https://github.com/lucasconstantino/graphql-resolvers\">graphql-resolvers</a> - Resolver composition library for GraphQL.</li>\n<li><a href=\"https://github.com/thebigredgeek/apollo-resolvers\">apollo-resolvers</a> - Expressive and composable resolvers for Apollo Server and graphql-tools.</li>\n<li><a href=\"https://github.com/thebigredgeek/apollo-errors\">apollo-errors</a> - Machine-readable custom errors for Apollo Server.</li>\n<li><a href=\"https://github.com/helfer/graphql-disable-introspection\">graphql-disable-introspection</a> - Graphql Disable Introspection</li>\n<li><a href=\"https://github.com/arackaf/mongo-graphql-starter\">mongo-graphql-starter</a> - Flexible and robust Mongo based resolvers for Node.</li>\n<li><a href=\"https://github.com/imolorhe/altair\">altair-express-middleware</a> - An express middleware for mounting an instance of Altair GraphQL client.</li>\n<li><a href=\"https://github.com/pa-bru/graphql-cost-analysis\">graphql-cost-analysis</a> - A Graphql query cost analyzer.</li>\n</ul>\n<h5>Relay Related</h5>\n<ul>\n<li><a href=\"https://github.com/facebook/relay\">relay</a> - Relay is a JavaScript framework for building data-driven React applications.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql/graphql-relay-js\">graphql-relay-js</a> - A library to help construct a graphql-js server supporting react-relay.</li>\n<li>-</li>\n<li><a href=\"https://github.com/MattMcFarland/sequelize-relay\">sequelize-relay</a> - Serverside library that connects sequelize and graphql-relay-js together.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphcool/babel-plugin-react-relay\">babel-plugin-react-relay</a> - Babel Plugin for Relay with</li>\n<li>-</li>\n<li><a href=\"https://www.npmjs.com/package/babel-relay-plugin\">babel-relay-plugin</a> - Babel Relay Plugin for transpiling GraphQL queries for u</li>\n<li>-</li>\n<li><a href=\"https://github.com/relay-tools/react-router-relay\">react-router-relay</a> - Relay integration for React Router.</li>\n<li>-</li>\n<li><a href=\"https://github.com/relay-tools/relay-local-schema\">relay-local-schema</a> - Use Relay without a GraphQL server.</li>\n<li>-</li>\n<li><a href=\"https://github.com/acdlite/relay-sink\">relay-sink</a> - Use Relay to fetch and store data outside of a React component.</li>\n<li>-</li>\n<li><a href=\"https://github.com/acdlite/recompose/tree/master/src/packages/recompose-relay\">recompose-relay</a> - Recompose helpers for Relay.</li>\n<li><a href=\"https://github.com/larsbs/graysql#Graylay\">Graylay</a> - A GraysQL extension to create a Relay compatible Schema.</li>\n<li><a href=\"https://github.com/apollographql/apollo-client\">Apollo Client</a> - A simple alternative to Relay, comes with React and Angular bindings.</li>\n<li><a href=\"https://github.com/nodkz/react-relay-network-layer\">react-relay-network-layer</a> - A network layer for Relay with query batching and middleware support (urlThunk, retryThunk, auth, defer and other).</li>\n<li><a href=\"https://github.com/edvinerikson/relay-subscriptions\">relay-subscriptions</a> - Subscription support for Relay.</li>\n<li><a href=\"https://github.com/alex-cory/portfolio\">Portfolio Relay Example</a> - An example website that fetches data from various apis and uses Relay and GraphQL to feed the data to React components!</li>\n<li><a href=\"https://github.com/lucasbento/react-relay-pokemon\">Relay Pokédex</a> - Project using GraphQL Pokémon to show how powerful Relay is.</li>\n<li><a href=\"https://github.com/ntkme/vue-relay\">vue-relay</a> - A framework for building GraphQL-driven Vue.js applications.</li>\n</ul>\n<h3>TypeScript Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/19majkel94/type-graphql\">TypeGraphQL</a> - Create GraphQL schema and resolvers with TypeScript, using classes and decorators!</li>\n<li>-</li>\n<li><a href=\"https://vesper-framework.com/\">Vesper</a> - NodeJS framework that helps you to create scalable, maintainable, extensible, declarative and fas</li>\n<li>-</li>\n<li><a href=\"https://github.com/calebmer/graphql-strong\">graphql-strong</a> - Define your GraphQL schemas with confidence that you</li>\n<li>-</li>\n<li><a href=\"https://github.com/3VLINC/graphql-to-typescript\">graphql-to-typescript</a> - Compiles GraphQL files into an importable typescript</li>\n<li>-</li>\n<li><a href=\"https://github.com/Quramy/graphql-decorator\">graphql-decorator</a> - Helps to build GraphQL schema with TypeScript.</li>\n<li><a href=\"https://github.com/indigotech/graphql-schema-decorator\">graphql-schema-decorator</a> - This package makes possible the use of decorators to define a GraphQL schema.</li>\n<li><a href=\"https://github.com/vichyssoise/graphql-typescript\">graphql-typescript</a> - Define and build GraphQL Schemas using typed classes</li>\n<li><a href=\"https://github.com/prismake/typegql\">typegql</a> - Create GraphQL schema with type-safe class decorators.</li>\n</ul>\n<h3>Ruby Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/rmosolgo/graphql-ruby\">graphql-ruby</a> - Ruby implementation of Facebook's GraphQL.</li>\n<li>-</li>\n<li><a href=\"https://github.com/Shopify/graphql-parser\">graphql-parser</a> - A small ruby gem wrapping the libgraphqlparser C library for parsing Gr</li>\n<li>-</li>\n<li><a href=\"https://github.com/github/graphql-client\">graphql-client</a> - A Ruby library for declaring, composing and executing GraphQL queries.</li>\n<li>-</li>\n<li><a href=\"https://github.com/Shopify/graphql-batch\">graphql-batch</a> - A query batching executor for the graphql gem.</li>\n<li><a href=\"https://github.com/exaspark/batch-loader\">batch-loader</a> - A powerful tool to avoid N+1 queries without extra dependencies or primitives.</li>\n<li><a href=\"https://github.com/exAspArk/graphql-guard\">graphql-guard</a> - A simple field-level authorization for the graphql gem.</li>\n</ul>\n<h3>PHP Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/webonyx/graphql-php\">graphql-php</a> - A PHP port of GraphQL reference implementation.</li>\n<li>-</li>\n<li><a href=\"https://github.com/ivome/graphql-relay-php\">graphql-relay-php</a> - Relay helpers for GraphQL &#x26; PHP.</li>\n<li>-</li>\n<li><a href=\"https://github.com/api-platform/api-platform\">API Platform</a> - API framework compatible with Symfony having native GraphQL support.</li>\n<li>-</li>\n<li><a href=\"https://github.com/Folkloreatelier/laravel-graphql\">laravel-graphql</a> - Facebook GraphQL for</li>\n<li>-</li>\n<li><a href=\"https://github.com/nuwave/laravel-graphql-relay\">laravel-graphql-relay</a> - A Laravel library to help constr</li>\n<li>-</li>\n<li><a href=\"https://github.com/4rthem/graphql-mapper\">graphql-mapper</a> - This library allows to build a GraphQL schema based on your m</li>\n<li>-</li>\n<li><a href=\"https://github.com/suribit/GraphQLBundle\">graphql-bundle</a> - GraphQL Bundle for Symfony 2.</li>\n<li>-</li>\n<li><a href=\"https://github.com/overblog/GraphQLBundle\">overblog/graphql-bundle</a> - This bundle provides tools to build a complete GraphQL server i</li>\n<li>-</li>\n<li><a href=\"https://github.com/Youshido/GraphQL\">GraphQL</a> - Well documented PHP implementation with no dependencies.</li>\n<li><a href=\"https://github.com/Youshido/GraphQLBundle\">GraphQL Symfony Bundle</a> - GraphQL Bundle for the Symfony 3 (supports 2.6+).</li>\n<li><a href=\"https://github.com/wp-graphql/wp-graphql\">WPGraphQL</a> - WordPress plugin that exposes a Relay compliant GraphQL endpoint</li>\n<li><a href=\"https://github.com/tim-field/graphql-wp\">graphql-wp</a> - a WordPress plugin that exposes a GraphQL endpoint.</li>\n<li><a href=\"https://www.symfony.fi/entry/graphql-bundle-adds-protocol-support-to-ez-platform-symfony-cms\">eZ Platform GraphQL Bundle</a> - GraphQL Bundle for the eZ Platform Symfony CMS.</li>\n<li><a href=\"https://github.com/stefanorg/graphql-middleware\">GraphQL Middleware</a> - GraphQL Psr7 Middleware</li>\n<li><a href=\"https://github.com/stefanorg/zend-expressive-graphiql\">Zend Expressive GraphiQL Extension</a> - GraphiQL extension for zend expressive</li>\n<li><a href=\"https://github.com/digiaonline/graphql-php\">GraphQL for PHP7</a> - A batteries-included, standard-compliant and easy to work with implementation of the GraphQL specification in PHP7 (based on the reference implementation).</li>\n</ul>\n<h3>Python Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/tryolabs/graphql-parser\">graphql-parser</a> - GraphQL parser for Python.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-python/graphql-core\">graphql-core</a> - GraphQL implementation for Python.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-python/graphql-relay-py\">graphql-relay-py</a> - A library to help construct a graphql-py server suppor</li>\n<li>-</li>\n<li><a href=\"https://github.com/tallstreet/graphql-parser-python\">graphql-parser-python</a> - A python wrapper around libgraphqlpar</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-python/graphene\">graphene</a> - A package for creating GraphQL schemas/types in a Pythonic easy</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-python/graphene-gae\">graphene-gae</a> - Adds GraphQL support to Google AppEngine (GAE).</li>\n<li><a href=\"https://github.com/graphql-python/flask-graphql\">flask-graphql</a> - Adds GraphQL support to your Flask application.</li>\n<li><a href=\"https://github.com/graphcool/python-graphql-client\">python-graphql-client</a> - Simple GraphQL client for Python 2.7+</li>\n<li><a href=\"https://github.com/healx/python-graphjoiner\">python-graphjoiner</a> - Create GraphQL APIs using joins, SQL or otherwise.</li>\n<li><a href=\"https://github.com/graphql-python/graphene-django\">graphene-django</a> - A Django integration for Graphene.</li>\n</ul>\n<h3>Java Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/graphql-java/graphql-java\">graphql-java</a> - GraphQL Java implementation.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-java/graphql-java-type-generator\">graphql-java-type-generator</a> - Auto-generates types for use with GraphQL Java</li>\n<li>-</li>\n<li><a href=\"https://github.com/bpatters/schemagen-graphql\">schemagen-graphql</a> - Schema generation and execution package that</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-java/graphql-java-annotations\">graphql-java-annotations</a> - Provides annotations-based syntax f</li>\n<li>-</li>\n<li><a href=\"https://github.com/oembedler/spring-graphql-common\">spring-graphql-common</a> - Spring Framework GraphQL Library.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-java/graphql-spring-boot\">graphql-spring-boot</a> - GraphQL and GraphiQL Spring Framework Boot Starters.</li>\n<li>-</li>\n<li><a href=\"https://github.com/neo4j-graphql/neo4j-graphql\">neo4j-graphql</a> - GraphQL bindings for Neo4j, generates and runs Cypher.</li>\n<li><a href=\"https://github.com/engagingspaces/vertx-graphql-service-discovery\">vertx-graphql-service-discovery</a> - Asynchronous GraphQL service discovery and querying for your microservices.</li>\n<li><a href=\"https://github.com/engagingspaces/vertx-dataloader\">vertx-dataloader</a> - Port of Facebook DataLoader for efficient, asynchronous batching and caching in clustered GraphQL environments</li>\n<li><a href=\"https://github.com/Billy-Bichon/LiveGQL\">LiveGQL</a> - GraphQL subscription client in Java.</li>\n<li><a href=\"https://github.com/ebridges/rdbms-to-graphql\">rdbms-to-graphql</a> - A Java CLI program that generates a GraphQL schema from a JDBC data source.</li>\n<li><a href=\"https://github.com/google/rejoiner\">Rejoiner</a> - Generates a GraphQL schema based on one or more gRPC microservices, or any other Protobuf source.</li>\n<li><a href=\"https://github.com/leangen/graphql-spqr\">graphql-spqr</a> - GraphQL SPQR aims to make it dead simple to add a GraphQL API to any Java project. It works by dynamically generating a GraphQL schema from Java code.</li>\n</ul>\n<h3>C/C++ Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/graphql/libgraphqlparser\">libgraphqlparser</a> - A GraphQL query parser in C++ with C and C++ APIs.</li>\n</ul>\n<h3>Go Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/graphql-go/graphql\">graphql</a> - An implementation of GraphQL for Go follows graphql-js</li>\n<li>-</li>\n<li><a href=\"https://github.com/machinebox/graphql\">machinebox/graphql</a> - Simple low-level GraphQL client for Go</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-go/relay\">graphql-relay-go</a> - A Go/Golang library to help construct a server supporting react-relay.</li>\n<li>-</li>\n<li><a href=\"https://github.com/neelance/graphql-go\">graphql-go</a> - GraphQL server with a focus on ease of use.</li>\n<li>-</li>\n<li><a href=\"https://github.com/tecbot/c-graphqlparser\">c-graphqlparser</a> - Go-gettable version of the libgraphqlparser C library for parsing GraphQL.</li>\n<li><a href=\"https://github.com/tallstreet/graphql\">tallstreet-graphql</a> - GraphQL parser and server for Go that leverages libgraphqlparser</li>\n<li><a href=\"https://github.com/playlyfe/go-graphql\">go-graphql</a> - A powerful GraphQL server implementation for Golang</li>\n<li><a href=\"https://github.com/nicksrandall/dataloader\">dataloader</a> - Implementation of Facebook's DataLoader in Golang</li>\n</ul>\n<h3>Scala Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/sangria-graphql/sangria\">sangria</a> - Scala GraphQL client and server library.</li>\n<li>-</li>\n<li><a href=\"https://github.com/sangria-graphql/sangria-relay\">sangria-relay</a> - Sangria Relay Support.</li>\n<li><a href=\"https://github.com/hrosenhorn/graphql-scala\">graphql-scala</a> - An attempt to get GraphQL going with Scala.</li>\n</ul>\n<h3>Perl Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/CurtTilmes/Perl6-GraphQL\">Perl6-GraphQL</a> - GraphQL for Perl6.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-perl/graphql-perl\">graphql-perl</a> - GraphQL for Perl5.</li>\n</ul>\n<h3>.NET Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/graphql-dotnet/graphql-dotnet\">graphql-dotnet</a> - GraphQL for .NET.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-dotnet/conventions\">Conventions</a> - Reflection-based schema ge</li>\n<li>-</li>\n<li><a href=\"https://github.com/ckimes89/graphql-net\">graphql-net</a> - GraphQL to IQueryable for .NET</li>\n<li><a href=\"https://github.com/fsprojects/FSharp.Data.GraphQL\">FSharp.Data.GraphQL</a> - FSharp GraphQL.</li>\n<li><a href=\"https://github.com/graphql-dotnet/graphql-client\">GraphQL.Client</a> - GraphQL Client for .NET.</li>\n</ul>\n<h3>Erlang Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/shopgun/graphql-erlang\">graphql-erlang</a> - Pure Erlang implementation with IDL and pattern-matching.</li>\n</ul>\n<h3>Elixir Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/absinthe-graphql/absinthe\">absinthe-graphql</a> - Fully Featured Elixir GraphQL Library.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-elixir/graphql\">graphql-elixir</a> - GraphQL Elixir.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-elixir/plug_graphql\">plug_graphql</a> - Plug integration for GraphQL Elixir.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-elixir/graphql_relay\">graphql_relay</a> - Relay helpers for GraphQL Elixir.</li>\n<li><a href=\"https://github.com/graphql-elixir/graphql_parser\">graphql_parser</a> - Elixir bindings for <a href=\"https://github.com/graphql/libgraphqlparser\">libgraphqlparser</a></li>\n<li><a href=\"https://github.com/asonge/graphql\">graphql</a> - Elixir GraphQL parser.</li>\n<li><a href=\"https://github.com/peburrows/plot\">plot</a> - GraphQL parser and resolver for Elixir.</li>\n</ul>\n<h3>Haskell Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/jdnavarro/graphql-haskell\">graphql-haskell</a> - GraphQL AST and parser for Haskell.</li>\n</ul>\n<h3>SQL Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/solidsnack/GraphpostgresQL\">GraphpostgresQL</a> - GraphQL for Postgres.</li>\n<li>-</li>\n<li><a href=\"https://github.com/rexxars/sql-to-graphql\">sql-to-graphql</a> - Generate a GraphQL API based on your SQL database structure.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphile/postgraphile\">PostGraphile</a> - A GraphQL API created by reflection over a PostgreSQL schema.</li>\n<li>-</li>\n<li><a href=\"https://github.com/ebridges/rdbms-to-graphql\">rdbms-to-graphql</a> - A Java CLI program that generates a GraphQL schema from a JDBC data source.</li>\n<li><a href=\"https://github.com/graphcool/prisma\">Prisma</a> - Turn your database into a GraphQL API. Prisma lets you design your data model and have a production ready GraphQL API online in minutes.</li>\n<li><a href=\"https://github.com/bradleyboy/tuql\">tuql</a> - Automatically create a GraphQL server from any sqlite database.</li>\n</ul>\n<h3>Lua Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/bjornbytes/graphql-lua\">graphql-lua</a> - GraphQL for Lua.</li>\n</ul>\n<h3>Elm Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/jamesmacaulay/elm-graphql\">jamesmacaulay/elm-graphql</a> - Client library that lets you build GraphQL queries in Elm.</li>\n<li>-</li>\n<li><a href=\"https://github.com/ghivert/elm-graphql\">ghivert/elm-graphql</a> - Client library that lets you build GraphQL queries in Elm with your own decoders.</li>\n<li><a href=\"https://github.com/jahewson/elm-graphql\">jahewson/elm-graphql</a> - Command-line tool that generates Elm code from queries in .graphql files.</li>\n</ul>\n<h3>Clojure Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/tendant/graphql-clj\">graphql-clj</a> - A Clojure library designed to provide GraphQL implementation.</li>\n<li>-</li>\n<li><a href=\"https://github.com/walmartlabs/lacinia\">lacinia</a> - GraphQL implementation in pure Clojure.</li>\n<li><a href=\"https://github.com/alumbra/alumbra\">alumbra</a> - Simple &#x26; Elegant GraphQL for Clojure!</li>\n</ul>\n<h3>ClojureScript Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/johanatan/speako\">speako</a> - A ClojureScript/NPM compiler for GraphQL Schema Language.</li>\n<li>-</li>\n<li><a href=\"https://github.com/Vincit/venia\">venia</a> - A Clojure(Script) GraphQL query generation</li>\n</ul>\n<h3>Swift Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/GraphQLSwift/GraphQL\">GraphQL</a> - Build GraphQL APIs with Swift.</li>\n<li>-</li>\n<li><a href=\"https://github.com/GraphQLSwift/Graphiti\">Graphiti</a> - Build Swiftier GraphQL APIs with Swift.</li>\n<li>-</li>\n<li><a href=\"https://github.com/dbart01/Gryphin\">Gryphin</a> - Type-safe GraphQL client for iOS and MacOS written in Swift.</li>\n<li><a href=\"https://github.com/apollographql/apollo-ios\">Apollo-iOS</a> - Strongly typed, code-generating, caching GraphQL client for Swift.</li>\n<li><a href=\"https://github.com/florianmari/LiveGQL\">LiveGQL</a> - GraphQL Subscription client in Swift.</li>\n</ul>\n<h3>OCaml Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/andreas/ocaml-graphql-server\">ocaml-graphql-server</a> - GraphQL servers in OCaml.</li>\n</ul>\n<h3>Rust Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/mhallin/juniper\">juniper</a> - GraphQL server library for Rust.</li>\n</ul>\n<h3>R Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/ropensci/graphql\">graphql</a> - Bindings to libgraphqlparser for R.</li>\n<li>-</li>\n<li><a href=\"https://github.com/schloerke/gqlr\">gqlr</a> - GraphQL server package for R.</li>\n<li><a href=\"https://github.com/ropensci/ghql\">ghql</a> - GraphQL client package for R.</li>\n</ul>\n<h3>Julia Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/codeneomatrix/Diana.jl\">Diana.jl</a> - Julia client for GraphQL.</li>\n</ul>\n<h3>Kotlin Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/prestongarno/ktq\">ktq</a> - Kotlin gradle plugin SDL type generator &#x26; runtime client</li>\n</ul>\n<h3>Unity Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/Gazuntype/graphQL-client-unity\">graphQL-client-unity</a> - A Unity client for GraphQL.</li>\n</ul>\n<h3>Crystal Libraries</h3>\n<ul>\n<li><a href=\"https://github.com/ziprandom/graphql-crystal\">graphql-crystal</a> - A graphql implementation for Crystal</li>\n</ul>\n<h2>Tools</h2>\n<ul>\n<li><a href=\"https://github.com/graphql/graphiql\">graphiql</a> - An in-browser IDE for exploring GraphQL.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphcool/graphql-playground\">GraphQL Playground</a> - GraphQL IDE that supports multi-co</li>\n<li>-</li>\n<li><a href=\"https://github.com/skevy/graphiql-app\">GraphiQL.app</a> - A light, Electron-based wrapper a</li>\n<li>-</li>\n<li><a href=\"https://github.com/Macroz/GraphQLviz\">GraphQLviz</a> - GraphQLviz marries GraphQL (schemas) with Graphviz.</li>\n<li>-</li>\n<li><a href=\"https://github.com/sheerun/graphqlviz\">graphqlviz</a> - GraphQL API visualizer in Node.js</li>\n<li>-</li>\n<li><a href=\"https://facebook.github.io/relay/prototyping/playground.html\">Relay Playground</a></li>\n<li>-</li>\n<li><a href=\"https://dferber90.github.io/graphql-ast-explorer/\">GraphQL AST Explorer</a> - Explore the AST of a GraphQL document interactively</li>\n<li>-</li>\n<li><a href=\"https://www.graphqlhub.com/\">GraphQLHub</a> - Query public API's schemas (e.g. Reddit, Twitter, Github, etc) using GraphiQL</li>\n<li>-</li>\n<li><a href=\"https://github.com/jimkyndemeyer/js-graphql-intellij-plugin/\">js-graphql-intellij-plugin</a> - GraphQL language support for IntelliJ IDEA and WebStorm, including Relay.QL tagged</li>\n<li>-</li>\n<li><a href=\"https://github.com/syrusakbary/gdom\">gdom</a> - DOM Traversing and Scraping using GraphQL.</li>\n<li>-</li>\n<li><a href=\"https://github.com/almilo/annotated-graphql-server\">Annotated GraphQL Server</a> - Server for annotated GraphQL showing how to transform a REST api into a GraphQL endpoint with annotatio</li>\n<li>-</li>\n<li><a href=\"https://nathanrandal.com/graphql-visualizer/\">Model Visualizer</a> - A small webapp that generates an ERD-l</li>\n<li>-</li>\n<li><a href=\"https://github.com/Ghirro/graphql-network\">GraphQL Network</a> - A chrome dev-tools extension for debugging GraphQL network requests.</li>\n<li>-</li>\n<li><a href=\"https://github.com/apollographql/eslint-plugin-graphql\">eslint-plugin-graphql</a> - An ESLint plugin that checks your GraphQL strings against a schema.</li>\n<li>-</li>\n<li><a href=\"https://astexplorer.net/\">AST Explorer</a> - Select \"GraphQL\" at the top, explore the GraphQL AST and highlight different parts by clicking in the query.</li>\n<li>-</li>\n<li><a href=\"https://github.com/jparise/vim-graphql\">vim-graphql</a> - A Vim plugin that provides GraphQL file detection and syntax highlighting.</li>\n<li>-</li>\n<li><a href=\"https://github.com/sarkistlt/graphql-auto-generating-cms\">GraphQL CMS</a> - Use your existing GraphQL sche</li>\n<li>-</li>\n<li><a href=\"https://github.com/2fd/graphdoc\">graphdoc</a> - Static page generator for documenting GraphQL Schema.</li>\n<li><a href=\"https://github.com/orionsoft/atom-graphql-autocomplete\">graphql-autocomplete</a> - Autocomplete and lint from a GraphQL endpoint in Atom.</li>\n<li><a href=\"https://github.com/redound/graphql-ide\">GraphQL IDE</a> - An extensive IDE for exploring GraphQL API's.</li>\n<li><a href=\"https://github.com/yarax/swagger-to-graphql\">Swagger to GraphQL</a> - GraphQL types builder based on REST API described in Swagger. Allows to migrate to GraphQL from REST for 5 minutes</li>\n<li><a href=\"https://github.com/APIs-guru/graphql-voyager\">GraphQL Voyager</a> - Represent any GraphQL API as an interactive graph.</li>\n<li><a href=\"https://graphql-docs.com/\">GraphQL Docs</a> - Instantly create beautiful GraphQL API docs hosted online.</li>\n<li><a href=\"https://github.com/APIs-guru/graphql-faker\">GraphQL Faker</a> - 🎲 Mock or extend your GraphQL API with faked data. No coding required.</li>\n<li><a href=\"https://github.com/Quramy/ts-graphql-plugin\">ts-graphql-plugin</a> - A language service plugin complete and validate GraphQL query in TypeScript template strings.</li>\n<li><a href=\"https://launchpad.graphql.com/\">Apollo Launchpad</a> - Like JSFiddle for GraphQL server code, write and deploy a GraphQL API directly from your browser.</li>\n<li><a href=\"https://github.com/apollographql/apollo-tracing\">Apollo Tracing</a> - GraphQL extension that enables you to easily get resolver-level performance information as part of a GraphQL response.</li>\n<li><a href=\"https://github.com/imolorhe/altair\">Altair GraphQL Client</a> - A beautiful feature-rich GraphQL Client for all platforms.</li>\n<li><a href=\"https://github.com/abhiaiyer91/apollo-storybook-decorator\">Apollo Storybook Decorator</a> - Wrap your React Storybook stories with Apollo Client, provide mocks for isolated UI testing with GraphQL</li>\n<li><a href=\"https://github.com/Workpop/graphql-metrics\">GraphQL Metrics</a> - instrument GraphQL resolvers, logging response times and statuses (if there was an error or not) to the console as well as to InfluxDB.</li>\n<li><a href=\"https://github.com/Brbb/graphql-rover\">GraphQL Rover</a> - GraphQL schema interactive navigation, rearrange nodes, search and explore types and fields.</li>\n<li><a href=\"https://github.com/marmelab/json-graphql-server\">json-graphql-server</a> - Get a full fake GraphQL API with zero coding in less than 30 seconds, based on a JSON data file.</li>\n<li><a href=\"https://insomnia.rest/\">Insomnia</a> - An full-featured API client with first-party GraphQL query editor</li>\n<li><a href=\"https://github.com/sly777/ran\">RAN Toolkit</a> - Production-ready toolkit/boilerplate with support for GraphQL, SSR, Hot-reload, CSS-in-JS, caching, and more.</li>\n</ul>\n<h2>Databases</h2>\n<ul>\n<li><a href=\"https://www.arangodb.com/\">ArangoDB</a> - Multi-model database that supports GraphQL schemas in JavaScript inside the database.</li>\n<li>-</li>\n<li><a href=\"https://dgraph.io/\">Dgraph</a> - Scalable, distributed, low latency, high throughput Graph database with a GraphQL like language (called <a href=\"https://docs.dgraph.io/query-language/\">GraphQL+</a>) as the query language. Dgrapqh can be queried with graphql by using <a href=\"https://github.com/dpeek/dgraphql\">dgraphql</a></li>\n</ul>\n<h2>Services</h2>\n<ul>\n<li><a href=\"https://graphcms.com/\">GraphCMS</a> - GraphQL based Headless Content Management System.</li>\n<li>-</li>\n<li><a href=\"https://www.graph.cool/\">Graphcool</a> - Your own GraphQL backend in under 5 minutes. Works with every GraphQL client such as Relay and Apollo.</li>\n<li>-</li>\n<li><a href=\"https://hasura.io/\">Hasura</a> - Create tables and get a GraphQL backend in under 60s. Works on top of Postgres that y</li>\n<li>-</li>\n<li><a href=\"https://www.reindex.io/\">Reindex</a> - Instant GraphQL Backend for Your React Apps.</li>\n<li><a href=\"https://scaphold.io/\">Scaphold</a> - GraphQL as a service that includes API integrations such as Stripe and Mailgun.</li>\n<li><a href=\"https://tipe.io/\">Tipe</a> - Next Generation API-first CMS with a GraphQL or REST API. Stop letting your CMS decide how you build your apps.</li>\n<li><a href=\"https://aws.amazon.com/appsync/\">AWS AppSync</a> - Serverless GraphQL</li>\n</ul>\n<h2>Examples</h2>\n<h3>JavaScript Examples</h3>\n<ul>\n<li><a href=\"https://github.com/relayjs/relay-starter-kit\">relay-starter-kit</a> - Barebones starting point for a Relay application.</li>\n<li>-</li>\n<li><a href=\"https://github.com/kriasoft/react-starter-kit\">react-starter-kit</a> - Isomorphic web app boilerplate (Node.js/Express, GraphQL, React)</li>\n<li>-</li>\n<li><a href=\"https://github.com/kriasoft/nodejs-api-starter\">nodejs-api-starter</a> - Boilerplate and tooling for authoring data API b</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql/swapi-graphql\">swapi-graphql</a> - A GraphQL schema and server wrap</li>\n<li>-</li>\n<li><a href=\"https://github.com/RisingStack/graphql-server\">graphql-server</a> - GraphQL server with Mongoos</li>\n<li>-</li>\n<li><a href=\"https://github.com/clayallsopp/graphql-intro\">graphql-intro</a> - <a href=\"%3Chttps://medium\">&#x3C;https://medium</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/jonsharratt/graphql-aws\">graphql-aws</a> - Amazon AWS GraphQL API Server.</li>\n<li>-</li>\n<li><a href=\"https://github.com/RisingStack/graffiti-todo\">graffiti-todo</a> - Example Relay TodoMVC a</li>\n<li>-</li>\n<li><a href=\"https://gist.github.com/devknoll/8b274f1c5d05230bfade\">devknoll/gist:8b274f1c5d05230bfade</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/codefoundries/UniversalRelayBoilerplate\">UniversalRelayBoilerplate</a> Boilerplate + examples for React Native (iOS, Android), React (isomorphic,</li>\n<li>-</li>\n<li><a href=\"https://github.com/vslinko/ripster/tree/master/src/graphql\">vslinko/ripster</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/fortruce/relay-skeleton\">relay-skeleton</a> - React, Relay, GraphQL project skeleton</li>\n<li>-</li>\n<li><a href=\"https://github.com/mhart/simple-relay-starter\">simple-relay-starter</a> - A very simple starter for React Relay using Browserify.</li>\n<li>-</li>\n<li><a href=\"https://github.com/transedward/relay-chat\">relay-chat</a> - an chat example showing Relay with routing and pagination.</li>\n<li>-</li>\n<li><a href=\"https://github.com/taion/relay-todomvc\">relay-todomvc</a> - Relay TodoMVC with routing.</li>\n<li>-</li>\n<li><a href=\"https://github.com/mrblueblue/graphql-express-sqlite\">graphql-express-sqlite</a> - GraphQL server with Sqlite and Express</li>\n<li>-</li>\n<li>[koa-graphql-relay-example](<a href=\"https://github.com/chentsulin/koa-graphql-relay-exa\">https://github.com/chentsulin/koa-graphql-relay-exa</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/lvarayut/relay-fullstack\">relay-fullstack</a> - Relay Starter Kit integrated with Relay, GraphQL, Express, ES6/ES7, JSX, Webpack, Babel, Material Design Lite, an</li>\n<li>-</li>\n<li><a href=\"https://github.com/serverless/serverless-graphql-blog\">serverless-graphql-blog</a> - A Serverless Blog le</li>\n<li>-</li>\n<li><a href=\"https://github.com/soonlive/relay-cart\">relay-cart</a> - A simple shopping cart example leveraging relay &#x26; GraphQL with routing and pagination.</li>\n<li><a href=\"https://github.com/applification/graphql-loader\">graphql-loader</a> - Example project to illustrate GraphQL, Express and Facebook DataLoader to connect to third party REST API</li>\n<li><a href=\"https://github.com/alvinthen/swapi-graphql-lambda\">swapi-graphql-lambda</a> - A GraphQL schema hosted in AWS Lambda wrapping <a href=\"http://swapi.co/\">http://swapi.co/</a></li>\n<li><a href=\"https://dev.apollodata.com/react/\">Apollo Client documentation</a> - Documentation and example for building GraphQL apps using apollo client</li>\n<li><a href=\"https://www.apollographql.com/docs/\">Apollo Server tools, products, and libraries documentation</a> - Documentation, tutorial and examples for building GraphQL server and connecting to SQL, MongoDB and REST endpoints.</li>\n<li><a href=\"https://www.apollographql.com/docs/link/\">Apollo Link</a> - The official guide for getting started with Apollo Link - a standard interface for modifying control flow of GraphQL requests and fetching GraphQL results.</li>\n<li><a href=\"https://github.com/nnance/f8app-apollo\">f8-apollo</a> - Refactored version of the official F8 app of 2016, powered by React Native and the Apollo Stack.</li>\n<li><a href=\"https://github.com/fbsamples/f8app\">f8app</a> - Source code of the official F8 app of 2016, powered by React Native and other Facebook open source projects. <a href=\"https://makeitopen.com/\">http://makeitopen.com</a></li>\n<li><a href=\"https://github.com/reindexio/reindex-examples\">Reindex Examples</a> - Example projects for Reindex with using React Native and React.js for web.</li>\n<li><a href=\"https://julienvincent.github.io/modelizr/\">Modelizr Documentation</a> - Documentation and Usage Examples for modelizr</li>\n<li><a href=\"https://github.com/Akryum/frontpage-vue-app\">Vue Apollo Example</a> - Apollo example project for Vue 2.0.</li>\n<li><a href=\"https://github.com/kamilkisiela/angular2-graphql-rest\">angular2-graphql-rest</a> - An example app with REST Api working side by side with GraphQL using Apollo Client with angular2-apollo. Includes step-by-step tutorial how to migrate from REST to GraphQL.</li>\n<li><a href=\"https://github.com/entria/graphql-dataloader-boilerplate\">GraphQL-DataLoader-Boilerplate</a> - Boilerplate to start your GraphQL with DataLoader server</li>\n<li><a href=\"https://github.com/sibelius/graphql-cep\">GraphQL-CEP</a> - Query address by CEP</li>\n<li><a href=\"https://github.com/katopz/react-apollo-graphql-github-example\">Apollo React example for Github GraphQL API</a> - Usage Examples Apollo React for Github GraphQL API with create-react-app</li>\n<li><a href=\"https://github.com/xpepermint/graphql-example\">Intuitive GraphQL Resolver Example</a> - GraphQL application example using <a href=\"https://github.com/xpepermint/rawmodeljs\">RawModel.js</a>.</li>\n<li><a href=\"https://reactql.org/\">ReactQL starter kit</a> - Universal React + Apollo + Redux + React Router 4, with SSR-enabled GraphQL, store (de/re)hydration and production code bundling.</li>\n<li><a href=\"https://github.com/stubailo/microhn\">microhn</a> - Simple Hacker News client built on top of GraphQLHub</li>\n<li><a href=\"https://github.com/sysgears/apollo-universal-starter-kit\">Apollo Web&#x26;Mobile Universal Starter Kit with Hot Code Reload</a> - Apollo, GraphQL, React, React Native, Expo, Redux, Express, SQL and Twitter Bootstrap. Hot Code Reload of back end &#x26; front end using Webpack and Hot Module Replacement.</li>\n<li><a href=\"https://malloc.fi/building-decoupled-sites-and-apps-with-graphql-and-next-js\">Building Decoupled Sites and Apps with GraphQL and Next.js</a></li>\n</ul>\n<h3>TypeScript Examples</h3>\n<ul>\n<li><a href=\"https://github.com/DxCx/webpack-graphql-server\">Basic Apollo Server</a> - Basic Starter for Apollo Server, Using typescript and Webpack.</li>\n<li>-</li>\n<li><a href=\"https://github.com/FinalDes/apollo-express-ts-server-boilerplate\">Apollo Graphql Express Server</a> - Minimal Apollo Graphql Express Server</li>\n<li><a href=\"https://github.com/KATT/shop\">Prisma/Apollo/React Full-stack Example</a> - An e-commerce example project with Prisma, GraphQL API Gateway, React, Apollo, Next.js, SSR, CI, and E2E testing. All TypeScript.</li>\n</ul>\n<h3>Ruby Examples</h3>\n<ul>\n<li><a href=\"https://github.com/rmosolgo/graphql-ruby-demo\">graphql-ruby-demo</a> - Use graphql-ruby to expose a Rails app.</li>\n<li>-</li>\n<li><a href=\"https://github.com/github/github-graphql-rails-example\">github-graphql-rails-example</a> - Example Rails app using GitHub's GraphQL API.</li>\n<li>-</li>\n<li><a href=\"https://github.com/nethsix/relay-on-rails\">relay-on-rails</a> - Barebones starter kit for Relay application with Rails GraphQL server.</li>\n<li><a href=\"https://github.com/gauravtiwari/relay-rails-blog\">relay-rails-blog</a> - A graphql, relay and standard rails application powered demo weblog.</li>\n<li><a href=\"https://github.com/jcdavison/to_eat_app\">to<em>eat</em>app</a> - A sample graphql/rails/relay application with a related 3-part article series.</li>\n</ul>\n<h3>Go Examples</h3>\n<ul>\n<li><a href=\"https://github.com/sogko/golang-relay-starter-kit\">golang-relay-starter-kit</a> - Barebones starting point for a Relay application with Golang GraphQL server.</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-go/playground\">golang-graphql-playground</a> - An example Golang GraphQL server written with graphql-go and graphql-relay-go. Try live demo at: <a href=\"https://golanggraphqlplayground-sogko.rhcloud.com/\">http://golanggraphqlplayground-sogko.rhcloud.com</a></li>\n<li><a href=\"https://github.com/sogko/todomvc-relay-go\">todomvc-relay-go</a> - Port of the React/Relay TodoMVC app, driven by a Golang GraphQL backend.</li>\n</ul>\n<h3>Scala Examples</h3>\n<ul>\n<li><a href=\"https://github.com/sangria-graphql/sangria-akka-http-example\">sangria-akka-http-example</a> - An example GraphQL server written with akka-http and <a href=\"https://sangria-graphql.org/\">sangria</a></li>\n<li>-</li>\n<li><a href=\"https://github.com/sangria-graphql/sangria-playground\">sangria-playground</a> - An example of GraphQL server written with Play and sangria.</li>\n</ul>\n<h3>Python Examples</h3>\n<ul>\n<li><a href=\"https://github.com/graphql-python/swapi-graphene\">swapi-graphene</a> - A GraphQL schema and server using <a href=\"https://graphene-python.org/\">Graphene</a> - <a href=\"https://swapi.graphene-python.org/\">View demo online</a>.</li>\n</ul>\n<h3>Elixir Examples</h3>\n<ul>\n<li><a href=\"https://github.com/absinthe-graphql/absinthe_example\">absinthe_example</a> - Example usage of Absinthe GraphQL</li>\n<li>-</li>\n<li><a href=\"https://github.com/graphql-elixir/hello_graphql_phoenix\">hello<em>graphql</em>phoenix</a> - Examples of GraphQL Elixir Plug endpoints mounted in Phoenix - <a href=\"https://playground.graphql-elixir.org/\">View demo online</a>.</li>\n</ul>\n<h3>PHP Examples</h3>\n<ul>\n<li><a href=\"https://siler.leocavalcante.com/graphql/\">Siler's GraphQL guide</a> - A guide on how to build a PHP GraphQL endpoint.</li>\n<li>-</li>\n<li><a href=\"https://github.com/ardani/laravel-graphql\">Laravel GraphQL</a> - A sample integrating GraphQL with Laravel</li>\n<li><a href=\"https://symfony.fi/entry/adding-a-graphql-api-to-your-symfony-flex-app\">Adding a GraphQL API to your Symfony Flex application</a></li>\n</ul>\n<h3>ReasonML Examples</h3>\n<ul>\n<li><a href=\"https://github.com/Gregoirevda/reason-ml-graphql-todo-list\">Todo list example</a> - A todo list integrating GraphQL.</li>\n</ul>\n<h2>Videos</h2>\n<ul>\n<li><a href=\"https://egghead.io/lessons/react-zero-config-apollo-graphql-with-apollo-boost\">Zero-config Apollo + GraphQL with Apollo Boost</a></li>\n<li>-</li>\n<li><a href=\"https://www.youtube.com/embed/UBGzsb2UkeY\">Zero to GraphQL in 30 Minutes</a></li>\n<li>-</li>\n<li>[Data fetching for React applications at Facebook](<a href=\"https://www.you\">https://www.you</a></li>\n<li>-</li>\n<li>[React Native &#x26; Relay: Bringing Modern Web Techniques to Mobile](<a href=\"https://www.yo\">https://www.yo</a></li>\n<li>-</li>\n<li><a href=\"https://www.youtube.com/watch?v=WQLzZf34FJ8\">Exploring GraphQL</a></li>\n<li>-</li>\n<li><a href=\"https://www.youtube.com/watch?v=gY48GW87Feo\">Creating a GraphQL Server</a></li>\n<li>-</li>\n<li>[GraphQL at The Financial Times](<a href=\"https://www.youtube.com/watch?v=S0s935RKK\">https://www.youtube.com/watch?v=S0s935RKK</a></li>\n<li>-</li>\n<li><a href=\"https://www.youtube.com/watch?v=IrgHurBjQbg\">Relay: An Application Framework For React</a></li>\n<li>-</li>\n<li>[Building and Deploying Relay with Facebook](<a href=\"https://www.youtube.com/watch?t=643&#x26;v=P\">https://www.youtube.com/watch?t=643&#x26;v=P</a></li>\n<li>-</li>\n<li><a href=\"https://vimeo.com/144817545\">Introduction to GraphQL</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=_9RgHXqH8J0\">Exploring GraphQL@Scale</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=IMUpYOc9z3c&#x26;feature=youtu.be\">What's Next for Phoenix by Chris McCord</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=Ed6oJXKt3-M\">GraphQL with Nick Schrock</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=DNPVqK_woRQ\">Build a GraphQL server for Node.js using PostgreSQL/MySQL</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=PHabPhgRUuU\">GraphQL server tutorial for Node.js with SQL, MongoDB and REST</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=ENqDNIp1Nd8\">JavaScript Air Episode 023: Transitioning from REST to GraphQL</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=ViXL0YQnioU\">GraphQL Future at react-europe 2016</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=etax3aEe2dA\">GraphQL at Facebook at react-europe 2016</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=z5rz3saDPJ8\">Building native mobile apps with GraphQL at react-europe 2016</a></li>\n</ul>\n<h2>Blogs</h2>\n<ul>\n<li><a href=\"https://graphql.org/blog/\">Official GraphQL blog</a></li>\n<li>-</li>\n<li><a href=\"https://dev-blog.apollodata.com/\">Building Apollo</a></li>\n</ul>\n<h2>Posts</h2>\n<ul>\n<li><a href=\"https://gajus.com/blog/9/using-dataloader-to-batch-requests\">Using DataLoader to batch GraphQL requests</a></li>\n<li>-</li>\n<li>[Introducing Relay and GraphQL](<a href=\"https://facebook.github.io/react/blog/2015/02/20/introducing-relay-a\">https://facebook.github.io/react/blog/2015/02/20/introducing-relay-a</a></li>\n<li>-</li>\n<li><a href=\"https://facebook.github.io/react/blog/2015/05/01/graphql-introduction.html\">GraphQL Introduction</a></li>\n<li>-</li>\n<li><a href=\"https://gist.github.com/wincent/598fa75e22bdfa44cf47\">Unofficial Relay FAQ</a></li>\n<li>-</li>\n<li>[Your First GraphQL Server](<a href=\"https://medium.com/@clayallsopp/your-first-graphql-server-3c766ab4f\">https://medium.com/@clayallsopp/your-first-graphql-server-3c766ab4f</a></li>\n<li>-</li>\n<li>[GraphQL Overview - Getting Started with GraphQL and Node.js](<a href=\"https://blog.risingstack.com/graphql-overview-getting-started-wit\">https://blog.risingstack.com/graphql-overview-getting-started-wit</a></li>\n<li>-</li>\n<li>[4 Reasons you should try out GraphQL](<a href=\"https://medium.freecodecamp.com/introdu\">https://medium.freecodecamp.com/introdu</a></li>\n<li>-</li>\n<li><a href=\"https://medium.com/@frikille/moving-from-rest-to-graphql-e3650b6f5247\">Moving from REST to GraphQL</a></li>\n<li>-</li>\n<li>[Writing a Basic API with GraphQL](<a href=\"http://davidandsuzi.com/writing-a-basic\">http://davidandsuzi.com/writing-a-basic</a>-</li>\n<li>-</li>\n<li>[Start using GraphQL with Graffiti](<a href=\"https://blog.risingstack.com/start-using-graphql-with-graffiti/\">https://blog.risingstack.com/start-using-graphql-with-graffiti/</a></li>\n<li>-</li>\n<li>[Building a GraphQL Server with Node.js and SQL](<a href=\"https://www.reindex.io/blog/building-a-graphql-server-with-node-js-a\">https://www.reindex.io/blog/building-a-graphql-server-with-node-js-a</a></li>\n<li>-</li>\n<li><a href=\"https://www.slideshare.net/LondonReact/graph-ql\">GraphQL at The Financial Times</a></li>\n<li>-</li>\n<li><a href=\"https://sgwilym.github.io/relay-visual-learners/\">Relay for visual learners</a></li>\n<li>-</li>\n<li><a href=\"https://medium.com/@cpojer/relay-and-routing-36b5439bad9\">Relay and Routing</a></li>\n<li>-</li>\n<li><a href=\"https://wehavefaces.net/learn-golang-graphql-relay-1-e59ea174a902\">Learn Golang + GraphQL + Relay, Part 1: Your first Golang GraphQL server</a></li>\n<li><a href=\"https://wehavefaces.net/learn-golang-graphql-relay-2-a56cbcc3e341\">Learn Golang + GraphQL + Relay, Part 2: Your first Relay application</a></li>\n<li><a href=\"https://0x2a.sh/from-rest-to-graphql-b4e95e94c26b\">From REST to GraphQL</a></li>\n<li><a href=\"https://graphql.org/blog/graphql-a-query-language/\">GraphQL: A data query language</a></li>\n<li><a href=\"https://graphql.org/blog/subscriptions-in-graphql-and-relay/\">Subscriptions in GraphQL and Relay</a></li>\n<li><a href=\"https://medium.com/@clayallsopp/relay-101-building-a-hacker-news-client-bb8b2bdc76e6\">Relay 101: Building A Hacker News Client</a></li>\n<li><a href=\"https://wehavefaces.net/graphql-shorthand-notation-cheatsheet-17cd715861b6\">GraphQL Shorthand Notation Cheatsheet</a></li>\n<li><a href=\"https://githubengineering.com/the-github-graphql-api/\">The GitHub GraphQL API</a></li>\n<li><a href=\"https://medium.com/@katopz/github-graphql-api-react-example-eace824d7b61\">Github GraphQL API React Example</a></li>\n<li><a href=\"https://medium.com/entria/testing-a-graphql-server-using-jest-4e00d0e4980e\">Testing a GraphQL Server using Jest</a></li>\n<li><a href=\"https://medium.com/entria/how-to-implement-viewercansee-in-graphql-78cc48de7464\">How to implement viewerCanSee in GraphQL</a></li>\n<li><a href=\"https://engineeringblog.yelp.com/2017/05/introducing-yelps-local-graph.html\">Introducing Yelp's Local Graph</a></li>\n<li><a href=\"https://labs.getninjas.com.br/sharing-data-in-a-microservices-architecture-using-graphql-97db59357602\">Sharing data in a Microservices Architecture using GraphQL</a></li>\n<li><a href=\"https://blog.codecentric.de/2017/09/graphql-mit-spotify-teil-1-server/\">Let's build a node.js GraphQL server for fetching Spotify REST API, in German</a> | <a href=\"https://blog.codecentric.de/en/2017/01/lets-build-spotify-graphql-server/\">in English</a></li>\n<li><a href=\"https://medium.com/@pierrecriulanscy/client-side-only-realtime-web-applications-with-firebase-graphql-and-apollo-client-2-0-9606160f7cf8\">\"Client-side only\" realtime web applications with Firebase, GraphQL and apollo-client 2.0</a></li>\n</ul>\n<h2>Tutorials</h2>\n<ul>\n<li><a href=\"https://www.howtographql.com/\">How to GraphQL</a> - Fullstack Tutorial Website with Tracks for all Major Frameworks &#x26; Languages including React, Apollo, Relay, JavaScript, Ruby, Java, Elixir and many more</li>\n<li>-</li>\n<li><a href=\"https://github.com/mugli/learning-graphql\">learning-graphql</a> - An attempt to learn</li>\n<li>-</li>\n<li><a href=\"https://www.learnrelay.org/\">Learn Relay</a> - A comprehensive introduction to Relay</li>\n<li><a href=\"https://www.learnapollo.com/\">Learn Apollo</a> - A hands-on tutorial for Apollo GraphQL Client</li>\n</ul>"},{"url":"/blog/code-playgrounds-of-2021/","relativePath":"blog/code-playgrounds-of-2021.md","relativeDir":"blog","base":"code-playgrounds-of-2021.md","name":"code-playgrounds-of-2021","frontmatter":{"title":"Code Playgrounds of 2021","template":"post","subtitle":"A plethora of front-end code playgrounds have appeared over the years. They offer a convenient way to experiment with client-side code and…","excerpt":"A plethora of front-end code playgrounds have appeared over the years. They offer a convenient way to experiment with client-side code and…","date":"2022-05-29T01:42:52.008Z","image":"https://cdn-images-1.medium.com/max/800/1*oUZy2IkIQGDbkSVQRGCvKQ.png","thumb_image":"https://cdn-images-1.medium.com/max/800/1*oUZy2IkIQGDbkSVQRGCvKQ.png","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/content-management.yaml"],"tags":["src/data/tags/cms.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/embedding-media-in-html.md"],"cmseditable":true},"html":"<h1>The Best Cloud-Based Code Playgrounds of 2021 (Part 1)</h1>\n<p>A plethora of front-end code playgrounds have appeared over the years. They offer a convenient way to experiment with client-side code and…</p>\n<hr>\n<h3>The Best Cloud-Based Code Playgrounds of 2021 (Part 1)</h3>\n<h4><strong>A plethora of front-end code playgrounds have appeared over the years. They offer a convenient way to experiment with client-side code and teach/share with others without the hassle of configuring a development environment.</strong></h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*oUZy2IkIQGDbkSVQRGCvKQ.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Typical features of these online playgrounds include:</h3>\n<ul>\n<li><span id=\"3386\"><strong><em>color-coded HTML, CSS and JavaScript editors</em></strong></span></li>\n<li><span id=\"152b\"><strong><em>a preview window — many update on the fly without a refresh</em></strong></span></li>\n<li><span id=\"c746\"><strong><em>HTML pre-processors such as HAML</em></strong></span></li>\n<li><span id=\"bf6f\"><strong><em>LESS, SASS and Stylus CSS pre-processing</em></strong></span></li>\n<li><span id=\"8093\"><strong><em>inclusion of popular JavaScript libraries</em></strong></span></li>\n<li><span id=\"b6d5\"><strong><em>developer consoles and code validation tools</em></strong></span></li>\n<li><span id=\"98e5\"><strong><em>sharing via a short URL</em></strong></span></li>\n<li><span id=\"e7c5\"><strong><em>embedding demonstrations in other pages</em></strong></span></li>\n<li><span id=\"2e11\"><strong><em>code forking</em></strong></span></li>\n<li><span id=\"efa6\"><strong><em>zero cost (or payment for premium services only)</em></strong></span></li>\n<li><span id=\"782a\"><strong><em>showing off your coding skills to the world!</em></strong></span></li>\n</ul>\n<hr>\n<h4>The following list is in no particular order and which playground you use is a matter of application and personal taste, they each have their own specialities.</h4>\n<hr>\n<h3>1.) REPL.IT</h3>\n<h3>My personal favorite for it's simplicity, versatility and capabilities.</h3>\n<h3>⚫No downloads, no configs, no setups</h3>\n<p>In your browser. Repl.it runs fully in your browser, so you can get started coding in seconds. No more ZIPs, PKGs, DMGs and WTFs.</p>\n<blockquote>\n<p>Any OS, any device<strong><em>(I'm looking at you chromebook coders)</em></strong>. You can use Repl.it on macOS, Windows, Linux, or any other OS .</p>\n</blockquote>\n<h3>⚫Clone, commit and push to any GitHub repo.</h3>\n<p>Repl from Repo. Get started with any Github repo, right from your browser. Commit and push without touching your terminal.</p>\n<h3>⚫<a href=\"https://blog.replit.com/markdown-preview\" class=\"markup--anchor markup--h3-anchor\">Markdown Preview</a></h3>\n<p><strong>>A new but fundamentally important feature</strong></p>\n<h3>⚫<a href=\"https://blog.replit.com/unit-tests\" class=\"markup--anchor markup--h3-anchor\">No-setup Unit Testing</a></h3>\n<p><strong>>Unit testing is a powerful way to verify that code works as intended and creates a quick feedback loop for development &#x26; learning. However, setting up a reproducible unit-testing environment is a time-consuming and delicate affair. Repl.it now features zero-setup unit testing!</strong></p>\n<h3>⚫<a href=\"https://blog.replit.com/https\" class=\"markup--anchor markup--h3-anchor\">HTTPS by default</a></h3>\n<h4>In the example below I have 72 solved Javascript Leetcode Problems but REPL.IT can handle almost any language you can think of.</h4>\n<h3>Here's another one that contains the Repl.it Docs:</h3>\n<hr>\n<h3>JS-Fiddle</h3>\n<blockquote>\n<a href=\"https://jsfiddle.net/\" class=\"markup--anchor markup--blockquote-anchor\">\n<strong>\n<em>jsFiddle</em>\n</strong>\n</a> **_is a cloud-based JavaScript code playground that allows web developers to tweak their code and see the results of this tweaking in real time. The editor supports not only JavaScript and its variants but also HTML and CSS code, and it further supports popular JavaScript frameworks, such as jQuery, AngularJS, ReactiveJS and D3. The ad-supported site is also completely free to use._**\n</blockquote>\n<h3>⚫Entering and running code</h3>\n<blockquote>\n<p>JSFiddle has the notion of panels (or tabs if you switch into the tabbed layout), there are 4 panels, 3 where you can enter code, and 1 to see the result.</p>\n</blockquote>\n<ul>\n<li><span id=\"0c0b\"><strong>HTML</strong> — structure code, no need to add <code class=\"language-text\">body</code> <code class=\"language-text\">doctype</code> <code class=\"language-text\">head</code>, that's added automatically</span></li>\n<li><span id=\"b95b\"><strong>CSS</strong> — styles. You can switch pre-pocessor to SCSS</span></li>\n<li><span id=\"1709\"><strong>JavaScript</strong> — behavior. There are many frameworks and code pre-processors you can use</span></li>\n</ul>\n<p>Once you enter code, just hit <strong>Run</strong> in the top actions bar, and the fourth panel with results will appear.</p>\n<h3>⚫Saving and Forking code</h3>\n<ul>\n<li><span id=\"f034\"><strong>Save</strong> / <strong>Update</strong> will do what you think, it'll save a new fiddle or update an existing one (and add a version number to it)</span></li>\n<li><span id=\"f634\"><strong>Fork</strong> will split out an existing fiddle into a new one, starting with version 0</span></li>\n</ul>\n<hr>\n<h3>StackBlitz</h3>\n<p><a href=\"https://stackblitz.com/\" class=\"markup--anchor markup--p-anchor\">StackBlitz</a></p>\n<ul>\n<li><span id=\"9cf4\"><strong>Installs packages ≥5x faster than Yarn &#x26; NPM 🔥</strong></span></li>\n<li><span id=\"d50f\"><strong>Reduces the size of</strong> <code class=\"language-text\">node_modules</code> <strong>up to two orders of magnitude 😮</strong></span></li>\n<li><span id=\"288c\"><strong>Has multiple layers of redundancy for production grade reliability</strong> 💪</span></li>\n<li><span id=\"ba5d\"><strong>Works <em>entirely</em> within your web browser, enabling lightning fast dev environments ⚡️</strong></span></li>\n</ul>\n<blockquote>\n<p>Dependencies still slip into the install process as dev &#x26; sub-dependencies and are downloaded &#x26; extracted all the same, resulting in the infamous black hole known as <code class=\"language-text\">node_modules</code>:</p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/0*-6LsqMPgWtP9NSBl.png\" class=\"graf-image\" />\n</figure>**Dank, relevant meme (pictured Left)**\n<p><strong>This is the crux of what prevents NPM from working natively in-browser. Resolving, downloading, and extracting the hundreds of megabytes (or gigabytes) typical frontend projects contain in their</strong> <code class=\"language-text\">node_modules</code> <strong>folder is a challenge browsers just aren't well suited for. Additionally, this is also why existing server side solutions to this problem have proven to be</strong> <a href=\"https://github.com/unpkg/unpkg/issues/35#issuecomment-317128917\" class=\"markup--anchor markup--p-anchor\">\n<strong>slow, unreliable</strong>\n</a></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*sl4vb3fP9-MErkioiCOyKQ.png\" class=\"graf-image\" />\n</figure>### Then just paste the embed code in an iframe and you're good to go!\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*PjhrjtInF1dPudtO.png\" class=\"graf-image\" />\n</figure>\n<a href=\"https://stackblitz.com/\" class=\"markup--anchor markup--blockquote-anchor\">\n<strong>\n<em>On StackBlitz.com</em>\n</strong>\n</a>**, you can create new projects and get the embed code from the ‘Share' dropdown link in the top navigation like so:**\n<h3>Embed Options</h3>\n<blockquote>\n<p><strong><em>&#x3C;iframe src=\"<a href=\"https://stackblitz.com/edit/angular?embed=1%22%3E%3C/iframe%3C\">https://stackblitz.com/edit/angular?embed=1\">&#x3C;/iframe></a>;</em></strong></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*6QF4ywBOMVFtS_MukRkLKw.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*5ekSGpNwJ28hI9Aog8V4DQ.png\" class=\"graf-image\" />\n</figure>🡩 **Alternatively, you can also use StackBlitz's** <a href=\"https://developer.stackblitz.com/docs/platform/embedding#open-and-embed-stackblitz-projects\" class=\"markup--anchor markup--blockquote-anchor\">\n<strong>Javascript SDK methods</strong>\n</a> **for easily embedding StackBlitz projects on the page & avoid all the hassles of creating/configuring iframes.**\n<p><span class=\"graf-dropCap\">H</span><strong>ere's a sample project of mine, it's a medium clone… <em>(So Metta)</em>… feel free to write a post… or don't …but either way … as you can see… Stack Blitz enables you to write serious web applications in a fraction of the time it would take with a conventional setup.</strong></p>\n<hr>\n<h3>Glitch</h3>\n<h3>⚫<a href=\"https://glitch.com/\" class=\"markup--anchor markup--h3-anchor\"></h3>\n<strong>\n<em>Glitch</em>\n</strong>\n</a> ** provides two project templates that you can use to start creating your app:**\n<ol>\n<li><span id=\"9488\"><strong>Classic Website</strong></span></li>\n<li><span id=\"ff69\"><strong>Node.js</strong></span></li>\n</ol>\n<p>If you know the type of project that you would like to create, <a href=\"https://glitch.com/create-project\" class=\"markup--anchor markup--p-anchor\">click here to get started!</a> Or keep reading to learn more about the Classic Website and Node.js templates.</p>\n<h3>⚫<strong>Classic Website</strong></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*AMVRXebQBuww_n_P.png\" class=\"graf-image\" />\n</figure>The **Classic Website** template is your starting point for creating a **static** website that includes an index.html page and static HTML, JavaScript, and CSS. Just start typing and your work will be live on the internet! Static websites enjoy unlimited uptime too! This means that your website stays on 24/7 without using your <a href=\"https://glitch.happyfox.com/kb/article/17/#Uptime\" class=\"markup--anchor markup--p-anchor\">Project Hours</a>.\n<p>An existing project will be identified by Glitch as a <strong>static</strong> site if it does not contain one of the following files:</p>\n<ul>\n<li><span id=\"69e6\"><strong>package.json</strong></span></li>\n<li><span id=\"fbe0\"><strong>requirements.txt</strong></span></li>\n<li><span id=\"4fe5\"><strong>glitch.json</strong></span></li>\n</ul>\n<h3>⚫<strong>Node.js</strong></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ppgGuMTHg-YxnImp.png\" class=\"graf-image\" />\n</figure>If you are looking to build a full-stack JavaScript application, choose the **Node.js** template. This template includes both front-end and back-end code using the popular <a href=\"https://expressjs.com/\" class=\"markup--anchor markup--p-anchor\">Express</a> Node.js application framework.\n<h3>⚫<strong>Here are some other ways to get started on Glitch…</strong></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*duFOnYTuCHLsfxFi.png\" class=\"graf-image\" />\n</figure>-   <span id=\"4b22\">Create an app by <a href=\"https://glitch.happyfox.com/kb/article/20-can-i-import-code-from-a-github-repository/\" class=\"markup--anchor markup--li-anchor\">importing a GitHub repo</a>.</span>\n-   <span id=\"dbd9\">Build an app that integrates with a popular third-party platform or framework, by remixing <a href=\"https://glitch.com/create\" class=\"markup--anchor markup--li-anchor\">one of these starter templates</a>.</span>\n<p><strong>Still not sure where to start? Check out these categories of community-built apps for inspiration:</strong></p>\n<ul>\n<li>\n<span id=\"53a7\">\n<a href=\"https://glitch.com/@glitch/games\" class=\"markup--anchor markup--li-anchor\">Games</a>\n</span>\n</li>\n<li>\n<span id=\"05b5\">\n<a href=\"https://glitch.com/@glitch/bots\" class=\"markup--anchor markup--li-anchor\">Bots</a>\n</span>\n</li>\n<li>\n<span id=\"a9e4\">\n<a href=\"https://glitch.com/@glitch/music\" class=\"markup--anchor markup--li-anchor\">Music</a>\n</span>\n</li>\n<li>\n<span id=\"0d44\">\n<a href=\"https://glitch.com/@glitch/art\" class=\"markup--anchor markup--li-anchor\">Art</a>\n</span>\n</li>\n<li>\n<span id=\"8927\">\n<a href=\"https://glitch.com/@glitch/tools-for-work\" class=\"markup--anchor markup--li-anchor\">Productivity</a>\n</span>\n</li>\n<li>\n<span id=\"7068\">\n<a href=\"https://glitch.com/@glitch/hardware\" class=\"markup--anchor markup--li-anchor\">Hardware</a>\n</span>\n</li>\n<li>\n<span id=\"5dd4\">\n<a href=\"https://glitch.com/@glitch/building-blocks\" class=\"markup--anchor markup--li-anchor\">Building Blocks</a>\n</span>\n</li>\n<li>\n<span id=\"0c79\">\n<a href=\"https://glitch.com/@glitch/learn-to-code\" class=\"markup--anchor markup--li-anchor\">Learn to Code</a>\n</span>\n</li>\n</ul>\n<h3>Here's a (temporarily) broken version of my personal portfolio .. hosted on glitch</h3>\n<h4>Click ‘view app' below to see how it renders</h4>\n<hr>\n<h3>If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content:</h3>\n<a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://gist.github.com/bgoonz\">\n<strong>bgoonz's gists</strong>\n<br />\n<em>Instantly share code, notes, and snippets. Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python |…</em>gist.github.com</a>\n<a href=\"https://gist.github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>Or Checkout my personal Resource Site:</h3>\n<a href=\"https://web-dev-resource-hub.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://web-dev-resource-hub.netlify.app/\">\n<strong>Web-Dev-Resource-Hub</strong>\n<br />\n<em>Edit description</em>web-dev-resource-hub.netlify.app</a>\n<a href=\"https://web-dev-resource-hub.netlify.app/\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/cdae9448db24\">March 20, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/the-best-cloud-based-code-playgrounds-of-2021-part-1-cdae9448db24\" class=\"p-canonical\">Canonical link</a></p>\n<p>on September 23, 2021.</p>"},{"url":"/blog/data-structures-algorithms-resources/","relativePath":"blog/data-structures-algorithms-resources.md","relativeDir":"blog","base":"data-structures-algorithms-resources.md","name":"data-structures-algorithms-resources","frontmatter":{"title":"Data Structures & Algorithms Resources","template":"post","subtitle":"Links to useful educational resources","excerpt":"Talk is cheap. Show me the code.  Software is like sex: it's better when it's free.  Microsoft isn't evil, they just make really crappy operating systems.","date":"2022-04-09T12:24:38.027Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.png?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/ds.yaml"],"tags":["src/data/tags/data-structures-algorithms.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/data-structures-algorithms-resources.md"],"cmseditable":true},"html":"<h1>Data Structures &#x26; Algorithms Resource List Part 1</h1>\n<p>Guess the author of the following quotes:</p>\n<h2>Data Structures &#x26; Algorithms Resource List Part 1 <a id=\"60dd\"></h2>\n</a>\n<p>Guess the author of the following quotes:</p>\n<blockquote>\n<p><em>Talk is cheap. Show me the code.</em></p>\n<p><em>Software is like sex: it's better when it's free.</em></p>\n<p><em>Microsoft isn't evil, they just make really crappy operating systems.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*rbMyH5LxQQFozL7F\" alt=\"image\"></p>\n<h2>Update: <a id=\"4129\"></h2>\n</a>\n<h3>Here's some more: <a id=\"42ff\"></h3>\n</a>\n<ul>\n<li>[The Framework for Learning Algorithms and intense problem solving exercises](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/Framework%20and%20thoughts%20about%20learning%20data%20structure%20and%20algorithm.md)</li>\n<li>[Algs4: Recommended book for Learning Algorithms and Data Structures](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/why<em>i</em>recommend_algs4.md)</li>\n<li>[An analysis of Dynamic Programming](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/AnalysisOfDynamicProgramming.md)</li>\n<li>[Dynamic Programming Q&#x26;A — What is Optimal Substructure](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/OptimalSubstructure.md)</li>\n<li>[The Framework for Backtracking Algorithm](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/DetailsaboutBacktracking.md)</li>\n<li>[Binary Search in Detail: I wrote a Poem](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/DetailedBinarySearch.md)</li>\n<li>[The Sliding Window Technique](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/SlidingWindowTechnique.md)</li>\n<li>[Difference Between Process and Thread in Linux](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/common_knowledge/linuxProcess.md)</li>\n<li>[Some Good Online Practice Platforms](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/common_knowledge/OnlinePraticePlatform.md)</li>\n<li>[Dynamic Programming in Details](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/AnalysisOfDynamicProgramming.md)</li>\n<li>[Dynamic Programming Q&#x26;A — What is Optimal Substructure](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/OptimalSubstructure.md)</li>\n<li>[Classic DP: Longest Common Subsequence](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/LongestCommonSubsequence.md)</li>\n<li>[Classic DP: Edit Distance](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/EditDistance.md)</li>\n<li>[Classic DP: Super Egg](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/ThrowingEggsinHighBuildings.md)</li>\n<li>[Classic DP: Super Egg (Advanced Solution)](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/SuperEggDropAdvanced.md)</li>\n<li>[The Strategies of Subsequence Problem](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/StrategiesForSubsequenceProblem.md)</li>\n<li>[Classic DP: Game Problems](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/GameProblemsInDynamicProgramming.md)</li>\n<li>[Greedy: Interval Scheduling](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/IntervalScheduling.md)</li>\n<li>[KMP Algorithm In Detail](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/KMPCharacterMatchingAlgorithmInDynamicProgramming.md)</li>\n<li>[A solution to all Buy Time to Buy and Sell Stock Problems](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/BestTimeToBuyAndSellStock.md)</li>\n<li>[A solution to all House Robber Problems](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/HouseRobber.md)</li>\n<li>[4 Keys Keyboard](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/FourKeysKeyboard.md)</li>\n<li>[Regular Expression](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/RegularExpression.md)</li>\n<li>[Longest Increasing Subsequence](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/LongestIncreasingSubsequence.md)</li>\n<li>[The Framework for Learning Algorithms and intense problem solving exercises](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/Framework%20and%20thoughts%20about%20learning%20data%20structure%20and%20algorithm.md)</li>\n<li>[Algs4: Recommended book for Learning Algorithms and Data Structures](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/why<em>i</em>recommend_algs4.md)</li>\n<li>[Binary Heap and Priority Queue](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data<em>structure/binary</em>heap<em>implements</em>priority_queues.md)</li>\n<li>[LRU Cache Strategy in Detail](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/LRU_algorithm.md)</li>\n<li>[Collections of Binary Search Operations](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data<em>structure/The</em>Manipulation<em>Collection</em>of<em>Binary</em>Search_Tree.md)</li>\n<li>[Special Data Structure: Monotonic Stack](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data_structure/MonotonicStack.md)</li>\n<li>[Special Data Structure: Monotonic Stack](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data<em>structure/Monotonic</em>queue.md)</li>\n<li>[Design Twitter](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data<em>structure/design</em>Twitter.md)</li>\n<li>[Reverse Part of Linked List via Recursion](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data<em>structure/reverse</em>part<em>of</em>a<em>linked</em>list<em>via</em>recursion.md)</li>\n<li>[Queue Implement Stack/Stack implement Queue](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data_structure/ImplementQueueUsingStacksImplementStackUsingQueues.md)</li>\n<li>[My Way to Learn Algorithm](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/ThewaytoAlgorithmlearning.md)</li>\n<li>[The Framework of Backtracking Algorithm](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/DetailsaboutBacktracking.md)</li>\n<li>[Binary Search in Detail](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/DetailedBinarySearch.md)</li>\n<li>[Backtracking Solve Subset/Permutation/Combination](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/Subset<em>Permutation</em>Combination.md)</li>\n<li>[Diving into the technical parts of Double Pointers](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/double_pointer.md)</li>\n<li>[Sliding Window Technique](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/SlidingWindowTechnique.md)</li>\n<li>[The Core Concept of TwoSum Problems](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/The<em>key</em>to<em>resolving</em>TwoSum_problems.md)</li>\n<li>[Common Bit Manipulations](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/CommonBitManipulation.md)</li>\n<li>[Breaking down a Complicated Problem: Implement a Calculator](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data<em>structure/Implementing</em>the<em>functions</em>of<em>a</em>calculator.md)</li>\n<li>[Pancake Sorting Algorithm](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/PancakesSorting.md)</li>\n<li>[Prefix Sum: Intro and Concept](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/prefix_sum.md)</li>\n<li>[String Multiplication](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/string_multiplication.md)</li>\n<li>[FloodFill Algorithm in Detail](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/flood_fill.md)</li>\n<li>[Interval Scheduling: Interval Merging](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/IntervalMerging.md)</li>\n<li>[Interval Scheduling: Intersections of Intervals](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/IntervalIntersection.md)</li>\n<li>[Russian Doll Envelopes Problem](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/RussianDollEnvelopes.md)</li>\n<li>[A collection of counter-intuitive Probability Problems](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/several<em>counter</em>intuitive<em>probability</em>problems.md)</li>\n<li>[Shuffle Algorithm](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/Shuffle_Algorithm.md)</li>\n<li>[Recursion In Detail](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/data_structure/RecursionInDetail.md)</li>\n<li>[How to Implement LRU Cache](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/LRU_algorithm.md)</li>\n<li>[How to Find Prime Number Efficiently](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/Print_PrimeNumbers.md)</li>\n<li>[How to Calculate Minimium Edit Distance](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/dynamic_programming/EditDistance.md)</li>\n<li>[How to use Binary Search](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/UsingBinarySearchAlgorithm.md)</li>\n<li>[How to efficiently solve Trapping Rain Water Problem](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/Trapping<em>Rain</em>Water.md)</li>\n<li>[How to Remove Duplicates From Sorted Array](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/RemoveDuplicatesfromSortedArray.md)</li>\n<li>[How to Find Longest Palindromic Substring](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/TheLongestPalindromicSubstring.md)</li>\n<li>[How to Reverse Linked List in K Group](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/reverse-nodes-in-k-group.md)</li>\n<li>[How to Check the Validation of Parenthesis](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/valid-parentheses.md)</li>\n<li>[How to Find Missing Element](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/missing_elements.md)</li>\n<li>[How to Find Duplicates and Missing Elements](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/Find-Duplicate-and-Missing-Element.md)</li>\n<li>[How to Check Palindromic LinkedList](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/check<em>palindromic</em>linkedlist.md)</li>\n<li>[How to Pick Elements From an Infinite Arbitrary Sequence](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/ReservoirSampling.md)</li>\n<li>[How to Schedule Seats for Students](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/Seatscheduling.md)</li>\n<li>[Union-Find Algorithm in Detail](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/Union-find-Explanation.md)</li>\n<li>[Union-Find Application](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/think<em>like</em>computer/Union-Find-Application.md)</li>\n<li>[Problems that can be solved in one line](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/one-line-code-puzzles.md)</li>\n<li>[Find Subsequence With Binary Search](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/interview/findSebesquenceWithBinarySearch.md)</li>\n<li>[Difference Between Process and Thread in Linux](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/common_knowledge/linuxProcess.md)</li>\n<li>[You Must Know About Linux Shell](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/common_knowledge/linuxshell.md)</li>\n<li>[You Must Know About Cookie and Session](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/common_knowledge/SessionAndCookie.md)</li>\n<li>[Cryptology Algorithm](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/common_knowledge/Cryptology.md)</li>\n<li>[Some Good Online Practice Platforms](https://72a70b9d-739e-477a-bd84-85357c883a09.vscode-webview-test.com/vscode-resource/file///c:/MY-WEB-DEV/_JOB-SEARCH/03-Interview-Prep/01-reference-guides/common_knowledge/OnlinePraticePlatform.md)</li>\n</ul>\n<h2>Algorithms: <a id=\"119a\"></h2>\n</a>\n<ul>\n<li>[100 days of algorithms](https://github.com/coells/100days)</li>\n<li>[Algorithms](https://github.com/marcosfede/algorithms) — Solved algorithms and data structures problems in many languages.</li>\n<li>[Algorithms by Jeff Erickson](https://jeffe.cs.illinois.edu/teaching/algorithms/) ([Code](https://github.com/jeffgerickson/algorithms)) ([HN](https://news.ycombinator.com/item?id=26074289))</li>\n<li>[Top algos/DS to learn](https://www.reddit.com/r/compsci/comments/5uz9lb/top<em>algorithmsdata</em>structuresconcepts_every/ddy8azz/)</li>\n<li>[Some neat algorithms](https://www.nayuki.io/category/programming)</li>\n<li>[Mathematical Proof of Algorithm Correctness and Efficiency (2019)](https://stackabuse.com/mathematical-proof-of-algorithm-correctness-and-efficiency/)</li>\n<li>[Algorithm Visualizer](https://github.com/algorithm-visualizer/algorithm-visualizer) — Interactive online platform that visualizes algorithms from code.</li>\n<li>[Algorithms for Optimization book](https://mitpress.mit.edu/books/algorithms-optimization)</li>\n<li>[Collaborative book on algorithms](https://www.algorithm-archive.org/) ([Code](https://github.com/algorithm-archivists/algorithm-archive))</li>\n<li>[Algorithms in C by Robert Sedgewick](https://index-of.co.uk/Algorithms/Algorithms%20in%20C.pdf)</li>\n<li>[Algorithm Design Manual](https://mimoza.marmara.edu.tr/~msakalli/cse706_12/SkienaTheAlgorithmDesignManual.pdf)</li>\n<li>[MIT Introduction to Algorithms course (2011)](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/)</li>\n<li>[How to implement an algorithm from a scientific paper (2012)](https://codecapsule.com/2012/01/18/how-to-implement-a-paper/)</li>\n<li>[Quadsort](https://github.com/scandum/quadsort) — Stable non-recursive merge sort named quadsort.</li>\n<li>[System design algorithms](https://github.com/resumejob/system-design-algorithms) — Algorithms you should know before system design.</li>\n<li>[Algorithms Design book](https://www.cs.sjtu.edu.cn/~jiangli/teaching/CS222/files/materials/Algorithm%20Design.pdf)</li>\n<li>[Think Complexity](https://greenteapress.com/complexity/html/index.html)</li>\n<li>[All Algorithms implemented in Rust](https://github.com/TheAlgorithms/Rust)</li>\n<li>[Solutions to Introduction to Algorithms book](https://walkccc.github.io/CLRS/) ([Code](https://github.com/walkccc/CLRS))</li>\n<li>[Maze Algorithms (2011)](https://www.jamisbuck.org/mazes/) ([HN](https://news.ycombinator.com/item?id=23429368))</li>\n<li>[Algorithmic Design Paradigms book](https://page.skerritt.blog/algorithms/) ([Code](https://github.com/brandonskerritt/AlgorithmsBook))</li>\n<li>[Words and buttons Online Blog](https://wordsandbuttons.online/) ([Code](https://github.com/akalenuk/wordsandbuttons))</li>\n<li>[Algorithms animated](https://www.chrislaux.com/)</li>\n<li>[Cache Oblivious Algorithms (2020)](https://jiahai-feng.github.io/posts/cache-oblivious-algorithms/) ([HN](https://news.ycombinator.com/item?id=23662434))</li>\n<li>[You could have invented fractional cascading (2012)](https://blog.ezyang.com/2012/03/you-could-have-invented-fractional-cascading/)</li>\n<li>[Guide to learning algorithms through LeetCode](https://labuladong.gitbook.io/algo-en/) ([Code](https://github.com/labuladong/fucking-algorithm/tree/english)) ([HN](https://news.ycombinator.com/item?id=24167297))</li>\n<li>[How hard is unshuffling a string?](https://cstheory.stackexchange.com/questions/34/how-hard-is-unshuffling-a-string)</li>\n<li>[Optimization Algorithms on Matrix Manifolds](https://sites.uclouvain.be/absil/amsbook/)</li>\n<li>[Problem Solving with Algorithms and Data Structures](https://runestone.academy/runestone/books/published/pythonds/index.html) ([HN](https://news.ycombinator.com/item?id=24287622)) ([PDF](https://www.cs.auckland.ac.nz/compsci105s1c/resources/ProblemSolvingwithAlgorithmsandDataStructures.pdf))</li>\n<li>[Algorithms implemented in Python](https://github.com/TheAlgorithms/Python)</li>\n<li>[Algorithms implemented in JavaScript](https://github.com/TheAlgorithms/Javascript)</li>\n<li>[Algorithms &#x26; Data Structures in Java](https://github.com/williamfiset/Algorithms)</li>\n<li>[Wolfsort](https://github.com/scandum/wolfsort) — Stable adaptive hybrid radix / merge sort.</li>\n<li>[Evolutionary Computation Bestiary](https://github.com/fcampelo/EC-Bestiary) — Bestiary of evolutionary, swarm and other metaphor-based algorithms.</li>\n<li>[Elements of Programming book](https://elementsofprogramming.com/) — Decomposing programs into a system of algorithmic components. ([Review](https://www.pathsensitive.com/2020/09/book-review-elements-of-programmnig.html)) ([HN](https://news.ycombinator.com/item?id=24635947)) ([Lobsters](https://lobste.rs/s/bqnhbo/book<em>review</em>elements_programmnig))</li>\n<li>[Competitive Programming Algorithms](https://cp-algorithms.com/)</li>\n<li>[CPP/C](https://github.com/akshitagit/CPP) — C/C++ algorithms/DS problems.</li>\n<li>[How to design an algorithm (2018)](https://www.adamconrad.dev/blog/how-to-design-an-algorithm/)</li>\n<li>[CSE 373 — Introduction to Algorithms, by Steven Skiena (2020)](https://www.youtube.com/playlist?list=PLOtl7M3yp-DX6ic0HGT0PUX_wiNmkWkXx)</li>\n<li>[Computer Algorithms II course (2020)](https://homepages.math.uic.edu/~lreyzin/f20_mcs501/)</li>\n<li>[Improving Binary Search by Guessing (2019)](https://notebook.drmaciver.com/posts/2019-04-30-13:03.html)</li>\n<li>[The case for a learned sorting algorithm (2020)](https://blog.acolyer.org/2020/10/19/the-case-for-a-learned-sorting-algorithm/) ([HN](https://news.ycombinator.com/item?id=24823611))</li>\n<li>[Elementary Algorithms](https://github.com/liuxinyu95/AlgoXY) — Introduces elementary algorithms and data structures. Includes side-by-side comparisons of purely functional realization and their imperative counterpart.</li>\n<li>[Combinatorics Algorithms for Coding Interviews (2018)](https://sahandsaba.com/combinatorial-generation-for-coding-interviews-in-python.html)</li>\n<li>[Algorithms written in different programming languages](https://github.com/ZoranPandovski/al-go-rithms) ([Web](https://zoranpandovski.github.io/al-go-rithms/))</li>\n<li>[Solving the Sequence Alignment problem in Python (2020)](https://johnlekberg.com/blog/2020-10-25-seq-align.html)</li>\n<li>[The Sound of Sorting](https://github.com/bingmann/sound-of-sorting) — Visualization and “Audibilization” of Sorting Algorithms. ([Web](https://panthema.net/2013/sound-of-sorting/))</li>\n<li>[Miniselect: Practical and Generic Selection Algorithms (2020)](https://danlark.org/2020/11/11/miniselect-practical-and-generic-selection-algorithms/)</li>\n<li>[The Slowest Quicksort (2019)](https://chasewilson.dev/blog/slowest-quicksort/)</li>\n<li>[Functional Algorithm Design (2020)](https://blog.sigplan.org/2020/11/17/functional-algorithm-design-part-0/)</li>\n<li>[Algorithms To Live By — Book Notes](https://milofultz.com/2020/12/27/atlb-notes)</li>\n<li>[Numerical Algorithms (2015)](https://people.csail.mit.edu/jsolomon/share/book/numerical_book.pdf)</li>\n<li>[Using approximate nearest neighbor search in real world applications (2020)](https://blog.vespa.ai/using-approximate-nearest-neighbor-search-in-real-world-applications/)</li>\n<li>[In search of the fastest concurrent Union-Find algorithm (2019)](https://arxiv.org/pdf/1911.06347.pdf)</li>\n<li>[Computer Science 521 Advanced Algorithm Design](https://www.cs.princeton.edu/courses/archive/fall13/cos521/)</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*2fb7io8VD9z8080F.jpg\" alt=\"image\"></p>\n<h2>Data Structures: <a id=\"e5f0\"></h2>\n</a>\n<ul>\n<li>[Data Structures and Algorithms implementation in Go](https://github.com/floyernick/Data-Structures-and-Algorithms)</li>\n<li>[Which algorithms/data structures should I “recognize” and know by name?](https://softwareengineering.stackexchange.com/questions/155639/which-algorithms-data-structures-should-i-recognize-and-know-by-name)</li>\n<li>[Dictionary of Algorithms and Data Structures](https://xlinux.nist.gov/dads/)</li>\n<li>[Phil's Data Structure Zoo](https://g1thubhub.github.io/data-structure-zoo.html)</li>\n<li>[The Periodic Table of Data Structures](https://stratos.seas.harvard.edu/files/stratos/files/periodictabledatastructures.pdf) ([HN](https://news.ycombinator.com/item?id=18314555))</li>\n<li>[Data Structure Visualizations](https://www.cs.usfca.edu/~galles/visualization/Algorithms.html) ([HN](https://news.ycombinator.com/item?id=19082943))</li>\n<li>[Data structures to name-drop when you want to sound smart in an interview](https://blog.amynguyen.net/?p=853)</li>\n<li>[On lists, cache, algorithms, and microarchitecture (2019)](https://pdziepak.github.io/2019/05/02/on-lists-cache-algorithms-and-microarchitecture/)</li>\n<li>[Topics in Advanced Data Structures (2019)](https://web.stanford.edu/class/cs166/handouts/100%20Suggested%20Final%20Project%20Topics.pdf) ([HN](https://news.ycombinator.com/item?id=19780387))</li>\n<li>[CS166 Advanced DS Course (2019)](https://web.stanford.edu/class/cs166/)</li>\n<li>[Advanced Data Structures (2017)](https://courses.csail.mit.edu/6.851/fall17/) ([HN](https://news.ycombinator.com/item?id=20044876))</li>\n<li>[Write a hash table in C](https://github.com/jamesroutley/write-a-hash-table)</li>\n<li>[Python Data Structures and Algorithms](https://github.com/prabhupant/python-ds)</li>\n<li>[HAMTs from Scratch (2018)](https://vaibhavsagar.com/blog/2018/07/29/hamts-from-scratch/)</li>\n<li>[JavaScript Data Structures and Algorithms](https://github.com/JoeKarlsson/data-structures)</li>\n<li>[Implementing a Key-Value Store series](https://codecapsule.com/2012/11/07/ikvs-implementing-a-key-value-store-table-of-contents/)</li>\n<li>[Open Data Structures](https://opendatastructures.org/) — Provide a high-quality open content data structures textbook that is both mathematically rigorous and provides complete implementations. ([Code](https://github.com/patmorin/ods))</li>\n<li>[A new analysis of the false positive rate of a Bloom filter (2009)](https://www.csee.usf.edu/~kchriste/energy/ipl10.pdf)</li>\n<li>[Ideal Hash Trees](https://lampwww.epfl.ch/papers/idealhashtrees.pdf)</li>\n<li>[RRB-Trees: Efficient Immutable Vectors](https://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=0265C1992F573129BCC7D4AF7734DBF7?doi=10.1.1.592.5377&#x26;rep=rep1&#x26;type=pdf)</li>\n<li>[Some data structures and algorithms written in OCaml](https://github.com/jdan/ocaml-data-structures)</li>\n<li>[Let's Invent B(+)-Trees](https://shachaf.net/w/b-trees) ([HN](https://news.ycombinator.com/item?id=23001831))</li>\n<li>[Anna](https://github.com/hydro-project/anna) — Low-latency, cloud-native KVS.</li>\n<li>[Persistent data structures thanks to recursive type aliases (2019)](https://www.aleksandra.codes/persistent-data-structures)</li>\n<li>[Log-Structured Merge-Trees (2020)](https://yetanotherdevblog.com/lsm/)</li>\n<li>[Bloom Filters for the Perplexed (2017)](https://sagi.io/bloom-filters-for-the-perplexed/)</li>\n<li>[Understanding Bloom Filters (2020)](https://yetanotherdevblog.com/bloom-filters/)</li>\n<li>[Dense vs. Sparse Indexes (2020)](https://yetanotherdevblog.com/dense-vs-sparse-indexes/)</li>\n<li>[Data Structures and Algorithms Problems](https://www.techiedelight.com/list-of-problems/)</li>\n<li>[Data Structures &#x26; Algorithms I Actually Used Working at Tech Companies (2020)](https://blog.pragmaticengineer.com/data-structures-and-algorithms-i-actually-used-day-to-day/) ([Lobsters](https://lobste.rs/s/n8tyip/data<em>structures</em>algorithms<em>i</em>actually)) ([HN](https://news.ycombinator.com/item?id=23841491))</li>\n<li>[Let's implement a Bloom Filter (2020)](https://onatm.dev/2020/08/10/let-s-implement-a-bloom-filter/) ([HN](https://news.ycombinator.com/item?id=24102617))</li>\n<li>[Data Structures Part 1: Bulk Data (2019)](https://ourmachinery.com/post/data-structures-part-1-bulk-data/) ([Lobsters](https://lobste.rs/s/t8mrxn/data<em>structures</em>part<em>1</em>bulk_data))</li>\n<li>[Data Structures Explained](https://www.freecodecamp.org/news/learn-all-about-data-structures-used-in-computer-science/)</li>\n<li>[Introduction to Cache-Oblivious Data Structures (2018)](https://rcoh.me/posts/cache-oblivious-datastructures/)</li>\n<li>[The Daily Coding newsletter](https://thedailycoding.com/) — Master JavaScript and Data Structures.</li>\n<li>[Lectures Note for Data Structures and Algorithms (2019)](https://www.cs.bham.ac.uk/~jxb/DSA/dsa.pdf)</li>\n<li>[Mechanically Deriving Binary Tree Iterators with Continuation Defunctionalization (2020)](https://abhinavsarkar.net/posts/continuation-defunctionalization/)</li>\n<li>[Segment Tree data structure](https://cp-algorithms.com/data<em>structures/segment</em>tree.html)</li>\n<li>[Structure of a binary state tree (2020)](https://medium.com/@gballet/structure-of-a-binary-state-tree-part-1-48c587836d2f)</li>\n<li>[Introductory data structures and algorithms](https://github.com/sushinoya/fundamentals)</li>\n<li>[Applying Textbook Data Structures for Real Life Wins (2020)](https://heap.io/blog/engineering/applying-textbook-data-structures-for-real-life-wins) ([HN](https://news.ycombinator.com/item?id=24761105))</li>\n<li>[Michael Scott — Nonblocking data structures lectures (2020)](https://www.youtube.com/watch?v=9XAx279s7gs) — Nonblocking concurrent data structures are an increasingly valuable tool for shared-memory parallel programming.</li>\n<li>[Scal](https://github.com/cksystemsgroup/scal) — High-performance multicore-scalable data structures and benchmarks. ([Web](https://scal.cs.uni-salzburg.at/))</li>\n<li>[Hyperbolic embedding implementations](https://github.com/HazyResearch/hyperbolics)</li>\n<li>[Morphisms of Computational Constructs](https://github.com/prathyvsh/morphisms-of-computational-structures) — Visual catalogue + story of morphisms displayed across computational structures.</li>\n<li>[What is key-value store? (build-your-own-x) (2020)](https://djkooks.github.io/build-your-own-kv-store)</li>\n<li>[Lesser Known but Useful Data Structures](https://stackoverflow.com/questions/500607/what-are-the-lesser-known-but-useful-data-structures)</li>\n<li>[Using Bloom filters to efficiently synchronize hash graphs (2020)](https://martin.kleppmann.com/2020/12/02/bloom-filter-hash-graph-sync.html)</li>\n<li>[Bloom Filters by Example](https://llimllib.github.io/bloomfilter-tutorial/) ([Code](https://github.com/llimllib/bloomfilter-tutorial))</li>\n<li>[Binary Decision Diagrams](https://crypto.stanford.edu/pbc/notes/zdd/) ([HN](https://news.ycombinator.com/item?id=25342922))</li>\n<li>[3 Steps to Designing Better Data Structures (2020)](https://mochromatic.com/3-steps-to-designing-better-data-structures-in-elixir/)</li>\n<li>[Sparse Matrices (2019)](https://matteding.github.io/2019/04/25/sparse-matrices/) ([HN](https://news.ycombinator.com/item?id=25601288))</li>\n<li>[Algorithms &#x26; Data Structures in C++](https://github.com/xtaci/algorithms)</li>\n<li>[Fancy Tree Traversals (2019)](https://drs.is/post/fancy-tree-traversals/)</li>\n<li>[The Robson Tree Traversal (2019)](https://drs.is/post/robson-traversal/)</li>\n<li>[Data structures and program structures](https://cr.yp.to/data.html)</li>\n<li>[cdb](https://cr.yp.to/cdb.html) — Fast, reliable, simple package for creating and reading constant databases.</li>\n<li>[PGM-index](https://pgm.di.unipi.it/) — Learned indexes that match B-tree performance with 83x less space. ([HN](https://news.ycombinator.com/item?id=25899286)) ([Code](https://github.com/gvinciguerra/PGM-index))</li>\n<li>[Structural and pure attributes](https://minimalmodeling.substack.com/p/structural-and-pure-attributes)</li>\n<li>[Cache-Tries: O(1) Concurrent Lock-Free Hash Tries (2018)](https://aleksandar-prokopec.com/resources/docs/p137-prokopec.pdf)</li>\n</ul>"},{"url":"/blog/data-structures/","relativePath":"blog/data-structures.md","relativeDir":"blog","base":"data-structures.md","name":"data-structures","frontmatter":{"title":"Leetcode (Data Structures)","subtitle":"practice","date":"2021-09-14","thumb_image_alt":"Big O Cheat Sheet","excerpt":"A guide to computational complexity","seo":{"title":"Leetcode-ds","description":"Data Structures & Algorithms","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"post","image":"images/ds.png","thumb_image":"images/bigo.jpg"},"html":"<h1>Leetcode</h1>\n<h2>Data Structures &#x26; Algorithms</h2>\n<p><a href=\"https://github.com/bgoonz/Data-Structures-Algos-Codebase\">DS Algo Codebase</a></p>\n<p><a href=\"#115-distinct-subsequenceshttpsleetcodecomproblemsdistinct-subsequencesdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/distinct-subsequences/description/\">115. Distinct Subsequences</a></h2>\n<h3>Problem</h3>\n<p>Given a string <strong>S</strong> and a string <strong>T</strong>, count the number of distinct subsequences of <strong>S</strong> which equals <strong>T</strong>.</p>\n<p>A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, <code class=\"language-text\">\"ACE\"</code> is a subsequence of <code class=\"language-text\">\"ABCDE\"</code> while <code class=\"language-text\">\"AEC\"</code> is not).</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: S = \"rabbbit\", T = \"rabbit\"\nOutput: 3\nExplanation:\n\nAs shown below, there are 3 ways you can generate \"rabbit\" from S.\n(The caret symbol ^ means the chosen letters)\n\nrabbbit\n^^^^ ^^\nrabbbit\n^^ ^^^^\nrabbbit\n^^^ ^^^</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: S = \"babgbag\", T = \"bag\"\nOutput: 5\nExplanation:\n\nAs shown below, there are 5 ways you can generate \"bag\" from S.\n(The caret symbol ^ means the chosen letters)\n\nbabgbag\n^^ ^\nbabgbag\n^^    ^\nbabgbag\n^    ^^\nbabgbag\n  ^  ^^\nbabgbag\n    ^^^</code></pre></div>\n<h3>Solution</h3>\n<p>Define <code class=\"language-text\">f(i, j)</code> to be the number of ways that generate <code class=\"language-text\">T[0...j)</code> from <code class=\"language-text\">S[0...i)</code>.</p>\n<p>For <code class=\"language-text\">f(i, j)</code> you can always skip <code class=\"language-text\">S[i-1]</code>, but can only take it when <code class=\"language-text\">S[i-1] === T[j-1]</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token comment\">// nothing to delete</span>\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token comment\">// delete all</span>\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">S</span><span class=\"token punctuation\">[</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span>j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Dynamic array can be used.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">numDistinct</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> lens <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> lent <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> dp <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span>lent <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">fill</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    dp<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> lens<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> lent<span class=\"token punctuation\">;</span> j <span class=\"token operator\">>=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                dp<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> dp<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> dp<span class=\"token punctuation\">[</span>lent<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Tree\": <a href=\"https://leetcode.com/tag/tree\">https://leetcode.com/tag/tree</a>\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\nSimilar Questions:\n\"Populating Next Right Pointers in Each Node II\": <a href=\"https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii\">https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii</a>\n\"Binary Tree Right Side View\": <a href=\"https://leetcode.com/problems/binary-tree-right-side-view\">https://leetcode.com/problems/binary-tree-right-side-view</a></p>\n<hr>\n<p><a href=\"#116-populating-next-right-pointers-in-each-nodehttpsleetcodecomproblemspopulating-next-right-pointers-in-each-nodedescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/populating-next-right-pointers-in-each-node/description/\">116. Populating Next Right Pointers in Each Node</a></h2>\n<h3>Problem</h3>\n<p>Given a binary tree</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">struct TreeLinkNode {\n  TreeLinkNode *left;\n  TreeLinkNode *right;\n  TreeLinkNode *next;\n}</code></pre></div>\n<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code class=\"language-text\">NULL</code>.</p>\n<p>Initially, all next pointers are set to <code class=\"language-text\">NULL</code>.</p>\n<p><strong>Note:</strong></p>\n<ul>\n<li>You may only use constant extra space.</li>\n<li>Recursive approach is fine, implicit stack space does not count as extra space for this problem.</li>\n<li>You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children).</li>\n</ul>\n<p><strong>Example:</strong></p>\n<p>Given the following perfect binary tree,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1\n   /  \\\n  2    3\n / \\  / \\\n4  5  6  7</code></pre></div>\n<p>After calling your function, the tree should look like:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1 -> NULL\n   /  \\\n  2 -> 3 -> NULL\n / \\  / \\\n4->5->6->7 -> NULL</code></pre></div>\n<h3>Solution</h3>\n<h4>ONE</h4>\n<p>Recursive.</p>\n<p>For every <code class=\"language-text\">node</code>:</p>\n<ul>\n<li>Left child: points to <code class=\"language-text\">node.right</code>.</li>\n<li>Right child: points to <code class=\"language-text\">node.next.left</code> if <code class=\"language-text\">node.next</code> exists.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for binary tree with next pointer.\n * function TreeLinkNode(val) {\n *     this.val = val;\n *     this.left = this.right = this.next = null;\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {TreeLinkNode} root\n * @return {void} Do not return anything, modify tree in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">connect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n        <span class=\"token function\">connect</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>next <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token function\">connect</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>Level order traversal.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for binary tree with next pointer.\n * function TreeLinkNode(val) {\n *     this.val = val;\n *     this.left = this.right = this.next = null;\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {TreeLinkNode} root\n * @return {void} Do not return anything, modify tree in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">connect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">,</span> root<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node <span class=\"token operator\">!==</span> node<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> queue<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Tree\": <a href=\"https://leetcode.com/tag/tree\">https://leetcode.com/tag/tree</a>\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\nSimilar Questions:\n\"Populating Next Right Pointers in Each Node\": <a href=\"https://leetcode.com/problems/populating-next-right-pointers-in-each-node\">https://leetcode.com/problems/populating-next-right-pointers-in-each-node</a></p>\n<hr>\n<p><a href=\"#117-populating-next-right-pointers-in-each-node-iihttpsleetcodecomproblemspopulating-next-right-pointers-in-each-node-iidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/description/\">117. Populating Next Right Pointers in Each Node II</a></h2>\n<h3>Problem</h3>\n<p>Given a binary tree</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">struct TreeLinkNode {\n  TreeLinkNode *left;\n  TreeLinkNode *right;\n  TreeLinkNode *next;\n}</code></pre></div>\n<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code class=\"language-text\">NULL</code>.</p>\n<p>Initially, all next pointers are set to <code class=\"language-text\">NULL</code>.</p>\n<p><strong>Note:</strong></p>\n<ul>\n<li>You may only use constant extra space.</li>\n<li>Recursive approach is fine, implicit stack space does not count as extra space for this problem.</li>\n</ul>\n<p><strong>Example:</strong></p>\n<p>Given the following binary tree,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1\n   /  \\\n  2    3\n / \\    \\\n4   5    7</code></pre></div>\n<p>After calling your function, the tree should look like:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1 -> NULL\n   /  \\\n  2 -> 3 -> NULL\n / \\    \\\n4-> 5 -> 7 -> NULL</code></pre></div>\n<h3>Solution</h3>\n<h4>ONE</h4>\n<p>Recursive. See <a href=\"./116.%20Populating%20Next%20Right%20Pointers%20in%20Each%20Node.md\">116. Populating Next Right Pointers in Each Node</a>.</p>\n<p>The tree may not be perfect now. So keep finding <code class=\"language-text\">next</code> until there is a node with children, or <code class=\"language-text\">null</code>.</p>\n<p>This also means post-order traversal is required.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for binary tree with next pointer.\n * function TreeLinkNode(val) {\n *     this.val = val;\n *     this.left = this.right = this.next = null;\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {TreeLinkNode} root\n * @return {void} Do not return anything, modify tree in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">connect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">let</span> next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span> node <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span> node <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>right <span class=\"token operator\">||</span> next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">connect</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">connect</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>Level order traversal. Exact same as <a href=\"./116.%20Populating%20Next%20Right%20Pointers%20in%20Each%20Node.md\">116. Populating Next Right Pointers in Each Node</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for binary tree with next pointer.\n * function TreeLinkNode(val) {\n *     this.val = val;\n *     this.left = this.right = this.next = null;\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {TreeLinkNode} root\n * @return {void} Do not return anything, modify tree in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">connect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">,</span> root<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node <span class=\"token operator\">!==</span> node<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> queue<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\nSimilar Questions:\n\"Pascal's Triangle II\": <a href=\"https://leetcode.com/problems/pascals-triangle-ii\">https://leetcode.com/problems/pascals-triangle-ii</a></p>\n<hr>\n<p><a href=\"#118-pascals-trianglehttpsleetcodecomproblemspascals-triangledescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/pascals-triangle/description/\">118. Pascal's Triangle</a></h2>\n<h3>Problem</h3>\n<p>Given a non-negative integer <em>numRows</em>, generate the first <em>numRows</em> of Pascal's triangle.</p>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAnimated2.gif\" alt=\"PascalTriangleAnimated2.gif\"></p>\n<p>In Pascal's triangle, each number is the sum of the two numbers directly above it.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: 5\nOutput:\n[\n     [1],\n    [1,1],\n   [1,2,1],\n  [1,3,3,1],\n [1,4,6,4,1]\n]</code></pre></div>\n<h3>Solution</h3>\n<p>Dynamic Programming 101.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} numRows\n * @return {number[][]}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">generate</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">numRows</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>numRows <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> numRows<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> lastRow <span class=\"token operator\">=</span> result<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> row <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> i<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            row<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> lastRow<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> lastRow<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        row<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\nSimilar Questions:\n\"Pascal's Triangle\": <a href=\"https://leetcode.com/problems/pascals-triangle\">https://leetcode.com/problems/pascals-triangle</a></p>\n<hr>\n<p><a href=\"#119-pascals-triangle-iihttpsleetcodecomproblemspascals-triangle-iidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/pascals-triangle-ii/description/\">119. Pascal's Triangle II</a></h2>\n<h3>Problem</h3>\n<p>Given a non-negative index <em>k</em> where <em>k</em> ≤ 33, return the <em>k</em>th index row of the Pascal's triangle.</p>\n<p>Note that the row index starts from 0.</p>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAnimated2.gif\" alt=\"PascalTriangleAnimated2.gif\"></p>\n<p>In Pascal's triangle, each number is the sum of the two numbers directly above it.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: 3\nOutput: [1,3,3,1]</code></pre></div>\n<p><strong>Follow up:</strong></p>\n<p>Could you optimize your algorithm to use only <em>O</em>(<em>k</em>) extra space?</p>\n<h3>Solution</h3>\n<p>Dynamic Programming 101 with dynamic array.</p>\n<p>State <code class=\"language-text\">(i, j)</code> depends on <code class=\"language-text\">(i-1, j)</code> and <code class=\"language-text\">(i-1, j-1)</code>. So to access <code class=\"language-text\">(i-1, j-1)</code> iteration must be from right to left.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} rowIndex\n * @return {number[]}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">getRow</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">rowIndex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rowIndex <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> row <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> rowIndex<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            row<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> row<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        row<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> row<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Dynamic Programming\": <a href=\"https://leetcode.com/tag/dynamic-programming\">https://leetcode.com/tag/dynamic-programming</a></p>\n<hr>\n<p><a href=\"#120-trianglehttpsleetcodecomproblemstriangledescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/triangle/description/\">120. Triangle</a></h2>\n<h3>Problem</h3>\n<p>Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.</p>\n<p>For example, given the following triangle</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[\n     [2],\n    [3,4],\n   [6,5,7],\n  [4,1,8,3]\n]</code></pre></div>\n<p>The minimum path sum from top to bottom is <code class=\"language-text\">11</code> (i.e., <strong>2</strong> + <strong>3</strong> + <strong>5</strong> + <strong>1</strong> = 11).</p>\n<p><strong>Note:</strong></p>\n<p>Bonus point if you are able to do this using only <em>O</em>(<em>n</em>) extra space, where <em>n</em> is the total number of rows in the triangle.</p>\n<h3>Solution</h3>\n<p>Define <code class=\"language-text\">f(i, j)</code> to be the minimum path sum from <code class=\"language-text\">triangle[0][0]</code> to <code class=\"language-text\">triangle[i][j]</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">f(i, 0) = f(i-1, j) + triangle[i][0]\nf(i, j) = min( f(i-1, j-1), f(i-1, j) ) + triangle[i][j], 0 &lt; j &lt; i\nf(i, i) = f(i-1, i-1) + triangle[i][i], i > 0</code></pre></div>\n<p>Dynamic array can be used.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[][]} triangle\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">minimumTotal</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">triangle</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>triangle<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> dp <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>triangle<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> triangle<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> dp<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> triangle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">>=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            dp<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>dp<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> dp<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> triangle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        dp<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> triangle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>dp<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Dynamic Programming\": <a href=\"https://leetcode.com/tag/dynamic-programming\">https://leetcode.com/tag/dynamic-programming</a>\nSimilar Questions:\n\"Maximum Subarray\": <a href=\"https://leetcode.com/problems/maximum-subarray\">https://leetcode.com/problems/maximum-subarray</a>\n\"Best Time to Buy and Sell Stock II\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii</a>\n\"Best Time to Buy and Sell Stock III\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii</a>\n\"Best Time to Buy and Sell Stock IV\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv</a>\n\"Best Time to Buy and Sell Stock with Cooldown\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown</a></p>\n<hr>\n<p><a href=\"#121-best-time-to-buy-and-sell-stockhttpsleetcodecomproblemsbest-time-to-buy-and-sell-stockdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/\">121. Best Time to Buy and Sell Stock</a></h2>\n<h3>Problem</h3>\n<p>Say you have an array for which the <em>i</em>th element is the price of a given stock on day<em>i</em>.</p>\n<p>If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.</p>\n<p>Note that you cannot sell a stock before you buy one.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,1,5,3,6,4]\nOutput: 5\nExplanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.\n             Not 7-1 = 6, as selling price needs to be larger than buying price.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0.</code></pre></div>\n<h3>Solution</h3>\n<p>Only care about positive profits. Take the frist item as base and scan to the right. If we encounter an item <code class=\"language-text\">j</code> whose price <code class=\"language-text\">price[j]</code> is lower than the base (which means if we sell now the profit would be negative), we sell <code class=\"language-text\">j-1</code> instead and make <code class=\"language-text\">j</code> the new base.</p>\n<p>Because <code class=\"language-text\">price[j]</code> is lower that the base, using <code class=\"language-text\">j</code> as new base is guaranteed to gain more profit comparing to the old one.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} prices\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxProfit</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">prices</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> max <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> base <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> prices<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> profit <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">-</span> base<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>profit <span class=\"token operator\">></span> max<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            max <span class=\"token operator\">=</span> profit<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>profit <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            base <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> max<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Greedy\": <a href=\"https://leetcode.com/tag/greedy\">https://leetcode.com/tag/greedy</a>\nSimilar Questions:\n\"Best Time to Buy and Sell Stock\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock</a>\n\"Best Time to Buy and Sell Stock III\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii</a>\n\"Best Time to Buy and Sell Stock IV\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv</a>\n\"Best Time to Buy and Sell Stock with Cooldown\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown</a>\n\"Best Time to Buy and Sell Stock with Transaction Fee\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee</a></p>\n<hr>\n<p><a href=\"#122-best-time-to-buy-and-sell-stock-iihttpsleetcodecomproblemsbest-time-to-buy-and-sell-stock-iidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/\">122. Best Time to Buy and Sell Stock II</a></h2>\n<h3>Problem</h3>\n<p>Say you have an array for which the <em>i</em>th element is the price of a given stock on day<em>i</em>.</p>\n<p>Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).</p>\n<p><strong>Note:</strong> You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,1,5,3,6,4]\nOutput: 7\nExplanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.\n             Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\n             Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are\n             engaging multiple transactions at the same time. You must sell before buying again.</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0.</code></pre></div>\n<h3>Solution</h3>\n<p>Sell immediately after the price drops. Or in other perspective, it is the sum of all the incremental pairs (buy in then immediately sell out).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} prices\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxProfit</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">prices</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> max <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> prices<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> prices<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            max <span class=\"token operator\">+=</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">-</span> prices<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> max<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Hard\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Dynamic Programming\": <a href=\"https://leetcode.com/tag/dynamic-programming\">https://leetcode.com/tag/dynamic-programming</a>\nSimilar Questions:\n\"Best Time to Buy and Sell Stock\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock</a>\n\"Best Time to Buy and Sell Stock II\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii</a>\n\"Best Time to Buy and Sell Stock IV\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv</a>\n\"Maximum Sum of 3 Non-Overlapping Subarrays\": <a href=\"https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays\">https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays</a></p>\n<hr>\n<p><a href=\"#123-best-time-to-buy-and-sell-stock-iiihttpsleetcodecomproblemsbest-time-to-buy-and-sell-stock-iiidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/description/\">123. Best Time to Buy and Sell Stock III</a></h2>\n<h3>Problem</h3>\n<p>Say you have an array for which the <em>i</em>th element is the price of a given stock on day<em>i</em>.</p>\n<p>Design an algorithm to find the maximum profit. You may complete at most <em>two</em> transactions.</p>\n<p>**Note:**You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [3,3,5,0,0,3,1,4]\nOutput: 6\nExplanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.\n             Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\n             Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are\n             engaging multiple transactions at the same time. You must sell before buying again.</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0.</code></pre></div>\n<h3>Solution</h3>\n<p>Multiple transactions may not be engaged in at the same time. That means if we view the days that involed in the same transaction as a group, there won't be any intersection. We may complete at most <em>two</em> transactions, so divide the days into two groups, <code class=\"language-text\">[0...k]</code> and <code class=\"language-text\">[k...n-1]</code>. Notice <code class=\"language-text\">k</code> exists in both groups because technically we can sell out then immediately buy in at the same day.</p>\n<p>Define <code class=\"language-text\">p1(i)</code> to be the max profit of day <code class=\"language-text\">[0...i]</code>. This is just like the problem of <a href=\"./121.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock.md\">121. Best Time to Buy and Sell Stock</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">p1(0) = 0\np1(i) = max( p1(i-1), prices[i] - min(prices[0], ..., prices[i-1]) ), 0 &lt; i &lt;= n-1</code></pre></div>\n<p>Define <code class=\"language-text\">p2(i)</code> to be the max profit of day <code class=\"language-text\">[i...n-1]</code>. This is the mirror of <code class=\"language-text\">p1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">p2(n-1) = 0\np2(i) = max( p2(i+1), max(prices[i], ..., prices[n-1]) - prices[i] ), n-1 > i >= 0</code></pre></div>\n<p>Define <code class=\"language-text\">f(k)</code> to be <code class=\"language-text\">p1(k) + p2(k)</code>. We need to get <code class=\"language-text\">max( f(0), ..., f(n-1) )</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} prices\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxProfit</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">prices</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> len <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>len <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> dp <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> min <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>dp<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">-</span> min<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        min <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> min<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> p2 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> max <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span>len <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> len <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        max <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> max<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        p2 <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>p2<span class=\"token punctuation\">,</span> max <span class=\"token operator\">-</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> p2<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>dp<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Hard\nRelated Topics:\n\"Tree\": <a href=\"https://leetcode.com/tag/tree\">https://leetcode.com/tag/tree</a>\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\nSimilar Questions:\n\"Path Sum\": <a href=\"https://leetcode.com/problems/path-sum\">https://leetcode.com/problems/path-sum</a>\n\"Sum Root to Leaf Numbers\": <a href=\"https://leetcode.com/problems/sum-root-to-leaf-numbers\">https://leetcode.com/problems/sum-root-to-leaf-numbers</a>\n\"Path Sum IV\": <a href=\"https://leetcode.com/problems/path-sum-iv\">https://leetcode.com/problems/path-sum-iv</a>\n\"Longest Univalue Path\": <a href=\"https://leetcode.com/problems/longest-univalue-path\">https://leetcode.com/problems/longest-univalue-path</a></p>\n<hr>\n<p><a href=\"#124-binary-tree-maximum-path-sumhttpsleetcodecomproblemsbinary-tree-maximum-path-sumdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/binary-tree-maximum-path-sum/description/\">124. Binary Tree Maximum Path Sum</a></h2>\n<h3>Problem</h3>\n<p>Given a <strong>non-empty</strong> binary tree, find the maximum path sum.</p>\n<p>For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain <strong>at least one node</strong> and does not need to go through the root.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [1,2,3]\n\n       1\n      / \\\n     2   3\n\nOutput: 6</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [-10,9,20,null,null,15,7]\n\n   -10\n   / \\\n  9  20\n    /  \\\n   15   7\n\nOutput: 42</code></pre></div>\n<h3>Solution</h3>\n<p>For every <code class=\"language-text\">node</code>, there are six possible ways to get the max path sum:</p>\n<ul>\n<li>\n<p>With <code class=\"language-text\">node.val</code></p>\n<ol>\n<li><code class=\"language-text\">node.val</code> plus the max sum of a path that ends with <code class=\"language-text\">node.left</code>.</li>\n<li><code class=\"language-text\">node.val</code> plus the max sum of a path that starts with <code class=\"language-text\">node.right</code>.</li>\n<li><code class=\"language-text\">node.val</code> plus the max sum of both paths.</li>\n<li>Just <code class=\"language-text\">node.val</code> (the max sum of both paths are negative).</li>\n</ol>\n</li>\n<li>\n<p>Without<code class=\"language-text\">node.val</code> (disconnected)</p>\n<ol>\n<li>The max-sum path is somewhere under the <code class=\"language-text\">node.left</code> subtree.</li>\n<li>The max-sum path is somewhere under the <code class=\"language-text\">node.right</code> subtree.</li>\n</ol>\n</li>\n</ul>\n<p>There are two ways to implement this.</p>\n<h4>ONE</h4>\n<p>Define a function that returns two values. The max sum of a path that may or may not end with <code class=\"language-text\">root</code> node, and the max sum of the path that ends with <code class=\"language-text\">root</code> node.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxPathSum</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span><span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {number[]}\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> left <span class=\"token operator\">=</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> right <span class=\"token operator\">=</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> root<span class=\"token punctuation\">.</span>val <span class=\"token operator\">+</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> left<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> left<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> right<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> root<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h4>TWO</h4>\n<p>Just return the later (max sum of a path that ends with <code class=\"language-text\">root</code>). Maintain a global variable to store the disconnected max sum.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxPathSum</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> global <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">max</span><span class=\"token operator\">:</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">,</span> global<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> global<span class=\"token punctuation\">.</span>max<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @param {object} global\n * @param {number} global.max\n * @return {number[]}\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">root<span class=\"token punctuation\">,</span> global</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> left <span class=\"token operator\">=</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">,</span> global<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> right <span class=\"token operator\">=</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">,</span> global<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> localMax <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> root<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">;</span>\n    global<span class=\"token punctuation\">.</span>max <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>global<span class=\"token punctuation\">.</span>max<span class=\"token punctuation\">,</span> localMax<span class=\"token punctuation\">,</span> root<span class=\"token punctuation\">.</span>val <span class=\"token operator\">+</span> left <span class=\"token operator\">+</span> right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> localMax<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Two Pointers\": <a href=\"https://leetcode.com/tag/two-pointers\">https://leetcode.com/tag/two-pointers</a>\n\"String\": <a href=\"https://leetcode.com/tag/string\">https://leetcode.com/tag/string</a>\nSimilar Questions:\n\"Palindrome Linked List\": <a href=\"https://leetcode.com/problems/palindrome-linked-list\">https://leetcode.com/problems/palindrome-linked-list</a>\n\"Valid Palindrome II\": <a href=\"https://leetcode.com/problems/valid-palindrome-ii\">https://leetcode.com/problems/valid-palindrome-ii</a></p>\n<hr>\n<p><a href=\"#125-valid-palindromehttpsleetcodecomproblemsvalid-palindromedescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/valid-palindrome/description/\">125. Valid Palindrome</a></h2>\n<h3>Problem</h3>\n<p>Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.</p>\n<p><strong>Note:</strong> For the purpose of this problem, we define empty string as valid palindrome.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"A man, a plan, a canal: Panama\"\nOutput: true</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"race a car\"\nOutput: false</code></pre></div>\n<h3>Solution</h3>\n<h4>ONE</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> clean <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^a-z0-9]*</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> clean<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> clean<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>Remove non-alphanumeric characters then compare.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> clean <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^a-zA-Z0-9]</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">=</span> clean<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> j<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>clean<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> clean<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>THREE</h4>\n<p>Compare the char codes.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> j<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> left <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> j <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">&lt;</span> <span class=\"token number\">48</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">></span> <span class=\"token number\">57</span> <span class=\"token operator\">&amp;&amp;</span> left <span class=\"token operator\">&lt;</span> <span class=\"token number\">65</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">></span> <span class=\"token number\">90</span> <span class=\"token operator\">&amp;&amp;</span> left <span class=\"token operator\">&lt;</span> <span class=\"token number\">97</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> left <span class=\"token operator\">></span> <span class=\"token number\">122</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            left <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token operator\">++</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">>=</span> j<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">>=</span> <span class=\"token number\">65</span> <span class=\"token operator\">&amp;&amp;</span> left <span class=\"token operator\">&lt;=</span> <span class=\"token number\">90</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            left <span class=\"token operator\">+=</span> <span class=\"token number\">32</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">let</span> right <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> j <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>right <span class=\"token operator\">&lt;</span> <span class=\"token number\">48</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>right <span class=\"token operator\">></span> <span class=\"token number\">57</span> <span class=\"token operator\">&amp;&amp;</span> right <span class=\"token operator\">&lt;</span> <span class=\"token number\">65</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>right <span class=\"token operator\">></span> <span class=\"token number\">90</span> <span class=\"token operator\">&amp;&amp;</span> right <span class=\"token operator\">&lt;</span> <span class=\"token number\">97</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> right <span class=\"token operator\">></span> <span class=\"token number\">122</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            right <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token operator\">--</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">>=</span> j<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>right <span class=\"token operator\">>=</span> <span class=\"token number\">65</span> <span class=\"token operator\">&amp;&amp;</span> right <span class=\"token operator\">&lt;=</span> <span class=\"token number\">90</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            right <span class=\"token operator\">+=</span> <span class=\"token number\">32</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">!==</span> right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Hard\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"String\": <a href=\"https://leetcode.com/tag/string\">https://leetcode.com/tag/string</a>\n\"Backtracking\": <a href=\"https://leetcode.com/tag/backtracking\">https://leetcode.com/tag/backtracking</a>\n\"Breadth-first Search\": <a href=\"https://leetcode.com/tag/breadth-first-search\">https://leetcode.com/tag/breadth-first-search</a>\nSimilar Questions:\n\"Word Ladder\": <a href=\"https://leetcode.com/problems/word-ladder\">https://leetcode.com/problems/word-ladder</a></p>\n<hr>\n<p><a href=\"#126-word-ladder-iihttpsleetcodecomproblemsword-ladder-iidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/word-ladder-ii/description/\">126. Word Ladder II</a></h2>\n<h3>Problem</h3>\n<p>Given two words (<em>beginWord</em> and <em>endWord</em>), and a dictionary's word list, find all shortest transformation sequence(s) from <em>beginWord</em> to <em>endWord</em>, such that:</p>\n<ol>\n<li>Only one letter can be changed at a time</li>\n<li>Each transformed word must exist in the word list. Note that <em>beginWord</em> is <em>not</em> a transformed word.</li>\n</ol>\n<p><strong>Note:</strong></p>\n<ul>\n<li>Return an empty list if there is no such transformation sequence.</li>\n<li>All words have the same length.</li>\n<li>All words contain only lowercase alphabetic characters.</li>\n<li>You may assume no duplicates in the word list.</li>\n<li>You may assume <em>beginWord</em> and <em>endWord</em> are non-empty and are not the same.</li>\n</ul>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nbeginWord = \"hit\",\nendWord = \"cog\",\nwordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\n\nOutput:\n[\n  [\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],\n  [\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]\n]</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nbeginWord = \"hit\"\nendWord = \"cog\"\nwordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\n\nOutput: []\n\nExplanation: The endWord \"cog\" is not in wordList, therefore no possible transformation.</code></pre></div>\n<h3>Solution</h3>\n<p>This is just like <a href=\"./127.%20Word%20Ladder\">127. Word Ladder</a>.</p>\n<p>The constrain still works, but instead of deleting the words right away, collect them and delete them all when a level ends, so that we can reuse the words (matching different parents in the same level).</p>\n<p>The items in the queue are not just words now. Parent nodes are also kept so that we can backtrack the path from the end.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} beginWord\n * @param {string} endWord\n * @param {string[]} wordList\n * @return {string[][]}\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">findLadders</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">beginWord<span class=\"token punctuation\">,</span> endWord<span class=\"token punctuation\">,</span> wordList</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    wordList <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>wordList<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>wordList<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>endWord<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> <span class=\"token constant\">ALPHABET</span> <span class=\"token operator\">=</span> <span class=\"token string\">'abcdefghijklmnopqrstuvwxyz'</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> isEndWordFound <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> levelWords <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span>beginWord<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>isEndWordFound<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            levelWords<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">word</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> wordList<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            levelWords<span class=\"token punctuation\">.</span><span class=\"token function\">clear</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> word <span class=\"token operator\">=</span> node<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> head <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> tail <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> c <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> c <span class=\"token operator\">&lt;</span> <span class=\"token number\">26</span><span class=\"token punctuation\">;</span> c<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">ALPHABET</span><span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> word<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">const</span> w <span class=\"token operator\">=</span> head <span class=\"token operator\">+</span> <span class=\"token constant\">ALPHABET</span><span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> tail<span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>w <span class=\"token operator\">===</span> endWord<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">const</span> path <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>endWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> n <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span> n <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span> n <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            path<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        isEndWordFound <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>wordList<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        levelWords<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>w<span class=\"token punctuation\">,</span> node<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Breadth-first Search\": <a href=\"https://leetcode.com/tag/breadth-first-search\">https://leetcode.com/tag/breadth-first-search</a>\nSimilar Questions:\n\"Word Ladder II\": <a href=\"https://leetcode.com/problems/word-ladder-ii\">https://leetcode.com/problems/word-ladder-ii</a>\n\"Minimum Genetic Mutation\": <a href=\"https://leetcode.com/problems/minimum-genetic-mutation\">https://leetcode.com/problems/minimum-genetic-mutation</a></p>\n<hr>\n<p><a href=\"#127-word-ladderhttpsleetcodecomproblemsword-ladderdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/word-ladder/description/\">127. Word Ladder</a></h2>\n<h3>Problem</h3>\n<p>Given two words (<em>beginWord</em> and <em>endWord</em>), and a dictionary's word list, find the length of shortest transformation sequence from <em>beginWord</em> to <em>endWord</em>, such that:</p>\n<ol>\n<li>Only one letter can be changed at a time.</li>\n<li>Each transformed word must exist in the word list. Note that <em>beginWord</em> is <em>not</em> a transformed word.</li>\n</ol>\n<p><strong>Note:</strong></p>\n<ul>\n<li>Return 0 if there is no such transformation sequence.</li>\n<li>All words have the same length.</li>\n<li>All words contain only lowercase alphabetic characters.</li>\n<li>You may assume no duplicates in the word list.</li>\n<li>You may assume <em>beginWord</em> and <em>endWord</em> are non-empty and are not the same.</li>\n</ul>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nbeginWord = \"hit\",\nendWord = \"cog\",\nwordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\n\nOutput: 5\n\nExplanation: As one shortest transformation is \"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> \"cog\",\nreturn its length 5.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nbeginWord = \"hit\"\nendWord = \"cog\"\nwordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\n\nOutput: 0\n\nExplanation: The endWord \"cog\" is not in wordList, therefore no possible transformation.</code></pre></div>\n<h3>Solution</h3>\n<p>Think of it as building a tree, with <code class=\"language-text\">begineWord</code> as root and <code class=\"language-text\">endWord</code> as leaves.</p>\n<p>The best way control the depth (length of the shortest transformations) while building the tree is level-order traversal (BFS).</p>\n<p>We do not actually build the tree because it is expensive (astronomical if the list is huge). In fact, we only need one shortest path. So just like Dijkstra's algorithm, we say that the first time (level <code class=\"language-text\">i</code>) we encounter a word that turns out to be in a shortest path, then level <code class=\"language-text\">i</code> is the lowest level this word could ever get. We can safely remove it from the <code class=\"language-text\">wordList</code>.</p>\n<p>To find all the next words, instead of filtering the <code class=\"language-text\">wordList</code>, enumerate all 25 possible words and check if in <code class=\"language-text\">wordList</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} beginWord\n * @param {string} endWord\n * @param {string[]} wordList\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">ladderLength</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">beginWord<span class=\"token punctuation\">,</span> endWord<span class=\"token punctuation\">,</span> wordList</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    wordList <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>wordList<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>wordList<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>endWord<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> <span class=\"token constant\">ALPHABET</span> <span class=\"token operator\">=</span> <span class=\"token string\">'abcdefghijklmnopqrstuvwxyz'</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> level <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>beginWord<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> word <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>word <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            level<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> head <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> tail <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> c <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> c <span class=\"token operator\">&lt;</span> <span class=\"token number\">26</span><span class=\"token punctuation\">;</span> c<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">ALPHABET</span><span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> word<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">const</span> word <span class=\"token operator\">=</span> head <span class=\"token operator\">+</span> <span class=\"token constant\">ALPHABET</span><span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> tail<span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>word <span class=\"token operator\">===</span> endWord<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> level <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>wordList<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Hard\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Union Find\": <a href=\"https://leetcode.com/tag/union-find\">https://leetcode.com/tag/union-find</a>\nSimilar Questions:\n\"Binary Tree Longest Consecutive Sequence\": <a href=\"https://leetcode.com/problems/binary-tree-longest-consecutive-sequence\">https://leetcode.com/problems/binary-tree-longest-consecutive-sequence</a></p>\n<hr>\n<p><a href=\"#128-longest-consecutive-sequencehttpsleetcodecomproblemslongest-consecutive-sequencedescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/longest-consecutive-sequence/description/\">128. Longest Consecutive Sequence</a></h2>\n<h3>Problem</h3>\n<p>Given an unsorted array of integers, find the length of the longest consecutive elements sequence.</p>\n<p>Your algorithm should run in O(<em>n</em>) complexity.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [100, 4, 200, 1, 3, 2]\nOutput: 4\nExplanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.</code></pre></div>\n<h3>Solution</h3>\n<p>Build a Set from the list. Pick a number, find all it's adjacent numbers that are also in the Set. Count them and remove them all from the Set. Repeat until the Set is empty. Time complexity O(n + n) = O(n).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} nums\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">longestConsecutive</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">nums</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> numSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>nums<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> maxCount <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>numSet<span class=\"token punctuation\">.</span>size <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> num <span class=\"token operator\">=</span> numSet<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span>\n        numSet<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> n <span class=\"token operator\">=</span> num <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> numSet<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> n<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            count<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> n <span class=\"token operator\">=</span> num <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> numSet<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> n<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            count<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">></span> maxCount<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            maxCount <span class=\"token operator\">=</span> count<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> maxCount<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Tree\": <a href=\"https://leetcode.com/tag/tree\">https://leetcode.com/tag/tree</a>\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\nSimilar Questions:\n\"Path Sum\": <a href=\"https://leetcode.com/problems/path-sum\">https://leetcode.com/problems/path-sum</a>\n\"Binary Tree Maximum Path Sum\": <a href=\"https://leetcode.com/problems/binary-tree-maximum-path-sum\">https://leetcode.com/problems/binary-tree-maximum-path-sum</a></p>\n<hr>\n<p><a href=\"#129-sum-root-to-leaf-numbershttpsleetcodecomproblemssum-root-to-leaf-numbersdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/sum-root-to-leaf-numbers/description/\">129. Sum Root to Leaf Numbers</a></h2>\n<h3>Problem</h3>\n<p>Given a binary tree containing digits from <code class=\"language-text\">0-9</code> only, each root-to-leaf path could represent a number.</p>\n<p>An example is the root-to-leaf path <code class=\"language-text\">1->2->3</code> which represents the number <code class=\"language-text\">123</code>.</p>\n<p>Find the total sum of all root-to-leaf numbers.</p>\n<p><strong>Note:</strong> A leaf is a node with no children.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [1,2,3]\n    1\n   / \\\n  2   3\nOutput: 25\nExplanation:\nThe root-to-leaf path 1->2 represents the number 12.\nThe root-to-leaf path 1->3 represents the number 13.\nTherefore, sum = 12 + 13 = 25.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [4,9,0,5,1]\n    4\n   / \\\n  9   0\n / \\\n5   1\nOutput: 1026\nExplanation:\nThe root-to-leaf path 4->9->5 represents the number 495.\nThe root-to-leaf path 4->9->1 represents the number 491.\nThe root-to-leaf path 4->0 represents the number 40.\nTherefore, sum = 495 + 491 + 40 = 1026.</code></pre></div>\n<h3>Solution</h3>\n<p>To write a clean solution for this promblem, use <code class=\"language-text\">0</code> as indicator of leaf node. If all the children get <code class=\"language-text\">0</code>, it is a leaf node, return the sum of current level.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">sumNumbers</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root<span class=\"token punctuation\">,</span> sum <span class=\"token operator\">=</span> <span class=\"token number\">0</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    sum <span class=\"token operator\">=</span> sum <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">+</span> root<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">sumNumbers</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">,</span> sum<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">sumNumbers</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">,</span> sum<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> sum<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\n\"Breadth-first Search\": <a href=\"https://leetcode.com/tag/breadth-first-search\">https://leetcode.com/tag/breadth-first-search</a>\n\"Union Find\": <a href=\"https://leetcode.com/tag/union-find\">https://leetcode.com/tag/union-find</a>\nSimilar Questions:\n\"Number of Islands\": <a href=\"https://leetcode.com/problems/number-of-islands\">https://leetcode.com/problems/number-of-islands</a>\n\"Walls and Gates\": <a href=\"https://leetcode.com/problems/walls-and-gates\">https://leetcode.com/problems/walls-and-gates</a></p>\n<hr>\n<p><a href=\"#130-surrounded-regionshttpsleetcodecomproblemssurrounded-regionsdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/surrounded-regions/description/\">130. Surrounded Regions</a></h2>\n<h3>Problem</h3>\n<p>Given a 2D board containing <code class=\"language-text\">'X'</code> and <code class=\"language-text\">'O'</code> (<strong>the letter O</strong>), capture all regions surrounded by <code class=\"language-text\">'X'</code>.</p>\n<p>A region is captured by flipping all <code class=\"language-text\">'O'</code>s into <code class=\"language-text\">'X'</code>s in that surrounded region.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">X X X X\nX O O X\nX X O X\nX O X X</code></pre></div>\n<p>After running your function, the board should be:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">X X X X\nX X X X\nX X X X\nX O X X</code></pre></div>\n<p><strong>Explanation:</strong></p>\n<p>Surrounded regions shouldn't be on the border, which means that any <code class=\"language-text\">'O'</code> on the border of the board are not flipped to <code class=\"language-text\">'X'</code>. Any <code class=\"language-text\">'O'</code> that is not on the border and it is not connected to an <code class=\"language-text\">'O'</code> on the border will be flipped to <code class=\"language-text\">'X'</code>. Two cells are connected if they are adjacent cells connected horizontally or vertically.</p>\n<h3>Solution</h3>\n<p>Find all the <code class=\"language-text\">O</code>s that are connected to the <code class=\"language-text\">O</code>s on the border, change them to <code class=\"language-text\">#</code>. Then scan the board, change <code class=\"language-text\">O</code> to <code class=\"language-text\">X</code> and <code class=\"language-text\">#</code> back to <code class=\"language-text\">O</code>.</p>\n<p>The process of finding the connected <code class=\"language-text\">O</code>s is just like tree traversal. <code class=\"language-text\">O</code>s on the border are the same level. Their children are the second level. And so on.</p>\n<p>So both BFS and DFS are good. I prefer BFS when pruning is not needed in favor of its readability.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {character[][]} board\n * @return {void} Do not return anything, modify board in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">solve</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">board</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> height <span class=\"token operator\">=</span> board<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>height <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">const</span> width <span class=\"token operator\">=</span> board<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>width <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> rowend <span class=\"token operator\">=</span> height <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> colend <span class=\"token operator\">=</span> width <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> row <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> row <span class=\"token operator\">&lt;</span> height<span class=\"token punctuation\">;</span> row<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>colend<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>colend<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">,</span> colend<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> col <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> col <span class=\"token operator\">&lt;</span> width<span class=\"token punctuation\">;</span> col<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> col<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>rowend<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>rowend<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>rowend<span class=\"token punctuation\">,</span> col<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> row <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> col <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>row <span class=\"token operator\">&lt;</span> rowend <span class=\"token operator\">&amp;&amp;</span> board<span class=\"token punctuation\">[</span>row <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> col<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>row <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> board<span class=\"token punctuation\">[</span>row <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> col<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">,</span> col <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">,</span> col <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> row <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> row <span class=\"token operator\">&lt;</span> height<span class=\"token punctuation\">;</span> row<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> col <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> col <span class=\"token operator\">&lt;</span> width<span class=\"token punctuation\">;</span> col<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'X'</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\n\"Breadth-first Search\": <a href=\"https://leetcode.com/tag/breadth-first-search\">https://leetcode.com/tag/breadth-first-search</a>\n\"Graph\": <a href=\"https://leetcode.com/tag/graph\">https://leetcode.com/tag/graph</a>\nSimilar Questions:\n\"Copy List with Random Pointer\": <a href=\"https://leetcode.com/problems/copy-list-with-random-pointer\">https://leetcode.com/problems/copy-list-with-random-pointer</a></p>\n<hr>\n<p><a href=\"#133-clone-graphhttpsleetcodecomproblemsclone-graphdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/clone-graph/description/\">133. Clone Graph</a></h2>\n<h3>Problem</h3>\n<p>Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph contains a <code class=\"language-text\">label</code> (<code class=\"language-text\">int</code>) and a list (<code class=\"language-text\">List[UndirectedGraphNode]</code>) of its <code class=\"language-text\">neighbors</code>. There is an edge between the given node and each of the nodes in its neighbors.</p>\n<p>OJ's undirected graph serialization (so you can understand error output):</p>\n<p>Nodes are labeled uniquely.</p>\n<p>We use <code class=\"language-text\">#</code> as a separator for each node, and <code class=\"language-text\">,</code> as a separator for node label and each neighbor of the node.</p>\n<p>As an example, consider the serialized graph <code class=\"language-text\">{0,1,2#1,2#2,2}</code>.</p>\n<p>The graph has a total of three nodes, and therefore contains three parts as separated by <code class=\"language-text\">#</code>.</p>\n<ol>\n<li>First node is labeled as <code class=\"language-text\">0</code>. Connect node <code class=\"language-text\">0</code> to both nodes <code class=\"language-text\">1</code> and <code class=\"language-text\">2</code>.</li>\n<li>Second node is labeled as <code class=\"language-text\">1</code>. Connect node <code class=\"language-text\">1</code> to node <code class=\"language-text\">2</code>.</li>\n<li>Third node is labeled as <code class=\"language-text\">2</code>. Connect node <code class=\"language-text\">2</code> to node <code class=\"language-text\">2</code> (itself), thus forming a self-cycle.</li>\n</ol>\n<p>Visually, the graph looks like the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">       1\n      / \\\n     /   \\\n    0 --- 2\n         / \\\n         \\_/</code></pre></div>\n<p><strong>Note</strong>: The information about the tree serialization is only meant so that you can understand error output if you get a wrong answer. You don't need to understand the serialization to solve the problem.</p>\n<h3>Solution</h3>\n<p>DFS. Cache the visited node before entering the next recursion.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for undirected graph.\n * function UndirectedGraphNode(label) {\n *     this.label = label;\n *     this.neighbors = [];   // Array of UndirectedGraphNode\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {UndirectedGraphNode} graph\n * @return {UndirectedGraphNode}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">cloneGraph</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">graph</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> cache <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">_clone</span><span class=\"token punctuation\">(</span>graph<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">_clone</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">graph</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>graph<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> graph<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">const</span> label <span class=\"token operator\">=</span> graph<span class=\"token punctuation\">.</span>label<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>cache<span class=\"token punctuation\">[</span>label<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            cache<span class=\"token punctuation\">[</span>label<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">UndirectedGraphNode</span><span class=\"token punctuation\">(</span>label<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            cache<span class=\"token punctuation\">[</span>label<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>neighbors <span class=\"token operator\">=</span> graph<span class=\"token punctuation\">.</span>neighbors<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_clone<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> cache<span class=\"token punctuation\">[</span>label<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><img src=\"https://github.com/everthis/leetcode-js/blob/master/images/binary-tree-upside-down.webp\" alt=\"alt text\" title=\"binary-tree-upside-down\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">upsideDownBinaryTree</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> curr <span class=\"token operator\">=</span> root<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> prev <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>curr <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        next <span class=\"token operator\">=</span> curr<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n        curr<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span>\n        temp <span class=\"token operator\">=</span> curr<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n        curr<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> prev<span class=\"token punctuation\">;</span>\n        prev <span class=\"token operator\">=</span> curr<span class=\"token punctuation\">;</span>\n        curr <span class=\"token operator\">=</span> next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> prev<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// another</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">upsideDownBinaryTree</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root <span class=\"token operator\">==</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">||</span> root<span class=\"token punctuation\">.</span>left <span class=\"token operator\">==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> root<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">const</span> newRoot <span class=\"token operator\">=</span> <span class=\"token function\">upsideDownBinaryTree</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n    root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> root<span class=\"token punctuation\">;</span>\n    root<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    root<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> newRoot<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><img src=\"https://github.com/everthis/leetcode-js/blob/master/images/maximum-sum-circular-subarray.png\" alt=\"alt text\" title=\"maximum-sum-circular-subarray\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} A\n * @return {number}\n */</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">maxSubarraySumCircular</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token constant\">A</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> minSum <span class=\"token operator\">=</span> <span class=\"token number\">Infinity</span><span class=\"token punctuation\">,</span>\n        sum <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n        maxSum <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">,</span>\n        curMax <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n        curMin <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> a <span class=\"token keyword\">of</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        sum <span class=\"token operator\">+=</span> a<span class=\"token punctuation\">;</span>\n        curMax <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>curMax <span class=\"token operator\">+</span> a<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        maxSum <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>maxSum<span class=\"token punctuation\">,</span> curMax<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        curMin <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>curMin <span class=\"token operator\">+</span> a<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        minSum <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>minSum<span class=\"token punctuation\">,</span> curMin<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> maxSum <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>maxSum<span class=\"token punctuation\">,</span> sum <span class=\"token operator\">-</span> minSum<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> maxSum<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><a href=\"#balanced-binary-tree---leetcode\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h1>➤ Balanced Binary Tree - LeetCode</h1>\n<blockquote>\n<p>Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.</p>\n</blockquote>\n<p>Given a binary tree, determine if it is height-balanced.</p>\n<p>For this problem, a height-balanced binary tree is defined as:</p>\n<blockquote>\n<p>a binary tree in which the left and right subtrees of <em>every</em> node differ in height by no more than 1.</p>\n</blockquote>\n<p><strong>Example 1:</strong></p>\n<p><img src=\"https://assets.leetcode.com/uploads/2020/10/06/balance_1.jpg\" alt=\"image\"></p>\n<p><strong>Input:</strong> root = [3,9,20,null,null,15,7]\n<strong>Output:</strong> true</p>\n<p><strong>Example 2:</strong></p>\n<p><img src=\"https://assets.leetcode.com/uploads/2020/10/06/balance_2.jpg\" alt=\"image\"></p>\n<p><strong>Input:</strong> root = [1,2,2,3,3,null,null,4,4]\n<strong>Output:</strong> false</p>\n<p><strong>Example 3:</strong></p>\n<p><strong>Input:</strong> root = []\n<strong>Output:</strong> true</p>\n<p><strong>Constraints:</strong></p>\n<ul>\n<li>The number of nodes in the tree is in the range <code class=\"language-text\">[0, 5000]</code>.</li>\n<li><code class=\"language-text\">-104 &lt;= Node.val &lt;= 104</code></li>\n</ul>\n<p><a href=\"https://leetcode.com/problems/balanced-binary-tree/\">Source</a># Convert Sorted Array to Binary Search Tree</p>\n<blockquote>\n<p>Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.</p>\n</blockquote>\n<p>Given an array where elements are sorted in ascending order, convert it to a height balanced BST.</p>\n<p>For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of <em>every</em> node never differ by more than 1.</p>\n<p><strong>Example:</strong></p>\n<p>Given the sorted array: [-10,-3,0,5,9],</p>\n<p>One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  0\n / \\\\</code></pre></div>\n<p>-3 9\n/ /\n-10 5</p>\n<p><a href=\"https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/\">Source</a># Delete Node in a BST</p>\n<blockquote>\n<p>Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.</p>\n</blockquote>\n<p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.</p>\n<p>Basically, the deletion can be divided into two stages:</p>\n<ol>\n<li>Search for a node to remove.</li>\n<li>If the node is found, delete the node.</li>\n</ol>\n<p><strong>Follow up:</strong> Can you solve it with time complexity <code class=\"language-text\">O(height of tree)</code>?</p>\n<p><strong>Example 1:</strong></p>\n<p><img src=\"https://assets.leetcode.com/uploads/2020/09/04/del_node_1.jpg\" alt=\"image\"></p>\n<p><strong>Input:</strong> root = [5,3,6,2,4,null,7], key = 3\n<strong>Output:</strong> [5,4,6,2,null,null,7]\n<strong>Explanation:</strong> Given key to delete is 3. So we find the node with value 3 and delete it.\nOne valid answer is [5,4,6,2,null,null,7], shown in the above BST.\nPlease notice that another valid answer is [5,2,6,null,4,null,7] and it's also accepted.</p>\n<p><img src=\"https://assets.leetcode.com/uploads/2020/09/04/del_node_supp.jpg\" alt=\"image\"></p>\n<p><strong>Example 2:</strong></p>\n<p><strong>Input:</strong> root = [5,3,6,2,4,null,7], key = 0\n<strong>Output:</strong> [5,3,6,2,4,null,7]\n<strong>Explanation:</strong> The tree does not contain a node with value = 0.</p>\n<p><strong>Example 3:</strong></p>\n<p><strong>Input:</strong> root = [], key = 0\n<strong>Output:</strong> []</p>\n<p><strong>Constraints:</strong></p>\n<ul>\n<li>The number of nodes in the tree is in the range <code class=\"language-text\">[0, 104]</code>.</li>\n<li><code class=\"language-text\">-105 &lt;= Node.val &lt;= 105</code></li>\n<li>Each node has a <strong>unique</strong> value.</li>\n<li><code class=\"language-text\">root</code> is a valid binary search tree.</li>\n<li><code class=\"language-text\">-105 &lt;= key &lt;= 105</code></li>\n</ul>\n<p><a href=\"https://leetcode.com/problems/delete-node-in-a-bst/\">Source</a><img src=\"https://github.com/everthis/leetcode-js/blob/master/images/meeting-room-ii-0.jpg\" alt=\"alt text\" title=\"meeting-room-ii\">\n<img src=\"https://github.com/everthis/leetcode-js/blob/master/images/meeting-room-ii-1.jpg\" alt=\"alt text\" title=\"meeting-room-ii\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[][]} intervals\n * @return {number}\n */</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">minMeetingRooms</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">intervals</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> len <span class=\"token operator\">=</span> intervals<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> starts <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span>len<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> ends <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span>len<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        starts<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> intervals<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        ends<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> intervals<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    starts<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    ends<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> rooms <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> endsIdx <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>starts<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> ends<span class=\"token punctuation\">[</span>endsIdx<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> rooms<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">else</span> endsIdx<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> rooms<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>"},{"url":"/blog/embedding-media-in-html/","relativePath":"blog/embedding-media-in-html.md","relativeDir":"blog","base":"embedding-media-in-html.md","name":"embedding-media-in-html","frontmatter":{"title":"Embedding Media In Html","template":"post","subtitle":"From object to iframe ","excerpt":"getting the hang of embedding things into your web pages","date":"2022-04-19T20:11:27.517Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embedded-media.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embedded-media.png?raw=true","image_position":"right","show_author_bio":false,"cmseditable":true},"html":"<!--StartFragment-->\n<h1>From object to iframe</h1>\n<p>By now you should really be getting the hang of embedding things into your web pages, including images, video and audio. At this point we'd like to take somewhat of a sideways step, looking at some elements that allow you to embed a wide variety of content types into your webpages: the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a> elements. <code class=\"language-text\">&lt;iframe></code>s are for embedding other web pages, and the other two allow you to embed PDFs, SVG, and even Flash — a technology that is on the way out, but which you'll still see semi-regularly.</p>\n<table>\n<thead>\n<tr>\n<th>Prerequisites:</th>\n<th>Basic computer literacy, <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/Installing_basic_software\">basic software installed</a>, basic knowledge of <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/Dealing_with_files\">working with files</a>, familiarity with HTML fundamentals (as covered in <a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Getting_started\">Getting started with HTML</a>) and the previous articles in this module.</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Objective:</td>\n<td>To learn how to embed items into web pages using <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a>, and <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a>, like PDF documents and other webpages.</td>\n</tr>\n</tbody>\n</table>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#a_short_history_of_embedding\" title=\"Permalink to A short history of embedding\">A short history of embedding</a></h2>\n<p>A long time ago on the Web, it was popular to use <strong>frames</strong> to create websites — small parts of a website stored in individual HTML pages. These were embedded in a master document called a <strong>frameset</strong>, which allowed you to specify the area on the screen that each frame filled, rather like sizing the columns and rows of a table. These were considered the height of coolness in the mid to late 90s, and there was evidence that having a webpage split up into smaller chunks like this was better for download speeds — especially noticeable with network connections being so slow back then. They did however have many problems, which far outweighed any positives as network speeds got faster, so you don't see them being used anymore.</p>\n<p>A little while later (late 90s, early 2000s), plugin technologies became very popular, such as <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Java\">Java Applets</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Adobe_Flash\">Flash</a> — these allowed web developers to embed rich content into webpages such as videos and animations, which just weren't available through HTML alone. Embedding these technologies was achieved through elements like <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a>, and the lesser-used <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a>, and they were very useful at the time. They have since fallen out of fashion due to many problems, including accessibility, security, file size, and more. These days major browsers have stopped supporting plugins such as Flash.</p>\n<p>Finally, the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a> element appeared (along with other ways of embedding content, such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas\"><code class=\"language-text\">&lt;canvas></code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a>, etc.) This provides a way to embed an entire web document inside another one, as if it were an <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img\"><code class=\"language-text\">&lt;img></code></a> or other such element, and is used regularly today.</p>\n<p>With the history lesson out of the way, let's move on and see how to use some of these.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#active_learning_classic_embedding_uses\" title=\"Permalink to Active learning: classic embedding uses\">Active learning: classic embedding uses</a></h2>\n<p>In this article we are going to jump straight into an active learning section, to immediately give you a real idea of just what embedding technologies are useful for. The online world is very familiar with <a href=\"https://www.youtube.com/\">YouTube</a>, but many people don't know about some of the sharing facilities it has available. Let's look at how YouTube allows us to embed a video in any page we like using an <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a>.</p>\n<ol>\n<li>First, go to YouTube and find a video you like.</li>\n<li>Below the video, you'll find a <em>Share</em> button — select this to display the sharing options.</li>\n<li>Select the <em>Embed</em> button and you'll be given some <code class=\"language-text\">&lt;iframe></code> code — copy this.</li>\n<li>Insert it into the <em>Input</em> box below, and see what the result is in the <em>Output</em>.</li>\n</ol>\n<p>For bonus points, you could also try embedding a <a href=\"https://www.google.com/maps/\">Google Map</a> in the example:</p>\n<ol>\n<li>Go to Google Maps and find a map you like.</li>\n<li>Click on the \"Hamburger Menu\" (three horizontal lines) in the top left of the UI.</li>\n<li>Select the <em>Share or embed map</em> option.</li>\n<li>Select the Embed map option, which will give you some <code class=\"language-text\">&lt;iframe></code> code — copy this.</li>\n<li>Insert it into the <em>Input</em> box below, and see what the result is in the <em>Output</em>.</li>\n</ol>\n<p>If you make a mistake, you can always reset it using the <em>Reset</em> button. If you get really stuck, press the <em>Show solution</em> button to see an answer.</p>\n<p><a href=\"https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies/_sample_.active_learning_classic_embedding_uses.html\">Active learning classic embedding uses sample</a></p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#iframes_in_detail\" title=\"Permalink to iframes in detail\">iframes in detail</a></h2>\n<p>So, that was easy and fun, right? <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a> elements are designed to allow you to embed other web documents into the current document. This is great for incorporating third-party content into your website that you might not have direct control over and don't want to have to implement your own version of — such as video from online video providers, commenting systems like <a href=\"https://disqus.com/\">Disqus</a>, maps from online map providers, advertising banners, etc. The live editable examples you've been using through this course are implemented using <code class=\"language-text\">&lt;iframe></code>s.</p>\n<p>There are some serious <a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#security_concerns\">Security concerns</a> to consider with <code class=\"language-text\">&lt;iframe></code>s, as we'll discuss below, but this doesn't mean that you shouldn't use them in your websites — it just requires some knowledge and careful thinking. Let's explore the code in a bit more detail. Say you wanted to include the MDN glossary on one of your web pages — you could try something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>This example includes the basic essentials needed to use an <code class=\"language-text\">&lt;iframe></code>:</p>\n<ul>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border\"><code class=\"language-text\">border: none</code></a></p>\n<p>If used, the <code class=\"language-text\">&lt;iframe></code> is displayed without a surrounding border. Otherwise, by default, browsers display the <code class=\"language-text\">&lt;iframe></code> with a surrounding border (which is generally undesirable).</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-allowfullscreen\"><code class=\"language-text\">allowfullscreen</code></a></p>\n<p>If set, the <code class=\"language-text\">&lt;iframe></code> is able to be placed in fullscreen mode using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API\">Fullscreen API</a> (somewhat beyond the scope of this article.)</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-src\"><code class=\"language-text\">src</code></a></p>\n<p>This attribute, as with <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a>/<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img\"><code class=\"language-text\">&lt;img></code></a>, contains a path pointing to the URL of the document to be embedded.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-width\"><code class=\"language-text\">width</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-height\"><code class=\"language-text\">height</code></a></p>\n<p>These attributes specify the width and height you want the iframe to be.</p>\n</li>\n<li>\n<p>Fallback content</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In the same way as other similar elements like [`&lt;video>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video), you can include fallback content between the opening and closing `&lt;iframe></code></pre></div>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\"><code class=\"language-text\">sandbox</code></a></p>\n<p>This attribute, which works in slightly more modern browsers than the rest of the <code class=\"language-text\">&lt;iframe></code> features (e.g. IE 10 and above) requests heightened security settings; we'll say more about this in the next section.</p>\n</li>\n</ul>\n<p><strong>Note:</strong> In order to improve speed, it's a good idea to set the iframe's <code class=\"language-text\">src</code> attribute with JavaScript after the main content is done with loading. This makes your page usable sooner and decreases your official page load time (an important <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/SEO\">SEO</a> metric.)</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#security_concerns\" title=\"Permalink to Security concerns\">Security concerns</a></h3>\n<p>Above we mentioned security concerns — let's go into this in a bit more detail now. We are not expecting you to understand all of this content perfectly the first time; we just want to make you aware of this concern, and provide a reference to come back to as you get more experienced and start considering using <code class=\"language-text\">&lt;iframe></code>s in your experiments and work. Also, there is no need to be scared and not use <code class=\"language-text\">&lt;iframe></code>s — you just need to be careful. Read on...</p>\n<p>Browser makers and Web developers have learned the hard way that iframes are a common target (official term: <strong>attack vector</strong>) for bad people on the Web (often termed <strong>hackers</strong>, or more accurately, <strong>crackers</strong>) to attack if they are trying to maliciously modify your webpage, or trick people into doing something they don't want to do, such as reveal sensitive information like usernames and passwords. Because of this, spec engineers and browser developers have developed various security mechanisms for making <code class=\"language-text\">&lt;iframe></code>s more secure, and there are also best practices to consider — we'll cover some of these below.</p>\n<p><strong>Note:</strong> <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Clickjacking\">Clickjacking</a> is one kind of common iframe attack where hackers embed an invisible iframe into your document (or embed your document into their own malicious website) and use it to capture users' interactions. This is a common way to mislead users or steal sensitive data.</p>\n<p>A quick example first though — try loading the previous example we showed above into your browser — you can <a href=\"https://mdn.github.io/learning-area/html/multimedia-and-embedding/other-embedding-technologies/iframe-detail.html\">find it live on GitHub</a> (<a href=\"https://github.com/mdn/learning-area/blob/gh-pages/html/multimedia-and-embedding/other-embedding-technologies/iframe-detail.html\">see the source code</a> too.) Instead of the page you expected, you'll probably see some kind of message to the effect of \"I can't open this page\", and if you look at the <em>Console</em> in the <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools\">browser developer tools</a>, you'll see a message telling you why. In Firefox, you'll get told something like <em>The loading of \"<a href=\"https://developer.mozilla.org/en-US/docs/Glossary\">https://developer.mozilla.org/en-US/docs/Glossary</a>\" in a frame is denied by \"X-Frame-Options\" directive set to \"DENY\".</em>. This is because the developers that built MDN have included a setting on the server that serves the website pages to disallow them from being embedded inside <code class=\"language-text\">&lt;iframe></code>s (see <a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#configure_csp_directives\">Configure CSP directives</a>, below.) This makes sense — an entire MDN page doesn't really make sense to be embedded in other pages unless you want to do something like embed them on your site and claim them as your own — or attempt to steal data via <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Clickjacking\">clickjacking</a>, which are both really bad things to do. Plus if everybody started to do this, all the additional bandwidth would start to cost Mozilla a lot of money.</p>\n<h4>Only embed when necessary</h4>\n<p>Sometimes it makes sense to embed third-party content — like youtube videos and maps — but you can save yourself a lot of headaches if you only embed third-party content when completely necessary. A good rule of thumb for web security is <em>\"You can never be too cautious. If you made it, double-check it anyway. If someone else made it, assume it's dangerous until proven otherwise.\"</em></p>\n<p>Besides security, you should also be aware of intellectual property issues. Most content is copyrighted, offline and online, even content you might not expect (for example, most images on <a href=\"https://commons.wikimedia.org/wiki/Main_Page\">Wikimedia Commons</a>). Never display content on your webpage unless you own it or the owners have given you written, unequivocal permission. Penalties for copyright infringement are severe. Again, you can never be too cautious.</p>\n<p>If the content is licensed, you must obey the license terms. For example, the content on MDN is <a href=\"https://developer.mozilla.org/en-US/docs/MDN/About#copyrights_and_licenses\">licensed under CC-BY-SA</a>. That means, you must <a href=\"https://wiki.creativecommons.org/wiki/Best_practices_for_attribution\">credit us properly</a> when you quote our content, even if you make substantial changes.</p>\n<h4>Use HTTPS</h4>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/https\">HTTPS</a> is the encrypted version of <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/HTTP\">HTTP</a>. You should serve your websites using HTTPS whenever possible:</p>\n<ol>\n<li>HTTPS reduces the chance that remote content has been tampered with in transit,</li>\n<li>HTTPS prevents embedded content from accessing content in your parent document, and vice versa.</li>\n</ol>\n<p>HTTPS-enabling your site requires a special security certificate to be installed. Many hosting providers offer HTTPS-enabled hosting without you needing to do any setup on your own to put a certificate in place. But if you <em>do</em> need to set up HTTPS support for your site on your own, <a href=\"https://letsencrypt.org/\">Let's Encrypt</a> provides tools and instructions you can use for automatically creating and installing the necessary certificate — with built-in support for the most widely-used web servers, including the Apache web server, Nginx, and others. The Let's Encrypt tooling is designed to make the process as easy as possible, so there's really no good reason to avoid using it or other available means to HTTPS-enable your site.</p>\n<p><strong>Note:</strong> <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Using_Github_pages\">GitHub pages</a> allow content to be served via HTTPS by default, so it is useful for hosting content. If you are using a different hosting provider and are not sure, ask them about it.</p>\n<h4>Always use the <code class=\"language-text\">sandbox</code> attribute</h4>\n<p>You want to give attackers as little power as you can to do bad things on your website, therefore you should give embedded content <em>only the permissions needed for doing its job.</em> Of course, this applies to your own content, too. A container for code where it can be used appropriately — or for testing — but can't cause any harm to the rest of the codebase (either accidental or malicious) is called a <a href=\"https://en.wikipedia.org/wiki/Sandbox_(computer_security)\">sandbox</a>.</p>\n<p>Unsandboxed content can do way too much (executing JavaScript, submitting forms, popup windows, etc.) By default, you should impose all available restrictions by using the <code class=\"language-text\">sandbox</code> attribute with no parameters, as shown in our previous example.</p>\n<p>If absolutely required, you can add permissions back one by one (inside the <code class=\"language-text\">sandbox=\"\"</code> attribute value) — see the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\"><code class=\"language-text\">sandbox</code></a> reference entry for all the available options. One important note is that you should <em>never</em> add both <code class=\"language-text\">allow-scripts</code> and <code class=\"language-text\">allow-same-origin</code> to your <code class=\"language-text\">sandbox</code> attribute — in that case, the embedded content could bypass the <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Same-origin_policy\">Same-origin policy</a> that stops sites from executing scripts, and use JavaScript to turn off sandboxing altogether.</p>\n<p><strong>Note:</strong> Sandboxing provides no protection if attackers can fool people into visiting malicious content directly (outside an <code class=\"language-text\">iframe</code>). If there's any chance that certain content may be malicious (e.g., user-generated content), please serve it from a different <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Domain\">domain</a> to your main site.</p>\n<h4>Configure CSP directives</h4>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/CSP\">CSP</a> stands for <strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP\">content security policy</a></strong> and provides <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy\">a set of HTTP Headers</a> (metadata sent along with your web pages when they are served from a web server) designed to improve the security of your HTML document. When it comes to securing <code class=\"language-text\">&lt;iframe></code>s, you can <em><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options\">configure your server to send an appropriate <code class=\"language-text\">X-Frame-Options</code> header.</a></em> This can prevent other websites from embedding your content in their web pages (which would enable <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Clickjacking\">clickjacking</a> and a host of other attacks), which is exactly what the MDN developers have done, as we saw earlier on.</p>\n<p><strong>Note:</strong> You can read Frederik Braun's post <a href=\"https://blog.mozilla.org/security/2013/12/12/on-the-x-frame-options-security-header/\">On the X-Frame-Options Security Header</a> for more background information on this topic. Obviously, it's rather out of scope for a full explanation in this article.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#the_embed_and_object_elements\" title=\"Permalink to The <embed> and <object> elements\">The <embed> and <object> elements</a></h2>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a> elements serve a different function to <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a> — these elements are general purpose embedding tools for embedding external content, such as PDFs.</p>\n<p>However, you are unlikely to use these elements very much. If you need to display PDFs, it's usually better to link to them, rather than embedding them in the page.</p>\n<p>Historically these elements have also been used for embedding content handled by browser <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Plugin\">plugins</a> such as <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Adobe_Flash\">Adobe Flash</a>, but this technology is now obsolete and is not supported by modern browsers.</p>\n<p>If you find yourself needing to embed plugin content, this is the kind of information you'll need, at a minimum:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a></th>\n<th><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/URL\">URL</a> of the embedded content</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed#attr-src\"><code class=\"language-text\">src</code></a></td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attr-data\"><code class=\"language-text\">data</code></a></td>\n</tr>\n<tr>\n<td><em>accurate</em> <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/MIME_type\">media type</a> of the embedded content</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed#attr-type\"><code class=\"language-text\">type</code></a></td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attr-type\"><code class=\"language-text\">type</code></a></td>\n</tr>\n<tr>\n<td>height and width (in CSS pixels) of the box controlled by the plugin</td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed#attr-height\"><code class=\"language-text\">height</code></a> <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed#attr-width\"><code class=\"language-text\">width</code></a></td>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attr-height\"><code class=\"language-text\">height</code></a> <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attr-width\"><code class=\"language-text\">width</code></a></td>\n</tr>\n<tr>\n<td>names and values, to feed the plugin as parameters</td>\n<td>ad hoc attributes with those names and values</td>\n<td>single-tag <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/param\"><code class=\"language-text\">&lt;param></code></a> elements, contained within <code class=\"language-text\">&lt;object></code></td>\n</tr>\n<tr>\n<td>independent HTML content as fallback for an unavailable resource</td>\n<td>not supported (<code class=\"language-text\">&lt;noembed></code> is obsolete)</td>\n<td>contained within <code class=\"language-text\">&lt;object></code>, after <code class=\"language-text\">&lt;param></code> elements</td>\n</tr>\n</tbody>\n</table>\n<p>Let's look at an <code class=\"language-text\">&lt;object></code> example that embeds a PDF into a page (see the <a href=\"https://mdn.github.io/learning-area/html/multimedia-and-embedding/other-embedding-technologies/object-pdf.html\">live example</a> and the <a href=\"https://github.com/mdn/learning-area/blob/gh-pages/html/multimedia-and-embedding/other-embedding-technologies/object-pdf.html\">source code</a>):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>PDFs were a necessary stepping stone between paper and digital, but they pose many <a href=\"https://webaim.org/techniques/acrobat/acrobat\">accessibility challenges</a> and can be hard to read on small screens. They do still tend to be popular in some circles, but it is much better to link to them so they can be downloaded or read on a separate page, rather than embedding them in a webpage.</p>\n<!--EndFragment-->"},{"url":"/blog/deploy-react-app-to-heroku/","relativePath":"blog/deploy-react-app-to-heroku.md","relativeDir":"blog","base":"deploy-react-app-to-heroku.md","name":"deploy-react-app-to-heroku","frontmatter":{"title":"Deploy React App To Heroku","template":"post","subtitle":"Deploy React App To Heroku Using Postgres & Express","excerpt":"Heroku is an web application that makes deploying applications easy for a beginner.","date":"2022-05-16T02:38:59.629Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/heroku.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/heroku.png?raw=true","image_position":"top","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/react.yaml","src/data/categories/js.yaml","src/data/categories/git.yaml"],"tags":["src/data/tags/cms.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/react-state.md","src/pages/blog/react-semantics.md","src/pages/blog/using-the-dom.md"],"cmseditable":true},"html":"<h1>Deploy React App To Heroku Using Postgres &#x26; Express</h1>\n<p>Heroku is an web application that makes deploying applications easy for a beginner.</p>\n<hr>\n<h3>Deploy React App To Heroku Using Postgres &#x26; Express</h3>\n<p>Heroku is an web application that makes deploying applications easy for a beginner.</p>\n<p>Before you begin deploying, make sure to remove any <code class=\"language-text\">console.log</code>'s or <code class=\"language-text\">debugger</code>'s in any production code. You can search your entire project folder if you are using them anywhere.</p>\n<p>You will set up Heroku to run on a production, not development, version of your application. When a Node.js application like yours is pushed up to Heroku, it is identified as a Node.js application because of the <code class=\"language-text\">package.json</code> file. It runs <code class=\"language-text\">npm install</code> automatically. Then, if there is a <code class=\"language-text\">heroku-postbuild</code> script in the <code class=\"language-text\">package.json</code> file, it will run that script. Afterwards, it will automatically run <code class=\"language-text\">npm start</code>.</p>\n<p>In the following phases, you will configure your application to work in production, not just in development, and configure the <code class=\"language-text\">package.json</code> scripts for <code class=\"language-text\">install</code>, <code class=\"language-text\">heroku-postbuild</code> and <code class=\"language-text\">start</code> scripts to install, build your React application, and start the Express production server.</p>\n<h3>Phase 1: Heroku Connection</h3>\n<p>If you haven't created a Heroku account yet, create one <a href=\"https://signup.heroku.com/\" class=\"markup--anchor markup--p-anchor\">here</a>.</p>\n<p>Add a new application in your <a href=\"https://dashboard.heroku.com/\" class=\"markup--anchor markup--p-anchor\">Heroku dashboard</a> named whatever you want. Under the \"Resources\" tab in your new application, click \"Find more add-ons\" and add the \"Heroku Postgres\" add-on with the free Hobby Dev setting.</p>\n<p>In your terminal, install the <a href=\"https://devcenter.heroku.com/articles/heroku-command-line\" class=\"markup--anchor markup--p-anchor\">Heroku CLI</a>. Afterwards, login to Heroku in your terminal by running the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">heroku login</code></pre></div>\n<p>Add Heroku as a remote to your project's git repository in the following command and replace <code class=\"language-text\">&lt;name-of-Heroku-app></code> with the name of the application you created in the <a href=\"https://dashboard.heroku.com/\" class=\"markup--anchor markup--p-anchor\">Heroku dashboard</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">heroku git:remote -a &lt;name-of-Heroku-app></code></pre></div>\n<p>Next, you will set up your Express + React application to be deployable to Heroku.</p>\n<h3>Phase 2: Setting up your Express + React application</h3>\n<p>Right now, your React application is on a different localhost port than your Express application. However, since your React application only consists of static files that don't need to bundled continuously with changes in production, your Express application can serve the React assets in production too. These static files live in the <code class=\"language-text\">frontend/build</code> folder after running <code class=\"language-text\">npm run build</code> in the <code class=\"language-text\">frontend</code> folder.</p>\n<p>Add the following changes into your <code class=\"language-text\">backend/routes.index.js</code> file.</p>\n<p>At the root route, serve the React application's static <code class=\"language-text\">index.html</code> file along with <code class=\"language-text\">XSRF-TOKEN</code> cookie. Then serve up all the React application's static files using the <code class=\"language-text\">express.static</code> middleware. Serve the <code class=\"language-text\">index.html</code> and set the <code class=\"language-text\">XSRF-TOKEN</code> cookie again on all routes that don't start in <code class=\"language-text\">/api</code>. You should already have this set up in <code class=\"language-text\">backend/routes/index.js</code> which should now look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// backend/routes/index.js\nconst express = require('express');\nconst router = express.Router();\nconst apiRouter = require('./api');\n\nrouter.use('/api', apiRouter);\n\n// Static routes\n// Serve React build files in production\nif (process.env.NODE_ENV === 'production') {\n  const path = require('path');\n  // Serve the frontend's index.html file at the root route\n  router.get('/', (req, res) => {\n    res.cookie('XSRF-TOKEN', req.csrfToken());\n    res.sendFile(\n      path.resolve(__dirname, '../../frontend', 'build', 'index.html')\n    );\n  });\n\n  // Serve the static assets in the frontend's build folder\n  router.use(express.static(path.resolve(\"../frontend/build\")));\n\n  // Serve the frontend's index.html file at all other routes NOT starting with /api\n  router.get(/^(?!\\/?api).*/, (req, res) => {\n    res.cookie('XSRF-TOKEN', req.csrfToken());\n    res.sendFile(\n      path.resolve(__dirname, '../../frontend', 'build', 'index.html')\n    );\n  });\n}\n\n// Add a XSRF-TOKEN cookie in development\nif (process.env.NODE_ENV !== 'production') {\n  router.get('/api/csrf/restore', (req, res) => {\n    res.cookie('XSRF-TOKEN', req.csrfToken());\n    res.status(201).json({});\n  });\n}\n\nmodule.exports = router;</code></pre></div>\n<p>Your Express backend's <code class=\"language-text\">package.json</code> should include scripts to run the <code class=\"language-text\">sequelize</code> CLI commands.</p>\n<p>The <code class=\"language-text\">backend/package.json</code>'s scripts should now look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">\"scripts\": {\n    \"sequelize\": \"sequelize\",\n    \"sequelize-cli\": \"sequelize-cli\",\n    \"start\": \"per-env\",\n    \"start:development\": \"nodemon -r dotenv/config ./bin/www\",\n    \"start:production\": \"node ./bin/www\"\n  },</code></pre></div>\n<p>Initialize a <code class=\"language-text\">package.json</code> file at the very root of your project directory (outside of both the <code class=\"language-text\">backend</code> and <code class=\"language-text\">frontend</code> folders). The scripts defined in this <code class=\"language-text\">package.json</code> file will be run by Heroku, not the scripts defined in the <code class=\"language-text\">backend/package.json</code> or the <code class=\"language-text\">frontend/package.json</code>.</p>\n<p>When Heroku runs <code class=\"language-text\">npm install</code>, it should install packages for both the <code class=\"language-text\">backend</code> and the <code class=\"language-text\">frontend</code>. Overwrite the <code class=\"language-text\">install</code> script in the root <code class=\"language-text\">package.json</code> with:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm --prefix backend install backend &amp;&amp; npm --prefix frontend install frontend</code></pre></div>\n<p>This will run <code class=\"language-text\">npm install</code> in the <code class=\"language-text\">backend</code> folder then run <code class=\"language-text\">npm install</code> in the <code class=\"language-text\">frontend</code> folder.</p>\n<p>Next, define a <code class=\"language-text\">heroku-postbuild</code> script that will run the <code class=\"language-text\">npm run build</code> command in the <code class=\"language-text\">frontend</code> folder. Remember, Heroku will automatically run this script after running <code class=\"language-text\">npm install</code>.</p>\n<p>Define a <code class=\"language-text\">sequelize</code> script that will run <code class=\"language-text\">npm run sequelize</code> in the <code class=\"language-text\">backend</code> folder.</p>\n<p>Finally, define a <code class=\"language-text\">start</code> that will run <code class=\"language-text\">npm start</code> in the `backend folder.</p>\n<p>The root <code class=\"language-text\">package.json</code>'s scripts should look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">\"scripts\": {\n    \"heroku-postbuild\": \"npm run build --prefix frontend\",\n    \"install\": \"npm --prefix backend install backend &amp;&amp; npm --prefix frontend install frontend\",\n    \"dev:backend\": \"npm install --prefix backend start\",\n    \"dev:frontend\": \"npm install --prefix frontend start\",\n    \"sequelize\": \"npm run --prefix backend sequelize\",\n    \"sequelize-cli\": \"npm run --prefix backend sequelize-cli\",\n    \"start\": \"npm start --prefix backend\"\n  },</code></pre></div>\n<p>The <code class=\"language-text\">dev:backend</code> and <code class=\"language-text\">dev:frontend</code> scripts are optional and will not be used for Heroku.</p>\n<p>Finally, commit your changes.</p>\n<h3>Phase 3: Deploy to Heroku</h3>\n<p>Once you're finished setting this up, navigate to your application's Heroku dashboard. Under \"Settings\" there is a section for \"Config Vars\". Click the <code class=\"language-text\">Reveal Config Vars</code> button to see all your production environment variables. You should have a <code class=\"language-text\">DATABASE_URL</code> environment variable already from the Heroku Postgres add-on.</p>\n<p>Add environment variables for <code class=\"language-text\">JWT_EXPIRES_IN</code> and <code class=\"language-text\">JWT_SECRET</code> and any other environment variables you need for production.</p>\n<p>You can also set environment variables through the Heroku CLI you installed earlier in your terminal. See the docs for <a href=\"https://devcenter.heroku.com/articles/config-vars\" class=\"markup--anchor markup--p-anchor\">Setting Heroku Config Variables</a>.</p>\n<p>Push your project to Heroku. Heroku only allows the <code class=\"language-text\">master</code> branch to be pushed. But, you can alias your branch to be named <code class=\"language-text\">master</code> when pushing to Heroku. For example, to push a branch called <code class=\"language-text\">login-branch</code> to <code class=\"language-text\">master</code> run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git push heroku login-branch:master</code></pre></div>\n<p>If you do want to push the <code class=\"language-text\">master</code> branch, just run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git push heroku master</code></pre></div>\n<p>You may want to make two applications on Heroku, the <code class=\"language-text\">master</code> branch site that should have working code only. And your <code class=\"language-text\">staging</code> site that you can use to test your work in progress code.</p>\n<p>Now you need to migrate and seed your production database.</p>\n<p>Using the Heroku CLI, you can run commands inside of your production application just like in development using the <code class=\"language-text\">heroku run</code> command.</p>\n<p>For example to migrate the production database, run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">heroku run npm run sequelize db:migrate</code></pre></div>\n<p>To seed the production database, run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">heroku run npm run sequelize db:seed:all</code></pre></div>\n<p>Note: You can interact with your database this way as you'd like, but beware that <code class=\"language-text\">db:drop</code> cannot be run in the Heroku environment. If you want to drop and create the database, you need to remove and add back the \"Heroku Postgres\" add-on.</p>\n<p>Another way to interact with the production application is by opening a bash shell through your terminal by running:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">heroku bash</code></pre></div>\n<p>In the opened shell, you can run things like <code class=\"language-text\">npm run sequelize db:migrate</code>.</p>\n<p>Open your deployed site and check to see if you successfully deployed your Express + React application to Heroku!</p>\n<p>If you see an <code class=\"language-text\">Application Error</code> or are experiencing different behavior than what you see in your local environment, check the logs by running:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">heroku logs</code></pre></div>\n<p>If you want to open a connection to the logs to continuously output to your terminal, then run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">heroku logs --tail</code></pre></div>\n<p>The logs may clue you into why you are experiencing errors or different behavior.</p>\n<h4>If you found this guide helpful feel free to checkout my github/gists where I host</h4>"},{"url":"/blog/big-o-complexity/","relativePath":"blog/big-o-complexity.md","relativeDir":"blog","base":"big-o-complexity.md","name":"big-o-complexity","frontmatter":{"title":"Big O Computational Complexity","subtitle":"Explained using gif animations","date":"2021-09-11","thumb_image_alt":"neural network","excerpt":"Bubble sort, sorts an array of integers by bubbling the largest integer to the top.","seo":{"title":"Big O","description":"Big O Computational Complexity","robots":[],"extra":[]},"template":"post","thumb_image":"images/neural.png","image":"images/my-back-0b8b3eaf.png"},"html":"<h3>Sorting Algorithms</h3>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Ck9aeGY-d5tbz7dT\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*AByxtBjFrPVVYmyu\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*GeYNxlRcbt2cf0rY\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*gbNU6wrszGPrfAZG\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*GeU8YwwCoK8GiSTD\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*IxqGb72XDVDeeiMl\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*HMCR--9niDt5zY6M\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*WLl_HpdBGXYx284T\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*-LyHJXGPTYsWLDZf\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*-naVYGTXzE2Yoali\" alt=\"image\">\n\n</p>\n<h3>Bubble Sort</h3>\n<p>Time Complexity: Quadratic O(n^2)</p>\n<ul>\n<li>The inner for-loop contributes to O(n), however in a worst case scenario the while loop will need to run n times before bringing all n elements to their final resting spot.</li>\n</ul>\n<p>Space Complexity: O(1)</p>\n<ul>\n<li>Bubble Sort will always use the same amount of memory regardless of n.</li>\n</ul>\n<p><a href=\"https://gist.github.com/eengineergz/e67e56bed7c5a20a54851867ba5efef6\">https://gist.github.com/eengineergz/e67e56bed7c5a20a54851867ba5efef6</a></p>\n<ul>\n<li>The first major sorting algorithm one learns in introductory programming courses.</li>\n<li>-</li>\n<li>Gives an intro on how to convert unsorted data into sorted data.</li>\n</ul>\n<blockquote>\n<p>It's almost never used in production code because:</p>\n</blockquote>\n<ul>\n<li><em>It's not efficient</em></li>\n<li>-</li>\n<li><em>It's not commonly used</em></li>\n<li>-</li>\n<li><em>There is stigma attached to it</em></li>\n<li><em>Bubbling Up : Term that infers that an item is in motion, moving in some direction, and has some final resting destination.</em></li>\n<li><em>Bubble sort, sorts an array of integers by bubbling the largest integer to the top.</em></li>\n</ul>\n<p><a href=\"https://gist.github.com/eengineergz/fd4acc0c89033bd219ebf9d3ec40b053\">https://gist.github.com/eengineergz/fd4acc0c89033bd219ebf9d3ec40b053</a>\n<a href=\"https://gist.github.com/eengineergz/80934783c628c70ac2a5a48119a82d54\">https://gist.github.com/eengineergz/80934783c628c70ac2a5a48119a82d54</a></p>\n<ul>\n<li><em>Worst Case &#x26; Best Case are always the same because it makes nested loops.</em></li>\n<li>-</li>\n<li><em>Double for loops are polynomial time complexity or more specifically in this case Quadratic (Big O) of: O(n²)</em></li>\n</ul>\n<h3>Selection Sort</h3>\n<p>Time Complexity: Quadratic O(n^2)</p>\n<ul>\n<li>Our outer loop will contribute O(n) while the inner loop will contribute O(n / 2) on average. Because our loops are nested we will get O(n²);</li>\n</ul>\n<p>Space Complexity: O(1)</p>\n<ul>\n<li>Selection Sort will always use the same amount of memory regardless of n.</li>\n</ul>\n<p><a href=\"https://gist.github.com/eengineergz/4abc0fe0bf01599b0c4104b0ba633402\">https://gist.github.com/eengineergz/4abc0fe0bf01599b0c4104b0ba633402</a></p>\n<ul>\n<li>Selection sort organizes the smallest elements to the start of the array.</li>\n</ul>\n<blockquote>\n<p>Summary of how Selection Sort should work:</p>\n</blockquote>\n<ol>\n<li><em>Set MIN to location 0</em></li>\n<li><em>Search the minimum element in the list.</em></li>\n<li><em>Swap with value at location Min</em></li>\n<li><em>Increment Min to point to next element.</em></li>\n<li><em>Repeat until list is sorted.</em></li>\n</ol>\n<p><a href=\"https://gist.github.com/eengineergz/61f130c8e0097572ed908fe2629bdee0\">https://gist.github.com/eengineergz/61f130c8e0097572ed908fe2629bdee0</a></p>\n<h3>Insertion Sort</h3>\n<p>Time Complexity: Quadratic O(n^2)</p>\n<ul>\n<li>Our outer loop will contribute O(n) while the inner loop will contribute O(n / 2) on average. Because our loops are nested we will get O(n²);</li>\n</ul>\n<p>Space Complexity: O(n)</p>\n<ul>\n<li>Because we are creating a subArray for each element in the original input, our Space Comlexity becomes linear.</li>\n</ul>\n<p><a href=\"https://gist.github.com/eengineergz/a9f4b8596c7546ac92746db659186d8c\">https://gist.github.com/eengineergz/a9f4b8596c7546ac92746db659186d8c</a></p>\n<h3>Merge Sort</h3>\n<p>Time Complexity: Log Linear O(nlog(n))</p>\n<ul>\n<li>Since our array gets split in half every single time we contribute O(log(n)). The while loop contained in our helper merge function contributes O(n) therefore our time complexity is O(nlog(n)); Space Complexity: O(n)</li>\n<li>-</li>\n<li>We are linear O(n) time because we are creating subArrays.</li>\n</ul>\n<h3>Example of Merge Sort</h3>\n<p><a href=\"https://gist.github.com/eengineergz/18fbb7edc9f5c4820ccfcecacf3c5e48\">https://gist.github.com/eengineergz/18fbb7edc9f5c4820ccfcecacf3c5e48</a>\n<a href=\"https://gist.github.com/eengineergz/cbb533137a7f957d3bc4077395c1ff64\">https://gist.github.com/eengineergz/cbb533137a7f957d3bc4077395c1ff64</a></p>\n<ul>\n<li><strong>Merge sort is O(nlog(n)) time.</strong></li>\n<li>-</li>\n<li><em>We need a function for merging and a function for sorting.</em></li>\n</ul>\n<blockquote>\n<p>Steps:</p>\n</blockquote>\n<ol>\n<li><em>If there is only one element in the list, it is already sorted; return the array.</em></li>\n<li><em>Otherwise, divide the list recursively into two halves until it can no longer be divided.</em></li>\n<li><em>Merge the smallest lists into new list in a sorted order.</em></li>\n</ol>\n<h3>Quick Sort</h3>\n<p>Time Complexity: Quadratic O(n^2)</p>\n<ul>\n<li>Even though the average time complexity O(nLog(n)), the worst case scenario is always quadratic.</li>\n</ul>\n<p>Space Complexity: O(n)</p>\n<ul>\n<li>Our space complexity is linear O(n) because of the partition arrays we create.</li>\n<li>-</li>\n<li>QS is another Divide and Conquer</li>\n<li>-</li>\n<li>Some key ideas to keep in mind:</li>\n<li>It is easy to sort elements of an array relative to a particular target value.</li>\n<li>An array of 0 or 1 elements is already trivially sorted.</li>\n</ul>\n<p><a href=\"https://gist.github.com/eengineergz/24bcbc5248a8c4e1671945e9512da57e\">https://gist.github.com/eengineergz/24bcbc5248a8c4e1671945e9512da57e</a></p>\n<h3>Binary Search</h3>\n<p>Time Complexity: Log Time O(log(n))</p>\n<p>Space Complexity: O(1)</p>\n<blockquote>\n<p><em>Recursive Solution</em></p>\n</blockquote>\n<p><a href=\"https://gist.github.com/eengineergz/c82c00a4bcba4b69b7d326d6cad3ac8c\">https://gist.github.com/eengineergz/c82c00a4bcba4b69b7d326d6cad3ac8c</a></p>\n<blockquote>\n<p><em>Min Max Solution</em></p>\n</blockquote>\n<p><a href=\"https://gist.github.com/eengineergz/eb8d1e1684db15cc2c8af28e13f38751\">https://gist.github.com/eengineergz/eb8d1e1684db15cc2c8af28e13f38751</a>\n<a href=\"https://gist.github.com/eengineergz/bc3f576b9795ccef12a108e36f9f820a\">https://gist.github.com/eengineergz/bc3f576b9795ccef12a108e36f9f820a</a></p>\n<ul>\n<li><em>Must be conducted on a sorted array.</em></li>\n<li>-</li>\n<li><em>Binary search is logarithmic time, not exponential b/c n is cut down by two, not growing.</em></li>\n<li><em>Binary Search is part of Divide and Conquer.</em></li>\n</ul>\n<h3>Insertion Sort</h3>\n<ul>\n<li><strong>Works by building a larger and larger sorted region at the left-most end of the array.</strong></li>\n</ul>\n<blockquote>\n<p>Steps:</p>\n</blockquote>\n<ol>\n<li><em>If it is the first element, and it is already sorted; return 1.</em></li>\n<li><em>Pick next element.</em></li>\n<li><em>Compare with all elements in the sorted sub list</em></li>\n<li><em>Shift all the elements in the sorted sub list that is greater than the value to be sorted.</em></li>\n<li><em>Insert the value</em></li>\n<li><em>Repeat until list is sorted.</em></li>\n</ol>\n<p><a href=\"https://gist.github.com/eengineergz/ffead1de0836c4bcc6445780a604f617\">https://gist.github.com/eengineergz/ffead1de0836c4bcc6445780a604f617</a></p>"},{"url":"/blog/everything-you-need-to-get-started-with-vscode/","relativePath":"blog/everything-you-need-to-get-started-with-vscode.md","relativeDir":"blog","base":"everything-you-need-to-get-started-with-vscode.md","name":"everything-you-need-to-get-started-with-vscode","frontmatter":{"title":"Everything You Need to Get Started With VSCode","template":"post","subtitle":"Every extension or tool you could possibly need","excerpt":"Every extension or tool you could possibly need","date":"2022-06-07T01:21:42.750Z","image":"https://cdn-images-1.medium.com/max/1200/1*gcp0kkiWQY6qd1Y4qEcqxw.png","thumb_image":"https://cdn-images-1.medium.com/max/1200/1*gcp0kkiWQY6qd1Y4qEcqxw.png","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/awesome-lists.yaml","src/data/categories/google.yaml","src/data/categories/git.yaml"],"tags":["src/data/tags/psql.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/awesome-resources.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h1>Everything You Need to Get Started With VSCode + Extensions &#x26; Resources</h1>\n<p>Commands:</p>\n<hr>\n<h3>Everything You Need to Get Started With VSCode + Extensions &#x26; Resources</h3>\n<h4>Every extension or tool you could possibly need</h4>\n<p><img src=\"https://cdn-images-1.medium.com/max/1200/1*gcp0kkiWQY6qd1Y4qEcqxw.png\" alt=\"image\"></p>\n<h3>Here’s a rudimentary static site I made that goes into more detail on the extensions I use…</h3>\n<p><a href=\"https://5fff5b9a2430bb564bfd451d--stoic-mccarthy-2c335f.netlify.app/#h18\" title=\"https://5fff5b9a2430bb564bfd451d--stoic-mccarthy-2c335f.netlify.app/#h18\"><strong>VSCodeExtensions</strong><br>\n5fff5b9a2430bb564bfd451d–stoic-mccarthy-2c335f.netlify.app</a><a href=\"https://5fff5b9a2430bb564bfd451d--stoic-mccarthy-2c335f.netlify.app/#h18\"></a></p>\n<h3>Here’s the repo it was deployed from:</h3>\n<p><a href=\"https://github.com/bgoonz/vscode-Extension-readmes\">https://github.com/bgoonz/vscode-Extension-readmes</a></p>\n<hr>\n<h3>Commands:</h3>\n<blockquote>\n<p>Command Palette</p>\n<p>Access all available commands based on your current context.</p>\n<p>Keyboard Shortcut: <strong>Ctrl+Shift+P</strong></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*BByhnDoVQdRPdO4F.gif\" alt=\"image\"></p>\n<h3>Command palette</h3>\n<p><code class=\"language-text\">⇧⌘P</code> Show all commands <code class=\"language-text\">⌘P</code> Show files</p>\n<h3>Sidebars</h3>\n<p><code class=\"language-text\">⌘B</code> Toggle sidebar <code class=\"language-text\">⇧⌘E</code> Explorer <code class=\"language-text\">⇧⌘F</code> Search <code class=\"language-text\">⇧⌘D</code> Debug <code class=\"language-text\">⇧⌘X</code> Extensions <code class=\"language-text\">⇧^G</code> Git (SCM)</p>\n<h3>Search</h3>\n<p><code class=\"language-text\">⌘F</code> Find <code class=\"language-text\">⌥⌘F</code> Replace <code class=\"language-text\">⇧⌘F</code> Find in files <code class=\"language-text\">⇧⌘H</code> Replace in files</p>\n<h3>Panel</h3>\n<p><code class=\"language-text\">⌘J</code> Toggle panel <code class=\"language-text\">⇧⌘M</code> Problems <code class=\"language-text\">⇧⌘U</code> Output <code class=\"language-text\">⇧⌘Y</code> Debug console ^` ``Terminal</p>\n<h3>View</h3>\n<p><code class=\"language-text\">⌘k</code> <code class=\"language-text\">z</code> Zen mode <code class=\"language-text\">⌘k</code> <code class=\"language-text\">u</code> Close unmodified <code class=\"language-text\">⌘k</code> <code class=\"language-text\">w</code> Close all</p>\n<h3>Debug</h3>\n<p><code class=\"language-text\">F5</code> Start <code class=\"language-text\">⇧F5</code> Stop <code class=\"language-text\">⇧⌘F5</code> Restart <code class=\"language-text\">^F5</code> Start without debugging <code class=\"language-text\">F9</code> Toggle breakpoint <code class=\"language-text\">F10</code> Step over <code class=\"language-text\">F11</code> Step into <code class=\"language-text\">⇧F11</code> Step out <code class=\"language-text\">⇧⌘D</code> Debug sidebar <code class=\"language-text\">⇧⌘Y</code> Debug panel</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/1200/0*llpkl5jsIMhWMucR.png\" alt=\"image\"></p>\n<hr>\n<h3>Tips-N-Tricks:</h3>\n<p>Here is a selection of common features for editing code. If the keyboard shortcuts aren’t comfortable for you, consider installing a <a href=\"https://marketplace.visualstudio.com/search?target=VSCode&#x26;category=Keymaps&#x26;sortBy=Downloads\">keymap extension</a> for your old editor.</p>\n<p>Tip: You can see recommended keymap extensions in the Extensions view with Ctrl+K Ctrl+M which filters the search to <code class=\"language-text\">@recommended:keymaps</code> .</p>\n<h3>Multi cursor selection</h3>\n<p>To add cursors at arbitrary positions, select a position with your mouse and use Alt+Click (Option+click on macOS).</p>\n<p>To set cursors above or below the current position use:</p>\n<p>Keyboard Shortcut: Ctrl+Alt+Up or Ctrl+Alt+Down</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Le_oEOiYnEBmFfig.gif\" alt=\"image\"></p>\n<p>You can add additional cursors to all occurrences of the current selection with Ctrl+Shift+L.</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*WcrfwIln6NIG3zNW.gif\" alt=\"image\"></p>\n<p><em>Note: You can also change the modifier to Ctrl/Cmd for applying multiple cursors with the</em> <code class=\"language-text\">editor.multiCursorModifier</code> <em><a href=\"https://code.visualstudio.com/docs/getstarted/settings\">setting</a> . See</em> <em><a href=\"https://code.visualstudio.com/docs/editor/codebasics#_multicursor-modifier\">Multi-cursor Modifier</a></em> <em>for details.</em></p>\n<p>If you do not want to add all occurrences of the current selection, you can use Ctrl+D instead. This only selects the next occurrence after the one you selected so you can add selections one by one.</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*09EveaKtpZEKFEpO.gif\" alt=\"image\"></p>\n<h3>Column (box) selection</h3>\n<p>You can select blocks of text by holding Shift+Alt (Shift+Option on macOS) while you drag your mouse. A separate cursor will be added to the end of each selected line.</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*LrsOBXP4MVqr7aes.gif\" alt=\"image\"></p>\n<p>You can also use <a href=\"https://code.visualstudio.com/docs/editor/codebasics#_column-box-selection\">keyboard shortcuts</a> to trigger column selection.</p>\n<hr>\n<h3>Extensions:</h3>\n<h4><a href=\"https://marketplace.visualstudio.com/items?itemName=cweijan.vscode-autohotkey-plus\">AutoHotkey Plus</a></h4>\n<blockquote>\n<p><em>Syntax Highlighting, Snippets, Go to Definition, Signature helper and Code formatter</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=rogalmic.bash-debug\">Bash Debug</a></h3>\n<blockquote>\n<p><em>A debugger extension for Bash scripts based on</em> <code class=\"language-text\">bashdb</code></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*8j2gGGs0WHcuFIwY.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=Remisa.shellman\">Shellman</a></h3>\n<blockquote>\n<p><em>Bash script snippets extension</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*wyimtX27gWygAeOb.gif\" alt=\"image\"></p>\n<h3>C++</h3>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools\">C/C++</a> — Preview C/C++ extension by <a href=\"https://www.microsoft.com/\">Microsoft</a>, read <a href=\"https://blogs.msdn.microsoft.com/vcblog/2016/03/31/cc-extension-for-visual-studio-code/\">official blog post</a> for the details</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd\">Clangd</a> — Provides C/C++ language IDE features for VS Code using clangd: code completion, compile errors and warnings, go-to-definition and cross references, include management, code formatting, simple refactorings.</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=austin.code-gnu-global\">gnu-global-tags</a> — Provide Intellisense for C/C++ with the help of the GNU Global tool.</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=RichardHe.you-complete-me\">YouCompleteMe</a> — Provides semantic completions for C/C++ (and TypeScript, JavaScript, Objective-C, Golang, Rust) using <a href=\"https://ycm-core.github.io/YouCompleteMe/\">YouCompleteMe</a>.</p>\n<p><a href=\"https://github.com/mitaki28/vscode-clang\">C/C++ Clang Command Adapter</a> — Completion and Diagnostic for C/C++/Objective-C using Clang command.</p>\n<p><a href=\"https://github.com/cquery-project/vscode-cquery\">CQuery</a> — <a href=\"https://github.com/jacobdufault/cquery\">C/C++ language server</a> supporting multi-million line code base, powered by libclang. Cross references, completion, diagnostics, semantic highlighting and more.</p>\n</blockquote>\n<h4>More</h4>\n<ul>\n<li><a href=\"https://devblogs.microsoft.com/cppblog/vscode-cpp-may-2019-update/\">Microsoft’s tutorial on using VSCode for remote C/C++ development</a></li>\n</ul>\n<h3>C#, ASP . NET and . NET Core</h3>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp\">C#</a> — C# extension by <a href=\"https://www.microsoft.com/\">Microsoft</a>, read <a href=\"https://code.visualstudio.com/docs/languages/csharp\">official documentation</a> for the details</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=Leopotam.csharpfixformat\">C# FixFormat</a> — Fix format of usings / indents / braces / empty lines</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=jchannon.csharpextensions\">C# Extensions</a> — Provides extensions to the IDE that will speed up your development workflow.</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=tintoy.msbuild-project-tools\">MSBuild Project Tools</a></p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=fernandoescolar.vscode-solution-explorer\">VSCode Solution Explorer</a></p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.dotnet-test-explorer\">. NET Core Test Explorer</a></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*ZG5W4_VVBv89zO_g.gif\" alt=\"image\"></p>\n<hr>\n<h3>CSS</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=pranaygp.vscode-css-peek\">CSS Peek</a></h3>\n<blockquote>\n<p><em>Peek or Jump to a CSS definition directly from HTML, just like in Brackets!</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*MN4pNqxDw4FyRk8g.gif\" alt=\"image\"></p>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=stylelint.vscode-stylelint\">stylelint</a> — Lint CSS/SCSS.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=mrmlnc.vscode-autoprefixer\">Autoprefixer</a> Parse CSS, SCSS, LESS and add vendor prefixes automatically.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*edXaUlo7z9TRDQnC.gif\" alt=\"image\"></p>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=Zignd.html-css-class-completion\">Intellisense for CSS class names</a> — Provides CSS class name completion for the HTML class attribute based on the CSS files in your workspace. Also supports React’s className attribute.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*AHJJrCMfkLWLHLH4.gif\" alt=\"image\"></p>\n<h3>Groovy</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=NicolasVuillamy.vscode-groovy-lint\">VsCode Groovy Lint</a> — Groovy lint, format, prettify and auto-fix</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*jmi5_-erJj7WOMq7.gif\" alt=\"image\"></p>\n<h3>Haskell</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=hoovercj.haskell-linter\">haskell-linter</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=alanz.vscode-hie-server\">Haskell IDE engine</a> — provides <a href=\"https://github.com/haskell/haskell-ide-engine\">language server</a> for stack and cabal projects.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=truman.autocomplate-shell\">autocomplate-shell</a></li>\n</ul>\n<hr>\n<h3>Java</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=redhat.java\">Language Support for Java(TM) by Red Hat</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug\">Debugger for Java</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven\">Maven for Java</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=GabrielBB.vscode-lombok\">Lombok</a></li>\n</ul>\n<hr>\n<h3>JavaScript</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=mgmcdermott.vscode-language-babel\">Babel JavaScript</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode\">Visual Studio IntelliCode</a> — This extension provides AI-assisted development features including autocomplete and other insights based on understanding your code context.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*i7CZbSbHqsWqEM4w.gif\" alt=\"image\"></p>\n<p>See the difference between these two <a href=\"https://github.com/michaelgmcd/vscode-language-babel/issues/1\">here</a></p>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-tslint-plugin\">tslint</a> — TSLint for Visual Studio Code (with <code class=\"language-text\">\"tslint.jsEnable\": true</code> ).</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint\">eslint</a> — Linter for <a href=\"https://eslint.org/\">eslint</a>.</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=samverschueren.linter-xo\">XO</a> — Linter for <a href=\"https://github.com/xojs/xo\">XO</a>.</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=samverschueren.ava\">AVA</a> — Snippets for <a href=\"https://github.com/avajs/ava\">AVA</a>.</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode\">Prettier</a> — Linter, Formatter and Pretty printer for <a href=\"https://github.com/prettier/prettier-vscode\">Prettier</a>.</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=austinleegordon.vscode-schema-dot-org\">Schema.org Snippets</a> — Snippets for <a href=\"https://schema.org/\">Schema.org</a>.</p>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker\">Code Spell Checker</a> — Spelling Checker for Visual Studio Code.</p>\n</blockquote>\n<p>Framework-specific:</p>\n<h4><a href=\"https://marketplace.visualstudio.com/items?itemName=octref.vetur\">Vetur</a> — Toolkit for Vue.js</h4>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*F7J_vW0ISbVMTXIZ.png\" alt=\"image\"></p>\n<hr>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome\">Debugger for Chrome</a></h3>\n<blockquote>\n<p><em>A VS Code extension to debug your JavaScript code in the Chrome browser, or other targets that support the Chrome Debugging Protocol.</em></p>\n</blockquote>\n<h3>Facebook Flow</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=flowtype.flow-for-vscode\">Flow Language Support</a> — provides all the functionality you would expect — linting, intellisense, type tooltips and click-to-definition</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=gcazaciuc.vscode-flow-ide\">vscode-flow-ide</a> — an alternative Flowtype extension for Visual Studio Code</li>\n</ul>\n<h3>TypeScript</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=eg2.tslint\">tslint</a> — TSLint for Visual Studio Code</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero\">TypeScript Hero</a> — Code outline view of your open TS, sort and organize your imports.</li>\n</ul>\n<hr>\n<h3>Markdown</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint\">markdownlint</a></h3>\n<blockquote>\n<p><em>Linter for</em> <em><a href=\"https://github.com/DavidAnson/markdownlint\">markdownlint</a>.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one\">Markdown All in One</a></h3>\n<blockquote>\n<p><em>All-in-one markdown plugin (keyboard shortcuts, table of contents, auto preview, list editing and more)</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*8oVrYuZ9kLRNSuBs.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=bierner.markdown-emoji\">Markdown Emoji</a></h3>\n<blockquote>\n<p><em>Adds emoji syntax support to VS Code’s built-in Markdown preview</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*rckUMIIZ9Jh7UE5q.png\" alt=\"image\"></p>\n<hr>\n<h3>PHP</h3>\n<h3>IntelliSense</h3>\n<p>These extensions provide slightly different sets of features. While the first one offers better autocompletion support, the second one seems to have more features overall.</p>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client\">PHP Intelephense</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense\">PHP IntelliSense</a></li>\n</ul>\n<h3>Laravel</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel5-snippets\">Laravel 5 Snippets</a> — Laravel 5 snippets for Visual Studio Code</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade\">Laravel Blade Snippets</a> — Laravel blade snippets and syntax highlight support</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*f4hMFe1l7NpJTG8v.gif\" alt=\"image\"></p>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=ahinkle.laravel-model-snippets\">Laravel Model Snippets</a> — Quickly get models up and running with Laravel Model Snippets.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*1xydH2CgYGDSMZtB.gif\" alt=\"image\"></p>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=ryannaddy.laravel-artisan\">Laravel Artisan</a> — Laravel Artisan commands within Visual Studio Code</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*rzK952c4UgikNNPR.gif\" alt=\"image\"></p>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=mikestead.dotenv\">DotENV</a> — Support for dotenv file syntax</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*fSAaqpXfBx1Sgztf.png\" alt=\"image\"></p>\n<hr>\n<h3>Other extensions</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=rifi2k.format-html-in-php\">Format HTML in PHP</a> — Formatting for the HTML in PHP files. Runs before the save action so you can still have a PHP formatter.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*6gF0K20iKes7I9ZF.gif\" alt=\"image\"></p>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=ikappas.composer\">Composer</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug\">PHP Debug</a> — XDebug extension for Visual Studio Code</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=neilbrayfield.php-docblocker\">PHP DocBlocker</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer\">php cs fixer</a> — PHP CS Fixer extension for VS Code, php formatter, php code beautify tool</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs\">phpcs</a> — PHP CodeSniffer for Visual Studio Code</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt\">phpfmt</a> — phpfmt for Visual Studio Code</li>\n</ul>\n<hr>\n<h3>Python</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-python.python\">Python</a> — Linting, Debugging (multi threaded, web apps), Intellisense, auto-completion, code formatting, snippets, unit testing, and more.</li>\n</ul>\n<h3>TensorFlow</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=vahidk.tensorflow-snippets\">TensorFlow Snippets</a> — This extension includes a set of useful code snippets for developing TensorFlow models in Visual Studio Code.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*stmhgQ3sGvJBTvf2.gif\" alt=\"image\"></p>\n<hr>\n<h3>Rust</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=rust-lang.rust\">Rust</a> — Linting, auto-completion, code formatting, snippets and more</li>\n</ul>\n<hr>\n<h3>Productivity</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=bencoleman.armview\">ARM Template Viewer</a></h3>\n<blockquote>\n<p><em>Displays a graphical preview of Azure Resource Manager (ARM) templates. The view will show all resources with the official Azure icons and also linkage between the resources.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*p8bvCI9DXF44m4z3.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-cosmosdb\">Azure Cosmos DB</a></h3>\n<blockquote>\n<p><em>Browse your database inside the vs code editor</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*VWvSU6Hbf20Kfc_P.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-toolkit\">Azure IoT Toolkit</a></h3>\n<blockquote>\n<p><em>Everything you need for the Azure IoT development: Interact with Azure IoT Hub, manage devices connected to Azure IoT Hub, and develop with code snippets for Azure IoT Hub</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*AobtCd80fICrbQPI.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks\">Bookmarks</a></h3>\n<blockquote>\n<p><em>Mark lines and jump to them</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=orepor.color-tabs-vscode-ext\">Color Tabs</a></h3>\n<blockquote>\n<p><em>An extension for big projects or monorepos that colors your tab/titlebar based on the current package</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*SEp-hgfDLlubNRyc.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=hardikmodha.create-tests\">Create tests</a></h3>\n<blockquote>\n<p><em>An extension to quickly generate test files.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*DLZLYmrBiui0YOBt.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=mkloubert.vs-deploy\">Deploy</a></h3>\n<blockquote>\n<p><em>Commands for upload or copy files of a workspace to a destination.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*lLasjzlmWnBwdbAT.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=mrmlnc.vscode-duplicate\">Duplicate Action</a></h3>\n<blockquote>\n<p><em>Ability to duplicate files and directories.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens\">Error Lens</a></h3>\n<blockquote>\n<p><em>Show language diagnostics inline (errors/warnings/…).</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*1tJJkV0p2Ka_W06r.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets\">ES7 React/Redux/GraphQL/React-Native snippets</a></h3>\n<blockquote>\n<p><em>Provides Javascript and React/Redux snippets in ES7</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*W3N0kbgEumWYa-m4.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=rubbersheep.gi\">Gi</a></h3>\n<blockquote>\n<p><em>Generating .gitignore files made easy</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*sfddghz8B1D362UB.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=vsls-contrib.gistfs\">GistPad</a></h3>\n<blockquote>\n<p><em>Allows you to manage GitHub Gists entirely within the editor. You can open, create, delete, fork, star and clone gists, and then seamlessly begin editing files as if they were local. It’s like your very own developer library for building and referencing code snippets, commonly used config/scripts, programming-related notes/documentation, and interactive samples.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*1MiBQ0u4Z8TPNaG9.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory\">Git History</a></h3>\n<blockquote>\n<p><em>View git log, file or line History</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=felipecaputo.git-project-manager\">Git Project Manager</a></h3>\n<blockquote>\n<p><em>Automatically indexes your git projects and lets you easily toggle between them</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=qezhu.gitlink\">GitLink</a></h3>\n<blockquote>\n<p><em>GoTo current file’s online link in browser and Copy the link in clipboard.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Acgfn2rmhinuIPjk.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens\">GitLens</a></h3>\n<blockquote>\n<p><em>Provides Git CodeLens information (most recent commit, # of authors), on-demand inline blame annotations, status bar blame information, file and blame history explorers, and commands to compare changes with the working tree or previous versions.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*MZu4GV7SOCW88UQQ.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=lamartire.git-indicators\">Git Indicators</a></h3>\n<blockquote>\n<p><em>Atom-like git indicators on active panel</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*vitZrD9ZU0_eWckU.png\" alt=\"image\"></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*0BHxQOLMx09FFuWZ.png\" alt=\"image\"></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*x8F97F4AdSvvtehT.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=KnisterPeter.vscode-github\">GitHub</a></h3>\n<blockquote>\n<p><em>Provides GitHub workflow support. For example browse project, issues, file (the current line), create and manage pull request. Support for other providers (e.g. gitlab or bitbucket) is planned. Have a look at the</em> <em><a href=\"https://github.com/KnisterPeter/vscode-github/blob/master/README.md\">README.md</a></em> <em>on how to get started with the setup for this extension.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=erichbehrens.pull-request-monitor\">GitHub Pull Request Monitor</a></h3>\n<blockquote>\n<p><em>This extension uses the GitHub api to monitor the state of your pull requests and let you know when it’s time to merge or if someone requested changes.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*TOq5OERkgQNETGPK.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=gitlab.gitlab-workflow\">GitLab Workflow</a></h3>\n<blockquote>\n<p><em>Adds a GitLab sidebar icon to view issues, merge requests and other GitLab resources. You can also view the results of your GitLab CI/CD pipeline and check the syntax of your</em> <code class=\"language-text\">.gitlab-ci.yml</code><em>.</em></p>\n</blockquote>\n<h4><a href=\"https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-gradle\">Gradle Tasks</a></h4>\n<blockquote>\n<p><em>Run gradle tasks in VS Code.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Vx-3DIT22BJpEnJr.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=idleberg.icon-fonts\">Icon Fonts</a></h3>\n<blockquote>\n<p><em>Snippets for popular icon fonts such as Font Awesome, Ionicons, Glyphicons, Octicons, Material Design Icons and many more!</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost\">Import Cost</a></h3>\n<blockquote>\n<p><em>This extension will display inline in the editor the size of the imported package. The extension utilizes webpack with babili-webpack-plugin in order to detect the imported size.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=Atlassian.atlascode\">Jira and Bitbucket</a></h3>\n<blockquote>\n<p><em>Bringing the power of Jira and Bitbucket to VS Code — With Atlassian for VS Code you can create and view issues, start work on issues, create pull requests, do code reviews, start builds, get build statuses and more!</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*T6iuH2VnPYj93YqW.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=lannonbr.vscode-js-annotations\">JS Parameter Annotations</a></h3>\n<blockquote>\n<p><em>Provides annotations on function calls in JS/TS files to provide parameter names to arguments.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*zHffPsYWln4dxhus.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=wmaurer.vscode-jumpy\">Jumpy</a></h3>\n<blockquote>\n<p><em>Provides fast cursor movement, inspired by Atom’s package of the same name.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*uPOceUJ4eMjCP_Qt.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=mkloubert.vscode-kanban\">Kanban</a></h3>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*SzUG3UU1fl5ub7bA.gif\" alt=\"image\"></p>\n<p><em>Simple Kanban board for use in Visual Studio Code, with time tracking and Markdown support.</em></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer\">Live Server</a></h3>\n<blockquote>\n<p><em>Launch a development local Server with live reload feature for static &#x26; dynamic pages.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Oj5zPrWwMbCBViBi.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=slevesque.vscode-multiclip\">Multiple clipboards</a></h3>\n<blockquote>\n<p><em>Override the regular Copy and Cut commands to keep selections in a clipboard ring</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=philnash.ngrok-for-vscode\">ngrok for VSCode</a></h3>\n<blockquote>\n<p><em>ngrok allows you to expose a web server running on your local machine to the internet. Just tell ngrok what port your web server is listening on. This extension allows you to control</em> <em><a href=\"https://ngrok.com/\">ngrok</a></em> <em>from the VSCode command palette</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*IX15MuJrEVBcTd0F.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=dbankier.vscode-instant-markdown\">Instant Markdown</a></h3>\n<blockquote>\n<p><em>Simply, edit markdown documents in vscode and instantly preview it in your browser as you type.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*jBw9vP9cAtvv2IcV.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=christian-kohler.npm-intellisense\">npm Intellisense</a></h3>\n<blockquote>\n<p><em>Visual Studio Code plugin that autocompletes npm modules in import statements.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*iVJamJugt_b7-VsV.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=DominicVonk.parameter-hints\">Parameter Hints</a></h3>\n<blockquote>\n<p><em>Provides parameter hints on function calls in JS/TS/PHP files.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*BSj8-Qt7xtVTsl1Z.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ryu1kn.partial-diff\">Partial Diff</a></h3>\n<blockquote>\n<p><em>Compare (diff) text selections within a file, across different files, or to the clipboard</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*KHki85jdv1hZeY3V.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=quicktype.quicktype\">Paste JSON as Code</a></h3>\n<blockquote>\n<p><em>Infer the structure of JSON and paste is as types in many programming languages</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*K2GCRMGsYjpsK8OX.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=christian-kohler.path-intellisense\">Path IntelliSense</a></h3>\n<blockquote>\n<p><em>Visual Studio Code plugin that autocompletes filenames</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*xwxU_1ffZvZ6DeoO.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ego-digital.vscode-powertools\">Power Tools</a></h3>\n<blockquote>\n<p><em>Extends Visual Studio Code via things like Node.js based scripts or shell commands, without writing separate extensions</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Cb7J6-PYsXsnjqSN.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=nobuhito.printcode\">PrintCode</a></h3>\n<blockquote>\n<p><em>PrintCode converts the code being edited into an HTML file, displays it by browser and prints it.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*2spvNSEEHM-ETd_F.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager\">Project Manager</a></h3>\n<blockquote>\n<p><em>Easily switch between projects.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=kruemelkatze.vscode-dashboard\">Project Dashboard</a></h3>\n<blockquote>\n<p><em>VSCode Project Dashboard is a Visual Studio Code extension that lets you organize your projects in a speed-dial like manner. Pin your frequently visited folders, files, and SSH remotes onto a dashboard to access them quickly.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*PxOoARROhi1rf63R.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv\">Rainbow CSV</a></h3>\n<blockquote>\n<p><em>Highlight columns in comma, tab, semicolon and pipe separated files, consistency check and linting with CSVLint, multi-cursor column editing, column trimming and realignment, and SQL-style querying with RBQL.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*XAb9jlOfGWlEaCEM.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack\">Remote Development</a></h3>\n<blockquote>\n<p><em>Allows users to open any folder in a container, on a remote machine, container or in Windows Subsystem for Linux(WSL) and take advantage of VS Code’s full feature set.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*b6XEPh9PJzeWDB_z.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=rafaelmaiolla.remote-vscode\">Remote VSCode</a></h3>\n<blockquote>\n<p><em>Allow user to edit files from Remote server in Visual Studio Code directly.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=humao.rest-client\">REST Client</a></h3>\n<blockquote>\n<p><em>Allows you to send HTTP request and view the response in Visual Studio Code directly.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*zGne78bniDbTXzyf.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync\">Settings Sync</a></h3>\n<blockquote>\n<p><em>Synchronize settings, snippets, themes, file icons, launch, key bindings, workspaces and extensions across multiple machines using GitHub Gist</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*ilH91MRgGnMF6C8c.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=qcz.text-power-tools\">Text Power Tools</a></h3>\n<blockquote>\n<p><em>All-in-one extension for text manipulation: filtering (grep), remove lines, insert number sequences and GUIDs, format content as table, change case, converting numbers and more. Great for finding information in logs and manipulating text.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Pfp4noD5OeQRbmsZ.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree\">Todo Tree</a></h3>\n<blockquote>\n<p><em>Custom keywords, highlighting, and colors for TODO comments. As well as a sidebar to view all your current tags.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*6utz502-rPCa0Xcg.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=BriteSnow.vscode-toggle-quotes\">Toggle Quotes</a></h3>\n<blockquote>\n<p><em>Cycle between single, double and backtick quotes</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*7kZFpggvGAVkvoYa\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=tusaeff.vscode-typescript-destructure-plugin\">Typescript Destructure</a></h3>\n<blockquote>\n<p><em>TypeScript Language Service Plugin providing a set of source actions for easy objects destructuring</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*sEi0imXK2Yx69m7H.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=WakaTime.vscode-wakatime\">WakaTime</a></h3>\n<blockquote>\n<p><em>Automatic time tracker and productivity dashboard showing how long you coded in each project, file, branch, and language.</em></p>\n</blockquote>\n<hr>\n<h3>Formatting &#x26; Beautification</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=wwm.better-align\">Better Align</a></h3>\n<blockquote>\n<p><em>Align your code by colon(:), assignment(=, +=, -=, *=, /=) and arrow(=> ). It has additional support for comma-first coding style and trailing comment.</em></p>\n<p><em>And it doesn’t require you to select what to be aligned, the extension will figure it out by itself.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*5maDjvvH57MAks1l.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag\">Auto Close Tag</a></h3>\n<blockquote>\n<p><em>Automatically add HTML/XML close tag, same as Visual Studio IDE or Sublime Text</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*h6Q6HLQ8jfHLnPlJ.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag\">Auto Rename Tag</a></h3>\n<blockquote>\n<p><em>Auto rename paired HTML/XML tags</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*uRKX2-umhSQzlESv.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify\">beautify</a></h3>\n<blockquote>\n<p><em>Beautify code in place for VS Code</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=dbalas.vscode-html2pug\">html2pug</a></h3>\n<blockquote>\n<p><em>Transform html to pug inside your Visual Studio Code, forget about using an external page anymore.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=vilicvane.es-quotes\">ECMAScript Quotes Transformer</a></h3>\n<blockquote>\n<p><em>Transform quotes of ECMAScript string literals</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*W1Z1fIvOGgPclFMJ.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=Rubymaniac.vscode-paste-and-indent\">Paste and Indent</a></h3>\n<blockquote>\n<p><em>Paste code with “correct” indentation</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=Tyriar.sort-lines\">Sort Lines</a></h3>\n<blockquote>\n<p><em>Sorts lines of text in specific order</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*a4wPhA7VjJqkp3lu.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=yatki.vscode-surround\">Surround</a></h3>\n<blockquote>\n<p><em>A simple yet powerful extension to add wrapper templates around your code blocks.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*lyjRgfSrvdmhGFXd.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=konstantin.wrapSelection\">Wrap Selection</a></h3>\n<blockquote>\n<p><em>Wraps selection or multiple selections with symbol or multiple symbols</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=tombonnike.vscode-status-bar-format-toggle\">Formatting Toggle</a></h3>\n<blockquote>\n<p><em>Allows you to toggle your formatter on and off with a simple click</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer\">Bracket Pair Colorizer</a></h3>\n<blockquote>\n<p><em>This extension allows matching brackets to be identified with colours. The user can define which characters to match, and which colours to use.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*m3nU-5UxgUxX4-eJ.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=steoates.autoimport\">Auto Import</a></h3>\n<blockquote>\n<p><em>Automatically finds, parses and provides code actions and code completion for all available imports. Works with Typescript and TSX.</em></p>\n</blockquote>\n<h3><a href=\"https://github.com/foxundermoon/vs-shell-format\">shell-format</a></h3>\n<blockquote>\n<p><em>shell script &#x26; Dockerfile &#x26; dotenv format</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*TThlkfK1KgQm5AKU.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=funkyremi.vscode-google-translate\">Vscode Google Translate</a></h3>\n<blockquote>\n<p><em>Quickly translate selected text right in your code</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*JF8NuxAFDxXiTn_u.gif\" alt=\"image\"></p>\n<h3>Explorer Icons</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme\">Material Icon Theme</a></h3>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*67ZZ9mhoISPk_lM4.png\" alt=\"image\"></p>\n<h3>Uncategorized</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=auchenberg.vscode-browser-preview\">Browser Preview</a></h3>\n<blockquote>\n<p><em>Browser Preview for VS Code enables you to open a real browser preview inside your editor that you can debug. Browser Preview is powered by Chrome Headless, and works by starting a headless Chrome instance in a new process. This enables a secure way to render web content inside VS Code, and enables interesting features such as in-editor debugging and more!</em></p>\n<p><strong><em>FYI:… I HAVE TRIED ENDLESSLEY TO GET THE DEBUGGER TO WORK IN VSCODE BUT IT DOES NOT… I SUSPECT THAT’S WHY IT HAS A 3 STAR RATING FOR AN OTHERWISE PHENOMINAL EXTENSION.</em></strong></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Oilwsi7EKGpCZb46.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=CodeRoad.coderoad\">CodeRoad</a></h3>\n<blockquote>\n<p><em>Play interactive tutorials in your favorite editor.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*iV8P93QMmWdYfnrQ.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner\">Code Runner</a></h3>\n<blockquote>\n<p><em>Run code snippet or code file for multiple languages: C, C++, Java, JavaScript, PHP, Python, Perl, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, C# Script, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*hMsM_IEyBklQXchd.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=softwaredotcom.swdc-vscode\">Code Time</a></h3>\n<blockquote>\n<p><em>Automatic time reports by project and other programming metrics right in VS Code.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Uo1BYexJenprpgLa\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight\">Color Highlight</a></h3>\n<blockquote>\n<p><em>Highlight web colors in your editor</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/1*ZwE7OHKR5opvDCJJOw9KeQ.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=IBM.output-colorizer\">Output Colorizer</a></h3>\n<blockquote>\n<p><em>Syntax highlighting for the VS Code Output Panel and log files</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*9DpzVZ9cUNp2TMyD.jpg\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=deerawan.vscode-dash\">Dash</a></h3>\n<blockquote>\n<p><em>Dash integration in Visual Studio Code</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/1*sqGllC-pgXNaEBfB-cxG9Q.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ryu1kn.edit-with-shell\">Edit with Shell Command</a></h3>\n<blockquote>\n<p><em>Leverage your favourite shell commands to edit text</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*2wW31HJ1nUCjORZe.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig\">Editor Config for VS Code</a></h3>\n<blockquote>\n<p><em>Editor Config for VS Code</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=lukasz-wronski.ftp-sync\">ftp-sync</a></h3>\n<blockquote>\n<p><em>Auto-sync your work to remote FTP server</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*-viKhwxpeYQdWHRE.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=vincaslt.highlight-matching-tag\">Highlight JSX/HTML tags</a></h3>\n<blockquote>\n<p><em>Highlights matching tags in the file.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow\">Indent Rainbow</a></h3>\n<blockquote>\n<p><em>A simple extension to make indentation more readable.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*GK_yEd-50SU3yc_y.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ftonato.password-generator\">Password Generator</a></h3>\n<blockquote>\n<p><em>Create a secure password using our generator tool. Help prevent a security threat by getting a strong password today.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*qPJAZk9-NcYgsx7H.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.platformio\">PlatformIO</a></h3>\n<blockquote>\n<p><em>An open source ecosystem for IoT development: supports 350+ embedded boards, 20+ development platforms, 10+ frameworks. Arduino and ARM mbed compatible.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*RywVt_vikqB-5urO.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=pnp.polacode\">Polacode</a></h3>\n<blockquote>\n<p><em>Polaroid for your code 📸.</em></p>\n<p><strong><em>Note: Polacode no longer works as of the most recent update… go for Polacode2020 or CodeSnap…</em></strong></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Io4fPojDRrDf5CmW.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=WallabyJs.quokka-vscode\">Quokka</a></h3>\n<h4>This one is super cool!</h4>\n<blockquote>\n<p><em>Rapid prototyping playground for JavaScript and TypeScript in VS Code, with access to your project’s files, inline reporting, code coverage and rich output formatting.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Q9kp8EWZHTD0Hfru.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=sozercan.slack\">Slack</a></h3>\n<blockquote>\n<p><em>Send messages and code snippets, upload files to Slack</em></p>\n</blockquote>\n<p>Personally I found this extension to slow down my editor in addition to confliction with other extensions: (I have over 200 as of this writing)….. <strong>yes I have been made fully aware that I have a problem and need to get help</strong></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*9-xxjXzdPCh_46kZ.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=shyykoserhiy.vscode-spotify\">Spotify</a></h3>\n<p><em>No real advantage over just using Spotify normally… it’s problematic enough in implementation that you won’t save any time using it. Further, it’s a bit tricky to configure … or at least it was the last time I tried syncing it with my spotify account.</em></p>\n<blockquote>\n<p><em>Provides integration with Spotify Desktop client. Shows the currently playing song in status bar, search lyrics and provides commands for controlling Spotify with buttons and hotkeys.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*IqsxXiGpZQWbQbfD.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=jock.svg\">SVG</a></h3>\n<blockquote>\n<p><em>A Powerful SVG Language Support Extension(beta). Almost all the features you need to handle SVG.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*SC6zCXGaBnM_LkgC.png\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=cssho.vscode-svgviewer\">SVG Viewer</a></h3>\n<blockquote>\n<p><em>View an SVG in the editor and export it as data URI scheme or PNG.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ryu1kn.text-marker\">Text Marker (Highlighter)</a></h3>\n<blockquote>\n<p><em>Highlight multiple text patterns with different colors at the same time. Highlighting a single text pattern can be done with the editor’s search functionality, but it cannot highlight multiple patterns at the same time, and this is where this extension comes handy.</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*YDreVyGNjZmqj_KC.gif\" alt=\"image\"></p>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=samundrak.esdoc-mdn\">ESDOC MDN</a></h3>\n<h3>THIS IS A MUST HAVE</h3>\n<blockquote>\n<p><em>Quickly bring up helpful MDN documentation in the editor</em></p>\n</blockquote>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*xiUfWBsz8x8beY70.gif\" alt=\"image\"></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*mMBU6d1iCkt5VHq2.gif\" alt=\"image\"></p>\n<h3>Themes:</h3>\n<p>In the interest of not making the reader scroll endlessly as I often do… I’ve made a separate post for that here. If you’ve made it this far, I thank you!</p>\n<!--EndFragment-->"},{"url":"/blog/file-system-route-api/","relativePath":"blog/file-system-route-api.md","relativeDir":"blog","base":"file-system-route-api.md","name":"file-system-route-api","frontmatter":{"title":"File System Route API","template":"post","subtitle":"GatsbyJS File System Route API","excerpt":"Use the File System Route API when you want to create dynamic pages","date":"2022-05-16T00:22:26.250Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/file-system.jpg?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/file-system.jpg?raw=true","image_position":"right","author":"src/data/authors/backup.yaml","categories":["src/data/categories/gatsbyjs.yaml"],"tags":["src/data/tags/javascript.yaml","src/data/tags/react.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/gatsby-cli.md"],"cmseditable":true},"html":"<p>Use the File System Route API when you want to create dynamic pages e.g. to create individual blog post pages for your blog.</p>\n<p>You should be able to accomplish most common tasks with this file-based API. If you want more control over the page creation you should use the <a href=\"/docs/reference/config-files/gatsby-node#createPages\"><code class=\"language-text\">createPages</code></a> API.</p>\n<p>Dynamic pages can be created from collections in Gatsby's <a href=\"/docs/conceptual/graphql-concepts/\">GraphQL data layer</a> and to create <a href=\"/docs/how-to/routing/client-only-routes-and-user-authentication\">client-only routes</a>.</p>\n<p>A complete example showcasing all options can be found in <a href=\"https://github.com/gatsbyjs/gatsby/tree/master/examples/route-api\">Gatsby's examples folder</a>.</p>\n<h2>Collection routes</h2>\n<p>Imagine a Gatsby project that sources a <code class=\"language-text\">product.yaml</code> file and multiple Markdown blog posts. At build time, Gatsby will automatically <a href=\"/docs/glossary/#inference\">infer</a> the fields and create multiple <a href=\"/docs/glossary#node\">nodes</a> for both types (<code class=\"language-text\">Product</code> and <code class=\"language-text\">MarkdownRemark</code>).</p>\n<p>To create collection routes, use curly braces (<code class=\"language-text\">{ }</code>) in your filenames to signify dynamic URL segments that relate to a field within the node. Here are a few examples:</p>\n<ul>\n<li><code class=\"language-text\">src/pages/products/{Product.name}.js</code> will generate a route like <code class=\"language-text\">/products/burger</code></li>\n<li><code class=\"language-text\">src/pages/products/{Product.fields__sku}.js</code> will generate a route like <code class=\"language-text\">/products/001923</code></li>\n<li><code class=\"language-text\">src/pages/blog/{MarkdownRemark.parent__(File)__name}.js</code> will generate a route like <code class=\"language-text\">/blog/learning-gatsby</code></li>\n</ul>\n<p>Gatsby creates a page for each node in a collection route. So if you have three markdown files that are blog posts, Gatsby will create the three pages from a collection route. As you add and remove markdown files, Gatsby will add and remove pages.</p>\n<p>Collection routes can be created for any GraphQL data type. Creating new collection routes in Gatsby is a process\nof adding a source plugin, use GraphiQL to identify the type and field to construct the route file name, and then code the route component.</p>\n<h3>Syntax (collection routes)</h3>\n<p>There are some general syntax requirements when using collection routes:</p>\n<ul>\n<li>Dynamic segments of file paths must start and end with curly braces (<code class=\"language-text\">{ }</code>).</li>\n<li>Types are case-sensitive (e.g. <code class=\"language-text\">MarkdownRemark</code> or <code class=\"language-text\">contentfulMyContentType</code>). Check GraphiQL for the correct names.</li>\n<li>Dynamic segments must include both a type and a field e.g. <code class=\"language-text\">{Type.field}</code> or <code class=\"language-text\">{BlogPost.slug}</code>.</li>\n</ul>\n<h3>Nested routes</h3>\n<p>You can use dynamic segments multiple times in a path. For example, you might want to nest product names within its product category. For example:</p>\n<ul>\n<li><code class=\"language-text\">src/pages/products/{Product.category}/{Product.name}.js</code> will generate a route like <code class=\"language-text\">/products/toys/fidget-spinner</code></li>\n<li><code class=\"language-text\">src/pages/products/{Product.category}/{Product.name}/{Product.color}.js</code> will generate a route like <code class=\"language-text\">/products/toys/fidget-spinner/red</code></li>\n</ul>\n<h3>Field syntax</h3>\n<h4>Dot notation</h4>\n<p>Using <code class=\"language-text\">.</code> you signify that you want to access a field on a node of a type.</p>\n<p><code class=\"language-text\">src/pages/products/{Product.name}.js</code> generates the following query:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">allProduct <span class=\"token punctuation\">{</span>\n  nodes <span class=\"token punctuation\">{</span>\n    id # Gatsby always queries <span class=\"token keyword\">for</span> id\n    name\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h4>Underscore notation</h4>\n<p>Using <code class=\"language-text\">__</code> (double underscore) you signify that you want to access a nested field on a node.</p>\n<p><code class=\"language-text\">src/pages/products/{Product.fields__sku}.js</code> generates the following query:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">allProduct <span class=\"token punctuation\">{</span>\n  nodes <span class=\"token punctuation\">{</span>\n    id # Gatsby always queries <span class=\"token keyword\">for</span> id\n    fields <span class=\"token punctuation\">{</span>\n      sku\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>You can nest as deep as necessary, e.g. <code class=\"language-text\">src/pages/products/{Product.fields__date__createdAt}.js</code> generates the following query:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">allProduct <span class=\"token punctuation\">{</span>\n  nodes <span class=\"token punctuation\">{</span>\n    id # Gatsby always queries <span class=\"token keyword\">for</span> id\n    fields <span class=\"token punctuation\">{</span>\n      date <span class=\"token punctuation\">{</span>\n        createdAt\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h4>Parentheses notation</h4>\n<p>Using <code class=\"language-text\">( )</code> you signify that you want to access a <a href=\"https://graphql.org/learn/schema/#union-types\">GraphQL union type</a>. This is often possible with types that Gatsby creates for you. For example, <code class=\"language-text\">MarkdownRemark</code> always has <code class=\"language-text\">File</code> as a parent type, and thus you can also access fields from the <code class=\"language-text\">File</code> node. You can use this multiple levels deep, too, e.g. <code class=\"language-text\">src/pages/blog/{Post.parent__(MarkdownRemark)__parent__(File)__name}.js</code>.</p>\n<p><code class=\"language-text\">src/pages/blog/{MarkdownRemark.parent__(File)__name}.js</code> generates the following query:</p>\n<div class=\"gatsby-highlight\" data-language=\"graphql\"><pre class=\"language-graphql\"><code class=\"language-graphql\"><span class=\"token object\">allMarkdownRemark</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token object\">nodes</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">id</span> <span class=\"token comment\"># Gatsby always queries for id</span>\n    <span class=\"token object\">parent</span> <span class=\"token punctuation\">{</span>\n      … <span class=\"token keyword\">on</span> <span class=\"token class-name\">File</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token property\">name</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Collection Route Components</h3>\n<p>Collection route components are passed two dynamic variables. The <code class=\"language-text\">id</code> of each page's node and the\nURL path as <code class=\"language-text\">params</code>. The params is passed to the component as <code class=\"language-text\">props.params</code> and the id as <code class=\"language-text\">props.pageContext.id</code>.</p>\n<p>Both are also passed as variables to the component's GraphQL query so you can query fields from the node. Page querying, including the use of variables, is explained in more depth in <a href=\"/docs/how-to/querying-data/page-query/\">querying data in pages with GraphQL</a>.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> graphql <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'gatsby'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Component</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"gatsby-highlight-code-line\">    <span class=\"token keyword\">return</span> props<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">.</span>fields<span class=\"token punctuation\">.</span>sku <span class=\"token operator\">+</span> props<span class=\"token punctuation\">.</span>params<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span></span><span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// This is the page query that connects the data to the actual component. Here you can query for any and all fields</span>\n<span class=\"token comment\">// you need access to within your code. Again, since Gatsby always queries for `id` in the collection, you can use that</span>\n<span class=\"token comment\">// to connect to this GraphQL query.</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> query <span class=\"token operator\">=</span> graphql<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"></span>\n<span class=\"token string\">    query ($id: String) {</span>\n<span class=\"token string\">        product(id: { eq: $id }) {</span>\n<span class=\"token string\">            fields {</span>\n<span class=\"token string\">                sku</span>\n<span class=\"token string\">            }</span>\n<span class=\"token string\">        }</span>\n<span class=\"token string\">    }</span>\n<span class=\"token string\"></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>For the page <code class=\"language-text\">src/pages/{Product.name}/{Product.coupon}.js</code> you'd have <code class=\"language-text\">props.params.name</code> and <code class=\"language-text\">props.params.coupon</code> available inside <code class=\"language-text\">{Product.coupon}.js</code>.</p>\n<p>If you need to want to create pages for only some nodes in a collection (e.g. filtering out any product of type <code class=\"language-text\">\"Food\"</code>) or customize the variables passed to the query, you should use the <a href=\"/docs/reference/config-files/gatsby-node#createPages\"><code class=\"language-text\">createPages</code></a> API instead as File System Route API doesn't support this at the moment.</p>\n<h3>Routing and linking</h3>\n<p>Gatsby \"slugifies\" every route that gets created from collection pages (by using <a href=\"https://github.com/sindresorhus/slugify\"><code class=\"language-text\">sindresorhus/slugify</code></a>). Or in other words: If you have a route called <code class=\"language-text\">src/pages/wholesome/{Animal.slogan}.js</code> where <code class=\"language-text\">slogan</code> is <code class=\"language-text\">I ♥ Dogs</code> the final URL will be <code class=\"language-text\">/wholesome/i-love-dogs</code>. Gatsby will convert the field into a human-readable URL format while stripping it of invalid characters.</p>\n<p>When you want to link to a collection route page, it may not always be clear how to construct the URL from scratch.</p>\n<p>To address this issue, Gatsby automatically includes a <code class=\"language-text\">gatsbyPath</code> field on every type used by collection pages. The <code class=\"language-text\">gatsbyPath</code> field must take an argument of the <code class=\"language-text\">filePath</code> it is trying to resolve. This is necessary because it’s possible that one type is used in multiple collection pages.</p>\n<p>There are some general syntax requirements when using the <code class=\"language-text\">filePath</code> argument:</p>\n<ul>\n<li>The path must be an absolute path (starting with a <code class=\"language-text\">/</code>).</li>\n<li>You must omit the file extension.</li>\n<li>You must omit the <code class=\"language-text\">src/pages</code> prefix.</li>\n<li>Your path must not include <code class=\"language-text\">index</code>.</li>\n</ul>\n<h4><code class=\"language-text\">gatsbyPath</code> example</h4>\n<p>Assume that a <code class=\"language-text\">Product</code> type is used in two pages:</p>\n<ul>\n<li><code class=\"language-text\">src/pages/products/{Product.name}.js</code></li>\n<li><code class=\"language-text\">src/pages/discounts/{Product.name}.js</code></li>\n</ul>\n<p>If you wanted to link to the <code class=\"language-text\">products/{Product.name}</code> and <code class=\"language-text\">discounts/{Product.name}</code> routes from your home page, you would have a component like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> Link<span class=\"token punctuation\">,</span> graphql <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'gatsby'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">HomePage</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">.</span>allProduct<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">product</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>product<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n<span class=\"gatsby-highlight-code-line\">                    <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>product<span class=\"token punctuation\">.</span>productPath<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>product<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>product<span class=\"token punctuation\">.</span>discountPath<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Discount<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span><span class=\"token punctuation\">)</span></span>                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> query <span class=\"token operator\">=</span> graphql<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"></span>\n<span class=\"token string\">  query {</span>\n<span class=\"token string\">    allProduct {</span>\n<span class=\"token string\">      name</span>\n<span class=\"gatsby-highlight-code-line\"><span class=\"token string\">      productPath: gatsbyPath(filePath: \"/products/{Product.name}\")</span><span class=\"gatsby-highlight-code-line\"><span class=\"token string\">      discountPath: gatsbyPath(filePath: \"/discounts/{Product.name}\")</span><span class=\"token string\">    }</span>\n<span class=\"token string\">  }</span>\n<span class=\"token string\"></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>By using <a href=\"/docs/graphql-reference/#aliasing\">aliasing</a> you can use <code class=\"language-text\">gatsbyPath</code> multiple times.</p>\n<h2>Creating client-only routes</h2>\n<p>Use <a href=\"/docs/how-to/routing/client-only-routes-and-user-authentication\">client-only routes</a> if you have dynamic data that does not live in Gatsby. This might be something like a user settings page, or some other dynamic content that isn't known to Gatsby at build time. In these situations, you will usually create a route with one or more dynamic segments to query data from a server in order to render your page.</p>\n<h3>Syntax (client-only routes)</h3>\n<p>You can use square brackets (<code class=\"language-text\">[ ]</code>) in the file path to mark any dynamic segments of the URL. For example, in order to edit a user, you might want a route like <code class=\"language-text\">/user/:id</code> to fetch the data for whatever <code class=\"language-text\">id</code> is passed into the URL.</p>\n<ul>\n<li><code class=\"language-text\">src/pages/users/[id].js</code> will generate a route like <code class=\"language-text\">/users/:id</code></li>\n<li><code class=\"language-text\">src/pages/users/[id]/group/[groupId].js</code> will generate a route like <code class=\"language-text\">/users/:id/group/:groupId</code></li>\n</ul>\n<h4>Splat routes</h4>\n<p>Gatsby also supports <em>splat</em> (or wildcard) routes, which are routes that will match <em>anything</em> after the splat. These are less common, but still have use cases. Use three periods in square brackets (<code class=\"language-text\">[...]</code>) in a file path to mark a page as a splat route. You can also name the parameter your page receives by adding a name after the three periods (<code class=\"language-text\">[...myNameKey]</code>).</p>\n<p>As an example, suppose that you are rendering images from <a href=\"/docs/how-to/previews-deploys-hosting/deploying-to-s3-cloudfront/\">S3</a> and the URL is actually the key to the asset in AWS. Here is how you might create your file:</p>\n<ul>\n<li><code class=\"language-text\">src/pages/image/[...].js</code> will generate a route like <code class=\"language-text\">/image/*</code>. <code class=\"language-text\">*</code> is accessible in your page's received properties with the key name <code class=\"language-text\">*</code>.</li>\n<li><code class=\"language-text\">src/pages/image/[...awsKey].js</code> will generate a route like <code class=\"language-text\">/image/*awsKey</code>. <code class=\"language-text\">*awsKey</code> is accessible in your page's received properties with the key name <code class=\"language-text\">awsKey</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">ImagePage</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> params <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> param <span class=\"token operator\">=</span> params<span class=\"token punctuation\">[</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">*</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// When visiting a route like `image/hello/world`,</span>\n    <span class=\"token comment\">// the value of `param` is `hello/world`.</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">ImagePage</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> params <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> param <span class=\"token operator\">=</span> params<span class=\"token punctuation\">[</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">awsKey</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// When visiting a route like `image/hello/world`,</span>\n    <span class=\"token comment\">// the value of `param` is `hello/world`.</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Splat routes may not live in the same directory as regular client only routes.</p>\n<h3>Examples</h3>\n<p>The dynamic segment of the file name (the part between the square brackets) will be filled in and provided to your components on a <code class=\"language-text\">props.params</code> object. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">//title=src/pages/users/[name].js</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">UserPage</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> name <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>params<span class=\"token punctuation\">.</span>name\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">ProductsPage</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> splat <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>params<span class=\"token punctuation\">.</span>awsKey<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">AppPage</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> splat <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>params<span class=\"token punctuation\">[</span>‘<span class=\"token operator\">*</span>’<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2><code class=\"language-text\">config</code> function</h2>\n<p>Inside a File System Route template you can export an async function called <code class=\"language-text\">config</code>. You can use this function to:</p>\n<ul>\n<li>Mark the page as deferred or not (see <a href=\"/docs/reference/rendering-options/deferred-static-generation/\">Deferred Static Generation API reference</a>)</li>\n</ul>\n<p>Inside your template:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> graphql <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'gatsby'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// The rest of your page, including imports, page component &amp; page query etc.</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">config</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> data <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> graphql<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n    {\n      # Your GraphQL query\n    }\n  </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> params <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">defer</span><span class=\"token operator\">:</span> params<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> data<span class=\"token punctuation\">.</span>someValue<span class=\"token punctuation\">.</span>name\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>When you export an async <code class=\"language-text\">config</code> function Gatsby will evaluate the returned object and optionally run any GraphQL queries defined inside the outer function. You can't run GraphQL queries inside the inner function.</p>\n<p>The <code class=\"language-text\">params</code> parameter is an object that contains the URL path, see <a href=\"#collection-route-components\">explanation above</a>.</p>\n<p>The inner function of <code class=\"language-text\">config</code> can return an object with one key:</p>\n<ul>\n<li><code class=\"language-text\">defer</code>: Boolean of whether the page should be marked as deferred or not</li>\n</ul>\n<p>Read the <a href=\"/docs/how-to/rendering-options/using-deferred-static-generation/\">Deferred Static Generation guide</a> to see a real-world example.</p>\n<h2>Example use cases</h2>\n<p>Have a look at the <a href=\"https://github.com/gatsbyjs/gatsby/tree/master/examples/route-api/src/pages/products\">route-api example</a> for more detail.</p>\n<h3>Collection route + fallback</h3>\n<p>By using a combination of a collection route with a client-only route, you can create a seamless experience when a user tries to visit a URL from the collection route that doesn’t exist (yet) for the collection item. Consider these two file paths:</p>\n<ul>\n<li><code class=\"language-text\">src/pages/products/{Product.name}.js</code> (collection route)</li>\n<li><code class=\"language-text\">src/pages/products/[name].js</code> (client-only route, fallback)</li>\n</ul>\n<p>The collection route will create all available product pages at the time of the <a href=\"/docs/glossary/build/\">build</a>. If you're adding a new product you want to link to but only periodically building your site, you'll need a fallback. By using a client-only route as a fallback you then can load the necessary information for the product on the client until you re-built your site.</p>\n<p>Similarly, the fallback page could also be used for when a product doesn't exist and you want to show some helpful information (like a 404 page).</p>\n<h3>Using one template for multiple routes</h3>\n<p>By placing the template/view for your routes into a reusable component you can display the same information under different routes. Take this example:</p>\n<p>You want to display product information which is both accessible by name and SKU but has the same design. Create two file paths first:</p>\n<ul>\n<li><code class=\"language-text\">src/pages/products/{Product.name}.js</code></li>\n<li><code class=\"language-text\">src/pages/products/{Product.meta__sku}.js</code></li>\n</ul>\n<p>Create a view component at <code class=\"language-text\">src/view/product-view.js</code> that takes in a <code class=\"language-text\">product</code> prop. Use that component in both collection routes, e.g.:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> graphql <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'gatsby'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ProductView <span class=\"token keyword\">from</span> <span class=\"token string\">'../../views/product-view'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Product</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> product <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>ProductView product<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>product<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Product<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> query <span class=\"token operator\">=</span> graphql<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n    query ($id: String!) {\n        product(id: { eq: $id }) {\n            name\n            description\n            appearance\n            meta {\n                createdAt\n                id\n                sku\n            }\n        }\n    }\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can copy the same code to the <code class=\"language-text\">src/pages/products/{Product.meta__sku}.js</code> file.</p>\n<h3>Purely client-only app</h3>\n<p>If you want your Gatsby app to be 100% client-only, you can create a file at <code class=\"language-text\">src/pages/[...].js</code> to catch all requests. See the <a href=\"https://github.com/gatsbyjs/gatsby/tree/master/examples/client-only-paths\">client-only-paths example</a> for more detail.</p>"},{"url":"/blog/flow-control-in-python/","relativePath":"blog/flow-control-in-python.md","relativeDir":"blog","base":"flow-control-in-python.md","name":"flow-control-in-python","frontmatter":{"title":"flow-control-in-python","subtitle":"flow-control-in-python","date":"2021-10-14","thumb_image_alt":"python logo","excerpt":"These operators evaluate to True or False depending on the values you give them","seo":{"title":"flow-control-in-python'","description":"These operators evaluate to True or False depending on the values you give them","robots":[],"extra":[]},"template":"post","thumb_image":"images/python.jpg","image":"images/python2-15e88a3a.jpg"},"html":"<h2>Read It</h2>\n<ul>\n<li><a href=\"https://www.pythoncheatsheet.org\">Website</a></li>\n<li><a href=\"https://github.com/wilfredinni/python-cheatsheet\">Github</a></li>\n<li><a href=\"https://github.com/wilfredinni/Python-cheatsheet/raw/master/python_cheat_sheet.pdf\">PDF</a></li>\n<li><a href=\"https://mybinder.org/v2/gh/wilfredinni/python-cheatsheet/master?filepath=jupyter_notebooks\">Jupyter Notebook</a></li>\n</ul>\n<h2>Flow Control</h2>\n<h3>Comparison Operators</h3>\n<table>\n<thead>\n<tr>\n<th>Operator</th>\n<th>Meaning</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">==</code></td>\n<td>Equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">!=</code></td>\n<td>Not equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">&lt;</code></td>\n<td>Less than</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">></code></td>\n<td>Greater Than</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">&lt;=</code></td>\n<td>Less than or Equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">>=</code></td>\n<td>Greater than or Equal to</td>\n</tr>\n</tbody>\n</table>\n<p>These operators evaluate to True or False depending on the values you give them.</p>\n<p>Examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token number\">42</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">40</span> <span class=\"token operator\">==</span> <span class=\"token number\">42</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'hello'</span> <span class=\"token operator\">==</span> <span class=\"token string\">'hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'hello'</span> <span class=\"token operator\">==</span> <span class=\"token string\">'Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'dog'</span> <span class=\"token operator\">!=</span> <span class=\"token string\">'cat'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token number\">42.0</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token string\">'42'</span></code></pre></div>\n<h3>Boolean evaluation</h3>\n<p>Never use <code class=\"language-text\">==</code> or <code class=\"language-text\">!=</code> operator to evaluate boolean operation. Use the <code class=\"language-text\">is</code> or <code class=\"language-text\">is not</code> operators,\nor use implicit boolean evaluation.</p>\n<p>NO (even if they are valid Python):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token operator\">!=</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>YES (even if they are valid Python):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>These statements are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span></code></pre></div>\n<p>And these as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> a<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span></code></pre></div>\n<h3>Boolean Operators</h3>\n<p>There are three Boolean operators: and, or, and not.</p>\n<p>The <em>and</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>True and True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>True and False</td>\n<td>False</td>\n</tr>\n<tr>\n<td>False and True</td>\n<td>False</td>\n</tr>\n<tr>\n<td>False and False</td>\n<td>False</td>\n</tr>\n</tbody>\n</table>\n<p>The <em>or</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>True or True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>True or False</td>\n<td>True</td>\n</tr>\n<tr>\n<td>False or True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>False or False</td>\n<td>False</td>\n</tr>\n</tbody>\n</table>\n<p>The <em>not</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>not True</td>\n<td>False</td>\n</tr>\n<tr>\n<td>not False</td>\n<td>True</td>\n</tr>\n</tbody>\n</table>\n<h3>Mixing Boolean and Comparison Operators</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token number\">9</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">or</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can also use multiple Boolean operators in an expression, along with the comparison operators:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">4</span> <span class=\"token keyword\">and</span> <span class=\"token keyword\">not</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">5</span> <span class=\"token keyword\">and</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span></code></pre></div>\n<h3>if Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>else Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, stranger.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>elif Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are not Alice, kiddo.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are not Alice, kiddo.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are neither Alice nor a little kid.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>while Loop Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n<span class=\"token keyword\">while</span> spam <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, world.'</span><span class=\"token punctuation\">)</span>\n    spam <span class=\"token operator\">=</span> spam <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<h3>break Statements</h3>\n<p>If the execution reaches a break statement, it immediately exits the while loop's clause:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Please type your name.'</span><span class=\"token punctuation\">)</span>\n    name <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'your name'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">break</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Thank you!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>continue Statements</h3>\n<p>When the program execution reaches a continue statement, the program execution immediately jumps back to the start of the loop.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Who are you?'</span><span class=\"token punctuation\">)</span>\n    name <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> name <span class=\"token operator\">!=</span> <span class=\"token string\">'Joe'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">continue</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, Joe. What is the password? (It is a fish.)'</span><span class=\"token punctuation\">)</span>\n    password <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> password <span class=\"token operator\">==</span> <span class=\"token string\">'swordfish'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">break</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Access granted.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>for Loops and the range() Function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'My name is'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Jimmy Five Times ({})'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <em>range()</em> function can also be called with three arguments. The first two arguments will be the start and stop values, and the third will be the step argument. The step is the amount that the variable is increased by after each iteration.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can even use a negative number for the step argument to make the for loop count down instead of up.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>For else statement</h3>\n<p>This allows you to specify a statement to execute after the full loop has been executed. Only\nuseful when a <code class=\"language-text\">break</code> condition can occur in the loop:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">if</span> i <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n       <span class=\"token keyword\">break</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"only executed when no item of the list is equal to 3\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Importing Modules</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random<span class=\"token punctuation\">,</span> sys<span class=\"token punctuation\">,</span> os<span class=\"token punctuation\">,</span> math</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> random <span class=\"token keyword\">import</span> <span class=\"token operator\">*</span></code></pre></div>\n<h3>Ending a Program with sys.exit</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> sys\n\n<span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Type exit to exit.'</span><span class=\"token punctuation\">)</span>\n    response <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> response <span class=\"token operator\">==</span> <span class=\"token string\">'exit'</span><span class=\"token punctuation\">:</span>\n        sys<span class=\"token punctuation\">.</span>exit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You typed {}.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>"},{"url":"/blog/event-handeling/","relativePath":"blog/event-handeling.md","relativeDir":"blog","base":"event-handeling.md","name":"event-handeling","frontmatter":{"title":"Event Handeling","template":"post","subtitle":"Event objects are normally created by Script","excerpt":"Event objects are normally created by Script","date":"2022-04-19T07:12:49.030Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eventloop.gif?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eventloop.gif?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/git.yaml","src/data/categories/ds.yaml","src/data/categories/js.yaml"],"tags":["src/data/tags/links.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/passing-arguments-to-a-callback-in-js.md","src/pages/blog/using-the-dom.md"],"cmseditable":true},"html":"<ul>\n<li>Event objects are normally created by ScriptUI and passed to your event handler. However, you can simulate a user action by constructing an event object using <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/scriptui-class.html#scriptui-events-createevent\">ScriptUI.events.createEvent()</a>, and sending it to a target object’s controlobj-dispatchEvent function.</li>\n<li>A helper object, <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/environment.html#environment-keyboard-state\">Keyboard state object</a>, provides global access to the keyboard state during function execution, outside the event-handling framework.</li>\n</ul>\n<hr>\n<h2>UIEvent base class<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#uievent-base-class\" title=\"Permalink to this headline\">¶</a></h2>\n<p>Encapsulates input event information for an event that propagates through a container and control hierarchy. This is a base class for the more specialized <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#keyboardevent-object\">KeyboardEvent object</a> and <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#mouseevent-object\">MouseEvent object</a>.</p>\n<h3>UIEvent object properties<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#uievent-object-properties\" title=\"Permalink to this headline\">¶</a></h3>\n<p>Both keyboard and mouse events have these properties.</p>\n<hr>\n<h4>bubbles<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#bubbles\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the event supports the bubbling phase.</p>\n<hr>\n<h4>cancelable<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#cancelable\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the handler can call this object’s <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#eventobj-preventdefault\">preventDefault()</a> method to cancel the default action of the event.</p>\n<hr>\n<h4>currentTarget<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#currenttarget\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Object</code></p>\n<p>The element object where the currently executing handler was registered. This could be an ancestor of the target object, if the handler is invoked during the capture or bubbling phase.</p>\n<hr>\n<h4>eventPhase<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#eventphase\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Number</code></p>\n<p>Current event propagation phase. One of these constants:</p>\n<ul>\n<li><code class=\"language-text\">Event.NOT_DISPATCHING</code></li>\n<li><code class=\"language-text\">Event.CAPTURING_PHASE</code></li>\n<li><code class=\"language-text\">Event.AT_TARGET</code></li>\n<li><code class=\"language-text\">Event.BUBBLING_PHASE</code></li>\n</ul>\n<hr>\n<h4>target<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#target\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Object</code></p>\n<p>The element object where the event occurred.</p>\n<hr>\n<h4>timeStamp<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#timestamp\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Object</code></p>\n<p>Time the event was initiated. A JavaScript Date object.</p>\n<hr>\n<h4>type<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#type\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">String</code></p>\n<p>The name of the event that occurred. Predefined events types are:</p>\n<table>\n<colgroup>\n<col> <col>\n</colgroup>\n<tbody>\n<tr>\n<td>\n<p>change</p>\n</td>\n<td>\n<p>changing</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>move</p>\n</td>\n<td>\n<p>moving</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>resize</p>\n</td>\n<td>\n<p>resizing</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>show</p>\n</td>\n<td>\n<p>enterKey</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>focus</p>\n</td>\n<td>\n<p>blur</p>\n</td>\n</tr>\n</tbody>\n</table>\n<p>Additional type names apply specifically to keyboard and mouse events.</p>\n<hr>\n<h4>view<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#view\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Object</code></p>\n<p>The container or control object that dispatched the event.</p>\n<hr>\n<h3>UIEvent object functions<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#uievent-object-functions\" title=\"Permalink to this headline\">¶</a></h3>\n<h4>initUIEvent()<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#inituievent\" title=\"Permalink to this headline\">¶</a></h4>\n<p><code class=\"language-text\">eventObj.initUIEvent(eventName, bubble, isCancelable, view, detail)</code></p>\n<table>\n<colgroup>\n<col> <col>\n</colgroup>\n<tbody>\n<tr>\n<td>\n<p>\n<code>\n<span>eventName</span>\n</code>\n</p>\n</td>\n<td>\n<p>The event name string.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>bubble</span>\n</code>\n</p>\n</td>\n<td>\n<p>When true, the event should be triggered in ancestors of the target object during the bubbling phase.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>isCancelable</span>\n</code>\n</p>\n</td>\n<td>\n<p>When true, the event can be cancelled.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>view</span>\n</code>\n</p>\n</td>\n<td>\n<p>The container or control object that dispatched the event.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>detail</span>\n</code>\n</p>\n</td>\n<td>\n<p>Details of the event, which vary according to the event type. The value is 1 or 2 for the click event, indicating a single or double click.</p>\n</td>\n</tr>\n</tbody>\n</table>\n<p>Modifies an event before it is dispatched to its targets. Takes effect only if <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#eventobj-eventphase\">UIEvent.eventPhase</a> is <code class=\"language-text\">Event.NOT_DISPATCHING</code>. Ignored at all other phases.</p>\n<p>Returns undefined.</p>\n<hr>\n<h4>preventDefault()<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#preventdefault\" title=\"Permalink to this headline\">¶</a></h4>\n<p><code class=\"language-text\">eventObj.preventDefault()</code></p>\n<p>Cancels the default action of this event, if this event is cancelable (that is, <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#eventobj-cancelable\">cancelable</a> is true). For example, the default click action of an OK button is to close the containing dialog; this call prevents that behavior.</p>\n<p>Returns <code class=\"language-text\">undefined</code>.</p>\n<hr>\n<h4>stopPropagation()<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#stoppropagation\" title=\"Permalink to this headline\">¶</a></h4>\n<p><code class=\"language-text\">eventObj.stopPropagation()</code></p>\n<p>Stops event propagation (bubbling and capturing) after executing the handler or handlers at the current target.</p>\n<p>Returns <code class=\"language-text\">undefined</code>.</p>\n<hr>\n<h2>KeyboardEvent object<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#keyboardevent-object\" title=\"Permalink to this headline\">¶</a></h2>\n<p>This type of object is passed to your registered event handler when a keyboard-input event occurs. The properties reflect the keypress and key modifier state at the time the keyboard event was generated. All properties are read-only.</p>\n<h3>KeyboardEvent object properties<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#keyboardevent-object-properties\" title=\"Permalink to this headline\">¶</a></h3>\n<p>In addition to the properties defined for <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#uievent-base-class\">UIEvent base class</a>, a keyboard event has these properties. All properties are read-only.</p>\n<hr>\n<h4>altKey<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#altkey\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the <code class=\"language-text\">ALT</code> key was active. Value is <code class=\"language-text\">undefined</code> if the <code class=\"language-text\">keyIdentifier</code> is for a modifier key.</p>\n<hr>\n<h4>ctrlKey<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#ctrlkey\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the <code class=\"language-text\">CTRL</code> key was active. Value is <code class=\"language-text\">undefined</code> if the <code class=\"language-text\">keyIdentifier</code> is for a modifier key.</p>\n<hr>\n<h4>metaKey<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#metakey\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the <code class=\"language-text\">META</code> or <code class=\"language-text\">COMMAND</code> key was active. Value is <code class=\"language-text\">undefined</code> if the <code class=\"language-text\">keyIdentifier</code> is for a modifier key.</p>\n<hr>\n<h4>shiftKey<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#shiftkey\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the <code class=\"language-text\">SHIFT</code> key was active. Value is <code class=\"language-text\">undefined</code> if the <code class=\"language-text\">keyIdentifier</code> is for a modifier key.</p>\n<hr>\n<h4>keyIdentifier<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#keyidentifier\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">String</code></p>\n<p>The key whose keypress generated the event, as a W3C identifier contained in a string; for example, <code class=\"language-text\">\"U+0044\"</code>. See <a href=\"https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/keyset.html\">W3 Keyset Article</a>.</p>\n<hr>\n<h4>keyLocation<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#keylocation\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Number</code></p>\n<p>A constant that identifies where on the keyboard the keypress occurred. One of:</p>\n<ul>\n<li><code class=\"language-text\">DOM_KEY_LOCATION_STANDARD</code></li>\n<li><code class=\"language-text\">DOM_KEY_LOCATION_LEFT</code></li>\n<li><code class=\"language-text\">DOM_KEY_LOCATION_RIGHT</code></li>\n<li><code class=\"language-text\">DOM_KEY_LOCATION_NUMPAD</code></li>\n</ul>\n<hr>\n<h4>keyName<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#keyname\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">String</code></p>\n<p>The key whose keypress generated the event, as a simple key name; for example <code class=\"language-text\">\"A\"</code>.</p>\n<hr>\n<h4>type<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#id4\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">String</code></p>\n<p>The name of the event that occurred. Key events types are:</p>\n<ul>\n<li><code class=\"language-text\">keyup</code></li>\n<li><code class=\"language-text\">keydown</code></li>\n</ul>\n<hr>\n<h3>KeyboardEvent object functions<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#keyboardevent-object-functions\" title=\"Permalink to this headline\">¶</a></h3>\n<p>In addition to the functions defined for <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#uievent-base-class\">UIEvent base class</a>, a keyboard event has these functions.</p>\n<hr>\n<h4>getModifierState()<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#getmodifierstate\" title=\"Permalink to this headline\">¶</a></h4>\n<p><code class=\"language-text\">eventObj.getModifierState(keyIdentifier)</code></p>\n<table>\n<colgroup>\n<col> <col>\n</colgroup>\n<tbody>\n<tr>\n<td>\n<p>\n<code>\n<span>keyIdentifier</span>\n</code>\n</p>\n</td>\n<td>\n<p>A string containing a modifier key identifier, one of:</p>\n<blockquote>\n<div>\n<ul>\n<li>\n<p>\n<code>\n<span>Alt</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>CapsLock</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>Control</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>Meta</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>NumLock</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>Scroll</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>Shift</span>\n</code>\n</p>\n</li>\n</ul>\n</div>\n</blockquote>\n</td>\n</tr>\n</tbody>\n</table>\n<p>Returns true if the given modifier was active when the event occurred, false otherwise.</p>\n<p>Note</p>\n<p>If you’re trying to check whether keyboard modifier keys (alt/ctrl/meta/shift) are held down at any time in your script, not just in an event, see <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/environment.html#environment-keyboard-state\">Keyboard state object</a>.</p>\n<hr>\n<h4>initKeyboardEvent()<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#initkeyboardevent\" title=\"Permalink to this headline\">¶</a></h4>\n<p><code class=\"language-text\">eventObj.initKeyboardEvent (eventName, bubble, isCancelable, view, keyID, keyLocation, modifiersList)</code></p>\n<table>\n<colgroup>\n<col> <col>\n</colgroup>\n<tbody>\n<tr>\n<td>\n<p>\n<code>\n<span>eventName</span>\n</code>\n</p>\n</td>\n<td>\n<p>The event name string.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>bubble</span>\n</code>\n</p>\n</td>\n<td>\n<p>When true, the event should be triggered in ancestors of the target object during the bubbling phase.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>isCancelable</span>\n</code>\n</p>\n</td>\n<td>\n<p>When true, the event can be cancelled.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>view</span>\n</code>\n</p>\n</td>\n<td>\n<p>The container or control object that dispatched the event.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>keyID</span>\n</code>\n</p>\n</td>\n<td>\n<p>Sets the <code>\n<span>keyIdentifier</span>\n</code> value.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>keyLocation</span>\n</code>\n</p>\n</td>\n<td>\n<p>Sets the <code>\n<span>keyLocation</span>\n</code>. value.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>modifiersList</span>\n</code>\n</p>\n</td>\n<td>\n<p>A whitespace-separated string of modifier key names, such as “Control Alt”.</p>\n</td>\n</tr>\n</tbody>\n</table>\n<p>Reinitializes the object, allowing you to change the event properties after construction. Arguments set the corresponding properties. Returns <code class=\"language-text\">undefined</code>.</p>\n<hr>\n<h2>MouseEvent object<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#mouseevent-object\" title=\"Permalink to this headline\">¶</a></h2>\n<p>This type of object is passed to your registered event handler when a mouse-input event occurs. The properties reflect the button and modifier-key state and pointer position at the time the event was generated. In the case of nested elements, mouse event types are always targeted at the most deeply nested element. Ancestors of the targeted element can use bubbling to obtain notification of mouse events which occur within its descendent elements.</p>\n<h3>MouseEvent object properties<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#mouseevent-object-properties\" title=\"Permalink to this headline\">¶</a></h3>\n<p>In addition to the properties defined for <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#uievent-base-class\">UIEvent base class</a>, a mouse event has these properties. All properties are read-only.</p>\n<hr>\n<h4>altKey<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#id7\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the <code class=\"language-text\">ALT</code> key was active. Value is <code class=\"language-text\">undefined</code> if the <code class=\"language-text\">keyIdentifier</code> is for a modifier key.</p>\n<hr>\n<h4>button<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#button\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Number</code></p>\n<p>Which mouse button changed state.</p>\n<table>\n<colgroup>\n<col> <col>\n</colgroup>\n<tbody>\n<tr>\n<td>\n<p>\n<code>\n<span>0</span>\n</code>\n</p>\n</td>\n<td>\n<p>The left button of a two- or three-button mouse or the one button on a one-button mouse, used to activate a UI button or select text.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>1</span>\n</code>\n</p>\n</td>\n<td>\n<p>The middle button of a three-button mouse, or the mouse wheel.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>2</span>\n</code>\n</p>\n</td>\n<td>\n<p>The right button, used to display a context menu, if present.</p>\n</td>\n</tr>\n</tbody>\n</table>\n<p>Some mice may provide or simulate more buttons, and values higher than 2 represent such buttons.</p>\n<hr>\n<h4>clientX and clientY<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#clientx-and-clienty\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Number</code></p>\n<p>The horizontal and vertical coordinates at which the event occurred relative to the target object. The origin is the top left of the control or window, inside any border decorations.</p>\n<hr>\n<h4>ctrlKey<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#id8\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the <code class=\"language-text\">CTRL</code> key was active. Value is <code class=\"language-text\">undefined</code> if the <code class=\"language-text\">keyIdentifier</code> is for a modifier key.</p>\n<hr>\n<h4>detail<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#detail\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Number</code></p>\n<p>Details of the event, which vary according to the event type. For the <code class=\"language-text\">click</code>, <code class=\"language-text\">mousedown</code>, and <code class=\"language-text\">mouseup</code> events, the value is <code class=\"language-text\">1</code> for a single click, or <code class=\"language-text\">2</code> for a double click.</p>\n<hr>\n<h4>metaKey<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#id9\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the <code class=\"language-text\">META</code> or <code class=\"language-text\">COMMAND`</code> key was active. Value is <code class=\"language-text\">undefined</code> if the <code class=\"language-text\">keyIdentifier</code> is for a modifier key.</p>\n<hr>\n<hr>\n<h4>screenX and screenY<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#screenx-and-screeny\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Number</code></p>\n<p>The horizontal and vertical coordinates at which the event occurred relative to the screen.</p>\n<hr>\n<h4>shiftKey<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#id10\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">Boolean</code></p>\n<p>When true, the <code class=\"language-text\">SHIFT</code> key was active. Value is <code class=\"language-text\">undefined</code> if the <code class=\"language-text\">keyIdentifier</code> is for a modifier key.</p>\n<hr>\n<h4>type<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#id11\" title=\"Permalink to this headline\">¶</a></h4>\n<p>Type: <code class=\"language-text\">String</code></p>\n<p>The name of the event that occurred. Mouse events types are:</p>\n<ul>\n<li><code class=\"language-text\">mousedown</code></li>\n<li><code class=\"language-text\">mouseup</code></li>\n<li><code class=\"language-text\">mousemove</code></li>\n<li><code class=\"language-text\">mouseover</code></li>\n<li><code class=\"language-text\">mouseout</code></li>\n<li><code class=\"language-text\">click (detail = 1 for single, 2 for double)</code></li>\n</ul>\n<p>The sequence of click events is: <code class=\"language-text\">mousedown</code>, <code class=\"language-text\">mouseup</code>, <code class=\"language-text\">click</code>.</p>\n<hr>\n<h3>MouseEvent object functions<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#mouseevent-object-functions\" title=\"Permalink to this headline\">¶</a></h3>\n<p>In addition to the functions defined for <a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#uievent-base-class\">UIEvent base class</a>, a mouse event has these functions.</p>\n<hr>\n<h4>getModifierState()<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#mouseevent-object-getmodifierstate\" title=\"Permalink to this headline\">¶</a></h4>\n<p><code class=\"language-text\">eventObj.getModifierState(keyIdentifier)</code></p>\n<table>\n<colgroup>\n<col> <col>\n</colgroup>\n<tbody>\n<tr>\n<td>\n<p>\n<code>\n<span>keyIdentifier</span>\n</code>\n</p>\n</td>\n<td>\n<p>A string containing a modifier key identifier, one of:</p>\n<blockquote>\n<div>\n<ul>\n<li>\n<p>\n<code>\n<span>Alt</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>CapsLock</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>Control</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>Meta</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>NumLock</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>Scroll</span>\n</code>\n</p>\n</li>\n<li>\n<p>\n<code>\n<span>Shift</span>\n</code>\n</p>\n</li>\n</ul>\n</div>\n</blockquote>\n</td>\n</tr>\n</tbody>\n</table>\n<p>Returns true if the given modifier was active when the event occurred, false otherwise.</p>\n<hr>\n<h4>initMouseEvent()<a href=\"https://extendscript.docsforadobe.dev/user-interface-tools/event-handling.html#initmouseevent\" title=\"Permalink to this headline\">¶</a></h4>\n<blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">eventObj.initMouseEvent(\n    eventName,\n    bubble,\n    isCancelable,\n    view,\n    detail,\n    screenX,\n    screenY,\n    clientX,\n    clientY,\n    ctrlKey,\n    altKey,\n    shiftKey,\n    metaKey,\n    button,\n    relatedTarge\n)</code></pre></div>\n</blockquote>\n<table>\n<colgroup>\n<col> <col>\n</colgroup>\n<tbody>\n<tr>\n<td>\n<p>\n<code>\n<span>eventName</span>\n</code>\n</p>\n</td>\n<td>\n<p>The event name string.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>bubble</span>\n</code>\n</p>\n</td>\n<td>\n<p>When true, the event should be triggered in ancestors of the target object during the bubbling phase.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>isCancelable</span>\n</code>\n</p>\n</td>\n<td>\n<p>When true, the event can be cancelled.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>view</span>\n</code>\n</p>\n</td>\n<td>\n<p>The container or control object that dispatched the event.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>detail</span>\n</code>\n</p>\n</td>\n<td>\n<p>Sets the single-double click value for the <code>\n<span>click</span>\n</code> event.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>screenX,</span> <span>screenY</span>\n</code>\n</p>\n</td>\n<td>\n<p>Sets the event coordinates relative to the screen.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>clientX,</span> <span>clientY</span>\n</code>\n</p>\n</td>\n<td>\n<p>Sets the event coordinates relative to the target object. The origin is the top left of the control or window, inside any border decorations.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>ctrlKey,</span> <span>altKey,</span> <span>metaKey</span>\n</code>\n</p>\n</td>\n<td>\n<p>Sets the modifier key states.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>button</span>\n</code>\n</p>\n</td>\n<td>\n<p>Sets the mouse button.</p>\n</td>\n</tr>\n<tr>\n<td>\n<p>\n<code>\n<span>relatedTarget</span>\n</code>\n</p>\n</td>\n<td>\n<p>Optional. Sets the related target, if any, for a <code>\n<span>mouseover</span>\n</code> or <code>\n<span>mouseout</span>\n</code> event.</p>\n</td>\n</tr>\n</tbody>\n</table>\n<p>Reinitializes the object, allowing you to change the event properties after construction. Arguments set the corresponding properties.</p>\n<p>Returns <code class=\"language-text\">undefined</code>.<a class=\"jsbin-embed\" href=\"https://jsbin.com/dizifem/embed?js,console,output\">JS Bin on jsbin.com</a></p>\n<script src=\"https://static.jsbin.com/js/embed.min.js?4.1.8\">\n</script>"},{"url":"/blog/expressjs-apis/","relativePath":"blog/expressjs-apis.md","relativeDir":"blog","base":"expressjs-apis.md","name":"expressjs-apis","frontmatter":{"title":"ExpressJS Apis","subtitle":"node & expressjs Overview","date":"2021-07-26","thumb_image_alt":"node and express js","excerpt":"## **Overview**  A **database schema** is the shape of our database. It defines what tables well have, which columns should exist within the tables and any restrictions on each column.  A well-designed database schema keeps the data well organized and can help ensure high-quality data.  Note that while schema design is usually left to Database Administrators (DBAs), understanding schema helps when designing APIs and database logic. And in a smaller team, this step may fall on the developer.","seo":{"title":"ExpressJS Apis","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"post","thumb_image":"images/express.png"},"html":"<h3>Part</h3>\n<h1>A <strong>database is a collection of data organized for easy retrieval and manipulation</strong></h1>\n<p><a href=\"https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_where\">SQL Tryit Editor v1.6</a></p>\n<blockquote>\n<p>We're concerned only with digital databases, those that run on computers or other electronic devices. Digital databases have been around since the 1960s. Relational databases, those which store \"related\" data, are the oldest and most common type of database in use today.</p>\n</blockquote>\n<h3><strong>Data Persistence</strong></h3>\n<p>A database is often necessary because our application or code requires data persistence. This term refers to data that is infrequently accessed and not likely to be modified. In less technical terms, the information will be safely stored and remain untouched unless intentionally modified.</p>\n<p>A familiar example of non-persistent data would be JavaScript objects and arrays, which reset each time the code runs.</p>\n<h4><strong>Relational Databases</strong></h4>\n<p>In relational databases, <strong>the data is stored in tabular format grouped into rows and columns</strong> (similar to spreadsheets). A collection of rows is called a table. Each row represents a single record in the table and is made up of one or more columns.</p>\n<p>These kinds of databases are relational because a <em>relation</em> is a mathematical idea equivalent to a table. So relational databases are databases that store their data in tables.</p>\n<h4><strong>Tables</strong></h4>\n<p><img src=\"https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2e309a41-e107-46f3-81e7-154d732d3dcf/Untitled.png\" alt=\"tables\"></p>\n<p><strong>Below are some basic facts about tables:</strong></p>\n<ul>\n<li>Tables organize data in rows and columns.</li>\n<li>Each row in a table represents one distinct record.</li>\n<li>Each column represents a field or attribute t</li>\n<li>Fields should have a descriptive name and a data type appropriate for the attribute it represents.</li>\n<li>Tables usually have more rows than columns.</li>\n<li>Tables have primary keys that uniquely identify each row.</li>\n<li>Foreign keys represent the relationships with other tables.</li>\n</ul>\n<h4><strong>Overview</strong></h4>\n<h4>SQL</h4>\n<p>SQL is a standard language, which means that it almost certainly will be supported, no matter how your database is managed. That said, be aware that the SQL language can vary depending on database management tools. This lesson focuses on a set of core commands that never change. Learning the standard commands is an excellent introduction since the knowledge transfers between database products.</p>\n<p>The syntax for SQL is English-like and requires fewer symbols than programming languages like C, Java, and JavaScript.</p>\n<p>It is declarative and concise, which means there is a lot less to learn to use it effectively.</p>\n<p>When learning SQL, it is helpful to understand that each command is designed for a different purpose. If we classify the commands by purpose, we'll end up with the following sub-categories of SQL:</p>\n<ul>\n<li><strong>Data Definition Language (DDL)</strong>: used to modify database objects. Some examples are: CREATE TABLE, ALTER TABLE, and DROP TABLE.</li>\n<li><strong>Data Manipulation Language (DML)</strong>: used to manipulate the data stored in the database. Some examples are: INSERT, UPDATE, and DELETE.</li>\n<li><strong>Data Query Language (DQL)</strong>: used to ask questions about the data stored in the database. The most commonly used SQL command is SELECT, and it falls in this category.</li>\n<li><strong>Data Control Language (DCL)</strong>: used to manage database security and user's access to data. These commands fall into the realm of Database Administrators. Some examples are GRANT and REVOKE.</li>\n<li><strong>Transaction Control Commands</strong>: used for managing groups of statements that must execute as a unit or not execute at all. Examples are COMMIT and ROLLBACK.</li>\n</ul>\n<p>As a developer, you'll need to get familiar with DDL and become proficient using DML and DQL. This lesson will cover only DML and DQL commands.</p>\n<h4><strong>Overview</strong></h4>\n<p>The four SQL operations covered in this section will allow a user to <strong>query</strong>, <strong>insert</strong>, and <strong>modify</strong> a database table.</p>\n<h4><strong>Query</strong></h4>\n<p>A <strong>query</strong> is a SQL statement used to retrieve data from a database. The command used to write queries is SELECT, and it is one of the most commonly used SQL commands.</p>\n<p>The basic syntax for a SELECT statement is this:</p>\n<p>To see all the fields on a table, we can use a * as the selection.</p>\n<p>The preceding statement would show all the records and all the columns for each record in the employees table.</p>\n<p>To pick the fields we want to see, we use a comma-separated list:</p>\n<p>The return of that statement would hold all records from the listed fields.</p>\n<p>We can extend the SELECT command's capabilities using clauses for things like filtering, sorting, pagination, and more.</p>\n<p>It is possible to query multiple tables in a single query. But, in this section, we only perform queries on a single table. We will cover performing queries on multiple tables in another section.</p>\n<h4><strong>Insert</strong></h4>\n<p>To <strong>insert</strong> new data into a table, we'll use the INSERT command. The basic syntax for an INSERT statement is this:</p>\n<p>Using this formula, we can specify which values will be inserted into which fields like so:</p>\n<h4><strong>Modify</strong></h4>\n<p><strong>Modifying</strong> a database consists of updating and removing records. For these operations, we'll use UPDATE and DELETE commands, respectively.</p>\n<p>The basic syntax for an UPDATE statement is:</p>\n<p>The basic syntax for a DELETE statement is:</p>\n<h4><strong>Follow Along</strong></h4>\n<h4><strong>Filtering results using WHERE clause</strong></h4>\n<p>When querying a database, the default result will be every entry in the given table. However, often, we are looking for a specific record or a set of records that meets certain criteria.</p>\n<p>A WHERE clause can help in both cases.</p>\n<p>Here's an example where we might only want to find customers living in Berlin.</p>\n<p>We can also chain together WHERE clauses using OR and AND to limit our results further.</p>\n<p>The following query includes only records that match both criteria.</p>\n<p>And this query includes records that match either criteria.</p>\n<p>These operators can be combined and grouped with parentheses to add complex selection logic. They behave similarly to what you're used to in programming languages.</p>\n<p>You can read more about SQLite operators from <a href=\"https://www.w3resource.com/sqlite/operators.php\">w3resource (Links to an external site.)</a>.</p>\n<p>To select a single record, we can use a WHERE statement with a uniquely identifying field, like an id:</p>\n<p>Other comparison operators also work in WHERE conditions, such as >, &#x3C;, &#x3C;=, and >=.</p>\n<h4><strong>Ordering results using the ORDER BY clause</strong></h4>\n<p>Query results are shown in the same order the data was inserted. To control how the data is sorted, we can use the ORDER BY clause. Let's see an example.</p>\n<p>We can pass a list of field names to order by and optionally choose asc or desc for the sort direction. The default is asc, so it doesn't need to be specified.</p>\n<p>Some SQL engines also support using field abbreviations when sorting.</p>\n<p>In this case, the results are sorted by the department in ascending order first and then by salary in descending order. The numbers refer to the fields' position in the <em>selection</em> portion of the query, so 1 would be <em>name</em>, 2 would be <em>salary</em>, and so on.</p>\n<p>Note that the WHERE clause should come after the FROM clause. The ORDER BY clause always goes last.</p>\n<h4><strong>Limiting results using the LIMIT clause</strong></h4>\n<p>When we wish to see only a limited number of records, we can use a LIMIT clause.</p>\n<p>The following returns the first ten records in the products table:</p>\n<p>LIMIT clauses are often used in conjunction with ORDER BY. The following shows us the five cheapest products:</p>\n<h4><strong>Inserting data using INSERT</strong></h4>\n<p>An insert statement adds a new record to the database. All non-null fields must be listed out in the same order as their values. Some fields, like ids and timestamps, may be auto-generated and do not need to be included in an INSERT statement.</p>\n<p>The values in an insert statement must not violate any restrictions and constraints that the database has in place, such as expected datatypes. We will learn more about constraints and schema design in a later section.</p>\n<h4><strong>Modifying recording using UPDATE</strong></h4>\n<p>When modifying a record, we identify a single record or a set of records to update using a WHERE clause. Then we can set the new value(s) in place.</p>\n<p>Technically the WHERE clause is not required, but leaving it off would result in every record within the table receiving the update.</p>\n<h4><strong>Removing records using DELETE</strong></h4>\n<p>When removing a record or set of records, we need only identify which record(s) to remove using a WHERE clause:</p>\n<p>Once again, the WHERE clause is not required, but leaving it off would remove every record in the table, so it's essential.</p>\n<h4><strong>Overview</strong></h4>\n<p>Raw SQL is a critical baseline skill. However, Node developers generally use an <strong>Object Relational Mapper (ORM)</strong> or <strong>query builder</strong> to write database commands in a backend codebase. Both <strong>ORMs</strong> and <strong>query builders</strong> are JavaScript libraries that allow us to interface with the database using a JavaScript version of the SQL language.</p>\n<p>For example, instead of a raw SQL SELECT:</p>\n<p>We could use a query builder to write the same logic in JavaScript:</p>\n<p><strong>Query builders</strong> are lightweight and easy to get off the ground, whereas <strong>ORMs</strong> use an object-oriented model and provide more heavy lifting within their rigid structure.</p>\n<p>We will use a <strong>query builder</strong> called <a href=\"https://knexjs.org/\">knex.js (Links to an external site.)</a>.</p>\n<h4><strong>Follow Along</strong></h4>\n<h4><strong>Knex Setup</strong></h4>\n<p>To use Knex in a repository, we'll need to add two libraries:</p>\n<p>knex is our query builder library, and sqlite3 allows us to interface with a sqlite database. We'll learn more about sqlite and other <strong>database management systems</strong> in the following module. For now, know that you need both libraries.</p>\n<p>Next, we use Knex to set up a config file:</p>\n<p>To use the query builder elsewhere in our code, we need to call knex and pass in a config object. We'll be discussing Knex configuration more in a future module. Still, we only need the client, connection, and useNullAsDefault keys as shown above. The filename should point towards the pre-existing database file, which can be recognized by the .db3 extension.</p>\n<p><strong>GOTCHA</strong>: The file path to the database should be with respect to the <strong>root</strong> of the repo, not the configuration file itself.</p>\n<p>Once Knex is configured, we can import the above config file anywhere in our codebase to access the database.</p>\n<p>The db object provides methods that allow us to begin building queries.</p>\n<h4><strong>SELECT using Knex</strong></h4>\n<p>In Knex, the equivalent of SELECT * FROM users is:</p>\n<p>There's a simpler way to write the same command:</p>\n<p>Using this, we could write a GET endpoint.</p>\n<p><strong>NOTE</strong>: All Knex queries return promises.</p>\n<p>Knex also allows for a where clause. In Knex, we could write SELECT * FROM users WHERE id=1 as</p>\n<p>This method will resolve to an array containing a single entry like so: [{ id: 1, name: 'bill' }].</p>\n<p>Using this, we might add a GET endpoint where a specific user:</p>\n<h4><strong>INSERT using Knex</strong></h4>\n<p>In Knex, the equivalent of INSERT INTO users (name, age) VALUES ('Eva', 32) is:</p>\n<p>The insert method in Knex will resolve to an array containing the newly created id for that user like so: [3].</p>\n<h4><strong>UPDATE using Knex</strong></h4>\n<p>In knex, the equivalent of UPDATE users SET name='Ava', age=33 WHERE id=3; is:</p>\n<p>Note that the where method comes before update, unlike in SQL.</p>\n<p>Update will resolve to a count of rows updated.</p>\n<h4><strong>DELETE using Knex</strong></h4>\n<p>In Knex, the equivalent of DELETE FROM users WHERE age=33; is:</p>\n<p>Once again, the where must come before the del. This method will resolve to a count of records removed.</p>\n<hr>\n<h3>Part    2</h3>\n<h4><strong>Overview</strong></h4>\n<p>SQLlite Studio is an application that allows us to create, open, view, and modify SQLite databases. To fully understand what SQLite Studio is and how it works, we must also understand the concept of the Database Management Systems (DBMS).</p>\n<h4><strong>Follow Along</strong></h4>\n<h4><strong>What is a DBMS?</strong></h4>\n<p>To manage digital databases we use specialized software called <strong>D</strong>ata<strong>B</strong>ase <strong>M</strong>anagement <strong>S</strong>ystems (DBMS). These systems typically run on servers and are managed by <strong>D</strong>ata<strong>B</strong>ase <strong>A</strong>dministrators (DBAs).</p>\n<p>In less technical terms, we need a type of software that will allow us to create, access, and generally manage our databases. In the world of relational databases, we specifically use Relational Database Mangement Systems (RDBMs). Some examples are Postgres, SQLite, MySQL, and Oracle.</p>\n<p>Choosing a DBMS determines everything from how you set up your database, to where and how the data is stored, to what SQL commands you can use. Most systems share the core of the SQL language that you've already learned.</p>\n<p>In other words, you can expect SELECT, UPDATE, INSERT, WHERE , and the like to be the same across all DBMSs, but the subtleties of the language may vary.</p>\n<h4><strong>What is SQLite?</strong></h4>\n<p><strong>SQLite</strong> is the DBMS, as the name suggests, it is a more lightweight system and thus easier to get set up than some others.</p>\n<p>SQLite allows us to store databases as single files. SQLite projects have a .db3 extension. That is the database.</p>\n<p>SQLite is <em>not a database</em> (like relational, graph, or document are databases) but rather <em>a database management system</em>.</p>\n<h4><strong>Opening an existing database in SQLite Studio</strong></h4>\n<p>One useful visual interface we might use with a SQLite database is called <strong>SQLite Studio</strong>. <a href=\"https://sqlitestudio.pl/\">Install SQLITE Studio here. (Links to an external site.)</a></p>\n<p>Once installed, we can use SQLite Studio to open any .db3 file from a previous lesson. We may view the tables, view the data, and even make changes to the database.</p>\n<p>For a more detailed look at SQLite Studio, follow along in the video above.</p>\n<h4><strong>Overview</strong></h4>\n<p>A <strong>database schema</strong> is the shape of our database. It defines what tables we'll have, which columns should exist within the tables and any restrictions on each column.</p>\n<p>A well-designed database schema keeps the data well organized and can help ensure high-quality data.</p>\n<p>Note that while schema design is usually left to Database Administrators (DBAs), understanding schema helps when designing APIs and database logic. And in a smaller team, this step may fall on the developer.</p>\n<h4><strong>Follow Along</strong></h4>\n<p>For a look at schema design in SQLite Studio, follow along in the video above.</p>\n<p>When designing a single table, we need to ask three things:</p>\n<ul>\n<li>What fields (or columns) are present?</li>\n<li>What type of data do we expect for each field?</li>\n<li>Are there other restrictions needed for each column?</li>\n</ul>\n<p>Looking at the following schema diagram for an accounts table, we can the answer to each other those questions:</p>\n<p><a href=\"https://www.notion.so/9790405dda624818822293a383eec2d2\">Untitled</a></p>\n<h4><strong>Table Fields</strong></h4>\n<p>Choosing which fields to include in a table is relatively straight forward. What information needs to be tracked regarding this resource? In the real world, this is determined by the intended use of the product or app.</p>\n<p>However, this is one requirement every table should satisfy: a <strong>primary key</strong>. A primary key is a way to identify each entry in the database uniquely. It is most often represented as a auto-incrementing integer called id or [tablename]Id.</p>\n<h4><strong>Datatypes</strong></h4>\n<p>Each field must also have a specified datatype. The datatype available depends on our DBMS. Some supported datatype in SQLite include:</p>\n<ul>\n<li><strong>Null:</strong> Missing or unknown information.</li>\n<li><strong>Integer:</strong> Whole numbers.</li>\n<li><strong>Real:</strong> Any number, including decimals.</li>\n<li><strong>Text:</strong> Character data.</li>\n<li><strong>Blob:</strong> a large binary object that can be used to store miscellaneous data.</li>\n</ul>\n<p>Any data inserted into the table must match the datatypes determined in schema design.</p>\n<h4><strong>Constraints</strong></h4>\n<p>Beyond datatypes, we may add additional <strong>constraints</strong> on each field. Some examples include:</p>\n<ul>\n<li><strong>Not Null:</strong> The field cannot be left empty</li>\n<li><strong>Unique:</strong> No two records can have the same value in this field</li>\n<li><strong>Primary key:</strong> - Indicates this field is the primary key. Both the not null and unique constraints will be enforced.</li>\n<li><strong>Default:</strong> - Sets a default value if none is provided.</li>\n</ul>\n<p>As with data types, any data that does not satisfy the schema constraints will be rejected from the database.</p>\n<h4><strong>Multi-Table Design</strong></h4>\n<p>Another critical component of schema design is to understand how different tables relate to each other. This will be covered in later lesson.</p>\n<h4><strong>Overview</strong></h4>\n<p>Knex provides a <strong>schema builder</strong>, which allows us to write code to design our database schema. However, beyond thinking about columns and constraints, we must also consider updates.</p>\n<p>When a schema needs to be updated, a developer must feel confident that the changes go into effect everywhere. This means schema updates on the developer's local machine, on any testing or staging versions, on the production database, and then on any other developer's local machines. This is where <strong>migrations</strong> come into play.</p>\n<p>A database migration describes changes made to the structure of a database. Migrations include things like adding new objects, adding new tables, and modifying existing objects or tables.</p>\n<h4><strong>Follow Along</strong></h4>\n<h4><strong>Knex Cli</strong></h4>\n<p>To use migrations (and to make Knex setup easier), we need to use <strong>knex cli</strong>. Install knex globally with npm install -g knex.</p>\n<p>This allows you to use Knex commands within any repo that has knex as a local dependency. If you have any issues with this global install, you can use the npx knex command instead.</p>\n<h4><strong>Initializing Knex</strong></h4>\n<p>To start, add the knex and sqlite3 libraries to your repository.</p>\n<p>npm install knex sqlite3</p>\n<p>We've seen how to use manually create a config object to get started with Knex, but the best practice is to use the following command:</p>\n<p>Or, if Knex isn't globally installed:</p>\n<p>This command will generate a file in your root folder called knexfile.js. It will be auto populated with three config objects, based on different environments. We can delete all except for the development object.</p>\n<p>We'll need to update the location (or desired location) of the database as well as add the useNullAsDefault option. The latter option prevents crashes when working with sqlite3.</p>\n<p>Now, wherever we configure our database, we may use the following syntax instead of hardcoding in a config object.</p>\n<h4><strong>Knex Migrations</strong></h4>\n<p>Once our knexfile is set up, we can begin creating <strong>migrations</strong>. Though it's not required, we are going to add an addition option to the config object to specify a directory for the migration files.</p>\n<p>We can generate a new migration with the following command:</p>\n<p>knex migrate:make [migration-name]</p>\n<p>If we needed to create an accounts table, we might run:</p>\n<p>knex migrate:make create-accounts</p>\n<p>Note that inside data/migrations/ a new file has appeared. Migrations have a timestamp in their filenames automatically. Wither you like this or not, <strong>do not edit migration names.</strong></p>\n<p>The migration file should have both an up and a down function. Within the up function, we write the ended database changes. Within the down function, we write the code to undo the up functions. This allows us to undo any changes made to the schema if necessary.</p>\n<p>References for these methods are found in the <strong>schema builder</strong> section of the <a href=\"https://knexjs.org/\">Knex docs (Links to an external site.)</a>.</p>\n<p>At this point, the table is <strong>not</strong> yet created. To run this (and any other) migrations, use the command:</p>\n<p>knex migrate:latest</p>\n<p>Note if the database does not exist, this command will auto-generate one. We can use SQLite Studio to confirm that the accounts table has been created.</p>\n<h4><strong>Changes and Rollbacks</strong></h4>\n<p>If later down the road, we realize you need to update your schema, you shouldn't edit the migration file. Instead, you will want to create a new migration with the command:</p>\n<p>knex migrate:make accounts-schema-update</p>\n<p>Once we've written our updates into this file we save and close with:</p>\n<p>knex migrate:latest</p>\n<p>If we migrate our database and then quickly realize something isn't right, we can edit the migration file. However, first, we need to <strong>rolllback</strong> (or undo) our last migration with:</p>\n<p>knex migrate:rollback</p>\n<p>Finally, we are free to rerun that file with knex migrate latest.</p>\n<p><strong>NOTE</strong>: A rollback should not be used to edit an old migration file once that file has accepted into a main branch. However, an entire team may use a rollback to return to a previous version of a database.</p>\n<h4><strong>Overview</strong></h4>\n<p>Knex provides a <strong>schema builder</strong>, which allows us to write code to design our database schema. However, beyond thinking about columns and constraints, we must also consider updates.</p>\n<p>When a schema needs to be updated, a developer must feel confident that the changes go into effect everywhere. This means schema updates on the developer's local machine, on any testing or staging versions, on the production database, and then on any other developer's local machines. This is where <strong>migrations</strong> come into play.</p>\n<p>A database migration describes changes made to the structure of a database. Migrations include things like adding new objects, adding new tables, and modifying existing objects or tables.</p>\n<h4><strong>Follow Along</strong></h4>\n<h4><strong>Knex Cli</strong></h4>\n<p>To use migrations (and to make Knex setup easier), we need to use <strong>knex cli</strong>. Install knex globally with npm install -g knex.</p>\n<p>This allows you to use Knex commands within any repo that has knex as a local dependency. If you have any issues with this global install, you can use the npx knex command instead.</p>\n<h4><strong>Initializing Knex</strong></h4>\n<p>To start, add the knex and sqlite3 libraries to your repository.</p>\n<p>npm install knex sqlite3</p>\n<p>We've seen how to use manually create a config object to get started with Knex, but the best practice is to use the following command:</p>\n<p>Or, if Knex isn't globally installed:</p>\n<p>This command will generate a file in your root folder called knexfile.js. It will be auto populated with three config objects, based on different environments. We can delete all except for the development object.</p>\n<p>We'll need to update the location (or desired location) of the database as well as add the useNullAsDefault option. The latter option prevents crashes when working with sqlite3.</p>\n<p>Now, wherever we configure our database, we may use the following syntax instead of hardcoding in a config object.</p>\n<h4><strong>Knex Migrations</strong></h4>\n<p>Once our knexfile is set up, we can begin creating <strong>migrations</strong>. Though it's not required, we are going to add an addition option to the config object to specify a directory for the migration files.</p>\n<p>We can generate a new migration with the following command:</p>\n<p>knex migrate:make [migration-name]</p>\n<p>If we needed to create an accounts table, we might run:</p>\n<p>knex migrate:make create-accounts</p>\n<p>Note that inside data/migrations/ a new file has appeared. Migrations have a timestamp in their filenames automatically. Wither you like this or not, <strong>do not edit migration names.</strong></p>\n<p>The migration file should have both an up and a down function. Within the up function, we write the ended database changes. Within the down function, we write the code to undo the up functions. This allows us to undo any changes made to the schema if necessary.</p>\n<p>References for these methods are found in the <strong>schema builder</strong> section of the <a href=\"https://knexjs.org/\">Knex docs (Links to an external site.)</a>.</p>\n<p>At this point, the table is <strong>not</strong> yet created. To run this (and any other) migrations, use the command:</p>\n<p>knex migrate:latest</p>\n<p>Note if the database does not exist, this command will auto-generate one. We can use SQLite Studio to confirm that the accounts table has been created.</p>\n<h4><strong>Changes and Rollbacks</strong></h4>\n<p>If later down the road, we realize you need to update your schema, you shouldn't edit the migration file. Instead, you will want to create a new migration with the command:</p>\n<p>knex migrate:make accounts-schema-update</p>\n<p>Once we've written our updates into this file we save and close with:</p>\n<p>knex migrate:latest</p>\n<p>If we migrate our database and then quickly realize something isn't right, we can edit the migration file. However, first, we need to <strong>rolllback</strong> (or undo) our last migration with:</p>\n<p>knex migrate:rollback</p>\n<p>Finally, we are free to rerun that file with knex migrate latest.</p>\n<p><strong>NOTE</strong>: A rollback should not be used to edit an old migration file once that file has accepted into a main branch. However, an entire team may use a rollback to return to a previous version of a database.</p>\n<h4><strong>Overview</strong></h4>\n<p>Often we want to pre-populate our database with sample data for testing. <strong>Seeds</strong> allow us to add and reset sample data easily.</p>\n<h4><strong>Follow Along</strong></h4>\n<p>The Knex command-line tool offers a way to <strong>seed</strong> our database; in other words, pre-populate our tables.</p>\n<p>Similarly to migrations, we want to customize where our seed files are generated using our knexfile</p>\n<p>To create a seed run: knex seed:make 001-seedName</p>\n<p>Numbering is a good idea because Knex doesn't attach a timestamp to the name like migrate does. Adding numbers to the file name, we can control the order in which they run.</p>\n<p>We want to create seeds for our accounts table:</p>\n<p>knex seed:make 001-accounts</p>\n<p>A file will appear in the designated seed folder.</p>\n<p>Run the seed files by typing:</p>\n<p>knex seed:run</p>\n<p>You can now use SQLite Studio to confirm that the accounts table has two entries.</p>\n<hr>\n<h3>Part    3</h3>\n<h4><strong>Overview</strong></h4>\n<p><strong>Foreign keys</strong> are a type of table field used for creating links between tables. Like <strong>primary keys</strong>, they are most often integers that identify (rather than store) data. However, whereas a primary key is used to id rows in a table, foreign keys are used to connect a record in one table to a record in a second table.</p>\n<h4><strong>Follow Along</strong></h4>\n<p>Consider the following farms and ranchers tables.</p>\n<p><a href=\"https://www.notion.so/5b20c5e233dd4a70a33d6ab2c2e1c8bb\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/0b0a909c24a9474fb9df80938546f12a\">Untitled</a></p>\n<p>The farm<em>id in the ranchers table is an example of a foreign key. Each entry in the farm</em>id (foreign key) column corresponds to an id (primary key) in the farms table. This allows us to track which farm each rancher belongs to while keeping the tables normalized.</p>\n<p>If we could only see the ranchers table, we would know that John, Jane, and Jen all work together and that Jim and Jay also work together. However, to know where any of them work, we would need to look at the farms table.</p>\n<p>Now that we understand the basics of querying data from a single table, let's move on to selecting data from multiple tables using JOIN operations.</p>\n<h4><strong>Overview</strong></h4>\n<p>We can use a JOIN to combine query data from multiple tables using a single SELECT statement.</p>\n<p>There are different types of joins; some are listed below:</p>\n<ul>\n<li>inner joins.</li>\n<li>outer joins.</li>\n<li>left joins.</li>\n<li>right joins.</li>\n<li>cross joins.</li>\n<li>non-equality joins.</li>\n<li>self joins.</li>\n</ul>\n<p>Using joins requires that the two tables of interest contain at least one field with shared information. For example, if a <em>departments</em> table has an <em>id</em> field, and an employee table has a <em>department</em>id_ field, and the values that exist in the <em>id</em> column of the <em>departments</em> table live in the <em>department</em>id_ field of the employee table, we can use those fields to join both tables like so:</p>\n<p>This query will return the data from both tables for every instance where the ON condition is true. If there are employees with no value for department<em>id or where the value stored in the field does not correspond to an existing id in the</em>departments<em>table, then that record will NOT be returned. In a similar fashion, any records from the</em>departments<em>table that don't have an employee associated with them will also be omitted from the results. Basically, if the</em> id* does not show as the value of department_id for an employee, it won't be able to join.</p>\n<p>We can shorten the condition by giving the table names an alias. This is a common practice. Below is the same example using aliases, picking which fields to return and sorting the results:</p>\n<p>Notice that we can take advantage of white space and indentation to make queries more readable.</p>\n<p>There are several ways of writing joins, but the one shown here should work on all database management systems and avoid some pitfalls, so we recommend it.</p>\n<p>The syntax for performing a similar join using Knex is as follows:</p>\n<h4><strong>Follow Along</strong></h4>\n<p>A good explanation of how the different types of joins can be seen <a href=\"https://www.w3resource.com/sql/joins/sql-joins.php\">in this article from w3resource.com (Links to an external site.)</a>.</p>\n<h4>What is SQL Joins?</h4>\n<p>An SQL JOIN clause combines rows from two or more tables. It creates a set of rows in a temporary table.</p>\n<h4>How to Join two tables in SQL?</h4>\n<p>A JOIN works on two or more tables if they have at least one common field and have a relationship between them.</p>\n<p>JOIN keeps the base tables (structure and data) unchanged.</p>\n<h3>Join vs. Subquery</h3>\n<ul>\n<li>JOINs are faster than a subquery and it is very rare that the opposite.</li>\n<li>In JOINs the RDBMS calculates an execution plan, that can predict, what data should be loaded and how much it will take to processed and as a result this pro</li>\n<li>A JOIN is checked conditions first and then put it into table and displays; where as a subquery take separate temp table internally and checking condition.</li>\n<li>When joins are using, there should be connection between two or more than two tables and each table has a relation with other while subquery means query inside another query, has no need to relation, it works on columns and conditions.</li>\n</ul>\n<h3>SQL JOINS: EQUI JOIN and NON EQUI JOIN</h3>\n<p>The are two types of SQL JOINS - EQUI JOIN and NON EQUI JOIN</p>\n<ol>\n<li>SQL EQUI JOIN :</li>\n</ol>\n<p>The SQL EQUI JOIN is a simple SQL join uses the equal sign(=) as the comparison operator for the condition. It has two types - SQL Outer join and SQL Inner join.</p>\n<ol>\n<li>SQL NON EQUI JOIN :</li>\n</ol>\n<p>The <strong>SQL NON EQUI JOIN</strong> is a join uses comparison operator other than the equal sign like >, &#x3C;, >=, &#x3C;= with the condition.</p>\n<p><strong>SQL EQUI JOIN : INNER JOIN and OUTER JOIN</strong></p>\n<p>The SQL EQUI JOIN can be classified into two types - INNER JOIN and OUTER JOIN</p>\n<ol>\n<li>SQL INNER JOIN</li>\n</ol>\n<p>This type of EQUI JOIN returns all rows from tables where the key record of one table is equal to the key records of another table.</p>\n<ol>\n<li>SQL OUTER JOIN</li>\n</ol>\n<p>This type of EQUI JOIN returns all rows from one table and only those rows from the secondary table where the joined condition is satisfying i.e. the columns are equal in both tables.</p>\n<p>In order to perform a JOIN query, the required information we need are:</p>\n<p><strong>a)</strong> The name of the tables<strong>b)</strong> Name of the columns of two or more tables, based on which a condition will perform.</p>\n<p><strong>Syntax:</strong></p>\n<p><strong>Parameters:</strong></p>\n<p><a href=\"https://www.notion.so/5522c3e6d5d0443eb870f7a34f60c7ff\">Untitled</a></p>\n<p><strong>Pictorial Presentation of SQL Joins:</strong></p>\n<p><img src=\"https://www.w3resource.com/w3r_images/sql-joins-all.gif\" alt=\"image\"></p>\n<p><strong>Example:</strong></p>\n<p><strong>Sample table: company</strong></p>\n<p><strong>Sample table: foods</strong></p>\n<p>To join two tables 'company' and 'foods', the following SQL statement can be used :</p>\n<p><strong>SQL Code:</strong></p>\n<p>Copy</p>\n<p>Output:</p>\n<h4><strong>Overview</strong></h4>\n<p>While we can write database code directly into our endpoints, best practices dictate that all database logic exists in separate, modular methods. These files containing database access helpers are often called <strong>models</strong></p>\n<h4><strong>Follow Along</strong></h4>\n<p>To handle CRUD operations for a single resource, we would want to create a <strong>model</strong> (or database access file) containing the following methods:</p>\n<p>Each of these functions would use Knex logic to perform the necessary database operation.</p>\n<p>For each method, we can choose what value to return. For example, we may prefer findById() to return a single user object rather than an array.</p>\n<p>We can also use existing methods like findById() to help add() return the new user (instead of just the id).</p>\n<p>Once all methods are written as desired, we can export them like so:</p>\n<p>…and use the helpers in our endpoints</p>\n<p>There should no be knex code in the endpoints themselves.</p>\n<hr>\n<h3>Part    4</h3>\n<p><img src=\"https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5ecaf43d-ee27-4da1-aa3c-aa1d9d96cc40/Untitled.png\" alt=\"image\"></p>\n<h4><strong>Overview</strong></h4>\n<p>Normalization is the process of designing or refactoring database tables for maximum consistency and minimum redundancy.</p>\n<p>With objects, we're used to <em>denormalized</em> data, stored with ease of use and speed in mind. Non-normalized tables are considered ineffective in relational databases.</p>\n<h4><strong>Follow Along</strong></h4>\n<p><strong>Data normalization</strong> is a deep topic in database design. To begin thinking about it, we'll explore a few basic guidelines and some data examples that violate these rules.</p>\n<h4><strong>Normalization Guidelines</strong></h4>\n<ul>\n<li>Each record has a primary key.</li>\n<li>No fields are repeated.</li>\n<li>All fields relate directly to the key data.</li>\n<li>Each field entry contains a single data point.</li>\n<li>There are no redundant entries.</li>\n</ul>\n<h4><strong>Denormalized Data</strong></h4>\n<p><a href=\"https://www.notion.so/19a01f68a659470fb85bbe6906fb4bad\">Untitled</a></p>\n<p>This table has two issues. There is no proper id field (as multiple farms may have the same name), and multiple fields are representing the same type of data: animals.</p>\n<p><a href=\"https://www.notion.so/075ad6dd99ac48698625d7b56ca67bef\">Untitled</a></p>\n<p>While we have now eliminated the first two issues, we now have multiple entries in one field, separated by commas. This isn't good either, as its another example of denormalization. There is no \"array\" data type in a relational database, so each field must contain only one data point.</p>\n<p><a href=\"https://www.notion.so/375a15b0cb3f444a8698cd6cb3a08fe0\">Untitled</a></p>\n<p>Now we've solved the multiple fields issue, but we created repeating data (the farm field), which is also an example of denormalization. As well, we can see that if we were tracking additional ranch information (such as annual revenue), that field is only vaguely related to the animal information.</p>\n<p><strong>When these issues begin arising in your schema design, it means that you should separate information into two or more tables.</strong></p>\n<h4><strong>Anomalies</strong></h4>\n<p>Obeying the above guidelines prevent <strong>anomalies</strong> in your database when inserting, updating, or deleting. For example, imagine if the revenue of Beech Ranch changed. With our denormalized schema, it may get updated in some records but not others:</p>\n<p><a href=\"https://www.notion.so/e05f5b2e8ff141798adc6f188f56f31e\">Untitled</a></p>\n<p>Similarly, if Beech Ranch shut down, there would be three (if not more) records that needed to be deleted to remove a single farm.</p>\n<p>Thus a denormalized table opens the door for contradictory, confusing, and unusable data.</p>\n<h4><strong>Challenge</strong></h4>\n<p>What issues does the following table have?</p>\n<p><a href=\"https://www.notion.so/2793e8f6b70a47f48f9208779366e69e\">Untitled</a></p>\n<h4><strong>Overview</strong></h4>\n<p>There are three types of relationships:</p>\n<ul>\n<li>One to one.</li>\n<li>One to many.</li>\n<li>Many to many.</li>\n</ul>\n<p>Determining how data is related can provide a set of guidelines for table representation and guides the use of foreign keys to connect said tables.</p>\n<h4><strong>Follow Along</strong></h4>\n<h4><strong>One to One Relationships</strong></h4>\n<p>Imagine we are storing the financial projections for a series of farms.</p>\n<p>We may wish to attach fields like farm name, address, description, projected revenue, and projected expenses. We could divide these fields into two categories: information related to the farm directly (name, address, description) and information related to the financial projections (revenue, expenses).</p>\n<p>We would say that farms and projections have a <strong>one-to-one</strong> relationship. This is to say that every farm has exactly one projection, and every project corresponds to exactly one farm.</p>\n<p>This data can be represented in two tables: farms and projections</p>\n<p><a href=\"https://www.notion.so/944e594f3464473ea06383bfdea13265\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/de32fcf6760e45f284707274433fee92\">Untitled</a></p>\n<p>The farm_id is the foreign key that links farms and projections together.</p>\n<p>Notes about one-to-one relationships:</p>\n<ul>\n<li>The foreign key should always have a unique constraint to prevent duplicate entries. In the example above, we wouldn't want to allow multiple projections records for one farm.</li>\n<li>The foreign key can be in either table. For example, we may have had a projection_id in the farms table instead. A good rule of thumb is to put the foreign key in whichever table is more auxiliary to the other.</li>\n<li>You can represent one-to-one data in a single table <em>without</em> creating anomalies. However, it is sometimes prudent to use two tables as shown above to keep separate concerns in separate tables.</li>\n</ul>\n<h4><strong>One to Many Relationships</strong></h4>\n<p>Now imagine, we are storing the full-time ranchers employed at each farm. In this case, each rancher would only work at one farm however, each farm may have multiple ranchers.</p>\n<p>This is called a <strong>one-to-many</strong> relationship.</p>\n<p>This is the most common type of relationship between entities. Some other examples:</p>\n<ul>\n<li>One customer can have many orders.</li>\n<li>One user can have many posts.</li>\n<li>One post can have many comments.</li>\n</ul>\n<p>Manage this type of relationship by adding a foreign key on the \"many\" table of the relationship that points to the primary key on the \"one\" table. Consider the farms and ranchers tables.</p>\n<p><a href=\"https://www.notion.so/7dfd2e69c9804a01845f2e9b716a5ac2\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/c95f3d418db94ab4b4532eeba0e4f918\">Untitled</a></p>\n<p>In a many-to-many relationship, the foreign key (in this case farm<em>id) should _not</em> be unique.</p>\n<h4><strong>Many to Many Relationships</strong></h4>\n<p>If we want to track animals on a farm as well, we must explore the <strong>many-to-many</strong> relationship. A farm has multiple animals, and multiple of each type of animal is present at multiple different farms.</p>\n<p>Some other examples:</p>\n<ul>\n<li>an order can have many products and the same product will appear in many orders.</li>\n<li>a book can have more than one author, and an author can write more than one book.</li>\n</ul>\n<p>To model this relationship, we need to introduce an <strong>intermediary table</strong> that holds foreign keys that reference the primary key on the related tables. We now have a farms, animals, and farm_animals table.</p>\n<p><a href=\"https://www.notion.so/3269812d7c2a4578b1a9f6bc27e485b1\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/c2642c7f632f489cb1b9639c80b8400d\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/d0b0042c5e104edd9ed55e122af89084\">Untitled</a></p>\n<p>While each foreign key on the intermediary table is not unique, the combinations of keys should be unique.</p>\n<h4><strong>Overview</strong></h4>\n<p>The Knex query builder library also allows us to create multi-table schemas include foreign keys. However, there are a few extra things to keep in mind when designing a multi-table schema, such as using the correct order when creating tables, dropping tables, seeding data, and removing data.</p>\n<p>We have to consider the way that delete and updates through our API will impact related data.</p>\n<h4><strong>Follow Along</strong></h4>\n<h4><strong>Foreign Key Setup</strong></h4>\n<p>In Knex, foreign key restrictions don't automatically work. Whenever using foreign keys in your schema, add the following code to your knexfile. This will prevent users from entering bad data into a foreign key column.</p>\n<h4><strong>Migrations</strong></h4>\n<p>Let's look at how we might track our farms and ranchers using Knex. In our migration file's up function, we would want to create two tables:</p>\n<p>Note that the foreign key can only be created <em>after</em> the reference table.</p>\n<p>In the down function, the opposite is true. We always want to drop a table with a foreign key <em>before</em> dropping the table it references.</p>\n<p>In the case of a many-to-many relationship, the syntax for creating an intermediary table is identical, except for one additional piece. We need a way to make sure our combination of foreign keys is unique.</p>\n<h4><strong>Seeds</strong></h4>\n<p>Order is also a concern when seeding. We want to create seeds in the <strong>same</strong> order we created our tables. In other words, don't create a seed with a foreign key, until that reference record exists.</p>\n<p>In our example, make sure to write the 01-farms seed file and then the 02-ranchers seed file.</p>\n<p>However, we run into a problem with truncating our seeds, because we want to truncate 02-ranchers <em>before</em> 01-farms. A library called knex-cleaner provides an easy solution for us.</p>\n<p>Run knex seed:make 00-cleanup and npm install knex-cleaner. Inside the cleanup seed, use the following code.</p>\n<p>This removes all tables (excluding the two tables that track migrations) in the correct order before any seed files run.</p>\n<h4><strong>Cascading</strong></h4>\n<p>If a user attempt to delete a record that is referenced by another record (such as attempting to delete Morton Ranch when entries in our ranchers table reference that record), by default, the database will block the action. The same thing can happen when updating a record when a foreign key reference.</p>\n<p>If we want that to override this default, we can delete or update with <strong>cascade</strong>. With cascade, deleting a record also deletes all referencing records, we can set that up in our schema.</p>"},{"url":"/blog/front-end-interview-questions-part-2/","relativePath":"blog/front-end-interview-questions-part-2.md","relativeDir":"blog","base":"front-end-interview-questions-part-2.md","name":"front-end-interview-questions-part-2","frontmatter":{"title":"Front End Interview Questions Part 2","template":"post","subtitle":"These will focus more on vocabulary and concepts than the application driven approach in my last post!","excerpt":"­­­­If you were to describe semantic HTML to the next cohort of students, what would you say","date":"2022-05-23T08:41:53.757Z","image":"https://camo.githubusercontent.com/22121fcc4ed529e7fdaea851db57c0e7dbee2ceeffe6f62b536039b71c7362c0/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f302a4433795149343267426b59706e4c58592e6a7067","thumb_image":"https://camo.githubusercontent.com/22121fcc4ed529e7fdaea851db57c0e7dbee2ceeffe6f62b536039b71c7362c0/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f302a4433795149343267426b59706e4c58592e6a7067","image_position":"right","author":"src/data/authors/bgoonz.yaml","tags":["src/data/tags/career-1.yaml","src/data/tags/javascript.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/python-quiz.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h1>Front End Interview Questions Part 2</h1>\n<p>These will focus more on vocabulary and concepts than the application driven approach in my last post!</p>\n<hr>\n<h4><a href=\"https://github.com/permission-squad/gist-notes/blob/main/2021-03-19_Front-End-Interview-Questions-Part-2-86ddc0e91443.md#codex\"></a><a href=\"https://medium.com/codex\">CODEX</a></h4>\n<h3><a href=\"https://github.com/permission-squad/gist-notes/blob/main/2021-03-19_Front-End-Interview-Questions-Part-2-86ddc0e91443.md#front-end-interview-questions-part2\"></a>Front End Interview Questions Part 2</h3>\n<h4><a href=\"https://github.com/permission-squad/gist-notes/blob/main/2021-03-19_Front-End-Interview-Questions-Part-2-86ddc0e91443.md#these-will-focus-more-on-vocabulary-and-concepts-than-the-application-driven-approach-in-my-lastpost\"></a>These will focus more on vocabulary and concepts than the application-driven approach in my last post!</h4>\n<p><a href=\"https://camo.githubusercontent.com/22121fcc4ed529e7fdaea851db57c0e7dbee2ceeffe6f62b536039b71c7362c0/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f302a4433795149343267426b59706e4c58592e6a7067\">\n<img src=\"https://camo.githubusercontent.com/22121fcc4ed529e7fdaea851db57c0e7dbee2ceeffe6f62b536039b71c7362c0/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f302a4433795149343267426b59706e4c58592e6a7067\" alt=\"image\"></a></p>\n<h3><a href=\"https://github.com/permission-squad/gist-notes/blob/main/2021-03-19_Front-End-Interview-Questions-Part-2-86ddc0e91443.md#heres-part-one-for-reference\"></a>Here’s part one for reference:</h3>\n<p><a href=\"https://bryanguner.medium.com/the-web-developers-technical-interview-e347d7db3822\" title=\"https://bryanguner.medium.com/the-web-developers-technical-interview-e347d7db3822\"><strong>The Web Developer’s Technical Interview</strong><br>\n<em>Questions….Answers… and links to the missing pieces.</em>bryanguner.medium.com</a><a href=\"https://bryanguner.medium.com/the-web-developers-technical-interview-e347d7db3822\"></a></p>\n<ul>\n<li><strong>­­­­If you were to describe semantic HTML to the next cohort of students, what would you say?</strong></li>\n</ul>\n<p>Semantic HTML is markup that conveys meaning, not appearance, to search engines to make everything easier to identify.</p>\n<ul>\n<li><strong>Name two big differences between display: block; and display: inline;.</strong></li>\n</ul>\n<p>block starts on a new line and takes up the full width of the content.<br>\ninline starts on the same line as previous content, in line with other content, and takes up only the space needed for the content.</p>\n<p>· <strong>What are the 4 areas of the box model?</strong></p>\n<p>content, padding, border, margin</p>\n<p>· <strong>While using flexbox, what axis does the following property work on: align-items: center?</strong></p>\n<p>cross-axis</p>\n<p>· <strong>Explain why git is valuable to a team of developers.</strong></p>\n<p>Allows you to dole out tiny pieces of a large project to many developers who can all work towards the same goal on their own chunks, allows roll back if you make a mistake; version control.</p>\n<p>· <strong>What is the difference between an adaptive website and a fully responsive website?</strong></p>\n<p>An adaptive website “adapts” to fit a pre-determined set of screen sizes/devices, and a responsive one changes to fit all devices.</p>\n<p>· <strong>Describe what it means to be mobile first vs desktop first.</strong></p>\n<p>It means you develop/code the site with mobile in mind first and work your way outward in screen size.</p>\n<p>· <strong>What does font-size: 62.5% in the html tag do for us when using rem units?</strong></p>\n<p>This setting makes it so that 1 rem = 10 px for font size, easier to calculate.</p>\n<p>· <strong>How would you describe preprocessing to someone new to CSS?</strong></p>\n<p>Preprocessing is basically a bunch of functions and variables you can use to store CSS settings in different ways that make it easier to code CSS.</p>\n<p>· <strong>What is your favorite concept in preprocessing? What is the concept that gives you the most trouble?</strong></p>\n<p>Favorite is (parametric) mixins; but I don’t have a lot of trouble with preprocessing. What gives me the most trouble is knowing ahead of time what would be good to go in a mixin for a given site.</p>\n<p>· <strong>Describe the biggest difference between .forEach &#x26; .map.</strong></p>\n<p>forEach iterates over an array item by item, and map calls a function on each array item, but returns another/additional array, unlike forEach.</p>\n<p>· <strong>What is the difference between a function and a method?</strong></p>\n<p>Every function is an object. If a value is a function, it is a method. Methods have to be ‘received’ by something; functions do not.</p>\n<p>· <strong>What is closure?</strong></p>\n<p>It is code identified elsewhere that we can use later; gives the ability to put functions together. If a variable isn’t defined, a function looks outward for context.</p>\n<p>· <strong>Describe the four rules of the ‘this’ keyword.</strong></p>\n<ol>\n<li>Window/global binding — this is the window/console object. ‘use strict’; to prevent window binding.</li>\n<li>Implicit binding — when a function is called by a dot, the object preceding the dot is the ‘this’. 80 percent of ‘this’ is from this type of binding.</li>\n<li>New binding — points to new object created &#x26; returned by constructor function</li>\n<li>Explicit binding — whenever call, bind, or apply are used.</li>\n</ol>\n<p>· <strong>Why do we need super() in an extended class?</strong></p>\n<p>Super ties the parent to the child.</p>\n<ul>\n<li><strong>What is the DOM?</strong></li>\n</ul>\n<p>Document object model, the ‘window’ or container that holds all the page’s elements</p>\n<ul>\n<li><strong>What is an event?</strong></li>\n</ul>\n<p>An event is something happening on or to the page, like a mouse click, doubleclick, key up/down, pointer out of element/over element, things like this. There are tons of “events” that javascript can detect.</p>\n<ul>\n<li><strong>What is an event listener?</strong></li>\n</ul>\n<p>Javascript command that ‘listens’ for an event to happen on the page to a given element and then runs a function when that event happens</p>\n<ul>\n<li><strong>Why would we convert a NodeList into an Array?</strong></li>\n</ul>\n<p>A NodeList isn’t a real array, so it won’t have access to array methods such as slice or map.</p>\n<ul>\n<li><strong>What is a component?</strong></li>\n</ul>\n<p>Reusable pieces of code to display info in a consistent repeatable way</p>\n<p>· <strong>What is React JS and what problems does it try and solve? Support your answer with concepts introduced in class and from your personal research on the web.</strong></p>\n<p>ReactJS is a library used to build large applications. It’s very good at assisting developers in manipulating the DOM element to create rich user experiences. We need a way to off-load the state/data that our apps use, and React helps us do that.</p>\n<p>· <strong>What does it mean to <em>think</em> in react?</strong></p>\n<p>It makes you think about how to organize/build apps a little differently because it’s very scalable and allows you to build huge apps. React’s one-way data flow makes everything modular and fast. You can build apps top-down or bottom-up.</p>\n<p>· <strong>Describe state.</strong></p>\n<p>Some data we want to display.</p>\n<p>· <strong>Describe props.</strong></p>\n<p>Props are like function arguments in JS and attributes in HTML.</p>\n<p>· <strong>What are side effects, and how do you sync effects in a React component to state or prop changes?</strong></p>\n<p>Side effects are anything that affects something outside the executed function’s scope like fetching data from an API, a timer, or logging.</p>\n<p>· <strong>Explain benefit(s) using client-side routing?</strong></p>\n<p>Answer: It’s much more efficient than the traditional way, because a lot of data isn’t being transmitted unnecessarily.</p>\n<p>· <strong>Why would you use class component over function components (removing hooks from the question)?</strong></p>\n<p>Because some companies still use class components and don’t want to switch their millions of dollars’ worth of code over to all functional hooks, and also there’s currently a lot more troubleshooting content out there for classes that isn’t out there for hooks. Also, functional components are better when you don’t need state, presentational components.</p>\n<p>· <strong>Name three lifecycle methods and their purposes.</strong></p>\n<p>componentDidMount = do the stuff inside this ‘function’ after the component mounted</p>\n<p>componentDidUpdate = do the stuff inside this function after the component updated</p>\n<p>componentWillUnmount = clean-up in death/unmounting phase</p>\n<p>· <strong>What is the purpose of a custom hook?</strong></p>\n<p>allow you to apply non-visual behavior and stateful logic throughout your components by reusing the same hook over and over again</p>\n<p>· <strong>Why is it important to test our apps?</strong></p>\n<p>Gets bugs fixed faster, reduces regression risk, makes you consider/work out the edge cases, acts as documentation, acts as safety net when refactoring, makes code more trustworthy</p>\n<p>· <strong>What problem does the context API help solve?</strong></p>\n<p>You can store data in a context object instead of prop drilling.</p>\n<p>· <strong>In your own words, describe actions, reducers and the store and their role in Redux. What does each piece do? Why is the store known as a ‘single source of truth’ in a redux application?</strong></p>\n<p>Everything that changes within your app is represented by a single JS object called the store. The store contains state for our application. When changes are made to our application state, we never write to our store object but rather clone the state object, modify the clone, and replace the original state with the new copy, never mutating the original object. Reducers are the only place we can update our state. Actions tell our reducers “how” to update the state, and perhaps with what data it should be updated, but only a reducer can actually update the state.</p>\n<p>· <strong>What is the difference between Application state and Component state? When would be a good time to use one over the other?</strong></p>\n<p>App state is global, component state is local. Use component state when you have component-specific variables.</p>\n<p>· <strong>Describe redux-thunk, what does it allow us to do? How does it change our action-creators?</strong></p>\n<p>Redux Thunk is middleware that provides the ability to handle asynchronous operations inside our Action Creators, because reducers are normally synchronous.</p>\n<p>· <strong>What is your favorite state management system you’ve learned and this sprint? Please explain why!</strong></p>\n<p>Redux, because I felt it was easier to understand than the context API.</p>\n<p>· <strong>Explain what a token is used for.</strong></p>\n<p>Many services out in the wild require the client (our React app, for example) to provide proof that it’s authenticated with them. The server running these services can issue a JWT (JSON Web Token) as the authentication token, in exchange for correct login credentials.</p>\n<p>· <strong>What steps can you take in your web apps to keep your data secure?</strong></p>\n<p>As we build our web apps, we will most likely have some “protected” routes — routes that we only want to render if the user has logged in and been authenticated by our server. The way this normally works is we make a login request, sending the server the user’s username and password. The server will check those credentials against what is in the database, and if it can authenticate the user, it will return a token. Once we have this token, we can add two layers of protection to our app. One with protected routes, the other by sending an authentication header with our API calls (as we learned in the above objective).</p>\n<p>· <strong>Describe how web servers work.</strong></p>\n<p>The “world wide web” (which we’ll refer to as “the web”) is just a part of the internet — which is itself a network of interconnected computers. The web is just one way to share data over the internet. It consists of a body of information stored on web servers, ready to be shared across the world. The term “web server” can mean two things:</p>\n<p>· a computer that stores the code for a website</p>\n<p>· a program that runs on such a computer</p>\n<p>The physical computer device that we call a web server is connected to the internet, and stores the code for different websites to be shared across the world at all times. When we load the code for our websites, or web apps, on a server like this, we would say that the server is “hosting” our website/app.</p>\n<p>· <strong>Which HTTP methods can be mapped to the CRUD acronym that we use when interfacing with APIs/Servers.</strong></p>\n<p>Create, Read, Update, Delete</p>\n<p>· <strong>Mention two parts of Express that you learned about this week.</strong></p>\n<p>Routing/router, Middleware, convenience helpers</p>\n<p>· <strong>Describe Middleware?</strong></p>\n<p>array of functions that get executed in the order they are introduced into the server code</p>\n<p>· <strong>Describe a Resource?</strong></p>\n<p>o everything is a <strong>resource</strong>.</p>\n<p>o each resource is accessible via a <strong>unique URI</strong>.</p>\n<p>o resources can have multiple <strong>representations</strong>.</p>\n<p>o communication is done over a <strong>stateless</strong> protocol (HTTP).</p>\n<p>o management of resources is done via <strong>HTTP methods</strong>.</p>\n<p>· <strong>What can the API return to help clients know if a request was successful?</strong></p>\n<p>200 status code/201 status code</p>\n<p>· <strong>How can we partition our application into sub-applications?</strong></p>\n<p>By dividing the code up into multiple files and ‘requiring’ them in the main server file.</p>\n<p>· <strong>Explain the difference between Relational Databases and SQL.</strong></p>\n<p>SQL is the language used to access a relational database.</p>\n<p>· <strong>Why do tables need a primary key?</strong></p>\n<p>To uniquely identify each record/row.</p>\n<p>· <strong>What is the name given to a table column that references the primary key on another table.</strong></p>\n<p>Foreign key</p>\n<p>· <strong>What do we need in order to have a <em>many to many</em> relationship between two tables.</strong></p>\n<p>An <strong>intermediary table</strong> that holds foreign keys that reference the primary key on the related tables.</p>\n<p>· <strong>What is the purpose of using <em>sessions</em>?</strong></p>\n<p>The purpose is to persist data across requests.</p>\n<p>· <strong>What does bcrypt do to help us store passwords in a secure manner?</strong></p>\n<p>o password hashing function.</p>\n<p>o implements salting both manual and automatically.</p>\n<p>o accumulative hashing rounds.</p>\n<p>· <strong>What does bcrypt do to slow down attackers?</strong></p>\n<p>Having an algorithm that hashes the information multiple times (rounds) means an attacker needs to have the hash, know the algorithm used, and how many rounds were used to generate the hash in the first place. So it basically makes it a lot more difficult to get somebody’s password.</p>\n<p>· <strong>What are the three parts of the JSON Web Token?</strong></p>\n<p>Header, payload, signature</p>\n<!--EndFragment-->"},{"url":"/blog/gatsby-cli/","relativePath":"blog/gatsby-cli.md","relativeDir":"blog","base":"gatsby-cli.md","name":"gatsby-cli","frontmatter":{"title":"Gatsby CLI","template":"post","subtitle":"The Gatsby CLI is available via npm ","excerpt":"The Gatsby command line tool  CLI is the main entry point for getting up and running with a Gatsby application ","date":"2022-05-15T23:44:13.229Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-cli.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-cli.png?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/js.yaml","src/data/categories/search.yaml","src/data/categories/react.yaml","src/data/categories/git.yaml","src/data/categories/html.yaml"],"tags":["src/data/tags/cms.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/using-the-dom.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h1>Commands (Gatsby CLI)</h1>\n<h2>TABLE OF CONTENTS</h2>\n<ul>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#how-to-use-gatsby-cli\">How to use gatsby-cli</a></li>\n<li>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#api-commands\">API commands</a></p>\n<ul>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#new\">new</a></li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#develop\">develop</a></li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#build\">build</a></li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#serve\">serve</a></li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#info\">info</a></li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#clean\">clean</a></li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#plugin\">plugin</a></li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#repl\">Repl</a></li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#disabling-colored-output\">Disabling colored output</a></li>\n</ul>\n</li>\n<li><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#how-to-change-your-default-package-manager-for-your-next-project\">How to change your default package manager for your next project?</a></li>\n</ul>\n<p>The Gatsby command line tool (CLI) is the main entry point for getting up and running with a Gatsby application and for using functionality including running a development server and building out your Gatsby application for deployment.</p>\n<p><em>This page provides similar documentation as the gatsby-cli <a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-cli/README.md\">README</a>. The <a href=\"https://www.gatsbyjs.com/docs/cheat-sheet/\">Gatsby cheat sheet</a> has docs for top CLI commands &#x26; APIs all ready to print out.</em></p>\n<h2><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#how-to-use-gatsby-cli\"></a>How to use gatsby-cli</h2>\n<p>The Gatsby CLI is available via <a href=\"https://www.npmjs.com/\">npm</a> and is installed globally by running <code class=\"language-text\">npm install -g gatsby-cli</code>.</p>\n<p>You can also use the <code class=\"language-text\">package.json</code> script variant of these commands, typically exposed <em>for you</em> with most <a href=\"https://www.gatsbyjs.com/docs/starters/\">starters</a>. For example, if you want to make the <a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#develop\"><code class=\"language-text\">gatsby develop</code></a> command available in your application, open up <code class=\"language-text\">package.json</code> and add a script like so:</p>\n<p>package.json</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//on</span>\n<span class=\"token comment\">//package.json</span>\n\n<span class=\"token punctuation\">{</span>\n    <span class=\"token string-property property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string-property property\">\"develop\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"gatsby develop\"</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#api-commands\"></a>API commands</h2>\n<p>All the following documentation is available in the tool by running <code class=\"language-text\">gatsby --help</code>.</p>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#new\"></a><code class=\"language-text\">new</code></h3>\n<h4><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#usage\"></a>Usage</h4>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">gatsby new</code></pre></div>\n<p>The CLI will run an interactive shell asking for these options before creating a Gatsby site for you:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">gatsby new\nWhat would you like to name the folder where your site will be created?\nmy-gatsby-site\nWill you be using a CMS? <span class=\"token punctuation\">(</span>single choice<span class=\"token punctuation\">)</span>\n  No <span class=\"token punctuation\">(</span>or I<span class=\"token string\">'ll add it later)\n  –\n  WordPress\n  Contentful\n  Sanity\n  DatoCMS\n  Shopify\nWould you like to install a styling system? (single choice)\n  No (or I'</span>ll <span class=\"token function\">add</span> it later<span class=\"token punctuation\">)</span>\n  –\n  CSS Modules/PostCSS\n  styled-components\n  Emotion\n  Sass\n  Theme UI\nWould you like to <span class=\"token function\">install</span> additional features with other plugins? <span class=\"token punctuation\">(</span>multiple choice<span class=\"token punctuation\">)</span>\n  ◯ Add the Google Analytics tracking script\n  ◯ Add responsive images\n  ◯ Add page meta tags with React Helmet\n  ◯ Add an automatic sitemap\n  ◯ Enable offline functionality\n  ◯ Generate a manifest <span class=\"token function\">file</span>\n  ◯ Add Markdown support <span class=\"token punctuation\">(</span>without MDX<span class=\"token punctuation\">)</span>\n  ◯ Add Markdown and MDX support</code></pre></div>\n<h4><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#creating-a-site-from-a-starter\"></a>Creating a site from a starter</h4>\n<p>To create a site from a starter instead, run the command with your site name and starter URL:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">gatsby new <span class=\"token punctuation\">[</span><span class=\"token operator\">&lt;</span>site-name<span class=\"token operator\">></span> <span class=\"token punctuation\">[</span><span class=\"token operator\">&lt;</span>starter-url<span class=\"token operator\">></span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Note that this will not prompt you to create a custom setup, but only clone the starter from the URL you specified.</p>\n<h5><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#arguments\"></a>Arguments</h5>\n<table>\n<thead>\n<tr>\n<th>Argument</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>site-name</td>\n<td>Your Gatsby site name, which is also used to create a project directory.</td>\n</tr>\n<tr>\n<td>starter-url</td>\n<td>A Gatsby starter URL or local file path. Defaults to <a href=\"https://github.com/gatsbyjs/gatsby-starter-default\">gatsby-starter-default</a>; see the <a href=\"https://www.gatsbyjs.com/docs/starters/\">Gatsby starters</a> docs for more information.</td>\n</tr>\n</tbody>\n</table>\n<blockquote>\n<p>Note: The <code class=\"language-text\">site-name</code> should only consist of letters and numbers. If you specify a <code class=\"language-text\">.</code>, <code class=\"language-text\">./</code> or a <code class=\"language-text\">&lt;space></code> in the name, <code class=\"language-text\">gatsby new</code> will throw an error.</p>\n</blockquote>\n<h5><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#examples\"></a>Examples</h5>\n<ul>\n<li>Create a Gatsby site named <code class=\"language-text\">my-awesome-site</code> using the default starter:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">gatsby new my-awesome-site</code></pre></div>\n<ul>\n<li>Create a Gatsby site named <code class=\"language-text\">my-awesome-blog-site</code>, using <a href=\"https://www.gatsbyjs.com/starters/gatsbyjs/gatsby-starter-blog/\">gatsby-starter-blog</a>:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">gatsby new my-awesome-blog-site https://github.com/gatsbyjs/gatsby-starter-blog</code></pre></div>\n<p>See the <a href=\"https://www.gatsbyjs.com/docs/starters/\">Gatsby starters docs</a> for more details.</p>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#develop\"></a><code class=\"language-text\">develop</code></h3>\n<p>Once you’ve installed a Gatsby site, go to the root directory of your project and start the development server:</p>\n<p><code class=\"language-text\">gatsby develop</code></p>\n<h4><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#options\"></a>Options</h4>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">-H</code>, <code class=\"language-text\">--host</code></td>\n<td>Set host. Defaults to localhost</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">-p</code>, <code class=\"language-text\">--port</code></td>\n<td>Set port. Defaults to env.PORT or 8000</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">-o</code>, <code class=\"language-text\">--open</code></td>\n<td>Open the site in your (default) browser for you</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">-S</code>, <code class=\"language-text\">--https</code></td>\n<td>Use HTTPS</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">--inspect</code></td>\n<td>Opens a port for debugging</td>\n</tr>\n</tbody>\n</table>\n<p>Follow the <a href=\"https://www.gatsbyjs.com/docs/local-https/\">Local HTTPS guide</a> to find out how you can set up an HTTPS development server using Gatsby.</p>\n<h4><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#preview-changes-on-other-devices\"></a>Preview changes on other devices</h4>\n<p>You can use the Gatsby develop command with the host option to access your dev environment on other devices on the same network, run:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">gatsby develop <span class=\"token parameter variable\">-H</span> <span class=\"token number\">0.0</span>.0.0</code></pre></div>\n<p>Then the terminal will log information as usual, but will additionally include a URL that you can navigate to from a client on the same network to see how the site renders.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">You can now view gatsbyjs.com <span class=\"token keyword\">in</span> the browser.\n⠀\n  Local:            http://0.0.0.0:8000/\n  On Your Network:  http://192.168.0.212:8000/</code></pre></div>\n<p><strong>Note</strong>: To access Gatsby on your local machine, use either <code class=\"language-text\">http://localhost:8000</code> or the “On Your Network” URL.</p>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#build\"></a><code class=\"language-text\">build</code></h3>\n<p>At the root of a Gatsby site, compile your application and make it ready for deployment:</p>\n<p><code class=\"language-text\">gatsby build</code></p>\n<h4><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#options-1\"></a>Options</h4>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">--prefix-paths</code></td>\n<td>Build site with link paths prefixed (set pathPrefix in your config)</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">--no-uglify</code></td>\n<td>Build site without uglifying JS bundles (for debugging)</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">--profile</code></td>\n<td>Build site with react profiling. See <a href=\"https://www.gatsbyjs.com/docs/profiling-site-performance-with-react-profiler/\">Profiling Site Performance with React Profiler</a></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">--open-tracing-config-file</code></td>\n<td>Tracer configuration file (OpenTracing compatible). See <a href=\"https://www.gatsbyjs.com/docs/performance-tracing/\">Performance Tracing</a></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">--graphql-tracing</code></td>\n<td>Trace (see above) every graphql resolver, may have performance implications.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">--no-color</code>, <code class=\"language-text\">--no-colors</code></td>\n<td>Disables colored terminal output</td>\n</tr>\n</tbody>\n</table>\n<p>In addition to these build options, there are some optional <a href=\"https://www.gatsbyjs.com/docs/how-to/local-development/environment-variables/#build-variables\">build environment variables</a> for more advanced configurations that can adjust how a build runs. For example, setting <code class=\"language-text\">CI=true</code> as an environment variable will tailor output for <a href=\"https://en.wikipedia.org/wiki/Computer_terminal#Dumb_terminals\">dumb terminals</a>.</p>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#serve\"></a><code class=\"language-text\">serve</code></h3>\n<p>At the root of a Gatsby site, serve the production build of your site for testing:</p>\n<p><code class=\"language-text\">gatsby serve</code></p>\n<h4><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#options-2\"></a>Options</h4>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">-H</code>, <code class=\"language-text\">--host</code></td>\n<td>Set host. Defaults to localhost</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">-p</code>, <code class=\"language-text\">--port</code></td>\n<td>Set port. Defaults to 9000</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">-o</code>, <code class=\"language-text\">--open</code></td>\n<td>Open the site in your (default) browser for you</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">--prefix-paths</code></td>\n<td>Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config.js).</td>\n</tr>\n</tbody>\n</table>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#info\"></a><code class=\"language-text\">info</code></h3>\n<p>At the root of a Gatsby site, get helpful environment information which will be required when reporting a bug:</p>\n<p><code class=\"language-text\">gatsby info</code></p>\n<h4><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#options-3\"></a>Options</h4>\n<table>\n<thead>\n<tr>\n<th>Option</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">-C</code>, <code class=\"language-text\">--clipboard</code></td>\n<td>Automagically copy environment information to clipboard</td>\n</tr>\n</tbody>\n</table>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#clean\"></a><code class=\"language-text\">clean</code></h3>\n<p>At the root of a Gatsby site, wipe out the cache (<code class=\"language-text\">.cache</code> folder) and public directories:</p>\n<p><code class=\"language-text\">gatsby clean</code></p>\n<p>This is useful as a last resort when your local project seems to have issues or content does not seem to be refreshing. Issues this may fix commonly include:</p>\n<ul>\n<li>Stale data, e.g. this file/resource/etc. isn’t appearing</li>\n<li>GraphQL error, e.g. this GraphQL resource should be present but is not</li>\n<li>Dependency issues, e.g. invalid version, cryptic errors in console, etc.</li>\n<li>Plugin issues, e.g. developing a local plugin and changes don’t seem to be taking effect</li>\n</ul>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#plugin\"></a><code class=\"language-text\">plugin</code></h3>\n<p>Run commands pertaining to gatsby plugins.</p>\n<h4><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#docs\"></a><code class=\"language-text\">docs</code></h4>\n<p><code class=\"language-text\">gatsby plugin docs</code></p>\n<p>Directs you to documentation about using and creating plugins.</p>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#repl\"></a>Repl</h3>\n<p>Get a Node.js REPL (interactive shell) with context of your Gatsby environment:</p>\n<p><code class=\"language-text\">gatsby repl</code></p>\n<p>Gatsby will prompt you to type in commands and explore. When it shows this: <code class=\"language-text\">gatsby ></code></p>\n<p>You can type in a command, such as one of these:</p>\n<p><code class=\"language-text\">babelrc</code></p>\n<p><code class=\"language-text\">components</code></p>\n<p><code class=\"language-text\">dataPaths</code></p>\n<p><code class=\"language-text\">getNodes()</code></p>\n<p><code class=\"language-text\">nodes</code></p>\n<p><code class=\"language-text\">pages</code></p>\n<p><code class=\"language-text\">schema</code></p>\n<p><code class=\"language-text\">siteConfig</code></p>\n<p><code class=\"language-text\">staticQueries</code></p>\n<p>When combined with the <a href=\"https://www.gatsbyjs.com/docs/how-to/querying-data/running-queries-with-graphiql/\">GraphQL explorer</a>, these REPL commands could be very helpful for understanding your Gatsby site’s data.</p>\n<p>For more information, check out the <a href=\"https://www.gatsbyjs.com/docs/gatsby-repl/\">Gatsby REPL documentation</a>.</p>\n<h3><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#disabling-colored-output\"></a>Disabling colored output</h3>\n<p>In addition to the explicit <code class=\"language-text\">--no-color</code> option, the CLI respects the presence of the <code class=\"language-text\">NO_COLOR</code> environment variable (see <a href=\"https://no-color.org/\">no-color.org</a>).</p>\n<h2><a href=\"https://www.gatsbyjs.com/docs/reference/gatsby-cli/#how-to-change-your-default-package-manager-for-your-next-project\"></a>How to change your default package manager for your next project?</h2>\n<p>When you use <code class=\"language-text\">gatsby new</code> for the first time to create a new project, you are asked to choose your default package manager between yarn and npm.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">Which package manager would you like to use ? › - Use arrow-keys. Return to submit.\n❯  <span class=\"token function\">yarn</span>\n   <span class=\"token function\">npm</span></code></pre></div>\n<p>Once you’ve made your choice, the CLI won’t ask for your preference again for any subsequent project.</p>\n<p>If you want to change this for your next project you have to edit the config file created automatically by the CLI. This file is available on your system at: <code class=\"language-text\">~/.config/gatsby/config.json</code></p>\n<p>In it you’re going to see something like this.</p>\n<p>config.json</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//on</span>\n<span class=\"token punctuation\">{</span>\n    <span class=\"token string-property property\">\"cli\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string-property property\">\"packageManager\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"yarn\"</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Edit your <code class=\"language-text\">packageManager</code> value, save and you’re good to go for your next project using <code class=\"language-text\">gatsby new</code>.</p>\n<!--EndFragment-->"},{"url":"/blog/frontend-vs-backend-development-an-essential-guide-for-developers/","relativePath":"blog/frontend-vs-backend-development-an-essential-guide-for-developers.md","relativeDir":"blog","base":"frontend-vs-backend-development-an-essential-guide-for-developers.md","name":"frontend-vs-backend-development-an-essential-guide-for-developers","frontmatter":{"title":"Frontend vs Backend Development: An Essential Guide For Developers","template":"post","subtitle":"If you're not a developer or engineer, concepts like front-end vs. back-end development can be challenging to wrap your head around.","date":"2023-01-19T07:28:32.112Z","image":"/blog/image_2023-01-19_131349843.png","image_position":"right","categories":["src/data/categories/resources.yaml"],"tags":["src/data/tags/web-development.yaml"],"show_author_bio":false,"related_posts":[],"cmseditable":true},"html":"<p>Knowing the differences between frontend and backend development can be essential for any developer looking to stay ahead of the curve. </p>\n<p>This article will go through all the basics of both frontend and backend development, making sure to break down the pros and cons of each so that you can make informed decisions when it comes to your next project. </p>\n<p>Learn how these two sides of web development play a role in the bigger picture, and how they can help you reach your ultimate goals!</p>\n<h2>Introduction</h2>\n<p><img src=\"https://images.theconversation.com/files/479421/original/file-20220816-10908-uvh62x.jpg?ixlib=rb-1.1.0&#x26;rect=4%2C5%2C994%2C497&#x26;q=45&#x26;auto=format&#x26;w=668&#x26;h=324&#x26;fit=crop\" alt=\"Coding – News, Research and Analysis – The Conversation – page 1\"></p>\n<p>In software engineering, frontend vs backend development refers to the division of labor between the graphical user interface (GUI) or presentation layer, and the application logic or business rules layer. </p>\n<p>The presentation layer consists of the user interface and its associated graphics and controls, such as buttons and text boxes. The application logic layer contains the code that implements the functionality of the application. This includes database access, calculations, workflow, and other processing.</p>\n<p>The terms \"front-end\" and \"back-end\" refer to the separation of these two layers. Front-end developers focus on developing the presentation layer. Back-end developers focus on developing the application logic layer. </p>\n<p>There is a lot of overlap between front-end and back-end development. For example, a back-end developer may need to write some HTML or CSS to create a custom control. A front-end developer may need to write some code to access data from a database.</p>\n<h2>What is Frontend Development?</h2>\n<p><img src=\"https://www.maxpixel.net/static/photo/1x/Development-Frontend-Technology-Web-Programming-4342425.png\" alt=\"Free photo Development Frontend Technology Web Programming - Max Pixel\"></p>\n<p><a href=\"https://wilsonwings.com/services/development/frontend-development-services/\">Frontend development</a> is the process of building the user interface and visual elements of a website or application. This can include anything from the layout and design to the functionality and interactivity. </p>\n<p>A frontend developer is responsible for making sure that the user experience is positive and that all of the visual elements work together seamlessly. </p>\n<p>The goal of frontend development is to create a website or application that is easy to use and looks good. It should be able to handle all of the user input and output without any issues. </p>\n<p>The frontend developer works closely with the backend developer to make sure that everything works together smoothly.</p>\n<h2>What is Backend Development?</h2>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/05/ilya-pavlov-OqtafYT5kTw-unsplash.jpg\" alt=\"What is Coding Used For?\"></p>\n<p><a href=\"https://wilsonwings.com/services/development/backend-development-services/\">Backend development</a> is the process of programming the server-side of an application. This includes the databases, server-side scripts, and APIs that are necessary to power the frontend. </p>\n<p>In order to be a backend developer, you need to have a strong understanding of server-side languages (like PHP, Ruby on Rails, or Node.js), database systems (like MySQL or MongoDB), and web hosting.</p>\n<h2>Differences Between Frontend and Backend Development</h2>\n<p><img src=\"https://c8.alamy.com/comp/PF3PDR/desktop-source-code-and-technology-background-developer-or-programer-with-coding-and-programming-wallpaper-by-computer-language-and-source-code-com-PF3PDR.jpg\" alt=\"Desktop source code and technology background, Developer or programer with  coding and programming, Wallpaper by Computer language and source code, Com  Stock Photo - Alamy\"></p>\n<p>When it comes to web development, there are two sides to the coin: frontend and backend development. Both are essential to building a functioning website or application, but they serve different purposes. Frontend developers focus on what the user sees and interacts with, while backend developers handle the behind-the-scenes functionality.</p>\n<p>Here's a more detailed look at the differences between frontend and backend development:</p>\n<p>Frontend Development</p>\n<p>As a frontend developer, your job is to build the user interface and experience for a website or application. This includes everything from the visual design to the actual code that makes it all work. You need to have a strong understanding of both design principles and web development technologies.</p>\n<p>Some of the skills you might need as a frontend developer include:</p>\n<p>• HTML: Used to structure content on a web page\n• CSS: Used to style that content\n• JavaScript: Used to add interactivity to web pages\n• UX/UI Design: User experience and user interface design principles</p>\n<p>Backend Development</p>\n<p>Backend developers need to have a good understanding of database design and application logic in order to create an effective server-side architecture.</p>\n<p>Both frontend and backend development require a good understanding of HTML, CSS, and JavaScript. However, frontend developers will also need to be familiar with frameworks such as React or Angular, while backend developers will need to be familiar with languages such as PHP, Python, or Ruby.</p>\n<h2>Skills Needed for Frontend and Backend Developers</h2>\n<p><img src=\"https://www.maxpixel.net/static/photo/1x/Software-Developer-Web-Developer-Programmer-6521720.jpg\" alt=\"Free photo Software Developer Web Developer Programmer - Max Pixel\"></p>\n<p>There is a lot of overlap between the skills needed for frontend and backend developers. Both need to have a strong understanding of HTML, CSS, and JavaScript. However, there are some key differences.</p>\n<p>Frontend developers need to be able to create and style web pages using HTML, CSS, and JavaScript. They also need to be able to use tools like React or Angular to create interactive user interfaces. Backend developers need to be able to write code in languages like PHP, Ruby, or Python. They also need to be able to use databases like MySQL or MongoDB.</p>\n<h2>Job Responsibilities of a Frontend vs. Backend Developer</h2>\n<p><img src=\"https://cdn.ucberkeleybootcamp.com/wp-content/uploads/sites/106/2020/08/CDG_blog_post_image_01.jpg\" alt=\"How to Become a Software Developer | Berkeley Boot Camps\"></p>\n<p>As a frontend developer, your job responsibilities will include building and maintaining the user interface and visual aspects of the website or application. This includes the layout, design, and overall look and feel of the site. You’ll also be responsible for ensuring that the site is responsive and works across all devices.</p>\n<p>As a backend developer, your job responsibilities will include building and maintaining the server-side of the website or application. This includes the database, application logic, and API. You’ll also be responsible for ensuring that the site is secure and scalable.</p>\n<h2>Popular Frameworks for Frontend and Backend Development</h2>\n<p><img src=\"https://www.simplilearn.com/ice9/free_resources_article_thumb/tester-or-developer-what-suits-you-the-most.jpg\" alt=\"Tester or Developer - What Suits You the Most?\"></p>\n<p>There are many frameworks available for frontend and backend development, and the most popular ones are listed below.</p>\n<p>Frontend Frameworks:</p>\n<ul>\n<li>AngularJS</li>\n<li>ReactJS</li>\n<li>Vue.js</li>\n</ul>\n<p>Backend Frameworks:</p>\n<ul>\n<li>Node.js</li>\n<li>Express.js</li>\n</ul>\n<h2>C﻿onclusion</h2>\n<p>Frontend and backend development are two of the most important aspects of web development. Understanding the differences between them is essential for developers who want to create a great website or application. </p>\n<p>While frontend development focuses on creating an attractive user interface, backend development focuses on building and maintaining a secure system that can store data and respond to user requests quickly. By understanding these concepts in detail, developers can create powerful applications that users will love to use.</p>"},{"url":"/blog/functions-in-python/","relativePath":"blog/functions-in-python.md","relativeDir":"blog","base":"functions-in-python.md","name":"functions-in-python","frontmatter":{"title":"Functions in Python","subtitle":"Functions in Python","date":"2021-10-14","thumb_image_alt":"image of pyhton","excerpt":"wubalubadubdub","seo":{"title":"Functions in Python","description":"Functions in Python","robots":[],"extra":[]},"template":"post","thumb_image":"images/python.jpg"},"html":"<h2>Functions</h2>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Return Values and return Statements</h3>\n<p>When creating a function using the def statement, you can specify what the return value should be with a return statement. A return statement consists of the following:</p>\n<ul>\n<li>The return keyword.</li>\n<li>The value or expression that the function should return.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n<span class=\"token keyword\">def</span> <span class=\"token function\">getAnswer</span><span class=\"token punctuation\">(</span>answerNumber<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'It is certain'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'It is decidedly so'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Yes'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Reply hazy try again'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Ask again later'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Concentrate and ask again'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">7</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'My reply is no'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">8</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Outlook not so good'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">9</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Very doubtful'</span>\n\nr <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span>\nfortune <span class=\"token operator\">=</span> getAnswer<span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>fortune<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The None Value</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello!'</span><span class=\"token punctuation\">)</span>\nspam <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span></code></pre></div>\n<p>Note: never compare to <code class=\"language-text\">None</code> with the <code class=\"language-text\">==</code> operator. Always use <code class=\"language-text\">is</code>.</p>\n<h3>print Keyword Arguments</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'World'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mice'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mice'</span><span class=\"token punctuation\">,</span> sep<span class=\"token operator\">=</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Local and Global Scope</h3>\n<ul>\n<li>Code in the global scope cannot use any local variables.</li>\n<li>However, a local scope can access global variables.</li>\n<li>Code in a function's local scope cannot use variables in any other local scope.</li>\n<li>You can use the same name for different variables if they are in different scopes. That is, there can be a local variable named spam and a global variable also named spam.</li>\n</ul>\n<h3>The global Statement</h3>\n<p>If you need to modify a global variable from within a function, use the global statement:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">spam</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">global</span> eggs\n    eggs <span class=\"token operator\">=</span> <span class=\"token string\">'spam'</span>\n\neggs <span class=\"token operator\">=</span> <span class=\"token string\">'global'</span>\nspam<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>eggs<span class=\"token punctuation\">)</span></code></pre></div>\n<p>There are four rules to tell whether a variable is in a local scope or global scope:</p>\n<ol>\n<li>If a variable is being used in the global scope (that is, outside of all functions), then it is always a global variable.</li>\n<li>If there is a global statement for that variable in a function, it is a global variable.</li>\n<li>Otherwise, if the variable is used in an assignment statement in the function, it is a local variable.</li>\n<li>But if the variable is not used in an assignment statement, it is a global variable.</li>\n</ol>"},{"url":"/blog/git-gateway/","relativePath":"blog/git-gateway.md","relativeDir":"blog","base":"git-gateway.md","name":"git-gateway","frontmatter":{"title":"Git Bash","subtitle":"understanding git bash","date":"2021-09-02","thumb_image_alt":"image of","excerpt":"At its core, Git is a set of command line utility programs that are designed to execute on a Unix style command-line environment. Modern operating systems like Linux and macOS both include built-in Unix command line terminals. This makes Linux and macOS complementary operating systems when working with Git. Microsoft Windows instead uses Windows command prompt, a non-Unix terminal environment.","seo":{"title":"Git Bash","description":"understanding git bash","robots":[],"extra":[]},"template":"post","thumb_image":"images/git-banner.png"},"html":"<h1>Understanding Git Bash</h1>\n<h1>Git Bash</h1>\n<p>At its core, Git is a set of command line utility programs that are designed to execute on a Unix style command-line environment. Modern operating systems like Linux and macOS both include built-in Unix command line terminals. This makes Linux and macOS complementary operating systems when working with Git. Microsoft Windows instead uses Windows command prompt, a non-Unix terminal environment.</p>\n<p>In Windows environments, Git is often packaged as part of higher level GUI applications. GUIs for Git may attempt to abstract and hide the underlying version control system primitives. This can be a great aid for Git beginners to rapidly contribute to a project. Once a project's collaboration requirements grow with other team members, it is critical to be aware of how the actual raw Git methods work. This is when it can be beneficial to drop a GUI version for the command line tools. Git Bash is offered to provide a terminal Git experience.</p>\n<h2>What is Git Bash?</h2>\n<p>Git Bash is an application for Microsoft Windows environments which provides an emulation layer for a Git command line experience. Bash is an acronym for Bourne Again Shell. A shell is a terminal application used to interface with an operating system through written commands. Bash is a popular default shell on Linux and macOS. Git Bash is a package that installs Bash, some common bash utilities, and Git on a Windows operating system.</p>\n<h2>How to install Git Bash</h2>\n<p>Git Bash comes included as part of the <a href=\"https://gitforwindows.org/\">Git For Windows</a> package. Download and install Git For Windows like other Windows applications. Once downloaded find the included <code class=\"language-text\">.exe</code> file and open to execute Git Bash.</p>\n<h2>How to use Git Bash</h2>\n<p>Git Bash has the same operations as a standard Bash experience. It will be helpful to review basic Bash usage. Advanced usage of Bash is outside the scope of this Git focused document.</p>\n<h2>How to navigate folders</h2>\n<p>The Bash command <code class=\"language-text\">pwd</code> is used to print the 'present working directory'. <code class=\"language-text\">pwd</code> is equivalent to executing cd on a DOS(Windows console host) terminal. This is the folder or path that the current Bash session resides in.</p>\n<p>The Bash command <code class=\"language-text\">ls</code> is used to 'list' contents of the current working directory. <code class=\"language-text\">ls</code> is equivalent to <code class=\"language-text\">DIR</code> on a Windows console host terminal.</p>\n<p>Both Bash and Windows console host have a cd command. cd is an acronym for 'Change Directory'. cd is invoked with an appended directory name. Executing cd will change the terminal sessions current working directory to the passed directory argument.</p>\n<h2>Git Bash Commands</h2>\n<p>Git Bash is packaged with additional commands that can be found in the <code class=\"language-text\">/usr/bin</code> directory of the Git Bash emulation. Git Bash can actually provide a fairly robust shell experience on Windows. Git Bash comes packaged with the following shell commands which are outside the scope of this document: <code class=\"language-text\">[Ssh](https://man.openbsd.org/ssh.1)</code>, <code class=\"language-text\">[scp](https://linux.die.net/man/1/scp)</code>, <code class=\"language-text\">[cat](https://man7.org/linux/man-pages/man1/cat.1.html)</code>, <code class=\"language-text\">[find](https://linux.die.net/man/1/find)</code>.</p>\n<p>In addition the previously discussed set of Bash commands, Git Bash includes the full set of Git core commands discussed through out this site. Learn more at the corresponding documentation pages for</p>"},{"url":"/blog/google-analytics/","relativePath":"blog/google-analytics.md","relativeDir":"blog","base":"google-analytics.md","name":"google-analytics","frontmatter":{"title":"google-analytics","template":"post","subtitle":"Page title and screen class","excerpt":"7 tips to become a better web developer","date":"2022-05-16T09:54:51.999Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-analytics.jpg?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-analytics.jpg?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/google.yaml"],"tags":["src/data/tags/cms.yaml","src/data/tags/resources.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/event-handeling.md","src/pages/blog/google-analytics.md"],"cmseditable":true},"html":"<table>\n<thead>\n<tr>\n<th><strong>Page title and screen class</strong></th>\n<th><strong>Views</strong></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong><em>7 tips to become a better web developer</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Awesome NodeJS</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Callstack Visualizer</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Cheat Sheets</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Clock</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Data Structures By Example</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>ExpressJS Apis</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>FAQ</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Gatsby Plugins For This Sites Content Model</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Git Cheatsheet</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>HTT{ Requests</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Jamstack</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>JavaScript Programming Language</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>List Of Projects</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Map and Set</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Node APIs With Express</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Palindrome Number</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>PostgreSQL Setup</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>README</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>RECENT PROJECTS</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>React</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>React Interview Questions &#x26; Answers</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Sitemap-April</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Ubuntu</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Web Design</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>1</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>npm</em></strong></td>\n<td><strong><em>1</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Archive</em></strong></td>\n<td><strong><em>2</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Developer Resources</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>2</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Heroku Error Codes</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>2</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Javascript Interview</em></strong></td>\n<td><strong><em>2</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Leetcode Practice</em></strong></td>\n<td><strong><em>2</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>NextJS</em></strong></td>\n<td><strong><em>2</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Python Functions</em></strong></td>\n<td><strong><em>2</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Queries and Mutations (Gatsby)</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>2</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>React Intro</em></strong></td>\n<td><strong><em>2</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Regex Tricks</em></strong></td>\n<td><strong><em>2</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Tips</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>2</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Data Structures Interview</em></strong></td>\n<td><strong><em>3</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Developer Community</em></strong></td>\n<td><strong><em>3</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Git and Github</em></strong></td>\n<td><strong><em>3</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Netlify CMS</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>3</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Overflow</em></strong></td>\n<td><strong><em>3</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>React State</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>3</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>readme</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>3</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>using the DOM</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>3</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Archive</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>4</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Audio Projects</em></strong></td>\n<td><strong><em>4</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Awesome Static Site Resources</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>4</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Bookmarks</em></strong></td>\n<td><strong><em>4</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>General structured data guidelines</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>4</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Learn Css</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>4</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>PSQl Cheat Sheet</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>4</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Platform Docs</em></strong></td>\n<td><strong><em>4</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Python General Notes</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>4</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Python Practice</em></strong></td>\n<td><strong><em>4</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>npx-create-react-app</em></strong></td>\n<td><strong><em>4</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>python</em></strong></td>\n<td><strong><em>4</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Blog Archive</em></strong></td>\n<td><strong><em>5</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Contact!</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>5</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Interactive Examples</em></strong></td>\n<td><strong><em>5</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Netlify CMS Reference Sheet</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>5</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Big-O Notation</em></strong></td>\n<td><strong><em>6</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Job Hunt</em></strong></td>\n<td><strong><em>6</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Projects</em></strong></td>\n<td><strong><em>6</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Reference</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>6</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Manage Content</em></strong></td>\n<td><strong><em>7</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Passing Arguments To A Callback In JS</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>7</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>CSS</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>8</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Documentation</em></strong></td>\n<td><strong><em>8</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Node vs Browser</em></strong></td>\n<td><strong><em>8</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Sitemap</em></strong></td>\n<td><strong><em>8</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Articles</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>9</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Showcase</em></strong></td>\n<td><strong><em>9</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Tutorials</em></strong></td>\n<td><strong><em>11</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>lorem-ipsum</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>14</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>How To Reinstall NPM and Node.js On Your System</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>15</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Dynamic Time Warping Algorithm Explained (Python)</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>16</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Job Board</em></strong></td>\n<td><strong><em>webdevhub</em></strong></td>\n<td><strong><em>16</em></strong></td>\n</tr>\n<tr>\n<td><strong><em>Data Structures</em></strong></td>\n<td><strong><em>17</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>About</em></strong></td>\n<td><strong><em>18</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Tools</em></strong></td>\n<td><strong><em>41</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Web Dev Hub</em></strong></td>\n<td><strong><em>42</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Blog</em></strong></td>\n<td><strong><em>43</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Content Manager</em></strong></td>\n<td><strong><em>99</em></strong></td>\n<td></td>\n</tr>\n<tr>\n<td><strong><em>Web-Dev-Hub</em></strong></td>\n<td><strong><em>553</em></strong></td>\n<td></td>\n</tr>\n</tbody>\n</table>"},{"url":"/blog/google-custom-search/","relativePath":"blog/google-custom-search.md","relativeDir":"blog","base":"google-custom-search.md","name":"google-custom-search","frontmatter":{"title":"Google Custom Search","template":"post","subtitle":"Google search","excerpt":"Google","date":"2022-06-06T20:55:39.767Z","image":"https://media.geeksforgeeks.org/wp-content/uploads/20200509200015/output.png","thumb_image":"https://media.geeksforgeeks.org/wp-content/uploads/20200509200015/output.png","image_position":"right","author":"src/data/authors/backup.yaml","show_author_bio":true,"cmseditable":true},"html":"<h1>Adding Google Custom Search to your Website | Solodev</h1>\n<blockquote>\n<p>If you're Looking to Add Search Functionality to your Website, Learn How to Harness the Power of Google to Create Custom Searches</p>\n</blockquote>\n<p><strong><em>Implementing Google Custom Search is as easy as registering your website with Google and letting our code do the rest. This article provides the code and styles you need to implement custom search on your website. Enjoy!</em></strong></p>\n<p>It's imperative your users have a reliable and easy method for finding your content. What better way to achieve this than including search powered by Google? But simply adding the default code provided by Google leaves your site's search lacking. While the functionality is there, the professional styling expected on websites today is notably absent. The tutorial below solves this dilemma, merging the powerful functionality of Google Custom Search with a sleekdesign.</p>\n<p>In <a href=\"https://www.solodev.com/\">Solodev</a>, implementing Google Custom Search is as easy as registering your website with Google and adding a shortcode. For other websites, we've included a pure HTML tutorial which is CMS neutral and will work on websites of all varieties.</p>\n<p>Below is all the code you need to implement custom search on your website.</p>\n<h2><a href=\"https://github.localhost/#step-1\"></a>Step 1</h2>\n<p>Copy and paste the HTML or Solodev Shortcode where you would like your search form to populate and <a href=\"https://cse.google.com/\">register your website with Google</a>.</p>\n<ul>\n<li><a href=\"https://github.localhost/#code1\">HTML</a></li>\n<li><a href=\"https://github.localhost/#code2\">Solodev Shortcode</a></li>\n</ul>\n<hr>\n<h2><a href=\"https://github.localhost/#step-2\"></a>Step 2</h2>\n<p>Download the JavaScript below and include it in your web page.</p>\n<p>google-custom-search.js</p>\n<hr>\n<h2><a href=\"https://github.localhost/#step-3---includes\"></a>Step 3 - Includes</h2>\n<p>Include the following JavaScript in your HTML document.</p>\n<hr>\n<h2><a href=\"https://github.localhost/#step-4---google-custom-search\"></a>Step 4 - Google Custom Search</h2>\n<p>Download the CSS below and include it in your web page</p>\n<p>google-custom-search.css</p>\n<hr>\n<h2><a href=\"https://github.localhost/#step-5---includes\"></a>Step 5 - Includes</h2>\n<p>Add the following includes to the header of your HTML file (or Solodev Shortcode Repeater file).</p>\n<h2><a href=\"https://github.localhost/#an-example-of-a-search-results-page-which-will-appear-via-ajax-is-shown-below\"></a>An example of a search results page, which will appear via AJAX, is shown below.</h2>\n<p><a href=\"\"><img src=\"\" alt=\"Search Page Example\"></a></p>\n<p>With just a few lines of code you have provided site visitors the ability to search your entire site using the power of Google (and the help of Solodev) - Enjoy!</p>\n<p><a href=\"https://www.solodev.com/blog/web-design/adding-google-custom-search-to-your-website.stml\">Source</a></p>"},{"url":"/blog/hoisting/","relativePath":"blog/hoisting.md","relativeDir":"blog","base":"hoisting.md","name":"hoisting","frontmatter":{"title":"Git Bash","subtitle":"understanding git bash","date":"2021-09-02","thumb_image_alt":"image of","excerpt":null,"seo":{"title":"Git Bash","description":"understanding git bash","robots":[],"extra":[]},"template":"post","thumb_image":"images/https://www.tutorialsteacher.com/Content/images/js/hoisting.png"},"html":"<p>Understanding <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#var_hoisting\">hoisting</a> will help you organize your function scope. Just remember, variable declarations and function definitions are hoisted to the top. Variable definitions are not, even if you declare and define a variable on the same line. Also, a variable <strong>declaration</strong> lets the system know that the variable exists while <strong>definition</strong> assigns it a value.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">doTheThing</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ReferenceError: notDeclared is not defined</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>notDeclared<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Outputs: undefined</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>definedLater<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> definedLater<span class=\"token punctuation\">;</span>\n\n    definedLater <span class=\"token operator\">=</span> <span class=\"token string\">'I am defined!'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Outputs: 'I am defined!'</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>definedLater<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Outputs: undefined</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>definedSimulateneously<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> definedSimulateneously <span class=\"token operator\">=</span> <span class=\"token string\">'I am defined!'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Outputs: 'I am defined!'</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>definedSimulateneously<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Outputs: 'I did it!'</span>\n    <span class=\"token function\">doSomethingElse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">doSomethingElse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I did it!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// TypeError: undefined is not a function</span>\n    <span class=\"token function\">functionVar</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">functionVar</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I did it!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To make things easier to read, declare all of your variables at the top of your function scope so it is clear which scope the variables are coming from. Define your variables before you need to use them. Define your functions at the bottom of your scope to keep them out of your way.</p>"},{"url":"/blog/htt-requests/","relativePath":"blog/htt-requests.md","relativeDir":"blog","base":"htt-requests.md","name":"htt-requests","frontmatter":{"title":"HTTP Requests","template":"post","subtitle":"What is HTTP","excerpt":"HTTP is a protocol, or a definite set of rules, for accessing resources on the web.","date":"2022-04-20T06:40:21.724Z","image":"https://imgs.search.brave.com/kExsXbNFftb4VTNT_HgQPhZoB3XYYEedZSJTB-Sqhk4/rs:fit:1200:622:1/g:ce/aHR0cDovL2J5dGVz/b2ZnaWdhYnl0ZXMu/Y29tL0lNQUdFUy9O/ZXR3b3JraW5nL0hU/VFBjb21tdW5jYXRp/b24vaHR0cCUyMGNv/bW11bmljYXRpb24u/cG5n","thumb_image":"https://imgs.search.brave.com/kExsXbNFftb4VTNT_HgQPhZoB3XYYEedZSJTB-Sqhk4/rs:fit:1200:622:1/g:ce/aHR0cDovL2J5dGVz/b2ZnaWdhYnl0ZXMu/Y29tL0lNQUdFUy9O/ZXR3b3JraW5nL0hU/VFBjb21tdW5jYXRp/b24vaHR0cCUyMGNv/bW11bmljYXRpb24u/cG5n","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/html.yaml","src/data/categories/google.yaml","src/data/categories/git.yaml"],"tags":["src/data/tags/links.yaml","src/data/tags/resources.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/using-the-dom.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h2>What is HTTP?</h2>\n<p>HTTP is a protocol, or a definite set of rules, for accessing resources on the web. Resources could mean anything from HTML files to data from a database, photos, text, and so on.</p>\n<p>These resources are made available to us via an <code class=\"language-text\">API</code> and we make requests to these APIs via the HTTP protocol. <code class=\"language-text\">API</code> stands for application programming interface. It is the mechanism that allows developers to request resources.</p>\n<h3>Client-Server Architecture</h3>\n<p>In order to understand the HTTP methods, it’s important to cover the concept of client/server architecture. This architecture describes how all web applications work and defines the rules for how they communicate.</p>\n<p>A client application is the one that a user is actually interacting with, that's displaying the content. A server application is the one that sends the content, or resource, to your client application. A server application is a program that is running somewhere, listening, and waiting for a request.</p>\n<p>The main reason for this separation is to secure sensitive information. Your entire client application gets downloaded into the browser, and all of the data can be accessed by anyone accessing your web page.</p>\n<p>This architecture helps protect things like your API keys, personal data, and more. Now modern tools like <a href=\"https://nextjs.org/\">Next.js</a> and <a href=\"https://www.netlify.com/\">Netlify</a> allow developers to run server code in the same app as their client app, without needing a dedicated server application.</p>\n<h3>Client-Server Communication</h3>\n<p>Client and server applications communicate by sending individual messages on an as-needed basis, rather than an ongoing stream of communication.</p>\n<p>These communications are almost always initiated by clients in the form of requests. These requests are fulfilled by the server application which sends back a response containing the resource you requested, among other things.</p>\n<h3>Why We Need A Server-Client Architecture</h3>\n<p>Let’s say you were building a weather web app, for example. The weather app that your user is going to interact with is the client application – it has buttons, a search bar, and displays data like city name, current temperature, AQI, and so on.</p>\n<p>This weather app wouldn’t have every city and its weather information coded directly into it. This would make the app bloated and slow, would take forever to research and manually add to a database, and would be a headache to update every single day.</p>\n<p>Instead, the app can access weather data by city using the Weather web API. Your app would gather your user’s location and then make a request to the server saying, “Hey, send me the weather information for this specific city.”</p>\n<p>Depending on what you are trying to achieve, you would use the various request methods that are available. The server sends back a response containing the weather information and a few other things, depending on how the API is written. It may also send back things like a timestamp, the region this city is located in, and more.</p>\n<p>Your client application communicated with a server application running somewhere, whose only job is to listen continuously for a request to that address. When it receives a request, it works to fulfill that request either by reading from a database, another API, local file, or a programmatic calculation based on data you pass in.</p>\n<h3>The Anatomy of an HTTP Request</h3>\n<p>An HTTP request must have the following:</p>\n<ul>\n<li>An HTTP method (like <code class=\"language-text\">GET</code>)</li>\n<li>A host URL (like <code class=\"language-text\">https://api.spotify.com/</code>)</li>\n<li>An endpoint path(like <code class=\"language-text\">v1/artists/{id}/related-artists</code>)</li>\n</ul>\n<p>A request can also optionally have:</p>\n<ul>\n<li>Body</li>\n<li>Headers</li>\n<li>Query strings</li>\n<li>HTTP version</li>\n</ul>\n<h3>The Anatomy of an HTTP Response</h3>\n<p>A response must have the following:</p>\n<ul>\n<li>Protocol version (like <code class=\"language-text\">HTTP/1.1</code>)</li>\n<li>Status code (like <code class=\"language-text\">200</code>)</li>\n<li>Status text (<code class=\"language-text\">OK</code>)</li>\n<li>Headers</li>\n</ul>\n<p>A response may also optionally have:</p>\n<ul>\n<li>Body</li>\n</ul>\n<h2>HTTP Methods Explained</h2>\n<p><a href=\"https://platform.twitter.com/embed/Tweet.html?creatorScreenName=camiinthisthang&#x26;dnt=false&#x26;embedId=twitter-widget-0&#x26;features=eyJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3NwYWNlX2NhcmQiOnsiYnVja2V0Ijoib2ZmIiwidmVyc2lvbiI6bnVsbH19&#x26;frame=false&#x26;hideCard=false&#x26;hideThread=false&#x26;id=1195350262145306624&#x26;lang=en&#x26;origin=https%3A%2F%2Fwww.freecodecamp.org%2Fnews%2Fhttp-request-methods-explained%2F&#x26;sessionId=a9192d5918ed5d41ccd0f351fa6e3fff5a8333ab&#x26;siteScreenName=freecodecamp&#x26;theme=light&#x26;widgetsVersion=c8fe9736dd6fb%3A1649830956492&#x26;width=550px\">Twitter Tweet</a></p>\n<p>Now that we know what HTTP is and why it’s used, let’s talk about the different methods we have available to us.</p>\n<p>In the weather app example above, we wanted to retrieve weather information about a city. But what if we wanted to submit weather information for a city?</p>\n<p>In real life, you probably wouldn’t have permissions to alter someone else’s data, but let’s imagine that we are contributors to a community-run weather app. And in addition to getting the weather information from an API, members in that city could update this information to display more accurate data.</p>\n<p>Or what if we wanted to add a new city altogether that, for some reason, doesn’t already exist in our database of cities? These are all different functions – retrieve data, update data, create new data – and there are HTTP methods for all of these.</p>\n<h3>HTTP POST request</h3>\n<p>We use <code class=\"language-text\">POST</code> to create a new resource. A <code class=\"language-text\">POST</code> request requires a body in which you define the data of the entity to be created.</p>\n<p>A successful POST request would be a 200 response code. In our weather app, we could use a POST method to add weather data about a new city.</p>\n<h3>HTTP GET request</h3>\n<p>We use <code class=\"language-text\">GET</code> to read or retrieve a resource. A successful <code class=\"language-text\">GET</code> returns a response containing the information you requested.</p>\n<p>In our weather app, we could use a GET to retrieve the current weather for a specific city.</p>\n<h3>HTTP PUT request</h3>\n<p>We use <code class=\"language-text\">PUT</code> to modify a resource. <code class=\"language-text\">PUT</code> updates the entire resource with data that is passed in the body payload. If there is no resource that matches the request, it will create a new resource.</p>\n<p>In our weather app, we could use <code class=\"language-text\">PUT</code> to update all weather data about a specific city.</p>\n<h3>HTTP PATCH request</h3>\n<p>We use <code class=\"language-text\">PATCH</code> to modify a part of a resource. With <code class=\"language-text\">PATCH</code>, you only need to pass in the data that you want to update.</p>\n<p>In our weather app, we could use <code class=\"language-text\">PATCH</code> to update the rainfall for a specified day in a specified city.</p>\n<h3>HTTP DELETE request</h3>\n<p>We use <code class=\"language-text\">DELETE</code> to delete a resource. In our weather app, we could use <code class=\"language-text\">DELETE</code> to delete a city we no longer wanted to track for some reason.</p>\n<h2>HTTP Method FAQs</h2>\n<h3>What’s the difference between PUT and POST?</h3>\n<p><code class=\"language-text\">PUT</code> requests are idempotent, meaning that executing the same <code class=\"language-text\">PUT</code> request will always produce the same result.</p>\n<p>On the other hand, a <code class=\"language-text\">POST</code> will produce different outcomes. If you execute a <code class=\"language-text\">POST</code> request multiple times, you'll create a new resource multiple times despite them having the same data being passed in.</p>\n<p>Using a restaurant analogy, <code class=\"language-text\">POST</code>ing multiple times would create multiple separate orders, whereas multiple <code class=\"language-text\">PUT</code> requests will update the same existing order.</p>\n<h3>What’s the difference between PUT and PATCH?</h3>\n<p>The key differences are that <code class=\"language-text\">PUT</code> will create a new resource if it cannot find the specified resource. And with <code class=\"language-text\">PUT</code> you need to pass in data to update the entire resource, even if you only want to modify one field.</p>\n<p>With <code class=\"language-text\">PATCH</code>, you can update part of a resource by simply passing in the data of the field to be updated.</p>\n<h3>What if I just want to update part of my resource? Can I still use PUT?</h3>\n<p>If you just want to update part of your resource, you still need to send in data for the entire resource when you make a <code class=\"language-text\">PUT</code> request. The better-suited option here would be <code class=\"language-text\">PATCH</code>.</p>\n<h3>Why is a body optional for a request and response?</h3>\n<p>A body is optional because for some requests, like resource retrievals using the <code class=\"language-text\">GET</code> method, there is nothing to specify in the body of your request. You are requesting all data from the specified endpoint.</p>\n<p>Similarly, a body is optional for some responses when a status code is sufficient or there is nothing to specify in the body, for example with a <code class=\"language-text\">DELETE</code> operation.</p>\n<h2>HTTP Request Examples</h2>\n<p>Now that we’ve covered what an HTTP request is, and why we use them, let’s make some requests! We’re going to be playing with the <a href=\"https://docs.github.com/en/rest/reference/gists\">GitHub Gist API</a>.</p>\n<blockquote>\n<p>\"Gist is a simple way to share snippets and pastes with others. All Gists are Git repositories, so they are automatically versioned, forkable and usable from Git.\" (Source: Github)</p>\n</blockquote>\n<p>You will need a GitHub account for this. If you don’t already have one, this is a great opportunity to start one to save your code in the future.</p>\n<p>Every user on GitHub can create gists, retrieve their gists, retrieve all public gists, delete a gist, and update a gist, amongst other things. To keep things simple we will use <a href=\"https://hoppscotch.io/\">Hoppscotch</a>, a platform with a nice interface used to quickly and easily make HTTP requests.</p>\n<p>A quick Hoppscotch walkthrough:</p>\n<ul>\n<li>There is a drop down menu where you can select the method you want to create a request with.</li>\n<li>There is a text box where you should paste the URL of of the API endpoint you want to access.</li>\n</ul>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-12.35.33-PM.png\" alt=\"Screen-Shot-2022-01-24-at-12.35.33-PM\"></p>\n<ul>\n<li>There is a Headers section where we will be passing in headers as instructed by the GitHub docs.</li>\n</ul>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-12.39.38-PM-1.png\" alt=\"Screen-Shot-2022-01-24-at-12.39.38-PM-1\"></p>\n<ul>\n<li>There is a body area where we will pass in content to our body as instructed by the GitHub docs.</li>\n</ul>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-12.41.14-PM.png\" alt=\"Screen-Shot-2022-01-24-at-12.41.14-PM\"></p>\n<ul>\n<li>The right column will quickly let you know if your request was successful. If it is green, you successfully made your request, and if it's red there was an error.</li>\n</ul>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-3.44.56-PM.png\" alt=\"Screen-Shot-2022-01-24-at-3.44.56-PM\"></p>\n<h3>How to Make a GET Request</h3>\n<p>To make a <code class=\"language-text\">GET</code> request to retrieve all of a specific users’ gists, we can use the following method and endpoint: <code class=\"language-text\">GET /users/{username}/gists</code>. The documentation tells us the parameters that we can pass in to make this request.</p>\n<p>We see that in the path we have to pass in a string with the target user’s username. We also see that we have to pass in a header called accept and set it to <code class=\"language-text\">application/vnd.github.v3+json</code>.</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-20-at-2.01.35-PM.png\" alt=\"Screen-Shot-2022-01-20-at-2.01.35-PM\"></p>\n<p>We're given the URL for this API:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<p>We're given the endpoint path for this specific operation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To make this request:</p>\n<ol>\n<li>Paste in the full URL + path in the input field of Hoppscotch. Be sure to replace <code class=\"language-text\">username</code> with an actual username. If you don't have a GitHub with existing Gists, you can use mine: camiinthisthang.</li>\n<li>Select the <code class=\"language-text\">GET</code> request method</li>\n<li>In the Headers tab, set accept as a header and set the value to <code class=\"language-text\">application/vnd.github.v3+json</code></li>\n</ol>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-12.39.38-PM-2.png\" alt=\"Screen-Shot-2022-01-24-at-12.39.38-PM-2\"></p>\n<ol start=\"4\">\n<li>Hit send!</li>\n</ol>\n<p>At the bottom, you'll see your response formatted as <code class=\"language-text\">JSON</code>. In order to read this more clearly, copy the response and paste it into an <a href=\"https://jsonformatter.curiousconcept.com/#\">online JSON formatter</a>.</p>\n<p>In the formatter, you're able to tell that the response is an array of objects. Each object represents one gist, showing us information like the URL, the ID, etc.</p>\n<h3>How to Make a POST Request</h3>\n<p>Now let's create a resource using the <code class=\"language-text\">POST</code> method. In this context, the new resource would be a new gist.</p>\n<p>First we’ll have to create a personal access token. To do that, <a href=\"https://github.com/settings/tokens\">go to your settings page</a> and hit Generate token.</p>\n<p>Name your token and select the scope “Create Gists”:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-20-at-2.59.11-PM.png\" alt=\"Screen-Shot-2022-01-20-at-2.59.11-PM\"></p>\n<p>Then click the green <code class=\"language-text\">Generate token</code> button at the bottom of the page.</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-20-at-3.28.01-PM.png\" alt=\"Screen-Shot-2022-01-20-at-3.28.01-PM\"></p>\n<p>Copy your access code and paste it somewhere you can easily retrieve it.</p>\n<p>Now we're ready to make our request! The documentation tells us we should pass in a header, and a <code class=\"language-text\">files</code> object in the body. We can optionally pass in a few other things, including a boolean that dictates if this gist is public or private.</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-20-at-2.07.23-PM.png\" alt=\"Screen-Shot-2022-01-20-at-2.07.23-PM\"></p>\n<p>We're given the URL for this API:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<p>We're given the endpoint path for this specific operation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To make this request:</p>\n<ol>\n<li>Paste the full URL + path into the input field of Hoppscotch.</li>\n<li>Select the <code class=\"language-text\">POST</code> request method</li>\n<li>In the Headers tab, set accept as a header and set the value to <code class=\"language-text\">application/vnd.github.v3+json</code></li>\n<li>In the Body tab, set the content type to <code class=\"language-text\">application/json</code>. Then start off with an object <code class=\"language-text\">{}</code>.<br>\n<br>\nInside of this object, we'll set the public <code class=\"language-text\">boolean</code> to <code class=\"language-text\">true</code>. Then we'll define the property <code class=\"language-text\">files</code>, and the value is another object with a key of the name of your new gist. The value for this should be another object whose key is <code class=\"language-text\">content</code>. The value here should be whatever you want to actually add to the gist.<br>\n<br>\nHere is the code for you to copy/paste:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"></code></pre></div>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-2.35.57-PM.png\" alt=\"Screen-Shot-2022-01-24-at-2.35.57-PM\"></p>\n<ol start=\"5\">\n<li>In the Authorization tab, set the authorization type to <code class=\"language-text\">Basic Auth</code>. Type in your Github username and pass your personal access token we created in the password field.</li>\n</ol>\n<p>After we run this, we get a long response. An easy way to check that your gist was created is to go to your Gists in GitHub.</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-2.39.27-PM.png\" alt=\"Screen-Shot-2022-01-24-at-2.39.27-PM\"></p>\n<p>We see that we successfully added a Gist!</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-2.39.58-PM.png\" alt=\"Screen-Shot-2022-01-24-at-2.39.58-PM\"></p>\n<h3>How to Make a PATCH Request</h3>\n<p>Let's update the title and description of the Gist we just created. Remember: <code class=\"language-text\">PATCH</code> allows you to update a part of a resource, not the entire resource. Anything that we don’t pass in will remain unchanged.</p>\n<p>We didn’t actually pass a description to our Gist when we created it, so we can patch this and create one.</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-20-at-3.35.56-PM.png\" alt=\"Screen-Shot-2022-01-20-at-3.35.56-PM\"></p>\n<p>We're given the URL for this API:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<p>We're given the endpoint path for this specific operation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To make this request:</p>\n<ol>\n<li>Paste in the full URL + path in the input field of Hoppscotch. Get the <code class=\"language-text\">Gist ID</code> of the gist you want to update. You can find the ID by going to the Gist in GitHub and copying the alphanumeric string at the end of the URL.</li>\n</ol>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-20-at-3.50.13-PM.png\" alt=\"Screen-Shot-2022-01-20-at-3.50.13-PM\"></p>\n<ol start=\"2\">\n<li>Select the <code class=\"language-text\">PATCH</code> request method.</li>\n<li>In the Headers tab, set accept as a header and set the value to <code class=\"language-text\">application/vnd.github.v3+json</code>.</li>\n<li>In the Authorization tab, set the authorization type to <code class=\"language-text\">Basic Auth</code>. Type in your GitHub username and pass your personal access token we created in the password field.</li>\n<li>In the Body tab, we'll pass in the updated description and title. Here is the code:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"></code></pre></div>\n<p>If we refresh our Gist, we see that we have an updated title and description!</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-3.38.35-PM.png\" alt=\"Screen-Shot-2022-01-24-at-3.38.35-PM\"></p>\n<h3>How to Make a DELTE Request</h3>\n<p>Let's delete the Gist we created. We should pass in the header and the Gist ID.</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-24-at-3.42.30-PM.png\" alt=\"Screen-Shot-2022-01-24-at-3.42.30-PM\"></p>\n<p>We're given the URL for this API:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<p>We're given the endpoint path for this specific operation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To make this request:</p>\n<ol>\n<li>Paste in the full URL + path in the input field of Hoppscotch. Get the <code class=\"language-text\">Gist ID</code> of the gist you want to update. You can find the ID by going to the Gist in GitHub and copying the alphanumeric string at the end of the URL.</li>\n</ol>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2022-01-20-at-3.50.13-PM.png\" alt=\"Screen-Shot-2022-01-20-at-3.50.13-PM\"></p>\n<ol start=\"2\">\n<li>Select the <code class=\"language-text\">DELETE</code> request method</li>\n<li>In the Headers tab, set accept as a header and set the value to <code class=\"language-text\">application/vnd.github.v3+json</code>.</li>\n</ol>\n<p>If we navigate to our Gists, we see that this one doesn't exist and we successfully deleted the resource.</p>\n<!--EndFragment-->"},{"url":"/blog/grep-in-linuz/","relativePath":"blog/grep-in-linuz.md","relativeDir":"blog","base":"grep-in-linuz.md","name":"grep-in-linuz","frontmatter":{"title":"Grep In Linuz","template":"post","subtitle":"command line utility for printing lines that match a pattern","excerpt":"command line utility for printing lines that match a pattern","date":"2022-04-19T06:21:57.572Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux.png?raw=true","image_position":"left","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/tools.yaml"],"tags":["src/data/tags/linux.yaml"],"show_author_bio":true,"cmseditable":true},"html":"<h2>What is the grep command in UNIX?</h2>\n<p>The <code class=\"language-text\">grep</code> command in UNIX is a command line utility for printing lines that match a pattern. It can be used to find text in a file and search a directory structure of files recursively. It also supports showing the context of a match by showing lines before and after the result and has support for regular expressions in pattern matching.</p>\n<h2>How to find text in a file</h2>\n<p>To find text in a file pass the string you are looking for to <code class=\"language-text\">grep</code> followed by the name of the file or files.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep 'computer' /usr/share/dict/words\ncomputer</code></pre></div>\n<p>The <code class=\"language-text\">grep</code> tool will print occurrences that it finds to standard output.</p>\n<h2>How to list line numbers for matches</h2>\n<p>To list line numbers and file names pass the <code class=\"language-text\">-n</code> option to grep. This prints matches to standard output along with the line number it was found on.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep 'computer' -n /usr/share/dict/words\n40565</code></pre></div>\n<p>This can be useful if you are looking to edit a file and want to launch vim and go straight to the line.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">vim +40565 /usr/share/dict/words</code></pre></div>\n<h2>How to print lines before and after a match</h2>\n<p>To print lines before and after a match the <code class=\"language-text\">-A</code> and <code class=\"language-text\">-B</code> options can be used. Both expect a number and will print this number of lines.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep -B 2 -A 2 'computer' /usr/share/dict/words\ncomputativeness\ncompute\ncomputer\ncomputist\ncomputus</code></pre></div>\n<p>Using the <code class=\"language-text\">-A</code> and <code class=\"language-text\">-B</code> options can be very useful for grepping through log files to see what occurred before and after the item of interest.</p>\n<p>A further option is available in <code class=\"language-text\">-C</code> that will print the context of the match. This is equivalent to using both <code class=\"language-text\">-A</code> and <code class=\"language-text\">-B</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep -C 2 'computer' /usr/share/dict/words\ncomputativeness\ncompute\ncomputer\ncomputist\ncomputus</code></pre></div>\n<p>The <code class=\"language-text\">--context</code> option may also be used and defaults to two lines before and after if no number is given.</p>\n<h2>How to count the number of matches</h2>\n<p>To count the number of matches use the <code class=\"language-text\">-c</code> option. This outputs a number count to standard output.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep -c 'comput*' /usr/share/dict/words\n50</code></pre></div>\n<h2>How to print the filename for a match</h2>\n<p>To print the filename for a match use the <code class=\"language-text\">-H</code> option. This is automatically invoked when <code class=\"language-text\">grep</code> is given more than one file to search.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep -H 'computer' /usr/share/dict/words\n/usr/share/dict/words:computer</code></pre></div>\n<h2>How to search recursively</h2>\n<p>To search for a pattern recursively use the <code class=\"language-text\">-R</code> option. This will search through all files in the directory tree that you have permission to read.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep -R 'passwd' /etc\n/etc/pam.d/su:# NIS (man nsswitch) as well as normal /etc/passwd and\n/etc/pam.d/chpasswd:# The PAM configuration file for the Shadow 'chpasswd' service</code></pre></div>\n<h2>How to search for the inverse of a pattern</h2>\n<p>To search for the inverse of a pattern use the <code class=\"language-text\">-v</code> option. This will print inverse matches to standard output.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep -v 'computer' /usr/share/dict/words\nA\na\naa\naal\n....</code></pre></div>\n<h2>How to ignore case when searching</h2>\n<p>To ignore case when searching use the <code class=\"language-text\">-i</code> option. By default <code class=\"language-text\">grep</code> will respect case.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep 'COMPUTER' /usr/share/dict/words\n# no match\ngrep -i 'COMPUTER' /usr/share/dict/words\ncomputer</code></pre></div>\n<h2>How to use basic regular expressions when searching</h2>\n<p>To use basic regular expressions all versions of <code class=\"language-text\">grep</code> support basic character matches. In the following example the pattern matches ‘ia’ characters at the end of the line.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep 'ia$' /usr/share/dict/words\nabasia\nAbelia\nabepithymia\n....</code></pre></div>\n<p>A great book for understanding the power of regular expressions is <a href=\"https://shop.oreilly.com/product/9780596528126.do\">Mastering Regular Expressions</a>.</p>\n<h2>How to use extended regular expressions when searching</h2>\n<p>To use extended regular expressions use the <code class=\"language-text\">-e</code> option. The following line matches lines that do not contain the words ‘foo’ or ‘bar’.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">grep -v -e 'foo' -e 'bar'</code></pre></div>"},{"url":"/blog/interview-questions-js-p3/","relativePath":"blog/interview-questions-js-p3.md","relativeDir":"blog","base":"interview-questions-js-p3.md","name":"interview-questions-js-p3","frontmatter":{"title":"JS-Questions P3","subtitle":"Javascript Interview Questions P3","date":"2021-09-11","thumb_image_alt":"big o","excerpt":"What are the possible ways to create objects in JavaScript","seo":{"title":"Javascript Interview","description":"What are the possible ways to create objects in JavaScript","robots":[],"extra":[{"name":"og:image","value":"images/js-code-spiral-num.png","keyName":"property","relativeUrl":true},{"name":"twitter:title","value":"JS-Interview","keyName":"name","relativeUrl":false},{"name":"twitter:description","value":"What are the possible ways to create objects in JavaScript","keyName":"name","relativeUrl":false}]},"template":"post","thumb_image":"images/bigo.jpg","image":"images/js-questions-n-answers.png"},"html":"<h4>45. What is the output of below code</h4>\n<hr>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1</li>\n<li>2: undefined</li>\n<li>3: SyntaxError</li>\n<li>4: TypeError</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>Generators are not constructible type. But if you still proceed to do, there will be an error saying \"TypeError: myGenFunc is not a constructor\"</p>\n</p>\n</details>\n<hr>\n<h4>46. What is the output of below code</h4>\n<hr>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{ value: 1, done: false }, { value: 2, done: true }, { value: undefined, done: true }</li>\n<li>2: { value: 1, done: false }, { value: 2, done: false }, { value: undefined, done: true }</li>\n<li>3: { value: 1, done: false }, { value: 2, done: true }, { value: 3, done: true }</li>\n<li>4: { value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>A return statement in a generator function will make the generator finish. If a value is returned, it will be set as the value property of the object and done property to true. When a generator is finished, subsequent next() calls return an object of this form: <code class=\"language-text\">{value: undefined, done: true}</code>.</p>\n</p>\n</details>\n<hr>\n<h4>47. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> myGenerator <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>1,2,3 and 1,2,3</li>\n<li>2: 1,2,3 and 4,5,6</li>\n<li>3: 1 and 1</li>\n<li>4: 1</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The generator should not be re-used once the iterator is closed. i.e, Upon exiting a loop(on completion or using break &#x26; return), the generator is closed and trying to iterate over it again does not yield any more results. Hence, the second loop doesn't print any value.</p>\n</p>\n</details>\n<hr>\n<h4>48. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> num <span class=\"token operator\">=</span> 0o38<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: 38</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>If you use an invalid number(outside of 0-7 range) in the octal literal, JavaScript will throw a SyntaxError. In ES5, it treats the octal literal as a decimal number.</p>\n</p>\n</details>\n<hr>\n<h4>49. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> squareObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Square</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>squareObj<span class=\"token punctuation\">.</span>area<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Square</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">length</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">get</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">set</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>area <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>1: 100</li>\n<li>2: ReferenceError</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Unlike function declarations, class declarations are not hoisted. i.e, First You need to declare your class and then access it, otherwise it will throw a ReferenceError \"Uncaught ReferenceError: Square is not defined\".\n<strong>Note:</strong> Class expressions also applies to the same hoisting restrictions of class declarations.</p>\n</p>\n</details>\n<hr>\n<h4>50. What is the output of below code</h4>\n<hr>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">walk</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nPerson<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">run</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> walk <span class=\"token operator\">=</span> user<span class=\"token punctuation\">.</span>walk<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> run <span class=\"token operator\">=</span> Person<span class=\"token punctuation\">.</span>run<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined, undefined</li>\n<li>2: Person, Person</li>\n<li>3: SyntaxError</li>\n<li>4: Window, Window</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>When a regular or prototype method is called without a value for <strong>this</strong>, the methods return an initial this value if the value is not undefined. Otherwise global window object will be returned. In our case, the initial <code class=\"language-text\">this</code> value is undefined so both methods return window objects.</p>\n</p>\n</details>\n<hr>\n<h4>51. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> vehicle started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Car</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> car started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'BMW'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: BMW vehicle started, BMW car started</li>\n<li>3: BMW car started, BMW vehicle started</li>\n<li>4: BMW car started, BMW car started</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The super keyword is used to call methods of a superclass. Unlike other languages the super invocation doesn't need to be a first statement. i.e, The statements will be executed in the same order of code.</p>\n</p>\n</details>\n<hr>\n<h4>52. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token constant\">USER</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">25</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30</li>\n<li>2: 25</li>\n<li>3: Uncaught TypeError</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Even though we used constant variables, the content of it is an object and the object's contents (e.g properties) can be altered. Hence, the change is going to be valid in this case.</p>\n</p>\n</details>\n<hr>\n<h4>53. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🙂'</span> <span class=\"token operator\">===</span> <span class=\"token string\">'🙂'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Emojis are unicodes and the unicode for smile symbol is \"U+1F642\". The unicode comparision of same emojies is equivalent to string comparison. Hence, the output is always true.</p>\n</p>\n</details>\n<hr>\n<h4>54. What is the output of below code?</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>string</li>\n<li>2: boolean</li>\n<li>3: NaN</li>\n<li>4: number</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The typeof operator on any primitive returns a string value. So even if you apply the chain of typeof operators on the return value, it is always string.</p>\n</p>\n</details>\n<hr>\n<h4>55. What is the output of below code?</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">let</span> zero <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>zero<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'If'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Else'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>If</li>\n<li>2: Else</li>\n<li>3: NaN</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 1</h5>\n<ol>\n<li>The type of operator on new Number always returns object. i.e, typeof new Number(0) --> object.</li>\n<li>\n<p>Objects are always truthy in if block\nHence the above code block always goes to if section.</p>\n</p>\n</details>\n</li>\n</ol>\n<hr>\n<h4>55. What is the output of below code in non strict mode?</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">let</span> msg <span class=\"token operator\">=</span> <span class=\"token string\">'Good morning!!'</span><span class=\"token punctuation\">;</span>\nmsg<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>msg<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>\"\"</li>\n<li>2: Error</li>\n<li>3: John</li>\n<li>4: Undefined</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It returns undefined for non-strict mode and returns Error for strict mode. In non-strict mode, the wrapper object is going to be created and get the mentioned property. But the object get disappeared after accessing the property in next line.</p>\n</p>\n</details>\n<hr>\n<h4>56. What is the output of below code?</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">innerFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">===</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">11</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>11, 10</li>\n<li>2: 11, 11</li>\n<li>3: 10, 11</li>\n<li>4: 10, 10</li>\n</ul>\n<details>\n<summary>Answer</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>11 and 10 is logged to the console.\nThe innerFunc is a closure which captures the count variable from the outerscope. i.e, 10. But the conditional has another local variable <code class=\"language-text\">count</code> which overwrites the ourter <code class=\"language-text\">count</code> variable. So the first console.log displays value 11.\nWhereas the second console.log logs 10 by capturing the count variable from outerscope.</p>\n</p>\n</details>\n<hr>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>"},{"url":"/blog/","relativePath":"blog/index.md","relativeDir":"blog","base":"index.md","name":"index","frontmatter":{"title":"Blog","subtitle":"Exclusive Blog Content","image":"images/maroon-onion.gif","has_more_link":true,"more_link_text":"Read more","seo":{"title":"Blog","description":"These are blog posts... not nescisarily different from the docs section except these pieces are more subject to my own opinions.","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Blog","keyName":"property"},{"name":"og:description","value":"This is the blog page","keyName":"property"},{"name":"og:image","value":"images/5.jpg","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"Blog"},{"name":"twitter:description","value":"This is the blog page"},{"name":"twitter:image","value":"images/5.jpg","relativeUrl":true}]},"template":"blog"},"html":""},{"url":"/blog/jsx-in-depth/","relativePath":"blog/jsx-in-depth.md","relativeDir":"blog","base":"jsx-in-depth.md","name":"jsx-in-depth","frontmatter":{"title":"JSX In Depth","template":"post","subtitle":"Fundamentally, JSX just provides syntactic sugar for the React.createElement","excerpt":"Fundamentally, JSX just provides syntactic sugar for the React.createElement","date":"2022-05-29T00:03:22.427Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.gif?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.gif?raw=true","image_position":"top","author":"src/data/authors/im.yaml","categories":["src/data/categories/react.yaml"],"tags":["src/data/tags/react.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/10-essential-react-interview-questions.md","src/pages/blog/deploy-react-app-to-heroku.md","src/pages/blog/adding-css-to-your-html.md","src/pages/blog/react-fragments.md","src/pages/blog/react-semantics.md","src/pages/blog/react-state.md","src/pages/blog/passing-arguments-to-a-callback-in-js.md"],"cmseditable":true},"html":"<h1>JSX In Depth</h1>\n<p>Fundamentally, JSX just provides syntactic sugar for the <code class=\"language-text\">React.createElement(component, props, ...children)</code> function. The JSX code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyButton color=\"blue\" shadowSize={2}>\n  Click Me\n&lt;/MyButton></code></pre></div>\n<p>compiles into:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">React.createElement(\n  MyButton,\n  {color: 'blue', shadowSize: 2},\n  'Click Me'\n)</code></pre></div>\n<p>You can also use the self-closing form of the tag if there are no children. So:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div className=\"sidebar\" /></code></pre></div>\n<p>compiles into:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">React.createElement(\n  'div',\n  {className: 'sidebar'}\n)</code></pre></div>\n<p>If you want to test out how some specific JSX is converted into JavaScript, you can try out <a href=\"https://babeljs.io/repl/#?presets=react&#x26;code_lz=GYVwdgxgLglg9mABACwKYBt1wBQEpEDeAUIogE6pQhlIA8AJjAG4B8AEhlogO5xnr0AhLQD0jVgG4iAXyJA\">the online Babel compiler</a>.</p>\n<h2><a href=\"https://reactjs.org/docs/jsx-in-depth.html#specifying-the-react-element-type\"></a>Specifying The React Element Type</h2>\n<p>The first part of a JSX tag determines the type of the React element.</p>\n<p>Capitalized types indicate that the JSX tag is referring to a React component. These tags get compiled into a direct reference to the named variable, so if you use the JSX <code class=\"language-text\">&lt;Foo /></code> expression, <code class=\"language-text\">Foo</code> must be in scope.</p>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#react-must-be-in-scope\"></a>React Must Be in Scope</h3>\n<p>Since JSX compiles into calls to <code class=\"language-text\">React.createElement</code>, the <code class=\"language-text\">React</code> library must also always be in scope from your JSX code.</p>\n<p>For example, both of the imports are necessary in this code, even though <code class=\"language-text\">React</code> and <code class=\"language-text\">CustomButton</code> are not directly referenced from JavaScript:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react';import CustomButton from './CustomButton';\nfunction WarningButton() {\n  // return React.createElement(CustomButton, {color: 'red'}, null);  return &lt;CustomButton color=\"red\" />;\n}</code></pre></div>\n<p>If you don’t use a JavaScript bundler and loaded React from a <code class=\"language-text\">&lt;script></code> tag, it is already in scope as the <code class=\"language-text\">React</code> global.</p>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#using-dot-notation-for-jsx-type\"></a>Using Dot Notation for JSX Type</h3>\n<p>You can also refer to a React component using dot-notation from within JSX. This is convenient if you have a single module that exports many React components. For example, if <code class=\"language-text\">MyComponents.DatePicker</code> is a component, you can use it directly from JSX with:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react';\n\nconst MyComponents = {\n  DatePicker: function DatePicker(props) {\n    return &lt;div>Imagine a {props.color} datepicker here.&lt;/div>;\n  }\n}\n\nfunction BlueDatePicker() {\n  return &lt;MyComponents.DatePicker color=\"blue\" />;}</code></pre></div>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#user-defined-components-must-be-capitalized\"></a>User-Defined Components Must Be Capitalized</h3>\n<p>When an element type starts with a lowercase letter, it refers to a built-in component like <code class=\"language-text\">&lt;div></code> or <code class=\"language-text\">&lt;span></code> and results in a string <code class=\"language-text\">'div'</code> or <code class=\"language-text\">'span'</code> passed to <code class=\"language-text\">React.createElement</code>. Types that start with a capital letter like <code class=\"language-text\">&lt;Foo /></code> compile to <code class=\"language-text\">React.createElement(Foo)</code> and correspond to a component defined or imported in your JavaScript file.</p>\n<p>We recommend naming components with a capital letter. If you do have a component that starts with a lowercase letter, assign it to a capitalized variable before using it in JSX.</p>\n<p>For example, this code will not run as expected:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react';\n\n// Wrong! This is a component and should have been capitalized:function hello(props) {  // Correct! This use of &lt;div> is legitimate because div is a valid HTML tag:\n  return &lt;div>Hello {props.toWhat}&lt;/div>;\n}\n\nfunction HelloWorld() {\n  // Wrong! React thinks &lt;hello /> is an HTML tag because it's not capitalized:  return &lt;hello toWhat=\"World\" />;}</code></pre></div>\n<p>To fix this, we will rename <code class=\"language-text\">hello</code> to <code class=\"language-text\">Hello</code> and use <code class=\"language-text\">&lt;Hello /></code> when referring to it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react';\n\n// Correct! This is a component and should be capitalized:function Hello(props) {  // Correct! This use of &lt;div> is legitimate because div is a valid HTML tag:\n  return &lt;div>Hello {props.toWhat}&lt;/div>;\n}\n\nfunction HelloWorld() {\n  // Correct! React knows &lt;Hello /> is a component because it's capitalized.  return &lt;Hello toWhat=\"World\" />;}</code></pre></div>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#choosing-the-type-at-runtime\"></a>Choosing the Type at Runtime</h3>\n<p>You cannot use a general expression as the React element type. If you do want to use a general expression to indicate the type of the element, just assign it to a capitalized variable first. This often comes up when you want to render a different component based on a prop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react';\nimport { PhotoStory, VideoStory } from './stories';\n\nconst components = {\n  photo: PhotoStory,\n  video: VideoStory\n};\n\nfunction Story(props) {\n  // Wrong! JSX type can't be an expression.  return &lt;components[props.storyType] story={props.story} />;}</code></pre></div>\n<p>To fix this, we will assign the type to a capitalized variable first:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react';\nimport { PhotoStory, VideoStory } from './stories';\n\nconst components = {\n  photo: PhotoStory,\n  video: VideoStory\n};\n\nfunction Story(props) {\n  // Correct! JSX type can be a capitalized variable.  const SpecificStory = components[props.storyType];  return &lt;SpecificStory story={props.story} />;}</code></pre></div>\n<h2><a href=\"https://reactjs.org/docs/jsx-in-depth.html#props-in-jsx\"></a>Props in JSX</h2>\n<p>There are several different ways to specify props in JSX.</p>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#javascript-expressions-as-props\"></a>JavaScript Expressions as Props</h3>\n<p>You can pass any JavaScript expression as a prop, by surrounding it with <code class=\"language-text\">{}</code>. For example, in this JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyComponent foo={1 + 2 + 3 + 4} /></code></pre></div>\n<p>For <code class=\"language-text\">MyComponent</code>, the value of <code class=\"language-text\">props.foo</code> will be <code class=\"language-text\">10</code> because the expression <code class=\"language-text\">1 + 2 + 3 + 4</code> gets evaluated.</p>\n<p><code class=\"language-text\">if</code> statements and <code class=\"language-text\">for</code> loops are not expressions in JavaScript, so they can’t be used in JSX directly. Instead, you can put these in the surrounding code. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function NumberDescriber(props) {\n  let description;\n  if (props.number % 2 == 0) {    description = &lt;strong>even&lt;/strong>;  } else {    description = &lt;i>odd&lt;/i>;  }  return &lt;div>{props.number} is an {description} number&lt;/div>;\n}</code></pre></div>\n<p>You can learn more about <a href=\"https://reactjs.org/docs/conditional-rendering.html\">conditional rendering</a> and <a href=\"https://reactjs.org/docs/lists-and-keys.html\">loops</a> in the corresponding sections.</p>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#string-literals\"></a>String Literals</h3>\n<p>You can pass a string literal as a prop. These two JSX expressions are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyComponent message=\"hello world\" />\n\n&lt;MyComponent message={'hello world'} /></code></pre></div>\n<p>When you pass a string literal, its value is HTML-unescaped. So these two JSX expressions are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyComponent message=\"&amp;lt;3\" />\n\n&lt;MyComponent message={'&lt;3'} /></code></pre></div>\n<p>This behavior is usually not relevant. It’s only mentioned here for completeness.</p>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#props-default-to-true\"></a>Props Default to “True”</h3>\n<p>If you pass no value for a prop, it defaults to <code class=\"language-text\">true</code>. These two JSX expressions are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyTextBox autocomplete />\n\n&lt;MyTextBox autocomplete={true} /></code></pre></div>\n<p>In general, we don’t recommend <em>not</em> passing a value for a prop, because it can be confused with the <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015\">ES6 object shorthand</a> <code class=\"language-text\">{foo}</code> which is short for <code class=\"language-text\">{foo: foo}</code> rather than <code class=\"language-text\">{foo: true}</code>. This behavior is just there so that it matches the behavior of HTML.</p>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#spread-attributes\"></a>Spread Attributes</h3>\n<p>If you already have <code class=\"language-text\">props</code> as an object, and you want to pass it in JSX, you can use <code class=\"language-text\">...</code> as a “spread” syntax to pass the whole props object. These two components are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function App1() {\n  return &lt;Greeting firstName=\"Ben\" lastName=\"Hector\" />;\n}\n\nfunction App2() {\n  const props = {firstName: 'Ben', lastName: 'Hector'};\n  return &lt;Greeting {...props} />;}</code></pre></div>\n<p>You can also pick specific props that your component will consume while passing all other props using the spread syntax.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = props => {\n  const { kind, ...other } = props;  const className = kind === \"primary\" ? \"PrimaryButton\" : \"SecondaryButton\";\n  return &lt;button className={className} {...other} />;\n};\n\nconst App = () => {\n  return (\n    &lt;div>\n      &lt;Button kind=\"primary\" onClick={() => console.log(\"clicked!\")}>\n        Hello World!\n      &lt;/Button>\n    &lt;/div>\n  );\n};</code></pre></div>\n<p>In the example above, the <code class=\"language-text\">kind</code> prop is safely consumed and <em>is not</em> passed on to the <code class=\"language-text\">&lt;button></code> element in the DOM. All other props are passed via the <code class=\"language-text\">...other</code> object making this component really flexible. You can see that it passes an <code class=\"language-text\">onClick</code> and <code class=\"language-text\">children</code> props.</p>\n<p>Spread attributes can be useful but they also make it easy to pass unnecessary props to components that don’t care about them or to pass invalid HTML attributes to the DOM. We recommend using this syntax sparingly.</p>\n<h2><a href=\"https://reactjs.org/docs/jsx-in-depth.html#children-in-jsx\"></a>Children in JSX</h2>\n<p>In JSX expressions that contain both an opening tag and a closing tag, the content between those tags is passed as a special prop: <code class=\"language-text\">props.children</code>. There are several different ways to pass children:</p>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#string-literals-1\"></a>String Literals</h3>\n<p>You can put a string between the opening and closing tags and <code class=\"language-text\">props.children</code> will just be that string. This is useful for many of the built-in HTML elements. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyComponent>Hello world!&lt;/MyComponent></code></pre></div>\n<p>This is valid JSX, and <code class=\"language-text\">props.children</code> in <code class=\"language-text\">MyComponent</code> will simply be the string <code class=\"language-text\">\"Hello world!\"</code>. HTML is unescaped, so you can generally write JSX just like you would write HTML in this way:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>This is valid HTML &amp;amp; JSX at the same time.&lt;/div></code></pre></div>\n<p>JSX removes whitespace at the beginning and ending of a line. It also removes blank lines. New lines adjacent to tags are removed; new lines that occur in the middle of string literals are condensed into a single space. So these all render to the same thing:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>Hello World&lt;/div>\n\n&lt;div>\n  Hello World\n&lt;/div>\n\n&lt;div>\n  Hello\n  World\n&lt;/div>\n\n&lt;div>\n\n  Hello World\n&lt;/div></code></pre></div>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#jsx-children\"></a>JSX Children</h3>\n<p>You can provide more JSX elements as the children. This is useful for displaying nested components:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyContainer>\n  &lt;MyFirstComponent />\n  &lt;MySecondComponent />\n&lt;/MyContainer></code></pre></div>\n<p>You can mix together different types of children, so you can use string literals together with JSX children. This is another way in which JSX is like HTML, so that this is both valid JSX and valid HTML:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  Here is a list:\n  &lt;ul>\n    &lt;li>Item 1&lt;/li>\n    &lt;li>Item 2&lt;/li>\n  &lt;/ul>\n&lt;/div></code></pre></div>\n<p>A React component can also return an array of elements:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render() {\n  // No need to wrap list items in an extra element!\n  return [\n    // Don't forget the keys :)\n    &lt;li key=\"A\">First item&lt;/li>,\n    &lt;li key=\"B\">Second item&lt;/li>,\n    &lt;li key=\"C\">Third item&lt;/li>,\n  ];\n}</code></pre></div>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#javascript-expressions-as-children\"></a>JavaScript Expressions as Children</h3>\n<p>You can pass any JavaScript expression as children, by enclosing it within <code class=\"language-text\">{}</code>. For example, these expressions are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyComponent>foo&lt;/MyComponent>\n\n&lt;MyComponent>{'foo'}&lt;/MyComponent></code></pre></div>\n<p>This is often useful for rendering a list of JSX expressions of arbitrary length. For example, this renders an HTML list:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Item(props) {\n  return &lt;li>{props.message}&lt;/li>;}\n\nfunction TodoList() {\n  const todos = ['finish doc', 'submit pr', 'nag dan to review'];\n  return (\n    &lt;ul>\n      {todos.map((message) => &lt;Item key={message} message={message} />)}    &lt;/ul>\n  );\n}</code></pre></div>\n<p>JavaScript expressions can be mixed with other types of children. This is often useful in lieu of string templates:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Hello(props) {\n  return &lt;div>Hello {props.addressee}!&lt;/div>;}</code></pre></div>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#functions-as-children\"></a>Functions as Children</h3>\n<p>Normally, JavaScript expressions inserted in JSX will evaluate to a string, a React element, or a list of those things. However, <code class=\"language-text\">props.children</code> works just like any other prop in that it can pass any sort of data, not just the sorts that React knows how to render. For example, if you have a custom component, you could have it take a callback as <code class=\"language-text\">props.children</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Calls the children callback numTimes to produce a repeated component\nfunction Repeat(props) {\n  let items = [];\n  for (let i = 0; i &lt; props.numTimes; i++) {    items.push(props.children(i));\n  }\n  return &lt;div>{items}&lt;/div>;\n}\n\nfunction ListOfTenThings() {\n  return (\n    &lt;Repeat numTimes={10}>\n      {(index) => &lt;div key={index}>This is item {index} in the list&lt;/div>}    &lt;/Repeat>\n  );\n}</code></pre></div>\n<p>Children passed to a custom component can be anything, as long as that component transforms them into something React can understand before rendering. This usage is not common, but it works if you want to stretch what JSX is capable of.</p>\n<h3><a href=\"https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored\"></a>Booleans, Null, and Undefined Are Ignored</h3>\n<p><code class=\"language-text\">false</code>, <code class=\"language-text\">null</code>, <code class=\"language-text\">undefined</code>, and <code class=\"language-text\">true</code> are valid children. They simply don’t render. These JSX expressions will all render to the same thing:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div />\n\n&lt;div>&lt;/div>\n\n&lt;div>{false}&lt;/div>\n\n&lt;div>{null}&lt;/div>\n\n&lt;div>{undefined}&lt;/div>\n\n&lt;div>{true}&lt;/div></code></pre></div>\n<p>This can be useful to conditionally render React elements. This JSX renders the <code class=\"language-text\">&lt;Header /></code> component only if <code class=\"language-text\">showHeader</code> is <code class=\"language-text\">true</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  {showHeader &amp;&amp; &lt;Header />}  &lt;Content />\n&lt;/div></code></pre></div>\n<p>One caveat is that some <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Falsy\">“falsy” values</a>, such as the <code class=\"language-text\">0</code> number, are still rendered by React. For example, this code will not behave as you might expect because <code class=\"language-text\">0</code> will be printed when <code class=\"language-text\">props.messages</code> is an empty array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  {props.messages.length &amp;&amp;    &lt;MessageList messages={props.messages} />\n  }\n&lt;/div></code></pre></div>\n<p>To fix this, make sure that the expression before <code class=\"language-text\">&amp;&amp;</code> is always boolean:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  {props.messages.length > 0 &amp;&amp;    &lt;MessageList messages={props.messages} />\n  }\n&lt;/div></code></pre></div>\n<p>Conversely, if you want a value like <code class=\"language-text\">false</code>, <code class=\"language-text\">true</code>, <code class=\"language-text\">null</code>, or <code class=\"language-text\">undefined</code> to appear in the output, you have to <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#String_conversion\">convert it to a string</a> first:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  My JavaScript variable is {String(myVariable)}.&lt;/div></code></pre></div>"},{"url":"/blog/intro-01-data-structures/","relativePath":"blog/intro-01-data-structures.md","relativeDir":"blog","base":"intro-01-data-structures.md","name":"intro-01-data-structures","frontmatter":{"title":"Intro-01-Data Structures","template":"post","subtitle":"a visual guide","excerpt":"The most basic of all data structures, an array s","date":"2022-04-19T05:30:39.001Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc2.gif?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc2.gif?raw=true","image_position":"top","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/ds.yaml"],"tags":["src/data/tags/ds-algo.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/data-structures-algorithms-resources.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h3>1. Array</h3>\n<p>The most basic of all data structures, an array stores data in memory for later use. Each array has a fixed number of cells decided on its creation, and each cell has a corresponding numeric index used to select its data. Whenever you’d like to use the array, all you need are the desired indices, and you can access any of the data within.</p>\n<p><a href=\"https://camo.githubusercontent.com/ab40ae120edb6f03676fd5bd971feb1f59801ee43d90464c5f3c0ac7f5dc4c25/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f35313633353033373435373631323830\">\n<img src=\"https://camo.githubusercontent.com/ab40ae120edb6f03676fd5bd971feb1f59801ee43d90464c5f3c0ac7f5dc4c25/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f35313633353033373435373631323830\" alt=\"image\"></a></p>\n<p>Advantages</p>\n<ul>\n<li>Simple to create and use.</li>\n<li>Foundational building block for complex data structures</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Fixed size</li>\n<li>Expensive to insert/delete or resequence values</li>\n<li>Inefficient to sort</li>\n</ul>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#applications\"></a>Applications</h4>\n<ul>\n<li>Basic spreadsheets</li>\n<li>Within complex structures such as hash tables</li>\n</ul>\n<p><br>\n\\</p>\n<h3><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#2-queues\"></a>2. Queues</h3>\n<p>Queues are conceptually similar to stacks; both are sequential structures, but queues process elements in the order they were entered rather than the most recent element.</p>\n<p>As a result, queues can be thought of as a FIFO (First In, First Out) version of stacks. These are helpful as a buffer for requests, storing each request in the order it was received until it can be processed.</p>\n<p><a href=\"https://camo.githubusercontent.com/0e19efa8b7251690191848de4d8538c36f7619aa1a69b46a306b16b19274edb0/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f34363038323536343133353332313630\">\n<img src=\"https://camo.githubusercontent.com/0e19efa8b7251690191848de4d8538c36f7619aa1a69b46a306b16b19274edb0/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f34363038323536343133353332313630\" alt=\"image\"></a></p>\n<p>For a visual, consider a single-lane tunnel: the first car to enter is the first car to exit. If other cars should wish to exit, but the first stops, all cars will have to wait for the first to exit before they can proceed.</p>\n<p>Advantages</p>\n<ul>\n<li>Dynamic size</li>\n<li>Orders data in the order it was received</li>\n<li>Low runtime</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Can only retrieve the oldest element</li>\n</ul>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#applications-1\"></a>Applications</h4>\n<ul>\n<li>Effective as a buffer when receiving frequent data</li>\n<li>Convenient way to store order-sensitive data such as stored voicemails</li>\n<li>Ensures the oldest data is processed first</li>\n</ul>\n<p><br>\n\\</p>\n<h3><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#3-linked-list\"></a>3. Linked List</h3>\n<p>Linked lists are a data structure which, unlike the previous three, does not use physical placement of data in memory. This means that, rather than indexes or positions, linked lists use a referencing system: elements are stored in nodes that contain a pointer to the next node, repeating until all nodes are linked.</p>\n<p>This system allows efficient insertion and removal of items without the need for reorganization.</p>\n<p><a href=\"https://camo.githubusercontent.com/c5b4f3b037de92da7118b3bbf05e9485a28507729cf9d9cffc2c17f37189971f/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f34353336323436353035333038313630\">\n<img src=\"https://camo.githubusercontent.com/c5b4f3b037de92da7118b3bbf05e9485a28507729cf9d9cffc2c17f37189971f/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f34353336323436353035333038313630\" alt=\"image\"></a></p>\n<p>Advantages</p>\n<ul>\n<li>Efficient insertion and removal of new elements</li>\n<li>Less complex than restructuring an array</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Uses more memory than arrays</li>\n<li>Inefficient to retrieve a specific element</li>\n<li>Inefficient to traverse the list backward</li>\n</ul>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#applications-2\"></a>Applications</h4>\n<ul>\n<li>Best used when data must be added and removed in quick succession from unknown locations</li>\n</ul>\n<p><br>\n\\</p>\n<h3><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#4-trees\"></a>4. Trees</h3>\n<p>Trees are another relation-based data structure, which specialize in representing hierarchical structures. Like a linked list, nodes contain both elements of data and pointers marking its relation to immediate nodes.</p>\n<p>Each tree has a “root” node, off of which all other nodes branch. The root contains references to all elements directly below it, which are known as its “child nodes”. This continues, with each child node, branching off into more child nodes.</p>\n<p>Nodes with linked child nodes are called internal nodes while those without child nodes are external nodes. A common type of tree is the “binary search tree” which is used to easily search stored data.</p>\n<p>These search operations are highly efficient, as its search duration is dependent not on the number of nodes but on the number of levels down the tree.</p>\n<p><a href=\"https://camo.githubusercontent.com/82cd3953e721f75e55b74c5854d64d3de002098592eba6338aa152f3ad1b4cc6/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f34383630343534383739383837333630\">\n<img src=\"https://camo.githubusercontent.com/82cd3953e721f75e55b74c5854d64d3de002098592eba6338aa152f3ad1b4cc6/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f34383630343534383739383837333630\" alt=\"image\"></a></p>\n<p>This type of tree is defined by four strict rules:</p>\n<ol>\n<li>The left subtree contains only nodes with elements lesser than the root.</li>\n<li>The right subtree contains only nodes with elements greater than the root.</li>\n<li>Left and right subtrees must also be a binary search tree. They must follow the above rules with the “root” of their tree.</li>\n<li>There can be no duplicate nodes, i.e. no two nodes can have the same value.</li>\n</ol>\n<p>Advantages</p>\n<ul>\n<li>Ideal for storing hierarchical relationships</li>\n<li>Dynamic size</li>\n<li>Quick at insert and delete operations</li>\n<li>In a binary search tree, inserted nodes are sequenced immediately.</li>\n<li>Binary search trees are efficient at searches; length is only O(height)O(height).</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Slow to rearrange nodes</li>\n<li>Child nodes hold no information about their parent node</li>\n<li>Binary search trees are not as fast as the more complicated hash table</li>\n<li>Binary search trees can degenerate into linear search (scanning all elements) if not implemented with balanced subtrees.</li>\n</ul>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#applications-3\"></a>Applications</h4>\n<ul>\n<li>Storing hierarchical data such as a file location.</li>\n<li>Binary search trees are excellent for tasks needing searching or ordering of data.</li>\n</ul>\n<blockquote>\n<p><strong>*Enjoying the article?</strong> Scroll down to* <em><a href=\"https://www.educative.io/blog/blog-newsletter-annoucement\">sign up</a></em> <em>for our free, bi-monthly newsletter.</em></p>\n</blockquote>\n<p>\\</p>\n<h3><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#5-graphs\"></a>5. Graphs</h3>\n<p>Graphs are a relation-based data structure helpful for storing web-like relationships. Each node, or vertex, as they’re called in graphs, has a title (A, B, C, etc.), a value contained within, and a list of links (called edges) it has with other vertices.</p>\n<p><a href=\"https://camo.githubusercontent.com/615c0612c32e8d319d2c79e596885e4aceb6ce7dc64ac235ede92637fac589f9/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f34393132363931303737343437363830\">\n<img src=\"https://camo.githubusercontent.com/615c0612c32e8d319d2c79e596885e4aceb6ce7dc64ac235ede92637fac589f9/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f34393132363931303737343437363830\" alt=\"image\"></a></p>\n<p>In the above example, each circle is a vertex, and each line is an edge. If produced in writing, this structure would look like:</p>\n<p><em>V = {a, b, c, d}</em></p>\n<p><em>E = {ab, ac, bc, cd}</em></p>\n<p>While hard to visualize at first, this structure is invaluable in conveying relationship charts in textual form, anything from circuitry to train networks.</p>\n<p>Advantages</p>\n<ul>\n<li>Can quickly convey visuals over text</li>\n<li>Usable to model a diverse number of subjects so long as they contain a relational structure</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>At a higher level, text can be time-consuming to convert to an image.</li>\n<li>It can be difficult to see the existing edges or how many edges a given vertex has connected to it</li>\n</ul>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#applications-4\"></a>Applications</h4>\n<ul>\n<li>Network representations</li>\n<li>Modeling social networks, such as Facebook.</li>\n</ul>\n<p>\\</p>\n<h3><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#6-hash-tables-map\"></a>6. Hash Tables (Map)</h3>\n<p>Hash tables are a complex data structure capable of storing large amounts of information and retrieving specific elements efficiently. This data structure relies on the concept of key/value pairs, where the “key” is a searched string and the “value” is the data paired with that key.</p>\n<p><a href=\"https://camo.githubusercontent.com/ed02956a5f707a017dc59966166c26835374fa0b48a9b6d0aaec06367d4dae10/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36373435393131313633303932393932\">\n<img src=\"https://camo.githubusercontent.com/ed02956a5f707a017dc59966166c26835374fa0b48a9b6d0aaec06367d4dae10/68747470733a2f2f7777772e6564756361746976652e696f2f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36373435393131313633303932393932\" alt=\"image\"></a> Each searched key is converted from its string form into a numerical value, called a hash, using a predefined hash function. This hash then points to a storage bucket – a smaller subgroup within the table. It then searches the bucket for the originally entered key and returns the value associated with that key.</p>\n<p>Advantages</p>\n<ul>\n<li>Key can be in any form, while array’s indices must be integers</li>\n<li>Highly efficient search function</li>\n<li>Constant number of operations for each search</li>\n<li>Constant cost for insertion or deletion operations</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Collisions: an error caused when two keys convert to the same hash code or two hash codes point to the same value.</li>\n<li>These errors can be common and often require an overhaul of the hash function.</li>\n</ul>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#applications-5\"></a>Applications</h4>\n<ul>\n<li>Database storage</li>\n<li>Address lookups by name</li>\n</ul>\n<p>Each hash table can be very different, from the types of the keys and values, to the way their hash functions work. Due to these differences and the multi-layered aspects of a hash table, it is nearly impossible to encapsulate so generally.</p>\n<p><br>\n\\</p>\n<h3><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#data-structure-interview-questions\"></a>Data structure interview questions</h3>\n<p>For many developers and programmers, data structures are most important for <a href=\"https://www.educative.io/blog/acing-the-javascript-interview-top-questions-explained\">cracking Javascript coding interviews</a>. Questions and problems on data structures are fundamental to modern-day coding interviews. In fact, they have a lot to say over your hireability and entry-level rate as a candidate.</p>\n<p>Today, we will be going over seven common coding interview questions for JavaScript data structures, one for each of the data structures we discussed above. Each will also discuss its time complexity based on the <a href=\"https://www.educative.io/blog/a-big-o-primer-for-beginning-devs\">BigO notation</a> theory.</p>\n<p>\\</p>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#array-remove-all-even-integers-from-an-array\"></a>Array: Remove all even integers from an array</h4>\n<p><strong>Problem statement:</strong> Implement a function <code class=\"language-text\">removeEven(arr)</code>, which takes an array arr in its input and removes all the even elements from a given array.</p>\n<p><strong>Input:</strong> An array of random integers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><strong>Output:</strong> an array containing only odd integers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>There are two ways you could solve this coding problem in an interview. Let’s discuss each.</p>\n<p>\\</p>\n<p><strong>Solution #1: Doing it “by hand”</strong></p>\n<p>123456789function removeEven(arr) { var odds = [] for (let number of arr) { if (number % 2 != 0) // Check if the item in the list is NOT even ('%' is the modulus symbol!) odds.push(number) //If it isn't even append it to the empty list } return odds // Return the new list}console.log(removeEven([3, 2, 41, 3, 34]))Run</p>\n<p>This approach starts with the first element of the array. If that current element is not even, it pushes this element into a new array. If it is even, it will move to the next element, repeating until it reaches the end of the array. In regards to time complexity, since the entire array has to be iterated over, this solution is in <em>O(n)O(n).</em></p>\n<p>\\</p>\n<p><strong>Solution #2: Using filter() and lambda function</strong></p>\n<p>1234function removeEven(arr) { return arr.filter((v => (v % 2) != 0))}console.log(removeEven([3,2,41,3,34]))</p>\n<p>This solution also begins with the first element and checks if it is even. If it is even, it filters out this element. If not, skips to the next element, repeating this process until it reaches the end of the array.</p>\n<p>The filter function uses lambda or arrow functions, which use shorter, simpler syntax. The filter filters out the element for which the lambda function returns false. The time complexity of this is the same as the time complexity of the previous solution.</p>\n<p>\\</p>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#stack-check-for-balanced-parentheses-using-a-stack\"></a>Stack: Check for balanced parentheses using a stack</h4>\n<p><strong>Problem statement:</strong> Implement the <code class=\"language-text\">isBalanced()</code> function to take a string containing only curly <code class=\"language-text\">{}</code>, square <code class=\"language-text\">[]</code>, and round <code class=\"language-text\">()</code> parentheses. The function should tell us if all the parentheses in the string are balanced. This means that every opening parenthesis will have a closing one. For example, <code class=\"language-text\">{[]}</code> is balanced, but <code class=\"language-text\">{[}]</code> is not.</p>\n<p><strong>Input:</strong> A string consisting solely of <code class=\"language-text\">(</code>, <code class=\"language-text\">)</code>, <code class=\"language-text\">{</code>, <code class=\"language-text\">}</code>, <code class=\"language-text\">[</code> and <code class=\"language-text\">]</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><strong>Output:</strong> Returns <code class=\"language-text\">False</code> if the expression doesn’t have balanced parentheses. If it does, the function returns <code class=\"language-text\">True</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To solve this problem, we can simply use a stack of characters. Look below at the code to see how it works.</p>\n<p>index.jsStack.js12345678910111213141516171819202122232425262728293031\"use strict\";module.exports = class Stack { constructor() { this.items = []; this.top = null; } getTop() { if (this.items.length == 0) return null; return this.top; } isEmpty() { return this.items.length == 0; } size() { return this.items.length; } push(element) { this.items.push(element); this.top = element; } pop() { if (this.items.length != 0) { if (this.items.length == 1) { this.top = null; return this.items.pop();Run</p>\n<p>This process will iterate over the string one character at a time. We can determine that the string is unbalanced based on two factors:</p>\n<ol>\n<li>The stack is empty.</li>\n<li>The top element in the stack is not the right type.</li>\n</ol>\n<p>If either of these conditions is true, we return <code class=\"language-text\">False</code>. If the parenthesis is an opening parenthesis, it is pushed into the stack. If by the end all are balanced, the stack will be empty. If it is not empty, we return <code class=\"language-text\">False</code>. Since we traverse the string exp only once, the time complexity is <em>O(n)</em>.</p>\n<p>\\</p>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#queue-generate-binary-numbers-from-1-to-n\"></a>Queue: Generate Binary Numbers from 1 to n</h4>\n<p><strong>Problem statement:</strong> Implement a function <code class=\"language-text\">findBin(n)</code>, which will generate binary numbers from <code class=\"language-text\">1</code> to <code class=\"language-text\">n</code> in the form of a string using a queue.</p>\n<p><strong>Input:</strong> A positive integer n</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><strong>Output:</strong> Returns binary numbers in the form of strings from <code class=\"language-text\">1</code> up to <code class=\"language-text\">n</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The easiest way to solve this problem is using a queue to generate new numbers from previous numbers. Let’s break that down.</p>\n<p>index.jsQueue.js12345678910111213141516171819202122232425262728293031\"use strict\";module.exports = class Queue { constructor() { this.items = []; this.front = null; this.back = null; } isEmpty() { return this.items.length == 0; } getFront() { if (this.items.length != 0) { return this.items[0]; } else return null; } size() { return this.items.length; } enqueue(element) { this.items.push(element); }Run</p>\n<p>The key is to generate consecutive binary numbers by appending 0 and 1 to previous binary numbers. To clarify,</p>\n<ul>\n<li>10 and 11 can be generated if 0 and 1 are appended to 1.</li>\n<li>100 and 101 are generated if 0 and 1 are appended to 10.</li>\n</ul>\n<p>Once we generate a binary number, it is then enqueued to a queue so that new binary numbers can be generated if we append 0 and 1 when that number will be enqueued.</p>\n<p>Since a queue follows the <em>First-In First-Out</em> property, the enqueued binary numbers are dequeued so that the resulting array is mathematically correct.</p>\n<p>Look at the code above. On line 7, <code class=\"language-text\">1</code> is enqueued. To generate the sequence of binary numbers, a number is dequeued and stored in the array <code class=\"language-text\">result</code>. On lines 11-12, we append <code class=\"language-text\">0</code> and <code class=\"language-text\">1</code> to produce the next numbers.</p>\n<p>Those new numbers are also enqueued at lines 14-15. The queue will take integer values, so it converts the string to an integer as it is enqueued.</p>\n<p>The time complexity of this solution is in <em>O(n)O(n)</em> since constant-time operations are executed for n times.</p>\n<p>\\</p>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#linked-list-reverse-a-linked-list\"></a>Linked List: Reverse a linked list</h4>\n<p><strong>Problem statement:</strong> Write the <code class=\"language-text\">reverse</code> function to take a singly linked list and reverse it in place.</p>\n<p><strong>Input:</strong> a singly linked list</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><strong>Output:</strong> a reverse linked list</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The easiest way to solve this problem is by using iterative pointer manipulation. Let’s take a look.</p>\n<p>index.jsLinkedList.jsNode.js12345678910111213141516171819202122232425262728293031\"use strict\";const Node = require('./Node.js');module.exports = class LinkedList { constructor() { this.head = null; } //Insertion At Head insertAtHead(newData) { let tempNode = new Node(newData); tempNode.nextElement = this.head; this.head = tempNode; return this; //returning the updated list } isEmpty() { return (this.head == null); } //function to print the linked list printList() { if (this.isEmpty()) { console.log(\"Empty List\"); return false; } else { let temp = this.head; while (temp != null) { process.stdout.write(String(temp.data)); process.stdout.write(\" -> \"); temp = temp.nextElement;Run</p>\n<p>We use a loop to iterate through the input list. For a <code class=\"language-text\">current</code> node, its link with the <code class=\"language-text\">previous</code> node is reversed. then, <code class=\"language-text\">next</code> stores the next node in the list. Let’s break that down by line.</p>\n<ul>\n<li>Line 22- Store the <code class=\"language-text\">current</code> node’s <code class=\"language-text\">nextElement</code> in <code class=\"language-text\">next</code></li>\n<li>Line 23 - Set <code class=\"language-text\">current</code> node’s <code class=\"language-text\">nextElement</code> to <code class=\"language-text\">previous</code></li>\n<li>Line 24 - Make the <code class=\"language-text\">current</code> node the new <code class=\"language-text\">previous</code> for the next iteration</li>\n<li>Line 25 - Use <code class=\"language-text\">next</code> to go to the next node</li>\n<li>Line 29 - We reset the <code class=\"language-text\">head</code> pointer to point at the last node</li>\n</ul>\n<p>Since the list is traversed only once, the algorithm runs in <em>O(n)</em>.</p>\n<p>\\</p>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#tree-find-the-minimum-value-in-a-binary-search-tree\"></a>Tree: Find the Minimum Value in a Binary Search Tree</h4>\n<p><strong>Problem statement:</strong> Use the <code class=\"language-text\">findMin(root)</code> function to find the minimum value in a Binary Search Tree.</p>\n<p><strong>Input:</strong> a root node for a binary search tree</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><strong>Output:</strong> the smallest integer value from that binary search tree</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Let’s look at an easy solution for this problem.</p>\n<p>\\</p>\n<p><strong>Solution: Iterative <code class=\"language-text\">findMin( )</code></strong></p>\n<p>This solution begins by checking if the root is <code class=\"language-text\">null</code>. It returns <code class=\"language-text\">null</code> if so. It then moves to the left subtree and continues with each node’s left child until the left-most child is reached.</p>\n<p>index.jsBinarySearchTree.jsNode.js12345678910111213141516171819202122232425262728293031\"use strict\";const Node = require('./Node.js');module.exports = class BinarySearchTree { constructor(rootValue) { this.root = new Node(rootValue); } insert(currentNode, newValue) { if (currentNode === null) { currentNode = new Node(newValue); } else if (newValue &#x3C; currentNode.val) { currentNode.leftChild = this.insert(currentNode.leftChild, newValue); } else { currentNode.rightChild = this.insert(currentNode.rightChild, newValue); } return currentNode; } insertBST(newValue) { if(this.root==null){ this.root=new Node(newValue); return; } this.insert(this.root, newValue); } preOrderPrint(currentNode) { if (currentNode !== null) { console.log(currentNode.val); this.preOrderPrint(currentNode.leftChild);Run\\</p>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#graph-remove-edge\"></a>Graph: Remove Edge</h4>\n<p><strong>Problem statement:</strong> Implement the removeEdge function to take a source and a destination as arguments. It should detect if an edge exists between them.</p>\n<p><strong>Input:</strong> A graph, a source, and a destination</p>\n<p><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md\">\n<img src=\"\" alt=\"image\"></a><a href=\"https://camo.githubusercontent.com/428156ffac3c84ccdc035827728a34648c3fb537f5967696fff27d5625f9fc18/68747470733a2f2f7777772e6564756361746976652e696f2f63646e2d6367692f696d6167652f663d6175746f2c6669743d636f6e7461696e2c773d3630302f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36353736313335363639323834383634\"><img src=\"https://camo.githubusercontent.com/428156ffac3c84ccdc035827728a34648c3fb537f5967696fff27d5625f9fc18/68747470733a2f2f7777772e6564756361746976652e696f2f63646e2d6367692f696d6167652f663d6175746f2c6669743d636f6e7461696e2c773d3630302f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36353736313335363639323834383634\" alt=\"widget\"></a><a href=\"https://camo.githubusercontent.com/bab248d2d24b5387823fe7b0259e5ce89b5b38e322500cae5fe67b5a379dad90/68747470733a2f2f7777772e6564756361746976652e696f2f63646e2d6367692f696d6167652f663d6175746f2c6669743d636f6e7461696e2c773d3330302c713d31302f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36353736313335363639323834383634\"><img src=\"https://camo.githubusercontent.com/bab248d2d24b5387823fe7b0259e5ce89b5b38e322500cae5fe67b5a379dad90/68747470733a2f2f7777772e6564756361746976652e696f2f63646e2d6367692f696d6167652f663d6175746f2c6669743d636f6e7461696e2c773d3330302c713d31302f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36353736313335363639323834383634\" alt=\"widget\"></a></p>\n<p><strong>Output:</strong> A graph with the edge between the source and the destination removed.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md\">\n<img src=\"\" alt=\"image\"></a><a href=\"https://camo.githubusercontent.com/3c66578e7e5a92a7e8bbe6957356049a8d4206d6d9a91ed2fd6460c7b9fb8ff5/68747470733a2f2f7777772e6564756361746976652e696f2f63646e2d6367692f696d6167652f663d6175746f2c6669743d636f6e7461696e2c773d3630302f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36303338353930393834323930333034\"><img src=\"https://camo.githubusercontent.com/3c66578e7e5a92a7e8bbe6957356049a8d4206d6d9a91ed2fd6460c7b9fb8ff5/68747470733a2f2f7777772e6564756361746976652e696f2f63646e2d6367692f696d6167652f663d6175746f2c6669743d636f6e7461696e2c773d3630302f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36303338353930393834323930333034\" alt=\"widget\"></a><a href=\"https://camo.githubusercontent.com/da5b513fd1a1678e0b6d6209a9673acb5555e3a7f863eb1580ff38d71f6bbfed/68747470733a2f2f7777772e6564756361746976652e696f2f63646e2d6367692f696d6167652f663d6175746f2c6669743d636f6e7461696e2c773d3330302c713d31302f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36303338353930393834323930333034\"><img src=\"https://camo.githubusercontent.com/da5b513fd1a1678e0b6d6209a9673acb5555e3a7f863eb1580ff38d71f6bbfed/68747470733a2f2f7777772e6564756361746976652e696f2f63646e2d6367692f696d6167652f663d6175746f2c6669743d636f6e7461696e2c773d3330302c713d31302f6170692f706167652f363039343438343838333337343038302f696d6167652f646f776e6c6f61642f36303338353930393834323930333034\" alt=\"widget\"></a></p>\n<p>The solution to this problem is fairly simple: we use Indexing and deletion. Take a look</p>\n<p>index.jsGraph.jsLinkedList.jsNode.js12345678910111213141516171819202122232425262728293031\"use strict\";const LinkedList = require('./LinkedList.js');const Node = require('./Node.js');module.exports = class Graph { constructor(vertices) { this.vertices = vertices; this.list = []; var it; for (it = 0; it &#x3C; vertices; it++) { let temp = new LinkedList(); this.list.push(temp); } } addEdge(source, destination) { if (source &#x3C; this.vertices &#x26;&#x26; destination &#x3C; this.vertices) this.list[source].insertAtHead(destination); return this; } printGraph() { console.log(\">>Adjacency List of Directed Graph&#x3C;&#x3C;\"); var i; for (i = 0; i &#x3C; this.list.length; i++) { process.stdout.write(\"|\" + String(i) + \"| => \");Run</p>\n<p>Since our vertices are stored in an array, we can access the <code class=\"language-text\">source</code> linked list. We then call the <code class=\"language-text\">delete</code> function for linked lists. The time complexity for this solution is O(E) since we may have to traverse E edges.</p>\n<p>\\</p>\n<h4><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE/blob/master/useful-downloads.md#hash-table-convert-max-heap-to-min-heap\"></a>Hash Table: Convert Max-Heap to Min-Heap</h4>\n<p><strong>Problem statement:</strong> Implement the function <code class=\"language-text\">convertMax(maxHeap)</code> to convert a binary max-heap into a binary min-heap. <code class=\"language-text\">maxHeap</code> should be an array in the <code class=\"language-text\">maxHeap</code> format, i.e the parent is greater than its children.</p>\n<p><strong>Input:</strong> a Max-Heap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><strong>Output:</strong> returns the converted array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To solve this problem, we must min heapify all parent nodes. Take a look.</p>\n<p>123456789101112131415161718192021222324252627function minHeapify(heap, index) { var left = index * 2; var right = (index * 2) + 1; var smallest = index; if ((heap.length > left) &#x26;&#x26; (heap[smallest] > heap[left])) { smallest = left } if ((heap.length > right) &#x26;&#x26; (heap[smallest] > heap[right])) smallest = right if (smallest != index) { var tmp = heap[smallest] heap[smallest] = heap[index] heap[index] = tmp minHeapify(heap, smallest) } return heap;}function convertMax(maxHeap) { for (var i = Math.floor((maxHeap.length) / 2); i > -1; i--) maxHeap = minHeapify(maxHeap, i) return maxHeap}var maxHeap = [9,4,7,1,-2,6,5]console.log(convertMax(maxHeap))Run</p>\n<p>We consider <code class=\"language-text\">maxHeap</code> to be a regular array and reorder it to accurately represent a min-heap. You can see this done in the code above. The <code class=\"language-text\">convertMax()</code> function then restores the heap property on all nodes from the lowest parent node by calling the <code class=\"language-text\">minHeapify()</code> function. In regards to time complexity, this solution takes <em>O(nlog(n))O(nlog(n))</em> time.</p>\n<!--EndFragment-->"},{"url":"/blog/intro-to-markdown/","relativePath":"blog/intro-to-markdown.md","relativeDir":"blog","base":"intro-to-markdown.md","name":"intro-to-markdown","frontmatter":{"title":"Intro To Markdown","template":"post","subtitle":"An Introduction to Markdown (Bonus Markdown Templates Included)","excerpt":"This topic is meant to give you a very basic overview of how Markdown works,","date":"2022-05-16T04:10:35.613Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/markdown.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/markdown.png?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/git.yaml"],"tags":["src/data/tags/cms.yaml"],"show_author_bio":true,"cmseditable":true},"html":"<h1>An Introduction to Markdown (Bonus Markdown Templates Included)</h1>\n<p>Basic Syntax Guide</p>\n<hr>\n<h3>An Introduction to Markdown (Bonus Markdown Templates Included)</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*oy6szzmI0FdRUiTd.png\" class=\"graf-image\" />\n</figure>\n<a href=\"https://github.com/bgoonz/Markdown-Templates.git\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/Markdown-Templates.git\">\n<strong>bgoonz/Markdown-Templates</strong>\n<br />\n<em>One Paragraph of project description goes here These instructions will get you a copy of the project up and running on…</em>github.com</a>\n<a href=\"https://github.com/bgoonz/Markdown-Templates.git\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>Basic Syntax Guide</h3>\n<p>This topic is meant to give you a very basic overview of how Markdown works, showing only some of the most common operations you use most frequently. Keep in mind that you can also use the Edit menus to inject markdown using the toolbar, which serves as a great way to see how Markdown works. However, Markdown's greatest strength lies in its simplicity and keyboard friendly approach that lets you focus on writing your text and staying on the keyboard.</p>\n<h3>What is Markdown</h3>\n<p>Markdown is very easy to learn and get comfortable with due it's relatively small set of markup ‘commands'. It uses already familiar syntax to represent common formatting operations. Markdown understands basic line breaks so you can generally just type text.</p>\n<p>Markdown also allows for raw HTML inside of a markdown document, so if you want to embed something more fancy than what Markdowns syntax can do you can always fall back to HTML. However to keep documents readable that's generally not recommended.</p>\n<h3>Basic Markdown Syntax</h3>\n<p>The following are a few examples of the most common things you are likely to do with Markdown while building typical documentation.</p>\n<h3>Bold and Italic</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\nThis text **is bold**.\nThis text *is italic*.</code></pre></div>\n<p>This text is bold.\nThis text <em>is italic</em>.</p>\n<h3>Header Text</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n# Header 1\n## Header 2\n### Header 3\n#### Header 4\n##### Header 5\n###### Header 6</code></pre></div>\n<h3>Header 1</h3>\n<h3>Header 2</h3>\n<h3>Header 3</h3>\n<h4>Header 4</h4>\n<p>Header 5Header 6</p>\n<h3>Line Continuation</h3>\n<p>By default Markdown adds paragraphs at double line breaks. Single line breaks by themselves are simply wrapped together into a single line. If you want to have soft returns that break a single line, add two spaces at the end of the line.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\nThis line has a paragraph break at the end (empty line after).\n\nTheses two lines should display as a single\nline because there's no double space at the end.\n\nThe following line has a soft break at the end (two spaces at end)\nThis line should be following on the very next line.</code></pre></div>\n<p>This line has a paragraph break at the end (empty line after).</p>\n<p>Theses two lines should display as a single line because there's no double space at the end.</p>\n<p>The following line has a soft break at the end (two spaces at end)\nThis line should be following on the very next line.</p>\n<h3>Links</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n[Help Builder Web Site](https://helpbuilder.west-wind.com/)</code></pre></div>\n<p><a href=\"http://helpbuilder.west-wind.com/\" class=\"markup--anchor markup--p-anchor\">Help Builder Web Site</a></p>\n<p>If you need additional image tags like targets or title attributes you can also embed HTML directly:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\nGo the Help Builder sitest Wind site: &lt;a href=\"http://west-wind.com/\" target=\"_blank\">Help Builder Site&lt;/a>.</code></pre></div>\n<h3>Images</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n![Help Builder Web Site](https://helpbuilder.west-wind.com/images/HelpBuilder_600.png)</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ibU0D-Zr0qDT5h3z.png\" class=\"graf-image\" />\n</figure>### Block Quotes\n<p>Block quotes are callouts that are great for adding notes or warnings into documentation.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n> ###  Headers break on their own\n> Note that headers don't need line continuation characters\nas they are block elements and automatically break. Only text\nlines require the double spaces for single line breaks.</code></pre></div>\n<blockquote>\n<p><em>Headers break on their own</em></p>\n</blockquote>\n<blockquote>\n<p><em>Note that headers don't need line continuation characters as they are block elements and automatically break. Only text lines require the double spaces for single line breaks.</em></p>\n</blockquote>\n<h3>Fontawesome Icons</h3>\n<p>Help Builder includes a custom syntax for <a href=\"http://fortawesome.github.io/Font-Awesome/icons/\" class=\"markup--anchor markup--p-anchor\">FontAwesome</a> icons in its templates. You can embed a <code class=\"language-text\">@ icon-</code> followed by a font-awesome icon name to automatically embed that icon without full HTML syntax.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\nGear:  Configuration</code></pre></div>\n<p>Configuration</p>\n<h3>HTML Markup</h3>\n<p>You can also embed plain HTML markup into the page if you like. For example, if you want full control over fontawesome icons you can use this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\nThis text can be **embedded** into Markdown:\n&lt;i class=\"fa fa-refresh fa-spin fa-lg\"></code></pre></div>\n<p></i> Refresh Page</p>\n<p>This text can be embedded into Markdown:\nRefresh Page</p>\n<h3>Unordered Lists</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n* Item 1\n* Item 2\n* Item 3\nThis text is part of the third item. Use two spaces at end of the the list item to break the line.\n\nA double line break, breaks out of the list.</code></pre></div>\n<ul>\n<li><span id=\"7904\">Item 1</span></li>\n<li><span id=\"1cf1\">Item 2</span></li>\n<li><span id=\"ded6\">Item 3\nThis text is part of the third item. Use two spaces at end of the the list item to break the line.</span></li>\n</ul>\n<p>A double line break, breaks out of the list.</p>\n<h3>Ordered Lists</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n1. **Item 1**\nItem 1 is really something\n2. **Item 2**\nItem two is really something else\n\nIf you want lines to break using soft returns use two spaces at the end of a line.</code></pre></div>\n<ol>\n<li><span id=\"01d6\">Item 1 Item 1 is really something</span></li>\n<li><span id=\"51ea\">Item 2\nItem two is really something else</span></li>\n</ol>\n<p>If you want to lines to break using soft returns use to spaces at the end of a line.</p>\n<h3>Inline Code</h3>\n<p>If you want to embed code in the middle of a paragraph of text to highlight a coding syntax or class/member name you can use inline code syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\nStructured statements like `for x =1 to 10` loop structures\ncan be codified using single back ticks.</code></pre></div>\n<p>Structured statements like <code class=\"language-text\">for x =1 to 10</code> loop structures can be codified using single back ticks.</p>\n<h3>Code Blocks with Syntax Highlighting</h3>\n<p>Markdown supports code blocks syntax in a variety of ways:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\nThe following code demonstrates:\n\n    // This is code by way of four leading spaces\n    // or a leading tab\n\nMore text here</code></pre></div>\n<p>The following code demonstrates:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pgsql\n\n// This is code by way of four leading spaces\n// or a leading tab</code></pre></div>\n<p>More text here</p>\n<h3>Code Blocks</h3>\n<p>You can also use triple back ticks plus an optional coding language to support for syntax highlighting (space injected before last ` to avoid markdown parsing):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n`` `csharp\n// this code will be syntax highlighted\nfor(var i=0; i++; i &lt; 10)\n{\n    Console.WriteLine(i);\n}\n`` `\n\ncsharp\n\n// this code will be syntax highlighted\nfor(var i=0; i++; i &lt; 10)\n{\n    Console.WriteLine(i);\n}</code></pre></div>\n<p>Many languages are supported: html, xml, javascript, css, csharp, foxpro, vbnet, sql, python, ruby, php and many more. Use the Code drop down list to get a list of available languages.</p>\n<p>You can also leave out the language to get no syntax coloring but the code box:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n`` `dos\nrobocopy c:\\temp\\test d:\\temp\\test\n`` `\n\ndos\n\nrobocopy c:\\temp\\test d:\\temp\\test</code></pre></div>\n<p>To create a formatted block but without formatting use the <code class=\"language-text\">txt</code> format:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">markdown\n\n`` `txt\nThis is some text that will not be syntax highlighted\nbut shows up in a code box.\n`` `</code></pre></div>\n<p>which gives you:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">text\n\nThis is some text that will not be syntax highlighted\nbut shows up in a code box.</code></pre></div>\n<p><a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--p-anchor\">bgoonz's gists · GitHub</a></p>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/3497ce56de3\">March 8, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/an-introduction-to-markdown-bonus-markdown-templates-included-3497ce56de3\" class=\"p-canonical\">Canonical link</a></p>\n<p>on September 23, 2021.</p>"},{"url":"/blog/passing-arguments-to-a-callback-in-js/","relativePath":"blog/passing-arguments-to-a-callback-in-js.md","relativeDir":"blog","base":"passing-arguments-to-a-callback-in-js.md","name":"passing-arguments-to-a-callback-in-js","frontmatter":{"title":"Passing Arguments To A Callback In JS","template":"post","subtitle":"By default you cannot pass arguments to a callback function","excerpt":"By default you cannot pass arguments to a callback function","date":"2022-04-17T08:07:40.104Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-first-example.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-first-example.png?raw=true","image_position":"left","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/js.yaml"],"tags":["src/data/tags/javascript.yaml","src/data/tags/links.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/data-structures-algorithms-resources.md"],"cmseditable":true},"html":"<p>By default you cannot pass arguments to a callback function. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi human'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'someelem'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can take advantage of the closure scope in Javascript to pass arguments to callback functions. Check this example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'sum = '</span><span class=\"token punctuation\">,</span> a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> x <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n    y <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'someelem'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>What are closures?</h3>\n<p>Closures are functions that refer to independent (free) variables. In other words, the function defined in the closure 'remembers' the environment in which it was created. <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures\">Check MDN Documentation</a> to learn more.</p>\n<p>So this way the arguments <code class=\"language-text\">x</code> and <code class=\"language-text\">y</code> are in scope of the callback function when it is called.</p>\n<p>Another method to do this is using the <code class=\"language-text\">bind</code> method. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">alertText</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">text</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'someelem'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token function\">alertText</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/blog/netlify-cms/","relativePath":"blog/netlify-cms.md","relativeDir":"blog","base":"netlify-cms.md","name":"netlify-cms","frontmatter":{"title":"Netlify CMS","subtitle":"Netlify CMS Reference Sheet","date":"2021-09-30","thumb_image_alt":"image of","excerpt":"Netlify CMS is an open source content management system for your Git workflow that enables you to provide editors with a friendly UI and intuitive workflows","seo":{"title":"Netlify CMS Reference Sheet","description":"Netlify CMS is an open source content management system for your Git workflow that enables you to provide editors with a friendly UI and intuitive workflows","robots":[],"extra":[{"name":"og:image","value":"images/netlify-dee8d6ae.svg","keyName":"property","relativeUrl":true},{"name":"og:title","value":"Intro to Netlify CMS","keyName":"property","relativeUrl":false},{"name":"twitter:card","value":"Intro to Netlify CMS","keyName":"name","relativeUrl":false}]},"template":"post","thumb_image":"images/netlify.png","image":"images/netlify-26904b46.svg"},"html":"<h1>Overview\n\n</h1>\n<p>Netlify CMS is an open source content management system for your Git workflow that enables you to provide editors with a friendly UI and intuitive workflows. You can use it with any static site generator to create faster, more flexible web projects. Content is stored in your Git repository alongside your code for easier versioning, multi-channel publishing, and the option to handle content updates directly in Git.</p>\n<p>At its core, Netlify CMS is an open-source React app that acts as a wrapper for the Git workflow, using the GitHub, GitLab, or Bitbucket API. This provides many advantages, including:</p>\n<ul>\n<li><strong>Fast, web-based UI:</strong> With rich-text editing, real-time preview, and drag-and-drop media uploads.</li>\n<li>-</li>\n<li><strong>Platform agnostic:</strong> Works with most static site generators.</li>\n<li>-</li>\n<li><strong>Easy installation:</strong> Add two files to your site and hook up the backend by including those f</li>\n<li>-</li>\n<li><strong>Modern authentication:</strong> Using GitHub, GitLab, or Bitbucket and JSON web tokens.</li>\n<li><strong>Flexible content types:</strong> Specify an unlimited number of content types with custom fields.</li>\n<li><strong>Fully extensible:</strong> Create custom-styled previews, UI widgets, and editor plugins.</li>\n</ul>\n<h2>Netlify CMS vs. Netlify</h2>\n<p><a href=\"https://www.netlify.com/\">Netlify.com</a> is a platform you can use to automatically build, deploy, serve, and manage your frontend sites and web apps. It also provides a variety of other features like form processing, serverless functions, and split testing. Not all Netlify sites use Netlify CMS, and not all sites using Netlify CMS are on Netlify.</p>\n<p>The folks at Netlify created Netlify CMS to fill a gap in the static site generation pipeline. There were some great proprietary headless CMS options, but no real contenders that were open source and extensible—that could turn into a community-built ecosystem like WordPress or Drupal. For that reason, Netlify CMS is <em>made</em> to be community-driven, and has never been locked to the Netlify platform (despite the name).</p>\n<p>With this in mind, you can:</p>\n<ul>\n<li>Use Netlify CMS without Netlify and deploy your site where you always have, hooking up your own CI, site hosting, CDN, etc.</li>\n<li>-</li>\n<li>Use Netlify without Netlify CMS and edit your static site in your code editor.</li>\n<li>Or, use them together and have a fully-working CMS-enabled site with <a href=\"https://www.netlifycms.org/docs/start-with-a-template/\">one click</a>!</li>\n</ul>\n<p>If you hook up Netlify CMS to your website, you're basically adding a tool for content editors to make commits to your site repository without touching code or learning Git.</p>\n<ul>\n<li>Add to Your Site<strong>These generatorsstore static files in</strong>Jekyll, GitBook/ (project root)Hugo, Gatsby, Nuxt, Gridsome, Zola, Sapper/staticNext/publicHexo, Middleman, Jigsaw/sourceSpike/viewsWyam/inputPelican/contentVuePress/.vuepress/publicElmstatic/_site11ty/_sitepreact-cli/src/staticnamePost type identifier, used in routes. Must be unique.labelWhat the admin UI calls the post type.folderWhere files of this type are stored, relative to the repo root.createSet to true to allow users to create new files in this collection.slugTemplate for filenames. {{year}}, {{month}}, and {{day}} pulls from the post's date field or save date. {{slug}} is a url-safe version of the post's title. Default is simply {{slug}}.fieldsFields listed here are shown as fields in the content editor, then saved as front matter at the beginning of the document (except for body, which follows the front matter). Each field contains the following properties:</li>\n</ul>\n<p>You can adapt Netlify CMS to a wide variety of projects. It works with any content written in markdown, JSON, YAML, or TOML files, stored in a repo on <a href=\"https://github.com/\">GitHub</a>, <a href=\"https://about.gitlab.com/\">GitLab</a>, or <a href=\"https://bitbucket.org/\">Bitbucket</a>. You can also create your own custom backend.</p>\n<p>This tutorial guides you through the steps for adding Netlify CMS to a site that's built with a common <a href=\"https://www.staticgen.com/\">static site generator</a>, like Jekyll, Hugo, Hexo, or Gatsby. Alternatively, you can <a href=\"https://www.netlifycms.org/docs/start-with-a-template\">start from a template</a> or dive right into <a href=\"https://www.netlifycms.org/docs/configuration-options\">configuration options</a>.</p>\n<h2>App File Structure</h2>\n<p>A static admin folder contains all Netlify CMS files, stored at the root of your published site. Where you store this folder in the source files depends on your static site generator. Here's the static file location for a few of the most popular static site generators:</p>\n<p>If your generator isn't listed here, you can check its documentation, or as a shortcut, look in your project for a css or images folder. The contents of folders like that are usually processed as static files, so it's likely you can store your admin folder next to those. (When you've found the location, feel free to add it to these docs by <a href=\"https://github.com/netlify/netlify-cms/blob/master/CONTRIBUTING.md#pull-requests\">filing a pull request</a>!)</p>\n<p>Inside the admin folder, you'll create two files:</p>\n<p>The first file, admin/index.html, is the entry point for the Netlify CMS admin interface. This means that users navigate to yoursite.com/admin/ to access it. On the code side, it's a basic HTML starter page that loads the Netlify CMS JavaScript file. The second file, admin/config.yml, is the heart of your Netlify CMS installation, and a bit more complex. The <a href=\"https://www.netlifycms.org/docs/add-to-your-site/#configuration\">Configuration</a> section covers the details.</p>\n<p>In this example, we pull the admin/index.html file from a public CDN.</p>\n<p>In the code above the script is loaded from the unpkg CDN. Should there be any issue, jsDelivr can be used as an alternative source. Simply set the src to <a href=\"https://cdn.jsdelivr.net/npm/netlify-cms@%5E2.0.0/dist/netlify-cms.js\">https://cdn.jsdelivr.net/npm/netlify-cms@^2.0.0/dist/netlify-cms.js</a></p>\n<h3>Installing with npm</h3>\n<p>You can also use Netlify CMS as an npm module. Wherever you import Netlify CMS, it automatically runs, taking over the current page. Make sure the script that imports it only runs on your CMS page. First install the package and save it to your project:</p>\n<p>Then import it (assuming your project has tooling for imports):</p>\n<h2>Configuration</h2>\n<p>Configuration is different for every site, so we'll break it down into parts. Add all the code snippets in this section to your admin/config.yml file.</p>\n<h3>Backend</h3>\n<p>We're using <a href=\"https://www.netlify.com/\">Netlify</a> for our hosting and authentication in this tutorial, so backend configuration is fairly straightforward.</p>\n<p>For GitHub and GitLab repositories, you can start your Netlify CMS config.yml file with these lines:</p>\n<p><em>(For Bitbucket repositories, use the</em><a href=\"https://www.netlifycms.org/docs/bitbucket-backend\"><em>Bitbucket backend</em></a><em>instructions instead.)</em></p>\n<p>The configuration above specifies your backend protocol and your publication branch. Git Gateway is an open source API that acts as a proxy between authenticated users of your site and your site repo. (We'll get to the details of that in the <a href=\"https://www.netlifycms.org/docs/add-to-your-site/#authentication\">Authentication section</a> below.) If you leave out the branch declaration, it defaults to master.</p>\n<h3>Editorial Workflow</h3>\n<p><strong>Note:</strong> Editorial workflow works with GitHub repositories, and support for GitLab and Bitbucket is <a href=\"https://www.netlifycms.org/docs/beta-features/#gitlab-and-bitbucket-editorial-workflow-support\">in beta</a>.</p>\n<p>By default, saving a post in the CMS interface pushes a commit directly to the publication branch specified in backend. However, you also have the option to enable the <a href=\"https://www.netlifycms.org/docs/configuration-options/#publish-mode\">Editorial Workflow</a>, which adds an interface for drafting, reviewing, and approving posts. To do this, add the following line to your Netlify CMS config.yml:</p>\n<h3>Media and Public Folders</h3>\n<p>Netlify CMS allows users to upload images directly within the editor. For this to work, the CMS needs to know where to save them. If you already have an images folder in your project, you could use its path, possibly creating an uploads sub-folder, for example:</p>\n<p>If you're creating a new folder for uploaded media, you'll need to know where your static site generator expects static files. You can refer to the paths outlined above in <a href=\"https://www.netlifycms.org/docs/add-to-your-site/#app-file-structure\">App File Structure</a>, and put your media folder in the same location where you put the admin folder.</p>\n<p>Note that themedia_folder file path is relative to the project root, so the example above would work for Jekyll, GitBook, or any other generator that stores static files at the project root. However, it would not work for Hugo, Hexo, Middleman or others that store static files in a subfolder. Here's an example that could work for a Hugo site:</p>\n<p>The configuration above adds a new setting, public<em>folder. While media</em>folder specifies where uploaded files are saved in the repo, public_folder indicates where they are found in the published site. Image src attributes use this path, which is relative to the file where it's called. For this reason, we usually start the path at the site root, using the opening /.</p>\n<p><em>If public</em>folder is not set, Netlify CMS defaults to the same value as media<em>folder, adding an opening / if one is not included.</em></p>\n<h3>Collections</h3>\n<p>Collections define the structure for the different content types on your static site. Since every site is different, the collections settings differ greatly from one site to the next.</p>\n<p>Let's say your site has a blog, with the posts stored in _posts/blog, and files saved in a date-title format, like 1999-12-31-lets-party.md. Each post begins with settings in yaml-formatted front matter, like so:</p>\n<p>Given this example, our collections settings would look like this in your NetlifyCMS config.yml file:</p>\n<p>Let's break that down:</p>\n<ul>\n<li>label: Field label in the editor UI.</li>\n<li>-</li>\n<li>name: Field name in the document front matter.</li>\n<li>-</li>\n<li>widget: Determines UI style and value data type (details below).</li>\n<li>default (optional): Sets a default value for the field.</li>\n</ul>\n<p>As described above, the widget property specifies a built-in or custom UI widget for a given field. When a content editor enters a value into a widget, that value is saved in the document front matter as the value for the name specified for that field. A full listing of available widgets can be found in the <a href=\"https://www.netlifycms.org/docs/widgets\">Widgets doc</a>.</p>\n<p>Based on this example, you can go through the post types in your site and add the appropriate settings to your Netlify CMS config.yml file. Each post type should be listed as a separate node under the collections field. See the <a href=\"https://www.netlifycms.org/docs/configuration-options/#collections\">Collections reference doc</a> for more configuration options.</p>\n<h3>Filter</h3>\n<p>The entries for any collection can be filtered based on the value of a single field. The example collection below only shows post entries with the value en in the language field.</p>\n<h2>Authentication</h2>\n<p>Now that you have your Netlify CMS files in place and configured, all that's left is to enable authentication. We're using the <a href=\"https://www.netlify.com/\">Netlify</a> platform here because it's one of the quickest ways to get started, but you can learn about other authentication options in the <a href=\"https://www.netlifycms.org/docs/backends-overview\">Backends</a> doc.</p>\n<h3>Setup on Netlify</h3>\n<p>Netlify offers a built-in authentication service called Identity. In order to use it, connect your site repo with Netlify. Netlify has published a general <a href=\"https://www.netlify.com/blog/2016/10/27/a-step-by-step-guide-deploying-a-static-site-or-single-page-app/\">Step-by-Step Guide</a> for this, along with detailed guides for many popular static site generators, including <a href=\"https://www.netlify.com/blog/2015/10/28/a-step-by-step-guide-jekyll-3.0-on-netlify/\">Jekyll</a>, <a href=\"https://www.netlify.com/blog/2016/09/21/a-step-by-step-guide-victor-hugo-on-netlify/\">Hugo</a>, <a href=\"https://www.netlify.com/blog/2015/10/26/a-step-by-step-guide-hexo-on-netlify/\">Hexo</a>, <a href=\"https://www.netlify.com/blog/2015/10/01/a-step-by-step-guide-middleman-on-netlify/\">Middleman</a>, <a href=\"https://www.netlify.com/blog/2016/02/24/a-step-by-step-guide-gatsby-on-netlify/\">Gatsby</a>, and more.</p>\n<h3>Enable Identity and Git Gateway</h3>\n<p>Netlify's Identity and Git Gateway services allow you to manage CMS admin users for your site without requiring them to have an account with your Git host or commit access on your repo. From your site dashboard on Netlify:</p>\n<ol>\n<li>Go to <strong>Settings > Identity</strong>, and select <strong>Enable Identity service</strong>.</li>\n<li>Under <strong>Registration preferences</strong>, select <strong>Open</strong> or <strong>Invite only</strong>. In most cases, you want only invited users to access your CMS, but if you're just experimenting, you can leave it open for convenience.</li>\n<li>If you'd like to allow one-click login with services like Google and GitHub, check the boxes next to the services you'd like to use, under <strong>External providers</strong>.</li>\n<li>Scroll down to <strong>Services > Git Gateway</strong>, and click <strong>Enable Git Gateway</strong>. This authenticates with your Git host and generates an API access token. In this case, we're leaving the <strong>Roles</strong> field blank, which means any logged in user may access the CMS. For information on changing this, check the <a href=\"https://www.netlify.com/docs/identity/\">Netlify Identity documentation</a>.</li>\n</ol>\n<h3>Add the Netlify Identity Widget</h3>\n<p>With the backend set to handle authentication, now you need a frontend interface to connect to it. The open source Netlify Identity Widget is a drop-in widget made for just this purpose. To include the widget in your site, add the following script tag in two places:</p>\n<p>Add this to the &#x3C;head> of your CMS index page at /admin/index.html, as well as the &#x3C;head> of your site's main index page. Depending on how your site generator is set up, this may mean you need to add it to the default template, or to a \"partial\" or \"include\" template. If you can find where the site stylesheet is linked, that's probably the right place. Alternatively, you can include the script in your site using Netlify's <a href=\"https://www.netlify.com/docs/inject-analytics-snippets/\">Script Injection</a> feature.</p>\n<p>When a user logs in with the Netlify Identity widget, an access token directs to the site homepage. In order to complete the login and get back to the CMS, redirect the user back to the /admin/ path. To do this, add the following script before the closing body tag of your site's main index page:</p>\n<p>Note: This example script requires modern JavaScript and does not work on IE11. For legacy browser support, use function expressions (function () {}) in place of the arrow functions (() => {}), or use a transpiler such as <a href=\"https://babeljs.io/\">Babel</a>.</p>\n<h2>Accessing the CMS</h2>\n<p>Your site CMS is now fully configured and ready for login!</p>\n<p>If you set your registration preference to \"Invite only,\" invite yourself (and anyone else you choose) as a site user. To do this, select the <strong>Identity</strong> tab from your site dashboard, and then select the <strong>Invite users</strong> button. Invited users receive an email invitation with a confirmation link. Clicking the link will take you to your site with a login prompt.</p>\n<p>If you left your site registration open, or for return visits after confirming an email invitation, access your site's CMS at yoursite.com/admin/.</p>\n<p><strong>Note:</strong> No matter where you access Netlify CMS — whether running locally, in a staging environment, or in your published site — it always fetches and commits files in your hosted repository (for example, on GitHub), on the branch you configured in your Netlify CMS config.yml file. This means that content fetched in the admin UI matches the content in the repository, which may be different from your locally running site. It also means that content saved using the admin UI saves directly to the hosted repository, even if you're running the UI locally or in staging.</p>\n<p>Examples</p>\n<p>Do\nyou have a great, open source example? Submit a pull request to this page!</p>\n<p>Example\nTools\nType\nSource\nMore info</p>\n<p><a href=\"https://github.com/robertcoopercode/gatsby-netlify-cms\">Gatsby &#x26; Netlify\nCMS Meetup Group Template</a>\nGatsby\ndemo\n<a href=\"https://github.com/robertcoopercode/gatsby-netlify-cms\">robertcoopercode/gatsby-netlify-cms</a>\n<a href=\"https://blog.logrocket.com/gatsby-netlify-cms-a-perfect-pairing-d50d59d16f67\">blog\npost</a></p>\n<p><a href=\"https://briandouglas.me/\">This\nDeveloping Journey</a>\nmiddleman\nblog\n<a href=\"https://github.com/bdougie/blog\">bdougie/blog</a>\n<a href=\"https://www.netlify.com/blog/2017/04/20/creating-a-blog-with-middleman-and-netlify-cms/\">blog\npost</a></p>\n<p><a href=\"https://jamstack-cms.netlify.com/\">Jamstack Recipes</a>\nHugo, Azure\ndemo\n<a href=\"https://github.com/hlaueriksson/jamstack-cms\">hlaueriksson/jamstack-cms</a>\n<a href=\"https://conductofcode.io/post/managing-content-for-a-jamstack-site-with-netlify-cms/\">blog\npost</a></p>\n<p><a href=\"https://bael-theme.jake101.com/\">Bael</a>\nVue, Nuxt\nblog\n<a href=\"https://github.com/jake-101/bael-template\">jake-101/bael-template</a>\n<a href=\"https://bael-theme.jake101.com/blog/2018-06-19-top-10-reasons-why\">blog\npost</a></p>\n<p><a href=\"https://www.forestgarden.wales/\">Forest\nGarden Wales</a>\nHugo\nblog\n<a href=\"https://github.com/forestgardenwales/forestgarden.wales\">forestgardenwales/forestgarden.wales</a>\n<a href=\"https://www.forestgarden.wales/blog/now-using-netlify-cms/\">blog\npost</a></p>\n<p><a href=\"https://jekyll-netlifycms.netlify.com/\">Jekyll Demo</a>\nJekyll, Gulp\ndemo\n<a href=\"https://github.com/NickStees/jekyll-cms\">NickStees/jekyll-cms</a>\n<a href=\"https://github.com/NickStees/jekyll-cms\">read me</a></p>\n<p><a href=\"https://alembic-kit-demo.netlify.com/\">Jekyll feat Alembic\nTheme Demo</a>\nJekyll\ndemo\n<a href=\"https://github.com/daviddarnes/alembic-netlifycms-kit\">DavidDarnes/alembic-netlifycms-kit</a>\n<a href=\"https://github.com/daviddarnes/alembic-netlifycms-kit#starter-kit-for-alembic-with-netlify-cms\">read\nme</a></p>\n<p><a href=\"https://eleventy-netlify-boilerplate.netlify.com/\">Eleventy Starter\nProject</a>\nEleventy\ndemo\n<a href=\"https://github.com/danurbanowicz/eleventy-netlify-boilerplate\">danurbanowicz/eleventy-netlify-boilerplate</a>\n<a href=\"https://github.com/danurbanowicz/eleventy-netlify-boilerplate\">read\nme</a></p>\n<p><a href=\"https://yellowcake.netlify.com/\">YellowCake\n- Complete website with blog</a>\nGatsby, Netlify-CMS, Uploadcare\ndemo\n<a href=\"https://github.com/thriveweb/yellowcake/\">thriveweb/yellowcake</a>\n<a href=\"https://thriveweb.com.au/the-lab/yellowcake-gatsby-react-js-starter-project/\">blog\npost</a></p>\n<p><a href=\"https://github.com/renestalder/nuxt-netlify-cms-starter-template\">Vue.js\n- Nuxt.js Starter Project</a>\nVue, Nuxt\ndemo\n<a href=\"https://github.com/renestalder/nuxt-netlify-cms-starter-template\">renestalder/nuxt-netlify-cms-starter-template</a>\n<a href=\"https://github.com/renestalder/nuxt-netlify-cms-starter-template\">read\nme</a></p>\n<p><a href=\"https://hexocms.imst.xyz/\">Hexo\nDemo</a>\nHexo\ndemo\n<a href=\"https://github.com/DemoMacro/Hexo-NetlifyCMS\">DemoMacro/Hexo-NetlifyCMS</a>\n<a href=\"https://github.com/DemoMacro/Hexo-NetlifyCMS\">read me</a></p>\n<p><a href=\"https://gitbook.imst.xyz/\">Gitbook\nDemo</a>\nGitbook\ndemo\n<a href=\"https://github.com/DemoMacro/Gitbook-NetlifyCMS\">DemoMacro/Gitbook-NetlifyCMS</a>\n<a href=\"https://github.com/DemoMacro/Gitbook-NetlifyCMS\">read me</a></p>\n<p><a href=\"https://vuepress.imst.xyz/\">VuePress\nDemo</a>\nVuePress\ndemo\n<a href=\"https://github.com/DemoMacro/VuePress-NetlifyCMS\">DemoMacro/VuePress-NetlifyCMS</a>\n<a href=\"https://github.com/DemoMacro/VuePress-NetlifyCMS\">read\nme</a></p>\n<p><a href=\"https://jigsaw-blog-netlify-netlifycms-template.netlify.com/\">Jigsaw\nBlog Starter Template Demo</a>\nJigsaw\ndemo\n<a href=\"https://github.com/erickpatrick/jigsaw-blog-netlify-netlifycms-template\">erickpatrick/jigsaw-blog-netlify-netlifycms-template</a>\n<a href=\"https://www.erickpatrick.net/blog/augmenting-tightenco-jigsaw-with-netlifycms/\">blog\npost</a></p>\n<p><a href=\"https://nuxt-netlifycms-boilerplate.netlify.com/\">Nuxt &#x26;\nNetlifyCMS Boilerplate</a>\nVue, Nuxt\ndemo\n<a href=\"https://github.com/tylermercer/nuxt-netlifycms-boilerplate\">tylermercer/nuxt-netlifycms-boilerplate</a>\n<a href=\"https://github.com/tylermercer/nuxt-netlifycms-boilerplate\">read\nme</a></p>\n<p><a href=\"https://netlifycms-nextjs.netlify.com/\">Next.js demo</a>\nNext.js\nblog\n<a href=\"https://github.com/masives/netlifycms-nextjs\">masives/netlifycms-nextjs</a>\n<a href=\"https://github.com/masives/netlifycms-nextjs\">read me</a></p>\n<p><a href=\"https://delog-w3layouts.netlify.com/\">Delog - Jamstack\nBlog with Netlify CMS</a>\nGatsby, Netlify-CMS\ndemo\n<a href=\"https://github.com/W3Layouts/gatsby-starter-delog\">W3Layouts/gatsby-starter-delog</a>\n<a href=\"https://w3layouts.com/articles/delog-gatsby-starter-netlify-cms/\">blog\npost</a></p>\n<p><a href=\"https://netlifycms-gridsome.suits.at/\">Netlify CMS template\nfor Gridsome</a>\nGridsome, Vue\ndemo\n<a href=\"https://github.com/suits-at/netlifycms-gridsome\">suits-at/netlifycms-gridsome</a>\n<a href=\"https://github.com/suits-at/netlifycms-gridsome\">read me</a></p>\n<p><a href=\"https://nextjs-netlify-blog-template.netlify.app/\">Next.js blogging\ntemplate for Netlify</a>\nNext.js, Netlify\nblog\n<a href=\"https://github.com/wutali/nextjs-netlify-blog-template\">wutali/nextjs-netlify-blog-template</a>\n<a href=\"https://github.com/wutali/nextjs-netlify-blog-template\">read\nme</a></p>\n<p><a href=\"https://github.com/pulumi/examples/tree/master/aws-ts-netlify-cms-and-oauth\">Netlify\nCMS and OAuth server on AWS</a>\nNetlify, Pulumi, AWS\nblog\n<a href=\"https://github.com/pulumi/examples/tree/master/aws-ts-netlify-cms-and-oauth\">pulumi/examples/aws-ts-netlify-cms-and-oauth</a>\n<a href=\"https://www.pulumi.com/blog/deploying-the-infrastructure-of-oauth-server-for-cms-app/\">blog\npost</a></p>\n<p><a href=\"https://creativedesignsguru.com/demo/Eleventy-Starter-Boilerplate/eleventy-starter-boilerplate-presentation/\">Eleventy\nStarter Boilerplate</a>\nEleventy, Netlify\ndemo\n<a href=\"https://github.com/ixartz/Eleventy-Starter-Boilerplate\">ixartz/Eleventy-Starter-Boilerplate</a>\n<a href=\"https://github.com/ixartz/Eleventy-Starter-Boilerplate\">read\nme</a></p>\n<p><a href=\"https://ntn-boilerplate.netlify.app/\">Nuxt, Tailwind &#x26;\nNetlifyCMS Boilerplate</a>\nVue, Nuxt\ndemo\n<a href=\"https://github.com/Knogobert/ntn-boilerplate\">Knogobert/ntn-boilerplate</a>\n<a href=\"https://github.com/Knogobert/ntn-boilerplate#readme\">read\nme</a></p>\n<p><a href=\"https://kind-mestorf-5a2bc0.netlify.com/\">Gatsby &#x26; Netlify\nCMS Personal Portfolio</a>\nGatsby\nportfolio\n<a href=\"https://github.com/EarlGeorge/React-Gatsby\">EarlGeorge/React-Gatsby</a>\n<a href=\"https://github.com/EarlGeorge/React-Gatsby/blob/master/README.md\">read\nme</a></p>\n<h1>Gatsby\n\n</h1>\n<p>This guide will help you get started using Netlify CMS and Gatsby.</p>\n<p>To get up and running with Gatsby, you'll need to have <a href=\"https://nodejs.org/\">Node.js</a> installed on your computer. <em>Note: Gatsby's minimum supported Node.js version is Node 8.</em></p>\n<h2>Create a new Gatsby site</h2>\n<p>Let's create a new site using the default Gatsby Starter Blog. Run the following commands in the terminal, in the folder where you'd like to create the blog:</p>\n<h2>Get to know Gatsby</h2>\n<p>In your favorite code editor, open up the code generated for your \"Gatsby Starter Blog\" site, and take a look at the content directory.</p>\n<p>You will see that there are multiple Markdown files that represent blog posts. Open one .md file and you will see something like this:</p>\n<p>We can see above that each blog post has a title, a date, a description and a body. Now, let's recreate this using Netlify CMS.</p>\n<h2>Add Netlify CMS to your site</h2>\n<p>First let's install some dependencies. We'll need netlify-cms-app and gatsby-plugin-netlify-cms. Run the following command in the terminal at the root of your site:</p>\n<h3>Configuration</h3>\n<p>For the purpose of this guide we will deploy to Netlify from a GitHub repository which requires the minimum configuration.</p>\n<p>Create a config.yml file in the directory structure you see below:</p>\n<p>In your config.yml file paste the following configuration:</p>\n<p><strong>Note:</strong> The above configuration allows assets to be stored relative to their content. Therefore posts would be stored in the format below as it is in gatsby-starter-blog.</p>\n<p>Finally, add the plugin to your gatsby-config.js.</p>\n<h3>Push to GitHub</h3>\n<p>It's now time to commit your changes and push to GitHub. The Gatsby starter initializes Git automatically for you, so you only need to do:</p>\n<h3>Add your repo to Netlify</h3>\n<p>Go to Netlify and select 'New Site from Git'. Select GitHub and the repository you just pushed to. Click Configure Netlify on GitHub and give access to your repository. Finish the setup by clicking Deploy Site. Netlify will begin reading your repository and starting building your project.</p>\n<h3>Enable Identity and Git Gateway</h3>\n<p>Netlify's Identity and Git Gateway services allow you to manage CMS admin users for your site without requiring them to have an account with your Git host or commit access on your repo. From your site dashboard on Netlify:</p>\n<ol>\n<li>Go to <strong>Settings > Identity</strong>, and select <strong>Enable Identity service</strong>.</li>\n<li>Under <strong>Registration preferences</strong>, select <strong>Open</strong> or <strong>Invite only</strong>. In most cases, you want only invited users to access your CMS, but if you're just experimenting, you can leave it open for convenience.</li>\n<li>If you'd like to allow one-click login with services like Google and GitHub, check the boxes next to the services you'd like to use, under <strong>External providers</strong>.</li>\n<li>Scroll down to <strong>Services > Git Gateway</strong>, and click <strong>Enable Git Gateway</strong>. This authenticates with your Git host and generates an API access token. In this case, we're leaving the <strong>Roles</strong> field blank, which means any logged in user may access the CMS. For information on changing this, check the <a href=\"https://www.netlify.com/docs/identity/\">Netlify Identity documentation</a>.</li>\n</ol>\n<h2>Start publishing</h2>\n<p>It's time to create your first blog post. Login to your site's /admin/ page and create a new post by clicking New Blog. Add a title, a date and some text. When you click Publish, a new commit will be created in your GitHub repo with this format Create Blog \"year-month-date-title\".</p>\n<p>Then Netlify will detect that there was a commit in your repo, and will start rebuilding your project. When your project is deployed you'll be able to see the post you created.</p>\n<h3>Cleanup</h3>\n<p>It is now safe to remove the default Gatsby blog posts.</p>"},{"url":"/blog/python-for-js-dev/","relativePath":"blog/python-for-js-dev.md","relativeDir":"blog","base":"python-for-js-dev.md","name":"python-for-js-dev","frontmatter":{"title":"Python Resources","date":"2021-06-03","image":"images/python.png","seo":{"title":"python","description":"Commodo ante vis placerat interdum massa massa primis","extra":[{"name":"og:type","value":"article","keyName":"property"},{"name":"og:title","value":"python","keyName":"property"},{"name":"og:description","value":"Commodo ante vis placerat interdum massa massa primis","keyName":"property"},{"name":"og:image","value":"images/python.png","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"python"},{"name":"twitter:description","value":"Commodo ante vis placerat interdum massa massa primis"},{"name":"twitter:image","value":"images/python.png","relativeUrl":true}]},"template":"post","thumb_image":"images/superb-triceratops.jpg","thumb_image_alt":"python logo"},"html":"<h1>Python Study Guide for a JavaScript Programmer\n</h1>\n<p><img src=\"https://miro.medium.com/max/1970/1*3V9VOfPk_hrFdbEAd3j-QQ.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/52/0*eC4EvZcv6hhH88jX.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/647/0*eC4EvZcv6hhH88jX.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/60/0*Ez_1PZ93N4FfvkRr.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/608/0*Ez_1PZ93N4FfvkRr.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/60/0*eE3E5H0AoqkhqK1z.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1648/0*eE3E5H0AoqkhqK1z.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/60/0*Q0CMqFd4PozLDFPB.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1638/0*Q0CMqFd4PozLDFPB.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/3216/0*HQpndNhm1Z_xSoHb.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/60/0*qHzGRLTOMTf30miT.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1614/0*qHzGRLTOMTf30miT.png\" alt=\"medium blog image\">[</p>\n<p>](<a href=\"https://github.com/bgoonz\">https://github.com/bgoonz</a>)</p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://py-prac-42.netlify.app/\" width=\"100%\" height=\"1200px\">\n<iframe>\n<h1>Applications of Tutorial &#x26; Cheat Sheet Respectivley (At Bottom Of Tutorial)</h1>\n<h1>Basics</h1>\n<ul>\n<li><strong>PEP8</strong> : Python Enhancement Proposals, style-guide for Python.</li>\n<li>-</li>\n<li>print is the equivalent of console.log.</li>\n</ul>\n<blockquote>\n<p>'print() == console.log()'</p>\n</blockquote>\n<h1># is used to make comments in your code</h1>\n<blockquote>\n<p><em>Python has a built in help function that let's you see a description of the source code without having to navigate to it… \"-SickNasty … Autor Unknown\"</em></p>\n</blockquote>\n<h1>Numbers</h1>\n<ul>\n<li>Python has three types of numbers:</li>\n<li><strong>Integer</strong></li>\n<li><strong>Positive and Negative Counting Numbers.</strong></li>\n</ul>\n<p>No Decimal Point</p>\n<blockquote>\n<p>Created by a literal non-decimal point number … <strong>or</strong> … with the <em>int()</em> constructor.</p>\n</blockquote>\n<p><strong>3. Complex Numbers</strong></p>\n<blockquote>\n<p>Consist of a real part and imaginary part.</p>\n</blockquote>\n<h2>Boolean is a subtype of integer in Python.🤷‍♂️</h2>\n<blockquote>\n<p>If you came from a background in JavaScript and learned to accept the premise(s) of the following meme…</p>\n</blockquote>\n<blockquote>\n<p>Than I am sure you will find the means to suspend your disbelief.</p>\n</blockquote>\n<h1>KEEP IN MIND</h1>\n<blockquote>\n<p><strong>The i is switched to a j in programming.</strong></p>\n</blockquote>\n<p>T*his is because the letter i is common place as the de facto index for any and all enumerable entities so it just makes sense not to compete for name-**space *<em>when there's another 25 letters that don't get used for every loop under the sun. My most medium apologies to Leonhard Euler.</em></p>\n<ul>\n<li><strong>Type Casting</strong> : The process of converting one number to another.</li>\n</ul>\n<p><strong>The arithmetic operators are the same between JS and Python, with two additions:</strong></p>\n<ul>\n<li><em>\"**\" : Double asterisk for exponent.</em></li>\n<li>-</li>\n<li><em>\"//\" : Integer Division.</em></li>\n<li>-</li>\n<li><strong>There are no spaces between math operations in Python.</strong></li>\n<li><strong>Integer Division gives the other part of the number from Module; it is a way to do round down numbers replacing Math.floor() in JS.</strong></li>\n<li><strong>There are no ++ and -- in Python, the only shorthand operators are:</strong></li>\n</ul>\n<h1>Strings</h1>\n<ul>\n<li>Python uses both single and double quotes.</li>\n<li>-</li>\n<li>You can escape strings like so 'Jodi asked, \"What\\'s up, Sam?\"'</li>\n<li>Multiline strings use triple quotes.</li>\n</ul>\n<p><strong>Use the len() function to get the length of a string.</strong></p>\n<h1><strong>Python uses zero-based indexing</strong></h1>\n<h2>Python allows negative indexing (thank god!)</h2>\n<ul>\n<li>Python let's you use ranges</li>\n</ul>\n<p>You can think of this as roughly equivalent to the slice method called on a JavaScript object or string… <em>(mind you that in JS … strings are wrapped in an object (under the hood)… upon which the string methods are actually called. As a immutable privative type <strong>by textbook definition</strong>, a string literal could not hope to invoke most of it's methods without violating the state it was bound to on initialization if it were not for this bit of syntactic sugar.)</em></p>\n<ul>\n<li>The end range is exclusive just like slice in JS.</li>\n</ul>\n<!---->\n<ul>\n<li>The index string function is the equiv. of indexOf() in JS</li>\n</ul>\n<!---->\n<ul>\n<li>The count function finds out how many times a substring appears in a string… pretty nifty for a hard coded feature of the language.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>You can use + to concatenate strings, just like in JS.</strong></li>\n<li>-</li>\n<li><strong>You can also use \"*\" to repeat strings or multiply strings.</strong></li>\n<li><strong>Use the format() function to use placeholders in a string to input values later on.</strong></li>\n</ul>\n<!---->\n<ul>\n<li>*Shorthand way to use format function is:\n*print(f'Your name is {first<em>name} {last</em>name}')</li>\n</ul>\n<h2>Some useful string methods</h2>\n<ul>\n<li><strong>Note that in JS join is used on an Array, in Python it is used on String.</strong></li>\n</ul>\n<!---->\n<ul>\n<li>There are also many handy testing methods.</li>\n</ul>\n<h1>Variables and Expressions</h1>\n<ul>\n<li><strong>Duck-Typing</strong> : Programming Style which avoids checking an object's type to figure out what it can do.</li>\n<li>-</li>\n<li>Duck Typing is the fundamental approach of Python.</li>\n<li>Assignment of a value automatically declares a variable.</li>\n</ul>\n<!---->\n<ul>\n<li><strong><em>You can chain variable assignments to give multiple var names the same value.</em></strong></li>\n</ul>\n<h2>Use with caution as this is highly unreadable</h2>\n<h2>The value and type of a variable can be re-assigned at any time</h2>\n<ul>\n<li>*NaN does not exist in Python, but you can 'create' it like so:\n<strong>print(float(\"nan\"))*</strong></li>\n<li><em>Python replaces null with none.</em></li>\n<li>-</li>\n<li><strong>*none is an object</strong> and can be directly assigned to a variable.*</li>\n</ul>\n<blockquote>\n<p>Using none is a convenient way to check to see why an action may not be operating correctly in your program.</p>\n</blockquote>\n<h1>Boolean Data Type</h1>\n<ul>\n<li>One of the biggest benefits of Python is that it reads more like English than JS does.</li>\n</ul>\n<!---->\n<ul>\n<li>By default, Python considers an object to be true UNLESS it is one of the following:</li>\n<li>-</li>\n<li>Constant None or False</li>\n<li>-</li>\n<li>Zero of any numeric type.</li>\n<li>Empty Sequence or Collection.</li>\n<li>True and False must be capitalized</li>\n</ul>\n<h1>Comparison Operators</h1>\n<ul>\n<li>Python uses all the same equality operators as JS.</li>\n<li>-</li>\n<li>In Python, equality operators are processed from left to right.</li>\n<li>Logical operators are processed in this order:</li>\n<li><strong>NOT</strong></li>\n<li><strong>AND</strong></li>\n<li><strong>OR</strong></li>\n</ul>\n<blockquote>\n<p>Just like in JS, you can use parentheses to change the inherent order of operations.</p>\n<p><strong>Short Circuit</strong> : Stopping a program when a true or false has been reached.</p>\n</blockquote>\n<h1>Identity vs Equality</h1>\n<ul>\n<li>In the Python community it is better to use is and is not over == or !=</li>\n</ul>\n<h1>If Statements</h1>\n<blockquote>\n<p>Remember the order of elif statements matter.</p>\n</blockquote>\n<h1>While Statements</h1>\n<ul>\n<li>Break statement also exists in Python.</li>\n</ul>\n<!---->\n<ul>\n<li>As are continue statements</li>\n</ul>\n<h1>Try/Except Statements</h1>\n<ul>\n<li>Python equivalent to try/catch</li>\n</ul>\n<!---->\n<ul>\n<li>You can name an error to give the output more specificity.</li>\n</ul>\n<!---->\n<ul>\n<li>You can also use the pass commmand to by pass a certain error.</li>\n</ul>\n<!---->\n<ul>\n<li>The pass method won't allow you to bypass every single error so you can chain an exception series like so:</li>\n</ul>\n<!---->\n<ul>\n<li>You can use an else statement to end a chain of except statements.</li>\n</ul>\n<!---->\n<ul>\n<li>finally is used at the end to clean up all actions under any circumstance.</li>\n</ul>\n<!---->\n<ul>\n<li>Using duck typing to check to see if some value is able to use a certain method.</li>\n</ul>\n<h1>Pass</h1>\n<ul>\n<li>Pass Keyword is required to write the JS equivalent of :</li>\n</ul>\n<h1>Functions</h1>\n<ul>\n<li><strong>Function definition includes:</strong></li>\n<li>-</li>\n<li><strong>The def keyword</strong></li>\n<li>-</li>\n<li><strong>The name of the function</strong></li>\n<li>-</li>\n<li><strong>A list of parameters enclosed in parentheses.</strong></li>\n<li><strong>A colon at the end of the line.</strong></li>\n<li><strong>One tab indentation for the code to run.</strong></li>\n<li><strong>You can use default parameters just like in JS</strong></li>\n</ul>\n<h2><strong>Keep in mind, default parameters must always come after regular parameters.</strong></h2>\n<ul>\n<li><em>You can specify arguments by name without destructuring in Python.</em></li>\n</ul>\n<!---->\n<ul>\n<li>The lambda keyword is used to create anonymous functions and are supposed to be one-liners.</li>\n</ul>\n<p>toUpper = lambda s: s.upper()</p>\n<h1>Notes</h1>\n<h2>Formatted Strings</h2>\n<blockquote>\n<p>Remember that in Python join() is called on a string with an array/list passed in as the argument.\nPython has a very powerful formatting engine.\nformat() is also applied directly to strings.</p>\n</blockquote>\n<h1>Comma Thousands Separator</h1>\n<h1>Date and Time</h1>\n<h1>Percentage</h1>\n<h1>Data Tables</h1>\n<p><strong>Python can be used to display html, css, and JS.</strong>\n<em>It is common to use Python as an API (Application Programming Interface)</em></p>\n<h2>Structured Data</h2>\n<h2>Sequence : The most basic data structure in Python where the index determines the order</h2>\n<blockquote>\n<p>List\nTuple\nRange\nCollections : Unordered data structures, hashable values.</p>\n</blockquote>\n<h2>Dictionaries\nSets</h2>\n<h2>Iterable : Generic name for a sequence or collection; any object that can be iterated through</h2>\n<h2>Can be mutable or immutable.\nBuilt In Data Types</h2>\n<h1>Lists are the python equivalent of arrays</h1>\n<h1>You can instantiate</h1>\n<h2>Test if a value is in a list</h2>\n<h2>Instantiated with parentheses</h2>\n<h2>Sometimes instantiated without</h2>\n<h2>Tuple() built in can be used to convert other data into a tuple</h2>\n<h2>Ranges : A list of numbers which can't be changed; often used with for loops</h2>\n<p><strong>Declared using one to three parameters</strong>.</p>\n<blockquote>\n<p>Start : opt. default 0, first # in sequence.\nStop : required next number past the last number in the sequence.\nStep : opt. default 1, difference between each number in the sequence.</p>\n</blockquote>\n<h2>Dictionaries : Mappable collection where a hashable value is used as a key to ref. an object stored in the dictionary</h2>\n<h2>Mutable</h2>\n<p><strong><em>Declared with curly braces of the built in dict()</em></strong></p>\n<blockquote>\n<p><em>Benefit of dictionaries in Python is that it doesn't matter how it is defined, if the keys and values are the same the dictionaries are considered equal.</em></p>\n</blockquote>\n<p><strong>Use the in operator to see if a key exists in a dictionary.</strong></p>\n<p>S<strong>ets : Unordered collection of distinct objects; objects that need to be hashable.</strong></p>\n<blockquote>\n<p><em>Always be unique, duplicate items are auto dropped from the set.</em></p>\n</blockquote>\n<h2>Common Uses</h2>\n<blockquote>\n<p>Removing Duplicates\nMembership Testing\nMathematical Operators: Intersection, Union, Difference, Symmetric Difference.</p>\n</blockquote>\n<p><strong>Standard Set is mutable, Python has a immutable version called frozenset.\nSets created by putting comma seperated values inside braces:</strong></p>\n<h2>Also can use set constructor to automatically put it into a set</h2>\n<p><strong>filter(function, iterable) : creates new iterable of the same type which includes each item for which the function returns true.</strong></p>\n<p><strong>map(function, iterable) : creates new iterable of the same type which includes the result of calling the function on every item of the iterable.</strong></p>\n<p><strong>sorted(iterable, key=None, reverse=False) : creates a new sorted list from the items in the iterable.</strong></p>\n<p><strong>Output is always a list</strong></p>\n<p><strong>key: opt function which coverts and item to a value to be compared.</strong></p>\n<p><strong>reverse: optional boolean.</strong></p>\n<p><strong>enumerate(iterable, start=0) : starts with a sequence and converts it to a series of tuples</strong></p>\n<h2>(0, 'First'), (1, 'Second'), (2, 'Third'), (3, 'Fourth')</h2>\n<h2>(1, 'First'), (2, 'Second'), (3, 'Third'), (4, 'Fourth')</h2>\n<blockquote>\n<p>zip(*iterables) : creates a zip object filled with tuples that combine 1 to 1 the items in each provided iterable.\nFunctions that analyze iterable</p>\n</blockquote>\n<p><strong>len(iterable) : returns the count of the number of items.</strong></p>\n<p><strong>max(*args, key=None) : returns the largest of two or more arguments.</strong></p>\n<p><strong>max(iterable, key=None) : returns the largest item in the iterable.</strong></p>\n<p><em>key optional function which converts an item to a value to be compared.\nmin works the same way as max</em></p>\n<p><strong>sum(iterable) : used with a list of numbers to generate the total.</strong></p>\n<p><em>There is a faster way to concatenate an array of strings into one string, so do not use sum for that.</em></p>\n<p><strong>any(iterable) : returns True if any items in the iterable are true.</strong></p>\n<p><strong>all(iterable) : returns True is all items in the iterable are true.</strong></p>\n<h1>Working with dictionaries</h1>\n<p><strong>dir(dictionary) : returns the list of keys in the dictionary.\nWorking with sets</strong></p>\n<p><strong>Union : The pipe | operator or union(*sets) function can be used to produce a new set which is a combination of all elements in the provided set.</strong></p>\n<h2>Intersection : The &#x26; operator ca be used to produce a new set of only the elements that appear in all sets</h2>\n<p><strong>Symmetric Difference : The ^ operator can be used to produce a new set of only the elements that appear in exactly one set and not in both.</strong></p>\n<h1><strong>For Statements\nIn python, there is only one for loop.</strong></h1>\n<p>Always Includes:</p>\n<blockquote>\n<p>1. The for keyword\n2. A variable name\n3. The 'in' keyword\n4. An iterable of some kid\n5. A colon\n6. On the next line, an indented block of code called the for clause.</p>\n</blockquote>\n<p><strong>You can use break and continue statements inside for loops as well.</strong></p>\n<p><strong>You can use the range function as the iterable for the for loop.</strong></p>\n<p><strong><em>Common technique is to use the len() on a pre-defined list with a for loop to iterate over the indices of the list.</em></strong></p>\n<p><strong>You can loop and destructure at the same time.</strong></p>\n<blockquote>\n<p>Prints 1, 2</p>\n<p>Prints 3, 4</p>\n<p>Prints 5, 6</p>\n</blockquote>\n<p><strong>You can use values() and keys() to loop over dictionaries.</strong></p>\n<p><em>Prints red</em></p>\n<p><em>Prints 42</em></p>\n<p><em>Prints color</em></p>\n<p><em>Prints age</em></p>\n<p><strong>For loops can also iterate over both keys and values.</strong></p>\n<p><strong>Getting tuples</strong></p>\n<p><em>Prints ('color', 'red')</em></p>\n<p><em>Prints ('age', 42)</em></p>\n<p><em>Destructuring to values</em></p>\n<p><em>Prints Key: age Value: 42</em></p>\n<p><em>Prints Key: color Value: red</em></p>\n<p><strong>Looping over string</strong></p>\n<p><strong>When you order arguments within a function or function call, the args need to occur in a particular order:</strong></p>\n<p><em>formal positional args.</em></p>\n<p>*args</p>\n<p><em>keyword args with default values</em></p>\n<p>**kwargs</p>\n<h1><strong>Importing in Python</strong></h1>\n<p><strong>Modules are similar to packages in Node.js</strong>\nCome in different types:</p>\n<p>Built-In,</p>\n<p>Third-Party,</p>\n<p>Custom.</p>\n<p><strong>All loaded using import statements.</strong></p>\n<h1><strong>Terms</strong></h1>\n<blockquote>\n<p>module : Python code in a separate file.\npackage : Path to a directory that contains modules.\n<a href=\"https://init.py/\"><strong>init.py</strong></a> : Default file for a package.\nsubmodule : Another file in a module's folder.\nfunction : Function in a module.</p>\n</blockquote>\n<p><strong>A module can be any file but it is usually created by placing a special file init.py into a folder. pic</strong></p>\n<p><em>Try to avoid importing with wildcards in Python.</em></p>\n<p><em>Use multiple lines for clarity when importing.</em></p>\n<h1>Watching Out for Python 2</h1>\n<p><strong>Python 3 removed &#x3C;> and only uses !=</strong></p>\n<p><strong>format() was introduced with P3</strong></p>\n<p><strong>All strings in P3 are unicode and encoded.\nmd5 was removed.</strong></p>\n<p><strong>ConfigParser was renamed to configparser\nsets were killed in favor of set() class.</strong></p>\n<h2><strong>print was a statement in P2, but is a function in P3.</strong></h2>\n<h1>Topics revisited (in python syntax)</h1>\n<h1>Cheat Sheet</h1>\n<h2>If you found this guide helpful feel free to checkout my github/gists where I host similar content</h2>\n<p><a href=\"https://gist.github.com/bgoonz\">bgoonz's gists · GitHub</a></p>\n<p>Or Checkout my personal Resource Site:</p>\n<h1>Python Cheat Sheet</h1>\n<h1>If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content</h1>"},{"url":"/blog/psql-cheat-sheet/","relativePath":"blog/psql-cheat-sheet.md","relativeDir":"blog","base":"psql-cheat-sheet.md","name":"psql-cheat-sheet","frontmatter":{"title":"PSQl Cheat Sheet","template":"post","subtitle":"Basic Commands","excerpt":"Login to postgresql","date":"2022-04-04T17:27:00.746Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-diagram.jpg?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-diagram.jpg?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/db.yaml"],"tags":["src/data/tags/psql.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/psql-cheat-sheet.md"],"cmseditable":true},"html":"<h1>💻 PSQL💻</h1>\n<blockquote>\n<p>source</p>\n</blockquote>\n<h2>Basic Commands</h2>\n<h3>Login to postgresql</h3>\n<div class=\"gatsby-highlight\" data-language=\"sql\"><pre class=\"language-sql\"><code class=\"language-sql\">psql <span class=\"token operator\">-</span>U postgres\npsql <span class=\"token operator\">-</span>d mydb <span class=\"token operator\">-</span>U myuser <span class=\"token operator\">-</span>W\npsql <span class=\"token operator\">-</span>h myhost <span class=\"token operator\">-</span>d mydb <span class=\"token operator\">-</span>U myuser <span class=\"token operator\">-</span>W\npsql <span class=\"token operator\">-</span>U myuser <span class=\"token operator\">-</span>h myhost <span class=\"token string\">\"dbname=mydb sslmode=require\"</span> <span class=\"token comment\"># ssl connection</span></code></pre></div>\n<h3>Default Admin Login</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token parameter variable\">-u</span> postgres psql <span class=\"token parameter variable\">-U</span> postgres\n<span class=\"token function\">sudo</span> <span class=\"token parameter variable\">-u</span> postgres psql</code></pre></div>\n<h3>List databases on postgresql server</h3>\n<h3>Determine system tables</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token keyword\">select</span> * from pg_tables where tableowner <span class=\"token operator\">=</span> <span class=\"token string\">'postgres'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>List databases from within a pg shell</h3>\n<h3>List databases from UNIX command prompt</h3>\n<h3>Describe a table</h3>\n<h3>Quit psql</h3>\n<h3>Switch postgres database within admin login shell</h3>\n<h3>Reset a user password as admin</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">alter user usertochange with password <span class=\"token string\">'new_passwd'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Show all tables</h3>\n<h3>List all Schemas</h3>\n<h3>List all users</h3>\n<h3>Load data into postgresql</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">psql <span class=\"token parameter variable\">-W</span> <span class=\"token parameter variable\">-U</span> username <span class=\"token parameter variable\">-H</span> <span class=\"token function\">hostname</span> <span class=\"token operator\">&lt;</span> file.sql</code></pre></div>\n<h3>Dump (Backup) Data into file</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">pg_dump <span class=\"token parameter variable\">-W</span> <span class=\"token parameter variable\">-U</span> username <span class=\"token parameter variable\">-h</span> <span class=\"token function\">hostname</span> database_name <span class=\"token operator\">></span> file.sql</code></pre></div>\n<h3>Increment a sequence</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">SELECT nextval<span class=\"token punctuation\">(</span><span class=\"token string\">'my_id_seq'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Create new user</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">CREATE <span class=\"token environment constant\">USER</span> lemmy WITH PASSWORD <span class=\"token string\">'myPassword'</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\"># or</span>\n\n<span class=\"token function\">sudo</span> <span class=\"token parameter variable\">-u</span> postgres createuser lemmy <span class=\"token parameter variable\">-W</span></code></pre></div>\n<h3>Change user password</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">ALTER <span class=\"token environment constant\">USER</span> Postgres WITH PASSWORD <span class=\"token string\">'mypass'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Grant user createdb privilege</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">ALTER <span class=\"token environment constant\">USER</span> myuser WITH createdb<span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Create a superuser user</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">create user mysuper with password <span class=\"token string\">'1234'</span> SUPERUSER\n<span class=\"token comment\"># or even better</span>\ncreate user mysuper with password <span class=\"token string\">'1234'</span> SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION<span class=\"token punctuation\">;</span>\n<span class=\"token comment\"># or</span>\n<span class=\"token function\">sudo</span> <span class=\"token parameter variable\">-u</span> postgres createuser lemmy <span class=\"token parameter variable\">-W</span> <span class=\"token parameter variable\">-s</span></code></pre></div>\n<h3>Upgrade an existing user to superuser</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">alter user mysuper with superuser<span class=\"token punctuation\">;</span>\n<span class=\"token comment\"># or even better</span>\nalter user mysuper with SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION</code></pre></div>\n<h3>Show Database Version</h3>\n<h3>Change Database Owner</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">alter database database_name owner to new_owner<span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Copy a database</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">CREATE DATABASE newdb WITH TEMPLATE originaldb<span class=\"token punctuation\">;</span></code></pre></div>\n<h3>View Database Connections</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">SELECT * FROM pg_stat_activity<span class=\"token punctuation\">;</span></code></pre></div>\n<h3>View show data directory (works on 9.1+)</h3>\n<h3>Show run-time parameters</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">show all<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">select</span> * from pg_settings<span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Show the block size setting</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># show block_size;</span>\n block_size\n------------\n <span class=\"token number\">8192</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">1</span> row<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Show stored procedure source</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">SELECT prosrc FROM pg_proc WHERE proname <span class=\"token operator\">=</span> <span class=\"token string\">'procname'</span></code></pre></div>\n<h3>Grant examples</h3>\n<div class=\"gatsby-highlight\" data-language=\"sql\"><pre class=\"language-sql\"><code class=\"language-sql\"><span class=\"token comment\"># readonly to all tables for myuser</span>\n<span class=\"token keyword\">grant</span> <span class=\"token keyword\">select</span> <span class=\"token keyword\">on</span> <span class=\"token keyword\">all</span> <span class=\"token keyword\">tables</span> <span class=\"token operator\">in</span> <span class=\"token keyword\">schema</span> <span class=\"token keyword\">public</span> <span class=\"token keyword\">to</span> myuser<span class=\"token punctuation\">;</span>\n<span class=\"token comment\"># all privileges on table1 and table2 to myuser</span>\n<span class=\"token keyword\">grant</span> <span class=\"token keyword\">all</span> <span class=\"token keyword\">privileges</span> <span class=\"token keyword\">on</span> table1<span class=\"token punctuation\">,</span> table2<span class=\"token punctuation\">,</span> table3 <span class=\"token keyword\">to</span> myuser<span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Restore Postgres .dump file</h3>\n<div class=\"gatsby-highlight\" data-language=\"sql\"><pre class=\"language-sql\"><code class=\"language-sql\">pg_restore <span class=\"token comment\">--verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump</span></code></pre></div>\n<p><a href=\"https://gist.github.com/kagemusha/1569836\">source</a></p>\n<h3>Find all active sessions and kill them (i.e. for when needing to drop or rename db)</h3>\n<p>Source: <a href=\"http://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it\">http://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it</a></p>\n<div class=\"gatsby-highlight\" data-language=\"sql\"><pre class=\"language-sql\"><code class=\"language-sql\"><span class=\"token comment\"># Postgres 9.6 and above</span>\n<span class=\"token keyword\">SELECT</span> pg_terminate_backend<span class=\"token punctuation\">(</span>pg_stat_activity<span class=\"token punctuation\">.</span>pid<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">FROM</span> pg_stat_activity\n<span class=\"token keyword\">WHERE</span> pg_stat_activity<span class=\"token punctuation\">.</span>datname <span class=\"token operator\">=</span> <span class=\"token string\">'TARGET_DB'</span>\n <span class=\"token operator\">AND</span> pid <span class=\"token operator\">&lt;></span> pg_backend_pid<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\"># Postgres 9.6 and below</span>\n<span class=\"token keyword\">SELECT</span> pg_terminate_backend<span class=\"token punctuation\">(</span>pg_stat_activity<span class=\"token punctuation\">.</span>procpid<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">FROM</span> pg_stat_activity\n<span class=\"token keyword\">WHERE</span> pg_stat_activity<span class=\"token punctuation\">.</span>datname <span class=\"token operator\">=</span> <span class=\"token string\">'TARGET_DB'</span>\n<span class=\"token operator\">AND</span> procpid <span class=\"token operator\">&lt;></span> pg_backend_pid<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Handy Queries</h2>\n<div class=\"gatsby-highlight\" data-language=\"sql\"><pre class=\"language-sql\"><code class=\"language-sql\"><span class=\"token comment\">-- List procedure/function</span>\n<span class=\"token keyword\">SELECT</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">FROM</span> pg_proc <span class=\"token keyword\">WHERE</span> proname<span class=\"token operator\">=</span><span class=\"token string\">'__procedurename__'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- List view (including the definition)</span>\n<span class=\"token keyword\">SELECT</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">FROM</span> pg_views <span class=\"token keyword\">WHERE</span> viewname<span class=\"token operator\">=</span><span class=\"token string\">'__viewname__'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Show DB table space in use</span>\n<span class=\"token keyword\">SELECT</span> pg_size_pretty<span class=\"token punctuation\">(</span>pg_total_relation_size<span class=\"token punctuation\">(</span><span class=\"token string\">'__table_name__'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>:\n\n<span class=\"token comment\">-- Show DB space in use</span>\n<span class=\"token keyword\">SELECT</span> pg_size_pretty<span class=\"token punctuation\">(</span>pg_database_size<span class=\"token punctuation\">(</span><span class=\"token string\">'__database_name__'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Show current user's statement timeout</span>\n<span class=\"token keyword\">show</span> statement_timeout<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Show table indexes</span>\n<span class=\"token keyword\">SELECT</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">FROM</span> pg_indexes <span class=\"token keyword\">WHERE</span> tablename<span class=\"token operator\">=</span><span class=\"token string\">'__table_name__'</span> <span class=\"token operator\">AND</span> schemaname<span class=\"token operator\">=</span><span class=\"token string\">'__schema_name__'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Get all indexes from all tables of a schema:</span>\n<span class=\"token keyword\">SELECT</span>\n   t<span class=\"token punctuation\">.</span>relname <span class=\"token keyword\">AS</span> table_name<span class=\"token punctuation\">,</span>\n   i<span class=\"token punctuation\">.</span>relname <span class=\"token keyword\">AS</span> index_name<span class=\"token punctuation\">,</span>\n   a<span class=\"token punctuation\">.</span>attname <span class=\"token keyword\">AS</span> column_name\n<span class=\"token keyword\">FROM</span>\n   pg_class t<span class=\"token punctuation\">,</span>\n   pg_class i<span class=\"token punctuation\">,</span>\n   pg_index ix<span class=\"token punctuation\">,</span>\n   pg_attribute a<span class=\"token punctuation\">,</span>\n   pg_namespace n\n<span class=\"token keyword\">WHERE</span>\n   t<span class=\"token punctuation\">.</span>oid <span class=\"token operator\">=</span> ix<span class=\"token punctuation\">.</span>indrelid\n   <span class=\"token operator\">AND</span> i<span class=\"token punctuation\">.</span>oid <span class=\"token operator\">=</span> ix<span class=\"token punctuation\">.</span>indexrelid\n   <span class=\"token operator\">AND</span> a<span class=\"token punctuation\">.</span>attrelid <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>oid\n   <span class=\"token operator\">AND</span> a<span class=\"token punctuation\">.</span>attnum <span class=\"token operator\">=</span> <span class=\"token keyword\">ANY</span><span class=\"token punctuation\">(</span>ix<span class=\"token punctuation\">.</span>indkey<span class=\"token punctuation\">)</span>\n   <span class=\"token operator\">AND</span> t<span class=\"token punctuation\">.</span>relnamespace <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>oid\n   <span class=\"token operator\">AND</span> n<span class=\"token punctuation\">.</span>nspname <span class=\"token operator\">=</span> <span class=\"token string\">'kartones'</span>\n<span class=\"token keyword\">ORDER</span> <span class=\"token keyword\">BY</span>\n   t<span class=\"token punctuation\">.</span>relname<span class=\"token punctuation\">,</span>\n   i<span class=\"token punctuation\">.</span>relname\n\n<span class=\"token comment\">-- Queries being executed at a certain DB</span>\n<span class=\"token keyword\">SELECT</span> datname<span class=\"token punctuation\">,</span> application_name<span class=\"token punctuation\">,</span> pid<span class=\"token punctuation\">,</span> backend_start<span class=\"token punctuation\">,</span> query_start<span class=\"token punctuation\">,</span> state_change<span class=\"token punctuation\">,</span> state<span class=\"token punctuation\">,</span> query\n  <span class=\"token keyword\">FROM</span> pg_stat_activity\n  <span class=\"token keyword\">WHERE</span> datname<span class=\"token operator\">=</span><span class=\"token string\">'__database_name__'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Get all queries from all dbs waiting for data (might be hung)</span>\n<span class=\"token keyword\">SELECT</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">FROM</span> pg_stat_activity <span class=\"token keyword\">WHERE</span> waiting<span class=\"token operator\">=</span><span class=\"token string\">'t'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Query analysis</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">-- See the query plan <span class=\"token keyword\">for</span> the given query\nEXPLAIN __query__\n\n-- See and execute the query plan <span class=\"token keyword\">for</span> the given query\nEXPLAIN ANALYZE __query__\n\n-- Collect statistics\nANALYZE <span class=\"token punctuation\">[</span>__table__<span class=\"token punctuation\">]</span></code></pre></div>\n<h2>Querying Data</h2>\n<h3>From a Single Table</h3>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">-- Query data <span class=\"token keyword\">in</span> columns c1, c2 from a table\nSELECT c1, c2 FROM t<span class=\"token punctuation\">;</span>\n\n-- Query distinct rows from a table\nSELECT DISTINCT c1\nFROM t\nWHERE condition<span class=\"token punctuation\">;</span>\n\n-- Sort the result <span class=\"token builtin class-name\">set</span> <span class=\"token keyword\">in</span> ascending or descending order\nSELECT c1, c2\nFROM t\nORDER BY c1 ASC <span class=\"token punctuation\">[</span>DESC<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n-- Skip offset of rows and <span class=\"token builtin class-name\">return</span> the next n rows\nSELECT c1, c2\nFROM t\nORDER BY c1\nLIMIT n\nOFFSET offset<span class=\"token punctuation\">;</span>\n\n-- Group rows using an aggregate <span class=\"token keyword\">function</span>\nSELECT c1, aggregate<span class=\"token punctuation\">(</span>c2<span class=\"token punctuation\">)</span>\nFROM t\nGROUP BY c1<span class=\"token punctuation\">;</span>\n\n-- Filter <span class=\"token function\">groups</span> using HAVING clause\nSELECT c1, aggregate<span class=\"token punctuation\">(</span>c2<span class=\"token punctuation\">)</span> FROM t\nGROUP BY c1\nHAVING condition<span class=\"token punctuation\">;</span></code></pre></div>\n<h3>From Multiple Tables</h3>\n<div class=\"gatsby-highlight\" data-language=\"sql\"><pre class=\"language-sql\"><code class=\"language-sql\"><span class=\"token comment\">-- Inner join t1 and t2</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">INNER</span> <span class=\"token keyword\">JOIN</span> t2\n<span class=\"token keyword\">ON</span> condition<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Left join t1 and t1</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">LEFT</span> <span class=\"token keyword\">JOIN</span> t2\n<span class=\"token keyword\">ON</span> condition<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Right join t1 and t2</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">RIGHT</span> <span class=\"token keyword\">JOIN</span> t2\n<span class=\"token keyword\">ON</span> condition<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Perform full outer join</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">FULL</span> <span class=\"token keyword\">OUTER</span> <span class=\"token keyword\">JOIN</span> t2\n<span class=\"token keyword\">ON</span> condition<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Produce a Cartesian product of rows in tables</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">CROSS</span> <span class=\"token keyword\">JOIN</span> t2<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Another way to perform cross join</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t1<span class=\"token punctuation\">,</span> t2<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Join t1 to itself using INNER JOIN clause</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t1 A\n<span class=\"token keyword\">INNER</span> <span class=\"token keyword\">JOIN</span> t2 B <span class=\"token keyword\">ON</span> condition</code></pre></div>\n<h3>Using SQL Operators</h3>\n<div class=\"gatsby-highlight\" data-language=\"sql\"><pre class=\"language-sql\"><code class=\"language-sql\"><span class=\"token comment\">-- Combine rows from two queries</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2 <span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">UNION</span> <span class=\"token punctuation\">[</span><span class=\"token keyword\">ALL</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2 <span class=\"token keyword\">FROM</span> t2<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Return the intersection of two queries</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2 <span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">INTERSECT</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2 <span class=\"token keyword\">FROM</span> t2<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Subtract a result set from another result set</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2 <span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">EXCEPT</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2 <span class=\"token keyword\">FROM</span> t2<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Query rows using pattern matching %, _</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2 <span class=\"token keyword\">FROM</span> t1\n<span class=\"token keyword\">WHERE</span> c1 <span class=\"token punctuation\">[</span><span class=\"token operator\">NOT</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">LIKE</span> pattern<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Query rows in a list</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t\n<span class=\"token keyword\">WHERE</span> c1\n<span class=\"token punctuation\">[</span><span class=\"token operator\">NOT</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">IN</span> value_list<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Query rows between two values</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2\n<span class=\"token keyword\">FROM</span> t\n<span class=\"token keyword\">WHERE</span> c1\n<span class=\"token operator\">BETWEEN</span> low <span class=\"token operator\">AND</span> high<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">-- Check if values in a table is NULL or not</span>\n<span class=\"token keyword\">SELECT</span> c1<span class=\"token punctuation\">,</span> c2 <span class=\"token keyword\">FROM</span> t\n<span class=\"token keyword\">WHERE</span> c1 <span class=\"token operator\">IS</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">NOT</span><span class=\"token punctuation\">]</span> <span class=\"token boolean\">NULL</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Source</h2>\n<ul>\n<li><a href=\"https://www.postgresql.org/docs/9.6/static/app-psql.html\">PostgreSQL 9.6.0 Documentation</a></li>\n<li><a href=\"https://pgexercises.com\">PostgreSQL Exercises</a></li>\n<li><a href=\"https://www.postgresqltutorial.com/postgresql-cheat-sheets\">PostgreSQL Tutorial</a></li>\n</ul>"},{"url":"/blog/python-resources/","relativePath":"blog/python-resources.md","relativeDir":"blog","base":"python-resources.md","name":"python-resources","frontmatter":{"title":"Python Resources","date":"2021-06-03","image":"images/best-zebra.gif","seo":{"title":"Python Practice","description":"Commodo ante vis placerat interdum massa massa primis","extra":[{"name":"og:type","value":"article","keyName":"property"},{"name":"og:title","value":"Python Practice","keyName":"property"},{"name":"og:description","value":"Commodo ante vis placerat interdum massa massa primis","keyName":"property"},{"name":"og:image","value":"images/2.jpg","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"Python Practice"},{"name":"twitter:description","value":"Commodo ante vis placerat interdum massa massa primis"},{"name":"twitter:image","value":"images/2.jpg","relativeUrl":true}]},"template":"post","thumb_image":"images/superb-amaranth.png","thumb_image_alt":"python logo"},"html":"<h1>Beginners Guide To Python</h1>\n<p><a href=\"https://levelup.gitconnected.com/basic-web-development-environment-setup-9f36c3f15afe\"><strong>Basic Web Development Environment Setup</strong>\n<em>Windows Subsystem for Linux (WSL) and Ubuntu</em>levelup.gitconnected.com</a>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*59V2ZNbyJfsdGR2N20PM7w.png\" alt=\"image\">\n<img src=\"https://cdn-images-1.medium.com/max/800/0*oVIDxWdgJXoIt7CI.jpg\" alt=\"image\"><a href=\"https://trinket.io/python3/2b693977e7\"><strong>Put Python Anywhere on the Web</strong>\n<em>Python in the browser. No installation required.</em>trinket.io</a>\n\n</p>\n<p>My favorite language for maintainability is Python. It has simple, clean syntax, object encapsulation, good library support, and optional named parameters.</p>\n<ul>\n<li>Bram Cohen</li>\n</ul>\n<p>Article on basic web development setup… it is geared towards web but VSCode is an incredibly versitile editor and this stack really could suit just about anyone working in the field of computer science.</p>\n<h3>The Repository &#x26; Live Site Behind This Article:</h3>\n<h3>About Python(Taken From Tutorial Page Of Docs):</h3>\n<p><a href=\"https://docs.python.org/3/tutorial/appetite.html\">Python enables programs to be written compactly and readably. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for several reasons:</a></p>\n<ul>\n<li>the high-level data types allow you to express complex operations in a single statement;</li>\n<li>-</li>\n<li>statement grouping is done by indentation instead of beginning and ending brackets;</li>\n<li>no variable or argument declarations are necessary.</li>\n</ul>\n<h3>Installing Python:</h3>\n<h3>Windows</h3>\n<p>To determine if your Windows computer already has Python 3:</p>\n<ol>\n<li>Open a command prompt by entering command prompt in the Windows 10 search box and selecting the Command Prompt App in the Best match section of the results.</li>\n<li>Enter the following command and then select the Enter key:</li>\n<li>ConsoleCopy</li>\n</ol>\n<p>python --version</p>\n<ol>\n<li>Running python --version may not return a value, or may return an error message stating <em>'python' is not recognized as an internal or external command, operable program or batch file.</em> This indicates Python is not installed on your Windows system.</li>\n<li>If you see the word Python with a set of numbers separated by . characters, some version of Python is installed.</li>\n</ol>\n<h4>i.e.</h4>\n<blockquote>\n<p>Python 3.8.0</p>\n</blockquote>\n<p><strong>As long as the first number is 3</strong>, you have Python 3 installed.</p>\n<blockquote>\n<p>Download Page:</p>\n<p><a href=\"https://www.python.org/downloads/release/python-395/\">https://www.python.org/downloads/release/python-395/</a></p>\n</blockquote>\n<blockquote>\n<p>Download Link:</p>\n<p><a href=\"https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe\">https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe</a></p>\n</blockquote>\n<h3>Install Jupyter Notebooks:</h3>\n<h3>pip</h3>\n<p>If you use pip, you can install it with:</p>\n<p>If installing using pip install --user, you must add the user-level bin directory to your PATH environment variable in order to launch jupyter lab. If you are using a Unix derivative (FreeBSD, GNU / Linux, OS X), you can achieve this by using export PATH=\"$HOME/.local/bin:$PATH\" command.</p>\n<h3>pipenv</h3>\n<p>If you use pipenv, you can install it as:</p>\n<p>or from a git checkout:</p>\n<p>When using pipenv, in order to launch jupyter lab, you must activate the project's virtualenv. For example, in the directory where pipenv's Pipfile and Pipfile.lock live (i.e., where you ran the above commands):</p>\n<p>Alternatively, you can run jupyter lab inside the virtualenv with</p>\n<p><a href=\"https://nbviewer.jupyter.org/github/bgoonz/Jupyter-Notebooks/tree/master/\">Jupyter Notebook Viewer</a></p>\n<h3>Python Syntax</h3>\n<p>Python syntax was made for readability, and easy editing. For example, the python language uses a : and indented code, while javascript and others generally use {} and indented code.</p>\n<h3>First Program</h3>\n<p>Lets create a <a href=\"https://repl.it/languages/python3\">python 3</a> repl, and call it <em>Hello World</em>. Now you have a blank file called <em>main.py</em>. Now let us write our first line of code:</p>\n<blockquote>\n<p><em>Brian Kernighan actually wrote the first \"Hello, World!\" program as part of the documentation for the BCPL programming language developed by Martin Richards.</em></p>\n</blockquote>\n<p>Now, press the run button, which obviously runs the code. If you are not using replit, this will not work. You should research how to run a file with your text editor.</p>\n<h3>Command Line</h3>\n<p>If you look to your left at the console where hello world was just printed, you can see a >, >>>, or $ depending on what you are using. After the prompt, try typing a line of code.</p>\n<p>The command line allows you to execute single lines of code at a time. It is often used when trying out a new function or method in the language.</p>\n<h3>New: Comments!</h3>\n<p>Another cool thing that you can generally do with all languages, are comments. In python, a comment starts with a #. The computer ignores all text starting after the #.</p>\n<p># Write some comments!</p>\n<p>If you have a huge comment, do <strong>not</strong> comment all the 350 lines, just put ''' before it, and ''' at the end. Technically, this is not a comment but a string, but the computer still ignores it, so we will use it.</p>\n<h3>New: Variables!</h3>\n<p>Unlike many other languages, there is no var, let, or const to declare a variable in python. You simply go name = 'value'.</p>\n<p>Remember, there is a difference between integers and strings. <em>Remember: String = \"\".</em> To convert between these two, you can put an int in a str() function, and a string in a int() function. There is also a less used one, called a float. Mainly, these are integers with decimals. Change them using the float() command.</p>\n<p><a href=\"https://repl.it/@bgoonz/second-scr?lite=true&#x26;referrer=https%3A%2F%2Fbryanguner.medium.com\">https://repl.it/@bgoonz/second-scr?lite=true&#x26;referrer=https%3A%2F%2Fbryanguner.medium.com</a></p>\n<p>Instead of using the , in the print function, you can put a + to combine the variables and string.</p>\n<h3>Operators</h3>\n<p>There are many operators in python:</p>\n<ul>\n<li>+</li>\n<li>-</li>\n<li>-</li>\n<li>-</li>\n<li>/</li>\n<li>*\nThese operators are the same in most languages, and allow for addition, subtraction, division, and multiplicaiton.\nNow, we can look at a few more complicated ones:</li>\n</ul>\n<p><em>simpleops.py</em></p>\n<p>You should already know everything shown above, as it is similar to other languages. If you continue down, you will see more complicated ones.</p>\n<p><em>complexop.py</em></p>\n<p>The ones above are to edit the current value of the variable.\nSorry to JS users, as there is no i++; or anything.</p>\n<h3><em>Fun Fact:\nThe python language was named after Monty Python.</em></h3>\n<p>If you really want to know about the others, view <a href=\"https://www.tutorialspoint.com/python/python_basic_operators.htm\">Py Operators</a></p>\n<h3>More Things With Strings</h3>\n<p>Like the title?\nAnyways, a ' and a \" both indicate a string, but <strong>do not combine them!</strong></p>\n<p><em>quotes.py</em></p>\n<p><em>slicing.py</em></p>\n<h3>String Slicing</h3>\n<p>You can look at only certain parts of the string by slicing it, using [num:num].\nThe first number stands for how far in you go from the front, and the second stands for how far in you go from the back.</p>\n<h3>Methods and Functions</h3>\n<p>Here is a list of functions/methods we will go over:</p>\n<ul>\n<li>.strip()</li>\n<li>-</li>\n<li>len()</li>\n<li>-</li>\n<li>.lower()</li>\n<li>-</li>\n<li>.upper()</li>\n<li>.replace()</li>\n<li>.split()</li>\n</ul>\n<h3>New: Input()</h3>\n<p>Input is a function that gathers input entered from the user in the command line. It takes one optional parameter, which is the users prompt.</p>\n<p><em>inp.py</em></p>\n<p>If you wanted to make it smaller, and look neater to the user, you could do…</p>\n<p><em>inp2.py</em></p>\n<p>Running:\n<em>inp.py</em></p>\n<p><em>inp2.py</em></p>\n<h3>New: Importing Modules</h3>\n<p>Python has created a lot of functions that are located in other .py files. You need to import these <strong>modules</strong> to gain access to the,, You may wonder why python did this. The purpose of separate modules is to make python faster. Instead of storing millions and millions of functions, , it only needs a few basic ones. To import a module, you must write input &#x3C;modulename>. Do not add the .py extension to the file name. In this example , we will be using a python created module named random.</p>\n<p><em>module.py</em></p>\n<p>Now, I have access to all functions in the random.py file. To access a specific function in the module, you would do &#x3C;module>.&#x3C;function>. For example:</p>\n<p><em>module2.py</em></p>\n<blockquote>\n<p>*Pro Tip:\nDo from random import randint to not have to do random.randint(), just randint()\nTo import all functions from a module, you could do from random import **</p>\n</blockquote>\n<blockquote>\n</blockquote>\n<h3>New: Loops!</h3>\n<p>Loops allow you to repeat code over and over again. This is useful if you want to print Hi with a delay of one second 100 times.</p>\n<h4>for Loop</h4>\n<p>The for loop goes through a list of variables, making a seperate variable equal one of the list every time.\nLet's say we wanted to create the example above.</p>\n<p><em>loop.py</em></p>\n<p>This will print Hello with a .3 second delay 100 times. This is just one way to use it, but it is usually used like this:</p>\n<p><em>loop2.py</em></p>\n<p><a href=\"https://storage.googleapis.com/replit/images/1539649280875_37d22e6d49e8e8fbc453631def345387.pn\">https://storage.googleapis.com/replit/images/1539649280875_37d22e6d49e8e8fbc453631def345387.pn</a></p>\n<h4>while Loop</h4>\n<p>The while loop runs the code while something stays true. You would put while &#x3C;expression>. Every time the loop runs, it evaluates if the expression is True. It it is, it runs the code, if not it continues outside of the loop. For example:</p>\n<p><em>while.py</em></p>\n<p>Or you could do:</p>\n<p><em>while2.py</em></p>\n<h3>New: if Statement</h3>\n<p>The if statement allows you to check if something is True. If so, it runs the code, if not, it continues on. It is kind of like a while loop, but it executes <strong>only once</strong>. An if statement is written:</p>\n<p><em>if.py</em></p>\n<p>Now, you may think that it would be better if you could make it print only one message. Not as many that are True. You can do that with an elif statement:</p>\n<p><em>elif.py</em></p>\n<p>Now, you may wonder how to run code if none work. Well, there is a simple statement called else:</p>\n<p><em>else.py</em></p>\n<h3>New: Functions (def)</h3>\n<p>So far, you have only seen how to use functions other people have made. Let use the example that you want to print the a random number between 1 and 9, and print different text every time.\nIt is quite tiring to type:</p>\n<p>Characters: 389</p>\n<p><em>nofunc.py</em></p>\n<p>Now with functions, you can seriously lower the amount of characters:</p>\n<p>Characters: 254</p>\n<p><em>functions.py</em></p>\n<h3>Project Based Learning:</h3>\n<p>The following is a modified version of a tutorial posted By: <a href=\"https://replit.com/@InvisibleOne\">InvisibleOne </a></p>\n<p>I would cite the original tutorial it's self but at the time of this writing I can no longer find it on his repl.it profile and so the only reference I have are my own notes from following the tutorial when I first found it.</p>\n<h3>1. Adventure Story</h3>\n<p>The first thing you need with an adventure story is a great storyline, something that is exciting and fun. The idea is, that at each pivotal point in the story, you give the player the opportunity to make a choice.\nFirst things first, let's import the stuff that we need, like this:</p>\n<p>Now, we need some variables to hold some of the player data.</p>\n<p>Ok, now we have the player's name and nickname, let's welcome them to the game</p>\n<p>Now for the story. The most important part of all stories is the introduction, so let's print our introduction</p>\n<p>Now, we'll give the player their first choice</p>\n<p>There you have it, a pretty simple choose your own ending story. You can make it as complex or uncomplex as you like.</p>\n<h3>2. TEXT ENCODER</h3>\n<p>Ever make secret messages as a kid? I used to. Anyways, here's the way you can make a program to encode messages! It's pretty simple. First things first, let's get the message the user wants to encode, we'll use input() for that:</p>\n<p>Now we need to split that string into a list of characters, this part is a bit more complicated.</p>\n<p>Now we need to convert the characters into code, well do this with a for loop:</p>\n<p>Once we've encoded the text, we'll print it back for the user</p>\n<p>And if you want to decode something, it is this same process but in reverse!</p>\n<h3>3. Guess my Number</h3>\n<p>Number guessing games are fun and pretty simple, all you need are a few loops. To start, we need to import random.</p>\n<p>That is pretty simple. Now we'll make a list with the numbers were want available for the game</p>\n<p>Next, we get a random number from the list</p>\n<p>Now, we need to ask the user for input, we'll to this with a while loop</p>\n<p>Have fun with this!</p>\n<h3>4. Notes</h3>\n<p>Here is a more advanced project, but still pretty easy. This will be using a txt file to save some notes. The first thing we need to do is to create a txt file in your repl, name it 'notes.txt'\nNow, to open a file in python we use open('filename', type) The type can be 'r' for read, or 'w' for write. There is another option, but we won't be using that here. Now, the first thing we are going to do is get what the user would like to save:</p>\n<p>Now we'll open our file and save that text</p>\n<p>There we go, now the information is in the file. Next, we'll retrieve it</p>\n<p>There we go, that's how you can open files and close files with python</p>\n<h3>5. Random Dare Generator</h3>\n<p>Who doesn't love a good dare? Here is a program that can generate random dares. The first thing we'll need to do is as always, import random. Then we'll make some lists of dares</p>"},{"url":"/blog/platform-docs/","relativePath":"blog/platform-docs.md","relativeDir":"blog","base":"platform-docs.md","name":"platform-docs","frontmatter":{"title":"Netlify CMS Intro","date":"2021-05-23","image":"images/dtw-slideshow.gif","seo":{"title":"Platform Docs","description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit","extra":[{"name":"og:type","value":"article","keyName":"property"},{"name":"og:title","value":"Platform Docs","keyName":"property"},{"name":"og:description","value":"Lorem ipsum dolor sit amet, consectetur adipiscing elit","keyName":"property"},{"name":"og:image","value":"images/dtw-slideshow.gif","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"Platform Docs"},{"name":"twitter:description","value":"Lorem ipsum dolor sit amet, consectetur adipiscing elit"},{"name":"twitter:image","value":"images/dtw-slideshow.gif","relativeUrl":true}]},"template":"post","thumb_image":"images/netlifycms.png"},"html":"<h1>Add to Your Site | Netlify CMS</h1>\n<blockquote>\n<p>Open source content management for your Git workflow</p>\n</blockquote>\n<p>You can adapt Netlify CMS to a wide variety of projects. It works with any content written in markdown, JSON, YAML, or TOML files, stored in a repo on <a href=\"https://github.com/\">GitHub</a>, <a href=\"https://about.gitlab.com/\">GitLab</a>, or <a href=\"https://bitbucket.org/\">Bitbucket</a>. You can also create your own custom backend.</p>\n<p>This tutorial guides you through the steps for adding Netlify CMS to a site that's built with a common <a href=\"https://www.staticgen.com/\">static site generator</a>, like Jekyll, Hugo, Hexo, or Gatsby. Alternatively, you can <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/start-with-a-template\">start from a template</a> or dive right into <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/configuration-options\">configuration options</a>.</p>\n<h2><a href=\"#app-file-structure\"></a>App File Structure</h2>\n<p>A static <code class=\"language-text\">admin</code> folder contains all Netlify CMS files, stored at the root of your published site. Where you store this folder in the source files depends on your static site generator. Here's the static file location for a few of the most popular static site generators:</p>\n<table>\n<thead>\n<tr>\n<th>These generators</th>\n<th>store static files in</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Jekyll, GitBook</td>\n<td><code class=\"language-text\">/</code> (project root)</td>\n</tr>\n<tr>\n<td>Hugo, Gatsby, Nuxt, Gridsome, Zola, Sapper</td>\n<td><code class=\"language-text\">/static</code></td>\n</tr>\n<tr>\n<td>Next</td>\n<td><code class=\"language-text\">/public</code></td>\n</tr>\n<tr>\n<td>Hexo, Middleman, Jigsaw</td>\n<td><code class=\"language-text\">/source</code></td>\n</tr>\n<tr>\n<td>Spike</td>\n<td><code class=\"language-text\">/views</code></td>\n</tr>\n<tr>\n<td>Wyam</td>\n<td><code class=\"language-text\">/input</code></td>\n</tr>\n<tr>\n<td>Pelican</td>\n<td><code class=\"language-text\">/content</code></td>\n</tr>\n<tr>\n<td>VuePress</td>\n<td><code class=\"language-text\">/.vuepress/public</code></td>\n</tr>\n<tr>\n<td>Elmstatic</td>\n<td><code class=\"language-text\">/_site</code></td>\n</tr>\n<tr>\n<td>11ty</td>\n<td><code class=\"language-text\">/_site</code></td>\n</tr>\n<tr>\n<td>preact-cli</td>\n<td><code class=\"language-text\">/src/static</code></td>\n</tr>\n</tbody>\n</table>\n<p>If your generator isn't listed here, you can check its documentation, or as a shortcut, look in your project for a <code class=\"language-text\">css</code> or <code class=\"language-text\">images</code> folder. The contents of folders like that are usually processed as static files, so it's likely you can store your <code class=\"language-text\">admin</code> folder next to those. (When you've found the location, feel free to add it to these docs by <a href=\"https://github.com/netlify/netlify-cms/blob/master/CONTRIBUTING.md#pull-requests\">filing a pull request</a>!)</p>\n<p>Inside the <code class=\"language-text\">admin</code> folder, you'll create two files:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">admin\n ├ index.html\n └ config.yml</code></pre></div>\n<p>The first file, <code class=\"language-text\">admin/index.html</code>, is the entry point for the Netlify CMS admin interface. This means that users navigate to <code class=\"language-text\">yoursite.com/admin/</code> to access it. On the code side, it's a basic HTML starter page that loads the Netlify CMS JavaScript file. In this example, we pull the file from a public CDN:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;!doctype html>\n&lt;html>\n&lt;head>\n  &lt;meta charset=\"utf-8\" />\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n  &lt;title>Content Manager&lt;/title>\n&lt;/head>\n&lt;body>\n\n  &lt;script src=\"https://unpkg.com/netlify-cms@^2.0.0/dist/netlify-cms.js\"></code></pre></div>\n</script>\n    </body>\n    </html>\n<p>In the code above the <code class=\"language-text\">script</code> is loaded from the <code class=\"language-text\">unpkg</code> CDN. Should there be any issue, <code class=\"language-text\">jsDelivr</code> can be used as an alternative source. Simply set the <code class=\"language-text\">src</code> to <code class=\"language-text\">https://cdn.jsdelivr.net/npm/netlify-cms@^2.0.0/dist/netlify-cms.js</code></p>\n<p>The second file, <code class=\"language-text\">admin/config.yml</code>, is the heart of your Netlify CMS installation, and a bit more complex. The <a href=\"#configuration\">Configuration</a> section covers the details.</p>\n<h3><a href=\"#installing-with-npm\"></a>Installing with npm</h3>\n<p>You can also use Netlify CMS as an npm module. Wherever you import Netlify CMS, it automatically runs, taking over the current page. Make sure the script that imports it only runs on your CMS page. First install the package and save it to your project:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install netlify-cms-app --save</code></pre></div>\n<p>Then import it (assuming your project has tooling for imports):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import CMS from 'netlify-cms-app'\n\nCMS.init()\n\nCMS.registerPreviewTemplate('my-template', MyTemplate)</code></pre></div>\n<h2><a href=\"#configuration\"></a>Configuration</h2>\n<p>Configuration is different for every site, so we'll break it down into parts. Add all the code snippets in this section to your <code class=\"language-text\">admin/config.yml</code> file.</p>\n<h3><a href=\"#backend\"></a>Backend</h3>\n<p>We're using <a href=\"https://www.netlify.com/\">Netlify</a> for our hosting and authentication in this tutorial, so backend configuration is fairly straightforward.</p>\n<p>For GitHub and GitLab repositories, you can start your Netlify CMS <code class=\"language-text\">config.yml</code> file with these lines:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">backend:\n  name: git-gateway\n  branch: master</code></pre></div>\n<p><em>(For Bitbucket repositories, use the <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/docs/bitbucket-backend\">Bitbucket backend</a> instructions instead.)</em></p>\n<p>The configuration above specifies your backend protocol and your publication branch. Git Gateway is an open source API that acts as a proxy between authenticated users of your site and your site repo. (We'll get to the details of that in the <a href=\"#authentication\">Authentication section</a> below.) If you leave out the <code class=\"language-text\">branch</code> declaration, it defaults to <code class=\"language-text\">master</code>.</p>\n<h3><a href=\"#editorial-workflow\"></a>Editorial Workflow</h3>\n<p><strong>Note:</strong> Editorial workflow works with GitHub repositories, and support for GitLab and Bitbucket is <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/docs/beta-features/#gitlab-and-bitbucket-editorial-workflow-support\">in beta</a>.</p>\n<p>By default, saving a post in the CMS interface pushes a commit directly to the publication branch specified in <code class=\"language-text\">backend</code>. However, you also have the option to enable the <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/configuration-options/#publish-mode\">Editorial Workflow</a>, which adds an interface for drafting, reviewing, and approving posts. To do this, add the following line to your Netlify CMS <code class=\"language-text\">config.yml</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">publish_mode: editorial_workflow</code></pre></div>\n<h3><a href=\"#media-and-public-folders\"></a>Media and Public Folders</h3>\n<p>Netlify CMS allows users to upload images directly within the editor. For this to work, the CMS needs to know where to save them. If you already have an <code class=\"language-text\">images</code> folder in your project, you could use its path, possibly creating an <code class=\"language-text\">uploads</code> sub-folder, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">media_folder: \"images/uploads\"</code></pre></div>\n<p>If you're creating a new folder for uploaded media, you'll need to know where your static site generator expects static files. You can refer to the paths outlined above in <a href=\"#app-file-structure\">App File Structure</a>, and put your media folder in the same location where you put the <code class=\"language-text\">admin</code> folder.</p>\n<p>Note that the<code class=\"language-text\">media_folder</code> file path is relative to the project root, so the example above would work for Jekyll, GitBook, or any other generator that stores static files at the project root. However, it would not work for Hugo, Hexo, Middleman or others that store static files in a subfolder. Here's an example that could work for a Hugo site:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">media_folder: \"static/images/uploads\"\npublic_folder: \"/images/uploads\"</code></pre></div>\n<p>The configuration above adds a new setting, <code class=\"language-text\">public_folder</code>. While <code class=\"language-text\">media_folder</code> specifies where uploaded files are saved in the repo, <code class=\"language-text\">public_folder</code> indicates where they are found in the published site. Image <code class=\"language-text\">src</code> attributes use this path, which is relative to the file where it's called. For this reason, we usually start the path at the site root, using the opening <code class=\"language-text\">/</code>.</p>\n<p><em>If `public</em>folder<code class=\"language-text\">is not set, Netlify CMS defaults to the same value as</code>media<em>folder<code class=\"language-text\">, adding an opening</code>/` if one is not included.</em></p>\n<h3><a href=\"#collections\"></a>Collections</h3>\n<p>Collections define the structure for the different content types on your static site. Since every site is different, the <code class=\"language-text\">collections</code> settings differ greatly from one site to the next.</p>\n<p>Let's say your site has a blog, with the posts stored in <code class=\"language-text\">_posts/blog</code>, and files saved in a date-title format, like <code class=\"language-text\">1999-12-31-lets-party.md</code>. Each post begins with settings in yaml-formatted front matter, like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">---\nlayout: blog\ntitle: \"Let's Party\"\ndate: 1999-12-31 11:59:59 -0800\nthumbnail: \"/images/prince.jpg\"\nrating: 5\n---\n\nThis is the post body, where I write about our last chance to party before the Y2K bug destroys us all.</code></pre></div>\n<p>Given this example, our <code class=\"language-text\">collections</code> settings would look like this in your NetlifyCMS <code class=\"language-text\">config.yml</code> file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">collections:\n  - name: \"blog\"\n    label: \"Blog\"\n    folder: \"_posts/blog\"\n    create: true\n    slug: \"{{year}}-{{month}}-{{day}}-{{slug}}\"\n    fields:\n      - {label: \"Layout\", name: \"layout\", widget: \"hidden\", default: \"blog\"}\n      - {label: \"Title\", name: \"title\", widget: \"string\"}\n      - {label: \"Publish Date\", name: \"date\", widget: \"datetime\"}\n      - {label: \"Featured Image\", name: \"thumbnail\", widget: \"image\"}\n      - {label: \"Rating (scale of 1-5)\", name: \"rating\", widget: \"number\"}\n      - {label: \"Body\", name: \"body\", widget: \"markdown\"}</code></pre></div>\n<p>Let's break that down:</p>\n<table>\n<tbody>\n<tr>\n<td>\n<code>name</code>\n</td>\n<td>Post type identifier, used in routes. Must be unique.</td>\n</tr>\n<tr>\n<td>\n<code>label</code>\n</td>\n<td>What the admin UI calls the post type.</td>\n</tr>\n<tr>\n<td>\n<code>folder</code>\n</td>\n<td>Where files of this type are stored, relative to the repo root.</td>\n</tr>\n<tr>\n<td>\n<code>create</code>\n</td>\n<td>Set to <code>true</code> to allow users to create new files in this collection.</td>\n</tr>\n<tr>\n<td>\n<code>slug</code>\n</td>\n<td>Template for filenames. <code>{{year}}</code>, <code>{{month}}</code>, and <code>{{day}}</code> pulls from the post's <code>date</code> field or save date. <code>{{slug}}</code> is a url-safe version of the post's <code>title</code>. Default is simply <code>{{slug}}</code>.</td>\n</tr>\n<tr>\n<td>\n<code>fields</code>\n</td>\n<td>Fields listed here are shown as fields in the content editor, then saved as front matter at the beginning of the document (except for <code>body</code>, which follows the front matter). Each field contains the following properties:<ul>\n<li>\n<code>label</code>: Field label in the editor UI.</li>\n<li>\n<code>name</code>: Field name in the document front matter.</li>\n<li>\n<code>widget</code>: Determines UI style and value data type (details below).</li>\n<li>\n<code>default</code> (optional): Sets a default value for the field.</li>\n</ul>\n</td>\n</tr>\n</tbody>\n</table>\n<p>As described above, the <code class=\"language-text\">widget</code> property specifies a built-in or custom UI widget for a given field. When a content editor enters a value into a widget, that value is saved in the document front matter as the value for the <code class=\"language-text\">name</code> specified for that field. A full listing of available widgets can be found in the <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/widgets\">Widgets doc</a>.</p>\n<p>Based on this example, you can go through the post types in your site and add the appropriate settings to your Netlify CMS <code class=\"language-text\">config.yml</code> file. Each post type should be listed as a separate node under the <code class=\"language-text\">collections</code> field. See the <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/configuration-options/#collections\">Collections reference doc</a> for more configuration options.</p>\n<h3><a href=\"#filter\"></a>Filter</h3>\n<p>The entries for any collection can be filtered based on the value of a single field. The example collection below only shows post entries with the value <code class=\"language-text\">en</code> in the <code class=\"language-text\">language</code> field.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">collections:\n  - name: \"posts\"\n    label: \"Post\"\n    folder: \"_posts\"\n    filter:\n      field: language\n      value: en\n    fields:\n      - {label: \"Language\", name: \"language\"}</code></pre></div>\n<h2><a href=\"#authentication\"></a>Authentication</h2>\n<p>Now that you have your Netlify CMS files in place and configured, all that's left is to enable authentication. We're using the <a href=\"https://www.netlify.com/\">Netlify</a> platform here because it's one of the quickest ways to get started, but you can learn about other authentication options in the <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/docs/backends-overview\">Backends</a> doc.</p>\n<h3><a href=\"#setup-on-netlify\"></a>Setup on Netlify</h3>\n<p>Netlify offers a built-in authentication service called Identity. In order to use it, connect your site repo with Netlify. Netlify has published a general <a href=\"https://www.netlify.com/blog/2016/10/27/a-step-by-step-guide-deploying-a-static-site-or-single-page-app/\">Step-by-Step Guide</a> for this, along with detailed guides for many popular static site generators, including <a href=\"https://www.netlify.com/blog/2015/10/28/a-step-by-step-guide-jekyll-3.0-on-netlify/\">Jekyll</a>, <a href=\"https://www.netlify.com/blog/2016/09/21/a-step-by-step-guide-victor-hugo-on-netlify/\">Hugo</a>, <a href=\"https://www.netlify.com/blog/2015/10/26/a-step-by-step-guide-hexo-on-netlify/\">Hexo</a>, <a href=\"https://www.netlify.com/blog/2015/10/01/a-step-by-step-guide-middleman-on-netlify/\">Middleman</a>, <a href=\"https://www.netlify.com/blog/2016/02/24/a-step-by-step-guide-gatsby-on-netlify/\">Gatsby</a>, and more.</p>\n<h3><a href=\"#enable-identity-and-git-gateway\"></a>Enable Identity and Git Gateway</h3>\n<p>Netlify's Identity and Git Gateway services allow you to manage CMS admin users for your site without requiring them to have an account with your Git host or commit access on your repo. From your site dashboard on Netlify:</p>\n<ol>\n<li>Go to <strong>Settings > Identity</strong>, and select <strong>Enable Identity service</strong>.</li>\n<li>Under <strong>Registration preferences</strong>, select <strong>Open</strong> or <strong>Invite only</strong>. In most cases, you want only invited users to access your CMS, but if you're just experimenting, you can leave it open for convenience.</li>\n<li>If you'd like to allow one-click login with services like Google and GitHub, check the boxes next to the services you'd like to use, under <strong>External providers</strong>.</li>\n<li>Scroll down to <strong>Services > ay</strong>, and click <strong>Enable Git Gateway</strong>. This authenticates with your Git host and generates an API access token. In this case, we're leaving the <strong>Roles</strong> field blank, which means any logged in user may access the CMS. For information on changing this, check the <a href=\"https://www.netlify.com/docs/identity/\">Netlify Identity documentation</a>.</li>\n</ol>\n<h3><a href=\"#add-the-netlify-identity-widget\"></a>Add the Netlify Identity Widget</h3>\n<p>With the backend set to handle authentication, now you need a frontend interface to connect to it. The open source Netlify Identity Widget is a drop-in widget made for just this purpose. To include the widget in your site, add the following script tag in two places:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script src=\"https://identity.netlify.com/v1/netlify-identity-widget.js\"></code></pre></div>\n</script>\n<p>Add this to the <code class=\"language-text\">&lt;head></code> of your CMS index page at <code class=\"language-text\">/admin/index.html</code>, as well as the <code class=\"language-text\">&lt;head></code> of your site's main index page. Depending on how your site generator is set up, this may mean you need to add it to the default template, or to a \"partial\" or \"include\" template. If you can find where the site stylesheet is linked, that's probably the right place. Alternatively, you can include the script in your site using Netlify's <a href=\"https://www.netlify.com/docs/inject-analytics-snippets/\">Script Injection</a> feature.</p>\n<p>When a user logs in with the Netlify Identity widget, an access token directs to the site homepage. In order to complete the login and get back to the CMS, redirect the user back to the <code class=\"language-text\">/admin/</code> path. To do this, add the following script before the closing <code class=\"language-text\">body</code> tag of your site's main index page:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script>\n  if (window.netlifyIdentity) {\n    window.netlifyIdentity.on(\"init\", user => {\n      if (!user) {\n        window.netlifyIdentity.on(\"login\", () => {\n          document.location.href = \"/admin/\";\n        });\n      }\n    });\n  }\n&lt;/script></code></pre></div>\n<p>Note: This example script requires modern JavaScript and does not work on IE11. For legacy browser support, use function expressions (<code class=\"language-text\">function () {}</code>) in place of the arrow functions (<code class=\"language-text\">() => {}</code>), or use a transpiler such as <a href=\"https://babeljs.io/\">Babel</a>.</p>\n<h2><a href=\"#accessing-the-cms\"></a>Accessing the CMS</h2>\n<p>Your site CMS is now fully configured and ready for login!</p>\n<p>If you set your registration preference to \"Invite only,\" invite yourself (and anyone else you choose) as a site user. To do this, select the <strong>Identity</strong> tab from your site dashboard, and then select the <strong>Invite users</strong> button. Invited users receive an email invitation with a confirmation link. Clicking the link will take you to your site with a login prompt.</p>\n<p>If you left your site registration open, or for return visits after confirming an email invitation, access your site's CMS at <code class=\"language-text\">yoursite.com/admin/</code>.</p>\n<p><strong>Note:</strong> No matter where you access Netlify CMS — whether running locally, in a staging environment, or in your published site — it always fetches and commits files in your hosted repository (for example, on GitHub), on the branch you configured in your Netlify CMS config.yml file. This means that content fetched in the admin UI matches the content in the repository, which may be different from your locally running site. It also means that content saved using the admin UI saves directly to the hosted repository, even if you're running the UI locally or in staging.</p>\n<p>Happy posting!</p>\n<p><a href=\"https://www.netlifycms.org/docs/add-to-your-site/\">Source</a></p>"},{"url":"/blog/python-quiz/","relativePath":"blog/python-quiz.md","relativeDir":"blog","base":"python-quiz.md","name":"python-quiz","frontmatter":{"title":"Python Quiz","template":"post","subtitle":"What statement about static methods is true","excerpt":"What statement about static methods is true","date":"2022-05-22T21:56:05.130Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python1-00990432.jpg?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python1-00990432.jpg?raw=true","image_position":"top","author":"src/data/authors/backup.yaml","categories":["src/data/categories/py.yaml"],"tags":["src/data/tags/python.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/data-structures-algorithms-resources.md"],"cmseditable":true},"html":"<h1>Python Quiz</h1>\n<h4>zQ1. What is an abstract class?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> An abstract class is the name for any class from which you can instantiate an object.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstract classes must be redefined any time an object is instantiated from them.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstract classes must inherit from concrete classes.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] An abstract class exists only so that other \"concrete\" classes can inherit from the abstract class.</li>\n</ul>\n<p><a href=\"https://www.geeksforgeeks.org/abstract-classes-in-python/\">reference</a></p>\n<h4>Q2. What happens when you use the build-in function <code class=\"language-text\">any()</code> on a list?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">any()</code> function will randomly return any item from the list.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <code class=\"language-text\">any()</code> function returns True if any item in the list evaluates to True. Otherwise, it returns False.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">any()</code> function takes as arguments the list to check inside, and the item to check for. If \"any\" of the items in the list match the item to check for, the function returns True.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">any()</code> function returns a Boolean value that answers the question \"Are there any items in this list?\"</li>\n</ul>\n<p><strong>example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> <span class=\"token builtin\">any</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Yes, there is True'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Yes<span class=\"token punctuation\">,</span> there <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span></code></pre></div>\n<h4>Q3. What data structure does a binary tree degenerate to if it isn't balanced properly?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] linked list</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> queue</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> set</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> OrderedDict</li>\n</ul>\n<h4>Q4. What statement about static methods is true?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods are called static because they always return <code class=\"language-text\">None</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods can be bound to either a class or an instance of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Static methods serve mostly as utility methods or helper methods, since they can't access or modify a class's state.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods can access and modify the state of a class or an instance of a class.</li>\n</ul>\n<p><a href=\"https://www.geeksforgeeks.org/class-method-vs-static-method-python\">reference</a></p>\n<h4>Q5. What are attributes?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Attributes are long-form version of an <code class=\"language-text\">if/else</code> statement, used when testing for equality between objects.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Attributes are a way to hold data or describe a state for a class or an instance of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Attributes are strings that describe characteristics of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Function arguments are called \"attributes\" in the context of class methods and instance methods.</li>\n</ul>\n<p><strong>Explanation</strong> Attributes defined under the class, arguments goes under the functions. arguments usually refer as parameter, whereas attributes are the constructor of the class or an instance of a class.</p>\n<h4>Q6. What is the term to describe this code?</h4>\n<p><code class=\"language-text\">count, fruit, price = (2, 'apple', 3.5)</code></p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">tuple assignment</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">tuple unpacking</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">tuple matching</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">tuple duplication</code></li>\n</ul>\n<h4>Q7. What built-in list method would you use to remove items from a list?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">.delete()</code> method</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">pop(my_list)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">del(my_list)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">.pop()</code> method</li>\n</ul>\n<p><strong>example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">my_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\nmy_list<span class=\"token punctuation\">.</span>pop<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\nmy_list\n<span class=\"token operator\">>></span><span class=\"token operator\">></span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h4>Q8. What is one of the most common use of Python's sys library?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] to capture command-line arguments given at a file's runtime</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to connect various systems, such as connecting a web front end, an API service, a database, and a mobile app</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to take a snapshot of all the packages and libraries in your virtual environment</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to scan the health of your Python ecosystem while inside a virtual environment</li>\n</ul>\n<h4>Q9. What is the runtime of accessing a value in a dictionary by using its key?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(n), also called linear time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(log n), also called logarithmic time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(n^2), also called quadratic time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] O(1), also called constant time.</li>\n</ul>\n<h4>Q10. What is the correct syntax for defining a class called Game, if it inherits from a parent class called LogicGame?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">class Game(LogicGame): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def Game(LogicGame): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def Game.LogicGame(): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">class Game.LogicGame(): pass</code></li>\n</ul>\n<p><strong>Explanation:</strong> <code class=\"language-text\">The parent class which is inherited is passed as an argument to the child class. Therefore, here the first option is the right answer.</code></p>\n<h4>Q11. What is the correct way to write a doctest?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    sum(4, 3)\n    7\n\n    sum(-4, 5)\n    1\n    \"\"\"</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li>[✅] B</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    >>> sum(4, 3)\n    7\n\n    >>> sum(-4, 5)\n    1\n    \"\"\"</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> C</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    # >>> sum(4, 3)\n    # 7\n\n    # >>> sum(-4, 5)\n    # 1\n    \"\"\"</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> D</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\">###</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">7</span>\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token comment\">###</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<p><strong>explanation</strong> - use ''' to start the doc and add output of the cell after >>></p>\n<h4>Q12. What built-in Python data type is commonly used to represent a stack?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">set</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">list</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">None</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">dictionary</code></li>\n</ul>\n<p><code class=\"language-text\">. You can only build a stack from scratch.</code></p>\n<h4>Q13. What would this expression return?</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">college_years <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Freshman'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Sophomore'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Junior'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Senior'</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>college_years<span class=\"token punctuation\">,</span> <span class=\"token number\">2019</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">[('Freshman', 2019), ('Sophomore', 2020), ('Junior', 2021), ('Senior', 2022)]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">[(2019, 2020, 2021, 2022), ('Freshman', 'Sophomore', 'Junior', 'Senior')]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">[('Freshman', 'Sophomore', 'Junior', 'Senior'), (2019, 2020, 2021, 2022)]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">[(2019, 'Freshman'), (2020, 'Sophomore'), (2021, 'Junior'), (2022, 'Senior')]</code></li>\n</ul>\n<h4>Q14. How does <code class=\"language-text\">defaultdict</code> work?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> will automatically create a dictionary for you that has keys which are the integers 0-10.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> forces a dictionary to only accept keys that are of the data type specified when you created the <code class=\"language-text\">defaultdict</code> (such as strings or integers).</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] If you try to read from a <code class=\"language-text\">defaultdict</code> with a nonexistent key, a new default key-value pair will be created for you instead of throwing a <code class=\"language-text\">KeyError</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> stores a copy of a dictionary in memory that you can default to if the original gets unintentionally modified.</li>\n</ul>\n<h4>Q15. What is the correct syntax for defining a class called \"Game\", if it inherits from a parent class called \"LogicGame\"?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">class Game.LogicGame(): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def Game(LogicGame): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">class Game(LogicGame): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def Game.LogicGame(): pass</code></li>\n</ul>\n<p><code class=\"language-text\">repeated but labels will be different</code></p>\n<h4>Q16. What is the purpose of the \"self\" keyword when defining or calling instance methods?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">self</code> means that no other arguments are required to be passed into the method.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no real purpose for the <code class=\"language-text\">self</code> method; it's just historic computer science jargon that Python keeps to stay consistent with other programming languages.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">self</code> refers to the instance whose method was called.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">self</code> refers to the class that was inherited from to create the object using <code class=\"language-text\">self</code>.</li>\n</ul>\n<p><strong>Simple example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">my_secrets</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> password<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        self<span class=\"token punctuation\">.</span>password <span class=\"token operator\">=</span> password\n        <span class=\"token keyword\">pass</span>\ninstance <span class=\"token operator\">=</span> my_secrets<span class=\"token punctuation\">(</span><span class=\"token string\">'1234'</span><span class=\"token punctuation\">)</span>\ninstance<span class=\"token punctuation\">.</span>password\n<span class=\"token operator\">>></span><span class=\"token operator\">></span><span class=\"token string\">'1234'</span></code></pre></div>\n<h4>Q17. Which of these is NOT a characteristic of namedtuples?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You can assign a name to each of the <code class=\"language-text\">namedtuple</code> members and refer to them that way, similarly to how you would access keys in <code class=\"language-text\">dictionary</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Each member of a namedtuple object can be indexed to directly, just like in a regular <code class=\"language-text\">tuple</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">namedtuples</code> are just as memory efficient as regular <code class=\"language-text\">tuples</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] No import is needed to use <code class=\"language-text\">namedtuples</code> because they are available in the standard library.</li>\n</ul>\n<p>**We need to import it using <code class=\"language-text\">from collections import namedtuple</code> **</p>\n<h4>Q18. What is an instance method?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Instance methods can modify the state of an instance or the state of its parent class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Instance methods hold data related to the instance.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> An instance method is any class method that doesn't take any arguments.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> An instance method is a regular function that belongs to a class, but it must return <code class=\"language-text\">None</code>.</li>\n</ul>\n<h4>Q19. Which choice is the most syntactically correct example of the conditional branching?</h4>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are a few people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are a few people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are a few people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are a few people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Also see Question 85 for the same question with different answers.</p>\n<h4>Q20. Which statement does NOT describe the object-oriented programming concept of encapsulation?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It protects the data from outside interference.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A parent class is encapsulated and no data from the parent class passes on to the child class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It keeps data and the methods that can manipulate that data in one place.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It only allows the data to be changed by methods.</li>\n</ul>\n<h4>Q21. What is the purpose of an if/else statement?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It tells the computer which chunk of code to run if the instructions you coded are incorrect.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It runs one chunk of code if all the imports were successful, and another chunk of code if the imports were not successful.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It executes one chunk of code if a condition is true, but a different chunk of code if the condition is false.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It tells the computer which chunk of code to run if the is enough memory to handle it, and which chunk of code to run if there is not enough memory to handle it.</li>\n</ul>\n<h4>Q22. What built-in Python data type is best suited for implementing a queue?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> dictionary</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> set</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> None. You can only build a queue from scratch.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] list</li>\n</ul>\n<h4>Q23. What is the correct syntax for instantiating a new object of the type Game?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_game = class.Game()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_game = class(Game)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">my_game = Game()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_game = Game.create()</code></li>\n</ul>\n<h4>Q24. What does the built-in <code class=\"language-text\">map()</code> function do?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It creates a path from multiple values in an iterable to a single value.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It applies a function to each item in an iterable and returns the value of that function.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It converts a complex value type into simpler value types.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It creates a mapping between two different elements of different iterables.</li>\n</ul>\n<p><strong>Explanation:</strong> - The synax for <code class=\"language-text\">map()</code> function is <code class=\"language-text\">list(map(function,iterable)</code>. the simple area finder using map would be like this</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> math\nradius <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\narea <span class=\"token operator\">=</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span>math<span class=\"token punctuation\">.</span>pi<span class=\"token operator\">*</span><span class=\"token punctuation\">(</span>x<span class=\"token operator\">**</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> radius<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\narea\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span><span class=\"token number\">3.14</span><span class=\"token punctuation\">,</span> <span class=\"token number\">12.57</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28.27</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h4>Q25. If you don't explicitly return a value from a function, what happens?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The function will return a RuntimeError if you don't return a value.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] If the return keyword is absent, the function will return <code class=\"language-text\">None</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> If the return keyword is absent, the function will return <code class=\"language-text\">True</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The function will enter an infinite loop because it won't know when to stop executing its code.</li>\n</ul>\n<h4>Q26. What is the purpose of the <code class=\"language-text\">pass</code> statement in Python?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is used to skip the <code class=\"language-text\">yield</code> statement of a generator and return a value of None.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It is a null operation used mainly as a placeholder in functions, classes, etc.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is used to pass control from one statement block to another.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is used to skip the rest of a <code class=\"language-text\">while</code> or <code class=\"language-text\">for loop</code> and return to the start of the loop.</li>\n</ul>\n<h4>Q27. What is the term used to describe items that may be passed into a function?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] arguments</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> paradigms</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> attributes</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> decorators</li>\n</ul>\n<h4>Q28. Which collection type is used to associate values with unique keys?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">slot</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">dictionary</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">queue</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">sorted list</code></li>\n</ul>\n<h4>Q29. When does a for loop stop iterating?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when it encounters an infinite loop</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when it encounters an if/else statement that contains a break keyword</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] when it has assessed each item in the iterable it is working on or a break keyword is encountered</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when the runtime for the loop exceeds O(n^2)</li>\n</ul>\n<h4>Q30. Assuming the node is in a singly linked list, what is the runtime complexity of searching for a specific node within a singly linked list?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The runtime is O(n) because in the worst case, the node you are searching for is the last node, and every node in the linked list must be visited.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime is O(nk), with n representing the number of nodes and k representing the amount of time it takes to access each node in memory.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime cannot be determined unless you know how many nodes are in the singly linked list.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime is O(1) because you can index directly to a node in a singly linked list.</li>\n</ul>\n<h4>Q31. Given the following three list, how would you create a new list that matches the desired output printed below?</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">fruits <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Apples'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Oranges'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Bananas'</span><span class=\"token punctuation\">]</span>\nquantities <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\nprices <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.50</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.25</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.89</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token comment\">#Desired output</span>\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Apples'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Oranges'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Bananas'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.89</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">output <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n\nfruit_tuple_0 <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> quantities<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> price<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\noutput<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>fruit_tuple<span class=\"token punctuation\">)</span>\n\nfruit_tuple_1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> quantities<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> price<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\noutput<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>fruit_tuple<span class=\"token punctuation\">)</span>\n\nfruit_tuple_2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> quantities<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> price<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\noutput<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>fruit_tuple<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">return</span> output</code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">i <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\noutput <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> fruit <span class=\"token keyword\">in</span> fruits<span class=\"token punctuation\">:</span>\n    temp_qty <span class=\"token operator\">=</span> quantities<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span>\n    temp_price <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span>\n    output<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>fruit<span class=\"token punctuation\">,</span> temp_qty<span class=\"token punctuation\">,</span> temp_price<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">return</span> output</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">groceries <span class=\"token operator\">=</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>fruits<span class=\"token punctuation\">,</span> quantities<span class=\"token punctuation\">,</span> prices<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">return</span> groceries\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Apples'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Oranges'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Bananas'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.89</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">i <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\noutput <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> fruit <span class=\"token keyword\">in</span> fruits<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> qty <span class=\"token keyword\">in</span> quantities<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">for</span> price <span class=\"token keyword\">in</span> prices<span class=\"token punctuation\">:</span>\n            output<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>fruit<span class=\"token punctuation\">,</span> qty<span class=\"token punctuation\">,</span> price<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">return</span> output</code></pre></div>\n<h4>Q32. What happens when you use the built-in function all() on a list?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">all()</code> function returns a Boolean value that answers the question \"Are all the items in this list the same?</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">all()</code> function returns True if all the items in the list can be converted to strings. Otherwise, it returns False.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">all()</code> function will return all the values in the list.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <code class=\"language-text\">all()</code> function returns True if all items in the list evaluate to True. Otherwise, it returns False.</li>\n</ul>\n<p><strong>Explaination</strong> - <code class=\"language-text\">all()</code> returns true if all in the list are True, see example below</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">test <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">if</span> <span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span>test<span class=\"token punctuation\">)</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Yeah all are True'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'There is an imposter'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> There <span class=\"token keyword\">is</span> an imposter</code></pre></div>\n<h4>Q33. What is the correct syntax for calling an instance method on a class named Game?</h4>\n<p><em>(Answer format may vary. Game and roll (or dice</em>roll) should each be called with no parameters.)_</p>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> dice <span class=\"token operator\">=</span> Game<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> dice<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> dice <span class=\"token operator\">=</span> Game<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> dice<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> dice <span class=\"token operator\">=</span> Game<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> dice<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> dice <span class=\"token operator\">=</span> Game<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> dice<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h4>Q34. What is the algorithmic paradigm of quick sort?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> backtracking</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> dynamic programming</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> decrease and conquer</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] divide and conquer</li>\n</ul>\n<h4>Q35. What is runtime complexity of the list's built-in <code class=\"language-text\">.append()</code> method?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] O(1), also called constant time</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(log n), also called logarithmic time</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(n^2), also called quadratic time</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(n), also called linear time</li>\n</ul>\n<h4>Q36. What is key difference between a <code class=\"language-text\">set</code> and a <code class=\"language-text\">list</code>?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A set is an ordered collection unique items. A list is an unordered collection of non-unique items.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Elements can be retrieved from a list but they cannot be retrieved from a set.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A set is an ordered collection of non-unique items. A list is an unordered collection of unique items.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A set is an unordered collection unique items. A list is an ordered collection of non-unique items.</li>\n</ul>\n<h4>Q37. What is the definition of abstraction as applied to object-oriented Python?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstraction means that a different style of code can be used, since many details are already known to the program behind the scenes.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Abstraction means the implementation is hidden from the user, and only the relevant data or information is shown.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstraction means that the data and the functionality of a class are combined into one entity.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstraction means that a class can inherit from more than one parent class.</li>\n</ul>\n<h4>Q38. What does this function print?</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">print_alpha_nums</span><span class=\"token punctuation\">(</span>abc_list<span class=\"token punctuation\">,</span> num_list<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> abc_list<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">for</span> num <span class=\"token keyword\">in</span> num_list<span class=\"token punctuation\">:</span>\n            <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">,</span> num<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span>\n\nprint_alpha_nums<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token number\">1</span>\na <span class=\"token number\">2</span>\na <span class=\"token number\">3</span>\nb <span class=\"token number\">1</span>\nb <span class=\"token number\">2</span>\nb <span class=\"token number\">3</span>\nc <span class=\"token number\">1</span>\nc <span class=\"token number\">2</span>\nc <span class=\"token number\">3</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">aaa\nbbb\nccc\n<span class=\"token number\">111</span>\n<span class=\"token number\">222</span>\n<span class=\"token number\">333</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>\nb <span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>\nc <span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span></code></pre></div>\n<h4>Q39. Correct representation of doctest for function in Python</h4>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># a = 1</span>\n    <span class=\"token comment\"># b = 2</span>\n    <span class=\"token comment\"># sum(a, b) = 3</span>\n\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    a = 1\n    b = 2\n    sum(a, b) = 3\n    \"\"\"</span>\n\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    >>> a = 1\n    >>> b = 2\n    >>> sum(a, b)\n    3\n    \"\"\"</span>\n\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">'''\n    a = 1\n    b = 2\n    sum(a, b) = 3\n    '''</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<p><strong>Explanation:</strong> Use \"\"\" to start and end the docstring and use >>> to represent the output. If you write this correctly you can also run the doctest using build-in doctest module</p>\n<h4>Q40. Suppose a Game class inherits from two parent classes: BoardGame and LogicGame. Which statement is true about the methods of an object instantiated from the Game class?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When instantiating an object, the object doesn't inherit any of the parent class's methods.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When instantiating an object, the object will inherit the methods of whichever parent class has more methods.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When instantiating an object, the programmer must specify which parent class to inherit methods from.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] An instance of the Game class will inherit whatever methods the BoardGame and LogicGame classes have.</li>\n</ul>\n<h4>Q41. What does calling namedtuple on a collection type return?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a generic object class with iterable parameter fields</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a generic object class with non-iterable named fields</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a tuple subclass with non-iterable parameter fields</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a tuple subclass with iterable named fields</li>\n</ul>\n<p><strong>Example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> math\nradius <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\narea <span class=\"token operator\">=</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span>math<span class=\"token punctuation\">.</span>pi<span class=\"token operator\">*</span><span class=\"token punctuation\">(</span>x<span class=\"token operator\">**</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> radius<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\narea\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span><span class=\"token number\">3.14</span><span class=\"token punctuation\">,</span> <span class=\"token number\">12.57</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28.27</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h4>Q42. What symbol(s) do you use to assess equality between two elements?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&amp;&amp;</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">=</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">==</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">||</code></li>\n</ul>\n<h4>Q43. Review the code below. What is the correct syntax for changing the price to 1.5?</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">fruit_info <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'fruit'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'apple'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'count'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'price'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3.5</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">fruit_info ['price'] = 1.5</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_list [3.5] = 1.5</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">1.5 = fruit_info ['price]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_list['price'] == 1.5</code></li>\n</ul>\n<h4>Q44. What value would be returned by this check for equality?</h4>\n<p><code class=\"language-text\">5 != 6</code></p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">yes</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">False</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">True</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">None</code></li>\n</ul>\n<p><strong>Explanation</strong> - <code class=\"language-text\">!=</code> is equivalent to <strong>not equal to</strong> in python</p>\n<h4>Q45. What does a class's <code class=\"language-text\">init()</code> method do?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">__init__</code> method makes classes aware of each other if more than one class is defined in a single code file.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The<code class=\"language-text\">__init__</code> method is included to preserve backwards compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <code class=\"language-text\">__init__</code> method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">__init__</code> method initializes any imports you may have included at the top of your file.</li>\n</ul>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">test</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I came here without your permission lol'</span><span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">pass</span>\nt1 <span class=\"token operator\">=</span> test<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'I came here without your permission lol'</span></code></pre></div>\n<h4>Q46. What is meant by the phrase \"space complexity\"?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">How many microprocessors it would take to run your code in less than one second</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">How many lines of code are in your code file</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">The amount of space taken up in memory as a function of the input size</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">How many copies of the code file could fit in 1 GB of memory</code></li>\n</ul>\n<h4>Q47. What is the correct syntax for creating a variable that is bound to a dictionary?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">fruit_info = {'fruit': 'apple', 'count': 2, 'price': 3.5}</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_info =('fruit': 'apple', 'count': 2,'price': 3.5 ).dict()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_info = ['fruit': 'apple', 'count': 2,'price': 3.5 ].dict()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_info = to_dict('fruit': 'apple', 'count': 2, 'price': 3.5)</code></li>\n</ul>\n<h4>Q48. What is the proper way to write a list comprehension that represents all the keys in this dictionary?</h4>\n<p><code class=\"language-text\">fruits = {'Apples': 5, 'Oranges': 3, 'Bananas': 4}</code></p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_names = [x in fruits.keys() for x]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_names = for x in fruits.keys() *</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">fruit_names = [x for x in fruits.keys()]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_names = x for x in fruits.keys()</code></li>\n</ul>\n<h4>Q49. What is the purpose of the <code class=\"language-text\">self</code> keyword when defining or calling methods on an instance of an object?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">self</code> refers to the class that was inherited from to create the object using <code class=\"language-text\">self</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no real purpose for the <code class=\"language-text\">self</code> method. It's just legacy computer science jargon that Python keeps to stay consistent with other programming languages.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">self</code> means that no other arguments are required to be passed into the method.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">self</code> refers to the instance whose method was called.</li>\n</ul>\n<p><strong>Explanation:</strong> - Try running the example of the Q45 without passing <code class=\"language-text\">self</code> argument inside the <code class=\"language-text\">__init__</code>, you'll understand the reason. You'll get the error like this <code class=\"language-text\">__init__() takes 0 positional arguments but 1 was given</code>, this means that something is going inside even if haven't specified, which is instance itself.</p>\n<h4>Q50. What statement about the class methods is true?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method is a regular function that belongs to a class, but it must return None.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A class method can modify the state of the class, but they can't directly modify the state of an instance that inherits from that class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method is similar to a regular function, but a class method doesn't take any arguments.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method hold all of the data for a particular class.</li>\n</ul>\n<h4>Q51. What does it mean for a function to have linear runtime?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You did not use very many advanced computer programming concepts in your code.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The difficulty level your code is written at is not that high.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It will take your program less than half a second to run.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The amount of time it takes the function to complete grows linearly as the input size increases.</li>\n</ul>\n<h4>Q52. What is the proper way to define a function?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def getMaxNum(list_of_nums): # body of function goes here</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">func get_max_num(list_of_nums): # body of function goes here</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">func getMaxNum(list_of_nums): # body of function goes here</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">def get_max_num(list_of_nums): # body of function goes here</code></li>\n</ul>\n<p><a href=\"https://www.python.org/dev/peps/pep-0008/\">explanation for 52 &#x26; 53</a></p>\n<h4>Q53. According to the PEP 8 coding style guidelines, how should constant values be named in Python?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> in camel case without using underscores to separate words -- e.g. <code class=\"language-text\">maxValue = 255</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> in lowercase with underscores to separate words -- e.g. <code class=\"language-text\">max_value = 255</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] in all caps with underscores separating words -- e.g. <code class=\"language-text\">MAX_VALUE = 255</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> in mixed case without using underscores to separate words -- e.g. <code class=\"language-text\">MaxValue = 255</code></li>\n</ul>\n<h4>Q54. Describe the functionality of a deque.</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A deque adds items to one side and remove items from the other side.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A deque adds items to either or both sides, but only removes items from the top.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A deque adds items at either or both ends, and remove items at either or both ends.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A deque adds items only to the top, but remove from either or both sides.</li>\n</ul>\n<p><strong>Explanation</strong> - <code class=\"language-text\">deque</code> is used to create block chanin and in that there is <em>first in first out</em> approch, which means the last element to enter will be the first to leave.</p>\n<h4>Q55. What is the correct syntax for creating a variable that is bound to a set?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">my_set = {0, 'apple', 3.5}</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_set = to_set(0, 'apple', 3.5)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_set = (0, 'apple', 3.5).to_set()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_set = (0, 'apple', 3.5).set()</code></li>\n</ul>\n<h4>Q56. What is the correct syntax for defining an <code class=\"language-text\">__init__()</code> method that takes no parameters?</h4>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">__init__</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<h4>Q57. Which of the following is TRUE About how numeric data would be organised in a binary Search tree?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] For any given Node in a binary Search Tree, the child node to the left is less than the value of the given node and the child node to its right is greater than the given node.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Binary Search Tree cannot be used to organize and search through numeric data, given the complication that arise with very deep trees.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The top node of the binary search tree would be an arbitrary number. All the nodes to the left of the top node need to be less than the top node's number, but they don't need to ordered in any particular way.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The smallest numeric value would go in the top most node. The next highest number would go in its left child node, the the next highest number after that would go in its right child node. This pattern would continue until all numeric values were in their own node.</li>\n</ul>\n<h4>Q58. Why would you use a decorator?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A decorator is similar to a class and should be used if you are doing functional programming instead of object oriented programming.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A decorator is a visual indicator to someone reading your code that a portion of your code is critical and should not be changed.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] You use the decorator to alter the functionality of a function without having to modify the functions code.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> An import statement is preceded by a decorator, python knows to import the most recent version of whatever package or library is being imported.</li>\n</ul>\n<h4>Q59. When would you use a for loop?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Only in some situations, as loops are used only for certain type of programming.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] When you need to check every element in an iterable of known length.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When you want to minimize the use of strings in your code.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When you want to run code in one file for a function in another file.</li>\n</ul>\n<h4>Q60. What is the most self-descriptive way to define a function that calculates sales tax on a purchase?</h4>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">tax</span><span class=\"token punctuation\">(</span>my_float<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">'''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.'''</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">tx</span><span class=\"token punctuation\">(</span>amt<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">'''Gets the tax on an amount.'''</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sales_tax</span><span class=\"token punctuation\">(</span>amount<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">'''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.'''</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">calculate_sales_tax</span><span class=\"token punctuation\">(</span>subtotal<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<h4>Q61. What would happen if you did not alter the state of the element that an algorithm is operating on recursively?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You do not have to alter the state of the element the algorithm is recursing on.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You would eventually get a KeyError when the recursive portion of the code ran out of items to recurse on.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] You would get a RuntimeError: maximum recursion depth exceeded.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The function using recursion would return None.</li>\n</ul>\n<p><a href=\"https://www.python-course.eu/python3_recursive_functions.php#Definition-of-Recursion\">explanation</a></p>\n<h4>Q62. What is the runtime complexity of searching for an item in a binary search tree?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime for searching in a binary search tree is O(1) because each node acts as a key, similar to a dictionary.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime for searching in a binary search tree is O(n!) because every node must be compared to every other node.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The runtime for searching in a binary search tree is generally O(h), where h is the height of the tree.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime for searching in a binary search tree is O(n) because every node in the tree must be visited.</li>\n</ul>\n<p><a href=\"https://www.geeksforgeeks.org/binary-search-tree-data-structure/\">explanation</a></p>\n<h4>Q63. Why would you use <code class=\"language-text\">mixin</code>?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You use a <code class=\"language-text\">mixin</code> to force a function to accept an argument at runtime even if the argument wasn't included in the function's definition.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You use a <code class=\"language-text\">mixin</code> to allow a decorator to accept keyword arguments.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You use a <code class=\"language-text\">mixin</code> to make sure that a class's attributes and methods don't interfere with global variables and functions.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] If you have many classes that all need to have the same functionality, you'd use a <code class=\"language-text\">mixin</code> to define that functionality.</li>\n</ul>\n<p><a href=\"https://www.youtube.com/watch?v=zVFLBfqV-q0\">explanation</a></p>\n<h4>Q64. What is the runtime complexity of adding an item to a stack and removing an item from a stack?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add items to a stack in O(1) time and remove items from a stack on O(n) time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Add items to a stack in O(1) time and remove items from a stack in O(1) time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add items to a stack in O(n) time and remove items from a stack on O(1) time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add items to a stack in O(n) time and remove items from a stack on O(n) time.</li>\n</ul>\n<h4>Q65. Which statement accurately describes how items are added to and removed from a stack?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a stacks adds items to one side and removes items from the other side.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a stacks adds items to the top and removes items from the top.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a stacks adds items to the top and removes items from anywhere in the stack.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a stacks adds items to either end and removes items from either end.</li>\n</ul>\n<p><strong>Explanation</strong> Stack uses the <em>first in first out</em> approach</p>\n<h4>Q66. What is a base case in a recursive function?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A base case is the condition that allows the algorithm to stop recursing. It is usually a problem that is small enough to solve directly.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The base case is summary of the overall problem that needs to be solved.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The base case is passed in as an argument to a function whose body makes use of recursion.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The base case is similar to a base class, in that it can be inherited by another object.</li>\n</ul>\n<h4>Q67. Why is it considered good practice to open a file from within a Python script by using the <code class=\"language-text\">with</code> keyword?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">with</code> keyword lets you choose which application to open the file in.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">with</code> keyword acts like a <code class=\"language-text\">for</code> loop, and lets you access each line in the file one by one.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no benefit to using the <code class=\"language-text\">with</code> keyword for opening a file in Python.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] When you open a file using the <code class=\"language-text\">with</code> keyword in Python, Python will make sure the file gets closed, even if an exception or error is thrown.</li>\n</ul>\n<p><a href=\"https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files\">explanation</a></p>\n<h4>Q68. Why would you use a virtual environment?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Virtual environments create a \"bubble\" around your project so that any libraries or packages you install within it don't affect your entire machine.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Teams with remote employees use virtual environments so they can share code, do code reviews, and collaborate remotely.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Virtual environments were common in Python 2 because they augmented missing features in the language. Virtual environments are not necessary in Python 3 due to advancements in the language.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Virtual environments are tied to your GitHub or Bitbucket account, allowing you to access any of your repos virtually from any machine.</li>\n</ul>\n<h4>Q69. What is the correct way to run all the doctests in a given file from the command line?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] python3 -m doctest &#x3C;<em>filename</em>></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> python3 &#x3C;<em>filename</em>></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> python3 &#x3C;<em>filename</em>> rundoctests</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> python3 doctest</li>\n</ul>\n<p><a href=\"https://www.youtube.com/watch?v=P8qm0VAbbww&#x26;t=180s\">tutorial video</a></p>\n<h4>Q70. What is a lambda function ?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> any function that makes use of scientific or mathematical constants, often represented by Greek letters in academic writing</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a function that get executed when decorators are used</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> any function whose definition is contained within five lines of code or fewer</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a small, anonymous function that can take any number of arguments but has only expression to evaluate</li>\n</ul>\n<p><a href=\"https://www.guru99.com/python-lambda-function.html\">Reference</a></p>\n<p><strong>Explanation:</strong> <code class=\"language-text\">the lambda notation is basically an anonymous function that can take any number of arguments with only single expression (i.e, cannot be overloaded). It has been introducted in other programming languages, such as C++ and Java. The lambda notation allows programmers to \"bypass\" function declaration.</code></p>\n<h4>Q71. What is the primary difference between lists and tuples?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You can access a specifc element in a list by indexing to its position, but you cannot access a specific element in a tuple unless you iterate through the tuple</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Lists are mutable, meaning you can change the data that is inside them at any time. Tuples are immutable, meaning you cannot change the data that is inside them once you have created the tuple.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Lists are immutable, meaning you cannot change the data that is inside them once you have created the list. Tuples are mutable, meaning you can change the data that is inside them at any time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Lists can hold several data types inside them at once, but tuples can only hold the same data type if multiple elements are present.</li>\n</ul>\n<h4>Q72. Which statement about static method is true?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods can be bound to either a class or an instance of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods can access and modify the state of a class or an instance of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Static methods serve mostly as utility or helper methods, since they cannot access or modify a class's state.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods are called static because they always return None.</li>\n</ul>\n<h4>Q73. What does a generator return?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> None</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] An iterable object</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A linked list data structure from a non-empty list</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> All the keys of the given dictionary</li>\n</ul>\n<h4>Q74. What is the difference between class attributes and instance attributes?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Instance attributes can be changed, but class attributes cannot be changed</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Class attributes are shared by all instances of the class. Instance attributes may be unique to just that instance</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no difference between class attributes and instance attributes</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Class attributes belong just to the class, not to instance of that class. Instance attributes are shared among all instances of a class</li>\n</ul>\n<h4>Q75. What is the correct syntax of creating an instance method?</h4>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">get_next_card</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token comment\"># method body goes here</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">get_next_card</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token comment\"># method body goes here</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> self<span class=\"token punctuation\">.</span>get_next_card<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token comment\"># method body goes here</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> self<span class=\"token punctuation\">.</span>get_next_card<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token comment\"># method body goes here</span></code></pre></div>\n<h4>Q76. What is the correct way to call a function?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] get<em>max</em>num([57, 99, 31, 18])</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> call.(get<em>max</em>num)</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def get<em>max</em>num([57, 99, 31, 18])</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> call.get<em>max</em>num([57, 99, 31, 18])</li>\n</ul>\n<h4>Q77. How is comment created?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">-- This is a comment</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\"># This is a comment</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">/_ This is a comment _\\</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">// This is a comment</code></li>\n</ul>\n<h4>Q78. What is the correct syntax for replacing the string apple in the list with the string orange?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> orange = my_list[1]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] my_list[1] = 'orange'</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my_list['orange'] = 1</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my_list[1] == orange</li>\n</ul>\n<h4>Q79. What will happen if you use a while loop and forget to include logic that eventually causes the while loop to stop?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Nothing will happen; your computer knows when to stop running the code in the while loop.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You will get a KeyError.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Your code will get stuck in an infinite loop.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You will get a WhileLoopError.</li>\n</ul>\n<h4>Q80. Describe the functionality of a queue?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A queue adds items to either end and removes items from either end.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A queue adds items to the top and removes items from the top.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A queue adds items to the top, and removes items from anywhere in, a list.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A queue adds items to the top and removes items from anywhere in the queue.</li>\n</ul>\n<h4>Q81. Which choice is the most syntactically correct example of the conditional branching?</h4>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This question seems to be an updated version of Question 19.</p>\n<h4>Q82. How does <code class=\"language-text\">defaultdict</code> work?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> will automatically create a dictionary for you that has keys which are the integers 0-10.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> forces a dictionary to only accept keys that are of the types specified when you created the <code class=\"language-text\">defaultdict</code> (such as strings or integers).</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] If you try to read from a <code class=\"language-text\">defaultdict</code> with a nonexistent key, a new default key-value pair will be created for you instead of throwing a <code class=\"language-text\">KeyError</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> stores a copy of a dictionary in memory that you can default to if the original gets unintentionally modified.</li>\n</ul>\n<p>Updated version of Question 14.</p>\n<h4>Q83. What is the correct syntax for adding a key called <code class=\"language-text\">variety</code> to the <code class=\"language-text\">fruit_info</code> dictionary that has a value of <code class=\"language-text\">Red Delicious</code>?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_info['variety'] == 'Red Delicious'</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">fruit_info['variety'] = 'Red Delicious'</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">red_delicious = fruit_info['variety']</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">red_delicious == fruit_info['variety']</code></li>\n</ul>\n<h4>Q84. When would you use a <code class=\"language-text\">while</code> loop?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you want to minimize the use of strings in your code</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you want to run code in one file while code in another file is also running</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] when you want some code to continue running as long as some condition is true</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you need to run two or more chunks of code at once within the same file</li>\n</ul>\n<p><strong>Simple Example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">while</span> i<span class=\"token operator\">&lt;</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Countdown:'</span><span class=\"token punctuation\">,</span>i<span class=\"token punctuation\">)</span>\n    i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<h4>Q85. What is the correct syntax for defining an <code class=\"language-text\">__init__()</code> method that sets instance-specific attributes upon creation of a new class instance?</h4>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> attr1<span class=\"token punctuation\">,</span> attr2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    attr1 <span class=\"token operator\">=</span> attr1\n    attr2 <span class=\"token operator\">=</span> attr2</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>attr1<span class=\"token punctuation\">,</span> attr2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    attr1 <span class=\"token operator\">=</span> attr1\n    attr2 <span class=\"token operator\">=</span> attr2</code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> attr1<span class=\"token punctuation\">,</span> attr2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    self<span class=\"token punctuation\">.</span>attr1 <span class=\"token operator\">=</span> attr1\n    self<span class=\"token punctuation\">.</span>attr2 <span class=\"token operator\">=</span> attr2</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>attr1<span class=\"token punctuation\">,</span> attr2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    self<span class=\"token punctuation\">.</span>attr1 <span class=\"token operator\">=</span> attr1\n    self<span class=\"token punctuation\">.</span>attr2 <span class=\"token operator\">=</span> attr2</code></pre></div>\n<p><strong>Explanation</strong>: When instantiating a new object from a given class, the <code class=\"language-text\">__init__()</code> method will take both <code class=\"language-text\">attr1</code> and <code class=\"language-text\">attr2</code>, and set its values to their corresponding object attribute, that's why the need of using <code class=\"language-text\">self.attr1 = attr1</code> instead of <code class=\"language-text\">attr1 = attr1</code>.</p>\n<h4>Q86. What would this recursive function print if it is called with no parameters?</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">count_recursive</span><span class=\"token punctuation\">(</span>n<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> n <span class=\"token operator\">></span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span>\n\ncount_recursive<span class=\"token punctuation\">(</span>n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">3</span>\n<span class=\"token number\">3</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">3</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">1</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">3</span>\n<span class=\"token number\">3</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">1</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">3</span></code></pre></div>\n<h4>Q87. In Python, when using sets, you use <strong>_ to calculate the intersection between two sets and _</strong> to calculate the union.</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">Intersect;union</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> |; &#x26;</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] &#x26;; |</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> &#x26;&#x26;; ||</li>\n</ul>\n<h4>Q88. What will this code fragment return?</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> numpy <span class=\"token keyword\">as</span> np\nnp<span class=\"token punctuation\">.</span>ones<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It returns a 5x5 matric; each row will have the values 1,2,3,4,5.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It returns an array with the values 1,2,3,4,5</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It returns five different square matrices filled with ones. The first is 1x1, the second 2x2, and so on to 5x5</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It returns a 5-dimensional array of size 1x2x3x4x5 filled with 1s.</li>\n</ul>\n<p><a href=\"https://www.geeksforgeeks.org/numpy-ones-python/\">Reference</a></p>\n<h4>Q89. You encounter a FileNotFoundException while using just the filename in the <code class=\"language-text\">open</code> function. What might be the easiest solution?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Make sure the file is on the system PATH</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Create a symbolic link to allow better access to the file</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Copy the file to the same directory as where the script is running from</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add the path to the file to the PYTHONPATH environment variable</li>\n</ul>\n<h4>Q90. what will this command return?</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">{</span>x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> x<span class=\"token operator\">%</span><span class=\"token number\">3</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a set of all the multiples of 3 less then 100</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a set of all the number from 0 to 100 multiplied by 3</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a list of all the multiples of 3 less then 100</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a set of all the multiples of 3 less then 100 excluding 0</li>\n</ul>\n<h4>Q91. What does the // operator in Python 3 allow you to do?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Perform integer division</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Perform operations on exponents</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Find the remainder of a division operation</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Perform floating point division</li>\n</ul>\n<h4>Q92. This code provides the _ of the list of numbers</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">21</span><span class=\"token punctuation\">,</span><span class=\"token number\">13</span><span class=\"token punctuation\">,</span><span class=\"token number\">19</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">18</span><span class=\"token punctuation\">]</span>\nnum_list<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nnum_list<span class=\"token punctuation\">[</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>num_list<span class=\"token punctuation\">)</span><span class=\"token operator\">//</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> mean</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> mode</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] median</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> average</li>\n</ul>\n<h4>Q93. Which statement about the class methods is true?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method holds all of the data for a particular class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A class method can modify the state of the class, but it cannot directly modify the state of an instance that inherits from that class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method is a regular function that belongs to a class, but it must return None</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method is similar to a regular function, but a class method does not take any arguments.</li>\n</ul>\n<h4>Q94. What file is imported to use dates in python?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] datetime</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> dateday</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> daytime</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> timedate</li>\n</ul>\n<h4>Q95. What is the correct syntax for defining a class called Game?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def Game(): pass</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def Game: pass</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] class Game: pass</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> class Game(): pass</li>\n</ul>\n<p><a href=\"https://docs.python.org/3/tutorial/classes.html\">reference here</a></p>\n<h4>Q96. What does a class's init() method do?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <strong>init</strong> method makes classes aware of each other if more than one class is defined in a single code file.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <strong>init</strong> method is included to preserve backward compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <strong>init</strong> method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <strong>init</strong> method initializes any imports you may have included at the top of your file.</li>\n</ul>\n<p><a href=\"https://stackoverflow.com/questions/625083/what-init-and-self-do-in-python\">reference here</a></p>\n<h4>Q97. What is the correct syntax for calling an instance method on a class named Game?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my<em>game = Game(self) self.my</em>game.roll_dice()</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] my<em>game = Game() self.my</em>game.roll_dice()</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my<em>game = Game() my</em>game.roll_dice()</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my<em>game = Game(self) my</em>game.roll_dice(self)</li>\n</ul>\n<h4>Q98. What is the output of this code? (NumPy has been imported as np.)?</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = np.array([1,2,3,4])\nprint(a[[False, True, False, False]])</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> {0,2}</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] [2]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> {2}</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [0,2,0,0]</li>\n</ul>\n<h4>Q99. Suppose you have a string variable defined as y=”stuff;thing;junk;”. What would be the output from this code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Z = y.split(‘;’)\nlen(z)</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> 17</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] 4</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> 0</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> 3</li>\n</ul>\n<p>explanation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">y=”stuff;thing;junk”\n\tlen(z) ==> 3\n\ny=”stuff;thing;junk;”\n\tlen(z) ==> 4</code></pre></div>\n<h4>Q100. What is the output of this code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">num_list = [1,2,3,4,5]\nnum_list.remove(2)\nprint(num_list)</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [1,2,4,5]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] [1,3,4,5]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [3,4,5]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [1,2,3]</li>\n</ul>\n<p>explanation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">num_list = [1,2,3,4,5]\n\nnum_list.pop(2)\n\t[1,2,4,5]\n\nnum_list.remove(2)\n\t[1,3,4,5]</code></pre></div>\n<h4>Q101. What is the correct syntax for creating an instance method?</h4>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def get<em>next</em>card(): # method body goes here</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def self.get<em>next</em>card(): # method body goes here</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] def get<em>next</em>card(self): # method body goes here</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def self.get<em>next</em>card(self): # method body goes here</li>\n</ul>"},{"url":"/blog/react-complete-guide-notes/","relativePath":"blog/react-complete-guide-notes.md","relativeDir":"blog","base":"react-complete-guide-notes.md","name":"react-complete-guide-notes","frontmatter":{"title":"React Complete Guide Notes","template":"post","subtitle":"A javascript library for building User Interfaces based on reusable components.","excerpt":"Javascript allows us to manipulate the DOM without loading a new page and react is a JS library","date":"2023-02-06T17:26:56.410Z","image":"https://uploads.sitepoint.com/wp-content/uploads/2017/04/1493235373large_react_apps_A-01.png","thumb_image":"/blog/react.png","image_position":"right","author":"src/data/authors/bgoonz.yaml","show_author_bio":true,"cmseditable":true},"html":"<h1>React-Complete-Guide-Course</h1>\n<h4>What is React?</h4>\n<blockquote>\n<p>A javascript library for building User Interfaces based on reusable components.</p>\n</blockquote>\n<h4>Why use react?</h4>\n<blockquote>\n<p>traditionally any button on a website triggered a request from a server to load a new html page.\nJavascript allows us to manipulate the DOM without loading a new page and react is a JS library</p>\n</blockquote>\n<h4>Composition</h4>\n<blockquote>\n<p>in react building components using a series of smaller components is called composition</p>\n</blockquote>\n<h4>Container Copmonents</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./Card.css\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Card</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"card\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Card<span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>props.children works because children is a reserved keyword in react and the value of the children prop will always be the content between the opening closing tags of your custom component.</li>\n</ul>\n<blockquote>\n<p>props.children is important for composition using a custom wrapper component often used to apply styles that are shared among components</p>\n</blockquote>\n<h4>A closer look at JSX</h4>\n<blockquote>\n<p>in package.json we use react and reactDOM</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// when you use jsx it is this(React.createElement ... requires importing React from react) method that gets called behind the scenes.</span>\n<span class=\"token comment\">/* the second argument is an object tha configures atributes of element... in here none so empty object*/</span>\n<span class=\"token comment\">// the third and subsequent arguments are the children of each sucessivly nested element or component.</span>\n<span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n  <span class=\"token string\">\"div\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"h2\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Let's get started!</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n  React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>Expenses<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">items</span><span class=\"token operator\">:</span> expenses <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<h2>Events</h2>\n<ul>\n<li>On all bult in html elements in react we have access to native dom events... we can use them in react by adding a prop to the element and setting it to a function that will be executed when the event occurs.</li>\n<li>Imperative approach:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"clicked\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p>In react we add a special prop to the element we want to listen to and set it to a function that will be executed when the event occurs.</p>\n</blockquote>\n<blockquote>\n<p>React exposes events as props that start with prefix on... so onClick, onChange, onSubmit, etc.</p>\n</blockquote>\n<p>i.e.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">onClick</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>clickHandler<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Change Title</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span>\n<span class=\"token comment\">//here we are just pointing to the function and not calling it</span></code></pre></div>\n<blockquote>\n<p>all the on-event handler props want a function passed as a value which will be executed when the event occurs.</p>\n</blockquote>\n<ul>\n<li>It is convention that you name your eventHandler functions as the event name + Handler i.e. clickHandler, submitHandler, etc.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">clickHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setTitle</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Updated!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>UseState</h3>\n<blockquote>\n<p>useState is a react hook that allows you to manage state in functional components.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// let title = props.title;</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>title<span class=\"token punctuation\">,</span> setTitle<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>We can't use let title = props.title because react will only run the function once and not re-run it when the state changes. so we use useState to manage state in functional components.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> useState <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p>here {UseState} is a <code class=\"language-text\">named import</code> from react</p>\n</blockquote>\n<ul>\n<li>useState is a React hook that returns an array with 2 elements, the first element is the current state and the second element is a function that allows us to update the state.</li>\n<li>useState is declared inside of our component function. It should be called at the top level of the function... do not nest UseState inside of if statements or loops or other functions.</li>\n<li>UseState wants a default value as an argument. This is the initial value that will be used when the component is first rendered.</li>\n</ul>\n<h6>We use array destructuring to store the current state and update state function in variables.</h6>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>title<span class=\"token punctuation\">,</span> setTitle<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>the initial value of title is the value of props.title which is passed in as a prop from the parent component.</li>\n<li>We can use the update state function (setTitle) to update the state.</li>\n</ul>\n<p>The useState hook always returns an array with these two elements.</p>\n<p>Now instead of using the title variable we use the state variable.</p>\n<ul>\n<li>So</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">clickHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  title <span class=\"token operator\">=</span> <span class=\"token string\">\"Updated!\"</span><span class=\"token punctuation\">;</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">- becomes</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">clickHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setTitle</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Updated!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h6>Expense Item Code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> useState <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ExpenseDate <span class=\"token keyword\">from</span> <span class=\"token string\">\"./ExpenseDate\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> Card <span class=\"token keyword\">from</span> <span class=\"token string\">\"../UI/Card\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./ExpenseItem.css\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">ExpenseItem</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// let title = props.title;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>title<span class=\"token punctuation\">,</span> setTitle<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"ExpenseItem evaluated by React\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">clickHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTitle</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Updated!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>Card className<span class=\"token operator\">=</span><span class=\"token string\">\"expense-item\"</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ExpenseDate date<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"expense-item__description\"</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>title<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"expense-item__price\"</span><span class=\"token operator\">></span>$<span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>amount<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>clickHandler<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Change Title<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Card<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ExpenseItem<span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>In the above code calling setTitle(\"Updated!\") will not update the title variable but will update the state variable which will cause react to re-evaluate the component function and update the dom. Changes to the state will cause react to re-render the component on which the state is used and only that component.</li>\n<li>Notice that below</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>title<span class=\"token punctuation\">,</span> setTitle<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>we are using const here even though we do eventually assign a new value to title. This is because we are not reassigning the variable title but rather the state variable which is managed by react.</li>\n<li>The line above is exicuted whenever the component is re-evaulated by react. So if the state changes react will re-evaluate the component and re-execute the useState hook.</li>\n</ul>\n<h6>Events in vanilla javascript:</h6>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"clicked\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>The following syntax:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">titleChangeHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setUserInput</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>userInput<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">enteredTitle</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">amountChangeHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setUserInput</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>userInput<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">enteredAmount</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">dateChangeHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setUserInput</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>userInput<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">enteredDate</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>takes all of the properties of the userInput object and adds them to a new object. It then overwrites the enteredTitle property with the new value. This is called merging objects. It is a common pattern in react to merge objects when you want to update a state property that is an object.</p>\n<h6>Single State version of Expense Form:</h6>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> useState <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./ExpenseForm.css\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">ExpenseForm</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">//   const [enteredTitle, setEnteredTitle] = useState(\"\");</span>\n  <span class=\"token comment\">//   const [enteredAmount, setEnteredAmount] = useState(\"\");</span>\n  <span class=\"token comment\">//   const [enteredDate, setEnteredDate] = useState(\"\");</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>userInput<span class=\"token punctuation\">,</span> setUserInput<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">enteredTitle</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">enteredAmount</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">enteredDate</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">titleChangeHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"title change event: value:\"</span><span class=\"token punctuation\">,</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// setEnteredTitle(event.target.value);</span>\n    <span class=\"token function\">setUserInput</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">previousState</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>userInput<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">enteredTitle</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">amountChangeHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"amount change event: value:\"</span><span class=\"token punctuation\">,</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//event.target.value is a string even if the input type is number</span>\n    <span class=\"token comment\">// setEnteredAmount(event.target.value);</span>\n    <span class=\"token function\">setUserInput</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">previousState</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>userInput<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">enteredAmount</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">dateChangeHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"date change event: value:\"</span><span class=\"token punctuation\">,</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// setEnteredDate(event.target.value);</span>\n    <span class=\"token function\">setUserInput</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">previousState</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>userInput<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">enteredDate</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>form<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"new-expense__controls\"</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"new-expense__control\"</span><span class=\"token operator\">></span>\n          <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>Title<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span>\n          <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>titleChangeHandler<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"new-expense__control\"</span><span class=\"token operator\">></span>\n          <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>Amount<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span>\n          <span class=\"token operator\">&lt;</span>input\n            type<span class=\"token operator\">=</span><span class=\"token string\">\"number\"</span>\n            min<span class=\"token operator\">=</span><span class=\"token string\">\"0.01\"</span>\n            step<span class=\"token operator\">=</span><span class=\"token string\">\"0.01\"</span>\n            onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>amountChangeHandler<span class=\"token punctuation\">}</span>\n          <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"new-expense__control\"</span><span class=\"token operator\">></span>\n          <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>Date<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span>\n          <span class=\"token operator\">&lt;</span>input\n            type<span class=\"token operator\">=</span><span class=\"token string\">\"date\"</span>\n            min<span class=\"token operator\">=</span><span class=\"token string\">\"2019-01-01\"</span>\n            max<span class=\"token operator\">=</span><span class=\"token string\">\"2023-12-31\"</span>\n            onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>dateChangeHandler<span class=\"token punctuation\">}</span>\n          <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"new-expense__actions\"</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>button type<span class=\"token operator\">=</span><span class=\"token string\">\"submit\"</span><span class=\"token operator\">></span>Add Expense<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ExpenseForm<span class=\"token punctuation\">;</span></code></pre></div>\n<h5>Submitting and Working with Form Data:</h5>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">submitHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span> <span class=\"token parameter\">event</span> <span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        event<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> expenseData <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> enteredTitle<span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">amount</span><span class=\"token operator\">:</span> enteredAmount<span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span> enteredDate <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>form onSubmit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span> submitHandler<span class=\"token punctuation\">}</span><span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li>onSubmit is a special event that is triggered when the form is submitted. It submits a request to the server, in this case the development server and that's not what we want here.</li>\n<li>Here we want to prevent the default behavior of the form and instead handle the data ourselves. We do this by calling event.preventDefault() in the submitHandler function.</li>\n</ul>\n<h5>Two way binding:</h5>\n<p>In React, data flows one way: from owner to child. We think that this makes your app's code easier to understand. You can think of it as \"one-way data binding.\"</p>\n<p>However, there are lots of applications that require you to read some data and flow it back into your program. For example, when developing forms, you'll often want to update some React <code class=\"language-text\">state</code> when you receive user input. Or perhaps you want to perform layout in JavaScript and react to changes in some DOM element size.</p>\n<p>In React, you would implement this by listening to a \"change\" event, read from your data source (usually the DOM) and call <code class=\"language-text\">setState()</code> on one of your components. \"Closing the data flow loop\" explicitly leads to more understandable and easier-to-maintain programs.</p>\n<p>Two-way binding --- implicitly enforcing that some value in the DOM is always consistent with some React <code class=\"language-text\">state</code> --- is concise and supports a wide variety of applications. We've provided <code class=\"language-text\">LinkedStateMixin</code>: syntactic sugar for setting up the common data flow loop pattern described above, or \"linking\" some data source to React <code class=\"language-text\">state</code>.</p>\n<ul>\n<li>For inputs we don't just listen for changes but we can aslo pass a new value back into the input so that we can reset the input programatically. This is called two way binding.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"\"</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>titleChangeHandler<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token comment\">// onChange is a prop that wants a function as a value</span></code></pre></div>\n<p>This will set the internal value property which every input element has and we can set it to a new value.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">submitHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  event<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> expenseData <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> enteredTitle<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">amount</span><span class=\"token operator\">:</span> enteredAmount<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span>enteredDate<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>expenseData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">setEnteredTitle</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">setEnteredAmount</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">setEnteredDate</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p>We can clear the data after hittin submit using the following code:</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">   <span class=\"token function\">setEnteredTitle</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">setEnteredAmount</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">setEnteredDate</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`</code></pre></div>\n<h5>How to pass data from child to parent component:</h5>\n<blockquote>\n<p>we pass data from parent to child via props and from child to parent via function props.</p>\n</blockquote>\n<blockquote>\n<p>We can pass data from child to parent via function props.We can create our own event props that expect functions as values which allows us to pass a function from a parent component to a child component and then call that function inside of the child component. When we call said function we can pass data to that function as a parameter and that data will then be passed back to the parent component.</p>\n</blockquote>\n<blockquote>\n<p>props can only be passed from parent component to child and we can't skip intermediate components.</p>\n</blockquote>\n<p>Let's say we want to pass expense data which we gather in the expense form component to the new expense component. We can do this by passing a function from the new expense component to the expense form component and then call that function inside of the expense form component and pass the data as a parameter to that function.</p>\n<h6>NEW EXPENSE COMPONENT:</h6>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./NewExpense.css\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ExpenseForm <span class=\"token keyword\">from</span> <span class=\"token string\">\"./ExpenseForm\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">NewExpense</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">//the value for onSaveExpenseData should be a function that is triggered when the user clicks the submit button.</span>\n  <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">onSaveExpenseDataHandler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">enteredExpenseData</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> expenseData <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token operator\">...</span>enteredExpenseData<span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">random</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"expense data enriched with id property\"</span><span class=\"token punctuation\">,</span> expenseData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    props<span class=\"token punctuation\">.</span><span class=\"token function\">onAddExpense</span><span class=\"token punctuation\">(</span>expenseData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token comment\">//the value for onSaveExpenseData should be a function that is triggered when the user clicks the submit button... we can pass data as an argument to onSaveExpenseDataHandler to pass that data from the child component to the parent component.</span>\n  <span class=\"token comment\">//onSaveExpenseDataHandler is a function that is passed as a value to onSaveExpenseData ... it does not get executed here, hence the absence of (). It will be exicuted in the expense form component when the user clicks the submit button.</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"new-expense\"</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ExpenseForm onSaveExpenseData<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>onSaveExpenseDataHandler<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> NewExpense<span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h4>Keys in Lists:</h4>\n<blockquote>\n<p>Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity.</p>\n</blockquote>\n<p>A “key” is a special string attribute you need to include when creating lists of elements in React. Keys are used in React to identify which items in the list are changed, updated, or deleted. In other words, we can say that keys are used to give an identity to the elements in the lists. The next thing that comes to mind is that what should be good to be chosen as key for the items in lists. It is recommended to use a string as a key that uniquely identifies the items in the list. Below example shows a list with string keys:  </p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> updatedNums <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">=></span><span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>index<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">}</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can also assign the array indexes as keys to the list items. The below example assigns array indexes as key to the elements. </p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> updatedNums <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span><span class=\"token operator\">=></span>\n<span class=\"token operator\">&lt;</span>li key <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>index<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n<span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Assigning indexes as keys are highly discouraged because if the elements of the arrays get reordered in the future then it will get confusing for the developer as the keys for the elements will also change.</p>\n<h4>Using Keys with Components</h4>\n<p>Consider a situation where you have created a separate component for list items and you are extracting list items from that component. In that case, you will have to assign keys to the component you are returning from the iterator and not to the list items. That is you should assign keys to <Component /> and not to <li> A good practice to avoid mistakes is to keep in mind that anything you are returning from inside of the map() function is needed to be assigned key. </p>\n<p>Below code shows incorrect usage of keys: </p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom'</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Component to be extracted</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">MenuItems</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> item <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>item<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span><span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&lt;</span>li key <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n<span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\t\t\t\n<span class=\"token comment\">// Component that will return an</span>\n<span class=\"token comment\">// unordered list</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Navmenu</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> list <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>menuitems<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> updatedList <span class=\"token operator\">=</span> list<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">listItems</span><span class=\"token punctuation\">)</span><span class=\"token operator\">=></span><span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&lt;</span>MenuItems item <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> listItems <span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\t\t\t\n<span class=\"token keyword\">return</span><span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>updatedList<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> menuItems <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&lt;</span>Navmenu menuitems <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\nmenuItems<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\t\t</code></pre></div>\n<p>**Output: **</p>\n<p><img src=\"https://media.geeksforgeeks.org/wp-content/uploads/incorrect.png\" alt=\"incorrect use of keys\"></p>\n<p>You can see in the above output that the list is rendered successfully but a warning is thrown to the console that the elements inside the iterator are not assigned <em>keys</em>. This is because we had not assigned <em>key</em> to the elements we are returning to the map() iterator.</p>\n<p>Below example shows correct usage of keys: </p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">\"react-dom\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Component to be extracted</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">MenuItems</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t<span class=\"token keyword\">const</span> item <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>item<span class=\"token punctuation\">;</span>\n\t<span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Component that will return an</span>\n<span class=\"token comment\">// unordered list</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Navmenu</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\t<span class=\"token keyword\">const</span> list <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>menuitems<span class=\"token punctuation\">;</span>\n\t<span class=\"token keyword\">const</span> updatedList <span class=\"token operator\">=</span> list<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">listItems</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n\t\t<span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>MenuItems key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>listItems<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> item<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>listItems<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n\t<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n\t<span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>updatedList<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> menuItems <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n\t<span class=\"token operator\">&lt;</span>Navmenu menuitems<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>menuItems<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\n\tdocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/blog/react-fragments/","relativePath":"blog/react-fragments.md","relativeDir":"blog","base":"react-fragments.md","name":"react-fragments","frontmatter":{"title":"React Fragments","template":"post","subtitle":"A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.","excerpt":"A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.","date":"2022-05-28T23:53:29.467Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.jpg?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.jpg?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","tags":["src/data/tags/react.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/10-essential-react-interview-questions.md","src/pages/blog/deploy-react-app-to-heroku.md","src/pages/blog/react-state.md","src/pages/blog/react-semantics.md","src/pages/blog/passing-arguments-to-a-callback-in-js.md"],"cmseditable":true},"html":"<p>A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render() {\n  return (\n    &lt;React.Fragment>\n      &lt;ChildA />\n      &lt;ChildB />\n      &lt;ChildC />\n    &lt;/React.Fragment>\n  );\n}</code></pre></div>\n<p>There is also a new <a href=\"https://reactjs.org/docs/fragments.html#short-syntax\">short syntax</a> for declaring them.</p>\n<h2><a href=\"https://reactjs.org/docs/fragments.html#motivation\"></a>Motivation</h2>\n<p>A common pattern is for a component to return a list of children. Take this example React snippet:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Table extends React.Component {\n  render() {\n    return (\n      &lt;table>\n        &lt;tr>\n          &lt;Columns />\n        &lt;/tr>\n      &lt;/table>\n    );\n  }\n}</code></pre></div>\n<p><code class=\"language-text\">&lt;Columns /></code> would need to return multiple <code class=\"language-text\">&lt;td></code> elements in order for the rendered HTML to be valid. If a parent div was used inside the <code class=\"language-text\">render()</code> of <code class=\"language-text\">&lt;Columns /></code>, then the resulting HTML will be invalid.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Columns extends React.Component {\n  render() {\n    return (\n      &lt;div>\n        &lt;td>Hello&lt;/td>\n        &lt;td>World&lt;/td>\n      &lt;/div>\n    );\n  }\n}</code></pre></div>\n<p>results in a <code class=\"language-text\">&lt;Table /></code> output of:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;table>\n  &lt;tr>\n    &lt;div>\n      &lt;td>Hello&lt;/td>\n      &lt;td>World&lt;/td>\n    &lt;/div>\n  &lt;/tr>\n&lt;/table></code></pre></div>\n<p>Fragments solve this problem.</p>\n<h2><a href=\"https://reactjs.org/docs/fragments.html#usage\"></a>Usage</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Columns extends React.Component {\n  render() {\n    return (\n      &lt;React.Fragment>        &lt;td>Hello&lt;/td>\n        &lt;td>World&lt;/td>\n      &lt;/React.Fragment>    );\n  }\n}</code></pre></div>\n<p>which results in a correct <code class=\"language-text\">&lt;Table /></code> output of:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;table>\n  &lt;tr>\n    &lt;td>Hello&lt;/td>\n    &lt;td>World&lt;/td>\n  &lt;/tr>\n&lt;/table></code></pre></div>\n<h3><a href=\"https://reactjs.org/docs/fragments.html#short-syntax\"></a>Short Syntax</h3>\n<p>There is a new, shorter syntax you can use for declaring fragments. It looks like empty tags:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Columns extends React.Component {\n  render() {\n    return (\n      &lt;>        &lt;td>Hello&lt;/td>\n        &lt;td>World&lt;/td>\n      &lt;/>    );\n  }\n}</code></pre></div>\n<p>You can use <code class=\"language-text\">&lt;>&lt;/></code> the same way you’d use any other element except that it doesn’t support keys or attributes.</p>\n<h3><a href=\"https://reactjs.org/docs/fragments.html#keyed-fragments\"></a>Keyed Fragments</h3>\n<p>Fragments declared with the explicit <code class=\"language-text\">&lt;React.Fragment></code> syntax may have keys. A use case for this is mapping a collection to an array of fragments — for example, to create a description list:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Glossary(props) {\n  return (\n    &lt;dl>\n      {props.items.map(item => (\n        // Without the `key`, React will fire a key warning\n        &lt;React.Fragment key={item.id}>\n          &lt;dt>{item.term}&lt;/dt>\n          &lt;dd>{item.description}&lt;/dd>\n        &lt;/React.Fragment>\n      ))}\n    &lt;/dl>\n  );\n}</code></pre></div>\n<p><code class=\"language-text\">key</code> is the only attribute that can be passed to <code class=\"language-text\">Fragment</code>. In the future, we may add support for additional attributes, such as event handlers.</p>\n<iframe height=\"800\" style=\"width: 100%;\" scrolling=\"no\" title=\"Example: Fragments\" src=\"https://codepen.io/bgoonz/embed/VwQQWyV?default-tab=html%2Cresult\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\">\n</iframe>"},{"url":"/blog/react-semantics/","relativePath":"blog/react-semantics.md","relativeDir":"blog","base":"react-semantics.md","name":"react-semantics","frontmatter":{"title":"React Semantics","template":"post","subtitle":"Learn React","excerpt":"Below I list the most common terms, and their definitions, used when talking about React.","date":"2022-04-18T20:21:35.309Z","image":"https://blog.logrocket.com/wp-content/uploads/2021/09/optimizing-performance-react-application.png","thumb_image":"https://blog.logrocket.com/wp-content/uploads/2021/09/optimizing-performance-react-application.png","image_position":"top","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/react.yaml","src/data/categories/js.yaml"],"tags":["src/data/tags/react.yaml","src/data/tags/javascript.yaml","src/data/tags/links.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/using-the-dom.md","src/pages/blog/react-semantics.md"],"cmseditable":true},"html":"<h1>2. React Semantics/Terminology</h1>\n<hr>\n<h2>React Semantics</h2>\n<h4>Babel</h4>\n<p><a href=\"https://babeljs.io/\">Babel</a> transforms JavaScript ES* (i.e., JS 2016, 2016, 2017) to ES5. Babel is the tool of choice from the React team for writing future ES* code and transforming JSX to ES5 code.</p>\n<hr>\n<h4>Babel CLI</h4>\n<p>Babel comes with a CLI tool, called <a href=\"https://babeljs.io/docs/usage/cli/\">Babel CLI</a>, that can be used to compile files from the command line.</p>\n<hr>\n<h4>Component Configuration Options (a.k.a, \"Component Specifications\")</h4>\n<p>The configuration arguments passed (as an object) to the <code class=\"language-text\">React.createClass()</code> function resulting in an instance of a React component.</p>\n<hr>\n<h4>Component Life Cycle Methods</h4>\n<p>A sub group of component events, semantically separated from the other component configuration options (i.e., <code class=\"language-text\">componentWillUnmount</code>, <code class=\"language-text\">componentDidUpdate</code>, <code class=\"language-text\">componentWillUpdate</code>, <code class=\"language-text\">shouldComponentUpdate</code>, <code class=\"language-text\">componentWillReceiveProps</code>, <code class=\"language-text\">componentDidMount</code>, <code class=\"language-text\">componentWillMount</code>). These methods are executed at specific points in a component's existence.</p>\n<hr>\n<h4>Document Object Model (a.k.a., DOM)</h4>\n<p>\"The Document Object Model (DOM) is a programming interface for HTML, XML and SVG documents. It provides a structured representation of the document as a tree. The DOM defines methods that allow access to the tree, so that they can change the document structure, style and content. The DOM provides a representation of the document as a structured group of nodes and objects, possessing various properties and methods. Nodes can also have event handlers attached to them, and once an event is triggered, the event handlers get executed. Essentially, it connects web pages to scripts or programming languages.\" - <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model\">MSD</a></p>\n<hr>\n<h4>ES5</h4>\n<p>The 5th edition of the ECMAScript standard. The <a href=\"https://www.ecma-international.org/ecma-262/5.1/\">ECMAScript 5.1 edition</a> was finalized in June 2011.</p>\n<hr>\n<h4>ES6/ES 2015</h4>\n<p>The 6th edition of the ECMAScript standard. A.k.a, JavaScript 2015 or ECMAScript 2015. The <a href=\"https://www.ecma-international.org/ecma-262/6.0/index.html\">ECMAScript 6th edition</a> was finalized in June 2015.</p>\n<hr>\n<h4>ECMAScript 2016 (a.k.a, ES7)</h4>\n<p>The 7th edition of the ECMAScript standard. The <a href=\"https://www.ecma-international.org/ecma-262/7.0/index.html\">ECMAScript 7th edition</a> was finalized in June 2016.</p>\n<hr>\n<h4>ES*</h4>\n<p>Used to represent the current version of JavaScript as well as potential future versions that can written today using tools like Babel. When you see \"ES*\" it more than likely means you'll find uses of ES5, ES6, and ES7 together.</p>\n<hr>\n<h4>JSX</h4>\n<p><a href=\"https://jsx.github.io/\">JSX</a> is an optional XML-like syntax extension to ECMAScript that can be used to define an HTML-like tree structure in a JavaScript file. The JSX expressions in a JavaScript file must be transformed to JavaScript syntax before a JavaScript engine can parse the file. Babel is typically used and recommended for transforming JSX expressions.</p>\n<hr>\n<h4>Node.js</h4>\n<p><a href=\"https://nodejs.org/\">Node.js</a> is an open-source, cross-platform runtime environment for writing JavaScript. The runtime environment interprets JavaScript using <a href=\"https://developers.google.com/v8/\">Google's V8 JavaScript engine</a>.</p>\n<hr>\n<h4>npm</h4>\n<p><a href=\"https://www.npmjs.com/\">npm</a> is the package manager for JavaScript born from the Node.js community.</p>\n<hr>\n<h4>React Attributes/Props</h4>\n<p>In one sense you can think of props as the configuration options for React nodes and in another sense you can think of them as HTML attributes.</p>\n<p>Props take on several roles:</p>\n<ol>\n<li>Props can become HTML attributes. If a prop matches a known HTML attribute then it will be added to the final HTML element in the DOM.</li>\n<li>Props passed to <code class=\"language-text\">createElement()</code> become values stored in a <code class=\"language-text\">prop</code> object as an instance property of <code class=\"language-text\">React.createElement()</code> instances (i.e., <code class=\"language-text\">[INSTANCE].props.[NAME OF PROP]</code>). Props by and large are used to input values into components.</li>\n<li>A few special props have side effects (e.g., <a href=\"https://facebook.github.io/react/docs/multiple-components.html#dynamic-children\"><code class=\"language-text\">key</code></a>, <a href=\"https://facebook.github.io/react/docs/more-about-refs.html\"><code class=\"language-text\">ref</code></a>, and <a href=\"https://facebook.github.io/react/tips/dangerously-set-inner-html.html\"><code class=\"language-text\">dangerouslySetInnerHTML</code></a>)</li>\n</ol>\n<hr>\n<h4>React</h4>\n<p><a href=\"https://facebook.github.io/react/\">React</a> is an open source JavaScript library for writing declarative, efficient, and flexible user interfaces.</p>\n<hr>\n<h4>React Component</h4>\n<p>A React component is created by calling <code class=\"language-text\">React.createClass()</code> (or, <code class=\"language-text\">React.Component</code> if using ES6 classes). This function takes an object of options that is used to configure and create a React component. The most common configuration option is the <code class=\"language-text\">render</code> function which returns React nodes. Thus, you can think of a React component as an abstraction containing one or more React nodes/components.</p>\n<hr>\n<h4>React Element Nodes (a.k.a., <code class=\"language-text\">ReactElement</code>)</h4>\n<p>An HTML or custom HTML element node representation in the Virtual DOM created using <code class=\"language-text\">React.createElement();</code>.</p>\n<hr>\n<h4>React Nodes</h4>\n<p>React nodes (i.e., element and text nodes) are the primary object type in React and can be created using <code class=\"language-text\">React.createElement('div');</code>. In other words React nodes are objects that represent DOM nodes and children DOM nodes. They are a light, stateless, immutable, virtual representation of a DOM node.</p>\n<hr>\n<h4>React Node Factories</h4>\n<p>A function that generates a React element node with a particular type property.</p>\n<hr>\n<h4>React Stateless Function Component</h4>\n<p>When a component is purely a result of props alone, no state, the component can be written as a pure function avoiding the need to create a React component instance.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var MyComponent = function(props){\n    return &lt;div>Hello {props.name}&lt;/div>;\n};\n\nReactDOM.render(&lt;MyComponent name=\"doug\" />, app);</code></pre></div>\n<hr>\n<h4>React Text Nodes (a.k.a., <code class=\"language-text\">ReactText</code>)</h4>\n<p>A text node representation in the Virtual DOM created using <code class=\"language-text\">React.createElement('div',null,'a text node');</code>.</p>\n<hr>\n<h4>Virtual DOM</h4>\n<p>An in-memory JavaScript tree of React elements/components that is used for efficient re-rendering (i.e., diffing via JavaScript) of the browser DOM.</p>\n<hr>\n<h4>Webpack</h4>\n<p><a href=\"https://webpack.github.io/\">Webpack</a> is a module loader and bundler that takes modules (.js, .css, .txt, etc.) with dependencies and generates static assets representing these modules.</p>\n<p>Need to take a few steps back and figure out <a href=\"https://www.reactenlightenment.com/what-is-react.html\">what is react</a> javascript and how you can use it?</p>"},{"url":"/blog/react-state/","relativePath":"blog/react-state.md","relativeDir":"blog","base":"react-state.md","name":"react-state","frontmatter":{"title":"React State","template":"post","subtitle":"In React, we write event handlers directly on the elements in our JSX","excerpt":"In React, we write event handlers directly on the elements in our JSX","date":"2022-05-04T19:10:59.235Z","image":"https://bgoonz-blog.netlify.app/images/react.gif","thumb_image":"https://bgoonz-blog.netlify.app/images/react.gif","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/js.yaml","src/data/categories/git.yaml"],"tags":["src/data/tags/react.yaml","src/data/tags/javascript.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/react-semantics.md","src/pages/blog/10-essential-react-interview-questions.md","src/pages/blog/front-end-interview-questions-part-2.md"],"cmseditable":true},"html":"<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#handling_events\" title=\"Permalink to Handling events\">Handling events</a></h2>\n<p>If you've only written vanilla JavaScript before now, you might be used to having a separate JavaScript file, where you query for some DOM nodes and attach listeners to them. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token keyword\">const</span> btn <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nbtn<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hi!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In React, we write event handlers directly on the elements in our JSX, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token operator\">&lt;</span>button type<span class=\"token operator\">=</span><span class=\"token string\">\"button\"</span> onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hi!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n    Say hi<span class=\"token operator\">!</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span></code></pre></div>\n<p><strong>Note:</strong> This may seem counter-intuitive regarding best-practice advice that tends to advise against use of inline event handlers on HTML, but remember that JSX is actually part of your JavaScript.</p>\n<p>In the above example, we're adding an <code class=\"language-text\">onClick</code> attribute to the <code class=\"language-text\">&lt;button></code> element. The value of that attribute is a function that triggers a simple alert.</p>\n<p>The <code class=\"language-text\">onClick</code> attribute has special meaning here: it tells React to run a given function when the user clicks on the button. There are a couple of other things to note:</p>\n<ul>\n<li>The camel-cased nature of <code class=\"language-text\">onClick</code> is important — JSX will not recognize <code class=\"language-text\">onclick</code> (again, it is already used in JavaScript for a specific purpose, which is related but different — standard <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick\"><code class=\"language-text\">onclick</code></a> handler properties).</li>\n<li>All browser events follow this format in JSX – <code class=\"language-text\">on</code>, followed by the name of the event.</li>\n</ul>\n<p>Let's apply this to our app, starting in the <code class=\"language-text\">Form.js</code> component.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#handling_form_submission\" title=\"Permalink to Handling form submission\">Handling form submission</a></h3>\n<p>At the top of the <code class=\"language-text\">Form()</code> component function, create a function named <code class=\"language-text\">handleSubmit()</code>. This function should <a href=\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#preventing_default_behavior\">prevent the default behavior of the <code class=\"language-text\">submit</code> event</a>. After that, it should trigger an <code class=\"language-text\">alert()</code>, which can say whatever you'd like. It should end up looking something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, world!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To use this function, add an <code class=\"language-text\">onSubmit</code> attribute to the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form\"><code class=\"language-text\">&lt;form></code></a> element, and set its value to the <code class=\"language-text\">handleSubmit</code> function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;form onSubmit={handleSubmit}></code></pre></div>\n<p>Now if you head back to your browser and click on the \"Add\" button, your browser will show you an alert dialog with the words \"Hello, world!\" — or whatever you chose to write there.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#callback_props\" title=\"Permalink to Callback props\">Callback props</a></h2>\n<p>In React applications, interactivity is rarely confined to just one component: events that happen in one component will affect other parts of the app. When we start giving ourselves the power to make new tasks, things that happen in the <code class=\"language-text\">&lt;Form /></code> component will affect the list rendered in <code class=\"language-text\">&lt;App /></code>.</p>\n<p>We want our <code class=\"language-text\">handleSubmit()</code> function to ultimately help us create a new task, so we need a way to pass information from <code class=\"language-text\">&lt;Form /></code> to <code class=\"language-text\">&lt;App /></code>. We can't pass data from child to parent in the same way as we pass data from parent to child using standard props. Instead, we can write a function in <code class=\"language-text\">&lt;App /></code> that will expect some data from our form as an input, then pass that function to <code class=\"language-text\">&lt;Form /></code> as a prop. This function-as-a-prop is called a callback prop. Once we have our callback prop, we can call it inside <code class=\"language-text\">&lt;Form /></code> to send the right data to <code class=\"language-text\">&lt;App /></code>.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#handling_form_submission_via_callbacks\" title=\"Permalink to Handling form submission via callbacks\">Handling form submission via callbacks</a></h3>\n<p>Inside the top of our <code class=\"language-text\">App()</code> component function, create a function named <code class=\"language-text\">addTask()</code> which has a single parameter of <code class=\"language-text\">name</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function addTask(name) {\n  alert(name);\n}</code></pre></div>\n<p>Next, we'll pass <code class=\"language-text\">addTask()</code> into <code class=\"language-text\">&lt;Form /></code> as a prop. The prop can have whatever name you want, but pick a name you'll understand later. Something like <code class=\"language-text\">addTask</code> works, because it matches the name of the function as well as what the function will do. Your <code class=\"language-text\">&lt;Form /></code> component call should be updated as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Form addTask={addTask} /></code></pre></div>\n<p>Finally, you can use this prop inside the <code class=\"language-text\">handleSubmit()</code> function in your <code class=\"language-text\">&lt;Form /></code> component! Update it as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function handleSubmit(e) {\n  e.preventDefault();\n  props.addTask(\"Say hello!\");\n}</code></pre></div>\n<p>Clicking on the \"Add\" button in your browser will prove that the <code class=\"language-text\">addTask()</code> callback function works, but it'd be nice if we could get the alert to show us what we're typing in our input field! This is what we'll do next.</p>\n<p><strong>Note:</strong> We decided to name our callback prop <code class=\"language-text\">addTask</code> to make it easy to understand what the prop will do. Another common convention you may well come across in React code is to prefix callback prop names with the word <code class=\"language-text\">on</code>, followed by the name of the event that will cause them to be run. For instance, we could have given our form a prop of <code class=\"language-text\">onSubmit</code> with the value of <code class=\"language-text\">addTask</code>.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#state_and_the_usestate_hook\" title=\"Permalink to State and the useState hook\">State and the <code class=\"language-text\">useState</code> hook</a></h2>\n<p>So far, we've used props to pass data through our components and this has served us just fine. Now that we're dealing with user input and data updates, however, we need something more.</p>\n<p>For one thing, props come from the parent of a component. Our <code class=\"language-text\">&lt;Form /></code> will not be inheriting a new name for our task; our <code class=\"language-text\">&lt;input /></code> element lives directly inside of <code class=\"language-text\">&lt;Form /></code>, so <code class=\"language-text\">&lt;Form/></code> will be directly responsible for creating that new name. We can't ask <code class=\"language-text\">&lt;Form /></code> to spontaneously create its own props, but we <em>can</em> ask it to track some of its own data for us. Data such as this, which a component itself owns, is called <strong>state</strong>. State is another powerful tool for React because components not only <em>own</em> state, but can <em>update</em> it later. It's not possible to update the props a component receives; only to read them.</p>\n<p>React provides a variety of special functions that allow us to provide new capabilities to components, like state. These functions are called <strong>hooks</strong>, and the <code class=\"language-text\">useState</code> hook, as its name implies, is precisely the one we need in order to give our component some state.</p>\n<p>To use a React hook, we need to import it from the React module. In <code class=\"language-text\">Form.js</code>, change your very first line so that it reads like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useState } from \"react\";</code></pre></div>\n<p>This allows us to import the <code class=\"language-text\">useState()</code> function by itself, and utilize it anywhere in this file.</p>\n<p><code class=\"language-text\">useState()</code> creates a piece of state for a component, and its only parameter determines the <em>initial value</em> of that state. It returns two things: the state, and a function that can be used to update the state later.</p>\n<p>This is a lot to take in at once, so let's try it out. We're going to make ourselves a <code class=\"language-text\">name</code> state, and a function for updating the <code class=\"language-text\">name</code> state.</p>\n<p>Write the following above your <code class=\"language-text\">handleSubmit()</code> function, inside <code class=\"language-text\">Form()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const [name, setName] = useState('Use hooks!');</code></pre></div>\n<p>What's going on in this line of code?</p>\n<ul>\n<li>We are setting the initial <code class=\"language-text\">name</code> value as \"Use hooks!\".</li>\n<li>We are defining a function whose job is to modify <code class=\"language-text\">name</code>, called <code class=\"language-text\">setName()</code>.</li>\n<li><code class=\"language-text\">useState()</code> returns these two things, so we are using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment\">array destructuring</a> to capture them both in separate variables.</li>\n</ul>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#reading_state\" title=\"Permalink to Reading state\">Reading state</a></h3>\n<p>You can see the <code class=\"language-text\">name</code> state in action right away. Add a <code class=\"language-text\">value</code> attribute to the form's input, and set its value to <code class=\"language-text\">name</code>. Your browser will render \"Use hooks!\" inside the input.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;input\n  type=\"text\"\n  id=\"new-todo-input\"\n  className=\"input input__lg\"\n  name=\"text\"\n  autoComplete=\"off\"\n  value={name}\n/></code></pre></div>\n<p>Change \"Use hooks!\" to an empty string once you're done; this is what we want for our initial state.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const [name, setName] = useState('');</code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#reading_user_input\" title=\"Permalink to Reading user input\">Reading user input</a></h3>\n<p>Before we can change the value of <code class=\"language-text\">name</code>, we need to capture a user's input as they type. For this, we can listen to the <code class=\"language-text\">onChange</code> event. Let's write a <code class=\"language-text\">handleChange()</code> function, and listen for it on the <code class=\"language-text\">&lt;input /></code> tag.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// near the top of the `Form` component\nfunction handleChange(e) {\n  console.log(\"Typing!\");\n}\n\n// Down in the return statement\n&lt;input\n  type=\"text\"\n  id=\"new-todo-input\"\n  className=\"input input__lg\"\n  name=\"text\"\n  autoComplete=\"off\"\n  value={name}\n  onChange={handleChange}\n/></code></pre></div>\n<p>Currently, your input's value will not change as you type, but your browser will log the word \"Typing!\" to the JavaScript console, so we know our event listener is attached to the input. In order to change the input's value, we have to use our <code class=\"language-text\">handleChange()</code> function to update our <code class=\"language-text\">name</code> state.</p>\n<p>To read the contents of the input field as they change, you can access the input's <code class=\"language-text\">value</code> property. We can do this inside <code class=\"language-text\">handleChange()</code> by reading <code class=\"language-text\">e.target.value</code>. <code class=\"language-text\">e.target</code> represents the element that fired the <code class=\"language-text\">change</code> event — that's our input. So, <code class=\"language-text\">value</code> is the text inside it.</p>\n<p>You can <code class=\"language-text\">console.log()</code> this value to see it in your browser's console.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function handleChange(e) {\n  console.log(e.target.value);\n}</code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#updating_state\" title=\"Permalink to Updating state\">Updating state</a></h3>\n<p>Logging isn't enough — we want to actually store the updated state of the name as the input value changes! Change the <code class=\"language-text\">console.log()</code> to <code class=\"language-text\">setName()</code>, as shown below:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function handleChange(e) {\n  setName(e.target.value);\n}</code></pre></div>\n<p>Now we need to change our <code class=\"language-text\">handleSubmit()</code> function so that it calls <code class=\"language-text\">props.addTask</code> with name as an argument — remember our callback prop? This will serve to send the task back to the <code class=\"language-text\">App</code> component, so we can add it to our list of tasks at some later date. As a matter of good practice, you should clear the input after your form submits, so we'll call <code class=\"language-text\">setName()</code> again with an empty string to do so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function handleSubmit(e) {\n  e.preventDefault();\n  props.addTask(name);\n  setName(\"\");\n}</code></pre></div>\n<p>At last, you can type something into the input field in your browser and click <em>Add</em> — whatever you typed will appear in an alert dialog.</p>\n<p>Your <code class=\"language-text\">Form.js</code> file should now read like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useState } from \"react\";\n\nfunction Form(props) {\n  const [name, setName] = useState(\"\");\n\n  function handleChange(e) {\n    setName(e.target.value);\n  }\n\n  function handleSubmit(e) {\n    e.preventDefault();\n    props.addTask(name);\n    setName(\"\");\n  }\n  return (\n    &lt;form onSubmit={handleSubmit}>\n      &lt;h2 className=\"label-wrapper\">\n        &lt;label htmlFor=\"new-todo-input\" className=\"label__lg\">\n          What needs to be done?\n        &lt;/label>\n      &lt;/h2>\n      &lt;input\n        type=\"text\"\n        id=\"new-todo-input\"\n        className=\"input input__lg\"\n        name=\"text\"\n        autoComplete=\"off\"\n        value={name}\n        onChange={handleChange}\n      />\n      &lt;button type=\"submit\" className=\"btn btn__primary btn__lg\">\n        Add\n      &lt;/button>\n    &lt;/form>\n  );\n}\n\nexport default Form;</code></pre></div>\n<p><strong>Note:</strong> One thing you'll notice is that you are able to submit empty tasks by just pressing the Add button without entering a task name. Can you think of a way to disallow empty tasks from being added? As a hint, you probably need to add some kind of check into the <code class=\"language-text\">handleSubmit()</code> function.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#putting_it_all_together_adding_a_task\" title=\"Permalink to Putting it all together: Adding a task\">Putting it all together: Adding a task</a></h2>\n<p>Now that we've practiced with events, callback props, and hooks we're ready to write functionality that will allow a user to add a new task from their browser.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#tasks_as_state\" title=\"Permalink to Tasks as state\">Tasks as state</a></h3>\n<p>Import <code class=\"language-text\">useState</code> into <code class=\"language-text\">App.js</code>, so that we can store our tasks in state — update your <code class=\"language-text\">React</code> import line to the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useState } from \"react\";</code></pre></div>\n<p>We want to pass <code class=\"language-text\">props.tasks</code> into the <code class=\"language-text\">useState()</code> hook – this will preserve its initial state. Add the following right at the top of your App() function definition:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const [tasks, setTasks] = useState(props.tasks);</code></pre></div>\n<p>Now, we can change our <code class=\"language-text\">taskList</code> mapping so that it is the result of mapping <code class=\"language-text\">tasks</code>, instead of <code class=\"language-text\">props.tasks</code>. Your <code class=\"language-text\">taskList</code> constant declaration should now look like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const taskList = tasks.map(task => (\n    &lt;Todo\n        id={task.id}\n        name={task.name}\n        completed={task.completed}\n        key={task.id}\n      />\n    )\n  );</code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#adding_a_task\" title=\"Permalink to Adding a task\">Adding a task</a></h3>\n<p>We've now got a <code class=\"language-text\">setTasks</code> hook that we can use in our <code class=\"language-text\">addTask()</code> function to update our list of tasks. There's one problem however: we can't just pass the <code class=\"language-text\">name</code> argument of <code class=\"language-text\">addTask()</code> into <code class=\"language-text\">setTasks</code>, because <code class=\"language-text\">tasks</code> is an array of objects and <code class=\"language-text\">name</code> is a string. If we tried to do this, the array would be replaced with the string.</p>\n<p>First of all, we need to put <code class=\"language-text\">name</code> into an object that has the same structure as our existing tasks. Inside of the <code class=\"language-text\">addTask()</code> function, we will make a <code class=\"language-text\">newTask</code> object to add to the array.</p>\n<p>We then need to make a new array with this new task added to it and then update the state of the tasks data to this new state. To do this, we can use spread syntax to <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#copy_an_array\">copy the existing array</a>, and add our object at the end. We then pass this array into <code class=\"language-text\">setTasks()</code> to update the state.</p>\n<p>Putting that all together, your <code class=\"language-text\">addTask()</code> function should read like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function addTask(name) {\n  const newTask = { id: \"id\", name: name, completed: false };\n  setTasks([...tasks, newTask]);\n}</code></pre></div>\n<p>Now you can use the browser to add a task to our data! Type anything into the form and click \"Add\" (or press the Enter key) and you'll see your new todo item appear in the UI!</p>\n<p><strong>However, we have another problem</strong>: our <code class=\"language-text\">addTask()</code> function is giving each task the same <code class=\"language-text\">id</code>. This is bad for accessibility, and makes it impossible for React to tell future tasks apart with the <code class=\"language-text\">key</code> prop. In fact, React will give you a warning in your DevTools console — \"Warning: Encountered two children with the same key...\"</p>\n<p>We need to fix this. Making unique identifiers is a hard problem – one for which the JavaScript community has written some helpful libraries. We'll use <a href=\"https://github.com/ai/nanoid\">nanoid</a> because it's tiny, and it works.</p>\n<p>Make sure you're in the root directory of your application and run the following terminal command:</p>\n<p><strong>Note:</strong> If you're using yarn, you'll need the following instead: <code class=\"language-text\">yarn add nanoid</code></p>\n<p>Now we can import <code class=\"language-text\">nanoid</code> into the top of <code class=\"language-text\">App.js</code> so we can use it to create unique IDs for our new tasks. First of all, include the following import line at the top of <code class=\"language-text\">App.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { nanoid } from \"nanoid\";</code></pre></div>\n<p>Now let's update <code class=\"language-text\">addTask()</code> so that each task ID becomes a prefix todo- plus a unique string generated by nanoid. Update your <code class=\"language-text\">newTask</code> constant declaration to this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const newTask = { id: \"todo-\" + nanoid(), name: name, completed: false };</code></pre></div>\n<p>Save everything, and try your app again — now you can add tasks without getting that warning about duplicate IDs.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#detour_counting_tasks\" title=\"Permalink to Detour: counting tasks\">Detour: counting tasks</a></h2>\n<p>Now that we can add new tasks, you may notice a problem: our heading reads 3 tasks remaining, no matter how many tasks we have! We can fix this by counting the length of <code class=\"language-text\">taskList</code> and changing the text of our heading accordingly.</p>\n<p>Add this inside your <code class=\"language-text\">App()</code> definition, before the return statement:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const headingText = `${taskList.length} tasks remaining`;</code></pre></div>\n<p>Hrm. This is almost right, except that if our list ever contains a single task, the heading will still use the word \"tasks\". We can make this a variable, too. Update the code you just added as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const tasksNoun = taskList.length !== 1 ? 'tasks' : 'task';\nconst headingText = `${taskList.length} ${tasksNoun} remaining`;</code></pre></div>\n<p>Now you can replace the list heading's text content with the <code class=\"language-text\">headingText</code> variable. Update your <code class=\"language-text\">&lt;h2></code> like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;h2 id=\"list-heading\">{headingText}&lt;/h2></code></pre></div>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#completing_a_task\" title=\"Permalink to Completing a task\">Completing a task</a></h2>\n<p>You might notice that, when you click on a checkbox, it checks and unchecks appropriately. As a feature of HTML, the browser knows how to remember which checkbox inputs are checked or unchecked without our help. This feature hides a problem, however: toggling a checkbox doesn't change the state in our React application. This means that the browser and our app are now out-of-sync. We have to write our own code to put the browser back in sync with our app.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#proving_the_bug\" title=\"Permalink to Proving the bug\">Proving the bug</a></h3>\n<p>Before we fix the problem, let's observe it happening.</p>\n<p>We'll start by writing a <code class=\"language-text\">toggleTaskCompleted()</code> function in our <code class=\"language-text\">App()</code> component. This function will have an <code class=\"language-text\">id</code> parameter, but we're not going to use it yet. For now, we'll log the first task in the array to the console – we're going to inspect what happens when we check or uncheck it in our browser:</p>\n<p>Add this just above your <code class=\"language-text\">taskList</code> constant declaration:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function toggleTaskCompleted(id) {\n  console.log(tasks[0])\n}</code></pre></div>\n<p>Next, we'll add <code class=\"language-text\">toggleTaskCompleted</code> to the props of each <code class=\"language-text\">&lt;Todo /></code> component rendered inside our <code class=\"language-text\">taskList</code>; update it like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const taskList = tasks.map(task => (\n  &lt;Todo\n      id={task.id}\n      name={task.name}\n      completed={task.completed}\n      key={task.id}\n      toggleTaskCompleted={toggleTaskCompleted}\n  />\n));</code></pre></div>\n<p>Next, go over to your <code class=\"language-text\">Todo.js</code> component and add an <code class=\"language-text\">onChange</code> handler to your <code class=\"language-text\">&lt;input /></code> element, which should use an anonymous function to call <code class=\"language-text\">props.toggleTaskCompleted()</code> with a parameter of <code class=\"language-text\">props.id</code>. The <code class=\"language-text\">&lt;input /></code> should now look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;input\n  id={props.id}\n  type=\"checkbox\"\n  defaultChecked={props.completed}\n  onChange={() => props.toggleTaskCompleted(props.id)}\n/></code></pre></div>\n<p>Save everything and return to your browser and notice that our first task, Eat, is checked. Open your JavaScript console, then click on the checkbox next to Eat. It unchecks, as we expect. Your JavaScript console, however, will log something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object { id: \"task-0\", name: \"Eat\", completed: true }</code></pre></div>\n<p>The checkbox unchecks in the browser, but our console tells us that Eat is still completed. We will fix that next!</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#synchronizing_the_browser_with_our_data\" title=\"Permalink to Synchronizing the browser with our data\">Synchronizing the browser with our data</a></h3>\n<p>Let's revisit our <code class=\"language-text\">toggleTaskCompleted()</code> function in <code class=\"language-text\">App.js</code>. We want it to change the <code class=\"language-text\">completed</code> property of only the task that was toggled, and leave all the others alone. To do this, we'll <code class=\"language-text\">map()</code> over the task list and just change the one we completed.</p>\n<p>Update your <code class=\"language-text\">toggleTaskCompleted()</code> function to the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function toggleTaskCompleted(id) {\n  const updatedTasks = tasks.map(task => {\n    // if this task has the same ID as the edited task\n    if (id === task.id) {\n      // use object spread to make a new object\n      // whose `completed` prop has been inverted\n      return {...task, completed: !task.completed}\n    }\n    return task;\n  });\n  setTasks(updatedTasks);\n}</code></pre></div>\n<p>Here, we define an <code class=\"language-text\">updatedTasks</code> constant that maps over the original <code class=\"language-text\">tasks</code> array. If the task's <code class=\"language-text\">id</code> property matches the <code class=\"language-text\">id</code> provided to the function, we use <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax\">object spread syntax</a> to create a new object, and toggle the <code class=\"language-text\">checked</code> property of that object before returning it. If it doesn't match, we return the original object.</p>\n<p>Then we call <code class=\"language-text\">setTasks()</code> with this new array in order to update our state.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#deleting_a_task\" title=\"Permalink to Deleting a task\">Deleting a task</a></h2>\n<p>Deleting a task will follow a similar pattern to toggling its completed state: We need to define a function for updating our state, then pass that function into <code class=\"language-text\">&lt;Todo /></code> as a prop and call it when the right event happens.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#the_deletetask_callback_prop\" title=\"Permalink to The deleteTask callback prop\">The <code class=\"language-text\">deleteTask</code> callback prop</a></h3>\n<p>Here we'll start by writing a <code class=\"language-text\">deleteTask()</code> function in your <code class=\"language-text\">App</code> component. Like <code class=\"language-text\">toggleTaskCompleted()</code>, this function will take an <code class=\"language-text\">id</code> parameter, and we will log that <code class=\"language-text\">id</code> to the console to start with. Add the following below <code class=\"language-text\">toggleTaskCompleted()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function deleteTask(id) {\n  console.log(id)\n}</code></pre></div>\n<p>Next, add another callback prop to our array of <code class=\"language-text\">&lt;Todo /></code> components:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const taskList = tasks.map(task => (\n  &lt;Todo\n    id={task.id}\n    name={task.name}\n    completed={task.completed}\n    key={task.id}\n    toggleTaskCompleted={toggleTaskCompleted}\n    deleteTask={deleteTask}\n  />\n));</code></pre></div>\n<p>In <code class=\"language-text\">Todo.js</code>, we want to call <code class=\"language-text\">props.deleteTask()</code> when the \"Delete\" button is pressed. <code class=\"language-text\">deleteTask()</code> needs to know the ID of the task that called it, so it can delete the correct task from the state.</p>\n<p>Update the \"Delete\" button inside Todo.js, like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;button\n  type=\"button\"\n  className=\"btn btn__danger\"\n  onClick={() => props.deleteTask(props.id)}\n>\n  Delete &lt;span className=\"visually-hidden\">{props.name}&lt;/span>\n&lt;/button></code></pre></div>\n<p>Now when you click on any of the \"Delete\" buttons in the app, your browser console should log the ID of the related task.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_interactivity_events_state#deleting_tasks_from_state_and_ui\" title=\"Permalink to Deleting tasks from state and UI\">Deleting tasks from state and UI</a></h2>\n<p>Now that we know <code class=\"language-text\">deleteTask()</code> is invoked correctly, we can call our <code class=\"language-text\">setTasks()</code> hook in <code class=\"language-text\">deleteTask()</code> to actually delete that task from the app's state as well as visually in the app UI. Since <code class=\"language-text\">setTasks()</code> expects an array as an argument, we should provide it with a new array that copies the existing tasks, <em>excluding</em> the task whose ID matches the one passed into <code class=\"language-text\">deleteTask()</code>.</p>\n<p>This is a perfect opportunity to use <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter\"><code class=\"language-text\">Array.prototype.filter()</code></a>. We can test each task, and exclude a task from the new array if its <code class=\"language-text\">id</code> prop matches the <code class=\"language-text\">id</code> parameter passed into <code class=\"language-text\">deleteTask()</code>.</p>\n<p>Update the <code class=\"language-text\">deleteTask()</code> function inside your <code class=\"language-text\">App.js</code> file as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function deleteTask(id) {\n  const remainingTasks = tasks.filter(task => id !== task.id);\n  setTasks(remainingTasks);\n}</code></pre></div>"},{"url":"/blog/using-the-dom/","relativePath":"blog/using-the-dom.md","relativeDir":"blog","base":"using-the-dom.md","name":"using-the-dom","frontmatter":{"title":" using the DOM","template":"post","subtitle":"Examples of web and XML development","excerpt":"The following example shows the use of the `height` and `width` properties alongside images of varying dimensions:","date":"2022-04-15T07:01:59.356Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dom.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dom.png?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/html.yaml","src/data/categories/js.yaml"],"tags":["src/data/tags/links.yaml","src/data/tags/javascript.yaml","src/data/tags/react.yaml","src/data/tags/resources.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/adding-css-to-your-html.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h1>DOM:</h1>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#example_1_height_and_width\" title=\"Permalink to Example 1: height and width\">Example 1: height and width</a></h2>\n<p>The following example shows the use of the <code class=\"language-text\">height</code> and <code class=\"language-text\">width</code> properties alongside images of varying dimensions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#example_2_image_attributes\" title=\"Permalink to Example 2: Image Attributes\">Example 2: Image Attributes</a></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#example_3_manipulating_styles\" title=\"Permalink to Example 3: Manipulating Styles\">Example 3: Manipulating Styles</a></h2>\n<p>In this simple example, some basic style properties of an HTML paragraph element are accessed using the style object on the element and that object's CSS style properties, which can be retrieved and set from the DOM. In this case, you are manipulating the individual styles directly. In the next example (see Example 4), you can use stylesheets and their rules to change styles for whole documents.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#example_4_using_stylesheets\" title=\"Permalink to Example 4: Using Stylesheets\">Example 4: Using Stylesheets</a></h2>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/styleSheets\" title=\"styleSheets\"><code class=\"language-text\">styleSheets</code></a> property on the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document\"><code class=\"language-text\">document</code></a> object returns a list of the stylesheets that have been loaded on that document. You can access these stylesheets and their rules individually using the stylesheet, style, and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSRule\"><code class=\"language-text\">CSSRule</code></a> objects, as demonstrated in this example, which prints out all of the style rule selectors to the console.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>For a document with a single stylesheet in which the following three rules are defined:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>This script outputs the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#example_5_event_propagation\" title=\"Permalink to Example 5: Event Propagation\">Example 5: Event Propagation</a></h2>\n<p>This example demonstrates how events fire and are handled in the DOM in a very simple way. When the BODY of this HTML document loads, an event listener is registered with the top row of the TABLE. The event listener handles the event by executing the function stopEvent, which changes the value in the bottom cell of the table.</p>\n<p>However, stopEvent also calls an event object method, <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation\"><code class=\"language-text\">event.stopPropagation</code></a>, which keeps the event from bubbling any further up into the DOM. Note that the table itself has an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onclick\" title=\"onclick\"><code class=\"language-text\">onclick</code></a> event handler that ought to display a message when the table is clicked. But the stopEvent method has stopped propagation, and so after the data in the table is updated, the event phase is effectively ended, and an alert box is displayed to confirm this.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#example_6_getcomputedstyle\" title=\"Permalink to Example 6: getComputedStyle\">Example 6: getComputedStyle</a></h2>\n<p>This example demonstrates how the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle\"><code class=\"language-text\">window.getComputedStyle</code></a> method can be used to get the styles of an element that are not set using the <code class=\"language-text\">style</code> attribute or with JavaScript (e.g., <code class=\"language-text\">elt.style.backgroundColor=\"rgb(173, 216, 230)\"</code>). These latter types of styles can be retrieved with the more direct <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style\" title=\"elt.style\"><code class=\"language-text\">elt.style</code></a> property, whose properties are listed in the <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference\">DOM CSS Properties List</a>.</p>\n<p><code class=\"language-text\">getComputedStyle()</code> returns a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration\"><code class=\"language-text\">CSSStyleDeclaration</code></a> object, whose individual style properties can be referenced with this object's <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration/getPropertyValue\" title=\"getPropertyValue()\"><code class=\"language-text\">getPropertyValue()</code></a> method, as the following example document shows.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#example_7_displaying_event_object_properties\" title=\"Permalink to Example 7: Displaying Event Object Properties\">Example 7: Displaying Event Object Properties</a></h2>\n<p>This example uses DOM methods to display all the properties of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload\"><code class=\"language-text\">GlobalEventHandlers.onload</code></a> <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Event\"><code class=\"language-text\">event</code></a> object and their values in a table. It also shows a useful technique of using a for..in loop to iterate over the properties of an object to get their values.</p>\n<p>The properties of event objects differs greatly between browsers, the <a href=\"https://dom.spec.whatwg.org/\">WHATWG DOM Standard</a> lists the standard properties, however many browsers have extended these greatly.</p>\n<p>Put the following code into a blank text file and load it into a variety of browsers, you'll be surprised at the different number and names of properties. You might also like to add some elements in the page and call this function from different event handlers.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#example_8_using_the_dom_table_interface\" title=\"Permalink to Example 8: Using the DOM Table Interface\">Example 8: Using the DOM Table Interface</a></h2>\n<p>The DOM <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement\"><code class=\"language-text\">HTMLTableElement</code></a> interface provides some convenience methods for creating and manipulating tables. Two frequently used methods are <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/insertRow\"><code class=\"language-text\">HTMLTableElement.insertRow</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableRowElement/insertCell\"><code class=\"language-text\">HTMLTableRowElement.insertCell</code></a>.</p>\n<p>To add a row and some cells to an existing table:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Examples#notes\" title=\"Permalink to Notes\">Notes</a></h3>\n<ul>\n<li>A table's <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML\" title=\"innerHTML\"><code class=\"language-text\">innerHTML</code></a> property should never be used to modify a table, although you can use it to write an entire table or the content of a cell.</li>\n<li>If DOM Core methods <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement\"><code class=\"language-text\">document.createElement</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild\"><code class=\"language-text\">Node.appendChild</code></a> are used to create rows and cells, IE requires that they are appended to a <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody\"><code class=\"language-text\">&lt;tbody></code></a> element, whereas other browsers will allow appending to a <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table\"><code class=\"language-text\">&lt;table></code></a> element (the rows will be added to the last <code class=\"language-text\">&lt;tbody></code> element).</li>\n<li>There are a number of other convenience methods belonging to the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement#methods\"><code class=\"language-text\">HTMLTableElement</code> interface</a> that can be used for creating and modifying tables.</li>\n</ul>\n<!--EndFragment-->"},{"url":"/blog/vs-code-extensions/","relativePath":"blog/vs-code-extensions.md","relativeDir":"blog","base":"vs-code-extensions.md","name":"vs-code-extensions","frontmatter":{"title":"VS Code extensions","template":"post","subtitle":"10 must-have VS Code extensions for JavaScript developers","excerpt":"Developers will most likely argue for the rest of eternity about the most productive code editor and the best extensions.","date":"2022-04-10T17:03:30.554Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode-extensions-list.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode-extensions-list.png?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/awesome-lists.yaml"],"tags":["src/data/tags/links.yaml","src/data/tags/career.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/adding-css-to-your-html.md","src/pages/blog/intro-to-markdown.md"],"cmseditable":true},"html":"<p>Developers will most likely argue for the rest of eternity about the most productive code editor and the best extensions. Here are my personal extension preferences for VS Code as a JavaScript developer:</p>\n<ol>\n<li>ESLint <a href=\"https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint\">ESLint</a> turns the popular JavaScript linter into an extension of VS Code. It automatically reads your linting configuration, identifies problems and even fixes them for you, if you want.</li>\n<li>GitLens <a href=\"https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens\">GitLens</a> is a very powerful collaboration tool for VS Code. It provides many useful tools for git such as blame, code authorship, activity heatmaps, recent changes, file history and even commit search.</li>\n<li>Debugger for Chrome <a href=\"https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome\">Debugger for Chrome</a> allows you to debug your JavaScript code in Chrome or Chromium. Breakpoints, call stack inspection and stepping inside a function are only some of its features.</li>\n<li>Bracket Pair Colorizer 2 <a href=\"https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2\">Bracket Pair Colorizer 2</a> makes reading code faster as it makes matching brackets the same color. This extension for VS Code improves upon its predecessor by providing improved performance.</li>\n<li>Bookmarks <a href=\"https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks\">Bookmarks</a> is one of those extensions that will significantly reduce your time jumping between different files, as it allows you to save important positions and navigate back to them easily and quickly.</li>\n<li>TODO Highlight <a href=\"https://marketplace.visualstudio.com/items?itemName=wayou.vscode-todo-highlight\">TODO Highlight</a> simplifies tracking leftover tasks by allowing you to list all of your TODO annotations, as well as adding a handy background highlight to them to make them pop out immediately.</li>\n<li>Live Server <a href=\"https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer\">Live Server</a> gives you an easy way to serve web pages from VS Code, making previewing and debugging a lot easier. One of the core features is the live reload support that many developers are used to.</li>\n<li>REST Client <a href=\"https://marketplace.visualstudio.com/items?itemName=humao.rest-client\">REST Client</a> allows you to send HTTP requests and view the responses directly in VS Code. This extension supports a wide range of formats and authorization and should work with most setups.</li>\n<li>One Dark Pro <a href=\"https://marketplace.visualstudio.com/items?itemName=zhuangtongfa.Material-theme\">One Dark Pro</a> is one of the most popular VS Code themes and with very good reason. It provides a clean theme with a nice palette that has great contrast and is very comfortable to use on a daily basis.</li>\n<li>Fira Code <a href=\"https://github.com/tonsky/FiraCode\">Fira Code</a> is not a traditional VS Code extension and might take a couple more steps to set up, but it’s a superb programming font with ligatures that will help you scan code faster once you get used to it.</li>\n</ol>"},{"url":"/blog/vscode-extensions/","relativePath":"blog/vscode-extensions.md","relativeDir":"blog","base":"vscode-extensions.md","name":"vscode-extensions","frontmatter":{"title":"VSCode Extensions","template":"post","subtitle":"the most useful vscode extensions I know of","date":"2022-04-18T06:50:55.010Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.png?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.png?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/tools.yaml"],"tags":["src/data/tags/🖇-🖇-🖇-🖇.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/vs-code-extensions.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h3>Make VS Code Easy to Read</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify\">Beautify</a> - Makes HTML, CSS and JS very easy to read by de-minifying and properly spacing your horrendous markup.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments\">Better Comments</a> - Create more human-friendly comments in your code. I use this all. the. time. It's a mandatory extension for our dev team.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks\">Bookmarks</a> - It helps you to navigate in your code, moving between important positions easily and quickly. I use this in conjunction with MetaGo to be almost mouse-free while coding.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=metaseed.metago\">MetaGO</a> - Wicked fast cursor movement/selection for a focus on keyboard usage. This changed how I use VS Code forever. Seriously.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=emilast.LogFileHighlighter\">Log File Highlighter</a> - Just as it sounds, gives VSCode .log file support so you can actually read those log dumps without your eyes bleeding.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=spywhere.guides\">Guides</a> - Now you don't have to collapse and open all you're freaking elements to figure out nesting. This works really great with Beautify mentioned above and Rainbow Brackets, below.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=2gua.rainbow-brackets\">Rainbow Brackets</a> - Highlights the current bracket-set you're in and colours the rest differently for very easy location identification. If you're a heavy JS developer this is a great extension.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=kisstkondoros.vscode-gutter-preview\">Image Preview</a> - Shows an image preview in the gutter and on hover. So key for checking if I just referenced the correct image/icon.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens\">GitLens</a> - One of the most used extensions for sure; Gitlens is a must have for VS Code and just makes the Git experience so much better all around. Pair this with the <a href=\"https://marketplace.visualstudio.com/items?itemName=codezombiech.gitignore\">.gitignore</a> and <a href=\"https://marketplace.visualstudio.com/items?itemName=rafaelmaiolla.diff\">.diff</a> extensions for good coverage.</li>\n</ul>\n<h3>Faster Coding inside VS Code</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=pranaygp.vscode-css-peek\">CSS Peek</a> - Inspired by a similar feature in Brackets called CSS Inline Editors. One of my favourite Bracket features now in VS Code.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=shinnn.stylelint\">stylelint</a> - We lint our JS, so why not our LESS/SASS/CSS too? Great for quickly cleaning up sloppy CSS.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=ritwickdey.live-sass\">Live Sass Compiler</a> - Sure, you got Gulp, Webpack, NPM, Grunt but sometimes you want to compile/transpile your SASS/SCSS files to CSS files in realtime with live browser reload. This does just that.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer\">Live Server</a> - Best local development Server with live reload feature for static &#x26; dynamic pages (even PHP!).</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=pflannery.vscode-versionlens\">Version Lens</a> - Update dependencies/devDependencies to latest version for specified package.json. Recommended by: <a href=\"https://dev.to/qm3ster\">Mihail</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=mikestead.dotenv\">DotENV</a> - Adds support and highlighting for .env files - something I rely on heavily pushing to Heroku, Netlify, etc...</li>\n</ul>\n<h3>Pretty Screenshots</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=pnp.polacode\">Polacode</a> - Highlight code, snap a really nice screenshot with your code theme's colours. Great for tutorials or documentation and you want to provide code examples.</li>\n</ul>\n<h3>Multiple Instances of VS Code</h3>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync\">Settings Sync</a> - Uses a private gist to save a setting file so you can sync Settings, Snippets, Themes, File Icons, Launch, Keybindings, Workspaces and Extensions between multiple VS Code instances. I use this to keep my Laptop, Work Desktop and Home Desktop all in sync with two simple commands.</li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig\">EditorConfig</a> - Override user/workspace settings with settings found in .editorconfig files. I use this to enforce specific rules for the development team on a per-project basis.</li>\n</ul>\n<p>So there you have it, while I have lots of other plugins more specific to the environments I use (Front-End Web + Azure Cloud) hopefully you'll find these extensions useful in your daily use of VS Code!</p>\n<p>Let me know if you already use them and if you love or hate them. Or, some extensions I might have missed and should try out!</p>\n<h3>Noteworthy Mentions</h3>\n<p>After getting some feedback in the comments of you guys showing me some of your favourite VS Code extensions here are some new ones that I think are solid enough to also include:</p>\n<ul>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost\">Import Cost</a> - Shows the filesize cost of importing. - Recommended by: <a href=\"https://dev.to/miku86\">miku86</a></li>\n<li><a href=\"https://marketplace.visualstudio.com/items?itemName=stuart.unique-window-colors\">Window Colors</a> - Run multiple instances of VS Code? Have each window uniquely coloured so you don't lose track of which project is in what window. - Recommended by: <a href=\"https://dev.to/jefrypozo\">Jefry Pozo</a></li>\n<li><a href=\"https://github.com/prettier/prettier-vscode\">Prettier</a> - Very \"Pretty\" markup cleaner. Used by Stackoverflow to display nice code snippits. But, doesn't handle HTML inside <code class=\"language-text\">.js/.ejs/.jade/.pug</code> templates so not the best if working with many static site generators.</li>\n</ul>\n<!--EndFragment-->"},{"url":"/blog/web-dev-trends/","relativePath":"blog/web-dev-trends.md","relativeDir":"blog","base":"web-dev-trends.md","name":"web-dev-trends","frontmatter":{"title":"Web Development Tools","subtitle":"In 2021","date":"2021-09-30","thumb_image_alt":"image of","excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"post","thumb_image":"images/webdev.png"},"html":"<p><strong>1. AI Chatbots</strong>\n<img src=\"https://blog.sagipl.com/wp-content/uploads/2019/05/AI-Chatbots-1-1024x573.png\" alt=\"image\"></p>\n<p>Artificial Intelligence (AI) refers to the intelligence displayed by machines. It is primarily used to replace human intelligence.</p>\n<p>As the demand for AI-powered automation, communication, and analytics solutions will rise this year, more web developers will be focusing on building AI-based chatbots and virtual assistant apps.</p>\n<p><strong>2. Single Page Application</strong></p>\n<p><a href=\"https://www.sagipl.com/ipad-apps-development/\">Single-page applications</a>, being light in weight, faster, and more efficient, increased both in demand and popularity in recent years.</p>\n<p>Developers will continue to use SPA for building responsive sites and apps in 2021.</p>\n<p><strong>3. JavaScript Frameworks</strong></p>\n<p>JavaScript continues to remain one of the <a href=\"https://blog.sagipl.com/top-programming-languages/\"><strong>most preferred web development languages</strong></a> owing to its flexibility, power and evolving frameworks.</p>\n<p>This year too, we will see many new applications being developed in this developer-friendly language.</p>\n<p><strong>4. Progressive Web Apps (PWAs)</strong></p>\n<p>These are special web applications which are designed to load with progressive enhancement.</p>\n<p>Because of its fast-loading and high functionality features, PWA will continue to remain one of the year's hottest web trends.</p>\n<p><strong>5. Mobile-Friendly Website</strong></p>\n<p>Mobile-responsive sites are the ones that are designed to work smoothly across devices of all sizes.</p>\n<p>Owing to Google's mobile-first index and other search guidelines, developers will keep offering mobile-optimized sites this year and beyond.</p>\n<p><strong>6. Blockchain Technology</strong></p>\n<p>Blockchain, which was founded as a technology for secure digital payments, is now finding its place as a distributed ledger, which is secure, decentralized and public and will dominate the web development industry in the coming years.</p>\n<p><strong>7. Motion UI</strong></p>\n<p>Motion UI (User Interface) is a technology for creating visually appealing apps, especially animations, graphics, and transitions.</p>\n<p>Owing to its great ability for <a href=\"https://www.sagipl.com/website-design/\">creating an interactive web design</a>, Motion UI will be a primary tool for web developers in 2021.</p>\n<p><strong>8. Accelerated Mobile Pages (AMP)</strong></p>\n<p>Accelerated mobile pages are an initiative by Google to ensure that existing desktop websites give an equally amazing user experience across mobile devices.</p>\n<p>Web developers who are familiar with this tech are helping companies to implement the same on their websites.</p>\n<p><strong>9. Cybersecurity</strong></p>\n<p>Cybersecurity, which is another term for IT security, will continue to have its place in the online space as long as the world of internet is threatened by data breaches, hacking and similar cyber attacks.</p>\n<p>Developers with specialization in IT security will be in high demand this year.</p>\n<p><strong>10. VR and AR</strong></p>\n<p>The Augmented Reality and Virtual Reality Technologies, which were introduced only two years back, have now become a core part of the modern web development frameworks.</p>\n<p>From digital reality to visualization to 3D replicas, AR/VR will be used for enhancing user experience in the online space.</p>\n<p><strong>11. Voice Search</strong></p>\n<p>Following Google's increased focus on voice search queries, websites based on voice search optimization are now trending more than ever.</p>\n<p>As the number of people using voice searches will increase this year, so will the demand for websites optimized for the same.</p>\n<p><strong>12.</strong> <strong>Push Notification</strong></p>\n<p>Push Notification is replacing the Newsletter service. It is not very old but maintaining a high conversion rate better than Newsletters.</p>\n<p>Services and platforms like Onesignal, ZoPush, Push Engage are improving day by day, so it will be in trend in upcoming years and web developers also have to take care of it.</p>\n<p>SAG IPL is a leading global <a href=\"https://www.sagipl.com/web-development/\">web development company</a> providing modern web/app development services to clients worldwide.</p>"},{"url":"/blog/web-dev-frameworks/","relativePath":"blog/web-dev-frameworks.md","relativeDir":"blog","base":"web-dev-frameworks.md","name":"web-dev-frameworks","frontmatter":{"title":"Web Dev frameworks","template":"post","subtitle":"Web Dev frameworks","excerpt":"Web Dev frameworks","date":"2022-05-29T17:57:08.295Z","image":"https://www.datocms-assets.com/48401/1644864897-next-framework.jpeg?fit=max&w=900","thumb_image":"https://www.datocms-assets.com/48401/1644864897-next-framework.jpeg?fit=max&w=900","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/awesome-lists.yaml"],"tags":["src/data/tags/cms.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/adding-css-to-your-html.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h2>Web Dev frameworks<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/vercel/next.js\">Next.js</a> - Framework for server-rendered or statically-exported React apps.</li>\n<li>​<a href=\"https://github.com/baidu/san\">San</a> - Flexible JavaScript component framework.</li>\n<li>​<a href=\"https://hapijs.com/\">hapi</a> - Rich framework for building applications and services.</li>\n<li>​<a href=\"https://koajs.com/#introduction\">Koa</a> - Smaller, more expressive, and more robust foundation for web applications and APIs.</li>\n<li>​<a href=\"https://github.com/umijs/umi\">Umi</a> - Pluggable enterprise-level react application framework.</li>\n<li>​<a href=\"https://vuejs.org/\">Vue.js</a> - Progressive JavaScript Framework.</li>\n<li>​<a href=\"https://mithril.js.org/\">Mithril</a> - Modern client-side Javascript framework for building Single Page Applications. (<a href=\"https://news.ycombinator.com/item?id=25800754\">HN</a>)</li>\n<li>​<a href=\"https://github.com/ryansolid/solid\">Solid</a> - Declarative, efficient, and flexible JavaScript library for building user interfaces.</li>\n<li>​<a href=\"https://github.com/mozilla-neutrino/neutrino-dev\">Neutrino dev</a>​</li>\n<li>​<a href=\"https://github.com/alpinejs/alpine\">Alpine.js</a> - Rugged, minimal framework for composing JavaScript behavior in your markup. (<a href=\"https://github.com/alpine-collective/awesome\">Awesome Alpine</a>)</li>\n<li>​<a href=\"https://github.com/jaredpalmer/after.js\">After.js</a> - Next.js-like framework for server-rendered React apps built with React Router 4.</li>\n<li>​<a href=\"https://github.com/thesephist/torus\">Torus</a> - Event-driven model-view UI framework for the web, focused on being tiny, efficient, and free of dependencies. (<a href=\"https://thesephist.github.io/torus/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/jorgebucaran/hyperapp\">Hyperapp</a> - Tiny framework for building web interfaces. (<a href=\"https://hyperapp.dev/\">Web</a>) (<a href=\"https://news.ycombinator.com/item?id=23688798\">HN</a>) (<a href=\"https://github.com/jorgebucaran/hyperawesome\">Hyperawesome</a>)</li>\n<li>​<a href=\"https://github.com/okwolf/hyperapp-fx\">Hyperapp FX</a> - Effects for use with Hyperapp.</li>\n<li>​<a href=\"https://github.com/phenomic/phenomic\">Phenomic</a> - Modular website compiler (React, Webpack, Reason and whatever you want).</li>\n<li>​<a href=\"https://github.com/halfmoonui/halfmoon\">Halfmoon</a> - Front-end framework with a built-in dark mode and full customizability using CSS variables; great for building dashboards and tools. (<a href=\"https://www.gethalfmoon.com/docs/introduction/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/luwes/sinuous\">Sinuous</a> - Low-level UI library with a tiny footprint. (<a href=\"https://sinuous.dev/docs/getting-started/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/fastmail/overture\">Overture</a> - Powerful JS library for building really slick web applications, with performance at, or surpassing, native apps.</li>\n<li>​<a href=\"https://github.com/aidenybai/lucia\">Lucia</a> - Tiny library for tiny web apps. (<a href=\"https://lucia.js.org/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/ractivejs/ractive\">Ractive.js</a> - Next-generation DOM manipulation.</li>\n<li>​<a href=\"https://github.com/BuilderIO/jsx-lite\">JSX Lite</a> - Write components once, run everywhere. Compiles to Vue, React, Solid, Liquid, and more.</li>\n<li>​<a href=\"https://github.com/PaulMaly/perlite\">Perlite</a> - Hyperactiv + lit-html + extensions. Simple and declarative way to create rich client-side widgets designed with server-side apps in mind.</li>\n<li>​<a href=\"https://github.com/etienne-dldc/democrat\">Democrat</a> - Library that mimic the API of React (Components, hooks, Context...) but instead of producing DOM mutation it produces a state tree.</li>\n<li>​<a href=\"https://github.com/andrejewski/raj\">Raj</a> - Elm Architecture for JavaScript.</li>\n<li>​<a href=\"https://github.com/reframejs/reframe\">Reframe</a> - New kind of web framework.</li>\n<li>​<a href=\"https://github.com/observablehq/stdlib\">observablehq/stdlib</a> - Observable standard library.</li>\n<li>​<a href=\"https://github.com/choojs/choo\">Choo</a> - Sturdy 4kb frontend framework. (<a href=\"https://www.choo.io/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/akheron/typera\">Typera</a> - Type-safe routes for Express and Koa.</li>\n<li>​<a href=\"https://github.com/frouriojs/frourio\">Frourio</a> - Fast and type-safe full stack framework, for TypeScript. (<a href=\"https://frourio.io/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/svelto/svelto\">Svelto</a> - Modular front end framework for modern browsers, with battery included: 100+ widgets and tools.</li>\n<li>​<a href=\"https://github.com/jpmorganchase/modular\">modular</a> - Collection of tools and guidance to enable UI development at scale. (<a href=\"https://twitter.com/threepointone/status/1340620223993540608\">Tweet</a>)</li>\n<li>​<a href=\"https://github.com/hotwired/turbo\">Turbo</a> - Speed of a single-page web application without having to write any JavaScript. (<a href=\"https://turbo.hotwire.dev/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/yisar/fre\">Fre</a> - Tiny Coroutine framework with Fiber.</li>\n<li>​<a href=\"https://glimmerjs.com/\">Glimmer</a> - Fast and light-weight UI components for the web. (<a href=\"https://github.com/glimmerjs/glimmer.js\">Code</a>)</li>\n<li>​<a href=\"https://github.com/glimmerjs/glimmer-vm\">Glimmer VM</a> - Flexible, low-level rendering pipeline for building a \"live\" DOM from Handlebars templates that can subsequently be updated cheaply when data changes.</li>\n<li>​<a href=\"https://github.com/frintjs/frint\">frint</a> - Modular JavaScript framework for building scalable and reactive applications.</li>\n<li>​<a href=\"https://github.com/sunesimonsen/nano-router\">Nano Router</a> - Framework agnostic minimalistic router with a focus on named routes.</li>\n<li>​<a href=\"https://github.com/berstend/tiny-request-router\">tiny-request-router</a> - Fast, generic and type safe router (match request method and path).</li>\n<li>​<a href=\"https://github.com/defx/synergy\">Synergy</a> - Tiny runtime library for building web user interfaces. (<a href=\"https://news.ycombinator.com/item?id=25677272\">HN</a>)</li>\n<li>​<a href=\"https://github.com/jalal246/dflex\">dflex</a> - JavaScript Project to Manipulate DOM Elements.</li>\n<li>​<a href=\"https://github.com/patrick-steele-idem/morphdom\">morphdom</a> - Fast and lightweight DOM diffing/patching (no virtual DOM needed).</li>\n<li>​<a href=\"https://github.com/forgojs/forgo\">Forgo</a> - Ultra-light UI runtime. Makes it super easy to create modern web apps using JSX (like React).</li>\n<li>​<a href=\"https://github.com/whatsup/whatsup\">Whats Up</a> - Front-end framework based on ideas of streams and fractals.</li>\n<li>​<a href=\"https://github.com/milesj/boost\">Boost</a> - Collection of type-safe cross-platform packages for building robust server-side and client-side systems.</li>\n<li>​<a href=\"https://github.com/ggoodman/nostalgie\">Nostalgie</a> - Opinionated, full-stack, runtime-agnostic framework for building web apps and web pages using react. (<a href=\"https://nostalgie.dev/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/jupyterlab/lumino\">Lumino</a> - Library for building interactive web applications.</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#animation-\"></a>Animation<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/juliangarnier/anime\">Anime.js</a> - JavaScript animation engine.</li>\n<li>​<a href=\"https://github.com/Popmotion/popmotion\">popmotion</a> - Functional, reactive animation library.</li>\n<li>​<a href=\"https://github.com/impress/impress.js\">impress.js</a> - Presentation framework based on the power of CSS3 transforms and transitions.</li>\n<li>​<a href=\"https://github.com/williamngan/pts\">Pts</a> - Library for visualization and creative-coding.</li>\n<li>​<a href=\"https://github.com/alexfoxy/laxxx\">lax.js</a> - Simple &#x26; light weight (&#x3C;2kb gzipped) vanilla JS plugin to create smooth &#x26; beautiful animations when you scroll.</li>\n<li>​<a href=\"https://github.com/davidkpiano/flipping\">Flipping</a> - Library (and collection of adapters) for implementing FLIP transitions.</li>\n<li>​<a href=\"https://github.com/franciscop/ola\">Ola</a> - Smooth animation library for interpolating numbers.</li>\n<li>​<a href=\"https://github.com/react-spring/react-spring\">react-spring</a> - Spring physics based React animation library.</li>\n<li>​<a href=\"https://github.com/nextapps-de/fat\">FAT</a> - Web's fastest and most lightweight animation tool.</li>\n<li>​<a href=\"https://github.com/jlkiri/react-easy-flip\">React Easy Flip</a> - Lightweight React library for smooth FLIP animations.</li>\n<li>​<a href=\"https://github.com/michalsnik/aos\">AOS</a> - Animate on scroll library.</li>\n<li>​<a href=\"https://github.com/veltman/flubber\">flubber</a> - Tools for smoother shape animations.</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#cli-\"></a>CLI<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/klaussinani/qoa\">qoa</a> - Minimal interactive command-line prompts.</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#test-\"></a>Test<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/unexpectedjs/unexpected\">Unexpected</a> - Extensible BDD assertion toolkit. (<a href=\"https://unexpected.js.org/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/thoughtbot/fishery\">Fishery</a> - Library for setting up JavaScript objects as test data.</li>\n<li>​<a href=\"https://github.com/boxine/pentf\">pentf</a> - Parallel end-to-end test framework.</li>\n<li>​<a href=\"https://github.com/kettanaito/test-flat\">test-flat</a> - Test framework extension to support resources teardown and cleanup in flat tests.</li>\n<li>​<a href=\"https://github.com/lorenzofox3/zora\">zora</a> - Lightest, yet Fastest JavaScript test runner for nodejs and browsers.</li>\n<li>​<a href=\"https://github.com/ealush/vest\">Vest</a> - Declarative Validation Testing.</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#state-management-\"></a>State management<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/jaredpalmer/mutik\">Mutik</a> - Tiny (495B) immutable state management library based on Immer.</li>\n<li>​<a href=\"https://github.com/cerebral/overmind\">Overmind</a> - Frictionless state management. (<a href=\"https://overmindjs.org/\">Docs</a>) (<a href=\"https://news.ycombinator.com/item?id=24750620\">HN</a>)</li>\n<li>​<a href=\"https://github.com/ai/storeon\">Storeon</a> - Tiny event-based Redux-like state manager for React and Preact.</li>\n<li>​<a href=\"https://github.com/fabiospampinato/overstated\">Overstated</a> - React state management library that's delightful to use, without sacrificing performance or scalability.</li>\n<li>​<a href=\"https://github.com/effector/effector\">Effector</a> - Reactive state manager. (<a href=\"https://github.com/ilyalesik/awesome-effector\">Awesome</a>) (<a href=\"https://effector.now.sh/docs/introduction/installation\">Docs</a>) (<a href=\"https://github.com/yumauri/effector-storage\">effector-storage</a>)</li>\n<li>​<a href=\"https://github.com/datorama/akita\">Akita</a> - State Management Tailored-Made for JS Applications.</li>\n<li>​<a href=\"https://github.com/DanWahlin/Observable-Store\">Observable Store</a> - Provides a simple way to manage state in Angular, React, Vue.js and other front-end applications.</li>\n<li>​<a href=\"https://github.com/cerebral/cerebral\">Cerebral</a> - Declarative state and side effects management solution for popular JavaScript frameworks.</li>\n<li>​<a href=\"https://github.com/pie6k/hooksy\">Hooksy</a> - State management solution based on react hooks.</li>\n<li>​<a href=\"https://github.com/RisingStack/react-easy-state\">React Easy State</a> - Simple React state management. Made with ❤️ and ES6 Proxies.</li>\n<li>​<a href=\"https://github.com/alloc/wana\">wana</a> - Easy observable state for React.</li>\n<li>​<a href=\"https://github.com/facebookexperimental/Recoil\">Recoil</a> - Experimental set of utilities for state management with React. (<a href=\"https://recoiljs.org/\">Web</a>) (<a href=\"https://www.youtube.com/watch?v=fb3cOMFkEzs\">Video</a>) (<a href=\"https://www.reddit.com/r/reactjs/comments/gjpbjc/facebook_has_open_sourced_an_experimental_state/\">Reddit</a>) (<a href=\"https://bennetthardwick.com/blog/recoil-js-clone-from-scratch-in-100-lines/\">Rewriting from scratch</a>) (<a href=\"https://github.com/open-source-labs/Recoilize\">Recoilize - Recoil developer tool</a>)</li>\n<li>​<a href=\"https://github.com/steveruizok/state-designer\">State Designer</a> - JavaScript and TypeScript library for managing the state of a user interface.</li>\n<li>​<a href=\"https://github.com/yahoo/fluxible\">Fluxible</a> - Pluggable container for universal flux applications.</li>\n<li>​<a href=\"https://github.com/logux/state\">Logux State</a> - Tiny state manager with CRDT, cross-tab, and Logux support.</li>\n<li>​<a href=\"https://github.com/hmans/statery\">Statery</a> - Surprise-Free State Management. Designed for React with functional components.</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#api-bindings-\"></a>API bindings<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/dilame/instagram-private-api\">NodeJS Instagram private API client</a>​</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#db-\"></a>DB<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/sql-js/sql.js\">sql.js</a> - SQLite compiled to JavaScript. Allows you to create a relational database and query it entirely in the browser. (<a href=\"https://sql.js.org/#/\">Docs</a>) (<a href=\"https://news.ycombinator.com/item?id=25008308\">HN</a>)</li>\n<li>​<a href=\"https://github.com/twooster/sqigil\">SQigiL</a> - Postgres SQL template string for Javascript.</li>\n<li>​<a href=\"https://github.com/supabase/postgrest-js\">Postgrest JS</a> - Isomorphic JavaScript client for PostgREST.</li>\n<li>​<a href=\"https://github.com/voxpelli/node-connect-pg-simple\">Connect PG Simple</a> - Simple, minimal PostgreSQL session store for Express/Connect.</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#react-\"></a>React<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/tanem/state-machines-in-react\">state-machines-in-react</a> - Small React, xstate and Framer Motion demo.</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#other-\"></a>Other<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://github.com/mxstbr/micro-github\">micro github</a> - Tiny microservice that makes adding authentication with GitHub to your application easy.</li>\n<li>​<a href=\"https://github.com/tehnokv/picojs\">pico.js</a> - Face detection library in 200 lines of JavaScript.</li>\n<li>​<a href=\"https://github.com/jamesknelson/mdxc\">mdxc</a> - Use React Components within Markdown.</li>\n<li>​<a href=\"https://github.com/RelaxedJS/ReLaXed\">ReLaXeD</a> - Create PDF documents using web technologies. (<a href=\"https://github.com/RelaxedJS/ReLaXed-examples\">Examples</a>)</li>\n<li>​<a href=\"https://github.com/bevacqua/dragula\">Dragula</a> - Drag and drop so simple it hurts.</li>\n<li>​<a href=\"https://github.com/hammerjs/hammer.js\">Hammer.js</a> - Multi-touch gestures.</li>\n<li>​<a href=\"https://github.com/sindresorhus/emittery\">emittery</a> - Simple and modern async event emitter.</li>\n<li>​<a href=\"https://github.com/davidkpiano/xstate\">Xstate</a> - State machines and statecharts for the modern web. (<a href=\"https://github.com/ooade/state-machines-workshop\">State Machines Workshop</a>)</li>\n<li>​<a href=\"https://github.com/tivac/xstate-component-tree\">xstate-component-tree</a> - Build a tree of UI components based on your state chart.</li>\n<li>​<a href=\"https://github.com/valdrinkoshi/virtual-scroller\">virtual-scroller</a> - Maps a provided set of JavaScript objects onto DOM nodes, and renders only the DOM nodes that are currently visible, leaving the rest \"virtualized\".</li>\n<li>​<a href=\"https://github.com/MrRio/jsPDF\">jSPDF</a> - Client-side JavaScript PDF generation for everyone.</li>\n<li>​<a href=\"https://github.com/oussamahamdaoui/forgJs\">ForgJS</a> - JavaScript lightweight object validator.</li>\n<li>​<a href=\"https://github.com/Marak/faker.js\">faker.js</a> - Generate massive amounts of realistic fake data in Node.js and the browser.</li>\n<li>​<a href=\"https://github.com/vercel/arg\">arg</a> - Simple argument parsing.</li>\n<li>​<a href=\"https://github.com/facebookincubator/fbt\">fbt</a> - JavaScript Internationalization Framework.</li>\n<li>​<a href=\"https://github.com/bevacqua/fuzzysearch\">fuzzysearch</a> - Tiny and blazing-fast fuzzy search in JavaScript.</li>\n<li>​<a href=\"https://github.com/paularmstrong/normalizr\">normalizr</a> - Normalizes nested JSON according to a schema.</li>\n<li>​<a href=\"https://github.com/facebook/fbjs\">FBJS</a> - Collection of utility libraries used by other Facebook JS projects.</li>\n<li>​<a href=\"https://github.com/transloadit/uppy\">Uppy</a> - Next open source file uploader for web browsers. (<a href=\"https://uppy.io/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/scrollreveal/scrollreveal\">ScrollReveal</a> - Animate elements as they scroll into view.</li>\n<li>​<a href=\"https://github.com/rikschennink/shiny\">Shiny</a> - Add shiny reflections to text, backgrounds, and borders on devices that support the DeviceMotion event.</li>\n<li>​<a href=\"https://github.com/github/hotkey\">Hotkey Behavior</a> - Trigger a action on element when keyboard hotkey is pressed.</li>\n<li>​<a href=\"https://github.com/egoist/bili\">Bili</a> - Makes it easier to bundle JavaScript libraries.</li>\n<li>​<a href=\"https://github.com/medikoo/memoizee\">Memoizee</a> - Complete memoize/cache solution for JavaScript.</li>\n<li>​<a href=\"https://github.com/mweststrate/immer/#async-producers\">Immer</a> - Create the next immutable state by mutating the current one.</li>\n<li>​<a href=\"https://github.com/nextapps-de/flexsearch\">FlexSearch</a> - Web's fastest and most memory-flexible full-text search library with zero dependencies.</li>\n<li>​<a href=\"https://github.com/neurosnap/cofx\">cofx</a> - Node and javascript library that helps developers describe side-effects as data in a declarative, flexible API.</li>\n<li>​<a href=\"https://github.com/postlight/mercury-parser\">Mercury Parser</a> - Extracts the bits that humans care about from any URL you give it.</li>\n<li>​<a href=\"https://github.com/fanduel-oss/refract\">Refract</a> - Harness the power of reactive programming to supercharge your components.</li>\n<li>​<a href=\"https://github.com/memcachier/memjs\">MemJS</a> - Memcache client for node using the binary protocol and SASL authentication.</li>\n<li>​<a href=\"https://github.com/streamich/memfs\">memfs</a> - In-memory filesystem with Node's API.</li>\n<li>​<a href=\"https://github.com/accounts-js/accounts\">Accounts</a> - Fullstack authentication and accounts-management for GraphQL and REST.</li>\n<li>​<a href=\"https://github.com/nosir/cleave.js\">Cleave.js</a> - Format input text content when you are typing...</li>\n<li>​<a href=\"https://github.com/developit/unistore\">Unistore</a> - Tiny 350b centralized state container with component bindings for Preact &#x26; React.</li>\n<li>​<a href=\"https://github.com/ramda/ramda\">Ramda</a> - Practical functional library for JavaScript programmers.</li>\n<li>​<a href=\"https://github.com/tomi/fromfrom\">fromfrom</a> - JS library written in TS to transform sequences of data from format to another.</li>\n<li>​<a href=\"https://github.com/codex-team/editor.js\">Editor.js</a> - Block-styled editor with clean JSON output.</li>\n<li>​<a href=\"https://github.com/lukejacksonn/ijk\">ijk</a> - Transforms arrays into virtual DOM trees.</li>\n<li>​<a href=\"https://github.com/nosir/cleave.js\">Cleave.js</a> - Format input text content when you are typing.</li>\n<li>​<a href=\"https://github.com/jimhigson/oboe.js\">Oboe.js</a> - Streaming approach to JSON. Oboe.js speeds up web applications by providing parsed objects before the response completes.</li>\n<li>​<a href=\"https://github.com/jshjohnson/Choices\">Choices.js</a> - Vanilla JS customisable select box/text input plugin.</li>\n<li>​<a href=\"https://github.com/shipshapecode/shepherd\">Shepherd</a> - Guide your users through a tour of your app.</li>\n<li>​<a href=\"https://github.com/Rich-Harris/object-cull\">object-cull</a> - Create a copy of an object with just the bits you actually need.</li>\n<li>​<a href=\"https://github.com/jacomyal/sigma.js\">Sigma</a> - JavaScript library dedicated to graph drawing.</li>\n<li>​<a href=\"https://github.com/taye/interact.js\">interact.js</a> - JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers.</li>\n<li>​<a href=\"https://github.com/lukeed/flru\">flru</a> - Tiny (215B) and fast Least Recently Used (LRU) cache.</li>\n<li>​<a href=\"https://github.com/jquense/yup\">Yup</a> - Dead simple Object schema validation.</li>\n<li>​<a href=\"https://github.com/lerna/lerna\">Lerna</a> - Tool for managing JavaScript projects with multiple packages.</li>\n<li>​<a href=\"https://github.com/dijs/wiki\">WikiJs</a> - Wikipedia Interface for Node.js.</li>\n<li>​<a href=\"https://github.com/benji6/virtual-audio-graph\">virtual-audio-graph</a> - Library for declaratively manipulating the Web Audio API.</li>\n<li>​<a href=\"https://github.com/mattphillips/deep-object-diff\">deep-object-diff</a> - Deep diffs two objects, including nested structures of arrays and objects, and returns the difference.</li>\n<li>​<a href=\"https://github.com/developit/snarkdown\">Snarkdown</a> - Snarky 1kb Markdown parser written in JavaScript.</li>\n<li>​<a href=\"https://github.com/terser-js/terser\">Terser</a> - JavaScript parser, mangler, optimizer and beautifier toolkit for ES6+.</li>\n<li>​<a href=\"https://github.com/openid/AppAuth-JS\">AppAuthJS</a> - JavaScript client SDK for communicating with OAuth 2.0 and OpenID Connect providers.</li>\n<li>​<a href=\"https://github.com/silentmatt/expr-eval\">expr-eval</a> - Mathematical expression evaluator in JavaScript.</li>\n<li>​<a href=\"https://github.com/mourner/robust-predicates\">robust-predicates</a> - Fast robust predicates for computational geometry in JavaScript.</li>\n<li>​<a href=\"https://github.com/sanctuary-js/sanctuary\">Sanctuary</a> - JavaScript functional programming library inspired by Haskell and PureScript.</li>\n<li>​<a href=\"https://github.com/upmostly/modali\">modali</a> - Delightful modal dialog component for React, built from the ground up to support React Hooks.</li>\n<li>​<a href=\"https://github.com/cocopon/tweakpane\">Tweakpane</a> - Compact GUI for fine-tuning parameters and monitoring value changes.</li>\n<li>​<a href=\"https://github.com/evilsoft/crocks\">crocks</a> - Collection of well known Algebraic Data Types for your utter enjoyment.</li>\n<li>​<a href=\"https://github.com/angus-c/just\">Just</a> - Library of zero-dependency npm modules that do just do one thing.</li>\n<li>​<a href=\"https://github.com/ai/nanoid\">nanoid</a> - Tiny (139 bytes), secure, URL-friendly, unique string ID generator for JavaScript.</li>\n<li>​<a href=\"https://github.com/visionmedia/debug\">debug</a> - Tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers.</li>\n<li>​<a href=\"https://github.com/jwilber/roughViz\">roughViz.js</a> - Reusable JavaScript library for creating sketchy/hand-drawn styled charts in the browser.</li>\n<li>​<a href=\"https://github.com/developit/mitt\">Mitt</a> - Tiny 200 byte functional event emitter / pubsub.</li>\n<li>​<a href=\"https://github.com/requirejs/requirejs\">RequireJS</a> - File and module loader for JavaScript.</li>\n<li>​<a href=\"https://github.com/sinclairzx81/zero\">Zero</a> - 3D graphics rendering pipeline. Implemented in JavaScript. Run in a terminal.</li>\n<li>​<a href=\"https://github.com/statecharts/xstate-viz\">xstate-viz</a> - Visualize state charts.</li>\n<li>​<a href=\"https://github.com/pveyes/htmr\">htmr</a> - Simple and lightweight (&#x3C; 2kB) HTML string to React element conversion library.</li>\n<li>​<a href=\"https://github.com/TroyAlford/react-jsx-parser\">react-jsx-parser</a> - React component which can parse JSX and output rendered React Components.</li>\n<li>​<a href=\"https://github.com/fantasyland/static-land\">Static Land</a> - Specification for common algebraic structures in JavaScript based on Fantasy Land.</li>\n<li>​<a href=\"https://github.com/jviide/sorted-queue\">sorted-queue</a> - Sorted queue, based on an array-backed binary heap.</li>\n<li>​<a href=\"https://github.com/rvagg/polendina\">polendina</a> - Non-UI browser testing for JavaScript libraries from the command-line.</li>\n<li>​<a href=\"https://github.com/Rich-Harris/agadoo\">agadoo</a> - Check whether a package is tree-shakeable.</li>\n<li>​<a href=\"https://github.com/andyrichardson/fielder\">Fielder</a> - React form library which adapts to change.</li>\n<li>​<a href=\"https://github.com/fogus/lemonad\">lemonad</a> - Functional programming library for JavaScript. An experiment in elegant JS.</li>\n<li>​<a href=\"https://github.com/httptoolkit/mockttp\">Mockttp</a> - Lets you quickly &#x26; reliably test HTTP requests &#x26; responses in JavaScript, in both Node and browsers.</li>\n<li>​<a href=\"https://github.com/alyssaxuu/flowy\">Flowy</a> - Minimal javascript library to create flowcharts.</li>\n<li>​<a href=\"https://github.com/erikbrinkman/d3-dag\">d3-dag</a> - Layout algorithms for visualizing directed acyclic graphs.</li>\n<li>​<a href=\"https://github.com/FormidableLabs/renature\">renature</a> - Physics-based animation library for React focused on modeling natural world forces.</li>\n<li>​<a href=\"https://github.com/nobrainr/morphism\">Morphism</a> - Do not repeat anymore your objects transformations.</li>\n<li>​<a href=\"https://github.com/optoolco/tonic\">Tonic</a> - Stable, Minimal, Auditable, Build-Tool-Free, Low Profile Component Framework.</li>\n<li>​<a href=\"https://github.com/quiet/quiet-js\">Quiet.js</a> - Transmit data with sound using Web Audio -- Javascript binding for libquiet.</li>\n<li>​<a href=\"https://github.com/evnbr/bindery\">Bindery</a> - Library for designing printable books with HTML and CSS.</li>\n<li>​<a href=\"https://github.com/elbywan/wretch\">Wretch</a> - Tiny wrapper built around fetch with an intuitive syntax.</li>\n<li>​<a href=\"https://github.com/arcanis/virtjs\">Virt.js</a> - Free collection of useful standard devices, that can be used to power various engine that makes use of the exposed interfaces.</li>\n<li>​<a href=\"https://github.com/pillarjs/path-to-regexp\">Path-to-RegExp</a> - Turn a path string such as /user/:name into a regular expression.</li>\n<li>​<a href=\"https://github.com/baconjs/bacon.js\">Bacon.js</a> - Functional reactive programming library for TypeScript and JavaScript.</li>\n<li>​<a href=\"https://github.com/alibaba/GGEditor\">GGEditor</a> - Visual graph editor based on G6 and React.</li>\n<li>​<a href=\"https://github.com/samizdatco/arbor\">Arbor</a> - Graph visualization library using web workers and jQuery. (<a href=\"https://arborjs.org/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/vstirbu/fsm-as-promised\">fsm-as-promised</a> - Finite state machine library using ES6 promises.</li>\n<li>​<a href=\"https://github.com/myliang/x-spreadsheet\">x-spreadsheet</a> - Web-based JavaScript（canvas）spreadsheet.</li>\n<li>​<a href=\"https://github.com/victorqribeiro/isocity\">IsoCity</a> - Isometric city builder in JavaScript.</li>\n<li>​<a href=\"https://github.com/pakastin/car\">car</a> - Simple 2d car physics with JavaScript. (<a href=\"https://news.ycombinator.com/item?id=21927076\">HN</a>)</li>\n<li>​<a href=\"https://github.com/micromatch/picomatch\">Picomatch</a> - Blazing fast and accurate glob matcher written in JavaScript.</li>\n<li>​<a href=\"https://github.com/jackyef/react-isomorphic-data\">react-isomorphic-data</a> - Easily fetch data in your React components, with similar APIs to react-apollo.</li>\n<li>​<a href=\"https://github.com/lukeed/klona\">klona</a> - Tiny (228B) and fast utility to \"deep clone\" Objects, Arrays, Dates, RegExps, and more.</li>\n<li>​<a href=\"https://github.com/janpaepke/ScrollMagic\">ScrollMagic</a> - JavaScript library for magical scroll interactions.</li>\n<li>​<a href=\"https://gojs.net/latest/index.html\">GoJS</a> - JavaScript and TypeScript library for building interactive diagrams and graphs.</li>\n<li>​<a href=\"https://github.com/retejs/rete\">Rete</a> - JavaScript framework for visual programming and creating node editor. (<a href=\"https://news.ycombinator.com/item?id=22024201\">HN</a>)</li>\n<li>​<a href=\"https://github.com/deanm/pre3d\">Pre3d</a> - JavaScript 3d rendering engine.</li>\n<li>​<a href=\"https://github.com/jsantell/dancer.js\">dancer.js</a> - High-level audio API, designed to make sweet visualizations.</li>\n<li>​<a href=\"https://github.com/GoogleWebComponents/model-viewer\">model-viewer</a> - Easily display interactive 3D models on the web and in AR.</li>\n<li>​<a href=\"https://github.com/TimvanScherpenzeel/spars\">Spars</a> - General toolkit for creating interactive web experiences.</li>\n<li>​<a href=\"https://github.com/janhuenermann/neurojs\">NeuroJS</a> - JavaScript deep learning and reinforcement learning library.</li>\n<li>​<a href=\"https://github.com/funkia/hareactive\">Hareactive</a> - Purely functional reactive programming library.</li>\n<li>​<a href=\"https://github.com/miragejs/miragejs\">Mirage JS</a> - Client-side server to develop, test and prototype your JavaScript app.</li>\n<li>​<a href=\"https://github.com/foliojs/dfa\">dfa</a> - State machine compiler with regular expression style syntax.</li>\n<li>​<a href=\"https://github.com/treenotation/jtree\">Jtree</a> - Tree Notation TypeScript/Javascript library.</li>\n<li>​<a href=\"https://github.com/ojack/hydra\">Hydra</a> - Livecoding networked visuals in the browser.</li>\n<li>​<a href=\"https://github.com/sindresorhus/p-queue\">p-queue</a> - Promise queue with concurrency control.</li>\n<li>​<a href=\"https://github.com/interactivethings/gsheets\">gsheets</a> - Get public Google Sheets as plain JavaScript/JSON.</li>\n<li>​<a href=\"https://github.com/YBogomolov/alga-ts\">alga-ts</a> - Algebraic graphs implementation in TypeScript.</li>\n<li>​<a href=\"https://github.com/chartjs/Chart.js\">Chart.js</a> - Simple HTML5 Charts using the tag. (<a href=\"https://github.com/chartjs/awesome\">Awesome</a>)</li>\n<li>​<a href=\"https://github.com/sindresorhus/on-change\">on-change</a> - Watch an object or array for changes.</li>\n<li>​<a href=\"https://github.com/fwilkerson/clean-set\">clean-set</a> - Deep assignment alternative to the object spread operator and Object.assign.</li>\n<li>​<a href=\"https://github.com/nepsilon/search-query-parser\">Search Query Syntax Parser</a>​</li>\n<li>​<a href=\"https://github.com/elninotech/uppload\">Uppload</a> - Better JavaScript image uploader with 30+ plugins.</li>\n<li>​<a href=\"https://github.com/pinojs/pino\">pino</a> - Super fast, all natural JSON logger.</li>\n<li>​<a href=\"https://github.com/orbitjs/orbit\">Orbit</a> - Composable data framework for ambitious web applications.</li>\n<li>​<a href=\"https://github.com/anvaka/panzoom\">panzoom</a> - Universal pan and zoom library (DOM, SVG, Custom).</li>\n<li>​<a href=\"https://github.com/jackocnr/intl-tel-input\">intl-tel-input</a> - JavaScript plugin for entering and validating international telephone numbers.</li>\n<li>​<a href=\"https://github.com/mrdoob/three.js\">three.js</a> - JavaScript 3D library.</li>\n<li>​<a href=\"https://github.com/dylang/shortid\">shortid</a> - Short id generator. Url-friendly. Non-predictable. Cluster-compatible.</li>\n<li>​<a href=\"https://github.com/mariusschulz/styx\">styx</a> - Derives a control flow graph from a JavaScript AST.</li>\n<li>​<a href=\"https://github.com/crossfilter/crossfilter\">Crossfilter</a> - JavaScript library for exploring large multivariate datasets in the browser.</li>\n<li>​<a href=\"https://github.com/kopiro/siriwave\">SiriWave</a> - Apple Siri wave-form replicated in a JS library.</li>\n<li>​<a href=\"https://github.com/jamesmcnamara/shades\">Shades</a> - Lodash-inspired lens-like library for Javascript.</li>\n<li>​<a href=\"https://github.com/jgraph/mxgraph\">mxGraph</a> - Fully client side JavaScript diagramming library.</li>\n<li>​<a href=\"https://github.com/npm/cacache\">cacache</a> - Node.js library for managing local key and content address caches.</li>\n<li>​<a href=\"https://github.com/webpack/enhanced-resolve\">enhanced-resolve</a> - Offers an async require.resolve function. It's highly configurable.</li>\n<li>​<a href=\"https://github.com/mmckegg/notevil\">notevil</a> - Evalulate javascript like the built-in javascript eval() method but safely.</li>\n<li>​<a href=\"https://github.com/uber/react-digraph\">react-digraph</a> - Library for creating directed graph editors.</li>\n<li>​<a href=\"https://github.com/mikeal/bent\">bent</a> - Functional JS HTTP client (Node.js &#x26; Fetch) w/ async await.</li>\n<li>​<a href=\"https://github.com/replit/clui\">CLUI</a> - Collection of JavaScript libraries for building command-line interfaces with context-aware autocomplete.</li>\n<li>​<a href=\"https://github.com/robinloeffel/cosha\">cosha</a> - Colorful shadows for your images.</li>\n<li>​<a href=\"https://github.com/selfrefactor/rambda\">Rambda</a> - Faster and smaller alternative to Ramda.</li>\n<li>​<a href=\"https://github.com/mathjax/MathJax\">MathJax</a> - Open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers. (<a href=\"https://www.mathjax.org/\">Web</a>) (<a href=\"https://news.ycombinator.com/item?id=24741077\">HN</a>)</li>\n<li>​<a href=\"https://github.com/wakirin/Litepicker\">Litepicker</a> - Date range picker - lightweight, no dependencies.</li>\n<li>​<a href=\"https://github.com/zloirock/core-js\">core-js</a> - Modular standard library for JavaScript.</li>\n<li>​<a href=\"https://github.com/hustcc/timeago.js\">timeago.js</a> - Nano library (less than 2 kb) used to format datetime with *** time ago statement. eg: '3 hours ago'.</li>\n<li>​<a href=\"https://github.com/yahoo/serialize-javascript\">Serialize JavaScript</a> - Serialize JavaScript to a superset of JSON that includes regular expressions, dates and functions.</li>\n<li>​<a href=\"https://github.com/atomiks/tippyjs\">Tippy.js</a> - Tooltip, popover, dropdown, and menu library.</li>\n<li>​<a href=\"https://github.com/goldfire/howler.js\">howler.js</a> - JavaScript audio library for the modern web.</li>\n<li>​<a href=\"https://github.com/date-fns/date-fns\">date-fns</a> - Modern JavaScript date utility library.</li>\n<li>​<a href=\"https://github.com/Tonejs/Midi\">Midi</a> - Convert MIDI into Tone.js-friendly JSON.</li>\n<li>​<a href=\"https://github.com/justadudewhohacks/face-api.js\">face-api.js</a> - JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js.</li>\n<li>​<a href=\"https://github.com/karlisup/spotlight\">Spotlight</a> - Search widget for your web API.</li>\n<li>​<a href=\"https://github.com/krisk/Fuse\">Fuse</a> - Lightweight fuzzy-search, in JavaScript.</li>\n<li>​<a href=\"https://github.com/xtermjs/xterm.js\">Xterm.js</a> - Terminal for the web.</li>\n<li>​<a href=\"https://github.com/blakeembrey/change-case\">Change Case</a> - Convert strings between camelCase, PascalCase, Capital Case, snake_case and more.</li>\n<li>​<a href=\"https://github.com/bryntum/chronograph\">ChronoGraph</a> - Reactive, graph-based, computation engine.</li>\n<li>​<a href=\"https://github.com/eclipse/sprotty\">Sprotty</a> - Diagramming framework for the web.</li>\n<li>​<a href=\"https://github.com/genderev/prerender.js\">prerender.js</a> - Loads pages quickly on any browser.</li>\n<li>​<a href=\"https://github.com/jshttp/on-finished\">on-finished</a> - Execute a callback when a request closes, finishes, or errors.</li>\n<li>​<a href=\"https://github.com/baianat/color-fns\">ColorFns</a> - Modern JavaScript color utilities library.</li>\n<li>​<a href=\"https://github.com/orling/grapheme-splitter\">grapheme-splitter</a> - JavaScript library that breaks strings into their individual user-perceived characters.</li>\n<li>​<a href=\"https://github.com/web-animations/web-animations-js\">Web Animations</a> - JavaScript implementation of the Web Animations API.</li>\n<li>​<a href=\"https://github.com/sindresorhus/p-limit\">p-limit</a> - Run multiple promise-returning &#x26; async functions with limited concurrency.</li>\n<li>​<a href=\"https://github.com/highcharts/highcharts\">Highcharts JS</a> - JavaScript charting library based on SVG.</li>\n<li>​<a href=\"https://github.com/leeoniya/uPlot\">μPlot</a> - Small, fast chart for time series, lines, areas, ohlc &#x26; bars.</li>\n<li>​<a href=\"https://github.com/Yomguithereal/baobab\">Baobab</a> - JavaScript &#x26; TypeScript persistent and optionally immutable data tree with cursors.</li>\n<li>​<a href=\"https://github.com/mathiasbynens/emoji-regex\">emoji-regex</a> - Regular expression to match all Emoji-only symbols as per the Unicode Standard.</li>\n<li>​<a href=\"https://github.com/miguelmota/merkletreejs\">MerkleTree.js</a> - Construct Merkle Trees and verify proofs in JavaScript.</li>\n<li>​<a href=\"https://github.com/snabbdom/snabbdom\">Snabbdom</a> - Virtual DOM library with focus on simplicity, modularity, powerful features and performance.</li>\n<li>​<a href=\"https://github.com/donavon/thwack\">Thwack</a> - Tiny modern data fetching solution.</li>\n<li>​<a href=\"https://github.com/mathiasbynens/regenerate\">Regenerate</a> - Generate JavaScript-compatible regular expressions based on a given set of Unicode symbols or code points.</li>\n<li>​<a href=\"https://github.com/bikeshaving/crank\">Crank.js</a> - Write JSX-driven components with functions, promises and generators. (<a href=\"https://crank.js.org/blog/introducing-crank\">Article</a>) (<a href=\"https://www.reddit.com/r/reactjs/comments/g2u135/crankjs_introducting_crank/\">Reddit</a>) (<a href=\"https://news.ycombinator.com/item?id=22903967\">HN</a>)</li>\n<li>​<a href=\"https://github.com/developit/redaxios\">redaxios</a> - Axios API, as an 800 byte Fetch wrapper.</li>\n<li>​<a href=\"https://github.com/josdejong/mathjs\">Math.js</a> - Extensive math library for JavaScript and Node.js.</li>\n<li>​<a href=\"https://github.com/mapbox/pixelmatch\">pixelmatch</a> - Smallest, simplest and fastest JavaScript pixel-level image comparison library.</li>\n<li>​<a href=\"https://github.com/Shopify/quilt\">quilt</a> - Loosely related set of packages for JavaScript / TypeScript projects at Shopify.</li>\n<li>​<a href=\"https://github.com/benjamine/jsondiffpatch\">jsondiffpatch</a> - Diff &#x26; patch JavaScript objects.</li>\n<li>​<a href=\"https://github.com/mweststrate/rval\">RVal</a> - Minimalistic transparent reactive programming library.</li>\n<li>​<a href=\"https://github.com/Jam3/orbit-controls\">orbit-controls</a> - Generic controls for orbiting a target in 3D.</li>\n<li>​<a href=\"https://github.com/Rich-Harris/estree-walker\">estree-walker</a> - Traverse an ESTree-compliant AST.</li>\n<li>​<a href=\"https://github.com/jitsi/lib-jitsi-meet\">Jitsi Meet API library</a> - Can use Jitsi Meet API to create Jitsi Meet video conferences with a custom GUI.</li>\n<li>​<a href=\"https://github.com/jdan/isomer\">isomer</a> - Simple isometric graphics library for HTML5 canvas.</li>\n<li>​<a href=\"https://github.com/kristianmandrup/schema-to-yup\">Schema to Yup schema</a>​</li>\n<li>​<a href=\"https://github.com/egoist/mordred\">Mordred</a> - Source data from anywhere, for Next.js, Nuxt.js, Eleventy and many more.</li>\n<li>​<a href=\"https://github.com/ashthornton-gc/asscroll\">ASScroll</a> - Hybrid smooth scroll setup that combines the performance gains of virtual scroll with the reliability of native scroll.</li>\n<li>​<a href=\"https://github.com/bendc/gallery\">Gallery</a> - Light, responsive, and performant JavaScript gallery.</li>\n<li>​<a href=\"https://github.com/logux/server\">Logux Server</a> - Build own Logux server or make proxy between WebSocket and HTTP backend on any language.</li>\n<li>​<a href=\"https://github.com/expo/results\">@expo/results</a> - Efficient, standards-compliant library for representing results of successful or failed operations.</li>\n<li>​<a href=\"https://github.com/milesj/emojibase\">Emojibase</a> - Collection of lightweight, up-to-date, pre-generated, specification compliant, localized emoji JSON datasets, regex patterns, and more.</li>\n<li>​serve-favicon - Node.js middleware for serving a favicon.</li>\n<li>​<a href=\"https://github.com/kevva/download\">download</a> - Download and extract files.</li>\n<li>​<a href=\"https://github.com/ricokahler/color2k\">color2k</a> - Color parsing and manipulation lib served in 2kB or less.</li>\n<li>​<a href=\"https://sandstorm.io/\">Sandstorm</a> - Open source platform for self-hosting web apps. (<a href=\"https://github.com/sandstorm-io/sandstorm\">Code</a>)</li>\n<li>​<a href=\"https://github.com/chrvadala/transformation-matrix\">transformation-matrix</a> - JS isomorphic 2D affine transformations written in ES6 syntax.</li>\n<li>​<a href=\"https://github.com/haltu/muuri\">Muuri</a> - JavaScript layout engine that allows you to build all kinds of layouts and make them responsive, sortable, filterable, draggable and/or animated.</li>\n<li>​<a href=\"https://github.com/nathancahill/split\">Split</a> - Unopinionated utilities for resizeable split views.</li>\n<li>​<a href=\"https://github.com/wagerfield/parallax\">Parallax Engine</a> - Reacts to the orientation of a smart device.</li>\n<li>​<a href=\"https://github.com/mcollina/fastq\">fastq</a> - Fast, in memory work queue.</li>\n<li>​<a href=\"https://github.com/vinaypillai/ac-colors\">ac-colors</a> - Reactive JavaScript color library that can freely convert color formats.</li>\n<li>​<a href=\"https://github.com/mcollina/sonic-boom\">sonic-boom</a> - Extremely fast utf8 only stream implementation.</li>\n<li>​<a href=\"https://github.com/pshihn/rough-notation\">Rough Notation</a> - Small JavaScript library to create and animate annotations on a web page. (<a href=\"https://news.ycombinator.com/item?id=23339244\">HN</a>)</li>\n<li>​<a href=\"https://github.com/codefrau/SqueakJS\">SqueakJS</a> - Squeak VM for the Web and Node.js. (<a href=\"https://squeak.js.org/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/fregante/fit-textarea\">fit-textarea</a> - Automatically expand a to fit its content, in a few bytes.</li>\n<li>​<a href=\"https://github.com/Simonwep/nanopop\">NanoPop</a> - Ultra Tiny, Opinionated Positioning Engine. (<a href=\"https://simonwep.github.io/nanopop/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/rish-16/Angelfire\">Angelfire</a> - Lets you quickly build right-click-enabled context menus and drop-down menus for any element on your webpage.</li>\n<li>​<a href=\"https://github.com/mafintosh/csv-parser\">csv-parser</a> - Streaming csv parser inspired by binary-csv that aims to be faster than everyone else.</li>\n<li>​<a href=\"https://github.com/substantial/updeep\">updeep</a> - Easily update nested frozen objects and arrays in a declarative and immutable manner.</li>\n<li>​<a href=\"https://github.com/AndriiHeonia/hull\">Hull.js</a> - JavaScript library that builds concave hull by set of points.</li>\n<li>​<a href=\"https://github.com/KuroLabs/stegcloak\">StegCloak</a> - Hide secrets with invisible characters in plain text securely using passwords.</li>\n<li>​<a href=\"https://github.com/sindresorhus/p-min-delay\">p-min-delay</a> - Delay a promise a minimum amount of time.</li>\n<li>​<a href=\"https://github.com/FGRibreau/match-when\">match-when</a> - Pattern matching for modern JavaScript.</li>\n<li>​<a href=\"https://github.com/nicolaspanel/numjs\">NumJs</a> - Like NumPy, in JavaScript.</li>\n<li>​<a href=\"https://github.com/spectjs/spect\">spect</a> - Reactive aspect-oriented web-framework.</li>\n<li>​<a href=\"https://github.com/multiformats/js-cid\">js-cid</a> - CID implementation in JavaScript.</li>\n<li>​<a href=\"https://github.com/ipld/js-ipld-block\">js-ipld-block</a> - Implementation of the Block data structure in JavaScript.</li>\n<li>​<a href=\"https://github.com/reframejs/wildcard-api\">wildcard-api</a> - Functions as API.</li>\n<li>​<a href=\"https://github.com/bpmn-io/bpmn-js\">bpmn-js</a> - BPMN 2.0 rendering toolkit and web modeler.</li>\n<li>​<a href=\"https://github.com/soswow/fit-curve\">fit-curve</a> - JavaScript implementation of Philip J. Schneider's \"Algorithm for Automatically Fitting Digitized Curves\" from the book \"Graphics Gems\".</li>\n<li>​<a href=\"https://github.com/nunofgs/clean-deep\">clean-deep</a> - Remove falsy, empty or nullable values from objects.</li>\n<li>​<a href=\"https://github.com/jpmorganchase/regular-table\">regular-table</a> - Regular library, for async and virtual data models.</li>\n<li>​<a href=\"https://github.com/hotwired/stimulus\">Stimulus</a> - Modest JavaScript framework for the HTML you already have. (<a href=\"https://stimulus.hotwire.dev/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/josephernest/bigpicture.js/\">bigpicture.js</a> - Library that allows infinite panning and infinite zooming in HTML pages. (<a href=\"https://josephernest.github.io/bigpicture.js/index.html\">Web</a>)</li>\n<li>​<a href=\"https://github.com/team-video/tragopan\">Tragopan</a> - Minimal dependency-free pan/zoom library. (<a href=\"https://news.ycombinator.com/item?id=23579102\">HN</a>)</li>\n<li>​<a href=\"https://github.com/terkelg/deakins\">Deakins</a> - Small Canvas 2D Camera.</li>\n<li>​<a href=\"https://github.com/turbolinks/turbolinks\">Turbolinks</a> - Makes navigating your web application faster.</li>\n<li>​<a href=\"https://github.com/CindyJS/CindyJS\">CindyJS</a> - Framework to create interactive (mathematical) content for the web. (<a href=\"https://cindyjs.org/\">Web</a>) (<a href=\"https://news.ycombinator.com/item?id=23589296\">HN</a>)</li>\n<li>​<a href=\"https://github.com/axios/axios\">axios</a> - Promise based HTTP client for the browser and nodeJS.</li>\n<li>​<a href=\"https://github.com/lukeed/astray\">astray</a> - Walk an AST without being led astray.</li>\n<li>​<a href=\"https://github.com/ikatyang/vnopts\">vnopts</a> - Validate and normalize options.</li>\n<li>​<a href=\"https://github.com/catdad/canvas-confetti\">canvas confetti</a> - On-demand confetti gun. (<a href=\"https://www.kirilv.com/canvas-confetti/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/dagrejs/graphlib\">Graphlib</a> - JavaScript library that provides data structures for undirected and directed multi-graphs along with algorithms that can be used with them.</li>\n<li>​<a href=\"https://github.com/dagrejs/dagre\">Dagre</a> - JavaScript library that makes it easy to lay out directed graphs on the client-side.</li>\n<li>​<a href=\"https://github.com/MozillaReality/ecsy\">ecsy</a> - Highly experimental Entity Component System framework implemented in javascript, aiming to be lightweight, easy to use and with good performance. (<a href=\"https://ecsy.io/docs/#/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/iendeavor/object-visualizer\">Object Visualizer</a> - Visualize the JSON object to the DOM. (<a href=\"https://news.ycombinator.com/item?id=23860568\">HN</a>)</li>\n<li>​<a href=\"https://github.com/open-draft/reach-schema\">Reach Schema</a> - Functional schema-driven JavaScript object validation library.</li>\n<li>​<a href=\"https://github.com/cyclejs/callbags\">@cycle/callbags</a> - Set of commonly used stream operators implemented as callbags with Typescript and ES modules.</li>\n<li>​<a href=\"https://github.com/thi-ng/umbrella/\">umbrella</a> - Broadly scoped ecosystem &#x26; mono-repository of ~135 TypeScript projects for functional, data driven development.</li>\n<li>​<a href=\"https://github.com/developit/htm\">HTM</a> - JSX-like syntax in plain JavaScript - no transpiler necessary.</li>\n<li>​<a href=\"https://github.com/nativescript/nativescript\">NativeScript</a> - Framework for building native iOS and Android apps using JavaScript and CSS.</li>\n<li>​<a href=\"https://github.com/google/schema-dts\">schema-dts</a> - JSON-LD TypeScript types for Schema.org vocabulary.</li>\n<li>​<a href=\"https://github.com/flatpickr/flatpickr\">flatpickr</a> - JS date time picker.</li>\n<li>​<a href=\"https://github.com/blitz-js/superjson\">superjson</a> - Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.</li>\n<li>​<a href=\"https://github.com/RobinMalfait/lazy-collections\">lazy-collections</a> - Collection of fast and lazy operations.</li>\n<li>​<a href=\"https://github.com/steveruizok/perfect-arrows\">Perfect Arrows</a> - Set of functions for drawing perfect arrows between points and shapes.</li>\n<li>​<a href=\"https://github.com/algolia/autocomplete.js\">Autocomplete.js</a> - Fast and full-featured autocomplete library.</li>\n<li>​<a href=\"https://github.com/balazsbotond/urlcat\">urlcat</a> - URL builder library for JavaScript. (<a href=\"https://urlcat.dev/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/awslabs/diagram-maker\">Diagram Maker</a> - Library to display an interactive editor for any graph-like data. (<a href=\"https://awslabs.github.io/diagram-maker/\">Docs</a>) (<a href=\"https://news.ycombinator.com/item?id=24688860\">HN</a>)</li>\n<li>​<a href=\"https://github.com/miketalbot/js-coroutines\">js-coroutines</a> - 60fps with JavaScript Coroutines for idle processing and animation.</li>\n<li>​<a href=\"https://github.com/dphilipson/transducist\">Transducist</a> - Ergonomic JavaScript/TypeScript transducers for beginners and experts.</li>\n<li>​<a href=\"https://github.com/MikeMcl/decimal.js\">decimal.js</a> - Arbitrary-precision Decimal type for JavaScript.</li>\n<li>​<a href=\"https://github.com/soatok/constant-time-js\">Constant-Time JavaScript</a> - Constant-time algorithms written in TypeScript.</li>\n<li>​<a href=\"https://github.com/SheetJS/sheetjs\">SheetJS</a> - Spreadsheet Data Toolkit. Read, edit, and export spreadsheets. Works in web browsers and servers. (<a href=\"https://sheetjs.com/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/z-pattern-matching/z\">Z</a> - Pattern Matching for JavaScript. (<a href=\"https://z-pattern-matching.github.io/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/graphology/graphology\">Graphology</a> - Robust &#x26; multipurpose Graph object for JavaScript &#x26; TypeScript. (<a href=\"https://graphology.github.io/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/node-ffi-napi/weak-napi\">weak-napi</a> - Make weak references to JavaScript Objects.</li>\n<li>​<a href=\"https://github.com/lukeed/nestie\">nestie</a> - Tiny (211B) and fast utility to expand a flattened object.</li>\n<li>​<a href=\"https://github.com/nuysoft/Mock\">Mock.js</a> - Simulation data generator.</li>\n<li>​<a href=\"https://github.com/TimvanScherpenzeel/detect-features\">Detect features</a> - Detect and report browser and hardware features.</li>\n<li>​<a href=\"https://github.com/Stuk/jszip\">JSZip</a> - Create, read and edit .zip files with JavaScript.</li>\n<li>​<a href=\"https://github.com/JedWatson/classnames\">Classnames</a> - Simple javascript utility for conditionally joining classNames together.</li>\n<li>​<a href=\"https://github.com/joe-bell/cx\">cx</a> - Concatenate your classes (with shortcuts).</li>\n<li>​<a href=\"https://github.com/borderless/defer\">Defer</a> - Tiny, type-safe, JavaScript-native defer implementation.</li>\n<li>​<a href=\"https://github.com/lukeed/freshie\">freshie</a> - Fresh take on building universal applications with support for pluggable frontends and backends.</li>\n<li>​<a href=\"https://github.com/mengshukeji/Luckysheet\">Luckysheet</a> - Online spreadsheet like excel that is powerful, simple to configure, and completely open source. (<a href=\"https://mengshukeji.github.io/LuckysheetDocs/guide/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/leongersen/noUiSlider\">noUiSlider</a> - Lightweight JavaScript range slider.</li>\n<li>​<a href=\"https://github.com/davidshimjs/qrcodejs\">QRCode.js</a> - Cross-browser QRCode generator for JavaScript. (<a href=\"https://davidshimjs.github.io/qrcodejs/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/hyperhype/hyperscript\">HyperScript</a> - Create HyperText with JavaScript, on client or server.</li>\n<li>​<a href=\"https://github.com/ohanhi/hyperscript-helpers\">hyperscript-helpers</a> - Terse syntax for hyperscript.</li>\n<li>​<a href=\"https://github.com/EnlighterJS/EnlighterJS\">EnlighterJS</a> - Open source syntax highlighter written in pure javascript.</li>\n<li>​<a href=\"https://github.com/anko/eslisp\">eslisp</a> - S-expression syntax for JavaScript, with Lisp-like hygienic macros. Minimal core, maximally customisable.</li>\n<li>​<a href=\"https://github.com/marvinhagemeister/smoldash\">Smoldash</a> - Tiny lodash alternative built for the modern web.</li>\n<li>​<a href=\"https://github.com/tameemsafi/typewriterjs\">TypewriterJS</a> - Simple yet powerful native javascript plugin for a cool typewriter effect.</li>\n<li>​<a href=\"https://github.com/mpetazzoni/sse.js\">sse.js</a> - Flexible Server Side Events source for JavaScript.</li>\n<li>​<a href=\"https://github.com/dyatko/arkit\">Arkit</a> - Visualises JavaScript, TypeScript and Flow codebases as meaningful and committable architecture diagrams. (<a href=\"https://arkit.pro/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/aws/jsii\">jsii</a> - Allows code in any language to naturally interact with JavaScript classes.</li>\n<li>​<a href=\"https://github.com/dai-shi/proxy-memoize\">proxy-memoize</a> - Intuitive magical memoization library with Proxy and WeakMap. (<a href=\"https://twitter.com/dai_shi/status/1321089602623557639\">Tweet</a>)</li>\n<li>​<a href=\"https://github.com/cosmos/cosmjs\">CosmJS</a> - Modular library consisting of multiple packages to power web experiences.</li>\n<li>​<a href=\"https://github.com/arwes/arwes\">Arwes</a> - Futuristic Sci-Fi and Cyberpunk Graphical User Interface Framework for Web Apps. (<a href=\"https://arwes.dev/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/lupomontero/psl\">psl (Public Suffix List)</a> - JavaScript domain name parser based on the Public Suffix List.</li>\n<li>​<a href=\"https://github.com/apollographql/invariant-packages\">invariant-packages</a> - Packages for working with invariant(condition, message) assertions.</li>\n<li>​<a href=\"https://github.com/garronej/evt\">evt</a> - EventEmitter's typesafe replacement.</li>\n<li>​<a href=\"https://github.com/samyk/webscan\">webscan</a> - Browser-based network scanner &#x26; local-IP detection.</li>\n<li>​<a href=\"https://github.com/rumkin/pill\">Pill</a> - Add dynamic content loading to static sites with only 1 KiB of JS.</li>\n<li>​<a href=\"https://github.com/epoberezkin/fast-deep-equal\">fast-deep-equal</a> - Fastest deep equal with ES6 Map, Set and Typed arrays support.</li>\n<li>​<a href=\"https://github.com/egoist/preview-card\">preview-card</a> - Customizable social media preview image.</li>\n<li>​<a href=\"https://github.com/naver/egjs-flicking\">egjs-flicking</a> - Easy-to-use and performant infinite carousel.</li>\n<li>​<a href=\"https://github.com/contrawork/sse-z\">SSE-Z</a> - Slim, easy-to-use wrapper around EventSource.</li>\n<li>​<a href=\"https://github.com/snowpackjs/DefinitelyExported\">DefinitelyExported</a> - Community-defined export maps for popular npm packages.</li>\n<li>​<a href=\"https://github.com/kpdecker/jsdiff\">jsdiff</a> - JavaScript text differencing implementation.</li>\n<li>​<a href=\"https://github.com/handsontable/hyperformula\">HyperFormula</a> - Open source, spreadsheet-like calculation engine.</li>\n<li>​<a href=\"https://github.com/fastify/fast-json-stringify\">fast-json-stringify</a> - Significantly faster than JSON.stringify() for small payloads.</li>\n<li>​<a href=\"https://github.com/omrilotan/isbot\">isbot</a> - JavaScript module that detects bots/crawlers/spiders via the user agent.</li>\n<li>​<a href=\"https://github.com/pmndrs/valtio\">valtio</a> - Makes proxy-state simple.</li>\n<li>​<a href=\"https://github.com/nodeca/pica\">pica</a> - High quality image resize in browser.</li>\n<li>​<a href=\"https://github.com/gajus/planton\">Planton</a> - Database-agnostic task scheduler.</li>\n<li>​<a href=\"https://github.com/jshttp/mime-types\">mime-types</a> - JavaScript content-type utility.</li>\n<li>​<a href=\"https://github.com/kentcdodds/match-sorter\">match-sorter</a> - Simple, expected, and deterministic best-match sorting of an array in JavaScript.</li>\n<li>​<a href=\"https://github.com/Azure/fetch-event-source\">Fetch Event Source</a> - Better API for making Event Source requests, with all the features of fetch().</li>\n<li>​<a href=\"https://github.com/pmndrs/rafz\">rafz</a> - Coordinate requestAnimationFrame calls across your app and/or libraries.</li>\n<li>​<a href=\"https://github.com/sindresorhus/p-state\">p-state</a> - Inspect the state of a promise.</li>\n<li>​<a href=\"https://github.com/copy/v86\">v86</a> - x86 virtualization in JavaScript, running in your browser and NodeJS. (<a href=\"https://copy.sh/v86/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/caroso1222/notyf\">Notyf</a> - Minimalistic, responsive, vanilla JavaScript library to show toast notifications.</li>\n<li>​<a href=\"https://github.com/daybrush/moveable\">Moveable</a> - Draggable, Resizable, Scalable, Rotatable, Warpable, Pinchable, Groupable, Snappable.</li>\n<li>​<a href=\"https://github.com/sindresorhus/execa\">Execa</a> - Process execution for humans.</li>\n<li>​<a href=\"https://github.com/sindresorhus/quick-lru\">quick-lru</a> - Simple “Least Recently Used” (LRU) cache.</li>\n<li>​<a href=\"https://github.com/YuriGor/deepdash\">Deepdash</a> - Tree traversal library written in Underscore/Lodash fashion. (<a href=\"https://deepdash.io/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/ai/nanodelay\">Nano Delay</a> - Tiny (25 bytes) Promise wrapper around setTimeout.</li>\n<li>​<a href=\"https://github.com/guybedford/es-module-lexer\">ES Module Lexer</a> - Low-overhead lexer dedicated to ES module parsing for fast analysis.</li>\n<li>​<a href=\"https://github.com/kripod/keez\">keez</a> - Frictionless hotkey handling for browsers.</li>\n<li>​<a href=\"https://github.com/terkelg/zet\">Zet</a> - Set() as it should be.</li>\n<li>​<a href=\"https://github.com/badgateway/ketting\">Ketting</a> - Hypermedia client for JavaScript.</li>\n<li>​<a href=\"https://github.com/sindresorhus/yocto-queue\">yocto-queue</a> - Tiny queue data structure.</li>\n<li>​<a href=\"https://github.com/nanojsx/nano\">Nano JSX</a> - Lightweight 1kB JSX library. (<a href=\"https://nanojsx.github.io/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/nythrox/effects.js\">Effects.js</a> - Algebraic effects in javascript with scoped handlers, multishot delimited continuations, stack safety and do notation.</li>\n<li>​<a href=\"https://github.com/alexbol99/flatten-js\">flatten-js</a> - JavaScript library for 2d geometry.</li>\n<li>​<a href=\"https://github.com/sindresorhus/is-retry-allowed\">is-retry-allowed</a> - Check whether a request can be retried based on the error.code.</li>\n<li>​<a href=\"https://github.com/microsoft/backfill\">backfill</a> - JavaScript caching library for reducing build time.</li>\n<li>​<a href=\"https://github.com/simontonsoftware/s-libs\">S-Libs</a> - Collection of libraries for any of JS, RxJS, or Angular.</li>\n<li>​<a href=\"https://github.com/webpack/watchpack\">watchpack</a> - Wrapper library for directory and file watching.</li>\n<li>​<a href=\"https://github.com/WebReflection/async-tag\">async-tag</a> - Resolves template literals tag values before applying a generic tag.</li>\n<li>​<a href=\"https://github.com/sindresorhus/serialize-error\">serialize-error</a> - Serialize/deserialize an error into a plain object.</li>\n<li>​<a href=\"https://github.com/marvinhagemeister/errorstacks\">errorstacks</a> - Tiny library to parse error stack traces.</li>\n<li>​<a href=\"https://github.com/fritzy/ape-ecs\">Ape-ECS</a> - Entity-Component-System library for JavaScript.</li>\n<li>​<a href=\"https://github.com/jakubroztocil/rrule\">rrule.js</a> - JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more. (<a href=\"https://jakubroztocil.github.io/rrule/\">Demo</a>)</li>\n<li>​<a href=\"https://github.com/rdmurphy/scroller\">scroller</a> - Super-tiny library for your scrollytelling needs.</li>\n<li>​<a href=\"https://github.com/kkomelin/isomorphic-dompurify\">Isomorphic DOMPurify</a> - Makes it possible to use DOMPurify on server and client in the same way.</li>\n<li>​<a href=\"https://github.com/lukeed/navaid\">navaid</a> - Navigation aid (aka, router) for the browser in 850 bytes.</li>\n<li>​<a href=\"https://github.com/fitzgen/glob-to-regexp\">glob-to-regexp</a> - Convert a glob to a regular expression.</li>\n<li>​<a href=\"https://github.com/ionstage/cmap\">cmap</a> - Interactive visualization library for concept map.</li>\n<li>​<a href=\"https://github.com/lezer-parser/lezer-tree\">lezer-tree</a> - Incremental GLR parser intended for use in an editor or similar system.</li>\n<li>​<a href=\"https://github.com/lukeed/matchit\">matchit</a> - Quickly parse &#x26; match URLs.</li>\n<li>​<a href=\"https://github.com/acornjs/acorn\">acorn</a> - Tiny, fast JavaScript parser, written completely in JavaScript.</li>\n<li>​<a href=\"https://github.com/mathiasbynens/jsesc\">jsesc</a> - Given some data, jsesc returns the shortest possible stringified &#x26; ASCII-safe representation of that data.</li>\n<li>​<a href=\"https://github.com/qntm/fastjson\">fastjson</a> - Single-tweet, standards-compliant, high-performance JSON stack.</li>\n<li>​<a href=\"https://github.com/TomerAberbach/grfn\">grfn</a> - Tiny (~400B) utility that executes a dependency graph of async functions as concurrently as possible.</li>\n<li>​<a href=\"https://github.com/mozilla/nunjucks\">Nunjucks</a> - Powerful templating engine with inheritance, asynchronous control, and more. (<a href=\"https://mozilla.github.io/nunjucks/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/behavior3/behavior3js\">Behavior3JS</a> - Structures and algorithms that assist you in the task of creating intelligent agents for your game or application.</li>\n<li>​<a href=\"https://github.com/ljharb/qs\">qs</a> - Querystring parser with nesting support.</li>\n<li>​<a href=\"https://github.com/terkelg/exifer\">Exifer</a> - Small module that read JPEG/TIFF meta-data.</li>\n<li>​<a href=\"https://github.com/Zod-/jsVideoUrlParser\">jsVideoUrlParser</a> - JavaScript parser to extract information like provider, channel, id, start time from YouTube, Vimeo, Dailymotion, Twitch,... urls.</li>\n<li>​<a href=\"https://github.com/typestack/typedi\">TypeDI</a> - Dependency injection tool for TypeScript and JavaScript.</li>\n<li>​<a href=\"https://github.com/franleplant/ibridge\">ibridge</a> - Tiny, promise based, type safe library for easy, bidirectional and secure iframe communication.</li>\n<li>​<a href=\"https://github.com/getify/monio\">Monio</a> - Async-capable IO monad for JS.</li>\n<li>​<a href=\"https://www.totaljs.com/\">Total.js</a> - Excellent and stable server-side Node.js framework, client-side library for creating web applications with more than 230 UI components for free.</li>\n<li>​<a href=\"https://github.com/alexreardon/memoize-one\">memoize-one</a> - Memoization library which only remembers the latest invocation.</li>\n<li>​<a href=\"https://github.com/tidwall/pjson\">pjson</a> - JSON stream parser for Go.</li>\n<li>​<a href=\"https://github.com/mbostock/internmap\">InternMap</a> - Map and Set with automatic key interning.</li>\n<li>​<a href=\"https://github.com/GeometryCollective/geometry-processing-js\">geometry-processing-js</a> - Fast, general-purpose framework for geometry processing on the web.</li>\n<li>​<a href=\"https://github.com/Aplet123/iterplus\">Iterplus</a> - Best of Rust/Haskell/Python iterators in JavaScript.</li>\n<li>​<a href=\"https://github.com/smolscrolljs/smolscroll\">SmolScroll</a> - Tiny, flexible scroll listener with React support.</li>\n<li>​<a href=\"https://github.com/observablehq/parser\">Observable parser</a>​</li>\n<li>​<a href=\"https://github.com/matthewp/robot\">Robot</a> - Functional, immutable Finite State Machine library. (<a href=\"https://thisrobot.life/\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/eslachance/enmap\">Enmap</a> - Enhanced Map structure with additional utility methods.</li>\n<li>​<a href=\"https://github.com/flauwekeul/honeycomb\">Honeycomb</a> - Create hex grids easily, in node or the browser.</li>\n<li>​<a href=\"https://github.com/sindresorhus/chunkify\">chunkify</a> - Split an iterable into evenly sized chunks.</li>\n<li>​<a href=\"https://github.com/skevy/wobble\">wobble</a> - Tiny spring physics micro-library that models a damped harmonic oscillator.</li>\n<li>​<a href=\"https://github.com/lukeed/tmp-cache\">tmp-cache</a> - Least-recently-used cache in 35 lines of code.</li>\n<li>​<a href=\"https://github.com/browserify/static-eval\">static-eval</a> - Evaluate statically-analyzable expressions.</li>\n<li>​<a href=\"https://github.com/vanruesc/sparse-octree\">Sparse Octree</a> - Sparse, pointer-based octree data structure.</li>\n<li>​<a href=\"https://github.com/szimek/signature_pad\">Signature Pad</a> - JavaScript library for drawing smooth signatures.</li>\n<li>​<a href=\"https://github.com/egoist/dom-to-image-retina\">dom-to-image-retina</a> - dom-to-image but generates high-resolution images.</li>\n<li>​<a href=\"https://github.com/pimterry/loglevel\">loglevel</a> - Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods.</li>\n<li>​<a href=\"https://github.com/steveruizok/perfect-freehand\">Perfect Freehand</a> - Draw perfect freehand lines.</li>\n<li>​<a href=\"https://github.com/alojs/alo\">Alo</a> - Full-fledged state management. (<a href=\"https://www.alojs.com/index.html\">Docs</a>)</li>\n<li>​<a href=\"https://github.com/form-data/form-data\">Form-Data</a> - Library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.</li>\n<li>​<a href=\"https://github.com/sindresorhus/conf\">conf</a> - Simple config handling for your app or module.</li>\n<li>​<a href=\"https://github.com/mattdesl/gifenc\">gifenc</a> - Fast and lightweight pure-JavaScript GIF encoder.</li>\n<li>​<a href=\"https://github.com/remusao/tldts\">tldts</a> - Blazing Fast URL Parsing.</li>\n<li>​<a href=\"https://github.com/barbajs/barba\">Barba.js</a> - Easy-to-use library that helps you create fluid and smooth transitions between your website's pages.</li>\n<li>​<a href=\"https://github.com/Vestride/Shuffle\">Shuffle.js</a> - Categorize, sort, and filter a responsive grid of items. (<a href=\"https://vestride.github.io/Shuffle/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/stdlib-js/stdlib\">stdlib</a> - Standard library for JavaScript and Node.js. (<a href=\"https://stdlib.io/\">Web</a>)</li>\n<li>​<a href=\"https://github.com/loganfsmyth/gensync\">gensync</a> - Allows users to use generators in order to write common functions that can be both sync or async.</li>\n<li>​<a href=\"https://github.com/monet/monet.js\">monet.js</a> - Monadic types library for JavaScript.</li>\n<li>​<a href=\"https://github.com/anvaka/VivaGraphJS\">VivaGraph</a> - Graph drawing library for JavaScript.</li>\n<li>​<a href=\"https://github.com/qteatime/crochet\">Crochet</a> - Small engine for story-driven games.</li>\n<li>​<a href=\"https://github.com/maraisr/diary\">diary</a> - Zero-dependency, fast logging library for both Node and Browser.</li>\n<li>​<a href=\"https://github.com/lukeed/tinydate\">tinydate</a> - Tiny reusable date formatter.</li>\n<li>​<a href=\"https://github.com/fingerprintjs/fingerprintjs\">FingerprintJS</a> - Browser fingerprinting library with the highest accuracy and stability.</li>\n<li>​<a href=\"https://github.com/ivan7237d/antiutils\">Antiutils</a> - TypeScript/JavaScript utilities for those who don't like utilities.</li>\n</ul>\n<h2><a href=\"https://github.com/bgoonz/Web-Dev-Hub-Docs/blob/master/javascript/untitled/README.md#links-\"></a>Links<a href=\"\"></a></h2>\n<ul>\n<li>​<a href=\"https://www.npmjs.com/\">NPM</a> - Node package manager registry.</li>\n<li>​<a href=\"https://github.com/notthetup/awesome-webaudio\">Awesome WebAudio</a>​</li>\n<li>​<a href=\"https://github.com/darrylhebbes/awesome_xstate\">Awesome XState</a>​</li>\n<li>​<a href=\"https://moiva.io/\">Moiva.io</a> - Measure and compare JavaScript libraries side by side.</li>\n<li>​<a href=\"https://about.scarf.sh/\">Scarf</a> - Installation analytics for your npm package. (<a href=\"https://github.com/scarf-sh/scarf-js\">Code</a>) {% endtab %} {% endtabs %}</li>\n</ul>\n<!--EndFragment-->"},{"url":"/blog/webdev-setup/","relativePath":"blog/webdev-setup.md","relativeDir":"blog","base":"webdev-setup.md","name":"webdev-setup","frontmatter":{"title":"WebDev Setup","template":"post","subtitle":"Basic Web Development Environment Setup","excerpt":"Windows Subsystem for Linux (WSL) and Ubuntu","date":"2022-05-08T18:10:03.296Z","image":"https://cdn-images-1.medium.com/max/800/0*aqKP1drNHmNm34zz.jpg","thumb_image":"https://cdn-images-1.medium.com/max/800/0*aqKP1drNHmNm34zz.jpg","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/js.yaml","src/data/categories/javascript.yaml"],"tags":["src/data/tags/links.yaml","src/data/tags/resources.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/vs-code-extensions.md","src/pages/blog/code-playgrounds-of-2021.md","src/pages/blog/adding-css-to-your-html.md","src/pages/blog/deploy-react-app-to-heroku.md"],"cmseditable":true},"html":"<h1>Basic Web Development Environment Setup</h1>\n<p>Windows Subsystem for Linux (WSL) and Ubuntu</p>\n<hr>\n<h3>Basic Web Development Environment Setup</h3>\n<h4>Windows Subsystem for Linux (WSL) and Ubuntu</h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*aqKP1drNHmNm34zz.jpg\" class=\"graf-image\" />\n</figure>Test if you have Ubuntu installed by typing \"Ubuntu\" in the search box in the bottom app bar that reads \"Type here to search\". If you see a search result that reads **\"Ubuntu 20.04 LTS\"** with \"App\" under it, then you have it installed.\n<ol>\n<li><span id=\"110a\">In the application search box in the bottom bar, type \"PowerShell\" to find the application named \"Windows PowerShell\"</span></li>\n<li><span id=\"54fd\">Right-click on \"Windows PowerShell\" and choose \"Run as administrator\" from the popup menu</span></li>\n<li><span id=\"a018\">In the blue PowerShell window, type the following: <code class=\"language-text\">Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux</code></span></li>\n<li><span id=\"6269\">Restart your computer</span></li>\n<li><span id=\"6dd9\">In the application search box in the bottom bar, type \"Store\" to find the application named \"Microsoft Store\"</span></li>\n<li><span id=\"eb4e\">Click \"Microsoft Store\"</span></li>\n<li><span id=\"74c1\">Click the \"Search\" button in the upper-right corner of the window</span></li>\n<li><span id=\"9d35\">Type in \"Ubuntu\"</span></li>\n<li><span id=\"4205\">Click \"Run Linux on Windows (Get the apps)\"</span></li>\n<li><span id=\"1799\">Click the orange tile labeled <strong>\"Ubuntu\"</strong> Note that there are 3 versions in the Microsoft Store… you want the one just entitled 'Ubuntu'</span></li>\n<li><span id=\"edec\">Click \"Install\"</span></li>\n<li><span id=\"2935\">After it downloads, click \"Launch\"</span></li>\n<li><span id=\"a859\">If you get the option, pin the application to the task bar. Otherwise, right-click on the orange Ubuntu icon in the task bar and choose \"Pin to taskbar\"</span></li>\n<li><span id=\"669c\">When prompted to \"Enter new UNIX username\", type your first name with no spaces</span></li>\n<li><span id=\"e9c1\">When prompted, enter and retype a password for this UNIX user (it can be the same as your Windows password)</span></li>\n<li><span id=\"4217\">Confirm your installation by typing the command <code class=\"language-text\">whoami 'as in who-am-i'</code>followed by Enter at the prompt (it should print your first name)</span></li>\n<li><span id=\"48fe\">You need to update your packages, so type <code class=\"language-text\">sudo apt update</code> (if prompted for your password, enter it)</span></li>\n<li><span id=\"d12f\">You need to upgrade your packages, so type <code class=\"language-text\">sudo apt upgrade</code> (if prompted for your password, enter it)</span></li>\n</ol>\n<h3>Git</h3>\n<p>Git comes with Ubuntu, so there's nothing to install. However, you should configure it using the following instructions.</p>\n<p>Open an Ubuntu terminal if you don't have one open already.</p>\n<ol>\n<li><span id=\"8cfe\">You need to configure Git, so type <code class=\"language-text\">git config --global user.name \"Your Name\"</code> with replacing \"Your Name\" with your real name.</span></li>\n<li><span id=\"0e0d\">You need to configure Git, so type <code class=\"language-text\">git config --global user.email your@email.com</code> with replacing \"<a href=\"mailto:your@email.com\" class=\"markup--anchor markup--li-anchor\">your@email.com</a>\" with your real email.</span></li>\n</ol>\n<p><strong>Note: if you want git to remember your login credentials type:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git config --global credential.helper store</code></pre></div>\n<h3>Google Chrome</h3>\n<p>Test if you have Chrome installed by typing \"Chrome\" in the search box in the bottom app bar that reads \"Type here to search\". If you see a search result that reads \"Chrome\" with \"App\" under it, then you have it installed. Otherwise, follow these instructions to install Google Chrome.</p>\n<ol>\n<li><span id=\"578c\">Open Microsoft Edge, the blue \"e\" in the task bar, and type in <a href=\"<http://chrome.google.com>/\" class=\"markup--anchor markup--li-anchor\">http://chrome.google.com</a>. Click the \"Download Chrome\" button. Click the \"Accept and Install\" button after reading the terms of service. Click \"Save\" in the \"What do you want to do with ChromeSetup.exe\" dialog at the bottom of the window. When you have the option to \"Run\" it, do so. Answer the questions as you'd like. Set it as the default browser.</span></li>\n<li><span id=\"40db\">Right-click on the Chrome icon in the task bar and choose \"Pin to taskbar\".</span></li>\n</ol>\n<h3>Node.js</h3>\n<p>Test if you have Node.js installed by opening an Ubuntu terminal and typing <code class=\"language-text\">node --version</code>. If it reports \"Command 'node' not found\", then you need to follow these directions.</p>\n<ol>\n<li><span id=\"9098\">In the Ubuntu terminal, type <code class=\"language-text\">sudo apt update</code> and press Enter</span></li>\n<li><span id=\"806b\">In the Ubuntu terminal, type <code class=\"language-text\">sudo apt install build-essential</code> and press Enter</span></li>\n<li><span id=\"5f3a\">In the Ubuntu terminal, type <code class=\"language-text\">curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash</code> and press Enter</span></li>\n<li><span id=\"2abd\">In the Ubuntu terminal, type <code class=\"language-text\">. ./.bashrc</code> and press Enter</span></li>\n<li><span id=\"3c16\">In the Ubuntu terminal, type <code class=\"language-text\">nvm install --lts</code> and press Enter</span></li>\n<li><span id=\"d567\">Confirm that <strong>node</strong> is installed by typing <code class=\"language-text\">node --version</code> and seeing it print something that is not \"Command not found\"!</span></li>\n</ol>\n<h3>Unzip</h3>\n<p>You will often have to download a zip file and unzip it. It is easier to do this from the command line. So we need to install a linux unzip utility.</p>\n<p>In the Ubuntu terminal type: <code class=\"language-text\">sudo apt install unzip</code> and press Enter</p>\n<p>Mocha.js</p>\n<p>Test if you have Mocha.js installed by opening an Ubuntu terminal and typing <code class=\"language-text\">which mocha</code>. If it prints a path, then you're good. Otherwise, if it prints nothing, install Mocha.js by typing <code class=\"language-text\">npm install -g mocha</code>.</p>\n<h3>Python 3</h3>\n<p>Ubuntu does not come with Python 3. Install it using the command <code class=\"language-text\">sudo apt install python3</code>. Test it by typing <code class=\"language-text\">python3 --version</code> and seeing it print a number.</p>\n<h3>Note about WSL</h3>\n<p>As of the time of writing of this document, WSL has an issue renaming or deleting files if Visual Studio Code is open. So before doing any linux commands which manipulate files, make sure you <strong>close</strong> Visual Studio Code before running those commands in the Ubuntu terminal.</p>\n<h3>Some other common instillations</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Installing build essentials\nsudo apt-get install -y build-essential libssl-dev\n# Nodejs and NVM\ncurl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash\nsource ~/.profile\nsudo nvm install 7.10.0\nsudo nvm use 7.10.0\nnode -v\n#nodemon\nsudo npm install -g nodemon\nsudo npm install -g loopback-cli\n# Forever to run nodejs scripts forever\nsudo npm install forever -g\n# Git - a version control system\nsudo apt-get update\nsudo apt-get install -y git xclip\n# Grunt - an automated task runner\nsudo npm install -g grunt-cli\n# Bower - a dependency manager\nsudo npm install -g bower\n# Yeoman - for generators\nsudo npm install -g yo\n# maven\nsudo apt-get install maven -y\n# Gulp - an automated task runner\nsudo npm install -g gulp-cli\n# Angular FullStack - My favorite MEAN boilerplate (MEAN = MongoDB, Express, Angularjs, Nodejs)\nsudo npm install -g generator-angular-fullstack\n# Vim, Curl, Python - Some random useful stuff\nsudo apt-get install -y vim curl python-software-properties\nsudo apt-get install -y python-dev, python-pip\nsudo apt-get install -y libkrb5-dev\n# Installing JDK and JRE\nsudo apt-get install -y default-jre\nsudo apt-get install -y default-jdk\n# Archive Extractors\nsudo apt-get install -y unace unrar zip unzip p7zip-full p7zip-rar sharutils rar uudeview mpack arj cabextract file-roller\n# FileZilla - a FTP client\nsudo apt-get install -y filezilla</code></pre></div>\n<h4>If you found this guide helpful feel free to checkout my github/gists where I host similar content</h4>\n<p><a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--p-anchor\">bgoonz's gists · GitHub</a></p>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz - Overview</strong>\n<br/>\n<p><em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<p>Or Checkout my personal Resource Site:</p>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonz-blog.netlify.app/\">\n<strong>Web-Dev-Hub</strong>\n<br/>\n<p><em>Memoization, Tabulation, and Sorting Algorithms by Example Why is looking at runtime not a reliable method of…</em>bgoonz-blog.netlify.app</a>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a></p>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/9f36c3f15afe\">February 27, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/basic-web-development-environment-setup-9f36c3f15afe\" class=\"p-canonical\">Canonical link</a></p>\n<p>August 6, 2021.</p>"},{"url":"/blog/typescript-react/","relativePath":"blog/typescript-react.md","relativeDir":"blog","base":"typescript-react.md","name":"typescript-react","frontmatter":{"title":"Typescript & React","template":"post","subtitle":"Using react with typescript","excerpt":"Typescript is a superset of javascript","date":"2023-03-30T23:54:21.750Z","image":"https://tech.pelmorex.com/wp-content/uploads/2020/06/ReactTS.png","thumb_image":"https://tech.pelmorex.com/wp-content/uploads/2020/06/ReactTS.png","image_position":"right","author":"src/data/authors/bgoonz.yaml","show_author_bio":true,"related_posts":["src/pages/blog/deploy-react-app-to-heroku.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h2>React &#x26; Typescript:</h2>\n<h6><a href=\"https://github.com/bgoonz/React-Complete-Guide-Course#typescript\"></a><a href=\"https://www.typescriptlang.org/\">Typescript</a></h6>\n<p><strong>Typescript is a superset of javascript</strong></p>\n<blockquote>\n<p>Typescript adds static typing to javascript</p>\n</blockquote>\n<ul>\n<li>Javascript is a dynamically typed language, this means a javascript function does not expect a certain type for arguments to it's parameters...</li>\n<li>For Example:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">function</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>here javascript knows that 2 and 5 are of type number but it doesn't know what type a and b are... so it's up to the developer to make sure that the function is called with the correct arguments to it's parameters.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">function</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> result2 <span class=\"token operator\">=</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"2\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"5\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Here where we add the strings 2 and 5 we get the unexpected behavior of 25 because it concatenates the strings instead of adding them as numbers.</li>\n<li>Typescript can not run directly in the browser... we need to compile it to javascript first.</li>\n<li>To compile a specific typescript file without a typescript config file we can use the following command:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">npx tsc <span class=\"token operator\">&lt;</span>filename.ts<span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li>Default type assumed for a variable is <code class=\"language-text\">any</code> which means that the variable can be of any type.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token comment\">//Primatives (number, string, boolean, null, undefined, symbol)</span>\n<span class=\"token comment\">//References(Objects, Arrays, Functions)</span>\n<span class=\"token comment\">// Primatives</span>\n<span class=\"token keyword\">let</span> age<span class=\"token operator\">:</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">;</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">12</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> userName<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\nuserName <span class=\"token operator\">=</span> <span class=\"token string\">\"Bryan\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> isInstructor<span class=\"token operator\">:</span> <span class=\"token builtin\">boolean</span><span class=\"token punctuation\">;</span>\nisInstructor <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// References</span>\n<span class=\"token keyword\">let</span> hobbies<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nhobbies <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"Sports\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Cooking\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> person<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n  name<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n  age<span class=\"token operator\">:</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nperson <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  name<span class=\"token operator\">:</span> <span class=\"token string\">\"Bryan\"</span><span class=\"token punctuation\">,</span>\n  age<span class=\"token operator\">:</span> <span class=\"token number\">27</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//People is an array of objects of the person type description</span>\n<span class=\"token keyword\">let</span> people<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n  name<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n  age<span class=\"token operator\">:</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//Type Alias</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">Person</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  name<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n  age<span class=\"token operator\">:</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//this is an array of objects of the person type description</span>\n<span class=\"token keyword\">let</span> People<span class=\"token operator\">:</span> Person<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\npeople <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n  <span class=\"token punctuation\">{</span>\n    name<span class=\"token operator\">:</span> <span class=\"token string\">\"Bryan\"</span><span class=\"token punctuation\">,</span>\n    age<span class=\"token operator\">:</span> <span class=\"token number\">27</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//Type inference</span>\n<span class=\"token keyword\">let</span> course <span class=\"token operator\">=</span> <span class=\"token string\">\"React - The Complete Guide\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//course = 12345; //Error</span>\n<span class=\"token comment\">//Union Types</span>\n<span class=\"token keyword\">let</span> courseUnion<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span> <span class=\"token operator\">|</span> <span class=\"token builtin\">number</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"React - The Complete Guide\"</span><span class=\"token punctuation\">;</span>\ncourseUnion <span class=\"token operator\">=</span> <span class=\"token number\">12345</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//Union of a string or an array of strings</span>\n<span class=\"token keyword\">let</span> courseUnion2<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span> <span class=\"token operator\">|</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"React - The Complete Guide\"</span><span class=\"token punctuation\">;</span>\ncourseUnion2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"React - The Complete Guide\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Angular - The Complete Guide\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//Functions &amp; Types</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">addNumbers</span><span class=\"token punctuation\">(</span>a<span class=\"token operator\">:</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">,</span> b<span class=\"token operator\">:</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token builtin\">number</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">printOutput</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> <span class=\"token builtin\">any</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">printOutput</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//Generics</span>\n<span class=\"token keyword\">function</span> <span class=\"token generic-function\"><span class=\"token function\">insertAtBeginning</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span>array<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> newArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>array<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> newArray<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> demoArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> updatedArray <span class=\"token operator\">=</span> <span class=\"token function\">insertAtBeginning</span><span class=\"token punctuation\">(</span>demoArray<span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [-1, 1, 2, 3]</span>\n<span class=\"token keyword\">const</span> stringArray <span class=\"token operator\">=</span> <span class=\"token function\">insertAtBeginning</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"d\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ['d', 'a', 'b', 'c']</span>\n<span class=\"token comment\">//the problem with the above is that it is not type safe... the following would not throw an error</span>\n<span class=\"token comment\">//Can't use split on a number</span>\n<span class=\"token comment\">// console.log(updatedArray[0].split(\"\")); // ['-', '1']</span>\n<span class=\"token comment\">//This tells typescript that the type of the elements in the array and the value that should be added to it must be of the same type:</span>\n<span class=\"token comment\">//array: T[], value: T</span></code></pre></div>\n<p><strong>Type Infrenece</strong> <em>Typescript can infer the type of a variable based on the value assigned to it</em></p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token comment\">//Type inference</span>\n<span class=\"token keyword\">let</span> course <span class=\"token operator\">=</span> <span class=\"token string\">\"React - The Complete Guide\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//course = 12345; //Error</span></code></pre></div>\n<p><strong>Union Types</strong> <em>Typescript allows us to define a variable as a union of types</em></p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token comment\">//Union Types</span>\n<span class=\"token keyword\">let</span> courseUnion<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span> <span class=\"token operator\">|</span> <span class=\"token builtin\">number</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"React - The Complete Guide\"</span><span class=\"token punctuation\">;</span>\ncourseUnion <span class=\"token operator\">=</span> <span class=\"token number\">12345</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Generics</strong> <em>Generics allow us to create reusable components that can work with a variety of types</em></p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token comment\">//Generics</span>\n<span class=\"token keyword\">function</span> <span class=\"token generic-function\"><span class=\"token function\">insertAtBeginning</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span>array<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> newArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>array<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> newArray<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Generic Types (\"Generics\") can be tricky to wrap your head around. But indeed, we are working with them all the time - one of the most prominent examples is an array. Consider this example array:</p>\n<ol>\n<li>let numbers = [1, 2, 3]; Here, the type is inferred, but if we would assign it explicitly, we could do it like this:</li>\n<li>let numbers: number[] = [1, 2, 3]; <code class=\"language-text\">number[]</code> is the TypeScript notation for saying \"this is an array of numbers\". But actually, <code class=\"language-text\">number[]</code> is just syntactic sugar! The actual type is <code class=\"language-text\">Array</code>. ALL arrays are of the <code class=\"language-text\">Array</code> type. BUT: Since an array type really only makes sense if we also describe the type of items in the array, <code class=\"language-text\">Array</code> actually is a generic type. You could also write the above example liks this:</li>\n<li>let numbers: Array = [1, 2, 3]; Here we have the angle brackets (<code class=\"language-text\">&lt;></code>) again! But this time NOT to create our own type (as we did it in the previous lecture) but instead to tell TypeScript which actual type should be used for the \"generic type placeholder\" (<code class=\"language-text\">T</code> in the previous lecture). Just as shown in the last lecture, TypeScript would be able to infer this as well - we rely on that when we just write:</li>\n<li>let numbers = [1, 2, 3]; But if we want to explicitly set a type, we could do it like this:</li>\n<li>let numbers: Array = [1, 2, 3]; Of course it can be a bit annoying to write this rather long and clunky type, that's why we have this alternative (syntactic sugar) for arrays:</li>\n<li>let numbers: number[] = [1, 2, 3]; If we take the example from the previous lecture, we could've also set the concrete type for our placeholder <code class=\"language-text\">T</code> explicitly:</li>\n<li>const stringArray = insertAtBeginning(['a', 'b', 'c'], 'd'); So we can not just use the angle brackets to define a generic type but also to USE a generic type and explicitly set the placeholder type that should be used - sometimes this is required if TypeScript is not able to infer the (correct) type. We'll see this later in this course section! <strong>Creating a React Typescript Project</strong> <em>We can create a typescript project using the create-react-app command with the --template typescript flag</em></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">npx create-react-app my-app <span class=\"token parameter variable\">--template</span> typescript</code></pre></div>\n<h6><a href=\"https://github.com/bgoonz/React-Complete-Guide-Course#prop-types-in-react\"></a>Prop Types in React</h6>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> Todos<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">FC</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Todos<span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>React.FC</strong> is a type that is a generic type that takes in a generic type argument. This generic type argument is the type of props that the component will receive. It makes it clear that Todos is a function that is a <em>React Function Component</em> that takes in a generic type argument of type <em>object</em>. <strong>Three ways to create a data model with typescript</strong></p>\n<ul>\n<li>Interface</li>\n<li>type</li>\n<li>class <strong>using classes</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Todo</span> <span class=\"token punctuation\">{</span>\n  id<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n  text<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span>todoText<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>id <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toISOString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text <span class=\"token operator\">=</span> todoText<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Todo<span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p>In Javascript it would look like this:</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Todo</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span>todoText<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>id <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toISOString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text <span class=\"token operator\">=</span> todoText<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Todo<span class=\"token punctuation\">;</span></code></pre></div>\n<!--EndFragment-->"},{"url":"/blog/what-is-a-web-developer/","relativePath":"blog/what-is-a-web-developer.md","relativeDir":"blog","base":"what-is-a-web-developer.md","name":"what-is-a-web-developer","frontmatter":{"title":"What Is a Web Developer?","template":"post","subtitle":"A website can have anywhere from a single person to an entire team behind it, but at minimum, it needs a web developer. These people write the code that gets a website working and visible on the world wide web.","excerpt":"A website can have anywhere from a single person to an entire team behind it, but at minimum, it needs a web developer. These people write the code that gets a website working and visible on the world wide web.","date":"2022-06-06T21:37:03.789Z","image":"/blog/28b10adb-7a99-4ef1-ae2a-4a74484fc50d.jpeg","thumb_image":"/blog/28b10adb-7a99-4ef1-ae2a-4a74484fc50d.jpeg","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/html.yaml","src/data/categories/css.yaml","src/data/categories/gatsbyjs.yaml","src/data/categories/google.yaml","src/data/categories/git.yaml","src/data/categories/javascript.yaml"],"tags":["src/data/tags/links.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/accessibility.md","src/pages/blog/adding-css-to-your-html.md","src/pages/blog/beginners-guide-to-python.md","src/pages/blog/code-playgrounds-of-2021.md"],"cmseditable":true},"html":"<h2>What Is a Web Developer?</h2>\n<p>A website can have anywhere from a single person to an entire team behind it, but at minimum, it needs a <a href=\"https://kinsta.com/blog/hire-wordpress-developer/\">web developer</a>. These people write the code that gets a website working and visible on the world wide web.</p>\n<p>The primary task of a web developer is to write code, which is a set of commands and instructions written in a particular programming language. Code makes up everything in the online world, from your computer’s operating system to the backend of a website you visit.</p>\n<p>Take a look at Wikipedia’s homepage and imagine what it might take to create even such a simple website. A web developer set up the layout of this page, from the sidebar to the tables to the top bar. They had to set up scripts to take blurbs from the featured articles and request dynamic content from the site.</p>\n<p>A database stores these articles and their revisions, also set up by a developer.</p>\n<p>Wikipedia homepage</p>\n<p>It takes a ton of work, but everything comes together piece by piece to create a functional website.</p>\n<p>With the exponential rise of the internet, programmers are in high demand and have a great job outlook. Everyone wants to have their website, and web developers are here to help them make it.</p>\n<p><a href=\"https://twitter.com/intent/tweet?url=https%3A%2F%2Fkinsta.com%2Fblog%2Fhow-to-become-a-web-developer%2F&#x26;via=kinsta&#x26;text=Want+to+work+in+web+development...+but+no+idea+where+to+start%3F+%F0%9F%98%85+This+post+has+the+best+online+learning+platforms%2C+web+development+tools%2C+and+career+info+you%E2%80%99ll+need+%E2%AC%87%EF%B8%8F&#x26;hashtags=WebDev%2CTechCareers\">Want to work in web development... but no idea where to start? 😅 This post has the best online learning platforms, web development tools, and career info you’ll need ⬇️Click to Tweet</a></p>\n<h2>What Does a Web Developer Do?</h2>\n<p>Wondering what exactly your daily tasks are? Here’s the general job description for a web developer:</p>\n<ul>\n<li>Use code to create websites and prototypes</li>\n<li>Design a visually appealing layout for a website (either from scratch or with the help of a <a href=\"https://kinsta.com/blog/responsive-web-design/\">web designer</a>)</li>\n<li>Maintain active websites by <a href=\"https://kinsta.com/blog/code-review-tools/\">cleaning up code</a> and debugging errors</li>\n<li>Create a database <a href=\"https://kinsta.com/knowledgebase/what-is-mysql/\">using SQL</a></li>\n<li>Work with clients to decide on project scope and figure out the fine details of website features and design</li>\n</ul>\n<p>There are dozens of ways you can specialize, which will change your job description a fair bit. For instance, you could choose to work in frontend or backend technologies, or you could <a href=\"https://kinsta.com/blog/sysadmin/\">become a systems administrator</a> responsible for keeping servers up and running.</p>\n<p>But in general, these are the most basic tasks you’ll be responsible for.</p>\n<h2>Why Become a Web Developer?</h2>\n<p>While it may not be for everyone, web development has a shallow barrier to entry and is one of the most accessible jobs you can pick up. Despite this, it pays reasonably well, and web developers are always in demand.</p>\n<p>That’s not to say that the work isn’t often challenging, but the fundamentals are very quickly self-taught (and many developers like the challenge!).</p>\n<p>Breaking into the ever-growing tech industry is always a good choice long-term. If you’re willing and able to pursue <a href=\"https://kinsta.com/blog/scripting-languages/\">popular coding languages</a> — and in web development, there’s always a hot new language employers are scrambling to hire for — you’re almost guaranteed a steady job.</p>\n<p>Popular coding languages between 2020–21</p>\n<p>Finally, web development is a flexible job. Your career may be spent <a href=\"https://kinsta.com/blog/best-tools-for-freelancers/\">doing freelance work</a> or at a <a href=\"https://kinsta.com/developer-roles/development-at-kinsta/\">company with a salary</a>. The tasks you do and the skills or languages you focus on are up to you.</p>\n<p>You’ll need to try out programming before you can say if it’s right for you, but if you put in the work to try beginner coding and find that it makes sense, then you may make a good web developer.</p>\n<h3>Web Developer Salary and Demand</h3>\n<p>If you’re considering becoming a web developer, it’s good to know what sort of salary you can expect and how easy it will be to get a job.</p>\n<p>You can check our write-ups on <a href=\"https://kinsta.com/blog/web-developer-salary/\">the average web developer salary</a>, plus <a href=\"https://kinsta.com/blog/php-developer-salary/\">PHP developers</a> and <a href=\"https://kinsta.com/blog/wordpress-developer-salary/\">WordPress developers</a>.</p>\n<p>But the consensus is that the average developer makes $60k–75k/year.</p>\n<p>Average developer base salary in June 2021</p>\n<p>Of course, the pay will depend on your experience level, the languages and technologies you pursue, and whether you freelance or work a steady job. But it’s a reasonable estimate to start with.</p>\n<p>As for demand, the US Bureau of Labor predicts that <a href=\"https://www.bls.gov/ooh/computer-and-information-technology/web-developers.htm#tab-6\">demand for web designers and developers will grow 8%</a> from 2019–29. For reference, that’s double what most occupations on average are projected to grow.</p>\n<p>U.S. Bureau of Labor statistics on increases in employment opportunities for web developers</p>\n<p>Some web developer jobs are more competitive than others — positions like frontend developer, which are far easier to pick up, may pay less well and be more laborious to find a job for — but the outlook is still outstanding.</p>\n<h2>How Hard Is It to Become a Web Developer?</h2>\n<p>Web development is one of the most straightforward jobs to get into — if you can figure out programming. Not all jobs are for everyone, and there will be those who may struggle to wrap their heads around code.</p>\n<p>For some people, becoming a web developer will be a breeze. For others, it may never quite click with you. But for most people, a little dedication and a lot of practice will go a long way.</p>\n<p>The process of becoming a web developer is much less convoluted than other jobs, and there are <a href=\"https://kinsta.com/blog/php-vs-angular/\">more paths available</a> to get you on the right track. It’s also a much more flexible, varied job with lots of different specializations. So whatever your learning style or skills you’re suited for, there’s something for you.</p>\n<p>Mastering web development will take ongoing work and dedication, and it’s a job that offers a challenge and requires problem-solving skills. It’s easy to learn the basics, but expect to encounter frustrating yet solvable problems along the way.</p>\n<h3>Web Development Requirements</h3>\n<p>Curious about what you’ll need to become a web developer? The exact requirements depend on where you’re specializing. For instance, a backend developer should generally create and edit a database, but you cannot expect the same of a frontend developer.</p>\n<p>In addition, the programming languages and frameworks you know will distinguish you as a specific type of developer.</p>\n<p>Still, here are some skills and knowledge you’ll need, regardless of specialization, before you can call yourself a web developer:</p>\n<ul>\n<li>Proficiency in at least one web language. Depending on your position, you will likely need to learn more.</li>\n<li>Knowledge in other related skills (<a href=\"https://kinsta.com/blog/php-vs-angular/\">web frameworks</a>, libraries, <a href=\"https://kinsta.com/knowledgebase/git-vs-github/\">Git</a>, etc.).</li>\n<li>Problem-solving skills are required to work with and debug code.</li>\n<li>Attentive to details to stop bugs from happening in the first place.</li>\n<li>Communication and team skills are essential to work with other developers, clients, designers, and testers.</li>\n<li>A degree of independence and being able to problem-solve on your own.</li>\n<li>Self-motivated learning is another necessary skill for success.</li>\n<li>Familiarity with <a href=\"https://kinsta.com/blog/web-development-tools/\">popular web development tools</a> is valuable.</li>\n</ul>\n<h3>Do You Need a Degree to Become a Web Developer?</h3>\n<p>Many jobs request that applicants have an associate’s degree in computer science or a similar field. Other positions may ask for a bachelor’s degree or just certification from an online course.</p>\n<p>However, you do not strictly need a college degree to get a job. Experience and a <a href=\"https://kinsta.com/blog/portfolio-website/\">complete portfolio</a> are often far more valuable. More and more job listings are skipping out on requiring a degree and opting to ask for proof of experience.</p>\n<p>As this is a highly technical field with plenty of room for self-teaching, it’s more important that you know how to do the job than that you’re certified to do it. That said, a degree will make it simpler from the start.</p>\n<p>Self-taught developers may find difficulty landing their first job with neither experience nor a degree. You’ll likely need to fill your portfolio with self-made projects first or turn to freelance to build up some job history.</p>\n<p>If you don’t want a formal college degree, online certifications like those offered by coding bootcamps can be a suitable replacement.</p>\n<h3>Types of Web Developers</h3>\n<p>Web development is a highly specialized career. You’ll rarely find a person who describes themselves simply as a “web developer.” Depending on what you do, which part of the website you focus on, and what technologies you work with, you can choose from a wide array of job titles.</p>\n<ul>\n<li><strong>Frontend developer:</strong> A widespread choice as the skills are easy to pick up, frontend/client-side developers work on the front-facing website. Languages of choice are <a href=\"https://kinsta.com/blog/html-vs-html5/\">HTML</a>, CSS, and JavaScript. Bootstrap and jQuery are also popular technologies.</li>\n<li><strong>Backend developer:</strong> These developers work with technologies like the server and database. No backend developer is the same, as there are dozens of backend programming languages. Common choices are Java, Ruby, <a href=\"https://kinsta.com/blog/php-tutorials/\">PHP</a>, Python, and <a href=\"https://kinsta.com/knowledgebase/what-is-mysql/\">MySQL</a>.</li>\n<li><strong>Full-stack developer:</strong> A combination of frontend and backend developers. They know enough languages to get by on the server and client sides.</li>\n</ul>\n<p>These are the main three, but you can specialize further by becoming a web engineer, security expert, <a href=\"https://kinsta.com/blog/wordpress-developer-salary/\">WordPress developer</a>, mobile web developer, web application developer, and more.</p>\n<h2>Steps to Becoming a Web Developer</h2>\n<p>You can take various paths to become a web developer, and your own experience will present unique challenges. But generally, most web development careers follow a similar form.</p>\n<p>First, you need to choose how you’ll learn development. Will you be going to college? What sort of degree are you pursuing? An associate’s or bachelor’s degree related in some way to computer science is best.</p>\n<p>If you’re not going to college, will you try to get certified? Certification or not, will you take a paid or free online course? Or are you going all-in to teach yourself using <a href=\"https://kinsta.com/blog/php-tutorials/\">only online resources</a>?</p>\n<p>After you’ve decided that, you’ll need to pick a specialization (frontend, backend, full-stack, etc.). You can put this off as you experiment with different aspects of web development, but you need to choose before pursuing a narrowed study.</p>\n<p>Next, is what <a href=\"https://kinsta.com/blog/best-programming-language-to-learn/\">programming languages</a> and technologies do you want to learn?</p>\n<p>All this may come in a different order. You may choose to specialize or go in already knowing what languages you want to learn and then select a course accordingly.</p>\n<h3>Want to know how we increased our traffic over 1000%?</h3>\n<p>Join 20,000+ others who get our weekly newsletter with insider WordPress tips!</p>\n<p><a href=\"https://kinsta.com/blog/how-to-become-a-web-developer/#newsletter\">Subscribe Now</a></p>\n<p>After you’ve picked up some web development skills, you’ll need to get some projects under your belt for your portfolio. Hands-on experience will also give you a better idea of what to expect in a real job. <a href=\"https://kinsta.com/knowledgebase/mysql-community-server/\">Set up your first server</a> and <a href=\"https://kinsta.com/blog/responsive-web-design/\">design a website</a> for yourself. A few small projects will set you on the right track.</p>\n<p>With the knowledge you need and a <a href=\"https://kinsta.com/blog/wordpress-portfolio-plugins/\">great starting portfolio</a>, you’ll be ready for your first job.</p>\n<h2>The Best Web Development Learning Resources</h2>\n<p>Ready to try web development for yourself? We’ve collected over a dozen great resources to get you started. If you’re choosing to teach yourself or learn online, this is the place to start. And for those going to college, they’re great supplements to your courses.</p>\n<h3>1. StackOverflow</h3>\n<p>StackOverflow</p>\n<p>The first rule of being a developer is to use <a href=\"https://stackoverflow.com/\">StackOverflow</a>. Every developer knows that this is the place to turn to when you’re stuck on a project. Your question has likely been asked and answered. If not, the <a href=\"https://kinsta.com/learn/wordpress-communities/\">community</a> of experienced professionals is eager to help.</p>\n<p>While this isn’t strictly a beginner’s learning resource, it will be there for you every step of the way.</p>\n<h3>2. W3Schools</h3>\n<p>W3Schools</p>\n<p><a href=\"https://www.w3schools.com/\">W3Schools</a> is an excellent beginner’s resource that will walk you through the fundamentals of various web languages and standards. It’s super easy to understand, even if you’re not used to coding.</p>\n<h3>3. Codecademy</h3>\n<p>Codecademy</p>\n<p>If you need a beginner-friendly course that offers over a dozen languages and technologies, <a href=\"https://www.codecademy.com/\">Codecademy</a> is the place to turn. Better yet, the bulk of the content is free. While there are premium features, the courses themselves are fully available for free.</p>\n<h3>4. Udemy</h3>\n<p>Udemy</p>\n<p>Need some more advanced courses, or ones in more specific skills? <a href=\"https://www.udemy.com/\">Udemy</a> might be the right site for you. There are thousands of courses made by professional instructors, and some even allow you to become accredited.</p>\n<h3>5. GitHub Learning Lab</h3>\n<p>GitHub Learning Lab</p>\n<p><a href=\"https://kinsta.com/knowledgebase/git/\">Git</a> can be very difficult to understand if you have no prior technical skills. It’s easy once you get the hang of it, but crossing that first hurdle can be tricky. <a href=\"https://lab.github.com/\">GitHub Learning Lab</a> walks you through it with a simple, fun, and interactive tutorial.</p>\n<h3>6. DevKinsta</h3>\n<p>DevKinsta</p>\n<p>Interested in <a href=\"https://kinsta.com/blog/learn-wordpress/\">learning WordPress development</a>? Make <a href=\"https://kinsta.com/devkinsta/\">DevKinsta</a> your first stop. It’s a free development suite that makes starting up a local WordPress server painless. Use it for testing and development and push the final result right to a Kinsta server.</p>\n<h3>7. FreeCodeCamp</h3>\n<p>FreeCodeCamp</p>\n<p>Want to learn to code and get certified while doing it? Unlike Codecademy, <a href=\"https://www.freecodecamp.org/\">FreeCodeCamp</a> is 100% free due to it being a nonprofit. Each certification path is estimated to take around 300 hours, and you can choose from a variety of different skills to learn.</p>\n<h3>8. DevDocs</h3>\n<p>DevDocs</p>\n<p>Any developer knows that finding documentation for dozens of different tools can be annoying. <a href=\"https://devdocs.io/\">DevDocs</a> is a free and open source tool that combines all this documentation into a single, easy-to-navigate app.</p>\n<h3>9. Team Treehouse</h3>\n<p>Team Treehouse</p>\n<p><a href=\"https://teamtreehouse.com/\">Treehouse</a> is a helpful beginner’s resource that aims to teach you web development and other fundamentals from scratch. The video-based learning platform also includes interactive challenges. Though a premium service, it’s an excellent starting point for developers.</p>\n<h3>10. Coursera</h3>\n<p>Coursera</p>\n<p><a href=\"https://www.coursera.org/\">Coursera</a> has one unique advantage unlike other <a href=\"https://kinsta.com/blog/wordpress-lms-plugins/\">learning platforms</a>: You can use it to earn both certification and full college degrees from technical universities. It can be cheaper than enrolling in college, but you’ll learn nearly the same content and work with the same professors as university students.</p>\n<p>As Coursera offers accredited and nonaccredited courses, make sure you know what you’re getting into if you’re aiming for a legitimate college degree.</p>\n<h3>11. Egghead.io</h3>\n<p>Egghead.io</p>\n<p><a href=\"https://egghead.io/\">Egghead</a> contains helpful, bite-sized lessons on a variety of development subjects. There are several dozen topics to choose from, each with even more articles covering every development aspect you can imagine. You can also find courses offered by professional instructors.</p>\n<h3>12. CSS-Tricks</h3>\n<p>CSS-Tricks</p>\n<p>While not a series of courses, <a href=\"https://css-tricks.com/\">CSS-Tricks</a> offers high-quality articles on frontend web development. If you want to <a href=\"https://kinsta.com/blog/javascript-libraries/\">master Javascript</a> or CSS, there’s plenty of reading material and how-to articles here.</p>\n<h3>13. Udacity</h3>\n<p>Udacity</p>\n<p><a href=\"https://www.udacity.com/\">Udacity</a> is a tech-focused provider of paid online courses. Along with web development, you can take highly specialized classes, such as <a href=\"https://kinsta.com/blog/cloud-security/\">cybersecurity</a>, data science, business, and more.</p>\n<h3>14. Coding Bootcamp Programs</h3>\n<p>If you learn best through intense programs full of crunching, you may want to turn to coding bootcamps. You can find them at all levels — there are even coding bootcamps for beginners that will teach you the ropes, as well as programs for professionals that’ll keep you on your toes.</p>\n<p>While colleges or other classes often offer them, you can also do online bootcamps. Some of them are paid courses, and some are free. It all depends on which you choose.</p>\n<p>This way of learning is a lot more stressful, but it can certainly be motivating if you’re struggling with code.</p>\n<p>There are plenty of coding bootcamps online, but you can start by looking into <a href=\"https://www.hackreactor.com/online-coding-bootcamp\">HackReactor</a>, <a href=\"https://www.fullstackacademy.com/online-coding-bootcamp\">Fullstack Academy</a>, and <a href=\"https://codesmith.io/\">CodeSmith</a>.</p>"},{"url":"/blog/what-is-a-redux-reducer/","relativePath":"blog/what-is-a-redux-reducer.md","relativeDir":"blog","base":"what-is-a-redux-reducer.md","name":"what-is-a-redux-reducer","frontmatter":{"title":"What is a Redux Reducer?","template":"post","subtitle":"A reducer is a function that determines changes to an applications state","excerpt":"A reducer is a function that determines changes to an applications state","date":"2022-05-16T06:08:24.979Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redux.gif?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redux.gif?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/react.yaml"],"tags":["src/data/tags/links.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/10-essential-react-interview-questions.md","src/pages/blog/react-semantics.md","src/pages/blog/react-state.md","src/pages/blog/using-the-dom.md"],"cmseditable":true},"html":"<h1>What is a Redux Reducer?</h1>\n<p><strong>This tutorial will teach you \"how Redux works\"</strong>, as well as <em>why</em> these patterns exist. Fair warning though - learning the concepts is different from putting them into practice in actual apps.</p>\n<p><strong>The initial code will be less concise than the way we suggest writing real app code</strong>, but writing it out long-hand is the best way to learn. Once you understand how everything fits together, we'll look at using Redux Toolkit to simplify things. <strong>Redux Toolkit is the recommended way to build production apps with Redux</strong>, and is built on all of the concepts that we will look at throughout this tutorial. Once you understand the core concepts covered here, you'll understand how to use Redux Toolkit more efficiently.</p>\n<p>:::info</p>\n<p>If you're looking to learn more about how Redux is used to write real-world applications, please see:</p>\n<ul>\n<li><a href=\"./part-8-modern-redux.md\"><strong>The \"Modern Redux\" page in this tutorial</strong></a>, which shows how to convert the low-level examples from earlier sections into the modern patterns we do recommend for real-world usage</li>\n<li><a href=\"../essentials/part-1-overview-concepts.md\"><strong>The \"Redux Essentials\" tutorial</strong></a>, which teaches \"how to use Redux, the right way\" for real-world apps, using our latest recommended patterns and practices.</li>\n</ul>\n<p>:::</p>\n<p>We've tried to keep these explanations beginner-friendly, but we do need to make some assumptions about what you know already so that we can focus on explaining Redux itself. <strong>This tutorial assumes that you know</strong>:</p>\n<p>:::important Prerequisites</p>\n<ul>\n<li>Familiarity with <a href=\"https://internetingishard.com/\">HTML &#x26; CSS</a>.</li>\n<li>Familiarity with <a href=\"https://www.taniarascia.com/es6-syntax-and-feature-overview/\">ES6 syntax and features</a></li>\n<li>Understanding of <a href=\"https://javascript.info/rest-parameters-spread#spread-syntax\">the array and object spread operators</a></li>\n<li>Knowledge of React terminology: <a href=\"https://reactjs.org/docs/introducing-jsx.html\">JSX</a>, <a href=\"https://reactjs.org/docs/state-and-lifecycle.html\">State</a>, <a href=\"https://reactjs.org/docs/components-and-props.html\">Function Components, Props</a>, and <a href=\"https://reactjs.org/docs/hooks-intro.html\">Hooks</a></li>\n<li>Knowledge of <a href=\"https://javascript.info/promise-basics\">asynchronous JavaScript</a> and <a href=\"https://javascript.info/fetch\">making AJAX requests</a></li>\n</ul>\n<p>:::</p>\n<p><strong>If you're not already comfortable with those topics, we encourage you to take some time to become comfortable with them first, and then come back to learn about Redux</strong>. We'll be here when you're ready!</p>\n<p>Finally, you should make sure that you have the React and Redux DevTools extensions installed in your browser:</p>\n<ul>\n<li>\n<p>React DevTools Extension:</p>\n<ul>\n<li><a href=\"https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en\">React DevTools Extension for Chrome</a></li>\n<li><a href=\"https://addons.mozilla.org/en-US/firefox/addon/react-devtools/\">React DevTools Extension for Firefox</a></li>\n</ul>\n</li>\n<li>\n<p>Redux DevTools Extension:</p>\n<ul>\n<li><a href=\"https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en\">Redux DevTools Extension for Chrome</a></li>\n<li><a href=\"https://addons.mozilla.org/en-US/firefox/addon/reduxdevtools/\">Redux DevTools Extension for Firefox</a></li>\n</ul>\n</li>\n</ul>\n<h2>What is Redux?</h2>\n<p>It helps to understand what this \"Redux\" thing is in the first place. What does it do? What problems does it help me solve? Why would I want to use it?</p>\n<p><strong>Redux is a pattern and library for managing and updating application state, using events called \"actions\".</strong> It serves as a centralized store for state that needs to be used across your entire application, with rules ensuring that the state can only be updated in a predictable fashion.</p>\n<h3>Why Should I Use Redux?</h3>\n<p>Redux helps you manage \"global\" state - state that is needed across many parts of your application.</p>\n<p><strong>The patterns and tools provided by Redux make it easier to understand when, where, why, and how the state in your application is being updated, and how your application logic will behave when those changes occur</strong>. Redux guides you towards writing code that is predictable and testable, which helps give you confidence that your application will work as expected.</p>\n<h3>When Should I Use Redux?</h3>\n<p>Redux helps you deal with shared state management, but like any tool, it has tradeoffs. There are more concepts to learn, and more code to write. It also adds some indirection to your code, and asks you to follow certain restrictions. It's a trade-off between short term and long term productivity.</p>\n<p>Redux is more useful when:</p>\n<ul>\n<li>You have large amounts of application state that are needed in many places in the app</li>\n<li>The app state is updated frequently over time</li>\n<li>The logic to update that state may be complex</li>\n<li>The app has a medium or large-sized codebase, and might be worked on by many people</li>\n</ul>\n<p><strong>Not all apps need Redux. Take some time to think about the kind of app you're building, and decide what tools would be best to help solve the problems you're working on.</strong></p>\n<p>:::info Want to Know More?</p>\n<p>If you're not sure whether Redux is a good choice for your app, these resources give some more guidance:</p>\n<ul>\n<li><strong><a href=\"https://changelog.com/posts/when-and-when-not-to-reach-for-redux\">When (and when not) to reach for Redux</a></strong></li>\n<li><strong><a href=\"https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1/\">The Tao of Redux, Part 1 - Implementation and Intent</a></strong></li>\n<li><strong><a href=\"../../faq/General.md#when-should-i-use-redux\">Redux FAQ: When should I use Redux?</a></strong></li>\n<li><strong><a href=\"https://medium.com/@dan_abramov/you-might-not-need-redux-be46360cf367\">You Might Not Need Redux</a></strong></li>\n</ul>\n<p>:::</p>\n<h3>Redux Libraries and Tools</h3>\n<p>Redux is a small standalone JS library. However, it is commonly used with several other packages:</p>\n<h4>React-Redux</h4>\n<p>Redux can integrate with any UI framework, and is most frequently used with React. <a href=\"https://react-redux.js.org/\"><strong>React-Redux</strong></a> is our official package that lets your React components interact with a Redux store by reading pieces of state and dispatching actions to update the store.</p>\n<h4>Redux Toolkit</h4>\n<p><a href=\"https://redux-toolkit.js.org\"><strong>Redux Toolkit</strong></a> is our recommended approach for writing Redux logic. It contains packages and functions that we think are essential for building a Redux app. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications.</p>\n<h4>Redux DevTools Extension</h4>\n<p>The <a href=\"https://github.com/reduxjs/redux-devtools/tree/main/extension\"><strong>Redux DevTools Extension</strong></a> shows a history of the changes to the state in your Redux store over time. This allows you to debug your applications effectively, including using powerful techniques like \"time-travel debugging\".</p>\n<h2>Redux Basics</h2>\n<p>Now that you know what Redux is, let's briefly look at the pieces that make up a Redux app and how it works.</p>\n<p>:::info</p>\n<p>The rest of the description on this page focuses solely on the Redux core library (the <code class=\"language-text\">redux</code> package). We'll talk about the other Redux-related packages as we go through the rest of the tutorial.</p>\n<p>:::</p>\n<h3>The Redux Store</h3>\n<p>The center of every Redux application is the <strong>store</strong>. A \"store\" is a container that holds your application's global <strong>state</strong>.</p>\n<p>A store is a JavaScript object with a few special functions and abilities that make it different than a plain global object:</p>\n<ul>\n<li>You must never directly modify or change the state that is kept inside the Redux store</li>\n<li>Instead, the only way to cause an update to the state is to create a plain <strong>action</strong> object that describes \"something that happened in the application\", and then <strong>dispatch</strong> the action to the store to tell it what happened.</li>\n<li>When an action is dispatched, the store runs the root <strong>reducer</strong> function, and lets it calculate the new state based on the old state and the action</li>\n<li>Finally, the store notifies <strong>subscribers</strong> that the state has been updated so the UI can be updated with the new data.</li>\n</ul>\n<h3>Redux Core Example App</h3>\n<p>Let's look at a minimal working example of a Redux app - a small counter application:</p>\n<iframe\n  class=\"codesandbox\"\n  src=\"https://codesandbox.io/embed/dank-architecture-lr7k1?fontsize=14&hidenavigation=1&theme=dark&runonclick=1\"\n  title=\"redux-fundamentals-core-example\"\n  allow=\"geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb\"\n  sandbox=\"allow-modals allow-forms allow-popups allow-scripts allow-same-origin\"\n>\n</iframe>\n<br>\n<p>Because Redux is a standalone JS library with no dependencies, this example is written by only loading a single script tag for the Redux library, and uses basic JS and HTML for the UI. In practice, Redux is normally used by <a href=\"../../introduction/Installation.md\">installing the Redux packages from NPM</a>, and the UI is created using a library like <a href=\"https://reactjs.org\">React</a>.</p>\n<p>:::info</p>\n<p><a href=\"./part-5-ui-and-react.md\">Part 5: UI and React</a> shows how to use Redux and React together.</p>\n<p>:::</p>\n<p>Let's break this example down into its separate parts to see what's happening.</p>\n<h4>State, Actions, and Reducers</h4>\n<p>We start by defining an initial <strong>state</strong> value to describe the application:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Define an initial state value for the app</span>\n<span class=\"token keyword\">const</span> initialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>For this app, we're going to track a single number with the current value of our counter.</p>\n<p>Redux apps normally have a JS object as the root piece of the state, with other values inside that object.</p>\n<p>Then, we define a <strong>reducer</strong> function. The reducer receives two arguments, the current <code class=\"language-text\">state</code> and an\n<code class=\"language-text\">action</code> object describing what happened. When the Redux app starts up, we don't have any state yet,\nso we provide the <code class=\"language-text\">initialState</code> as the default value for this reducer:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Create a \"reducer\" function that determines what the new state</span>\n<span class=\"token comment\">// should be when something happens in the app</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">counterReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Reducers usually look at the type of action that happened</span>\n    <span class=\"token comment\">// to decide how to update the state</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">case</span> <span class=\"token string\">'counter/incremented'</span><span class=\"token operator\">:</span>\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> state<span class=\"token punctuation\">.</span>value <span class=\"token operator\">+</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">case</span> <span class=\"token string\">'counter/decremented'</span><span class=\"token operator\">:</span>\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> state<span class=\"token punctuation\">.</span>value <span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n            <span class=\"token comment\">// If the reducer doesn't care about this action type,</span>\n            <span class=\"token comment\">// return the existing state unchanged</span>\n            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Action objects always have a <code class=\"language-text\">type</code> field, which is a string you provide that\nacts as a unique name for the action. The <code class=\"language-text\">type</code> should be a readable name so that\nanyone who looks at this code understands what it means. In this case, we use the\nword 'counter' as the first half of our action type, and the second half is a\ndescription of \"what happened\". In this case, our 'counter' was 'incremented', so\nwe write the action type as <code class=\"language-text\">'counter/incremented'</code>.</p>\n<p>Based on the type of the action, we either need to return a brand-new object to\nbe the new <code class=\"language-text\">state</code> result, or return the existing <code class=\"language-text\">state</code> object if nothing should change.\nNote that we update the state <em>immutably</em> by copying the existing state and updating the\ncopy, instead of modifying the original object directly.</p>\n<h4>Store</h4>\n<p>Now that we have a reducer function, we can create a <strong>store</strong> instance by\ncalling the Redux library <code class=\"language-text\">createStore</code> API.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Create a new Redux store with the `createStore` function,</span>\n<span class=\"token comment\">// and use the `counterReducer` for the update logic</span>\n<span class=\"token keyword\">const</span> store <span class=\"token operator\">=</span> Redux<span class=\"token punctuation\">.</span><span class=\"token function\">createStore</span><span class=\"token punctuation\">(</span>counterReducer<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We pass the reducer function to <code class=\"language-text\">createStore</code>, which uses the reducer function\nto generate the initial state, and to calculate any future updates.</p>\n<h4>UI</h4>\n<p>In any application, the user interface will show existing state on screen. When a user\ndoes something, the app will update its data and then redraw the UI with those values.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Our \"user interface\" is some text in a single HTML element</span>\n<span class=\"token keyword\">const</span> valueEl <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'value'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Whenever the store state changes, update the UI by</span>\n<span class=\"token comment\">// reading the latest store state and showing new data</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> state <span class=\"token operator\">=</span> store<span class=\"token punctuation\">.</span><span class=\"token function\">getState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    valueEl<span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> state<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Update the UI with the initial data</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// And subscribe to redraw whenever the data changes in the future</span>\nstore<span class=\"token punctuation\">.</span><span class=\"token function\">subscribe</span><span class=\"token punctuation\">(</span>render<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In this small example, we're only using some basic HTML elements as our UI,\nwith a single <code class=\"language-text\">&lt;div></code> showing the current value.</p>\n<p>So, we write a function that knows how to get the latest state from the Redux\nstore using the <code class=\"language-text\">store.getState()</code> method, then takes that value and updates the UI to show it.</p>\n<p>The Redux store lets us call <code class=\"language-text\">store.subscribe()</code> and pass a subscriber callback function that will be called\nevery time the store is updated. So, we can pass our <code class=\"language-text\">render</code> function as the subscriber, and know that\neach time the store updates, we can update the UI with the latest value.</p>\n<p>Redux itself is a standalone library that can be used anywhere. This also means that it can be used with any UI layer.</p>\n<h4>Dispatching Actions</h4>\n<p>Finally, we need to respond to user input by creating <strong>action</strong> objects that\ndescribe what happened, and <strong>dispatching</strong> them to the store. When we call <code class=\"language-text\">store.dispatch(action)</code>,\nthe store runs the reducer, calculates the updated state, and runs the subscribers\nto update the UI.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Handle user inputs by \"dispatching\" action objects,</span>\n<span class=\"token comment\">// which should describe \"what happened\" in the app</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'increment'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    store<span class=\"token punctuation\">.</span><span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'counter/incremented'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'decrement'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    store<span class=\"token punctuation\">.</span><span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'counter/decremented'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'incrementIfOdd'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// We can write logic to decide what to do based on the state</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>store<span class=\"token punctuation\">.</span><span class=\"token function\">getState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">!==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        store<span class=\"token punctuation\">.</span><span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'counter/incremented'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'incrementAsync'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// We can also write async logic that interacts with the store</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        store<span class=\"token punctuation\">.</span><span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'counter/incremented'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here, we'll dispatch the actions that will make the reducer add 1 or\nsubtract 1 from the current counter value.</p>\n<p>We can also write code that only dispatches an action if a certain\ncondition is true, or write some async code that dispatches an action\nafter a delay.</p>\n<h3>Data Flow</h3>\n<p>We can summarize the flow of data through a Redux app with this diagram. It represents how:</p>\n<ul>\n<li>actions are dispatched in response to a user interaction like a click</li>\n<li>the store runs the reducer function to calculate a new state</li>\n<li>the UI reads the new state to display the new values</li>\n</ul>\n<p>(Don't worry if these pieces aren't quite clear yet! Keep this picture in your mind as you go through the rest of this tutorial, and you'll see how the pieces fit together.)</p>\n<p><img src=\"/img/tutorials/essentials/ReduxDataFlowDiagram.gif\" alt=\"Redux data flow diagram\"></p>\n<h2>What You've Learned</h2>\n<p>That counter example was small, but it does show all the working pieces of a real Redux app.\n<strong>Everything we'll talk about in the following sections expands on those basic pieces.</strong></p>\n<p>With that in mind, let's review what we've learned so far:</p>\n<p>:::tip Summary</p>\n<ul>\n<li>\n<p><strong>Redux is a library for managing global application state</strong></p>\n<ul>\n<li>Redux is typically used with the React-Redux library for integrating Redux and React together</li>\n<li>Redux Toolkit is the recommended way to write Redux logic</li>\n</ul>\n</li>\n<li>\n<p><strong>Redux uses several types of code</strong></p>\n<ul>\n<li><em>Actions</em> are plain objects with a <code class=\"language-text\">type</code> field, and describe \"what happened\" in the app</li>\n<li><em>Reducers</em> are functions that calculate a new state value based on previous state + an action</li>\n<li>A Redux <em>store</em> runs the root reducer whenever an action is <em>dispatched</em></li>\n</ul>\n</li>\n</ul>\n<h3>State Management</h3>\n<p>Let's start by looking at a small React counter component. It tracks a number in component state, and increments the number when a button is clicked:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Counter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// State: a counter value</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>counter<span class=\"token punctuation\">,</span> setCounter<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Action: code that causes an update to the state when something happens</span>\n    <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">increment</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">setCounter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">prevCounter</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> prevCounter <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// View: the UI definition</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token literal-property property\">Value</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>counter<span class=\"token punctuation\">}</span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>increment<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Increment<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>It is a self-contained app with the following parts:</p>\n<ul>\n<li>The <strong>state</strong>, the source of truth that drives our app;</li>\n<li>The <strong>view</strong>, a declarative description of the UI based on the current state</li>\n<li>The <strong>actions</strong>, the events that occur in the app based on user input, and trigger updates in the state</li>\n</ul>\n<p>This is a small example of <strong>\"one-way data flow\"</strong>:</p>\n<ul>\n<li>State describes the condition of the app at a specific point in time</li>\n<li>The UI is rendered based on that state</li>\n<li>When something happens (such as a user clicking a button), the state is updated based on what occurred</li>\n<li>The UI re-renders based on the new state</li>\n</ul>\n<p><img src=\"/img/tutorials/essentials/one-way-data-flow.png\" alt=\"One-way data flow\"></p>\n<p>However, the simplicity can break down when we have <strong>multiple components that need to share and use the same state</strong>, especially if those components are located in different parts of the application. Sometimes this can be solved by <a href=\"https://reactjs.org/docs/lifting-state-up.html\">\"lifting state up\"</a> to parent components, but that doesn't always help.</p>\n<p>One way to solve this is to extract the shared state from the components, and put it into a centralized location outside the component tree. With this, our component tree becomes a big \"view\", and any component can access the state or trigger actions, no matter where they are in the tree!</p>\n<p>By defining and separating the concepts involved in state management and enforcing rules that maintain independence between views and states, we give our code more structure and maintainability.</p>\n<p>This is the basic idea behind Redux: a single centralized place to contain the global state in your application, and specific patterns to follow when updating that state to make the code predictable.</p>\n<h3>Immutability</h3>\n<p>\"Mutable\" means \"changeable\". If something is \"immutable\", it can never be changed.</p>\n<p>JavaScript objects and arrays are all mutable by default. If I create an object, I can change the contents of its fields. If I create an array, I can change the contents as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// still the same object outside, but the contents have changed</span>\nobj<span class=\"token punctuation\">.</span>b <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// In the same way, we can change the contents of this array</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\narr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is called <em>mutating</em> the object or array. It's the same object or array reference in memory, but now the contents inside the object have changed.</p>\n<p><strong>In order to update values immutably, your code must make <em>copies</em> of existing objects/arrays, and then modify the copies</strong>.</p>\n<p>We can do this by hand using JavaScript's array / object spread operators, as well as array methods that return new copies of the array instead of mutating the original array:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// To safely update obj.a.c, we have to copy each piece</span>\n        <span class=\"token literal-property property\">c</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> obj2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// copy obj</span>\n    <span class=\"token operator\">...</span>obj<span class=\"token punctuation\">,</span>\n    <span class=\"token comment\">// overwrite a</span>\n    <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// copy obj.a</span>\n        <span class=\"token operator\">...</span>obj<span class=\"token punctuation\">.</span>a<span class=\"token punctuation\">,</span>\n        <span class=\"token comment\">// overwrite c</span>\n        <span class=\"token literal-property property\">c</span><span class=\"token operator\">:</span> <span class=\"token number\">42</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Create a new copy of arr, with \"c\" appended to the end</span>\n<span class=\"token keyword\">const</span> arr2 <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// or, we can make a copy of the original array:</span>\n<span class=\"token keyword\">const</span> arr3 <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// and mutate the copy:</span>\narr3<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Redux expects that all state updates are done immutably</strong>. We'll look at where and how this is important a bit later, as well as some easier ways to write immutable update logic.</p>\n<p>:::info Want to Know More?</p>\n<p>For more info on how immutability works in JavaScript, see:</p>\n<ul>\n<li><a href=\"https://daveceddia.com/javascript-references/\">A Visual Guide to References in JavaScript</a></li>\n<li><a href=\"https://daveceddia.com/react-redux-immutability-guide/\">Immutability in React and Redux: The Complete Guide</a></li>\n</ul>\n<p>:::</p>\n<h2>Redux Terminology</h2>\n<p>There's some important Redux terms that you'll need to be familiar with before we continue:</p>\n<h3>Actions</h3>\n<p>An <strong>action</strong> is a plain JavaScript object that has a <code class=\"language-text\">type</code> field. <strong>You can think of an action as an event that describes something that happened in the application</strong>.</p>\n<p>The <code class=\"language-text\">type</code> field should be a string that gives this action a descriptive name, like <code class=\"language-text\">\"todos/todoAdded\"</code>. We usually write that type string like <code class=\"language-text\">\"domain/eventName\"</code>, where the first part is the feature or category that this action belongs to, and the second part is the specific thing that happened.</p>\n<p>An action object can have other fields with additional information about what happened. By convention, we put that information in a field called <code class=\"language-text\">payload</code>.</p>\n<p>A typical action object might look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> addTodoAction <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'todos/todoAdded'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">payload</span><span class=\"token operator\">:</span> <span class=\"token string\">'Buy milk'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Reducers</h3>\n<p>A <strong>reducer</strong> is a function that receives the current <code class=\"language-text\">state</code> and an <code class=\"language-text\">action</code> object, decides how to update the state if necessary, and returns the new state: <code class=\"language-text\">(state, action) => newState</code>. <strong>You can think of a reducer as an event listener which handles events based on the received action (event) type.</strong></p>\n<p>:::info</p>\n<p>\"Reducer\" functions get their name because they're similar to the kind of callback function you pass to the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce\"><code class=\"language-text\">Array.reduce()</code></a> method.</p>\n<p>:::</p>\n<p>Reducers must <em>always</em> follow some specific rules:</p>\n<ul>\n<li>They should only calculate the new state value based on the <code class=\"language-text\">state</code> and <code class=\"language-text\">action</code> arguments</li>\n<li>They are not allowed to modify the existing <code class=\"language-text\">state</code>. Instead, they must make <em>immutable updates</em>, by copying the existing <code class=\"language-text\">state</code> and making changes to the copied values.</li>\n<li>They must not do any asynchronous logic, calculate random values, or cause other \"side effects\"</li>\n</ul>\n<p>We'll talk more about the rules of reducers later, including why they're important and how to follow them correctly.</p>\n<p>The logic inside reducer functions typically follows the same series of steps:</p>\n<ul>\n<li>\n<p>Check to see if the reducer cares about this action</p>\n<ul>\n<li>If so, make a copy of the state, update the copy with new values, and return it</li>\n</ul>\n</li>\n<li>Otherwise, return the existing state unchanged</li>\n</ul>\n<p>Here's a small example of a reducer, showing the steps that each reducer should follow:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> initialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">counterReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Check to see if the reducer cares about this action</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type <span class=\"token operator\">===</span> <span class=\"token string\">'counter/incremented'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// If so, make a copy of `state`</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span>\n            <span class=\"token comment\">// and update the copy with the new value</span>\n            <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> state<span class=\"token punctuation\">.</span>value <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">// otherwise return the existing state unchanged</span>\n    <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Reducers can use any kind of logic inside to decide what the new state should be: <code class=\"language-text\">if/else</code>, <code class=\"language-text\">switch</code>, loops, and so on.</p>\n<DetailedExplanation title=\"Detailed Explanation: Why Are They Called 'Reducers?'\" >\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce\"><code class=\"language-text\">Array.reduce()</code></a> method lets you take an array of values, process each item in the array one at a time, and return a single final result. You can think of it as \"reducing the array down to one value\".</p>\n<p><code class=\"language-text\">Array.reduce()</code> takes a callback function as an argument, which will be called one time for each item in the array. It takes two arguments:</p>\n<ul>\n<li><code class=\"language-text\">previousResult</code>, the value that your callback returned last time</li>\n<li><code class=\"language-text\">currentItem</code>, the current item in the array</li>\n</ul>\n<p>The first time that the callback runs, there isn't a <code class=\"language-text\">previousResult</code> available, so we need to also pass in an initial value that will be used as the first <code class=\"language-text\">previousResult</code>.</p>\n<p>If we wanted to add together an array of numbers to find out what the total is, we could write a reduce callback that looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">addNumbers</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">previousResult<span class=\"token punctuation\">,</span> currentItem</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> previousResult<span class=\"token punctuation\">,</span> currentItem <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> previousResult <span class=\"token operator\">+</span> currentItem<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> initialValue <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> total <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span>addNumbers<span class=\"token punctuation\">,</span> initialValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// {previousResult: 0, currentItem: 2}</span>\n<span class=\"token comment\">// {previousResult: 2, currentItem: 5}</span>\n<span class=\"token comment\">// {previousResult: 7, currentItem: 8}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>total<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 15</span></code></pre></div>\n<p>Notice that this <code class=\"language-text\">addNumbers</code> \"reduce callback\" function doesn't need to keep track of anything itself. It takes the <code class=\"language-text\">previousResult</code> and <code class=\"language-text\">currentItem</code> arguments, does something with them, and returns a new result value.</p>\n<p><strong>A Redux reducer function is exactly the same idea as this \"reduce callback\" function!</strong> It takes a \"previous result\" (the <code class=\"language-text\">state</code>), and the \"current item\" (the <code class=\"language-text\">action</code> object), decides a new state value based on those arguments, and returns that new state.</p>\n<p>If we were to create an array of Redux actions, call <code class=\"language-text\">reduce()</code>, and pass in a reducer function, we'd get a final result the same way:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> actions <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'counter/incremented'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'counter/incremented'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'counter/incremented'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> initialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> finalResult <span class=\"token operator\">=</span> actions<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span>counterReducer<span class=\"token punctuation\">,</span> initialState<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>finalResult<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// {value: 3}</span></code></pre></div>\n<p>We can say that <strong>Redux reducers reduce a set of actions (over time) into a single state</strong>. The difference is that with <code class=\"language-text\">Array.reduce()</code> it happens all at once, and with Redux, it happens over the lifetime of your running app.</p>\n</DetailedExplanation>\n<h3>Store</h3>\n<p>The current Redux application state lives in an object called the <strong>store</strong> .</p>\n<p>The store is created by passing in a reducer, and has a method called <code class=\"language-text\">getState</code> that returns the current state value:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> configureStore <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@reduxjs/toolkit'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> store <span class=\"token operator\">=</span> <span class=\"token function\">configureStore</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">reducer</span><span class=\"token operator\">:</span> counterReducer <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>store<span class=\"token punctuation\">.</span><span class=\"token function\">getState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// {value: 0}</span></code></pre></div>\n<h3>Dispatch</h3>\n<p>The Redux store has a method called <code class=\"language-text\">dispatch</code>. <strong>The only way to update the state is to call <code class=\"language-text\">store.dispatch()</code> and pass in an action object</strong>. The store will run its reducer function and save the new state value inside, and we can call <code class=\"language-text\">getState()</code> to retrieve the updated value:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nstore<span class=\"token punctuation\">.</span><span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'counter/incremented'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>store<span class=\"token punctuation\">.</span><span class=\"token function\">getState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// {value: 1}</span></code></pre></div>\n<p><strong>You can think of dispatching actions as \"triggering an event\"</strong> in the application. Something happened, and we want the store to know about it. Reducers act like event listeners, and when they hear an action they are interested in, they update the state in response.</p>\n<h3>Selectors</h3>\n<p><strong>Selectors</strong> are functions that know how to extract specific pieces of information from a store state value. As an application grows bigger, this can help avoid repeating logic as different parts of the app need to read the same data:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">selectCounterValue</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">state</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> state<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> currentValue <span class=\"token operator\">=</span> <span class=\"token function\">selectCounterValue</span><span class=\"token punctuation\">(</span>store<span class=\"token punctuation\">.</span><span class=\"token function\">getState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>currentValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 2</span></code></pre></div>\n<h2>Core Concepts and Principles</h2>\n<p>Overall, we can summarize the intent behind Redux's design in three core concepts:</p>\n<h3>Single Source of Truth</h3>\n<p>The <strong>global state</strong> of your application is stored as an object inside a single <strong>store</strong>. Any given piece of data should only exist in one location, rather than being duplicated in many places.</p>\n<p>This makes it easier to debug and inspect your app's state as things change, as well as centralizing logic that needs to interact with the entire application.</p>\n<p>:::tip</p>\n<p>This does <em>not</em> mean that <em>every</em> piece of state in your app must go into the Redux store! You should decide whether a piece of state belongs in Redux or your UI components, based on where it's needed.</p>\n<p>:::</p>\n<h3>State is Read-Only</h3>\n<p>The only way to change the state is to dispatch an <strong>action</strong>, an object that describes what happened.</p>\n<p>This way, the UI won't accidentally overwrite data, and it's easier to trace why a state update happened. Since actions are plain JS objects, they can be logged, serialized, stored, and later replayed for debugging or testing purposes.</p>\n<h3>Changes are Made with Pure Reducer Functions</h3>\n<p>To specify how the state tree is updated based on actions, you write <strong>reducer</strong> functions. Reducers are pure functions that take the previous state and an action, and return the next state. Like any other functions, you can split reducers into smaller functions to help do the work, or write reusable reducers for common tasks.</p>\n<h2>Redux Application Data Flow</h2>\n<p>Earlier, we talked about \"one-way data flow\", which describes this sequence of steps to update the app:</p>\n<ul>\n<li>State describes the condition of the app at a specific point in time</li>\n<li>The UI is rendered based on that state</li>\n<li>When something happens (such as a user clicking a button), the state is updated based on what occurred</li>\n<li>The UI re-renders based on the new state</li>\n</ul>\n<p>For Redux specifically, we can break these steps into more detail:</p>\n<ul>\n<li>\n<p>Initial setup:</p>\n<ul>\n<li>A Redux store is created using a root reducer function</li>\n<li>The store calls the root reducer once, and saves the return value as its initial <code class=\"language-text\">state</code></li>\n<li>When the UI is first rendered, UI components access the current state of the Redux store, and use that data to decide what to render. They also subscribe to any future store updates so they can know if the state has changed.</li>\n</ul>\n</li>\n<li>\n<p>Updates:</p>\n<ul>\n<li>Something happens in the app, such as a user clicking a button</li>\n<li>The app code dispatches an action to the Redux store, like <code class=\"language-text\">dispatch({type: 'counter/incremented'})</code></li>\n<li>The store runs the reducer function again with the previous <code class=\"language-text\">state</code> and the current <code class=\"language-text\">action</code>, and saves the return value as the new <code class=\"language-text\">state</code></li>\n<li>The store notifies all parts of the UI that are subscribed that the store has been updated</li>\n<li>Each UI component that needs data from the store checks to see if the parts of the state they need have changed.</li>\n<li>Each component that sees its data has changed forces a re-render with the new data, so it can update what's shown on the screen</li>\n</ul>\n</li>\n</ul>\n<p>Here's what that data flow looks like visually:</p>\n<p><img src=\"/img/tutorials/essentials/ReduxDataFlowDiagram.gif\" alt=\"Redux data flow diagram\"></p>\n<h2>What You've Learned</h2>\n<p>:::tip Summary</p>\n<ul>\n<li>\n<p><strong>Redux's intent can be summarized in three principles</strong></p>\n<ul>\n<li>Global app state is kept in a single store</li>\n<li>The store state is read-only to the rest of the app</li>\n<li>Reducer functions are used to update the state in response to actions</li>\n</ul>\n</li>\n<li>\n<p><strong>Redux uses a \"one-way data flow\" app structure</strong></p>\n<ul>\n<li>State describes the condition of the app at a point in time, and UI renders based on that state</li>\n<li>\n<p>When something happens in the app:</p>\n<ul>\n<li>The UI dispatches an action</li>\n<li>The store runs the reducers, and the state is updated based on what occurred</li>\n<li>The store notifies the UI that the state has changed</li>\n</ul>\n</li>\n<li>The UI re-renders based on the new state</li>\n</ul>\n</li>\n</ul>\n<h3>Project Setup</h3>\n<p>For this tutorial, we've created a pre-configured starter project that already has React set up, includes some default styling, and has a fake REST API that will allow us to write actual API requests in our app. You'll use this as the basis for writing the actual application code.</p>\n<p>To get started, you can open and fork this CodeSandbox:</p>\n<iframe\n  class=\"codesandbox\"\n  src=\"https://codesandbox.io/embed/github/reduxjs/redux-fundamentals-example-app/tree/master/?fontsize=14&hidenavigation=1&theme=dark&runonclick=1\"\n  title=\"redux-fundamentals-example-app\"\n  allow=\"geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb\"\n  sandbox=\"allow-modals allow-forms allow-popups allow-scripts allow-same-origin\"\n>\n</iframe>\n<br>\n<p>You can also <a href=\"https://github.com/reduxjs/redux-fundamentals-example-app\">clone the same project from this Github repo</a>. After cloning the repo, you can install the tools for the project with <code class=\"language-text\">npm install</code>, and start it with <code class=\"language-text\">npm start</code>.</p>\n<p>If you'd like to see the final version of what we're going to build, you can check out <a href=\"https://github.com/reduxjs/redux-fundamentals-example-app/tree/tutorial-steps\">the <strong><code class=\"language-text\">tutorial-steps</code> branch</strong></a>, or <a href=\"https://codesandbox.io/s/github/reduxjs/redux-fundamentals-example-app/tree/tutorial-steps\">look at the final version in this CodeSandbox</a>.</p>\n<h4>Creating a New Redux + React Project</h4>\n<p>Once you've finished this tutorial, you'll probably want to try working on your own projects. <strong>We recommend using the <a href=\"https://github.com/reduxjs/cra-template-redux\">Redux templates for Create-React-App</a> as the fastest way to create a new Redux + React project</strong>. It comes with Redux Toolkit and React-Redux already configured, using <a href=\"./part-1-overview.md\">a modernized version of the \"counter\" app example you saw in Part 1</a>. This lets you jump right into writing your actual application code without having to add the Redux packages and set up the store.</p>\n<p>If you want to know specific details on how to add Redux to a project, see this explanation:</p>\n<DetailedExplanation title=\"Detailed Explanation: Adding Redux to a React Project\">\n<p>The Redux template for CRA comes with Redux Toolkit and React-Redux already configured. If you're setting up a new project from scratch without that template, follow these steps:</p>\n<ul>\n<li>Add the <code class=\"language-text\">@reduxjs/toolkit</code> and <code class=\"language-text\">react-redux</code> packages</li>\n<li>Create a Redux store using RTK's <code class=\"language-text\">configureStore</code> API, and pass in at least one reducer function</li>\n<li>Import the Redux store into your application's entry point file (such as <code class=\"language-text\">src/index.js</code>)</li>\n<li>Wrap your root React component with the <code class=\"language-text\">&lt;Provider></code> component from React-Redux, like:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>Provider store<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>store<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>App <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Provider<span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</DetailedExplanation>\n<h4>Exploring the Initial Project</h4>\n<p>This initial project is based on <a href=\"https://create-react-app.dev/docs/getting-started\">the standard Create-React-App</a> project template, with some modifications.</p>\n<p>Let's take a quick look at what the initial project contains:</p>\n<ul>\n<li>\n<p><code class=\"language-text\">/src</code></p>\n<ul>\n<li><code class=\"language-text\">index.js</code>: the entry point file for the application. It renders the main <code class=\"language-text\">&lt;App></code> component.</li>\n<li><code class=\"language-text\">App.js</code>: the main application component.</li>\n<li><code class=\"language-text\">index.css</code>: styles for the complete application</li>\n<li>\n<p><code class=\"language-text\">/api</code></p>\n<ul>\n<li><code class=\"language-text\">client.js</code>: a small AJAX request client that allows us to make GET and POST requests</li>\n<li><code class=\"language-text\">server.js</code>: provides a fake REST API for our data. Our app will fetch data from these fake endpoints later.</li>\n</ul>\n</li>\n<li><code class=\"language-text\">/exampleAddons</code>: contains some additional Redux addons that we'll use later in the tutorial to show how things work</li>\n</ul>\n</li>\n</ul>\n<p>If you load the app now, you should see a welcome message, but the rest of the app is otherwise empty.</p>\n<p>With that, let's get started!</p>\n<h2>Starting the Todo Example App</h2>\n<p>Our example application will be a small \"todo\" application. You've probably seen todo app examples before - they make\ngood examples because they let us show how to do things like tracking a list of items, handling user input, and updating\nthe UI when that data changes, which are all things that happen in a normal application.</p>\n<h3>Defining Requirements</h3>\n<p>Let's start by figuring out the initial business requirements for this application:</p>\n<ul>\n<li>\n<p>The UI should consist of three main sections:</p>\n<ul>\n<li>An input box to let the user type in the text of a new todo item</li>\n<li>A list of all the existing todo items</li>\n<li>A footer section that shows the number of non-completed todos, and shows filtering options</li>\n</ul>\n</li>\n<li>Todo list items should have a checkbox that toggles their \"completed\" status. We should also be able to add a color-coded\ncategory tag for a predefined list of colors, and delete todo items.</li>\n<li>The counter should pluralize the number of active todos: \"0 items\", \"1 item\", \"3 items\", etc</li>\n<li>There should be buttons to mark all todos as completed, and to clear all completed todos by removing them</li>\n<li>\n<p>There should be two ways to filter the displayed todos in the list:</p>\n<ul>\n<li>Filtering based on showing \"All\", \"Active\", and \"Completed\" todos</li>\n<li>Filtering based on selecting one or more colors, and showing any todos whose tag that match those colors</li>\n</ul>\n</li>\n</ul>\n<p>We'll add some more requirements later on, but this is enough to get us started.</p>\n<p>The end goal is an app that should look like this:</p>\n<p><img src=\"/img/tutorials/fundamentals/todos-app-screenshot.png\" alt=\"Example todo app screenshot\"></p>\n<h3>Designing the State Values</h3>\n<p>One of the core principles of React and Redux is that <strong>your UI should be based on your state</strong>. So, one approach to designing an application is to first think of all the state needed to describe how the application works. It's also a good idea\nto try to describe your UI with as few values in the state as possible, so there's less data you need to keep track of\nand update.</p>\n<p>Conceptually, there are two main aspects of this application:</p>\n<ul>\n<li>The actual list of current todo items</li>\n<li>The current filtering options</li>\n</ul>\n<p>We'll also need to keep track of the data the user is typing into the \"Add Todo\" input box, but that's less important\nand we'll handle that later.</p>\n<p>For each todo item, we need to store a few pieces of information:</p>\n<ul>\n<li>The text the user entered</li>\n<li>The boolean flag saying if it's completed or not</li>\n<li>A unique ID value</li>\n<li>A color category, if selected</li>\n</ul>\n<p>Our filtering behavior can probably be described with some enumerated values:</p>\n<ul>\n<li>Completed status: \"All\", \"Active\", and \"Completed\"</li>\n<li>Colors: \"Red\", \"Yellow\", \"Green\", \"Blue\", \"Orange\", \"Purple\"</li>\n</ul>\n<p>Looking at these values, we can also say that the todos are \"app state\" (the core data that the application works with),\nwhile the filtering values are \"UI state\" (state that describes what the app is doing right now). It can be helpful to\nthink about these different kinds of categories to help understand how the different pieces of state are being used.</p>\n<h3>Designing the State Structure</h3>\n<p>With Redux, <strong>our application state is always kept in plain JavaScript objects and arrays</strong>. That means you may not put\nother things into the Redux state - no class instances, built-in JS types like <code class=\"language-text\">Map</code> / <code class=\"language-text\">Set</code> <code class=\"language-text\">Promise</code> / <code class=\"language-text\">Date</code>, functions, or anything else that is not plain JS data.</p>\n<p><strong>The root Redux state value is almost always a plain JS object</strong>, with other data nested inside of it.</p>\n<p>Based on this information, we should now be able to describe the kinds of values we need to have inside our Redux state:</p>\n<ul>\n<li>\n<p>First, we need an array of todo item objects. Each item should have these fields:</p>\n<ul>\n<li><code class=\"language-text\">id</code>: a unique number</li>\n<li><code class=\"language-text\">text</code>: the text the user typed in</li>\n<li><code class=\"language-text\">completed</code>: a boolean flag</li>\n<li><code class=\"language-text\">color</code>: An optional color category</li>\n</ul>\n</li>\n<li>\n<p>Then, we need to describe our filtering options. We need to have:</p>\n<ul>\n<li>The current \"completed\" filter value</li>\n<li>An array of the currently selected color categories</li>\n</ul>\n</li>\n</ul>\n<p>So, here's what an example of our app's state might look like:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> todoAppState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Learn React'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Learn Redux'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'purple'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Build something fun!'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'blue'</span> <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">filters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">status</span><span class=\"token operator\">:</span> <span class=\"token string\">'Active'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">colors</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>It's important to note that <strong>it's okay to have other state values outside of Redux!</strong>. This example is small enough so far that we actually do have all our state in the Redux store, but as we'll see later, some data really doesn't need to be kept in Redux (like \"is this dropdown open?\" or \"current value of a form input\").</p>\n<h3>Designing Actions</h3>\n<p><strong>Actions</strong> are plain JavaScript objects that have a <code class=\"language-text\">type</code> field. As mentioned earlier, <strong>you can think of an action as an event that describes something that happened in the application</strong>.</p>\n<p>In the same way that we designed the state structure based on the app's requirements, we should also be able to\ncome up with a list of some of the actions that describe what's happening:</p>\n<ul>\n<li>Add a new todo entry based on the text the user entered</li>\n<li>Toggle the completed status of a todo</li>\n<li>Select a color category for a todo</li>\n<li>Delete a todo</li>\n<li>Mark all todos as completed</li>\n<li>Clear all completed todos</li>\n<li>Choose a different \"completed\" filter value</li>\n<li>Add a new color filter</li>\n<li>Remove a color filter</li>\n</ul>\n<p>We normally put any extra data needed to describe what's happening into the <code class=\"language-text\">action.payload</code> field. This could be a\nnumber, a string, or an object with multiple fields inside.</p>\n<p>The Redux store doesn't care what the actual text of the <code class=\"language-text\">action.type</code> field is. However, your own code will look\nat <code class=\"language-text\">action.type</code> to see if an update is needed. Also, you will frequently look at action type strings in the Redux\nDevTools Extension while debugging to see what's going on in your app. So, try to choose action types that are\nreadable and clearly describe what's happening - it'll be much easier to understand things when you look at them later!</p>\n<p>Based on that list of things that can happen, we can create a list of actions that our application will use:</p>\n<ul>\n<li><code class=\"language-text\">{type: 'todos/todoAdded', payload: todoText}</code></li>\n<li><code class=\"language-text\">{type: 'todos/todoToggled', payload: todoId}</code></li>\n<li><code class=\"language-text\">{type: 'todos/colorSelected, payload: {todoId, color}}</code></li>\n<li><code class=\"language-text\">{type: 'todos/todoDeleted', payload: todoId}</code></li>\n<li><code class=\"language-text\">{type: 'todos/allCompleted'}</code></li>\n<li><code class=\"language-text\">{type: 'todos/completedCleared'}</code></li>\n<li><code class=\"language-text\">{type: 'filters/statusFilterChanged', payload: filterValue}</code></li>\n<li><code class=\"language-text\">{type: 'filters/colorFilterChanged', payload: {color, changeType}}</code></li>\n</ul>\n<p>In this case, the actions primarily have a single extra piece of data, so we can put that directly in the <code class=\"language-text\">action.payload</code> field. We could have split the color filter behavior into two actions, one for \"added\" and one for \"removed\", but in this case\nwe'll do it as one action with an extra field inside specifically to show that we can have objects as an action payload.</p>\n<p>Like the state data, <strong>actions should contain the smallest amount of information needed to describe what happened</strong>.</p>\n<h2>Writing Reducers</h2>\n<p>Now that we know what our state structure and our actions look like, it's time to write our first reducer.</p>\n<p><strong>Reducers</strong> are functions that take the current <code class=\"language-text\">state</code> and an <code class=\"language-text\">action</code> as arguments, and return a new <code class=\"language-text\">state</code> result. In other words, <strong><code class=\"language-text\">(state, action) => newState</code></strong>.</p>\n<h3>Creating the Root Reducer</h3>\n<p><strong>A Redux app really only has one reducer function: the \"root reducer\" function</strong> that you will pass to <code class=\"language-text\">createStore</code> later on. That one root reducer function is responsible for handling <em>all</em> of the actions that are dispatched, and calculating what the <em>entire</em> new state result should be every time.</p>\n<p>Let's start by creating a <code class=\"language-text\">reducer.js</code> file in the <code class=\"language-text\">src</code> folder, alongside <code class=\"language-text\">index.js</code> and <code class=\"language-text\">App.js</code>.</p>\n<p>Every reducer needs some initial state, so we'll add some fake todo entries to get us started. Then, we can write an outline for the logic inside the reducer function:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/reducer.js\"</span>\n<span class=\"token keyword\">const</span> initialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Learn React'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Learn Redux'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'purple'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Build something fun!'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'blue'</span> <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">filters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">status</span><span class=\"token operator\">:</span> <span class=\"token string\">'All'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">colors</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Use the initialState as a default value</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">appReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// The reducer normally looks at the action type field to decide what happens</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Do something here based on the different types of actions</span>\n        <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n            <span class=\"token comment\">// If this reducer doesn't recognize the action type, or doesn't</span>\n            <span class=\"token comment\">// care about this specific action, return the existing state unchanged</span>\n            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>A reducer may be called with <code class=\"language-text\">undefined</code> as the state value when the application is being initialized. If that happens, we need to provide an initial state value so the rest of the reducer code has something to work with. <strong>Reducers normally use ES6 default argument syntax to provide initial state: <code class=\"language-text\">(state = initialState, action)</code></strong>.</p>\n<p>Next, let's add the logic to handle the <code class=\"language-text\">'todos/todoAdded'</code> action.</p>\n<p>We first need to check if the current action's type matches that specific string.\nThen, we need to return a new object containing <em>all</em> of the state, even for the fields\nthat didn't change.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/reducer.js\"</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">nextTodoId</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todos</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> maxId <span class=\"token operator\">=</span> todos<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">maxId<span class=\"token punctuation\">,</span> todo</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>todo<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">,</span> maxId<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> maxId <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Use the initialState as a default value</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">appReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// The reducer normally looks at the action type field to decide what happens</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Do something here based on the different types of actions</span>\n<span class=\"gatsby-highlight-code-line\">        <span class=\"token keyword\">case</span> <span class=\"token string\">'todos/todoAdded'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token comment\">// We need to return a new state object</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token comment\">// that has all the existing state data</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token comment\">// but has a new array for the `todos` field</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token comment\">// with all of the old todos</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token operator\">...</span>state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token comment\">// and the new todo object</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                        <span class=\"token comment\">// Use an auto-incrementing numeric ID for this example</span></span><span class=\"gatsby-highlight-code-line\">                        <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token function\">nextTodoId</span><span class=\"token punctuation\">(</span>state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                        <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> action<span class=\"token punctuation\">.</span>payload<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                        <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token punctuation\">}</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token punctuation\">]</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">        <span class=\"token punctuation\">}</span></span>        <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n            <span class=\"token comment\">// If this reducer doesn't recognize the action type, or doesn't</span>\n            <span class=\"token comment\">// care about this specific action, return the existing state unchanged</span>\n            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>That's... an awful lot of work to add one todo item to the state. Why is all this extra work necessary?</p>\n<h3>Rules of Reducers</h3>\n<p>We said earlier that <strong>reducers must <em>always</em> follow some special rules</strong>:</p>\n<ul>\n<li>They should only calculate the new state value based on the <code class=\"language-text\">state</code> and <code class=\"language-text\">action</code> arguments</li>\n<li>They are not allowed to modify the existing <code class=\"language-text\">state</code>. Instead, they must make <em>immutable updates</em>, by copying the existing <code class=\"language-text\">state</code> and making changes to the copied values.</li>\n<li>They must not do any asynchronous logic or other \"side effects\"</li>\n</ul>\n<p>:::tip</p>\n<p><strong>A \"side effect\" is any change to state or behavior that can be seen outside of returning a value from a function</strong>. Some common kinds of side effects are things like:</p>\n<ul>\n<li>Logging a value to the console</li>\n<li>Saving a file</li>\n<li>Setting an async timer</li>\n<li>Making an AJAX HTTP request</li>\n<li>Modifying some state that exists outside of a function, or mutating arguments to a function</li>\n<li>Generating random numbers or unique random IDs (such as <code class=\"language-text\">Math.random()</code> or <code class=\"language-text\">Date.now()</code>)</li>\n</ul>\n<p>:::</p>\n<p>Any function that follows these rules is also known as a <strong>\"pure\" function</strong>, even if it's not specifically written as a reducer function.</p>\n<p>But why are these rules important? There's a few different reasons:</p>\n<ul>\n<li>One of the goals of Redux is to make your code predictable. When a function's output is only calculated from the input arguments, it's easier to understand how that code works, and to test it.</li>\n<li>On the other hand, if a function depends on variables outside itself, or behaves randomly, you never know what will happen when you run it.</li>\n<li>If a function modifies other values, including its arguments, that can change the way the application works unexpectedly. This can be a common source of bugs, such as \"I updated my state, but now my UI isn't updating when it should!\"</li>\n<li>Some of the Redux DevTools capabilities depend on having your reducers follow these rules correctly</li>\n</ul>\n<p>The rule about \"immutable updates\" is particularly important, and worth talking about further.</p>\n<h3>Reducers and Immutable Updates</h3>\n<p>Earlier, we talked about \"mutation\" (modifying existing object/array values) and \"immutability\" (treating values as something that cannot be changed).</p>\n<p>:::warning</p>\n<p>In Redux, <strong>our reducers are <em>never</em> allowed to mutate the original / current state values!</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// ❌ Illegal - by default, this will mutate the state!</span>\nstate<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> <span class=\"token number\">123</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>:::</p>\n<p>There are several reasons why you must not mutate state in Redux:</p>\n<ul>\n<li>It causes bugs, such as the UI not updating properly to show the latest values</li>\n<li>It makes it harder to understand why and how the state has been updated</li>\n<li>It makes it harder to write tests</li>\n<li>It breaks the ability to use \"time-travel debugging\" correctly</li>\n<li>It goes against the intended spirit and usage patterns for Redux</li>\n</ul>\n<p>So if we can't change the originals, how do we return an updated state?</p>\n<p>:::tip</p>\n<p><strong>Reducers can only make <em>copies</em> of the original values, and then they can mutate the copies.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// ✅ This is safe, because we made a copy</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">123</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>:::</p>\n<p>We already saw that we can <a href=\"./part-2-concepts-data-flow.md#immutability\">write immutable updates by hand</a>, by using JavaScript's array / object spread operators and other functions that return copies of the original values.</p>\n<p>This becomes harder when the data is nested. <strong>A critical rule of immutable updates is that you must make a copy of <em>every</em> level of nesting that needs to be updated.</strong></p>\n<p>However, if you're thinking that \"writing immutable updates by hand this way looks hard to remember and do correctly\"... yeah, you're right! :)</p>\n<p>Writing immutable update logic by hand <em>is</em> hard, and <strong>accidentally mutating state in reducers is the single most common mistake Redux users make</strong>.</p>\n<p>:::tip</p>\n<p><strong>In real-world applications, you won't have to write these complex nested immutable updates by hand</strong>. In <a href=\"./part-8-modern-redux.md\">Part 8: Modern Redux with Redux Toolkit</a>, you'll\nlearn how to use Redux Toolkit to simplify writing immutable update logic in reducers.</p>\n<p>:::</p>\n<h3>Handling Additional Actions</h3>\n<p>With that in mind, let's add the reducer logic for a couple more cases. First, toggling a todo's <code class=\"language-text\">completed</code> field based on its ID:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/reducer.js\"</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">appReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">case</span> <span class=\"token string\">'todos/todoAdded'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span>\n                <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n                    <span class=\"token operator\">...</span>state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token function\">nextTodoId</span><span class=\"token punctuation\">(</span>state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> action<span class=\"token punctuation\">.</span>payload<span class=\"token punctuation\">,</span>\n                        <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">]</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n<span class=\"gatsby-highlight-code-line\">        <span class=\"token keyword\">case</span> <span class=\"token string\">'todos/todoToggled'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token comment\">// Again copy the entire state object</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token comment\">// This time, we need to make a copy of the old todos array</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todo</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token comment\">// If this isn't the todo item we're looking for, leave it alone</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>todo<span class=\"token punctuation\">.</span>id <span class=\"token operator\">!==</span> action<span class=\"token punctuation\">.</span>payload<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                        <span class=\"token keyword\">return</span> todo<span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token punctuation\">}</span></span><span class=\"gatsby-highlight-code-line\"></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token comment\">// We've found the todo that has to change. Return a copy:</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                        <span class=\"token operator\">...</span>todo<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                        <span class=\"token comment\">// Flip the completed flag</span></span><span class=\"gatsby-highlight-code-line\">                        <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span>todo<span class=\"token punctuation\">.</span>completed</span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">        <span class=\"token punctuation\">}</span></span>        <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>And since we've been focusing on the todos state, let's add a case to handle the \"visibility selection changed\" action as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/reducer.js\"</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">appReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">case</span> <span class=\"token string\">'todos/todoAdded'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span>\n                <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n                    <span class=\"token operator\">...</span>state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token function\">nextTodoId</span><span class=\"token punctuation\">(</span>state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> action<span class=\"token punctuation\">.</span>payload<span class=\"token punctuation\">,</span>\n                        <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">]</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">case</span> <span class=\"token string\">'todos/todoToggled'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span>\n                <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todo</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>todo<span class=\"token punctuation\">.</span>id <span class=\"token operator\">!==</span> action<span class=\"token punctuation\">.</span>payload<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> todo<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token operator\">...</span>todo<span class=\"token punctuation\">,</span>\n                        <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span>todo<span class=\"token punctuation\">.</span>completed\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n<span class=\"gatsby-highlight-code-line\">        <span class=\"token keyword\">case</span> <span class=\"token string\">'filters/statusFilterChanged'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token comment\">// Copy the whole state</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token comment\">// Overwrite the filters value</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token literal-property property\">filters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token comment\">// copy the other filter fields</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token operator\">...</span>state<span class=\"token punctuation\">.</span>filters<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token comment\">// And replace the status field with the new value</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token literal-property property\">status</span><span class=\"token operator\">:</span> action<span class=\"token punctuation\">.</span>payload</span><span class=\"gatsby-highlight-code-line\">                <span class=\"token punctuation\">}</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">        <span class=\"token punctuation\">}</span></span>        <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We've only handled 3 actions, but this is already getting a bit long. If we try to handle every action in this one reducer\nfunction, it's going to be hard to read it all.</p>\n<p>That's why <strong>reducers are typically split into multiple smaller reducer functions</strong> - to make it easier to understand and\nmaintain the reducer logic.</p>\n<h2>Splitting Reducers</h2>\n<p>As part of this, <strong>Redux reducers are typically split apart based on the section of the Redux state that they update</strong>. Our todo app state currently has two top-level sections: <code class=\"language-text\">state.todos</code> and <code class=\"language-text\">state.filters</code>. So, we can split the large root reducer function into two smaller reducers - a <code class=\"language-text\">todosReducer</code> and a <code class=\"language-text\">filtersReducer</code>.</p>\n<p>So, where should these split-up reducer functions live?</p>\n<p><strong>We recommend organizing your Redux app folders and files based on \"features\"</strong> - code that relates to a specific concept\nor area of your application. <strong>The Redux code for a particular feature is usually written as a single file, known as a\n\"slice\" file</strong>, which contains all the reducer logic and all of the action-related code for that part of your app state.</p>\n<p>Because of that, <strong>the reducer for a specific section of the Redux app state is called a \"slice reducer\"</strong>. Typically, some of the action objects will be closely related to a specific slice reducer, and so the action type strings should start with the name of that feature (like <code class=\"language-text\">'todos'</code>) and describe the event that happened (like <code class=\"language-text\">'todoAdded'</code>), joined together into one string (<code class=\"language-text\">'todos/todoAdded'</code>).</p>\n<p>In our project, create a new <code class=\"language-text\">features</code> folder, and then a <code class=\"language-text\">todos</code> folder inside that. Create a new file named <code class=\"language-text\">todosSlice.js</code>, and let's cut and paste the todo-related initial state over into this file:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/features/todos/todosSlice.js\"</span>\n<span class=\"token keyword\">const</span> initialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Learn React'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Learn Redux'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'purple'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Build something fun!'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'blue'</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">nextTodoId</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todos</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> maxId <span class=\"token operator\">=</span> todos<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">maxId<span class=\"token punctuation\">,</span> todo</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>todo<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">,</span> maxId<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> maxId <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">todosReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now we can copy over the logic for updating the todos. However, there's an important difference here. <strong>This file only has to update the todos-related state - it's not nested any more!</strong> This is another reason why we split up reducers. Since the todos state is an array by itself, we don't have to copy the outer root state object in here. That makes this reducer easier to read.</p>\n<p>This is called <strong>reducer composition</strong>, and it's the fundamental pattern of building Redux apps.</p>\n<p>Here's what the updated reducer looks like after we handle those actions:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/features/todos/todosSlice.js\"</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">todosReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"gatsby-highlight-code-line\">        <span class=\"token keyword\">case</span> <span class=\"token string\">'todos/todoAdded'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token comment\">// Can return just the new todos array - no extra object around it</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token function\">nextTodoId</span><span class=\"token punctuation\">(</span>state<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> action<span class=\"token punctuation\">.</span>payload<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token punctuation\">}</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">        <span class=\"token punctuation\">}</span></span><span class=\"gatsby-highlight-code-line\">        <span class=\"token keyword\">case</span> <span class=\"token string\">'todos/todoToggled'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todo</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>todo<span class=\"token punctuation\">.</span>id <span class=\"token operator\">!==</span> action<span class=\"token punctuation\">.</span>payload<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token keyword\">return</span> todo<span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token punctuation\">}</span></span><span class=\"gatsby-highlight-code-line\"></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token operator\">...</span>todo<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                    <span class=\"token literal-property property\">completed</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span>todo<span class=\"token punctuation\">.</span>completed</span><span class=\"gatsby-highlight-code-line\">                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">        <span class=\"token punctuation\">}</span></span>        <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>That's a bit shorter and easier to read.</p>\n<p>Now we can do the same thing for the visibility logic. Create <code class=\"language-text\">src/features/filters/filtersSlice.js</code>, and let's move all the filter-related code over there:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/features/filters/filtersSlice.js\"</span>\n<span class=\"token keyword\">const</span> initialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">status</span><span class=\"token operator\">:</span> <span class=\"token string\">'All'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">colors</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">filtersReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> initialState<span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"gatsby-highlight-code-line\">        <span class=\"token keyword\">case</span> <span class=\"token string\">'filters/statusFilterChanged'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token comment\">// Again, one less level of nesting to copy</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span></span><span class=\"gatsby-highlight-code-line\">                <span class=\"token literal-property property\">status</span><span class=\"token operator\">:</span> action<span class=\"token punctuation\">.</span>payload</span><span class=\"gatsby-highlight-code-line\">            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></span><span class=\"gatsby-highlight-code-line\">        <span class=\"token punctuation\">}</span></span>        <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n            <span class=\"token keyword\">return</span> state<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We still have to copy the object containing the filters state, but since there's less nesting, it's easier to read what's happening.</p>\n<p>:::info</p>\n<p>To keep this page shorter, we'll skip showing how to write the reducer update logic for the other actions.</p>\n<p><strong>Try writing the updates for those yourself</strong>, based on <a href=\"#defining-requirements\">the requirements described above</a>.</p>\n<p>If you get stuck, see <a href=\"#what-youve-learned\">the CodeSandbox at the end of this page</a> for the complete implementation of these reducers.</p>\n<p>:::</p>\n<h2>Combining Reducers</h2>\n<p>We now have two separate slice files, each with its own slice reducer function. But, we said earlier that the Redux store needs <em>one</em> root reducer function when we create it. So, how can we go back to having a root reducer without putting all the code in one big function?</p>\n<p>Since reducers are normal JS functions, we can import the slice reducers back into <code class=\"language-text\">reducer.js</code>, and write a new root reducer whose only job is to call the other two functions.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/reducer.js\"</span>\n<span class=\"token keyword\">import</span> todosReducer <span class=\"token keyword\">from</span> <span class=\"token string\">'./features/todos/todosSlice'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> filtersReducer <span class=\"token keyword\">from</span> <span class=\"token string\">'./features/filters/filtersSlice'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">function</span> <span class=\"token function\">rootReducer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> action</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// always return a new object for the root state</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// the value of `state.todos` is whatever the todos reducer returns</span>\n        <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> <span class=\"token function\">todosReducer</span><span class=\"token punctuation\">(</span>state<span class=\"token punctuation\">.</span>todos<span class=\"token punctuation\">,</span> action<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        <span class=\"token comment\">// For both reducers, we only pass in their slice of the state</span>\n        <span class=\"token literal-property property\">filters</span><span class=\"token operator\">:</span> <span class=\"token function\">filtersReducer</span><span class=\"token punctuation\">(</span>state<span class=\"token punctuation\">.</span>filters<span class=\"token punctuation\">,</span> action<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Note that each of these reducers is managing its own part of the global state. The state parameter is different for every reducer, and corresponds to the part of the state it manages.</strong></p>\n<p>This allows us to split up our logic based on features and slices of state, to keep things maintainable.</p>\n<h3><code class=\"language-text\">combineReducers</code></h3>\n<p>We can see that the new root reducer is doing the same thing for each slice: calling the slice reducer, passing in the slice of the state owned by that reducer, and assigning the result back to the root state object. If we were to add more slices, the pattern\nwould repeat.</p>\n<p>The Redux core library includes a utility called <a href=\"../../api/combineReducers.md\"><code class=\"language-text\">combineReducers</code></a>, which does this same boilerplate step for us. We can replace our hand-written <code class=\"language-text\">rootReducer</code> with a shorter one generated by <code class=\"language-text\">combineReducers</code>.</p>\n<p><strong>Now that we need <code class=\"language-text\">combineReducers</code>, it's time to actually install the Redux core library</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nnpm install redux</code></pre></div>\n<p>Once that's done, we can import <code class=\"language-text\">combineReducers</code> and use it:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// title=\"src/reducer.js\"</span>\n<span class=\"gatsby-highlight-code-line\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> combineReducers <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'redux'</span><span class=\"token punctuation\">;</span></span>\n<span class=\"token keyword\">import</span> todosReducer <span class=\"token keyword\">from</span> <span class=\"token string\">'./features/todos/todosSlice'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> filtersReducer <span class=\"token keyword\">from</span> <span class=\"token string\">'./features/filters/filtersSlice'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> rootReducer <span class=\"token operator\">=</span> <span class=\"token function\">combineReducers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Define a top-level state field named `todos`, handled by `todosReducer`</span>\n    <span class=\"token literal-property property\">todos</span><span class=\"token operator\">:</span> todosReducer<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">filters</span><span class=\"token operator\">:</span> filtersReducer\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> rootReducer<span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">combineReducers</code> accepts an object where the key names will become the keys in your root state object, and the\nvalues are the slice reducer functions that know how to update those slices of the Redux state.</p>\n<p><strong>Remember, the key names you give to <code class=\"language-text\">combineReducers</code> decides what the key names of your state object will be!</strong></p>\n<h2>What You've Learned</h2>\n<p><strong>State, Actions, and Reducers are the building blocks of Redux</strong>. Every Redux app has state values, creates actions to describe what happened, and uses reducer functions to calculate new state values based on the previous state and an action.</p>\n<p>Here's the contents of our app so far:</p>\n<iframe\n  class=\"codesandbox\"\n  src=\"https://codesandbox.io/embed/github/reduxjs/redux-fundamentals-example-app/tree/checkpoint-1-combinedReducers/?fontsize=14&hidenavigation=1&module=%2Fsrc%2Freducer.js&theme=dark&runonclick=1\"\n  title=\"redux-fundamentals-example-app\"\n  allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n  sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n>\n</iframe>\n<br>\n<p>:::tip Summary</p>\n<ul>\n<li>\n<p><strong>Redux apps use plain JS objects, arrays, and primitives as the state values</strong></p>\n<ul>\n<li>The root state value should be a plain JS object</li>\n<li>The state should contain the smallest amount of data needed to make the app work</li>\n<li>Classes, Promises, functions, and other non-plain values should <em>not</em> go in the Redux state</li>\n<li>Reducers must not create random values like <code class=\"language-text\">Math.random()</code> or <code class=\"language-text\">Date.now()</code></li>\n<li>It's okay to have other state values that are not in the Redux store (like local component state) side-by side with Redux</li>\n</ul>\n</li>\n<li>\n<p><strong>Actions are plain objects with a <code class=\"language-text\">type</code> field that describe what happened</strong></p>\n<ul>\n<li>The <code class=\"language-text\">type</code> field should be a readable string, and is usually written as <code class=\"language-text\">'feature/eventName'</code></li>\n<li>Actions may contain other values, which are typically stored in the <code class=\"language-text\">action.payload</code> field</li>\n<li>Actions should have the smallest amount of data needed to describe what happened</li>\n</ul>\n</li>\n<li>\n<p><strong>Reducers are functions that look like <code class=\"language-text\">(state, action) => newState</code></strong></p>\n<ul>\n<li>\n<p>Reducers must always follow special rules:</p>\n<ul>\n<li>Only calculate the new state based on the <code class=\"language-text\">state</code> and <code class=\"language-text\">action</code> arguments</li>\n<li>Never mutate the existing <code class=\"language-text\">state</code> - always return a copy</li>\n<li>No \"side effects\" like AJAX calls or async logic</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Reducers should be split up to make them easier to read</strong></p>\n<ul>\n<li>Reducers are usually split based on top-level state keys or \"slices\" of state</li>\n<li>Reducers are usually written in \"slice\" files, organized into \"feature\" folders</li>\n<li>Reducers can be combined together with the Redux <code class=\"language-text\">combineReducers</code> function</li>\n<li>The key names given to <code class=\"language-text\">combineReducers</code> define the top-level state object keys</li>\n</ul>\n</li>\n</ul>"},{"url":"/docs/archive/","relativePath":"docs/archive.md","relativeDir":"docs","base":"archive.md","name":"archive","frontmatter":{"title":"Archive","weight":0,"excerpt":"more tools that I have created or collaborated on.","seo":{"title":"Resource Archive","description":"embeded developer tools and utilities","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<div class=\"important\"><strong>Archive<strong></div>\n<br>\n<br>\n<br>\n<br>\n<h1>     Resource Archive           </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://resourcerepo2.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Google Drive</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://drive.google.com/embeddedfolderview?id=1DHyQsPLziqSUODclplhnNX1eknzbZrL8#list\" style=\"width:100%; height:600px; border:0;\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>    Internet Archive        </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://archive.org/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Lambda Student Site </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://lambda-resources.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Bass Station CSS Showcase</h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://bgoonz.github.io/bass-station/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Interview     </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://web-dev-interview-prep-quiz-website.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Speach Recognition api </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe  class=\"block-content\" src=\"https://random-static-html-deploys.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  The Algos Bgoonz Branch </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe  class=\"block-content\" src=\"https://thealgorithms.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>Markdown Templates</h1>\n<br>\n<br>\n<br>\n<br>\n<iframe  class=\"block-content\" src=\"https://markdown-templates-42.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>CURL</h1>\n<br>\n<br>\n<br>\n<br>\n<iframe  class=\"block-content\" src=\"https://bgoonz.github.io/everything-curl/index.html\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Text Tools     </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://devtools42.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Ternary Converter   </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://ternary42.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Github HTML Render from link </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://githtmlpreview.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Form Builder GUI </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://fourm-builder-gui.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Border Builder </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://codepen.io/bgoonz/embed/zYwLVmb?default-tab=html%2Cresult\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h2>Archives</h2>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Original Blog Site </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://web-dev-resource-hub.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write;  encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/privacy-policy/","relativePath":"docs/privacy-policy.md","relativeDir":"docs","base":"privacy-policy.md","name":"privacy-policy","frontmatter":{"title":"Privacy Policy","weight":0,"excerpt":"Privacy Policy","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PRIVACY NOTICE</code></pre></div>\n<ul>\n<li>Visit our website at <a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a></li>\n</ul>\n<!---->\n<ul>\n<li>Use our Facebook application — <a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a></li>\n</ul>\n<!---->\n<ul>\n<li>Engage with us in other related ways ― including any sales, marketing, or events</li>\n</ul>\n<!---->\n<ul>\n<li>\"<strong>Website</strong>,\" we are referring to any website of ours that references or links to this policy</li>\n</ul>\n<!---->\n<ul>\n<li>\"<strong>App</strong>,\" we are referring to any application of ours that references or links to this policy, including any listed above</li>\n</ul>\n<!---->\n<ul>\n<li>\"<strong>Services</strong>,\" we are referring to our Website, App, and other related services, including any sales, marketing, or events</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To facilitate account creation and logon process.</strong> If you choose to link your account with us to a third-party account (such as your Google or Facebook account), we use the information you allowed us to collect from those third parties to facilitate account creation and logon process for the performance of the contract.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To post testimonials.</strong> We post testimonials on our Services that may contain personal information. Prior to posting a testimonial, we will obtain your consent to use your name and the content of the testimonial. If you wish to update, or delete your testimonial, please contact us at __________ and be sure to include your name, testimonial location, and contact information.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Request feedback.</strong>  We may use your information to request feedback and to contact you about your use of our Services.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To enable user-to-user communications.</strong> We may use your information in order to enable user-to-user communications with each user's consent.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To manage user accounts.</strong>  We may use your information for the purposes of managing our account and keeping it in working order.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To send administrative information to you.</strong>  We may use your personal information to send you product, service and new feature information and/or information about changes to our terms, conditions, and policies.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To protect our Services.</strong>  We may use your information as part of our efforts to keep our Services safe and secure (for example, for fraud monitoring and prevention).</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To enforce our terms, conditions and policies for business purposes, to comply with legal and regulatory requirements or in connection with our contract.</strong></li>\n</ul>\n<!---->\n<ul>\n<li><strong>To respond to legal requests and prevent harm.</strong>  If we receive a subpoena or other legal request, we may need to inspect the data we hold to determine how to respond.</li>\n<li></li>\n<li><strong>Fulfill and manage your orders.</strong> We may use your information to fulfill and manage your orders, payments, returns, and exchanges made through the Services.</li>\n<li></li>\n<li><strong>Administer prize draws and competitions.</strong> We may use your information to administer prize draws and competitions when you elect to participate in our competitions.</li>\n<li><strong>To deliver and facilitate delivery of services to the user.</strong> We may use your information to provide you with the requested service.</li>\n<li><strong>To respond to user inquiries/offer support to users.</strong> We may use your information to respond to your inquiries and solve any potential issues you might have with the use of our Services.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To send you marketing and promotional communications.</strong> We and/or our third-party marketing partners may use the personal information you send to us for our marketing purposes, if this is in accordance with your marketing preferences. For example, when expressing an interest in obtaining information about us or our Services, subscribing to marketing or otherwise contacting us, we will collect personal information from you. You can opt-out of our marketing emails at any time (see the \"<a href=\"https://cdpn.io/bgoonz/fullpage/LYLJZrW#privacyrights\">WHAT ARE YOUR PRIVACY RIGHTS?</a>\" below).</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Deliver targeted advertising to you.</strong> We may use your information to develop and display personalized content and advertising (and work with third parties who do so) tailored to your interests and/or location and to measure its effectiveness.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Consent:</strong> We may process your data if you have given us specific consent to use your personal information for a specific purpose.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Legitimate Interests:</strong> We may process your data when it is reasonably necessary to achieve our legitimate business interests.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Performance of a Contract:</strong> Where we have entered into a contract with you, we may process your personal information to fulfill the terms of our contract.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Legal Obligations:</strong> We may disclose your information where we are legally required to do so in order to comply with applicable law, governmental requests, a judicial proceeding, court order, or legal process, such as in response to a court order or a subpoena (including in response to public authorities to meet national security or law enforcement requirements).</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Vital Interests:</strong> We may disclose your information where we believe it is necessary to investigate, prevent, or take action regarding potential violations of our policies, suspected fraud, situations involving potential threats to the safety of any person and illegal activities, or as evidence in litigation in which we are involved.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Business Transfers.</strong> We may share or transfer your information in connection with, or during negotiations of, any merger, sale of company assets, financing, or acquisition of all or a portion of our business to another company.</li>\n</ul>\n<!---->\n<ul>\n<li>Receiving help through our customer support channels;</li>\n</ul>\n<!---->\n<ul>\n<li>Participation in customer surveys or contests; and</li>\n</ul>\n<!---->\n<ul>\n<li>Facilitation in the delivery of our Services and to respond to your inquiries.</li>\n</ul>\n<!---->\n<ul>\n<li>whether we collect and use your personal information;</li>\n</ul>\n<!---->\n<ul>\n<li>the categories of personal information that we collect;</li>\n</ul>\n<!---->\n<ul>\n<li>the purposes for which the collected personal information is used;</li>\n</ul>\n<!---->\n<ul>\n<li>whether we sell your personal information to third parties;</li>\n</ul>\n<!---->\n<ul>\n<li>the categories of personal information that we sold or disclosed for a business purpose;</li>\n</ul>\n<!---->\n<ul>\n<li>the categories of third parties to whom the personal information was sold or disclosed for a business purpose; and</li>\n</ul>\n<!---->\n<ul>\n<li>the business or commercial purpose for collecting or selling personal information.</li>\n</ul>\n<!---->\n<ul>\n<li>you may object to the processing of your personal data</li>\n</ul>\n<!---->\n<ul>\n<li>you may request correction of your personal data if it is incorrect or no longer relevant, or ask to restrict the processing of the data</li>\n</ul>\n<!---->\n<ul>\n<li>you can designate an authorized agent to make a request under the CCPA on your behalf. We may deny a request from an authorized agent that does not submit proof that they have been validly authorized to act on your behalf in accordance with the CCPA.</li>\n</ul>\n<!---->\n<ul>\n<li>you may request to opt-out from future selling of your personal information to third parties. Upon receiving a request to opt-out, we will act upon the request as soon as feasibly possible, but no later than 15 days from the date of the request submission.</li>\n</ul>"},{"url":"/blog/wordpress-vs-headless-cms/","relativePath":"blog/wordpress-vs-headless-cms.md","relativeDir":"blog","base":"wordpress-vs-headless-cms.md","name":"wordpress-vs-headless-cms","frontmatter":{"title":"Wordpress VS Headless CMS","template":"post","subtitle":"What is a Content Management System (CMS)","excerpt":"What is a Content Management System (CMS)","date":"2022-05-29T02:04:35.310Z","image":"https://img.youtube.com/vi/PPtmowJoe3s/sddefault.jpg","thumb_image":"https://img.youtube.com/vi/PPtmowJoe3s/sddefault.jpg","image_position":"top","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/content-management.yaml"],"tags":["src/data/tags/data-structures-algorithms.yaml","src/data/tags/cms.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/code-playgrounds-of-2021.md"],"cmseditable":true},"html":"<h2>Introduction:</h2>\n<ul>\n<li><em>What is a Content Management System (CMS)?</em></li>\n</ul>\n<p>A content management system, or CMS, is a software program that allows users to create and maintain websites without having to write them from the ground up or even knowing how to code.</p>\n<p>A content management system (CMS) allows you to generate, manage, change, and publish material using a user-friendly interface. Rather than coding, you may change the look and functionality of your site by downloading or purchasing templates and plugins. You can have several users collaborating in the same tool's backend, among other things.</p>\n<ul>\n<li><em>Evolution of CMS: The new scaffolding</em></li>\n</ul>\n<p>Like all good things, CMS's emerged in their final form after a lot of evolution throughout the years.</p>\n<p>In the early 90s, flat HTML files were popular, but around 1993, we got our first visual support. This paved the way for the launch of Internet Explorer browser, which supported CSS. After this, the next step was working towards dynamic content. DOM came about in 1997 and allowed us to identify and manage elements of a document programmatically.</p>\n<p>Now fast forward to 2010s, the DXP platform emerged, where we could create and deliver integrated and optimized customer experiences across all digital media, all audiences (while keeping the focus on the customer), and all phases of the user/customer journey.</p>\n<p>We have come along with CMSs indeed.</p>\n<h2>WordPress CMS: The choice of an all-inclusive frontend and backend</h2>\n<p>WordPress is an open-source platform for building websites. WordPress is a content management system (CMS) developed in PHP that uses a MySQL database.</p>\n<p>Any website that uses WordPress as its content management system is referred to as a WordPress website (CMS). Both the backend (the interface where a user signs in to make changes or add new material) and the frontend (the visible part of the website that your visitors see on the web) are powered by WordPress in most cases.</p>\n<p>Bear in mind that some WP REST API and AngularJS expertise will be required to build a WordPress-powered frontend application. On the other hand, with WordPress as the backend, you will be able to create any application. With a combination of either of these, you can deviate from the common WordPress theme and admin model. (Keep in mind you will need the help of wireframes forbuilding a WordPress-powered frontend application)</p>\n<p>There are a few things you should know if you're just getting started with WordPress. To begin, you must first understand the distinction between WordPress.com and WordPress.org.</p>\n<p>If you're unfamiliar with WordPress, the distinction between WordPress.com and WordPress.org might be perplexing.</p>\n<p>WordPress.com</p>\n<p>i.) WordPress.com is a hosted version of WordPress where you may establish a blog or website by signing up for a WordPress.com account.</p>\n<p>ii.) A custom domain, additional storage space, Google Analytics connection, the option to install your plugins and themes, and other features are all available as paid upgrades.</p>\n<p>iii.) The word \"WordPress\" will be included in your website's URL or domain by default, such as mysite.wordpress.com.</p>\n<p>WordPress.org</p>\n<p>i.) The WordPress software may be downloaded from WordPress.org and installed on your server or web hosting account.</p>\n<p>ii.) The WordPress software is open-source, which means you may download and use it for free.</p>\n<p>iii.) You'll need a domain name and web hosting from another trustworthy business to utilize the WordPress.org version of WordPress.</p>\n<p>iv.) If you don't want to install WordPress manually, most web providers offer a WordPress \"fast install\" or \"done-for-you\" installation to assist you in getting started.</p>\n<h2>Headless CMS: The alternative</h2>\n<p>Content, images, HTML, and CSS were all thrown into one massive bucket in the conventional CMS style to manage content. Because the material was intertwined with code, it was hard to reuse.</p>\n<p>As digital platforms have grown, more adaptable solutions have been necessary. Desktop websites, mobile sites, applications, digital displays, conversational interfaces, and more are now being developed by businesses.</p>\n<p>Meanwhile, traditional content management systems (CMS) have fallen behind. Why? Because a CMS organizes material into webpage-oriented frameworks, the same content cannot be adapted to other digital platforms.</p>\n<p>Any back-end content management system in which the content repository \"body\" is isolated or disconnected from the presentation layer \"head\" is known as a headless CMS. Content stored in a headless CMS is provided via APIs to ensure that it is shown consistently across devices.</p>\n<p>Some conventional CMS solutions have a \"headless API\" that lets you deliver content to a different display layer. Because the presentation layer is isolated from the body, this is referred to as \"headless.\"</p>\n<h2>Headless CMS: Benefits &#x26; Drawbacks</h2>\n<h3>The Advantage of the Headless CMS Architecture</h3>\n<ul>\n<li>Multi Channel Content Delivery</li>\n</ul>\n<p>A single content source, such as a product description for an online product, can automatically adapt to its publishing environment and present itself optimally for its destination.</p>\n<ul>\n<li>More Secure</li>\n</ul>\n<p>Because it is distinct from the frontend, headless content provides a far less exposed region of a possible assault.</p>\n<ul>\n<li>Faster Editing Experiences</li>\n</ul>\n<p>In a headless CMS, the separation of code and content makes life easier for content writers and editors, who can ignore the code and focus solely on the material they are responsible for.</p>\n<ul>\n<li>Compatibility</li>\n</ul>\n<p>API-delivered content is easier to integrate, edit, and disseminate, cutting down on time to develop content-driven experiences like websites and applications.</p>\n<ul>\n<li>Rapid Content Deployment (via API)</li>\n</ul>\n<p>Most headless CMS-s use an API-first approach that allows developers to stream in content quickly. You may easily scale or deploy additional channels within a couple of hours.</p>\n<p>Find out how to create GraphQL APIs here​.</p>\n<p><img src=\"https://cdn.sanity.io/images/ay6gmb6r/production/3c59f37c1399b5e98fd9b34c040a8b3c93fed2dd-2853x813.png?w=729&#x26;fm=webp&#x26;fit=max&#x26;auto=format\" alt=\"Create APIs with Hasura to save 30%+ app dev costs\" title=\"Create APIs with Hasura to save 30%+ app dev costs\">[</p>\n<p>](<a href=\"https://www.solutelabs.com/blog/hasura-api-development\">https://www.solutelabs.com/blog/hasura-api-development</a>)</p>\n<ul>\n<li>Scalability</li>\n</ul>\n<p>Instead of implementing multiple, parallel content management system instances, e.g., to support web and mobile channels, a single headless CMS instance can serve unlimited digital channels.</p>\n<ul>\n<li>Flexibility</li>\n</ul>\n<p>Developers, meanwhile, can use all the latest tools and frameworks to bring content experiences to life on any modern platform without being locked into a proprietary language or other limitations of a particular content management system.</p>\n<ul>\n<li>Modular Content</li>\n</ul>\n<p>Since the content in your headless CMS isn't tied to any particular front-end display, it becomes modular, allowing it to be handled and delivered across any applicable touchpoint without having to be duplicated or restructured.</p>\n<ul>\n<li>Choice of media (Video, Audio)</li>\n</ul>\n<p>Headless CMS isn't just about textual content anymore. It now integrates other forms of media like audio and video.</p>\n<h3>The Challenges of Using a Headless CMS</h3>\n<ul>\n<li>Rigid presentation</li>\n</ul>\n<p>Your medium is fixed with a second-screen experience; unlike websites, which allow you to customize zones and resize and rearrange dynamic information, a fixed medium (such as a mobile app container or kiosk) is limited to presenting dynamic content in a defined zone. This means you can add and remove information, but you won't be able to change the positioning or presentation much beyond that.</p>\n<ul>\n<li>Expensive development</li>\n</ul>\n<p>Because a headless CMS lacks a frontend, a development team would require hours to create one, which may be costly and time-consuming.</p>\n<ul>\n<li>Formatting challenges</li>\n</ul>\n<p>To adapt to managing various systems, a headless CMS team would need to extend its knowledge substantially.</p>\n<ul>\n<li>Content Reorganization</li>\n</ul>\n<p>Because this architecture does not include notions such as sitemaps and pages, content editors may need to adapt to the unique content structure on the website or other channels.</p>\n<h3>Use Cases for A Headless CMS</h3>\n<p>Headless CMS can be ideal for the following use cases:</p>\n<p>1. Content-friendly</p>\n<p>It makes content generation, administration, and editing easier for big content teams with daily deadlines.</p>\n<p>Because headless CMS is essentially an API, the content saved in it is easier to handle and integrate with other systems than information kept in a traditional CMS.</p>\n<p>Connecting a headless CMS to any frontend platform is simple, and content teams have more choices with this approach than with traditional CMS's built-in extensions.</p>\n<p>2. Serving the same content on different channels</p>\n<p>Content providers can distribute their work across any channel. They can also repurpose material across several platforms. It will be simple for developers to add a few lines of code to the API whenever a new channel is introduced to the marketing strategy. For both marketers and engineers, this is a typical win-win situation.</p>\n<p>3. Capable of using Javascript frameworks</p>\n<p>Frameworks like VueJs, React, and Angular may be used to create SPAs. This will combine a headless CMS on the backend with Single Page Applications on the frontend to provide enhanced capabilities for content creators.</p>\n<p>Applications include:</p>\n<p>1. Websites &#x26; Web Apps</p>\n<p>2. Products &#x26; Services</p>\n<p>3. Ecommerce Sites</p>\n<h2>WordPress: Benefits &#x26; Drawbacks</h2>\n<h3>Advantages of WordPress</h3>\n<ul>\n<li>Ease of Installation</li>\n</ul>\n<p>The installation procedure for WordPress is straightforward and quick, making it a pleasure to get started. All you have to do now is create your web pages and upload your database. If you're using FTP, just create a database, upload WordPress, and install it to get going.</p>\n<ul>\n<li>Easy Media Management</li>\n</ul>\n<p>To enrich the content on your WordPress website, you may quickly add images, videos, and other media components. It has a drag-and-drop mechanism that lets you quickly drag and drop media content into the uploader to have it posted. You can also use image editing features if necessary.</p>\n<ul>\n<li>Responsive Design</li>\n</ul>\n<p>Because mobile has become the most effective method of getting traffic for company websites, they must be responsive to attract potential customers via the mobile channel. WordPress has a responsive design that assures that your website is optimized well on various devices without requiring you to put in extra effort to create separate web pages for each one.</p>\n<ul>\n<li>Ease of Use</li>\n</ul>\n<p>The most appealing characteristic of WordPress is its simplicity. Because the program has an intuitive interface, anyone can become a professional while playing around with it. It has an integrated dashboard that allows users to create new pages, articles, or categories, modify themes and settings, and much more. Because the open-source platform is free, it is a cost-effective alternative.</p>\n<ul>\n<li>Lots of Theme Options</li>\n</ul>\n<p>Themes determine a site's appearance and navigation. WordPress offers a variety of theme choices that may be modified to meet specific company needs. Users may download themes based on their needs and experiment to create attractive websites that reflect their company's brand with a similar online presence.</p>\n<ul>\n<li>Availability of Plugins</li>\n</ul>\n<p>This platform's bedrock is made up of plugins. Users may modify the site and add the required features and functions by using plugins. Installing a plugin is all that is needed to add a new feature to the site. Surprisingly, there are many of them, and most of them are either free or reasonably priced.</p>\n<ul>\n<li>E-commerce-friendly</li>\n</ul>\n<p>WooCommerce, a free WordPress eCommerce plugin, allows you to create visually beautiful and feature-rich e-commerce stores. WooCommerce is a sophisticated e-commerce system that integrates easily with WordPress and provides shop owners and developers total flexibility over how to sell their products online.</p>\n<ul>\n<li>Minimum Coding Required</li>\n</ul>\n<p>The necessity for coding is reduced to a minimum with WordPress since the CMS comes with various user-friendly features that allow you to do a lot without putting in a lot of effort. Content management, draft creation, post revision, media insertion, and publication planning may all be done with little to no code.</p>\n<h3>Challenges of WordPress</h3>\n<ul>\n<li>Additional Features Require Lots of Plugins</li>\n</ul>\n<p>When you buy a design template, you usually get entirely created website pages that need to be customized with your branded content.</p>\n<p>If your agency wants to add some more features to your website, it will have to look for plugins on WordPress. Some plugins are free, while others cost money. Often the plugins discovered are obsolete and no longer in use.</p>\n<p>If you want to embed your Instagram feed on your website, for instance, you'll need to download a plugin called InstaWidget.</p>\n<p>The plugins would have to be installed, managed, and updated by your agency. This is tough to handle and seldom happens with agencies.</p>\n<ul>\n<li>The Updates Keep Pouring In</li>\n</ul>\n<p>Remember that things are continuously evolving in the digital era to enrich and enhance the user experience.</p>\n<p>Your firm would have to keep checking your website's dashboard to determine whether your theme or plugins needed to be updated regularly. This is something your team may overlook due to other initiatives that need to be examined and updated frequently.</p>\n<p>Remember that with all technological improvements, there will be bugs and mistakes. Your site may encounter faulty links or even crash.</p>\n<ul>\n<li>Slow-Loading Pages</li>\n</ul>\n<p>WordPress is still a sluggish platform due to all of the additional plugins, oversaturated databases, and codebases.</p>\n<p>However, those aren't the only factors that might cause your website to load slowly. Your website's performance might be affected by large pictures, a lot of text on a page, and unstable hosting.</p>\n<p>Your website's page speed is critical. You want a quick-loading website so that your visitors don't get frustrated and leave, which might cost you sales because they won't see what you have to offer.</p>\n<ul>\n<li>Poor SEO Ranking</li>\n</ul>\n<p>WordPress only includes a few SEO tools in its packages, which are insufficient to help you rank in Google.</p>\n<p>If you want to get the most out of your SEO efforts, you'll need more powerful tools and technology to compete with other businesses in a crowded market.</p>\n<p>Furthermore, you will want a third-party targeting thousands of relevant keywords rather than just a few, which can be a hassle.</p>\n<ul>\n<li>Your Website Might Go Down Without Notice</li>\n</ul>\n<p>Websites might go down for a variety of reasons and without warning.</p>\n<p>You might not know your site is unavailable if you aren't paying closely. It might be down for a few hours or perhaps days, causing significant disruption to your company operation.</p>\n<p>Then you'll have to pay a company to assist you in getting it back up, which is another expenditure you don't want to incur.</p>\n<ul>\n<li>Flimsy Security</li>\n</ul>\n<p>Your website, like anything else on the internet, is vulnerable to being hacked and spammed.</p>\n<p>WordPress is a frequent target for hackers because of its popularity. Even if your firm installs all of WordPress' security plugins, it won't be enough to keep your site safe.</p>\n<p>If you have a blog area that enables comments or a contact us form, your website will likely get spammed. And going through the comments and emails might take a long time.</p>\n<p>Any website flaw might harm your reputation and even distribute malware to your users.</p>\n<h3>Use Cases for WordPress</h3>\n<p>A WP framework is best used for:</p>\n<p>1. Blogs</p>\n<p>WordPress began as a blogging platform and grew into a comprehensive content management system. Tens of millions of blogs now use WordPress to post and curate content. Large online magazines like TechCrunch and Time use WordPress to power their sites; in some ways, they're classic blogs with many front-end and back-end customization.</p>\n<p>2. Entertainment</p>\n<p>Many comic-book websites and tv-channel websites like WGN TV are built on WordPress.</p>\n<p>3. Educational Institutions</p>\n<p>WordPress is a content management system; however, because of the system's flexibility and control, we can construct almost any type of website with it. Take Georgia State University's website, for instance.</p>\n<p>4. Communities</p>\n<p>WordPress has been used to create several community websites that may be seen online. Fresh Apps is a good example; while it appears to be a standard website, it has about 40,000 registered individuals who contribute to the published apps by making them \"fresh.\" This is only possible if the user is logged in, demonstrating the community component that WordPress can offer to your website.</p>\n<p>5. Business</p>\n<p>Do you create software, tools, or apps? To build a company website, you'll need a website foundation. You may easily configure your WordPress installation to seem like a professional company website if you have an adequate understanding of how front-end technology works, as seen in the Raven Tools site!</p>\n<h2>WordPress as a Headless CMS: Decoupled or client-side development</h2>\n<p>Headless WordPress is a type of web app development that is sometimes referred to as decoupled or client-side development. It uses WordPress for content management and a custom frontend stack to show that content to site visitors. While there are numerous advantages to a site created using headless WordPress, one of the most important is decoupling content editing teams and programmers.</p>\n<p>With Headless WordPress, the branding or content team may continue to use their familiar WordPress interface. In contrast, the development team can utilize their favorite tools, such as React and GraphQL, in a familiar Git workflow.</p>\n<p>In other words, the app's interface is built &#x26; controlled by the client --- usually on a browser --- rather than on the server. The interface is created using material received from WordPress by a JavaScript application running in the browser.</p>\n<p>WordPress's head, its PHP-based front-end interface, is circumvented in a somewhat macabre metaphor, leaving the body (the CMS itself) on the server, managed remotely by an external program.</p>\n<p>How does it work?</p>\n<p>A client-side web app and a server-side CMS need to communicate with each other. That is where APIs come in. When an application asks for information or tells other software what to do, it communicates via an API.</p>\n<p>WordPress features a REST API, a web-based API that allows the program to communicate with it using HTTP web addresses called endpoints via the internet. Endpoints resemble the web addresses we use to access websites every day. They allow a variety of requests, including GET requests for retrieving information, POST requests for submitting information, and so on.</p>\n<p>WordPress, for instance, offers a \"posts\" endpoint that looks something like this:</p>\n<p><a href=\"https://example.com/wp-json/wp/v2/posts\">https://example.com/wp-json/wp/v2/posts</a>​</p>\n<p>When software makes a GET call to a WordPress site's \"posts\" endpoint, it gets a list of posts and related information back.</p>\n<h3>Possible drawbacks of a Headless WordPress:</h3>\n<p>1.) There isn't a WYSIWYG editor</p>\n<p>You will forfeit your live preview option if you use an utterly headless approach. You won't be able to quickly test what the user would see on the front end.</p>\n<p>2.) Programming skills are required</p>\n<p>You'd need a front-end coder now if you didn't have one before. To get the most out of a headless system, you'll need some more sophisticated libraries too.</p>\n<p>3.) More upkeep is required</p>\n<p>This is especially true in a disconnected setup. You may wind up with two systems to manage, especially in terms of security and upgrades.</p>\n<p>4.) Credentialing will be more stringent</p>\n<p>Users must be credentialed differently in a headless CMS than in a linked CMS. This might be a time-consuming process, but it does result in a more secure workplace.</p>\n<h3>Use Cases for a WordPress Headless CMS</h3>\n<p>A WP Headless CMS is best used for</p>\n<p>1.) Cross-Platform Publishers</p>\n<p>Websites are no longer considered independent platforms. Between social media, applications, and even other websites, there is a network of links, and automation keeps everything operating smoothly. You may now publish anything and have it distributed instantaneously across countless different platforms.</p>\n<p>Multi-channel publishing is a time-saving strategy used by large internet enterprises. Here are a few instances of what you might be able to do:</p>\n<ul>\n<li>Add items to your website as well as online merchants such as Amazon and eBay.</li>\n<li>Provide material to your partners' websites.</li>\n<li>Send a message to your email subscribers informing them of a new post.</li>\n<li>When you publish recent blog articles or pages, you may immediately share them on social networking.</li>\n<li>Save and organize material in preparation for actual printing.</li>\n<li>Use the Internet of Things to your advantage (smart devices).</li>\n</ul>\n<p>The REST API, which links your WordPress back end to other apps, allows you to do all of this. An API is just an interface, similar to a controller that you can configure to govern how your server handles data. Now that WordPress is decoupled from its front end, you may use this controller to govern what platforms your site links to and what it does with your data.</p>\n<p>For example, if you write a blog post on WordPress, you may set up REST to take that article and publish it on a separate site. It requires some setup, but once it's up and running, everything happens on its own.</p>\n<p>2.) App Building</p>\n<p>One of the most well-known applications of headless WordPress's cross-platform features is the ability to operate a complete app using simply a website and the REST API. This is an excellent method to feed an application with content, whether a web app or a mobile app.</p>\n<p>This is nearly difficult with conventional WordPress. A frontend website is inextricably tied to your back end. This also implies you'll have to use PHP (no mobile apps and no cross-platform frameworks like React).</p>\n<p>When you detach it, you may move the content in your back end wherever you want, and it will update immediately on your applications. You are free to use whatever coding language you choose. You're no longer confined to PHP and Javascript. You're ready to go right after you've connected your headless WordPress instance to a mobile app.</p>\n<p>Aside from developing an app, there is a slew of other inventive uses for this functionality. You aren't restricted to smartphone apps, for example. There are also web applications. There are different online apps to consider. You could even connect WordPress to your in-store kiosk application to automatically keep its product lists up to date!</p>\n<p>Please remember that because Gutenberg is developed using React, you can integrate that into your project.</p>\n<p>3.) e-Commerce</p>\n<p>Let's take a look at one specific headless option: You may leverage an existing eCommerce platform, such as Shopify, to create a complete flow that handles the whole checkout process, or you can use Shopify's headless option.</p>\n<ul>\n<li>Because your design will rely mainly on Shopify's templates and out-of-the-box capabilities in the first scenario, modifying the checkout procedure will be doable but restricted.</li>\n<li>In the latter instance, you may design your checkout flow as you want, and Shopify will only handle the money transaction.</li>\n</ul>\n<p>The main difference is that with the headless option, you'll have to create every view your user sees. If it seems like a pain with no benefit, a headless solution is probably not for you.</p>\n<p>A team that requires the headless version will appreciate the flexibility this gives. Your design will be unrestricted, and you'll have complete control over every pixel of every viewpoint. You'll have full control over all the code running on your users' devices, allowing you to track, optimize, and accelerate almost every interaction.</p>\n<p>At the same time, you're still entrusting transaction processing to your headless eCommerce solution, allowing you to make use of their backend system.</p>\n<p>You can find some examples of headless e-commerce websites <a href=\"https://www.solutelabs.com/blog/top-10-headless-ecommerce-websites-built-on-jamstack\">here</a>​</p>\n<h2>Popular Headless CMS's:</h2>\n<p>There are many popular headless CMS's in the market right now, like Magnolia, Agility, or even Contentful. But Sanity takes the cake in terms of fame. It is arguably one of the most popular Headless CMS's. Hence, it only fits that we talk about it.</p>\n<h3>Sanity: A Headless CMS</h3>\n<p>Sanity Studio is a headless real-time CMS built with JavaScript and React that you may modify.</p>\n<ul>\n<li>It has efficient editing and a quick UI for complex fields.</li>\n<li>It works on tiny screens and is responsive.</li>\n<li>Customizable input components and plug-in architecture</li>\n<li>Personalize your look with your images.</li>\n<li>JavaScript could be used to provide field validations, arrange documents, and establish starting values in an advanced block editor for structured content.</li>\n</ul>\n<h4>Reasons to opt for Sanity.</h4>\n<ul>\n<li><em>Easy to get started with</em></li>\n</ul>\n<p>Sanity.io is easy to get started by simply installing the CLI from npm and creating a new project. Sanity's starter projects, on the other hand, will help you get started in seconds with a pre-configured Sanity Studio and a functioning front-end with a variety of frameworks to pick from, all deployed to Netlify and with source code on GitHub.</p>\n<ul>\n<li><em>Better APIs</em></li>\n</ul>\n<p>The main advantage of a headless CMS is its API-first design, which allows you to access content via APIs.</p>\n<p>For reading, writing, querying, and patching documents, Sanity provides two robust APIs:</p>\n<ul>\n<li>The live, uncached API in api.sanity.io.</li>\n<li>The CDN-distributed, cached API in apicdn.sanity.io.</li>\n</ul>\n<p>To query your material, Sanity now supports the use of GROQ and GraphQL APIs. The platform's Data Store is hosted in the cloud and may be reached through the Sanity API, either through Sanity's client libraries or directly over the HTTP API.</p>\n<ul>\n<li><em>Better editing tools</em></li>\n</ul>\n<p>Sanity's editor, often known as the Sanity Studio, is an open-source program that lets you build content models using basic JavaScript. Sanity Studio is a single-page React.js app that you may edit or expand with your React.js components. Its sophisticated capabilities allow you to change your editors' processes.</p>\n<p>Sanity Studio includes fundamental features such as Block Content, Structure Builder, and a Dashboard plugin in addition to customization.</p>\n<ul>\n<li><em>Headless content models that are easy to use</em></li>\n</ul>\n<p>Although fundamental JavaScript expertise is required to get started with Sanity, it is not difficult to locate someone knowledgeable with the popular online programming language. Content writers, graphic and interaction designers, and technology specialists may cooperate on the information architecture using Sanity. Front-end developers can save time by using APIs to access content fields immediately.</p>\n<ul>\n<li><em>Mature Tech Stack</em></li>\n</ul>\n<p>Because Sanity is a cloud-hosted CMS with a real-time content studio, all data is instantaneously synchronized. PostgreSQL, ElasticSearch, and JavaScript, and lightning-fast React form the foundation of the system. It saves logical object structures rather than HTML, XML, or rich text in the database. For example, you don't have to read HTML if you want Alexa to read from your text fields. Sanity comes with well-maintained JavaScript, HTML, and PHP clients, allowing you to get up and running quickly with your preferred front-end architecture.</p>\n<h4>Some Cool Projects Powered by Sanity</h4>\n<ul>\n<li><em>Agnes</em></li>\n</ul>\n<p>A sophisticated rental real estate site developed with Gatsby, Sanity, and Shopify features a headless Shopify shop that gets listing data through API.</p>\n<p>Gatsby was an excellent choice for this site, including content from Sanity, Shopify, and their client's real estate rental platform called Entrata.</p>\n<p>The Sanity Studio is designed to handle many building and development sites while simultaneously serving as the content management system for the developer's corporate website. Editors can evaluate their modifications in real-time before they are published, thanks to a feature called real-time draft previewing.</p>\n<p>Homepage editing environment</p>\n<ul>\n<li><em>Jamstack Explorers</em></li>\n</ul>\n<p>Jamstack Explorers is a free learning tool built by the Netlify team to help you navigate the incredible Jamstack ecosystem.</p>\n<p>Jamstack Explorers is a platform to learn more about the modern web's evolving benchmarks. Popular frameworks, new tools, APIs, and Netlify's capabilities and workflows are all covered. Phil Hawksworth, Cassidy Williams, Debbie O'Brien, Ekene Eze, and others provide thorough courses on these topics.</p>\n<p>The project features a user login feature that allows users to keep track of their progress (and earn certificates!) as they go. It also features a custom dashboard for all Jamstack Explorer users.</p>\n<p><img src=\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0OCA0OCIgd2lkdGg9IjQ4cHgiIGhlaWdodD0iNDhweCI+PGxpbmVhckdyYWRpZW50IGlkPSJQZ0JfVUhhMjloMFRwRlZfbW9KSTlhIiB4MT0iOS44MTYiIHgyPSI0MS4yNDYiIHkxPSI5Ljg3MSIgeTI9IjQxLjMwMSIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2Y0NGY1YSIvPjxzdG9wIG9mZnNldD0iLjQ0MyIgc3RvcC1jb2xvcj0iI2VlM2Q0YSIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iI2U1MjAzMCIvPjwvbGluZWFyR3JhZGllbnQ+PHBhdGggZmlsbD0idXJsKCNQZ0JfVUhhMjloMFRwRlZfbW9KSTlhKSIgZD0iTTQ1LjAxMiwzNC41NmMtMC40MzksMi4yNC0yLjMwNCwzLjk0Ny00LjYwOCw0LjI2N0MzNi43ODMsMzkuMzYsMzAuNzQ4LDQwLDIzLjk0NSw0MAljLTYuNjkzLDAtMTIuNzI4LTAuNjQtMTYuNDU5LTEuMTczYy0yLjMwNC0wLjMyLTQuMTctMi4wMjctNC42MDgtNC4yNjdDMi40MzksMzIuMTA3LDIsMjguNDgsMiwyNHMwLjQzOS04LjEwNywwLjg3OC0xMC41NgljMC40MzktMi4yNCwyLjMwNC0zLjk0Nyw0LjYwOC00LjI2N0MxMS4xMDcsOC42NCwxNy4xNDIsOCwyMy45NDUsOHMxMi43MjgsMC42NCwxNi40NTksMS4xNzNjMi4zMDQsMC4zMiw0LjE3LDIuMDI3LDQuNjA4LDQuMjY3CUM0NS40NTEsMTUuODkzLDQ2LDE5LjUyLDQ2LDI0QzQ1Ljg5LDI4LjQ4LDQ1LjQ1MSwzMi4xMDcsNDUuMDEyLDM0LjU2eiIvPjxwYXRoIGQ9Ik0zMi4zNTIsMjIuNDRsLTExLjQzNi03LjYyNGMtMC41NzctMC4zODUtMS4zMTQtMC40MjEtMS45MjUtMC4wOTNDMTguMzgsMTUuMDUsMTgsMTUuNjgzLDE4LDE2LjM3Ngl2MTUuMjQ4YzAsMC42OTMsMC4zOCwxLjMyNywwLjk5MSwxLjY1NGMwLjI3OCwwLjE0OSwwLjU4MSwwLjIyMiwwLjg4NCwwLjIyMmMwLjM2NCwwLDAuNzI2LTAuMTA2LDEuMDQtMC4zMTVsMTEuNDM2LTcuNjI0CWMwLjUyMy0wLjM0OSwwLjgzNS0wLjkzMiwwLjgzNS0xLjU2QzMzLjE4NywyMy4zNzIsMzIuODc0LDIyLjc4OSwzMi4zNTIsMjIuNDR6IiBvcGFjaXR5PSIuMDUiLz48cGF0aCBkPSJNMjAuNjgxLDE1LjIzN2wxMC43OSw3LjE5NGMwLjY4OSwwLjQ5NSwxLjE1MywwLjkzOCwxLjE1MywxLjUxM2MwLDAuNTc1LTAuMjI0LDAuOTc2LTAuNzE1LDEuMzM0CWMtMC4zNzEsMC4yNy0xMS4wNDUsNy4zNjQtMTEuMDQ1LDcuMzY0Yy0wLjkwMSwwLjYwNC0yLjM2NCwwLjQ3Ni0yLjM2NC0xLjQ5OVYxNi43NDRDMTguNSwxNC43MzksMjAuMDg0LDE0LjgzOSwyMC42ODEsMTUuMjM3eiIgb3BhY2l0eT0iLjA3Ii8+PHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE5LDMxLjU2OFYxNi40MzNjMC0wLjc0MywwLjgyOC0xLjE4NywxLjQ0Ny0wLjc3NGwxMS4zNTIsNy41NjhjMC41NTMsMC4zNjgsMC41NTMsMS4xOCwwLDEuNTQ5CWwtMTEuMzUyLDcuNTY4QzE5LjgyOCwzMi43NTUsMTksMzIuMzEyLDE5LDMxLjU2OHoiLz48L3N2Zz4=\" alt=\"Youtube Play\"><img src=\"https://img.youtube.com/vi/PPtmowJoe3s/sddefault.jpg\" alt=\"video\"></p>\n<ul>\n<li><em>Figma</em></li>\n</ul>\n<p>Figma is a web-based graphics editing and UI design application. It may be used for various graphic design tasks, including wireframing websites, building mobile app interfaces, prototyping designs, and creating social media posts.</p>\n<p>Figma is not like other graphics editing software. It works primarily because it is browser-based. This means you can access your projects and begin designing from any computer or platform without purchasing additional licenses or software. One of the biggest pluses is that it allows designers to collaborate online on the same project in real-time.</p>\n<p>Sanity UI was designed to allow users to design directly in the browser using code.</p>\n<p>Arcade, an online sandbox where you can mix and match all of the library's elements and see the results in real-time, is the simplest method to play with it.</p>\n<p>Sanity also offers a fully-featured Figma library comprising all of the components, icons, font styles, and effects included in the project if you want to prototype your Sanity UI experiences with design tools.</p>\n<ul>\n<li><em>Middlesbrough Town Centre App</em></li>\n</ul>\n<p>The app was built using Flutter, Sanity, and Figma to help a small town in the UK called Middlesbrough.</p>\n<p>To encourage business, the Visit Middlesbrough app contains information about the town center's stores, restaurants, and cafés. To promote a regulated return to the town center, the app includes crucial travel and safety information.</p>\n<p>By showing the quietest periods for footfall, live data can assist vulnerable persons in planning their visits.</p>\n<p>The app's shopping area is linked to Google Maps for door-to-door navigation, and users will have the latest updates from the Council at their disposal, receiving up-to-date information directly to their screens.</p>"},{"url":"/docs/","relativePath":"docs/index.md","relativeDir":"docs","base":"index.md","name":"index","frontmatter":{"title":"Docs","seo":{"title":"Web Dev Hub","description":"Application, Back-end, Bootstrap, Browser, Caching, Code, CSS, Content Management System (CMS) , Cookies, Domain Name ,Frameworks, Front-end, JavaScript, Python","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Web Dev Hub","keyName":"property"},{"name":"og:description","value":"Docs Home","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Web Dev Hub"},{"name":"twitter:description","value":"Docs Home"}]},"template":"docs","weight":900,"excerpt":"docs quick reference"},"html":"<h1>Go To <a href=\"./docs/sitemap/\">SITEMAP --></a></h1>\n<hr>\n<h1>Docs</h1>\n<h1>Search Blog</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    class=\"inner\" src=\"https://random-list-of-embedable-content.vercel.app/blog-search.html#gsc.tab=0\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<hr>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    class=\"inner\" src=\"https://docs42.netlify.app/#C:/MY-WEB-DEV/__NEW_GIT/DOCS/docs-collection\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<h1>Gitpod Docs</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    class=\"inner\" src=\"https://archive-42.github.io/my-docs-gitpod-html/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<hr>\n<h2>Doc Websites &#x26; Repos</h2>\n<ul>\n<li><a href=\"https://github.com/bgoonz/PYTHON_PRAC\">Python Practice</a></li>\n<li><a href=\"https://lambda-resources.netlify.app/\">Lambda Bootcamp Website</a></li>\n<li><a href=\"https://github.com/bgoonz/React_Notes_V3\">React Notes</a></li>\n<li><a href=\"https://github.com/bgoonz/Project-Showcase\">Project Showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">Data Structures &#x26; Algorithms</a></li>\n<li><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\">Lambda Site Static Content Server</a></li>\n<li><a href=\"https://github.com/bgoonz/mini-project-showcase\">Mini-Project Showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/Useful-Snippets-js\">Useful Snippets</a></li>\n<li><a href=\"https://github.com/bgoonz/Markdown-Templates\">Markdown Templates</a></li>\n<li><a href=\"https://github.com/bgoonz/zumzi-chat-messenger\">Zumzi Video Conferencing App (mesibo api backend)</a></li>\n</ul>"},{"url":"/docs/about/eng-portfolio/","relativePath":"docs/about/eng-portfolio.md","relativeDir":"docs/about","base":"eng-portfolio.md","name":"eng-portfolio","frontmatter":{"title":"Engineering Portfolio","weight":0,"seo":{"title":"Engineering Portfolio","description":"This is an Engineering Portfolio page that contains a powerpoint portfolio of my work as an electrical engineer!","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Engineering Portfolio","keyName":"property"},{"name":"og:description","value":"This is the Engineering Portfolio page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Engineering Portfolio"},{"name":"twitter:description","value":"This is the Engineering Portfolio page"}]},"template":"docs"},"html":"<h1>Portfolio</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://onedrive.live.com/embed?cid=D21009FDD967A241&resid=D21009FDD967A241%21940107&authkey=ABhIgEQ32UYlvMU\" width=\"1000\" height=\"800\" frameborder=\"0\" scrolling=\"no\">\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/bold-surf-xfsiq?fontsize=14&hidenavigation=1&theme=dark&view=preview\"\nstyle=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\ntitle=\"bold-surf-xfsiq\"\n ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n>\n</iframe>\n<br>"},{"url":"/docs/showcase/","relativePath":"docs/showcase.md","relativeDir":"docs","base":"showcase.md","name":"showcase","frontmatter":{"title":"Showcase","sections":[{"section_id":"hero","type":"section_hero","title":"Showcase","image":"images/spin-cube.gif","content":"Some of my more engaging projects!\n"},{"section_id":"showcase","type":"section_grid","col_number":"three","grid_items":[{"title":"Git HTML PREVIEW","title_url":"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL","image":"images/futuristic-mars.gif","content":"Preview html files by pasting their url into the search bar **Access-Control-Allow-Origin Header When Site A tries to fetch content from Site B**\n","actions":[{"label":"Live Site","url":"/https://ds-algo-official-c3dw6uapg-bgoonz.vercel.app/","style":"icon","icon_class":"github","new_window":true,"no_follow":false,"type":"action"}],"image_alt":"git html preview"},{"title":"Guitar Effects Automation Using Subsequence Dynamic Time Warping","title_url":"https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering","image":"images/curious-europa.gif","content":"**Modified subsequence dynamic time warping feature detection using pure data implemented in python**\n","actions":[{"label":"Slide Show","url":"https://1drv.ms/p/s!AkGiZ9n9CRDSpY88x407JwfEKNrDxg?e=faHSx9","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}]},{"title":"Data Structures Interactive Learning Hub","title_url":"https://ds-algo-official-c3dw6uapg-bgoonz.vercel.app/","image":"images/ds-algo.gif","content":"**Big O notation is the language we use for talking about how long an algorithm takes to run. It's how we compare the efficiency of different approaches to a problem.**\n","actions":[{"label":"Live Site","url":"https://github.com/bgoonz/DS-ALGO-OFFICIAL","style":"icon","icon_class":"github","new_window":true,"no_follow":false,"type":"action"}]},{"title":"Learning Redux","title_url":"https://learning-redux42.netlify.app/","image_alt":"image of","content":"***React Redux provides a pair of custom React hooks that allow your React components to interact with the Redux store.***\n","actions":[{"label":"Website","url":"https://learning-redux42.netlify.app/","style":"icon","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}],"type":"grid_item","image":"images/best-birch.gif"},{"title":"Mihir-Beg-Music.com","title_url":"https://panoramic-eggplant-452e4.netlify.app/","image":"images/mihir.png","content":"Artist Showcase & Podcasting Site\n","actions":[{"label":"Live Site","url":"https://panoramic-eggplant-452e4.netlify.app/","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}]},{"title":"Aux Blog w NextJS","title_url":"https://bgoonz-blog-v3-0.netlify.app/","image_alt":"get in touch","content":"**Here lives my alternate/backup blog site!**\n","actions":[{"label":"git repo","url":"https://github.com/bgoonz/alternate-blog-theme","style":"icon","icon_class":"github","new_window":true,"no_follow":false,"type":"action"}],"type":"grid_item","image":"images/-form.png"},{"title":"Potluck Planner","title_url":"https://potluck-landing.netlify.app/","image_alt":"image of","content":"## Potluck Planner If you have ever tried to organize a potluck through text messages, online to-do lists or spreadsheets, you'll understand why this app is essential.In the world of social gatherings and potlucks the \"Potluck Planner\" is king. This is your place for all things pot luck.\n","actions":[],"type":"grid_item","image":"images/potluck-planner.JPG"},{"title":"Zumzi Video Conferencing","title_url":"https://github.com/bgoonz/zumzi-chat-messenger","image_alt":"video chat","content":"**Features:   Live Streaming, Screen Sharing, Fine control over all video & audio parameters and user permissions, Supports video streaming at various resolutions: Standard, HD, FHD and 4K, Group Chat, One-to-One chat, Invite Participants**\n","actions":[{"label":"Live Site","url":"https://goofy-perlman-0f61df.netlify.app/","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}],"type":"grid_item","image":"images/energetic-sunflower.png"},{"title":"Web Audio Workstation","title_url":"web audio workstation","image_alt":"image of web audio workstation","content":"Made using jQuery and Vanilla JS\n","actions":[{"label":"Go To Live Site","url":"https://mihirbegmusiclab.netlify.app/","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"},{"label":"Github Repo","url":"https://github.com/bgoonz/MihirBegMusicLab","style":"link","icon_class":"dev","new_window":true,"no_follow":false,"type":"action"}],"type":"grid_item","image":"images/mihir.jpg"}]}],"seo":{"title":"Showcase","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Showcase","keyName":"property"},{"name":"og:description","value":"project showcase","keyName":"property"},{"name":"og:image","value":"images/My Post-4ecb169f.png","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"Showcase"},{"name":"twitter:description","value":"This is the showcase page"},{"name":"twitter:image","value":"images/5.jpg","relativeUrl":true}],"description":"Git HTML PREVIEW, Guitar Effects, Data Structures, Redux, Podcast Blog, Contact Form, Potluck Planner, Video Conferencing, Web Audio Workstation"},"template":"advanced"},"html":""},{"url":"/docs/sitemap/","relativePath":"docs/sitemap.md","relativeDir":"docs","base":"sitemap.md","name":"sitemap","frontmatter":{"title":"Navigation","weight":900,"excerpt":"Navigation quick reference","seo":{"title":"Web Dev Hub","description":"This website contains docs, blogs, a personal portfolio spread out across multiple pages as well as interactive animations and tools.","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Web Dev Hub","keyName":"property"},{"name":"og:description","value":"Navigation Home","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Web Dev Hub"},{"name":"twitter:description","value":"Navigation Home"},{"name":"og:image","value":"images/background.gif","keyName":"property","relativeUrl":true}]},"template":"docs"},"html":"<h1><a href=\"https://bgoonz-blog.netlify.app/\"><strong>➡️🏠🏠HOME🏠🏠⬅️</strong></a></h1>\n<details>\n<summary>Click Here To See Most Up To Date Sitemap</summary>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app//\">https://bgoonz-blog.netlify.app//</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/\">https://bgoonz-blog.netlify.app/docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/\">https://bgoonz-blog.netlify.app/blog/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app//admin/\">https://bgoonz-blog.netlify.app//admin/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/\">https://bgoonz-blog.netlify.app/docs/faq/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/css/\">https://bgoonz-blog.netlify.app/docs/css/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/\">https://bgoonz-blog.netlify.app/docs/about/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/\">https://bgoonz-blog.netlify.app/docs/audio/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/\">https://bgoonz-blog.netlify.app/docs/career/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/\">https://bgoonz-blog.netlify.app/docs/python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/\">https://bgoonz-blog.netlify.app/docs/js-tips/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/\">https://bgoonz-blog.netlify.app/docs/content/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app//docs/career/\">https://bgoonz-blog.netlify.app//docs/career/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/\">https://bgoonz-blog.netlify.app/docs/projects/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/\">https://bgoonz-blog.netlify.app/docs/overflow/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/css/\">https://bgoonz-blog.netlify.app/docs/docs/css/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/\">https://bgoonz-blog.netlify.app/docs/quick-ref/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/\">https://bgoonz-blog.netlify.app/docs/community/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/\">https://bgoonz-blog.netlify.app/docs/reference/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/\">https://bgoonz-blog.netlify.app/docs/tutorials/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/bash/\">https://bgoonz-blog.netlify.app/docs/docs/bash/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/jsx/\">https://bgoonz-blog.netlify.app/docs/react/jsx/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/typescript/\">https://bgoonz-blog.netlify.app/docs/typescript/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/\">https://bgoonz-blog.netlify.app/docs/javascript/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/demo/\">https://bgoonz-blog.netlify.app/docs/react/demo/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/quiz/\">https://bgoonz-blog.netlify.app/docs/react/quiz/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/any/\">https://bgoonz-blog.netlify.app/docs/js-tips/any/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/var/\">https://bgoonz-blog.netlify.app/docs/js-tips/var/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/abs/\">https://bgoonz-blog.netlify.app/docs/js-tips/abs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/map/\">https://bgoonz-blog.netlify.app/docs/js-tips/map/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/all/\">https://bgoonz-blog.netlify.app/docs/js-tips/all/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/contact/\">https://bgoonz-blog.netlify.app/docs/faq/contact/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/v8/\">https://bgoonz-blog.netlify.app/docs/overflow/v8/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2/\">https://bgoonz-blog.netlify.app/docs/react/react2/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/eval/\">https://bgoonz-blog.netlify.app/docs/js-tips/eval/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/sitemap/\">https://bgoonz-blog.netlify.app/docs/docs/sitemap/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/resume/\">https://bgoonz-blog.netlify.app/docs/about/resume/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/npm/\">https://bgoonz-blog.netlify.app/docs/articles/npm/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/url/\">https://bgoonz-blog.netlify.app/docs/articles/url/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/httrack/\">https://bgoonz-blog.netlify.app/docs/tips/httrack/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sort/\">https://bgoonz-blog.netlify.app/docs/js-tips/sort/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/plug-ins/\">https://bgoonz-blog.netlify.app/docs/faq/plug-ins/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bind/\">https://bgoonz-blog.netlify.app/docs/js-tips/bind/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/date/\">https://bgoonz-blog.netlify.app/docs/js-tips/date/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acos/\">https://bgoonz-blog.netlify.app/docs/js-tips/acos/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/this/\">https://bgoonz-blog.netlify.app/docs/js-tips/this/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/archive/\">https://bgoonz-blog.netlify.app/docs/docs/archive/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/readme/\">https://bgoonz-blog.netlify.app/docs/about/readme/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/big-o/\">https://bgoonz-blog.netlify.app/docs/ds-algo/big-o/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/heaps/\">https://bgoonz-blog.netlify.app/docs/ds-algo/heaps/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acosh/\">https://bgoonz-blog.netlify.app/docs/js-tips/acosh/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/glossary/\">https://bgoonz-blog.netlify.app/docs/docs/glossary/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/const/\">https://bgoonz-blog.netlify.app/docs/js-tips/const/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/graph/\">https://bgoonz-blog.netlify.app/docs/ds-algo/graph/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/gists/\">https://bgoonz-blog.netlify.app/docs/content/gists/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array/\">https://bgoonz-blog.netlify.app/docs/js-tips/array/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/markdown/\">https://bgoonz-blog.netlify.app/docs/docs/markdown/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/http/\">https://bgoonz-blog.netlify.app/docs/overflow/http/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/every/\">https://bgoonz-blog.netlify.app/docs/js-tips/every/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/links/\">https://bgoonz-blog.netlify.app/docs/projects/links/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/storybook/\">https://bgoonz-blog.netlify.app/docs/tips/storybook/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/emmet/\">https://bgoonz-blog.netlify.app/docs/overflow/emmet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/concat/\">https://bgoonz-blog.netlify.app/docs/js-tips/concat/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/airtable/\">https://bgoonz-blog.netlify.app/docs/tools/airtable/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/intrests/\">https://bgoonz-blog.netlify.app/docs/about/intrests/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/object/\">https://bgoonz-blog.netlify.app/docs/js-tips/object/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/reduce/\">https://bgoonz-blog.netlify.app/docs/js-tips/reduce/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/modules/\">https://bgoonz-blog.netlify.app/docs/python/modules/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/psql/\">https://bgoonz-blog.netlify.app/docs/reference/psql/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/import/\">https://bgoonz-blog.netlify.app/docs/js-tips/import/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/clock/\">https://bgoonz-blog.netlify.app/docs/interact/clock/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/html-tags/\">https://bgoonz-blog.netlify.app/docs/docs/html-tags/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/https/\">https://bgoonz-blog.netlify.app/docs/overflow/https/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/string/\">https://bgoonz-blog.netlify.app/docs/js-tips/string/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/bash/\">https://bgoonz-blog.netlify.app/docs/tutorials/bash/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/filter/\">https://bgoonz-blog.netlify.app/docs/js-tips/filter/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/regexp/\">https://bgoonz-blog.netlify.app/docs/js-tips/regexp/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/figma/\">https://bgoonz-blog.netlify.app/docs/projects/figma/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/nodejs/\">https://bgoonz-blog.netlify.app/docs/overflow/nodejs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/foreach/\">https://bgoonz-blog.netlify.app/docs/js-tips/foreach/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/classes/\">https://bgoonz-blog.netlify.app/docs/js-tips/classes/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/examples/\">https://bgoonz-blog.netlify.app/docs/python/examples/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/archive/\">https://bgoonz-blog.netlify.app/docs/content/archive/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/fetch/\">https://bgoonz-blog.netlify.app/docs/quick-ref/fetch/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/recent/\">https://bgoonz-blog.netlify.app/docs/projects/recent/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/snippets/\">https://bgoonz-blog.netlify.app/docs/python/snippets/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/portfolio/\">https://bgoonz-blog.netlify.app/docs/about/portfolio/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/css/css-flexbox/\">https://bgoonz-blog.netlify.app/docs/css/css-flexbox/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/regex-tips/\">https://bgoonz-blog.netlify.app/docs/tips/regex-tips/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/bigo/\">https://bgoonz-blog.netlify.app/docs/javascript/bigo/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nextjs/\">https://bgoonz-blog.netlify.app/docs/articles/nextjs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/functions/\">https://bgoonz-blog.netlify.app/docs/python/functions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/job-search/\">https://bgoonz-blog.netlify.app/docs/about/job-search/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/interview/\">https://bgoonz-blog.netlify.app/docs/career/interview/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/cheatsheet/\">https://bgoonz-blog.netlify.app/docs/react/cheatsheet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-docs/\">https://bgoonz-blog.netlify.app/docs/react/react-docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/vscode/\">https://bgoonz-blog.netlify.app/docs/reference/vscode/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-ds/\">https://bgoonz-blog.netlify.app/docs/python/python-ds/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/modules/\">https://bgoonz-blog.netlify.app/docs/overflow/modules/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/for...of/\">https://bgoonz-blog.netlify.app/docs/js-tips/for...of/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/addition/\">https://bgoonz-blog.netlify.app/docs/js-tips/addition/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/dev-dep/\">https://bgoonz-blog.netlify.app/docs/articles/dev-dep/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/buffers/\">https://bgoonz-blog.netlify.app/docs/articles/buffers/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/git/git-tutorial/\">https://bgoonz-blog.netlify.app/docs/git/git-tutorial/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/regex-in-js/\">https://bgoonz-blog.netlify.app/docs/docs/regex-in-js/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/review/\">https://bgoonz-blog.netlify.app/docs/javascript/review/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/bookmarks/\">https://bgoonz-blog.netlify.app/docs/content/bookmarks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/jamstack/\">https://bgoonz-blog.netlify.app/docs/articles/jamstack/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/ajax-n-apis/\">https://bgoonz-blog.netlify.app/docs/react/ajax-n-apis/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic/\">https://bgoonz-blog.netlify.app/docs/articles/semantic/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bad_radix/\">https://bgoonz-blog.netlify.app/docs/js-tips/bad_radix/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/job-boards/\">https://bgoonz-blog.netlify.app/docs/career/job-boards/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/css/the-box-model/\">https://bgoonz-blog.netlify.app/docs/css/the-box-model/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/ubuntu-setup/\">https://bgoonz-blog.netlify.app/docs/tips/ubuntu-setup/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/decrement/\">https://bgoonz-blog.netlify.app/docs/js-tips/decrement/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/html-spec/\">https://bgoonz-blog.netlify.app/docs/overflow/html-spec/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-router/\">https://bgoonz-blog.netlify.app/docs/react/react-router/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/discrete-fft/\">https://bgoonz-blog.netlify.app/docs/audio/discrete-fft/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-bash/\">https://bgoonz-blog.netlify.app/docs/quick-ref/git-bash/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-repl/\">https://bgoonz-blog.netlify.app/docs/overflow/node-repl/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/html-standard/\">https://bgoonz-blog.netlify.app/docs/docs/html-standard/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/fs-module/\">https://bgoonz-blog.netlify.app/docs/articles/fs-module/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-quiz/\">https://bgoonz-blog.netlify.app/docs/python/python-quiz/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/css/media-querries/\">https://bgoonz-blog.netlify.app/docs/css/media-querries/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/asyncjs/\">https://bgoonz-blog.netlify.app/docs/javascript/asyncjs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/allsettled/\">https://bgoonz-blog.netlify.app/docs/js-tips/allsettled/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/internal-use/\">https://bgoonz-blog.netlify.app/docs/about/internal-use/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-reference/\">https://bgoonz-blog.netlify.app/docs/docs/git-reference/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/os-module/\">https://bgoonz-blog.netlify.app/docs/articles/os-module/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/accessability/\">https://bgoonz-blog.netlify.app/docs/docs/accessability/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/my-websites/\">https://bgoonz-blog.netlify.app/docs/career/my-websites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/cheat-sheet/\">https://bgoonz-blog.netlify.app/docs/python/cheat-sheet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/video-chat/\">https://bgoonz-blog.netlify.app/docs/interact/video-chat/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/privacy-policy/\">https://bgoonz-blog.netlify.app/docs/docs/privacy-policy/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/eng-portfolio/\">https://bgoonz-blog.netlify.app/docs/about/eng-portfolio/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/history-api/\">https://bgoonz-blog.netlify.app/docs/content/history-api/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/resources/\">https://bgoonz-blog.netlify.app/docs/reference/resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/bookmarks/\">https://bgoonz-blog.netlify.app/docs/community/bookmarks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/web-audio-api/\">https://bgoonz-blog.netlify.app/docs/audio/web-audio-api/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bookmarks/\">https://bgoonz-blog.netlify.app/docs/reference/bookmarks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/dev-utilities/\">https://bgoonz-blog.netlify.app/docs/tools/dev-utilities/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/flow-control/\">https://bgoonz-blog.netlify.app/docs/python/flow-control/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/markdown-html/\">https://bgoonz-blog.netlify.app/docs/tools/markdown-html/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/accessibility/\">https://bgoonz-blog.netlify.app/docs/react/accessibility/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-overview/\">https://bgoonz-blog.netlify.app/docs/ds-algo/ds-overview/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/promises/\">https://bgoonz-blog.netlify.app/docs/javascript/promises/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/my-websites/\">https://bgoonz-blog.netlify.app/docs/projects/my-websites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/for-loops/\">https://bgoonz-blog.netlify.app/docs/javascript/for-loops/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-tricks/\">https://bgoonz-blog.netlify.app/docs/quick-ref/git-tricks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/complete-react/\">https://bgoonz-blog.netlify.app/docs/react/complete-react/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/psql-setup/\">https://bgoonz-blog.netlify.app/docs/tutorials/psql-setup/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/video-chat/\">https://bgoonz-blog.netlify.app/docs/community/video-chat/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/variables/\">https://bgoonz-blog.netlify.app/docs/javascript/variables/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites/\">https://bgoonz-blog.netlify.app/docs/interact/other-sites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/project-links/\">https://bgoonz-blog.netlify.app/docs/career/project-links/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-in-depth/\">https://bgoonz-blog.netlify.app/docs/react/react-in-depth/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/all-emojis/\">https://bgoonz-blog.netlify.app/docs/quick-ref/all-emojis/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/part2-pojo/\">https://bgoonz-blog.netlify.app/docs/javascript/part2-pojo/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/no-whiteboarding/\">https://bgoonz-blog.netlify.app/docs/docs/no-whiteboarding/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/quick-links/\">https://bgoonz-blog.netlify.app/docs/quick-ref/quick-links/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/family-promise/\">https://bgoonz-blog.netlify.app/docs/career/family-promise/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/minifiction/\">https://bgoonz-blog.netlify.app/docs/quick-ref/minifiction/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/render-elements/\">https://bgoonz-blog.netlify.app/docs/react/render-elements/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/main-projects/\">https://bgoonz-blog.netlify.app/docs/content/main-projects/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array-methods/\">https://bgoonz-blog.netlify.app/docs/js-tips/array-methods/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-run-cli/\">https://bgoonz-blog.netlify.app/docs/overflow/node-run-cli/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/firebase-hosting/\">https://bgoonz-blog.netlify.app/docs/tips/firebase-hosting/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-modules/\">https://bgoonz-blog.netlify.app/docs/python/python-modules/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-by-example/\">https://bgoonz-blog.netlify.app/docs/ds-algo/ds-by-example/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/clean-code/\">https://bgoonz-blog.netlify.app/docs/javascript/clean-code/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/js-objects/\">https://bgoonz-blog.netlify.app/docs/javascript/js-objects/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/project-list/\">https://bgoonz-blog.netlify.app/docs/projects/project-list/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/nodevsbrowser/\">https://bgoonz-blog.netlify.app/docs/overflow/nodevsbrowser/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/reading-files/\">https://bgoonz-blog.netlify.app/docs/articles/reading-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/async_function/\">https://bgoonz-blog.netlify.app/docs/js-tips/async_function/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/google-cloud/\">https://bgoonz-blog.netlify.app/docs/reference/google-cloud/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic-html/\">https://bgoonz-blog.netlify.app/docs/articles/semantic-html/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/writing-files/\">https://bgoonz-blog.netlify.app/docs/articles/writing-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/how-2-ubuntu/\">https://bgoonz-blog.netlify.app/docs/tutorials/how-2-ubuntu/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects/\">https://bgoonz-blog.netlify.app/docs/projects/mini-projects/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/web-accessibility/\">https://bgoonz-blog.netlify.app/docs/tips/web-accessibility/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/top-10-money-tips/\">https://bgoonz-blog.netlify.app/docs/tips/top-10-money-tips/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/free-code-camp/\">https://bgoonz-blog.netlify.app/docs/ds-algo/free-code-camp/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/installation/\">https://bgoonz-blog.netlify.app/docs/quick-ref/installation/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/node-docs-complete/\">https://bgoonz-blog.netlify.app/docs/docs/node-docs-complete/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sorting-strings/\">https://bgoonz-blog.netlify.app/docs/js-tips/sorting-strings/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/webdev-review/\">https://bgoonz-blog.netlify.app/docs/tutorials/webdev-review/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects2/\">https://bgoonz-blog.netlify.app/docs/projects/mini-projects2/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-lists/\">https://bgoonz-blog.netlify.app/docs/reference/awesome-lists/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/embed-the-web/\">https://bgoonz-blog.netlify.app/docs/reference/embed-the-web/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/arrow_functions/\">https://bgoonz-blog.netlify.app/docs/js-tips/arrow_functions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bash-commands/\">https://bgoonz-blog.netlify.app/docs/reference/bash-commands/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/common-modules/\">https://bgoonz-blog.netlify.app/docs/articles/common-modules/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-search/\">https://bgoonz-blog.netlify.app/docs/reference/github-search/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/vscode-themes/\">https://bgoonz-blog.netlify.app/docs/quick-ref/vscode-themes/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-static/\">https://bgoonz-blog.netlify.app/docs/reference/awesome-static/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/await-keyword/\">https://bgoonz-blog.netlify.app/docs/javascript/await-keyword/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-nodejs/\">https://bgoonz-blog.netlify.app/docs/reference/awesome-nodejs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/intro-for-js-devs/\">https://bgoonz-blog.netlify.app/docs/python/intro-for-js-devs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/notes-template/\">https://bgoonz-blog.netlify.app/docs/reference/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/trouble-shooting/\">https://bgoonz-blog.netlify.app/docs/content/trouble-shooting/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/insert-into-array/\">https://bgoonz-blog.netlify.app/docs/js-tips/insert-into-array/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/intro-to-nodejs/\">https://bgoonz-blog.netlify.app/docs/reference/intro-to-nodejs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/js-expressions/\">https://bgoonz-blog.netlify.app/docs/javascript/js-expressions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/embeded-websites/\">https://bgoonz-blog.netlify.app/docs/projects/embeded-websites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-js-language/\">https://bgoonz-blog.netlify.app/docs/overflow/node-js-language/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/google-firebase/\">https://bgoonz-blog.netlify.app/docs/quick-ref/google-firebase/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/how-to-ask-questions/\">https://bgoonz-blog.netlify.app/docs/tips/how-to-ask-questions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-algo-interview/\">https://bgoonz-blog.netlify.app/docs/ds-algo/ds-algo-interview/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/installing-node/\">https://bgoonz-blog.netlify.app/docs/reference/installing-node/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/callstack-visual/\">https://bgoonz-blog.netlify.app/docs/interact/callstack-visual/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/bash-cheat-sheet/\">https://bgoonz-blog.netlify.app/docs/tutorials/bash-cheat-sheet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dtw-python-explained/\">https://bgoonz-blog.netlify.app/docs/audio/dtw-python-explained/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/bash-commands-my/\">https://bgoonz-blog.netlify.app/docs/tutorials/bash-commands-my/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-the-web-works/\">https://bgoonz-blog.netlify.app/docs/articles/how-the-web-works/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/comprehensive-guide/\">https://bgoonz-blog.netlify.app/docs/python/comprehensive-guide/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/cs-basics-in-js/\">https://bgoonz-blog.netlify.app/docs/javascript/cs-basics-in-js/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/create-react-app/\">https://bgoonz-blog.netlify.app/docs/quick-ref/create-react-app/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-resources/\">https://bgoonz-blog.netlify.app/docs/reference/github-resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/arrow-functions/\">https://bgoonz-blog.netlify.app/docs/javascript/arrow-functions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/google-sheets-api/\">https://bgoonz-blog.netlify.app/docs/quick-ref/google-sheets-api/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/markdown-dropdowns/\">https://bgoonz-blog.netlify.app/docs/quick-ref/markdown-dropdowns/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/dont-use-index-as-keys/\">https://bgoonz-blog.netlify.app/docs/react/dont-use-index-as-keys/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-docs/\">https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/relational-databases/\">https://bgoonz-blog.netlify.app/docs/content/relational-databases/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/get-file-extension/\">https://bgoonz-blog.netlify.app/docs/tutorials/get-file-extension/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/conditional_operator/\">https://bgoonz-blog.netlify.app/docs/js-tips/conditional_operator/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/heroku-error-codes/\">https://bgoonz-blog.netlify.app/docs/quick-ref/heroku-error-codes/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/understanding-path/\">https://bgoonz-blog.netlify.app/docs/quick-ref/understanding-path/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/css/css-selector-specificity/\">https://bgoonz-blog.netlify.app/docs/css/css-selector-specificity/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/art-of-command-line/\">https://bgoonz-blog.netlify.app/docs/reference/art-of-command-line/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/this-is-about-this/\">https://bgoonz-blog.netlify.app/docs/javascript/this-is-about-this/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/pull-request-rubric/\">https://bgoonz-blog.netlify.app/docs/quick-ref/pull-request-rubric/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-2-reinstall-npm/\">https://bgoonz-blog.netlify.app/docs/reference/how-2-reinstall-npm/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/markdown-styleguide/\">https://bgoonz-blog.netlify.app/docs/reference/markdown-styleguide/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/higher-order-components/\">https://bgoonz-blog.netlify.app/docs/react/higher-order-components/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/javascript-examples/\">https://bgoonz-blog.netlify.app/docs/javascript/javascript-examples/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-dev-tools-profiler/\">https://bgoonz-blog.netlify.app/docs/react/react-dev-tools-profiler/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-to-kill-a-process/\">https://bgoonz-blog.netlify.app/docs/reference/how-to-kill-a-process/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/understanding-firebase/\">https://bgoonz-blog.netlify.app/docs/overflow/understanding-firebase/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/new-repo-instructions/\">https://bgoonz-blog.netlify.app/docs/quick-ref/new-repo-instructions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-patterns-by-usecase/\">https://bgoonz-blog.netlify.app/docs/react/react-patterns-by-usecase/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/data-structures-in-python/\">https://bgoonz-blog.netlify.app/docs/python/data-structures-in-python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/constructor-functions/\">https://bgoonz-blog.netlify.app/docs/javascript/constructor-functions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/web-standards-checklist/\">https://bgoonz-blog.netlify.app/docs/articles/web-standards-checklist/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-search-engines-work/\">https://bgoonz-blog.netlify.app/docs/articles/how-search-engines-work/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-in-python/\">https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-in-python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/python-builtin-functions/\">https://bgoonz-blog.netlify.app/docs/quick-ref/python-builtin-functions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-cheat-sheet/\">https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-cheat-sheet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/native-data-structures-in-js/\">https://bgoonz-blog.netlify.app/docs/ds-algo/native-data-structures-in-js/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/asynchronous-javascript-and-xml/\">https://bgoonz-blog.netlify.app/docs/javascript/asynchronous-javascript-and-xml/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/general-structured-data-guidelines/\">https://bgoonz-blog.netlify.app/docs/quick-ref/general-structured-data-guidelines/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/7-tips-to-become-a-better-web-developer/\">https://bgoonz-blog.netlify.app/docs/tips/7-tips-to-become-a-better-web-developer/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/css/the-ultimate-guide-for-advanced-css-hacks/\">https://bgoonz-blog.netlify.app/docs/css/the-ultimate-guide-for-advanced-css-hacks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/7-tips-to-become-a-better-web-developer/7tips/\">https://bgoonz-blog.netlify.app/docs/tips/7-tips-to-become-a-better-web-developer/7tips/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/javascript-examples/flattening-arrays-in-javascript/\">https://bgoonz-blog.netlify.app/docs/javascript/javascript-examples/flattening-arrays-in-javascript/</a></li>\n</ul>\n</details>\n<div class=\"important\"><strong>Not Up To Date<strong></div>\n<center>\n<h2><a href=\"https://bgoonz-blog.netlify.app/docs\"><strong><ins>➡️📚🏠docs🏠📚⬅️</ins></strong></a></h2>\n<h3><a href=\"https://bgoonz-blog.netlify.app/readme\"><strong>readme</ins></strong></a></h3>\n<h3><a href=\"https://bgoonz-blog.netlify.app/showcase\"><strong><ins>showcase</ins></strong></a></h3>\n<h5><a href=\"https://bgoonz-blog.netlify.app/admin\"><strong><ins>🔏admin</ins></strong></a></h5>\n<h5><a href=\"https://bgoonz-blog.netlify.app/privacy-policy\"><strong><ins>🔏privacy-policy</ins></strong></a></h5>\n</center>\n<br>\n<br>\n<details>\n<summary> 📰📰 BLOG 📰📰 </h6>\n</summary>\n<h5><a href=\"https://bgoonz-blog.netlify.app/blog\"><strong><ins>Blog Article List</ins></strong></a></h5>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/blog/web-scraping\">📰blog📰</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/300-react-questions\">📰300-react-questions</a></li>\n</ul>\n</li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/adding-css-to-your-html\">📰adding-css-to-your-html</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/awesome-graphql\">📰awesome-graphql</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/big-o-complexity\">📰big-o-complexity</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blog-archive\">📰blog-archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures\">📰data-structures</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures-algorithms-resources\">📰data-structures-algorithms-resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/expressjs-apis\">📰expressjs-apis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/flow-control-in-python\">📰flow-control-in-python</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/functions-in-python\">📰functions-in-python</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/git-gateway\">📰git-gateway</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/hoisting\">📰hoisting</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js\">📰interview-questions-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js-p2\">📰interview-questions-js-p2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js-p3\">📰interview-questions-js-p3</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/netlify-cms\">📰netlify-cms</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/platform-docs\">📰platform-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/psql-cheat-sheet\">📰psql-cheat-sheet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-for-js-dev\">📰python-for-js-dev</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-resources\">📰python-resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/vs-code-extensions\">📰vs-code-extensions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/web-dev-trends\">📰web-dev-trends</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/web-scraping\">📰web-scraping</a></li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - About</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/about\">📚docs📚/about</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/README\">📚docs📚/about/README</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/eng-portfolio\">📚docs📚/about/eng-portfolio</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/intrests\">📚docs📚/about/intrests</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/job-search\">📚docs📚/about/job-search</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/resume\">📚docs📚/about/resume</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 🗞️Artices🗞️</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/articles\">📚docs📚/🗞️articles🗞️</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev\">📚docs📚/🗞️articles🗞️basic-web-dev</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/buffers\">📚docs📚/🗞️articles🗞️buffers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/common-modules\">📚docs📚/🗞️articles🗞️common-modules</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/dev-dep\">📚docs📚/🗞️articles🗞️dev-dep</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/event-loop\">📚docs📚/🗞️articles🗞️event-loop</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/fs-module\">📚docs📚/🗞️articles🗞️fs-module</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-search-engines-work\">📚docs📚/🗞️articles🗞️how-search-engines-work</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-the-web-works\">📚docs📚/🗞️articles🗞️how-the-web-works</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/intro\">📚docs📚/🗞️articles🗞️intro</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/jamstack\">📚docs📚/🗞️articles🗞️jamstack</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nextjs\">📚docs📚/🗞️articles🗞️nextjs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-api-express\">📚docs📚/🗞️articles🗞️node-api-express</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nodejs\">📚docs📚/🗞️articles🗞️nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/npm\">📚docs📚/🗞️articles🗞️npm</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/os-module\">📚docs📚/🗞️articles🗞️os-module</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/reading-files\">📚docs📚/🗞️articles🗞️reading-files</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic\">📚docs📚/🗞️articles🗞️semantic</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic-html\">📚docs📚/🗞️articles🗞️semantic-html</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/url\">📚docs📚/🗞️articles🗞️url</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/web-standards-checklist\">📚docs📚/🗞️articles🗞️web-standards-checklist</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/webdev-tools\">📚docs📚/🗞️articles🗞️webdev-tools</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/writing-files\">📚docs📚/🗞️articles🗞️writing-files</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 🔊 Audio</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/audio\">📚Docs - Audio🔊</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dfft\">📚docs📚/audio/dfft</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/discrete-fft\">📚docs📚/audio/discrete-fft</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dtw-python-explained\">📚docs📚/audio/dtw-python-explained</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dynamic-time-warping\">📚docs📚/audio/dynamic-time-warping</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/web-audio-api\">📚docs📚/audio/web-audio-api</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 -  Career </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/career\">📚docs📚/career</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/dev-interview\">📚docs📚/career/dev-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/dos-and-donts\">📚docs📚/career/dos-and-donts</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/job-boards\">📚docs📚/career/job-boards</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview\">📚docs📚/career/web-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview2\">📚docs📚/career/web-interview2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview3\">📚docs📚/career/web-interview3</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview4\">📚docs📚/career/web-interview4</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/job-search-nav\">📚docs📚/interview/job-search-nav</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/previous-concepts\">📚docs📚/interview/previous-concepts</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/review-concepts\">📚docs📚/interview/review-concepts</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 -  👫👫Community👫👫 </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/community\">📚docs📚/👫👫community👫👫</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/an-open-letter-2-future-developers\">📚docs📚/community/an-open-letter-2-future-developers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/bookmarks\">📚docs📚/community/bookmarks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/video-chat\">📚docs📚/community/video-chat</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 💼Content💼</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/content/\">📚docs📚/💼content💼</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/archive\">📚docs📚/💼content💼/archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/gatsby-Queries-Mutations\">📚docs📚/💼content💼/gatsby-Queries-Mutations</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/gists\">📚docs📚/💼content💼/gists</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/history-api\">📚docs📚/💼content💼/history-api</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/main-projects\">📚docs📚/💼content💼/main-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/trouble-shooting\">📚docs📚/💼content💼/trouble-shooting</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 📓Documentation📓</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/docs\">📚docs📚/docs</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/appendix\">📚docs📚/docs/appendix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/art-of-command-line\">📚docs📚/docs/art-of-command-line</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/bash\">📚docs📚/docs/bash</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/css\">📚docs📚/docs/css</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/data-structures-docs\">📚docs📚/docs/data-structures-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/es-6-features\">📚docs📚/docs/es-6-features</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-reference\">📚docs📚/docs/git-reference</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-repos\">📚docs📚/docs/git-repos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/glossary\">📚docs📚/docs/glossary</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/html-tags\">📚docs📚/docs/html-tags</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/markdown\">📚docs📚/docs/markdown</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/no-whiteboarding\">📚docs📚/docs/no-whiteboarding</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/node-docs-complete\">📚docs📚/docs/node-docs-complete</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/regex-in-js\">📚docs📚/docs/regex-in-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/sitemap\">📚docs📚/docs/sitemap</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/snippets\">📚docs📚/docs/snippets</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>\n <ins>📚Docs📚 - 🕸Data Structures & Algorithms🕸</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo\">📚docs📚/🕸ds-algo🕸</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/big-o\">📚docs📚/🕸ds-algo🕸/big-o</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-algo-interview\">📚docs📚/🕸ds-algo🕸/ds-algo-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-overview\">📚docs📚/🕸ds-algo🕸/ds-overview</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - ❓FAQ❓</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/faq\">📚docs📚/faq</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/contact\">📚docs📚/❓faq❓/contact</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/plug-ins\">📚docs📚/❓faq❓/plug-ins</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 🧑‍🔬Interactive🧑‍🔬 </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/interact\">📚docs📚/interact</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/callstack-visual\">📚docs📚/🧑‍🔬interact🧑‍🔬/callstack-visual</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/clock\">📚docs📚/🧑‍🔬interact🧑‍🔬/clock</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/jupyter-notebooks\">📚docs📚/🧑‍🔬interact🧑‍🔬/jupyter-notebooks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites\">📚docs📚/🧑‍🔬interact🧑‍🔬/other-sites</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/video-chat\">📚docs📚/🧑‍🔬interact🧑‍🔬/video-chat</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 💻Javascript💻</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/javascript\">📚docs📚/💻javascript💻</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/arrow-functions\">📚docs📚/💻javascript💻/arrow-functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/asyncjs\">📚docs📚/💻javascript💻/asyncjs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/await-keyword\">📚docs📚/💻javascript💻/await-keyword</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/bigo\">📚docs📚/💻javascript💻/bigo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/clean-code\">📚docs📚/💻javascript💻/clean-code</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/constructor-functions\">📚docs📚/💻javascript💻/constructor-functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/cs-basics-in-js\">📚docs📚/💻javascript💻/cs-basics-in-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/for-loops\">📚docs📚/💻javascript💻/for-loops</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/part2-pojo\">📚docs📚/💻javascript💻/part2-pojo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/promises\">📚docs📚/💻javascript💻/promises</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/review\">📚docs📚/💻javascript💻/review</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/this-is-about-this\">📚docs📚/💻javascript💻/this-is-about-this</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 -  💸JS-Tips💸</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips\">📚docs📚/💸js-tips💸</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/abs\">📚docs📚/💸js-tips💸/abs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acos\">📚docs📚/💸js-tips💸/acos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acosh\">📚docs📚/💸js-tips💸/acosh</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/addition\">📚docs📚/💸js-tips💸/addition</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/all\">📚docs📚/💸js-tips💸/all</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/allsettled\">📚docs📚/💸js-tips💸/allsettled</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/any\">📚docs📚/💸js-tips💸/any</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array\">📚docs📚/💸js-tips💸/array</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array-methods\">📚docs📚/💸js-tips💸/array-methods</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/arrow_functions\">📚docs📚/💸js-tips💸/arrow_functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/async_function\">📚docs📚/💸js-tips💸/async_function</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bad_radix\">📚docs📚/💸js-tips💸/bad_radix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bind\">📚docs📚/💸js-tips💸/bind</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/classes\">📚docs📚/💸js-tips💸/classes</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/concat\">📚docs📚/💸js-tips💸/concat</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/conditional_operator\">📚docs📚/💸js-tips💸/conditional_operator</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/const\">📚docs📚/💸js-tips💸/const</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/create\">📚docs📚/💸js-tips💸/create</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/date\">📚docs📚/💸js-tips💸/date</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/eval\">📚docs📚/💸js-tips💸/eval</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/every\">📚docs📚/💸js-tips💸/every</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/filter\">📚docs📚/💸js-tips💸/filter</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/for...of\">📚docs📚/💸js-tips💸/for...of</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/foreach\">📚docs📚/💸js-tips💸/foreach</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/functions\">📚docs📚/💸js-tips💸/functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/import\">📚docs📚/💸js-tips💸/import</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/insert-into-array\">📚docs📚/💸js-tips💸/insert-into-array</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/map\">📚docs📚/💸js-tips💸/map</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/object\">📚docs📚/💸js-tips💸/object</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/reduce\">📚docs📚/💸js-tips💸/reduce</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/regexp\">📚docs📚/💸js-tips💸/regexp</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sort\">📚docs📚/💸js-tips💸/sort</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sorting-strings\">📚docs📚/💸js-tips💸/sorting-strings</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/string\">📚docs📚/💸js-tips💸/string</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/this\">📚docs📚/💸js-tips💸/this</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/var\">📚docs📚/💸js-tips💸/var</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 🏆Leetcode🏆 </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode\">📚docs📚/🏆leetcode🏆</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ContaineWitMosWater\">📚docs📚/🏆leetcode🏆/ContaineWitMosWater</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/DividTwIntegers\">📚docs📚/🏆leetcode🏆/DividTwIntegers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/GeneratParentheses\">📚docs📚/🏆leetcode🏆/GeneratParentheses</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/LetteCombinationoPhonNumber\">📚docs📚/🏆leetcode🏆/LetteCombinationoPhonNumber</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/LongesCommoPrefix\">📚docs📚/🏆leetcode🏆/LongesCommoPrefix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/MediaoTwSorteArrays\">📚docs📚/🏆leetcode🏆/MediaoTwSorteArrays</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/NexPermutation\">📚docs📚/🏆leetcode🏆/NexPermutation</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/PalindromNumber\">📚docs📚/🏆leetcode🏆/PalindromNumber</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RegulaExpressioMatching\">📚docs📚/🏆leetcode🏆/RegulaExpressioMatching</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RemovDuplicatefroSorteArray\">📚docs📚/🏆leetcode🏆/RemovDuplicatefroSorteArray</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RemovNtNodFroEnoList\">📚docs📚/🏆leetcode🏆/RemovNtNodFroEnoList</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RomatInteger\">📚docs📚/🏆leetcode🏆/RomatInteger</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/SearciRotateSorteArray\">📚docs📚/🏆leetcode🏆/SearciRotateSorteArray</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/StrintIntege(atoi)\">📚docs📚/🏆leetcode🏆/StrintIntege(atoi)</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ValiParentheses\">📚docs📚/🏆leetcode🏆/ValiParentheses</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ZigZaConversion\">📚docs📚/🏆leetcode🏆/ZigZaConversion</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 -  🌊 Overflow🌊     </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/overflow\">📚docs📚/🌊overflow🌊</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/html-spec\">📚docs📚/🌊overflow🌊/html-spec</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/http\">📚docs📚/🌊overflow🌊/http</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/install\">📚docs📚/🌊overflow🌊/install</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/modules\">📚docs📚/🌊overflow🌊/modules</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-cli-args\">📚docs📚/🌊overflow🌊/node-cli-args</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-js-language\">📚docs📚/🌊overflow🌊/node-js-language</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-package-manager\">📚docs📚/🌊overflow🌊/node-package-manager</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-repl\">📚docs📚/🌊overflow🌊/node-repl</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-run-cli\">📚docs📚/🌊overflow🌊/node-run-cli</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/nodevsbrowser\">📚docs📚/🌊overflow🌊/nodevsbrowser</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/understanding-firebase\">📚docs📚/🌊overflow🌊/understanding-firebase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/v8\">📚docs📚/🌊overflow🌊/v8</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - Projects  </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/projects\">📚docs📚/projects</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/embeded-websites\">📚docs📚/projects/embeded-websites</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/list-of-projects\">📚docs📚/projects/list-of-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects\">📚docs📚/projects/mini-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects2\">📚docs📚/projects/mini-projects2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/my-websites\">📚docs📚/projects/my-websites</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 🐍Python🐍  </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/python\">📚docs📚/🐍python🐍</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/at-length\">📚docs📚/🐍python🐍/at-length</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/cheat-sheet\">📚docs📚/🐍python🐍/cheat-sheet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/comprehensive-guide\">📚docs📚/🐍python🐍/comprehensive-guide</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/examples\">📚docs📚/🐍python🐍/examples</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/flow-control\">📚docs📚/🐍python🐍/flow-control</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/functions\">📚docs📚/🐍python🐍/functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/google-sheets-api\">📚docs📚/🐍python🐍/google-sheets-api</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-ds\">📚docs📚/🐍python🐍/python-ds</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/intro-for-js-devs\">📚docs📚/🐍python🐍/intro-for-js-devs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-quiz\">📚docs📚/🐍python🐍/python-quiz</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/snippets\">📚docs📚/🐍python🐍/snippets</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 📚🏃‍♂️Quick Reference📚🏃‍♂️   </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref\">📚docs📚/quick-ref</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/Emmet\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/Emmet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/all-emojis\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/all-emojis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/create-react-app\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/create-react-app</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-bash\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/git-bash</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-tricks\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/git-tricks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/google-firebase\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/google-firebase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/heroku-error-codes\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/heroku-error-codes</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/installation\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/installation</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/markdown-dropdowns\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/markdown-dropdowns</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/minifiction\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/minifiction</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/new-repo-instructions\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/new-repo-instructions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/psql-setup\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/psql-setup</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/pull-request-rubric\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/pull-request-rubric</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/quick-links\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/quick-links</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/topRepos\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/topRepos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/understanding-path\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/understanding-path</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/vscode-themes\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/vscode-themes</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/accessibility\">📚docs📚/⚛️react⚛️/accessibility</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - ⚛️React⚛️ </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/react\">📚docs📚/⚛️react⚛️</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/ajax-n-apis\">📚docs📚/⚛️react⚛️/ajax-n-apis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/cheatsheet\">📚docs📚/⚛️react⚛️/cheatsheet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/createReactApp\">📚docs📚/⚛️react⚛️/createReactApp</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/demo\">📚docs📚/⚛️react⚛️/demo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/dont-use-index-as-keys\">📚docs📚/⚛️react⚛️/dont-use-index-as-keys</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/jsx\">📚docs📚/⚛️react⚛️/jsx</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/quiz\">📚docs📚/⚛️react⚛️/quiz</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-docs\">📚docs📚/⚛️react⚛️/react-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-in-depth\">📚docs📚/⚛️react⚛️/react-in-depth</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-patterns-by-usecase\">📚docs📚/⚛️react⚛️/react-patterns-by-usecase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2\">📚docs📚/⚛️react⚛️/react2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/render-elements\">📚docs📚/⚛️react⚛️/render-elements</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 -  ※🕮Reference Materials🕮※</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/reference\">📚docs📚/※reference※</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-lists\">📚docs📚/※🕮reference※🕮/awesome-lists</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-nodejs\">📚docs📚/※🕮reference※🕮/awesome-nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-static\">📚docs📚/※🕮reference※🕮/awesome-static</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bash-commands\">📚docs📚/※🕮reference※🕮/bash-commands</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bookmarks\">📚docs📚/※🕮reference※🕮/bookmarks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/embed-the-web\">📚docs📚/※🕮reference※🕮/embed-the-web</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-resources\">📚docs📚/※🕮reference※🕮/github-resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-search\">📚docs📚/※🕮reference※🕮/github-search</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/google-cloud\">📚docs📚/※🕮reference※🕮/google-cloud</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-2-reinstall-npm\">📚docs📚/※🕮reference※🕮/how-2-reinstall-npm</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-to-kill-a-process\">📚docs📚/※🕮reference※🕮/how-to-kill-a-process</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/installing-node\">📚docs📚/※🕮reference※🕮/installing-node</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/intro-to-nodejs\">📚docs📚/※🕮reference※🕮/intro-to-nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/markdown-styleguide\">📚docs📚/※🕮reference※🕮/markdown-styleguide</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/notes-template\">📚docs📚/※🕮reference※🕮/notes-template</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/psql\">📚docs📚/※🕮reference※🕮/psql</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/resources\">📚docs📚/※🕮reference※🕮/resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/vscode\">📚docs📚/※🕮reference※🕮/vscode</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/web-api&#x27;s\">📚docs📚/※🕮reference※🕮/web-api's</a></li>\n</ul>\n</li>\n</ul>\n</details>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 🔊 Mini Web Dev Tips </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/tips\">📚docs📚/tips</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/regex-tips\">📚docs📚/tips/regex-tips</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - ⚒Tools⚒ </summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/tools\">📚docs📚/⚒Tools⚒/</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/all\">📚docs📚/⚒Tools⚒/all</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/all-stripped\">📚docs📚/⚒Tools⚒/all-stripped</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/archive\">📚docs📚/⚒Tools⚒/archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/dev-utilities\">📚docs📚/⚒Tools⚒/dev-utilities</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/markdown-html\">📚docs📚/⚒Tools⚒/📚markdown-html</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<br>\n<br>\n<br>\n<details>\n<summary>📚Docs📚 - 📑Tutorials📑</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials\">📚docs📚/tutorials</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/enviorment-setup\">📚docs📚/📑tutorials📑/enviorment-setup</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/get-file-extension\">📚docs📚/📑tutorials📑/get-file-extension</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/get-file-name\">📚docs📚/📑tutorials📑/get-file-name</a></li>\n</ul>\n</li>\n</ul>"},{"url":"/docs/about/readme/","relativePath":"docs/about/readme.md","relativeDir":"docs/about","base":"readme.md","name":"readme","frontmatter":{"title":"readme","weight":0,"excerpt":"readme","seo":{"title":"Readme For This Website","description":"website documentation","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Bgoonz Blog Readme</h1>\n<div align=\"center\">\n<h2><a href=\"https://bgoonz-blog.netlify.app\">⇨WEBSITE🗺️⇦</a></h2>\n<h2>💫 Deploy</h2>\n<p><a href=\"https://app.netlify.com/start/deploy?repository=https://github.com/BGOONZ_BLOG_2.0.git\"><img src=\"https://www.netlify.com/img/deploy/button.svg\" alt=\"Deploy to Netlify**\"></a><a href=\"https://vercel.com/import/project?template=https://github.com/BGOONZ_BLOG_2.0.git\"><img src=\"https://vercel.com/button\" alt=\"Deploy with Vercel**\"></a><img src=\"https://visitor-badge-reloaded.herokuapp.com/badge?page_id=bgoonz.visitor.badge.reloaded&#x26;color=00bbbb&#x26;style=for-the-badge&#x26;logo=github\" alt=\"GitHub visitors\"></p>\n<p><a href=\"https://app.netlify.com/sites/bgoonz-blog/deploys\"><img src=\"https://api.netlify.com/api/v1/badges/a1b7ee1a-11a7-4bd2-a341-2260656e216f/deploy-status\" alt=\"Netlify Status\"></a><a href=\"https://www.codefactor.io/repository/github/bgoonz/bgoonz_blog_2.0\"><img src=\"https://www.codefactor.io/repository/github/bgoonz/bgoonz_blog_2.0/badge\" alt=\"CodeFactor\"></a></p>\n<h5><a href=\"./CHANGELOG.md\">CHANGELOG</a></h5>\n<h5><a href=\"https://bgoonz-blog.netlify.app\">⇨WEBSITE🗺️⇦</a> <a href=\"https://bgoonz-blog-2-0.pages.dev/\">⇨<strong>Cloudfare-Backup</strong>⇦</a> <a href=\"https://www.algolia.com/realtime-search-demo/web-dev-resource-hub-9e6b8aa8-6106-44c5-9f59-ff3f9531abd4\">⇨<strong>search</strong>⇦</a> <a href=\"https://bgoonzblog20-backup.netlify.app/#gsc.tab=0\">⇨<strong>Backup Repo Deploy</strong>⇦</a> <a href=\"https://bgoonz.github.io/BGOONZ_BLOG_2.0/\">⇨<strong>Github pages</strong>⇦</a><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki\">⇨<strong>Go To Site Wiki</strong>⇦</a> <a href=\"https://bgoonzblog20master.gatsbyjs.io/\">⇨<strong>Gatsby Cloud Version</strong>⇦</a> <a href=\"https://bgoonz-blog.vercel.app/\">⇨<strong>Vercel Version</strong>⇦</a><a href=\"www.webdevhub.us\">⇨<strong>Cloudfare-Domain</strong>⇦</a> <a href=\"https://bgoonz.github.io/BGOONZ_BLOG_2.0/\">⇨<strong>gh-pages</strong>⇦</a> <a href=\"https://bgoonz-blog20-backup.netlify.app/\">⇨<strong>backup netlify deploy</strong>⇦</a></h5>\n<h3>Repos:</h3>\n<p><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\">THIS REPO</a>\n<a href=\"https://github.com/BGOOONZ-BLOG/bgoonz-blog2.0-v-5\">Alt Backup</a>\n<a href=\"https://github.com/bgoonz/MainBlogContent\">Blog Content</a></p>\n<h4>Branch Deploys:</h4>\n<h5><a href=\"https://app.usersnap.com/#/6bf5b719-6d97-4b67-9cc8-271a747f56d3/statistics\">Bug Tracker</a></h5>\n<ul>\n<li><a href=\"http://gitpop2.herokuapp.com/bgoonz/BGOONZ_BLOG_2.0\">Most Updated Forks</a></li>\n<li><a href=\"https://codepen.io/bgoonz/pen/LYLJZrW\">⇨Privacy policy⇦</a></li>\n</ul>\n<p><a href=\"https://www.youtube.com/watch?v=OGCcq1_Tbzk\"><img src=\"https://img.youtube.com/vi/OGCcq1_Tbzk/0.jpg\" alt=\"Demo\"></a>\n<img src=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/blob/master/static/images/blog-img.png?raw=true\" alt=\"preview\"></p>\n<p><a  href=\"https://bgoonzblog20master.gatsbyjs.io/\"><img src=\"https://qrickit.com/api/qr.php?d=https%3A%2F%2Fbgoonzblog20master.gatsbyjs.io%2F&addtext=Click+For+Mobil+Version&txtcolor=000000&fgdcolor=000000&bgdcolor=FFFFFF&qrsize=25&t=p&e=h\" style=\"position: fixed;bottom: 100px;right:20px;\"></a></p>\n<hr>\n<h2>Forks</h2>\n<hr>\n<table>\n<thead>\n<tr>\n<th>Repo</th>\n<th>Stars</th>\n<th>Forks</th>\n<th>Modified</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://github.com/floridamandingo/BGOONZ_BLOG_2.0\">floridamandingo/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>2</td>\n<td>1</td>\n<td>6 days, 18 hours ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/Web-Audio-Tools/BGOONZ_BLOG_2.0\">Web-Audio-Tools/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>1</td>\n<td>0</td>\n<td>6 months, 1 week ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/hdi200/BGOONZ_BLOG_2.0\">hdi200/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>1</td>\n<td>1</td>\n<td>2 weeks, 5 days ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/eengineergz/BGOONZ_BLOG_2.0\">eengineergz/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>1</td>\n<td>0</td>\n<td>6 months, 3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/Web-Dev-Collaborative/BGOONZ_BLOG_2.0\">Web-Dev-Collaborative/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>1</td>\n<td>0</td>\n<td>5 minutes ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/Bryan-Guner-Backup/BGOONZ_BLOG_2.0\">Bryan-Guner-Backup/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>1</td>\n<td>0</td>\n<td>5 hours ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/impastasyndrome/BGOONZ_BLOG_2.0\">impastasyndrome/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>1</td>\n<td>0</td>\n<td>1 month, 3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/ft-anywherefitness-2/BGOONZ_BLOG_2.0\">ft-anywherefitness-2/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>2 months, 2 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/heathermils98/BGOONZ_BLOG_2.0\">heathermils98/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>2 months, 3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/Portfolio-Projects42/BGOONZ_BLOG_2.0\">Portfolio-Projects42/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>6 months, 3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/BGOOONZ-BLOG/BGOONZ_BLOG_2.0\">BGOOONZ-BLOG/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>5 minutes ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/webdevhub42/BGOONZ_BLOG_2.0\">webdevhub42/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>2 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/hartemolly1/BGOONZ_BLOG_2.0\">hartemolly1/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>3 months ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/techsavvyy/BGOONZ_BLOG_2.0\">techsavvyy/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>3 months, 1 week ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/TeaganBriggs/BGOONZ_BLOG_2.0\">TeaganBriggs/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>1 month, 2 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/Archive-42/BGOONZ_BLOG_2.0\">Archive-42/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>2 months, 4 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/whatamidoing24/BGOONZ_BLOG_2.0\">whatamidoing24/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>5 hours ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/side-projects-42/BGOONZ_BLOG_2.0\">side-projects-42/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>4 months, 3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/DanHefrman/BGOONZ_BLOG_2.0\">DanHefrman/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>9 months, 3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/ladykraken/BGOONZ_BLOG_2.0\">ladykraken/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>3 months, 3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/ArjunBEG/BGOONZ_BLOG_2.0\">ArjunBEG/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>4 months, 3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/permission-squad/BGOONZ_BLOG_2.0\">permission-squad/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>2 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/JuanParker1/BGOONZ_BLOG_2.0\">JuanParker1/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>1 month, 2 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/web-tools42/BGOONZ_BLOG_2.0\">web-tools42/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>6 months ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/TheLadyKProject/BGOONZ_BLOG_2.0\">TheLadyKProject/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>3 months, 1 week ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz-duke/BGOONZ_BLOG_2.0\">bgoonz-duke/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>3 weeks, 6 days ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/RelativeTech/BGOONZ_BLOG_2.0\">RelativeTech/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>1</td>\n<td>10 months ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/ETS-ReactNative5/BGOONZ_BLOG_2.0\">ETS-ReactNative5/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>3 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/webdev-docs/BGOONZ_BLOG_2.0\">webdev-docs/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>9 months ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/DUKE42web/BGOONZ_BLOG_2.0\">DUKE42web/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>3 months, 1 week ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/academic-resources/BGOONZ_BLOG_2.0\">academic-resources/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>6 months, 4 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/jyoshnakarna/BGOONZ_BLOG_2.0\">jyoshnakarna/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>0</td>\n<td>0</td>\n<td>2 months, 2 weeks ago</td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\">bgoonz/BGOONZ<em>BLOG</em>2.0</a></td>\n<td>14</td>\n<td>35</td>\n<td>5 minutes ago</td>\n</tr>\n</tbody>\n</table>\n<h2><a href=\"https://6309792f5c634e0009e7e51b--bgoonz-blog.netlify.app/\">vercel branch netlify</a></h2>\n</div>\n<h2>Wiki Nav</h2>\n<ul>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki\">Home</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/add-copy-to-code-blocks.md\">add copy to code blocks.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/Add-site-search-w-algolia.md\">Add site search w algolia.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/adding-mailing-list.md\">adding mailing list.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/Adding-search-2-gatsby-site.md\">Adding search 2 gatsby site.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/awesome.md\">awesome.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/broken-links.md\">broken links.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/configure-custom-domain.md\">configure custom domain.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/contentauthoring.md\">contentauthoring.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/full-text-search-w-lunar.md\">full text search w lunar.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/inject-4.md\">inject 4.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/inject3.md\">inject3.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/inject4.md\">inject4.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/injected-content-part2.md\">injected content part2.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/injected-js-part4.md\">injected js part4.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/injected-part3.md\">injected part3.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/links-2-embed.md\">links 2 embed.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/links-to-remember\">links to remember</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/Netlify-Injected-Content\">Netlify Injected Content</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/old-version-of-index.md\">old version of index.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/optimize-vscode.md\">optimize vscode.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/possibly-useful-snippets.md\">possibly useful snippets.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/privacy-policy.md\">privacy policy.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/random-stuff.md\">random stuff.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/random.md\">random.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/ref-type\">ref type</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/SEO.md\">SEO.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/stable-points.md\">stable points.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/tech-used.md\">tech used.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/Technologies-Used.md\">Technologies Used.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/THINGS-TO-EMBED.md\">THINGS TO EMBED.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/validation-report.md\">validation report.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/web-archive.md\">web archive.md</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/wiki/wordpress-vs-headless-cms.md\">wordpress vs headless cms.md</a></li>\n</ul>"},{"url":"/docs/about/resume/","relativePath":"docs/about/resume.md","relativeDir":"docs/about","base":"resume.md","name":"resume","frontmatter":{"title":"Resume","weight":0,"seo":{"title":"Resume","description":"Successfully completed and delivered a platform to digitize a guitar signal and perform filtering before executing frequency & time domain analysis to track a current performance against prerecorded performance.","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Resume","keyName":"property"},{"name":"og:description","value":"This is the Resume page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Resume"},{"name":"twitter:description","value":"This is the Resume page"}]},"template":"docs"},"html":"<h1><em><strong>Resume</strong></em></h1>\n<div align=\"center\">\n<h1><strong>Bryan</strong> <strong>Guner</strong></h1>\n<h2><em>551-254-5505 | <a href=\"mailto:bryan.guner@gmail.com\">bryan.guner@gmail.com</a></em></h2>\n</div>\n<h2>➤Skills</h2>\n<table>\n<thead>\n<tr>\n<th>Languages:</th>\n<th>JavaScript ES-6, NodeJS, HTML5, CSS3, SCSS, Bash Shell, SQL, MATLAB, Python, C++, Mathematica, JSON</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Frameworks / Libraries:</td>\n<td>React, Redux, ExpressJS, Gatsby, NextJS, Ant-Design, Loadash, Sequelize, GraphQL, AJAX, Jest, Mocha, jQuery, Electron</td>\n</tr>\n<tr>\n<td>Databases:</td>\n<td>PostgreSQL, MongoDB, SQlite3</td>\n</tr>\n<tr>\n<td>Tools:</td>\n<td>Figma, Adobe XD, GitHub, GitLab, Excel, VSCode, Sublime Text, Atom, Google Analytics, Bootstrap, Tailwind, FontAwesome</td>\n</tr>\n<tr>\n<td>Tools (continued):</td>\n<td>Docker, Firebase, Postman, Wordpress, Chrome Dev Tools, Jira, Trello, Confluence, Firebase, AWS S3, Okta, Algolia, Loadash</td>\n</tr>\n<tr>\n<td>Hosting:</td>\n<td>Heroku, Netlify, Vercel, Wordpress, Cloudfare, AWS, Firebase, Digital Ocean</td>\n</tr>\n<tr>\n<td>Operating Systems:</td>\n<td>Linux, Windows (WSL), IOS</td>\n</tr>\n</tbody>\n</table>\n<h2>➤Projects</h2>\n<p><strong>Gatsby</strong> <strong>GraphQL-Blog</strong> <strong><a href=\"https://bgoonz-blog.netlify.app/\">Live Site |</a><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\">GitHub</a></strong></p>\n<p><strong>Stack:</strong> <em>JavaScript, React / Gatsby | GraphQL | SCSS | Lodash | Jamstack | Facebook Comments API | jQuery | Firebase</em></p>\n<p><em><strong>A</strong></em><a href=\"https://bgoonz-blog.netlify.app/\"><em><strong>web development blog</strong></em></a><em><strong>featuring convenient web development tools and interactive content</strong></em></p>\n<ul>\n<li>Implemented 4 Gatsby page models and GraphQL schema to fetch markdown content and feed it into react components.</li>\n<li>Designed and integrated a set of convenient web-hosted <a href=\"https://bgoonz-blog.netlify.app/docs/tools/\">developer tools</a> and GUI interfaces.</li>\n<li>Added interactive content including comments, <a href=\"https://bgoonz-blog.netlify.app/docs/interact/video-chat/\">video conferencing</a>, <a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites/\">data-structure visualization</a>, <a href=\"https://bgoonz-blog.netlify.app/docs/interact/\">games</a> and full text search.</li>\n</ul>\n<p><strong>Autonomously Triggered Guitar Effects Platform**</strong> <a href=\"https://bgoonz.github.io/Revamped-Automatic-Guitar-Effect-Triggering/\">Live Site</a>| <a href=\"https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering/tree/master/Triggered-Guitar-Effects-Platform\">GitHub</a>**</p>\n<p><strong>Stack:</strong> <em>C++ | Python | MATLAB | PureData</em></p>\n<p><a href=\"https://bgoonz.github.io/Revamped-Automatic-Guitar-Effect-Triggering/SR%20Project%20II%20Presentation.pdf\"><em><strong>Platform</strong></em></a><em><strong>designed to analyze a time sequence of notes and autonomously trigger guitar effects at</strong></em><a href=\"https://youtu.be/pRKjaprdWx4\"><em><strong>a predetermined point in the song</strong></em></a></p>\n<ul>\n<li>Used pure data to filter a guitar signal before executing frequency domain analysis and implementing <a href=\"https://youtu.be/krRVGoK9NcA\">custom built guitar effects.</a></li>\n<li>Implemented the Dynamic Time Warping algorithm in C++ and Python to generate a time agnostic measure of similarity between performances.</li>\n<li>Autonomously activated or adjusted guitar effects at multiple pre-designated sections of performance.</li>\n</ul>\n<hr>\n<p><strong>Data Structures</strong> <a href=\"https://ds-algo-official.netlify.app/\"><strong>Interactive Teaching Tool</strong></a><a href=\"https://ds-algo-official.netlify.app/\"><strong>Live Site</strong></a> <strong>|**</strong> <a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">GitHub</a>**</p>\n<p><strong>Stack:</strong> <em>jQuery | ExpressJS | Google Analytics |Algolia Full Text Search | Amazon S3</em></p>\n<p><em><strong>A</strong></em><a href=\"https://youtu.be/onquAh1Bl0g\"><em><strong>website</strong></em></a><em><strong>for visualizing and practicing data structures and algorithms in JavaScript &#x26; Python</strong></em></p>\n<ul>\n<li>Implemented an repl.it backend to enable commenting using express and the fs <strong>module</strong> to write user comments to a storage.json file.</li>\n<li>Developed proprietary npm package to recursively walk the project directory structure and generate a <a href=\"https://ds-algo-official.netlify.app/sitemap.html\">site navigation page</a>.</li>\n<li>Created multiple embedded data structure visualizations that interact with user input.</li>\n<li>Automated the generation and submission of a <a href=\"https://ds-algo-official.netlify.app/sitemap.xml\">sitemap</a>to (Google, Bing, and Yandex) on every build.</li>\n</ul>\n<hr>\n<br>\n<h2>➤ Experience</h2>\n<p><strong>Product Development Engineer |</strong> <a href=\"https://www.cembre.com/\"><em><strong>Cembre</strong></em></a><em><strong>, Edison, NJ</strong>\\</em>_|_<strong>Oct 2019 - Mar 2020</strong></p>\n<ul>\n<li>Converted client's product needs into <a href=\"https://www.cembre.com/family/details/5202\">technical specs</a> to be sent to the development team in Italy.</li>\n<li>Reorganized internal file server structure and conducted system integration and product demonstrations.</li>\n<li>Presided over internal and end user software trainings in addition to producing customer facing documentation.</li>\n<li>Conducted <a href=\"https://drive.google.com/drive/folders/1USAQtiQ3jLm3fiRCxIm4TEkWGlq4fO6j?usp=sharing\">electrical conductivity &#x26; tensile testing of electrical components</a> and presided over troubleshooting railroad hardware and software in North America.</li>\n</ul>\n<p><a href=\"https://familypromise.org/\"><strong>Family Promise</strong></a> <strong>Service Tracker</strong></p>\n<p><strong>Full Stack Web Development Intern | Remote | Sept 2021 - Present</strong> <strong><a href=\"https://a.familypromiseservicetracker.dev/\">Live Site |</a><a href=\"https://github.com/Lambda-School-Labs/family-promise-service-tracker-fe-a\">GitHub</a></strong></p>\n<p><strong>Stack:</strong> <em>React | Redux | ExpressJS | Figma | Okta | AWS</em></p>\n<p><em><strong>An</strong></em><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/roadmap\"><em><strong>app</strong></em></a><em><strong>built to helps local communities provide services to address the root causes of family homelessness</strong></em></p>\n<ul>\n<li>Collaborated on state management using Redux to handle application state and middleware using redux-promise &#x26; redux-thunk.</li>\n<li>Built two graphic visuals of the user hierarchy and the scope of their permissions as well as maintained the team's <a href=\"https://bryan-guner.gitbook.io/my-docs/v/lambda-labs/\">docs</a>.</li>\n<li>Created Figma UI mockups for possible future developments, such as displaying metrics data and map pinpoint functionality.</li>\n</ul>\n<br>\n<hr>\n<h2>➤ Education</h2>\n<h4><a href=\"https://www.credly.com/badges/bd145ba3-0f09-42fc-8d1f-a3bc4e0a46b4/public_url\"><strong>Lambda School</strong></a> , <em><strong>Full Stack Web Development</strong></em></h4>\n<blockquote>\n<p><em><strong>May 2020 - Nov 2021</strong></em></p>\n</blockquote>\n<p>Six-month immersive software development course with a focus on <a href=\"https://gist.github.com/bgoonz/17494dab0042a6f70eda7929c08c878f\">full stack web development</a>. Over 2000 hours of work invested including class time, homework, and projects.</p>\n<p><strong>B.S.</strong> <a href=\"https://electrical-computerengineering.tcnj.edu/\"><strong>Electrical Engineering</strong></a> <strong>, TCNJ, Ewing NJ</strong> <strong>2014 - 2019</strong></p>\n<p><a href=\"https://github.com/bgoonz/random-static-html-page-deploy/blob/master/ElectricalEngineeringCurriculum.pdf\">2 <strong>Curriculum link</strong></a></p>\n<blockquote>\n<p><a href=\"https://bryan-guner.gitbook.io/my-docs/v/electrical-engineering/\">Knowledge of</a> circuit boards, processors, chips, electronic equipment, and computer hardware and software, including applications and programming.</p>\n</blockquote>\n<div align=\"center\">\n<p><em><strong>References &#x26; further work experience available upon request.</strong></em></p>\n</div>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://onedrive.live.com/embed?cid=D21009FDD967A241&resid=D21009FDD967A241%21738414&authkey=AK-_7RN0U5yPS_U&em=2\" width=\"100%\" height=\"800\" frameborder=\"0\" scrolling=\"yes\">\n</iframe>\n<br>"},{"url":"/docs/archive/embeded-websites/","relativePath":"docs/archive/embeded-websites.md","relativeDir":"docs/archive","base":"embeded-websites.md","name":"embeded-websites","frontmatter":{"title":"Embeded Websites & Projects","weight":0,"seo":{"title":"Gatsby Plugins For This Sites Content Model","description":"This is my markdown notes tempate","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Gatsby Plugins For This Sites Content Model","keyName":"property"},{"name":"og:description","value":"This is the Gatsby Plugins For This Sites Content Model page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Gatsby Plugins For This Sites Content Model"},{"name":"twitter:description","value":"This is the Gatsby Plugins For This Sites Content Model page"}]},"template":"docs"},"html":"<br>\n<br>\n<br>\n<h1>Family Promise Project:</h1>\n<h1>Table of contents</h1>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/README\">Home</a></li>\n</ul>\n<h2>navigation</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/navigation\">NAVIGATION</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/calendar\">Calendar</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/youtube\">Youtube:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/roadmap\">Roadmap:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/team-members\">TEAM MEMBERS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/running-list-of-notes-links-and-pertinent-info-from-meetings\">Running List Of Notes Links &#x26; Pertinent Info From Meetings</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/trello/README\">Trello</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/trello/github-trello-integration\">Github/Trello Integration</a></li>\n</ul>\n</li>\n</ul>\n<h2>UX</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/README\">UX_TOPICS</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/action-items\">Action Items:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/accessibility\">Accessibility</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/README\">Figma Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/notes\">Notes</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/prototyping-in-figma\">Prototyping In Figma</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/more-notes\">More Notes</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ux-design/README\">UX-Design</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ux-design/facebook-graph-api\">Facebook Graph API</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/README\">Ant Design</a></p>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-components/README\">ANT Components</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-components/buttons\">Buttons</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-docs\">ANT DOCS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/application-codesandbox\">Application (Codesandbox)</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/examples\">Examples</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/how-to-add-external-url-links-to-your-prototype\">How to add external URL links to your prototype</a></li>\n</ul>\n</li>\n</ul>\n<h2>CANVAS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/README\">Design</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/whats-inclusive-design\">What's Inclusive Design?</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/accessibility\">Accessibility</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/what-are-design-systems\">What are Design Systems?</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/canvas\">Canvas</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/README\">Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/user-experience-design\">User Experience Design</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/user-research\">User Research</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/interaction-design\">Interaction Design</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/README\">UX-Engineer</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/patterns\">Patterns</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/design-tools\">Design Tools</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/design-critiques\">Design Critiques</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/product-review\">Product Review</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/quiz\">Quiz</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/seven-principles-of-design\">Seven Principles of Design</a></li>\n</ul>\n</li>\n</ul>\n<h2>Front End</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/front-end/untitled\">Frontend:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/front-end/redux\">Redux</a></li>\n</ul>\n<h2>Back End</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/back-end/untitled/README\">Backend:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/back-end/untitled/api\">API</a></li>\n</ul>\n</li>\n</ul>\n<h2>Research</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/README\">Research Navigation</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/front-end\">Front End</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/back-end\">Back End</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/ux\">UX</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/ptm\">PTM</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/general\">General</a></li>\n</ul>\n</li>\n</ul>\n<h2>DS_API</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ds_api/untitled\">Data Science API</a></li>\n</ul>\n<h2>ROLES</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/roles/untitled/README\">TEAM ROLES</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/roles/untitled/bryan-guner\">Bryan Guner</a></li>\n</ul>\n</li>\n</ul>\n<h2>Action Items</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/action-items/untitled\">Trello</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/action-items/maps\">Maps</a></li>\n</ul>\n<h2>ARCHITECTURE</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/dns\">DNS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/aws\">AWS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/heroku\">Heroku</a></li>\n</ul>\n<h2>Questions</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/questions/from-previous-cohort\">From Previous Cohort</a></li>\n</ul>\n<h2>Standup Notes</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/README\">Meeting Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/overview\">Stakeholder Meeting 1</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/9-29-2021\">9/29/2021</a></li>\n</ul>\n</li>\n</ul>\n<h2>GitHub &#x26; Project Practice</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/README\">GitHub</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/untitled\">Github Guide</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/github-actions\">Github Actions:</a></li>\n</ul>\n</li>\n</ul>\n<h2>MISC</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/misc/untitled\">MISCELLANEOUS</a></li>\n</ul>\n<h2>Background Information</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/README\">Background Info</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/swagger-open-api-specification\">Swagger OPEN API SPECIFICATION</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/README\">GITHUB:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/git-bash\">Git Bash</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/git-prune\">Git Prune:</a></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<h2>DOCS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/README\">Coding</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/environment-variables\">Environment Variables</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/git-rebase\">Git Rebase:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/git-workflow\">Git Workflow:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/linting-and-formatting\">Linting and Formatting</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/README\">Project Docs</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/eng-docs-home\">Eng-Docs-Home</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/basic-node-api\">Basic Node API</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/contributing-to-this-scaffold-project\">Contributing to this scaffold project</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/examples\">Examples:</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-description\">PROJECT DESCRIPTION (Feature List)</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-learners-guide\">Labs Learners Guide</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/README\">REACT</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/untitled\">Create React App</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/awesome-react\">Awesome React</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/untitled\">Links</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/README\">Labs Engineering Docs</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/okta-basics\">Okta Basics</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/roadmap\">Roadmap</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/repositories\">Repositories</a></li>\n</ul>\n</li>\n</ul>\n<h2>Workflow</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/workflow/workflow\">Workflow</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/workflow/advice\">Advice</a></li>\n</ul>\n<h2>AWS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/README\">AWS</a></p>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/elastic-beanstalk/README\">Elastic Beanstalk</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/elastic-beanstalk/elastic-beanstalk-dns\">Elastic Beanstalk DNS</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/amplify/README\">Amplify:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/amplify/amplify-dns\">Amplify-DNS</a></li>\n</ul>\n</li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/untitled-1\">Account Basics</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws-networking\">AWS-Networking</a></li>\n</ul>\n<h2>Career &#x26; Job Hunt</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/career-and-job-hunt/career\">Career</a></li>\n</ul>\n<h2>Group 1</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/group-1/live-implementation\">Live Implementation</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FbOwyinWBikQ5jdEpSx5WcI%2FFamily-Promise-Copy\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"Family_Promise_embed\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/family-promise-embed-b434z?autoresize=1&fontsize=12&hidenavigation=1&theme=dark&view=preview\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"Family_Promise_embed\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Family-Promise Application</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://a.familypromiseservicetracker.dev/dashboard\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/about/intrests/","relativePath":"docs/about/intrests.md","relativeDir":"docs/about","base":"intrests.md","name":"intrests","frontmatter":{"title":"Youtube","weight":0,"excerpt":"youtube","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/xGZSWvFess8\"  frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<iframe width=\"600\" height=\"515\" src=\"https://www.youtube-nocookie.com/embed/xGZSWvFess8\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<iframe width=\"600\" height=\"515\" src=\"https://www.youtube-nocookie.com/embed/xGZSWvFess8\" title=\"YouTube video player\"  clipboard-write;  allowfullscreen>\n</iframe>\n<br>\n<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/o3eqmSEif80\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/UBVV8pch1dM\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/AQbmpecxS2w\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>\n<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/M4fGgOXK4Kw\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen>\n</iframe>\n<br>"},{"url":"/docs/articles/buffers/","relativePath":"docs/articles/buffers.md","relativeDir":"docs/articles","base":"buffers.md","name":"buffers","frontmatter":{"title":"Node Buffers","sections":[],"seo":{"title":"","description":"A buffer is an area of memory. JavaScript developers are not familiar with this concept, much less than C, C++ or Go developers","robots":[],"extra":[{"name":"og:description","value":"A buffer is an area of memory. JavaScript developers are not familiar with this concept, much less than C, C++ or Go developers","keyName":"property","relativeUrl":false},{"name":"og:title","value":"Buffer","keyName":"property","relativeUrl":false},{"name":"og:image","value":"images/javascript-4ced5a19.gif","keyName":"property","relativeUrl":true}],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>What is a buffer?</h2>\n<p>A buffer is an area of memory. JavaScript developers are not familiar with this concept, much less than C, C++ or Go developers (or any programmer that uses a system programming language), which interact with memory every day.</p>\n<p>It represents a fixed-size chunk of memory (can't be resized) allocated outside of the V8 JavaScript engine.</p>\n<p>You can think of a buffer like an array of integers, which each represent a byte of data.</p>\n<p>It is implemented by the Node.js <a href=\"https://nodejs.org/api/buffer.html\">Buffer class</a>.</p>\n<h2>Why do we need a buffer?</h2>\n<p>Buffers were introduced to help developers deal with binary data, in an ecosystem that traditionally only dealt with strings rather than binaries.</p>\n<p>Buffers are deeply linked with streams. When a stream processor receives data faster than it can digest, it puts the data in a buffer.</p>\n<p>A simple visualization of a buffer is when you are watching a YouTube video and the red line goes beyond your visualization point: you are downloading data faster than you're viewing it, and your browser buffers it.</p>\n<h2>How to create a buffer</h2>\n<p>A buffer is created using the <a href=\"https://nodejs.org/api/buffer.html#buffer_buffer_from_buffer_alloc_and_buffer_allocunsafe\"><code class=\"language-text\">Buffer.from()</code></a>, <a href=\"https://nodejs.org/api/buffer.html#buffer_class_method_buffer_alloc_size_fill_encoding\"><code class=\"language-text\">Buffer.alloc()</code></a>, and <a href=\"https://nodejs.org/api/buffer.html#buffer_class_method_buffer_allocunsafe_size\"><code class=\"language-text\">Buffer.allocUnsafe()</code></a> methods.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><a href=\"https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_array\"><code class=\"language-text\">Buffer.from(array)</code></a></li>\n<li><a href=\"https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length\"><code class=\"language-text\">Buffer.from(arrayBuffer[, byteOffset[, length]])</code></a></li>\n<li><a href=\"https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_buffer\"><code class=\"language-text\">Buffer.from(buffer)</code></a></li>\n<li><a href=\"https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encoding\"><code class=\"language-text\">Buffer.from(string[, encoding])</code></a></li>\n</ul>\n<p>You can also just initialize the buffer passing the size. This creates a 1KB buffer:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">alloc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1024</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//or</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">allocUnsafe</span><span class=\"token punctuation\">(</span><span class=\"token number\">1024</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>While both <code class=\"language-text\">alloc</code> and <code class=\"language-text\">allocUnsafe</code> allocate a <code class=\"language-text\">Buffer</code> of the specified size in bytes, the <code class=\"language-text\">Buffer</code> created by <code class=\"language-text\">alloc</code> will be <em>initialized</em> with zeroes and the one created by <code class=\"language-text\">allocUnsafe</code> will be <em>uninitialized</em>. This means that while <code class=\"language-text\">allocUnsafe</code> would be quite fast in comparison to <code class=\"language-text\">alloc</code>, the allocated segment of memory may contain old data which could potentially be sensitive.</p>\n<p>Older data, if present in the memory, can be accessed or leaked when the <code class=\"language-text\">Buffer</code> memory is read. This is what really makes <code class=\"language-text\">allocUnsafe</code> unsafe and extra care must be taken while using it.</p>\n<h2>Using a buffer</h2>\n<h3>Access the content of a buffer</h3>\n<p>A buffer, being an array of bytes, can be accessed like an array:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>buf<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//72</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>buf<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//101</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>buf<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//121</span></code></pre></div>\n<p>Those numbers are the Unicode Code that identifies the character in the buffer position (H => 72, e => 101, y => 121)</p>\n<p>You can print the full content of the buffer using the <code class=\"language-text\">toString()</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>buf<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p>Notice that if you initialize a buffer with a number that sets its size, you'll get access to pre-initialized memory that will contain random data, not an empty buffer!</p>\n</blockquote>\n<h3>Get the length of a buffer</h3>\n<p>Use the <code class=\"language-text\">length</code> property:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>buf<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Iterate over the contents of a buffer</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> item <span class=\"token keyword\">of</span> buf<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//72 101 121 33</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Changing the content of a buffer</h3>\n<p>You can write to a buffer a whole string of data by using the <code class=\"language-text\">write()</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">alloc</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Just like you can access a buffer with an array syntax, you can also set the contents of the buffer in the same way:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nbuf<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">111</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//o</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>buf<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//Hoy!</span></code></pre></div>\n<h3>Copy a buffer</h3>\n<p>Copying a buffer is possible using the <code class=\"language-text\">copy()</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> bufcopy <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">alloc</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//allocate 4 bytes</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">copy</span><span class=\"token punctuation\">(</span>bufcopy<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>By default you copy the whole buffer. 3 more parameters let you define the starting position, the ending position, and the new buffer length:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> bufcopy <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">alloc</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//allocate 2 bytes</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">copy</span><span class=\"token punctuation\">(</span>bufcopy<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nbufcopy<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//'He'</span></code></pre></div>\n<h3>Slice a buffer</h3>\n<p>If you want to create a partial visualization of a buffer, you can create a slice. A slice is not a copy: the original buffer is still the source of truth. If that changes, your slice changes.</p>\n<p>Use the <code class=\"language-text\">slice()</code> method to create it. The first parameter is the starting position, and you can specify an optional second parameter with the end position:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> buf <span class=\"token operator\">=</span> Buffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hey!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//Hey!</span>\n<span class=\"token keyword\">const</span> slice <span class=\"token operator\">=</span> buf<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>slice<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//He</span>\nbuf<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">111</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//o</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>slice<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//Ho</span></code></pre></div>"},{"url":"/docs/about/job-search/","relativePath":"docs/about/job-search.md","relativeDir":"docs/about","base":"job-search.md","name":"job-search","frontmatter":{"title":"Job Search","weight":0,"excerpt":"the hunt for a webdev position","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Job Boards and The Hunt</h1>\n<p>I can't imagine the kind of masochism it would take to enjoy the act of posting and daily maintenance on a job board…It's part of the…</p>\n<hr>\n<h3>Job Boards and The Hunt</h3>\n<h4>I can't imagine the kind of masochism it would take to enjoy the act of posting and daily maintenance on a job board…It's part of the process that you've already invested so much of yourself in, so you should take pride in it; do a good job the first time around and you'll get where your going in the blink of an eye!</h4>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\">\n<strong>A list of all of my articles to link to future posts</strong>\n<br />\n<em>You should probably skip this one… seriously it's just for internal use!</em>bryanguner.medium.com</a>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<hr>\n<h3>Update(After The Interview):</h3>\n<p>As a candidate, there are key next steps that you can and should after every interview to help you stand out.</p>\n<p><strong>Send a thank you email within 24 business hours</strong></p>\n<p><strong>Do not miss this step!</strong> It takes less than five minutes and can make the difference between you and another candidate. It also keeps you fresh in your interviewers' memories. For example:</p>\n<p>‍</p>\n<p><em>Hi (name),</em></p>\n<blockquote>\n<p><em>Thank you so much for taking the time to meet with me yesterday to discuss my candidacy for (role title). After learning more about (share one or two takeaways from the interview about the company/team's priorities), I'm even more excited to bring my skills in (1-3 relevant skills) to the team.</em></p>\n</blockquote>\n<blockquote>\n<p><em>I look forward to hearing from you about next steps, and if there is anything that I can clarify about my experience or qualifications for the (role title) position, please don't hesitate to reach out.</em></p>\n</blockquote>\n<blockquote>\n<p><em>Thank you for your consideration,</em></p>\n</blockquote>\n<blockquote>\n<p><em>(your name)</em></p>\n</blockquote>\n<p><strong>Follow up</strong></p>\n<p>Don't wait for the company to reach out to you! Be proactive in showing your interest by checking in to see where you stand in the process. If a company indicates a deadline by which you will hear back, and the deadline has passed, follow-up!</p>\n<p><strong>Check your email and phone regularly<br>\n‍*</strong><br>\n*Don't ghost on a company at any stage in the process; make sure you add their domain to your safe senders list and respond to any messages within 24 hours.</p>\n<p>‍</p>\n<p><strong>Be prepared<br>\n‍*</strong><br>\n*You might be invited for another interview on short notice; review the description regularly so it doesn't slip from your memory, and keep brushing up on skills you may need for an interview (chances are, this won't be the only job you'll need them for anyway!)</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*H4pwwuDEjkYTWKpJ.gif\" class=\"graf-image\" />\n</figure>\n<hr>\n<blockquote>\n<p>Here I will maintain a running list of applicable job boards and below I will go into detail about the niches they occupy and whatever I resource I have found to use them to your maximum advantage. !</p>\n</blockquote>\n<h3>Update (remote work edition):</h3>\n<ol>\n<li>\n<span id=\"3063\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#arc\" class=\"markup--anchor markup--li-anchor\">Arc</a>\n</span>\n</li>\n<li>\n<span id=\"7639\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#we-work-remotely\" class=\"markup--anchor markup--li-anchor\">We Work Remotely</a>\n</span>\n</li>\n<li>\n<span id=\"e21f\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#skip-the-drive\" class=\"markup--anchor markup--li-anchor\">Skip The Drive</a>\n</span>\n</li>\n<li>\n<span id=\"e1df\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#power-to-fly\" class=\"markup--anchor markup--li-anchor\">Power to Fly</a>\n</span>\n</li>\n<li>\n<span id=\"ecb8\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#remote-ok\" class=\"markup--anchor markup--li-anchor\">Remote OK</a>\n</span>\n</li>\n<li>\n<span id=\"c08c\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#remotive\" class=\"markup--anchor markup--li-anchor\">Remotive</a>\n</span>\n</li>\n<li>\n<span id=\"b4f2\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#flexjobs\" class=\"markup--anchor markup--li-anchor\">FlexJobs</a>\n</span>\n</li>\n<li>\n<span id=\"e670\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#dribble\" class=\"markup--anchor markup--li-anchor\">Dribble</a>\n</span>\n</li>\n<li>\n<span id=\"3b01\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#angellist\" class=\"markup--anchor markup--li-anchor\">AngelList</a>\n</span>\n</li>\n<li>\n<span id=\"4e54\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#remote-co\" class=\"markup--anchor markup--li-anchor\">Remote.co</a>\n</span>\n</li>\n<li>\n<span id=\"043a\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#justremote\" class=\"markup--anchor markup--li-anchor\">JustRemote</a>\n</span>\n</li>\n<li>\n<span id=\"7190\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#virtual-vocations\" class=\"markup--anchor markup--li-anchor\">Virtual Vocations</a>\n</span>\n</li>\n<li>\n<span id=\"8128\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#pangian\" class=\"markup--anchor markup--li-anchor\">Pangian</a>\n</span>\n</li>\n<li>\n<span id=\"f142\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#working-nomads\" class=\"markup--anchor markup--li-anchor\">Working Nomads</a>\n</span>\n</li>\n<li>\n<span id=\"6d89\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#jobspresso\" class=\"markup--anchor markup--li-anchor\">Jobspresso</a>\n</span>\n</li>\n<li>\n<span id=\"8732\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#outsourcely\" class=\"markup--anchor markup--li-anchor\">Outsourcely</a>\n</span>\n</li>\n<li>\n<span id=\"4f25\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#landing-jobs\" class=\"markup--anchor markup--li-anchor\">Landing.Jobs</a>\n</span>\n</li>\n<li>\n<span id=\"f994\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#authentic-jobs\" class=\"markup--anchor markup--li-anchor\">Authentic Jobs</a>\n</span>\n</li>\n<li>\n<span id=\"4b77\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#stack-overflow\" class=\"markup--anchor markup--li-anchor\">Stack Overflow</a>\n</span>\n</li>\n<li>\n<span id=\"bb76\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#gun-io\" class=\"markup--anchor markup--li-anchor\">Gun.io</a>\n</span>\n</li>\n<li>\n<span id=\"114e\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#idealist\" class=\"markup--anchor markup--li-anchor\">Idealist</a>\n</span>\n</li>\n<li>\n<span id=\"5da2\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#fiverr\" class=\"markup--anchor markup--li-anchor\">Fiverr</a>\n</span>\n</li>\n<li>\n<span id=\"fa5e\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#upwork\" class=\"markup--anchor markup--li-anchor\">Upwork</a>\n</span>\n</li>\n<li>\n<span id=\"f209\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#freelancer\" class=\"markup--anchor markup--li-anchor\">Freelancer</a>\n</span>\n</li>\n<li>\n<span id=\"5ec4\">\n<a href=\"https://www.freecodecamp.org/news/how-to-find-remote-jobs/#freelancermap\" class=\"markup--anchor markup--li-anchor\">freelancermap</a>\n</span>\n</li>\n</ol>\n<hr>\n<h3>List:</h3>\n<h4>General Boards</h4>\n<ul>\n<li>\n<span id=\"a076\">\n<a href=\"https://builtin.com/jobs\" class=\"markup--anchor markup--li-anchor\">Built In</a>\n</span>\n</li>\n<li>\n<span id=\"c522\">\n<a href=\"https://stackoverflow.com/jobs\" class=\"markup--anchor markup--li-anchor\">Stack Overflow</a>\n</span>\n</li>\n<li>\n<span id=\"8235\">\n<a href=\"http://angel.co/jobs\" class=\"markup--anchor markup--li-anchor\">angel.co</a>\n</span>\n</li>\n<li>\n<span id=\"ae9e\">\n<a href=\"https://www.theladders.com/jobs/search-jobs\" class=\"markup--anchor markup--li-anchor\">The Ladders</a>\n</span>\n</li>\n<li>\n<span id=\"aceb\">\n<a href=\"http://www.crunchboard.com/jobs\" class=\"markup--anchor markup--li-anchor\">CrunchBoard</a>\n</span>\n</li>\n<li>\n<span id=\"7e5f\">\n<a href=\"https://uncubed.com/\" class=\"markup--anchor markup--li-anchor\">Uncubed</a>\n</span>\n</li>\n<li>\n<span id=\"8678\">\n<a href=\"https://technical.ly/jobs/\" class=\"markup--anchor markup--li-anchor\">Technical.ly</a>\n</span>\n</li>\n<li>\n<span id=\"c7fe\">\n<a href=\"https://www.dice.com/\" class=\"markup--anchor markup--li-anchor\">Dice</a>\n</span>\n</li>\n<li>\n<span id=\"23f7\">\n<a href=\"https://www.techcareers.com/\" class=\"markup--anchor markup--li-anchor\">Tech Careers</a>\n</span>\n</li>\n<li>\n<span id=\"20cf\">\n<a href=\"http://jobs.mashable.com/jobs/search/results\" class=\"markup--anchor markup--li-anchor\">Mashable</a>\n</span>\n</li>\n</ul>\n<h4>Remote or Relocation Boards:</h4>\n<ul>\n<li>\n<span id=\"1e47\">\n<a href=\"https://weworkremotely.com/\" class=\"markup--anchor markup--li-anchor\">We Work Remotely</a>\n</span>\n</li>\n<li>\n<span id=\"37d2\">\n<a href=\"https://relocate.me/\" class=\"markup--anchor markup--li-anchor\">Relocate</a>\n<a href=\"https://workfromhomejobs.me/\" class=\"markup--anchor markup--li-anchor\">‍</a>\n</span>\n</li>\n<li>\n<span id=\"aad7\">\n<a href=\"https://workfromhomejobs.me/\" class=\"markup--anchor markup--li-anchor\">Work From Home Jobs</a>\n</span>\n</li>\n<li>\n<span id=\"d1fc\">\n<a href=\"https://docs.google.com/spreadsheets/d/16V7hG7l24hBAnlcmaSG3mrusDx1uj_ZsLwnTu7L_wsQ/edit?usp=sharing\" class=\"markup--anchor markup--li-anchor\">Remote Boards &amp; Companies Spreadsheet</a>\n</span>\n</li>\n<li>\n<span id=\"5267\">\n<a href=\"https://careervault.io/\" class=\"markup--anchor markup--li-anchor\">Career Vault</a>\n</span>\n</li>\n</ul>\n<h4>DS Boards:</h4>\n<ul>\n<li>\n<span id=\"a50a\">\n<a href=\"https://www.bigdatajobs.com/\" class=\"markup--anchor markup--li-anchor\">BigDataJobs</a>\n</span>\n</li>\n<li>\n<span id=\"e7ce\">\n<a href=\"https://icrunchdata.com/data-science-jobs/\" class=\"markup--anchor markup--li-anchor\">Icrunchdata</a>\n</span>\n</li>\n<li>\n<span id=\"d66f\">\n<a href=\"https://www.analyticsjobs.co.uk/\" class=\"markup--anchor markup--li-anchor\">Analyticsjobs.co.uk</a>\n</span>\n</li>\n</ul>\n<h4>Design Boards</h4>\n<ul>\n<li>\n<span id=\"0a09\">\n<a href=\"https://www.behance.net/joblist\" class=\"markup--anchor markup--li-anchor\">Behance</a>\n</span>\n</li>\n<li>\n<span id=\"0174\">\n<a href=\"https://www.uxjobsboard.com/\" class=\"markup--anchor markup--li-anchor\">UX Jobs Board</a>\n</span>\n</li>\n<li>\n<span id=\"ef44\">\n<a href=\"https://www.krop.com/creative-jobs/ux-ui-designer/\" class=\"markup--anchor markup--li-anchor\">Krop</a>\n</span>\n</li>\n</ul>\n<h4>Software Development</h4>\n<ul>\n<li>\n<span id=\"4702\">\n<a href=\"https://www.honeypot.io/pages/for_employers\" class=\"markup--anchor markup--li-anchor\">Honeypot.io</a>\n</span>\n</li>\n<li>\n<span id=\"d025\">\n<a href=\"https://jobs.github.com/\" class=\"markup--anchor markup--li-anchor\">GitHub</a>\n</span>\n</li>\n<li>\n<span id=\"ed46\">\n<a href=\"https://blabladev.eu/\" class=\"markup--anchor markup--li-anchor\">BlablaDev</a>\n</span>\n</li>\n<li>\n<span id=\"c23f\">\n<a href=\"http://jobs.smashingmagazine.com/\" class=\"markup--anchor markup--li-anchor\">Smashing <strong>Magazine</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"61fd\">\n<a href=\"http://jobs.arstechnica.com/\" class=\"markup--anchor markup--li-anchor\">arstechnica</a>\n</span>\n</li>\n<li>\n<span id=\"c526\">\n<a href=\"http://jobs.37signals.com/\" class=\"markup--anchor markup--li-anchor\">obs.37signals</a>\n</span>\n</li>\n<li>\n<span id=\"1ec6\">\n<a href=\"http://news.ycombinator.com/submitted?id=whoishiring\" class=\"markup--anchor markup--li-anchor\">ycombinator</a>\n</span>\n</li>\n<li>\n<span id=\"fa87\">\n<a href=\"http://jobs.slashdot.org/jobboard.php\" class=\"markup--anchor markup--li-anchor\">jobs.slashdot.org</a>\n</span>\n</li>\n<li>\n<span id=\"3dfc\">\n<a href=\"http://angel.co/talent\" class=\"markup--anchor markup--li-anchor\">http://angel.co/talent</a>\n</span>\n</li>\n<li>\n<span id=\"319e\">\n<a href=\"https://www.whitetruffle.com/\" class=\"markup--anchor markup--li-anchor\">whitetruffle</a>\n</span>\n</li>\n<li>\n<span id=\"428a\">\n<a href=\"http://www.crunchboard.com/jobs/\" class=\"markup--anchor markup--li-anchor\">crunchboard</a>\n</span>\n</li>\n</ul>\n<p><strong>I am intentionally not linking glassdoor because they have irritated me for the last time by insisting I provide a job review every time I want to access their content… (To the makers of glassdoor… HOW MANY TIMES A MONTH DO YOU THINK I CHANGE JOBS!!!!) I don't have 15 minutes to make up a job experience every time I want to read a review.</strong></p>\n<hr>\n<blockquote>\n<p>Also here is a repo of compiled job search and interviewing resources:</p>\n</blockquote>\n<a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE\">\n<strong>bgoonz/INTERVIEW-PREP-COMPLETE</strong>\n<br />\n<em>Your resume is your personal summary sheet. Your resume is the thing that gets your foot in the door. So, there's a few…</em>github.com</a>\n<a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*3_3Cb73SQM_YazWGpZWtIw.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*aI1PfkSpsUks598LAJvKoQ.png\" class=\"graf-image\" />\n</figure>\n<h4>First off I am going to introduce a few different categories for those of you who are completely overwhelmed by the prospect of even selecting a job board let alone establishing a competitive presence on one. Here's a few catorizations I think are worth distinguishing for one and other.</h4>\n<h3>1. Interpersonal Connections</h3>\n<p>Seek to leverage the connections you have with people you know and companies you want to work with. I know that that's a violation of the premise of this article but without even feeling the need to provide quantitative proof; I can confidently assume that this is the most <a href=\"https://www.investopedia.com/terms/r/returnoninvestment.asp\" class=\"markup--anchor markup--p-anchor\">RO</a>I efficient way to produce a desirable result. (Sorry introverts… 2020 may have been your year but this is our world. 😘)</p>\n<p><strong>If personal connections don't come through, the next best thing is cold outreach (<em>best in terms of results…. personally I hate cold calling strangers and I am an extrovert</em>.)</strong></p>\n<ol>\n<li><span id=\"2139\">Before or after submitting an application, <strong>identify 1-3 professionals to reach out to</strong> at the company to express interest in opportunities.</span></li>\n<li><span id=\"fb8b\"><strong>Send a message to express interest and request an informational interview</strong> with the individual via LinkedIn, email, Twitter, or other available communication methods.</span></li>\n<li><span id=\"840d\"><strong>If you hear back</strong> and the individual is willing to connect, <strong>confirm a day and time to conduct a preliminary interview.</strong> <em>OR</em> <strong>If you have yet to hear back after 3 business days, follow-up.</strong></span></li>\n</ol>\n<p>Once you send off a message in step two, there are a variety of responses you may receive. Sometimes an individual will forward you along to someone who may be of better assistance, other times your message may be overlooked with no reply, and its possible (best case scenario) your request for a chat becomes an invitation to interview.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*3_3Cb73SQM_YazWGpZWtIw.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*aI1PfkSpsUks598LAJvKoQ.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*5eObFD9fV2fe5DztitZfsA.png\" class=\"graf-image\" />\n</figure>### ***2. LinkedIn***.\n<p>I am going to devote a lot of time to this one because it is the largest and most active of all the job board ecosystems… period… full stop regardless of your industry.</p>\n<p>LinkedIn now has <a href=\"https://news.linkedin.com/about-us#Statistics\" class=\"markup--anchor markup--p-anchor\">almost 740 million members</a> with over 55 million registered companies. (for comparison 12.3 million people visited Indeed in October, up 19.6 percent. <a href=\"http://www.monster.com/\" class=\"markup--anchor markup--p-anchor\">Monster.com</a> attracted 12.1 million people, and <a href=\"http://www.careerbuilder.com/\" class=\"markup--anchor markup--p-anchor\">CareerBuilder.com</a>attractedd 11.3 million in that same time) and LinkedIn is the most-used social media platform amongst Fortune 500 companies as it provides far more networking capabilities than pure recruitment.</p>\n<p>If you put your resume and skills on LinkedIn.com as a software Engineer, and state that you are open to new opportunities, you <em>will</em> be contacted by multiple recruiters, and if your skills are desirable possibly also directly by companies seeking to hire you. It's a developer's market; there's not enough people out there, especially in America.</p>\n<p>Here's my profile… feel free to connect… the larger your network the greater your exposure is to someone who works at your potential dream job.</p>\n<a href=\"https://www.linkedin.com/in/bryan-guner-046199128/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://www.linkedin.com/in/bryan-guner-046199128/\">\n<strong>Bryan Guner - Web Developer - Freelance | LinkedIn</strong>\n<br />\n<em>View Bryan Guner's profile on LinkedIn, the world's largest professional community. Bryan has 5 jobs listed on their…</em>www.linkedin.com</a>\n<a href=\"https://www.linkedin.com/in/bryan-guner-046199128/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>Here's A Linkedin Checklist I will be using before I return to the job hunt!</p>\n<a href=\"https://www.notion.so/LinkedIn-d8b35e25ff0c451dbb5506ffa1179a8d\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://www.notion.so/LinkedIn-d8b35e25ff0c451dbb5506ffa1179a8d\">\n<strong>LinkedIn</strong>\n<br />\n<em>Personal and Contact Information:</em>www.notion.so</a>\n<a href=\"https://www.notion.so/LinkedIn-d8b35e25ff0c451dbb5506ffa1179a8d\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<blockquote>\n<p>excerpt:</p>\n</blockquote>\n<h4>Experience Section</h4>\n<ul>\n<li><span id=\"a517\">[ ] I <strong>have</strong> listed all professional roles included on my resume in this section and any that I had to cut from my resume for space</span></li>\n<li><span id=\"eca7\">[ ] I <strong>have</strong> written 2-4 power statements for each experience listed (okay to copy and paste from resume)</span></li>\n<li><span id=\"d298\">[ ] My power statements for each experience <a href=\"https://www.linkedin.com/pulse/update-how-add-bullet-points-your-linkedin-profile-erin-dore-miller/\" class=\"markup--anchor markup--li-anchor\">are bulleted</a>, not in paragraph form.</span></li>\n<li><span id=\"ec6c\">[ ] I <strong>did</strong> list responsibilities in bullet point format (I <strong>did not</strong> leave in paragraph format)</span></li>\n<li><span id=\"f472\">[ ] I <strong>did</strong> start each bullet point with <a href=\"https://docs.google.com/document/d/1wZkDPBWtQZDGGdvStD61iRx_jOWVlIyyQl9UOYHtZgA/edit?usp=sharing\" class=\"markup--anchor markup--li-anchor\">an action verb</a> and I <strong>did not</strong> use phrases such as: <code class=\"language-text\">Assisted with...</code> <code class=\"language-text\">Worked on...</code> <code class=\"language-text\">Helped with...</code> (<code class=\"language-text\">Solely responsible for...</code> ok)</span></li>\n<li><span id=\"9a26\">[ ] I <strong>did</strong> describe past projects in past tense and current projects in present tense</span></li>\n<li><span id=\"0f5a\">[ ] I <strong>did not</strong> use pronouns such as: \"I,\" \"we,\" \"they, \"you,\" \"me,\" \"us\"</span></li>\n<li><span id=\"3616\">[ ] <strong>Optional:</strong> Bootcamp student experience and projects can be listed under your experience section if you have no (or almost no) prior work experience.</span></li>\n<li><span id=\"7fa1\">[ ] If I listed my Bootcamp student experience, my title is [name of program] Student (example: Data Science Student)</span></li>\n<li><span id=\"c928\">[ ] I copied and pasted my Lambda projects in my student description and also included them in the Accomplishments section</span></li>\n</ul>\n<h3>Do's:</h3>\n<p><strong>Spend a good portion of your time learning and reading. Your jobs teach you so much about an organization and the business.</strong></p>\n<p><strong>Follow business owners and senior managers, successful team leaders in large organizations, startup owners. You would be surprised how willing some otherwise busy executives are to rub elbows with veritable newcomers. They're not just doing this out of the kindness of their hearts, just like you… they have an ulterior motive. They are hoping to build goodwill with the incoming workforce in a bid to make their company more attractive to high quality candidates. If they give you any of their time…treat it like an interview.</strong></p>\n<blockquote>\n<p><em>To leverage this information, (the trick is to constantly remind yourself to be on your game with speaking with them.) I do not care what your teacher's past have said… mark my words…</em> <strong>*THERE IS MOST CERTAINLY SUCH A THING AS A STUPID QUESTION**</strong>…Anyone who tells you otherwise is either stupid themselves or just overcome with their own compassion (an admirable trait but ultimately a disservice to you the competitive job seeker).*</p>\n</blockquote>\n<a href=\"https://hbr.org/2018/05/the-surprising-power-of-questions\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://hbr.org/2018/05/the-surprising-power-of-questions\">\n<strong>How to Ask Great Questions</strong>\n<br />\n<em>In Brief The Problem Some professionals such as litigators, journalists and even doctors, are taught to ask questions…</em>hbr.org</a>\n<a href=\"https://hbr.org/2018/05/the-surprising-power-of-questions\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<blockquote>\n<p>Engage in networking. I would recommend <strong>finding and connecting with current attendee of any software development bootcamp</strong>. They're all (for the most part) programatically encouraged to connect network and engage in peer skill promotion (even if they have no idea of you skill level). If that weren't enough reason, all of them come from a cohort of other individuals being instructed to do the same. Once you have a few in your network other's will seek you out through Linkedin recommendations algorithm.</p>\n</blockquote>\n<blockquote>\n<p><strong>Note to prospective employers please just skip the next few sentences and don't ask why…😅</strong></p>\n</blockquote>\n<blockquote>\n<p><strong>Of the 214 people that vouched for me… I guestimate about only 80 actually know me in any respectable capacity, and of those, only probably 30 or so are familiar with my competency in the skills they endorsed. It all boils down to the strategies that bootcamps instill in their students. It's the polar opposite of a zero sum game and they're more than happy to exchange personal recommendations with you. They're also far more driven to consistently engage with other members of the linkedin ecosystem because they need to a network to help compensate for their lack of a four year degree and the connections you make in that time.</strong></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/400/1*E519LWHx8W3CXw6c5FXgqg.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1000/1*AUDMmyZrugM3SSy_0axgfQ.jpeg\" class=\"graf-image\" />\n</figure>\n<blockquote>\n<p>Build your personal brand. Developing your brand will not only help you attract clients or recruits if you decide to start a business, but will also help you find great job opportunities. You can post anything you take pride in so long as it's fairly professional. Definitely make use of the featured section to showcase your work.</p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*DlqWg94B670bgin5STdJNg.png\" class=\"graf-image\" />\n</figure>### Don't:\n<h4>Don't Use LinkedIn's Default Headline</h4>\n<p>LinkedIn automatically populates your headline with your current job title and company name. I hope it goes without saying… but as a rule avoid signaling to prospective employers the depths of your laziness by using any stock responses LinkedIn provides you.</p>\n<h4>Don't Go Ham On Keyword Placment</h4>\n<p>Placing keywords strategically into your LinkedIn profile is virtually the only way to ensure being flagged by search algorithms as a potential candidate.You could be forgiven for being tempted to heed the advice of your inner lizard brain, and just stuffing your profile with buzzwords but this will likely trigger a spam account checker and result in worse outcomes than the absence of said keywords.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*3_3Cb73SQM_YazWGpZWtIw.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*aI1PfkSpsUks598LAJvKoQ.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Why it matters<em>¿</em></h3>\n<h4>Are We Really All Connected by Just Six Degrees of Separation?</h4>\n<p>Most of us are familiar with the concept of six degrees of separation — the idea is that anyone in the planet can be connected to anyone else in just six steps. So through just five other people, you're effectively connected to the Queen of England, Jim Belushi or even yo mamma.</p>\n<hr>\n<h3>Back to the other Job Board Niches:</h3>\n<p><strong><em>3. Traditional job boards</em></strong>. Dice.com, Monster.com, etc. They will not find you great jobs at technology companies; they may find you openings as a software engineer at other types of more traditional companies (for example, banks, retail chains, etc though.</p>\n<p><strong><em>4. Local-focused sites</em></strong>. The biggest is Craigslist, but there are others. Often great for contract work and opportunities you wouldn't have otherwise come across.</p>\n<p><strong><em>5. Freelancer websites</em></strong>. oDesk.com, Elance.com, etc. Lower pay, but 100% contract work, and has a lot of flexible opportunities if you're not looking for traditional full-time employment or remote work.</p>\n<ul>\n<li>\n<span id=\"1350\">\n<a href=\"https://www.quora.com/What-are-the-best-job-boards-for-software-engineers\" class=\"markup--anchor markup--li-anchor\">Source</a>\n</span>\n</li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*3_3Cb73SQM_YazWGpZWtIw.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*aI1PfkSpsUks598LAJvKoQ.png\" class=\"graf-image\" />\n</figure>\n<h3>Lastly Here's A Github Profile Guide:</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*0nYkgla6oc0uImSZJElpdw.jpeg\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*wIhqnhU5zoyIr1GwZ2UTNA.jpeg\" class=\"graf-image\" />\n</figure>Medium is causing strange formatting… they normally form a grid!\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*-ypWlmloBF6kz9UnVG2kOA.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*Y9SdKz9cS3FtjlKaRge3jg.png\" class=\"graf-image\" />\n</figure>### Rubric:\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*5-FYxWj0q8sUvpDoAR3ZLA.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Discover More:</h3>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonz-blog.netlify.app/\">\n<strong>Web-Dev-Hub</strong>\n<br />\n<em>Memoization, Tabulation, and Sorting Algorithms by Example Why is looking at runtime not a reliable method of…</em>bgoonz-blog.netlify.app</a>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h1><strong>General</strong></h1>\n<ul>\n<li><strong><a href=\"https://haseebq.com/how-to-break-into-tech-job-hunting-and-interviews/\">How To Break Into Tech - Job Hunting and Interviews by Haseeb Qureshi</a></strong></li>\n<li><strong><a href=\"https://mintbean.io/\">Mintbean.io - Hackathons and Workshops</a></strong></li>\n<li><strong><a href=\"https://talent.works/category/science-of-the-job-search/\">Data on the job search and how to do it!</a></strong></li>\n<li><strong><a href=\"https://www.linkedin.com/post-inspector/inspect/\">LinkedIn Post Inspector</a></strong></li>\n<li><strong><a href=\"https://medium.com/@jamesyhiggs/how-to-add-thumbnail-images-to-the-featured-section-of-your-linkedin-profile-for-web-apps-sites-917346235932\">LinkedIn Featured Images</a></strong></li>\n<li><strong><a href=\"https://frontendmasters.com/\">Frontend Masters</a></strong> - Expensive, but worth every penny</li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Resume</strong></h1>\n<ul>\n<li><strong><a href=\"http://blog.alinelerner.com/lessons-from-a-years-worth-of-hiring-data/\">Spelling/Grammar mistakes on Resume costs jobs</a></strong></li>\n</ul>\n<h1><strong>Cover Letter</strong></h1>\n<ul>\n<li><strong><a href=\"http://www.fsb.miamioh.edu/fsb/content/programs/howe-writing-initiative/HWI-handout-CsofBusComm.html\">Six C's of Business Communication</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Heroku</strong> - <em>Use at your own risk</em></h1>\n<ul>\n<li><strong><a href=\"https://medium.com/@pandachain/keep-free-heroku-app-awake-during-a-specific-period-using-google-app-script-in-2017-63fe37ee9e9f\">Keep Heroku App Awake For Free Using Google App Script</a></strong></li>\n<li><strong><a href=\"https://uptimerobot.com/\">UptimeRobot</a></strong></li>\n<li><strong><a href=\"https://kaffeine.herokuapp.com/\">Kaffeine</a></strong></li>\n<li><strong><a href=\"https://docs.google.com/document/d/1_BZswbvmcEtVul9gD59Lk4IUk2mHp1Wbe2ucaHTY7A0/edit\">UptimeRobot and Dyno Lecture</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Trivia</strong></h1>\n<ul>\n<li>\n<h2><strong>JavaScript Trivia</strong></h2>\n<ul>\n<li><strong><a href=\"https://www.fullstack.cafe/\">Fullstack Cafe - EVERYTHING</a></strong></li>\n<li><strong><a href=\"https://www.thatjsdude.com/interview/\">Front-end trivia</a></strong></li>\n</ul>\n</li>\n<li>\n<h2><strong>Python Trivia</strong></h2>\n</li>\n<li>\n<h2><strong>Frontend Trivia</strong></h2>\n<ul>\n<li><a href=\"https://www.toptal.com/designers/web/interview-questions\"><strong>12 Essential Web Design Interview Questions</strong></a></li>\n</ul>\n</li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Language Resources</strong></h1>\n<ul>\n<li>\n<h2><strong>JavaScript Resources</strong></h2>\n<ul>\n<li><strong><a href=\"https://github.com/antonjb/TypeScript-Learning-Plan\">TypeScript Learning Plan</a></strong></li>\n<li>\n<p><strong>React Native</strong></p>\n<ul>\n<li>\n<p><strong><a href=\"https://codewithmosh.com/courses/enrolled\">Code With Mosh Enrolled</a></strong></p>\n<ul>\n<li><em>satagonia@gmail.com / qqqq1111</em></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<h2><strong>Python Resources</strong></h2>\n</li>\n<li>-</li>\n<li>\n<h2><strong>HTML5 Resources</strong></h2>\n<ul>\n<li><a href=\"https://digital.com/tools/html-cheatsheet/\"><strong>HTML5 Cheat Sheet</strong></a></li>\n<li><a href=\"https://www.html5rocks.com/en/resources.html\"><strong>HTML5 Rocks</strong></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML\"><strong>MDN - HTML</strong></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML\"><strong>MDN - HTML5</strong></a></li>\n<li><a href=\"http://html5doctor.com/\"><strong>HTML5 Doctor</strong></a></li>\n<li>-</li>\n</ul>\n</li>\n<li>\n<h2><strong>CSS3 Resources</strong></h2>\n<ul>\n<li><a href=\"https://www.w3schools.com/css/\"><strong>W3 Schools CSS3 Tutorial</strong></a></li>\n<li><a href=\"https://www.tutorialrepublic.com/css-tutorial/\"><strong>Tutorial Republic - Ultimate Tutorial for Beginners</strong></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS\"><strong>MDN - CSS</strong></a></li>\n<li><a href=\"https://www.css3.info/\"><strong>CSS3.info</strong></a></li>\n<li>\n<p><a href=\"https://css-tricks.com/\"><strong>CSS Tricks</strong></a></p>\n<ul>\n<li><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox/\">Complete Guide to Flexbox</a></li>\n<li><a href=\"https://css-tricks.com/snippets/css/complete-guide-grid/\">Complete Guide to Grid</a></li>\n</ul>\n</li>\n<li><a href=\"https://grid.layoutit.com/\"><strong>Interactive CSS Grid Generator</strong></a></li>\n<li><a href=\"http://csszengarden.com/\"><strong>CSS Zen Garden</strong></a></li>\n<li><a href=\"http://flexboxgrid.com/\"><strong>Flexbox Grid (Package)</strong></a></li>\n<li><a href=\"http://www.specifishity.com/\"><strong>Specifishity</strong></a></li>\n<li><a href=\"https://www.onblastblog.com/css3-cheat-sheet/\"><strong>CSS3 Cheat Sheet</strong></a></li>\n<li><a href=\"https://labs.jensimmons.com/\"><strong>Jen Simmons Labs</strong></a></li>\n</ul>\n</li>\n<li>\n<h2><strong>Miscellaneous Resources</strong></h2>\n<ul>\n<li>\n<p><a href=\"https://codepen.io/\"><strong>CodePen</strong></a></p>\n<ul>\n<li><a href=\"https://codepen.io/202/popular/pens/\">2020 Most Popular Pens (replace year for more)</a></li>\n</ul>\n</li>\n<li><a href=\"https://web-design-weekly.com/\"><strong>Web Design Weekly</strong></a></li>\n<li><a href=\"https://responsivedesign.is/\"><strong>Responsive Design Weekly</strong></a></li>\n</ul>\n</li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>DS&#x26;A</strong></h1>\n<ul>\n<li><strong><a href=\"https://leetcode.com/explore\">Leetcode</a></strong></li>\n<li><strong><a href=\"https://www.algoexpert.io/\">AlgoExpert</a></strong></li>\n</ul>\n<h2><strong>Hash Tables:</strong></h2>\n<ul>\n<li>\n<p><strong><a href=\"https://www.youtube.com/watch?v=shs0KM3wKv8\">What is a Hash Table</a></strong></p>\n<ul>\n<li>O(1) for a \"good\" table</li>\n<li>O(n) for a terrible table (lots of collisions, etc.)</li>\n</ul>\n</li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>System Design</strong></h1>\n<ul>\n<li><strong><a href=\"https://www.educative.io/courses/grokking-the-system-design-interview/m2yDVZnQ8lG\">The Basics</a></strong></li>\n<li><strong><a href=\"https://levelup.gitconnected.com/everything-you-need-to-know-about-caching-system-design-932a6bdf3334\">Caching</a></strong></li>\n<li><strong><a href=\"https://codeburst.io/system-design-basics-load-balancer-101-adc4f602d08f\">Load Balancing</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Interviewing</strong></h1>\n<ul>\n<li>\n<h3><strong>Mock Interviewing</strong></h3>\n<ul>\n<li><strong><a href=\"https://interviewing.io/\">Interviewing.io</a></strong></li>\n</ul>\n</li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Networking</strong></h1>\n<ul>\n<li><strong><a href=\"https://www.meetup.com/\">MeetUp</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Managing and Organizing Job Search</strong></h1>\n<ul>\n<li>\n<p><strong><a href=\"notion.so\">Notion</a></strong></p>\n<ul>\n<li>Trillo clone but with added features that make it really great! Consider creating a template for new job seekers!</li>\n</ul>\n</li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Negotiations</strong></h1>\n<ul>\n<li><strong><a href=\"https://haseebq.com/my-ten-rules-for-negotiating-a-job-offer/\">Haseeb's 10 Rules - Part 1</a></strong></li>\n<li><strong><a href=\"https://haseebq.com/how-not-to-bomb-your-offer-negotiation/\">Haseeb's 10 Rules - Part 2</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Portfolio Sites</strong></h1>\n<p>Take 25 minutes to choose a template, download it, rename it githubusername.github.io , git init, and push it to a github repo of the same name:</p>\n<h2><strong>Template Sources</strong></h2>\n<ul>\n<li><a href=\"http://www.free-css.com/template-categories/portfolio\"><strong>Free CSS Templates</strong></a></li>\n<li><a href=\"http://html5up.net/\"><strong>HTML5 UP</strong></a></li>\n<li><a href=\"http://startbootstrap.com/\"><strong>Start Bootstrap</strong></a></li>\n<li><a href=\"https://themewagon.com/top-html-landing-page-templates/\"><strong>Theme Wagon</strong></a></li>\n<li><a href=\"https://templatemo.com/tag/portfolio\"><strong>Templatemo</strong></a></li>\n<li><a href=\"https://onepagelove.com/templates/free-templates\"><strong>One Page Love</strong></a></li>\n<li>Once you've decided on a template, download it to your machine.</li>\n<li>Rename the folder <code class=\"language-text\">{$yourGitHubUserName}.github.io</code>, (e.g. if my GitHub\nusername were QueenOfTheBeyhive, I would name my repo\n<code class=\"language-text\">QueenOfTheBeyhive.github.io</code>). This will be important for deployment to GitHub\npages later.</li>\n<li>Make sure to <code class=\"language-text\">git init</code> and set up your remote repository.</li>\n<li>As always, make sure to read through any provided README for any potentially\nuseful information.</li>\n<li>Take some time to explore the structure, included elements, and default assets\nincluded in the template. Take special note of style sheets and the main HTML\nfile. The main HTML must be called <code class=\"language-text\">index.html</code> and it must be located in the root\nof the directory. If the file is located elsewhere, relocate it to the root and adjust\nany relative paths for any imported scripts or style sheets.</li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>QA Engineering</strong></h1>\n<ul>\n<li><strong><a href=\"https://teamtreehouse.com/library/introduction-to-qa-engineering\">Full course in 7 day trial</a></strong></li>\n<li><strong><a href=\"https://docs.google.com/document/d/1REtlnM0j88iGgIkPmOyeuwf-VdhOSV6U0QkcPEz81Oc/edit\">Prep Notes</a></strong></li>\n</ul>\n<h1><strong>Alternative Roles</strong></h1>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Data Analyst\nSales Engineer\nTechnical Support Engineer\nCustomer Success Engineer\nData Engineer\nDev Ops Engineer\nQA Engineer\nSolutions Engineer\nSupport Engineer\nTechnical Product Manager\nScrum Master\nImplementation Specialist\nTechnical Account Manager</code></pre></div>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Externship</strong></h1>\n<ul>\n<li><strong><a href=\"https://www.insidesherpa.com/\">insidesherpa</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Open Source</strong></h1>\n<ul>\n<li><strong><a href=\"https://opensource.guide/\">GitHub's open source guides</a></strong></li>\n<li><strong><a href=\"https://opensource.com/resources/getting-started-open-source\">Getting started with open source</a></strong></li>\n<li><strong><a href=\"https://www.firsttimersonly.com/\">First timers only</a></strong></li>\n<li><strong><a href=\"https://opensourceunderdogs.com/episodes/\">Open Source Underdogs</a></strong></li>\n<li><strong><a href=\"https://www.codetriage.com/\">Code Triage</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Volunteer</strong></h1>\n<ul>\n<li><strong><a href=\"https://www.codeforamerica.org/\">Code For America</a></strong></li>\n<li><strong><a href=\"https://www.donatecode.com/\">Donate Code</a></strong></li>\n<li><strong><a href=\"https://socialcoder.org/Home/Index\">Social Coder</a></strong></li>\n<li><strong><a href=\"https://www.catchafire.org/\">Catch A Fire</a></strong></li>\n<li><strong><a href=\"https://www.hackersforcharity.org/\">Hackers For Charity</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Imposter Syndrome</strong></h1>\n<ul>\n<li><strong><a href=\"https://www.zainrizvi.io/blog/the-impostors-advantage/\">The Imposter's Advantage - Zain Rizvi</a></strong></li>\n<li><strong><a href=\"https://www.techrepublic.com/article/why-58-of-tech-employees-suffer-from-imposter-syndrome/\">Stats on the tech giants</a></strong></li>\n<li><strong><a href=\"http://blog.alinelerner.com/how-different-is-a-b-s-in-computer-science-from-a-m-s-in-computer-science-when-it-comes-to-recruiting/\">Why MS degrees are shit</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Podcasts</strong></h1>\n<ul>\n<li><strong><a href=\"https://freecodecamp.libsyn.com/\">FreeCodeCamp Podcast</a></strong></li>\n<li><strong><a href=\"https://www.heroku.com/podcasts/codeish/85-the-new-definition-of-frontend-development\">Codish Podcast</a></strong></li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>Books</strong></h1>\n<ul>\n<li>\n<p><strong>Grokking the Coding Interview</strong></p>\n<ul>\n<li><a href=\"https://github.com/cl2333/Grokking-the-Coding-Interview-Patterns-for-Coding-Questions\">GitHub Coding Questions</a></li>\n<li><a href=\"https://www.educative.io/courses/grokking-the-coding-interview\">Purchase Course</a></li>\n</ul>\n</li>\n<li>\n<p><strong>Grokking the System Design Interview</strong></p>\n<ul>\n<li><a href=\"https://github.com/ema2159/Grokking-System-Design-Interview-Quizzes\">Quizzes</a></li>\n<li><a href=\"https://www.educative.io/courses/grokking-the-system-design-interview\">Purchase Course</a></li>\n</ul>\n</li>\n<li><strong>Elements of Programming Interviews (EPI) in Python</strong></li>\n<li>\n<ul>\n<li><a href=\"https://www.amazon.com/Elements-Programming-Interviews-Python-Insiders/dp/1537713949\">Amazon</a></li>\n</ul>\n</li>\n<li>\n<p><strong>Skienna Algorithm Design Manual</strong></p>\n<ul>\n<li><a href=\"https://www.amazon.com/Algorithm-Design-Manual-Steven-Skiena-ebook-dp-B00B8139Z8/dp/B00B8139Z8/ref=mt_other?_encoding=UTF8&#x26;me=&#x26;qid=\">Amazon</a></li>\n</ul>\n</li>\n</ul>\n<br>\n<br>\n<br>\n<br>\n<h1><strong>QA Questions</strong></h1>\n<p><strong>10:22:12 From Alexis Kozak to Everyone : Scenario 1</strong></p>\n<ul>\n<li>It's 7:00 pm on a Friday, and you receive a message from Dev Ops that they haven't been able to upgrade a live Production environment as planned. There were feature updates in this release that customers have planned marketing campaigns around. It also included a bug fix for one customer that's currently having to maintain a very manual workaround. What do you do?</li>\n</ul>\n<p><strong>10:24:40 From Alexis Kozak to Everyone : Scenario 2</strong></p>\n<ul>\n<li>An application has been configured to send an email every time a patient requests a changed email. The automated email sends something to the old email, acknowledging that they changed their email, and if that isn't right, to please contact Secular Health Network. When you come into the office one morning, you see that thousands of emails have been generated in the space of two hours. What do you do? How do you find the number of emails sent?</li>\n</ul>\n<p><strong>10:28:11 From Alexis Kozak to Everyone : Scenario 3</strong></p>\n<ul>\n<li>A customer has requested a change to SSO logic such that only users from a certain region can access SmartExam. You've implemented the rule on their demo environments and given them a testing plan that is simple and straightforward. During testing, you're included in multiple email chains with different parties, as well as some one-off calls and texts messages. Resources seem scattered, but the testing happens. After receiving confirmation from the customer that testing was successful, you're told the code is good to go into production. However, upon doing some quick checks, you discover that the rule you wrote doesn't work and would actually prevent any user from logging into SmartExam. The fix is quite simple. What do you do?</li>\n</ul>"},{"url":"/docs/archive/","relativePath":"docs/archive/index.md","relativeDir":"docs/archive","base":"index.md","name":"index","frontmatter":{"title":"Docs Archive","excerpt":"See some interesting Archive developed by the Web-Dev-Hubcommunity to help automate parts of your workflow.","seo":{"title":"Docs Archive","description":"paste to markdown, excel table to markdown, excel to html, cloud storage, text manipulation, ternary converter, github html preview, form builder, border","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Archive","keyName":"property"},{"name":"og:description","value":"paste to markdown, excel table to markdown, excel to html, cloud storage, text manipulation, ternary converter, github html preview, form builder, border","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Archive"},{"name":"twitter:description","value":"This is the Archive page"},{"name":"og:image","value":"images/tex.png","keyName":"property","relativeUrl":true}]},"template":"docs"},"html":"<h1>   Speach Recognition api </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://random-static-html-deploys.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Sidebar Blog  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://side-bar-blog-4.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1>   Paste To Markdown </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bgoonz.github.io/paste-2-markdown-web/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h1>   Paste Excel Tabel To Markdown </h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://codepen.io/bgoonz/embed/JjNaPpL?default-tab=result&theme-id=light\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1>Paste excel to HTML</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://pedantic-wing-adbf82.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<h1>  Cloud Storage </h1>\n<br>\n<h2> Up to 1TB of cloud Storage for file sharing!</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://onedrive.live.com/embed?cid=D21009FDD967A241&resid=D21009FDD967A241%21538729&authkey=AHSDSyoYqzg2K2E\" height=\"800px\" width=\"100%\" style=\"zoom:0.69; align-self:center;display:auto;display: block;border:12px solid gold;\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>     Resource Archive           </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://resourcerepo2.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Lambda Student Site </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    class=\"inner\" src=\"https://lambda-resources.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Text Tools     </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://devtools42.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Ternary Converter   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://ternary42.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Github HTML Render from link </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://githtmlpreview.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Data Structures</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://determined-dijkstra-ee7390.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Interview     </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\" src=\"https://web-dev-interview-prep-quiz-website.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Form Builder GUI </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\" src=\"https://fourm-builder-gui.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Border Builder </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\" src=\"https://codepen.io/bgoonz/embed/zYwLVmb?default-tab=html%2Cresult\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>                </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://ds-algo-official.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1>                </h1>\n<br>\n <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"1000px\" height=\"800px\" scrolling=\"yes\" title=\"Simple Typing Carousel \" src=\"https://codepen.io/bgoonz/embed/ExZvGoZ?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n  See the Pen <a href=\"https://codepen.io/bgoonz/pen/ExZvGoZ\">\n  Simple Typing Carousel </a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n  on <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  title=\"Fibonacci Carousel\"\n      src=\"https://codepen.io/bgoonz/embed/JjNagJo?default-tab=result&theme-id=dark\"   frameborder=\"yes\" loading=\"lazy\"\n       allowfullscreen=\"true\">\n      See the Pen <a href=\"https://codepen.io/bgoonz/pen/JjNagJo\">\n        Fibonacci Carousel</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n      on <a href=\"https://codepen.io\">CodePen</a>.\n    </iframe>\n<br>\n    <br>\n    <br>\n    <br>\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"1000px\" style=\"width: 1300px;\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  title=\"embed-twitter-feed\"\n      src=\"https://codepen.io/bgoonz/embed/poPOqEO?default-tab=result&theme-id=dark\"   frameborder=\"yes\" loading=\"lazy\"\n       allowfullscreen=\"true\">\n      See the Pen <a href=\"https://codepen.io/bgoonz/pen/poPOqEO\">\n        embed-twitter-feed</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n      on <a href=\"https://codepen.io\">CodePen</a>.\n    </iframe>\n<br>\n    <br>\n    <br>\n    <br>\n\\\n    <br>\n    <br>\n    <br>\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"1000px\" style=\"width: 1300px;\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  src=\"//jsfiddle.net/bgoonz/vtz7820m/embedded/result/dark/\"\n      allowfullscreen=\"allowfullscreen\" frameborder=\"0\">\n</iframe>\n<br>\n    <br>\n    <br>\n    <br>\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"1000px\" style=\"width: 1300px;\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n      src=\"//jsfiddle.net/bgoonz/1dye9uws/2/embedded/js,html,css,result/dark/\" allowfullscreen=\"allowfullscreen\"\n      frameborder=\"0\">\n</iframe>\n<br>\n    <br>\n    <br>\n    <br>\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"1000px\" style=\"width: 1300px;\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  src=\"//jsfiddle.net/bgoonz/3mpgzkx7/1/embedded/\"\n      allowfullscreen=\"allowfullscreen\" frameborder=\"0\">\n</iframe>\n<br>\n    <br>\n    <br>\n    <br>\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" src=\"https://codepen.io/bgoonz/embed/zYwJQaw?default-tab=html%2Cresult\"\n      style=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"hvbrd-sockets (forked)\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n    <br>\n    <br>\n    <!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n    <br>\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" src=\"https://codesandbox.io/embed/bigo-3wqy4?fontsize=14&hidenavigation=1&theme=dark\"\n      style=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"hvbrd-sockets (forked)\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n    <br>\n    <br>\n    <br>\n    <!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\"\n      src=\"https://codesandbox.io/embed/hvbrd-sockets-forked-vsi2o?fontsize=14&hidenavigation=1&theme=dark\"\n      style=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"hvbrd-sockets (forked)\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n    <!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n    <br>\n    <br>\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" src=\"https://codesandbox.io/embed/summer-surf-p6dei?fontsize=14&hidenavigation=1&theme=dark\"\n      style=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"summer-surf-p6dei\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n    <br>\n    <br>\n    <br>\n    <br>\n    <!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n    <br> <br>\n    <br>\n    <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\"\n      src=\"https://codesandbox.io/embed/sharp-feistel-x8bvv?fontsize=14&hidenavigation=1&theme=dark\"\n      style=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"sharp-feistel-x8bvv\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n    <br>\n    <!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n    <!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n    <center>\n      <br>\n      <br>\n      <br>\n      <br>\n      <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\n        title=\"3D Cover Flow in React! | @keyframers 3.7\"\n        src=\"https://codepen.io/bgoonz/embed/ExZvGoZ?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"\n         allowfullscreen=\"true\">\n        See the Pen <a href='https://codepen.io/bgoonz42/pen/RwpeaWr'>3D Cover Flow in React! | @keyframers\n          3.7</a> by Bryan\n        C Guner\n        (<a href='https://codepen.io/bgoonz42'>@bgoonz42</a>) on <a href='https://codepen.io'>CodePen</a>.\n      </iframe>\n<br>\n      <br>\n      <br>\n      <br>\n      <br>\n      <br>\n      <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Simple Typing Carousel \"\n        src=\"https://codepen.io/bgoonz/embed/ExZvGoZ?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"\n         allowfullscreen=\"true\">\n        See the Pen <a href=\"https://codepen.io/bgoonz/pen/ExZvGoZ\">\n          Simple Typing Carousel </a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n        on <a href=\"https://codepen.io\">CodePen</a>.\n      </iframe>\n<br>\n      <br>\n      <br>\n      <br>\n      <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\n        title=\"3D Cover Flow in React! | @keyframers 3.7\"\n        src=\"https://codepen.io/bgoonz42/embed/RwpeaWr?height=375&theme=dark&default-tab=js,result\" frameborder=\"no\"\n        loading=\"lazy\"  allowfullscreen=\"true\">\n        See the Pen <a href='https://codepen.io/bgoonz42/pen/RwpeaWr'>3D Cover Flow in React! | @keyframers\n          3.7</a> by Bryan\n        C Guner\n        (<a href='https://codepen.io/bgoonz42'>@bgoonz42</a>) on <a href='https://codepen.io'>CodePen</a>.\n      </iframe>\n<br>\n      <br>\n      <br>\n      <br>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    &lt;br></code></pre></div>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" src=\"https://portfolio42.netlify.app/\"\n  style=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"hvbrd-sockets (forked)\"\n  sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n<br>\n  <br>\n  <!-------------------------------------------------------------------------------------->\n  <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Video Background 1\"\n    src=\"https://codesandbox.io/embed/bgoonzblog20-oo3x5?fontsize=14&hidenavigation=1&theme=dark\"\n    style=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"bgoonzblog2.0\"\n    sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n  <br>\n  <br>\n  <br>\n  <!-------------------------------------------------------------------------------------->\n  <br>\n  <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Video Background 1\"\n    src=\"https://codepen.io/bgoonz/embed/BaRLKBd?default-tab=html%2Cresult&theme-id=dark\" frameborder=\"no\"\n    loading=\"lazy\"  allowfullscreen=\"true\">\n    See the Pen <a href=\"https://codepen.io/bgoonz/pen/BaRLKBd\">\n      Video Background 1</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n    on <a href=\"https://codepen.io\">CodePen</a>.\n  </iframe>\n<br>\n  <!-------------------------------------------------------------------------------------->\n  <br>\n<br>\n      <!-------------------------------------------------------------------------------------->\n      <br>\n<br>\n      <center>\n        <br>\n        <br>\n        <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\n          title=\"CSS-only Colorful Calendar Concept\" src=\"https://documentation-site-react2.vercel.app/\"\n            frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n          See the Pen <a href=\"https://codepen.io/bgoonz/pen/vYmKQYj\">\n            CSS-only Colorful Calendar Concept</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n          on <a href=\"https://codepen.io\">CodePen</a>.\n        </iframe>\n<br>\n        <br>\n        <br>\n        <br>\n        <!-------------------------------------------------------------------------------------->\n        <br>\n<br>\n        <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"FullTextSearchjs\"\n          src=\"https://codepen.io/bgoonz/embed/QWvMWoQ?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"\n           allowfullscreen=\"true\">\n          See the Pen <a href=\"https://codepen.io/bgoonz/pen/QWvMWoQ\">\n            FullTextSearchjs</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n          on <a href=\"https://codepen.io\">CodePen</a>.\n        </iframe>\n<br>\n        <br>\n        <br>\n        <br>\n        <!-------------------------------------------------------------------------------------->\n        <br>\n        <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"CSS Grid: Info Card\"\n          src=\"https://codepen.io/bgoonz42/embed/MWmpjmy?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"\n           allowfullscreen=\"true\">\n          See the Pen <a href=\"https://codepen.io/bgoonz42/pen/MWmpjmy\">\n            CSS Grid: Info Card</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz42\">@bgoonz42</a>)\n          on <a href=\"https://codepen.io\">CodePen</a>.\n        </iframe>\n<br>\n        <br>\n        <br>\n        <br>\n        <br>\n        <!-------------------------------------------------------------------------------------->\n        <iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\n          title=\"CSS-only Colorful Calendar Concept\"\n          src=\"https://codepen.io/bgoonz/embed/vYmKQYj?default-tab=html%2Cresult&theme-id=dark\" frameborder=\"no\"\n          loading=\"lazy\"  allowfullscreen=\"true\">\n          See the Pen <a href=\"https://codepen.io/bgoonz/pen/vYmKQYj\">\n            CSS-only Colorful Calendar Concept</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n          on <a href=\"https://codepen.io\">CodePen</a>.\n        </iframe>\n<br>\n        <br>\n        <br>\n        <br>"},{"url":"/docs/articles/common-modules/","relativePath":"docs/articles/common-modules.md","relativeDir":"docs/articles","base":"common-modules.md","name":"common-modules","frontmatter":{"title":"Common Modules","weight":0,"excerpt":"resources","seo":{"title":"NodeJS Module System","description":"This section is similar to a blog but is more technical in nature and time invariant with regard to content.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Modules: CommonJS modules<a href=\"https://nodejs.org/api/modules.html#modules_modules_commonjs_modules\">#</a></h2>\n<p><a href=\"https://nodejs.org/api/documentation.html#documentation_stability_index\">Stability: 2</a> - Stable</p>\n<p>In the Node.js module system, each file is treated as a separate module. For example, consider a file named <code class=\"language-text\">foo.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> circle <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./circle.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">The area of a circle of radius 4 is </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>circle<span class=\"token punctuation\">.</span><span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>On the first line, <code class=\"language-text\">foo.js</code> loads the module <code class=\"language-text\">circle.js</code> that is in the same directory as <code class=\"language-text\">foo.js</code>.</p>\n<p>Here are the contents of <code class=\"language-text\">circle.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token constant\">PI</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">area</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">r</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token constant\">PI</span> <span class=\"token operator\">*</span> r <span class=\"token operator\">**</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">circumference</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">r</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token constant\">PI</span> <span class=\"token operator\">*</span> r<span class=\"token punctuation\">;</span></code></pre></div>\n<p>The module <code class=\"language-text\">circle.js</code> has exported the functions <code class=\"language-text\">area()</code> and <code class=\"language-text\">circumference()</code>. Functions and objects are added to the root of a module by specifying additional properties on the special <code class=\"language-text\">exports</code> object.</p>\n<p>Variables local to the module will be private, because the module is wrapped in a function by Node.js (see <a href=\"https://nodejs.org/api/modules.html#modules_the_module_wrapper\">module wrapper</a>). In this example, the variable <code class=\"language-text\">PI</code> is private to <code class=\"language-text\">circle.js</code>.</p>\n<p>The <code class=\"language-text\">module.exports</code> property can be assigned a new value (such as a function or object).</p>\n<p>Below, <code class=\"language-text\">bar.js</code> makes use of the <code class=\"language-text\">square</code> module, which exports a Square class:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> Square <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./square.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> mySquare <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Square</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">The area of mySquare is </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>mySquare<span class=\"token punctuation\">.</span><span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The <code class=\"language-text\">square</code> module is defined in <code class=\"language-text\">square.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// Assigning to exports will not modify module, must use module.exports</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Square</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">width</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> width<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">**</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The module system is implemented in the <code class=\"language-text\">require('module')</code> module.</p>\n<h3>Accessing the main module<a href=\"https://nodejs.org/api/modules.html#modules_accessing_the_main_module\">#</a></h3>\n<p>When a file is run directly from Node.js, <code class=\"language-text\">require.main</code> is set to its <code class=\"language-text\">module</code>. That means that it is possible to determine whether a file has been run directly by testing <code class=\"language-text\">require.main === module</code>.</p>\n<p>For a file <code class=\"language-text\">foo.js</code>, this will be <code class=\"language-text\">true</code> if run via <code class=\"language-text\">node foo.js</code>, but <code class=\"language-text\">false</code> if run by <code class=\"language-text\">require('./foo')</code>.</p>\n<p>Because <code class=\"language-text\">module</code> provides a <code class=\"language-text\">filename</code> property (normally equivalent to <code class=\"language-text\">__filename</code>), the entry point of the current application can be obtained by checking <code class=\"language-text\">require.main.filename</code>.</p>\n<h3>Package manager tips<a href=\"https://nodejs.org/api/modules.html#modules_package_manager_tips\">#</a></h3>\n<p>The semantics of the Node.js <code class=\"language-text\">require()</code> function were designed to be general enough to support reasonable directory structures. Package manager programs such as <code class=\"language-text\">dpkg</code>, <code class=\"language-text\">rpm</code>, and <code class=\"language-text\">npm</code> will hopefully find it possible to build native packages from Node.js modules without modification.</p>\n<p>Below we give a suggested directory structure that could work:</p>\n<p>Let's say that we wanted to have the folder at <code class=\"language-text\">/usr/lib/node/&lt;some-package>/&lt;some-version></code> hold the contents of a specific version of a package.</p>\n<p>Packages can depend on one another. In order to install package <code class=\"language-text\">foo</code>, it may be necessary to install a specific version of package <code class=\"language-text\">bar</code>. The <code class=\"language-text\">bar</code> package may itself have dependencies, and in some cases, these may even collide or form cyclic dependencies.</p>\n<p>Because Node.js looks up the <code class=\"language-text\">realpath</code> of any modules it loads (that is, it resolves symlinks) and then <a href=\"https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders\">looks for their dependencies in <code class=\"language-text\">node_modules</code> folders</a>, this situation can be resolved with the following architecture:</p>\n<ul>\n<li><code class=\"language-text\">/usr/lib/node/foo/1.2.3/</code>: Contents of the <code class=\"language-text\">foo</code> package, version 1.2.3.</li>\n<li><code class=\"language-text\">/usr/lib/node/bar/4.3.2/</code>: Contents of the <code class=\"language-text\">bar</code> package that <code class=\"language-text\">foo</code> depends on.</li>\n<li><code class=\"language-text\">/usr/lib/node/foo/1.2.3/node_modules/bar</code>: Symbolic link to <code class=\"language-text\">/usr/lib/node/bar/4.3.2/</code>.</li>\n<li><code class=\"language-text\">/usr/lib/node/bar/4.3.2/node_modules/*</code>: Symbolic links to the packages that <code class=\"language-text\">bar</code> depends on.</li>\n</ul>\n<p>Thus, even if a cycle is encountered, or if there are dependency conflicts, every module will be able to get a version of its dependency that it can use.</p>\n<p>When the code in the <code class=\"language-text\">foo</code> package does <code class=\"language-text\">require('bar')</code>, it will get the version that is symlinked into <code class=\"language-text\">/usr/lib/node/foo/1.2.3/node_modules/bar</code>. Then, when the code in the <code class=\"language-text\">bar</code> package calls <code class=\"language-text\">require('quux')</code>, it'll get the version that is symlinked into <code class=\"language-text\">/usr/lib/node/bar/4.3.2/node_modules/quux</code>.</p>\n<p>Furthermore, to make the module lookup process even more optimal, rather than putting packages directly in <code class=\"language-text\">/usr/lib/node</code>, we could put them in <code class=\"language-text\">/usr/lib/node_modules/&lt;name>/&lt;version></code>. Then Node.js will not bother looking for missing dependencies in <code class=\"language-text\">/usr/node_modules</code> or <code class=\"language-text\">/node_modules</code>.</p>\n<p>In order to make modules available to the Node.js REPL, it might be useful to also add the <code class=\"language-text\">/usr/lib/node_modules</code> folder to the <code class=\"language-text\">$NODE_PATH</code> environment variable. Since the module lookups using <code class=\"language-text\">node_modules</code> folders are all relative, and based on the real path of the files making the calls to <code class=\"language-text\">require()</code>, the packages themselves can be anywhere.</p>\n<h3>The <code class=\"language-text\">.mjs</code> extension<a href=\"https://nodejs.org/api/modules.html#modules_the_mjs_extension\">#</a></h3>\n<p>It is not possible to <code class=\"language-text\">require()</code> files that have the <code class=\"language-text\">.mjs</code> extension. Attempting to do so will throw <a href=\"https://nodejs.org/api/errors.html#errors_err_require_esm\">an error</a>. The <code class=\"language-text\">.mjs</code> extension is reserved for <a href=\"https://nodejs.org/api/esm.html\">ECMAScript Modules</a> which cannot be loaded via <code class=\"language-text\">require()</code>. See <a href=\"https://nodejs.org/api/esm.html\">ECMAScript Modules</a> for more details.</p>\n<h3>All together...<a href=\"https://nodejs.org/api/modules.html#modules_all_together\">#</a></h3>\n<p>To get the exact filename that will be loaded when <code class=\"language-text\">require()</code> is called, use the <code class=\"language-text\">require.resolve()</code> function.</p>\n<p>Putting together all of the above, here is the high-level algorithm in pseudocode of what <code class=\"language-text\">require()</code> does:</p>\n<p>require(X) from module at path Y</p>\n<ol>\n<li>If X is a core module,\na. return the core module\nb. STOP</li>\n<li>If X begins with '/'\na. set Y to be the filesystem root</li>\n<li>If X begins with './' or '/' or '../'\na. LOAD<em>AS</em>FILE(Y + X)\nb. LOAD<em>AS</em>DIRECTORY(Y + X)\nc. THROW \"not found\"</li>\n<li>If X begins with '#'\na. LOAD<em>PACKAGE</em>IMPORTS(X, dirname(Y))</li>\n<li>LOAD<em>PACKAGE</em>SELF(X, dirname(Y))</li>\n<li>LOAD<em>NODE</em>MODULES(X, dirname(Y))</li>\n<li>THROW \"not found\"</li>\n</ol>\n<p>LOAD<em>AS</em>FILE(X)</p>\n<ol>\n<li>If X is a file, load X as its file extension format. STOP</li>\n<li>If X.js is a file, load X.js as JavaScript text. STOP</li>\n<li>If X.json is a file, parse X.json to a JavaScript Object. STOP</li>\n<li>If X.node is a file, load X.node as binary addon. STOP</li>\n</ol>\n<p>LOAD_INDEX(X)</p>\n<ol>\n<li>If X/index.js is a file, load X/index.js as JavaScript text. STOP</li>\n<li>If X/index.json is a file, parse X/index.json to a JavaScript object. STOP</li>\n<li>If X/index.node is a file, load X/index.node as binary addon. STOP</li>\n</ol>\n<p>LOAD<em>AS</em>DIRECTORY(X)</p>\n<ol>\n<li>If X/package.json is a file,\na. Parse X/package.json, and look for \"main\" field.\nb. If \"main\" is a falsy value, GOTO 2.\nc. let M = X + (json main field)\nd. LOAD<em>AS</em>FILE(M)\ne. LOAD<em>INDEX(M)\nf. LOAD</em>INDEX(X) DEPRECATED\ng. THROW \"not found\"</li>\n<li>LOAD_INDEX(X)</li>\n</ol>\n<p>LOAD<em>NODE</em>MODULES(X, START)</p>\n<ol>\n<li>let DIRS = NODE<em>MODULES</em>PATHS(START)</li>\n<li>for each DIR in DIRS:\na. LOAD<em>PACKAGE</em>EXPORTS(X, DIR)\nb. LOAD<em>AS</em>FILE(DIR/X)\nc. LOAD<em>AS</em>DIRECTORY(DIR/X)</li>\n</ol>\n<p>NODE<em>MODULES</em>PATHS(START)</p>\n<ol>\n<li>let PARTS = path split(START)</li>\n<li>let I = count of PARTS - 1</li>\n<li>let DIRS = [GLOBAL_FOLDERS]</li>\n<li>while I >= 0,\na. if PARTS[I] = \"node<em>modules\" CONTINUE\nb. DIR = path join(PARTS[0 .. I] + \"node</em>modules\")\nc. DIRS = DIRS + DIR\nd. let I = I - 1</li>\n<li>return DIRS</li>\n</ol>\n<p>LOAD<em>PACKAGE</em>IMPORTS(X, DIR)</p>\n<ol>\n<li>Find the closest package scope SCOPE to DIR.</li>\n<li>If no scope was found, return.</li>\n<li>If the SCOPE/package.json \"imports\" is null or undefined, return.</li>\n<li>let MATCH = PACKAGE<em>IMPORTS</em>RESOLVE(X, pathToFileURL(SCOPE),\n[\"node\", \"require\"]) <a href=\"https://nodejs.org/api/esm.md#resolver-algorithm-specification\">defined in the ESM resolver</a>.</li>\n<li>RESOLVE<em>ESM</em>MATCH(MATCH).</li>\n</ol>\n<p>LOAD<em>PACKAGE</em>EXPORTS(X, DIR)</p>\n<ol>\n<li>Try to interpret X as a combination of NAME and SUBPATH where the name\nmay have a @scope/ prefix and the subpath begins with a slash (<code class=\"language-text\">/</code>).</li>\n<li>If X does not match this pattern or DIR/NAME/package.json is not a file,\nreturn.</li>\n<li>Parse DIR/NAME/package.json, and look for \"exports\" field.</li>\n<li>If \"exports\" is null or undefined, return.</li>\n<li>let MATCH = PACKAGE<em>EXPORTS</em>RESOLVE(pathToFileURL(DIR/NAME), \".\" + SUBPATH,\n<code class=\"language-text\">package.json</code> \"exports\", [\"node\", \"require\"]) <a href=\"https://nodejs.org/api/esm.md#resolver-algorithm-specification\">defined in the ESM resolver</a>.</li>\n<li>RESOLVE<em>ESM</em>MATCH(MATCH)</li>\n</ol>\n<p>LOAD<em>PACKAGE</em>SELF(X, DIR)</p>\n<ol>\n<li>Find the closest package scope SCOPE to DIR.</li>\n<li>If no scope was found, return.</li>\n<li>If the SCOPE/package.json \"exports\" is null or undefined, return.</li>\n<li>If the SCOPE/package.json \"name\" is not the first segment of X, return.</li>\n<li>let MATCH = PACKAGE<em>EXPORTS</em>RESOLVE(pathToFileURL(SCOPE),\n\".\" + X.slice(\"name\".length), <code class=\"language-text\">package.json</code> \"exports\", [\"node\", \"require\"])\n<a href=\"https://nodejs.org/api/esm.md#resolver-algorithm-specification\">defined in the ESM resolver</a>.</li>\n<li>RESOLVE<em>ESM</em>MATCH(MATCH)</li>\n</ol>\n<p>RESOLVE<em>ESM</em>MATCH(MATCH)</p>\n<ol>\n<li>let { RESOLVED, EXACT } = MATCH</li>\n<li>let RESOLVED_PATH = fileURLToPath(RESOLVED)</li>\n<li>If EXACT is true,\na. If the file at RESOLVED<em>PATH exists, load RESOLVED</em>PATH as its extension\nformat. STOP</li>\n<li>Otherwise, if EXACT is false,\na. LOAD<em>AS</em>FILE(RESOLVED<em>PATH)\nb. LOAD</em>AS<em>DIRECTORY(RESOLVED</em>PATH)</li>\n<li>THROW \"not found\"</li>\n</ol>\n<h3>Caching<a href=\"https://nodejs.org/api/modules.html#modules_caching\">#</a></h3>\n<p>Modules are cached after the first time they are loaded. This means (among other things) that every call to <code class=\"language-text\">require('foo')</code> will get exactly the same object returned, if it would resolve to the same file.</p>\n<p>Provided <code class=\"language-text\">require.cache</code> is not modified, multiple calls to <code class=\"language-text\">require('foo')</code> will not cause the module code to be executed multiple times. This is an important feature. With it, \"partially done\" objects can be returned, thus allowing transitive dependencies to be loaded even when they would cause cycles.</p>\n<p>To have a module execute code multiple times, export a function, and call that function.</p>\n<h4>Module caching caveats<a href=\"https://nodejs.org/api/modules.html#modules_module_caching_caveats\">#</a></h4>\n<p>Modules are cached based on their resolved filename. Since modules may resolve to a different filename based on the location of the calling module (loading from <code class=\"language-text\">node_modules</code> folders), it is not a <em>guarantee</em> that <code class=\"language-text\">require('foo')</code> will always return the exact same object, if it would resolve to different files.</p>\n<p>Additionally, on case-insensitive file systems or operating systems, different resolved filenames can point to the same file, but the cache will still treat them as different modules and will reload the file multiple times. For example, <code class=\"language-text\">require('./foo')</code> and <code class=\"language-text\">require('./FOO')</code> return two different objects, irrespective of whether or not <code class=\"language-text\">./foo</code> and <code class=\"language-text\">./FOO</code> are the same file.</p>\n<h3>Core modules<a href=\"https://nodejs.org/api/modules.html#modules_core_modules\">#</a></h3>\n<p>History</p>\n<p>Node.js has several modules compiled into the binary. These modules are described in greater detail elsewhere in this documentation.</p>\n<p>The core modules are defined within the Node.js source and are located in the <code class=\"language-text\">lib/</code> folder.</p>\n<p>Core modules are always preferentially loaded if their identifier is passed to <code class=\"language-text\">require()</code>. For instance, <code class=\"language-text\">require('http')</code> will always return the built in HTTP module, even if there is a file by that name.</p>\n<p>Core modules can also be identified using the <code class=\"language-text\">node:</code> prefix, in which case it bypasses the <code class=\"language-text\">require</code> cache. For instance, <code class=\"language-text\">require('node:http')</code> will always return the built in HTTP module, even if there is <code class=\"language-text\">require.cache</code> entry by that name.</p>\n<h3>Cycles<a href=\"https://nodejs.org/api/modules.html#modules_cycles\">#</a></h3>\n<p>When there are circular <code class=\"language-text\">require()</code> calls, a module might not have finished executing when it is returned.</p>\n<p>Consider this situation:</p>\n<p><code class=\"language-text\">a.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a starting'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nexports<span class=\"token punctuation\">.</span>done <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> b <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./b.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'in a, b.done = %j'</span><span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">.</span>done<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nexports<span class=\"token punctuation\">.</span>done <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a done'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">b.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'b starting'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nexports<span class=\"token punctuation\">.</span>done <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> a <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./a.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'in b, a.done = %j'</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">.</span>done<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nexports<span class=\"token punctuation\">.</span>done <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'b done'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">main.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'main starting'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> a <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./a.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> b <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./b.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'in main, a.done = %j, b.done = %j'</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">.</span>done<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">.</span>done<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>When <code class=\"language-text\">main.js</code> loads <code class=\"language-text\">a.js</code>, then <code class=\"language-text\">a.js</code> in turn loads <code class=\"language-text\">b.js</code>. At that point, <code class=\"language-text\">b.js</code> tries to load <code class=\"language-text\">a.js</code>. In order to prevent an infinite loop, an unfinished copy of the <code class=\"language-text\">a.js</code> exports object is returned to the <code class=\"language-text\">b.js</code> module. <code class=\"language-text\">b.js</code> then finishes loading, and its <code class=\"language-text\">exports</code> object is provided to the <code class=\"language-text\">a.js</code> module.</p>\n<p>By the time <code class=\"language-text\">main.js</code> has loaded both modules, they're both finished. The output of this program would thus be:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">node</span> main.js\nmain starting\na starting\nb starting\n<span class=\"token keyword\">in</span> b, a.done <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span>\nb <span class=\"token keyword\">done</span>\n<span class=\"token keyword\">in</span> a, b.done <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span>\na <span class=\"token keyword\">done</span>\n<span class=\"token keyword\">in</span> main, a.done <span class=\"token operator\">=</span> true, b.done <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span></code></pre></div>\n<p>Careful planning is required to allow cyclic module dependencies to work correctly within an application.</p>\n<h3>File modules<a href=\"https://nodejs.org/api/modules.html#modules_file_modules\">#</a></h3>\n<p>If the exact filename is not found, then Node.js will attempt to load the required filename with the added extensions: <code class=\"language-text\">.js</code>, <code class=\"language-text\">.json</code>, and finally <code class=\"language-text\">.node</code>.</p>\n<p><code class=\"language-text\">.js</code> files are interpreted as JavaScript text files, and <code class=\"language-text\">.json</code> files are parsed as JSON text files. <code class=\"language-text\">.node</code> files are interpreted as compiled addon modules loaded with <code class=\"language-text\">process.dlopen()</code>.</p>\n<p>A required module prefixed with <code class=\"language-text\">'/'</code> is an absolute path to the file. For example, <code class=\"language-text\">require('/home/marco/foo.js')</code> will load the file at <code class=\"language-text\">/home/marco/foo.js</code>.</p>\n<p>A required module prefixed with <code class=\"language-text\">'./'</code> is relative to the file calling <code class=\"language-text\">require()</code>. That is, <code class=\"language-text\">circle.js</code> must be in the same directory as <code class=\"language-text\">foo.js</code> for <code class=\"language-text\">require('./circle')</code> to find it.</p>\n<p>Without a leading <code class=\"language-text\">'/'</code>, <code class=\"language-text\">'./'</code>, or <code class=\"language-text\">'../'</code> to indicate a file, the module must either be a core module or is loaded from a <code class=\"language-text\">node_modules</code> folder.</p>\n<p>If the given path does not exist, <code class=\"language-text\">require()</code> will throw an <a href=\"https://nodejs.org/api/errors.html#errors_class_error\"><code class=\"language-text\">Error</code></a> with its <code class=\"language-text\">code</code> property set to <code class=\"language-text\">'MODULE_NOT_FOUND'</code>.</p>\n<h3>Folders as modules<a href=\"https://nodejs.org/api/modules.html#modules_folders_as_modules\">#</a></h3>\n<p>It is convenient to organize programs and libraries into self-contained directories, and then provide a single entry point to those directories. There are three ways in which a folder may be passed to <code class=\"language-text\">require()</code> as an argument.</p>\n<p>The first is to create a <a href=\"https://nodejs.org/api/packages.html#packages_node_js_package_json_field_definitions\"><code class=\"language-text\">package.json</code></a> file in the root of the folder, which specifies a <code class=\"language-text\">main</code> module. An example <a href=\"https://nodejs.org/api/packages.html#packages_node_js_package_json_field_definitions\"><code class=\"language-text\">package.json</code></a> file might look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"json\"><pre class=\"language-json\"><code class=\"language-json\"><span class=\"token punctuation\">{</span> <span class=\"token property\">\"name\"</span> <span class=\"token operator\">:</span> <span class=\"token string\">\"some-library\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token property\">\"main\"</span> <span class=\"token operator\">:</span> <span class=\"token string\">\"./lib/some-library.js\"</span> <span class=\"token punctuation\">}</span></code></pre></div>\n<p>If this was in a folder at <code class=\"language-text\">./some-library</code>, then <code class=\"language-text\">require('./some-library')</code> would attempt to load <code class=\"language-text\">./some-library/lib/some-library.js</code>.</p>\n<p>This is the extent of the awareness of <code class=\"language-text\">package.json</code> files within Node.js.</p>\n<p>If there is no <a href=\"https://nodejs.org/api/packages.html#packages_node_js_package_json_field_definitions\"><code class=\"language-text\">package.json</code></a> file present in the directory, or if the <a href=\"https://nodejs.org/api/packages.html#packages_main\"><code class=\"language-text\">\"main\"</code></a> entry is missing or cannot be resolved, then Node.js will attempt to load an <code class=\"language-text\">index.js</code> or <code class=\"language-text\">index.node</code> file out of that directory. For example, if there was no <a href=\"https://nodejs.org/api/packages.html#packages_node_js_package_json_field_definitions\"><code class=\"language-text\">package.json</code></a> file in the previous example, then <code class=\"language-text\">require('./some-library')</code> would attempt to load:</p>\n<ul>\n<li><code class=\"language-text\">./some-library/index.js</code></li>\n<li><code class=\"language-text\">./some-library/index.node</code></li>\n</ul>\n<p>If these attempts fail, then Node.js will report the entire module as missing with the default error:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Error: Cannot find module 'some-library'</code></pre></div>\n<h3>Loading from <code class=\"language-text\">node_modules</code> folders<a href=\"https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders\">#</a></h3>\n<p>If the module identifier passed to <code class=\"language-text\">require()</code> is not a <a href=\"https://nodejs.org/api/modules.html#modules_core_modules\">core</a> module, and does not begin with <code class=\"language-text\">'/'</code>, <code class=\"language-text\">'../'</code>, or <code class=\"language-text\">'./'</code>, then Node.js starts at the parent directory of the current module, and adds <code class=\"language-text\">/node_modules</code>, and attempts to load the module from that location. Node.js will not append <code class=\"language-text\">node_modules</code> to a path already ending in <code class=\"language-text\">node_modules</code>.</p>\n<p>If it is not found there, then it moves to the parent directory, and so on, until the root of the file system is reached.</p>\n<p>For example, if the file at <code class=\"language-text\">'/home/ry/projects/foo.js'</code> called <code class=\"language-text\">require('bar.js')</code>, then Node.js would look in the following locations, in this order:</p>\n<ul>\n<li><code class=\"language-text\">/home/ry/projects/node_modules/bar.js</code></li>\n<li><code class=\"language-text\">/home/ry/node_modules/bar.js</code></li>\n<li><code class=\"language-text\">/home/node_modules/bar.js</code></li>\n<li><code class=\"language-text\">/node_modules/bar.js</code></li>\n</ul>\n<p>This allows programs to localize their dependencies, so that they do not clash.</p>\n<p>It is possible to require specific files or sub modules distributed with a module by including a path suffix after the module name. For instance <code class=\"language-text\">require('example-module/path/to/file')</code> would resolve <code class=\"language-text\">path/to/file</code> relative to where <code class=\"language-text\">example-module</code> is located. The suffixed path follows the same module resolution semantics.</p>\n<h3>Loading from the global folders<a href=\"https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders\">#</a></h3>\n<p>If the <code class=\"language-text\">NODE_PATH</code> environment variable is set to a colon-delimited list of absolute paths, then Node.js will search those paths for modules if they are not found elsewhere.</p>\n<p>On Windows, <code class=\"language-text\">NODE_PATH</code> is delimited by semicolons (<code class=\"language-text\">;</code>) instead of colons.</p>\n<p><code class=\"language-text\">NODE_PATH</code> was originally created to support loading modules from varying paths before the current <a href=\"https://nodejs.org/api/modules.html#modules_all_together\">module resolution</a> algorithm was defined.</p>\n<p><code class=\"language-text\">NODE_PATH</code> is still supported, but is less necessary now that the Node.js ecosystem has settled on a convention for locating dependent modules. Sometimes deployments that rely on <code class=\"language-text\">NODE_PATH</code> show surprising behavior when people are unaware that <code class=\"language-text\">NODE_PATH</code> must be set. Sometimes a module's dependencies change, causing a different version (or even a different module) to be loaded as the <code class=\"language-text\">NODE_PATH</code> is searched.</p>\n<p>Additionally, Node.js will search in the following list of GLOBAL_FOLDERS:</p>\n<ul>\n<li>1: <code class=\"language-text\">$HOME/.node_modules</code></li>\n<li>2: <code class=\"language-text\">$HOME/.node_libraries</code></li>\n<li>3: <code class=\"language-text\">$PREFIX/lib/node</code></li>\n</ul>\n<p>Where <code class=\"language-text\">$HOME</code> is the user's home directory, and <code class=\"language-text\">$PREFIX</code> is the Node.js configured <code class=\"language-text\">node_prefix</code>.</p>\n<p>These are mostly for historic reasons.</p>\n<p>It is strongly encouraged to place dependencies in the local <code class=\"language-text\">node_modules</code> folder. These will be loaded faster, and more reliably.</p>\n<h3>The module wrapper<a href=\"https://nodejs.org/api/modules.html#modules_the_module_wrapper\">#</a></h3>\n<p>Before a module's code is executed, Node.js will wrap it with a function wrapper that looks like the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(function(exports, require, module, __filename, __dirname) {\n// Module code actually lives in here\n});</code></pre></div>\n<p>By doing this, Node.js achieves a few things:</p>\n<ul>\n<li>It keeps top-level variables (defined with <code class=\"language-text\">var</code>, <code class=\"language-text\">const</code> or <code class=\"language-text\">let</code>) scoped to the module rather than the global object.</li>\n<li>\n<p>It helps to provide some global-looking variables that are actually specific to the module, such as:</p>\n<ul>\n<li>The <code class=\"language-text\">module</code> and <code class=\"language-text\">exports</code> objects that the implementor can use to export values from the module.</li>\n<li>The convenience variables <code class=\"language-text\">__filename</code> and <code class=\"language-text\">__dirname</code>, containing the module's absolute filename and directory path.</li>\n</ul>\n</li>\n</ul>\n<h3>The module scope<a href=\"https://nodejs.org/api/modules.html#modules_the_module_scope\">#</a></h3>\n<h4><code class=\"language-text\">__dirname</code><a href=\"https://nodejs.org/api/modules.html#modules_dirname\">#</a></h4>\n<p>Added in: v0.1.27</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\"><string></a></li>\n</ul>\n<p>The directory name of the current module. This is the same as the <a href=\"https://nodejs.org/api/path.html#path_path_dirname_path\"><code class=\"language-text\">path.dirname()</code></a> of the <a href=\"https://nodejs.org/api/modules.html#modules_filename\"><code class=\"language-text\">__filename</code></a>.</p>\n<p>Example: running <code class=\"language-text\">node example.js</code> from <code class=\"language-text\">/Users/mjr</code></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>__dirname<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Prints: /Users/mjr</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">.</span><span class=\"token function\">dirname</span><span class=\"token punctuation\">(</span>__filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Prints: /Users/mjr</span></code></pre></div>\n<h4><code class=\"language-text\">__filename</code><a href=\"https://nodejs.org/api/modules.html#modules_filename\">#</a></h4>\n<p>Added in: v0.0.1</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\"><string></a></li>\n</ul>\n<p>The file name of the current module. This is the current module file's absolute path with symlinks resolved.</p>\n<p>For a main program this is not necessarily the same as the file name used in the command line.</p>\n<p>See <a href=\"https://nodejs.org/api/modules.html#modules_dirname\"><code class=\"language-text\">__dirname</code></a> for the directory name of the current module.</p>\n<p>Examples:</p>\n<p>Running <code class=\"language-text\">node example.js</code> from <code class=\"language-text\">/Users/mjr</code></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>__filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Prints: /Users/mjr/example.js</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>__dirname<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Prints: /Users/mjr</span></code></pre></div>\n<p>Given two modules: <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code>, where <code class=\"language-text\">b</code> is a dependency of <code class=\"language-text\">a</code> and there is a directory structure of:</p>\n<ul>\n<li><code class=\"language-text\">/Users/mjr/app/a.js</code></li>\n<li><code class=\"language-text\">/Users/mjr/app/node_modules/b/b.js</code></li>\n</ul>\n<p>References to <code class=\"language-text\">__filename</code> within <code class=\"language-text\">b.js</code> will return <code class=\"language-text\">/Users/mjr/app/node_modules/b/b.js</code> while references to <code class=\"language-text\">__filename</code> within <code class=\"language-text\">a.js</code> will return <code class=\"language-text\">/Users/mjr/app/a.js</code>.</p>\n<h4><code class=\"language-text\">exports</code><a href=\"https://nodejs.org/api/modules.html#modules_exports\">#</a></h4>\n<p>Added in: v0.1.12</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\"><Object></a></li>\n</ul>\n<p>A reference to the <code class=\"language-text\">module.exports</code> that is shorter to type. See the section about the <a href=\"https://nodejs.org/api/modules.html#modules_exports_shortcut\">exports shortcut</a> for details on when to use <code class=\"language-text\">exports</code> and when to use <code class=\"language-text\">module.exports</code>.</p>\n<h4><code class=\"language-text\">module</code><a href=\"https://nodejs.org/api/modules.html#modules_module\">#</a></h4>\n<p>Added in: v0.1.16</p>\n<ul>\n<li><a href=\"https://nodejs.org/api/modules.html#modules_the_module_object\"><module></a></li>\n</ul>\n<p>A reference to the current module, see the section about the <a href=\"https://nodejs.org/api/modules.html#modules_the_module_object\"><code class=\"language-text\">module</code> object</a>. In particular, <code class=\"language-text\">module.exports</code> is used for defining what a module exports and makes available through <code class=\"language-text\">require()</code>.</p>\n<h4><code class=\"language-text\">require(id)</code><a href=\"https://nodejs.org/api/modules.html#modules_require_id\">#</a></h4>\n<p>Added in: v0.1.13</p>\n<ul>\n<li><code class=\"language-text\">id</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\"><string></a> module name or path</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\"><any></a> exported module content</li>\n</ul>\n<p>Used to import modules, <code class=\"language-text\">JSON</code>, and local files. Modules can be imported from <code class=\"language-text\">node_modules</code>. Local modules and JSON files can be imported using a relative path (e.g. <code class=\"language-text\">./</code>, <code class=\"language-text\">./foo</code>, <code class=\"language-text\">./bar/baz</code>, <code class=\"language-text\">../foo</code>) that will be resolved against the directory named by <a href=\"https://nodejs.org/api/modules.html#modules_dirname\"><code class=\"language-text\">__dirname</code></a> (if defined) or the current working directory. The relative paths of POSIX style are resolved in an OS independent fashion, meaning that the examples above will work on Windows in the same way they would on Unix systems.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// Importing a local module with a path relative to the `__dirname` or current</span>\n<span class=\"token comment\">// working directory. (On Windows, this would resolve to .\\path\\myLocalModule.)</span>\n<span class=\"token keyword\">const</span> myLocalModule <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./path/myLocalModule'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Importing a JSON file:</span>\n<span class=\"token keyword\">const</span> jsonData <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./path/filename.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Importing a module from node_modules or Node.js built-in module:</span>\n<span class=\"token keyword\">const</span> crypto <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'crypto'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h5><code class=\"language-text\">require.cache</code><a href=\"https://nodejs.org/api/modules.html#modules_require_cache\">#</a></h5>\n<p>Added in: v0.3.0</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\"><Object></a></li>\n</ul>\n<p>Modules are cached in this object when they are required. By deleting a key value from this object, the next <code class=\"language-text\">require</code> will reload the module. This does not apply to <a href=\"https://nodejs.org/api/addons.html\">native addons</a>, for which reloading will result in an error.</p>\n<p>Adding or replacing entries is also possible. This cache is checked before native modules and if a name matching a native module is added to the cache, only <code class=\"language-text\">node:</code>-prefixed require calls are going to receive the native module. Use with care!</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> assert <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'assert'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> realFs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> fakeFs <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nrequire<span class=\"token punctuation\">.</span>cache<span class=\"token punctuation\">.</span>fs <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">exports</span><span class=\"token operator\">:</span> fakeFs <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">strictEqual</span><span class=\"token punctuation\">(</span><span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> fakeFs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">strictEqual</span><span class=\"token punctuation\">(</span><span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'node:fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> realFs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h5><code class=\"language-text\">require.extensions</code><a href=\"https://nodejs.org/api/modules.html#modules_require_extensions\">#</a></h5>\n<p>Added in: v0.3.0Deprecated since: v0.10.6</p>\n<p><a href=\"https://nodejs.org/api/documentation.html#documentation_stability_index\">Stability: 0</a> - Deprecated</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\"><Object></a></li>\n</ul>\n<p>Instruct <code class=\"language-text\">require</code> on how to handle certain file extensions.</p>\n<p>Process files with the extension <code class=\"language-text\">.sjs</code> as <code class=\"language-text\">.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">require<span class=\"token punctuation\">.</span>extensions<span class=\"token punctuation\">[</span><span class=\"token string\">'.sjs'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> require<span class=\"token punctuation\">.</span>extensions<span class=\"token punctuation\">[</span><span class=\"token string\">'.js'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Deprecated. In the past, this list has been used to load non-JavaScript modules into Node.js by compiling them on-demand. However, in practice, there are much better ways to do this, such as loading modules via some other Node.js program, or compiling them to JavaScript ahead of time.</p>\n<p>Avoid using <code class=\"language-text\">require.extensions</code>. Use could cause subtle bugs and resolving the extensions gets slower with each registered extension.</p>\n<h5><code class=\"language-text\">require.main</code><a href=\"https://nodejs.org/api/modules.html#modules_require_main\">#</a></h5>\n<p>Added in: v0.1.17</p>\n<ul>\n<li><a href=\"https://nodejs.org/api/modules.html#modules_the_module_object\"><module></a></li>\n</ul>\n<p>The <code class=\"language-text\">Module</code> object representing the entry script loaded when the Node.js process launched. See <a href=\"https://nodejs.org/api/modules.html#modules_accessing_the_main_module\">\"Accessing the main module\"</a>.</p>\n<p>In <code class=\"language-text\">entry.js</code> script:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>require<span class=\"token punctuation\">.</span>main<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">node entry<span class=\"token punctuation\">.</span>js</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">Module <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token string\">'.'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> <span class=\"token string\">'/absolute/path/to'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">exports</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">filename</span><span class=\"token operator\">:</span> <span class=\"token string\">'/absolute/path/to/entry.js'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">loaded</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">paths</span><span class=\"token operator\">:</span>\n   <span class=\"token punctuation\">[</span> <span class=\"token string\">'/absolute/path/to/node_modules'</span><span class=\"token punctuation\">,</span>\n     <span class=\"token string\">'/absolute/path/node_modules'</span><span class=\"token punctuation\">,</span>\n     <span class=\"token string\">'/absolute/node_modules'</span><span class=\"token punctuation\">,</span>\n     <span class=\"token string\">'/node_modules'</span> <span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span></code></pre></div>\n<h5><code class=\"language-text\">require.resolve(request[, options])</code><a href=\"https://nodejs.org/api/modules.html#modules_require_resolve_request_options\">#</a></h5>\n<p>History</p>\n<ul>\n<li><code class=\"language-text\">request</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\"><string></a> The module path to resolve.</li>\n<li><code class=\"language-text\">options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\"><Object></a></li>\n<li>\n<ul>\n<li><code class=\"language-text\">paths</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\">&#x3C;string[]></a> Paths to resolve module location from. If present, these paths are used instead of the default resolution paths, with the exception of <a href=\"https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders\">GLOBAL_FOLDERS</a> like <code class=\"language-text\">$HOME/.node_modules</code>, which are always included. Each of these paths is used as a starting point for the module resolution algorithm, meaning that the <code class=\"language-text\">node_modules</code> hierarchy is checked from this location.</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\"><string></a></li>\n</ul>\n<p>Use the internal <code class=\"language-text\">require()</code> machinery to look up the location of a module, but rather than loading the module, just return the resolved filename.</p>\n<p>If the module can not be found, a <code class=\"language-text\">MODULE_NOT_FOUND</code> error is thrown.</p>\n<h6><code class=\"language-text\">require.resolve.paths(request)</code><a href=\"https://nodejs.org/api/modules.html#modules_require_resolve_paths_request\">#</a></h6>\n<p>Added in: v8.9.0</p>\n<ul>\n<li><code class=\"language-text\">request</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\"><string></a> The module path whose lookup paths are being retrieved.</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\">&#x3C;string[]></a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Null_type\"><null></a></li>\n</ul>\n<p>Returns an array containing the paths searched during resolution of <code class=\"language-text\">request</code> or <code class=\"language-text\">null</code> if the <code class=\"language-text\">request</code> string references a core module, for example <code class=\"language-text\">http</code> or <code class=\"language-text\">fs</code>.</p>\n<h3>The <code class=\"language-text\">module</code> object<a href=\"https://nodejs.org/api/modules.html#modules_the_module_object\">#</a></h3>\n<p>Added in: v0.1.16</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\"><Object></a></li>\n</ul>\n<p>In each module, the <code class=\"language-text\">module</code> free variable is a reference to the object representing the current module. For convenience, <code class=\"language-text\">module.exports</code> is also accessible via the <code class=\"language-text\">exports</code> module-global. <code class=\"language-text\">module</code> is not actually a global but rather local to each module.</p>\n<h4><code class=\"language-text\">module.children</code><a href=\"https://nodejs.org/api/modules.html#modules_module_children\">#</a></h4>\n<p>Added in: v0.1.16</p>\n<ul>\n<li><a href=\"https://nodejs.org/api/modules.html#modules_the_module_object\">&#x3C;module[]></a></li>\n</ul>\n<p>The module objects required for the first time by this one.</p>\n<h4><code class=\"language-text\">module.exports</code><a href=\"https://nodejs.org/api/modules.html#modules_module_exports\">#</a></h4>\n<p>Added in: v0.1.16</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\"><Object></a></li>\n</ul>\n<p>The <code class=\"language-text\">module.exports</code> object is created by the <code class=\"language-text\">Module</code> system. Sometimes this is not acceptable; many want their module to be an instance of some class. To do this, assign the desired export object to <code class=\"language-text\">module.exports</code>. Assigning the desired object to <code class=\"language-text\">exports</code> will simply rebind the local <code class=\"language-text\">exports</code> variable, which is probably not what is desired.</p>\n<p>For example, suppose we were making a module called <code class=\"language-text\">a.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> EventEmitter <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'events'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">EventEmitter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Do some work, and after some time emit</span>\n<span class=\"token comment\">// the 'ready' event from the module itself.</span>\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  module<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">.</span><span class=\"token function\">emit</span><span class=\"token punctuation\">(</span><span class=\"token string\">'ready'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Then in another file we could do:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> a <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./a'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\na<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'ready'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'module \"a\" is ready'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Assignment to <code class=\"language-text\">module.exports</code> must be done immediately. It cannot be done in any callbacks. This does not work:</p>\n<p><code class=\"language-text\">x.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token string\">'hello'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">y.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> x <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./x'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h5><code class=\"language-text\">exports</code> shortcut<a href=\"https://nodejs.org/api/modules.html#modules_exports_shortcut\">#</a></h5>\n<p>Added in: v0.1.16</p>\n<p>The <code class=\"language-text\">exports</code> variable is available within a module's file-level scope, and is assigned the value of <code class=\"language-text\">module.exports</code> before the module is evaluated.</p>\n<p>It allows a shortcut, so that <code class=\"language-text\">module.exports.f = ...</code> can be written more succinctly as <code class=\"language-text\">exports.f = ...</code>. However, be aware that like any variable, if a new value is assigned to <code class=\"language-text\">exports</code>, it is no longer bound to <code class=\"language-text\">module.exports</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">module<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">.</span>hello <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Exported from require of module</span>\nexports <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">hello</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Not exported, only available in the module</span></code></pre></div>\n<p>When the <code class=\"language-text\">module.exports</code> property is being completely replaced by a new object, it is common to also reassign <code class=\"language-text\">exports</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// ... etc.</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To illustrate the behavior, imagine this hypothetical implementation of <code class=\"language-text\">require()</code>, which is quite similar to what is actually done by <code class=\"language-text\">require()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">function</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token comment\">/* ... */</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> module <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">exports</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">module<span class=\"token punctuation\">,</span> exports</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Module code here. In this example, define a function.</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">someFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    exports <span class=\"token operator\">=</span> someFunc<span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// At this point, exports is no longer a shortcut to module.exports, and</span>\n    <span class=\"token comment\">// this module will still export an empty default object.</span>\n    module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> someFunc<span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// At this point, the module will now export someFunc, instead of the</span>\n    <span class=\"token comment\">// default object.</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">,</span> module<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> module<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>"},{"url":"/docs/articles/dev-dep/","relativePath":"docs/articles/dev-dep.md","relativeDir":"docs/articles","base":"dev-dep.md","name":"dev-dep","frontmatter":{"title":"Dev Dependencies","sections":[],"seo":{"title":"Dependencies","description":"install an npm package using npm install you are installing it as a dependency. (npm install --production) to avoid installing those development dependencies.\n\n","robots":[],"extra":[{"name":"og:image","value":"images/react2.jpg","keyName":"property","relativeUrl":true},{"name":"og:description","value":"install an npm package using npm install you are installing it as a dependency. (npm install --production) to avoid installing those development dependencies.\n\n","keyName":"property","relativeUrl":false},{"name":"og:type","value":"website","keyName":"property","relativeUrl":false},{"name":"twitter:image","value":"images/browserify-25532eef.png","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image","keyName":"name","relativeUrl":false},{"name":"og:title","value":"Dev Dependencies","keyName":"property","relativeUrl":false}],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>When you install an npm package using <code class=\"language-text\">npm install &lt;package-name></code>, you are installing it as a <strong>dependency</strong>.</p>\n<p>The package is automatically listed in the package.json file, under the <code class=\"language-text\">dependencies</code> list (as of npm 5: before you had to manually specify <code class=\"language-text\">--save</code>).</p>\n<p>When you add the <code class=\"language-text\">-D</code> flag, or <code class=\"language-text\">--save-dev</code>, you are installing it as a development dependency, which adds it to the <code class=\"language-text\">devDependencies</code> list.</p>\n<p>Development dependencies are intended as development-only packages, that are unneeded in production. For example testing packages, webpack or Babel.</p>\n<p>When you go in production, if you type <code class=\"language-text\">npm install</code> and the folder contains a <code class=\"language-text\">package.json</code> file, they are installed, as npm assumes this is a development deploy.</p>\n<p>You need to set the <code class=\"language-text\">--production</code> flag (<code class=\"language-text\">npm install --production</code>) to avoid installing those development dependencies.</p>"},{"url":"/docs/articles/how-the-web-works/","relativePath":"docs/articles/how-the-web-works.md","relativeDir":"docs/articles","base":"how-the-web-works.md","name":"how-the-web-works","frontmatter":{"title":"How The Web Works","weight":0,"excerpt":"We can start by differentiating the Internet and the World Wide Web. These are often confused because the Web is the main use that most people have for the Internet and a common web browser is called \"Internet Explorer\". However, we can properly distinguish between them. The Internet is a collection of inter-connected computers using the TCP/IP protocol to exchange information.","seo":{"title":"","description":"Perhaps the first thing to establish in our discussion of the web is what exactly it is. This chapter will look in brief overview at the core technologies that go together to make the World Wide Web.","robots":[],"extra":[]},"template":"docs"},"html":"<h2>What is the World Wide Web?\n\n</h2>\n<p>Perhaps the first thing to establish in our discussion of the web is what exactly it is. This chapter will look in brief overview at the core technologies that go together to make the World Wide Web.</p>\n<p>We can start by differentiating the Internet and the World Wide Web. These are often confused because the Web is the main use that most people have for the Internet and a common web browser is called \"Internet Explorer\". However, we can properly distinguish between them. The Internet is a collection of inter-connected computers using the TCP/IP protocol to exchange information. The World Wide Web is a particular use of the Internet to exchange HTML web pages (and other documents) using the Hypertext Transfer Protocol (HTTP).</p>\n<p>Let's look briefly at the four basic ingredients of the Web:</p>\n<ul>\n<li>TCP/IP - is a low level message protocol that is used to transfer messages between computers on the Internet.</li>\n<li></li>\n<li>HTTP - is used by a Web Client to make a request to a Web Server and for the server to return the response.</li>\n<li></li>\n<li>URL - is a way of writing down the address of something on the Web so that a browser can work out where to get it from.</li>\n<li>HTML - is a language for writing web pages containing text, images and other content.</li>\n</ul>\n<p>Together, these four technologies allow a web client - the web browser on your computer - to fetch pages from a web server anywhere in the world that might contain links to other documents and so on. It's the links between documents that make this a <em>Web</em> and the Internet that allows it to be the <em>World Wide Web</em>.</p>\n<p>Let's look at each of these technologies in a little more detail; although we'll explore most of them a lot more throughout the rest of this book.</p>\n<h2>TCP/IP and DNS</h2>\n<p>TCP/IP, the Transmission Control Protocol/Internet Protocol, is the standard way of exchanging messages on the Internet - in fact it effectively defines what the Internet is: a network of computers communicating via TCP/IP. For our purposes, there's no need to have a deep understanding of the low level details of TCP/IP, though many of you will learn more about it if you study any networking topics. However there are a few higher level things that touch on how we use the Internet in the context of the World Wide Web.</p>\n<p>A <em>Protocol</em> in this sense is a formal standard for how two machines will talk to each other over a communications channel. It describes what messages are allowed and what they mean and how data is transferred over the network. Later, we'll look at HTTP which is a higher level protocol for web requests. TCP/IP deals with the low level exchange of data and doesn't really care what the content of that data is.</p>\n<p>The Internet is a collection of computer networks joined by physical network channels. Within an organisation, there may be a physical network based on the Ethernet standard (wired or wireless) which effectively connects all computers on the network to each other. Organisations connect to each other via DSL or cable connections. These <em>inter</em>-connected <em>net</em>works make up the Internet. The role of TCP/IP is to allow a computer within one organisation (your laptop) to establish a connection to a computer in another (a web server). Importantly, this connection is a <em>point-to-point</em> connection - like a private channel between the two computers, even though the data is carried by this shared network of networks.</p>\n<p>TCP/IP is a <em>packet oriented</em> protocol. To send a message, it is broken up into small chunks (packets) which are each addressed and sent over the network. The receiving computer intercepts these packets, notices that they are addressed to them, and re-assembles the original message. Packets can arrive out of order (or not at all) and TCP/IP defines what the two communicating computers should do in this case.</p>\n<p>Each computer on the network is assigned a unique <em>IP address</em> which is a 32 bit number usually expressed as four 8 bit digits separated by dots. For example 192.168.1.2 or 137.111.158.22. These numbers are used as the addresses of the packets sent around the Internet. Within an organisation, all computers will share the first part of their address; for example, all Macquarie University computers will have addresses starting with 137.111. This means that any packet sent from within Macquarie to an address in the range 137.111.x.x will find it's destination somewhere inside the organisation. However, if we send a packet to 143.119.160.16 (the NSW Government website) the network protocols need to know that this packet should be forwarded to the NSW Government network before it can be delivered. We can pretend that this all happens by magic (this isn't a networking course) and rest assured that a clever <em>network routing</em> algorithm will get the packets to where they need to go. As long as we know the IP address of the destination computer, we can establish a point-to-point channel and send data back and forth.</p>\n<p>Within your home you might have your own private network, often established by a wireless router that connects to your ADSL or cable service. While this router will have a proper IP address, the network it establishes in your home is a <em>private network</em> and will use one of two address ranges: 192.168.x.x or 10.10.x.x. Both of these are reserved for private use, so that my laptop and your printer might have the same IP address of 192.168.100.13. A trick called Network Address Translation (NAT) carried out by your router allows each of these devices to connect to the Internet through the router, even though they don't have a full IP address. Again, we don't need to worry about the details but sometimes it's useful to know how to communicate directly with devices on your own network, in which case you might start finding out about these private IP addresses.</p>\n<p>A significant issue with the success and ubiquity of the Internet is that we might run out of unique addresses. Since an IP address is a 32 bit number, that means there are only 4,294,967,296 unique addresses. If every computer, mobile phone, printer and electricity meter is to be connected to the Internet, the it's clear that more addresses will be needed. There are two responses to this. The first is that many of these devices share a single IP address (using NAT) which multiplies the number available significantly. THe second is a new standard called IPv6 (rather than IPv4 which I've described here) where addresses are 128 bits long. Most modern devices are able to use IPv6 addressing so the crisis is unlikely to hit us catastrophically.</p>\n<p>IP addresses give a unique identifier for each device but they aren't very easy to remember. We're used to giving the names of web-sites via names like www.nsw.gov.au or sales.example.com. These names are translated into numerical IP addresses via the Domain Name System (DNS) which works using a clever hierarchical algorithm. For example, to work out what sales.example.com means our local DNS server would look at the last part of the address and forward the query to a server that it knows is authoritative for all addresses ending in .com. The .com server may not know which IP address corresponds to sales.example.com so it sends the query on to the DNS server for example.com which will respond with the answer. As the result is passed back to the original DNS server, it is cached (remembered) so that it can be returned more quickly the next time it is requested.</p>\n<p>DNS allows an organisation to set up whatever names it needs and link those names to its servers. It's common to have the main web server called www.example.com but the same server could also be referred to as example.com, sales.example.com or test.example.com. We'll see later how this arrangement can be used to provide a lot of flexibility when setting up web servers.</p>\n<h2>HTTP</h2>\n<p>In 1991 Tim Berners-Lee invented the World Wide Web. He was building on the existing technology of the Internet that allowed computers to exchange information around the world. His invention consisted essentially of three things: the Hypertext Transfer Protocol (HTTP), the Universal Resource Locator (URL) and the Hypertext Markup Language (HTML). HTTP is the language that a web client (your browser) talks to a web server to ask for a page and get the response back. It's a protocol, just like TCP/IP, but it's a much higher level protocol and it's one that we need to understand very well as web programmers.</p>\n<p>HTTP requires that we first establish a point-to-point connection between a client (who is sending a request) and a server (who will fulfil the request if possible). This connection is usually via TCP/IP over the Internet but could also be over any other communication medium such as <a href=\"http://code.google.com/p/bt-http-server/\">bluetooth</a>. Once the connection is established, the conversation can begin.</p>\n<p>One of the important features of HTTP is that it is a simple, text based protocol. The request and response consist of a number of lines of text in a well defined format. Here is an example request that might be sent to a server:</p>\n<p>The first word in the request is always one of the defined <em>HTTP verbs</em> (most frequently GET, HEAD or POST, we'll explore these in more detail later). A GET request asks the server to return the given resource, in this case '/storefront.html' which is probably an HTML file stored somewhere on the server. The last part of the first line (HTTP/1.1) defines the version of the standard that we are using; there was a version 1.0 but most modern browsers will use 1.1. The remaining lines of the request include other <em>headers</em> that qualify the request in some way. The <em>Host</em> header is required and denotes the server that the request is being sent to. The Accept header defines what kinds of document we'd like in return; in this case, any kind of text document is ok. The request ends with a blank line, which is how the server knows that all headers have been received.</p>\n<p>The request is received and processed by the server and a response is sent back to the client containing the web page that was asked for. Again the format of the response is easy to understand:</p>\n<p>The first word of the response must be HTTP/1.1, the remainder of the first line contains a response code (200) and explanation (OK) in this case saying everything is fine, here's the page you asked for. The second header here defines the type of document being returned (it's an HTML page). There is then a blank line which ends the headers (as with the request) and the HTML content is then sent.</p>\n<p>A real request and response pair will have many more headers than this but their format follows this basic pattern: header lines followed by a blank line and an optional body. The point here is that HTTP is a very simple conversation between web client and server.</p>\n<p>One important feature of HTTP is that each request/response pair is independent of every other. This means that all the information about your request must be included in the request headers; the server doesn't remember anything you told it last time. This is one reason that HTTP and the web have been so successful. It is very easy to implement an HTTP server and it can be done on very small devices. This might be one of the reasons why the Web succeeded where other similar systems failed. Since the protocol is so simple, it was easy to write a web server and many people did. This meant that the web was used by many small groups to publish content, forming the groundswell that led to institutional and corporate adoption.</p>\n<p>We'll look at HTTP in more detail later, for now the take home message is:</p>\n<ul>\n<li>HTTP is a simple text based protocol</li>\n<li></li>\n<li>The client (browser) sends a request to the server</li>\n<li></li>\n<li>The server receives the request and returns a response</li>\n<li>The server doesn't need to remember the client - every request is independant.</li>\n<li>The simple nature of HTTP makes it easy to understand and makes writing web servers relatively easy.</li>\n</ul>\n<h2>Uniform Resource Locators: URL</h2>\n<p>Another part of Tim Berners-Lee's invention is the Uniform Resource Locator, URL. These days, URLs are ubiquitous. We see them on advertisments, on the TV, we send them to each other in email, even reference them in books and reports. Most organisations today will have at least one top-level URL for their website and often have many connected to particular services, departments or advertising campaigns.</p>\n<p>See <a href=\"https://pwp.stevecassidy.net/web/urls.html\">the URL chapter</a> for a detaile discussion.</p>\n<h2>Hypertext Markup Language: HTML</h2>\n<p>HTML is the last link in the chain that makes the Web. It is a language that allows authors to write Hypertext documents that include structure and formatting instructions. <em>Hypertext</em> describes the idea of linking one document to another via <em>hyperlinks</em> so that when you activate a link, you jump to a new document. There were hypertext systems before the birth of the web (<a href=\"http://www.xanadu.com/\">Project Xanadu</a>, <a href=\"http://en.wikipedia.org/wiki/HyperCard\">Hypercard</a>) but HTML has been much more successful than any other standard in this space.</p>\n<p>HTML is a <em>Markup Language</em> which means that it provides a way of adding additional information or markup to plain text. In this case, the markup defines the structure of the document - headers, paragraphs, lists, tables - as well as the hypertext features - links and anchors. There are other markup languages, for example LaTeX is used to write scientific papers by adding markup to text (e.g. \\textbf{bold text} or \\section{A heading}). All markup languages have some way of differentiating the text in a document from the markup instructions. In HTML this is via the angle brackets which surround tag names: &#x3C;tag>.</p>\n<p>HTML was invented by Tim Berners-Lee but it derives from an earlier standard called SGML (Standard Generalised Markup Language) that had been in use for some years as a language for writing technical documentation. It came out of work by IBM on their technical documentation and became an industry standard ratified by the ISO. SGML is in fact a meta-standard in that it defines a way of defining a markup language. HTML is one such markup language and can strictly be treated as such; however, since HTML is so much more common than any other SGML language, it is usually treated as a special case. So, for example, while we could use general purpose SGML authoring tools to write HTML, we generally use applications tailored to writing web pages that only understand HTML.</p>\n<p>Another related markup language is <a href=\"http://www.w3.org/XML/\">XML</a>, the eXtensible Markup Language. XML began as an attempt to streamline the SGML standard to make it more suitable for the web. Like SGML, XML is a meta-standard that defines how markup languages can be written. There is a version of HTML defined as an XML language called <a href=\"http://www.w3.org/MarkUp/\">XHTML</a> but this never really took off and the standardisation work around it was stopped in 2010. Instead, XML has become widely used to describe <em>data</em> rather than <em>documents</em> and we'll look at how it is used today on the web later in this book.</p>"},{"url":"/docs/articles/","relativePath":"docs/articles/index.md","relativeDir":"docs/articles","base":"index.md","name":"index","frontmatter":{"title":"Articles","weight":0,"excerpt":"my web development articles","seo":{"title":"","description":"This section is similar to a blog but is more technical in nature and time invariant with regard to content.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Articles</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://codesandbox.io/embed/medium-articles-vdxzf?autoresize=1&fontsize=18&hidenavigation=1&theme=light&view=preview\"\n     style=\"width:1200px; height:800px; border:0; border-radius: 4px; \"\n     title=\"medium-articles\"\n     allow=\"allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>"},{"url":"/docs/articles/fs-module/","relativePath":"docs/articles/fs-module.md","relativeDir":"docs/articles","base":"fs-module.md","name":"fs-module","frontmatter":{"title":"Fs-Module","sections":[],"seo":{"title":"","description":"Fs-Module","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>The <code class=\"language-text\">fs</code> module provides a lot of very useful functionality to access and interact with the file system.</p>\n<p>There is no need to install it. Being part of the Node.js core, it can be used by simply requiring it:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Once you do so, you have access to all its methods, which include:</p>\n<ul>\n<li><code class=\"language-text\">fs.access()</code>: check if the file exists and Node.js can access it with its permissions</li>\n<li><code class=\"language-text\">fs.appendFile()</code>: append data to a file. If the file does not exist, it's created</li>\n<li><code class=\"language-text\">fs.chmod()</code>: change the permissions of a file specified by the filename passed. Related: <code class=\"language-text\">fs.lchmod()</code>, <code class=\"language-text\">fs.fchmod()</code></li>\n<li><code class=\"language-text\">fs.chown()</code>: change the owner and group of a file specified by the filename passed. Related: <code class=\"language-text\">fs.fchown()</code>, <code class=\"language-text\">fs.lchown()</code></li>\n<li><code class=\"language-text\">fs.close()</code>: close a file descriptor</li>\n<li><code class=\"language-text\">fs.copyFile()</code>: copies a file</li>\n<li><code class=\"language-text\">fs.createReadStream()</code>: create a readable file stream</li>\n<li><code class=\"language-text\">fs.createWriteStream()</code>: create a writable file stream</li>\n<li><code class=\"language-text\">fs.link()</code>: create a new hard link to a file</li>\n<li><code class=\"language-text\">fs.mkdir()</code>: create a new folder</li>\n<li><code class=\"language-text\">fs.mkdtemp()</code>: create a temporary directory</li>\n<li><code class=\"language-text\">fs.open()</code>: set the file mode</li>\n<li><code class=\"language-text\">fs.readdir()</code>: read the contents of a directory</li>\n<li><code class=\"language-text\">fs.readFile()</code>: read the content of a file. Related: <code class=\"language-text\">fs.read()</code></li>\n<li><code class=\"language-text\">fs.readlink()</code>: read the value of a symbolic link</li>\n<li><code class=\"language-text\">fs.realpath()</code>: resolve relative file path pointers (<code class=\"language-text\">.</code>, <code class=\"language-text\">..</code>) to the full path</li>\n<li><code class=\"language-text\">fs.rename()</code>: rename a file or folder</li>\n<li><code class=\"language-text\">fs.rmdir()</code>: remove a folder</li>\n<li><code class=\"language-text\">fs.stat()</code>: returns the status of the file identified by the filename passed. Related: <code class=\"language-text\">fs.fstat()</code>, <code class=\"language-text\">fs.lstat()</code></li>\n<li><code class=\"language-text\">fs.symlink()</code>: create a new symbolic link to a file</li>\n<li><code class=\"language-text\">fs.truncate()</code>: truncate to the specified length the file identified by the filename passed. Related: <code class=\"language-text\">fs.ftruncate()</code></li>\n<li><code class=\"language-text\">fs.unlink()</code>: remove a file or a symbolic link</li>\n<li><code class=\"language-text\">fs.unwatchFile()</code>: stop watching for changes on a file</li>\n<li><code class=\"language-text\">fs.utimes()</code>: change the timestamp of the file identified by the filename passed. Related: <code class=\"language-text\">fs.futimes()</code></li>\n<li><code class=\"language-text\">fs.watchFile()</code>: start watching for changes on a file. Related: <code class=\"language-text\">fs.watch()</code></li>\n<li><code class=\"language-text\">fs.writeFile()</code>: write data to a file. Related: <code class=\"language-text\">fs.write()</code></li>\n</ul>\n<p>One peculiar thing about the <code class=\"language-text\">fs</code> module is that all the methods are asynchronous by default, but they can also work synchronously by appending <code class=\"language-text\">Sync</code>.</p>\n<p>For example:</p>\n<ul>\n<li><code class=\"language-text\">fs.rename()</code></li>\n<li><code class=\"language-text\">fs.renameSync()</code></li>\n<li><code class=\"language-text\">fs.write()</code></li>\n<li><code class=\"language-text\">fs.writeSync()</code></li>\n</ul>\n<p>This makes a huge difference in your application flow.</p>\n<blockquote>\n<p>Node.js 10 includes <a href=\"https://nodejs.org/api/fs.html#fs_fs_promises_api\">experimental support</a> for a promise based API</p>\n</blockquote>\n<p>For example let's examine the <code class=\"language-text\">fs.rename()</code> method. The asynchronous API is used with a callback:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">rename</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before.json'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'after.json'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">//done</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>A synchronous API can be used like this, with a try/catch block to handle errors:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    fs<span class=\"token punctuation\">.</span><span class=\"token function\">renameSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before.json'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'after.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">//done</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The key difference here is that the execution of your script will block in the second example, until the file operation succeeded.</p>"},{"url":"/docs/articles/intro/","relativePath":"docs/articles/intro.md","relativeDir":"docs/articles","base":"intro.md","name":"intro","frontmatter":{"title":"Intro To Node","excerpt":"Web-Dev-Hubis a Unibit theme created for project documentations. You can use it for your project.","seo":{"title":"Intro To Node","description":"This is the Intro To Node page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Intro To Node","keyName":"property"},{"name":"og:description","value":"This is the Intro To Node page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Intro To Node"},{"name":"twitter:description","value":"This is the Intro To Node page"}]},"template":"docs"},"html":"<p>Node.js is an open-source and cross-platform JavaScript runtime environment. It is a popular tool for almost any kind of project!</p>\n<p>Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant.</p>\n<p>A Node.js app is run in a single process, without creating a new thread for every request. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent JavaScript code from blocking and generally, libraries in Node.js are written using non-blocking paradigms, making blocking behavior the exception rather than the norm.</p>\n<p>When Node.js performs an I/O operation, like reading from the network, accessing a database or the filesystem, instead of blocking the thread and wasting CPU cycles waiting, Node.js will resume the operations when the response comes back.</p>\n<p>This allows Node.js to handle thousands of concurrent connections with a single server without introducing the burden of managing thread concurrency, which could be a significant source of bugs.</p>\n<p>Node.js has a unique advantage because millions of frontend developers that write JavaScript for the browser are now able to write the server-side code in addition to the client-side code without the need to learn a completely different language.</p>\n<p>In Node.js the new ECMAScript standards can be used without problems, as you don't have to wait for all your users to update their browsers - you are in charge of deciding which ECMAScript version to use by changing the Node.js version, and you can also enable specific experimental features by running Node.js with flags.</p>\n<h2>A Vast Number of Libraries</h2>\n<p>npm with its simple structure helped the ecosystem of Node.js proliferate, and now the npm registry hosts over 1,000,000 open source packages you can freely use.</p>\n<h2>An Example Node.js Application</h2>\n<p>The most common example Hello World of Node.js is a web server:</p>\n<iframe\n  title=\"Hello world web server\"\n  src=\"https://glitch.com/embed/#!/embed/nodejs-dev-0001-01?path=server.js&previewSize=30&attributionHidden=true&sidebarCollapsed=true\"\n  alt=\"nodejs-dev-0001-01 on Glitch\"\n  style=\"height: 400px; width: 100%; border: 0;\">\n</iframe>\n<br>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> http <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'http'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> hostname <span class=\"token operator\">=</span> <span class=\"token string\">'127.0.0.1'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> port <span class=\"token operator\">=</span> <span class=\"token number\">3000</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> server <span class=\"token operator\">=</span> http<span class=\"token punctuation\">.</span><span class=\"token function\">createServer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">req<span class=\"token punctuation\">,</span> res</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    res<span class=\"token punctuation\">.</span>statusCode <span class=\"token operator\">=</span> <span class=\"token number\">200</span><span class=\"token punctuation\">;</span>\n    res<span class=\"token punctuation\">.</span><span class=\"token function\">setHeader</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Content-Type'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'text/plain'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    res<span class=\"token punctuation\">.</span><span class=\"token function\">end</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello World\\n'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">listen</span><span class=\"token punctuation\">(</span>port<span class=\"token punctuation\">,</span> hostname<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Server running at http://</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>hostname<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">:</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>port<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">/</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To run this snippet, save it as a <code class=\"language-text\">server.js</code> file and run <code class=\"language-text\">node server.js</code> in your terminal.--></p>\n<p>This code first includes the Node.js <a href=\"https://nodejs.org/api/http.html\"><code class=\"language-text\">http</code> module</a>.</p>\n<p>Node.js has a fantastic <a href=\"https://nodejs.org/api/\">standard library</a>, including first-class support for networking.</p>\n<p>The <code class=\"language-text\">createServer()</code> method of <code class=\"language-text\">http</code> creates a new HTTP server and returns it.</p>\n<p>The server is set to listen on the specified port and host name. When the server is ready, the callback function is called, in this case informing us that the server is running.</p>\n<p>Whenever a new request is received, the <a href=\"https://nodejs.org/api/http.html#http_event_request\"><code class=\"language-text\">request</code> event</a> is called, providing two objects: a request (an <a href=\"https://nodejs.org/api/http.html#http_class_http_incomingmessage\"><code class=\"language-text\">http.IncomingMessage</code></a> object) and a response (an <a href=\"https://nodejs.org/api/http.html#http_class_http_serverresponse\"><code class=\"language-text\">http.ServerResponse</code></a> object).</p>\n<p>Those 2 objects are essential to handle the HTTP call.</p>\n<p>The first provides the request details. In this simple example, this is not used, but you could access the request headers and request data.</p>\n<p>The second is used to return data to the caller.</p>\n<p>In this case with:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nres<span class=\"token punctuation\">.</span>statusCode <span class=\"token operator\">=</span> <span class=\"token number\">200</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>we set the statusCode property to 200, to indicate a successful response.</p>\n<p>We set the Content-Type header:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nres<span class=\"token punctuation\">.</span><span class=\"token function\">setHeader</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Content-Type'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'text/plain'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>and we close the response, adding the content as an argument to <code class=\"language-text\">end()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nres<span class=\"token punctuation\">.</span><span class=\"token function\">end</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello World\\n'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Node.js Frameworks and Tools</h2>\n<p>Node.js is a low-level platform. In order to make things easy and exciting for developers, thousands of libraries were built upon Node.js by the community.</p>\n<p>Many of those established over time as popular options. Here is a non-comprehensive list of the ones worth learning:</p>\n<ul>\n<li><a href=\"https://adonisjs.com/\"><strong>AdonisJs</strong></a>: A full-stack framework highly focused on developer ergonomics, stability, and confidence. Adonis is one of the fastest Node.js web frameworks.</li>\n<li><a href=\"https://expressjs.com/\"><strong>Express</strong></a>: It provides one of the most simple yet powerful ways to create a web server. Its minimalist approach, unopinionated, focused on the core features of a server, is key to its success.</li>\n<li><a href=\"https://fastify.io/\"><strong>Fastify</strong></a>: A web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture. Fastify is one of the fastest Node.js web frameworks.</li>\n<li><a href=\"https://www.gatsbyjs.com/\"><strong>Gatsby</strong></a>: A <a href=\"https://reactjs.org/\">React</a>-based, <a href=\"https://graphql.org/\">GraphQL</a> powered, static site generator with a very rich ecosystem of plugins and starters.</li>\n<li><a href=\"https://hapijs.com\"><strong>hapi</strong></a>: A rich framework for building applications and services that enables developers to focus on writing reusable application logic instead of spending time building infrastructure.</li>\n<li><a href=\"http://koajs.com/\"><strong>koa</strong></a>: It is built by the same team behind Express, aims to be even simpler and smaller, building on top of years of knowledge. The new project born out of the need to create incompatible changes without disrupting the existing community.</li>\n<li><a href=\"https://loopback.io/\"><strong>Loopback.io</strong></a>: Makes it easy to build modern applications that require complex integrations.</li>\n<li><a href=\"https://meteor.com\"><strong>Meteor</strong></a>: An incredibly powerful full-stack framework, powering you with an isomorphic approach to building apps with JavaScript, sharing code on the client and the server. Once an off-the-shelf tool that provided everything, now integrates with frontend libs <a href=\"https://reactjs.org/\">React</a>, <a href=\"https://vuejs.org/\">Vue</a>, and <a href=\"https://angular.io\">Angular</a>. Can be used to create mobile apps as well.</li>\n<li><a href=\"https://github.com/zeit/micro\"><strong>Micro</strong></a>: It provides a very lightweight server to create asynchronous HTTP microservices.</li>\n<li><a href=\"https://nestjs.com/\"><strong>NestJS</strong></a>: A TypeScript based progressive Node.js framework for building enterprise-grade efficient, reliable and scalable server-side applications.</li>\n<li><a href=\"https://nextjs.org/\"><strong>Next.js</strong></a>: <a href=\"https://reactjs.org\">React</a> framework that gives you the best developer experience with all the features you need for production: hybrid static &#x26; server rendering, TypeScript support, smart bundling, route pre-fetching, and more.</li>\n<li><a href=\"https://nx.dev/\"><strong>Nx</strong></a>: A toolkit for full-stack monorepo development using NestJS, Express, <a href=\"https://reactjs.org/\">React</a>, <a href=\"https://angular.io\">Angular</a>, and more! Nx helps scale your development from one team building one application to many teams collaborating on multiple applications!</li>\n<li><a href=\"https://sapper.svelte.dev/\"><strong>Sapper</strong></a>: Sapper is a framework for building web applications of all sizes, with a beautiful development experience and flexible filesystem-based routing. Offers SSR and more!</li>\n<li><a href=\"https://socket.io/\"><strong>Socket.io</strong></a>: A real-time communication engine to build network applications.</li>\n<li><a href=\"https://strapi.io/\"><strong>Strapi</strong></a>: Strapi is a flexible, open-source Headless CMS that gives developers the freedom to choose their favorite tools and frameworks while also allowing editors to easily manage and distribute their content. By making the admin panel and API extensible through a plugin system, Strapi enables the world's largest companies to accelerate content delivery while building beautiful digital experiences.</li>\n</ul>"},{"url":"/docs/articles/how-search-engines-work/","relativePath":"docs/articles/how-search-engines-work.md","relativeDir":"docs/articles","base":"how-search-engines-work.md","name":"how-search-engines-work","frontmatter":{"title":"The Anatomy of a Search Engine","sections":[],"seo":{"title":"","description":"hardware performance and cost have improved dramatically to partially offset the difficulty. There are, however, several notable exceptions to this progress such as disk seek time and operating system robustness. In designing Google, we have considered both the rate of growth of the Web and technological changes. Google is designed to scale well to extremely large data sets. It makes efficient use of storage space to store the index. Its data structures are optimized for fast and efficient access (see section 4.2). Further, we expect that the cost to index and store text or HTML will eventually decline relative to the amount that will be available (see Appendix B). This will result in favorable scaling properties for centralized systems like Google.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>The Anatomy of a Search Engine</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>These tasks are becoming increasingly difficult as the Web grows. However,\nhardware performance and cost have improved dramatically to partially offset\nthe difficulty. There are, however, several notable exceptions to this\nprogress such as disk seek time and operating system robustness. In designing\nGoogle, we have considered both the rate of growth of the Web and technological\nchanges. Google is designed to scale well to extremely large data sets.\nIt makes efficient use of storage space to store the index. Its data structures\nare optimized for fast and efficient access (see section 4.2).\nFurther, we expect that the cost to index and store text or HTML will eventually\ndecline relative to the amount that will be available (see Appendix\nB). This will result in favorable scaling properties for centralized\nsystems like Google.</p>\n</blockquote>\n<hr>\n<p><strong>Sergey Brin and Lawrence Page</strong></p>\n<p>{sergey, page}@cs.stanford.edu</p>\n<p>Computer Science Department, Stanford University, Stanford, CA 94305</p>\n<h3>Abstract</h3>\n<blockquote>\n<p>In this paper, we present Google, a prototype of a large-scale search engine which makes heavy use of the structure present in hypertext. Google is designed to crawl and index the Web efficiently and produce much more satisfying search results than existing systems. The prototype with a full text and hyperlink database of at least 24 million pages is available at <a href=\"http://google.stanford.edu/\">http://google.stanford.edu/</a>\nTo engineer a search engine is a challenging task. Search engines index tens to hundreds of millions of web pages involving a comparable number of distinct terms. They answer tens of millions of queries every day. Despite the importance of large-scale search engines on the web, very little academic research has been done on them. Furthermore, due to rapid advance in technology and web proliferation, creating a web search engine today is very different from three years ago. This paper provides an in-depth description of our large-scale web search engine -- the first such detailed public description we know of to date.\nApart from the problems of scaling traditional search techniques to data of this magnitude, there are new technical challenges involved with using the additional information present in hypertext to produce better search results. This paper addresses this question of how to build a practical large-scale system which can exploit the additional information present in hypertext. Also we look at the problem of how to effectively deal with uncontrolled hypertext collections where anyone can publish anything they want.</p>\n<p><strong>Keywords</strong>: World Wide Web, Search Engines, Information Retrieval, PageRank, Google</p>\n</blockquote>\n<h2>1. Introduction</h2>\n<p><em>(Note: There are two versions of this paper -- a longer full version and a shorter printed version. The full version is available on the web and the conference CD-ROM.)</em>\nThe web creates new challenges for information retrieval. The amount of information on the web is growing rapidly, as well as the number of new users inexperienced in the art of web research. People are likely to surf the web using its link graph, often starting with high quality human maintained indices such as <a href=\"http://www.yahoo.com/\">Yahoo!</a> or with search engines. Human maintained lists cover popular topics effectively but are subjective, expensive to build and maintain, slow to improve, and cannot cover all esoteric topics. Automated search engines that rely on keyword matching usually return too many low quality matches. To make matters worse, some advertisers attempt to gain people's attention by taking measures meant to mislead automated search engines. We have built a large-scale search engine which addresses many of the problems of existing systems. It makes especially heavy use of the additional structure present in hypertext to provide much higher quality search results. We chose our system name, Google, because it is a common spelling of googol, or 10100 and fits well with our goal of building very large-scale search engines.</p>\n<h3>1.1 Web Search Engines -- Scaling Up: 1994 - 2000</h3>\n<p>Search engine technology has had to scale dramatically to keep up with the growth of the web. In 1994, one of the first web search engines, the World Wide Web Worm (WWWW) <a href=\"http://www.cs.colorado.edu/home/mcbryan/mypapers/www94.ps\">[McBryan 94]</a> had an index of 110,000 web pages and web accessible documents. As of November, 1997, the top search engines claim to index from 2 million (WebCrawler) to 100 million web documents (from <a href=\"http://www.searchenginewatch.com/\">Search Engine Watch)</a>. It is foreseeable that by the year 2000, a comprehensive index of the Web will contain over a billion documents. At the same time, the number of queries search engines handle has grown incredibly too. In March and April 1994, the World Wide Web Worm received an average of about 1500 queries per day. In November 1997, Altavista claimed it handled roughly 20 million queries per day. With the increasing number of users on the web, and automated systems which query search engines, it is likely that top search engines will handle hundreds of millions of queries per day by the year 2000. The goal of our system is to address many of the problems, both in quality and scalability, introduced by scaling search engine technology to such extraordinary numbers.</p>\n<h3>1.2. Google: Scaling with the Web</h3>\n<p>Creating a search engine which scales even to today's web presents many challenges. Fast crawling technology is needed to gather the web documents and keep them up to date. Storage space must be used efficiently to store indices and, optionally, the documents themselves. The indexing system must process hundreds of gigabytes of data efficiently. Queries must be handled quickly, at a rate of hundreds to thousands per second.</p>\n<p>These tasks are becoming increasingly difficult as the Web grows. However, hardware performance and cost have improved dramatically to partially offset the difficulty. There are, however, several notable exceptions to this progress such as disk seek time and operating system robustness. In designing Google, we have considered both the rate of growth of the Web and technological changes. Google is designed to scale well to extremely large data sets. It makes efficient use of storage space to store the index. Its data structures are optimized for fast and efficient access (see section <a href=\"http://infolab.stanford.edu/~backrub/google.html#data\">4.2</a>). Further, we expect that the cost to index and store text or HTML will eventually decline relative to the amount that will be available (see <a href=\"http://infolab.stanford.edu/~backrub/google.html#b\">Appendix B</a>). This will result in favorable scaling properties for centralized systems like Google.</p>\n<h3>1.3 Design Goals</h3>\n<h4>1.3.1 Improved Search Quality</h4>\n<p>Our main goal is to improve the quality of web search engines. In 1994, some people believed that a complete search index would make it possible to find anything easily. According to <a href=\"http://botw.org/1994/awards/navigators.html\">Best of the Web 1994 -- Navigators,</a> \"The best navigation service should make it easy to find almost anything on the Web (once all the data is entered).\" However, the Web of 1997 is quite different. Anyone who has used a search engine recently, can readily testify that the completeness of the index is not the only factor in the quality of search results. \"Junk results\" often wash out any results that a user is interested in. In fact, as of November 1997, only one of the top four commercial search engines finds itself (returns its own search page in response to its name in the top ten results). One of the main causes of this problem is that the number of documents in the indices has been increasing by many orders of magnitude, but the user's ability to look at documents has not. People are still only willing to look at the first few tens of results. Because of this, as the collection size grows, we need tools that have very high precision (number of relevant documents returned, say in the top tens of results). Indeed, we want our notion of \"relevant\" to only include the very best documents since there may be tens of thousands of slightly relevant documents. This very high precision is important even at the expense of recall (the total number of relevant documents the system is able to return). There is quite a bit of recent optimism that the use of more hypertextual information can help improve search and other applications [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Marchiori 97</a>] [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Spertus 97</a>] [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Weiss 96</a>] [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Kleinberg 98</a>]. In particular, link structure [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Page 98</a>] and link text provide a lot of information for making relevance judgments and quality filtering. Google makes use of both link structure and anchor text (see Sections <a href=\"http://infolab.stanford.edu/~backrub/google.html#pr\">2.1</a> and <a href=\"http://infolab.stanford.edu/~backrub/google.html#anchor\">2.2</a>).</p>\n<h4>1.3.2 Academic Search Engine Research</h4>\n<p>Aside from tremendous growth, the Web has also become increasingly commercial over time. In 1993, 1.5% of web servers were on .com domains. This number grew to over 60% in 1997. At the same time, search engines have migrated from the academic domain to the commercial. Up until now most search engine development has gone on at companies with little publication of technical details. This causes search engine technology to remain largely a black art and to be advertising oriented (see <a href=\"http://infolab.stanford.edu/~backrub/google.html#a\">Appendix A</a>). With Google, we have a strong goal to push more development and understanding into the academic realm.</p>\n<p>Another important design goal was to build systems that reasonable numbers of people can actually use. Usage was important to us because we think some of the most interesting research will involve leveraging the vast amount of usage data that is available from modern web systems. For example, there are many tens of millions of searches performed every day. However, it is very difficult to get this data, mainly because it is considered commercially valuable.</p>\n<p>Our final design goal was to build an architecture that can support novel research activities on large-scale web data. To support novel research uses, Google stores all of the actual documents it crawls in compressed form. One of our main goals in designing Google was to set up an environment where other researchers can come in quickly, process large chunks of the web, and produce interesting results that would have been very difficult to produce otherwise. In the short time the system has been up, there have already been several papers using databases generated by Google, and many others are underway. Another goal we have is to set up a Spacelab-like environment where researchers or even students can propose and do interesting experiments on our large-scale web data.</p>\n<h2>2. System Features</h2>\n<p>The Google search engine has two important features that help it produce high precision results. First, it makes use of the link structure of the Web to calculate a quality ranking for each web page. This ranking is called PageRank and is described in detail in [Page 98]. Second, Google utilizes link to improve search results.</p>\n<h3>2.1 PageRank: Bringing Order to the Web</h3>\n<p>The citation (link) graph of the web is an important resource that has largely gone unused in existing web search engines. We have created maps containing as many as 518 million of these hyperlinks, a significant sample of the total. These maps allow rapid calculation of a web page's \"PageRank\", an objective measure of its citation importance that corresponds well with people's subjective idea of importance. Because of this correspondence, PageRank is an excellent way to prioritize the results of web keyword searches. For most popular subjects, a simple text matching search that is restricted to web page titles performs admirably when PageRank prioritizes the results (demo available at <a href=\"http://google.stanford.edu/\">google.stanford.edu</a>). For the type of full text searches in the main Google system, PageRank also helps a great deal.</p>\n<h4>2.1.1 Description of PageRank Calculation</h4>\n<p>Academic citation literature has been applied to the web, largely by counting citations or backlinks to a given page. This gives some approximation of a page's importance or quality. PageRank extends this idea by not counting links from all pages equally, and by normalizing by the number of links on a page. PageRank is defined as follows:</p>\n<blockquote>\n<p><em>We assume page A has pages T1...Tn which point to it (i.e., are citations). The parameter d is a damping factor which can be set between 0 and 1. We usually set d to 0.85. There are more details about d in the next section. Also C(A) is defined as the number of links going out of page A. The PageRank of a page A is given as follows:</em></p>\n<p><em>PR(A) = (1-d) + d (PR(T1)/C(T1) + ... + PR(Tn)/C(Tn))</em></p>\n<p><em>Note that the PageRanks form a probability distribution over web pages, so the sum of all web pages' PageRanks will be one.</em></p>\n</blockquote>\n<p>PageRank or <em>PR(A)</em> can be calculated using a simple iterative algorithm, and corresponds to the principal eigenvector of the normalized link matrix of the web. Also, a PageRank for 26 million web pages can be computed in a few hours on a medium size workstation. There are many other details which are beyond the scope of this paper.</p>\n<h4>2.1.2 Intuitive Justification</h4>\n<p>PageRank can be thought of as a model of user behavior. We assume there is a \"random surfer\" who is given a web page at random and keeps clicking on links, never hitting \"back\" but eventually gets bored and starts on another random page. The probability that the random surfer visits a page is its PageRank. And, the <em>d</em> damping factor is the probability at each page the \"random surfer\" will get bored and request another random page. One important variation is to only add the damping factor <em>d</em> to a single page, or a group of pages. This allows for personalization and can make it nearly impossible to deliberately mislead the system in order to get a higher ranking. We have several other extensions to PageRank, again see [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Page 98</a>].</p>\n<p>Another intuitive justification is that a page can have a high PageRank if there are many pages that point to it, or if there are some pages that point to it and have a high PageRank. Intuitively, pages that are well cited from many places around the web are worth looking at. Also, pages that have perhaps only one citation from something like the <a href=\"http://www.yahoo.com/\">Yahoo!</a> homepage are also generally worth looking at. If a page was not high quality, or was a broken link, it is quite likely that Yahoo's homepage would not link to it. PageRank handles both these cases and everything in between by recursively propagating weights through the link structure of the web.</p>\n<h3>2.2 Anchor Text</h3>\n<p>The text of links is treated in a special way in our search engine. Most search engines associate the text of a link with the page that the link is on. In addition, we associate it with the page the link points to. This has several advantages. First, anchors often provide more accurate descriptions of web pages than the pages themselves. Second, anchors may exist for documents which cannot be indexed by a text-based search engine, such as images, programs, and databases. This makes it possible to return web pages which have not actually been crawled. Note that pages that have not been crawled can cause problems, since they are never checked for validity before being returned to the user. In this case, the search engine can even return a page that never actually existed, but had hyperlinks pointing to it. However, it is possible to sort the results, so that this particular problem rarely happens.</p>\n<p>This idea of propagating anchor text to the page it refers to was implemented in the World Wide Web Worm [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">McBryan 94</a>] especially because it helps search non-text information, and expands the search coverage with fewer downloaded documents. We use anchor propagation mostly because anchor text can help provide better quality results. Using anchor text efficiently is technically difficult because of the large amounts of data which must be processed. In our current crawl of 24 million pages, we had over 259 million anchors which we indexed.</p>\n<h3>2.3 Other Features</h3>\n<p>Aside from PageRank and the use of anchor text, Google has several other features. First, it has location information for all hits and so it makes extensive use of proximity in search. Second, Google keeps track of some visual presentation details such as font size of words. Words in a larger or bolder font are weighted higher than other words. Third, full raw HTML of pages is available in a repository.</p>\n<h2>3 Related Work</h2>\n<p>Search research on the web has a short and concise history. The World Wide Web Worm (WWWW) <a href=\"http://www.cs.colorado.edu/home/mcbryan/mypapers/www94.ps\">[McBryan 94]</a> was one of the first web search engines. It was subsequently followed by several other academic search engines, many of which are now public companies. Compared to the growth of the Web and the importance of search engines there are precious few documents about recent search engines [<a href=\"http://info.webcrawler.com/bp/WWW94.html\">Pinkerton 94</a>]. According to Michael Mauldin (chief scientist, Lycos Inc) <a href=\"http://www.computer.org/pubs/expert/1997/trends/x1008/mauldin.htm\">[Mauldin]</a>, \"the various services (including Lycos) closely guard the details of these databases\". However, there has been a fair amount of work on specific features of search engines. Especially well represented is work which can get results by post-processing the results of existing commercial search engines, or produce small scale \"individualized\" search engines. Finally, there has been a lot of research on information retrieval systems, especially on well controlled collections. In the next two sections, we discuss some areas where this research needs to be extended to work better on the web.</p>\n<h3>3.1 Information Retrieval</h3>\n<p>Work in information retrieval systems goes back many years and is well developed [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Witten 94</a>]. However, most of the research on information retrieval systems is on small well controlled homogeneous collections such as collections of scientific papers or news stories on a related topic. Indeed, the primary benchmark for information retrieval, the Text Retrieval Conference [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">TREC 96</a>], uses a fairly small, well controlled collection for their benchmarks. The \"Very Large Corpus\" benchmark is only 20GB compared to the 147GB from our crawl of 24 million web pages. Things that work well on TREC often do not produce good results on the web. For example, the standard vector space model tries to return the document that most closely approximates the query, given that both query and document are vectors defined by their word occurrence. On the web, this strategy often returns very short documents that are the query plus a few words. For example, we have seen a major search engine return a page containing only \"Bill Clinton Sucks\" and picture from a \"Bill Clinton\" query. Some argue that on the web, users should specify more accurately what they want and add more words to their query. We disagree vehemently with this position. If a user issues a query like \"Bill Clinton\" they should get reasonable results since there is a enormous amount of high quality information available on this topic. Given examples like these, we believe that the standard information retrieval work needs to be extended to deal effectively with the web.</p>\n<h3>3.2 Differences Between the Web and Well Controlled Collections</h3>\n<p>The web is a vast collection of completely uncontrolled heterogeneous documents. Documents on the web have extreme variation internal to the documents, and also in the external meta information that might be available. For example, documents differ internally in their language (both human and programming), vocabulary (email addresses, links, zip codes, phone numbers, product numbers), type or format (text, HTML, PDF, images, sounds), and may even be machine generated (log files or output from a database). On the other hand, we define external meta information as information that can be inferred about a document, but is not contained within it. Examples of external meta information include things like reputation of the source, update frequency, quality, popularity or usage, and citations. Not only are the possible sources of external meta information varied, but the things that are being measured vary many orders of magnitude as well. For example, compare the usage information from a major homepage, like Yahoo's which currently receives millions of page views every day with an obscure historical article which might receive one view every ten years. Clearly, these two items must be treated very differently by a search engine.</p>\n<p>Another big difference between the web and traditional well controlled collections is that there is virtually no control over what people can put on the web. Couple this flexibility to publish anything with the enormous influence of search engines to route traffic and companies which deliberately manipulating search engines for profit become a serious problem. This problem that has not been addressed in traditional closed information retrieval systems. Also, it is interesting to note that metadata efforts have largely failed with web search engines, because any text on the page which is not directly represented to the user is abused to manipulate search engines. There are even numerous companies which specialize in manipulating search engines for profit.</p>\n<h2>4 System Anatomy</h2>\n<p>First, we will provide a high level discussion of the architecture. Then, there is some in-depth descriptions of important data structures. Finally, the major applications: crawling, indexing, and searching will be examined in depth.</p>\n<p>Figure 1. High Level Google Architecture</p>\n<h3>4.1 Google Architecture Overview</h3>\n<p>In this section, we will give a high level overview of how the whole system works as pictured in Figure 1. Further sections will discuss the applications and data structures not mentioned in this section. Most of Google is implemented in C or C++ for efficiency and can run in either Solaris or Linux.</p>\n<p>In Google, the web crawling (downloading of web pages) is done by several distributed crawlers. There is a URLserver that sends lists of URLs to be fetched to the crawlers. The web pages that are fetched are then sent to the storeserver. The storeserver then compresses and stores the web pages into a repository. Every web page has an associated ID number called a docID which is assigned whenever a new URL is parsed out of a web page. The indexing function is performed by the indexer and the sorter. The indexer performs a number of functions. It reads the repository, uncompresses the documents, and parses them. Each document is converted into a set of word occurrences called hits. The hits record the word, position in document, an approximation of font size, and capitalization. The indexer distributes these hits into a set of \"barrels\", creating a partially sorted forward index. The indexer performs another important function. It parses out all the links in every web page and stores important information about them in an anchors file. This file contains enough information to determine where each link points from and to, and the text of the link.</p>\n<p>The URLresolver reads the anchors file and converts relative URLs into absolute URLs and in turn into docIDs. It puts the anchor text into the forward index, associated with the docID that the anchor points to. It also generates a database of links which are pairs of docIDs. The links database is used to compute PageRanks for all the documents.</p>\n<p>The sorter takes the barrels, which are sorted by docID (this is a simplification, see <a href=\"http://infolab.stanford.edu/~backrub/google.html#hits\">Section 4.2.5</a>), and resorts them by wordID to generate the inverted index. This is done in place so that little temporary space is needed for this operation. The sorter also produces a list of wordIDs and offsets into the inverted index. A program called DumpLexicon takes this list together with the lexicon produced by the indexer and generates a new lexicon to be used by the searcher. The searcher is run by a web server and uses the lexicon built by DumpLexicon together with the inverted index and the PageRanks to answer queries.</p>\n<h3>4.2 Major Data Structures</h3>\n<p>Google's data structures are optimized so that a large document collection can be crawled, indexed, and searched with little cost. Although, CPUs and bulk input output rates have improved dramatically over the years, a disk seek still requires about 10 ms to complete. Google is designed to avoid disk seeks whenever possible, and this has had a considerable influence on the design of the data structures.</p>\n<h4>4.2.1 BigFiles</h4>\n<p>BigFiles are virtual files spanning multiple file systems and are addressable by 64 bit integers. The allocation among multiple file systems is handled automatically. The BigFiles package also handles allocation and deallocation of file descriptors, since the operating systems do not provide enough for our needs. BigFiles also support rudimentary compression options.</p>\n<h4>4.2.2 Repository</h4>\n<p><img src=\"http://infolab.stanford.edu/~backrub/repos.gif\" alt=\"image\"></p>\n<p>Figure 2. Repository Data Structure</p>\n<p>The repository contains the full HTML of every web page. Each page is compressed using zlib (see <a href=\"ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html\">RFC1950</a>). The choice of compression technique is a tradeoff between speed and compression ratio. We chose zlib's speed over a significant improvement in compression offered by <a href=\"http://www.muraroa.demon.co.uk/\">bzip</a>. The compression rate of bzip was approximately 4 to 1 on the repository as compared to zlib's 3 to 1 compression. In the repository, the documents are stored one after the other and are prefixed by docID, length, and URL as can be seen in Figure 2. The repository requires no other data structures to be used in order to access it. This helps with data consistency and makes development much easier; we can rebuild all the other data structures from only the repository and a file which lists crawler errors.</p>\n<h4>4.2.3 Document Index</h4>\n<p>The document index keeps information about each document. It is a fixed width ISAM (Index sequential access mode) index, ordered by docID. The information stored in each entry includes the current document status, a pointer into the repository, a document checksum, and various statistics. If the document has been crawled, it also contains a pointer into a variable width file called docinfo which contains its URL and title. Otherwise the pointer points into the URLlist which contains just the URL. This design decision was driven by the desire to have a reasonably compact data structure, and the ability to fetch a record in one disk seek during a search</p>\n<p>Additionally, there is a file which is used to convert URLs into docIDs. It is a list of URL checksums with their corresponding docIDs and is sorted by checksum. In order to find the docID of a particular URL, the URL's checksum is computed and a binary search is performed on the checksums file to find its docID. URLs may be converted into docIDs in batch by doing a merge with this file. This is the technique the URLresolver uses to turn URLs into docIDs. This batch mode of update is crucial because otherwise we must perform one seek for every link which assuming one disk would take more than a month for our 322 million link dataset.</p>\n<h4>4.2.4 Lexicon</h4>\n<p>The lexicon has several different forms. One important change from earlier systems is that the lexicon can fit in memory for a reasonable price. In the current implementation we can keep the lexicon in memory on a machine with 256 MB of main memory. The current lexicon contains 14 million words (though some rare words were not added to the lexicon). It is implemented in two parts -- a list of the words (concatenated together but separated by nulls) and a hash table of pointers. For various functions, the list of words has some auxiliary information which is beyond the scope of this paper to explain fully.</p>\n<h4>4.2.5 Hit Lists</h4>\n<p>A hit list corresponds to a list of occurrences of a particular word in a particular document including position, font, and capitalization information. Hit lists account for most of the space used in both the forward and the inverted indices. Because of this, it is important to represent them as efficiently as possible. We considered several alternatives for encoding position, font, and capitalization -- simple encoding (a triple of integers), a compact encoding (a hand optimized allocation of bits), and Huffman coding. In the end we chose a hand optimized compact encoding since it required far less space than the simple encoding and far less bit manipulation than Huffman coding. The details of the hits are shown in Figure 3.</p>\n<p>Our compact encoding uses two bytes for every hit. There are two types of hits: fancy hits and plain hits. Fancy hits include hits occurring in a URL, title, anchor text, or meta tag. Plain hits include everything else. A plain hit consists of a capitalization bit, font size, and 12 bits of word position in a document (all positions higher than 4095 are labeled 4096). Font size is represented relative to the rest of the document using three bits (only 7 values are actually used because 111 is the flag that signals a fancy hit). A fancy hit consists of a capitalization bit, the font size set to 7 to indicate it is a fancy hit, 4 bits to encode the type of fancy hit, and 8 bits of position. For anchor hits, the 8 bits of position are split into 4 bits for position in anchor and 4 bits for a hash of the docID the anchor occurs in. This gives us some limited phrase searching as long as there are not that many anchors for a particular word. We expect to update the way that anchor hits are stored to allow for greater resolution in the position and docIDhash fields. We use font size relative to the rest of the document because when searching, you do not want to rank otherwise identical documents differently just because one of the documents is in a larger font.</p>\n<p><img src=\"http://infolab.stanford.edu/~backrub/barrels.gif\" alt=\"image\"></p>\n<p>Figure 3. Forward and Reverse Indexes and the Lexicon</p>\n<p>The length of a hit list is stored before the hits themselves. To save space, the length of the hit list is combined with the wordID in the forward index and the docID in the inverted index. This limits it to 8 and 5 bits respectively (there are some tricks which allow 8 bits to be borrowed from the wordID). If the length is longer than would fit in that many bits, an escape code is used in those bits, and the next two bytes contain the actual length.</p>\n<h4>4.2.6 Forward Index</h4>\n<p>The forward index is actually already partially sorted. It is stored in a number of barrels (we used 64). Each barrel holds a range of wordID's. If a document contains words that fall into a particular barrel, the docID is recorded into the barrel, followed by a list of wordID's with hitlists which correspond to those words. This scheme requires slightly more storage because of duplicated docIDs but the difference is very small for a reasonable number of buckets and saves considerable time and coding complexity in the final indexing phase done by the sorter. Furthermore, instead of storing actual wordID's, we store each wordID as a relative difference from the minimum wordID that falls into the barrel the wordID is in. This way, we can use just 24 bits for the wordID's in the unsorted barrels, leaving 8 bits for the hit list length.</p>\n<h4>4.2.7 Inverted Index</h4>\n<p>The inverted index consists of the same barrels as the forward index, except that they have been processed by the sorter. For every valid wordID, the lexicon contains a pointer into the barrel that wordID falls into. It points to a doclist of docID's together with their corresponding hit lists. This doclist represents all the occurrences of that word in all documents.</p>\n<p>An important issue is in what order the docID's should appear in the doclist. One simple solution is to store them sorted by docID. This allows for quick merging of different doclists for multiple word queries. Another option is to store them sorted by a ranking of the occurrence of the word in each document. This makes answering one word queries trivial and makes it likely that the answers to multiple word queries are near the start. However, merging is much more difficult. Also, this makes development much more difficult in that a change to the ranking function requires a rebuild of the index. We chose a compromise between these options, keeping two sets of inverted barrels -- one set for hit lists which include title or anchor hits and another set for all hit lists. This way, we check the first set of barrels first and if there are not enough matches within those barrels we check the larger ones.</p>\n<h3>4.3 Crawling the Web</h3>\n<p>Running a web crawler is a challenging task. There are tricky performance and reliability issues and even more importantly, there are social issues. Crawling is the most fragile application since it involves interacting with hundreds of thousands of web servers and various name servers which are all beyond the control of the system.</p>\n<p>In order to scale to hundreds of millions of web pages, Google has a fast distributed crawling system. A single URLserver serves lists of URLs to a number of crawlers (we typically ran about 3). Both the URLserver and the crawlers are implemented in Python. Each crawler keeps roughly 300 connections open at once. This is necessary to retrieve web pages at a fast enough pace. At peak speeds, the system can crawl over 100 web pages per second using four crawlers. This amounts to roughly 600K per second of data. A major performance stress is DNS lookup. Each crawler maintains a its own DNS cache so it does not need to do a DNS lookup before crawling each document. Each of the hundreds of connections can be in a number of different states: looking up DNS, connecting to host, sending request, and receiving response. These factors make the crawler a complex component of the system. It uses asynchronous IO to manage events, and a number of queues to move page fetches from state to state.</p>\n<p>It turns out that running a crawler which connects to more than half a million servers, and generates tens of millions of log entries generates a fair amount of email and phone calls. Because of the vast number of people coming on line, there are always those who do not know what a crawler is, because this is the first one they have seen. Almost daily, we receive an email something like, \"Wow, you looked at a lot of pages from my web site. How did you like it?\" There are also some people who do not know about the <a href=\"http://info.webcrawler.com/mak/projects/robots/norobots.html\">robots exclusion protocol</a>, and think their page should be protected from indexing by a statement like, \"This page is copyrighted and should not be indexed\", which needless to say is difficult for web crawlers to understand. Also, because of the huge amount of data involved, unexpected things will happen. For example, our system tried to crawl an online game. This resulted in lots of garbage messages in the middle of their game! It turns out this was an easy problem to fix. But this problem had not come up until we had downloaded tens of millions of pages. Because of the immense variation in web pages and servers, it is virtually impossible to test a crawler without running it on large part of the Internet. Invariably, there are hundreds of obscure problems which may only occur on one page out of the whole web and cause the crawler to crash, or worse, cause unpredictable or incorrect behavior. Systems which access large parts of the Internet need to be designed to be very robust and carefully tested. Since large complex systems such as crawlers will invariably cause problems, there needs to be significant resources devoted to reading the email and solving these problems as they come up.</p>\n<h3>4.4 Indexing the Web</h3>\n<ul>\n<li><strong>Parsing --</strong> Any parser which is designed to run on the entire Web must handle a huge array of possible errors. These range from typos in HTML tags to kilobytes of zeros in the middle of a tag, non-ASCII characters, HTML tags nested hundreds deep, and a great variety of other errors that challenge anyone's imagination to come up with equally creative ones. For maximum speed, instead of using YACC to generate a CFG parser, we use flex to generate a lexical analyzer which we outfit with its own stack. Developing this parser which runs at a reasonable speed and is very robust involved a fair amount of work.</li>\n<li><strong>Indexing</strong> <strong>Documents into Barrels --</strong> After each document is parsed, it is encoded into a number of barrels. Every word is converted into a wordID by using an in-memory hash table -- the lexicon. New additions to the lexicon hash table are logged to a file. Once the words are converted into wordID's, their occurrences in the current document are translated into hit lists and are written into the forward barrels. The main difficulty with parallelization of the indexing phase is that the lexicon needs to be shared. Instead of sharing the lexicon, we took the approach of writing a log of all the extra words that were not in a base lexicon, which we fixed at 14 million words. That way multiple indexers can run in parallel and then the small log file of extra words can be processed by one final indexer.</li>\n<li><strong>Sorting</strong> -- In order to generate the inverted index, the sorter takes each of the forward barrels and sorts it by wordID to produce an inverted barrel for title and anchor hits and a full text inverted barrel. This process happens one barrel at a time, thus requiring little temporary storage. Also, we parallelize the sorting phase to use as many machines as we have simply by running multiple sorters, which can process different buckets at the same time. Since the barrels don't fit into main memory, the sorter further subdivides them into baskets which do fit into memory based on wordID and docID. Then the sorter, loads each basket into memory, sorts it and writes its contents into the short inverted barrel and the full inverted barrel.</li>\n</ul>\n<h3>4.5 Searching</h3>\n<p>The goal of searching is to provide quality search results efficiently. Many of the large commercial search engines seemed to have made great progress in terms of efficiency. Therefore, we have focused more on quality of search in our research, although we believe our solutions are scalable to commercial volumes with a bit more effort. The google query evaluation process is show in Figure 4.</p>\n<ol>\n<li>Parse the query.</li>\n<li>Convert words into wordIDs.</li>\n<li>Seek to the start of the doclist in the short barrel for every word.</li>\n<li>Scan through the doclists until there is a document that matches all the search terms.</li>\n<li>Compute the rank of that document for the query.</li>\n<li>If we are in the short barrels and at the end of any doclist, seek to the start of the doclist in the full barrel for every word and go to step 4.</li>\n<li>If we are not at the end of any doclist go to step 4.</li>\n</ol>\n<p>Sort the documents that have matched by rank and return the top k.</p>\n<p>Figure 4. Google Query Evaluation</p>\n<p>To put a limit on response time, once a certain number (currently 40,000) of matching documents are found, the searcher automatically goes to step 8 in Figure 4. This means that it is possible that sub-optimal results would be returned. We are currently investigating other ways to solve this problem. In the past, we sorted the hits according to PageRank, which seemed to improve the situation.</p>\n<h4>4.5.1 The Ranking System</h4>\n<p>Google maintains much more information about web documents than typical search engines. Every hitlist includes position, font, and capitalization information. Additionally, we factor in hits from anchor text and the PageRank of the document. Combining all of this information into a rank is difficult. We designed our ranking function so that no particular factor can have too much influence. First, consider the simplest case -- a single word query. In order to rank a document with a single word query, Google looks at that document's hit list for that word. Google considers each hit to be one of several different types (title, anchor, URL, plain text large font, plain text small font, ...), each of which has its own type-weight. The type-weights make up a vector indexed by type. Google counts the number of hits of each type in the hit list. Then every count is converted into a count-weight. Count-weights increase linearly with counts at first but quickly taper off so that more than a certain count will not help. We take the dot product of the vector of count-weights with the vector of type-weights to compute an IR score for the document. Finally, the IR score is combined with PageRank to give a final rank to the document.</p>\n<p>For a multi-word search, the situation is more complicated. Now multiple hit lists must be scanned through at once so that hits occurring close together in a document are weighted higher than hits occurring far apart. The hits from the multiple hit lists are matched up so that nearby hits are matched together. For every matched set of hits, a proximity is computed. The proximity is based on how far apart the hits are in the document (or anchor) but is classified into 10 different value \"bins\" ranging from a phrase match to \"not even close\". Counts are computed not only for every type of hit but for every type and proximity. Every type and proximity pair has a type-prox-weight. The counts are converted into count-weights and we take the dot product of the count-weights and the type-prox-weights to compute an IR score. All of these numbers and matrices can all be displayed with the search results using a special debug mode. These displays have been very helpful in developing the ranking system.</p>\n<h4>4.5.2 Feedback</h4>\n<p>The ranking function has many parameters like the type-weights and the type-prox-weights. Figuring out the right values for these parameters is something of a black art. In order to do this, we have a user feedback mechanism in the search engine. A trusted user may optionally evaluate all of the results that are returned. This feedback is saved. Then when we modify the ranking function, we can see the impact of this change on all previous searches which were ranked. Although far from perfect, this gives us some idea of how a change in the ranking function affects the search results.</p>\n<h2>5 Results and Performance</h2>\n<p>The most important measure of a search engine is the quality of its search results. While a complete user evaluation is beyond the scope of this paper, our own experience with Google has shown it to produce better results than the major commercial search engines for most searches. As an example which illustrates the use of PageRank, anchor text, and proximity, Figure 4 shows Google's results for a search on \"bill clinton\". These results demonstrates some of Google's features. The results are clustered by server. This helps considerably when sifting through result sets. A number of results are from the whitehouse.gov domain which is what one may reasonably expect from such a search. Currently, most major commercial search engines do not return any results from whitehouse.gov, much less the right ones. Notice that there is no title for the first result. This is because it was not crawled. Instead, Google relied on anchor text to determine this was a good answer to the query. Similarly, the fifth result is an email address which, of course, is not crawlable. It is also a result of anchor text.</p>\n<p>All of the results are reasonably high quality pages and, at last check, none were broken links. This is largely because they all have high PageRank. The PageRanks are the percentages in red along with bar graphs. Finally, there are no results about a Bill other than Clinton or about a Clinton other than Bill. This is because we place heavy importance on the proximity of word occurrences. Of course a true test of the quality of a search engine would involve an extensive user study or results analysis which we do not have room for here. Instead, we invite the reader to try Google for themselves at <a href=\"http://google.stanford.edu/\">http://google.stanford.edu</a>.</p>\n<h3>5.1 Storage Requirements</h3>\n<p>Aside from search quality, Google is designed to scale cost effectively to the size of the Web as it grows. One aspect of this is to use storage efficiently. Table 1 has a breakdown of some statistics and storage requirements of Google. Due to compression the total size of the repository is about 53 GB, just over one third of the total data it stores. At current disk prices this makes the repository a relatively cheap source of useful data. More importantly, the total of all the data used by the search engine requires a comparable amount of storage, about 55 GB. Furthermore, most queries can be answered using just the short inverted index. With better encoding and compression of the Document Index, a high quality web search engine may fit onto a 7GB drive of a new PC.</p>\n<p>Storage Statistics</p>\n<p>Total Size of Fetched Pages</p>\n<p>147.8 GB</p>\n<p>Compressed Repository</p>\n<p>53.5 GB</p>\n<p>Short Inverted Index</p>\n<p>4.1 GB</p>\n<p>Full Inverted Index</p>\n<p>37.2 GB</p>\n<p>Lexicon</p>\n<p>293 MB</p>\n<p>Temporary Anchor Data\n(not in total)</p>\n<p>6.6 GB</p>\n<p>Document Index Incl.\nVariable Width Data</p>\n<p>9.7 GB</p>\n<p>Links Database</p>\n<p>3.9 GB</p>\n<p>Total Without Repository</p>\n<p>55.2 GB</p>\n<p>Total With Repository</p>\n<p>108.7 GB</p>\n<p>Web Page Statistics</p>\n<p>Number of Web Pages Fetched</p>\n<p>24 million</p>\n<p>Number of Urls Seen</p>\n<p>76.5 million</p>\n<p>Number of Email Addresses</p>\n<p>1.7 million</p>\n<p>Number of 404's</p>\n<p>1.6 million</p>\n<p>Table 1. Statistics</p>\n<h3>5.2 System Performance</h3>\n<p>It is important for a search engine to crawl and index efficiently. This way information can be kept up to date and major changes to the system can be tested relatively quickly. For Google, the major operations are Crawling, Indexing, and Sorting. It is difficult to measure how long crawling took overall because disks filled up, name servers crashed, or any number of other problems which stopped the system. In total it took roughly 9 days to download the 26 million pages (including errors). However, once the system was running smoothly, it ran much faster, downloading the last 11 million pages in just 63 hours, averaging just over 4 million pages per day or 48.5 pages per second. We ran the indexer and the crawler simultaneously. The indexer ran just faster than the crawlers. This is largely because we spent just enough time optimizing the indexer so that it would not be a bottleneck. These optimizations included bulk updates to the document index and placement of critical data structures on the local disk. The indexer runs at roughly 54 pages per second. The sorters can be run completely in parallel; using four machines, the whole process of sorting takes about 24 hours.</p>\n<h3>5.3 Search Performance</h3>\n<p>Improving the performance of search was not the major focus of our research up to this point. The current version of Google answers most queries in between 1 and 10 seconds. This time is mostly dominated by disk IO over NFS (since disks are spread over a number of machines). Furthermore, Google does not have any optimizations such as query caching, subindices on common terms, and other common optimizations. We intend to speed up Google considerably through distribution and hardware, software, and algorithmic improvements. Our target is to be able to handle several hundred queries per second. Table 2 has some sample query times from the current version of Google. They are repeated to show the speedups resulting from cached IO.</p>\n<p><strong>Initial Query</strong></p>\n<p><strong>Same Query Repeated (IO mostly cached)</strong></p>\n<p><strong>Query</strong></p>\n<p><strong>CPU Time(s)</strong></p>\n<p><strong>Total Time(s)</strong></p>\n<p><strong>CPU Time(s)</strong></p>\n<p><strong>Total Time(s)</strong></p>\n<p>al gore</p>\n<p>0.09</p>\n<p>2.13</p>\n<p>0.06</p>\n<p>0.06</p>\n<p>vice president</p>\n<p>1.77</p>\n<p>3.84</p>\n<p>1.66</p>\n<p>1.80</p>\n<p>hard disks</p>\n<p>0.25</p>\n<p>4.86</p>\n<p>0.20</p>\n<p>0.24</p>\n<p>search engines</p>\n<p>1.31</p>\n<p>9.63</p>\n<p>1.16</p>\n<p>1.16</p>\n<p>Table 2. Search Times</p>\n<h2>6 Conclusions</h2>\n<p>Google is designed to be a scalable search engine. The primary goal is to provide high quality search results over a rapidly growing World Wide Web. Google employs a number of techniques to improve search quality including page rank, anchor text, and proximity information. Furthermore, Google is a complete architecture for gathering web pages, indexing them, and performing search queries over them.</p>\n<h3>6.1 Future Work</h3>\n<p>A large-scale web search engine is a complex system and much remains to be done. Our immediate goals are to improve search efficiency and to scale to approximately 100 million web pages. Some simple improvements to efficiency include query caching, smart disk allocation, and subindices. Another area which requires much research is updates. We must have smart algorithms to decide what old web pages should be recrawled and what new ones should be crawled. Work toward this goal has been done in [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Cho 98</a>]. One promising area of research is using proxy caches to build search databases, since they are demand driven. We are planning to add simple features supported by commercial search engines like boolean operators, negation, and stemming. However, other features are just starting to be explored such as relevance feedback and clustering (Google currently supports a simple hostname based clustering). We also plan to support user context (like the user's location), and result summarization. We are also working to extend the use of link structure and link text. Simple experiments indicate PageRank can be personalized by increasing the weight of a user's home page or bookmarks. As for link text, we are experimenting with using text surrounding links in addition to the link text itself. A Web search engine is a very rich environment for research ideas. We have far too many to list here so we do not expect this Future Work section to become much shorter in the near future.</p>\n<h3>6.2 High Quality Search</h3>\n<p>The biggest problem facing users of web search engines today is the quality of the results they get back. While the results are often amusing and expand users' horizons, they are often frustrating and consume precious time. For example, the top result for a search for \"Bill Clinton\" on one of the most popular commercial search engines was the <a href=\"http://www.io.com/~cjburke/clinton/970414.html\">Bill Clinton Joke of the Day: April 14, 1997</a>. Google is designed to provide higher quality search so as the Web continues to grow rapidly, information can be found easily. In order to accomplish this Google makes heavy use of hypertextual information consisting of link structure and link (anchor) text. Google also uses proximity and font information. While evaluation of a search engine is difficult, we have subjectively found that Google returns higher quality search results than current commercial search engines. The analysis of link structure via PageRank allows Google to evaluate the quality of web pages. The use of link text as a description of what the link points to helps the search engine return relevant (and to some degree high quality) results. Finally, the use of proximity information helps increase relevance a great deal for many queries.</p>\n<h3>6.3 Scalable Architecture</h3>\n<p>Aside from the quality of search, Google is designed to scale. It must be efficient in both space and time, and constant factors are very important when dealing with the entire Web. In implementing Google, we have seen bottlenecks in CPU, memory access, memory capacity, disk seeks, disk throughput, disk capacity, and network IO. Google has evolved to overcome a number of these bottlenecks during various operations. Google's major data structures make efficient use of available storage space. Furthermore, the crawling, indexing, and sorting operations are efficient enough to be able to build an index of a substantial portion of the web -- 24 million pages, in less than one week. We expect to be able to build an index of 100 million pages in less than a month.</p>\n<h3>6.4 A Research Tool</h3>\n<p>In addition to being a high quality search engine, Google is a research tool. The data Google has collected has already resulted in many other papers submitted to conferences and many more on the way. Recent research such as [<a href=\"http://infolab.stanford.edu/~backrub/google.html#ref\">Abiteboul 97</a>] has shown a number of limitations to queries about the Web that may be answered without having the Web available locally. This means that Google (or a similar system) is not only a valuable research tool but a necessary one for a wide range of applications. We hope Google will be a resource for searchers and researchers all around the world and will spark the next generation of search engine technology.</p>"},{"url":"/docs/articles/jamstack/","relativePath":"docs/articles/jamstack.md","relativeDir":"docs/articles","base":"jamstack.md","name":"jamstack","frontmatter":{"title":"Jamstack","weight":0,"excerpt":"Websites are served as static HTML files. These can be generated from source files, such as Markdown, using a Static Site Generator.","seo":{"title":"","description":"Websites are served as static HTML files. These can be generated from source files, such as Markdown, using a Static Site Generator.","robots":[],"extra":[]},"template":"docs"},"html":"<h2>What is Jamstack</h2>\n<hr>\n<h3>History</h3>\n<p>\"Jamstack\" was originally cased as \"JAMstack\" where \"JAM\" stood for JavaScript, API &#x26; Markup.</p>\n<blockquote>\n<p>\"A modern web development architecture based on client-side JavaScript, reusable APIs, and prebuilt Markup\"</p>\n<p>— Mathias Biilmann (CEO &#x26; Co-founder of Netlify).</p>\n</blockquote>\n<h4>JavaScript</h4>\n<p>Dynamic functionalities are handled by JavaScript. There is no restriction on which framework or library you must use.</p>\n<h4>APIs</h4>\n<p>Server side operations are abstracted into reusable APIs and accessed over HTTPS with JavaScript. These can be third party services or your custom function.</p>\n<h4>Markup</h4>\n<p>Websites are served as static HTML files. These can be generated from source files, such as Markdown, using a Static Site Generator.</p>\n<hr>\n<h3>Meaning</h3>\n<p>Today, Jamstack is used to more broadly refer to an architectural approach for building websites. Though there are varying opinions on what exactly Jamstack means today, these attributes are present in most sites that claim to be Jamstack sites:</p>\n<h4>Decoupled</h4>\n<p>The front end uses tooling separate from the back end. The front end is typically built using a static site generator. And the back end is often integrated with the front through the use of APIs used during the build process. Server-side processes can also be run using serverless functions.</p>\n<h4>Static-first</h4>\n<p>While various practices exist for introducing dynamic elements to Jamstack sites, most are pre-rendered, which means the front end was built and compiled into HTML, CSS, and JavaScript files.</p>\n<h4>Progressively enhanced</h4>\n<p>JavaScript can be introduced to pre-rendered sites on an as-needed basis, thus increasing performance in the browser.</p>\n<hr>\n<h3>Benefits</h3>\n<p>Here are the main benefits provided by the Jamstack.</p>\n<h4>Faster performance</h4>\n<p>Serve pre-built markup and assets over a CDN.</p>\n<h4>More secure</h4>\n<p>No need to worry about server or database vulnerabilities.</p>\n<h4>Less expensive</h4>\n<p>Hosting of static files is cheap or <a href=\"https://www.netlify.com/\">even free.</a></p>\n<h4>Better developer experience</h4>\n<p>Front end developers can focus on the front end, without being tied to a monolithic architecture. This usually means quicker and more focused development.</p>\n<h4>Scalability</h4>\n<p>If your product suddenly goes viral and has many active users, the CDN seamlessly compensates.</p>\n<hr>\n<h3>Best practices</h3>\n<p>The following tips will help you leverage the best out of the stack.</p>\n<h4>Content delivery network</h4>\n<p>Since all the markup and assets are pre-built, they can be served via CDN. This provides better performance and easier scalability.</p>\n<p><a href=\"https://www.cloudflare.com/learning/cdn/what-is-a-cdn/\" title=\"Read more about CDN\">Learn more</a></p>\n<h4>Atomic deploys</h4>\n<p>Each deploy is a full snapshot of the site. This helps guarantee a consistent version of the site globally.</p>\n<p><a href=\"https://buddy.works/blog/introducing-atomic-deployments#what-are-atomic-deployments\" title=\"Read more about atomic deploys\">Learn more</a></p>\n<h4>Cache invalidation</h4>\n<p>Once your build is uploaded, the CDN invalidates its cache. This means that your new build is live in an instant.</p>\n<p><a href=\"https://www.netlify.com/blog/2015/09/11/instant-cache-invalidation/\" title=\"Read more about cache invalidation\">Learn more</a></p>\n<h4>Everything in version control</h4>\n<p>Your codebase lives in version control system, such as Git. The main benefits are changing the history of every file, collaborators and traceability.</p>\n<p><a href=\"https://www.atlassian.com/git/tutorials/what-is-version-control\" title=\"Read more about version control\">Learn more</a></p>\n<h4>Automated builds</h4>\n<p>Your server is notified when a new build is required, typically via webhooks. Server builds the project, updates the CDNs and the site is live.</p>\n<p><a href=\"https://www.agilealliance.org/glossary/automated-build\" title=\"Read more about automated builds\">Learn more</a></p>\n<hr>\n<h3>Workflow</h3>\n<p>Here's an ideal Jamstack workflow:</p>\n<p>Develop</p>\n<p>Version Control</p>\n<p>Automated build</p>\n<p>Static assets</p>\n<p>Atomic deploy</p>\n<p>Pre-render &#x26; invalidate cache</p>\n<p>Update CDN</p>\n<hr>\n<h3>Timeline</h3>\n<p>A brief history of Jamstack shows its growth in popularity.</p>\n<h4>2015</h4>\n<p>Static sites are becoming popular due to the popularity of certain SSG such as Jekyll.</p>\n<h4>2016</h4>\n<p>A small group of developers believe that Static sites don't have to be static and the term \"Jamstack\" comes to life.</p>\n<h4>2017</h4>\n<p>The modern web revolution starts prioritising the importance of performance, scalability and developer experience. The term Jamstack starts to be adopted by a wider group of developers and the first enterprise Jamstack projects are announced.</p>\n<h4>2018</h4>\n<p>Tools like Netlify, Gatsby and Contentful have helped promote the term and the community is rapidly growing. This was also the year of the first Jamstack Conference.</p>\n<h4>2019</h4>\n<p>The year that Jamstack went mainstream. An explosion of new tools and services enter the market to support Jamstack sites.</p>\n<h4>2020</h4>\n<p>\"JAMstack\" becomes \"Jamstack\" and brought with it a new brand for the community. ZEIT becomes Vercel and begins blurring the lines of what Jamstack really means as Next.js grows in popularity, largely due to its ability to combine server-side and static rendering in the same site.</p>\n<h4>2021</h4>\n<p>While Jamstack continues to expand, confusion about what it really means has become a common theme. And yet, tools like <a href=\"https://redwoodjs.com/\">RedwoodJS</a> and <a href=\"https://blitzjs.com/\">Blitz.js</a> show us that Jamstack isn't slowing down.</p>\n<h2>Getting started</h2>\n<hr>\n<h3>Development</h3>\n<p>However you decide to generate your HTML assets is up to you. The three most common approaches are:</p>\n<h4>Hand coding</h4>\n<p>Simple and effective method of writing HTML, it's ideal for super simple pages.</p>\n<h4>Static Site Generators</h4>\n<p>Most Jamstack sites are powered by a static site generator. There's no enforcement on which SSG you decide to use.</p>\n<ul>\n<li><a href=\"https://nextjs.org/\" title=\"Next.js\">Next.js</a></li>\n<li><a href=\"https://www.gatsbyjs.com/\" title=\"Gatsby\">Gatsby</a></li>\n<li><a href=\"https://gohugo.io/\" title=\"Hugo\">Hugo</a></li>\n</ul>\n<h4>Site Builders</h4>\n<p>Tools that bring Jamstack to less technical users, while enabling developers to customize sites through modern tooling.</p>\n<ul>\n<li><a href=\"https://www.stackbit.com/\" title=\"Stackbit\">Stackbit</a></li>\n<li><a href=\"https://www.builder.io/\" title=\"Builder.io\">Builder.io</a></li>\n<li><a href=\"https://cloudcannon.com/\" title=\"CloudCannon\">CloudCannon</a></li>\n</ul>\n<hr>\n<h3>Dynamic parts</h3>\n<p>Jamstack websites don't have to be static. There are great services available to help bring some dynamic data to your product.</p>\n<hr>"},{"url":"/docs/articles/nextjs/","relativePath":"docs/articles/nextjs.md","relativeDir":"docs/articles","base":"nextjs.md","name":"nextjs","frontmatter":{"title":"NextJS","weight":0,"excerpt":"Next.js is a JavaScript framework created by Zeit. It lets you build server-side rendering and static web applications using React. Its a great tool to build your next website. It has many great features and advantages.","seo":{"title":"NextJS","description":"Next.js is a JavaScript framework created by Zeit. It lets you build server-side rendering and static web applications using React. Its a great tool to build your next website. It has many great features and advantages.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"page","image":"images/theme.png","subtitle":"how we introduce modularity into our code in the node ecosystem"},"html":"<h2>Nextjs for everyone — with some basic knowledge of React</h2>\n<blockquote>\n<h2>Excerpt</h2>\n<p>With some basic React and JavaScript knowledge, you'll be on your wayNext.js is a JavaScript framework created by Zeit. It lets you build server-side rendering and static web applications using React. It's a great tool to build your next website. It has many great features and advantages,</p>\n</blockquote>\n<hr>\n<h4>With some basic React and JavaScript knowledge, you'll be on your way</h4>\n<p><strong>Next.js</strong> is a JavaScript framework created by <a href=\"https://zeit.co/\">Zeit</a>. It lets you build server-side rendering and static web applications using React. It's a great tool to build your next website. It has many great features and advantages, which can make Nextjs your first option for building your next web application.</p>\n<p>You don't need any configuration of webpack or similar to start using Next.js. It comes with its configuration. All you need is to run <code class=\"language-text\">npm run dev</code> and start building your application ?.</p>\n<p>In this article, we are going to explore the great features and tricks of Next.js, and how to start building your next website with it.</p>\n<p><strong>This post assumes that you have some basic knowledge of React and JavaScript.</strong></p>\n<p>Here are some great websites built with Next.js:</p>\n<ul>\n<li><a href=\"https://syntax.fm/\">Syntaxt.fm</a></li>\n<li><a href=\"https://www.npmjs.com/\">npmjs</a></li>\n<li><a href=\"https://material-ui.com/\">material-ui.io</a></li>\n<li><a href=\"https://expo.io/\">expo.io</a></li>\n<li><a href=\"https://www.codementor.io/\">codemenitor.io</a></li>\n</ul>\n<p>I even used Nextjs to build my personal website <a href=\"https://www.saidhayani.me/\">saidhayani.me</a> — you can get the source code on GitHub <a href=\"https://github.com/hayanisaid/said-hayani-nextjs\">here</a>.</p>\n<h3>Getting starting with Next.js</h3>\n<p>To start with Next.js you need to have node.js installed in your machine and that's all. Next.js is like any other node.js application — you need npm or Yarn to install dependencies.</p>\n<p>Let's get started and create a Next.js project.</p>\n<p>First, we need to create a folder and give it a name of our choice. I'm gonna name it <code class=\"language-text\">nextjs-app</code>.</p>\n<p>You can easily do that with this command line:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*k8DzCXqZwRaY64Bhli5-yQ.png\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">mkdir nextjs-app</code></pre></div>\n<p>After creating the nextjs-app folder, open it on the terminal. Run <code class=\"language-text\">npm init</code> to create the <code class=\"language-text\">package.json</code> file.</p>\n<p>Next, we have to install our dependencies.</p>\n<p>Installing Next.js</p>\n<ul>\n<li>using Yarn, type</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add next</code></pre></div>\n<ul>\n<li>using npm, type:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm i next --save</code></pre></div>\n<p>Then we have to install React because Next.js uses React. The first line below uses Yarn for the installation.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add react react-dom</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// with npm</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm i react react-dom --save</code></pre></div>\n<p>After that you have to create two necessary folders: <code class=\"language-text\">pages</code> and <code class=\"language-text\">static</code> . Next.js won't work without them!!</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*s3N5eZcSSSgRdBiaMQeCRA.png\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">mkdir pages static</code></pre></div>\n<p>You <strong>must</strong> have this structure after running these commands :</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">nextjs-app  -pages  -static  -package.json</code></pre></div>\n<p>And then simply you can run <code class=\"language-text\">npm next dev</code> and then open <code class=\"language-text\">[http://localhost:3000/](http://localhost:3000/)</code> in your browser.</p>\n<p>The <code class=\"language-text\">NotFound</code> page will show up because we don't have any page yet!</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*Hv_4BaqTnrlriZ8Q3zk5ZQ.png\" alt=\"image\"></p>\n<p>So let's create a <code class=\"language-text\">home</code> page and an entry point <code class=\"language-text\">index.js</code>.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*IwZ5Ahr9egJ8KHF5HnLfHQ.png\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">touch index.js home.js</code></pre></div>\n<p>And then you can write a normal React component. As I said above, Next.js is for building React applications.</p>\n<p>Here is what our <code class=\"language-text\">home.js</code> looks like:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*He5fQw-VgeY5Gjo2RFGckw.png\" alt=\"image\"></p>\n<p>And here is our <code class=\"language-text\">index.js</code> file:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*AgGKp-WdRTwb3bOuqljcug.png\" alt=\"image\"></p>\n<p>Next.js has a live reload feature. All you need to do is just change and save, and Next.js will compile and reload the app automatically for you.</p>\n<p><strong>Note</strong>: Next.js is like any other server-side rendering tool we need to define the default page of our application, in our case is <code class=\"language-text\">index.js</code>.</p>\n<p>You will see this change in the browser after running <code class=\"language-text\">npm next dev</code>:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*QuQK1J5P0Rc4S-0BhllNmg.png\" alt=\"image\"></p>\n<p>Congratulations! We just created a Next.js app with a few simple steps. These instructions to create a Next.js app are described in the <a href=\"https://nextjs.org/learn/basics/getting-started/first-page\">official docs of Next.js</a> .</p>\n<h4>My alternative</h4>\n<p>I usually don't use this way. I use the <a href=\"http://import%20react%20from/\">create-next-app</a> CLI instead that will do all this stuff for me in one single line.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npx create-next-app my-app</code></pre></div>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*W5KCIFWP7yMHI-zaeVcmPA.png\" alt=\"image\"></p>\n<p>You can check out the documentation <a href=\"https://github.com/segmentio/create-next-app\">here</a> to explore more features.</p>\n<h3>Create custom configs for Next.js</h3>\n<p>Sometimes you might want to add some additional dependencies or packages to your Next.js app.</p>\n<p>Next.js gives you the option to customize your configuration using a <code class=\"language-text\">next-config.js</code> file.</p>\n<p>For example, you might want to add sass support to your app. In this case you have to use the <a href=\"https://github.com/zeit/next-plugins/tree/master/packages/next-sass\">next-sass</a> package <strong>and</strong> you have to add it to the <code class=\"language-text\">next-config.js</code> file as in the example below:</p>\n<p>First, install <code class=\"language-text\">next-sass</code>:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*5XSEx8DH0851FNzMxDx5LQ.png\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add @zeit/next-sass</code></pre></div>\n<p>Then include it inside the <code class=\"language-text\">next-config.js</code> file:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*YN_aoR5dzlnMyG2xVHJcww.png\" alt=\"image\"></p>\n<p>And then you can create write your sass code and import it in your component:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*kde4wjR-EpoNHc1c4JTb8g.png\" alt=\"image\"></p>\n<p>Importing the sass file in our component:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*yv1cTBXPeONqaV-CS1OZ2A.png\" alt=\"image\"></p>\n<p>And here is the result:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*VYfSkK1fIZKu75-2P8s4Bw.png\" alt=\"image\"></p>\n<p>Wow, wasn't that <strong>super easy</strong> to add sass support to out Next.js app?</p>\n<p>At this point, we just covered the installation and configuration part. Now let's talk about the features of Next.js!</p>\n<h3>The features</h3>\n<p>Next.js comes with a bunch of great features like server-side rendering, routers, and lazy loading.</p>\n<h4>Server-side rendering</h4>\n<p>Next.js performs server-side rendering by default. This makes your application optimized for search engines. Also, you can integrate any middleware such as <a href=\"https://expressjs.com/\">express.js</a> or <a href=\"https://hapijs.com/\">Hapi.js</a>, and you can run any database such as MongoDB or MySQL.</p>\n<p>Speaking of search engine optimization, Next.js comes with a <code class=\"language-text\">Head</code> component that allows you to add and make dynamic meta tags. It's my favorite feature — you can make custom and dynamic meta tags. These make your website able to be indexed by search engines like Google. Here is an example of a <code class=\"language-text\">Head</code> component :</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*mnIJGBgF59r1YjX5jXu8IA.png\" alt=\"image\"></p>\n<p>And you can import and use the<code class=\"language-text\">Head</code> component in any other page:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*liF5bNPAQ_j7gA9funSGTg.png\" alt=\"image\"></p>\n<p>Awesome!</p>\n<p><strong>Note</strong>: With Next.js you <strong>don't</strong> need to import React because Next.js does this for you.</p>\n<h4>Generating a static website with Next.js</h4>\n<p>As well as server-side rendering, you still can compile and export your application as an HTML static website and deploy it on a static website hosting like a GitHub page or <a href=\"https://www.netlify.com/\">netlify</a>. You can learn more how to make a static website with Next.js <a href=\"https://nextjs.org/learn/excel/static-html-export/setup\">here in the official docs</a>.</p>\n<h4>Routers</h4>\n<p>This is another one of the great features of Next.js. When you use the <a href=\"https://github.com/facebook/create-react-app\">create-react-app</a>, you usually need to install <a href=\"https://github.com/ReactTraining/react-router\">react-router</a> and create its custom configuration.</p>\n<p>Next.js comes with its own routers with zero configs. You don't need any extra configuration of your routers. Just create your page inside the <code class=\"language-text\">pages</code> folder and Next.js will take care of all routing configuration.</p>\n<p>Let's go ahead and create a custom navigation to make everything clear!</p>\n<p>To navigate between pages, Next.js has the <code class=\"language-text\">Link</code> method to manage the navigation.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*D54h6wnKX9fCS0AU34tVLA.png\" alt=\"image\"></p>\n<p>Let's create <code class=\"language-text\">blog.js</code> and <code class=\"language-text\">contact.js</code> pages:</p>\n<p><code class=\"language-text\">blog.js</code></p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*f6_vaaPs1Okfj8vZ9Fhk8g.png\" alt=\"image\"></p>\n<p>And here is the <code class=\"language-text\">contact.js</code> page:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*5lWCDzAUWed2NlsGpTC5EQ.png\" alt=\"image\"></p>\n<p>And now we must be able to navigate between those pages ?</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*7WYZeRb92PAwqthLo0xqHg.gif\" alt=\"image\"></p>\n<p>Wow that so easy and super awesome.</p>\n<h4>Lazy loading</h4>\n<p>Lazy loading makes your application deliver a better user experience. Sometimes the page might take time to load. The user may abandon your app if the loading takes more than 30 seconds.</p>\n<p>The way to avoid this is to use some trick to indicate to the user that the page is loading, for example by displaying a spinner. Lazy loading or code splitting is one of the features that allow you to deal with, and control, slow loading so you only load the necessary code in your page.</p>\n<p>Next.js comes with its own code splitting method. It provides us a method, called <code class=\"language-text\">dynamic</code>, to load our component, as in the example below:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*Ib835M7Ih-RY1kRBOUnXFA.png\" alt=\"image\"></p>\n<p>You can find the source code of these examples on <a href=\"https://github.com/hayanisaid/nextjs-intro-example\">GitHub</a></p>"},{"url":"/docs/articles/npm/","relativePath":"docs/articles/npm.md","relativeDir":"docs/articles","base":"npm.md","name":"npm","frontmatter":{"title":"Introduction to npm","weight":0,"excerpt":"npm is the standard package manager for nodejs","seo":{"title":"npm","description":"npm is the standard package manager for Node.js.\nIn January 2017 over 350000 packages were reported being listed in the npm registry.\n","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Introduction to npm</h2>\n<p><code class=\"language-text\">npm</code> is the standard package manager for Node.js.</p>\n<p>In January 2017 over 350000 packages were reported being listed in the npm registry, making it the biggest single language code repository on Earth, and you can be sure there is a package for (almost!) everything.</p>\n<p>It started as a way to download and manage dependencies of Node.js packages, but it has since become a tool used also in frontend JavaScript.</p>\n<p>There are many things that <code class=\"language-text\">npm</code> does.</p>\n<blockquote>\n<p><a href=\"https://yarnpkg.com/en/\"><strong>Yarn</strong></a> is an alternative to npm. Make sure you check it out as well.</p>\n</blockquote>\n<h2>Downloads</h2>\n<p><code class=\"language-text\">npm</code> manages downloads of dependencies of your project.</p>\n<h3>Installing all dependencies</h3>\n<p>If a project has a <code class=\"language-text\">package.json</code> file, by running</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span></code></pre></div>\n<p>it will install everything the project needs, in the <code class=\"language-text\">node_modules</code> folder, creating it if it's not existing already.</p>\n<h3>Installing a single package</h3>\n<p>You can also install a specific package by running</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> <span class=\"token operator\">&lt;</span>package-name<span class=\"token operator\">></span></code></pre></div>\n<p>Often you'll see more flags added to this command:</p>\n<ul>\n<li><code class=\"language-text\">--save</code> installs and adds the entry to the <code class=\"language-text\">package.json</code> file <em>dependencies</em></li>\n<li><code class=\"language-text\">--save-dev</code> installs and adds the entry to the <code class=\"language-text\">package.json</code> file <em>devDependencies</em></li>\n</ul>\n<p>The difference is mainly that devDependencies are usually development tools, like a testing library, while <code class=\"language-text\">dependencies</code> are bundled with the app in production.</p>\n<h3>Updating packages</h3>\n<p>Updating is also made easy, by running</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> update</code></pre></div>\n<p><code class=\"language-text\">npm</code> will check all packages for a newer version that satisfies your versioning constraints.</p>\n<p>You can specify a single package to update as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> update <span class=\"token operator\">&lt;</span>package-name<span class=\"token operator\">></span></code></pre></div>\n<h2>Versioning</h2>\n<p>In addition to plain downloads, <code class=\"language-text\">npm</code> also manages <strong>versioning</strong>, so you can specify any specific version of a package, or require a version higher or lower than what you need.</p>\n<p>Many times you'll find that a library is only compatible with a major release of another library.</p>\n<p>Or a bug in the latest release of a lib, still unfixed, is causing an issue.</p>\n<p>Specifying an explicit version of a library also helps to keep everyone on the same exact version of a package, so that the whole team runs the same version until the <code class=\"language-text\">package.json</code> file is updated.</p>\n<p>In all those cases, versioning helps a lot, and <code class=\"language-text\">npm</code> follows the semantic versioning (semver) standard.</p>\n<h2>Running Tasks</h2>\n<p>The package.json file supports a format for specifying command line tasks that can be run by using</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> run <span class=\"token operator\">&lt;</span>task-name<span class=\"token operator\">></span></code></pre></div>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//on</span>\n<span class=\"token punctuation\">{</span>\n    <span class=\"token string-property property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string-property property\">\"start-dev\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"node lib/server-development\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string-property property\">\"start\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"node lib/server-production\"</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>It's very common to use this feature to run Webpack:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//on</span>\n<span class=\"token punctuation\">{</span>\n    <span class=\"token string-property property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string-property property\">\"watch\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"webpack --watch --progress --colors --config webpack.conf.js\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string-property property\">\"dev\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"webpack --progress --colors --config webpack.conf.js\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string-property property\">\"prod\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"NODE_ENV=production webpack -p --config webpack.conf.js\"</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>So instead of typing those long commands, which are easy to forget or mistype, you can run</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">npm</span> run <span class=\"token function\">watch</span>\n$ <span class=\"token function\">npm</span> run dev\n$ <span class=\"token function\">npm</span> run prod</code></pre></div>"},{"url":"/docs/articles/os-module/","relativePath":"docs/articles/os-module.md","relativeDir":"docs/articles","base":"os-module.md","name":"os-module","frontmatter":{"title":"OS-Module","sections":[],"seo":{"title":"","description":"OS-Module","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>This module provides many functions that you can use to retrieve information from the underlying operating system and the computer the program runs on, and interact with it.</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> os <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'os'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>There are a few useful properties that tell us some key things related to handling files:</p>\n<p><code class=\"language-text\">os.EOL</code> gives the line delimiter sequence. It's <code class=\"language-text\">\\n</code> on Linux and macOS, and <code class=\"language-text\">\\r\\n</code> on Windows.</p>\n<p><code class=\"language-text\">os.constants.signals</code> tells us all the constants related to handling process signals, like SIGHUP, SIGKILL and so on.</p>\n<p><code class=\"language-text\">os.constants.errno</code> sets the constants for error reporting, like EADDRINUSE, EOVERFLOW and more.</p>\n<p>You can read them all on <a href=\"https://nodejs.org/api/os.html#os_signal_constants\">https://nodejs.org/api/os.html#os_signal_constants</a>.</p>\n<p>Let's now see the main methods that <code class=\"language-text\">os</code> provides:</p>\n<h2><code class=\"language-text\">os.arch()</code></h2>\n<p>Return the string that identifies the underlying architecture, like <code class=\"language-text\">arm</code>, <code class=\"language-text\">x64</code>, <code class=\"language-text\">arm64</code>.</p>\n<h2><code class=\"language-text\">os.cpus()</code></h2>\n<p>Return information on the CPUs available on your system.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">model</span><span class=\"token operator\">:</span> <span class=\"token string\">'Intel(R) Core(TM)2 Duo CPU     P8600  @ 2.40GHz'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">speed</span><span class=\"token operator\">:</span> <span class=\"token number\">2400</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">times</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">user</span><span class=\"token operator\">:</span> <span class=\"token number\">281685380</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">nice</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">sys</span><span class=\"token operator\">:</span> <span class=\"token number\">187986530</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">idle</span><span class=\"token operator\">:</span> <span class=\"token number\">685833750</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">irq</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">model</span><span class=\"token operator\">:</span> <span class=\"token string\">'Intel(R) Core(TM)2 Duo CPU     P8600  @ 2.40GHz'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">speed</span><span class=\"token operator\">:</span> <span class=\"token number\">2400</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">times</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">user</span><span class=\"token operator\">:</span> <span class=\"token number\">282348700</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">nice</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">sys</span><span class=\"token operator\">:</span> <span class=\"token number\">161800480</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">idle</span><span class=\"token operator\">:</span> <span class=\"token number\">703509470</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">irq</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><code class=\"language-text\">os.endianness()</code></h2>\n<p>Return <code class=\"language-text\">BE</code> or <code class=\"language-text\">LE</code> depending if Node.js was compiled with <a href=\"https://en.wikipedia.org/wiki/Endianness\">Big Endian or Little Endian</a>.</p>\n<h2><code class=\"language-text\">os.freemem()</code></h2>\n<p>Return the number of bytes that represent the free memory in the system.</p>\n<h2><code class=\"language-text\">os.homedir()</code></h2>\n<p>Return the path to the home directory of the current user.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token string\">'/Users/joe'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><code class=\"language-text\">os.hostname()</code></h2>\n<p>Return the host name.</p>\n<h2><code class=\"language-text\">os.loadavg()</code></h2>\n<p>Return the calculation made by the operating system on the load average.</p>\n<p>It only returns a meaningful value on Linux and macOS.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">3.68798828125</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4.00244140625</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11.1181640625</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><code class=\"language-text\">os.networkInterfaces()</code></h2>\n<p>Returns the details of the network interfaces available on your system.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">lo0</span><span class=\"token operator\">:</span>\n   <span class=\"token punctuation\">[</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">address</span><span class=\"token operator\">:</span> <span class=\"token string\">'127.0.0.1'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">netmask</span><span class=\"token operator\">:</span> <span class=\"token string\">'255.0.0.0'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">family</span><span class=\"token operator\">:</span> <span class=\"token string\">'IPv4'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">mac</span><span class=\"token operator\">:</span> <span class=\"token string\">'fe:82:00:00:00:00'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">internal</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n     <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">address</span><span class=\"token operator\">:</span> <span class=\"token string\">'::1'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">netmask</span><span class=\"token operator\">:</span> <span class=\"token string\">'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">family</span><span class=\"token operator\">:</span> <span class=\"token string\">'IPv6'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">mac</span><span class=\"token operator\">:</span> <span class=\"token string\">'fe:82:00:00:00:00'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">scopeid</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">internal</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n     <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">address</span><span class=\"token operator\">:</span> <span class=\"token string\">'fe80::1'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">netmask</span><span class=\"token operator\">:</span> <span class=\"token string\">'ffff:ffff:ffff:ffff::'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">family</span><span class=\"token operator\">:</span> <span class=\"token string\">'IPv6'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">mac</span><span class=\"token operator\">:</span> <span class=\"token string\">'fe:82:00:00:00:00'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">scopeid</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">internal</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">en1</span><span class=\"token operator\">:</span>\n   <span class=\"token punctuation\">[</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">address</span><span class=\"token operator\">:</span> <span class=\"token string\">'fe82::9b:8282:d7e6:496e'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">netmask</span><span class=\"token operator\">:</span> <span class=\"token string\">'ffff:ffff:ffff:ffff::'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">family</span><span class=\"token operator\">:</span> <span class=\"token string\">'IPv6'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">mac</span><span class=\"token operator\">:</span> <span class=\"token string\">'06:00:00:02:0e:00'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">scopeid</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">internal</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n     <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">address</span><span class=\"token operator\">:</span> <span class=\"token string\">'192.168.1.38'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">netmask</span><span class=\"token operator\">:</span> <span class=\"token string\">'255.255.255.0'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">family</span><span class=\"token operator\">:</span> <span class=\"token string\">'IPv4'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">mac</span><span class=\"token operator\">:</span> <span class=\"token string\">'06:00:00:02:0e:00'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">internal</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">utun0</span><span class=\"token operator\">:</span>\n   <span class=\"token punctuation\">[</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">address</span><span class=\"token operator\">:</span> <span class=\"token string\">'fe80::2513:72bc:f405:61d0'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">netmask</span><span class=\"token operator\">:</span> <span class=\"token string\">'ffff:ffff:ffff:ffff::'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">family</span><span class=\"token operator\">:</span> <span class=\"token string\">'IPv6'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">mac</span><span class=\"token operator\">:</span> <span class=\"token string\">'fe:80:00:20:00:00'</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">scopeid</span><span class=\"token operator\">:</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span>\n       <span class=\"token literal-property property\">internal</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span></code></pre></div>\n<h2><code class=\"language-text\">os.platform()</code></h2>\n<p>Return the platform that Node.js was compiled for:</p>\n<ul>\n<li><code class=\"language-text\">darwin</code></li>\n<li><code class=\"language-text\">freebsd</code></li>\n<li><code class=\"language-text\">linux</code></li>\n<li><code class=\"language-text\">openbsd</code></li>\n<li><code class=\"language-text\">win32</code></li>\n<li>...more</li>\n</ul>\n<h2><code class=\"language-text\">os.release()</code></h2>\n<p>Returns a string that identifies the operating system release number</p>\n<h2><code class=\"language-text\">os.tmpdir()</code></h2>\n<p>Returns the path to the assigned temp folder.</p>\n<h2><code class=\"language-text\">os.totalmem()</code></h2>\n<p>Returns the number of bytes that represent the total memory available in the system.</p>\n<h2><code class=\"language-text\">os.type()</code></h2>\n<p>Identifies the operating system:</p>\n<ul>\n<li><code class=\"language-text\">Linux</code></li>\n<li><code class=\"language-text\">Darwin</code> on macOS</li>\n<li><code class=\"language-text\">Windows_NT</code> on Windows</li>\n</ul>\n<h2><code class=\"language-text\">os.uptime()</code></h2>\n<p>Returns the number of seconds the computer has been running since it was last rebooted.</p>\n<h2><code class=\"language-text\">os.userInfo()</code></h2>\n<p>Returns an object that contains the current <code class=\"language-text\">username</code>, <code class=\"language-text\">uid</code>, <code class=\"language-text\">gid</code>, <code class=\"language-text\">shell</code>, and <code class=\"language-text\">homedir</code></p>"},{"url":"/blog/web-scraping/","relativePath":"blog/web-scraping.md","relativeDir":"blog","base":"web-scraping.md","name":"web-scraping","frontmatter":{"title":"Webscraping w nodejs","date":"2021-07-26","image":"images/web-development.gif","seo":{"title":"webscraping","description":"There are a lot of use cases for web scraping","extra":[{"name":"og:type","value":"article","keyName":"property"},{"name":"og:title","value":"Platform Docs","keyName":"property"},{"name":"og:description","value":"Lorem ipsum dolor sit amet, consectetur adipiscing elit","keyName":"property"},{"name":"og:image","value":"images/dtw-slideshow.gif","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"Platform Docs"},{"name":"twitter:description","value":"Lorem ipsum dolor sit amet, consectetur adipiscing elit"},{"name":"twitter:image","value":"images/web-development.gif","relativeUrl":true}]},"template":"post","thumb_image":"images/blue-plankton.png"},"html":"<h1>Web Scraping with Node.js</h1>\n<blockquote>\n<p>So what's web scraping anyway? It involves automating away the laborious task of collecting information from websites. There are a lot of use cases for web scraping: you might want to collect prices from various e-commerce sites for a price comparison site. Or perhaps you need flight times and</p>\n</blockquote>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*KkVKtysvgh2hIVRI1Irk-Q.jpeg\" alt=\"The Ultimate Guide to Web Scraping with Node.js\"></p>\n<p>So what's web scraping anyway? It involves automating away the laborious task of collecting information from websites.</p>\n<p>There are a lot of use cases for web scraping: you might want to collect prices from various e-commerce sites for a price comparison site. Or perhaps you need flight times and hotel/AirBNB listings for a travel site. Maybe you want to collect emails from various directories for sales leads, or use data from the internet to train machine learning/AI models. Or you could even be wanting to build a search engine like Google!</p>\n<p>Getting started with web scraping is easy, and the process can be broken down into two main parts:</p>\n<ul>\n<li>acquiring the data using an HTML request library or a headless browser,</li>\n<li>and parsing the data to get the exact information you want.</li>\n</ul>\n<p>This guide will walk you through the process with the popular Node.js <a href=\"https://github.com/request/request-promise\">request-promise</a> module, <a href=\"https://github.com/cheeriojs/cheerio\">CheerioJS</a>, and <a href=\"https://github.com/GoogleChrome/puppeteer\">Puppeteer</a>. Working through the examples in this guide, you will learn all the tips and tricks you need to become a pro at gathering any data you need with Node.js!</p>\n<p>We will be gathering a list of all the names and birthdays of U.S. presidents from Wikipedia and the titles of all the posts on the front page of Reddit.</p>\n<p>First things first: Let's install the libraries we'll be using in this guide (Puppeteer will take a while to install as it needs to download Chromium as well).</p>\n<h3>Making your first request</h3>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-install-libraries-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-install-libraries-LC1\">npm install --save request request-promise cheerio puppeteer</td>\n</tr>\n</tbody>\n</table>\n<p>Next, let's open a new text file (name the file potusScraper.js), and write a quick function to get the HTML of the Wikipedia \"List of Presidents\" page.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusscraper-js-v1-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC1\">const rp = require('request-promise');</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC2\">const url = 'https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States';</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC3\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC4\">rp(url)</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC5\">.then(function(html){</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC6\">//success!</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC7\">console.log(html);</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC8\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC9\">.catch(function(err){</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC10\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusscraper-js-v1-LC11\">});</td>\n</tr>\n</tbody>\n</table>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusscraper-js-v1-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusscraper-js-v1-output-LC1\">&lt;!DOCTYPE html&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusscraper-js-v1-output-LC2\">&lt;html class=\"client-nojs\" lang=\"en\" dir=\"ltr\"&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-output-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusscraper-js-v1-output-LC3\">&lt;head&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-output-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusscraper-js-v1-output-LC4\">&lt;meta charset=\"UTF-8\"/&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-output-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusscraper-js-v1-output-LC5\">&lt;title&gt;List of Presidents of the United States - Wikipedia&lt;/title&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v1-output-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusscraper-js-v1-output-LC6\">...</td>\n</tr>\n</tbody>\n</table>\n<h3>Using Chrome DevTools</h3>\n<p>Cool, we got the raw HTML from the web page! But now we need to make sense of this giant blob of text. To do that, we'll need to use Chrome DevTools to allow us to easily search through the HTML of a web page.</p>\n<p>Using Chrome DevTools is easy: simply open Google Chrome, and right click on the element you would like to scrape (in this case I am right clicking on George Washington, because we want to get links to all of the individual presidents' Wikipedia pages):</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*gLKhu_EO-cDqYna1P9WL_w.png\" alt=\"image\"></p>\n<p>Now, simply click inspect, and Chrome will bring up its DevTools pane, allowing you to easily inspect the page's source HTML.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*HSUjFgji22vjwvGi2uZe1A.png\" alt=\"image\"></p>\n<h3>Parsing HTML with Cheerio.js</h3>\n<p>Awesome, Chrome DevTools is now showing us the exact pattern we should be looking for in the code (a \"big\" tag with a hyperlink inside of it). Let's use Cheerio.js to parse the HTML we received earlier to return a list of links to the individual Wikipedia pages of U.S. presidents.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusscraper-js-v2-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC1\">const rp = require('request-promise');</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC2\">const $ = require('cheerio');</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC3\">const url = 'https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States';</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC4\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC5\">rp(url)</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC6\">.then(function(html){</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC7\">//success!</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC8\">console.log($('big &gt; a', html).length);</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC9\">console.log($('big &gt; a', html));</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC10\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC11\">.catch(function(err){</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC12\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-potusscraper-js-v2-LC13\">});</td>\n</tr>\n</tbody>\n</table>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC1\">45</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC2\">{ '0':</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC3\">{ type: 'tag',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC4\">name: 'a',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC5\">attribs: { href: '/wiki/George_Washington', title: 'George Washington' },</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC6\">children: [ [Object] ],</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC7\">next: null,</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC8\">prev: null,</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC9\">parent:</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC10\">{ type: 'tag',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC11\">name: 'big',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC12\">attribs: {},</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC13\">children: [Array],</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L14\" data-line-number=\"14\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC14\">next: null,</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L15\" data-line-number=\"15\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC15\">prev: null,</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L16\" data-line-number=\"16\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC16\">parent: [Object] } },</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L17\" data-line-number=\"17\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC17\">'1':</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L18\" data-line-number=\"18\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC18\">{ type: 'tag'</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v2-output-L19\" data-line-number=\"19\">\n</td>\n<td id=\"file-potusscraper-js-v2-output-LC19\">...</td>\n</tr>\n</tbody>\n</table>\n<p>We check to make sure there are exactly 45 elements returned (the number of U.S. presidents), meaning there aren't any extra hidden \"big\" tags elsewhere on the page. Now, we can go through and grab a list of links to all 45 presidential Wikipedia pages by getting them from the \"attribs\" section of each element.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusscraper-js-v3-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC1\">const rp = require('request-promise');</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC2\">const $ = require('cheerio');</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC3\">const url = 'https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States';</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC4\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC5\">rp(url)</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC6\">.then(function(html){</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC7\">//success!</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC8\">const wikiUrls = [];</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC9\">for (let i = 0; i &lt; 45; i++) {</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC10\">wikiUrls.push($('big &gt; a', html)[i].attribs.href);</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC11\">}</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC12\">console.log(wikiUrls);</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC13\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L14\" data-line-number=\"14\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC14\">.catch(function(err){</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L15\" data-line-number=\"15\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC15\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-L16\" data-line-number=\"16\">\n</td>\n<td id=\"file-potusscraper-js-v3-LC16\">});</td>\n</tr>\n</tbody>\n</table>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC1\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC2\">[</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC3\">'/wiki/George_Washington',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC4\">'/wiki/John_Adams',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC5\">'/wiki/Thomas_Jefferson',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC6\">'/wiki/James_Madison',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC7\">'/wiki/James_Monroe',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC8\">'/wiki/John_Quincy_Adams',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC9\">'/wiki/Andrew_Jackson',</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC10\">...</td>\n</tr>\n<tr>\n<td id=\"file-potusscraper-js-v3-output-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusscraper-js-v3-output-LC11\">]</td>\n</tr>\n</tbody>\n</table>\n<p>Now we have a list of all 45 presidential Wikipedia pages. Let's create a new file (named potusParse.js), which will contain a function to take a presidential Wikipedia page and return the president's name and birthday. First things first, let's get the raw HTML from George Washington's Wikipedia page.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusparse-js-v1-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusparse-js-v1-LC1\">const rp = require('request-promise');</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusparse-js-v1-LC2\">const url = 'https://en.wikipedia.org/wiki/George_Washington';</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusparse-js-v1-LC3\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusparse-js-v1-LC4\">rp(url)</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusparse-js-v1-LC5\">.then(function(html) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusparse-js-v1-LC6\">console.log(html);</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusparse-js-v1-LC7\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusparse-js-v1-LC8\">.catch(function(err) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusparse-js-v1-LC9\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusparse-js-v1-LC10\">});</td>\n</tr>\n</tbody>\n</table>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusparse-js-v1-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusparse-js-v1-output-LC1\">&lt;html class=\"client-nojs\" lang=\"en\" dir=\"ltr\"&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusparse-js-v1-output-LC2\">&lt;head&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-output-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusparse-js-v1-output-LC3\">&lt;meta charset=\"UTF-8\"/&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-output-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusparse-js-v1-output-LC4\">&lt;title&gt;George Washington - Wikipedia&lt;/title&gt;</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v1-output-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusparse-js-v1-output-LC5\">...</td>\n</tr>\n</tbody>\n</table>\n<p>Let's once again use Chrome DevTools to find the syntax of the code we want to parse, so that we can extract the name and birthday with Cheerio.js.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*exzZbuIwfrCcbTM2rr9_bw.png\" alt=\"image\"></p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*yth6AmHpywM77n0wEprpiA.png\" alt=\"image\"></p>\n<p>So we see that the name is in a class called \"firstHeading\" and the birthday is in a class called \"bday\". Let's modify our code to use Cheerio.js to extract these two classes.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusparse-js-v2-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusparse-js-v2-LC1\">const rp = require('request-promise');</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusparse-js-v2-LC2\">const $ = require('cheerio');</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusparse-js-v2-LC3\">const url = 'https://en.wikipedia.org/wiki/George_Washington';</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusparse-js-v2-LC4\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusparse-js-v2-LC5\">rp(url)</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusparse-js-v2-LC6\">.then(function(html) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusparse-js-v2-LC7\">console.log($('.firstHeading', html).text());</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusparse-js-v2-LC8\">console.log($('.bday', html).text());</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusparse-js-v2-LC9\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusparse-js-v2-LC10\">.catch(function(err) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusparse-js-v2-LC11\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-potusparse-js-v2-LC12\">});</td>\n</tr>\n</tbody>\n</table>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusparse-js-v2-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusparse-js-v2-output-LC1\">George Washington</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v2-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusparse-js-v2-output-LC2\">1732-02-22</td>\n</tr>\n</tbody>\n</table>\n<h3>Putting it all together</h3>\n<p>Perfect! Now let's wrap this up into a function and export it from this module.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusparse-js-v3-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusparse-js-v3-LC1\">const rp = require('request-promise');</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusparse-js-v3-LC2\">const $ = require('cheerio');</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusparse-js-v3-LC3\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusparse-js-v3-LC4\">const potusParse = function(url) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusparse-js-v3-LC5\">return rp(url)</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusparse-js-v3-LC6\">.then(function(html) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusparse-js-v3-LC7\">return {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusparse-js-v3-LC8\">name: $('.firstHeading', html).text(),</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusparse-js-v3-LC9\">birthday: $('.bday', html).text(),</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusparse-js-v3-LC10\">};</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusparse-js-v3-LC11\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-potusparse-js-v3-LC12\">.catch(function(err) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-potusparse-js-v3-LC13\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L14\" data-line-number=\"14\">\n</td>\n<td id=\"file-potusparse-js-v3-LC14\">});</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L15\" data-line-number=\"15\">\n</td>\n<td id=\"file-potusparse-js-v3-LC15\">};</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L16\" data-line-number=\"16\">\n</td>\n<td id=\"file-potusparse-js-v3-LC16\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v3-L17\" data-line-number=\"17\">\n</td>\n<td id=\"file-potusparse-js-v3-LC17\">module.exports = potusParse;</td>\n</tr>\n</tbody>\n</table>\n<p>Now let's return to our original file potusScraper.js and require the potusParse.js module. We'll then apply it to the list of wikiUrls we gathered earlier.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusparse-js-v4-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusparse-js-v4-LC1\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusparse-js-v4-LC2\">const rp = require('request-promise');</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusparse-js-v4-LC3\">const $ = require('cheerio');</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusparse-js-v4-LC4\">const potusParse = require('./potusParse');</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusparse-js-v4-LC5\">const url = 'https://en.wikipedia.org/wiki/List_of_Presidents_of_the_United_States';</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusparse-js-v4-LC6\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusparse-js-v4-LC7\">rp(url)</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusparse-js-v4-LC8\">.then(function(html) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusparse-js-v4-LC9\">//success!</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusparse-js-v4-LC10\">const wikiUrls = [];</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusparse-js-v4-LC11\">for (let i = 0; i &lt; 45; i++) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-potusparse-js-v4-LC12\">wikiUrls.push($('big &gt; a', html)[i].attribs.href);</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-potusparse-js-v4-LC13\">}</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L14\" data-line-number=\"14\">\n</td>\n<td id=\"file-potusparse-js-v4-LC14\">return Promise.all(</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L15\" data-line-number=\"15\">\n</td>\n<td id=\"file-potusparse-js-v4-LC15\">wikiUrls.map(function(url) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L16\" data-line-number=\"16\">\n</td>\n<td id=\"file-potusparse-js-v4-LC16\">return potusParse('https://en.wikipedia.org' + url);</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L17\" data-line-number=\"17\">\n</td>\n<td id=\"file-potusparse-js-v4-LC17\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L18\" data-line-number=\"18\">\n</td>\n<td id=\"file-potusparse-js-v4-LC18\">);</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L19\" data-line-number=\"19\">\n</td>\n<td id=\"file-potusparse-js-v4-LC19\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L20\" data-line-number=\"20\">\n</td>\n<td id=\"file-potusparse-js-v4-LC20\">.then(function(presidents) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L21\" data-line-number=\"21\">\n</td>\n<td id=\"file-potusparse-js-v4-LC21\">console.log(presidents);</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L22\" data-line-number=\"22\">\n</td>\n<td id=\"file-potusparse-js-v4-LC22\">})</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L23\" data-line-number=\"23\">\n</td>\n<td id=\"file-potusparse-js-v4-LC23\">.catch(function(err) {</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L24\" data-line-number=\"24\">\n</td>\n<td id=\"file-potusparse-js-v4-LC24\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L25\" data-line-number=\"25\">\n</td>\n<td id=\"file-potusparse-js-v4-LC25\">console.log(err);</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-L26\" data-line-number=\"26\">\n</td>\n<td id=\"file-potusparse-js-v4-LC26\">});</td>\n</tr>\n</tbody>\n</table>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC1\">\n</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC2\">[</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC3\">{ name: 'George Washington', birthday: '1732-02-22' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC4\">{ name: 'John Adams', birthday: '1735-10-30' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC5\">{ name: 'Thomas Jefferson', birthday: '1743-04-13' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC6\">{ name: 'James Madison', birthday: '1751-03-16' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC7\">{ name: 'James Monroe', birthday: '1758-04-28' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC8\">{ name: 'John Quincy Adams', birthday: '1767-07-11' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC9\">{ name: 'Andrew Jackson', birthday: '1767-03-15' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC10\">{ name: 'Martin Van Buren', birthday: '1782-12-05' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC11\">{ name: 'William Henry Harrison', birthday: '1773-02-09' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC12\">{ name: 'John Tyler', birthday: '1790-03-29' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC13\">{ name: 'James K. Polk', birthday: '1795-11-02' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L14\" data-line-number=\"14\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC14\">{ name: 'Zachary Taylor', birthday: '1784-11-24' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L15\" data-line-number=\"15\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC15\">{ name: 'Millard Fillmore', birthday: '1800-01-07' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L16\" data-line-number=\"16\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC16\">{ name: 'Franklin Pierce', birthday: '1804-11-23' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L17\" data-line-number=\"17\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC17\">{ name: 'James Buchanan', birthday: '1791-04-23' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L18\" data-line-number=\"18\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC18\">{ name: 'Abraham Lincoln', birthday: '1809-02-12' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L19\" data-line-number=\"19\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC19\">{ name: 'Andrew Johnson', birthday: '1808-12-29' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L20\" data-line-number=\"20\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC20\">{ name: 'Ulysses S. Grant', birthday: '1822-04-27' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L21\" data-line-number=\"21\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC21\">{ name: 'Rutherford B. Hayes', birthday: '1822-10-04' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L22\" data-line-number=\"22\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC22\">{ name: 'James A. Garfield', birthday: '1831-11-19' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L23\" data-line-number=\"23\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC23\">{ name: 'Chester A. Arthur', birthday: '1829-10-05' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L24\" data-line-number=\"24\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC24\">{ name: 'Grover Cleveland', birthday: '1837-03-18' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L25\" data-line-number=\"25\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC25\">{ name: 'Benjamin Harrison', birthday: '1833-08-20' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L26\" data-line-number=\"26\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC26\">{ name: 'Grover Cleveland', birthday: '1837-03-18' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L27\" data-line-number=\"27\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC27\">{ name: 'William McKinley', birthday: '1843-01-29' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L28\" data-line-number=\"28\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC28\">{ name: 'Theodore Roosevelt', birthday: '1858-10-27' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L29\" data-line-number=\"29\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC29\">{ name: 'William Howard Taft', birthday: '1857-09-15' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L30\" data-line-number=\"30\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC30\">{ name: 'Woodrow Wilson', birthday: '1856-12-28' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L31\" data-line-number=\"31\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC31\">{ name: 'Warren G. Harding', birthday: '1865-11-02' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L32\" data-line-number=\"32\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC32\">{ name: 'Calvin Coolidge', birthday: '1872-07-04' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L33\" data-line-number=\"33\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC33\">{ name: 'Herbert Hoover', birthday: '1874-08-10' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L34\" data-line-number=\"34\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC34\">{ name: 'Franklin D. Roosevelt', birthday: '1882-01-30' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L35\" data-line-number=\"35\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC35\">{ name: 'Harry S. Truman', birthday: '1884-05-08' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L36\" data-line-number=\"36\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC36\">{ name: 'Dwight D. Eisenhower', birthday: '1890-10-14' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L37\" data-line-number=\"37\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC37\">{ name: 'John F. Kennedy', birthday: '1917-05-29' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L38\" data-line-number=\"38\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC38\">{ name: 'Lyndon B. Johnson', birthday: '1908-08-27' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L39\" data-line-number=\"39\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC39\">{ name: 'Richard Nixon', birthday: '1913-01-09' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L40\" data-line-number=\"40\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC40\">{ name: 'Gerald Ford', birthday: '1913-07-14' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L41\" data-line-number=\"41\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC41\">{ name: 'Jimmy Carter', birthday: '1924-10-01' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L42\" data-line-number=\"42\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC42\">{ name: 'Ronald Reagan', birthday: '1911-02-06' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L43\" data-line-number=\"43\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC43\">{ name: 'George H. W. Bush', birthday: '1924-06-12' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L44\" data-line-number=\"44\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC44\">{ name: 'Bill Clinton', birthday: '1946-08-19' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L45\" data-line-number=\"45\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC45\">{ name: 'George W. Bush', birthday: '1946-07-06' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L46\" data-line-number=\"46\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC46\">{ name: 'Barack Obama', birthday: '1961-08-04' },</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L47\" data-line-number=\"47\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC47\">{ name: 'Donald Trump', birthday: '1946-06-14' }</td>\n</tr>\n<tr>\n<td id=\"file-potusparse-js-v4-output-L48\" data-line-number=\"48\">\n</td>\n<td id=\"file-potusparse-js-v4-output-LC48\">]</td>\n</tr>\n</tbody>\n</table>\n<h3>Rendering JavaScript Pages</h3>\n<p>Voilà! A list of the names and birthdays of all 45 U.S. presidents. Using just the request-promise module and Cheerio.js should allow you to scrape the vast majority of sites on the internet.</p>\n<p>Recently, however, many sites have begun using JavaScript to generate dynamic content on their websites. This causes a problem for request-promise and other similar HTTP request libraries (such as axios and fetch), because they only get the response from the initial request, but they cannot execute the JavaScript the way a web browser can.</p>\n<p>Thus, to scrape sites that require JavaScript execution, we need another solution. In our next example, we will get the titles for all of the posts on the front page of Reddit. Let's see what happens when we try to use request-promise as we did in the previous example.</p>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-reddit-js-v1-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-reddit-js-v1-LC1\">const rp = require('request-promise');</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-reddit-js-v1-LC2\">const url = 'https://www.reddit.com';</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-reddit-js-v1-LC3\">\n</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-reddit-js-v1-LC4\">rp(url)</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-reddit-js-v1-LC5\">.then(function(html){</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-reddit-js-v1-LC6\">//success!</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-reddit-js-v1-LC7\">console.log(html);</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-reddit-js-v1-LC8\">})</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-reddit-js-v1-LC9\">.catch(function(err){</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-reddit-js-v1-LC10\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-reddit-js-v1-LC11\">});</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-reddit-js-v1-LC12\">}</td>\n</tr>\n</tbody>\n</table>\n<p>Here's what the output looks like:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-reddit-js-v1-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-reddit-js-v1-output-LC1\">&lt;!DOCTYPE html&gt;&lt;html</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-reddit-js-v1-output-LC2\">lang=\"en\"&gt;&lt;head&gt;&lt;title&gt;reddit: the front page of the</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-output-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-reddit-js-v1-output-LC3\">internet&lt;/title&gt;</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v1-output-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-reddit-js-v1-output-LC4\">...</td>\n</tr>\n</tbody>\n</table>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*mKzPVGRR4CFKMwQw5y_YnQ.png\" alt=\"image\"></p>\n<p>Hmmm…not quite what we want. That's because getting the actual content requires you to run the JavaScript on the page! With Puppeteer, that's no problem.</p>\n<p>Puppeteer is an extremely popular new module brought to you by the Google Chrome team that allows you to control a headless browser. This is perfect for programmatically scraping pages that require JavaScript execution. Let's get the HTML from the front page of Reddit using Puppeteer instead of request-promise.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-reddit-js-v2-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-reddit-js-v2-LC1\">const puppeteer = require('puppeteer');</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-reddit-js-v2-LC2\">const url = 'https://www.reddit.com';</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-reddit-js-v2-LC3\">\n</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-reddit-js-v2-LC4\">puppeteer</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-reddit-js-v2-LC5\">.launch()</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-reddit-js-v2-LC6\">.then(function(browser) {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-reddit-js-v2-LC7\">return browser.newPage();</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-reddit-js-v2-LC8\">})</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-reddit-js-v2-LC9\">.then(function(page) {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-reddit-js-v2-LC10\">return page.goto(url).then(function() {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-reddit-js-v2-LC11\">return page.content();</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-reddit-js-v2-LC12\">});</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-reddit-js-v2-LC13\">})</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L14\" data-line-number=\"14\">\n</td>\n<td id=\"file-reddit-js-v2-LC14\">.then(function(html) {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L15\" data-line-number=\"15\">\n</td>\n<td id=\"file-reddit-js-v2-LC15\">console.log(html);</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L16\" data-line-number=\"16\">\n</td>\n<td id=\"file-reddit-js-v2-LC16\">})</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L17\" data-line-number=\"17\">\n</td>\n<td id=\"file-reddit-js-v2-LC17\">.catch(function(err) {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L18\" data-line-number=\"18\">\n</td>\n<td id=\"file-reddit-js-v2-LC18\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-L19\" data-line-number=\"19\">\n</td>\n<td id=\"file-reddit-js-v2-LC19\">});</td>\n</tr>\n</tbody>\n</table>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-reddit-js-v2-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-reddit-js-v2-output-LC1\">&lt;!DOCTYPE html&gt;&lt;html lang=\"en\"&gt;&lt;head&gt;&lt;link</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-reddit-js-v2-output-LC2\">href=\"//c.amazon-adsystem.com/aax2/apstag.js\" rel=\"preload\"</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-output-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-reddit-js-v2-output-LC3\">as=\"script\"&gt;</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v2-output-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-reddit-js-v2-output-LC4\">...</td>\n</tr>\n</tbody>\n</table>\n<p>Nice! The page is filled with the correct content!</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*N5HtAiijcMEB_fBQvPd7Ow.png\" alt=\"image\"></p>\n<p>Now we can use Chrome DevTools like we did in the previous example.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/1*tHSgjPMvn3M26N2f7Q2B1Q.png\" alt=\"image\"></p>\n<p>It looks like Reddit is putting the titles inside \"h2\" tags. Let's use Cheerio.js to extract the h2 tags from the page.</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-reddit-js-v3-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-reddit-js-v3-LC1\">const puppeteer = require('puppeteer');</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-reddit-js-v3-LC2\">const $ = require('cheerio');</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-reddit-js-v3-LC3\">const url = 'https://www.reddit.com';</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-reddit-js-v3-LC4\">\n</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-reddit-js-v3-LC5\">puppeteer</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-reddit-js-v3-LC6\">.launch()</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-reddit-js-v3-LC7\">.then(function(browser) {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-reddit-js-v3-LC8\">return browser.newPage();</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-reddit-js-v3-LC9\">})</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-reddit-js-v3-LC10\">.then(function(page) {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-reddit-js-v3-LC11\">return page.goto(url).then(function() {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-reddit-js-v3-LC12\">return page.content();</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-reddit-js-v3-LC13\">});</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L14\" data-line-number=\"14\">\n</td>\n<td id=\"file-reddit-js-v3-LC14\">})</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L15\" data-line-number=\"15\">\n</td>\n<td id=\"file-reddit-js-v3-LC15\">.then(function(html) {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L16\" data-line-number=\"16\">\n</td>\n<td id=\"file-reddit-js-v3-LC16\">$('h2', html).each(function() {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L17\" data-line-number=\"17\">\n</td>\n<td id=\"file-reddit-js-v3-LC17\">console.log($(this).text());</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L18\" data-line-number=\"18\">\n</td>\n<td id=\"file-reddit-js-v3-LC18\">});</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L19\" data-line-number=\"19\">\n</td>\n<td id=\"file-reddit-js-v3-LC19\">})</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L20\" data-line-number=\"20\">\n</td>\n<td id=\"file-reddit-js-v3-LC20\">.catch(function(err) {</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L21\" data-line-number=\"21\">\n</td>\n<td id=\"file-reddit-js-v3-LC21\">//handle error</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-L22\" data-line-number=\"22\">\n</td>\n<td id=\"file-reddit-js-v3-LC22\">});</td>\n</tr>\n</tbody>\n</table>\n<p>Output:</p>\n<table data-tab-size=\"8\" data-paste-markdown-skip=\"\">\n<tbody>\n<tr>\n<td id=\"file-reddit-js-v3-output-L1\" data-line-number=\"1\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC1\">Russian Pipeline. Upvote so that this is the first image people see when they Google \"Russian Pipeline\"</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L2\" data-line-number=\"2\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC2\">John F. Kennedy Jr. Sitting in the pilot seat of the Marine One circa 1963</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L3\" data-line-number=\"3\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC3\">I didn't take it as a compliment.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L4\" data-line-number=\"4\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC4\">How beautiful is this</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L5\" data-line-number=\"5\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC5\">Hustle like Faye</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L6\" data-line-number=\"6\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC6\">The power of a salt water crocodile's tail.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L7\" data-line-number=\"7\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC7\">I'm 36, and will be dead inside of a year.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L8\" data-line-number=\"8\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC8\">F***ing genius.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L9\" data-line-number=\"9\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC9\">TIL Anthony Daniels, who endured years of discomfort in the C-3PO costume, was so annoyed by Alan Tudyk (Rogue One) playing K-2SO in the comfort of a motion-capture suit that he cursed at Tudyk. Tudyk later joked that a \"fuck you\" from Daniels was among the highest compliments he had ever received.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L10\" data-line-number=\"10\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC10\">Reminder about the fact UC Davis paid over $100k to remove this photo from the internet.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L11\" data-line-number=\"11\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC11\">King of the Hill reruns will start airing on Comedy Central July 24th</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L12\" data-line-number=\"12\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC12\">[Image] Slow and steady</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L13\" data-line-number=\"13\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC13\">White House: Trump open to Russia questioning US citizens</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L14\" data-line-number=\"14\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC14\">Godzilla: King of the Monsters Teaser Banner</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L15\" data-line-number=\"15\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC15\">He tried</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L16\" data-line-number=\"16\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC16\">Soldier reunited with his dog after being away.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L17\" data-line-number=\"17\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC17\">Hiring a hitman on yourself and preparing for battle is the ultimate extreme sport.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L18\" data-line-number=\"18\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC18\">Two paintballs colliding midair</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L19\" data-line-number=\"19\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC19\">My thoughts &amp; prayers are with those ears</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L20\" data-line-number=\"20\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC20\">When even your fantasy starts dropping hints</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L21\" data-line-number=\"21\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC21\">Elon Musk's apology is out</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L22\" data-line-number=\"22\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC22\">\"When you're going private so you plant trees to throw some last shade at TDNW before you vanish.\" Thanos' farm advances. The soul children will have full bellies. 1024 points will give him the resources to double, and irrigate, his farm. (See comment)</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L23\" data-line-number=\"23\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC23\">Some leaders prefer chess, others prefer hungry hippos. Travis Chapman, oil, 2018</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L24\" data-line-number=\"24\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC24\">The S.S. Ste. Claire, retired from ferrying amusement park goers, now ferries The Damned across the river Styx.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L25\" data-line-number=\"25\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC25\">A soldier is reunited with his dog</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L26\" data-line-number=\"26\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC26\">*hits blunt*</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L27\" data-line-number=\"27\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC27\">Today I Learned</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L28\" data-line-number=\"28\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC28\">Black Panther Scene Representing the Pan-African Flag</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L29\" data-line-number=\"29\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC29\">The precision of this hydraulic press.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L30\" data-line-number=\"30\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC30\">Let bring the game to another level</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L31\" data-line-number=\"31\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC31\">When you're fighting a Dark Souls boss and you gamble to get 'just one extra hit' in instead of rolling out of range.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L32\" data-line-number=\"32\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC32\">\"I check for traps\"</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L33\" data-line-number=\"33\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC33\">Anon finds his home at last</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L34\" data-line-number=\"34\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC34\">He's hungry</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L35\" data-line-number=\"35\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC35\">Being a single mother is a thankless job.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L36\" data-line-number=\"36\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC36\">TIL That when you're pulling out Minigun, you're actually pulling out suitcase that then transforms into Minigun.</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L37\" data-line-number=\"37\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC37\">OMG guys don't look!!! 🙈🙈🙈</td>\n</tr>\n<tr>\n<td id=\"file-reddit-js-v3-output-L38\" data-line-number=\"38\">\n</td>\n<td id=\"file-reddit-js-v3-output-LC38\">hyubsama's emote of his own face denied for political reasons because twitch thinks its a picture of Kim Jong Un</td>\n</tr>\n</tbody>\n</table>\n<h3>Additional Resources</h3>\n<p>And there's the list! At this point you should feel comfortable writing your first web scraper to gather data from any website. Here are a few additional resources that you may find helpful during your web scraping journey:</p>\n<ul>\n<li><a href=\"https://www.scraperapi.com/blog/the-10-best-rotating-proxy-services-for-web-scraping\">List of web scraping proxy services</a></li>\n<li><a href=\"https://www.scraperapi.com/blog/the-10-best-web-scraping-tools\">List of handy web scraping tools</a></li>\n<li><a href=\"https://www.scraperapi.com/blog/5-tips-for-web-scraping\">List of web scraping tips</a></li>\n<li><a href=\"https://www.scraperapi.com/blog/free-shared-dedicated-datacenter-residential-rotating-proxies-for-web-scraping\">Comparison of web scraping proxies</a></li>\n<li><a href=\"https://github.com/cheeriojs/cheerio\">Cheerio Documentation</a></li>\n<li><a href=\"https://github.com/GoogleChrome/puppeteer\">Puppeteer Documentation</a></li>\n</ul>\n<hr>"},{"url":"/docs/articles/reading-files/","relativePath":"docs/articles/reading-files.md","relativeDir":"docs/articles","base":"reading-files.md","name":"reading-files","frontmatter":{"title":"Reading Files","excerpt":"Web-Dev-Hubis a Unibit theme created for project documentations. You can use it for your project.","seo":{"title":"Reading files","description":"The simplest way to read a file in Node.js is to use the fs.readFile() method, passing it the file path, encoding and a callback function that will be called","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Reading files","keyName":"property"},{"name":"og:description","value":"This is the Reading files page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Reading files"},{"name":"twitter:description","value":"This is the Reading files page"}]},"template":"docs"},"html":"<p>The simplest way to read a file in Node.js is to use the <code class=\"language-text\">fs.readFile()</code> method, passing it the file path, encoding and a callback function that will be called with the file data (and the error):</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/Users/joe/test.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'utf8'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err<span class=\"token punctuation\">,</span> data</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Alternatively, you can use the synchronous version <code class=\"language-text\">fs.readFileSync()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> fs<span class=\"token punctuation\">.</span><span class=\"token function\">readFileSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/Users/joe/test.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'utf8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Both <code class=\"language-text\">fs.readFile()</code> and <code class=\"language-text\">fs.readFileSync()</code> read the full content of the file in memory before returning the data.</p>\n<p>This means that big files are going to have a major impact on your memory consumption and speed of execution of the program.</p>\n<p>In this case, a better option is to read the file content using streams.</p>"},{"url":"/docs/articles/semantic/","relativePath":"docs/articles/semantic.md","relativeDir":"docs/articles","base":"semantic.md","name":"semantic","frontmatter":{"title":"Semantic Versioning","sections":[],"seo":{"title":"","description":"Semantic Versioning using npm","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>If there's one great thing in Node.js packages, it's that they all agreed on using Semantic Versioning for their version numbering.</p>\n<p>The Semantic Versioning concept is simple: all versions have 3 digits: <code class=\"language-text\">x.y.z</code>.</p>\n<ul>\n<li>the first digit is the major version</li>\n<li>the second digit is the minor version</li>\n<li>the third digit is the patch version</li>\n</ul>\n<p>When you make a new release, you don't just up a number as you please, but you have rules:</p>\n<ul>\n<li>you up the major version when you make incompatible API changes</li>\n<li>you up the minor version when you add functionality in a backward-compatible manner</li>\n<li>you up the patch version when you make backward-compatible bug fixes</li>\n</ul>\n<p>The convention is adopted all across programming languages, and it is very important that every <code class=\"language-text\">npm</code> package adheres to it, because the whole system depends on that.</p>\n<p>Why is that so important?</p>\n<p>Because <code class=\"language-text\">npm</code> set some rules we can use in the <code class=\"language-text\">package.json</code> file to choose which versions it can update our packages to, when we run <code class=\"language-text\">npm update</code>.</p>\n<p>The rules use those symbols:</p>\n<ul>\n<li><code class=\"language-text\">^</code></li>\n<li><code class=\"language-text\">~</code></li>\n<li><code class=\"language-text\">></code></li>\n<li><code class=\"language-text\">>=</code></li>\n<li><code class=\"language-text\">&lt;</code></li>\n<li><code class=\"language-text\">&lt;=</code></li>\n<li><code class=\"language-text\">=</code></li>\n<li><code class=\"language-text\">-</code></li>\n<li><code class=\"language-text\">||</code></li>\n</ul>\n<p>Let's see those rules in detail:</p>\n<ul>\n<li><code class=\"language-text\">^</code>: It will only do updates that do not change the leftmost non-zero number. If you write <code class=\"language-text\">^0.13.0</code>, when running <code class=\"language-text\">npm update</code>, it can update to <code class=\"language-text\">0.13.1</code>, <code class=\"language-text\">0.13.2</code>, and so on, but not to <code class=\"language-text\">0.14.0</code> or above. If you write <code class=\"language-text\">^1.13.0</code>, when running <code class=\"language-text\">npm update</code>, it can update to <code class=\"language-text\">1.13.1</code>, <code class=\"language-text\">1.14.0</code> and so on, but will not update to <code class=\"language-text\">2.0.0</code> or above.</li>\n<li><code class=\"language-text\">~</code>: if you write <code class=\"language-text\">~0.13.0</code>, when running <code class=\"language-text\">npm update</code> it can update to patch releases: <code class=\"language-text\">0.13.1</code> is ok, but <code class=\"language-text\">0.14.0</code> is not.</li>\n<li><code class=\"language-text\">></code>: you accept any version higher than the one you specify</li>\n<li><code class=\"language-text\">>=</code>: you accept any version equal to or higher than the one you specify</li>\n<li><code class=\"language-text\">&lt;=</code>: you accept any version equal or lower to the one you specify</li>\n<li><code class=\"language-text\">&lt;</code>: you accept any version lower to the one you specify</li>\n<li><code class=\"language-text\">=</code>: you accept that exact version</li>\n<li><code class=\"language-text\">-</code>: you accept a range of versions. Example: <code class=\"language-text\">2.1.0 - 2.6.2</code></li>\n<li><code class=\"language-text\">||</code>: you combine sets. Example: <code class=\"language-text\">&lt; 2.1 || > 2.6</code></li>\n</ul>\n<p>You can combine some of those notations, for example use <code class=\"language-text\">1.0.0 || >=1.1.0 &lt;1.2.0</code> to either use 1.0.0 or one release from 1.1.0 up, but lower than 1.2.0.</p>\n<p>There are other rules, too:</p>\n<ul>\n<li>no symbol: you accept only that specific version you specify (<code class=\"language-text\">1.2.1</code>)</li>\n<li><code class=\"language-text\">latest</code>: you want to use the latest version available</li>\n</ul>"},{"url":"/docs/articles/semantic-html/","relativePath":"docs/articles/semantic-html.md","relativeDir":"docs/articles","base":"semantic-html.md","name":"semantic-html","frontmatter":{"title":"Web Design","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<p>Three different aspects of web site production:</p>\n<ul>\n<li>Content -- the text, images, etc. What the user wants to read.</li>\n<li></li>\n<li>Style -- how the content is arranged on the page, fonts, colours, page style.</li>\n<li>Behaviour -- how users interact with the site, data processing, dynamic page elements.</li>\n</ul>\n<p>Since each requires different skills, a good (software) design would seperate them.</p>\n<p>Each of these areas has a different associated technology in the web world: HTML, Cascading Style Sheets (CSS) and Javascript.</p>\n<p>Note that it hasn't always been this way, HTML can do a bunch of Style things (eg. the &#x3C;font> tag) but now that we have good standards compliant browser we don't need to use them.</p>\n<h2>Document Production</h2>\n<p><img src=\"http://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/Metal_movable_type.jpg/640px-Metal_movable_type.jpg\" alt=\"image\"></p>\n<p>Moveable type, source <a href=\"http://commons.wikimedia.org/wiki/File:Metal_movable_type.jpg\">Wikimedia Commons</a></p>\n<p>Many years ago, when printed pages were made with moveable type, the printer who assembled the page of type was responsible for all aspects of the page design. They would choose the typeface, and in the early days even make the matrix and cast the type themselves. They would lay out the lines of text, choosing suitable spacing in each line, deciding where to break the line and adding hyphens to improve the overall look of the page while maintaining readability. The page was then set in the press and pages were printed.</p>\n<p>Even before that, the monks who copied manuscripts did everything themselves, copying the text and adding beautiful illuminations to each page to add to the value of the book.</p>\n<p>As the industry developed though, the task of type-setter became more mechanical. Other people became expert in how to best lay out pages, what visual design elements would best communicate the desired message etc. The type-setter still made the technical choices to achieve the desired goals, but didn't have to be an expert in design. The production of a printed document would involve a number of people who were expert in their given area, from author to visual designer to type-setter.</p>\n<p>This team based approach to document production means that each person can develop their own expertise and to a certain extent, doesn't need to worry about what the people later in the chain will do. The author doesn't worry about how to place figures or images in the page, just that they will be there; the designer doesn't need to be concerned about kerning and the use of em-spaces in type-setting; the type-setter isn't an expert in the content of the text. All can work together to produce a superior printed document.</p>\n<p>The world of document production worked like this for a long time until the invention of the personal computer and <em>Desktop Publishing</em> software. Suddenly, authors became designers and type-setters through easy to use computer software. They could choose fonts, set margins, force hyphenation and make minute decisions about the layout and look and feel of each page. Not surprisingly, this becomes a significant distraction from the task of creating content, but it also means that the expertise of the specialist designer or type-setter isn't used any more. This might lead to more productivity as the production process is compressed, but it doesn't usually lead to more readable, better presented documents; many of the early self-produced documents were an unsightly mix of fonts, colours and sizes.</p>\n<p>If we fast-forward to the software tools we have today for document production, it's interesting to note that the expertise of the designer and typesetter has crept back in to the process. Rather than being involved in the production of every document, these people are now able to write stylesheets and templates as well as contribute to the algorithms used in the software to lay out the text on a page. Most companies will have a standard document template that is used for reports or letters, this has usually been designed by a professional and all the author needs to do is enter the text in the right place. Stylesheets in word processors mean that there will be a consistency of font use throughout the document and importantly, that the decisions on which fonts and how they are used doesn't need to be made by the author.</p>\n<p>So, to summarise this little discussion of history, there have always been people who's expertise is the way that a text is rendered on the page. With the onset of desktop publishing software, there has been a tendency for the author to spend time in document design, meaning that the relevant expertise was not being applied. However, modern software now allows for the designer's voice to be heard again through the use of stylesheets and document templates. This leaves the author to concentrate on the text meaning they will be more productive and should produce better looking documents as well.</p>\n<h2>Web Document Production</h2>\n<p>Fundamentally, the web is a technology for delivering content to readers through a document based interface (the web browser). So, producing web content is a document production process and as such, should parallel the ideas discussed above. It's interesting to look at the development of HTML and see how it parallels the developments described above.</p>\n<p>Early HTML was a language for encoding content. It included tags for headings, paragraphs, lists etc. but didn't provide any way to change the way these things were rendered by the browser. The browser made sensible decisions and web documents all looked about the same. The focus was on the content. Soon, <a href=\"http://www.ncsa.illinois.edu/Projects/mosaic.html\">graphical browsers</a> started to appear that allowed images to be included in pages and people started to want to have some control over the appearance of their pages.</p>\n<p>The growth of the web into the commercial arena and the wider range of documents being published led to the 'browser wars' between Netscape and Microsoft. One of the features of this war was the arms race of features in each browser designed to make web pages look better. Each vendor would introduce new ways to control the look and feel of pages, for example the &#x3C;FONT> tag was introduced by Netscape to allow control of the font used to display text while Microsoft included the &#x3C;MARQUEE> tag that displayed text scrolling across the page. Eventually, some of these tags were standardised into a later version of HTML and were implemented by most of the browsers. These tags encouraged authors to get involved in page design, in fact they had to since the only way to control the appearance of a page was to insert codes into the text.</p>\n<p>While the &#x3C;FONT> tag allowed some control over the appearance of text, there was still a problem of laying out a page as a whole. The solution that became standard practice was to mis-use the &#x3C;TABLE> tag and construct the whole page as a table with rows and columns for the different page elements such as header, menu, content and footer. This worked really well, but again meant that the HTML code that an author was writing had to contain a lot of information about the layout of the page. In addition, it was common for people to mis-use tags just for the sake of appearance, for example to have more control over the appearance of headings, one might just encode them using &#x3C;B> or &#x3C;FONT> tags rather than header tags.</p>\n<p>All of these additions to HTML and the mis-use of existing tags meant that a language that was originally designed to allow authors to concentrate on content had turned into a page layout language. Luckily, sense has prevailed and we have now developed ways to control page layout without adding special instructions into the HTML code - that is, we have the Cascading Stylesheet language (CSS). Once again, we can let the author concentrate on content in HTML while all (or most) design decisions are encoded in the stylesheet.</p>\n<p>The current suite of web languages understood by your browser (HTML, CSS and Javascript) each serve different roles in the web development process:</p>\n<ul>\n<li>HTML - Content</li>\n<li></li>\n<li>CSS - Style</li>\n<li>Javascript - Behaviour</li>\n</ul>\n<p>The third of these - Javascript and Behaviour - refer to the way that Javascript can be used to change the way that the user interacts with the page. This doesn't really have an analogue in the print document production world but it's an important aspect of modern web content production. It fits into this framework because the behavioural changes that Javascript can introduce should not be the concern of the content author or the visual designer (though both might have opinions on what they'd like to see).</p>\n<p>It is useful to think of these three aspects of web design as independent things. The same web content could be presented using alternate stylesheets and have a completely different impact. Similarly, Javascript can be used to change the way that a user interacts with content, making it more usable. We can see the Style and Behaviour aspects as layers that are applied to the core Content to enhance it for the user.</p>\n<h2>The Separation of Concerns</h2>\n<p>From a Computer Science/Software Engineering point of view there is a very important principle called the <a href=\"http://en.wikipedia.org/wiki/Separation_of_concerns\">Separation of Concerns</a> (SoC) that is illustrated perfectly by the way that the various web languages have evolved. The SoC principle is about partitioning the work that we do in software development into parts that can be considered separately. This is achieved by <em>modularisation</em> within a software project and is helped by things like classes and interface descriptions between modules</p>\n<ul>\n<li>in fact these things have been developed to support SoC.</li>\n</ul>\n<p>The SoC principle allows us to develop large complex software by allowing us to concentrate on different aspects of the solution. It could be that we do that alone, spending time on one aspect and then another, or as a team with different people assigned to different aspects. Either way, being able to work on part of the problem makes it manageable and improves the overall quality of the solution.</p>\n<p>In web development, the separation of concerns is supported by the different languages that work together to build a modern web application. It is important to recognise this and make sure that we use each of these tools in such a way as to respect their roles and capabilities. So, while it is possible to use HTML structures to make text large and bold for a heading, we don't, we use one of the header tags and rely on the stylesheet to apply the appropriate settings. Having the author respect good HTML usage means that the designer can make assumptions about the page structure in the stylesheet and ensure that the document appearance is consistent for the user.</p>\n<h2>Semantic HTML Markup</h2>\n<p>One corollary of this kind of thinking is that each component that we use should be used as it was designed and according to it's role in the overall picture. In particular for HTML this implies that the markup we use should encode only the <em>structure</em> of the document rather than aspects of the <em>appearance</em> which is properly dealt with using CSS. Further, this means that we should use markup in a way that imparts useful <em>meaning</em> to the document structure. This is generally known as using <em>Semantic HTML</em> (<a href=\"http://en.wikipedia.org/wiki/Semantic_HTML\">Wikipedia</a>, <a href=\"http://microformats.org/wiki/posh\">POSH</a> on Microformats.org) and is the current best practice in HTML authoring.</p>\n<p>To clarify this point we can look at some examples. Writing semantic HTML means using the HTML tags as they were designed to be used - to convey the meaning of a particular document structure or textual element. So a good example is when we want to encode the main heading in a page I would use the H1 tag:</p>\n<p>This seems obvious, but in some cases, an author might decide that the default rendering of the H1 tag is too big, so rather than using CSS to define an alternate style, they use the H2 tag instead.</p>\n<p>This may seem harmless, after all we've still marked up this text as a heading. The problem is that we've lost the information that this is the main heading in the page that was conveyed by the H1 tag.</p>\n<p>Even worse, I could use the B (bold) tag and the now deprecated FONT tag to make my text look like a heading:</p>\n<p>In this case the appearance might be ok but the markup is not appropriate for the task. The author's focus has been on the appearance rather than the meaning of the markup; we could say that the author is overstepping their responsibilities a little - the appearance of the text should be the domain of the designer. If the heading is encoded as in this example, the designer will not be able to re-style the headings in a robust way (we could apply a style to bold paragraphs but that would also apply to any other use of this markup in the text).</p>\n<p>The example illustrates the importance of using an appropriate markup tag where one exists. In the case of a heading, this is pretty clear but other parts of the document might need a bit of thought to see what markup is appropriate. One common issue is whether to use a TABLE for some information that you want to appear as a list or array. TABLE is meant for data that has columns and rows, for example, the results of a survey or test scores for a class of students.</p>\n<p>While it is less common these days, the most frequent mis-use of tables is as a means of laying out all or part of a page as a rectangular grid. You may still see this in the navigation links on a page which the designer might want to appear in a row near the top of the page or a column down the side. Semantically this is a list and should really be marked up as such. If a table-like appearance is needed then CSS rules can be used to acheive this (eg. display: table-row).</p>\n<p>TABLE is sometimes used for things that might be more appropriately marked up as lists, eg. using UL (unordered list), OL (ordered list) or DL (description list) tags. An example might be the list of ingredients for a recipe; you might be tempted to encode it as a table because you want the quantities to be lined up in a column on the left. It might be appropriate to use TABLE here but a bit of reflection might tell you that it's really an unordered list - for example you might note that while there's usually a quantity for each ingredient it's not always the case ('salt to taste') so this isn't really columns of data, just list items that might have a distinguished field.</p>\n<p>A final example might be the description of a staff member in an online directory, the commonly contains entries for name, office, phone number, email address etc and it might seem natural to encode this as a table if you want a nice neat layout. However, in this case there is more appropriate markup in the DL (description list) tag. Each entry in a description list contains two parts DT (description title) and DD (description data) which are used to mark up the property name and value:</p>\n<p>Some authors are put off the description list because of the default style that is associated with it which puts the DT and DD parts on different lines. However, changing this is very easy with CSS so it really should be used for information that is structured in this way.</p>\n<p>Using the right semantic markup <em>adds</em> information to the text that can be used by the designer to enhance the communicative power of the web page. Using a consistent style for headings makes it easier for a reader to see the structure of a page and understand it. Similarly, I can use inline tags for things like <em>emphasis</em> (EM), Abbrv. (abbreviations, ABBR), \"a quotation\" (Q) or <strong>a strongly emphasised point</strong> (STRONG). Each of these has a default style (or in some cases like ABBR, is just the same as the default text style) but can be re-styled by the designer to achieve a particular look and feel. If these elements are used consistently throughout a text, the overall readability of the text can be greatly improved.</p>\n<p>Another motivation for using semantic markup is for users who cannot read via a normal web browser. Blind people make use software that reads out the content of a web page; if the page uses the appropriate semantic markup then the software can make use of this to present the content more appropriately to the user. This might include using the headings to provide a summary of the page or the emphasis tags to generate an appropriate intonation pattern. You might also think about the difference in reading out a list vs. a table of data - that might be a useful way of choosing between the two for a particular part of your page.</p>\n<h3>Exercises</h3>\n<ol>\n<li>\n<p>Find an appropriate HTML tag to mark up the following items:</p>\n<ul>\n<li>the name of a book that you are citing in an essay</li>\n<li>a fragment of computer code, eg. a bit of Python</li>\n<li>an abbreviation or acronym and it's expansion (e.g. HTML - Hypertext Markup language)</li>\n</ul>\n</li>\n</ol>\n<h2>Extending the Semantics of HTML</h2>\n<p>The tag set defined by the HTML standard supports a wide range of content and was designed to cover the most common document structures and entities that appear on the web. However, the designers of HTML couldn't forsee everything that you might want to mark in your documents and so an extension mechanism is included such that you can effectively add new semantics to existing tags. This is the HTML class attribute which allows you to enter a user defined class for any tag. It is effectively a specialisation of any tag that can be used to encode special meanings for your documents.</p>\n<p>The class attribute is meant to contain one or more class identifiers which are single words that mean something to your application. They can be applied to any HTML tag. An example might be the use of the class important to mark something as important in some way. I can add this to a paragraph or a list item:</p>\n<p>In this example, the class attribute is specialising the meaning of the main HTML tag so that we can differentiate important paragraphs and list items from others. We might want to do this so that we can highlight them in some way in the final presentation of the text. In this way, the designer can make the decision about how to emphasise this text (maybe differently on desktop and mobile devices) and the author is free just to decide which things are important. The alternative in this case might have been to use an emphasis EM tag around the text we wanted to emphasise. The advantage of the class attribute is that we identify the whole paragraph or list item as important and we are able to differentiate different kinds of emphasis. This might be useful where, for example, there are some things that are 'important' and others that are 'critical' in a set of instructions. The use of class attributes means that we can transfer the concepts that mean something in the domain of the document directly into the HTML code and then allow the designer to make decisions about how the different ideas are expressed visually.</p>\n<p>Sometimes there isn't an HTML tag that really fits what you are trying to express; in these cases you can use the generic DIV and SPAN tags along with a class attribute. For example, it has been common to use a series of DIV tags to denote the overall structure of a web page:</p>\n<p>This pattern allows the designer to write a stylesheet that places each section at the right place on the page with the right fonts, colours etc. This pattern has become so common that the new HTML5 standard has included new tags named after some of these classes, so you can now write:</p>\n<p>This is part of the evolution of the HTML language; the observation that some kinds of structure are being used very widely leading to the introduction of new elements that properly convey the semantics that are required.</p>\n<p>One final note about the use of classes to convey new semantics. It is possible to use more than one class name where that is appropriate to convey more specialisations. For example, all of the code examples in this text are marked up as PRE tags with the class code and another class to denote the language the code is written in, so on this page I have examples like:</p>\n<p>Note that I have to encode the HTML markup as entity references using the &#x26; notation so that they appear correctly when you view them in the web browser (view source to check this out). Having more than one class name means that I can apply standard styling to code examples and special style for different languages. It also means that I could write a script to pull out all of the examples in a given language if I wanted to check their syntax etc.</p>\n<h1>A View of HTML\n\n</h1>\n<p>Rather than being a chapter that will teach you the HTML language this will be a chapter about the language, how it works, why it has the structures it does and what you should and shouldn't do with it.</p>\n<p>Most people will know some HTML by now (assuming you've been studying computing for a while or have a general interest in the web). My task here is not to teach you HTML or act as a reference for the language, there are plenty of resources around that will do this. Some examples are:</p>\n<ul>\n<li><a href=\"http://www.w3schools.com/html/default.asp\">w3schools HTML tutorial</a> w3schools is one of the most widely used tutorial and reference sites on the web for HTML and other web technologies.</li>\n<li></li>\n<li><a href=\"https://developer.mozilla.org/en-US/learn/html\">Learn HTML</a> from the Mozilla Developer Network, the organisation that produces the Firefox browser. This page has pointers to a number of HTML tutorials and resources.</li>\n</ul>\n<h2>About HTML</h2>\n<p>HTML is a <em>markup language</em>, which is a formal language used to add encode structured documents, often by mixing formal elements and plain text. Another example is the LaTeX language used to typeset scientific and technical documents. Here's a fragment of LaTeX that shows the use of commands preceded by a backslash character and curly braces to enclose text:</p>\n<p>These commands are interpreted by the LaTeX system which uses then to produce nicely typeset PDF output. Markup can also be used to identify regions of text for analysis. Here's an example from a language corpus used to study human interaction:</p>\n<p>In this example, special character sequences are used to mark things like speaker turns, pauses, phrases and overlapping speech. This markup can be used to help analyse the language and find examples of certain linguistic phenomena (for example, find me examples of <em>'you know'</em> and show me what the next person says in response).</p>\n<p>HTML is the <em>Hypertext</em> Markup Language, meaning that it is designed to encode hypertext documents - that is, documents containing links to other documents on the World Wide Web. In fact, the hyperlink is just a small part of HTML and much more interesting are all the other parts of the language that allows us to produce useful documents for the web.</p>\n<p>HTML is based on an earlier standard called SGML (Standard Generalised Markup language) which had a successor called XML (eXtensible Markup Language). SGML and XML are both languages for defining markup languages, that is they define the syntax of a markup language but allow you to develop your own language for a specific purpose. The syntax is the angle brackets containing start and end tags &#x3C;p> and &#x3C;/p> that you will be familiar with (and a number of other rules). SGML and XML based languages all use this same syntax but allow the language designer to make up their own tags and define how they should be used together. HTML was designed originally by Tim Berners-Lee and later by the W3C as a language to encode pages of content for the web.</p>\n<p>Importantly, HTML is a <em>markup language</em> not a <em>programming language</em>. The job of a markup language is to record the structure of a document; that structure can then be interpreted by a program to generate some output. A programming language contains instructions that will be executed (or interpreted) to carry out some action or compute some result.</p>\n<h2>Versions of HTML</h2>\n<p>The first version of HTML was developed by Tim Berners-Lee as part of his World Wide Web project along with the HTTP protocol and the URL syntax. At first it was a very simple language for encoding articles and so had tags for headings, paragraphs, lists etc. Later, the language evolved to encompas new features in the browser such as the ability to display images, tables and modify the font that text was displayed in. The evolution of HTML has been quite gradual and at times part of intense competition between browser vendors (look up the <a href=\"http://en.wikipedia.org/wiki/Browser_wars\">Browser Wars</a> to get the full story). The Internet Engineering Task Force (IETF) and later the World Wide Web Consortium (W3C) tried to standardise the language but it took some time for industry practice to align with the W3C standards. Luckily now we are in a period of relative stability where the standards process aligns well with what the major browsers are able to understand.</p>\n<p>A version of HTML is defined by a Document Type Definintion (DTD) - a formal definition of the allowed tags and attributes and the allowed structure of an HTML document. The DTD says that you can have a &#x3C;p> tag and that it can contain a &#x3C;strong> tag but that a &#x3C;li> has to be inside a &#x3C;ul> or &#x3C;ol> tag and so on. If a document conforms to the DTD (follows the rules) we say that it is <em>valid</em>, if it contains errors such as having an unknown tag or a tag in the wrong place it is invalid.</p>\n<p>Early versions of HTML were subject to a lot of change and it wasn't until HTML version 4.0.1, released in 1999 that there was a bit of stability in the language and consensus about what should be included and what should be left out. Before then, HTML had grown to contain a lot of <em>visual</em> markup that had been developed by the browser vendors (Netscape and Microsoft) to try to make their browser look better than the competition. An example is the &#x3C;font> tag introduced by Microsoft (and copied by Netscape) which could change the font used to render some text. By the time HTML 4.01 was published, Cascading Style Sheets (CSS) were becoming more widely adopted and the use of markup that explicitly referred to the visual appearance of the content was discouraged.</p>\n<p>HTML 4.0.1 is still the latest version of the official W3C standard although there have been a large number of changes implemented by the browser vendors since the time it was released.</p>\n<p>In 1997 the XML standard was introduced. XML was intended to generalise the use of markup on the web and allow developers to design thier own markup languages for specific purposes. XML is an evolution of the earlier SGML standard on which HTML had been based; it simplified the syntax rules a lot and made it easier to write parsers for XML. One of the early applications of XML was to develop XHTML - a version of HTML converted to adhere to the XML standard. XHTML 1.0 retained almost all of the tags in HTML 4.0.1 but introduced the constraints of XML. For example in an XML document every opening tag must have a corresponding close tag; in HTML, many close tags are optional (e.g. you can leave out the closing &#x3C;p> tag for a paragraph since it is implied by the next opening &#x3C;p> tag) and many tags never have a close tag because they never contain any text (e.g. &#x3C;img> or &#x3C;br>). In XHTML then, paragraphs always require a close tag and empty tags are written with the new XML syntax: &#x3C;br />.</p>\n<p>One of the motivations for introducing XHTML was to try to encourage web developers to adhere more closely to the published standards. The web had grown up with a culture of view-source where people would learn how to encode web pages by looking at the source HTML of other web pages rather than by reading the standard. They would then write their own pages and if they looked ok in the browser, they would publish them. To cope with the amount of badly formed HTML content on the web, the browser vendors built thier HTML parsers to be very forgiving. If you put a paragraph inside an image tag or a header inside a paragraph it would have a go at rendering the content. As a consequence, very few web publishers cared about generating proper HTML and anyone who wanted to parse web content had to make very few assumptions about HTML structure.</p>\n<p>Around this time there was a move towards having more automated clients consuming web content. One group was the search engine developers who were just interested in the textual content of pages but other groups were trying to glean real data from the web. For example, price comparison services were starting up which tried to extract pricing information from store listings. Other services might try to find event information from web pages. All of these services needed to parse the HTML structure and had problems when the HTML was badly structured; this became known as <a href=\"http://essaysfromexodus.scripting.com/whatIsTagSoup\">Tag Soup</a> since one could not rely on proper HTML structure it was just treated as an unstructured collection of tagged text. Permissive parsers such as <a href=\"http://www.crummy.com/software/BeautifulSoup/\">Beautiful Soup</a> (Python) and <a href=\"http://home.ccil.org/~cowan/XML/tagsoup/\">Tagsoup</a> (Java) were developed to cope with the messy markup and give the developer as much detail as possible from the page.</p>\n<h1>HTML5</h1>\n<p>The most recent version of HTML is HTML5 - note the name with no spaces which is quite different to earlier versions. HTML5 was a big change in the way that the standard was put together and followed a long break in the development of standards for HTML: HTML 4.0.1 was last updated in 2000, HTML5 was finally released in 2012. The goal of HTML5 was to standardise current practice in browsers, rather than to define new structures or limit what was possible. The W3C worked with the browser developers to agree on standards for new technologies that they had introduced. For example, being able to include audio and video elements in HTML had been possible in some browsers; HTML5 defined a standard for these that all browser vendors could agree on and implement.</p>"},{"url":"/docs/articles/url/","relativePath":"docs/articles/url.md","relativeDir":"docs/articles","base":"url.md","name":"url","frontmatter":{"title":"The Uniform Resource Locator (URL)","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h3>Let's look at the anatomy of a URL:\n\n</h3>\n<p>The first part of the URL is http://, this is often left out when URLs are written, so we might see the above as www.mq.edu.au/about/profile/history.html. This will work when you type it into your web browser because the browser will assume you meant this as an HTTP URL. However, if we are being pedantic, the prefix is required as it tells us something about the web address - that we should use the HTTP protocol to access it.</p>\n<p>URLs are not only useful for HTTP addresses. Other <em>schemes</em> are allowed and they tell the client how to get access to the content that the URL describes. The most common you will see is https:// which is the secure variant of HTTP (we'll find out about that later). HTTPS uses the same protocol as HTTP but over a secure connection so that information that is exchanged can't be intercepted. Another scheme is ftp:// which tells the browser to use the older FTP protocol to access the content. Finally, you might see a mailto URL which allows us to write a link that triggers the browser to start composing an email message. This has a slightly different form: <a href=\"mailto:Steve.Cassidy@mq.edu.au\">Steve.Cassidy@mq.edu.au</a> but it's still a URL. In fact, the pattern looks like this:</p>\n<p>For the HTTP scheme the pattern is:</p>\n<p>The first part &#x3C;net_loc> is the network location of the resource: the domain name of the web server that holds the web page we want. This is preceded by two forward slashes and followed by a single forward slash. Then follows the &#x3C;path> which the server will use to identify which page we want. The ;&#x3C;params>?&#x3C;query>#&#x3C;fragment> are used to further qualify the resource that we want; we'll see some examples of how they are used later in the book.</p>\n<p>The URL is a unique form of identifier in that it has two roles. First, it identifies a document, video or music file that's out on the web (we call these things <em>resources</em>). Each resource has a unique URL and you can refer to them via the URL. If we two people refer to the same URL, then they know they have read the same document. Secondly, the URL contains enough information for a web client to retrieve a copy of the resource. The client can use the scheme defined (HTTP) to connect to the server and send an HTTP request for the path part of the URL.</p>\n<p>There are other kinds of formal identifier that don't have this second property. For example, every book has an ISBN (International Standard Book Number) which uniquely identifies it. However, the ISBN contains no information about how to get a copy of the book. To do so, you'd need to look up the ISBN in a catalogue which might tell you who the publisher was and then contact them for a copy. Alternately you could go to a book-shop or library and use their catalogue to find the book. With a URL, there's no need for a catalogue or third party service to decode the identifier. The information on how to retrieve the resource is right there in the Uniform Resource Locator.</p>\n<p>The <a href=\"http://www.ietf.org/\">Internet Engineering Task Force (IETF)</a> is as close as we get to a governing body for the Internet and it's home to many of the standards that define how the Internet and the Web work. The standards documents are called <em>Request for Comments</em> or RFC, a name which reflects the democratic nature of the early Internet. <a href=\"http://datatracker.ietf.org/doc/rfc2068/\">RFC2068</a> defines HTTP version 1.1 and <a href=\"http://datatracker.ietf.org/doc/rfc1738/\">RFC1738</a> defines the URL. Look out also for <a href=\"http://datatracker.ietf.org/doc/rfc2324/\">RFC2324</a> which can be relevant after a long coding session.</p>\n<h2>Uniform Resource Identifiers</h2>\n<p>There's another similar term that is sometimes used instead of URL: Uniform Resource Identifier (URI). URI is actually a more general term that includes URLs and Universal Resource Names (URNs). URNs are identifiers that don't contain any locator information such as the ISBN. They have a formal syntax so I can cite a particular ISBN as a URN as URN:ISBN:978-0-395-36341-6 (an example from the <a href=\"http://tools.ietf.org/html/draft-ietf-urnbis-rfc3187bis-isbn-urn-01\">IETF RFC3187</a> document that defines the standard). As explained above, we need a third party service to resolve a URN into a real location (a URL). You might see the term URI used in discussions of web technologies; it is often used instead of URL but generally means the same thing if we're talking about HTTP based services.</p>\n<p>Since URLs are both names and addresses it becomes important that once you put a resource on the web, it stays there. This is discussed in Tim Berners-Lee's paper called \"<a href=\"http://www.w3.org/Provider/Style/URI\">Cool URIs don't change</a>\". It's a principle that all web designers should bear in mind as it is easy to violate as we re-build old web-sites.</p>\n<h2>Absolute and relative URLs</h2>\n<p>When we include a URL in a web page there are a number of choices about how it can be written. The first option is to include the full URL:</p>\n<p>This is clearly a link to a resource on the server at <em>example.org</em> using the http protocol. However, if this page is being served by the server at <em>example.org</em> then we could also write this link as:</p>\n<p>This is known as a <em>relative URL</em> and is interpreted relative to the URL of the page that is currently being viewed. Let's assume that this page is at the URL <a href=\"http://example.org/about/info.html\">http://example.org/about/info.html</a>. Note that the URL above starts with a / character, in this case, the browser will interpret this URL by adding the protocol (http) and domain (example.org) parts of the page URL to this one to get <a href=\"http://example.org/static/style.css\">http://example.org/static/style.css</a>.</p>\n<p>Another way to write a URL is:</p>\n<p>In this case there is no / at the start of the URL and so this is interpreted relative to the page URL by removing everything but the last part of the URL <a href=\"http://example.org/about/\">http://example.org/about/</a> and then adding the new URL text to get <a href=\"http://example.org/about/static/style.css\">http://example.org/about/static/style.css</a>. Note that this is different to the previous example. If the intention was to reference the same URL as before, you could use the URL:</p>\n<p>Here the .. path refers to the parent directory (thinking of these paths as filenames) so the path becomes /about/../static/style.css which can be shortened to /static/style.css.</p>\n<p>The different URL styles have different uses. If you are writing a static HTML page that you will view on your local computer and perhaps host on the web somewhere (but you're not sure where) then you might put all of your files in one directory and use a relative URL like static/style.css to refer to linked resources. This ensures that your directory of files could be dropped anywhere into a web server file system and it would be self-contained and the links would work.</p>\n<p>However, if you are writing a web application that will be hosted on some domain (like example.org) you know that you have control of all URLs on that site and so would more likely use a relative URL starting with a / (like /static/style.css). This is important if your web application has complex routes (eg. pages like /users/steve/profile/edit) and you want to ensure that whatever the page URL being served, the links to stylesheets and other resources will work. The application can be deployed on different servers (like example.org and example.com) and the links will still work because they don't mention the domain name at all.</p>\n<p>Finally, absolute URLs (like <a href=\"http://example.org/static/style.css\">http://example.org/static/style.css</a>) will be used when we know that this URL is fixed at this location. It may be something external to our own site, or something that we know will be hosted at this URL on our site. There is an argument from a Search Engine Optimisation (SEO) viewpoint that all URLs in a website should be absolute urls even when they refer to assets on the same site. The reasons relate to the way that search engines crawl sites and the possible duplication of content if two URLs point to the same page (eg. <a href=\"https://example.org/\">https://example.org/</a> and <a href=\"http://example.org\">http://example.org</a>).</p>\n<p>One final form of relative URL looks like this:</p>\n<p>This URL is only missing the protocol part and is turned into an absolute URL by adding the protocol part of the current page URL. So if the current page was requested over http or https, this URL will use the same protocol. This is often useful if a site can be served over both protocols although it is increasingly the case that https is being used everywhere so this may become less common as time progresses.</p>\n<p><a href=\"https://www.facebook.com/sharer/sharer.php?u=https://bgoonz-blog.netlify.app/\">Share To Facebook:</a></p>"},{"url":"/docs/articles/writing-files/","relativePath":"docs/articles/writing-files.md","relativeDir":"docs/articles","base":"writing-files.md","name":"writing-files","frontmatter":{"title":"Writing Files","excerpt":"Web-Dev-Hubis a Unibit theme created for project documentations. You can use it for your project.","seo":{"title":"Writing Files","description":"This is the Writing Files page. The easiest way to write to files in Node.js is to use the fs.writeFile() API. const fs = require('fs');","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Writing Files","keyName":"property"},{"name":"og:description","value":"This is the Writing Files page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Writing Files"},{"name":"twitter:description","value":"This is the Writing Files page"}]},"template":"docs"},"html":"<p>The easiest way to write to files in Node.js is to use the <code class=\"language-text\">fs.writeFile()</code> API.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> content <span class=\"token operator\">=</span> <span class=\"token string\">'Some content!'</span><span class=\"token punctuation\">;</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/Users/joe/test.txt'</span><span class=\"token punctuation\">,</span> content<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">//file written successfully</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Alternatively, you can use the synchronous version <code class=\"language-text\">fs.writeFileSync()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> content <span class=\"token operator\">=</span> <span class=\"token string\">'Some content!'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> fs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFileSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/Users/joe/test.txt'</span><span class=\"token punctuation\">,</span> content<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">//file written successfully</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>By default, this API will <strong>replace the contents of the file</strong> if it does already exist.</p>\n<p>You can modify the default by specifying a flag:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/Users/joe/test.txt'</span><span class=\"token punctuation\">,</span> content<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">flag</span><span class=\"token operator\">:</span> <span class=\"token string\">'a+'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The flags you'll likely use are</p>\n<ul>\n<li><code class=\"language-text\">r+</code> open the file for reading and writing</li>\n<li><code class=\"language-text\">w+</code> open the file for reading and writing, positioning the stream at the beginning of the file. The file is created if not existing</li>\n<li><code class=\"language-text\">a</code> open the file for writing, positioning the stream at the end of the file. The file is created if not existing</li>\n<li><code class=\"language-text\">a+</code> open the file for reading and writing, positioning the stream at the end of the file. The file is created if not existing</li>\n</ul>\n<p>(you can find more flags at <a href=\"https://nodejs.org/api/fs.html#fs_file_system_flags\">https://nodejs.org/api/fs.html#fs_file_system_flags</a>)</p>\n<h2>Append to a file</h2>\n<p>A handy method to append content to the end of a file is <code class=\"language-text\">fs.appendFile()</code> (and its <code class=\"language-text\">fs.appendFileSync()</code> counterpart):</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> content <span class=\"token operator\">=</span> <span class=\"token string\">'Some content!'</span><span class=\"token punctuation\">;</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">appendFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'file.log'</span><span class=\"token punctuation\">,</span> content<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">//done!</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Using streams</h2>\n<p>All those methods write the full content to the file before returning the control back to your program (in the async version, this means executing the callback)</p>\n<p>In this case, a better option is to write the file content using streams.</p>\n<p>72</p>\n<p><a href=\"https://stackoverflow.com/posts/11194896/timeline\"></a></p>\n<p>Here's a sketch. Error handling is left as an exercise for the reader.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    path <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">dirTree</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">filename</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> stats <span class=\"token operator\">=</span> fs<span class=\"token punctuation\">.</span><span class=\"token function\">lstatSync</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        info <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> filename<span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">basename</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>stats<span class=\"token punctuation\">.</span><span class=\"token function\">isDirectory</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        info<span class=\"token punctuation\">.</span>type <span class=\"token operator\">=</span> <span class=\"token string\">'folder'</span><span class=\"token punctuation\">;</span>\n        info<span class=\"token punctuation\">.</span>children <span class=\"token operator\">=</span> fs<span class=\"token punctuation\">.</span><span class=\"token function\">readdirSync</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">child</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token function\">dirTree</span><span class=\"token punctuation\">(</span>filename <span class=\"token operator\">+</span> <span class=\"token string\">'/'</span> <span class=\"token operator\">+</span> child<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Assuming it's a file. In real life it could be a symlink or</span>\n        <span class=\"token comment\">// something else!</span>\n        info<span class=\"token punctuation\">.</span>type <span class=\"token operator\">=</span> <span class=\"token string\">'file'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> info<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>parent <span class=\"token operator\">==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// node dirTree.js ~/foo/bar</span>\n    <span class=\"token keyword\">let</span> util <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'util'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">inspect</span><span class=\"token punctuation\">(</span><span class=\"token function\">dirTree</span><span class=\"token punctuation\">(</span>process<span class=\"token punctuation\">.</span>argv<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>"},{"url":"/docs/articles/web-standards-checklist/","relativePath":"docs/articles/web-standards-checklist.md","relativeDir":"docs/articles","base":"web-standards-checklist.md","name":"web-standards-checklist","frontmatter":{"title":"Web Standards Checklist","weight":0,"excerpt":"(HTML, XHTML, XML, CSS, XSLT, DOM, MathML, SVG etc) and *pursue best practices* (valid code, accessible code, semantically correct code, user-friendly URLs etc).","seo":{"title":"Web Standards Checklist","description":"as an aid for developers who are interested in moving towards web standards","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Web Standards Checklist</h2>\n<p>The term web standards can mean different things to different people. For some, it is '<em>table-free sites</em>', for others it is '<em>using valid code</em>'. However, web standards are much broader than that. A site built to web standards should <em>adhere to standards</em> (HTML, XHTML, XML, CSS, XSLT, DOM, MathML, SVG etc) and <em>pursue best practices</em> (valid code, accessible code, semantically correct code, user-friendly URLs etc).</p>\n<p>In other words, a site built to web standards should ideally be <em>lean, clean, CSS-based, accessible, usable and search engine friendly</em>.</p>\n<h3>About the checklist</h3>\n<p>This is a guide that can be used:</p>\n<ul>\n<li>to show the breadth of web standards</li>\n<li>as a handy tool for developers during the production phase of websites</li>\n<li>as an aid for developers who are interested in moving towards web standards</li>\n</ul>\n<h3>The checklist</h3>\n<ol>\n<li>\n<p><a href=\"http://maxdesign.com.au/news/checklist/#quality\">Quality of code</a></p>\n<ol>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-1\">Does the site use a correct Doctype?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-2\">Does the site use a Character set?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-3\">Does the site use Valid (X)HTML?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-4\">Does the site use Valid CSS?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-5\">Does the site use any CSS hacks?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-6\">Does the site use unnecessary classes or ids?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-7\">Is the code well structured?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-8\">Does the site have any broken links?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-9\">How does the site perform in terms of speed/page size?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section1-10\">Does the site have JavaScript errors?</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"http://maxdesign.com.au/news/checklist/#degree\">Degree of separation between content and presentation</a></p>\n<ol>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section2-1\">Does the site use CSS for all presentation aspects (fonts, colour, padding, borders etc)?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section2-2\">Are all decorative images in the CSS, or do they appear in the (X)HTML?</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"http://maxdesign.com.au/news/checklist/#users\">Accessibility for users</a></p>\n<ol>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-1\">Are \"alt\" attributes used for all descriptive images?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-2\">Does the site use relative units rather than absolute units for text size?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-3\">Do any aspects of the layout break if font size is increased?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-4\">Does the site use visible skip menus?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-5\">Does the site use accessible forms?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-6\">Does the site use accessible tables?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-7\">Is there sufficient colour brightness/contrasts?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-8\">Is colour alone used for critical information?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-9\">Is there delayed responsiveness for dropdown menus (for users with reduced motor skills)?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section3-10\">Are all links descriptive (for blind users)?</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"http://maxdesign.com.au/news/checklist/#devices\">Accessibility for devices</a></p>\n<ol>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section4-1\">Does the site work acceptably across modern and older browsers?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section4-2\">Is the content accessible with CSS switched off or not supported?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section4-3\">Is the content accessible with images switched off or not supported?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section4-4\">Does the site work in text browsers such as Lynx?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section4-5\">Does the site work well when printed?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section4-6\">Does the site work well in Hand Held devices?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section4-7\">Does the site include detailed metadata?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section4-8\">Does the site work well in a range of browser window sizes?</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"http://maxdesign.com.au/news/checklist/#usability\">Basic Usability</a></p>\n<ol>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-1\">Is there a clear visual hierarchy?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-2\">Are heading levels easy to distinguish?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-3\">Is the site's navigation easy to understand?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-4\">Is the site's navigation consistent?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-5\">Does the site use consistent and appropriate language?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-6\">Does the site have a sitemap page and contact page? Are they easy to find?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-7\">For large sites, is there a search tool?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-8\">Is there a link to the home page on every page in the site?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-9\">Are links underlined?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section5-10\">Are visited links clearly defined?</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"http://maxdesign.com.au/news/checklist/#site\">Site management</a></p>\n<ol>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section6-1\">Does the site have a meaningful and helpful 404 error page that works from any depth in the site?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section6-2\">Does the site use friendly URLs?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section6-3\">Do your URLs work without \"www\"?</a></li>\n<li><a href=\"http://maxdesign.com.au/news/checklist/#section6-4\">Does the site have a favicon?</a></li>\n</ol>\n</li>\n</ol>\n<h3>1. Quality of code</h3>\n<h4>1.1 Does the site use a correct Doctype?</h4>\n<blockquote>\n<p>A doctype (short for 'document type declaration') informs the validator which version of (X)HTML you're using, and must appear at the very top of every web page. Doctypes are a key component of compliant web pages: your markup and CSS won't validate without them.</p>\n<p><em><a href=\"http://www.alistapart.com/articles/doctype/\">Fix your site with the right doctype</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.w3.org/QA/2002/04/valid-dtd-list.html\">http://www.w3.org/QA/2002/04/valid-dtd-list.html</a></li>\n<li><a href=\"http://css.maxdesign.com.au/listamatic/about-boxmodel.htm\">http://css.maxdesign.com.au/listamatic/about-boxmodel.htm</a></li>\n<li><a href=\"http://gutfeldt.ch/matthias/articles/doctypeswitch.html\">http://gutfeldt.ch/matthias/articles/doctypeswitch.html</a></li>\n</ul>\n<h4>1.2 Does the site use a Character set?</h4>\n<blockquote>\n<p>If a user agent (eg. a browser) is unable to detect the character encoding used in a Web document, the user may be presented with unreadable text. This information is particularly important for those maintaining and extending a multilingual site, but declaring the character encoding of the document is important for anyone producing XHTML/HTML or CSS.</p>\n<p><em><a href=\"http://www.w3.org/International/tutorials/tutorial-char-enc/\">Tutorial: Character sets &#x26; encodings in XHTML, HTML and CSS</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.w3.org/International/O-charset.html\">Character encodings</a></li>\n</ul>\n<h4>1.3 Does the site use Valid (X)HTML?</h4>\n<blockquote>\n<p>Valid code will render faster than code with errors. Valid code will render better than invalid code. Browsers are becoming more standards compliant, and it is becoming increasingly necessary to write valid and standards compliant HTML</p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://validator.w3.org/\">W3C Markup Validation Service</a></li>\n</ul>\n<h4>1.4 Does the site use Valid CSS?</h4>\n<blockquote>\n<p>You need to make sure that there aren't any errors in either your HTML or your CSS, since mistakes in either place can result in botched document appearance.</p>\n<p><em><a href=\"http://www.meyerweb.com/eric/articles/webrev/199904.html\">Help! My CSS Isn't Working!</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://jigsaw.w3.org/css-validator/\">W3C CSS Validation Service</a></li>\n</ul>\n<h4>1.5 Does the site use any CSS hacks?</h4>\n<blockquote>\n<p>Basically, hacks come down to personal choice, the amount of knowledge you have of workarounds, the specific design you are trying to achieve.</p>\n<p><em><a href=\"http://www.mail-archive.com/wsg@webstandardsgroup.org/msg05823.html\">Standard Hacks?</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://css-discuss.incutio.com/?page=CssHack\">CSS Hacks</a></li>\n<li><a href=\"http://css-discuss.incutio.com/?page=ToHackOrNotToHack\">To hack or not to hack</a></li>\n<li><a href=\"http://centricle.com/ref/css/filters/\">CSS filters</a></li>\n</ul>\n<h4>1.6 Does the site use unnecessary classes or ids?</h4>\n<blockquote>\n<p>I've noticed that developers learning new skills often end up with good CSS but poor XHTML. Specifically, the HTML code tends to be full of unnecessary divs and ids. This results in fairly meaningless HTML and bloated style sheets.</p>\n<p><em><a href=\"http://www.clagnut.com/blog/228/\">Markup tactics</a></em></p>\n</blockquote>\n<h4>1.7 Is the code well structured?</h4>\n<blockquote>\n<p>Semantically correct markup uses html elements for their given purpose. Well structured HTML has semantic meaning for a wide range of user agents (browsers without style sheets, text browsers, PDAs, search engines etc.)</p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.w3.org/2003/12/semantic-extractor.html\">Semantic data extractor</a></li>\n</ul>\n<h4>1.8 Does the site have any broken links?</h4>\n<p>Broken links can frustrate users and potentially drive customers away. Broken links can also keep search engines from properly indexing your site.</p>\n<p>More:</p>\n<ul>\n<li><a href=\"http://validator.w3.org/checklink\">W3C Link checker</a></li>\n</ul>\n<h4>1.9 How does the site perform in terms of speed/page size?</h4>\n<blockquote>\n<p>Don't make me wait... That's the message users give us in survey after survey. Even broadband users can suffer the slow-loading blues.</p>\n<p><em><a href=\"http://www.websiteoptimization.com/speed/\">Speed Up Your Site: Web Site Optimization</a></em></p>\n</blockquote>\n<h4>1.10 Does the site have JavaScript errors?</h4>\n<p>Internet Explore for Windows allows you to turn on a debugger that will pop up a new window and let you know there are javascript errors on your site. This is available under 'Internet Options' on the Advanced tab. Uncheck 'Disable script debugging'.</p>\n<h3>2. Degree of separation between content and presentation</h3>\n<h4>2.1 Does the site use CSS for all presentation aspects (fonts, colour, padding, borders etc)?</h4>\n<blockquote>\n<p>Use style sheets to control layout and presentation</p>\n<p><em><a href=\"http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-style-sheets\">Web Content Accessibility Guidelines 1.0 -- checkpoint 3.3</a></em></p>\n</blockquote>\n<h4>2.2 Are all decorative images in the CSS, or do they appear in the (X)HTML?</h4>\n<blockquote>\n<p>The aim for web developers is to remove all presentation from the html code, leaving it clean and semantically correct.</p>\n</blockquote>\n<h3>3. Accessibility for users</h3>\n<h4>3.1 Are \"alt\" attributes used for all descriptive images?</h4>\n<blockquote>\n<p>Provide a text equivalent for every non-text element</p>\n<p><em><a href=\"http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-text-equivalent\">Web Content Accessibility Guidelines -- checkpoint 1.1</a></em></p>\n</blockquote>\n<h4>3.2 Does the site use relative units rather than absolute units for text size?</h4>\n<blockquote>\n<p>Use relative rather than absolute units in markup language attribute values and style sheet property values'</p>\n<p><em><a href=\"http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-relative-units\">Web Content Accessibility Guidelines -- checkpoint 3.4</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-relative-units\">Web Content Accessibility Guidelines -- checkpoint 3.4</a></li>\n<li><a href=\"http://www.clagnut.com/blog/348/\">How to size text using ems</a></li>\n</ul>\n<h4>3.3 Do any aspects of the layout break if font size is increased?</h4>\n<p>Try this simple test. Look at your website in a browser that supports easy incrementation of font size. Now increase your browser's font size. And again. And again... Look at your site. Does the page layout still hold together? It is dangerous for developers to assume that everyone browses using default font sizes.</p>\n<h4>3.4 Does the site use visible skip menus?</h4>\n<blockquote>\n<p>A method shall be provided that permits users to skip repetitive navigation links.</p>\n<p><em><a href=\"http://www.section508.gov/index.cfm?FuseAction=Content&#x26;ID=12\">Section 508</a></em></p>\n</blockquote>\n<blockquote>\n<p>Group related links, identify the group (for user agents), and, until user agents do so, provide a way to bypass the group</p>\n<p><em><a href=\"http://www.w3.org/TR/WCAG10-TECHS/#tech-group-links\">Web Content Accessibility Guidelines -- checkpoint 13.6</a></em></p>\n</blockquote>\n<blockquote>\n<p>...blind visitors are not the only ones inconvenienced by too many links in a navigation area. Recall that a mobility-impaired person with poor adaptive technology might be stuck tabbing through that morass.</p>\n<p><em><a href=\"http://joeclark.org/book/sashay/serialization/Chapter08.html#h4-2020\">Keep them visible!</a></em></p>\n</blockquote>\n<h4>3.5 Does the site use accessible forms?</h4>\n<blockquote>\n<p>Forms aren't the easiest of things to use for people with disabilities. Navigating around a page with written content is one thing, hopping between form fields and inputting information is another</p>\n<p><em><a href=\"http://www.htmldog.com/guides/htmladvanced/forms/\">Accessible forms</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.webstandards.org/learn/tutorials/accessible-forms/01-accessible-forms.html\">Accessible html/xhtml forms</a></li>\n<li><a href=\"http://www.accessify.com/tools-and-wizards/accessible-form-builder.asp\">Accessible form builder</a></li>\n</ul>\n<h4>3.6 Does the site use accessible tables?</h4>\n<blockquote>\n<p>For data tables, identify row and column headers... For data tables that have two or more logical levels of row or column headers, use markup to associate data cells and header cells.</p>\n<p><em><a href=\"http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-table-headers\">Web Content Accessiblity Guidelines -- checkpoint 5.1</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://bellevuecollege.edu/webpublishing/tips/accessibility/tables.asp\">How to create accessible tables</a></li>\n<li><a href=\"http://www.accessify.com/tools-and-wizards/accessibility-tools/table-builder/\">Accessible table builder</a></li>\n<li><a href=\"http://www.webaim.org/techniques/tables/\">Creating accessible tables</a></li>\n</ul>\n<h4>3.7 Is there sufficient colour brightness/contrasts?</h4>\n<blockquote>\n<p>Ensure that foreground and background colour combinations provide sufficient contrast when viewed by someone having colour deficits</p>\n<p><em><a href=\"http://www.w3.org/TR/WAI-WEBCONTENT-TECHS/#tech-color-contrast\">Web Content Accessibilty Guidelines -- checkpoint 2.2</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.juicystudio.com/services/colourcontrast.asp\">Colour Contrast Analyser</a></li>\n</ul>\n<h4>3.8 Is colour alone used for critical information?</h4>\n<blockquote>\n<p>Ensure that all information conveyed with colour is also available without colour, for example from context or markup</p>\n<p><em><a href=\"http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-color-convey\">Web Content Accessibilty Guidelines -- checkpoint 2.1</a></em></p>\n</blockquote>\n<p>There are basically three types of colour deficiency; Deuteranope (a form of red/green colour deficit), Protanope (another form of red/green colour deficit) and Tritanope (a blue/yellow deficit- very rare).</p>\n<p>More:</p>\n<ul>\n<li><a href=\"http://colorfilter.wickline.org/\">Colourblind Webpage filter</a></li>\n<li><a href=\"http://www.vischeck.com/vischeck/vischeckURL.php\">Vischeck</a></li>\n</ul>\n<h4>3.9 Is there delayed responsiveness for dropdown menus?</h4>\n<p>Users with reduced motor skills may find dropdown menus hard to use if responsiveness is set too fast.</p>\n<h4>3.10 Are all links descriptive?</h4>\n<blockquote>\n<p>Link text should be meaningful enough to make sense when read out of context -- either on its own or as part of a sequence of links. Link text should also be terse.</p>\n<p><em><a href=\"http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-meaningful-links\">Web Content Accessibility Guidelines 1.0 -- checkpoint 13.1</a></em></p>\n</blockquote>\n<h3>4. Accessibility for devices</h3>\n<h4>4.1 Does the site work acceptably across modern and older browsers?</h4>\n<blockquote>\n<p>Before starting to build a CSS-based layout, you should decide which browsers to support and to what level you intend to support them.</p>\n</blockquote>\n<h4>4.2 Is the content accessible with CSS switched off or not supported?</h4>\n<p>Some people may visit your site with either a browser that does not support CSS or a browser with CSS switched off. In content is structured well, this will not be an issue.</p>\n<h4>4.3 Is the content accessible with images switched off or not supported?</h4>\n<p>Some people browse websites with images switched off -- especially people on very slow connections. Content should still be accessible for these people.</p>\n<h4>4.4 Does the site work in text browsers such as Lynx?</h4>\n<p>This is like a combination of images and CSS switched off. A text-based browser will rely on well structured content to provide meaning.</p>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.delorie.com/web/lynxview\">Lynx Viewer</a></li>\n</ul>\n<h4>4.5 Does the site work well when printed?</h4>\n<blockquote>\n<p>You can take any (X)HTML document and simply style it for print, without having to touch the markup.</p>\n<p><em><a href=\"http://www.alistapart.com/articles/goingtoprint/\">Going to print</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.d.umn.edu/itss/support/Training/Online/webdesign/css.html#print\">Web Design References -- Print</a></li>\n</ul>\n<h4>4.6 Does the site work well in Hand Held devices?</h4>\n<p>This is a hard one to deal with until hand held devices consistently support their correct media type. However, some layouts work better in current hand-held devices. The importance of supporting hand held devices will depend on target audiences.</p>\n<h4>4.7 Does the site include detailed metadata?</h4>\n<blockquote>\n<p>Metadata is machine understandable information for the web</p>\n<p><em><a href=\"http://www.w3.org/Metadata/\">W3C -- Metadata and Resource Description</a></em></p>\n</blockquote>\n<p>Metadata is structured information that is created specifically to describe another resource. In other words, metadata is 'data about data'.</p>\n<h4>4.8 Does the site work well in a range of browser window sizes?</h4>\n<p>It is a common assumption amongst developers that average screen sizes are increasing. Some developers assume that the average screen size is now 1024px wide. But what about users with smaller screens and users with hand held devices? Are they part of your target audience and are they being disadvantaged?</p>\n<h3>5. Basic Usability</h3>\n<h4>5.1 Is there a clear visual hierarchy?</h4>\n<blockquote>\n<p>Organise and prioritise the contents of a page by using size, prominence and content relationships</p>\n<p><em><a href=\"http://www.great-web-design-tips.com/web-site-design/165.html\">Create a Clear Visual Hierarchy</a></em></p>\n</blockquote>\n<h4>5.2 Are heading levels easy to distinguish?</h4>\n<blockquote>\n<p>Use header elements to convey document structure and use them according to specification</p>\n<p><em><a href=\"http://www.w3.org/TR/WCAG10/wai-pageauth.html#tech-logical-headings\">Web Content Accessibility Guidelines 1.0 -- checkpoint 3.5</a></em></p>\n</blockquote>\n<h4>5.3 Is the site's navigation easy to understand?</h4>\n<blockquote>\n<p>Your navigation system should give your visitor a clue as to what page of the site they are currently on and where they can go next.</p>\n<p><em>[Design Tutorial -- Navigation](<a href=\"http://www.1stsitefree.com/design\">http://www.1stsitefree.com/design</a></em>nav.htm)_</p>\n</blockquote>\n<h4>5.4 Is the site's navigation consistent?</h4>\n<blockquote>\n<p>If each page on your site has a consistent style of presentation, visitors will find it easier to navigate between pages and find information</p>\n<p><em><a href=\"http://www.juicystudio.com/tutorial/accessibility/navigation.asp\">Juicy studios -- Navigation</a></em></p>\n</blockquote>\n<h4>5.5 Does the site use consistent and appropriate language?</h4>\n<blockquote>\n<p>The use of clear and simple language promotes effective communication. Trying to come across as articulate can be as difficult to read as poorly written grammar, especially if the language used isn't the visitor's primary language.</p>\n<p><em><a href=\"http://www.juicystudio.com/tutorial/accessibility/clear.asp\">Clear language</a></em></p>\n</blockquote>\n<h4>5.6 Does the site have a sitemap page and contact page? Are they easy to find?</h4>\n<blockquote>\n<p>Most site maps fail to convey multiple levels of the site's information architecture. In usability tests, users often overlook site maps or can't find them. Complexity is also a problem: a map should be a map, not a navigational challenge of its own.</p>\n<p><em><a href=\"http://www.useit.com/alertbox/20020106.html\">Site Map Usability</a></em></p>\n</blockquote>\n<h4>5.7 For large sites, is there a search tool?</h4>\n<p>While search tools are not needed on smaller sites, and some people will not ever use them, site-specific search tools allow users a choice of navigation options.</p>\n<h4>5.8 Is there a link to the home page on every page in the site?</h4>\n<p>Some users like to go back to a site's home page after navigating to content within a site. The home page becomes a base camp for these users, allowing them to regroup before exploring new content.</p>\n<h4>5.9 Are links underlined?</h4>\n<blockquote>\n<p>To maximise the <a href=\"http://www.jnd.org/dn.mss/affordances-and-design.html\">perceived affordance</a> of clickability, colour and underline the link text. Users shouldn't have to guess or scrub the page to find out where they can click.</p>\n<p><em><a href=\"http://www.useit.com/alertbox/20040510.html\">Guidelines for Visualizing Links</a></em></p>\n</blockquote>\n<h4>5.10 Are visited links clearly defined?</h4>\n<blockquote>\n<p>Most important, knowing which pages they've already visited frees users from unintentionally revisiting the same pages over and over again.</p>\n<p><em><a href=\"http://www.useit.com/alertbox/20040503.html\">Change the Color of Visited Links</a></em></p>\n</blockquote>\n<h3>6. Site management</h3>\n<h4>6.1 Does the site have a meaningful and helpful 404 error page that works from any depth in the site?</h4>\n<blockquote>\n<p>You've requested a page -- either by typing a URL directly into the address bar or clicking on an out-of-date link and you've found yourself in the middle of cyberspace nowhere. A user-friendly website will give you a helping hand while many others will simply do nothing, relying on the browser's built-in ability to explain what the problem is.</p>\n<p><em><a href=\"http://www.alistapart.com/articles/perfect404/\">The perfect 404</a></em></p>\n</blockquote>\n<h4>6.2 Does the site use friendly URLs?</h4>\n<blockquote>\n<p>Most search engines (with a few exceptions -- namely Google) will not index any pages that have a question mark or other character (like an ampersand or equals sign) in the URL... what good is a site if no one can find it?</p>\n<p><em><a href=\"http://www.sitepoint.com/article/search-engine-friendly-urls\">Search Engine-Friendly URLs</a></em></p>\n</blockquote>\n<blockquote>\n<p>One of the worst elements of the web from a user interface standpoint is the URL. However, if they're short, logical, and self-correcting, URLs can be acceptably usable</p>\n<p><em><a href=\"http://www.merges.net/theory/20010305.html\">How to make URLs user-friendly</a></em></p>\n</blockquote>\n<p>More:</p>\n<ul>\n<li><a href=\"http://www.websitegoodies.com/article/32\">Creating Search Engine Friendly URLs</a></li>\n<li><a href=\"http://www.merges.net/theory/20010305.html\">How to make URLs user-friendly</a></li>\n</ul>\n<h4>6.3 Does the site's URL work without \"www\"?</h4>\n<p>While this is not critical, and in some cases is not even possible, it is always good to give people the choice of both options. If a user types your domain name without the www and gets no site, this could disadvantage both the user and you.</p>\n<h4>6.4 Does the site have a favicon?</h4>\n<blockquote>\n<p>A Favicon is a multi-resolution image included on nearly all professionally developed sites. The Favicon allows the webmaster to further promote their site, and to create a more customized appearance within a visitor's browser</p>\n<p><em><a href=\"http://www.favicon.com/\">Favicon.com</a></em></p>\n</blockquote>\n<p>Favicons are definitely not critical. However, if they are not present, they can cause 404 errors in your logs (site statistics). Browsers like IE will request them from the server when a site is bookmarked. If a favicon isn't available, a 404 error may be generated. Therefore, having a favicon could cut down on favicon specific 404 errors. The same is true of a 'robots.txt' file.</p>"},{"url":"/docs/articles/webdev-tools/","relativePath":"docs/articles/webdev-tools.md","relativeDir":"docs/articles","base":"webdev-tools.md","name":"webdev-tools","frontmatter":{"title":"Web Developer Tools","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<ol>\n<li>What Are Web Development Tools?</li>\n</ol>\n<h5><strong>Client-side</strong>Otherwise known as front-end web development, this refers to anything a user can see or engage with—an app or website are good examples. This is about providing a top-notch user experience and smooth interface (usually with a combination of HTML, CSS and various JavaScript libraries.<strong>Server-side</strong>Otherwise known as back-end web development, this refers to the stuff behind the scenes of apps and websites that users can't see. It's the frameworks, servers and databases that keep things running.Image Source: Paperform\n\n</h5>\n<p>When people speak about web development tools (or devtools in the biz), they're usually referring to the apps and software that allows web developers to test and debug the code and interface of a website or web application.</p>\n<p>Technically, the term doesn't refer to tools that *actually help you <em>build a webpage or app</em>. *But that distinction isn't helpful. Web developers require a range of tools that go beyond debugging and testing—whether it be a remote collaboration tool like Slack, a design tool like Figma, or even just an online forum like <a href=\"https://stackoverflow.com/\">StackOverflow</a>.</p>\n<p>For that reason, we've gone beyond the traditional definition of devtools with the aim of giving a realistic view of the kind of apps and software devs use in their day to day workflows. We think you'll find some familiar favourites, as well as some useful tools to add to your tech stack.</p>\n<h2>What To Consider When Choosing Web Development Tools</h2>\n<p>Whether you're <a href=\"https://www.templatemonster.com/bootstrap-website-templates/\">bootstrapping a website</a> from scratch or developing a simple web application, there are few things to keep in mind. Foremost is something that applies to any tool: pick the <em>right option for your specific needs.</em></p>\n<blockquote>\n<p><em>What works for one project might not work for the next. As a web developer, you constantly need to investigate new tools and ways of doing things. Of course, we all have our favourites, but as a general rule, your tech stack should never be stagnant.</em></p>\n</blockquote>\n<p>There's one other general principle to keep in mind. Tech should simplify your workflow—not complicate it. We know how easy it is to get bogged down in the nerdy details, but when in doubt, ask yourself: <em>does this tool actually make my job easier?</em></p>\n<p>Here are a few things to think about beyond these broader considerations:</p>\n<p><strong>Functionality:</strong> Simply, what does each tool help achieve? Does it have a single purpose and can it be replaced by a more feature-rich option?</p>\n<p><strong>Ease of use:</strong> Ensure that the tools that you have control over balance comprehensive features with actually being useable.</p>\n<p><strong>Scalability:</strong> At least some of the tools that you use should be scalable to both small and large projects.</p>\n<p><strong>Portability:</strong> This may not be a gamechanger in the age of remote work, but often web devs travel between clients, the office, home and the local cafe.</p>\n<p><strong>Customisation:</strong> Whether it's a theme on Google Chrome or an add-on for your development environment, we all like to make tools feel unique to us.</p>\n<p><strong>Security:</strong> The security of users, your employer and the sites or apps you are working on always has to be looked after.</p>\n<p><strong>Cost:</strong> If you work for a fancy startup with cash to splash this may not be an issue, but most folks will have to shell out for their own web development tools. Make sure you are getting bang for your buck.</p>\n<h3>A Note On Web Dev Tech Stacks</h3>\n<p>Web development is an all-encompassing term that refers to a bunch of roles. You can split web development into two parts: client-side and server-side.</p>\n<p>Most of the time, web developers specialise in one of the two. However, there are a few show-offs that can do both—they're referred to as full-stack developers.</p>\n<blockquote>\n<p>The term stack is used because the tools that websites and apps use 'stack' on top of each other to build the final product.</p>\n</blockquote>\n<p>Check out this example of Paperform's tech stack for example.</p>\n<h2>The 50 Awesome Modern Web-Dev tools</h2>\n<p>Alright, as we Antipodeans say, no more beating around the bush. Let's get into the list of the best web development tools we recommend using in 2021.</p>\n<h2>Code and Text Editors</h2>\n<p>Web developers wouldn't be able to do their jobs fast and efficiently without text editors. A dev's text editor of choice is kind of a holy thing—once devs find a text editor they love, they tend to stick with it for the long haul.</p>\n<p>Which is why it's such an important decision. It's like a carpenter choosing his hammer, or a Jedi Knight choosing his lightsaber. The good news is you can't go wrong with any listed below:</p>\n<h3>1. Atom</h3>\n<p>The creators of <a href=\"https://atom.io/\">Atom</a> describe it as a \"hackable text editor for the 21st Century\". This is in reference to the insane levels of customisation it offers that allow you to make it uniquely yours.</p>\n<p>Choose from thousands of open-source packages that add new functionality, tweak the look and feel with CSS, or even add your own major features with HTML and JavaScript.</p>\n<p>Using Atom really is a smooth experience. It works with Mac, Windows or Linux and has all the features you would expect. Plus, there is a nice suite of real-time collaboration tools to help you work with a team.</p>\n<h3>2. Sublime Text</h3>\n<p><a href=\"https://www.sublimetext.com/\">Sublime Text</a> is going to be at the top of any list of the best text editors. It doesn't have all the advanced features other solutions do, but what it lacks in power, it more than makes up for with its beautiful appearance and overall ease of use.</p>\n<blockquote>\n<p>With handy keyboard shortcuts, a Command Palette that you won't be able to live without once you use it and a UX to die for, it's an absolute pleasure to use.</p>\n</blockquote>\n<p>The context-aware auto-completion feature is particularly useful. It suggests code based on your text, meaning you can cut down on repetitive typing. Add to that an updated Python API, syntax definitions and hyper-fast load times, Sublime Text is hard to go past.</p>\n<h3>3. Notepad++</h3>\n<p><a href=\"https://notepad-plus-plus.org/\">Notepad++</a> is for those of you who don't care about themes and minimalist design and all that fancy stuff. From an aesthetic viewpoint, it's not going to win any awards, but it's still a powerful open-source text editor that has most of your needs covered.</p>\n<p>Created by a talented software engineer web dev named Don Ho, Notepad++ is a user friendly text editing solution for Windows users. It supports 27 programming languages, synchronised edits and views, and uses Win32 API to produce a tiny program size and faster execution speed.</p>\n<p><strong>💡Pro Tip:</strong> This is also a good option for energy conscious users. By optimising as much as possible, Ho aims to use less CPU power and reduce power consumption, leading to a greener environment.</p>\n<h3>4. Vim</h3>\n<p>If you're after a highly configurable text editor to build your perfect programming environment, then <a href=\"https://www.vim.org/\">Vim</a> is the way to go. While it does work out of the box, for the most part, it's a tool that you have to learn to conquer.</p>\n<p>The cool thing about Vim is that it can be used for any type of text editing—from writing an email to posting blogs in Markup, or of course, editing HTML code. It comes with 200+ syntax files, a comprehensive tag system and integrations with Perl, TCL and Python, and can even act as an OLE automation server in Windows.</p>\n<h3>5. Visual Code Studio</h3>\n<p><a href=\"https://code.visualstudio.com/\">Visual Studio Code</a> (or VS Code) is an open-source code editing program built by Microsoft. It runs everywhere and allows you to do anything from debugging code to inputting Git commands or creating Sass code.</p>\n<p>There is a bevy of appearance options, including the ability to customise fonts, icons, layout and colour scheme. But the remote development features are what set it apart—you can use a container or a remote machine as a full-featured dev environment.</p>\n<p>VS Code is the text editor of choice for Dean McPherson, Paperform's co-founder and resident code-geek. He uses the remote plugins for version control and to keep our global dev team working in the same virtual environment.</p>\n<h2>Web Application Frameworks</h2>\n<p>Web application frameworks (or just web frameworks) are software libraries that are designed to help you build web services, resources and APIs.</p>\n<p>Choosing the right framework for your project is super important. Why? Because it's difficult, time-consuming and expensive to switch to a different solution. It's much easier to stick with one.</p>\n<p>Below we've curated a list of the <a href=\"https://www.appypie.com/top-web-development-frameworks\">best web frameworks</a> in 2021—both front-end and back-end to cover all the bases. This is a big decision and this is only meant as an overview of options, so be sure to do further research before deciding on one.</p>\n<h3>6. Django</h3>\n<p><a href=\"https://www.djangoproject.com/\">Django</a> is a high-level <a href=\"https://www.educba.com/python-frameworks/\">Python framework</a> built by expert developers and used by giant web apps like Reddit, Instagram and Uber. It's secure and scalable, which means it's suitable for a small side hustle or enterprise-scale projects.</p>\n<p>In a nutshell, Django makes it easier to build great web apps. Fast. The focus here is on enabling devs to create sites and apps with less code (to get nerdy, Django's server-side processing speed is super fast and the file structure is feather-light).</p>\n<blockquote>\n<p>Django's goal is to support devs to go from concept to completion as quickly as possible. They achieve this by encouraging clean design and swift development.</p>\n</blockquote>\n<p>One of the greatest strengths of Django is its community. They contribute a tonne of useful packages and utilities—a search on PyPI brings up 4,000+ packages free and ready to use.</p>\n<h3>7. Ruby On Rails</h3>\n<p><a href=\"https://rubyonrails.org/\">Ruby on Rails</a> is a favourite in the dev community. While it requires a certain quality of code, as a general rule it's easy to read, write, monkey patch, test, maintain and deploy, making it any web developer's dream.</p>\n<p>Rails, as it's called in the biz, is used in a bunch of server-side web apps, including big names like Square, Hulu, Twitch and Shopify. It's a popular framework because straight out of the box you get structures for web services, pages and a database, requiring far less groundwork than other options.</p>\n<p>So why choose Rails? Well, it's an excellent choice if you're after a robust tool that's simple to use. It has a clean design language, an intuitive workflow, and seamlessly integrates with third-party applications.</p>\n<p><strong>💡Pro Tip:</strong> If you are starting to build your product, Ruby on Rails is an ideal solution to get your MVP up and running. It allows solo web developers to swiftly get projects off the ground and make changes on the fly.</p>\n<h3>8. Angular</h3>\n<p><a href=\"https://angular.io/\">Angular</a> (or Angularjs) is a popular Javascript framework created and maintained by Google. It's a cross-platform solution with a cohesive ecosystem of third-party components, meaning you can add a bunch of your own unique functionality improvements.</p>\n<p>You'll find all the relevant features you'd expect for each stage of the development process, from code generation and splitting to complex animation timelines.</p>\n<p>The Command-line Interface (CLI) is probably the most notable feature though. it allows you to initialise, develop, scaffold and maintain Angular apps right from the command shell.</p>\n<p><strong>💡Pro Tip:</strong> A JavaScript library is a collection or \"library\" of prewritten code snippets that can be used to repeat common JavaScript functions. It's also important to note, that which JavaScript framework you use often depends on your client's/business' stack.</p>\n<h3>9. React</h3>\n<p>React (<a href=\"https://reactjs.org/\">React.js</a>) is another great Javascript library built by another ultra-powerful tech company: in this case, Facebook. Made specifically for building user interfaces, it makes it painless to create interactive UIs in a visual way.</p>\n<p>A component-based system means that individual components manage their own state, and can then be composed to build complex UIs. React can also render on a server using Node, and with <a href=\"https://facebook.github.io/react-native/\">React Native</a> you can power mobile apps as well.</p>\n<p>React is one of the most popular of the many JavaScript frameworks available. Used by WordPress for their backend and Block Editor, it's a platform to consider for any web developer working with user interfaces.</p>\n<h3>10. Vue</h3>\n<p>Yet another JavaScript library, like React, <a href=\"https://vuejs.org/\">Vue</a> (or Vue.js) is built for working with user interfaces. Labelling itself as a more \"approachable, versatile and performant\" alternative, it helps you create a more maintainable and testable codebase.</p>\n<p>As with other leading frameworks, Vue allows you to take a webpage and split it up into reusable components. Each component then has its own HTML, CSS and JS needed to render that piece of the page—making it faster to make granular changes.</p>\n<p>Vue offers a more \"batteries-included\" approach to web application development. It's simple to use and comes with <a href=\"https://vuejs.org/v2/guide/\">comprehensive documentation</a> and templates to guide you along.</p>\n<h3>11. Meteor</h3>\n<p><a href=\"https://www.meteor.com/\">Meteor.js</a> is a free and open-source full-stack isomorphic framework (meaning you can run it both on the client and server side). It might not be as popular as React or Vue, but it's still considered one of the best solutions to enable devs to swiftly build and deploy web, mobile or desktop apps.</p>\n<p>One of Meteor's biggest selling points is that it seamlessly integrates with the rest of your tech stack—allowing you to focus on building rather than configuring tools to work together. Meteor APM also provides real-time metrics so you can monitor how your app is running.</p>\n<p>Boasting almost 14,000 packages, over half a million unique installs and used by companies like Ikea, Qualcomm and Honeywell, Meteor is a strong option.</p>\n<h3>12. ASP.NET</h3>\n<p>Alright, by now this is a familiar story. Prepare for the buzzwords and giant tech companies. <a href=\"https://dotnet.microsoft.com/apps/aspnet\">ASP.NET</a> is a free, cross-platform framework for <a href=\"https://www.techcronus.com/asp-net-application-development/\">building web apps</a> and services developed by Microsoft.</p>\n<p>What sets it apart from other frameworks is that it uses C# instead of JavaScript. C# supports reference-type (class) and value-type (struct) user-defined types, which can unlock significant performance benefits over JavaScript if you're a more advanced web developer.</p>\n<p>If you're looking to learn NET then there are plenty of resources. Microsoft has plenty of <a href=\"https://dotnet.microsoft.com/learn/aspnet\">learning materials</a> and there's an active <a href=\"https://github.com/dotnet?WT.mc_id=dotnet-35129-website\">community on GitHub</a> with over 100,000 people and 3,700 companies contributing.</p>\n<h2>Front-End Frameworks</h2>\n<p>Front-end frameworks (or \"CSS frameworks\") are packages containing pre-written, standardised code for easy application. It's kind of like a coding dictionary to help you quickly complete actions without having to come up with code yourself.</p>\n<p>Keep in mind that there is some crossover with tools we've previously covered. For example, according to the <a href=\"https://2020.stateofjs.com/en-US/technologies/javascript-flavors/\">State of JavaScript 2020</a>*, in the US, React, Angular and Vue *are the three most popular front-end frameworks.</p>\n<p>Here are some other viable options:</p>\n<h3>13. Bootstrap</h3>\n<p><a href=\"http://getbootstrap.com/\">Bootstrap</a> is a leading open-source CSS framework created by a bunch of the developers behind Twitter (ever heard of it?). Released back in 2011, it's a full-scale tool designed to help you quickly create and customise responsive mobile-first sites.</p>\n<p>It features Sass variables and mixins (so you can assign variables to a name and refer to it rather than the value itself), extensive prebuilt components and comprehensive JavaScript plugins. In a first for front-end frameworks, it also comes with its own SVG icon library designed to work with your Bootstrap sites.</p>\n<h3>14. Semantic UI</h3>\n<p><a href=\"https://semantic-ui.com/\">Semantic UI</a> is a component framework for theming websites using what they call \"human-friendly HTML\" (sorry dogs). What they mean by this is that the tool uses words and classes as exchangeable concepts, giving you the same benefits as BEM without the headache.</p>\n<p>But the real strength here is the breadth of Semantic UI's components. Whether it's elements, collections, views, modules of behaviours, the whole gamut of interface design is covered.</p>\n<h3>15. Foundation</h3>\n<p>The folks at <a href=\"https://foundation.zurb.com/\">Foundation</a> refer to their tool as \"the most advanced responsive front-end framework in the world\", which is certainly setting the bar high. Though it really is suitable for any device, medium and level of accessibility.</p>\n<p>Foundation is packed with features to help build content-focused websites, even providing users with HTML, CSS &#x26; Javascript templates to speed up the process. You can also use Foundation For Emails to craft HTML emails that look a million bucks on any platform.</p>\n<h3><strong>16. Materialize</strong></h3>\n<p><a href=\"https://materializecss.com/\">Materialize</a> is a modern framework based on Google's Material Design language, combining the classic <a href=\"https://paperform.co/blog/principles-of-design/\">principles of design</a> with innovation and tech. As a language its goal is to help unify user experience across any platform, which is fitting, as this is a focus at Materialize as well.</p>\n<p>From the animations to UI elements and everything between, there's a real focus on <a href=\"https://paperform.co/blog/ux-design-portfolio/\">user experience</a> above all else. That's not to say the technical tools aren't there. They are. It's fast, robust and has a low learning curve.</p>\n<h3>17. ChromeDevTools</h3>\n<p><a href=\"https://developer.chrome.com/docs/devtools/\">Chrome DevTools</a> is the name for the web development tools built into the Google Chrome web browser. No need to download any programs or check if it's got MacOS compatibility—just right click in the browser, choose \"Inspect\" and get stuck in.</p>\n<p>It doesn't have as many features as the other options on this list, but it does let you edit pages and diagnose problems with your sites. View and manipulate the DOM, change a page's style sheets (CSS) or use it as a JavaScript debugger.</p>\n<h3>18. Svelte</h3>\n<p>We love <a href=\"https://svelte.dev/\">Svelte</a> for two reasons. One, it just sounds awesome and two, it's all about empowering folks to build their projects with *way less code, *which is something we're passionate about here at Paperform.</p>\n<p>Technically, Svelte isn't a framework or a library. It's a \"compiler\", and it's gained quite a reputation in the web dev community for being one of the best frontend frameworks on the market. It's lightweight, SEO-optimised and unlike tools like React or Vue, doesn't require heavy browser processing.</p>\n<p>Svelte's \"killer app\" is that is has no virtual Dom. This means there's considerably less re-renders of the UI, leading to a lightning fast experience. Some devs will be put off by this, but it makes it an ideal option for beginners or smaller projects.</p>\n<h3>19. Ember</h3>\n<p><a href=\"https://emberjs.com/\">Ember.js</a> is an open-source JavaScript web framework released back in 2011. Since then it's been adopted by a large chunk of the web dev community and it's easy to see why—using it's simple and, whether you're creating feature-rich apps or client-side websites, the user experience is seamless.</p>\n<p>Working with Ember is a \"batteries included\" experience. Out of the box you have all the tools to start building UIs that work on any device. The built-in development environment comes with fast rebuilds, auto-reload and a test runner. Ember Data also lets you set up asynchronous relationships and keep models up to date across your app, which is perfect for remote work.</p>\n<p>Not sold? Some of the biggest and best development teams in the world use Ember to iterate on their products, including Netflix, Intercom and Apple. Convinced?</p>\n<h2>Package Managers</h2>\n<p>If you've ever installed a bunch of programs on your computer you'll know it's a tedious process. You've got to visit each individual website, download the installer, then set each one up individually.</p>\n<p>This is fine if all you're doing is downloading Spotify. But back- and front-end developers work with hundreds of programs. Which is why package managers exist. These tools automate the process of installing, upgrading, configuring and removing programs from a computer's operating system.</p>\n<h3>20. Yarn</h3>\n<p><a href=\"https://yarnpkg.com/lang/en/\">Yarn</a> is a relatively new package manager built by Facebook. It's known for its speed and stability—about the only two things you need from a package manager. But what sets it apart from similar tools is that it doubles as a project management tool.</p>\n<p>Installation is a breeze, and if you get stuck, the documentation is comprehensive. The Workspace feature allows you to split your project into sub-components, which is handy for keeping multiple versions of your project live. There is also a (small) plugin library to extend functionality.</p>\n<h3>21. Node Package Manager (npm)</h3>\n<p><a href=\"https://www.npmjs.com/\">Node Package Manager</a> is a package manager for NodeJS, created in 2009 as an open-source project to give JavaScript devs an easy way to share code modules. The npm Registry consists of more than a million packages—making it the largest software registry in the world.</p>\n<p>With a quick search you'll find everything from front-end web apps to robots and routers. There is hardly a working web developer out there that wouldn't have used npm at some point. And, now that it's moved to GitHub, npm's already vibrant community is only going to grow.</p>\n<h3>22. DPKG - Package Manager for Debian</h3>\n<p>Debian is a stable and secure Linux-based operating system extremely popular with web devs. <a href=\"https://man7.org/linux/man-pages/man1/dpkg.1.html\">Dpkg</a> is a tool built specifically to manage Debian packages. While dpkg does have a more user-friendly front-end alternative called <a href=\"https://wiki.debian.org/Aptitude\">aptitude</a>, dpkg itself runs entirely via the command line.</p>\n<p>In terms of functionality, it's definitely a more low-level solution. But if you're trying to handle the installation and removal of Debian software, it's the place to start. For a more advanced tool try <a href=\"https://wiki.archlinux.org/title/pacman\">Pacman</a> or <a href=\"https://wiki.debian.org/Apt\">APT</a> (literally, Advanced Package Tool). Both fetch packages from remote locations and deal with more complex functions.</p>\n<h2>Git Clients</h2>\n<p>In Britain, 'Git' is slang for someone you think is a bit stupid. But in the world of web development, Git is the name for the software used to track changes in file sets. Most of the time it's used to help devs collaborate during software development.</p>\n<p>A Git *client *is the software you use to work with Git repositories, which can be either remote or locally stored. These allow you to make changes to your Git project (e.g. pushing changes and staging). There are a bunch of different Git clients available across various operating systems.</p>\n<p><strong>💡Pro Tip:</strong> Git is a command line interface and Git clients aren't strictly necessary. It's kind of like using a translator versus learning a language natively. GUIs don't have all the same functionality that a command line client offers, which is why many web devs go that route instead.</p>\n<h3><strong>23. Github Desktop</strong></h3>\n<p>Built by GitHub, the authority when it comes to all things Git, <a href=\"https://desktop.github.com/\">Github Desktop</a> is a tool that allows you to interact with GitHub from your desktop. It's all about giving you a beautiful interface to cut down on distraction and let you focus on what matters.</p>\n<p>Whether you're a seasoned veteran or a Git newbie, GitHub Desktop has you covered. Quickly add commits with collaborators, see all open pull requests from your repositories, and easily see before and after shots of your work in progress with expanded image diff support.</p>\n<p>On top of that there's a heap of automated testing tools to play with. Open-source and available on MacOS and Windows, GitHub is pretty much the default option.</p>\n<h3>24. GitKraken</h3>\n<p><a href=\"https://www.gitkraken.com/\">GitKraken</a> bills itself as the \"easiest, safest and most powerful\" way to use Git. They understand that Git can be difficult to learn, which is why they offer exhaustive docs, as well as integrations with GitHub, GitLab and Azure DevOps to make adding remotes easy.</p>\n<p>The UI is equal parts gorgeous and intuitive. One particularly helpful feature is the ability to map complicated commands to a single button or click of the keyboard. If you're working with a team, the visual commit graph also assists you to quickly view who made code changes and when.</p>\n<p>Other notable features include syntax highlighting, a nifty built-in code editor, interactive rebase and light and dark mode for those late-night coding sessions.</p>\n<h3>25. SourceTree</h3>\n<p><a href=\"https://www.sourcetreeapp.com/\">Sourcetree</a> is a Graphical User Interface (GUI for the cool kids) used to manage Git repository hosts. Built by Atlassian (go Aussies!) it allows you to visualise and manage your repos so you can focus purely on coding.</p>\n<p>Whether you're just starting out as a web developer or are an old pro, Sourcetree has all the tools you need. Leave the command line behind, or delve deeper to review change-sets, stash or cherry-pick between branches—built-in smart branching keeps development clean and efficient.</p>\n<p>Sourcetree is available to download for free on both MacOS and Windows. They've got a huge range of <a href=\"https://support.atlassian.com/bitbucket-cloud/docs/tutorial-learn-bitbucket-with-sourcetree/\">tutorials</a> that'll have you up and running in no time. After some initial hiccups, it's now more powerful and reliable than almost any other Git client.</p>\n<h2>API and Testing Cloud Tools</h2>\n<p>Web APIs are a crucial part of web development these days. APIs allow devs to access specific features or data within an application, service or other system.</p>\n<p>For example, the tech world recently went nuts when Notion announced the beta for their API. By accessing the API devs can now connect other apps with Notion pages and databases.</p>\n<p><strong>📚 Learn more about **[</strong>Paperform's Notion integration<strong>](<a href=\"https://paperform.co/integrations/notion/\">https://paperform.co/integrations/notion/</a>)</strong>.**</p>\n<p>When testing and building with web APIs it's crucial to have reliable tools. Here are some of the best:</p>\n<h3>26. Postman</h3>\n<p><a href=\"https://www.postman.com/\">Postman</a> is an API platform for building using APIs (duh) with features centred around simplifying the process and streamlining team collaboration. <a href=\"https://www.postman.com/api-platform/\">They promise</a> 5x faster development, 4x faster bug fixes and a whopping 10x more effective team collaboration.</p>\n<p>Do they back it up? The *15 million *developers that use Postman would say so. There are integrated tools for every stage of the API lifecycle, from design, mocking, testing and deploying all the way through to maintenance and deprecation.</p>\n<h3>27. REST Assured</h3>\n<p><a href=\"https://rest-assured.io/\">REST Assured</a> is the tool of choice for most web devs working with Java. Made so you don't have to be a HTTP expert to use it, REST Assured enables you to test and validate REST services with the simplicity of more dynamic languages like Ruby.</p>\n<p>It saves you time and effort through automating part of the boilerplate code required to set up HTTP connections, send and receive requests and parse responses. There are also Given/When/Then test notations to help make tests easily comprehensible.</p>\n<h3>28. HoppScotch</h3>\n<p><a href=\"https://hoppscotch.io/\">HoppScotch</a> is a lightweight open source API development tool that runs smoothly and looks beautiful. Over the last few months it's gained popularity with the dev community, largely thanks to its balance of advanced functionality and gorgeous design.</p>\n<p>Whether you need to establish full-duplex communication channels or execute queries with GraphQL, Hoppscotch can handle just about anything you throw at it. You can even add your own translations if English isn't your preferred language.</p>\n<p>Other features include collections to keep API requests organised, the ability to sync and restore request entries with a click, and real-time connections with WebSocket, MQTT and more.</p>\n<h3><strong>29. LambdaTest</strong></h3>\n<p>It's crucial that web applications and services work the same way no matter what browser folks use to access them. But you can't check how your HTML, CSS and JavaScript looks on every web browser and operating system on the planet.</p>\n<p><a href=\"https://www.lambdatest.com/\">LambaTest</a> can. This tool performs automated and live interactive testing on 2,000+ real browsers and operating systems to help ensure your web apps look spiffy wherever they appear.</p>\n<p>It also has the ability to auto-generate full page screenshots across any browser, OS, device or resolution. And with integrated debugging, geolocation testing and seamless collaboration via Asana, Slack and Trello integrations, Lambdatest is a must-have.</p>\n<h2>Web Design and Prototyping Tools</h2>\n<p>It's not enough just to know how to code. Part of being a web designer is understanding what goes into good UI and <a href=\"https://paperform.co/blog/in-conversation-kyro-samaan/\">UX design</a>—from prototyping and wire-framing to creating a visual language for your app. These <a href=\"https://paperform.co/blog/ux-design-tools/\">design tools</a> are vital.</p>\n<h3>30. Figma</h3>\n<p>Only a few years ago, if you wanted a professional design tool you'd need to spend a whole lot of cash and download complex software. Not anymore.</p>\n<p>With <a href=\"https://www.figma.com/ui-design-tool/\">Figma</a>, you get everything you need to design for the web, completely free and accessible from any browser. From UI, UX and <a href=\"https://paperform.co/blog/graphic-design-tools/\">graphic design</a> to wire-framing and diagramming, Figma truly is the all-in-one platform for your design needs.</p>\n<p>It's like LEGO for web devs. Need to mock up a mobile app? Design an entire UI? Build your client's dream website from scratch? Just use the drag-and-drop editor and away you go. With version history you can even collaborate in real-time and not worry about breaking things.</p>\n<p>There's a reason the whole internet is raving about it—Figma's a rare tool that you will find yourself actively looking for reasons to use. It's not hyperbole when we say that it's seriously the only design tool you'll need.</p>\n<h3>31. Adobe XD</h3>\n<p><a href=\"https://www.adobe.com/products/xd.html\">Adobe XD</a> is just the latest in a long range of excellent design tools from Adobe. With XD you can sketch wireframes and mockups, build interactive prototypes and create high-fidelity designs for any screen, thanks to their vector-based system.</p>\n<p>Flat images not enough? 3D transform allows you to turn static objects into dynamic, three dimensional designs in a click. Move or rotate objects, add the appearance of depth, or even build unique immersive AR/VR experiences.</p>\n<p>Above all, Adobe XD succeeds at making your prototypes feel like the real thing—with no coding required. Add user flows, interactions and motion, and save time by using reusable buttons and components.</p>\n<p>Of course, Adobe XD works seamlessly with the rest of the Adobe suite (editing .PSD files from Photoshop is a particularly handy feature). There are a range of co-editing tools to aid real-time collaboration and 200+ plugins to extend functionality.</p>\n<h3>32. Sketch</h3>\n<p><a href=\"https://www.sketch.com/\">Sketch</a> vs Figma is kind of like Apple vs Android: both offer very similar tools, and which one you prefer comes down to preference and your individual workflow.</p>\n<p>Sketch happens to be the app of choice for companies like Google, Facebook and Xbox. It's easy to use, offers a host of useful keyboard shortcuts, and is lightning fast no matter what you throw at it, from <a href=\"https://paperform.co/blog/social-media-design/\">social media designs</a> to working prototypes or fancy new icon sets.</p>\n<p>Having said that, most web developers agree that Figma's prototyping capabilities are superior to Sketch. They also cite the built-in version history, collaboration features and the way Figma handles colour and text styling. The Auto-Layout is also preferred over Sketch's Smart layout.</p>\n<p>But. That's not the whole story. Sketch is regarded as being more stable (Figma can be on the buggy side sometimes), having clearer layer organisation, and being faster to load large files. There's also a dark mode, which we all know, is music to any web developer's ear.</p>\n<p><strong>💡Pro Tip:</strong> The Figma vs Sketch battle isn't going to be decided in this blog post. Luckily, Figma is free to use and Sketch has a generous free trial. If you're unsure which is the right choice for you, just try them both.</p>\n<h3>33. ProtoPie</h3>\n<p><a href=\"https://www.protopie.io/\">ProtoPie</a> bill themselves as the \"easiest way to turn your interaction design ideas into realistic prototypes\". It's a no-code creation tool used to create interactive prototypes for mobile, web, desktop or the 'Internet of Things' (IoT).</p>\n<p>What sets ProtoPie apart is one thing: simplicity. Their goal isn't to be the most complex tool on the market—they want to take the pain out of building workable prototypes, fast. As with any no-code tool, the emphasis is on replacing code with simple buttons and keyboard commands to simplify your workflow.</p>\n<p>There's a gradual learning curve which makes it great for beginners. Prototypes also interact with each other, meaning you can make interactions across devices. It's not as popular as the big players, but it's certainly a powerful tool.</p>\n<h3>34. Framer</h3>\n<p>If you're comfortable with code, then <a href=\"https://framer.com/\">Framer</a> is an awesome tool to empower you to create interactive, highly-customisable prototypes. Web devs around the world use it to build apps, websites, design systems and even slick new video game interfaces.</p>\n<p>What sets it apart from something like Figma? Well, with Framer the idea is that you can work with designs that can *realistically be implemented *with code. It's a bridge for UX designers and developers to collaborate and rapidly experiment in a shared workspace.</p>\n<p>📚 **Related reading: **<a href=\"https://paperform.co/blog/in-conversation-kyro-samaan/\"><strong>How to stand out as a UX Designer</strong></a></p>\n<p>Even if code isn't your thing, Framer is great. The GUI and design elements are on part with Sketch (or at least in the same ballpark) and the built-in prototyping is a breeze to use. There are also plenty of third-party packages to add new elements.</p>\n<h3>35. Toolset</h3>\n<p>Sick of doing everything with code? <a href=\"https://toolset.com/\">Toolset</a> is a WordPress page builder which lets you build custom sites without any code. This is a great option for web developers and designers looking to complete complex projects quickly.</p>\n<p>Use Toolset to design from within WordPress. Create rich sites that look great on any device and load quickly for the SEO gods. It's got everything you could require to set up custom post types, fields, templates, searches, front-end forms and more.</p>\n<p>The biggest benefit of Toolset is that it saves you from having to use a bunch of different tools to build WordPress sites—all for a reasonable price of $69.</p>\n<h3>36. Animator By Haiku</h3>\n<p>Animation is difficult but <a href=\"https://www.haikuforteams.com/animator/\">Animator by Haiku</a> makes it a little bit more palatable. It lets you bring motion design to production, from your initial design tools like Figma to your final codebase.</p>\n<p>Animator uses an interface called Timeline to choreograph animations in a visual way. You can sequence and animate elements using the built-in curves library, or delve deeper with the custom editor. If you're more comfortable with code, use any code editor of your choice to animate directly from your code.</p>\n<h3>37. Affinity Designer</h3>\n<p>Adobe Illustrator has long been the industry standard when it comes to creating vector graphics. However, the new kid on the block, <a href=\"https://affinity.serif.com/en-gb/designer/\">Affinity Designer</a>, is certainly giving Adobe a run for its money.</p>\n<p>You'll find Affinity evangelists all over the net—and for good reason. It offers a silky-smooth experience at a much more affordable price, custom-built with professional illustrators, web designers, game devs and other creatives in mind.</p>\n<p>Affinity offers many of the same tools as Adobe Illustrator in a beautifully designed (and not bloated) package. Work with vectors and rasters to create concept art, print projects, logos, icons, UIs or just about anything else you can imagine.</p>\n<p>The biggest drawcard? There's no monthly fee. You can own Affinity Designer for a one-off payment of $84.99 on Windows or Mac or $34.99 on iPad.</p>\n<h2>Collaboration Tools</h2>\n<p>We've covered just about all the technical tools you could possibly need to be a web developer. But whether you're working in-house, at an agency or going it alone as a freelancer, <a href=\"https://unito.io/features/\">collaboration tools</a> are equally as important as your text editor of choice.</p>\n<p>Often the success of a project isn't simply down to technical brilliance—it relies on clear and efficient communication. The tools below will help you achieve it.</p>\n<h3>38. ClickUp</h3>\n<p>Product management tools should do two things: simplify your processes and help you ship products faster. <a href=\"https://clickup.com/\">ClickUp</a> does both. With an expansive suite of tools, it is truly \"one app to replace them all\", covering tasks, docs, chat, goals and more.</p>\n<p>Whether you're working solo or in a team, ClickUp lets you map out tasks, better plan your work and see your overall product vision. The major benefit here is the dizzying versatility of the platform. From building mind maps to planning tasks on a Kanban board, you can build out your own custom product management setup.</p>\n<h3>39. Asana</h3>\n<p><a href=\"https://asana.com/\">Asana</a> is probably the single most well-known and popular project management and collaboration tool on the market. It's a tool built to stop you shuffling between emails, spreadsheets and other apps to keep organised—from brainstorming to meeting that deadline, you can manage everything with Asana.</p>\n<p>At Paperform we use Asana to assign tasks to team members, create projects split among our Product, Marketing and Content teams, and monitor deadlines to ensure we're hitting our goals. It's simple and visual, and is particularly excellent for keeping remote teams on the same page.</p>\n<h3>40. JIRA</h3>\n<p><a href=\"https://www.atlassian.com/software/jira\">JIRA</a> is the go-to project management platform for software teams to plan, track and release their products. From creating user stories and planning sprints to the final stages of shipping and data analysis, JIRA is *the *way to take any product to launch and beyond.</p>\n<p>One big advantage JIRA has over other similar tools is that it's so customisable. It is possible to build the perfect workflow for your specific product or team—this is also a slight drawback, as it results in a slightly steeper learning curve upfront.</p>\n<p>As you'd expect, it's built with trademark Atlassian polish. And with the Atlassian Marketplace you can connect with over 3,000 first and third-party apps like Slack, Google Drive and GitHub, to extend functionality.</p>\n<h3>41. Slack</h3>\n<p>If you work online in any capacity and haven't heard of <a href=\"https://slack.com/intl/en-au/\">Slack</a>, you must be living under a rock, at the bottom of the ocean, next to a starfish named Patrick. In the last few years, Slack has become synonymous with remote team communication.</p>\n<p>At its core Slack is a team messaging platform. It cuts down on the need for email by separating conversations into distinct Channels, so you can track topics, ideas and projects without long email threads. This makes it the virtual headquarters for your business.</p>\n<p>Of course, there's much more to it than simple text chat. Jump on video calls, add integrations with your favourite tools, and even communicate with external clients or folks in other companies</p>\n<p>Slack isn't just for teams, either. Communities allow you to connect with people in your niche—<a href=\"https://http//www.javaspecialists.eu/slack/\">Java Specialists</a>, <a href=\"https://rubydevs.herokuapp.com/\">Ruby Developers</a> and <a href=\"https://pyslackers.com/web\">Python Developers</a> are just a few of the most active.</p>\n<h3>42. Zoom</h3>\n<p>Occasionally an app or program hits levels of popularity so high that it becomes the noun for what it's used for. This happened to Google long ago (\"I'll Google it\") and it happened to video chat tool <a href=\"https://zoom.us/\">Zoom</a> in the last year and a half (RIP Skype).</p>\n<p>This happened for a reason: Zoom is awesome. While nothing replaces the feeling of face-to-face communication, it's the next best thing. Whether you want to chat to your family across the country or liaise with web design clients, it makes video calls ridiculously easy.</p>\n<p>Zoom is free for 40-minute calls, meaning your meetings come with a convenient end timer. Plus you can record any calls (with your companion's permission), which has become a popular way to record <a href=\"https://paperform.co/blog/how-to-record-a-webinar/\">webinars</a> and podcasts.</p>\n<p>**📚 Related reading: **<a href=\"https://paperform.co/blog/how-to-be-a-good-interviewer/\"><strong>How to be a good interviewer</strong></a></p>\n<h2>Miscellaneous Web Development Tools</h2>\n<h3>43. TypeScript</h3>\n<p>TypeScript is an insanely popular open-source language that builds extra features on top of JavaScript. Essentially, think of regular Java as Clark Kent and TypeScript as Superman—bigger, better, faster and all-round more capable.</p>\n<p>Devs love Typescript because it makes their job easier. It catches both code and type errors, as well as bugs that can easily be missed. This reduces troubleshooting time, while also saving you the effort of having to track down mistakes manually.</p>\n<p>The only real downside is that once you try TypeScript you'll find it hard to return to vanilla Java. The good thing is that you don't need to make a binary choice—all valid JavaScript code is also TypeScript code, and TypeScript can be transformed into Java too.</p>\n<p>If you want clean, simple code with excellent documentation and tools that save you hours of time, TypeScript might be worth a try. Just don't think you can master it in a few minutes, as most devs find there's a steep (albeit worthwhile) learning curve.</p>\n<h3>44. Sass</h3>\n<p>You might've seen the term <a href=\"https://sass-lang.com/guide\">Sass</a> mentioned in web dev circles. But what is it? Well, Sass is a CSS preprocessor that extends what you can do with regular CSS, adding special features like variables, nested rules, inheritance (not the monetary type) and mixins.</p>\n<p>The benefit is that it speeds up your workflow and modularises your code, making edits easier and more efficient to make. It allows you to achieve the same end result as regular CSS, with a fraction of the effort.</p>\n<p>For example, let's say you're working with a theme colour that you keep having to reuse in your CSS code. Rather than having to retype it every time, you can specify the colour once and save the variable. Then, every time you want to use that colour you just refer to the variable instead of hard-coding it.</p>\n<p><strong>💡Pro Tip:</strong> Sass is compatible with any version of CSS, the only requirement being you need Ruby installed for it to work. Just make sure you don't start using Sass before you have CSS mastered—it's important to get a firm grip of the basics first.</p>\n<h3>45. Stack Overflow</h3>\n<p>Okay, so this isn't technically a tool. However, it's not hyperbole on the <a href=\"https://stackoverflow.com/\">Stack Overflow</a> website when it says, \"every developer has a tab open to Stack Overflow\". Ask around—they do. It's the most popular and comprehensive web development community on the internet.</p>\n<p>Stack Overflow is a public platform that aims to build the single most definitive collection of coding questions and answers. Developers, system admins and data scientists of every shape and size rely on it for accurate information to difficult technical challenges.</p>\n<p>We're talking the real nitty gritty. If you want to know why InvokeAsync shows an an error in a Blazor component, how to undo the most recent local commits in Git, or why HTML thinks the tag \"chucknorris\" is a colour, this is the place for you.</p>\n<p>While it's undoubtedly a gold mine of useful resources, it's important to note that the community can be a bit toxic when it comes to welcoming new web developers. Stack Overflow mods are aware of this (and have added new guidelines in response) but do be wary—and look for existing answers before asking a query of your own.</p>\n<p><strong>💡Pro Tip:</strong> More broadly it would be remiss not to mention your other best friend: Google! Not even the most seasoned web developer knows how to fix everything and you can almost guarantee that you'll find someone out there who's had the same problem as you at some point.</p>\n<h3>46. Squoosh Image Optimiser\n</h3>\n<p>Assets. Content. Media. Even the simplest web design project will need basic images and icons. Image optimisation apps allow you to compress image file sizes without affecting quality, which means your sites will stay as fast and responsive as possible.</p>\n<p>Now, there's no shortage of great image optimisation apps but we love <a href=\"https://squoosh.app/\">Squoosh</a>. It's a no-frills experience that does exactly what you need it to. Just drag and drop your image into the editor and Squoosh does its thing.</p>\n<p>You aren't limited to compression either. With the simple interface you can resize, compress or change the image format. The changes are almost instant and the finished product can be downloaded with a click.</p>\n<p>One drawback is that you can only work with one image at a time. So, if you're working on a large project requiring lots of images, <a href=\"https://shortpixel.com/\">ShortPixel</a> may better suit your needs.</p>\n<h3>47. ColorPick Eyedropper Chrome Extension</h3>\n<p>Whether you're designing a website, putting together a UI or creating a <a href=\"https://paperform.co/blog/canva-alternatives/\">Canva design</a>, colour is serious business for web developers and designers. Colours are crucial for brand awareness, evoking certain emotions and, most importantly, accessibility.</p>\n<p>Colour picking tools allow you to identify the Hex codes of elements on the web to gain inspiration or keep designs consistent. There are thousands of tools in this space, but you won't find one easier than <a href=\"https://chrome.google.com/webstore/detail/colorpick-eyedropper/ohcpnigalekghcmgcdcenkpelffpdolg?hl=en\">ColorPick Eyedropper for Chrome</a>.</p>\n<p>Just click the extension and hover over <em>any</em> element on *any *webpage. A small box appears with the Hex code and RGB model. These are automatically copied to the clipboard for you to use. If your only experience working with colours was using crayons in kindergarten, Material.io has a great to the <a href=\"https://material.io/design/color/the-color-system.html#color-usage-and-palettes\">Material Design system</a>.</p>\n<h3>48. Google Lighthouse</h3>\n<p>Technically a part of Chrome Developer Tools, <a href=\"https://developers.google.com/web/tools/lighthouse/\">Google Lighthouse</a> deserves its own dedicated entry. It's an open-source, automated tool for improving the quality of web pages. You can run it on any existing web page to audit overall performance, accessibility, best practices and SEO.</p>\n<p>While you can run it from the command line, or as a Node module, the visual interface within Chrome DevTools is useful for getting actionable insight into what's working (and what is not working) about any given site.</p>\n<p>There are two new features that extend the functionality somewhat too. Stack Packs allow Lighthouse to detect what platform your site is built on and display more specific guidance based on your unique tools.</p>\n<p><strong>💡Pro Tip:</strong> New Lighthouse plugins also allow you to use the data you've collected to create new audits and reports. Used in tandem with PageSpeed Insights, it's a surefire way to make sure your website is in good shape.</p>\n<h3>49. A Second Monitor</h3>\n<p>No guide to web development tools would be complete without recommending you treat yourself to a second monitor. The extra screen real estate makes life <em>so much easier</em> and development <em>so much faster.</em></p>\n<p>Just think of a world where you can have IDE and terminal open on one screen, and the app that you're debugging on the other. Or Slack on the first, your browser and Stack Overflow on the second, maybe Spotify in the corner for some Lo-Fi beats.</p>\n<p>With one screen you're constantly cycling through open applications. Half the time you lose a tab, or forget what you're looking for altogether. This takes time, and as we all know, time is money. Treat yourself to a second monitor—it's a whole new world.</p>\n<h3>50. Paperform</h3>\n<p>For all the advances we've made in the world—sending billionaires to the moon, having the power of a supercomputer in our pockets—it's still weirdly difficult to code beautiful online forms (seriously, PHP is a pain.) That's where <a href=\"https://paperform.co/\">Paperform</a> comes in.</p>\n<p>Paperform empowers you to create beautiful <a href=\"https://paperform.co/blog/best-online-form-builders/\">online forms</a> and landing pages without any code. Just use our free-text editor to build anything from basic <a href=\"https://paperform.co/templates/contact-us-form/\">contact forms</a> to complex <a href=\"https://paperform.co/templates/apparel-order-form/\">eCommerce pages</a> that can be embedded anywhere on the internet.</p>\n<p>Use our theme tools to get started, then add your own unique tweaks with support for custom HTML and CSS. Developing on WordPress? We've even got a plugin that makes <a href=\"https://paperform.co/blog/wordpress-form-builder-plugins/\">embedding forms on WordPress</a> a breeze—and makes life way easier for you and your clients.</p>\n<p>But that's not all you can do. Want to collect feedback from <a href=\"https://paperform.co/blog/customer-satisfaction-survey/\">satisfied customers</a>? Send a <a href=\"https://paperform.co/templates/new-client-onboarding-form/\">client questionnaire</a> for each new project? Or maybe you want to set up a <a href=\"https://paperform.co/blog/one-page-website/\">landing page</a> where you can sell <a href=\"https://paperform.co/blog/online-course-ideas/\">online courses</a>, schedule appointments and <a href=\"https://paperform.co/blog/email-list-sign-ups/\">grow a mailing list</a>?</p>\n<p>With Paperform you can do all that and more. And with our 3,000+ Direct and Zapier integrations, connecting with the rest of your tech stack to streamline your web development workflow is so easy your grandma could do it</p>\n<p><img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/PF-STACK.jpg\" alt=\"image\">\n<img src=\"https://lh4.googleusercontent.com/TGU36vvkMGBvyuV-3moKfrSXGILBOwxz43E7jYdef4p2Vqeb2P90yFchj_RYj3OpvgAZxYQ9MRYpNwuSLFo3NIYD6p96Rb8uw4QXOsribEx_JjDoxTUWE1dSBMTJ17aC4ZH70E25\" alt=\"image\">Image Source: <a href=\"https://atom.io/\">Atom</a>\n<img src=\"https://lh5.googleusercontent.com/me7eP6zI6TqSg-oyEJyqTAoveecqRgW9NNFHRIfuAVvbIJzl9af3yArn0QMuVXH51E-MeZv6BFNk3P1qKl4eJlsaMFWAIT0z2jUWFaVCvD_GDfro_GJbe9srCT299c8Aa2yg2oO9\" alt=\"image\">Image Source: <a href=\"https://www.sublimetext.com/\">Sublime Text</a>\n<img src=\"https://lh6.googleusercontent.com/D44i98NM_KaAxB0vloVdqpkW3QQrOeh-gahRhYT_FT1wGaN9o4BOkV4bDecBTXQRqgSmXNf8emg5FEDMjvievgGr4_UADd6xGReiBqKVEi0FvfauKVDmYOOlEA4XSqmL9ND8EMk9\" alt=\"image\">Image Source: <a href=\"https://notepad-plus-plus.org/\">Notepad++</a>\n<img src=\"https://lh5.googleusercontent.com/D-ZILznlMZ64gUXl3ODwXyyLvJOOV6Tgem2e7Nzt8p02Yz3v4JCA5tmyFKlz7JczYh_CpJcUAN0wHxf_Z5rzVxCX50EHbctJQ2iyaMAhtARmoJqYF3Ikl-G0g_4XILXJaF62b60S\" alt=\"image\">Source: <a href=\"https://commons.wikimedia.org/wiki/File:Vim-(logiciel)-console.png\">Wikipedia Commons</a>\n<img src=\"https://lh6.googleusercontent.com/252gQ1IpAEUNr3lCHi-MvLrULiBMFo56aGsb47nNy6W6ZshOFQgk4FFYaKRn8Fyy4fOBJrcVBIDBEHQU9zg59G8XbmNxkcot4zMf28sJDQWNwxBCjv-UaH8weY6BKQU6ErDlmzu5\" alt=\"image\">Image Source: <a href=\"https://www.google.com/imgres?imgurl=https%3A%2F%2Fcode.visualstudio.com%2Fassets%2Fupdates%2F1_37%2Ficons.gif&#x26;imgrefurl=https%3A%2F%2Fcode.visualstudio.com%2Fupdates%2Fv1_37&#x26;tbnid=FK_-tkfGX0bzmM&#x26;vet=12ahUKEwjznbKQ2YfyAhXUnUsFHULwDJQQMygAegUIARDOAQ..i&#x26;docid=xSPl9orBLj6FKM&#x26;w=1930&#x26;h=1282&#x26;q=vs%20code&#x26;ved=2ahUKEwjznbKQ2YfyAhXUnUsFHULwDJQQMygAegUIARDOAQ\">Visual Studio</a>\n<img src=\"https://lh5.googleusercontent.com/sMHy-q3-qu13ZaFwDwrHy6sKhDnR_K5GdFtsL3J7Wknw9lUFNDOLx8LtRq7owH4GJIQ2bsxePWLN-CrMAdmE0TmsK71mrvaF-7pBlFqwXNMKzNhpdLYre9YmSuqpCP_URy7NxUJx\" alt=\"image\">Image Source: <a href=\"https://www.djangoproject.com/\">Django</a>\n<img src=\"https://lh5.googleusercontent.com/mxpPHMijc7hvVz5LGZYx-QA9knoI7o3F4inDBERqyXqT7sFOqXky2R2WoyponK1WcZXMc6K5-5s3LYc1iedDCjOpu67Go6uEaTUKMc_CHfzMxFOFr_yN1TbnyTcfg7DhiKUirO9S\" alt=\"image\">Image Source: <a href=\"https://rubyonrails.org/\">Ruby on Rails</a>\n<img src=\"https://lh4.googleusercontent.com/Xddm--wmths99nAn-_6kEFm_nwZxr1LHX-e585zbH9DVsCUMeMNYnfp2zSNVk7AZ7FvjZ4FTA_Qt23_cL4_HD6pqq5EqiVTjziFQAHgU9fbnFp0d42au3FA-LqLTRe7vORIbR8oB\" alt=\"image\">Image Source: <a href=\"https://angular.io/\">Angular</a>\n<img src=\"https://lh5.googleusercontent.com/SF8F6NLYMhdsbjPY8lYimBA1R-A39nC2JEmDQIQAxQP0zjcVM5Cn-VBFxlKx2mNCFZY0R6E61BmeKuT6_MN5OZ5EKgIqQ6hRLkFi5pQIy0yeiNmJ_z861aE8txtAnFix2stdDPXf\" alt=\"image\">Image Source: <a href=\"https://reactjs.org/\">React</a>\n<img src=\"https://lh4.googleusercontent.com/pdrGHJeVHJujGzs9PFtJY7E1s0aiDruAGdUquFd0iHKTIXhUaxnECP9GMwYpzmWgsejhmj0TGi6h9ej6FqI-ogSuNcYFDZqiTiGFy13PAFxVXJHKeT2PCD1lIQabE4uaLRFeeCX6\" alt=\"image\">Image Source: <a href=\"https://vuejs.org/\">Vue</a>\n<img src=\"https://lh6.googleusercontent.com/Vwun5FAge-Hh-IB-O2tJ9qMPuoLaSos0GRH1GxS-FD_F_EDuKJZNZk0hlOpB4Xv2gauE1vjC4sY38Ik19s0KtqgeR4IHivFcPCnDFMlAJ8EgfbGdA6fg9K8zOuiFF1GNR4mAwnes\" alt=\"image\">Image Source: <a href=\"https://www.meteor.com/\">Meteor</a>\n<img src=\"https://lh3.googleusercontent.com/Zi7hE50XUZBiBZf9G9Jd8-gdp5GMeQ8ymf5XvkPX0wHKdC60ZlKf_uNeqcDoZo9iOaXFRMsFszhHl3Gy4N1XB7d7U1bfwCtlKXu4TJRYzh_206wQRBSK4eeAs_jatl2qyp4Rjv-m\" alt=\"image\">Image Source: <a href=\"https://dotnet.microsoft.com/apps/aspnet\">ASP.NET</a>\n<img src=\"https://lh6.googleusercontent.com/NXYMRFbspS4M_OKEtx4AywW_r5xJdkgfIvGNYUcQhp5D5ocZYMdWKLzjMFGyVVENpsaK66j77qX8PhKXV2D1xFEPhUClwppQml00ehBAWCkt6Pzimu4EqS8A37QmxzzEKrAGznqD\" alt=\"image\">Image Source: <a href=\"http://getbootstrap.com/\">Bootstrap</a>\n<img src=\"https://lh6.googleusercontent.com/yxo-yyVy5TmurN540Ka207_sQbyGKBqd00nvilE-fqtqYZv33OkE8jWRpBjNWO3tIxKtoi7ujMYfNS6Mbc9MCI3Fw18tjIRLo0kWosD9FRMd7t99nHbKcE_p1ArhMWppx65u0A9U\" alt=\"image\">Image Source: <a href=\"https://semantic-ui.com/\">Semantic UI</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628736193378.png\" alt=\"image\">Image Source: <a href=\"https://foundation.zurb.com/\">Foundation</a>\n<img src=\"https://lh4.googleusercontent.com/_-hHtXVr3_H96K1TcXksh7ZrmhMucG7eIZ97alh5H-2z7ZDiWVnD6XKOAbOE-jOsgxPubVhcHNvfNPfVZq9SVbeB134GJom3h5HWbLikVv5i3SxQObohCtfqPq71JoSG1YfkUNA_\" alt=\"image\">Image Source: <a href=\"https://materializecss.com/\">Materialize</a>\n<img src=\"https://lh5.googleusercontent.com/Xh6Lar3pQSSFHp6yhyU2ZLzuw77eVd-kqYgluxW0qLZ3KpO5_J3OTINaHVta53n5rOrcl3vjwUIupb6YaFcalhXxV0eFSpANCcczX5wjefmRMsHv6YmRzg3Xo3mUvW_WzN-lmX-B\" alt=\"image\">Image Source: <a href=\"https://developer.chrome.com/docs/devtools/\">ChromeDevTools</a>\n<img src=\"https://lh3.googleusercontent.com/pEMKE5gpTl7SHgXBCl1r6gyGDHBeIyuoerr5dsSETZqyavGRu1VOghqgu-ZPodrZJ1QS1pBDwBHHcxDLczWZg6303oektGn-ttIjmnr_2RzXbsKwYwRbJ-nQ7NvvXOvoU7Bs-HgD\" alt=\"image\">Image Source: <a href=\"https://svelte.dev/\">Svelte</a>\n<img src=\"https://lh6.googleusercontent.com/FdOwMdbWSLMXcnJ2gyj2NtGs5l5ShVxOPxRdw1Qj6OEeDiEXw-JPxYoN7Sbi8QLR_EquaOxyT_jey2R6JQXaqhDC_zbpMwy45PoMLjNZrk_QI6IJ3gCjBvCbA_rQl1Dabf0kX2nD\" alt=\"image\">Image Source: <a href=\"https://emberjs.com/\">Ember</a>\n<img src=\"https://lh3.googleusercontent.com/7scAnAsMX-TlzJ6PLimPYY2Tb6aH6p1EtjLbBdz5M8SX3bIk78Q6sr1-mdc9LUgttgj2Ks_EVPP9XD6fb5LyMHK6-A8A1O-dFnVXW52AG5ZGurdFDe3AvIzO0ddGZ5DGWdE1k2mA\" alt=\"image\">Image Source: <a href=\"https://yarnpkg.com/lang/en/\">Yarn</a>\n<img src=\"https://lh5.googleusercontent.com/6kCFq5M0LzWPsqts2sa5HMCU7NVeAG2HfaqQKmbe_sAuwH4fh_reNO1lkqn2Aq_FQO9BMNrXPv-8lTsTBhgaNIVPBy-l-hXqaHURRvhTlXdRChL6f0n2j0J0ZvnvjzUrtzubpK4D\" alt=\"image\">Image Source: <a href=\"https://www.npmjs.com/\">npm</a>\n<img src=\"https://lh6.googleusercontent.com/sihMGTxUb8BieGKwjsMZSHtErIikM2B3ioRYAQ-U8RnRYkN9xdfYjLCA_dTbVuSxFoXFgjZsd7ljFMeBzZOcs5lSih1SJO1SLR5mTtcVGioSvOdjrUJCF20a6so4aNxnbQobt0hv\" alt=\"image\">Image Source: <a href=\"https://man7.org/linux/man-pages/man1/dpkg.1.html\">DPKG</a>\n<img src=\"https://lh3.googleusercontent.com/9huTvL7gtUbXzzwMaYxE8GwC5Nh6RBD1984zLAbB3sx2ES98MqooBO9EN1UyTXr8uyANfcKfdWdGP2hwe3JdmdbjyK-XWkeJxymmpJd7HTKqU3QFPBXm3siMkEC9pB5sIw1RWiCi\" alt=\"image\">Image Source: <a href=\"https://desktop.github.com/\">Github Desktop</a>\n<img src=\"https://lh4.googleusercontent.com/vEhY-y601AhXiD9FedJhwwwkd66UeRQQeyaHw9SL7LsyqUJCm7Vc4n5p0dLgQrCPJWUhiZmbFRugcKOfIlJYT3ah9W0lHjcMd3B4Pdh5kHx4yKdTOrmx709i4SYRuosO3L40_y0Y\" alt=\"image\">Image Source: <a href=\"https://www.gitkraken.com/\">GitKraken</a>\n<img src=\"https://lh6.googleusercontent.com/IhG5Y6dLenofqcIvTY5sOrZoy7rf3f1CagwBeit_m0QZU_QZ5eoMpsWENAU2y4DB93nHq25dgX3WnTVKNNWnnYmoFaEIyT4WYE_JAi5OsjG1przlD9KLSX5-ar1CpXu1_wEhq2SY\" alt=\"image\">Image Source: <a href=\"https://www.sourcetreeapp.com/\">Sourcetree</a>\n<img src=\"https://lh6.googleusercontent.com/1hWg3CPX-XkaeJXPECAninfnozi2o3p3RSk57Y7B8WdvZKsMODbZi3rxR5gyLORQyxbARj2-VoESeqwtWthttAZAItVnheneivMIG0ZTbPludRnzq6rMtzN2eTlEHeODaxrqmRIa\" alt=\"image\">Image Source: <a href=\"https://www.postman.com/\">Postman</a>\n<img src=\"https://lh4.googleusercontent.com/Qg-U_I4ZNgtaun616Nlky0T5ram5v_kZ3h-F33Zmai5t9QoNqutJruPxl2yybA1elIk7J_Qs21_G4wpUR32-TYVP6bx7wCmtOIvIZaTZ3BxI1EqoIVklH-6KRRtnQT8deRXOWSZl\" alt=\"image\">\n<img src=\"https://lh5.googleusercontent.com/XROFNSk7cll32bNRftZzEeL9VDSS3IiLRIgZ4QRhMfadnJ_LLnohR_SMSGQW_CPbiqklUkOutHhK3yRICKp4b9OMb6nLn1M1i76COiDIv_9CTTm0XgxCRt7ZH_VKIgIawnWXskPm\" alt=\"image\">Image Source: <a href=\"https://hoppscotch.io/\">HoppScotch</a>\n<img src=\"https://lh5.googleusercontent.com/cUod2uM6ebt50jQq4JtQ7SPMfAy8Xp8Ad05fe7bSREmHxh-kiJT5el1czMEqBfjEUiPiPTUQCqOZU8Ylw386MW3G0E2jQ35T_FKsksw_cieFbsmY8ubbmMNqwWwTLwXI1z8qtfvo\" alt=\"image\">Image Source: <a href=\"https://www.lambdatest.com/\">LambdaTest</a>\n<img src=\"https://lh5.googleusercontent.com/qlIEiSqu53w7iAu9a6DbOtf6Mhpw1PFBKQHDhr1Fpoyq5Z8md6ctRU-mZcltNt3L6o1NZw29ibT7PvOmGMj4G0t0VbU_2y5Qvs0Nd3dykkA7fyVZkYij-qcHqveR-jMrwemNP4JQ\" alt=\"image\">Image Source: <a href=\"https://www.figma.com/ui-design-tool/\">Figma</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628742272023.png\" alt=\"image\">Image Source: <a href=\"https://www.adobe.com/products/xd.html\">Adobe XD</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628743157849.png\" alt=\"image\">Image Source: <a href=\"https://www.sketch.com/\">Sketch</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628752045112.png\" alt=\"image\">Image Source: <a href=\"https://www.protopie.io/\">ProtoPie</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628749998307.png\" alt=\"image\">Image Source: <a href=\"https://framer.com/\">Framer</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628747997257.png\" alt=\"image\">Image Source: <a href=\"https://toolset.com/\">Toolset</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628748611285.png\" alt=\"image\">Image Source: <a href=\"https://www.haikuforteams.com/animator/\">Animator by Haiku</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628751023068.png\" alt=\"image\">Image Source: <a href=\"https://affinity.serif.com/en-gb/designer/\">Affinity Designer</a>\n<img src=\"https://lh6.googleusercontent.com/zSjT3K_KLXPwq32-5oA8RLQMAXmjNSBfTUXgxxJir7KQ6fOdd1yRYd0jzBxo7O42N3mNv5UQgIzgGmCvFb_Cc18h17DAED2ShKiPvl6qpn2LFWVogn9QcEMIX6DgHCvopX0pFB_1\" alt=\"image\">Image Source: <a href=\"https://clickup.com/\">ClickUp</a>\n<img src=\"https://lh6.googleusercontent.com/8gm_048J2wEJ_WD_9vXB7esjB0bzTnj7hNPyhIewLbQSyEeqtuRhsYzUz7jE_n0E3GylWvamewgWYkbWSawAkAo3t5ZD-bM10TT-ZkSRSrEc3Fmib7Y7L_XTWe-OGOfdIT5zAOn1\" alt=\"image\">Image Source: <a href=\"https://asana.com/\">Asana</a>\n<img src=\"https://lh4.googleusercontent.com/DOfqKLR_ON8XzgdLDjTuVMSa_bTKVSm9tZ3lbx3CW03AX8Q3Y9qYbP17d1EhH4F7KGNFbYRciB-NUFM775UhBHWkJbfPuhahhroh9P4EDUf714Zc-zBrXtKK644je6G8n589jewp\" alt=\"image\">Image Source: <a href=\"https://www.atlassian.com/software/jira\">JIRA</a>\n<img src=\"https://lh4.googleusercontent.com/ES8WaJ_R9ZY9kYtfAlc-Wt28uUDmTMoRvA1zQLp2ijGfTvhVEuBYFYAS7FHSspYMokpuIv9VLqwhtxYxlnrImdxTLwFqnS_k6AqvXhPWSwqpNGc5lpfcHcbglV-I3Imcz1yOI2c_\" alt=\"image\">Image Source: <a href=\"https://slack.com/intl/en-au/\">Slack</a>\n<img src=\"https://lh3.googleusercontent.com/9MTbGgNToiS4BrnLGuDkrIykZFtGbDE9g6khzKy7w52VnFQqnXwi2mlYjRFA9EI_49dmEyD53M3WFOxuR49RcAu_yQi3qxGI3NGs79qVKM4HJyDsQF6-5YH-hUDHrqvxnG_b_EUI\" alt=\"image\">Image Source: <a href=\"https://zoom.us/\">Zoom</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628831608408.png\" alt=\"image\">Image Source: <a href=\"https://www.typescriptlang.org/\">TypeScript</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628828564183-1.png\" alt=\"image\">Image Source: <a href=\"https://sass-lang.com/guide\">Sass</a>\n<img src=\"https://lh6.googleusercontent.com/GVUZo-jhQxvyTfdhcC0SIpT7yTjtXiVUFDzhtxc-NuVtF5AXqQcgpCSEIZyWdLZs7rPtUYvu-lIHvY-eKymaFAT5sprEffolutJJ1gGAWJB9s37ZmGUlH6UIqleVpfciapcMvAR7\" alt=\"image\">Image Source: <a href=\"https://stackoverflow.com/\">Stack Overflow</a>\n<img src=\"https://lh4.googleusercontent.com/VkP8y5mQdyGHN36GWELx53tup1fhCQiOPMmce1-wCGTBF18UTLrXnEa2KmDy6Op9QfwU00frx_xQBnRLIYJx7TERs0SwTNeufbMnM3RTIRS2ZDcrynUlQSEaEzoPTO7jD94kvtzr\" alt=\"image\">Image Source: <a href=\"https://squoosh.app/\">Squoosh</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/screely-1628823617932.png\" alt=\"image\">Image Source: Paperform\n<img src=\"https://lh6.googleusercontent.com/ALDwwi8tDvEmnWjsFJlyzFwWQ4p4V4uuS7egg1DNcbRWG0B02BeYbXO2o7aiRIHuSzTdStodCMJh7dSyT-L6XoyGhQArSNJam0_6HqDiEEkx4H7YkJ5fvOHy0sU3dUEE9UzqdPEa\" alt=\"image\">Image Source: <a href=\"https://developers.google.com/web/tools/lighthouse/\">Google Lighthouse</a>\n<img src=\"https://img.paperform.co/fetch/f_webp,w_1500/https://s3.amazonaws.com/paperform-blog/2021/08/Facebook-post---5--2-.png\" alt=\"image\">Image Source: Stack Overflow\n<img src=\"https://lh3.googleusercontent.com/-B-6-8bBUycMywsPV65wJs1vKrkW3QCCo_Bd4eXovfkHh3uMkLyGdvBTYNDOj05o97iTVm7M4B9rLjINH8PZ9NLsIzJ7peSOcf3T2yJ9_8Efz5Rn5jMUv4xLpetCt3zF1PDs8iiU\" alt=\"image\"></p>"},{"url":"/docs/audio/discrete-fft/","relativePath":"docs/audio/discrete-fft.md","relativeDir":"docs/audio","base":"discrete-fft.md","name":"discrete-fft","frontmatter":{"title":"Fast Fourier Transform","weight":0,"excerpt":"Visualizing the Discrete Fourier Transform","seo":{"title":"Fast Fourier Transform","description":"Visualizing the Discrete Fourier Transform","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Visualizing the Discrete Fourier Transform</h2>\n<p>A couple of years ago I suggested a way of thinking about <a href=\"https://blog.revolutionanalytics.com/2014/01/the-fourier-transform-explained-in-one-sentence.html\">how the Discrete Fourier Transform works</a>, based on Stuart Riffle's elegant colour-coding of the equation:</p>\n<p><a href=\"http://revolution-computing.typepad.com/.a/6a010534b1db25970b019b0172129c970c-pi\"><img src=\"https://revolution-computing.typepad.com/.a/6a010534b1db25970b019b0172129c970c-800wi\" alt=\"The fourier transform, explained in one color-coded sentence\" title=\"The fourier transform, explained in one color-coded sentence\"></a></p>\n<p>(Sadly, Stuart's <a href=\"http://www.altdevblogaday.com/2011/05/17/understanding-the-fourier-transform/\">original post</a> describing the equation has been lost to bitrot, and can't even be found in the Wayback Machine.) My contribution was the following analogy:</p>\n<blockquote>\n<p>Imagine an enormous speaker, mounted on a pole, playing a repeating sound. The speaker is so large, you can see the cone move back and forth with the sound. Mark a point on the cone, and now rotate the pole. Trace the point from an above-ground view, if the resulting squiggly curve is off-center, then there is frequency corresponding the pole's rotational frequency represented in the sound.</p>\n</blockquote>\n<p>Dr Bill Connelly from Australia National University has created an interactive simulation of the analogy. Here, the sound from the speaker is a chord of two tones: just enter their frequency and amplitude, and see how the DFT is calculated from the analysis of the rotation:</p>\n<p><a href=\"http://www.billconnelly.net/?p=276\"><img src=\"https://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb08743789970d-800wi\" alt=\"DFT\" title=\"DFT\"></a></p>"},{"url":"/docs/audio/dfft/","relativePath":"docs/audio/dfft.md","relativeDir":"docs/audio","base":"dfft.md","name":"dfft","frontmatter":{"title":"Discrete Fast Fourier Transform","weight":0,"excerpt":"Fast Fourier Transform","seo":{"title":"fft","description":"The discrete Fourier transform operates on sampled data,\nin contrast to the standard Fourier transform which is\ndefined for continuous functions.","robots":[],"extra":[{"name":"og:description","value":"The discrete Fourier transform operates on sampled data,\nin contrast to the standard Fourier transform which is\ndefined for continuous functions.","keyName":"property","relativeUrl":false},{"name":"og:image","value":"images/fft.jpg","keyName":"property","relativeUrl":true},{"name":"og:title","value":"Fast Fourier Transform","keyName":"property","relativeUrl":false}],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Frequency and the fast Fourier transform</h1>\n<blockquote>\n<p>If you want to find the secrets of the universe, think in terms of energy,\nfrequency and vibration.</p>\n<p>— Nikola Tesla</p>\n</blockquote>\n<p><em>This chapter was written in collaboration with SW's father, PW van der Walt.</em></p>\n<h2>Introducing frequency</h2>\n<p>We'll start by setting up some plotting styles and importing the usual\nsuspects:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Make plots appear inline, set custom plotting style</span>\n<span class=\"token operator\">%</span>matplotlib inline\n<span class=\"token keyword\">import</span> matplotlib<span class=\"token punctuation\">.</span>pyplot <span class=\"token keyword\">as</span> plt\nplt<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>use<span class=\"token punctuation\">(</span><span class=\"token string\">'style/elegant.mplstyle'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> numpy <span class=\"token keyword\">as</span> np</code></pre></div>\n<p>The discrete<sup id=\"fnref-discrete\"><a href=\"#fn-discrete\" class=\"footnote-ref\">discrete</a></sup> Fourier transform (DFT) is a mathematical technique\nto convert temporal or spatial data into <em>frequency domain</em> data.\n<em>Frequency</em> is a familiar concept, due to its colloquial occurrence in\nthe English language: the lowest notes your headphones can rumble out\nare around 20 Hertz, whereas middle C on a piano lies around 261.6\nHertz. Hertz (Hz), or oscillations per second, in this case literally\nrefers to the number of times per second at which the membrane inside\nthe headphone moves to-and-fro. That, in turn, creates compressed\npulses of air which, upon arrival at your eardrum, induces a vibration\nat the same frequency. So, if you take a simple periodic function, $\\sin(10 \\times 2 \\pi t)$, you can view it as a wave:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">f <span class=\"token operator\">=</span> <span class=\"token number\">10</span>  <span class=\"token comment\"># Frequency, in cycles per second, or Hertz</span>\nf_s <span class=\"token operator\">=</span> <span class=\"token number\">100</span>  <span class=\"token comment\"># Sampling rate, or number of measurements per second</span>\n\nt <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>linspace<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> f_s<span class=\"token punctuation\">,</span> endpoint<span class=\"token operator\">=</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span>\nx <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>sin<span class=\"token punctuation\">(</span>f <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> np<span class=\"token punctuation\">.</span>pi <span class=\"token operator\">*</span> t<span class=\"token punctuation\">)</span>\n\nfig<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Time [s]'</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Signal amplitude'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"A simple periodic function in time\" -->\n<p>Or you can equivalently think of it as a repeating signal of\n<em>frequency</em> 10 Hertz (it repeats once every $1/10$ seconds—a length of\ntime we call its <em>period</em>). Although we naturally associate frequency\nwith time, it can equally well be applied to space. E.g., a\nphoto of a textile patterns exhibits high <em>spatial frequency</em>, whereas\nthe sky or other smooth objects have low spatial frequency.</p>\n<p>Let us now examine our sinusoid through application of the discrete Fourier\ntransform:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> scipy <span class=\"token keyword\">import</span> fftpack\n\nX <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span>\nfreqs <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>fftfreq<span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> f_s\n\nfig<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\nax<span class=\"token punctuation\">.</span>stem<span class=\"token punctuation\">(</span>freqs<span class=\"token punctuation\">,</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>X<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Frequency in Hertz [Hz]'</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Frequency Domain (Spectrum) Magnitude'</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_xlim<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span>f_s <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> f_s <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">110</span><span class=\"token punctuation\">)</span></code></pre></div>\n<!-- caption text=\"Frequencies that make up our periodic signal above\" -->\n<p>We see that the output of the FFT is a one-dimensional array of the\nsame shape as the input, containing complex values. All values are\nzero, except for two entries. Traditionally, we visualize the\nmagnitude of the result as a <em>stem plot</em>, in which the height of each\nstem corresponds to the underlying value.</p>\n<p>(We explain why you see positive and negative frequencies later on\nin the sidebox titled \"Discrete Fourier transforms\". You may also\nrefer to that section for a more in-depth overview of the underlying\nmathematics.)</p>\n<p>The Fourier transform takes us from the <em>time</em> to the <em>frequency</em>\ndomain, and this turns out to have a massive number of applications.\nThe <em>fast Fourier transform</em> is an algorithm for computing the\ndiscrete Fourier transform; it achieves its high speed by storing and\nre-using results of computations as it progresses.</p>\n<p>In this chapter, we examine a few applications of the discrete Fourier\ntransform to demonstrate that the FFT can be applied to\nmultidimensional data (not just 1D measurements) to achieve a variety\nof goals.</p>\n<h2>Illustration: a birdsong spectrogram</h2>\n<p>Let's start with one of the most common applications, converting a sound signal (consisting of variations of air pressure over time) to a <em>spectrogram</em>.\nYou might have seen spectrograms on your music player's equalizer view, or even on an old-school stereo.</p>\n<p><img src=\"../images/sergey_gerasimuk_numark-eq-2600-IMG_0236.jpg\" alt=\"The Numark EQ2600 Stereo Equalizer; image used with permission from the author, Sergey Gerasimuk. Source: http://sgerasimuk.blogspot.com/2014/06/numark-eq-2600-10-band-stereo-graphic.html\"></p>\n<p>Listen to the following snippet of nightingale birdsong (released under CC BY 4.0 at\n<a href=\"http://www.orangefreesounds.com/nightingale-sound/\">http://www.orangefreesounds.com/nightingale-sound/</a>):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> IPython<span class=\"token punctuation\">.</span>display <span class=\"token keyword\">import</span> Audio\nAudio<span class=\"token punctuation\">(</span><span class=\"token string\">'data/nightingale.wav'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>If you are reading the paper version of this book, you'll have to use\nyour imagination! It goes something like this:\nchee-chee-woorrrr-hee-hee cheet-wheet-hoorrr-chi\nrrr-whi-wheo-wheo-wheo-wheo-wheo-wheo.</p>\n<p>Since we realise that not everyone is fluent in bird-speak, perhaps\nit's best if we visualize the measurements—better known as \"the\nsignal\"—instead.</p>\n<p>We load the audio file, which gives us\nthe sampling rate (number of measurements per second) as well as audio\ndata as an <code class=\"language-text\">(N, 2)</code> array—two columns because this is a stereo\nrecording.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> scipy<span class=\"token punctuation\">.</span>io <span class=\"token keyword\">import</span> wavfile\n\nrate<span class=\"token punctuation\">,</span> audio <span class=\"token operator\">=</span> wavfile<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token string\">'data/nightingale.wav'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>We convert to mono by averaging the left and right channels.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">audio <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>mean<span class=\"token punctuation\">(</span>audio<span class=\"token punctuation\">,</span> axis<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Then, calculate the length of the snippet and plot the audio.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">N <span class=\"token operator\">=</span> audio<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\nL <span class=\"token operator\">=</span> N <span class=\"token operator\">/</span> rate\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f'Audio length: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>L<span class=\"token punctuation\">:</span><span class=\"token format-spec\">.2f</span><span class=\"token punctuation\">}</span></span><span class=\"token string\"> seconds'</span></span><span class=\"token punctuation\">)</span>\n\nf<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span>arange<span class=\"token punctuation\">(</span>N<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> rate<span class=\"token punctuation\">,</span> audio<span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Time [s]'</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Amplitude [unknown]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Audio waveform plot of birdsong\" -->\n<p>Well, that's not very satisfying, is it? If I sent this voltage to a\nspeaker, I might hear a bird chirping, but I can't very well imagine\nhow it would sound like in my head. Is there a better way of <em>seeing</em>\nwhat is going on?</p>\n<p>There is, and it is called the discrete Fourier transform, where\ndiscrete refers to the recording consisting of time-spaced sound\nmeasurements, in contrast to a continual recording as, e.g., on\nmagnetic tape (remember casettes?). The discrete Fourier\ntransform is often computed using the <em>fast Fourier transform</em> (FFT)\nalgorithm, a name informally used to refer to the DFT itself. The\nDFT tells us which frequencies or \"notes\" to expect in our signal.</p>\n<p>Of course, a bird sings many notes throughout the song, so we'd also\nlike to know <em>when</em> each note occurs. The Fourier transform takes a\nsignal in the time domain (i.e., a set of measurements over time) and\nturns it into a spectrum—a set of frequencies with corresponding\n(complex<sup id=\"fnref-complex\"><a href=\"#fn-complex\" class=\"footnote-ref\">complex</a></sup>) values. The spectrum does not contain any information about\ntime! <sup id=\"fnref-time\"><a href=\"#fn-time\" class=\"footnote-ref\">time</a></sup></p>\n<p>So, to find both the frequencies and the time at which they were sung,\nwe'll need to be somewhat clever. Our strategy is as follows:\ntake the audio signal, split it into small, overlapping slices, and\napply the Fourier transform to each (a technique known as the Short\nTime Fourier Transform).</p>\n<p>We'll split the signal into slices of 1024 samples—that's about 0.02\nseconds of audio. Why we choose 1024 and not 1000 we'll explain in a\nsecond when we examine performance. The slices will overlap by 100\nsamples as shown here:</p>\n<p><img src=\"../figures/generated/sliding_window.png\" alt=\"A sliding window operation\"></p>\n<p>Start by chopping up the signal into slices of 1024 samples, each\nslice overlapping the previous by 100 samples. The resulting <code class=\"language-text\">slices</code>\nobject contains one slice per row.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> skimage <span class=\"token keyword\">import</span> util\n\nM <span class=\"token operator\">=</span> <span class=\"token number\">1024</span>\n\nslices <span class=\"token operator\">=</span> util<span class=\"token punctuation\">.</span>view_as_windows<span class=\"token punctuation\">(</span>audio<span class=\"token punctuation\">,</span> window_shape<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span>M<span class=\"token punctuation\">,</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> step<span class=\"token operator\">=</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f'Audio shape: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>audio<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">}</span></span><span class=\"token string\">, Sliced audio shape: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>slices<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">}</span></span><span class=\"token string\">'</span></span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Generate a windowing function (see the section on windowing for a\ndiscussion of the underlying assumptions and interpretations of each)\nand multiply it with the signal:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">win <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>hanning<span class=\"token punctuation\">(</span>M <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nslices <span class=\"token operator\">=</span> slices <span class=\"token operator\">*</span> win</code></pre></div>\n<p>It's more convenient to have one slice per column, so we take the transpose:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">slices <span class=\"token operator\">=</span> slices<span class=\"token punctuation\">.</span>T\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Shape of `slices`:'</span><span class=\"token punctuation\">,</span> slices<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">)</span></code></pre></div>\n<p>For each slice, calculate the discrete Fourier transform. The DFT\nreturns both positive and negative frequencies (more on that in\n\"Frequencies and their ordering\"), so we slice out the positive M / 2\nfrequencies for now.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spectrum <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>slices<span class=\"token punctuation\">,</span> axis<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>M <span class=\"token operator\">//</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nspectrum <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>spectrum<span class=\"token punctuation\">)</span></code></pre></div>\n<p>(As a quick aside, you'll note that we use <code class=\"language-text\">scipy.fftpack.fft</code> and\n<code class=\"language-text\">np.fft</code> interchangeably. NumPy provides basic FFT functionality,\nwhich SciPy extends further, but both include an <code class=\"language-text\">fft</code> function, based\non the Fortran FFTPACK.)</p>\n<p>The spectrum can contain both very large and very small values.\nTaking the log compresses the range significantly.</p>\n<p>Here we do a log plot of the ratio of the signal divided by the maximum signal.\nThe specific unit used for the ratio is the decibel, $20\nlog_{10}\\left(\\mathrm{amplitude ratio}\\right)$.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">f<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span>figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nS <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>spectrum<span class=\"token punctuation\">)</span>\nS <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token operator\">*</span> np<span class=\"token punctuation\">.</span>log10<span class=\"token punctuation\">(</span>S <span class=\"token operator\">/</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span>S<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nax<span class=\"token punctuation\">.</span>imshow<span class=\"token punctuation\">(</span>S<span class=\"token punctuation\">,</span> origin<span class=\"token operator\">=</span><span class=\"token string\">'lower'</span><span class=\"token punctuation\">,</span> cmap<span class=\"token operator\">=</span><span class=\"token string\">'viridis'</span><span class=\"token punctuation\">,</span>\n          extent<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> L<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> rate <span class=\"token operator\">/</span> <span class=\"token number\">2</span> <span class=\"token operator\">/</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>axis<span class=\"token punctuation\">(</span><span class=\"token string\">'tight'</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Frequency [kHz]'</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Time [s]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Birdsong spectrogram\" -->\n<p>Much better! We can now see the frequencies vary over time, and it\ncorresponds to the way the audio sounds. See if you can match my\nearlier description: chee-chee-woorrrr-hee-hee cheet-wheet-hoorrr-chi\nrrr-whi-wheo-wheo-wheo-wheo-wheo-wheo (I didn't transcribe the section\nfrom 3 to 5 seconds—that's another bird).</p>\n<p>SciPy already includes an implementation of this\nprocedure as <code class=\"language-text\">scipy.signal.spectrogram</code>, which can be invoked as\nfollows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> scipy <span class=\"token keyword\">import</span> signal\n\nfreqs<span class=\"token punctuation\">,</span> times<span class=\"token punctuation\">,</span> Sx <span class=\"token operator\">=</span> signal<span class=\"token punctuation\">.</span>spectrogram<span class=\"token punctuation\">(</span>audio<span class=\"token punctuation\">,</span> fs<span class=\"token operator\">=</span>rate<span class=\"token punctuation\">,</span> window<span class=\"token operator\">=</span><span class=\"token string\">'hanning'</span><span class=\"token punctuation\">,</span>\n                                      nperseg<span class=\"token operator\">=</span><span class=\"token number\">1024</span><span class=\"token punctuation\">,</span> noverlap<span class=\"token operator\">=</span>M <span class=\"token operator\">-</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span>\n                                      detrend<span class=\"token operator\">=</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> scaling<span class=\"token operator\">=</span><span class=\"token string\">'spectrum'</span><span class=\"token punctuation\">)</span>\n\nf<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span>figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>pcolormesh<span class=\"token punctuation\">(</span>times<span class=\"token punctuation\">,</span> freqs <span class=\"token operator\">/</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span> <span class=\"token operator\">*</span> np<span class=\"token punctuation\">.</span>log10<span class=\"token punctuation\">(</span>Sx<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> cmap<span class=\"token operator\">=</span><span class=\"token string\">'viridis'</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Frequency [kHz]'</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Time [s]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"SciPy built-in rendition of birdsong spectrogram\" -->\n<p>The only differences are that SciPy returns the spectrum magnitude\nsquared (which turns measured voltage into measured energy), and\nmultiplies it by some normalization factors<sup id=\"fnref-scaling\"><a href=\"#fn-scaling\" class=\"footnote-ref\">scaling</a></sup>.</p>\n<h2>History</h2>\n<p>Tracing the exact origins of the Fourier transform is tricky. Some\nrelated procedures go as far back as Babylonian times, but it was the\nhot topics of calculating asteroid orbits and solving the heat (flow)\nequation that led to several breakthroughs in the early 1800s. Whom\nexactly among Clairaut, Lagrange, Euler, Gauss and D'Alembert we\nshould thank is not exactly clear, but Gauss was the first to describe\nthe fast Fourier transform (an algorithm for computing the discrete\nFourier transform, popularized by Cooley and Tukey in 1965). Joseph\nFourier, after whom the transform is named, first claimed that\n<em>arbitrary</em> periodic <sup id=\"fnref-periodic\"><a href=\"#fn-periodic\" class=\"footnote-ref\">periodic</a></sup> functions can be expressed as a sum of\ntrigonometric functions.</p>\n<h2>Implementation</h2>\n<p>The discrete Fourier transform functionality in SciPy lives in the\n`scipy.fftpack<code class=\"language-text\"></code> module. Among other things, it provides the\nfollowing DFT-related functionality:</p>\n<ul>\n<li><code class=\"language-text\">fft</code>, <code class=\"language-text\">fft2</code>, <code class=\"language-text\">fftn</code>: Compute the discrete Fourier transform using</li>\n<li>the Fast Fourier Transform algorithm in 1, 2, or <code class=\"language-text\">n</code> dim</li>\n<li><code class=\"language-text\">ifft</code>, <code class=\"language-text\">ifft2</code>, <code class=\"language-text\">ifftn</code>: Compute the inverse of the DFT</li>\n<li><code class=\"language-text\">dct</code>, <code class=\"language-text\">idct</code>, <code class=\"language-text\">dst</code>, <code class=\"language-text\">idst</code>: Compute the cosine and sine transforms, and their inverses.</li>\n<li><code class=\"language-text\">fftshift</code>, <code class=\"language-text\">ifftshift</code>: Shift the zero-frequency component to the c</li>\n<li><code class=\"language-text\">fftfreq</code>: Return the discrete Fourier transform sample frequencies.</li>\n<li><code class=\"language-text\">rfft</code>: Compute the DFT of a real sequence, exploiting the symmetry of the resulting spectrum for increased performance. Also used by <code class=\"language-text\">fft</code> internally when applicable.</li>\n</ul>\n<p>This is complemented by the following functions in NumPy:</p>\n<ul>\n<li><code class=\"language-text\">np.hanning</code>, <code class=\"language-text\">np.hamming</code>, <code class=\"language-text\">np.bartlett</code>, <code class=\"language-text\">np.blackman</code>,\n<code class=\"language-text\">np.kaiser</code>: Tapered windowing functions.</li>\n</ul>\n<p>It is also used to perform fast convolutions of large inputs by\n<code class=\"language-text\">scipy.signal.fftconvolve</code>.</p>\n<p>SciPy wraps the Fortran FFTPACK library—it is not the fastest out\nthere, but unlike packages such as FFTW, it has a permissive free\nsoftware license.</p>\n<h2>Choosing the length of the discrete Fourier transform (DFT)</h2>\n<p>A naive calculation of the DFT takes $\\mathcal{O}\\left(N^2\\right)$ operations <sup id=\"fnref-big_o\"><a href=\"#fn-big_o\" class=\"footnote-ref\">big_o</a></sup>.\nHow come? Well, you have $N$\n(complex) sinusoids of different frequencies ($2 \\pi f \\times 0, 2 \\pi f \\times\n1, 2 \\pi f \\times 3, ..., 2 \\pi f \\times (N - 1)$), and you want to see how\nstrongly your signal corresponds to each. Starting with the first,\nyou take the dot product with the signal (which, in itself, entails $N$\nmultiplication operations). Repeating this operation $N$ times, once\nfor each sinusoid, then gives $N^2$ operations.</p>\n<p>Now, contrast that with the fast Fourier transform, which is $\\mathcal{O}\\left(N \\log N\\right)$ in\nthe ideal case due to the clever re-use of\ncalculations—a great improvement! However, the classical Cooley-Tukey\nalgorithm implemented in FFTPACK (and used by SciPy) recursively breaks up the transform\ninto smaller (prime-sized) pieces and only shows this improvement for\n\"smooth\" input lengths (an input length is considered smooth when its\nlargest prime factor is small). For large prime-sized pieces, the\nBluestein or Rader algorithms can be used in conjunction with the\nCooley-Tukey algorithm, but this optimization is not implemented in\nFFTPACK.<sup id=\"fnref-fast\"><a href=\"#fn-fast\" class=\"footnote-ref\">fast</a></sup></p>\n<p>Let us illustrate:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> time\n\n<span class=\"token keyword\">from</span> scipy <span class=\"token keyword\">import</span> fftpack\n<span class=\"token keyword\">from</span> sympy <span class=\"token keyword\">import</span> factorint\n\nK <span class=\"token operator\">=</span> <span class=\"token number\">1000</span>\nlengths <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">250</span><span class=\"token punctuation\">,</span> <span class=\"token number\">260</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Calculate the smoothness for all input lengths</span>\nsmoothness <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span>factorint<span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> lengths<span class=\"token punctuation\">]</span>\n\nexec_times <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> lengths<span class=\"token punctuation\">:</span>\n    z <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>random<span class=\"token punctuation\">.</span>random<span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n\n    <span class=\"token comment\"># For each input length i, execute the FFT K times</span>\n    <span class=\"token comment\"># and store the execution time</span>\n\n    times <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n    <span class=\"token keyword\">for</span> k <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>K<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        tic <span class=\"token operator\">=</span> time<span class=\"token punctuation\">.</span>monotonic<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n        fftpack<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>z<span class=\"token punctuation\">)</span>\n        toc <span class=\"token operator\">=</span> time<span class=\"token punctuation\">.</span>monotonic<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n        times<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>toc <span class=\"token operator\">-</span> tic<span class=\"token punctuation\">)</span>\n\n    <span class=\"token comment\"># For each input length, remember the *minimum* execution time</span>\n    exec_times<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span>times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nf<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>ax0<span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> sharex<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\nax0<span class=\"token punctuation\">.</span>stem<span class=\"token punctuation\">(</span>lengths<span class=\"token punctuation\">,</span> np<span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">(</span>exec_times<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span><span class=\"token operator\">**</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\nax0<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Execution time (µs)'</span><span class=\"token punctuation\">)</span>\n\nax1<span class=\"token punctuation\">.</span>stem<span class=\"token punctuation\">(</span>lengths<span class=\"token punctuation\">,</span> smoothness<span class=\"token punctuation\">)</span>\nax1<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Smoothness of input length\\n(lower is better)'</span><span class=\"token punctuation\">)</span>\nax1<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Length of input'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"FFT execution time vs smoothness for different input lengths\" -->\n<p>The intuition is that, for smooth input lengths, the FFT can be broken up\ninto many small pieces. After performing the FFT on the first piece,\nthose results can be reused in subsequent computations. This explains\nwhy we chose a length of 1024 for our audio slices earlier—it has a\nsmoothness of only 2, resulting in the optimal \"radix-2 Cooley-Tukey\"\nalgorithm, which computes the FFT using only $(N/2) \\log_2 N = 5120$ complex\nmultiplications, instead of $N^2 = 1048576$. Choosing $N = 2^m$\nalways ensures a maximally smooth $N$ (and, thus, the fastest FFT).</p>\n<h2>More discrete Fourier transform concepts</h2>\n<p>Next, we present a couple of common concepts worth knowing before\noperating heavy Fourier transform machinery, whereafter we tackle\nanother real-world problem: analyzing target detection in radar data.</p>\n<h3>Frequencies and their ordering</h3>\n<p>For historical reasons, most implementations return an array where\nfrequencies vary from low-to-high-to-low (see the box \"Discrete\nFourier transforms\" for further explanation of frequencies). E.g., when we do the real\nFourier transform of a signal of all ones, an input that has no\nvariation and therefore only has the slowest, constant Fourier\ncomponent (also known as the \"DC\" or Direct Current component—just\nelectronics jargon for \"mean of the signal\"), we see this DC component\nappearing as the first entry:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> scipy <span class=\"token keyword\">import</span> fftpack\nN <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n\nfftpack<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span>ones<span class=\"token punctuation\">(</span>N<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># The first component is np.mean(x) * N</span></code></pre></div>\n<p>When we try the FFT on a rapidly changing signal, we see a high\nfrequency component appear:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">z <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>ones<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\nz<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f'Applying FFT to </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>z<span class=\"token punctuation\">}</span></span><span class=\"token string\">'</span></span><span class=\"token punctuation\">)</span>\nfftpack<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>z<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Note that the FFT returns a complex spectrum which, in the case of\nreal inputs, is conjugate symmetrical (i.e., symmetric in the real\npart, and anti-symmetric in the imaginary part):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">12</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\nX <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">with</span> np<span class=\"token punctuation\">.</span>printoptions<span class=\"token punctuation\">(</span>precision<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Real part:     \"</span><span class=\"token punctuation\">,</span> X<span class=\"token punctuation\">.</span>real<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Imaginary part:\"</span><span class=\"token punctuation\">,</span> X<span class=\"token punctuation\">.</span>imag<span class=\"token punctuation\">)</span></code></pre></div>\n<p>(And, again, recall that the first component is <code class=\"language-text\">np.mean(x) * N</code>.)</p>\n<p>The <code class=\"language-text\">fftfreq</code> function tells us which frequencies we are looking at\nspecifically:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">fftpack<span class=\"token punctuation\">.</span>fftfreq<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The result tells us that our maximum component occured at a frequency\nof 0.5 cycles per sample. This agrees with the input, where a\nminus-one-plus-one cycle repeated every second sample.</p>\n<p>Sometimes, it is convenient to view the spectrum organized slightly\ndifferently, from high-negative to low to-high-positive (for now, we\nwon't dive too deeply into the concept of negative frequency, other\nthan saying a real-world sine wave is produced by a combination of\npositive and negative frequencies). We re-shuffle the spectrum using\nthe <code class=\"language-text\">fftshift</code> function.</p>\n<blockquote>\n<p><strong>Discrete Fourier transforms {.callout}</strong></p>\n<p>The Discrete Fourier Transform (DFT) converts a sequence of $N$\nequally spaced real or complex samples $x<em>{0},x</em>{1},\\ldots, x<em>{N-1}$ of\na function $x(t)$ of time (or another variable, depending on the\napplication) into a sequence of $N$ complex numbers $X</em>{k}$ by the\nsummation</p>\n<p>$$\nX<em>{k}=\\sum</em>{n=0}^{N-1}x_{n}e^{-j2\\pi kn/N},;k=0,1,\\ldots,\nN-1.\n$$</p>\n<p>With the numbers $X<em>{k}$ known, the inverse DFT _exactly</em> recovers the\nsample values $x_{n}$ through the summation</p>\n<p>$$x<em>{n}=\\frac{1}{N}\\sum</em>{k=0}^{N-1}X_{k}e^{j2\\pi kn/N}.$$</p>\n<p>Keeping in mind that $e^{j\\theta}=\\cos\\theta+j\\sin\\theta,$ the last\nequation shows that the DFT has decomposed the sequence $x<em>{n}$ into a\ncomplex discrete Fourier series with coefficients $X</em>{k}$. Comparing\nthe DFT with a continuous complex Fourier series</p>\n<p>$$x(t)=\\sum<em>{n=-\\infty}^{\\infty}c</em>{n}e^{jn\\omega_{0}t},$$</p>\n<p>the DFT is a <em>finite</em> series with $N$ terms defined at the equally\nspaced discrete instances of the <em>angle</em> $(\\omega<em>{0}t</em>{n})=2\\pi\\frac{k}{N}$\nin the interval $[0,2\\pi)$,\ni.e. <em>including</em> $0$ and <em>excluding</em> $2\\pi$.\nThis automatically normalizes the DFT so that time does\nnot appear explicitly in the forward or inverse transform.</p>\n<p>If the original function $x(t)$ is limited in frequency to less than\nhalf of the sampling frequency (the so-called <em>Nyquist frequency</em>),\ninterpolation between sample values produced by the inverse DFT will\nusually give a faithful reconstruction of $x(t)$. If $x(t)$ is <em>not</em>\nlimited as such, the inverse DFT can, in general, not be used to\nreconstruct $x(t)$ by interpolation. Note that this limit does not\nimply that there are <em>no</em> methods that can do such a\nreconstruction—see, e.g., compressed sensing, or finite rate of\ninnovation sampling.</p>\n<p>The function $e^{j2\\pi k/N}=\\left(e^{j2\\pi/N}\\right)^{k}=w^{k}$ takes on\ndiscrete values between $0$ and $2\\pi\\frac{N-1}{N}$ on the unit circle in\nthe complex plane. The function $e^{j2\\pi kn/N}=w^{kn}$ encircles the\norigin $n\\frac{N-1}{N}$ times, thus generating harmonics of the fundamental\nsinusoid for which $n=1$.</p>\n<p>The way in which we defined the DFT leads to a few subtleties\nwhen $n>\\frac{N}{2}$, for even $N$ <sup id=\"fnref-odd_n\"><a href=\"#fn-odd_n\" class=\"footnote-ref\">odd_n</a></sup>. The function $e^{j2\\pi kn/N}$ is plotted\nfor increasing values of $k$ in the figure below,\nfor the cases $n=1$ to $n=N-1$ for $N=16$. When $k$ increases from $k$\nto $k+1$, the angle increases by $\\frac{2\\pi n}{N}$. When $n=1$,\nthe step is $\\frac{2\\pi}{N}$. When $n=N-1$, the angle\nincreases by $2\\pi\\frac{N-1}{N}=2\\pi-\\frac{2\\pi}{N}$. Since $2\\pi$\nis precisely once around the circle, the step equates to $-\\frac{2\\pi}{N}$,\ni.e. in the direction of a negative\nfrequency. The components up to $N/2$ represent <em>positive</em> frequency\ncomponents, those above $N/2$ up to $N-1$ represent <em>negative</em>\nfrequencies. The angle increment for the component $N/2$\nfor $N$ even advances precisely halfway around the circle for\neach increment in $k$ and can therefore be interpreted as either a\npositive or a negative frequency. This component of the DFT represents\nthe Nyquist Frequency, i.e. half of the sampling frequency, and is\nuseful to orientate oneself when looking at DFT graphics.</p>\n<p>The FFT in turn is simply a special and highly efficient algorithm for\ncalculating the DFT. Whereas a straightforward calculation of the DFT\ntakes of the order of $N^{2}$ calculations to compute, the FFT\nalgorithm requires of the order $N\\log N$ calculations. The FFT was\nthe key to the wide-spread use of the DFT in real-time applications\nand was included in a list of the top $10$ algorithms of the $20^{th}$\ncentury by the IEEE journal Computing in Science &#x26; Engineering in the\nyear $2000$.</p>\n<p><img src=\"../figures/unit_circle_samples.png\" alt=\"Unit circle samples\"></p>\n</blockquote>\n<p>Let's examine the frequency components in a noisy image. Note that,\nwhile a static image has no time-varying component, its values do vary\nacross <em>space</em>. The DFT applies equally to either case.</p>\n<p>First, load and display the image:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> skimage <span class=\"token keyword\">import</span> io\nimage <span class=\"token operator\">=</span> io<span class=\"token punctuation\">.</span>imread<span class=\"token punctuation\">(</span><span class=\"token string\">'images/moonlanding.png'</span><span class=\"token punctuation\">)</span>\nM<span class=\"token punctuation\">,</span> N <span class=\"token operator\">=</span> image<span class=\"token punctuation\">.</span>shape\n\nf<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span>figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4.8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>imshow<span class=\"token punctuation\">(</span>image<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>M<span class=\"token punctuation\">,</span> N<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> image<span class=\"token punctuation\">.</span>dtype<span class=\"token punctuation\">)</span></code></pre></div>\n<!-- caption text=\"A noisy image of the moon landing\" -->\n<p>Do not adjust your monitor! The image you are seeing is real,\nalthough clearly distorted by either the measurement or transmission\nequipment.</p>\n<p>To examine the spectrum of the image, we use <code class=\"language-text\">fftn</code> (instead of <code class=\"language-text\">fft</code>)\nto compute the DFT, since it has more than one dimension. The\ntwo-dimensional FFT is equivalent to taking the 1-D FFT across rows\nand then across columns (or vice versa).</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">F <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>fftn<span class=\"token punctuation\">(</span>image<span class=\"token punctuation\">)</span>\n\nF_magnitude <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>F<span class=\"token punctuation\">)</span>\nF_magnitude <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>fftshift<span class=\"token punctuation\">(</span>F_magnitude<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Again, we take the log of the spectrum to compress the range of\nvalues, before displaying:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">f<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span>figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4.8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nax<span class=\"token punctuation\">.</span>imshow<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">+</span> F_magnitude<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> cmap<span class=\"token operator\">=</span><span class=\"token string\">'viridis'</span><span class=\"token punctuation\">,</span>\n          extent<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span>M <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> M <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax<span class=\"token punctuation\">.</span>set_title<span class=\"token punctuation\">(</span><span class=\"token string\">'Spectrum magnitude'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Spectrum of the noisy moon landing image (magnitude)\" -->\n<p>Note the high values around the origin (middle) of the spectrum—these\ncoefficients describe the low frequencies or smooth parts of the\nimage; a vague canvas of the photo. Higher frequency components,\nspread throughout the spectrum, fill in the edges and detail. Peaks\naround higher frequencies correspond to the periodic noise.</p>\n<p>From the photo, we can see that the noise (measurement artifacts) is\nhighly periodic, so we hope to remove it by zeroing out the\ncorresponding parts of the spectrum.</p>\n<p>The image with those peaks suppressed indeed looks quite different!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Set block around center of spectrum to zero</span>\nK <span class=\"token operator\">=</span> <span class=\"token number\">40</span>\nF_magnitude<span class=\"token punctuation\">[</span>M <span class=\"token operator\">//</span> <span class=\"token number\">2</span> <span class=\"token operator\">-</span> K<span class=\"token punctuation\">:</span> M <span class=\"token operator\">//</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> K<span class=\"token punctuation\">,</span> N <span class=\"token operator\">//</span> <span class=\"token number\">2</span> <span class=\"token operator\">-</span> K<span class=\"token punctuation\">:</span> N <span class=\"token operator\">//</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> K<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n<span class=\"token comment\"># Find all peaks higher than the 98th percentile</span>\npeaks <span class=\"token operator\">=</span> F_magnitude <span class=\"token operator\">&lt;</span> np<span class=\"token punctuation\">.</span>percentile<span class=\"token punctuation\">(</span>F_magnitude<span class=\"token punctuation\">,</span> <span class=\"token number\">98</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Shift the peaks back to align with the original spectrum</span>\npeaks <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>ifftshift<span class=\"token punctuation\">(</span>peaks<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Make a copy of the original (complex) spectrum</span>\nF_dim <span class=\"token operator\">=</span> F<span class=\"token punctuation\">.</span>copy<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Set those peak coefficients to zero</span>\nF_dim <span class=\"token operator\">=</span> F_dim <span class=\"token operator\">*</span> peaks<span class=\"token punctuation\">.</span>astype<span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Do the inverse Fourier transform to get back to an image</span>\n<span class=\"token comment\"># Since we started with a real image, we only look at the real part of</span>\n<span class=\"token comment\"># the output.</span>\nimage_filtered <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>real<span class=\"token punctuation\">(</span>fftpack<span class=\"token punctuation\">.</span>ifft2<span class=\"token punctuation\">(</span>F_dim<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nf<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>ax0<span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax0<span class=\"token punctuation\">.</span>imshow<span class=\"token punctuation\">(</span>fftpack<span class=\"token punctuation\">.</span>fftshift<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span>log10<span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">+</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>F_dim<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> cmap<span class=\"token operator\">=</span><span class=\"token string\">'viridis'</span><span class=\"token punctuation\">)</span>\nax0<span class=\"token punctuation\">.</span>set_title<span class=\"token punctuation\">(</span><span class=\"token string\">'Spectrum after suppression'</span><span class=\"token punctuation\">)</span>\n\nax1<span class=\"token punctuation\">.</span>imshow<span class=\"token punctuation\">(</span>image_filtered<span class=\"token punctuation\">)</span>\nax1<span class=\"token punctuation\">.</span>set_title<span class=\"token punctuation\">(</span><span class=\"token string\">'Reconstructed image'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Filtered moon landing image and its spectrum\" -->\n<h3>Windowing</h3>\n<p>If we examine the Fourier transform of a rectangular pulse, we see\nsignificant sidelobes in the spectrum:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>zeros<span class=\"token punctuation\">(</span><span class=\"token number\">500</span><span class=\"token punctuation\">)</span>\nx<span class=\"token punctuation\">[</span><span class=\"token number\">100</span><span class=\"token punctuation\">:</span><span class=\"token number\">150</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n\nX <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span>\n\nf<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>ax0<span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> sharex<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n\nax0<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span>\nax0<span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">0.1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.1</span><span class=\"token punctuation\">)</span>\n\nax1<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>fftpack<span class=\"token punctuation\">.</span>fftshift<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>X<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax1<span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">55</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Spectrum of a rectangular pulse (magnitude)\" -->\n<p>In theory, you would need a combination of infinitely many sinusoids\n(frequencies) to represent any abrupt transition; the coefficients would\ntypically have the same sidelobe structure as seen here for the pulse.</p>\n<p>Importantly, the discrete Fourier transform assumes that the input\nsignal is periodic. If the signal is not, the assumption is simply\nthat, right at the end of the signal, it jumps back to its beginning\nvalue. Consider the function, $x(t)$, shown here:</p>\n<img src=\"../figures/periodic.png\"/>\n<!-- caption text=\"Eight samples have been taken of a given\n function with effective length $T_{eff}$.  With the discrete Fourier\n transform assuming periodicity, it creates a step discontinuity\n between the first and last samples.\" -->\n<p>We only measure the signal for a short time, labeled $T_{eff}$. The\nFourier transform assumes that $x(8) = x(0)$, and that the signal is\ncontinued as the dashed, rather than the solid line. This introduces\na big jump at the edge, with the expected oscillation in the spectrum:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">t <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>linspace<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">500</span><span class=\"token punctuation\">)</span>\nx <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>sin<span class=\"token punctuation\">(</span><span class=\"token number\">49</span> <span class=\"token operator\">*</span> np<span class=\"token punctuation\">.</span>pi <span class=\"token operator\">*</span> t<span class=\"token punctuation\">)</span>\n\nX <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span>\n\nf<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>ax0<span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n\nax0<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span>\nax0<span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">1.1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.1</span><span class=\"token punctuation\">)</span>\n\nax1<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>fftpack<span class=\"token punctuation\">.</span>fftfreq<span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>X<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax1<span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">190</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Spectrum oscillation due to signal edge discontinuity\" -->\n<p>Instead of the expected two lines, the peaks are spread out in the\nspectrum.</p>\n<p>We can counter this effect by a process called <em>windowing</em>. The\noriginal function is multiplied with a window function such as the\nKaiser window $K(N,\\beta)$. Here we visualize it for $\\beta$ ranging\nfrom 0 to 100:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">f<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\nN <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\nbeta_max <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\ncolormap <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>cm<span class=\"token punctuation\">.</span>plasma\n\nnorm <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>Normalize<span class=\"token punctuation\">(</span>vmin<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> vmax<span class=\"token operator\">=</span>beta_max<span class=\"token punctuation\">)</span>\n\nlines <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    ax<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span>kaiser<span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">,</span> beta<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> color<span class=\"token operator\">=</span>colormap<span class=\"token punctuation\">(</span>norm<span class=\"token punctuation\">(</span>beta<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">for</span> beta <span class=\"token keyword\">in</span> np<span class=\"token punctuation\">.</span>linspace<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> beta_max<span class=\"token punctuation\">,</span> N<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">]</span>\n\nsm <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>cm<span class=\"token punctuation\">.</span>ScalarMappable<span class=\"token punctuation\">(</span>cmap<span class=\"token operator\">=</span>colormap<span class=\"token punctuation\">,</span> norm<span class=\"token operator\">=</span>norm<span class=\"token punctuation\">)</span>\n\nsm<span class=\"token punctuation\">.</span>_A <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n\nplt<span class=\"token punctuation\">.</span>colorbar<span class=\"token punctuation\">(</span>sm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>set_label<span class=\"token punctuation\">(</span><span class=\"token string\">r'Kaiser $\\beta$'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"The Kaiser window for various values of $\\beta$\" -->\n<p>By changing the parameter $\\beta$, the shape of the window can be\nchanged from rectangular ($\\beta=0$, no windowing) to a window that\nproduces signals that smoothly increase from zero and decrease to zero\nat the endpoints of the sampled interval, producing very low side\nlobes ($\\beta$ typically between 5 and 10) <sup id=\"fnref-choosing_a_window\"><a href=\"#fn-choosing_a_window\" class=\"footnote-ref\">choosing_a_window</a></sup>.</p>\n<!--\n*For online notebook, use something like:*\n\n#```\n# @interact(beta=(0, 20.))\n# def window(beta):\n#    x = np.kaiser(1000, beta)\n#    f, axes = plt.subplots(1, 2, figsize=(4.8, 2.4))\n#    axes[0].plot(x)\n#    axes[1].plot(fftpack.fftshift(np.abs(np.fft.fft(x, 10000))))\n#    axes[1].set_xlim(2*2480, 2*2520)\n#    plt.show()\n#```\n-->\n<p>The effect of windowing our previous example is noticeable:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">win <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>kaiser<span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\nx_win <span class=\"token operator\">=</span> x <span class=\"token operator\">*</span> win\n\nX_win <span class=\"token operator\">=</span> fftpack<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>x_win<span class=\"token punctuation\">)</span>\n\nf<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>ax0<span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n\nax0<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>x_win<span class=\"token punctuation\">)</span>\nax0<span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">1.1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.1</span><span class=\"token punctuation\">)</span>\n\nax1<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>fftpack<span class=\"token punctuation\">.</span>fftfreq<span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>X_win<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nax1<span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">190</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Spectrum of a windowed signal (magnitude)\" -->\n<h2>Real-world Application: Analyzing Radar Data</h2>\n<p>Linearly modulated FMCW (Frequency-Modulated Continuous-Wave) radars\nmake extensive use of the FFT algorithm for signal processing and\nprovide examples of various applications of the FFT. We will use actual\ndata from an FMCW radar to demonstrate one such an application: target\ndetection.</p>\n<p>Roughly, an FMCW radar works like this (see box \"A\nsimple FMCW radar system\" for more detail):</p>\n<p>A signal with changing frequency is generated. This signal is\ntransmitted by an antenna, after which it travels outwards, away from the\nradar. When it hits an object, part of the signal is reflected back\nto the radar, where it is received, multiplied by a copy of the\ntransmitted signal, and sampled, turning it into\nnumbers that are packed into an array. Our challenge is to interpret\nthose numbers to form meaningful results.</p>\n<p>The multiplication step above is important. From school, recall the\ntrigonometric identity:</p>\n<p>$\n\\sin(xt) \\sin(yt) = \\frac{1}{2}\n\\left[ \\sin \\left( (x - y)t + \\frac{\\pi}{2} \\right) - \\sin \\left( (x + y)t + \\frac{\\pi}{2} \\right) \\right]\n$</p>\n<p>Thus, if we multiply the received signal by the transmitted signal, we\nexpect two frequency components to appear in the spectrum: one that is\nthe difference in frequencies between the received and transmitted\nsignal, and one that is the sum of their frequencies.</p>\n<p>We are particularly interested in the first, since that gives us some\nindication of how long it took the signal to reflect back to the radar\n(in other words, how far away the object is from us!). We discard the\nother by applying a low-pass filter to the signal (i.e., a filter that\ndiscards any high frequencies).</p>\n<blockquote>\n<p><strong>A simple FMCW radar system</strong> {.callout}</p>\n<p><img src=\"../figures/FMCW_Block.png\" alt=\"The block diagram of a simple FMCW radar system\"></p>\n<p>A block diagram of a simple FMCW radar that uses separate\ntransmit and receive antennas is shown above. The radar consists of a waveform generator\nthat generates a sinusoidal signal of which the frequency varies\nlinearly around the required transmit frequency. The generated signal\nis amplified to the required power level by the transmit amplifier\nand routed to the transmit antenna via a coupler circuit where a copy\nof the transmit signal is tapped off. The transmit antenna radiates\nthe transmit signal as an electromagnetic wave in a narrow beam\ntowards the target to be detected. When the wave encounters an object\nthat reflects electromagnetic waves, a fraction of of the energy\nirradiating the target is reflected back to the receiver as a second\nelectromagnetic wave that propagates in the direction of the radar\nsystem. When this wave encounters the receive antenna, the antenna\ncollects the energy in the wave energy impinging on it and converts\nit to a fluctuating voltage that is fed to the mixer. The mixer\nmultiplies the received signal with a replica of the transmit signal\nand produces a sinusoidal signal with a frequency equal to the\ndifference in frequency between the transmitted and received\nsignals. The low-pass filter ensures that the received signal is band\nlimited (i.e., does not contain frequencies that we don't care about)\nand the receive amplifier strengthens the signal to a suitable\namplitude for the analog to digital converter (ADC) that feeds data\nto the computer.</p>\n</blockquote>\n<p>To summarize, we should note that:</p>\n<ul>\n<li>The data that reaches the computer consists of $N$ samples sampled\n(from the multiplied, filtered signal) at a sample frequency of\n$f_{s}$.</li>\n<li>The <strong>amplitude</strong> of the returned signal varies depending on the\n<strong>strength of the reflection</strong> (i.e., is a property of the target\nobject and the distance between the target and the radar).</li>\n<li>The <strong>frequency measured</strong> is an indication of the <strong>distance</strong> of the\ntarget object from the radar.</li>\n</ul>\n<!--\n\n### Signal properties in the time domain\n\nThe transmit signal is a sinusoidal signal with an instantaneous\nfrequency that increases linearly with time, as shown in\nFig. [fig:FMCW waveform](a).\n\nStarting at $f_{min}$, the frequency increases at a rate $S$ Hz/s to $f_{max}.$\nThe frequency is then decreased rapidly back to $f_{min}$\nafter which a next frequency sweep occurs.\n\nThis signal is radiated by a directional transmit antenna. When the\nwave with propagation velocity $v\\approx300\\times10^{6}$ m/s (the\npropagation speed of electromagnetic waves in air is ever-so-slightly\nslower than the speed of light in a vacuum) hits a target at a range $R$,\nthe echo will reach the radar after a time\n\n$$t_{d}=\\frac{2R}{v}.$$\n\nHere it is collected by the receive antenna and converted to a\nsinusoidally fluctuating voltage. The received signal is a replica of\nthe transmitted signal, delayed by the transit time $t_{d}$ and is\nshown dashed in Fig. [fig:FMCW waveform](b).\n\nA radar is designed to detect targets up to a maximum range $R_{max}$.\nEchoes from maximum range reach the radar after a transit\ntime $t_{dm}$ as shown in Fig. [fig:FMCW waveform](c).\n\nWe note that there is a constant difference in frequency between the\ntransmitted and received signals and this will be true for all targets\nafter time $t_{s}$ until $t_{e}$. We conclude from\nFig. [fig:FMCW waveform] that the frequency difference is given by\n\n$$f_{d}=S\\times t_{d}=\\frac{2SR}{v},$$\n\nwhere $T_{eff}=t_{e}-t_{s}=\\frac{N}{f_{s}}$ is the effective sweep duration\nof the radar. The frequency excursion of the sweep during $T_{eff}$ is\nthe effective bandwidth of the radar, given by\n\n$$B_{eff}=f_{max}-f_{1}=ST_{eff}.$$\n\nWe will see that the range resolution of the radar is determined by\nthe effective bandwidth.\n\nReturning to Fig. [fig: block-diagram], the signal produced by the\nreceiver at the input to the Analog to Digital Converter (ADC) when\nthere is a single target is a sinusoid with constant amplitude,\nproportional to the amplitude of the echo, and constant frequency,\nproportional to the range to the target.\n\n-->\n<p><img src=\"../figures/FMCW_waveform.png\" alt=\"The frequency relationships in an FMCW radar with\n linear frequency modulation\"></p>\n<p>To start off, we'll generate some synthetic signals, after which we'll\nturn our focus to the output of an actual radar.</p>\n<p>Recall that the radar is increasing its frequency as it transmits at a\nrate of $S$ Hz/s. After a certain amount of time, $t$, has passed,\nthe frequency will now be $t S$ higher. In that same time span, the\nradar signal has traveled $d = t / v$ meters, where $v$ is the speed of\nthe transmitted wave through air (roughly the same as the speed of\nlight, $3 \\times 10^8$ m/s).</p>\n<p>Combining the above observations, we can calculate the amount of time\nit would take the signal to travel to, bounce off, and return from a\ntarget that is distance $R$ away:</p>\n<p>$$ t_R = 2R / v $$</p>\n<p>Therefore, the change in frequency for a target at range $R$ will be:</p>\n<p>$$ f_{d}= t_R S = \\frac{2RS}{v}$$</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">pi <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>pi\n\n<span class=\"token comment\"># Radar parameters</span>\nfs <span class=\"token operator\">=</span> <span class=\"token number\">78125</span>          <span class=\"token comment\"># Sampling frequency in Hz, i.e. we sample 78125</span>\n                    <span class=\"token comment\"># times per second</span>\n\nts <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token operator\">/</span> fs         <span class=\"token comment\"># Sampling time, i.e. one sample is taken each</span>\n                    <span class=\"token comment\"># ts seconds</span>\n\nTeff <span class=\"token operator\">=</span> <span class=\"token number\">2048.0</span> <span class=\"token operator\">*</span> ts  <span class=\"token comment\"># Total sampling time for 2048 samples</span>\n                    <span class=\"token comment\"># (AKA effective sweep duration) in seconds.</span>\n\nBeff <span class=\"token operator\">=</span> <span class=\"token number\">100e6</span>        <span class=\"token comment\"># Range of transmit signal frequency during the time the</span>\n                    <span class=\"token comment\"># radar samples, known as the \"effective bandwidth\"</span>\n                    <span class=\"token comment\"># (given in Hz)</span>\n\nS <span class=\"token operator\">=</span> Beff <span class=\"token operator\">/</span> Teff     <span class=\"token comment\"># Frequency sweep rate in Hz/s</span>\n\n<span class=\"token comment\"># Specification of targets.  We made these targets up, imagining they</span>\n<span class=\"token comment\"># are objects seen by the radar with the specified range and size</span>\n\nR <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token number\">137</span><span class=\"token punctuation\">,</span> <span class=\"token number\">154</span><span class=\"token punctuation\">,</span> <span class=\"token number\">159</span><span class=\"token punctuation\">,</span>  <span class=\"token number\">180</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Ranges (in meter)</span>\nM <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0.33</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.02</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Target size</span>\nP <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> pi <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> pi <span class=\"token operator\">/</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> pi <span class=\"token operator\">/</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> pi <span class=\"token operator\">/</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Randomly chosen phase offsets</span>\n\nt <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>arange<span class=\"token punctuation\">(</span><span class=\"token number\">2048</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> ts  <span class=\"token comment\"># Sample times</span>\n\nfd <span class=\"token operator\">=</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> S <span class=\"token operator\">*</span> R <span class=\"token operator\">/</span> <span class=\"token number\">3E8</span>      <span class=\"token comment\"># Frequency differences for these targets</span>\n\n<span class=\"token comment\"># Generate five targets</span>\nsignals <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>cos<span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">*</span> pi <span class=\"token operator\">*</span> fd <span class=\"token operator\">*</span> t<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">,</span> np<span class=\"token punctuation\">.</span>newaxis<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> P<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Save the signal associated with the first target as an example for</span>\n<span class=\"token comment\"># later inspection</span>\nv_single <span class=\"token operator\">=</span> signals<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token comment\"># Weigh the signals, according to target size, and sum, to generate</span>\n<span class=\"token comment\"># the combined signal seen by the radar</span>\nv_sim <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span>M <span class=\"token operator\">*</span> signals<span class=\"token punctuation\">,</span> axis<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">## The above code is equivalent to:</span>\n<span class=\"token comment\">#</span>\n<span class=\"token comment\"># v0 = np.cos(2 * pi * fd[0] * t)</span>\n<span class=\"token comment\"># v1 = np.cos(2 * pi * fd[1] * t + pi / 2)</span>\n<span class=\"token comment\"># v2 = np.cos(2 * pi * fd[2] * t + pi / 3)</span>\n<span class=\"token comment\"># v3 = np.cos(2 * pi * fd[3] * t + pi / 5)</span>\n<span class=\"token comment\"># v4 = np.cos(2 * pi * fd[4] * t + pi / 6)</span>\n<span class=\"token comment\">#</span>\n<span class=\"token comment\">## Blend them together</span>\n<span class=\"token comment\"># v_single = v0</span>\n<span class=\"token comment\"># v_sim = (0.33 * v0) + (0.2 * v1) + (0.9 * v2) + (0.02 * v3) + (0.1 * v4)</span></code></pre></div>\n<p>Above, we generate a synthetic signal, $v_\\mathrm{single}$, received when\nlooking at a single target (see figure below). By counting the number\nof cycles seen in a given time period, we can compute the frequency of\nthe signal and thus the distance to the target.</p>\n<p>A real radar will rarely receive only a single echo, though. The\nsimulated signal $v<em>\\mathrm{sim}$ shows what a radar signal will look\nlike with five targets at different ranges (including two close to one\nanother at 154 and 159 meters), and $v</em>\\mathrm{actual}(t)$ shows the\noutput signal obtained with an actual radar. When multiple echoes add\ntogether, the result makes little intuitive sense; until, that is, we\nlook at it more carefully through the lens of the discrete Fourier\ntransform.</p>\n<!--\nA synthetic radar signal is shown as $v_{1}(t)$ in Fig. [fig:radar time signals]\nfor a radar with parameters $B_{eff}=100$ MHz, sampling frequency\n28125 Hz and N=2048 samples. The effective sweep time is\n$T_{eff}=\\frac{2048}{28125}=26.214$ ms. We can interpret this signal\nby counting the number of cycles in the graph — about\n$66\\frac{1}{2}$. The difference frequency is approximately\n$\\frac{66.5}{26.214E-3}=6.35$ kHz. With\n$S=\\frac{B_{eff}}{T_{eff}}=\\frac{100E6}{26.214E-3}=3.815\\times10^{9}$\nHz/s, we can calculate the range to the target as\n$R=\\frac{vf_{d}}{2S}=\\frac{3\\times10^{8}\\times6.35\\times10^{3}}{2\\times3.815\\times10^{9}}=249.7$\nm.\n-->\n<p><img src=\"../figures/generated/radar_time_signals.png\" alt=\"Receiver output signals: (a) single simulated target\n (b) five simulated targets (c) actual radar data\"></p>\n<p>The real-world radar data is read from a NumPy-format <code class=\"language-text\">.npz</code> file (a\nlight-weight, cross-platform and cross-version compatible storage\nformat). These files can be saved with the <code class=\"language-text\">np.savez</code> or\n<code class=\"language-text\">np.savez_compressed</code> functions. Note that SciPy's <code class=\"language-text\">io</code> submodule\ncan also easily read other formats, such as MATLAB(R) and NetCDF\nfiles.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">data <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>load<span class=\"token punctuation\">(</span><span class=\"token string\">'data/radar_scan_0.npz'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Load variable 'scan' from 'radar_scan_0.npz'</span>\nscan <span class=\"token operator\">=</span> data<span class=\"token punctuation\">[</span><span class=\"token string\">'scan'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token comment\"># The dataset contains multiple measurements, each taken with the</span>\n<span class=\"token comment\"># radar pointing in a different direction.  Here we take one such as</span>\n<span class=\"token comment\"># measurement, at a specified azimuth (left-right position) and elevation</span>\n<span class=\"token comment\"># (up-down position).  The measurement has shape (2048,).</span>\n\nv_actual <span class=\"token operator\">=</span> scan<span class=\"token punctuation\">[</span><span class=\"token string\">'samples'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">14</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token comment\"># The signal amplitude ranges from -2.5V to +2.5V.  The 14-bit</span>\n<span class=\"token comment\"># analogue-to-digital converter in the radar gives out integers</span>\n<span class=\"token comment\"># between -8192 to 8192.  We convert back to voltage by multiplying by</span>\n<span class=\"token comment\"># $(2.5 / 8192)$.</span>\n\nv_actual <span class=\"token operator\">=</span> v_actual <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2.5</span> <span class=\"token operator\">/</span> <span class=\"token number\">8192</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Since <code class=\"language-text\">.npz</code>-files can store multiple variables, we have to select\nthe one we want: <code class=\"language-text\">data['scan']</code>. That returns a\n<em>structured NumPy array</em> with the following fields:</p>\n<ul>\n<li><strong>time</strong> : unsigned 64-bit (8 byte) integer (<code class=\"language-text\">np.uint64</code>)</li>\n<li><strong>size</strong> : unsigned 32-bit (4 byte) integer (<code class=\"language-text\">np.uint32</code>)</li>\n<li>\n<p><strong>position</strong></p>\n<ul>\n<li><strong>az</strong> : 32-bit float (<code class=\"language-text\">np.float32</code>)</li>\n<li><strong>el</strong> : 32-bit float (<code class=\"language-text\">np.float32</code>)</li>\n<li><strong>region_type</strong> : unsigned 8-bit (1 byte) integer (<code class=\"language-text\">np.uint8</code>)</li>\n<li><strong>region_ID</strong> : unsigned 16-bit (2 byte) integer (<code class=\"language-text\">np.uint16</code>)</li>\n<li><strong>gain</strong> : unsigned 8-bit (1 byte) integer (<code class=\"language-text\">np.uin8</code>)</li>\n<li><strong>samples</strong> : 2048 unsigned 16-bit (2 byte) integers (<code class=\"language-text\">np.uint16</code>)</li>\n</ul>\n</li>\n</ul>\n<p>While it is true that NumPy arrays are <em>homogeneous</em> (i.e., all the\nelements inside are the same), it does not mean that those elements\ncannot be compound elements, as is the case here.</p>\n<p>An individual field is accessed using dictionary syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">azimuths <span class=\"token operator\">=</span> scan<span class=\"token punctuation\">[</span><span class=\"token string\">'position'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token string\">'az'</span><span class=\"token punctuation\">]</span>  <span class=\"token comment\"># Get all azimuth measurements</span></code></pre></div>\n<p>To summarize what we've seen so far: the shown measurements\n($v<em>\\mathrm{sim}$ and $v</em>\\mathrm{actual}$) are the sum of sinusoidal\nsignals reflected by each of several objects. We need to determine\neach of the constituent components of these composite radar\nsignals. The FFT is the tool that will do this for us.</p>\n<h3>Signal properties in the frequency domain</h3>\n<p>First, we take the FFTs of our three signals (synthetic single target,\nsynthetic multi-target, and real) and then display the\npositive frequency components (i.e., components $0$ to $N/2$). These\nare called the <em>range traces</em> in radar terminology.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">fig<span class=\"token punctuation\">,</span> axes <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> sharex<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Take FFTs of our signals.  Note the convention to name FFTs with a</span>\n<span class=\"token comment\"># capital letter.</span>\n\nV_single <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>v_single<span class=\"token punctuation\">)</span>\nV_sim <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>v_sim<span class=\"token punctuation\">)</span>\nV_actual <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>v_actual<span class=\"token punctuation\">)</span>\n\nN <span class=\"token operator\">=</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>V_single<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">with</span> plt<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">(</span><span class=\"token string\">'style/thinner.mplstyle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>V_single<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">\"$|V_\\mathrm{single}|$\"</span><span class=\"token punctuation\">)</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_xlim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1100</span><span class=\"token punctuation\">)</span>\n\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>V_sim<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">\"$|V_\\mathrm{sim} |$\"</span><span class=\"token punctuation\">)</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span>\n\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>V_actual<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_ylim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">750</span><span class=\"token punctuation\">)</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span><span class=\"token string\">\"$|V_\\mathrm{actual}|$\"</span><span class=\"token punctuation\">)</span>\n\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">\"FFT component $n$\"</span><span class=\"token punctuation\">)</span>\n\n    <span class=\"token keyword\">for</span> ax <span class=\"token keyword\">in</span> axes<span class=\"token punctuation\">:</span>\n        ax<span class=\"token punctuation\">.</span>grid<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<!-- caption text=\"Range traces for: (a) single simulated target, (b) mutiple simulated targets, (c) real-world targets\" -->\n<p>Suddenly, the information makes sense!</p>\n<p>The plot for $|V<em>\\mathrm{single}|$ clearly shows a target at component 67, and\nfor $|V</em>\\mathrm{sim}|$ shows the targets that produced the signal that was\nuninterpretable in the time domain. The real radar\nsignal, $|V_\\mathrm{actual}|$ shows a large number of targets between\ncomponent 400 and 500 with a large peak in component 443. This happens\nto be an echo return from a radar illuminating the high wall of an\nopen-cast mine.</p>\n<p>To get useful information from the plot, we must determine the range!\nAgain, we use the formula:</p>\n<p>$$R<em>{n}=\\frac{nv}{2B</em>{eff}}$$</p>\n<p>In radar terminology, each DFT component is known as a <em>range bin</em>.</p>\n<!--\nThe sinusoid associated with the first component of the DFT has a\nperiod exactly equal to the duration $T_{eff}$ of the time domain\nsignal, so $f_{1}=\\frac{1}{T_{eff}}$. The other sinusoids in the\nFourier series are harmonics of this, $f_{n}=\\frac{n}{T_{eff}}$.\n\nThe ranges associated with the DFT components follow from\nEqs. ([eq:difference frequency]) and ([eq:Effective bandwidth]) as\n\n$$R_{n}=\\frac{nv}{2B_{eff}}$$\n\nand the associated DFT components are known as *range bins* in radar\nterminology.\n\n-->\n<p>This equation also defines the range resolution of the radar: targets\nwill only be distinguishable if they are separated by more than two\nrange bins, i.e.</p>\n<p>$$\\Delta R>\\frac{1}{B_{eff}}.$$</p>\n<p>This is a fundamental property of all types of radar.</p>\n<!--\nThe plot in Fig. ([fig:FFT range traces]) has a fundamental\nshortcoming. The observable dynamic range is the signal is very\nlimited! We could easily have missed one of the targets in the trace\nfor $V_{5}$!  To ameliorate the problem, we plot the same FFTs but\nthis time against a logarithmic y-axis.  The traces were all\nnormalized by dividing the amplitudes with the maximum value.\n-->\n<p>This result is quite satisfying—but the dynamic range is so large\nthat we could very easily miss some peaks. Let's take the $\\log$ as\nbefore with the spectrogram:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">c <span class=\"token operator\">=</span> <span class=\"token number\">3e8</span>  <span class=\"token comment\"># Approximately the speed of light and of</span>\n         <span class=\"token comment\"># electromagnetic waves in air</span>\n\nfig<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>ax0<span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">,</span> ax2<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">dB</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token string\">\"Calculate the log ratio of y / max(y) in decibel.\"</span>\n\n    y <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span>\n    y <span class=\"token operator\">/=</span> y<span class=\"token punctuation\">.</span><span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token number\">20</span> <span class=\"token operator\">*</span> np<span class=\"token punctuation\">.</span>log10<span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">log_plot_normalized</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> ylabel<span class=\"token punctuation\">,</span> ax<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    ax<span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> dB<span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span>ylabel<span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>grid<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\nrng <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>arange<span class=\"token punctuation\">(</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> c <span class=\"token operator\">/</span> <span class=\"token number\">2</span> <span class=\"token operator\">/</span> Beff\n\n<span class=\"token keyword\">with</span> plt<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">(</span><span class=\"token string\">'style/thinner.mplstyle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    log_plot_normalized<span class=\"token punctuation\">(</span>rng<span class=\"token punctuation\">,</span> V_single<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"$|V_0|$ [dB]\"</span><span class=\"token punctuation\">,</span> ax0<span class=\"token punctuation\">)</span>\n    log_plot_normalized<span class=\"token punctuation\">(</span>rng<span class=\"token punctuation\">,</span> V_sim<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"$|V_5|$ [dB]\"</span><span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">)</span>\n    log_plot_normalized<span class=\"token punctuation\">(</span>rng<span class=\"token punctuation\">,</span> V_actual<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"$|V_{\\mathrm{actual}}|$ [dB]\"</span><span class=\"token punctuation\">,</span> ax2<span class=\"token punctuation\">)</span>\n\nax0<span class=\"token punctuation\">.</span>set_xlim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Change x limits for these plots so that</span>\nax1<span class=\"token punctuation\">.</span>set_xlim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># we are better able to see the shape of the peaks.</span>\nax2<span class=\"token punctuation\">.</span>set_xlim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>V_actual<span class=\"token punctuation\">)</span> <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\nax2<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">'range'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<!-- caption text=\"Logarithm of range traces\" -->\n<p>The observable dynamic range is much improved in these plots. For\ninstance, in the real radar signal the <em>noise floor</em> of the radar has\nbecome visible (i.e., the level where electronic noise in the system\nstarts to limit the radar's ability to detect a target).</p>\n<!-- The noise floor is ultimately caused by a phenomenon\ncalled thermal noise that is produced by all conducting elements that\nhave resistance at temperatures above absolute zero, as well as by\nshot noise, a noise mechanism inherent in all the electronic devices\nthat are used for processing the radar signal. The noise floor of a\nradar limits its ability to detect weak echoes. -->\n<h3>Windowing, applied</h3>\n<p>We're getting there, but in the spectrum of the simulated signal, we\nstill cannot distinguish the peaks at 154 and 159 meters. Who knows\nwhat we're missing in the real-world signal! To sharpen the peaks,\nwe'll return to our toolbox and make use of <em>windowing</em>.</p>\n<!--\n\nThe range traces in Fig. ([fig:Log range traces]) display a further\nserious shortcoming. The signals $v_{1}$ and $v_{5}$ are composed of\npure sinusoids and we would ideally expect the FFT to produce line\nspectra for these signals. The logarithmic plots show steadily\nincreasing values as the peaks are approached from both sides, to such\nan extent that one of the targets in the plot for $|v_{5}|$ can hardly\nbe distinguished even though it is separated by several range bins\nfrom the large target. The broadening is caused by *side lobes* in the\nDFT. These are caused by an inherent clash between the properties of\nthe signal we analyzed and the signal produced by the inverse DFT.\n\n-->\n<p>Here are the signals used thus far in this example, windowed with a\nKaiser window with $\\beta=6.1$:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">f<span class=\"token punctuation\">,</span> axes <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> sharex<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nt_ms <span class=\"token operator\">=</span> t <span class=\"token operator\">*</span> <span class=\"token number\">1000</span>  <span class=\"token comment\"># Sample times in milli-second</span>\n\nw <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>kaiser<span class=\"token punctuation\">(</span>N<span class=\"token punctuation\">,</span> <span class=\"token number\">6.1</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Kaiser window with beta = 6.1</span>\n\n<span class=\"token keyword\">for</span> n<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>signal<span class=\"token punctuation\">,</span> label<span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> <span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span>v_single<span class=\"token punctuation\">,</span> <span class=\"token string\">r'$v_0 [V]$'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                     <span class=\"token punctuation\">(</span>v_sim<span class=\"token punctuation\">,</span> <span class=\"token string\">r'$v_5 [V]$'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                     <span class=\"token punctuation\">(</span>v_actual<span class=\"token punctuation\">,</span> <span class=\"token string\">r'$v_{\\mathrm{actual}} [V]$'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">with</span> plt<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">(</span><span class=\"token string\">'style/thinner.mplstyle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        axes<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>plot<span class=\"token punctuation\">(</span>t_ms<span class=\"token punctuation\">,</span> w <span class=\"token operator\">*</span> signal<span class=\"token punctuation\">)</span>\n        axes<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span>label<span class=\"token punctuation\">)</span>\n        axes<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>grid<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\naxes<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_xlim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> t_ms<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\naxes<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span><span class=\"token string\">'Time [ms]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Windowed signals for: (a) single simulated target, (b) multiple simulated targets, (c) real targets\" -->\n<p>And the corresponding FFTs (or \"range traces\", in radar terms):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">V_single_win <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>w <span class=\"token operator\">*</span> v_single<span class=\"token punctuation\">)</span>\nV_sim_win <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>w <span class=\"token operator\">*</span> v_sim<span class=\"token punctuation\">)</span>\nV_actual_win <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>w <span class=\"token operator\">*</span> v_actual<span class=\"token punctuation\">)</span>\n\nfig<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>ax0<span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">,</span>ax2<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">with</span> plt<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">(</span><span class=\"token string\">'style/thinner.mplstyle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    log_plot_normalized<span class=\"token punctuation\">(</span>rng<span class=\"token punctuation\">,</span> V_single_win<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token string\">r\"$|V_{0,\\mathrm{win}}|$ [dB]\"</span><span class=\"token punctuation\">,</span> ax0<span class=\"token punctuation\">)</span>\n    log_plot_normalized<span class=\"token punctuation\">(</span>rng<span class=\"token punctuation\">,</span> V_sim_win<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token string\">r\"$|V_{5,\\mathrm{win}}|$ [dB]\"</span><span class=\"token punctuation\">,</span> ax1<span class=\"token punctuation\">)</span>\n    log_plot_normalized<span class=\"token punctuation\">(</span>rng<span class=\"token punctuation\">,</span> V_actual_win<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token string\">r\"$|V_\\mathrm{actual,win}|$ [dB]\"</span><span class=\"token punctuation\">,</span> ax2<span class=\"token punctuation\">)</span>\n\nax0<span class=\"token punctuation\">.</span>set_xlim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Change x limits for these plots so that</span>\nax1<span class=\"token punctuation\">.</span>set_xlim<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># we are better able to see the shape of the peaks.</span>\n\nax1<span class=\"token punctuation\">.</span>annotate<span class=\"token punctuation\">(</span><span class=\"token string\">\"New, previously unseen!\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">160</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">35</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> xytext<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">15</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n             textcoords<span class=\"token operator\">=</span><span class=\"token string\">\"offset points\"</span><span class=\"token punctuation\">,</span> color<span class=\"token operator\">=</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> size<span class=\"token operator\">=</span><span class=\"token string\">'x-small'</span><span class=\"token punctuation\">,</span>\n             arrowprops<span class=\"token operator\">=</span><span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>width<span class=\"token operator\">=</span><span class=\"token number\">0.5</span><span class=\"token punctuation\">,</span> headwidth<span class=\"token operator\">=</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> headlength<span class=\"token operator\">=</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span>\n                             fc<span class=\"token operator\">=</span><span class=\"token string\">'k'</span><span class=\"token punctuation\">,</span> shrink<span class=\"token operator\">=</span><span class=\"token number\">0.1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"Range traces (spectrum) of windowed signals\" -->\n<p>Compare these with the earlier range traces. There is a dramatic\nlowering in side lobe level, but at a price: the peaks have changed in\nshape, widening and becoming less peaky, thus lowering the radar\nresolution, that is, the ability of the radar to distinguish between\ntwo closely space targets. The choice of window is a compromise\nbetween side lobe level and resolution. Even so, referring to the\ntrace for $V_\\mathrm{sim}$, windowing has dramatically increased our\nability to distinguish the small target from its large neighbor.</p>\n<p>In the real radar data range trace windowing has also reduced the side\nlobes. This is most visible in the depth of the notch between the two\ngroups of targets.</p>\n<h3>Radar Images</h3>\n<p>Knowing how to analyze a single trace, we can expand to looking at\nradar images.</p>\n<p>The data is produced by a radar with a parabolic reflector antenna. It\nproduces a highly directive round pencil beam with a $2^\\circ$\nspreading angle between half-power points. When directed with normal\nincidence at a plane, the radar will illuminate a spot of about $2$ meters in\ndiameter at a distance of 60 meters.\nOutside this spot, the power drops off quite rapidly, but strong\nechoes from outside the spot will nevertheless still be visible.</p>\n<p>By varying the pencil beam's azimuth (left-right position) and\nelevation (up-down position), we can sweep it across the target area\nof interest. When reflections are picked up, we can calculate the\ndistance to the reflector (the object hit by the radar signal).\nTogether with the current pencil beam azimuth and elevation, this\ndefines the reflector's position in 3D.</p>\n<p>A rock slope consists of thousands of reflectors. A range bin can be\nthought of as a large sphere with the radar at its center that\nintersects the slope along a ragged line. The scatterers on this line\nwill produce reflections in this range bin. The wavelength of the\nradar (distance the transmitted wave travels in one oscillation\nsecond) is about 30 mm. The reflections from scatterers separated by\nodd multiples of a quarter wavelength in range, about 7.5 mm, will\ntend to interfere destructively, while those from scatterers separated\nby multiples of a half wavelength will tend to interfere\nconstructively at the radar. The reflections combine to produce\napparent spots of strong reflections. This specific radar moves its\nantenna in order to scan small regions consisting of $20^\\circ$\nazimuth and $30^\\circ$ elevation bins scanned in steps of $0.5^\\circ$.</p>\n<p>We will now draw some contour plots of the resulting radar data.\nPlease refer to the diagram below to see how the different slices are\ntaken. A first slice at fixed range shows the strength of echoes\nagainst elevation and azimuth. Another two slices at fixed elevation\nand azimuth respectively shows the slope. The stepped construction of\nthe high wall in an opencast mine is visible in the azimuth plane.</p>\n<p><img src=\"../figures/axes_slices.png\"\n     alt=\"Diagram showing azimuth, elevation and range slices through data volume\"/></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">data <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>load<span class=\"token punctuation\">(</span><span class=\"token string\">'data/radar_scan_1.npz'</span><span class=\"token punctuation\">)</span>\nscan <span class=\"token operator\">=</span> data<span class=\"token punctuation\">[</span><span class=\"token string\">'scan'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token comment\"># The signal amplitude ranges from -2.5V to +2.5V.  The 14-bit</span>\n<span class=\"token comment\"># analogue-to-digital converter in the radar gives out integers</span>\n<span class=\"token comment\"># between -8192 to 8192.  We convert back to voltage by multiplying by</span>\n<span class=\"token comment\"># $(2.5 / 8192)$.</span>\n\nv <span class=\"token operator\">=</span> scan<span class=\"token punctuation\">[</span><span class=\"token string\">'samples'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">*</span> <span class=\"token number\">2.5</span> <span class=\"token operator\">/</span> <span class=\"token number\">8192</span>\nwin <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>hanning<span class=\"token punctuation\">(</span>N <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token comment\"># Take FFT for each measurement</span>\nV <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">(</span>v <span class=\"token operator\">*</span> win<span class=\"token punctuation\">,</span> axis<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">:</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">:</span>N <span class=\"token operator\">//</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\n\ncontours <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>arange<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">40</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># ignore MPL layout warnings</span>\n<span class=\"token keyword\">import</span> warnings\nwarnings<span class=\"token punctuation\">.</span>filterwarnings<span class=\"token punctuation\">(</span><span class=\"token string\">'ignore'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'.*Axes.*compatible.*tight_layout.*'</span><span class=\"token punctuation\">)</span>\n\nf<span class=\"token punctuation\">,</span> axes <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4.8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> tight_layout<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n\nlabels <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'Range'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Azimuth'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Elevation'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">plot_slice</span><span class=\"token punctuation\">(</span>ax<span class=\"token punctuation\">,</span> radar_slice<span class=\"token punctuation\">,</span> title<span class=\"token punctuation\">,</span> xlabel<span class=\"token punctuation\">,</span> ylabel<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    ax<span class=\"token punctuation\">.</span>contourf<span class=\"token punctuation\">(</span>dB<span class=\"token punctuation\">(</span>radar_slice<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> contours<span class=\"token punctuation\">,</span> cmap<span class=\"token operator\">=</span><span class=\"token string\">'magma_r'</span><span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>set_title<span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span>xlabel<span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span>ylabel<span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>set_facecolor<span class=\"token punctuation\">(</span>plt<span class=\"token punctuation\">.</span>cm<span class=\"token punctuation\">.</span>magma_r<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">40</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">with</span> plt<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">(</span><span class=\"token string\">'style/thinner.mplstyle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    plot_slice<span class=\"token punctuation\">(</span>axes<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> V<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">:</span><span class=\"token punctuation\">,</span> <span class=\"token number\">250</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Range=250'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Azimuth'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Elevation'</span><span class=\"token punctuation\">)</span>\n    plot_slice<span class=\"token punctuation\">(</span>axes<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> V<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Azimuth=3'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Range'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Elevation'</span><span class=\"token punctuation\">)</span>\n    plot_slice<span class=\"token punctuation\">(</span>axes<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> V<span class=\"token punctuation\">[</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">:</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>T<span class=\"token punctuation\">,</span> <span class=\"token string\">'Elevation=6'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Azimuth'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Range'</span><span class=\"token punctuation\">)</span>\n    axes<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>axis<span class=\"token punctuation\">(</span><span class=\"token string\">'off'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<!-- caption text=\"Contour plots of range traces along various axes (see diagram)\" -->\n<h4>3D visualization</h4>\n<p>We can also visualize the volume in three dimensions.</p>\n<p>We first compute the argmax (the index of the maximum value) in the\nrange direction. This should give an indication of the range at which\nthe radar beam hit the rock slope. Each argmax index is converted to\na three-dimensional (elevation-azimuth-range) coordinate:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">r <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>argmax<span class=\"token punctuation\">(</span>V<span class=\"token punctuation\">,</span> axis<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n\nel<span class=\"token punctuation\">,</span> az <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>meshgrid<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span><span class=\"token punctuation\">[</span>np<span class=\"token punctuation\">.</span>arange<span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> s <span class=\"token keyword\">in</span> r<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> indexing<span class=\"token operator\">=</span><span class=\"token string\">'ij'</span><span class=\"token punctuation\">)</span>\n\naxis_labels <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Elevation'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Azimuth'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Range'</span><span class=\"token punctuation\">]</span>\ncoords <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>column_stack<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">.</span>flat<span class=\"token punctuation\">,</span> az<span class=\"token punctuation\">.</span>flat<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">.</span>flat<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Taking these coordinates, we project them onto the plane (by dropping\nthe range coordinate), and perform a Delaunay tesselation. The\ntesselation returns a set of indices into our coordinates that define\ntriangles (or simplices). While the triangles are strictly speaking\ndefined on the projected coordinates, we use our original coordinates\nfor the reconstruction, thereby adding back the range component:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> scipy <span class=\"token keyword\">import</span> spatial\n\nd <span class=\"token operator\">=</span> spatial<span class=\"token punctuation\">.</span>Delaunay<span class=\"token punctuation\">(</span>coords<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">:</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\nsimplexes <span class=\"token operator\">=</span> coords<span class=\"token punctuation\">[</span>d<span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">]</span></code></pre></div>\n<p>For display purposes, we swap the range axis to be the first:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">coords <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span>coords<span class=\"token punctuation\">,</span> shift<span class=\"token operator\">=</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> axis<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\naxis_labels <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span>axis_labels<span class=\"token punctuation\">,</span> shift<span class=\"token operator\">=</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Now, Matplotlib's <code class=\"language-text\">trisurf</code> can be used to visualize the result:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># This import initializes Matplotlib's 3D machinery</span>\n<span class=\"token keyword\">from</span> mpl_toolkits<span class=\"token punctuation\">.</span>mplot3d <span class=\"token keyword\">import</span> Axes3D\n\n<span class=\"token comment\"># Set up the 3D axis</span>\nf<span class=\"token punctuation\">,</span> ax <span class=\"token operator\">=</span> plt<span class=\"token punctuation\">.</span>subplots<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> figsize<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4.8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                     subplot_kw<span class=\"token operator\">=</span><span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>projection<span class=\"token operator\">=</span><span class=\"token string\">'3d'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">with</span> plt<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>context<span class=\"token punctuation\">(</span><span class=\"token string\">'style/thinner.mplstyle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    ax<span class=\"token punctuation\">.</span>plot_trisurf<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>coords<span class=\"token punctuation\">.</span>T<span class=\"token punctuation\">,</span> triangles<span class=\"token operator\">=</span>d<span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">,</span> cmap<span class=\"token operator\">=</span><span class=\"token string\">'magma_r'</span><span class=\"token punctuation\">)</span>\n\n    ax<span class=\"token punctuation\">.</span>set_xlabel<span class=\"token punctuation\">(</span>axis_labels<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>set_ylabel<span class=\"token punctuation\">(</span>axis_labels<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>set_zlabel<span class=\"token punctuation\">(</span>axis_labels<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> labelpad<span class=\"token operator\">=</span><span class=\"token operator\">-</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    ax<span class=\"token punctuation\">.</span>set_xticks<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">15</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Adjust the camera position to match our diagram above</span>\nax<span class=\"token punctuation\">.</span>view_init<span class=\"token punctuation\">(</span>azim<span class=\"token operator\">=</span><span class=\"token operator\">-</span><span class=\"token number\">50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<!-- caption text=\"3-D visualization of estimated rock slope position\" -->\n<h3>Further applications of the FFT</h3>\n<p>The examples above show just one of the uses of the FFT in\nradar. There are many others, such as movement (Doppler) measurement\nand target recognition. The fast Fourier transform is pervasive, and is\nseen anywhere from Magnetic Resonance Imaging (MRI) to statistics.\nWith the basic techniques that this chapter outlines in hand, you\nshould be well equipped to use it!</p>\n<h3>Further reading</h3>\n<p>On the Fourier transform:</p>\n<ul>\n<li>A. Papoulis, <em>The Fourier Integral and Its Applications</em>,</li>\n<li>McGraw-Hill, 1960.</li>\n<li>Ronald A. Bracewell, <em>The Fourier Transform and Its Applications</em>,\nMcGraw-Hill, 1986.</li>\n</ul>\n<p>On radar signal processing:</p>\n<ul>\n<li>Mark A. Richards, <em>Principles of Modern Radar: Basic Principles</em>,</li>\n<li>SciTech, 2010</li>\n<li>Mark A. Richards, <em>Fundamentals of Radar Signal Processing</em>,\nMcGraw-Hill, 2014.</li>\n</ul>\n<!-- exercise begin -->\n<p><strong>Exercise:</strong> The FFT is often used to speed up image convolution\n(convolution is the application of a moving filter mask). Convolve an\nimage with <code class=\"language-text\">np.ones((5, 5))</code>, using a) numpy's <code class=\"language-text\">np.convolve</code> and\nb) <code class=\"language-text\">np.fft.fft2</code>. Confirm that the results are identical.</p>\n<p>Hints:</p>\n<ul>\n<li>The convolution of <code class=\"language-text\">x</code> and <code class=\"language-text\">y</code> is equivalent to <code class=\"language-text\">ifft2(X * Y)</code>, where</li>\n<li><code class=\"language-text\">X</code> and <code class=\"language-text\">Y</code> are the FFTs of x and y respectively.</li>\n<li>In order to multiply <code class=\"language-text\">X</code> and <code class=\"language-text\">Y</code>, they have to be the same size.\nUse <code class=\"language-text\">np.pad</code> to extend <code class=\"language-text\">x</code> and <code class=\"language-text\">y</code> with zeros (toward the right and\nbottom) <em>before</em> taking their FFT.</li>\n<li>You may see some edge effects. These can be removed by increasing\nthe padding size, so that both <code class=\"language-text\">x</code> and <code class=\"language-text\">y</code> have dimensions\n<code class=\"language-text\">shape(x) + shape(y) - 1</code>.</li>\n</ul>\n<!-- solution begin -->\n<p><strong>Solution:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> scipy <span class=\"token keyword\">import</span> signal\n\nx <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>random<span class=\"token punctuation\">.</span>random<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">50</span><span class=\"token punctuation\">,</span> <span class=\"token number\">50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\ny <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>ones<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nL <span class=\"token operator\">=</span> x<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> y<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span>\nPx <span class=\"token operator\">=</span> L <span class=\"token operator\">-</span> x<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\nPy <span class=\"token operator\">=</span> L <span class=\"token operator\">-</span> y<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n\nxx <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>pad<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> Px<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> Px<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> mode<span class=\"token operator\">=</span><span class=\"token string\">'constant'</span><span class=\"token punctuation\">)</span>\nyy <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>pad<span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> Py<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> Py<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> mode<span class=\"token operator\">=</span><span class=\"token string\">'constant'</span><span class=\"token punctuation\">)</span>\n\nzz <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>ifft2<span class=\"token punctuation\">(</span>np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft2<span class=\"token punctuation\">(</span>xx<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> np<span class=\"token punctuation\">.</span>fft<span class=\"token punctuation\">.</span>fft2<span class=\"token punctuation\">(</span>yy<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>real\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Resulting shape:'</span><span class=\"token punctuation\">,</span> zz<span class=\"token punctuation\">.</span>shape<span class=\"token punctuation\">,</span> <span class=\"token string\">' &lt;-- Why?'</span><span class=\"token punctuation\">)</span>\n\nz <span class=\"token operator\">=</span> signal<span class=\"token punctuation\">.</span>convolve2d<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Results are equal?'</span><span class=\"token punctuation\">,</span> np<span class=\"token punctuation\">.</span>allclose<span class=\"token punctuation\">(</span>zz<span class=\"token punctuation\">,</span> z<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<!-- solution end -->\n<!-- exercise end -->\n<div class=\"footnotes\">\n<hr>\n<ol>\n<li id=\"fn-discrete\">\n<p>The discrete Fourier transform operates on sampled data,\nin contrast to the standard Fourier transform which is\ndefined for continuous functions.</p>\n<a href=\"#fnref-discrete\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-complex\">\n<p>The Fourier transform essentially tells us how to combine\na set of sinusoids of varying frequency to form the input\nsignal. The spectrum consists of complex numbers—one for\neach sinusoid. A complex number encodes two things: a\nmagnitude and an angle. The magnitude is the strength of\nthe sinusoid in the signal, and the angle how much it is\nshifted in time. At this point, we only care about the\nmagnitude, which we calculate using <code class=\"language-text\">np.abs</code>.</p>\n<a href=\"#fnref-complex\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-time\">\n<p>For more on techniques for calculating both (approximate) frequencies\nand time of occurrence, read up on wavelet analysis.</p>\n<a href=\"#fnref-time\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-scaling\">\n<p>SciPy goes to some effort to preserve the energy in the\nspectrum. Therefore, when taking only half the components\n(for N even), it multiplies the remaining components,\napart from the first and last components, by two (those\ntwo components are \"shared\" by the two halves of the\nspectrum). It also normalizes the window by dividing it\nby its sum.</p>\n<a href=\"#fnref-scaling\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-periodic\">\n<p>The period can, in fact, also be infinite! The general\ncontinuous Fourier transform provides for this\npossibility. Discrete Fourier transforms are generally\ndefined over a finite interval, and this is implicitly\nthe period of the time domain function that is\ntransformed. In other words, if you do the inverse\ndiscrete Fourier transform, you <em>always</em> get a periodic\nsignal out.</p>\n<a href=\"#fnref-periodic\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-big_o\">\n<p>In computer science, the computational cost of an algorithm\nis often expressed in \"Big O\" notation. The notation gives\nus an indication of how an algorithm's execution time scales\nwith an increasing number of elements. If an algorithm is $\\mathcal{O}(N)$,\nit means its execution time increases linearly with\nthe number of input elements (for example, searching for a\ngiven value in an unsorted list is $\\mathcal{O}\\left(N\\right)$). Bubble sort is\nan example of an $O\\left(N^2\\right)$ algorithm; the exact number of\noperations performed may, hypothetically, be $N + \\frac{1}{2} N^2$,\nmeaning that the computational cost grows quadratically with\nthe number of input elements.</p>\n<a href=\"#fnref-big_o\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-fast\">\n<p>While ideally we don't want to reimplement existing\nalgorithms, sometimes it becomes necessary in order to obtain\nthe best execution speeds possible, and tools\nlike <a href=\"http://cython.org\">Cython</a>—which compiles Python to\nC—and <a href=\"http://numba.pydata.org\">Numba</a>—which does\njust-in-time compilation of Python code—make life a lot\neasier (and faster!). If you are able to use GPL-licenced\nsoftware, you may consider\nusing <a href=\"https://github.com/hgomersall/pyFFTW\">PyFFTW</a> for\nfaster FFTs.</p>\n<a href=\"#fnref-fast\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-odd_n\">\n<p>We leave it as an exercise for the reader to picture the\nsituation for $N$ odd. In this chapter, all examples use\neven-order DFTs.</p>\n<a href=\"#fnref-odd_n\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-choosing_a_window\">\n<p>The classical windowing functions include Hann,\nHamming, and Blackman. They differ in their\nsidelobe levels and in the broadening of the\nmain lobe (in the Fourier domain). A modern and\nflexible window function that is close to\noptimal for most applications is the Kaiser\nwindow—a good approximation to the optimal\nprolate spheroid window, which concentrates the\nmost energy into the main lobe. The Kaiser\nwindow can be tuned to suit the particular\napplication, as illustrated in the main text, by\nadjusting the parameter $\\beta$.</p>\n<a href=\"#fnref-choosing_a_window\" class=\"footnote-backref\">↩</a>\n</li>\n</ol>\n</div>"},{"url":"/docs/audio/dynamic-time-warping/","relativePath":"docs/audio/dynamic-time-warping.md","relativeDir":"docs/audio","base":"dynamic-time-warping.md","name":"dynamic-time-warping","frontmatter":{"title":"dynamic-time-warping","weight":0,"excerpt":"dynamic-time-warping","seo":{"title":"dynamic-time-warping","description":"dynamic-time-warping","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Dynamic Time Warping Triggered Guitar Effects Project:</h1>\n<h1>DTW Algorithm:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://onedrive.live.com/embed?cid=D21009FDD967A241&amp;resid=D21009FDD967A241%21634692&amp;authkey=AHfsGpj1Un3UNuE&amp;em=2&amp;wdAr=1.7777777777777777\" width=\"962px\" height=\"565px\" frameborder=\"0\">This is an embedded <a target=\"_blank\" href=\"https://office.com\">Microsoft Office</a> presentation, powered by <a target=\"_blank\" href=\"https://office.com/webapps\">Office</a>.</iframe>\n<br>\n<hr>\n<h1>Project:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://onedrive.live.com/embed?resid=D21009FDD967A241%21608188&amp;authkey=%21AL1vMFzOuqvFbUY&amp;em=2&amp;wdAr=1.7777777777777777\" width=\"962px\" height=\"565px\" frameborder=\"0\">This is an embedded <a target=\"_blank\" href=\"https://office.com\">Microsoft Office</a> presentation, powered by <a target=\"_blank\" href=\"https://office.com/webapps\">Office</a>.</iframe>\n<br>"},{"url":"/docs/audio/","relativePath":"docs/audio/index.md","relativeDir":"docs/audio","base":"index.md","name":"index","frontmatter":{"title":"Audio","weight":0,"excerpt":"Audio Projects and tools / web audio daw","seo":{"title":"Audio Projects","description":"A collection of web audio projects","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"100%\" height=\"500\" frameborder=\"0\"\nsrc=\"https://bgoonz.github.io/extracting-features-from-audio/\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"100%\" height=\"500\" frameborder=\"0\"\nsrc=\"https://observablehq.com/embed/@bgoonz/mode-lighting/2?cell=*\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h2>Music Theory</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"100%\" height=\"500\" frameborder=\"0\"\nsrc=\"https://synth-music-theory.netlify.app/\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n    <iframe\n      width=\"100%\"\n      height=\"1000\"\n      frameborder=\"0\"\n      src=\"https://observablehq.com/embed/@bgoonz/determining-the-key-of-bwv1001-1st-movement-adagio?cell=*\"\n    >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n    <iframe\n      width=\"100%\"\n      height=\"784\"\n      frameborder=\"0\"\n      src=\"https://observablehq.com/embed/@bgoonz/can-sound-add-value-to-data-visualizations?cells=viewof+chart\"\n    >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/audio/web-audio-api/","relativePath":"docs/audio/web-audio-api.md","relativeDir":"docs/audio","base":"web-audio-api.md","name":"web-audio-api","frontmatter":{"title":"Web Audio Api","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"Web Audio Api","description":"This article explains some of the audio theory behind how the features of the Web Audio API work","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Web Audio Api</h2>\n<h1>Basic concepts behind Web Audio API</h1>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#audio_graphs\" title=\"Permalink to Audio graphs\">Audio graphs</a></h2>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API\">Web Audio API</a> involves handling audio operations inside an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioContext\">audio context</a>, and has been designed to allow <strong>modular routing</strong>. Basic audio operations are performed with <strong>audio nodes</strong>, which are linked together to form an <strong>audio routing graph</strong>. Several sources --- with different types of channel layout --- are supported even within a single context. This modular design provides the flexibility to create complex audio functions with dynamic effects.</p>\n<p>Audio nodes are linked via their inputs and outputs, forming a chain that starts with one or more sources, goes through one or more nodes, then ends up at a destination. Although, you don't have to provide a destination if you, say, just want to visualize some audio data. A simple, typical workflow for web audio would look something like this:</p>\n<ol>\n<li>Create the audio context.</li>\n<li>Inside the context, create sources --- such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio\"><code class=\"language-text\">&lt;audio></code></a>, oscillator, or stream.</li>\n<li>Create effects nodes, such as reverb, biquad filter, panner, or compressor.</li>\n<li>Choose the final destination for the audio, such as the user's computer speakers.</li>\n<li>Establish connections from the audio sources through zero or more effects, eventually ending at the chosen destination.</li>\n</ol>\n<p><strong>Note:</strong> The number of audio channels available on a signal is frequently presented in a numeric format, such as 2.0 or 5.1. This is called <a href=\"https://en.wikipedia.org/wiki/Surround_sound#Channel_notation\" title=\"channel notation\">channel notation</a>. The first number is the number of full frequency range audio channels that the signal includes. The number after the period indicates the number of those channels which are reserved for low-frequency effect (LFE) outputs; these are often referred to as <strong>subwoofers</strong>.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API/webaudioapi_en.svg\" alt=\"A simple box diagram with an outer box labeled Audio context, and three inner boxes labeled Sources, Effects and Destination. The three inner boxes have arrow between them pointing from left to right, indicating the flow of audio information.\"></p>\n<p>Each input or output is composed of one or more audio <strong>channels,</strong> which together represent a specific audio layout. Any discrete channel structure is supported, including <em>mono</em>, <em>stereo</em>, <em>quad</em>, <em>5.1</em>, and so on.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API/mdn.png\" alt=\"Show the ability of AudioNodes to connect via their inputs and outputs and the channels inside these inputs/outputs.\"></p>\n<p>Audio sources can be obtained in a number of ways:</p>\n<ul>\n<li>Sound can be generated directly in JavaScript by an audio node (such as an oscillator).</li>\n<li>Created from raw PCM data (the audio context has methods to decode supported audio formats).</li>\n<li>Taken from HTML media elements (such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio\"><code class=\"language-text\">&lt;audio></code></a>).</li>\n<li>Taken directly from a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API\">WebRTC</a> <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStream\"><code class=\"language-text\">MediaStream</code></a> (such as a webcam or microphone).</li>\n</ul>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#audio_data_whats_in_a_sample\" title=\"Permalink to Audio data: what&#x27;s in a sample\">Audio data: what's in a sample</a></h2>\n<p>When an audio signal is processed, <strong>sampling</strong> means the conversion of a <a href=\"https://en.wikipedia.org/wiki/Continuous_signal\" title=\"Continuous signal\">continuous signal</a> to a <a href=\"https://en.wikipedia.org/wiki/Discrete_signal\" title=\"Discrete signal\">discrete signal</a>; or put another way, a continuous sound wave, such as a band playing live, is converted to a sequence of samples (a discrete-time signal) that allow a computer to handle the audio in distinct blocks.</p>\n<p>A lot more information can be found on the Wikipedia page <a href=\"https://en.wikipedia.org/wiki/Sampling_%28signal_processing%29\">Sampling (signal processing)</a>.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#audio_buffers_frames_samples_and_channels\" title=\"Permalink to Audio buffers: frames, samples and channels\">Audio buffers: frames, samples and channels</a></h2>\n<p>An <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer\"><code class=\"language-text\">AudioBuffer</code></a> takes as its parameters a number of channels (1 for mono, 2 for stereo, etc), a length, meaning the number of sample frames inside the buffer, and a sample rate, which is the number of sample frames played per second.</p>\n<p>A sample is a single float32 value that represents the value of the audio stream at each specific point in time, in a specific channel (left or right, if in the case of stereo). A frame, or sample frame, is the set of all values for all channels that will play at a specific point in time: all the samples of all the channels that play at the same time (two for a stereo sound, six for 5.1, etc.)</p>\n<p>The sample rate is the number of those samples (or frames, since all samples of a frame play at the same time) that will play in one second, measured in Hz. The higher the sample rate, the better the sound quality.</p>\n<p>Let's look at a Mono and a Stereo audio buffer, each is one second long, and playing at 44100Hz:</p>\n<ul>\n<li>The Mono buffer will have 44100 samples, and 44100 frames. The <code class=\"language-text\">length</code> property will be 44100.</li>\n<li>The Stereo buffer will have 88200 samples, but still 44100 frames. The <code class=\"language-text\">length</code> property will still be 44100 since it's equal to the number of frames.</li>\n</ul>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API/sampleframe-english.png\" alt=\"A diagram showing several frames in an audio buffer in a long line, each one containing two samples, as the buffer has two channels, it is stereo.\"></p>\n<p>When a buffer plays, you will hear the left most sample frame, and then the one right next to it, etc. In the case of stereo, you will hear both channels at the same time. Sample frames are very useful, because they are independent of the number of channels, and represent time, in a useful way for doing precise audio manipulation.</p>\n<p><strong>Note:</strong> To get a time in seconds from a frame count, divide the number of frames by the sample rate. To get a number of frames from a number of samples, divide by the channel count.</p>\n<p>Here's a couple of simple examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var context = new AudioContext();\nvar buffer = context.createBuffer(2, 22050, 44100);</code></pre></div>\n<p><strong>Note:</strong> In <a href=\"https://en.wikipedia.org/wiki/Digital_audio\" title=\"Digital audio\">digital audio</a>, <strong>44,100 <a href=\"https://en.wikipedia.org/wiki/Hertz\">Hz</a></strong> (alternately represented as <strong>44.1 kHz</strong>) is a common <a href=\"https://en.wikipedia.org/wiki/Sampling_frequency\" title=\"Sampling frequency\">sampling frequency</a>. Why 44.1kHz?</p>\n<p>Firstly, because the <a href=\"https://en.wikipedia.org/wiki/Hearing_range\" title=\"Hearing range\">hearing range</a> of human ears is roughly 20 Hz to 20,000 Hz. Via the <a href=\"https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem\" title=\"Nyquist--Shannon sampling theorem\">Nyquist--Shannon sampling theorem</a>, the sampling frequency must be greater than twice the maximum frequency one wishes to reproduce. Therefore, the sampling rate has to be greater than 40 kHz.</p>\n<p>Secondly, signals must be <a href=\"https://en.wikipedia.org/wiki/Low-pass_filter\" title=\"Low-pass filter\">low-pass filtered</a> before sampling, otherwise <a href=\"https://en.wikipedia.org/wiki/Aliasing\">aliasing</a> occurs. While an ideal low-pass filter would perfectly pass frequencies below 20 kHz (without attenuating them) and perfectly cut off frequencies above 20 kHz, in practice a <a href=\"https://en.wikipedia.org/wiki/Transition_band\" title=\"Transition band\">transition band</a> is necessary, where frequencies are partly attenuated. The wider this transition band is, the easier and more economical it is to make an <a href=\"https://en.wikipedia.org/wiki/Anti-aliasing_filter\" title=\"Anti-aliasing filter\">anti-aliasing filter</a>. The 44.1 kHz sampling frequency allows for a 2.05 kHz transition band.</p>\n<p>If you use this call above, you will get a stereo buffer with two channels, that when played back on an AudioContext running at 44100Hz (very common, most normal sound cards run at this rate), will last for 0.5 seconds: 22050 frames/44100Hz = 0.5 seconds.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var context = new AudioContext();\nvar buffer = context.createBuffer(1, 22050, 22050);</code></pre></div>\n<p>If you use this call, you will get a mono buffer with just one channel), that when played back on an AudioContext running at 44100Hz, will be automatically <em>resampled</em> to 44100Hz (and therefore yield 44100 frames), and last for 1.0 second: 44100 frames/44100Hz = 1 second.</p>\n<p><strong>Note:</strong> Audio resampling is very similar to image resizing. Say you've got a 16 x 16 image, but you want it to fill a 32x32 area. You resize (or resample) it. The result has less quality (it can be blurry or edgy, depending on the resizing algorithm), but it works, with the resized image taking up less space. Resampled audio is exactly the same: you save space, but in practice you will be unable to properly reproduce high frequency content, or treble sound.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#planar_versus_interleaved_buffers\" title=\"Permalink to Planar versus interleaved buffers\">Planar versus interleaved buffers</a></h3>\n<p>The Web Audio API uses a planar buffer format. The left and right channels are stored like this:</p>\n<p>LLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRR (for a buffer of 16 frames)</p>\n<p>This is very common in audio processing: it makes it easy to process each channel independently.</p>\n<p>The alternative is to use an interleaved buffer format:</p>\n<p>LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR (for a buffer of 16 frames)</p>\n<p>This format is very common for storing and playing back audio without much processing, for example a decoded MP3 stream.</p>\n<p>The Web Audio API exposes <strong>only</strong> planar buffers, because it's made for processing. It works with planar, but converts the audio to interleaved when it is sent to the sound card for playback. Conversely, when an MP3 is decoded, it starts off in interleaved format, but is converted to planar for processing.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#audio_channels\" title=\"Permalink to Audio channels\">Audio channels</a></h2>\n<p>Different audio buffers contain different numbers of channels: from the more basic mono (only one channel) and stereo (left and right channels), to more complex sets like quad and 5.1, which have different sound samples contained in each channel, leading to a richer sound experience. The channels are usually represented by standard abbreviations detailed in the table below:</p>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Channels</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><em>Mono</em></td>\n<td><code class=\"language-text\">0: M: mono</code></td>\n</tr>\n<tr>\n<td><em>Stereo</em></td>\n<td><code class=\"language-text\">0: L: left 1: R: right</code></td>\n</tr>\n<tr>\n<td><em>Quad</em></td>\n<td><code class=\"language-text\">0: L: left 1: R: right 2: SL: surround left 3: SR: surround right</code></td>\n</tr>\n<tr>\n<td><em>5.1</em></td>\n<td><code class=\"language-text\">0: L: left 1: R: right 2: C: center 3: LFE: subwoofer 4: SL: surround left 5: SR: surround right</code></td>\n</tr>\n</tbody>\n</table>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API#up-mixing_and_down-mixing\" title=\"Permalink to Up-mixing and down-mixing\">Up-mixing and down-mixing</a></h3>\n<p>When the number of channels doesn't match between an input and an output, up- or down-mixing happens according the following rules. This can be somewhat controlled by setting the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode/channelInterpretation\"><code class=\"language-text\">AudioNode.channelInterpretation</code></a> property to <code class=\"language-text\">speakers</code> or <code class=\"language-text\">discrete</code>:</p>\n<h1>Web Audio API</h1>\n<p>The Web Audio API provides a powerful and versatile system for controlling audio on the Web, allowing developers to choose audio sources, add effects to audio, create audio visualizations, apply spatial effects (such as panning) and much more.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#web_audio_concepts_and_usage\" title=\"Permalink to Web audio concepts and usage\">Web audio concepts and usage</a></h2>\n<p>The Web Audio API involves handling audio operations inside an <strong>audio context</strong>, and has been designed to allow <strong>modular routing</strong>. Basic audio operations are performed with <strong>audio nodes</strong>, which are linked together to form an <strong>audio routing graph</strong>. Several sources --- with different types of channel layout --- are supported even within a single context. This modular design provides the flexibility to create complex audio functions with dynamic effects.</p>\n<p>Audio nodes are linked into chains and simple webs by their inputs and outputs. They typically start with one or more sources. Sources provide arrays of sound intensities (samples) at very small timeslices, often tens of thousands of them per second. These could be either computed mathematically (such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode\"><code class=\"language-text\">OscillatorNode</code></a>), or they can be recordings from sound/video files (like <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode\"><code class=\"language-text\">AudioBufferSourceNode</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaElementAudioSourceNode\"><code class=\"language-text\">MediaElementAudioSourceNode</code></a>) and audio streams (<a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioSourceNode\"><code class=\"language-text\">MediaStreamAudioSourceNode</code></a>). In fact, sound files are just recordings of sound intensities themselves, which come in from microphones or electric instruments, and get mixed down into a single, complicated wave.</p>\n<p>Outputs of these nodes could be linked to inputs of others, which mix or modify these streams of sound samples into different streams. A common modification is multiplying the samples by a value to make them louder or quieter (as is the case with <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GainNode\"><code class=\"language-text\">GainNode</code></a>). Once the sound has been sufficiently processed for the intended effect, it can be linked to the input of a destination (<a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/destination\"><code class=\"language-text\">BaseAudioContext.destination</code></a>), which sends the sound to the speakers or headphones. This last connection is only necessary if the user is supposed to hear the audio.</p>\n<p>A simple, typical workflow for web audio would look something like this:</p>\n<ol>\n<li>Create audio context</li>\n<li>Inside the context, create sources --- such as <code class=\"language-text\">&lt;audio></code>, oscillator, stream</li>\n<li>Create effects nodes, such as reverb, biquad filter, panner, compressor</li>\n<li>Choose final destination of audio, for example your system speakers</li>\n<li>Connect the sources up to the effects, and the effects to the destination.</li>\n</ol>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/audio-context_.png\" alt=\"A simple box diagram with an outer box labeled Audio context, and three inner boxes labeled Sources, Effects and Destination. The three inner boxes have arrows between them pointing from left to right, indicating the flow of audio information.\"></p>\n<p>Timing is controlled with high precision and low latency, allowing developers to write code that responds accurately to events and is able to target specific samples, even at a high sample rate. So applications such as drum machines and sequencers are well within reach.</p>\n<p>The Web Audio API also allows us to control how audio is <em>spatialized</em>. Using a system based on a <em>source-listener model</em>, it allows control of the <em>panning model</em> and deals with <em>distance-induced attenuation</em> induced by a moving source (or moving listener).</p>\n<p><strong>Note:</strong> You can read about the theory of the Web Audio API in a lot more detail in our article <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API\">Basic concepts behind Web Audio API</a>.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#web_audio_api_target_audience\" title=\"Permalink to Web Audio API target audience\">Web Audio API target audience</a></h2>\n<p>The Web Audio API can seem intimidating to those that aren't familiar with audio or music terms, and as it incorporates a great deal of functionality it can prove difficult to get started if you are a developer.</p>\n<p>It can be used to incorporate audio into your website or application, by <a href=\"https://www.futurelibrary.no/\">providing atmosphere like futurelibrary.no</a>, or <a href=\"https://css-tricks.com/form-validation-web-audio/\">auditory feedback on forms</a>. However, it can also be used to create <em>advanced</em> interactive instruments. With that in mind, it is suitable for both developers and musicians alike.</p>\n<p>We have a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API\">simple introductory tutorial</a> for those that are familiar with programming but need a good introduction to some of the terms and structure of the API.</p>\n<p>There's also a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API\">Basic Concepts Behind Web Audio API</a> article, to help you understand the way digital audio works, specifically in the realm of the API. This also includes a good introduction to some of the concepts the API is built upon.</p>\n<p>Learning coding is like playing cards --- you learn the rules, then you play, then you go back and learn the rules again, then you play again. So if some of the theory doesn't quite fit after the first tutorial and article, there's an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Advanced_techniques\">advanced tutorial</a> which extends the first one to help you practice what you've learnt, and apply some more advanced techniques to build up a step sequencer.</p>\n<p>We also have other tutorials and comprehensive reference material available that covers all features of the API. See the sidebar on this page for more.</p>\n<p>If you are more familiar with the musical side of things, are familiar with music theory concepts, want to start building instruments, then you can go ahead and start building things with the advanced tutorial and others as a guide (the above-linked tutorial covers scheduling notes, creating bespoke oscillators and envelopes, as well as an LFO among other things.)</p>\n<p>If you aren't familiar with the programming basics, you might want to consult some beginner's JavaScript tutorials first and then come back here --- see our <a href=\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript\">Beginner's JavaScript learning module</a> for a great place to begin.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#web_audio_api_interfaces\" title=\"Permalink to Web Audio API interfaces\">Web Audio API interfaces</a></h2>\n<p>The Web Audio API has a number of interfaces and associated events, which we have split up into nine categories of functionality.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#general_audio_graph_definition\" title=\"Permalink to General audio graph definition\">General audio graph definition</a></h3>\n<p>General containers and definitions that shape audio graphs in Web Audio API usage.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioContext\"><code class=\"language-text\">AudioContext</code></a></p>\n<p>The <strong><code class=\"language-text\">AudioContext</code></strong> interface represents an audio-processing graph built from audio modules linked together, each represented by an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a>. An audio context controls the creation of the nodes it contains and the execution of the audio processing, or decoding. You need to create an <code class=\"language-text\">AudioContext</code> before you do anything else, as everything happens inside a context.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a></p>\n<p>The <strong><code class=\"language-text\">AudioNode</code></strong> interface represents an audio-processing module like an <em>audio source</em> (e.g. an HTML <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio\"><code class=\"language-text\">&lt;audio></code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a> element), <em>audio destination</em>, <em>intermediate processing module</em> (e.g. a filter like <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode\"><code class=\"language-text\">BiquadFilterNode</code></a>, or <em>volume control</em> like <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GainNode\"><code class=\"language-text\">GainNode</code></a>).</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioParam\"><code class=\"language-text\">AudioParam</code></a></p>\n<p>The <strong><code class=\"language-text\">AudioParam</code></strong> interface represents an audio-related parameter, like one of an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a>. It can be set to a specific value or a change in value, and can be scheduled to happen at a specific time and following a specific pattern.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioParamMap\"><code class=\"language-text\">AudioParamMap</code></a></p>\n<p>Provides a maplike interface to a group of <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioParam\"><code class=\"language-text\">AudioParam</code></a> interfaces, which means it provides the methods <code class=\"language-text\">forEach()</code>, <code class=\"language-text\">get()</code>, <code class=\"language-text\">has()</code>, <code class=\"language-text\">keys()</code>, and <code class=\"language-text\">values()</code>, as well as a <code class=\"language-text\">size</code> property.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext\"><code class=\"language-text\">BaseAudioContext</code></a></p>\n<p>The <strong><code class=\"language-text\">BaseAudioContext</code></strong> interface acts as a base definition for online and offline audio-processing graphs, as represented by <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioContext\"><code class=\"language-text\">AudioContext</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext\"><code class=\"language-text\">OfflineAudioContext</code></a> respectively. You wouldn't use <code class=\"language-text\">BaseAudioContext</code> directly --- you'd use its features via one of these two inheriting interfaces.</p>\n<p>The <code class=\"language-text\">[ended](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/ended_event \"/en-US/docs/Web/Events/ended\")</code> event</p>\n<p>The <code class=\"language-text\">ended</code> event is fired when playback has stopped because the end of the media was reached.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#defining_audio_sources\" title=\"Permalink to Defining audio sources\">Defining audio sources</a></h3>\n<p>Interfaces that define audio sources for use in the Web Audio API.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioScheduledSourceNode\"><code class=\"language-text\">AudioScheduledSourceNode</code></a></p>\n<p>The <strong><code class=\"language-text\">AudioScheduledSourceNode</code></strong> is a parent interface for several types of audio source node interfaces. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a>.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode\"><code class=\"language-text\">OscillatorNode</code></a></p>\n<p>The <strong><code class=\"language-text\">OscillatorNode</code></strong> interface represents a periodic waveform, such as a sine or triangle wave. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> audio-processing module that causes a given <em>frequency</em> of wave to be created.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer\"><code class=\"language-text\">AudioBuffer</code></a></p>\n<p>The <strong><code class=\"language-text\">AudioBuffer</code></strong> interface represents a short audio asset residing in memory, created from an audio file using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/decodeAudioData\"><code class=\"language-text\">BaseAudioContext.decodeAudioData</code></a> method, or created with raw data using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/createBuffer\"><code class=\"language-text\">BaseAudioContext.createBuffer</code></a>. Once decoded into this form, the audio can then be put into an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode\"><code class=\"language-text\">AudioBufferSourceNode</code></a>.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode\"><code class=\"language-text\">AudioBufferSourceNode</code></a></p>\n<p>The <strong><code class=\"language-text\">AudioBufferSourceNode</code></strong> interface represents an audio source consisting of in-memory audio data, stored in an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer\"><code class=\"language-text\">AudioBuffer</code></a>. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> that acts as an audio source.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaElementAudioSourceNode\"><code class=\"language-text\">MediaElementAudioSourceNode</code></a></p>\n<p>The <strong><code class=\"language-text\">MediaElementAudioSourceNode</code></strong> interface represents an audio source consisting of an HTML5 <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio\"><code class=\"language-text\">&lt;audio></code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a> element. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> that acts as an audio source.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioSourceNode\"><code class=\"language-text\">MediaStreamAudioSourceNode</code></a></p>\n<p>The <strong><code class=\"language-text\">MediaStreamAudioSourceNode</code></strong> interface represents an audio source consisting of a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStream\"><code class=\"language-text\">MediaStream</code></a> (such as a webcam, microphone, or a stream being sent from a remote computer). If multiple audio tracks are present on the stream, the track whose <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/id\" title=\"id\"><code class=\"language-text\">id</code></a> comes first lexicographically (alphabetically) is used. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> that acts as an audio source.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackAudioSourceNode\"><code class=\"language-text\">MediaStreamTrackAudioSourceNode</code></a></p>\n<p>A node of type <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackAudioSourceNode\"><code class=\"language-text\">MediaStreamTrackAudioSourceNode</code></a> represents an audio source whose data comes from a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack\"><code class=\"language-text\">MediaStreamTrack</code></a>. When creating the node using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaStreamTrackSource\" title=\"createMediaStreamTrackSource()\"><code class=\"language-text\">createMediaStreamTrackSource()</code></a> method to create the node, you specify which track to use. This provides more control than <code class=\"language-text\">MediaStreamAudioSourceNode</code>.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#defining_audio_effects_filters\" title=\"Permalink to Defining audio effects filters\">Defining audio effects filters</a></h3>\n<p>Interfaces for defining effects that you want to apply to your audio sources.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode\"><code class=\"language-text\">BiquadFilterNode</code></a></p>\n<p>The <strong><code class=\"language-text\">BiquadFilterNode</code></strong> interface represents a simple low-order filter. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> that can represent different kinds of filters, tone control devices, or graphic equalizers. A <code class=\"language-text\">BiquadFilterNode</code> always has exactly one input and one output.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ConvolverNode\"><code class=\"language-text\">ConvolverNode</code></a></p>\n<p>The <strong><code class=\"language-text\">ConvolverNode</code></strong> interface is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> that performs a Linear Convolution on a given <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer\"><code class=\"language-text\">AudioBuffer</code></a>, and is often used to achieve a reverb effect.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DelayNode\"><code class=\"language-text\">DelayNode</code></a></p>\n<p>The <strong><code class=\"language-text\">DelayNode</code></strong> interface represents a <a href=\"https://en.wikipedia.org/wiki/Digital_delay_line\">delay-line</a>; an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> audio-processing module that causes a delay between the arrival of an input data and its propagation to the output.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DynamicsCompressorNode\"><code class=\"language-text\">DynamicsCompressorNode</code></a></p>\n<p>The <strong><code class=\"language-text\">DynamicsCompressorNode</code></strong> interface provides a compression effect, which lowers the volume of the loudest parts of the signal in order to help prevent clipping and distortion that can occur when multiple sounds are played and multiplexed together at once.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GainNode\"><code class=\"language-text\">GainNode</code></a></p>\n<p>The <strong><code class=\"language-text\">GainNode</code></strong> interface represents a change in volume. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> audio-processing module that causes a given <em>gain</em> to be applied to the input data before its propagation to the output.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WaveShaperNode\"><code class=\"language-text\">WaveShaperNode</code></a></p>\n<p>The <strong><code class=\"language-text\">WaveShaperNode</code></strong> interface represents a non-linear distorter. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> that use a curve to apply a waveshaping distortion to the signal. Beside obvious distortion effects, it is often used to add a warm feeling to the signal.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PeriodicWave\"><code class=\"language-text\">PeriodicWave</code></a></p>\n<p>Describes a periodic waveform that can be used to shape the output of an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode\"><code class=\"language-text\">OscillatorNode</code></a>.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IIRFilterNode\"><code class=\"language-text\">IIRFilterNode</code></a></p>\n<p>Implements a general <strong><a href=\"https://en.wikipedia.org/wiki/infinite%20impulse%20response\" title=\"infinite impulse response\">infinite impulse response</a></strong> (IIR) filter; this type of filter can be used to implement tone control devices and graphic equalizers as well.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#defining_audio_destinations\" title=\"Permalink to Defining audio destinations\">Defining audio destinations</a></h3>\n<p>Once you are done processing your audio, these interfaces define where to output it.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioDestinationNode\"><code class=\"language-text\">AudioDestinationNode</code></a></p>\n<p>The <strong><code class=\"language-text\">AudioDestinationNode</code></strong> interface represents the end destination of an audio source in a given context --- usually the speakers of your device.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioDestinationNode\"><code class=\"language-text\">MediaStreamAudioDestinationNode</code></a></p>\n<p>The <strong><code class=\"language-text\">MediaStreamAudioDestinationNode</code></strong> interface represents an audio destination consisting of a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API\">WebRTC</a> <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStream\"><code class=\"language-text\">MediaStream</code></a> with a single <code class=\"language-text\">AudioMediaStreamTrack</code>, which can be used in a similar way to a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStream\"><code class=\"language-text\">MediaStream</code></a> obtained from <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia\" title=\"getUserMedia()\"><code class=\"language-text\">getUserMedia()</code></a>. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> that acts as an audio destination.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#data_analysis_and_visualization\" title=\"Permalink to Data analysis and visualization\">Data analysis and visualization</a></h3>\n<p>If you want to extract time, frequency, and other data from your audio, the <code class=\"language-text\">AnalyserNode</code> is what you need.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode\"><code class=\"language-text\">AnalyserNode</code></a></p>\n<p>The <strong><code class=\"language-text\">AnalyserNode</code></strong> interface represents a node able to provide real-time frequency and time-domain analysis information, for the purposes of data analysis and visualization.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#splitting_and_merging_audio_channels\" title=\"Permalink to Splitting and merging audio channels\">Splitting and merging audio channels</a></h3>\n<p>To split and merge audio channels, you'll use these interfaces.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ChannelSplitterNode\"><code class=\"language-text\">ChannelSplitterNode</code></a></p>\n<p>The <strong><code class=\"language-text\">ChannelSplitterNode</code></strong> interface separates the different channels of an audio source out into a set of <em>mono</em> outputs.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ChannelMergerNode\"><code class=\"language-text\">ChannelMergerNode</code></a></p>\n<p>The <strong><code class=\"language-text\">ChannelMergerNode</code></strong> interface reunites different mono inputs into a single output. Each input will be used to fill a channel of the output.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#audio_spatialization\" title=\"Permalink to Audio spatialization\">Audio spatialization</a></h3>\n<p>These interfaces allow you to add audio spatialization panning effects to your audio sources.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioListener\"><code class=\"language-text\">AudioListener</code></a></p>\n<p>The <strong><code class=\"language-text\">AudioListener</code></strong> interface represents the position and orientation of the unique person listening to the audio scene used in audio spatialization.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PannerNode\"><code class=\"language-text\">PannerNode</code></a></p>\n<p>The <strong><code class=\"language-text\">PannerNode</code></strong> interface represents the position and behavior of an audio source signal in 3D space, allowing you to create complex panning effects.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StereoPannerNode\"><code class=\"language-text\">StereoPannerNode</code></a></p>\n<p>The <strong><code class=\"language-text\">StereoPannerNode</code></strong> interface represents a simple stereo panner node that can be used to pan an audio stream left or right.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#audio_processing_in_javascript\" title=\"Permalink to Audio processing in JavaScript\">Audio processing in JavaScript</a></h3>\n<p>Using audio worklets, you can define custom audio nodes written in JavaScript or <a href=\"https://developer.mozilla.org/en-US/docs/WebAssembly\">WebAssembly</a>. Audio worklets implement the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Worklet\"><code class=\"language-text\">Worklet</code></a> interface, a lightweight version of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Worker\"><code class=\"language-text\">Worker</code></a> interface.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet\"><code class=\"language-text\">AudioWorklet</code></a></p>\n<p>The <code class=\"language-text\">AudioWorklet</code> interface is available through the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioContext\"><code class=\"language-text\">AudioContext</code></a> object's <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext/audioWorklet\" title=\"audioWorklet\"><code class=\"language-text\">audioWorklet</code></a>, and lets you add modules to the audio worklet to be executed off the main thread.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletNode\"><code class=\"language-text\">AudioWorkletNode</code></a></p>\n<p>The <code class=\"language-text\">AudioWorkletNode</code> interface represents an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> that is embedded into an audio graph and can pass messages to the corresponding <code class=\"language-text\">AudioWorkletProcessor</code>.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor\"><code class=\"language-text\">AudioWorkletProcessor</code></a></p>\n<p>The <code class=\"language-text\">AudioWorkletProcessor</code> interface represents audio processing code running in a <code class=\"language-text\">AudioWorkletGlobalScope</code> that generates, processes, or analyses audio directly, and can pass messages to the corresponding <code class=\"language-text\">AudioWorkletNode</code>.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletGlobalScope\"><code class=\"language-text\">AudioWorkletGlobalScope</code></a></p>\n<p>The <code class=\"language-text\">AudioWorkletGlobalScope</code> interface is a <code class=\"language-text\">WorkletGlobalScope</code>-derived object representing a worker context in which an audio processing script is run; it is designed to enable the generation, processing, and analysis of audio data directly using JavaScript in a worklet thread rather than on the main thread.</p>\n<h4>Obsolete: script processor nodes</h4>\n<p>Before audio worklets were defined, the Web Audio API used the <code class=\"language-text\">ScriptProcessorNode</code> for JavaScript-based audio processing. Because the code runs in the main thread, they have bad performance. The <code class=\"language-text\">ScriptProcessorNode</code> is kept for historic reasons but is marked as deprecated.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode\"><code class=\"language-text\">ScriptProcessorNode</code></a></p>\n<p>The <strong><code class=\"language-text\">ScriptProcessorNode</code></strong> interface allows the generation, processing, or analyzing of audio using JavaScript. It is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a> audio-processing module that is linked to two buffers, one containing the current input, one containing the output. An event, implementing the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioProcessingEvent\"><code class=\"language-text\">AudioProcessingEvent</code></a> interface, is sent to the object each time the input buffer contains new data, and the event handler terminates when it has filled the output buffer with data.</p>\n<p><code class=\"language-text\">[audioprocess](https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode/audioprocess_event \"/en-US/docs/Web/Events/audioprocess\")</code> (event)</p>\n<p>The <code class=\"language-text\">audioprocess</code> event is fired when an input buffer of a Web Audio API <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode\"><code class=\"language-text\">ScriptProcessorNode</code></a> is ready to be processed.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioProcessingEvent\"><code class=\"language-text\">AudioProcessingEvent</code></a></p>\n<p>The <code class=\"language-text\">AudioProcessingEvent</code> represents events that occur when a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode\"><code class=\"language-text\">ScriptProcessorNode</code></a> input buffer is ready to be processed.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#offlinebackground_audio_processing\" title=\"Permalink to Offline/background audio processing\">Offline/background audio processing</a></h3>\n<p>It is possible to process/render an audio graph very quickly in the background --- rendering it to an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer\"><code class=\"language-text\">AudioBuffer</code></a> rather than to the device's speakers --- with the following.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext\"><code class=\"language-text\">OfflineAudioContext</code></a></p>\n<p>The <strong><code class=\"language-text\">OfflineAudioContext</code></strong> interface is an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioContext\"><code class=\"language-text\">AudioContext</code></a> interface representing an audio-processing graph built from linked together <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a>s. In contrast with a standard <code class=\"language-text\">AudioContext</code>, an <code class=\"language-text\">OfflineAudioContext</code> doesn't really render the audio but rather generates it, <em>as fast as it can</em>, in a buffer.</p>\n<p><code class=\"language-text\">[complete](https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext/complete_event \"/en-US/docs/Web/Events/complete\")</code> (event)</p>\n<p>The <code class=\"language-text\">complete</code> event is fired when the rendering of an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext\"><code class=\"language-text\">OfflineAudioContext</code></a> is terminated.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioCompletionEvent\"><code class=\"language-text\">OfflineAudioCompletionEvent</code></a></p>\n<p>The <code class=\"language-text\">OfflineAudioCompletionEvent</code> represents events that occur when the processing of an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext\"><code class=\"language-text\">OfflineAudioContext</code></a> is terminated. The <code class=\"language-text\">[complete](https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext/complete_event \"/en-US/docs/Web/Events/complete\")</code> event uses this interface.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#guides_and_tutorials\" title=\"Permalink to Guides and tutorials\">Guides and tutorials</a></h2>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Advanced_techniques\">Advanced techniques: Creating and sequencing audio</a></p>\n<p>In this tutorial, we're going to cover sound creation and modification, as well as timing and scheduling. We're going to introduce sample loading, envelopes, filters, wavetables, and frequency modulation. If you're familiar with these terms and you're looking for an introduction to their application within with the Web Audio API, you've come to the right place.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet\">Background audio processing using AudioWorklet</a></p>\n<p>This article explains how to create an audio worklet processor and use it in a Web Audio application.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Basic_concepts_behind_Web_Audio_API\">Basic concepts behind Web Audio API</a></p>\n<p>This article explains some of the audio theory behind how the features of the Web Audio API work, to help you make informed decisions while designing how audio is routed through your app.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Controlling_multiple_parameters_with_ConstantSourceNode\">Controlling multiple parameters with ConstantSourceNode</a></p>\n<p>This article demonstrates how to use a <code class=\"language-text\">ConstantSourceNode</code> to link multiple parameters together so they share the same value, which can be changed by setting the value of the <code class=\"language-text\">ConstantSourceNode.offset</code> parameter.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Simple_synth\">Example and tutorial: Simple synth keyboard</a></p>\n<p>This article presents the code and working demo of a video keyboard you can play using the mouse. The keyboard allows you to switch among the standard waveforms as well as one custom waveform, and you can control the main gain using a volume slider beneath the keyboard. This example makes use of the following Web API interfaces: <code class=\"language-text\">AudioContext</code>, <code class=\"language-text\">OscillatorNode</code>, <code class=\"language-text\">PeriodicWave</code>, and <code class=\"language-text\">GainNode</code>.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Migrating_from_webkitAudioContext\">Migrating from webkitAudioContext</a></p>\n<p>In this article, we cover the differences in Web Audio API since it was first implemented in WebKit and how to update your code to use the modern Web Audio API.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Tools\">Tools for analyzing Web Audio usage</a></p>\n<p>While working on your Web Audio API code, you may find that you need tools to analyze the graph of nodes you create or to otherwise debug your work. This article discusses tools available to help you do that.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_IIR_filters\">Using IIR filters</a></p>\n<p>The <strong><code class=\"language-text\">IIRFilterNode</code></strong> interface of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API\">Web Audio API</a> is an <code class=\"language-text\">AudioNode</code> processor that implements a general <a href=\"https://en.wikipedia.org/wiki/infinite%20impulse%20response\">infinite impulse response</a> (IIR) filter; this type of filter can be used to implement tone control devices and graphic equalizers, and the filter response parameters can be specified, so that it can be tuned as needed. This article looks at how to implement one, and use it in a simple example.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API\">Using the Web Audio API</a></p>\n<p>Let's take a look at getting started with the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API\">Web Audio API</a>. We'll briefly look at some concepts, then study a simple boombox example that allows us to load an audio track, play and pause it, and change its volume and stereo panning.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Visualizations_with_Web_Audio_API\">Visualizations with Web Audio API</a></p>\n<p>One of the most interesting features of the Web Audio API is the ability to extract frequency, waveform, and other data from your audio source, which can then be used to create visualizations. This article explains how, and provides a couple of basic use cases.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Best_practices\">Web Audio API best practices</a></p>\n<p>There's no strict right or wrong way when writing creative code. As long as you consider security, performance, and accessibility, you can adapt to your own style. In this article, we'll share a number of <em>best practices</em> --- guidelines, tips, and tricks for working with the Web Audio API.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Web_audio_spatialization_basics\">Web audio spatialization basics</a></p>\n<p>As if its extensive variety of sound processing (and other) options wasn't enough, the Web Audio API also includes facilities to allow you to emulate the difference in sound as a listener moves around a sound source, for example panning as you move around a sound source inside a 3D game. The official term for this is <strong>spatialization</strong>, and this article will cover the basics of how to implement such a system.</p>"},{"url":"/docs/audio/dtw-python-explained/","relativePath":"docs/audio/dtw-python-explained.md","relativeDir":"docs/audio","base":"dtw-python-explained.md","name":"dtw-python-explained","frontmatter":{"title":"Dynamic Time Warping Algorithm Explained (Python)","weight":0,"excerpt":"Dynamic Time Warping Algorithm Explained (Python)","seo":{"title":"Dynamic Time Warping Algorithm","description":"Algorithm explained in python programming language","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Dynamic Time Warping Algorithm Explained (Python)</h1>\n<p>In this world which is getting dominated by Internet of Things (IoT), there is an increasing need to understand signals from devices installed in households, shopping malls, factories and offices. For example, any voice assistant detects, authenticates and interprets commands from humans even if it is slow or fast. Our voice tone tends to be different during different times of the day. In the early morning after we get up from bed, we interact with a slower, heavier and lazier tone compared to other times of the day. These devices treat the signals as time series and compare the peaks, troughs and slopes by taking into account the varying lags and phases in the signals to come up with a similarity score. One of the most common algorithms used to accomplish this is <em>Dynamic Time Warping (DTW)</em>. It is a very robust technique to compare two or more Time Series by ignoring any shifts and speed.</p>\n<p>As part of Walmart Real Estate team, I am working on understanding the energy consumption pattern of different assets like refrigeration units, dehumidifiers, lighting, etc. installed in the retail stores.This will help in improving quality of data collected from IoT sensors, detect and prevent faults in the systems and improve energy consumption forecasting and planning. This analysis involves time series of energy consumption during different times of a day i.e. different days of a week, weeks of a month and months of a year. Time series forecasting often gives bad predictions when there is sudden shift in phase of the energy consumption due to unknown factors. For example if the defrost schedule, items refresh routine for a refrigeration unit, or weather changes suddenly and are not captured to explain the phase shifts of energy consumption, it is important to detect these change points.</p>\n<p>In the example below, the items refresh routine of a store has shifted by 2 hours on Tuesday leading the shift in peak energy consumption of refrigeration units and this information was not available to us for many such stores.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*WEe7LQivzU4YOvDCe0_P_A.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*WEe7LQivzU4YOvDCe0_P_A.png\" alt=\"medium blog image\"></p>\n<p>The peak at 2 am got shifted to 4 am. DTW when run recursively for consecutive days can identify the cases for which phase shift occurred without much change in shape of signals.</p>\n<p><img src=\"https://miro.medium.com/max/52/1*jDuu7XE8XitCTBSythQICw.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*jDuu7XE8XitCTBSythQICw.png\" alt=\"medium blog image\"></p>\n<p>The training data can be restricted to Tuesday onwards to improve the prediction of energy consumption in future in this case as phase shift was detected on Tuesday. The setup improved the predictions substantially ( > 50%) for the stores for which the reason of shift was not known. This was not possible by traditional ways of one to one comparison of signals.</p>\n<p>In this blog, I will explain how DTW algorithm works and throw some light on the calculation of the similarity score between two time series and its implementation in python. Most of the contents in this blog have been sourced from this <a href=\"https://ieeexplore.ieee.org/document/1163055\">paper</a>, also mentioned in the references section below.</p>\n<p>2. Why do we need DTW ?</p>\n<p>Any two time series can be compared using euclidean distance or other similar distances on a one to one basis on time axis. The amplitude of first time series at time T will be compared with amplitude of second time series at time T. This will result into a very poor comparison and similarity score even if the two time series are very similar in shape but out of phase in time.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*HQleh0-1HlGsLkVlcaFRLw.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*HQleh0-1HlGsLkVlcaFRLw.png\" alt=\"medium blog image\"></p>\n<p>DTW compares amplitude of first signal at time T with amplitude of second signal at time T+1 and T-1 or T+2 and T-2. This makes sure it does not give low similarity score for signals with similar shape and different phase.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*6Yzt8SiQ-kTRx8pFqDZXkw.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*6Yzt8SiQ-kTRx8pFqDZXkw.png\" alt=\"medium blog image\"></p>\n<ol start=\"3\">\n<li>How it works?</li>\n</ol>\n<p>Let us take two time series signals P and Q</p>\n<p>Series 1 (P) : 1,4,5,10,9,3,2,6,8,4</p>\n<p>Series 2 (Q): 1,7,3,4,1,10,5,4,7,4</p>\n<p><img src=\"https://miro.medium.com/max/60/1*x8-vv9W3cfmdd0mW_1MLTg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*x8-vv9W3cfmdd0mW_1MLTg.png\" alt=\"medium blog image\"></p>\n<p><em>Step 1 :</em> Empty Cost Matrix Creation</p>\n<p>Create an empty cost matrix M with x and y labels as amplitudes of the two series to be compared.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*MrjHYFHyeeE3aiBEA-E5cw.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*MrjHYFHyeeE3aiBEA-E5cw.png\" alt=\"medium blog image\"></p>\n<p><em>Step 2: Cost Calculation</em></p>\n<p>Fill the cost matrix using the formula mentioned below starting from left and bottom corner.</p>\n<p>M(i, j) = |P(i) --- Q(j)| + min ( M(i-1,j-1), M(i, j-1), M(i-1,j) )</p>\n<p>where</p>\n<p>M is the matrix</p>\n<p>i is the iterator for series P</p>\n<p>j is the iterator for series Q</p>\n<p><img src=\"https://miro.medium.com/max/60/1*hhpagt7BEeFU22X83Q76yQ.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*hhpagt7BEeFU22X83Q76yQ.png\" alt=\"medium blog image\"></p>\n<p>Let us take few examples (11,3 and 8 ) to illustrate the calculation as highlighted in the below table.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*bHaMHM9eBfLc6q166iiI9g.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*bHaMHM9eBfLc6q166iiI9g.png\" alt=\"medium blog image\"></p>\n<p>for 11,</p>\n<p><img src=\"https://miro.medium.com/max/60/1*dzBbhICP6wqwtmW-GGwGmg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*dzBbhICP6wqwtmW-GGwGmg.png\" alt=\"medium blog image\"></p>\n<p>|10 --4| + min( 5, 12, 5 )</p>\n<p>= 6 + 5</p>\n<p>= 11</p>\n<p>Similarly for 3,</p>\n<p>|4 --1| + min( 0 )</p>\n<p>= 3+ 0</p>\n<p>= 3</p>\n<p>and for 8,</p>\n<p>|1 --3| + min( 6)</p>\n<p>= 2 + 6</p>\n<p>= 8</p>\n<p>The full table will look like this:</p>\n<p><img src=\"https://miro.medium.com/max/60/1*7pphf0WWYElhtohnQPFPNA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*7pphf0WWYElhtohnQPFPNA.png\" alt=\"medium blog image\"></p>\n<p><em>Step 3:</em> Warping Path Identification</p>\n<p>Identify the warping path starting from top right corner of the matrix and traversing to bottom left. The traversal path is identified based on the neighbour with minimum value.</p>\n<p>In our example it starts with 15 and looks for minimum value i.e. 15 among its neighbours 18, 15 and 18.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*p6hJxIcUjOzgpTINBHLdmQ.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*p6hJxIcUjOzgpTINBHLdmQ.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/60/1*RnqvEKdMmWklx5m59YiP3g.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*RnqvEKdMmWklx5m59YiP3g.png\" alt=\"medium blog image\"></p>\n<p>The next number in the warping traversal path is 14. This process continues till we reach the bottom or the left axis of the table.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*mjtlGiB44Zz2pALmMiYNLQ.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*mjtlGiB44Zz2pALmMiYNLQ.png\" alt=\"medium blog image\"></p>\n<p>The final path will look like this:</p>\n<p><img src=\"https://miro.medium.com/max/60/1*WaC_xFSpJi-2GlF7OG37CA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*WaC_xFSpJi-2GlF7OG37CA.png\" alt=\"medium blog image\"></p>\n<p>Let this warping path series be called as d.</p>\n<p>d = [15,15,14,13,11,9,8,8,4,4,3,0]</p>\n<p><em>Step 4:</em> Final Distance Calculation</p>\n<p>Time normalised distance , D</p>\n<p><img src=\"https://miro.medium.com/max/60/1*6M_cotyKNao7xo03zsMLZQ.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/385/1*6M_cotyKNao7xo03zsMLZQ.png\" alt=\"medium blog image\"></p>\n<p>where k is the length of the series d.</p>\n<p>k = 12 in our case.</p>\n<p>D = ( 15 + 15 + 14 + 13 + 11 + 9 + 8 + 8 + 4 + 4 + 3 + 0 ) /12</p>\n<p>= 104/12</p>\n<p>= 8.63</p>\n<p>Let us take another example with two very similar time series with unit time shift difference.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*CLSlk3qD0Hil2H4XBBeE3Q.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*CLSlk3qD0Hil2H4XBBeE3Q.png\" alt=\"medium blog image\"></p>\n<p>Cost matrix and warping path will look like this.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*Wx823zTAqUkrSbX1ivMAlg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*Wx823zTAqUkrSbX1ivMAlg.png\" alt=\"medium blog image\"></p>\n<p>DTW distance ,D =</p>\n<p>( 0 + 0 + 0 + 0 + 0 +0 +0 +0 +0 +0 +0 ) /11</p>\n<p>= 0</p>\n<p>Zero DTW distance implies that the time series are very similar and that is indeed the case as observed in the plot.</p>\n<h1>Resummation (Spaced Repitition)</h1>\n<p>Dynamic Time Warping (DTW) is a way to compare two -usually temporal- sequences that do not sync up perfectly. It is a method to calculate the optimal matching between two sequences. DTW is useful in many domains such as speech recognition, data mining, financial markets, etc. It's commonly used in data mining to measure the distance between two time-series.</p>\n<p>In this post, we will go over the mathematics behind DTW. Then, two illustrative examples are provided to better understand the concept. If you are not interested in the math behind it, please jump to examples.</p>\n<h1>Formulation</h1>\n<p>Let's assume we have two sequences like the following:</p>\n<p><em>𝑋=𝑥[1], 𝑥[2], ..., x[i], ..., x[n]</em></p>\n<p><em>Y=y[1], y[2], ..., y[j], ..., y[m]</em></p>\n<p>The sequences 𝑋 and 𝑌 can be arranged to form an 𝑛-by-𝑚 grid, where each point (𝑖, j) is the alignment between 𝑥[𝑖] and 𝑦[𝑗].</p>\n<p>A warping path 𝑊 maps the elements of 𝑋 and 𝑌 to minimize the <em>distance</em> between them. 𝑊 is a sequence of grid points (𝑖, 𝑗). We will see an example of the warping path later.</p>\n<h2>Warping Path and DTW distance</h2>\n<p>The Optimal path to (𝑖<em>𝑘, 𝑗</em>𝑘) can be computed by:</p>\n<p><img src=\"https://miro.medium.com/max/60/1*8hJEJWuxrccwCMuUG_aPbQ.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*8hJEJWuxrccwCMuUG_aPbQ.png\" alt=\"medium blog image\"></p>\n<p>where 𝑑 is the Euclidean distance. Then, the overall path cost can be calculated as</p>\n<p><img src=\"https://miro.medium.com/max/60/1*2OGDOJ-a0zTO_9T1FIGejQ.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/272/1*2OGDOJ-a0zTO_9T1FIGejQ.png\" alt=\"medium blog image\"></p>\n<h1>Restrictions on the Warping function</h1>\n<p>The warping path is found using a dynamic programming approach to align two sequences. Going through all possible paths is \"combinatorically explosive\" [1]. Therefore, for efficiency purposes, it's important to limit the number of possible warping paths, and hence the following constraints are outlined:</p>\n<ul>\n<li>Boundary Condition: This constraint ensures that the warping path begins with the start points of both signals and terminates with their endpoints.</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*SHsmQu2TqpaDyIArn2snzg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/452/1*SHsmQu2TqpaDyIArn2snzg.png\" alt=\"medium blog image\"></p>\n<ul>\n<li>Monotonicity condition: This constraint preserves the time-order of points (not going back in time).</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*RNg2VENGaWoyvGrvyeg61A.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/311/1*RNg2VENGaWoyvGrvyeg61A.png\" alt=\"medium blog image\"></p>\n<ul>\n<li>Continuity (step size) condition: This constraint limits the path transitions to adjacent points in time (not jumping in time).</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*lU99pFyomdPeaHuR26bDyA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/418/1*lU99pFyomdPeaHuR26bDyA.png\" alt=\"medium blog image\"></p>\n<p>In addition to the above three constraints, there are other less frequent conditions for an allowable warping path:</p>\n<ul>\n<li>Warping window condition: Allowable points can be restricted to fall within a given warping window of width 𝜔 (a positive integer).</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*9apgwkXeU3gOHLudFsIosA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/168/1*9apgwkXeU3gOHLudFsIosA.png\" alt=\"medium blog image\"></p>\n<ul>\n<li>Slope condition: The warping path can be constrained by restricting the slope, and consequently avoiding extreme movements in one direction.</li>\n</ul>\n<p>An acceptable warping path has combinations of chess king moves that are:</p>\n<ul>\n<li>Horizontal moves: (𝑖, 𝑗) → (𝑖, 𝑗+1)</li>\n<li>Vertical moves: (𝑖, 𝑗) → (𝑖+1, 𝑗)</li>\n<li>Diagonal moves: (𝑖, 𝑗) → (𝑖+1, 𝑗+1)</li>\n</ul>\n<h1>Implementation</h1>\n<p>Let's import all python packages we need.</p>\n<p>import pandas as pd<br>\nimport numpy as np# Plotting Packages<br>\nimport matplotlib.pyplot as plt<br>\nimport seaborn as sbn# Configuring Matplotlib<br>\nimport matplotlib as mpl<br>\nmpl.rcParams['figure.dpi'] = 300<br>\nsavefig<em>options = dict(format=\"png\", dpi=300, bbox</em>inches=\"tight\")# Computation packages<br>\nfrom scipy.spatial.distance import euclidean<br>\nfrom fastdtw import fastdtw</p>\n<p>Let's define a method to compute the accumulated cost matrix <em>D</em> for the warp path. The cost matrix uses the Euclidean distance to calculate the distance between every two points. The methods to compute the Euclidean distance matrix and accumulated cost matrix are defined below:</p>\n<h1>Example 1</h1>\n<p>In this example, we have two sequences <em>x</em> and <em>y</em> with different lengths.</p>\n<h1>Create two sequences\\</h1>\n<p>x = [3, 1, 2, 2, 1]<br>\ny = [2, 0, 0, 3, 3, 1, 0]</p>\n<p>We cannot calculate the Euclidean distance between <em>x</em> and <em>y</em> since they don't have equal lengths.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*ADzLGLGGq13onO72EO_ZpQ.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*ADzLGLGGq13onO72EO_ZpQ.png\" alt=\"medium blog image\"></p>\n<p>Example 1: Euclidean distance between x and y (is it possible? 🤔) (Image by Author)</p>\n<h1>Compute DTW distance and warp path</h1>\n<p>Many Python packages calculate the DTW by just providing the sequences and the type of distance (usually Euclidean). Here, we use a popular Python implementation of DTW that is <a href=\"https://github.com/slaypni/fastdtw\">FastDTW</a> which is an approximate DTW algorithm with lower time and memory complexities [2].</p>\n<p>dtw<em>distance, warp</em>path = fastdtw(x, y, dist=euclidean)</p>\n<p>Note that we are using <a href=\"https://pypi.org/project/scipy/\">SciPy</a>'s distance function <em>Euclidean</em> that we imported earlier. For a better understanding of the warp path, let's first compute the accumulated cost matrix and then visualize the path on a grid. The following code will plot a heatmap of the accumulated cost matrix.</p>\n<p>cost<em>matrix = compute</em>accumulated<em>cost</em>matrix(x, y)</p>\n<p>Example 1: Python code to plot (and save) the heatmap of the accumulated cost matrix</p>\n<p><img src=\"https://miro.medium.com/max/54/1*PIKZAwsV15NBvqkh9N1KMg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/375/1*PIKZAwsV15NBvqkh9N1KMg.png\" alt=\"medium blog image\"></p>\n<p>Example 1: Accumulated cost matrix and warping path (Image by Author)</p>\n<p>The color bar shows the cost of each point in the grid. As can be seen, the warp path (blue line) is going through the lowest cost on the grid. Let's see the DTW distance and the warping path by printing these two variables.</p>\n<blockquote>\n<blockquote>\n<blockquote>\n<p>DTW distance: 6.0<br>\nWarp path: [(0, 0), (1, 1), (1, 2), (2, 3), (3, 4), (4, 5), (4, 6)]</p>\n</blockquote>\n</blockquote>\n</blockquote>\n<p>The warping path starts at point (0, 0) and ends at (4, 6) by 6 moves. Let's also calculate the accumulated cost most using the functions we defined earlier and compare the values with the heatmap.</p>\n<p>cost<em>matrix = compute</em>accumulated<em>cost</em>matrix(x, y)<br>\nprint(np.flipud(cost_matrix)) # Flipping the cost matrix for easier comparison with heatmap values!>>> [[32. 12. 10. 10.  6.]<br>\n[23. 11.  6.  6.  5.]<br>\n[19. 11.  5.  5.  9.]<br>\n[19.  7.  4.  5.  8.]<br>\n[19.  3.  6. 10.  4.]<br>\n[10.  2.  6.  6.  3.]<br>\n[ 1.  2.  2.  2.  3.]]</p>\n<p>The cost matrix is printed above has similar values to the heatmap.</p>\n<p>Now let's plot the two sequences and connect the mapping points. The code to plot the DTW distance between <em>x</em> and <em>y</em> is given below.</p>\n<p>Example 1: Python code to plot (and save) the DTW distance between x and y</p>\n<p><img src=\"https://miro.medium.com/max/60/1*bF9I-49iVW9b2MvDbRBZxA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*bF9I-49iVW9b2MvDbRBZxA.png\" alt=\"medium blog image\"></p>\n<p>Example 1: DTW distance between x and y (Image by Author)</p>\n<h1>Example 2</h1>\n<p>In this example, we will use two sinusoidal signals and see how they will be matched by calculating the DTW distance between them.</p>\n<p>Example 2: Generate two sinusoidal signals (x1 and x2) with different lengths</p>\n<p>Just like Example 1, let's calculate the DTW distance and the warp path for *x1 *and *x2 *signals using FastDTW package.</p>\n<p>distance, warp_path = fastdtw(x1, x2, dist=euclidean)</p>\n<p>Example 2: Python code to plot (and save) the DTW distance between x1 and x2</p>\n<p><img src=\"https://miro.medium.com/max/60/1*Bzubc5uGFXd_-Sj7W_QFjg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*Bzubc5uGFXd_-Sj7W_QFjg.png\" alt=\"medium blog image\"></p>\n<p>Example 2: DTW distance between x1 and x2 (Image by Author)</p>\n<p>As can be seen in above figure, the DTW distance between the two signals is particularly powerful when the signals have similar patterns. The extrema (maximum and minimum points) between the two signals are correctly mapped. Moreover, unlike Euclidean distance, we may see many-to-one mapping when DTW distance is used, particularly if the two signals have different lengths.</p>\n<p>You may spot an issue with dynamic time warping from the figure above. Can you guess what it is?</p>\n<p>The issue is around the head and tail of time-series that do not properly match. This is because the DTW algorithm cannot afford the warping invariance for at the endpoints. In short, the effect of this is that a small difference at the sequence endpoints will tend to contribute disproportionately to the estimated similarity[3].</p>\n<h1>Conclusion</h1>\n<p>DTW is an algorithm to find an optimal alignment between two sequences and a useful distance metric to have in our toolbox. This technique is useful when we are working with two non-linear sequences, particularly if one sequence is a non-linear stretched/shrunk version of the other. The warping path is a combination of \"chess king\" moves that starts from the head of two sequences and ends with their tails.</p>\n<p>You can find the Jupyter notebook for this blog post <a href=\"https://github.com/e-alizadeh/medium/blob/master/notebooks/intro_to_dtw.ipynb\">here</a>. Thanks for reading!</p>\n<h1>References</h1>\n<p>[1] Donald J. Berndt and James Clifford, <a href=\"https://www.aaai.org/Papers/Workshops/1994/WS-94-03/WS94-03-031.pdf\">Using Dynamic Time Warping to Find Patterns in Time Series</a>, 3rd International Conference on Knowledge Discovery and Data Mining</p>\n<p>[2] Salvador, S. and P. Chan, <a href=\"https://cs.fit.edu/~pkc/papers/tdm04.pdf\">FastDTW: Toward accurate dynamic time warping in linear time and space</a>(2007), Intelligent Data Analysis</p>\n<p>[3] Diego Furtado Silva, <em>et al.</em>, <a href=\"https://core.ac.uk/display/147806669\">On the effect of endpoints on dynamic time warping</a> (2016), SIGKDD Workshop on Mining and Learning from Time Series</p>\n<h1>Useful Links</h1>\n<p>[1] <a href=\"https://nipunbatra.github.io/blog/ml/2014/05/01/dtw.html\">https://nipunbatra.github.io/blog/ml/2014/05/01/dtw.html</a></p>\n<p>[2] <a href=\"https://databricks.com/blog/2019/04/30/understanding-dynamic-time-warping.html\">https://databricks.com/blog/2019/04/30/understanding-dynamic-time-warping.html</a></p>\n<p>Sounds like time traveling or some kind of future technic, however, it is not. Dynamic Time Warping is used to compare the similarity or calculate the distance between two arrays or time series with different length.</p>\n<p>Suppose we want to calculate the distance of two equal-length arrays:</p>\n<p>a = [1, 2, 3]<br>\nb = [3, 2, 2]</p>\n<p>How to do that? One obvious way is to match up <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> in 1-to-1 fashion and sum up the total distance of each component. This sounds easy, but what if <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> have different lengths?</p>\n<p>a = [1, 2, 3]<br>\nb = [2, 2, 2, 3, 4]</p>\n<p>How to match them up? Which should map to which? To solve the problem, there comes dynamic time warping. Just as its name indicates, to warp the series so that they can match up.</p>\n<h1>Use Cases</h1>\n<p>Before digging into the algorithm, you might have the question that is it useful? Do we really need to compare the distance between two unequal-length time series?</p>\n<p>Yes, in a lot of scenarios DTW is playing a key role.</p>\n<h2>Sound Pattern Recognition</h2>\n<p>One use case is to detect the sound pattern of the same kind. Suppose we want to recognise the voice of a person by analysing his sound track, and we are able to collect his sound track of saying <code class=\"language-text\">Hello</code> in one scenario. However, people speak in the same word in different ways, what if he speaks hello in a much slower pace like <code class=\"language-text\">Heeeeeeelloooooo</code> , we will need an algorithm to match up the sound track of different lengths and be able to identify they come from the same person.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*gi1TtOqFCsb2M_U7iAUAag.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*gi1TtOqFCsb2M_U7iAUAag.png\" alt=\"medium blog image\"></p>\n<h2>Stock Market</h2>\n<p>In a stock market, people always hope to be able to predict the future, however using general machine learning algorithms can be exhaustive, as most prediction task requires test and training set to have the same dimension of features. However, if you ever speculate in the stock market, you will know that even the same pattern of a stock can have very different length reflection on klines and indicators.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*4QUO4Tqm_z-8ydMBGgqmPg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*4QUO4Tqm_z-8ydMBGgqmPg.png\" alt=\"medium blog image\"></p>\n<h1>Definition &#x26; Idea</h1>\n<p>A concise explanation of DTW from wiki,</p>\n<blockquote>\n<p>In time series analysis, dynamic time warping (DTW) is one of the algorithms for measuring similarity between two temporal sequences, which may vary in speed. DTW has been applied to temporal sequences of video, audio, and graphics data --- indeed, any data that can be turned into a linear sequence can be analysed with DTW.</p>\n</blockquote>\n<p><em>The idea to compare arrays with different length is to build one-to-many and many-to-one matches so that the total distance can be minimised between the two.</em></p>\n<p>Suppose we have two different arrays red and blue with different length:</p>\n<p><img src=\"https://miro.medium.com/max/42/1*uFicSZjqkNBfsyrsJw7J9g.jpeg?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/612/1*uFicSZjqkNBfsyrsJw7J9g.jpeg\" alt=\"medium blog image\"></p>\n<p>Clearly these two series follow the same pattern, but the blue curve is longer than the red. If we apply the one-to-one match, shown in the top, the mapping is not perfectly synced up and the tail of the blue curve is being left out.</p>\n<p>DTW overcomes the issue by developing a one-to-many match so that the troughs and peaks with the same pattern are perfectly matched, and there is no left out for both curves(shown in the bottom top).</p>\n<h1>Rules</h1>\n<p>In general, DTW is a method that calculates an optimal match between two given sequences (e.g. time series) with certain restriction and rules(comes from wiki):</p>\n<ul>\n<li>Every index from the first sequence must be matched with one or more indices from the other sequence and vice versa</li>\n<li>The first index from the first sequence must be matched with the first index from the other sequence (but it does not have to be its only match)</li>\n<li>The last index from the first sequence must be matched with the last index from the other sequence (but it does not have to be its only match)</li>\n<li>The mapping of the indices from the first sequence to indices from the other sequence must be monotonically increasing, and vice versa, i.e. if <code class=\"language-text\">j > i</code> are indices from the first sequence, then there must not be two indices <code class=\"language-text\">l > k</code> in the other sequence, such that index <code class=\"language-text\">i</code> is matched with index <code class=\"language-text\">l</code> and index <code class=\"language-text\">j</code> is matched with index <code class=\"language-text\">k</code> , and vice versa</li>\n</ul>\n<p>The optimal match is denoted by the match that satisfies all the restrictions and the rules and that has the minimal cost, where the cost is computed as the sum of absolute differences, for each matched pair of indices, between their values.</p>\n<p>To summarise is that <em>head and tail must be positionally matched, no cross-match and no left out.</em></p>\n<h1>Implementation</h1>\n<p>The implementation of the algorithm looks extremely concise:</p>\n<p><img src=\"https://miro.medium.com/max/60/1*fGr2Mj7fEB7tEyqAzcp2LA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*fGr2Mj7fEB7tEyqAzcp2LA.png\" alt=\"medium blog image\"></p>\n<p>where <code class=\"language-text\">DTW[i, j]</code> is the distance between <code class=\"language-text\">s[1:i]</code> and <code class=\"language-text\">t[1:j]</code> with the best alignment.</p>\n<p>The key lies in:</p>\n<p>DTW[i, j] := cost + minimum(DTW[i-1, j ],<br>\nDTW[i , j-1],<br>\nDTW[i-1, j-1])</p>\n<p>Which is saying that the cost of between two arrays with length <code class=\"language-text\">i and j</code> equals <em>the distance between the tails + the minimum of cost in arrays with length _<code class=\"language-text\">*i-1, j*</code></em> , <em><code class=\"language-text\">*i, j-1*</code></em> , and <em><code class=\"language-text\">*i-1, j-1*</code></em> ._</p>\n<p>Put it in python would be:</p>\n<p>Example:</p>\n<p><img src=\"https://miro.medium.com/max/60/1*eogOkXkOUzi6Cq7U9BgiLg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*eogOkXkOUzi6Cq7U9BgiLg.png\" alt=\"medium blog image\"></p>\n<p>The distance between <code class=\"language-text\">a and b</code> would be the last element of the matrix, which is 2.</p>\n<h2>Add Window Constraint</h2>\n<p>One issue of the above algorithm is that we allow one element in an array to match an unlimited number of elements in the other array(as long as the tail can match in the end), this would cause the mapping to bent over a lot, for example, the following array:</p>\n<p>a = [1, 2, 3]<br>\nb = [1, 2, 2, 2, 2, 2, 2, 2, ..., 5]</p>\n<p>To minimise the distance, the element 2 in array <code class=\"language-text\">a</code> would match all the 2 in array <code class=\"language-text\">b</code> , which causes an array <code class=\"language-text\">b</code> to bent severely. To avoid this, we can add a window constraint to limit the number of elements one can match:</p>\n<p><img src=\"https://miro.medium.com/max/60/1*0_xypte7FHDWJuuBexEvHg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*0_xypte7FHDWJuuBexEvHg.png\" alt=\"medium blog image\"></p>\n<p>The key difference is that now each element is confined to match elements in range <code class=\"language-text\">i --- w</code> and <code class=\"language-text\">i + w</code> . The <code class=\"language-text\">w := max(w, abs(n-m))</code> guarantees all indices can be matched up.</p>\n<p>The implementation and example would be:</p>\n<p><img src=\"https://miro.medium.com/max/60/1*2K6C-3QrRmbbhpe-jt9UQA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*2K6C-3QrRmbbhpe-jt9UQA.png\" alt=\"medium blog image\"></p>\n<h1>Apply a Package</h1>\n<p>There is also contributed packages available on Pypi to use directly. Here I demonstrate an example using <a href=\"https://pypi.org/project/fastdtw/\">fastdtw</a>:</p>\n<p>It gives you the distance of two lists and index mapping(the example can extend to a multi-dimension array).</p>"},{"url":"/docs/career/family-promise/","relativePath":"docs/career/family-promise.md","relativeDir":"docs/career","base":"family-promise.md","name":"family-promise","frontmatter":{"title":"Figma","template":"docs","excerpt":"iframe embeds"},"html":"<p> <iframe style=\"border: 1px solid rgba(0, 0, 0, 0.1);\" width=\"650\" height=\"550\" src=\"https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FbOwyinWBikQ5jdEpSx5WcI%2FFamily-Promise-Copy%3Fnode-id%3D0%253A1\" allowfullscreen></iframe></p>\n<br>\n<iframe style=\"border: 1px solid rgba(0, 0, 0, 0.1);\" width=\"650\" height=\"550\" src=\"https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FbOwyinWBikQ5jdEpSx5WcI%2FFamily-Promise-Copy%3Fnode-id%3D0%253A1\" allowfullscreen></iframe>"},{"url":"/docs/career/","relativePath":"docs/career/index.md","relativeDir":"docs/career","base":"index.md","name":"index","frontmatter":{"title":"Career","weight":0,"excerpt":"Reference materials and descriptions of fundamental concepts as well as visua","seo":{"title":"Job Hunt","description":"Job search guidance for front end web developers.","robots":[],"extra":[{"name":"og:image","value":"images/7-b052e510.jpg","keyName":"property","relativeUrl":true}]},"template":"docs"},"html":"<h1>Job Search Docs:</h1>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Job Search Gitbook Docs </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://web-dev-collaborative.github.io/gitpod-job-search-html-static/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h2>My Repos</h2>\n<table>\n<thead>\n<tr>\n<th><a href=\"https://github.com/bgoonz/03-fetch-data\">https://github.com/bgoonz/03-fetch-data</a></th>\n<th><a href=\"https://github.com/bgoonz/gatsby-netlify-cms-norwex\">https://github.com/bgoonz/gatsby-netlify-cms-norwex</a></th>\n<th><a href=\"https://hub.com/bgoonz/React-movie-app\">https://hub.com/bgoonz/React-movie-app</a></th>\n<th><a href=\"https://github.com/bgoonz/Exploring-Promises\">https://github.com/bgoonz/Exploring-Promises</a></th>\n<th><a href=\"https://hub.com/bgoonz/vscode-customized-config\">https://hub.com/bgoonz/vscode-customized-config</a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://github.com/bgoonz/a-whole-bunch-o-gatsby-templates\">https://github.com/bgoonz/a-whole-bunch-o-gatsby-templates</a></td>\n<td><a href=\"https://github.com/bgoonz/gatsby-react-portfolio\">https://github.com/bgoonz/gatsby-react-portfolio</a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-medium-clone\">https://hub.com/bgoonz/react-redux-medium-clone</a></td>\n<td><a href=\"https://github.com/bgoonz/express-API-template\">https://github.com/bgoonz/express-API-template</a></td>\n<td><a href=\"https://hub.com/bgoonz/vscode-Extension-readmes\">https://hub.com/bgoonz/vscode-Extension-readmes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/activity-box\">https://github.com/bgoonz/activity-box</a></td>\n<td><a href=\"https://github.com/bgoonz/GIT-CDN-FILES\">https://github.com/bgoonz/GIT-CDN-FILES</a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-notes-v5\">https://hub.com/bgoonz/react-redux-notes-v5</a></td>\n<td><a href=\"https://github.com/bgoonz/Express-basic-server-template\">https://github.com/bgoonz/Express-basic-server-template</a></td>\n<td><a href=\"https://hub.com/bgoonz/web-crawler-node\">https://hub.com/bgoonz/web-crawler-node</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/All-Undergrad-Archive\">https://github.com/bgoonz/All-Undergrad-Archive</a></td>\n<td><a href=\"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL\">https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL</a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-registration-login-example\">https://hub.com/bgoonz/react-redux-registration-login-example</a></td>\n<td><a href=\"https://github.com/bgoonz/express-knex-postgres-boilerplate\">https://github.com/bgoonz/express-knex-postgres-boilerplate</a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-interview-prep-quiz-website\">https://hub.com/bgoonz/web-dev-interview-prep-quiz-website</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/alternate-blog-theme\">https://github.com/bgoonz/alternate-blog-theme</a></td>\n<td><a href=\"https://github.com/bgoonz/gitbook\">https://github.com/bgoonz/gitbook</a></td>\n<td><a href=\"https://hub.com/bgoonz/React_Notes_V3\">https://hub.com/bgoonz/React_Notes_V3</a></td>\n<td><a href=\"https://github.com/bgoonz/EXPRESS-NOTES\">https://github.com/bgoonz/EXPRESS-NOTES</a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-notes-resource-site\">https://hub.com/bgoonz/web-dev-notes-resource-site</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/anki-cards\">https://github.com/bgoonz/anki-cards</a></td>\n<td><a href=\"https://github.com/bgoonz/github-readme-stats\">https://github.com/bgoonz/github-readme-stats</a></td>\n<td><a href=\"https://hub.com/bgoonz/Recursion-Practice-Website\">https://hub.com/bgoonz/Recursion-Practice-Website</a></td>\n<td><a href=\"https://github.com/bgoonz/fast-fourier-transform\">https://github.com/bgoonz/fast-fourier-transform</a>-</td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-setup-checker\">https://hub.com/bgoonz/web-dev-setup-checker</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/ask-me-anything\">https://github.com/bgoonz/ask-me-anything</a></td>\n<td><a href=\"https://github.com/bgoonz/github-reference-repo\">https://github.com/bgoonz/github-reference-repo</a></td>\n<td><a href=\"https://hub.com/bgoonz/Regex-and-Express-JS\">https://hub.com/bgoonz/Regex-and-Express-JS</a></td>\n<td><a href=\"https://github.com/bgoonz/form-builder-vanilla-js\">https://github.com/bgoonz/form-builder-vanilla-js</a></td>\n<td><a href=\"https://hub.com/bgoonz/WEB-DEV-TOOLS-HUB\">https://hub.com/bgoonz/WEB-DEV-TOOLS-HUB</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/atlassian-templates\">https://github.com/bgoonz/atlassian-templates</a></td>\n<td><a href=\"https://github.com/bgoonz/GoalsTracker\">https://github.com/bgoonz/GoalsTracker</a></td>\n<td><a href=\"https://hub.com/bgoonz/repo-utils\">https://hub.com/bgoonz/repo-utils</a></td>\n<td><a href=\"https://github.com/bgoonz/Front-End-Frameworks-Practice\">https://github.com/bgoonz/Front-End-Frameworks-Practice</a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-utils-package\">https://hub.com/bgoonz/web-dev-utils-package</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Authentication-Notes\">https://github.com/bgoonz/Authentication-Notes</a></td>\n<td><a href=\"https://github.com/bgoonz/graphql-experimentation\">https://github.com/bgoonz/graphql-experimentation</a></td>\n<td><a href=\"https://hub.com/bgoonz/resume-cv-portfolio-samples\">https://hub.com/bgoonz/resume-cv-portfolio-samples</a></td>\n<td><a href=\"https://github.com/bgoonz/full-stack-react-redux\">https://github.com/bgoonz/full-stack-react-redux</a></td>\n<td><a href=\"https://hub.com/bgoonz/WebAudioDaw\">https://hub.com/bgoonz/WebAudioDaw</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-commands-walkthrough\">https://github.com/bgoonz/bash-commands-walkthrough</a></td>\n<td><a href=\"https://github.com/bgoonz/https*__mihirbeg.com\">https://github.com/bgoonz/https*__mihirbeg.com</a>*</td>\n<td><a href=\"https://hub.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering\">https://hub.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering</a></td>\n<td><a href=\"https://github.com/bgoonz/Full-Text-Search\">https://github.com/bgoonz/Full-Text-Search</a></td>\n<td><a href=\"https://hub.com/bgoonz/website\">https://hub.com/bgoonz/website</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-config-backup\">https://github.com/bgoonz/bash-config-backup</a></td>\n<td><a href=\"https://github.com/bgoonz/iframe-showcase\">https://github.com/bgoonz/iframe-showcase</a></td>\n<td><a href=\"https://hub.com/bgoonz/scope-closure-context\">https://hub.com/bgoonz/scope-closure-context</a></td>\n<td><a href=\"https://github.com/bgoonz/Games\">https://github.com/bgoonz/Games</a></td>\n<td><a href=\"https://github.com/bgoonz/Data-Structures-Algos-Codebase\">https://github.com/bgoonz/Data-Structures-Algos-Codebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-shell-utility-functions\">https://github.com/bgoonz/bash-shell-utility-functions</a></td>\n<td><a href=\"https://github.com/bgoonz/Image-Archive-Traning-Data\">https://github.com/bgoonz/Image-Archive-Traning-Data</a></td>\n<td><a href=\"https://hub.com/bgoonz/Shell-Script-Practice\">https://hub.com/bgoonz/Shell-Script-Practice</a></td>\n<td><a href=\"https://github.com/bgoonz/MihirBegMusicV3\">https://github.com/bgoonz/MihirBegMusicV3</a></td>\n<td><a href=\"https://github.com/bgoonz/DATA_STRUC_PYTHON_NOTES\">https://github.com/bgoonz/DATA_STRUC_PYTHON_NOTES</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bass-station\">https://github.com/bgoonz/bass-station</a></td>\n<td><a href=\"https://github.com/bgoonz/Independent-Blog-Entries\">https://github.com/bgoonz/Independent-Blog-Entries</a></td>\n<td><a href=\"https://hub.com/bgoonz/site-analysis\">https://hub.com/bgoonz/site-analysis</a></td>\n<td><a href=\"https://github.com/bgoonz/Mihir_Beg_Final\">https://github.com/bgoonz/Mihir_Beg_Final</a></td>\n<td><a href=\"https://github.com/bgoonz/design-home-page-with-routes-bq5v7k\">https://github.com/bgoonz/design-home-page-with-routes-bq5v7k</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bgoonz\">https://github.com/bgoonz/bgoonz</a></td>\n<td><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE\">https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE</a></td>\n<td><a href=\"https://hub.com/bgoonz/sorting-algorithms\">https://hub.com/bgoonz/sorting-algorithms</a></td>\n<td><a href=\"https://github.com/bgoonz/mini-project-showcase\">https://github.com/bgoonz/mini-project-showcase</a></td>\n<td><a href=\"https://github.com/bgoonz/docs-collection\">https://github.com/bgoonz/docs-collection</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZBLOG2.0STABLE\">https://github.com/bgoonz/BGOONZBLOG2.0STABLE</a></td>\n<td><a href=\"https://github.com/bgoonz/JAMSTACK-TEMPLATES\">https://github.com/bgoonz/JAMSTACK-TEMPLATES</a></td>\n<td><a href=\"https://hub.com/bgoonz/sorting-algos\">https://hub.com/bgoonz/sorting-algos</a></td>\n<td><a href=\"https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard\">https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard</a></td>\n<td><a href=\"https://github.com/bgoonz/Documentation-site-react\">https://github.com/bgoonz/Documentation-site-react</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\">https://github.com/bgoonz/BGOONZ_BLOG_2.0</a></td>\n<td><a href=\"https://github.com/bgoonz/Javascript-Best-Practices_--Tools\">https://github.com/bgoonz/Javascript-Best-Practices_--Tools</a></td>\n<td><a href=\"https://hub.com/bgoonz/sqlite3-nodejs-demo\">https://hub.com/bgoonz/sqlite3-nodejs-demo</a></td>\n<td><a href=\"https://github.com/bgoonz/my-gists\">https://github.com/bgoonz/my-gists</a></td>\n<td><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">https://github.com/bgoonz/DS-ALGO-OFFICIAL</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Binary-Search\">https://github.com/bgoonz/Binary-Search</a></td>\n<td><a href=\"https://github.com/bgoonz/jsanimate\">https://github.com/bgoonz/jsanimate</a></td>\n<td><a href=\"https://hub.com/bgoonz/stalk-photos-web-assets\">https://hub.com/bgoonz/stalk-photos-web-assets</a></td>\n<td><a href=\"https://github.com/bgoonz/My-Medium-Blog\">https://github.com/bgoonz/My-Medium-Blog</a></td>\n<td><a href=\"https://github.com/bgoonz/DS-AND-ALGO-Notes-P2\">https://github.com/bgoonz/DS-AND-ALGO-Notes-P2</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-2.o-versions\">https://github.com/bgoonz/blog-2.o-versions</a></td>\n<td><a href=\"https://github.com/bgoonz/Jupyter-Notebooks\">https://github.com/bgoonz/Jupyter-Notebooks</a></td>\n<td><a href=\"https://hub.com/bgoonz/Standalone-Metranome\">https://hub.com/bgoonz/Standalone-Metranome</a></td>\n<td><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template\">https://github.com/bgoonz/nextjs-netlify-blog-template</a></td>\n<td><a href=\"https://github.com/bgoonz/ecommerce-interactive\">https://github.com/bgoonz/ecommerce-interactive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-templates\">https://github.com/bgoonz/blog-templates</a></td>\n<td><a href=\"https://github.com/bgoonz/Lambda\">https://github.com/bgoonz/Lambda</a></td>\n<td><a href=\"https://hub.com/bgoonz/Star-wars-API-Promise-take2\">https://hub.com/bgoonz/Star-wars-API-Promise-take2</a></td>\n<td><a href=\"https://github.com/bgoonz/norwex-coff-ecom\">https://github.com/bgoonz/norwex-coff-ecom</a></td>\n<td><a href=\"https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground\">https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-w-comments\">https://github.com/bgoonz/blog-w-comments</a></td>\n<td><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\">https://github.com/bgoonz/Lambda-Resource-Static-Assets</a></td>\n<td><a href=\"https://hub.com/bgoonz/Static-Study-Site\">https://hub.com/bgoonz/Static-Study-Site</a></td>\n<td><a href=\"https://github.com/bgoonz/old-c-and-cpp-repos-from-undergrad\">https://github.com/bgoonz/old-c-and-cpp-repos-from-undergrad</a></td>\n<td><a href=\"https://github.com/bgoonz/excel2html-table\">https://github.com/bgoonz/excel2html-table</a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Blog2.0-August-Super-Stable\">https://github.com/bgoonz/Blog2.0-August-Super-Stable</a></td>\n<td><a href=\"https://github.com/bgoonz/learning-nextjs\">https://github.com/bgoonz/learning-nextjs</a></td>\n<td><a href=\"https://hub.com/bgoonz/styling-templates\">https://hub.com/bgoonz/styling-templates</a></td>\n<td><a href=\"https://github.com/bgoonz/old-code-from-undergrad\">https://github.com/bgoonz/old-code-from-undergrad</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bootstrap-sidebar-template\">https://github.com/bgoonz/bootstrap-sidebar-template</a></td>\n<td><a href=\"https://github.com/bgoonz/Learning-Redux\">https://github.com/bgoonz/Learning-Redux</a></td>\n<td><a href=\"https://hub.com/bgoonz/supertemp\">https://hub.com/bgoonz/supertemp</a></td>\n<td><a href=\"https://github.com/bgoonz/picture-man-bob-v2\">https://github.com/bgoonz/picture-man-bob-v2</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/callbacks\">https://github.com/bgoonz/callbacks</a></td>\n<td><a href=\"https://github.com/bgoonz/Links-Shortcut-Site\">https://github.com/bgoonz/Links-Shortcut-Site</a></td>\n<td><a href=\"https://hub.com/bgoonz/Ternary-converter\">https://hub.com/bgoonz/Ternary-converter</a></td>\n<td><a href=\"https://github.com/bgoonz/Project-Showcase\">https://github.com/bgoonz/Project-Showcase</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Comments\">https://github.com/bgoonz/Comments</a></td>\n<td><a href=\"https://github.com/bgoonz/live-examples\">https://github.com/bgoonz/live-examples</a></td>\n<td><a href=\"https://hub.com/bgoonz/TetrisJS\">https://hub.com/bgoonz/TetrisJS</a></td>\n<td><a href=\"https://github.com/bgoonz/promises-with-async-and-await\">https://github.com/bgoonz/promises-with-async-and-await</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store\">https://github.com/bgoonz/commercejs-nextjs-demo-store</a></td>\n<td><a href=\"https://github.com/bgoonz/live-form\">https://github.com/bgoonz/live-form</a></td>\n<td><a href=\"https://hub.com/bgoonz/TexTools\">https://hub.com/bgoonz/TexTools</a></td>\n<td><a href=\"https://github.com/bgoonz/psql-practice\">https://github.com/bgoonz/psql-practice</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Common-npm-Readme-Compilation\">https://github.com/bgoonz/Common-npm-Readme-Compilation</a></td>\n<td><a href=\"https://github.com/bgoonz/loadash-es6-refactor\">https://github.com/bgoonz/loadash-es6-refactor</a></td>\n<td><a href=\"https://hub.com/bgoonz/The-Algorithms\">https://hub.com/bgoonz/The-Algorithms</a></td>\n<td><a href=\"https://github.com/bgoonz/python-playground-embed\">https://github.com/bgoonz/python-playground-embed</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Comparing-Web-Development-Bootcamps-2021\">https://github.com/bgoonz/Comparing-Web-Development-Bootcamps-2021</a></td>\n<td><a href=\"https://github.com/bgoonz/markdown-css\">https://github.com/bgoonz/markdown-css</a></td>\n<td><a href=\"https://hub.com/bgoonz/TRASH\">https://hub.com/bgoonz/TRASH</a></td>\n<td><a href=\"https://github.com/bgoonz/python-practice-notes\">https://github.com/bgoonz/python-practice-notes</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Connect-Four-Final-Version\">https://github.com/bgoonz/Connect-Four-Final-Version</a></td>\n<td><a href=\"https://github.com/bgoonz/Markdown-Templates\">https://github.com/bgoonz/Markdown-Templates</a></td>\n<td><a href=\"https://hub.com/bgoonz/Triggered-Guitar-Effects-Platform\">https://hub.com/bgoonz/Triggered-Guitar-Effects-Platform</a></td>\n<td><a href=\"https://github.com/bgoonz/python-scripts\">https://github.com/bgoonz/python-scripts</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/convert-folder-contents-2-website\">https://github.com/bgoonz/convert-folder-contents-2-website</a></td>\n<td><a href=\"https://github.com/bgoonz/meditation-app\">https://github.com/bgoonz/meditation-app</a></td>\n<td><a href=\"https://hub.com/bgoonz/Useful-Snippets-js\">https://hub.com/bgoonz/Useful-Snippets-js</a></td>\n<td><a href=\"https://github.com/bgoonz/PYTHON_PRAC\">https://github.com/bgoonz/PYTHON_PRAC</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Copy-2-Clipboard-jQuery\">https://github.com/bgoonz/Copy-2-Clipboard-jQuery</a></td>\n<td><a href=\"https://github.com/bgoonz/MihirBegMusicLab\">https://github.com/bgoonz/MihirBegMusicLab</a></td>\n<td><a href=\"https://hub.com/bgoonz/UsefulResourceRepo2.0\">https://hub.com/bgoonz/UsefulResourceRepo2.0</a></td>\n<td><a href=\"https://github.com/bgoonz/random-list-of-embedable-content\">https://github.com/bgoonz/random-list-of-embedable-content</a></td>\n<td></td>\n</tr>\n</tbody>\n</table>"},{"url":"/docs/career/my-websites/","relativePath":"docs/career/my-websites.md","relativeDir":"docs/career","base":"my-websites.md","name":"my-websites","frontmatter":{"title":"My Sites","excerpt":"In this section you'll learn how to add syntax highlighting, examples, callouts and much more.","seo":{"title":"My Sites","description":"This is the My Sites page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"My Sites","keyName":"property"},{"name":"og:description","value":"This is the My Sites page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"My Sites"},{"name":"twitter:description","value":"This is the My Sites page"}]},"template":"docs"},"html":"<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://random-static-html-deploys.netlify.app/my-websites/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<h1> Links </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://links4242.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<h1> Wikipedia Viewer</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://random-static-html-deploys.netlify.app/wikipedia-viewer.html\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://web-dev-resource-hub.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://learning-redux42.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>/\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://trusting-dijkstra-4d3b17.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://web-dev-interview-prep-quiz-website.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>/intro-js2.html\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://zen-lamport-5aab2c.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://csb-ov0d1-bgoonz.vercel.app/\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://amazing-hodgkin-33aea6.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://angry-fermat-dcf5dd.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://boring-heisenberg-f425d8.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://site-analysis.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>/\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://clever-bartik-b5ba19.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://code-playground.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://condescending-lewin-c96727.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://determined-dijkstra-666766.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://determined-dijkstra-ee7390.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://eager-northcutt-456076.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://ecstatic-jang-593fd1.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://eloquent-sammet-ba1810.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://embedable-content.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://festive-borg-e4d856.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://focused-pasteur-0faac8.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://gists42.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://gracious-raman-474030.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://happy-mestorf-0f8e75.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://hungry-shaw-30d504.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://inspiring-jennings-d14689.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://links4242.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://modest-booth-4e17df.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://modest-torvalds-34afbc.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://modest-varahamihira-772b59.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://nervous-swartz-0ab2cc.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://objective-borg-a327cd.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://pedantic-wing-adbf82.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://pensive-meitner-1ea8c4.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://sanity-gatsby-portfolio-3-web-4dmiq19t.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://project-portfolio42.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://portfolio42.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://priceless-shaw-86ccb2.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://quizzical-mcnulty-fa09f2.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://relaxed-bhaskara-dc85ec.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://romantic-hamilton-514b79.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://silly-lichterman-b22b5f.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://silly-shirley-ec955e.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://stoic-mccarthy-2c335f.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://web-dev-resource-hub-manual-deploy.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https\n://wonderful-pasteur-392fbe.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>"},{"url":"/docs/career/job-boards/","relativePath":"docs/career/job-boards.md","relativeDir":"docs/career","base":"job-boards.md","name":"job-boards","frontmatter":{"title":"Job Board","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Job Boards</h1>\n<p><a href=\"https://github.com/sindresorhus/awesome\"><img src=\"https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg\" alt=\"Awesome\"></a></p>\n<p>A curated list of awesome job boards.</p>\n<h2>Table of Contents</h2>\n<ul>\n<li><a href=\"#general\">General</a></li>\n<li><a href=\"#data-science\">Data Science</a></li>\n<li><a href=\"#blockchain\">Blockchain</a></li>\n<li><a href=\"#design\">Design</a></li>\n<li><a href=\"#infosec\">InfoSec</a></li>\n<li><a href=\"#programming\">Programming</a></li>\n<li><a href=\"#remote\">Remote</a></li>\n<li><a href=\"#freelancer\">Freelancer</a></li>\n<li><a href=\"#other\">Other</a></li>\n</ul>\n<h2>General</h2>\n<ul>\n<li><a href=\"https://www.linkedin.com/\">LinkedIn</a></li>\n<li><a href=\"https://www.indeed.com/\">Indeed</a></li>\n<li><a href=\"https://www.glassdoor.com/\">Glassdoor</a></li>\n<li><a href=\"https://angel.co\">Angel List</a></li>\n<li><a href=\"https://www.arbeitnow.com\">arbeitnow</a></li>\n<li><a href=\"https://4dayweek.io/\">4 day week</a></li>\n</ul>\n<h2>Data Science</h2>\n<ul>\n<li><a href=\"https://datajobs.com/\">DataJobs.com</a></li>\n<li><a href=\"https://jobs.dataelixir.com/\">Data Elixir</a></li>\n<li><a href=\"https://ai-jobs.net/\">AI Jobs</a></li>\n<li><a href=\"https://jobhunt.ai/\">Machine learning jobs</a></li>\n<li><a href=\"https://www.kaggle.com/jobs\">Kaggle jobs</a></li>\n<li><a href=\"https://icrunchdata.com/\">icrunchdata</a></li>\n<li><a href=\"https://www.kdnuggets.com/jobs/index.html\">KDnuggets</a></li>\n<li><a href=\"https://www.datayoshi.com/\">Data Yoshi</a></li>\n<li><a href=\"https://jobs.opendatascience.com/\">Opendatascience Jobs</a></li>\n<li><a href=\"https://jobsnew.analyticsvidhya.com/jobs/all\">AnalyticsVidhya Jobs</a></li>\n<li><a href=\"https://www.jobsfornewdatascientists.com/\">Jobs for New Data Scientists</a></li>\n<li><a href=\"https://www.bigdatajobs.com/\">BigDataJobs</a></li>\n<li><a href=\"https://www.statsjobs.com/\">StatsJobs</a></li>\n<li><a href=\"https://bigcloud.global/find-a-job/\">Big Cloud</a></li>\n<li><a href=\"https://www.microprediction.com/jobs\">Microprediction jobs</a></li>\n</ul>\n<h2>Blockchain</h2>\n<ul>\n<li><a href=\"https://blocktribe.com/\">Blocktribe</a></li>\n<li><a href=\"https://cryptojobslist.com/\">Crypto Jobs List</a></li>\n<li><a href=\"https://crypto.jobs/\">CryptoJobs</a></li>\n<li><a href=\"https://blockew.com/\">Blockew</a></li>\n<li><a href=\"https://cryptocurrencyjobs.co/\">Cryptocurrency Jobs</a></li>\n</ul>\n<h2>Design</h2>\n<ul>\n<li><a href=\"https://designjobs.aiga.org/\">AIGA</a></li>\n<li><a href=\"https://www.authenticjobs.com/\">Authentic Jobs</a></li>\n<li><a href=\"https://www.behance.net/joblist\">Behance</a></li>\n<li><a href=\"https://www.coroflot.com/design-jobs\">Coroflot</a></li>\n<li><a href=\"http://ixda.org/jobs/\">IXDA</a></li>\n<li><a href=\"https://dribbble.com/jobs\">Dribble</a></li>\n<li><a href=\"https://www.krop.com/creative-jobs/\">Krop</a></li>\n<li><a href=\"https://opensourcedesign.net/jobs/\">Open Source Design Jobs</a></li>\n<li><a href=\"https://www.uxjobsboard.com\">UX Jobs Board</a></li>\n<li><a href=\"https://designerjobs.co/jobs\">Designer Jobs</a></li>\n<li><a href=\"https://designmodo.com/jobs/\">designmodo</a></li>\n<li><a href=\"https://www.designjobsboard.com/\">Design Jobs Board</a></li>\n<li><a href=\"https://jobs.designweek.co.uk/\">Design Week Jobs</a></li>\n<li><a href=\"https://designjobs.aiga.org/\">AIGA Design Jobs</a></li>\n<li><a href=\"https://ifyoucouldjobs.com/jobs\">If You Could Jobs</a></li>\n<li><a href=\"https://creativemornings.com/jobs\">CreativeMornings</a></li>\n<li><a href=\"https://creativepool.com/jobs/\">Creativepool</a></li>\n<li><a href=\"https://www.theloop.com.au/jobs\">The Loop</a></li>\n</ul>\n<h2>InfoSec</h2>\n<ul>\n<li><a href=\"https://ninjajobs.org/\">NinjaJobs</a></li>\n<li><a href=\"https://infosec-jobs.com/\">infosec-jobs</a></li>\n<li><a href=\"https://www.cybersecurityjobsite.com/jobs/\">CyberSecurityJobsite</a></li>\n<li><a href=\"https://www.careersincyber.com/browse-jobs/\">CareersinCyber</a></li>\n<li><a href=\"https://www.careersinfosecurity.com/jobs/\">CareersInfoSecurity</a></li>\n<li><a href=\"https://www.cybersecurityjobs.net/\">CyberSecurityJobs</a></li>\n<li><a href=\"https://jobs.yeswehack.com/en/\">YesWeHack</a></li>\n</ul>\n<h2>Programming</h2>\n<ul>\n<li><a href=\"https://thecarrots.io/jobs\">Carrots</a></li>\n<li><a href=\"https://www.goopensource.dev/\">Goopensource.dev</a></li>\n<li><a href=\"https://iosdevjobs.com/\">iOS Dev Jobs</a></li>\n<li><a href=\"https://elixir.career/\">Elixir Jobs</a></li>\n<li><a href=\"http://frontenddeveloperjob.com/\">Front-End Developer Jobs</a></li>\n<li><a href=\"https://fullstackjob.com/\">Full-Stack Developer Jobs</a></li>\n<li><a href=\"https://functionaljobs.com/\">Functional Jobs</a></li>\n<li><a href=\"https://www.golangprojects.com/\">Golangprojects</a></li>\n<li><a href=\"https://www.welovegolang.com/\">we love golang</a></li>\n<li><a href=\"https://forum.golangbridge.org/c/jobs\">Golang Forum Jobs</a></li>\n<li><a href=\"https://golangjob.xyz/\">Golang Job Board</a></li>\n<li><a href=\"https://golang.cafe/\">Golang Cafe</a></li>\n<li><a href=\"https://angularjobs.com/\">Angular Jobs</a></li>\n<li><a href=\"https://angular.work/\">Angular Work</a></li>\n<li><a href=\"https://jobs.emberjs.com/\">Ember Job Board</a></li>\n<li><a href=\"https://vuejobs.com/\">Vue.js Jobs</a></li>\n<li><a href=\"https://madewithvuejs.com/jobs\">Made with Vue.js Jobs</a></li>\n<li><a href=\"https://www.react-jobs.com/\">React Jobs</a></li>\n<li><a href=\"https://www.reactjobboard.com/\">React Job Board</a></li>\n<li><a href=\"https://www.weloveangular.com/\">We Love Angular</a></li>\n<li><a href=\"https://www.weworkmeteor.com/\">We Work Meteor</a></li>\n<li><a href=\"https://jobs.drupal.org/\">Drupal Jobs</a></li>\n<li><a href=\"https://jobs.wordpress.net/\">WordPress Jobs</a></li>\n<li><a href=\"https://larajobs.com/\">LaraJobs</a></li>\n<li><a href=\"https://www.wphired.com/\">WPhired</a></li>\n<li><a href=\"https://www.python.org/jobs/\">Python Job Board</a></li>\n<li><a href=\"https://www.pythonjobshq.com/\">Pycoder's Jobs</a></li>\n<li><a href=\"https://djangogigs.com/\">django gigs</a></li>\n<li><a href=\"https://djangojobs.net/jobs/\">Django Jobs</a></li>\n<li><a href=\"https://jobs.rubynow.com/\">RubyNow</a></li>\n<li><a href=\"https://www.rorjobs.com/\">Ruby on Rails Jobs</a></li>\n<li><a href=\"http://rust-jobs.com/\">Rust Programming Language Jobs</a></li>\n<li><a href=\"https://webassemblyjobs.com/\">WebAssembly Jobs</a></li>\n<li><a href=\"https://jobs.date-fns.org/\">JavaScript Jobs</a></li>\n<li><a href=\"https://jobsinjs.com/\">Jobs in JS</a></li>\n<li><a href=\"https://www.r-users.com/\">R-users</a></li>\n</ul>\n<h2>Remote</h2>\n<ul>\n<li><a href=\"https://careervault.io/\">Career Vault</a></li>\n<li><a href=\"https://remotebond.com/\">Remotebond</a></li>\n<li><a href=\"https://jobspresso.co/remote-work/\">Jobspresso</a></li>\n<li><a href=\"https://weworkremotely.com/\">We Work Remotely</a></li>\n<li><a href=\"https://workaline.com/\">Workaline</a></li>\n<li><a href=\"https://remotive.io/\">Remotive</a></li>\n<li><a href=\"https://remote.com/remote-jobs\">Remote</a></li>\n<li><a href=\"https://remoteok.io/\">remote | OK</a></li>\n<li><a href=\"https://justremote.co/\">JustRemote</a></li>\n<li><a href=\"https://www.skipthedrive.com/\">SkipTheDrive</a></li>\n<li><a href=\"https://remote.co/remote-jobs/\">remote.co</a></li>\n<li><a href=\"https://remote4me.com/\">remote4me.com</a></li>\n<li><a href=\"https://www.workingnomads.co/jobs\">Working Nomads</a></li>\n<li><a href=\"https://europeremotely.com/\">EuropeRemotely</a></li>\n<li><a href=\"https://www.awesomejobs.io/\">AwesomeJobs</a></li>\n<li><a href=\"https://www.remotepython.com/\">Remote Python</a></li>\n<li><a href=\"https://rubyonremote.com/\">Ruby On Remote</a></li>\n<li><a href=\"https://remoteml.com/\">Remote ML</a></li>\n<li><a href=\"https://jsremotely.com/\">JS Remotely</a></li>\n<li><a href=\"https://remotearena.com/\">Remote Arena</a></li>\n<li><a href=\"https://www.letsworkremotely.com/remote-jobs/\">letsworkremotely</a></li>\n<li><a href=\"https://workew.com/remote-jobs/\">Workew</a></li>\n<li><a href=\"https://wellpaid.io/\">wellpaid.io</a></li>\n<li><a href=\"https://nodesk.co/remote-jobs/\">NODESK Remote Jobs</a></li>\n<li><a href=\"https://www.flexjobs.com/\">FlexJobs</a></li>\n<li><a href=\"https://rmtwrk.com/\">RMTWRK</a></li>\n<li><a href=\"https://remotify.me/\">remotify</a></li>\n<li><a href=\"https://remoters.net/jobs/\">Remoters</a></li>\n<li><a href=\"https://jobmote.com/\">Jobmote</a></li>\n<li><a href=\"https://www.remotelyawesomejobs.com/\">Remotely Awesome Jobs</a></li>\n<li><a href=\"https://dailyremote.com/\">DailyRemote</a></li>\n<li><a href=\"https://www.remote-developer-jobs.com/\">Remote Developer Jobs</a></li>\n<li><a href=\"https://remotees.com/\">Remotees</a></li>\n<li><a href=\"https://meerkad.com/\">Meerkad</a></li>\n<li><a href=\"https://workfromhomejobs.me/\">Work From Home Jobs</a></li>\n<li><a href=\"https://pangian.com/job-travel-remote/\">Pangian</a></li>\n<li><a href=\"https://www.outsourcely.com/remote-workers\">Outsourcely</a></li>\n<li><a href=\"https://www.prospercircle.org/\">ProsperCircle.org</a></li>\n<li><a href=\"https://www.dynamitejobs.com/\">DynamiteJobs</a></li>\n<li><a href=\"https://flatworld.co/jobs/\">FlatWorld</a></li>\n<li><a href=\"https://www.beefrii.com/\">beefrii</a></li>\n<li><a href=\"https://hireremote.io/\">Hire Remote</a></li>\n</ul>\n<h2>Freelancer</h2>\n<ul>\n<li><a href=\"https://www.upwork.com\">Upwork</a></li>\n<li><a href=\"https://www.toptal.com/\">Toptal</a></li>\n<li><a href=\"https://www.freelancer.com\">Freelancer</a></li>\n<li><a href=\"https://www.guru.com/\">Guru</a></li>\n<li><a href=\"https://www.peopleperhour.com\">People Per Hour</a></li>\n<li><a href=\"https://www.fiverr.com/\">Fiverr</a></li>\n<li><a href=\"https://talent.hubstaff.com/\">Hubstaff</a></li>\n<li><a href=\"https://outsource.com\">Outsource</a></li>\n<li><a href=\"https://www.giggrabbers.com\">GigGrabbers</a></li>\n<li><a href=\"https://www.cloudpeeps.com\">CloudPeeps</a></li>\n<li><a href=\"https://localsolo.com/\">Local Solo</a></li>\n<li><a href=\"https://www.yunojuno.com/\">YunoJuno</a></li>\n<li><a href=\"https://www.gun.io/\">Gun.io</a></li>\n</ul>\n<h2>Other</h2>\n<ul>\n<li><a href=\"https://www.monster.com/\">Monster</a></li>\n<li><a href=\"https://jobs.github.com/\">GitHub Jobs</a></li>\n<li><a href=\"https://www.amazon.jobs/en\">Amazon Jobs</a></li>\n<li><a href=\"https://news.ycombinator.com/jobs\">HackerNews Jobs</a></li>\n<li><a href=\"https://stackoverflow.com/jobs\">Stack Overflow Jobs</a></li>\n<li><a href=\"https://www.crunchboard.com/\">Crunchboard</a></li>\n<li><a href=\"https://jobs.hackernoon.com/\">Hacker Noon Jobs</a></li>\n<li><a href=\"https://jobbatical.com/jobs\">Jobbatical</a></li>\n<li><a href=\"https://powertofly.com/jobs/\">PowerToFly</a> (Women)</li>\n<li><a href=\"https://whoishiring.io/\">whoishiring.io</a></li>\n<li><a href=\"https://www.simplyhired.com/\">SimplyHired</a></li>\n<li><a href=\"https://www.careerbuilder.com\">CareerBuilder</a></li>\n<li><a href=\"https://www.careercast.com/jobs/search/\">CareerCast</a></li>\n<li><a href=\"https://www.dice.com/\">Dice</a></li>\n<li><a href=\"https://jobs.techstars.com/\">Techstars</a></li>\n<li><a href=\"https://www.producthunt.com/jobs/\">Product Hunt Jobs</a></li>\n<li><a href=\"https://www.ziprecruiter.com/\">ZipRecruiter</a></li>\n<li><a href=\"https://www.idealist.org/\">Idealist</a></li>\n<li><a href=\"https://aquent.com/find-work/\">Aquent</a></li>\n<li><a href=\"https://hackerx.org/jobs/\">HackerX</a></li>\n<li><a href=\"https://findwork.dev/\">findwork.dev</a></li>\n<li><a href=\"https://jobs.livecareer.com/\">Livecareer</a></li>\n<li><a href=\"https://www.themuse.com/jobs\">The Muse</a></li>\n<li><a href=\"https://linkup.com/\">LinkUp</a></li>\n<li><a href=\"https://authenticjobs.com/\">Authentic Jobs</a></li>\n<li><a href=\"https://devsnap.io/\">DevSnap</a></li>\n<li><a href=\"https://joblist.app/\">Joblist.app</a></li>\n<li><a href=\"https://www.jobs2careers.com/\">Jobs2Careers</a></li>\n<li><a href=\"https://www.jobisjob.com/\">JobisJob</a></li>\n<li><a href=\"https://joblift.com/\">Joblift</a></li>\n<li><a href=\"https://www.adzuna.com/\">Adzuna</a></li>\n<li><a href=\"https://techmeabroad.com/\">TechMeAbroad</a></li>\n<li><a href=\"https://www.hackerrank.com/jobs/search\">HackerRank Jobs</a></li>\n<li><a href=\"https://findbacon.com/\">Find Bacon</a></li>\n<li><a href=\"https://codersrank.io/find-a-job/\">Codersrank</a></li>\n<li><a href=\"https://www.reddit.com/r/forhire/search?q=%28title%3A%22%5Bhiring%5D%22+OR+flair%3AHiring%29+AND+%28subreddit%3Aforhire+OR+subreddit%3Ajobbit+OR+subreddit%3Ajobopenings%29&#x26;sort=new&#x26;t=all\">jobbit subreddit</a></li>\n<li><a href=\"https://www.jora.com/\">Jora</a></li>\n<li><a href=\"https://hnhiring.com/\">HNHIRING</a></li>\n<li><a href=\"https://nocsok.com/\">nocsok</a></li>\n<li><a href=\"https://ycombinator.monday.vc/\">Y Combinator Job Board</a></li>\n<li><a href=\"https://relocate.me/\">Relocate.me</a></li>\n<li><a href=\"https://producthire.net/\">PRODUCTHIRE.NET</a></li>\n<li><a href=\"https://sportekjobs.com\">Sports tech jobs</a></li>\n<li><a href=\"https://epicjobs.co/\">#epicjobs</a></li>\n<li><a href=\"https://able.bio/jobs\">Able</a></li>\n<li><a href=\"https://stackshare.io/match\">StackShare</a></li>\n<li><a href=\"https://neuvoo.com/\">Neuvoo</a></li>\n<li><a href=\"https://www.toplanguagejobs.com/\">Top Language Jobs</a></li>\n<li><a href=\"https://vanhack.com/platform/#/jobs\">Vanhack</a></li>\n<li><a href=\"http://calmjobs.io/jobs\">CalmJobs</a></li>\n<li><a href=\"https://peoplefirstjobs.com/\">PeopleFirstJobs</a></li>\n<li><a href=\"https://www.naukri.com/\">Naukri</a></li>\n<li><a href=\"https://jobs.digitaloxford.com/\">Digital Oxford Jobs</a></li>\n<li><a href=\"https://css-tricks.com/jobs/\">CSS-Tricks Jobs</a></li>\n<li><a href=\"https://www.smashingmagazine.com/jobs/\">Smashing Magazine</a></li>\n<li><a href=\"https://www.totaljobs.com/\">Totaljobs</a></li>\n<li><a href=\"https://www.xing.com/jobs\">XING</a></li>\n<li><a href=\"https://codepen.io/jobs/\">Codepen Jobs</a></li>\n<li><a href=\"https://jobs.theguardian.com/jobs/\">The Guardian Jobs</a></li>\n<li><a href=\"https://www.jobsinnetwork.com/\">Jobs in Network</a></li>\n<li><a href=\"https://www.snagajob.com/\">snagajob</a></li>\n<li><a href=\"https://www.roberthalf.com/jobs\">Robert Half</a></li>\n<li><a href=\"https://www.higheredjobs.com/\">HigherEdJobs</a></li>\n<li><a href=\"https://www.mediabistro.com/\">Mediabistro</a></li>\n<li><a href=\"https://www.joblist.com/\">Joblist</a></li>\n<li><a href=\"https://www.workatastartup.com/job_list\">Workatastartup</a></li>\n<li><a href=\"https://enviro.work/\">enviro</a></li>\n<li><a href=\"https://www.f6s.com/jobs\">f6s</a></li>\n<li><a href=\"https://www.theladders.com/jobs/search-jobs\">Ladders</a></li>\n<li><a href=\"https://www.cleverism.com/jobs\">Cleverism</a></li>\n<li><a href=\"https://www.virtualvocations.com/\">VirtualVocations</a></li>\n<li><a href=\"https://jobs.mashable.com/\">Mashable</a></li>\n<li><a href=\"http://www.jobvertise.com/\">Jobvertise</a></li>\n<li><a href=\"https://equalopportunity.work/\">EqualOpportunity</a></li>\n<li><a href=\"https://jobs.cncf.io/\">CNCF Job Board</a></li>\n<li><a href=\"https://www.kdrrecruitment.com/jobs/\">KDR Recruitment</a></li>\n<li><a href=\"https://www.diversifytech.co/job-board/\">Diversify Tech</a></li>\n<li><a href=\"https://www.womenwhocode.com/jobs\">Women Who Code</a></li>\n<li><a href=\"https://hitmarker.net/jobs\">Hitmarker</a></li>\n<li><a href=\"https://careers.greatercph.com/gamedev\">Open GameDev Jobs</a></li>\n<li><a href=\"https://www.heygamer.co/\">Hey Gamer</a></li>\n<li><a href=\"https://jobs.prsa.org/\">PRSA Job Center</a></li>\n<li><a href=\"https://www.efinancialcareers.com/\">eFinancialCareers</a></li>\n<li><a href=\"https://uncubed.com/jobs\">Uncubed</a></li>\n<li><a href=\"https://healthecareers.com/\">Health eCareers</a></li>\n<li><a href=\"https://www.techfetch.com/\">TechFetch</a></li>\n<li><a href=\"https://launchafrica.io/\">LaunchAfrica</a></li>\n<li><a href=\"https://www.diversityjobs.com/\">DiversityJobs</a></li>\n<li><a href=\"https://www.clearancejobs.com/\">ClearanceJobs</a></li>\n<li><a href=\"https://itjobpro.com/\">IT Job Pro</a></li>\n<li><a href=\"https://the-dots.com/jobs/search\">The-Dots</a></li>\n<li><a href=\"https://www.campaignlive.co.uk/jobs/all/\">CampaignJobs</a></li>\n<li><a href=\"https://goodjobs.careers/\">GoodJobs</a>(Climate change, food insecurity)</li>\n<li><a href=\"https://techjobsforgood.com/\">Tech Jobs for Good</a></li>\n</ul>\n<h3>Entry Level</h3>\n<ul>\n<li><a href=\"https://www.entryleveljobs.me/\">Entry Level Jobs</a></li>\n<li><a href=\"https://www.collegerecruiter.com/\">College Recruiter</a></li>\n<li><a href=\"https://www.internships.com/\">Internships</a></li>\n<li><a href=\"https://www.jrdevjobs.com/\">Jr.DevJobs</a></li>\n<li><a href=\"https://graduateland.com/jobs\">Graduateland</a></li>\n<li><a href=\"https://talentegg.ca/\">TalentEgg</a></li>\n<li><a href=\"https://entrylevel.io/\">entrylevel.io</a></li>\n<li><a href=\"https://erasmusintern.org/traineeships\">ErasmusIntern</a></li>\n<li><a href=\"https://www.careerrookie.com/\">CareerRookie</a></li>\n<li><a href=\"https://www.aftercollege.com/\">AfterCollege</a></li>\n</ul>\n<h3>Startups</h3>\n<ul>\n<li><a href=\"https://startup.jobs/\">Startup Jobs</a></li>\n<li><a href=\"https://www.startupers.com/\">StartUpers</a></li>\n<li><a href=\"https://workinstartups.com/\">WorkinStartups</a></li>\n<li><a href=\"https://thehub.io/\">The Hub</a></li>\n<li><a href=\"https://unicornhunt.io/\">Unicorn Hunt</a></li>\n<li><a href=\"https://www.startuphire.com/\">StartupHire</a></li>\n</ul>\n<h3>United States</h3>\n<ul>\n<li><a href=\"https://www.dallasjobs.io/\">DallasJobs</a></li>\n<li><a href=\"https://us.jobs/\">US Jobs</a></li>\n<li><a href=\"https://www.careerjet.com/\">Careerjet</a></li>\n<li><a href=\"https://www.nexxt.com/\">Nexxt</a></li>\n<li><a href=\"https://usnlx.com/\">National Labor Exchange</a></li>\n</ul>\n<h3>Free &#x26; Open Source</h3>\n<ul>\n<li><a href=\"https://www.fossjobs.net/\">Free &#x26; Open Source Jobs</a></li>\n<li><a href=\"https://oo.t9t.io/jobs\">Open Source Jobs</a></li>\n<li><a href=\"https://www.linuxjobs.io/\">LinuxJobs.io</a></li>\n</ul>\n<h3>DevOps</h3>\n<ul>\n<li><a href=\"https://jobsfordevops.com\">Jobs For DevOps</a></li>\n<li><a href=\"https://kube.careers\">Kube Careers</a></li>\n</ul>\n<h3>Growth Hacking</h3>\n<ul>\n<li><a href=\"https://growthhackers.com/jobs\">GrowthHackers</a></li>\n</ul>"},{"url":"/docs/community/an-open-letter-2-future-developers/","relativePath":"docs/community/an-open-letter-2-future-developers.md","relativeDir":"docs/community","base":"an-open-letter-2-future-developers.md","name":"an-open-letter-2-future-developers","frontmatter":{"title":"New Developers","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"An open letter to future developers","description":"Why are frameworks useful","robots":[],"extra":[]},"template":"docs"},"html":"<h2>1. Why are frameworks useful?</h2>\n<p>Essentially the allure of these is the amount of time that is saved and the resulting efficiency in getting a project rolled out faster because there's a lot less of the initial work to be done.</p>\n<p>Frameworks take care of tasks like default browser settings, file structures, and layout templates for your website. This automation generates a uniform design for page elements like text, tables, forms, and buttons, amongst other things. Even complex navigation menus become standardized with frameworks as it can be consistently applied across your website with ease.</p>\n<h2>2. Types of framework</h2>\n<p>There are many different kinds of this platform available for programmers. Typically, like a lot of things within this discipline can be split between <a href=\"https://careerfoundry.com/en/blog/web-development/whats-the-difference-between-frontend-and-backend/\">frontend and backend development</a>---first let's make the distinction between the two to help you understand the usefulness of these solutions.</p>\n<h3>Backend frameworks</h3>\n<p>These are designed to make the responsibility of interacting with the database an easier endeavor for the developer. It automates a lot of functions and processes that web developers use to record and retrieve user-inputted data.</p>\n<h3>Frontend frameworks</h3>\n<p>As the name suggests, these are very helpful on the presentation side of the website, creating a good foundation from which to build pages. These frameworks combine HTML, CSS, and <a href=\"https://careerfoundry.com/en/blog/web-development/how-long-does-it-take-to-learn-javascript/\">Javascript</a> to be really effective in creating conventions for various elements. Typically frontend web developers use them in conjunction with <a href=\"https://careerfoundry.com/en/blog/web-development/7-essential-tools-for-front-end-development/\">other effective tools</a>.</p>\n<p><a href=\"https://careerfoundry.com/en/blog/web-development/what-is-html-a-beginners-guide/\">HTML</a> conventions allow for standardization for elements like typography, while <a href=\"https://careerfoundry.com/en/blog/web-development/what-is-css/\">CSS</a> conventions can help standardize positioning of elements in a grid-like system on the pages. This makes it easier for the developer to arrange and organize elements into a simple and uniform design across multiple displays and browsers. Javascript conventions offer the ability to style more advanced components like image carousels, lightboxes, button behaviors, and pop-ups.</p>\n<p>On another note, there are Javascript frameworks that focus on full application support---like AngularJS and Reactjs. Libraries of Javascript code like <a href=\"https://careerfoundry.com/en/blog/web-development/javascript-vs-jquery-whats-the-difference/\">jQuery</a> are also helpful in developing conventions that can be readily implemented in websites.</p>\n<p>To recap, the use of these tools helps the developer get up and running quickly without having to get bogged down with the initial hurdles that come with setting up a website. It creates uniform code across all pages of your website and presents a clean look for users. This in turn solves common issues like typography consistency and positioning difficulties on different pages.</p>\n<p>Best of all, frontend frameworks resolve any issues with browser compatibility and are key to responsive web design, which we'll discuss further on.</p>\n<h4>Curious about a careerin Web Development?</h4>\n<p>Start learning for free!</p>\n<p><a href=\"https://careerfoundry.com/en/short-courses/become-a-web-developer/?popup-tracking=blog-inline-DEV\">\n<img src=\"https://careerfoundry.com/en/wp-content/uploads/2021/07/web-image@3x.jpg\" alt=\"image\"></a></p>\n<h2>3. Popular frameworks</h2>\n<p>There are many of these tools that have become must-haves for beginner and expert web developers alike. As well as different languages, they focus on different directives and outcomes.</p>\n<p>One of the most popular frameworks is <a href=\"https://careerfoundry.com/en/blog/web-development/what-is-bootstrap-a-beginners-guide/\">Bootstrap, which was originally developed by Twitter</a> to maintain consistency in their interface development. It's very polished and efficient, and makes website development easier and faster. It has standardized conventions that are well recognized for HTML elements like buttons, alerts, forms, and typography.</p>\n<p>So popular that it's now known simply as \"Rails,\" <a href=\"https://careerfoundry.com/en/blog/web-development/should-i-learn-ruby-on-rails/\">Ruby on Rails </a>has revolutionised this language. As well as making it one of the <a href=\"https://careerfoundry.com/en/blog/web-development/easiest-programming-languages/\">easier programming languages to learn</a>, Rails is particularly popular with beginners looking to code full-stack early on in their careers.</p>\n<p>Foundation was created from the Zurb style guide and much like Bootstrap, offers a complete solution for front-end design. Many large companies like Facebook, Yahoo, and Ebay utilize Foundation in their layouts. The framework encourages web developers to expand on the conventions and personalize them for developers' websites.</p>\n<p>Skeleton is a lighter example that doesn't come with all the bells and whistles that accompany the heavy-lifters like Bootstrap and Foundation. This encourages greater customization by only providing styling on the most basic and necessary elements. Developers who only need specific components to be styled utilize light-weight frameworks like Skeleton to achieve their goals.</p>\n<p>A simple Google search will turn up a lot of results for top tools being used and recommended. It's definitely beneficial to check out the different options and see which suits your development needs and design goals.</p>\n<h2>4. How do I use frameworks?</h2>\n<p>Regardless of whether a developer uses a full frontend framework like Bootstrap or a lightweight option like Skeleton, these are efficient tools that should be seriously considered in every developer's process.</p>\n<p>Recognized frameworks offer more ease in collaboration as developers can access the same libraries for design conventions without having to resort to individual opinionated decisions. Additionally, there is support from the specific community with tutorials and articles on how to effectively use it.</p>\n<p>The ease of implementation and efficiency makes it almost a necessity to employ these tools in a web developer's process. Any time a programmer is finding themselves creating an ever-growing proprietary list of CSS rules, it's probably a good idea to look into using a framework to tidy things up.</p>\n<h2>5. What is a responsive framework?</h2>\n<p>One of the best features of these systems is that they help create websites that are easily accessible and are able to be viewed across different browsers on different devices. A lot of frameworks accomplish this with dynamic code---utilizing classes that can be reused and formatted to take into consideration the device and/or browser that is being used.</p>\n<p>In other words, the layouts of webpages will change---certain elements will disappear and text will be smaller on smaller screens, while certain Javascript elements might not take effect at all. On larger screens, the extra real estate can be used to showcase higher quality images and more sophisticated design elements, as well as allowing for the white space beloved by web designers.</p>\n<p>In this current age when users are <a href=\"https://www.statista.com/statistics/277125/share-of-website-traffic-coming-from-mobile-devices/\">more likely to view websites on their mobile devices</a> than their computers, it's important to have a mobile responsive website that creates an enriching user experience no matter what interface the user interacts with. In this video, our in-house web developer Abhi explains more about styling a mobile-responsive website with CSS:</p>\n<h2>6. Final thoughts</h2>\n<p>Critics of frontend frameworks cite them as the source of a lot of cookie-cutter websites that are identical in appearance and interaction. This however, is an oversimplification. Why? Let's go back to the cooking example: a spatula is just a spatula---a lot of people have one and use the tool in the kitchen. But the food that is created will vary wildly across the spectrum, depending on the cook.</p>\n<p>In the same light, frontend frameworks are simply a tool that can be employed to create diverse and distinctive websites. Yes they're efficient, but it's up to the developer to make sure they're effective.</p>\n<p>If you want to learn some more about web development right now, these articles may interest you:</p>\n<ul>\n<li><a href=\"https://careerfoundry.com/en/blog/web-development/best-coding-bootcamps/\">A Guide To The Best Web Development Bootcamps And How To Choose One</a></li>\n<li>-</li>\n<li><a href=\"https://careerfoundry.com/en/blog/web-development/in-demand-web-developer-skills/\">The Most In-Demand Web Developer Skills in 2021</a></li>\n<li><a href=\"https://careerfoundry.com/en/blog/web-development/5-latest-trends-in-web-development/\">5 Web Development Trends To Watch This Year</a></li>\n</ul>"},{"url":"/docs/career/project-links/","relativePath":"docs/career/project-links.md","relativeDir":"docs/career","base":"project-links.md","name":"project-links","frontmatter":{"title":"Projects ","excerpt":"We'd love it if you participate in the Web-Dev-Hubcommunity. Find out how to get connected.","seo":{"title":"List Of Projects","description":"introductory-react-part-2\na-very-quick-guide-to-calculating-big-o-computational-complexity\nintroduction-to-react css-animations\n","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"List Of Projects Articles","keyName":"property"},{"name":"og:description","value":"","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"List Of Projectss"},{"name":"twitter:description","value":"This is the community page"},{"name":"og:image","value":"images/beige-maple.png","keyName":"property","relativeUrl":true}]},"template":"docs","weight":0},"html":"<ol>\n<li><a href=\"https://web-dev-resource-hub.netlify.app\">WEB DEV RESOURCE HUB</a></li>\n<li><a href=\"https://learning-redux42.netlify.app/\">Learn Redux</a></li>\n<li><a href=\"https://trusting-dijkstra-4d3b17.netlify.app\">Data Structures Website</a></li>\n<li><a href=\"https://web-dev-interview-prep-quiz-website.netlify.app/intro-js2.html\">Web-Dev-Quizzes</a></li>\n<li><a href=\"https://zen-lamport-5aab2c.netlify.app\">Recursion</a></li>\n<li><a href=\"https://csb-ov0d1-bgoonz.vercel.app/\">React Documentation Site</a></li>\n<li><a href=\"https://amazing-hodgkin-33aea6.netlify.app\">Blogs-from-webdevhub</a></li>\n<li><a href=\"https://angry-fermat-dcf5dd.netlify.app\">Realty Website Demo</a></li>\n<li><a href=\"https://boring-heisenberg-f425d8.netlify.app\">Best-Prac &#x26; Tools</a></li>\n<li><a href=\"https://site-analysis.netlify.app/\">site-analysis</a></li>\n<li><a href=\"https://clever-bartik-b5ba19.netlify.app\">a/AOpen Notes</a></li>\n<li><a href=\"https://code-playground.netlify.app\">Iframe Embed Playground</a></li>\n<li><a href=\"https://condescending-lewin-c96727.netlify.app\">Triggered Effects Guitar Platform</a></li>\n<li><a href=\"https://determined-dijkstra-666766.netlify.app\">Live Form</a></li>\n<li><a href=\"https://determined-dijkstra-ee7390.netlify.app\">Interview Questions</a></li>\n<li><a href=\"https://eager-northcutt-456076.netlify.app\">Resources Compilation</a></li>\n<li><a href=\"https://ecstatic-jang-593fd1.netlify.app\">React Blog Depreciated</a></li>\n<li><a href=\"https://eloquent-sammet-ba1810.netlify.app\">MihirBeg.com</a></li>\n<li><a href=\"https://embedable-content.netlify.app\">Embeded Html Projects</a></li>\n<li><a href=\"https://festive-borg-e4d856.netlify.app\">Cheat Sheets</a></li>\n<li><a href=\"https://focused-pasteur-0faac8.netlify.app\">Early Version Of WebDevHub</a></li>\n<li><a href=\"https://gists42.netlify.app\">My Gists</a></li>\n<li><a href=\"https://gracious-raman-474030.netlify.app\">DS-Algo-Links</a></li>\n<li><a href=\"https://happy-mestorf-0f8e75.netlify.app\">Video Chat App</a></li>\n<li><a href=\"https://hungry-shaw-30d504.netlify.app\">Ciriculumn</a></li>\n<li><a href=\"https://inspiring-jennings-d14689.netlify.app\">Cheat Sheets</a></li>\n<li><a href=\"https://links4242.netlify.app\">Links</a></li>\n<li><a href=\"https://modest-booth-4e17df.netlify.app\">Medium Articles</a></li>\n<li><a href=\"https://modest-torvalds-34afbc.netlify.app\">NextJS Blog Template</a></li>\n<li><a href=\"https://modest-varahamihira-772b59.netlify.app\">React Demo</a></li>\n<li><a href=\"https://nervous-swartz-0ab2cc.netlify.app\">Ecomerce Norwex V1</a></li>\n<li><a href=\"https://objective-borg-a327cd.netlify.app\">Gifs</a></li>\n<li><a href=\"https://pedantic-wing-adbf82.netlify.app\">Excel2HTML</a></li>\n<li><a href=\"https://pensive-meitner-1ea8c4.netlify.app\">Data Structures Site</a></li>\n<li><a href=\"https://portfolio42.netlify.app\">Portfolio</a></li>\n<li><a href=\"https://priceless-shaw-86ccb2.netlify.app\">Page Templates</a></li>\n<li><a href=\"https://quizzical-mcnulty-fa09f2.netlify.app\">Photo Gallary</a></li>\n<li><a href=\"https://relaxed-bhaskara-dc85ec.netlify.app\">Coffee Website</a></li>\n<li><a href=\"https://romantic-hamilton-514b79.netlify.app\">Awesome Resources</a></li>\n<li><a href=\"https://silly-lichterman-b22b5f.netlify.app\">Cheat Sheets</a></li>\n<li><a href=\"https://silly-shirley-ec955e.netlify.app\">Link City</a></li>\n<li><a href=\"https://stoic-mccarthy-2c335f.netlify.app\">VSCODE Extensions</a></li>\n<li><a href=\"https://web-dev-resource-hub-manual-deploy.netlify.app\">webdevhub manual attempt</a></li>\n<li><a href=\"https://wonderful-pasteur-392fbe.netlify.app\">Norwex Resources</a></li>\n<li><a href=\"https://zen-bhabha-bd046f.netlify.app\">idk</a></li>\n<li><a href=\"https://getting-started42.herokuapp.com/\">heroku bare bones template</a></li>\n<li><a href=\"https://bad-reads42.herokuapp.com/\">bad reads</a></li>\n<li><a href=\"https://documentation-site-react2.vercel.app/\">docusaurus</a></li>\n<li><a href=\"https://app.stackbit.com/studio/609b2d7c71a5dd0016f36326\">stackbit</a></li>\n</ol>\n<hr>\n<h1>More</h1>\n<ul>\n<li><a href=\"https://admiring-montalcini-965c0b.netlify.app\">https://admiring-montalcini-965c0b</a></li>\n<li><a href=\"https://adoring-carson-fac9fb.netlify.app\">https://adoring-carson-fac9fb</a></li>\n<li><a href=\"https://adoring-nobel-85c068.netlify.app\">https://adoring-nobel-85c068</a></li>\n<li><a href=\"https://bg-portfolio.netlify.app\">https://bg-portfolio</a></li>\n<li><a href=\"https://bg-resume.netlify.app\">https://bg-resume</a></li>\n<li><a href=\"https://bgoonz-blog-v3-0.netlify.app\">https://bgoonz-blog-v3-0</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app\">https://bgoonz-blog</a></li>\n<li><a href=\"https://bgoonz-bookmarks.netlify.app\">https://bgoonz-bookmarks</a></li>\n<li><a href=\"https://bgoonz-cv.netlify.app\">https://bgoonz-cv</a></li>\n<li><a href=\"https://bgoonz-games.netlify.app\">https://bgoonz-games</a></li>\n<li><a href=\"https://bgoonzblog20-backup.netlify.app\">https://bgoonzblog20-backup</a></li>\n<li><a href=\"https://bgoonzblog20-redo.netlify.app\">https://bgoonzblog20-redo</a></li>\n<li><a href=\"https://bgoonzblog20starter.netlify.app\">https://bgoonzblog20starter</a></li>\n<li><a href=\"https://bgoonzblog30.netlify.app\">https://bgoonzblog30</a></li>\n<li><a href=\"https://bgoonzconnekt4.netlify.app\">https://bgoonzconnekt4</a></li>\n<li><a href=\"https://bgoonzgist\">https://bgoonzgist</a></li>\n<li><a href=\"https://bgoonzmedium.netlify.app\">https://bgoonzmedium</a></li>\n<li><a href=\"https://bicknborty.netlify.app\">https://bicknborty</a></li>\n<li><a href=\"https://blog-v42-31eba.netlify.app\">https://blog-v42-31eba</a></li>\n<li><a href=\"https://blog3-backup-dd7df.netlify.app\">https://blog3-backup-dd7df</a></li>\n<li><a href=\"https://cheatsheets42\">https://cheatsheets42</a></li>\n<li><a href=\"https://clever-ramanujan-f9ce0a.netlify.app\">https://clever-ramanujan-f9ce0a</a></li>\n<li><a href=\"https://code-playground.netlify.app\">https://code-playground</a></li>\n<li><a href=\"https://condescending-lewin-c96727.netlify.app\">https://condescending-lewin-c96727</a></li>\n<li><a href=\"https://curious-rabbit-f33af.netlify.app\">https://curious-rabbit-f33af</a></li>\n<li><a href=\"https://determined-dijkstra-ee7390\">https://determined-dijkstra-ee7390</a></li>\n<li><a href=\"https://dev-journal42.netlify.app\">https://dev-journal42</a></li>\n<li><a href=\"https://devtools42.netlify.app\">https://devtools42</a></li>\n<li><a href=\"https://docs42.netlify.app\">https://docs42</a></li>\n<li><a href=\"https://ds-algo-official.netlify.app\">https://ds-algo-official</a></li>\n<li><a href=\"https://ds-unit-5-lambda\">https://ds-unit-5-lambda</a></li>\n<li><a href=\"https://elegant-goodall-566182\">https://elegant-goodall-566182</a></li>\n<li><a href=\"https://elite-cabbage-3551b.netlify.app\">https://elite-cabbage-3551b</a></li>\n<li><a href=\"https://enthusiastic-tomato-a7ebc\">https://enthusiastic-tomato-a7ebc</a></li>\n<li><a href=\"https://exploring-next-sanity.netlify.app\">https://exploring-next-sanity</a></li>\n<li><a href=\"https://festive-elion-13b19c.netlify.app\">https://festive-elion-13b19c</a></li>\n<li><a href=\"https://festive-kilby-f0a784\">https://festive-kilby-f0a784</a></li>\n<li><a href=\"https://flamboyant-northcutt-14b025.netlify.app\">https://flamboyant-northcutt-14b025</a></li>\n<li><a href=\"https://fourm-builder-gui.netlify.app\">https://fourm-builder-gui</a></li>\n<li><a href=\"https://friendly-amaranth-51833.netlify.app\">https://friendly-amaranth-51833</a></li>\n<li><a href=\"https://friendly-poincare-a11e2f.netlify.app\">https://friendly-poincare-a11e2f</a></li>\n<li><a href=\"https://githtmlpreview.netlify.app\">https://githtmlpreview</a></li>\n<li><a href=\"https://github.com/bgoonz/alternate-blog-theme\">https://github.com/bgoonz/alternate-blog-theme</a></li>\n<li><a href=\"https://github.com/bgoonz/atlassian-templates\">https://github.com/bgoonz/atlassian-templates</a></li>\n<li><a href=\"https://github.com/bgoonz/bgoonz.github.io\">https://github.com/bgoonz/bgoonz.github.io</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZBLOG2.0STABLE\">https://github.com/bgoonz/BGOONZBLOG2.0STABLE</a></li>\n<li><a href=\"https://github.com/bgoonz/bgoonzblog3.0\">https://github.com/bgoonz/bgoonzblog3.0</a></li>\n<li><a href=\"https://github.com/bgoonz/blog-research\">https://github.com/bgoonz/blog-research</a></li>\n<li><a href=\"https://github.com/bgoonz/blog-v42\">https://github.com/bgoonz/blog-v42</a></li>\n<li><a href=\"https://github.com/bgoonz/blog3-backup\">https://github.com/bgoonz/blog3-backup</a></li>\n<li><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store42\">https://github.com/bgoonz/commercejs-nextjs-demo-store42</a></li>\n<li><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store\">https://github.com/bgoonz/commercejs-nextjs-demo-store</a></li>\n<li><a href=\"https://github.com/bgoonz/Common-npm-Readme-Compilation\">https://github.com/bgoonz/Common-npm-Readme-Compilation</a></li>\n<li><a href=\"https://github.com/bgoonz/Connect-Four-Final-Version\">https://github.com/bgoonz/Connect-Four-Final-Version</a></li>\n<li><a href=\"https://github.com/bgoonz/cool-hickory\">https://github.com/bgoonz/cool-hickory</a></li>\n<li><a href=\"https://github.com/bgoonz/Cumulative-Resource-List\">https://github.com/bgoonz/Cumulative-Resource-List</a></li>\n<li><a href=\"https://github.com/bgoonz/curious-eggplant\">https://github.com/bgoonz/curious-eggplant</a></li>\n<li><a href=\"https://github.com/bgoonz/curious-zebra\">https://github.com/bgoonz/curious-zebra</a></li>\n<li><a href=\"https://github.com/bgoonz/Data-Struc-Static\">https://github.com/bgoonz/Data-Struc-Static</a></li>\n<li><a href=\"https://github.com/bgoonz/docs-collection\">https://github.com/bgoonz/docs-collection</a></li>\n<li><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">https://github.com/bgoonz/DS-ALGO-OFFICIAL</a></li>\n<li><a href=\"https://github.com/bgoonz/ecommerce-interactive\">https://github.com/bgoonz/ecommerce-interactive</a></li>\n<li><a href=\"https://github.com/bgoonz/ecommerce-react\">https://github.com/bgoonz/ecommerce-react</a></li>\n<li><a href=\"https://github.com/bgoonz/elite-cabbage\">https://github.com/bgoonz/elite-cabbage</a></li>\n<li><a href=\"https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground\">https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground</a></li>\n<li><a href=\"https://github.com/bgoonz/excel2html-table\">https://github.com/bgoonz/excel2html-table</a></li>\n<li><a href=\"https://github.com/bgoonz/form-builder-vanilla-js\">https://github.com/bgoonz/form-builder-vanilla-js</a></li>\n<li><a href=\"https://github.com/bgoonz/friendly-amaranth\">https://github.com/bgoonz/friendly-amaranth</a></li>\n<li><a href=\"https://github.com/bgoonz/Games\">https://github.com/bgoonz/Games</a></li>\n<li><a href=\"https://github.com/bgoonz/gatsby-netlify-cms\">https://github.com/bgoonz/gatsby-netlify-cms</a></li>\n<li><a href=\"https://github.com/bgoonz/gatsby-starter-portfolio-cara\">https://github.com/bgoonz/gatsby-starter-portfolio-cara</a></li>\n<li><a href=\"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL\">https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL</a></li>\n<li><a href=\"https://github.com/bgoonz/graceful-pine\">https://github.com/bgoonz/graceful-pine</a></li>\n<li><a href=\"https://github.com/bgoonz/html-resume\">https://github.com/bgoonz/html-resume</a></li>\n<li><a href=\"https://github.com/bgoonz/https___mihirbeg.com_\">https://github.com/bgoonz/https<em>__mihirbeg.com</em></a></li>\n<li><a href=\"https://github.com/bgoonz/hugo-cms\">https://github.com/bgoonz/hugo-cms</a></li>\n<li><a href=\"https://github.com/bgoonz/iframe-showcase\">https://github.com/bgoonz/iframe-showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/interesting-aspen\">https://github.com/bgoonz/interesting-aspen</a></li>\n<li><a href=\"https://github.com/bgoonz/jamstack-comments-engine1\">https://github.com/bgoonz/jamstack-comments-engine1</a></li>\n<li><a href=\"https://github.com/bgoonz/jamstack-comments-engine2\">https://github.com/bgoonz/jamstack-comments-engine2</a></li>\n<li><a href=\"https://github.com/bgoonz/jamstack-comments-engine\">https://github.com/bgoonz/jamstack-comments-engine</a></li>\n<li><a href=\"https://github.com/bgoonz/kind-petunia\">https://github.com/bgoonz/kind-petunia</a></li>\n<li><a href=\"https://github.com/bgoonz/lambda-prep\">https://github.com/bgoonz/lambda-prep</a></li>\n<li><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\">https://github.com/bgoonz/Lambda-Resource-Static-Assets</a></li>\n<li><a href=\"https://github.com/bgoonz/Lambda\">https://github.com/bgoonz/Lambda</a></li>\n<li><a href=\"https://github.com/bgoonz/Links-Shortcut-Site\">https://github.com/bgoonz/Links-Shortcut-Site</a></li>\n<li><a href=\"https://github.com/bgoonz/live-form\">https://github.com/bgoonz/live-form</a></li>\n<li><a href=\"https://github.com/bgoonz/Live-htmlRendered-Mocha-Spec--Recursion-Practice\">https://github.com/bgoonz/Live-htmlRendered-Mocha-Spec--Recursion-Practice</a></li>\n<li><a href=\"https://github.com/bgoonz/marvelous-aluminum\">https://github.com/bgoonz/marvelous-aluminum</a></li>\n<li><a href=\"https://github.com/bgoonz/meditation-app\">https://github.com/bgoonz/meditation-app</a></li>\n<li><a href=\"https://github.com/bgoonz/Medium_Articles\">https://github.com/bgoonz/Medium_Articles</a></li>\n<li><a href=\"https://github.com/bgoonz/MihirBegMusicLab\">https://github.com/bgoonz/MihirBegMusicLab</a></li>\n<li><a href=\"https://github.com/bgoonz/Mihir_Beg_Final\">https://github.com/bgoonz/Mihir<em>Beg</em>Final</a></li>\n<li><a href=\"https://github.com/bgoonz/mini-project-showcase\">https://github.com/bgoonz/mini-project-showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/modern-triceratops\">https://github.com/bgoonz/modern-triceratops</a></li>\n<li><a href=\"https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard\">https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard</a></li>\n<li><a href=\"https://github.com/bgoonz/My-Medium-Blog\">https://github.com/bgoonz/My-Medium-Blog</a></li>\n<li><a href=\"https://github.com/bgoonz/nervous-parsley\">https://github.com/bgoonz/nervous-parsley</a></li>\n<li><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template2\">https://github.com/bgoonz/nextjs-netlify-blog-template2</a></li>\n<li><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template42\">https://github.com/bgoonz/nextjs-netlify-blog-template42</a></li>\n<li><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template\">https://github.com/bgoonz/nextjs-netlify-blog-template</a></li>\n<li><a href=\"https://github.com/bgoonz/norwex-react\">https://github.com/bgoonz/norwex-react</a></li>\n<li><a href=\"https://github.com/bgoonz/ntn-boilerplate\">https://github.com/bgoonz/ntn-boilerplate</a></li>\n<li><a href=\"https://github.com/bgoonz/oval-cabbage\">https://github.com/bgoonz/oval-cabbage</a></li>\n<li><a href=\"https://github.com/bgoonz/panoramic-eggplant\">https://github.com/bgoonz/panoramic-eggplant</a></li>\n<li><a href=\"https://github.com/bgoonz/Potluck-Planner\">https://github.com/bgoonz/Potluck-Planner</a></li>\n<li><a href=\"https://github.com/bgoonz/Project-Showcase\">https://github.com/bgoonz/Project-Showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/python-playground-embed\">https://github.com/bgoonz/python-playground-embed</a></li>\n<li><a href=\"https://github.com/bgoonz/PYTHON_PRAC\">https://github.com/bgoonz/PYTHON_PRAC</a></li>\n<li><a href=\"https://github.com/bgoonz/random-list-of-embedable-content\">https://github.com/bgoonz/random-list-of-embedable-content</a></li>\n<li><a href=\"https://github.com/bgoonz/random-static-html-page-deploy\">https://github.com/bgoonz/random-static-html-page-deploy</a></li>\n<li><a href=\"https://github.com/bgoonz/React-Practice\">https://github.com/bgoonz/React-Practice</a></li>\n<li><a href=\"https://github.com/bgoonz/react-web-anki-flash-cards\">https://github.com/bgoonz/react-web-anki-flash-cards</a></li>\n<li><a href=\"https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering\">https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-catalyst\">https://github.com/bgoonz/sanity-catalyst</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-commercelayer1\">https://github.com/bgoonz/sanity-commercelayer1</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-commercelayer\">https://github.com/bgoonz/sanity-commercelayer</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-blog3\">https://github.com/bgoonz/sanity-gatsby-blog3</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-blog4\">https://github.com/bgoonz/sanity-gatsby-blog4</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-blog\">https://github.com/bgoonz/sanity-gatsby-blog</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-hey-sugar2\">https://github.com/bgoonz/sanity-gatsby-hey-sugar2</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-hey-sugar5\">https://github.com/bgoonz/sanity-gatsby-hey-sugar5</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-hey-sugar\">https://github.com/bgoonz/sanity-gatsby-hey-sugar</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-portfolio3\">https://github.com/bgoonz/sanity-gatsby-portfolio3</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-portfolio\">https://github.com/bgoonz/sanity-gatsby-portfolio</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-jigsaw-blog\">https://github.com/bgoonz/sanity-jigsaw-blog</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-kitchen-sink2\">https://github.com/bgoonz/sanity-kitchen-sink2</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-kitchen-sink3\">https://github.com/bgoonz/sanity-kitchen-sink3</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-kitchen-sink5\">https://github.com/bgoonz/sanity-kitchen-sink5</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-kitchen-sink\">https://github.com/bgoonz/sanity-kitchen-sink</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-nuxt-events\">https://github.com/bgoonz/sanity-nuxt-events</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-translation-examples\">https://github.com/bgoonz/sanity-translation-examples</a></li>\n<li><a href=\"https://github.com/bgoonz/scope-closure-context\">https://github.com/bgoonz/scope-closure-context</a></li>\n<li><a href=\"https://github.com/bgoonz/searching-bick-n-borty-api\">https://github.com/bgoonz/searching-bick-n-borty-api</a></li>\n<li><a href=\"https://github.com/bgoonz/site-analysis\">https://github.com/bgoonz/site-analysis</a></li>\n<li><a href=\"https://github.com/bgoonz/smart-artichoke\">https://github.com/bgoonz/smart-artichoke</a></li>\n<li><a href=\"https://github.com/bgoonz/Standalone-Metranome\">https://github.com/bgoonz/Standalone-Metranome</a></li>\n<li><a href=\"https://github.com/bgoonz/starter\">https://github.com/bgoonz/starter</a></li>\n<li><a href=\"https://github.com/bgoonz/successful-cabbage\">https://github.com/bgoonz/successful-cabbage</a></li>\n<li><a href=\"https://github.com/bgoonz/Ternary-converter\">https://github.com/bgoonz/Ternary-converter</a></li>\n<li><a href=\"https://github.com/bgoonz/terrific-dolphin\">https://github.com/bgoonz/terrific-dolphin</a></li>\n<li><a href=\"https://github.com/bgoonz/TetrisJS\">https://github.com/bgoonz/TetrisJS</a></li>\n<li><a href=\"https://github.com/bgoonz/TexTools\">https://github.com/bgoonz/TexTools</a></li>\n<li><a href=\"https://github.com/bgoonz/vscode-Extension-readmes\">https://github.com/bgoonz/vscode-Extension-readmes</a></li>\n<li><a href=\"https://github.com/bgoonz/web-dev-interview-prep-quiz-website\">https://github.com/bgoonz/web-dev-interview-prep-quiz-website</a></li>\n<li><a href=\"https://github.com/bgoonz/web-dev-notes-backup\">https://github.com/bgoonz/web-dev-notes-backup</a></li>\n<li><a href=\"https://github.com/bgoonz/week-10-take-2\">https://github.com/bgoonz/week-10-take-2</a></li>\n<li><a href=\"https://github.com/bgoonz/yellowcake-mailchimp\">https://github.com/bgoonz/yellowcake-mailchimp</a></li>\n<li><a href=\"https://github.com/bgoonz/zumzi-chat-messenger\">https://github.com/bgoonz/zumzi-chat-messenger</a></li>\n<li><a href=\"https://github.com/my-lambda-projects/peer\">https://github.com/my-lambda-projects/peer</a></li>\n<li><a href=\"https://github.com/side-projects-42/DS-Bash-Examples-Deploy\">https://github.com/side-projects-42/DS-Bash-Examples-Deploy</a></li>\n<li><a href=\"https://github.com/side-projects-42/friendly-panda\">https://github.com/side-projects-42/friendly-panda</a></li>\n<li><a href=\"https://github.com/side-projects-42/superb-celery\">https://github.com/side-projects-42/superb-celery</a></li>\n<li><a href=\"https://github.com/stackbit-projects/best-celery-b2d7c\">https://github.com/stackbit-projects/best-celery-b2d7c</a></li>\n<li><a href=\"https://github.com/stackbit-projects/curious-rabbit-f33af\">https://github.com/stackbit-projects/curious-rabbit-f33af</a></li>\n<li><a href=\"https://github.com/stackbit-projects/oceanic-pluto-4029d\">https://github.com/stackbit-projects/oceanic-pluto-4029d</a></li>\n<li><a href=\"https://github.com/stackbit-projects/splendid-onion-b0ec3\">https://github.com/stackbit-projects/splendid-onion-b0ec3</a></li>\n<li><a href=\"https://github.com/Web-Dev-Collaborative/fractions-visualizations-n-resources\">https://github.com/Web-Dev-Collaborative/fractions-visualizations-n-resources</a></li>\n<li><a href=\"https://gitlab.com/bryan.guner.dev/algo-prac\">https://gitlab.com/bryan.guner.dev/algo-prac</a></li>\n<li><a href=\"https://gitlab.com/bryan.guner.dev/one-click-hugo-cms\">https://gitlab.com/bryan.guner.dev/one-click-hugo-cms</a></li>\n<li><a href=\"https://gitlab.com/bryan.guner.dev/starter-hugo-online-course\">https://gitlab.com/bryan.guner.dev/starter-hugo-online-course</a></li>\n<li><a href=\"https://goofy-curran-95aa66.netlify.app\">https://goofy-curran-95aa66</a></li>\n<li><a href=\"https://gracious-raman-474030.netlify.app\">https://gracious-raman-474030</a></li>\n<li><a href=\"https://happy-mestorf-0f8e75.netlify.app\">https://happy-mestorf-0f8e75</a></li>\n<li><a href=\"https://hardcore-hamilton-c5b45e.netlify.app\">https://hardcore-hamilton-c5b45e</a></li>\n<li><a href=\"https://hardcore-lamport-7eb855.netlify.app\">https://hardcore-lamport-7eb855</a></li>\n<li><a href=\"https://hopeful-shockley-150bee.netlify.app\">https://hopeful-shockley-150bee</a></li>\n<li><a href=\"https://hugo-cms-42.netlify.app\">https://hugo-cms-42</a></li>\n<li><a href=\"https://hungry-shaw-30d504\">https://hungry-shaw-30d504</a></li>\n<li><a href=\"https://iframeshowcase.netlify.app\">https://iframeshowcase</a></li>\n<li><a href=\"https://interesting-aspen-ce986.netlify.app\">https://interesting-aspen-ce986</a></li>\n<li><a href=\"https://jovial-agnesi-8ec8b1.netlify.app\">https://jovial-agnesi-8ec8b1</a></li>\n<li><a href=\"https://jovial-keller-063835.netlify.app\">https://jovial-keller-063835</a></li>\n<li><a href=\"https://keen-williams-48be7c\">https://keen-williams-48be7c</a></li>\n<li><a href=\"https://kguner-fractions-website.netlify.app\">https://kguner-fractions-website</a></li>\n<li><a href=\"https://kind-petunia-e8f9f.netlify.app\">https://kind-petunia-e8f9f</a></li>\n<li><a href=\"https://lambda-prep.netlify.app\">https://lambda-prep</a></li>\n<li><a href=\"https://lambda-resources.netlify.app\">https://lambda-resources</a></li>\n<li><a href=\"https://learning-redux42\">https://learning-redux42</a></li>\n<li><a href=\"https://links4242.netlify.app\">https://links4242</a></li>\n<li><a href=\"https://live-form.netlify.app\">https://live-form</a></li>\n<li><a href=\"https://marvelous-aluminum-11a84.netlify.app\">https://marvelous-aluminum-11a84</a></li>\n<li><a href=\"https://meditate42app.netlify.app\">https://meditate42app</a></li>\n<li><a href=\"https://memes42069.netlify.app\">https://memes42069</a></li>\n<li><a href=\"https://mihirbeg28.netlify.app\">https://mihirbeg28</a></li>\n<li><a href=\"https://mihirbegmusiclab.netlify.app\">https://mihirbegmusiclab</a></li>\n<li><a href=\"https://mihirbegmusic.netlify.app\">https://mihirbegmusic</a></li>\n<li><a href=\"https://modest-booth-4e17df.netlify.app\">https://modest-booth-4e17df</a></li>\n<li><a href=\"https://nervous-swartz-0ab2cc.netlify.app\">https://nervous-swartz-0ab2cc</a></li>\n<li><a href=\"https://norwex-next-js.netlify.app\">https://norwex-next-js</a></li>\n<li><a href=\"https://objective-rosalind-d4ff71.netlify.app\">https://objective-rosalind-d4ff71</a></li>\n<li><a href=\"https://objective-torvalds-1c12dd.netlify.app\">https://objective-torvalds-1c12dd</a></li>\n<li><a href=\"https://optimistic-curie-ddd352.netlify.app\">https://optimistic-curie-ddd352</a></li>\n<li><a href=\"https://oval-cabbage-354f6.netlify.app\">https://oval-cabbage-354f6</a></li>\n<li><a href=\"https://pedantic-wing-adbf82.netlify.app\">https://pedantic-wing-adbf82</a></li>\n<li><a href=\"https://portfolio42.netlify.app\">https://portfolio42</a></li>\n<li><a href=\"https://potluck-landing.netlify.app\">https://potluck-landing</a></li>\n<li><a href=\"https://priceless-shaw-86ccb2.netlify.app\">https://priceless-shaw-86ccb2</a></li>\n<li><a href=\"https://project-portfolio42.netlify.app\">https://project-portfolio42</a></li>\n<li><a href=\"https://project-showcase-bgoonz.netlify.app\">https://project-showcase-bgoonz</a></li>\n<li><a href=\"https://py-prac-42.netlify.app\">https://py-prac-42</a></li>\n<li><a href=\"https://python-playground42.netlify.app\">https://python-playground42</a></li>\n<li><a href=\"https://python-playground43\">https://python-playground43</a></li>\n<li><a href=\"https://quirky-meninsky-4181b5.netlify.app\">https://quirky-meninsky-4181b5</a></li>\n<li><a href=\"https://random-embedable-content.netlify.app\">https://random-embedable-content</a></li>\n<li><a href=\"https://random-static-html-deploys.netlify.app\">https://random-static-html-deploys</a></li>\n<li><a href=\"https://react-blog-1.netlify.app\">https://react-blog-1</a></li>\n<li><a href=\"https://recursion-prompts.netlify.app\">https://recursion-prompts</a></li>\n<li><a href=\"https://resourcerepo2\">https://resourcerepo2</a></li>\n<li><a href=\"https://romantic-hamilton-514b79.netlify.app\">https://romantic-hamilton-514b79</a></li>\n<li><a href=\"https://sad-ramanujan-235384\">https://sad-ramanujan-235384</a></li>\n<li><a href=\"https://sanity-catalyst-studio-njajg3jt.netlify.app\">https://sanity-catalyst-studio-njajg3jt</a></li>\n<li><a href=\"https://sanity-catalyst-web-1zjgvx2t\">https://sanity-catalyst-web-1zjgvx2t</a></li>\n<li><a href=\"https://sanity-commercelayer-1-studio-rkmntw55.netlify.app\">https://sanity-commercelayer-1-studio-rkmntw55</a></li>\n<li><a href=\"https://sanity-commercelayer-1-web\">https://sanity-commercelayer-1-web</a></li>\n<li><a href=\"https://sanity-commercelayer-studio-nzbh7yx7\">https://sanity-commercelayer-studio-nzbh7yx7</a></li>\n<li><a href=\"https://sanity-commercelayer-web-56265s29.netlify.app\">https://sanity-commercelayer-web-56265s29</a></li>\n<li><a href=\"https://sanity-gatsby-blog-3-studio-ch48ysi1.netlify.app\">https://sanity-gatsby-blog-3-studio-ch48ysi1</a></li>\n<li><a href=\"https://sanity-gatsby-blog-3-web-dnkdb4p7.netlify.app\">https://sanity-gatsby-blog-3-web-dnkdb4p7</a></li>\n<li><a href=\"https://sanity-gatsby-blog-4-studio-p6qrh84r.netlify.app\">https://sanity-gatsby-blog-4-studio-p6qrh84r</a></li>\n<li><a href=\"https://sanity-gatsby-blog-4-web-mobyn8k4.netlify.app\">https://sanity-gatsby-blog-4-web-mobyn8k4</a></li>\n<li><a href=\"https://sanity-gatsby-blog-studio-m195df5o.netlify.app\">https://sanity-gatsby-blog-studio-m195df5o</a></li>\n<li><a href=\"https://sanity-gatsby-blog-web-skwx3b17.netlify.app\">https://sanity-gatsby-blog-web-skwx3b17</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-2-studio-1dm9vw5o\">https://sanity-gatsby-hey-sugar-2-studio-1dm9vw5o</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-2-web.netlify.app\">https://sanity-gatsby-hey-sugar-2-web</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-5-studio.netlify.app\">https://sanity-gatsby-hey-sugar-5-studio</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-5.netlify.app\">https://sanity-gatsby-hey-sugar-5</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-studio-rkg94h5e.netlify.app\">https://sanity-gatsby-hey-sugar-studio-rkg94h5e</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-web-666eqtdv\">https://sanity-gatsby-hey-sugar-web-666eqtdv</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-3-studio-bit6zuzq.netlify.app\">https://sanity-gatsby-portfolio-3-studio-bit6zuzq</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-3-web-4dmiq19t\">https://sanity-gatsby-portfolio-3-web-4dmiq19t</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-studio-89chyji1.netlify.app\">https://sanity-gatsby-portfolio-studio-89chyji1</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-web-1wwhtk8k.netlify.app\">https://sanity-gatsby-portfolio-web-1wwhtk8k</a></li>\n<li><a href=\"https://sanity-jigsaw-blog-studio-mgk1nds9.netlify.app\">https://sanity-jigsaw-blog-studio-mgk1nds9</a></li>\n<li><a href=\"https://sanity-jigsaw-blog-web-cy6y69s7\">https://sanity-jigsaw-blog-web-cy6y69s7</a></li>\n<li><a href=\"https://sanity-kitchen-sink-2-studio-71rv9mea.netlify.app\">https://sanity-kitchen-sink-2-studio-71rv9mea</a></li>\n<li><a href=\"https://sanity-kitchen-sink-2-web-p1dc8gro\">https://sanity-kitchen-sink-2-web-p1dc8gro</a></li>\n<li><a href=\"https://sanity-kitchen-sink-3-studio-qpaz93e3.netlify.app\">https://sanity-kitchen-sink-3-studio-qpaz93e3</a></li>\n<li><a href=\"https://sanity-kitchen-sink-3-web-v2fb8vmv\">https://sanity-kitchen-sink-3-web-v2fb8vmv</a></li>\n<li><a href=\"https://sanity-kitchen-sink-5-studio-9hogian6\">https://sanity-kitchen-sink-5-studio-9hogian6</a></li>\n<li><a href=\"https://sanity-kitchen-sink-5-web.netlify.app\">https://sanity-kitchen-sink-5-web</a></li>\n<li><a href=\"https://sanity-kitchen-sink-studio-us5ymc5z.netlify.app\">https://sanity-kitchen-sink-studio-us5ymc5z</a></li>\n<li><a href=\"https://sanity-kitchen-sink-web-geaa75ie.netlify.app\">https://sanity-kitchen-sink-web-geaa75ie</a></li>\n<li><a href=\"https://sanity-nuxt-events-studio-zd46wiji.netlify.app\">https://sanity-nuxt-events-studio-zd46wiji</a></li>\n<li><a href=\"https://sanity-nuxt-events-web-i78cd7mw.netlify.app\">https://sanity-nuxt-events-web-i78cd7mw</a></li>\n<li><a href=\"https://sanity-signup.netlify.app\">https://sanity-signup</a></li>\n<li><a href=\"https://sanity-translation-examples-studio-u93wc5ox.netlify.app\">https://sanity-translation-examples-studio-u93wc5ox</a></li>\n<li><a href=\"https://scopeclosurecontext.netlify.app\">https://scopeclosurecontext</a></li>\n<li><a href=\"https://side-bar-blog-4.netlify.app\">https://side-bar-blog-4</a></li>\n<li><a href=\"https://sidebar-blog.netlify.app\">https://sidebar-blog</a></li>\n<li><a href=\"https://silly-lichterman-b22b5f\">https://silly-lichterman-b22b5f</a></li>\n<li><a href=\"https://site-analysis.netlify.app\">https://site-analysis</a></li>\n<li><a href=\"https://splendid-onion-b0ec3.netlify.app\">https://splendid-onion-b0ec3</a></li>\n<li><a href=\"https://starter-520d2.netlify.app\">https://starter-520d2</a></li>\n<li><a href=\"https://stupefied-wilson-2bc726.netlify.app\">https://stupefied-wilson-2bc726</a></li>\n<li><a href=\"https://synth-music-theory.netlify.app\">https://synth-music-theory</a></li>\n<li><a href=\"https://ternary42.netlify.app\">https://ternary42</a></li>\n<li><a href=\"https://tetris42.netlify.app\">https://tetris42</a></li>\n<li><a href=\"https://thealgorithms\">https://thealgorithms</a></li>\n<li><a href=\"https://trusting-aryabhata-e5438d.netlify.app\">https://trusting-aryabhata-e5438d</a></li>\n<li><a href=\"https://unruffled-bhabha-2ea500.netlify.app\">https://unruffled-bhabha-2ea500</a></li>\n<li><a href=\"https://upbeat-mayer-92c10b.netlify.app\">https://upbeat-mayer-92c10b</a></li>\n<li><a href=\"https://vibrant-noether-dbe366.netlify.app\">https://vibrant-noether-dbe366</a></li>\n<li><a href=\"https://web-dev-interview-prep-quiz-website.netlify.app\">https://web-dev-interview-prep-quiz-website</a></li>\n<li><a href=\"https://web-dev-resource-hub.netlify.app\">https://web-dev-resource-hub</a></li>\n<li><a href=\"https://wizardly-hermann-c9ade8.netlify.app\">https://wizardly-hermann-c9ade8</a></li>\n<li><a href=\"https://wonderful-pasteur-392fbe.netlify.app\">https://wonderful-pasteur-392fbe</a></li>\n<li><a href=\"https://zen-bhabha-bd046f.netlify.app\">https://zen-bhabha-bd046f</a></li>\n</ul>"},{"url":"/docs/community/bookmarks/","relativePath":"docs/community/bookmarks.md","relativeDir":"docs/community","base":"bookmarks.md","name":"bookmarks","frontmatter":{"title":"Bookmarks","weight":0,"excerpt":"Bookmarks","seo":{"title":"Bookmarks","description":"My chrome bookmars","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Bookmarks</h1>\n<p><a href=\"https://gist.github.com/bgoonz/046443c6859f1b188fe55d03cbf12003\">Link to Bookmarks</a></p>"},{"url":"/docs/community/","relativePath":"docs/community/index.md","relativeDir":"docs/community","base":"index.md","name":"index","frontmatter":{"title":"Community","excerpt":"We'd love it if you participate in the Libris community. Find out how to get connected.","seo":{"title":"Developer Community","description":"This is the community page (Connect via social networks or code hosting services)","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Where To Get Support","keyName":"property"},{"name":"og:description","value":"This is the community page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Where To Get Support"},{"name":"twitter:description","value":"This is the community page"}]},"template":"docs"},"html":" <div align=\"center\">\n<h1>➤ Connect with me:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://bgoonz.github.io/fb-and-twitter-api-embeds/\"  id=\"social-embed\"  width=\"100%\" height=\"100%\" scrolling=\"yes\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"  src=\"https://discord.com/widget?id=739632674276245685&theme=dark\" width=\"350\" height=\"500\"  frameborder=\"0\" sandbox=\"allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<p><a href=\"mailto:bryan.guner@gmail.com\"><img src=\"https://img.icons8.com/color/96/000000/gmail.png\" alt=\"email\"/></a><a href=\"https://www.facebook.com/bryan.guner/\">\n<img src=\"https://img.icons8.com/color/96/000000/facebook.png\" alt=\"facebook\"/>\n</a><a href=\"https://twitter.com/bgooonz\"><img src=\"https://img.icons8.com/color/96/000000/twitter-squared.png\" alt=\"twitter\"/></a><a href=\"https://www.youtube.com/channel/UC9-rYyUMsnEBK8G8fCyrXXA/videos\"><img src=\"https://img.icons8.com/color/96/000000/youtube.png\" alt=\"youtube\"/></a><a href=\"https://www.instagram.com/bgoonz/?hl=en\"><img src=\"https://img.icons8.com/color/96/000000/instagram-new.png\" alt=\"instagram\"/></a><a href=\"https://www.pinterest.com/bryanguner/_saved/\"><img src=\"https://img.icons8.com/color/96/000000/pinterest--v1.png\" alt=\"pinterest\"/></a><a href=\"https://www.linkedin.com/in/bryan-guner-046199128/\"><img src=\"https://img.icons8.com/color/96/000000/linkedin.png\" alt=\"linkedin\"/></a><a href=\"https://bryanguner.medium.com/\"><img src=\"https://img.icons8.com/color/96/000000/medium-logo.png\" alt=\"medium\"/>\n</a>\n<a href=\"https://open.spotify.com/user/bgoonz?si=ShH9wYbIQWab5Jz_30BKFw\">\n<img src=\"https://img.icons8.com/color/96/000000/spotify--v1.png\" alt=\"spotify\"/>\n</a></p>\n<br>\n<br>\n---\n<br>\n<br>\n <div align=\"center\">\n<h1>➤ Connect with me:</h1>\n<table>\n<thead>\n<tr>\n<th></th>\n<th><a href=\"https://github.com/bgoonz\">GitHub</a></th>\n<th><a href=\"https://gitlab.com/bryan.guner.dev\">Gitlab</a></th>\n<th><a href=\"https://bitbucket.org/bgoonz/\">Bitbucket</a></th>\n<th><a href=\"https://bryanguner.medium.com/\">Medium</a></th>\n<th><a href=\"https://codepen.io/bgoonz\">code pen</a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://repl.it/@bgoonz/\">Replit</a></td>\n<td><a href=\"https://www.quora.com/q/webdevresourcehub?invite_code=qwZOqbpAhgQ6hjjGl8NN\">Quora</a></td>\n<td><a href=\"https://www.reddit.com/user/bgoonz1\">Redit</a></td>\n<td><a href=\"https://webcomponents.dev/user/bgoonz\">webcomponents.dev</a></td>\n<td><a href=\"https://dev.to/bgoonz\">dev.to</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://runkit.com/bgoonz\">runkit</a></td>\n<td><a href=\"https://observablehq.com/@bgoonz?tab=profile\">Observable Notebooks</a></td>\n<td><a href=\"https://www.npmjs.com/~bgoonz11\">npm</a></td>\n<td><a href=\"https://meta.stackexchange.com/users/936785/bryan-guner\">stack-exchange</a></td>\n<td><a href=\"https://observablehq.com/@bgoonz?tab=profile\">Observable Notebooks</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://www.upwork.com/freelancers/~01bb1a3627e1e9c630?viewMode=1&#x26;s=1110580755057594368\">Upwork</a></td>\n<td><a href=\"https://www.notion.so/Overview-Of-Css-5d88b0bc9a73422a9be1481d599a56ba\">Notion</a></td>\n<td><a href=\"https://angel.co/u/bryan-guner\">AngelList</a></td>\n<td><a href=\"https://stackshare.io/bryanguner\">StackShare</a></td>\n<td><a href=\"http://plnkr.co/account/plunks\">Plunk</a></td>\n<td><a href=\"https://tealfeed.com/bryan_759844\">Tealfeed</a></td>\n</tr>\n<tr>\n<td><a href=\"https://giphy.com/channel/bryanguner\">giphy</a></td>\n<td><a href=\"https://ko-fi.com/bgoonz\">kofi</a></td>\n<td><a href=\"https://www.codewars.com/users/bgoonz\">Codewars</a></td>\n<td><a href=\"https://dribbble.com/bgoonz4242?onboarding=true\">Dribble</a></td>\n<td><a href=\"https://glitch.com/@bgoonz\">Glitch</a></td>\n<td><a href=\"https://yhype.me/github/accounts/bgoonz\">YHYPE</a></td>\n</tr>\n<tr>\n<td><a href=\"https://app.contentful.com/spaces/lelpu0ihaz11/assets?id=MocOPmmNliLn6PPv\">contentful</a></td>\n<td><a href=\"https://app.netlify.com/user/settings#profile\">Netlify</a></td>\n<td><a href=\"https://stackblitz.com/@bgoonz\">Stackblitz</a></td>\n<td><a href=\"https://vercel.com/bgoonz\">Vercel</a></td>\n<td><a href=\"https://www.youtube.com/channel/UC9-rYyUMsnEBK8G8fCyrXXA/featured\">Youtube</a></td>\n<td><a href=\"https://www.freecodecamp.org/bgoonz\">Free Code Camp</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/\">wordpress</a></td>\n<td><a href=\"https://edabit.com/user/dsRcx6yCwAgYwZbRB\">Edabit</a></td>\n<td><a href=\"https://vimeo.com/user128661018\">Vinmeo</a></td>\n<td><a href=\"https://jsfiddle.net/user/bgoonz/\">js fiddle</a></td>\n<td><a href=\"https://hashnode.com/@bgoonz/joinme\">hashnode</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://developers.google.com/profile/u/100803355943326309646?utm_source=developers.google.com\">Google Developer Profile</a></td>\n<td><a href=\"https://gitee.com/bgoonz\">Gittee</a></td>\n<td><a href=\"https://wakatime.com/@bgoonz42\">Wakatime</a></td>\n<td><a href=\"https://hubpages.com/@bryanguner\">Hubpages</a></td>\n<td><a href=\"https://bryan-guner.gitbook.io/web-dev-hub-docs/\">Gitbook</a></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n</div>\n<p><a class=\"twitter-timeline\" href=\"https://twitter.com/bgooonz?ref_src=twsrc%5Etfw\">Tweets by bgooonz</a>\n<br></p>\n<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\">\n</script>\n</div>\n<iframe width=\"700\" height=\"800\" frameborder=\"0\" scrolling=\"no\" src=\"https://onedrive.live.com/embed?resid=D21009FDD967A241%21942548&authkey=%21AB_1c2R9mwIBOWo&em=2&AllowTyping=True&ActiveCell='Sheet1'!A1&wdHideGridlines=True&wdHideHeaders=True&wdDownloadButton=True&wdInConfigurator=True&wdInConfigurator=True&edesNext=false&ejss=false\">\n</iframe>\n<br>\n<hr>\n <iframe class=\"utterances-frame\" title=\"Comments\" scrolling=\"no\" src=\"https://utteranc.es/utterances.html?src=https%3A%2F%2Futteranc.es%2Fclient.js&repo=bgoonz%2FBGOONZ_BLOG_2.0&issue-term=url&label=comment&theme=github-light&crossorigin=anonymous&async=&url=https%3A%2F%2Fbgoonz-blog.netlify.app%2Fadmin%2F&origin=https%3A%2F%2Fbgoonz-blog.netlify.app&pathname=admin%2F&title=Content+Manager&description=&og%3Atitle=&session=893b13e5949a24761d07a5a8lPqWXyqXu6NYrAlbw5%2FXWJwhyGoNgw0Nfqt4f6jL%2B%2BhqBSHrR9YC4g4tA5eUQRuWlCEvLGnO9En39ieuEAzoM840RS6pkSo8sL5ViCXQ3IcqQR68vd%2FbOvjEWgU%3D\" loading=\"lazy\">\n</iframe>\n<br>"},{"url":"/docs/content/bookmarks/","relativePath":"docs/content/bookmarks.md","relativeDir":"docs/content","base":"bookmarks.md","name":"bookmarks","frontmatter":{"title":"recent bookmarks","weight":0,"excerpt":"Some of my recent pet bookmarks","seo":{"title":"recent bookmarks","description":"Some of my recent pet bookmarks","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<br>\n<h1>Bgoonz Bookmarks   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bgoonz-bookmarks.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>"},{"url":"/docs/community/video-chat/","relativePath":"docs/community/video-chat.md","relativeDir":"docs/community","base":"video-chat.md","name":"video-chat","frontmatter":{"title":"Video Chat","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"Video Chat","description":"Video Chat","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Zumzi Instant Messenger</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://zumzi-chat-messenger.vercel.app/web/login.html\" width=\"1000px\" height=\"800px\" >\n</iframe>\n<br>\n<a class=\"github-corner\" href=\"https://github.com/bgoonz/zumzi-chat-messenger\" aria-label=\"View source on Github\">\n<svg aria-hidden=\"true\" width=\"40\" height=\"40\" viewBox=\"0 0 250 250\" style=\"z-index: 100000; fill: black; color: rgb(255, 255, 255); position: fixed; top: 0px; border: 0px; left: 0px; transform: scale(-1.5, 1.5);\">\n<path d=\"M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z\">\n</path>\n<path class=\"octo-arm\" d=\"M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2\" fill=\"currentColor\" style=\"transform-origin: 130px 106px;\">\n</path>\n<path class=\"octo-body\" d=\"M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z\" fill=\"currentColor\">\n</path>\n</svg>\n</a>"},{"url":"/docs/content/algo/","relativePath":"docs/content/algo.md","relativeDir":"docs/content","base":"algo.md","name":"algo","frontmatter":{"title":"Algorithms & Data Structures","subtitle":"The Algorithms & Data Structures provides you with a blueprint of default post and page styles.","image":"images/5.jpg","seo":{"title":"Algorithms & Data Structures","description":"A reference for suggested typographic treatment and styles for your content","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Algorithms & Data Structures","keyName":"property"},{"name":"og:description","value":"A reference for suggested typographic treatment and styles for your content","keyName":"property"},{"name":"og:image","value":"images/5.jpg","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_large_image"},{"name":"twitter:title","value":"Algorithms & Data Structures"},{"name":"twitter:description","value":"A reference for suggested typographic treatment and styles for your content"},{"name":"twitter:image","value":"images/5.jpg","relativeUrl":true}]},"template":"docs"},"html":"<h1>Fundamental Data Structures In JavaScript</h1>\n<br>\n<br>\n<br>\n<h1>   Algorithms </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bgoonz-branch-the-algos.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1>  The Algos Bgoonz Branch </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://thealgorithms.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\" height=\"1400\" src=\"https://ds-algo-official.netlify.app/\" frameborder=\"0\" allowfullscreen style=\"zoom:0.7;\">\n</iframe>\n<br>\n<p>Fundamental Data Structures In JavaScript</p>\n<h2>Data structures in JavaScript</h2>\n<p>Here's a website I created to practice data structures!\n<a href=\"https://ds-algo-official-c3dw6uapg-bgoonz.vercel.app/\"><strong>directory</strong>\n<em>Edit description</em>ds-algo-official-c3dw6uapg-bgoonz.vercel.app</a></p>\n<p>Here's the repo that the website is built on:\n<a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\"><strong>bgoonz/DS-ALGO-OFFICIAL</strong>\n<em>Navigation ####Author:Bryan Guner Big O notation is the language we use for talking about how long an algorithm takes…</em>github.com</a></p>\n<h2>Resources (article content below):</h2>\n<h3>Videos</h3>\n<ul>\n<li><a href=\"https://www.youtube.com/watch?v=0IAPZzGSbME&#x26;list=PLDN4rrl48XKpZkf03iYFl-O29szjTrs_O&#x26;index=2&#x26;t=0s\">Abdul Bari: YouTubeChannel for Algorithms</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"1000px\" height=\"800px\" src=\"https://www.youtube.com/embed/0IAPZzGSbME\"   allowfullscreen>\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://www.youtube.com/watch?v=lxja8wBwN0k&#x26;list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s\">Data Structures and algorithms</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"1000px\" height=\"800px\" src=\"https://www.youtube.com/embed/lxja8wBwN0k\"   allowfullscreen>\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://www.youtube.com/playlist?list=PLmGElG-9wxc9Us6IK6Qy-KHlG_F3IS6Q9\">Data Structures and algorithms Course</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"1000px\" height=\"800px\" src=\"https://www.youtube.com/embed/videoseries?list=PLmGElG-9wxc9Us6IK6Qy-KHlG_F3IS6Q9\"   allowfullscreen>\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://www.khanacademy.org/computing/computer-science/algorithms\">Khan Academy</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"714\" height=\"401\" src=\"https://www.youtube.com/embed/CvSOaYi89B4\"   allowfullscreen>\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://www.youtube.com/playlist?list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P\">Data structures by mycodeschool</a>Pre-requisite for this lesson is good understanding of pointers in C.</li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"1000px\" height=\"800px\" src=\"https://www.youtube.com/embed/videoseries?list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P\"   allowfullscreen>\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://www.youtube.com/watch?v=HtSuA80QTyo&#x26;list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb\">MIT 6.006: Intro to Algorithms(2011)</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"1000px\" height=\"800px\" src=\"https://www.youtube.com/embed/HtSuA80QTyo\"   allowfullscreen>\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://www.youtube.com/watch?v=5_5oE5lgrhw&#x26;list=PLu0W_9lII9ahIappRPN0MCAgtOu3lQjQi\">Data Structures and Algorithms by Codewithharry</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"1000px\" height=\"800px\" src=\"https://www.youtube.com/embed/5_5oE5lgrhw\"   allowfullscreen>\n</iframe>\n<br>\n<h3>Books</h3>\n<ul>\n<li><a href=\"https://edutechlearners.com/download/Introduction_to_algorithms-3rd%20Edition.pdf\">Introduction to Algorithms</a> by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein</li>\n<li><a href=\"http://www.sso.sy/sites/default/files/competitive%20programming%203_1.pdf\">Competitive Programming 3</a> by Steven Halim and Felix Halim</li>\n<li><a href=\"https://cses.fi/book/book.pdf\">Competitive Programmers Hand Book</a> Beginner friendly hand book for competitive programmers.</li>\n<li><a href=\"https://github.com/Amchuz/My-Data-Structures-and-Algorithms-Resources/raw/master/Books/Data%20Structures%20and%20Algorithms%20-%20Narasimha%20Karumanchi.pdf\">Data Structures and Algorithms Made Easy</a> by Narasimha Karumanchi</li>\n<li><a href=\"https://github.com/Amchuz/My-Data-Structures-and-Algorithms-Resources/raw/master/Books/Learning%20Algorithms%20Through%20Programming%20and%20Puzzle%20Solving.pdf\">Learning Algorithms Through Programming and Puzzle Solving</a> by Alexander Kulikov and Pavel Pevzner</li>\n</ul>\n<h3>Coding practice</h3>\n<ul>\n<li><a href=\"https://leetcode.com/\">LeetCode</a></li>\n<li><a href=\"https://www.interviewbit.com/\">InterviewBit</a></li>\n<li><a href=\"https://codility.com/\">Codility</a></li>\n<li><a href=\"https://www.hackerrank.com/\">HackerRank</a></li>\n<li><a href=\"https://projecteuler.net/\">Project Euler</a></li>\n<li><a href=\"https://spoj.com/\">Spoj</a></li>\n<li><a href=\"https://code.google.com/codejam/contests.html\">Google Code Jam practice problems</a></li>\n<li><a href=\"https://www.hackerearth.com/\">HackerEarth</a></li>\n<li><a href=\"https://www.topcoder.com/\">Top Coder</a></li>\n<li><a href=\"https://www.codechef.com/\">CodeChef</a></li>\n<li><a href=\"https://www.codewars.com/\">Codewars</a></li>\n<li><a href=\"https://codesignal.com/\">CodeSignal</a></li>\n<li><a href=\"http://codekata.com/\">CodeKata</a></li>\n<li><a href=\"https://www.firecode.io/\">Firecode</a></li>\n</ul>\n<h3>Courses</h3>\n<ul>\n<li><a href=\"https://academy.zerotomastery.io/p/master-the-coding-interview-faang-interview-prep\">Master the Coding Interview: Big Tech (FAANG) Interviews</a> Course by Andrei and his team.</li>\n<li><a href=\"https://realpython.com/python-data-structures\">Common Python Data Structures</a> Data structures are the fundamental constructs around which you build your programs. Each data structure provides a particular way of organizing data so it can be accessed efficiently, depending on your use case. Python ships with an extensive set of data structures in its standard library.</li>\n<li><a href=\"https://www.geeksforgeeks.org/fork-cpp-course-structure\">Fork CPP</a> A good course for beginners.</li>\n<li><a href=\"https://codeforces.com/edu/course/2\">EDU</a> Advanced course.</li>\n<li><a href=\"https://www.udacity.com/course/c-for-programmers--ud210\">C++ For Programmers</a> Learn features and constructs for C++.</li>\n</ul>\n<h3>Guides</h3>\n<ul>\n<li><a href=\"http://www.geeksforgeeks.org/\">GeeksForGeeks — A CS portal for geeks</a></li>\n<li><a href=\"https://www.learneroo.com/subjects/8\">Learneroo — Algorithms</a></li>\n<li><a href=\"http://www.topcoder.com/tc?d1=tutorials&#x26;d2=alg_index&#x26;module=Static\">Top Coder tutorials</a></li>\n<li><a href=\"http://www.infoarena.ro/training-path\">Infoarena training path</a> (RO)</li>\n<li>Steven &#x26; Felix Halim — <a href=\"https://uva.onlinejudge.org/index.php?option=com_onlinejudge&#x26;Itemid=8&#x26;category=118\">Increasing the Lower Bound of Programming Contests</a> (UVA Online Judge)</li>\n</ul>\n<h2><strong><em>space</em></strong></h2>\n<blockquote>\n<p><em>The space complexity represents the memory consumption of a data structure. As for most of the things in life, you can't have it all, so it is with the data structures. You will generally need to trade some time for space or the other way around.</em></p>\n</blockquote>\n<h2><em>time</em></h2>\n<blockquote>\n<p><em>The time complexity for a data structure is in general more diverse than its space complexity.</em></p>\n</blockquote>\n<h2><em>Several operations</em></h2>\n<blockquote>\n<p><em>In contrary to algorithms, when you look at the time complexity for data structures you need to express it for several operations that you can do with data structures. It can be adding elements, deleting elements, accessing an element or even searching for an element.</em></p>\n</blockquote>\n<h2><em>Dependent on data</em></h2>\n<blockquote>\n<p><em>Something that data structure and algorithms have in common when talking about time complexity is that they are both dealing with data. When you deal with data you become dependent on them and as a result the time complexity is also dependent of the data that you received. To solve this problem we talk about 3 different time complexity.</em></p>\n</blockquote>\n<ul>\n<li><strong>The best-case complexity: when the data looks the best</strong></li>\n<li>-</li>\n<li><strong>The worst-case complexity: when the data looks the worst</strong></li>\n<li><strong>The average-case complexity: when the data looks average</strong></li>\n</ul>\n<h2>Big O notation</h2>\n<p>The complexity is usually expressed with the Big O notation. The wikipedia page about this subject is pretty complex but you can find here a good summary of the different complexity for the most famous data structures and sorting algorithms.</p>\n<h2>The Array data structure</h2>\n<p><img src=\"https://cdn-images-1.medium.com/max/2000/0*Qk3UYgeqXamRrFLR.gif\" alt=\"image\"></p>\n<h2>Definition</h2>\n<p>An Array data structure, or simply an Array, is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. The simplest type of data structure is a linear array, also called one-dimensional array. From Wikipedia</p>\n<p>Arrays are among the oldest and most important data structures and are used by every program. They are also used to implement many other data structures.</p>\n<p><em>Complexity</em>\n<em>Average</em>\n<em>Access Search Insertion Deletion</em></p>\n<p>O(1) O(n) O(1) O(n)</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ArrayADT</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>array <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>array <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">current</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> current <span class=\"token operator\">!==</span> data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">search</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> foundIndex <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>foundIndex <span class=\"token operator\">===</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> foundIndex<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getAtIndex</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">index</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> array <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ArrayADT</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'const array = new ArrayADT();: '</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'array.add(1): '</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\narray<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\narray<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'array.add(2);: '</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'array.add(3);'</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'array.add(4); '</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\narray<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'search 3 gives index 2:'</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">search</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'getAtIndex 2 gives 3:'</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">getAtIndex</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'length is 4:'</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\narray<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\narray<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\narray<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\narray<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\narray<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\narray<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\narray<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/*\n     ~ final : (master) node 01-array.js \n    const array = new ArrayADT();:  ArrayADT { array: [] }\n    -------------------------------\n    array.add(1):  undefined\n    array.add(2);:  undefined array.add(3); undefined array.add(4);  undefined\n    -------------------------------\n    1 3 4 2 3 4\n    -------------------------------\n    search 3 gives index 2: null\n    -------------------------------\n    getAtIndex 2 gives 3: 4\n    -------------------------------\n    length is 4: 6\n    -------------------------------\n    1 4 2 4\n    -------------------------------\n    1 4 2 4 5 5\n    -------------------------------\n    1 4 2 4\n    -------------------------------\n     ~ final : (master) \n     */</span></code></pre></div>\n<p><img src=\"https://cdn-images-1.medium.com/max/2000/1*-BJ2hU-CZO2kuzu4x5a53g.png\" alt=\"image\"></p>\n<p>indexvalue0 … this is the first value, stored at zero position</p>\n<ol>\n<li>The index of an array <strong>runs in sequence</strong></li>\n<li>This could be useful for storing data that are required to be ordered, such as rankings or queues</li>\n<li>In JavaScript, array's value could be mixed; meaning value of each index could be of different data, be it String, Number or even Objects</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token comment\">// 1. Creating Arrays</span>\n    <span class=\"token keyword\">let</span> firstArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"c\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> secondArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"d\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"e\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"f\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// 2. Access an Array Item</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>firstArray<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Results: \"a\"</span>\n\n    <span class=\"token comment\">// 3. Loop over an Array</span>\n    firstArray<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item<span class=\"token punctuation\">,</span> index<span class=\"token punctuation\">,</span> array</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Results:</span>\n    <span class=\"token comment\">// a 0</span>\n    <span class=\"token comment\">// b 1</span>\n    <span class=\"token comment\">// c 2</span>\n\n    <span class=\"token comment\">// 4. Add new item to END of array</span>\n    secondArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token string\">'g'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>secondArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Results: [\"d\",\"e\",\"f\", \"g\"]</span>\n\n    <span class=\"token comment\">// 5. Remove item from END of array</span>\n    secondArray<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>secondArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Results: [\"d\",\"e\",\"f\"]</span>\n\n    <span class=\"token comment\">// 6. Remove item from FRONT of array</span>\n    secondArray<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>secondArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Results: [\"e\",\"f\"]</span>\n\n    <span class=\"token comment\">// 7. Add item to FRONT of array</span>\n    secondArray<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"d\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>secondArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Results: [\"d\",\"e\",\"f\"]</span>\n\n    <span class=\"token comment\">// 8. Find INDEX of an item in array</span>\n    <span class=\"token keyword\">let</span> position <span class=\"token operator\">=</span> secondArray<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Results: 2</span>\n\n    <span class=\"token comment\">// 9. Remove Item by Index Position</span>\n    secondArray<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>position<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>secondArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Note, the second argument, in this case \"1\",</span>\n    <span class=\"token comment\">// represent the number of array elements to be removed</span>\n    <span class=\"token comment\">// Results:  [\"d\",\"e\"]</span>\n\n    <span class=\"token comment\">// 10. Copy an Array</span>\n    <span class=\"token keyword\">let</span> shallowCopy <span class=\"token operator\">=</span> secondArray<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>secondArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>shallowCopy<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Results: ShallowCopy === [\"d\",\"e\"]</span>\n\n    <span class=\"token comment\">// 11. JavaScript properties that BEGIN with a digit MUST be accessed using bracket notation</span>\n    renderer<span class=\"token punctuation\">.</span>3d<span class=\"token punctuation\">.</span><span class=\"token function\">setTexture</span><span class=\"token punctuation\">(</span>model<span class=\"token punctuation\">,</span> <span class=\"token string\">'character.png'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>     <span class=\"token comment\">// a syntax error</span>\n    renderer<span class=\"token punctuation\">[</span><span class=\"token string\">'3d'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">setTexture</span><span class=\"token punctuation\">(</span>model<span class=\"token punctuation\">,</span> <span class=\"token string\">'character.png'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// works properly</span>\n\n    <span class=\"token comment\">// 12. Combine two Arrays</span>\n    <span class=\"token keyword\">let</span> thirdArray <span class=\"token operator\">=</span> firstArray<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>secondArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>thirdArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// [\"a\",\"b\",\"c\", \"d\", \"e\"];</span>\n\n    <span class=\"token comment\">// 13. Combine all Array elements into a string</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>thirdArray<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Results: a,b,c,d,e</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>thirdArray<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Results: abcde</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>thirdArray<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Results: a-b-c-d-e</span>\n\n    <span class=\"token comment\">// 14. Reversing an Array (in place, i.e. destructive)</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>thirdArray<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [\"e\", \"d\", \"c\", \"b\", \"a\"]</span>\n\n    <span class=\"token comment\">// 15. sort</span>\n    <span class=\"token keyword\">let</span> unsortedArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"Alphabet\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Zoo\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Products\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Computer Science\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Computer\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>unsortedArray<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Results: [\"Alphabet\", \"Computer\", \"Computer Science\", \"Products\", \"Zoo\" ]</span></code></pre></div>\n<h2>2. Objects</h2>\n<p>Think of objects as a logical grouping of a bunch of properties.</p>\n<p>Properties could be some variable that it's storing or some methods that it's using.</p>\n<p>I also visualize an object as a table.</p>\n<p>The main difference is that object's \"index\" need not be numbers and is not necessarily sequenced.</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/2572/1*KVZkD2zrgEa_47igW8Hq8g.png\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// 16. Creating an Object</span>\n\n<span class=\"token keyword\">let</span> newObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"I'm an object\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">values</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">others</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string-property property\">'1property'</span><span class=\"token operator\">:</span> <span class=\"token string\">'example of property name starting with digit'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// 17. Figure out what keys/properties are in an object</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>newObj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Results: [ 'name', 'values', 'others', '1property' ]</span>\n\n<span class=\"token comment\">// 18. Show all values stored in the object</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span>newObj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Results:</span>\n<span class=\"token comment\">// [ 'I\\'m an object',</span>\n<span class=\"token comment\">//   [ 1, 10, 11, 20 ],</span>\n<span class=\"token comment\">//   '',</span>\n<span class=\"token comment\">//   'example of property name starting with digit' ]</span>\n\n<span class=\"token comment\">// 19. Show all key and values of the object</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span> <span class=\"token keyword\">of</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span>newObj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>key<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>value<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// Results:</span>\n<span class=\"token comment\">// name: I'm an object</span>\n<span class=\"token comment\">// values: 1,10,11,20</span>\n<span class=\"token comment\">// others:</span>\n<span class=\"token comment\">// 1property: example of property name starting with digit</span>\n\n<span class=\"token comment\">// 20. Accessing Object's Properties</span>\n<span class=\"token comment\">// Two different ways to access properties, both produce same results</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newObj<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newObj<span class=\"token punctuation\">[</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// But if the property name starts with a digit,</span>\n<span class=\"token comment\">// we CANNOT use dot notation</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newObj<span class=\"token punctuation\">[</span><span class=\"token string\">'1property'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// 21. Adding a Method to an Object</span>\nnewObj<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">helloWorld</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello World from inside an object!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// 22. Invoking an Object's Method</span>\nnewObj<span class=\"token punctuation\">.</span><span class=\"token function\">helloWorld</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>The Hash Table</h2>\n<p><img src=\"https://cdn-images-1.medium.com/max/2000/0*avbxLAFocSV6vsl5.gif\" alt=\"image\"></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/2048/0*3GJiRoLyEoZ_aIlO\" alt=\"image\"></p>\n<h2><em>Definition</em></h2>\n<blockquote>\n<p><em>A Hash Table (Hash Map) is a data structure used to implement an associative array, a structure that can map keys to values. A Hash Table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found. From Wikipedia</em></p>\n</blockquote>\n<p>Hash Tables are considered the more efficient data structure for lookup and for this reason, they are widely used.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion</p>\n<ul>\n<li>\n<p>O(1) O(1) O(1)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n</li>\n</ul>\n<p>Note, here I am storing another object for every hash in my Hash Table.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">HashTable</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">size</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size <span class=\"token operator\">=</span> size<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key<span class=\"token punctuation\">,</span> value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">calculateHash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>hash<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>hash<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>hash<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>hash<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">calculateHash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>hash<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>hash<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>hash<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">calculateHash</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> key<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">%</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">search</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">calculateHash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>hash<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>hash<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>hash<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> string <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> value <span class=\"token keyword\">in</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> key <span class=\"token keyword\">in</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                string <span class=\"token operator\">+=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>string<span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">let</span> hashTable <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">HashTable</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'first'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'second'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'third'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fourth'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fifth'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 4 1 3 5</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'length gives 5:'</span><span class=\"token punctuation\">,</span> hashTable<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 5</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'search second gives 2:'</span><span class=\"token punctuation\">,</span> hashTable<span class=\"token punctuation\">.</span><span class=\"token function\">search</span><span class=\"token punctuation\">(</span><span class=\"token string\">'second'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fourth'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token string\">'first'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhashTable<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 3 5</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'length gives 3:'</span><span class=\"token punctuation\">,</span> hashTable<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 3</span>\n<span class=\"token comment\">/*\n       ~ js-files : (master) node hash.js \n    2 4 1 3 5\n    length gives 5: 5\n    search second gives 2: 2\n    2 3 5\n    length gives 3: 3\n    */</span></code></pre></div>\n<h2>The Set</h2>\n<h2>Sets</h2>\n<p>Sets are pretty much what it sounds like. It's the same intuition as Set in Mathematics. I visualize Sets as Venn Diagrams.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// 23. Creating a new Set</span>\n<span class=\"token keyword\">let</span> newSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// 24. Adding new elements to a set</span>\nnewSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Set[1]</span>\nnewSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'text'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Set[1, \"text\"]</span>\n\n<span class=\"token comment\">// 25. Check if element is in set</span>\nnewSet<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n\n<span class=\"token comment\">// 24. Check size of set</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newSet<span class=\"token punctuation\">.</span>size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Results: 2</span>\n\n<span class=\"token comment\">// 26. Delete element from set</span>\nnewSet<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Set[\"text\"]</span>\n\n<span class=\"token comment\">// 27. Set Operations: isSuperSet</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">isSuperset</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">set<span class=\"token punctuation\">,</span> subset</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> elem <span class=\"token keyword\">of</span> subset<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>set<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// 28. Set Operations: union</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">union</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">setA<span class=\"token punctuation\">,</span> setB</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> _union <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> elem <span class=\"token keyword\">of</span> setB<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        _union<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> _union<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// 29. Set Operations: intersection</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">setA<span class=\"token punctuation\">,</span> setB</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> _intersection <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> elem <span class=\"token keyword\">of</span> setB<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            _intersection<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> _intersection<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// 30. Set Operations: symmetricDifference</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">symmetricDifference</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">setA<span class=\"token punctuation\">,</span> setB</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> _difference <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> elem <span class=\"token keyword\">of</span> setB<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>_difference<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            _difference<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            _difference<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> _difference<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// 31. Set Operations: difference</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">difference</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">setA<span class=\"token punctuation\">,</span> setB</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> _difference <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> elem <span class=\"token keyword\">of</span> setB<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        _difference<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> _difference<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Examples</span>\n<span class=\"token keyword\">let</span> setA <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> setB <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> setC <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isSuperset</span><span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">,</span> setB<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">union</span><span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">,</span> setC<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => Set [1, 2, 3, 4, 5, 6]</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">,</span> setC<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => Set [3, 4]</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">symmetricDifference</span><span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">,</span> setC<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => Set [1, 2, 5, 6]</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">difference</span><span class=\"token punctuation\">(</span>setA<span class=\"token punctuation\">,</span> setC<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => Set [1, 2]</span></code></pre></div>\n<p><img src=\"https://cdn-images-1.medium.com/max/2000/0*gOE33ANZP2ujbjIG\" alt=\"image\"></p>\n<h2><em>Definition</em></h2>\n<blockquote>\n<p><em>A Set is an abstract data type that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite Set. From Wikipedia</em></p>\n</blockquote>\n<p>The Set data structure is usually used to test whether elements belong to set of values. Rather then only containing elements, Sets are more used to perform operations on multiple values at once with methods such as union, intersect, etc…</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion</p>\n<ul>\n<li>\n<p>O(n) O(n) O(n)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">add</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token operator\">~</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">remove</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">~</span>index<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">contains</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">union</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">set</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> newSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    set<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        newSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        newSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> newSet<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">intersect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">set</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> newSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>set<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            newSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> newSet<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">difference</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">set</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> newSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>set<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            newSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> newSet<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">isSubset</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">set</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> set<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">every</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">length</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Set</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">print</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> set <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1 2 3 4</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1 2 4</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'contains 4 is true:'</span><span class=\"token punctuation\">,</span> set<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'contains 3 is false:'</span><span class=\"token punctuation\">,</span> set<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => false</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'---'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> set1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset1<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset1<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> set2 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset2<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset2<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> set3 <span class=\"token operator\">=</span> set2<span class=\"token punctuation\">.</span><span class=\"token function\">union</span><span class=\"token punctuation\">(</span>set1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset3<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1 2 3</span>\n<span class=\"token keyword\">let</span> set4 <span class=\"token operator\">=</span> set2<span class=\"token punctuation\">.</span><span class=\"token function\">intersect</span><span class=\"token punctuation\">(</span>set1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset4<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2</span>\n<span class=\"token keyword\">let</span> set5 <span class=\"token operator\">=</span> set<span class=\"token punctuation\">.</span><span class=\"token function\">difference</span><span class=\"token punctuation\">(</span>set3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1 2 4 diff 1 2 3</span>\nset5<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 4</span>\n<span class=\"token keyword\">let</span> set6 <span class=\"token operator\">=</span> set3<span class=\"token punctuation\">.</span><span class=\"token function\">difference</span><span class=\"token punctuation\">(</span>set<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1 2 3 diff 1 2 4</span>\nset6<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 3</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'set1 subset of set is true:'</span><span class=\"token punctuation\">,</span> set<span class=\"token punctuation\">.</span><span class=\"token function\">isSubset</span><span class=\"token punctuation\">(</span>set1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'set2 subset of set is false:'</span><span class=\"token punctuation\">,</span> set<span class=\"token punctuation\">.</span><span class=\"token function\">isSubset</span><span class=\"token punctuation\">(</span>set2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => false</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'set1 length gives 2:'</span><span class=\"token punctuation\">,</span> set1<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'set3 length gives 3:'</span><span class=\"token punctuation\">,</span> set3<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 3</span></code></pre></div>\n<h2>The Singly Linked List</h2>\n<p><img src=\"https://cdn-images-1.medium.com/max/2048/0*fLs64rV-Xq19aVCA.gif\" alt=\"image\"></p>\n<h2><em>Definition</em></h2>\n<blockquote>\n<p><em>A Singly Linked List is a linear collection of data elements, called nodes pointing to the next node by means of pointer. It is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of data and a reference (in other words, a link) to the next node in the sequence.</em></p>\n</blockquote>\n<p>Linked Lists are among the simplest and most common data structures because it allows for efficient insertion or removal of elements from any position in the sequence.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(1) O(1)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Node</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>data <span class=\"token operator\">=</span> data<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">SinglyLinkedList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">SinglyLinkedList</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">add</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Node</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">SinglyLinkedList</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">remove</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> previous <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>current<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>current<span class=\"token punctuation\">.</span>data <span class=\"token operator\">===</span> data<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>current <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>current <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> previous<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            previous<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            previous <span class=\"token operator\">=</span> current<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">SinglyLinkedList</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">insertAfter</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">data<span class=\"token punctuation\">,</span> toNodeData</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>current<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>current<span class=\"token punctuation\">.</span>data <span class=\"token operator\">===</span> toNodeData<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Node</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>current <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                node<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n                current<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">SinglyLinkedList</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">traverse</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">fn</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>current<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>current<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">SinglyLinkedList</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">length</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfValues<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">SinglyLinkedList</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">print</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> string <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>current<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        string <span class=\"token operator\">+=</span> current<span class=\"token punctuation\">.</span>data <span class=\"token operator\">+</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">;</span>\n        current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>string<span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> singlyLinkedList <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">SinglyLinkedList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => ''</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1 2 3 4</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'length is 4:'</span><span class=\"token punctuation\">,</span> singlyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 4</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// remove value</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1 2 4</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// remove non existing value</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1 2 4</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// remove head</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 4</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// remove tail</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'length is 1:'</span><span class=\"token punctuation\">,</span> singlyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 6</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">insertAfter</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 3 6</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">insertAfter</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 3 4 6</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">insertAfter</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// insertAfter a non existing node</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 3 4 6</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">insertAfter</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">insertAfter</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// insertAfter the tail</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 3 4 5 6 7</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// add node with normal method</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 2 3 4 5 6 7 8</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'length is 7:'</span><span class=\"token punctuation\">,</span> singlyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 7</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    node<span class=\"token punctuation\">.</span>data <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>data <span class=\"token operator\">+</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 12 13 14 15 16 17 18</span>\nsinglyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 12 13 14 15 16 17 18</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'length is 7:'</span><span class=\"token punctuation\">,</span> singlyLinkedList<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 7</span></code></pre></div>\n<h2>The Doubly Linked List</h2>\n<p><img src=\"https://cdn-images-1.medium.com/max/2000/0*TQXiR-L_itiG3WP-.gif\" alt=\"image\"></p>\n<h2><em>Definition</em></h2>\n<blockquote>\n<p><em>A Doubly Linked List is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes. From Wikipedia</em></p>\n</blockquote>\n<p>Having two node links allow traversal in either direction but adding or removing a node in a doubly linked list requires changing more links than the same operations on a Singly Linked List.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(1) O(1)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Node {\n    constructor(data) {\n        this.data = data;\n        this.previous = null;\n        this.next = null;\n    }\n}\nclass DoublyLinkedList {\n    constructor() {\n        this.head = null;\n        this.tail = null;\n        this.numberOfValues = 0;\n    }\n\n    add(data) {\n        let node = new Node(data);\n        if (!this.head) {\n            this.head = node;\n            this.tail = node;\n        } else {\n            node.previous = this.tail;\n            this.tail.next = node;\n            this.tail = node;\n        }\n        this.numberOfValues++;\n    }\n    remove(data) {\n        let current = this.head;\n        while (current) {\n            if (current.data === data) {\n                if (current === this.head &amp;&amp; current === this.tail) {\n                    this.head = null;\n                    this.tail = null;\n                } else if (current === this.head) {\n                    this.head = this.head.next;\n                    this.head.previous = null;\n                } else if (current === this.tail) {\n                    this.tail = this.tail.previous;\n                    this.tail.next = null;\n                } else {\n                    current.previous.next = current.next;\n                    current.next.previous = current.previous;\n                }\n                this.numberOfValues--;\n            }\n            current = current.next;\n        }\n    }\n    insertAfter(data, toNodeData) {\n        let current = this.head;\n        while (current) {\n            if (current.data === toNodeData) {\n                let node = new Node(data);\n                if (current === this.tail) {\n                    this.add(data);\n                } else {\n                    current.next.previous = node;\n                    node.previous = current;\n                    node.next = current.next;\n                    current.next = node;\n                    this.numberOfValues++;\n                }\n            }\n            current = current.next;\n        }\n    }\n    traverse(fn) {\n        let current = this.head;\n        while (current) {\n            if (fn) {\n                fn(current);\n            }\n            current = current.next;\n        }\n    }\n    traverseReverse(fn) {\n        let current = this.tail;\n        while (current) {\n            if (fn) {\n                fn(current);\n            }\n            current = current.previous;\n        }\n    }\n    length() {\n        return this.numberOfValues;\n    }\n    print() {\n        let string = \"\";\n        let current = this.head;\n        while (current) {\n            string += current.data + \" \";\n            current = current.next;\n        }\n        console.log(string.trim());\n    }\n}\n\nlet doublyLinkedList = new DoublyLinkedList();\ndoublyLinkedList.print(); // => ''\ndoublyLinkedList.add(1);\ndoublyLinkedList.add(2);\ndoublyLinkedList.add(3);\ndoublyLinkedList.add(4);\ndoublyLinkedList.print(); // => 1 2 3 4\nconsole.log(\"length is 4:\", doublyLinkedList.length()); // => 4\ndoublyLinkedList.remove(3); // remove value\ndoublyLinkedList.print(); // => 1 2 4\ndoublyLinkedList.remove(9); // remove non existing value\ndoublyLinkedList.print(); // => 1 2 4\ndoublyLinkedList.remove(1); // remove head\ndoublyLinkedList.print(); // => 2 4\ndoublyLinkedList.remove(4); // remove tail\ndoublyLinkedList.print(); // => 2\nconsole.log(\"length is 1:\", doublyLinkedList.length()); // => 1\ndoublyLinkedList.remove(2); // remove tail, the list should be empty\ndoublyLinkedList.print(); // => ''\nconsole.log(\"length is 0:\", doublyLinkedList.length()); // => 0\ndoublyLinkedList.add(2);\ndoublyLinkedList.add(6);\ndoublyLinkedList.print(); // => 2 6\ndoublyLinkedList.insertAfter(3, 2);\ndoublyLinkedList.print(); // => 2 3 6\ndoublyLinkedList.traverseReverse(function (node) {\n    console.log(node.data);\n});\ndoublyLinkedList.insertAfter(4, 3);\ndoublyLinkedList.print(); // => 2 3 4 6\ndoublyLinkedList.insertAfter(5, 9); // insertAfter a non existing node\ndoublyLinkedList.print(); // => 2 3 4 6\ndoublyLinkedList.insertAfter(5, 4);\ndoublyLinkedList.insertAfter(7, 6); // insertAfter the tail\ndoublyLinkedList.print(); // => 2 3 4 5 6 7\ndoublyLinkedList.add(8); // add node with normal method\ndoublyLinkedList.print(); // => 2 3 4 5 6 7 8\nconsole.log(\"length is 7:\", doublyLinkedList.length()); // => 7\ndoublyLinkedList.traverse(function (node) {\n    node.data = node.data + 10;\n});\ndoublyLinkedList.print(); // => 12 13 14 15 16 17 18\ndoublyLinkedList.traverse(function (node) {\n    console.log(node.data);\n}); // => 12 13 14 15 16 17 18\nconsole.log(\"length is 7:\", doublyLinkedList.length()); // => 7\ndoublyLinkedList.traverseReverse(function (node) {\n    console.log(node.data);\n}); // => 18 17 16 15 14 13 12\ndoublyLinkedList.print(); // => 12 13 14 15 16 17 18\nconsole.log(\"length is 7:\", doublyLinkedList.length()); // => 7\n/*\n   ~ js-files : (master) node double-linked-list.js\n\n1 2 3 4\nlength is 4: 4\n1 2 4\n1 2 4\n2 4\n2\nlength is 1: 1\n\nlength is 0: 0\n2 6\n2 3 6\n6\n3\n2\n2 3 4 6\n2 3 4 6\n2 3 4 5 6 7\n2 3 4 5 6 7 8\nlength is 7: 7\n12 13 14 15 16 17 18\n12\n13\n14\n15\n16\n17\n18\nlength is 7: 7\n18\n17\n16\n15\n14\n13\n12\n12 13 14 15 16 17 18\nlength is 7: 7\n ~ js-files : (master)\n*/</code></pre></div>\n<h2>The Stack</h2>\n<p><img src=\"https://cdn-images-1.medium.com/max/4050/0*qsjYW-Lvfo22ecLE.gif\" alt=\"image\"></p>\n<h2><em>Definition</em></h2>\n<blockquote>\n<p><em>A Stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed. The order in which elements come off a Stack gives rise to its alternative name, LIFO (for last in, first out). From Wikipedia</em></p>\n</blockquote>\n<p>A Stack often has a third method peek which allows to check the last pushed element without popping it.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(1) O(1)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Stack() {\n  this.stack = [];\n}\n\nStack.prototype.push = function(value) {\n  this.stack.push(value);\n};\nStack.prototype.pop = function() {\n  return this.stack.pop();\n};\nStack.prototype.peek = function() {\n  return this.stack[this.stack.length - 1];\n};\nStack.prototype.length = function() {\n  return this.stack.length;\n};\nStack.prototype.print = function() {\n  console.log(this.stack.join(' '));\n};\n\nlet stack = new Stack();\nstack.push(1);\nstack.push(2);\nstack.push(3);\nstack.print(); // => 1 2 3\nconsole.log('length is 3:', stack.length()); // => 3\nconsole.log('peek is 3:', stack.peek()); // => 3\nconsole.log('pop is 3:', stack.pop()); // => 3\nstack.print(); // => 1 2\nconsole.log('pop is 2:', stack.pop());  // => 2\nconsole.log('length is 1:', stack.length()); // => 1\nconsole.log('pop is 1:', stack.pop()); // => 1\nstack.print(); // => ''\nconsole.log('peek is undefined:', stack.peek()); // => undefined\nconsole.log('pop is undefined:', stack.pop()); // => undefined</code></pre></div>\n<h2>The Queue</h2>\n<p><img src=\"https://cdn-images-1.medium.com/max/4050/0*YvfuX5tKP7-V0p7v.gif\" alt=\"image\"></p>\n<h2><em>Definition</em></h2>\n<blockquote>\n<p><em>A Queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal operations are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue. This makes the Queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the Queue will be the first one to be removed.</em></p>\n</blockquote>\n<p>As for the Stack data structure, a peek operation is often added to the Queue data structure. It returns the value of the front element without dequeuing it.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(1) O(n)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Queue() {\n  this.queue = [];\n}\n\nQueue.prototype.enqueue = function(value) {\n  this.queue.push(value);\n};\nQueue.prototype.dequeue = function() {\n  return this.queue.shift();\n};\nQueue.prototype.peek = function() {\n  return this.queue[0];\n};\nQueue.prototype.length = function() {\n  return this.queue.length;\n};\nQueue.prototype.print = function() {\n  console.log(this.queue.join(' '));\n};\n\nlet queue = new Queue();\nqueue.enqueue(1);\nqueue.enqueue(2);\nqueue.enqueue(3);\nqueue.print(); // => 1 2 3\nconsole.log('length is 3:', queue.length()); // => 3\nconsole.log('peek is 1:', queue.peek()); // => 3\nconsole.log('dequeue is 1:', queue.dequeue()); // => 1\nqueue.print(); // => 2 3\nconsole.log('dequeue is 2:', queue.dequeue());  // => 2\nconsole.log('length is 1:', queue.length()); // => 1\nconsole.log('dequeue is 3:', queue.dequeue()); // => 3\nqueue.print(); // => ''\nconsole.log('peek is undefined:', queue.peek()); // => undefined\nconsole.log('dequeue is undefined:', queue.dequeue()); // => undefined</code></pre></div>\n<h2>The Tree</h2>\n<p><img src=\"https://cdn-images-1.medium.com/max/2000/0*yUiQ-NaPKeLQnN7n\" alt=\"image\"></p>\n<h2><em>Definition</em></h2>\n<blockquote>\n<p><em>A Tree is a widely used data structure that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node. A tree data structure can be defined recursively as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of references to nodes (the \"children\"), with the constraints that no reference is duplicated, and none points to the root node. From Wikipedia</em></p>\n</blockquote>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(n) O(n)\nTo get a full overview of the time and space complexity of the Tree data structure, have a look to this excellent Big O cheat sheet.</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/2000/1*DCdQiB6XqBJCrFRz12BwqA.png\" alt=\"image\"></p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Node(data) {\n  this.data = data;\n  this.children = [];\n}\n\nfunction Tree() {\n  this.root = null;\n}\n\nTree.prototype.add = function(data, toNodeData) {\n  let node = new Node(data);\n  let parent = toNodeData ? this.findBFS(toNodeData) : null;\n  if(parent) {\n    parent.children.push(node);\n  } else {\n    if(!this.root) {\n      this.root = node;\n    } else {\n      return 'Root node is already assigned';\n    }\n  }\n};\nTree.prototype.remove = function(data) {\n  if(this.root.data === data) {\n    this.root = null;\n  }\n\n  let queue = [this.root];\n  while(queue.length) {\n    let node = queue.shift();\n    for(let i = 0; i &lt; node.children.length; i++) {\n      if(node.children[i].data === data) {\n        node.children.splice(i, 1);\n      } else {\n        queue.push(node.children[i]);\n      }\n    }\n  }\n};\nTree.prototype.contains = function(data) {\n  return this.findBFS(data) ? true : false;\n};\nTree.prototype.findBFS = function(data) {\n  let queue = [this.root];\n  while(queue.length) {\n    let node = queue.shift();\n    if(node.data === data) {\n      return node;\n    }\n    for(let i = 0; i &lt; node.children.length; i++) {\n      queue.push(node.children[i]);\n    }\n  }\n  return null;\n};\nTree.prototype._preOrder = function(node, fn) {\n  if(node) {\n    if(fn) {\n      fn(node);\n    }\n    for(let i = 0; i &lt; node.children.length; i++) {\n      this._preOrder(node.children[i], fn);\n    }\n  }\n};\nTree.prototype._postOrder = function(node, fn) {\n  if(node) {\n    for(let i = 0; i &lt; node.children.length; i++) {\n      this._postOrder(node.children[i], fn);\n    }\n    if(fn) {\n      fn(node);\n    }\n  }\n};\nTree.prototype.traverseDFS = function(fn, method) {\n  let current = this.root;\n  if(method) {\n    this['_' + method](current, fn);\n  } else {\n    this._preOrder(current, fn);\n  }\n};\nTree.prototype.traverseBFS = function(fn) {\n  let queue = [this.root];\n  while(queue.length) {\n    let node = queue.shift();\n    if(fn) {\n      fn(node);\n    }\n    for(let i = 0; i &lt; node.children.length; i++) {\n      queue.push(node.children[i]);\n    }\n  }\n};\nTree.prototype.print = function() {\n  if(!this.root) {\n    return console.log('No root node found');\n  }\n  let newline = new Node('|');\n  let queue = [this.root, newline];\n  let string = '';\n  while(queue.length) {\n    let node = queue.shift();\n    string += node.data.toString() + ' ';\n    if(node === newline &amp;&amp; queue.length) {\n      queue.push(newline);\n    }\n    for(let i = 0; i &lt; node.children.length; i++) {\n      queue.push(node.children[i]);\n    }\n  }\n  console.log(string.slice(0, -2).trim());\n};\nTree.prototype.printByLevel = function() {\n  if(!this.root) {\n    return console.log('No root node found');\n  }\n  let newline = new Node('\\n');\n  let queue = [this.root, newline];\n  let string = '';\n  while(queue.length) {\n    let node = queue.shift();\n    string += node.data.toString() + (node.data !== '\\n' ? ' ' : '');\n    if(node === newline &amp;&amp; queue.length) {\n      queue.push(newline);\n    }\n    for(let i = 0; i &lt; node.children.length; i++) {\n      queue.push(node.children[i]);\n    }\n  }\n  console.log(string.trim());\n};\n\nlet tree = new Tree();\ntree.add('ceo');\ntree.add('cto', 'ceo');\ntree.add('dev1', 'cto');\ntree.add('dev2', 'cto');\ntree.add('dev3', 'cto');\ntree.add('cfo', 'ceo');\ntree.add('accountant', 'cfo');\ntree.add('cmo', 'ceo');\ntree.print(); // => ceo | cto cfo cmo | dev1 dev2 dev3 accountant\ntree.printByLevel();  // => ceo \\n cto cfo cmo \\n dev1 dev2 dev3 accountant\nconsole.log('tree contains dev1 is true:', tree.contains('dev1')); // => true\nconsole.log('tree contains dev4 is false:', tree.contains('dev4')); // => false\nconsole.log('--- BFS');\ntree.traverseBFS(function(node) { console.log(node.data); }); // => ceo cto cfo cmo dev1 dev2 dev3 accountant\nconsole.log('--- DFS preOrder');\ntree.traverseDFS(function(node) { console.log(node.data); }, 'preOrder'); // => ceo cto dev1 dev2 dev3 cfo accountant cmo\nconsole.log('--- DFS postOrder');\ntree.traverseDFS(function(node) { console.log(node.data); }, 'postOrder'); // => dev1 dev2 dev3 cto accountant cfo cmo ceo\ntree.remove('cmo');\ntree.print(); // => ceo | cto cfo | dev1 dev2 dev3 accountant\ntree.remove('cfo');\ntree.print(); // => ceo | cto | dev1 dev2 dev3</code></pre></div>\n<h2>The Graph</h2>\n<p><img src=\"https://cdn-images-1.medium.com/max/2000/0*q31mL1kjFWlIzw3l.gif\" alt=\"image\"></p>\n<h2><em>Definition</em></h2>\n<blockquote>\n<p><em>A Graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected Graph or a set of ordered pairs for a directed Graph. These pairs are known as edges, arcs, or lines for an undirected Graph and as arrows, directed edges, directed arcs, or directed lines for a directed Graph. The vertices may be part of the Graph structure, or may be external entities represented by integer indices or references. From Wikipedia</em></p>\n</blockquote>\n<p>A Graph data structure may also associate to each edge some edge value, such as a symbolic label or a numeric attribute (cost, capacity, length, etc.).</p>\n<p>Representation\nThere are different ways of representing a graph, each of them with its own advantages and disadvantages. Here are the main 2:</p>\n<p>Adjacency list: For every vertex a list of adjacent vertices is stored. This can be viewed as storing the list of edges. This data structure allows the storage of additional data on the vertices and edges.\nAdjacency matrix: Data are stored in a two-dimensional matrix, in which the rows represent source vertices and columns represent destination vertices. The data on the edges and vertices must be stored externally.\nComplexity\nAdjacency list\nStorage Add Vertex Add Edge Query\nO( V + E\nAdjacency matrix\nStorage Add Vertex Add Edge Query\nO( V ^2) O(</p>\n<p>Graph</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//below uses the adjacency list representation.</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n        <span class=\"token keyword\">function</span> <span class=\"token function\">Graph</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfEdges <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">addVertex</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">removeVertex</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">let</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">~</span>index<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n          <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> adjacentVertex <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span>adjacentVertex<span class=\"token punctuation\">,</span> vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">addEdge</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex1<span class=\"token punctuation\">,</span> vertex2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfEdges<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">removeEdge</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex1<span class=\"token punctuation\">,</span> vertex2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">let</span> index1 <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>vertex2<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">let</span> index2 <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">~</span>index1<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>index1<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfEdges<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n          <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">~</span>index2<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>index2<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">size</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">relations</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>numberOfEdges<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">traverseDFS</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex<span class=\"token punctuation\">,</span> fn</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token operator\">~</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Vertex not found'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n          <span class=\"token keyword\">let</span> visited <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_traverseDFS</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">,</span> visited<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">_traverseDFS</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex<span class=\"token punctuation\">,</span> visited<span class=\"token punctuation\">,</span> fn</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          visited<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n          <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>visited<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n              <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_traverseDFS</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> visited<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n          <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">traverseBFS</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex<span class=\"token punctuation\">,</span> fn</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token operator\">~</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Vertex not found'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n          <span class=\"token keyword\">let</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n          queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">let</span> visited <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n          visited<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n\n          <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            vertex <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n              <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>visited<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                visited<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n              <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n          <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">pathFromTo</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertexSource<span class=\"token punctuation\">,</span> vertexDestination</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token operator\">~</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>vertexSource<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Vertex not found'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n          <span class=\"token keyword\">let</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n          queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertexSource<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">let</span> visited <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n          visited<span class=\"token punctuation\">[</span>vertexSource<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">let</span> paths <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n          <span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> vertex <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n              <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>visited<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                visited<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token comment\">// save paths between vertices</span>\n                paths<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> vertex<span class=\"token punctuation\">;</span>\n              <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n          <span class=\"token punctuation\">}</span>\n          <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>visited<span class=\"token punctuation\">[</span>vertexDestination<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n\n          <span class=\"token keyword\">let</span> path <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> vertexDestination<span class=\"token punctuation\">;</span> j <span class=\"token operator\">!=</span> vertexSource<span class=\"token punctuation\">;</span> j <span class=\"token operator\">=</span> paths<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            path<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n          path<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">return</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">print</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>vertex <span class=\"token operator\">+</span> <span class=\"token string\">' -> '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">', '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">' | '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`\n        <span class=\"token keyword\">let</span> graph <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Graph</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1 -> | 2 -> | 3 -> | 4 -> | 5 -> | 6 -></span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1 -> 2, 5 | 2 -> 1, 3, 5 | 3 -> 2, 4 | 4 -> 3, 5, 6 | 5 -> 1, 2, 4 | 6 -> 4</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'graph size (number of vertices):'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">size</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 6</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'graph relations (number of edges):'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">relations</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 7</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">traverseDFS</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1 2 3 4 5 6</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'---'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">traverseBFS</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1 2 5 3 4 6</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">traverseDFS</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 'Vertex not found'</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">traverseBFS</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 'Vertex not found'</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path from 6 to 1:'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">pathFromTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 6-4-5-1</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path from 3 to 5:'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">pathFromTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 3-2-5</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'graph relations (number of edges):'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">relations</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 5</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path from 6 to 1:'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">pathFromTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 6-4-3-2-5-1</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'graph relations (number of edges):'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">relations</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 7</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path from 6 to 1:'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">pathFromTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 6-4-5-1</span>\n        graph<span class=\"token punctuation\">.</span><span class=\"token function\">removeVertex</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'graph size (number of vertices):'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">size</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 5</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'graph relations (number of edges):'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">relations</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 4</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path from 6 to 1:'</span><span class=\"token punctuation\">,</span> graph<span class=\"token punctuation\">.</span><span class=\"token function\">pathFromTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 6-4-3-2-1</span></code></pre></div>"},{"url":"/docs/content/archive/","relativePath":"docs/content/archive.md","relativeDir":"docs/content","base":"archive.md","name":"archive","frontmatter":{"title":"Archive","weight":0,"seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Archives:</h1>\n<br>\n<br>\n<br>\n<br>\n<h1> Text Tools     </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://devtools42.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Ternary Converter   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://ternary42.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<table>\n<thead>\n<tr>\n<th>---</th>\n<th>---</th>\n<th>---</th>\n<th>---</th>\n<th>---</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>leonardomso/33-js-concepts<em>This repository was created with the intention of helping developers master their concepts in JavaScript. It is not a…</em>github.com</td>\n<td>Call stack - MDN Web Docs Glossary: Definitions of Web-related terms MDN<em>A call stack is a mechanism for an interpreter (like the JavaScript interpreter in a web browser) to keep track of its…</em>developer.mozilla.org</td>\n<td>Understanding Javascript Function Executions — Call Stack, Event Loop , Tasks &#x26; more<em>Web developers or Front end engineers, as that's what we like to be called, nowadays do everything right from acting as…</em>medium.com</td>\n<td>Understanding the JavaScript call stack<em>The JavaScript engine (which is found in a hosting environment like the browser), is a single-threaded interpreter…</em>medium.freecodecamp.org Javascript: What Is The Execution Context? What Is The Call Stack?<em>What is the Execution Context in Javascript? I bet you don't know the answer. What are the most basic components of a…</em>web.archive.org</td>\n<td>Understanding Execution Context and Execution Stack in Javascript<em>Understanding execution context and stack to become a better Javascript developer.</em>blog.bitsrc.io</td>\n</tr>\n<tr>\n<td>JavaScript data types and data structures - JavaScript MDN<em>Programming languages all have built-in data structures, but these often differ from one language to another. This…</em>developer.mozilla.org</td>\n<td>How numbers are encoded in JavaScript<em>Edit description</em>2ality.com</td>\n<td>Here is what you need to know about JavaScript's Number type<em>Why 0.1+0.2 IS NOT equal to 0.3 and 9007199254740992 IS equal to 9007199254740993</em>medium.com</td>\n<td>What Every JavaScript Developer Should Know About Floating Point Numbers<em>After I gave my talk on JavaScript (really, I was there trying to shamelessly plug my book - Underhanded JavaScript and…</em>blog.chewxy.com</td>\n<td>The Secret Life of JavaScript Primitives<em>You may not know it but, in JavaScript, whenever you interact with string, number or boolean primitives you enter a…</em>javascriptweblog.wordpress.com</td>\n</tr>\n<tr>\n<td>JavaScript Reference and Copy Variables Hacker Noon<em>Each programming language has its own peculiarities (and JavaScript has a lot), and today I'm going to talk about…</em>hackernoon.com</td>\n<td>JavaScript Primitive vs. Reference Values<em>Summary: in this tutorial, you will learn the differences between primitive and reference values. In JavaScript, a…</em>www.javascripttutorial.net</td>\n<td>JavaScript by reference vs. by value<em>I'm looking for some good comprehensive reading material on when JavaScript passes something by value and when by…</em>stackoverflow.com</td>\n<td>JavaScript Interview Prep: Primitive vs. Reference Types<em>original article In a JavaScript interview, they might ask if you understand the difference between primitive and…</em>dev.to</td>\n<td>What you need to know about Javascript's Implicit Coercion<em>Javascript's implicit coercion simply refers to Javascript attempting to coerce an unexpected value type to the…</em>dev.to</td>\n</tr>\n<tr>\n<td>Javascript Coercion Explained<em>Along with some practical examples</em>hackernoon.com</td>\n<td>What exactly is Type Coercion in Javascript?<em>Let's start with a short intro to type systems which I think will help you understand the general idea of type…</em>stackoverflow.com</td>\n<td><a href=\"https://thedevs.network/*Weak\">https://thedevs.network/*Weak</a> dynamic typing is arguably one of those things everybody likes to pick at about JavaScript. For an elegant dynamic…*thedevs.network</td>\n<td>getify/You-Dont-Know-JS<em>A book series on JavaScript. @YDKJS on twitter. Contribute to getify/You-Dont-Know-JS development by creating an…</em>github.com</td>\n<td>JavaScript — Double Equals vs. Triple Equals<em>Learn equality in JavaScript in 3 minutes</em>codeburst.io</td>\n</tr>\n<tr>\n<td>Why Use the Triple-Equals Operator in JavaScript? - Impressive Webs<em>\"Determining whether two variables are equivalent is one of the most important operations in programming.\" That's…</em>www.impressivewebs.com</td>\n<td>What is the difference between == and === in JavaScript?_On the surface == and === appear to be functionally the same, so why bother typing an extra character? In this video…_www.oreilly.com</td>\n<td>Why javascript's typeof always return \"object\"?<em>To add in with the others, typeof returns both objects and primitives. There are 5 primitive types in javascript…</em>stackoverflow.com</td>\n<td>Checking Types in Javascript<em>Have you ever wondered: what is the correct way to check if a Javascript variable is an Array? Do a Google search and…</em>tobyho.com</td>\n<td>How to better check data types in javascript - Webbjocke<em>To check what data type something has in javascript is not always the easiest. The language itself provides an operator…</em>webbjocke.com</td>\n</tr>\n<tr>\n<td>A JavaScript Fundamentals Cheat Sheet: Scope, Context, and \"this\"<em>Scope Scope refers to where a variable can be accessed within a program. Some variables can be accessed from anywhere…</em>dev.to</td>\n<td>Quick Tip: Function Expressions vs Function Declarations - SitePoint<em>This article was peer reviewed by Jeff Mott. Thanks to all of SitePoint's peer reviewers for making SitePoint content…</em>www.sitepoint.com</td>\n<td>JavaScript Function — Declaration vs Expression<em>Functions are considered as First Class citizen in JavaScript and it is really important to be clear with the concept…</em>medium.com</td>\n<td>Function Declarations vs. Function Expressions<em>What is Function Statement/Declarations in JavaScript?</em>medium.com</td>\n<td>Function Declarations vs. Function Expressions<em>Lets start with a short quiz. What is alerted in each case?: Question 1: Question 2: Question 3: Question 4: If you…</em>javascriptweblog.wordpress.com</td>\n</tr>\n<tr>\n<td>16. Modules<em>Edit description</em>exploringjs.com</td>\n<td>ES modules: A cartoon deep-dive - Mozilla Hacks - the Web developer blog<em>ES modules bring an official, standardized module system to JavaScript. With the release of Firefox 60 in May, all…</em>hacks.mozilla.org</td>\n<td>Understanding ES6 Modules - SitePoint<em>Almost every language has a concept of modules - a way to include functionality declared in one file within another…</em>www.sitepoint.com</td>\n<td>An overview of ES6 Modules in JavaScript<em>Introduction Until recently if you wanted to take full advantage of modules in JavaScript you needed to make use of…</em>blog.cloud66.com</td>\n<td>ES6 Modules in Depth<em>Welcome back to ES6 - \"Oh, good. It's not another article about Unicode\" - in Depth series. If you've never been around…</em>ponyfoo.com</td>\n</tr>\n<tr>\n<td>How JavaScript works: Event loop and the rise of Async programming + 5 ways to better coding with…<em>Welcome to post # 4 of the series dedicated to exploring JavaScript and its building components. In the process of…</em>blog.sessionstack.com</td>\n<td>Tasks, microtasks, queues and schedules<em>Edit description</em>jakearchibald.com</td>\n<td>Visualising the JavaScript Event Loop with a Pizza Restaurant analogy<em>Consider a pizza restaurant. There are two types of orders that we currently have from a single customer - one is an…</em>dev.to</td>\n<td>✨♻️ JavaScript Visualized: Event Loop<em>Oh boi the event loop. It's one of those things that every JavaScript developer has to deal with in one way or another…</em>dev.to</td>\n<td>Scheduling: setTimeout and setInterval<em>Edit description</em>javascript.info</td>\n</tr>\n<tr>\n<td>Understanding How the Chrome V8 Engine Translates JavaScript into Machine Code<em>Before diving deep into the core of Chrome's V8, first, let's get our fundamentals down. All of our systems consist of…</em>medium.freecodecamp.org</td>\n<td>Understanding V8's Bytecode<em>V8 is Google's open source JavaScript engine. Chrome, Node.js, and many other applications use V8. This article…</em>medium.com</td>\n<td>A Brief History of Google's V8 JavaScript Engine<em>Javascript has a reputation in developer circles as a terrible language. It's classless, loosely typed, and plagued by…</em>www.mediacurrent.com</td>\n<td>JavaScript essentials: why you should know how the engine works<em>This article is also available in Spanish.</em>medium.freecodecamp.org</td>\n<td>JavaScript engine fundamentals: Shapes and Inline Caches<em>This article describes some key fundamentals that are common to all JavaScript engines - and not just V8, the engine…</em>mathiasbynens.be</td>\n</tr>\n<tr>\n<td>JavaScript engine fundamentals: optimizing prototypes<em>This article describes some key fundamentals that are common to all JavaScript engines - and not just V8, the engine…</em>mathiasbynens.be</td>\n<td>Elements kinds in V8<em>Note: If you prefer watching a presentation over reading articles, then enjoy the video below! JavaScript objects can…</em>v8.dev</td>\n<td>Programming with JS: Bitwise Operations<em>In this series of articles we take a look at different Computer Science topics from the prism of JavaScript. We've…</em>hackernoon.com</td>\n<td>Using JavaScript's Bitwise Operators in Real Life<em>Let's pretend we're machine code programmers!</em>codeburst.io</td>\n<td>JavaScript Bitwise Operators - w3resource<em>Bitwise operators perform an operation on the bitwise (0,1) representation of their arguments, rather than as decimal…</em>www.w3resource.com</td>\n</tr>\n<tr>\n<td>JavaScript DOM Tutorial with Example<em>Details JavaScript can access all the elements in a webpage making use of Document Object Model (DOM). In fact, the web…</em>www.guru99.com</td>\n<td>What is the DOM?<em>A reader recently wrote in asking me what the DOM was. They said they've heard it mentioned and alluded to, but aren't…</em>css-tricks.com</td>\n<td>Traversing the DOM with JavaScript<em>A good JavaScript developer needs to know how to traverse the DOM-it's the act of selecting an element from another…</em>zellwk.com</td>\n<td>DOM tree<em>The backbone of an HTML document is tags. According to the Document Object Model (DOM), every HTML tag is an object…</em>javascript.info</td>\n<td>How to traverse the DOM in JavaScript<em>Learn how to navigate your way through the DOM tree.</em>javascript.plainenglish.io</td>\n</tr>\n<tr>\n<td>A Vanilla JS Guide On Mastering the DOM<em>Note: The contents of this post are intended to be introductory and does not include use of any libraries like jQuery…</em>dev.to</td>\n<td>How To Use Classes in JavaScript DigitalOcean<em>JavaScript is a prototype-based language, and every object in JavaScript has a hidden internal property called…</em>www.digitalocean.com</td>\n<td>Javascript Classes — Under The Hood<em>Javascript classes are nothing but a syntactic sugar over existing prototype based inheritance and constructor…</em>medium.com</td>\n<td>ES6 Classes - JavaScript January<em>Object-Oriented Programming (OOP) can be a great way to organize your projects. Introduced with ES6, the javascript…</em>www.javascriptjanuary.com</td>\n<td>Practical Ways to Write Better JavaScript<em>Solid methods of improving your JS. Tagged with javascript, webdev, beginners, react.</em>dev.to</td>\n</tr>\n<tr>\n<td>Better JavaScript with ES6, Pt. II: A Deep Dive into Classes<em>Out with the Old, In with the new Let's be clear about one thing from the start: Under the hood, ES6 classes are not…</em>scotch.io</td>\n<td>Understand the Factory Design Pattern in plain javascript<em>The simplest way to understand Factory Design Pattern</em>medium.com</td>\n<td>Factory Functions in JavaScript Aten Design Group<em>As we move from an age of jQuery plugins and script drop-ins to a world of CommonJS and modular architectures it's…</em>atendesigngroup.com</td>\n<td>The Factory Pattern in JS ES6<em>I'm trying to get the most out of all the new things in ES6 (ES2015). And I'm writing a new library where I need a…</em>medium.com</td>\n<td>Class vs Factory function: exploring the way forward<em>ECMAScript 2015 (aka ES6) comes with the class syntax, so now we have two competing patterns for creating objects. In…</em>medium.freecodecamp.org</td>\n</tr>\n<tr>\n<td>Prototype in Javascript Codementor<em>By default every function has a property name as prototype which is EMPTY ( by default). We can add properties and…</em>www.codementor.io</td>\n<td>Prototypes in JavaScript<em>In this post, we will discuss what are prototypes in JavaScript, how they help JavaScript in achieving the concepts of…</em>betterprogramming.pub</td>\n<td>Prototype in JavaScript: it's quirky, but here's how it works<em>The following four lines are enough to confuse most JavaScript developers:</em>medium.freecodecamp.org</td>\n<td>Understanding JavaScript: Prototype and Inheritance<em>Due to the amazing quantity of libraries, tools and all kinds of things that make your development easier, a lot of…</em>hackernoon.com</td>\n<td>Understanding Classes (ES5) and Prototypal Inheritance in JavaScript<em>In a nutshell the above snippet creates a Person class that can have multiple instances. By convention functional…</em>dev.to</td>\n</tr>\n<tr>\n<td>_Master JavaScript Prototypes &#x26; _Inheritance__\\ Inheritancecodeburst.io</td>\n<td>JavaScript's Prototypal Inheritance Explained Using CSS<em>Prototypal inheritance is arguably the least understood aspect of JavaScript. Well the good news is that if you…</em>medium.freecodecamp.org</td>\n<td>Demystifying ES6 Classes And Prototypal Inheritance<em>In the early history of the JavaScript language, a cloud of animosity formed over the lack of a proper syntax for…</em>scotch.io</td>\n<td>Intro To Prototypal Inheritance - JS<em>In this article I will try to give an introduction to protypal inheritance. As an \"optional\" pre-requisite, you can…</em>dev.to</td>\n<td>Let's Build Prototypal Inheritance in JS<em>The idea for this post is pretty simple. I want to some extent build and with that, illustrate how prototypes work in…</em>dev.to</td>\n</tr>\n<tr>\n<td>Understanding Prototypal Inheritance In JavaScript<em>What Is Object-oriented Programming (OOP) Classical vs Prototypal Inheritance The Prototype Object And The Prototype…</em>dev.to</td>\n<td>Object.create() - JavaScript MDN<em>The Object.create() method creates a new object, using an existing object as the prototype of the newly created object…</em>developer.mozilla.org</td>\n<td>Object.assign() - JavaScript MDN<em>The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It…</em>developer.mozilla.org</td>\n<td>Object.create in JavaScript<em>The Object.create method is one of the methods to create a new object in JavaScript.</em>medium.com</td>\n<td>Javascript Objects A New Way to Create Objects HTML Goodies<em>There are a lot of ways to create Objects in JavaScript, perhaps even more to integrate inheritance into them. Just…</em>www.htmlgoodies.com</td>\n</tr>\n<tr>\n<td>JavaScript Object Creation: Patterns and Best Practices - SitePoint<em>Jeff Mott guides you through a step-by-step approach to JavaScript object creation - from object literals to factory…</em>www.sitepoint.com</td>\n<td>Dealing With Objects in JavaScript With Object.assign, Object.keys and hasOwnProperty …<em>This post is a sort of grab bag to help you explore a few very useful methods to help you manage your objects in…</em>alligator.io</td>\n<td>Copying Objects in JavaScript DigitalOcean<em>Objects are the fundamental blocks of JavaScript. An object is a collection of properties, and a property is an…</em>scotch.io</td>\n<td>JavaScript: Object.assign()<em>Veja nesse artigo como utilizar o Object.assign() do ECMAScript 6</em>codeburst.io</td>\n<td>How to deep clone a JavaScript object<em>Copying objects in JavaScript can be tricky. Some ways perform a shallow copy, which is the default behavior in most of…</em>flaviocopes.com</td>\n</tr>\n<tr>\n<td>How to Use Map, Filter, and Reduce in JavaScript<em>Functional programming has been making quite a splash in the development world these days. And for good reason…</em>code.tutsplus.com</td>\n<td>JavaScript — Learn to Chain Map, Filter, and Reduce<em>Learn how to chain map, filter, and reduce in JavaScript</em>codeburst.io</td>\n<td>Understanding map, filter and reduce in Javascript<em>When working on Javascript projects you inevitably come across situations where you have to do some data manipulation…</em>hackernoon.com</td>\n<td>Functional Programming in JS: map, filter, reduce (Pt. 5)<em>Note: This is part of the \"Javascript and Functional Programming\" series on learning functional programming techniques…</em>hackernoon.com</td>\n<td>JavaScript: Map, Filter, Reduce<em>JavaScript's built-in map, filter, and reduce array methods are invaluable to a modern JavaScript developer. First…</em>wsvincent.com</td>\n</tr>\n<tr>\n<td>A simple guide to help you understand closures in JavaScript<em>Closures in JavaScript are one of those concepts that many struggle to get their heads around. In the following…</em>medium.freecodecamp.org</td>\n<td>Understanding JavaScript Closures: A Practical Approach<em>Learning a new language involves a series of steps, whereas its mastery is a product of patience, practice, mistakes…</em>scotch.io</td>\n<td>Understanding JavaScript: Closures<em>Why learn JavaScript in depth?</em>hackernoon.com</td>\n<td>How to use JavaScript closures with confidence<em>Using closures will be a piece of (chocolate) cake</em>hackernoon.com</td>\n<td>JavaScript Closures by Example<em>At some point you may have run into a problem when executing functions from within a for loop. The first time it…</em>howchoo.com</td>\n</tr>\n<tr>\n<td>Higher-Order Functions :: Eloquent JavaScript<em>Tzu-li and Tzu-ssu were boasting about the size of their latest programs. 'Two-hundred thousand lines,' said Tzu-li…</em>eloquentjavascript.net</td>\n<td>Higher-Order Functions in JavaScript - SitePoint<em>Continuing his look at functional programming in JavaScript, M. David Green examines higher-order functions and how…</em>www.sitepoint.com</td>\n<td>Higher Order Functions: Using Filter, Map and Reduce for More Maintainable Code<em>Higher order functions can help you to step up your JavaScript game by making your code more declarative. That is…</em>medium.freecodecamp.org</td>\n<td>First-class and Higher Order Functions: Effective Functional JavaScript<em>Functions: the killer JavaScript feature we never talk about.</em>hackernoon.com</td>\n<td>Higher Order Functions in JavaScript<em>Higher-order functions can be intimidating at first, but they're not that hard to learn. A higher-order function is…</em>www.lullabot.com</td>\n</tr>\n<tr>\n<td>ES6 Promises: Patterns and Anti-Patterns<em>When I first got started with NodeJS a few years ago, I was mortified by what is now affectionately known as \"callback…</em>medium.com</td>\n<td>A Simple Guide to ES6 Promises<em>The woods are lovely, dark and deep. But I have promises to keep, and miles to go before I sleep. — Robert Frost</em>codeburst.io</td>\n<td>The ES6 Promises<em>A very helpful feature in ES6</em>codeburst.io</td>\n<td>ES6 Promises in Depth<em>Promises are a very involved paradigm, so we'll take it slow. Here's a table of contents with the topics we'll cover in…</em>ponyfoo.com</td>\n<td>Javascript Promises: An In-Depth Approach<em>\"Write down the syntax for promises on this sheet of paper\", is enough to give nightmares to a lot of junior and even…</em>codeburst.io</td>\n</tr>\n<tr>\n<td>Promises - JavaScript concepts<em>This is part of a series where I try to explain through each of 33 JS Concepts. This part corresponds to Promises…</em>dev.to</td>\n<td>Javascript Promise 101<em>Knowing how Promise works in javascript will boost your development skill exponentially. Here I will share: I promise…</em>dev.to</td>\n<td>Simplify JavaScript Promises<em>I love promises. Not from people, but from JavaScript. Tweet Quote I love promises. Not from people, but from…</em>dev.to</td>\n<td>The Lowdown on Promises<em>A quick and concise guide on how Promises work in JavaScript</em>medium.com</td>\n<td>⭐️🎀 JavaScript Visualized: Promises &#x26; Async/Await<em>Ever had to deal with JS code that just… didn't run the way you expected it to? Maybe it seemed like functions got…</em>dev.to</td>\n</tr>\n<tr>\n<td>How to escape async/await hell<em>async/await freed us from callback hell, but people have started abusing it — leading to the birth of async/await hell.</em>medium.freecodecamp.org</td>\n<td>Understanding JavaScript's async await<em>Let's suppose we had code like the following. Here I'm wrapping an HTTP request in a Promise. The promise fulfills with…</em>ponyfoo.com</td>\n<td>JavaScript Async/Await: Serial, Parallel and Complex Flow - TechBrij<em>If you have experience on ASP.NET MVC then probably you are familiar with async/await keywords in C#. The same thing is…</em>techbrij.com</td>\n<td>From JavaScript Promises to Async/Await: why bother?<em>In this tutorial, we will cover why we need async/await when we could achieve the same fit with JavaScript Promises, to…</em>blog.pusher.com</td>\n<td>Flow Control in Modern JS: Callbacks to Promises to Async/Await - SitePoint<em>JavaScript is regularly claimed to be asynchronous. What does that mean? How does it affect development? How has the…</em>www.sitepoint.com</td>\n</tr>\n<tr>\n<td>Time Complexity Analysis in JavaScript<em>An algorithm is a self-contained step-by-step set of instructions to solve a problem. It takes time for these steps to…</em>www.jenniferbland.com</td>\n<td>Algorithms in plain English: time complexity and Big-O notation<em>Every good developer has time on their mind. They want to give their users more of it, so they can do all those things…</em>medium.freecodecamp.org</td>\n<td>An Introduction to Big O Notation<em>Big O notation is a big topic, and its universal importance stems from the fact that it describes the efficiency of…</em>dev.to</td>\n<td>[Crizstian/data-structure-and-algorithms-with-ES6<em>Num Type Exercises Description 10.- Graph Data Structure 2 A graph consists of a set of vertices and a set of edges. A…</em>github.com](<a href=\"https://github.com/Crizstian/data-structure-and-algorithms-with-ES6\">https://github.com/Crizstian/data-structure-and-algorithms-with-ES6</a> \"<a href=\"https://github.com/Crizs\">https://github.com/Crizs</a></td>\n<td></td>\n</tr>\n</tbody>\n</table>"},{"url":"/docs/content/gists/","relativePath":"docs/content/gists.md","relativeDir":"docs/content","base":"gists.md","name":"gists","frontmatter":{"title":"my gists","weight":0,"excerpt":null,"seo":{"title":"Gist Archive","description":"A collection of my github gists","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Gist Archive</h2>\n<h2>Gist Archive</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bgoonzgist.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<hr>\n<h2>Featured Gists:</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> Promise <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bluebird'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">promisifyAll</span><span class=\"token punctuation\">(</span><span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> crypto <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'crypto'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> path <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> pathA <span class=\"token operator\">=</span> <span class=\"token string\">'.'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> pathB <span class=\"token operator\">=</span> <span class=\"token string\">'/path/to/the/directory/you/want/to/compare/it/to'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> hashes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">hashDirIn</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">folder</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> pathPromiseA <span class=\"token operator\">=</span> fs\n        <span class=\"token punctuation\">.</span><span class=\"token function\">readdirAsync</span><span class=\"token punctuation\">(</span>folder<span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">fileName</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> workPath <span class=\"token operator\">=</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>folder<span class=\"token punctuation\">,</span> fileName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">var</span> statPromise <span class=\"token operator\">=</span> fs<span class=\"token punctuation\">.</span><span class=\"token function\">statAsync</span><span class=\"token punctuation\">(</span>workPath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>statPromise<span class=\"token punctuation\">,</span> fileName<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">statPromise<span class=\"token punctuation\">,</span> fileName</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>statPromise<span class=\"token punctuation\">.</span><span class=\"token function\">isFile</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">makeStream</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">file<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> result <span class=\"token operator\">=</span> fs<span class=\"token punctuation\">.</span><span class=\"token function\">createReadStream</span><span class=\"token punctuation\">(</span>workPath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">process</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">stream</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> hash <span class=\"token operator\">=</span> crypto<span class=\"token punctuation\">.</span><span class=\"token function\">createHash</span><span class=\"token punctuation\">(</span><span class=\"token string\">'md5'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            stream<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token function\">updateProcess</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">chunk</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                hash<span class=\"token punctuation\">.</span><span class=\"token function\">update</span><span class=\"token punctuation\">(</span>chunk<span class=\"token punctuation\">,</span> <span class=\"token string\">'utf8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            stream<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'end'</span><span class=\"token punctuation\">,</span> resolve<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">publish</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">var</span> digest <span class=\"token operator\">=</span> hash<span class=\"token punctuation\">.</span><span class=\"token function\">digest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hex'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            hashes<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">digest</span><span class=\"token operator\">:</span> digest<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> workPath <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token function\">makeStream</span><span class=\"token punctuation\">(</span>fileName<span class=\"token punctuation\">,</span> process<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                hashes<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>digest <span class=\"token operator\">&lt;</span> b<span class=\"token punctuation\">.</span>digest<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>digest <span class=\"token operator\">></span> b<span class=\"token punctuation\">.</span>digest<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">var</span> dupe <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                hashes<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">obj<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span>digest <span class=\"token operator\">==</span> hashes<span class=\"token punctuation\">[</span>index <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>digest<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Dupe '</span> <span class=\"token operator\">+</span> dupe <span class=\"token operator\">+</span> <span class=\"token string\">' found:'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Equal to:'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>hashes<span class=\"token punctuation\">[</span>index <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>path <span class=\"token operator\">+</span> <span class=\"token string\">'\\n'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            dupe<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">hashDirIn</span><span class=\"token punctuation\">(</span>pathA<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">hashDirIn</span><span class=\"token punctuation\">(</span>pathB<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<blockquote>\n<p>will replace any spaces in file names with an underscore!</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"> <span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">$file</span>\"</span> <span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token builtin class-name\">echo</span> $file <span class=\"token operator\">|</span> <span class=\"token function\">tr</span> <span class=\"token string\">' '</span> <span class=\"token string\">'_'</span><span class=\"token variable\">`</span></span> <span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span>\n  <span class=\"token comment\">## TAKING IT A STEP FURTHER:</span>\n <span class=\"token comment\"># Let's do it recursivley:</span>\n  <span class=\"token keyword\">function</span> <span class=\"token function-name function\">RecurseDirs</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">{</span>\n    <span class=\"token assign-left variable\">oldIFS</span><span class=\"token operator\">=</span><span class=\"token environment constant\">$IFS</span>\n    <span class=\"token assign-left variable\"><span class=\"token environment constant\">IFS</span></span><span class=\"token operator\">=</span><span class=\"token string\">$'<span class=\"token entity\" title=\"\\n\">\\n</span>'</span>\n    <span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">f</span> <span class=\"token keyword\">in</span> <span class=\"token string\">\"<span class=\"token variable\">$@</span>\"</span>\n    <span class=\"token keyword\">do</span>\n  <span class=\"token comment\"># YOUR CODE HERE!</span>\n\n<span class=\"token punctuation\">[</span><span class=\"token operator\">!</span><span class=\"token punctuation\">[</span>-----------------------------------------------------<span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span>https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">\\</span>*<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">$file</span>\"</span> <span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token builtin class-name\">echo</span> $file <span class=\"token operator\">|</span> <span class=\"token function\">tr</span> <span class=\"token string\">' '</span> <span class=\"token string\">'_'</span><span class=\"token variable\">`</span></span> <span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span> <span class=\"token parameter variable\">-d</span> <span class=\"token string\">\"<span class=\"token variable\">${f}</span>\"</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">then</span>\n<span class=\"token builtin class-name\">cd</span> <span class=\"token string\">\"<span class=\"token variable\">${f}</span>\"</span>\n            RecurseDirs <span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token function\">ls</span> <span class=\"token parameter variable\">-1</span> <span class=\"token string\">\".\"</span><span class=\"token variable\">)</span></span>\n            <span class=\"token builtin class-name\">cd</span> <span class=\"token punctuation\">..</span>\n        <span class=\"token keyword\">fi</span>\n    <span class=\"token keyword\">done</span>\n    <span class=\"token assign-left variable\"><span class=\"token environment constant\">IFS</span></span><span class=\"token operator\">=</span><span class=\"token variable\">$oldIFS</span>\n<span class=\"token punctuation\">}</span>\nRecurseDirs <span class=\"token string\">\"./\"</span></code></pre></div>\n<hr>\n<h3>Copy to clipboard jQuerry</h3>\n<blockquote>\n<p>Language: Javascript/Jquery</p>\n</blockquote>\n<blockquote>\n<p>In combination with the script tag : <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js\"> > </script> , this snippet will add a copy to clipboard button to all of your embedded <code> blocks.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">$</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">ready</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token string\">'code, pre'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">append</span><span class=\"token punctuation\">(</span>'<span class=\"token operator\">&lt;</span>span <span class=\"token keyword\">class</span><span class=\"token operator\">=</span><span class=\"token string\">\"command-copy\"</span> <span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>i <span class=\"token keyword\">class</span><span class=\"token operator\">=</span><span class=\"token string\">\"fa fa-clipboard\"</span> aria<span class=\"token operator\">-</span>hidden<span class=\"token operator\">=</span><span class=\"token string\">\"true\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>i<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>'<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token string\">'code span.command-copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">click</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> text <span class=\"token operator\">=</span> <span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">parent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">text</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//.text();</span>\n        <span class=\"token keyword\">var</span> copyHex <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        copyHex<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> text<span class=\"token punctuation\">;</span>\n        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        copyHex<span class=\"token punctuation\">.</span><span class=\"token function\">select</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        document<span class=\"token punctuation\">.</span><span class=\"token function\">execCommand</span><span class=\"token punctuation\">(</span><span class=\"token string\">'copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token string\">'pre span.command-copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">click</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> text <span class=\"token operator\">=</span> <span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">parent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">text</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">var</span> copyHex <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        copyHex<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> text<span class=\"token punctuation\">;</span>\n        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        copyHex<span class=\"token punctuation\">.</span><span class=\"token function\">select</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        document<span class=\"token punctuation\">.</span><span class=\"token function\">execCommand</span><span class=\"token punctuation\">(</span><span class=\"token string\">'copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3>Append Files in PWD</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">//APPEND-DIR.js</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> cat <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'child_process'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">execSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cat *'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token string\">'UTF-8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'output.md'</span><span class=\"token punctuation\">,</span> cat<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> err<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3>doesUserFrequentStarbucks.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> isAppleDevice <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">Mac|iPod|iPhone|iPad</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>navigator<span class=\"token punctuation\">.</span>platform<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>isAppleDevice<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Result: will return true if user is on an Apple device</span></code></pre></div>\n<hr>\n<h3>arr-intersection.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/*\n function named intersection(firstArr) that takes in an array and\nreturns a function.\nWhen the function returned by intersection is invoked\npassing in an array (secondArr) it returns a new array containing the elements\ncommon to both firstArr and secondArr.\n*/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">firstArr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">secondArr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> common <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> firstArr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> el <span class=\"token operator\">=</span> firstArr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>secondArr<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                common<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> common<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">let</span> abc <span class=\"token operator\">=</span> <span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a function</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">abc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [ 'b', 'c' ]</span>\n\n<span class=\"token keyword\">let</span> fame <span class=\"token operator\">=</span> <span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'m'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'e'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a function</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fame</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'z'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [ 'f', 'a' ]</span></code></pre></div>\n<hr>\n<h3>arr-of-cum-partial-sums.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/*\nFirst is recurSum(arr, start) which returns the sum of the elements of arr from the index start till the very end.\nSecond is partrecurSum() that recursively concatenates the required sum into an array and when we reach the end of the array, it returns the concatenated array.\n*/</span>\n<span class=\"token comment\">//arr.length -1 = 5</span>\n<span class=\"token comment\">//                   arr   [    1,    7,    12,   6,    5,    10   ]</span>\n<span class=\"token comment\">//                   ind   [    0     1     2     3     4      5   ]</span>\n<span class=\"token comment\">//                              ↟                              ↟</span>\n<span class=\"token comment\">//                            start                           end</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">recurSum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> sum <span class=\"token operator\">=</span> <span class=\"token number\">0</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>start <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">recurSum</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> start <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> sum <span class=\"token operator\">+</span> arr<span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> sum<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">rPartSumsArr</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> partSum <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>start <span class=\"token operator\">&lt;=</span> end<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">rPartSumsArr</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> partSum<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token function\">recurSum</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">++</span>start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> partSum<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'------------------------------------------------rPartSumArr------------------------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'rPartSumsArr(arr)=[ 1, 1, 5, 2, 6, 10 ]: '</span><span class=\"token punctuation\">,</span> <span class=\"token function\">rPartSumsArr</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'rPartSumsArr(arr1)=[ 1, 7, 12, 6, 5, 10 ]: '</span><span class=\"token punctuation\">,</span> <span class=\"token function\">rPartSumsArr</span><span class=\"token punctuation\">(</span>arr1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'------------------------------------------------rPartSumArr------------------------------------------------'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/*\n------------------------------------------------rPartSumArr------------------------------------------------\nrPartSumsArr(arr)=[ 1, 1, 5, 2, 6, 10 ]:  [ 10, 16, 18, 23, 24, 25 ]\nrPartSumsArr(arr1)=[ 1, 7, 12, 6, 5, 10 ]:  [ 10, 15, 21, 33, 40, 41 ]\n------------------------------------------------rPartSumArr------------------------------------------------\n*/</span></code></pre></div>\n<hr>\n<h3>camel2Kabab.js</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">camelToKebab</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> value<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">([a-z])([A-Z])</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'$1-$2'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h3>camelCase.js</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">camel</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">str</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(?:^\\w|[A-Z]|\\b\\w|\\s+)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">match<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">+</span>match <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// or if (/\\s+/.test(match)) for white spaces</span>\n        <span class=\"token keyword\">return</span> index <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> match<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> match<span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h3>concatLinkedLists.js</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">addTwoNumbers</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">l1<span class=\"token punctuation\">,</span> l2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ListNode</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> currentNode <span class=\"token operator\">=</span> result<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> carryOver <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>l1 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">||</span> l2 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> v1 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> v2 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l1 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> v1 <span class=\"token operator\">=</span> l1<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l2 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> v2 <span class=\"token operator\">=</span> l2<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> sum <span class=\"token operator\">=</span> v1 <span class=\"token operator\">+</span> v2 <span class=\"token operator\">+</span> carryOver<span class=\"token punctuation\">;</span>\n        carryOver <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>sum <span class=\"token operator\">/</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        sum <span class=\"token operator\">=</span> sum <span class=\"token operator\">%</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n        currentNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ListNode</span><span class=\"token punctuation\">(</span>sum<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l1 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> l1 <span class=\"token operator\">=</span> l1<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l2 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> l2 <span class=\"token operator\">=</span> l2<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>carryOver <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        currentNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ListNode</span><span class=\"token punctuation\">(</span>carryOver<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h3>fast-is-alpha-numeric.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">//Function to test if a character is alpha numeric that is faster than a regular</span>\n<span class=\"token comment\">//expression in JavaScript</span>\n\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isAlphaNumeric</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">char</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    char <span class=\"token operator\">=</span> char<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> id <span class=\"token operator\">=</span> char<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>id <span class=\"token operator\">></span> <span class=\"token number\">47</span> <span class=\"token operator\">&amp;&amp;</span> id <span class=\"token operator\">&lt;</span> <span class=\"token number\">58</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token comment\">// if not numeric(0-9)</span>\n        <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>id <span class=\"token operator\">></span> <span class=\"token number\">64</span> <span class=\"token operator\">&amp;&amp;</span> id <span class=\"token operator\">&lt;</span> <span class=\"token number\">91</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token comment\">// if not letter(A-Z)</span>\n        <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>id <span class=\"token operator\">></span> <span class=\"token number\">96</span> <span class=\"token operator\">&amp;&amp;</span> id <span class=\"token operator\">&lt;</span> <span class=\"token number\">123</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// if not letter(a-z)</span>\n    <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token string\">'z'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//false</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token string\">'!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//false</span></code></pre></div>\n<hr>\n<h3>find-n-replace.js</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">replaceWords</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">str<span class=\"token punctuation\">,</span> before<span class=\"token punctuation\">,</span> after</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[A-Z]</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>before<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        after <span class=\"token operator\">=</span> after<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> after<span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        after <span class=\"token operator\">=</span> after<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> after<span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span>before<span class=\"token punctuation\">,</span> after<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">replaceWords</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Let us go to the store'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'store'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mall'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//\"Let us go to the mall\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">replaceWords</span><span class=\"token punctuation\">(</span><span class=\"token string\">'He is Sleeping on the couch'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Sleeping'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'sitting'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//\"He is Sitting on the couch\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">replaceWords</span><span class=\"token punctuation\">(</span><span class=\"token string\">'His name is Tom'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Tom'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'john'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//\"His name is John\"</span></code></pre></div>\n<hr>\n<h3>flatten-arr.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/*Simple Function to flatten an array into a single layer */</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">flatten</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> array<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">accum<span class=\"token punctuation\">,</span> ele</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> accum<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>ele<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span>ele<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> ele<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3>isWeekDay.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">isWeekday</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">date</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> date<span class=\"token punctuation\">.</span><span class=\"token function\">getDay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">%</span> <span class=\"token number\">6</span> <span class=\"token operator\">!==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isWeekday</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token number\">2021</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Result: true (Monday)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isWeekday</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token number\">2021</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Result: false (Sunday)</span></code></pre></div>\n<hr>\n<h3>longest-common-prefix.js</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">longestCommonPrefix</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">strs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> prefix <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> strs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> character <span class=\"token operator\">=</span> strs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> strs<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> character<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        prefix <span class=\"token operator\">=</span> prefix <span class=\"token operator\">+</span> character<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>"},{"url":"/docs/content/history-api/","relativePath":"docs/content/history-api.md","relativeDir":"docs/content","base":"history-api.md","name":"history-api","frontmatter":{"title":"History API","weight":0,"excerpt":"history API explained","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>History Api</h1>\n<h1>\n\n</h1>\n<p>The DOM <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window\">Window</a> object provides access to the browser's session history (not to be confused for <a href=\"https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/history\">WebExtensions history</a>) through the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window/history\">history</a> object. It exposes useful methods and properties that let you navigate back and forth through the user's history, and manipulate the contents of the history stack.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API#concepts_and_usage\">Concepts and usage</a></h2>\n<p>Moving backward and forward through the user's history is done using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/back\">back()</a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/forward\">forward()</a>, and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/go\">go()</a> methods.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API#moving_forward_and_backward\">Moving forward and backward</a></h3>\n<p>To move backward through history:</p>\n<p>This acts exactly as if the user clicked on the <strong>Back</strong> button in their browser toolbar.</p>\n<p>Similarly, you can move forward (as if the user clicked the <strong>Forward</strong> button), like this:</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API#moving_to_a_specific_point_in_history\">Moving to a specific point in history</a></h3>\n<p>You can use the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/go\">go()</a> method to load a specific page from session history, identified by its relative position to the current page. (The current page's relative position is 0.)</p>\n<p>To move back one page (the equivalent of calling <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/back\">back()</a>):</p>\n<p>To move forward a page, just like calling <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/forward\">forward()</a>:</p>\n<p>Similarly, you can move forward 2 pages by passing 2, and so forth.</p>\n<p>Another use for the go() method is to refresh the current page by either passing 0, or by invoking it without an argument:</p>\n<p>You can determine the number of pages in the history stack by looking at the value of the length property:</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API#interfaces\">Interfaces</a></h2>\n<p>Allows manipulation of the browser <em>session history</em> (that is, the pages visited in the tab or frame that the current page is loaded in).</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API#examples\">Examples</a></h2>\n<p>The following example assigns a listener to the onpopstate property. And then illustrates some of the methods of the history object to add, replace, and move within the browser history for the current tab.</p>\n<h1>Working with the History API\n</h1>\n<p>HTML5 introduced the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/pushState\">pushState()</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState\">replaceState()</a> methods for add and modifying history entries, respectively. These methods work in conjunction with the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate\">onpopstate</a> event.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#adding_and_modifying_history_entries\">Adding and modifying history entries</a></h2>\n<p>Using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/pushState\">pushState()</a> changes the referrer that gets used in the HTTP header for <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\">XMLHttpRequest</a> objects created after you change the state. The referrer will be the URL of the document whose window is this at the time of creation of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\">XMLHttpRequest</a> object.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#example_of_pushstate_method\">Example of pushState() method</a></h3>\n<p>Suppose <a href=\"https://mozilla.org/foo.html\">https://mozilla.org/foo.html</a> executes the following JavaScript:</p>\n<p>This will cause the URL bar to display <a href=\"https://mozilla.org/bar.html\">https://mozilla.org/bar.html</a>, but won't cause the browser to load bar.html or even check that bar.html exists.</p>\n<p>Suppose now that the user navigates to <a href=\"https://google.com\">https://google.com</a>, then clicks the <strong>Back</strong> button. At this point, the URL bar will display <a href=\"https://mozilla.org/bar.html\">https://mozilla.org/bar.html</a> and history.state will contain the stateObj. The popstate event won't be fired because the page has been reloaded. The page itself will look like bar.html.</p>\n<p>If the user clicks <strong>Back</strong> once again, the URL will change to <a href=\"https://mozilla.org/foo.html\">https://mozilla.org/foo.html</a>, and the document will get a popstate event, this time with a null state object. Here too, going back doesn't change the document's contents from what they were in the previous step, although the document might update its contents manually upon receiving the popstate event.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#the_pushstate_method\">The pushState() method</a></h3>\n<p>pushState() takes three parameters: a <strong>state object</strong>; a <strong>title</strong> (currently ignored); and (optionally), a <strong>URL</strong>.</p>\n<p>Let's examine each of these three parameters in more detail.</p>\n<p>The state object is a JavaScript object which is associated with the new history entry created by pushState(). Whenever the user navigates to the new state, a popstate event is fired, and the state property of the event contains a copy of the history entry's state object. The state object can be anything that can be serialized. Because Firefox saves state objects to the user's disk so they can be restored after the user restarts the browser, we impose a size limit of 640k characters on the serialized representation of a state object. If you pass a state object whose serialized representation is larger than this to pushState(), the method will throw an exception. If you need more space than this, you're encouraged to use sessionStorage and/or localStorage.</p>\n<p><a href=\"https://github.com/whatwg/html/issues/2174\">All browsers but Safari currently ignore this parameter</a>, although they may use it in the future. Passing the empty string here should be safe against future changes to the method. Alternatively, you could pass a short title for the state to which you're moving.</p>\n<p>The new history entry's URL is given by this parameter. Note that the browser won't attempt to load this URL after a call to pushState(), but it might attempt to load the URL later, for instance after the user restarts the browser. The new URL does not need to be absolute; if it's relative, it's resolved relative to the current URL. The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception. This parameter is optional; if it isn't specified, it's set to the document's current URL.</p>\n<p><strong>Note:</strong> In Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) through Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2), the passed object is serialized using JSON. Starting in Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), the object is serialized using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\">the structured clone algorithm</a>. This allows a wider variety of objects to be safely passed.</p>\n<p>In a sense, calling pushState() is similar to setting window.location = \"#foo\", in that both will also create and activate another history entry associated with the current document.</p>\n<p>But pushState() has a few advantages:</p>\n<ul>\n<li>The new URL can be any URL in the same origin as the current URL. In contrast, setting window.location keeps you at the same <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document\">document</a> only if you modify only the hash.</li>\n<li></li>\n<li>You don't have to change the URL if you don't want to. In contrast, setting window.location = \"#foo\"; creates a new history entry only if the current hash isn</li>\n<li></li>\n<li>You can associate arbitrary data with your new history entry. With the hash-based approach, you need to encode all of the relevant data into a short string.</li>\n<li>If title is subsequently used by browsers, this data can be utilized (independent of, say, the hash).</li>\n</ul>\n<p>Note that pushState() never causes a hashchange event to be fired, even if the new URL differs from the old URL only in its hash.</p>\n<p>In other documents, it creates an element with a null namespace URI.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#the_replacestate_method\">The replaceState() method</a></h3>\n<p>history.replaceState() operates exactly like history.pushState(), except that replaceState() modifies the current history entry instead of creating a new one. Note that this doesn't prevent the creation of a new entry in the global browser history.</p>\n<p>replaceState() is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.</p>\n<p><strong>Note:</strong> In Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) through Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2), the passed object is serialized using JSON. Starting in Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), the object is serialized using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm\">the structured clone algorithm</a>. This allows a wider variety of objects to be safely passed.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#example_of_replacestate_method\">Example of replaceState() method</a></h3>\n<p>Suppose <a href=\"https://mozilla.org/foo.html\">https://mozilla.org/foo.html</a> executes the following JavaScript:</p>\n<p>The explanation of these two lines above can be found at the above section <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#example_of_pushstate_method\"><em>Example of pushState() method</em></a> section.</p>\n<p>Next, suppose <a href=\"https://mozilla.org/bar.html\">https://mozilla.org/bar.html</a> executes the following JavaScript:</p>\n<p>This will cause the URL bar to display <a href=\"https://mozilla.org/bar2.html\">https://mozilla.org/bar2.html</a>, but won't cause the browser to load bar2.html or even check that bar2.html exists.</p>\n<p>Suppose now that the user navigates to <a href=\"https://www.microsoft.com\">https://www.microsoft.com</a>, then clicks the <strong>Back</strong> button. At this point, the URL bar will display <a href=\"https://mozilla.org/bar2.html\">https://mozilla.org/bar2.html</a>. If the user now clicks <strong>Back</strong> again, the URL bar will display <a href=\"https://mozilla.org/foo.html\">https://mozilla.org/foo.html</a>, and totally bypass bar.html.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#the_popstate_event\">The popstate event</a></h3>\n<p>A popstate event is dispatched to the window every time the active history entry changes. If the history entry being activated was created by a call to <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/pushState\">pushState</a> or affected by a call to <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState\">replaceState</a>, the popstate event's state property contains a copy of the history entry's state object.</p>\n<p>See <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate\">WindowEventHandlers.onpopstate</a> for sample usage.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#reading_the_current_state\">Reading the current state</a></h3>\n<p>When your page loads, it might have a non-null state object. This can happen, for example, if the page sets a state object (using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/pushState\">pushState()</a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState\">replaceState()</a>) and then the user restarts their browser. When the page reloads, the page will receive an onload event, but no popstate event. However, if you read the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/state\">history.state</a> property, you'll get back the state object you would have gotten if a popstate had fired.</p>\n<p>You can read the state of the current history entry without waiting for a popstate event using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/state\">history.state</a> property like this:</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API#see_also\">See also</a></h2>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API\">History API</a></li>\n<li></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Example\">Ajax navigation example</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window/history\">window.history</a></li>\n</ul>\n<h1>Window.historyCopy to Clipboard\n\n</h1>\n<p>The Window.history read-only property returns a reference to the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History\">History</a> object, which provides an interface for manipulating the browser <em>session history</em> (pages visited in the tab or frame that the current page is loaded in).</p>\n<p>See <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API\">Manipulating the browser history</a> for examples and details. In particular, that article explains security features of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/pushState\">pushState()</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState\">replaceState()</a> methods that you should be aware of before using them.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window/history#example\">Example</a></h2>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window/history#notes\">Notes</a></h2>\n<p>For top-level pages you can see the list of pages in the session history, accessible via the History object, in the browser's dropdowns next to the back and forward buttons.</p>\n<p>For security reasons the History object doesn't allow the non-privileged code to access the <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/URL\">URLs</a> of other pages in the session history, but it does allow it to navigate the session history.</p>\n<p>There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Location/replace\">location.replace()</a> method, which replaces the current item of the session history with the provided URL.</p>"},{"url":"/docs/content/main-projects/","relativePath":"docs/content/main-projects.md","relativeDir":"docs/content","base":"main-projects.md","name":"main-projects","frontmatter":{"title":"RECENT PROJECTS","weight":0,"excerpt":"Some of my recent pet projects","seo":{"title":"RECENT PROJECTS","description":"Some of my recent pet projects","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<br>\n<h1>  Potluck Planner </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://potluck-landing.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>Meditation App </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://meditate42app.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h1>  Web Audio DAW      </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://mihirbeg28.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h1>React & Shopify Ecommerce Site (Norwex)     </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://friendly-amaranth-51833.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>Goal Tracker  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://splendid-onion-b0ec3.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/content/","relativePath":"docs/content/index.md","relativeDir":"docs/content","base":"index.md","name":"index","frontmatter":{"title":"Content","excerpt":"In this section you'll learn how to add syntax highlighting, examples, callouts and much more.","seo":{"title":"Manage Content","description":"This is the manage content page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Manage Content","keyName":"property"},{"name":"og:description","value":"This is the manage content page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Manage Content"},{"name":"twitter:description","value":"This is the manage content page"}]},"template":"docs","weight":0},"html":"<div class=\"note\">\n \n # My Repos:\n<table>\n<thead>\n<tr>\n<th><a href=\"https://github.com/bgoonz/a-whole-bunch-o-gatsby-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=a-whole-bunch-o-gatsby-templates\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/Comments\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Comments\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/EXPRESS-NOTES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=EXPRESS-NOTES\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=INTERVIEW-PREP-COMPLETE\" alt=\"ReadMe Card\"></a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://github.com/bgoonz/alternate-blog-theme\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=alternate-blog-theme\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=commercejs-nextjs-demo-store\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/fast-fourier-transform-\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=fast-fourier-transform-\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/JAMSTACK-TEMPLATES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=JAMSTACK-TEMPLATES\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/anki-cards\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=anki-cards\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Common-npm-Readme-Compilation\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Common-npm-Readme-Compilation\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/form-builder-vanilla-js\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=form-builder-vanilla-js\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Javascript-Best-Practices_--Tools\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Javascript-Best-Practices_--Tools\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/ask-me-anything\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=ask-me-anything\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Connect-Four-Final-Version\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Connect-Four-Final-Version\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Front-End-Frameworks-Practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Front-End-Frameworks-Practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/jsanimate\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=jsanimate\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/atlassian-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=atlassian-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/convert-folder-contents-2-website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=convert-folder-contents-2-website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/full-stack-react-redux\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=full-stack-react-redux\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Jupyter-Notebooks\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Jupyter-Notebooks\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Authentication-Notes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Authentication-Notes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Copy-2-Clipboard-jQuery\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Copy-2-Clipboard-jQuery\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Full-Text-Search\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Full-Text-Search\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Lambda\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Lambda\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-commands-walkthrough\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-commands-walkthrough\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Data-Structures-Algos-Codebase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Data-Structures-Algos-Codebase\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Games\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Games\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Lambda-Resource-Static-Assets\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-config-backup\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-config-backup\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DATA_STRUC_PYTHON_NOTES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DATA_STRUC_PYTHON_NOTES\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gatsby-netlify-cms-norwex\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gatsby-netlify-cms-norwex\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/learning-nextjs\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=learning-nextjs\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-shell-utility-functions\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-shell-utility-functions\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/design-home-page-with-routes-bq5v7k\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=design-home-page-with-routes-bq5v7k\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gatsby-react-portfolio\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gatsby-react-portfolio\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Learning-Redux\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Learning-Redux\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bass-station\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bass-station\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/docs-collection\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=docs-collection\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GIT-CDN-FILES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GIT-CDN-FILES\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Links-Shortcut-Site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Links-Shortcut-Site\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bgoonz\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bgoonz\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Documentation-site-react\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Documentation-site-react\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GIT-HTML-PREVIEW-TOOL\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/live-examples\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=live-examples\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZBLOG2.0STABLE\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=BGOONZBLOG2.0STABLE\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DS-ALGO-OFFICIAL\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gitbook\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gitbook\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/live-form\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=live-form\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=BGOONZ_BLOG_2.0\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DS-AND-ALGO-Notes-P2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DS-AND-ALGO-Notes-P2\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/github-readme-stats\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=github-readme-stats\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/loadash-es6-refactor\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=loadash-es6-refactor\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Binary-Search\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Binary-Search\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/ecommerce-interactive\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=ecommerce-interactive\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/github-reference-repo\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=github-reference-repo\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/markdown-css\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=markdown-css\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-2.o-versions\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-2.o-versions\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=embedable-repl-and-integrated-code-space-playground\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GoalsTracker\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GoalsTracker\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Markdown-Templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Markdown-Templates\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/excel2html-table\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=excel2html-table\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/graphql-experimentation\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=graphql-experimentation\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/meditation-app\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=meditation-app\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-w-comments\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-w-comments\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Exploring-Promises\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Exploring-Promises\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/https___mihirbeg.com_\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=https___mihirbeg.com_\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/MihirBegMusicLab\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=MihirBegMusicLab\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Blog2.0-August-Super-Stable\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Blog2.0-August-Super-Stable\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/express-API-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=express-API-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/iframe-showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=iframe-showcase\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/MihirBegMusicV3\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=MihirBegMusicV3\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bootstrap-sidebar-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bootstrap-sidebar-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Express-basic-server-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Express-basic-server-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Image-Archive-Traning-Data\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Image-Archive-Traning-Data\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Mihir_Beg_Final\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Mihir_Beg_Final\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/callbacks\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=callbacks\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/express-knex-postgres-boilerplate\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=express-knex-postgres-boilerplate\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Independent-Blog-Entries\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Independent-Blog-Entries\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Project-Showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Project-Showcase\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Shell-Script-Practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Shell-Script-Practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/promises-with-async-and-await\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=promises-with-async-and-await\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-notes-v5\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-notes-v5\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/mini-project-showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=mini-project-showcase\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/site-analysis\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=site-analysis\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/psql-practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=psql-practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-registration-login-example\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-registration-login-example\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Music-Theory-n-Web-Synth-Keyboard\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sorting-algorithms\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sorting-algorithms\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-playground-embed\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-playground-embed\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/React_Notes_V3\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=React_Notes_V3\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/my-gists\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=my-gists\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sorting-algos\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sorting-algos\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-practice-notes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-practice-notes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Recursion-Practice-Website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Recursion-Practice-Website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/My-Medium-Blog\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=My-Medium-Blog\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sqlite3-nodejs-demo\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sqlite3-nodejs-demo\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-scripts\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-scripts\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Regex-and-Express-JS\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Regex-and-Express-JS\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=nextjs-netlify-blog-template\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/stalk-photos-web-assets\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=stalk-photos-web-assets\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/PYTHON_PRAC\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=PYTHON_PRAC\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/repo-utils\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=repo-utils\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/norwex-coff-ecom\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=norwex-coff-ecom\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Standalone-Metranome\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Standalone-Metranome\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/random-list-of-embedable-content\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=random-list-of-embedable-content\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/resume-cv-portfolio-samples\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=resume-cv-portfolio-samples\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/old-c-and-cpp-repos-from-undergrad\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=old-c-and-cpp-repos-from-undergrad\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Star-wars-API-Promise-take2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Star-wars-API-Promise-take2\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/random-static-html-page-deploy\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=random-static-html-page-deploy\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Revamped-Automatic-Guitar-Effect-Triggering\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/old-code-from-undergrad\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=old-code-from-undergrad\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Static-Study-Site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Static-Study-Site\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/React-movie-app\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=React-movie-app\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/supertemp\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=supertemp\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/picture-man-bob-v2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=picture-man-bob-v2\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/styling-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=styling-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-medium-clone\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-medium-clone\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Ternary-converter\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Ternary-converter\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/scope-closure-context\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=scope-closure-context\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/TetrisJS\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TetrisJS\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/The-Algorithms\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=The-Algorithms\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Triggered-Guitar-Effects-Platform\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Triggered-Guitar-Effects-Platform\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/UsefulResourceRepo2.0\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=UsefulResourceRepo2.0\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/TexTools\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TexTools\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/TRASH\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TRASH\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Useful-Snippets-js\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Useful-Snippets-js\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/vscode-customized-config\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=vscode-customized-config\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/vscode-Extension-readmes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=vscode-Extension-readmes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-interview-prep-quiz-website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-interview-prep-quiz-website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-setup-checker\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-setup-checker\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-utils-package\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-utils-package\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/web-crawler-node\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-crawler-node\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-notes-resource-site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-notes-resource-site\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/WEB-DEV-TOOLS-HUB\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=WEB-DEV-TOOLS-HUB\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/WebAudioDaw\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=WebAudioDaw\" alt=\"ReadMe Card\"></a></td>\n</tr>\n</tbody>\n</table>"},{"url":"/docs/content/relational-databases/","relativePath":"docs/content/relational-databases.md","relativeDir":"docs/content","base":"relational-databases.md","name":"relational-databases","frontmatter":{"title":"Relational Databases","weight":0,"excerpt":"For Front end developers who like myself struggle with making the jump to fullstack","seo":{"title":"Relational Databases","description":"For Front end developers who like myself struggle with making the jump to fullstack","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p><img src=\"https://cdn-images-1.medium.com/max/800/0*3wDVBrK5ltmjjVSJ.jpeg\" alt=\"image\"></p>\n<p><strong>For Front end developers who like myself struggle with making the jump to fullstack.</strong></p>\n<p>You can access and query the data using the findByPk, findOne, and findAll methods.</p>\n<p><strong>Terminology:</strong></p>\n<ul>\n<li><a href=\"https://nodejs.org/en/\">NodeJS</a> We re going to use this to run JavaScript code on the server. I ve decided to use the latest version of Node, v6.3.0 at the time of writing, so that we ll have access to most of the new features introduced in ES6.</li>\n<li><a href=\"https://expressjs.com/\">Express</a> As per their website, Express is a Fast, unopinionated, minimalist web framework for Node.js , that we re going to be building our Todo list application on.</li>\n<li><a href=\"https://www.postgresql.org/docs/9.5/static/index.html\">PostgreSQL</a> This is a powerful open-source database that we re going to use. I ve attached an article I published on the setup below!</li>\n</ul>\n<p>[<strong>PostgreSQL Setup For Windows &#x26; WSL/Ubuntu</strong></p>\n<p><em>If you follow this guide to a tee you will install PostgreSQL itself on your Windows installation. Then, you will</em> bryanguner.medium.com](<a href=\"https://bryanguner.medium.com/postgresql-setup-for-windows-wsl-ubuntu-801672ab7089\">https://bryanguner.medium.com/postgresql-setup-for-windows-wsl-ubuntu-801672ab7089</a> \"<a href=\"https://bryanguner.medium.com/postgresql-setup-for-windows-wsl-ubuntu-801672ab7089%22\">https://bryanguner.medium.com/postgresql-setup-for-windows-wsl-ubuntu-801672ab7089\"</a>)</p>\n<ul>\n<li>However, if you face issues while installing PostgreSQL, or you don t want to dive into installing it, you can opt for a version of PostgreSQL hosted online. I recommend <a href=\"https://www.elephantsql.com/\">ElephantSQL</a>. I found it s pretty easy to get started with. However, the free version will only give you a 20MB allowance.</li>\n<li><a href=\"https://docs.sequelizejs.com/en/latest/\">Sequelize</a> In addition, we re going to use Sequelize, which is a database <a href=\"https://en.wikipedia.org/wiki/Object-relational_mapping\">ORM</a> that will interface with the Postgres database for us.</li>\n</ul>\n<p><strong>RDBMS and Database Entities</strong></p>\n<p><strong>Define what a relational database management system is</strong></p>\n<ul>\n<li>RDBMS stands for Relational Database Management System</li>\n<li>A software application that you run that your programs can connect to so that they can store, modify, and retrieve data.</li>\n<li>An RDBMS can track many databases. We will use PostgreSQL, or postgres , primarily for our RDBMS and it will be able to create individual databases for each of our projects.</li>\n</ul>\n<p><strong>Describe what relational data is</strong></p>\n<ul>\n<li>In general, relational data is information that is connected to other pieces of information.</li>\n<li>When working with relational databases, we can connect two entries together utilizing foreign keys (explained below).</li>\n<li>In a pets database, we could be keeping track of dogs and cats as well as the toys that each of them own. That ownership of a cat to a toy is the relational aspect of relational data. Two pieces of information that can be connected together to show some sort of meaning.</li>\n</ul>\n<p><strong>Define what a database is</strong></p>\n<ul>\n<li>The actual location that data is stored.</li>\n<li>A database can be made up of many tables that each store specific kinds of information.</li>\n<li>We could have a pets database that stores information about many different types of animals. Each animal type could potentially be represented by a different table.</li>\n</ul>\n<p><strong>Define what a database table is</strong></p>\n<ul>\n<li>Within a database, a table stores one specific kind of information.</li>\n<li>The records (entries) on these tables can be connected to records on other tables through the use of foreign keys</li>\n<li>In our pets database, we could have a dogs table, with individual records</li>\n</ul>\n<p><strong>Describe the purpose of a primary key</strong></p>\n<ul>\n<li>A primary key is used in the database as a unique identifier for the table.</li>\n<li>We often use an id field that simply increments with each entry. The incrementing ensures that each record has a unique identifier, even if their are other fields of the record that are repeated (two people with the same name would still need to have a unique identifier, for example).</li>\n<li>With a unique identifier, we can easily connect records within the table to records from other tables.</li>\n</ul>\n<p><strong>Describe the purpose of a foreign key</strong></p>\n<ul>\n<li>A foreign key is used as the connector from this record to the primary key of another table s record.</li>\n<li>In our pets example, we can imagine two tables to demonstrate: a table to represent cats and a table to represent toys. Each of these tables has a primary key of id that is used as the unique identifier. In order to make a connection between a toy and a cat, we can add another field to the cat table called owner<em>id , indicating that it is a foreign key for the cat table. By setting a toy s owner</em>id to the same value as a particular cat s id , we can indicate that the cat is the owner of that toy.</li>\n</ul>\n<p><strong>Describe how to properly name things in PostgreSQL</strong></p>\n<ul>\n<li>Names within postgres should generally consist of only lowercase letters, numbers, and underscores.</li>\n<li>Tables within a database are plural by convention, so a table for cats would typically be cats and office locations would be office_locations (all lowercase, underscores to replace spaces, plural)</li>\n</ul>\n<p><strong>Connect to an instance of PostgreSQL with the command line tool psql</strong></p>\n<ul>\n<li>The psql command by default will try to connect to a database and username that matches your system s username</li>\n<li>We connect to a different database by providing an argument to the psql command</li>\n<li>psql pets</li>\n<li>To connect with a different username we can use the -U flag followed by the username we would like to use. To connect to the pets database as pets_user</li>\n<li>psql -U pets_user pets</li>\n<li>If there is a password for the user, we can tell psql that we would like a prompt for the password to show up by using the -W flag.</li>\n<li>psql -U pets<em>user -W pets (the order of our flags doesn t matter, as long as any arguments associated with them are together, such as pets</em>user directly following -U in this example)</li>\n</ul>\n<p><strong>Identify whether a user is a normal user or a superuser by the prompt in the psql shell</strong></p>\n<ul>\n<li>You can tell if you are logged in as a superuser or normal user by the prompt in the terminal.</li>\n<li>If the prompt shows =>, the user is a normal user</li>\n<li>If the prompt show =#, the user is a superuser</li>\n</ul>\n<p><strong>Create a user for the relational database management system</strong></p>\n<ul>\n<li>Within psql, we can create a user with the CREATE USER {username} {WITH options} command.</li>\n<li>The most common options we ll want to use are WITH PASSWORD 'mypassword' to provide a password for the user we are creating, CREATEDB to allow the user to create new databases, or SUPERUSER to create a user with all elevated permissions.</li>\n</ul>\n<p><strong>Create a database in the database management system</strong></p>\n<ul>\n<li>We can use the command CREATE DATABASE {database name} {options} inside psql to create a new database.</li>\n<li>A popular option we may utilize is WITH OWNER {owner name} to set another user as the owner of the database we are making.</li>\n</ul>\n<p><strong>Configure a database so that only the owner (and superusers) can connect to it</strong></p>\n<ul>\n<li>We can GRANT and REVOKE privileges from a database to users or categories of users.</li>\n<li>In order to remove connection privileges to a database from the public we can use REVOKE CONNECT ON DATABASE {db_name} FROM PUBLIC;, removing all public connection access.</li>\n<li>If we wanted to grant it back, or to a specific user, we could similarly do GRANT CONNECT ON DATABASE {db_name} FROM {specific user, PUBLIC, etc.};</li>\n</ul>\n<p><strong>View a list of databases in an installation of PostgreSQL</strong></p>\n<ul>\n<li>To list all databases we can use the \\l or \\list command in psql.</li>\n</ul>\n<p><strong>Create tables in a database</strong></p>\n<p>CREATE TABLE {table name} (\n{columnA} {typeA},\n{columnB} {typeB},\netc...\n);</p>\n<ul>\n<li>The whitespace does not matter. Creating the SQL statements on multiple lines is easier to read, but just like JavaScript, they can be presented differently.</li>\n<li>One common issue is that SQL does not like trailing commas, so the last column cannot have a comma after its type in this example.</li>\n</ul>\n<p><strong>View a list of tables in a database</strong></p>\n<ul>\n<li>To list all database tables, use the \\dt command.</li>\n</ul>\n<p><strong>Identify and describe the common data types used in PostgreSQL</strong></p>\n<ul>\n<li>There are many different data types that we can use in our tables, here are some common examples:</li>\n<li>SERIAL: autoincrementing, very useful for IDs</li>\n<li>VARCHAR(n): a string with a character limit of n</li>\n<li>TEXT: doesn t have character limit, but less performant</li>\n<li>BOOLEAN: true/false</li>\n<li>SMALLINT: signed two-byte integer (-32768 to 32767)</li>\n<li>INTEGER: signed four-byte integer (standard)</li>\n<li>BIGINT: signed eight-byte integer (very large numbers)</li>\n<li>NUMERIC: or DECIMAL, can store exact decimal values</li>\n<li>TIMESTAMP: date and time</li>\n</ul>\n<p><strong>Describe the purpose of the UNIQUE and NOT NULL constraints, and create columns in database tables that have them</strong></p>\n<ul>\n<li>In addition to the data type, we can provide flags for constraints to place on our column data.</li>\n<li>The UNIQUE flag indicates that the data for the column must not be repeated.</li>\n<li>By default we can create entries in our tables that are missing data from columns. When creating a pet, maybe we don t provide an age because we don t know it, for example. If we want to require that the data be present in order to create a new record, we can indicate that column must be NOT NULL.</li>\n<li>\n<p>In the example below, we are requiring our pets to have unique names and for them to be present (both UNIQUE and NOT NULL). We have no such constraints on the age column, allowing repetition of ages or their complete absence.</p>\n<p>CREATE TABLE pets (<br>\nid SERIAL PRIMARY KEY,<br>\nname VARCHAR(255) UNIQUE NOT NULL,<br>\nage SMALLINT<br>\n);</p>\n</li>\n</ul>\n<p><strong>Create a primary key for a table</strong></p>\n<ul>\n<li>\n<p>When creating a table we can indicate the primary key by passing in the column name to parentheses like so:</p>\n<p>CREATE TABLE people (<br>\nid SERIAL,<br>\nfirst<em>name VARCHAR(50),<br>\nlast</em>name VARCHAR(50),<br>\nPRIMARY KEY (id)<br>\n);</p>\n</li>\n<li>\n<p>We could have also used the PRIMARY KEY flag on the column definition itself:</p>\n<p>CREATE TABLE people (<br>\nid SERIAL PRIMARY KEY,<br>\nfirst<em>name VARCHAR(50),<br>\nlast</em>name VARCHAR(50)<br>\n);</p>\n</li>\n</ul>\n<p><strong>Create foreign key constraints to relate tables</strong></p>\n<ul>\n<li>In our table definition, we can use the line FOREIGN KEY (foreign<em>key</em>stored<em>in</em>this<em>table) REFERENCE {other table} ({other</em>tables<em>key</em>name}) to connect two tables.</li>\n<li>\n<p>This is probably easier to see in an example:</p>\n<p>CREATE TABLE people (<br>\nid SERIAL PRIMARY KEY,<br>\nfirst<em>name VARCHAR(50),<br>\nlast</em>name VARCHAR(50)<br>\n);</p>\n<p>CREATE TABLE pets (<br>\nid SERIAL PRIMARY KEY,<br>\nname VARCHAR(255),<br>\nage SMALLINT,<br>\nperson<em>id INTEGER,<br>\nFOREIGN KEY (person</em>id) REFERENCES people (id)<br>\n);</p>\n</li>\n</ul>\n<p><strong>SQL is not case sensitive for its keywords but is for its entity names</strong></p>\n<ul>\n<li>Exactly as the LO states, CREATE TABLE and create table are interpreted the same way. Using capitalization is a good convention in order to distinguish your keywords.</li>\n<li>The entity names that we use ARE case-sensitive, however. So a table named pets is unique from a table named Pets. In general, we prefer to use all lowercase for our entities to avoid any of this confusion.</li>\n</ul>\n<p><strong>SQL</strong></p>\n<ol>\n<li>How to use the SELECT ... FROM ... statement to select data from a single table</li>\n<li>Supply the column names in the SELECT clause. If we want all columns, we can also use *</li>\n<li>Supply the table names in the FROM clause</li>\n</ol>\n<p>--- Selects all columns from the friends table</p>\n<p>SELECT\n*\nFROM\nfriends;</p>\n<p>--- Selects the first_name column from the friends table (remember whitespace is ignored)<br>\nSELECT name<br>\nFROM friends;</p>\n<ul>\n<li>Sometimes we may need to specify what table we are selecting a column from, particulurly if we had joined multiple tables together.</li>\n</ul>\n<p>--- Notice here we are indicating that we want the \"name\" field from the \"friends\" table as well as the \"name\" field from the \"puppies\" table. We indicate the table name by table.column<br>\n--- We are also aliasing these fields with the AS keyword so that our returned results have friend<em>name and puppy</em>name as field headers</p>\n<p>SELECT\nfriends.name AS friend<em>name , puppies.name AS puppy</em>name\nFROM\nfriends\nJOIN\npuppies ON friends.puppy_id = puppies.id</p>\n<p><strong>How to use the WHERE clause on SELECT, UPDATE, and DELETE statements to narrow the scope of the command</strong></p>\n<ul>\n<li>The WHERE clause allows us to select or apply actions to records that match specific criteria instead of to a whole table.</li>\n<li>We can use WHERE with a couple of different operators when making our comparison</li>\n<li>WHERE {column} = {value} provides an exact comparison</li>\n<li>WHERE {column} IN ({value1}, {value2}, {value3}, etc.) matches any provided value in the IN statement. We can make this more complex by having a subquery inside of the parentheses, having our column match any values within the returned results.</li>\n<li>WHERE {column} BETWEEN {value1} AND {value2} can check for matches between two values (numeric ranges)</li>\n<li>WHERE {column} LIKE {pattern} can check for matches to a string. This is most useful when we use the wildcard %, such as WHERE breed LIKE '%Shepherd', which will match any breed that ends in Shepherd</li>\n<li>The NOT operator can also be used for negation in the checks.</li>\n<li>\n<p>Mathematical operators can be used when performing calculations or comparisons within a query as well, such as</p>\n<p>SELECT name, breed, weight<em>lbs FROM puppies WHERE weight</em>lbs > 50; --- OR SELECT name, breed, age<em>yrs FROM puppies WHERE age</em>yrs * 10 = 5;</p>\n</li>\n</ul>\n<p><strong>How to use the JOIN keyword to join two (or more) tables together into a single virtual table</strong></p>\n<ul>\n<li>When we want to get information from a related table or do querying based on related table values, we can join the connected table by comparing the foreign key to where it lines up on the other table:</li>\n</ul>\n<p>--- Here we are joining the puppies table on to the friends table. We are specifying that the comparison we should make is the foreign key puppy_id on the friends table should line up with the primary key id on the puppies table.</p>\n<p>SELECT\n*\nFROM\nfriends\nJOIN\npuppies ON friends.puppy_id = puppies.id</p>\n<p><strong>How to use the INSERT statement to insert data into a table</strong></p>\n<ul>\n<li>When a table is already created we can then insert records into it using the INSERT INTO keywords.</li>\n<li>We provide the name of the table that we would like to add records to, followed by the VALUES keyword and each record we are adding. Here s an example:</li>\n</ul>\n<p>--- We are providing the table name, then multiple records to insert<br>\n--- The values are listed in the order that they are defined on the table</p>\n<p>INSERT INTO table<em>name\nVALUES\n(column1</em>value, colum2<em>value, column3</em>value),\n(column1<em>value, colum2</em>value, column3<em>value),\n(column1</em>value, colum2<em>value, column3</em>value);</p>\n<ul>\n<li>We can also specify columns when we are inserting data. This makes it clear which fields we are providing data for and allows us to provide them out of order, skip null or default values, etc.</li>\n</ul>\n<p>--- In this example, we want to use the default value for id since it is autoincremented, so we provide DEFAULT for this field</p>\n<p>INSERT INTO friends (id, first<em>name, last</em>name)\nVALUES\n(DEFAULT, 'Amy', 'Pond');</p>\n<p>--- Alternatively, we can leave it out completely, since the default value will be used if none is provided</p>\n<p>INSERT INTO friends (first<em>name, last</em>name)\nVALUES\n('Rose', 'Tyler'),\n('Martha', 'Jones'),\n('Donna', 'Noble'),\n('River', 'Song');</p>\n<p><strong>How to use an UPDATE statement to update data in a table</strong></p>\n<ul>\n<li>The UPDATE keyword can be used to find records and change their values in our database.</li>\n<li>We generally follow the pattern of UPDATE {table} SET {column} = {new value} WHERE {match condition};.</li>\n<li>Without a condition to narrow our records down, we will update every record in the table, so this is an important thing to double check!</li>\n<li>We can update multiple fields as well by specifying each column in parentheses and their associated new values: UPDATE {table} SET ({column1}, {column2}) = ({value1}, {value2}) WHERE {match condition};</li>\n</ul>\n<p>--- Updates the pet with id of 4 to change their name and breed</p>\n<p>UPDATE\npets\nSET\n(name, breed) = ('Floofy', 'Fluffy Dog Breed') WHERE id = 4;</p>\n<p><strong>How to use a DELETE statement to remove data from a table</strong></p>\n<ul>\n<li>Similar to selecting records, we can delete records from a table by specifying what table we are deleting from and what criteria we would like to match in order to delete.</li>\n<li>We follow the general structure DELETE FROM {table} WHERE {condition};</li>\n<li>The condition here is also very important! Without a condition, all records match and will be deleted.</li>\n</ul>\n<p>--- Deletes from the pets table any record that either has a name Floofy, a name Doggo, or an id of 3.</p>\n<p>DELETE FROM\npets\nWHERE\nname IN ('Floofy', 'Doggo') OR id = 3;</p>\n<p><strong>How to use a seed file to populate data in a database</strong></p>\n<ul>\n<li>Seed files are a great way for us to create records that we want to start our database out with.</li>\n<li>Instead of having to individually add records to our tables or manually entering them in psql or postbird, we can create a file that has all of these records and then just pass this file to psql to run.</li>\n<li>Seed files are also great if we ever need to reset our database. We can clear out any records that we have by dropping all of our tables, then just run our seed files to get it into a predetermined starting point. This is great for our personal projects, testing environments, starting values for new tables we create, etc.</li>\n<li>There are two main ways we can use a seed file with psql, the &#x3C; and the | operators. They perform the same function for us, just in slightly different orders, taking the content of a .sql file and executing in within the psql environment:</li>\n<li>psql -d {database} &#x3C; {sql filepath}</li>\n<li>cat {sql filepath} | psql -d {database}</li>\n</ul>\n<p><strong>SQL (continued)</strong></p>\n<p><strong>How to perform relational database design</strong></p>\n<ul>\n<li>Steps to Designing the Database:</li>\n<li>Define the entities. What data are are you storing, what are the fields for each entity?</li>\n<li>You can think of this in similar ways to OOP (object oriented programming).</li>\n<li>If you wanted to model this information using classes, what classes would you make? Those are generally going to be the tables that are created in your database.</li>\n<li>The attributes of your classes are generally going to be the fields/columns that we need for each table.</li>\n<li>Identify primary keys. Most of the time these will be ids that you can generate as a serial field, incrementing with each addition to the database.</li>\n<li>Establish table relationships. Connect related data together with foreign keys. Know how we store these keys in a one-to-one, one-to-many, or many-to-many relationship.</li>\n<li>With a one-to-one or one-to-many relationship, we are able to use a foreign key on the table to indicate the other specific record that it is connected to.</li>\n<li>With a many-to-many relationship, each record could be connected to multiple records, so we have to create a join table to connect these entities. A record on this join table connects a record from one table to a record from another table.</li>\n</ul>\n<p><strong>How to use transactions to group multiple SQL commands into one succeed or fail operation</strong></p>\n<ul>\n<li>We can define an explicit transaction using BEGIN and ending with either COMMIT or ROLLBACK.</li>\n<li>\n<p>If any command inside the block fails, everything will be rolled back. We can also specify that we want to roll back at the end of the block instead of committing. We saw that this can be useful when analyzing operations that would manipulate our database.</p>\n<p>BEGIN;<br>\nUPDATE accounts SET balance = balance --- 100.00<br>\nWHERE name = 'Alice';<br>\nUPDATE branches SET balance = balance --- 100.00<br>\nWHERE name = (SELECT branch<em>name FROM accounts WHERE name = 'Alice');<br>\nUPDATE accounts SET balance = balance + 100.00<br>\nWHERE name = 'Bob';<br>\nUPDATE branches SET balance = balance + 100.00<br>\nWHERE name = (SELECT branch</em>name FROM accounts WHERE name = 'Bob');<br>\nCOMMIT;</p>\n<p>BEGIN;<br>\nEXPLAIN ANALYZE<br>\nUPDATE cities<br>\nSET city = 'New York City'<br>\nWHERE city = 'New York';<br>\nROLLBACK;</p>\n</li>\n</ul>\n<p><strong>How to apply indexes to tables to improve performance</strong></p>\n<ul>\n<li>An index can help optimize queries that we have to run regularly. If we are constantly looking up records in a table by a particular field (such as username or phone number), we can add an index in order to speed up this process.</li>\n<li>An index maintains a sorted version of the field with a reference to the record that it points to in the table (via primary key). If we want to find a record based on a field that we have an index for, we can look through this index in a more efficient manner than having to scan through the entire table (generally O(log n) since the index is sorted, instead of O(n) for a sequential scan).</li>\n<li>\n<p>To add an index to a field we can use the following syntax:</p>\n<p>CREATE INDEX index<em>name ON table</em>name (column_name);</p>\n</li>\n<li>\n<p>To drop an index we can do the following:</p>\n<p>DROP INDEX index_name</p>\n</li>\n<li>Making an index is not always the best approach. Indices allow for faster lookup, but slow down record insertion and the updating of associated fields, since we not only have to add the information to the table, but also manipulate the index.</li>\n<li>We generally wouldn t care about adding an index if:</li>\n<li>The tables are small</li>\n<li>We are updating the table frequently, especially the associated columns</li>\n<li>The column has many NULL values</li>\n</ul>\n<p><strong>Explain what the EXPLAIN command is used for:</strong></p>\n<ul>\n<li>EXPLAIN gives us information about how a query will run (the query plan)</li>\n<li>It gives us an idea of how our database will search for data as well as a qualitative comparitor for how expensive that operation will be. Comparing the cost of two queries will tell us which one is more efficient (lower cost).</li>\n<li>We can also use the ANALYZE command with EXPLAIN, which will actually run the specified query. Doing so gives us more detailed information, such as the milliseconds it took our query to execute as well as specifics like the exact number of rows filtered and returned.</li>\n<li>Demonstrate how to install and use the node-postgres library and its Pool class to query a PostgreSQL-managed database</li>\n<li>\n<p>We can add the node-postgres library to our application with npm install pg. From there we will typically use the Pool class associated with this library. That way we can run many SQL queries with one database connection (as opposed to Client, which closes the connection after a query).</p>\n<p>const { Pool } = require('pg');</p>\n</li>\n</ul>\n<p>// If we need to specify a username, password, or database, we can do so when we create a Pool instance, otherwise the default values for logging in to psql are used:</p>\n<p>const pool = new Pool({ username: '&#x3C;<username>>', password: '&#x3C;<password>>', database: '&#x3C;<database>>'})</p>\n<ul>\n<li>\n<p>The query method on the Pool instance will allow us to execute a SQL query on our database. We can pass in a string that represents the query we want to run</p>\n<p>const allAirportsSql = <code class=\"language-text\">SELECT id, city_id, faa_id, name FROM airports;</code>;</p>\n<p>async function selectAllAirports() {<br>\nconst results = await pool.query(allAirportsSql);<br>\nconsole.log(results.rows);<br>\npool.end(); // invoking end() will close our connection to the database<br>\n}</p>\n</li>\n</ul>\n<p>selectAllAirports();</p>\n<ul>\n<li>The return value of this asynchronous function is an object with a rows key that points to an array of objects, each object representing a record with field names as keys.</li>\n</ul>\n<p><strong>Explain how to write prepared statements with placeholders for parameters of the form 1 ,1,2 , and so on</strong></p>\n<ul>\n<li>The prepared statement (SQL string that we wrote) can also be made more dynamic by allowing for parameters to be passed in.</li>\n<li>\n<p>The Pool instance s query function allows us to pass a second argument, an array of parameters to be used in the query string. The location of the parameter substitutions are designated with 1,1,2, etc., to signify the first, second, etc., arguments.</p>\n<p>const airportsByNameSql = <code class=\"language-text\">SELECT name, faa_id FROM airports WHERE UPPER(name) LIKE UPPER($1)</code>;</p>\n</li>\n</ul>\n<p>async function selectAirportsByName(name) {<br>\nconst results = await pool.query(airportsByNameSql, ParseError: KaTeX parse error: Expected group as argument to '`' at end of input: `%${name}%`);<br>\nconsole.log(results.rows);<br>\npool.end(); // invoking end() will close our connection to the database<br>\n}</p>\n<p>// Get the airport name from the command line and store it\n// in the variable \"name\". Pass that value to the\n// selectAirportsByName function.\nconst name = process.argv[2];\n// console.log(name);\nselectAirportsByName(name);</p>\n<p><strong>ORM</strong></p>\n<ol>\n<li>How to install, configure, and use Sequelize, an ORM for JavaScript</li>\n<li>To start a new project we use our standard npm initialize statement</li>\n<li>npm init -y</li>\n<li>Add in the packages we will need (sequelize, sequelize-cli, and pg)</li>\n<li>npm install sequelize@⁵.0.0 sequelize-cli@⁵.0.0 pg@⁸.0.0</li>\n<li>Initialize sequelize in our project</li>\n<li>npx sequelize-cli init</li>\n<li>Create a database user with credentials we will use for the project</li>\n<li>psql</li>\n<li>CREATE USER example_user WITH PASSWORD 'badpassword'</li>\n<li>\n<p>Here we can also create databases since we are already in postgres</p>\n<p>CREATE DATABASE example<em>app</em>development WITH OWNER example_user</p>\n<p>CREATE DATABASE example<em>app</em>test WITH OWNER example_user</p>\n<p>CREATE DATABASE example<em>app</em>production WITH OWNER example_user</p>\n</li>\n<li>If we don t create these databases now, we could also create them after we make our changes to our config file. If we take this approach, we need to make sure our user that we created has the CREATEDB option when we make them, since sequelize will attempt to make the databases with this user. This other approach would look like:</li>\n<li>In psql: CREATE USER example_user WITH PASSWORD 'badpassword' CREATEDB</li>\n<li>In terminal: npx sequelize-cli db:create</li>\n<li>\n<p>Double check that our configuration file matches our username, password, database, dialect, and seederStorage (these will be filled out for you in an assessment scenario):</p>\n<p>{<br>\n\"development\": {<br>\n\"username\": \"sequelize<em>recipe</em>box<em>app\",<br>\n\"password\": \"HfKfK79k\",<br>\n\"database\": \"recipe</em>box<em>development\",<br>\n\"host\": \"127.0.0.1\",<br>\n\"dialect\": \"postgres\",<br>\n\"seederStorage\": \"sequelize\"<br>\n},<br>\n\"test\": {<br>\n\"username\": \"sequelize</em>recipe<em>box</em>app\",<br>\n\"password\": \"HfKfK79k\",<br>\n\"database\": \"recipe<em>box</em>test\",<br>\n\"host\": \"127.0.0.1\",<br>\n\"dialect\": \"postgres\",<br>\n\"seederStorage\": \"sequelize\"<br>\n},<br>\n\"production\": {<br>\n\"username\": \"sequelize<em>recipe</em>box<em>app\",<br>\n\"password\": \"HfKfK79k\",<br>\n\"database\": \"recipe</em>box_production\",<br>\n\"host\": \"127.0.0.1\",<br>\n\"dialect\": \"postgres\",<br>\n\"seederStorage\": \"sequelize\"<br>\n}<br>\n}</p>\n</li>\n<li>How to use database migrations to make your database grow with your application in a source-control enabled way</li>\n</ol>\n<p><strong>Migrations</strong></p>\n<ul>\n<li>\n<p>In order to make new database tables and sequelize models that reflect them, we want to generate a migration file and model file using model:generate</p>\n<p>npx sequelize-cli model:generate --- name Cat --- attributes \"firstName:string,specialSkill:string\"</p>\n</li>\n<li>Here we are creating a migration file and a model file for a Cat. We are specifying that we want this table to have fields for firstName and specialSkill. Sequelize will automatically make fields for an id, createdAt, and updatedAt, as well, so we do not need to specify these.</li>\n<li>Once our migration file is created, we can go in and edit any details that we need to. Most often we will want to add in database constraints such as allowNull: false, adding a uniqueness constraint with unique: true, adding in character limits to fields such as type: Sequelize.STRING(100), or specifying a foreign key with references to another table references: { model: 'Categories' }.</li>\n<li>\n<p>After we make any necessary changes to our migration file, we need to perform the migration, which will run the SQL commands to actually create the table.</p>\n<p>npx sequelize-cli db:migrate</p>\n</li>\n<li>This command runs any migration files that have not been previously run, in the order that they were created (this is why the timestamp in the file name is important)</li>\n<li>\n<p>If we realize that we made a mistake after migrating, we can undo our previous migration, or all of our migrations. After undoing them, we can make any changes necessary to our migration files (They won t be deleted from the undo, so we don t need to generate anything! Just make the necessary changes to the files that already exist and save the files.). Running the migrations again will make the tables with the updates reflected.</p>\n<p>npx sequelize-cli db:migrate:undo</p>\n<p>npx sequelize-cli db:migrate:undo:all</p>\n</li>\n</ul>\n<p><strong>Models Validations and Associations</strong></p>\n<ul>\n<li>In addition to the migration files, our model:generate command also created a model file for us. This file is what allows sequelize to transform the results of its SQL queries into useful JavaScript objects for us.</li>\n<li>\n<p>The model is where we can specify a validation that we want to perform before trying to run a SQL query. If the validation fails, we can respond with a message instead of running the query, which can be an expensive operation that we know won t work.</p>\n<p>// Before we make changes, sequelize generates the type that this field represents specification:<br>\nDataTypes.TEXT<br>\n// We can replace the generated format with an object to specify not only the type, but the validations that we want to implement. The validations can also take in messages the respond with on failure and arguments.<br>\nspecification: {<br>\ntype: DataTypes.TEXT,<br>\nvalidate: {<br>\nnotEmpty: {<br>\nmsg: 'The specification cannot be empty'<br>\n},<br>\nlen: {<br>\nargs: [10, 100]<br>\nmsg: 'The specifcation must be between 10 and 100 characters'<br>\n}<br>\n}<br>\n}</p>\n</li>\n<li>Another key part of the model file is setting up our associations. We can use the belongsTo, hasMany, and belongsToMany methods to set up model-level associations. Doing so is what creates the helpful functionality like addOwner that we saw in the pets example, a function that automatically generates the SQL necessary to create a petOwner record and supplies the appropriate petId and ownerId.</li>\n<li>In a one-to-many association, we need to have a belongsTo association on the many side, and a hasMany association on the one side:</li>\n<li>Instruction.belongsTo(models.Recipe, { foreignKey: 'recipeId' });</li>\n<li>Recipe.hasMany(models.Instruction, { foreignKey: 'recipeId' });</li>\n<li>\n<p>In a many-to-many association, we need to have a belongsToMany on each side of the association. We generally specify a columnMapping object to show the association more clearly:</p>\n<p>// In our Owner model</p>\n<p>// To connect this Owner to a Pet through the PetOwner</p>\n<p>const columnMapping = {</p>\n<p>through: 'PetOwner',</p>\n<p>// joins table</p>\n<p>otherKey: 'petId',</p>\n<p>// key that connects to other table we have a many association with foreignKey: 'ownerId'</p>\n<p>// our foreign key in the joins table</p>\n<p>}</p>\n<p>Owner.belongsToMany( models.Pet, columnMapping );</p>\n<p>// In our Pet model</p>\n<p>// To connect this Pet to an Owner through the PetOwner</p>\n<p>const columnMapping = { through: 'PetOwner',</p>\n<p>// joins table</p>\n<p>otherKey: 'ownerId',</p>\n<p>// key that connects to other table we have a many association with</p>\n<p>foreignKey: 'petId'</p>\n<p>// our foreign key in the joins table</p>\n<p>}</p>\n<p>Pet.belongsToMany( models.Owner, columnMapping );</p>\n</li>\n</ul>\n<h3><strong>How to perform CRUD operations with Sequelize</strong></h3>\n<ul>\n<li>Seed Files</li>\n<li>Seed files can be used to populate our database with starter data.</li>\n<li>npx sequelize-cli seed:generate --- name add-cats</li>\n<li>up indicates what to create when we seed our database, down indicates what to delete if we want to unseed the database.</li>\n<li>\n<p>For our up, we use the queryInterface.bulkInsert() method, which takes in the name of the table to seed and an array of objects representing the records we want to create:</p>\n<p>up: (queryInterface, Sequelize) => {<br>\nreturn queryInterface.bulkInsert('&#x3C;>', [{<br>\nfield1: value1a,<br>\nfield2: value2a<br>\n}, {<br>\nfield1: value1b,<br>\nfield2: value2b<br>\n}, {<br>\nfield1: value1c,<br>\nfield2: value2c<br>\n}]);<br>\n}</p>\n</li>\n<li>\n<p>For our down, we use the queryInterface.bulkDelete() method, which takes in the name of the table and an object representing our WHERE clause. Unseeding will delete all records from the specified table that match the WHERE clause.</p>\n<p>// If we want to specify what to remove:<br>\ndown: (queryInterface, Sequelize) => {<br>\nreturn queryInterface.bulkDelete('&#x3C;>', {<br>\nfield1: [value1a, value1b, value1c], //...etc.<br>\n});<br>\n};<br>\n// If we want to remove everything from the table:<br>\ndown: (queryInterface, Sequelize) => {<br>\nreturn queryInterface.bulkDelete('&#x3C;>', null, {});<br>\n};</p>\n</li>\n<li>Running npx sequelize-cli db:seed:all will run all of our seeder files.</li>\n<li>npx sequelize-cli db:seed:undo:all will undo all of our seeding.</li>\n<li>If we omit the :all we can run specific seed files</li>\n<li>Inserting with Build and Create</li>\n<li>In addition to seed files, which we generally use for starter data, we can create new records in our database by using build and save, or the combined create</li>\n<li>\n<p>Use the .build method of the Cat model to create a new Cat instance in index.js</p>\n<p>// Constructs an instance of the JavaScript <code class=\"language-text\">Cat</code> class. <strong>Does not<br>\n// save anything to the database yet</strong>. Attributes are passed in as a<br>\n// POJO.<br>\nconst newCat = Cat.build({<br>\nfirstName: 'Markov',<br>\nspecialSkill: 'sleeping',<br>\nage: 5<br>\n});<br>\n// This actually creates a new <code class=\"language-text\">Cats</code> record in the database. We must<br>\n// wait for this asynchronous operation to succeed.<br>\nawait newCat.save();<br>\n// This builds and saves all in one step. If we don't need to perform any operations on the instance before saving it, this can optimize our code.<br>\nconst newerCat = await Cat.create({<br>\nfirstName: 'Whiskers',<br>\nspecialSkill: 'sleeping',<br>\nage: 2<br>\n})</p>\n</li>\n</ul>\n<p><strong>Updating Records</strong></p>\n<ul>\n<li>When we have a reference to an instance of a model (i.e. after we have queried for it or created it), we can update values by simply reassigning those fields and using the save method</li>\n</ul>\n<p><strong>Deleting Records</strong></p>\n<ul>\n<li>When we have a reference to an instance of a model, we can delete that record by using destroy</li>\n<li>const cat = await Cat.findByPk(1); // Remove the Markov record. await cat.destroy();</li>\n<li>We can also call destroy on the model itself. By passing in an object that specifies a where clause, we can destroy all records that match that query</li>\n<li>await Cat.destroy({ where: { specialSkill: 'jumping' } });</li>\n</ul>\n<p><strong>How to query using Sequelize</strong></p>\n<p><strong>findAll</strong></p>\n<p>const cats = await Cat.findAll();\n// Log the fetched cats.\n// The extra arguments to stringify are a replacer and a space respectively\n// Here we're specifying a space of 2 in order to print more legibly\n// We don't want a replacer, so we pass null just so that we can pass a 3rd argument\nconsole.log(JSON.stringify(cats, null, 2));</p>\n<p><strong>WHERE clause</strong></p>\n<ul>\n<li>Passing an object to findAll can add on clauses to our query</li>\n<li>The where key takes an object as a value to indicate what we are filtering by</li>\n<li>\n<p>{ where: { field: value } } => WHERE field = value</p>\n<p>const cats = await Cat.findAll({ where: { firstName: \"Markov\" } }); console.log(JSON.stringify(cats, null, 2));</p>\n</li>\n</ul>\n<p><strong>OR in the WHERE clause</strong></p>\n<ul>\n<li>Using an array for the value tells sequelize we want to match any of these values</li>\n</ul>\n<p>{ where: { field:value1, value2value1,value2} => WHERE field IN (value1, value2)</p>\n<p>const cats = await Cat.findAll({ where: { firstName: [\"Markov\", \"Curie\"] } });const cats = await Cat.findAll({\nwhere: {\nfirstName: \"Markov\",\nage: 4\n}\n});\nconsole.log(JSON.stringify(cats, null, 2));</p>\n<p>console.log(JSON.stringify(cats, null, 2));</p>\n<p><strong>AND in the WHERE clause</strong></p>\n<ul>\n<li>Providing additional key/value pairs to the where object indicates all filters must match</li>\n<li>{ where: { field1: value1, field2: value2 } } => WHERE field1 = value1 AND field2 = value2</li>\n</ul>\n<h3>Sequelize Op operator</h3>\n<ul>\n<li>By requiring Op from the sequelize library we can provide more advanced comparison operators</li>\n<li>const { Op } = require(\"sequelize\");</li>\n<li>\n<p><a href=\"https://op.ne/\">Op.ne</a>: Not equal operator</p>\n<p>const cats = await Cat.findAll({<br>\nwhere: {<br>\nfirstName: {<br>\n// All cats where the name is not equal to \"Markov\"<br>\n// We use brackets in order to evaluate <a href=\"https://op.ne/\">Op.ne</a> and use the value as the key<br>\n[<a href=\"https://op.ne/\">Op.ne</a>]: \"Markov\"<br>\n},<br>\n},<br>\n});<br>\nconsole.log(JSON.stringify(cats, null, 2));</p>\n</li>\n</ul>\n<h3>Op.and: and operator</h3>\n<p>const cats = await Cat.findAll({\nwhere: {\n// The array that Op.and points to must all be true\n// Here, we find cats where the name is not \"Markov\" and the age is 4\n[Op.and]: [{\nfirstName: {\n[Op.ne]: \"Markov\"\n}\n}, {\nage: 4\n}, ],\n},\n});\nconsole.log(JSON.stringify(cats, null, 2));</p>\n<h3>Op.or: or operator</h3>\n<p>const cats = await Cat.findAll({\nwhere: {\n// One condition in the array that Op.or points to must be true\n// Here, we find cats where the name is \"Markov\" or where the age is 4\n[Op.or]: [{\nfirstName: \"Markov\"\n}, {\nage: 4\n}, ],\n},\n});\nconsole.log(JSON.stringify(cats, null, 2));</p>\n<p><a href=\"https://op.gt/\">Op.gt</a> and <a href=\"https://op.lt/\">Op.lt</a>: greater than and less than operators</p>\n<p>const cats = await Cat.findAll({ where: { // Find all cats where the age is greater than 4 age: {Op.gtOp.gt: 4 }, } }, }); console.log(JSON.stringify(cats, null, 2));</p>\n<h4>Ordering results</h4>\n<ul>\n<li>Just like the where clause, we can pass an order key to specify we want our results ordered</li>\n<li>The key order points to an array with the fields that we want to order by</li>\n<li>By default, the order is ascending, just like standard SQL. If we want to specify descending, we can instead use a nested array with the field name as the first element and DESC as the second element. (We could also specify ASC as a second element in a nested array, but it is unnecessary as it is default)</li>\n<li>\n<p>const cats = await Cat.findAll({ // Order by age descending, then by firstName ascending if cats have the same age order: ParseError: KaTeX parse error: Undefined control sequence: [ at position 1: \\̲[̲\"age\", \"DESC\", \"firstName\"], }); console.log(JSON.stringify(cats, null, 2));</p>\n<p>// Get a reference to the cat record that we want to update (here just the cat with primary key of 1)<br>\nconst cat = await Cat.findByPk(1);<br>\n// Change cat's attributes.<br>\ncat.firstName = \"Curie\";<br>\ncat.specialSkill = \"jumping\";<br>\ncat.age = 123;<br>\n// Save the new name to the database.<br>\nawait cat.save();</p>\n</li>\n<li>Limiting results</li>\n<li>\n<p>We can provide a limit key in order to limit our results to a specified number</p>\n<p>const cats = await Cat.findAll({<br>\norder: [<br>\n[\"age\", \"DESC\"]<br>\n],<br>\n// Here we are limiting our results to one record. It will still return an array, just with one object inside. We could have said any number here, the result is always an array.<br>\nlimit: 1,<br>\n});<br>\nconsole.log(JSON.stringify(cats, null, 2));</p>\n</li>\n</ul>\n<h3>findOne</h3>\n<ul>\n<li>If we only want one record to be returned we can use findOne instead of findAll</li>\n<li>If multiple records would have matched our findOne query, it will return the first record</li>\n<li>\n<p>Unlike findAll, findOne will return the object directly instead of an array. If no records matched the query it will return null.</p>\n<p>// finds the oldest cat const cat = await Cat.findOne({ order: <a href=\"file:///C:/MY-WEB-DEV/BLOG____2.0/BGOONZ_BLOG_2.0/src/pages/docs/content/%E2%80%9Cage%E2%80%9D,_%E2%80%9CDESC%E2%80%9D.md\">\"age\", \"DESC\"</a>, }); console.log(JSON.stringify(cat, null, 2));</p>\n</li>\n<li><strong>Querying with Associations</strong></li>\n</ul>\n<p>We can include associated data by adding an include key to our options object</p>\n<p>const pet = Pet.findByPk(1, {\ninclude: [PetType, Owner]\n});\nconsole.log(pet.id, pet.name, pet.age, pet.petTypeId, pet.PetType.type, pet.Owners</p>\n<p>We can get nested associations by having include point to an object that specifies which model we have an association with, then chaining an association on with another include</p>\n<p><strong>How to perform data validations with Sequelize</strong></p>\n<ul>\n<li>See the database migrations section above.</li>\n<li>\n<p>In general, we add in a validate key to each field that we want validations for. This key points to an object that specifies all of the validations we want to make on that field, such as notEmpty, notNull, len, isIn, etc.</p>\n<p>specification: {<br>\ntype: DataTypes.TEXT,<br>\nvalidate: {<br>\nnotEmpty: {<br>\nmsg: 'The specification cannot be empty'<br>\n},<br>\nlen: {<br>\nargs: [10, 100]<br>\nmsg: 'The specifcation must be between 10 and 100 characters'<br>\n}<br>\n}<br>\n}</p>\n</li>\n</ul>\n<p><strong>How to use transactions with Sequelize</strong></p>\n<ul>\n<li>We can create a transaction block in order to make sure either all operations are performed or none of them are</li>\n<li>We use the .transaction method in order to create our block. The method takes in a callback with an argument to track our transaction id (typically just a simple tx variable).</li>\n<li>\n<p>All of our sequelize operations can be passed a transaction key on their options argument which points to our transaction id. This indicates that this operation is part of the transaction block and should only be executed in the database when the whole block executes without error.</p>\n<p>async function main() {<br>\ntry {<br>\n// Do all database access within the transaction.<br>\nawait sequelize.transaction(async (tx) => {<br>\n// Fetch Markov and Curie's accounts.<br>\nconst markovAccount = await BankAccount.findByPk(<br>\n1, {<br>\ntransaction: tx<br>\n},<br>\n);<br>\nconst curieAccount = await BankAccount.findByPk(<br>\n2, {<br>\ntransaction: tx<br>\n}<br>\n);<br>\n// No one can mess with Markov or Curie's accounts until the<br>\n// transaction completes! The account data has been locked!<br>\n// Increment Curie's balance by 5,000. curieAccount.balance += 5000; await curieAccount.save({ transaction: tx }); // Decrement Markov's balance by5,000.curieAccount.balance+=5000;awaitcurieAccount.save(transaction:tx);//DecrementMarkov′sbalanceby5,000.<br>\nmarkovAccount.balance -= 5000;<br>\nawait markovAccount.save({<br>\ntransaction: tx<br>\n});<br>\n});<br>\n} catch (err) {<br>\n// Report if anything goes wrong.<br>\nconsole.log(\"Error!\");<br>\nfor (const e of err.errors) {<br>\nconsole.log(<br>\n<code class=\"language-text\">${e.instance.clientName}: ${e.message}</code><br>\n);<br>\n}<br>\n}<br>\nawait sequelize.close();<br>\n}<br>\nmain();</p>\n</li>\n</ul>\n<hr>\n<h3>Sequelize Cheatsheet</h3>\n<h4>Command Line</h4>\n<p>Sequelize provides utilities for generating migrations, models, and seed files. They are exposed through the <code class=\"language-text\">sequelize-cli</code> command.</p>\n<h4>Init Project</h4>\n<p>$ npx sequelize-cli init</p>\n<p>You must create a database user, and update the <code class=\"language-text\">config/config.json</code> file to match your database settings to complete the initialization process.</p>\n<h4>Create Database</h4>\n<p>npx sequelize-cli db:create</p>\n<h4>Generate a model and its migration</h4>\n<p>npx sequelize-cli model:generate --name <ModelName> --attributes <column1>:<type>,<column2>:<type>,...</p>\n<h4>Run pending migrations</h4>\n<p>npx sequelize-cli db:migrate</p>\n<h4>Rollback one migration</h4>\n<p>npx sequelize-cli db:migrate:undo</p>\n<h4>Rollback all migrations</h4>\n<p>npx sequelize-cli db:migrate:undo:all</p>\n<h4>Generate a new seed file</h4>\n<p>npx sequelize-cli seed:generate --name <descriptiveName></p>\n<h4>Run all pending seeds</h4>\n<p>npx sequelize-cli db:seed:all</p>\n<h4>Rollback one seed</h4>\n<p>npx sequelize-cli db:seed:undo</p>\n<h4>Rollback all seeds</h4>\n<p>npx sequelize-cli db:seed:undo:all</p>\n<h4>Migrations</h4>\n<h3>Create Table (usually used in the up() method)</h3>\n<p>// This uses the short form for references\nreturn queryInterface.createTable(<TableName>, {\n<columnName>: {\ntype: Sequelize.<type>,\nallowNull: &#x3C;true|false>,\nunique: &#x3C;true|false>,\nreferences: { model: <TableName> }, // This is the plural table name\n// that the column references.\n}\n});\n// This the longer form for references that is less confusing\nreturn queryInterface.createTable(<TableName>, {\n<columnName>: {\ntype: Sequelize.<type>,\nallowNull: &#x3C;true|false>,\nunique: &#x3C;true|false>,\nreferences: {\nmodel: {\ntableName: <TableName> // This is the plural table name\n}\n}\n}\n});</p>\n<h3>Delete Table (usually used in the down() function)</h3>\n<p>return queryInterface.dropTable(<TableName>);</p>\n<h3>Adding a column</h3>\n<p>return queryInteface.addColumn(<TableName>, <columnName>: {\ntype: Sequelize.<type>,\nallowNull: &#x3C;true|false>,\nunique: &#x3C;true|false>,\nreferences: { model: <TableName> }, // This is the plural table name\n// that the column references.\n});</p>\n<h3>Removing a column</h3>\n<p>return queryInterface.removeColumn(<TableName>, <columnName>);</p>\n<h3>Model Associations</h3>\n<h3>One to One between Student and Scholarship</h3>\n<p><code class=\"language-text\">student.js</code></p>\n<p>Student.hasOne(models.Scholarship, { foreignKey: 'studentId' });</p>\n<p><code class=\"language-text\">scholarship.js</code></p>\n<p>Scholarship.belongsTo(models.Student, { foreignKey: 'studentId' });</p>\n<h3>One to Many between Student and Class</h3>\n<p><code class=\"language-text\">student.js</code></p>\n<p>Student.belongsTo(models.Class, { foreignKey: 'classId' });</p>\n<p><code class=\"language-text\">class.js</code></p>\n<p>Class.hasMany(models.Student, { foreignKey: 'classId' });</p>\n<h3>Many to Many between Student and Lesson through StudentLessons table</h3>\n<p><code class=\"language-text\">student.js</code></p>\n<p>const columnMapping = {\nthrough: 'StudentLesson', // This is the model name referencing the join table.\notherKey: 'lessonId',\nforeignKey: 'studentId'\n}\nStudent.belongsToMany(models.Lesson, columnMapping);</p>\n<p><code class=\"language-text\">lesson.js</code></p>\n<p>const columnMapping = {\nthrough: 'StudentLesson', // This is the model name referencing the join table.\notherKey: 'studentId',\nforeignKey: 'lessonId'\n}\nLesson.belongsToMany(models.Student, columnMapping);</p>\n<h3>Inserting a new item</h3>\n<p>// Way 1 - With build and save\nconst pet = Pet.build({\nname: \"Fido\",\npetTypeId: 1\n});\nawait pet.save();\n// Way 2 - With create\nconst pet = await Pet.create({\nname: \"Fido\",\npetTypeId: 1\n});</p>\n<h3>Updating an item</h3>\n<p>// Find the pet with id = 1\nconst pet = await Pet.findByPk(1);\n// Way 1\npet.name = \"Fido, Sr.\"\nawait pet.save;\n// Way 2\nawait pet.update({\nname: \"Fido, Sr.\"\n});</p>\n<h3>Deleting a single item</h3>\n<p>// Find the pet with id = 1\nconst pet = await Pet.findByPk(1);\n// Notice this is an instance method\npet.destroy();</p>\n<h3>Deleting multiple items</h3>\n<p>// Notice this is a static class method\nawait Pet.destroy({\nwhere: {\npetTypeId: 1 // Destorys all the pets where the petType is 1\n}\n});</p>\n<h3>Query Format</h3>\n<h3>findOne</h3>\n<p>await <Model>.findOne({\nwhere: {\n<column>: {\n[Op.<operator>]: <value>\n}\n},\n});</p>\n<h3>findAll</h3>\n<p>await <Model>.findAll({\nwhere: {\n<column>: {\n[Op.<operator>]: <value>\n}\n},\ninclude: &#x3C;include_specifier>,\noffset: 10,\nlimit: 2\n});</p>\n<h3>findByPk</h3>\n<p>await <Model>.findByPk(&#x3C;primary<em>key>, {\ninclude: &#x3C;include</em>specifier>\n});</p>\n<h3>Eager loading associations with <code class=\"language-text\">include</code></h3>\n<p>Simple include of one related model.</p>\n<p>await Pet.findByPk(1,  {\ninclude: PetType\n})</p>\n<p>Include can take an array of models if you need to include more than one.</p>\n<p>await Pet.findByPk(1, {\ninclude: [Pet, Owner]\n})</p>\n<p>Include can also take an object with keys <code class=\"language-text\">model</code> and <code class=\"language-text\">include</code>.<br>\nThis is in case you have nested associations.<br>\nIn this case Owner doesn't have an association with PetType, but<br>\nPet does, so we want to include PetType onto the Pet Model.</p>\n<p>await Owner.findByPk(1, {\ninclude: {\nmodel: Pet\ninclude: PetType\n}\n});</p>\n<h3>toJSON method</h3>\n<p>The confusingly named toJSON() method does <strong>not</strong> return a JSON string but instead<br>\nreturns a POJO for the instance.</p>\n<p>// pet is an instance of the Pet class\nconst pet = await Pet.findByPk(1);\nconsole.log(pet) // prints a giant object with\n// tons of properties and methods\n// petPOJO is now just a plain old Javascript Object\nconst petPOJO = pet.toJSON();\nconsole.log(petPOJO); // { name: \"Fido\", petTypeId: 1 }</p>\n<h3>Common Where Operators</h3>\n<p>const Op = Sequelize.Op\n[Op.and]: [{a: 5}, {b: 6}] // (a = 5) AND (b = 6)\n[Op.or]: [{a: 5}, {a: 6}]  // (a = 5 OR a = 6)\n[Op.gt]: 6,                // > 6\n[Op.gte]: 6,               // >= 6\n[Op.lt]: 10,               // &#x3C; 10\n[Op.lte]: 10,              // &#x3C;= 10\n[Op.ne]: 20,               // != 20\n[Op.eq]: 3,                // = 3\n[Op.is]: null              // IS NULL\n[Op.not]: true,            // IS NOT TRUE\n[Op.between]: [6, 10],     // BETWEEN 6 AND 10\n[Op.notBetween]: [11, 15], // NOT BETWEEN 11 AND 15\n[Op.in]: [1, 2],           // IN [1, 2]\n[Op.notIn]: [1, 2],        // NOT IN [1, 2]\n[Op.like]: '%hat',         // LIKE '%hat'\n[Op.notLike]: '%hat'       // NOT LIKE '%hat'\n[Op.iLike]: '%hat'         // ILIKE '%hat' (case insensitive) (PG only)\n[Op.notILike]: '%hat'      // NOT ILIKE '%hat'  (PG only)\n[Op.startsWith]: 'hat'     // LIKE 'hat%'\n[Op.endsWith]: 'hat'       // LIKE '%hat'\n[Op.substring]: 'hat'      // LIKE '%hat%'\n[Op.regexp]: '^[h|a|t]'    // REGEXP/~ '^[h|a|t]' (MySQL/PG only)\n[Op.notRegexp]: '^[h|a|t]' // NOT REGEXP/!~ '^[h|a|t]' (MySQL/PG only)\n[Op.iRegexp]: '^[h|a|t]'    // ~<em>'^[h|a|t]' (PG only)\n[Op.notIRegexp]: '^[h|a|t]' // !~</em> '^[h|a|t]' (PG only)\n[Op.like]: { [Op.any]: ['cat', 'hat']}</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/2560/1*IdBeXbBynFmQD7WwTNr7Hw.png\" alt=\"image\"></p>\n<h1><img src=\"https://cdn-images-1.medium.com/max/2560/1*bgZjuBly2EBDtGiCFaFoFw.png\" alt=\"image\"></h1>\n<p><img src=\"https://cdn-images-1.medium.com/max/2560/1*IdBeXbBynFmQD7WwTNr7Hw.png\"></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/2560/1*bgZjuBly2EBDtGiCFaFoFw.png\"></p>\n<blockquote>\n<blockquote>\n<blockquote>\n<blockquote>\n<blockquote>\n<blockquote>\n<p>c7e25372c (broken)</p>\n</blockquote>\n</blockquote>\n</blockquote>\n</blockquote>\n</blockquote>\n</blockquote>\n<h3>Accessing the Data</h3>\n<p>You can access and query the data using the <code class=\"language-text\">findByPk</code>, <code class=\"language-text\">findOne</code>, and <code class=\"language-text\">findAll</code> methods. First, make sure you import the models in your JavaScript file. In this case, we are assuming your JavaScript file is in the root of your project and so is the models folder.</p>\n<p>const { Recipe, Ingredient, Instruction, MeasurementUnit } = require('./models');</p>\n<p>The models folder exports each of the models that you have created. We have these four in our data model, so we will destructure the models to access each table individually. The associations that you have defined in each of your models will allow you to access data of related tables when you query your database using the <code class=\"language-text\">include</code> option.</p>\n<p>If you want to find all recipes, for the recipe list, you would use the <code class=\"language-text\">findAll</code> method. You need to await this, so make sure your function is async.</p>\n<p>async function findAllRecipes() {</p>\n<p>return await Recipe.findAll();</p>\n<p>}</p>\n<p>If you would like to include all the ingredients so you can create a shopping list for all the recipes, you would use <code class=\"language-text\">include</code>. This is possible because of the association you have defined in your Recipe and Ingredient models.</p>\n<p>async function getShoppingList() {</p>\n<p>return await Recipe.findAll({ include: [ Ingredient ] });</p>\n<p>}</p>\n<p>If you only want to find one where there is chicken in the ingredients list, you would use <code class=\"language-text\">findOne</code> and <code class=\"language-text\">findByPk</code>.</p>\n<p>async function findAChickenRecipe() {</p>\n<p>const chickenRecipe = await Ingredient.findOne({</p>\n<p>where: {</p>\n<p>foodStuff: 'chicken'</p>\n<p>}</p>\n<p>});</p>\n<p>return await Recipe.findByPk(chickenRecipe.recipeId);</p>\n<p>}</p>\n<h3>Data Access to Create/Update/Delete Rows</h3>\n<p>You have two options when you want to create a row in a table (where you are saving one record into the table). You can either <code class=\"language-text\">.build</code> the row and then <code class=\"language-text\">.save</code> it, or you can <code class=\"language-text\">.create</code> it. Either way it does the same thing. Here are some examples:</p>\n<p>Let's say we have a form that accepts the name of the recipe (for simplicity). When we get the results of the form, we can:</p>\n<p>const newRecipe = await Recipe.build({ title: 'Chicken Noodle Soup' });</p>\n<p>await newRecipe.save();</p>\n<p>This just created our new recipe and added it to our Recipes table. You can do the same thing like this:</p>\n<p>await Recipe.create({ title: 'Chicken Noodle Soup' });</p>\n<p>If you want to modify an item in your table, you can use <code class=\"language-text\">update</code>. Let's say we want to change the chicken noodle soup to chicken noodle soup with extra veggies, first we need to get the recipe, then we can update it.</p>\n<p>const modRecipe = await Recipe.findOne({ where: { title: 'Chicken Noodle Soup' } });</p>\n<p>await modRecipe.update({ title: 'Chicken Noodle Soup with Extra Veggies' });</p>\n<p>To delete an item from your table, you will do the same kind of process. Find the recipe you want to delete and <code class=\"language-text\">destroy</code> it, like this:</p>\n<p>const deleteThis = await Recipe.findOne({ where: { title: 'Chicken Noodle Soup with Extra Veggies' } });</p>\n<p>await deleteThis.destroy();</p>\n<p><strong>NOTE:</strong> If you do not await these, you will receive a promise, so you will need to use <code class=\"language-text\">.then</code> and <code class=\"language-text\">.catch</code> to do more with the items you are accessing and modifying.</p>\n<h3>Documentation</h3>\n<p>For the data types and validations in your models, here are the official docs. The sequelize docs are hard to look at, so these are the specific sections with just the lists:<br>\n<strong>Sequelize Data Types:</strong> <a href=\"https://sequelize.org/v5/manual/data-types.html\"><em>https://sequelize.org/v5/manual/data-types.html</em></a><br>\n<strong>Validations:</strong> <a href=\"https://sequelize.org/v5/manual/models-definition.html#validations\"><em>https://sequelize.org/v5/manual/models-definition.html#validations</em></a><br>\nWhen you access the data in your queries, here are the operators available, again because the docs are hard to navigate, this is the specific section with the list of operators.<br>\n<strong>Operators:</strong> <a href=\"https://sequelize.org/v5/manual/querying.html#operators\"><em>https://sequelize.org/v5/manual/querying.html#operators</em></a><br>\nThe documentation for building, saving, creating, updating and destroying is linked here, it does a pretty good job of explaining in my opinion, it just has a title that we have not been using in this course. When they talk about an instance, they mean an item stored in your table.<br>\n<strong>Create/Update/Destroy:</strong> <a href=\"https://sequelize.org/v5/manual/instances.html\"><em>https://sequelize.org/v5/manual/instances.html</em></a></p>"},{"url":"/docs/content/trouble-shooting/","relativePath":"docs/content/trouble-shooting.md","relativeDir":"docs/content","base":"trouble-shooting.md","name":"trouble-shooting","frontmatter":{"title":"Trouble Shooting","weight":0,"excerpt":"Here I will save details of problems I have been troubleshooting.","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<h1>  Trouble Shooting Log </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"900\" height=\"1400\" frameborder=\"0\" scrolling=\"no\" src=\"https://onedrive.live.com/embed?resid=D21009FDD967A241%21538628&authkey=%21AB8fPL3wSKz3AxU&em=2&AllowTyping=True&wdHideGridlines=True&wdHideHeaders=True&wdDownloadButton=True&wdInConfigurator=True\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/css/","relativePath":"docs/css/index.md","relativeDir":"docs/css","base":"index.md","name":"index","frontmatter":{"title":"CSS ","template":"docs"},"html":"<h1>CSS</h1>\n<p>CSS is among the core languages of the open web and is standardized across Web browsers according to <a href=\"https://w3.org/Style/CSS/#specs\">W3C specifications</a>. Previously, development of various parts of CSS specification was done synchronously, which allowed versioning of the latest recommendations. You might have heard about CSS1, CSS2.1, CSS3. However, CSS4 has never become an official version.</p>\n<p>From CSS3, the scope of the specification increased significantly and the progress on different CSS modules started to differ so much, that it became more effective to <a href=\"https://www.w3.org/Style/CSS/current-work\">develop and release recommendations separately per module</a>. Instead of versioning the CSS specification, W3C now periodically takes a snapshot of <a href=\"https://www.w3.org/TR/css/\">the latest stable state of the CSS specification</a>.</p>\n<h2><a href=\"https://webdevhub.us/docs/css/#key_resources\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS#key_resources\" title=\"Permalink to Key resources\">Key resources</a></h2>\n<p>CSS Introduction</p>\n<p>If you're new to web development, be sure to read our <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics\">CSS basics</a> article to learn what CSS is and how to use it.</p>\n<p>CSS Tutorials</p>\n<p>Our <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS\">CSS learning area</a> contains a wealth of tutorials to take you from beginner level to proficiency, covering all the fundamentals.</p>\n<p>CSS Reference</p>\n<p>Our <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference\">exhaustive CSS reference</a> for seasoned Web developers describes every property and concept of CSS.</p>\n<h4>Looking to become a front-end web developer?</h4>\n<p>We have put together a course that includes all the essential information you need to work towards your goal.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Front-end_web_developer\">Get started</a></p>\n<h2><a href=\"https://webdevhub.us/docs/css/#tutorials\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS#tutorials\" title=\"Permalink to Tutorials\">Tutorials</a></h2>\n<p>Our <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS\">CSS Learning Area</a> features multiple modules that teach CSS from the ground up --- no previous knowledge required.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps\">CSS first steps</a></p>\n<p>CSS (Cascading Style Sheets) is used to style and layout web pages --- for example, to alter the font, color, size, and spacing of your content, split it into multiple columns, or add animations and other decorative features. This module provides a gentle beginning to your path towards CSS mastery with the basics of how it works, what the syntax looks like, and how you can start using it to add styling to HTML.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks\">CSS building blocks</a></p>\n<p>This module carries on where <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps\">CSS first steps</a> left off --- now you've gained familiarity with the language and its syntax, and got some basic experience with using it, it's time to dive a bit deeper. This module looks at the cascade and inheritance, all the selector types we have available, units, sizing, styling backgrounds and borders, debugging, and lots more.</p>\n<p>The aim here is to provide you with a toolkit for writing competent CSS and help you understand all the essential theory, before moving on to more specific disciplines like <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text\">text styling</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout\">CSS layout</a>.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text\">Styling text</a></p>\n<p>With the basics of the CSS language covered, the next CSS topic for you to concentrate on is styling text --- one of the most common things you'll do with CSS. Here we look at text styling fundamentals, including setting font, boldness, italics, line and letter spacing, drop shadows, and other text features. We round off the module by looking at applying custom fonts to your page, and styling lists and links.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout\">CSS layout</a></p>\n<p>At this point we've already looked at CSS fundamentals, how to style text, and how to style and manipulate the boxes that your content sits inside. Now it's time to look at how to place your boxes in the right place in relation to the viewport, and to each other. We have covered the necessary prerequisites so we can now dive deep into CSS layout, looking at different display settings, modern layout tools like flexbox, CSS grid, and positioning, and some of the legacy techniques you might still want to know about.</p>\n<ul>\n<li>The property which is an identifier, that is a human-readable <em>name</em>, that defines which feature is considered.</li>\n<li>The value which describe how the feature must be handled by the engine. Each property has a set of valid values, defined by a formal grammar, as well as a semantic meaning, implemented by the browser engine.</li>\n</ul>\n<h2><a href=\"https://webdevhub.us/docs/css/#css_declarations\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declarations\" title=\"Permalink to CSS declarations\">CSS declarations</a></h2>\n<p>Setting CSS properties to specific values is the core function of the CSS language. A property and value pair is called a declaration, and any CSS engine calculates which declarations apply to every single element of a page in order to appropriately lay it out, and to style it.</p>\n<p>Both properties and values are case-insensitive by default in CSS. The pair is separated by a colon, '<code class=\"language-text\">:</code>' (<code class=\"language-text\">U+003A COLON</code>), and white spaces before, between, and after properties and values, but not necessarily inside, are ignored.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/css_syntax_-_declaration.png\" alt=\"css syntax - declaration.png\"></p>\n<p>There are more than <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference\">100 different properties</a> in CSS and a nearly infinite number of different values. Not all pairs of properties and values are allowed and each property defines what are the valid values. When a value is not valid for a given property, the declaration is deemed <em>invalid</em> and is wholly ignored by the CSS engine.</p>\n<h2><a href=\"https://webdevhub.us/docs/css/#css_declaration_blocks\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declaration_blocks\" title=\"Permalink to CSS declaration blocks\">CSS declaration blocks</a></h2>\n<p>Declarations are grouped in blocks, that is in a structure delimited by an opening brace, '<code class=\"language-text\">{</code>' (<code class=\"language-text\">U+007B LEFT CURLY BRACKET</code>), and a closing one, '<code class=\"language-text\">}</code>' (<code class=\"language-text\">U+007D RIGHT CURLY BRACKET</code>). Blocks sometimes can be nested, so opening and closing braces must be matched.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/css_syntax_-_block.png\" alt=\"css syntax - block.png\"></p>\n<p>Such blocks are naturally called declaration blocks and declarations inside them are separated by a semi-colon, '<code class=\"language-text\">;</code>' (<code class=\"language-text\">U+003B SEMICOLON</code>). A declaration block may be empty, that is containing null declaration. White spaces around declarations are ignored. The last declaration of a block doesn't need to be terminated by a semi-colon, though it is often considered <em>good style</em> to do it as it prevents forgetting to add it when extending the block with another declaration.</p>\n<p>A CSS declaration block is visualized in the diagram below.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/declaration-block.png\" alt=\"css syntax - declarations block.png\"></p>\n<p>Note: The content of a CSS declaration block, that is a list of semi-colon-separated declarations, without the initial and closing braces, can be put inside an HTML <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#attr-style\"><code class=\"language-text\">style</code></a> attribute.</p>\n<h2><a href=\"https://webdevhub.us/docs/css/#css_rulesets\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_rulesets\" title=\"Permalink to CSS rulesets\">CSS rulesets</a></h2>\n<p>If style sheets could only apply a declaration to each element of a Web page, they would be pretty useless. The real goal is to apply different declarations to different parts of the document.</p>\n<p>CSS allows this by associating conditions with declarations blocks. Each (valid) declaration block is preceded by one or more comma-separated <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors\">selectors</a>, which are conditions selecting some elements of the page. A <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Selector_list\">selector group</a> and an associated declarations block, together, are called a ruleset, or often a rule.</p>\n<p>A CSS ruleset (or rule) is visualized in the diagram below.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/ruleset.png\" alt=\"css syntax - ruleset.png\"></p>\n<p>As an element of the page may be matched by several selectors, and therefore by several rules potentially containing a given property several times, with different values, the CSS standard defines which one has precedence over the other and must be applied: this is called the <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance\">cascade</a> algorithm.</p>\n<p>Note: It is important to note that even if a ruleset characterized by a group of selectors is a kind of shorthand replacing rulesets with a single selector each, this doesn't apply to the validity of the ruleset itself.</p>\n<p>This leads to an important consequence: if one single basic selector is invalid, like when using an unknown pseudo-element or pseudo-class, the whole <em>selector</em> is invalid and therefore the entire rule is ignored (as invalid too).</p>\n<h2><a href=\"https://webdevhub.us/docs/css/#css_statements\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_statements\" title=\"Permalink to CSS statements\">CSS statements</a></h2>\n<p>Rulesets are the main building blocks of a style sheet, which often consists of only a big list of them. But there is other information that a Web author wants to convey in the style sheet, like the character set, other external style sheets to import, font face or list counter descriptions and many more. It will use other and specific kinds of statements to do that.</p>\n<p>A statement is a building block that begins with any non-space characters and ends at the first closing brace or semi-colon (outside a string, non-escaped and not included into another {}, () or [] pair).</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/css_syntax_-_statements_venn_diag.png\" alt=\"css syntax - statements Venn diag.png\"></p>\n<p>There are two kinds of statements:</p>\n<ul>\n<li>Rulesets (or <em>rules</em>) that, as seen, associate a collection of CSS declarations to a condition described by a <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors\">selector</a>.</li>\n<li>At-rules that start with an at sign, '<code class=\"language-text\">@</code>' (<code class=\"language-text\">U+0040 COMMERCIAL AT</code>), followed by an identifier and then continuing up to the end of the statement, that is up to the next semi-colon (;) outside of a block, or the end of the next block. Each type of <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule\">at-rules</a>, defined by the identifier, may have its own internal syntax, and semantics of course. They are used to convey meta-data information (like <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@charset\"><code class=\"language-text\">@charset</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@import\"><code class=\"language-text\">@import</code></a>), conditional information (like <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@media\"><code class=\"language-text\">@media</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@document\"><code class=\"language-text\">@document</code></a>), or descriptive information (like <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face\"><code class=\"language-text\">@font-face</code></a>).</li>\n</ul>\n<p>Any statement which isn't a ruleset or an at-rule is invalid and ignored.</p>\n<h3><a href=\"https://webdevhub.us/docs/css/#nested_statements\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#nested_statements\" title=\"Permalink to Nested statements\">Nested statements</a></h3>\n<p>There is another group of statements -- the nested statements. These are statements that can be used in a specific subset of at-rules -- the <em>conditional group rules</em>. These statements only apply if a specific condition is matched: the <code class=\"language-text\">@media</code> at-rule content is applied only if the device on which the browser runs matches the expressed condition; the <code class=\"language-text\">@document</code> at-rule content is applied only if the current page matches some conditions, and so on. In CSS1 and CSS2.1, only <em>rulesets</em> could be used inside conditional group rules. That was very restrictive and this restriction was lifted in <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS3#Conditionals\" title=\"This is a link to an unwritten page\"><em>CSS Conditionals Level 3</em></a>. Now, though still experimental and not supported by every browser, conditional group rules can contain a wider range of content: rulesets but also some, but not all, at-rules.\nCSS </p>"},{"url":"/docs/docs/accessability/","relativePath":"docs/docs/accessability.md","relativeDir":"docs/docs","base":"accessability.md","name":"accessability","frontmatter":{"title":"Learn  Accessibility","weight":0,"excerpt":"Learn  Accessibility","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<iframe src=\"https://codesandbox.io/embed/htmlstandard-forked-p559i8?autoresize=1&fontsize=14&hidenavigation=1&theme=dark&view=preview\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"htmlstandard (forked)\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   ></iframe>"},{"url":"/docs/docs/appendix/","relativePath":"docs/docs/appendix.md","relativeDir":"docs/docs","base":"appendix.md","name":"appendix","frontmatter":{"title":"Apendix","weight":0,"excerpt":"resources","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>index</h1>\n<p>This appendix is a non-exhaustive list of new syntactic features and methods that were added to JavaScript in ES6. These features are the most commonly used and most helpful.</p>\n<p>While this appendix doesn't cover ES6 classes, we go over the basics while learning about components in the book. In addition, this appendix doesn't include descriptions of some larger new features like promises and generators. If you'd like more info on those or on any topic below, we encourage you to reference the <a href=\"https://developer.mozilla.org/\">Mozilla Developer Network's website</a> (MDN).</p>\n<h2>Prefer <code class=\"language-text\">const</code> and <code class=\"language-text\">let</code> over <code class=\"language-text\">var</code></h2>\n<p>If you've worked with ES5 JavaScript before, you're likely used to seeing variables declared with <code class=\"language-text\">var</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ar myVariable = 5;</code></pre></div>\n<p>Both the <code class=\"language-text\">const</code> and <code class=\"language-text\">let</code> statements also declare variables. They were introduced in ES6.</p>\n<p>Use <code class=\"language-text\">const</code> in cases where a variable is never re-assigned. Using <code class=\"language-text\">const</code> makes this clear to whoever is reading your code. It refers to the \"constant\" state of the variable in the context it is defined within.</p>\n<p>If the variable will be re-assigned, use <code class=\"language-text\">let</code>.</p>\n<p>We encourage the use of <code class=\"language-text\">const</code> and <code class=\"language-text\">let</code> instead of <code class=\"language-text\">var</code>. In addition to the restriction introduced by <code class=\"language-text\">const</code>, both <code class=\"language-text\">const</code> and <code class=\"language-text\">let</code> are <em>block scoped</em> as opposed to <em>function scoped</em>. This scoping can help avoid unexpected bugs.</p>\n<h2>Arrow functions</h2>\n<p>There are three ways to write arrow function bodies. For the examples below, let's say we have an array of city objects:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">onst cities = [\n  { name: 'Cairo', pop: 7764700 },\n  { name: 'Lagos', pop: 8029200 },\n];</code></pre></div>\n<p>If we write an arrow function that spans multiple lines, we must use braces to delimit the function body like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const formattedPopulations = cities.map((city) => {\n  const popMM = (city.pop / 1000000).toFixed(2);\n  return popMM + ' million';\n});\nconsole.log(formattedPopulations);</code></pre></div>\n<p>Note that we must also explicitly specify a <code class=\"language-text\">return</code> for the function.</p>\n<p>However, if we write a function body that is only a single line (or single expression) we can use parentheses to delimit it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const formattedPopulations2 = cities.map((city) => (\n  (city.pop / 1000000).toFixed(2) + ' million'\n));</code></pre></div>\n<p>Notably, we don't use <code class=\"language-text\">return</code> as it's implied.</p>\n<p>Furthermore, if your function body is terse you can write it like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const pops = cities.map(city => city.pop);\nconsole.log(pops);</code></pre></div>\n<p>The terseness of arrow functions is one of two reasons that we use them. Compare the one-liner above to this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const popsNoArrow = cities.map(function(city) { return city.pop });</code></pre></div>\n<p>Of greater benefit, though, is how arrow functions bind the <code class=\"language-text\">this</code> object.</p>\n<p>The traditional JavaScript function declaration syntax (<code class=\"language-text\">function () {}</code>) will bind <code class=\"language-text\">this</code> in anonymous functions to the global object. To illustrate the confusion this causes, consider the following example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">unction printSong() {\n  console.log(\"Oops - The Global Object\");\n}\n\nconst jukebox = {\n  songs: [\n    {\n      title: \"Wanna Be Startin' Somethin'\",\n      artist: \"Michael Jackson\",\n    },\n    {\n      title: \"Superstar\",\n      artist: \"Madonna\",\n    },\n  ],\n  printSong: function (song) {\n    console.log(song.title + \" - \" + song.artist);\n  },\n  printSongs: function () {\n\n    this.songs.forEach(function(song) {\n\n      this.printSong(song);\n    });\n  },\n}\n\njukebox.printSongs();</code></pre></div>\n<p>The method <code class=\"language-text\">printSongs()</code> iterates over <code class=\"language-text\">this.songs</code> with <code class=\"language-text\">forEach()</code>. In this context, <code class=\"language-text\">this</code> is bound to the object (<code class=\"language-text\">jukebox</code>) as expected. However, the anonymous function passed to <code class=\"language-text\">forEach()</code> binds its internal <code class=\"language-text\">this</code> to the global object. As such, <code class=\"language-text\">this.printSong(song)</code> calls the function declared at the top of the example, <em>not</em> the method on <code class=\"language-text\">jukebox</code>.</p>\n<p>JavaScript developers have traditionally used workarounds for this behavior, but arrow functions solve the problem by <strong>capturing the <code class=\"language-text\">this</code> value of the enclosing context</strong>. Using an arrow function for <code class=\"language-text\">printSongs()</code> has the expected result:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  printSongs: function () {\n    this.songs.forEach((song) => {\n\n      this.printSong(song);\n    });\n  },\n}\n\njukebox.printSongs();</code></pre></div>\n<p>For this reason, throughout the book we use arrow functions for all anonymous functions.</p>\n<h2>Modules</h2>\n<p>ES6 formally supports modules using the <code class=\"language-text\">import</code>/<code class=\"language-text\">export</code> syntax.</p>\n<p><strong>Named exports</strong></p>\n<p>Inside any file, you can use <code class=\"language-text\">export</code> to specify a variable the module should expose. Here's an example of a file that exports two functions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export const sayHi = () => (console.log('Hi!'));\nexport const sayBye = () => (console.log('Bye!'));\n\nconst saySomething = () => (console.log('Something!'));</code></pre></div>\n<p>Now, anywhere we wanted to use these functions we could use <code class=\"language-text\">import</code>. We need to specify which functions we want to import. A common way of doing this is using ES6's destructuring assignment syntax to list them out like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { sayHi, sayBye } from './greetings';\n\nsayHi();\nsayBye();</code></pre></div>\n<p>Importantly, the function that was <em>not</em> exported (<code class=\"language-text\">saySomething</code>) is unavailable outside of the module.</p>\n<p>Also note that we supply a <strong>relative path</strong> to <code class=\"language-text\">from</code>, indicating that the ES6 module is a local file as opposed to an npm package.</p>\n<p>Instead of inserting an <code class=\"language-text\">export</code> before each variable you'd like to export, you can use this syntax to list off all the exposed variables in one area:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const sayHi = () => (console.log('Hi!'));\nconst sayBye = () => (console.log('Bye!'));\n\nconst saySomething = () => (console.log('Something!'));\n\nexport { sayHi, sayBye };</code></pre></div>\n<p>We can also specify that we'd like to import all of a module's functionality underneath a given namespace with the <code class=\"language-text\">import * as &lt;Namespace></code> syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import * as Greetings from './greetings';\n\nGreetings.sayHi();\n\nGreetings.sayBye();\n\nGreetings.saySomething();</code></pre></div>\n<p><strong>Default export</strong></p>\n<p>The other type of export is a default export. A module can only contain one default export:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const sayHi = () => (console.log('Hi!'));\nconst sayBye = () => (console.log('Bye!'));\n\nconst saySomething = () => (console.log('Something!'));\n\nconst Greetings = { sayHi, sayBye };\n\nexport default Greetings;</code></pre></div>\n<p>This is a common pattern for libraries. It means you can easily import the library wholesale without specifying what individual functions you want:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import Greetings from './greetings';\n\nGreetings.sayHi();\nGreetings.sayBye();</code></pre></div>\n<p>It's not uncommon for a module to use a mix of both named exports and default exports. For instance, with <code class=\"language-text\">react-dom</code>, you can import <code class=\"language-text\">ReactDOM</code> (a default export) like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import ReactDOM from 'react-dom';\n\nReactDOM.render(\n\n);</code></pre></div>\n<p>Or, if you're only going to use the <code class=\"language-text\">render()</code> function, you can import the named <code class=\"language-text\">render()</code> function like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { render } from 'react-dom';\n\nrender(\n\n);</code></pre></div>\n<p>To achieve this flexibility, the export implementation for <code class=\"language-text\">react-dom</code> looks something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export const render = (component, target) => {\n\n};\n\nconst ReactDOM = {\n  render,\n\n};\n\nexport default ReactDOM;</code></pre></div>\n<p>If you want to play around with the module syntax, check out the folder <code class=\"language-text\">code/webpack/es6-modules</code>.</p>\n<p>For more reading on ES6 modules, see this article from Mozilla: \"<a href=\"https://hacks.mozilla.org/2015/08/es6-in-depth-modules/\">ES6 in Depth: Modules</a>\".</p>\n<h2><code class=\"language-text\">Object.assign()</code></h2>\n<p>We use <code class=\"language-text\">Object.assign()</code> often throughout the book. We use it in areas where we want to create a modified version of an existing object.</p>\n<p><code class=\"language-text\">Object.assign()</code> accepts any number of objects as arguments. When the function receives two arguments, it <em>copies</em> the properties of the second object onto the first, like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">onst coffee = { };\nconst noCream = { cream: false };\nconst noMilk = { milk: false };\nObject.assign(coffee, noCream);</code></pre></div>\n<p>It is idiomatic to pass in three arguments to <code class=\"language-text\">Object.assign()</code>. The first argument is a new JavaScript object, the one that <code class=\"language-text\">Object.assign()</code> will ultimately return. The second is the object whose properties we'd like to build off of. The last is the changes we'd like to apply:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const coffeeWithMilk = Object.assign({}, coffee, { milk: true });</code></pre></div>\n<p><code class=\"language-text\">Object.assign()</code> is a handy method for working with \"immutable\" JavaScript objects.</p>\n<h2>Template literals</h2>\n<p>In ES5 JavaScript, you'd interpolate variables into strings like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var greeting = 'Hello, ' + user + '! It is ' + degF + ' degrees outside.';</code></pre></div>\n<p>With ES6 template literals, we can create the same string like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const greeting = `Hello, ${user}! It is ${degF} degrees outside.`;</code></pre></div>\n<h2>The spread operator (<code class=\"language-text\">...</code>)</h2>\n<p>In arrays, the ellipsis <code class=\"language-text\">...</code> operator will <em>expand</em> the array that follows into the parent array. The spread operator enables us to succinctly construct new arrays as a composite of existing arrays.</p>\n<p>Here is an example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">onst a = [ 1, 2, 3 ];\nconst b = [ 4, 5, 6 ];\nconst c = [ ...a, ...b, 7, 8, 9 ];\n\nconsole.log(c);</code></pre></div>\n<p>Notice how this is different than if we wrote:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const d = [ a, b, 7, 8, 9 ];\nconsole.log(d);</code></pre></div>\n<h2>Enhanced object literals</h2>\n<p>In ES5, all objects were required to have explicit key and value declarations:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const explicit = {\n  getState: getState,\n  dispatch: dispatch,\n};</code></pre></div>\n<p>In ES6, you can use this terser syntax whenever the property name and variable name are the same:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const implicit = {\n  getState,\n  dispatch,\n};</code></pre></div>\n<p>Lots of open source libraries use this syntax, so it's good to be familiar with it. But whether you use it in your own code is a matter of stylistic preference.</p>\n<h2>Default arguments</h2>\n<p>With ES6, you can specify a default value for an argument in the case that it is <code class=\"language-text\">undefined</code> when the function is called.</p>\n<p>This:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">unction divide(a, b) {\n\n  const divisor = typeof b === 'undefined' ? 1 : b;\n\n  return a / divisor;\n}</code></pre></div>\n<p>Can be written as this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function divide(a, b = 1) {\n  return a / b;\n}</code></pre></div>\n<p>In both cases, using the function looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">divide(14, 2);\n\ndivide(14, undefined);\n\ndivide(14);</code></pre></div>\n<p>Whenever the argument <code class=\"language-text\">b</code> in the example above is <code class=\"language-text\">undefined</code>, the default argument is used. Note that <code class=\"language-text\">null</code> will not use the default argument:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">divide(14, null);</code></pre></div>\n<h2>Destructuring assignments</h2>\n<h3>For arrays</h3>\n<p>In ES5, extracting and assigning multiple elements from an array looked like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ar fruits = [ 'apples', 'bananas', 'oranges' ];\nvar fruit1 = fruits[0];\nvar fruit2 = fruits[1];</code></pre></div>\n<p>In ES6, we can use the destructuring syntax to accomplish the same task like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const [ veg1, veg2 ] = [ 'asparagus', 'broccoli', 'onion' ];\nconsole.log(veg1);\nconsole.log(veg2);</code></pre></div>\n<p>The variables in the array on the left are \"matched\" and assigned to the corresponding elements in the array on the right. Note that <code class=\"language-text\">'onion'</code> is ignored and has no variable bound to it.</p>\n<h3>For objects</h3>\n<p>We can do something similar for extracting object properties into variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const smoothie = {\n  fats: [ 'avocado', 'peanut butter', 'greek yogurt' ],\n  liquids: [ 'almond milk' ],\n  greens: [ 'spinach' ],\n  fruits: [ 'blueberry', 'banana' ],\n};\n\nconst { liquids, fruits } = smoothie;\n\nconsole.log(liquids);\nconsole.log(fruits);</code></pre></div>\n<h3>Parameter context matching</h3>\n<p>We can use these same principles to bind arguments inside a function to properties of an object supplied as an argument:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const containsSpinach = ({ greens }) => {\n  if (greens.find(g => g === 'spinach')) {\n    return true;\n  } else {\n    return false;\n  }\n};\n\ncontainsSpinach(smoothie);</code></pre></div>\n<p>We do this often with functional React components:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const IngredientList = ({ ingredients, onClick }) => (\n  &lt;ul className='IngredientList'>\n    {\n      ingredients.map(i => (\n        &lt;li\n          key={i.id}\n          onClick={() => onClick(i.id)}\n          className='item'\n        >\n          {i.name}\n        &lt;/li>\n      ))\n    }\n  &lt;/ul>\n)</code></pre></div>\n<p>Here, we use destructuring to extract the props into variables (<code class=\"language-text\">ingredients</code> and <code class=\"language-text\">onClick</code>) that we then use inside the component's function body.</p>"},{"url":"/docs/docs/archive/","relativePath":"docs/docs/archive.md","relativeDir":"docs/docs","base":"archive.md","name":"archive","frontmatter":{"title":"Archive","weight":0,"excerpt":"more tools that I have created or collaborated on.","seo":{"title":"","description":"embeded developer tools and utilities","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<br>\n<br>\n<br>\n<h1>     Resource Archive           </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://resourcerepo2.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Google Drive</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://drive.google.com/embeddedfolderview?id=1DHyQsPLziqSUODclplhnNX1eknzbZrL8#list\" style=\"width:100%; height:600px; border:0;\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>    Internet Archive        </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://archive.org/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Lambda Student Site </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://lambda-resources.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Bass Station CSS Showcase</h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://bgoonz.github.io/bass-station/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Interview     </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://web-dev-interview-prep-quiz-website.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Speach Recognition api </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe  class=\"<iframe \" src=\"https://random-static-html-deploys.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  The Algos Bgoonz Branch </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe  class=\"<iframe \" src=\"https://thealgorithms.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>Markdown Templates</h1>\n<br>\n<br>\n<br>\n<br>\n<iframe  class=\"<iframe \" src=\"https://markdown-templates-42.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>CURL</h1>\n<br>\n<br>\n<br>\n<br>\n<iframe  class=\"<iframe \" src=\"https://bgoonz.github.io/everything-curl/index.html\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Text Tools     </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://devtools42.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Ternary Converter   </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://ternary42.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Github HTML Render from link </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://githtmlpreview.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Form Builder GUI </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://fourm-builder-gui.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Border Builder </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://codepen.io/bgoonz/embed/zYwLVmb?default-tab=html%2Cresult\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h2>Archives</h2>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Original Blog Site </h1>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://web-dev-resource-hub.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" frameborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\"   clipboard-write;   allowfullscreen>\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/docs/glossary/","relativePath":"docs/docs/glossary.md","relativeDir":"docs/docs","base":"glossary.md","name":"glossary","frontmatter":{"title":"Glossary","weight":0,"excerpt":"Glossary","seo":{"title":"glossary","description":"a","robots":[],"extra":[]},"template":"docs"},"html":"<h3><a href=\"https://gist.github.com/bgoonz/c7fe5f303392e1049f24f91be9cb9d02\">WEB DEVELOPMENT GLOSSARY</a></h3>"},{"url":"/docs/docs/css/","relativePath":"docs/docs/css.md","relativeDir":"docs/docs","base":"css.md","name":"css","frontmatter":{"title":"Learn Css","weight":0,"excerpt":"Learn Css","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Learn CSS</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://onedrive.live.com/embed?cid=D21009FDD967A241&amp;resid=D21009FDD967A241%21634693&amp;authkey=AAQrdzlmcaPgMGA&amp;em=2&amp;wdAr=1.7777777777777777\" width=\"1186px\" height=\"691px\" frameborder=\"0\">This is an embedded <a target=\"_blank\" href=\"https://office.com\">Microsoft Office</a> presentation, powered by <a target=\"_blank\" href=\"https://office.com/webapps\">Office</a>.</iframe>\n<br>\n<p>CSS Selectors</p>\n<hr>\n<h3>Learn CSS So That Your Site Doesn't Look Like Garbage</h3>\n<h3>CSS Selectors</h3>\n<ul>\n<li><span id=\"62c3\"><code class=\"language-text\">CSS Selector</code> : Applies styles to a specific DOM element(s), there are various types:</span></li>\n<li><span id=\"d60d\"><code class=\"language-text\">Type Selectors</code> : Matches by node name.</span></li>\n<li><span id=\"9826\"><code class=\"language-text\">Class Selectors</code> : Matches by class name.</span></li>\n<li><span id=\"10a7\"><code class=\"language-text\">ID Selectors</code> : Matches by ID name.</span></li>\n<li><span id=\"64c0\"><code class=\"language-text\">Universal Selectors</code> : Selects all HTML elements on a page.</span></li>\n<li><span id=\"9c6b\"><code class=\"language-text\">Attribute Selectors</code> : Matches elements based on the prescence or value of a given attribute. (i.e. a[title] will match all a elements with a title attribute)</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/* Type selector */\ndiv {\n  background-color: #000000;\n}/* Class selector */\n.active {\n  color: #ffffff;\n}/* ID selector */\n#list-1 {\n  border: 1px solid gray;\n}/* Universal selector */\n* {\n  padding: 10px;\n}/* Attribute selector */\na[title] {\n  font-size: 2em;\n}</code></pre></div>\n<p><strong>Class Selectors</strong></p>\n<ul>\n<li><span id=\"fddf\">Used to select all elements of a certain class denoted with a <code class=\"language-text\">.[class name]</code></span></li>\n<li><span id=\"72af\">You can assign multiple classes to a DOM element by separating them with a space.</span></li>\n</ul>\n<p><strong>Compound Class Selectors</strong></p>\n<ul>\n<li><span id=\"befd\">To get around accidentally selecting elements with multiple classes beyond what we want to grab we can chain dots.</span></li>\n<li><span id=\"e2c8\">TO use a compound class selector just append the classes together when referencing them in the CSS.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"box yellow\"></code></pre></div>\n</div>\n    <div class=\"box orange\">\n</div>\n    <div class=\"circle orange\">\n</div>\n<ul>\n<li><span id=\"7dd3\">i.e. .box.yellow will select only the first element.</span></li>\n<li><span id=\"8904\">KEEP IN MIND that if you do include a space it will make the selector into a <em>descendant selector</em>.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">h1#heading,\nh2.subheading {\n  font-style: italic;\n}</code></pre></div>\n<ul>\n<li><span id=\"a8bc\">When we want to target all <code class=\"language-text\">h1</code> tags with the id of <code class=\"language-text\">heading</code>.</span></li>\n</ul>\n<p><strong>CSS Combinators</strong></p>\n<ul>\n<li><span id=\"c196\">CSS Combinators are used to combine other selectors into more complex or targeted selectors — they are very powerful!</span></li>\n<li><span id=\"71a6\">Be careful not to use too many of them as they will make your CSS far too complex.</span></li>\n<li><span id=\"6032\"><code class=\"language-text\">Descendant Selectors</code></span></li>\n<li><span id=\"6f41\">Separated by a space.</span></li>\n<li><span id=\"3829\">Selects all descendants of a parent container.</span></li>\n<li><span id=\"e90c\"><code class=\"language-text\">Direct Child Selectors</code></span></li>\n<li><span id=\"52b5\">Indicated with a <code class=\"language-text\">></code>.</span></li>\n<li><span id=\"ea8e\">Different from descendants because it only affects the direct children of an element.</span></li>\n<li><span id=\"486f\"><code class=\"language-text\">.menu > .is-active { background-color: #ffe0b2; }</code></span></li>\n<li><span id=\"96f9\"><code class=\"language-text\">&lt;body> &lt;div class=\"menu\"> &lt;div class=\"is-active\">Belka&lt;/div> &lt;div> &lt;div class=\"is-active\">Strelka&lt;/div> &lt;/div> &lt;/div> &lt;/body> &lt;div class=\"is-active\"> Laika &lt;/div> &lt;/body></code></span></li>\n<li><span id=\"59ca\">Belka would be the only element selected.</span></li>\n<li><span id=\"0266\"><code class=\"language-text\">Adjacent Sibling Selectors</code></span></li>\n<li><span id=\"a648\">Uses the <code class=\"language-text\">+</code> symbol.</span></li>\n<li><span id=\"9d79\">Used for elements that directly follow one another and who both have the same parent.</span></li>\n<li><span id=\"4865\"><code class=\"language-text\">h1 + h2 { font-style: italic; } &lt;h1>Big header&lt;/h1> &lt;h2>This one is styled because it is directly adjacent to the H1&lt;/h2> &lt;h2>This one is NOT styled because there is no H1 right before it&lt;/h2></code></span></li>\n</ul>\n<p><strong>Pseudo-Classes</strong></p>\n<ul>\n<li><span id=\"b638\"><code class=\"language-text\">Pseudo-Class</code> : Specifies a special state of the seleted element(s) and does not refer to any elements or attributes contained in the DOM.</span></li>\n<li><span id=\"0360\">Format is a <code class=\"language-text\">Selector:Pseudo-Class Name</code> or <code class=\"language-text\">A:B</code></span></li>\n<li><span id=\"91ee\"><code class=\"language-text\">a:hover { font-family: \"Roboto Condensed\", sans-serif; color: #4fc3f7; text-decoration: none; border-bottom: 2px solid #4fc3f7; }</code></span></li>\n<li><span id=\"27ac\">Some common pseudo-classes that are frequently used are:</span></li>\n<li><span id=\"9b2b\"><code class=\"language-text\">active</code> : 'push down', when ele are activated.</span></li>\n<li><span id=\"5b2f\"><code class=\"language-text\">checked</code> : applies to things like radio buttons or checkbox inputs.</span></li>\n<li><span id=\"58da\"><code class=\"language-text\">disabled</code> : any disabled element.</span></li>\n<li><span id=\"d3bd\"><code class=\"language-text\">first-child</code> : first element in a group of children/siblings.</span></li>\n<li><span id=\"40fc\"><code class=\"language-text\">focus</code> : elements that have current focus.</span></li>\n<li><span id=\"ed43\"><code class=\"language-text\">hover</code> : elements that have cursor hovering over it.</span></li>\n<li><span id=\"6fa2\"><code class=\"language-text\">invalid</code> : any form elements in an invalid state from client-side form validation.</span></li>\n<li><span id=\"7811\"><code class=\"language-text\">last-child</code> : last element in a group of children/siblings.</span></li>\n<li><span id=\"1bdf\"><code class=\"language-text\">not(selector)</code> : elements that do not match the provided selector.</span></li>\n<li><span id=\"be5c\"><code class=\"language-text\">required</code> : form elements that are required.</span></li>\n<li><span id=\"43ed\"><code class=\"language-text\">valid</code> : form elements in a valid state.</span></li>\n<li><span id=\"6460\"><code class=\"language-text\">visited</code> : anchor tags of whih the user has already been to the URL that the href points to.</span></li>\n</ul>\n<p><code class=\"language-text\">Pseudo-Selectors</code></p>\n<ul>\n<li><span id=\"89e7\">Used to create pseudo-elements as children of the elements to which the property applies.</span></li>\n<li><span id=\"0bef\"><code class=\"language-text\">::after</code></span></li>\n<li><span id=\"52f9\"><code class=\"language-text\">::before</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;style>\n  p::before {\n    background-color: lightblue;\n    border-right: 4px solid violet;\n    content: \":-) \";\n    margin-right: 4px;\n    padding-left: 4px;\n  }\n&lt;/style>\n&lt;p>This is the first paragraph&lt;/p>\n&lt;p>This is the second paragraph&lt;/p>\n&lt;p>This is the third paragraph&lt;/p></code></pre></div>\n<ul>\n<li><span id=\"a843\">Will add some blue smiley faces before the p tag elements.</span></li>\n</ul>\n<p><strong>CSS Rules</strong></p>\n<ul>\n<li><span id=\"919a\"><code class=\"language-text\">CSS Rule</code> : Collection of single or compound selectors, a curly brace, zero or more properties</span></li>\n<li><span id=\"555f\"><code class=\"language-text\">CSS Rule Specificity</code> : Sometimes CSS rules will contain multiple elements and may have overlapping properties rules for those same elements - there is an algorithm in CSS that calculates which rule takes precedence.</span></li>\n<li><span id=\"a1db\"><code class=\"language-text\">The Four Number Calculation</code> : listed in increasing order of importance.</span></li>\n</ul>\n<p>Who has the most IDs? If no one, continue.</p>\n<p>Who has the most classes? If no one, continue.</p>\n<p>Who has the most tags? If no one, continue.</p>\n<p>Last Read in the browser wins.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Ub47AaMXuT1m8_T-\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*t0oXzsLPxpMwNbKo.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*2xr0vyHwf6UN905l\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*oq83hQ5qvtT6gDd9.png\" class=\"graf-image\" />\n</figure>\n<style>\n      .box {\n        width: 50px;\n        height: 50px;\n        border: 1px solid black;\n      }\n      .orange {\n        background-color: orange;\n      }\n      .yellow {\n        background-color: yellow;\n        border: 1px solid purple;\n      }\n    </style>\n    <div class=\"box yellow\">\n</div>\n    <div class=\"box orange\">\n</div>\n<ul>\n<li><span id=\"1939\">Coming back to our example where all the CSS Rules have tied, the last step 4 wins out so our element will have a <code class=\"language-text\">purple border</code>.</span></li>\n</ul>\n<hr>\n<h3>CSS: Type, Properties, and Imports</h3>\n<p><strong>Typography</strong></p>\n<ul>\n<li><span id=\"d6fc\"><code class=\"language-text\">font-family</code> : change the font.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ssVcT1Bd9Edfo6KF\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*WmqUyKiumM8RCJQo.png\" class=\"graf-image\" />\n</figure>- <span id=\"daba\">Remember that not all computers have the same fonts on them.</span>\n- <span id=\"0aa8\">You can import web fonts via an api by using</span>\n- <span id=\"0c5d\">`@import url('https://fonts.googleapis.com/css2?family=Liu+Jian+Mao+Cao&display=swap');` and pasting it st the top of your CSS file.</span>\n- <span id=\"d8ff\">And then reference it in your font-family.</span>\n- <span id=\"ee9f\">`font-size` : Changes the size of your font.</span>\n- <span id=\"782e\">Keep in mind the two kind of units CSS uses:</span>\n- <span id=\"c4f7\">`Absolute` : `Pixels`, Points, Inches, Centimeters.</span>\n- <span id=\"2884\">`Relative` : Em, Rem.</span>\n- <span id=\"f9b5\">Em: Calulating the size relative to the previous div (bubbles down)</span>\n- <span id=\"5a5d\">Rem: Calulates relative to the parent element always.</span>\n- <span id=\"79b0\">`font-style` : Used to set a font to italics.</span>\n- <span id=\"f464\">`font-weight` : Used to make a font bold.</span>\n- <span id=\"3d56\">`text-align` : Used to align your text to the left, center, or right.</span>\n- <span id=\"4cbc\">`text-decoration` : Use to put lines above, through, or under text. Lines can be solid, dashed, or wavy!</span>\n- <span id=\"1c96\">`text-transform` : Used to set text to all lowercase, uppercase, or capitalize all words.</span>\n<p><strong>Background-Images</strong></p>\n<ul>\n<li><span id=\"13eb\">You can use the background-image property to set a background image for an element.</span></li>\n</ul>\n<hr>\n<h3>CSS: Colors, Borders, and Shadows</h3>\n<p><strong>Colors</strong></p>\n<ul>\n<li><span id=\"6bed\">You can set colors in CSS in three popular ways: by name, by hexadecimal RGB value, and by their decimal RGB value.</span></li>\n<li><span id=\"38fb\">rgba() is used to make an rbg value more transparent, the <code class=\"language-text\">a</code> is used to specify the <code class=\"language-text\">alpha channel</code>.</span></li>\n<li><span id=\"cb05\"><strong>Color</strong> : Property used to change the color of text.</span></li>\n<li><span id=\"6f05\"><strong>Background-Color</strong> : Property to change the backgrounf color of an element.</span></li>\n</ul>\n<p><strong>Borders</strong></p>\n<ul>\n<li><span id=\"d922\">Borders take three values: The width of the border, the style (i.e. solid, dotted, dashed), color of the border.</span></li>\n</ul>\n<p><strong>Shadows</strong></p>\n<ul>\n<li><span id=\"bccb\">There are two kinds of shadows in CSS: <code class=\"language-text\">box shadows</code> and <code class=\"language-text\">text shadows</code>.</span></li>\n<li><span id=\"7fd2\">Box refers to HTML elements.</span></li>\n<li><span id=\"f3a7\">Text refers to text.</span></li>\n<li><span id=\"2a53\">Shadows take values such as, the horizontal &#x26; vertical offsets of the shadow, the blur radius of the shadow, the spread radius, and of course the colors.</span></li>\n</ul>\n<hr>\n<h3>The Box Model</h3>\n<p><strong>Box Model</strong> : A concept that basically boils down that every DOM element has a box around it.</p>\n<p>Imagine a gift, inside is the gift, wrapped in foam all around (padding), and the giftbox outside of it (border) and then a wrapping paper on the giftbox (margin).- For items that are using <code class=\"language-text\">block</code> as it's display, the browser will follow these rules to layout the element: - The box fills 100% of the available container space. - Every new box takes on a new line/row. - Width and Height properties are respected. - Padding, Margin, and Border will push other elements away from the box. - Certain elements have <code class=\"language-text\">block</code> as their default display, such as: divs, headers, and paragraphs.- For items that are using <code class=\"language-text\">inline</code> as it's display, the browser will follow these rules to layout the element: - Each box appears in a single line until it fills up the space. - Width and height are <strong>not</strong> respected. - Padding, Margin, and Border are applied but they <strong>do not</strong> push other elements away from the box. - Certain elements have <code class=\"language-text\">inline</code> as their default display, such as: span tags, anchors, and images.</p>\n<p><strong>Standard Box Model vs Border-Box</strong>- As per the standard Box Model, the width and height pertains to the content of the box and excludes any additional padding, borders, and margins.</p>\n<p>This bothered many programmers so they created the <strong>border box</strong> to include the calculation of the entire box's height and width.</p>\n<p><strong>Inline-Block</strong>- Inline-block uses the best features of both <code class=\"language-text\">block</code> and <code class=\"language-text\">inline</code>. - Elements still get laid out left to right. - Layout takes into account specified width and height.</p>\n<p><strong>Padding</strong>- Padding applies padding to every side of a box. It is shorthand for four padding properties in this order: <code class=\"language-text\">padding-top</code>, <code class=\"language-text\">padding-right</code>, <code class=\"language-text\">padding-bottom</code>, <code class=\"language-text\">padding-left</code> (clockwise!)</p>\n<p><strong>Border</strong>- Border applies a border on all sides of an element. It takes three values in this order: <code class=\"language-text\">border-width</code>, <code class=\"language-text\">border-style</code>, <code class=\"language-text\">border-color</code>. - All three properties can be broken down in the four sides clockwise: top, right, bottom, left.</p>\n<p><strong>Margin</strong>- Margin sets margins on every side of an element. It takes four values in this order: <code class=\"language-text\">margin-top</code>, <code class=\"language-text\">margin-right</code>, <code class=\"language-text\">margin-bottom</code>, <code class=\"language-text\">margin-left</code>. - You can use <code class=\"language-text\">margin: 0 auto</code> to center an element.</p>\n<h3>Positioning</h3>\n<ul>\n<li><span id=\"d380\">The <code class=\"language-text\">position</code> property allows us to set the position of elements on a page and is an integral part of creatnig a Web page layout.</span></li>\n<li><span id=\"1bd6\">It accepts five values: <code class=\"language-text\">static</code>, <code class=\"language-text\">relative</code>, <code class=\"language-text\">absolute</code>, <code class=\"language-text\">fixed</code>, <code class=\"language-text\">sticky</code>.</span></li>\n<li><span id=\"0b53\">Every property (minus <code class=\"language-text\">static</code>) is used with: <code class=\"language-text\">top</code>, <code class=\"language-text\">right</code>, <code class=\"language-text\">bottom</code>, and <code class=\"language-text\">left</code> to position an element on a page.</span></li>\n</ul>\n<p><strong>Static Positioning</strong></p>\n<ul>\n<li><span id=\"7aa9\">The default position value of page elements.</span></li>\n<li><span id=\"700a\">Most likely will not use static that much.</span></li>\n</ul>\n<p><strong>Relative Positioning</strong></p>\n<ul>\n<li><span id=\"adc3\">Remains in it's original position in the page flow.</span></li>\n<li><span id=\"9533\">It is positioned <em>RELATIVE</em> to the it's <em>ORIGINAL PLACE</em> on the page flow.</span></li>\n<li><span id=\"8c0b\">Creates a <strong>stacking context</strong> : overlapping elements whose order can be set by the z-index property.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#pink-box {\n  background-color: #ff69b4;\n  bottom: 0;\n  left: -20px;\n  position: relative;\n  right: 0;\n  top: 0;\n}</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*mMCUEQ94L4_zxwNc\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*TgjpfTmdczESRAfU.png\" class=\"graf-image\" />\n</figure>**Absolute Positioning**\n<ul>\n<li><span id=\"d597\">Absolute elements are removed from the normal page flow and other elements around it act like it's not there. (how we can easily achieve some layering)</span></li>\n<li><span id=\"eb5b\">Here are some examples to illustration absolute positioning:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.container {\n  background-color: #2b2d2f;\n  position: relative;\n}#pink-box {\n  position: absolute;\n  top: 60px;\n}</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Mu1E5D10RQaBpzms\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*6jvV-NnX5HS5PuVT.png\" class=\"graf-image\" />\n</figure>- <span id=\"adb4\">Note that the container ele has a relative positioning — this is so that any changes made to the absolute positioned children will be positioned from it's top-left corner.</span>\n- <span id=\"be4f\">Note that because we removed the pink from the normal page flow, the container has now shifted the blue box to where the pink box should have been — which is why it is now layered beneath the pink.</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.container {\n  background-color: #2b2d2f;\n  position: relative;\n}#pink-box {\n  position: absolute;\n  top: 60px;\n}#blue-box {\n  position: absolute;\n}</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*phWx-191VVQ5pRF9\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*o_T8meZgQSu7kxfs.png\" class=\"graf-image\" />\n</figure>- <span id=\"9e42\">As you can see here, since we have also taken the blue box out of the normal page flow by declaring it as absoutely positioned it now overlaps over the pink box.</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.container {\n  background-color: #2b2d2f;\n  position: relative;\n}#pink-box {\n  background-color: #ff69b4;\n  bottom: 60px;\n  position: absolute;\n}</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*HJbtARqC1qmeWTHS\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*rRNttTlXfnhqERYU.png\" class=\"graf-image\" />\n</figure>- <span id=\"528a\">Example where the absolute element has it's bottom property modified.</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.container {\n  background-color: #2b2d2f;\n}#pink-box {\n  background-color: #ff69b4;\n  bottom: 60px;\n  position: absolute;\n}</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*e7H6ImFUmcPGMaoa\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Al6ILt84EC0bhjnK.png\" class=\"graf-image\" />\n</figure>- <span id=\"f676\">If we removed the container's relative position. Our absolute unit would look for the nearest parent which would be the document itself.</span>\n<p><strong>Fixed Positioning</strong></p>\n<ul>\n<li><span id=\"fe31\">Another positioning that removes it's element from the page flow, and automatically positions it's parent as the HTML doc itself.</span></li>\n<li><span id=\"2388\">Fixed also uses top, right, bottom, and left.</span></li>\n<li><span id=\"3903\">Useful for things like nav bars or other features we want to keep visible as the user scrolls.</span></li>\n</ul>\n<p><strong>Sticky Positioning</strong></p>\n<ul>\n<li><span id=\"8ae2\">Remains in it's original position in the page flow, and it is positioned relative to it's closest block-level ancestor and any <em>scrolling</em> ancestors.</span></li>\n<li><span id=\"abe8\">Behaves like a relatively positioned element until the point at which you would normally scroll past it's viewport — then it sticks!</span></li>\n<li><span id=\"7ac0\">It is positioned with top, right, bottom, and left.</span></li>\n<li><span id=\"9080\">A good example are headers in a scrollable list.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*BRVlqobKK0IZtnXq\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*jQQJYWVoQY2eNANS.gif\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Flexible Box Model</h3>\n<ul>\n<li><span id=\"46aa\">Flexbox is a <strong>CSS module</strong> that provides a convenient way for us to display items inside a flexible container so that the layout is responsive.</span></li>\n<li><span id=\"ebb3\">Float was used back in the day to display position of elements in a container.</span></li>\n<li><span id=\"2a8e\">A very inconvenient aspect of float is the need to <em>clear</em> the float.</span></li>\n<li><span id=\"ba98\">To 'clear' a float we need to set up a ghost div to properly align — this is already sounds so inefficient.</span></li>\n</ul>\n<p><strong>Using Flexbox</strong></p>\n<ul>\n<li><span id=\"e23b\">Flexbox automatically resizes a container element to fit the viewport size without needing to use breakpoints.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*_SXOQpq3yrywWCcL\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*IBJIWQ7Z_23eERWn.png\" class=\"graf-image\" />\n</figure>- <span id=\"b505\">Flexbox layout applies styles to the parent element, and it's children.</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.container {\n  display: flex; /*sets display to use flex*/\n  flex-wrap: wrap; /*bc flex tries to fit everything into one line, use wrap to have the elements wrap to the next line*/\n  flex-direction: row; /*lets us create either rows or columns*/\n}</code></pre></div>\n<ul>\n<li><span id=\"4898\"><code class=\"language-text\">flex-flow</code> can be used to combine wrap and direction.</span></li>\n<li><span id=\"acdb\"><code class=\"language-text\">justify-content</code> used to define the alignment of flex items along the main axis.</span></li>\n<li><span id=\"68d6\"><code class=\"language-text\">align-items</code> used to define the alignment on the Y-axis.</span></li>\n<li><span id=\"f0d8\"><code class=\"language-text\">align-content</code> redistributes extra space on the cross axis.</span></li>\n<li><span id=\"531c\">By default, flex items will appear in the order they are added to the DOM, but we can use the <code class=\"language-text\">order</code> property to change that.</span></li>\n<li><span id=\"39b0\">Some other properties we can use on flex items are:</span></li>\n<li><span id=\"ec38\"><code class=\"language-text\">flex-grow</code> : dictates amount of avail. space the item should take up.</span></li>\n<li><span id=\"0916\"><code class=\"language-text\">flex-shrink</code> : defines the ability for a flex item to shrink.</span></li>\n<li><span id=\"4dda\"><code class=\"language-text\">flex-basis</code> : Default size of an element before the remaining space is distributed.</span></li>\n<li><span id=\"d9f2\"><code class=\"language-text\">flex</code> : shorthand for grow, shrink and basis.</span></li>\n<li><span id=\"f127\"><code class=\"language-text\">align-self</code> : Overrides default alignment in the container.</span></li>\n</ul>\n<hr>\n<h3>Grid Layout</h3>\n<ul>\n<li><span id=\"cc4f\">CSS Grid is a 2d layout system that let's use create a grid with columns and rows purely using Vanilla CSS. (flex is one dimensional)</span></li>\n</ul>\n<p><strong>Bootstrap vs CSS Grid</strong></p>\n<ul>\n<li><span id=\"4af2\">Bootstrap was a front-end library commonly used to create grid layouts but now CSS grid provides greater flexibility and control.</span></li>\n<li><span id=\"e404\">Grid applies style to a parent container and it's child elements.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.grid-container {\n  display: grid;\n  grid-template-columns: repeat(3, 1fr);\n  grid-template-rows: auto;\n  grid-template-areas:\n    \"header header header\"\n    \"main . sidebar\"\n    \"footer footer footer\";  grid-column-gap: 20px;\n  grid-row-gap: 30px;\n  justify-items: stretch;\n  align-items: stretch;\n  justify-content: stretch;\n  align-content: stretch;\n}.item-1 {\n  grid-area: header;\n}\n.item-2 {\n  grid-area: main;\n}\n.item-3 {\n  grid-area: sidebar;\n}\n.item-4 {\n  grid-area: footer;\n}</code></pre></div>\n<ul>\n<li><span id=\"26c3\">Columns and Rows can be defined with: pixels, percentages, auto, named grid lines, using <code class=\"language-text\">repeat</code>, fractions.</span></li>\n<li><span id=\"a117\"><code class=\"language-text\">Grid Template Areas</code> gives us a handy way to map out and visualize areas of the grid layout.</span></li>\n<li><span id=\"17ae\">Combine areas with templates to define how much space an area should take up.</span></li>\n<li><span id=\"f90a\"><code class=\"language-text\">Grid Gaps</code> can be used to create 'gutters' between grid item.s</span></li>\n<li><span id=\"d7c0\">The way we have defined our grid with <code class=\"language-text\">grid-templates</code> and <code class=\"language-text\">areas</code> are considered <strong>explicit</strong>.</span></li>\n<li><span id=\"cef6\">We can also <code class=\"language-text\">implicitly</code> define grids.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.grid-container {\n  display: grid;\n  grid-template-columns: 100px 100px 100px 100px;\n  grid-template-rows: 50px 50px 50px;\n  grid-auto-columns: 100px;\n  grid-auto-rows: 50px;\n}</code></pre></div>\n<ul>\n<li><span id=\"e6d3\">Any grid items that aren't explicity placed are automatically placed or <em>re-flowed</em></span></li>\n</ul>\n<p><strong>Spanning Columns &#x26; Rows</strong></p>\n<ul>\n<li><span id=\"98c8\">We can use the following properties to take up a specified num of cols and rows.</span></li>\n<li><span id=\"0208\"><code class=\"language-text\">grid-column-start</code></span></li>\n<li><span id=\"437a\"><code class=\"language-text\">grid-column-end</code></span></li>\n<li><span id=\"7d03\"><code class=\"language-text\">grid-row-start</code></span></li>\n<li><span id=\"0a8e\"><code class=\"language-text\">grid-row-end</code></span></li>\n<li><span id=\"c62b\">All four properties can take any of the following values: the line number, span #, span name, auto.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.item-1 {\n  grid-row-start: row2-start; /* Item starts at row line named \"row2-start\" */\n  grid-row-end: 5; /* Item ends at row line 5 */\n  grid-column-start: 1; /* Item starts at column line 1 */\n  grid-column-end: three; /* Item ends at column line named \"three\" */\n}.item-2 {\n  grid-row-start: 1; /* Item starts at row line 1 */\n  grid-row-end: span 2; /* Item spans two rows and ends at row line 3 */\n  grid-column-start: 3; /* Item starts at column line 3 */\n  grid-column-end: span col5-start; /* Item spans and ends at line named \"col5-start\" */\n}</code></pre></div>\n<p><strong>Grid Areas</strong></p>\n<ul>\n<li><span id=\"9dd0\">We use the grid areas in conjunction with grid-container property to <strong>define sections of the layout</strong>.</span></li>\n<li><span id=\"5ec2\">We can then assign named sections to individual element's css rules.</span></li>\n</ul>\n<p><strong>Justify &#x26; Align Self</strong></p>\n<ul>\n<li><span id=\"06b0\">Justify items and Align Items can be used to align all grid items at once.</span></li>\n<li><span id=\"53f5\"><strong>Justify Self</strong> is used to align self on the row.</span></li>\n<li><span id=\"f6b1\">It can take four values: start, end, center, stretch.</span></li>\n<li><span id=\"72bb\"><strong>Align Self</strong> is used to align self on the column.</span></li>\n<li><span id=\"d5d4\">It can take four values: start, end, center, stretch.</span></li>\n</ul>\n<hr>\n<p><strong>CSS Hover Effect and Handling</strong></p>\n<p><strong>Overflow</strong></p>\n<p><code class=\"language-text\">css .btn { background-color: #00bfff; color: #ffffff; border-radius: 10px; padding: 1.5rem; }</code></p>\n<p><code class=\"language-text\">.btn--active:hover { cursor: pointer; transform: translateY(-0.25rem);</code></p>\n<p><code class=\"language-text\">/* Moves our button up/down on the Y axis */ }</code></p>\n<p>The Pseudo Class Selector <code class=\"language-text\">hover</code> activates when the cursor goes over the selected element.</p>\n<p><strong>Content Overflow</strong>- You can apply an <code class=\"language-text\">overflow</code> content property to an element if it's inner contents are spilling over.</p>\n<p>There are three members in the overflow family: — <code class=\"language-text\">overflow-x</code> : Apply horizontally. - <code class=\"language-text\">overflow-y</code> : Apply vertically. - <code class=\"language-text\">overflow</code> : Apply both directions.</p>\n<h3>Transitions</h3>\n<ul>\n<li><span id=\"b5a7\">Transitions provide a way to control animation speed when changing CSS properties.</span></li>\n<li><span id=\"2e1b\"><strong>Implicit Transitions</strong> : Animations that involve transitioning between two states.</span></li>\n</ul>\n<p><strong>Defining Transitions</strong></p>\n<ul>\n<li><span id=\"bbd6\"><code class=\"language-text\">transition-property</code> : specifies the name of the CSS property to apply the transition.</span></li>\n<li><span id=\"6340\"><code class=\"language-text\">transition-duration</code> : during of the transition.</span></li>\n<li><span id=\"7463\"><code class=\"language-text\">transition-delay</code> : time before the transition should start.</span></li>\n</ul>\n<p><strong>Examples</strong> :</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#delay {\n  font-size: 14px;\n  transition-property: font-size;\n  transition-duration: 4s;\n  transition-delay: 2s;\n}#delay:hover {\n  font-size: 36px;\n}</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Z6AbWnbmbFfu-tSM\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*_6nSuCOR34-6ET7n.gif\" class=\"graf-image\" />\n</figure>- <span id=\"e6c9\">After a delay of two seconds, a four second transition begins where the font size goes from 36px to 14px.</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.box {\n  border-style: solid;\n  border-width: 1px;\n  display: block;\n  width: 100px;\n  height: 100px;\n  background-color: #0000ff;\n  transition: width 2s, height 2s, background-color 2s, transform 2s;\n}.box:hover {\n  background-color: #ffcccc;\n  width: 200px;\n  height: 200px;\n  transform: rotate(180deg);\n}</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*PH5_YmVDFVGqWGjO\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Ya7xiy0AqJaJ9RPq.gif\" class=\"graf-image\" />\n</figure>- <span id=\"c336\">When the mouse hovers over a box, it spins due to the rotate transform. Width and height change and also the bg color.</span>\n<hr>\n<h3>BEM Guidelines</h3>\n<ul>\n<li><span id=\"6474\">BEM was created as a guideline to solve the issue of loose standards around CSS naming conventions.</span></li>\n<li><span id=\"6d0c\"><strong>BEM</strong> stands for <code class=\"language-text\">block</code>, <code class=\"language-text\">element</code>, <code class=\"language-text\">modifier</code>.</span></li>\n<li><span id=\"3eb9\"><strong>Block</strong></span></li>\n<li><span id=\"f6b4\">A standalone entity that is meaningful on it's own.</span></li>\n<li><span id=\"7e86\">Can be nested and interact with one another.</span></li>\n<li><span id=\"338e\">Holistic entities without DOM rep can be blocks.</span></li>\n<li><span id=\"f2f0\">May consist latin letters, digits, and dashes.</span></li>\n<li><span id=\"3bfb\">Any DOM node can be a block if it accepts a class name.</span></li>\n<li><span id=\"5c9b\"><strong>Element</strong></span></li>\n<li><span id=\"1b95\">Part of a block and has no standalone meaning.</span></li>\n<li><span id=\"b5cf\">Any element that is semantically tied to a block.</span></li>\n<li><span id=\"10e2\">May consist latin letters, digits, and dashes.</span></li>\n<li><span id=\"9b79\">Formed by using two underscores after it's block name.</span></li>\n<li><span id=\"e282\">Any DOM node within a block can be an element.</span></li>\n<li><span id=\"a0dc\">Element classes should be used independently.</span></li>\n<li><span id=\"26f1\"><strong>Modifier</strong></span></li>\n<li><span id=\"6642\">A flag on blocks or elements. Use them to change appearance, behavior or state.</span></li>\n<li><span id=\"6cca\">Extra class name to add onto blocks or elements.</span></li>\n<li><span id=\"745f\">Add mods only to the elements they modify.</span></li>\n<li><span id=\"6416\">Modifier names may consist of Latin letters, digits, dashes and underscores.</span></li>\n<li><span id=\"f940\">Written with two dashes.</span></li>\n</ul>\n<p><strong>BEM Example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;form class=\"form form--theme-xmas form--simple\">\n  &lt;input class=\"form__input\" type=\"text\" />\n  &lt;input class=\"form__submit form__submit--disabled\" type=\"submit\" />\n&lt;/form>/* block selector */\n.form {\n}/* block modifier selector */\n.form--theme-xmas {\n}/* block modifier selector */\n.form--simple {\n}/* element selector */\n.form__input {\n}/* element selector */\n.form__submit {\n}/* element modifier selector */\n.form__submit--disabled {\n}</code></pre></div>\n<h4>If you found this guide helpful feel free to checkout my github/gists where I host similar content:</h4>\n<p><a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--p-anchor\">bgoonz's gists · GitHub</a></p>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>Or Checkout my personal Resource Site:</p>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\">\n<strong>a/A-Student-Resources</strong>\n<br />\n<em>Edit description</em>goofy-euclid-1cd736.netlify.app</a>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/938871b4521a\">March 6, 2021</a>.</p>"},{"url":"/docs/docs/git-reference/","relativePath":"docs/docs/git-reference.md","relativeDir":"docs/docs","base":"git-reference.md","name":"git-reference","frontmatter":{"title":"Git Reference","weight":0,"excerpt":"Git Reference","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Git Reference</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bgoonz.github.io/GIT_GUIDE_Bgoonz/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<p>Git is a distributed version control and source code management system.</p>\n<p>It does this through a series of snapshots of your project, and it works\nwith those snapshots to provide you with functionality to version and\nmanage your source code.</p>\n<h2>Versioning Concepts</h2>\n<h3>What is version control?</h3>\n<p>Version control is a system that records changes to a file(s), over time.</p>\n<h3>Centralized Versioning vs. Distributed Versioning</h3>\n<ul>\n<li>Centralized version control focuses on synchronizing, tracking, and backing</li>\n<li>up files.</li>\n<li>Distributed version control focuses on sharing changes. Every change has a\nunique id.</li>\n<li>Distributed systems have no defined structure. You could easily have a SVN\nstyle, centralized system, with git.</li>\n</ul>\n<p><a href=\"http://git-scm.com/book/en/Getting-Started-About-Version-Control\">Additional Information</a></p>\n<h3>Why Use Git?</h3>\n<ul>\n<li>Can work offline.</li>\n<li>Collaborating with others is easy!</li>\n<li>Branching is easy!</li>\n<li>Branching is fast!</li>\n<li>Merging is easy!</li>\n<li>Git is fast.</li>\n<li>Git is flexible.</li>\n</ul>\n<h2>Git Architecture</h2>\n<h3>Repository</h3>\n<p>A set of files, directories, historical records, commits, and heads. Imagine it\nas a source code data structure, with the attribute that each source code\n\"element\" gives you access to its revision history, among other things.</p>\n<p>A git repository is comprised of the .git directory &#x26; working tree.</p>\n<h3>.git Directory (component of repository)</h3>\n<p>The .git directory contains all the configurations, logs, branches, HEAD, and\nmore.\n<a href=\"http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html\">Detailed List.</a></p>\n<h3>Working Tree (component of repository)</h3>\n<p>This is basically the directories and files in your repository. It is often\nreferred to as your working directory.</p>\n<h3>Index (component of .git dir)</h3>\n<p>The Index is the staging area in git. It's basically a layer that separates\nyour working tree from the Git repository. This gives developers more power\nover what gets sent to the Git repository.</p>\n<h3>Commit</h3>\n<p>A git commit is a snapshot of a set of changes, or manipulations to your\nWorking Tree. For example, if you added 5 files, and removed 2 others, these\nchanges will be contained in a commit (or snapshot). This commit can then be\npushed to other repositories, or not!</p>\n<h3>Branch</h3>\n<p>A branch is essentially a pointer to the last commit you made. As you go on\ncommitting, this pointer will automatically update to point to the latest commit.</p>\n<h3>Tag</h3>\n<p>A tag is a mark on specific point in history. Typically people use this\nfunctionality to mark release points (v1.0, and so on).</p>\n<h3>HEAD and head (component of .git dir)</h3>\n<p>HEAD is a pointer that points to the current branch. A repository only has 1\n<em>active</em> HEAD.\nhead is a pointer that points to any commit. A repository can have any number\nof heads.</p>\n<h3>Stages of Git</h3>\n<ul>\n<li>Modified - Changes have been made to a file but file has not been committed</li>\n<li>to Git Database yet</li>\n<li>Staged - Marks a modified file to go into your next commit snapshot</li>\n<li>Committed - Files have been committed to the Git Database</li>\n</ul>\n<h3>Conceptual Resources</h3>\n<ul>\n<li><a href=\"http://eagain.net/articles/git-for-computer-scientists/\">Git For Computer Scientists</a></li>\n<li><a href=\"http://hoth.entp.com/output/git_for_designers.html\">Git For Designers</a></li>\n</ul>\n<h2>Commands</h2>\n<h3>init</h3>\n<p>Create an empty Git repository. The Git repository's settings, stored\ninformation, and more is stored in a directory (a folder) named \".git\".</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> init</code></pre></div>\n<h3>config</h3>\n<p>To configure settings. Whether it be for the repository, the system itself,\nor global configurations ( global config file is <code class=\"language-text\">~/.gitconfig</code> ).</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Print &amp; Set Some Basic Config Variables (Global)</span>\n <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> user.email <span class=\"token string\">\"bryan.guner@gmail.com\"</span>\n <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> user.name <span class=\"token string\">\"bryan\"</span></code></pre></div>\n<p><a href=\"http://git-scm.com/docs/git-config\">Learn More About git config.</a></p>\n<h3>help</h3>\n<p>To give you quick access to an extremely detailed guide of each command. Or to\njust give you a quick reminder of some semantics.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Quickly check available commands</span>\n$ <span class=\"token function\">git</span> <span class=\"token builtin class-name\">help</span>\n\n<span class=\"token comment\"># Check all available commands</span>\n$ <span class=\"token function\">git</span> <span class=\"token builtin class-name\">help</span> <span class=\"token parameter variable\">-a</span>\n\n<span class=\"token comment\"># Command specific help - user manual</span>\n<span class=\"token comment\"># git help &lt;command_here></span>\n$ <span class=\"token function\">git</span> <span class=\"token builtin class-name\">help</span> <span class=\"token function\">add</span>\n$ <span class=\"token function\">git</span> <span class=\"token builtin class-name\">help</span> commit\n$ <span class=\"token function\">git</span> <span class=\"token builtin class-name\">help</span> init\n<span class=\"token comment\"># or git &lt;command_here> --help</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token parameter variable\">--help</span>\n$ <span class=\"token function\">git</span> commit <span class=\"token parameter variable\">--help</span>\n$ <span class=\"token function\">git</span> init <span class=\"token parameter variable\">--help</span></code></pre></div>\n<h3>ignore files</h3>\n<p>To intentionally untrack file(s) &#x26; folder(s) from git. Typically meant for\nprivate &#x26; temp files which would otherwise be shared in the repository.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"temp/\"</span> <span class=\"token operator\">>></span> .gitignore\n$ <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"private_key\"</span> <span class=\"token operator\">>></span> .gitignore</code></pre></div>\n<h3>status</h3>\n<p>To show differences between the index file (basically your working copy/repo)\nand the current HEAD commit.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Will display the branch, untracked files, changes and other differences</span>\n$ <span class=\"token function\">git</span> status\n\n<span class=\"token comment\"># To learn other \"tid bits\" about git status</span>\n$ <span class=\"token function\">git</span> <span class=\"token builtin class-name\">help</span> status</code></pre></div>\n<h3>add</h3>\n<p>To add files to the staging area/index. If you do not <code class=\"language-text\">git add</code> new files to\nthe staging area/index, they will not be included in commits!</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># add a file in your current working directory</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">add</span> HelloWorld.java\n\n<span class=\"token comment\"># add a file in a nested dir</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">add</span> /path/to/file/HelloWorld.c\n\n<span class=\"token comment\"># Regular Expression support!</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">add</span> ./*.java\n\n<span class=\"token comment\"># You can also add everything in your working directory to the staging area.</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token parameter variable\">-A</span></code></pre></div>\n<p>This only adds a file to the staging area/index, it doesn't commit it to the\nworking directory/repo.</p>\n<h3>branch</h3>\n<p>Manage your branches. You can view, edit, create, delete branches using this\ncommand.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># list existing branches &amp; remotes</span>\n$ <span class=\"token function\">git</span> branch <span class=\"token parameter variable\">-a</span>\n\n<span class=\"token comment\"># create a new branch</span>\n$ <span class=\"token function\">git</span> branch myNewBranch\n\n<span class=\"token comment\"># delete a branch</span>\n$ <span class=\"token function\">git</span> branch <span class=\"token parameter variable\">-d</span> myBranch\n\n<span class=\"token comment\"># rename a branch</span>\n<span class=\"token comment\"># git branch -m &lt;oldname> &lt;newname></span>\n$ <span class=\"token function\">git</span> branch <span class=\"token parameter variable\">-m</span> myBranchName myNewBranchName\n\n<span class=\"token comment\"># edit a branch's description</span>\n$ <span class=\"token function\">git</span> branch myBranchName --edit-description</code></pre></div>\n<h3>tag</h3>\n<p>Manage your tags</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># List tags</span>\n$ <span class=\"token function\">git</span> tag\n\n<span class=\"token comment\"># Create a annotated tag</span>\n<span class=\"token comment\"># The -m specifies a tagging message, which is stored with the tag.</span>\n<span class=\"token comment\"># If you don't specify a message for an annotated tag,</span>\n<span class=\"token comment\"># Git launches your editor so you can type it in.</span>\n$ <span class=\"token function\">git</span> tag <span class=\"token parameter variable\">-a</span> v2.0 <span class=\"token parameter variable\">-m</span> <span class=\"token string\">'my version 2.0'</span>\n\n<span class=\"token comment\"># Show info about tag</span>\n<span class=\"token comment\"># That shows the tagger information, the date the commit was tagged,</span>\n<span class=\"token comment\"># and the annotation message before showing the commit information.</span>\n$ <span class=\"token function\">git</span> show v2.0\n\n<span class=\"token comment\"># Push a single tag to remote</span>\n$ <span class=\"token function\">git</span> push origin v2.0\n\n<span class=\"token comment\"># Push a lot of tags to remote</span>\n$ <span class=\"token function\">git</span> push origin <span class=\"token parameter variable\">--tags</span></code></pre></div>\n<h3>checkout</h3>\n<p>Updates all files in the working tree to match the version in the index, or\nspecified tree.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Checkout a repo - defaults to master branch</span>\n$ <span class=\"token function\">git</span> checkout\n\n<span class=\"token comment\"># Checkout a specified branch</span>\n$ <span class=\"token function\">git</span> checkout branchName\n\n<span class=\"token comment\"># Create a new branch &amp; switch to it</span>\n<span class=\"token comment\"># equivalent to \"git branch &lt;name>; git checkout &lt;name>\"</span>\n\n$ <span class=\"token function\">git</span> checkout <span class=\"token parameter variable\">-b</span> newBranch</code></pre></div>\n<h3>clone</h3>\n<p>Clones, or copies, an existing repository into a new directory. It also adds\nremote-tracking branches for each branch in the cloned repo, which allows you\nto push to a remote branch.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Clone learnxinyminutes-docs</span>\n$ <span class=\"token function\">git</span> clone https://github.com/adambard/learnxinyminutes-docs.git\n\n<span class=\"token comment\"># shallow clone - faster cloning that pulls only latest snapshot</span>\n$ <span class=\"token function\">git</span> clone <span class=\"token parameter variable\">--depth</span> <span class=\"token number\">1</span> https://github.com/adambard/learnxinyminutes-docs.git\n\n<span class=\"token comment\"># clone only a specific branch</span>\n$ <span class=\"token function\">git</span> clone <span class=\"token parameter variable\">-b</span> master-cn https://github.com/adambard/learnxinyminutes-docs.git --single-branch</code></pre></div>\n<h3>commit</h3>\n<p>Stores the current contents of the index in a new \"commit.\" This commit\ncontains the changes made and a message created by the user.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># commit with a message</span>\n$ <span class=\"token function\">git</span> commit <span class=\"token parameter variable\">-m</span> <span class=\"token string\">\"Added multiplyNumbers() function to HelloWorld.c\"</span>\n\n<span class=\"token comment\"># signed commit with a message (user.signingkey must have been set</span>\n<span class=\"token comment\"># with your GPG key e.g. git config --global user.signingkey 5173AAD5)</span>\n$ <span class=\"token function\">git</span> commit <span class=\"token parameter variable\">-S</span> <span class=\"token parameter variable\">-m</span> <span class=\"token string\">\"signed commit message\"</span>\n\n<span class=\"token comment\"># automatically stage modified or deleted files, except new files, and then commit</span>\n$ <span class=\"token function\">git</span> commit <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-m</span> <span class=\"token string\">\"Modified foo.php and removed bar.php\"</span>\n\n<span class=\"token comment\"># change last commit (this deletes previous commit with a fresh commit)</span>\n$ <span class=\"token function\">git</span> commit <span class=\"token parameter variable\">--amend</span> <span class=\"token parameter variable\">-m</span> <span class=\"token string\">\"Correct message\"</span></code></pre></div>\n<h3>diff</h3>\n<p>Shows differences between a file in the working directory, index and commits.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Show difference between your working dir and the index</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">diff</span>\n\n<span class=\"token comment\"># Show differences between the index and the most recent commit.</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">diff</span> <span class=\"token parameter variable\">--cached</span>\n\n<span class=\"token comment\"># Show differences between your working dir and the most recent commit</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">diff</span> HEAD</code></pre></div>\n<h3>grep</h3>\n<p>Allows you to quickly search a repository.</p>\n<p>Optional Configurations:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Thanks to Travis Jeffery for these</span>\n<span class=\"token comment\"># Set line numbers to be shown in grep search results</span>\n$ <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> grep.lineNumber <span class=\"token boolean\">true</span>\n\n<span class=\"token comment\"># Make search results more readable, including grouping</span>\n$ <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> alias.g <span class=\"token string\">\"grep --break --heading --line-number\"</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Search for \"variableName\" in all java files</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">grep</span> <span class=\"token string\">'variableName'</span> -- <span class=\"token string\">'*.java'</span>\n\n<span class=\"token comment\"># Search for a line that contains \"arrayListName\" and, \"add\" or \"remove\"</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'arrayListName'</span> <span class=\"token parameter variable\">--and</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">(</span> <span class=\"token parameter variable\">-e</span> <span class=\"token function\">add</span> <span class=\"token parameter variable\">-e</span> remove <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Google is your friend; for more examples\n<a href=\"http://travisjeffery.com/b/2012/02/search-a-git-repo-like-a-ninja\">Git Grep Ninja</a></p>\n<h3>log</h3>\n<p>Display commits to the repository.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Show all commits</span>\n$ <span class=\"token function\">git</span> log\n\n<span class=\"token comment\"># Show only commit message &amp; ref</span>\n$ <span class=\"token function\">git</span> log <span class=\"token parameter variable\">--oneline</span>\n\n<span class=\"token comment\"># Show merge commits only</span>\n$ <span class=\"token function\">git</span> log <span class=\"token parameter variable\">--merges</span>\n\n<span class=\"token comment\"># Show all commits represented by an ASCII graph</span>\n$ <span class=\"token function\">git</span> log <span class=\"token parameter variable\">--graph</span></code></pre></div>\n<h3>merge</h3>\n<p>\"Merge\" in changes from external commits into the current branch.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Merge the specified branch into the current.</span>\n$ <span class=\"token function\">git</span> merge branchName\n\n<span class=\"token comment\"># Always generate a merge commit when merging</span>\n$ <span class=\"token function\">git</span> merge --no-ff branchName</code></pre></div>\n<h3>mv</h3>\n<p>Rename or move a file</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Renaming a file</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">mv</span> HelloWorld.c HelloNewWorld.c\n\n<span class=\"token comment\"># Moving a file</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">mv</span> HelloWorld.c ./new/path/HelloWorld.c\n\n<span class=\"token comment\"># Force rename or move</span>\n<span class=\"token comment\"># \"existingFile\" already exists in the directory, will be overwritten</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">mv</span> <span class=\"token parameter variable\">-f</span> myFile existingFile</code></pre></div>\n<h3>pull</h3>\n<p>Pulls from a repository and merges it with another branch.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Update your local repo, by merging in new changes</span>\n<span class=\"token comment\"># from the remote \"origin\" and \"master\" branch.</span>\n<span class=\"token comment\"># git pull &lt;remote> &lt;branch></span>\n$ <span class=\"token function\">git</span> pull origin master\n\n<span class=\"token comment\"># By default, git pull will update your current branch</span>\n<span class=\"token comment\"># by merging in new changes from its remote-tracking branch</span>\n$ <span class=\"token function\">git</span> pull\n\n<span class=\"token comment\"># Merge in changes from remote branch and rebase</span>\n<span class=\"token comment\"># branch commits onto your local repo, like: \"git fetch &lt;remote> &lt;branch>, git</span>\n<span class=\"token comment\"># rebase &lt;remote>/&lt;branch>\"</span>\n$ <span class=\"token function\">git</span> pull origin master <span class=\"token parameter variable\">--rebase</span></code></pre></div>\n<h3>push</h3>\n<p>Push and merge changes from a branch to a remote &#x26; branch.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Push and merge changes from a local repo to a</span>\n<span class=\"token comment\"># remote named \"origin\" and \"master\" branch.</span>\n<span class=\"token comment\"># git push &lt;remote> &lt;branch></span>\n$ <span class=\"token function\">git</span> push origin master\n\n<span class=\"token comment\"># By default, git push will push and merge changes from</span>\n<span class=\"token comment\"># the current branch to its remote-tracking branch</span>\n$ <span class=\"token function\">git</span> push\n\n<span class=\"token comment\"># To link up current local branch with a remote branch, add -u flag:</span>\n$ <span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin master\n<span class=\"token comment\"># Now, anytime you want to push from that same local branch, use shortcut:</span>\n$ <span class=\"token function\">git</span> push</code></pre></div>\n<h3>stash</h3>\n<p>Stashing takes the dirty state of your working directory and saves it on a\nstack of unfinished changes that you can reapply at any time.</p>\n<p>Let's say you've been doing some work in your git repo, but you want to pull\nfrom the remote. Since you have dirty (uncommitted) changes to some files, you\nare not able to run <code class=\"language-text\">git pull</code>. Instead, you can run <code class=\"language-text\">git stash</code> to save your\nchanges onto a stack!</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> stash\nSaved working directory and index state <span class=\"token punctuation\">\\</span>\n  <span class=\"token string\">\"WIP on master: 049d078 added the index file\"</span>\n  HEAD is now at 049d078 added the index <span class=\"token function\">file</span>\n  <span class=\"token punctuation\">(</span>To restore them <span class=\"token builtin class-name\">type</span> <span class=\"token string\">\"git stash apply\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Now you can pull!</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> pull</code></pre></div>\n<p><code class=\"language-text\">...changes apply...</code></p>\n<p>Now check that everything is OK</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> status\n<span class=\"token comment\"># On branch master</span>\nnothing to commit, working directory clean</code></pre></div>\n<p>You can see what \"hunks\" you've stashed so far using <code class=\"language-text\">git stash list</code>.\nSince the \"hunks\" are stored in a Last-In-First-Out stack, our most recent\nchange will be at top.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> stash list\nstash@<span class=\"token punctuation\">{</span><span class=\"token number\">0</span><span class=\"token punctuation\">}</span>: WIP on master: 049d078 added the index <span class=\"token function\">file</span>\nstash@<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">}</span>: WIP on master: c264051 Revert <span class=\"token string\">\"added file_size\"</span>\nstash@<span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">}</span>: WIP on master: 21d80a5 added number to log</code></pre></div>\n<p>Now let's apply our dirty changes back by popping them off the stack.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> stash pop\n<span class=\"token comment\"># On branch master</span>\n<span class=\"token comment\"># Changes not staged for commit:</span>\n<span class=\"token comment\">#   (use \"git add &lt;file>...\" to update what will be committed)</span>\n<span class=\"token comment\">#</span>\n<span class=\"token comment\">#      modified:   index.html</span>\n<span class=\"token comment\">#      modified:   lib/simplegit.rb</span>\n<span class=\"token comment\">#</span></code></pre></div>\n<p><code class=\"language-text\">git stash apply</code> does the same thing</p>\n<p>Now you're ready to get back to work on your stuff!</p>\n<p><a href=\"http://git-scm.com/book/en/v1/Git-Tools-Stashing\">Additional Reading.</a></p>\n<h3>rebase (caution)</h3>\n<p>Take all changes that were committed on one branch, and replay them onto\nanother branch.\n<em>Do not rebase commits that you have pushed to a public repo</em>.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Rebase experimentBranch onto master</span>\n<span class=\"token comment\"># git rebase &lt;basebranch> &lt;topicbranch></span>\n$ <span class=\"token function\">git</span> rebase master experimentBranch</code></pre></div>\n<p><a href=\"http://git-scm.com/book/en/Git-Branching-Rebasing\">Additional Reading.</a></p>\n<h3>reset (caution)</h3>\n<p>Reset the current HEAD to the specified state. This allows you to undo merges,\npulls, commits, adds, and more. It's a great command but also dangerous if you\ndon't know what you are doing.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Reset the staging area, to match the latest commit (leaves dir unchanged)</span>\n$ <span class=\"token function\">git</span> reset\n\n<span class=\"token comment\"># Reset the staging area, to match the latest commit, and overwrite working dir</span>\n$ <span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span>\n\n<span class=\"token comment\"># Moves the current branch tip to the specified commit (leaves dir unchanged)</span>\n<span class=\"token comment\"># all changes still exist in the directory.</span>\n$ <span class=\"token function\">git</span> reset 31f2bb1\n\n<span class=\"token comment\"># Moves the current branch tip backward to the specified commit</span>\n<span class=\"token comment\"># and makes the working dir match (deletes uncommitted changes and all commits</span>\n<span class=\"token comment\"># after the specified commit).</span>\n$ <span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> 31f2bb1</code></pre></div>\n<h3>reflog (caution)</h3>\n<p>Reflog will list most of the git commands you have done for a given time period,\ndefault 90 days.</p>\n<p>This give you the chance to reverse any git commands that have gone wrong\n(for instance, if a rebase has broken your application).</p>\n<p>You can do this:</p>\n<ol>\n<li><code class=\"language-text\">git reflog</code> to list all of the git commands for the rebase</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">38b323f HEAD@{0}: rebase -i (finish): returning to refs/heads/feature/add_git_reflog\n38b323f HEAD@{1}: rebase -i (pick): Clarify inc/dec operators\n4fff859 HEAD@{2}: rebase -i (pick): Update java.html.markdown\n34ed963 HEAD@{3}: rebase -i (pick): [yaml/en] Add more resources (#1666)\ned8ddf2 HEAD@{4}: rebase -i (pick): pythonstatcomp spanish translation (#1748)\n2e6c386 HEAD@{5}: rebase -i (start): checkout 02fb96d</code></pre></div>\n<ol start=\"2\">\n<li>Select where to reset to, in our case its <code class=\"language-text\">2e6c386</code>, or <code class=\"language-text\">HEAD@{5}</code></li>\n<li>'git reset --hard HEAD@{5}' this will reset your repo to that head</li>\n<li>You can start the rebase again or leave it alone.</li>\n</ol>\n<p><a href=\"https://git-scm.com/docs/git-reflog\">Additional Reading.</a></p>\n<h3>revert</h3>\n<p>Revert can be used to undo a commit. It should not be confused with reset which\nrestores the state of a project to a previous point. Revert will add a new\ncommit which is the inverse of the specified commit, thus reverting it.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Revert a specified commit</span>\n$ <span class=\"token function\">git</span> revert <span class=\"token operator\">&lt;</span>commit<span class=\"token operator\">></span></code></pre></div>\n<h3>rm</h3>\n<p>The opposite of git add, git rm removes files from the current working tree.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># remove HelloWorld.c</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">rm</span> HelloWorld.c\n\n<span class=\"token comment\"># Remove a file from a nested dir</span>\n$ <span class=\"token function\">git</span> <span class=\"token function\">rm</span> /pather/to/the/file/HelloWorld.c</code></pre></div>\n<ul>\n<li><code class=\"language-text\">git checkout</code></li>\n<li><code class=\"language-text\">git reset</code></li>\n<li><code class=\"language-text\">git restore</code></li>\n<li><code class=\"language-text\">git switch</code></li>\n</ul>\n<p>I'll throw in one more, the misnamed <code class=\"language-text\">git revert</code>, as well.</p>\n<h3>From an end-user perspective</h3>\n<p>All you <em>need</em> are <code class=\"language-text\">git checkout</code>, <code class=\"language-text\">git reset</code>, and <code class=\"language-text\">git revert</code>. These commands have been in Git all along.</p>\n<p>But <code class=\"language-text\">git checkout</code> has, in effect, two <em>modes of operation</em>. One mode is \"safe\": it won't accidentally destroy any unsaved work. The other mode is \"unsafe\": if you use it, and it tells Git to wipe out some unsaved file, Git assumes that (a) you knew it meant that and (b) you really did mean to wipe out your unsaved file, so Git immediately wipes out your unsaved file.</p>\n<p>This is not very friendly, so the Git folks finally---after years of users griping---split <code class=\"language-text\">git checkout</code> into two new commands. This leads us to:</p>\n<h3>From a historical perspective</h3>\n<p><code class=\"language-text\">git restore</code> is <em>new</em>, having first come into existence in August 2019, in Git 2.23. <code class=\"language-text\">git reset</code> is very old, having been in Git all along, dating back to before 2005. Both commands have the ability to destroy unsaved work.</p>\n<p>The <code class=\"language-text\">git switch</code> command is also new, introduced along with <code class=\"language-text\">git restore</code> in Git 2.23. It implements the \"safe half\" of <code class=\"language-text\">git checkout</code>; <code class=\"language-text\">git restore</code> implements the \"unsafe half\".</p>\n<h3>When would you use which command?</h3>\n<p>This is the most complicated part, and to really understand it, we need to know the following items:</p>\n<ul>\n<li>Git is really all about <em>commits</em>. Commits get stored <em>in</em> the Git repository. The <code class=\"language-text\">git push</code> and <code class=\"language-text\">git fetch</code> commands transfer <em>commits</em>---whole commits, as an all-or-nothing deal^1^---to the other Git. You either have all of a commit, or you don't have it. Other commands, such as <code class=\"language-text\">git merge</code> or <code class=\"language-text\">git rebase</code>, all work with <em>local</em> commits. The <code class=\"language-text\">pull</code> command runs <code class=\"language-text\">fetch</code> (to get commits) followed by a second command to work with the commits once they're local.</li>\n<li>-</li>\n<li>New commits <em>add to the repository</em>. You almost never <em>remove</em> a commit <em>from</em> the repository. Only one of the five commands listed here---checkout, reset, restore, revert, and switch---is capable of removing commits.^2^</li>\n<li>-</li>\n<li>Each commit is numbered by its <em>hash ID</em>, which is unique to that one particular commit. It's actually computed from what's <em>in</em> the commit, which is how Git makes these numbers work across all Gits eveywhere. This means that what is in the commit is frozen for all time: if you change anything, what you get is a new commit with a new number, and the old commit is still there, with its same old number.</li>\n<li>Each commit stores two things: a snapshot, and metadata. The metadata include the hash ID(s) of some previous commit(s). This makes commits form backwards-looking chains.</li>\n<li>\n<p>A <em>branch name</em> holds the hash ID of one commit. This makes the branch name <em>find</em> that commit, which in turn means two things:</p>\n<ul>\n<li>that particular commit is the <em>tip commit</em> of that branch; and</li>\n<li>all commits leading up to and including that tip commit are <em>on</em> that branch.</li>\n</ul>\n</li>\n<li>We're also going to talk about Git's <em>index</em> in a moment, and your <em>working tree</em>. They're separate from these but worth mentioning early, especially since the index has three names: Git sometimes calls it the <em>index</em>, sometimes calls it the <em>staging area</em>, and sometimes---rarely these days---calls it the <em>cache</em>. All three names refer to the same thing.</li>\n</ul>\n<p>Everything up through the <em>branch name</em> is, I think, best understood via pictures (at least for most people). If we draw a series of commits, with newer commits towards the right, using <code class=\"language-text\">o</code> for each commit and omitting some commits for space or whatever, we get something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        o--o---o   &lt;-- feature-top\n       /\\\no--o--o--o--...--o---o--o   &lt;-- main\n    \\               /\n     o--o--...--o--o   &lt;-- feature-hull</code></pre></div>\n<p>which, as you can see, is a boat repository. 😀 There are three branches. The mainline branch holds <em>every commit</em>, including all the commits on the top row and bottom (hull) row. The <code class=\"language-text\">feature-top</code> branch holds the top three commits and also the three commits along the main line to the left, but not any of the commits on the bottom row. All the connectors <em>between</em> commits are---well, <em>should be</em> but I don't have a good enough font---one-way arrows, pointing left, or down-and-left, or up-and-left.</p>\n<p>These \"arrows\", or one way connections from commit to commit, are technically <a href=\"https://math.stackexchange.com/a/31208\"><em>arcs</em>, or one-way edges</a>, in a <a href=\"https://en.wikipedia.org/wiki/Directed_graph\"><em>directed graph</em></a>. This directed graph is one without cycles, making it a Directed Acyclic Graph or <a href=\"https://en.wikipedia.org/wiki/Directed_acyclic_graph\">DAG</a>, which has a bunch of properties that are useful to Git.</p>\n<p>If you're just using Git to store files inside commits, all you really care about are the round <code class=\"language-text\">o</code> <a href=\"https://math.stackexchange.com/a/1441525\"><em>nodes</em> or <em>vertices</em> (again two words for the same thing)</a>, each of which acts to store your files, but you should at least be vaguely aware of how they are arranged. It matters, especially because of <em>merges</em>. Merge commits are those with two outgoing arcs, pointing backwards to two of what Git calls <em>parent commits</em>. The child commit is the one \"later\": just as human parents are always older than their children, Git parent commits are older than their children.</p>\n<p>We need one more thing, though: <strong>Where do new commits come from?</strong> We noted that what's in a commit---both the snapshot, holding all the files, and the metadata, holding the rest of the information Git keeps about a commit---is all read-only. Your files are not only frozen, they're also <em>transformed</em>, and the transformed data are then <em>de-duplicated</em>, so that even though every commit has a full snapshot of <em>every</em> file, the repository itself stays relatively slim. But this means that the files <em>in</em> a commit can only be <em>read</em> by Git, and <em>nothing</em>---not even Git itself---can <em>write</em> to them. They get saved once, and are de-duplicated from then on. The commits act as archives, almost like tar or rar or winzip or whatever.</p>\n<p>To work with a Git repository, then, we have to have Git <em>extract</em> the files. This takes the files <em>out</em> of some commit, turning those special archive-formatted things into regular, usable files. Note that Git may well be able to store files that your computer literally <em>can't</em> store: a classic example is a file named <code class=\"language-text\">aux.h</code>, for some C program, on a Windows machine. We won't go into all the details, but it is theoretically possible to still get work done with this repository, which was probably built on a Linux system, even if you're on a Windows system where you can't work with the <code class=\"language-text\">aux.h</code> file directly.</p>\n<p>Anyway, assuming there are no nasty little surprises like <code class=\"language-text\">aux.h</code>, you would just run <code class=\"language-text\">git checkout</code> or <code class=\"language-text\">git switch</code> to get some commit <em>out</em> of Git. This will fill in your <em>working tree</em>, populating it from the files stored in the <em>tip commit</em> of some branch. The <em>tip commit</em> is, again, the <em>last</em> commit on that branch, as found by the <em>branch name</em>. Your <code class=\"language-text\">git checkout</code> or <code class=\"language-text\">git switch</code> selected that commit to be the <em>current commit</em>, by selecting that branch name to be the <em>current branch</em>. You now have all the files <em>from</em> that commit, in an area where you can see them and work on them: your <em>working tree</em>.</p>\n<p>Note that the files in your working tree <em>are not actually in Git itself</em>. They were just <em>extracted from</em> Git. This matters a lot, because when <code class=\"language-text\">git checkout</code> extracts the files <em>from</em> Git, it actually puts each file in two places. One of those places is the ordinary everyday file you see and work on / with. The other place Git puts each file is into Git's <em>index</em>.</p>\n<p>As I mentioned a moment ago, the index has three names: index, staging area, and cache. All refer to the same thing: the place Git sticks these \"copies\" of each file. Each one is actually pre-de-duplicated, so the word \"copy\" is slightly wrong, but---unlike much of the rest of its innards---Git actually does a really good job of hiding the de-duplication aspect. Unless you start getting into internal commands like <code class=\"language-text\">git ls-files</code> and <code class=\"language-text\">git update-index</code>, you don't need to know about this part, and can just think of the index as holding a copy of the file, ready to go into the <em>next commit</em>.</p>\n<p>What this all means for you as someone just <em>using</em> Git is that the index / staging-area acts as your <em>proposed next commit</em>. When you run <code class=\"language-text\">git commit</code>, Git is going to package up <em>these</em> copies of the file as the ones to be archived in the snapshot. The copies you have in your working tree are <em>yours;</em> the <em>index / staging-area</em> copies are <em>Git's</em>, ready to go. So, if you <em>change</em> your copies and want the <em>changed</em> copy to be what goes in the next snapshot, you must tell Git: <em>Update the Git copy, in the Git index / staging-area.</em> You do this with <code class=\"language-text\">git add</code>.^3^ The <code class=\"language-text\">git add</code> command means <em>make the proposed-next-commit copy match the working-tree copy</em>. It's the <code class=\"language-text\">add</code> command that does the updating: this is when Git compresses and de-duplicates the file and makes it ready for archiving, not at <code class=\"language-text\">git commit</code> time.^4^</p>\n<p>Then, assuming you have some series of commits ending with the one with <em><code class=\"language-text\">hash-N</code>:</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[hash1] &lt;-[hash2] ... &lt;-[hashN]   &lt;--branch</code></pre></div>\n<p>you run <code class=\"language-text\">git commit</code>, give it any metadata it needs (a commit log message), and you get an N+1'th commit:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[hash1] &lt;-[hash2] ... &lt;-[hashN] &lt;-[hashN+1]   &lt;--branch</code></pre></div>\n<p>Git automatically updates the <em>branch name</em> to point to the <em>new commit</em>, which has therefore been <em>added to the branch</em>.</p>\n<p>Let's look at each of the various commands now:</p>\n<ul>\n<li>\n<p><code class=\"language-text\">git checkout</code>: this is a large and complicated command.</p>\n<p>We already saw this one, or at least, <em>half</em> of this one. We used it to pick out a branch name, and therefore a particular commit. This kind of checkout first looks at our current commit, index, and working tree. It makes sure that we have committed all our modified files, or---this part gets a bit complicated---that if we <em>haven't</em> committed all our modified files, switching to that other branch is \"safe\". If it's <em>not</em> safe, <code class=\"language-text\">git checkout</code> tells you that you can't switch due to having modified files. If it <em>is</em> safe, <code class=\"language-text\">git checkout</code> will switch; if you didn't mean to switch, you can just switch back. (See also <a href=\"https://stackoverflow.com/q/22053757/1256452\">Checkout another branch when there are uncommitted changes on the current branch</a>)</p>\n<p>But <code class=\"language-text\">git checkout</code> has an <em>unsafe</em> half. Suppose you have modified some file in your working tree, such as <code class=\"language-text\">README.md</code> or <code class=\"language-text\">aux.h</code> or whatever. You now look back at what you changed and think: <em>No, that's a bad idea. I should get rid of this change. I'd like the file back exactly as it was before.</em></p>\n<p>To get this---to <em>wipe out</em> your changes to, say, <code class=\"language-text\">README.md</code>---you can run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git checkout -- README.md</code></pre></div>\n<p>The <code class=\"language-text\">--</code> part here is optional. It's a good idea to use it, because it tells Git that the part that comes after <code class=\"language-text\">--</code> is a <em>file name</em>, not a <em>branch name</em>.</p>\n<p>Suppose you have a <em>branch</em> named <code class=\"language-text\">hello</code> <em>and</em> a <em>file</em> named <code class=\"language-text\">hello</code>. What does:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git checkout hello</code></pre></div>\n<p>mean? Are we asking Git to clobber the <em>file</em> <code class=\"language-text\">hello</code> to remove the changes we made, or are we asking Git to check out the <em>branch</em> <code class=\"language-text\">hello</code>? To make this unambiguous, you have to write either:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git checkout -- hello        (clobber the file)</code></pre></div>\n<p>or:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git checkout hello --      (get the branch)</code></pre></div>\n<p>This case, where there are branches and files or directories with the same name, is a particularly insidious one. It has bitten real users. It's <em>why</em> <code class=\"language-text\">git switch</code> exists now. The <code class=\"language-text\">git switch</code> command <em>never means clobber my files</em>. It only means <em>do the safe kind of <code class=\"language-text\">git checkout</code>.</em></p>\n<p>(The <code class=\"language-text\">git checkout</code> command has been smartened up too, so that if you have the new commands and you run the \"bad\" kind of ambiguous <code class=\"language-text\">git checkout</code>, Git will just complain at you and do nothing at all. Either use the smarter split-up commands, or add the <code class=\"language-text\">--</code> at the right place to pick which kind of operation you want.)</p>\n<p>More precisely, <em>this kind</em> of <code class=\"language-text\">git checkout</code>, ideally spelled <code class=\"language-text\">git checkout -- *paths*</code>, is a request for Git to copy files from Git's index to your working tree. This means <em>clobber my files</em>. You can also run <code class=\"language-text\">git checkout *tree-ish* -- *paths*</code>, where you add a commit hash ID^5^ to the command. This tells Git to copy the files from that commit, first to Git's index, and then on to your working tree. This, too, means <em>clobber my files:</em> the difference is where Git gets the copies of the files it's extracting.</p>\n<p>If you ran <code class=\"language-text\">git add</code> on some file and thus copied it into Git's index, you need <code class=\"language-text\">git checkout HEAD -- *file*</code> to get it back from the current commit. The copy that's in Git's <em>index</em> is the one you <code class=\"language-text\">git add</code>-ed. So these two forms of <code class=\"language-text\">git checkout</code>, with a commit hash ID (or the name <code class=\"language-text\">HEAD</code>), the optional <code class=\"language-text\">--</code>, and the file name, are the unsafe <em>clobber my files</em> forms.</p>\n</li>\n<li>\n<p><code class=\"language-text\">git reset</code>: this is also a large and complicated command.</p>\n<p>There are, depending on how you count, up to about five or six different forms of <code class=\"language-text\">git reset</code>. We'll concentrate on a smaller subset here.</p>\n<ul>\n<li>\n<p><code class=\"language-text\">git reset [ --hard | --mixed | --soft ] [ *commit* ]</code></p>\n<p>Here, we're asking Git to do several things. First, if we give a <em><code class=\"language-text\">commit</code></em> argument, such as <code class=\"language-text\">HEAD</code> or <code class=\"language-text\">HEAD~3</code> or some such, we've picked a particular <em>commit</em> that Git should <em>reset to</em>. This is the kind of command that will <em>remove commits</em> by ejecting them off the end of the branch. Of all the commands listed here, this is the only one that removes any commits. One other command---<code class=\"language-text\">git commit --amend</code>---has the effect of ejecting the <em>last</em> commit while putting on a new replacement, but that one is limited to ejecting <em>one</em> commit.</p>\n<p>Let's show this as a drawing. Suppose we have:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">...--E--F--G--H   &lt;-- branch</code></pre></div>\n<p>That is, this branch, named <code class=\"language-text\">branch</code>, ends with four commits whose hash IDs we'll call <code class=\"language-text\">E</code>, <code class=\"language-text\">F</code>, <code class=\"language-text\">G</code>, and <code class=\"language-text\">H</code> in that order. The name <code class=\"language-text\">branch</code> currently stores the hash ID of the last of these commits, <code class=\"language-text\">H</code>. If we use <code class=\"language-text\">git reset --hard HEAD~3</code>, we're telling Git to eject the <em>last three commits</em>. The result is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">       F--G--H   ???\n      /\n...--E   &lt;-- branch</code></pre></div>\n<p>The name <code class=\"language-text\">branch</code> now selects commit <code class=\"language-text\">E</code>, not commit <code class=\"language-text\">H</code>. If we did not write down (on paper, on a whiteboard, in a file) the hash IDs of the last three commits, they've just become somewhat hard to find. Git does gives a way to find them again, for a while, but mostly they just seem to be <em>gone</em>.</p>\n<p>The <code class=\"language-text\">HEAD~3</code> part of this command is how we chose to drop the last three commits. It's part of a whole sub-topic in Git, documented in <a href=\"https://git-scm.com/docs/gitrevisions\">the gitrevisions manual</a>, on ways to name specific commits. The reset command just needs the hash ID of an actual commit, or anything equivalent, and <code class=\"language-text\">HEAD~3</code> means <em>go back three first-parent steps</em>, which in this case gets us from commit <code class=\"language-text\">H</code> back to commit <code class=\"language-text\">E</code>.</p>\n<p>The <code class=\"language-text\">--hard</code> part of the <code class=\"language-text\">git reset</code> is how we tell Git what to do with (a) its index and (b) our working tree files. We have three choices here:</p>\n<ul>\n<li><code class=\"language-text\">--soft</code> tells Git: <em>leave both alone</em>. Git will move the <em>branch name</em> without touching the index or our working tree. If you run <code class=\"language-text\">git commit</code> now, whatever is (still) in the index is what goes into the <em>new</em> commit. If the index matches the snapshot in commit <code class=\"language-text\">H</code>, this gets you a new commit whose <em>snapshot</em> is <code class=\"language-text\">H</code>, but whose <em>parent</em> is <code class=\"language-text\">E</code>, as if commits <code class=\"language-text\">F</code> through <code class=\"language-text\">H</code> had all been collapsed into a single new commit. People usually call this <em>squashing</em>.</li>\n<li><code class=\"language-text\">--mixed</code> tells Git: <em>reset your index, but leave my working tree alone</em>. Git will move the branch name, then <em>replace every file that is in the index with the one from the newly selected commit</em>. But Git will leave all your <em>working tree</em> files alone. This means that as far as Git is concerned, you can start <code class=\"language-text\">git add</code>ing files to make a new commit. Your new commit won't match <code class=\"language-text\">H</code> unless you <code class=\"language-text\">git add</code> <em>everything</em>, so this means you could, for instance, build a new intermediate commit, sort of like <code class=\"language-text\">E+F</code> or something, if you wanted.</li>\n<li><code class=\"language-text\">--hard</code> tells Git: <em>reset your index <strong>and</strong> my working tree.</em> Git will move the branch name, replace all the files in its index, and replace all the files in your working tree, all as one big thing. It's now as if you never made those three commits at all. You no longer have the files from <code class=\"language-text\">F</code>, or <code class=\"language-text\">G</code>, or <code class=\"language-text\">H</code>: you have the files from commit <code class=\"language-text\">E</code>.</li>\n</ul>\n<p>Note that if you leave out the <em><code class=\"language-text\">commit</code></em> part of this kind of (hard/soft/mixed) <code class=\"language-text\">reset</code>, Git will use <code class=\"language-text\">HEAD</code>. Since <code class=\"language-text\">HEAD</code> names the <em>current commit</em> (as selected by the current branch name), this leaves the branch name itself unchanged: it still selects the same commit as before. So this is only useful with <code class=\"language-text\">--mixed</code> or <code class=\"language-text\">--hard</code>, because <code class=\"language-text\">git reset --soft</code>, with no commit hash ID, means <em>don't move the branch name, don't change Git's index, and don't touch my working tree</em>. Those are the three things this kind of <code class=\"language-text\">git reset</code> can do---move the branch name, change what's in Git's index, and change what's in your working tree---and you just ruled all three out. Git is OK with doing nothing, but why bother?</p>\n</li>\n<li>\n<p><code class=\"language-text\">git reset [ *tree-ish* ] -- *path*</code></p>\n<p>This is the other kind of <code class=\"language-text\">git reset</code> we'll care about here. It's a bit like a mixed reset, in that it means <em>clobber some of the index copies of files</em>, but here you specify <em>which files to clobber</em>. It's also a bit <em>unlike</em> a mixed reset, because this kind of <code class=\"language-text\">git reset</code> will never move the branch name.</p>\n<p>Instead, you pick which files you want copied from somewhere. The <em>somewhere</em> is the <em><code class=\"language-text\">tree-ish</code></em> you give; if you don't give one, the <em>somewhere</em> is <code class=\"language-text\">HEAD</code>, i.e., the current commit. This can only restore files in the <em>proposed next commit</em> to the form they have in <em>some existing commit</em>. By defaulting to the <em>current</em> existing commit, this kind of <code class=\"language-text\">git reset -- *path*</code> has the effect of undoing a <code class=\"language-text\">git add -- *path*</code>.^6^</p>\n<p>There are several other forms of <code class=\"language-text\">git reset</code>. To see what they all mean, consult <a href=\"https://git-scm.com/docs/git-reset\">the documentation</a>.</p>\n</li>\n</ul>\n</li>\n<li>\n<p><code class=\"language-text\">git restore</code>: this got split off from <code class=\"language-text\">git checkout</code>.</p>\n<p>Basically, this does the same thing as the various forms of <code class=\"language-text\">git checkout</code> and <code class=\"language-text\">git reset</code> that clobber files (in your working tree and/or in Git's index). It's <em>smarter</em> than the old <code class=\"language-text\">git checkout</code>-and-clobber-my-work variant, in that you get to choose where the files come from <em>and</em> where they go, all in the one command line.</p>\n<p>To do what you used to do with <code class=\"language-text\">git checkout -- *file*</code>, you just run <code class=\"language-text\">git restore --staged --worktree -- *file*</code>. (You can leave out the <code class=\"language-text\">--</code> part, as with <code class=\"language-text\">git checkout</code>, in most cases, but it's just generally wise to get in the habit of using it. Like <code class=\"language-text\">git add</code>, this command is designed such that only files named <code class=\"language-text\">-whatever</code> are actually problematic.)</p>\n<p>To do what you used to do with <code class=\"language-text\">git reset -- *file*</code>, you just run <code class=\"language-text\">git restore --staged -- *file*</code>. That is, you tell <code class=\"language-text\">git restore</code> to copy from <code class=\"language-text\">HEAD</code> to staging area / index, which is how <code class=\"language-text\">git reset</code> operates.</p>\n<p>Note that you can copy a file from some existing commit, to Git's index, without touching your working tree copy of that file: <code class=\"language-text\">git restore --source *commit* --staged -- *file*</code> does that. You can't do that at all with the old <code class=\"language-text\">git checkout</code> but you <em>can</em> do that with the old <code class=\"language-text\">git reset</code>, as <code class=\"language-text\">git reset *commit* -- *file*</code>. And, you can copy a file from some existing commit, to your working tree, without touching the staged copy: <code class=\"language-text\">git restore --source *commit* --worktree -- *file*</code> does that. The overlapping part (restore and reset) exists <em>because</em> <code class=\"language-text\">git restore</code> is new, and this kind of restore makes sense; probably, ideally, we should always use <code class=\"language-text\">git restore</code> here, instead of using the old <code class=\"language-text\">git reset</code> way of doing things, but Git tries to maintain backwards compatibility.</p>\n<p>The new ability---to copy from any arbitrary source, to your working tree, without touching Git's index / staging-area copy---is just that: new. You couldn't do it before. (You could run <code class=\"language-text\">git show *commit*:*path* > *path*</code>, before, but that falls outside our five commands to examine.)</p>\n</li>\n<li><code class=\"language-text\">git switch</code>: this just does the \"safe half\" of <code class=\"language-text\">git checkout</code>. That's really all you need to know. Using <code class=\"language-text\">git switch</code>, without <code class=\"language-text\">--force</code>, Git won't overwrite your unsaved work, even if you make a typo or whatever. The old <code class=\"language-text\">git checkout</code> command could overwrite unsaved work: if your typo turns a branch name into a file name, for instance, well, oops.</li>\n<li>-</li>\n<li>\n<p><code class=\"language-text\">git revert</code> (I added this for completeness): this makes a <em>new commit</em>. The point of the new commit is to <em>back out</em> what someone did in some existing commit. You therefore need to name the existing commit that revert should back out. This command probably should have been named <code class=\"language-text\">git backout</code>.</p>\n<p>If you back out the most recent commit, this does revert to the second-most-recent snapshot:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  ...--G--H   &lt;-- branch</code></pre></div>\n<p>becomes:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  ...--G--H--Ħ   &lt;-- branch</code></pre></div>\n<p>where commit <code class=\"language-text\">Ħ</code> (H-bar) \"undoes\" commit <code class=\"language-text\">H</code> and therefore leaves us with the same <em>files</em> as commit <code class=\"language-text\">G</code>. But we don't have to undo the <em>most recent</em> commit. We could take:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  ...--E--F--G--H   &lt;-- branch</code></pre></div>\n<p>and add a commit <code class=\"language-text\">Ǝ</code> that undoes <code class=\"language-text\">E</code> to get:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  ...--E--F--G--H--Ǝ   &lt;-- branch</code></pre></div>\n<p>which may not match the source snapshot of any previous commit!</p>\n</li>\n</ul>\n<h2>Further Information</h2>\n<ul>\n<li><a href=\"http://try.github.io/levels/1/challenges/1\">tryGit - A fun interactive way to learn Git.</a></li>\n<li>-</li>\n<li>[Learn Git Branching - the most visual and interactive way to learn Git on the web](<a href=\"http://learngitbranch\">http://learngitbranch</a></li>\n<li>-</li>\n<li>[Udemy Git Tutorial: A Comprehensive Guide](<a href=\"https://blog\">https://blog</a></li>\n<li>-</li>\n<li>[Git Immersion - A Guided tour that walks through the fundamentals of git</li>\n<li>-</li>\n<li>[git-scm - Video Tutorials](<a href=\"http://g\">http://g</a></li>\n<li>-</li>\n<li>[git-scm - Documentation](<a href=\"http://git-scm.com/d\">http://git-scm.com/d</a></li>\n<li>-</li>\n<li><a href=\"https://www.atlassian.com/git/\">Atlassian Git - Tutorials &#x26; Workflows</a></li>\n<li><a href=\"http://res.cloudinary.com/hy4kyit2a/image/upload/SF_git_cheatsheet.pdf\">SalesForce Cheat Sheet</a></li>\n<li><a href=\"http://www.gitguys.com/\">GitGuys</a></li>\n<li><a href=\"http://rogerdudler.github.io/git-guide/index.html\">Git - the simple guide</a></li>\n<li><a href=\"http://www.git-scm.com/book/en/v2\">Pro Git</a></li>\n<li><a href=\"http://product.hubspot.com/blog/git-and-github-tutorial-for-beginners\">An introduction to Git and GitHub for Beginners (Tutorial)</a></li>\n<li><a href=\"https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAKWClAD_iKpNC0bGHxGhcx\">The New Boston tutorial to Git covering basic commands and workflow</a></li>\n</ul>"},{"url":"/docs/docs/html-standard/","relativePath":"docs/docs/html-standard.md","relativeDir":"docs/docs","base":"html-standard.md","name":"html-standard","frontmatter":{"title":"Learn HTML","weight":0,"excerpt":"Learn HTML","seo":{"title":" Learn HTML","description":" Learn HTML","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<iframe src=\"https://codesandbox.io/embed/htmlstandard-ndeqf3?autoresize=1&fontsize=14&hidenavigation=1&theme=dark&view=preview\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"htmlstandard\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   ></iframe>"},{"url":"/docs/docs/markdown/","relativePath":"docs/docs/markdown.md","relativeDir":"docs/docs","base":"markdown.md","name":"markdown","frontmatter":{"title":"Markdown","weight":0,"excerpt":"Markdown","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Markdown:</h2>\n<h2>Why markdown?</h2>\n<p>Markdown is a universal doc format that is easy to write and easy to add to a version control system.</p>\n<ul>\n<li><strong>Open</strong> - Anyone can submit content, fix typos &#x26; update anything via pull requests</li>\n<li><strong>Version control</strong> - Roll back &#x26; see the history of any given post</li>\n<li><strong>No CMS lock in</strong> - We can easily port to any static site generator</li>\n<li><strong>It's just simple</strong> - No user accounts to manage, no CMS software to upgrade, no plugins to install.</li>\n</ul>\n<hr>\n<h2>Markdown basics</h2>\n<p>The basics of markdown can be found <a href=\"https://guides.github.com/features/mastering-markdown/\">here</a> &#x26; <a href=\"https://daringfireball.net/projects/markdown/\">here</a>. Super easy!</p>\n<h2>Advanced Formatting tips</h2>\n<h3><code class=\"language-text\">left</code> alignment</h3>\n<img align=\"left\" width=\"100\" height=\"100\" src=\"\">\n<p>This is the code you need to align images to the left:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;img align=\"left\" width=\"100\" height=\"100\" src=\"\"></code></pre></div>\n<hr>\n<h3><code class=\"language-text\">right</code> alignment</h3>\n<img align=\"right\" width=\"100\" height=\"100\" src=\"\">\n<p>This is the code you need to align images to the right:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;img align=\"right\" width=\"100\" height=\"100\" src=\"\"></code></pre></div>\n<hr>\n<h3><code class=\"language-text\">center</code> alignment example</h3>\n<p align=\"center\">\n  <img width=\"460\" height=\"300\" src=\"http://www.fillmurray.com/460/300\">\n</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p align=\"center\">\n  &lt;img width=\"460\" height=\"300\" src=\"http://www.fillmurray.com/460/300\">\n&lt;/p></code></pre></div>\n<hr>\n<h3><code class=\"language-text\">collapse</code> Sections</h3>\n<p>Collapsing large blocks of text can make your markdown much easier to digest</p>\n<details>\n<summary>\"Click to expand\"</summary>\nthis is hidden block\n</details>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;details>\n&lt;summary>\"Click to expand\"&lt;/summary>\nthis is hidden\n&lt;/details></code></pre></div>\n<p>Collapsing large blocks of Markdown text</p>\n<details>\n<summary>To make sure markdown is rendered correctly in the collapsed section...</summary>\n<ol>\n<li>Put an <strong>empty line</strong> after the <code class=\"language-text\">&lt;summary></code> block.</li>\n<li><em>Insert your markdown syntax</em></li>\n<li>Put an <strong>empty line</strong> before the <code class=\"language-text\">&lt;/details></code> tag</li>\n</ol>\n</details>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;details>\n&lt;summary>To make sure markdown is rendered correctly in the collapsed section...&lt;/summary>\n\n 1. Put an **empty line** after the `&lt;summary>` block.\n 2. *Insert your markdown syntax*\n 3. Put an **empty line** before the `&lt;/details>` tag\n\n&lt;/details></code></pre></div>\n<hr>\n<h3><code class=\"language-text\">additional links</code></h3>\n<p><a href=\"http://www.serverless.com\">Website</a> • <a href=\"http://eepurl.com/b8dv4P\">Email Updates</a> • <a href=\"https://gitter.im/serverless/serverless\">Gitter</a> • <a href=\"http://forum.serverless.com\">Forum</a> • <a href=\"https://github.com/serverless-meetups/main\">Meetups</a> • <a href=\"https://twitter.com/goserverless\">Twitter</a> • <a href=\"https://www.facebook.com/serverless\">Facebook</a> • <a href=\"mailto:hello@serverless.com\">Contact Us</a></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[Website](http://www.serverless.com) • [Email Updates](http://eepurl.com/b8dv4P) • [Gitter](https://gitter.im/serverless/serverless) • [Forum](http://forum.serverless.com) • [Meetups](https://github.com/serverless-meetups/main) • [Twitter](https://twitter.com/goserverless) • [Facebook](https://www.facebook.com/serverless) • [Contact Us](mailto:hello@serverless.com)</code></pre></div>\n<hr>\n<h3>Badges</h3>\n<p>I hate them so. Don't use badges.</p>\n<hr>\n<h3>Nice looking file tree</h3>\n<p>For whatever <a href=\"https://twitter.com/alexdotjs/status/1421015442286596100\">reason</a> the <code class=\"language-text\">graphql</code> syntax will nicely highlight file trees like below:</p>\n<div class=\"gatsby-highlight\" data-language=\"graphql\"><pre class=\"language-graphql\"><code class=\"language-graphql\"><span class=\"token comment\"># Code &amp; components for pages</span>\n./<span class=\"token property\">src</span>/*\n  ├─ <span class=\"token property\">src</span>/<span class=\"token property\">assets</span> - <span class=\"token comment\"># Minified images, fonts, icon files</span>\n  ├─ <span class=\"token property\">src</span>/<span class=\"token property\">components</span> - <span class=\"token comment\"># Individual smaller components</span>\n  ├─ <span class=\"token property\">src</span>/<span class=\"token property\">fragments</span> - <span class=\"token comment\"># Larger chunks of a page composed of multiple components</span>\n  ├─ <span class=\"token property\">src</span>/<span class=\"token property\">layouts</span> - <span class=\"token comment\"># Page layouts used for different types of pages composed of components and fragments</span>\n  ├─ <span class=\"token property\">src</span>/<span class=\"token property\">page</span> - <span class=\"token comment\"># Custom pages or pages composed of layouts with hardcoded data components, fragments, &amp; layouts</span>\n  ├─ <span class=\"token property\">src</span>/<span class=\"token property\">pages</span>/* - <span class=\"token comment\"># Next.js file based routing</span>\n  │  ├─ <span class=\"token property\">_app</span>.<span class=\"token property\">js</span> - <span class=\"token comment\"># next.js app entry point</span>\n  │  ├─ <span class=\"token property\">_document</span>.<span class=\"token property\">js</span> - <span class=\"token comment\"># next.js document wrapper</span>\n  │  ├─ <span class=\"token property\">global</span>.<span class=\"token property\">css</span> - <span class=\"token comment\">#  Global CSS styles</span>\n  │  └─ <span class=\"token property\">Everything</span> <span class=\"token property\">else</span><span class=\"token operator\">...</span> - <span class=\"token comment\"># File based routing</span>\n  └─ <span class=\"token property\">src</span>/<span class=\"token property\">utils</span> - <span class=\"token comment\"># Utility functions used in various places</span></code></pre></div>\n<hr>\n<h2>Useful packages</h2>\n<ol>\n<li><a href=\"https://www.npmjs.com/package/gray-matter\">gray-matter</a></li>\n</ol>\n<p>YAML front-matter is your friend. You can keep metadata in markdown files</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">title: Serverless Framework Documentation\ndescription: \"Great F'in docs!\"\nmenuText: Docs\nlayout: Doc</code></pre></div>\n<ol start=\"2\">\n<li><a href=\"https://www.npmjs.com/package/remark\">Remark</a></li>\n</ol>\n<p>Useful for rendering markdown in HTML/React</p>\n<ol start=\"3\">\n<li><a href=\"https://github.com/DavidWells/markdown-magic\">Markdown Magic</a></li>\n<li><a href=\"https://github.com/DavidWells/markdown-magic\">Repo</a></li>\n<li><a href=\"https://github.com/DavidWells/markdown-magic#plugins\">Plugins</a></li>\n<li>Show automatic doc generation. <a href=\"https://github.com/DavidWells/markdown-magic/blob/master/examples/generate-readme.js#L15-L23\">Example 1</a> | <a href=\"https://github.com/serverless/examples/blob/master/generate-readme.js#L71-L87\">Example 2</a></li>\n</ol>\n<hr>\n<h2>Useful utilities</h2>\n<ol>\n<li><a href=\"https://github.com/serverless/post-scheduler\">Schedule Posts</a> - Post scheduler for static sites</li>\n</ol>\n<p>Show DEMO</p>\n<ol start=\"2\">\n<li><a href=\"https://jekyll-anon.surge.sh/gods/2015/02/18/vesta.html\">Zero friction inline content editing</a></li>\n</ol>\n<p>Show DEMO</p>\n<ol start=\"3\">\n<li><a href=\"https://bywordapp.com/\">Byword</a> &#x26; <a href=\"https://typora.io/\">Typora</a> - Good Editors</li>\n<li><a href=\"https://monodraw.helftone.com/\">Monodraw</a> - Flow charts for days</li>\n<li><a href=\"https://getkap.co/\">Kap</a> - Make gifs</li>\n<li><a href=\"https://atom.io/packages/markdown-preview\">IDE markdown preview</a></li>\n<li>Stuck on WordPress? Try <a href=\"https://github.com/DavidWells/easy-markdown\">easy-markdown plugin</a></li>\n</ol>\n<hr>\n<h2>How Serverless uses markdown</h2>\n<p>Serverless.com is comprised of 3 separate repositories</p>\n<ul>\n<li><a href=\"https://github.com/serverless/blog\">https://github.com/serverless/blog</a></li>\n<li><a href=\"https://github.com/serverless/serverless\">https://github.com/serverless/serverless</a> | Shoutout to <a href=\"https://phenomic.io/\">Phenomic.io</a></li>\n<li><a href=\"https://github.com/serverless/site\">https://github.com/serverless/site</a></li>\n</ul>\n<p><strong>Why multiple repos?</strong></p>\n<ol>\n<li>We wanted documentation about the framework to live in the serverless github repo for easy access</li>\n<li>We wanted our blog content to be easily portable to any static site generator separate from the implementation (site)</li>\n<li><code class=\"language-text\">prebuild</code> npm script pulls the content together &#x26; processes them for site build</li>\n</ol>\n<p>A single repo is easier to manage but harder for people to find/edit/PR content.</p>\n<hr>\n<h3>DEMO</h3>\n<ul>\n<li>Site structure</li>\n<li>Serverless build process</li>\n<li><a href=\"https://github.com/serverless/blog/blob/master/.travis.yml#L10\">Validation</a></li>\n<li><a href=\"https://serverless.com/framework/docs/providers/aws/cli-reference/deploy/\">Editing Flow</a></li>\n<li>\n<p>Github optimizations</p>\n<ul>\n<li><a href=\"https://github.com/serverless/serverless/blob/master/docs/providers/aws/events/schedule.md\">Link from top of each doc to live link on site</a></li>\n<li>use markdown magic =) to <a href=\"https://github.com/serverless/examples\">auto generate tables</a> etc</li>\n<li><a href=\"https://github.com/serverless/serverless/blame/master/docs/providers/aws/events/schedule.md#L1-L7\">Hide yaml frontmatter from github folks</a></li>\n<li>consider linking everything to site</li>\n</ul>\n</li>\n</ul>\n<h2>Other Markdown Resources</h2>\n<ul>\n<li><a href=\"https://www.npmjs.com/package/verb\">Verb</a> - Documentation generator for GitHub projects</li>\n<li><a href=\"http://asciidoctor.org/\">ACSII docs</a> - Markdown alternative</li>\n</ul>"},{"url":"/docs/docs/git-repos/","relativePath":"docs/docs/git-repos.md","relativeDir":"docs/docs","base":"git-repos.md","name":"git-repos","frontmatter":{"title":"Git Repo List","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>My Repos:</h1>\n<details>\n<summary><span style=\"align-self: center; margin: auto; font-family: papyrus; font-size: 2em;\"> ===➤(_CLICK TO SEE MORE_)➤</span></summary>\n<table>\n<thead>\n<tr>\n<th><a href=\"https://github.com/bgoonz/a-whole-bunch-o-gatsby-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=a-whole-bunch-o-gatsby-templates\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/Comments\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Comments\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/EXPRESS-NOTES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=EXPRESS-NOTES\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=INTERVIEW-PREP-COMPLETE\" alt=\"ReadMe Card\"></a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://github.com/bgoonz/alternate-blog-theme\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=alternate-blog-theme\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=commercejs-nextjs-demo-store\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/fast-fourier-transform-\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=fast-fourier-transform-\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/JAMSTACK-TEMPLATES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=JAMSTACK-TEMPLATES\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/anki-cards\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=anki-cards\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Common-npm-Readme-Compilation\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Common-npm-Readme-Compilation\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/form-builder-vanilla-js\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=form-builder-vanilla-js\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Javascript-Best-Practices_--Tools\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Javascript-Best-Practices_--Tools\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/ask-me-anything\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=ask-me-anything\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Connect-Four-Final-Version\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Connect-Four-Final-Version\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Front-End-Frameworks-Practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Front-End-Frameworks-Practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/jsanimate\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=jsanimate\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/atlassian-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=atlassian-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/convert-folder-contents-2-website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=convert-folder-contents-2-website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/full-stack-react-redux\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=full-stack-react-redux\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Jupyter-Notebooks\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Jupyter-Notebooks\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Authentication-Notes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Authentication-Notes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Copy-2-Clipboard-jQuery\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Copy-2-Clipboard-jQuery\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Full-Text-Search\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Full-Text-Search\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Lambda\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Lambda\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-commands-walkthrough\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-commands-walkthrough\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Data-Structures-Algos-Codebase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Data-Structures-Algos-Codebase\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Games\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Games\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Lambda-Resource-Static-Assets\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-config-backup\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-config-backup\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DATA_STRUC_PYTHON_NOTES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DATA_STRUC_PYTHON_NOTES\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gatsby-netlify-cms-norwex\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gatsby-netlify-cms-norwex\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/learning-nextjs\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=learning-nextjs\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-shell-utility-functions\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-shell-utility-functions\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/design-home-page-with-routes-bq5v7k\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=design-home-page-with-routes-bq5v7k\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gatsby-react-portfolio\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gatsby-react-portfolio\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Learning-Redux\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Learning-Redux\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bass-station\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bass-station\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/docs-collection\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=docs-collection\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GIT-CDN-FILES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GIT-CDN-FILES\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Links-Shortcut-Site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Links-Shortcut-Site\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bgoonz\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bgoonz\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Documentation-site-react\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Documentation-site-react\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GIT-HTML-PREVIEW-TOOL\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/live-examples\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=live-examples\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZBLOG2.0STABLE\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=BGOONZBLOG2.0STABLE\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DS-ALGO-OFFICIAL\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gitbook\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gitbook\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/live-form\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=live-form\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=BGOONZ_BLOG_2.0\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DS-AND-ALGO-Notes-P2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DS-AND-ALGO-Notes-P2\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/github-readme-stats\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=github-readme-stats\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/loadash-es6-refactor\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=loadash-es6-refactor\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Binary-Search\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Binary-Search\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/ecommerce-interactive\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=ecommerce-interactive\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/github-reference-repo\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=github-reference-repo\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/markdown-css\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=markdown-css\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-2.o-versions\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-2.o-versions\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=embedable-repl-and-integrated-code-space-playground\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GoalsTracker\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GoalsTracker\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Markdown-Templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Markdown-Templates\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/excel2html-table\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=excel2html-table\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/graphql-experimentation\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=graphql-experimentation\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/meditation-app\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=meditation-app\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-w-comments\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-w-comments\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Exploring-Promises\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Exploring-Promises\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/https___mihirbeg.com_\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=https___mihirbeg.com_\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/MihirBegMusicLab\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=MihirBegMusicLab\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Blog2.0-August-Super-Stable\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Blog2.0-August-Super-Stable\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/express-API-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=express-API-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/iframe-showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=iframe-showcase\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/MihirBegMusicV3\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=MihirBegMusicV3\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bootstrap-sidebar-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bootstrap-sidebar-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Express-basic-server-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Express-basic-server-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Image-Archive-Traning-Data\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Image-Archive-Traning-Data\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Mihir_Beg_Final\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Mihir_Beg_Final\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/callbacks\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=callbacks\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/express-knex-postgres-boilerplate\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=express-knex-postgres-boilerplate\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Independent-Blog-Entries\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Independent-Blog-Entries\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Project-Showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Project-Showcase\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Shell-Script-Practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Shell-Script-Practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/promises-with-async-and-await\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=promises-with-async-and-await\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-notes-v5\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-notes-v5\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/mini-project-showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=mini-project-showcase\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/site-analysis\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=site-analysis\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/psql-practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=psql-practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-registration-login-example\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-registration-login-example\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Music-Theory-n-Web-Synth-Keyboard\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sorting-algorithms\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sorting-algorithms\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-playground-embed\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-playground-embed\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/React_Notes_V3\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=React_Notes_V3\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/my-gists\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=my-gists\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sorting-algos\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sorting-algos\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-practice-notes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-practice-notes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Recursion-Practice-Website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Recursion-Practice-Website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/My-Medium-Blog\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=My-Medium-Blog\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sqlite3-nodejs-demo\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sqlite3-nodejs-demo\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-scripts\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-scripts\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Regex-and-Express-JS\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Regex-and-Express-JS\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=nextjs-netlify-blog-template\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/stalk-photos-web-assets\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=stalk-photos-web-assets\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/PYTHON_PRAC\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=PYTHON_PRAC\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/repo-utils\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=repo-utils\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/norwex-coff-ecom\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=norwex-coff-ecom\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Standalone-Metranome\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Standalone-Metranome\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/random-list-of-embedable-content\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=random-list-of-embedable-content\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/resume-cv-portfolio-samples\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=resume-cv-portfolio-samples\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/old-c-and-cpp-repos-from-undergrad\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=old-c-and-cpp-repos-from-undergrad\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Star-wars-API-Promise-take2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Star-wars-API-Promise-take2\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/random-static-html-page-deploy\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=random-static-html-page-deploy\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Revamped-Automatic-Guitar-Effect-Triggering\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/old-code-from-undergrad\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=old-code-from-undergrad\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Static-Study-Site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Static-Study-Site\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/React-movie-app\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=React-movie-app\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/supertemp\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=supertemp\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/picture-man-bob-v2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=picture-man-bob-v2\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/styling-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=styling-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-medium-clone\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-medium-clone\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Ternary-converter\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Ternary-converter\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/scope-closure-context\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=scope-closure-context\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/TetrisJS\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TetrisJS\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/The-Algorithms\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=The-Algorithms\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Triggered-Guitar-Effects-Platform\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Triggered-Guitar-Effects-Platform\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/UsefulResourceRepo2.0\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=UsefulResourceRepo2.0\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/TexTools\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TexTools\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/TRASH\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TRASH\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Useful-Snippets-js\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Useful-Snippets-js\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/vscode-customized-config\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=vscode-customized-config\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/vscode-Extension-readmes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=vscode-Extension-readmes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-interview-prep-quiz-website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-interview-prep-quiz-website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-setup-checker\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-setup-checker\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-utils-package\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-utils-package\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/web-crawler-node\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-crawler-node\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-notes-resource-site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-notes-resource-site\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/WEB-DEV-TOOLS-HUB\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=WEB-DEV-TOOLS-HUB\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/WebAudioDaw\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=WebAudioDaw\" alt=\"ReadMe Card\"></a></td>\n</tr>\n</tbody>\n</table>\n</details>  \n  \n<ul>\n<li><a href=\"https://github.com/bgoonz/03-fetch-data\">https://github.com/bgoonz/03-fetch-data</a></li>\n<li><a href=\"https://github.com/bgoonz/a-whole-bunch-o-gatsby-templates\">https://github.com/bgoonz/a-whole-bunch-o-gatsby-templates</a></li>\n<li><a href=\"https://github.com/bgoonz/activity-box\">https://github.com/bgoonz/activity-box</a></li>\n<li><a href=\"https://github.com/bgoonz/All-Undergrad-Archive\">https://github.com/bgoonz/All-Undergrad-Archive</a></li>\n<li><a href=\"https://github.com/bgoonz/alternate-blog-theme\">https://github.com/bgoonz/alternate-blog-theme</a></li>\n<li><a href=\"https://github.com/bgoonz/anki-cards\">https://github.com/bgoonz/anki-cards</a></li>\n<li><a href=\"https://github.com/bgoonz/ask-me-anything\">https://github.com/bgoonz/ask-me-anything</a></li>\n<li><a href=\"https://github.com/bgoonz/atlassian-templates\">https://github.com/bgoonz/atlassian-templates</a></li>\n<li><a href=\"https://github.com/bgoonz/Authentication-Notes\">https://github.com/bgoonz/Authentication-Notes</a></li>\n<li><a href=\"https://github.com/bgoonz/bash-commands-walkthrough\">https://github.com/bgoonz/bash-commands-walkthrough</a></li>\n<li><a href=\"https://github.com/bgoonz/bash-config-backup\">https://github.com/bgoonz/bash-config-backup</a></li>\n<li><a href=\"https://github.com/bgoonz/bash-shell-utility-functions\">https://github.com/bgoonz/bash-shell-utility-functions</a></li>\n<li><a href=\"https://github.com/bgoonz/bass-station\">https://github.com/bgoonz/bass-station</a></li>\n<li><a href=\"https://github.com/bgoonz/bgoonz\">https://github.com/bgoonz/bgoonz</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZBLOG2.0STABLE\">https://github.com/bgoonz/BGOONZBLOG2.0STABLE</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\">https://github.com/bgoonz/BGOONZ<em>BLOG</em>2.0</a></li>\n<li><a href=\"https://github.com/bgoonz/Binary-Search\">https://github.com/bgoonz/Binary-Search</a></li>\n<li><a href=\"https://github.com/bgoonz/blog-2.o-versions\">https://github.com/bgoonz/blog-2.o-versions</a></li>\n<li><a href=\"https://github.com/bgoonz/blog-templates\">https://github.com/bgoonz/blog-templates</a></li>\n<li><a href=\"https://github.com/bgoonz/blog-w-comments\">https://github.com/bgoonz/blog-w-comments</a></li>\n<li><a href=\"https://github.com/bgoonz/Blog2.0-August-Super-Stable\">https://github.com/bgoonz/Blog2.0-August-Super-Stable</a></li>\n<li><a href=\"https://github.com/bgoonz/bootstrap-sidebar-template\">https://github.com/bgoonz/bootstrap-sidebar-template</a></li>\n<li><a href=\"https://github.com/bgoonz/callbacks\">https://github.com/bgoonz/callbacks</a></li>\n<li><a href=\"https://github.com/bgoonz/Comments\">https://github.com/bgoonz/Comments</a></li>\n<li><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store\">https://github.com/bgoonz/commercejs-nextjs-demo-store</a></li>\n<li><a href=\"https://github.com/bgoonz/Common-npm-Readme-Compilation\">https://github.com/bgoonz/Common-npm-Readme-Compilation</a></li>\n<li><a href=\"https://github.com/bgoonz/Comparing-Web-Development-Bootcamps-2021\">https://github.com/bgoonz/Comparing-Web-Development-Bootcamps-2021</a></li>\n<li><a href=\"https://github.com/bgoonz/Connect-Four-Final-Version\">https://github.com/bgoonz/Connect-Four-Final-Version</a></li>\n<li><a href=\"https://github.com/bgoonz/convert-folder-contents-2-website\">https://github.com/bgoonz/convert-folder-contents-2-website</a></li>\n<li><a href=\"https://github.com/bgoonz/Copy-2-Clipboard-jQuery\">https://github.com/bgoonz/Copy-2-Clipboard-jQuery</a></li>\n<li><a href=\"https://github.com/bgoonz/Data-Structures-Algos-Codebase\">https://github.com/bgoonz/Data-Structures-Algos-Codebase</a></li>\n<li><a href=\"https://github.com/bgoonz/DATA_STRUC_PYTHON_NOTES\">https://github.com/bgoonz/DATA<em>STRUC</em>PYTHON_NOTES</a></li>\n<li><a href=\"https://github.com/bgoonz/design-home-page-with-routes-bq5v7k\">https://github.com/bgoonz/design-home-page-with-routes-bq5v7k</a></li>\n<li><a href=\"https://github.com/bgoonz/docs-collection\">https://github.com/bgoonz/docs-collection</a></li>\n<li><a href=\"https://github.com/bgoonz/Documentation-site-react\">https://github.com/bgoonz/Documentation-site-react</a></li>\n<li><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">https://github.com/bgoonz/DS-ALGO-OFFICIAL</a></li>\n<li><a href=\"https://github.com/bgoonz/DS-AND-ALGO-Notes-P2\">https://github.com/bgoonz/DS-AND-ALGO-Notes-P2</a></li>\n<li><a href=\"https://github.com/bgoonz/ecommerce-interactive\">https://github.com/bgoonz/ecommerce-interactive</a></li>\n<li><a href=\"https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground\">https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground</a></li>\n<li><a href=\"https://github.com/bgoonz/excel2html-table\">https://github.com/bgoonz/excel2html-table</a></li>\n<li><a href=\"https://github.com/bgoonz/Exploring-Promises\">https://github.com/bgoonz/Exploring-Promises</a></li>\n<li><a href=\"https://github.com/bgoonz/express-API-template\">https://github.com/bgoonz/express-API-template</a></li>\n<li><a href=\"https://github.com/bgoonz/Express-basic-server-template\">https://github.com/bgoonz/Express-basic-server-template</a></li>\n<li><a href=\"https://github.com/bgoonz/express-knex-postgres-boilerplate\">https://github.com/bgoonz/express-knex-postgres-boilerplate</a></li>\n<li><a href=\"https://github.com/bgoonz/EXPRESS-NOTES\">https://github.com/bgoonz/EXPRESS-NOTES</a></li>\n<li><a href=\"https://github.com/bgoonz/fast-fourier-transform-\">https://github.com/bgoonz/fast-fourier-transform-</a></li>\n<li><a href=\"https://github.com/bgoonz/form-builder-vanilla-js\">https://github.com/bgoonz/form-builder-vanilla-js</a></li>\n<li><a href=\"https://github.com/bgoonz/Front-End-Frameworks-Practice\">https://github.com/bgoonz/Front-End-Frameworks-Practice</a></li>\n<li><a href=\"https://github.com/bgoonz/full-stack-react-redux\">https://github.com/bgoonz/full-stack-react-redux</a></li>\n<li><a href=\"https://github.com/bgoonz/Full-Text-Search\">https://github.com/bgoonz/Full-Text-Search</a></li>\n<li><a href=\"https://github.com/bgoonz/Games\">https://github.com/bgoonz/Games</a></li>\n<li><a href=\"https://github.com/bgoonz/gatsby-netlify-cms-norwex\">https://github.com/bgoonz/gatsby-netlify-cms-norwex</a></li>\n<li><a href=\"https://github.com/bgoonz/gatsby-react-portfolio\">https://github.com/bgoonz/gatsby-react-portfolio</a></li>\n<li><a href=\"https://github.com/bgoonz/GIT-CDN-FILES\">https://github.com/bgoonz/GIT-CDN-FILES</a></li>\n<li><a href=\"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL\">https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL</a></li>\n<li><a href=\"https://github.com/bgoonz/gitbook\">https://github.com/bgoonz/gitbook</a></li>\n<li><a href=\"https://github.com/bgoonz/github-readme-stats\">https://github.com/bgoonz/github-readme-stats</a></li>\n<li><a href=\"https://github.com/bgoonz/github-reference-repo\">https://github.com/bgoonz/github-reference-repo</a></li>\n<li><a href=\"https://github.com/bgoonz/GoalsTracker\">https://github.com/bgoonz/GoalsTracker</a></li>\n<li><a href=\"https://github.com/bgoonz/graphql-experimentation\">https://github.com/bgoonz/graphql-experimentation</a></li>\n<li><a href=\"https://github.com/bgoonz/https___mihirbeg.com_\">https://github.com/bgoonz/https<em>__mihirbeg.com</em></a></li>\n<li><a href=\"https://github.com/bgoonz/iframe-showcase\">https://github.com/bgoonz/iframe-showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/Image-Archive-Traning-Data\">https://github.com/bgoonz/Image-Archive-Traning-Data</a></li>\n<li><a href=\"https://github.com/bgoonz/Independent-Blog-Entries\">https://github.com/bgoonz/Independent-Blog-Entries</a></li>\n<li><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE\">https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE</a></li>\n<li><a href=\"https://github.com/bgoonz/JAMSTACK-TEMPLATES\">https://github.com/bgoonz/JAMSTACK-TEMPLATES</a></li>\n<li><a href=\"https://github.com/bgoonz/Javascript-Best-Practices_--Tools\">https://github.com/bgoonz/Javascript-Best-Practices_--Tools</a></li>\n<li><a href=\"https://github.com/bgoonz/jsanimate\">https://github.com/bgoonz/jsanimate</a></li>\n<li><a href=\"https://github.com/bgoonz/Jupyter-Notebooks\">https://github.com/bgoonz/Jupyter-Notebooks</a></li>\n<li><a href=\"https://github.com/bgoonz/Lambda\">https://github.com/bgoonz/Lambda</a></li>\n<li><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\">https://github.com/bgoonz/Lambda-Resource-Static-Assets</a></li>\n<li><a href=\"https://github.com/bgoonz/learning-nextjs\">https://github.com/bgoonz/learning-nextjs</a></li>\n<li><a href=\"https://github.com/bgoonz/Learning-Redux\">https://github.com/bgoonz/Learning-Redux</a></li>\n<li><a href=\"https://github.com/bgoonz/Links-Shortcut-Site\">https://github.com/bgoonz/Links-Shortcut-Site</a></li>\n<li><a href=\"https://github.com/bgoonz/live-examples\">https://github.com/bgoonz/live-examples</a></li>\n<li><a href=\"https://github.com/bgoonz/live-form\">https://github.com/bgoonz/live-form</a></li>\n<li><a href=\"https://github.com/bgoonz/loadash-es6-refactor\">https://github.com/bgoonz/loadash-es6-refactor</a></li>\n<li><a href=\"https://github.com/bgoonz/markdown-css\">https://github.com/bgoonz/markdown-css</a></li>\n<li><a href=\"https://github.com/bgoonz/Markdown-Templates\">https://github.com/bgoonz/Markdown-Templates</a></li>\n<li><a href=\"https://github.com/bgoonz/meditation-app\">https://github.com/bgoonz/meditation-app</a></li>\n<li><a href=\"https://github.com/bgoonz/MihirBegMusicLab\">https://github.com/bgoonz/MihirBegMusicLab</a></li>\n<li><a href=\"https://github.com/bgoonz/MihirBegMusicV3\">https://github.com/bgoonz/MihirBegMusicV3</a></li>\n<li><a href=\"https://github.com/bgoonz/Mihir_Beg_Final\">https://github.com/bgoonz/Mihir<em>Beg</em>Final</a></li>\n<li><a href=\"https://github.com/bgoonz/mini-project-showcase\">https://github.com/bgoonz/mini-project-showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard\">https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard</a></li>\n<li><a href=\"https://github.com/bgoonz/my-gists\">https://github.com/bgoonz/my-gists</a></li>\n<li><a href=\"https://github.com/bgoonz/My-Medium-Blog\">https://github.com/bgoonz/My-Medium-Blog</a></li>\n<li><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template\">https://github.com/bgoonz/nextjs-netlify-blog-template</a></li>\n<li><a href=\"https://github.com/bgoonz/norwex-coff-ecom\">https://github.com/bgoonz/norwex-coff-ecom</a></li>\n<li><a href=\"https://github.com/bgoonz/old-c-and-cpp-repos-from-undergrad\">https://github.com/bgoonz/old-c-and-cpp-repos-from-undergrad</a></li>\n<li><a href=\"https://github.com/bgoonz/old-code-from-undergrad\">https://github.com/bgoonz/old-code-from-undergrad</a></li>\n<li><a href=\"https://github.com/bgoonz/picture-man-bob-v2\">https://github.com/bgoonz/picture-man-bob-v2</a></li>\n<li><a href=\"https://github.com/bgoonz/Project-Showcase\">https://github.com/bgoonz/Project-Showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/promises-with-async-and-await\">https://github.com/bgoonz/promises-with-async-and-await</a></li>\n<li><a href=\"https://github.com/bgoonz/psql-practice\">https://github.com/bgoonz/psql-practice</a></li>\n<li><a href=\"https://github.com/bgoonz/python-playground-embed\">https://github.com/bgoonz/python-playground-embed</a></li>\n<li><a href=\"https://github.com/bgoonz/python-practice-notes\">https://github.com/bgoonz/python-practice-notes</a></li>\n<li><a href=\"https://github.com/bgoonz/python-scripts\">https://github.com/bgoonz/python-scripts</a></li>\n<li><a href=\"https://github.com/bgoonz/PYTHON_PRAC\">https://github.com/bgoonz/PYTHON_PRAC</a></li>\n<li><a href=\"https://github.com/bgoonz/random-list-of-embedable-content\">https://github.com/bgoonz/random-list-of-embedable-content</a></li>\n<li><a href=\"https://hub.com/bgoonz/random-static-html-page-deploy\">https://hub.com/bgoonz/random-static-html-page-deploy</a></li>\n<li><a href=\"https://hub.com/bgoonz/React-movie-app\">https://hub.com/bgoonz/React-movie-app</a></li>\n<li><a href=\"https://hub.com/bgoonz/react-redux-medium-clone\">https://hub.com/bgoonz/react-redux-medium-clone</a></li>\n<li><a href=\"https://hub.com/bgoonz/react-redux-notes-v5\">https://hub.com/bgoonz/react-redux-notes-v5</a></li>\n<li><a href=\"https://hub.com/bgoonz/react-redux-registration-login-example\">https://hub.com/bgoonz/react-redux-registration-login-example</a></li>\n<li><a href=\"https://hub.com/bgoonz/React_Notes_V3\">https://hub.com/bgoonz/React<em>Notes</em>V3</a></li>\n<li><a href=\"https://hub.com/bgoonz/Recursion-Practice-Website\">https://hub.com/bgoonz/Recursion-Practice-Website</a></li>\n<li><a href=\"https://hub.com/bgoonz/Regex-and-Express-JS\">https://hub.com/bgoonz/Regex-and-Express-JS</a></li>\n<li><a href=\"https://hub.com/bgoonz/repo-utils\">https://hub.com/bgoonz/repo-utils</a></li>\n<li><a href=\"https://hub.com/bgoonz/resume-cv-portfolio-samples\">https://hub.com/bgoonz/resume-cv-portfolio-samples</a></li>\n<li><a href=\"https://hub.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering\">https://hub.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering</a></li>\n<li><a href=\"https://hub.com/bgoonz/scope-closure-context\">https://hub.com/bgoonz/scope-closure-context</a></li>\n<li><a href=\"https://hub.com/bgoonz/Shell-Script-Practice\">https://hub.com/bgoonz/Shell-Script-Practice</a></li>\n<li><a href=\"https://hub.com/bgoonz/site-analysis\">https://hub.com/bgoonz/site-analysis</a></li>\n<li><a href=\"https://hub.com/bgoonz/sorting-algorithms\">https://hub.com/bgoonz/sorting-algorithms</a></li>\n<li><a href=\"https://hub.com/bgoonz/sorting-algos\">https://hub.com/bgoonz/sorting-algos</a></li>\n<li><a href=\"https://hub.com/bgoonz/sqlite3-nodejs-demo\">https://hub.com/bgoonz/sqlite3-nodejs-demo</a></li>\n<li><a href=\"https://hub.com/bgoonz/stalk-photos-web-assets\">https://hub.com/bgoonz/stalk-photos-web-assets</a></li>\n<li><a href=\"https://hub.com/bgoonz/Standalone-Metranome\">https://hub.com/bgoonz/Standalone-Metranome</a></li>\n<li><a href=\"https://hub.com/bgoonz/Star-wars-API-Promise-take2\">https://hub.com/bgoonz/Star-wars-API-Promise-take2</a></li>\n<li><a href=\"https://hub.com/bgoonz/Static-Study-Site\">https://hub.com/bgoonz/Static-Study-Site</a></li>\n<li><a href=\"https://hub.com/bgoonz/styling-templates\">https://hub.com/bgoonz/styling-templates</a></li>\n<li><a href=\"https://hub.com/bgoonz/supertemp\">https://hub.com/bgoonz/supertemp</a></li>\n<li><a href=\"https://hub.com/bgoonz/Ternary-converter\">https://hub.com/bgoonz/Ternary-converter</a></li>\n<li><a href=\"https://hub.com/bgoonz/TetrisJS\">https://hub.com/bgoonz/TetrisJS</a></li>\n<li><a href=\"https://hub.com/bgoonz/TexTools\">https://hub.com/bgoonz/TexTools</a></li>\n<li><a href=\"https://hub.com/bgoonz/The-Algorithms\">https://hub.com/bgoonz/The-Algorithms</a></li>\n<li><a href=\"https://hub.com/bgoonz/TRASH\">https://hub.com/bgoonz/TRASH</a></li>\n<li><a href=\"https://hub.com/bgoonz/Triggered-Guitar-Effects-Platform\">https://hub.com/bgoonz/Triggered-Guitar-Effects-Platform</a></li>\n<li><a href=\"https://hub.com/bgoonz/Useful-Snippets-js\">https://hub.com/bgoonz/Useful-Snippets-js</a></li>\n<li><a href=\"https://hub.com/bgoonz/UsefulResourceRepo2.0\">https://hub.com/bgoonz/UsefulResourceRepo2.0</a></li>\n<li><a href=\"https://hub.com/bgoonz/vscode-customized-config\">https://hub.com/bgoonz/vscode-customized-config</a></li>\n<li><a href=\"https://hub.com/bgoonz/vscode-Extension-readmes\">https://hub.com/bgoonz/vscode-Extension-readmes</a></li>\n<li><a href=\"https://hub.com/bgoonz/web-crawler-node\">https://hub.com/bgoonz/web-crawler-node</a></li>\n<li><a href=\"https://hub.com/bgoonz/web-dev-interview-prep-quiz-website\">https://hub.com/bgoonz/web-dev-interview-prep-quiz-website</a></li>\n<li><a href=\"https://hub.com/bgoonz/web-dev-notes-resource-site\">https://hub.com/bgoonz/web-dev-notes-resource-site</a></li>\n<li><a href=\"https://hub.com/bgoonz/web-dev-setup-checker\">https://hub.com/bgoonz/web-dev-setup-checker</a></li>\n<li><a href=\"https://hub.com/bgoonz/WEB-DEV-TOOLS-HUB\">https://hub.com/bgoonz/WEB-DEV-TOOLS-HUB</a></li>\n<li><a href=\"https://hub.com/bgoonz/web-dev-utils-package\">https://hub.com/bgoonz/web-dev-utils-package</a></li>\n<li><a href=\"https://hub.com/bgoonz/WebAudioDaw\">https://hub.com/bgoonz/WebAudioDaw</a></li>\n<li><a href=\"https://hub.com/bgoonz/website\">https://hub.com/bgoonz/website</a></li>\n</ul>"},{"url":"/docs/docs/","relativePath":"docs/docs/index.md","relativeDir":"docs/docs","base":"index.md","name":"index","frontmatter":{"title":"Docs","weight":0,"excerpt":"Documentation","seo":{"title":"Documentation","description":"Documentation","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<h1>My DevDocs Deploy</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://devdecs42.herokuapp.com/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h1>Personal Docs</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bryan-guner.gitbook.io/my-docs/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/job-hunt/\">/job-hunt/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/notes-template/\">/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/\">/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/showcase/\">/showcase/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/\">/blog/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/review/\">/review/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blog-archive/\">/blog/blog-archive/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/my-medium/\">/blog/my-medium/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blogwcomments/\">/blog/blogwcomments/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures/\">/blog/data-structures/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/gallery/\">/docs/gallery/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-for-js-dev/\">/blog/python-for-js-dev/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/platform-docs/\">/blog/platform-docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/sitemap/\">/docs/sitemap/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/me/\">/docs/about/me/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-resources/\">/blog/python-resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/resume/\">/docs/about/resume/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/\">/docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/web-scraping/\">/blog/web-scraping/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/\">/docs/about/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/algo/\">/docs/articles/algo/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/install/\">/docs/articles/install/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/\">/docs/articles/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/gallery/\">/docs/articles/gallery/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/intro/\">/docs/articles/intro/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev/\">/docs/articles/basic-web-dev/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/reading-files/\">/docs/articles/reading-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/writing-files/\">/docs/articles/writing-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/audio/\">/docs/audio/audio/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/projects/\">/docs/content/projects/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/terms/\">/docs/audio/terms/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/\">/docs/faq/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/\">/docs/community/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/resources/\">/docs/articles/resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/\">/docs/content/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-repos/\">/docs/docs/git-repos/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/trouble-shooting/\">/docs/content/trouble-shooting/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/python/\">/docs/articles/python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/clock/\">/docs/interact/clock/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/python/\">/docs/docs/python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/jupyter-notebooks/\">/docs/interact/jupyter-notebooks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/\">/docs/interact/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/contact/\">/docs/faq/contact/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/docs/\">/docs/quick-reference/docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites/\">/docs/interact/other-sites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/new-repo-instructions/\">/docs/quick-reference/new-repo-instructions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/Emmet/\">/docs/quick-reference/Emmet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/installation/\">/docs/quick-reference/installation/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/vscode-themes/\">/docs/quick-reference/vscode-themes/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/createReactApp/\">/docs/react/createReactApp/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2/\">/docs/react/react2/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/\">/docs/quick-reference/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/\">/docs/react/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/\">/docs/tools/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/notes-template/\">/docs/tools/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/more-tools/\">/docs/tools/more-tools/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/plug-ins/\">/docs/tools/plug-ins/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/install/\">/docs/articles/node/install/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/vscode/\">/docs/tools/vscode/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/intro/\">/docs/articles/node/intro/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/nodejs/\">/docs/articles/node/nodejs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/nodevsbrowser/\">/docs/articles/node/nodevsbrowser/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/npm/\">/docs/articles/node/npm/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/reading-files/\">/docs/articles/node/reading-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/writing-files/\">/docs/articles/node/writing-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react-in-depth/\">/docs/react-in-depth/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/article-compilation/\">/docs/articles/article-compilation/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/my-websites/\">/docs/medium/my-websites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/social/\">/docs/medium/social/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/medium-links/\">/docs/medium/medium-links/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/\">/docs/medium/</a></li>\n</ul>"},{"url":"/docs/docs/html-tags/","relativePath":"docs/docs/html-tags.md","relativeDir":"docs/docs","base":"html-tags.md","name":"html-tags","frontmatter":{"title":"HTML Elements","weight":0,"excerpt":"HTML Elements","seo":{"title":"HTML Elements","description":"HTML Elements mdn docs","robots":[],"extra":[]},"template":"docs"},"html":"<p>HTML Elements</p>\n<ol>\n<li>\n<p>A</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a\"><code class=\"language-text\">&lt;a></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/abbr\"><code class=\"language-text\">&lt;abbr></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/acronym\"><code class=\"language-text\">&lt;acronym></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/address\"><code class=\"language-text\">&lt;address></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/applet\"><code class=\"language-text\">&lt;applet></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area\"><code class=\"language-text\">&lt;area></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article\"><code class=\"language-text\">&lt;article></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside\"><code class=\"language-text\">&lt;aside></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio\"><code class=\"language-text\">&lt;audio></code></a></li>\n</ol>\n</li>\n<li>\n<p>B</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/b\"><code class=\"language-text\">&lt;b></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base\"><code class=\"language-text\">&lt;base></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/basefont\"><code class=\"language-text\">&lt;basefont></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdi\"><code class=\"language-text\">&lt;bdi></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdo\"><code class=\"language-text\">&lt;bdo></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bgsound\"><code class=\"language-text\">&lt;bgsound></code></a></del></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/big\"><code class=\"language-text\">&lt;big></code></a></del></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/blink\"><code class=\"language-text\">&lt;blink></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/blockquote\"><code class=\"language-text\">&lt;blockquote></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body\"><code class=\"language-text\">&lt;body></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br\"><code class=\"language-text\">&lt;br></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button\"><code class=\"language-text\">&lt;button></code></a></li>\n</ol>\n</li>\n<li>\n<p>C</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas\"><code class=\"language-text\">&lt;canvas></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption\"><code class=\"language-text\">&lt;caption></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center\"><code class=\"language-text\">&lt;center></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/cite\"><code class=\"language-text\">&lt;cite></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code\"><code class=\"language-text\">&lt;code></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col\"><code class=\"language-text\">&lt;col></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup\"><code class=\"language-text\">&lt;colgroup></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/content\"><code class=\"language-text\">&lt;content></code></a></li>\n</ol>\n</li>\n<li>\n<p>D</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data\"><code class=\"language-text\">&lt;data></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist\"><code class=\"language-text\">&lt;datalist></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dd\"><code class=\"language-text\">&lt;dd></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del\"><code class=\"language-text\">&lt;del></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details\"><code class=\"language-text\">&lt;details></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dfn\"><code class=\"language-text\">&lt;dfn></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog\"><code class=\"language-text\">&lt;dialog></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dir\"><code class=\"language-text\">&lt;dir></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div\"><code class=\"language-text\">&lt;div></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl\"><code class=\"language-text\">&lt;dl></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dt\"><code class=\"language-text\">&lt;dt></code></a></li>\n</ol>\n</li>\n<li>\n<p>E</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em\"><code class=\"language-text\">&lt;em></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a></li>\n</ol>\n</li>\n<li>\n<p>F</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset\"><code class=\"language-text\">&lt;fieldset></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption\"><code class=\"language-text\">&lt;figcaption></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure\"><code class=\"language-text\">&lt;figure></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font\"><code class=\"language-text\">&lt;font></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer\"><code class=\"language-text\">&lt;footer></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form\"><code class=\"language-text\">&lt;form></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frame\"><code class=\"language-text\">&lt;frame></code></a></del></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frameset\"><code class=\"language-text\">&lt;frameset></code></a></del></li>\n</ol>\n</li>\n<li>\n<p>G H</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements\"><code class=\"language-text\">&lt;heading_elements></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head\"><code class=\"language-text\">&lt;head></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header\"><code class=\"language-text\">&lt;header></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hgroup\"><code class=\"language-text\">&lt;hgroup></code></a></del></li>\n<li>[`</li>\n</ol>\n</li>\n</ol>\n<br>\n<br>\n<br>\n<br>\n<p><code class=\"language-text\">](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hr)\n    6. [</code><html>`](<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html\">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html</a>)</p>\n<ol start=\"8\">\n<li>\n<p>I</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i\"><code class=\"language-text\">&lt;i></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img\"><code class=\"language-text\">&lt;img></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input\"><code class=\"language-text\">&lt;input></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins\"><code class=\"language-text\">&lt;ins></code></a></li>\n<li><del><code class=\"language-text\">&lt;isindex></code></del></li>\n</ol>\n</li>\n<li>\n<p>J K</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd\"><code class=\"language-text\">&lt;kbd></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/keygen\"><code class=\"language-text\">&lt;keygen></code></a></li>\n</ol>\n</li>\n<li>\n<p>L</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label\"><code class=\"language-text\">&lt;label></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/legend\"><code class=\"language-text\">&lt;legend></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li\"><code class=\"language-text\">&lt;li></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link\"><code class=\"language-text\">&lt;link></code></a></li>\n<li><del><code class=\"language-text\">&lt;listing></code></del></li>\n</ol>\n</li>\n<li>\n<p>M</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/main\"><code class=\"language-text\">&lt;main></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map\"><code class=\"language-text\">&lt;map></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark\"><code class=\"language-text\">&lt;mark></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/marquee\"><code class=\"language-text\">&lt;marquee></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/menu\"><code class=\"language-text\">&lt;menu></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/menuitem\"><code class=\"language-text\">&lt;menuitem></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta\"><code class=\"language-text\">&lt;meta></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meter\"><code class=\"language-text\">&lt;meter></code></a></li>\n</ol>\n</li>\n<li>\n<p>N</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nav\"><code class=\"language-text\">&lt;nav></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nobr\"><code class=\"language-text\">&lt;nobr></code></a></del></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noframes\"><code class=\"language-text\">&lt;noframes></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript\"><code class=\"language-text\">&lt;noscript></code></a></li>\n</ol>\n</li>\n<li>\n<p>O</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol\"><code class=\"language-text\">&lt;ol></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup\"><code class=\"language-text\">&lt;optgroup></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option\"><code class=\"language-text\">&lt;option></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/output\"><code class=\"language-text\">&lt;output></code></a></li>\n</ol>\n</li>\n<li>\n<p>P</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p\"><code class=\"language-text\">&lt;p></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/param\"><code class=\"language-text\">&lt;param></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture\"><code class=\"language-text\">&lt;picture></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/plaintext\"><code class=\"language-text\">&lt;plaintext></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre\"><code class=\"language-text\">&lt;pre></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress\"><code class=\"language-text\">&lt;progress></code></a></li>\n</ol>\n</li>\n<li>\n<p>Q</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q\"><code class=\"language-text\">&lt;q></code></a></li>\n</ol>\n</li>\n<li>\n<p>R</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rp\"><code class=\"language-text\">&lt;rp></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rt\"><code class=\"language-text\">&lt;rt></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rtc\"><code class=\"language-text\">&lt;rtc></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby\"><code class=\"language-text\">&lt;ruby></code></a></li>\n</ol>\n</li>\n<li>\n<p>S</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/s\"><code class=\"language-text\">&lt;s></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/samp\"><code class=\"language-text\">&lt;samp></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script\"><code class=\"language-text\">&lt;script></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section\"><code class=\"language-text\">&lt;section></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select\"><code class=\"language-text\">&lt;select></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/shadow\"><code class=\"language-text\">&lt;shadow></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot\"><code class=\"language-text\">&lt;slot></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/small\"><code class=\"language-text\">&lt;small></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source\"><code class=\"language-text\">&lt;source></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/spacer\"><code class=\"language-text\">&lt;spacer></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span\"><code class=\"language-text\">&lt;span></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strike\"><code class=\"language-text\">&lt;strike></code></a></del></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strong\"><code class=\"language-text\">&lt;strong></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style\"><code class=\"language-text\">&lt;style></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub\"><code class=\"language-text\">&lt;sub></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary\"><code class=\"language-text\">&lt;summary></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup\"><code class=\"language-text\">&lt;sup></code></a></li>\n</ol>\n</li>\n<li>\n<p>T</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table\"><code class=\"language-text\">&lt;table></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody\"><code class=\"language-text\">&lt;tbody></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td\"><code class=\"language-text\">&lt;td></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template\"><code class=\"language-text\">&lt;template></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea\"><code class=\"language-text\">&lt;textarea></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tfoot\"><code class=\"language-text\">&lt;tfoot></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th\"><code class=\"language-text\">&lt;th></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/thead\"><code class=\"language-text\">&lt;thead></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time\"><code class=\"language-text\">&lt;time></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title\"><code class=\"language-text\">&lt;title></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr\"><code class=\"language-text\">&lt;tr></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track\"><code class=\"language-text\">&lt;track></code></a></li>\n<li><del><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tt\"><code class=\"language-text\">&lt;tt></code></a></del></li>\n</ol>\n</li>\n<li>\n<p>U</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/u\"><code class=\"language-text\">&lt;u></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul\"><code class=\"language-text\">&lt;ul></code></a></li>\n</ol>\n</li>\n<li>\n<p>V</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/var\"><code class=\"language-text\">&lt;var></code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a></li>\n</ol>\n</li>\n<li>\n<p>W</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/wbr\"><code class=\"language-text\">&lt;wbr></code></a></li>\n</ol>\n</li>\n</ol>"},{"url":"/docs/docs/privacy-policy/","relativePath":"docs/docs/privacy-policy.md","relativeDir":"docs/docs","base":"privacy-policy.md","name":"privacy-policy","frontmatter":{"title":"Privacy Policy","weight":0,"excerpt":"Privacy Policy","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PRIVACY NOTICE</code></pre></div>\n<ul>\n<li>Visit our website at <a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a></li>\n</ul>\n<!---->\n<ul>\n<li>Use our Facebook application — <a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a></li>\n</ul>\n<!---->\n<ul>\n<li>Engage with us in other related ways ― including any sales, marketing, or events</li>\n</ul>\n<!---->\n<ul>\n<li>\"<strong>Website</strong>,\" we are referring to any website of ours that references or links to this policy</li>\n</ul>\n<!---->\n<ul>\n<li>\"<strong>App</strong>,\" we are referring to any application of ours that references or links to this policy, including any listed above</li>\n</ul>\n<!---->\n<ul>\n<li>\"<strong>Services</strong>,\" we are referring to our Website, App, and other related services, including any sales, marketing, or events</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To facilitate account creation and logon process.</strong> If you choose to link your account with us to a third-party account (such as your Google or Facebook account), we use the information you allowed us to collect from those third parties to facilitate account creation and logon process for the performance of the contract.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To post testimonials.</strong> We post testimonials on our Services that may contain personal information. Prior to posting a testimonial, we will obtain your consent to use your name and the content of the testimonial. If you wish to update, or delete your testimonial, please contact us at __________ and be sure to include your name, testimonial location, and contact information.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Request feedback.</strong>  We may use your information to request feedback and to contact you about your use of our Services.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To enable user-to-user communications.</strong> We may use your information in order to enable user-to-user communications with each user's consent.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To manage user accounts.</strong>  We may use your information for the purposes of managing our account and keeping it in working order.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To send administrative information to you.</strong>  We may use your personal information to send you product, service and new feature information and/or information about changes to our terms, conditions, and policies.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To protect our Services.</strong>  We may use your information as part of our efforts to keep our Services safe and secure (for example, for fraud monitoring and prevention).</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To enforce our terms, conditions and policies for business purposes, to comply with legal and regulatory requirements or in connection with our contract.</strong></li>\n</ul>\n<!---->\n<ul>\n<li><strong>To respond to legal requests and prevent harm.</strong>  If we receive a subpoena or other legal request, we may need to inspect the data we hold to determine how to respond.</li>\n<li></li>\n<li><strong>Fulfill and manage your orders.</strong> We may use your information to fulfill and manage your orders, payments, returns, and exchanges made through the Services.</li>\n<li></li>\n<li><strong>Administer prize draws and competitions.</strong> We may use your information to administer prize draws and competitions when you elect to participate in our competitions.</li>\n<li><strong>To deliver and facilitate delivery of services to the user.</strong> We may use your information to provide you with the requested service.</li>\n<li><strong>To respond to user inquiries/offer support to users.</strong> We may use your information to respond to your inquiries and solve any potential issues you might have with the use of our Services.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>To send you marketing and promotional communications.</strong> We and/or our third-party marketing partners may use the personal information you send to us for our marketing purposes, if this is in accordance with your marketing preferences. For example, when expressing an interest in obtaining information about us or our Services, subscribing to marketing or otherwise contacting us, we will collect personal information from you. You can opt-out of our marketing emails at any time (see the \"<a href=\"https://cdpn.io/bgoonz/fullpage/LYLJZrW#privacyrights\">WHAT ARE YOUR PRIVACY RIGHTS?</a>\" below).</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Deliver targeted advertising to you.</strong> We may use your information to develop and display personalized content and advertising (and work with third parties who do so) tailored to your interests and/or location and to measure its effectiveness.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Consent:</strong> We may process your data if you have given us specific consent to use your personal information for a specific purpose.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Legitimate Interests:</strong> We may process your data when it is reasonably necessary to achieve our legitimate business interests.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Performance of a Contract:</strong> Where we have entered into a contract with you, we may process your personal information to fulfill the terms of our contract.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Legal Obligations:</strong> We may disclose your information where we are legally required to do so in order to comply with applicable law, governmental requests, a judicial proceeding, court order, or legal process, such as in response to a court order or a subpoena (including in response to public authorities to meet national security or law enforcement requirements).</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Vital Interests:</strong> We may disclose your information where we believe it is necessary to investigate, prevent, or take action regarding potential violations of our policies, suspected fraud, situations involving potential threats to the safety of any person and illegal activities, or as evidence in litigation in which we are involved.</li>\n</ul>\n<!---->\n<ul>\n<li><strong>Business Transfers.</strong> We may share or transfer your information in connection with, or during negotiations of, any merger, sale of company assets, financing, or acquisition of all or a portion of our business to another company.</li>\n</ul>\n<!---->\n<ul>\n<li>Receiving help through our customer support channels;</li>\n</ul>\n<!---->\n<ul>\n<li>Participation in customer surveys or contests; and</li>\n</ul>\n<!---->\n<ul>\n<li>Facilitation in the delivery of our Services and to respond to your inquiries.</li>\n</ul>\n<!---->\n<ul>\n<li>whether we collect and use your personal information;</li>\n</ul>\n<!---->\n<ul>\n<li>the categories of personal information that we collect;</li>\n</ul>\n<!---->\n<ul>\n<li>the purposes for which the collected personal information is used;</li>\n</ul>\n<!---->\n<ul>\n<li>whether we sell your personal information to third parties;</li>\n</ul>\n<!---->\n<ul>\n<li>the categories of personal information that we sold or disclosed for a business purpose;</li>\n</ul>\n<!---->\n<ul>\n<li>the categories of third parties to whom the personal information was sold or disclosed for a business purpose; and</li>\n</ul>\n<!---->\n<ul>\n<li>the business or commercial purpose for collecting or selling personal information.</li>\n</ul>\n<!---->\n<ul>\n<li>you may object to the processing of your personal data</li>\n</ul>\n<!---->\n<ul>\n<li>you may request correction of your personal data if it is incorrect or no longer relevant, or ask to restrict the processing of the data</li>\n</ul>\n<!---->\n<ul>\n<li>you can designate an authorized agent to make a request under the CCPA on your behalf. We may deny a request from an authorized agent that does not submit proof that they have been validly authorized to act on your behalf in accordance with the CCPA.</li>\n</ul>\n<!---->\n<ul>\n<li>you may request to opt-out from future selling of your personal information to third parties. Upon receiving a request to opt-out, we will act upon the request as soon as feasibly possible, but no later than 15 days from the date of the request submission.</li>\n</ul>"},{"url":"/docs/docs/node-docs-complete/","relativePath":"docs/docs/node-docs-complete.md","relativeDir":"docs/docs","base":"node-docs-complete.md","name":"node-docs-complete","frontmatter":{"title":"Node Docs","weight":0,"excerpt":"Node Docs","seo":{"title":"Node Docs","description":"The API reference documentation provides detailed information about a function or object in Node.js. This documentation indicates what arguments a method accepts, the return value of that method, and what errors may be related to that method. It also indicates which methods are available for different versions of Node.js.","robots":[],"extra":[]},"template":"docs"},"html":"<h3><a href=\"https://nodejs.org/en/\">Node.js</a></h3>\n<h4><a href=\"https://gist.github.com/bgoonz/5715a458f0a0fcdc1a49fbecd07baef3\">Full Documentation</a></h4>"},{"url":"/docs/ds-algo/ds-by-example/","relativePath":"docs/ds-algo/ds-by-example.md","relativeDir":"docs/ds-algo","base":"ds-by-example.md","name":"ds-by-example","frontmatter":{"title":"Data Structures By Example","weight":0,"excerpt":"Algorithm is a fancy name for step-by-step sets of operations to be performed","seo":{"title":" Data Structures By Example","description":"Essentially, Data Structures are different methods of storing and organizing data tha serve a number of different needs.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Data Structures</h1>\n<details>\n<summary>All Code From This Writeup</summary>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token string\">\"use strict\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">List</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>address<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n \n  <span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> lastAddress <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> value <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>lastAddress<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>lastAddress<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> value<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> previous <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> address <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> address<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> previous<span class=\"token punctuation\">;</span>\n      previous <span class=\"token operator\">=</span> current<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> previous<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> value <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> address <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> address<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> value<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">HashTable</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">hashKey</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> index <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> index <span class=\"token operator\">&lt;</span> key<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> index<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">let</span> code <span class=\"token operator\">=</span> key<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      hash <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>hash <span class=\"token operator\">&lt;&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> hash <span class=\"token operator\">+</span> code<span class=\"token punctuation\">)</span> <span class=\"token operator\">|</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> hash<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">hashKey</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">set</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">hashKey</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">hashKey</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Stack</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">peek</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Queue</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">dequeue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">peek</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Graph</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>nodes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">addNode</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>nodes<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n      value<span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">lines</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">find</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>nodes<span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> node<span class=\"token punctuation\">.</span>value <span class=\"token operator\">===</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">addLine</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">startValue<span class=\"token punctuation\">,</span> endValue</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> startNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span>startValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> endNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span>endValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>startNode <span class=\"token operator\">||</span> <span class=\"token operator\">!</span>endNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Both nodes need to exist\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    startNode<span class=\"token punctuation\">.</span>lines<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>endNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">LinkedList</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>position<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>position <span class=\"token operator\">>=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Position outside of list range\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> index <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> index <span class=\"token operator\">&lt;</span> position<span class=\"token punctuation\">;</span> index<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> current<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value<span class=\"token punctuation\">,</span> position</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n      value<span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>position <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      node<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">let</span> prev <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>position <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> prev<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n      node<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> current<span class=\"token punctuation\">;</span>\n      prev<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">position</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Removing from empty list\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>position <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">let</span> prev <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>position <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      prev<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> prev<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Tree</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      node<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span>walk<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value<span class=\"token punctuation\">,</span> parentValue</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> newNode <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n      value<span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> newNode<span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>value <span class=\"token operator\">===</span> parentValue<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        node<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>newNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">BinarySearchTree</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">contains</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>current<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">></span> current<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">&lt;</span> current<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> value<span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">left</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">right</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">></span> current<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>current<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          current<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">&lt;</span> current<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>current<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          current<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  List<span class=\"token punctuation\">,</span>\n  HashTable<span class=\"token punctuation\">,</span>\n  Stack<span class=\"token punctuation\">,</span>\n  Queue<span class=\"token punctuation\">,</span>\n  Graph<span class=\"token punctuation\">,</span>\n  LinkedList<span class=\"token punctuation\">,</span>\n  Tree<span class=\"token punctuation\">,</span>\n  BinarySearchTree<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2></details></h2>\n<h2>Data Structures By Example?</h2>\n<ul>\n<li>Essentially, they are different methods of storing and organizing data tha serve a number of different needs.</li>\n<li>Data can always be represented in many different ways. However, depending on</li>\n<li>what that data is and what you need to do with it, one representation will</li>\n<li>be a better choice than the others.</li>\n<li>To understand why let's first talk a bit about algorithms.</li>\n</ul>\n<hr>\n<h3>ALGORITHMS</h3>\n<hr>\n<hr>\n<h4>Algorithm is a fancy name for step-by-step sets of operations to be performed</h4>\n<ul>\n<li>Data structures are implemented with algorithms, and algorithms are</li>\n<li>implemented with data structures. It's data structures and algorithms all the way down until you reach the microscopic people with punch cards that control the computer. (That's how computers work right?)</li>\n<li>Any given task can be implemented in an infinite number of ways. So for common tasks there are often many different algorithms that people have come up with.</li>\n<li>For example, there are an absurd number of algorithms for sorting a set of unordered items:</li>\n<li>Insertion Sort, Selection Sort, Merge Sort, Bubble Sort, Heap Sort,</li>\n<li>Quick Sort, Shell Sort, Timsort, Bucket Sort, Radix Sort, ...</li>\n<li>Some of these are significantly faster than others. Some use less memory.</li>\n<li>Some are easy to implement. Some are based on assumptions about the dataset.</li>\n<li>Every single one of them will be better for <em>something</em>. So you'll need to</li>\n<li>make a decision based on what your needs are and for that, you'll need a way</li>\n<li>of comparing them, a way to measure them.</li>\n<li>When we compare the performance of algorithms we use a rough measurement of</li>\n<li>their average and worst-case performance using something called \"Big-O\".</li>\n</ul>\n<hr>\n<h2>BIG-O NOTATION</h2>\n<hr>\n<h3>Big-O Notation is a way of roughly measuring the performance of algorithms</h3>\n<ul>\n<li>in order to compare one against another when discussing them.</li>\n<li>Big-O is a mathematical notation that we borrowed in computer science to</li>\n<li>classify algorithms by how they respond to the number (N) of items that you</li>\n<li>give them.</li>\n<li>There are two primary things that you measure with Big-O:</li>\n<li><strong>Time complexity</strong> refers to the total count of operations an algorithm</li>\n<li>will perform given a set of items.</li>\n<li><strong>Space complexity</strong> refers to the total memory an algorithm will take up</li>\n<li>while running given a set of items.</li>\n<li>We measure these independently from one another because while an algorithm</li>\n<li>may perform fewer operations than another, it may also take up way more</li>\n<li>memory. Depending on what your requirements are, one may be a better choice</li>\n<li>than the other.</li>\n<li>These are some common Big-O's:\n| Name         | Notation   | How you feel when they show up at your party |\n|--------------|------------|----------------------------------------------|\n| Constant     | O(1)       | AWESOME!!                                    |\n| Logarithmic  | O(log N)   | GREAT!                                       |\n| Linear       | O(N)       | OKAY.                                        |\n| Linearithmic | O(N log N) | UGH...                                       |\n| Polynomial   | O(N ^ 2)   | SHITTY                                       |\n| Exponential  | O(2 ^ N)   | HORRIBLE                                     |\n| Factorial    | O(N!)      | WTF                                          |</li>\n<li>To give you an idea of how many operations we're talking about. Let's look</li>\n<li>at what these would equal given the (N) number of items.\n| N=5        | 10        | 20        | 30             |\n| ---------- | --------- | --------- | -------------- |\n| O(1)       | 1         | 1         | 1              | 1                                           |\n| O(log N)   | 2.3219... | 3.3219... | 4.3219...      | 4.9068...                                   |\n| O(N)       | 5         | 10        | 20             | 30                                          |\n| O(N log N) | 11.609... | 33.219... | 84.638...      | 147.204...                                  |\n| O(N ^ 2)   | 25        | 100       | 400            | 900                                         |\n| O(2 ^ N)   | 32        | 1024      | 1,048,576      | 1,073,741,824                               |\n| O(N!)      | 120       | 3,628,800 | 2,432,902,0... | 265,252,859,812,191,058,636,308,480,000,000 |</li>\n<li>As you can see, even for relatively small sets of data you could do</li>\n<li>a <strong>lot</strong> of extra work.</li>\n<li>With data structures, you can perform 4 primary types of actions:</li>\n<li>Accessing, Searching, Inserting, and Deleting.</li>\n<li>It is important to note that data structures may be good at one action but</li>\n<li>bad at another.</li>\n</ul>\n<hr>\n<h4>Comparison</h4>\n<table>\n<thead>\n<tr>\n<th>Accessing</th>\n<th>Searching</th>\n<th>Inserting</th>\n<th>Deleting</th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Array</td>\n<td>O(1)</td>\n<td>O(N)</td>\n<td>O(N)</td>\n<td>O(N)</td>\n</tr>\n<tr>\n<td>L-List</td>\n<td>O(N)</td>\n<td>O(N)</td>\n<td>O(1)</td>\n<td>O(1)</td>\n</tr>\n<tr>\n<td>BST</td>\n<td>O(log N)</td>\n<td>O(log N)</td>\n<td>O(log N)</td>\n<td>O(log N)</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>Or rather...</li>\n<li>Accessing Searching Inserting Deleting</li>\n</ul>\n<hr>\n<h4>Array AWESOME!! OKAY OKAY OKAY</h4>\n<ul>\n<li>Linked List OKAY OKAY AWESOME!! AWESOME!!</li>\n<li>Binary Search Tree GREAT! GREAT! GREAT! GREAT!</li>\n<li>Even further, some actions will have a different \"average\" performance and a</li>\n<li>\"worst case scenario\" performance.</li>\n<li>There is no perfect data structure, and you choose one over another based on</li>\n<li>the data that you are working with and the things you are going to do with</li>\n<li>it. This is why it is important to know a number of different common data</li>\n<li>structures so that you can choose from them.</li>\n</ul>\n<hr>\n<h2>MEMORY</h2>\n<hr>\n<h3>A computer's memory is pretty boring, it's just a bunch of ordered slots</h3>\n<ul>\n<li>where you can store information. You hold onto memory addresses in order to</li>\n<li>find information.</li>\n<li>Let's imagine a chunk of memory like this:</li>\n<li>Values: |1001|0110|1000|0100|0101|1010|0010|0001|1101|1011...</li>\n<li>Addresses: 0 1 2 3 4 5 6 7 8 9 ...</li>\n<li>If you've ever wondered why things are zero-indexed in programming languages</li>\n<li>before, it is because of the way that memory works. If you want to read the</li>\n<li>first chunk of memory you read from 0 to 1, the second you read from 1 to 2.</li>\n<li>So the address that you hold onto for each of those is 0 and 1 respectively.</li>\n<li>Your computer has much much more memory than this, and it is all just a</li>\n<li>continuation of the pattern above.</li>\n<li>Memory is a bit like the wild west, every program running on your machine is</li>\n<li>stored within this same <em>physical</em> data structure. Without layers of</li>\n<li>abstraction over it, it would be extremely difficult to use.</li>\n<li>But these abstractions serve two additional purposes:</li>\n<li>Storing data in memory in a way that is more efficient and/or faster to</li>\n<li>work with.</li>\n<li>Storing data in memory in a way that makes it easier to use.</li>\n</ul>\n<hr>\n<h2>LISTS</h2>\n<hr>\n<h3>To demonstrate the raw interaction between memory and a data structure we're</h3>\n<ul>\n<li>going to first implement a list.</li>\n<li>A list is a representation of an ordered sequence of values where the same</li>\n<li>value may appear many times.</li>\n</ul>\n<hr>\n<p>class List {</p>\n<ul>\n<li>We start with an empty block of memory which we are going to represent</li>\n<li>with a normal JavaScript array and we'll store the length of the list.</li>\n<li>-</li>\n<li>Note that we want to store the length separately because in real life the</li>\n<li>\"memory\" doesn't have a length you can read from.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>First we need a way to retrieve data from our list.</li>\n<li>With a plain list, you have very fast memory access because you keep track</li>\n<li>of the address directly.</li>\n<li>List access is constant O(1) * \"AWESOME!!\"</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>address<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Because lists have an order you can insert stuff at the start, middle,</li>\n<li>or end of them.</li>\n<li>For our implementation, we're going to focus on adding and removing values</li>\n<li>at the start or end of our list with these four methods:</li>\n<li>Push * Add value to the end</li>\n<li>Pop * Remove a value from the end</li>\n<li>Unshift * Add value to the start</li>\n<li>Shift * Remove a value from the start</li>\n</ul>\n<hr>\n<blockquote>\n<p>Starting with \"push\" we need a way to add items to the end of the list.</p>\n</blockquote>\n<ul>\n<li>It is as simple as adding a value in the address after the end of our</li>\n<li>list. Because we store the length this is easy to calculate. We just add</li>\n<li>the value and increment our length.</li>\n<li>Pushing an item to the end of a list is constant O(1) * \"AWESOME!!\"</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Next we need a way to \"pop\" items off of the end of our list.</li>\n<li>Similar to push all we need to do is remove the value at the address at</li>\n<li>the end of our list. Then just decrement length.</li>\n<li>Popping an item from the end of a list is constant O(1) * \"AWESOME!!\"</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Don't do anything if we don't have any items.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Get the last value, stop storing it, and return it.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> lastAddress <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> value <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>lastAddress<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>lastAddress<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p>Also return the value so it can be used.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">return</span> value<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>\"push\" and \"pop\" both operate on the end of a list, and overall are pretty</li>\n<li>simple operations because they don't need to be concerned with the rest of</li>\n<li>the list.</li>\n<li>Let's see what happens when we operate at the beginning of the list with</li>\n<li>\"unshift\" and \"shift\".</li>\n</ul>\n<hr>\n<h4>In order to add a new item at the beginning of our list, we need to make</h4>\n<ul>\n<li>room for our value at the start by sliding all of the values over by one.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token operator\">*</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">,</span> d<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">]</span>\n  <span class=\"token operator\">*</span>  <span class=\"token number\">0</span>  <span class=\"token number\">1</span>  <span class=\"token number\">2</span>  <span class=\"token number\">3</span>  <span class=\"token number\">4</span>\n  <span class=\"token operator\">*</span>   ⬊  ⬊  ⬊  ⬊  ⬊\n  <span class=\"token operator\">*</span>  <span class=\"token number\">1</span>  <span class=\"token number\">2</span>  <span class=\"token number\">3</span>  <span class=\"token number\">4</span>  <span class=\"token number\">5</span>\n  <span class=\"token operator\">*</span> <span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">,</span> d<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>In order to slide all of the items over we need to iterate over each one</li>\n<li>moving the prev value over.</li>\n<li>Because we have to iterate over every single item in the list:</li>\n<li>Unshifting an item to the start of a list is linear O(N) * \"OKAY.\"</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Store the value we are going to add to the start.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> previous <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Iterate through each item...</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> address <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> address<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>replacing the \"current\" value with the \"previous\" value and storing the</p>\n<blockquote>\n<p>\"current\" value for the next iteration.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> previous<span class=\"token punctuation\">;</span>\n   previous <span class=\"token operator\">=</span> current<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Add the last item in a new position at the end of the list.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> previous<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>// Finally, we need to write a shift function to move in the opposite</li>\n<li>direction.</li>\n<li>We delete the first value and then slide through every single item in the</li>\n<li>list to move it down one address.</li>\n<li>[x, a, b, c, d, e]</li>\n<li>1 2 3 4 5</li>\n<li>⬋ ⬋ ⬋ ⬋ ⬋</li>\n<li>0 1 2 3 4</li>\n<li>[a, b, c, d, e]</li>\n<li>Shifting an item from the start of a list is linear O(N) * \"OKAY.\"</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Don't do anything if we don't have any items.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> value <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Iterate through each item...</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> address <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> address<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>and replace them with the next item in the list.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Delete the last item since it is now in the previous address.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">return</span> value<span class=\"token punctuation\">;</span>\n <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h4>Lists are great for fast access and dealing with items at the end. However</h4>\n<ul>\n<li>as we've seen it isn't great at dealing with items not at the end of the</li>\n<li>list and we have to manually hold onto memory addresses.</li>\n<li>So let's take a look at a different data structure and how it deals with</li>\n<li>adding, accessing, and removing values without needing to know memory</li>\n<li>addresses.</li>\n</ul>\n<hr>\n<h2>HASH TABLES</h2>\n<hr>\n<ul>\n<li>A hash table is a data structure that's <em>unordered</em>. Instead we have \"keys\" and \"values\" where we</li>\n<li>computed an address in memory using the key.</li>\n<li>The basic idea is that we have keys that are \"hashable\" (which we'll get to</li>\n<li>in a second) and can be used to add, access, and remove from memory very</li>\n<li>efficiently.</li>\n<li>var hashTable = new HashTable();</li>\n<li>hashTable.set('myKey', 'myValue');</li>\n<li>hashTable.get('myKey');</li>\n</ul>\n<blockquote>\n<blockquote>\n<p>'myValue'</p>\n</blockquote>\n</blockquote>\n<hr>\n<p>class HashTable {</p>\n<ul>\n<li>Again we're going to use a plain JavaScript array to represent our memory.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>In order to store key-value pairs in memory from our hash table we need a</li>\n<li>way to take the key and turn it into an address. We do this through an</li>\n<li>operation known as \"hashing\".</li>\n<li>Basically it takes a key and serializes it into a unique number for that</li>\n<li>key.</li>\n<li>hashKey(\"abc\") => 96354</li>\n<li>hashKey(\"xyz\") => 119193</li>\n<li>You have to be careful though, if you had a really big key you don't want</li>\n<li>to match it to a memory address that does not exist.</li>\n<li>So the hashing algorithm needs to limit the size, which means that there</li>\n<li>are a limited number of addresses for an unlimited number of values.</li>\n<li>The result is that you can end up with collisions. Places where two keys</li>\n<li>get turned into the same address.</li>\n<li>Any real-world hash table implementation would have to deal with this,</li>\n<li>however, we are just going to glaze over it and pretend that doesn't happen.</li>\n</ul>\n<hr>\n<h3>Let's set up our \"hashKey\" function</h3>\n<ul>\n<li>Don't worry about understanding the logic of this function, just know that</li>\n<li>it accepts a string and outputs a (mostly) unique address that we will use</li>\n<li>in all of our other functions.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">hashKey</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> index <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> index <span class=\"token operator\">&lt;</span> key<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> index<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>//Oh look*magic.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">let</span> code <span class=\"token operator\">=</span> key<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhash <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>hash <span class=\"token operator\">&lt;&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token operator\">*</span> hash<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> code <span class=\"token operator\">|</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> hash<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Next, let's define our \"get\" function so we have a way of accessing values</li>\n<li>by their key.</li>\n<li>HashTable access is constant O(1) * \"AWESOME!!\"</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<hr>\n<h4>We start by turning our key into an address</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">hashKey</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// then we simply return whatever is at that address.</span>\n<span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>}</p>\n<ul>\n<li>We also need a way of adding data before we access it, so we will create</li>\n<li>a \"set\" function that inserts values.</li>\n<li>HashTable setting is constant O(1) * \"AWESOME!!\"</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">set</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Again we start by turning the key into an address.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n    <span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">hashKey</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n\n\n <span class=\"token comment\">// then just set the value at that address.</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n\n<span class=\"token operator\">*</span> <span class=\"token comment\">// Finally we just need a way to remove items from our hash table.</span></code></pre></div>\n<ul>\n<li>HashTable deletion is constant O(1) * \"AWESOME!!\"</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>As always, we hash the key to get an address.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n    <span class=\"token keyword\">let</span> address <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">hashKey</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n <span class=\"token comment\">// then, if it exists, we `delete` it.</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>memory<span class=\"token punctuation\">[</span>address<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h4>From this point going forward we are going to stop interacting directly with</h4>\n<ul>\n<li>memory as the rest of these data structures start to be implemented with</li>\n<li>other data structures.</li>\n<li>These data structures focus on doing two things:</li>\n<li>Organizing data based on how it is used</li>\n<li>Abstracting away implementation details</li>\n<li>These data structures focus on creating an organization that makes sense for</li>\n<li>various types of programs. They insert a language that allows you to discuss</li>\n<li>more complicated logic. All of this while abstracting away implementation</li>\n<li>details so that their implementation can change to be made faster.</li>\n</ul>\n<hr>\n<h2>STACKS</h2>\n<hr>\n<h3>Stacks are similar to lists in that they have an order, but they limit you</h3>\n<ul>\n<li>to only pushing and popping values at the end of the list, which as we saw</li>\n<li>before are very fast operations when mapping directly to memory.</li>\n<li>However, Stacks can also be implemented with other data structures in order</li>\n<li>to add functionality to them.</li>\n<li>The most common usage of the stacks is in the places where you have one process adding</li>\n<li>items to the stack and another process removing them from the end-</li>\n<li>prioritizing items added most recently.</li>\n</ul>\n<hr>\n<p>class Stack {</p>\n<ul>\n<li>We're going to again be backed by a JavaScript array, but this time it</li>\n<li>represents a list like we implemented before rather than memory.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>We're going to implement two of the functions from list's \"push\" and \"pop\"</li>\n<li>which are going to be identical in terms of functionality.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n####  Push to add items to the top <span class=\"token keyword\">of</span> the stack<span class=\"token punctuation\">.</span>\n\n<span class=\"token operator\">--</span><span class=\"token operator\">-</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n <span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>And pop to remove items from the top of the stack.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Don't do anything if we don't have any items.\nif (this.length === 0) return;</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n Pop the last item off the end <span class=\"token keyword\">of</span> the list and <span class=\"token keyword\">return</span> the value<span class=\"token punctuation\">.</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>We're also going to add a function in order to view the item at the top of</li>\n<li>the stack without removing it from the stack.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">peek</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Return the last item in \"items\" without removing it.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h3>QUEUES</h3>\n<hr>\n<h4>Next, we're going to build a queue which is complementary to stacks. The</h4>\n<ul>\n<li>difference is that this time you remove items from the start of the queue</li>\n<li>rather than the end. Removing the oldest items rather than the most recent.</li>\n<li>Again, because this limits the amount of functionality, there are many</li>\n<li>different ways of implementing it. A good way might be to use a linked list</li>\n<li>which we will see later.</li>\n</ul>\n<hr>\n<p>class Queue {</p>\n<ul>\n<li>Again, our queue is using a JavaScript array as a list rather than memory.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Similar to stacks we're going to define two functions for adding and</li>\n<li>removing items from the queue. The first is \"enqueue\".</li>\n<li>This will push values to the end of the list.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Next is \"dequeue\", instead of removing the item from the end of the list,</li>\n<li>we're going to remove it from the start.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">dequeue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Don't do anything if we don't have any items.\nif (this.length === 0) return;</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n Shift the first item off the start <span class=\"token keyword\">of</span> the list and <span class=\"token keyword\">return</span> the value<span class=\"token punctuation\">.</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Same as stacks we're going to define a \"peek\" function for getting the next</li>\n<li>value without removing it from the queue.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">peek</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h4>The important thing to note here is that because we used a list to back our</h4>\n<ul>\n<li>queue it inherits the performance of \"shift\" which is linear O(N) \"OKAY.\"</li>\n<li>Later we'll see linked lists that will allow us to implement a much faster</li>\n<li>Queue.</li>\n</ul>\n<hr>\n<h4>From this point forward we're going to start dealing with data structures</h4>\n<ul>\n<li>where the values of the data structure reference one another.</li>\n<li>Data Structure</li>\n</ul>\n<hr>\n<ul>\n<li>| Item A</li>\n</ul>\n<hr>\n<ul>\n<li>Item B</li>\n</ul>\n<hr>\n<ul>\n<li>| Value: 1 | | Value: 2 |</li>\n<li>| Reference to: (Item B) | Reference to: (Item A) |</li>\n</ul>\n<hr>\n<hr>\n<ul>\n<li>The values inside the data structure become their own mini data structures</li>\n<li>in that they contain a value along with additional information including</li>\n<li>references to other items within the overall data structure.</li>\n<li>You'll see what I mean by this in a second.</li>\n</ul>\n<hr>\n<h2>GRAPHS</h2>\n<hr>\n<h3>Contrary to the ascii art above, a graph is not a visual chart of some sort</h3>\n<ul>\n<li>Instead imagine it like this:</li>\n<li>A -→ B ←---* C → D ↔ E</li>\n<li>↑ ↕ ↙ ↑ ↘</li>\n<li>F -→ G → H ← I----→ J</li>\n<li>↓ ↘ ↑</li>\n<li>K L</li>\n<li>We have a bunch of \"nodes\" (A, B, C, D, ...) that are connected with lines.</li>\n<li>These nodes are going to look like this:</li>\n<li>Node {</li>\n<li>value: ...,</li>\n<li>lines: [(Node), (Node), ...]</li>\n<li>}</li>\n<li>The entire graph will look like this:</li>\n<li>Graph {</li>\n<li>nodes: [</li>\n<li>Node {...},</li>\n<li>Node {...},</li>\n<li>...</li>\n<li>]</li>\n<li>}</li>\n</ul>\n<hr>\n<p>class Graph {</p>\n<ul>\n<li>We'll hold onto all of our nodes in a regular JavaScript array. Not</li>\n<li>because there is any particular order to the nodes but because we need a</li>\n<li>way to store references to everything.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>nodes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>We can start to add values to our graph by creating nodes without any</li>\n<li>lines.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">addNode</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>nodes<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n   value<span class=\"token punctuation\">,</span>\n   <span class=\"token literal-property property\">lines</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Next we need to be able to lookup nodes in the graph. Most of the time</li>\n<li>you'd have another data structure on top of a graph in order to make</li>\n<li>searching faster.</li>\n<li>But for our case, we're simply going to search through all of the nodes to find</li>\n<li>the one with the matching value. This is a slower option, but it works for</li>\n<li>now.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">find</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>nodes<span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> node<span class=\"token punctuation\">.</span>value <span class=\"token operator\">===</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Next we can connect two nodes by making a \"line\" from one to the other.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">addLine</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">startValue<span class=\"token punctuation\">,</span> endValue</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Find the nodes for each value.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n    <span class=\"token keyword\">let</span> startNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span>startValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> endNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span>endValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n Freak out <span class=\"token keyword\">if</span> we didn't find one or the other<span class=\"token punctuation\">.</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>startNode <span class=\"token operator\">||</span> <span class=\"token operator\">!</span>endNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Both nodes need to exist'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span></code></pre></div>\n<p>And add a reference to the endNode from the startNode.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    startNode<span class=\"token punctuation\">.</span>lines<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>endNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h4>// Finally you can use a graph like this</h4>\n<ul>\n<li>var graph = new Graph();</li>\n<li>graph.addNode(1);</li>\n<li>graph.addNode(2);</li>\n<li>graph.addLine(1, 2);</li>\n<li>var two = graph.find(1).lines[0];</li>\n<li>This might seem like a lot of work to do very little, but it's actually a</li>\n<li>quite powerful pattern, especially for finding sanity in complex programs.</li>\n<li>They do this by optimizing for the connections between data rather than</li>\n<li>operating on the data itself. Once you have one node in the graph, it's</li>\n<li>extremely simple to find all the related items in the graph.</li>\n<li>Tons of things can be represented this way, users with friends, the 800</li>\n<li>transitive dependencies in a node_modules folder, the internet itself is a</li>\n<li>graph of webpages connected together by links.</li>\n</ul>\n<hr>\n<h2>LINKED LISTS</h2>\n<hr>\n<h3>Next we're going to see how a graph-like structure can help optimize ordered</h3>\n<ul>\n<li>lists of data.</li>\n<li>Linked lists are a very common data structure that is often used to</li>\n<li>implement other data structures because of its ability to efficiently add</li>\n<li>items to the start, middle, and end.</li>\n<li>The basic idea of a linked list is similar to a graph. You have nodes that</li>\n<li>point to other nodes. They look sorta like this:</li>\n<li>1 -> 2 -> 3 -> 4 -> 5</li>\n<li>Visualizing them as a JSON-like structure looks like this:</li>\n<li>{</li>\n<li>value: 1,</li>\n<li>next: {</li>\n<li>value: 2,</li>\n<li>next: {</li>\n<li>value: 3,</li>\n<li>next: {...}</li>\n<li>}</li>\n<li>}</li>\n<li>}</li>\n</ul>\n<hr>\n<p>class LinkedList {</p>\n<ul>\n<li>Unlike a graph, a linked list has a single node that starts off the entire</li>\n<li>chain. This is known as the \"head\" of the linked list.</li>\n<li>We're also going to track the length.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>First we need a way to retrieve a value in a given position.</li>\n<li>This works differently than normal lists as we can't just jump to the</li>\n<li>correct position. Instead, we need to move through the individual nodes.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>position<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>Throw an error if position is greater than the length of the LinkedList</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>position <span class=\"token operator\">>=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Position outside of list range\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Start with the head of the list.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Slide through all of the items using node.next until we reach the specified position.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> index <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> index <span class=\"token operator\">&lt;</span> position<span class=\"token punctuation\">;</span> index<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Return the node we found.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">return</span> current<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Next we need a way to add nodes to the specified position.</li>\n<li>We're going for a generic add method that accepts a value and a position.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value<span class=\"token punctuation\">,</span> position</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// First create a node to hold our value.</span>\n\n<span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  value<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h4>We need to have a special case for nodes being inserted at the head</h4>\n<hr>\n<h4>We'll set the \"next\" field to the current head and then replace it with</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n our <span class=\"token keyword\">new</span> <span class=\"token class-name\">node<span class=\"token punctuation\">.</span></span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>position <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   node<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>If we're adding a node in any other position we need to splice it in\nbetween the current node and the previous node.\n} else {\nFirst, find the previous node and the current node.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> prev <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>position <span class=\"token operator\">*</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> prev<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span></code></pre></div>\n<p>// then insert the new node in between them by setting its \"next\" field</p>\n<ul>\n<li>to the current node and updating the previous node's \"next\" field to</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token comment\">// the new one.</span>\n   node<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> current<span class=\"token punctuation\">;</span>\n   prev<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n <span class=\"token comment\">// Finally just increment the length.</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>The last method we need is a remove method. We're just going to look up a</li>\n<li>node by its position and splice it out of the chain.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">position</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<hr>\n<h4>We should not be able to remove from an empty list</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Removing from empty list\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>If we're removing the first node we simply need to set the head to the</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n next node <span class=\"token keyword\">in</span> the chain\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>position <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span></code></pre></div>\n<p>For any other position, we need to look up the previous node and set it</p>\n<ul>\n<li>to the node after the current position.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> prev <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>position <span class=\"token operator\">*</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  prev<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> prev<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// then we just decrement the length.</span>\n   <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h4>The remaining two data structures we are going to cover are both in the</h4>\n<ul>\n<li>\"tree\" family.</li>\n<li>Much like real life, there are many different types of tree data structures.</li>\n<li>Binary Trees:</li>\n<li>AA Tree, AVL Tree, Binary Search Tree, Binary Tree, Cartesian Tree,</li>\n<li>left child/right sibling tree, order statistic tree, Pagoda, ...</li>\n<li>B Trees:</li>\n<li>B Tree, B+ Tree, B* Tree, B Sharp Tree, Dancing Tree, 2-3 Tree, ...</li>\n<li>Heaps:</li>\n<li>Heap, Binary Heap, Weak Heap, Binomial Heap, Fibonacci Heap, Leonardo</li>\n<li>Heap, 2-3 Heap, Soft Heap, Pairing Heap, Leftist Heap, Treap, ...</li>\n<li>Trees:</li>\n<li>Trie, Radix Tree, Suffix Tree, Suffix Array, FM-index, B-trie, ...</li>\n<li>Multi-way Trees:</li>\n<li>Ternary Tree, K-ary tree, And-or tree, (a,b)-tree, Link/Cut Tree, ...</li>\n<li>Space Partitioning Trees:</li>\n<li>Segment Tree, Interval Tree, Range Tree, Bin, Kd Tree, Quadtree,</li>\n<li>Octree, Z-Order, UB-Tree, R-Tree, X-Tree, Metric Tree, Cover Tree, ...</li>\n<li>Application-Specific Trees:</li>\n<li>Abstract Syntax Tree, Parse Tree, Decision Tree, Minimax Tree, ...</li>\n<li>Little did you know you'd be studying dendrology today... and that's not even</li>\n<li>all of them. But don't let any of this scare you, most of those don't matter</li>\n<li>at all. There were just a lot of Computer Science PhDs who had something to</li>\n<li>prove.</li>\n<li>Trees are much like graphs or linked lists except they are \"unidirectional\".</li>\n<li>All this means is that they can't have loops of references.</li>\n<li>Tree: | Not a Tree:</li>\n<li>A | A</li>\n<li>↙ ↘ | ↗ ↘</li>\n<li>B C | B ←---* C</li>\n<li>If you can draw a loop between connected nodes in a tree... well, you don't</li>\n<li>have a tree.</li>\n<li>Trees have many different uses, they can be used to optimize searching or</li>\n<li>sorting. They can organize programs better. They can give you a</li>\n<li>representation that is easier to work with.</li>\n</ul>\n<hr>\n<h2>TREES</h2>\n<h3>We'll start off with an extremely simple tree structure. It doesn't have any</h3>\n<ul>\n<li>special rules to it and looks something like this:</li>\n<li>Tree {</li>\n<li>root: {</li>\n<li>value: 1,</li>\n<li>children: [{</li>\n<li>value: 2,</li>\n<li>children: [...]</li>\n<li>}, {</li>\n<li>value: 3,</li>\n<li>children: [...]</li>\n<li>}]</li>\n<li>}</li>\n<li>}</li>\n</ul>\n<hr>\n<p>class Tree {</p>\n<ul>\n<li>The tree has to start with a single parent, the \"root\" of the tree.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>We need a way to traverse our tree and call a function on each node in the</li>\n<li>tree.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<hr>\n<h4>We'll define a walk function that we can call recursively on every node</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token keyword\">in</span> the tree<span class=\"token punctuation\">.</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">js\n//\n First call the callback on the node.\n   callback(node);\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>js\n<span class=\"token comment\">//</span>\n <span class=\"token comment\">// then recursively call the walk function on all of its children.</span>\n   node<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span>walk<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now kick the traversal process off.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Next we need a way to add nodes to our tree.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value<span class=\"token punctuation\">,</span> parentValue</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> newNode <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n   value<span class=\"token punctuation\">,</span>\n   <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>If there is no root, just set it to the new node.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> newNode<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n Otherwise traverse the entire tree and find a node <span class=\"token keyword\">with</span> a matching value\n\n\n and add the <span class=\"token keyword\">new</span> <span class=\"token class-name\">node</span> to its children<span class=\"token punctuation\">.</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>value <span class=\"token operator\">===</span> parentValue<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n     node<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>newNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h4>This is one of the most basic trees you could have and is probably only</h4>\n<ul>\n<li>useful if the data you are representing actually resembles a tree.</li>\n<li>But with some extra rules, a tree can serve a lot of different purposes.</li>\n</ul>\n<hr>\n<h2>BINARY SEARCH TREES</h2>\n<hr>\n<h3>Binary search trees are a fairly common form of tree for their ability to</h3>\n<ul>\n<li>efficiently access, search, insert, and delete values all while keeping them</li>\n<li>in a sorted order.</li>\n<li>Imagine taking a sequence of numbers:</li>\n<li>1 2 3 4 5 6 7</li>\n<li>And turning it into a tree starting from the center.</li>\n<li>4</li>\n<li>/ \\</li>\n<li>2 6</li>\n<li>/ \\ / \\</li>\n<li>1 3 5 7</li>\n<li>-^--^--^--^--^--^--^-</li>\n<li>1 2 3 4 5 6 7</li>\n<li>\n<p>This is how a binary tree works. Each node can have two children:</p>\n<ul>\n<li>Left: Less than parent node's value.</li>\n<li>Right: Greater than parent node's value.</li>\n</ul>\n</li>\n<li>\n<blockquote>\n<p>Note: In order to make this work all values must be unique in the tree.</p>\n</blockquote>\n</li>\n<li>This makes the traversal to find a value very efficient. Say we're trying to</li>\n<li>find the number 5 in our tree:</li>\n<li>(4) &#x3C;</li>\n</ul>\n<hr>\n<p>5 > 4, so move right.</p>\n<ul>\n<li>/ \\</li>\n<li>2 (6) &#x3C;</li>\n</ul>\n<hr>\n<p>5 &#x3C; 6, so move left.</p>\n<ul>\n<li>/ \\ / \\</li>\n<li>1 3 (5) 7 &#x3C;</li>\n</ul>\n<hr>\n<p>We've reached 5!</p>\n<ul>\n<li>Notice how we only had to do 3 checks to reach the number 5. If we were to</li>\n<li>expand this tree to 1000 items. We'd go:</li>\n<li>500 -> 250 -> 125 -> 62 -> 31 -> 15 -> 7 -> 3 -> 4 -> 5</li>\n<li>Only 10 checks for 1000 items!</li>\n<li>The other important thing about binary search trees is that they are similar</li>\n<li>to linked lists in the sense that you only need to update the immediately</li>\n<li>surrounding items when adding or removing a value.</li>\n</ul>\n<hr>\n<p><code class=\"language-text\">class BinarySearchTree {</code></p>\n<ul>\n<li>Same as the previous Tree, we need to have a \"root\" of the binary search</li>\n<li>tree.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>In order to test if the value exists in the tree, we first need to search</li>\n<li>through the tree.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">contains</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<hr>\n<h4>We start at the root</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h4>We're going to keep running as long as we have another node to visit</h4>\n<ul>\n<li>If we reach a <code class=\"language-text\">left</code> or <code class=\"language-text\">right</code> that is <code class=\"language-text\">null</code> then this loop ends.\n<code class=\"language-text\">while (current) {</code></li>\n<li>If the value is greater than the current.value we move to the right</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">></span> current<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n     current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>If the value is less than the current.value we move to the left.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">&lt;</span> current<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n     current <span class=\"token operator\">=</span> current<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Otherwise we must be equal values and we return true.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>If we haven't matched anything then we return false.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>In order to add items to this tree we are going to do the same traversal</li>\n<li>as before, bouncing between left and right nodes depending on them being</li>\n<li>less than or greater than the value we're adding.</li>\n<li>However, this time when we reach a <code class=\"language-text\">left</code> or <code class=\"language-text\">right</code> that is <code class=\"language-text\">null</code> we're</li>\n<li>going to add a new node in that position.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>First let's setup our node.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> value<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">left</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">right</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Special case for when there isn't any root node and we just need to add one.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h4>We start at the root node</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h4>We're going to loop until we've either added our item or discovered it</h4>\n<p>already exists in the tree.\n<code class=\"language-text\">while (true) {</code></p>\n<ul>\n<li>If the value is greater than the current.value we move to the right.\n<code class=\"language-text\">if (value > current.value) {</code></li>\n<li>If <code class=\"language-text\">right</code> does not exist, set it to our node, and stop traversing.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n     <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>current<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   current<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n     <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Otherwise just move on to the right node.\ncurrent = current.right;</p>\n<ul>\n<li>If the value is less than the current.value we move to the left.\n<code class=\"language-text\">} else if (value &lt; current.value) {</code></li>\n<li>If <code class=\"language-text\">left</code> does not exist, set it to our node, and stop traversing.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n     <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>current<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   current<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n     <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Otherwise just move on to the left node.\ncurrent = current.left;</p>\n<ul>\n<li>If the number isn't less than or greater, then it must be the same and</li>\n</ul>\n<hr>\n<ul>\n<li>We don't do anything.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n     <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h2>YOU REACHED THE END</h2>\n<hr>\n<p>Just exporting everything for the tests...</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  List<span class=\"token punctuation\">,</span>\n  HashTable<span class=\"token punctuation\">,</span>\n  Stack<span class=\"token punctuation\">,</span>\n  Queue<span class=\"token punctuation\">,</span>\n  Graph<span class=\"token punctuation\">,</span>\n  LinkedList<span class=\"token punctuation\">,</span>\n  Tree<span class=\"token punctuation\">,</span>\n  BinarySearchTree<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/docs/ds-algo/data-structures-docs/","relativePath":"docs/ds-algo/data-structures-docs.md","relativeDir":"docs/ds-algo","base":"data-structures-docs.md","name":"data-structures-docs","frontmatter":{"title":"Data Structures Docs","weight":0,"excerpt":"Data Structures Docs","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1><strong>Data Structures</strong> are a specialized means of organizing and storing data in computers in such a way that we can perform operations on the stored data more efficiently. Data structures have a wide and diverse scope of usage across the fields of Computer Science and Software Engineering.Image by author</h1>\n<p><img src=\"https://miro.medium.com/max/473/1*KpDOKMFAgDWaGTQHL0r70g.png\" alt=\"medium blog image\"></p>\n<p>Data structures are being used in almost every program or software system that has been developed. Moreover, data structures come under the fundamentals of Computer Science and Software Engineering. It is a key topic when it comes to Software Engineering interview questions. Hence as developers, we must have good knowledge about data structures.</p>\n<p>In this article, I will be briefly explaining 8 commonly used data structures every programmer must know.</p>\n<p>{% embed url=\"<a href=\"https://replit.com/@bgoonz/DATASTRUCTURES-NOTES%5C#sorting/insertion%5C_sort/insertion.py\">https://replit.com/@bgoonz/DATASTRUCTURES-NOTES\\#sorting/insertion\\_sort/insertion.py</a>\" %}</p>\n<h2>1. Arrays <a id=\"31ab\"></h2>\n</a>\n<p>An <strong>array</strong> is a structure of fixed-size, which can hold items of the same data type. It can be an array of integers, an array of floating-point numbers, an array of strings or even an array of arrays (such as <em>2-dimensional arrays</em>). Arrays are indexed, meaning that random access is possible.<img src=\"https://miro.medium.com/max/60/1*pYIKtQYbX8vgCWrwe1YOyg.png?q=20\" alt=\"medium blog image\">Fig 1. Visualization of basic Terminology of Arrays (Image by author)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*pYIKtQYbX8vgCWrwe1YOyg.png\" alt=\"medium blog image\"></p>\n<h3>Array operations <a id=\"6504\"></h3>\n</a>\n<ul>\n<li><strong>Traverse</strong>: Go through the elements and print them.</li>\n<li><strong>Search</strong>: Search for an element in the array. You can search the element by its value or its index</li>\n<li><strong>Update</strong>: Update the value of an existing element at a given index</li>\n</ul>\n<p><strong>Inserting</strong> elements to an array and <strong>deleting</strong> elements from an array cannot be done straight away as arrays are fixed in size. If you want to insert an element to an array, first you will have to create a new array with increased size (current size + 1), copy the existing elements and add the new element. The same goes for the deletion with a new array of reduced size.</p>\n<h3><strong>Applications of arrays</strong> <a id=\"edcd\"></h3>\n</a>\n<ul>\n<li>Used as the building blocks to build other data structures such as array lists, heaps, hash tables, vectors and matrices.</li>\n<li>Used for different sorting algorithms such as insertion sort, quick sort, bubble sort and merge sort.</li>\n</ul>\n<h2>2. Linked Lists <a id=\"d965\"></h2>\n</a>\n<p>A <strong>linked list</strong> is a sequential structure that consists of a sequence of items in linear order which are linked to each other. Hence, you have to access data sequentially and random access is not possible. Linked lists provide a simple and flexible representation of dynamic sets.</p>\n<p>Let's consider the following terms regarding linked lists. You can get a clear idea by referring to Figure 2.</p>\n<ul>\n<li>Elements in a linked list are known as <strong>nodes</strong>.</li>\n<li>Each node contains a <strong>key</strong> and a pointer to its successor node, known as <strong>next</strong>.</li>\n<li>The attribute named <strong>head</strong> points to the first element of the linked list.</li>\n<li>The last element of the linked list is known as the <strong>tail</strong>.</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*4fuF6lHXOSmoVNcOV8aaJA.png?q=20\" alt=\"medium blog image\">Fig 2. Visualization of basic Terminology of Linked Lists (Image by author)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*4fuF6lHXOSmoVNcOV8aaJA.png\" alt=\"medium blog image\"></p>\n<p>Following are the various types of linked lists available.</p>\n<ul>\n<li><strong>Singly linked list</strong> — Traversal of items can be done in the forward direction only.</li>\n<li><strong>Doubly linked list</strong> — Traversal of items can be done in both forward and backward directions. Nodes consist of an additional pointer known as <strong>prev</strong>, pointing to the previous node.</li>\n<li><strong>Circular linked lists</strong> — Linked lists where the prev pointer of the head points to the tail and the next pointer of the tail points to the head.</li>\n</ul>\n<h3>Linked list operations <a id=\"d683\"></h3>\n</a>\n<ul>\n<li><strong>Search</strong>: Find the first element with the key <strong>k</strong> in the given linked list by a simple linear search and returns a pointer to this element</li>\n<li><strong>Insert</strong>: Insert a key to the linked list. An insertion can be done in 3 different ways; insert at the beginning of the list, insert at the end of the list and insert in the middle of the list.</li>\n<li><strong>Delete</strong>: Removes an element <strong>x</strong> from a given linked list. You cannot delete a node by a single step. A deletion can be done in 3 different ways; delete from the beginning of the list, delete from the end of the list and delete from the middle of the list.</li>\n</ul>\n<h3><strong>Applications of linked lists</strong> <a id=\"1da5\"></h3>\n</a>\n<ul>\n<li>Used for <em>symbol table management</em> in compiler design.</li>\n<li>Used in switching between programs using Alt + Tab (implemented using Circular Linked List).</li>\n</ul>\n<h2>3. Stacks <a id=\"ca20\"></h2>\n</a>\n<p>A <strong>stack</strong> is a <strong>LIFO</strong> (Last In First Out — the element placed at last can be accessed at first) structure which can be commonly found in many programming languages. This structure is named as \"stack\" because it resembles a real-world stack — a stack of plates.Image by [congerdesign](https://pixabay.com/users/congerdesign-509903/?utm<em>source=link-attribution&#x26;utm</em>medium=referral&#x26;utm<em>campaign=image&#x26;utm</em>content=629987) from [Pixabay](https://pixabay.com/?utm<em>source=link-attribution&#x26;utm</em>medium=referral&#x26;utm<em>campaign=image&#x26;utm</em>content=629987)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*e4XWkyzxdOreblbPlbOCyw.jpeg\" alt=\"medium blog image\"></p>\n<h3>Stack operations <a id=\"4b54\"></h3>\n</a>\n<p>Given below are the 2 basic operations that can be performed on a stack. Please refer to Figure 3 to get a better understanding of the stack operations.</p>\n<ul>\n<li><strong>Push</strong>: Insert an element on to the top of the stack.</li>\n<li><strong>Pop</strong>: Delete the topmost element and return it.</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*QMifqahZm4DGQ91GkOhu4g.png?q=20\" alt=\"medium blog image\">Fig 3. Visualization of basic Operations of Stacks (Image by author)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*QMifqahZm4DGQ91GkOhu4g.png\" alt=\"medium blog image\"></p>\n<p>Furthermore, the following additional functions are provided for a stack in order to check its status.</p>\n<ul>\n<li><strong>Peek</strong>: Return the top element of the stack without deleting it.</li>\n<li><strong>isEmpty</strong>: Check if the stack is empty.</li>\n<li><strong>isFull</strong>: Check if the stack is full.</li>\n</ul>\n<h3>Applications of stacks <a id=\"f7fc\"></h3>\n</a>\n<ul>\n<li>Used for expression evaluation (e.g.: <em>shunting-yard algorithm</em> for parsing and evaluating mathematical expressions).</li>\n<li>Used to implement function calls in recursion programming.</li>\n</ul>\n<h2>4. Queues <a id=\"0e94\"></h2>\n</a>\n<p>A <strong>queue</strong> is a <strong>FIFO</strong> (First In First Out — the element placed at first can be accessed at first) structure which can be commonly found in many programming languages. This structure is named as \"queue\" because it resembles a real-world queue — people waiting in a queue.<img src=\"https://miro.medium.com/max/60/1*GbtPRh9OWh1jtCtCa9czIg.jpeg?q=20\" alt=\"medium blog image\">Image by [Sabine Felidae](https://pixabay.com/users/sheadquarters-5187/?utm<em>source=link-attribution&#x26;utm</em>medium=referral&#x26;utm<em>campaign=image&#x26;utm</em>content=50119) from [Pixabay](https://pixabay.com/?utm<em>source=link-attribution&#x26;utm</em>medium=referral&#x26;utm<em>campaign=image&#x26;utm</em>content=50119)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*GbtPRh9OWh1jtCtCa9czIg.jpeg\" alt=\"medium blog image\"></p>\n<h3>Queue operations <a id=\"9bcd\"></h3>\n</a>\n<p>Given below are the 2 basic operations that can be performed on a queue. Please refer to Figure 4 to get a better understanding of the queue operations.</p>\n<ul>\n<li><strong>Enqueue</strong>: Insert an element to the end of the queue.</li>\n<li><strong>Dequeue</strong>: Delete the element from the beginning of the queue.</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*K4-7c0lyUcSGRPmv3_9uqw.png?q=20\" alt=\"medium blog image\">Fig 4. Visualization of Basic Operations of Queues (Image by author)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*K4-7c0lyUcSGRPmv3_9uqw.png\" alt=\"Fig 4. Visualization of Basic Operations of Queues (Image by author)\"></p>\n<h3>Applications of queues <a id=\"07fd\"></h3>\n</a>\n<ul>\n<li>Used to manage threads in multithreading.</li>\n<li>Used to implement queuing systems (e.g.: priority queues).</li>\n</ul>\n<h2>5. Hash Tables <a id=\"4690\"></h2>\n</a>\n<p>A <strong>Hash Table</strong> is a data structure that stores values which have keys associated with each of them. Furthermore, it supports lookup efficiently if we know the key associated with the value. Hence it is very efficient in inserting and searching, irrespective of the size of the data.</p>\n<p><strong>Direct Addressing</strong> uses the one-to-one mapping between the values and keys when storing in a table. However, there is a problem with this approach when there is a large number of key-value pairs. The table will be huge with so many records and may be impractical or even impossible to be stored, given the memory available on a typical computer. To avoid this issue we use <strong>hash tables</strong>.</p>\n<h3>Hash Function <a id=\"9052\"></h3>\n</a>\n<p>A special function named as the <strong>hash function</strong> (<strong>h</strong>) is used to overcome the aforementioned problem in direct addressing.</p>\n<p>In direct accessing, a value with key <strong>k</strong> is stored in the slot <strong>k</strong>. Using the hash function, we calculate the index of the table (slot) to which each value goes. The value calculated using the hash function for a given key is called the <strong>hash value</strong> which indicates the index of the table to which the value is mapped.</p>\n<blockquote>\n<p><strong>h(k) = k % m</strong></p>\n</blockquote>\n<ul>\n<li><strong>h:</strong> Hash function</li>\n<li><strong>k:</strong> Key of which the hash value should be determined</li>\n<li><strong>m:</strong> Size of the hash table (number of slots available). A prime value that is not close to an exact power of 2 is a good choice for <strong>m</strong>.</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*xOmBfzMxLLldy1ll4w7esg.png?q=20\" alt=\"medium blog image\">Fig 5. Representation of a Hash Function (Image by author)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*xOmBfzMxLLldy1ll4w7esg.png\" alt=\"medium blog image\"></p>\n<p>Consider the hash function <strong>h(k) = k % 20</strong>, where the size of the hash table is 20. Given a set of keys, we want to calculate the hash value of each to determine the index where it should go in the hash table. Consider we have the following keys, the hash and the hash table index.</p>\n<ul>\n<li>1 → 1%20 → 1</li>\n<li>5 → 5%20 → 5</li>\n<li>23 → 23%20 → 3</li>\n<li>63 → 63%20 → 3</li>\n</ul>\n<p>From the last two examples given above, we can see that <strong>collision</strong> can arise when the hash function generates the same index for more than one key. We can resolve collisions by selecting a suitable hash function h and use techniques such as <strong>chaining</strong> and <strong>open addressing</strong>.</p>\n<h3>Applications of hash tables <a id=\"0328\"></h3>\n</a>\n<ul>\n<li>Used to implement database indexes.</li>\n<li>Used to implement associative arrays.</li>\n<li>Used to implement the \"set\" data structure.</li>\n</ul>\n<h2>6. Trees <a id=\"1c0f\"></h2>\n</a>\n<p>A <strong>tree</strong> is a hierarchical structure where data is organized hierarchically and are linked together. This structure is different from a linked list whereas, in a linked list, items are linked in a linear order.</p>\n<p>Various types of trees have been developed throughout the past decades, in order to suit certain applications and meet certain constraints. Some examples are binary search tree, B tree, treap, red-black tree, splay tree, AVL tree and n-ary tree.</p>\n<h3>Binary Search Trees <a id=\"ba6b\"></h3>\n</a>\n<p>A <strong>binary search tree (BST)</strong>, as the name suggests, is a binary tree where data is organized in a hierarchical structure. This data structure stores values in sorted order.</p>\n<p>Every node in a binary search tree comprises the following attributes.</p>\n<ol>\n<li><strong>key</strong>: The value stored in the node.</li>\n<li><strong>left</strong>: The pointer to the left child.</li>\n<li><strong>right</strong>: The pointer to the right child.</li>\n<li><strong>p</strong>: The pointer to the parent node.</li>\n</ol>\n<p>A binary search tree exhibits a unique property that distinguishes it from other trees. This property is known as the <strong>binary-search-tree property</strong>.</p>\n<p>Let <strong>x</strong> be a node in a binary search tree.</p>\n<ul>\n<li>If <strong>y</strong> is a node in the <strong>left</strong> subtree of x, then <strong>y.key ≤ x.key</strong></li>\n<li>If <strong>y</strong> is a node in the <strong>right</strong> subtree of x, then <strong>y.key ≥ x.key</strong></li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*TMn800emvMuqwY3AZpfwCg.png?q=20\" alt=\"medium blog image\">Fig 6. Visualization of Basic Terminology of Trees (Image by author)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*TMn800emvMuqwY3AZpfwCg.png\" alt=\"medium blog image\"></p>\n<h3>Applications of trees <a id=\"3ea1\"></h3>\n</a>\n<ul>\n<li><strong>Binary Trees</strong>: Used to implement expression parsers and expression solvers.</li>\n<li><strong>Binary Search Tree</strong>: used in many search applications where data are constantly entering and leaving.</li>\n<li><strong>Heaps</strong>: used by JVM (Java Virtual Machine) to store Java objects.</li>\n<li><strong>Treaps</strong>: used in wireless networking.</li>\n</ul>\n<p>Check my articles below on 8 useful tree data structures and self-balancing binary search trees.[8 Useful Tree Data Structures Worth KnowingAn overview of 8 different tree data structurestowardsdatascience.com](https://towardsdatascience.com/8-useful-tree-data-structures-worth-knowing-8532c7231e8c)[Self-Balancing Binary Search Trees 101Introduction to Self-Balancing Binary Search Treestowardsdatascience.com](https://towardsdatascience.com/self-balancing-binary-search-trees-101-fc4f51199e1d)</p>\n<h2>7. Heaps <a id=\"9e26\"></h2>\n</a>\n<p>A <strong>Heap</strong> is a special case of a binary tree where the parent nodes are compared to their children with their values and are arranged accordingly.</p>\n<p>Let us see how we can represent heaps. Heaps can be represented using trees as well as arrays. Figures 7 and 8 show how we can represent a binary heap using a binary tree and an array.<img src=\"https://miro.medium.com/max/60/1*BEq4aj8K7u4LbIaIEtHNmQ.png?q=20\" alt=\"medium blog image\">Fig 7. Binary Tree Representation of a Heap (Image by author)<img src=\"https://miro.medium.com/max/60/1*N7R4banKc1NG5KqdXmJnkA.png?q=20\" alt=\"medium blog image\">Fig 8. Array Representation of a Heap (Image by author)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*N7R4banKc1NG5KqdXmJnkA.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/473/1*BEq4aj8K7u4LbIaIEtHNmQ.png\" alt=\"medium blog image\"></p>\n<p>Heaps can be of 2 types.</p>\n<ol>\n<li><strong>Min Heap</strong> — the key of the parent is less than or equal to those of its children. This is called the <strong>min-heap property</strong>. The root will contain the minimum value of the heap.</li>\n<li><strong>Max Heap</strong> — the key of the parent is greater than or equal to those of its children. This is called the <strong>max-heap property</strong>. The root will contain the maximum value of the heap.</li>\n</ol>\n<h3>Applications of heaps <a id=\"6986\"></h3>\n</a>\n<ul>\n<li>Used in <strong>heapsort algorithm</strong>.</li>\n<li>Used to implement priority queues as the priority values can be ordered according to the heap property where the heap can be implemented using an array.</li>\n<li>Queue functions can be implemented using heaps within <strong>O(log n)</strong> time.</li>\n<li>Used to find the kᵗʰ smallest (or largest) value in a given array.</li>\n</ul>\n<p>Check my article below on implementing a heap using the python heapq module.[Introduction to Python Heapq ModuleA simple introduction on how to use Python's heapq moduletowardsdatascience.com](https://towardsdatascience.com/introduction-to-python-heapq-module-53534feda625)</p>\n<h2>8. Graphs <a id=\"e0c7\"></h2>\n</a>\n<p>A <strong>graph</strong> consists of a finite set of <strong>vertices</strong> or nodes and a set of <strong>edges</strong> connecting these vertices.</p>\n<p>The <strong>order</strong> of a graph is the number of vertices in the graph. The <strong>size</strong> of a graph is the number of edges in the graph.</p>\n<p>Two nodes are said to be <strong>adjacent</strong> if they are connected to each other by the same edge.</p>\n<h3>Directed Graphs <a id=\"3763\"></h3>\n</a>\n<p>A graph <strong>G</strong> is said to be a <strong>directed graph</strong> if all its edges have a direction indicating what is the start vertex and what is the end vertex.</p>\n<p>We say that <strong>(u, v)</strong> is <strong>incident from</strong> or <strong>leaves</strong> vertex <strong>u</strong> and is <strong>incident to</strong> or <strong>enters</strong> vertex <strong>v</strong>.</p>\n<p><strong>Self-loops</strong>: Edges from a vertex to itself.</p>\n<h3>Undirected Graphs <a id=\"9fe9\"></h3>\n</a>\n<p>A graph <strong>G</strong> is said to be an <strong>undirected graph</strong> if all its edges have no direction. It can go in both ways between the two vertices.</p>\n<p>If a vertex is not connected to any other node in the graph, it is said to be <strong>isolated</strong>.<img src=\"https://miro.medium.com/max/60/1*bgRmFfnYXHYXSv1pbNea0A.png?q=20\" alt=\"medium blog image\">Fig 9. Visualization of Terminology of Graphs (Image by author)</p>\n<p><img src=\"https://miro.medium.com/max/473/1*bgRmFfnYXHYXSv1pbNea0A.png\" alt=\"medium blog image\"></p>\n<p>You can read more about graph algorithms from my article [10 Graph Algorithms Visually Explained](https://medium.com/@vijinimallawaarachchi/10-graph-algorithms-visually-explained-e57faa1336f3).[10 Graph Algorithms Visually ExplainedA quick introduction to 10 basic graph algorithms with examples and visualisationsmedium.com](https://medium.com/@vijinimallawaarachchi/10-graph-algorithms-visually-explained-e57faa1336f3)</p>\n<h3>Applications of graphs <a id=\"888d\"></h3>\n</a>\n<ul>\n<li>Used to represent social media networks. Each user is a vertex, and when users connect they create an edge.</li>\n<li>Used to represent web pages and links by search engines. Web pages on the internet are linked to each other by hyperlinks. Each page is a vertex and the hyperlink between two pages is an edge. Used for Page Ranking in Google.</li>\n<li>Used to represent locations and routes in GPS. Locations are vertices and the routes connecting locations are edges. Used to calculate the shortest route between two locations.</li>\n</ul>"},{"url":"/docs/docs/sitemap/","relativePath":"docs/docs/sitemap.md","relativeDir":"docs/docs","base":"sitemap.md","name":"sitemap","frontmatter":{"title":"Sitemap","weight":0,"excerpt":"Sitemap","seo":{"title":"Sitemap","description":"Website Navigation Layout","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<details>\n<summary>  Update </summary>\n \n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/\">Home</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/admin\">admin</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog\">blog</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/300-react-questions\">blog/300-react-questions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/awesome-graphql\">blog/awesome-graphql</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/big-o-complexity\">blog/big-o-complexity</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blog-archive\">blog/blog-archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures\">blog/data-structures</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/expressjs-apis\">blog/expressjs-apis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/flow-control-in-python\">blog/flow-control-in-python</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/functions-in-python\">blog/functions-in-python</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/git-gateway\">blog/git-gateway</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/hoisting\">blog/hoisting</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js-p2\">blog/interview-questions-js-p2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js-p3\">blog/interview-questions-js-p3</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js\">blog/interview-questions-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/netlify-cms\">blog/netlify-cms</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/platform-docs\">blog/platform-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-for-js-dev\">blog/python-for-js-dev</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-resources\">blog/python-resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/web-dev-trends\">blog/web-dev-trends</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/web-scraping\">blog/web-scraping</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs\">docs</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about\">docs/about</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/eng-portfolio\">docs/about/eng-portfolio</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/intrests\">docs/about/intrests</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/job-search\">docs/about/job-search</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/README\">docs/about/README</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/resume\">docs/about/resume</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles\">docs/articles</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev\">docs/articles/basic-web-dev</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/buffers\">docs/articles/buffers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/common-modules\">docs/articles/common-modules</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/dev-dep\">docs/articles/dev-dep</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/event-loop\">docs/articles/event-loop</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/fs-module\">docs/articles/fs-module</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-search-engines-work\">docs/articles/how-search-engines-work</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-the-web-works\">docs/articles/how-the-web-works</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/intro\">docs/articles/intro</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/jamstack\">docs/articles/jamstack</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nextjs\">docs/articles/nextjs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-api-express\">docs/articles/node-api-express</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/npm\">docs/articles/npm</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/os-module\">docs/articles/os-module</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/reading-files\">docs/articles/reading-files</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic-html\">docs/articles/semantic-html</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic\">docs/articles/semantic</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/url\">docs/articles/url</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/web-standards-checklist\">docs/articles/web-standards-checklist</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/webdev-tools\">docs/articles/webdev-tools</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/writing-files\">docs/articles/writing-files</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio\">docs/audio</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dfft\">docs/audio/dfft</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/discrete-fft\">docs/audio/discrete-fft</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dtw-python-explained\">docs/audio/dtw-python-explained</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dynamic-time-warping\">docs/audio/dynamic-time-warping</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/web-audio-api\">docs/audio/web-audio-api</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career\">docs/career</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/job-boards\">docs/career/job-boards</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/list-of-projects\">docs/career/list-of-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/my-websites\">docs/career/my-websites</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community\">docs/community</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/an-open-letter-2-future-developers\">docs/community/an-open-letter-2-future-developers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/bookmarks\">docs/community/bookmarks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/video-chat\">docs/community/video-chat</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content\">docs/content</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/algo\">docs/content/algo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/archive\">docs/content/archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/gatsby-Queries-Mutations\">docs/content/gatsby-Queries-Mutations</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/gists\">docs/content/gists</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/history-api\">docs/content/history-api</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/main-projects\">docs/content/main-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/trouble-shooting\">docs/content/trouble-shooting</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs\">docs/docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/appendix\">docs/docs/appendix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/bash\">docs/docs/bash</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/css\">docs/docs/css</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/es-6-features\">docs/docs/es-6-features</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-reference\">docs/docs/git-reference</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-repos\">docs/docs/git-repos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/glossary\">docs/docs/glossary</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/html-tags\">docs/docs/html-tags</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/markdown\">docs/docs/markdown</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/no-whiteboarding\">docs/docs/no-whiteboarding</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/node-docs-complete\">docs/docs/node-docs-complete</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/regex-in-js\">docs/docs/regex-in-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/sitemap\">docs/docs/sitemap</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo\">docs/ds-algo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/big-o\">docs/ds-algo/big-o</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-docs\">docs/ds-algo/data-structures-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-algo-interview\">docs/ds-algo/ds-algo-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-overview\">docs/ds-algo/ds-overview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/free-code-camp\">docs/ds-algo/free-code-camp</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/graph\">docs/ds-algo/graph</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/heaps\">docs/ds-algo/heaps</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/tree\">docs/ds-algo/tree</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq\">docs/faq</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/contact\">docs/faq/contact</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/plug-ins\">docs/faq/plug-ins</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact\">docs/interact</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/callstack-visual\">docs/interact/callstack-visual</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/clock\">docs/interact/clock</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/jupyter-notebooks\">docs/interact/jupyter-notebooks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites\">docs/interact/other-sites</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/react-testing-library\">docs/interact/react-testing-library</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/video-chat\">docs/interact/video-chat</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview\">docs/interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/dev-interview\">docs/interview/dev-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/dos-and-donts\">docs/interview/dos-and-donts</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/interview-questions\">docs/interview/interview-questions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/job-search-nav\">docs/interview/job-search-nav</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/previous-concepts\">docs/interview/previous-concepts</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/review-concepts\">docs/interview/review-concepts</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/web-interview\">docs/interview/web-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/web-interview2\">docs/interview/web-interview2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/web-interview3\">docs/interview/web-interview3</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/web-interview4\">docs/interview/web-interview4</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript\">docs/javascript</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/arrow-functions\">docs/javascript/arrow-functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/asyncjs\">docs/javascript/asyncjs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/await-keyword\">docs/javascript/await-keyword</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/bigo\">docs/javascript/bigo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/clean-code\">docs/javascript/clean-code</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/constructor-functions\">docs/javascript/constructor-functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/cs-basics-in-js\">docs/javascript/cs-basics-in-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/for-loops\">docs/javascript/for-loops</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/js-expressions\">docs/javascript/js-expressions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/js-objects\">docs/javascript/js-objects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/part2-pojo\">docs/javascript/part2-pojo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/promises\">docs/javascript/promises</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/review\">docs/javascript/review</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/this-is-about-this\">docs/javascript/this-is-about-this</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/variables\">docs/javascript/variables</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips\">docs/js-tips</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/abs\">docs/js-tips/abs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acos\">docs/js-tips/acos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acosh\">docs/js-tips/acosh</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/addition\">docs/js-tips/addition</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/all\">docs/js-tips/all</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/allsettled\">docs/js-tips/allsettled</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/any\">docs/js-tips/any</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array-methods\">docs/js-tips/array-methods</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array\">docs/js-tips/array</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/arrow_functions\">docs/js-tips/arrow_functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/async_function\">docs/js-tips/async_function</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bad_radix\">docs/js-tips/bad_radix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bind\">docs/js-tips/bind</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/classes\">docs/js-tips/classes</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/concat\">docs/js-tips/concat</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/conditional_operator\">docs/js-tips/conditional_operator</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/const\">docs/js-tips/const</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/create\">docs/js-tips/create</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/date\">docs/js-tips/date</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/eval\">docs/js-tips/eval</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/every\">docs/js-tips/every</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/filter\">docs/js-tips/filter</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/for...of\">docs/js-tips/for...of</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/foreach\">docs/js-tips/foreach</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/functions\">docs/js-tips/functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/import\">docs/js-tips/import</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/insert-into-array\">docs/js-tips/insert-into-array</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/map\">docs/js-tips/map</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/object\">docs/js-tips/object</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/reduce\">docs/js-tips/reduce</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/regexp\">docs/js-tips/regexp</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sort\">docs/js-tips/sort</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sorting-strings\">docs/js-tips/sorting-strings</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/string\">docs/js-tips/string</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/this\">docs/js-tips/this</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/var\">docs/js-tips/var</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode\">docs/leetcode</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ContaineWitMosWater\">docs/leetcode/ContaineWitMosWater</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/DividTwIntegers\">docs/leetcode/DividTwIntegers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/GeneratParentheses\">docs/leetcode/GeneratParentheses</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/LetteCombinationoPhonNumber\">docs/leetcode/LetteCombinationoPhonNumber</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/LongesCommoPrefix\">docs/leetcode/LongesCommoPrefix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/MediaoTwSorteArrays\">docs/leetcode/MediaoTwSorteArrays</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/NexPermutation\">docs/leetcode/NexPermutation</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/PalindromNumber\">docs/leetcode/PalindromNumber</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RegulaExpressioMatching\">docs/leetcode/RegulaExpressioMatching</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RemovDuplicatefroSorteArray\">docs/leetcode/RemovDuplicatefroSorteArray</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RemovNtNodFroEnoList\">docs/leetcode/RemovNtNodFroEnoList</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RomatInteger\">docs/leetcode/RomatInteger</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/SearciRotateSorteArray\">docs/leetcode/SearciRotateSorteArray</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/StrintIntege(atoi)\">docs/leetcode/StrintIntege(atoi)</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ValiParentheses\">docs/leetcode/ValiParentheses</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ZigZaConversion\">docs/leetcode/ZigZaConversion</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow\">docs/overflow</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/html-spec\">docs/overflow/html-spec</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/http\">docs/overflow/http</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/install\">docs/overflow/install</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/modules\">docs/overflow/modules</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-cli-args\">docs/overflow/node-cli-args</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-js-language\">docs/overflow/node-js-language</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-package-manager\">docs/overflow/node-package-manager</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-repl\">docs/overflow/node-repl</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-run-cli\">docs/overflow/node-run-cli</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/nodejs\">docs/overflow/nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/nodevsbrowser\">docs/overflow/nodevsbrowser</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/understanding-firebase\">docs/overflow/understanding-firebase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/v8\">docs/overflow/v8</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/privacy-policy\">docs/privacy-policy</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects\">docs/projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/embeded-websites\">docs/projects/embeded-websites</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects\">docs/projects/mini-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects2\">docs/projects/mini-projects2</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python\">docs/python</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/at-length\">docs/python/at-length</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/cheat-sheet\">docs/python/cheat-sheet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/comprehensive-guide\">docs/python/comprehensive-guide</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/examples\">docs/python/examples</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/flow-control\">docs/python/flow-control</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/functions\">docs/python/functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/google-sheets-api\">docs/python/google-sheets-api</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/intro-for-js-devs\">docs/python/intro-for-js-devs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-ds\">docs/python/python-ds</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-quiz\">docs/python/python-quiz</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/snippets\">docs/python/snippets</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref\">docs/quick-ref</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/all-emojis\">docs/quick-ref/all-emojis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/create-react-app\">docs/quick-ref/create-react-app</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/Emmet\">docs/quick-ref/Emmet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/fetch\">docs/quick-ref/fetch</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-bash\">docs/quick-ref/git-bash</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-tricks\">docs/quick-ref/git-tricks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/google-firebase\">docs/quick-ref/google-firebase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/heroku-error-codes\">docs/quick-ref/heroku-error-codes</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/installation\">docs/quick-ref/installation</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/markdown-dropdowns\">docs/quick-ref/markdown-dropdowns</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/minifiction\">docs/quick-ref/minifiction</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/new-repo-instructions\">docs/quick-ref/new-repo-instructions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/pull-request-rubric\">docs/quick-ref/pull-request-rubric</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/quick-links\">docs/quick-ref/quick-links</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/topRepos\">docs/quick-ref/topRepos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/understanding-path\">docs/quick-ref/understanding-path</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/vscode-themes\">docs/quick-ref/vscode-themes</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react\">docs/react</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/accessibility\">docs/react/accessibility</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/ajax-n-apis\">docs/react/ajax-n-apis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/cheatsheet\">docs/react/cheatsheet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/complete-react\">docs/react/complete-react</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/createReactApp\">docs/react/createReactApp</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/demo\">docs/react/demo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/dont-use-index-as-keys\">docs/react/dont-use-index-as-keys</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/jsx\">docs/react/jsx</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/quiz\">docs/react/quiz</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-docs\">docs/react/react-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-in-depth\">docs/react/react-in-depth</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-patterns-by-usecase\">docs/react/react-patterns-by-usecase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2\">docs/react/react2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/render-elements\">docs/react/render-elements</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference\">docs/reference</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/art-of-command-line\">docs/reference/art-of-command-line</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-lists\">docs/reference/awesome-lists</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-nodejs\">docs/reference/awesome-nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-static\">docs/reference/awesome-static</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bash-commands\">docs/reference/bash-commands</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bookmarks\">docs/reference/bookmarks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/embed-the-web\">docs/reference/embed-the-web</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-resources\">docs/reference/github-resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-search\">docs/reference/github-search</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/google-cloud\">docs/reference/google-cloud</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-2-reinstall-npm\">docs/reference/how-2-reinstall-npm</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-to-kill-a-process\">docs/reference/how-to-kill-a-process</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/installing-node\">docs/reference/installing-node</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/intro-to-nodejs\">docs/reference/intro-to-nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/markdown-styleguide\">docs/reference/markdown-styleguide</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/notes-template\">docs/reference/notes-template</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/psql\">docs/reference/psql</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/resources\">docs/reference/resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/vscode\">docs/reference/vscode</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/web-api&#x27;s\">docs/reference/web-api's</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/sitemap\">docs/sitemap</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips\">docs/tips</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/regex-tips\">docs/tips/regex-tips</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools\">docs/tools</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/all-stripped\">docs/tools/all-stripped</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/all\">docs/tools/all</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/Archive\">docs/tools/Archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/archive\">docs/tools/archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/dev-utilities\">docs/tools/dev-utilities</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/markdown-html\">docs/tools/markdown-html</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials\">docs/tutorials</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/algolia-search\">docs/tutorials/algolia-search</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/bash-commands-my\">docs/tutorials/bash-commands-my</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/bash\">docs/tutorials/bash</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/get-file-extension\">docs/tutorials/get-file-extension</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/how-2-ubuntu\">docs/tutorials/how-2-ubuntu</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/psql-setup\">docs/tutorials/psql-setup</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/react-class-2-func\">docs/tutorials/react-class-2-func</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/interview-questions-js\">interview-questions-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/privacy-policy\">privacy-policy</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/readme\">readme</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/showcase\">showcase</a></li>\n</ul>\n</details>\n<h1><a href=\"https://bgoonz-blog.netlify.app/\"><strong>➡️🏠🏠HOME🏠🏠⬅️</strong></a></h1>\n<center>\n<h2><a href=\"https://bgoonz-blog.netlify.app/docs\"><strong><ins>➡️📚🏠docs🏠📚⬅️</ins></strong></a></h2>\n<h3><a href=\"https://bgoonz-blog.netlify.app/readme\"><strong>readme</ins></strong></a></h3>\n<h3><a href=\"https://bgoonz-blog.netlify.app/showcase\"><strong><ins>showcase</ins></strong></a></h3>\n<h5><a href=\"https://bgoonz-blog.netlify.app/admin\"><strong><ins>🔏admin</ins></strong></a></h5>\n<h5><a href=\"https://bgoonz-blog.netlify.app/privacy-policy\"><strong><ins>🔏privacy-policy</ins></strong></a></h5>\n</center>\n<details>\n<summary>\n<ins>\n<h6>\n<h6> 📰         📰 BLOG 📰         📰 </h6>\n</h6>\n</ins>\n</summary>\n<h3><a href=\"https://bgoonz-blog.netlify.app/blog\"><strong><ins>Blog Article List</ins></strong></a></h3>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/blog/web-scraping\">📰blog📰</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/300-react-questions\">📰blog📰/300-react-questions⚛</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/awesome-graphql\">📰blog📰/awesome-graphql፨</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/big-o-complexity\">📰blog📰/big-o-complexity</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blog-archive\">📰blog📰/blog-archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures\">📰blog📰/data-structures</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/expressjs-apis\">📰blog📰/expressjs-apis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/flow-control-in-python\">📰blog📰/flow-control-in-python</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/functions-in-python\">📰blog📰/functions-in-python</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/git-gateway\">📰blog📰/git-gateway</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js\">📰blog📰/interview-questions-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/netlify-cms\">📰blog📰/netlify-cms</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/platform-docs\">📰blog📰/platform-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-for-js-dev\">📰blog📰/python-for-js-dev</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-resources\">📰blog📰/python-resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/web-dev-trends\">📰blog📰/web-dev-trends</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/web-scraping\">📰blog📰/web-scraping</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - ❓About</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/about\">📚docs📚/about</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/README\">📚docs📚/about/README</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/eng-portfolio\">📚docs📚/about/eng-portfolio</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/intrests\">📚docs📚/about/intrests</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/job-search\">📚docs📚/about/job-search</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/resume\">📚docs📚/about/resume</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - 🗞️Artices🗞️</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/articles\">📚docs📚/🗞️articles🗞️</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev\">📚docs📚/🗞️articles🗞️basic-web-dev</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/buffers\">📚docs📚/🗞️articles🗞️buffers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/common-modules\">📚docs📚/🗞️articles🗞️common-modules</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/dev-dep\">📚docs📚/🗞️articles🗞️dev-dep</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/event-loop\">📚docs📚/🗞️articles🗞️event-loop</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/fs-module\">📚docs📚/🗞️articles🗞️fs-module</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-search-engines-work\">📚docs📚/🗞️articles🗞️how-search-engines-work</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-the-web-works\">📚docs📚/🗞️articles🗞️how-the-web-works</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/intro\">📚docs📚/🗞️articles🗞️intro</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/jamstack\">📚docs📚/🗞️articles🗞️jamstack</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nextjs\">📚docs📚/🗞️articles🗞️nextjs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-api-express\">📚docs📚/🗞️articles🗞️node-api-express</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nodejs\">📚docs📚/🗞️articles🗞️nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/npm\">📚docs📚/🗞️articles🗞️npm</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/os-module\">📚docs📚/🗞️articles🗞️os-module</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/reading-files\">📚docs📚/🗞️articles🗞️reading-files</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic\">📚docs📚/🗞️articles🗞️semantic</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic-html\">📚docs📚/🗞️articles🗞️semantic-html</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/url\">📚docs📚/🗞️articles🗞️url</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/web-standards-checklist\">📚docs📚/🗞️articles🗞️web-standards-checklist</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/webdev-tools\">📚docs📚/🗞️articles🗞️webdev-tools</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/writing-files\">📚docs📚/🗞️articles🗞️writing-files</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - 🔊 Audio</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/audio\">📚Docs - Audio🔊</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dfft\">📚docs📚/audio/dfft</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/discrete-fft\">📚docs📚/audio/discrete-fft</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dtw-python-explained\">📚docs📚/audio/dtw-python-explained</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dynamic-time-warping\">📚docs📚/audio/dynamic-time-warping</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/web-audio-api\">📚docs📚/audio/web-audio-api</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 -  Career </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/career\">📚docs📚/career</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/dev-interview\">📚docs📚/career/dev-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/dos-and-donts\">📚docs📚/career/dos-and-donts</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/job-boards\">📚docs📚/career/job-boards</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview\">📚docs📚/career/web-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview2\">📚docs📚/career/web-interview2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview3\">📚docs📚/career/web-interview3</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview4\">📚docs📚/career/web-interview4</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/job-search-nav\">📚docs📚/interview/job-search-nav</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/previous-concepts\">📚docs📚/interview/previous-concepts</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interview/review-concepts\">📚docs📚/interview/review-concepts</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 -  👫👫Community👫👫 </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/community\">📚docs📚/👫👫community👫👫</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/an-open-letter-2-future-developers\">📚docs📚/community/an-open-letter-2-future-developers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/bookmarks\">📚docs📚/community/bookmarks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/video-chat\">📚docs📚/community/video-chat</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - 💼Content💼</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/content/\">📚docs📚/💼content💼</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/archive\">📚docs📚/💼content💼/archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/gatsby-Queries-Mutations\">📚docs📚/💼content💼/gatsby-Queries-Mutations</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/gists\">📚docs📚/💼content💼/gists</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/history-api\">📚docs📚/💼content💼/history-api</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/main-projects\">📚docs📚/💼content💼/main-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/trouble-shooting\">📚docs📚/💼content💼/trouble-shooting</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - 📓Documentation📓</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/docs\">📚docs📚/docs</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/appendix\">📚docs📚/docs/appendix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/art-of-command-line\">📚docs📚/docs/art-of-command-line</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/bash\">📚docs📚/docs/bash</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/css\">📚docs📚/docs/css</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/data-structures-docs\">📚docs📚/docs/data-structures-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/es-6-features\">📚docs📚/docs/es-6-features</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-reference\">📚docs📚/docs/git-reference</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-repos\">📚docs📚/docs/git-repos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/glossary\">📚docs📚/docs/glossary</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/html-tags\">📚docs📚/docs/html-tags</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/markdown\">📚docs📚/docs/markdown</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/no-whiteboarding\">📚docs📚/docs/no-whiteboarding</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/node-docs-complete\">📚docs📚/docs/node-docs-complete</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/regex-in-js\">📚docs📚/docs/regex-in-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/sitemap\">📚docs📚/docs/sitemap</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/snippets\">📚docs📚/docs/snippets</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n <ins>📚Docs📚 - 🕸Data Structures & Algorithms🕸</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo\">📚docs📚/🕸ds-algo🕸</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/big-o\">📚docs📚/🕸ds-algo🕸/big-o</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-algo-interview\">📚docs📚/🕸ds-algo🕸/ds-algo-interview</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-overview\">📚docs📚/🕸ds-algo🕸/ds-overview</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚  - ❓FAQ❓</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/faq\">📚docs📚/faq</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/contact\">📚docs📚/❓faq❓/contact</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/plug-ins\">📚docs📚/❓faq❓/plug-ins</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - 🧑‍🔬Interactive🧑‍🔬 </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/interact\">📚docs📚/interact</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/callstack-visual\">📚docs📚/🧑‍🔬interact🧑‍🔬/callstack-visual</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/clock\">📚docs📚/🧑‍🔬interact🧑‍🔬/clock</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/jupyter-notebooks\">📚docs📚/🧑‍🔬interact🧑‍🔬/jupyter-notebooks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites\">📚docs📚/🧑‍🔬interact🧑‍🔬/other-sites</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/video-chat\">📚docs📚/🧑‍🔬interact🧑‍🔬/video-chat</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - Javascript</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/javascript\">📚docs📚/javascript</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/arrow-functions\">📚docs📚/javascript/arrow-functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/asyncjs\">📚docs📚/javascript/asyncjs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/await-keyword\">📚docs📚/javascript/await-keyword</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/bigo\">📚docs📚/javascript/bigo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/clean-code\">📚docs📚/javascript/clean-code</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/constructor-functions\">📚docs📚/javascript/constructor-functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/cs-basics-in-js\">📚docs📚/javascript/cs-basics-in-js</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/for-loops\">📚docs📚/javascript/for-loops</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/part2-pojo\">📚docs📚/javascript/part2-pojo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/promises\">📚docs📚/javascript/promises</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/review\">📚docs📚/javascript/review</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/this-is-about-this\">📚docs📚/javascript/this-is-about-this</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 -  JS-Tips        </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips\">📚docs📚/js-tips</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/abs\">📚docs📚/js-tips/abs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acos\">📚docs📚/js-tips/acos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acosh\">📚docs📚/js-tips/acosh</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/addition\">📚docs📚/js-tips/addition</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/all\">📚docs📚/js-tips/all</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/allsettled\">📚docs📚/js-tips/allsettled</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/any\">📚docs📚/js-tips/any</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array\">📚docs📚/js-tips/array</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array-methods\">📚docs📚/js-tips/array-methods</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/arrow_functions\">📚docs📚/js-tips/arrow_functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/async_function\">📚docs📚/js-tips/async_function</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bad_radix\">📚docs📚/js-tips/bad_radix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bind\">📚docs📚/js-tips/bind</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/classes\">📚docs📚/js-tips/classes</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/concat\">📚docs📚/js-tips/concat</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/conditional_operator\">📚docs📚/js-tips/conditional_operator</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/const\">📚docs📚/js-tips/const</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/create\">📚docs📚/js-tips/create</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/date\">📚docs📚/js-tips/date</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/eval\">📚docs📚/js-tips/eval</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/every\">📚docs📚/js-tips/every</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/filter\">📚docs📚/js-tips/filter</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/for...of\">📚docs📚/js-tips/for...of</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/foreach\">📚docs📚/js-tips/foreach</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/functions\">📚docs📚/js-tips/functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/import\">📚docs📚/js-tips/import</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/insert-into-array\">📚docs📚/js-tips/insert-into-array</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/map\">📚docs📚/js-tips/map</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/object\">📚docs📚/js-tips/object</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/reduce\">📚docs📚/js-tips/reduce</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/regexp\">📚docs📚/js-tips/regexp</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sort\">📚docs📚/js-tips/sort</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sorting-strings\">📚docs📚/js-tips/sorting-strings</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/string\">📚docs📚/js-tips/string</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/this\">📚docs📚/js-tips/this</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/var\">📚docs📚/js-tips/var</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - Leetcode      </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode\">📚docs📚/leetcode</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ContaineWitMosWater\">📚docs📚/leetcode/ContaineWitMosWater</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/DividTwIntegers\">📚docs📚/leetcode/DividTwIntegers</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/GeneratParentheses\">📚docs📚/leetcode/GeneratParentheses</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/LetteCombinationoPhonNumber\">📚docs📚/leetcode/LetteCombinationoPhonNumber</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/LongesCommoPrefix\">📚docs📚/leetcode/LongesCommoPrefix</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/MediaoTwSorteArrays\">📚docs📚/leetcode/MediaoTwSorteArrays</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/NexPermutation\">📚docs📚/leetcode/NexPermutation</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/PalindromNumber\">📚docs📚/leetcode/PalindromNumber</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RegulaExpressioMatching\">📚docs📚/leetcode/RegulaExpressioMatching</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RemovDuplicatefroSorteArray\">📚docs📚/leetcode/RemovDuplicatefroSorteArray</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RemovNtNodFroEnoList\">📚docs📚/leetcode/RemovNtNodFroEnoList</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/RomatInteger\">📚docs📚/leetcode/RomatInteger</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/SearciRotateSorteArray\">📚docs📚/leetcode/SearciRotateSorteArray</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/StrintIntege(atoi)\">📚docs📚/leetcode/StrintIntege(atoi)</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ValiParentheses\">📚docs📚/leetcode/ValiParentheses</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/ZigZaConversion\">📚docs📚/leetcode/ZigZaConversion</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 -  🌊 Overflow     </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/overflow\">📚docs📚/overflow</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/html-spec\">📚docs📚/overflow/html-spec</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/http\">📚docs📚/overflow/http</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/install\">📚docs📚/overflow/install</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/modules\">📚docs📚/overflow/modules</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-cli-args\">📚docs📚/overflow/node-cli-args</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-js-language\">📚docs📚/overflow/node-js-language</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-package-manager\">📚docs📚/overflow/node-package-manager</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-repl\">📚docs📚/overflow/node-repl</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-run-cli\">📚docs📚/overflow/node-run-cli</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/nodevsbrowser\">📚docs📚/overflow/nodevsbrowser</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/understanding-firebase\">📚docs📚/overflow/understanding-firebase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/v8\">📚docs📚/overflow/v8</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - Projects  </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/projects\">📚docs📚/projects</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/embeded-websites\">📚docs📚/projects/embeded-websites</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/list-of-projects\">📚docs📚/projects/list-of-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects\">📚docs📚/projects/mini-projects</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects2\">📚docs📚/projects/mini-projects2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/projects/my-websites\">📚docs📚/projects/my-websites</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚  - 🐍Python🐍  </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/python\">📚docs📚/🐍python🐍</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/at-length\">📚docs📚/🐍python🐍/at-length</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/cheat-sheet\">📚docs📚/🐍python🐍/cheat-sheet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/comprehensive-guide\">📚docs📚/🐍python🐍/comprehensive-guide</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/examples\">📚docs📚/🐍python🐍/examples</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/flow-control\">📚docs📚/🐍python🐍/flow-control</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/functions\">📚docs📚/🐍python🐍/functions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/google-sheets-api\">📚docs📚/🐍python🐍/google-sheets-api</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-ds\">📚docs📚/🐍python🐍/python-ds</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/intro-for-js-devs\">📚docs📚/🐍python🐍/intro-for-js-devs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-quiz\">📚docs📚/🐍python🐍/python-quiz</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/snippets\">📚docs📚/🐍python🐍/snippets</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚  - 📚🏃‍♂️Quick Reference📚🏃‍♂️   </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref\">📚docs📚/quick-ref</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/Emmet\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/Emmet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/all-emojis\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/all-emojis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/create-react-app\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/create-react-app</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-bash\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/git-bash</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-tricks\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/git-tricks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/google-firebase\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/google-firebase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/heroku-error-codes\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/heroku-error-codes</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/installation\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/installation</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/markdown-dropdowns\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/markdown-dropdowns</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/minifiction\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/minifiction</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/new-repo-instructions\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/new-repo-instructions</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/psql-setup\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/psql-setup</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/pull-request-rubric\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/pull-request-rubric</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/quick-links\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/quick-links</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/topRepos\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/topRepos</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/understanding-path\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/understanding-path</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/vscode-themes\">📚docs📚/🏃‍♂️📚quick-ref📚🏃‍♂️/vscode-themes</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/accessibility\">📚docs📚/⚛️react⚛️/accessibility</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚  - ⚛️React⚛️ </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/react\">📚docs📚/⚛️react⚛️</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/ajax-n-apis\">📚docs📚/⚛️react⚛️/ajax-n-apis</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/cheatsheet\">📚docs📚/⚛️react⚛️/cheatsheet</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/createReactApp\">📚docs📚/⚛️react⚛️/createReactApp</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/demo\">📚docs📚/⚛️react⚛️/demo</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/dont-use-index-as-keys\">📚docs📚/⚛️react⚛️/dont-use-index-as-keys</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/jsx\">📚docs📚/⚛️react⚛️/jsx</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/quiz\">📚docs📚/⚛️react⚛️/quiz</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-docs\">📚docs📚/⚛️react⚛️/react-docs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-in-depth\">📚docs📚/⚛️react⚛️/react-in-depth</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-patterns-by-usecase\">📚docs📚/⚛️react⚛️/react-patterns-by-usecase</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2\">📚docs📚/⚛️react⚛️/react2</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/render-elements\">📚docs📚/⚛️react⚛️/render-elements</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚  -  ※🕮Reference Materials🕮※</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/reference\">📚docs📚/※reference※</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-lists\">📚docs📚/※🕮reference※🕮/awesome-lists</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-nodejs\">📚docs📚/※🕮reference※🕮/awesome-nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-static\">📚docs📚/※🕮reference※🕮/awesome-static</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bash-commands\">📚docs📚/※🕮reference※🕮/bash-commands</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bookmarks\">📚docs📚/※🕮reference※🕮/bookmarks</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/embed-the-web\">📚docs📚/※🕮reference※🕮/embed-the-web</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-resources\">📚docs📚/※🕮reference※🕮/github-resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-search\">📚docs📚/※🕮reference※🕮/github-search</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/google-cloud\">📚docs📚/※🕮reference※🕮/google-cloud</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-2-reinstall-npm\">📚docs📚/※🕮reference※🕮/how-2-reinstall-npm</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-to-kill-a-process\">📚docs📚/※🕮reference※🕮/how-to-kill-a-process</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/installing-node\">📚docs📚/※🕮reference※🕮/installing-node</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/intro-to-nodejs\">📚docs📚/※🕮reference※🕮/intro-to-nodejs</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/markdown-styleguide\">📚docs📚/※🕮reference※🕮/markdown-styleguide</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/notes-template\">📚docs📚/※🕮reference※🕮/notes-template</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/psql\">📚docs📚/※🕮reference※🕮/psql</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/resources\">📚docs📚/※🕮reference※🕮/resources</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/vscode\">📚docs📚/※🕮reference※🕮/vscode</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/reference/web-api&#x27;s\">📚docs📚/※🕮reference※🕮/web-api's</a></li>\n</ul>\n</li>\n</ul>\n</details>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - 🔊 Mini Web Dev Tips </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/tips\">📚docs📚/tips</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tips/regex-tips\">📚docs📚/tips/regex-tips</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚 - ⚒Tools⚒ </h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/tools\">📚docs📚/⚒Tools⚒/</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/all\">📚docs📚/⚒Tools⚒/all</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/all-stripped\">📚docs📚/⚒Tools⚒/all-stripped</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/archive\">📚docs📚/⚒Tools⚒/archive</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/dev-utilities\">📚docs📚/⚒Tools⚒/dev-utilities</a> </li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/markdown-html\">📚docs📚/⚒Tools⚒/📚markdown-html</a></li>\n</ul>\n</li>\n</ul>\n</details>\n<hr>\n<details>\n<summary>\n<ins>\n<h6>📚Docs📚  - 📑Tutorials📑</h6>\n</ins>\n</summary>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials\">📚docs📚/tutorials</a></p>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/enviorment-setup\">📚docs📚/📑tutorials📑/enviorment-setup</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/get-file-extension\">📚docs📚/📑tutorials📑/get-file-extension</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/get-file-name\">📚docs📚/📑tutorials📑/get-file-name</a></li>\n</ul>\n</li>\n</ul>"},{"url":"/docs/docs/regex-in-js/","relativePath":"docs/docs/regex-in-js.md","relativeDir":"docs/docs","base":"regex-in-js.md","name":"regex-in-js","frontmatter":{"title":"Regular Expressions","weight":0,"excerpt":"Regular Expressions","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Regular Expressions</h1>\n<p>description:</p>\n<hr>\n<h4><a href=\"http://medium.com/codex\" class=\"markup--anchor markup--h4-anchor\">CODEX</a></h4>\n<h3>Regular Expressions</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*VdDVM2Nzv6oGC5I0.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*D83R_a0SSgMR0hI4jP6Asw.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*vk5n412Bs-dx6UdgyUywdg.png\" class=\"graf-image\" />\n</figure>### description:\n<p><em>Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the</em> <code class=\"language-text\">exec()</code> <em>and</em> <code class=\"language-text\">test()</code> <em>methods of</em> <code class=\"language-text\">RegExp</code><em>, and with the</em> <code class=\"language-text\">match()</code><em>,</em> <code class=\"language-text\">matchAll()</code><em>,</em> <code class=\"language-text\">replace()</code><em>,</em> <code class=\"language-text\">replaceAll()</code><em>,</em> <code class=\"language-text\">search()</code><em>, and</em> <code class=\"language-text\">split()</code> <em>methods of</em> <code class=\"language-text\">String</code><em>. This chapter describes JavaScript regular expressions.</em></p>\n<h3>Creating a regular expression</h3>\n<p>You construct a regular expression in one of two ways:</p>\n<ol>\n<li><span id=\"8a7f\"><strong>Using a regular expression literal, which consists of a pattern enclosed between slashes, as follows:</strong></span></li>\n</ol>\n<p><code class=\"language-text\">let re = /ab+c/;</code></p>\n<ul>\n<li><span id=\"f4e2\">Regular expression literals provide compilation of the regular expression when the script is loaded. If the regular expression remains constant, using this can improve performance.</span></li>\n</ul>\n<p><strong>2. Or calling the constructor function of the</strong> <code class=\"language-text\">RegExp</code> <strong>object, as follows:</strong></p>\n<ul>\n<li><span id=\"2016\"><code class=\"language-text\">let re = new RegExp('ab+c');</code></span></li>\n</ul>\n<blockquote>\n<p><em>Using the constructor function provides runtime compilation of the regular expression</em>. Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input.</p>\n</blockquote>\n<h3>Writing a regular expression pattern</h3>\n<p>A regular expression pattern is composed of simple characters, such as <code class=\"language-text\">/abc/</code>, or a combination of simple and special characters, such as <code class=\"language-text\">/ab*c/</code> or <code class=\"language-text\">/Chapter (\\d+)\\.\\d*/</code>.</p>\n<p>The last example includes <strong>parentheses, which are used as a memory device</strong>. <em>The match made with this part of the pattern is remembered for later use.</em></p>\n<h3>Using simple patterns</h3>\n<p>Simple patterns are constructed of characters for which you want to find a direct match.</p>\n<p>For example, the pattern <code class=\"language-text\">/abc/</code> matches character combinations in strings only when the exact sequence <code class=\"language-text\">\"abc\"</code> occurs (all characters together and in that order).</p>\n<p>Such a match would succeed in the strings <code class=\"language-text\">\"Hi, do you know your abc's?\"</code> and <code class=\"language-text\">\"The latest airplane designs evolved from slabcraft.\"</code></p>\n<p>In both cases the match is with the substring <code class=\"language-text\">\"abc\"</code>.</p>\n<p>There is no match in the string <code class=\"language-text\">\"Grab crab\"</code> because while it contains the substring <code class=\"language-text\">\"ab c\"</code>, it does not contain the exact substring <code class=\"language-text\">\"abc\"</code>.</p>\n<h3>Using special characters</h3>\n<p>When the search for a match requires something more than a direct match, such as finding one or more b's, or finding white space, you can include special characters in the pattern.</p>\n<p>For example, to match <em>a single</em> <code class=\"language-text\">\"a\"</code> <em>followed by zero or more</em> <code class=\"language-text\">\"b\"</code><em>s followed by</em> <code class=\"language-text\">\"c\"</code>, you'd use the pattern <code class=\"language-text\">/ab*c/</code>:</p>\n<blockquote>\n<p>the <code class=\"language-text\">*</code> after <code class=\"language-text\">\"b\"</code> means \"0 or more occurrences of the preceding item.\" In the string <code class=\"language-text\">\"cbbabbbbcdebc\"</code>, this pattern will match the substring <code class=\"language-text\">\"abbbbc\"</code>.</p>\n</blockquote>\n<a href=\"https://github.com/bgoonz/Cheat-Sheets/blob/master/Regular_Expressions/Assertions.html\" class=\"markup--anchor markup--p-anchor\">\n<strong>Assertions</strong>\n</a>** : Assertions include boundaries, which indicate the beginnings and endings of lines and words, and other patterns indicating in some way that a match is possible (including look-ahead, look-behind, and conditional expressions).**\n<a href=\"https://github.com/bgoonz/Cheat-Sheets/blob/master/Regular_Expressions/Character_Classes.html\" class=\"markup--anchor markup--p-anchor\">\n<strong>Character classes</strong>\n</a>** : Distinguish different types of characters. For example, distinguishing between letters and digits.**\n<a href=\"https://github.com/bgoonz/Cheat-Sheets/blob/master/Regular_Expressions/Groups_and_Ranges.html\" class=\"markup--anchor markup--p-anchor\">\n<strong>Groups and ranges</strong>\n</a>** : Indicate groups and ranges of expression characters.**\n<a href=\"https://github.com/bgoonz/Cheat-Sheets/blob/master/Regular_Expressions/Quantifiers.html\" class=\"markup--anchor markup--p-anchor\">\n<strong>Quantifiers</strong>\n</a>** : Indicate numbers of characters or expressions to match.**\n<a href=\"https://github.com/bgoonz/Cheat-Sheets/blob/master/Regular_Expressions/Unicode_Property_Escapes.html\" class=\"markup--anchor markup--p-anchor\">\n<strong>Unicode property escapes</strong>\n</a>** : Distinguish based on unicode character properties, for example, upper- and lower-case letters, math symbols, and punctuation.**\n<p>If you want to look at all the special characters that can be used in regular expressions in a single table, see the following:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*Wk5zFr1IHJxacq2a2zi5RQ.png\" class=\"graf-image\" />\n</figure>### Special characters in regular expressions.\n<h3>Escaping</h3>\n<p>If you need to use any of the special characters literally (actually searching for a <code class=\"language-text\">\"*\"</code>, for instance), you must escape it by putting a <strong>backslash</strong> in front of it.</p>\n<p>For instance, to search for <code class=\"language-text\">\"a\"</code> followed by <code class=\"language-text\">\"*\"</code> followed by <code class=\"language-text\">\"b\"</code>,</p>\n<blockquote>\n<p>you'd use <code class=\"language-text\">/a\\*b/</code> --- the backslash \"escapes\" the <code class=\"language-text\">\"*\"</code>, making it literal instead of special.</p>\n</blockquote>\n<p>Similarly, if you're writing a regular expression literal and need to match a slash (\"/\"), you need to escape that (otherwise, it terminates the pattern)</p>\n<p>For instance, to search for the string \"/example/\" followed by one or more alphabetic characters, you'd use <code class=\"language-text\">/\\/example\\/[a-z]+/i</code></p>\n<p><strong>--the backslashes before each slash make them literal.</strong></p>\n<p>To match a literal backslash, you need to escape the backslash.</p>\n<p>For instance, to match the string \"C:\\\" where \"C\" can be any letter,</p>\n<p>you'd use <code class=\"language-text\">/[A-Z]:\\\\/</code></p>\n<p>--- the first backslash escapes the one after it, so the expression searches for a single literal backslash.</p>\n<p>If using the <code class=\"language-text\">RegExp</code> constructor with a string literal, <strong>remember that the backslash is an escape in string literals, so to use it in the regular expression, you need to escape it at the string literal level</strong>.</p>\n<p><code class=\"language-text\">/a\\*b/</code> and <code class=\"language-text\">new RegExp(\"a\\\\*b\")</code> create the same expression,</p>\n<p>which searches for \"a\" followed by a literal \"*\" followed by \"b\".</p>\n<p>If escape strings are not already part of your pattern you can add them using <code class=\"language-text\">String.replace</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function escapeRegExp(string) {\n  return string.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&amp;'); // $&amp; means the whole matched string\n}</code></pre></div>\n<p><strong>The \"g\" after the regular expression is an option or flag that performs a global search, looking in the whole string and returning all matches.</strong></p>\n<h3>Using parentheses</h3>\n<p>Parentheses around any part of the regular expression pattern causes that part of the matched substring to be remembered.</p>\n<p>Once remembered, the substring can be recalled for other use.</p>\n<h3>Using regular expressions in JavaScript</h3>\n<p>Regular expressions are used with the <code class=\"language-text\">RegExp</code> <strong>methods</strong></p>\n<p><code class=\"language-text\">test()</code> <strong>and</strong> <code class=\"language-text\">exec()</code></p>\n<p>and with the <code class=\"language-text\">String</code> <strong>methods</strong> <code class=\"language-text\">match()</code><strong>,</strong> <code class=\"language-text\">replace()</code><strong>,</strong> <code class=\"language-text\">search()</code><strong>, and</strong> <code class=\"language-text\">split()</code><strong>.</strong></p>\n<hr>\n<h3>Method Descriptions</h3>\n<h4><code class=\"language-text\">exec()</code></h4>\n<p>Executes a search for a match in a string.</p>\n<p>It returns an array of information or <code class=\"language-text\">null</code> on a mismatch.</p>\n<h4><code class=\"language-text\">test()</code></h4>\n<p>Tests for a match in a string.</p>\n<p>It returns <code class=\"language-text\">true</code> or <code class=\"language-text\">false</code>.</p>\n<h4><code class=\"language-text\">match()</code></h4>\n<p>Returns an array containing all of the matches, including capturing groups, or <code class=\"language-text\">null</code> if no match is found.</p>\n<h4><code class=\"language-text\">matchAll()</code></h4>\n<p>Returns an iterator containing all of the matches, including capturing groups.</p>\n<h4><code class=\"language-text\">search()</code></h4>\n<p>Tests for a match in a string.</p>\n<p>It returns the index of the match, or <code class=\"language-text\">-1</code> if the search fails.</p>\n<h4><code class=\"language-text\">replace()</code></h4>\n<p>Executes a search for a match in a string, and replaces the matched substring with a replacement substring.</p>\n<h4><code class=\"language-text\">replaceAll()</code></h4>\n<p>Executes a search for all matches in a string, and replaces the matched substrings with a replacement substring.</p>\n<h4><code class=\"language-text\">split()</code></h4>\n<p>Uses a regular expression or a fixed string to break a string into an array of substrings.</p>\n<h3>Methods that use regular expressions</h3>\n<p>When you want to know whether a pattern is found in a string, use the <code class=\"language-text\">test()</code> or <code class=\"language-text\">search()</code> methods;</p>\n<p>for more information (but slower execution) use the <code class=\"language-text\">exec()</code> or <code class=\"language-text\">match()</code> methods.</p>\n<p>If you use <code class=\"language-text\">exec()</code> or <code class=\"language-text\">match()</code> and if the match succeeds, these methods return an array and update properties of the associated regular expression object and also of the predefined regular expression object, <code class=\"language-text\">RegExp</code>.</p>\n<p>If the <strong>match fails, the</strong> <code class=\"language-text\">exec()</code> <strong>method returns</strong> <code class=\"language-text\">null</code> (which coerces to <code class=\"language-text\">false</code>).</p>\n<p>In the following example, the script uses the <code class=\"language-text\">exec()</code> method to find a match in a string.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myRe = /d(b+)d/g;\nlet myArray = myRe.exec('cdbbdbsbz');</code></pre></div>\n<p>If you do not need to access the properties of the regular expression, an alternative way of creating <code class=\"language-text\">myArray</code> is with this script:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myArray = /d(b+)d/g.exec('cdbbdbsbz');\n    // similar to \"cdbbdbsbz\".match(/d(b+)d/g); however,\n    // \"cdbbdbsbz\".match(/d(b+)d/g) outputs Array [ \"dbbd\" ], while\n    // /d(b+)d/g.exec('cdbbdbsbz') outputs Array [ 'dbbd', 'bb', index: 1, input: 'cdbbdbsbz' ].</code></pre></div>\n<p>(See <a href=\"https://github.com/bgoonz/Cheat-Sheets/blob/master/Regular_Expressions.md#g-different-behaviors\" class=\"markup--anchor markup--p-anchor\">different behaviors</a> for further info about the different behaviors.)</p>\n<p>If you want to construct the regular expression from a string, yet another alternative is this script:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myRe = new RegExp('d(b+)d', 'g');\nlet myArray = myRe.exec('cdbbdbsbz');</code></pre></div>\n<p>With these scripts, the match succeeds and returns the array and updates the properties shown in the following table.</p>\n<p>Results of regular expression execution.</p>\n<p>You can use a regular expression created with an object initializer without assigning it to a letiable.</p>\n<p>If you do, however, every occurrence is a new regular expression.</p>\n<p>For this reason, if you use this form without assigning it to a letiable, you cannot subsequently access the properties of that regular expression.</p>\n<p>For example, assume you have this script:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myRe = /d(b+)d/g;\nlet myArray = myRe.exec('cdbbdbsbz');\nconsole.log('The value of lastIndex is ' + myRe.lastIndex);\n\n// \"The value of lastIndex is 5\"</code></pre></div>\n<p>However, if you have this script:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myArray = /d(b+)d/g.exec('cdbbdbsbz');\nconsole.log('The value of lastIndex is ' + /d(b+)d/g.lastIndex);\n\n// \"The value of lastIndex is 0\"</code></pre></div>\n<p>The occurrences of <code class=\"language-text\">/d(b+)d/g</code> in the two statements are different regular expression objects and hence have different values for their <code class=\"language-text\">lastIndex</code> property.</p>\n<p>If you need to access the properties of a regular expression created with an object initializer, you should first assign it to a variable.</p>\n<h3>[Advanced searching with flags]</h3>\n<p>Regular expressions have <strong>six optional flags</strong> that allow for functionality like global and case insensitive searching.</p>\n<p>These flags can be used separately or together in any order, and are included as part of the regular expression.</p>\n<p>Flag Description Corresponding property</p>\n<hr>\n<p><code class=\"language-text\">g</code> Global search. <code class=\"language-text\">RegExp.prototype.global</code></p>\n<p><code class=\"language-text\">i</code> Case-insensitive search. <code class=\"language-text\">RegExp.prototype.ignoreCase</code></p>\n<p><code class=\"language-text\">m</code> Multi-line search. <code class=\"language-text\">RegExp.prototype.multiline</code></p>\n<p><code class=\"language-text\">s</code> Allows <code class=\"language-text\">.</code> to match newline characters. <code class=\"language-text\">RegExp.prototype.dotAll</code></p>\n<p><code class=\"language-text\">u</code> \"unicode\"; treat a pattern as a sequence of unicode code points. <code class=\"language-text\">RegExp.prototype.unicode</code></p>\n<p><code class=\"language-text\">y</code> Perform a \"sticky\" search that matches starting at the current position in the target string. <code class=\"language-text\">RegExp.prototype.sticky</code></p>\n<h4>Regular expression flags</h4>\n<p><em>To include a flag with the regular expression, use this syntax:</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = /pattern/flags;</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = new RegExp('pattern', 'flags');</code></pre></div>\n<p>Note that the flags are an integral part of a regular expression. They cannot be added or removed later.</p>\n<p>For example, <code class=\"language-text\">re = /\\w+\\s/g</code> creates a regular expression that looks for one or more characters followed by a space, and it looks for this combination throughout the string.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = /\\w+\\s/g;\nlet str = 'fee fi fo fum';\nlet myArray = str.match(re);\nconsole.log(myArray);\n\n// [\"fee \", \"fi \", \"fo \"]</code></pre></div>\n<p>You could replace the line:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = /\\w+\\s/g;</code></pre></div>\n<p>with:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = new RegExp('\\\\w+\\\\s', 'g');</code></pre></div>\n<p>and get the same result.</p>\n<p>The behavior associated with the <code class=\"language-text\">g</code> flag is different when the <code class=\"language-text\">.exec()</code> method is used.</p>\n<p>The roles of \"class\" and \"argument\" get reversed:</p>\n<p>In the case of <code class=\"language-text\">.match()</code>, the string class (or data type) owns the method and the regular expression is just an argument,</p>\n<p>while in the case of <code class=\"language-text\">.exec()</code>, it is the regular expression that owns the method, with the string being the argument.</p>\n<p>Contrast this <code class=\"language-text\">str.match(re)</code> versus <code class=\"language-text\">re.exec(str)</code>.</p>\n<p>The <code class=\"language-text\">g</code> flag is used with the <code class=\"language-text\">.exec()</code> method to get iterative progression.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let xArray; while(xArray = re.exec(str)) console.log(xArray);\n// produces:\n// [\"fee \", index: 0, input: \"fee fi fo fum\"]\n// [\"fi \", index: 4, input: \"fee fi fo fum\"]\n// [\"fo \", index: 7, input: \"fee fi fo fum\"]</code></pre></div>\n<p>The <code class=\"language-text\">m</code> flag is used to specify that a multiline input string should be treated as multiple lines.</p>\n<p>If the <code class=\"language-text\">m</code> flag is used, <code class=\"language-text\">^</code> and <code class=\"language-text\">$</code> match at the start or end of any line within the input string instead of the start or end of the entire string.</p>\n<h3>Using special characters to verify input</h3>\n<p>In the following example, the user is expected to enter a phone number. When the user presses the \"Check\" button, the script checks the validity of the number. If the number is valid (matches the character sequence specified by the regular expression), the script shows a message thanking the user and confirming the number. If the number is invalid, the script informs the user that the phone number is not valid.</p>\n<p>Within non-capturing parentheses <code class=\"language-text\">(?:</code> , the regular expression looks for three numeric characters <code class=\"language-text\">\\d{3}</code> OR <code class=\"language-text\">|</code> a left parenthesis <code class=\"language-text\">\\(</code> followed by three digits<code class=\"language-text\">\\d{3}</code>, followed by a close parenthesis <code class=\"language-text\">\\)</code>, (end non-capturing parenthesis <code class=\"language-text\">)</code>), followed by one dash, forward slash, or decimal point and when found, remember the character <code class=\"language-text\">([-\\/\\.])</code>, followed by three digits <code class=\"language-text\">\\d{3}</code>, followed by the remembered match of a dash, forward slash, or decimal point <code class=\"language-text\">\\1</code>, followed by four digits <code class=\"language-text\">\\d{4}</code>.</p>\n<p>The <code class=\"language-text\">Change</code> event activated when the user presses Enter sets the value of <code class=\"language-text\">RegExp.input</code>.</p>\n<h4>HTML</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>\n  Enter your phone number (with area code) and then click \"Check\".\n  &lt;br>\n  The expected format is like ###-###-####.\n&lt;/p>\n&lt;form action=\"#\">\n  &lt;input id=\"phone\">\n    &lt;button onclick=\"testInfo(document.getElementById('phone'));\">Check&lt;/button>\n&lt;/form></code></pre></div>\n<h4>JavaScript</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = /(?:\\d{3}|\\(\\d{3}\\))([-\\/\\.])\\d{3}\\1\\d{4}/;\nfunction testInfo(phoneInput) {\n  let OK = re.exec(phoneInput.value);\n  if (!OK) {\n    console.error(phoneInput.value + ' isn\\'t a phone number with area code!');\n  } else {\n    console.log('Thanks, your phone number is ' + OK[0]);}\n}</code></pre></div>\n<h3>Cheat Sheet</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*VmpGy_BYCekOncdyrgSrxw.png\" class=\"graf-image\" />\n</figure>#### If you found this guide helpful feel free to checkout my GitHub/gist's where I host similar content:\n<blockquote>\n<a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--blockquote-anchor\">\n<strong>bgoonz's</strong> gists · GitHub</a>\n</blockquote>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>Or Checkout my personal Resource Site:</p>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\">\n<strong>a/A-Student-Resources</strong>\n<br />\n<em>Edit description</em>goofy-euclid-1cd736.netlify.app</a>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/4d8fb3eb146b\">March 6, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/regular-expressions-4d8fb3eb146b\" class=\"p-canonical\">Canonical link</a></p>\n<p>August 17, 2021.</p>"},{"url":"/docs/ds-algo/ds-overview/","relativePath":"docs/ds-algo/ds-overview.md","relativeDir":"docs/ds-algo","base":"ds-overview.md","name":"ds-overview","frontmatter":{"title":"What are data structures","weight":0,"excerpt":"Data structures, at a high level, are techniques for storing and organizing data that make it easier to modify, navigate, and access. Data structures determine how data is collected, the functions we can use to access it, and the relationships between data.","seo":{"title":" What are data structures","description":"Data structures are used in almost all areas of computer science and programming, from operating systems to basic vanilla code to artificial intelligence.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>What are data structures</h1>\n<p>Data structures, at a high level, are techniques for storing and organizing data that make it easier to modify, navigate, and access. Data structures determine how data is collected, the functions we can use to access it, and the relationships between data.</p>\n<p>Data structures are used in almost all areas of computer science and programming, from operating systems to basic vanilla code to artificial intelligence.</p>\n<p>Data structures enable us to:</p>\n<ul>\n<li>Manage and utilize large datasets</li>\n<li>Search for particular data from a database</li>\n<li>Design algorithms that are tailored towards particular programs</li>\n<li>Handle multiple requests from users at once</li>\n<li>Simplify and speed up data processing</li>\n</ul>\n<p>Data structures are vital for efficient, real-world problem solving. After all, the way we organize data has a lot of impact on performance and useability. In fact, most top companies require a strong understanding of data structures.</p>\n<blockquote>\n<p>Anyone looking to crack the coding interview will need to master data structures.</p>\n</blockquote>\n<p>JavaScript has primitive and non-primitive data structures. Primitive data structures and data types are native to the programming language. These include boolean, null, number, string, etc.</p>\n<p>Non-primitive data structures are not defined by the programming language but rather by the programmer. These include linear data structures, static data structures, and dynamic data structures, like queue and linked lists.</p>\n<h2>1. Array</h2>\n<p>The most basic of all data structures, an array stores data in memory for later use. Each array has a fixed number of cells decided on its creation, and each cell has a corresponding numeric index used to select its data. Whenever you'd like to use the array, all you need are the desired indices, and you can access any of the data within.</p>\n<p><img src=\"https://www.educative.io/api/page/6094484883374080/image/download/5163503745761280\" alt=\"image\"></p>\n<p>Advantages</p>\n<ul>\n<li>Simple to create and use.</li>\n<li>Foundational building block for complex data structures</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Fixed size</li>\n<li>Expensive to insert/delete or resequence values</li>\n<li>Inefficient to sort</li>\n</ul>\n<h3>Applications</h3>\n<ul>\n<li>Basic spreadsheets</li>\n<li>Within complex structures such as hash tables</li>\n</ul>\n<h2>2. Queues</h2>\n<p>Queues are conceptually similar to stacks; both are sequential structures, but queues process elements in the order they were entered rather than the most recent element.</p>\n<p>As a result, queues can be thought of as a FIFO (First In, First Out) version of stacks. These are helpful as a buffer for requests, storing each request in the order it was received until it can be processed.</p>\n<p><img src=\"https://www.educative.io/api/page/6094484883374080/image/download/4608256413532160\" alt=\"image\"></p>\n<p>For a visual, consider a single-lane tunnel: the first car to enter is the first car to exit. If other cars should wish to exit, but the first stops, all cars will have to wait for the first to exit before they can proceed.</p>\n<p>Advantages</p>\n<ul>\n<li>Dynamic size</li>\n<li>Orders data in the order it was received</li>\n<li>Low runtime</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Can only retrieve the oldest element</li>\n</ul>\n<h3>Applications</h3>\n<ul>\n<li>Effective as a buffer when receiving frequent data</li>\n<li>Convenient way to store order-sensitive data such as stored voicemails</li>\n<li>Ensures the oldest data is processed first</li>\n</ul>\n<h2>3. Linked List</h2>\n<p>Linked lists are a data structure which, unlike the previous three, does not use physical placement of data in memory. This means that, rather than indexes or positions, linked lists use a referencing system: elements are stored in nodes that contain a pointer to the next node, repeating until all nodes are linked.</p>\n<p>This system allows efficient insertion and removal of items without the need for reorganization.</p>\n<p><img src=\"https://www.educative.io/api/page/6094484883374080/image/download/4536246505308160\" alt=\"image\"></p>\n<p>Advantages</p>\n<ul>\n<li>Efficient insertion and removal of new elements</li>\n<li>Less complex than restructuring an array</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Uses more memory than arrays</li>\n<li>Inefficient to retrieve a specific element</li>\n<li>Inefficient to traverse the list backward</li>\n</ul>\n<h3>Applications</h3>\n<ul>\n<li>Best used when data must be added and removed in quick succession from unknown locations</li>\n</ul>\n<h2>4. Trees</h2>\n<p>Trees are another relation-based data structure, which specialize in representing hierarchical structures. Like a linked list, nodes contain both elements of data and pointers marking its relation to immediate nodes.</p>\n<p>Each tree has a \"root\" node, off of which all other nodes branch. The root contains references to all elements directly below it, which are known as its \"child nodes\". This continues, with each child node, branching off into more child nodes.</p>\n<p>Nodes with linked child nodes are called internal nodes while those without child nodes are external nodes. A common type of tree is the \"binary search tree\" which is used to easily search stored data.</p>\n<p>These search operations are highly efficient, as its search duration is dependent not on the number of nodes but on the number of levels down the tree.</p>\n<p><img src=\"https://www.educative.io/api/page/6094484883374080/image/download/4860454879887360\" alt=\"height of tree\"></p>\n<p>This type of tree is defined by four strict rules:</p>\n<ol>\n<li>The left subtree contains only nodes with elements lesser than the root.</li>\n<li>The right subtree contains only nodes with elements greater than the root.</li>\n<li>Left and right subtrees must also be a binary search tree. They must follow the above rules with the \"root\" of their tree.</li>\n<li>There can be no duplicate nodes, i.e. no two nodes can have the same value.</li>\n</ol>\n<p>Advantages</p>\n<ul>\n<li>Ideal for storing hierarchical relationships</li>\n<li>Dynamic size</li>\n<li>Quick at insert and delete operations</li>\n<li>In a binary search tree, inserted nodes are sequenced immediately.</li>\n<li>Binary search trees are efficient at searches; length is only O(height)O(height).</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Slow to rearrange nodes</li>\n<li>Child nodes hold no information about their parent node</li>\n<li>Binary search trees are not as fast as the more complicated hash table</li>\n<li>Binary search trees can degenerate into linear search (scanning all elements) if not implemented with balanced subtrees.</li>\n</ul>\n<h3>Applications</h3>\n<ul>\n<li>Storing hierarchical data such as a file location.</li>\n<li>Binary search trees are excellent for tasks needing searching or ordering of data.</li>\n</ul>\n<blockquote>\n<p><em>Enjoying the article? Scroll down to <a href=\"https://www.educative.io/blog/blog-newsletter-annoucement\">sign up</a> for our free, bi-monthly newsletter.</em></p>\n</blockquote>\n<h2>5. Graphs</h2>\n<p>Graphs are a relation-based data structure helpful for storing web-like relationships. Each node, or vertex, as they're called in graphs, has a title (A, B, C, etc.), a value contained within, and a list of links (called edges) it has with other vertices.</p>\n<p><img src=\"https://www.educative.io/api/page/6094484883374080/image/download/4912691077447680\" alt=\"image\"></p>\n<p>In the above example, each circle is a vertex, and each line is an edge. If produced in writing, this structure would look like:</p>\n<p><code class=\"language-text\">V = {a, b, c, d}</code></p>\n<p><code class=\"language-text\">E = {ab, ac, bc, cd}</code></p>\n<p>While hard to visualize at first, this structure is invaluable in conveying relationship charts in textual form, anything from circuitry to train networks.</p>\n<p>Advantages</p>\n<ul>\n<li>Can quickly convey visuals over text</li>\n<li>Usable to model a diverse number of subjects so long as they contain a relational structure</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>At a higher level, text can be time-consuming to convert to an image.</li>\n<li>It can be difficult to see the existing edges or how many edges a given vertex has connected to it</li>\n</ul>\n<h3>Applications</h3>\n<ul>\n<li>Network representations</li>\n<li>Modeling social networks, such as Facebook.</li>\n</ul>\n<h2>6. Hash Tables (Map)</h2>\n<p>Hash tables are a complex data structure capable of storing large amounts of information and retrieving specific elements efficiently. This data structure relies on the concept of key/value pairs, where the \"key\" is a searched string and the \"value\" is the data paired with that key.</p>\n<p><img src=\"https://www.educative.io/api/page/6094484883374080/image/download/6745911163092992\" alt=\"key value pair\"> Each searched key is converted from its string form into a numerical value, called a hash, using a predefined hash function. This hash then points to a storage bucket -- a smaller subgroup within the table. It then searches the bucket for the originally entered key and returns the value associated with that key.</p>\n<p>Advantages</p>\n<ul>\n<li>Key can be in any form, while array's indices must be integers</li>\n<li>Highly efficient search function</li>\n<li>Constant number of operations for each search</li>\n<li>Constant cost for insertion or deletion operations</li>\n</ul>\n<p>Disadvantages</p>\n<ul>\n<li>Collisions: an error caused when two keys convert to the same hash code or two hash codes point to the same value.</li>\n<li>These errors can be common and often require an overhaul of the hash function.</li>\n</ul>\n<h3>Applications</h3>\n<ul>\n<li>Database storage</li>\n<li>Address lookups by name</li>\n</ul>\n<p>Each hash table can be very different, from the types of the keys and values, to the way their hash functions work. Due to these differences and the multi-layered aspects of a hash table, it is nearly impossible to encapsulate so generally.</p>\n<h2>Data structure interview questions</h2>\n<details>\n<summary> 🔥See Interview Questions </summary>\n<p>For many developers and programmers, data structures are most important for <a href=\"https://www.educative.io/blog/acing-the-javascript-interview-top-questions-explained\">cracking Javascript coding interviews</a>. Questions and problems on data structures are fundamental to modern-day coding interviews. In fact, they have a lot to say over your hireability and entry-level rate as a candidate.</p>\n<p>Today, we will be going over seven common coding interview questions for JavaScript data structures, one for each of the data structures we discussed above. Each will also discuss its time complexity based on the <a href=\"https://www.educative.io/blog/a-big-o-primer-for-beginning-devs\">BigO notation</a> theory.</p>\n<h3>Array: Remove all even integers from an array</h3>\n<p>Problem statement: Implement a function <code class=\"language-text\">removeEven(arr)</code>, which takes an array arr in its input and removes all the even elements from a given array.</p>\n<p>Input: An array of random integers</p>\n<div class=\"gatsby-highlight\" data-language=\"txt\"><pre class=\"language-txt\"><code class=\"language-txt\">[1,2,4,5,10,6,3]</code></pre></div>\n<p>Output: an array containing only odd integers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[1,5,3]</code></pre></div>\n<p>There are two ways you could solve this coding problem in an interview. Let's discuss each.</p>\n<h4>Solution #1: Doing it \"by hand\"</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">removeEven</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> odds <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> number <span class=\"token keyword\">of</span> arr<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>number <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">!=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n            <span class=\"token comment\">// Check if the item in the list is NOT even ('%' is the modulus symbol!)</span>\n            odds<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//If it isn't even append it to the empty list</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> odds<span class=\"token punctuation\">;</span> <span class=\"token comment\">// Return the new list</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">let</span> example <span class=\"token operator\">=</span> <span class=\"token function\">removeEven</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">41</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">34</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'EXAMPLE:'</span><span class=\"token punctuation\">,</span> example<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//EXAMPLE: [ 3, 41, 3 ]</span></code></pre></div>\n<p>This approach starts with the first element of the array. If that current element is not even, it pushes this element into a new array. If it is even, it will move to the next element, repeating until it reaches the end of the array. In regards to time complexity, since the entire array has to be iterated over, this solution is in <em>O(n)O(n).</em></p>\n<h4>Solution #2: Using filter() and lambda function</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">removeEven</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">v</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">!=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">removeEven</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">41</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">34</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This solution also begins with the first element and checks if it is even. If it is even, it filters out this element. If not, skips to the next element, repeating this process until it reaches the end of the array.</p>\n<p>The filter function uses lambda or arrow functions, which use shorter, simpler syntax. The filter filters out the element for which the lambda function returns false. The time complexity of this is the same as the time complexity of the previous solution.</p>\n<h3>Stack: Check for balanced parentheses using a stack</h3>\n<p>Problem statement: Implement the <code class=\"language-text\">isBalanced()</code> function to take a string containing only curly <code class=\"language-text\">{}</code>, square <code class=\"language-text\">[]</code>, and round <code class=\"language-text\">()</code> parentheses. The function should tell us if all the parentheses in the string are balanced. This means that every opening parenthesis will have a closing one. For example, <code class=\"language-text\">{[]}</code> is balanced, but <code class=\"language-text\">{[}]</code> is not.</p>\n<p>Input: A string consisting solely of <code class=\"language-text\">(</code>, <code class=\"language-text\">)</code>, <code class=\"language-text\">{</code>, <code class=\"language-text\">}</code>, <code class=\"language-text\">[</code> and <code class=\"language-text\">]</code></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexp <span class=\"token operator\">=</span> <span class=\"token string\">'{[({})]}'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Output: Returns <code class=\"language-text\">False</code> if the expression doesn't have balanced parentheses. If it does, the function returns <code class=\"language-text\">True</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">True</code></pre></div>\n<p>To solve this problem, we can simply use a stack of characters. Look below at the code to see how it works.</p>\n<p>index.js</p>\n<p>Stack.js</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token string\">\"use strict\"</span><span class=\"token punctuation\">;</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Stack</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>top <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">getTop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length <span class=\"token operator\">==</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>top<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">isEmpty</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">size</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">push</span><span class=\"token punctuation\">(</span> <span class=\"token parameter\">element</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span> element <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>top <span class=\"token operator\">=</span> element<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length <span class=\"token operator\">!=</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length <span class=\"token operator\">==</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>top <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>This process will iterate over the string one character at a time. We can determine that the string is unbalanced based on two factors:</p>\n<ol>\n<li>The stack is empty.</li>\n<li>The top element in the stack is not the right type.</li>\n</ol>\n<p>If either of these conditions is true, we return <code class=\"language-text\">False</code>. If the parenthesis is an opening parenthesis, it is pushed into the stack. If by the end all are balanced, the stack will be empty. If it is not empty, we return <code class=\"language-text\">False</code>. Since we traverse the string exp only once, the time complexity is <em>O(n)</em>.</p>\n<h3>Queue: Generate Binary Numbers from 1 to n</h3>\n<p>Problem statement: Implement a function <code class=\"language-text\">findBin(n)</code>, which will generate binary numbers from <code class=\"language-text\">1</code> to <code class=\"language-text\">n</code> in the form of a string using a queue.</p>\n<p>Input: A positive integer n</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nn <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Output: Returns binary numbers in the form of strings from <code class=\"language-text\">1</code> up to <code class=\"language-text\">n</code></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nresult <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'1'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'11'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The easiest way to solve this problem is using a queue to generate new numbers from previous numbers. Let's break that down.</p>\n<p>index.js</p>\n<p>Queue.js</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token string\">\"use strict\"</span><span class=\"token punctuation\">;</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Queue</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>front <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>back <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">isEmpty</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">getFront</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length <span class=\"token operator\">!=</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">[</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">size</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span> <span class=\"token parameter\">element</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span> element <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<p>The key is to generate consecutive binary numbers by appending 0 and 1 to previous binary numbers. To clarify,</p>\n<ul>\n<li>10 and 11 can be generated if 0 and 1 are appended to 1.</li>\n<li>100 and 101 are generated if 0 and 1 are appended to 10.</li>\n</ul>\n<p>Once we generate a binary number, it is then enqueued to a queue so that new binary numbers can be generated if we append 0 and 1 when that number will be enqueued.</p>\n<p>Since a queue follows the <em>First-In First-Out</em> property, the enqueued binary numbers are dequeued so that the resulting array is mathematically correct.</p>\n<p>Look at the code above. On line 7, <code class=\"language-text\">1</code> is enqueued. To generate the sequence of binary numbers, a number is dequeued and stored in the array <code class=\"language-text\">result</code>. On lines 11-12, we append <code class=\"language-text\">0</code> and <code class=\"language-text\">1</code> to produce the next numbers.</p>\n<p>Those new numbers are also enqueued at lines 14-15. The queue will take integer values, so it converts the string to an integer as it is enqueued.</p>\n<p>The time complexity of this solution is in <em>O(n)O(n)</em> since constant-time operations are executed for n times.</p>\n<h3>Linked List: Reverse a linked list</h3>\n<p>Problem statement: Write the <code class=\"language-text\">reverse</code> function to take a singly linked list and reverse it in place.</p>\n<p>Input: a singly linked list</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nLinkedList <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token operator\">-</span><span class=\"token operator\">></span><span class=\"token number\">1</span><span class=\"token operator\">-</span><span class=\"token operator\">></span><span class=\"token number\">2</span><span class=\"token operator\">-</span><span class=\"token operator\">></span><span class=\"token number\">3</span><span class=\"token operator\">-</span><span class=\"token number\">4</span></code></pre></div>\n<p>Output: a reverse linked list</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nLinkedList <span class=\"token operator\">=</span> <span class=\"token number\">4</span><span class=\"token operator\">-</span><span class=\"token operator\">></span><span class=\"token number\">3</span><span class=\"token operator\">-</span><span class=\"token operator\">></span><span class=\"token number\">2</span><span class=\"token operator\">-</span><span class=\"token operator\">></span><span class=\"token number\">1</span><span class=\"token operator\">-</span><span class=\"token operator\">></span><span class=\"token number\">0</span></code></pre></div>\n<p>The easiest way to solve this problem is by using iterative pointer manipulation. Let's take a look.</p>\n<p>index.js</p>\n<p>LinkedList.js</p>\n<p>Node.js</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token string\">\"use strict\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> Node <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span> <span class=\"token string\">'./Node.js'</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">LinkedList</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">//Insertion At Head</span>\n    <span class=\"token function\">insertAtHead</span><span class=\"token punctuation\">(</span> <span class=\"token parameter\">newData</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">let</span> tempNode <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Node</span><span class=\"token punctuation\">(</span> newData <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      tempNode<span class=\"token punctuation\">.</span>nextElement <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> tempNode<span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//returning the updated list</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">isEmpty</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">==</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">//function to print the linked list</span>\n    <span class=\"token function\">printList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">isEmpty</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span> <span class=\"token string\">\"Empty List\"</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span> temp <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            process<span class=\"token punctuation\">.</span>stdout<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span> <span class=\"token function\">String</span><span class=\"token punctuation\">(</span> temp<span class=\"token punctuation\">.</span>data <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            process<span class=\"token punctuation\">.</span>stdout<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span> <span class=\"token string\">\" -> \"</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            temp <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">.</span>nextElement<span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>We use a loop to iterate through the input list. For a <code class=\"language-text\">current</code> node, its link with the <code class=\"language-text\">previous</code> node is reversed. then, <code class=\"language-text\">next</code> stores the next node in the list. Let's break that down by line.</p>\n<ul>\n<li>Line 22- Store the <code class=\"language-text\">current</code> node's <code class=\"language-text\">nextElement</code> in <code class=\"language-text\">next</code></li>\n<li>Line 23 - Set <code class=\"language-text\">current</code> node's <code class=\"language-text\">nextElement</code> to <code class=\"language-text\">previous</code></li>\n<li>Line 24 - Make the <code class=\"language-text\">current</code> node the new <code class=\"language-text\">previous</code> for the next iteration</li>\n<li>Line 25 - Use <code class=\"language-text\">next</code> to go to the next node</li>\n<li>Line 29 - We reset the <code class=\"language-text\">head</code> pointer to point at the last node</li>\n</ul>\n<p>Since the list is traversed only once, the algorithm runs in <em>O(n)</em>.</p>\n<h3>Tree: Find the Minimum Value in a Binary Search Tree</h3>\n<p>Problem statement: Use the <code class=\"language-text\">findMin(root)</code> function to find the minimum value in a Binary Search Tree.</p>\n<p>Input: a root node for a binary search tree</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nbst <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>    <span class=\"token number\">6</span> <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token number\">9</span>    <span class=\"token number\">4</span> <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span>    <span class=\"token number\">9</span> <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">12</span>    <span class=\"token number\">12</span> <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">14</span><span class=\"token punctuation\">}</span>where parent <span class=\"token operator\">-</span><span class=\"token operator\">></span> leftChild<span class=\"token punctuation\">,</span>rightChild</code></pre></div>\n<p>Output: the smallest integer value from that binary search tree</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2</code></pre></div>\n<p>Let's look at an easy solution for this problem.</p>\n<h4>Solution: Iterative <code class=\"language-text\">findMin( )</code></h4>\n<p>This solution begins by checking if the root is <code class=\"language-text\">null</code>. It returns <code class=\"language-text\">null</code> if so. It then moves to the left subtree and continues with each node's left child until the left-most child is reached.</p>\n<p>index.js</p>\n<p>BinarySearchTree.js</p>\n<p>Node.js</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> Node <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./Node.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">BinarySearchTree</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">rootValue</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Node</span><span class=\"token punctuation\">(</span>rootValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">currentNode<span class=\"token punctuation\">,</span> newValue</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Node</span><span class=\"token punctuation\">(</span>newValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>newValue <span class=\"token operator\">&lt;</span> currentNode<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            currentNode<span class=\"token punctuation\">.</span>leftChild <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>leftChild<span class=\"token punctuation\">,</span> newValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            currentNode<span class=\"token punctuation\">.</span>rightChild <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>rightChild<span class=\"token punctuation\">,</span> newValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> currentNode<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">insertBST</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">newValue</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Node</span><span class=\"token punctuation\">(</span>newValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">,</span> newValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">preOrderPrint</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">currentNode</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">preOrderPrint</span><span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>leftChild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3>Graph: Remove Edge</h3>\n<p>Problem statement: Implement the removeEdge function to take a source and a destination as arguments. It should detect if an edge exists between them.</p>\n<p>Input: A graph, a source, and a destination</p>\n<p><img src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjA4MCIgaGVpZ2h0PSIyOTEwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIvPg==\" alt=\"image\"></p>\n<p><img src=\"https://www.educative.io/cdn-cgi/image/f=auto,fit=contain,w=600/api/page/6094484883374080/image/download/6576135669284864\" alt=\"widget\"></p>\n<p><img src=\"https://www.educative.io/cdn-cgi/image/f=auto,fit=contain,w=300,q=10/api/page/6094484883374080/image/download/6576135669284864\" alt=\"widget\"></p>\n<p>Output: A graph with the edge between the source and the destination removed.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span>graph<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><img src=\"https://www.educative.io/cdn-cgi/image/f=auto,fit=contain,w=600/api/page/6094484883374080/image/download/6038590984290304\" alt=\"widget\"></p>\n<p><img src=\"https://www.educative.io/cdn-cgi/image/f=auto,fit=contain,w=300,q=10/api/page/6094484883374080/image/download/6038590984290304\" alt=\"widget\"></p>\n<p>The solution to this problem is fairly simple: we use Indexing and deletion. Take a look</p>\n<p>index.js</p>\n<p>Graph.js</p>\n<p>LinkedList.js</p>\n<p>Node.js</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> LinkedList <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./LinkedList.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> Node <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./Node.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Graph</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vertices</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices <span class=\"token operator\">=</span> vertices<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> it<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>it <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> it <span class=\"token operator\">&lt;</span> vertices<span class=\"token punctuation\">;</span> it<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">LinkedList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>temp<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">source<span class=\"token punctuation\">,</span> destination</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>source <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices <span class=\"token operator\">&amp;&amp;</span> destination <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>vertices<span class=\"token punctuation\">)</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span>source<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">insertAtHead</span><span class=\"token punctuation\">(</span>destination<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">printGraph</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'>>Adjacency List of Directed Graph&lt;&lt;'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> i<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            process<span class=\"token punctuation\">.</span>stdout<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">|</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token function\">String</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">| => </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Since our vertices are stored in an array, we can access the <code class=\"language-text\">source</code> linked list. We then call the <code class=\"language-text\">delete</code> function for linked lists. The time complexity for this solution is O(E) since we may have to traverse E edges.</p>\n<h3>Hash Table: Convert Max-Heap to Min-Heap</h3>\n<p>Problem statement: Implement the function <code class=\"language-text\">convertMax(maxHeap)</code> to convert a binary max-heap into a binary min-heap. <code class=\"language-text\">maxHeap</code> should be an array in the <code class=\"language-text\">maxHeap</code> format, i.e the parent is greater than its children.</p>\n<p>Input: a Max-Heap</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmaxHeap <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Output: returns the converted array</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nresult <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To solve this problem, we must min heapify all parent nodes. Take a look.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">minHeapify</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">heap<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> left <span class=\"token operator\">=</span> index <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> right <span class=\"token operator\">=</span> index <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> smallest <span class=\"token operator\">=</span> index<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>heap<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> left <span class=\"token operator\">&amp;&amp;</span> heap<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> heap<span class=\"token punctuation\">[</span>left<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        smallest <span class=\"token operator\">=</span> left<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>heap<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> right <span class=\"token operator\">&amp;&amp;</span> heap<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> heap<span class=\"token punctuation\">[</span>right<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> smallest <span class=\"token operator\">=</span> right<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>smallest <span class=\"token operator\">!=</span> index<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> tmp <span class=\"token operator\">=</span> heap<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        heap<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> heap<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        heap<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> tmp<span class=\"token punctuation\">;</span>\n        <span class=\"token function\">minHeapify</span><span class=\"token punctuation\">(</span>heap<span class=\"token punctuation\">,</span> smallest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> heap<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">convertMax</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">maxHeap</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>maxHeap<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">></span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> maxHeap <span class=\"token operator\">=</span> <span class=\"token function\">minHeapify</span><span class=\"token punctuation\">(</span>maxHeap<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> maxHeap<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> maxHeap <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">convertMax</span><span class=\"token punctuation\">(</span>maxHeap<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>We consider <code class=\"language-text\">maxHeap</code> to be a regular array and reorder it to accurately represent a min-heap. You can see this done in the code above. The <code class=\"language-text\">convertMax()</code> function then restores the heap property on all nodes from the lowest parent node by calling the <code class=\"language-text\">minHeapify()</code> function. In regards to time complexity, this solution takes <em>O(nlog(n))O(nlog(n))</em> time.</p>\n</details>"},{"url":"/docs/ds-algo/ds-in-javascript/","relativePath":"docs/ds-algo/ds-in-javascript.md","relativeDir":"docs/ds-algo","base":"ds-in-javascript.md","name":"ds-in-javascript","frontmatter":{"title":"Native Data Structures in JS","template":"docs","excerpt":"In javascript"},"html":"<h1>Data Structures</h1>\n<h1>JavaScript data types and data structures</h1>\n<p>Programming languages all have built-in data structures, but these often differ from one language to another. This article attempts to list the built-in data structures available in JavaScript and what properties they have. These can be used to build other data structures. Wherever possible, comparisons with other languages are drawn.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#dynamic_typing\" title=\"Permalink to Dynamic typing\">Dynamic typing</a></h2>\n<p>JavaScript is a <em>loosely typed</em> and <em>dynamic</em>language. Variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned (and re-assigned) values of all types:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#javascript_types\" title=\"Permalink to JavaScript types\">JavaScript types</a></h2>\n<p>The set of types in the JavaScript language consists of <em><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values\">primitive values</a></em> and <em><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#objects\">objects</a></em>.</p>\n<ul>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values\">Primitive values</a> (immutable datum represented directly at the lowest level of the language)</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type\">Boolean type</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type\">Null type</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type\">Undefined type</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type\">Number type</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#bigint_type\">BigInt type</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type\">String type</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type\">Symbol type</a></li>\n</ul>\n</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#objects\">Objects</a> (collections of properties)</li>\n</ul>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values\" title=\"Permalink to Primitive values\">Primitive values</a></h2>\n<p>All types except objects define immutable values (that is, values which can't be changed). For example (and unlike in C), Strings are immutable. We refer to values of these types as \"<em>primitive values</em>\".</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type\" title=\"Permalink to Boolean type\">Boolean type</a></h3>\n<p>Boolean represents a logical entity and can have two values: <code class=\"language-text\">true</code> and <code class=\"language-text\">false</code>. See <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Boolean\">Boolean</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean\"><code class=\"language-text\">Boolean</code></a> for more details.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type\" title=\"Permalink to Null type\">Null type</a></h3>\n<p>The Null type has exactly one value: <code class=\"language-text\">null</code>. See <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null\"><code class=\"language-text\">null</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Null\">Null</a> for more details.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type\" title=\"Permalink to Undefined type\">Undefined type</a></h3>\n<p>A variable that has not been assigned a value has the value <code class=\"language-text\">undefined</code>. See <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined\"><code class=\"language-text\">undefined</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/undefined\">Undefined</a> for more details.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#numeric_types\" title=\"Permalink to Numeric types\">Numeric types</a></h3>\n<p>ECMAScript has two built-in numeric types: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number-type\">Number</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#bigint-type\">BigInt</a> — along with the related value <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#nan\">NaN</a>.</p>\n<h4>Number type</h4>\n<p>The Number type is a <a href=\"https://en.wikipedia.org/wiki/Double_precision_floating-point_format\">double-precision 64-bit binary format IEEE 754 value</a>. It is capable of storing floating-point numbers between 2^-1074 and 2^1024, but can only safely store integers in the range -(2^53 − 1) to 2^53 − 1. Values outside of the range from <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE\"><code class=\"language-text\">Number.MIN_VALUE</code></a> to <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE\"><code class=\"language-text\">Number.MAX_VALUE</code></a> are automatically converted to either <code class=\"language-text\">+Infinity</code> or <code class=\"language-text\">-Infinity</code>, which behave similarly to mathematical infinity, but with some slight differences; see <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY\"><code class=\"language-text\">Number.POSITIVE_INFINITY</code></a> for details.</p>\n<p><strong>Note:</strong> You are can check if a number is in the double-precision floating-point number range using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger\"><code class=\"language-text\">Number.isSafeInteger()</code></a> Outside the range from <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER\"><code class=\"language-text\">Number.MIN_SAFE_INTEGER</code></a> to <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER\"><code class=\"language-text\">Number.MAX_SAFE_INTEGER</code></a>, JavaScript can no longer safely represent integers; they will instead be represented by a double-precision floating point approximation.</p>\n<p>The number type has only one integer with multiple representations: <code class=\"language-text\">0</code> is represented as both <code class=\"language-text\">-0</code> and <code class=\"language-text\">+0</code> (where <code class=\"language-text\">0</code> is an alias for <code class=\"language-text\">+0</code>). In practice, there is almost no difference between the different representations; for example, <code class=\"language-text\">+0 === -0</code> is <code class=\"language-text\">true</code>. However, you are able to notice this when you divide by zero:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>Although a number often represents only its value, JavaScript provides <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators\"><code class=\"language-text\">binary (bitwise) operators</code></a>.</p>\n<p><strong>Note:</strong> Although bitwise operators <em>can</em> be used to represent several Boolean values within a single number using <a href=\"https://en.wikipedia.org/wiki/Mask_%28computing%29\">bit masking</a>, this is usually considered a bad practice. JavaScript offers other means to represent a set of Booleans (like an array of Booleans, or an object with Boolean values assigned to named properties). Bit masking also tends to make the code more difficult to read, understand, and maintain.</p>\n<p>It may be necessary to use such techniques in very constrained environments, like when trying to cope with the limitations of local storage, or in extreme cases (such as when each bit over the network counts). This technique should only be considered when it is the last measure that can be taken to optimize size.</p>\n<h4>BigInt type</h4>\n<p>The BigInt type is a numeric primitive in JavaScript that can represent integers with arbitrary precision. With BigInts, you can safely store and operate on large integers even beyond the safe integer limit for Numbers.</p>\n<p>A BigInt is created by appending <code class=\"language-text\">n</code> to the end of an integer or by calling the constructor.</p>\n<p>You can obtain the largest safe value that can be incremented with Numbers by using the constant <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER\"><code class=\"language-text\">Number.MAX_SAFE_INTEGER</code></a>. With the introduction of BigInts, you can operate with numbers beyond the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER\"><code class=\"language-text\">Number.MAX_SAFE_INTEGER</code></a>.</p>\n<p>This example demonstrates, where incrementing the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER\"><code class=\"language-text\">Number.MAX_SAFE_INTEGER</code></a> returns the expected result:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>You can use the operators <code class=\"language-text\">+</code>, <code class=\"language-text\">*</code>, <code class=\"language-text\">-</code>, <code class=\"language-text\">**</code>, and <code class=\"language-text\">%</code>with BigInts—just like with Numbers. A BigInt is not strictly equal to a Number, but it is loosely so.</p>\n<p>A BigInt behaves like a Number in cases where it is converted to boolean: <code class=\"language-text\">if</code>, <code class=\"language-text\">||</code>, <code class=\"language-text\">&amp;&amp;</code>, <code class=\"language-text\">Boolean</code>, <code class=\"language-text\">!</code>.</p>\n<p><code class=\"language-text\">BigInt</code>s cannot be operated on interchangeably with Numbers. Instead a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError\"><code class=\"language-text\">TypeError</code></a> will be thrown.</p>\n<h4>NaN</h4>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN\"><code class=\"language-text\">NaN</code></a> (\"<strong>N</strong>ot a <strong>N</strong>umber\") is typically encountered when the result of an arithmetic operation cannot be expressed as a number. It is also the only value in JavaScript that is not equal to itself.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type\" title=\"Permalink to String type\">String type</a></h3>\n<p>JavaScript's String type is used to represent textual data. It is a set of \"elements\" of 16-bit unsigned integer values. Each element in the String occupies a position in the String. The first element is at index <code class=\"language-text\">0</code>, the next at index <code class=\"language-text\">1</code>, and so on. The length of a String is the number of elements in it.</p>\n<p>Unlike some programming languages (such as C), JavaScript strings are immutable. This means that once a string is created, it is not possible to modify it.</p>\n<p>However, it is still possible to create another string based on an operation on the original string. For example:</p>\n<ul>\n<li>A substring of the original by picking individual letters or using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr\"><code class=\"language-text\">String.substr()</code></a>.</li>\n<li>A concatenation of two strings using the concatenation operator (<code class=\"language-text\">+</code>) or <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat\"><code class=\"language-text\">String.concat()</code></a>.</li>\n</ul>\n<h4>Beware of \"stringly-typing\" your code!</h4>\n<p>It can be tempting to use strings to represent complex data. Doing this comes with short-term benefits:</p>\n<ul>\n<li>It is easy to build complex strings with concatenation.</li>\n<li>Strings are easy to debug (what you see printed is always what is in the string).</li>\n<li>Strings are the common denominator of a lot of APIs (<a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement\">input fields</a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API\">local storage</a> values, <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\"><code class=\"language-text\">XMLHttpRequest</code></a> responses when using <code class=\"language-text\">responseText</code>, etc.) and it can be tempting to only work with strings.</li>\n</ul>\n<p>With conventions, it is possible to represent any data structure in a string. This does not make it a good idea. For instance, with a separator, one could emulate a list (while a JavaScript array would be more suitable). Unfortunately, when the separator is used in one of the \"list\" elements, then, the list is broken. An escape character can be chosen, etc. All of this requires conventions and creates an unnecessary maintenance burden.</p>\n<p>Use strings for textual data. When representing complex data, <em>parse</em> strings, and use the appropriate abstraction.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#symbol_type\" title=\"Permalink to Symbol type\">Symbol type</a></h3>\n<p>A Symbol is a <strong>unique</strong> and <strong>immutable</strong> primitive value and may be used as the key of an Object property (see below). In some programming languages, Symbols are called \"atoms\".</p>\n<p>For more details see <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Symbol\">Symbol</a> and the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol\"><code class=\"language-text\">Symbol</code></a>object wrapper in JavaScript.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#objects\" title=\"Permalink to Objects\">Objects</a></h2>\n<p>In computer science, an object is a value in memory which is possibly referenced by an <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Identifier\">identifier</a>.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#properties\" title=\"Permalink to Properties\">Properties</a></h3>\n<p>In JavaScript, objects can be seen as a collection of properties. With the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#object_literals\">object literal syntax</a>, a limited set of properties are initialized; then properties can be added and removed. Property values can be values of any type, including other objects, which enables building complex data structures. Properties are identified using <em>key</em>values. A <em>key</em> value is either a <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/String\">String value</a> or a <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Symbol\">Symbol value</a>.</p>\n<p>There are two types of object properties: The <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#data_property\"><em>data</em> property</a> and the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#accessor_property\"><em>accessor</em> property</a>.</p>\n<p><strong>Note:</strong> Each property has corresponding <em>attributes</em>. Attributes are used internally by the JavaScript engine, so you cannot directly access them. That's why attributes are listed in double square brackets, rather than single.</p>\n<p>See <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty\"><code class=\"language-text\">Object.defineProperty()</code></a> to learn more.</p>\n<h4>Data property</h4>\n<p>Associates a key with a value, and has the following attributes:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>[[Value]]</td>\n<td>Any JavaScript type</td>\n<td>The value retrieved by a get access of the property.</td>\n<td><code class=\"language-text\">undefined</code></td>\n</tr>\n<tr>\n<td>[[Writable]]</td>\n<td>Boolean</td>\n<td>If <code class=\"language-text\">false</code>, the property's [[Value]] cannot be changed.</td>\n<td><code class=\"language-text\">false</code></td>\n</tr>\n<tr>\n<td>[[Enumerable]]</td>\n<td>Boolean</td>\n<td></td>\n<td><code class=\"language-text\">false</code></td>\n</tr>\n<tr>\n<td>[[Configurable]]</td>\n<td>Boolean</td>\n<td>If <code class=\"language-text\">false</code>, the property cannot be deleted, cannot be changed to an accessor property, and attributes other than [[Value]] and [[Writable]] cannot be changed.</td>\n<td><code class=\"language-text\">false</code></td>\n</tr>\n</tbody>\n</table>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Read-only</td>\n<td>Boolean</td>\n<td>Reversed state of the ES5 [[Writable]] attribute.</td>\n</tr>\n<tr>\n<td>DontEnum</td>\n<td>Boolean</td>\n<td>Reversed state of the ES5 [[Enumerable]] attribute.</td>\n</tr>\n<tr>\n<td>DontDelete</td>\n<td>Boolean</td>\n<td>Reversed state of the ES5 [[Configurable]] attribute.</td>\n</tr>\n</tbody>\n</table>\n<h4>Accessor property</h4>\n<p>Associates a key with one of two accessor functions (<code class=\"language-text\">get</code> and <code class=\"language-text\">set</code>) to retrieve or store a value.</p>\n<p><strong>Note:</strong> It's important to recognize it's accessor <em>property</em> — not accessor <em>method</em>. We can give a JavaScript object class-like accessors by using a function as a value — but that doesn't make the object a class.</p>\n<p>An accessor property has the following attributes:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>[[Get]]</td>\n<td>Function object or <code class=\"language-text\">undefined</code></td>\n<td>The function is called with an empty argument list and retrieves the property value whenever a get access to the value is performed. See also <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get\"><code class=\"language-text\">get</code></a>.</td>\n<td><code class=\"language-text\">undefined</code></td>\n</tr>\n<tr>\n<td>[[Set]]</td>\n<td>Function object or <code class=\"language-text\">undefined</code></td>\n<td>The function is called with an argument that contains the assigned value and is executed whenever a specified property is attempted to be changed. See also <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set\"><code class=\"language-text\">set</code></a>.</td>\n<td><code class=\"language-text\">undefined</code></td>\n</tr>\n<tr>\n<td>[[Enumerable]]</td>\n<td>Boolean</td>\n<td>If <code class=\"language-text\">true</code>, the property will be enumerated in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in\"><code class=\"language-text\">for...in</code></a>loops.</td>\n<td><code class=\"language-text\">false</code></td>\n</tr>\n<tr>\n<td>[[Configurable]]</td>\n<td>Boolean</td>\n<td>If <code class=\"language-text\">false</code>, the property can't be deleted and can't be changed to a data property.</td>\n<td><code class=\"language-text\">false</code></td>\n</tr>\n</tbody>\n</table>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#normal_objects_and_functions\" title=\"Permalink to &#x22;Normal&#x22; objects, and functions\">\"Normal\" objects, and functions</a></h3>\n<p>A JavaScript object is a mapping between <em>keys</em>and <em>values</em>. Keys are strings (or Symbols), and <em>values</em> can be anything. This makes objects a natural fit for <a href=\"https://en.wikipedia.org/wiki/Hash_table\">hashmaps</a>.</p>\n<p>Functions are regular objects with the additional capability of being <em>callable</em>.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#dates\" title=\"Permalink to Dates\">Dates</a></h3>\n<p>When representing dates, the best choice is to use the built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date\"><code class=\"language-text\">Date</code> utility</a> in JavaScript.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#indexed_collections_arrays_and_typed_arrays\" title=\"Permalink to Indexed collections: Arrays and typed Arrays\">Indexed collections: Arrays and typed Arrays</a></h3>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array\">Arrays</a> are regular objects for which there is a particular relationship between integer-keyed properties and the <code class=\"language-text\">length</code> property.</p>\n<p>Additionally, arrays inherit from <code class=\"language-text\">Array.prototype</code>, which provides to them a handful of convenient methods to manipulate arrays. For example, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf\"><code class=\"language-text\">indexOf()</code></a> (searching a value in the array) or <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push\"><code class=\"language-text\">push()</code></a> (adding an element to the array), and so on. This makes Arrays a perfect candidate to represent lists or sets.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays\">Typed Arrays</a> are new to JavaScript with ECMAScript 2015, and present an array-like view of an underlying binary data buffer. The following table helps determine the equivalent C data types:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array\"><code class=\"language-text\">Int8Array</code></a></td>\n<td><code class=\"language-text\">-128</code> to <code class=\"language-text\">127</code></td>\n<td>1</td>\n<td>8-bit two's complement signed integer</td>\n<td><code class=\"language-text\">byte</code></td>\n<td><code class=\"language-text\">int8_t</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\"><code class=\"language-text\">Uint8Array</code></a></td>\n<td><code class=\"language-text\">0</code> to <code class=\"language-text\">255</code></td>\n<td>1</td>\n<td>8-bit unsigned integer</td>\n<td><code class=\"language-text\">octet</code></td>\n<td><code class=\"language-text\">uint8_t</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray\"><code class=\"language-text\">Uint8ClampedArray</code></a></td>\n<td><code class=\"language-text\">0</code> to <code class=\"language-text\">255</code></td>\n<td>1</td>\n<td>8-bit unsigned integer (clamped)</td>\n<td><code class=\"language-text\">octet</code></td>\n<td><code class=\"language-text\">uint8_t</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array\"><code class=\"language-text\">Int16Array</code></a></td>\n<td><code class=\"language-text\">-32768</code> to <code class=\"language-text\">32767</code></td>\n<td>2</td>\n<td>16-bit two's complement signed integer</td>\n<td><code class=\"language-text\">short</code></td>\n<td><code class=\"language-text\">int16_t</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array\"><code class=\"language-text\">Uint16Array</code></a></td>\n<td><code class=\"language-text\">0</code> to <code class=\"language-text\">65535</code></td>\n<td>2</td>\n<td>16-bit unsigned integer</td>\n<td><code class=\"language-text\">unsigned short</code></td>\n<td><code class=\"language-text\">uint16_t</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array\"><code class=\"language-text\">Int32Array</code></a></td>\n<td><code class=\"language-text\">-2147483648</code>to <code class=\"language-text\">2147483647</code></td>\n<td>4</td>\n<td>32-bit two's complement signed integer</td>\n<td><code class=\"language-text\">long</code></td>\n<td><code class=\"language-text\">int32_t</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array\"><code class=\"language-text\">Uint32Array</code></a></td>\n<td><code class=\"language-text\">0</code> to <code class=\"language-text\">4294967295</code></td>\n<td>4</td>\n<td>32-bit unsigned integer</td>\n<td><code class=\"language-text\">unsigned long</code></td>\n<td><code class=\"language-text\">uint32_t</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array\"><code class=\"language-text\">Float32Array</code></a></td>\n<td><code class=\"language-text\">1.2E-38</code> to <code class=\"language-text\">3.4E38</code></td>\n<td>4</td>\n<td>32-bit IEEE floating point number (7 significant digits e.g., <code class=\"language-text\">1.1234567</code>)</td>\n<td><code class=\"language-text\">unrestricted float</code></td>\n<td><code class=\"language-text\">float</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array\"><code class=\"language-text\">Float64Array</code></a></td>\n<td><code class=\"language-text\">5E-324</code> to <code class=\"language-text\">1.8E308</code></td>\n<td>8</td>\n<td>64-bit IEEE floating point number (16 significant digits e.g., <code class=\"language-text\">1.123...15</code>)</td>\n<td><code class=\"language-text\">unrestricted double</code></td>\n<td><code class=\"language-text\">double</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array\"><code class=\"language-text\">BigInt64Array</code></a></td>\n<td><code class=\"language-text\">-2^63</code> to <code class=\"language-text\">2^63 - 1</code></td>\n<td>8</td>\n<td>64-bit two's complement signed integer</td>\n<td><code class=\"language-text\">bigint</code></td>\n<td><code class=\"language-text\">int64_t (signed long long)</code></td>\n</tr>\n<tr>\n<td><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array\"><code class=\"language-text\">BigUint64Array</code></a></td>\n<td><code class=\"language-text\">0</code> to <code class=\"language-text\">2^64 - 1</code></td>\n<td>8</td>\n<td>64-bit unsigned integer</td>\n<td><code class=\"language-text\">bigint</code></td>\n<td><code class=\"language-text\">uint64_t (unsigned long long)</code></td>\n</tr>\n</tbody>\n</table>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#keyed_collections_maps_sets_weakmaps_weaksets\" title=\"Permalink to Keyed collections: Maps, Sets, WeakMaps, WeakSets\">Keyed collections: Maps, Sets, WeakMaps, WeakSets</a></h3>\n<p>These data structures, introduced in ECMAScript Edition 6, take object references as keys. <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\"><code class=\"language-text\">Set</code></a>and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code class=\"language-text\">WeakSet</code></a> represent a set of objects, while <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\"><code class=\"language-text\">Map</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\"><code class=\"language-text\">WeakMap</code></a> associate a value to an object.</p>\n<p>The difference between <code class=\"language-text\">Map</code>s and <code class=\"language-text\">WeakMap</code>s is that in the former, object keys can be enumerated over. This allows garbage collection optimizations in the latter case.</p>\n<p>One could implement <code class=\"language-text\">Map</code>s and <code class=\"language-text\">Set</code>s in pure ECMAScript 5. However, since objects cannot be compared (in the sense of <code class=\"language-text\">&lt;</code> \"less than\", for instance), look-up performance would necessarily be linear. Native implementations of them (including <code class=\"language-text\">WeakMap</code>s) can have look-up performance that is approximately logarithmic to constant time.</p>\n<p>Usually, to bind data to a DOM node, one could set properties directly on the object, or use <code class=\"language-text\">data-*</code> attributes. This has the downside that the data is available to any script running in the same context. <code class=\"language-text\">Map</code>s and <code class=\"language-text\">WeakMap</code>s make it easy to <em>privately</em> bind data to an object.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#structured_data_json\" title=\"Permalink to Structured data: JSON\">Structured data: JSON</a></h3>\n<p>JSON (<strong>J</strong>ava<strong>S</strong>cript <strong>O</strong>bject <strong>N</strong>otation) is a lightweight data-interchange format, derived from JavaScript, but used by many programming languages. JSON builds universal data structures.</p>\n<p>See <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/JSON\">JSON</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON\"><code class=\"language-text\">JSON</code></a> for more details.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#more_objects_in_the_standard_library\" title=\"Permalink to More objects in the standard library\">More objects in the standard library</a></h3>\n<p>JavaScript has a standard library of built-in objects.</p>\n<p>Please have a look at the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects\">reference</a> to find out about more objects.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#determining_types_using_the_typeof_operator\" title=\"Permalink to Determining types using the typeof operator\">Determining types using the <code class=\"language-text\">typeof</code> operator</a></h2>\n<p>The <code class=\"language-text\">typeof</code> operator can help you to find the type of your variable.</p>\n<p>Please read the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof\">reference page</a> for more details and edge cases.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#see_also\" title=\"Permalink to See also\">See also</a></h2>\n<ul>\n<li><a href=\"https://github.com/trekhleb/javascript-algorithms\">JavaScript Data Structures and Algorithms by Oleksii Trekhleb</a></li>\n<li><a href=\"https://github.com/nzakas/computer-science-in-javascript/\">Nicholas Zakas collection of common data structure and common algorithms in JavaScript.</a></li>\n<li><a href=\"https://github.com/monmohan/DataStructures_In_Javascript\">Search Tre(i)es implemented in JavaScript</a></li>\n<li><a href=\"https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values\">Data Types and Values in the ECMAScript specification</a></li>\n</ul>"},{"url":"/docs/ds-algo/ds-in-python/","relativePath":"docs/ds-algo/ds-in-python.md","relativeDir":"docs/ds-algo","base":"ds-in-python.md","name":"ds-in-python","frontmatter":{"title":"Data Structures In Python","template":"docs","excerpt":"In this tutorial, you'll learn about Python's data structures. You'll look at several implementations of abstract data types and learn which implementations are best for your specific use cases."},"html":"<h1>Common Python Data Structures (Guide) – Real Python</h1>\n<hr>\n<h2>Dictionaries, Maps, and Hash Tables</h2>\n<p>In Python, <strong>dictionaries(or dicts for short) are a central data structure. Dicts store an arbitrary number of objects, each identified by a unique dictionary</strong>  <strong>key</strong>.</p>\n<p>Dictionaries are also often called <strong>maps</strong>, <strong>hashmaps</strong>, <strong>lookup tables</strong>, or <strong>associative arrays</strong>. They allow for the efficient lookup, insertion, and deletion of any object associated with a given key.</p>\n<p>Phone books make a decent real-world analog for dictionary objects. They allow you to quickly retrieve the information (phone number) associated with a given key (a person’s name). Instead of having to read a phone book front to back to find someone’s number, you can jump more or less directly to a name and look up the associated information.</p>\n<p>This analogy breaks down somewhat when it comes to <em>how</em> the information is organized to allow for fast lookups. But the fundamental performance characteristics hold. Dictionaries allow you to quickly find the information associated with a given key.</p>\n<p>Dictionaries are one of the most important and frequently used data structures in computer science. So, how does Python handle dictionaries? Let’s take a tour of the dictionary implementations available in core Python and the Python standard library.</p>\n<h3><code class=\"language-text\">dict</code>: Your Go-To Dictionary</h3>\n<p>Because dictionaries are so important, Python features a robust dictionary implementation that’s built directly into the core language: the <a href=\"https://docs.python.org/3/library/stdtypes.html#mapping-types-dict\"><code class=\"language-text\">dict</code></a> data type.</p>\n<p>Python also provides some useful <strong>syntactic sugar</strong> for working with dictionaries in your programs. For example, the curly-brace ({ }) dictionary expression syntax and <a href=\"https://realpython.com/iterate-through-dictionary-python/#using-comprehensions\">dictionary comprehensions</a> allow you to conveniently define new dictionary objects:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> phonebook <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"bob\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">7387</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"alice\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3719</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"jack\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">7052</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token punctuation\">}</span>\n\n squares <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">*</span> x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n phonebook<span class=\"token punctuation\">[</span><span class=\"token string\">\"alice\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">3719</span>\n\n squares\n<span class=\"token punctuation\">{</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span> <span class=\"token number\">16</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span> <span class=\"token number\">25</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>There are some restrictions on which objects can be used as valid keys.</p>\n<p>Python’s dictionaries are indexed by keys that can be of any <a href=\"https://docs.python.org/3/glossary.html#term-hashable\">hashable</a> type. A <strong>hashable</strong> object has a hash value that never changes during its lifetime (see <code class=\"language-text\">__hash__</code>), and it can be compared to other objects (see <code class=\"language-text\">__eq__</code>). Hashable objects that compare as equal must have the same hash value.</p>\n<p><a href=\"https://realpython.com/courses/immutability-python/\"><strong>Immutable</strong> types</a> like <a href=\"https://realpython.com/python-strings/\">strings</a> and <a href=\"https://realpython.com/python-data-types/\">numbers</a> are hashable and work well as dictionary keys. You can also use <a href=\"https://realpython.com/python-lists-tuples/#python-tuples\"><code class=\"language-text\">tuple</code> objects</a> as dictionary keys as long as they contain only hashable types themselves.</p>\n<p>For most use cases, Python’s built-in dictionary implementation will do everything you need. Dictionaries are highly optimized and underlie many parts of the language. For example, <a href=\"https://realpython.com/python-scope-legb-rule/#class-and-instance-attributes-scope\">class attributes</a> and variables in a <a href=\"https://en.wikipedia.org/wiki/Call_stack#Structure\">stack frame</a> are both stored internally in dictionaries.</p>\n<p>Python dictionaries are based on a well-tested and finely tuned <a href=\"https://realpython.com/python-hash-table/\">hash table</a> implementation that provides the performance characteristics you’d expect: <em>O</em>(1) time complexity for lookup, insert, update, and delete operations in the average case.</p>\n<p>There’s little reason not to use the standard <code class=\"language-text\">dict</code> implementation included with Python. However, specialized third-party dictionary implementations exist, such as <a href=\"https://en.wikipedia.org/wiki/Skip_list\">skip lists</a> or <a href=\"https://en.wikipedia.org/wiki/B-tree\">B-tree–based</a> dictionaries.</p>\n<p>Besides plain <code class=\"language-text\">dict</code> objects, Python’s standard library also includes a number of specialized dictionary implementations. These specialized dictionaries are all based on the built-in dictionary class (and share its performance characteristics) but also include some additional convenience features.</p>\n<p>Let’s take a look at them.</p>\n<h3><code class=\"language-text\">collections.OrderedDict</code>: Remember the Insertion Order of Keys<a href=\"#collectionsordereddict-remember-the-insertion-order-of-keys\" title=\"Permanent link\"></a></h3>\n<p>Python includes a specialized <code class=\"language-text\">dict</code> subclass that remembers the insertion order of keys added to it: <a href=\"https://realpython.com/python-ordereddict/\"><code class=\"language-text\">collections.OrderedDict</code></a>.</p>\n<p><strong>Note:</strong> <code class=\"language-text\">OrderedDict</code> is not a built-in part of the core language and must be imported from the <code class=\"language-text\">collections</code> module in the standard library.</p>\n<p>While standard <code class=\"language-text\">dict</code> instances preserve the insertion order of keys in CPython 3.6 and above, this was simply a <a href=\"https://mail.python.org/pipermail/python-dev/2016-September/146327.html\">side effect</a> of the CPython implementation and was not defined in the language spec until Python 3.7. So, if key order is important for your algorithm to work, then it’s best to communicate this clearly by explicitly using the <code class=\"language-text\">OrderedDict</code> class:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">import</span> collections\n d <span class=\"token operator\">=</span> collections<span class=\"token punctuation\">.</span>OrderedDict<span class=\"token punctuation\">(</span>one<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> two<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> three<span class=\"token operator\">=</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n\n d\nOrderedDict<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n d<span class=\"token punctuation\">[</span><span class=\"token string\">\"four\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">4</span>\n d\nOrderedDict<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n             <span class=\"token punctuation\">(</span><span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'four'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n d<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nodict_keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'four'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Until <a href=\"https://realpython.com/python38-new-features/\">Python 3.8</a>, you couldn’t iterate over dictionary items in reverse order using <code class=\"language-text\">reversed()</code>. Only <code class=\"language-text\">OrderedDict</code> instances offered that functionality. Even in Python 3.8, <code class=\"language-text\">dict</code> and <code class=\"language-text\">OrderedDict</code> objects aren’t exactly the same. <code class=\"language-text\">OrderedDict</code> instances have a <a href=\"https://realpython.com/python-data-types/\"><code class=\"language-text\">.move_to_end()</code> method</a> that is unavailable on plain <code class=\"language-text\">dict</code> instance, as well as a more customizable <a href=\"https://docs.python.org/3/library/collections.html#collections.OrderedDict.popitem\"><code class=\"language-text\">.popitem()</code> method</a> than the one plain <code class=\"language-text\">dict</code> instances.</p>\n<h3><code class=\"language-text\">collections.defaultdict</code>: Return Default Values for Missing Keys<a href=\"#collectionsdefaultdict-return-default-values-for-missing-keys\" title=\"Permanent link\"></a></h3>\n<p>The <a href=\"https://docs.python.org/3/library/collections.html#collections.defaultdict\"><code class=\"language-text\">defaultdict</code></a> class is another dictionary subclass that accepts a callable in its constructor whose return value will be used if a requested key cannot be found.</p>\n<p>This can save you some typing and make your intentions clearer as compared to using <code class=\"language-text\">get()</code> or catching a <a href=\"https://realpython.com/python-keyerror/\"><code class=\"language-text\">KeyError</code> exception</a> in regular dictionaries:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> defaultdict\n dd <span class=\"token operator\">=</span> defaultdict<span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Accessing a missing key creates it and</span>\n <span class=\"token comment\"># initializes it using the default factory,</span>\n <span class=\"token comment\"># i.e. list() in this example:</span>\n dd<span class=\"token punctuation\">[</span><span class=\"token string\">\"dogs\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">\"Rufus\"</span><span class=\"token punctuation\">)</span>\n dd<span class=\"token punctuation\">[</span><span class=\"token string\">\"dogs\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">\"Kathrin\"</span><span class=\"token punctuation\">)</span>\n dd<span class=\"token punctuation\">[</span><span class=\"token string\">\"dogs\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">\"Mr Sniffles\"</span><span class=\"token punctuation\">)</span>\n\n dd<span class=\"token punctuation\">[</span><span class=\"token string\">\"dogs\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'Rufus'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Kathrin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Mr Sniffles'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"https://srv.realpython.net/click/33172000876/?c=43772654581&#x26;p=58946116052&#x26;r=75987\">\n<img src=\"https://img.realpython.net/c34848d05efe728b284c7a87c7fcd5c9\" alt=\"image\"></a></p>\n<p><a href=\"https://realpython.com/account/join/\">Remove ads</a></p>\n<h3><code class=\"language-text\">collections.ChainMap</code>: Search Multiple Dictionaries as a Single Mapping<a href=\"#collectionschainmap-search-multiple-dictionaries-as-a-single-mapping\" title=\"Permanent link\"></a></h3>\n<p>The <a href=\"https://docs.python.org/3/library/collections.html#collections.ChainMap\"><code class=\"language-text\">collections.ChainMap</code></a> data structure groups multiple dictionaries into a single mapping. Lookups search the underlying mappings one by one until a key is found. Insertions, updates, and deletions only affect the first mapping added to the chain:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> ChainMap\n dict1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n dict2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"three\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"four\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\n chain <span class=\"token operator\">=</span> ChainMap<span class=\"token punctuation\">(</span>dict1<span class=\"token punctuation\">,</span> dict2<span class=\"token punctuation\">)</span>\n\n chain\nChainMap<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'three'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'four'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># ChainMap searches each collection in the chain</span>\n <span class=\"token comment\"># from left to right until it finds the key (or fails):</span>\n chain<span class=\"token punctuation\">[</span><span class=\"token string\">\"three\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">3</span>\n chain<span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1</span>\n chain<span class=\"token punctuation\">[</span><span class=\"token string\">\"missing\"</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nKeyError<span class=\"token punctuation\">:</span> <span class=\"token string\">'missing'</span></code></pre></div>\n<h3><code class=\"language-text\">types.MappingProxyType</code>: A Wrapper for Making Read-Only Dictionaries<a href=\"#typesmappingproxytype-a-wrapper-for-making-read-only-dictionaries\" title=\"Permanent link\"></a></h3>\n<p><a href=\"https://docs.python.org/3/library/types.html#types.MappingProxyType\"><code class=\"language-text\">MappingProxyType</code></a> is a wrapper around a standard dictionary that provides a read-only view into the wrapped dictionary’s data. This class was added in Python 3.3 and can be used to create immutable proxy versions of dictionaries.</p>\n<p><code class=\"language-text\">MappingProxyType</code> can be helpful if, for example, you’d like to return a dictionary carrying internal state from a class or module while discouraging write access to this object. Using <code class=\"language-text\">MappingProxyType</code> allows you to put these restrictions in place without first having to create a full copy of the dictionary:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">from</span> types <span class=\"token keyword\">import</span> MappingProxyType\n writable <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n read_only <span class=\"token operator\">=</span> MappingProxyType<span class=\"token punctuation\">(</span>writable<span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># The proxy is read-only:</span>\n read_only<span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1</span>\n read_only<span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">23</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'mappingproxy'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support item assignment\n\n <span class=\"token comment\"># Updates to the original are reflected in the proxy:</span>\n writable<span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">42</span>\n read_only\nmappingproxy<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Dictionaries in Python: Summary<a href=\"#dictionaries-in-python-summary\" title=\"Permanent link\"></a></h3>\n<p>All the Python dictionary implementations listed in this tutorial are valid implementations that are built into the Python standard library.</p>\n<p>If you’re looking for a general recommendation on which mapping type to use in your programs, I’d point you to the built-in <code class=\"language-text\">dict</code> data type. It’s a versatile and optimized hash table implementation that’s built directly into the core language.</p>\n<p>I would recommend that you use one of the other data types listed here only if you have special requirements that go beyond what’s provided by <code class=\"language-text\">dict</code>.</p>\n<p>All the implementations are valid options, but your code will be clearer and easier to maintain if it relies on standard Python dictionaries most of the time.</p>\n<h2>Array Data Structures<a href=\"#array-data-structures\" title=\"Permanent link\"></a></h2>\n<p>An <strong>array</strong> is a fundamental data structure available in most programming languages, and it has a wide range of uses across different algorithms.</p>\n<p>In this section, you’ll take a look at array implementations in Python that use only core language features or functionality that’s included in the Python standard library. You’ll see the strengths and weaknesses of each approach so you can decide which implementation is right for your use case.</p>\n<p>But before we jump in, let’s cover some of the basics first. How do arrays work, and what are they used for? Arrays consist of fixed-size data records that allow each element to be efficiently located based on its index:</p>\n<p><a href=\"https://files.realpython.com/media/python-linked-list-array-visualization.5b9f4c4040cb.jpeg\"><img src=\"https://files.realpython.com/media/python-linked-list-array-visualization.5b9f4c4040cb.jpeg\" alt=\"Visual representation of an array\"></a></p>\n<p>Because arrays store information in adjoining blocks of memory, they’re considered <strong>contiguous</strong> data structures (as opposed to <strong>linked</strong> data structures like linked lists, for example).</p>\n<p>A real-world analogy for an array data structure is a parking lot. You can look at the parking lot as a whole and treat it as a single object, but inside the lot there are parking spots indexed by a unique number. Parking spots are containers for vehicles—each parking spot can either be empty or have a car, a motorbike, or some other vehicle parked on it.</p>\n<p>But not all parking lots are the same. Some parking lots may be restricted to only one type of vehicle. For example, a motor home parking lot wouldn’t allow bikes to be parked on it. A restricted parking lot corresponds to a <strong>typed</strong> array data structure that allows only elements that have the same data type stored in them.</p>\n<p>Performance-wise, it’s very fast to look up an element contained in an array given the element’s index. A proper array implementation guarantees a constant <em>O</em>(1) access time for this case.</p>\n<p>Python includes several array-like data structures in its standard library that each have slightly different characteristics. Let’s take a look.</p>\n<h3><code class=\"language-text\">list</code>: Mutable Dynamic Arrays<a href=\"#list-mutable-dynamic-arrays\" title=\"Permanent link\"></a></h3>\n<p><a href=\"https://docs.python.org/3.6/library/stdtypes.html#lists\">Lists</a> are a part of the core Python language. Despite their name, Python’s lists are implemented as <strong>dynamic arrays</strong> behind the scenes.</p>\n<p>This means a list allows elements to be added or removed, and the list will automatically adjust the backing store that holds these elements by allocating or releasing memory.</p>\n<p>Python lists can hold arbitrary elements—everything is an object in Python, including functions. Therefore, you can mix and match different kinds of data types and store them all in a single list.</p>\n<p>This can be a powerful feature, but the downside is that supporting multiple data types at the same time means that data is generally less tightly packed. As a result, the whole structure takes up more space:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"three\"</span><span class=\"token punctuation\">]</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'one'</span>\n\n <span class=\"token comment\"># Lists have a nice repr:</span>\n arr\n<span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span>\n\n <span class=\"token comment\"># Lists are mutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\n arr\n<span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span>\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n arr\n<span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span>\n\n <span class=\"token comment\"># Lists can hold arbitrary data types:</span>\n arr<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token number\">23</span><span class=\"token punctuation\">)</span>\n arr\n<span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3><code class=\"language-text\">tuple</code>: Immutable Containers<a href=\"#tuple-immutable-containers\" title=\"Permanent link\"></a></h3>\n<p>Just like lists, <a href=\"https://docs.python.org/3/library/stdtypes.html#tuple\">tuples</a> are part of the Python core language. Unlike lists, however, Python’s <code class=\"language-text\">tuple</code> objects are immutable. This means elements can’t be added or removed dynamically—all elements in a tuple must be defined at creation time.</p>\n<p>Tuples are another data structure that can hold elements of arbitrary data types. Having this flexibility is powerful, but again, it also means that data is less tightly packed than it would be in a typed array:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"three\"</span><span class=\"token punctuation\">)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'one'</span>\n\n <span class=\"token comment\"># Tuples have a nice repr:</span>\n arr\n<span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Tuples are immutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'tuple'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support item assignment\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'tuple'</span> <span class=\"token builtin\">object</span> doesn't support item deletion\n\n <span class=\"token comment\"># Tuples can hold arbitrary data types:</span>\n <span class=\"token comment\"># (Adding elements creates a copy of the tuple)</span>\n arr <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token number\">23</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3><code class=\"language-text\">array.array</code>: Basic Typed Arrays<a href=\"#arrayarray-basic-typed-arrays\" title=\"Permanent link\"></a></h3>\n<p>Python’s <code class=\"language-text\">array</code> module provides space-efficient storage of basic C-style data types like bytes, 32-bit integers, floating-point numbers, and so on.</p>\n<p>Arrays created with the <a href=\"https://docs.python.org/3/library/array.html\"><code class=\"language-text\">array.array</code></a> class are mutable and behave similarly to lists except for one important difference: they’re <strong>typed arrays</strong> constrained to a single data type.</p>\n<p>Because of this constraint, <code class=\"language-text\">array.array</code> objects with many elements are more space efficient than lists and tuples. The elements stored in them are tightly packed, and this can be useful if you need to store many elements of the same type.</p>\n<p>Also, arrays support many of the same methods as regular lists, and you might be able to use them as a drop-in replacement without requiring other changes to your application code.</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">import</span> array\n arr <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">(</span><span class=\"token string\">\"f\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1.5</span>\n\n <span class=\"token comment\"># Arrays have a nice repr:</span>\n arr\narray<span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Arrays are mutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">23.0</span>\n arr\narray<span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n arr\narray<span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n arr<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token number\">42.0</span><span class=\"token punctuation\">)</span>\n arr\narray<span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">42.0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Arrays are \"typed\":</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> must be real number<span class=\"token punctuation\">,</span> <span class=\"token keyword\">not</span> <span class=\"token builtin\">str</span></code></pre></div>\n<h3><code class=\"language-text\">str</code>: Immutable Arrays of Unicode Characters<a href=\"#str-immutable-arrays-of-unicode-characters\" title=\"Permanent link\"></a></h3>\n<p>Python 3.x uses <a href=\"https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str\"><code class=\"language-text\">str</code></a> objects to store textual data as immutable sequences of <a href=\"https://realpython.com/python-encodings-guide/\">Unicode characters</a>. Practically speaking, that means a <code class=\"language-text\">str</code> is an immutable array of characters. Oddly enough, it’s also a <a href=\"https://realpython.com/python-thinking-recursively/\">recursive</a> data structure—each character in a string is itself a <code class=\"language-text\">str</code> object of length 1.</p>\n<p>String objects are space efficient because they’re tightly packed and they specialize in a single data type. If you’re storing Unicode text, then you should use a string.</p>\n<p>Because strings are immutable in Python, modifying a string requires creating a modified copy. The closest equivalent to a mutable string is storing individual characters inside a list:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token string\">\"abcd\"</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'b'</span>\n\n arr\n<span class=\"token string\">'abcd'</span>\n\n <span class=\"token comment\"># Strings are immutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"e\"</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'str'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support item assignment\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'str'</span> <span class=\"token builtin\">object</span> doesn't support item deletion\n\n <span class=\"token comment\"># Strings can be unpacked into a list to</span>\n <span class=\"token comment\"># get a mutable representation:</span>\n <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abcd\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">]</span>\n <span class=\"token string\">\"\"</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abcd\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'abcd'</span>\n\n <span class=\"token comment\"># Strings are recursive data structures:</span>\n <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">\"&lt;class 'str'>\"</span>\n <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">\"&lt;class 'str'>\"</span></code></pre></div>\n<h3><code class=\"language-text\">bytes</code>: Immutable Arrays of Single Bytes<a href=\"#bytes-immutable-arrays-of-single-bytes\" title=\"Permanent link\"></a></h3>\n<p><a href=\"https://docs.python.org/3/library/stdtypes.html#bytes-objects\"><code class=\"language-text\">bytes</code></a> objects are immutable sequences of single bytes, or integers in the range 0 ≤ <em>x</em> ≤ 255. Conceptually, <code class=\"language-text\">bytes</code> objects are similar to <code class=\"language-text\">str</code> objects, and you can also think of them as immutable arrays of bytes.</p>\n<p>Like strings, <code class=\"language-text\">bytes</code> have their own literal syntax for creating objects and are space efficient. <code class=\"language-text\">bytes</code> objects are immutable, but unlike strings, there’s a dedicated mutable byte array data type called <code class=\"language-text\">bytearray</code> that they can be unpacked into:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token builtin\">bytes</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1</span>\n\n <span class=\"token comment\"># Bytes literals have their own syntax:</span>\n arr\n<span class=\"token string\">b'\\x00\\x01\\x02\\x03'</span>\n arr <span class=\"token operator\">=</span> <span class=\"token string\">b\"\\x00\\x01\\x02\\x03\"</span>\n\n <span class=\"token comment\"># Only valid `bytes` are allowed:</span>\n <span class=\"token builtin\">bytes</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nValueError<span class=\"token punctuation\">:</span> <span class=\"token builtin\">bytes</span> must be <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">256</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Bytes are immutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">23</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'bytes'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support item assignment\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'bytes'</span> <span class=\"token builtin\">object</span> doesn't support item deletion</code></pre></div>\n<h3><code class=\"language-text\">bytearray</code>: Mutable Arrays of Single Bytes<a href=\"#bytearray-mutable-arrays-of-single-bytes\" title=\"Permanent link\"></a></h3>\n<p>The <a href=\"https://docs.python.org/3.1/library/functions.html#bytearray\"><code class=\"language-text\">bytearray</code></a> type is a mutable sequence of integers in the range 0 ≤ <em>x</em> ≤ 255. The <code class=\"language-text\">bytearray</code> object is closely related to the <code class=\"language-text\">bytes</code> object, with the main difference being that a <code class=\"language-text\">bytearray</code> can be modified freely—you can overwrite elements, remove existing elements, or add new ones. The <code class=\"language-text\">bytearray</code> object will grow and shrink accordingly.</p>\n<p>A <code class=\"language-text\">bytearray</code> can be converted back into immutable <code class=\"language-text\">bytes</code> objects, but this involves copying the stored data in full—a slow operation taking <em>O</em>(<em>n</em>) time:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1</span>\n\n <span class=\"token comment\"># The bytearray repr:</span>\n arr\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token string\">b'\\x00\\x01\\x02\\x03'</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Bytearrays are mutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">23</span>\n arr\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token string\">b'\\x00\\x17\\x02\\x03'</span><span class=\"token punctuation\">)</span>\n\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">23</span>\n\n <span class=\"token comment\"># Bytearrays can grow and shrink in size:</span>\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n arr\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token string\">b'\\x00\\x02\\x03'</span><span class=\"token punctuation\">)</span>\n\n arr<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token number\">42</span><span class=\"token punctuation\">)</span>\n arr\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token string\">b'\\x00\\x02\\x03*'</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Bytearrays can only hold `bytes`</span>\n <span class=\"token comment\"># (integers in the range 0 &lt;= x &lt;= 255)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'str'</span> <span class=\"token builtin\">object</span> cannot be interpreted <span class=\"token keyword\">as</span> an integer\n\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">300</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nValueError<span class=\"token punctuation\">:</span> byte must be <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">256</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Bytearrays can be converted back into bytes objects:</span>\n <span class=\"token comment\"># (This will copy the data)</span>\n <span class=\"token builtin\">bytes</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span>\n<span class=\"token string\">b'\\x00\\x02\\x03*'</span></code></pre></div>\n<h3>Arrays in Python: Summary<a href=\"#arrays-in-python-summary\" title=\"Permanent link\"></a></h3>\n<p>There are a number of built-in data structures you can choose from when it comes to implementing arrays in Python. In this section, you’ve focused on core language features and data structures included in the standard library.</p>\n<p>If you’re willing to go beyond the Python standard library, then third-party packages like <a href=\"https://realpython.com/numpy-array-programming/\">NumPy</a> and <a href=\"https://realpython.com/pandas-dataframe/\">pandas</a> offer a wide range of fast array implementations for scientific computing and data science.</p>\n<p>If you want to restrict yourself to the array data structures included with Python, then here are a few guidelines:</p>\n<ul>\n<li>If you need to store arbitrary objects, potentially with mixed data types, then use a <code class=\"language-text\">list</code> or a <code class=\"language-text\">tuple</code>, depending on whether or not you want an immutable data structure.</li>\n<li>If you have numeric (integer or floating-point) data and tight packing and performance is important, then try out <code class=\"language-text\">array.array</code>.</li>\n<li>If you have textual data represented as Unicode characters, then use Python’s built-in <code class=\"language-text\">str</code>. If you need a mutable string-like data structure, then use a <code class=\"language-text\">list</code> of characters.</li>\n<li>If you want to store a contiguous block of bytes, then use the immutable <code class=\"language-text\">bytes</code> type or a <code class=\"language-text\">bytearray</code> if you need a mutable data structure.</li>\n</ul>\n<p>In most cases, I like to start out with a simple <code class=\"language-text\">list</code>. I’ll only specialize later on if performance or storage space becomes an issue. Most of the time, using a general-purpose array data structure like <code class=\"language-text\">list</code> gives you the fastest development speed and the most programming convenience.</p>\n<p>I’ve found that this is usually much more important in the beginning than trying to squeeze out every last drop of performance right from the start.</p>\n<h2>Records, Structs, and Data Transfer Objects<a href=\"#records-structs-and-data-transfer-objects\" title=\"Permanent link\"></a></h2>\n<p>Compared to arrays, <strong>record</strong> data structures provide a fixed number of fields. Each field can have a name and may also have a different type.</p>\n<p>In this section, you’ll see how to implement records, structs, and plain old data objects in Python using only built-in data types and classes from the standard library.</p>\n<p><strong>Note:</strong> I’m using the definition of a record loosely here. For example, I’m also going to discuss types like Python’s built-in <code class=\"language-text\">tuple</code> that may or may not be considered records in a strict sense because they don’t provide named fields.</p>\n<p>Python offers several data types that you can use to implement records, structs, and data transfer objects. In this section, you’ll get a quick look at each implementation and its unique characteristics. At the end, you’ll find a summary and a decision-making guide that will help you make your own picks.</p>\n<p><strong>Note:</strong> This tutorial is adapted from the chapter “Common Data Structures in Python” in <a href=\"https://realpython.com/products/python-tricks-book/\"><em>Python Tricks: The Book</em></a>. If you enjoy what you’re reading, then be sure to check out <a href=\"https://realpython.com/products/python-tricks-book/\">the rest of the book</a>.</p>\n<p>Alright, let’s get started!</p>\n<h3><code class=\"language-text\">dict</code>: Simple Data Objects<a href=\"#dict-simple-data-objects\" title=\"Permanent link\"></a></h3>\n<p>As mentioned <a href=\"#dictionaries-maps-and-hash-tables\">previously</a>, Python dictionaries store an arbitrary number of objects, each identified by a unique key. Dictionaries are also often called <strong>maps</strong> or <strong>associative arrays</strong> and allow for efficient lookup, insertion, and deletion of any object associated with a given key.</p>\n<p>Using dictionaries as a record data type or data object in Python is possible. Dictionaries are easy to create in Python as they have their own syntactic sugar built into the language in the form of <strong>dictionary literals</strong>. The dictionary syntax is concise and quite convenient to type.</p>\n<p>Data objects created using dictionaries are mutable, and there’s little protection against misspelled field names as fields can be added and removed freely at any time. Both of these properties can introduce surprising bugs, and there’s always a trade-off to be made between convenience and error resilience:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> car1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"color\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"mileage\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3812.4</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"automatic\"</span><span class=\"token punctuation\">:</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token punctuation\">}</span>\n car2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"color\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"blue\"</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"mileage\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">40231</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"automatic\"</span><span class=\"token punctuation\">:</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token punctuation\">}</span>\n\n <span class=\"token comment\"># Dicts have a nice repr:</span>\n car2</code></pre></div>"},{"url":"/docs/ds-algo/graph/","relativePath":"docs/ds-algo/graph.md","relativeDir":"docs/ds-algo","base":"graph.md","name":"graph","frontmatter":{"title":"Graph ADS","weight":0,"excerpt":"ADS stands for (abstract data structure)","seo":{"title":"Graph ADS","description":"In computer science, a graph is an abstract data type that is meant to implement the undirected graph and directed graph concepts from mathematics, specifically the field of graph theory","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Graph</h1>\n<p><strong>In computer science, a</strong>graph<strong>is an abstract data type that is meant to implement the undirected graph and directed graph concepts from mathematics, specifically the field of graph theory</strong></p>\n<p>A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph. These pairs are known as edges, arcs, or lines for an undirected graph and as arrows, directed edges, directed arcs, or directed lines for a directed graph. The vertices may be part of t</p>\n<p><img src=\"https://www.tutorialspoint.com/data_structures_algorithms/images/graph.jpg\" alt=\"Graph\"></p>\n<h2>References</h2>\n<ul>\n<li><a href=\"https://en.wikipedia.org/wiki/Graph_(abstract_data_type)\">Wikipedia</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=gXgEDyodOJU&#x26;index=9&#x26;list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8\">Introduction to Graphs on YouTube</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=k1wraWzqtvQ&#x26;index=10&#x26;list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8\">Graphs representation on YouTube</a></li>\n</ul>"},{"url":"/docs/ds-algo/tree/","relativePath":"docs/ds-algo/tree.md","relativeDir":"docs/ds-algo","base":"tree.md","name":"tree","frontmatter":{"title":"Tree","weight":0,"excerpt":"A tree data structure can be defined recursively (locally) as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of references to nodes","seo":{"title":"Tree Data Structure","description":"In Javascript","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Tree</h1>\n<ul>\n<li><a href=\"binary-search-tree\">Binary Search Tree</a></li>\n<li><a href=\"avl-tree\">AVL Tree</a></li>\n<li><a href=\"red-black-tree\">Red-Black Tree</a></li>\n<li><a href=\"segment-tree\">Segment Tree</a> - with min/max/sum range queries examples</li>\n<li><a href=\"fenwick-tree\">Fenwick Tree</a> (Binary Indexed Tree)</li>\n</ul>\n<p>In computer science, a <strong>tree</strong> is a widely used abstract data type (ADT) — or data structure implementing this ADT—that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node, represented as a set of linked nodes. </p>\n<p>A tree data structure can be defined recursively (locally) as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of references to nodes (the \"children\"), with the constraints that no reference is duplicated, and none points to the root. </p>\n<p>A simple unordered tree; in this diagram, the node labeled 7 has two children, labeled 2 and 6, and one parent, labeled 2. The root node, at the top, has no parent.</p>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/f/f7/Binary_tree.svg\" alt=\"Tree\"></p>\n<h2>References</h2>\n<ul>\n<li><a href=\"https://en.wikipedia.org/wiki/Tree_(data_structure)\">Wikipedia</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=oSWTXtMglKE&#x26;list=PLLXdhg_r2hKA7DPDsunoDZ-Z769jWn4R8&#x26;index=8\">YouTube</a></li>\n</ul>"},{"url":"/docs/ds-algo/heaps/","relativePath":"docs/ds-algo/heaps.md","relativeDir":"docs/ds-algo","base":"heaps.md","name":"heaps","frontmatter":{"title":"What are data structures","weight":0,"excerpt":"Data structures, at a high level, are techniques for storing and organizing data that make it easier to modify, navigate, and access. Data structures determine how data is collected, the functions we can use to access it, and the relationships between data.","seo":{"title":" What are data structures","description":"Data structures are used in almost all areas of computer science and programming, from operating systems to basic vanilla code to artificial intelligence.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>What is heap data structure</h1>\n<p>Heap is one efficient implementation of an abstract data structure called a <a href=\"https://learnersbucket.com/tutorials/data-structures/priority-queue-implementation-in-javascript\">priority queue</a>.</p>\n<hr>\n<h2>Priority Queue</h2>\n<details>\n<summary> Click To Learn About Priority Queues </summary>\n<h2>What is priority queue?</h2>\n<p>As queues are widely used in computer programming and in real lives as well, there was a need for some different models of original <a href=\"https://learnersbucket.com/tutorials/algorithms/queue-implementation-in-javascript\">queue data structure</a> to process the data more efficiently.</p>\n<p>A priority queue is one of the variants of the original queue. In this elements are added and removed based on their priorities. It is an abstract data type that captures the idea of a container whose elements have priorities attached to them. An element of highest priority always appears at the front of the queue. If that element is removed, the next highest priority element advances to the front.</p>\n<p>A real-life example of the priority queue are the patients in the hospitals, the one with at most priority are treated first and then the others.</p>\n<p>Another example is people standing in a queue at the boarding line at the airport, first and second class(Business class) peoples passengers get priority over the coach class(Economy).</p>\n<p>In India elderly or women get priority over young and men at many places like in railway and bus.</p>\n<p><img src=\"https://i0.wp.com/learnersbucket.com/wp-content/uploads/2019/09/ezgif.com-optimize-2.gif?resize=600%2C338&#x26;ssl=1\" alt=\"Priority queue in javascript\"></p>\n<h2>Why do we need priority queue?</h2>\n<p>It is used when we have to choose between the same values who have different priorities or weight.</p>\n<ul>\n<li>Dijkstra's Shortest Path Algorithm using priority queue: When the graph is stored in the form of adjacency list or matrix, priority queue can be used to extract minimum efficiently when implementing Dijkstra's algorithm.</li>\n<li>Prim's algorithm: to store keys of nodes and extract minimum key node at every step.</li>\n<li>Data compression: It is used in Huffman Codes which is used to compresses data.</li>\n<li>Operating system: It is used by operating systems for <a href=\"https://www.nginx.com/resources/glossary/load-balancing/\">load balancing</a>.</li>\n</ul>\n<p>Now I am sure that you have a good idea about priority queue, so let us start implementing it in javascript.</p>\n<h2>List of operations performed on priority queue</h2>\n<ul>\n<li>enqueue(): Adds an item at the tail of the queue.</li>\n<li>dequeue(): Removes an item from the head of the queue.</li>\n<li>front(): Retruns the first item in the queue.</li>\n<li>rear(): Retruns the last item in the queue.</li>\n<li>size(): Returns the size of the queue.</li>\n<li>isEmpty(): Returns <code class=\"language-text\">true</code> if queue is empty, <code class=\"language-text\">false</code> otherwise.</li>\n</ul>\n<p>There are two ways of implementing a priority queue.</p>\n<ul>\n<li>Add elements at appropriate place based on their priorities.</li>\n<li>Queue elements as they are added and remove them according to their priorities.</li>\n</ul>\n<p>We will be using the first approach as we just have to place the elements at the appropriate place and then it can be dequeued normally.</p>\n<h2>Implementing a priority queue in javascript</h2>\n<p>We will use an extra function (container) which will be storing the value and its priority.</p>\n<p>function  PriorityQueue(){  let items =  [];  //Container  function  QueueElement(element, priority){  this.element = element;  this.priority = priority;  }  //Other methods go here  }</p>\n<hr>\n<h3>Adding an item in the priority queue</h3>\n<p>This is the only major method which will be modifying to store the data based on priorities.</p>\n<p>We will iterate each element that is already present in the queue and compare their priority with the new element's priority. If the new elements priority is greater then will add it at that place.</p>\n<p>To add elements at specific index we will need to shift the remaining elements back, But [javascript array] has an inbuilt method for this <code class=\"language-text\">splice(index, count, element)</code> which we will be using.</p>\n<p>//Add a new element in queue  this.enqueue =  function(element, priority){  let queueElement =  new  QueueElement(element, priority);  //To check if element is added  let added =  false;  for(let i =  0; i &#x3C; items.length; i++){  //We are using giving priority to higher numbers  //If new element has more priority then add it at that place  if(queueElement.priority > items[i].priority){ items.splice(i,  0, queueElement);  //Mark the flag true added =  true;  break;  }  }  //If element is not added  //Then add it to the end of the queue  if(!added){ items.push(queueElement);  }  }</p>\n<hr>\n<h3>Remove an item from the priority queue</h3>\n<p>//Remove element from the queue  this.dequeue =  ()  =>  {  return items.shift();  }</p>\n<hr>\n<h3>Return the first element from the priority queue</h3>\n<p>//Return the first element from the queue  this.front =  ()  =>  {  return items[0];  }</p>\n<hr>\n<h3>Return the last element from the priority queue</h3>\n<p>//Return the last element from the queue  this.rear =  ()  =>  {  return items[items.length -  1];  }</p>\n<hr>\n<h3>Check if queue is empty</h3>\n<p>//Check if queue is empty  this.isEmpty =  ()  =>  {  return items.length ==  0;  }</p>\n<hr>\n<h3>Return the size of the queue</h3>\n<p>//Return the size of the queue  this.size =  ()  =>  {  return items.length;  }</p>\n<hr>\n<h3>Print the queue</h3>\n<p>//Print the queue  this.print  =  function(){  for(let i =  0; i &#x3C; items.length; i++){ console.log(<code class=\"language-text\">${items[i].element} - ${items[i].priority}</code>);  }  }</p>\n<hr>\n<h2>Complete code of the priority queue</h2>\n<p>function  PriorityQueue(){  let items =  [];  //Container  function  QueueElement(element, priority){  this.element = element;  this.priority = priority;  }  //Add a new element in queue  this.enqueue =  function(element, priority){  let queueElement =  new  QueueElement(element, priority);  //To check if element is added  let added =  false;  for(let i =  0; i &#x3C; items.length; i++){  //We are using giving priority to higher numbers  //If new element has more priority then add it at that place  if(queueElement.priority > items[i].priority){ items.splice(i,  0, queueElement);  //Mark the flag true added =  true;  break;  }  }  //If element is not added  //Then add it to the end of the queue  if(!added){ items.push(queueElement);  }  }  //Remove element from the queue  this.dequeue =  ()  =>  {  return items.shift();  }  //Return the first element from the queue  this.front =  ()  =>  {  return items[0];  }  //Return the last element from the queue  this.rear =  ()  =>  {  return items[items.length -  1];  }  //Check if queue is empty  this.isEmpty =  ()  =>  {  return items.length ==  0;  }  //Return the size of the queue  this.size =  ()  =>  {  return items.length;  }  //Print the queue  this.print  =  function(){  for(let i =  0; i &#x3C; items.length; i++){ console.log(<code class=\"language-text\">${items[i].element} - ${items[i].priority}</code>);  }  }  }</p>\n<p>Input:  let pQ =  new  PriorityQueue(); pQ.enqueue(1,  3); pQ.enqueue(5,  2); pQ.enqueue(6,  1); pQ.enqueue(11,  1); pQ.enqueue(13,  1); pQ.enqueue(10,  3); pQ.dequeue(); pQ.print();  Output:  \"10 - 3\"  \"5 - 2\"  \"6 - 1\"  \"11 - 1\"  \"13 - 1\"</p>\n<hr>\n<h2>ES6 class based implementation of priority queue</h2>\n<p>//Container  class  QueueElement{  constructor(element, priority){  this.element = element;  this.priority = priority;  }  }  //PriorityQueue  class  PriorityQueue{  constructor(){  this.items =  [];  }  //Add a new element in queue enqueue =  function(element, priority){  let queueElement =  new  QueueElement(element, priority);  //To check if element is added  let added =  false;  for(let i =  0; i &#x3C;  this.items.length; i++){  //We are using giving priority to higher numbers  //If new element has more priority then add it at that place  if(queueElement.priority >  this.items[i].priority){  this.items.splice(i,  0, queueElement);  //Mark the flag true added =  true;  break;  }  }  //If element is not added  //Then add it to the end of the queue  if(!added){  this.items.push(queueElement);  }  }  //Remove element from the queue dequeue =  function(){  return  this.items.shift();  }  //Return the first element from the queue front =  function(){  return  this.items[0];  }  //Return the last element from the queue rear =  function(){  return  this.items[this.items.length -  1];  }  //Check if queue is empty isEmpty =  function(){  return  this.items.length ==  0;  }  //Return the size of the queue size =  function(){  return  this.items.length;  }  //Print the queue  print  =  function(){  for(let i =  0; i &#x3C;  this.items.length; i++){ console.log(<code class=\"language-text\">${this.items[i].element} - ${this.items[i].priority}</code>);  }  }  }</p>\n<p>Input:  let pQ =  new  PriorityQueue(); pQ.enqueue(1,  3); pQ.enqueue(5,  2); pQ.enqueue(6,  1); pQ.enqueue(11,  1); pQ.enqueue(13,  1); pQ.enqueue(10,  3); pQ.dequeue(); pQ.print();  Output:  \"10 - 3\"  \"5 - 2\"  \"6 - 1\"  \"11 - 1\"  \"13 - 1\"</p>\n<hr>\n<h2>Making this class private with closure and IIFE</h2>\n<p>let  PriorityQueue  =  (function(){  //Container  class  QueueElement{  constructor(element, priority){  this.element = element;  this.priority = priority;  }  }  //PriorityQueue  return  class  PriorityQueue{  constructor(){  this.items =  [];  }  //Add a new element in queue enqueue =  function(element, priority){  let queueElement =  new  QueueElement(element, priority);  //To check if element is added  let added =  false;  for(let i =  0; i &#x3C;  this.items.length; i++){  //We are using giving priority to higher numbers  //If new element has more priority then add it at that place  if(queueElement.priority >  this.items[i].priority){  this.items.splice(i,  0, queueElement);  //Mark the flag true added =  true;  break;  }  }  //If element is not added  //Then add it to the end of the queue  if(!added){  this.items.push(queueElement);  }  }  //Remove element from the queue dequeue =  function(){  return  this.items.shift();  }  //Return the first element from the queue front =  function(){  return  this.items[0];  }  //Return the last element from the queue rear =  function(){  return  this.items[this.items.length -  1];  }  //Check if queue is empty isEmpty =  function(){  return  this.items.length ==  0;  }  //Return the size of the queue size =  function(){  return  this.items.length;  }  //Print the queue  print  =  function(){  for(let i =  0; i &#x3C;  this.items.length; i++){ console.log(<code class=\"language-text\">${this.items[i].element} - ${this.items[i].priority}</code>);  }  }  }  }());</p>\n<h4>Time Complexity</h4>\n<table>\n<thead>\n<tr>\n<th>#</th>\n<th>Access</th>\n<th>Search</th>\n<th>Insert</th>\n<th>Delete</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Average</td>\n<td>Θ(N)</td>\n<td>Θ(N)</td>\n<td>Θ(N)</td>\n<td>Θ(1)</td>\n</tr>\n<tr>\n<td>Worst</td>\n<td>O(N)</td>\n<td>O(N)</td>\n<td>O(N)</td>\n<td>O(1)</td>\n</tr>\n</tbody>\n</table>\n<hr>\n<h4>Space Complexity</h4>\n<table>\n<thead>\n<tr>\n<th>#</th>\n<th>space</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Worst</td>\n<td>O(N)</td>\n</tr>\n</tbody>\n</table>\n</details>\n<p>In a heap, the highest (or lowest) priority element is always stored at the root, thus priority queue is often referred to as heaps irrespective of their implementation.</p>\n<p>Heap is the most useful data structure when it is necessary to repeatedly remove the object with the highest (or lowest) priority.</p>\n<p>One of the most common implementations of the heap is the binary heap which is basically a binary tree.</p>\n<p>A binary heap is basically a binary tree with two additional properties.</p>\n<ol>\n<li><strong>Shape property</strong>: It must be a complete binary tree, which means all the levels of the tree, except the deepest (last) one are fully filled. In case the last level of the tree is not complete, the nodes of that level are filled from left to right.</li>\n<li><strong>Heap property</strong>: All nodes are either greater than or equal to or less than or equal to each of its children. If the parent nodes are greater than their child nodes, the heap is called a Max-Heap, and if the parent nodes are smaller than their child nodes, the heap is called Min-Heap.</li>\n</ol>\n<p><img src=\"https://i0.wp.com/learnersbucket.com/wp-content/uploads/2020/10/max-and-min-heap-1.png?resize=768%2C500&#x26;ssl=1\" alt=\"Max and Min heap\"></p>\n<hr>\n<h2>List of operations performed on binary heap</h2>\n<ul>\n<li><strong>insert(num)</strong>: Add a new key to the heap.</li>\n<li><strong>delete(num)</strong>: Removes a key from the heap.</li>\n<li><strong>heapify</strong>: Create a (min or max) heap from the given array.</li>\n<li><strong>findMax or (findMin)</strong>: Return the max element from the heap or (min).</li>\n<li><strong>extractMax or (extractMin)</strong>: Remove and return the max element from the heap or (min).</li>\n<li><strong>deleteMax or (deleteMin)</strong>: Remove the max element from the heap or (min).</li>\n<li><strong>size</strong>: Return the size of the heap.</li>\n<li><strong>isEmpty</strong>: Is heap empty or not?.</li>\n<li><strong>getList</strong>: Get the heap as an array.</li>\n</ul>\n<hr>\n<h2>Implementing binary heap data structure in Javascript</h2>\n<p>Binary heaps can be represented using an array with certain mathematical calculations.</p>\n<p>If the index of any element in the array is <code class=\"language-text\">i</code>, the element in the index <code class=\"language-text\">2i+1</code> will become the left child, and the element in the <code class=\"language-text\">2i+2</code> index will become the right child. Also, the parent of any element at index <code class=\"language-text\">i</code> is given by the lower bound of <code class=\"language-text\">(i-1)/2</code>.</p>\n<p>Thus we can create the binary heap using an array rather than using a tree.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">BinaryHeap</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">//other operations will go here.</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h3>Heapify</h3>\n<p>The first operation which we will be adding is heapify, because either after inserting or deleting a new element in the heap we will have to heapify it to retain the form.</p>\n<p>To build a max-heap from any tree, we can start heapifying each sub-tree from the bottom up and end up with a max-heap. Repeat this for all the elements including the root element.</p>\n<p>In the case of a complete tree, the first index of a non-leaf node is given by <code class=\"language-text\">n/2 - 1</code>. All other nodes after that are leaf-nodes and thus don't need to be heapified.</p>\n<p><img src=\"https://i0.wp.com/learnersbucket.com/wp-content/uploads/2020/10/how-to-heapify-root-element-1.png?resize=768%2C500&#x26;ssl=1\" alt=\"Heapify root element\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  //Heapify\n  this.maxHeapify = (arr, n, i) => {\n    let largest = i;\n    let l = 2 * i + 1; //left child index\n    let r = 2 * i + 2; //right child index\n\n    //If left child is smaller than root\n     if (l &lt; n &amp;&amp; arr[l] > arr[largest]) {\n           largest = l; \n     }\n\n     // If right child is smaller than smallest so far \n     if (r &lt; n &amp;&amp; arr[r] > arr[largest]) {\n          largest = r; \n     }\n\n     // If smallest is not root \n     if (largest != i) { \n          let temp = arr[i]; \n          arr[i] = arr[largest]; \n          arr[largest] = temp; \n\n        // Recursively heapify the affected sub-tree \n        this.maxHeapify(arr, n, largest); \n      } \n  }</code></pre></div>\n<hr>\n<h3>Inserting a new element in the heap</h3>\n<p>To add a new element, we first check if the list is empty or not. If it is empty then push the element directly, else we will have to heapify the list after addition.</p>\n<p><img src=\"https://i0.wp.com/learnersbucket.com/wp-content/uploads/2020/10/Adding-a-new-node-in-the-binary-heap-1.png?resize=768%2C500&#x26;ssl=1\" alt=\"Adding a new node in the binary heap\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Insert Value\n  this.insert = (num) => {\n    const size = list.length;\n    if(size === 0){\n      list.push(num);\n    }else{\n      list.push(num);\n      \n     for (let i = parseInt(list.length / 2 - 1); i >= 0; i--) {\n         this.maxHeapify(list, list.length, i); \n     }\n    }\n  }</code></pre></div>\n<hr>\n<h3>Removing an element from the heap</h3>\n<p>Removing a node is 4 step process.</p>\n<ol>\n<li>Find the element in the array.</li>\n<li>Swap the element with the last element.</li>\n<li>Remove the last element.</li>\n<li>Heapify the list.</li>\n</ol>\n<p><img src=\"https://i0.wp.com/learnersbucket.com/wp-content/uploads/2020/10/Delete-a-node-in-binary-heap-1-1.png?resize=768%2C500&#x26;ssl=1\" alt=\"Delete a node in binary heap \"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Remove value\n  this.delete = (num) => {\n    const size = list.length;\n    \n    //Get the index of the number to be removed\n    let i;\n    for(i = 0; i &lt; size; i++){\n      if(num === list[i]){\n        break;\n      }\n    }\n    \n    //Swap the number with last element\n    [list[i], list[size - 1]] = [list[size - 1], list[i]];\n    \n    //Remove the last element\n    list.splice(size - 1);\n    \n    //Heapify the list again\n    for (let i = parseInt(list.length / 2 - 1); i >= 0; i--) {\n         this.maxHeapify(list, list.length, i); \n     }\n  }</code></pre></div>\n<hr>\n<h3>Find max from the heap</h3>\n<p>As the list is already max heapified, we just need to return the root element because it is the max.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Return max value\n  this.findMax = () => list[0];</code></pre></div>\n<hr>\n<h3>Delete max from the heap</h3>\n<p>Delete the root to remove the max. We can use the exisiting delete method for it.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Remove max val\n  this.deleteMax = () => {\n    this.delete(list[0]);\n  }</code></pre></div>\n<hr>\n<h3>Extract max from the heap</h3>\n<p>Store the max value in a variable and then delete it from the heap, after that return the value.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Remove and return max value\n  this.extractMax = () => {\n    const max = list[0];\n    this.delete(max);\n    return max;\n  }</code></pre></div>\n<hr>\n<h3>Size of the heap</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Size\n  this.size = () => list.length;</code></pre></div>\n<hr>\n<h3>IsEmpty check</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//IsEmpty\n  this.isEmpty = () => list.length === 0;</code></pre></div>\n<hr>\n<h3>Get the heap</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Return head\n  this.getList = () => list;</code></pre></div>\n<hr>\n<h2>Complete code of binary heap data structure implemented in Javascript</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function BinaryHeap(){\n  let list = [];\n  \n  //Heapify\n  this.maxHeapify = (arr, n, i) => {\n    let largest = i;\n    let l = 2 * i + 1; //left child index\n    let r = 2 * i + 2; //right child index\n\n    //If left child is smaller than root\n     if (l &lt; n &amp;&amp; arr[l] > arr[largest]) {\n           largest = l; \n     }\n\n     // If right child is smaller than smallest so far \n     if (r &lt; n &amp;&amp; arr[r] > arr[largest]) {\n          largest = r; \n     }\n\n     // If smallest is not root \n     if (largest != i) { \n          let temp = arr[i]; \n          arr[i] = arr[largest]; \n          arr[largest] = temp; \n\n        // Recursively heapify the affected sub-tree \n        this.maxHeapify(arr, n, largest); \n      } \n  }\n  \n  //Insert Value\n  this.insert = (num) => {\n    const size = list.length;\n    \n    if(size === 0){\n      list.push(num);\n    }else{\n      list.push(num);\n\n      //Heapify\n      for (let i = parseInt(list.length / 2 - 1); i >= 0; i--) {\n         this.maxHeapify(list, list.length, i); \n      }\n    }\n  }\n  \n  //Remove value\n  this.delete = (num) => {\n    const size = list.length;\n    \n    //Get the index of the number to be removed\n    let i;\n    for(i = 0; i &lt; size; i++){\n      if(list[i] === num){\n        break;\n      }\n    }\n    \n    //Swap the number with last element\n    [list[i], list[size - 1]] = [list[size - 1], list[i]];\n\n    //Remove the last element\n    list.splice(size - 1);\n    \n    //Heapify the list again\n    for (let i = parseInt(list.length / 2 - 1); i >= 0; i--) {\n         this.maxHeapify(list, list.length, i); \n     }\n  }\n  \n  //Return max value\n  this.findMax = () => list[0];\n  \n  //Remove max val\n  this.deleteMax = () => {\n    this.delete(list[0]);\n  }\n  \n  //Remove and return max value\n  this.extractMax = () => {\n    const max = list[0];\n    this.delete(max);\n    return max;\n  }\n  \n  //Size\n  this.size = () => list.length;\n  \n  //IsEmpty\n  this.isEmpty = () => list.length === 0;\n  \n  //Return head\n  this.getList = () => list;\n}</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nconst heap = new BinaryHeap();\nheap.insert(3);\nheap.insert(4);\nheap.insert(9);\nheap.insert(5);\nheap.insert(2);\nconsole.log(heap.getList());\n\nheap.delete(9);\nconsole.log(heap.getList());\n\nheap.insert(7);\nconsole.log(heap.getList());\n\nOutput:\n[9, 5, 4, 3, 2]\n[5, 3, 4, 2]\n[7, 5, 4, 2, 3]</code></pre></div>\n<hr>\n<h2>Binary heap with Min-Heap</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">BinaryHeap</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">//Heapify</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">minHeapify</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> smallest <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> l <span class=\"token operator\">=</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//left child index</span>\n    <span class=\"token keyword\">let</span> r <span class=\"token operator\">=</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> i <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//right child index</span>\n\n    <span class=\"token comment\">//If left child is smaller than root</span>\n     <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">&lt;</span> n <span class=\"token operator\">&amp;&amp;</span> arr<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n           smallest <span class=\"token operator\">=</span> l<span class=\"token punctuation\">;</span> \n     <span class=\"token punctuation\">}</span>\n\n     <span class=\"token comment\">// If right child is smaller than smallest so far </span>\n     <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">&lt;</span> n <span class=\"token operator\">&amp;&amp;</span> arr<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          smallest <span class=\"token operator\">=</span> r<span class=\"token punctuation\">;</span> \n     <span class=\"token punctuation\">}</span>\n\n     <span class=\"token comment\">// If smallest is not root </span>\n     <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>smallest <span class=\"token operator\">!=</span> i<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> \n          <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> \n          arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> \n          arr<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span> \n\n        <span class=\"token comment\">// Recursively heapify the affected sub-tree </span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">minHeapify</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> smallest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> \n      <span class=\"token punctuation\">}</span> \n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Insert Value</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">insert</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">num</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> size <span class=\"token operator\">=</span> list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    \n    <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>size <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">{</span>\n      list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      \n      <span class=\"token comment\">//Heapify</span>\n      <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n         <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">minHeapify</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">,</span> list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> \n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Remove value</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">delete</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">num</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> size <span class=\"token operator\">=</span> list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    \n    <span class=\"token comment\">//Get the index of the number to be removed</span>\n    <span class=\"token keyword\">let</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> size<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    \n    <span class=\"token comment\">//Swap the number with last element</span>\n    <span class=\"token punctuation\">[</span>list<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> list<span class=\"token punctuation\">[</span>size <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>list<span class=\"token punctuation\">[</span>size <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> list<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">//Remove the last element</span>\n    list<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>size <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    \n    <span class=\"token comment\">//Heapify the list again</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n         <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">minHeapify</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">,</span> list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> \n     <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Return min value</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">findMin</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> list<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">//Remove min val</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">deleteMin</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Remove and return min value</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">extractMin</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> min <span class=\"token operator\">=</span> list<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>min<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> min<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Size</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">size</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">//IsEmpty</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">isEmpty</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> list<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">//Return head</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getList</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> list<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token literal-property property\">Input</span><span class=\"token operator\">:</span>\n<span class=\"token keyword\">const</span> heap <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">BinaryHeap</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nheap<span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nheap<span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nheap<span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nheap<span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nheap<span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>heap<span class=\"token punctuation\">.</span><span class=\"token function\">getList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nheap<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>heap<span class=\"token punctuation\">.</span><span class=\"token function\">getList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nheap<span class=\"token punctuation\">.</span><span class=\"token function\">insert</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>heap<span class=\"token punctuation\">.</span><span class=\"token function\">getList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token literal-property property\">Output</span><span class=\"token operator\">:</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">]</span></code></pre></div>\n<hr>\n<h2>Class based implementation of binary heap in javascript</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">BinaryHeap</span><span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Heapify</span>\n  <span class=\"token function-variable function\">maxHeapify</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> largest <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> l <span class=\"token operator\">=</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//left child index</span>\n    <span class=\"token keyword\">let</span> r <span class=\"token operator\">=</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> i <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//right child index</span>\n\n    <span class=\"token comment\">//If left child is smaller than root</span>\n     <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">&lt;</span> n <span class=\"token operator\">&amp;&amp;</span> arr<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> arr<span class=\"token punctuation\">[</span>largest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n           largest <span class=\"token operator\">=</span> l<span class=\"token punctuation\">;</span> \n     <span class=\"token punctuation\">}</span>\n\n     <span class=\"token comment\">// If right child is smaller than smallest so far </span>\n     <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">&lt;</span> n <span class=\"token operator\">&amp;&amp;</span> arr<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> arr<span class=\"token punctuation\">[</span>largest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          largest <span class=\"token operator\">=</span> r<span class=\"token punctuation\">;</span> \n     <span class=\"token punctuation\">}</span>\n\n     <span class=\"token comment\">// If smallest is not root </span>\n     <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>largest <span class=\"token operator\">!=</span> i<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> \n          <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> \n          arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>largest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> \n          arr<span class=\"token punctuation\">[</span>largest<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span> \n\n        <span class=\"token comment\">// Recursively heapify the affected sub-tree </span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">maxHeapify</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> largest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> \n      <span class=\"token punctuation\">}</span> \n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Insert Value</span>\n  <span class=\"token function-variable function\">insert</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">num</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> size <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>size <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      \n      <span class=\"token comment\">//Heapify</span>\n      <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n         <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">maxHeapify</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> \n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Remove value</span>\n  <span class=\"token function-variable function\">delete</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">num</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> size <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    \n    <span class=\"token comment\">//Get the index of the number to be removed</span>\n    <span class=\"token keyword\">let</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> size<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>num <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    \n    <span class=\"token comment\">//Swap the number with last element</span>\n    <span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span>size <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span>size <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    \n    <span class=\"token comment\">//Remove the last element</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>size <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    \n    <span class=\"token comment\">//Heapify the list again</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n         <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">maxHeapify</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> \n     <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Return max value</span>\n  <span class=\"token function-variable function\">findMax</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">//Remove max val</span>\n  <span class=\"token function-variable function\">deleteMax</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Remove and return max value</span>\n  <span class=\"token function-variable function\">extractMax</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> max <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>max<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> max<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  \n  <span class=\"token comment\">//Size</span>\n  <span class=\"token function-variable function\">size</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">//IsEmpty</span>\n  <span class=\"token function-variable function\">isEmpty</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">//Return head</span>\n  <span class=\"token function-variable function\">getList</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>list<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Time complexity of heap data structure</h3>\n<table>\n<thead>\n<tr>\n<th>#</th>\n<th>Access</th>\n<th>Search</th>\n<th>Insert</th>\n<th>Delete</th>\n<th>FindMax or (Min)</th>\n<th>DeleteMax or (Min)</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Average</td>\n<td>Θ(N)</td>\n<td>Θ(N)</td>\n<td>ΘLog(N)</td>\n<td>ΘLog(N)</td>\n<td>Θ(1)</td>\n<td>ΘLog(N)</td>\n</tr>\n<tr>\n<td>Worst</td>\n<td>O(N)</td>\n<td>O(N)</td>\n<td>OLog(N)</td>\n<td>OLog(N)</td>\n<td>O(1)</td>\n<td>OLog(N)</td>\n</tr>\n</tbody>\n</table>\n<h3>Space complexity</h3>\n<hr>\n<h3>Applications</h3>\n<ul>\n<li>Implementing a priority queue.</li>\n<li>Dijkstra's Algorithm.</li>\n<li>Heap Sort.</li>\n</ul>"},{"url":"/docs/interact/react-testing-library/","relativePath":"docs/interact/react-testing-library.md","relativeDir":"docs/interact","base":"react-testing-library.md","name":"react-testing-library","frontmatter":{"title":"React Testing Library","weight":0,"excerpt":"React Testing Library","seo":{"title":"React Testing Library","description":"React Testing Library","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://testing-playground.com/embed/27ea36b9aa7868d05a38787a6bd21518/99c765c3a2ac8895c8dd1b866b663186e1700093?panes=query,result\" height=\"450\" width=\"100%\" scrolling=\"yes\" frameBorder=\"0\"  title=\"Testing Playground\" style=\"display: block; width: 100%\">\n</iframe>\n<br>\n<h1>🧪 React Testing Library</h1>\n<h2>About Queries | Testing Library</h2>\n<blockquote>\n<h4>Excerpt</h4>\n<p>Overview</p>\n</blockquote>\n<hr>\n<h3>Overview</h3>\n<p>Queries are the methods that Testing Library gives you to find elements on the page. There are several <a href=\"https://testing-library.com/docs/queries/about/#types-of-queries\">types of queries</a> (\"get\", \"find\", \"query\"); the difference between them is whether the query will throw an error if no element is found or if it will return a Promise and retry. Depending on what page content you are selecting, different queries may be more or less appropriate. See the <a href=\"https://testing-library.com/docs/queries/about/#priority\">priority guide</a> for recommendations on how to make use of semantic queries to test your page in the most accessible way.</p>\n<p>After selecting an element, you can use the <a href=\"https://testing-library.com/docs/dom-testing-library/api-events\">Events API</a> or <a href=\"https://testing-library.com/docs/ecosystem-user-event\">user-event</a> to fire events and simulate user interactions with the page, or use Jest and <a href=\"https://testing-library.com/docs/ecosystem-jest-dom\">jest-dom</a> to make assertions about the element.</p>\n<p>There are Testing Library helper methods that work with queries. As elements appear and disappear in response to actions, <a href=\"https://testing-library.com/docs/dom-testing-library/api-async\">Async APIs</a> like <a href=\"https://testing-library.com/docs/dom-testing-library/api-async#waitfor\"><code class=\"language-text\">waitFor</code></a> or <a href=\"https://testing-library.com/docs/dom-testing-library/api-async#findby-queries\"><code class=\"language-text\">findBy</code> queries</a> can be used to await the changes in the DOM. To find only elements that are children of a specific element, you can use <a href=\"https://testing-library.com/docs/dom-testing-library/api-within\"><code class=\"language-text\">within</code></a>. If necessary, there are also a few options you can <a href=\"https://testing-library.com/docs/dom-testing-library/api-configuration\">configure</a>, like the timeout for retries and the default testID attribute.</p>\n<h3>Example</h3>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> render<span class=\"token punctuation\">,</span> screen <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@testing-library/react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// (or /dom, /vue, ...)test('should show login form', () => {  render(&lt;Login />)</span>\n\n<span class=\"token keyword\">const</span> input <span class=\"token operator\">=</span> screen<span class=\"token punctuation\">.</span><span class=\"token function\">getByLabelText</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Username'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Events and assertions...})</span></code></pre></div>\n<h3>Types of Queries</h3>\n<ul>\n<li>\n<p>Single Elements</p>\n<ul>\n<li><code class=\"language-text\">getBy...</code>: Returns the matching node for a query, and throw a descriptive error if no elements match <em>or</em> if more than one match is found (use <code class=\"language-text\">getAllBy</code> instead if more than one element is expected).</li>\n<li><code class=\"language-text\">queryBy...</code>: Returns the matching node for a query, and return <code class=\"language-text\">null</code> if no elements match. This is useful for asserting an element that is not present. Throws an error if more than one match is found (use <code class=\"language-text\">queryAllBy</code> instead if this is OK).</li>\n<li><code class=\"language-text\">findBy...</code>: Returns a Promise which resolves when an element is found which matches the given query. The promise is rejected if no element is found or if more than one element is found after a default timeout of 1000ms. If you need to find more than one element, use <code class=\"language-text\">findAllBy</code>.</li>\n</ul>\n</li>\n<li>\n<p>Multiple Elements</p>\n<ul>\n<li><code class=\"language-text\">getAllBy...</code>: Returns an array of all matching nodes for a query, and throws an error if no elements match.</li>\n<li><code class=\"language-text\">queryAllBy...</code>: Returns an array of all matching nodes for a query, and return an empty array (<code class=\"language-text\">[]</code>) if no elements match.</li>\n<li>\n<p><code class=\"language-text\">findAllBy...</code>: Returns a promise which resolves to an array of elements when any elements are found which match the given query. The promise is rejected if no elements are found after a default timeout of <code class=\"language-text\">1000</code>ms.</p>\n<ul>\n<li><code class=\"language-text\">findBy</code> methods are a combination of <code class=\"language-text\">getBy*</code> queries and <a href=\"https://testing-library.com/docs/dom-testing-library/api-async#waitfor\"><code class=\"language-text\">waitFor</code></a>. They accept the <code class=\"language-text\">waitFor</code> options as the last argument (i.e. <code class=\"language-text\">await screen.findByText('text', queryOptions, waitForOptions)</code>)</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<p>Summary Table</p>\n<table>\n<thead>\n<tr>\n<th>Type of Query</th>\n<th>0 Matches</th>\n<th>1 Match</th>\n<th>>1 Matches</th>\n<th>Retry (Async/Await)</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>Single Element</strong></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">getBy...</code></td>\n<td>Throw error</td>\n<td>Return element</td>\n<td>Throw error</td>\n<td>No</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">queryBy...</code></td>\n<td>Return <code class=\"language-text\">null</code></td>\n<td>Return element</td>\n<td>Throw error</td>\n<td>No</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">findBy...</code></td>\n<td>Throw error</td>\n<td>Return element</td>\n<td>Throw error</td>\n<td>Yes</td>\n</tr>\n<tr>\n<td><strong>Multiple Elements</strong></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">getAllBy...</code></td>\n<td>Throw error</td>\n<td>Return array</td>\n<td>Return array</td>\n<td>No</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">queryAllBy...</code></td>\n<td>Return <code class=\"language-text\">[]</code></td>\n<td>Return array</td>\n<td>Return array</td>\n<td>No</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">findAllBy...</code></td>\n<td>Throw error</td>\n<td>Return array</td>\n<td>Return array</td>\n<td>Yes</td>\n</tr>\n</tbody>\n</table>\n<h3>Priority</h3>\n<p>Based on <a href=\"https://testing-library.com/docs/guiding-principles\">the Guiding Principles</a>, your test should resemble how users interact with your code (component, page, etc.) as much as possible. With this in mind, we recommend this order of priority:</p>\n<ol>\n<li>\n<p><strong>Queries Accessible to Everyone</strong> Queries that reflect the experience of visual/mouse users as well as those that use assistive technology.</p>\n<ol>\n<li><code class=\"language-text\">getByRole</code>: This can be used to query every element that is exposed in the <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/AOM\">accessibility tree</a>. With the <code class=\"language-text\">name</code> option you can filter the returned elements by their <a href=\"https://www.w3.org/TR/accname-1.1/\">accessible name</a>. This should be your top preference for just about everything. There's not much you can't get with this (if you can't, it's possible your UI is inaccessible). Most often, this will be used with the <code class=\"language-text\">name</code> option like so: <code class=\"language-text\">getByRole('button', {name: /submit/i})</code>. Check the <a href=\"https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#Roles\">list of roles</a>.</li>\n<li><code class=\"language-text\">getByLabelText</code>: This method is really good for form fields. When navigating through a website form, users find elements using label text. This method emulates that behavior, so it should be your top preference.</li>\n<li><code class=\"language-text\">getByPlaceholderText</code>: <a href=\"https://www.nngroup.com/articles/form-design-placeholders/\">A placeholder is not a substitute for a label</a>. But if that's all you have, then it's better than alternatives.</li>\n<li><code class=\"language-text\">getByText</code>: Outside of forms, text content is the main way users find elements. This method can be used to find non-interactive elements (like divs, spans, and paragraphs).</li>\n<li><code class=\"language-text\">getByDisplayValue</code>: The current value of a form element can be useful when navigating a page with filled-in values.</li>\n</ol>\n</li>\n<li>\n<p><strong>Semantic Queries</strong> HTML5 and ARIA compliant selectors. Note that the user experience of interacting with these attributes varies greatly across browsers and assistive technology.</p>\n<ol>\n<li><code class=\"language-text\">getByAltText</code>: If your element is one which supports <code class=\"language-text\">alt</code> text (<code class=\"language-text\">img</code>, <code class=\"language-text\">area</code>, <code class=\"language-text\">input</code>, and any custom element), then you can use this to find that element.</li>\n<li><code class=\"language-text\">getByTitle</code>: The title attribute is not consistently read by screenreaders, and is not visible by default for sighted users</li>\n</ol>\n</li>\n<li>\n<p><strong>Test IDs</strong></p>\n<ol>\n<li><code class=\"language-text\">getByTestId</code>: The user cannot see (or hear) these, so this is only recommended for cases where you can't match by role or text or it doesn't make sense (e.g. the text is dynamic).</li>\n</ol>\n</li>\n</ol>\n<h3>Using Queries</h3>\n<p>The base queries from DOM Testing Library require you to pass a <code class=\"language-text\">container</code> as the first argument. Most framework-implementations of Testing Library provide a pre-bound version of these queries when you render your components with them which means you <em>do not have to provide a container</em>. In addition, if you just want to query <code class=\"language-text\">document.body</code> then you can use the <a href=\"https://testing-library.com/docs/queries/about/#screen\"><code class=\"language-text\">screen</code></a> export as demonstrated below (using <code class=\"language-text\">screen</code> is recommended).</p>\n<p>The primary argument to a query can be a <em>string</em>, <em>regular expression</em>, or <em>function</em>. There are also options to adjust how node text is parsed. See <a href=\"https://testing-library.com/docs/queries/about/#textmatch\">TextMatch</a> for documentation on what can be passed to a query.</p>\n<p>Given the following DOM elements (which can be rendered by React, Vue, Angular, or plain HTML code):</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>body</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>app<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>label</span> <span class=\"token attr-name\">for</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>username-input<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>Username<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>label</span><span class=\"token punctuation\">></span></span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>input</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>username-input<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>body</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>You can use a query to find an element (byLabelText, in this case):</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> screen<span class=\"token punctuation\">,</span> getByLabelText <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@testing-library/dom'</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// With screen:</span>\n\n<span class=\"token keyword\">const</span> inputNode1 <span class=\"token operator\">=</span> screen<span class=\"token punctuation\">.</span><span class=\"token function\">getByLabelText</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Username'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Without screen, you need to provide a container:</span>\n\n<span class=\"token keyword\">const</span> container <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'#app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> inputNode2 <span class=\"token operator\">=</span> <span class=\"token function\">getByLabelText</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">,</span> <span class=\"token string\">'Username'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4><code class=\"language-text\">screen</code></h4>\n<p>All of the queries exported by DOM Testing Library accept a <code class=\"language-text\">container</code> as the first argument. Because querying the entire <code class=\"language-text\">document.body</code> is very common, DOM Testing Library also exports a <code class=\"language-text\">screen</code> object which has every query that is pre-bound to <code class=\"language-text\">document.body</code> (using the <a href=\"https://testing-library.com/docs/dom-testing-library/api-within\"><code class=\"language-text\">within</code></a> functionality). Wrappers such as React Testing Library re-export <code class=\"language-text\">screen</code> so you can use it the same way.</p>\n<p>Here's how you use it:</p>\n<ul>\n<li>Native</li>\n<li>React</li>\n<li>Cypress</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> screen <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@testing-library/dom'</span><span class=\"token punctuation\">;</span>\ndocument<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">  &lt;label for=\"example\">Example&lt;/label>  &lt;input id=\"example\" /></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> exampleInput <span class=\"token operator\">=</span> screen<span class=\"token punctuation\">.</span><span class=\"token function\">getByLabelText</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Example'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p><strong>Note</strong></p>\n<p>You need a global DOM environment to use <code class=\"language-text\">screen</code>. If you're using jest, with the <a href=\"https://jestjs.io/docs/en/configuration#testenvironment-string\">testEnvironment</a> set to <code class=\"language-text\">jsdom</code>, a global DOM environment will be available for you.</p>\n<p>If you're loading your test with a <code class=\"language-text\">script</code> tag, make sure it comes after the <code class=\"language-text\">body</code>. An example can be seen <a href=\"https://github.com/testing-library/dom-testing-library/issues/700#issuecomment-692218886\">here</a>.</p>\n</blockquote>\n<h3><code class=\"language-text\">TextMatch</code></h3>\n<p>Most of the query APIs take a <code class=\"language-text\">TextMatch</code> as an argument, which means the argument can be either a <em>string</em>, <em>regex</em>, or a <em>function</em> which returns <code class=\"language-text\">true</code> for a match and <code class=\"language-text\">false</code> for a mismatch.</p>\n<h4>TextMatch Examples</h4>\n<p>Given the following HTML:</p>\n<p><em><strong>Will</strong></em>** find the div:**</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Matching a string:screen.getByText('Hello World')</span>\n<span class=\"token comment\">// full string matchscreen.getByText('llo Worl', {exact: false})</span>\n<span class=\"token comment\">// substring matchscreen.getByText('hello world', {exact: false})</span>\n<span class=\"token comment\">// ignore case</span>\n<span class=\"token comment\">// Matching a regex:screen.getByText(/World/)</span>\n<span class=\"token comment\">// substring matchscreen.getByText(/world/i)</span>\n<span class=\"token comment\">// substring match, ignore casescreen.getByText(/^hello world$/i)</span>\n<span class=\"token comment\">// full string match, ignore casescreen.getByText(/Hello W?oRlD/i)</span>\n<span class=\"token comment\">// substring match, ignore case, searches for \"hello world\" or \"hello orld\"</span>\n<span class=\"token comment\">// Matching with a custom function:screen.getByText((content, element) => content.startsWith('Hello'))</span></code></pre></div>\n<p><em><strong>Will not</strong></em>** find the div:**</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// full string does not matchscreen.getByText('Goodbye World')</span>\n<span class=\"token comment\">// case-sensitive regex with different casescreen.getByText(/hello world/)</span>\n<span class=\"token comment\">// function looking for a span when it's actually a div:screen.getByText((content, element) => {  return element.tagName.toLowerCase() === 'span' &amp;&amp; content.startsWith('Hello')})</span></code></pre></div>\n<h4>Precision</h4>\n<p>Queries that take a <code class=\"language-text\">TextMatch</code> also accept an object as the final argument that can contain options that affect the precision of string matching:</p>\n<ul>\n<li>\n<p><code class=\"language-text\">exact</code>: Defaults to <code class=\"language-text\">true</code>; matches full strings, case-sensitive. When false, matches substrings and is not case-sensitive.</p>\n<ul>\n<li><code class=\"language-text\">exact</code> has no effect on <code class=\"language-text\">regex</code> or <code class=\"language-text\">function</code> arguments.</li>\n<li>In most cases using a regex instead of a string gives you more control over fuzzy matching and should be preferred over <code class=\"language-text\">{ exact: false }</code>.</li>\n</ul>\n</li>\n<li><code class=\"language-text\">normalizer</code>: An optional function which overrides normalization behavior. See <a href=\"https://testing-library.com/docs/queries/about/#normalization\"><code class=\"language-text\">Normalization</code></a>.</li>\n</ul>\n<h4>Normalization</h4>\n<p>Before running any matching logic against text in the DOM, <code class=\"language-text\">DOM Testing Library</code> automatically normalizes that text. By default, normalization consists of trimming whitespace from the start and end of text, and collapsing multiple adjacent whitespace characters into a single space.</p>\n<p>If you want to prevent that normalization, or provide alternative normalization (e.g. to remove Unicode control characters), you can provide a <code class=\"language-text\">normalizer</code> function in the options object. This function will be given a string and is expected to return a normalized version of that string.</p>\n<blockquote>\n<p><strong>Note</strong></p>\n<p>Specifying a value for <code class=\"language-text\">normalizer</code> <em>replaces</em> the built-in normalization, but you can call <code class=\"language-text\">getDefaultNormalizer</code> to obtain a built-in normalizer, either to adjust that normalization or to call it from your own normalizer.</p>\n</blockquote>\n<p><code class=\"language-text\">getDefaultNormalizer</code> takes an options object which allows the selection of behaviour:</p>\n<ul>\n<li><code class=\"language-text\">trim</code>: Defaults to <code class=\"language-text\">true</code>. Trims leading and trailing whitespace</li>\n<li><code class=\"language-text\">collapseWhitespace</code>: Defaults to <code class=\"language-text\">true</code>. Collapses inner whitespace (newlines, tabs, repeated spaces) into a single space.</li>\n</ul>\n<hr>\n<h4>Normalization Examples</h4>\n<p>To perform a match against text without trimming:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\">screen<span class=\"token punctuation\">.</span><span class=\"token function\">getByText</span><span class=\"token punctuation\">(</span><span class=\"token string\">'text'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> normalizer<span class=\"token operator\">:</span> <span class=\"token function\">getDefaultNormalizer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> trim<span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To override normalization to remove some Unicode characters whilst keeping some (but not all) of the built-in normalization behavior:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\">screen<span class=\"token punctuation\">.</span><span class=\"token function\">getByText</span><span class=\"token punctuation\">(</span><span class=\"token string\">'text'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token function-variable function\">normalizer</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">getDefaultNormalizer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> trim<span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[\\u200E-\\u200F]*</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Debugging</h3>\n<h4><code class=\"language-text\">screen.debug()</code></h4>\n<p>For convenience screen also exposes a <code class=\"language-text\">debug</code> method in addition to the queries. This method is essentially a shortcut for <code class=\"language-text\">console.log(prettyDOM())</code>. It supports debugging the document, a single element, or an array of elements.</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> screen <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@testing-library/dom'</span><span class=\"token punctuation\">;</span>\ndocument<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">  &lt;button>test&lt;/button>  &lt;span>multi-test&lt;/span>  &lt;div>multi-test&lt;/div></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// debug documentscreen.debug()</span>\n<span class=\"token comment\">// debug single elementscreen.debug(screen.getByText('test'))</span>\n<span class=\"token comment\">// debug multiple elementsscreen.debug(screen.getAllByText('multi-test'))</span></code></pre></div>\n<h4><code class=\"language-text\">screen.logTestingPlaygroundURL()</code></h4>\n<p>For debugging using <a href=\"https://testing-playground.com\">testing-playground</a>, screen exposes this convenient method which logs a URL that can be opened in a browser.</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">import</span>  <span class=\"token punctuation\">{</span>screen<span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@testing-library/dom'</span>document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">  &lt;button>test&lt;/button>  &lt;span>multi-test&lt;/span>  &lt;div>multi-test&lt;/div></span><span class=\"token template-punctuation string\">`</span></span>\n<span class=\"token comment\">// log entire document to testing-playgroundscreen.logTestingPlaygroundURL()</span>\n<span class=\"token comment\">// log a single elementscreen.logTestingPlaygroundURL(screen.getByText('test'))</span></code></pre></div>\n<h3>Manual Queries</h3>\n<p>On top of the queries provided by the testing library, you can use the regular <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector\"><code class=\"language-text\">querySelector</code> DOM API</a> to query elements. Note that using this as an escape hatch to query by class or id is not recommended because they are invisible to the user. Use a testid if you have to, to make your intention to fall back to non-semantic queries clear and establish a stable API contract in the HTML.</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// @testing-library/react</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> container <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">MyComponent</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> foo <span class=\"token operator\">=</span> container<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'[data-foo=\"bar\"]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Browser extension</h3>\n<p>Do you still have problems knowing how to use Testing Library queries?</p>\n<p>There is a very cool Browser extension for <a href=\"https://chrome.google.com/webstore/detail/testing-playground/hejbmebodbijjdhflfknehhcgaklhano/related\">Chrome</a> and <a href=\"https://addons.mozilla.org/en/firefox/addon/testing-playground/\">Firefox</a> named Testing Playground, and it helps you find the best queries to select elements. It allows you to inspect the element hierarchies in the Browser's Developer Tools, and provides you with suggestions on how to select them, while encouraging good testing practices.</p>\n<h3>Playground</h3>\n<p>If you want to get more familiar with these queries, you can try them out on <a href=\"https://testing-playground.com\">testing-playground.com</a>. Testing Playground is an interactive sandbox where you can run different queries against your own html, and get visual feedback matching the rules mentioned above.</p>\n<h1>🕚 React Testing Library (events)</h1>\n<h2>Firing Events | Testing Library</h2>\n<blockquote>\n<p><strong>Excerpt</strong></p>\n<p>Note</p>\n</blockquote>\n<hr>\n<blockquote>\n<p><strong>Note</strong></p>\n<p>Most projects have a few use cases for <code class=\"language-text\">fireEvent</code>, but the majority of the time you should probably use [<code class=\"language-text\">@testing-library/user-event</code>](https: //testing-library.com/docs/ecosystem-user-event).</p>\n</blockquote>\n<h3><code class=\"language-text\">fireEvent</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token function\">fireEvent</span><span class=\"token punctuation\">(</span>node<span class=\"token operator\">:</span> HTMLElement<span class=\"token punctuation\">,</span> event<span class=\"token operator\">:</span> Event<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Fire DOM events.</p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token comment\">// &lt;button>Submit&lt;/button>fireEvent(  getByText(container, 'Submit'),  new MouseEvent('click', {    bubbles: true,    cancelable: true,  }),)</span></code></pre></div>\n<h3><code class=\"language-text\">fireEvent[eventName]</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\">fireEvent<span class=\"token punctuation\">[</span>eventName<span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span>node<span class=\"token operator\">:</span> HTMLElement<span class=\"token punctuation\">,</span> eventProperties<span class=\"token operator\">:</span> Object<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Convenience methods for firing DOM events. Check out [src/event-map.js](https: //github.com/testing-library/dom-testing-library/blob/master/src/event-map.js) for a full list as well as default <code class=\"language-text\">eventProperties</code>.</p>\n<p><strong>target</strong>: When an event is dispatched on an element, the event has the subjected element on a property called <code class=\"language-text\">target</code>. As a convenience, if you provide a <code class=\"language-text\">target</code> property in the <code class=\"language-text\">eventProperties</code> (second argument), then those properties will be assigned to the node which is receiving the event.</p>\n<p>This is particularly useful for a change event:</p>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\">fireEvent<span class=\"token punctuation\">.</span><span class=\"token function\">change</span><span class=\"token punctuation\">(</span><span class=\"token function\">getByLabelText</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">username</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> target<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> value<span class=\"token operator\">:</span> <span class=\"token string\">'a'</span> <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// note: attempting to manually set the files property of an HTMLInputElement</span>\n<span class=\"token comment\">// results in an error as the files property is read-only.</span>\n<span class=\"token comment\">// this feature works around that by using Object.defineProperty.fireEvent.change(getByLabelText(/picture/i), {  target: {    files: [new File(['(⌐□_□)'], 'chucknorris.png', {type: 'image/png'})],  },})</span>\n<span class=\"token comment\">// Note: The 'value' attribute must use ISO 8601 format when firing a</span>\n<span class=\"token comment\">// change event on an input of type \"date\". Otherwise the element will not</span>\n<span class=\"token comment\">// reflect the changed value.</span>\n<span class=\"token comment\">// Invalid:fireEvent.change(input, {target: {value: '24/05/2020'}})</span>\n<span class=\"token comment\">// Valid:fireEvent.change(input, {target: {value: '2020-05-24'}})</span></code></pre></div>\n<p><strong>dataTransfer</strong>: Drag events have a <code class=\"language-text\">dataTransfer</code> property that contains data transferred during the operation. As a convenience, if you provide a <code class=\"language-text\">dataTransfer</code> property in the <code class=\"language-text\">eventProperties</code> (second argument), then those properties will be added to the event.</p>\n<p>This should predominantly be used for testing drag and drop interactions.</p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\">fireEvent<span class=\"token punctuation\">.</span><span class=\"token function\">drop</span><span class=\"token punctuation\">(</span><span class=\"token function\">getByLabelText</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">drop files here</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    dataTransfer<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        files<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">File</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'(⌐□_□)'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'chucknorris.png'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> type<span class=\"token operator\">:</span> <span class=\"token string\">'image/png'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Keyboard events</strong>: There are three event types related to keyboard input - <code class=\"language-text\">keyPress</code>, <code class=\"language-text\">keyDown</code>, and <code class=\"language-text\">keyUp</code>. When firing these you need to reference an element in the DOM and the key you want to fire.</p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\">fireEvent<span class=\"token punctuation\">.</span><span class=\"token function\">keyDown</span><span class=\"token punctuation\">(</span>domNode<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>key<span class=\"token operator\">:</span> <span class=\"token string\">'Enter'</span><span class=\"token punctuation\">,</span> code<span class=\"token operator\">:</span> <span class=\"token string\">'Enter'</span><span class=\"token punctuation\">,</span> charCode<span class=\"token operator\">:</span> <span class=\"token number\">13</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>fireEvent<span class=\"token punctuation\">.</span><span class=\"token function\">keyDown</span><span class=\"token punctuation\">(</span>domNode<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>key<span class=\"token operator\">:</span> <span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> code<span class=\"token operator\">:</span> <span class=\"token string\">'KeyA'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can find out which key code to use at [https: //keycode.info/](https: //keycode.info).</p>\n<h3><code class=\"language-text\">createEvent[eventName]</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\">createEvent<span class=\"token punctuation\">[</span>eventName<span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span>node<span class=\"token operator\">:</span> HTMLElement<span class=\"token punctuation\">,</span> eventProperties<span class=\"token operator\">:</span> Object<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Convenience methods for creating DOM events that can then be fired by <code class=\"language-text\">fireEvent</code>, allowing you to have a reference to the event created: this might be useful if you need to access event properties that cannot be initiated programmatically (such as <code class=\"language-text\">timeStamp</code>).</p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">const</span> myEvent <span class=\"token operator\">=</span> createEvent<span class=\"token punctuation\">.</span><span class=\"token function\">click</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>button<span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token function\">fireEvent</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">,</span> myEvent<span class=\"token punctuation\">)</span>\n<span class=\"token comment\">// myEvent.timeStamp can be accessed just like any other properties from myEvent</span>\n<span class=\"token comment\">// note: The access to the events created by `createEvent` is based on the native event API,</span>\n<span class=\"token comment\">// Therefore, native properties of HTMLEvent object (e.g. `timeStamp`, `cancelable`, `type`) should be set using Object.defineProperty</span>\n<span class=\"token comment\">// For more info see: https:</span>\n<span class=\"token comment\">//developer.mozilla.org/en-US/docs/Web/API/Event</span></code></pre></div>\n<p>You can also create generic events:</p>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token comment\">// simulate the 'input' event on a file inputfireEvent(  input,  createEvent('input', input, {    target: {files: inputFiles},    ...init,  }),)</span></code></pre></div>\n<h3>Using Jest Function Mocks</h3>\n<p>[Jest's Mock functions](https: //jestjs.io/docs/en/mock-functions) can be used to test that a callback passed to the function was called, or what it was called when the event that <strong>should</strong> trigger the callback function does trigger the bound callback.</p>\n<ul>\n<li>React</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"typescript\"><pre class=\"language-typescript\"><code class=\"language-typescript\"><span class=\"token keyword\">import</span>  <span class=\"token punctuation\">{</span>render<span class=\"token punctuation\">,</span> screen<span class=\"token punctuation\">,</span> fireEvent<span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@testing-library/react'</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Button</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>onClick<span class=\"token punctuation\">,</span> children<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>onClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span><span class=\"token string\">'calls onClick prop when clicked'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">const</span> handleClick <span class=\"token operator\">=</span> jest<span class=\"token punctuation\">.</span><span class=\"token function\">fn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>handleClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Click Me<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Button<span class=\"token operator\">></span><span class=\"token punctuation\">)</span>  fireEvent<span class=\"token punctuation\">.</span><span class=\"token function\">click</span><span class=\"token punctuation\">(</span>screen<span class=\"token punctuation\">.</span><span class=\"token function\">getByText</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">click me</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token function\">expect</span><span class=\"token punctuation\">(</span>handleClick<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toHaveBeenCalledTimes</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>"},{"url":"/docs/interact/callstack-visual/","relativePath":"docs/interact/callstack-visual.md","relativeDir":"docs/interact","base":"callstack-visual.md","name":"callstack-visual","frontmatter":{"title":"Callstack Visualizer","weight":0,"excerpt":"Callstack Visualizer","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<script async src=\"//jsfiddle.net/bgoonz/tu3Lw57r/embed/result/dark/\">\n</script>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"800px\" width=\"1000px\" scrolling=\"yes\" title=\"Linear vs Binary Search\" src=\"https://codepen.io/bgoonz/embed/MWbZoOa?default-tab=result&editable=true&theme-id=light\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n  See the Pen <a href=\"https://codepen.io/bgoonz/pen/MWbZoOa\">\n  Linear vs Binary Search</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n  on <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n<p class=\"codepen\" data-height=\"300\" data-theme-id=\"light\" data-default-tab=\"result\" data-slug-hash=\"GRNPEdY\" data-editable=\"true\" data-user=\"bgoonz\" style=\"height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;\">\n  <span>See the Pen <a href=\"https://codepen.io/bgoonz/pen/GRNPEdY\">\n  Data Structures Viz</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n  on <a href=\"https://codepen.io\">CodePen</a>.</span>\n</p>\n<script async src=\"https://cpwebassets.codepen.io/assets/embed/ei.js\">\n</script>\n<h2>Callstack Visualizer</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://visualize-callstack-qdvyu8oyc-visualize42.vercel.app/\" height=\"900px\" width=\"100%\">\n</iframe>\n<br>\n<h6>About the Call Stack</h6>\n<p><strong>TL;DR</strong> <em>The <strong>Call Stack</strong> tracks function calls. It is a LIFO stack of frames. Each frame represents a function call.</em></p>\n<hr>\n<p>The <strong>Call Stack</strong> is a fundamental part of the JavaScript language. It is a record-keeping structure that allows us to perform function calls. Each function call is represented as a frame on the <strong>Call Stack</strong>. This is how the JavaScript engine keeps track of which functions have been called and in what order. The JS engine uses this information to ensure execution picks back up in the right spot after a function returns.</p>\n<p>When a JavaScript program first starts executing, the <strong>Call Stack</strong> is empty. When the first function call is made, a new frame is pushed onto the top of the <strong>Call Stack</strong>. When that function returns, its frame is popped off of the <strong>Call Stack</strong>.</p>\n<h6>About the Event Loop</h6>\n<p><strong>TL;DR</strong> <em>The <strong>Event Loop</strong> processes Tasks and Microtasks. It places them into the Call Stack for execution one at a time. It also controls when rerendering occurs.</em></p>\n<hr>\n<p>The Event Loop is a looping algorithm that processes the Tasks/Microtasks in the Task Queue and Microtask Queue. It handles selecting the next Task/Microtask to be run and placing it in the Call Stack for execution.</p>\n<p>The Event Loop algorithm consists of four key steps:</p>\n<ol>\n<li><strong>Evaluate Script:</strong> Synchronously execute the script as though it were a function body. Run until the Call Stack is empty.</li>\n<li><strong>Run a Task:</strong> Select the oldest Task from the Task Queue. Run it until the Call Stack is empty.</li>\n<li><strong>Run all Microtasks:</strong> Select the oldest Microtask from the Microtask Queue. Run it until the Call Stack is empty. Repeat until the Microtask Queue is empty.</li>\n<li><strong>Rerender the UI:</strong> Rerender the UI. Then, return to step 2. (This step only applies to browsers, not NodeJS).</li>\n</ol>\n<p>Let's model the Event Loop with some JavaScript psuedocode:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">while (EventLoop.waitForTask()) {\n  const taskQueue = EventLoop.selectTaskQueue();\n  if (taskQueue.hasNextTask()) {\n    taskQueue.processNextTask();\n  }\n\n  const microtaskQueue = EventLoop.microTaskQueue;\n  while (microtaskQueue.hasNextMicrotask()) {\n    microtaskQueue.processNextMicrotask();\n  }\n\n  rerender();\n}</code></pre></div>"},{"url":"/docs/interact/clock/","relativePath":"docs/interact/clock.md","relativeDir":"docs/interact","base":"clock.md","name":"clock","frontmatter":{"title":"Clock","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<center>\n<h2 style=\" margin-bottom: 2em; align-self:center;\">World Clock(Click To See Localized Time)</h2>\n</center>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://observablehq.com/embed/1b6399182c98cd36@480?cells=chart%2Cviewof+date\" loading=\"lazy\"\nwidth=\"90%\" height=\"629\" frameborder=\"0\">\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/bgoonz/full/QWgYoBp\" loading=\"lazy\"\nwidth=\"90%\" height=\"629\" frameborder=\"0\">"},{"url":"/docs/interact/","relativePath":"docs/interact/index.md","relativeDir":"docs/interact","base":"index.md","name":"index","frontmatter":{"title":"Interact","weight":0,"excerpt":"Interactive examples and projects","seo":{"title":"Interactive Examples","description":"here is content the user can interact with","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<ul>\n<li><a href=\"https://ds-algo-official.netlify.app/\">Data Structures Interactive</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://ds-algo-official.netlify.app/\" height=\"900px\" width=\"100%\">\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://bgoonz-games.netlify.app/\">Games</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bgoonz-games.netlify.app/\" height=\"900px\" width=\"100%\">\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://webdevhub42.notion.site/Embeds-a3b7edb038b246a0adbfed9de9c2a9ac\">Embeds</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://random-static-html-deploys.netlify.app/embeds_notion\" height=\"900px\" width=\"100%\">\n</iframe>\n<br>"},{"url":"/docs/interact/other-sites/","relativePath":"docs/interact/other-sites.md","relativeDir":"docs/interact","base":"other-sites.md","name":"other-sites","frontmatter":{"title":"Other Websites","weight":0,"seo":{"title":"Typography","description":"This is the typography page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Typography","keyName":"property"},{"name":"og:description","value":"This is the typography page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Typography"},{"name":"twitter:description","value":"This is the typography page"}]},"template":"docs"},"html":"<h1> Here are some other websites I have worked on since endeavoring to learn web development! </h1>\n<br>\n<h1>  Alternate Blog</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"  https://bgoonz-blog-v3-0.netlify.app/  \" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Games </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"  https://bgoonz-games.netlify.app/  \" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h1>  Projects         </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\" https://project-portfolio42.netlify.app/  \" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Wordpress Site </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    class=\"inner\" src=\"  https://bgoonz-blog.netlify.app/  \" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Interview     </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\" src=\"   \" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Speach Recognition api </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\" class=\"   \" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  The Algos Bgoonz Branch </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bgoonz-branch-the-algos.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://thealgorithms.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>"},{"url":"/docs/interact/video-chat/","relativePath":"docs/interact/video-chat.md","relativeDir":"docs/interact","base":"video-chat.md","name":"video-chat","frontmatter":{"title":"Zumzi Video Conferencing (Mesibo API Backend)","weight":0,"excerpt":"Video chat front end app","seo":{"title":"Zumzi Video Conference:","description":"Features:\nGroup Voice and Video Call with unlimited members\nLive Streaming\nScreen Sharing\nSupports video streaming at various resolutions.","robots":[],"extra":[{"name":"og:description","value":"Features:\nGroup Voice and Video Call with unlimited members\nLive Streaming\nScreen Sharing\nSupports video streaming at various resolutions.","keyName":"property","relativeUrl":false},{"name":"og:title","value":"Zumzi Video Conference:","keyName":"property","relativeUrl":false},{"name":"og:image","value":"images/zumzi-video-chat-0aba1c15.png","keyName":"property","relativeUrl":true}],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Zumzi Video Conference:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    class=\"block-content\" width=\"100%  width=\"1000px\" height=\"1400px\"\n        src=\"https://zumzi-chat-messenger.vercel.app/web/login.html\">\n</iframe>\n<br>\n<h2>Zumzi Live Demo</h2>\n<p><img src=\"https://zumzi-chat-messenger.vercel.app/web/login.html\" alt=\"demo\"></p>\n<h2>Features:</h2>\n<ul>\n<li>Group Voice and Video Call with unlimited members</li>\n<li>Live Streaming</li>\n<li>Screen Sharing</li>\n<li>Fine control over all video &#x26; audio parameters and user permissions</li>\n<li>Supports video streaming at various resolutions: Standard, HD, FHD and 4K</li>\n<li>Group Chat</li>\n<li>One-to-One chat</li>\n<li>Invite Participants</li>\n</ul>\n<p>There are two sub-folders:</p>\n<ul>\n<li><strong>backend</strong> contains the source code for hosting the backend APIs for the app</li>\n<li><strong>web</strong> contains the source code for the app which you can directly integrate into your website.</li>\n</ul>\n<h2>Apendix</h2>\n<ul>\n<li>\n<p>access token:</p>\n<blockquote>\n<p>An Access Token needs to be generated for every user who needs to access mesibo real-time messaging API. You can generate Access Token for every user of your application on demand and send it to the user. The user will then use this access token to initialize mesibo client-side API..</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>api key</p>\n<blockquote>\n<p>API key is a unique alphanumeric identifier associated with your Mesibo account. You can view, change or regenerate the API key from the Mesibo console.</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>Application Token</p>\n<blockquote>\n<p>is a unique alphanumeric identifier with one of your application. You can view and change the app token from the Mesibo Console.</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>Mesibo container</p>\n<blockquote>\n<p>A container is a runtime instance of mesibo in-premises docker image.</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>MAU</p>\n<blockquote>\n<p>MAU is counted when a user connects to mesibo server within monthly billing period. To further clarify, it will be only counted as one when a unique user connects to mesibo server multiple times within monthly billing period</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>High-availability clusters</p>\n<blockquote>\n<p>(also known as HA clusters or fail-over clusters) are\ngroups of computers that support server applications that can be reliably utilized with a minimum amount of down-time</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>namespace</p>\n<blockquote>\n<p>in mesibo is refer to a mesibo feature that isolates users and groups of an application from another application. Users can only interact with users and groups of the same application that are part of the same namespace. Namespaces are an important part of Mesibo's isolation model</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>node</p>\n<blockquote>\n<p>A [node]is a physical or virtual machine running an instance of the mesibo.</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>On premises deployment</p>\n<blockquote>\n<p>Mesibo On-premises deploment allows you to run Mesibo in your own data center or cloud.</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>1-1 Communication</p>\n<blockquote>\n<p>Communication is between two parties; for example, a chat or a call</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<ul>\n<li>\n<p>Peer-to-peer\n(P2P)</p>\n<blockquote>\n<p>It is a distributed application architecture that partitions tasks or workloads between peers. Peers are equally privileged, equipotent participants in the application.They are said to form a peer-to-peer network of nodes.</p>\n</blockquote>\n</li>\n</ul>\n<hr>\n<p><img src=\"https://github.com/bgoonz/zumzi-chat-messenger/blob/master/zumzi.png?raw=true\" alt=\"zzumzi\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[.](.)&lt;br>\n├── [./backend](./backend)\n│ ├── [./backend/activation.php](./backend/activation.php)\n│ ├── [./backend/api_functions.php](./backend/api_functions.php)\n│ ├── [./backend/api.php](./backend/api.php)\n│ ├── [./backend/captcha.php](./backend/captcha.php)\n│ ├── [./backend/config.php](./backend/config.php)\n│ ├── [./backend/consts.php](./backend/consts.php)\n│ ├── [./backend/db.sql](./backend/db.sql)\n│ ├── [./backend/errorhandler.php](./backend/errorhandler.php)\n│ ├── [./backend/httpheaders.php](./backend/httpheaders.php)\n│ ├── [./backend/image.php](./backend/image.php)\n│ ├── [./backend/json.php](./backend/json.php)\n│ ├── [./backend/mesiboapi.php](./backend/mesiboapi.php)\n│ ├── [./backend/mesibohelper.php](./backend/mesibohelper.php)\n│ ├── [./backend/mysqldb.php](./backend/mysqldb.php)\n│ ├── [./backend/mysql-wrapper.php](./backend/mysql-wrapper.php)\n│ ├── [./backend/README.md](./backend/README.md)\n│ ├── [./backend/upload.php](./backend/upload.php)\n│ └── [./backend/utility.php](./backend/utility.php)\n├── [./glossary_files](./glossary_files)\n│ ├── [./glossary_files/559862854355634.js](./glossary_files/559862854355634.js)\n│ ├── [./glossary_files/analytics.js](./glossary_files/analytics.js)\n│ ├── [./glossary_files/archive.js](./glossary_files/archive.js)\n│ ├── [./glossary_files/bootstrap.min.css](./glossary_files/bootstrap.min.css)\n│ ├── [./glossary_files/bootstrap.min.js](./glossary_files/bootstrap.min.js)\n│ ├── [./glossary_files/buttons.js](./glossary_files/buttons.js)\n│ ├── [./glossary_files/collections_tocs.js](./glossary_files/collections_tocs.js)\n│ ├── [./glossary_files/css.css](./glossary_files/css.css)\n│ ├── [./glossary_files/docs.js](./glossary_files/docs.js)\n│ ├── [./glossary_files/fbevents.js](./glossary_files/fbevents.js)\n│ ├── [./glossary_files/font-awesome.min.css](./glossary_files/font-awesome.min.css)\n│ ├── [./glossary_files/github.css](./glossary_files/github.css)\n│ ├── [./glossary_files/glossary.js](./glossary_files/glossary.js)\n│ ├── [./glossary_files/jquery.js](./glossary_files/jquery.js)\n│ ├── [./glossary_files/menu.js](./glossary_files/menu.js)\n│ ├── [./glossary_files/mesibo-logo.svg](./glossary_files/mesibo-logo.svg)\n│ ├── [./glossary_files/mesibo-logo-white.png](./glossary_files/mesibo-logo-white.png)\n│ ├── [./glossary_files/metadata.js](./glossary_files/metadata.js)\n│ ├── [./glossary_files/perldoc.css](./glossary_files/perldoc.css)\n│ ├── [./glossary_files/stickyfill.min.js](./glossary_files/stickyfill.min.js)\n│ ├── [./glossary_files/style.css](./glossary_files/style.css)\n│ └── [./glossary_files/toc.js](./glossary_files/toc.js)&lt;br>\n├── [./glossary.html](./glossary.html)&lt;br>\n├── [./index.html](./index.html)&lt;br>\n├── [./package-lock.json](./package-lock.json)&lt;br>\n├── [./README.md](./README.md)&lt;br>\n├── [./scrap.md](./scrap.md)&lt;br>\n├── [./tree.md](./tree.md)&lt;br>\n├── [./TREE.md](./TREE.md)&lt;br>\n├── [./web](./web)\n│ ├── [./web/assets](./web/assets)\n│ │ ├── [./web/assets/audio](./web/assets/audio)\n│ │ │ ├── [./web/assets/audio/join.mp3](./web/assets/audio/join.mp3)\n│ │ │ └── [./web/assets/audio/join.ogg](./web/assets/audio/join.ogg)\n│ │ ├── [./web/assets/fonts](./web/assets/fonts)\n│ │ │ └── [./web/assets/fonts/font-awesome](./web/assets/fonts/font-awesome)\n│ │ │ └── [./web/assets/fonts/font-awesome/css](./web/assets/fonts/font-awesome/css)\n│ │ │ └── [./web/assets/fonts/font-awesome/css/font-awesome.css](./web/assets/fonts/font-awesome/css/font-awesome.css)\n│ │ ├── [./web/assets/images](./web/assets/images)\n│ │ │ ├── [./web/assets/images/blank-white.jpg](./web/assets/images/blank-white.jpg)\n│ │ │ ├── [./web/assets/images/file](./web/assets/images/file)\n│ │ │ │ └── [./web/assets/images/file/default_file_icon.jpg](./web/assets/images/file/default_file_icon.jpg)\n│ │ │ ├── [./web/assets/images/mesibo-logo-m.png](./web/assets/images/mesibo-logo-m.png)\n│ │ │ ├── [./web/assets/images/mesibo-logo.png](./web/assets/images/mesibo-logo.png)\n│ │ │ ├── [./web/assets/images/profile](./web/assets/images/profile)\n│ │ │ │ ├── [./web/assets/images/profile/default-group-icon.jpg](./web/assets/images/profile/default-group-icon.jpg)\n│ │ │ │ └── [./web/assets/images/profile/default-profile-icon.jpg](./web/assets/images/profile/default-profile-icon.jpg)\n│ │ │ └── [./web/assets/images/social.png](./web/assets/images/social.png)\n│ │ └── [./web/assets/scripts](./web/assets/scripts)\n│ │ └── [./web/assets/scripts/platform.js](./web/assets/scripts/platform.js)\n│ ├── [./web/index.html](./web/index.html)\n│ ├── [./web/listing.md](./web/listing.md)\n│ ├── [./web/login.html](./web/login.html)\n│ ├── [./web/mesibo](./web/mesibo)\n│ │ ├── [./web/mesibo/app.js](./web/mesibo/app.js)\n│ │ ├── [./web/mesibo/calls.js](./web/mesibo/calls.js)\n│ │ ├── [./web/mesibo/config.js](./web/mesibo/config.js)\n│ │ ├── [./web/mesibo/files.js](./web/mesibo/files.js)\n│ │ ├── [./web/mesibo/notify.js](./web/mesibo/notify.js)\n│ │ └── [./web/mesibo/utils.js](./web/mesibo/utils.js)\n│ ├── [./web/README.md](./web/README.md)\n│ ├── [./web/scripts](./web/scripts)\n│ │ ├── [./web/scripts/app-utils.js](./web/scripts/app-utils.js)\n│ │ ├── [./web/scripts/controller.js](./web/scripts/controller.js)\n│ │ └── [./web/scripts/login.js](./web/scripts/login.js)\n│ ├── [./web/styles](./web/styles)\n│ │ ├── [./web/styles/live.css](./web/styles/live.css)\n│ │ ├── [./web/styles/mesibolive.css](./web/styles/mesibolive.css)\n│ │ ├── [./web/styles/popup.css](./web/styles/popup.css)\n│ │ └── [./web/styles/popupdesign.css](./web/styles/popupdesign.css)\n│ └── [./web/vendor](./web/vendor)\n│ ├── [./web/vendor/bootstrap.min.css](./web/vendor/bootstrap.min.css)\n│ └── [./web/vendor/bootstrap.min.js](./web/vendor/bootstrap.min.js)&lt;br>\n└── [./zumzi-video-chat.png](./zumzi-video-chat.png)&lt;br></code></pre></div>\n<h2>Messenger</h2>\n<p>Edit <code class=\"language-text\">config.js</code> and provide the <code class=\"language-text\">AUTH TOKEN</code> &#x26; <code class=\"language-text\">APP ID</code>.</p>\n<p>You can obtain the <code class=\"language-text\">AUTH TOKEN</code> and <code class=\"language-text\">APP ID</code> for a user from <a href=\"https://mesibo.com/console/\">Mesibo Console</a>.</p>\n<p>Refer to the <a href=\"https://mesibo.com/documentation/tutorials/get-started\">Get-Started Guide</a> to learn about the basics of mesibo.</p>\n<p>To open messenger demo launch <code class=\"language-text\">messenger.html</code></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">MESIBO_ACCESS_TOKEN</span> <span class=\"token operator\">=</span> <span class=\"token string\">'xxxxxxx'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">MESIBO_APP_ID</span> <span class=\"token operator\">=</span> <span class=\"token string\">'xxxx'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">MESIBO_API_URL</span> <span class=\"token operator\">=</span> <span class=\"token string\">'https://app.mesibo.com/api.php'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If you are hosting mesibo-backend on your own server, you need to change the API URL to point to your server.</p>\n<h3>Messenger Login</h3>\n<p>You can synchronize contacts, by using a phone number to login to mesibo messenger-javascript.</p>\n<p>To login to the mesibo messenger web app, in the login screen provide the phone number along with country code starting with <code class=\"language-text\">+</code> For Example, If your country code is <code class=\"language-text\">91</code> and your ten-digit phone number is <code class=\"language-text\">XXXXXXXXXX</code>, enter your phone number as <code class=\"language-text\">+91XXXXXXXXXX</code> (with out any spaces or special characters in between)</p>\n<p>Use OTP 123456 to login. Mesibo will generate and store <code class=\"language-text\">MESIBO_ACCESS_TOKEN</code> if login is successful.</p>\n<p>Please note that you only need to login once as for later sessions your token will be stored in local storage.</p>\n<p>If you DO NOT wish to login with your phone number, make sure you configure a valid <code class=\"language-text\">MESIBO_ACCESS_TOKEN</code> in <code class=\"language-text\">config.js</code> and set <code class=\"language-text\">isLoginEnabled = false</code></p>\n<h3>Synchronizing contacts on Messenger</h3>\n<p>To synchronize contacts set <code class=\"language-text\">isContactSync = true</code></p>\n<p>For the best experience using the messenger app, make sure you have some contacts who are using Mesibo Messenger. These contacts will be displayed as a list of available users to whom you can send messages or make calls. Optionally, you can also manually provide a list of phone numbers of contacts who are using mesibo in <code class=\"language-text\">MESIBO_LOCAL_CONTACTS</code> or by clicking on the <code class=\"language-text\">Add Contact</code> button.</p>\n<p>You can provide a list of local contacts that will be loaded as a list of available users. Set local contacts as follows in <code class=\"language-text\">config.js</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var MESIBO_LOCAL_CONTACTS =[\n\n{\n        \"address\" : \"18885551001\",\n        \"groupid\" : 0,\n        \"picture\" : \"images/profile/default-profile-icon.jpg\",\n        \"name\"    : \"MesiboTest\",\n        \"status\": \"Let's Chat..\"\n},\n\n{\n        \"groupid\" : 104661,\n        \"picture\" : \"images/profile/default-group-icon.jpg\",\n        \"name\"    : \"Mesibo Group\",\n        \"members\" : \"1:123,456,789\"             //Members list. Add 1: to mark as admin\n},\n\n]</code></pre></div>\n<h2>Popup</h2>\n<p>To launch popup demo you can configure the following for setting the displayed user avatar and destination user(to which all messages will be sent) in <code class=\"language-text\">config.js</code> and launch <code class=\"language-text\">popup.html</code></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">POPUP_DISPLAY_NAME</span> <span class=\"token operator\">=</span> <span class=\"token string\">'xxxx'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">POPUP_DISPLAY_PICTURE</span> <span class=\"token operator\">=</span> <span class=\"token string\">'images/profile/default-profile-icon.jpg'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">POPUP_DESTINATION_USER</span> <span class=\"token operator\">=</span> <span class=\"token string\">'xxxx'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>FAQ &#x26; Troubleshooting</h2>\n<h3>Getting <code class=\"language-text\">AUTHFAIL</code> with getcontacts API</h3>\n<p>This means the token you have provided in <code class=\"language-text\">MESIBO_ACCESS_TOKEN</code> is not generated or validated with your phone number which is required for synchronizing contacts.</p>\n<p>To generate a token by validating your phone number, make sure you have set <code class=\"language-text\">isLoginEnabled = true</code>. A login screen will then appear during app start, where you can enter your phone number(Example +91XXXXXXXXXX), get an OTP, and log in.</p>\n<p>If you do not wish to synchronize contacts, set <code class=\"language-text\">isContactSync = false</code> and provide a list of local contacts in <code class=\"language-text\">MESIBO_LOCAL_CONTACTS</code>.</p>\n<h3>I do not wish to use phone login, what should I do?</h3>\n<p>Set <code class=\"language-text\">isLoginEnabled = false</code> and make sure that you provide a valid <code class=\"language-text\">MESIBO_ACCESS_TOKEN</code></p>\n<h3>I do not want to synchronize with my phone contacts, how do I configure that?</h3>\n<p>If you do not wish to synchronize contacts, set <code class=\"language-text\">isContactSync = false</code> and provide a list of local contacts in <code class=\"language-text\">MESIBO_LOCAL_CONTACTS</code>.</p>\n<h3>Do I need to log in with my phone number every time I load the app?</h3>\n<p>No the first time you log in with your phone number with a valid OTP the token will be stored in localStorage. In future loading of the app, the token will be loaded from local storage. Or if you have provided a valid <code class=\"language-text\">MESIBO_ACCESS_TOKEN</code> in <code class=\"language-text\">config.js</code> that will be loaded.</p>\n<h3>Getting $scope.mesibo.X is not a function</h3>\n<p>Ensure that you perform a hard reload so that you have the latest Mesibo Javascript API</p>\n<h2>Install Mesibo Javascript SDK</h2>\n<p>The easiest way to install Mesibo Javascript SDK is to include following in <code class=\"language-text\">&lt;HEAD></code> section of your HTML file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script type=\"text/javascript\" src=\"https://api.mesibo.com/mesibo.js\"></code></pre></div>\n</script>\n<p>You can also use <code class=\"language-text\">async</code> and <code class=\"language-text\">defer</code> attributes inside <code class=\"language-text\">script</code> tag if requires.</p>\n<p>Alternatively, you may also use DOM method to load the mesibo JS on demand when it is not possible to use the script tag.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const script = document.createElement(\"script\");\nscript.src = \"https://api.mesibo.com/mesibo.js\";\ndocument.body.appendChild(script);</code></pre></div>\n<blockquote>\n<p>You must use a secure website (https) to use mesibo javascript. It may NOT work from <code class=\"language-text\">http://</code> or <code class=\"language-text\">file://</code> sites due to browser security restrictions.</p>\n</blockquote>\n<h2>Notes when using it for Calls and Conferencing</h2>\n<p>Due to the browser security model, camera and microphone access require the following:</p>\n<ul>\n<li>You MUST use a secure URL (<code class=\"language-text\">https://</code>). The <code class=\"language-text\">http://</code> or <code class=\"language-text\">file://</code> URLs will NOT work.</li>\n<li>You MUST also use a valid certificate with recognized authority, the self-signed certificate will NOT work.</li>\n</ul>\n<p>The browser will not grant the camera and microphone permissions unless your app meets the above requirements. If permissions are not granted, calls and conferencing will not work.</p>\n<p>These restrictions are by the browsers and NOT by the mesibo. Refer Security section in the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#security\">Mozilla documentation</a> for more information.</p>\n<h3>That's All!</h3>\n<p>You can now begin developing features with mesibo.</p>\n<p><a href=\"https://mesibo.com/documentation/glossary/?term=javascript%20chat%20sdk\">javascript chat sdk</a>, <a href=\"https://mesibo.com/documentation/glossary/?term=messaging%20sdk%20for%20javascript\">messaging sdk for javascript</a>, <a href=\"https://mesibo.com/documentation/glossary/?term=javascript%20sdk%20for%20chat\">javascript sdk for chat</a>, <a href=\"https://mesibo.com/documentation/glossary/?term=install%20sdk%20through%20javascript\">install sdk through javascript</a></p>"},{"url":"/docs/faq/contact/","relativePath":"docs/faq/contact.md","relativeDir":"docs/faq","base":"contact.md","name":"contact","frontmatter":{"title":"Contact!","sections":[],"seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bgoonz-blog-v3-0.netlify.app/contact/\" height=\"900px\" width=\"100%\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://comments-3.bgoonz.repl.co/\" height=\"900px\" width=\"100%\">\n</iframe>\n<br>\n<h3>Calendar:</h3>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://calendar.google.com/calendar/embed?src=c_f16bvhnsdsp8epckcinsu4978g%40group.calendar.google.com&ctz=America%2FNew_York\" style=\"border: 0\" width=\"800\" height=\"600\" frameborder=\"0\" scrolling=\"no\">\n</iframe>\n<br>"},{"url":"/docs/fetch-api/fetch-api/","relativePath":"docs/fetch-api/fetch-api.md","relativeDir":"docs/fetch-api","base":"fetch-api.md","name":"fetch-api","frontmatter":{"title":"Fetch API","template":"docs","excerpt":"So far, we know quite a bit about fetch"},"html":"<h1>Fetch API</h1>\n<p>So far, we know quite a bit about <code class=\"language-text\">fetch</code>.</p>\n<p>Let's see the rest of API, to cover all its abilities.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Please note: most of these options are used rarely. You may skip this chapter and still use `fetch` well.\n\nStill, it's good to know what `fetch` can do, so if the need arises, you can return and read the details.</code></pre></div>\n<p>Here's the full list of all possible <code class=\"language-text\">fetch</code> options with their default values (alternatives in comments):</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> promise <span class=\"token operator\">=</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">method</span><span class=\"token operator\">:</span> <span class=\"token string\">\"GET\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// POST, PUT, DELETE, etc.</span>\n  <span class=\"token literal-property property\">headers</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// the content type header value is usually auto-set</span>\n    <span class=\"token comment\">// depending on the request body</span>\n    <span class=\"token string-property property\">\"Content-Type\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"text/plain;charset=UTF-8\"</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token keyword\">undefined</span> <span class=\"token comment\">// string, FormData, Blob, BufferSource, or URLSearchParams</span>\n  <span class=\"token literal-property property\">referrer</span><span class=\"token operator\">:</span> <span class=\"token string\">\"about:client\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// or \"\" to send no Referer header,</span>\n  <span class=\"token comment\">// or an url from the current origin</span>\n  <span class=\"token literal-property property\">referrerPolicy</span><span class=\"token operator\">:</span> <span class=\"token string\">\"no-referrer-when-downgrade\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// no-referrer, origin, same-origin...</span>\n  <span class=\"token literal-property property\">mode</span><span class=\"token operator\">:</span> <span class=\"token string\">\"cors\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// same-origin, no-cors</span>\n  <span class=\"token literal-property property\">credentials</span><span class=\"token operator\">:</span> <span class=\"token string\">\"same-origin\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// omit, include</span>\n  <span class=\"token literal-property property\">cache</span><span class=\"token operator\">:</span> <span class=\"token string\">\"default\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// no-store, reload, no-cache, force-cache, or only-if-cached</span>\n  <span class=\"token literal-property property\">redirect</span><span class=\"token operator\">:</span> <span class=\"token string\">\"follow\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// manual, error</span>\n  <span class=\"token literal-property property\">integrity</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// a hash, like \"sha256-abcdef1234567890\"</span>\n  <span class=\"token literal-property property\">keepalive</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// true</span>\n  <span class=\"token literal-property property\">signal</span><span class=\"token operator\">:</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// AbortController to abort request</span>\n  <span class=\"token literal-property property\">window</span><span class=\"token operator\">:</span> window <span class=\"token comment\">// null</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>An impressive list, right?</p>\n<p>We fully covered <code class=\"language-text\">method</code>, <code class=\"language-text\">headers</code> and <code class=\"language-text\">body</code> in the chapter &#x3C;info:fetch>.</p>\n<p>The <code class=\"language-text\">signal</code> option is covered in &#x3C;info:fetch-abort>.</p>\n<p>Now let's explore the remaining capabilities.</p>\n<h2>referrer, referrerPolicy</h2>\n<p>These options govern how <code class=\"language-text\">fetch</code> sets the HTTP <code class=\"language-text\">Referer</code> header.</p>\n<p>Usually that header is set automatically and contains the url of the page that made the request. In most scenarios, it's not important at all, sometimes, for security purposes, it makes sense to remove or shorten it.</p>\n<p><strong>The <code class=\"language-text\">referrer</code> option allows to set any <code class=\"language-text\">Referer</code> (within the current origin) or remove it.</strong></p>\n<p>To send no referer, set an empty string:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/page'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n<span class=\"token operator\">*</span><span class=\"token operator\">!</span><span class=\"token operator\">*</span>\n  <span class=\"token literal-property property\">referrer</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span> <span class=\"token comment\">// no Referer header</span>\n<span class=\"token operator\">*</span><span class=\"token operator\">/</span><span class=\"token operator\">!</span><span class=\"token operator\">*</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To set another url within the current origin:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/page'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// assuming we're on https://javascript.info</span>\n  <span class=\"token comment\">// we can set any Referer header, but only within the current origin</span>\n<span class=\"token operator\">*</span><span class=\"token operator\">!</span><span class=\"token operator\">*</span>\n  <span class=\"token literal-property property\">referrer</span><span class=\"token operator\">:</span> <span class=\"token string\">\"https://javascript.info/anotherpage\"</span>\n<span class=\"token operator\">*</span><span class=\"token operator\">/</span><span class=\"token operator\">!</span><span class=\"token operator\">*</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>The <code class=\"language-text\">referrerPolicy</code> option sets general rules for <code class=\"language-text\">Referer</code>.</strong></p>\n<p>Requests are split into 3 types:</p>\n<ol>\n<li>Request to the same origin.</li>\n<li>Request to another origin.</li>\n<li>Request from HTTPS to HTTP (from safe to unsafe protocol).</li>\n</ol>\n<p>Unlike the <code class=\"language-text\">referrer</code> option that allows to set the exact <code class=\"language-text\">Referer</code> value, <code class=\"language-text\">referrerPolicy</code> tells the browser general rules for each request type.</p>\n<p>Possible values are described in the <a href=\"https://w3c.github.io/webappsec-referrer-policy/\">Referrer Policy specification</a>:</p>\n<ul>\n<li><strong><code class=\"language-text\">\"no-referrer-when-downgrade\"</code></strong> -- the default value: full <code class=\"language-text\">Referer</code> is always sent, unless we send a request from HTTPS to HTTP (to the less secure protocol).</li>\n<li><strong><code class=\"language-text\">\"no-referrer\"</code></strong> -- never send <code class=\"language-text\">Referer</code>.</li>\n<li><strong><code class=\"language-text\">\"origin\"</code></strong> -- only send the origin in <code class=\"language-text\">Referer</code>, not the full page URL, e.g. only <code class=\"language-text\">http://site.com</code> instead of <code class=\"language-text\">http://site.com/path</code>.</li>\n<li><strong><code class=\"language-text\">\"origin-when-cross-origin\"</code></strong> -- send the full <code class=\"language-text\">Referer</code> to the same origin, but only the origin part for cross-origin requests (as above).</li>\n<li><strong><code class=\"language-text\">\"same-origin\"</code></strong> -- send the full <code class=\"language-text\">Referer</code> to the same origin, but no <code class=\"language-text\">Referer</code> for cross-origin requests.</li>\n<li><strong><code class=\"language-text\">\"strict-origin\"</code></strong> -- send only the origin, not the <code class=\"language-text\">Referer</code> for HTTPS→HTTP requests.</li>\n<li><strong><code class=\"language-text\">\"strict-origin-when-cross-origin\"</code></strong> -- for same-origin send the full <code class=\"language-text\">Referer</code>, for cross-origin send only the origin, unless it's HTTPS→HTTP request, then send nothing.</li>\n<li><strong><code class=\"language-text\">\"unsafe-url\"</code></strong> -- always send the full url in <code class=\"language-text\">Referer</code>, even for HTTPS→HTTP requests.</li>\n</ul>\n<p>Here's a table with all combinations:</p>\n<table>\n<thead>\n<tr>\n<th>Value</th>\n<th>To same origin</th>\n<th>To another origin</th>\n<th>HTTPS→HTTP</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">\"no-referrer\"</code></td>\n<td>-</td>\n<td>-</td>\n<td>-</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\"no-referrer-when-downgrade\"</code> or <code class=\"language-text\">\"\"</code> (default)</td>\n<td>full</td>\n<td>full</td>\n<td>-</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\"origin\"</code></td>\n<td>origin</td>\n<td>origin</td>\n<td>origin</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\"origin-when-cross-origin\"</code></td>\n<td>full</td>\n<td>origin</td>\n<td>origin</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\"same-origin\"</code></td>\n<td>full</td>\n<td>-</td>\n<td>-</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\"strict-origin\"</code></td>\n<td>origin</td>\n<td>origin</td>\n<td>-</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\"strict-origin-when-cross-origin\"</code></td>\n<td>full</td>\n<td>origin</td>\n<td>-</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\"unsafe-url\"</code></td>\n<td>full</td>\n<td>full</td>\n<td>full</td>\n</tr>\n</tbody>\n</table>\n<p>Let's say we have an admin zone with a URL structure that shouldn't be known from outside of the site.</p>\n<p>If we send a <code class=\"language-text\">fetch</code>, then by default it always sends the <code class=\"language-text\">Referer</code> header with the full url of our page (except when we request from HTTPS to HTTP, then no <code class=\"language-text\">Referer</code>).</p>\n<p>E.g. <code class=\"language-text\">Referer: https://javascript.info/admin/secret/paths</code>.</p>\n<p>If we'd like other websites know only the origin part, not the URL-path, we can set the option:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://another.com/page'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token literal-property property\">referrerPolicy</span><span class=\"token operator\">:</span> <span class=\"token string\">'origin-when-cross-origin'</span> <span class=\"token comment\">// Referer: https://javascript.info</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We can put it to all <code class=\"language-text\">fetch</code> calls, maybe integrate into JavaScript library of our project that does all requests and uses <code class=\"language-text\">fetch</code> inside.</p>\n<p>Its only difference compared to the default behavior is that for requests to another origin <code class=\"language-text\">fetch</code> sends only the origin part of the URL (e.g. <code class=\"language-text\">https://javascript.info</code>, without path). For requests to our origin we still get the full <code class=\"language-text\">Referer</code> (maybe useful for debugging purposes).</p>\n<p>`<code class=\"language-text\"></code>text header=\"Referrer policy is not only for <code class=\"language-text\">fetch</code>\" Referrer policy, described in the <a href=\"https://w3c.github.io/webappsec-referrer-policy/\">specification</a>, is not just for <code class=\"language-text\">fetch</code>, but more global.</p>\n<p>In particular, it's possible to set the default policy for the whole page using the <code class=\"language-text\">Referrer-Policy</code> HTTP header, or per-link, with <code class=\"language-text\">&lt;a rel=\"noreferrer\"></code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">## mode\n\nThe `mode` option is a safe-guard that prevents occasional cross-origin requests:\n\n- **`\"cors\"`** -- the default, cross-origin requests are allowed, as described in &lt;info:fetch-crossorigin>,\n- **`\"same-origin\"`** -- cross-origin requests are forbidden,\n- **`\"no-cors\"`** -- only safe cross-origin requests are allowed.\n\nThis option may be useful when the URL for `fetch` comes from a 3rd-party, and we want a \"power off switch\" to limit cross-origin capabilities.\n\n## credentials\n\nThe `credentials` option specifies whether `fetch` should send cookies and HTTP-Authorization headers with the request.\n\n- **`\"same-origin\"`** -- the default, don't send for cross-origin requests,\n- **`\"include\"`** -- always send, requires `Accept-Control-Allow-Credentials` from cross-origin server in order for JavaScript to access the response, that was covered in the chapter &lt;info:fetch-crossorigin>,\n- **`\"omit\"`** -- never send, even for same-origin requests.\n\n## cache\n\nBy default, `fetch` requests make use of standard HTTP-caching. That is, it respects the `Expires` and `Cache-Control` headers, sends `If-Modified-Since` and so on. Just like regular HTTP-requests do.\n\nThe `cache` options allows to ignore HTTP-cache or fine-tune its usage:\n\n- **`\"default\"`** -- `fetch` uses standard HTTP-cache rules and headers,\n- **`\"no-store\"`** -- totally ignore HTTP-cache, this mode becomes the default if we set a header `If-Modified-Since`, `If-None-Match`, `If-Unmodified-Since`, `If-Match`, or `If-Range`,\n- **`\"reload\"`** -- don't take the result from HTTP-cache (if any), but populate the cache with the response (if the response headers permit this action),\n- **`\"no-cache\"`** -- create a conditional request if there is a cached response, and a normal request otherwise. Populate HTTP-cache with the response,\n- **`\"force-cache\"`** -- use a response from HTTP-cache, even if it's stale. If there's no response in HTTP-cache, make a regular HTTP-request, behave normally,\n- **`\"only-if-cached\"`** -- use a response from HTTP-cache, even if it's stale. If there's no response in HTTP-cache, then error. Only works when `mode` is `\"same-origin\"`.\n\n## redirect\n\nNormally, `fetch` transparently follows HTTP-redirects, like 301, 302 etc.\n\nThe `redirect` option allows to change that:\n\n- **`\"follow\"`** -- the default, follow HTTP-redirects,\n- **`\"error\"`** -- error in case of HTTP-redirect,\n- **`\"manual\"`** -- allows to process HTTP-redirects manually. In case of redirect, we'll get a special response object, with `response.type=\"opaqueredirect\"` and zeroed/empty status and most other properies.\n\n## integrity\n\nThe `integrity` option allows to check if the response matches the known-ahead checksum.\n\nAs described in the [specification](https://w3c.github.io/webappsec-subresource-integrity/), supported hash-functions are SHA-256, SHA-384, and SHA-512, there might be others depending on the browser.\n\nFor example, we're downloading a file, and we know that it's SHA-256 checksum is \"abcdef\" (a real checksum is longer, of course).\n\nWe can put it in the `integrity` option, like this:\n\n```js\n//\nfetch('http://site.com/file', {\n  integrity: 'sha256-abcdef'\n});</code></pre></div>\n<p>Then <code class=\"language-text\">fetch</code> will calculate SHA-256 on its own and compare it with our string. In case of a mismatch, an error is triggered.</p>\n<h2>keepalive</h2>\n<p>The <code class=\"language-text\">keepalive</code> option indicates that the request may \"outlive\" the webpage that initiated it.</p>\n<p>For example, we gather statistics on how the current visitor uses our page (mouse clicks, page fragments he views), to analyze and improve the user experience.</p>\n<p>When the visitor leaves our page -- we'd like to save the data to our server.</p>\n<p>We can use the <code class=\"language-text\">window.onunload</code> event for that:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// run</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onunload</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/analytics'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">method</span><span class=\"token operator\">:</span> <span class=\"token string\">'POST'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token string\">\"statistics\"</span><span class=\"token punctuation\">,</span>\n<span class=\"token operator\">*</span><span class=\"token operator\">!</span><span class=\"token operator\">*</span>\n    <span class=\"token literal-property property\">keepalive</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n<span class=\"token operator\">*</span><span class=\"token operator\">/</span><span class=\"token operator\">!</span><span class=\"token operator\">*</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Normally, when a document is unloaded, all associated network requests are aborted. But the <code class=\"language-text\">keepalive</code> option tells the browser to perform the request in the background, even after it leaves the page. So this option is essential for our request to succeed.</p>\n<p>It has a few limitations:</p>\n<ul>\n<li>\n<p>We can't send megabytes: the body limit for <code class=\"language-text\">keepalive</code> requests is 64KB.</p>\n<ul>\n<li>If we need to gather a lot of statistics about the visit, we should send it out regularly in packets, so that there won't be a lot left for the last <code class=\"language-text\">onunload</code> request.</li>\n<li>This limit applies to all <code class=\"language-text\">keepalive</code> requests together. In other words, we can perform multiple <code class=\"language-text\">keepalive</code> requests in parallel, but the sum of their body lengths should not exceed 64KB.</li>\n</ul>\n</li>\n<li>\n<p>We can't handle the server response if the document is unloaded. So in our example <code class=\"language-text\">fetch</code> will succeed due to <code class=\"language-text\">keepalive</code>, but subsequent functions won't work.</p>\n<ul>\n<li>In most cases, such as sending out statistics, it's not a problem, as the server just accepts the data and usually sends an empty response to such requests.</li>\n</ul>\n</li>\n</ul>"},{"url":"/docs/faq/plug-ins/","relativePath":"docs/faq/plug-ins.md","relativeDir":"docs/faq","base":"plug-ins.md","name":"plug-ins","frontmatter":{"title":"Plug-ins","weight":0,"seo":{"title":"Gatsby Plugins For This Sites Content Model","description":"This is the Gatsby Plugins For This Sites Content Model page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Gatsby Plugins For This Sites Content Model","keyName":"property"},{"name":"og:description","value":"This is the Gatsby Plugins For This Sites Content Model page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Gatsby Plugins For This Sites Content Model"},{"name":"twitter:description","value":"This is the Gatsby Plugins For This Sites Content Model page"}]},"template":"docs"},"html":"<div class=\"note\">\n  <strong>Note:</strong> These are the gatsby plugins that power the file system of this website! <strong>See more in the Docs</strong> section.\n</div>\n<h3>Code:</h3>\n<blockquote>\n<p>Gatsby Source File System</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">js\nconst path = require('path');\nconst fs = require('fs');\nconst { createFilePath } = require('gatsby-source-filesystem');\nconst _ = require('lodash');\n\nfunction findFileNode({ node, getNode }) {\n    let fileNode = node;\n    let ids = [fileNode.id];\n\n    while (fileNode &amp;&amp; fileNode.internal.type !== `File` &amp;&amp; fileNode.parent) {\n        fileNode = getNode(fileNode.parent);\n\n        if (!fileNode) {\n            break;\n        }\n\n        if (_.includes(ids, fileNode.id)) {\n            console.log(`found cyclic reference between nodes`);\n            break;\n        }\n\n        ids.push(fileNode.id);\n    }\n\n    if (!fileNode || fileNode.internal.type !== `File`) {\n        console.log('did not find ancestor File node');\n        return null;\n    }\n\n    return fileNode;\n}\n\nexports.onCreateNode = ({ node, getNode, actions }, options) => {\n    const { createNodeField } = actions;\n\n    if (node.internal.type === 'MarkdownRemark') {\n        let fileNode = findFileNode({ node, getNode });\n        if (!fileNode) {\n            throw new Error('could not find parent File node for MarkdownRemark node: ' + node);\n        }\n\n        let url;\n        if (node.frontmatter.url) {\n            url = node.frontmatter.url;\n        } else if (_.get(options, 'uglyUrls', false)) {\n            url = path.join(fileNode.relativeDirectory, fileNode.name + '.html');\n        } else {\n            url = createFilePath({ node, getNode });\n        }\n\n        createNodeField({ node, name: 'url', value: url });\n        createNodeField({\n            node,\n            name: 'absolutePath',\n            value: fileNode.absolutePath\n        });\n        createNodeField({\n            node,\n            name: 'relativePath',\n            value: fileNode.relativePath\n        });\n        createNodeField({ node, name: 'absoluteDir', value: fileNode.dir });\n        createNodeField({\n            node,\n            name: 'relativeDir',\n            value: fileNode.relativeDirectory\n        });\n        createNodeField({ node, name: 'base', value: fileNode.base });\n        createNodeField({ node, name: 'ext', value: fileNode.ext });\n        createNodeField({ node, name: 'name', value: fileNode.name });\n    }\n};\n\nexports.createPages = ({ graphql, getNode, actions, getNodesByType }) => {\n    const { createPage, deletePage } = actions;\n\n    // Use GraphQL to bring only the \"id\" and \"html\" (added by gatsby-transformer-remark)\n    // properties of the MarkdownRemark nodes. Don't bring additional fields\n    // such as \"relativePath\". Otherwise, Gatsby's GraphQL resolvers might infer\n    // types these fields as File and change their structure. For example, the\n    // \"html\" attribute exists only on a GraphQL node, but does not exist on the\n    // underlying node.\n    return graphql(`\n        {\n            allMarkdownRemark {\n                edges {\n                    node {\n                        id\n                        html\n                    }\n                }\n            }\n        }\n    `).then((result) => {\n        if (result.errors) {\n            return Promise.reject(result.errors);\n        }\n\n        const nodes = result.data.allMarkdownRemark.edges.map(({ node }) => node);\n        const siteNode = getNode('Site');\n        const siteDataNode = getNode('SiteData');\n        const sitePageNodes = getNodesByType('SitePage');\n        const sitePageNodesByPath = _.keyBy(sitePageNodes, 'path');\n        const siteData = _.get(siteDataNode, 'data', {});\n\n        const pages = nodes.map((graphQLNode) => {\n            // Use the node id to get the underlying node. It is not exactly the\n            // same node returned by GraphQL, because GraphQL resolvers might\n            // transform node fields.\n            const node = getNode(graphQLNode.id);\n            return {\n                url: node.fields.url,\n                relativePath: node.fields.relativePath,\n                relativeDir: node.fields.relativeDir,\n                base: node.fields.base,\n                name: node.fields.name,\n                frontmatter: node.frontmatter,\n                html: graphQLNode.html\n            };\n        });\n\n        nodes.forEach((graphQLNode) => {\n            const node = getNode(graphQLNode.id);\n            const url = node.fields.url;\n\n            const template = node.frontmatter.template;\n            if (!template) {\n                console.error(`Error: undefined template for ${url}`);\n                return;\n            }\n\n            const component = path.resolve(`./src/templates/${template}.js`);\n            if (!fs.existsSync(component)) {\n                console.error(`Error: component \"src/templates/${template}.js\" missing for ${url}`);\n                return;\n            }\n\n            const existingPageNode = _.get(sitePageNodesByPath, url);\n\n            const page = {\n                path: url,\n                component: component,\n                context: {\n                    url: url,\n                    relativePath: node.fields.relativePath,\n                    relativeDir: node.fields.relativeDir,\n                    base: node.fields.base,\n                    name: node.fields.name,\n                    frontmatter: node.frontmatter,\n                    html: graphQLNode.html,\n                    pages: pages,\n                    site: {\n                        siteMetadata: _.get(siteData, 'site-metadata', {}),\n                        pathPrefix: siteNode.pathPrefix,\n                        data: _.omit(siteData, 'site-metadata')\n                    }\n                }\n            };\n\n            if (existingPageNode &amp;&amp; !_.get(page, 'context.menus')) {\n                page.context.menus = _.get(existingPageNode, 'context.menus');\n            }\n\n            createPage(page);\n        });\n    });\n};\n\n```\n&lt;/pre></code></pre></div>\n<h5>Gatsby Source Data</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;pre>\n```js\n//</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> path <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> yaml <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'js-yaml'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> fse <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs-extra'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> chokidar <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'chokidar'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> _ <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'lodash'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> metadataFileName <span class=\"token operator\">=</span> <span class=\"token string\">'site-metadata.json'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> parsers <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">yaml</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> yaml<span class=\"token punctuation\">.</span><span class=\"token function\">safeLoad</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">schema</span><span class=\"token operator\">:</span> yaml<span class=\"token punctuation\">.</span><span class=\"token constant\">JSON_SCHEMA</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">json</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> supportedExtensions <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">yaml</span><span class=\"token operator\">:</span> parsers<span class=\"token punctuation\">.</span>yaml<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">yml</span><span class=\"token operator\">:</span> parsers<span class=\"token punctuation\">.</span>yaml<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">json</span><span class=\"token operator\">:</span> parsers<span class=\"token punctuation\">.</span>json\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">sourceNodes</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">props<span class=\"token punctuation\">,</span> pluginOptions <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> createContentDigest <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>createContentDigest<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> createNode <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>actions<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> reporter <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>reporter<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>pluginOptions<span class=\"token punctuation\">,</span> <span class=\"token string\">'path'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        pluginOptions<span class=\"token punctuation\">.</span>path <span class=\"token operator\">=</span> <span class=\"token string\">'src/data'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>path<span class=\"token punctuation\">.</span><span class=\"token function\">isAbsolute</span><span class=\"token punctuation\">(</span>pluginOptions<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        pluginOptions<span class=\"token punctuation\">.</span>path <span class=\"token operator\">=</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span>process<span class=\"token punctuation\">.</span><span class=\"token function\">cwd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> pluginOptions<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    reporter<span class=\"token punctuation\">.</span><span class=\"token function\">info</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">[gatsby-source-data] setup file watcher and create site data</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> dataPath <span class=\"token operator\">=</span> pluginOptions<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> createSiteDataFromFilesPartial <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">partial</span><span class=\"token punctuation\">(</span>createSiteDataFromFiles<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n        dataPath<span class=\"token punctuation\">,</span>\n        createNode<span class=\"token punctuation\">,</span>\n        createContentDigest<span class=\"token punctuation\">,</span>\n        reporter\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> watcher <span class=\"token operator\">=</span> chokidar<span class=\"token punctuation\">.</span><span class=\"token function\">watch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>dataPath<span class=\"token punctuation\">,</span> metadataFileName<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">cwd</span><span class=\"token operator\">:</span> <span class=\"token string\">'.'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">ignoreInitial</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    watcher<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'add'</span><span class=\"token punctuation\">,</span> createSiteDataFromFilesPartial<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    watcher<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'change'</span><span class=\"token punctuation\">,</span> createSiteDataFromFilesPartial<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    watcher<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'unlink'</span><span class=\"token punctuation\">,</span> createSiteDataFromFilesPartial<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token function\">createSiteDataFromFiles</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> dataPath<span class=\"token punctuation\">,</span> createNode<span class=\"token punctuation\">,</span> createContentDigest<span class=\"token punctuation\">,</span> reporter <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">createSiteDataFromFiles</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> dataPath<span class=\"token punctuation\">,</span> createNode<span class=\"token punctuation\">,</span> createContentDigest<span class=\"token punctuation\">,</span> reporter <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> changedFile</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    reporter<span class=\"token punctuation\">.</span><span class=\"token function\">info</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">[gatsby-source-data] create site data from files, updated path: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>changedFile<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> dataFiles <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> dataPathExists <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> fse<span class=\"token punctuation\">.</span><span class=\"token function\">pathExists</span><span class=\"token punctuation\">(</span>dataPath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>dataPathExists<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        dataFiles <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">readDirRecursively</span><span class=\"token punctuation\">(</span>dataPath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> metadataPath <span class=\"token operator\">=</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span>metadataFileName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> metadataExists <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> fse<span class=\"token punctuation\">.</span><span class=\"token function\">pathExists</span><span class=\"token punctuation\">(</span>metadataPath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>metadataExists<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        dataFiles<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>metadataFileName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> sortedDataFiles <span class=\"token operator\">=</span> dataFiles<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">convertDataFilesToJSON</span><span class=\"token punctuation\">(</span>sortedDataFiles<span class=\"token punctuation\">,</span> dataPath<span class=\"token punctuation\">,</span> reporter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">createNode</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token string\">'SiteData'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">parent</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">data</span><span class=\"token operator\">:</span> data<span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">internal</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'SiteData'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">contentDigest</span><span class=\"token operator\">:</span> <span class=\"token function\">createContentDigest</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">description</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Site data from </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>path<span class=\"token punctuation\">.</span><span class=\"token function\">relative</span><span class=\"token punctuation\">(</span>process<span class=\"token punctuation\">.</span><span class=\"token function\">cwd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> dataPath<span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">readDirRecursively</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">dir<span class=\"token punctuation\">,</span> options</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> rootDir <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>options<span class=\"token punctuation\">,</span> <span class=\"token string\">'rootDir'</span><span class=\"token punctuation\">,</span> dir<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> files <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> fse<span class=\"token punctuation\">.</span><span class=\"token function\">readdir</span><span class=\"token punctuation\">(</span>dir<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> promises <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>files<span class=\"token punctuation\">,</span> <span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">file</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> filePath <span class=\"token operator\">=</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>dir<span class=\"token punctuation\">,</span> file<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> stats <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> fse<span class=\"token punctuation\">.</span><span class=\"token function\">stat</span><span class=\"token punctuation\">(</span>filePath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>stats<span class=\"token punctuation\">.</span><span class=\"token function\">isDirectory</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token function\">readDirRecursively</span><span class=\"token punctuation\">(</span>filePath<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> rootDir <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>stats<span class=\"token punctuation\">.</span><span class=\"token function\">isFile</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">relative</span><span class=\"token punctuation\">(</span>rootDir<span class=\"token punctuation\">,</span> filePath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> recFiles <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span>promises<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">chain</span><span class=\"token punctuation\">(</span>recFiles<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">compact</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">value</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">convertDataFilesToJSON</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">dataFiles<span class=\"token punctuation\">,</span> dataDirPath<span class=\"token punctuation\">,</span> reporter</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> promises <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>dataFiles<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">filePath</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> pathObject <span class=\"token operator\">=</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>filePath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> absFilePath <span class=\"token operator\">=</span> pathObject<span class=\"token punctuation\">.</span>base <span class=\"token operator\">===</span> metadataFileName <span class=\"token operator\">?</span> metadataFileName <span class=\"token operator\">:</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>dataDirPath<span class=\"token punctuation\">,</span> filePath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> relPath <span class=\"token operator\">=</span> pathObject<span class=\"token punctuation\">.</span>base <span class=\"token operator\">===</span> metadataFileName <span class=\"token operator\">?</span> metadataFileName <span class=\"token operator\">:</span> filePath<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> relDir <span class=\"token operator\">=</span> pathObject<span class=\"token punctuation\">.</span>base <span class=\"token operator\">===</span> metadataFileName <span class=\"token operator\">?</span> <span class=\"token string\">''</span> <span class=\"token operator\">:</span> pathObject<span class=\"token punctuation\">.</span>dir<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> ext <span class=\"token operator\">=</span> pathObject<span class=\"token punctuation\">.</span>ext<span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>supportedExtensions<span class=\"token punctuation\">,</span> ext<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> fse<span class=\"token punctuation\">.</span><span class=\"token function\">readFile</span><span class=\"token punctuation\">(</span>absFilePath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> propPath <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">compact</span><span class=\"token punctuation\">(</span>relDir<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">.</span>sep<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>pathObject<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> res <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">const</span> parsedData <span class=\"token operator\">=</span> supportedExtensions<span class=\"token punctuation\">[</span>ext<span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                _<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span>res<span class=\"token punctuation\">,</span> propPath<span class=\"token punctuation\">,</span> parsedData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                reporter<span class=\"token punctuation\">.</span><span class=\"token function\">warn</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">[gatsby-source-data] could not parse file: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>relPath<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">return</span> res<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span>promises<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">results</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span>results<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">data<span class=\"token punctuation\">,</span> res</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> _<span class=\"token punctuation\">.</span><span class=\"token function\">merge</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">,</span> res<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>pre<span class=\"token operator\">></span></code></pre></div>"},{"url":"/docs/git/git-tutorial/","relativePath":"docs/git/git-tutorial.md","relativeDir":"docs/git","base":"git-tutorial.md","name":"git-tutorial","frontmatter":{"title":"Github Tutorial","template":"docs","excerpt":"To use git we'll be using the terminal."},"html":"<!--StartFragment-->\n<h2>Step 1: Create a local git repository</h2>\n<p>When creating a new project on your local machine using git, you'll first create a new <a href=\"https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository\">repository</a> (or often, 'repo', for short).</p>\n<p>To use git we'll be using the terminal. If you don't have much experience with the terminal and basic commands, <a href=\"https://ubuntu.com/tutorials/command-line-for-beginners#1-overview\">check out this tutorial</a> (If you don’t want/ need a short history lesson, skip to step three.)</p>\n<p>To begin, open up a terminal and move to where you want to place the project on your local machine using the cd (change directory) command. For example, if you have a 'projects' folder on your desktop, you'd do something like:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/67a84eb876984f0b5785/raw/d4560016d742865c1fd68d97fcff1feb557d5e19/terminalcd.md\">view raw</a><a href=\"https://gist.github.com/cubeton/67a84eb876984f0b5785#file-terminalcd-md\">terminalcd.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>To initialize a git repository in the root of the folder, run the <a href=\"http://git-scm.com/docs/git-init\">git init</a> command:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/89793ba1bc947f64658e/raw/f3dba1dd72fda5eeb98b761338aedfc310d29d54/gitinit.md\">view raw</a><a href=\"https://gist.github.com/cubeton/89793ba1bc947f64658e#file-gitinit-md\">gitinit.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h2>Step 2: Add a new file to the repo</h2>\n<p>Go ahead and add a new file to the project, using any text editor you like or running a <a href=\"http://linux.die.net/man/1/touch\">touch</a> command. `touch newfile.txt` just creates and saves a blank file named newfile.txt.</p>\n<p>Once you've added or modified files in a folder containing a git repo, git will notice that  the file exists inside the repo. But, git won't track the file unless you explicitly tell it to. Git only saves/manages changes to files that it <em>tracks</em>, so we’ll need to send a command to confirm that yes, we want git to track our new file.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/2d8f224bede4c2dde86b/raw/b865e27cc4715b3a3a4a5839e77ab232ff1b31f9/addfile.md\">view raw</a><a href=\"https://gist.github.com/cubeton/2d8f224bede4c2dde86b#file-addfile-md\">addfile.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>After creating the new file, you can use the <a href=\"http://git-scm.com/docs/git-status\">git status</a> command to see which files git knows exist.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/02e849bbffcbea1e9a61/raw/71c93139666a8a4e06795f53c9aec5db95e6019a/gitstatus.md\">view raw</a><a href=\"https://gist.github.com/cubeton/02e849bbffcbea1e9a61#file-gitstatus-md\">gitstatus.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>What this basically says is, \"Hey, we noticed you created a new file called mnelson.txt, but unless you use the 'git add' command we aren't going to do anything with it.\"</p>\n<blockquote>\n<h4>An interlude: The staging environment, the commit, and you</h4>\n<p>One of the most confusing parts when you're first learning git is the concept of the staging environment and how it relates to a commit.</p>\n<p>A <a href=\"https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/github-glossary#:~:text=the%20repository%20owner.-,commit,who%20made%20them%20and%20when.\">commit</a> is a record of what changes you have made since the last time you made a commit. Essentially, you make changes to your repo (for example, adding a file or modifying one) and then tell git to put those changes into a commit.</p>\n<p>Commits make up the essence of your project and allow you to jump to the state of a project at any other commit.</p>\n<p>So, how do you tell git which files to put into a commit? This is where the <a href=\"https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository\">staging environment or index</a> come in. As seen in Step 2, when you make changes to your repo, git notices that a file has changed but won't do anything with it (like adding it in a commit).</p>\n<p>To add a file to a commit, you first need to add it to the staging environment. To do this, you can use the <a href=\"http://git-scm.com/docs/git-add\">git add</a> <filename> command (see Step 3 below).</p>\n<p>Once you've used the git add command to add all the files you want to the staging environment, you can then tell git to package them into a commit using the <a href=\"http://git-scm.com/docs/git-commit\">git commit</a> command.</p>\n<p>Note: The staging environment, also called 'staging', is the new preferred term for this, but you can also see it referred to as the 'index'.</p>\n</blockquote>\n<h2>Step 3: Add a file to the staging environment</h2>\n<p>Add a file to the staging environment using the git add command.</p>\n<p>If you rerun the git status command, you'll see that git has added the file to the staging environment (notice the \"Changes to be committed\" line).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/28f7bea3b232f67e031c/raw/875157cd78d75c23f3f0e29bf0c97989e3d52937/addtostaging.md\">view raw</a><a href=\"https://gist.github.com/cubeton/28f7bea3b232f67e031c#file-addtostaging-md\">addtostaging.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>To reiterate, the file has <strong>not</strong> yet been added to a commit, but it's about to be.</p>\n<h2>Step 4: Create a commit</h2>\n<p>It's time to create your first commit!</p>\n<p>Run the command <code class=\"language-text\">git commit -m \"Your message about the commit\"</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/1068d965d147b4039e4d/raw/5c3262c3f6e3c28328ba57ea33c512dbab149fcf/commit.md\">view raw</a><a href=\"https://gist.github.com/cubeton/1068d965d147b4039e4d#file-commit-md\">commit.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>The message at the end of the commit should be something related to what the commit contains - maybe it's a new feature, maybe it's a bug fix, maybe it's just fixing a typo. Don't put a message like \"asdfadsf\" or \"foobar\". That makes the other people who see your commit sad. Very, very, sad. Commits live forever in a repository (technically you <em>can</em> delete them if you really, really need to but it’s messy), so if you leave a clear explanation of your changes it can be extremely helpful for future programmers (perhaps future you!) who are trying to figure out why some change was made years later.</p>\n<h2>Step 5: Create a new branch</h2>\n<p>Now that you've made a new commit, let's try something a little more advanced.</p>\n<p>Say you want to make a new feature but are worried about making changes to the main project while developing the feature. This is where <a href=\"https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell\">git branches</a> come in.</p>\n<p>Branches allow you to move back and forth between 'states' of a project. Official git docs describe branches this way: ‘A branch in Git is simply a lightweight movable pointer to one of these commits.’ For instance, if you want to add a new page to your website you can create a new branch just for that page without affecting the main part of the project. Once you're done with the page, you can <a href=\"https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging\">merge</a> your changes from your branch into the primary branch. When you create a new branch, Git keeps track of which commit your branch 'branched' off of, so it knows the history behind all the files.</p>\n<p>Let's say you are on the primary branch and want to create a new branch to develop your web page. Here's what you'll do: Run <a href=\"http://git-scm.com/docs/git-checkout\">git checkout -b <my branch name></a>. This command will automatically create a new branch and then 'check you out' on it, meaning git will move you to that branch, off of the primary branch.</p>\n<p>After running the above command, you can use the <a href=\"http://git-scm.com/docs/git-branch\">git branch</a> command to confirm that your branch was created:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/fa25a25f322a2cd5f405/raw/81033788d288adeffe260bd724ab2699b29e3e35/gitbranch.md\">view raw</a><a href=\"https://gist.github.com/cubeton/fa25a25f322a2cd5f405#file-gitbranch-md\">gitbranch.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>The branch name with the asterisk next to it indicates which branch you're on at that given time.</p>\n<blockquote>\n<h4>A note on branch names</h4>\n<p>By default, every git repository’s first branch is named `master` (and is typically used as the primary branch in the project). As part of the tech industry’s general anti-racism work, some groups have begun to use alternate names for the default branch (we are using “primary” in this tutorial, for example). In other documentation and discussions, you may see “master”, or other terms, used to refer to the primary branch. Regardless of the name, just keep in mind that nearly every repository has a primary branch that can be thought of as the official version of the repository. If it’s a website, then the primary branch is the version that users see. If it’s an application, then the primary branch is the version that users download. This isn’t <em>technically</em> necessary (git doesn’t treat any branches differently from other branches), but it’s how git is traditionally used in a project.</p>\n<p>If you are curious about the decision to use different default branch names, GitHub has an explanation of <em>their</em> change here: <a href=\"https://github.com/github/renaming\">https://github.com/github/renaming</a></p>\n<p>Now, if you switch back to the primary branch and make some more commits, your new branch won't see any of those changes until you <a href=\"http://git-scm.com/docs/git-merge\">merge</a> those changes onto your new branch.</p>\n</blockquote>\n<h2>Step 6: Create a new repository on GitHub</h2>\n<p>If you only want to keep track of your code locally, you don't need to use GitHub. But if you want to work with a team, you can use GitHub to collaboratively modify the project's code.</p>\n<p>To create a new repo on GitHub, log in and go to the GitHub home page. You can find the “New repository” option under the “+” sign next to your profile picture, in the top right corner of the navbar:</p>\n<p><img src=\"https://product.hubspot.com/hs-fs/hubfs/Git_1.png?width=600&#x26;name=Git_1.png\" alt=\"Git_1\"></p>\n<p>After clicking the button, GitHub will ask you to name your repo and provide a brief description:</p>\n<p><img src=\"https://product.hubspot.com/hs-fs/hubfs/Git_2.png?width=512&#x26;name=Git_2.png\" alt=\"Git_2\"></p>\n<p>When you're done filling out the information, press the 'Create repository' button to make your new repo.</p>\n<p>GitHub will ask if you want to create a new repo from scratch or if you want to add a repo you have created locally. In this case, since we've already created a new repo locally, we want to push that onto GitHub so follow the '....or push an existing repository from the command line' section:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/3a2616c44e35ca68a6b0/raw/41e5758cfdbd7db8a1659c1adaba9346680097f9/addgithub.md\">view raw</a><a href=\"https://gist.github.com/cubeton/3a2616c44e35ca68a6b0#file-addgithub-md\">addgithub.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>(You'll want to change the URL in the first command line to what GitHub lists in this section since your GitHub username and repo name are different.)</p>\n<h2>Step 7: Push a branch to GitHub</h2>\n<p>Now we'll push the commit in your branch to your new GitHub repo. This allows other people to see the changes you've made. If they're approved by the repository's owner, the changes can then be merged into the primary branch.</p>\n<p>To push changes onto a new branch on GitHub, you'll want to run <a href=\"http://git-scm.com/docs/git-push\">git push</a> origin yourbranchname. GitHub will automatically create the branch for you on the remote repository:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/bf8274609c344b6d0e70/raw/4764e740cac9a48eefad341d9e34ceb09f89b73f/addnewbranchgithub.md\">view raw</a><a href=\"https://gist.github.com/cubeton/bf8274609c344b6d0e70#file-addnewbranchgithub-md\">addnewbranchgithub.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>You might be wondering what that \"origin\" word means in the command above. What happens is that when you clone a remote repository to your local machine, git creates an alias for you. In nearly all cases this alias is called \"<a href=\"https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes\">origin</a>.\" It's essentially shorthand for the remote repository's URL. So, to push your changes to the remote repository, you could've used either the command: git push git@github.com:git/git.git yourbranchname or git push origin yourbranchname</p>\n<p>(If this is your first time using GitHub locally, it might prompt you to log in with your GitHub username and password.)</p>\n<p>If you refresh the GitHub page, you'll see note saying a branch with your name has just been pushed into the repository. You can also click the 'branches' link to see your branch listed there.</p>\n<p><a href=\"https://cloud.githubusercontent.com/assets/5241432/9189475/da30eb86-3fb6-11e5-934f-ca596a2cac69.png\"><img src=\"https://product.hubspot.com/hs-fs/hubfs/Git_3.png?width=869&#x26;name=Git_3.png\" alt=\"Git_3\"></a></p>\n<p>Now click the green button in the screenshot above. We're going to make a <strong>pull request</strong>!</p>\n<h2>Step 8: Create a pull request (PR)</h2>\n<p>A pull request (or PR) is a way to alert a repo's owners that you want to make some changes to their code. It allows them to review the code and make sure it looks good before putting your changes on the primary branch.</p>\n<p>This is what the PR page looks like before you've submitted it:</p>\n<p><a href=\"https://cloud.githubusercontent.com/assets/5241432/9189500/4688c07e-3fb7-11e5-99ed-d75b50ed9e48.png\"><img src=\"https://product.hubspot.com/hs-fs/hubfs/Git_4.png?width=600&#x26;name=Git_4.png\" alt=\"Git_4\"></a></p>\n<p>And this is what it looks like once you've submitted the PR request:</p>\n<p><a href=\"https://cloud.githubusercontent.com/assets/5241432/9189528/b39a7176-3fb7-11e5-87b1-7fed3e63b6bb.png\"><img src=\"https://product.hubspot.com/hs-fs/hubfs/Git_5.png?width=600&#x26;name=Git_5.png\" alt=\"Git_5\"></a></p>\n<p>You might see a big green button at the bottom that says 'Merge pull request'. Clicking this means you'll merge your changes into the primary branch..</p>\n<p>Sometimes you'll be a co-owner or the sole owner of a repo, in which case you may not need to create a PR to merge your changes. However, it's still a good idea to make one so you can keep a more complete history of your updates and to make sure you always create a new branch when making changes.</p>\n<h2>Step 9: Merge a PR</h2>\n<p>Go ahead and click the green 'Merge pull request' button. This will merge your changes into the primary branch.</p>\n<p><a href=\"https://cloud.githubusercontent.com/assets/5241432/9189587/76631d98-3fb8-11e5-9fdb-17e7dec1c2a4.png\"><img src=\"https://product.hubspot.com/hs-fs/hubfs/Git_6.png?width=600&#x26;name=Git_6.png\" alt=\"Git_6\"></a></p>\n<p>When you're done, I recommend deleting your branch (too many branches can become messy), so hit that grey 'Delete branch' button as well.</p>\n<p>You can double check that your commits were merged by clicking on the 'Commits' link on the first page of your new repo.</p>\n<p><img src=\"https://product.hubspot.com/hs-fs/hubfs/Git_7.png?width=600&#x26;name=Git_7.png\" alt=\"Git_7\"></p>\n<p>This will show you a list of all the commits in that branch. You can see the one I just merged right up top (Merge pull request #1).</p>\n<p><img src=\"https://product.hubspot.com/hs-fs/hubfs/Git_8.png?width=600&#x26;name=Git_8.png\" alt=\"Git_8\"></p>\n<p>You can also see the <a href=\"https://git-scm.com/docs/git-hash-object\">hash code</a> of the commit on the right hand side. A hash code is a unique identifier for that specific commit. It's useful for referring to specific commits and when undoing changes (use the <a href=\"http://git-scm.com/docs/git-revert\">git revert </a><hash code number> command to backtrack).</p>\n<h2>Step 10: Get changes on GitHub back to your computer</h2>\n<p>Right now, the repo on GitHub looks a little different than what you have on your local machine. For example, the commit you made in your branch and merged into the primary branch doesn't exist in the primary branch on your local machine.</p>\n<p>In order to get the most recent changes that you or others have merged on GitHub, use the git pull origin master command (when working on the primary branch). In most cases, this can be shortened to “git pull”.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/48b5c726b496d50c3975/raw/fe2c68e0988c467fd218587e2397552076355b52/pulloriginmaster.md\">view raw</a><a href=\"https://gist.github.com/cubeton/48b5c726b496d50c3975#file-pulloriginmaster-md\">pulloriginmaster.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p>This shows you all the files that have changed and how they've changed.</p>\n<p>Now we can use the <a href=\"http://git-scm.com/docs/git-log\">git log</a> command again to see all new commits.</p>\n<p>(You may need to switch branches back to the primary branch. You can do that using the git checkout master command.)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><a href=\"https://gist.github.com/cubeton/48f55c5a237cd8e1a238/raw/3e31113a073b9bdec16800407d718b631dd0f587/gitlogaftermerge.md\">view raw</a><a href=\"https://gist.github.com/cubeton/48f55c5a237cd8e1a238#file-gitlogaftermerge-md\">gitlogaftermerge.md </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<!--EndFragment-->"},{"url":"/docs/javascript/arrow-functions/","relativePath":"docs/javascript/arrow-functions.md","relativeDir":"docs/javascript","base":"arrow-functions.md","name":"arrow-functions","frontmatter":{"title":"JS Fat Arrow Functions","weight":0,"excerpt":"JS Fat Arrow Functions","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>JS Fat Arrow Functions</h2>\n<p>Classical JavaScript function syntax doesn't provide for any flexibility, be that a 1 statement function or an unfortunate multi-page function. Every time you need a function you have to type out the dreaded <code class=\"language-text\">function () {}</code>. More concise function syntax was one of the many reasons why <a href=\"http://coffeescript.org/\">CoffeeScript</a> gained so much momentum back in the day. This is especially pronounced in the case of tiny callback functions. Lets look at a Promise chain:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function getVerifiedToken(selector) {\n  return getUsers(selector)\n    .then(function (users) { return users[0]; })\n    .then(verifyUser)\n    .then(function (user, verifiedToken) { return verifiedToken; })\n    .catch(function (err) { log(err.stack); });\n}</code></pre></div>\n<p>Above is more or less plausible piece of code written using classical JavaScript <code class=\"language-text\">function</code> syntax. Here is what the same code could look like rewritten using the arrow syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function getVerifiedToken(selector) {\n  return getUsers(selector)\n    .then(users => users[0])\n    .then(verifyUser)\n    .then((user, verifiedToken) => verifiedToken)\n    .catch(err => log(err.stack));\n}</code></pre></div>\n<p>A few important things to notice here:</p>\n<ol>\n<li>We've lost <code class=\"language-text\">function</code> and <code class=\"language-text\">{}</code> because all of our callback functions are one liners.</li>\n<li>We've lost <code class=\"language-text\">()</code> around the argument list when there's just one argument (rest arguments are an exception, eg <code class=\"language-text\">(...args) => ...</code>)</li>\n<li>We've lost the <code class=\"language-text\">return</code> keyword because when omitting <code class=\"language-text\">{}</code>, single line arrow functions perform an implicit return (these functions are often referred to as lambda functions in other languages).</li>\n</ol>\n<p>It's important to reinforce the last point. Implicit return only happens for single statement arrow functions. When arrow function is declared with <code class=\"language-text\">{}</code>, even if it's a single statement, implicit return does not happen:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const getVerifiedToken = selector => {\n  return getUsers()\n    .then(users => users[0])\n    .then(verifyUser)\n    .then((user, verifiedToken) => verifiedToken)\n    .catch(err => log(err.stack));\n}</code></pre></div>\n<p>Here's the really fun bit. Because our function has only one statement, we can still get rid of the <code class=\"language-text\">{}</code> and it will look almost exactly like <a href=\"http://coffeescript.org/\">CoffeeScript</a> syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const getVerifiedToken = selector =>\n  getUsers()\n    .then(users => users[0])\n    .then(verifyUser)\n    .then((user, verifiedToken) => verifiedToken)\n    .catch(err => log(err.stack));</code></pre></div>\n<p>Yep, the example above is completely valid ES2015 syntax (I was also surprised that it <a href=\"http://babeljs.io/repl/#?\">compiles fine</a>). When we talk about single statement arrow functions, it doesn't mean the statement can't be spread out to multiple lines for better comprehension.</p>\n<p>There's one caveat, however, with omitting <code class=\"language-text\">{}</code> from arrow functions -- how do you return an empty object, eg <code class=\"language-text\">{}</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const emptyObject = () => {};\nemptyObject(); // ?</code></pre></div>\n<p>Unfortunately there's no way to distinguish between empty block <code class=\"language-text\">{}</code> and an object <code class=\"language-text\">{}</code>. Because of that <code class=\"language-text\">emptyObject()</code> evaluates to <code class=\"language-text\">undefined</code> and <code class=\"language-text\">{}</code> interpreted as empty block. To return an empty object from fat arrow functions you have to surround it with brackets like so <code class=\"language-text\">({})</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const emptyObject = () => ({});\nemptyObject(); // {}</code></pre></div>\n<p>Here's all of the above together:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function () { return 1; }\n() => { return 1; }\n() => 1\n\nfunction (a) { return a * 2; }\n(a) => { return a * 2; }\n(a) => a * 2\na => a * 2\n\nfunction (a, b) { return a * b; }\n(a, b) => { return a * b; }\n(a, b) => a * b\n\nfunction () { return arguments[0]; }\n(...args) => args[0]\n\n() => {} // undefined\n() => ({}) // {}</code></pre></div>\n<h2>Lexical <code class=\"language-text\">this</code></h2>\n<p>The story of clobbering <code class=\"language-text\">this</code> in JavaScript is a really old one. Each <code class=\"language-text\">function</code> in JavaScript defines its own <code class=\"language-text\">this</code> context, which is as easy to get around as it is annoying. The example below tries to display a clock that updates every second using jQuery:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$('.current-time').each(function () {\n  setInterval(function () {\n    $(this).text(Date.now());\n  }, 1000);\n});</code></pre></div>\n<p>When attempting to reference the DOM element <code class=\"language-text\">this</code> set by <code class=\"language-text\">each</code> in the <code class=\"language-text\">setInterval</code> callback, we unfortunately get a brand new <code class=\"language-text\">this</code> that belongs to the callback itself. A common way around this is to declare <code class=\"language-text\">that</code> or <code class=\"language-text\">self</code> variable:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$('.current-time').each(function () {\n  var self = this;\n\n  setInterval(function () {\n    $(self).text(Date.now());\n  }, 1000);\n});</code></pre></div>\n<p>The fat arrow functions allow you to solve this problem because they don't introduce their own <code class=\"language-text\">this</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$('.current-time').each(function () {\n  setInterval(() => $(this).text(Date.now()), 1000);\n});</code></pre></div>\n<h2>What about arguments?</h2>\n<p>One of the caveats with arrow functions is that they also don't have their own <code class=\"language-text\">arguments</code> variable like regular functions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function log(msg) {\n  const print = () => console.log(arguments[0]);\n  print(`LOG: ${msg}`);\n}\n\nlog('hello'); // hello</code></pre></div>\n<p>To reiterate, fat arrow functions don't have their own <code class=\"language-text\">this</code> and <code class=\"language-text\">arguments</code>. Having said that, you can still get all arguments passed into the arrow functions using rest parameters (also known as spread operator):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function log(msg) {\n  const print = (...args) => console.log(args[0]);\n  print(`LOG: ${msg}`);\n}\n\nlog('hello'); // LOG: hello</code></pre></div>\n<h2>What about yield?</h2>\n<p>Fat arrow functions can't be used as generators. That's it -- no exceptions, no caveats and no workarounds.</p>\n<h2>Bottom Line</h2>\n<p>Fat arrow functions are one of my favorite additions to JavaScript. It might be very tempting to just start using <code class=\"language-text\">=></code> instead of <code class=\"language-text\">function</code> everywhere. I've seen whole libraries written just using <code class=\"language-text\">=></code> and I don't think it's the right thing to do because of the special features that <code class=\"language-text\">=></code> introduces. I recommend using arrow functions only in places where you explicitly want to use the new features:</p>\n<ul>\n<li>Single statement functions that immediately return (lambdas)</li>\n<li>Functions that need to work with parent scope <code class=\"language-text\">this</code></li>\n</ul>"},{"url":"/docs/faq/","relativePath":"docs/faq/index.md","relativeDir":"docs/faq","base":"index.md","name":"index","frontmatter":{"title":"FAQ","excerpt":"In this section you'll find commonly asked questions regarding the Libris theme. If you have questions, don't hesitate to ask us directly.","seo":{"title":"FAQ","description":"FAQ What's your favorite non-business book?\nHitchhiker's Guide To The Galaxy","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"FAQ","keyName":"property"},{"name":"og:description","value":"This is the faqpage","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"FAQ"},{"name":"twitter:description","value":"This is the faqpage"}]},"template":"docs","weight":900},"html":"<h4>What's the most useful business-related book you've ever read?</h4>\n<blockquote>\n<p>A Random Walk Down Wall Street</p>\n</blockquote>\n<h4>What's your favorite non-business book?</h4>\n<blockquote>\n<p>Hitchhiker's Guide To The Galaxy</p>\n</blockquote>\n<h4>If money were not an issue, what would you be doing right now?</h4>\n<blockquote>\n<p>Designing recording software/hardware and using it</p>\n</blockquote>\n<h4>What words of advice would you give your younger self?</h4>\n<blockquote>\n<p>Try harder and listen to your parents more (the latter bit of advice would be almost certain to fall on deaf ears lol)</p>\n</blockquote>\n<h4>What's the most creative thing you've ever done?</h4>\n<blockquote>\n<p>I built a platform that listens to a guitarist's performance and automatically triggers guitar effects at the appropriate time in the song.</p>\n</blockquote>\n<h4>Which founders or startups do you most admire?</h4>\n<blockquote>\n<p>Is it to basic to say Tesla... I know they're prevalent now but I've been an avid fan since as early as 2012.</p>\n</blockquote>\n<h4>What's your super power?</h4>\n<blockquote>\n<p>Having really good ideas and forgetting them moments later.</p>\n</blockquote>\n<h4>What's the best way for people to get in touch with you?</h4>\n<blockquote>\n<p>A text</p>\n</blockquote>\n<h4>What aspects of your work are you most passionate about?</h4>\n<p>Creating things that change my every day life.</p>\n<h4>What was the most impactful class you took in school?</h4>\n<blockquote>\n<p>Modern Physics... almost changed my major after that class... but at the end of the day engineering was a much more fiscally secure avenue.</p>\n</blockquote>\n<h4>What's something you wish you had done years earlier?</h4>\n<blockquote>\n<p>Learned to code ... and sing</p>\n</blockquote>\n<h4>What words of wisdom do you live by?</h4>\n<blockquote>\n<p>*Disclaimer: The following wisdom is very cliche ... but... \"Be the change that you wish to see in the world.\"</p>\n</blockquote>"},{"url":"/docs/javascript/asyncjs/","relativePath":"docs/javascript/asyncjs.md","relativeDir":"docs/javascript","base":"asyncjs.md","name":"asyncjs","frontmatter":{"title":"Asynchronous-JS","weight":0,"excerpt":"Let's start with the async keyword. It can be placed before a function","seo":{"title":"Asynchronous-JS","description":"The word \"async\" before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Async functions:</h1>\n<h2>Asynchronous JavaScript</h2>\n<p>Let's start with the <code class=\"language-text\">async</code> keyword. It can be placed before a function, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The word \"async\" before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically.</p>\n<p>For instance, this function returns a resolved promise with the result of <code class=\"language-text\">1</code>; let's test it:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>alert<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1</span></code></pre></div>\n<p>...We could explicitly return a promise, which would be the same:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>alert<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1</span></code></pre></div>\n<p>So, <code class=\"language-text\">async</code> ensures that the function returns a promise, and wraps non-promises in it. Simple enough, right? But not only that. There's another keyword, <code class=\"language-text\">await</code>, that works only inside <code class=\"language-text\">async</code> functions, and it's pretty cool.</p>\n<h2><a href=\"#await\">Await</a></h2>\n<p>The syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// works only inside async functions</span>\n<span class=\"token keyword\">let</span> value <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> promise<span class=\"token punctuation\">;</span></code></pre></div>\n<p>The keyword <code class=\"language-text\">await</code> makes JavaScript wait until that promise settles and returns its result.</p>\n<p>Here's an example with a promise that resolves in 1 second:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">'done!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> promise<span class=\"token punctuation\">;</span> <span class=\"token comment\">// wait until the promise resolves (*)</span>\n\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"done!\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The function execution \"pauses\" at the line <code class=\"language-text\">(*)</code> and resumes when the promise settles, with <code class=\"language-text\">result</code> becoming its result. So the code above shows \"done!\" in one second.</p>\n<p>Let's emphasize: <code class=\"language-text\">await</code> literally suspends the function execution until the promise settles, and then resumes it with the promise result. That doesn't cost any CPU resources, because the JavaScript engine can do other jobs in the meantime: execute other scripts, handle events, etc.</p>\n<p>It's just a more elegant syntax of getting the promise result than <code class=\"language-text\">promise.then</code>. And, it's easier to read and write.</p>\n<p>Can't use <code class=\"language-text\">await</code> in regular functions</p>\n<p>If we try to use <code class=\"language-text\">await</code> in a non-async function, there would be a syntax error:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> promise <span class=\"token operator\">=</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> promise<span class=\"token punctuation\">;</span> <span class=\"token comment\">// Syntax error</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We may get this error if we forget to put <code class=\"language-text\">async</code> before a function. As stated earlier, <code class=\"language-text\">await</code> only works inside an <code class=\"language-text\">async</code> function.</p>\n<p>Let's take the <code class=\"language-text\">showAvatar()</code> example from the chapter <a href=\"promise-chaining\">Promises chaining</a> and rewrite it using <code class=\"language-text\">async/await</code>:</p>\n<ol>\n<li>We'll need to replace <code class=\"language-text\">.then</code> calls with <code class=\"language-text\">await</code>.</li>\n<li>Also we should make the function <code class=\"language-text\">async</code> for them to work.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">showAvatar</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// read our JSON</span>\n    <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/article/promise-chaining/user.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// read github user</span>\n    <span class=\"token keyword\">let</span> githubResponse <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">https://api.github.com/users/</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>user<span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> githubUser <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> githubResponse<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// show the avatar</span>\n    <span class=\"token keyword\">let</span> img <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'img'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    img<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> githubUser<span class=\"token punctuation\">.</span>avatar_url<span class=\"token punctuation\">;</span>\n    img<span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> <span class=\"token string\">'promise-avatar-example'</span><span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">append</span><span class=\"token punctuation\">(</span>img<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// wait 3 seconds</span>\n    <span class=\"token keyword\">await</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    img<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> githubUser<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">showAvatar</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Pretty clean and easy to read, right? Much better than before.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> won't work in the top-level code\n\nPeople who are just starting to use </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> tend to forget the fact that we can't use </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> in top-level code. For example, this will not work:\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>js\n<span class=\"token comment\">//</span>\n<span class=\"token comment\">// syntax error in top-level code</span>\n<span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/article/promise-chaining/user.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>But we can wrap it into an anonymous async function, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/article/promise-chaining/user.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token operator\">...</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>P.S. New feature: starting from V8 engine version 8.9+, top-level await works in <a href=\"modules\">modules</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> accepts \"thenables\"\n\nLike </span><span class=\"token template-punctuation string\">`</span></span>promise<span class=\"token punctuation\">.</span>then<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">, </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> allows us to use thenable objects (those with a callable </span><span class=\"token template-punctuation string\">`</span></span>then<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> method). The idea is that a third-party object may not be a promise, but promise-compatible: if it supports </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">.</span>then<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">, that's enough to use it with </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">.\n\nHere's a demo </span><span class=\"token template-punctuation string\">`</span></span>Thenable<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> class; the </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> below accepts its instances:\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>js\n<span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Thenable</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">num</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>num <span class=\"token operator\">=</span> num<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// resolve with this.num*2 after 1000ms</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>num <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// (*)</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// waits for 1 second, then result becomes 2</span>\n  <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Thenable</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If <code class=\"language-text\">await</code> gets a non-promise object with <code class=\"language-text\">.then</code>, it calls that method providing the built-in functions <code class=\"language-text\">resolve</code> and <code class=\"language-text\">reject</code> as arguments (just as it does for a regular <code class=\"language-text\">Promise</code> executor). Then <code class=\"language-text\">await</code> waits until one of them is called (in the example above it happens in the line <code class=\"language-text\">(*)</code>) and then proceeds with the result.</p>\n<p>Async class methods</p>\n<p>To declare an async class method, just prepend it with <code class=\"language-text\">async</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Waiter</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">async</span> <span class=\"token function\">wait</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">Waiter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">wait</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>alert<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1 (this is the same as (result => alert(result)))</span></code></pre></div>\n<p>The meaning is the same: it ensures that the returned value is a promise and enables <code class=\"language-text\">await</code>.</p>\n<h2>[Error handling]</h2>\n<p>If a promise resolves normally, then <code class=\"language-text\">await promise</code> returns the result. But in the case of a rejection, it throws the error, just as if there were a <code class=\"language-text\">throw</code> statement at that line.</p>\n<p>This code:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">reject</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Whoops!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>...is the same as this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Whoops!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>In real situations, the promise may take some time before it rejects. In that case there will be a delay before <code class=\"language-text\">await</code> throws an error.</p>\n<p>We can catch that error using <code class=\"language-text\">try..catch</code>, the same way as a regular <code class=\"language-text\">throw</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'http://no-such-url'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// TypeError: failed to fetch</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In the case of an error, the control jumps to the <code class=\"language-text\">catch</code> block. We can also wrap multiple lines:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/no-user-here'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// catches errors both in fetch and response.json</span>\n        <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If we don't have <code class=\"language-text\">try..catch</code>, then the promise generated by the call of the async function <code class=\"language-text\">f()</code> becomes rejected. We can append <code class=\"language-text\">.catch</code> to handle it:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'http://no-such-url'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// f() becomes a rejected promise</span>\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span>alert<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// TypeError: failed to fetch // (*)</span></code></pre></div>\n<p>If we forget to add <code class=\"language-text\">.catch</code> there, then we get an unhandled promise error (viewable in the console). We can catch such errors using a global <code class=\"language-text\">unhandledrejection</code> event handler as described in the chapter <a href=\"promise-error-handling\">Error handling with promises</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nasync<span class=\"token operator\">/</span><span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> and </span><span class=\"token template-punctuation string\">`</span></span>promise<span class=\"token punctuation\">.</span>then<span class=\"token operator\">/</span>catch</code></pre></div>\n<p>When we use <code class=\"language-text\">async/await</code>, we rarely need <code class=\"language-text\">.then</code>, because <code class=\"language-text\">await</code> handles the waiting for us. And we can use a regular <code class=\"language-text\">try..catch</code> instead of <code class=\"language-text\">.catch</code>. That's usually (but not always) more convenient.</p>\n<p>But at the top level of the code, when we're outside any <code class=\"language-text\">async</code> function, we're syntactically unable to use <code class=\"language-text\">await</code>, so it's a normal practice to add <code class=\"language-text\">.then/catch</code> to handle the final result or falling-through error, like in the line <code class=\"language-text\">(*)</code> of the example above.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nasync<span class=\"token operator\">/</span><span class=\"token keyword\">await</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> works well with </span><span class=\"token template-punctuation string\">`</span></span>Promise<span class=\"token punctuation\">.</span>all</code></pre></div>\n<p>When we need to wait for multiple promises, we can wrap them in <code class=\"language-text\">Promise.all</code> and then <code class=\"language-text\">await</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// wait for the array of results</span>\n<span class=\"token keyword\">let</span> results <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>\n  <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n  <span class=\"token operator\">...</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In the case of an error, it propagates as usual, from the failed promise to <code class=\"language-text\">Promise.all</code>, and then becomes an exception that we can catch using <code class=\"language-text\">try..catch</code> around the call.</p>\n<h2><a href=\"#summary\">Summary</a></h2>\n<p>The <code class=\"language-text\">async</code> keyword before a function has two effects:</p>\n<ol>\n<li>Makes it always return a promise.</li>\n<li>Allows <code class=\"language-text\">await</code> to be used in it.</li>\n</ol>\n<p>The <code class=\"language-text\">await</code> keyword before a promise makes JavaScript wait until that promise settles, and then:</p>\n<ol>\n<li>If it's an error, the exception is generated --- same as if <code class=\"language-text\">throw error</code> were called at that very place.</li>\n<li>Otherwise, it returns the result.</li>\n</ol>\n<p>Together they provide a great framework to write asynchronous code that is easy to both read and write.</p>\n<p>With <code class=\"language-text\">async/await</code> we rarely need to write <code class=\"language-text\">promise.then/catch</code>, but we still shouldn't forget that they are based on promises, because sometimes (e.g. in the outermost scope) we have to use these methods. Also <code class=\"language-text\">Promise.all</code> is nice when we are waiting for many tasks simultaneously.</p>\n<h2>Cleaning up your asynchronous code with <code class=\"language-text\">await</code></h2>\n<p>REPLs have traditionally had a difficult time allowing you to interact with asynchronous code since they encourage a coding style where you evaluate expressions and use those results in the next field. But if you are using promises or callbacks, this breaks down because these results exist only in the callback, not the next line:</p>\n<p>In RunKit, you can use top-level <code class=\"language-text\">await</code> to get the same behavior of synchronous code.</p>\n<p>Now we can treat this code as synchronous, despite the fact that the code is still executing asynchronously.</p>\n<p>Let's look how. It helps to have a more complex example, where we need to do a few asynchronous operations in sequence. You can see how <code class=\"language-text\">await</code>, promises and callbacks achieve the same results, but the <code class=\"language-text\">await</code> style works better in a REPL:</p>\n<ul>\n<li>await</li>\n<li>promises</li>\n<li>callbacks</li>\n</ul>\n<p>Here, we use <code class=\"language-text\">await</code> on lines 4 and 8, and the results from each request remain in scope.</p>\n<p>Remember, <code class=\"language-text\">await</code> expects a <code class=\"language-text\">promise</code> so you can either write your own or use one of the many libraries that natively supports promises, and npm is full of packages that add promise support to existing libraries. Here are a few of our favorites:</p>\n<ul>\n<li><a href=\"https://npm.runkit.com/fs-promise\">fs-promise</a> - promise based filesystem api</li>\n<li><a href=\"https://npm.runkit.com/request-promise\">request-promise</a> - a wrapper around \"request\" for http stuff</li>\n<li><a href=\"https://npm.runkit.com/glob-promise\">glob-promise</a> - glob style filesystem queries</li>\n<li><a href=\"https://npm.runkit.com/bluebird\">bluebird</a> - general promise library with lots of utilities</li>\n</ul>\n<h3>Further Reading</h3>\n<ul>\n<li><a href=\"http://rossboucher.com/await\">ES7 Async/Await presented at Brookyln.js</a></li>\n<li><a href=\"https://babeljs.io/\">Babel.js</a></li>\n<li><a href=\"https://github.com/lukehoban/ecmascript-asyncawait/\">ECMAScript's Proposal for async/await</a></li>\n<li><a href=\"https://esdiscuss.org/notes/2014-01-30#async-await\">ES Meeting Notes discussing on async/await</a></li>\n<li><a href=\"https://esdiscuss.org/topic/does-async-await-solve-a-real-problem\">Does async/await Solve a Real Problem?</a></li>\n<li><a href=\"https://thomashunter.name/blog/the-long-road-to-asyncawait-in-javascript/\">The Long Road to async/await in JavaScript</a></li>\n<li><a href=\"https://www.twilio.com/blog/2015/10/asyncawait-the-hero-javascript-deserved.html\">async/await: The Hero JavaScript Deserved</a></li>\n</ul>"},{"url":"/docs/javascript/await-keyword/","relativePath":"docs/javascript/await-keyword.md","relativeDir":"docs/javascript","base":"await-keyword.md","name":"await-keyword","frontmatter":{"title":"Await ","weight":0,"excerpt":"Async and await","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>await</h1>\n<p>The <code class=\"language-text\">await</code> operator is used to wait for a <a href=\"../global_objects/promise\"><code class=\"language-text\">Promise</code></a>. It can only be used inside an <a href=\"../statements/async_function\"><code class=\"language-text\">async function</code></a> within regular JavaScript code; however it can be used on its own with <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\">JavaScript modules.</a></p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[rv] = await expression;</code></pre></div>\n<p><code class=\"language-text\">expression</code><br>\nA <a href=\"../global_objects/promise\"><code class=\"language-text\">Promise</code></a> or any value to wait for.</p>\n<p><code class=\"language-text\">rv</code><br>\nReturns the fulfilled value of the promise, or the value itself if it's not a <code class=\"language-text\">Promise</code>.</p>\n<h2>Description</h2>\n<p>The <code class=\"language-text\">await</code> expression causes <code class=\"language-text\">async</code> function execution to pause until a <code class=\"language-text\">Promise</code> is settled (that is, fulfilled or rejected), and to resume execution of the <code class=\"language-text\">async</code> function after fulfillment. When resumed, the value of the <code class=\"language-text\">await</code> expression is that of the fulfilled <code class=\"language-text\">Promise</code>.</p>\n<p>If the <code class=\"language-text\">Promise</code> is rejected, the <code class=\"language-text\">await</code> expression throws the rejected value.</p>\n<p>If the value of the <em>expression</em> following the <code class=\"language-text\">await</code> operator is not a <code class=\"language-text\">Promise</code>, it's converted to a <a href=\"../global_objects/promise/resolve\">resolved Promise</a>.</p>\n<p>An <code class=\"language-text\">await</code> splits execution flow, allowing the caller of the async function to resume execution. After the <code class=\"language-text\">await</code> defers the continuation of the async function, execution of subsequent statements ensues. If this <code class=\"language-text\">await</code> is the last expression executed by its function, execution continues by returning to the function's caller a pending <code class=\"language-text\">Promise</code> for completion of the <code class=\"language-text\">await</code>'s function and resuming execution of that caller.</p>\n<h2>Examples</h2>\n<h3>Awaiting a promise to be fulfilled</h3>\n<p>If a <code class=\"language-text\">Promise</code> is passed to an <code class=\"language-text\">await</code> expression, it waits for the <code class=\"language-text\">Promise</code> to be fulfilled and returns the fulfilled value.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function resolveAfter2Seconds(x) {\n  return new Promise(resolve => {\n    setTimeout(() => {\n      resolve(x);\n    }, 2000);\n  });\n}\n\nasync function f1() {\n  var x = await resolveAfter2Seconds(10);\n  console.log(x); // 10\n}\n\nf1();</code></pre></div>\n<h3>Thenable objects</h3>\n<p><a href=\"../global_objects/promise/then\"><code class=\"language-text\">Thenable objects</code></a> will be fulfilled just the same.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function f2() {\n  const thenable = {\n    then: function(resolve, _reject) {\n      resolve('resolved!')\n    }\n  };\n  console.log(await thenable); // resolved!\n}\n\nf2();</code></pre></div>\n<h3>Conversion to promise</h3>\n<p>If the value is not a <code class=\"language-text\">Promise</code>, it converts the value to a resolved <code class=\"language-text\">Promise</code>, and waits for it.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function f3() {\n  var y = await 20;\n  console.log(y); // 20\n}\n\nf3();</code></pre></div>\n<h3>Promise rejection</h3>\n<p>If the <code class=\"language-text\">Promise</code> is rejected, the rejected value is thrown.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function f4() {\n  try {\n    var z = await Promise.reject(30);\n  } catch(e) {\n    console.error(e); // 30\n  }\n}\n\nf4();</code></pre></div>\n<h3>Handling rejected promises</h3>\n<p>Handle rejected <code class=\"language-text\">Promise</code> without try block.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var response = await promisedFunction().catch((err) => { console.error(err); });\n// response will be undefined if the promise is rejected</code></pre></div>\n<h3>Top level await</h3>\n<p>You can use the <code class=\"language-text\">await</code> keyword on its own (outside of an async function) within a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\">JavaScript module</a>. This means modules, with child modules that use <code class=\"language-text\">await</code>, wait for the child module to execute before they themselves run. All while not blocking other child modules from loading.</p>\n<p>Here is an example of a simple module using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\">Fetch API</a> and specifying await within the <code class=\"language-text\">export statement</code>. Any modules that include this will wait for the fetch to resolve before running any code.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// fetch request\nconst colors = fetch('../data/colors.json')\n  .then(response => response.json());\n\nexport default await colors;</code></pre></div>"},{"url":"/docs/javascript/bigo/","relativePath":"docs/javascript/bigo.md","relativeDir":"docs/javascript","base":"bigo.md","name":"bigo","frontmatter":{"title":"A Very Quick Guide To Calculating Big O Computational Complexity","weight":0,"excerpt":"A quick guide to big O","seo":{"title":"big O","description":" A Very Quick Guide To Calculating Big O Computational Complexity","robots":[],"extra":[]},"template":"docs"},"html":"<h1>A Very Quick Guide To Calculating Big O Computational Complexity\n\n</h1>\n<p><strong>Big O</strong>: big picture, broad strokes, not details</p>\n<p><img src=\"https://miro.medium.com/max/630/0*lte81mEvgEPYXodB.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/304/1*5t2u8n1uKhioIzZIXX2zbg.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/563/1*HhXmG2cNdg8y4ZCCQGTyuQ.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*ULeXxVCDkF73GwhsxyM_2g.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/900/1*hkZWlUgFyOSaLD5Uskv0tQ.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1115/1*COjzunj0-FsMJ0d7v7Z-6g.png\" alt=\"medium blog image\"></p>\n<p>For a more complete guide… checkout :</p>\n<ul>\n<li>way we analyze how efficient algorithms are without getting too mired in details</li>\n<li></li>\n<li>can model how much time any function will take given n inputs</li>\n<li></li>\n<li>interested in order of magnitude of number of the exact figure</li>\n<li>O absorbs all fluff and n = biggest term</li>\n<li>Big O of 3x^2 +x + 1 = O(n^2)</li>\n</ul>\n<h1>Time Complexity</h1>\n<p>no loops or exit &#x26; return = O(1)</p>\n<p>0 nested loops = O(n)\n1 nested loops = O(n^2)\n2 nested loops = O(n^3)\n3 nested loops = O(n^4)</p>\n<p><strong>recursive</strong>: as you add more terms, increase in time as you add input diminishes\n<strong>recursion</strong>: when you define something in terms of itself, a function that calls itself</p>\n<ul>\n<li>used because of ability to maintain state at diffferent levels of recursion</li>\n<li></li>\n<li>inherently carries large footprint</li>\n<li>every time function called, you add call to stack</li>\n</ul>\n<p><strong>iterative</strong>: use loops instead of recursion (preferred)\n- favor readability over performance</p>\n<p>O(n log(n)) &#x26; O(log(n)): dividing/halving</p>\n<ul>\n<li>if code employs recursion/divide-and-conquer strategy</li>\n<li></li>\n<li>what power do i need to power my base to get n</li>\n</ul>\n<h1>Time Definitions</h1>\n<ul>\n<li><strong>constant</strong>: does not scale with input, will take same amount of time</li>\n<li></li>\n<li>for any input size n, constant time performs same number of operations every time</li>\n<li></li>\n<li>**logarit</li>\n<li></li>\n<li>function log n grows very slowly, so as n gets longer, number of operations the algorithm needs to perform</li>\n<li></li>\n<li>halving</li>\n<li></li>\n<li><strong>linear</strong>: increases number of operations it performs as linear function of input size n</li>\n<li></li>\n<li>number of additional operations needed to perform grows in direct proportion to increase in</li>\n<li></li>\n<li><strong>log-linear</strong>: increases number of operations it performs as log-linear function of input size n</li>\n<li>looking over every element and doing work on each one</li>\n<li><strong>quadratic</strong>: increases number of operations it performs as quadratic function of input size n</li>\n<li><strong>exponential</strong>: increases number of operations it performs as exponential function of input size n</li>\n<li>number of nested loops increases as function of n</li>\n<li><strong>polynomial</strong>: as size of input increases, runtime/space used will grow at a faster rate</li>\n<li><strong>factorial</strong>: as size of input increases, runtime/space used will grow astronomically even with relatively small inputs</li>\n<li><strong>rate of growth</strong>: how fast a function grows with input size</li>\n</ul>\n<h1>Space Complexity</h1>\n<ul>\n<li>How does the space usage scale/change as input gets very large?</li>\n<li></li>\n<li>What auxiliary space does your algorithm use or is it in place (constant)?</li>\n<li>Runtime stack space counts as part of space complexity unless told otherwise.</li>\n</ul>\n<h1>Data Structures &#x26; Algos In JS</h1>\n<hr>"},{"url":"/docs/javascript/clean-code/","relativePath":"docs/javascript/clean-code.md","relativeDir":"docs/javascript","base":"clean-code.md","name":"clean-code","frontmatter":{"title":"Clean Code","weight":0,"excerpt":"Clean Code","seo":{"title":"Clean Code","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>clean-code-javascript</h1>\n<h2>Table of Contents</h2>\n<ol>\n<li><a href=\"#introduction\">Introduction</a></li>\n<li><a href=\"#variables\">Variables</a></li>\n<li><a href=\"#functions\">Functions</a></li>\n<li><a href=\"#objects-and-data-structures\">Objects and Data Structures</a></li>\n<li><a href=\"#classes\">Classes</a></li>\n<li><a href=\"#solid\">SOLID</a></li>\n<li><a href=\"#testing\">Testing</a></li>\n<li><a href=\"#concurrency\">Concurrency</a></li>\n<li><a href=\"#error-handling\">Error Handling</a></li>\n<li><a href=\"#formatting\">Formatting</a></li>\n<li><a href=\"#comments\">Comments</a></li>\n<li><a href=\"#translation\">Translation</a></li>\n</ol>\n<h2>Introduction</h2>\n<p><img src=\"https://www.osnews.com/images/comics/wtfm.jpg\" alt=\"Humorous image of software quality estimation as a count of how many expletives\nyou shout when reading code\"></p>\n<p>Software engineering principles, from Robert C. Martin's book\n<a href=\"https://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882\"><em>Clean Code</em></a>,\nadapted for JavaScript. This is not a style guide. It's a guide to producing\n<a href=\"https://github.com/ryanmcdermott/3rs-of-software-architecture\">readable, reusable, and refactorable</a> software in JavaScript.</p>\n<p>Not every principle herein has to be strictly followed, and even fewer will be\nuniversally agreed upon. These are guidelines and nothing more, but they are\nones codified over many years of collective experience by the authors of\n<em>Clean Code</em>.</p>\n<p>Our craft of software engineering is just a bit over 50 years old, and we are\nstill learning a lot. When software architecture is as old as architecture\nitself, maybe then we will have harder rules to follow. For now, let these\nguidelines serve as a touchstone by which to assess the quality of the\nJavaScript code that you and your team produce.</p>\n<p>One more thing: knowing these won't immediately make you a better software\ndeveloper, and working with them for many years doesn't mean you won't make\nmistakes. Every piece of code starts as a first draft, like wet clay getting\nshaped into its final form. Finally, we chisel away the imperfections when\nwe review it with our peers. Don't beat yourself up for first drafts that need\nimprovement. Beat up the code instead!</p>\n<h2><strong>Variables</strong></h2>\n<h3>Use meaningful and pronounceable variable names</h3>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> yyyymmdstr <span class=\"token operator\">=</span> <span class=\"token function\">moment</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">format</span><span class=\"token punctuation\">(</span><span class=\"token string\">'YYYY/MM/DD'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> currentDate <span class=\"token operator\">=</span> <span class=\"token function\">moment</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">format</span><span class=\"token punctuation\">(</span><span class=\"token string\">'YYYY/MM/DD'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Use the same vocabulary for the same type of variable</h3>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getUserInfo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">getClientData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">getCustomerRecord</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getUser</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Use searchable names</h3>\n<p>We will read more code than we will ever write. It's important that the code we\ndo write is readable and searchable. By <em>not</em> naming variables that end up\nbeing meaningful for understanding our program, we hurt our readers.\nMake your names searchable. Tools like\n<a href=\"https://github.com/danielstjules/buddy.js\">buddy.js</a> and\n<a href=\"https://github.com/eslint/eslint/blob/660e0918933e6e7fede26bc675a0763a6b357c94/docs/rules/no-magic-numbers.md\">ESLint</a>\ncan help identify unnamed constants.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// What the heck is 86400000 for?</span>\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>blastOff<span class=\"token punctuation\">,</span> <span class=\"token number\">86400000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Declare them as capitalized named constants.</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">MILLISECONDS_PER_DAY</span> <span class=\"token operator\">=</span> <span class=\"token number\">60</span> <span class=\"token operator\">*</span> <span class=\"token number\">60</span> <span class=\"token operator\">*</span> <span class=\"token number\">24</span> <span class=\"token operator\">*</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//86400000;</span>\n\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>blastOff<span class=\"token punctuation\">,</span> <span class=\"token constant\">MILLISECONDS_PER_DAY</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Use explanatory variables</h3>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> address <span class=\"token operator\">=</span> <span class=\"token string\">'One Infinite Loop, Cupertino 95014'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> cityZipCodeRegex <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[^,\\\\]+[,\\\\\\s]+(.+?)\\s*(\\d{5})?$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">saveCityZipCode</span><span class=\"token punctuation\">(</span>address<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span>cityZipCodeRegex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> address<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span>cityZipCodeRegex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> address <span class=\"token operator\">=</span> <span class=\"token string\">'One Infinite Loop, Cupertino 95014'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> cityZipCodeRegex <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[^,\\\\]+[,\\\\\\s]+(.+?)\\s*(\\d{5})?$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>_<span class=\"token punctuation\">,</span> city<span class=\"token punctuation\">,</span> zipCode<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> address<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span>cityZipCodeRegex<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">saveCityZipCode</span><span class=\"token punctuation\">(</span>city<span class=\"token punctuation\">,</span> zipCode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Avoid Mental Mapping</h3>\n<p>Explicit is better than implicit.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> locations <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Austin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'New York'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'San Francisco'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nlocations<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">l</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">doStuff</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">doSomeOtherStuff</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token comment\">// Wait, what is `l` for again?</span>\n    <span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> locations <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Austin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'New York'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'San Francisco'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nlocations<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">location</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">doStuff</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">doSomeOtherStuff</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span>location<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Don't add unneeded context</h3>\n<p>If your class/object name tells you something, don't repeat that in your\nvariable name.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> Car <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">carMake</span><span class=\"token operator\">:</span> <span class=\"token string\">'Honda'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">carModel</span><span class=\"token operator\">:</span> <span class=\"token string\">'Accord'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">carColor</span><span class=\"token operator\">:</span> <span class=\"token string\">'Blue'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">paintCar</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">car<span class=\"token punctuation\">,</span> color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    car<span class=\"token punctuation\">.</span>carColor <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> Car <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">make</span><span class=\"token operator\">:</span> <span class=\"token string\">'Honda'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">model</span><span class=\"token operator\">:</span> <span class=\"token string\">'Accord'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'Blue'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">paintCar</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">car<span class=\"token punctuation\">,</span> color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    car<span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Use default arguments instead of short circuiting or conditionals</h3>\n<p>Default arguments are often cleaner than short circuiting. Be aware that if you\nuse them, your function will only provide default values for <code class=\"language-text\">undefined</code>\narguments. Other \"falsy\" values such as <code class=\"language-text\">''</code>, <code class=\"language-text\">\"\"</code>, <code class=\"language-text\">false</code>, <code class=\"language-text\">null</code>, <code class=\"language-text\">0</code>, and\n<code class=\"language-text\">NaN</code>, will not be replaced by a default value.</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createMicrobrewery</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> breweryName <span class=\"token operator\">=</span> name <span class=\"token operator\">||</span> <span class=\"token string\">'Hipster Brew Co.'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createMicrobrewery</span><span class=\"token punctuation\">(</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Hipster Brew Co.'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2><strong>Functions</strong></h2>\n<h3>Function arguments (2 or fewer ideally)</h3>\n<p>Limiting the amount of function parameters is incredibly important because it\nmakes testing your function easier. Having more than three leads to a\ncombinatorial explosion where you have to test tons of different cases with\neach separate argument.</p>\n<p>One or two arguments is the ideal case, and three should be avoided if possible.\nAnything more than that should be consolidated. Usually, if you have\nmore than two arguments then your function is trying to do too much. In cases\nwhere it's not, most of the time a higher-level object will suffice as an\nargument.</p>\n<p>Since JavaScript allows you to make objects on the fly, without a lot of class\nboilerplate, you can use an object if you are finding yourself needing a\nlot of arguments.</p>\n<p>To make it obvious what properties the function expects, you can use the ES2015/ES6\ndestructuring syntax. This has a few advantages:</p>\n<ol>\n<li>When someone looks at the function signature, it's immediately clear what\nproperties are being used.</li>\n<li>It can be used to simulate named parameters.</li>\n<li>Destructuring also clones the specified primitive values of the argument\nobject passed into the function. This can help prevent side effects. Note:\nobjects and arrays that are destructured from the argument object are NOT\ncloned.</li>\n<li>Linters can warn you about unused properties, which would be impossible\nwithout destructuring.</li>\n</ol>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createMenu</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> body<span class=\"token punctuation\">,</span> buttonText<span class=\"token punctuation\">,</span> cancellable</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">createMenu</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Foo'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Bar'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Baz'</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createMenu</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> title<span class=\"token punctuation\">,</span> body<span class=\"token punctuation\">,</span> buttonText<span class=\"token punctuation\">,</span> cancellable <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">createMenu</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">'Foo'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token string\">'Bar'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">buttonText</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baz'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">cancellable</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Functions should do one thing</h3>\n<p>This is by far the most important rule in software engineering. When functions\ndo more than one thing, they are harder to compose, test, and reason about.\nWhen you can isolate a function to just one action, it can be refactored\neasily and your code will read much cleaner. If you take nothing else away from\nthis guide other than this, you'll be ahead of many developers.</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">emailClients</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">clients</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    clients<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">client</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> clientRecord <span class=\"token operator\">=</span> database<span class=\"token punctuation\">.</span><span class=\"token function\">lookup</span><span class=\"token punctuation\">(</span>client<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>clientRecord<span class=\"token punctuation\">.</span><span class=\"token function\">isActive</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">email</span><span class=\"token punctuation\">(</span>client<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">emailActiveClients</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">clients</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    clients<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span>isActiveClient<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span>email<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">isActiveClient</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">client</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> clientRecord <span class=\"token operator\">=</span> database<span class=\"token punctuation\">.</span><span class=\"token function\">lookup</span><span class=\"token punctuation\">(</span>client<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> clientRecord<span class=\"token punctuation\">.</span><span class=\"token function\">isActive</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Function names should say what they do</h3>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">addToDate</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">date<span class=\"token punctuation\">,</span> month</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> date <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// It's hard to tell from the function name what is added</span>\n<span class=\"token function\">addToDate</span><span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">addMonthToDate</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">month<span class=\"token punctuation\">,</span> date</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> date <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">addMonthToDate</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Functions should only be one level of abstraction</h3>\n<p>When you have more than one level of abstraction your function is usually\ndoing too much. Splitting up functions leads to reusability and easier\ntesting.</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">parseBetterJSAlternative</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">code</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token constant\">REGEXES</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> statements <span class=\"token operator\">=</span> code<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> tokens <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token constant\">REGEXES</span><span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token constant\">REGEX</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        statements<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">statement</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// ...</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> ast <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    tokens<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">token</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// lex...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    ast<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// parse...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">parseBetterJSAlternative</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">code</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> tokens <span class=\"token operator\">=</span> <span class=\"token function\">tokenize</span><span class=\"token punctuation\">(</span>code<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> syntaxTree <span class=\"token operator\">=</span> <span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>tokens<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    syntaxTree<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// parse...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">tokenize</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">code</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token constant\">REGEXES</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> statements <span class=\"token operator\">=</span> code<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> tokens <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token constant\">REGEXES</span><span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token constant\">REGEX</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        statements<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">statement</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            tokens<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token comment\">/* ... */</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> tokens<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">parse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">tokens</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> syntaxTree <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    tokens<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">token</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        syntaxTree<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token comment\">/* ... */</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> syntaxTree<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Remove duplicate code</h3>\n<p>Do your absolute best to avoid duplicate code. Duplicate code is bad because it\nmeans that there's more than one place to alter something if you need to change\nsome logic.</p>\n<p>Imagine if you run a restaurant and you keep track of your inventory: all your\ntomatoes, onions, garlic, spices, etc. If you have multiple lists that\nyou keep this on, then all have to be updated when you serve a dish with\ntomatoes in them. If you only have one list, there's only one place to update!</p>\n<p>Oftentimes you have duplicate code because you have two or more slightly\ndifferent things, that share a lot in common, but their differences force you\nto have two or more separate functions that do much of the same things. Removing\nduplicate code means creating an abstraction that can handle this set of\ndifferent things with just one function/module/class.</p>\n<p>Getting the abstraction right is critical, that's why you should follow the\nSOLID principles laid out in the <em>Classes</em> section. Bad abstractions can be\nworse than duplicate code, so be careful! Having said this, if you can make\na good abstraction, do it! Don't repeat yourself, otherwise you'll find yourself\nupdating multiple places anytime you want to change one thing.</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">showDeveloperList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">developers</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    developers<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">developer</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> expectedSalary <span class=\"token operator\">=</span> developer<span class=\"token punctuation\">.</span><span class=\"token function\">calculateExpectedSalary</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> experience <span class=\"token operator\">=</span> developer<span class=\"token punctuation\">.</span><span class=\"token function\">getExperience</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> githubLink <span class=\"token operator\">=</span> developer<span class=\"token punctuation\">.</span><span class=\"token function\">getGithubLink</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            expectedSalary<span class=\"token punctuation\">,</span>\n            experience<span class=\"token punctuation\">,</span>\n            githubLink\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token function\">render</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">showManagerList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">managers</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    managers<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">manager</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> expectedSalary <span class=\"token operator\">=</span> manager<span class=\"token punctuation\">.</span><span class=\"token function\">calculateExpectedSalary</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> experience <span class=\"token operator\">=</span> manager<span class=\"token punctuation\">.</span><span class=\"token function\">getExperience</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> portfolio <span class=\"token operator\">=</span> manager<span class=\"token punctuation\">.</span><span class=\"token function\">getMBAProjects</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            expectedSalary<span class=\"token punctuation\">,</span>\n            experience<span class=\"token punctuation\">,</span>\n            portfolio\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token function\">render</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">showEmployeeList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">employees</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    employees<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">employee</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> expectedSalary <span class=\"token operator\">=</span> employee<span class=\"token punctuation\">.</span><span class=\"token function\">calculateExpectedSalary</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> experience <span class=\"token operator\">=</span> employee<span class=\"token punctuation\">.</span><span class=\"token function\">getExperience</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            expectedSalary<span class=\"token punctuation\">,</span>\n            experience\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>employee<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">case</span> <span class=\"token string\">'manager'</span><span class=\"token operator\">:</span>\n                data<span class=\"token punctuation\">.</span>portfolio <span class=\"token operator\">=</span> employee<span class=\"token punctuation\">.</span><span class=\"token function\">getMBAProjects</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">case</span> <span class=\"token string\">'developer'</span><span class=\"token operator\">:</span>\n                data<span class=\"token punctuation\">.</span>githubLink <span class=\"token operator\">=</span> employee<span class=\"token punctuation\">.</span><span class=\"token function\">getGithubLink</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token function\">render</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Set default objects with Object.assign</h3>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> menuConfig <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token string\">'Bar'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">buttonText</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">cancellable</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createMenu</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">config</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    config<span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> config<span class=\"token punctuation\">.</span>title <span class=\"token operator\">||</span> <span class=\"token string\">'Foo'</span><span class=\"token punctuation\">;</span>\n    config<span class=\"token punctuation\">.</span>body <span class=\"token operator\">=</span> config<span class=\"token punctuation\">.</span>body <span class=\"token operator\">||</span> <span class=\"token string\">'Bar'</span><span class=\"token punctuation\">;</span>\n    config<span class=\"token punctuation\">.</span>buttonText <span class=\"token operator\">=</span> config<span class=\"token punctuation\">.</span>buttonText <span class=\"token operator\">||</span> <span class=\"token string\">'Baz'</span><span class=\"token punctuation\">;</span>\n    config<span class=\"token punctuation\">.</span>cancellable <span class=\"token operator\">=</span> config<span class=\"token punctuation\">.</span>cancellable <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span> <span class=\"token operator\">?</span> config<span class=\"token punctuation\">.</span>cancellable <span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">createMenu</span><span class=\"token punctuation\">(</span>menuConfig<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> menuConfig <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">'Order'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token comment\">// User did not include 'body' key</span>\n    <span class=\"token literal-property property\">buttonText</span><span class=\"token operator\">:</span> <span class=\"token string\">'Send'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">cancellable</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createMenu</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">config</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> finalConfig <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">assign</span><span class=\"token punctuation\">(</span>\n        <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">'Foo'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token string\">'Bar'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">buttonText</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baz'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">cancellable</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        config\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> finalConfig<span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// config now equals: {title: \"Order\", body: \"Bar\", buttonText: \"Send\", cancellable: true}</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">createMenu</span><span class=\"token punctuation\">(</span>menuConfig<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Don't use flags as function parameters</h3>\n<p>Flags tell your user that this function does more than one thing. Functions should do one thing. Split out your functions if they are following different code paths based on a boolean.</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createFile</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name<span class=\"token punctuation\">,</span> temp</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>temp<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        fs<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">./temp/</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        fs<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createFile</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    fs<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createTempFile</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">createFile</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">./temp/</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Avoid Side Effects (part 1)</h3>\n<p>A function produces a side effect if it does anything other than take a value in\nand return another value or values. A side effect could be writing to a file,\nmodifying some global variable, or accidentally wiring all your money to a\nstranger.</p>\n<p>Now, you do need to have side effects in a program on occasion. Like the previous\nexample, you might need to write to a file. What you want to do is to\ncentralize where you are doing this. Don't have several functions and classes\nthat write to a particular file. Have one service that does it. One and only one.</p>\n<p>The main point is to avoid common pitfalls like sharing state between objects\nwithout any structure, using mutable data types that can be written to by anything,\nand not centralizing where your side effects occur. If you can do this, you will\nbe happier than the vast majority of other programmers.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Global variable referenced by following function.</span>\n<span class=\"token comment\">// If we had another function that used this name, now it'd be an array and it could break it.</span>\n<span class=\"token keyword\">let</span> name <span class=\"token operator\">=</span> <span class=\"token string\">'Ryan McDermott'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">splitIntoFirstAndLastName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">splitIntoFirstAndLastName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ['Ryan', 'McDermott'];</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">splitIntoFirstAndLastName</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> name<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> name <span class=\"token operator\">=</span> <span class=\"token string\">'Ryan McDermott'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> newName <span class=\"token operator\">=</span> <span class=\"token function\">splitIntoFirstAndLastName</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 'Ryan McDermott';</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ['Ryan', 'McDermott'];</span></code></pre></div>\n<h3>Avoid Side Effects (part 2)</h3>\n<p>In JavaScript, some values are unchangeable (immutable) and some are changeable\n(mutable). Objects and arrays are two kinds of mutable values so it's important\nto handle them carefully when they're passed as parameters to a function. A\nJavaScript function can change an object's properties or alter the contents of\nan array which could easily cause bugs elsewhere.</p>\n<p>Suppose there's a function that accepts an array parameter representing a\nshopping cart. If the function makes a change in that shopping cart array -\nby adding an item to purchase, for example - then any other function that\nuses that same <code class=\"language-text\">cart</code> array will be affected by this addition. That may be\ngreat, however it could also be bad. Let's imagine a bad situation:</p>\n<p>The user clicks the \"Purchase\" button which calls a <code class=\"language-text\">purchase</code> function that\nspawns a network request and sends the <code class=\"language-text\">cart</code> array to the server. Because\nof a bad network connection, the <code class=\"language-text\">purchase</code> function has to keep retrying the\nrequest. Now, what if in the meantime the user accidentally clicks an \"Add to Cart\"\nbutton on an item they don't actually want before the network request begins?\nIf that happens and the network request begins, then that purchase function\nwill send the accidentally added item because the <code class=\"language-text\">cart</code> array was modified.</p>\n<p>A great solution would be for the <code class=\"language-text\">addItemToCart</code> function to always clone the\n<code class=\"language-text\">cart</code>, edit it, and return the clone. This would ensure that functions that are still\nusing the old shopping cart wouldn't be affected by the changes.</p>\n<p>Two caveats to mention to this approach:</p>\n<ol>\n<li>There might be cases where you actually want to modify the input object,\nbut when you adopt this programming practice you will find that those cases\nare pretty rare. Most things can be refactored to have no side effects!</li>\n<li>Cloning big objects can be very expensive in terms of performance. Luckily,\nthis isn't a big issue in practice because there are\n<a href=\"https://facebook.github.io/immutable-js/\">great libraries</a> that allow\nthis kind of programming approach to be fast and not as memory intensive as\nit would be for you to manually clone objects and arrays.</li>\n</ol>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">addItemToCart</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">cart<span class=\"token punctuation\">,</span> item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    cart<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> item<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">addItemToCart</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">cart<span class=\"token punctuation\">,</span> item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>cart<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> item<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Don't write to global functions</h3>\n<p>Polluting globals is a bad practice in JavaScript because you could clash with another\nlibrary and the user of your API would be none-the-wiser until they get an\nexception in production. Let's think about an example: what if you wanted to\nextend JavaScript's native Array method to have a <code class=\"language-text\">diff</code> method that could\nshow the difference between two arrays? You could write your new function\nto the <code class=\"language-text\">Array.prototype</code>, but it could clash with another library that tried\nto do the same thing. What if that other library was just using <code class=\"language-text\">diff</code> to find\nthe difference between the first and last elements of an array? This is why it\nwould be much better to just use ES2015/ES6 classes and simply extend the <code class=\"language-text\">Array</code> global.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">diff</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token function\">diff</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">comparisonArray</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> hash <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>comparisonArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">elem</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">!</span>hash<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">SuperArray</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Array</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">diff</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">comparisonArray</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> hash <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>comparisonArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">elem</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">!</span>hash<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>elem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Favor functional programming over imperative programming</h3>\n<p>JavaScript isn't a functional language in the way that Haskell is, but it has\na functional flavor to it. Functional languages can be cleaner and easier to test.\nFavor this style of programming when you can.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> programmerOutput <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Uncle Bobby'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linesOfCode</span><span class=\"token operator\">:</span> <span class=\"token number\">500</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Suzie Q'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linesOfCode</span><span class=\"token operator\">:</span> <span class=\"token number\">1500</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jimmy Gosling'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linesOfCode</span><span class=\"token operator\">:</span> <span class=\"token number\">150</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Gracie Hopper'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linesOfCode</span><span class=\"token operator\">:</span> <span class=\"token number\">1000</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> totalOutput <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> programmerOutput<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    totalOutput <span class=\"token operator\">+=</span> programmerOutput<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>linesOfCode<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> programmerOutput <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Uncle Bobby'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linesOfCode</span><span class=\"token operator\">:</span> <span class=\"token number\">500</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Suzie Q'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linesOfCode</span><span class=\"token operator\">:</span> <span class=\"token number\">1500</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jimmy Gosling'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linesOfCode</span><span class=\"token operator\">:</span> <span class=\"token number\">150</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Gracie Hopper'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linesOfCode</span><span class=\"token operator\">:</span> <span class=\"token number\">1000</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> totalOutput <span class=\"token operator\">=</span> programmerOutput<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">totalLines<span class=\"token punctuation\">,</span> output</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> totalLines <span class=\"token operator\">+</span> output<span class=\"token punctuation\">.</span>linesOfCode<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Encapsulate conditionals</h3>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>fsm<span class=\"token punctuation\">.</span>state <span class=\"token operator\">===</span> <span class=\"token string\">'fetching'</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">isEmpty</span><span class=\"token punctuation\">(</span>listNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">shouldShowSpinner</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">fsm<span class=\"token punctuation\">,</span> listNode</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> fsm<span class=\"token punctuation\">.</span>state <span class=\"token operator\">===</span> <span class=\"token string\">'fetching'</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">isEmpty</span><span class=\"token punctuation\">(</span>listNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">shouldShowSpinner</span><span class=\"token punctuation\">(</span>fsmInstance<span class=\"token punctuation\">,</span> listNodeInstance<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Avoid negative conditionals</h3>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">isDOMNodeNotPresent</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">isDOMNodeNotPresent</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">isDOMNodePresent</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">isDOMNodePresent</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Avoid conditionals</h3>\n<p>This seems like an impossible task. Upon first hearing this, most people say,\n\"how am I supposed to do anything without an <code class=\"language-text\">if</code> statement?\" The answer is that\nyou can use polymorphism to achieve the same task in many cases. The second\nquestion is usually, \"well that's great but why would I want to do that?\" The\nanswer is a previous clean code concept we learned: a function should only do\none thing. When you have classes and functions that have <code class=\"language-text\">if</code> statements, you\nare telling your user that your function does more than one thing. Remember,\njust do one thing.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Airplane</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token function\">getCruisingAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">case</span> <span class=\"token string\">'777'</span><span class=\"token operator\">:</span>\n                <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getMaxAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getPassengerCount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">case</span> <span class=\"token string\">'Air Force One'</span><span class=\"token operator\">:</span>\n                <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getMaxAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">case</span> <span class=\"token string\">'Cessna'</span><span class=\"token operator\">:</span>\n                <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getMaxAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getFuelExpenditure</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Airplane</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Boeing777</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Airplane</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token function\">getCruisingAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getMaxAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getPassengerCount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">AirForceOne</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Airplane</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token function\">getCruisingAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getMaxAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Cessna</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Airplane</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n    <span class=\"token function\">getCruisingAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getMaxAltitude</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getFuelExpenditure</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Avoid type-checking (part 1)</h3>\n<p>JavaScript is untyped, which means your functions can take any type of argument.\nSometimes you are bitten by this freedom and it becomes tempting to do\ntype-checking in your functions. There are many ways to avoid having to do this.\nThe first thing to consider is consistent APIs.</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">travelToTexas</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vehicle</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>vehicle <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Bicycle</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        vehicle<span class=\"token punctuation\">.</span><span class=\"token function\">pedal</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>currentLocation<span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Location</span><span class=\"token punctuation\">(</span><span class=\"token string\">'texas'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>vehicle <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        vehicle<span class=\"token punctuation\">.</span><span class=\"token function\">drive</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>currentLocation<span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Location</span><span class=\"token punctuation\">(</span><span class=\"token string\">'texas'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">travelToTexas</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">vehicle</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    vehicle<span class=\"token punctuation\">.</span><span class=\"token function\">move</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>currentLocation<span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Location</span><span class=\"token punctuation\">(</span><span class=\"token string\">'texas'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Avoid type-checking (part 2)</h3>\n<p>If you are working with basic primitive values like strings and integers,\nand you can't use polymorphism but you still feel the need to type-check,\nyou should consider using TypeScript. It is an excellent alternative to normal\nJavaScript, as it provides you with static typing on top of standard JavaScript\nsyntax. The problem with manually type-checking normal JavaScript is that\ndoing it well requires so much extra verbiage that the faux \"type-safety\" you get\ndoesn't make up for the lost readability. Keep your JavaScript clean, write\ngood tests, and have good code reviews. Otherwise, do all of that but with\nTypeScript (which, like I said, is a great alternative!).</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">combine</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">val1<span class=\"token punctuation\">,</span> val2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> val1 <span class=\"token operator\">===</span> <span class=\"token string\">'number'</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> val2 <span class=\"token operator\">===</span> <span class=\"token string\">'number'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> val1 <span class=\"token operator\">===</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> val2 <span class=\"token operator\">===</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> val1 <span class=\"token operator\">+</span> val2<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Must be of type String or Number'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">combine</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">val1<span class=\"token punctuation\">,</span> val2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> val1 <span class=\"token operator\">+</span> val2<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Don't over-optimize</h3>\n<p>Modern browsers do a lot of optimization under-the-hood at runtime. A lot of\ntimes, if you are optimizing then you are just wasting your time. <a href=\"https://github.com/petkaantonov/bluebird/wiki/Optimization-killers\">There are good\nresources</a>\nfor seeing where optimization is lacking. Target those in the meantime, until\nthey are fixed if they can be.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// On old browsers, each iteration with uncached `list.length` would be costly</span>\n<span class=\"token comment\">// because of `list.length` recomputation. In modern browsers, this is optimized.</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> len <span class=\"token operator\">=</span> list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> list<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Remove dead code</h3>\n<p>Dead code is just as bad as duplicate code. There's no reason to keep it in\nyour codebase. If it's not being called, get rid of it! It will still be safe\nin your version history if you still need it.</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">oldRequestModule</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">newRequestModule</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> req <span class=\"token operator\">=</span> newRequestModule<span class=\"token punctuation\">;</span>\n<span class=\"token function\">inventoryTracker</span><span class=\"token punctuation\">(</span><span class=\"token string\">'apples'</span><span class=\"token punctuation\">,</span> req<span class=\"token punctuation\">,</span> <span class=\"token string\">'www.inventory-awesome.io'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">newRequestModule</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> req <span class=\"token operator\">=</span> newRequestModule<span class=\"token punctuation\">;</span>\n<span class=\"token function\">inventoryTracker</span><span class=\"token punctuation\">(</span><span class=\"token string\">'apples'</span><span class=\"token punctuation\">,</span> req<span class=\"token punctuation\">,</span> <span class=\"token string\">'www.inventory-awesome.io'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><strong>Objects and Data Structures</strong></h2>\n<h3>Use getters and setters</h3>\n<p>Using getters and setters to access data on objects could be better than simply\nlooking for a property on an object. \"Why?\" you might ask. Well, here's an\nunorganized list of reasons why:</p>\n<ul>\n<li>When you want to do more beyond getting an object property, you don't have</li>\n<li>to look up and change every accessor in your codeb</li>\n<li>Makes adding validation simple when doing</li>\n<li>Encapsulates the internal representation.</li>\n<li>Easy to add logging and error handling when getting and setting.</li>\n<li>You can lazy load your object's properties, let's say getting it from a\nserver.</li>\n</ul>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">makeBankAccount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">balance</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> account <span class=\"token operator\">=</span> <span class=\"token function\">makeBankAccount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\naccount<span class=\"token punctuation\">.</span>balance <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">makeBankAccount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// this one is private</span>\n    <span class=\"token keyword\">let</span> balance <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// a \"getter\", made public via the returned object below</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">getBalance</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> balance<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// a \"setter\", made public via the returned object below</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">setBalance</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">amount</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ... validate before updating the balance</span>\n        balance <span class=\"token operator\">=</span> amount<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n        getBalance<span class=\"token punctuation\">,</span>\n        setBalance\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> account <span class=\"token operator\">=</span> <span class=\"token function\">makeBankAccount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\naccount<span class=\"token punctuation\">.</span><span class=\"token function\">setBalance</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Make objects have private members</h3>\n<p>This can be accomplished through closures (for ES5 and below).</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Employee</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token class-name\">Employee</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getName</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token function\">getName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> employee <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Employee</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John Doe'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Employee name: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>employee<span class=\"token punctuation\">.</span><span class=\"token function\">getName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Employee name: John Doe</span>\n<span class=\"token keyword\">delete</span> employee<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Employee name: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>employee<span class=\"token punctuation\">.</span><span class=\"token function\">getName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Employee name: undefined</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">makeEmployee</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">getName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> name<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> employee <span class=\"token operator\">=</span> <span class=\"token function\">makeEmployee</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John Doe'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Employee name: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>employee<span class=\"token punctuation\">.</span><span class=\"token function\">getName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Employee name: John Doe</span>\n<span class=\"token keyword\">delete</span> employee<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Employee name: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>employee<span class=\"token punctuation\">.</span><span class=\"token function\">getName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Employee name: John Doe</span></code></pre></div>\n<h2><strong>Classes</strong></h2>\n<h3>Prefer ES2015/ES6 classes over ES5 plain functions</h3>\n<p>It's very difficult to get readable class inheritance, construction, and method\ndefinitions for classical ES5 classes. If you need inheritance (and be aware\nthat you might not), then prefer ES2015/ES6 classes. However, prefer small functions over\nclasses until you find yourself needing larger and more complex objects.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Animal</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">age</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Animal</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Instantiate Animal with `new`'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> age<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token class-name\">Animal</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">move</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token function\">move</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Mammal</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">age<span class=\"token punctuation\">,</span> furColor</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Mammal</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Instantiate Mammal with `new`'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">Animal</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>furColor <span class=\"token operator\">=</span> furColor<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token class-name\">Mammal</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Animal</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Mammal</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">=</span> Mammal<span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Mammal</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">liveBirth</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token function\">liveBirth</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Human</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">age<span class=\"token punctuation\">,</span> furColor<span class=\"token punctuation\">,</span> languageSpoken</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Human</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Instantiate Human with `new`'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">Mammal</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">,</span> furColor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>languageSpoken <span class=\"token operator\">=</span> languageSpoken<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Mammal</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">=</span> Human<span class=\"token punctuation\">;</span>\n<span class=\"token class-name\">Human</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">speak</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token function\">speak</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Animal</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">age</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> age<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">move</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">/* ... */</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Mammal</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Animal</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">age<span class=\"token punctuation\">,</span> furColor</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>furColor <span class=\"token operator\">=</span> furColor<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">liveBirth</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">/* ... */</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Human</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Mammal</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">age<span class=\"token punctuation\">,</span> furColor<span class=\"token punctuation\">,</span> languageSpoken</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>age<span class=\"token punctuation\">,</span> furColor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>languageSpoken <span class=\"token operator\">=</span> languageSpoken<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">speak</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">/* ... */</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Use method chaining</h3>\n<p>This pattern is very useful in JavaScript and you see it in many libraries such\nas jQuery and Lodash. It allows your code to be expressive, and less verbose.\nFor that reason, I say, use method chaining and take a look at how clean your code\nwill be. In your class functions, simply return <code class=\"language-text\">this</code> at the end of every function,\nand you can chain further class methods onto it.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Car</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">make<span class=\"token punctuation\">,</span> model<span class=\"token punctuation\">,</span> color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>make <span class=\"token operator\">=</span> make<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setMake</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">make</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>make <span class=\"token operator\">=</span> make<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setModel</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">model</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setColor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">save</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>make<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Ford'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'F-150'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ncar<span class=\"token punctuation\">.</span><span class=\"token function\">setColor</span><span class=\"token punctuation\">(</span><span class=\"token string\">'pink'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ncar<span class=\"token punctuation\">.</span><span class=\"token function\">save</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Car</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">make<span class=\"token punctuation\">,</span> model<span class=\"token punctuation\">,</span> color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>make <span class=\"token operator\">=</span> make<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setMake</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">make</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>make <span class=\"token operator\">=</span> make<span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// NOTE: Returning this for chaining</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setModel</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">model</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// NOTE: Returning this for chaining</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setColor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// NOTE: Returning this for chaining</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">save</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>make<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// NOTE: Returning this for chaining</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Ford'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'F-150'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">setColor</span><span class=\"token punctuation\">(</span><span class=\"token string\">'pink'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">save</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Prefer composition over inheritance</h3>\n<p>As stated famously in <a href=\"https://en.wikipedia.org/wiki/Design_Patterns\"><em>Design Patterns</em></a> by the Gang of Four,\nyou should prefer composition over inheritance where you can. There are lots of\ngood reasons to use inheritance and lots of good reasons to use composition.\nThe main point for this maxim is that if your mind instinctively goes for\ninheritance, try to think if composition could model your problem better. In some\ncases it can.</p>\n<p>You might be wondering then, \"when should I use inheritance?\" It\ndepends on your problem at hand, but this is a decent list of when inheritance\nmakes more sense than composition:</p>\n<ol>\n<li>Your inheritance represents an \"is-a\" relationship and not a \"has-a\"\nrelationship (Human->Animal vs. User->UserDetails).</li>\n<li>You can reuse code from the base classes (Humans can move like all animals).</li>\n<li>You want to make global changes to derived classes by changing a base class.\n(Change the caloric expenditure of all animals when they move).</li>\n</ol>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Employee</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name<span class=\"token punctuation\">,</span> email</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>email <span class=\"token operator\">=</span> email<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Bad because Employees \"have\" tax data. EmployeeTaxData is not a type of Employee</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">EmployeeTaxData</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Employee</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">ssn<span class=\"token punctuation\">,</span> salary</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>ssn <span class=\"token operator\">=</span> ssn<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>salary <span class=\"token operator\">=</span> salary<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">EmployeeTaxData</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">ssn<span class=\"token punctuation\">,</span> salary</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>ssn <span class=\"token operator\">=</span> ssn<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>salary <span class=\"token operator\">=</span> salary<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Employee</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name<span class=\"token punctuation\">,</span> email</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>email <span class=\"token operator\">=</span> email<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setTaxData</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">ssn<span class=\"token punctuation\">,</span> salary</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>taxData <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">EmployeeTaxData</span><span class=\"token punctuation\">(</span>ssn<span class=\"token punctuation\">,</span> salary<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2><strong>SOLID</strong></h2>\n<h3>Single Responsibility Principle (SRP)</h3>\n<p>As stated in Clean Code, \"There should never be more than one reason for a class\nto change\". It's tempting to jam-pack a class with a lot of functionality, like\nwhen you can only take one suitcase on your flight. The issue with this is\nthat your class won't be conceptually cohesive and it will give it many reasons\nto change. Minimizing the amount of times you need to change a class is important.\nIt's important because if too much functionality is in one class and you modify\na piece of it, it can be difficult to understand how that will affect other\ndependent modules in your codebase.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">UserSettings</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">user</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>user <span class=\"token operator\">=</span> user<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">changeSettings</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">settings</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">verifyCredentials</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// ...</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">verifyCredentials</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">UserAuth</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">user</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>user <span class=\"token operator\">=</span> user<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">verifyCredentials</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">UserSettings</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">user</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>user <span class=\"token operator\">=</span> user<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>auth <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">UserAuth</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">changeSettings</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">settings</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>auth<span class=\"token punctuation\">.</span><span class=\"token function\">verifyCredentials</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// ...</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Open/Closed Principle (OCP)</h3>\n<p>As stated by Bertrand Meyer, \"software entities (classes, modules, functions,\netc.) should be open for extension, but closed for modification.\" What does that\nmean though? This principle basically states that you should allow users to\nadd new functionalities without changing existing code.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">AjaxAdapter</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Adapter</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'ajaxAdapter'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">NodeAdapter</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Adapter</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'nodeAdapter'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">HttpRequester</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">adapter</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>adapter <span class=\"token operator\">=</span> adapter<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>adapter<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'ajaxAdapter'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token function\">makeAjaxCall</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                <span class=\"token comment\">// transform response and return</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>adapter<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'nodeAdapter'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token function\">makeHttpCall</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                <span class=\"token comment\">// transform response and return</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">makeAjaxCall</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// request and return promise</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">makeHttpCall</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// request and return promise</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">AjaxAdapter</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Adapter</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'ajaxAdapter'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">request</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// request and return promise</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">NodeAdapter</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Adapter</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'nodeAdapter'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">request</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// request and return promise</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">HttpRequester</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">adapter</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>adapter <span class=\"token operator\">=</span> adapter<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>adapter<span class=\"token punctuation\">.</span><span class=\"token function\">request</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// transform response and return</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Liskov Substitution Principle (LSP)</h3>\n<p>This is a scary term for a very simple concept. It's formally defined as \"If S\nis a subtype of T, then objects of type T may be replaced with objects of type S\n(i.e., objects of type S may substitute objects of type T) without altering any\nof the desirable properties of that program (correctness, task performed,\netc.).\" That's an even scarier definition.</p>\n<p>The best explanation for this is if you have a parent class and a child class,\nthen the base class and child class can be used interchangeably without getting\nincorrect results. This might still be confusing, so let's take a look at the\nclassic Square-Rectangle example. Mathematically, a square is a rectangle, but\nif you model it using the \"is-a\" relationship via inheritance, you quickly\nget into trouble.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Rectangle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>height <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setColor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">area</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setWidth</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">width</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> width<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setHeight</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">height</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>height <span class=\"token operator\">=</span> height<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getArea</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">*</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>height<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Square</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Rectangle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setWidth</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">width</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> width<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>height <span class=\"token operator\">=</span> width<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setHeight</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">height</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> height<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>height <span class=\"token operator\">=</span> height<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">renderLargeRectangles</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">rectangles</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    rectangles<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">rectangle</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        rectangle<span class=\"token punctuation\">.</span><span class=\"token function\">setWidth</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        rectangle<span class=\"token punctuation\">.</span><span class=\"token function\">setHeight</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> area <span class=\"token operator\">=</span> rectangle<span class=\"token punctuation\">.</span><span class=\"token function\">getArea</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// BAD: Returns 25 for Square. Should be 20.</span>\n        rectangle<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>area<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> rectangles <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Rectangle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Rectangle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Square</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">renderLargeRectangles</span><span class=\"token punctuation\">(</span>rectangles<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Shape</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setColor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">area</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Rectangle</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Shape</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">width<span class=\"token punctuation\">,</span> height</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> width<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>height <span class=\"token operator\">=</span> height<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getArea</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>width <span class=\"token operator\">*</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>height<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Square</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Shape</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">length</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getArea</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">renderLargeShapes</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">shapes</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    shapes<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">shape</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> area <span class=\"token operator\">=</span> shape<span class=\"token punctuation\">.</span><span class=\"token function\">getArea</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        shape<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>area<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> shapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Rectangle</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Rectangle</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Square</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">renderLargeShapes</span><span class=\"token punctuation\">(</span>shapes<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Interface Segregation Principle (ISP)</h3>\n<p>JavaScript doesn't have interfaces so this principle doesn't apply as strictly\nas others. However, it's important and relevant even with JavaScript's lack of\ntype system.</p>\n<p>ISP states that \"Clients should not be forced to depend upon interfaces that\nthey do not use.\" Interfaces are implicit contracts in JavaScript because of\nduck typing.</p>\n<p>A good example to look at that demonstrates this principle in JavaScript is for\nclasses that require large settings objects. Not requiring clients to setup\nhuge amounts of options is beneficial, because most of the time they won't need\nall of the settings. Making them optional helps prevent having a\n\"fat interface\".</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">DOMTraverser</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">settings</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>settings <span class=\"token operator\">=</span> settings<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>rootNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>settings<span class=\"token punctuation\">.</span>rootNode<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>settings<span class=\"token punctuation\">.</span>animationModule<span class=\"token punctuation\">.</span><span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> $ <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">DOMTraverser</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">rootNode</span><span class=\"token operator\">:</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByTagName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'body'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">animationModule</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token comment\">// Most of the time, we won't need to animate when traversing.</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">DOMTraverser</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">settings</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>settings <span class=\"token operator\">=</span> settings<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>options <span class=\"token operator\">=</span> settings<span class=\"token punctuation\">.</span>options<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>rootNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>settings<span class=\"token punctuation\">.</span>rootNode<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setupOptions</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">setupOptions</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>options<span class=\"token punctuation\">.</span>animationModule<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// ...</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> $ <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">DOMTraverser</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">rootNode</span><span class=\"token operator\">:</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByTagName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'body'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">options</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">animationModule</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Dependency Inversion Principle (DIP)</h3>\n<p>This principle states two essential things:</p>\n<ol>\n<li>High-level modules should not depend on low-level modules. Both should\ndepend on abstractions.</li>\n<li>Abstractions should not depend upon details. Details should depend on\nabstractions.</li>\n</ol>\n<p>This can be hard to understand at first, but if you've worked with AngularJS,\nyou've seen an implementation of this principle in the form of Dependency\nInjection (DI). While they are not identical concepts, DIP keeps high-level\nmodules from knowing the details of its low-level modules and setting them up.\nIt can accomplish this through DI. A huge benefit of this is that it reduces\nthe coupling between modules. Coupling is a very bad development pattern because\nit makes your code hard to refactor.</p>\n<p>As stated previously, JavaScript doesn't have interfaces so the abstractions\nthat are depended upon are implicit contracts. That is to say, the methods\nand properties that an object/class exposes to another object/class. In the\nexample below, the implicit contract is that any Request module for an\n<code class=\"language-text\">InventoryTracker</code> will have a <code class=\"language-text\">requestItems</code> method.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">InventoryRequester</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token constant\">REQ_METHODS</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'HTTP'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">requestItem</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">InventoryTracker</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">items</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items <span class=\"token operator\">=</span> items<span class=\"token punctuation\">;</span>\n\n        <span class=\"token comment\">// BAD: We have created a dependency on a specific request implementation.</span>\n        <span class=\"token comment\">// We should just have requestItems depend on a request method: `request`</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>requester <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">InventoryRequester</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">requestItems</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>requester<span class=\"token punctuation\">.</span><span class=\"token function\">requestItem</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> inventoryTracker <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">InventoryTracker</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'apples'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bananas'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ninventoryTracker<span class=\"token punctuation\">.</span><span class=\"token function\">requestItems</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">InventoryTracker</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">items<span class=\"token punctuation\">,</span> requester</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items <span class=\"token operator\">=</span> items<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>requester <span class=\"token operator\">=</span> requester<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">requestItems</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>requester<span class=\"token punctuation\">.</span><span class=\"token function\">requestItem</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">InventoryRequesterV1</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token constant\">REQ_METHODS</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'HTTP'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">requestItem</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">InventoryRequesterV2</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token constant\">REQ_METHODS</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'WS'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">requestItem</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// By constructing our dependencies externally and injecting them, we can easily</span>\n<span class=\"token comment\">// substitute our request module for a fancy new one that uses WebSockets.</span>\n<span class=\"token keyword\">const</span> inventoryTracker <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">InventoryTracker</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'apples'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bananas'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">InventoryRequesterV2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ninventoryTracker<span class=\"token punctuation\">.</span><span class=\"token function\">requestItems</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><strong>Testing</strong></h2>\n<p>Testing is more important than shipping. If you have no tests or an\ninadequate amount, then every time you ship code you won't be sure that you\ndidn't break anything. Deciding on what constitutes an adequate amount is up\nto your team, but having 100% coverage (all statements and branches) is how\nyou achieve very high confidence and developer peace of mind. This means that\nin addition to having a great testing framework, you also need to use a\n<a href=\"https://gotwarlost.github.io/istanbul/\">good coverage tool</a>.</p>\n<p>There's no excuse to not write tests. There are <a href=\"https://jstherightway.org/#testing-tools\">plenty of good JS test frameworks</a>, so find one that your team prefers.\nWhen you find one that works for your team, then aim to always write tests\nfor every new feature/module you introduce. If your preferred method is\nTest Driven Development (TDD), that is great, but the main point is to just\nmake sure you are reaching your coverage goals before launching any feature,\nor refactoring an existing one.</p>\n<h3>Single concept per test</h3>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> assert <span class=\"token keyword\">from</span> <span class=\"token string\">'assert'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">describe</span><span class=\"token punctuation\">(</span><span class=\"token string\">'MomentJS'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">it</span><span class=\"token punctuation\">(</span><span class=\"token string\">'handles date boundaries'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> date<span class=\"token punctuation\">;</span>\n\n        date <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">MomentJS</span><span class=\"token punctuation\">(</span><span class=\"token string\">'1/1/2015'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        date<span class=\"token punctuation\">.</span><span class=\"token function\">addDays</span><span class=\"token punctuation\">(</span><span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        assert<span class=\"token punctuation\">.</span><span class=\"token function\">equal</span><span class=\"token punctuation\">(</span><span class=\"token string\">'1/31/2015'</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        date <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">MomentJS</span><span class=\"token punctuation\">(</span><span class=\"token string\">'2/1/2016'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        date<span class=\"token punctuation\">.</span><span class=\"token function\">addDays</span><span class=\"token punctuation\">(</span><span class=\"token number\">28</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        assert<span class=\"token punctuation\">.</span><span class=\"token function\">equal</span><span class=\"token punctuation\">(</span><span class=\"token string\">'02/29/2016'</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        date <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">MomentJS</span><span class=\"token punctuation\">(</span><span class=\"token string\">'2/1/2015'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        date<span class=\"token punctuation\">.</span><span class=\"token function\">addDays</span><span class=\"token punctuation\">(</span><span class=\"token number\">28</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        assert<span class=\"token punctuation\">.</span><span class=\"token function\">equal</span><span class=\"token punctuation\">(</span><span class=\"token string\">'03/01/2015'</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> assert <span class=\"token keyword\">from</span> <span class=\"token string\">'assert'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">describe</span><span class=\"token punctuation\">(</span><span class=\"token string\">'MomentJS'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">it</span><span class=\"token punctuation\">(</span><span class=\"token string\">'handles 30-day months'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> date <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">MomentJS</span><span class=\"token punctuation\">(</span><span class=\"token string\">'1/1/2015'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        date<span class=\"token punctuation\">.</span><span class=\"token function\">addDays</span><span class=\"token punctuation\">(</span><span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        assert<span class=\"token punctuation\">.</span><span class=\"token function\">equal</span><span class=\"token punctuation\">(</span><span class=\"token string\">'1/31/2015'</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">it</span><span class=\"token punctuation\">(</span><span class=\"token string\">'handles leap year'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> date <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">MomentJS</span><span class=\"token punctuation\">(</span><span class=\"token string\">'2/1/2016'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        date<span class=\"token punctuation\">.</span><span class=\"token function\">addDays</span><span class=\"token punctuation\">(</span><span class=\"token number\">28</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        assert<span class=\"token punctuation\">.</span><span class=\"token function\">equal</span><span class=\"token punctuation\">(</span><span class=\"token string\">'02/29/2016'</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">it</span><span class=\"token punctuation\">(</span><span class=\"token string\">'handles non-leap year'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> date <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">MomentJS</span><span class=\"token punctuation\">(</span><span class=\"token string\">'2/1/2015'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        date<span class=\"token punctuation\">.</span><span class=\"token function\">addDays</span><span class=\"token punctuation\">(</span><span class=\"token number\">28</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        assert<span class=\"token punctuation\">.</span><span class=\"token function\">equal</span><span class=\"token punctuation\">(</span><span class=\"token string\">'03/01/2015'</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><strong>Concurrency</strong></h2>\n<h3>Use Promises, not callbacks</h3>\n<p>Callbacks aren't clean, and they cause excessive amounts of nesting. With ES2015/ES6,\nPromises are a built-in global type. Use them!</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> get <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'request'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> writeFile <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'fs'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://en.wikipedia.org/wiki/Robert_Cecil_Martin'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">requestErr<span class=\"token punctuation\">,</span> response<span class=\"token punctuation\">,</span> body</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>requestErr<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>requestErr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'article.html'</span><span class=\"token punctuation\">,</span> body<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">writeErr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>writeErr<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>writeErr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'File written'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> get <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'request-promise'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> writeFile <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'fs-extra'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://en.wikipedia.org/wiki/Robert_Cecil_Martin'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">body</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'article.html'</span><span class=\"token punctuation\">,</span> body<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'File written'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Async/Await are even cleaner than Promises</h3>\n<p>Promises are a very clean alternative to callbacks, but ES2017/ES8 brings async and await\nwhich offer an even cleaner solution. All you need is a function that is prefixed\nin an <code class=\"language-text\">async</code> keyword, and then you can write your logic imperatively without\na <code class=\"language-text\">then</code> chain of functions. Use this if you can take advantage of ES2017/ES8 features\ntoday!</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> get <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'request-promise'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> writeFile <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'fs-extra'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://en.wikipedia.org/wiki/Robert_Cecil_Martin'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">body</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'article.html'</span><span class=\"token punctuation\">,</span> body<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'File written'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> get <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'request-promise'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> writeFile <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'fs-extra'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">getCleanCodeArticle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> body <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://en.wikipedia.org/wiki/Robert_Cecil_Martin'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'article.html'</span><span class=\"token punctuation\">,</span> body<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'File written'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">getCleanCodeArticle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><strong>Error Handling</strong></h2>\n<p>Thrown errors are a good thing! They mean the runtime has successfully\nidentified when something in your program has gone wrong and it's letting\nyou know by stopping function execution on the current stack, killing the\nprocess (in Node), and notifying you in the console with a stack trace.</p>\n<h3>Don't ignore caught errors</h3>\n<p>Doing nothing with a caught error doesn't give you the ability to ever fix\nor react to said error. Logging the error to the console (<code class=\"language-text\">console.log</code>)\nisn't much better as often times it can get lost in a sea of things printed\nto the console. If you wrap any bit of code in a <code class=\"language-text\">try/catch</code> it means you\nthink an error may occur there and therefore you should have a plan,\nor create a code path, for when it occurs.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">functionThatMightThrow</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">functionThatMightThrow</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// One option (more noisy than console.log):</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Another option:</span>\n    <span class=\"token function\">notifyUserOfError</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Another option:</span>\n    <span class=\"token function\">reportErrorToService</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// OR do all three!</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Don't ignore rejected promises</h3>\n<p>For the same reason you shouldn't ignore caught errors\nfrom <code class=\"language-text\">try/catch</code>.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getdata</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">functionThatMightThrow</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getdata</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">functionThatMightThrow</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// One option (more noisy than console.log):</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// Another option:</span>\n        <span class=\"token function\">notifyUserOfError</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// Another option:</span>\n        <span class=\"token function\">reportErrorToService</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// OR do all three!</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><strong>Formatting</strong></h2>\n<p>Formatting is subjective. Like many rules herein, there is no hard and fast\nrule that you must follow. The main point is DO NOT ARGUE over formatting.\nThere are <a href=\"https://standardjs.com/rules.html\">tons of tools</a> to automate this.\nUse one! It's a waste of time and money for engineers to argue over formatting.</p>\n<p>For things that don't fall under the purview of automatic formatting\n(indentation, tabs vs. spaces, double vs. single quotes, etc.) look here\nfor some guidance.</p>\n<h3>Use consistent capitalization</h3>\n<p>JavaScript is untyped, so capitalization tells you a lot about your variables,\nfunctions, etc. These rules are subjective, so your team can choose whatever\nthey want. The point is, no matter what you all choose, just be consistent.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">DAYS_IN_WEEK</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> daysInMonth <span class=\"token operator\">=</span> <span class=\"token number\">30</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> songs <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Back In Black'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Stairway to Heaven'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Hey Jude'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> Artists <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'ACDC'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Led Zeppelin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The Beatles'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">eraseDatabase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">restore_database</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">animal</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Alpaca</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">DAYS_IN_WEEK</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">DAYS_IN_MONTH</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token constant\">SONGS</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Back In Black'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Stairway to Heaven'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Hey Jude'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">ARTISTS</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'ACDC'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Led Zeppelin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The Beatles'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">eraseDatabase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">restoreDatabase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Animal</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Alpaca</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Function callers and callees should be close</h3>\n<p>If a function calls another, keep those functions vertically close in the source\nfile. Ideally, keep the caller right above the callee. We tend to read code from\ntop-to-bottom, like a newspaper. Because of this, make your code read that way.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">PerformanceReview</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">employee</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>employee <span class=\"token operator\">=</span> employee<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">lookupPeers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> db<span class=\"token punctuation\">.</span><span class=\"token function\">lookup</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>employee<span class=\"token punctuation\">,</span> <span class=\"token string\">'peers'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">lookupManager</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> db<span class=\"token punctuation\">.</span><span class=\"token function\">lookup</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>employee<span class=\"token punctuation\">,</span> <span class=\"token string\">'manager'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getPeerReviews</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> peers <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">lookupPeers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">perfReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getPeerReviews</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getManagerReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getSelfReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getManagerReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> manager <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">lookupManager</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getSelfReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> review <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">PerformanceReview</span><span class=\"token punctuation\">(</span>employee<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nreview<span class=\"token punctuation\">.</span><span class=\"token function\">perfReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">PerformanceReview</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">employee</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>employee <span class=\"token operator\">=</span> employee<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">perfReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getPeerReviews</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getManagerReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">getSelfReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getPeerReviews</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> peers <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">lookupPeers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">lookupPeers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> db<span class=\"token punctuation\">.</span><span class=\"token function\">lookup</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>employee<span class=\"token punctuation\">,</span> <span class=\"token string\">'peers'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getManagerReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> manager <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">lookupManager</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">lookupManager</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> db<span class=\"token punctuation\">.</span><span class=\"token function\">lookup</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>employee<span class=\"token punctuation\">,</span> <span class=\"token string\">'manager'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getSelfReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> review <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">PerformanceReview</span><span class=\"token punctuation\">(</span>employee<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nreview<span class=\"token punctuation\">.</span><span class=\"token function\">perfReview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2><strong>Comments</strong></h2>\n<h3>Only comment things that have business logic complexity.</h3>\n<p>Comments are an apology, not a requirement. Good code <em>mostly</em> documents itself.</p>\n<p><strong>Bad:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">hashIt</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// The hash</span>\n    <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Length of string</span>\n    <span class=\"token keyword\">const</span> length <span class=\"token operator\">=</span> data<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Loop through every character in data</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Get character code.</span>\n        <span class=\"token keyword\">const</span> char <span class=\"token operator\">=</span> data<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// Make the hash</span>\n        hash <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>hash <span class=\"token operator\">&lt;&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> hash <span class=\"token operator\">+</span> char<span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// Convert to 32-bit integer</span>\n        hash <span class=\"token operator\">&amp;=</span> hash<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">hashIt</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> length <span class=\"token operator\">=</span> data<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> char <span class=\"token operator\">=</span> data<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        hash <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>hash <span class=\"token operator\">&lt;&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> hash <span class=\"token operator\">+</span> char<span class=\"token punctuation\">;</span>\n\n        <span class=\"token comment\">// Convert to 32-bit integer</span>\n        hash <span class=\"token operator\">&amp;=</span> hash<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Don't leave commented out code in your codebase</h3>\n<p>Version control exists for a reason. Leave old code in your history.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">doStuff</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// doOtherStuff();</span>\n<span class=\"token comment\">// doSomeMoreStuff();</span>\n<span class=\"token comment\">// doSoMuchStuff();</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">doStuff</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Don't have journal comments</h3>\n<p>Remember, use version control! There's no need for dead code, commented code,\nand especially journal comments. Use <code class=\"language-text\">git log</code> to get history!</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * 2016-12-20: Removed monads, didn't understand them (RM)\n * 2016-10-01: Improved using special monads (JP)\n * 2016-02-03: Removed type-checking (LI)\n * 2015-03-14: Added combine with type-checking (JR)\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">combine</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">combine</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Avoid positional markers</h3>\n<p>They usually just add noise. Let the functions and variable names along with the\nproper indentation and formatting give the visual structure to your code.</p>\n<p><strong>Bad:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">////////////////////////////////////////////////////////////////////////////////</span>\n<span class=\"token comment\">// Scope Model Instantiation</span>\n<span class=\"token comment\">////////////////////////////////////////////////////////////////////////////////</span>\n$scope<span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">menu</span><span class=\"token operator\">:</span> <span class=\"token string\">'foo'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">nav</span><span class=\"token operator\">:</span> <span class=\"token string\">'bar'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">////////////////////////////////////////////////////////////////////////////////</span>\n<span class=\"token comment\">// Action setup</span>\n<span class=\"token comment\">////////////////////////////////////////////////////////////////////////////////</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">actions</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Good:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n$scope<span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">menu</span><span class=\"token operator\">:</span> <span class=\"token string\">'foo'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">nav</span><span class=\"token operator\">:</span> <span class=\"token string\">'bar'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">actions</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Translation</h2>\n<p>This is also available in other languages:</p>\n<ul>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Armenia.png\" alt=\"am\"> <strong>Armenian</strong>: <a href=\"https://github.com/hanumanum/clean-code-javascript\">hanumanum/clean-code-javascript/</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Bangladesh.png\" alt=\"bd\"> <strong>Bangla(বাংলা)</strong>: <a href=\"https://github.com/InsomniacSabbir/clean-code-javascript/\">InsomniacSabbir/clean-code-javascript/</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Brazil.png\" alt=\"br\"> <strong>Brazilian Portuguese</strong>: <a href=\"https://github.com/fesnt/clean-code-javascript\">fesnt/clean-code-javascript</a></li>\n<li>\n<p><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/China.png\" alt=\"cn\"> <strong>Simplified Chinese</strong>:</p>\n<ul>\n<li><a href=\"https://github.com/alivebao/clean-code-js\">alivebao/clean-code-js</a></li>\n<li><a href=\"https://github.com/beginor/clean-code-javascript\">beginor/clean-code-javascript</a></li>\n</ul>\n</li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Taiwan.png\" alt=\"tw\"> <strong>Traditional Chinese</strong>: <a href=\"https://github.com/AllJointTW/clean-code-javascript\">AllJointTW/clean-code-javascript</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/France.png\" alt=\"fr\"> <strong>French</strong>: <a href=\"https://github.com/GavBaros/clean-code-javascript-fr\">GavBaros/clean-code-javascript-fr</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Germany.png\" alt=\"de\"> <strong>German</strong>: <a href=\"https://github.com/marcbruederlin/clean-code-javascript\">marcbruederlin/clean-code-javascript</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Indonesia.png\" alt=\"id\"> <strong>Indonesia</strong>: <a href=\"https://github.com/andirkh/clean-code-javascript/\">andirkh/clean-code-javascript/</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png\" alt=\"it\"> <strong>Italian</strong>: <a href=\"https://github.com/frappacchio/clean-code-javascript/\">frappacchio/clean-code-javascript/</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png\" alt=\"ja\"> <strong>Japanese</strong>: <a href=\"https://github.com/mitsuruog/clean-code-javascript/\">mitsuruog/clean-code-javascript/</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/South-Korea.png\" alt=\"kr\"> <strong>Korean</strong>: <a href=\"https://github.com/qkraudghgh/clean-code-javascript-ko\">qkraudghgh/clean-code-javascript-ko</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Poland.png\" alt=\"pl\"> <strong>Polish</strong>: <a href=\"https://github.com/greg-dev/clean-code-javascript-pl\">greg-dev/clean-code-javascript-pl</a></li>\n<li>\n<p><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Russia.png\" alt=\"ru\"> <strong>Russian</strong>:</p>\n<ul>\n<li><a href=\"https://github.com/BoryaMogila/clean-code-javascript-ru/\">BoryaMogila/clean-code-javascript-ru/</a></li>\n<li><a href=\"https://github.com/maksugr/clean-code-javascript\">maksugr/clean-code-javascript</a></li>\n</ul>\n</li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Spain.png\" alt=\"es\"> <strong>Spanish</strong>: <a href=\"https://github.com/tureey/clean-code-javascript\">tureey/clean-code-javascript</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Uruguay.png\" alt=\"es\"> <strong>Spanish</strong>: <a href=\"https://github.com/andersontr15/clean-code-javascript-es\">andersontr15/clean-code-javascript</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Serbia.png\" alt=\"rs\"> <strong>Serbian</strong>: <a href=\"https://github.com/doskovicmilos/clean-code-javascript\">doskovicmilos/clean-code-javascript/</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Turkey.png\" alt=\"tr\"> <strong>Turkish</strong>: <a href=\"https://github.com/bsonmez/clean-code-javascript/tree/turkish-translation\">bsonmez/clean-code-javascript</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Ukraine.png\" alt=\"ua\"> <strong>Ukrainian</strong>: <a href=\"https://github.com/mindfr1k/clean-code-javascript-ua\">mindfr1k/clean-code-javascript-ua</a></li>\n<li><img src=\"https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png\" alt=\"vi\"> <strong>Vietnamese</strong>: <a href=\"https://github.com/hienvd/clean-code-javascript/\">hienvd/clean-code-javascript/</a></li>\n</ul>"},{"url":"/docs/javascript/for-loops/","relativePath":"docs/javascript/for-loops.md","relativeDir":"docs/javascript","base":"for-loops.md","name":"for-loops","frontmatter":{"title":"Js-Loops","weight":0,"excerpt":"JS-Loops","seo":{"title":"Js-Loops","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>for</h1>\n<p>The <strong>for statement</strong> creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement (usually a <a href=\"block\">block statement</a>) to be executed in the loop.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for ([initialization]; [condition]; [final-expression])\n   statement</code></pre></div>\n<p><code class=\"language-text\">initialization</code>\nAn expression (including assignment expressions) or variable declaration evaluated once before the loop begins. Typically used to initialize a counter variable. This expression may optionally declare new variables with <code class=\"language-text\">var</code> or <code class=\"language-text\">let</code> keywords. Variables declared with <code class=\"language-text\">var</code> are not local to the loop, i.e. they are in the same scope the <code class=\"language-text\">for</code> loop is in. Variables declared with <code class=\"language-text\">let</code> are local to the statement.</p>\n<p>The result of this expression is discarded.</p>\n<p><code class=\"language-text\">condition</code>\nAn expression to be evaluated before each loop iteration. If this expression evaluates to true, <code class=\"language-text\">statement</code> is executed. This conditional test is optional. If omitted, the condition always evaluates to true. If the expression evaluates to false, execution skips to the first expression following the <code class=\"language-text\">for</code> construct.</p>\n<p><code class=\"language-text\">final-expression</code>\nAn expression to be evaluated at the end of each loop iteration. This occurs before the next evaluation of <code class=\"language-text\">condition</code>. Generally used to update or increment the counter variable.</p>\n<p><code class=\"language-text\">statement</code>\nA statement that is executed as long as the condition evaluates to true. To execute multiple statements within the loop, use a <a href=\"block\">block</a> statement (<code class=\"language-text\">{ ... }</code>) to group those statements. To execute no statement within the loop, use an <a href=\"empty\">empty</a> statement (<code class=\"language-text\">;</code>).</p>\n<h2>Examples</h2>\n<h3>Using for</h3>\n<p>The following <code class=\"language-text\">for</code> statement starts by declaring the variable <code class=\"language-text\">i</code> and initializing it to <code class=\"language-text\">0</code>. It checks that <code class=\"language-text\">i</code> is less than nine, performs the two succeeding statements, and increments <code class=\"language-text\">i</code> by 1 after each pass through the loop.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for (let i = 0; i &lt; 9; i++) {\n   console.log(i);\n   // more statements\n}</code></pre></div>\n<h3>Optional for expressions</h3>\n<p>All three expressions in the head of the <code class=\"language-text\">for</code> loop are optional.</p>\n<p>For example, in the <code class=\"language-text\">initialization</code> block it is not required to initialize variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">9</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// more statements</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Like the <code class=\"language-text\">initialization</code> block, the <code class=\"language-text\">condition</code> block is also optional. If you are omitting this expression, you must make sure to break the loop in the body in order to not create an infinite loop.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">></span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// more statements</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>You can also omit all three blocks. Again, make sure to use a <a href=\"break\"><code class=\"language-text\">break</code></a> statement to end the loop and also modify (increase) a variable, so that the condition for the break statement is true at some point.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">></span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Using for without a statement</h3>\n<p>The following <code class=\"language-text\">for</code> cycle calculates the offset position of a node in the <code class=\"language-text\">final-expression</code> section, and therefore it does not require the use of a <code class=\"language-text\">statement</code> section, a semicolon is used instead.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">showOffsetPos</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">sId</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> nLeft <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n        nTop <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token keyword\">var</span> oItNode <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span>sId<span class=\"token punctuation\">)</span> <span class=\"token comment\">/* initialization */</span><span class=\"token punctuation\">;</span>\n        oItNode <span class=\"token comment\">/* condition */</span><span class=\"token punctuation\">;</span>\n        nLeft <span class=\"token operator\">+=</span> oItNode<span class=\"token punctuation\">.</span>offsetLeft<span class=\"token punctuation\">,</span> nTop <span class=\"token operator\">+=</span> oItNode<span class=\"token punctuation\">.</span>offsetTop<span class=\"token punctuation\">,</span> oItNode <span class=\"token operator\">=</span> oItNode<span class=\"token punctuation\">.</span>offsetParent <span class=\"token comment\">/* final-expression */</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">/* semicolon */</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Offset position of '\"</span> <span class=\"token operator\">+</span> sId <span class=\"token operator\">+</span> <span class=\"token string\">\"' element:\\n left: \"</span> <span class=\"token operator\">+</span> nLeft <span class=\"token operator\">+</span> <span class=\"token string\">'px;\\n top: '</span> <span class=\"token operator\">+</span> nTop <span class=\"token operator\">+</span> <span class=\"token string\">'px;'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Example call: */</span>\n\n<span class=\"token function\">showOffsetPos</span><span class=\"token punctuation\">(</span><span class=\"token string\">'content'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Output:</span>\n<span class=\"token comment\">// \"Offset position of \"content\" element:</span>\n<span class=\"token comment\">// left: 0px;</span>\n<span class=\"token comment\">// top: 153px;\"</span></code></pre></div>\n<p><strong>Note:</strong> This is one of the few cases in JavaScript where <strong>the semicolon is mandatory</strong>. Indeed, without the semicolon the line that follows the cycle declaration will be considered a statement.</p>\n<hr>\n<h2>For... In</h2>\n<h1>for...in</h1>\n<p>The <code class=\"language-text\">for...in</code> iterates over all <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties\">enumerable properties</a> of an object that are keyed by strings (ignoring ones keyed by <a href=\"../global_objects/symbol\">Symbol</a>s), including inherited enumerable properties.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for (variable in object)\n  statement</code></pre></div>\n<p><code class=\"language-text\">variable</code>\nA different property name is assigned to <code class=\"language-text\">variable</code> on each iteration.</p>\n<p><code class=\"language-text\">object</code>\nObject whose non-Symbol enumerable properties are iterated over.</p>\n<h2>Description</h2>\n<p>A <code class=\"language-text\">for...in</code> loop only iterates over enumerable, non-Symbol properties. Objects created from built-in constructors like <code class=\"language-text\">Array</code> and <code class=\"language-text\">Object</code> have inherited non-enumerable properties from <code class=\"language-text\">Object.prototype</code> and <code class=\"language-text\">String.prototype</code>, such as <a href=\"../global_objects/string\"><code class=\"language-text\">String</code></a>'s <a href=\"../global_objects/string/indexof\"><code class=\"language-text\">indexOf()</code></a> method or <a href=\"../global_objects/object\"><code class=\"language-text\">Object</code></a>'s <a href=\"../global_objects/object/tostring\"><code class=\"language-text\">toString()</code></a> method. The loop will iterate over all enumerable properties of the object itself and those the object inherits from its prototype chain (properties of nearer prototypes take precedence over those of prototypes further away from the object in its prototype chain).</p>\n<h3>Deleted, added, or modified properties</h3>\n<p>A <code class=\"language-text\">for...in</code> loop iterates over the properties of an object in an arbitrary order (see the <a href=\"../operators/delete\"><code class=\"language-text\">delete</code></a> operator for more on why one cannot depend on the seeming orderliness of iteration, at least in a cross-browser setting).</p>\n<p>If a property is modified in one iteration and then visited at a later time, its value in the loop is its value at that later time. A property that is deleted before it has been visited will not be visited later. Properties added to the object over which iteration is occurring may either be visited or omitted from iteration.</p>\n<p>In general, it is best not to add, modify, or remove properties from the object during iteration, other than the property currently being visited. There is no guarantee whether an added property will be visited, whether a modified property (other than the current one) will be visited before or after it is modified, or whether a deleted property will be visited before it is deleted.</p>\n<h3>Array iteration and for...in</h3>\n<p><strong>Note:</strong> <code class=\"language-text\">for...in</code> should not be used to iterate over an <a href=\"../global_objects/array\"><code class=\"language-text\">Array</code></a> where the index order is important.</p>\n<p>Array indexes are just enumerable properties with integer names and are otherwise identical to general object properties. There is no guarantee that <code class=\"language-text\">for...in</code> will return the indexes in any particular order. The <code class=\"language-text\">for...in</code> loop statement will return all enumerable properties, including those with non-integer names and those that are inherited.</p>\n<p>Because the order of iteration is implementation-dependent, iterating over an array may not visit elements in a consistent order. Therefore, it is better to use a <a href=\"for\"><code class=\"language-text\">for</code></a> loop with a numeric index (or <a href=\"../global_objects/array/foreach\"><code class=\"language-text\">Array.prototype.forEach()</code></a> or the <a href=\"for...of\"><code class=\"language-text\">for...of</code></a> loop) when iterating over arrays where the order of access is important.</p>\n<h3>Iterating over own properties only</h3>\n<p>If you only want to consider properties attached to the object itself, and not its prototypes, use <a href=\"../global_objects/object/getownpropertynames\"><code class=\"language-text\">getOwnPropertyNames()</code></a> or perform a <a href=\"../global_objects/object/hasownproperty\"><code class=\"language-text\">hasOwnProperty()</code></a> check (<a href=\"../global_objects/object/propertyisenumerable\"><code class=\"language-text\">propertyIsEnumerable()</code></a> can also be used). Alternatively, if you know there won't be any outside code interference, you can extend built-in prototypes with a check method.</p>\n<h2>Why Use for...in?</h2>\n<p>Given that <code class=\"language-text\">for...in</code> is built for iterating object properties, not recommended for use with arrays, and options like <code class=\"language-text\">Array.prototype.forEach()</code> and <code class=\"language-text\">for...of</code> exist, what might be the use of <code class=\"language-text\">for...in</code> at all?</p>\n<p>It may be most practically used for debugging purposes, being an easy way to check the properties of an object (by outputting to the console or otherwise). Although arrays are often more practical for storing data, in situations where a key-value pair is preferred for working with data (with properties acting as the \"key\"), there may be instances where you want to check if any of those keys hold a particular value.</p>\n<h2>Examples</h2>\n<h3>Using for...in</h3>\n<p>The <code class=\"language-text\">for...in</code> loop below iterates over all of the object's enumerable, non-Symbol properties and logs a string of the property names and their values.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">c</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> prop <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">obj.</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>prop<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>obj<span class=\"token punctuation\">[</span>prop<span class=\"token punctuation\">]</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Output:</span>\n<span class=\"token comment\">// \"obj.a = 1\"</span>\n<span class=\"token comment\">// \"obj.b = 2\"</span>\n<span class=\"token comment\">// \"obj.c = 3\"</span></code></pre></div>\n<h3>Iterating own properties</h3>\n<p>The following function illustrates the use of <a href=\"../global_objects/object/hasownproperty\"><code class=\"language-text\">hasOwnProperty()</code></a>: the inherited properties are not displayed.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> triangle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">c</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">ColoredTriangle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">ColoredTriangle</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> triangle<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> obj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ColoredTriangle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> prop <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>prop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">obj.</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>prop<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>obj<span class=\"token punctuation\">[</span>prop<span class=\"token punctuation\">]</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Output:</span>\n<span class=\"token comment\">// \"obj.color = red\"</span></code></pre></div>\n<hr>\n<h2>For await Of</h2>\n<h1>for await...of</h1>\n<p>The <code class=\"language-text\">for await...of</code> creates a loop iterating over async iterable objects as well as on sync iterables, including: built-in <a href=\"../global_objects/string\"><code class=\"language-text\">String</code></a>, <a href=\"../global_objects/array\"><code class=\"language-text\">Array</code></a>, <code class=\"language-text\">Array</code>-like objects (e.g., <a href=\"../functions/arguments\"><code class=\"language-text\">arguments</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeList\"><code class=\"language-text\">NodeList</code></a>), <a href=\"../global_objects/typedarray\"><code class=\"language-text\">TypedArray</code></a>, <a href=\"../global_objects/map\"><code class=\"language-text\">Map</code></a>, <a href=\"../global_objects/set\"><code class=\"language-text\">Set</code></a>, and user-defined async/sync iterables. It invokes a custom iteration hook with statements to be executed for the value of each distinct property of the object. This statement can only be used inside an <a href=\"async_function\">async function</a>.</p>\n<p><strong>Note:</strong> <code class=\"language-text\">for await...of</code> doesn't work with async iterators that are not async iterables.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for await (variable of iterable) {\n  statement\n}</code></pre></div>\n<p><code class=\"language-text\">variable</code>\nOn each iteration a value of a different property is assigned to <code class=\"language-text\">variable</code>. <code class=\"language-text\">variable</code> may be declared with <code class=\"language-text\">const</code>, <code class=\"language-text\">let</code>, or <code class=\"language-text\">var</code>.</p>\n<p><code class=\"language-text\">iterable</code>\nObject whose iterable properties are to be iterated over.</p>\n<h2>Examples</h2>\n<h3>Iterating over async iterables</h3>\n<p>You can also iterate over an object that explicitly implements async iterable protocol:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> asyncIterable <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span>asyncIterator<span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">i</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>i <span class=\"token operator\">&lt;</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>i<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">done</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">done</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token keyword\">await</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> num <span class=\"token keyword\">of</span> asyncIterable<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// 2</span></code></pre></div>\n<h3>Iterating over async generators</h3>\n<p>Since the return values of async generators conform to the async iterable protocol, they can be looped using <code class=\"language-text\">for await...of</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">asyncGenerator</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">yield</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token keyword\">await</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> num <span class=\"token keyword\">of</span> <span class=\"token function\">asyncGenerator</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// 2</span></code></pre></div>\n<p>For a more concrete example of iterating over an async generator using <code class=\"language-text\">for await...of</code>, consider iterating over data from an API.</p>\n<p>This example first creates an async iterable for a stream of data, then uses it to find the size of the response from the API.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">streamAsyncIterable</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">stream</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> reader <span class=\"token operator\">=</span> stream<span class=\"token punctuation\">.</span><span class=\"token function\">getReader</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> done<span class=\"token punctuation\">,</span> value <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> reader<span class=\"token punctuation\">.</span><span class=\"token function\">read</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>done<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">yield</span> value<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">finally</span> <span class=\"token punctuation\">{</span>\n        reader<span class=\"token punctuation\">.</span><span class=\"token function\">releaseLock</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// Fetches data from url and calculates response size using the async generator.</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">getResponseSize</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Will hold the size of the response, in bytes.</span>\n    <span class=\"token keyword\">let</span> responseSize <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// The for-await-of loop. Async iterates over each portion of the response.</span>\n    <span class=\"token keyword\">for</span> <span class=\"token keyword\">await</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> chunk <span class=\"token keyword\">of</span> <span class=\"token function\">streamAsyncIterable</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Incrementing the total response length.</span>\n        responseSize <span class=\"token operator\">+=</span> chunk<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Response Size: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>responseSize<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> bytes</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// expected output: \"Response Size: 1071472\"</span>\n    <span class=\"token keyword\">return</span> responseSize<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">getResponseSize</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://jsonplaceholder.typicode.com/photos'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Iterating over sync iterables and generators</h3>\n<p><code class=\"language-text\">for await...of</code> loop also consumes sync iterables and generators. In that case it internally awaits emitted values before assign them to the loop control variable.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">generator</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token keyword\">await</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> num <span class=\"token keyword\">of</span> <span class=\"token function\">generator</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// 2</span>\n<span class=\"token comment\">// 3</span>\n<span class=\"token comment\">// 4</span>\n\n<span class=\"token comment\">// compare with for-of loop:</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> numOrPromise <span class=\"token keyword\">of</span> <span class=\"token function\">generator</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numOrPromise<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// Promise { 2 }</span>\n<span class=\"token comment\">// Promise { 3 }</span>\n<span class=\"token comment\">// 4</span></code></pre></div>\n<p><strong>Note:</strong> Be aware of yielding rejected promises from sync generator. In such case <code class=\"language-text\">for await...of</code> throws when consuming rejected promise and DOESN'T CALL <code class=\"language-text\">finally</code> blocks within that generator. This can be undesirable if you need to free some allocated resources with <code class=\"language-text\">try/finally</code>.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">generatorWithRejectedPromises</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">yield</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">yield</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">yield</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">reject</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">yield</span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">throw</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">finally</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'called finally'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token keyword\">await</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> num <span class=\"token keyword\">of</span> <span class=\"token function\">generatorWithRejectedPromises</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'caught'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// 2</span>\n<span class=\"token comment\">// caught 3</span>\n\n<span class=\"token comment\">// compare with for-of loop:</span>\n\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> numOrPromise <span class=\"token keyword\">of</span> <span class=\"token function\">generatorWithRejectedPromises</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numOrPromise<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'caught'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// Promise { 2 }</span>\n<span class=\"token comment\">// Promise { &lt;rejected> 3 }</span>\n<span class=\"token comment\">// 4</span>\n<span class=\"token comment\">// caught 5</span>\n<span class=\"token comment\">// called finally</span></code></pre></div>\n<p>To make <code class=\"language-text\">finally</code> blocks of a sync generator to be always called use appropriate form of the loop, <code class=\"language-text\">for await...of</code> for the async generator and <code class=\"language-text\">for...of</code> for the sync one and await yielded promises explicitly inside the loop.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> numOrPromise <span class=\"token keyword\">of</span> <span class=\"token function\">generatorWithRejectedPromises</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">await</span> numOrPromise<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'caught'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// 2</span>\n<span class=\"token comment\">// caught 3</span>\n<span class=\"token comment\">// called finally</span></code></pre></div>"},{"url":"/docs/javascript/constructor-functions/","relativePath":"docs/javascript/constructor-functions.md","relativeDir":"docs/javascript","base":"constructor-functions.md","name":"constructor-functions","frontmatter":{"title":"Constructor Functions","weight":0,"excerpt":"Constructor Functions","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><strong>Constructor Functions</strong></h2>\n<p><strong>Defining a constructor function</strong>\n<em>Example of an object using object initialiation</em></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fellowshipOfTheRing <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">'The Fellowship of the Ring'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">series</span><span class=\"token operator\">:</span> <span class=\"token string\">'The Lord of the Rings'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">author</span><span class=\"token operator\">:</span> <span class=\"token string\">'J.R.R. Tolkien'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>The above literal is a \"Book\" object type.</li>\n<li>\n<p><strong><code class=\"language-text\">Object Type</code></strong> is defined by it's attributes and behaviors.</p>\n<ul>\n<li><strong><code class=\"language-text\">Behaviors</code></strong> are represented by methods.</li>\n</ul>\n</li>\n<li>\n<p><strong><code class=\"language-text\">Constructor Functions</code></strong> : Handle the creation of an object - it's a factory for creating objects of a specific type.</p>\n<ul>\n<li>\n<p>There are a few specific things to constructors worth noting:</p>\n<ul>\n<li><strong>The name of the constructor function is capitalized</strong></li>\n<li><strong>The Function does not explicityly return a value</strong></li>\n<li><strong>Within the body, the <em>this</em> keyword references the newly created object</strong></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Book</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> author</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series <span class=\"token operator\">=</span> series<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author <span class=\"token operator\">=</span> author<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2><strong>Invoking a constructor function</strong></h2>\n<ul>\n<li>We can invoke a constructor function using the <strong><code class=\"language-text\">new</code></strong> keyword.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Book</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> author</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series <span class=\"token operator\">=</span> series<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author <span class=\"token operator\">=</span> author<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> fellowshipOfTheRing <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The Fellowship of the Ring'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The Lord of the Rings'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'J.R.R. Tolkien'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>fellowshipOfTheRing<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Book { title: 'The Fellowship of the Ring', ... }</span></code></pre></div>\n<ul>\n<li>\n<p><em>Four Things will happen when invoking a constructor function</em></p>\n<ol>\n<li>A new empty object is created {};</li>\n<li>The new obj's <strong><code class=\"language-text\">prototype</code></strong> is set to the object referenced by the constructors prototype property.</li>\n<li><strong><code class=\"language-text\">This</code></strong> is bound to the new object.</li>\n<li>The new object is returned after the constructor function has completed.</li>\n</ol>\n</li>\n</ul>\n<p><strong>Understanding New Object Instances</strong></p>\n<ul>\n<li><strong><code class=\"language-text\">Instance</code></strong> : term to describe an objected created from a constructor function.</li>\n<li>Every instance created is a unique object and therefore not equal to each other.</li>\n</ul>\n<p><strong>Using the instanceof operator to check an object's type</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>fellowshipOfTheRing <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n<ul>\n<li>\n<p>By using the <code class=\"language-text\">instanceof</code> operator we can verify that an object was created from a certain object type.</p>\n<ul>\n<li><em>The instanceOf operator works by checking to see if the prototype object of the left side of the operator is the same as the prototype object of the right side of the operator.</em></li>\n</ul>\n</li>\n</ul>\n<p><strong>Invoking a constructor function without the new keyword</strong></p>\n<ul>\n<li>\n<p>If we invoke a constructor function without the <strong><code class=\"language-text\">new</code></strong> keyword, we may result in one of two unexpected outcomes:</p>\n<ol>\n<li>In <strong>non-strict</strong> mode, this will be bound to the <strong>global object</strong> instead.</li>\n<li>\n<p>In <strong><code class=\"language-text\">strict</code></strong> mode, this will become undefined.</p>\n<ul>\n<li>You can enable strict mode by typing <code class=\"language-text\">\"use strict\"</code> at the top of your file.</li>\n</ul>\n</li>\n</ol>\n</li>\n</ul>\n<p><strong>Defining Sharable Methods</strong></p>\n<ul>\n<li><em>Avoid the temptation to store an object method inside a constructor function, it is inefficient with computer memory usage b/c each object instance would have it's own method definition.</em></li>\n<li>\n<p><strong><code class=\"language-text\">Prototype</code></strong> : An object that is delegated to when a reference to an object property or method can't be resolved.</p>\n<ul>\n<li>Every instance created by a constructor function shares the same prototype.</li>\n</ul>\n</li>\n<li>\n<p><strong><code class=\"language-text\">Object.setPrototypeOf()</code></strong> and <strong><code class=\"language-text\">Object.getPrototypeOf()</code></strong> are just used to set a prototype of one object to another object; and also the verify a prototype.</p>\n<ul>\n<li><strong><code class=\"language-text\">proto</code></strong> : aka \"dunder proto\" is a property used to gain easy access to an object's prototype - it is widely supported by browsers but is considered deprecated.</li>\n</ul>\n</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Book</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> author</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series <span class=\"token operator\">=</span> series<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author <span class=\"token operator\">=</span> author<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Any method defined on the `Book.prototype` property</span>\n<span class=\"token comment\">// will be shared across all `Book` instances.</span>\n<span class=\"token class-name\">Book</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getInformation</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> by </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> fellowshipOfTheRing <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The Fellowship of the Ring'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The Lord of the Rings'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'J.R.R. Tolkien'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>fellowshipOfTheRing<span class=\"token punctuation\">.</span><span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Every method we define on a constructor function's prototype property will be shared across all instances of that object type.</li>\n</ul>\n<p><strong>The Problem with Arrow Functions</strong></p>\n<ul>\n<li>\n<p>We <strong>cannot</strong> use arrow functions when defining methods on a constructor function's prototype property.</p>\n<ul>\n<li>Arrow functions don't include their own <strong>this</strong> binding; therefore it will not reference the current instance - always stick with the function () keyword.</li>\n</ul>\n</li>\n</ul>\n<hr>\n<h2><strong>Putting the Class in Javascript Classes</strong></h2>\n<p>In ES2015, JS gained the <strong><code class=\"language-text\">class</code></strong> keyword - replacing the need to use only constructor functions &#x26; prototypes to mimic classes!</p>\n<ul>\n<li><strong><code class=\"language-text\">class</code></strong> : keyword that gives developers a formal way to create a class definition to specify an object type's attributes and behavior; also used to create objects of that specific type.</li>\n</ul>\n<p><strong>Defining a ES2015 class</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Book</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> author</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series <span class=\"token operator\">=</span> series<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author <span class=\"token operator\">=</span> author<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Class names also begin only with capital letters.</li>\n<li>\n<p>Although not required, class definitions can include a <strong><code class=\"language-text\">class constructor function</code></strong> - these are similar to regular constructors in that:</p>\n<ul>\n<li>They don't explicitly return a value.</li>\n<li>The <strong>this</strong> keyword references the newly created object instance.</li>\n</ul>\n</li>\n</ul>\n<p><strong>Instantiating an instance of a class</strong></p>\n<ul>\n<li>\n<p>We can also use the <strong><code class=\"language-text\">new</code></strong>.</p>\n<ul>\n<li>Four things occur when instantiating an instance of a class:</li>\n<li>New empty object is created {};</li>\n<li>The new obj's prototype is set to the class prototype's property value.</li>\n<li><strong><code class=\"language-text\">This</code></strong> is bound to the new object.</li>\n<li>After the constructor method has completed, the new obj is returned.</li>\n</ul>\n</li>\n<li>Don't try to instatiate a class object without the <strong>new</strong> keyword.</li>\n</ul>\n<p><strong>Class Definitions are NOT hoisted</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">test</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">test</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'This works!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>In JS you can call a function before it's declared - this is known as <strong><code class=\"language-text\">hoisting</code></strong>.</li>\n<li>Class defs are NOT hoisted, so just get in the habit of declaring them <strong>before</strong> you use them.</li>\n</ul>\n<p><strong>Defining Methods</strong></p>\n<ul>\n<li>A class can contain two types of methods:</li>\n<li></li>\n<li>\n<p><strong><code class=\"language-text\">Instance Method</code></strong> : Methods that are invoked on an instance of the class - useful for performing an action on a specific instance.</p>\n<ul>\n<li>Instance methods are also sometimes referred to as <strong><code class=\"language-text\">prototype</code></strong> methods because they are defined on a shared prototype object.</li>\n</ul>\n</li>\n<li>\n<p><strong><code class=\"language-text\">Static Method</code></strong> : Methods that invoked directly on a class, not on an instance.</p>\n<ul>\n<li><code class=\"language-text\">Important</code>: Invoking a static method on an instance will result in a runtime error.</li>\n<li>Prepending the <strong><code class=\"language-text\">static</code></strong> keyword at the beginning on the method name will make it static.</li>\n</ul>\n</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Book</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> author</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series <span class=\"token operator\">=</span> series<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author <span class=\"token operator\">=</span> author<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// Notice the use of a rest parameter (...books)</span>\n    <span class=\"token comment\">// to capture the passed parameters as an array of values.</span>\n    <span class=\"token keyword\">static</span> <span class=\"token function\">getTitles</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>books</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> books<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">book</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> book<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> by </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> fellowshipOfTheRing <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The Fellowship of the Ring'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The Lord of the Rings'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'J.R.R. Tolkien'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> theTwoTowers <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The Two Towers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The Lord of the Rings'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'J.R.R. Tolkien'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> bookTitles <span class=\"token operator\">=</span> Book<span class=\"token punctuation\">.</span><span class=\"token function\">getTitles</span><span class=\"token punctuation\">(</span>fellowshipOfTheRing<span class=\"token punctuation\">,</span> theTwoTowers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>bookTitles<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">', '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// The Fellowship of the Ring, The Two Towers</span></code></pre></div>\n<ul>\n<li>If we go back to an example of how constructor functions also use static methods - we see that static methods are <em>defined directly on the constructor function</em> - whereas instance methods need to be defined on the <em>prototype</em> object.</li>\n</ul>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Book</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> author</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series <span class=\"token operator\">=</span> series<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author <span class=\"token operator\">=</span> author<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Static methods are defined</span>\n<span class=\"token comment\">// directly on the constructor function.</span>\nBook<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getTitles</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>books</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> books<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">book</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> book<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Instance methods are defined</span>\n<span class=\"token comment\">// on the constructor function's `prototype` property.</span>\n<span class=\"token class-name\">Book</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getInformation</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> by </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> fellowshipOfTheRing <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The Fellowship of the Ring'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The Lord of the Rings'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'J.R.R. Tolkien'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> theTwoTowers <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The Two Towers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The Lord of the Rings'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'J.R.R. Tolkien'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>fellowshipOfTheRing<span class=\"token punctuation\">.</span><span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// The Fellowship of the Ring by J.R.R. Tolkien</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>theTwoTowers<span class=\"token punctuation\">.</span><span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// The Two Towers by J.R.R. Tolkien</span>\n\n<span class=\"token comment\">// Call the static `Book.getTitles()` method</span>\n<span class=\"token comment\">// to get an array of the book titles.</span>\n<span class=\"token keyword\">const</span> bookTitles <span class=\"token operator\">=</span> Book<span class=\"token punctuation\">.</span><span class=\"token function\">getTitles</span><span class=\"token punctuation\">(</span>fellowshipOfTheRing<span class=\"token punctuation\">,</span> theTwoTowers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>bookTitles<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">', '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// The Fellowship of the Ring, The Two Towers</span></code></pre></div>\n<p><strong>Comparing Classes to Constructor Functions</strong></p>\n<blockquote>\n<p>ES2015 Classes are essentially syntactic sugar over traditional constructor functions and prototypes.</p>\n</blockquote>\n<hr>\n<h2><strong>Javascript Inheritance</strong></h2>\n<ul>\n<li><strong><code class=\"language-text\">Child Class</code></strong> : Class that is based upon another class and inherits properties and methods from that other class.</li>\n<li><strong><code class=\"language-text\">Parent Class</code></strong> : Class that is being inherited downwards.</li>\n<li><strong><code class=\"language-text\">Inheritance</code></strong> : The process of basing a class upon another class.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">CatalogItem</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series <span class=\"token operator\">=</span> series<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> (</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>series<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">)</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Book</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">CatalogItem</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> author</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>author <span class=\"token operator\">=</span> author<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Movie</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">CatalogItem</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> director</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>director <span class=\"token operator\">=</span> director<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> theGrapesOfWrath <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The Grapes of Wrath'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John Steinbeck'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> aNewHope <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Movie</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Episode 4: A New Hope'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Star Wars'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'George Lucas'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>theGrapesOfWrath<span class=\"token punctuation\">.</span><span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// The Grapes of Wrath</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>aNewHope<span class=\"token punctuation\">.</span><span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Episode 4: A New Hope (Star Wars)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Catalogitem <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Function</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Book <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Function</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n<ul>\n<li>\n<p>A <strong><code class=\"language-text\">prototype chain</code></strong> defines a series of prototype objects that are delegated to one by one, when a property or method can't be found on an instance object.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>theGrapesOfWrath<span class=\"token punctuation\">.</span><span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// The Grapes of Wrath</span></code></pre></div>\n<p>When the <code class=\"language-text\">getInformation()</code> method is invoked:</p>\n<ul>\n<li>JS looks for get() on the current object.</li>\n<li>If it isn't found, the method call is delegated to the object's prototype.</li>\n<li>It continues up the prototype chain until the method is found.</li>\n</ul>\n</li>\n</ul>\n<p><strong>Overriding a method in a parent class</strong></p>\n<ul>\n<li><strong><code class=\"language-text\">Method Overriding</code></strong> : when a child class provides an implementation of a method that's already defined in a parent class.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Movie</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">CatalogItem</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">,</span> director</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">,</span> series<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>director <span class=\"token operator\">=</span> director<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">super</span><span class=\"token punctuation\">.</span><span class=\"token function\">getInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>director<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            result <span class=\"token operator\">+=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> [directed by </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>director<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">]</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>We can simply declare our own method of the same name in our child class to override our parent's version of <code class=\"language-text\">getInformation()</code></li>\n</ul>\n<hr>\n<h2><strong>Javascript Modules</strong></h2>\n<p><strong>Introducing Node.js modules</strong></p>\n<ul>\n<li>In Node.js, each JS file in a project defines a <strong><code class=\"language-text\">module</code></strong>.</li>\n<li>Module's contents are private by default.</li>\n<li><strong><code class=\"language-text\">Local Modules</code></strong> : Modules defined within your project.</li>\n<li><strong><code class=\"language-text\">Core Modules</code></strong> : Native modules contained within Node.js that you can use to perform tasks or to add functionality to your application.</li>\n<li><strong><code class=\"language-text\">CommonJS</code></strong> : A legacy module system.</li>\n<li><strong><code class=\"language-text\">ES Modules</code></strong> : Newer module sysem that will eventually replace CommonJS.</li>\n<li><strong><code class=\"language-text\">Entry Point</code></strong> : JS File that is passed to Node for access to the entire application.</li>\n<li>\n<p>Syntax for exporting modules:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmodule<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">.</span>Book <span class=\"token operator\">=</span> Book<span class=\"token punctuation\">;</span>\nmodule<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">.</span>Movie <span class=\"token operator\">=</span> Movie<span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    Book<span class=\"token punctuation\">,</span>\n    Movie\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>Syntax for importing modules:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> classes <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./classes'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> Book<span class=\"token punctuation\">,</span> Movie <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./classes'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Using Single Item Modules</strong></p>\n<blockquote>\n<p>Following the convention of a single exported item per module helps to keep modules focused and less likely to become bloted with too much code.</p>\n</blockquote>\n<p><strong>Understanding Module Loading</strong></p>\n<ul>\n<li>\n<p>When loading a module, Node will examine the identifier passed to the require() function to determine if our module is local, core, or third-party:</p>\n<ul>\n<li><strong><code class=\"language-text\">Local Module</code></strong>: identifier starts with ./ ../ or /</li>\n<li><strong><code class=\"language-text\">Node.js Core</code></strong>: identifier matches name</li>\n<li><strong><code class=\"language-text\">Third-Party</code></strong>: identifier matches a module in the node modules folder (installed package)</li>\n</ul>\n</li>\n</ul>\n<hr>\n</li>\n</ul>"},{"url":"/docs/javascript/","relativePath":"docs/javascript/index.md","relativeDir":"docs/javascript","base":"index.md","name":"index","frontmatter":{"title":"Javascript","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":"JavaScript Programming Language","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Javascript</h2>\n<details>\n<summary>  Cheatsheet </summary>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token comment\">// Single-line comments start with two slashes.</span>\n<span class=\"token comment\">/* Multiline comments start with slash-star,\n   and end with star-slash */</span>\n\n<span class=\"token comment\">// Statements can be terminated by ;</span>\n<span class=\"token function\">doStuff</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// ... but they don't have to be, as semicolons are automatically inserted</span>\n<span class=\"token comment\">// wherever there's a newline, except in certain cases.</span>\n<span class=\"token function\">doStuff</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Because those cases can cause unexpected results, we'll keep on using</span>\n<span class=\"token comment\">// semicolons in this guide.</span>\n\n<span class=\"token comment\">///////////////////////////////////</span>\n<span class=\"token comment\">// 1. Numbers, Strings and Operators</span>\n\n<span class=\"token comment\">// JavaScript has one number type (which is a 64-bit IEEE 754 double).</span>\n<span class=\"token comment\">// Doubles have a 52-bit mantissa, which is enough to store integers</span>\n<span class=\"token comment\">// up to about 9✕10¹⁵ precisely.</span>\n<span class=\"token number\">3</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 3</span>\n<span class=\"token number\">1.5</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 1.5</span>\n\n<span class=\"token comment\">// Some basic arithmetic works as you'd expect.</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 2</span>\n<span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 0.30000000000000004</span>\n<span class=\"token number\">8</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 7</span>\n<span class=\"token number\">10</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 20</span>\n<span class=\"token number\">35</span> <span class=\"token operator\">/</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 7</span>\n\n<span class=\"token comment\">// Including uneven division.</span>\n<span class=\"token number\">5</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 2.5</span>\n\n<span class=\"token comment\">// And modulo division.</span>\n<span class=\"token number\">10</span> <span class=\"token operator\">%</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 0</span>\n<span class=\"token number\">30</span> <span class=\"token operator\">%</span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 2</span>\n<span class=\"token number\">18.5</span> <span class=\"token operator\">%</span> <span class=\"token number\">7</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 4.5</span>\n\n<span class=\"token comment\">// Bitwise operations also work; when you perform a bitwise operation your float</span>\n<span class=\"token comment\">// is converted to a signed int *up to* 32 bits.</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">&lt;&lt;</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 4</span>\n\n<span class=\"token comment\">// Precedence is enforced with parentheses.</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 8</span>\n\n<span class=\"token comment\">// There are three special not-a-real-number values:</span>\n<span class=\"token number\">Infinity</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// result of e.g. 1/0</span>\n<span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// result of e.g. -1/0</span>\n<span class=\"token number\">NaN</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// result of e.g. 0/0, stands for 'Not a Number'</span>\n\n<span class=\"token comment\">// There's also a boolean type.</span>\n<span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Strings are created with ' or \".</span>\n<span class=\"token string\">'abc'</span><span class=\"token punctuation\">;</span>\n<span class=\"token string\">\"Hello, world\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Negation uses the ! symbol</span>\n<span class=\"token operator\">!</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = false</span>\n<span class=\"token operator\">!</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n\n<span class=\"token comment\">// Equality is ===</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n<span class=\"token number\">2</span> <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = false</span>\n\n<span class=\"token comment\">// Inequality is !==</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">!==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = false</span>\n<span class=\"token number\">2</span> <span class=\"token operator\">!==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n\n<span class=\"token comment\">// More comparisons</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = false</span>\n<span class=\"token number\">2</span> <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n<span class=\"token number\">2</span> <span class=\"token operator\">>=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n\n<span class=\"token comment\">// Strings are concatenated with +</span>\n<span class=\"token string\">\"Hello \"</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"world!\"</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"Hello world!\"</span>\n\n<span class=\"token comment\">// ... which works with more than just strings</span>\n<span class=\"token string\">\"1, 2, \"</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"1, 2, 3\"</span>\n<span class=\"token string\">\"Hello \"</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"world\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"!\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"Hello world,!\"</span>\n\n<span class=\"token comment\">// and are compared with &lt; and ></span>\n<span class=\"token string\">\"a\"</span> <span class=\"token operator\">&lt;</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n\n<span class=\"token comment\">// Type coercion is performed for comparisons with double equals...</span>\n<span class=\"token string\">\"5\"</span> <span class=\"token operator\">==</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n<span class=\"token keyword\">null</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n\n<span class=\"token comment\">// ...unless you use ===</span>\n<span class=\"token string\">\"5\"</span> <span class=\"token operator\">===</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = false</span>\n<span class=\"token keyword\">null</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = false</span>\n\n<span class=\"token comment\">// ...which can result in some weird behaviour...</span>\n<span class=\"token number\">13</span> <span class=\"token operator\">+</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 14</span>\n<span class=\"token string\">\"13\"</span> <span class=\"token operator\">+</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// '13true'</span>\n\n<span class=\"token comment\">// You can access characters in a string with `charAt`</span>\n<span class=\"token string\">\"This is a string\"</span><span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// = 'T'</span>\n\n<span class=\"token comment\">// ...or use `substring` to get larger pieces.</span>\n<span class=\"token string\">\"Hello world\"</span><span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"Hello\"</span>\n\n<span class=\"token comment\">// `length` is a property, so don't use ().</span>\n<span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 5</span>\n\n<span class=\"token comment\">// There's also `null` and `undefined`.</span>\n<span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>      <span class=\"token comment\">// used to indicate a deliberate non-value</span>\n<span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// used to indicate a value is not currently present (although</span>\n           <span class=\"token comment\">// `undefined` is actually a value itself)</span>\n\n<span class=\"token comment\">// false, null, undefined, NaN, 0 and \"\" are falsy; everything else is truthy.</span>\n<span class=\"token comment\">// Note that 0 is falsy and \"0\" is truthy, even though 0 == \"0\".</span>\n\n<span class=\"token comment\">///////////////////////////////////</span>\n<span class=\"token comment\">// 2. Variables, Arrays and Objects</span>\n\n<span class=\"token comment\">// Variables are declared with the `var` keyword. JavaScript is dynamically</span>\n<span class=\"token comment\">// typed, so you don't need to specify type. Assignment uses a single `=`</span>\n<span class=\"token comment\">// character.</span>\n<span class=\"token keyword\">var</span> someVar <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// If you leave the var keyword off, you won't get an error...</span>\nsomeOtherVar <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// ...but your variable will be created in the global scope, not in the scope</span>\n<span class=\"token comment\">// you defined it in.</span>\n\n<span class=\"token comment\">// Variables declared without being assigned to are set to undefined.</span>\n<span class=\"token keyword\">var</span> someThirdVar<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = undefined</span>\n\n<span class=\"token comment\">// If you want to declare a couple of variables, then you could use a comma</span>\n<span class=\"token comment\">// separator</span>\n<span class=\"token keyword\">var</span> someFourthVar <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> someFifthVar <span class=\"token operator\">=</span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// There's shorthand for performing math operations on variables:</span>\nsomeVar <span class=\"token operator\">+=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// equivalent to someVar = someVar + 5; someVar is 10 now</span>\nsomeVar <span class=\"token operator\">*=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// now someVar is 100</span>\n\n<span class=\"token comment\">// and an even-shorter-hand for adding or subtracting 1</span>\nsomeVar<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// now someVar is 101</span>\nsomeVar<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// back to 100</span>\n\n<span class=\"token comment\">// Arrays are ordered lists of values, of any type.</span>\n<span class=\"token keyword\">var</span> myArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">45</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Their members can be accessed using the square-brackets subscript syntax.</span>\n<span class=\"token comment\">// Array indices start at zero.</span>\nmyArray<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 45</span>\n\n<span class=\"token comment\">// Arrays are mutable and of variable length.</span>\nmyArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"World\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmyArray<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 4</span>\n\n<span class=\"token comment\">// Add/Modify at specific index</span>\nmyArray<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Add and remove element from front or back end of an array</span>\nmyArray<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Add as the first element</span>\nsomeVar <span class=\"token operator\">=</span> myArray<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Remove first element and return it</span>\nmyArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Add as the last element</span>\nsomeVar <span class=\"token operator\">=</span> myArray<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Remove last element and return it</span>\n\n<span class=\"token comment\">// Join all elements of an array with semicolon</span>\n<span class=\"token keyword\">var</span> myArray0 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">32</span><span class=\"token punctuation\">,</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"js\"</span><span class=\"token punctuation\">,</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">56</span><span class=\"token punctuation\">,</span><span class=\"token number\">90</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nmyArray0<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">\";\"</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// = \"32;false;js;12;56;90\"</span>\n\n<span class=\"token comment\">// Get subarray of elements from index 1 (include) to 4 (exclude)</span>\nmyArray0<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = [false,\"js\",12]</span>\n\n<span class=\"token comment\">// Remove 4 elements starting from index 2, and insert there strings</span>\n<span class=\"token comment\">// \"hi\",\"wr\" and \"ld\"; return removed subarray</span>\nmyArray0<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"hi\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"wr\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"ld\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = [\"js\",12,56,90]</span>\n<span class=\"token comment\">// myArray0 === [32,false,\"hi\",\"wr\",\"ld\"]</span>\n\n<span class=\"token comment\">// JavaScript's objects are equivalent to \"dictionaries\" or \"maps\" in other</span>\n<span class=\"token comment\">// languages: an unordered collection of key-value pairs.</span>\n<span class=\"token keyword\">var</span> myObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">key1</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">key2</span><span class=\"token operator\">:</span> <span class=\"token string\">\"World\"</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Keys are strings, but quotes aren't required if they're a valid</span>\n<span class=\"token comment\">// JavaScript identifier. Values can be any type.</span>\n<span class=\"token keyword\">var</span> myObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">myKey</span><span class=\"token operator\">:</span> <span class=\"token string\">\"myValue\"</span><span class=\"token punctuation\">,</span> <span class=\"token string-property property\">\"my other key\"</span><span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Object attributes can also be accessed using the subscript syntax,</span>\nmyObj<span class=\"token punctuation\">[</span><span class=\"token string\">\"my other key\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 4</span>\n\n<span class=\"token comment\">// ... or using the dot syntax, provided the key is a valid identifier.</span>\nmyObj<span class=\"token punctuation\">.</span>myKey<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"myValue\"</span>\n\n<span class=\"token comment\">// Objects are mutable; values can be changed and new keys added.</span>\nmyObj<span class=\"token punctuation\">.</span>myThirdKey <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// If you try to access a value that's not yet set, you'll get undefined.</span>\nmyObj<span class=\"token punctuation\">.</span>myFourthKey<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = undefined</span>\n\n<span class=\"token comment\">///////////////////////////////////</span>\n<span class=\"token comment\">// 3. Logic and Control Structures</span>\n\n<span class=\"token comment\">// The `if` structure works as you'd expect.</span>\n<span class=\"token keyword\">var</span> count <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// evaluated if count is 3</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">==</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// evaluated if count is 4</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// evaluated if it's not either 3 or 4</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// As does `while`.</span>\n<span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// An infinite loop!</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Do-while loops are like while loops, except they always run at least once.</span>\n<span class=\"token keyword\">var</span> input<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">do</span> <span class=\"token punctuation\">{</span>\n    input <span class=\"token operator\">=</span> <span class=\"token function\">getInput</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">isValid</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// The `for` loop is the same as C and Java:</span>\n<span class=\"token comment\">// initialization; continue condition; iteration.</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// will run 5 times</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Breaking out of labeled loops is similar to Java</span>\n<span class=\"token literal-property property\">outer</span><span class=\"token operator\">:</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">==</span> <span class=\"token number\">5</span> <span class=\"token operator\">&amp;&amp;</span> j <span class=\"token operator\">==</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">break</span> outer<span class=\"token punctuation\">;</span>\n            <span class=\"token comment\">// breaks out of outer loop instead of only the inner one</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// The for/in statement allows iteration over properties of an object.</span>\n<span class=\"token keyword\">var</span> description <span class=\"token operator\">=</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">fname</span><span class=\"token operator\">:</span><span class=\"token string\">\"Paul\"</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lname</span><span class=\"token operator\">:</span><span class=\"token string\">\"Ken\"</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span><span class=\"token number\">18</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> x <span class=\"token keyword\">in</span> person<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    description <span class=\"token operator\">+=</span> person<span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token string\">\" \"</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token comment\">// description = 'Paul Ken 18 '</span>\n\n<span class=\"token comment\">// The for/of statement allows iteration over iterable objects (including the built-in String,</span>\n<span class=\"token comment\">// Array, e.g. the Array-like arguments or NodeList objects, TypedArray, Map and Set,</span>\n<span class=\"token comment\">// and user-defined iterables).</span>\n<span class=\"token keyword\">var</span> myPets <span class=\"token operator\">=</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> pets <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"cat\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"dog\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hamster\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hedgehog\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> pet <span class=\"token keyword\">of</span> pets<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    myPets <span class=\"token operator\">+=</span> pet <span class=\"token operator\">+</span> <span class=\"token string\">\" \"</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token comment\">// myPets = 'cat dog hamster hedgehog '</span>\n\n<span class=\"token comment\">// &amp;&amp; is logical and, || is logical or</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>house<span class=\"token punctuation\">.</span>size <span class=\"token operator\">==</span> <span class=\"token string\">\"big\"</span> <span class=\"token operator\">&amp;&amp;</span> house<span class=\"token punctuation\">.</span>colour <span class=\"token operator\">==</span> <span class=\"token string\">\"blue\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    house<span class=\"token punctuation\">.</span>contains <span class=\"token operator\">=</span> <span class=\"token string\">\"bear\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>colour <span class=\"token operator\">==</span> <span class=\"token string\">\"red\"</span> <span class=\"token operator\">||</span> colour <span class=\"token operator\">==</span> <span class=\"token string\">\"blue\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// colour is either red or blue</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// &amp;&amp; and || \"short circuit\", which is useful for setting default values.</span>\n<span class=\"token keyword\">var</span> name <span class=\"token operator\">=</span> otherName <span class=\"token operator\">||</span> <span class=\"token string\">\"default\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// The `switch` statement checks for equality with `===`.</span>\n<span class=\"token comment\">// Use 'break' after each case</span>\n<span class=\"token comment\">// or the cases after the correct one will be executed too.</span>\ngrade <span class=\"token operator\">=</span> <span class=\"token string\">'B'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>grade<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">case</span> <span class=\"token string\">'A'</span><span class=\"token operator\">:</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Great job\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">case</span> <span class=\"token string\">'B'</span><span class=\"token operator\">:</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"OK job\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">case</span> <span class=\"token string\">'C'</span><span class=\"token operator\">:</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"You can do better\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Oy vey\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">///////////////////////////////////</span>\n<span class=\"token comment\">// 4. Functions, Scope and Closures</span>\n\n<span class=\"token comment\">// JavaScript functions are declared with the `function` keyword.</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">thing</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> thing<span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"foo\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"FOO\"</span>\n\n<span class=\"token comment\">// Note that the value to be returned must start on the same line as the</span>\n<span class=\"token comment\">// `return` keyword, otherwise you'll always return `undefined` due to</span>\n<span class=\"token comment\">// automatic semicolon insertion. Watch out for this when using Allman style.</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token comment\">// &lt;- semicolon automatically inserted here</span>\n    <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">thisIsAn</span><span class=\"token operator\">:</span> <span class=\"token string\">'object literal'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = undefined</span>\n\n<span class=\"token comment\">// JavaScript functions are first class objects, so they can be reassigned to</span>\n<span class=\"token comment\">// different variable names and passed to other functions as arguments - for</span>\n<span class=\"token comment\">// example, when supplying an event handler:</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// this code will be called in 5 seconds' time</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>myFunction<span class=\"token punctuation\">,</span> <span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Note: setTimeout isn't part of the JS language, but is provided by browsers</span>\n<span class=\"token comment\">// and Node.js.</span>\n\n<span class=\"token comment\">// Another function provided by browsers is setInterval</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// this code will be called every 5 seconds</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span>myFunction<span class=\"token punctuation\">,</span> <span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Function objects don't even have to be declared with a name - you can write</span>\n<span class=\"token comment\">// an anonymous function definition directly into the arguments of another.</span>\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// this code will be called in 5 seconds' time</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// JavaScript has function scope; functions get their own scope but other blocks</span>\n<span class=\"token comment\">// do not.</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\ni<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 5 - not undefined as you'd expect in a block-scoped language</span>\n\n<span class=\"token comment\">// This has led to a common pattern of \"immediately-executing anonymous</span>\n<span class=\"token comment\">// functions\", which prevent temporary variables from leaking into the global</span>\n<span class=\"token comment\">// scope.</span>\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> temporary <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// We can access the global scope by assigning to the \"global object\", which</span>\n    <span class=\"token comment\">// in a web browser is always `window`. The global object may have a</span>\n    <span class=\"token comment\">// different name in non-browser environments such as Node.js.</span>\n    window<span class=\"token punctuation\">.</span>permanent <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ntemporary<span class=\"token punctuation\">;</span> <span class=\"token comment\">// raises ReferenceError</span>\npermanent<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 10</span>\n\n<span class=\"token comment\">// One of JavaScript's most powerful features is closures. If a function is</span>\n<span class=\"token comment\">// defined inside another function, the inner function has access to all the</span>\n<span class=\"token comment\">// outer function's variables, even after the outer function exits.</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">sayHelloInFiveSeconds</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> prompt <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello, \"</span> <span class=\"token operator\">+</span> name <span class=\"token operator\">+</span> <span class=\"token string\">\"!\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Inner functions are put in the local scope by default, as if they were</span>\n    <span class=\"token comment\">// declared with `var`.</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>prompt<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>inner<span class=\"token punctuation\">,</span> <span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// setTimeout is asynchronous, so the sayHelloInFiveSeconds function will</span>\n    <span class=\"token comment\">// exit immediately, and setTimeout will call inner afterwards. However,</span>\n    <span class=\"token comment\">// because inner is \"closed over\" sayHelloInFiveSeconds, inner still has</span>\n    <span class=\"token comment\">// access to the `prompt` variable when it is finally called.</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">sayHelloInFiveSeconds</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Adam\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// will open a popup with \"Hello, Adam!\" in 5s</span>\n\n<span class=\"token comment\">///////////////////////////////////</span>\n<span class=\"token comment\">// 5. More about Objects; Constructors and Prototypes</span>\n\n<span class=\"token comment\">// Objects can contain functions.</span>\n<span class=\"token keyword\">var</span> myObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">myFunc</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">\"Hello world!\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nmyObj<span class=\"token punctuation\">.</span><span class=\"token function\">myFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"Hello world!\"</span>\n\n<span class=\"token comment\">// When functions attached to an object are called, they can access the object</span>\n<span class=\"token comment\">// they're attached to using the `this` keyword.</span>\nmyObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">myString</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Hello world!\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">myFunc</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myString<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nmyObj<span class=\"token punctuation\">.</span><span class=\"token function\">myFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"Hello world!\"</span>\n\n<span class=\"token comment\">// What this is set to has to do with how the function is called, not where</span>\n<span class=\"token comment\">// it's defined. So, our function doesn't work if it isn't called in the</span>\n<span class=\"token comment\">// context of the object.</span>\n<span class=\"token keyword\">var</span> myFunc <span class=\"token operator\">=</span> myObj<span class=\"token punctuation\">.</span>myFunc<span class=\"token punctuation\">;</span>\n<span class=\"token function\">myFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = undefined</span>\n\n<span class=\"token comment\">// Inversely, a function can be assigned to the object and gain access to it</span>\n<span class=\"token comment\">// through `this`, even if it wasn't attached when it was defined.</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">myOtherFunc</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myString<span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nmyObj<span class=\"token punctuation\">.</span>myOtherFunc <span class=\"token operator\">=</span> myOtherFunc<span class=\"token punctuation\">;</span>\nmyObj<span class=\"token punctuation\">.</span><span class=\"token function\">myOtherFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"HELLO WORLD!\"</span>\n\n<span class=\"token comment\">// We can also specify a context for a function to execute in when we invoke it</span>\n<span class=\"token comment\">// using `call` or `apply`.</span>\n\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">anotherFunc</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myString <span class=\"token operator\">+</span> s<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">anotherFunc</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>myObj<span class=\"token punctuation\">,</span> <span class=\"token string\">\" And Hello Moon!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"Hello World! And Hello Moon!\"</span>\n\n<span class=\"token comment\">// The `apply` function is nearly identical, but takes an array for an argument</span>\n<span class=\"token comment\">// list.</span>\n\n<span class=\"token function\">anotherFunc</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>myObj<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\" And Hello Sun!\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"Hello World! And Hello Sun!\"</span>\n\n<span class=\"token comment\">// This is useful when working with a function that accepts a sequence of</span>\n<span class=\"token comment\">// arguments and you want to pass an array.</span>\n\nMath<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">27</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 6</span>\nMath<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">27</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = NaN (uh-oh!)</span>\nMath<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">27</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 6</span>\n\n<span class=\"token comment\">// But, `call` and `apply` are only temporary. When we want it to stick, we can</span>\n<span class=\"token comment\">// use `bind`.</span>\n\n<span class=\"token keyword\">var</span> boundFunc <span class=\"token operator\">=</span> <span class=\"token function\">anotherFunc</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>myObj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">boundFunc</span><span class=\"token punctuation\">(</span><span class=\"token string\">\" And Hello Saturn!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"Hello World! And Hello Saturn!\"</span>\n\n<span class=\"token comment\">// `bind` can also be used to partially apply (curry) a function.</span>\n\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">product</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span> <span class=\"token keyword\">return</span> a <span class=\"token operator\">*</span> b<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> doubler <span class=\"token operator\">=</span> <span class=\"token function\">product</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">doubler</span><span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 16</span>\n\n<span class=\"token comment\">// When you call a function with the `new` keyword, a new object is created, and</span>\n<span class=\"token comment\">// made available to the function via the `this` keyword. Functions designed to be</span>\n<span class=\"token comment\">// called like that are called constructors.</span>\n\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">MyConstructor</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myNumber <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nmyNewObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">MyConstructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = {myNumber: 5}</span>\nmyNewObj<span class=\"token punctuation\">.</span>myNumber<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 5</span>\n\n<span class=\"token comment\">// Unlike most other popular object-oriented languages, JavaScript has no</span>\n<span class=\"token comment\">// concept of 'instances' created from 'class' blueprints; instead, JavaScript</span>\n<span class=\"token comment\">// combines instantiation and inheritance into a single concept: a 'prototype'.</span>\n\n<span class=\"token comment\">// Every JavaScript object has a 'prototype'. When you go to access a property</span>\n<span class=\"token comment\">// on an object that doesn't exist on the actual object, the interpreter will</span>\n<span class=\"token comment\">// look at its prototype.</span>\n\n<span class=\"token comment\">// Some JS implementations let you access an object's prototype on the magic</span>\n<span class=\"token comment\">// property `__proto__`. While this is useful for explaining prototypes it's not</span>\n<span class=\"token comment\">// part of the standard; we'll get to standard ways of using prototypes later.</span>\n<span class=\"token keyword\">var</span> myObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">myString</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Hello world!\"</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> myPrototype <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">meaningOfLife</span><span class=\"token operator\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">myFunc</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myString<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nmyObj<span class=\"token punctuation\">.</span>__proto__ <span class=\"token operator\">=</span> myPrototype<span class=\"token punctuation\">;</span>\nmyObj<span class=\"token punctuation\">.</span>meaningOfLife<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 42</span>\n\n<span class=\"token comment\">// This works for functions, too.</span>\nmyObj<span class=\"token punctuation\">.</span><span class=\"token function\">myFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"hello world!\"</span>\n\n<span class=\"token comment\">// Of course, if your property isn't on your prototype, the prototype's</span>\n<span class=\"token comment\">// prototype is searched, and so on.</span>\nmyPrototype<span class=\"token punctuation\">.</span>__proto__ <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">myBoolean</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nmyObj<span class=\"token punctuation\">.</span>myBoolean<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n\n<span class=\"token comment\">// There's no copying involved here; each object stores a reference to its</span>\n<span class=\"token comment\">// prototype. This means we can alter the prototype and our changes will be</span>\n<span class=\"token comment\">// reflected everywhere.</span>\nmyPrototype<span class=\"token punctuation\">.</span>meaningOfLife <span class=\"token operator\">=</span> <span class=\"token number\">43</span><span class=\"token punctuation\">;</span>\nmyObj<span class=\"token punctuation\">.</span>meaningOfLife<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 43</span>\n\n<span class=\"token comment\">// The for/in statement allows iteration over properties of an object,</span>\n<span class=\"token comment\">// walking up the prototype chain until it sees a null prototype.</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> x <span class=\"token keyword\">in</span> myObj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myObj<span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">///prints:</span>\n<span class=\"token comment\">// Hello world!</span>\n<span class=\"token comment\">// 43</span>\n<span class=\"token comment\">// [Function: myFunc]</span>\n<span class=\"token comment\">// true</span>\n\n<span class=\"token comment\">// To only consider properties attached to the object itself</span>\n<span class=\"token comment\">// and not its prototypes, use the `hasOwnProperty()` check.</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> x <span class=\"token keyword\">in</span> myObj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>myObj<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myObj<span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">///prints:</span>\n<span class=\"token comment\">// Hello world!</span>\n\n<span class=\"token comment\">// We mentioned that `__proto__` was non-standard, and there's no standard way to</span>\n<span class=\"token comment\">// change the prototype of an existing object. However, there are two ways to</span>\n<span class=\"token comment\">// create a new object with a given prototype.</span>\n\n<span class=\"token comment\">// The first is Object.create, which is a recent addition to JS, and therefore</span>\n<span class=\"token comment\">// not available in all implementations yet.</span>\n<span class=\"token keyword\">var</span> myObj <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>myPrototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmyObj<span class=\"token punctuation\">.</span>meaningOfLife<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 43</span>\n\n<span class=\"token comment\">// The second way, which works anywhere, has to do with constructors.</span>\n<span class=\"token comment\">// Constructors have a property called prototype. This is *not* the prototype of</span>\n<span class=\"token comment\">// the constructor function itself; instead, it's the prototype that new objects</span>\n<span class=\"token comment\">// are given when they're created with that constructor and the new keyword.</span>\n<span class=\"token class-name\">MyConstructor</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">myNumber</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getMyNumber</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myNumber<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> myNewObj2 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">MyConstructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmyNewObj2<span class=\"token punctuation\">.</span><span class=\"token function\">getMyNumber</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 5</span>\nmyNewObj2<span class=\"token punctuation\">.</span>myNumber <span class=\"token operator\">=</span> <span class=\"token number\">6</span><span class=\"token punctuation\">;</span>\nmyNewObj2<span class=\"token punctuation\">.</span><span class=\"token function\">getMyNumber</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 6</span>\n\n<span class=\"token comment\">// Built-in types like strings and numbers also have constructors that create</span>\n<span class=\"token comment\">// equivalent wrapper objects.</span>\n<span class=\"token keyword\">var</span> myNumber <span class=\"token operator\">=</span> <span class=\"token number\">12</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> myNumberObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">(</span><span class=\"token number\">12</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmyNumber <span class=\"token operator\">==</span> myNumberObj<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = true</span>\n\n<span class=\"token comment\">// Except, they aren't exactly equivalent.</span>\n<span class=\"token keyword\">typeof</span> myNumber<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 'number'</span>\n<span class=\"token keyword\">typeof</span> myNumberObj<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = 'object'</span>\nmyNumber <span class=\"token operator\">===</span> myNumberObj<span class=\"token punctuation\">;</span> <span class=\"token comment\">// = false</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// This code won't execute, because 0 is falsy.</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n   <span class=\"token comment\">// This code will execute, because wrapped numbers are objects, and objects</span>\n   <span class=\"token comment\">// are always truthy.</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// However, the wrapper objects and the regular builtins share a prototype, so</span>\n<span class=\"token comment\">// you can actually add functionality to a string, for instance.</span>\n<span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">firstCharacter</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">.</span><span class=\"token function\">firstCharacter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// = \"a\"</span>\n\n<span class=\"token comment\">// This fact is often used in \"polyfilling\", which is implementing newer</span>\n<span class=\"token comment\">// features of JavaScript in an older subset of JavaScript, so that they can be</span>\n<span class=\"token comment\">// used in older environments such as outdated browsers.</span>\n\n<span class=\"token comment\">// For instance, we mentioned that Object.create isn't yet available in all</span>\n<span class=\"token comment\">// implementations, but we can still use it with this polyfill:</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span>create <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span> <span class=\"token comment\">// don't overwrite it if it exists</span>\n    Object<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">create</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">proto</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// make a temporary constructor with the right prototype</span>\n        <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">Constructor</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token class-name\">Constructor</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> proto<span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// then use it to create a new, appropriately-prototyped object</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * GLOBAL OBJECTS > OBJECT\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Global object: properties</span>\nObject<span class=\"token punctuation\">.</span>length                                        <span class=\"token comment\">// length is a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters. This number does not include the rest parameter. Has a value of 1.</span>\n<span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype                                     <span class=\"token comment\">// Represents the Object prototype object and allows to add new properties and methods to all objects of type Object.</span>\n\n<span class=\"token comment\">// Methods of the Object constructor</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">assign</span><span class=\"token punctuation\">(</span>target<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>sources<span class=\"token punctuation\">)</span>                    <span class=\"token comment\">// Copies the values of all enumerable own properties from one or more source objects to a target object. method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>MyObject<span class=\"token punctuation\">)</span>                              <span class=\"token comment\">// Creates a new object with the specified prototype object and properties. The object which should be the prototype of the newly-created object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">,</span> prop<span class=\"token punctuation\">,</span> descriptor<span class=\"token punctuation\">)</span>         <span class=\"token comment\">// Adds the named property described by a given descriptor to an object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperties</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">,</span> props<span class=\"token punctuation\">)</span>                  <span class=\"token comment\">// Adds the named properties described by the given descriptors to an object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                                  <span class=\"token comment\">// Returns an array containing all of the [key, value] pairs of a given object's own enumerable string properties.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">freeze</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                                   <span class=\"token comment\">// Freezes an object: other code can't delete or change any properties.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertyDescriptor</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">,</span> prop<span class=\"token punctuation\">)</span>           <span class=\"token comment\">// Returns a property descriptor for a named property on an object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertyDescriptors</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                <span class=\"token comment\">// Returns an object containing all own property descriptors for an object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertyNames</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                      <span class=\"token comment\">// Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertySymbols</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                    <span class=\"token comment\">// Returns an array of all symbol properties found directly upon a given object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">getPrototypeOf</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                           <span class=\"token comment\">// Returns the prototype of the specified object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">is</span><span class=\"token punctuation\">(</span>value1<span class=\"token punctuation\">,</span> value2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                           <span class=\"token comment\">// Compares if two values are the same value. Equates all NaN values (which differs from both Abstract Equality Comparison and Strict Equality Comparison).</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">isExtensible</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                             <span class=\"token comment\">// Determines if extending of an object is allowed.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">isFrozen</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                                 <span class=\"token comment\">// Determines if an object was frozen.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">isSealed</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                                 <span class=\"token comment\">// Determines if an object is sealed.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                                     <span class=\"token comment\">// Returns an array containing the names of all of the given object's own enumerable string properties.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">preventExtensions</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                        <span class=\"token comment\">// Prevents any extensions of an object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">seal</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                                     <span class=\"token comment\">// Prevents other code from deleting properties of an object.</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">setPrototypeOf</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">,</span> prototype<span class=\"token punctuation\">)</span>                <span class=\"token comment\">// Sets the prototype (i.e., the internal [[Prototype]] property).</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                                   <span class=\"token comment\">// Returns an array containing the values that correspond to all of a given object's own enumerable string properties.</span>\n\n<span class=\"token comment\">// Object instances and Object prototype object (Object.prototype.property or Object.prototype.method())</span>\n<span class=\"token comment\">// Properties</span>\nobj<span class=\"token punctuation\">.</span>constructor                                      <span class=\"token comment\">// Specifies the function that creates an object's prototype.</span>\nobj<span class=\"token punctuation\">.</span>__proto__                                        <span class=\"token comment\">// Points to the object which was used as prototype when the object was instantiated.</span>\n\n<span class=\"token comment\">// Methods</span>\nobj<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>prop<span class=\"token punctuation\">)</span>                             <span class=\"token comment\">// Returns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain.</span>\nprototypeObj<span class=\"token punctuation\">.</span><span class=\"token function\">isPrototypeOf</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span>                   <span class=\"token comment\">// Returns a boolean indicating whether the object this method is called upon is in the prototype chain of the specified object.</span>\nobj<span class=\"token punctuation\">.</span><span class=\"token function\">propertyIsEnumerable</span><span class=\"token punctuation\">(</span>prop<span class=\"token punctuation\">)</span>                       <span class=\"token comment\">// Returns a boolean indicating if the internal ECMAScript [[Enumerable]] attribute is set.</span>\nobj<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                 <span class=\"token comment\">// Calls toString().</span>\nobj<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                       <span class=\"token comment\">// Returns a string representation of the object.</span>\nobject<span class=\"token punctuation\">.</span><span class=\"token function\">valueOf</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                     <span class=\"token comment\">// Returns the primitive value of the specified object.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * GLOBAL OBJECTS > ARRAY\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Global object: properties</span>\nArray<span class=\"token punctuation\">.</span>length                                         <span class=\"token comment\">// Reflects the number of elements in an array.</span>\n<span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype                                      <span class=\"token comment\">// Represents the prototype for the Array constructor and allows to add new properties and methods to all Array objects.</span>\n\n<span class=\"token comment\">// Global object: methods</span>\nArray<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span>arrayLike<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> mapFn<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> thisArg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>            <span class=\"token comment\">// Creates a new Array instance from an array-like or iterable object.</span>\nArray<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span>                                   <span class=\"token comment\">// Returns true if a variable is an array, if not false.</span>\nArray<span class=\"token punctuation\">.</span><span class=\"token function\">of</span><span class=\"token punctuation\">(</span>element0<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> element1<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> elementN<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>    <span class=\"token comment\">// Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments.</span>\n\n<span class=\"token comment\">// Instance: properties</span>\narr<span class=\"token punctuation\">.</span>length                                           <span class=\"token comment\">// Reflects the number of elements in an array.</span>\n\n<span class=\"token comment\">// Instance: mutator methods</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">copyWithin</span><span class=\"token punctuation\">(</span>target<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span>                   <span class=\"token comment\">// Copies a sequence of array elements within the array.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">fill</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span>                          <span class=\"token comment\">// Fills all the elements of an array from a start index to an end index with a static value.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                            <span class=\"token comment\">// Removes the last element from an array and returns that element.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>element1<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> elementN<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>              <span class=\"token comment\">// Adds one or more elements to the end of an array and returns the new length of the array.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                        <span class=\"token comment\">// Reverses the order of the elements of an array in place — the first becomes the last, and the last becomes the first.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                          <span class=\"token comment\">// Removes the first element from an array and returns that element.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                           <span class=\"token comment\">// Sorts the elements of an array in place and returns the array.</span>\narray<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> deleteCount<span class=\"token punctuation\">,</span> item1<span class=\"token punctuation\">,</span> item2<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\">// Adds and/or removes elements from an array.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>element1<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> elementN<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>           <span class=\"token comment\">// Adds one or more elements to the front of an array and returns the new length of the array.</span>\n\n<span class=\"token comment\">// Instance: accessor methods</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>value1<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> value2<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> valueN<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>        <span class=\"token comment\">// Returns a new array comprised of this array joined with other array(s) and/or value(s).</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span>searchElement<span class=\"token punctuation\">,</span> fromIndex<span class=\"token punctuation\">)</span>               <span class=\"token comment\">// Determines whether an array contains a certain element, returning true or false as appropriate.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>searchElement<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> fromIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>              <span class=\"token comment\">// Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>separator<span class=\"token punctuation\">)</span>                                  <span class=\"token comment\">// Joins all elements of an array into a string.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">lastIndexOf</span><span class=\"token punctuation\">(</span>searchElement<span class=\"token punctuation\">,</span> fromIndex<span class=\"token punctuation\">)</span>            <span class=\"token comment\">// Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>begin<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span>                                <span class=\"token comment\">// Extracts a section of an array and returns a new array.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                       <span class=\"token comment\">// Returns a string representing the array and its elements. Overrides the Object.prototype.toString() method.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleString</span><span class=\"token punctuation\">(</span>locales<span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">)</span>                 <span class=\"token comment\">// Returns a localized string representing the array and its elements. Overrides the Object.prototype.toLocaleString() method.</span>\n\n<span class=\"token comment\">// Instance: iteration methods</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                        <span class=\"token comment\">// Returns a new Array Iterator object that contains the key/value pairs for each index in the array.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">every</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> thisArg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>                       <span class=\"token comment\">// Returns true if every element in this array satisfies the provided testing function.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> thisArg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>                      <span class=\"token comment\">// Creates a new array with all of the elements of this array for which the provided filtering function returns true.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> thisArg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>                        <span class=\"token comment\">// Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">findIndex</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> thisArg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>                   <span class=\"token comment\">// Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> thisArg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>                     <span class=\"token comment\">// Calls a function for each element in the array.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                           <span class=\"token comment\">// Returns a new Array Iterator that contains the keys for each index in the array.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> initialValue<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>                    <span class=\"token comment\">// Creates a new array with the results of calling a provided function on every element in this array.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> initialValue<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>                 <span class=\"token comment\">// Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">reduceRight</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> initialValue<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>            <span class=\"token comment\">// Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">some</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> initialValue<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>                   <span class=\"token comment\">// Returns true if at least one element in this array satisfies the provided testing function.</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>                                         <span class=\"token comment\">// Returns a new Array Iterator object that contains the values for each index in the array.</span></code></pre></div>\n</details>\n<hr>\n<h1>Fundamental Javascript Concepts You Should Understand</h1>\n<p>Plain Old JS Object Lesson Concepts</p>\n<hr>\n<h3>Fundamental Javascript Concepts You Should Understand</h3>\n<h3>Plain Old JS Object Lesson Concepts</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*bEuahctJRS_qCQgV.jpg\" class=\"graf-image\" />\n</figure>- <span id=\"d911\">Label variables as either Primitive vs. Reference</span>\n- <span id=\"42a0\">primitives: strings, booleans, numbers, null and undefined</span>\n- <span id=\"4423\">primitives are immutable</span>\n- <span id=\"fd1a\">refereces: objects (including arrays)</span>\n- <span id=\"d581\">references are mutable</span>\n- <span id=\"65e2\">Identify when to use `.` vs `[]` when accessing values of an object</span>\n- <span id=\"eb9d\">dot syntax `object.key`</span>\n- <span id=\"8e03\">easier to read</span>\n- <span id=\"1662\">easier to write</span>\n- <span id=\"5796\">cannot use variables as keys</span>\n- <span id=\"588a\">keys cannot begin with a number</span>\n- <span id=\"5501\">bracket notation `object[\"key]`</span>\n- <span id=\"5734\">allows variables as keys</span>\n- <span id=\"76ca\">strings that start with numbers can be use as keys</span>\n- <span id=\"822a\">Write an object literal with a variable key using interpolation</span>\n<h4>put it in brackets to access the value of the variable, rather than just make the value that string</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> a <span class=\"token operator\">=</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token string\">\"letter_a\"</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token string\">\"letter b\"</span>\n        <span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li><span id=\"e4fc\">Use the <code class=\"language-text\">obj[key] !== undefined</code> pattern to check if a given variable that contains a key exists in an object</span></li>\n<li><span id=\"0baa\">can also use <code class=\"language-text\">(key in object)</code> syntax interchangeably (returns a boolean)</span></li>\n<li><span id=\"ad4c\">Utilize Object.keys and Object.values in a function</span></li>\n<li><span id=\"b548\"><code class=\"language-text\">Object.keys(obj)</code> returns an array of all the keys in <code class=\"language-text\">obj</code></span></li>\n<li><span id=\"f39b\"><code class=\"language-text\">Object.values(obj)</code> returns an array of the values in <code class=\"language-text\">obj</code></span></li>\n</ul>\n<h4>Iterate through an object using a <code class=\"language-text\">for in</code> loop</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> <span class=\"token function-variable function\">printValues</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">obj</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> key <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n              <span class=\"token keyword\">let</span> value <span class=\"token operator\">=</span> obj<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n              console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">}</span></code></pre></div>\n<h4>Define a function that utilizes <code class=\"language-text\">...rest</code> syntax to accept an arbitrary number of arguments</h4>\n<ul>\n<li><span id=\"58a5\"><code class=\"language-text\">...rest</code> syntax will store all additional arguments in an array</span></li>\n<li><span id=\"5f8b\">array will be empty if there are no additional arguments</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myFunction = function(str, ...strs) {\n        console.log(\"The first string is \" + str);\n        console.log(\"The rest of the strings are:\");\n        strs.forEach(function(str) {\n            console.log(str);\n        })\n    }</code></pre></div>\n<h4>Use <code class=\"language-text\">...spread</code> syntax for Object literals and Array literals</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> arr1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">let</span> longer <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>arr1<span class=\"token punctuation\">,</span> <span class=\"token string\">\"d\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"e\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [\"a\", \"b\", \"c\", \"d\", \"e\"]</span>\n      <span class=\"token comment\">// without spread syntax, this would give you a nested array</span>\n      <span class=\"token keyword\">let</span> withoutRest <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>arr1<span class=\"token punctuation\">,</span> <span class=\"token string\">\"d\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"e\"</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">// [[\"a\", \"b\", \"c\"], \"d\", \"e\"]</span></code></pre></div>\n<ul>\n<li><span id=\"118b\">Destructure an array to reference specific elements</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let array = [35, 9];\n\nlet [firstEl, secondEl] = array;\n\nconsole.log(firstEl); // => 35\n\nconsole.log(secondEl); // => 9\n\n// can also destructure using … syntax let array = [35, 9, 14]; let [head, …tail] = array; console.log(head); // => 35 console.log(tail); // => [9, 14]\n\n-Destructure an object to reference specific values\n    -\n    if you want to use variable names that don 't match the keys, you can use aliasing -\n    `let { oldkeyname: newkeyname } = object` -\n    rule of thumb— only destructure values from objects that are two levels deep ``\n`javascript\nlet obj = {\n   name: \"Wilfred\",\n   appearance: [\"short\", \"mustache\"],\n   favorites: {\n      color: \"mauve\",\n      food: \"spaghetti squash\",\n      number: 3\n   }\n}\n// with variable names that match keys\nlet { name, appearance } = obj;\nconsole.log(name); // \"Wilfred\"\nconsole.log(appearance); // [\"short\", \"mustache\"]\n\n// with new variable names (aliasing)\nlet {name: myName, appearance: myAppearance} = obj;\n\nconsole.log(myName); // \"Wilfred\"\nconsole.log(myAppearance); // [\"short\", \"mustache\"]\n\n// in a function call\nlet sayHello = function({name}) {\nconsole.log(\"Hello, \" + name); // \"Hello Wilfred\"\n}\n\n// nested objects + aliasing\nlet { favorites: {color, food: vegetable} } = obj;\nconsole.log(color, vegetable); //=> mauve spaghetti squash</code></pre></div>\n<h4>Write a function that accepts a array as an argument and returns an object representing the count of each character in the array</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//\n  let elementCounts = function(array) {\n      let obj = {};\n      array.forEach(function(el) {\n          if (el in obj) obj[el] += 1;\n          else obj[el] = 1;\n      })\n      return obj;\n  }\n  console.log(elementCounts([\"e\", \"f\", \"g\", \"f\"])); // => Object {e: 1, f: 2, g: 1}</code></pre></div>\n<h3>Callbacks Lesson Concepts</h3>\n<ul>\n<li><span id=\"a16e\">Given multiple plausible reasons, identify why functions are called \"First Class Objects\" in JavaScript.</span></li>\n<li><span id=\"0d89\">they can be stored in variables, passed as arguments to other functions, and serve as return value for a function</span></li>\n<li><span id=\"e458\">supports same basic operations as other types (strings, bools, numbers)</span></li>\n<li><span id=\"6af2\">higher-order functions take functions as arguments or return functions as values</span></li>\n<li><span id=\"adbe\">Given a code snippet containing an anonymous callback, a named callback, and multiple <code class=\"language-text\">console.log</code>s, predict what will be printed</span></li>\n<li><span id=\"e93b\">what is this referring to?</span></li>\n<li><span id=\"c73f\">Write a function that takes in a value and two callbacks. The function should return the result of the callback that is greater.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let greaterCB = function(val, callback1, callback2) {\n    if (callback1(val) > callback2(val)) {\n        return callback1(val);\n    }\n    return callback2(val);\n}\n\nlet greaterCB = function(val, callback1, callback2) {\n    if (callback1(val) > callback2(val)) {\n        return callback1(val);\n    }\n    return callback2(val);\n}</code></pre></div>\n<p>// shorter version let greaterCB = function(val, callback1, callback2) { return Math.max(callback1(val), callback2(val)); } // even shorter, cause why not let greaterCB = (val, cb1, cb2) => Math.max(cb1(val), cb2(val));</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">-Write a\nfunction, myMap, that takes in an array and a callback as arguments.The\nfunction should mimic the behavior of `Array#map`.\n``\n`javascript\nlet myMap = function(array, callback) {\n   let newArr = [];\n   for (let i = 0; i &lt; array.length; i ++) {\n      mapped = callback(array[i], i, array);\n      newArr.push(mapped);\n   }\n   return newArr;\n}\nconsole.log( myMap([16,25,36], Math.sqrt)); // => [4, 5, 6];\n\nlet myMapArrow = (array, callback) => {\n   let newArr = [];\n   array.forEach( (ele, ind, array) => {\n      newArr.push(callback(ele, ind, array));\n   })\n   return newArr;\n}\nconsole.log(myMapArrow([16,25,36], Math.sqrt)); // => [4, 5, 6];</code></pre></div>\n<h4>Write a function, myFilter, that takes in an array and a callback as arguments. The function should mimic the behavior of <code class=\"language-text\">Array#filter</code></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myFilter = function(array, callback) {\n      let filtered = [];\n      for (let i = 0; i &lt; array.length; i++) {\n          if (callback(array[i])) {\n              filtered.push(array[i], i, array);\n          }\n      }\n  }</code></pre></div>\n<h4>Write a function, myEvery, that takes in an array and a callback as arguments. The function should mimic the behavior of <code class=\"language-text\">Array#every</code></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myEvery = function(array, callback) {\n      for (let i = 0; i &lt; array.length; i++) {\n          if (!callback(array[i], i, array)) {\n              return false\n          }\n      }\n      return true;\n  }\n  // with arrow function syntax\n  let myEvery = (array, callback) => {\n      for (let i = 0; i &lt; array.length; i++) {\n          if (!callback(array[i])) {\n              return false\n          }\n      }\n      return true;\n  }</code></pre></div>\n<h3>Scope Lesson Concepts</h3>\n<ul>\n<li><span id=\"685f\">Identify the difference between <code class=\"language-text\">const</code>, <code class=\"language-text\">let</code>, and <code class=\"language-text\">var</code> declarations</span></li>\n<li><span id=\"7308\"><code class=\"language-text\">const</code> - cannot reassign variable, scoped to block</span></li>\n<li><span id=\"e07f\"><code class=\"language-text\">let</code> - can reassign variable, scoped to block</span></li>\n<li><span id=\"670d\"><code class=\"language-text\">var</code> - outdated, may or may not be reassigned, scoped to function. can be not just reassigned, but also redeclared!</span></li>\n<li><span id=\"b254\">a variable will always evaluate to the value it contains regardless of how it was declared</span></li>\n<li><span id=\"aace\">Explain the difference between <code class=\"language-text\">const</code>, <code class=\"language-text\">let</code>, and <code class=\"language-text\">var</code> declarations</span></li>\n<li><span id=\"5d79\"><code class=\"language-text\">var</code> is function scoped—so if you declare it anywhere in a function, the declaration (but not assignment) is \"hoisted\"</span></li>\n<li><span id=\"a54b\">so it will exist in memory as \"undefined\" which is bad and unpredictable</span></li>\n<li><span id=\"2dc2\"><code class=\"language-text\">var</code> will also allow you to redeclare a variable, while <code class=\"language-text\">let</code> or <code class=\"language-text\">const</code> will raise a syntax error. you shouldn't be able to do that!</span></li>\n<li><span id=\"1f74\"><code class=\"language-text\">const</code> won't let you reassign a variable, but if it points to a mutable object, you will still be able to change the value by mutating the object</span></li>\n<li><span id=\"2c20\">block-scoped variables allow new variables with the same name in new scopes</span></li>\n<li><span id=\"c3d4\">block-scoped still performs hoisting of all variables within the block, but it doesn't initialize to the value of <code class=\"language-text\">undefined</code> like <code class=\"language-text\">var</code> does, so it throws a specific reference error if you try to access the value before it has been declared</span></li>\n<li><span id=\"f797\">if you do not use <code class=\"language-text\">var</code> or <code class=\"language-text\">let</code> or <code class=\"language-text\">const</code> when initializing, it will be declared as global—THIS IS BAD</span></li>\n<li><span id=\"2212\">if you assign a value without a declaration, it exists in the global scope (so then it would be accessible by all outer scopes, so bad). however, there's no hoisting, so it doesn't exist in the scope until after the line is run</span></li>\n<li><span id=\"86d1\">Predict the evaluation of code that utilizes function scope, block scope, lexical scope, and scope chaining</span></li>\n<li><span id=\"25dc\">scope of a program means the set of variables that are available for use within the program</span></li>\n<li><span id=\"bcaf\">global scope is represented by the <code class=\"language-text\">window</code> object in the browser and the <code class=\"language-text\">global</code> object in Node.js</span></li>\n<li><span id=\"7bc3\">global variables are available everywhere, and so increase the risk of name collisions</span></li>\n<li><span id=\"5172\">local scope is the set of variables available for use within the function</span></li>\n<li><span id=\"ed33\">when we enter a function, we enter a new scope</span></li>\n<li><span id=\"c21b\">includes functions arguments, local variables declared inside function, and any variables that were already declared when the function is defined (hmm about that last one)</span></li>\n<li><span id=\"51ad\">for blocks (denoted by curly braces <code class=\"language-text\">{}</code>, as in conditionals or <code class=\"language-text\">for</code> loops), variables can be block scoped</span></li>\n<li><span id=\"09f1\">inner scope does not have access to variables in the outer scope</span></li>\n<li><span id=\"587e\">scope chaining — if a given variable is not found in immediate scope, javascript will search all accessible outer scopes until variable is found</span></li>\n<li><span id=\"6ea5\">so an inner scope can access outer scope variables</span></li>\n<li><span id=\"5188\">but an outer scope can never access inner scope variables</span></li>\n</ul>\n<h4>Define an arrow function</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let arrowFunction = (param1, param2) => {\n\nlet sum = param1 + param2;\n\nreturn sum;\n\n}\n\n// with 1 param you can remove parens around parameters let arrowFunction = param =>\n\n// if your return statement is one line, you can use implied return let arrowFunction = param => param + 1;\n\n// you don't have to assign to variable, can be anonymous // if you never need to use it again param => param + 1;</code></pre></div>\n<h4>Given an arrow function, deduce the value of <code class=\"language-text\">this</code> without executing the code</h4>\n<ul>\n<li><span id=\"0ee6\">arrow functions are automatically bound to the context they were declared in.</span></li>\n<li><span id=\"9fb2\">unlike regular function which use the context they are invoked in (unless they have been bound using <code class=\"language-text\">Function#bind</code>).</span></li>\n<li><span id=\"683a\">if you implement an arrow function as a method in an object the context it will be bound to is NOT the object itself, but the global context.</span></li>\n<li><span id=\"e9e1\">so you can't use an arrow function to define a method directly</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let obj = {\nname: \"my object\",\nunboundFunc: function () {\n\nreturn this.name;\n\n// this function will be able to be called on different objects\n\n},\nboundToGlobal: () => { return this.name; // this function, no matter how you call it, will be called // on the global object, and it cannot be rebound // this is because it was defined using arrow syntax },\n\nmakeFuncBoundToObj: function() {\n        return () => {\n            return this.name;\n        }\n        // this function will return a function that will be bound\n        // to the object where we call the outer method\n        // because the arrow syntax is nested inside one of this\n        // function's methods, it cannot be rebound\n    },\n\n    makeUnboundFunc: function() {\n        return function() {\n            return this.name;\n        }\n        //this function will return a function that will still be unbound\n    },\n\n    immediatelyInvokedFunc: function() {\n        return this.name;\n    }(), // this property will be set to the return value of this anonymous function,\n    // which is invoked during the object definition;\n    // basically, it's a way to check the context inside of an object, at this moment\n\n    innerObj: {\n        name: \"inner object\",\n        innerArrowFunc: () => {\n            return this.name;\n        } // the context inside a nested object is not the parent, it's still\n        // the global object. entering an object definition doesn't change the context\n    },\n\n    let otherObj = {\n        name: \"my other object\"\n    }\n// call unboundFunc on obj, we get \"my object\" console.log(\"unboundFunc: \", obj.unboundFunc()); // => \"my object\" // assign unboundFunc to a variable and call it let newFunc = obj.unboundFunc; // this newFunc will default to being called on global object console.log(\"newFunc: \",newFunc()); // => undefined // but you could bind it directly to a different object if you wanted console.log(\"newFunc: \", newFunc.bind(otherObj)()); // \"my other object\"\n// meanwhile, obj.boundToGlobal will only ever be called on global object console.log(\"boundToGlobal: \", obj.boundToGlobal()); //=> undefined let newBoundFunc = obj.boundToGlobal; console.log(\"newBoundFunc: \", newBoundFunc()); // => undefined // even if you try to directly bind to another object, it won't work! console.log(\"newBoundFunc: \", newBoundFunc.bind(otherObj)()); // => undefined\n// let's make a new function that will always be bound to the context // where we call our function maker let boundFunc = obj.makeFuncBoundToObj();// note that we're invoking, not just assigning console.log(\"boundFunc: \", boundFunc()); // => \"my object\" // we can't rebind this function console.log(\"boundFunc: \", boundFunc.bind(otherObj)()) // =>\"my object\"\n// but if I call makeFuncBoundToObj on another context // the new bound function is stuck with that other context let boundToOther = obj.makeFuncBoundToObj.bind(otherObj)(); console.log(\"boundToOther: \", boundToOther()); // => \"my other object\" console.log(\"boundToOther: \", boundToOther.bind(obj)()) // \"my other object\"\n// the return value of my immediately invoked function // shows that the context inside of the object is the // global object, not the object itself // context only changes inside a function that is called // on an object console.log(\"immediatelyInvokedFunc: \", obj.immediatelyInvokedFunc); // => undefined\n// even though we're inside a nested object, the context is // still the same as it was outside the outer object // in this case, the global object console.log(\"innerArrowFunc: \", obj.innerObj.innerArrowFunc()); // => undefined\n\n}\n\n-Implement a closure and explain how the closure effects scope\n    -\n    a closure is \"the combination of a function and the lexical environment within which that function was declared\" -\n    alternatively, \"when an inner function uses or changes variables in an outer function\" -\n    closures have access to any variables within their own scope + scope of outer functions + global scope— the set of all these available variables is \"lexical environemnt\" -\n    closure keeps reference to all variables ** even\nif the outer\nfunction has returned **\n    -each\nfunction has a private mutable state that cannot be accessed externally\n    -\n    the inner\nfunction will maintain a reference to the scope in which it was declared.so it has access to variables that were initialized in any outer scope— even\nif that scope\n    -\n    if a variable exists in the scope of what could have been accessed by a\nfunction(e.g.global scope, outer\n    function, etc), does that variable wind up in the closure even\nif it never got accessed ?\n    -\n    if you change the value of a variable(e.g.i++) you will change the value of that variable in the scope that it was declared in\n\n    ``\n`javascript\nfunction createCounter() {\n   // this function starts a counter at 0, then returns a\n   // new function that can access and change that counter\n   //\n   // each new counter you create will have a single internal\n   // state, that can be changed only by calling the function.\n   // you can't access that state from outside of the function,\n   // even though the count variable in question is initialized\n   // by the outer function, and it remains accessible to the\n   // inner function after the outer function returns.\n   let count = 0;\n   return function() {\n      count ++;\n      return count;\n   }\n}\n\nlet counter = createCounter();\nconsole.log(counter()); //=> 1\nconsole.log(counter()); //=> 2\n// so the closure here comes into play because\n// an inner function is accessing and changing\n// a variable from an outer function\n\n// the closure is the combination of the counter\n// function and the all the variables that existed\n// in the scope that it was declared in. because\n// inner blocks/functions have access to outer\n// scopes, that includes the scope of the outer\n// function.\n\n// so counter variable is a closure, in that\n// it contains the inner count value that was\n// initialized by the outer createCounter() function\n// count has been captured or closed over\n\n// this state is private, so if i run createCounter again\n// i get a totally separate count that doesn't interact\n// with the previous one and each of the new functions\n// will have their own internal state based on the\n// initial declaration in the now-closed outer function\n\nlet counter2 = createCounter();\nconsole.log(counter2()); // => 1\n\n// if i set a new function equal to my existing counter\n// the internal state is shared with the new function\nlet counter3 = counter2;\nconsole.log(counter3());</code></pre></div>\n<h4>Define a method that references <code class=\"language-text\">this</code> on an object literal</h4>\n<ul>\n<li><span id=\"ae61\">when we use <code class=\"language-text\">this</code> in a method it refers to the object that the method is invoked on</span></li>\n<li><span id=\"29a2\">it will let you access other pieces of information from within that object, or even other methods</span></li>\n<li><span id=\"c41d\">method style invocation — <code class=\"language-text\">object.method(args)</code> (e.g. built in examples like <code class=\"language-text\">Array#push</code>, or <code class=\"language-text\">String#toUpperCase</code>)</span></li>\n<li><span id=\"c99d\">context is set every time we invoke a function</span></li>\n<li><span id=\"fa43\">function style invocation sets the context to the global object no matter what</span></li>\n<li><span id=\"8cc1\">being inside an object does not make the context that object! you still have to use method-style invocation</span></li>\n<li><span id=\"f578\">Utilize the built in <code class=\"language-text\">Function#bind</code> on a callback to maintain the context of this</span></li>\n<li><span id=\"26ba\">when we call bind on a function, we get an exotic function back — so the context will always be the same for that new function</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cat = {\n  purr: function () {\n  console.log(\"meow\");\n  },\n  purrMore: function () {\n  this.purr();\n  },\n  };\n  let sayMeow = cat.purrMore; console.log(sayMeow()); // TypeError: this.purr is not a function\n\n  // we can use the built in Function.bind to ensure our context, our this, // is the cat object let boundCat = sayMeow.bind(cat);\n  boundCat(); // prints \"meow\"\n\n-`bind`\n   can also work with arguments, so you can have a version of a\n   function with particular arguments and a particular context.the first arg will be the context aka the `this`\n   you want it to use.the next arguments will be the functions arguments that you are binding -\n       if you just want to bind it to those arguments in particular, you can use `null`\n   as the first argument, so the context won 't be bound, just the arguments -\n       Given a code snippet, identify what `this`\n   refers to\n       -\n       important to recognize the difference between scope and context -\n       scope works like a dictionary that has all the variables that are available within a given block, plus a pointer back the next outer scope(which itself has pointers to new scopes until you reach the global scope.so you can think about a whole given block 's scope as a kind of linked list of dictionaries) (also, this is not to say that scope is actually implemented in this way, that is just the schema that i can use to understand it) -\n           context refers to the value of the `this`\n           keyword -\n           the keyword `this`\n           exists in every\n           function and it evaluates to the object that is currently invoking that\n           function -so the context is fairly straightforward when we talk about methods being called on specific objects -\n           you could, however, call an object 's method on something other than that object, and then this would refer to the context where/how it was called, e.g.\n           ``\n           `javascript\nlet dog = {\n   name: \"Bowser\",\n   changeName: function () {\n      this.name = \"Layla\";\n  },\n};\n\n// note this is **not invoked** - we are assigning the function itself\nlet change = dog.changeName;\nconsole.log(change()); // undefined\n\n// our dog still has the same name\nconsole.log(dog); // { name: 'Bowser', changeName: [Function: changeName] }\n\n// instead of changing the dog we changed the global name!!!\nconsole.log(this); // Object [global] {etc, etc, etc,  name: 'Layla'}</code></pre></div>\n<h3>CALLING SOMETHING IN THE WRONG CONTEXT CAN MESS YOU UP</h3>\n<ul>\n<li><span id=\"b960\">could throw an error if it expects this to have some other method or whatever that doesn't exist</span></li>\n<li><span id=\"1880\">you could also overwrite values or assign values to exist in a space where they should not exist</span></li>\n<li><span id=\"c9f0\">if you call a function as a callback, it will set <code class=\"language-text\">this</code> to be the outer function itself, even if the function you were calling is a method that was called on a particular object</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cat = {\n  purr: function () {\n  console.log(\"meow\");\n  },\n  purrMore: function () {\n  this.purr();\n  },\n  };\n  global.setTimeout(cat.purrMore, 5000); // 5 seconds later: TypeError: this.purr is not a function</code></pre></div>\n<p>we can use strict mode with <code class=\"language-text\">\"use strict\";</code> this will prevent you from accessing the global object with <code class=\"language-text\">this</code> in functions, so if you try to call <code class=\"language-text\">this</code> in the global context and change a value, you will get a type error, and the things you try to access will be undefined</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let sayMeow = cat.purrMore; console.log(sayMeow()); // TypeError: this.purr is not a function\n\n// we can use the built in Function.bind to ensure our context, our this , // is the cat object let boundCat = sayMeow.bind(cat);\n\nboundCat(); // prints \"meow\"\n\n-`bind`\n   can also work with arguments, so you can have a version of a\n   function with particular arguments and a particular context.the first arg will be the context aka the `this`\n   you want it to use.the next arguments will be the functions arguments that you are binding -\n       if you just want to bind it to those arguments in particular, you can use `null`\n   as the first argument, so the context won 't be bound, just the arguments -\n       Given a code snippet, identify what `this`\n   refers to\n       -\n       important to recognize the difference between scope and context -\n       scope works like a dictionary that has all the variables that are available within a given block, plus a pointer back the next outer scope(which itself has pointers to new scopes until you reach the global scope.so you can think about a whole given block 's scope as a kind of linked list of dictionaries) (also, this is not to say that scope is actually implemented in this way, that is just the schema that i can use to understand it) -\n           context refers to the value of the `this`\n           keyword -\n           the keyword `this`\n           exists in every\n           function and it evaluates to the object that is currently invoking that\n           function -so the context is fairly straightforward when we talk about methods being called on specific objects -\n           you could, however, call an object 's method on something other than that object, and then this would refer to the context where/how it was called, e.g.\n           ``\n           `javascript\nlet dog = {\n   name: \"Bowser\",\n   changeName: function () {\n      this.name = \"Layla\";\n  },\n};\n\n// note this is **not invoked** - we are assigning the function itself\nlet change = dog.changeName;\nconsole.log(change()); // undefined\n\n// our dog still has the same name\nconsole.log(dog); // { name: 'Bowser', changeName: [Function: changeName] }\n\n// instead of changing the dog we changed the global name!!!\nconsole.log(this); // Object [global] {etc, etc, etc,  name: 'Layla'}</code></pre></div>\n<ul>\n<li><span id=\"48ab\">CALLING SOMETHING IN THE WRONG CONTEXT CAN MESS YOU UP!</span></li>\n<li><span id=\"857d\">could throw an error if it expects this to have some other method or whatever that doesn't exist</span></li>\n<li><span id=\"e09e\">you could also overwrite values or assign values to exist in a space where they should not exist</span></li>\n<li><span id=\"b6e0\">if you call a function as a callback, it will set <code class=\"language-text\">this</code> to be the outer function itself, even if the function you were calling is a method that was called on a particular object</span></li>\n</ul>\n<blockquote>\n<p>we can use strict mode with <code class=\"language-text\">\"use strict\";</code> this will prevent you from accessing the global object with <code class=\"language-text\">this</code> in functions, so if you try to call <code class=\"language-text\">this</code> in the global context and change a value, you will get a type error, and the things you try to access will be undefined</p>\n</blockquote>"},{"url":"/docs/javascript/cs-basics-in-js/","relativePath":"docs/javascript/cs-basics-in-js.md","relativeDir":"docs/javascript","base":"cs-basics-in-js.md","name":"cs-basics-in-js","frontmatter":{"title":"CS Basics","weight":0,"excerpt":"Computer Science Basics In JavaScript","seo":{"title":"Comp Sci Basics In Javascript","description":"create an anonymous function, and execute it immediately","robots":[],"extra":[]},"template":"docs"},"html":"<h3>Anonymous Closures</h3>\n<p>This is the fundamental construct that makes it all possible, and really is the single <strong>best feature of JavaScript</strong>. We'll simply create an anonymous function, and execute it immediately. All of the code that runs inside the function lives in a <strong>closure</strong>, which provides <strong>privacy</strong> and <strong>state</strong> throughout the lifetime of our application.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ... all vars and functions are in this scope only</span>\n    <span class=\"token comment\">// still maintains access to all globals</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Notice the <code class=\"language-text\">()</code> around the anonymous function. This is required by the language, since statements that begin with the token <code class=\"language-text\">function</code> are always considered to be <strong>function declarations</strong>. Including <code class=\"language-text\">()</code> creates a <strong>function expression</strong> instead.</p>\n<h3>Global Import</h3>\n<p>JavaScript has a feature known as <strong>implied globals</strong>. Whenever a name is used, the interpreter walks the scope chain backwards looking for a <code class=\"language-text\">var</code> statement for that name. If none is found, that variable is assumed to be global. If it's used in an assignment, the global is created if it doesn't already exist. This means that using or creating global variables in an anonymous closure is easy. Unfortunately, this leads to hard-to-manage code, as it's not obvious (to humans) which variables are global in a given file.</p>\n<h6>Luckily, our anonymous function provides an easy alternative. By passing globals as parameters to our anonymous function, we <strong>import</strong> them into our code, which is both <strong>clearer</strong> and <strong>faster</strong> than implied globals. Here's an example:</h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(function ($, YAHOO) {\n// now have access to globals jQuery (as $) and YAHOO in this code\n}(jQuery, YAHOO));</code></pre></div>\n<h3>Module Export</h3>\n<p>Sometimes you don't just want to <em>use</em> globals, but you want to <em>declare</em> them. We can easily do this by exporting them, using the anonymous function's <strong>return value</strong>. Doing so will complete the basic module pattern, so here's a complete example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> my <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        privateVariable <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">privateMethod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n\n    my<span class=\"token punctuation\">.</span>moduleProperty <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    my<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">moduleMethod</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Notice that we've declared a global module named <code class=\"language-text\">MODULE</code>, with two public properties: a method named <code class=\"language-text\">MODULE.moduleMethod</code> and a variable named <code class=\"language-text\">MODULE.moduleProperty</code>. In addition, it maintains <strong>private internal state</strong> using the closure of the anonymous function. Also, we can easily import needed globals, using the pattern we learned above.</p>\n<h6>## Advanced Patterns</h6>\n<p>While the above is enough for many uses, we can take this pattern farther and create some very powerful, extensible constructs. Lets work through them one-by-one, continuing with our module named <code class=\"language-text\">MODULE</code>.</p>\n<h3>Augmentation</h3>\n<p>One limitation of the module pattern so far is that the entire module must be in one file. Anyone who has worked in a large code-base understands the value of splitting among multiple files. Luckily, we have a nice solution to <strong>augment modules</strong>. First, we import the module, then we add properties, then we export it. Here's an example, augmenting our <code class=\"language-text\">MODULE</code> from above:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">my</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    my<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">anotherMethod</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// added method...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">MODULE</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We use the <code class=\"language-text\">var</code> keyword again for consistency, even though it's not necessary. After this code has run, our module will have gained a new public method named <code class=\"language-text\">MODULE.anotherMethod</code>. This augmentation file will also maintain its own private internal state and imports.</p>\n<h3>Loose Augmentation</h3>\n<p>While our example above requires our initial module creation to be first, and the augmentation to happen second, that isn't always necessary. One of the best things a JavaScript application can do for performance is to load scripts asynchronously. We can create flexible multi-part modules that can load themselves in any order with <strong>loose augmentation</strong>. Each file should have the following structure:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let MODULE = (function (my) {\n// add capabilities...\n\n###### return my;\n}(MODULE || {}));</code></pre></div>\n<p>In this pattern, the <code class=\"language-text\">var</code> statement is always necessary. Note that the import will create the module if it does not already exist. This means you can use a tool like <a href=\"http://labjs.com/\">LABjs</a> and load all of your module files in parallel, without needing to block.</p>\n<h3>Tight Augmentation</h3>\n<p>While loose augmentation is great, it does place some limitations on your module. Most importantly, you cannot override module properties safely. You also cannot use module properties from other files during initialization (but you can at run-time after intialization). <strong>Tight augmentation</strong> implies a set loading order, but allows <strong>overrides</strong>. Here is a simple example (augmenting our original <code class=\"language-text\">MODULE</code>):</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">my</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> old_moduleMethod <span class=\"token operator\">=</span> my<span class=\"token punctuation\">.</span>moduleMethod<span class=\"token punctuation\">;</span>\n\n    my<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">moduleMethod</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// method override, has access to old through old_moduleMethod...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">MODULE</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here we've overridden <code class=\"language-text\">MODULE.moduleMethod</code>, but maintain a reference to the original method, if needed.</p>\n<h3>Cloning and Inheritance</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE_TWO</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">old</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> my <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        key<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>key <span class=\"token keyword\">in</span> old<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>old<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            my<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> old<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> super_moduleMethod <span class=\"token operator\">=</span> old<span class=\"token punctuation\">.</span>moduleMethod<span class=\"token punctuation\">;</span>\n    my<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">moduleMethod</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// override method on the clone, access to super through super_moduleMethod</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">MODULE</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This pattern is perhaps the <strong>least flexible</strong> option. It does allow some neat compositions, but that comes at the expense of flexibility. As I've written it, properties which are objects or functions will <em>not</em> be duplicated, they will exist as one object with two references. Changing one will change the other. This could be fixed for objects with a recursive cloning process, but probably cannot be fixed for functions, except perhaps with <code class=\"language-text\">eval</code>. Nevertheless, I've included it for completeness.</p>\n<h3>Cross-File Private State</h3>\n<p>One severe limitation of splitting a module across multiple files is that each file maintains its own private state, and does not get access to the private state of the other files. This can be fixed. Here is an example of a loosely augmented module that will <strong>maintain private state</strong> across all augmentations:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">my</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> _private <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>my<span class=\"token punctuation\">.</span>_private <span class=\"token operator\">=</span> my<span class=\"token punctuation\">.</span>_private <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        _seal <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>my<span class=\"token punctuation\">.</span>_seal <span class=\"token operator\">=</span>\n            my<span class=\"token punctuation\">.</span>_seal <span class=\"token operator\">||</span>\n            <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">delete</span> my<span class=\"token punctuation\">.</span>_private<span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">delete</span> my<span class=\"token punctuation\">.</span>_seal<span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">delete</span> my<span class=\"token punctuation\">.</span>_unseal<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        _unseal <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>my<span class=\"token punctuation\">.</span>_unseal <span class=\"token operator\">=</span>\n            my<span class=\"token punctuation\">.</span>_unseal <span class=\"token operator\">||</span>\n            <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                my<span class=\"token punctuation\">.</span>_private <span class=\"token operator\">=</span> _private<span class=\"token punctuation\">;</span>\n                my<span class=\"token punctuation\">.</span>_seal <span class=\"token operator\">=</span> _seal<span class=\"token punctuation\">;</span>\n                my<span class=\"token punctuation\">.</span>_unseal <span class=\"token operator\">=</span> _unseal<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// permanent access to _private, _seal, and _unseal</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">MODULE</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Any file can set properties on their local variable <code class=\"language-text\">_private</code>, and it will be immediately available to the others. Once this module has loaded completely, the application should call <code class=\"language-text\">MODULE._seal()</code>, which will prevent external access to the internal <code class=\"language-text\">_private</code>. If this module were to be augmented again, further in the application's lifetime, one of the internal methods, in any file, can call <code class=\"language-text\">_unseal()</code> before loading the new file, and call <code class=\"language-text\">_seal()</code> again after it has been executed. This pattern occurred to me today while I was at work, I have not seen this elsewhere. I think this is a very useful pattern, and would have been worth writing about all on its own.</p>\n<h3>Sub-modules</h3>\n<p>Our final advanced pattern is actually the simplest. There are many good cases for creating sub-modules. It is just like creating regular modules:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token constant\">MODULE</span><span class=\"token punctuation\">.</span>sub <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> my <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ...</span>\n\n######   <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>While this may have been obvious, I thought it worth including. Sub-modules have all the advanced capabilities of normal modules, including augmentation and private state.</p>\n<h6>## Conclusions</h6>\n<p>Most of the advanced patterns can be combined with each other to create more useful patterns. If I had to advocate a route to take in designing a complex application, I'd combine <strong>loose augmentation</strong>, <strong>private state</strong>, and <strong>sub-modules</strong>.</p>\n<h6>I haven't touched on performance here at all, but I'd like to put in one quick note: The module pattern is <strong>good for performance</strong>. It minifies really well, which makes downloading the code faster. Using <strong>loose augmentation</strong> allows easy non-blocking parallel downloads, which also speeds up download speeds. Initialization time is probably a bit slower than other methods, but worth the trade-off. Run-time performance should suffer no penalties so long as globals are imported correctly, and will probably gain speed in sub-modules by shortening the reference chain with local variables.</h6>\n<h6>To close, here's an example of a sub-module that loads itself dynamically to its parent (creating it if it does not exist). I've left out private state for brevity, but including it would be simple. This code pattern allows an entire complex heirarchical code-base to be loaded completely in parallel with itself, sub-modules and all.</h6>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">UTIL</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">parent<span class=\"token punctuation\">,</span> $</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> my <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>parent<span class=\"token punctuation\">.</span>ajax <span class=\"token operator\">=</span> parent<span class=\"token punctuation\">.</span>ajax <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    my<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">get</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">url<span class=\"token punctuation\">,</span> params<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ok, so I'm cheating a bit :)</span>\n        <span class=\"token keyword\">return</span> $<span class=\"token punctuation\">.</span><span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">,</span> params<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// etc...</span>\n\n######   <span class=\"token keyword\">return</span> parent<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">UTIL</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> jQuery<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h1>Summary:</h1>\n<details>\n<summary> recitation  </summary>\n<h3>Anonymous Closures</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ... all vars and functions are in this scope only</span>\n    <span class=\"token comment\">// still maintains access to all globals</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Global Import</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">$<span class=\"token punctuation\">,</span> <span class=\"token constant\">YAHOO</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// now have access to globals jQuery (as $) and YAHOO in this code</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>jQuery<span class=\"token punctuation\">,</span> <span class=\"token constant\">YAHOO</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Module Export</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> my <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        privateVariable <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">privateMethod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n\n    my<span class=\"token punctuation\">.</span>moduleProperty <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    my<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">moduleMethod</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h1>Advanced Patterns</h1>\n<h3>Augmentation</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">my</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    my<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">anotherMethod</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// added method...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">MODULE</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Loose Augmentation</h3>\n<p>In this pattern, the let statement is always necessary. Note that the import will create the module if it does not already exist. This means you can use a tool like LABjs and load all of your module files in parallel, without needing to block.</p>\n<h6>`<code class=\"language-text\"></code>js</h6>\n<p>//</p>\n<p>let MODULE = (function (my) {\n// add capabilities...</p>\n<h6>return my;</h6>\n<p>})(MODULE || {});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">### Tight Augmentation\n\nHere we've overridden MODULE.moduleMethod, but maintain a reference to the original method, if needed.\n\n###### ```js\n//\nlet MODULE = (function (my) {\n    let old_moduleMethod = my.moduleMethod;\n\n    my.moduleMethod = function () {\n        // method override, has access to old through old_moduleMethod...\n    };\n\n    return my;\n})(MODULE);</code></pre></div>\n<h3>Cloning and Inheritance</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE_TWO</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">old</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> my <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        key<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>key <span class=\"token keyword\">in</span> old<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>old<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            my<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> old<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> super_moduleMethod <span class=\"token operator\">=</span> old<span class=\"token punctuation\">.</span>moduleMethod<span class=\"token punctuation\">;</span>\n    my<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">moduleMethod</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// override method on the clone, access to super through super_moduleMethod</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">MODULE</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Cross-File Private State</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token constant\">MODULE</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">my</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> _private <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>my<span class=\"token punctuation\">.</span>_private <span class=\"token operator\">=</span> my<span class=\"token punctuation\">.</span>_private <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        _seal <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>my<span class=\"token punctuation\">.</span>_seal <span class=\"token operator\">=</span>\n            my<span class=\"token punctuation\">.</span>_seal <span class=\"token operator\">||</span>\n            <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">delete</span> my<span class=\"token punctuation\">.</span>_private<span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">delete</span> my<span class=\"token punctuation\">.</span>_seal<span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">delete</span> my<span class=\"token punctuation\">.</span>_unseal<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        _unseal <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>my<span class=\"token punctuation\">.</span>_unseal <span class=\"token operator\">=</span>\n            my<span class=\"token punctuation\">.</span>_unseal <span class=\"token operator\">||</span>\n            <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                my<span class=\"token punctuation\">.</span>_private <span class=\"token operator\">=</span> _private<span class=\"token punctuation\">;</span>\n                my<span class=\"token punctuation\">.</span>_seal <span class=\"token operator\">=</span> _seal<span class=\"token punctuation\">;</span>\n                my<span class=\"token punctuation\">.</span>_unseal <span class=\"token operator\">=</span> _unseal<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// permanent access to _private, _seal, and _unseal</span>\n\n    <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">MODULE</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Sub-modules</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token constant\">MODULE</span><span class=\"token punctuation\">.</span>sub <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> my <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ...</span>\n\n######   <span class=\"token keyword\">return</span> my<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</details>"},{"url":"/docs/javascript/part2-pojo/","relativePath":"docs/javascript/part2-pojo.md","relativeDir":"docs/javascript","base":"part2-pojo.md","name":"part2-pojo","frontmatter":{"title":"Part 2 Plain Old Javascript Obects","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":"Part 2 Plain Old Javascript Obects","description":"Javascript considers most data types to be ‘primitive","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>POJOs</h1>\n<h2>1. Label variables as either Primitive vs. Reference</h2>\n<p>Javascript considers most data types to be ‘primitive', these data types are immutable, and are passed by value. The more complex data types: Array and Object are mutable, are considered ‘reference' data types, and are passed by reference.</p>\n<ul>\n<li><span id=\"6f83\">Boolean — Primitive</span></li>\n<li><span id=\"6556\">Null — Primitive</span></li>\n<li><span id=\"0048\">Undefined — Primitive</span></li>\n<li><span id=\"8dec\">Number — Primitive</span></li>\n<li><span id=\"684c\">String — Primitive</span></li>\n<li><span id=\"41c1\">Array — Reference</span></li>\n<li><span id=\"9371\">Object — Reference</span></li>\n<li><span id=\"64c8\">Function — Reference</span></li>\n</ul>\n<h4>2. Identify when to use . vs [] when accessing values of an object</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string-property property\">\"one\"</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string-property property\">\"two\"</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Choose the square brackets property accessor when the property name is determined at</span>\n    <span class=\"token comment\">// runtime, or if the property name is not a valid identifier</span>\n    <span class=\"token keyword\">let</span> myKey <span class=\"token operator\">=</span> <span class=\"token string\">\"one\"</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">[</span>myKey<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Choose the dot property accessor when the property name is known ahead of time.</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span>two<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>3. Write an object literal with a variable key using interpolation`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> keyName <span class=\"token operator\">=</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// If the key is not known, you can use an alternative `[]` syntax for</span>\n    <span class=\"token comment\">// object initialization only</span>\n    <span class=\"token keyword\">let</span> obj2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token punctuation\">[</span>keyName<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>4. Use the obj[key] !== undefined pattern to check if a given variable that contains a key exists in an object`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">function</span>  <span class=\"token function\">doesKeyExist</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">obj<span class=\"token punctuation\">,</span> key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// obj[key] !== undefined</span>\n        <span class=\"token comment\">// or:</span>\n        <span class=\"token keyword\">return</span> key <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n\n    <span class=\"token keyword\">let</span> course <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">bootcamp</span><span class=\"token operator\">:</span> <span class=\"token string\">'Lambda'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">course</span><span class=\"token operator\">:</span> <span class=\"token string\">'Bootcamp Prep'</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">doesKeyExist</span><span class=\"token punctuation\">(</span>course<span class=\"token punctuation\">,</span> <span class=\"token string\">'course'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => true</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">doesKeyExist</span><span class=\"token punctuation\">(</span>course<span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => false</span></code></pre></div>\n<h4>5. Utilize Object`.keys and Object.values in a function`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">function</span>  <span class=\"token function\">printKeys</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">object</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n\n    <span class=\"token keyword\">function</span>  <span class=\"token function\">printValues</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">object</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">printKeys</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">dog</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Strelka\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">dog2</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Belka\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">printValues</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">dog</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Strelka\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">dog2</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Belka\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>6. Iterate through an object using a for in loop`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> player <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Sergey\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">skill</span><span class=\"token operator\">:</span> <span class=\"token string\">\"hockey\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> key <span class=\"token keyword\">in</span> player<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> player<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span>player<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>7. Define a function that utilizes …rest syntax to accept an arbitrary number of arguments`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">function</span>  <span class=\"token function\">restSum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>otherNums</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> sum <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>otherNums<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        otherNums<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">num</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            sum <span class=\"token operator\">+=</span> num<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> sum<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">restSum</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 14</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">restSum</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 45</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">restSum</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 0</span></code></pre></div>\n<h4>8. Use …spread syntax for Object literals and Array literals`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> numArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> moreNums <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>numArray<span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>moreNums<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n\n    <span class=\"token keyword\">let</span> shoe <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">size</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> newShoe <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token operator\">...</span>shoe<span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">brand</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Nike\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">size</span><span class=\"token operator\">:</span> <span class=\"token number\">12</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newShoe<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    newShoe<span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> <span class=\"token string\">\"black\"</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newShoe<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>shoe<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>9. Destructure an array to reference specific elements`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n\n    <span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>first<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>10. Destructure an object to reference specific values`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">let</span> me <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Ian\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">instruments</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'bass'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'synth'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'guitar'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">siblings</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">brothers</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Alistair'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">sisters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Meghan'</span><span class=\"token punctuation\">]</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n\n    <span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span>\n        name<span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">instruments</span><span class=\"token operator\">:</span> musical_instruments<span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">siblings</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            sisters\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> me<span class=\"token punctuation\">;</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>musical_instruments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sisters<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>11. Write a function that accepts a string as an argument and returns an object representing the count of each character in the array`<code class=\"language-text\"></code>js</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">    <span class=\"token keyword\">function</span>  <span class=\"token function\">charCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">inputString</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n        <span class=\"token keyword\">let</span> res <span class=\"token operator\">=</span> inputString<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">accum<span class=\"token punctuation\">,</span> el</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>el <span class=\"token keyword\">in</span> accum<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                accum<span class=\"token punctuation\">[</span>el<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> accum<span class=\"token punctuation\">[</span>el<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                accum<span class=\"token punctuation\">[</span>el<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">return</span> accum<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">return</span> res<span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">charCount</span><span class=\"token punctuation\">(</span><span class=\"token string\">'aaabbbeebbcdkjfalksdfjlkasdfasdfiiidkkdingds'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/docs/javascript/js-expressions/","relativePath":"docs/javascript/js-expressions.md","relativeDir":"docs/javascript","base":"js-expressions.md","name":"js-expressions","frontmatter":{"title":"Javascript Operators","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":"JavaScript Programming Language","description":"Expressions & Statements","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>Like many C-like programming languages, most operators JavaScript are binary or\nunary, and written in infix notation, i.e. <code class=\"language-text\">a op b</code>.</p>\n<p>Here is list of typical operations:</p>\n<ul>\n<li><strong>[Assignment][]</strong>: <code class=\"language-text\">a = b</code>, <code class=\"language-text\">a += b</code>, <code class=\"language-text\">a |= b</code>, and more</li>\n<li></li>\n<li><strong>[Arithmetic][]</strong>: <code class=\"language-text\">a + b</code>, `a - b</li>\n<li></li>\n<li><strong>String concatenation:</strong> <code class=\"language-text\">a + b</code></li>\n<li></li>\n<li><strong>[Boolean][]:</strong> <code class=\"language-text\">a &amp;&amp; b</code>, <code class=\"language-text\">a || b</code>, <code class=\"language-text\">!a</code></li>\n<li></li>\n<li><strong>[Bitwise][]:</strong> <code class=\"language-text\">a &amp; b</code>, <code class=\"language-text\">a | b</code>, <code class=\"language-text\">a ^ b</code>, <code class=\"language-text\">~a</code>, <code class=\"language-text\">a &lt;&lt; b</code>, <code class=\"language-text\">a >> b</code>, <code class=\"language-text\">a >>> b</code></li>\n<li><strong>Function calls</strong>: <code class=\"language-text\">foo()</code>, <code class=\"language-text\">foo(a, b, c)</code></li>\n<li><strong>Increment/Decrement</strong>: <code class=\"language-text\">a++</code>, <code class=\"language-text\">++a</code>, <code class=\"language-text\">a--</code>, <code class=\"language-text\">--a</code></li>\n<li><strong>[Conditional][]</strong>: <code class=\"language-text\">foo ? bar : baz</code></li>\n<li>Others: [<code class=\"language-text\">in</code>][in], [<code class=\"language-text\">instanceof</code>][instanceof], [<code class=\"language-text\">typeof</code>][typeof],\n[<code class=\"language-text\">new</code>][new]</li>\n</ul>\n<p>JavaScript also has <strong>comparison</strong> operators and <strong>property accessors</strong>,\nboth of which are explained in more detail in the next slides.</p>\n<div class=\"callout secondary\">\n<i class=\"fa fa-info-circle\" aria-hidden=\"true\">\n</i> **ES2016**\n<p>ES2016 introduces the <em>[exponentiation operator][pow]</em>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> result <span class=\"token operator\">=</span> <span class=\"token number\">5</span> <span class=\"token operator\">**</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// equivalent to Math.pow(5, 2)</span></code></pre></div>\n</div>"},{"url":"/docs/javascript/review/","relativePath":"docs/javascript/review.md","relativeDir":"docs/javascript","base":"review.md","name":"review","frontmatter":{"title":"Javascript Concepts Review","weight":0,"excerpt":"Javascript Concepts Review","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Core Concept Review</h2>\n<h1>Core Concepts</h1>\n<h1>index</h1>\n<p>This appendix is a non-exhaustive list of new syntactic features and methods that were added to JavaScript in ES6. These features are the most commonly used and most helpful.</p>\n<p>While this appendix doesn't cover ES6 classes, we go over the basics while learning about components in the book. In addition, this appendix doesn't include descriptions of some larger new features like promises and generators. If you'd like more info on those or on any topic below, we encourage you to reference the <a href=\"https://developer.mozilla.org/\">Mozilla Developer Network's website</a> (MDN).</p>\n<h2>Prefer <code class=\"language-text\">const</code> and <code class=\"language-text\">let</code> over <code class=\"language-text\">var</code></h2>\n<p>If you've worked with ES5 JavaScript before, you're likely used to seeing variables declared with <code class=\"language-text\">var</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nar myVariable <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Both the <code class=\"language-text\">const</code> and <code class=\"language-text\">let</code> statements also declare variables. They were introduced in ES6.</p>\n<p>Use <code class=\"language-text\">const</code> in cases where a variable is never re-assigned. Using <code class=\"language-text\">const</code> makes this clear to whoever is reading your code. It refers to the \"constant\" state of the variable in the context it is defined within.</p>\n<p>If the variable will be re-assigned, use <code class=\"language-text\">let</code>.</p>\n<p>We encourage the use of <code class=\"language-text\">const</code> and <code class=\"language-text\">let</code> instead of <code class=\"language-text\">var</code>. In addition to the restriction introduced by <code class=\"language-text\">const</code>, both <code class=\"language-text\">const</code> and <code class=\"language-text\">let</code> are <em>block scoped</em> as opposed to <em>function scoped</em>. This scoping can help avoid unexpected bugs.</p>\n<h2>Arrow functions</h2>\n<p>There are three ways to write arrow function bodies. For the examples below, let's say we have an array of city objects:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nonst cities <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Cairo'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">pop</span><span class=\"token operator\">:</span> <span class=\"token number\">7764700</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Lagos'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">pop</span><span class=\"token operator\">:</span> <span class=\"token number\">8029200</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If we write an arrow function that spans multiple lines, we must use braces to delimit the function body like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> formattedPopulations <span class=\"token operator\">=</span> cities<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">city</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> popMM <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>city<span class=\"token punctuation\">.</span>pop <span class=\"token operator\">/</span> <span class=\"token number\">1000000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toFixed</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> popMM <span class=\"token operator\">+</span> <span class=\"token string\">' million'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>formattedPopulations<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Note that we must also explicitly specify a <code class=\"language-text\">return</code> for the function.</p>\n<p>However, if we write a function body that is only a single line (or single expression) we can use parentheses to delimit it:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> formattedPopulations2 <span class=\"token operator\">=</span> cities<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">city</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>city<span class=\"token punctuation\">.</span>pop <span class=\"token operator\">/</span> <span class=\"token number\">1000000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toFixed</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' million'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Notably, we don't use <code class=\"language-text\">return</code> as it's implied.</p>\n<p>Furthermore, if your function body is terse you can write it like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> pops <span class=\"token operator\">=</span> cities<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">city</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> city<span class=\"token punctuation\">.</span>pop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>pops<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The terseness of arrow functions is one of two reasons that we use them. Compare the one-liner above to this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> popsNoArrow <span class=\"token operator\">=</span> cities<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">city</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> city<span class=\"token punctuation\">.</span>pop<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Of greater benefit, though, is how arrow functions bind the <code class=\"language-text\">this</code> object.</p>\n<p>The traditional JavaScript function declaration syntax (<code class=\"language-text\">function () {}</code>) will bind <code class=\"language-text\">this</code> in anonymous functions to the global object. To illustrate the confusion this causes, consider the following example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nunction <span class=\"token function\">printSong</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Oops - The Global Object\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> jukebox <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">songs</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Wanna Be Startin' Somethin'\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">artist</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Michael Jackson\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Superstar\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">artist</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Madonna\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function-variable function\">printSong</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">song</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>song<span class=\"token punctuation\">.</span>title <span class=\"token operator\">+</span> <span class=\"token string\">\" - \"</span> <span class=\"token operator\">+</span> song<span class=\"token punctuation\">.</span>artist<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function-variable function\">printSongs</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>songs<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">song</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">printSong</span><span class=\"token punctuation\">(</span>song<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\n\njukebox<span class=\"token punctuation\">.</span><span class=\"token function\">printSongs</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The method <code class=\"language-text\">printSongs()</code> iterates over <code class=\"language-text\">this.songs</code> with <code class=\"language-text\">forEach()</code>. In this context, <code class=\"language-text\">this</code> is bound to the object (<code class=\"language-text\">jukebox</code>) as expected. However, the anonymous function passed to <code class=\"language-text\">forEach()</code> binds its internal <code class=\"language-text\">this</code> to the global object. As such, <code class=\"language-text\">this.printSong(song)</code> calls the function declared at the top of the example, <em>not</em> the method on <code class=\"language-text\">jukebox</code>.</p>\n<p>JavaScript developers have traditionally used workarounds for this behavior, but arrow functions solve the problem by <strong>capturing the <code class=\"language-text\">this</code> value of the enclosing context</strong>. Using an arrow function for <code class=\"language-text\">printSongs()</code> has the expected result:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token function-variable function\">printSongs</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>songs<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">song</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">printSong</span><span class=\"token punctuation\">(</span>song<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\n\njukebox<span class=\"token punctuation\">.</span><span class=\"token function\">printSongs</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>For this reason, throughout the book we use arrow functions for all anonymous functions.</p>\n<h2>Modules</h2>\n<p>ES6 formally supports modules using the <code class=\"language-text\">import</code>/<code class=\"language-text\">export</code> syntax.</p>\n<p><strong>Named exports</strong></p>\n<p>Inside any file, you can use <code class=\"language-text\">export</code> to specify a variable the module should expose. Here's an example of a file that exports two functions:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">sayHi</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">sayBye</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Bye!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">saySomething</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Something!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Now, anywhere we wanted to use these functions we could use <code class=\"language-text\">import</code>. We need to specify which functions we want to import. A common way of doing this is using ES6's destructuring assignment syntax to list them out like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> sayHi<span class=\"token punctuation\">,</span> sayBye <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'./greetings'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">sayHi</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">sayBye</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Importantly, the function that was <em>not</em> exported (<code class=\"language-text\">saySomething</code>) is unavailable outside of the module.</p>\n<p>Also note that we supply a <strong>relative path</strong> to <code class=\"language-text\">from</code>, indicating that the ES6 module is a local file as opposed to an npm package.</p>\n<p>Instead of inserting an <code class=\"language-text\">export</code> before each variable you'd like to export, you can use this syntax to list off all the exposed variables in one area:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">sayHi</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">sayBye</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Bye!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">saySomething</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Something!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token punctuation\">{</span> sayHi<span class=\"token punctuation\">,</span> sayBye <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We can also specify that we'd like to import all of a module's functionality underneath a given namespace with the <code class=\"language-text\">import * as &lt;Namespace></code> syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> Greetings <span class=\"token keyword\">from</span> <span class=\"token string\">'./greetings'</span><span class=\"token punctuation\">;</span>\n\nGreetings<span class=\"token punctuation\">.</span><span class=\"token function\">sayHi</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nGreetings<span class=\"token punctuation\">.</span><span class=\"token function\">sayBye</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nGreetings<span class=\"token punctuation\">.</span><span class=\"token function\">saySomething</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Default export</strong></p>\n<p>The other type of export is a default export. A module can only contain one default export:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">sayHi</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">sayBye</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Bye!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">saySomething</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Something!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> Greetings <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> sayHi<span class=\"token punctuation\">,</span> sayBye <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Greetings<span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is a common pattern for libraries. It means you can easily import the library wholesale without specifying what individual functions you want:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> Greetings <span class=\"token keyword\">from</span> <span class=\"token string\">'./greetings'</span><span class=\"token punctuation\">;</span>\n\nGreetings<span class=\"token punctuation\">.</span><span class=\"token function\">sayHi</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nGreetings<span class=\"token punctuation\">.</span><span class=\"token function\">sayBye</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>It's not uncommon for a module to use a mix of both named exports and default exports. For instance, with <code class=\"language-text\">react-dom</code>, you can import <code class=\"language-text\">ReactDOM</code> (a default export) like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom'</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Or, if you're only going to use the <code class=\"language-text\">render()</code> function, you can import the named <code class=\"language-text\">render()</code> function like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> render <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To achieve this flexibility, the export implementation for <code class=\"language-text\">react-dom</code> looks something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">render</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">component<span class=\"token punctuation\">,</span> target</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> ReactDOM <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    render\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ReactDOM<span class=\"token punctuation\">;</span></code></pre></div>\n<p>If you want to play around with the module syntax, check out the folder <code class=\"language-text\">code/webpack/es6-modules</code>.</p>\n<p>For more reading on ES6 modules, see this article from Mozilla: \"<a href=\"https://hacks.mozilla.org/2015/08/es6-in-depth-modules/\">ES6 in Depth: Modules</a>\".</p>\n<h2><code class=\"language-text\">Object.assign()</code></h2>\n<p>We use <code class=\"language-text\">Object.assign()</code> often throughout the book. We use it in areas where we want to create a modified version of an existing object.</p>\n<p><code class=\"language-text\">Object.assign()</code> accepts any number of objects as arguments. When the function receives two arguments, it <em>copies</em> the properties of the second object onto the first, like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nonst coffee <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> noCream <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">cream</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> noMilk <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">assign</span><span class=\"token punctuation\">(</span>coffee<span class=\"token punctuation\">,</span> noCream<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>It is idiomatic to pass in three arguments to <code class=\"language-text\">Object.assign()</code>. The first argument is a new JavaScript object, the one that <code class=\"language-text\">Object.assign()</code> will ultimately return. The second is the object whose properties we'd like to build off of. The last is the changes we'd like to apply:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> coffeeWithMilk <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">assign</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> coffee<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">Object.assign()</code> is a handy method for working with \"immutable\" JavaScript objects.</p>\n<h2>Template literals</h2>\n<p>In ES5 JavaScript, you'd interpolate variables into strings like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> greeting <span class=\"token operator\">=</span> <span class=\"token string\">'Hello, '</span> <span class=\"token operator\">+</span> user <span class=\"token operator\">+</span> <span class=\"token string\">'! It is '</span> <span class=\"token operator\">+</span> degF <span class=\"token operator\">+</span> <span class=\"token string\">' degrees outside.'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>With ES6 template literals, we can create the same string like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> greeting <span class=\"token operator\">=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Hello, </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>user<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">! It is </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>degF<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> degrees outside.</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>The spread operator (<code class=\"language-text\">...</code>)</h2>\n<p>In arrays, the ellipsis <code class=\"language-text\">...</code> operator will <em>expand</em> the array that follows into the parent array. The spread operator enables us to succinctly construct new arrays as a composite of existing arrays.</p>\n<p>Here is an example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nonst a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> b <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> c <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span> <span class=\"token operator\">...</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Notice how this is different than if we wrote:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> d <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Enhanced object literals</h2>\n<p>In ES5, all objects were required to have explicit key and value declarations:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> explicit <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">getState</span><span class=\"token operator\">:</span> getState<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">dispatch</span><span class=\"token operator\">:</span> dispatch\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In ES6, you can use this terser syntax whenever the property name and variable name are the same:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> implicit <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    getState<span class=\"token punctuation\">,</span>\n    dispatch\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Lots of open source libraries use this syntax, so it's good to be familiar with it. But whether you use it in your own code is a matter of stylistic preference.</p>\n<h2>Default arguments</h2>\n<p>With ES6, you can specify a default value for an argument in the case that it is <code class=\"language-text\">undefined</code> when the function is called.</p>\n<p>This:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nunction <span class=\"token function\">divide</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n  <span class=\"token keyword\">const</span> divisor <span class=\"token operator\">=</span> <span class=\"token keyword\">typeof</span> b <span class=\"token operator\">===</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">?</span> <span class=\"token number\">1</span> <span class=\"token operator\">:</span> b<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> a <span class=\"token operator\">/</span> divisor<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Can be written as this:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">divide</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">/</span> b<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>In both cases, using the function looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">divide</span><span class=\"token punctuation\">(</span><span class=\"token number\">14</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">divide</span><span class=\"token punctuation\">(</span><span class=\"token number\">14</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">divide</span><span class=\"token punctuation\">(</span><span class=\"token number\">14</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Whenever the argument <code class=\"language-text\">b</code> in the example above is <code class=\"language-text\">undefined</code>, the default argument is used. Note that <code class=\"language-text\">null</code> will not use the default argument:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">divide</span><span class=\"token punctuation\">(</span><span class=\"token number\">14</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Destructuring assignments</h2>\n<h3>For arrays</h3>\n<p>In ES5, extracting and assigning multiple elements from an array looked like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nar fruits <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span> <span class=\"token string\">'apples'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bananas'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'oranges'</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> fruit1 <span class=\"token operator\">=</span> fruits<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> fruit2 <span class=\"token operator\">=</span> fruits<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In ES6, we can use the destructuring syntax to accomplish the same task like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>veg1<span class=\"token punctuation\">,</span> veg2<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'asparagus'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'broccoli'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'onion'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>veg1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>veg2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The variables in the array on the left are \"matched\" and assigned to the corresponding elements in the array on the right. Note that <code class=\"language-text\">'onion'</code> is ignored and has no variable bound to it.</p>\n<h3>For objects</h3>\n<p>We can do something similar for extracting object properties into variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> smoothie <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">fats</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'avocado'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'peanut butter'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'greek yogurt'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">liquids</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'almond milk'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">greens</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'spinach'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">fruits</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'blueberry'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'banana'</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> liquids<span class=\"token punctuation\">,</span> fruits <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> smoothie<span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>liquids<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>fruits<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Parameter context matching</h3>\n<p>We can use these same principles to bind arguments inside a function to properties of an object supplied as an argument:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">containsSpinach</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> greens <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>greens<span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">g</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> g <span class=\"token operator\">===</span> <span class=\"token string\">'spinach'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">containsSpinach</span><span class=\"token punctuation\">(</span>smoothie<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We do this often with functional React components:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">IngredientList</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> ingredients<span class=\"token punctuation\">,</span> onClick <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>ul className<span class=\"token operator\">=</span><span class=\"token string\">\"IngredientList\"</span><span class=\"token operator\">></span>\n        <span class=\"token punctuation\">{</span>ingredients<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span> onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">onClick</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"item\"</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here, we use destructuring to extract the props into variables (<code class=\"language-text\">ingredients</code> and <code class=\"language-text\">onClick</code>) that we then use inside the component's function body.</p>\n<p>Share To Linkedin:</p>"},{"url":"/docs/javascript/js-objects/","relativePath":"docs/javascript/js-objects.md","relativeDir":"docs/javascript","base":"js-objects.md","name":"js-objects","frontmatter":{"title":"JS Objects","weight":0,"excerpt":"JS Objects","seo":{"title":"JS Objects","description":"JS Objects","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Objects in JavaScript:</h1>\n<h2>Everything else besides primitive data type values is an <em>object</em>.</h2>\n<p>Objects are <em>key-value</em> stores, more specifically <em>stringkey-value</em> stores. The\n\"keys\" of an object are called <em>properties</em>.</p>\n<p>The syntax to create a plain object is <code class=\"language-text\">{key: value, ...}</code>, which is called an\nobject literal. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">foo</span><span class=\"token operator\">:</span> <span class=\"token string\">'bar'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">baz</span><span class=\"token operator\">:</span> <span class=\"token number\">42</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Note that the above example doesn't use <em>quotation marks</em> around the property\nnames. In an object literal, quotation marks can be be omitted if the property\nname would also be a <em>valid variable name</em>. If not, they need to be quoted.\n<em>Number literals</em> are valid an object literal as well.</p>\n<p>Here are some more examples of valid and invalid property names in object\nliterals:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">foo</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>        <span class=\"token comment\">// valid, could be variable name</span>\n  <span class=\"token string-property property\">'bar'</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>      <span class=\"token comment\">// string literals are always valid</span>\n  <span class=\"token number\">123</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>        <span class=\"token comment\">// number literals are always valid</span>\n  <span class=\"token number\">1.5</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>        <span class=\"token comment\">// ^</span>\n  foo<span class=\"token operator\">-</span>bar<span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>    <span class=\"token comment\">// invalid, would not be a valid variable name</span>\n  <span class=\"token string-property property\">'foo-bar'</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>  <span class=\"token comment\">// string literals are alwaus valid</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"callout warning\">\n<p><strong>Important:</strong> No matter which value or syntax you use for a property name, the\nvalue will always be converted to a <strong>string</strong>.</p>\n</div>\n<div class=\"callout secondary\">\n<i class=\"fa fa-info-circle\" aria-hidden=\"true\">\n</i> **ES2015**\n<p>ES2015 adds two extensions to object values and object literals:</p>\n<ul>\n<li><em>Symbols</em> are can be used as property names. They are not converted to\nstrings.</li>\n<li>\n<p>Object literals can contain <em>[computed property names][computed properties]</em>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> foo <span class=\"token operator\">=</span> <span class=\"token number\">42</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token punctuation\">[</span>foo<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// creates {42: 0}</span></code></pre></div>\n</li>\n</ul>\n</div>\n<h2>References</h2>\n<p>Just like in Java and other object-oriented programming languages, objects are\nrepresented as <em>references</em>. That means if a variable has an object as a value,\nit really has a reference to that object.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> user <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Tom'</span><span class=\"token punctuation\">}</span><span class=\"token operator\">:</span></code></pre></div>\n<p>:::ascii</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">                         ┌──────────────┐\n┌─────┬──────────┐       │  Object#123  │\n│user │ ref:123 ◆┼──────▶├──────┬───────┤\n└─────┴──────────┘       │ name │ \"Tom\" │\n                         └──────┴───────┘</code></pre></div>\n<p>:::</p>\n<p>Assigning the value to another variable makes both variables point to the same\nobject:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> owner <span class=\"token operator\">=</span> user<span class=\"token punctuation\">;</span></code></pre></div>\n<p>:::ascii</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">┌─────┬──────────┐       ┌──────────────┐\n│user │ ref:123 ◆┼──┐    │  Object#123  │\n├─────┼──────────┤  ├───▶├──────┬───────┤\n│owner│ ref:123 ◆┼──┘    │ name │ \"Tom\" │\n└─────┴──────────┘       └──────┴───────┘</code></pre></div>\n<p>:::</p>\n<p>Assigning to <code class=\"language-text\">user.name</code> will therefore also \"change\" <code class=\"language-text\">owner.name</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nuser<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Joe'</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">,</span> owner<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Joe, Joe</span></code></pre></div>\n<p>:::ascii</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">┌─────┬──────────┐       ┌──────────────┐\n│user │ ref:123 ◆┼──┐    │  Object#123  │\n├─────┼──────────┤  ├───▶├──────┬───────┤\n│owner│ ref:123 ◆┼──┘    │ name │ \"Joe\" │\n└─────┴──────────┘       └──────┴───────┘</code></pre></div>\n<p>:::</p>\n<p>But assigning a new value to either <code class=\"language-text\">user</code> or <code class=\"language-text\">owner</code> will result in only that\nvariable referring to the new value. The other variable will still refer to the\nsame value.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nowner <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Kim'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>:::ascii</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">                         ┌──────────────┐\n                         │  Object#123  │\n                    ┌───▶├──────┬───────┤\n┌─────┬──────────┐  │    │ name │ \"Joe\" │\n│user │ ref:123 ◆┼──┘    └──────┴───────┘\n├─────┼──────────┤\n│owner│ ref:456 ◆┼──┐    ┌──────────────┐\n└─────┴──────────┘  │    │  Object#456  │\n                    └───▶├──────┬───────┤\n                         │ name │ \"Kim\" │\n                         └──────┴───────┘</code></pre></div>\n<p>:::</p>\n<hr>\n<p>The JavaScript standard defines a couple of <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects\">built-in objects</a> with additional\nproperties and special internal behavior, must notably <em>arrays</em> and\n<em>functions</em>, which are explained in the next slides.</p>"},{"url":"/docs/javascript/snippets/","relativePath":"docs/javascript/snippets.md","relativeDir":"docs/javascript","base":"snippets.md","name":"snippets","frontmatter":{"title":"Javascript","weight":0,"excerpt":"Javascript Snippets","seo":{"title":"JavaScript Programming Language","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Javascript Snippets</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://bgoonz.github.io/Useful-Snippets/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>"},{"url":"/docs/javascript/this-is-about-this/","relativePath":"docs/javascript/this-is-about-this.md","relativeDir":"docs/javascript","base":"this-is-about-this.md","name":"this-is-about-this","frontmatter":{"title":"WhatisTHIS","weight":0,"excerpt":"Arrow functions are great because the inner value of this cant be changed, its *always* the same as the outer this.","seo":{"title":"This in JavaScript","description":"Arrow functions are great because the inner value of this cant be changed, its *always* the same as the outer this.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>What is THIS</h1>\n<h1>What is <code class=\"language-text\">this</code>?</h1>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this\"><strong><code class=\"language-text\">this</code></strong></a> is a special \"variable\" which implicitly exists in every\nfunction. It can be thought of being similar to Java's <code class=\"language-text\">this</code> and Python's\n<code class=\"language-text\">self</code>, but it's much more flexible than that.</p>\n<div class=\"callout warning\">\n<p><strong>Important</strong>: The value of <code class=\"language-text\">this</code> is determined when the\nfunction is <strong>called</strong>, not when the function is\n<em>defined</em>.</p>\n</div>\n<p>Given the following function:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>these would be the values of <code class=\"language-text\">this</code> if called in those specific ways:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// \"normal call\": global object / window in browsers</span>\n<span class=\"token comment\">//                undefined in strict mode</span>\n<span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// as object \"method\": to the object</span>\n<span class=\"token keyword\">var</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">method</span><span class=\"token operator\">:</span> foo <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nobj<span class=\"token punctuation\">.</span><span class=\"token function\">method</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// via .call / .apply: To the value passed as first argument</span>\n<span class=\"token function\">foo</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>bar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>What is the this keyword</h2>\n<p>In general, the <code class=\"language-text\">this</code> references the object of which the function is a property. In other words, the <code class=\"language-text\">this</code> references the object that is currently calling the function.</p>\n<p>Suppose you have an object called <code class=\"language-text\">counter</code> that has a method <code class=\"language-text\">next()</code>. When you call the <code class=\"language-text\">next()</code> method, you can access the <code class=\"language-text\">this</code> object.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function-variable function\">next</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">++</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\ncounter<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Inside the <code class=\"language-text\">next()</code> function, the <code class=\"language-text\">this</code> references the <code class=\"language-text\">counter</code> object. See the following method call:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\ncounter<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token constant\">CSS</span> <span class=\"token punctuation\">(</span>css<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">next()</code> is a function that is the property of the <code class=\"language-text\">counter</code> object. Therefore, inside the <code class=\"language-text\">next()</code> function, the <code class=\"language-text\">this</code> references the <code class=\"language-text\">counter</code> object.</p>\n<h2>Global context</h2>\n<p>In the global context, the <code class=\"language-text\">this</code> references the <a href=\"https://www.javascripttutorial.net/es-next/javascript-globalthis/\">global object</a>, which is the <code class=\"language-text\">window</code> object on the web browser or <code class=\"language-text\">global</code> object on Node.js.</p>\n<p>This behavior is consistent in both strict and non-strict modes. Here's the output on the web browser:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token operator\">===</span> window<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// trueCode language: JavaScript (javascript)</span></code></pre></div>\n<p>If you assign a property to <code class=\"language-text\">this</code> object in the global context, JavaScript will add the property to the global object as shown in the following example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color<span class=\"token operator\">=</span> <span class=\"token string\">'Red'</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>color<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 'Red'Code language: JavaScript (javascript)</span></code></pre></div>\n<h2>Function context</h2>\n<p>In JavaScript, you can call a <a href=\"https://www.javascripttutorial.net/javascript-function/\">function</a> in the following ways:</p>\n<ul>\n<li>Function invocation</li>\n<li>Method invocation</li>\n<li>Constructor invocation</li>\n<li>Indirect invocation</li>\n</ul>\n<p>Each function invocation defines its own context. Therefore, the <code class=\"language-text\">this</code> behaves differently.</p>\n<h3>1) Simple function invocation</h3>\n<p>In the non-strict mode, the <code class=\"language-text\">this</code> references the global object when the function is called as follows:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">show</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token operator\">===</span> window<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">show</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>When you call the <code class=\"language-text\">show()</code> function, the <code class=\"language-text\">this</code> references the <a href=\"https://www.javascripttutorial.net/es-next/javascript-globalthis/\">global object</a>, which is the <code class=\"language-text\">window</code> on the web browser and <code class=\"language-text\">global</code> on Node.js.</p>\n<p>Calling the <code class=\"language-text\">show()</code> function is the same as:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function\">show</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>In the strict mode, JavaScript sets the <code class=\"language-text\">this</code> inside a function to <code class=\"language-text\">undefined</code>. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token string\">\"use strict\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">show</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">show</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>To enable the strict mode, you use the directive <code class=\"language-text\">\"use strict\"</code> at the beginning of the JavaScript file. If you want to apply the strict mode to a specific function only, you place it at the top of the function body.</p>\n<p>Note that the strict mode has been available since ECMAScript 5.1. The <code class=\"language-text\">strict</code> mode applies to both function and nested functions. For example:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">show</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">\"use strict\"</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">display</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">display</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">show</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token boolean\">true</span>\ntrueCode language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>In the <code class=\"language-text\">display()</code> inner function, the <code class=\"language-text\">this</code> also set to <code class=\"language-text\">undefined</code> as shown in the console.</p>\n<h3>2) Method invocation</h3>\n<p>When you call a method of an object, JavaScript sets <code class=\"language-text\">this</code> to the object that owns the method. See the following <code class=\"language-text\">car</code> object:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> car <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">brand</span><span class=\"token operator\">:</span> <span class=\"token string\">'Honda'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getBrand</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>brand<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">.</span><span class=\"token function\">getBrand</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// HondaCode language: JavaScript (javascript)</span></code></pre></div>\n<p>In this example, the <code class=\"language-text\">this</code> object in the <code class=\"language-text\">getBrand()</code> method references the <code class=\"language-text\">car</code> object.</p>\n<p>Since a method is a property of an object which is a value, you can store it in a variable.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> brand <span class=\"token operator\">=</span> car<span class=\"token punctuation\">.</span>getBrand<span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>And then call the method via the variable</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">brand</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// undefinedCode language: JavaScript (javascript)</span></code></pre></div>\n<p>You get <code class=\"language-text\">undefined</code> instead of <code class=\"language-text\">\"Honda\"</code> because when you call a method without specifying its object, JavaScript sets <code class=\"language-text\">this</code> to the global object in non-strict mode and <code class=\"language-text\">undefined</code> in the strict mode.</p>\n<p>To fix this issue, you use the <code class=\"language-text\">[bind()](https://www.javascripttutorial.net/javascript-bind/)</code> method of the <code class=\"language-text\">Function.prototype</code> object. The <code class=\"language-text\">bind()</code> method creates a new function whose the <code class=\"language-text\">this</code> keyword is set to a specified value.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> brand <span class=\"token operator\">=</span> car<span class=\"token punctuation\">.</span><span class=\"token function\">getBrand</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">brand</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Honda</span>\nCode language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>In this example, when you call the <code class=\"language-text\">brand()</code> method, the <code class=\"language-text\">this</code> keyword is bound to the <code class=\"language-text\">car</code> object. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> car <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">brand</span><span class=\"token operator\">:</span> <span class=\"token string\">'Honda'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getBrand</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>brand<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> bike <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">brand</span><span class=\"token operator\">:</span> <span class=\"token string\">'Harley Davidson'</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> brand <span class=\"token operator\">=</span> car<span class=\"token punctuation\">.</span><span class=\"token function\">getBrand</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>bike<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">brand</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nHarley Davidson</code></pre></div>\n<p>In this example, the <code class=\"language-text\">bind()</code> method sets the <code class=\"language-text\">this</code> to the <code class=\"language-text\">bike</code> object, therefore, you see the value of the <code class=\"language-text\">brand</code> property of the <code class=\"language-text\">bike</code> object on the console.</p>\n<h3>3) Constructor invocation</h3>\n<p>When you use the <code class=\"language-text\">new</code> keyword to create an instance of a function object, you use the function as a constructor.</p>\n<p>The following example declares a <code class=\"language-text\">Car</code> function, then invokes it as a constructor:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Car</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">brand</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>brand <span class=\"token operator\">=</span> brand<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Car</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getBrand</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>brand<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Honda'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">.</span><span class=\"token function\">getBrand</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The expression <code class=\"language-text\">new Car('Honda')</code> is a constructor invocation of the <code class=\"language-text\">Car</code> function.</p>\n<p>JavaScript creates a new object and sets <code class=\"language-text\">this</code> to the newly created object. This pattern works great with only one potential problem.</p>\n<p>Now, you can invoke the <code class=\"language-text\">Car()</code> as a function or as a constructor. If you omit the <code class=\"language-text\">new</code> keyword as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> bmw <span class=\"token operator\">=</span> <span class=\"token function\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'BMW'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>bmw<span class=\"token punctuation\">.</span>brand<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// => TypeError: Cannot read property 'brand' of undefinedCode language: JavaScript (javascript)</span></code></pre></div>\n<p>Since the <code class=\"language-text\">this</code> value in the <code class=\"language-text\">Car()</code> sets to the global object, the <code class=\"language-text\">bmw.brand</code> returns <code class=\"language-text\">undefined</code>.</p>\n<p>To make sure that the <code class=\"language-text\">Car()</code> function is always invoked using constructor invocation, you add a check at the beginning of the <code class=\"language-text\">Car()</code> function as follows:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Car</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">brand</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span> <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">throw</span> <span class=\"token function\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Must use the new operator to call the function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>brand <span class=\"token operator\">=</span> brand<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>ES6 introduced a meta-property named <a href=\"https://www.javascripttutorial.net/es6/javascript-new-target/\"><code class=\"language-text\">new.target</code></a> that allows you to detect whether a function is invoked as a simple invocation or as a constructor.</p>\n<p>You can modify the <code class=\"language-text\">Car()</code> function that uses the <code class=\"language-text\">new.target</code> metaproperty as follows:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Car</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">brand</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">new</span><span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">throw</span> <span class=\"token function\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Must use the new operator to call the function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>brand <span class=\"token operator\">=</span> brand<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>4) Indirect Invocation</h3>\n<p>In JavaScript, <a href=\"https://www.javascripttutorial.net/javascript-functions-are-first-class-citizens/\">functions are first-class citizens</a>. In other words, functions are objects, which are instances of the <a href=\"https://www.javascripttutorial.net/javascript-function-type/\">Function type</a>.</p>\n<p>The <code class=\"language-text\">Function</code> type has two methods: <code class=\"language-text\">[call()](https://www.javascripttutorial.net/javascript-call/)</code> and <code class=\"language-text\">[apply()](https://www.javascripttutorial.net/javascript-apply-method/)</code> . These methods allow you to set the <code class=\"language-text\">this</code> value when calling a function. For example:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getBrand</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">prefix</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>prefix <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>brand<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> honda <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">brand</span><span class=\"token operator\">:</span> <span class=\"token string\">'Honda'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> audi <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">brand</span><span class=\"token operator\">:</span> <span class=\"token string\">'Audi'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">getBrand</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>honda<span class=\"token punctuation\">,</span> <span class=\"token string\">\"It's a \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">getBrand</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>audi<span class=\"token punctuation\">,</span> <span class=\"token string\">\"It's an \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>Code language<span class=\"token operator\">:</span> <span class=\"token function\">JavaScript</span> <span class=\"token punctuation\">(</span>javascript<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nIt's a Honda\nIt's an AudiCode language<span class=\"token operator\">:</span> <span class=\"token constant\">PHP</span> <span class=\"token punctuation\">(</span>php<span class=\"token punctuation\">)</span></code></pre></div>\n<p>In this example, we called the <code class=\"language-text\">getBrand()</code> function indirectly using the <code class=\"language-text\">call()</code> method of the <code class=\"language-text\">getBrand</code> function. We passed <code class=\"language-text\">honda</code> and  <code class=\"language-text\">audi</code> object as the first argument of the <code class=\"language-text\">call()</code> method, therefore, we got the corresponding brand in each call.</p>\n<p>The <code class=\"language-text\">apply()</code> method is similar to the <code class=\"language-text\">call()</code> method except that its second argument is an array of arguments.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getBrand</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>honda<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"It's a \"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"It's a Honda\"</span>\n<span class=\"token function\">getBrand</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>audi<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"It's an \"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"It's a Audi\"Code language: JavaScript (javascript)</span></code></pre></div>\n<h2>Arrow functions</h2>\n<p><a href=\"https://www.javascripttutorial.net/es6/\">ES6</a> introduced a new concept named <a href=\"https://www.javascripttutorial.net/es6/javascript-arrow-function/\">arrow function</a>. In arrow functions, JavaScript sets the <code class=\"language-text\">this</code> lexically.</p>\n<p>It means the arrow function does not create its own <a href=\"https://www.javascripttutorial.net/javascript-execution-context/\">execution context</a> but inherits the <code class=\"language-text\">this</code> from the outer function where the arrow function is defined. See the following example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">getThis</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">getThis</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> window<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// trueCode language: JavaScript (javascript)</span></code></pre></div>\n<p>In this example, the <code class=\"language-text\">this</code> value is set to the global object i.e., <code class=\"language-text\">window</code> in the web browser.</p>\n<p>Since an arrow function does not create its own execution context, defining a method using an arrow function will cause an issue. For example:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Car</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>speed <span class=\"token operator\">=</span> <span class=\"token number\">120</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Car</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getSpeed</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>speed<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ncar<span class=\"token punctuation\">.</span><span class=\"token function\">getSpeed</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// TypeErrorCode language: JavaScript (javascript)</span></code></pre></div>\n<p>Inside the <code class=\"language-text\">getSpeed()</code> method, the <code class=\"language-text\">this</code> value reference the global object, not the <code class=\"language-text\">Car</code> object. Therefore the <code class=\"language-text\">car.getSpeed()</code> invocation causes an error because the global object does not have the <code class=\"language-text\">speed</code> property.</p>"},{"url":"/docs/js-tips/abs/","relativePath":"docs/js-tips/abs.md","relativeDir":"docs/js-tips","base":"abs.md","name":"abs","frontmatter":{"title":"Math.abs()","weight":0,"excerpt":null,"seo":{"title":"Math.abs()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Math.abs()</h1>\n<p>The <code class=\"language-text\">Math.abs()</code> function returns the absolute value of a number. That is, it returns <code class=\"language-text\">x</code> if <code class=\"language-text\">x</code> is positive or zero, and the negation of <code class=\"language-text\">x</code> if <code class=\"language-text\">x</code> is negative.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Math.abs(x)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">x</code><br>\nA number.</p>\n<h3>Return value</h3>\n<p>The absolute value of the given number.</p>\n<h2>Description</h2>\n<p>Because <code class=\"language-text\">abs()</code> is a static method of <code class=\"language-text\">Math</code>, you always use it as <code class=\"language-text\">Math.abs()</code>, rather than as a method of a <code class=\"language-text\">Math</code> object you created (<code class=\"language-text\">Math</code> is not a constructor).</p>\n<h2>Examples</h2>\n<h3>Behavior of Math.abs()</h3>\n<p>Passing an empty object, an array with more than one member, a non-numeric string or <a href=\"../undefined\"><code class=\"language-text\">undefined</code></a>/empty variable returns <a href=\"../nan\"><code class=\"language-text\">NaN</code></a>. Passing <a href=\"../null\"><code class=\"language-text\">null</code></a>, an empty string or an empty array returns 0.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Math.abs('-1');     // 1\nMath.abs(-2);       // 2\nMath.abs(null);     // 0\nMath.abs('');       // 0\nMath.abs([]);       // 0\nMath.abs([2]);      // 2\nMath.abs([1,2]);    // NaN\nMath.abs({});       // NaN\nMath.abs('string'); // NaN\nMath.abs();         // NaN</code></pre></div>"},{"url":"/docs/javascript/promises/","relativePath":"docs/javascript/promises.md","relativeDir":"docs/javascript","base":"promises.md","name":"promises","frontmatter":{"title":"Promises","weight":0,"excerpt":"Promises","seo":{"title":"Promises","description":"JavaScript is single threaded, meaning that two bits of script cannot run at the same time; they have to run one after another.","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Promises</h2>\n<p>JavaScript is single threaded, meaning that two bits of script cannot run at the same time; they have to run one after another. In browsers, JavaScript shares a thread with a load of other stuff that differs from browser to browser. But typically JavaScript is in the same queue as painting, updating styles, and handling user actions (such as highlighting text and interacting with form controls). Activity in one of these things delays the others.</p>\n<p>As a human being, you're multithreaded. You can type with multiple fingers, you can drive and hold a conversation at the same time. The only blocking function we have to deal with is sneezing, where all current activity must be suspended for the duration of the sneeze. That's pretty annoying, especially when you're driving and trying to hold a conversation. You don't want to write code that's sneezy.</p>\n<p>You've probably used events and callbacks to get around this. Here are events:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> img1 <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.img-1'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nimg1<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'load'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// woo yey image loaded</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nimg1<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'error'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// argh everything's broken</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This isn't sneezy at all. We get the image, add a couple of listeners, then JavaScript can stop executing until one of those listeners is called.</p>\n<p>Unfortunately, in the example above, it's possible that the events happened before we started listening for them, so we need to work around that using the \"complete\" property of images:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> img1 <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.img-1'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">loaded</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// woo yey image loaded}if (img1.complete) {</span>\n<span class=\"token function\">loaded</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\nimg1<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'load'</span><span class=\"token punctuation\">,</span> loaded<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>img1<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'error'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// argh everything's broken</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This doesn't catch images that errored before we got a chance to listen for them; unfortunately the DOM doesn't give us a way to do that. Also, this is loading one image. Things get even more complex if we want to know when a set of images have loaded.</p>\n<h2>Events aren't always the best way <a href=\"https://web.dev/promises/#events-aren&#x27;t-always-the-best-way\">#</a></h2>\n<p>Events are great for things that can happen multiple times on the same object---<code class=\"language-text\">keyup</code>, <code class=\"language-text\">touchstart</code> etc. With those events you don't really care about what happened before you attached the listener. But when it comes to async success/failure, ideally you want something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nimg1<span class=\"token punctuation\">.</span><span class=\"token function\">callThisIfLoadedOrWhenLoaded</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// loaded}).orIfFailedCallThis(function() {</span>\n<span class=\"token comment\">// failed</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// and...whenAllTheseHaveLoaded([img1, img2]).callThis(function() {</span>\n<span class=\"token comment\">// all loaded}).orIfSomeFailedCallThis(function() {</span>\n<span class=\"token comment\">// one or more failed</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is what promises do, but with better naming. If HTML image elements had a \"ready\" method that returned a promise, we could do this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nimg1<span class=\"token punctuation\">.</span><span class=\"token function\">ready</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// loaded}, function() {</span>\n<span class=\"token comment\">// failed</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// and...Promise.all([img1.ready(), img2.ready()]).then(function() {</span>\n<span class=\"token comment\">// all loaded}, function() {</span>\n<span class=\"token comment\">// one or more failed</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>At their most basic, promises are a bit like event listeners except:</p>\n<ul>\n<li>A promise can only succeed or fail once. It cannot succeed or fail twice, neither can it switch from success to failure or vice versa.</li>\n<li>If a promise has succeeded or failed and you later add a success/failure callback, the correct callback will be called, even though the event took place earlier.</li>\n</ul>\n<p>This is extremely useful for async success/failure, because you're less interested in the exact time something became available, and more interested in reacting to the outcome.</p>\n<h2>Promise terminology <a href=\"https://web.dev/promises/#promise-terminology\">#</a></h2>\n<p><a href=\"https://twitter.com/domenic\">Domenic Denicola</a> proof read the first draft of this article and graded me \"F\" for terminology. He put me in detention, forced me to copy out <a href=\"https://github.com/domenic/promises-unwrapping/blob/master/docs/states-and-fates.md\">States and Fates</a> 100 times, and wrote a worried letter to my parents. Despite that, I still get a lot of the terminology mixed up, but here are the basics:</p>\n<p>A promise can be:</p>\n<ul>\n<li>fulfilled - The action relating to the promise succeeded</li>\n<li>rejected - The action relating to the promise failed</li>\n<li>pending - Hasn't fulfilled or rejected yet</li>\n<li>settled - Has fulfilled or rejected</li>\n</ul>\n<p><a href=\"https://www.ecma-international.org/ecma-262/#sec-promise-objects\">The spec</a> also uses the term thenable to describe an object that is promise-like, in that it has a <code class=\"language-text\">then</code> method. This term reminds me of ex-England Football Manager <a href=\"https://en.wikipedia.org/wiki/Terry_Venables\">Terry Venables</a> so I'll be using it as little as possible.</p>\n<h2>Promises arrive in JavaScript! <a href=\"https://web.dev/promises/#promises-arrive-in-javascript!\">#</a></h2>\n<p>Promises have been around for a while in the form of libraries, such as:</p>\n<ul>\n<li><a href=\"https://github.com/kriskowal/q\">Q</a></li>\n<li><a href=\"https://github.com/cujojs/when\">when</a></li>\n<li><a href=\"https://msdn.microsoft.com/library/windows/apps/br211867.aspx\">WinJS</a></li>\n<li><a href=\"https://github.com/tildeio/rsvp.js\">RSVP.js</a></li>\n</ul>\n<p>The above and JavaScript promises share a common, standardized behaviour called <a href=\"https://github.com/promises-aplus/promises-spec\">Promises/A+</a>. If you're a jQuery user, they have something similar called <a href=\"https://api.jquery.com/category/deferred-object/\">Deferreds</a>. However, Deferreds aren't Promise/A+ compliant, which makes them <a href=\"https://thewayofcode.wordpress.com/tag/jquery-deferred-broken/\">subtly different and less useful</a>, so beware. jQuery also has <a href=\"https://api.jquery.com/Types/#Promise\">a Promise type</a>, but this is just a subset of Deferred and has the same issues.</p>\n<p>Although promise implementations follow a standardized behaviour, their overall APIs differ. JavaScript promises are similar in API to RSVP.js. Here's how you create a promise:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// do a thing, possibly async, then...  if (/* everything turned out fine */) {</span>\n  <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Stuff worked!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>  <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">reject</span><span class=\"token punctuation\">(</span><span class=\"token function\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"It broke\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The promise constructor takes one argument, a callback with two parameters, resolve and reject. Do something within the callback, perhaps async, then call resolve if everything worked, otherwise call reject.</p>\n<p>Like <code class=\"language-text\">throw</code> in plain old JavaScript, it's customary, but not required, to reject with an Error object. The benefit of Error objects is they capture a stack trace, making debugging tools more helpful.</p>\n<p>Here's how you use that promise:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\npromise<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// \"Stuff worked!\"}, function(err) {</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Error: \"It broke\"</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">then()</code> takes two arguments, a callback for a success case, and another for the failure case. Both are optional, so you can add a callback for the success or failure case only.</p>\n<p>JavaScript promises started out in the DOM as \"Futures\", renamed to \"Promises\", and finally moved into JavaScript. Having them in JavaScript rather than the DOM is great because they'll be available in non-browser JS contexts such as Node.js (whether they make use of them in their core APIs is another question).</p>\n<p>Although they're a JavaScript feature, the DOM isn't afraid to use them. In fact, all new DOM APIs with async success/failure methods will use promises. This is happening already with <a href=\"https://dvcs.w3.org/hg/quota/raw-file/tip/Overview.html#idl-def-StorageQuota\">Quota Management</a>, <a href=\"http://dev.w3.org/csswg/css-font-loading/#font-face-set-ready\">Font Load Events</a>, <a href=\"https://github.com/slightlyoff/ServiceWorker/blob/cf459d473ae09f6994e8539113d277cbd2bce939/service_worker.ts#L17\">ServiceWorker</a>, <a href=\"https://webaudio.github.io/web-midi-api/#widl-Navigator-requestMIDIAccess-Promise-MIDIOptions-options\">Web MIDI</a>, <a href=\"https://github.com/whatwg/streams#basereadablestream\">Streams</a>, and more.</p>\n<h2>Browser support &#x26; polyfill <a href=\"https://web.dev/promises/#browser-support-and-polyfill\">#</a></h2>\n<p>There are already implementations of promises in browsers today.</p>\n<p>As of Chrome 32, Opera 19, Firefox 29, Safari 8 &#x26; Microsoft Edge, promises are enabled by default.</p>\n<p>To bring browsers that lack a complete promises implementation up to spec compliance, or add promises to other browsers and Node.js, check out <a href=\"https://github.com/jakearchibald/ES6-Promises#readme\">the polyfill</a> (2k gzipped).</p>\n<h2>Compatibility with other libraries <a href=\"https://web.dev/promises/#compatibility-with-other-libraries\">#</a></h2>\n<p>The JavaScript promises API will treat anything with a <code class=\"language-text\">then()</code> method as promise-like (or <code class=\"language-text\">thenable</code> in promise-speak <em>sigh</em>), so if you use a library that returns a Q promise, that's fine, it'll play nice with the new JavaScript promises.</p>\n<p>Although, as I mentioned, jQuery's Deferreds are a bit ... unhelpful. Thankfully you can cast them to standard promises, which is worth doing as soon as possible:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> jsPromise <span class=\"token operator\">=</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span>$<span class=\"token punctuation\">.</span><span class=\"token function\">ajax</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/whatever.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here, jQuery's <code class=\"language-text\">$.ajax</code> returns a Deferred. Since it has a <code class=\"language-text\">then()</code> method, <code class=\"language-text\">Promise.resolve()</code> can turn it into a JavaScript promise. However, sometimes deferreds pass multiple arguments to their callbacks, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> jqDeferred <span class=\"token operator\">=</span> $<span class=\"token punctuation\">.</span><span class=\"token function\">ajax</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/whatever.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\njqDeferred<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response<span class=\"token punctuation\">,</span> statusText<span class=\"token punctuation\">,</span> xhrObj</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// ...}, function(xhrObj, textStatus, err) {</span>\n<span class=\"token comment\">// ...})</span></code></pre></div>\n<p>Whereas JS promises ignore all but the first:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\njsPromise<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// ...}, function(xhrObj) {</span>\n<span class=\"token comment\">// ...})</span></code></pre></div>\n<p>Thankfully this is usually what you want, or at least gives you access to what you want. Also, be aware that jQuery doesn't follow the convention of passing Error objects into rejections.</p>\n<h2>Complex async code made easier <a href=\"https://web.dev/promises/#complex-async-code-made-easier\">#</a></h2>\n<p>Right, let's code some things. Say we want to:</p>\n<ol>\n<li>Start a spinner to indicate loading</li>\n<li>Fetch some JSON for a story, which gives us the title, and urls for each chapter</li>\n<li>Add title to the page</li>\n<li>Fetch each chapter</li>\n<li>Add the story to the page</li>\n<li>Stop the spinner</li>\n</ol>\n<p>... but also tell the user if something went wrong along the way. We'll want to stop the spinner at that point too, else it'll keep on spinning, get dizzy, and crash into some other UI.</p>\n<p>Of course, you wouldn't use JavaScript to deliver a story, <a href=\"https://jakearchibald.com/2013/progressive-enhancement-is-faster/\">serving as HTML is faster</a>, but this pattern is pretty common when dealing with APIs: Multiple data fetches, then do something when it's all done.</p>\n<p>To start with, let's deal with fetching data from the network:</p>\n<h2>Promisifying XMLHttpRequest <a href=\"https://web.dev/promises/#promisifying-xmlhttprequest\">#</a></h2>\n<p>Old APIs will be updated to use promises, if it's possible in a backwards compatible way. <code class=\"language-text\">XMLHttpRequest</code> is a prime candidate, but in the mean time let's write a simple function to make a GET request:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Return a new promise.</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Do the usual XHR stuff</span>\n        <span class=\"token keyword\">var</span> req <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">XMLHttpRequest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        req<span class=\"token punctuation\">.</span><span class=\"token function\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'GET'</span><span class=\"token punctuation\">,</span> url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        req<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onload</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// This is called even on 404 etc</span>\n            <span class=\"token comment\">// so check the status</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>req<span class=\"token punctuation\">.</span>status <span class=\"token operator\">==</span> <span class=\"token number\">200</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token comment\">// Resolve the promise with the response text</span>\n                <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span>req<span class=\"token punctuation\">.</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token comment\">// Otherwise reject with the status text</span>\n                <span class=\"token comment\">// which will hopefully be a meaningful error</span>\n                <span class=\"token function\">reject</span><span class=\"token punctuation\">(</span><span class=\"token function\">Error</span><span class=\"token punctuation\">(</span>req<span class=\"token punctuation\">.</span>statusText<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token comment\">// Handle network errors</span>\n        req<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onerror</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">reject</span><span class=\"token punctuation\">(</span><span class=\"token function\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Network Error'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token comment\">// Make the request</span>\n        req<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now let's use it:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>\n    <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Success!'</span><span class=\"token punctuation\">,</span> response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Failed!'</span><span class=\"token punctuation\">,</span> error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Now we can make HTTP requests without manually typing <code class=\"language-text\">XMLHttpRequest</code>, which is great, because the less I have to see the infuriating camel-casing of <code class=\"language-text\">XMLHttpRequest</code>, the happier my life will be.</p>\n<h2>Chaining <a href=\"https://web.dev/promises/#chaining\">#</a></h2>\n<p><code class=\"language-text\">then()</code> isn't the end of the story, you can chain <code class=\"language-text\">then</code>s together to transform values or run additional async actions one after another.</p>\n<h3>Transforming values <a href=\"https://web.dev/promises/#transforming-values\">#</a></h3>\n<p>You can transform values simply by returning the new value:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\npromise\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">val</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// 1</span>\n        <span class=\"token keyword\">return</span> val <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">val</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// 3</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>As a practical example, let's go back to:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Success!'</span><span class=\"token punctuation\">,</span> response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The response is JSON, but we're currently receiving it as plain text. We could alter our get function to use the JSON <a href=\"https://developer.mozilla.org/docs/Web/API/XMLHttpRequest#responseType\"><code class=\"language-text\">responseType</code></a>, but we could also solve it in promises land:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Yey JSON!'</span><span class=\"token punctuation\">,</span> response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Since <code class=\"language-text\">JSON.parse()</code> takes a single argument and returns a transformed value, we can make a shortcut:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span>parse<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Yey JSON!'</span><span class=\"token punctuation\">,</span> response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In fact, we could make a <code class=\"language-text\">getJSON()</code> function really easily:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span>parse<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><code class=\"language-text\">getJSON()</code> still returns a promise, one that fetches a url then parses the response as JSON.</p>\n<h3>Queuing asynchronous actions <a href=\"https://web.dev/promises/#queuing-asynchronous-actions\">#</a></h3>\n<p>You can also chain <code class=\"language-text\">then</code>s to run async actions in sequence.</p>\n<p>When you return something from a <code class=\"language-text\">then()</code> callback, it's a bit magic. If you return a value, the next <code class=\"language-text\">then()</code> is called with that value. However, if you return something promise-like, the next <code class=\"language-text\">then()</code> waits on it, and is only called when that promise settles (succeeds/fails). For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">story</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span>story<span class=\"token punctuation\">.</span>chapterUrls<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">chapter1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Got chapter 1!'</span><span class=\"token punctuation\">,</span> chapter1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here we make an async request to <code class=\"language-text\">story.json</code>, which gives us a set of URLs to request, then we request the first of those. This is when promises really start to stand out from simple callback patterns.</p>\n<p>You could even make a shortcut method to get chapters:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> storyPromise<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getChapter</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">i</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    storyPromise <span class=\"token operator\">=</span> storyPromise <span class=\"token operator\">||</span> <span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> storyPromise<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">story</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span>story<span class=\"token punctuation\">.</span>chapterUrls<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// and using it is simple:</span>\n<span class=\"token function\">getChapter</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">chapter</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>chapter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token function\">getChapter</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">chapter</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>chapter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We don't download <code class=\"language-text\">story.json</code> until <code class=\"language-text\">getChapter</code> is called, but the next time(s) <code class=\"language-text\">getChapter</code> is called we reuse the story promise, so <code class=\"language-text\">story.json</code> is only fetched once. Yay Promises!</p>\n<h2>Error handling <a href=\"https://web.dev/promises/#error-handling\">#</a></h2>\n<p>As we saw earlier, <code class=\"language-text\">then()</code> takes two arguments, one for success, one for failure (or fulfill and reject, in promises-speak):</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>\n    <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Success!'</span><span class=\"token punctuation\">,</span> response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Failed!'</span><span class=\"token punctuation\">,</span> error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can also use <code class=\"language-text\">catch()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Success!'</span><span class=\"token punctuation\">,</span> response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Failed!'</span><span class=\"token punctuation\">,</span> error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>There's nothing special about <code class=\"language-text\">catch()</code>, it's just sugar for <code class=\"language-text\">then(undefined, func)</code>, but it's more readable. Note that the two code examples above do not behave the same, the latter is equivalent to:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Success!'</span><span class=\"token punctuation\">,</span> response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Failed!'</span><span class=\"token punctuation\">,</span> error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The difference is subtle, but extremely useful. Promise rejections skip forward to the next <code class=\"language-text\">then()</code> with a rejection callback (or <code class=\"language-text\">catch()</code>, since it's equivalent). With <code class=\"language-text\">then(func1, func2)</code>, <code class=\"language-text\">func1</code> or <code class=\"language-text\">func2</code> will be called, never both. But with <code class=\"language-text\">then(func1).catch(func2)</code>, both will be called if <code class=\"language-text\">func1</code> rejects, as they're separate steps in the chain. Take the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">asyncThing1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">asyncThing2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">asyncThing3</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">asyncRecovery1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token function\">asyncThing4</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token function\">asyncRecovery2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Don't worry about it\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'All done!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The flow above is very similar to normal JavaScript try/catch, errors that happen within a \"try\" go immediately to the <code class=\"language-text\">catch()</code> block. Here's the above as a flowchart (because I love flowcharts):</p>\n<p>Follow the blue lines for promises that fulfill, or the red for ones that reject.</p>\n<h3>JavaScript exceptions and promises <a href=\"https://web.dev/promises/#javascript-exceptions-and-promises\">#</a></h3>\n<p>Rejections happen when a promise is explicitly rejected, but also implicitly if an error is thrown in the constructor callback:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> jsonPromise <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// JSON.parse throws an error if you feed it some  // invalid JSON, so this implicitly rejects:  resolve(JSON.parse(\"This ain't JSON\"));</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\njsonPromise\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// This never happens:  console.log(\"It worked!\", data);</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Instead, this happens:  console.log(\"It failed!\", err);</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This means it's useful to do all your promise-related work inside the promise constructor callback, so errors are automatically caught and become rejections.</p>\n<p>The same goes for errors thrown in <code class=\"language-text\">then()</code> callbacks.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">get('/').then(JSON.parse).then(function() {\n// This never happens, '/' is an HTML page, not JSON  // so JSON.parse throws  console.log(\"It worked!\", data);\n}).catch(function(err) {\n// Instead, this happens:  console.log(\"It failed!\", err);\n})</code></pre></div>\n<h3>Error handling in practice <a href=\"https://web.dev/promises/#error-handling-in-practice\">#</a></h3>\n<p>With our story and chapters, we can use catch to display an error to the user:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">story</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span>story<span class=\"token punctuation\">.</span>chapterUrls<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">chapter1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>chapter1<span class=\"token punctuation\">.</span>html<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">addTextToPage</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Failed to show chapter'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.spinner'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>display <span class=\"token operator\">=</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If fetching <code class=\"language-text\">story.chapterUrls[0]</code> fails (e.g., http 500 or user is offline), it'll skip all following success callbacks, which includes the one in <code class=\"language-text\">getJSON()</code> which tries to parse the response as JSON, and also skips the callback that adds chapter1.html to the page. Instead it moves onto the catch callback. As a result, \"Failed to show chapter\" will be added to the page if any of the previous actions failed.</p>\n<p>Like JavaScript's try/catch, the error is caught and subsequent code continues, so the spinner is always hidden, which is what we want. The above becomes a non-blocking async version of:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> story <span class=\"token operator\">=</span> <span class=\"token function\">getJSONSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> chapter1 <span class=\"token operator\">=</span> <span class=\"token function\">getJSONSync</span><span class=\"token punctuation\">(</span>story<span class=\"token punctuation\">.</span>chapterUrls<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>chapter1<span class=\"token punctuation\">.</span>html<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">addTextToPage</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Failed to show chapter'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.spinner'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>display <span class=\"token operator\">=</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You may want to <code class=\"language-text\">catch()</code> simply for logging purposes, without recovering from the error. To do this, just rethrow the error. We could do this in our <code class=\"language-text\">getJSON()</code> method:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span>parse<span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'getJSON failed for'</span><span class=\"token punctuation\">,</span> url<span class=\"token punctuation\">,</span> err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">throw</span> err<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>So we've managed to fetch one chapter, but we want them all. Let's make that happen.</p>\n<h2>Parallelism and sequencing: getting the best of both <a href=\"https://web.dev/promises/#parallelism-and-sequencing:-getting-the-best-of-both\">#</a></h2>\n<p>Thinking async isn't easy. If you're struggling to get off the mark, try writing the code as if it were synchronous. In this case:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> story <span class=\"token operator\">=</span> <span class=\"token function\">getJSONSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>story<span class=\"token punctuation\">.</span>heading<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    story<span class=\"token punctuation\">.</span>chapterUrls<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">chapterUrl</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> chapter <span class=\"token operator\">=</span> <span class=\"token function\">getJSONSync</span><span class=\"token punctuation\">(</span>chapterUrl<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>chapter<span class=\"token punctuation\">.</span>html<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">addTextToPage</span><span class=\"token punctuation\">(</span><span class=\"token string\">'All done'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">addTextToPage</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Argh, broken: '</span> <span class=\"token operator\">+</span> err<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.spinner'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>display <span class=\"token operator\">=</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>That works! But it's sync and locks up the browser while things download. To make this work async we use <code class=\"language-text\">then()</code> to make things happen one after another.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">getJSON('story.json').then(function(story) {\naddHtmlToPage(story.heading);\n  // TODO: for each url in story.chapterUrls, fetch &amp;amp; display}).then(function() {\n// And we're all done!  addTextToPage(\"All done\");\n}).catch(function(err) {\n// Catch any error that happened along the way  addTextToPage(\"Argh, broken: \" + err.message);\n}).then(function() {\n// Always hide the spinner  document.querySelector('.spinner').style.display = 'none';})</code></pre></div>\n<p>But how can we loop through the chapter urls and fetch them in order? This doesn't work:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nstory<span class=\"token punctuation\">.</span>chapterUrls<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">chapterUrl</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// Fetch chapter  getJSON(chapterUrl).then(function(chapter) {</span>\n  <span class=\"token comment\">// and add it to the page    addHtmlToPage(chapter.html);</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">forEach</code> isn't async-aware, so our chapters would appear in whatever order they download, which is basically how Pulp Fiction was written. This isn't Pulp Fiction, so let's fix it.</p>\n<h3>Creating a sequence <a href=\"https://web.dev/promises/#creating-a-sequence\">#</a></h3>\n<p>We want to turn our <code class=\"language-text\">chapterUrls</code> array into a sequence of promises. We can do that using <code class=\"language-text\">then()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Start off with a promise that always resolvesvar sequence = Promise.resolve();</span>\n<span class=\"token comment\">// Loop through our chapter urlsstory.chapterUrls.forEach(function(chapterUrl) {</span>\n<span class=\"token comment\">// Add these actions to the end of the sequence  sequence = sequence.then(function() {</span>\n  <span class=\"token keyword\">return</span> <span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span>chapterUrl<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">chapter</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>chapter<span class=\"token punctuation\">.</span>html<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This is the first time we've seen <code class=\"language-text\">Promise.resolve()</code>, which creates a promise that resolves to whatever value you give it. If you pass it an instance of <code class=\"language-text\">Promise</code> it'll simply return it (note: this is a change to the spec that some implementations don't yet follow). If you pass it something promise-like (has a <code class=\"language-text\">then()</code> method), it creates a genuine <code class=\"language-text\">Promise</code> that fulfills/rejects in the same way. If you pass in any other value, e.g., <code class=\"language-text\">Promise.resolve('Hello')</code>, it creates a promise that fulfills with that value. If you call it with no value, as above, it fulfills with \"undefined\".</p>\n<p>There's also <code class=\"language-text\">Promise.reject(val)</code>, which creates a promise that rejects with the value you give it (or undefined).</p>\n<p>We can tidy up the above code using <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce\"><code class=\"language-text\">array.reduce</code></a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Loop through our chapter urlsstory.chapterUrls.reduce(function(sequence, chapterUrl) {</span>\n<span class=\"token comment\">// Add these actions to the end of the sequence  return sequence.then(function() {</span>\n  <span class=\"token keyword\">return</span> <span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span>chapterUrl<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">chapter</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>chapter<span class=\"token punctuation\">.</span>html<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This is doing the same as the previous example, but doesn't need the separate \"sequence\" variable. Our reduce callback is called for each item in the array. \"sequence\" is <code class=\"language-text\">Promise.resolve()</code> the first time around, but for the rest of the calls \"sequence\" is whatever we returned from the previous call. <code class=\"language-text\">array.reduce</code> is really useful for boiling an array down to a single value, which in this case is a promise.</p>\n<p>Let's put it all together:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">story</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>story<span class=\"token punctuation\">.</span>heading<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> story<span class=\"token punctuation\">.</span>chapterUrls<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">sequence<span class=\"token punctuation\">,</span> chapterUrl</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Once the last chapter's promise is done...    return sequence.then(function() {</span>\n    <span class=\"token comment\">// ...fetch the next chapter      return getJSON(chapterUrl);</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">chapter</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// and add it to the page      addHtmlToPage(chapter.html);</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// And we're all done!  addTextToPage(\"All done\");</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// Catch any error that happened along the way  addTextToPage(\"Argh, broken: \" + err.message);</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// Always hide the spinner  document.querySelector('.spinner').style.display = 'none';})</span></code></pre></div>\n<p>And there we have it, a fully async version of the sync version. But we can do better. At the moment our page is downloading like this:</p>\n<p>Browsers are pretty good at downloading multiple things at once, so we're losing performance by downloading chapters one after the other. What we want to do is download them all at the same time, then process them when they've all arrived. Thankfully there's an API for this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nPromise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span>arrayOfPromises<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arrayOfResults</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">//...})</span></code></pre></div>\n<p><code class=\"language-text\">Promise.all</code> takes an array of promises and creates a promise that fulfills when all of them successfully complete. You get an array of results (whatever the promises fulfilled to) in the same order as the promises you passed in.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">getJSON('story.json').then(function(story) {\naddHtmlToPage(story.heading);\n  // Take an array of promises and wait on them all  return Promise.all(    // Map our array of chapter urls to    // an array of chapter json promises    story.chapterUrls.map(getJSON)  );\n}).then(function(chapters) {\n// Now we have the chapters jsons in order! Loop through...  chapters.forEach(function(chapter) {\n  // ...and add to the page    addHtmlToPage(chapter.html);\n\n});\n  addTextToPage(\"All done\");\n}).catch(function(err) {\n// catch any error that happened so far  addTextToPage(\"Argh, broken: \" + err.message);\n}).then(function() {\ndocument.querySelector('.spinner').style.display = 'none';})</code></pre></div>\n<p>Depending on connection, this can be seconds faster than loading one-by-one, and it's less code than our first try. The chapters can download in whatever order, but they appear on screen in the right order.</p>\n<p>However, we can still improve perceived performance. When chapter one arrives we should add it to the page. This lets the user start reading before the rest of the chapters have arrived. When chapter three arrives, we wouldn't add it to the page because the user may not realize chapter two is missing. When chapter two arrives, we can add chapters two and three, etc etc.</p>\n<p>To do this, we fetch JSON for all our chapters at the same time, then create a sequence to add them to the document:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getJSON</span><span class=\"token punctuation\">(</span><span class=\"token string\">'story.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">story</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>story<span class=\"token punctuation\">.</span>heading<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token comment\">// Map our array of chapter urls to  // an array of chapter json promises.  // This makes sure they all download in parallel.  return story.chapterUrls.map(getJSON)    .reduce(function(sequence, chapterPromise) {</span>\n    <span class=\"token comment\">// Use reduce to chain the promises together,      // adding content to the page for each chapter      return sequence      .then(function() {</span>\n      <span class=\"token comment\">// Wait for everything in the sequence so far,        // then wait for this chapter to arrive.        return chapterPromise;      }).then(function(chapter) {</span>\n      <span class=\"token function\">addHtmlToPage</span><span class=\"token punctuation\">(</span>chapter<span class=\"token punctuation\">.</span>html<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">addTextToPage</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"All done\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// catch any error that happened along the way  addTextToPage(\"Argh, broken: \" + err.message);</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.spinner'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>display <span class=\"token operator\">=</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Async Await:</h2>\n<details>\n<summary> Async Await:  </summary>\n<h2>The basics of async/await</h2>\n<p>There are two parts to using async/await in your code.</p>\n<h3>The async keyword</h3>\n<p>First of all we have the <code class=\"language-text\">async</code> keyword, which you put in front of a function declaration to turn it into an <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/async_function\">async function</a>. An async function is a function that knows how to expect the possibility of the <code class=\"language-text\">await</code> keyword being used to invoke asynchronous code.</p>\n<p>Try typing the following lines into your browser's JS console:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">return</span> <span class=\"token string\">\"Hello\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The function returns \"Hello\" — nothing special, right?</p>\n<p>But what if we turn this into an async function? Try the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">return</span> <span class=\"token string\">\"Hello\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Ah. Invoking the function now returns a promise. This is one of the traits of async functions — their return values are guaranteed to be converted to promises.</p>\n<p>You can also create an <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/async_function\">async function expression</a>, like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">hello</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">return</span> <span class=\"token string\">\"Hello\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>And you can use <a href=\"/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions\">arrow functions</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">hello</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>These all do basically the same thing.</p>\n<p>To actually consume the value returned when the promise fulfills, since it is returning a promise, we could use a <code class=\"language-text\">.then()</code> block:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>or even just shorthand such as</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Like we saw in the last article.</p>\n<p>So the <code class=\"language-text\">async</code> keyword is added to functions to tell them to return a promise rather than directly returning the value.</p>\n<h3>The await keyword</h3>\n<p>The advantage of an async function only becomes apparent when you combine it with the <a href=\"/en-US/docs/Web/JavaScript/Reference/Operators/await\">await</a> keyword. <code class=\"language-text\">await</code> only works inside async functions within regular JavaScript code, however it can be used on its own with <a href=\"/en-US/docs/Web/JavaScript/Guide/Modules\">JavaScript modules.</a></p>\n<p><code class=\"language-text\">await</code> can be put in front of any async promise-based function to pause your code on that line until the promise fulfills, then return the resulting value.</p>\n<p>You can use <code class=\"language-text\">await</code> when calling any function that returns a Promise, including web API functions.</p>\n<p>Here is a trivial example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>alert<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Of course, the above example is not very useful, although it does serve to illustrate the syntax. Let's move on and look at a real example.</p>\n<h2>Rewriting promise code with async/await</h2>\n<p>Let's look back at a simple fetch example that we saw in the previous article:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'coffee.jpg'</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>response<span class=\"token punctuation\">.</span>ok<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">HTTP error! status: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>response<span class=\"token punctuation\">.</span>status<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">blob</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">myBlob</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> objectURL <span class=\"token operator\">=</span> <span class=\"token constant\">URL</span><span class=\"token punctuation\">.</span><span class=\"token function\">createObjectURL</span><span class=\"token punctuation\">(</span>myBlob<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> image <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'img'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    image<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> objectURL<span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>image<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'There has been a problem with your fetch operation: '</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>By now, you should have a reasonable understanding of promises and how they work, but let's convert this to use async/await to see how much simpler it makes things:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">myFetch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'coffee.jpg'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>response<span class=\"token punctuation\">.</span>ok<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">HTTP error! status: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>response<span class=\"token punctuation\">.</span>status<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token keyword\">let</span> myBlob <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">blob</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> objectURL <span class=\"token operator\">=</span> <span class=\"token constant\">URL</span><span class=\"token punctuation\">.</span><span class=\"token function\">createObjectURL</span><span class=\"token punctuation\">(</span>myBlob<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> image <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'img'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  image<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> objectURL<span class=\"token punctuation\">;</span>\n  document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>image<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">myFetch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'There has been a problem with your fetch operation: '</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>It makes code much simpler and easier to understand — no more <code class=\"language-text\">.then()</code> blocks everywhere!</p>\n<p>Since an <code class=\"language-text\">async</code> keyword turns a function into a promise, you could refactor your code to use a hybrid approach of promises and await, bringing the second half of the function out into a new block to make it more flexible:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">myFetch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'coffee.jpg'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>response<span class=\"token punctuation\">.</span>ok<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">HTTP error! status: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>response<span class=\"token punctuation\">.</span>status<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">blob</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">myFetch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">blob</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> objectURL <span class=\"token operator\">=</span> <span class=\"token constant\">URL</span><span class=\"token punctuation\">.</span><span class=\"token function\">createObjectURL</span><span class=\"token punctuation\">(</span>blob<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> image <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'img'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    image<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> objectURL<span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>image<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can try typing in the example yourself, or running our <a href=\"https://mdn.github.io/learning-area/javascript/asynchronous/async-await/simple-fetch-async-await.html\">live example</a> (see also the <a href=\"https://github.com/mdn/learning-area/blob/master/javascript/asynchronous/async-await/simple-fetch-async-await.html\">source code</a>).</p>\n<h3>But how does it work?</h3>\n<p>You'll note that we've wrapped the code inside a function, and we've included the <code class=\"language-text\">async</code> keyword before the <code class=\"language-text\">function</code> keyword. This is necessary — you have to create an async function to define a block of code in which you'll run your async code; as we said earlier, <code class=\"language-text\">await</code> only works inside of async functions.</p>\n<p>Inside the <code class=\"language-text\">myFetch()</code> function definition you can see that the code closely resembles the previous promise version, but there are some differences. Instead of needing to chain a <code class=\"language-text\">.then()</code> block on to the end of each promise-based method, you just need to add an <code class=\"language-text\">await</code> keyword before the method call, and then assign the result to a variable. The <code class=\"language-text\">await</code> keyword causes the JavaScript runtime to pause your code on this line, not allowing further code to execute in the meantime until the async function call has returned its result — very useful if subsequent code relies on that result!</p>\n<p>Once that's complete, your code continues to execute starting on the next line. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'coffee.jpg'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The response returned by the fulfilled <code class=\"language-text\">fetch()</code> promise is assigned to the <code class=\"language-text\">response</code> variable when that response becomes available, and the parser pauses on this line until that occurs. Once the response is available, the parser moves to the next line, which creates a <a href=\"/en-US/docs/Web/API/Blob\"><code class=\"language-text\">Blob</code></a> out of it. This line also invokes an async promise-based method, so we use <code class=\"language-text\">await</code> here as well. When the result of operation returns, we return it out of the <code class=\"language-text\">myFetch()</code> function.</p>\n<p>This means that when we call the <code class=\"language-text\">myFetch()</code> function, it returns a promise, so we can chain a <code class=\"language-text\">.then()</code> onto the end of it inside which we handle displaying the blob onscreen.</p>\n<p>You are probably already thinking \"this is really cool!\", and you are right — fewer <code class=\"language-text\">.then()</code> blocks to wrap around code, and it mostly just looks like synchronous code, so it is really intuitive.</p>\n<h3>Adding error handling</h3>\n<p>And if you want to add error handling, you've got a couple of options.</p>\n<p>You can use a synchronous <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/try...catch\"><code class=\"language-text\">try...catch</code></a> structure with <code class=\"language-text\">async</code>/<code class=\"language-text\">await</code>. This example expands on the first version of the code we showed above:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">myFetch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'coffee.jpg'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>response<span class=\"token punctuation\">.</span>ok<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">HTTP error! status: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>response<span class=\"token punctuation\">.</span>status<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">let</span> myBlob <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">blob</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> objectURL <span class=\"token operator\">=</span> <span class=\"token constant\">URL</span><span class=\"token punctuation\">.</span><span class=\"token function\">createObjectURL</span><span class=\"token punctuation\">(</span>myBlob<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> image <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'img'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    image<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> objectURL<span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>image<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">myFetch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The <code class=\"language-text\">catch() {}</code> block is passed an error object, which we've called <code class=\"language-text\">e</code>; we can now log that to the console, and it will give us a detailed error message showing where in the code the error was thrown.</p>\n<p>If you wanted to use the second (refactored) version of the code that we showed above, you would be better off just continuing the hybrid approach and chaining a <code class=\"language-text\">.catch()</code> block onto the end of the <code class=\"language-text\">.then()</code> call, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">myFetch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'coffee.jpg'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>response<span class=\"token punctuation\">.</span>ok<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">HTTP error! status: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>response<span class=\"token punctuation\">.</span>status<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">blob</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">myFetch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">blob</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> objectURL <span class=\"token operator\">=</span> <span class=\"token constant\">URL</span><span class=\"token punctuation\">.</span><span class=\"token function\">createObjectURL</span><span class=\"token punctuation\">(</span>blob<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> image <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'img'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    image<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> objectURL<span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>image<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is because the <code class=\"language-text\">.catch()</code> block will catch errors occurring in both the async function call and the promise chain. If you used the <code class=\"language-text\">try</code>/<code class=\"language-text\">catch</code> block here, you might still get unhandled errors in the <code class=\"language-text\">myFetch()</code> function when it's called.</p>\n<p>You can find both of these examples on GitHub:</p>\n<ul>\n<li><a href=\"https://mdn.github.io/learning-area/javascript/asynchronous/async-await/simple-fetch-async-await-try-catch.html\">simple-fetch-async-await-try-catch.html</a> (see <a href=\"https://github.com/mdn/learning-area/blob/master/javascript/asynchronous/async-await/simple-fetch-async-await-try-catch.html\">source code</a>)</li>\n<li><a href=\"https://mdn.github.io/learning-area/javascript/asynchronous/async-await/simple-fetch-async-await-promise-catch.html\">simple-fetch-async-await-promise-catch.html</a> (see <a href=\"https://github.com/mdn/learning-area/blob/master/javascript/asynchronous/async-await/simple-fetch-async-await-promise-catch.html\">source code</a>)</li>\n</ul>\n<h2>Awaiting a Promise.all()</h2>\n<p>async/await is built on top of <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\">promises</a>, so it's compatible with all the features offered by promises. This includes <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all\"><code class=\"language-text\">Promise.all()</code></a> — you can quite happily await a <code class=\"language-text\">Promise.all()</code> call to get all the results returned into a variable in a way that looks like simple synchronous code. Again, let's return to <a href=\"https://github.com/mdn/learning-area/blob/master/javascript/asynchronous/promises/promise-all.html\">an example we saw in our previous article</a>. Keep it open in a separate tab so you can compare and contrast with the new version shown below.</p>\n<p>Converting this to async/await (see <a href=\"https://mdn.github.io/learning-area/javascript/asynchronous/async-await/promise-all-async-await.html\">live demo</a> and <a href=\"https://github.com/mdn/learning-area/blob/master/javascript/asynchronous/async-await/promise-all-async-await.html\">source code</a>), this now looks like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">fetchAndDecode</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">url<span class=\"token punctuation\">,</span> type</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> content<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>response<span class=\"token punctuation\">.</span>ok<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">HTTP error! status: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>response<span class=\"token punctuation\">.</span>status<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>type <span class=\"token operator\">===</span> <span class=\"token string\">'blob'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      content <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">blob</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>type <span class=\"token operator\">===</span> <span class=\"token string\">'text'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      content <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">text</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> content<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">displayContent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> coffee <span class=\"token operator\">=</span> <span class=\"token function\">fetchAndDecode</span><span class=\"token punctuation\">(</span><span class=\"token string\">'coffee.jpg'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blob'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> tea <span class=\"token operator\">=</span> <span class=\"token function\">fetchAndDecode</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tea.jpg'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blob'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> description <span class=\"token operator\">=</span> <span class=\"token function\">fetchAndDecode</span><span class=\"token punctuation\">(</span><span class=\"token string\">'description.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'text'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> values <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>coffee<span class=\"token punctuation\">,</span> tea<span class=\"token punctuation\">,</span> description<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> objectURL1 <span class=\"token operator\">=</span> <span class=\"token constant\">URL</span><span class=\"token punctuation\">.</span><span class=\"token function\">createObjectURL</span><span class=\"token punctuation\">(</span>values<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> objectURL2 <span class=\"token operator\">=</span> <span class=\"token constant\">URL</span><span class=\"token punctuation\">.</span><span class=\"token function\">createObjectURL</span><span class=\"token punctuation\">(</span>values<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> descText <span class=\"token operator\">=</span> values<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> image1 <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'img'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> image2 <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'img'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  image1<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> objectURL1<span class=\"token punctuation\">;</span>\n  image2<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> objectURL2<span class=\"token punctuation\">;</span>\n  document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>image1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>image2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">let</span> para <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'p'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  para<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">=</span> descText<span class=\"token punctuation\">;</span>\n  document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>para<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">displayContent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You'll see that the <code class=\"language-text\">fetchAndDecode()</code> function has been converted easily into an async function with just a few changes. See the <code class=\"language-text\">Promise.all()</code> line:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">let</span> values <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>coffee<span class=\"token punctuation\">,</span> tea<span class=\"token punctuation\">,</span> description<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>By using <code class=\"language-text\">await</code> here we are able to get all the results of the three promises returned into the <code class=\"language-text\">values</code> array, when they are all available, in a way that looks very much like sync code. We've had to wrap all the code in a new async function, <code class=\"language-text\">displayContent()</code>, and we've not reduced the code by a lot of lines, but being able to move the bulk of the code out of the <code class=\"language-text\">.then()</code> block provides a nice, useful simplification, leaving us with a much more readable program.</p>\n<p>For error handling, we've included a <code class=\"language-text\">.catch()</code> block on our <code class=\"language-text\">displayContent()</code> call; this will handle errors occurring in both functions.</p>\n<blockquote>\n<p><strong>Note:</strong> It is also possible to use a sync <a href=\"/en-US/docs/Web/JavaScript/Reference/Statements/try...catch#the_finally_clause\"><code class=\"language-text\">finally</code></a> block within an async function, in place of a <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally\"><code class=\"language-text\">.finally()</code></a> async block, to show a final report on how the operation went — you can see this in action in our <a href=\"https://mdn.github.io/learning-area/javascript/asynchronous/async-await/promise-finally-async-await.html\">live example</a> (see also the <a href=\"https://github.com/mdn/learning-area/blob/master/javascript/asynchronous/async-await/promise-finally-async-await.html\">source code</a>).</p>\n</blockquote>\n<h2>Handling async/await slowdown</h2>\n<p>Async/await makes your code look synchronous, and in a way it makes it behave more synchronously. The <code class=\"language-text\">await</code> keyword blocks execution of all the code that follows it until the promise fulfills, exactly as it would with a synchronous operation. It does allow other tasks to continue to run in the meantime, but the awaited code is blocked. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">makeResult</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">items</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> newArr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> items<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    newArr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token string\">'word_'</span> <span class=\"token operator\">+</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> newArr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">getResult</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">makeResult</span><span class=\"token punctuation\">(</span>items<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n <span class=\"token comment\">// Blocked on this line</span>\n  <span class=\"token function\">useThatResult</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n <span class=\"token comment\">// Will not be executed before makeResult() is done</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>As a result, your code could be slowed down by a significant number of awaited promises happening straight after one another. Each <code class=\"language-text\">await</code> will wait for the previous one to finish, whereas actually what you might want is for the promises to begin processing simultaneously, like they would do if we weren't using async/await.</p>\n<p>Let's look at two examples — <a href=\"https://mdn.github.io/learning-area/javascript/asynchronous/async-await/slow-async-await.html\">slow-async-await.html</a> (see <a href=\"https://github.com/mdn/learning-area/blob/master/javascript/asynchronous/async-await/slow-async-await.html\">source code</a>) and <a href=\"https://mdn.github.io/learning-area/javascript/asynchronous/async-await/fast-async-await.html\">fast-async-await.html</a> (see <a href=\"https://github.com/mdn/learning-area/blob/master/javascript/asynchronous/async-await/fast-async-await.html\">source code</a>). Both of them start off with a custom promise function that fakes an async process with a <a href=\"/en-US/docs/Web/API/setTimeout\"><code class=\"language-text\">setTimeout()</code></a> call:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">timeoutPromise</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">interval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"done\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> interval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Then each one includes a <code class=\"language-text\">timeTest()</code> async function that awaits three <code class=\"language-text\">timeoutPromise()</code> calls:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token operator\">...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Each one ends by recording a start time, seeing how long the <code class=\"language-text\">timeTest()</code> promise takes to fulfill, then recording an end time and reporting how long the operation took in total:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">let</span> startTime <span class=\"token operator\">=</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> finishTime <span class=\"token operator\">=</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> timeTaken <span class=\"token operator\">=</span> finishTime <span class=\"token operator\">-</span> startTime<span class=\"token punctuation\">;</span>\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Time taken in milliseconds: \"</span> <span class=\"token operator\">+</span> timeTaken<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>It is the <code class=\"language-text\">timeTest()</code> function that differs in each case.</p>\n<p>In the <code class=\"language-text\">slow-async-await.html</code> example, <code class=\"language-text\">timeTest()</code> looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">await</span> <span class=\"token function\">timeoutPromise</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">await</span> <span class=\"token function\">timeoutPromise</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">await</span> <span class=\"token function\">timeoutPromise</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Here we await all three <code class=\"language-text\">timeoutPromise()</code> calls directly, making each one alert after 3 seconds. Each subsequent one is forced to wait until the last one finished — if you run the first example, you'll see the alert box reporting a total run time of around 9 seconds.</p>\n<p>In the <code class=\"language-text\">fast-async-await.html</code> example, <code class=\"language-text\">timeTest()</code> looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> timeoutPromise1 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromise</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> timeoutPromise2 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromise</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> timeoutPromise3 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromise</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">await</span> timeoutPromise1<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">await</span> timeoutPromise2<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">await</span> timeoutPromise3<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Here we store the three <code class=\"language-text\">Promise</code> objects in variables, which has the effect of setting off their associated processes all running simultaneously.</p>\n<p>Next, we await their results — because the promises all started processing at essentially the same time, the promises will all fulfill at the same time; when you run the second example, you'll see the alert box reporting a total run time of just over 3 seconds!</p>\n<h3>Handling errors</h3>\n<p>There is an issue with the above pattern however — it could lead to unhandled errors.</p>\n<p>Let's update the previous examples, this time adding a rejected promise and a <code class=\"language-text\">catch</code> statement in the end:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">interval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"successful\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> interval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">timeoutPromiseReject</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">interval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token function\">reject</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"error\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> interval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">await</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">await</span> <span class=\"token function\">timeoutPromiseReject</span><span class=\"token punctuation\">(</span><span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">await</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> startTime <span class=\"token operator\">=</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> finishTime <span class=\"token operator\">=</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> timeTaken <span class=\"token operator\">=</span> finishTime <span class=\"token operator\">-</span> startTime<span class=\"token punctuation\">;</span>\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Time taken in milliseconds: \"</span> <span class=\"token operator\">+</span> timeTaken<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>In the above example, the error is handled properly, and the alert appears after approximately 7 seconds.</p>\n<p>Now onto the second pattern:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">interval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"successful\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> interval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">timeoutPromiseReject</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">interval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token function\">reject</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"error\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> interval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> timeoutPromiseResolve1 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> timeoutPromiseReject2 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromiseReject</span><span class=\"token punctuation\">(</span><span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> timeoutPromiseResolve3 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">await</span> timeoutPromiseResolve1<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">await</span> timeoutPromiseReject2<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">await</span> timeoutPromiseResolve3<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> startTime <span class=\"token operator\">=</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> finishTime <span class=\"token operator\">=</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> timeTaken <span class=\"token operator\">=</span> finishTime <span class=\"token operator\">-</span> startTime<span class=\"token punctuation\">;</span>\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Time taken in milliseconds: \"</span> <span class=\"token operator\">+</span> timeTaken<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>In this example, we have an unhandled error in the console (after 2 seconds), and the alert appears after approximately 5 seconds.</p>\n<p>To start the promises in parallel and catch the error properly, we could use <code class=\"language-text\">Promise.all()</code>, as discussed earlier:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">interval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"successful\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> interval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">timeoutPromiseReject</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">interval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n      <span class=\"token function\">reject</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"error\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> interval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> timeoutPromiseResolve1 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> timeoutPromiseReject2 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromiseReject</span><span class=\"token punctuation\">(</span><span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> timeoutPromiseResolve3 <span class=\"token operator\">=</span> <span class=\"token function\">timeoutPromiseResolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> results <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>timeoutPromiseResolve1<span class=\"token punctuation\">,</span> timeoutPromiseReject2<span class=\"token punctuation\">,</span> timeoutPromiseResolve3<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> results<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> startTime <span class=\"token operator\">=</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">timeTest</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> finishTime <span class=\"token operator\">=</span> Date<span class=\"token punctuation\">.</span><span class=\"token function\">now</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> timeTaken <span class=\"token operator\">=</span> finishTime <span class=\"token operator\">-</span> startTime<span class=\"token punctuation\">;</span>\n    <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Time taken in milliseconds: \"</span> <span class=\"token operator\">+</span> timeTaken<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>In this example, the error is handled properly after around 2 seconds and we also see the alert after around 2 seconds.</p>\n<p>The <code class=\"language-text\">Promise.all()</code> rejects when any of the input promises are rejected. If you want all the promises to settle and then use some of their fulfilled values, even when some of\nthem are rejected, you could use <a href=\"/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled\"><code class=\"language-text\">Promise.allSettled()</code></a> instead.</p>\n<h2>Async/await class methods</h2>\n<p>As a final note before we move on, you can even add <code class=\"language-text\">async</code> in front of class/object methods to make them return promises, and <code class=\"language-text\">await</code> promises inside them. Take a look at the <a href=\"/en-US/docs/Learn/JavaScript/Objects/Inheritance#ecmascript_2015_classes\">ES class code we saw in our object-oriented JavaScript article</a>, and then look at our modified version with an <code class=\"language-text\">async</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Person</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> last<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">,</span> gender<span class=\"token punctuation\">,</span> interests</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n      first<span class=\"token punctuation\">,</span>\n      last\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> age<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>gender <span class=\"token operator\">=</span> gender<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>interests <span class=\"token operator\">=</span> interests<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token keyword\">async</span> <span class=\"token function\">greeting</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">await</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Hi! I'm </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">.</span>first<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token function\">farewell</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">.</span>first<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> has left the building. Bye for now!</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> han <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Han'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Solo'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'male'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Smuggling'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The first class method could now be used something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//js</span>\nhan<span class=\"token punctuation\">.</span><span class=\"token function\">greeting</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</details>"},{"url":"/docs/javascript/variables/","relativePath":"docs/javascript/variables.md","relativeDir":"docs/javascript","base":"variables.md","name":"variables","frontmatter":{"title":"Javascript Variables","weight":0,"excerpt":"Variables can be declared without an initial value.","seo":{"title":"Javascript Variables","description":"variables in the javascript language","robots":[],"extra":[]},"template":"docs"},"html":"<p>Variables are declared with the <code class=\"language-text\">var</code> keyword. JavaScript is\n<em>dynamically typed</em> so every variable can hold a value of any data type.</p>\n<p>Variables can be declared without an initial value.</p>\n<p>Some example declarations:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> foo<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> bar <span class=\"token operator\">=</span> <span class=\"token number\">42</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> foo<span class=\"token punctuation\">,</span> bar<span class=\"token punctuation\">,</span> baz<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> foo <span class=\"token operator\">=</span> <span class=\"token number\">42</span><span class=\"token punctuation\">,</span>\n    bar <span class=\"token operator\">=</span> <span class=\"token string\">'baz'</span><span class=\"token punctuation\">,</span>\n    z<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Variables that don't explicitly get assigned an initial value have the value\n<code class=\"language-text\">undefined</code>.</p>\n<div class=\"callout secondary\">\n<i class=\"fa fa-info-circle\" aria-hidden=\"true\">\n</i> **ES2015**\n<p>Since ES2015, <code class=\"language-text\">let</code> and <code class=\"language-text\">const</code> can be used in addition to <code class=\"language-text\">var</code>. We will learn\nhow they differ from <code class=\"language-text\">var</code> later. For now, lets have a look how <code class=\"language-text\">const</code> differs\nfrom <code class=\"language-text\">var</code> or <code class=\"language-text\">let</code>: <code class=\"language-text\">const</code> can be assigned a value only <em>once</em> (<em>const</em>ant).<br>\nReassigning a value will either throw an error (in strict mode, see below) or\nis silently ignored:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> foo <span class=\"token operator\">=</span> <span class=\"token number\">42</span><span class=\"token punctuation\">;</span>\nfoo <span class=\"token operator\">=</span> <span class=\"token number\">21</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// error or ignored</span></code></pre></div>\n<p><code class=\"language-text\">const</code>s <em>must</em> be initialized with a value:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> foo<span class=\"token punctuation\">;</span> <span class=\"token comment\">// error</span>\nfoo <span class=\"token operator\">=</span> <span class=\"token number\">42</span><span class=\"token punctuation\">;</span></code></pre></div>\n</div>\n<hr>\n<h2>Variable names</h2>\n<p>Valid characters for variable names include <a href=\"http://mathiasbynens.be/notes/javascript-identifiers\">a wide range of <em>unicode\ncharacters</em></a>.\nHowever, the name <em>must</em> start with a letter, <code class=\"language-text\">_</code> or <code class=\"language-text\">$</code>. Not doing so will\nresult in a syntax error.</p>\n<p>Examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> π <span class=\"token operator\">=</span> <span class=\"token number\">3.141</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> _foo <span class=\"token operator\">=</span> π<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> 0_bar <span class=\"token operator\">=</span> <span class=\"token string\">'...'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Syntax error</span></code></pre></div>\n<hr>\n<h2>Variable access</h2>\n<p>Trying to <em>read</em> an <em>undeclared variable</em> results in a runtime error:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> foo<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>bar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ReferenceError: bar is not defined.</span></code></pre></div>\n<p>However, <em>writing</em> to an undeclared variable is valid by default. It will\ncreate an <em>implicit global variable</em> and should thus be avoided:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    bar <span class=\"token operator\">=</span> <span class=\"token number\">42</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>bar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// no error</span></code></pre></div>\n<div class=\"callout primary\">\n<p>If code runs in <em><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode\">strict mode</a></em>, assigning to an undeclared variable throws\nan <em>error</em>.</p>\n</div>\n<div class=\"callout primary\">\n<h3>Strict mode</h3>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode\">Strict mode</a> is a mode of evaluating JavaScript that enforces stricter\nrules. It was introduced to \"deprecate\" certain patterns/behaviors that are\nconsidered bad or confusing.</p>\n<p>Strict mode can be enabled for a JavaScript or a function by putting</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>at the beginning of it.</p>\n</div>\n<p>JavaScript has <em>6</em> data types. Five of those are so called <em>primitive</em> data\ntypes:</p>\n<ul>\n<li>Boolean</li>\n<li>Number</li>\n<li>String</li>\n<li>Null</li>\n<li>Undefined</li>\n</ul>\n<p>Everything else that is not a value of one of the above types is an</p>\n<ul>\n<li>Object</li>\n</ul>\n<p>As we will see in the following slides, objects belong to different kinds of\n\"classes\" of objects.</p>\n<div class=\"callout secondary\">\n<i class=\"fa fa-info-circle\" aria-hidden=\"true\">\n</i> **ES2015**\n<p>ES2015 introduces a 6th primitive data type: <em>[Symbol][]</em>. Symbols are <em>unique</em>\nand <em>immutable</em> values.</p>\n</div>"},{"url":"/docs/js-tips/acos/","relativePath":"docs/js-tips/acos.md","relativeDir":"docs/js-tips","base":"acos.md","name":"acos","frontmatter":{"title":"Math.acos()","weight":0,"excerpt":null,"seo":{"title":" Math.acos()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Math.acos()</h1>\n<p>The <code class=\"language-text\">Math.acos()</code> function returns the arccosine (in radians) of a number, that is</p>\n<p>∀<em>x</em> ∈ [ − 1; 1], <code class=\"language-text\">Math.acos</code> <code class=\"language-text\">(``x``)</code> = arccos (<em>x</em>) = the unique <em>y</em> ∈ [0; <em>π</em>] such that cos (<em>y</em>) = <em>x</em></p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Math.acos(x)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">x</code><br>\nA number representing a cosine, where <code class=\"language-text\">x</code> is between <code class=\"language-text\">-1</code> and <code class=\"language-text\">1</code>.</p>\n<h3>Return value</h3>\n<p>The arccosine (angle in radians) of the given number if it's between <code class=\"language-text\">-1</code> and <code class=\"language-text\">1</code>; otherwise, <a href=\"../nan\"><code class=\"language-text\">NaN</code></a>.</p>\n<h2>Description</h2>\n<p>The <code class=\"language-text\">Math.acos()</code> method returns a numeric value between 0 and π radians for <code class=\"language-text\">x</code> between -1 and 1. If the value of <code class=\"language-text\">x</code> is outside this range, it returns <a href=\"../nan\"><code class=\"language-text\">NaN</code></a>.</p>\n<p>Because <code class=\"language-text\">acos()</code> is a static method of <code class=\"language-text\">Math</code>, you always use it as <code class=\"language-text\">Math.acos()</code>, rather than as a method of a <code class=\"language-text\">Math</code> object you created (<code class=\"language-text\">Math</code> is not a constructor).</p>\n<h2>Examples</h2>\n<h3>Using Math.acos()</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Math.acos(-2);  // NaN\nMath.acos(-1);  // 3.141592653589793\nMath.acos(0);   // 1.5707963267948966\nMath.acos(0.5); // 1.0471975511965979\nMath.acos(1);   // 0\nMath.acos(2);   // NaN</code></pre></div>\n<p>For values less than -1 or greater than 1, <code class=\"language-text\">Math.acos()</code> returns <a href=\"../nan\"><code class=\"language-text\">NaN</code></a>.</p>"},{"url":"/docs/js-tips/all/","relativePath":"docs/js-tips/all.md","relativeDir":"docs/js-tips","base":"all.md","name":"all","frontmatter":{"title":"Promise.all()","weight":0,"excerpt":null,"seo":{"title":"Promise.all()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Promise.all()</h1>\n<p>The <code class=\"language-text\">Promise.all()</code> method takes an iterable of promises as an input, and returns a single <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> that resolves to an array of the results of the input promises. This returned promise will resolve when all of the input's promises have resolved, or if the input iterable contains no promises. It rejects immediately upon any of the input promises rejecting or non-promises throwing an error, and will reject with this first rejection message / error.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.all(iterable);</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">iterable</code>\nAn <a href=\"../../iteration_protocols#the_iterable_protocol\">iterable</a> object such as an <a href=\"../array\"><code class=\"language-text\">Array</code></a>.</p>\n<h3>Return value</h3>\n<ul>\n<li>An <strong>already resolved</strong> <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> if the iterable passed is empty.</li>\n<li>An <strong>asynchronously resolved</strong> <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> if the iterable passed contains no promises. Note, Google Chrome 58 returns an <strong>already resolved</strong> promise in this case.</li>\n<li>A <strong>pending</strong> <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> in all other cases. This returned promise is then resolved/rejected <strong>asynchronously</strong> (as soon as the stack is empty) when all the promises in the given iterable have resolved, or if any of the promises reject. See the example about \"Asynchronicity or synchronicity of Promise.all\" below. Returned values will be in order of the Promises passed, regardless of completion order.</li>\n</ul>\n<h2>Description</h2>\n<p>This method can be useful for aggregating the results of multiple promises. It is typically used when there are multiple related asynchronous tasks that the overall code relies on to work successfully — all of whom we want to fulfill before the code execution continues.</p>\n<p><code class=\"language-text\">Promise.all()</code> will reject immediately upon <strong>any</strong> of the input promises rejecting. In comparison, the promise returned by <a href=\"allsettled\"><code class=\"language-text\">Promise.allSettled()</code></a> will wait for all input promises to complete, regardless of whether or not one rejects. Consequently, it will always return the final result of every promise and function from the input iterable.</p>\n<h3>Fulfillment</h3>\n<p>The returned promise is fulfilled with an array containing <strong>all</strong> the resolved values (including non-promise values) in the iterable passed as the argument.</p>\n<ul>\n<li>If an empty iterable is passed, then the promise returned by this method is fulfilled synchronously. The resolved value is an empty array.</li>\n<li>If a nonempty <em>iterable</em> is passed, and <strong>all</strong> of the promises fulfill, or are not promises, then the promise returned by this method is fulfilled asynchronously.</li>\n</ul>\n<h3>Rejection</h3>\n<p>If any of the passed-in promises reject, <code class=\"language-text\">Promise.all</code> asynchronously rejects with the value of the promise that rejected, whether or not the other promises have resolved.</p>\n<h2>Examples</h2>\n<h3>Using <code class=\"language-text\">Promise.all</code></h3>\n<p><code class=\"language-text\">Promise.all</code> waits for all fulfillments (or the first rejection).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var p1 = Promise.resolve(3);\nvar p2 = 1337;\nvar p3 = new Promise((resolve, reject) => {\n  setTimeout(() => {\n    resolve(\"foo\");\n  }, 100);\n});\n\nPromise.all([p1, p2, p3]).then(values => {\n  console.log(values); // [3, 1337, \"foo\"]\n});</code></pre></div>\n<p>If the iterable contains non-promise values, they will be ignored, but still counted in the returned promise array value (if the promise is fulfilled):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// this will be counted as if the iterable passed is empty, so it gets fulfilled\nvar p = Promise.all([1,2,3]);\n// this will be counted as if the iterable passed contains only the resolved promise with value \"444\", so it gets fulfilled\nvar p2 = Promise.all([1,2,3, Promise.resolve(444)]);\n// this will be counted as if the iterable passed contains only the rejected promise with value \"555\", so it gets rejected\nvar p3 = Promise.all([1,2,3, Promise.reject(555)]);\n\n// using setTimeout we can execute code after the stack is empty\nsetTimeout(function() {\n    console.log(p);\n    console.log(p2);\n    console.log(p3);\n});\n\n// logs\n// Promise { &lt;state>: \"fulfilled\", &lt;value>: Array[3] }\n// Promise { &lt;state>: \"fulfilled\", &lt;value>: Array[4] }\n// Promise { &lt;state>: \"rejected\", &lt;reason>: 555 }</code></pre></div>\n<h3>Asynchronicity or synchronicity of <code class=\"language-text\">Promise.all</code></h3>\n<p>This following example demonstrates the asynchronicity (or synchronicity, if the iterable passed is empty) of <code class=\"language-text\">Promise.all</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// we are passing as argument an array of promises that are already resolved,\n// to trigger Promise.all as soon as possible\nvar resolvedPromisesArray = [Promise.resolve(33), Promise.resolve(44)];\n\nvar p = Promise.all(resolvedPromisesArray);\n// immediately logging the value of p\nconsole.log(p);\n\n// using setTimeout we can execute code after the stack is empty\nsetTimeout(function() {\n    console.log('the stack is now empty');\n    console.log(p);\n});\n\n// logs, in order:\n// Promise { &lt;state>: \"pending\" }\n// the stack is now empty\n// Promise { &lt;state>: \"fulfilled\", &lt;value>: Array[2] }</code></pre></div>\n<p>The same thing happens if <code class=\"language-text\">Promise.all</code> rejects:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var mixedPromisesArray = [Promise.resolve(33), Promise.reject(44)];\nvar p = Promise.all(mixedPromisesArray);\nconsole.log(p);\nsetTimeout(function() {\n    console.log('the stack is now empty');\n    console.log(p);\n});\n\n// logs\n// Promise { &lt;state>: \"pending\" }\n// the stack is now empty\n// Promise { &lt;state>: \"rejected\", &lt;reason>: 44 }</code></pre></div>\n<p>But, <code class=\"language-text\">Promise.all</code> resolves synchronously <strong>if and only if</strong> the iterable passed is empty:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var p = Promise.all([]); // will be immediately resolved\nvar p2 = Promise.all([1337, \"hi\"]); // non-promise values will be ignored, but the evaluation will be done asynchronously\nconsole.log(p);\nconsole.log(p2)\nsetTimeout(function() {\n    console.log('the stack is now empty');\n    console.log(p2);\n});\n\n// logs\n// Promise { &lt;state>: \"fulfilled\", &lt;value>: Array[0] }\n// Promise { &lt;state>: \"pending\" }\n// the stack is now empty\n// Promise { &lt;state>: \"fulfilled\", &lt;value>: Array[2] }</code></pre></div>\n<h3><code class=\"language-text\">Promise.all</code> fail-fast behavior</h3>\n<p><code class=\"language-text\">Promise.all</code> is rejected if any of the elements are rejected. For example, if you pass in four promises that resolve after a timeout and one promise that rejects immediately, then <code class=\"language-text\">Promise.all</code> will reject immediately.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var p1 = new Promise((resolve, reject) => {\n  setTimeout(() => resolve('one'), 1000);\n});\nvar p2 = new Promise((resolve, reject) => {\n  setTimeout(() => resolve('two'), 2000);\n});\nvar p3 = new Promise((resolve, reject) => {\n  setTimeout(() => resolve('three'), 3000);\n});\nvar p4 = new Promise((resolve, reject) => {\n  setTimeout(() => resolve('four'), 4000);\n});\nvar p5 = new Promise((resolve, reject) => {\n  reject(new Error('reject'));\n});\n\n// Using .catch:\nPromise.all([p1, p2, p3, p4, p5])\n.then(values => {\n  console.log(values);\n})\n.catch(error => {\n  console.error(error.message)\n});\n\n//From console:\n//\"reject\"</code></pre></div>\n<p>It is possible to change this behavior by handling possible rejections:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var p1 = new Promise((resolve, reject) => {\n  setTimeout(() => resolve('p1_delayed_resolution'), 1000);\n});\n\nvar p2 = new Promise((resolve, reject) => {\n  reject(new Error('p2_immediate_rejection'));\n});\n\nPromise.all([\n  p1.catch(error => { return error }),\n  p2.catch(error => { return error }),\n]).then(values => {\n  console.log(values[0]) // \"p1_delayed_resolution\"\n  console.error(values[1]) // \"Error: p2_immediate_rejection\"\n})</code></pre></div>"},{"url":"/docs/js-tips/acosh/","relativePath":"docs/js-tips/acosh.md","relativeDir":"docs/js-tips","base":"acosh.md","name":"acosh","frontmatter":{"title":"Math.acosh()","weight":0,"excerpt":null,"seo":{"title":"Math.acosh()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Math.acosh()</h1>\n<p>The <code class=\"language-text\">Math.acosh()</code> function returns the hyperbolic arc-cosine of a number, that is</p>\n<p>∀<em>x</em> ≥ 1, <code class=\"language-text\">Math.acosh</code> <code class=\"language-text\">(``x``)</code> = arcosh (<em>x</em>) = the unique <em>y</em> ≥ 0 such that cosh (<em>y</em>) = <em>x</em></p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Math.acosh(x)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">x</code><br>\nA number.</p>\n<h3>Return value</h3>\n<p>The hyperbolic arc-cosine of the given number. If the number is less than <strong>1</strong>, <a href=\"../nan\"><code class=\"language-text\">NaN</code></a>.</p>\n<h2>Description</h2>\n<p>Because <code class=\"language-text\">acosh()</code> is a static method of <code class=\"language-text\">Math</code>, you always use it as <code class=\"language-text\">Math.acosh()</code>, rather than as a method of a <code class=\"language-text\">Math</code> object you created (<code class=\"language-text\">Math</code> is no constructor).</p>\n<h2>Examples</h2>\n<h3>Using Math.acosh()</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Math.acosh(-1);  // NaN\nMath.acosh(0);   // NaN\nMath.acosh(0.5); // NaN\nMath.acosh(1);   // 0\nMath.acosh(2);   // 1.3169578969248166</code></pre></div>\n<p>For values less than 1 <code class=\"language-text\">Math.acosh()</code> returns <a href=\"../nan\"><code class=\"language-text\">NaN</code></a>.</p>\n<h2>Polyfill</h2>\n<p>For all <em>x</em> ≥ 1, we have $\\operatorname{arcosh}(x) = \\ln\\left( {x + \\sqrt{x^{2} - 1}} \\right)$ and so this can be emulated with the following function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Math.acosh = Math.acosh || function(x) {\n  return Math.log(x + Math.sqrt(x * x - 1));\n};</code></pre></div>"},{"url":"/docs/js-tips/allsettled/","relativePath":"docs/js-tips/allsettled.md","relativeDir":"docs/js-tips","base":"allsettled.md","name":"allsettled","frontmatter":{"title":"Promise.allSettled()","weight":0,"excerpt":null,"seo":{"title":"Promise.allSettled()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Promise.allSettled()</h1>\n<p>The <code class=\"language-text\">Promise.allSettled()</code> method returns a promise that resolves after all of the given promises have either fulfilled or rejected, with an array of objects that each describes the outcome of each promise.</p>\n<p>It is typically used when you have multiple asynchronous tasks that are not dependent on one another to complete successfully, or you'd always like to know the result of each promise.</p>\n<p>In comparison, the Promise returned by <a href=\"all\"><code class=\"language-text\">Promise.all()</code></a> may be more appropriate if the tasks are dependent on each other / if you'd like to immediately reject upon any of them rejecting.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.allSettled(iterable);</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">iterable</code>\nAn <a href=\"../../iteration_protocols\">iterable</a> object, such as an <a href=\"../array\"><code class=\"language-text\">Array</code></a>, in which each member is a <code class=\"language-text\">Promise</code>.</p>\n<h3>Return value</h3>\n<p>A <strong>pending</strong> <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> that will be <strong>asynchronously</strong> fulfilled once every promise in the specified collection of promises has completed, either by successfully being fulfilled or by being rejected. At that time, the returned promise's handler is passed as input an array containing the outcome of each promise in the original set of promises.</p>\n<p>However, <strong>if and only if</strong> an empty iterable is passed as an argument, <code class=\"language-text\">Promise.allSettled()</code> returns a <code class=\"language-text\">Promise</code> object that has <strong>already been resolved</strong> as an empty array.</p>\n<p>For each outcome object, a <code class=\"language-text\">status</code> string is present. If the status is <code class=\"language-text\">fulfilled</code>, then a <code class=\"language-text\">value</code> is present. If the status is <code class=\"language-text\">rejected</code>, then a <code class=\"language-text\">reason</code> is present. The value (or reason) reflects what value each promise was fulfilled (or rejected) with.</p>\n<h2>Examples</h2>\n<h3>Using Promise.allSettled</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.allSettled([\n  Promise.resolve(33),\n  new Promise(resolve => setTimeout(() => resolve(66), 0)),\n  99,\n  Promise.reject(new Error('an error'))\n])\n.then(values => console.log(values));\n\n// [\n//   {status: \"fulfilled\", value: 33},\n//   {status: \"fulfilled\", value: 66},\n//   {status: \"fulfilled\", value: 99},\n//   {status: \"rejected\",  reason: Error: an error}\n// ]</code></pre></div>"},{"url":"/docs/js-tips/array-methods/","relativePath":"docs/js-tips/array-methods.md","relativeDir":"docs/js-tips","base":"array-methods.md","name":"array-methods","frontmatter":{"title":"Rotate (Array) Problem Walkthrough","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"Rotate (Array) Problem Walkthrough","description":" The function should return a new array where the elements of the array are rotated to the right number times. The function should not mutate the original array and instead return a new array.","robots":[],"extra":[]},"template":"docs"},"html":"<h3>Rotate (Array) Problem Walkthrough</h3>\n<h3>Explanation for Rotate Right</h3>\n<p><img src=\"https://cdn-images-1.medium.com/max/1200/0*3_vbGvHeWOgSTxk7.png\" alt=\"image\"></p>\n<h3>Question</h3>\n<p>Write a function <code class=\"language-text\">rotateRight(array, num)</code> that takes in an array and a number as arguments.</p>\n<blockquote>\n<p>The function should return a new array where the elements of the array are rotated to the right number times. The function should not mutate the original array and instead return a new array.</p>\n</blockquote>\n<blockquote>\n<p>Define this function using <code class=\"language-text\">[*function expression syntax*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function)</code><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function\">.</a></p>\n</blockquote>\n<p><strong>HINT:</strong> you can use <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice\">Array#slice</a> to create a copy of an array</p>\n<hr>\n<blockquote>\n<p>JavaScript gives us four methods to add or remove items from the beginning or end of arrays:</p>\n</blockquote>\n<h3>pop(): Remove an item from the end of an array</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cats = ['Bob', 'Willy', 'Mini'];</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cats.pop(); // ['Bob', 'Willy']</code></pre></div>\n<blockquote>\n<p>pop() returns the removed item.</p>\n</blockquote>\n<h3>push(): Add items to the end of an array</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cats = ['Bob'];</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cats.push('Willy'); // ['Bob', 'Willy']</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cats.push('Puff', 'George'); // ['Bob', 'Willy', 'Puff', 'George']</code></pre></div>\n<blockquote>\n<p>push() returns the new array length.</p>\n</blockquote>\n<h3>shift(): Remove an item from the beginning of an array</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cats = ['Bob', 'Willy', 'Mini'];</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cats.shift(); // ['Willy', 'Mini']</code></pre></div>\n<blockquote>\n<p>shift() returns the removed item.</p>\n</blockquote>\n<h3>unshift(): Add items to the beginning of an array</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cats = ['Bob'];</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cats.unshift('Willy'); // ['Willy', 'Bob']</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cats.unshift('Puff', 'George'); // ['Puff', 'George', 'Willy', 'Bob']</code></pre></div>\n<blockquote>\n<p>unshift() returns the new array length.</p>\n</blockquote>\n<p><strong>We are being asked for two things:</strong></p>\n<ol>\n<li>To return an array with all the elements shifted over 'num ' times.</li>\n<li>To <code class=\"language-text\">NOT</code> mutate the original array</li>\n</ol>\n<p><strong>Step 1.</strong><br>\nWe need to start the function and create a variable to hold a COPY of our input array.</p>\n<p>let rotateRight = function (array, num) {\nlet result = array.slice(0);\n};</p>\n<p><a href=\"https://gist.github.com/bgoonz/ca7a48c316345f6f7acd9383e13fb23e/raw/ec4c2296e563c005a0091d35cf4299c17944b826/copy-arr.js\">view raw</a><a href=\"https://gist.github.com/bgoonz/ca7a48c316345f6f7acd9383e13fb23e#file-copy-arr-js\">copy-arr.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice\" title=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice\"><strong>Array.prototype.slice()</strong><br>\n<em>The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end...</em>developer.mozilla.org</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice\"></a></p>\n<ul>\n<li>We assign array.slice(0) to a variable called result.</li>\n<li>Slicing our input array simply creates a sliced copy of the data.</li>\n<li>Remember that by excluding a second argument in our slice parameter allows us to slice from the first argument all the way to the end.</li>\n</ul>\n<p><strong>Step 2.</strong><br>\nWe need to create a for loop to tell our function how many times we want to rotate.</p>\n<p>let rotateRight = function (array, num) {\nlet result = array.slice(0);\nfor (var i = 0; i &#x3C; num; i++) {\n// some code here\n}\n};</p>\n<p><a href=\"https://gist.github.com/bgoonz/b2a934289a677f337a72bcd7751a55df/raw/7e76928d94617e115e3f894d1557caf1f8549590/for-loop-rotate.js\">view raw</a><a href=\"https://gist.github.com/bgoonz/b2a934289a677f337a72bcd7751a55df#file-for-loop-rotate-js\">for-loop-rotate.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<ul>\n<li>By setting our second delimiter to i &#x3C; num we will ask our loops to run num times.</li>\n<li>Running num times is the same as executing the code block within num times.</li>\n</ul>\n<p><strong>Step 3.</strong><br>\nWe need to put some executable code within our for loop to be run during every cycle.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">rotateRight</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> num</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> num<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> ele <span class=\"token operator\">=</span> result<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nresult<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span>ele<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><a href=\"https://gist.github.com/bgoonz/44e66960ba5cc0ffe04ea0499f7c3134/raw/8427e5139b96194f78552f10af07e6309ea2135a/rot.js\">view raw</a><a href=\"https://gist.github.com/bgoonz/44e66960ba5cc0ffe04ea0499f7c3134#file-rot-js\">rot.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<ul>\n<li>Since we are rotating to the right, every change to our result array under the hood will look like this (if we ref. our first test case):</li>\n<li><code class=\"language-text\">['a', 'b', 'c', 'd', 'e'];</code> (how it looks like at the start)</li>\n<li><code class=\"language-text\">['e', 'a', 'b', 'c', 'd'];</code> (after one run of the for loop)</li>\n<li><code class=\"language-text\">['d', 'e', 'a', 'b', 'c'];</code> (after second/last run of the for loop)</li>\n<li>To accomplish this we first need to '<code class=\"language-text\">pop</code>' off or remove our last element.</li>\n<li>Two things happen when we use this built-in function.</li>\n<li>Our copied array is mutated to lose it''s last ele.</li>\n<li>The removed element is stored in the variable we assigned to the function.</li>\n<li>Our second step is to add it to the start of our array, to do this we can use <code class=\"language-text\">unshift</code>.</li>\n<li>By inputting the variable we are using to hold our removed element into the parameter of unshift we are adding our element to the front of the array.</li>\n</ul>\n<p><strong>Step 4.</strong></p>\n<p>Now that our for loop has ended and our copied array looks just like how the answer looks, we need to output the answer.</p>\n<p>let rotateRight = function (array, num) {\nlet result = array.slice(0);\nfor (var i = 0; i &#x3C; num; i++) {\nlet ele = result.pop();\nresult.unshift(ele);\n}\nreturn result;\n};</p>\n<p><a href=\"https://gist.github.com/bgoonz/b033f820c35869af0869ce712af68bda/raw/41176af3dce167556337e74744c3156756f470b1/rot2.js\">view raw</a><a href=\"https://gist.github.com/bgoonz/b033f820c35869af0869ce712af68bda#file-rot2-js\">rot2.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<ul>\n<li>We accomplish this by creating a <code class=\"language-text\">return</code> line AFTER the for loop.</li>\n</ul>\n<h3>End Result</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">rotateRight</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> num</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> num<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> ele <span class=\"token operator\">=</span> result<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nresult<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span>ele<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//let arr = [\"a\", \"b\", \"c\", \"d\", \"e\"];</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">rotateRight</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//[\"d\", \"e\", \"a\", \"b\", \"c\"];</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"d\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"e\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> animals <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"wombat\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"koala\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"opossum\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"kangaroo\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">rotateRight</span><span class=\"token punctuation\">(</span>animals<span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//[\"koala\", \"opossum\", \"kangaroo\", \"wombat\"];</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>animals<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//[\"wombat\", \"koala\", \"opossum\", \"kangaroo\"];</span></code></pre></div>\n<p><a href=\"https://gist.github.com/bgoonz/4e2a040cd94006bb887a77a68f4287b9/raw/83bafeb8c66bf5a3653b88a2215fdf67efd9c24a/rotate.js\">view raw</a><a href=\"https://gist.github.com/bgoonz/4e2a040cd94006bb887a77a68f4287b9#file-rotate-js\">rotate.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>"},{"url":"/docs/js-tips/addition/","relativePath":"docs/js-tips/addition.md","relativeDir":"docs/js-tips","base":"addition.md","name":"addition","frontmatter":{"title":"Addition (+)","weight":0,"excerpt":null,"seo":{"title":" Addition (+)","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Addition (+)</h1>\n<p>The addition operator (<code class=\"language-text\">+</code>) produces the sum of numeric operands or string concatenation.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Operator: x + y</code></pre></div>\n<h2>Examples</h2>\n<h3>Numeric addition</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Number + Number -> addition\n1 + 2 // 3\n\n// Boolean + Number -> addition\ntrue + 1 // 2\n\n// Boolean + Boolean -> addition\nfalse + false // 0</code></pre></div>\n<h3>String concatenation</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// String + String -> concatenation\n'foo' + 'bar' // \"foobar\"\n\n// Number + String -> concatenation\n5 + 'foo' // \"5foo\"\n\n// String + Boolean -> concatenation\n'foo' + false // \"foofalse\"</code></pre></div>"},{"url":"/docs/js-tips/any/","relativePath":"docs/js-tips/any.md","relativeDir":"docs/js-tips","base":"any.md","name":"any","frontmatter":{"title":"Promise.any()","weight":0,"excerpt":null,"seo":{"title":" Promise.any()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Promise.any()</h1>\n<p><code class=\"language-text\">Promise.any()</code> takes an iterable of <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> objects and, as soon as one of the promises in the iterable fulfills, returns a single promise that resolves with the value from that promise. If no promises in the iterable fulfill (if all of the given promises are rejected), then the returned promise is rejected with an <a href=\"../aggregateerror\"><code class=\"language-text\">AggregateError</code></a>, a new subclass of <a href=\"../error\"><code class=\"language-text\">Error</code></a> that groups together individual errors. Essentially, this method is the opposite of <a href=\"all\"><code class=\"language-text\">Promise.all()</code></a>.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.any(iterable);</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">iterable</code>\nAn <a href=\"../../iteration_protocols#the_iterable_protocol\">iterable</a> object, such as an <a href=\"../array\"><code class=\"language-text\">Array</code></a>.</p>\n<h3>Return value</h3>\n<ul>\n<li>An <strong>already rejected</strong> <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> if the iterable passed is empty.</li>\n<li>An <strong>asynchronously resolved</strong> <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> if the iterable passed contains no promises.</li>\n<li>A <strong>pending</strong> <a href=\"../promise\"><code class=\"language-text\">Promise</code></a> in all other cases. This returned promise is then resolved/rejected <strong>asynchronously</strong> (as soon as the stack is empty) when any of the promises in the given iterable resolve, or if all the promises have rejected.</li>\n</ul>\n<h2>Description</h2>\n<p>This method is useful for returning the first promise that fulfills. It short-circuits after a promise fulfills, so it does not wait for the other promises to complete once it finds one. Unlike <a href=\"all\"><code class=\"language-text\">Promise.all()</code></a>, which returns an <em>array</em> of fulfillment values, we only get one fulfillment value (assuming at least one promise fulfills). This can be beneficial if we need only one promise to fulfill but we do not care which one does. Note another difference: This method rejects upon receiving an <em>empty iterable</em>, since, truthfully, the iterable contains no items that fulfill.</p>\n<p>Also, unlike <a href=\"race\"><code class=\"language-text\">Promise.race()</code></a>, which returns the first <em>settled</em> value (either fulfillment or rejection), this method returns the first <em>fulfilled</em> value. This method will ignore all rejected promises up until the first promise that fulfils.</p>\n<h3>Fulfillment</h3>\n<p>The returned promise is fulfilled with <strong>the first</strong> resolved value (or non-promise value) in the iterable passed as the argument, whether or not the other promises have rejected.</p>\n<ul>\n<li>If a nonempty <em>iterable</em> is passed, and <strong>any</strong> of the promises fulfill, or are not promises, then the promise returned by this method is fulfilled asynchronously.</li>\n</ul>\n<h3>Rejection</h3>\n<p>If all of the passed-in promises reject, <code class=\"language-text\">Promise.any</code> asynchronously rejects with an <a href=\"../aggregateerror\"><code class=\"language-text\">AggregateError</code></a> object, which extends <a href=\"../error\"><code class=\"language-text\">Error</code></a>, and contains an <code class=\"language-text\">errors</code> property with an array of rejection values.</p>\n<ul>\n<li>If an empty iterable is passed, then the promise returned by this method is rejected synchronously. The rejected reason is an <code class=\"language-text\">AggregateError</code> object whose <code class=\"language-text\">errors</code> property is an empty array.</li>\n</ul>\n<h2>Examples</h2>\n<h3>First to fulfil</h3>\n<p><code class=\"language-text\">Promise.any()</code> resolves with the first promise to fulfil, even if a promise rejects first. This is in contrast to <a href=\"race\"><code class=\"language-text\">Promise.race()</code></a>, which resolves or rejects with the first promise to settle.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const pErr = new Promise((resolve, reject) => {\n  reject(\"Always fails\");\n});\n\nconst pSlow = new Promise((resolve, reject) => {\n  setTimeout(resolve, 500, \"Done eventually\");\n});\n\nconst pFast = new Promise((resolve, reject) => {\n  setTimeout(resolve, 100, \"Done quick\");\n});\n\nPromise.any([pErr, pSlow, pFast]).then((value) => {\n  console.log(value);\n  // pFast fulfils first\n})\n// expected output: \"Done quick\"</code></pre></div>\n<h3>Rejections with AggregateError</h3>\n<p><code class=\"language-text\">Promise.any()</code> rejects with an <a href=\"../aggregateerror\"><code class=\"language-text\">AggregateError</code></a> if no promise fulfils.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const pErr = new Promise((resolve, reject) => {\n  reject('Always fails');\n});\n\nPromise.any([pErr]).catch((err) => {\n  console.log(err);\n})\n// expected output: \"AggregateError: No Promise in Promise.any was resolved\"</code></pre></div>\n<h3>Displaying the first image loaded</h3>\n<p>In this example, we have a function that fetches an image and returns a blob. We use <code class=\"language-text\">Promise.any()</code> to fetch a couple of images and display the first one available (i.e. whose promise has resolved).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function fetchAndDecode(url) {\n  return fetch(url).then(response => {\n    if(!response.ok) {\n      throw new Error(`HTTP error! status: ${response.status}`);\n    } else {\n      return response.blob();\n    }\n  })\n}\n\nlet coffee = fetchAndDecode('coffee.jpg');\nlet tea = fetchAndDecode('tea.jpg');\n\nPromise.any([coffee, tea]).then(value => {\n  let objectURL = URL.createObjectURL(value);\n  let image = document.createElement('img');\n  image.src = objectURL;\n  document.body.appendChild(image);\n})\n.catch(e => {\n  console.log(e.message);\n});</code></pre></div>"},{"url":"/docs/js-tips/array/","relativePath":"docs/js-tips/array.md","relativeDir":"docs/js-tips","base":"array.md","name":"array","frontmatter":{"title":"Array","weight":0,"excerpt":null,"seo":{"title":"Javascript Arrays","description":"class is a global object that is used in the construction of arrays; which are high-level, list-like objects.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Array</h1>\n<p>Arrays are everywhere in JavaScript and with the new <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator\">spread operators</a> introduced in ECMAScript 6, you can do awesome things with them. In this post I will show you 3 useful tricks you can use when programming.</p>\n<h3>1. Iterating through an empty array</h3>\n<p>JavaScript arrays are sparse in nature in that there are a lot of holes in them. Try creating an array using the Array's constructor and you will see what I mean.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">[</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You may find that iterating over a sparse array to apply a certain transformation is hard.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token operator\">></span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">elem<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">[</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>To solve this, you can use <code class=\"language-text\">Array.apply</code> when creating the array.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token function\">Array</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token operator\">></span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">elem<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3>2. Passing an empty parameter to a method</h3>\n<p>If you want to call a method and ignore one of its parameters, then JavaScript will complain if you keep it empty.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">method</span><span class=\"token punctuation\">(</span><span class=\"token string\">'parameter1'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token string\">'parameter3'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nUncaught SyntaxError<span class=\"token operator\">:</span> Unexpected token <span class=\"token punctuation\">,</span></code></pre></div>\n<p>A workaround that people usually resort to is to pass either <code class=\"language-text\">null</code> or <code class=\"language-text\">undefined</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">method</span><span class=\"token punctuation\">(</span><span class=\"token string\">'parameter1'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'parameter3'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// or</span>\n<span class=\"token function\">method</span><span class=\"token punctuation\">(</span><span class=\"token string\">'parameter1'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'parameter3'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>I personally don't like using <code class=\"language-text\">null</code> since JavaScript treats it as an object and that's just weird. With the introduction of spread operators in ES6, there is a neater way of passing empty parameters to a method. As previously mentioned, arrays are sparse in nature and so passing empty values to it is totally okay. We'll use this to our advantage.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">method</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span><span class=\"token punctuation\">[</span><span class=\"token string\">'parameter1'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token string\">'parameter3'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// works!</span></code></pre></div>\n<h3>3. Unique array values</h3>\n<p>I always wonder why the Array constructor does not have a designated method to facilitate the use of unique array values. Spread operators are here for the rescue. Use spread operators with the <code class=\"language-text\">Set</code> constructor to generate unique array values.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The JavaScript <code class=\"language-text\">Array</code> class is a global object that is used in the construction of arrays; which are high-level, list-like objects.</p>\n<h2>Description</h2>\n<p>Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Neither the length of a JavaScript array nor the types of its elements are fixed. Since an array's length can change at any time, and data can be stored at non-contiguous locations in the array, JavaScript arrays are not guaranteed to be dense; this depends on how the programmer chooses to use them. In general, these are convenient characteristics; but if these features are not desirable for your particular use, you might consider using typed arrays.</p>\n<p>Arrays cannot use strings as element indexes (as in an <a href=\"https://en.wikipedia.org/wiki/Associative_array\">associative array</a>) but must use integers. Setting or accessing via non-integers using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#objects_and_properties\">bracket notation</a> (or <a href=\"../operators/property_accessors\">dot notation</a>) will not set or retrieve an element from the array list itself, but will set or access a variable associated with that array's <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#properties\">object property collection</a>. The array's object properties and list of array elements are separate, and the array's <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections#array_methods\">traversal and mutation operations</a> cannot be applied to these named properties.</p>\n<h3>Common operations</h3>\n<p><strong>Create an Array</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let fruits = ['Apple', 'Banana']\n\nconsole.log(fruits.length)\n// 2</code></pre></div>\n<p><strong>Access an Array item using the index position</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let first = fruits[0]\n// Apple\n\nlet last = fruits[fruits.length - 1]\n// Banana</code></pre></div>\n<p><strong>Loop over an Array</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fruits.forEach(function(item, index, array) {\n  console.log(item, index)\n})\n// Apple 0\n// Banana 1</code></pre></div>\n<p><strong>Add an item to the end of an Array</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let newLength = fruits.push('Orange')\n// [\"Apple\", \"Banana\", \"Orange\"]</code></pre></div>\n<p><strong>Remove an item from the end of an Array</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let last = fruits.pop() // remove Orange (from the end)\n// [\"Apple\", \"Banana\"]</code></pre></div>\n<p><strong>Remove an item from the beginning of an Array</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let first = fruits.shift() // remove Apple from the front\n// [\"Banana\"]</code></pre></div>\n<p><strong>Add an item to the beginning of an Array</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let newLength = fruits.unshift('Strawberry') // add to the front\n// [\"Strawberry\", \"Banana\"]</code></pre></div>\n<p><strong>Find the index of an item in the Array</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fruits.push('Mango')\n// [\"Strawberry\", \"Banana\", \"Mango\"]\n\nlet pos = fruits.indexOf('Banana')\n// 1</code></pre></div>\n<p><strong>Remove an item by index position</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let removedItem = fruits.splice(pos, 1) // this is how to remove an item\n\n// [\"Strawberry\", \"Mango\"]</code></pre></div>\n<p><strong>Remove items from an index position</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let vegetables = ['Cabbage', 'Turnip', 'Radish', 'Carrot']\nconsole.log(vegetables)\n// [\"Cabbage\", \"Turnip\", \"Radish\", \"Carrot\"]\n\nlet pos = 1\nlet n = 2\n\nlet removedItems = vegetables.splice(pos, n)\n// this is how to remove items, n defines the number of items to be removed,\n// starting at the index position specified by pos and progressing toward the end of array.\n\nconsole.log(vegetables)\n// [\"Cabbage\", \"Carrot\"] (the original array is changed)\n\nconsole.log(removedItems)\n// [\"Turnip\", \"Radish\"]</code></pre></div>\n<p><strong>Copy an Array</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let shallowCopy = fruits.slice() // this is how to make a copy\n// [\"Strawberry\", \"Mango\"]</code></pre></div>\n<h3>Accessing array elements</h3>\n<p>JavaScript arrays are zero-indexed. The first element of an array is at index <code class=\"language-text\">0</code>, and the last element is at the index value equal to the value of the array's <a href=\"array/length\"><code class=\"language-text\">length</code></a> property minus <code class=\"language-text\">1</code>.</p>\n<p>Using an invalid index number returns <code class=\"language-text\">undefined</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let arr = ['this is the first element', 'this is the second element', 'this is the last element']\nconsole.log(arr[0])              // logs 'this is the first element'\nconsole.log(arr[1])              // logs 'this is the second element'\nconsole.log(arr[arr.length - 1]) // logs 'this is the last element'</code></pre></div>\n<p>Array elements are object properties in the same way that <code class=\"language-text\">toString</code> is a property (to be specific, however, <code class=\"language-text\">toString()</code> is a method). Nevertheless, trying to access an element of an array as follows throws a syntax error because the property name is not valid:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(arr.0) // a syntax error</code></pre></div>\n<p>There is nothing special about JavaScript arrays and the properties that cause this. JavaScript properties that begin with a digit cannot be referenced with dot notation and must be accessed using bracket notation.</p>\n<p>For example, if you had an object with a property named <code class=\"language-text\">3d</code>, it can only be referenced using bracket notation.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]\nconsole.log(years.0)   // a syntax error\nconsole.log(years[0])  // works properly\n\nrenderer.3d.setTexture(model, 'character.png')     // a syntax error\nrenderer['3d'].setTexture(model, 'character.png')  // works properly</code></pre></div>\n<p>In the <code class=\"language-text\">3d</code> example, <code class=\"language-text\">'3d'</code> <em>had</em> to be quoted (because it begins with a digit). But it's also possible to quote the array indexes as well (e.g., <code class=\"language-text\">years['2']</code> instead of <code class=\"language-text\">years[2]</code>), although it's not necessary.</p>\n<p>The <code class=\"language-text\">2</code> in <code class=\"language-text\">years[2]</code> is coerced into a string by the JavaScript engine through an implicit <code class=\"language-text\">toString</code> conversion. As a result, <code class=\"language-text\">'2'</code> and <code class=\"language-text\">'02'</code> would refer to two different slots on the <code class=\"language-text\">years</code> object, and the following example could be <code class=\"language-text\">true</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(years['2'] != years['02'])</code></pre></div>\n<h3>Relationship between length and numerical properties</h3>\n<p>A JavaScript array's <a href=\"array/length\"><code class=\"language-text\">length</code></a> property and numerical properties are connected.</p>\n<p>Several of the built-in array methods (e.g., <a href=\"array/join\"><code class=\"language-text\">join()</code></a>, <a href=\"array/slice\"><code class=\"language-text\">slice()</code></a>, <a href=\"array/indexof\"><code class=\"language-text\">indexOf()</code></a>, etc.) take into account the value of an array's <a href=\"array/length\"><code class=\"language-text\">length</code></a> property when they're called.</p>\n<p>Other methods (e.g., <a href=\"array/push\"><code class=\"language-text\">push()</code></a>, <a href=\"array/splice\"><code class=\"language-text\">splice()</code></a>, etc.) also result in updates to an array's <a href=\"array/length\"><code class=\"language-text\">length</code></a> property.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const fruits = []\nfruits.push('banana', 'apple', 'peach')\n\nconsole.log(fruits.length) // 3</code></pre></div>\n<p>When setting a property on a JavaScript array when the property is a valid array index and that index is outside the current bounds of the array, the engine will update the array's <a href=\"array/length\"><code class=\"language-text\">length</code></a> property accordingly:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fruits[5] = 'mango'\nconsole.log(fruits[5])            // 'mango'\nconsole.log(Object.keys(fruits))  // ['0', '1', '2', '5']\nconsole.log(fruits.length)        // 6</code></pre></div>\n<p>Increasing the <a href=\"array/length\"><code class=\"language-text\">length</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fruits.length = 10\nconsole.log(fruits)              // ['banana', 'apple', 'peach', empty x 2, 'mango', empty x 4]\nconsole.log(Object.keys(fruits)) // ['0', '1', '2', '5']\nconsole.log(fruits.length)       // 10\nconsole.log(fruits[8])           // undefined</code></pre></div>\n<p>Decreasing the <a href=\"array/length\"><code class=\"language-text\">length</code></a> property does, however, delete elements.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fruits.length = 2\nconsole.log(Object.keys(fruits)) // ['0', '1']\nconsole.log(fruits.length)       // 2</code></pre></div>\n<p>This is explained further on the <a href=\"array/length\"><code class=\"language-text\">Array.length</code></a> page.</p>\n<h3>Creating an array using the result of a match</h3>\n<p>The result of a match between a <a href=\"regexp\"><code class=\"language-text\">RegExp</code></a> and a string can create a JavaScript array. This array has properties and elements which provide information about the match. Such an array is returned by <a href=\"regexp/exec\"><code class=\"language-text\">RegExp.exec()</code></a>, <a href=\"string/match\"><code class=\"language-text\">String.match()</code></a>, and <a href=\"string/replace\"><code class=\"language-text\">String.replace()</code></a>.</p>\n<p>To help explain these properties and elements, see this example and then refer to the table below:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Match one d followed by one or more b's followed by one d\n// Remember matched b's and the following d\n// Ignore case\n\nconst myRe = /d(b+)(d)/i\nconst myArray = myRe.exec('cdbBdbsbz')</code></pre></div>\n<p>The properties and elements returned from this match are as follows:</p>\n<table>\n<thead>\n<tr class=\"header\">\n<th>Property/Element</th>\n<th>Description</th>\n<th>Example</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td>\n<code>input</code>\n<br/>\n<p><span class=\"badge inline readonly\">Read only </span></p>\n</td>\n<td>The original string against which the regular expression was matched.</td>\n<td>\n<code>\"cdbBdbsbz\"</code>\n</td>\n</tr>\n<tr class=\"even\">\n<td>\n<code>index</code>\n<br/>\n<p><span class=\"badge inline readonly\">Read only </span></p>\n</td>\n<td>The zero-based index of the match in the string.</td>\n<td>\n<code>1</code>\n</td>\n</tr>\n<tr class=\"odd\">\n<td>\n<code>[0]</code>\n<br/>\n<p><span class=\"badge inline readonly\">Read only </span></p>\n</td>\n<td>The last matched characters.</td>\n<td>\n<code>\"dbBd\"</code>\n</td>\n</tr>\n<tr class=\"even\">\n<td>\n<code>[1], ...[n]</code>\n<br/>\n<p><span class=\"badge inline readonly\">Read only </span></p>\n</td>\n<td>Elements that specify the parenthesized substring matches (if included) in the regular expression. The number of possible parenthesized substrings is unlimited.</td>\n<td>\n<code>[1]: \"bB\" [2]: \"d\"</code>\n</td>\n</tr>\n</tbody>\n</table>\n<h2>Constructor</h2>\n<p><a href=\"array/array\"><code class=\"language-text\">Array()</code></a>\nCreates a new <code class=\"language-text\">Array</code> object.</p>\n<h2>Static properties</h2>\n<p><a href=\"array/@@species\"><code class=\"language-text\">get Array[@@species]</code></a>\nThe constructor function is used to create derived objects.</p>\n<h2>Static methods</h2>\n<p><a href=\"array/from\"><code class=\"language-text\">Array.from()</code></a>\nCreates a new <code class=\"language-text\">Array</code> instance from an array-like or iterable object.</p>\n<p><a href=\"array/isarray\"><code class=\"language-text\">Array.isArray()</code></a>\nReturns <code class=\"language-text\">true</code> if the argument is an array, or <code class=\"language-text\">false</code> otherwise.</p>\n<p><a href=\"array/of\"><code class=\"language-text\">Array.of()</code></a>\nCreates a new <code class=\"language-text\">Array</code> instance with a variable number of arguments, regardless of number or type of the arguments.</p>\n<h2>Instance properties</h2>\n<p><a href=\"array/length\"><code class=\"language-text\">Array.prototype.length</code></a>\nReflects the number of elements in an array.</p>\n<p><a href=\"array/@@unscopables\"><code class=\"language-text\">Array.prototype[@@unscopables]</code></a>\nA symbol containing property names to exclude from a <a href=\"../statements/with\"><code class=\"language-text\">with</code></a> binding scope.</p>\n<h2>Instance methods</h2>\n<p><a href=\"array/at\"><code class=\"language-text\">Array.prototype.at()</code></a><span class=\"icon experimental\" viewbox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\" role=\"img\"> This is an experimental API that should not be used in production code. </span>\nReturns the array item at the given index. Accepts negative integers, which count back from the last item.</p>\n<p><a href=\"array/concat\"><code class=\"language-text\">Array.prototype.concat()</code></a>\nReturns a new array that is this array joined with other array(s) and/or value(s).</p>\n<p><a href=\"array/copywithin\"><code class=\"language-text\">Array.prototype.copyWithin()</code></a>\nCopies a sequence of array elements within the array.</p>\n<p><a href=\"array/entries\"><code class=\"language-text\">Array.prototype.entries()</code></a>\nReturns a new <code class=\"language-text\">Array Iterator</code> object that contains the key/value pairs for each index in the array.</p>\n<p><a href=\"array/every\"><code class=\"language-text\">Array.prototype.every()</code></a>\nReturns <code class=\"language-text\">true</code> if every element in this array satisfies the testing function.</p>\n<p><a href=\"array/fill\"><code class=\"language-text\">Array.prototype.fill()</code></a>\nFills all the elements of an array from a start index to an end index with a static value.</p>\n<p><a href=\"array/filter\"><code class=\"language-text\">Array.prototype.filter()</code></a>\nReturns a new array containing all elements of the calling array for which the provided filtering function returns <code class=\"language-text\">true</code>.</p>\n<p><a href=\"array/find\"><code class=\"language-text\">Array.prototype.find()</code></a>\nReturns the found <code class=\"language-text\">element</code> in the array, if some element in the array satisfies the testing function, or <code class=\"language-text\">undefined</code> if not found.</p>\n<p><a href=\"array/findindex\"><code class=\"language-text\">Array.prototype.findIndex()</code></a>\nReturns the found index in the array, if an element in the array satisfies the testing function, or <code class=\"language-text\">-1</code> if not found.</p>\n<p><a href=\"array/foreach\"><code class=\"language-text\">Array.prototype.forEach()</code></a>\nCalls a function for each element in the array.</p>\n<p><a href=\"array/includes\"><code class=\"language-text\">Array.prototype.includes()</code></a>\nDetermines whether the array contains a value, returning <code class=\"language-text\">true</code> or <code class=\"language-text\">false</code> as appropriate.</p>\n<p><a href=\"array/indexof\"><code class=\"language-text\">Array.prototype.indexOf()</code></a>\nReturns the first (least) index of an element within the array equal to an element, or <code class=\"language-text\">-1</code> if none is found.</p>\n<p><a href=\"array/join\"><code class=\"language-text\">Array.prototype.join()</code></a>\nJoins all elements of an array into a string.</p>\n<p><a href=\"array/keys\"><code class=\"language-text\">Array.prototype.keys()</code></a>\nReturns a new <code class=\"language-text\">Array Iterator</code> that contains the keys for each index in the array.</p>\n<p><a href=\"array/lastindexof\"><code class=\"language-text\">Array.prototype.lastIndexOf()</code></a>\nReturns the last (greatest) index of an element within the array equal to an element, or <code class=\"language-text\">-1</code> if none is found.</p>\n<p><a href=\"array/map\"><code class=\"language-text\">Array.prototype.map()</code></a>\nReturns a new array containing the results of calling a function on every element in this array.</p>\n<p><a href=\"array/pop\"><code class=\"language-text\">Array.prototype.pop()</code></a>\nRemoves the last element from an array and returns that element.</p>\n<p><a href=\"array/push\"><code class=\"language-text\">Array.prototype.push()</code></a>\nAdds one or more elements to the end of an array, and returns the new <code class=\"language-text\">length</code> of the array.</p>\n<p><a href=\"array/reduce\"><code class=\"language-text\">Array.prototype.reduce()</code></a>\nApply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.</p>\n<p><a href=\"array/reduceright\"><code class=\"language-text\">Array.prototype.reduceRight()</code></a>\nApply a function against an accumulator> and each value of the array (from right-to-left) as to reduce it to a single value.</p>\n<p><a href=\"array/reverse\"><code class=\"language-text\">Array.prototype.reverse()</code></a>\nReverses the order of the elements of an array <em>in place</em>. (First becomes the last, last becomes first.)</p>\n<p><a href=\"array/shift\"><code class=\"language-text\">Array.prototype.shift()</code></a>\nRemoves the first element from an array and returns that element.</p>\n<p><a href=\"array/slice\"><code class=\"language-text\">Array.prototype.slice()</code></a>\nExtracts a section of the calling array and returns a new array.</p>\n<p><a href=\"array/some\"><code class=\"language-text\">Array.prototype.some()</code></a>\nReturns <code class=\"language-text\">true</code> if at least one element in this array satisfies the provided testing function.</p>\n<p><a href=\"array/sort\"><code class=\"language-text\">Array.prototype.sort()</code></a>\nSorts the elements of an array in place and returns the array.</p>\n<p><a href=\"array/splice\"><code class=\"language-text\">Array.prototype.splice()</code></a>\nAdds and/or removes elements from an array.</p>\n<p><a href=\"array/tolocalestring\"><code class=\"language-text\">Array.prototype.toLocaleString()</code></a>\nReturns a localized string representing the array and its elements. Overrides the <a href=\"object/tolocalestring\"><code class=\"language-text\">Object.prototype.toLocaleString()</code></a> method.</p>\n<p><a href=\"array/tostring\"><code class=\"language-text\">Array.prototype.toString()</code></a>\nReturns a string representing the array and its elements. Overrides the <a href=\"object/tostring\"><code class=\"language-text\">Object.prototype.toString()</code></a> method.</p>\n<p><a href=\"array/unshift\"><code class=\"language-text\">Array.prototype.unshift()</code></a>\nAdds one or more elements to the front of an array, and returns the new <code class=\"language-text\">length</code> of the array.</p>\n<p><a href=\"array/values\"><code class=\"language-text\">Array.prototype.values()</code></a>\nReturns a new <code class=\"language-text\">Array Iterator</code> object that contains the values for each index in the array.</p>\n<p><a href=\"array/@@iterator\"><code class=\"language-text\">Array.prototype[@@iterator]()</code></a>\nReturns a new <code class=\"language-text\">Array Iterator</code> object that contains the values for each index in the array.</p>\n<h2>Examples</h2>\n<h3>Creating an array</h3>\n<p>The following example creates an array, <code class=\"language-text\">msgArray</code>, with a length of <code class=\"language-text\">0</code>, then assigns values to <code class=\"language-text\">msgArray[0]</code> and <code class=\"language-text\">msgArray[99]</code>, changing the <code class=\"language-text\">length</code> of the array to <code class=\"language-text\">100</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let msgArray = []\nmsgArray[0] = 'Hello'\nmsgArray[99] = 'world'\n\nif (msgArray.length === 100) {\n  console.log('The length is 100.')\n}</code></pre></div>\n<h3>Creating a two-dimensional array</h3>\n<p>The following creates a chessboard as a two-dimensional array of strings. The first move is made by copying the <code class=\"language-text\">'p'</code> in <code class=\"language-text\">board[6][4]</code> to <code class=\"language-text\">board[4][4]</code>. The old position at <code class=\"language-text\">[6][4]</code> is made blank.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let board = [\n  ['R','N','B','Q','K','B','N','R'],\n  ['P','P','P','P','P','P','P','P'],\n  [' ',' ',' ',' ',' ',' ',' ',' '],\n  [' ',' ',' ',' ',' ',' ',' ',' '],\n  [' ',' ',' ',' ',' ',' ',' ',' '],\n  [' ',' ',' ',' ',' ',' ',' ',' '],\n  ['p','p','p','p','p','p','p','p'],\n  ['r','n','b','q','k','b','n','r'] ]\n\nconsole.log(board.join('\\n') + '\\n\\n')\n\n// Move King's Pawn forward 2\nboard[4][4] = board[6][4]\nboard[6][4] = ' '\nconsole.log(board.join('\\n'))</code></pre></div>\n<p>Here is the output:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">R,N,B,Q,K,B,N,R\nP,P,P,P,P,P,P,P\n , , , , , , ,\n , , , , , , ,\n , , , , , , ,\n , , , , , , ,\np,p,p,p,p,p,p,p\nr,n,b,q,k,b,n,r\n\nR,N,B,Q,K,B,N,R\nP,P,P,P,P,P,P,P\n , , , , , , ,\n , , , , , , ,\n , , , ,p, , ,\n , , , , , , ,\np,p,p,p, ,p,p,p\nr,n,b,q,k,b,n,r</code></pre></div>\n<h3>Using an array to tabulate a set of values</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">values = []\nfor (let x = 0; x &lt; 10; x++){\n values.push([\n  2 ** x,\n  2 * x ** 2\n ])\n}\nconsole.table(values)</code></pre></div>\n<p>Results in</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// The first column is the index\n0   1   0\n1   2   2\n2   4   8\n3   8   18\n4   16  32\n5   32  50\n6   64  72\n7   128 98\n8   256 128\n9   512 162</code></pre></div>"},{"url":"/docs/js-tips/bad_radix/","relativePath":"docs/js-tips/bad_radix.md","relativeDir":"docs/js-tips","base":"bad_radix.md","name":"bad_radix","frontmatter":{"title":"RangeError","weight":0,"excerpt":null,"seo":{"title":"RangeError radix must be an integer","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>RangeError: radix must be an integer</h1>\n<p>The JavaScript exception \"radix must be an integer at least 2 and no greater than 36\" occurs when the optional <code class=\"language-text\">radix</code> parameter of the <a href=\"../global_objects/number/tostring\"><code class=\"language-text\">Number.prototype.toString()</code></a> or the <a href=\"../global_objects/bigint/tostring\"><code class=\"language-text\">BigInt.prototype.toString()</code></a> method was specified and is not between 2 and 36.</p>\n<h2>Message</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">RangeError: invalid argument (Edge)\nRangeError: radix must be an integer at least 2 and no greater than 36 (Firefox)\nRangeError: toString() radix argument must be between 2 and 36 (Chrome)</code></pre></div>\n<h2>Error type</h2>\n<p><a href=\"../global_objects/rangeerror\"><code class=\"language-text\">RangeError</code></a></p>\n<h2>What went wrong?</h2>\n<p>The optional <code class=\"language-text\">radix</code> parameter of the <a href=\"../global_objects/number/tostring\"><code class=\"language-text\">Number.prototype.toString()</code></a> or the <a href=\"../global_objects/bigint/tostring\"><code class=\"language-text\">BigInt.prototype.toString()</code></a> method was specified. Its value must be an integer (a number) between 2 and 36, specifying the base of the number system to be used for representing numeric values. For example, the decimal (base 10) number 169 is represented in hexadecimal (base 16) as A9.</p>\n<p>Why is this parameter's value limited to 36? A radix that is larger than 10 uses alphabetical characters as digits; therefore, the radix can't be larger than 36, since the Latin alphabet (used by English and many other languages) only has 26 characters.</p>\n<p>The most common radixes:</p>\n<ul>\n<li>2 for <a href=\"https://en.wikipedia.org/wiki/Binary_number\">binary numbers</a>,</li>\n<li>8 for <a href=\"https://en.wikipedia.org/wiki/Octal\">octal numbers</a>,</li>\n<li>10 for <a href=\"https://en.wikipedia.org/wiki/Decimal\">decimal numbers</a>,</li>\n<li>16 for <a href=\"https://en.wikipedia.org/wiki/Hexadecimal\">hexadecimal numbers</a>.</li>\n</ul>\n<h2>Examples</h2>\n<h3>Invalid cases</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(42).toString(0);\n(42).toString(1);\n(42).toString(37);\n(42).toString(150);\n// You cannot use a string like this for formatting:\n(12071989).toString('MM-dd-yyyy');</code></pre></div>\n<h3>Valid cases</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(42).toString(2);     // \"101010\" (binary)\n(13).toString(8);     // \"15\"     (octal)\n(0x42).toString(10);  // \"66\"     (decimal)\n(100000).toString(16) // \"186a0\"  (hexadecimal)</code></pre></div>"},{"url":"/docs/js-tips/arrow_functions/","relativePath":"docs/js-tips/arrow_functions.md","relativeDir":"docs/js-tips","base":"arrow_functions.md","name":"arrow_functions","frontmatter":{"title":"Arrow function expressions","weight":0,"excerpt":"An arrow function expression is a compact alternative to a traditional function expression, but is limited and can't be used in all situations.","seo":{"title":"Arrow function expressions","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Arrow function expressions</h1>\n<p>An <strong>arrow function expression</strong> is a compact alternative to a traditional <a href=\"../operators/function\">function expression</a>, but is limited and can't be used in all situations.</p>\n<p><strong>Differences &#x26; Limitations:</strong></p>\n<ul>\n<li>Does not have its own bindings to <code class=\"language-text\">this</code> or <code class=\"language-text\">super</code>, and should not be used as <code class=\"language-text\">methods</code>.</li>\n<li>Does not have <code class=\"language-text\">arguments</code>, or <code class=\"language-text\">new.target</code> keywords.</li>\n<li>Not suitable for <code class=\"language-text\">call</code>, <code class=\"language-text\">apply</code> and <a href=\"../global_objects/function/bind\"><code class=\"language-text\">bind</code></a> methods, which generally rely on establishing a <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Scope\">scope</a>.</li>\n<li>Can not be used as <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Constructor\">constructors</a>.</li>\n<li>Can not use <code class=\"language-text\">yield</code>, within its body.</li>\n</ul>\n<h3>Comparing traditional functions to arrow functions</h3>\n<p>Let's decompose a \"traditional function\" down to the simplest \"arrow function\" step-by-step:\nNOTE: Each step along the way is a valid \"arrow function\"</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Traditional Function\nfunction (a){\n  return a + 100;\n}\n\n// Arrow Function Break Down\n\n// 1. Remove the word \"function\" and place arrow between the argument and opening body bracket\n(a) => {\n  return a + 100;\n}\n\n// 2. Remove the body brackets and word \"return\" -- the return is implied.\n(a) => a + 100;\n\n// 3. Remove the argument parentheses\na => a + 100;</code></pre></div>\n<p><strong>Note:</strong> As shown above, the { brackets } and ( parentheses ) and \"return\" are optional, but may be required.</p>\n<p>For example, if you have <strong>multiple arguments</strong> or <strong>no arguments</strong>, you'll need to re-introduce parentheses around the arguments:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Traditional Function\nfunction (a, b){\n  return a + b + 100;\n}\n\n// Arrow Function\n(a, b) => a + b + 100;\n\n// Traditional Function (no arguments)\nlet a = 4;\nlet b = 2;\nfunction (){\n  return a + b + 100;\n}\n\n// Arrow Function (no arguments)\nlet a = 4;\nlet b = 2;\n() => a + b + 100;</code></pre></div>\n<p>Likewise, if the body requires <strong>additional lines</strong> of processing, you'll need to re-introduce brackets <strong>PLUS the \"return\"</strong> (arrow functions do not magically guess what or when you want to \"return\"):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Traditional Function\nfunction (a, b){\n  let chuck = 42;\n  return a + b + chuck;\n}\n\n// Arrow Function\n(a, b) => {\n  let chuck = 42;\n  return a + b + chuck;\n}</code></pre></div>\n<p>And finally, for <strong>named functions</strong> we treat arrow expressions like variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Traditional Function\nfunction bob (a){\n  return a + 100;\n}\n\n// Arrow Function\nlet bob = a => a + 100;</code></pre></div>\n<h2>Syntax</h2>\n<h3>Basic syntax</h3>\n<p>One param. With simple expression return is not needed:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">param => expression</code></pre></div>\n<p>Multiple params require parentheses. With simple expression return is not needed:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(param1, paramN) => expression</code></pre></div>\n<p>Multiline statements require body brackets and return:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">param => {\n  let a = 1;\n  return a + param;\n}</code></pre></div>\n<p>Multiple params require parentheses. Multiline statements require body brackets and return:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(param1, paramN) => {\n   let a = 1;\n   return a + param1 + paramN;\n}</code></pre></div>\n<h3>Advanced syntax</h3>\n<p>To return an object literal expression requires parentheses around expression:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">params => ({foo: \"a\"}) // returning the object {foo: \"a\"}</code></pre></div>\n<p><a href=\"rest_parameters\">Rest parameters</a> are supported:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(a, b, ...r) => expression</code></pre></div>\n<p><a href=\"default_parameters\">Default parameters</a> are supported:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(a=400, b=20, c) => expression</code></pre></div>\n<p><a href=\"../operators/destructuring_assignment\">Destructuring</a> within params supported:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">([a, b] = [10, 20]) => a + b;  // result is 30\n({ a, b } = { a: 10, b: 20 }) => a + b; // result is 30</code></pre></div>\n<h2>Description</h2>\n<h3>Arrow functions used as methods</h3>\n<p>As stated previously, arrow function expressions are best suited for non-method functions. Let's see what happens when we try to use them as methods:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'use strict';\n\nvar obj = { // does not create a new scope\n  i: 10,\n  b: () => console.log(this.i, this),\n  c: function() {\n    console.log(this.i, this);\n  }\n}\n\nobj.b(); // prints undefined, Window {...} (or the global object)\nobj.c(); // prints 10, Object {...}</code></pre></div>\n<p>Arrow functions do not have their own <code class=\"language-text\">this</code>. Another example involving <a href=\"../global_objects/object/defineproperty\"><code class=\"language-text\">Object.defineProperty()</code></a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'use strict';\n\nvar obj = {\n  a: 10\n};\n\nObject.defineProperty(obj, 'b', {\n  get: () => {\n    console.log(this.a, typeof this.a, this); // undefined 'undefined' Window {...} (or the global object)\n    return this.a + 10; // represents global object 'Window', therefore 'this.a' returns 'undefined'\n  }\n});</code></pre></div>\n<h3>call, apply and bind</h3>\n<p>The <code class=\"language-text\">call</code>, <code class=\"language-text\">apply</code> and <a href=\"../global_objects/function/bind\"><code class=\"language-text\">bind</code></a> methods are <strong>NOT suitable</strong> for Arrow functions -- as they were designed to allow methods to execute within different scopes -- because <strong>Arrow functions establish \"this\" based on the scope the Arrow function is defined within.</strong></p>\n<p>For example <code class=\"language-text\">call</code>, <code class=\"language-text\">apply</code> and <a href=\"../global_objects/function/bind\"><code class=\"language-text\">bind</code></a> work as expected with Traditional functions, because we establish the scope for each of the methods:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// ----------------------\n// Traditional Example\n// ----------------------\n// A simplistic object with its very own \"this\".\nvar obj = {\n    num: 100\n}\n\n// Setting \"num\" on window to show how it is NOT used.\nwindow.num = 2020; // yikes!\n\n// A simple traditional function to operate on \"this\"\nvar add = function (a, b, c) {\n  return this.num + a + b + c;\n}\n\n// call\nvar result = add.call(obj, 1, 2, 3) // establishing the scope as \"obj\"\nconsole.log(result) // result 106\n\n// apply\nconst arr = [1, 2, 3]\nvar result = add.apply(obj, arr) // establishing the scope as \"obj\"\nconsole.log(result) // result 106\n\n// bind\nvar result = add.bind(obj) // establishing the scope as \"obj\"\nconsole.log(result(1, 2, 3)) // result 106</code></pre></div>\n<p>With Arrow functions, since our <code class=\"language-text\">add</code> function is essentially created on the <code class=\"language-text\">window</code> (global) scope, it will assume <code class=\"language-text\">this</code> is the window.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// ----------------------\n// Arrow Example\n// ----------------------\n\n// A simplistic object with its very own \"this\".\nvar obj = {\n    num: 100\n}\n\n// Setting \"num\" on window to show how it gets picked up.\nwindow.num = 2020; // yikes!\n\n// Arrow Function\nvar add = (a, b, c) => this.num + a + b + c;\n\n// call\nconsole.log(add.call(obj, 1, 2, 3)) // result 2026\n\n// apply\nconst arr = [1, 2, 3]\nconsole.log(add.apply(obj, arr)) // result 2026\n\n// bind\nconst bound = add.bind(obj)\nconsole.log(bound(1, 2, 3)) // result 2026</code></pre></div>\n<p>Perhaps the greatest benefit of using Arrow functions is with DOM-level methods (setTimeout, setInterval, addEventListener) that usually required some kind of closure, call, apply or bind to ensure the function executed in the proper scope.</p>\n<p><strong>Traditional Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var obj = {\n    count : 10,\n    doSomethingLater : function (){\n        setTimeout(function(){ // the function executes on the window scope\n            this.count++;\n            console.log(this.count);\n        }, 300);\n    }\n}\n\nobj.doSomethingLater(); // console prints \"NaN\", because the property \"count\" is not in the window scope.</code></pre></div>\n<p><strong>Arrow Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var obj = {\n    count : 10,\n    doSomethingLater : function(){ // of course, arrow functions are not suited for methods\n        setTimeout( () => { // since the arrow function was created within the \"obj\", it assumes the object's \"this\"\n            this.count++;\n            console.log(this.count);\n        }, 300);\n    }\n}\n\nobj.doSomethingLater();</code></pre></div>\n<h3>No binding of <code class=\"language-text\">arguments</code></h3>\n<p>Arrow functions do not have their own <a href=\"arguments\"><code class=\"language-text\">arguments</code> object</a>. Thus, in this example, <code class=\"language-text\">arguments</code> is a reference to the arguments of the enclosing scope:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var arguments = [1, 2, 3];\nvar arr = () => arguments[0];\n\narr(); // 1\n\nfunction foo(n) {\n  var f = () => arguments[0] + n; // foo's implicit arguments binding. arguments[0] is n\n  return f();\n}\n\nfoo(3); // 3 + 3 = 6</code></pre></div>\n<p>In most cases, using <a href=\"rest_parameters\">rest parameters</a> is a good alternative to using an <code class=\"language-text\">arguments</code> object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function foo(n) {\n  var f = (...args) => args[0] + n;\n  return f(10);\n}\n\nfoo(1); // 11</code></pre></div>\n<h3>Use of the <code class=\"language-text\">new</code> operator</h3>\n<p>Arrow functions cannot be used as constructors and will throw an error when used with <code class=\"language-text\">new</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var Foo = () => {};\nvar foo = new Foo(); // TypeError: Foo is not a constructor</code></pre></div>\n<h3>Use of <code class=\"language-text\">prototype</code> property</h3>\n<p>Arrow functions do not have a <code class=\"language-text\">prototype</code> property.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var Foo = () => {};\nconsole.log(Foo.prototype); // undefined</code></pre></div>\n<h3>Use of the <code class=\"language-text\">yield</code> keyword</h3>\n<p>The <code class=\"language-text\">yield</code> keyword may not be used in an arrow function's body (except when permitted within functions further nested within it). As a consequence, arrow functions cannot be used as generators.</p>\n<h3>Function body</h3>\n<p>Arrow functions can have either a \"concise body\" or the usual \"block body\".</p>\n<p>In a concise body, only an expression is specified, which becomes the implicit return value. In a block body, you must use an explicit <code class=\"language-text\">return</code> statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var func = x => x * x;\n// concise body syntax, implied \"return\"\n\nvar func = (x, y) => { return x + y; };\n// with block body, explicit \"return\" needed</code></pre></div>\n<h3>Returning object literals</h3>\n<p>Keep in mind that returning object literals using the concise body syntax <code class=\"language-text\">params => {object:literal}</code> will not work as expected.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var func = () => { foo: 1 };\n// Calling func() returns undefined!\n\nvar func = () => { foo: function() {} };\n// SyntaxError: function statement requires a name</code></pre></div>\n<p>This is because the code inside braces ({}) is parsed as a sequence of statements (i.e. <code class=\"language-text\">foo</code> is treated like a label, not a key in an object literal).</p>\n<p>You must wrap the object literal in parentheses:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var func = () => ({ foo: 1 });</code></pre></div>\n<h3>Line breaks</h3>\n<p>An arrow function cannot contain a line break between its parameters and its arrow.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var func = (a, b, c)\n  => 1;\n// SyntaxError: expected expression, got '=>'</code></pre></div>\n<p>However, this can be amended by putting the line break after the arrow or using parentheses/braces as seen below to ensure that the code stays pretty and fluffy. You can also put line breaks between arguments.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var func = (a, b, c) =>\n  1;\n\nvar func = (a, b, c) => (\n  1\n);\n\nvar func = (a, b, c) => {\n  return 1\n};\n\nvar func = (\n  a,\n  b,\n  c\n) => 1;\n\n// no SyntaxError thrown</code></pre></div>\n<h3>Parsing order</h3>\n<p>Although the arrow in an arrow function is not an operator, arrow functions have special parsing rules that interact differently with <a href=\"../operators/operator_precedence\">operator precedence</a> compared to regular functions.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">let</span> callback<span class=\"token punctuation\">;</span>\n\n    callback <span class=\"token operator\">=</span> callback <span class=\"token operator\">||</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ok</span>\n\n    callback <span class=\"token operator\">=</span> callback <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// SyntaxError: invalid arrow-function arguments</span>\n\n    callback <span class=\"token operator\">=</span> callback <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// ok</span></code></pre></div>\n<h2>Examples</h2>\n<h3>Basic usage</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token comment\">// An empty arrow function returns undefined</span>\n    <span class=\"token keyword\">let</span> <span class=\"token function-variable function\">empty</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token string\">'foobar'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Returns \"foobar\"</span>\n    <span class=\"token comment\">// (this is an Immediately Invoked Function Expression)</span>\n\n    <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">simple</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">a</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">></span> <span class=\"token number\">15</span> <span class=\"token operator\">?</span> <span class=\"token number\">15</span> <span class=\"token operator\">:</span> a<span class=\"token punctuation\">;</span>\n    <span class=\"token function\">simple</span><span class=\"token punctuation\">(</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 15</span>\n    <span class=\"token function\">simple</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 10</span>\n\n    <span class=\"token keyword\">let</span> <span class=\"token function-variable function\">max</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">></span> b <span class=\"token operator\">?</span> a <span class=\"token operator\">:</span> b<span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Easy array filtering, mapping, ...</span>\n\n    <span class=\"token keyword\">var</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">13</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">18</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">var</span> sum <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// 66</span>\n\n    <span class=\"token keyword\">var</span> even <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">v</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// [6, 0, 18]</span>\n\n    <span class=\"token keyword\">var</span> double <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">v</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// [10, 12, 26, 0, 2, 36, 46]</span>\n\n    <span class=\"token comment\">// More concise promise chains</span>\n    promise<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">b</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Parameterless arrow functions that are visually easier to parse</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I happen sooner'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// deeper code</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I happen later'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/docs/js-tips/async_function/","relativePath":"docs/js-tips/async_function.md","relativeDir":"docs/js-tips","base":"async_function.md","name":"async_function","frontmatter":{"title":"async function","weight":0,"excerpt":null,"seo":{"title":"async function","description":"An async function is a function declared with the async keyword, and the await keyword is permitted within them. The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>async function</h1>\n<p>An async function is a function declared with the <code class=\"language-text\">async</code> keyword, and the <code class=\"language-text\">await</code> keyword is permitted within them. The <code class=\"language-text\">async</code> and <code class=\"language-text\">await</code> keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains.</p>\n<p>Async functions may also be defined <a href=\"../operators/async_function\">as expressions</a>.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function name([param[, param[, ...param]]]) {\n   statements\n}</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">name</code>\nThe function's name.</p>\n<p><code class=\"language-text\">param</code>\nThe name of an argument to be passed to the function.</p>\n<p><code class=\"language-text\">statements</code>\nThe statements comprising the body of the function. The <code class=\"language-text\">await</code> mechanism may be used.</p>\n<h3>Return value</h3>\n<p>A <a href=\"../global_objects/promise\"><code class=\"language-text\">Promise</code></a> which will be resolved with the value returned by the async function, or rejected with an exception thrown from, or uncaught within, the async function.</p>\n<h2>Description</h2>\n<p>Async functions can contain zero or more <a href=\"../operators/await\"><code class=\"language-text\">await</code></a> expressions. Await expressions make promise-returning functions behave as though they're synchronous by suspending execution until the returned promise is fulfilled or rejected. The resolved value of the promise is treated as the return value of the await expression. Use of <code class=\"language-text\">async</code> and <code class=\"language-text\">await</code> enables the use of ordinary <code class=\"language-text\">try</code> / <code class=\"language-text\">catch</code> blocks around asynchronous code.</p>\n<p><strong>Note:</strong> The <code class=\"language-text\">await</code> keyword is only valid inside async functions within regular JavaScript code. If you use it outside of an async function's body, you will get a <a href=\"../global_objects/syntaxerror\"><code class=\"language-text\">SyntaxError</code></a>.</p>\n<p><code class=\"language-text\">await</code> can be used on its own with <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\">JavaScript modules.</a></p>\n<p><strong>Note:</strong> The purpose of <code class=\"language-text\">async</code>/<code class=\"language-text\">await</code> is to simplify the syntax necessary to consume promise-based APIs. The behavior of <code class=\"language-text\">async</code>/<code class=\"language-text\">await</code> is similar to combining <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\">generators</a> and promises.</p>\n<p>Async functions always return a promise. If the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise.</p>\n<p>For example, the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function foo() {\n   return 1\n}</code></pre></div>\n<p>...is similar to:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function foo() {\n   return Promise.resolve(1)\n}</code></pre></div>\n<p><strong>Checking equality with <code class=\"language-text\">Promise.resolve</code> vs <code class=\"language-text\">async</code> return</strong></p>\n<p>Even though the return value of an async function behaves as if it's wrapped in a <code class=\"language-text\">Promise.resolve</code>, they are not equivalent.</p>\n<p>An async function will return a different <em>reference</em>, whereas <code class=\"language-text\">Promise.resolve</code> returns the same reference if the given value is a promise.</p>\n<p>It can be a problem when you want to check the equality of a promise and a return value of an async function.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const p = new Promise((res, rej) => {\n  res(1);\n})\n\nasync function asyncReturn() {\n  return p;\n}\n\nfunction basicReturn() {\n  return Promise.resolve(p);\n}\n\nconsole.log(p === basicReturn()); // true\nconsole.log(p === asyncReturn()); // false</code></pre></div>\n<p>The body of an async function can be thought of as being split by zero or more await expressions. Top-level code, up to and including the first await expression (if there is one), is run synchronously. In this way, an async function without an await expression will run synchronously. If there is an await expression inside the function body, however, the async function will always complete asynchronously.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function foo() {\n   await 1\n}</code></pre></div>\n<p>...is equivalent to:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function foo() {\n   return Promise.resolve(1).then(() => undefined)\n}</code></pre></div>\n<p>Code after each await expression can be thought of as existing in a <code class=\"language-text\">.then</code> callback. In this way a promise chain is progressively constructed with each reentrant step through the function. The return value forms the final link in the chain.</p>\n<p>In the following example, we successively await two promises. Progress moves through function <code class=\"language-text\">foo</code> in three stages.</p>\n<ol>\n<li>The first line of the body of function <code class=\"language-text\">foo</code> is executed synchronously, with the await expression configured with the pending promise. Progress through <code class=\"language-text\">foo</code> is then suspended and control is yielded back to the function that called <code class=\"language-text\">foo</code>.</li>\n<li>Some time later, when the first promise has either been fulfilled or rejected, control moves back into <code class=\"language-text\">foo</code>. The result of the first promise fulfillment (if it was not rejected) is returned from the await expression. Here <code class=\"language-text\">1</code> is assigned to <code class=\"language-text\">result1</code>. Progress continues, and the second await expression is evaluated. Again, progress through <code class=\"language-text\">foo</code> is suspended and control is yielded.</li>\n<li>Some time later, when the second promise has either been fulfilled or rejected, control re-enters <code class=\"language-text\">foo</code>. The result of the second promise resolution is returned from the second await expression. Here <code class=\"language-text\">2</code> is assigned to <code class=\"language-text\">result2</code>. Control moves to the return expression (if any). The default return value of <code class=\"language-text\">undefined</code> is returned as the resolution value of the current promise.</li>\n</ol>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function foo() {\n   const result1 = await new Promise((resolve) => setTimeout(() => resolve('1')))\n   const result2 = await new Promise((resolve) => setTimeout(() => resolve('2')))\n}\nfoo()</code></pre></div>\n<p>Note how the promise chain is not built-up in one go. Instead, the promise chain is constructed in stages as control is successively yielded from and returned to the async function. As a result, we must be mindful of error handling behavior when dealing with concurrent asynchronous operations.</p>\n<p>For example, in the following code an unhandled promise rejection error will be thrown, even if a <code class=\"language-text\">.catch</code> handler has been configured further along the promise chain. This is because <code class=\"language-text\">p2</code> will not be \"wired into\" the promise chain until control returns from <code class=\"language-text\">p1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function foo() {\n   const p1 = new Promise((resolve) => setTimeout(() => resolve('1'), 1000))\n   const p2 = new Promise((_,reject) => setTimeout(() => reject('2'), 500))\n   const results = [await p1, await p2] // Do not do this! Use Promise.all or Promise.allSettled instead.\n}\nfoo().catch(() => {}) // Attempt to swallow all errors...</code></pre></div>\n<h2>Examples</h2>\n<h3>Async functions and execution order</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function resolveAfter2Seconds() {\n  console.log(\"starting slow promise\")\n  return new Promise(resolve => {\n    setTimeout(function() {\n      resolve(\"slow\")\n      console.log(\"slow promise is done\")\n    }, 2000)\n  })\n}\n\nfunction resolveAfter1Second() {\n  console.log(\"starting fast promise\")\n  return new Promise(resolve => {\n    setTimeout(function() {\n      resolve(\"fast\")\n      console.log(\"fast promise is done\")\n    }, 1000)\n  })\n}\n\nasync function sequentialStart() {\n  console.log('==SEQUENTIAL START==')\n\n  // 1. Execution gets here almost instantly\n  const slow = await resolveAfter2Seconds()\n  console.log(slow) // 2. this runs 2 seconds after 1.\n\n  const fast = await resolveAfter1Second()\n  console.log(fast) // 3. this runs 3 seconds after 1.\n}\n\nasync function concurrentStart() {\n  console.log('==CONCURRENT START with await==');\n  const slow = resolveAfter2Seconds() // starts timer immediately\n  const fast = resolveAfter1Second() // starts timer immediately\n\n  // 1. Execution gets here almost instantly\n  console.log(await slow) // 2. this runs 2 seconds after 1.\n  console.log(await fast) // 3. this runs 2 seconds after 1., immediately after 2., since fast is already resolved\n}\n\nfunction concurrentPromise() {\n  console.log('==CONCURRENT START with Promise.all==')\n  return Promise.all([resolveAfter2Seconds(), resolveAfter1Second()]).then((messages) => {\n    console.log(messages[0]) // slow\n    console.log(messages[1]) // fast\n  })\n}\n\nasync function parallel() {\n  console.log('==PARALLEL with await Promise.all==')\n\n  // Start 2 \"jobs\" in parallel and wait for both of them to complete\n  await Promise.all([\n      (async()=>console.log(await resolveAfter2Seconds()))(),\n      (async()=>console.log(await resolveAfter1Second()))()\n  ])\n}\n\nsequentialStart() // after 2 seconds, logs \"slow\", then after 1 more second, \"fast\"\n\n// wait above to finish\nsetTimeout(concurrentStart, 4000) // after 2 seconds, logs \"slow\" and then \"fast\"\n\n// wait again\nsetTimeout(concurrentPromise, 7000) // same as concurrentStart\n\n// wait again\nsetTimeout(parallel, 10000) // truly parallel: after 1 second, logs \"fast\", then after 1 more second, \"slow\"</code></pre></div>\n<h4>await and parallelism</h4>\n<p>In <code class=\"language-text\">sequentialStart</code>, execution suspends 2 seconds for the first <code class=\"language-text\">await</code>, and then another second for the second <code class=\"language-text\">await</code>. The second timer is not created until the first has already fired, so the code finishes after 3 seconds.</p>\n<p>In <code class=\"language-text\">concurrentStart</code>, both timers are created and then <code class=\"language-text\">await</code>ed. The timers run concurrently, which means the code finishes in 2 rather than 3 seconds, i.e. the slowest timer.\nHowever, the <code class=\"language-text\">await</code> calls still run in series, which means the second <code class=\"language-text\">await</code> will wait for the first one to finish. In this case, the result of the fastest timer is processed after the slowest.</p>\n<p>If you wish to safely perform two or more jobs in parallel, you must await a call to <code class=\"language-text\">Promise.all</code>, or <code class=\"language-text\">Promise.allSettled</code>.</p>\n<p><strong>Warning:</strong> The functions <code class=\"language-text\">concurrentStart</code> and <code class=\"language-text\">concurrentPromise</code> are not functionally equivalent.</p>\n<p>In <code class=\"language-text\">concurrentStart</code>, if promise <code class=\"language-text\">fast</code> rejects before promise <code class=\"language-text\">slow</code> is fulfilled, then an unhandled promise rejection error will be raised, regardless of whether the caller has configured a catch clause.</p>\n<p>In <code class=\"language-text\">concurrentPromise,</code> <code class=\"language-text\">Promise.all</code> wires up the promise chain in one go, meaning that the operation will fail-fast regardless of the order of rejection of the promises, and the error will always occur within the configured promise chain, enabling it to be caught in the normal way.</p>\n<h3>Rewriting a Promise chain with an async function</h3>\n<p>An API that returns a <a href=\"../global_objects/promise\"><code class=\"language-text\">Promise</code></a> will result in a promise chain, and it splits the function into many parts. Consider the following code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function getProcessedData(url) {\n  return downloadData(url) // returns a promise\n    .catch(e => {\n      return downloadFallbackData(url)  // returns a promise\n    })\n    .then(v => {\n      return processDataInWorker(v)  // returns a promise\n    })\n}</code></pre></div>\n<p>it can be rewritten with a single async function as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function getProcessedData(url) {\n  let v\n  try {\n    v = await downloadData(url)\n  } catch(e) {\n    v = await downloadFallbackData(url)\n  }\n  return processDataInWorker(v)\n}</code></pre></div>\n<p>In the above example, notice there is no <code class=\"language-text\">await</code> statement after the <code class=\"language-text\">return</code> keyword, although that would be valid too: The return value of an <code class=\"language-text\">async function</code> is implicitly wrapped in <a href=\"../global_objects/promise/resolve\"><code class=\"language-text\">Promise.resolve</code></a> - if it's not already a promise itself (as in this example).</p>\n<p><strong>Note:</strong> The implicit wrapping of return values in <a href=\"../global_objects/promise/resolve\"><code class=\"language-text\">Promise.resolve</code></a> does not imply that <code class=\"language-text\">return await promiseValue</code> is functionally equivalent to <code class=\"language-text\">return promiseValue</code>.</p>\n<p>Consider the following rewrite of the above code. It returns <code class=\"language-text\">null</code> if <code class=\"language-text\">processDataInWorker</code> rejects with an error:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">async function getProcessedData(url) {\n  let v\n  try {\n    v = await downloadData(url)\n  } catch(e) {\n    v = await downloadFallbackData(url)\n  }\n  try {\n    return await processDataInWorker(v)  // Note the `return await` vs. just `return`\n  } catch (e) {\n    return null\n  }\n}</code></pre></div>\n<p>Writing <code class=\"language-text\">return processDataInWorker(v)</code> would have caused the <a href=\"../global_objects/promise\"><code class=\"language-text\">Promise</code></a> returned by the function to reject, instead of resolving to <code class=\"language-text\">null</code> if <code class=\"language-text\">processDataInWorker(v)</code> rejects.</p>\n<p>This highlights the subtle difference between <code class=\"language-text\">return foo;</code> and <code class=\"language-text\">return await foo;</code> — <code class=\"language-text\">return foo</code> immediately returns <code class=\"language-text\">foo</code> and never throws, even if <code class=\"language-text\">foo</code> is a Promise that rejects. <code class=\"language-text\">return await foo</code> will <em>wait</em> for <code class=\"language-text\">foo</code> to resolve or reject if it's a Promise, and throws <strong>before returning</strong> if it rejects.</p>"},{"url":"/docs/js-tips/classes/","relativePath":"docs/js-tips/classes.md","relativeDir":"docs/js-tips","base":"classes.md","name":"classes","frontmatter":{"title":"Classes","weight":0,"excerpt":"Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on prototypes but also have some syntax and semantics that are not shared with ES5 class-like semantics.","seo":{"title":"Classes","description":"Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on prototypes but also have some syntax and semantics that are not shared with ES5 class-like semantics.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Classes</h1>\n<p>Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on prototypes but also have some syntax and semantics that are not shared with ES5 class-like semantics.</p>\n<h2>Defining classes</h2>\n<p>Classes are in fact \"special functions\", and just as you can define <a href=\"operators/function\">function expressions</a> and <a href=\"statements/function\">function declarations</a>, the class syntax has two components: <a href=\"operators/class\">class expressions</a> and <a href=\"statements/class\">class declarations</a>.</p>\n<h3>Class declarations</h3>\n<p>One way to define a class is using a <strong>class declaration</strong>. To declare a class, you use the <code class=\"language-text\">class</code> keyword with the name of the class (\"Rectangle\" here).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Rectangle {\n  constructor(height, width) {\n    this.height = height;\n    this.width = width;\n  }\n}</code></pre></div>\n<h4>Hoisting</h4>\n<p>An important difference between <strong>function declarations</strong> and <strong>class declarations</strong> is that function declarations are <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Hoisting\">hoisted</a> and class declarations are not. You first need to declare your class and then access it, otherwise code like the following will throw a <a href=\"global_objects/referenceerror\"><code class=\"language-text\">ReferenceError</code></a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const p = new Rectangle(); // ReferenceError\n\nclass Rectangle {}</code></pre></div>\n<h3>Class expressions</h3>\n<p>A <strong>class expression</strong> is another way to define a class. Class expressions can be named or unnamed. The name given to a named class expression is local to the class's body. (it can be retrieved through the class's (not an instance's) <a href=\"global_objects/function/name\"><code class=\"language-text\">name</code></a> property, though).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// unnamed\nlet Rectangle = class {\n  constructor(height, width) {\n    this.height = height;\n    this.width = width;\n  }\n};\nconsole.log(Rectangle.name);\n// output: \"Rectangle\"\n\n// named\nlet Rectangle = class Rectangle2 {\n  constructor(height, width) {\n    this.height = height;\n    this.width = width;\n  }\n};\nconsole.log(Rectangle.name);\n// output: \"Rectangle2\"</code></pre></div>\n<p><strong>Note:</strong> Class <strong>expressions</strong> are subject to the same hoisting restrictions as described in the <a href=\"#class_declarations\">Class declarations</a> section.</p>\n<h2>Class body and method definitions</h2>\n<p>The body of a class is the part that is in curly brackets <code class=\"language-text\">{}</code>. This is where you define class members, such as methods or constructor.</p>\n<h3>Strict mode</h3>\n<p>The body of a class is executed in <a href=\"strict_mode\">strict mode</a>, i.e., code written here is subject to stricter syntax for increased performance, some otherwise silent errors will be thrown, and certain keywords are reserved for future versions of ECMAScript.</p>\n<h3>Constructor</h3>\n<p>The <a href=\"classes/constructor\">constructor</a> method is a special method for creating and initializing an object created with a <code class=\"language-text\">class</code>. There can only be one special method with the name \"constructor\" in a class. A <a href=\"global_objects/syntaxerror\"><code class=\"language-text\">SyntaxError</code></a> will be thrown if the class contains more than one occurrence of a <code class=\"language-text\">constructor</code> method.</p>\n<p>A constructor can use the <code class=\"language-text\">super</code> keyword to call the constructor of the super class.</p>\n<h3>Prototype methods</h3>\n<p>See also <a href=\"functions/method_definitions\">method definitions</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Rectangle {\n  constructor(height, width) {\n    this.height = height;\n    this.width = width;\n  }\n  // Getter\n  get area() {\n    return this.calcArea();\n  }\n  // Method\n  calcArea() {\n    return this.height * this.width;\n  }\n}\n\nconst square = new Rectangle(10, 10);\n\nconsole.log(square.area); // 100</code></pre></div>\n<h3>Generator methods</h3>\n<p>See also <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\">Iterators and generators</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Polygon {\n  constructor(...sides) {\n    this.sides = sides;\n  }\n  // Method\n  *getSides() {\n    for(const side of this.sides){\n      yield side;\n    }\n  }\n}\n\nconst pentagon = new Polygon(1,2,3,4,5);\n\nconsole.log([...pentagon.getSides()]); // [1,2,3,4,5]</code></pre></div>\n<h3>Static methods and properties</h3>\n<p>The <a href=\"classes/static\">static</a> keyword defines a static method or property for a class. Static members (properties and methods) are called without <a href=\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects#the_object_(class_instance)\">instantiating</a> their class and <strong>cannot</strong> be called through a class instance. Static methods are often used to create utility functions for an application, whereas static properties are useful for caches, fixed-configuration, or any other data you don't need to be replicated across instances.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Point {\n  constructor(x, y) {\n    this.x = x;\n    this.y = y;\n  }\n\n  static displayName = \"Point\";\n  static distance(a, b) {\n    const dx = a.x - b.x;\n    const dy = a.y - b.y;\n\n    return Math.hypot(dx, dy);\n  }\n}\n\nconst p1 = new Point(5, 5);\nconst p2 = new Point(10, 10);\np1.displayName; // undefined\np1.distance;    // undefined\np2.displayName; // undefined\np2.distance;    // undefined\n\nconsole.log(Point.displayName);      // \"Point\"\nconsole.log(Point.distance(p1, p2)); // 7.0710678118654755</code></pre></div>\n<h3>Binding <code class=\"language-text\">this</code> with prototype and static methods</h3>\n<p>When a static or prototype method is called without a value for <a href=\"operators/this\"><code class=\"language-text\">this</code></a>, such as by assigning the method to a variable and then calling it, the <code class=\"language-text\">this</code> value will be <code class=\"language-text\">undefined</code> inside the method. This behavior will be the same even if the <a href=\"strict_mode\"><code class=\"language-text\">\"use strict\"</code></a> directive isn't present, because code within the <code class=\"language-text\">class</code> body's syntactic boundary is always executed in strict mode.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Animal {\n  speak() {\n    return this;\n  }\n  static eat() {\n    return this;\n  }\n}\n\nlet obj = new Animal();\nobj.speak(); // the Animal object\nlet speak = obj.speak;\nspeak(); // undefined\n\nAnimal.eat() // class Animal\nlet eat = Animal.eat;\neat(); // undefined</code></pre></div>\n<p>If we rewrite the above using traditional function-based syntax in non-strict mode, then <code class=\"language-text\">this</code> method calls are automatically bound to the initial <code class=\"language-text\">this</code> value, which by default is the <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Global_object\">global object</a>. In strict mode, autobinding will not happen; the value of <code class=\"language-text\">this</code> remains as passed.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Animal() { }\n\nAnimal.prototype.speak = function() {\n  return this;\n}\n\nAnimal.eat = function() {\n  return this;\n}\n\nlet obj = new Animal();\nlet speak = obj.speak;\nspeak(); // global object (in non-strict mode)\n\nlet eat = Animal.eat;\neat(); // global object (in non-strict mode)</code></pre></div>\n<h3>Instance properties</h3>\n<p>Instance properties must be defined inside of class methods:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Rectangle {\n  constructor(height, width) {\n    this.height = height;\n    this.width = width;\n  }\n}</code></pre></div>\n<p>Static (class-side) data properties and prototype data properties must be defined outside of the ClassBody declaration:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Rectangle.staticWidth = 20;\nRectangle.prototype.prototypeWidth = 25;</code></pre></div>\n<h3>Field declarations</h3>\n<p><strong>Warning:</strong> Public and private field declarations are an <a href=\"https://github.com/tc39/proposal-class-fields\">experimental feature (stage 3)</a> proposed at <a href=\"https://tc39.es\">TC39</a>, the JavaScript standards committee. Support in browsers is limited, but the feature can be used through a build step with systems like <a href=\"https://babeljs.io/\">Babel</a>.</p>\n<h4>Public field declarations</h4>\n<p>With the JavaScript field declaration syntax, the above example can be written as:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Rectangle {\n  height = 0;\n  width;\n  constructor(height, width) {\n    this.height = height;\n    this.width = width;\n  }\n}</code></pre></div>\n<p>By declaring fields up-front, class definitions become more self-documenting, and the fields are always present.</p>\n<p>As seen above, the fields can be declared with or without a default value.</p>\n<p>See <a href=\"classes/public_class_fields\">public class fields</a> for more information.</p>\n<h4>Private field declarations</h4>\n<p>Using private fields, the definition can be refined as below.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Rectangle {\n  #height = 0;\n  #width;\n  constructor(height, width) {\n    this.#height = height;\n    this.#width = width;\n  }\n}</code></pre></div>\n<p>It's an error to reference private fields from outside of the class; they can only be read or written within the class body. By defining things that are not visible outside of the class, you ensure that your classes' users can't depend on internals, which may change from version to version.</p>\n<p><strong>Note:</strong> Private fields can only be declared up-front in a field declaration.</p>\n<p>Private fields cannot be created later through assigning to them, the way that normal properties can.</p>\n<p>For more information, see <a href=\"classes/private_class_fields\">private class fields</a>.</p>\n<h2>Sub classing with <code class=\"language-text\">extends</code></h2>\n<p>The <a href=\"classes/extends\"><code class=\"language-text\">extends</code></a> keyword is used in <em>class declarations</em> or <em>class expressions</em> to create a class as a child of another class.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Animal {\n  constructor(name) {\n    this.name = name;\n  }\n\n  speak() {\n    console.log(`${this.name} makes a noise.`);\n  }\n}\n\nclass Dog extends Animal {\n  constructor(name) {\n    super(name); // call the super class constructor and pass in the name parameter\n  }\n\n  speak() {\n    console.log(`${this.name} barks.`);\n  }\n}\n\nlet d = new Dog('Mitzie');\nd.speak(); // Mitzie barks.</code></pre></div>\n<p>If there is a constructor present in the subclass, it needs to first call super() before using \"this\".</p>\n<p>One may also extend traditional function-based \"classes\":</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Animal (name) {\n  this.name = name;\n}\n\nAnimal.prototype.speak = function () {\n  console.log(`${this.name} makes a noise.`);\n}\n\nclass Dog extends Animal {\n  speak() {\n    console.log(`${this.name} barks.`);\n  }\n}\n\nlet d = new Dog('Mitzie');\nd.speak(); // Mitzie barks.\n\n// For similar methods, the child's method takes precedence over parent's method</code></pre></div>\n<p>Note that classes cannot extend regular (non-constructible) objects. If you want to inherit from a regular object, you can instead use <a href=\"global_objects/object/setprototypeof\"><code class=\"language-text\">Object.setPrototypeOf()</code></a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Animal = {\n  speak() {\n    console.log(`${this.name} makes a noise.`);\n  }\n};\n\nclass Dog {\n  constructor(name) {\n    this.name = name;\n  }\n}\n\n// If you do not do this you will get a TypeError when you invoke speak\nObject.setPrototypeOf(Dog.prototype, Animal);\n\nlet d = new Dog('Mitzie');\nd.speak(); // Mitzie makes a noise.</code></pre></div>\n<h2>Species</h2>\n<p>You might want to return <a href=\"global_objects/array\"><code class=\"language-text\">Array</code></a> objects in your derived array class <code class=\"language-text\">MyArray</code>. The species pattern lets you override default constructors.</p>\n<p>For example, when using methods such as <a href=\"global_objects/array/map\"><code class=\"language-text\">map()</code></a> that returns the default constructor, you want these methods to return a parent <code class=\"language-text\">Array</code> object, instead of the <code class=\"language-text\">MyArray</code> object. The <a href=\"global_objects/symbol/species\"><code class=\"language-text\">Symbol.species</code></a> symbol lets you do this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class MyArray extends Array {\n  // Overwrite species to the parent Array constructor\n  static get [Symbol.species]() { return Array; }\n}\n\nlet a = new MyArray(1,2,3);\nlet mapped = a.map(x => x * x);\n\nconsole.log(mapped instanceof MyArray); // false\nconsole.log(mapped instanceof Array);   // true</code></pre></div>\n<h2>Super class calls with <code class=\"language-text\">super</code></h2>\n<p>The <a href=\"operators/super\"><code class=\"language-text\">super</code></a> keyword is used to call corresponding methods of super class. This is one advantage over prototype-based inheritance.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Cat {\n  constructor(name) {\n    this.name = name;\n  }\n\n  speak() {\n    console.log(`${this.name} makes a noise.`);\n  }\n}\n\nclass Lion extends Cat {\n  speak() {\n    super.speak();\n    console.log(`${this.name} roars.`);\n  }\n}\n\nlet l = new Lion('Fuzzy');\nl.speak();\n// Fuzzy makes a noise.\n// Fuzzy roars.</code></pre></div>\n<h2>Mix-ins</h2>\n<p>Abstract subclasses or <em>mix-ins</em> are templates for classes. An ECMAScript class can only have a single superclass, so multiple inheritance from tooling classes, for example, is not possible. The functionality must be provided by the superclass.</p>\n<p>A function with a superclass as input and a subclass extending that superclass as output can be used to implement mix-ins in ECMAScript:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let calculatorMixin = Base => class extends Base {\n  calc() { }\n};\n\nlet randomizerMixin = Base => class extends Base {\n  randomize() { }\n};</code></pre></div>\n<p>A class that uses these mix-ins can then be written like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Foo { }\nclass Bar extends calculatorMixin(randomizerMixin(Foo)) { }</code></pre></div>\n<h2>Re-running a class definition</h2>\n<p>A class can't be redefined. Attempting to do so produces a <code class=\"language-text\">SyntaxError</code>.</p>\n<p>If you're experimenting with code in a web browser, such as the Firefox Web Console (<strong>Tools</strong> > <strong>Web Developer</strong> > <strong>Web Console</strong>) and you 'Run' a definition of a class with the same name twice, you'll get a <code class=\"language-text\">SyntaxError: redeclaration of let ClassName;</code>. (See further discussion of this issue in <a href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=1428672\">bug 1428672</a>.) Doing something similar in Chrome Developer Tools gives you a message like <code class=\"language-text\">Uncaught SyntaxError: Identifier 'ClassName' has already been declared at &lt;anonymous>:1:1</code>.</p>"},{"url":"/docs/js-tips/bind/","relativePath":"docs/js-tips/bind.md","relativeDir":"docs/js-tips","base":"bind.md","name":"bind","frontmatter":{"title":"Function.bind()","weight":0,"excerpt":null,"seo":{"title":"Function.prototype.bind()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Function.prototype.bind()</h1>\n<p>The <code class=\"language-text\">bind()</code> method creates a new function that, when called, has its <code class=\"language-text\">this</code> keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">bind(thisArg)\nbind(thisArg, arg1)\nbind(thisArg, arg1, arg2)\nbind(thisArg, arg1, ... , argN)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">thisArg</code>\nThe value to be passed as the <code class=\"language-text\">this</code> parameter to the target function <code class=\"language-text\">func</code> when the bound function is called. The value is ignored if the bound function is constructed using the <a href=\"../../operators/new\"><code class=\"language-text\">new</code></a> operator. When using <code class=\"language-text\">bind</code> to create a function (supplied as a callback) inside a <code class=\"language-text\">setTimeout</code>, any primitive value passed as <code class=\"language-text\">thisArg</code> is converted to object. If no arguments are provided to <code class=\"language-text\">bind</code>, or if the <code class=\"language-text\">thisArg</code> is <code class=\"language-text\">null</code> or <code class=\"language-text\">undefined</code>, the <code class=\"language-text\">this</code> of the executing scope is treated as the <code class=\"language-text\">thisArg</code> for the new function.</p>\n<p><code class=\"language-text\">arg1, arg2, ...argN</code> <span class=\"badge inline optional\">Optional</span>\nArguments to prepend to arguments provided to the bound function when invoking <code class=\"language-text\">func</code>.</p>\n<h3>Return value</h3>\n<p>A copy of the given function with the specified <code class=\"language-text\">this</code> value, and initial arguments (if provided).</p>\n<h2>Description</h2>\n<p>The <code class=\"language-text\">bind()</code> function creates a new <strong>bound function</strong>, which is an <em>exotic function object</em> (a term from ECMAScript 2015) that wraps the original function object. Calling the bound function generally results in the execution of its wrapped function.</p>\n<p>A bound function has the following internal properties:</p>\n<p><code class=\"language-text\">[[BoundTargetFunction]]</code>\nThe wrapped function object</p>\n<p><code class=\"language-text\">[[BoundThis]]</code>\nThe value that is always passed as <code class=\"language-text\">this</code> value when calling the wrapped function.</p>\n<p><code class=\"language-text\">[[BoundArguments]]</code>\nA list of values whose elements are used as the first arguments to any call to the wrapped function.</p>\n<p><code class=\"language-text\">[[Call]]</code>\nExecutes code associated with this object. Invoked via a function call expression. The arguments to the internal method are a <code class=\"language-text\">this</code> value and a list containing the arguments passed to the function by a call expression.</p>\n<p>When a bound function is called, it calls internal method <code class=\"language-text\">[[Call]]</code> on <code class=\"language-text\">[[BoundTargetFunction]]</code>, with following arguments <code class=\"language-text\">Call(boundThis, ...args)</code>. Where <code class=\"language-text\">boundThis</code> is <code class=\"language-text\">[[BoundThis]]</code>, <code class=\"language-text\">args</code> is <code class=\"language-text\">[[BoundArguments]]</code>, followed by the arguments passed by the function call.</p>\n<p>A bound function may also be constructed using the <a href=\"../../operators/new\"><code class=\"language-text\">new</code></a> operator. Doing so acts as though the target function had instead been constructed. The provided <code class=\"language-text\">this</code> value is ignored, while prepended arguments are provided to the emulated function.</p>\n<h2>Examples</h2>\n<h3>Creating a bound function</h3>\n<p>The simplest use of <code class=\"language-text\">bind()</code> is to make a function that, no matter how it is called, is called with a particular <code class=\"language-text\">this</code> value.</p>\n<p>A common mistake for new JavaScript programmers is to extract a method from an object, then to later call that function and expect it to use the original object as its <code class=\"language-text\">this</code> (e.g., by using the method in callback-based code).</p>\n<p>Without special care, however, the original object is usually lost. Creating a bound function from the function, using the original object, neatly solves this problem:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.x = 9;    // 'this' refers to global 'window' object here in a browser\nconst module = {\n  x: 81,\n  getX: function() { return this.x; }\n};\n\nmodule.getX();\n//  returns 81\n\nconst retrieveX = module.getX;\nretrieveX();\n//  returns 9; the function gets invoked at the global scope\n\n//  Create a new function with 'this' bound to module\n//  New programmers might confuse the\n//  global variable 'x' with module's property 'x'\nconst boundGetX = retrieveX.bind(module);\nboundGetX();\n//  returns 81</code></pre></div>\n<h3>Partially applied functions</h3>\n<p>The next simplest use of <code class=\"language-text\">bind()</code> is to make a function with pre-specified initial arguments.</p>\n<p>These arguments (if any) follow the provided <code class=\"language-text\">this</code> value and are then inserted at the start of the arguments passed to the target function, followed by whatever arguments are passed bound function at the time it is called.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function list() {\n  return Array.prototype.slice.call(arguments);\n}\n\nfunction addArguments(arg1, arg2) {\n  return arg1 + arg2\n}\n\nconst list1 = list(1, 2, 3);\n//  [1, 2, 3]\n\nconst result1 = addArguments(1, 2);\n//  3\n\n// Create a function with a preset leading argument\nconst leadingThirtysevenList = list.bind(null, 37);\n\n// Create a function with a preset first argument.\nconst addThirtySeven = addArguments.bind(null, 37);\n\nconst list2 = leadingThirtysevenList();\n//  [37]\n\nconst list3 = leadingThirtysevenList(1, 2, 3);\n//  [37, 1, 2, 3]\n\nconst result2 = addThirtySeven(5);\n//  37 + 5 = 42\n\nconst result3 = addThirtySeven(5, 10);\n//  37 + 5 = 42\n//  (the second argument is ignored)</code></pre></div>\n<h3>With <code class=\"language-text\">setTimeout()</code></h3>\n<p>By default within <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout\"><code class=\"language-text\">window.setTimeout()</code></a>, the <code class=\"language-text\">this</code> keyword will be set to the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window\"><code class=\"language-text\">window</code></a> (or <code class=\"language-text\">global</code>) object. When working with class methods that require <code class=\"language-text\">this</code> to refer to class instances, you may explicitly bind <code class=\"language-text\">this</code> to the callback function, in order to maintain the instance.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function LateBloomer() {\n  this.petalCount = Math.floor(Math.random() * 12) + 1;\n}\n\n// Declare bloom after a delay of 1 second\nLateBloomer.prototype.bloom = function() {\n  window.setTimeout(this.declare.bind(this), 1000);\n};\n\nLateBloomer.prototype.declare = function() {\n  console.log(`I am a beautiful flower with ${this.petalCount} petals!`);\n};\n\nconst flower = new LateBloomer();\nflower.bloom();\n//  after 1 second, calls 'flower.declare()'</code></pre></div>\n<h3>Bound functions used as constructors</h3>\n<p><strong>Warning:</strong> This section demonstrates JavaScript capabilities and documents some edge cases of the <code class=\"language-text\">bind()</code> method.</p>\n<p>The methods shown below are not the best way to do things, and probably should not be used in any production environment.</p>\n<p>Bound functions are automatically suitable for use with the <a href=\"../../operators/new\"><code class=\"language-text\">new</code></a> operator to construct new instances created by the target function. When a bound function is used to construct a value, the provided <code class=\"language-text\">this</code> is ignored.</p>\n<p>However, provided arguments are still prepended to the constructor call:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Point(x, y) {\n  this.x = x;\n  this.y = y;\n}\n\nPoint.prototype.toString = function() {\n  return `${this.x},${this.y}`;\n};\n\nconst p = new Point(1, 2);\np.toString();\n// '1,2'\n\n//  not supported in the polyfill below,\n\n//  works fine with native bind:\n\nconst YAxisPoint = Point.bind(null, 0/*x*/);\n\nconst emptyObj = {};\nconst YAxisPoint = Point.bind(emptyObj, 0/*x*/);\n\nconst axisPoint = new YAxisPoint(5);\naxisPoint.toString();                    // '0,5'\n\naxisPoint instanceof Point;              // true\naxisPoint instanceof YAxisPoint;         // true\nnew YAxisPoint(17, 42) instanceof Point; // true</code></pre></div>\n<p>Note that you need not do anything special to create a bound function for use with <a href=\"../../operators/new\"><code class=\"language-text\">new</code></a>.</p>\n<p>The corollary is that you need not do anything special to create a bound function to be called plainly, even if you would rather require the bound function to only be called using <a href=\"../../operators/new\"><code class=\"language-text\">new</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//  Example can be run directly in your JavaScript console\n//  ...continued from above\n\n//  Can still be called as a normal function\n//  (although usually this is undesired)\nYAxisPoint(13);\n\n`${emptyObj.x},${emptyObj.y}`;\n// >  '0,13'</code></pre></div>\n<p>If you wish to support the use of a bound function only using <a href=\"../../operators/new\"><code class=\"language-text\">new</code></a>, or only by calling it, the target function must enforce that restriction.</p>\n<h3>Creating shortcuts</h3>\n<p><code class=\"language-text\">bind()</code> is also helpful in cases where you want to create a shortcut to a function which requires a specific <code class=\"language-text\">this</code> value.</p>\n<p>Take <a href=\"../array/slice\"><code class=\"language-text\">Array.prototype.slice()</code></a>, for example, which you want to use for converting an array-like object to a real array. You could create a shortcut like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const slice = Array.prototype.slice;\n\n// ...\n\nslice.apply(arguments);</code></pre></div>\n<p>With <code class=\"language-text\">bind()</code>, this can be simplified.</p>\n<p>In the following piece of code, <code class=\"language-text\">slice()</code> is a bound function to the <a href=\"apply\"><code class=\"language-text\">apply()</code></a> function of <a href=\"../function\"><code class=\"language-text\">Function</code></a>, with the <code class=\"language-text\">this</code> value set to the <a href=\"../array/slice\"><code class=\"language-text\">slice()</code></a> function of <span class=\"page-not-created\"><code class=\"language-text\">Array.prototype</code></span>. This means that additional <code class=\"language-text\">apply()</code> calls can be eliminated:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//  same as \"slice\" in the previous example\nconst unboundSlice = Array.prototype.slice;\nconst slice = Function.prototype.apply.bind(unboundSlice);\n\n// ...\n\nslice(arguments);</code></pre></div>\n<h2>Polyfill</h2>\n<p>Because older browsers are generally also slower browsers, it is far more critical than most people recognize to create performance polyfills to make the browsing experience in outdated browsers slightly less horrible.</p>\n<p>Thus, presented below are two options for <code class=\"language-text\">Function.prototype.bind()</code> polyfills:</p>\n<ol>\n<li>The first one is much smaller and more performant, but does not work when using the <code class=\"language-text\">new</code> operator.</li>\n<li>The second one is bigger and less performant, but it permits some usage of the <code class=\"language-text\">new</code> operator on bound functions.</li>\n</ol>\n<p>Generally, in most code it's very rare to see <code class=\"language-text\">new</code> used on a bound function, so it is generally best to go with the first option.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//  Does not work with `new (funcA.bind(thisArg, args))`\nif (!Function.prototype.bind) (function(){\n  var slice = Array.prototype.slice;\n  Function.prototype.bind = function() {\n    var thatFunc = this, thatArg = arguments[0];\n    var args = slice.call(arguments, 1);\n    if (typeof thatFunc !== 'function') {\n      // closest thing possible to the ECMAScript 5\n      // internal IsCallable function\n      throw new TypeError('Function.prototype.bind - ' +\n             'what is trying to be bound is not callable');\n    }\n    return function(){\n      var funcArgs = args.concat(slice.call(arguments))\n      return thatFunc.apply(thatArg, funcArgs);\n    };\n  };\n})();</code></pre></div>\n<p>You can partially work around this by inserting the following code at the beginning of your scripts, allowing use of much of the functionality of <code class=\"language-text\">bind()</code> in implementations that do not natively support it.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//  Yes, it does work with `new (funcA.bind(thisArg, args))`\nif (!Function.prototype.bind) (function(){\n  var ArrayPrototypeSlice = Array.prototype.slice;\n  Function.prototype.bind = function(otherThis) {\n    if (typeof this !== 'function') {\n      // closest thing possible to the ECMAScript 5\n      // internal IsCallable function\n      throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');\n    }\n\n    var baseArgs= ArrayPrototypeSlice.call(arguments, 1),\n        baseArgsLength = baseArgs.length,\n        fToBind = this,\n        fNOP    = function() {},\n        fBound  = function() {\n          baseArgs.length = baseArgsLength; // reset to default base arguments\n          baseArgs.push.apply(baseArgs, arguments);\n          return fToBind.apply(\n                 fNOP.prototype.isPrototypeOf(this) ? this : otherThis, baseArgs\n          );\n        };\n\n    if (this.prototype) {\n      // Function.prototype doesn't have a prototype property\n      fNOP.prototype = this.prototype;\n    }\n    fBound.prototype = new fNOP();\n\n    return fBound;\n  };\n})();</code></pre></div>\n<p>Some of the many differences (there may well be others, as this list does not seriously attempt to be exhaustive) between this algorithm and the specified algorithm are:</p>\n<ul>\n<li>The partial implementation relies on <a href=\"../array/slice\"><code class=\"language-text\">Array.prototype.slice()</code></a>, <a href=\"../array/concat\"><code class=\"language-text\">Array.prototype.concat()</code></a>, <a href=\"call\"><code class=\"language-text\">Function.prototype.call()</code></a> and <a href=\"apply\"><code class=\"language-text\">Function.prototype.apply()</code></a>, built-in methods to have their original values.</li>\n<li>The partial implementation creates functions that do not have immutable \"poison pill\" <a href=\"caller\"><code class=\"language-text\">caller</code></a> and <code class=\"language-text\">arguments</code> properties that throw a <a href=\"../typeerror\"><code class=\"language-text\">TypeError</code></a> upon get, set, or deletion. (This could be added if the implementation supports <a href=\"../object/defineproperty\"><code class=\"language-text\">Object.defineProperty</code></a>, or partially implemented [without throw-on-delete behavior] if the implementation supports the <a href=\"../object/__definegetter__\"><code class=\"language-text\">__defineGetter__</code></a> and <a href=\"../object/__definesetter__\"><code class=\"language-text\">__defineSetter__</code></a> extensions.)</li>\n<li>The partial implementation creates functions that have a <code class=\"language-text\">prototype</code> property. (Proper bound functions have none.)</li>\n<li>The partial implementation creates bound functions whose <a href=\"length\"><code class=\"language-text\">length</code></a> property does not agree with that mandated by ECMA-262: it creates functions with <code class=\"language-text\">length</code> of <code class=\"language-text\">0</code>. A full implementation—depending on the length of the target function and the number of pre-specified arguments—may return a non-zero length.</li>\n<li>The partial implementation creates bound functions whose <a href=\"name\"><code class=\"language-text\">name</code></a> property is not derived from the original function name. According to ECMA-262, name of the returned bound function should be \"bound \" + name of target function (note the space character).</li>\n</ul>\n<p>If you choose to use this partial implementation, <strong>you must not rely on those cases where behavior deviates from ECMA-262, 5<sup>th</sup> edition!</strong> Thankfully, these deviations from the specification rarely (if ever) come up in most coding situations. If you do not understand any of the deviations from the specification above, then it is safe in this particular case to not worry about these noncompliant deviation details.</p>\n<p><strong>If it's absolutely necessary and performance is not a concern</strong>, a far slower (but more specification-compliant solution) can be found at <a href=\"https://github.com/Raynos/function-bind\">https://github.com/Raynos/function-bind</a>.</p>"},{"url":"/docs/js-tips/conditional_operator/","relativePath":"docs/js-tips/conditional_operator.md","relativeDir":"docs/js-tips","base":"conditional_operator.md","name":"conditional_operator","frontmatter":{"title":"Conditional (ternary) operator","weight":0,"excerpt":null,"seo":{"title":"Conditional (ternary) operator","description":"Conditional (ternary) operator","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Conditional (ternary) operator</h1>\n<p>The <strong>conditional (ternary) operator</strong> is the only JavaScript operator that takes three operands: a condition followed by a question mark (<code class=\"language-text\">?</code>), then an expression to execute if the condition is <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Truthy\">truthy</a> followed by a colon (<code class=\"language-text\">:</code>), and finally the expression to execute if the condition is <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Falsy\">falsy</a>. This operator is frequently used as a shortcut for the <a href=\"../statements/if...else\"><code class=\"language-text\">if</code></a> statement.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">condition ? exprIfTrue : exprIfFalse</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">condition</code>\nAn expression whose value is used as a condition.</p>\n<p><code class=\"language-text\">exprIfTrue</code>\nAn expression which is evaluated if the <code class=\"language-text\">condition</code> evaluates to a <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Truthy\">truthy</a> value (one which equals or can be converted to <code class=\"language-text\">true</code>).</p>\n<p><code class=\"language-text\">exprIfFalse</code>\nAn expression which is executed if the <code class=\"language-text\">condition</code> is <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Falsy\">falsy</a> (that is, has a value which can be converted to <code class=\"language-text\">false</code>).</p>\n<h2>Description</h2>\n<p>Besides <code class=\"language-text\">false</code>, possible falsy expressions are: <code class=\"language-text\">null</code>, <code class=\"language-text\">NaN</code>, <code class=\"language-text\">0</code>, the empty string (<code class=\"language-text\">\"\"</code>), and <code class=\"language-text\">undefined</code>. If <code class=\"language-text\">condition</code> is any of these, the result of the conditional expression will be the result of executing the expression <code class=\"language-text\">exprIfFalse</code>.</p>\n<h2>Examples</h2>\n<h3>A simple example</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var age = 26;\nvar beverage = (age >= 21) ? \"Beer\" : \"Juice\";\nconsole.log(beverage); // \"Beer\"</code></pre></div>\n<h3>Handling null values</h3>\n<p>One common usage is to handle a value that may be <code class=\"language-text\">null</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let greeting = person => {\n    let name = person ? person.name : `stranger`\n    return `Howdy, ${name}`\n}\n\nconsole.log(greeting({name: `Alice`}));  // \"Howdy, Alice\"\nconsole.log(greeting(null));             // \"Howdy, stranger\"</code></pre></div>\n<h3>Conditional chains</h3>\n<p>The ternary operator is right-associative, which means it can be \"chained\" in the following way, similar to an <code class=\"language-text\">if … else if … else if … else</code> chain:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function example(…) {\n    return condition1 ? value1\n         : condition2 ? value2\n         : condition3 ? value3\n         : value4;\n}\n\n// Equivalent to:\n\nfunction example(…) {\n    if (condition1) { return value1; }\n    else if (condition2) { return value2; }\n    else if (condition3) { return value3; }\n    else { return value4; }\n}</code></pre></div>"},{"url":"/docs/js-tips/concat/","relativePath":"docs/js-tips/concat.md","relativeDir":"docs/js-tips","base":"concat.md","name":"concat","frontmatter":{"title":"Array.concat()","weight":0,"excerpt":null,"seo":{"title":"Array.prototype.concat()","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Array.prototype.concat()</h1>\n<p>The <code class=\"language-text\">concat()</code> method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">concat()\nconcat(value0)\nconcat(value0, value1)\nconcat(value0, value1, ... , valueN)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">valueN</code> <span class=\"badge inline optional\">Optional</span>\nArrays and/or values to concatenate into a new array. If all <code class=\"language-text\">valueN</code> parameters are omitted, <code class=\"language-text\">concat</code> returns a shallow copy of the existing array on which it is called. See the description below for more details.</p>\n<h3>Return value</h3>\n<p>A new <a href=\"../array\"><code class=\"language-text\">Array</code></a> instance.</p>\n<h2>Description</h2>\n<p>The <code class=\"language-text\">concat</code> method creates a new array consisting of the elements in the object on which it is called, followed in order by, for each argument, the elements of that argument (if the argument is an array) or the argument itself (if the argument is not an array). It does not recurse into nested array arguments.</p>\n<p>The <code class=\"language-text\">concat</code> method does not alter <code class=\"language-text\">this</code> or any of the arrays provided as arguments but instead returns a shallow copy that contains copies of the same elements combined from the original arrays. Elements of the original arrays are copied into the new array as follows:</p>\n<ul>\n<li>Object references (and not the actual object): <code class=\"language-text\">concat</code> copies object references into the new array. Both the original and new array refer to the same object. That is, if a referenced object is modified, the changes are visible to both the new and original arrays. This includes elements of array arguments that are also arrays.</li>\n<li>Data types such as strings, numbers and booleans (not <a href=\"../string\"><code class=\"language-text\">String</code></a>, <a href=\"../number\"><code class=\"language-text\">Number</code></a>, and <a href=\"../boolean\"><code class=\"language-text\">Boolean</code></a> objects): <code class=\"language-text\">concat</code> copies the values of strings and numbers into the new array.</li>\n</ul>\n<p><strong>Note:</strong> Concatenating array(s)/value(s) will leave the originals untouched. Furthermore, any operation on the new array (except operations on elements which are object references) will have no effect on the original arrays, and vice versa.</p>\n<h2>Examples</h2>\n<h3>Concatenating two arrays</h3>\n<p>The following code concatenates two arrays:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const letters = ['a', 'b', 'c'];\nconst numbers = [1, 2, 3];\n\nletters.concat(numbers);\n// result in ['a', 'b', 'c', 1, 2, 3]</code></pre></div>\n<h3>Concatenating three arrays</h3>\n<p>The following code concatenates three arrays:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const num1 = [1, 2, 3];\nconst num2 = [4, 5, 6];\nconst num3 = [7, 8, 9];\n\nconst numbers = num1.concat(num2, num3);\n\nconsole.log(numbers);\n// results in [1, 2, 3, 4, 5, 6, 7, 8, 9]</code></pre></div>\n<h3>Concatenating values to an array</h3>\n<p>The following code concatenates three values to an array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const letters = ['a', 'b', 'c'];\n\nconst alphaNumeric = letters.concat(1, [2, 3]);\n\nconsole.log(alphaNumeric);\n// results in ['a', 'b', 'c', 1, 2, 3]</code></pre></div>\n<h3>Concatenating nested arrays</h3>\n<p>The following code concatenates nested arrays and demonstrates retention of references:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const num1 = [[1]];\nconst num2 = [2, [3]];\n\nconst numbers = num1.concat(num2);\n\nconsole.log(numbers);\n// results in [[1], 2, [3]]\n\n// modify the first element of num1\nnum1[0].push(4);\n\nconsole.log(numbers);\n// results in [[1, 4], 2, [3]]</code></pre></div>"},{"url":"/docs/js-tips/date/","relativePath":"docs/js-tips/date.md","relativeDir":"docs/js-tips","base":"date.md","name":"date","frontmatter":{"title":"Date","weight":0,"excerpt":null,"seo":{"title":"Date","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Date</h1>\n<p>JavaScript <code class=\"language-text\">Date</code> objects represent a single moment in time in a platform-independent format. <code class=\"language-text\">Date</code> objects contain a <code class=\"language-text\">Number</code> that represents milliseconds since 1 January 1970 UTC.</p>\n<p><strong>Note:</strong> TC39 is working on <a href=\"https://tc39.es/proposal-temporal/docs/index.html\">Temporal</a>, a new Date/Time API. Read more about it on the <a href=\"https://blogs.igalia.com/compilers/2020/06/23/dates-and-times-in-javascript/\">Igalia blog</a>. It is not yet ready for production use!</p>\n<h2>Description</h2>\n<h3>The ECMAScript epoch and timestamps</h3>\n<p>A JavaScript date is fundamentally specified as the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC. This date and time are not the same as the <strong>UNIX epoch</strong> (the number of seconds that have elapsed since midnight on January 1, 1970, UTC), which is the predominant base value for computer-recorded date and time values.</p>\n<p><strong>Note:</strong> It's important to keep in mind that while the time value at the heart of a Date object is UTC, the basic methods to fetch the date and time or its components all work in the local (i.e. host system) time zone and offset.</p>\n<p>It should be noted that the maximum <code class=\"language-text\">Date</code> is not of the same value as the maximum safe integer (<code class=\"language-text\">Number.MAX_SAFE_INTEGER</code> is 9,007,199,254,740,991). Instead, it is defined in ECMA-262 that a maximum of ±100,000,000 (one hundred million) days relative to January 1, 1970 UTC (that is, April 20, 271821 BCE ~ September 13, 275760 CE) can be represented by the standard <code class=\"language-text\">Date</code> object (equivalent to ±8,640,000,000,000,000 milliseconds).</p>\n<h3>Date format and time zone conversions</h3>\n<p>There are several methods available to obtain a date in various formats, as well as to perform time zone conversions. Particularly useful are the functions that output the date and time in Coordinated Universal Time (UTC), the global standard time defined by the World Time Standard. (This time is historically known as <em>Greenwich Mean Time</em>, as UTC lies along the meridian that includes London—and nearby Greenwich—in the United Kingdom.) The user's device provides the local time.</p>\n<p>In addition to methods to read and alter individual components of the local date and time (such as <a href=\"date/getday\"><code class=\"language-text\">getDay()</code></a> and <a href=\"date/sethours\"><code class=\"language-text\">setHours()</code></a>), there are also versions of the same methods that read and manipulate the date and time using UTC (such as <a href=\"date/getutcday\"><code class=\"language-text\">getUTCDay()</code></a> and <a href=\"date/setutchours\"><code class=\"language-text\">setUTCHours()</code></a>).</p>\n<h2>Constructor</h2>\n<p><a href=\"date/date\"><code class=\"language-text\">Date()</code></a>\nWhen called as a function, returns a string representation of the current date and time, exactly as <code class=\"language-text\">new Date().toString()</code> does.</p>\n<p><a href=\"date/date\"><code class=\"language-text\">new Date()</code></a>\nWhen called as a constructor, returns a new <code class=\"language-text\">Date</code> object.</p>\n<h2>Static methods</h2>\n<p><a href=\"date/now\"><code class=\"language-text\">Date.now()</code></a>\nReturns the numeric value corresponding to the current time—the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC, with leap seconds ignored.</p>\n<p><a href=\"date/parse\"><code class=\"language-text\">Date.parse()</code></a>\nParses a string representation of a date and returns the number of milliseconds since 1 January, 1970, 00:00:00 UTC, with leap seconds ignored.</p>\n<p><strong>Note:</strong> Parsing of strings with <code class=\"language-text\">Date.parse</code> is strongly discouraged due to browser differences and inconsistencies.</p>\n<p><a href=\"date/utc\"><code class=\"language-text\">Date.UTC()</code></a>\nAccepts the same parameters as the longest form of the constructor (i.e. 2 to 7) and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC, with leap seconds ignored.</p>\n<h2>Instance methods</h2>\n<p><a href=\"date/getdate\"><code class=\"language-text\">Date.prototype.getDate()</code></a>\nReturns the day of the month (<code class=\"language-text\">1</code>-<code class=\"language-text\">31</code>) for the specified date according to local time.</p>\n<p><a href=\"date/getday\"><code class=\"language-text\">Date.prototype.getDay()</code></a>\nReturns the day of the week (<code class=\"language-text\">0</code>-<code class=\"language-text\">6</code>) for the specified date according to local time.</p>\n<p><a href=\"date/getfullyear\"><code class=\"language-text\">Date.prototype.getFullYear()</code></a>\nReturns the year (4 digits for 4-digit years) of the specified date according to local time.</p>\n<p><a href=\"date/gethours\"><code class=\"language-text\">Date.prototype.getHours()</code></a>\nReturns the hour (<code class=\"language-text\">0</code>-<code class=\"language-text\">23</code>) in the specified date according to local time.</p>\n<p><a href=\"date/getmilliseconds\"><code class=\"language-text\">Date.prototype.getMilliseconds()</code></a>\nReturns the milliseconds (<code class=\"language-text\">0</code>-<code class=\"language-text\">999</code>) in the specified date according to local time.</p>\n<p><a href=\"date/getminutes\"><code class=\"language-text\">Date.prototype.getMinutes()</code></a>\nReturns the minutes (<code class=\"language-text\">0</code>-<code class=\"language-text\">59</code>) in the specified date according to local time.</p>\n<p><a href=\"date/getmonth\"><code class=\"language-text\">Date.prototype.getMonth()</code></a>\nReturns the month (<code class=\"language-text\">0</code>-<code class=\"language-text\">11</code>) in the specified date according to local time.</p>\n<p><a href=\"date/getseconds\"><code class=\"language-text\">Date.prototype.getSeconds()</code></a>\nReturns the seconds (<code class=\"language-text\">0</code>-<code class=\"language-text\">59</code>) in the specified date according to local time.</p>\n<p><a href=\"date/gettime\"><code class=\"language-text\">Date.prototype.getTime()</code></a>\nReturns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC. (Negative values are returned for prior times.)</p>\n<p><a href=\"date/gettimezoneoffset\"><code class=\"language-text\">Date.prototype.getTimezoneOffset()</code></a>\nReturns the time-zone offset in minutes for the current locale.</p>\n<p><a href=\"date/getutcdate\"><code class=\"language-text\">Date.prototype.getUTCDate()</code></a>\nReturns the day (date) of the month (<code class=\"language-text\">1</code>-<code class=\"language-text\">31</code>) in the specified date according to universal time.</p>\n<p><a href=\"date/getutcday\"><code class=\"language-text\">Date.prototype.getUTCDay()</code></a>\nReturns the day of the week (<code class=\"language-text\">0</code>-<code class=\"language-text\">6</code>) in the specified date according to universal time.</p>\n<p><a href=\"date/getutcfullyear\"><code class=\"language-text\">Date.prototype.getUTCFullYear()</code></a>\nReturns the year (4 digits for 4-digit years) in the specified date according to universal time.</p>\n<p><a href=\"date/getutchours\"><code class=\"language-text\">Date.prototype.getUTCHours()</code></a>\nReturns the hours (<code class=\"language-text\">0</code>-<code class=\"language-text\">23</code>) in the specified date according to universal time.</p>\n<p><a href=\"date/getutcmilliseconds\"><code class=\"language-text\">Date.prototype.getUTCMilliseconds()</code></a>\nReturns the milliseconds (<code class=\"language-text\">0</code>-<code class=\"language-text\">999</code>) in the specified date according to universal time.</p>\n<p><a href=\"date/getutcminutes\"><code class=\"language-text\">Date.prototype.getUTCMinutes()</code></a>\nReturns the minutes (<code class=\"language-text\">0</code>-<code class=\"language-text\">59</code>) in the specified date according to universal time.</p>\n<p><a href=\"date/getutcmonth\"><code class=\"language-text\">Date.prototype.getUTCMonth()</code></a>\nReturns the month (<code class=\"language-text\">0</code>-<code class=\"language-text\">11</code>) in the specified date according to universal time.</p>\n<p><a href=\"date/getutcseconds\"><code class=\"language-text\">Date.prototype.getUTCSeconds()</code></a>\nReturns the seconds (<code class=\"language-text\">0</code>-<code class=\"language-text\">59</code>) in the specified date according to universal time.</p>\n<p><a href=\"date/getyear\"><code class=\"language-text\">Date.prototype.getYear()</code></a>\nReturns the year (usually 2-3 digits) in the specified date according to local time. Use <a href=\"date/getfullyear\"><code class=\"language-text\">getFullYear()</code></a> instead.</p>\n<p><a href=\"date/setdate\"><code class=\"language-text\">Date.prototype.setDate()</code></a>\nSets the day of the month for a specified date according to local time.</p>\n<p><a href=\"date/setfullyear\"><code class=\"language-text\">Date.prototype.setFullYear()</code></a>\nSets the full year (e.g. 4 digits for 4-digit years) for a specified date according to local time.</p>\n<p><a href=\"date/sethours\"><code class=\"language-text\">Date.prototype.setHours()</code></a>\nSets the hours for a specified date according to local time.</p>\n<p><a href=\"date/setmilliseconds\"><code class=\"language-text\">Date.prototype.setMilliseconds()</code></a>\nSets the milliseconds for a specified date according to local time.</p>\n<p><a href=\"date/setminutes\"><code class=\"language-text\">Date.prototype.setMinutes()</code></a>\nSets the minutes for a specified date according to local time.</p>\n<p><a href=\"date/setmonth\"><code class=\"language-text\">Date.prototype.setMonth()</code></a>\nSets the month for a specified date according to local time.</p>\n<p><a href=\"date/setseconds\"><code class=\"language-text\">Date.prototype.setSeconds()</code></a>\nSets the seconds for a specified date according to local time.</p>\n<p><a href=\"date/settime\"><code class=\"language-text\">Date.prototype.setTime()</code></a>\nSets the <a href=\"date\"><code class=\"language-text\">Date</code></a> object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC. Use negative numbers for times prior.</p>\n<p><a href=\"date/setutcdate\"><code class=\"language-text\">Date.prototype.setUTCDate()</code></a>\nSets the day of the month for a specified date according to universal time.</p>\n<p><a href=\"date/setutcfullyear\"><code class=\"language-text\">Date.prototype.setUTCFullYear()</code></a>\nSets the full year (e.g. 4 digits for 4-digit years) for a specified date according to universal time.</p>\n<p><a href=\"date/setutchours\"><code class=\"language-text\">Date.prototype.setUTCHours()</code></a>\nSets the hour for a specified date according to universal time.</p>\n<p><a href=\"date/setutcmilliseconds\"><code class=\"language-text\">Date.prototype.setUTCMilliseconds()</code></a>\nSets the milliseconds for a specified date according to universal time.</p>\n<p><a href=\"date/setutcminutes\"><code class=\"language-text\">Date.prototype.setUTCMinutes()</code></a>\nSets the minutes for a specified date according to universal time.</p>\n<p><a href=\"date/setutcmonth\"><code class=\"language-text\">Date.prototype.setUTCMonth()</code></a>\nSets the month for a specified date according to universal time.</p>\n<p><a href=\"date/setutcseconds\"><code class=\"language-text\">Date.prototype.setUTCSeconds()</code></a>\nSets the seconds for a specified date according to universal time.</p>\n<p><a href=\"date/setyear\"><code class=\"language-text\">Date.prototype.setYear()</code></a>\nSets the year (usually 2-3 digits) for a specified date according to local time. Use <a href=\"date/setfullyear\"><code class=\"language-text\">setFullYear()</code></a> instead.</p>\n<p><a href=\"date/todatestring\"><code class=\"language-text\">Date.prototype.toDateString()</code></a>\nReturns the \"date\" portion of the <a href=\"date\"><code class=\"language-text\">Date</code></a> as a human-readable string like <code class=\"language-text\">'Thu Apr 12 2018'</code>.</p>\n<p><a href=\"date/toisostring\"><code class=\"language-text\">Date.prototype.toISOString()</code></a>\nConverts a date to a string following the ISO 8601 Extended Format.</p>\n<p><a href=\"date/tojson\"><code class=\"language-text\">Date.prototype.toJSON()</code></a>\nReturns a string representing the <a href=\"date\"><code class=\"language-text\">Date</code></a> using <a href=\"date/toisostring\"><code class=\"language-text\">toISOString()</code></a>. Intended for use by <a href=\"json/stringify\"><code class=\"language-text\">JSON.stringify()</code></a>.</p>\n<p><a href=\"date/togmtstring\"><code class=\"language-text\">Date.prototype.toGMTString()</code></a>\nReturns a string representing the <a href=\"date\"><code class=\"language-text\">Date</code></a> based on the GMT (UTC) time zone. Use <a href=\"date/toutcstring\"><code class=\"language-text\">toUTCString()</code></a> instead.</p>\n<p><a href=\"date/tolocaledatestring\"><code class=\"language-text\">Date.prototype.toLocaleDateString()</code></a>\nReturns a string with a locality sensitive representation of the date portion of this date based on system settings.</p>\n<p><span class=\"page-not-created\"><code class=\"language-text\">Date.prototype.toLocaleFormat()</code></span>\nConverts a date to a string, using a format string.</p>\n<p><a href=\"date/tolocalestring\"><code class=\"language-text\">Date.prototype.toLocaleString()</code></a>\nReturns a string with a locality-sensitive representation of this date. Overrides the <a href=\"object/tolocalestring\"><code class=\"language-text\">Object.prototype.toLocaleString()</code></a> method.</p>\n<p><a href=\"date/tolocaletimestring\"><code class=\"language-text\">Date.prototype.toLocaleTimeString()</code></a>\nReturns a string with a locality-sensitive representation of the time portion of this date, based on system settings.</p>\n<p><a href=\"date/tostring\"><code class=\"language-text\">Date.prototype.toString()</code></a>\nReturns a string representing the specified <a href=\"date\"><code class=\"language-text\">Date</code></a> object. Overrides the <a href=\"object/tostring\"><code class=\"language-text\">Object.prototype.toString()</code></a> method.</p>\n<p><a href=\"date/totimestring\"><code class=\"language-text\">Date.prototype.toTimeString()</code></a>\nReturns the \"time\" portion of the <a href=\"date\"><code class=\"language-text\">Date</code></a> as a human-readable string.</p>\n<p><a href=\"date/toutcstring\"><code class=\"language-text\">Date.prototype.toUTCString()</code></a>\nConverts a date to a string using the UTC timezone.</p>\n<p><a href=\"date/valueof\"><code class=\"language-text\">Date.prototype.valueOf()</code></a>\nReturns the primitive value of a <a href=\"date\"><code class=\"language-text\">Date</code></a> object. Overrides the <a href=\"object/valueof\"><code class=\"language-text\">Object.prototype.valueOf()</code></a> method.</p>\n<h2>Examples</h2>\n<h3>Several ways to create a Date object</h3>\n<p>The following examples show several ways to create JavaScript dates:</p>\n<p><strong>Note:</strong> Parsing of date strings with the <code class=\"language-text\">Date</code> constructor (and <code class=\"language-text\">Date.parse</code>, they are equivalent) is strongly discouraged due to browser differences and inconsistencies.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let today = new Date()\nlet birthday = new Date('December 17, 1995 03:24:00')\nlet birthday = new Date('1995-12-17T03:24:00')\nlet birthday = new Date(1995, 11, 17)            // the month is 0-indexed\nlet birthday = new Date(1995, 11, 17, 3, 24, 0)\nlet birthday = new Date(628021800000)            // passing epoch timestamp</code></pre></div>\n<h3>To get Date, Month and Year or Time</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let [month, date, year]    = new Date().toLocaleDateString(\"en-US\").split(\"/\")\nlet [hour, minute, second] = new Date().toLocaleTimeString(\"en-US\").split(/:| /)</code></pre></div>\n<h3>Two digit years map to 1900 - 1999</h3>\n<p>Values from <code class=\"language-text\">0</code> to <code class=\"language-text\">99</code> map to the years <code class=\"language-text\">1900</code> to <code class=\"language-text\">1999</code>. All other values are the actual year .</p>\n<p>In order to create and get dates between the years <code class=\"language-text\">0</code> and <code class=\"language-text\">99</code> the <a href=\"date/setfullyear\"><code class=\"language-text\">Date.prototype.setFullYear()</code></a> and <a href=\"date/getfullyear\"><code class=\"language-text\">Date.prototype.getFullYear()</code></a> methods should be used.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let date = new Date(98, 1)  // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT)\n\n// Deprecated method; 98 maps to 1998 here as well\ndate.setYear(98)            // Sun Feb 01 1998 00:00:00 GMT+0000 (GMT)\n\ndate.setFullYear(98)        // Sat Feb 01 0098 00:00:00 GMT+0000 (BST)</code></pre></div>\n<h3>Calculating elapsed time</h3>\n<p>The following examples show how to determine the elapsed time between two JavaScript dates in milliseconds.</p>\n<p>Due to the differing lengths of days (due to daylight saving changeover), months, and years, expressing elapsed time in units greater than hours, minutes, and seconds requires addressing a number of issues, and should be thoroughly researched before being attempted.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Using Date objects\nlet start = Date.now()\n\n// The event to time goes here:\ndoSomethingForALongTime()\nlet end = Date.now()\nlet elapsed = end - start // elapsed time in milliseconds\n\n// Using built-in methods\nlet start = new Date()\n\n// The event to time goes here:\ndoSomethingForALongTime()\nlet end = new Date()\nlet elapsed = end.getTime() - start.getTime() // elapsed time in milliseconds\n\n// To test a function and get back its return\nfunction printElapsedTime(fTest) {\n  let nStartTime = Date.now(),\n      vReturn = fTest(),\n      nEndTime = Date.now()\n\n  console.log(`Elapsed time: ${ String(nEndTime - nStartTime) } milliseconds`)\n  return vReturn\n}\n\nlet yourFunctionReturn = printElapsedTime(yourFunction)</code></pre></div>\n<p><strong>Note:</strong> In browsers that support the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window/performance\">Web Performance API</a>'s high-resolution time feature, <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Performance/now\"><code class=\"language-text\">Performance.now()</code></a> can provide more reliable and precise measurements of elapsed time than <a href=\"date/now\"><code class=\"language-text\">Date.now()</code></a>.</p>\n<h3>Get the number of seconds since the ECMAScript Epoch</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let seconds = Math.floor(Date.now() / 1000)</code></pre></div>\n<p>In this case, it's important to return only an integer—so a simple division won't do. It's also important to only return actually elapsed seconds. (That's why this code uses <a href=\"math/floor\"><code class=\"language-text\">Math.floor()</code></a>, and <em>not</em> <a href=\"math/round\"><code class=\"language-text\">Math.round()</code></a>.)</p>"},{"url":"/docs/js-tips/const/","relativePath":"docs/js-tips/const.md","relativeDir":"docs/js-tips","base":"const.md","name":"const","frontmatter":{"title":"const","weight":0,"excerpt":"Constants are block-scoped, much like variables declared using the let keyword. The value of a constant cant be changed through reassignment, and it cant be redeclared.","seo":{"title":"const","description":"Constants are block-scoped, much like variables declared using the let keyword. The value of a constant cant be changed through reassignment, and it cant be redeclared.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>const</h1>\n<p>Constants are block-scoped, much like variables declared using the <code class=\"language-text\">let</code> keyword. The value of a constant can't be changed through reassignment, and it can't be redeclared.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const name1 = value1 [, name2 = value2 [, ... [, nameN = valueN]]];</code></pre></div>\n<p><code class=\"language-text\">nameN</code>\nThe constant's name, which can be any legal <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Identifier\">identifier</a>.</p>\n<p><code class=\"language-text\">valueN</code>\nThe constant's value. This can be any legal <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#expressions\">expression</a>, including a function expression.</p>\n<p>The <a href=\"../operators/destructuring_assignment\">Destructuring Assignment</a> syntax can also be used to declare variables.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const { bar } = foo; // where foo = { bar:10, baz:12 };\n/* This creates a constant with the name 'bar', which has a value of 10 */</code></pre></div>\n<h2>Description</h2>\n<p>This declaration creates a constant whose scope can be either global or local to the block in which it is declared. Global constants do <strong>not</strong> become properties of the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window\"><code class=\"language-text\">window</code></a> object, unlike <a href=\"var\"><code class=\"language-text\">var</code></a> variables.</p>\n<p>An initializer for a constant is required. You must specify its value in the same statement in which it's declared. (This makes sense, given that it can't be changed later.)</p>\n<p>The <code class=\"language-text\">const</code> creates a read-only reference to a value. It does <strong>not</strong> mean the value it holds is immutable—just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its properties) can be altered.</p>\n<p>All the considerations about the \"<a href=\"let#temporal_dead_zone_tdz\">temporal dead zone</a>\" apply to both <a href=\"let\"><code class=\"language-text\">let</code></a> and <code class=\"language-text\">const</code>.</p>\n<p>A constant cannot share its name with a function or a variable in the same scope.</p>\n<h2>Examples</h2>\n<h3>Basic const usage</h3>\n<p>Constants can be declared with uppercase or lowercase, but a common convention is to use all-uppercase letters.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// define MY_FAV as a constant and give it the value 7\nconst MY_FAV = 7;\n\n// this will throw an error - Uncaught TypeError: Assignment to constant variable.\nMY_FAV = 20;\n\n// MY_FAV is 7\nconsole.log('my favorite number is: ' + MY_FAV);\n\n// trying to redeclare a constant throws an error\n// Uncaught SyntaxError: Identifier 'MY_FAV' has already been declared\nconst MY_FAV = 20;\n\n// the name MY_FAV is reserved for constant above, so this will fail too\nvar MY_FAV = 20;\n\n// this throws an error too\nlet MY_FAV = 20;</code></pre></div>\n<h3>Block scoping</h3>\n<p>It's important to note the nature of block scoping.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if (MY_FAV === 7) {\n  // this is fine and creates a block scoped MY_FAV variable\n  // (works equally well with let to declare a block scoped non const variable)\n  let MY_FAV = 20;\n\n  // MY_FAV is now 20\n  console.log('my favorite number is ' + MY_FAV);\n\n  // this gets hoisted into the global context and throws an error\n  var MY_FAV = 20;\n}\n\n// MY_FAV is still 7\nconsole.log('my favorite number is ' + MY_FAV);</code></pre></div>\n<h3>const needs to be initialized</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// throws an error\n// Uncaught SyntaxError: Missing initializer in const declaration\n\nconst FOO;</code></pre></div>\n<h3>const in objects and arrays</h3>\n<p>const also works on objects and arrays.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const MY_OBJECT = {'key': 'value'};\n\n// Attempting to overwrite the object throws an error\n// Uncaught TypeError: Assignment to constant variable.\nMY_OBJECT = {'OTHER_KEY': 'value'};\n\n// However, object keys are not protected,\n// so the following statement is executed without problem\nMY_OBJECT.key = 'otherValue'; // Use Object.freeze() to make object immutable\n\n// The same applies to arrays\nconst MY_ARRAY = [];\n// It's possible to push items into the array\nMY_ARRAY.push('A'); // [\"A\"]\n// However, assigning a new array to the variable throws an error\n// Uncaught TypeError: Assignment to constant variable.\nMY_ARRAY = ['B'];</code></pre></div>"},{"url":"/docs/js-tips/create/","relativePath":"docs/js-tips/create.md","relativeDir":"docs/js-tips","base":"create.md","name":"create","frontmatter":{"title":"Object.create()","weight":0,"excerpt":null,"seo":{"title":"Object.create()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Object.create()</h1>\n<p>The <code class=\"language-text\">Object.create()</code> method creates a new object, using an existing object as the prototype of the newly created object.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object.create(proto)\nObject.create(proto, propertiesObject)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">proto</code>\nThe object which should be the prototype of the newly-created object.</p>\n<p><code class=\"language-text\">propertiesObject</code> <span class=\"badge inline optional\">Optional</span>\nIf specified and not <a href=\"../undefined\"><code class=\"language-text\">undefined</code></a>, an object whose enumerable own properties (that is, those properties defined upon itself and <em>not</em> enumerable properties along its prototype chain) specify property descriptors to be added to the newly-created object, with the corresponding property names. These properties correspond to the second argument of <a href=\"defineproperties\"><code class=\"language-text\">Object.defineProperties()</code></a>.</p>\n<h3>Return value</h3>\n<p>A new object with the specified prototype object and properties.</p>\n<h3>Exceptions</h3>\n<p>The <code class=\"language-text\">proto</code> parameter has to be either</p>\n<ul>\n<li><a href=\"../null\"><code class=\"language-text\">null</code></a> or</li>\n<li>an <a href=\"../object\"><code class=\"language-text\">Object</code></a> excluding <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Primitive#primitive_wrapper_objects_in_javascript\">primitive wrapper objects</a>.</li>\n</ul>\n<p>If <code class=\"language-text\">proto</code> is neither of these a <a href=\"../typeerror\"><code class=\"language-text\">TypeError</code></a> is thrown.</p>\n<h2>Custom and Null objects</h2>\n<p>A new object created from a completely custom object (especially one created from the <code class=\"language-text\">null</code> object, which is basically a custom object with NO members) can behave in unexpected ways. This is especially true when debugging, since common object-property converting/detecting utility functions may generate errors, or lose information (especially if using silent error-traps that ignore errors). For example, here are two objects:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">oco = Object.create( {} );   // create a normal object\nocn = Object.create( null ); // create a \"null\" object\n\n> console.log(oco) // {} -- Seems normal\n> console.log(ocn) // {} -- Seems normal here too, so far\n\noco.p = 1; // create a simple property on normal obj\nocn.p = 0; // create a simple property on \"null\" obj\n\n> console.log(oco) // {p: 1} -- Still seems normal\n> console.log(ocn) // {p: 0} -- Still seems normal here too. BUT WAIT...</code></pre></div>\n<p>As shown above, all seems normal so far. However, when attempting to actually use these objects, their differences quickly become apparent:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">> \"oco is: \" + oco // shows \"oco is: [object Object]\"\n\n> \"ocn is: \" + ocn // throws error: Cannot convert object to primitive value</code></pre></div>\n<p>Testing just a few of the many most basic built-in functions shows the magnitude of the problem more clearly:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">> alert(oco) // shows [object Object]\n> alert(ocn) // throws error: Cannot convert object to primitive value\n\n> oco.toString() // shows [object Object]\n> ocn.toString() // throws error: ocn.toString is not a function\n\n> oco.valueOf() // shows {}\n> ocn.valueOf() // throws error: ocn.valueOf is not a function\n\n> oco.hasOwnProperty(\"p\") // shows \"true\"\n> ocn.hasOwnProperty(\"p\") // throws error: ocn.hasOwnProperty is not a function\n\n> oco.constructor // shows \"Object() { [native code] }\"\n> ocn.constructor // shows \"undefined\"</code></pre></div>\n<p>As said, these differences can make debugging even simple-seeming problems quickly go astray. For example:</p>\n<p><em>A simple common debugging function:</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// display top-level property name:value pairs of given object\nfunction ShowProperties(obj){\n  for(var prop in obj){\n    console.log(prop + \": \" + obj[prop] + \"\\n\" );\n  }\n}</code></pre></div>\n<p><em>Not such simple results: (especially if silent error-trapping had hidden the error messages)</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ob={}; ob.po=oco; ob.pn=ocn; // create a compound object using the test objects from above as property values\n\n> ShowProperties( ob ) // display top-level properties\n- po: [object Object]\n- Error: Cannot convert object to primitive value\n\nNote that only first property gets shown.</code></pre></div>\n<p><em>(But if the same object is created in a different order -- at least in some implementations...)</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ob={}; ob.pn=ocn; ob.po=oco; // create same compound object again, but create same properties in different order\n\n> ShowProperties( ob ) // display top-level properties\n- Error: Cannot convert object to primitive value\n\nNote that neither property gets shown.</code></pre></div>\n<p>Note that such a different order may arise statically via disparate fixed codings such as here, but also dynamically via whatever the order any such property-adding code-branches actually get executed at runtime as depends on inputs and/or random-variables. Then again, the actual iteration order is not guaranteed no matter what the order members are added.</p>\n<p>Be aware of, also, that using Object.entries() on an object created via Object.create() will result in an empty array being returned.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var obj = Object.create({ a: 1, b: 2 });\n\n> console.log(Object.entries(obj)); // shows \"[]\"</code></pre></div>\n<h4>Some NON-solutions</h4>\n<p>A good solution for the missing object-methods is not immediately apparent.</p>\n<p>Adding the missing object-method directly from the standard-object does NOT work:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ocn = Object.create( null ); // create \"null\" object (same as before)\n\nocn.toString = Object.toString; // since new object lacks method then try assigning it directly from standard-object\n\n> ocn.toString // shows \"toString() { [native code] }\" -- missing method seems to be there now\n> ocn.toString == Object.toString // shows \"true\" -- method seems to be same as the standard object-method\n\n> ocn.toString() // error: Function.prototype.toString requires that 'this' be a Function</code></pre></div>\n<p>Adding the missing object-method directly to new object's \"prototype\" does not work either, since the new object does not have a real prototype (which is really the cause of ALL these problems) and one cannot be <strong>directly</strong> added:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ocn = Object.create( null ); // create \"null\" object (same as before)\n\nocn.prototype.toString = Object.toString; // Error: Cannot set property 'toString' of undefined\n\nocn.prototype = {};                       // try to create a prototype\nocn.prototype.toString = Object.toString; // since new object lacks method then try assigning it from standard-object\n\n> ocn.toString() // error: ocn.toString is not a function</code></pre></div>\n<p>Adding the missing object-method by using the standard-object as new object's prototype does not work either:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ocn = Object.create( null );        // create \"null\" object (same as before)\nObject.setPrototypeOf(ocn, Object); // set new object's prototype to the standard-object\n\n> ocn.toString() // error: Function.prototype.toString requires that 'this' be a Function</code></pre></div>\n<h4>Some OK solutions</h4>\n<p>Again, adding the missing object-method directly from the <strong>standard-object</strong> does NOT work. However, adding the <strong>generic</strong> method directly, DOES:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ocn = Object.create( null ); // create \"null\" object (same as before)\n\nocn.toString = toString; // since new object lacks method then assign it directly from generic version\n\n> ocn.toString() // shows \"[object Object]\"\n> \"ocn is: \" + ocn // shows \"ocn is: [object Object]\"\n\nob={}; ob.pn=ocn; ob.po=oco; // create a compound object (same as before)\n\n> ShowProperties(ob) // display top-level properties\n- po: [object Object]\n- pn: [object Object]</code></pre></div>\n<p>However, setting the generic <strong>prototype</strong> as the new object's prototype works even better:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ocn = Object.create( null );                  // create \"null\" object (same as before)\nObject.setPrototypeOf(ocn, Object.prototype); // set new object's prototype to the \"generic\" object (NOT standard-object)</code></pre></div>\n<p><em>(In addition to all the string-related functions shown above, this also adds:)</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">> ocn.valueOf() // shows {}\n> ocn.hasOwnProperty(\"x\") // shows \"false\"\n> ocn.constructor // shows \"Object() { [native code] }\"\n\n// ...and all the rest of the properties and methods of Object.prototype.</code></pre></div>\n<p>As shown, objects modified this way now look very much like ordinary objects.</p>\n<h2>Polyfill</h2>\n<p>This polyfill covers the main use case, which is creating a new object for which the prototype has been chosen but doesn't take the second argument into account.</p>\n<p>Note that while the setting of <code class=\"language-text\">null</code> as <code class=\"language-text\">[[Prototype]]</code> is supported in the real ES5 <code class=\"language-text\">Object.create</code>, this polyfill cannot support it due to a limitation inherent in versions of ECMAScript lower than 5.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> if (typeof Object.create !== \"function\") {\n    Object.create = function (proto, propertiesObject) {\n        if (typeof proto !== 'object' &amp;&amp; typeof proto !== 'function') {\n            throw new TypeError('Object prototype may only be an Object: ' + proto);\n        } else if (proto === null) {\n            throw new Error(\"This browser's implementation of Object.create is a shim and doesn't support 'null' as the first argument.\");\n        }\n\n        if (typeof propertiesObject != 'undefined') {\n            throw new Error(\"This browser's implementation of Object.create is a shim and doesn't support a second argument.\");\n        }\n\n        function F() {}\n        F.prototype = proto;\n\n        return new F();\n    };\n}</code></pre></div>\n<h2>Examples</h2>\n<h3>Classical inheritance with <code class=\"language-text\">Object.create()</code></h3>\n<p>Below is an example of how to use <code class=\"language-text\">Object.create()</code> to achieve classical inheritance. This is for a single inheritance, which is all that JavaScript supports.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Shape - superclass\nfunction Shape() {\n  this.x = 0;\n  this.y = 0;\n}\n\n// superclass method\nShape.prototype.move = function(x, y) {\n  this.x += x;\n  this.y += y;\n  console.info('Shape moved.');\n};\n\n// Rectangle - subclass\nfunction Rectangle() {\n  Shape.call(this); // call super constructor.\n}\n\n// subclass extends superclass\nRectangle.prototype = Object.create(Shape.prototype);\n\n//If you don't set Rectangle.prototype.constructor to Rectangle,\n//it will take the prototype.constructor of Shape (parent).\n//To avoid that, we set the prototype.constructor to Rectangle (child).\nRectangle.prototype.constructor = Rectangle;\n\nvar rect = new Rectangle();\n\nconsole.log('Is rect an instance of Rectangle?', rect instanceof Rectangle); // true\nconsole.log('Is rect an instance of Shape?', rect instanceof Shape); // true\nrect.move(1, 1); // Outputs, 'Shape moved.'</code></pre></div>\n<p>If you wish to inherit from multiple objects, then mixins are a possibility.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function MyClass() {\n  SuperClass.call(this);\n  OtherSuperClass.call(this);\n}\n\n// inherit one class\nMyClass.prototype = Object.create(SuperClass.prototype);\n// mixin another\nObject.assign(MyClass.prototype, OtherSuperClass.prototype);\n// re-assign constructor\nMyClass.prototype.constructor = MyClass;\n\nMyClass.prototype.myMethod = function() {\n  // do something\n};</code></pre></div>\n<p><a href=\"assign\"><code class=\"language-text\">Object.assign()</code></a> copies properties from the OtherSuperClass prototype to the MyClass prototype, making them available to all instances of MyClass. <code class=\"language-text\">Object.assign()</code> was introduced with ES2015 and <a href=\"assign#polyfill\">can be polyfilled</a>. If support for older browsers is necessary, <code class=\"language-text\">jQuery.extend()</code> or <code class=\"language-text\">_.assign()</code> can be used.</p>\n<h3>Using propertiesObject argument with Object.create()</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var o;\n\n// create an object with null as prototype\no = Object.create(null);\n\no = {};\n// is equivalent to:\no = Object.create(Object.prototype);\n\n// Example where we create an object with a couple of\n// sample properties. (Note that the second parameter\n// maps keys to *property descriptors*.)\no = Object.create(Object.prototype, {\n  // foo is a regular 'value property'\n  foo: {\n    writable: true,\n    configurable: true,\n    value: 'hello'\n  },\n  // bar is a getter-and-setter (accessor) property\n  bar: {\n    configurable: false,\n    get: function() { return 10; },\n    set: function(value) {\n      console.log('Setting `o.bar` to', value);\n    }\n/* with ES2015 Accessors our code can look like this\n    get() { return 10; },\n    set(value) {\n      console.log('Setting `o.bar` to', value);\n    } */\n  }\n});\n\nfunction Constructor() {}\no = new Constructor();\n// is equivalent to:\no = Object.create(Constructor.prototype);\n// Of course, if there is actual initialization code\n// in the Constructor function,\n// the Object.create() cannot reflect it\n\n// Create a new object whose prototype is a new, empty\n// object and add a single property 'p', with value 42.\no = Object.create({}, { p: { value: 42 } });\n\n// by default properties ARE NOT writable,\n// enumerable or configurable:\no.p = 24;\no.p;\n// 42\n\no.q = 12;\nfor (var prop in o) {\n  console.log(prop);\n}\n// 'q'\n\ndelete o.p;\n// false\n\n// to specify an ES3 property\no2 = Object.create({}, {\n  p: {\n    value: 42,\n    writable: true,\n    enumerable: true,\n    configurable: true\n  }\n});\n/* is not equivalent to:\nThis will create an object with prototype : {p: 42 }\no2 = Object.create({p: 42}) */</code></pre></div>"},{"url":"/docs/js-tips/decrement/","relativePath":"docs/js-tips/decrement.md","relativeDir":"docs/js-tips","base":"decrement.md","name":"decrement","frontmatter":{"title":"Decrement","template":"docs","excerpt":"The decrement operator (--) decrements (subtracts one from) its operand and returns a value."},"html":"<h1>Decrement (--)</h1>\n<p>The decrement operator (<code class=\"language-text\">--</code>) decrements (subtracts one from) its operand and returns a value.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Operator: x-- or --x</code></pre></div>\n<h2>Description</h2>\n<p>If used postfix, with operator after operand (for example, <code class=\"language-text\">x--</code>), the decrement operator decrements and returns the value before decrementing.</p>\n<p>If used prefix, with operator before operand (for example, <code class=\"language-text\">--x</code>), the decrement operator decrements and returns the value after decrementing.</p>\n<h2>Examples</h2>\n<h3>Postfix decrement</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let x = 3;\ny = x--;\n\n// y = 3\n// x = 2</code></pre></div>\n<h3>Prefix decrement</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let a = 2;\nb = --a;\n\n// a = 1\n// b = 1</code></pre></div>"},{"url":"/docs/js-tips/for...of/","relativePath":"docs/js-tips/for...of.md","relativeDir":"docs/js-tips","base":"for...of.md","name":"for...of","frontmatter":{"title":"for...of","weight":0,"excerpt":null,"seo":{"title":"for...of","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>for...of</h1>\n<p>The <code class=\"language-text\">for...of</code> creates a loop iterating over <a href=\"../iteration_protocols#the_iterable_protocol\">iterable objects</a>, including: built-in <a href=\"../global_objects/string\"><code class=\"language-text\">String</code></a>, <a href=\"../global_objects/array\"><code class=\"language-text\">Array</code></a>, array-like objects (e.g., <a href=\"../functions/arguments\"><code class=\"language-text\">arguments</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeList\"><code class=\"language-text\">NodeList</code></a>), <a href=\"../global_objects/typedarray\"><code class=\"language-text\">TypedArray</code></a>, <a href=\"../global_objects/map\"><code class=\"language-text\">Map</code></a>, <a href=\"../global_objects/set\"><code class=\"language-text\">Set</code></a>, and user-defined iterables. It invokes a custom iteration hook with statements to be executed for the value of each distinct property of the object.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for (variable of iterable) {\n  statement\n}</code></pre></div>\n<p><code class=\"language-text\">variable</code>\nOn each iteration a value of a different property is assigned to <code class=\"language-text\">variable</code>. <code class=\"language-text\">variable</code> may be declared with <code class=\"language-text\">const</code>, <code class=\"language-text\">let</code>, or <code class=\"language-text\">var</code>.</p>\n<p><code class=\"language-text\">iterable</code>\nObject whose iterable properties are iterated.</p>\n<h2>Examples</h2>\n<h3>Iterating over an <code class=\"language-text\">Array</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const iterable = [10, 20, 30];\n\nfor (const value of iterable) {\n  console.log(value);\n}\n// 10\n// 20\n// 30</code></pre></div>\n<p>You can use <a href=\"let\"><code class=\"language-text\">let</code></a> instead of <a href=\"const\"><code class=\"language-text\">const</code></a> too, if you reassign the variable inside the block.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const iterable = [10, 20, 30];\n\nfor (let value of iterable) {\n  value += 1;\n  console.log(value);\n}\n// 11\n// 21\n// 31</code></pre></div>\n<h3>Iterating over a <code class=\"language-text\">String</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const iterable = 'boo';\n\nfor (const value of iterable) {\n  console.log(value);\n}\n// \"b\"\n// \"o\"\n// \"o\"</code></pre></div>\n<h3>Iterating over a <code class=\"language-text\">TypedArray</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const iterable = new Uint8Array([0x00, 0xff]);\n\nfor (const value of iterable) {\n  console.log(value);\n}\n// 0\n// 255</code></pre></div>\n<h3>Iterating over a <code class=\"language-text\">Map</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const iterable = new Map([['a', 1], ['b', 2], ['c', 3]]);\n\nfor (const entry of iterable) {\n  console.log(entry);\n}\n// ['a', 1]\n// ['b', 2]\n// ['c', 3]\n\nfor (const [key, value] of iterable) {\n  console.log(value);\n}\n// 1\n// 2\n// 3</code></pre></div>\n<h3>Iterating over a <code class=\"language-text\">Set</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const iterable = new Set([1, 1, 2, 2, 3, 3]);\n\nfor (const value of iterable) {\n  console.log(value);\n}\n// 1\n// 2\n// 3</code></pre></div>\n<h3>Iterating over the arguments object</h3>\n<p>You can iterate over the <a href=\"../functions/arguments\"><code class=\"language-text\">arguments</code></a> object to examine all of the parameters passed into a JavaScript function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(function() {\n  for (const argument of arguments) {\n    console.log(argument);\n  }\n})(1, 2, 3);\n\n// 1\n// 2\n// 3</code></pre></div>\n<h3>Iterating over a DOM collection</h3>\n<p>Iterating over DOM collections like <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeList\"><code class=\"language-text\">NodeList</code></a>: the following example adds a <code class=\"language-text\">read</code> class to paragraphs that are direct descendants of an article:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Note: This will only work in platforms that have\n// implemented NodeList.prototype[Symbol.iterator]\nconst articleParagraphs = document.querySelectorAll('article > p');\n\nfor (const paragraph of articleParagraphs) {\n  paragraph.classList.add('read');\n}</code></pre></div>\n<h3>Closing iterators</h3>\n<p>In <code class=\"language-text\">for...of</code> loops, abrupt iteration termination can be caused by <code class=\"language-text\">break</code>, <code class=\"language-text\">throw</code> or <code class=\"language-text\">return</code>. In these cases, the iterator is closed.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function* foo(){\n  yield 1;\n  yield 2;\n  yield 3;\n};\n\nfor (const o of foo()) {\n  console.log(o);\n  break; // closes iterator, execution continues outside of the loop\n}\nconsole.log('done');</code></pre></div>\n<h3>Iterating over generators</h3>\n<p>You can also iterate over <a href=\"function*\">generators</a>, i.e. functions generating an iterable object:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function* fibonacci() { // a generator function\n  let [prev, curr] = [0, 1];\n  while (true) {\n    [prev, curr] = [curr, prev + curr];\n    yield curr;\n  }\n}\n\nfor (const n of fibonacci()) {\n  console.log(n);\n  // truncate the sequence at 1000\n  if (n >= 1000) {\n    break;\n  }\n}</code></pre></div>\n<h4>Do not reuse generators</h4>\n<p>Generators should not be re-used, even if the <code class=\"language-text\">for...of</code> loop is terminated early, for example via the <a href=\"break\"><code class=\"language-text\">break</code></a> keyword. Upon exiting a loop, the generator is closed and trying to iterate over it again does not yield any further results.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const gen = (function *(){\n  yield 1;\n  yield 2;\n  yield 3;\n})();\nfor (const o of gen) {\n  console.log(o);\n  break;  // Closes iterator\n}\n\n// The generator should not be re-used, the following does not make sense!\nfor (const o of gen) {\n  console.log(o); // Never called.\n}</code></pre></div>\n<h3>Iterating over other iterable objects</h3>\n<p>You can also iterate over an object that explicitly implements the <a href=\"../iteration_protocols#iterable\">iterable</a> protocol:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const iterable = {\n  [Symbol.iterator]() {\n    return {\n      i: 0,\n      next() {\n        if (this.i &lt; 3) {\n          return { value: this.i++, done: false };\n        }\n        return { value: undefined, done: true };\n      }\n    };\n  }\n};\n\nfor (const value of iterable) {\n  console.log(value);\n}\n// 0\n// 1\n// 2</code></pre></div>\n<h3>Difference between <code class=\"language-text\">for...of</code> and <code class=\"language-text\">for...in</code></h3>\n<p>Both <code class=\"language-text\">for...in</code> and <code class=\"language-text\">for...of</code> statements iterate over something. The main difference between them is in what they iterate over.</p>\n<p>The <a href=\"for...in\"><code class=\"language-text\">for...in</code></a> statement iterates over the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties\">enumerable properties</a> of an object, in an arbitrary order.</p>\n<p>The <code class=\"language-text\">for...of</code> statement iterates over values that the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#iterables\">iterable object</a> defines to be iterated over.</p>\n<p>The following example shows the difference between a <code class=\"language-text\">for...of</code> loop and a <code class=\"language-text\">for...in</code> loop when used with an <a href=\"../global_objects/array\"><code class=\"language-text\">Array</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object.prototype.objCustom = function() {};\nArray.prototype.arrCustom = function() {};\n\nconst iterable = [3, 5, 7];\niterable.foo = 'hello';\n\nfor (const i in iterable) {\n  console.log(i); // logs \"0\", \"1\", \"2\", \"foo\", \"arrCustom\", \"objCustom\"\n}\n\nfor (const i in iterable) {\n  if (iterable.hasOwnProperty(i)) {\n    console.log(i); // logs \"0\", \"1\", \"2\", \"foo\"\n  }\n}\n\nfor (const i of iterable) {\n  console.log(i); // logs 3, 5, 7\n}</code></pre></div>\n<p>Let us look into the above code step by step.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object.prototype.objCustom = function() {};\nArray.prototype.arrCustom = function() {};\n\nconst iterable = [3, 5, 7];\niterable.foo = 'hello';</code></pre></div>\n<p>Every object will inherit the <code class=\"language-text\">objCustom</code> property and every object that is an <a href=\"../global_objects/array\"><code class=\"language-text\">Array</code></a> will inherit the <code class=\"language-text\">arrCustom</code> property since these properties have been added to <a href=\"../global_objects/object\"><code class=\"language-text\">Object.prototype</code></a> and <span class=\"page-not-created\"><code class=\"language-text\">Array.prototype</code></span>, respectively. The object <code class=\"language-text\">iterable</code> inherits the properties <code class=\"language-text\">objCustom</code> and <code class=\"language-text\">arrCustom</code> because of <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain\">inheritance and the prototype chain</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for (const i in iterable) {\n  console.log(i); // logs 0, 1, 2, \"foo\", \"arrCustom\", \"objCustom\"\n}</code></pre></div>\n<p>This loop logs only <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties\">enumerable properties</a> of the <code class=\"language-text\">iterable</code> object, in arbitrary order. It doesn't log array <strong>elements</strong> <code class=\"language-text\">3</code>, <code class=\"language-text\">5</code>, <code class=\"language-text\">7</code> or <code class=\"language-text\">hello</code> because those are <strong>not</strong> enumerable properties, in fact they are not properties at all, they are <strong>values</strong>. It logs array <strong>indexes</strong> as well as <code class=\"language-text\">arrCustom</code> and <code class=\"language-text\">objCustom</code>, which are. If you're not sure why these properties are iterated over, there's a more thorough explanation of how <a href=\"for...in#array_iteration_and_for...in\"><code class=\"language-text\">array iteration and for...in</code></a> work.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for (const i in iterable) {\n  if (iterable.hasOwnProperty(i)) {\n    console.log(i); // logs 0, 1, 2, \"foo\"\n  }\n}</code></pre></div>\n<p>This loop is similar to the first one, but it uses <a href=\"../global_objects/object/hasownproperty\"><code class=\"language-text\">hasOwnProperty()</code></a> to check if the found enumerable property is the object's own, i.e. not inherited. If it is, the property is logged. Properties <code class=\"language-text\">0</code>, <code class=\"language-text\">1</code>, <code class=\"language-text\">2</code> and <code class=\"language-text\">foo</code> are logged because they are own properties (<strong>not inherited</strong>). Properties <code class=\"language-text\">arrCustom</code> and <code class=\"language-text\">objCustom</code> are not logged because they <strong>are inherited</strong>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for (const i of iterable) {\n  console.log(i); // logs 3, 5, 7\n}</code></pre></div>\n<p>This loop iterates and logs <strong>values</strong> that <code class=\"language-text\">iterable</code>, as an <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#iterables\">iterable object</a>, defines to be iterated over. The object's <strong>elements</strong> <code class=\"language-text\">3</code>, <code class=\"language-text\">5</code>, <code class=\"language-text\">7</code> are shown, but none of the object's <strong>properties</strong>.</p>"},{"url":"/docs/js-tips/filter/","relativePath":"docs/js-tips/filter.md","relativeDir":"docs/js-tips","base":"filter.md","name":"filter","frontmatter":{"title":"Array.filter()","weight":0,"excerpt":null,"seo":{"title":"Array.prototype.filter()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Array.prototype.filter()</h1>\n<p>The <code class=\"language-text\">filter()</code> method <strong>creates a new array</strong> with all elements that pass the test implemented by the provided function.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Arrow function\nfilter((element) => { ... } )\nfilter((element, index) => { ... } )\nfilter((element, index, array) => { ... } )\n\n// Callback function\nfilter(callbackFn)\nfilter(callbackFn, thisArg)\n\n// Inline callback function\nfilter(function callbackFn(element) { ... })\nfilter(function callbackFn(element, index) { ... })\nfilter(function callbackFn(element, index, array){ ... })\nfilter(function callbackFn(element, index, array) { ... }, thisArg)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">callbackFn</code>\nFunction is a predicate, to test each element of the array. Return a value that coerces to <code class=\"language-text\">true</code> to keep the element, or to <code class=\"language-text\">false</code> otherwise.</p>\n<p>It accepts three arguments:</p>\n<p><code class=\"language-text\">element</code>\nThe current element being processed in the array.</p>\n<p><code class=\"language-text\">index</code><span class=\"badge inline optional\">Optional</span>\nThe index of the current element being processed in the array.</p>\n<p><code class=\"language-text\">array</code><span class=\"badge inline optional\">Optional</span>\nThe array <code class=\"language-text\">filter</code> was called upon.</p>\n<p><code class=\"language-text\">thisArg</code><span class=\"badge inline optional\">Optional</span>\nValue to use as <code class=\"language-text\">this</code> when executing <code class=\"language-text\">callbackFn</code>.</p>\n<h3>Return value</h3>\n<p>A new array with the elements that pass the test. If no elements pass the test, an empty array will be returned.</p>\n<h2>Description</h2>\n<p><code class=\"language-text\">filter()</code> calls a provided <code class=\"language-text\">callbackFn</code> function once for each element in an array, and constructs a new array of all the values for which <code class=\"language-text\">callbackFn</code> returns <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Truthy\">a value that coerces to <code class=\"language-text\">true</code></a>. <code class=\"language-text\">callbackFn</code> is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values. Array elements which do not pass the <code class=\"language-text\">callbackFn</code> test are skipped, and are not included in the new array.</p>\n<p><code class=\"language-text\">callbackFn</code> is invoked with three arguments:</p>\n<ol>\n<li>the value of the element</li>\n<li>the index of the element</li>\n<li>the Array object being traversed</li>\n</ol>\n<p>If a <code class=\"language-text\">thisArg</code> parameter is provided to <code class=\"language-text\">filter</code>, it will be used as the callback's <code class=\"language-text\">this</code> value. Otherwise, the value <code class=\"language-text\">undefined</code> will be used as its <code class=\"language-text\">this</code> value. The <code class=\"language-text\">this</code> value ultimately observable by <code class=\"language-text\">callback</code> is determined according to <a href=\"../../operators/this\">the usual rules for determining the <code class=\"language-text\">this</code> seen by a function</a>.</p>\n<p><code class=\"language-text\">filter()</code> does not mutate the array on which it is called.</p>\n<p>The range of elements processed by <code class=\"language-text\">filter()</code> is set before the first invocation of <code class=\"language-text\">callbackFn</code>. Elements which are appended to the array (from <code class=\"language-text\">callbackFn</code>) after the call to <code class=\"language-text\">filter()</code> begins will not be visited by <code class=\"language-text\">callbackFn</code>. If existing elements of the array are deleted in the same way they will not be visited.</p>\n<h2>Polyfill</h2>\n<p><code class=\"language-text\">filter()</code> was added to the ECMA-262 standard in the 5th edition. Therefore, it may not be present in all implementations of the standard.</p>\n<p>You can work around this by inserting the following code at the beginning of your scripts, allowing use of <code class=\"language-text\">filter()</code> in ECMA-262 implementations which do not natively support it. This algorithm is exactly equivalent to the one specified in ECMA-262, 5th edition, assuming that <code class=\"language-text\">fn.call</code> evaluates to the original value of <a href=\"../function/bind\"><code class=\"language-text\">Function.prototype.bind()</code></a>, and that <a href=\"push\"><code class=\"language-text\">Array.prototype.push()</code></a> has its original value.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if (!Array.prototype.filter){\n  Array.prototype.filter = function(func, thisArg) {\n    'use strict';\n    if ( ! ((typeof func === 'Function' || typeof func === 'function') &amp;&amp; this) )\n        throw new TypeError();\n\n    var len = this.length >>> 0,\n        res = new Array(len), // preallocate array\n        t = this, c = 0, i = -1;\n\n    var kValue;\n    if (thisArg === undefined){\n      while (++i !== len){\n        // checks to see if the key was set\n        if (i in this){\n          kValue = t[i]; // in case t is changed in callback\n          if (func(t[i], i, t)){\n            res[c++] = kValue;\n          }\n        }\n      }\n    }\n    else{\n      while (++i !== len){\n        // checks to see if the key was set\n        if (i in this){\n          kValue = t[i];\n          if (func.call(thisArg, t[i], i, t)){\n            res[c++] = kValue;\n          }\n        }\n      }\n    }\n\n    res.length = c; // shrink down array to proper size\n    return res;\n  };\n}</code></pre></div>\n<h2>Examples</h2>\n<h3>Filtering out all small values</h3>\n<p>The following example uses <code class=\"language-text\">filter()</code> to create a filtered array that has all elements with values less than <code class=\"language-text\">10</code> removed.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function isBigEnough(value) {\n  return value >= 10\n}\n\nlet filtered = [12, 5, 8, 130, 44].filter(isBigEnough)\n// filtered is [12, 130, 44]</code></pre></div>\n<h3>Find all prime numbers in an array</h3>\n<p>The following example returns all prime numbers in the array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const array = [-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];\n\nfunction isPrime(num) {\n  for (let i = 2; num > i; i++) {\n    if (num % i == 0) {\n      return false;\n    }\n  }\n  return num > 1;\n}\n\nconsole.log(array.filter(isPrime)); // [2, 3, 5, 7, 11, 13]</code></pre></div>\n<h3>Filtering invalid entries from JSON</h3>\n<p>The following example uses <code class=\"language-text\">filter()</code> to create a filtered json of all elements with non-zero, numeric <code class=\"language-text\">id</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let arr = [\n  { id: 15 },\n  { id: -1 },\n  { id: 0 },\n  { id: 3 },\n  { id: 12.2 },\n  { },\n  { id: null },\n  { id: NaN },\n  { id: 'undefined' }\n]\n\nlet invalidEntries = 0\n\nfunction filterByID(item) {\n  if (Number.isFinite(item.id) &amp;&amp; item.id !== 0) {\n    return true\n  }\n  invalidEntries++\n  return false;\n}\n\nlet arrByID = arr.filter(filterByID)\n\nconsole.log('Filtered Array\\n', arrByID)\n// Filtered Array\n// [{ id: 15 }, { id: -1 }, { id: 3 }, { id: 12.2 }]\n\nconsole.log('Number of Invalid Entries = ', invalidEntries)\n// Number of Invalid Entries = 5</code></pre></div>\n<h3>Searching in array</h3>\n<p>Following example uses <code class=\"language-text\">filter()</code> to filter array content based on search criteria.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let fruits = ['apple', 'banana', 'grapes', 'mango', 'orange']\n\n/**\n * Filter array items based on search criteria (query)\n */\nfunction filterItems(arr, query) {\n  return arr.filter(function(el) {\n      return el.toLowerCase().indexOf(query.toLowerCase()) !== -1\n  })\n}\n\nconsole.log(filterItems(fruits, 'ap'))  // ['apple', 'grapes']\nconsole.log(filterItems(fruits, 'an'))  // ['banana', 'mango', 'orange']</code></pre></div>\n<h4>ES2015 Implementation</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const fruits = ['apple', 'banana', 'grapes', 'mango', 'orange']\n\n/**\n * Filter array items based on search criteria (query)\n */\nconst filterItems = (arr, query) => {\n  return arr.filter(el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1)\n}\n\nconsole.log(filterItems(fruits, 'ap'))  // ['apple', 'grapes']\nconsole.log(filterItems(fruits, 'an'))  // ['banana', 'mango', 'orange']</code></pre></div>\n<h3>Affecting Initial Array (modifying, appending and deleting)</h3>\n<p>The following examples tests the behavior of the <code class=\"language-text\">filter</code> method when the array is modified.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Modifying each words\nlet words = ['spray', 'limit', 'exuberant', 'destruction','elite', 'present']\n\nconst modifiedWords = words.filter( (word, index, arr) => {\n  arr[index+1] +=' extra'\n  return word.length &lt; 6\n})\n\nconsole.log(modifiedWords)\n// Notice there are three words below length 6, but since they've been modified one is returned\n// [\"spray\"]\n\n// Appending new words\nwords = ['spray', 'limit', 'exuberant', 'destruction','elite', 'present']\nconst appendedWords = words.filter( (word, index, arr) => {\n  arr.push('new')\n  return word.length &lt; 6\n})\n\nconsole.log(appendedWords)\n// Only three fits the condition even though the `words` itself now has a lot more words with character length less than 6\n// [\"spray\" ,\"limit\" ,\"elite\"]\n\n// Deleting words\nwords = ['spray', 'limit', 'exuberant', 'destruction', 'elite', 'present']\nconst deleteWords = words.filter( (word, index, arr) => {\n  arr.pop()\n  return word.length &lt; 6\n})\n\nconsole.log(deleteWords)\n// Notice 'elite' is not even obtained as its been popped off `words` before filter can even get there\n// [\"spray\" ,\"limit\"]</code></pre></div>"},{"url":"/docs/js-tips/eval/","relativePath":"docs/js-tips/eval.md","relativeDir":"docs/js-tips","base":"eval.md","name":"eval","frontmatter":{"title":"eval()","weight":0,"excerpt":null,"seo":{"title":"eval()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>eval()</h1>\n<p><strong>Warning:</strong> Executing JavaScript from a string is an enormous security risk. It is far too easy for a bad actor to run arbitrary code when you use <code class=\"language-text\">eval()</code>. See <a href=\"#never_use_eval!\">Never use eval()!</a>, below.</p>\n<p>The <code class=\"language-text\">eval()</code> function evaluates JavaScript code represented as a string.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">eval(string)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">string</code>\nA string representing a JavaScript expression, statement, or sequence of statements. The expression can include variables and properties of existing objects.</p>\n<h3>Return value</h3>\n<p>The completion value of evaluating the given code. If the completion value is empty, <a href=\"undefined\"><code class=\"language-text\">undefined</code></a> is returned.</p>\n<h2>Description</h2>\n<p><code class=\"language-text\">eval()</code> is a function property of the global object.</p>\n<p>The argument of the <code class=\"language-text\">eval()</code> function is a string. If the string represents an expression, <code class=\"language-text\">eval()</code> evaluates the expression. If the argument represents one or more JavaScript statements, <code class=\"language-text\">eval()</code> evaluates the statements. Do not call <code class=\"language-text\">eval()</code> to evaluate an arithmetic expression; JavaScript evaluates arithmetic expressions automatically.</p>\n<p>If you construct an arithmetic expression as a string, you can use <code class=\"language-text\">eval()</code> to evaluate it at a later time. For example, suppose you have a variable <code class=\"language-text\">x</code>. You can postpone evaluation of an expression involving <code class=\"language-text\">x</code> by assigning the string value of the expression, say \"<code class=\"language-text\">3 * x + 2</code>\", to a variable, and then calling <code class=\"language-text\">eval()</code> at a later point in your script.</p>\n<p>If the argument of <code class=\"language-text\">eval()</code> is not a string, <code class=\"language-text\">eval()</code> returns the argument unchanged. In the following example, the <code class=\"language-text\">String</code> constructor is specified and <code class=\"language-text\">eval()</code> returns a <code class=\"language-text\">String</code> object rather than evaluating the string.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">eval(new String('2 + 2')); // returns a String object containing \"2 + 2\"\neval('2 + 2');             // returns 4</code></pre></div>\n<p>You can work around this limitation in a generic fashion by using <code class=\"language-text\">toString()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var expression = new String('2 + 2');\neval(expression.toString());            // returns 4</code></pre></div>\n<p>If you use the <code class=\"language-text\">eval</code> function <em>indirectly,</em> by invoking it via a reference other than <code class=\"language-text\">eval</code>, <a href=\"https://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2\">as of ECMAScript 5</a> it works in the global scope rather than the local scope. This means, for instance, that function declarations create global functions, and that the code being evaluated doesn't have access to local variables within the scope where it's being called.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function test() {\n  var x = 2, y = 4;\n  // Direct call, uses local scope\n  console.log(eval('x + y')); // Result is 6\n  // Indirect call using the comma operator to return eval\n  console.log((0, eval)('x + y')); // Uses global scope, throws because x is undefined\n  // Indirect call using a variable to store and return eval\n  var geval = eval;\n  console.log(geval('x + y')); // Uses global scope, throws because x is undefined\n}</code></pre></div>\n<h2>Never use eval()!</h2>\n<p><code class=\"language-text\">eval()</code> is a dangerous function, which executes the code it's passed with the privileges of the caller. If you run <code class=\"language-text\">eval()</code> with a string that could be affected by a malicious party, you may end up running malicious code on the user's machine with the permissions of your webpage / extension. More importantly, a third-party code can see the scope in which <code class=\"language-text\">eval()</code> was invoked, which can lead to possible attacks in ways to which the similar <a href=\"function\"><code class=\"language-text\">Function</code></a> is not susceptible.</p>\n<p><code class=\"language-text\">eval()</code> is also slower than the alternatives, since it has to invoke the JavaScript interpreter, while many other constructs are optimized by modern JS engines.</p>\n<p>Additionally, modern javascript interpreters convert javascript to machine code. This means that any concept of variable naming gets obliterated. Thus, any use of <code class=\"language-text\">eval()</code> will force the browser to do long expensive variable name lookups to figure out where the variable exists in the machine code and set its value. Additionally, new things can be introduced to that variable through <code class=\"language-text\">eval()</code> such as changing the type of that variable, forcing the browser to re-evaluate all of the generated machine code to compensate.</p>\n<p>Fortunately, there's a very good alternative to <code class=\"language-text\">eval()</code>: using <a href=\"function\"><code class=\"language-text\">window.Function()</code></a>. See this example of how to convert code using a dangerous <code class=\"language-text\">eval()</code> to using <code class=\"language-text\">Function()</code>, see below.</p>\n<p>Bad code with <code class=\"language-text\">eval()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function looseJsonParse(obj){\n    return eval(\"(\" + obj + \")\");\n}\nconsole.log(looseJsonParse(\n   \"{a:(4-1), b:function(){}, c:new Date()}\"\n))</code></pre></div>\n<p>Better code without <code class=\"language-text\">eval()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function looseJsonParse(obj){\n    return Function('\"use strict\";return (' + obj + ')')();\n}\nconsole.log(looseJsonParse(\n   \"{a:(4-1), b:function(){}, c:new Date()}\"\n))</code></pre></div>\n<p>Comparing the two code snippets above, the two code snippets might seem to work the same way, but think again: the <code class=\"language-text\">eval()</code> one is a great deal slower. Notice <code class=\"language-text\">c: new Date()</code> in the evaluated object. In the function without the <code class=\"language-text\">eval()</code>, the object is being evaluated in the global scope, so it is safe for the browser to assume that <code class=\"language-text\">Date</code> refers to <code class=\"language-text\">window.Date()</code> instead of a local variable called <code class=\"language-text\">Date</code>. But, in the code using <code class=\"language-text\">eval()</code>, the browser cannot assume this since what if your code looked like the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Date(n){\n    return [\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\",\"Sunday\"][n%7 || 0];\n}\nfunction looseJsonParse(obj){\n    return eval(\"(\" + obj + \")\");\n}\nconsole.log(looseJsonParse(\n   \"{a:(4-1), b:function(){}, c:new Date()}\"\n))</code></pre></div>\n<p>Thus, in the <code class=\"language-text\">eval()</code> version of the code, the browser is forced to make the expensive lookup call to check to see if there are any local variables called <code class=\"language-text\">Date()</code>. This is incredibly inefficient compared to <code class=\"language-text\">Function()</code>.</p>\n<p>In a related circumstance, what if you actually wanted your <code class=\"language-text\">Date()</code> function to be able to be called from the code inside <code class=\"language-text\">Function()</code>. Should you just take the easy way out and fall back to <code class=\"language-text\">eval()</code>? No! Never. Instead try the approach below.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Date(n){\n    return [\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\",\"Sunday\"][n%7 || 0];\n}\nfunction runCodeWithDateFunction(obj){\n    return Function('\"use strict\";return (' + obj + ')')()(\n        Date\n    );\n}\nconsole.log(runCodeWithDateFunction(\n   \"function(Date){ return Date(5) }\"\n))</code></pre></div>\n<p>The code above may seem inefficiently slow because of the triple nested function, but let's analyze the benefits of the above efficient method:</p>\n<ul>\n<li>It allows the code in the string passed to <code class=\"language-text\">runCodeWithDateFunction()</code> to be minified.</li>\n<li>Function call overhead is minimal, making the far smaller code size well worth the benefit</li>\n<li><code class=\"language-text\">Function()</code> more easily allows your code to utilize the performance buttering <code class=\"language-text\">\"use strict\";</code></li>\n<li>The code does not use <code class=\"language-text\">eval()</code>, making it orders of magnitude faster than otherwise.</li>\n</ul>\n<p>Lastly, let's examine minification. With using <code class=\"language-text\">Function()</code> as shown above, you can minify the code string passed to <code class=\"language-text\">runCodeWithDateFunction()</code> far more efficiently because the function arguments names can be minified too as seen in the minified code below.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(Function('\"use strict\";return(function(a){return a(5)})')()(function(a){\nreturn\"Monday Tuesday Wednesday Thursday Friday Saturday Sunday\".split(\" \")[a%7||0]}));</code></pre></div>\n<p>There are also additional safer (and faster!) alternatives to <code class=\"language-text\">eval()</code> or <code class=\"language-text\">Function()</code> for common use-cases.</p>\n<h3>Accessing member properties</h3>\n<p>You should not use <code class=\"language-text\">eval()</code> to convert property names into properties. Consider the following example where the property of the object to be accessed is not known until the code is executed. This can be done with <code class=\"language-text\">eval()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var obj = { a: 20, b: 30 };\nvar propName = getPropName();  // returns \"a\" or \"b\"\n\neval( 'var result = obj.' + propName );</code></pre></div>\n<p>However, <code class=\"language-text\">eval()</code> is not necessary here. In fact, its use here is discouraged. Instead, use the <a href=\"../operators/property_accessors\">property accessors</a>, which are much faster and safer:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var obj = { a: 20, b: 30 };\nvar propName = getPropName();  // returns \"a\" or \"b\"\nvar result = obj[ propName ];  //  obj[ \"a\" ] is the same as obj.a</code></pre></div>\n<p>You can even use this method to access descendant properties. Using <code class=\"language-text\">eval()</code> this would look like:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var obj = {a: {b: {c: 0}}};\nvar propPath = getPropPath();  // returns e.g. \"a.b.c\"\n\neval( 'var result = obj.' + propPath );</code></pre></div>\n<p>Avoiding <code class=\"language-text\">eval()</code> here could be done by splitting the property path and looping through the different properties:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function getDescendantProp(obj, desc) {\n  var arr = desc.split('.');\n  while (arr.length) {\n    obj = obj[arr.shift()];\n  }\n  return obj;\n}\n\nvar obj = {a: {b: {c: 0}}};\nvar propPath = getPropPath();  // returns e.g. \"a.b.c\"\nvar result = getDescendantProp(obj, propPath);</code></pre></div>\n<p>Setting a property that way works similarly:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function setDescendantProp(obj, desc, value) {\n  var arr = desc.split('.');\n  while (arr.length > 1) {\n    obj = obj[arr.shift()];\n  }\n  return obj[arr[0]] = value;\n}\n\nvar obj = {a: {b: {c: 0}}};\nvar propPath = getPropPath();  // returns e.g. \"a.b.c\"\nvar result = setDescendantProp(obj, propPath, 1);  // obj.a.b.c will now be 1</code></pre></div>\n<h3>Use functions instead of evaluating snippets of code</h3>\n<p>JavaScript has <a href=\"https://en.wikipedia.org/wiki/First-class_function\">first-class functions</a>, which means you can pass functions as arguments to other APIs, store them in variables and objects' properties, and so on. Many DOM APIs are designed with this in mind, so you can (and should) write:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// instead of setTimeout(\" ... \", 1000) use:\nsetTimeout(function() { ... }, 1000);\n\n// instead of elt.setAttribute(\"onclick\", \"...\") use:\nelt.addEventListener('click', function() { ... } , false);</code></pre></div>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures\">Closures</a> are also helpful as a way to create parameterized functions without concatenating strings.</p>\n<h3>Parsing JSON (converting strings to JavaScript objects)</h3>\n<p>If the string you're calling <code class=\"language-text\">eval()</code> on contains data (for example, an array: <code class=\"language-text\">\"[1, 2, 3]\"</code>), as opposed to code, you should consider switching to <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/JSON\">JSON</a>, which allows the string to use a subset of JavaScript syntax to represent data.</p>\n<p>Note that since JSON syntax is limited compared to JavaScript syntax, many valid JavaScript literals will not parse as JSON. For example, trailing commas are not allowed in JSON, and property names (keys) in object literals must be enclosed in quotes. Be sure to use a JSON serializer to generate strings that will be later parsed as JSON.</p>\n<h3>Pass data instead of code</h3>\n<p>For example, an extension designed to scrape contents of web-pages could have the scraping rules defined in <a href=\"https://developer.mozilla.org/en-US/docs/Web/XPath\">XPath</a> instead of JavaScript code.</p>\n<h2>Examples</h2>\n<h3>Using <code class=\"language-text\">eval</code></h3>\n<p>In the following code, both of the statements containing <code class=\"language-text\">eval()</code> return 42. The first evaluates the string \"<code class=\"language-text\">x + y + 1</code>\"; the second evaluates the string \"<code class=\"language-text\">42</code>\".</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var x = 2;\nvar y = 39;\nvar z = '42';\neval('x + y + 1'); // returns 42\neval(z);           // returns 42</code></pre></div>\n<h3>Using <code class=\"language-text\">eval</code> to evaluate a string of JavaScript statements</h3>\n<p>The following example uses <code class=\"language-text\">eval()</code> to evaluate the string <code class=\"language-text\">str</code>. This string consists of JavaScript statements that assigns <code class=\"language-text\">z</code> a value of 42 if <code class=\"language-text\">x</code> is five, and assigns 0 to <code class=\"language-text\">z</code> otherwise. When the second statement is executed, <code class=\"language-text\">eval()</code> will cause these statements to be performed, and it will also evaluate the set of statements and return the value that is assigned to <code class=\"language-text\">z</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var x = 5;\nvar str = \"if (x == 5) {console.log('z is 42'); z = 42;} else z = 0;\";\n\nconsole.log('z is ', eval(str));</code></pre></div>\n<p>If you define multiple values then the last value is returned.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var x = 5;\nvar str = \"if (x == 5) {console.log('z is 42'); z = 42; x = 420; } else z = 0;\";\n\nconsole.log('x is ', eval(str)); // z is 42  x is 420</code></pre></div>\n<h3>Last expression is evaluated</h3>\n<p><code class=\"language-text\">eval()</code> returns the value of the last expression evaluated.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var str = 'if ( a ) { 1 + 1; } else { 1 + 2; }';\nvar a = true;\nvar b = eval(str);  // returns 2\n\nconsole.log('b is : ' + b);\n\na = false;\nb = eval(str);  // returns 3\n\nconsole.log('b is : ' + b);</code></pre></div>\n<h3><code class=\"language-text\">eval</code> as a string defining function requires \"(\" and \")\" as prefix and suffix</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var fctStr1 = 'function a() {}'\nvar fctStr2 = '(function a() {})'\nvar fct1 = eval(fctStr1)  // return undefined\nvar fct2 = eval(fctStr2)  // return a function</code></pre></div>"},{"url":"/docs/js-tips/foreach/","relativePath":"docs/js-tips/foreach.md","relativeDir":"docs/js-tips","base":"foreach.md","name":"foreach","frontmatter":{"title":"Array.forEach()","weight":0,"excerpt":null,"seo":{"title":"Array.prototype.forEach()","description":"The forEach() method executes a provided function once for each array element.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Array.prototype.forEach()</h1>\n<p>The <code class=\"language-text\">forEach()</code> method executes a provided function once for each array element.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Arrow function\nforEach((element) => { ... } )\nforEach((element, index) => { ... } )\nforEach((element, index, array) => { ... } )\n\n// Callback function\nforEach(callbackFn)\nforEach(callbackFn, thisArg)\n\n// Inline callback function\nforEach(function callbackFn(element) { ... })\nforEach(function callbackFn(element, index) { ... })\nforEach(function callbackFn(element, index, array){ ... })\nforEach(function callbackFn(element, index, array) { ... }, thisArg)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">callbackFn</code>\nFunction to execute on each element. It accepts between one and three arguments:</p>\n<p><code class=\"language-text\">element</code>\nThe current element being processed in the array.</p>\n<p><code class=\"language-text\">index</code> <span class=\"badge inline optional\">Optional</span>\nThe index of <code class=\"language-text\">element</code> in the array.</p>\n<p><code class=\"language-text\">array</code> <span class=\"badge inline optional\">Optional</span>\nThe array <code class=\"language-text\">forEach()</code> was called upon.</p>\n<p><code class=\"language-text\">thisArg</code> <span class=\"badge inline optional\">Optional</span>\nValue to use as <code class=\"language-text\">this</code> when executing <code class=\"language-text\">callbackFn</code>.</p>\n<h3>Return value</h3>\n<p><code class=\"language-text\">undefined</code>.</p>\n<h2>Description</h2>\n<p><code class=\"language-text\">forEach()</code> calls a provided <code class=\"language-text\">callbackFn</code> function once for each element in an array in ascending index order. It is not invoked for index properties that have been deleted or are uninitialized. (For sparse arrays, <a href=\"#sparsearray\">see example below</a>.)</p>\n<p><code class=\"language-text\">callbackFn</code> is invoked with three arguments:</p>\n<ol>\n<li>the value of the element</li>\n<li>the index of the element</li>\n<li>the Array object being traversed</li>\n</ol>\n<p>If a <code class=\"language-text\">thisArg</code> parameter is provided to <code class=\"language-text\">forEach()</code>, it will be used as callback's <code class=\"language-text\">this</code> value. The <code class=\"language-text\">thisArg</code> value ultimately observable by <code class=\"language-text\">callbackFn</code> is determined according to <a href=\"../../operators/this\">the usual rules for determining the <code class=\"language-text\">this</code> seen by a function</a>.</p>\n<p>The range of elements processed by <code class=\"language-text\">forEach()</code> is set before the first invocation of <code class=\"language-text\">callbackFn</code>. Elements which are appended to the array after the call to <code class=\"language-text\">forEach()</code> begins will not be visited by <code class=\"language-text\">callbackFn</code>. If existing elements of the array are changed or deleted, their value as passed to <code class=\"language-text\">callbackFn</code> will be the value at the time <code class=\"language-text\">forEach()</code> visits them; elements that are deleted before being visited are not visited. If elements that are already visited are removed (e.g. using <a href=\"shift\"><code class=\"language-text\">shift()</code></a>) during the iteration, later elements will be skipped. (<a href=\"#Modifying_the_array_during_iteration\">See this example, below</a>.)</p>\n<p><code class=\"language-text\">forEach()</code> executes the <code class=\"language-text\">callbackFn</code> function once for each array element; unlike <a href=\"map\"><code class=\"language-text\">map()</code></a> or <a href=\"reduce\"><code class=\"language-text\">reduce()</code></a> it always returns the value <a href=\"../undefined\"><code class=\"language-text\">undefined</code></a> and is not chainable. The typical use case is to execute side effects at the end of a chain.</p>\n<p><code class=\"language-text\">forEach()</code> does not mutate the array on which it is called. (However, <code class=\"language-text\">callbackFn</code> may do so)</p>\n<p><strong>Note:</strong> There is no way to stop or break a <code class=\"language-text\">forEach()</code> loop other than by throwing an exception. If you need such behavior, the <code class=\"language-text\">forEach()</code> method is the wrong tool.</p>\n<p>Early termination may be accomplished with:</p>\n<ul>\n<li>A simple <a href=\"../../statements/for\">for</a> loop</li>\n<li>A <a href=\"../../statements/for...of\">for...of</a> / <a href=\"../../statements/for...in\">for...in</a> loops</li>\n<li><a href=\"every\"><code class=\"language-text\">Array.prototype.every()</code></a></li>\n<li><a href=\"some\"><code class=\"language-text\">Array.prototype.some()</code></a></li>\n<li><a href=\"find\"><code class=\"language-text\">Array.prototype.find()</code></a></li>\n<li><a href=\"findindex\"><code class=\"language-text\">Array.prototype.findIndex()</code></a></li>\n</ul>\n<p>Array methods: <a href=\"every\"><code class=\"language-text\">every()</code></a>, <a href=\"some\"><code class=\"language-text\">some()</code></a>, <a href=\"find\"><code class=\"language-text\">find()</code></a>, and <a href=\"findindex\"><code class=\"language-text\">findIndex()</code></a> test the array elements with a predicate returning a truthy value to determine if further iteration is required.</p>\n<p><strong>Note:</strong> <code class=\"language-text\">forEach</code> expects a synchronous function.</p>\n<p><code class=\"language-text\">forEach</code> does not wait for promises. Make sure you are aware of the implications while using promises (or async functions) as <code class=\"language-text\">forEach</code> callback.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let ratings = [5, 4, 5];\nlet sum = 0;\n\nlet sumFunction = async function (a, b)\n{\n  return a + b\n}\n\nratings.forEach(async function(rating) {\n  sum = await sumFunction(sum, rating)\n})\n\nconsole.log(sum)\n// Naively expected output: 14\n// Actual output: 0</code></pre></div>\n<h2>Polyfill</h2>\n<p><code class=\"language-text\">forEach()</code> was added to the ECMA-262 standard in the 5<sup>th</sup> edition, and it may not be present in all implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of <code class=\"language-text\">forEach()</code> in implementations which do not natively support it.</p>\n<p>This algorithm is exactly the one specified in ECMA-262, 5<sup>th</sup> edition, assuming <a href=\"../object\"><code class=\"language-text\">Object</code></a> and <a href=\"../typeerror\"><code class=\"language-text\">TypeError</code></a> have their original values and that <code class=\"language-text\">fun.call</code> evaluates to the original value of <a href=\"../function/call\"><code class=\"language-text\">Function.prototype.call()</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Production steps of ECMA-262, Edition 5, 15.4.4.18\n// Reference: https://es5.github.io/#x15.4.4.18\n\nif (!Array.prototype['forEach']) {\n\n  Array.prototype.forEach = function(callback, thisArg) {\n\n    if (this == null) { throw new TypeError('Array.prototype.forEach called on null or undefined'); }\n\n    var T, k;\n    // 1. Let O be the result of calling toObject() passing the\n    // |this| value as the argument.\n    var O = Object(this);\n\n    // 2. Let lenValue be the result of calling the Get() internal\n    // method of O with the argument \"length\".\n    // 3. Let len be toUint32(lenValue).\n    var len = O.length >>> 0;\n\n    // 4. If isCallable(callback) is false, throw a TypeError exception.\n    // See: https://es5.github.com/#x9.11\n    if (typeof callback !== \"function\") { throw new TypeError(callback + ' is not a function'); }\n\n    // 5. If thisArg was supplied, let T be thisArg; else let\n    // T be undefined.\n    if (arguments.length > 1) { T = thisArg; }\n\n    // 6. Let k be 0\n    k = 0;\n\n    // 7. Repeat, while k &lt; len\n    while (k &lt; len) {\n\n      var kValue;\n\n      // a. Let Pk be ToString(k).\n      //    This is implicit for LHS operands of the in operator\n      // b. Let kPresent be the result of calling the HasProperty\n      //    internal method of O with argument Pk.\n      //    This step can be combined with c\n      // c. If kPresent is true, then\n      if (k in O) {\n\n        // i. Let kValue be the result of calling the Get internal\n        // method of O with argument Pk.\n        kValue = O[k];\n\n        // ii. Call the Call internal method of callback with T as\n        // the this value and argument list containing kValue, k, and O.\n        callback.call(T, kValue, k, O);\n      }\n      // d. Increase k by 1.\n      k++;\n    }\n    // 8. return undefined\n  };\n}</code></pre></div>\n<h2>Examples</h2>\n<h3>No operation for uninitialized values (sparse arrays)</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const arraySparse = [1,3,,7]\nlet numCallbackRuns = 0\n\narraySparse.forEach(function(element) {\n  console.log(element)\n  numCallbackRuns++\n})\n\nconsole.log(\"numCallbackRuns: \", numCallbackRuns)\n\n// 1\n// 3\n// 7\n// numCallbackRuns: 3\n// comment: as you can see the missing value between 3 and 7 didn't invoke callback function.</code></pre></div>\n<h3>Converting a for loop to forEach</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const items = ['item1', 'item2', 'item3']\nconst copyItems = []\n\n// before\nfor (let i = 0; i &lt; items.length; i++) {\n  copyItems.push(items[i])\n}\n\n// after\nitems.forEach(function(item){\n  copyItems.push(item)\n})</code></pre></div>\n<h3>Printing the contents of an array</h3>\n<p><strong>Note:</strong> In order to display the content of an array in the console, you can use <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Console/table\"><code class=\"language-text\">console.table()</code></a>, which prints a formatted version of the array.</p>\n<p>The following example illustrates an alternative approach, using <code class=\"language-text\">forEach()</code>.</p>\n<p>The following code logs a line for each element in an array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function logArrayElements(element, index, array) {\n  console.log('a[' + index + '] = ' + element)\n}\n\n// Notice that index 2 is skipped, since there is no item at\n// that position in the array...\n[2, 5, , 9].forEach(logArrayElements)\n// logs:\n// a[0] = 2\n// a[1] = 5\n// a[3] = 9</code></pre></div>\n<h3>Using thisArg</h3>\n<p>The following (contrived) example updates an object's properties from each entry in the array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Counter() {\n  this.sum = 0\n  this.count = 0\n}\nCounter.prototype.add = function(array) {\n  array.forEach(function countEntry(entry) {\n    this.sum += entry\n    ++this.count\n  }, this)\n}\n\nconst obj = new Counter()\nobj.add([2, 5, 9])\nobj.count\n// 3\nobj.sum\n// 16</code></pre></div>\n<p>Since the <code class=\"language-text\">thisArg</code> parameter (<code class=\"language-text\">this</code>) is provided to <code class=\"language-text\">forEach()</code>, it is passed to <code class=\"language-text\">callback</code> each time it's invoked. The callback uses it as its <code class=\"language-text\">this</code> value.</p>\n<p><strong>Note:</strong> If passing the callback function used an <a href=\"../../functions/arrow_functions\">arrow function expression</a>, the <code class=\"language-text\">thisArg</code> parameter could be omitted, since all arrow functions lexically bind the <a href=\"../../operators/this\"><code class=\"language-text\">this</code></a> value.</p>\n<h3>An object copy function</h3>\n<p>The following code creates a copy of a given object.</p>\n<p>There are different ways to create a copy of an object. The following is just one way and is presented to explain how <code class=\"language-text\">Array.prototype.forEach()</code> works by using ECMAScript 5 <code class=\"language-text\">Object.*</code> meta property functions.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function copy(obj) {\n  const copy = Object.create(Object.getPrototypeOf(obj))\n  const propNames = Object.getOwnPropertyNames(obj)\n\n  propNames.forEach(function(name) {\n    const desc = Object.getOwnPropertyDescriptor(obj, name)\n    Object.defineProperty(copy, name, desc)\n  })\n\n  return copy\n}\n\nconst obj1 = { a: 1, b: 2 }\nconst obj2 = copy(obj1) // obj2 looks like obj1 now</code></pre></div>\n<h3>Modifying the array during iteration</h3>\n<p>The following example logs <code class=\"language-text\">one</code>, <code class=\"language-text\">two</code>, <code class=\"language-text\">four</code>.</p>\n<p>When the entry containing the value <code class=\"language-text\">two</code> is reached, the first entry of the whole array is shifted off—resulting in all remaining entries moving up one position. Because element <code class=\"language-text\">four</code> is now at an earlier position in the array, <code class=\"language-text\">three</code> will be skipped.</p>\n<p><code class=\"language-text\">forEach()</code> does not make a copy of the array before iterating.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let words = ['one', 'two', 'three', 'four']\nwords.forEach(function(word) {\n  console.log(word)\n  if (word === 'two') {\n    words.shift() //'one' will delete from array\n  }\n}) // one // two // four\n\nconsole.log(words);  //['two', 'three', 'four']</code></pre></div>\n<h3>Flatten an array</h3>\n<p>The following example is only here for learning purpose. If you want to flatten an array using built-in methods you can use <a href=\"flat\"><code class=\"language-text\">Array.prototype.flat()</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function flatten(arr) {\n  const result = []\n\n  arr.forEach(function(i) {\n    if (Array.isArray(i)) {\n      result.push(...flatten(i))\n    } else {\n      result.push(i)\n    }\n  })\n\n  return result\n}\n\n// Usage\nconst nested = [1, 2, 3, [4, 5, [6, 7], 8, 9]]\n\nflatten(nested) // [1, 2, 3, 4, 5, 6, 7, 8, 9]</code></pre></div>"},{"url":"/docs/js-tips/import/","relativePath":"docs/js-tips/import.md","relativeDir":"docs/js-tips","base":"import.md","name":"import","frontmatter":{"title":"import","weight":0,"excerpt":null,"seo":{"title":"import","description":"The static import statement is used to import read only live bindings which are exported by another module.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>import</h1>\n<p>The static <code class=\"language-text\">import</code> statement is used to import read only live bindings which are <a href=\"export\">exported</a> by another module.</p>\n<p>Imported modules are in <a href=\"../strict_mode\"><code class=\"language-text\">strict mode</code></a> whether you declare them as such or not. The <code class=\"language-text\">import</code> statement cannot be used in embedded scripts unless such script has a <code class=\"language-text\">type=\"module\"</code>. Bindings imported are called live bindings because they are updated by the module that exported the binding.</p>\n<p>There is also a function-like dynamic <code class=\"language-text\">import()</code>, which does not require scripts of <code class=\"language-text\">type=\"module\"</code>.</p>\n<p>Backward compatibility can be ensured using attribute <code class=\"language-text\">nomodule</code> on the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script\"><code class=\"language-text\">&lt;script></code></a> tag.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">import</span> defaultExport <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> name <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token keyword\">as</span> alias1 <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token punctuation\">,</span> export2 <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> foo <span class=\"token punctuation\">,</span> bar <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name/path/to/specific/un-exported/file\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token punctuation\">,</span> export2 <span class=\"token keyword\">as</span> alias2 <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> defaultExport<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> export1 <span class=\"token punctuation\">[</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> defaultExport<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> name <span class=\"token keyword\">from</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">import</span> <span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">import</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"module-name\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">defaultExport</code>\nName that will refer to the default export from the module.</p>\n<p><code class=\"language-text\">module-name</code>\nThe module to import from. This is often a relative or absolute path name to the <code class=\"language-text\">.js</code> file containing the module. Certain bundlers may permit or require the use of the extension; check your environment. Only single quoted and double quoted Strings are allowed.</p>\n<p><code class=\"language-text\">name</code>\nName of the module object that will be used as a kind of namespace when referring to the imports.</p>\n<p><code class=\"language-text\">exportN</code>\nName of the exports to be imported.</p>\n<p><code class=\"language-text\">aliasN</code>\nNames that will refer to the named imports.</p>\n<h2>Description</h2>\n<p>The <code class=\"language-text\">name</code> parameter is the name of the \"module object\" which will be used as a kind of namespace to refer to the exports. The <code class=\"language-text\">export</code> parameters specify individual named exports, while the <code class=\"language-text\">import * as name</code> syntax imports all of them. Below are examples to clarify the syntax.</p>\n<h3>Import an entire module's contents</h3>\n<p>This inserts <code class=\"language-text\">myModule</code> into the current scope, containing all the exports from the module in the file located in <code class=\"language-text\">/modules/my-module.js</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import * as myModule from '/modules/my-module.js';</code></pre></div>\n<p>Here, accessing the exports means using the module name (\"myModule\" in this case) as a namespace. For example, if the module imported above includes an export <code class=\"language-text\">doAllTheAmazingThings()</code>, you would call it like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">myModule.doAllTheAmazingThings();</code></pre></div>\n<h3>Import a single export from a module</h3>\n<p>Given an object or value named <code class=\"language-text\">myExport</code> which has been exported from the module <code class=\"language-text\">my-module</code> either implicitly (because the entire module is exported, for example using <code class=\"language-text\">export * from 'another.js'</code>) or explicitly (using the <a href=\"export\"><code class=\"language-text\">export</code></a> statement), this inserts <code class=\"language-text\">myExport</code> into the current scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import {myExport} from '/modules/my-module.js';</code></pre></div>\n<h3>Import multiple exports from module</h3>\n<p>This inserts both <code class=\"language-text\">foo</code> and <code class=\"language-text\">bar</code> into the current scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import {foo, bar} from '/modules/my-module.js';</code></pre></div>\n<h3>Import an export with a more convenient alias</h3>\n<p>You can rename an export when importing it. For example, this inserts <code class=\"language-text\">shortName</code> into the current scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import {reallyReallyLongModuleExportName as shortName}\n  from '/modules/my-module.js';</code></pre></div>\n<h3>Rename multiple exports during import</h3>\n<p>Import multiple exports from a module with convenient aliases.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import {\n  reallyReallyLongModuleExportName as shortName,\n  anotherLongModuleName as short\n} from '/modules/my-module.js';</code></pre></div>\n<h3>Import a module for its side effects only</h3>\n<p>Import an entire module for side effects only, without importing anything. This runs the module's global code, but doesn't actually import any values.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import '/modules/my-module.js';</code></pre></div>\n<p>This works with <a href=\"#dynamic_imports\">dynamic imports</a> as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(async () => {\n  if (somethingIsTrue) {\n    // import module for side effects\n    await import('/modules/my-module.js');\n  }\n})();</code></pre></div>\n<p>If your project uses packages that export ESM, you can also import them for side effects only. This will run the code in the package entry point file (and any files it imports) only.</p>\n<h3>Importing defaults</h3>\n<p>It is possible to have a default <a href=\"export\"><code class=\"language-text\">export</code></a> (whether it is an object, a function, a class, etc.). The <code class=\"language-text\">import</code> statement may then be used to import such defaults.</p>\n<p>The simplest version directly imports the default:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import myDefault from '/modules/my-module.js';</code></pre></div>\n<p>It is also possible to use the default syntax with the ones seen above (namespace imports or named imports). In such cases, the default import will have to be declared first. For instance:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import myDefault, * as myModule from '/modules/my-module.js';\n// myModule used as a namespace</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import myDefault, {foo, bar} from '/modules/my-module.js';\n// specific, named imports</code></pre></div>\n<p>When importing a default export with <a href=\"#dynamic_imports\">dynamic imports</a>, it works a bit differently. You need to destructure and rename the \"default\" key from the returned object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(async () => {\n  if (somethingIsTrue) {\n    const { default: myDefault, foo, bar } = await import('/modules/my-module.js');\n  }\n})();</code></pre></div>\n<h3>Dynamic Imports</h3>\n<p>The standard import syntax is static and will always result in all code in the imported module being evaluated at load time. In situations where you wish to load a module conditionally or on demand, you can use a dynamic import instead. The following are some reasons why you might need to use dynamic import:</p>\n<ul>\n<li>When importing statically significantly slows the loading of your code and there is a low likelihood that you will need the code you are importing, or you will not need it until a later time.</li>\n<li>When importing statically significantly increases your program's memory usage and there is a low likelihood that you will need the code you are importing.</li>\n<li>When the module you are importing does not exist at load time</li>\n<li>When the import specifier string needs to be constructed dynamically. (Static import only supports static specifiers.)</li>\n<li>When the module being imported has side effects, and you do not want those side effects unless some condition is true. (It is recommended not to have any side effects in a module, but you sometimes cannot control this in your module dependencies.)</li>\n</ul>\n<p>Use dynamic import only when necessary. The static form is preferable for loading initial dependencies, and can benefit more readily from static analysis tools and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking\">tree shaking</a>.</p>\n<p>To dynamically import a module, the <code class=\"language-text\">import</code> keyword may be called as a function. When used this way, it returns a promise.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import('/modules/my-module.js')\n  .then((module) => {\n    // Do something with the module.\n  });</code></pre></div>\n<p>This form also supports the <code class=\"language-text\">await</code> keyword.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let module = await import('/modules/my-module.js');</code></pre></div>\n<h2>Examples</h2>\n<h3>Standard Import</h3>\n<p>The code below shows how to import from a secondary module to assist in processing an AJAX JSON request.</p>\n<h4>The module: file.js</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function getJSON(url, callback) {\n  let xhr = new XMLHttpRequest();\n  xhr.onload = function () {\n    callback(this.responseText)\n  };\n  xhr.open('GET', url, true);\n  xhr.send();\n}\n\nexport function getUsefulContents(url, callback) {\n  getJSON(url, data => callback(JSON.parse(data)));\n}</code></pre></div>\n<h4>The main program: main.js</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { getUsefulContents } from '/modules/file.js';\n\ngetUsefulContents('http://www.example.com',\n    data => { doSomethingUseful(data); });</code></pre></div>\n<h3>Dynamic Import</h3>\n<p>This example shows how to load functionality on to a page based on a user action, in this case a button click, and then call a function within that module. This is not the only way to implement this functionality. The <code class=\"language-text\">import()</code> function also supports <code class=\"language-text\">await</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const main = document.querySelector(\"main\");\nfor (const link of document.querySelectorAll(\"nav > a\")) {\n  link.addEventListener(\"click\", e => {\n    e.preventDefault();\n\n    import('/modules/my-module.js')\n      .then(module => {\n        module.loadPageInto(main);\n      })\n      .catch(err => {\n        main.textContent = err.message;\n      });\n  });\n}</code></pre></div>"},{"url":"/docs/js-tips/every/","relativePath":"docs/js-tips/every.md","relativeDir":"docs/js-tips","base":"every.md","name":"every","frontmatter":{"title":"Array.every()","weight":0,"excerpt":null,"seo":{"title":"Array.prototype.every()","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Array.prototype.every()</h1>\n<p>The <code class=\"language-text\">every()</code> method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Arrow function\nevery((element) => { ... } )\nevery((element, index) => { ... } )\nevery((element, index, array) => { ... } )\n\n// Callback function\nevery(callbackFn)\nevery(callbackFn, thisArg)\n\n// Inline callback function\nevery(function callbackFn(element) { ... })\nevery(function callbackFn(element, index) { ... })\nevery(function callbackFn(element, index, array){ ... })\nevery(function callbackFn(element, index, array) { ... }, thisArg)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">callbackFn</code>\nA function to test for each element, taking three arguments:</p>\n<p><code class=\"language-text\">element</code>\nThe current element being processed in the array.</p>\n<p><code class=\"language-text\">index</code> <span class=\"badge inline optional\">Optional</span>\nThe index of the current element being processed in the array.</p>\n<p><code class=\"language-text\">array</code> <span class=\"badge inline optional\">Optional</span>\nThe array <code class=\"language-text\">every</code> was called upon.</p>\n<p><code class=\"language-text\">thisArg</code> <span class=\"badge inline optional\">Optional</span>\nA value to use as <code class=\"language-text\">this</code> when executing <code class=\"language-text\">callbackFn</code>.</p>\n<h3>Return value</h3>\n<p><code class=\"language-text\">true</code> if the <code class=\"language-text\">callbackFn</code> function returns a <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Truthy\">truthy</a> value for every array element. Otherwise, <code class=\"language-text\">false</code>.</p>\n<h2>Description</h2>\n<p>The <code class=\"language-text\">every</code> method executes the provided <code class=\"language-text\">callbackFn</code> function once for each element present in the array until it finds the one where <code class=\"language-text\">callbackFn</code> returns a <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Falsy\">falsy</a> value. If such an element is found, the <code class=\"language-text\">every</code> method immediately returns <code class=\"language-text\">false</code>. Otherwise, if <code class=\"language-text\">callbackFn</code> returns a <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Truthy\">truthy</a> value for all elements, <code class=\"language-text\">every</code> returns <code class=\"language-text\">true</code>.</p>\n<p><strong>Note:</strong> Calling this method on an empty array will return <code class=\"language-text\">true</code> for any condition!</p>\n<p><code class=\"language-text\">callbackFn</code> is invoked only for array indexes which have assigned values. It is not invoked for indexes which have been deleted, or which have never been assigned values.</p>\n<p><code class=\"language-text\">callbackFn</code> is invoked with three arguments: the value of the element, the index of the element, and the Array object being traversed.</p>\n<p>If a <code class=\"language-text\">thisArg</code> parameter is provided to <code class=\"language-text\">every</code>, it will be used as callback's <code class=\"language-text\">this</code> value. Otherwise, the value <code class=\"language-text\">undefined</code> will be used as its <code class=\"language-text\">this</code> value. The <code class=\"language-text\">this</code> value ultimately observable by <code class=\"language-text\">callback</code> is determined according to <a href=\"../../operators/this\">the usual rules for determining the <code class=\"language-text\">this</code> seen by a function</a>.</p>\n<p><code class=\"language-text\">every</code> does not mutate the array on which it is called.</p>\n<p>The range of elements processed by <code class=\"language-text\">every</code> is set before the first invocation of <code class=\"language-text\">callbackFn</code>. Therefore, <code class=\"language-text\">callbackFn</code> will not run on elements that are appended to the array after the call to <code class=\"language-text\">every</code> begins. If existing elements of the array are changed, their value as passed to <code class=\"language-text\">callbackFn</code> will be the value at the time <code class=\"language-text\">every</code> visits them. Elements that are deleted are not visited.</p>\n<p><code class=\"language-text\">every</code> acts like the \"for all\" quantifier in mathematics. In particular, for an empty array, it returns <code class=\"language-text\">true</code>. (It is <a href=\"https://en.wikipedia.org/wiki/Vacuous_truth\">vacuously true</a> that all elements of the <a href=\"https://en.wikipedia.org/wiki/Empty_set#Properties\">empty set</a> satisfy any given condition.)</p>\n<h2>Polyfill</h2>\n<p><code class=\"language-text\">every</code> was added to the ECMA-262 standard in the 5<sup>th</sup> edition, and it may not be present in other implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of <code class=\"language-text\">every</code> in implementations which do not natively support it.</p>\n<p>This algorithm is exactly the one specified in ECMA-262, 5<sup>th</sup> edition, assuming <code class=\"language-text\">Object</code> and <code class=\"language-text\">TypeError</code> have their original values, and that <code class=\"language-text\">callbackfn.call</code> evaluates to the original value of <a href=\"../function/call\"><code class=\"language-text\">Function.prototype.call</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if (!Array.prototype.every) {\n  Array.prototype.every = function(callbackfn, thisArg) {\n    'use strict';\n    var T, k;\n\n    if (this == null) {\n      throw new TypeError('this is null or not defined');\n    }\n\n    // 1. Let O be the result of calling ToObject passing the this\n    //    value as the argument.\n    var O = Object(this);\n\n    // 2. Let lenValue be the result of calling the Get internal method\n    //    of O with the argument \"length\".\n    // 3. Let len be ToUint32(lenValue).\n    var len = O.length >>> 0;\n\n    // 4. If IsCallable(callbackfn) is false, throw a TypeError exception.\n    if (typeof callbackfn !== 'function' &amp;&amp; Object.prototype.toString.call(callbackfn) !== '[object Function]') {\n      throw new TypeError();\n    }\n\n    // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.\n    if (arguments.length > 1) {\n      T = thisArg;\n    }\n\n    // 6. Let k be 0.\n    k = 0;\n\n    // 7. Repeat, while k &lt; len\n    while (k &lt; len) {\n\n      var kValue;\n\n      // a. Let Pk be ToString(k).\n      //   This is implicit for LHS operands of the in operator\n      // b. Let kPresent be the result of calling the HasProperty internal\n      //    method of O with argument Pk.\n      //   This step can be combined with c\n      // c. If kPresent is true, then\n      if (k in O) {\n        var testResult;\n        // i. Let kValue be the result of calling the Get internal method\n        //    of O with argument Pk.\n        kValue = O[k];\n\n        // ii. Let testResult be the result of calling the Call internal method\n        // of callbackfn with T as the this value if T is not undefined\n        // else is the result of calling callbackfn\n        // and argument list containing kValue, k, and O.\n        if(T) testResult = callbackfn.call(T, kValue, k, O);\n        else testResult = callbackfn(kValue,k,O)\n\n        // iii. If ToBoolean(testResult) is false, return false.\n        if (!testResult) {\n          return false;\n        }\n      }\n      k++;\n    }\n    return true;\n  };\n}</code></pre></div>\n<h2>Examples</h2>\n<h3>Testing size of all array elements</h3>\n<p>The following example tests whether all elements in the array are bigger than 10.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function isBigEnough(element, index, array) {\n  return element >= 10;\n}\n[12, 5, 8, 130, 44].every(isBigEnough);   // false\n[12, 54, 18, 130, 44].every(isBigEnough); // true</code></pre></div>\n<h3>Using arrow functions</h3>\n<p><a href=\"../../functions/arrow_functions\">Arrow functions</a> provide a shorter syntax for the same test.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[12, 5, 8, 130, 44].every(x => x >= 10);   // false\n[12, 54, 18, 130, 44].every(x => x >= 10); // true</code></pre></div>\n<h3>Affecting Initial Array (modifying, appending, and deleting)</h3>\n<p>The following examples tests the behavior of the <code class=\"language-text\">every</code> method when the array is modified.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// ---------------\n// Modifying items\n// ---------------\nlet arr = [1, 2, 3, 4];\narr.every( (elem, index, arr) => {\n  arr[index+1] -= 1\n  console.log(`[${arr}][${index}] -> ${elem}`)\n  return elem &lt; 2\n})\n\n// Loop runs for 3 iterations, but would\n// have run 2 iterations without any modification\n//\n// 1st iteration: [1,1,3,4][0] -> 1\n// 2nd iteration: [1,1,2,4][1] -> 1\n// 3rd iteration: [1,1,2,3][2] -> 2\n\n// ---------------\n// Appending items\n// ---------------\narr = [1, 2, 3];\narr.every( (elem, index, arr) => {\n  arr.push('new')\n  console.log(`[${arr}][${index}] -> ${elem}`)\n  return elem &lt; 4\n})\n\n// Loop runs for 3 iterations, even after appending new items\n//\n// 1st iteration: [1, 2, 3, new][0] -> 1\n// 2nd iteration: [1, 2, 3, new, new][1] -> 2\n// 3rd iteration: [1, 2, 3, new, new, new][2] -> 3\n\n// ---------------\n// Deleting items\n// ---------------\narr = [1, 2, 3, 4];\narr.every( (elem, index, arr) => {\n  arr.pop()\n  console.log(`[${arr}][${index}] -> ${elem}`)\n  return elem &lt; 4\n})\n\n// Loop runs for 2 iterations only, as the remaining\n// items are `pop()`ed off\n//\n// 1st iteration: [1,2,3][0] -> 1\n// 2nd iteration: [1,2][1] -> 2</code></pre></div>"},{"url":"/docs/js-tips/","relativePath":"docs/js-tips/index.md","relativeDir":"docs/js-tips","base":"index.md","name":"index","frontmatter":{"title":"JS-Quick-Tips","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":"Quick Tips (js)","description":"Javascript Quick Tips Directory","robots":[],"extra":[{"name":"og:image","value":"images/javascript.jpeg","keyName":"property","relativeUrl":true},{"name":"og:title","value":"JavaScript Quick Tips","keyName":"property","relativeUrl":false},{"name":"og:description","value":"JavaScript built-in methods and mdn style examples","keyName":"property","relativeUrl":false}],"type":"stackbit_page_meta"},"template":"docs"},"html":""},{"url":"/docs/js-tips/functions/","relativePath":"docs/js-tips/functions.md","relativeDir":"docs/js-tips","base":"functions.md","name":"functions","frontmatter":{"title":"JS Functions","weight":0,"excerpt":"Generally speaking, a function is a \"subprogram\" that can be called by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the function body. Values can be passed to a function, and the function will return a value.","seo":{"title":"Functions","description":"Generally speaking, a function is a \"subprogram\" that can be called by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the function body. Values can be passed to a function, and the function will return a value.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Functions</h1>\n<p>Generally speaking, a function is a \"subprogram\" that can be <em>called</em> by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the <em>function body</em>. Values can be <em>passed</em> to a function, and the function will <em>return</em> a value.</p>\n<p>In JavaScript, functions are first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called. In brief, they are <code class=\"language-text\">Function</code> objects.</p>\n<p>For more examples and explanations, see also the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions\">JavaScript guide about functions</a>.</p>\n<h2>Description</h2>\n<p>Every function in JavaScript is a <code class=\"language-text\">Function</code> object. See <a href=\"global_objects/function\"><code class=\"language-text\">Function</code></a> for information on properties and methods of <code class=\"language-text\">Function</code> objects.</p>\n<p>To return a value other than the default, a function must have a <code class=\"language-text\">return</code> statement that specifies the value to return. A function without a return statement will return a default value. In the case of a <a href=\"global_objects/object/constructor\">constructor</a> called with the <code class=\"language-text\">new</code> keyword, the default value is the value of its <code class=\"language-text\">this</code> parameter. For all other functions, the default return value is <a href=\"global_objects/undefined\"><code class=\"language-text\">undefined</code></a>.</p>\n<p>The parameters of a function call are the function's <em>arguments</em>. Arguments are passed to functions <em>by value</em>. If the function changes the value of an argument, this change is not reflected globally or in the calling function. However, object references are values, too, and they are special: if the function changes the referred object's properties, that change is visible outside the function, as shown in the following example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/* Declare the function 'myFunc' */\nfunction myFunc(theObject) {\n  theObject.brand = \"Toyota\";\n}\n\n/*\n * Declare variable 'mycar';\n * create and initialize a new Object;\n * assign reference to it to 'mycar'\n */\nvar mycar = {\n  brand: \"Honda\",\n  model: \"Accord\",\n  year: 1998\n};\n\n/* Logs 'Honda' */\nconsole.log(mycar.brand);\n\n/* Pass object reference to the function */\nmyFunc(mycar);\n\n/*\n * Logs 'Toyota' as the value of the 'brand' property\n * of the object, as changed to by the function.\n */\nconsole.log(mycar.brand);</code></pre></div>\n<p>The <a href=\"operators/this\"><code class=\"language-text\">this</code> keyword</a> does not refer to the currently executing function, so you must refer to <code class=\"language-text\">Function</code> objects by name, even within the function body.</p>\n<h2>Defining functions</h2>\n<p>There are several ways to define functions:</p>\n<h3>The function declaration (<code class=\"language-text\">function</code> statement)</h3>\n<p>There is a special syntax for declaring functions (see <a href=\"statements/function\">function statement</a> for details):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function name([param[, param[, ... param]]]) {\n   statements\n}</code></pre></div>\n<p><code class=\"language-text\">name</code>\nThe function name.</p>\n<p><code class=\"language-text\">param</code>\nThe name of an argument to be passed to the function.</p>\n<p><code class=\"language-text\">statements</code>\nThe statements comprising the body of the function.</p>\n<h3>The function expression (<code class=\"language-text\">function</code> expression)</h3>\n<p>A function expression is similar to and has the same syntax as a function declaration (see <a href=\"operators/function\">function expression</a> for details). A function expression may be a part of a larger expression. One can define \"named\" function expressions (where the name of the expression might be used in the call stack for example) or \"anonymous\" function expressions. Function expressions are not <em>hoisted</em> onto the beginning of the scope, therefore they cannot be used before they appear in the code.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function [name]([param[, param[, ... param]]]) {\n   statements\n}</code></pre></div>\n<p><code class=\"language-text\">name</code>\nThe function name. Can be omitted, in which case the function becomes known as an anonymous function.</p>\n<p><code class=\"language-text\">param</code>\nThe name of an argument to be passed to the function.</p>\n<p><code class=\"language-text\">statements</code>\nThe statements comprising the body of the function.</p>\n<p>Here is an example of an <strong>anonymous</strong> function expression (the <code class=\"language-text\">name</code> is not used):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var myFunction = function() {\n    statements\n}</code></pre></div>\n<p>It is also possible to provide a name inside the definition in order to create a <strong>named</strong> function expression:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var myFunction = function namedFunction(){\n    statements\n}</code></pre></div>\n<p>One of the benefits of creating a named function expression is that in case we encountered an error, the stack trace will contain the name of the function, making it easier to find the origin of the error.</p>\n<p>As we can see, both examples do not start with the <code class=\"language-text\">function</code> keyword. Statements involving functions which do not start with <code class=\"language-text\">function</code> are function expressions.</p>\n<p>When functions are used only once, a common pattern is an <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/IIFE\">IIFE (Immediately Invoked Function Expression)</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(function() {\n    statements\n})();</code></pre></div>\n<p>IIFE are function expressions that are invoked as soon as the function is declared.</p>\n<h3>The generator function declaration (<code class=\"language-text\">function*</code> statement)</h3>\n<p>There is a special syntax for generator function declarations (see <a href=\"statements/function*\"><code class=\"language-text\">function* statement</code></a> for details):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function* name([param[, param[, ... param]]]) {\n   statements\n}</code></pre></div>\n<p><code class=\"language-text\">name</code>\nThe function name.</p>\n<p><code class=\"language-text\">param</code>\nThe name of an argument to be passed to the function.</p>\n<p><code class=\"language-text\">statements</code>\nThe statements comprising the body of the function.</p>\n<h3>The generator function expression (<code class=\"language-text\">function*</code> expression)</h3>\n<p>A generator function expression is similar to and has the same syntax as a generator function declaration (see <a href=\"operators/function*\"><code class=\"language-text\">function* expression</code></a> for details):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function* [name]([param[, param[, ... param]]]) {\n   statements\n}</code></pre></div>\n<p><code class=\"language-text\">name</code>\nThe function name. Can be omitted, in which case the function becomes known as an anonymous function.</p>\n<p><code class=\"language-text\">param</code>\nThe name of an argument to be passed to the function.</p>\n<p><code class=\"language-text\">statements</code>\nThe statements comprising the body of the function.</p>\n<h3>The arrow function expression (=>)</h3>\n<p>An arrow function expression has a shorter syntax and lexically binds its <code class=\"language-text\">this</code> value (see <a href=\"functions/arrow_functions\">arrow functions</a> for details):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">([param[, param]]) => {\n   statements\n}\n\nparam => expression</code></pre></div>\n<p><code class=\"language-text\">param</code>\nThe name of an argument. Zero arguments need to be indicated with <code class=\"language-text\">()</code>. For only one argument, the parentheses are not required. (like <code class=\"language-text\">foo => 1</code>)</p>\n<p><code class=\"language-text\">statements</code> or <code class=\"language-text\">expression</code>\nMultiple statements need to be enclosed in brackets. A single expression requires no brackets. The expression is also the implicit return value of the function.</p>\n<h3>The <code class=\"language-text\">Function</code> constructor</h3>\n<p><strong>Note:</strong> Using the <code class=\"language-text\">Function</code> constructor to create functions is not recommended since it needs the function body as a string which may prevent some JS engine optimizations and can also cause other problems.</p>\n<p>As all other objects, <a href=\"global_objects/function\"><code class=\"language-text\">Function</code></a> objects can be created using the <code class=\"language-text\">new</code> operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">new Function (arg1, arg2, ... argN, functionBody)</code></pre></div>\n<p><code class=\"language-text\">arg1, arg2, ... argN</code>\nZero or more names to be used by the function as formal parameters. Each must be a proper JavaScript identifier.</p>\n<p><code class=\"language-text\">functionBody</code>\nA string containing the JavaScript statements comprising the function body.</p>\n<p>Invoking the <code class=\"language-text\">Function</code> constructor as a function (without using the <code class=\"language-text\">new</code> operator) has the same effect as invoking it as a constructor.</p>\n<h3>The <code class=\"language-text\">GeneratorFunction</code> constructor</h3>\n<p><strong>Note:</strong> <code class=\"language-text\">GeneratorFunction</code> is not a global object, but could be obtained from generator function instance (see <a href=\"global_objects/generatorfunction\"><code class=\"language-text\">GeneratorFunction</code></a> for more detail).</p>\n<p><strong>Note:</strong> Using the <code class=\"language-text\">GeneratorFunction</code> constructor to create functions is not recommended since it needs the function body as a string which may prevent some JS engine optimizations and can also cause other problems.</p>\n<p>As all other objects, <a href=\"global_objects/generatorfunction\"><code class=\"language-text\">GeneratorFunction</code></a> objects can be created using the <code class=\"language-text\">new</code> operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">new GeneratorFunction (arg1, arg2, ... argN, functionBody)</code></pre></div>\n<p><code class=\"language-text\">arg1, arg2, ... argN</code>\nZero or more names to be used by the function as formal argument names. Each must be a string that conforms to the rules for a valid JavaScript identifier or a list of such strings separated with a comma; for example \"<code class=\"language-text\">x</code>\", \"<code class=\"language-text\">theValue</code>\", or \"<code class=\"language-text\">a,b</code>\".</p>\n<p><code class=\"language-text\">functionBody</code>\nA string containing the JavaScript statements comprising the function definition.</p>\n<p>Invoking the <code class=\"language-text\">GeneratorFunction</code> constructor as a function (without using the <code class=\"language-text\">new</code> operator) has the same effect as invoking it as a constructor.</p>\n<h2>Function parameters</h2>\n<h3>Default parameters</h3>\n<p>Default function parameters allow formal parameters to be initialized with default values if no value or <code class=\"language-text\">undefined</code> is passed. For more details, see <a href=\"functions/default_parameters\">default parameters</a>.</p>\n<h3>Rest parameters</h3>\n<p>The rest parameter syntax allows representing an indefinite number of arguments as an array. For more details, see <a href=\"functions/rest_parameters\">rest parameters</a>.</p>\n<h2>The <code class=\"language-text\">arguments</code> object</h2>\n<p>You can refer to a function's arguments within the function by using the <code class=\"language-text\">arguments</code> object. See <a href=\"functions/arguments\">arguments</a>.</p>\n<ul>\n<li><code class=\"language-text\">arguments</code>: An array-like object containing the arguments passed to the currently executing function.</li>\n<li><code class=\"language-text\">arguments.callee</code> : The currently executing function.</li>\n<li><code class=\"language-text\">arguments.caller</code> : The function that invoked the currently executing function.</li>\n<li><code class=\"language-text\">arguments.length</code>: The number of arguments passed to the function.</li>\n</ul>\n<h2>Defining method functions</h2>\n<h3>Getter and setter functions</h3>\n<p>You can define getters (accessor methods) and setters (mutator methods) on any standard built-in object or user-defined object that supports the addition of new properties. The syntax for defining getters and setters uses the object literal syntax.</p>\n<p><a href=\"functions/get\">get</a>\nBinds an object property to a function that will be called when that property is looked up.</p>\n<p><a href=\"functions/set\">set</a>\nBinds an object property to a function to be called when there is an attempt to set that property.</p>\n<h3>Method definition syntax</h3>\n<p>Starting with ECMAScript 2015, you are able to define own methods in a shorter syntax, similar to the getters and setters. See <a href=\"functions/method_definitions\">method definitions</a> for more information.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var obj = {\n  foo() {},\n  bar() {}\n};</code></pre></div>\n<h2>Constructor vs. declaration vs. expression</h2>\n<p>Compare the following:</p>\n<p>A function defined with the <code class=\"language-text\">Function</code> <em>constructor</em> assigned to the variable <code class=\"language-text\">multiply</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var multiply = new Function('x', 'y', 'return x * y');</code></pre></div>\n<p>A <em>function declaration</em> of a function named <code class=\"language-text\">multiply</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function multiply(x, y) {\n   return x * y;\n} // there is no semicolon here</code></pre></div>\n<p>A <em>function expression</em> of an anonymous function assigned to the variable <code class=\"language-text\">multiply</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var multiply = function(x, y) {\n   return x * y;\n};</code></pre></div>\n<p>A <em>function expression</em> of a function named <code class=\"language-text\">func_name</code> assigned to the variable <code class=\"language-text\">multiply</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var multiply = function func_name(x, y) {\n   return x * y;\n};</code></pre></div>\n<h3>Differences</h3>\n<p>All do approximately the same thing, with a few subtle differences:</p>\n<p>There is a distinction between the function name and the variable the function is assigned to. The function name cannot be changed, while the variable the function is assigned to can be reassigned. The function name can be used only within the function's body. Attempting to use it outside the function's body results in an error (or <code class=\"language-text\">undefined</code> if the function name was previously declared via a <code class=\"language-text\">var</code> statement). For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var y = function x() {};\nalert(x); // throws an error</code></pre></div>\n<p>The function name also appears when the function is serialized via <a href=\"global_objects/function/tostring\"><code class=\"language-text\">Function</code>'s toString method</a>.</p>\n<p>On the other hand, the variable the function is assigned to is limited only by its scope, which is guaranteed to include the scope in which the function is declared.</p>\n<p>As the 4th example shows, the function name can be different from the variable the function is assigned to. They have no relation to each other. A function declaration also creates a variable with the same name as the function name. Thus, unlike those defined by function expressions, functions defined by function declarations can be accessed by their name in the scope they were defined in:</p>\n<p>A function defined by '<code class=\"language-text\">new Function'</code> does not have a function name. However, in the <a href=\"https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey\">SpiderMonkey</a> JavaScript engine, the serialized form of the function shows as if it has the name \"anonymous\". For example, <code class=\"language-text\">alert(new Function())</code> outputs:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function anonymous() {\n}</code></pre></div>\n<p>Since the function actually does not have a name, <code class=\"language-text\">anonymous</code> is not a variable that can be accessed within the function. For example, the following would result in an error:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var foo = new Function(\"alert(anonymous);\");\nfoo();</code></pre></div>\n<p>Unlike functions defined by function expressions or by the <code class=\"language-text\">Function</code> constructor, a function defined by a function declaration can be used before the function declaration itself. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">foo(); // alerts FOO!\nfunction foo() {\n   alert('FOO!');\n}</code></pre></div>\n<p>A function defined by a function expression or by a function declaration inherits the current scope. That is, the function forms a closure. On the other hand, a function defined by a <code class=\"language-text\">Function</code> constructor does not inherit any scope other than the global scope (which all functions inherit).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/*\n * Declare and initialize a variable 'p' (global)\n * and a function 'myFunc' (to change the scope) inside which\n * declare a varible with same name 'p' (current) and\n * define three functions using three different ways:-\n *     1. function declaration\n *     2. function expression\n *     3. function constructor\n * each of which will log 'p'\n */\nvar p = 5;\nfunction myFunc() {\n    var p = 9;\n\n    function decl() {\n        console.log(p);\n    }\n    var expr = function() {\n        console.log(p);\n    };\n    var cons = new Function('\\tconsole.log(p);');\n\n    decl();\n    expr();\n    cons();\n}\nmyFunc();\n\n/*\n * Logs:-\n * 9  - for 'decl' by function declaration (current scope)\n * 9  - for 'expr' by function expression (current scope)\n * 5  - for 'cons' by Function constructor (global scope)\n */</code></pre></div>\n<p>Functions defined by function expressions and function declarations are parsed only once, while those defined by the <code class=\"language-text\">Function</code> constructor are not. That is, the function body string passed to the <code class=\"language-text\">Function</code> constructor must be parsed each and every time the constructor is called. Although a function expression creates a closure every time, the function body is not reparsed, so function expressions are still faster than \"<code class=\"language-text\">new Function(...)</code>\". Therefore the <code class=\"language-text\">Function</code> constructor should generally be avoided whenever possible.</p>\n<p>It should be noted, however, that function expressions and function declarations nested within the function generated by parsing a <code class=\"language-text\">Function constructor</code> 's string aren't parsed repeatedly. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var foo = (new Function(\"var bar = \\'FOO!\\';\\nreturn(function() {\\n\\talert(bar);\\n});\"))();\nfoo(); // The segment \"function() {\\n\\talert(bar);\\n}\" of the function body string is not re-parsed.</code></pre></div>\n<p>A function declaration is very easily (and often unintentionally) turned into a function expression. A function declaration ceases to be one when it either:</p>\n<ul>\n<li>becomes part of an expression</li>\n<li>is no longer a \"source element\" of a function or the script itself. A \"source element\" is a non-nested statement in the script or a function body:</li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var x = 0;               // source element\nif (x === 0) {           // source element\n   x = 10;               // not a source element\n   function boo() {}     // not a source element\n}\nfunction foo() {         // source element\n   var y = 20;           // source element\n   function bar() {}     // source element\n   while (y === 10) {    // source element\n      function blah() {} // not a source element\n      y++;               // not a source element\n   }\n}</code></pre></div>\n<h3>Examples</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// function declaration\nfunction foo() {}\n\n// function expression\n(function bar() {})\n\n// function expression\nx = function hello() {}\n\nif (x) {\n   // function expression\n   function world() {}\n}\n\n// function declaration\nfunction a() {\n   // function declaration\n   function b() {}\n   if (0) {\n      // function expression\n      function c() {}\n   }\n}</code></pre></div>\n<h2>Block-level functions</h2>\n<p>In <a href=\"strict_mode\">strict mode</a>, starting with ES2015, functions inside blocks are now scoped to that block. Prior to ES2015, block-level functions were forbidden in strict mode.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'use strict';\n\nfunction f() {\n  return 1;\n}\n\n{\n  function f() {\n    return 2;\n  }\n}\n\nf() === 1; // true\n\n// f() === 2 in non-strict mode</code></pre></div>\n<h3>Block-level functions in non-strict code</h3>\n<p>In a word: Don't.</p>\n<p>In non-strict code, function declarations inside blocks behave strangely. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if (shouldDefineZero) {\n   function zero() {     // DANGER: compatibility risk\n      console.log(\"This is zero.\");\n   }\n}</code></pre></div>\n<p>ES2015 says that if <code class=\"language-text\">shouldDefineZero</code> is false, then <code class=\"language-text\">zero</code> should never be defined, since the block never executes. However, it's a new part of the standard. Historically, this was left unspecified, and some browsers would define <code class=\"language-text\">zero</code> whether the block executed or not.</p>\n<p>In <a href=\"strict_mode\">strict mode</a>, all browsers that support ES2015 handle this the same way: <code class=\"language-text\">zero</code> is defined only if <code class=\"language-text\">shouldDefineZero</code> is true, and only in the scope of the <code class=\"language-text\">if</code>-block.</p>\n<p>A safer way to define functions conditionally is to assign a function expression to a variable:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var zero;\nif (shouldDefineZero) {\n   zero = function() {\n      console.log(\"This is zero.\");\n   };\n}</code></pre></div>\n<h2>Examples</h2>\n<h3>Returning a formatted number</h3>\n<p>The following function returns a string containing the formatted representation of a number padded with leading zeros.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// This function returns a string padded with leading zeros\nfunction padZeros(num, totalLen) {\n   var numStr = num.toString();             // Initialize return value as string\n   var numZeros = totalLen - numStr.length; // Calculate no. of zeros\n   for (var i = 1; i &lt;= numZeros; i++) {\n      numStr = \"0\" + numStr;\n   }\n   return numStr;\n}</code></pre></div>\n<p>The following statements call the padZeros function.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var result;\nresult = padZeros(42,4); // returns \"0042\"\nresult = padZeros(42,2); // returns \"42\"\nresult = padZeros(5,4);  // returns \"0005\"</code></pre></div>\n<h3>Determining whether a function exists</h3>\n<p>You can determine whether a function exists by using the <code class=\"language-text\">typeof</code> operator. In the following example, a test is performed to determine if the <code class=\"language-text\">window</code> object has a property called <code class=\"language-text\">noFunc</code> that is a function. If so, it is used; otherwise, some other action is taken.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> if ('function' === typeof window.noFunc) {\n   // use noFunc()\n } else {\n   // do something else\n }</code></pre></div>\n<p>Note that in the <code class=\"language-text\">if</code> test, a reference to <code class=\"language-text\">noFunc</code> is used—there are no brackets \"()\" after the function name so the actual function is not called.</p>"},{"url":"/docs/js-tips/map/","relativePath":"docs/js-tips/map.md","relativeDir":"docs/js-tips","base":"map.md","name":"map","frontmatter":{"title":"Map","weight":0,"excerpt":"The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.","seo":{"title":"Map","description":"The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Map</h1>\n<p>The <code class=\"language-text\">Map</code> object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Primitive\">primitive values</a>) may be used as either a key or a value.</p>\n<h2>Description</h2>\n<p>A <code class=\"language-text\">Map</code> object iterates its elements in insertion order — a <a href=\"../statements/for...of\"><code class=\"language-text\">for...of</code></a> loop returns an array of <code class=\"language-text\">[key, value]</code> for each iteration.</p>\n<h3>Key equality</h3>\n<ul>\n<li>Key equality is based on the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#same-value-zero_equality\"><code class=\"language-text\">sameValueZero</code></a> algorithm.</li>\n<li><a href=\"nan\"><code class=\"language-text\">NaN</code></a> is considered the same as <code class=\"language-text\">NaN</code> (even though <code class=\"language-text\">NaN !== NaN</code>) and all other values are considered equal according to the semantics of the <code class=\"language-text\">===</code> operator.</li>\n<li>In the current ECMAScript specification, <code class=\"language-text\">-0</code> and <code class=\"language-text\">+0</code> are considered equal, although this was not so in earlier drafts. See <em>\"Value equality for -0 and 0\"</em> in the <a href=\"#browser_compatibility\">Browser compatibility</a> table for details.</li>\n</ul>\n<h3>Objects vs. Maps</h3>\n<p><a href=\"object\"><code class=\"language-text\">Object</code></a> is similar to <code class=\"language-text\">Map</code>—both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. For this reason (and because there were no built-in alternatives), <code class=\"language-text\">Object</code> has been used as <code class=\"language-text\">Map</code> historically.</p>\n<p>However, there are important differences that make <code class=\"language-text\">Map</code> preferable in certain cases:</p>\n<table>\n<colgroup>\n<col style=\"width: 33%\" />\n<col style=\"width: 33%\" />\n<col style=\"width: 33%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th>\n</th>\n<th>Map</th>\n<th>Object</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td>Accidental Keys</td>\n<td>A <code>Map</code> does not contain any keys by default. It only contains what is explicitly put into it.</td>\n<td>\n<p>An <code>Object</code> has a prototype, so it contains default keys that could collide with your own keys if you're not careful.</p>\n<div class=\"notecard note\">\n<p>\n<strong>Note:</strong> As of ES5, this can be bypassed by using <a href=\"object/create\">\n<code>Object.create(null)</code>\n</a>, but this is seldom done.</p>\n</div>\n</td>\n</tr>\n<tr class=\"even\">\n<td>Key Types</td>\n<td>A <code>Map</code>'s keys can be any value (including functions, objects, or any primitive).</td>\n<td>The keys of an <code>Object</code> must be either a <a href=\"string\">\n<code>String</code>\n</a> or a <a href=\"symbol\">\n<code>Symbol</code>\n</a>.</td>\n</tr>\n<tr class=\"odd\">\n<td>Key Order</td>\n<td>\n<p>The keys in <code>Map</code> are ordered in a simple, straightforward way: A <code>Map</code> object iterates entries, keys, and values in the order of entry insertion.</p>\n</td>\n<td>\n<p>Although the keys of an ordinary <code>Object</code> are ordered now, this was not always the case, and the order is complex. As a result, it's best not to rely on property order.</p>\n<p>The order was first defined for own properties only in ECMAScript 2015; ECMAScript 2020 defines order for inherited properties as well. See the <a href=\"https://tc39.es/ecma262/#sec-ordinaryownpropertykeys\">OrdinaryOwnPropertyKeys</a> and <a href=\"https://tc39.es/ecma262/#sec-enumerate-object-properties\">EnumerateObjectProperties</a> abstract specification operations. But note that no single mechanism iterates <strong>all</strong> of an object's properties; the various mechanisms each include different subsets of properties. (<a href=\"../statements/for...in\">\n<code>for-in</code>\n</a> includes only enumerable string-keyed properties; <a href=\"object/keys\">\n<code>Object.keys</code>\n</a> includes only own, enumerable, string-keyed properties; <a href=\"object/getownpropertynames\">\n<code>Object.getOwnPropertyNames</code>\n</a> includes own, string-keyed properties even if non-enumerable; <a href=\"object/getownpropertysymbols\">\n<code>Object.getOwnPropertySymbols</code>\n</a> does the same for just <code>Symbol</code>-keyed properties, etc.)</p>\n</td>\n</tr>\n<tr class=\"even\">\n<td>\n<p>Size</p>\n</td>\n<td>The number of items in a <code>Map</code> is easily retrieved from its <a href=\"map/size\">\n<code>size</code>\n</a> property.</td>\n<td>The number of items in an <code>Object</code> must be determined manually.</td>\n</tr>\n<tr class=\"odd\">\n<td>Iteration</td>\n<td>A <code>Map</code> is an <a href=\"../iteration_protocols\">iterable</a>, so it can be directly iterated.</td>\n<td>\n<p>\n<code>Object</code> does not implement an <a href=\"../iteration_protocols#the_iterable_protocol\">iteration protocol</a>, and so objects are not directly iterable using the JavaScript <a href=\"../statements/for...of\">for...of</a> statement (by default).</p>\n<div class=\"notecard note\">\n<p>\n<strong>Note:</strong>\n</p>\n<ul>\n<li>An object can implement the iteration protocol, or you can get an iterable for an object using <a href=\"object/keys\">\n<code>Object.keys</code>\n</a> or <a href=\"object/entries\">\n<code>Object.entries</code>\n</a>.</li>\n<li>The <a href=\"../statements/for...in\">for...in</a> statement allows you to iterate over the <em>enumerable</em> properties of an object.</li>\n</ul>\n</div>\n</td>\n</tr>\n<tr class=\"even\">\n<td>Performance</td>\n<td>\n<p>Performs better in scenarios involving frequent additions and removals of key-value pairs.</p>\n</td>\n<td>\n<p>Not optimized for frequent additions and removals of key-value pairs.</p>\n</td>\n</tr>\n</tbody>\n</table>\n<h3>Setting object properties</h3>\n<p>Setting Object properties works for Map objects as well, and can cause considerable confusion.</p>\n<p>Therefore, this appears to work in a way:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let wrongMap = new Map()\nwrongMap['bla'] = 'blaa'\nwrongMap['bla2'] = 'blaaa2'\n\nconsole.log(wrongMap)  // Map { bla: 'blaa', bla2: 'blaaa2' }</code></pre></div>\n<p>But that way of setting a property does not interact with the Map data structure. It uses the feature of the generic object. The value of 'bla' is not stored in the Map for queries. Other operations on the data fail:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">wrongMap.has('bla')    // false\nwrongMap.delete('bla') // false\nconsole.log(wrongMap)  // Map { bla: 'blaa', bla2: 'blaaa2' }</code></pre></div>\n<p>The correct usage for storing data in the Map is through the <code class=\"language-text\">set(key, value)</code> method.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let contacts = new Map()\ncontacts.set('Jessie', {phone: \"213-555-1234\", address: \"123 N 1st Ave\"})\ncontacts.has('Jessie') // true\ncontacts.get('Hilary') // undefined\ncontacts.set('Hilary', {phone: \"617-555-4321\", address: \"321 S 2nd St\"})\ncontacts.get('Jessie') // {phone: \"213-555-1234\", address: \"123 N 1st Ave\"}\ncontacts.delete('Raymond') // false\ncontacts.delete('Jessie') // true\nconsole.log(contacts.size) // 1</code></pre></div>\n<h2>Constructor</h2>\n<p><a href=\"map/map\"><code class=\"language-text\">Map()</code></a>\nCreates a new <code class=\"language-text\">Map</code> object.</p>\n<h2>Static properties</h2>\n<p><a href=\"map/@@species\"><code class=\"language-text\">get Map[@@species]</code></a>\nThe constructor function that is used to create derived objects.</p>\n<h2>Instance properties</h2>\n<p><a href=\"map/size\"><code class=\"language-text\">Map.prototype.size</code></a>\nReturns the number of key/value pairs in the <code class=\"language-text\">Map</code> object.</p>\n<h2>Instance methods</h2>\n<p><a href=\"map/clear\"><code class=\"language-text\">Map.prototype.clear()</code></a>\nRemoves all key-value pairs from the <code class=\"language-text\">Map</code> object.</p>\n<p><a href=\"map/delete\"><code class=\"language-text\">Map.prototype.delete(key)</code></a>\nReturns <code class=\"language-text\">true</code> if an element in the <code class=\"language-text\">Map</code> object existed and has been removed, or <code class=\"language-text\">false</code> if the element does not exist. <code class=\"language-text\">Map.prototype.has(key)</code> will return <code class=\"language-text\">false</code> afterwards.</p>\n<p><a href=\"map/get\"><code class=\"language-text\">Map.prototype.get(key)</code></a>\nReturns the value associated to the <code class=\"language-text\">key</code>, or <code class=\"language-text\">undefined</code> if there is none.</p>\n<p><a href=\"map/has\"><code class=\"language-text\">Map.prototype.has(key)</code></a>\nReturns a boolean asserting whether a value has been associated to the <code class=\"language-text\">key</code> in the <code class=\"language-text\">Map</code> object or not.</p>\n<p><a href=\"map/set\"><code class=\"language-text\">Map.prototype.set(key, value)</code></a>\nSets the <code class=\"language-text\">value</code> for the <code class=\"language-text\">key</code> in the <code class=\"language-text\">Map</code> object. Returns the <code class=\"language-text\">Map</code> object.</p>\n<h3>Iteration methods</h3>\n<p><a href=\"map/@@iterator\"><code class=\"language-text\">Map.prototype[@@iterator]()</code></a>\nReturns a new Iterator object that contains <code class=\"language-text\">[key, value]</code> for each element in the <code class=\"language-text\">Map</code> object in insertion order.</p>\n<p><a href=\"map/keys\"><code class=\"language-text\">Map.prototype.keys()</code></a>\nReturns a new Iterator object that contains the <strong>keys</strong> for each element in the <code class=\"language-text\">Map</code> object in insertion order.</p>\n<p><a href=\"map/values\"><code class=\"language-text\">Map.prototype.values()</code></a>\nReturns a new Iterator object that contains the <strong>values</strong> for each element in the <code class=\"language-text\">Map</code> object in insertion order.</p>\n<p><a href=\"map/entries\"><code class=\"language-text\">Map.prototype.entries()</code></a>\nReturns a new Iterator object that contains <code class=\"language-text\">[key, value]</code> for each element in the <code class=\"language-text\">Map</code> object in insertion order.</p>\n<p><a href=\"map/foreach\"><code class=\"language-text\">Map.prototype.forEach(callbackFn[, thisArg])</code></a>\nCalls <code class=\"language-text\">callbackFn</code> once for each key-value pair present in the <code class=\"language-text\">Map</code> object, in insertion order. If a <code class=\"language-text\">thisArg</code> parameter is provided to <code class=\"language-text\">forEach</code>, it will be used as the <code class=\"language-text\">this</code> value for each callback.</p>\n<h2>Examples</h2>\n<h3>Using the Map object</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myMap = new Map()\n\nlet keyString = 'a string'\nlet keyObj    = {}\nlet keyFunc   = function() {}\n\n// setting the values\nmyMap.set(keyString, \"value associated with 'a string'\")\nmyMap.set(keyObj, 'value associated with keyObj')\nmyMap.set(keyFunc, 'value associated with keyFunc')\n\nmyMap.size              // 3\n\n// getting the values\nmyMap.get(keyString)    // \"value associated with 'a string'\"\nmyMap.get(keyObj)       // \"value associated with keyObj\"\nmyMap.get(keyFunc)      // \"value associated with keyFunc\"\n\nmyMap.get('a string')    // \"value associated with 'a string'\"\n                         // because keyString === 'a string'\nmyMap.get({})            // undefined, because keyObj !== {}\nmyMap.get(function() {}) // undefined, because keyFunc !== function () {}</code></pre></div>\n<h3>Using NaN as Map keys</h3>\n<p><a href=\"nan\"><code class=\"language-text\">NaN</code></a> can also be used as a key. Even though every <code class=\"language-text\">NaN</code> is not equal to itself (<code class=\"language-text\">NaN !== NaN</code> is true), the following example works because <code class=\"language-text\">NaN</code>s are indistinguishable from each other:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myMap = new Map()\nmyMap.set(NaN, 'not a number')\n\nmyMap.get(NaN)\n// \"not a number\"\n\nlet otherNaN = Number('foo')\nmyMap.get(otherNaN)\n// \"not a number\"</code></pre></div>\n<h3>Iterating Map with for..of</h3>\n<p>Maps can be iterated using a <code class=\"language-text\">for..of</code> loop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myMap = new Map()\nmyMap.set(0, 'zero')\nmyMap.set(1, 'one')\n\nfor (let [key, value] of myMap) {\n  console.log(key + ' = ' + value)\n}\n// 0 = zero\n// 1 = one\n\nfor (let key of myMap.keys()) {\n  console.log(key)\n}\n// 0\n// 1\n\nfor (let value of myMap.values()) {\n  console.log(value)\n}\n// zero\n// one\n\nfor (let [key, value] of myMap.entries()) {\n  console.log(key + ' = ' + value)\n}\n// 0 = zero\n// 1 = one</code></pre></div>\n<h3>Iterating Map with forEach()</h3>\n<p>Maps can be iterated using the <a href=\"map/foreach\"><code class=\"language-text\">forEach()</code></a> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">myMap.forEach(function(value, key) {\n  console.log(key + ' = ' + value)\n})\n// 0 = zero\n// 1 = one</code></pre></div>\n<h3>Relation with Array objects</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let kvArray = [['key1', 'value1'], ['key2', 'value2']]\n\n// Use the regular Map constructor to transform a 2D key-value Array into a map\nlet myMap = new Map(kvArray)\n\nmyMap.get('key1') // returns \"value1\"\n\n// Use Array.from() to transform a map into a 2D key-value Array\nconsole.log(Array.from(myMap)) // Will show you exactly the same Array as kvArray\n\n// A succinct way to do the same, using the spread syntax\nconsole.log([...myMap])\n\n// Or use the keys() or values() iterators, and convert them to an array\nconsole.log(Array.from(myMap.keys())) // [\"key1\", \"key2\"]</code></pre></div>\n<h3>Cloning and merging Maps</h3>\n<p>Just like <code class=\"language-text\">Array</code>s, <code class=\"language-text\">Map</code>s can be cloned:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let original = new Map([\n  [1, 'one']\n])\n\nlet clone = new Map(original)\n\nconsole.log(clone.get(1))       // one\nconsole.log(original === clone) // false (useful for shallow comparison)</code></pre></div>\n<p><strong>Note:</strong> Keep in mind that <em>the data itself</em> is not cloned.</p>\n<p>Maps can be merged, maintaining key uniqueness:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let first = new Map([\n  [1, 'one'],\n  [2, 'two'],\n  [3, 'three'],\n])\n\nlet second = new Map([\n  [1, 'uno'],\n  [2, 'dos']\n])\n\n// Merge two maps. The last repeated key wins.\n// Spread operator essentially converts a Map to an Array\nlet merged = new Map([...first, ...second])\n\nconsole.log(merged.get(1)) // uno\nconsole.log(merged.get(2)) // dos\nconsole.log(merged.get(3)) // three</code></pre></div>\n<p>Maps can be merged with Arrays, too:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let first = new Map([\n  [1, 'one'],\n  [2, 'two'],\n  [3, 'three'],\n])\n\nlet second = new Map([\n  [1, 'uno'],\n  [2, 'dos']\n])\n\n// Merge maps with an array. The last repeated key wins.\nlet merged = new Map([...first, ...second, [1, 'eins']])\n\nconsole.log(merged.get(1)) // eins\nconsole.log(merged.get(2)) // dos\nconsole.log(merged.get(3)) // three</code></pre></div>"},{"url":"/docs/js-tips/object/","relativePath":"docs/js-tips/object.md","relativeDir":"docs/js-tips","base":"object.md","name":"object","frontmatter":{"title":"Object","weight":0,"excerpt":"The Object class represents one of JavaScript's data types. It is used to store various keyed collections and more complex entities. Objects can be created using the Object() constructor or the object initializer / literal syntax.","seo":{"title":"Object","description":"Javascript Quick Tips Directory","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Object</h1>\n<p>The <code class=\"language-text\">Object</code> class represents one of <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures\">JavaScript's data types</a>. It is used to store various keyed collections and more complex entities. Objects can be created using the <a href=\"object/object\"><code class=\"language-text\">Object()</code></a> constructor or the <a href=\"../operators/object_initializer\">object initializer / literal syntax</a>.</p>\n<h2>Description</h2>\n<p>Nearly all objects in JavaScript are instances of <a href=\"object\"><code class=\"language-text\">Object</code></a>; a typical object inherits properties (including methods) from <code class=\"language-text\">Object.prototype</code>, although these properties may be shadowed (a.k.a. overridden). However, an <code class=\"language-text\">Object</code> may be deliberately created for which this is not true (e.g. by <a href=\"object/create\"><code class=\"language-text\">Object.create(null)</code></a>), or it may be altered so that this is no longer true (e.g. with <a href=\"object/setprototypeof\"><code class=\"language-text\">Object.setPrototypeOf</code></a>).</p>\n<p>Changes to the <code class=\"language-text\">Object</code> prototype object are seen by <strong>all</strong> objects through prototype chaining, unless the properties and methods subject to those changes are overridden further along the prototype chain. This provides a very powerful although potentially dangerous mechanism to override or extend object behavior.</p>\n<p>The <code class=\"language-text\">Object</code> constructor creates an object wrapper for the given value.</p>\n<ul>\n<li>If the value is <a href=\"null\"><code class=\"language-text\">null</code></a> or <a href=\"undefined\"><code class=\"language-text\">undefined</code></a>, it will create and return an empty object.</li>\n<li>Otherwise, it will return an object of a Type that corresponds to the given value.</li>\n<li>If the value is an object already, it will return the value.</li>\n</ul>\n<p>When called in a non-constructor context, <code class=\"language-text\">Object</code> behaves identically to <code class=\"language-text\">new Object()</code>.</p>\n<p>See also the <a href=\"../operators/object_initializer\">object initializer / literal syntax</a>.</p>\n<h3>Deleting a property from an object</h3>\n<p>There isn't any method in an Object itself to delete its own properties (such as <a href=\"map/delete\"><code class=\"language-text\">Map.prototype.delete()</code></a>). To do so, one must use the <a href=\"../operators/delete\">delete operator</a>.</p>\n<h2>Constructor</h2>\n<p><a href=\"object/object\"><code class=\"language-text\">Object()</code></a>\nCreates a new <code class=\"language-text\">Object</code> object. It is a wrapper for the given value.</p>\n<h2>Static methods</h2>\n<p><a href=\"object/assign\"><code class=\"language-text\">Object.assign()</code></a>\nCopies the values of all enumerable own properties from one or more source objects to a target object.</p>\n<p><a href=\"object/create\"><code class=\"language-text\">Object.create()</code></a>\nCreates a new object with the specified prototype object and properties.</p>\n<p><a href=\"object/defineproperty\"><code class=\"language-text\">Object.defineProperty()</code></a>\nAdds the named property described by a given descriptor to an object.</p>\n<p><a href=\"object/defineproperties\"><code class=\"language-text\">Object.defineProperties()</code></a>\nAdds the named properties described by the given descriptors to an object.</p>\n<p><a href=\"object/entries\"><code class=\"language-text\">Object.entries()</code></a>\nReturns an array containing all of the <code class=\"language-text\">[key, value]</code> pairs of a given object's <strong>own</strong> enumerable string properties.</p>\n<p><a href=\"object/freeze\"><code class=\"language-text\">Object.freeze()</code></a>\nFreezes an object. Other code cannot delete or change its properties.</p>\n<p><a href=\"object/fromentries\"><code class=\"language-text\">Object.fromEntries()</code></a>\nReturns a new object from an iterable of <code class=\"language-text\">[key, value]</code> pairs. (This is the reverse of <a href=\"object/entries\"><code class=\"language-text\">Object.entries</code></a>).</p>\n<p><a href=\"object/getownpropertydescriptor\"><code class=\"language-text\">Object.getOwnPropertyDescriptor()</code></a>\nReturns a property descriptor for a named property on an object.</p>\n<p><a href=\"object/getownpropertydescriptors\"><code class=\"language-text\">Object.getOwnPropertyDescriptors()</code></a>\nReturns an object containing all own property descriptors for an object.</p>\n<p><a href=\"object/getownpropertynames\"><code class=\"language-text\">Object.getOwnPropertyNames()</code></a>\nReturns an array containing the names of all of the given object's <strong>own</strong> enumerable and non-enumerable properties.</p>\n<p><a href=\"object/getownpropertysymbols\"><code class=\"language-text\">Object.getOwnPropertySymbols()</code></a>\nReturns an array of all symbol properties found directly upon a given object.</p>\n<p><a href=\"object/getprototypeof\"><code class=\"language-text\">Object.getPrototypeOf()</code></a>\nReturns the prototype (internal <code class=\"language-text\">[[Prototype]]</code> property) of the specified object.</p>\n<p><a href=\"object/is\"><code class=\"language-text\">Object.is()</code></a>\nCompares if two values are the same value. Equates all <code class=\"language-text\">NaN</code> values (which differs from both Abstract Equality Comparison and Strict Equality Comparison).</p>\n<p><a href=\"object/isextensible\"><code class=\"language-text\">Object.isExtensible()</code></a>\nDetermines if extending of an object is allowed.</p>\n<p><a href=\"object/isfrozen\"><code class=\"language-text\">Object.isFrozen()</code></a>\nDetermines if an object was frozen.</p>\n<p><a href=\"object/issealed\"><code class=\"language-text\">Object.isSealed()</code></a>\nDetermines if an object is sealed.</p>\n<p><a href=\"object/keys\"><code class=\"language-text\">Object.keys()</code></a>\nReturns an array containing the names of all of the given object's <strong>own</strong> enumerable string properties.</p>\n<p><a href=\"object/preventextensions\"><code class=\"language-text\">Object.preventExtensions()</code></a>\nPrevents any extensions of an object.</p>\n<p><a href=\"object/seal\"><code class=\"language-text\">Object.seal()</code></a>\nPrevents other code from deleting properties of an object.</p>\n<p><a href=\"object/setprototypeof\"><code class=\"language-text\">Object.setPrototypeOf()</code></a>\nSets the object's prototype (its internal <code class=\"language-text\">[[Prototype]]</code> property).</p>\n<p><a href=\"object/values\"><code class=\"language-text\">Object.values()</code></a>\nReturns an array containing the values that correspond to all of a given object's <strong>own</strong> enumerable string properties.</p>\n<h2>Instance properties</h2>\n<p><a href=\"object/constructor\"><code class=\"language-text\">Object.prototype.constructor</code></a>\nSpecifies the function that creates an object's prototype.</p>\n<p><a href=\"object/proto\"><code class=\"language-text\">Object/proto</code></a>\nPoints to the object which was used as prototype when the object was instantiated.</p>\n<h2>Instance methods</h2>\n<p><a href=\"object/__definegetter__\"><code class=\"language-text\">Object.prototype.__defineGetter__()</code></a>\nAssociates a function with a property that, when accessed, executes that function and returns its return value.</p>\n<p><a href=\"object/__definesetter__\"><code class=\"language-text\">Object.prototype.__defineSetter__()</code></a>\nAssociates a function with a property that, when set, executes that function which modifies the property.</p>\n<p><a href=\"object/__lookupgetter__\"><code class=\"language-text\">Object.prototype.__lookupGetter__()</code></a>\nReturns the function associated with the specified property by the <a href=\"object/__definegetter__\"><code class=\"language-text\">__defineGetter__()</code></a> method.</p>\n<p><a href=\"object/__lookupsetter__\"><code class=\"language-text\">Object.prototype.__lookupSetter__()</code></a>\nReturns the function associated with the specified property by the <a href=\"object/__definesetter__\"><code class=\"language-text\">__defineSetter__()</code></a> method.</p>\n<p><a href=\"object/hasownproperty\"><code class=\"language-text\">Object.prototype.hasOwnProperty()</code></a>\nReturns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain.</p>\n<p><a href=\"object/isprototypeof\"><code class=\"language-text\">Object.prototype.isPrototypeOf()</code></a>\nReturns a boolean indicating whether the object this method is called upon is in the prototype chain of the specified object.</p>\n<p><a href=\"object/propertyisenumerable\"><code class=\"language-text\">Object.prototype.propertyIsEnumerable()</code></a>\nReturns a boolean indicating if the internal <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#properties\">ECMAScript [[Enumerable]] attribute</a> is set.</p>\n<p><a href=\"object/tolocalestring\"><code class=\"language-text\">Object.prototype.toLocaleString()</code></a>\nCalls <a href=\"object/tostring\"><code class=\"language-text\">toString()</code></a>.</p>\n<p><a href=\"object/tostring\"><code class=\"language-text\">Object.prototype.toString()</code></a>\nReturns a string representation of the object.</p>\n<p><a href=\"object/valueof\"><code class=\"language-text\">Object.prototype.valueOf()</code></a>\nReturns the primitive value of the specified object.</p>\n<h2>Examples</h2>\n<h3>Using <code class=\"language-text\">Object</code> given <code class=\"language-text\">undefined</code> and <code class=\"language-text\">null</code> types</h3>\n<p>The following examples store an empty <code class=\"language-text\">Object</code> object in <code class=\"language-text\">o</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let o = new Object()\n\nlet o = new Object(undefined)\n\nlet o = new Object(null)</code></pre></div>\n<h3>Using <code class=\"language-text\">Object</code> to create <code class=\"language-text\">Boolean</code> objects</h3>\n<p>The following examples store <a href=\"boolean\"><code class=\"language-text\">Boolean</code></a> objects in <code class=\"language-text\">o</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// equivalent to o = new Boolean(true)\nlet o = new Object(true)\n\n// equivalent to o = new Boolean(false)\nlet o = new Object(Boolean())</code></pre></div>\n<h3>Object prototypes</h3>\n<p>When altering the behavior of existing <code class=\"language-text\">Object.prototype</code> methods, consider injecting code by wrapping your extension before or after the existing logic. For example, this (untested) code will pre-conditionally execute custom logic before the built-in logic or someone else's extension is executed.</p>\n<p>When a function is called, the arguments to the call are held in the array-like \"variable\" <a href=\"../functions/arguments\">arguments</a>. For example, in the call <code class=\"language-text\">myFn(a, b, c)</code>, the arguments within <code class=\"language-text\">myFn</code>'s body will contain 3 array-like elements corresponding to <code class=\"language-text\">(a, b, c)</code>.</p>\n<p>When modifying prototypes with hooks, pass <code class=\"language-text\">this</code> and the arguments (the call state) to the current behavior by calling <code class=\"language-text\">apply()</code> on the function. This pattern can be used for any prototype, such as <code class=\"language-text\">Node.prototype</code>, <code class=\"language-text\">Function.prototype</code>, etc.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var current = Object.prototype.valueOf;\n\n// Since my property \"-prop-value\" is cross-cutting and isn't always\n// on the same prototype chain, I want to modify Object.prototype:\nObject.prototype.valueOf = function() {\n  if (this.hasOwnProperty('-prop-value')) {\n    return this['-prop-value'];\n  } else {\n    // It doesn't look like one of my objects, so let's fall back on\n    // the default behavior by reproducing the current behavior as best we can.\n    // The apply behaves like \"super\" in some other languages.\n    // Even though valueOf() doesn't take arguments, some other hook may.\n    return current.apply(this, arguments);\n  }\n}</code></pre></div>\n<p>Since JavaScript doesn't exactly have sub-class objects, prototype is a useful workaround to make a \"base class\" object of certain functions that act as objects. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n    <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">Person</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>canTalk <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">greet</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>canTalk<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, I am '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">Employee</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name<span class=\"token punctuation\">,</span> title</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">Person</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token class-name\">Employee</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token class-name\">Employee</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">=</span> Employee<span class=\"token punctuation\">;</span> <span class=\"token comment\">//If you don't set Object.prototype.constructor to Employee,</span>\n                                               <span class=\"token comment\">//it will take prototype.constructor of Person (parent).</span>\n                                               <span class=\"token comment\">//To avoid that, we set the prototype.constructor to Employee (child).</span>\n\n    <span class=\"token class-name\">Employee</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">greet</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>canTalk<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, I am '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">+</span> <span class=\"token string\">', the '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">Customer</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">Person</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token class-name\">Customer</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token class-name\">Customer</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">=</span> Customer<span class=\"token punctuation\">;</span> <span class=\"token comment\">//If you don't set Object.prototype.constructor to Customer,</span>\n                                               <span class=\"token comment\">//it will take prototype.constructor of Person (parent).</span>\n                                               <span class=\"token comment\">//To avoid that, we set the prototype.constructor to Customer (child).</span>\n\n    <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">Mime</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">Person</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>canTalk <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token class-name\">Mime</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token class-name\">Mime</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">=</span> Mime<span class=\"token punctuation\">;</span> <span class=\"token comment\">//If you don't set Object.prototype.constructor to Mime,</span>\n                                       <span class=\"token comment\">//it will take prototype.constructor of Person (parent).</span>\n                                       <span class=\"token comment\">//To avoid that, we set the prototype.constructor to Mime (child).</span>\n\n    <span class=\"token keyword\">var</span> bob <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Employee</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Bob'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Builder'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> joe <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Customer</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Joe'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> rg <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Employee</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Red Green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Handyman'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> mike <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Customer</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Mike'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> mime <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Mime</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Mime'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    bob<span class=\"token punctuation\">.</span><span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Hi, I am Bob, the Builder</span>\n\n    joe<span class=\"token punctuation\">.</span><span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Hi, I am Joe</span>\n\n    rg<span class=\"token punctuation\">.</span><span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Hi, I am Red Green, the Handyman</span>\n\n    mike<span class=\"token punctuation\">.</span><span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Hi, I am Mike</span>\n\n    mime<span class=\"token punctuation\">.</span><span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/docs/js-tips/reduce/","relativePath":"docs/js-tips/reduce.md","relativeDir":"docs/js-tips","base":"reduce.md","name":"reduce","frontmatter":{"title":"Array.reduce()","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":"Array.prototype.reduce()","description":"Javascript Quick Tips Directory","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Array.prototype.reduce()</h1>\n<p>The <code class=\"language-text\">reduce()</code> method executes a <strong>reducer</strong> function (that you provide) on each element of the array, resulting in a single output value.</p>\n<p>The <strong>reducer</strong> function takes four arguments:</p>\n<ol>\n<li>Accumulator</li>\n<li>Current Value</li>\n<li>Current Index</li>\n<li>Source Array</li>\n</ol>\n<p>Your <strong>reducer</strong> function's returned value is assigned to the accumulator, whose value is remembered across each iteration throughout the array, and ultimately becomes the final, single resulting value.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Arrow function\nreduce((accumulator, currentValue) => { ... } )\nreduce((accumulator, currentValue, index) => { ... } )\nreduce((accumulator, currentValue, index, array) => { ... } )\nreduce((accumulator, currentValue, index, array) => { ... }, initialValue)\n\n// Reducer function\nreduce(reducerFn)\nreduce(reducerFn, initialValue)\n\n// Inline reducer function\nreduce(function reducerFn(accumulator, currentValue) { ... })\nreduce(function reducerFn(accumulator, currentValue, index) { ... })\nreduce(function reducerFn(accumulator, currentValue, index, array){ ... })\nreduce(function reducerFn(accumulator, currentValue, index, array) { ... }, initialValue)</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">callback</code>\nA function to execute on each element in the array (except for the first, if no <code class=\"language-text\">initialValue</code> is supplied).</p>\n<p>It takes four arguments:</p>\n<p><code class=\"language-text\">accumulator</code>\nThe accumulator accumulates callback's return values. It is the accumulated value previously returned in the last invocation of the callback—or <code class=\"language-text\">initialValue</code>, if it was supplied (see below).</p>\n<p><code class=\"language-text\">currentValue</code>\nThe current element being processed in the array.</p>\n<p><code class=\"language-text\">index</code> <span class=\"badge inline optional\">Optional</span>\nThe index of the current element being processed in the array. Starts from index <code class=\"language-text\">0</code> if an <code class=\"language-text\">initialValue</code> is provided. Otherwise, it starts from index <code class=\"language-text\">1</code>.</p>\n<p><code class=\"language-text\">array</code> <span class=\"badge inline optional\">Optional</span>\nThe array <code class=\"language-text\">reduce()</code> was called upon.</p>\n<p><code class=\"language-text\">initialValue</code> <span class=\"badge inline optional\">Optional</span>\nA value to use as the first argument to the first call of the <code class=\"language-text\">callback</code>. If no <code class=\"language-text\">initialValue</code> is supplied, the first element in the array will be used as the initial <code class=\"language-text\">accumulator</code> value and skipped as <code class=\"language-text\">currentValue</code>. Calling <code class=\"language-text\">reduce()</code> on an empty array without an <code class=\"language-text\">initialValue</code> will throw a <a href=\"../typeerror\"><code class=\"language-text\">TypeError</code></a>.</p>\n<h3>Return value</h3>\n<p>The single value that results from the reduction.</p>\n<h2>Description</h2>\n<p>The <code class=\"language-text\">reduce()</code> method executes the <code class=\"language-text\">callback</code> once for each assigned value present in the array, taking four arguments:</p>\n<ol>\n<li><code class=\"language-text\">accumulator</code></li>\n<li><code class=\"language-text\">currentValue</code></li>\n<li><code class=\"language-text\">currentIndex</code></li>\n<li><code class=\"language-text\">array</code></li>\n</ol>\n<p>The first time the callback is called, <code class=\"language-text\">accumulator</code> and <code class=\"language-text\">currentValue</code> can be one of two values. If <code class=\"language-text\">initialValue</code> is provided in the call to <code class=\"language-text\">reduce()</code>, then <code class=\"language-text\">accumulator</code> will be equal to <code class=\"language-text\">initialValue</code>, and <code class=\"language-text\">currentValue</code> will be equal to the first value in the array. If no <code class=\"language-text\">initialValue</code> is provided, then <code class=\"language-text\">accumulator</code> will be equal to the first value in the array, and <code class=\"language-text\">currentValue</code> will be equal to the second.</p>\n<p><strong>Note:</strong> If <code class=\"language-text\">initialValue</code> is not provided, <code class=\"language-text\">reduce()</code> will execute the callback function starting at index <code class=\"language-text\">1</code>, skipping the first index. If <code class=\"language-text\">initialValue</code> is provided, it will start at index <code class=\"language-text\">0</code>.</p>\n<p>If the array is empty and no <code class=\"language-text\">initialValue</code> is provided, <a href=\"../typeerror\"><code class=\"language-text\">TypeError</code></a> will be thrown.</p>\n<p>If the array only has one element (regardless of position) and no <code class=\"language-text\">initialValue</code> is provided, or if <code class=\"language-text\">initialValue</code> is provided but the array is empty, the solo value will be returned <em>without</em> calling <em><code class=\"language-text\">callback</code>.</em></p>\n<p>It is almost always safer to provide an <code class=\"language-text\">initialValue</code>, because there can be up to <em>four</em> possible output types without <code class=\"language-text\">initialValue</code>, as shown in the following example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let maxCallback = ( acc, cur ) => Math.max( acc.x, cur.x );\nlet maxCallback2 = ( max, cur ) => Math.max( max, cur );\n\n// reduce without initialValue\n[ { x: 2 }, { x: 22 }, { x: 42 } ].reduce( maxCallback ); // NaN\n[ { x: 2 }, { x: 22 }            ].reduce( maxCallback ); // 22\n[ { x: 2 }                       ].reduce( maxCallback ); // { x: 2 }\n[                                ].reduce( maxCallback ); // TypeError\n\n// map &amp; reduce with initialValue; better solution, also works for empty or larger arrays\n[ { x: 22 }, { x: 42 } ].map( el => el.x )\n                        .reduce( maxCallback2, -Infinity );</code></pre></div>\n<h3>How reduce() works</h3>\n<p>Suppose the following use of <code class=\"language-text\">reduce()</code> occurred:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[0, 1, 2, 3, 4].reduce(function(accumulator, currentValue, currentIndex, array) {\n  return accumulator + currentValue\n})</code></pre></div>\n<p>The callback would be invoked four times, with the arguments and return values in each call being as follows:</p>\n<table>\n<thead>\n<tr class=\"header\">\n<th>\n<code>callback</code> iteration</th>\n<th>\n<code>accumulator</code>\n</th>\n<th>\n<code>currentValue</code>\n</th>\n<th>\n<code>currentIndex</code>\n</th>\n<th>\n<code>array</code>\n</th>\n<th>return value</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td>first call</td>\n<td>\n<code>0</code>\n</td>\n<td>\n<code>1</code>\n</td>\n<td>\n<code>1</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>1</code>\n</td>\n</tr>\n<tr class=\"even\">\n<td>second call</td>\n<td>\n<code>1</code>\n</td>\n<td>\n<code>2</code>\n</td>\n<td>\n<code>2</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>3</code>\n</td>\n</tr>\n<tr class=\"odd\">\n<td>third call</td>\n<td>\n<code>3</code>\n</td>\n<td>\n<code>3</code>\n</td>\n<td>\n<code>3</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>6</code>\n</td>\n</tr>\n<tr class=\"even\">\n<td>fourth call</td>\n<td>\n<code>6</code>\n</td>\n<td>\n<code>4</code>\n</td>\n<td>\n<code>4</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>10</code>\n</td>\n</tr>\n</tbody>\n</table>\n<p>The value returned by <code class=\"language-text\">reduce()</code> would be that of the last callback invocation (<code class=\"language-text\">10</code>).</p>\n<p>You can also provide an <a href=\"../../functions/arrow_functions\">Arrow Function</a> instead of a full function. The code below will produce the same output as the code in the block above:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[0, 1, 2, 3, 4].reduce( (accumulator, currentValue, currentIndex, array) => accumulator + currentValue )</code></pre></div>\n<p>If you were to provide an <code class=\"language-text\">initialValue</code> as the second argument to <code class=\"language-text\">reduce()</code>, the result would look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[0, 1, 2, 3, 4].reduce((accumulator, currentValue, currentIndex, array) => {\n    return accumulator + currentValue\n}, 10)</code></pre></div>\n<table>\n<thead>\n<tr class=\"header\">\n<th>\n<code>callback</code> iteration</th>\n<th>\n<code>accumulator</code>\n</th>\n<th>\n<code>currentValue</code>\n</th>\n<th>\n<code>currentIndex</code>\n</th>\n<th>\n<code>array</code>\n</th>\n<th>return value</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td>first call</td>\n<td>\n<code>10</code>\n</td>\n<td>\n<code>0</code>\n</td>\n<td>\n<code>0</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>10</code>\n</td>\n</tr>\n<tr class=\"even\">\n<td>second call</td>\n<td>\n<code>10</code>\n</td>\n<td>\n<code>1</code>\n</td>\n<td>\n<code>1</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>11</code>\n</td>\n</tr>\n<tr class=\"odd\">\n<td>third call</td>\n<td>\n<code>11</code>\n</td>\n<td>\n<code>2</code>\n</td>\n<td>\n<code>2</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>13</code>\n</td>\n</tr>\n<tr class=\"even\">\n<td>fourth call</td>\n<td>\n<code>13</code>\n</td>\n<td>\n<code>3</code>\n</td>\n<td>\n<code>3</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>16</code>\n</td>\n</tr>\n<tr class=\"odd\">\n<td>fifth call</td>\n<td>\n<code>16</code>\n</td>\n<td>\n<code>4</code>\n</td>\n<td>\n<code>4</code>\n</td>\n<td>\n<code>[0, 1, 2, 3, 4]</code>\n</td>\n<td>\n<code>20</code>\n</td>\n</tr>\n</tbody>\n</table>\n<p>The value returned by <code class=\"language-text\">reduce()</code> in this case would be <code class=\"language-text\">20</code>.</p>\n<h2>Polyfill</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Production steps of ECMA-262, Edition 5, 15.4.4.21\n// Reference: https://es5.github.io/#x15.4.4.21\n// https://tc39.github.io/ecma262/#sec-array.prototype.reduce\nif (!Array.prototype.reduce) {\n  Object.defineProperty(Array.prototype, 'reduce', {\n    value: function(callback /*, initialValue*/) {\n      if (this === null) {\n        throw new TypeError( 'Array.prototype.reduce ' +\n          'called on null or undefined' );\n      }\n      if (typeof callback !== 'function') {\n        throw new TypeError( callback +\n          ' is not a function');\n      }\n\n      // 1. Let O be ? ToObject(this value).\n      var o = Object(this);\n\n      // 2. Let len be ? ToLength(? Get(O, \"length\")).\n      var len = o.length >>> 0;\n\n      // Steps 3, 4, 5, 6, 7\n      var k = 0;\n      var value;\n\n      if (arguments.length >= 2) {\n        value = arguments[1];\n      } else {\n        while (k &lt; len &amp;&amp; !(k in o)) {\n          k++;\n        }\n\n        // 3. If len is 0 and initialValue is not present,\n        //    throw a TypeError exception.\n        if (k >= len) {\n          throw new TypeError( 'Reduce of empty array ' +\n            'with no initial value' );\n        }\n        value = o[k++];\n      }\n\n      // 8. Repeat, while k &lt; len\n      while (k &lt; len) {\n        // a. Let Pk be ! ToString(k).\n        // b. Let kPresent be ? HasProperty(O, Pk).\n        // c. If kPresent is true, then\n        //    i.  Let kValue be ? Get(O, Pk).\n        //    ii. Let accumulator be ? Call(\n        //          callbackfn, undefined,\n        //          « accumulator, kValue, k, O »).\n        if (k in o) {\n          value = callback(value, o[k], k, o);\n        }\n\n        // d. Increase k by 1.\n        k++;\n      }\n\n      // 9. Return accumulator.\n      return value;\n    }\n  });\n}</code></pre></div>\n<p><strong>Note:</strong> If you need to support truly obsolete JavaScript engines that do not support <a href=\"../object/defineproperty\"><code class=\"language-text\">Object.defineProperty()</code></a>, it is best not to polyfill <code class=\"language-text\">Array.prototype</code> methods at all, as you cannot make them <strong>non-enumerable</strong>.</p>\n<h2>Examples</h2>\n<h3>Sum all the values of an array</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let sum = [0, 1, 2, 3].reduce(function (accumulator, currentValue) {\n  return accumulator + currentValue\n}, 0)\n// sum is 6</code></pre></div>\n<p>Alternatively written with an arrow function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let total = [ 0, 1, 2, 3 ].reduce(\n  ( accumulator, currentValue ) => accumulator + currentValue,\n  0\n)</code></pre></div>\n<h3>Sum of values in an object array</h3>\n<p>To sum up the values contained in an array of objects, you <strong>must</strong> supply an <code class=\"language-text\">initialValue</code>, so that each item passes through your function.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let initialValue = 0\nlet sum = [{x: 1}, {x: 2}, {x: 3}].reduce(function (accumulator, currentValue) {\n    return accumulator + currentValue.x\n}, initialValue)\n\nconsole.log(sum) // logs 6</code></pre></div>\n<p>Alternatively written with an arrow function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let initialValue = 0\nlet sum = [{x: 1}, {x: 2}, {x: 3}].reduce(\n    (accumulator, currentValue) => accumulator + currentValue.x\n    , initialValue\n)\n\nconsole.log(sum) // logs 6</code></pre></div>\n<h3>Flatten an array of arrays</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let flattened = [[0, 1], [2, 3], [4, 5]].reduce(\n  function(accumulator, currentValue) {\n    return accumulator.concat(currentValue)\n  },\n  []\n)\n// flattened is [0, 1, 2, 3, 4, 5]</code></pre></div>\n<p>Alternatively written with an arrow function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let flattened = [[0, 1], [2, 3], [4, 5]].reduce(\n  ( accumulator, currentValue ) => accumulator.concat(currentValue),\n  []\n)</code></pre></div>\n<h3>Counting instances of values in an object</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice']\n\nlet countedNames = names.reduce(function (allNames, name) {\n  if (name in allNames) {\n    allNames[name]++\n  }\n  else {\n    allNames[name] = 1\n  }\n  return allNames\n}, {})\n// countedNames is:\n// { 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 }</code></pre></div>\n<h3>Grouping objects by a property</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let people = [\n  { name: 'Alice', age: 21 },\n  { name: 'Max', age: 20 },\n  { name: 'Jane', age: 20 }\n];\n\nfunction groupBy(objectArray, property) {\n  return objectArray.reduce(function (acc, obj) {\n    let key = obj[property]\n    if (!acc[key]) {\n      acc[key] = []\n    }\n    acc[key].push(obj)\n    return acc\n  }, {})\n}\n\nlet groupedPeople = groupBy(people, 'age')\n// groupedPeople is:\n// {\n//   20: [\n//     { name: 'Max', age: 20 },\n//     { name: 'Jane', age: 20 }\n//   ],\n//   21: [{ name: 'Alice', age: 21 }]\n// }</code></pre></div>\n<h3>Bonding arrays contained in an array of objects using the spread operator and initialValue</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// friends - an array of objects\n// where object field \"books\" is a list of favorite books\nlet friends = [{\n  name: 'Anna',\n  books: ['Bible', 'Harry Potter'],\n  age: 21\n}, {\n  name: 'Bob',\n  books: ['War and peace', 'Romeo and Juliet'],\n  age: 26\n}, {\n  name: 'Alice',\n  books: ['The Lord of the Rings', 'The Shining'],\n  age: 18\n}]\n\n// allbooks - list which will contain all friends' books +\n// additional list contained in initialValue\nlet allbooks = friends.reduce(function(accumulator, currentValue) {\n  return [...accumulator, ...currentValue.books]\n}, ['Alphabet'])\n\n// allbooks = [\n//   'Alphabet', 'Bible', 'Harry Potter', 'War and peace',\n//   'Romeo and Juliet', 'The Lord of the Rings',\n//   'The Shining'\n// ]</code></pre></div>\n<h3>Remove duplicate items in an array</h3>\n<p><strong>Note:</strong> If you are using an environment compatible with <a href=\"../set\"><code class=\"language-text\">Set</code></a> and <a href=\"from\"><code class=\"language-text\">Array.from()</code></a>, you could use <code class=\"language-text\">let orderedArray = Array.from(new Set(myArray))</code> to get an array where duplicate items have been removed.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd']\nlet myOrderedArray = myArray.reduce(function (accumulator, currentValue) {\n  if (accumulator.indexOf(currentValue) === -1) {\n    accumulator.push(currentValue)\n  }\n  return accumulator\n}, [])\n\nconsole.log(myOrderedArray)</code></pre></div>\n<h3>Replace .filter().map() with .reduce()</h3>\n<p>Using <a href=\"filter\"><code class=\"language-text\">Array.filter()</code></a> then <a href=\"map\"><code class=\"language-text\">Array.map()</code></a> traverses the array twice, but you can achieve the same effect while traversing only once with <a href=\"reduce\"><code class=\"language-text\">Array.reduce()</code></a>, thereby being more efficient. (If you like for loops, you can filter and map while traversing once with <a href=\"foreach\"><code class=\"language-text\">Array.forEach()</code></a>).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const numbers = [-5, 6, 2, 0,];\n\nconst doubledPositiveNumbers = numbers.reduce((accumulator, currentValue) => {\n  if (currentValue > 0) {\n    const doubled = currentValue * 2;\n    accumulator.push(doubled);\n  }\n  return accumulator;\n}, []);\n\nconsole.log(doubledPositiveNumbers); // [12, 4]</code></pre></div>\n<h3>Running Promises in Sequence</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/**\n * Runs promises from array of functions that can return promises\n * in chained manner\n *\n * @param {array} arr - promise arr\n * @return {Object} promise object\n */\nfunction runPromiseInSequence(arr, input) {\n  return arr.reduce(\n    (promiseChain, currentFunction) => promiseChain.then(currentFunction),\n    Promise.resolve(input)\n  )\n}\n\n// promise function 1\nfunction p1(a) {\n  return new Promise((resolve, reject) => {\n    resolve(a * 5)\n  })\n}\n\n// promise function 2\nfunction p2(a) {\n  return new Promise((resolve, reject) => {\n    resolve(a * 2)\n  })\n}\n\n// function 3  - will be wrapped in a resolved promise by .then()\nfunction f3(a) {\n return a * 3\n}\n\n// promise function 4\nfunction p4(a) {\n  return new Promise((resolve, reject) => {\n    resolve(a * 4)\n  })\n}\n\nconst promiseArr = [p1, p2, f3, p4]\nrunPromiseInSequence(promiseArr, 10)\n  .then(console.log)   // 1200</code></pre></div>\n<h3>Function composition enabling piping</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Building-blocks to use for composition\nconst double = x => x + x\nconst triple = x => 3 * x\nconst quadruple = x => 4 * x\n\n// Function composition enabling pipe functionality\nconst pipe = (...functions) => input => functions.reduce(\n    (acc, fn) => fn(acc),\n    input\n)\n\n// Composed functions for multiplication of specific values\nconst multiply6 = pipe(double, triple)\nconst multiply9 = pipe(triple, triple)\nconst multiply16 = pipe(quadruple, quadruple)\nconst multiply24 = pipe(double, triple, quadruple)\n\n// Usage\nmultiply6(6)   // 36\nmultiply9(9)   // 81\nmultiply16(16) // 256\nmultiply24(10) // 240</code></pre></div>\n<h3>Write map using reduce</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if (!Array.prototype.mapUsingReduce) {\n  Array.prototype.mapUsingReduce = function(callback, initialValue) {\n    return this.reduce(function(mappedArray, currentValue, index, array) {\n      mappedArray[index] = callback.call(initialValue, currentValue, index, array)\n      return mappedArray\n    }, [])\n  }\n}\n\n[1, 2, , 3].mapUsingReduce(\n  (currentValue, index, array) => currentValue + index + array.length\n) // [5, 7, , 10]</code></pre></div>"},{"url":"/docs/js-tips/insert-into-array/","relativePath":"docs/js-tips/insert-into-array.md","relativeDir":"docs/js-tips","base":"insert-into-array.md","name":"insert-into-array","frontmatter":{"title":"Insert Into Array","weight":0,"excerpt":"We have some in-built methods to add at elements at the beginning and end of the array.","seo":{"title":"Insert Into Array","description":"We have some in-built methods to add at elements at the beginning and end of the array.","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Insert Into Array</h2>\n<p>We have some <code class=\"language-text\">in-built methods</code> to add at elements at the beginning and end of the array.</p>\n<p><code class=\"language-text\">push(value)</code> → Add an element to the end of the array.</p>\n<p><code class=\"language-text\">unshift(value)</code> → Add an element to the beginning of an array.</p>\n<p>To add an element to the specific index there is no method available in <code class=\"language-text\">Array</code> object. But we can use already available <code class=\"language-text\">splice</code> method in <code class=\"language-text\">Array</code> object to achieve this.</p>\n<p>An array starts from <code class=\"language-text\">index 0</code> ,So if we want to add an element as first element of the array , then the index of the element is <code class=\"language-text\">0</code> .If we want to add an element to <code class=\"language-text\">nth</code> position , then the index is <code class=\"language-text\">(n-1) th</code> index.</p>\n<p>MDN : The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements, in the original array(which means the source array is modified)</p>\n<p><code class=\"language-text\">splice()</code> method takes three argument</p>\n<ol>\n<li><em>start\\</em>* → *The index at which to start changing the array.</li>\n<li>*deleteCount(optional) → *An integer indicating the number of elements in the array to remove from <code class=\"language-text\">start</code>.</li>\n<li>*(elem1, elem2 ...) → *The elements to add to the array, beginning from <code class=\"language-text\">start</code>. If you do not specify any elements, <code class=\"language-text\">splice()</code> will only remove elements from the array.</li>\n</ol>\n<p>In order to insert an element to the specific index , we need to provide arguments as</p>\n<ol>\n<li><code class=\"language-text\">start</code> → <code class=\"language-text\">index</code> where to insert the element</li>\n<li><code class=\"language-text\">deleteCount</code> → <code class=\"language-text\">0</code> (because we don't need to delete element)</li>\n<li><code class=\"language-text\">elem</code> → elements to insert</li>\n</ol>\n<p>Let's Write the function<br>\nfunction insertAt(array, index, ...elementsArray) { array.splice(index, 0, ...elements);}</p>\n<p>Now Let's call the function</p>\n<p>var num = [1,2,3,6,7,8];/*<br>\narguments\\</p>\n<ul>\n<li>\n<ol>\n<li>source array - num\\</li>\n</ol>\n</li>\n<li>\n<ol start=\"2\">\n<li>index to insert - 3\\</li>\n</ol>\n</li>\n<li>\n<ol start=\"3\">\n<li>remaining are elements to insert<br>\n*/insertAt(num, 3, 4, 5); // [1,2,3,4,5,6,7,8]<strong>**</strong>**<strong>**</strong>**<strong>**</strong>**<strong>**</strong>____<strong>**</strong>**<strong>**</strong>**<strong>**</strong>**<strong>**</strong>// let's try changing the indexvar num = [1,2,3,6,7,8];insertAt(numbers, 2, 4,5); // [1,2,4,5,3,6,7,8]</li>\n</ol>\n</li>\n</ul>"},{"url":"/docs/js-tips/sorting-strings/","relativePath":"docs/js-tips/sorting-strings.md","relativeDir":"docs/js-tips","base":"sorting-strings.md","name":"sorting-strings","frontmatter":{"title":"Sorting Strings","weight":0,"excerpt":"Sorting Strings","seo":{"title":"Sorting Strings","description":"Sorting Strings","robots":[],"extra":[]},"template":"docs"},"html":"<p>Javascript has a native method <strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\">sort</a></strong> that allows sorting arrays. Doing a simple <code class=\"language-text\">array.sort()</code> will treat each array entry as a string and sort it alphabetically. Also you can provide your <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters\">own custom sorting</a> function.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'Shanghai'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'New York'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Mumbai'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Buenos Aires'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// [\"Buenos Aires\", \"Mumbai\", \"New York\", \"Shanghai\"]</span></code></pre></div>\n<p>But when you try order an array of non ASCII characters like this <code class=\"language-text\">['é', 'a', 'ú', 'c']</code>, you will obtain a strange result <code class=\"language-text\">['c', 'e', 'á', 'ú']</code>. That happens because sort works only with the English language.</p>\n<p>See the next example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Spanish</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'único'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'árbol'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cosas'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'fútbol'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// [\"cosas\", \"fútbol\", \"árbol\", \"único\"] // bad order</span>\n\n<span class=\"token comment\">// German</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'Woche'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'wöchentlich'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'wäre'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Wann'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// [\"Wann\", \"Woche\", \"wäre\", \"wöchentlich\"] // bad order</span></code></pre></div>\n<p>Fortunately, there are two ways to overcome this behavior <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare\">localeCompare</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator\">Intl.Collator</a> provided by ECMAScript Internationalization API.</p>\n<blockquote>\n<p>Both methods have their own custom parameters in order to configure it to work adequately.</p>\n</blockquote>\n<h3>Using <code class=\"language-text\">localeCompare()</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'único'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'árbol'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cosas'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'fútbol'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> a<span class=\"token punctuation\">.</span><span class=\"token function\">localeCompare</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// [\"árbol\", \"cosas\", \"fútbol\", \"único\"]</span>\n\n<span class=\"token punctuation\">[</span><span class=\"token string\">'Woche'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'wöchentlich'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'wäre'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Wann'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> a<span class=\"token punctuation\">.</span><span class=\"token function\">localeCompare</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// [\"Wann\", \"wäre\", \"Woche\", \"wöchentlich\"]</span></code></pre></div>\n<h3>Using <code class=\"language-text\">Intl.Collator()</code></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'único'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'árbol'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cosas'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'fútbol'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span>Intl<span class=\"token punctuation\">.</span><span class=\"token function\">Collator</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>compare<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// [\"árbol\", \"cosas\", \"fútbol\", \"único\"]</span>\n\n<span class=\"token punctuation\">[</span><span class=\"token string\">'Woche'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'wöchentlich'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'wäre'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Wann'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span>Intl<span class=\"token punctuation\">.</span><span class=\"token function\">Collator</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>compare<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// [\"Wann\", \"wäre\", \"Woche\", \"wöchentlich\"]</span></code></pre></div>\n<ul>\n<li>For each method you can customize the location.</li>\n<li>According to <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#Performance\">Firefox</a> Intl.Collator is faster when comparing large numbers of strings.</li>\n</ul>\n<p>So when you are working with arrays of strings in a language other than English, remember to use this method to avoid unexpected sorting.</p>"},{"url":"/docs/js-tips/regexp/","relativePath":"docs/js-tips/regexp.md","relativeDir":"docs/js-tips","base":"regexp.md","name":"regexp","frontmatter":{"title":"RegExp","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":" RegExp ","description":"Javascript Quick Tips Directory","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>RegExp</h1>\n<p>The <code class=\"language-text\">RegExp</code> object is used for matching text with a pattern.</p>\n<p>For an introduction to regular expressions, read the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\">Regular Expressions chapter</a> in the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\">JavaScript Guide</a>.</p>\n<h2>Description</h2>\n<h3>Literal notation and constructor</h3>\n<p>There are two ways to create a <code class=\"language-text\">RegExp</code> object: a <em>literal notation</em> and a <em>constructor</em>.</p>\n<ul>\n<li><strong>The literal notation's</strong> parameters are enclosed between slashes and do not use quotation marks.</li>\n<li><strong>The constructor function's</strong> parameters are not enclosed between slashes but do use quotation marks.</li>\n</ul>\n<p>The following three expressions create the same regular expression object:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = /ab+c/i; // literal notation\nlet re = new RegExp('ab+c', 'i') // constructor with string pattern as first argument\nlet re = new RegExp(/ab+c/, 'i') // constructor with regular expression literal as first argument (Starting with ECMAScript 6)</code></pre></div>\n<p>The literal notation results in compilation of the regular expression when the expression is evaluated. Use literal notation when the regular expression will remain constant. For example, if you use literal notation to construct a regular expression used in a loop, the regular expression won't be recompiled on each iteration.</p>\n<p>The constructor of the regular expression object—for example, <code class=\"language-text\">new RegExp('ab+c')</code>—results in runtime compilation of the regular expression. Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and obtain it from another source, such as user input.</p>\n<h3>Flags in constructor</h3>\n<p>Starting with ECMAScript 6, <code class=\"language-text\">new RegExp(/ab+c/, 'i')</code> no longer throws a <a href=\"typeerror\"><code class=\"language-text\">TypeError</code></a> (<code class=\"language-text\">\"can't supply flags when constructing one RegExp from another\"</code>) when the first argument is a <code class=\"language-text\">RegExp</code> and the second <code class=\"language-text\">flags</code> argument is present. A new <code class=\"language-text\">RegExp</code> from the arguments is created instead.</p>\n<p>When using the constructor function, the normal string escape rules (preceding special characters with <code class=\"language-text\">\\</code> when included in a string) are necessary.</p>\n<p>For example, the following are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = /\\w+/\nlet re = new RegExp('\\\\w+')</code></pre></div>\n<h3>Perl-like RegExp properties</h3>\n<p>Note that several of the <a href=\"regexp\"><code class=\"language-text\">RegExp</code></a> properties have both long and short (Perl-like) names. Both names always refer to the same value. (Perl is the programming language from which JavaScript modeled its regular expressions.). See also <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features#regexp_properties\">deprecated <code class=\"language-text\">RegExp</code> properties.</a></p>\n<h2>Constructor</h2>\n<p><a href=\"regexp/regexp\"><code class=\"language-text\">RegExp()</code></a>\nCreates a new <code class=\"language-text\">RegExp</code> object.</p>\n<h2>Static properties</h2>\n<p><a href=\"regexp/@@species\"><code class=\"language-text\">get RegExp[@@species]</code></a>\nThe constructor function that is used to create derived objects.</p>\n<h2>Instance properties</h2>\n<p><a href=\"regexp/flags\"><code class=\"language-text\">RegExp.prototype.flags</code></a>\nA string that contains the flags of the <code class=\"language-text\">RegExp</code> object.</p>\n<p><a href=\"regexp/dotall\"><code class=\"language-text\">RegExp.prototype.dotAll</code></a>\nWhether <code class=\"language-text\">.</code> matches newlines or not.</p>\n<p><a href=\"regexp/global\"><code class=\"language-text\">RegExp.prototype.global</code></a>\nWhether to test the regular expression against all possible matches in a string, or only against the first.</p>\n<p><a href=\"regexp/hasindices\"><code class=\"language-text\">RegExp.prototype.hasIndices</code></a>\nWhether the regular expression result exposes the start and end indices of captured substrings.</p>\n<p><a href=\"regexp/ignorecase\"><code class=\"language-text\">RegExp.prototype.ignoreCase</code></a>\nWhether to ignore case while attempting a match in a string.</p>\n<p><a href=\"regexp/multiline\"><code class=\"language-text\">RegExp.prototype.multiline</code></a>\nWhether or not to search in strings across multiple lines.</p>\n<p><a href=\"regexp/source\"><code class=\"language-text\">RegExp.prototype.source</code></a>\nThe text of the pattern.</p>\n<p><a href=\"regexp/sticky\"><code class=\"language-text\">RegExp.prototype.sticky</code></a>\nWhether or not the search is sticky.</p>\n<p><a href=\"regexp/unicode\"><code class=\"language-text\">RegExp.prototype.unicode</code></a>\nWhether or not Unicode features are enabled.</p>\n<p><a href=\"regexp/lastindex\"><code class=\"language-text\">RegExp: lastIndex</code></a>\nThe index at which to start the next match.</p>\n<h2>Instance methods</h2>\n<p><a href=\"regexp/compile\"><code class=\"language-text\">RegExp.prototype.compile()</code></a> <span class=\"icon deprecated\" viewbox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\" role=\"img\"> This deprecated API should no longer be used, but will probably still work. </span>\n(Re-)compiles a regular expression during execution of a script.</p>\n<p><a href=\"regexp/exec\"><code class=\"language-text\">RegExp.prototype.exec()</code></a>\nExecutes a search for a match in its string parameter.</p>\n<p><a href=\"regexp/test\"><code class=\"language-text\">RegExp.prototype.test()</code></a>\nTests for a match in its string parameter.</p>\n<p><a href=\"regexp/tostring\"><code class=\"language-text\">RegExp.prototype.toString()</code></a>\nReturns a string representing the specified object. Overrides the <a href=\"object/tostring\"><code class=\"language-text\">Object.prototype.toString()</code></a> method.</p>\n<p><a href=\"regexp/@@match\"><code class=\"language-text\">RegExp.prototype[@@match]()</code></a>\nPerforms match to given string and returns match result.</p>\n<p><a href=\"regexp/@@matchall\"><code class=\"language-text\">RegExp.prototype[@@matchAll]()</code></a>\nReturns all matches of the regular expression against a string.</p>\n<p><a href=\"regexp/@@replace\"><code class=\"language-text\">RegExp.prototype[@@replace]()</code></a>\nReplaces matches in given string with new substring.</p>\n<p><a href=\"regexp/@@search\"><code class=\"language-text\">RegExp.prototype[@@search]()</code></a>\nSearches the match in given string and returns the index the pattern found in the string.</p>\n<p><a href=\"regexp/@@split\"><code class=\"language-text\">RegExp.prototype[@@split]()</code></a>\nSplits given string into an array by separating the string into substrings.</p>\n<h2>Examples</h2>\n<h3>Using a regular expression to change data format</h3>\n<p>The following script uses the <a href=\"string/replace\"><code class=\"language-text\">replace()</code></a> method of the <a href=\"string\"><code class=\"language-text\">String</code></a> instance to match a name in the format <em>first last</em> and output it in the format <em>last, first</em>.</p>\n<p>In the replacement text, the script uses <code class=\"language-text\">$1</code> and <code class=\"language-text\">$2</code> to indicate the results of the corresponding matching parentheses in the regular expression pattern.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let re = /(\\w+)\\s(\\w+)/\nlet str = 'John Smith'\nlet newstr = str.replace(re, '$2, $1')\nconsole.log(newstr)</code></pre></div>\n<p>This displays <code class=\"language-text\">\"Smith, John\"</code>.</p>\n<h3>Using regular expression to split lines with different line endings/ends of line/line breaks</h3>\n<p>The default line ending varies depending on the platform (Unix, Windows, etc.). The line splitting provided in this example works on all platforms.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let text = 'Some text\\nAnd some more\\r\\nAnd yet\\rThis is the end'\nlet lines = text.split(/\\r\\n|\\r|\\n/)\nconsole.log(lines) // logs [ 'Some text', 'And some more', 'And yet', 'This is the end' ]</code></pre></div>\n<p>Note that the order of the patterns in the regular expression matters.</p>\n<h3>Using regular expression on multiple lines</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let s = 'Please yes\\nmake my day!'\n\ns.match(/yes.*day/);\n// Returns null\n\ns.match(/yes[^]*day/);\n// Returns [\"yes\\nmake my day\"]</code></pre></div>\n<h3>Using a regular expression with the sticky flag</h3>\n<p>The <a href=\"regexp/sticky\"><code class=\"language-text\">sticky</code></a> flag indicates that the regular expression performs sticky matching in the target string by attempting to match starting at <a href=\"regexp/lastindex\"><code class=\"language-text\">RegExp.prototype.lastIndex</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let str = '#foo#'\nlet regex = /foo/y\n\nregex.lastIndex = 1\nregex.test(str)      // true\nregex.lastIndex = 5\nregex.test(str)      // false (lastIndex is taken into account with sticky flag)\nregex.lastIndex      // 0 (reset after match failure)</code></pre></div>\n<h3>The difference between the sticky flag and the global flag</h3>\n<p>With the sticky flag <code class=\"language-text\">y</code>, the next match has to happen at the <code class=\"language-text\">lastIndex</code> position, while with the global flag <code class=\"language-text\">g</code>, the match can happen at the <code class=\"language-text\">lastIndex</code> position or later:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">re = /\\d/y;\nwhile (r = re.exec(\"123 456\")) console.log(r, \"AND re.lastIndex\", re.lastIndex);\n\n// [ '1', index: 0, input: '123 456', groups: undefined ] AND re.lastIndex 1\n// [ '2', index: 1, input: '123 456', groups: undefined ] AND re.lastIndex 2\n// [ '3', index: 2, input: '123 456', groups: undefined ] AND re.lastIndex 3\n//   ... and no more match.</code></pre></div>\n<p>With the global flag <code class=\"language-text\">g</code>, all 6 digits would be matched, not just 3.</p>\n<h3>Regular expression and Unicode characters</h3>\n<p><code class=\"language-text\">\\w</code> and <code class=\"language-text\">\\W</code> only matches ASCII based characters; for example, <code class=\"language-text\">a</code> to <code class=\"language-text\">z</code>, <code class=\"language-text\">A</code> to <code class=\"language-text\">Z</code>, <code class=\"language-text\">0</code> to <code class=\"language-text\">9</code>, and <code class=\"language-text\">_</code>.</p>\n<p>To match characters from other languages such as Cyrillic or Hebrew, use <code class=\"language-text\">\\uhhhh</code>, where <code class=\"language-text\">hhhh</code> is the character's Unicode value in hexadecimal.</p>\n<p>This example demonstrates how one can separate out Unicode characters from a word.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let text = 'Образец text на русском языке'\nlet regex = /[\\u0400-\\u04FF]+/g\n\nlet match = regex.exec(text)\nconsole.log(match[0])        // logs 'Образец'\nconsole.log(regex.lastIndex) // logs '7'\n\nlet match2 = regex.exec(text)\nconsole.log(match2[0])       // logs 'на' [did not log 'text']\nconsole.log(regex.lastIndex) // logs '15'\n\n// and so on</code></pre></div>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes\">Unicode property escapes</a> feature introduces a solution, by allowing for a statement as simple as <code class=\"language-text\">\\p{scx=Cyrl}</code>.</p>\n<h3>Extracting sub-domain name from URL</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let url = 'http://xxx.domain.com'\nconsole.log(/[^.]+/.exec(url)[0].substr(7)) // logs 'xxx'</code></pre></div>\n<p><strong>Note:</strong> Instead of using regular expressions for parsing URLs, it is usually better to use the browsers built-in URL parser by using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/URL_API\">URL API</a>.</p>"},{"url":"/docs/js-tips/sort/","relativePath":"docs/js-tips/sort.md","relativeDir":"docs/js-tips","base":"sort.md","name":"sort","frontmatter":{"title":"Array.sort()","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":"Array.prototype.sort()","description":"Javascript Quick Tips Directory","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Array.prototype.sort()</h1>\n<p>The <code class=\"language-text\">sort()</code> method sorts the elements of an array <em>[in place](<a href=\"https://en.wikipedia.org/wiki/In-place\">https://en.wikipedia.org/wiki/In-place</a></em>algorithm)_ and returns the sorted array. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.</p>\n<p>The time and space complexity of the sort cannot be guaranteed as it depends on the implementation.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Functionless\nsort()\n\n// Arrow function\nsort((firstEl, secondEl) => { ... } )\n\n// Compare function\nsort(compareFn)\n\n// Inline compare function\nsort(function compareFn(firstEl, secondEl) { ... })</code></pre></div>\n<h3>Parameters</h3>\n<p><code class=\"language-text\">compareFunction</code> <span class=\"badge inline optional\">Optional</span>\nSpecifies a function that defines the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value.</p>\n<p><code class=\"language-text\">firstEl</code>\nThe first element for comparison.</p>\n<p><code class=\"language-text\">secondEl</code>\nThe second element for comparison.</p>\n<h3>Return value</h3>\n<p>The sorted array. Note that the array is sorted <em>[in place](<a href=\"https://en.wikipedia.org/wiki/In-place\">https://en.wikipedia.org/wiki/In-place</a></em>algorithm)_, and no copy is made.</p>\n<h2>Description</h2>\n<p>If <code class=\"language-text\">compareFunction</code> is not supplied, all non-<code class=\"language-text\">undefined</code> array elements are sorted by converting them to strings and comparing strings in UTF-16 code units order. For example, \"banana\" comes before \"cherry\". In a numeric sort, 9 comes before 80, but because numbers are converted to strings, \"80\" comes before \"9\" in the Unicode order. All <code class=\"language-text\">undefined</code> elements are sorted to the end of the array.</p>\n<p><strong>Note:</strong> In UTF-16, Unicode characters above <code class=\"language-text\">\\uFFFF</code> are encoded as two surrogate code units, of the range <code class=\"language-text\">\\uD800</code>-<code class=\"language-text\">\\uDFFF</code>. The value of each code unit is taken separately into account for the comparison. Thus the character formed by the surrogate pair <code class=\"language-text\">\\uD655\\uDE55</code> will be sorted before the character <code class=\"language-text\">\\uFF3A</code>.</p>\n<p>If <code class=\"language-text\">compareFunction</code> is supplied, all non-<code class=\"language-text\">undefined</code> array elements are sorted according to the return value of the compare function (all <code class=\"language-text\">undefined</code> elements are sorted to the end of the array, with no call to <code class=\"language-text\">compareFunction</code>). If <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> are two elements being compared, then:</p>\n<ul>\n<li>If <code class=\"language-text\">compareFunction(a, b)</code> returns less than 0, leave <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> unchanged.</li>\n<li>If <code class=\"language-text\">compareFunction(a, b)</code> returns 0, leave <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> unchanged with respect to each other, but sorted with respect to all different elements. Note: the ECMAScript standard only started guaranteeing this behavior <a href=\"https://www.ecma-international.org/ecma-262/10.0/index.html#sec-intro\">in 2019</a>, thus, older browsers may not respect this.</li>\n<li>If <code class=\"language-text\">compareFunction(a, b)</code> returns greater than 0, sort <code class=\"language-text\">b</code> before <code class=\"language-text\">a</code>.</li>\n<li><code class=\"language-text\">compareFunction(a, b)</code> must always return the same value when given a specific pair of elements <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> as its two arguments. If inconsistent results are returned, then the sort order is undefined.</li>\n</ul>\n<p>So, the compare function has the following form:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function compare(a, b) {\n  if (a is less than b by some ordering criterion) {\n    return -1;\n  }\n  if (a is greater than b by the ordering criterion) {\n    return 1;\n  }\n  // a must be equal to b\n  return 0;\n}</code></pre></div>\n<p>To compare numbers instead of strings, the compare function can subtract <code class=\"language-text\">b</code> from <code class=\"language-text\">a</code>. The following function will sort the array in ascending order (if it doesn't contain <code class=\"language-text\">Infinity</code> and <code class=\"language-text\">NaN</code>):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function compareNumbers(a, b) {\n  return a - b;\n}</code></pre></div>\n<p>The <code class=\"language-text\">sort</code> method can be conveniently used with <a href=\"../../operators/function\">function expressions</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var numbers = [4, 2, 5, 1, 3];\nnumbers.sort(function(a, b) {\n  return a - b;\n});\nconsole.log(numbers);\n\n// [1, 2, 3, 4, 5]</code></pre></div>\n<p>ES2015 provides <a href=\"../../functions/arrow_functions\">arrow function expressions</a> with even shorter syntax.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let numbers = [4, 2, 5, 1, 3];\nnumbers.sort((a, b) => a - b);\nconsole.log(numbers);\n\n// [1, 2, 3, 4, 5]</code></pre></div>\n<p>Arrays of objects can be sorted by comparing the value of one of their properties.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var items = [\n  { name: 'Edward', value: 21 },\n  { name: 'Sharpe', value: 37 },\n  { name: 'And', value: 45 },\n  { name: 'The', value: -12 },\n  { name: 'Magnetic', value: 13 },\n  { name: 'Zeros', value: 37 }\n];\n\n// sort by value\nitems.sort(function (a, b) {\n  return a.value - b.value;\n});\n\n// sort by name\nitems.sort(function(a, b) {\n  var nameA = a.name.toUpperCase(); // ignore upper and lowercase\n  var nameB = b.name.toUpperCase(); // ignore upper and lowercase\n  if (nameA &lt; nameB) {\n    return -1;\n  }\n  if (nameA > nameB) {\n    return 1;\n  }\n\n  // names must be equal\n  return 0;\n});</code></pre></div>\n<h2>Examples</h2>\n<h3>Creating, displaying, and sorting an array</h3>\n<p>The following example creates four arrays and displays the original array, then the sorted arrays. The numeric arrays are sorted without a compare function, then sorted using one.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let stringArray = ['Blue', 'Humpback', 'Beluga'];\nlet numericStringArray = ['80', '9', '700'];\nlet numberArray = [40, 1, 5, 200];\nlet mixedNumericArray = ['80', '9', '700', 40, 1, 5, 200];\n\nfunction compareNumbers(a, b) {\n  return a - b;\n}\n\nstringArray.join(); // 'Blue,Humpback,Beluga'\nstringArray.sort(); // ['Beluga', 'Blue', 'Humpback']\n\nnumberArray.join(); // '40,1,5,200'\nnumberArray.sort(); // [1, 200, 40, 5]\nnumberArray.sort(compareNumbers); // [1, 5, 40, 200]\n\nnumericStringArray.join(); // '80,9,700'\nnumericStringArray.sort(); // [700, 80, 9]\nnumericStringArray.sort(compareNumbers); // [9, 80, 700]\n\nmixedNumericArray.join(); // '80,9,700,40,1,5,200'\nmixedNumericArray.sort(); // [1, 200, 40, 5, 700, 80, 9]\nmixedNumericArray.sort(compareNumbers); // [1, 5, 9, 40, 80, 200, 700]</code></pre></div>\n<h3>Sorting non-ASCII characters</h3>\n<p>For sorting strings with non-ASCII characters, i.e. strings with accented characters (e, é, è, a, ä, etc.), strings from languages other than English, use <a href=\"../string/localecompare\"><code class=\"language-text\">String.localeCompare</code></a>. This function can compare those characters so they appear in the right order.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];\nitems.sort(function (a, b) {\n  return a.localeCompare(b);\n});\n\n// items is ['adieu', 'café', 'communiqué', 'éclair', 'premier', 'réservé']</code></pre></div>\n<h3>Sorting with map</h3>\n<p>The <code class=\"language-text\">compareFunction</code> can be invoked multiple times per element within the array. Depending on the <code class=\"language-text\">compareFunction</code>'s nature, this may yield a high overhead. The more work a <code class=\"language-text\">compareFunction</code> does and the more elements there are to sort, it may be more efficient to use <a href=\"map\">map</a> for sorting. The idea is to traverse the array once to extract the actual values used for sorting into a temporary array, sort the temporary array, and then traverse the temporary array to achieve the right order.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// the array to be sorted\nconst in = ['delta', 'alpha', 'charlie', 'bravo'];\n\n// temporary array holds objects with position and sort-value\nconst mapped = in.map((v, i) => {\n  return { i, value: someSlowOperation(v) };\n})\n\n// sorting the mapped array containing the reduced values\nmapped.sort((a, b) => {\n  if (a.value > b.value) {\n    return 1;\n  }\n  if (a.value &lt; b.value) {\n    return -1;\n  }\n  return 0;\n});\n\nconst result = mapped.map(v => in[v.i]);</code></pre></div>\n<p>There is an open source library available called <a href=\"https://null.house/open-source/mapsort\">mapsort</a> which applies this approach.</p>\n<h3>Sort stability</h3>\n<p>Since version 10 (or EcmaScript 2019), the <a href=\"https://tc39.es/ecma262/#sec-array.prototype.sort\">specification</a> dictates that <code class=\"language-text\">Array.prototype.sort</code> is stable.</p>\n<p>For example, say you had a list of students alongside their grades. Note that the list of students is already pre-sorted by name in alphabetical order:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const students = [\n  { name: \"Alex\",   grade: 15 },\n  { name: \"Devlin\", grade: 15 },\n  { name: \"Eagle\",  grade: 13 },\n  { name: \"Sam\",    grade: 14 },\n];</code></pre></div>\n<p>After sorting this array by <code class=\"language-text\">grade</code> in ascending order:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">students.sort((firstItem, secondItem) => firstItem.grade - secondItem.grade);</code></pre></div>\n<p>The <code class=\"language-text\">students</code> variable will then have the following value:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[\n  { name: \"Eagle\",  grade: 13 },\n  { name: \"Sam\",    grade: 14 },\n  { name: \"Alex\",   grade: 15 }, // original maintained for similar grade (stable sorting)\n  { name: \"Devlin\", grade: 15 }, // original maintained for similar grade (stable sorting)\n];</code></pre></div>\n<p>It's important to note that students that have the same grade (for example, Alex and Devlin), will remain in the same order as before calling the sort. This is what a stable sorting algorithm guarantees.</p>\n<p>Before version 10 (or EcmaScript 2019), sort stabiliy was not guaranteed, meaning that you could end up with the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[\n  { name: \"Eagle\",  grade: 13 },\n  { name: \"Sam\",    grade: 14 },\n  { name: \"Devlin\", grade: 15 }, // original order not maintained\n  { name: \"Alex\",   grade: 15 }, // original order not maintained\n];</code></pre></div>"},{"url":"/docs/js-tips/string/","relativePath":"docs/js-tips/string.md","relativeDir":"docs/js-tips","base":"string.md","name":"string","frontmatter":{"title":"String","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":"String","description":"Javascript Quick Tips Directory","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>String</h1>\n<p>The <code class=\"language-text\">String</code> object is used to represent and manipulate a sequence of characters.</p>\n<h2>Description</h2>\n<p>Strings are useful for holding data that can be represented in text form. Some of the most-used operations on strings are to check their <a href=\"string/length\"><code class=\"language-text\">length</code></a>, to build and concatenate them using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#string_operators\">+ and += string operators</a>, checking for the existence or location of substrings with the <a href=\"string/indexof\"><code class=\"language-text\">indexOf()</code></a> method, or extracting substrings with the <a href=\"string/substring\"><code class=\"language-text\">substring()</code></a> method.</p>\n<h3>Creating strings</h3>\n<p>Strings can be created as primitives, from string literals, or as objects, using the <a href=\"string/string\"><code class=\"language-text\">String()</code></a> constructor:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const string1 = \"A string primitive\";\nconst string2 = 'Also a string primitive';\nconst string3 = `Yet another string primitive`;\n\nconst string4 = new String(\"A String object\");</code></pre></div>\n<p>String primitives and string objects can be used interchangeably in most situations. See \"<a href=\"#string_primitives_and_string_objects\">String primitives and String objects</a>\" below.</p>\n<p>String literals can be specified using single or double quotes, which are treated identically, or using the backtick character `. This last form specifies a <a href=\"../template_literals\">template literal</a>: with this form you can interpolate expressions.</p>\n<h3>Character access</h3>\n<p>There are two ways to access an individual character in a string. The first is the <a href=\"string/charat\"><code class=\"language-text\">charAt()</code></a> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">return 'cat'.charAt(1) // returns \"a\"</code></pre></div>\n<p>The other way (introduced in ECMAScript 5) is to treat the string as an array-like object, where individual characters correspond to a numerical index:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">return 'cat'[1] // returns \"a\"</code></pre></div>\n<p>When using bracket notation for character access, attempting to delete or assign a value to these properties will not succeed. The properties involved are neither writable nor configurable. (See <a href=\"object/defineproperty\"><code class=\"language-text\">Object.defineProperty()</code></a> for more information.)</p>\n<h3>Comparing strings</h3>\n<p>In C, the <code class=\"language-text\">strcmp()</code> function is used for comparing strings. In JavaScript, you just use the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators\">less-than and greater-than operators</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let a = 'a'\nlet b = 'b'\nif (a &lt; b) { // true\n  console.log(a + ' is less than ' + b)\n} else if (a > b) {\n  console.log(a + ' is greater than ' + b)\n} else {\n  console.log(a + ' and ' + b + ' are equal.')\n}</code></pre></div>\n<p>A similar result can be achieved using the <a href=\"string/localecompare\"><code class=\"language-text\">localeCompare()</code></a> method inherited by <code class=\"language-text\">String</code> instances.</p>\n<p>Note that <code class=\"language-text\">a == b</code> compares the strings in <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> for being equal in the usual case-sensitive way. If you wish to compare without regard to upper or lower case characters, use a function similar to this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function isEqual(str1, str2)\n{\n    return str1.toUpperCase() === str2.toUpperCase()\n} // isEqual</code></pre></div>\n<p>Upper case is used instead of lower case in this function, due to problems with certain UTF-8 character conversions.</p>\n<h3>String primitives and String objects</h3>\n<p>Note that JavaScript distinguishes between <code class=\"language-text\">String</code> objects and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Primitive\">primitive string</a> values. (The same is true of <a href=\"boolean\"><code class=\"language-text\">Boolean</code></a> and <a href=\"number\"><code class=\"language-text\">Numbers</code></a>.)</p>\n<p>String literals (denoted by double or single quotes) and strings returned from <code class=\"language-text\">String</code> calls in a non-constructor context (that is, called without using the <a href=\"../operators/new\"><code class=\"language-text\">new</code></a> keyword) are primitive strings. JavaScript automatically converts primitives to <code class=\"language-text\">String</code> objects, so that it's possible to use <code class=\"language-text\">String</code> object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let s_prim = 'foo'\nlet s_obj = new String(s_prim)\n\nconsole.log(typeof s_prim) // Logs \"string\"\nconsole.log(typeof s_obj)  // Logs \"object\"</code></pre></div>\n<p>String primitives and <code class=\"language-text\">String</code> objects also give different results when using <a href=\"eval\"><code class=\"language-text\">eval()</code></a>. Primitives passed to <code class=\"language-text\">eval</code> are treated as source code; <code class=\"language-text\">String</code> objects are treated as all other objects are, by returning the object. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let s1 = '2 + 2'              // creates a string primitive\nlet s2 = new String('2 + 2')  // creates a String object\nconsole.log(eval(s1))         // returns the number 4\nconsole.log(eval(s2))         // returns the string \"2 + 2\"</code></pre></div>\n<p>For these reasons, the code may break when it encounters <code class=\"language-text\">String</code> objects when it expects a primitive string instead, although generally, authors need not worry about the distinction.</p>\n<p>A <code class=\"language-text\">String</code> object can always be converted to its primitive counterpart with the <a href=\"string/valueof\"><code class=\"language-text\">valueOf()</code></a> method.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(eval(s2.valueOf()))  // returns the number 4</code></pre></div>\n<h3><span id=\"escape_sequences\">Escape sequences</span></h3>\n<p>Special characters can be encoded using escape sequences:</p>\n<table>\n<thead>\n<tr class=\"header\">\n<th>Escape sequence</th>\n<th>Unicode code point</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td>\n<code>\\0</code>\n</td>\n<td>null character (U+0000 NULL)</td>\n</tr>\n<tr class=\"even\">\n<td>\n<code>\\'</code>\n</td>\n<td>single quote (U+0027 APOSTROPHE)</td>\n</tr>\n<tr class=\"odd\">\n<td>\n<code>\\\"</code>\n</td>\n<td>double quote (U+0022 QUOTATION MARK)</td>\n</tr>\n<tr class=\"even\">\n<td>\n<code>\\\\</code>\n</td>\n<td>backslash (U+005C REVERSE SOLIDUS)</td>\n</tr>\n<tr class=\"odd\">\n<td>\n<code>\\n</code>\n</td>\n<td>newline (U+000A LINE FEED; LF)</td>\n</tr>\n<tr class=\"even\">\n<td>\n<code>\\r</code>\n</td>\n<td>carriage return (U+000D CARRIAGE RETURN; CR)</td>\n</tr>\n<tr class=\"odd\">\n<td>\n<code>\\v</code>\n</td>\n<td>vertical tab (U+000B LINE TABULATION)</td>\n</tr>\n<tr class=\"even\">\n<td>\n<code>\\t</code>\n</td>\n<td>tab (U+0009 CHARACTER TABULATION)</td>\n</tr>\n<tr class=\"odd\">\n<td>\n<code>\\b</code>\n</td>\n<td>backspace (U+0008 BACKSPACE)</td>\n</tr>\n<tr class=\"even\">\n<td>\n<code>\\f</code>\n</td>\n<td>form feed (U+000C FORM FEED)</td>\n</tr>\n<tr class=\"odd\">\n<td>\n<code>\\uXXXX</code>\n<br/>\n<p>…where <code>XXXX</code> is exactly 4 hex digits in the range <code>0000</code>-<code>FFFF</code>; e.g., <code>\\u000A</code> is the same as <code>\\n</code> (LINE FEED); <code>\\u0021</code> is \"<code>!</code>\"</td></p>\n<td>Unicode code point between <code>U+0000</code> and <code>U+FFFF</code> (the Unicode Basic Multilingual Plane)</td>\n</tr>\n<tr class=\"even\">\n<td>\n<code>\\u{X}</code>…<code>\\u{XXXXXX}</code>\n<br/>\n<p>…where <code>X</code>…<code>XXXXXX</code> is 1-6 hex digits in the range <code>0</code>-<code>10FFFF</code>; e.g., <code>\\u{A}</code> is the same as <code>\\n</code> (LINE FEED); <code>\\u{21}</code> is \"<code>!</code>\"</td></p>\n<td>Unicode code point between <code>U+0000</code> and <code>U+10FFFF</code> (the entirety of Unicode)</td>\n</tr>\n<tr class=\"odd\">\n<td>\n<code>\\xXX</code>\n<br/>\n<p>…where <code>XX</code> is exactly 2 hex digits in the range <code>00</code>-<code>FF</code>; e.g., <code>\\x0A</code> is the same as <code>\\n</code> (LINE FEED); <code>\\x21</code> is \"<code>!</code>\"</td></p>\n<td>Unicode code point between <code>U+0000</code> and <code>U+00FF</code> (the Basic Latin and Latin-1 Supplement blocks; equivalent to ISO-8859-1)</td>\n</tr>\n</tbody>\n</table>\n<h3>Long literal strings</h3>\n<p>Sometimes, your code will include strings which are very long. Rather than having lines that go on endlessly, or wrap at the whim of your editor, you may wish to specifically break the string into multiple lines in the source code without affecting the actual string contents. There are two ways you can do this.</p>\n<h4>Method 1</h4>\n<p>You can use the <a href=\"../operators/addition\">+</a> operator to append multiple strings together, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let longString = \"This is a very long string which needs \" +\n                 \"to wrap across multiple lines because \" +\n                 \"otherwise my code is unreadable.\"</code></pre></div>\n<h4>Method 2</h4>\n<p>You can use the backslash character (<code class=\"language-text\">\\</code>) at the end of each line to indicate that the string will continue on the next line. Make sure there is no space or any other character after the backslash (except for a line break), or as an indent; otherwise it will not work.</p>\n<p>That form looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let longString = \"This is a very long string which needs \\\nto wrap across multiple lines because \\\notherwise my code is unreadable.\"</code></pre></div>\n<p>Both of the above methods result in identical strings.</p>\n<h2>Constructor</h2>\n<p><a href=\"string/string\"><code class=\"language-text\">String()</code></a>\nCreates a new <code class=\"language-text\">String</code> object. It performs type conversion when called as a function, rather than as a constructor, which is usually more useful.</p>\n<h2>Static methods</h2>\n<p><a href=\"string/fromcharcode\"><code class=\"language-text\">String.fromCharCode(num1 [, ...[, numN]])</code></a>\nReturns a string created by using the specified sequence of Unicode values.</p>\n<p>[<code class=\"language-text\">String.fromCodePoint(num1 [, ...[, numN)</code>](string/fromcodepoint)\nReturns a string created by using the specified sequence of code points.</p>\n<p><a href=\"string/raw\"><code class=\"language-text\">String.raw()</code></a>\nReturns a string created from a raw template string.</p>\n<h2>Instance properties</h2>\n<p><a href=\"string/length\"><code class=\"language-text\">String.prototype.length</code></a>\nReflects the <code class=\"language-text\">length</code> of the string. Read-only.</p>\n<h2>Instance methods</h2>\n<p><a href=\"string/at\"><code class=\"language-text\">String.prototype.at(index)</code></a><span class=\"icon experimental\" viewbox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\" role=\"img\"> This is an experimental API that should not be used in production code. </span>\nReturns the character (exactly one UTF-16 code unit) at the specified <code class=\"language-text\">index</code>. Accepts negative integers, which count back from the last string character.</p>\n<p><a href=\"string/charat\"><code class=\"language-text\">String.prototype.charAt(index)</code></a>\nReturns the character (exactly one UTF-16 code unit) at the specified <code class=\"language-text\">index</code>.</p>\n<p><a href=\"string/charcodeat\"><code class=\"language-text\">String.prototype.charCodeAt(index)</code></a>\nReturns a number that is the UTF-16 code unit value at the given <code class=\"language-text\">index</code>.</p>\n<p><a href=\"string/codepointat\"><code class=\"language-text\">String.prototype.codePointAt(pos)</code></a>\nReturns a nonnegative integer Number that is the code point value of the UTF-16 encoded code point starting at the specified <code class=\"language-text\">pos</code>.</p>\n<p><a href=\"string/concat\"><code class=\"language-text\">String.prototype.concat(str [, ...strN ])</code></a>\nCombines the text of two (or more) strings and returns a new string.</p>\n<p><a href=\"string/includes\"><code class=\"language-text\">String.prototype.includes(searchString [, position])</code></a>\nDetermines whether the calling string contains <code class=\"language-text\">searchString</code>.</p>\n<p><a href=\"string/endswith\"><code class=\"language-text\">String.prototype.endsWith(searchString [, length])</code></a>\nDetermines whether a string ends with the characters of the string <code class=\"language-text\">searchString</code>.</p>\n<p><a href=\"string/indexof\"><code class=\"language-text\">String.prototype.indexOf(searchValue [, fromIndex])</code></a>\nReturns the index within the calling <a href=\"string\"><code class=\"language-text\">String</code></a> object of the first occurrence of <code class=\"language-text\">searchValue</code>, or <code class=\"language-text\">-1</code> if not found.</p>\n<p><a href=\"string/lastindexof\"><code class=\"language-text\">String.prototype.lastIndexOf(searchValue [, fromIndex])</code></a>\nReturns the index within the calling <a href=\"string\"><code class=\"language-text\">String</code></a> object of the last occurrence of <code class=\"language-text\">searchValue</code>, or <code class=\"language-text\">-1</code> if not found.</p>\n<p><a href=\"string/localecompare\"><code class=\"language-text\">String.prototype.localeCompare(compareString [, locales [, options]])</code></a>\nReturns a number indicating whether the reference string <code class=\"language-text\">compareString</code> comes before, after, or is equivalent to the given string in sort order.</p>\n<p><a href=\"string/match\"><code class=\"language-text\">String.prototype.match(regexp)</code></a>\nUsed to match regular expression <code class=\"language-text\">regexp</code> against a string.</p>\n<p><a href=\"string/matchall\"><code class=\"language-text\">String.prototype.matchAll(regexp)</code></a>\nReturns an iterator of all <code class=\"language-text\">regexp</code>'s matches.</p>\n<p><a href=\"string/normalize\"><code class=\"language-text\">String.prototype.normalize([form])</code></a>\nReturns the Unicode Normalization Form of the calling string value.</p>\n<p><a href=\"string/padend\"><code class=\"language-text\">String.prototype.padEnd(targetLength [, padString])</code></a>\nPads the current string from the end with a given string and returns a new string of the length <code class=\"language-text\">targetLength</code>.</p>\n<p><a href=\"string/padstart\"><code class=\"language-text\">String.prototype.padStart(targetLength [, padString])</code></a>\nPads the current string from the start with a given string and returns a new string of the length <code class=\"language-text\">targetLength</code>.</p>\n<p><a href=\"string/repeat\"><code class=\"language-text\">String.prototype.repeat(count)</code></a>\nReturns a string consisting of the elements of the object repeated <code class=\"language-text\">count</code> times.</p>\n<p><a href=\"string/replace\"><code class=\"language-text\">String.prototype.replace(searchFor, replaceWith)</code></a>\nUsed to replace occurrences of <code class=\"language-text\">searchFor</code> using <code class=\"language-text\">replaceWith</code>. <code class=\"language-text\">searchFor</code> may be a string or Regular Expression, and <code class=\"language-text\">replaceWith</code> may be a string or function.</p>\n<p><a href=\"string/replaceall\"><code class=\"language-text\">String.prototype.replaceAll(searchFor, replaceWith)</code></a>\nUsed to replace all occurrences of <code class=\"language-text\">searchFor</code> using <code class=\"language-text\">replaceWith</code>. <code class=\"language-text\">searchFor</code> may be a string or Regular Expression, and <code class=\"language-text\">replaceWith</code> may be a string or function.</p>\n<p><a href=\"string/search\"><code class=\"language-text\">String.prototype.search(regexp)</code></a>\nSearch for a match between a regular expression <code class=\"language-text\">regexp</code> and the calling string.</p>\n<p><a href=\"string/slice\"><code class=\"language-text\">String.prototype.slice(beginIndex[, endIndex])</code></a>\nExtracts a section of a string and returns a new string.</p>\n<p><a href=\"string/split\"><code class=\"language-text\">String.prototype.split([sep [, limit] ])</code></a>\nReturns an array of strings populated by splitting the calling string at occurrences of the substring <code class=\"language-text\">sep</code>.</p>\n<p><a href=\"string/startswith\"><code class=\"language-text\">String.prototype.startsWith(searchString [, length])</code></a>\nDetermines whether the calling string begins with the characters of string <code class=\"language-text\">searchString</code>.</p>\n<p><a href=\"string/substring\"><code class=\"language-text\">String.prototype.substring(indexStart [, indexEnd])</code></a>\nReturns a new string containing characters of the calling string from (or between) the specified index (or indeces).</p>\n<p><a href=\"string/tolocalelowercase\"><code class=\"language-text\">String.prototype.toLocaleLowerCase( [locale, ...locales])</code></a>\nThe characters within a string are converted to lowercase while respecting the current locale.</p>\n<p>For most languages, this will return the same as <a href=\"string/tolowercase\"><code class=\"language-text\">toLowerCase()</code></a>.</p>\n<p><a href=\"string/tolocaleuppercase\"><code class=\"language-text\">String.prototype.toLocaleUpperCase( [locale, ...locales])</code></a>\nThe characters within a string are converted to uppercase while respecting the current locale.</p>\n<p>For most languages, this will return the same as <a href=\"string/touppercase\"><code class=\"language-text\">toUpperCase()</code></a>.</p>\n<p><a href=\"string/tolowercase\"><code class=\"language-text\">String.prototype.toLowerCase()</code></a>\nReturns the calling string value converted to lowercase.</p>\n<p><a href=\"string/tostring\"><code class=\"language-text\">String.prototype.toString()</code></a>\nReturns a string representing the specified object. Overrides the <a href=\"object/tostring\"><code class=\"language-text\">Object.prototype.toString()</code></a> method.</p>\n<p><a href=\"string/touppercase\"><code class=\"language-text\">String.prototype.toUpperCase()</code></a>\nReturns the calling string value converted to uppercase.</p>\n<p><a href=\"string/trim\"><code class=\"language-text\">String.prototype.trim()</code></a>\nTrims whitespace from the beginning and end of the string. Part of the ECMAScript 5 standard.</p>\n<p><a href=\"string/trimstart\"><code class=\"language-text\">String.prototype.trimStart()</code></a>\nTrims whitespace from the beginning of the string.</p>\n<p><a href=\"string/trimend\"><code class=\"language-text\">String.prototype.trimEnd()</code></a>\nTrims whitespace from the end of the string.</p>\n<p><a href=\"string/valueof\"><code class=\"language-text\">String.prototype.valueOf()</code></a>\nReturns the primitive value of the specified object. Overrides the <a href=\"object/valueof\"><code class=\"language-text\">Object.prototype.valueOf()</code></a> method.</p>\n<p><a href=\"string/@@iterator\"><code class=\"language-text\">String.prototype.@@iterator()</code></a>\nReturns a new iterator object that iterates over the code points of a String value, returning each code point as a String value.</p>\n<h2>HTML wrapper methods</h2>\n<p><strong>Warning:</strong> Deprecated. Avoid these methods.</p>\n<p>They are of limited use, as they provide only a subset of the available HTML tags and attributes.</p>\n<p><a href=\"string/anchor\"><code class=\"language-text\">String.prototype.anchor()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-name\"><code class=\"language-text\">&lt;a name=\"name\"></code></a> (hypertext target)</p>\n<p><a href=\"string/big\"><code class=\"language-text\">String.prototype.big()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/big\"><code class=\"language-text\">&lt;big></code></a></p>\n<p><a href=\"string/blink\"><code class=\"language-text\">String.prototype.blink()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/blink\"><code class=\"language-text\">&lt;blink></code></a></p>\n<p><a href=\"string/bold\"><code class=\"language-text\">String.prototype.bold()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/b\"><code class=\"language-text\">&lt;b></code></a></p>\n<p><a href=\"string/fixed\"><code class=\"language-text\">String.prototype.fixed()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tt\"><code class=\"language-text\">&lt;tt></code></a></p>\n<p><a href=\"string/fontcolor\"><code class=\"language-text\">String.prototype.fontcolor()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font#attr-color\"><code class=\"language-text\">&lt;font color=\"color\"></code></a></p>\n<p><a href=\"string/fontsize\"><code class=\"language-text\">String.prototype.fontsize()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/font#attr-size\"><code class=\"language-text\">&lt;font size=\"size\"></code></a></p>\n<p><a href=\"string/italics\"><code class=\"language-text\">String.prototype.italics()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i\"><code class=\"language-text\">&lt;i></code></a></p>\n<p><a href=\"string/link\"><code class=\"language-text\">String.prototype.link()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href\"><code class=\"language-text\">&lt;a href=\"url\"></code></a> (link to URL)</p>\n<p><a href=\"string/small\"><code class=\"language-text\">String.prototype.small()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/small\"><code class=\"language-text\">&lt;small></code></a></p>\n<p><a href=\"string/strike\"><code class=\"language-text\">String.prototype.strike()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strike\"><code class=\"language-text\">&lt;strike></code></a></p>\n<p><a href=\"string/sub\"><code class=\"language-text\">String.prototype.sub()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub\"><code class=\"language-text\">&lt;sub></code></a></p>\n<p><a href=\"string/sup\"><code class=\"language-text\">String.prototype.sup()</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup\"><code class=\"language-text\">&lt;sup></code></a></p>\n<h2>Examples</h2>\n<h3>String conversion</h3>\n<p>It's possible to use <code class=\"language-text\">String</code> as a more reliable <a href=\"string/tostring\"><code class=\"language-text\">toString()</code></a> alternative, as it works when used on <a href=\"null\"><code class=\"language-text\">null</code></a>, <a href=\"undefined\"><code class=\"language-text\">undefined</code></a>, and on <a href=\"symbol\"><code class=\"language-text\">symbols</code></a>. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let outputStrings = []\nfor (let i = 0, n = inputValues.length; i &lt; n; ++i) {\n  outputStrings.push(String(inputValues[i]));\n}</code></pre></div>"},{"url":"/docs/leetcode/ContaineWitMosWater/","relativePath":"docs/leetcode/ContaineWitMosWater.md","relativeDir":"docs/leetcode","base":"ContaineWitMosWater.md","name":"ContaineWitMosWater","frontmatter":{"title":"Container With Most Water","weight":0,"excerpt":"feel free to try the examples","seo":{"title":" Container With Most Water  ","description":"Leetcode practice","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/container-with-most-water/description/\">11. Container With Most Water</a></h2>\n<h3>Problem:</h3>\n<p>Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.</p>\n<p>Note: You may not slant the container and n is at least 2.</p>\n<h3>Solution:</h3>\n<p>Greedy Algorithm.</p>\n<p>If we look at the simple brute force approach, where we choose one point at a time and calculate all the possible areas with other points on the right, it is easy to make a observation that we are narrowing down the horizontal distance.</p>\n<p>Greedy Algorithm can help us skip some of the conditions. It is base on a fact that the area between two columns are determined by the shorter one.</p>\n<p>Let's say we have pointer <code class=\"language-text\">l</code> and <code class=\"language-text\">r</code> at the begin and end of a distance, and the area is <code class=\"language-text\">area(l, r)</code>, how should we narrow down the distance?</p>\n<p>If <code class=\"language-text\">height[l] &lt; height[r]</code>, we know that the height of the area will never be greater than <code class=\"language-text\">height[l]</code> if we keep <code class=\"language-text\">l</code>. Now if we get rid of <code class=\"language-text\">r</code>, the area can only get smaller since the distance is shorter, and the height is at most <code class=\"language-text\">height[l]</code>.</p>\n<p>Here we conclude rule NO.1: Get rid of the smaller one.</p>\n<p>What if <code class=\"language-text\">height[l] == height[r]</code>? It is safe to get rid of both. We do not need any of them to constrain the max height of the rest points.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} height\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxArea</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">height</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> max <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> l <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> r <span class=\"token operator\">=</span> height<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> l <span class=\"token operator\">&lt;</span> r<span class=\"token punctuation\">;</span> l<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> r<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        max <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>max<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">-</span> l<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>height<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> height<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>height<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> height<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            r<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            l<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> max<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/js-tips/var/","relativePath":"docs/js-tips/var.md","relativeDir":"docs/js-tips","base":"var.md","name":"var","frontmatter":{"title":"var","weight":0,"excerpt":"Javascript articles  and docs","seo":{"title":"var","description":"The var declares a function-scoped or globally-scoped variable, optionally initializing it to a value.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>var</h1>\n<p>The <code class=\"language-text\">var</code> declares a function-scoped or globally-scoped variable, optionally initializing it to a value.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var varname1 [= value1] [, varname2 [= value2] ... [, varnameN [= valueN]]];</code></pre></div>\n<p><code class=\"language-text\">varnameN</code>\nVariable name. It can be any legal identifier.</p>\n<p><code class=\"language-text\">valueN</code> <span class=\"badge inline optional\">Optional</span>\nInitial value of the variable. It can be any legal expression. Default value is <code class=\"language-text\">undefined</code>.</p>\n<p>Alternatively, the <a href=\"../operators/destructuring_assignment\">Destructuring Assignment</a> syntax can also be used to declare variables.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var { bar } = foo; // where foo = { bar:10, baz:12 };\n/* This creates a variable with the name 'bar', which has a value of 10 */</code></pre></div>\n<h2>Description</h2>\n<p><code class=\"language-text\">var</code> declarations, wherever they occur, are processed before any code is executed. This is called hoisting, and is discussed further below.</p>\n<p>The scope of a variable declared with <code class=\"language-text\">var</code> is its current <em>execution context and closures thereof</em>, which is either the enclosing function and functions declared within it, or, for variables declared outside any function, global. Duplicate variable declarations using <code class=\"language-text\">var</code> will not trigger an error, even in strict mode, and the variable will not lose its value, unless another assignment is performed.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'use strict';\nfunction foo() {\n  var x = 1;\n  function bar() {\n    var y = 2;\n    console.log(x); // 1 (function `bar` closes over `x`)\n    console.log(y); // 2 (`y` is in scope)\n  }\n  bar();\n  console.log(x); // 1 (`x` is in scope)\n  console.log(y); // ReferenceError in strict mode, `y` is scoped to `bar`\n}\n\nfoo();</code></pre></div>\n<p>Variables declared using <code class=\"language-text\">var</code> are created before any code is executed in a process known as hoisting. Their initial value is <code class=\"language-text\">undefined</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'use strict';\nconsole.log(x);                // undefined (note: not ReferenceError)\nconsole.log('still going...'); // still going...\nvar x = 1;\nconsole.log(x);                // 1\nconsole.log('still going...'); // still going...</code></pre></div>\n<p>In the global context, a variable declared using <code class=\"language-text\">var</code> is added as a non-configurable property of the global object. This means its property descriptor cannot be changed and it cannot be deleted using <a href=\"../operators/delete\"><code class=\"language-text\">delete</code></a>. The corresponding name is also added to a list on the internal <code class=\"language-text\">[[VarNames]]</code> slot on the <a href=\"https://www.ecma-international.org/ecma-262/10.0/index.html#sec-global-environment-records\">global environment record</a> (which forms part of the global lexical environment). The list of names in <code class=\"language-text\">[[VarNames]]</code> enables the runtime to distinguish between global variables and straightforward properties on the global object.</p>\n<p>The property created on the global object for global variables, is set to be non-configurable because the identifier is to be treated as a variable, rather than a straightforward property of the global object. JavaScript has automatic memory management, and it would make no sense to be able to use the <code class=\"language-text\">delete</code> operator on a global variable.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'use strict';\nvar x = 1;\nglobalThis.hasOwnProperty('x'); // true\ndelete globalThis.x; // TypeError in strict mode. Fails silently otherwise.\ndelete x;  // SyntaxError in strict mode. Fails silently otherwise.</code></pre></div>\n<p>Note that in both NodeJS <a href=\"http://www.commonjs.org/\">CommonJS</a> modules and native <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\">ECMAScript modules</a>, top-level variable declarations are scoped to the module, and are not, therefore added as properties to the global object.</p>\n<h3>Unqualified identifier assignments</h3>\n<p>The global object sits at the top of the scope chain. When attempting to resolve a name to a value, the scope chain is searched. This means that properties on the global object are conveniently visible from every scope, without having to qualify the names with <code class=\"language-text\">globalThis.</code> or <code class=\"language-text\">window.</code> or <code class=\"language-text\">global.</code>.</p>\n<p>So you can just type:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function foo() {\n  String('s') // Note the function `String` is implicitly visible\n}</code></pre></div>\n<p>...because</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">globalThis.hasOwnProperty('String') // true</code></pre></div>\n<p>So the global object will ultimately be searched for unqualified identifiers. You don't have to type <code class=\"language-text\">globalThis.String</code>, you can just type the unqualified <code class=\"language-text\">String</code>. The corollary, in non-strict mode, is that assignment to unqualified identifiers will, if there is no variable of the same name declared in the scope chain, assume you want to create a property with that name on the global object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">foo = 'f' // In non-strict mode, assumes you want to create a property named `foo` on the global object\nglobalThis.hasOwnProperty('foo') // true</code></pre></div>\n<p>In ECMAScript 5, this behavior was changed for <a href=\"../strict_mode\">strict mode</a>. Assignment to an unqualified identifier in strict mode will result in a <code class=\"language-text\">ReferenceError</code>, to avoid the accidental creation of properties on the global object.</p>\n<p>Note that the implication of the above, is that, contrary to popular misinformation, JavaScript does not have implicit or undeclared variables, it merely has a syntax that looks like it does.</p>\n<h3>var hoisting</h3>\n<p>Because variable declarations (and declarations in general) are processed before any code is executed, declaring a variable anywhere in the code is equivalent to declaring it at the top. This also means that a variable can appear to be used before it's declared. This behavior is called \"hoisting\", as it appears that the variable declaration is moved to the top of the function or global code.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">bla = 2;\nvar bla;\n\n// ...is implicitly understood as:\n\nvar bla;\nbla = 2;</code></pre></div>\n<p>For that reason, it is recommended to always declare variables at the top of their scope (the top of global code and the top of function code) so it's clear which variables are function scoped (local) and which are resolved on the scope chain.</p>\n<p>It's important to point out that the hoisting will affect the variable declaration, but not its value's initialization. The value will be indeed assigned when the assignment statement is reached:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function do_something() {\n  console.log(bar); // undefined\n  var bar = 111;\n  console.log(bar); // 111\n}\n\n// ...is implicitly understood as:\n\nfunction do_something() {\n  var bar;\n  console.log(bar); // undefined\n  bar = 111;\n  console.log(bar); // 111\n}</code></pre></div>\n<h2>Examples</h2>\n<h3>Declaring and initializing two variables</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var a = 0, b = 0;</code></pre></div>\n<h3>Assigning two variables with single string value</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var a = 'A';\nvar b = a;\n\n// ...is equivalent to:\n\nvar a, b = a = 'A';</code></pre></div>\n<p>Be mindful of the order:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var x = y, y = 'A';\nconsole.log(x + y); // undefinedA</code></pre></div>\n<p>Here, <code class=\"language-text\">x</code> and <code class=\"language-text\">y</code> are declared before any code is executed, but the assignments occur later. At the time \"<code class=\"language-text\">x = y</code>\" is evaluated, <code class=\"language-text\">y</code> exists so no <code class=\"language-text\">ReferenceError</code> is thrown and its value is <code class=\"language-text\">undefined</code>. So, <code class=\"language-text\">x</code> is assigned the undefined value. Then, <code class=\"language-text\">y</code> is assigned the value <code class=\"language-text\">'A'</code>. Consequently, after the first line, <code class=\"language-text\">x === undefined &amp;&amp; y === 'A'</code>, hence the result.</p>\n<h3>Initialization of several variables</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var x = 0;\nfunction f() {\n  var x = y = 1; // Declares x locally; declares y globally.\n}\nf();\n\nconsole.log(x, y); // 0 1\n\n// In non-strict mode:\n// x is the global one as expected;\n// y is leaked outside of the function, though!</code></pre></div>\n<p>The same example as above but with a strict mode:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'use strict';\n\nvar x = 0;\nfunction f() {\n  var x = y = 1; // Throws a ReferenceError in strict mode.\n}\nf();\n\nconsole.log(x, y);</code></pre></div>\n<h3>Implicit globals and outer function scope</h3>\n<p>Variables that appear to be implicit globals may be references to variables in an outer function scope:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var x = 0; // Declares x within file scope, then assigns it a value of 0.\n\nconsole.log(typeof z); // \"undefined\", since z doesn't exist yet\n\nfunction a() {\n  var y = 2; // Declares y within scope of function a, then assigns it a value of 2.\n\n  console.log(x, y); // 0 2\n\n  function b() {\n    x = 3; // Assigns 3 to existing file scoped x.\n    y = 4; // Assigns 4 to existing outer y.\n    z = 5; // Creates a new global variable z, and assigns it a value of 5.\n           // (Throws a ReferenceError in strict mode.)\n  }\n\n  b(); // Creates z as a global variable.\n  console.log(x, y, z); // 3 4 5\n}\n\na(); // Also calls b.\nconsole.log(x, z);     // 3 5\nconsole.log(typeof y); // \"undefined\", as y is local to function a</code></pre></div>"},{"url":"/docs/js-tips/this/","relativePath":"docs/js-tips/this.md","relativeDir":"docs/js-tips","base":"this.md","name":"this","frontmatter":{"title":"This","weight":0,"excerpt":"In most cases, the value of this is determined by how a function is called (runtime binding). It can't be set by assignment during execution, and it may be different each time the function is called. ES5 introduced the bind() method to set the value of a function's this regardless of how it's called, and ES2015 introduced arrow functions which don't provide their own this binding (it retains the this value of the enclosing lexical context).","seo":{"title":"Javascript Quick Tips Directory","description":"A this behaves a little differently in JavaScript compared to other languages. It also has some differences between strict mode and non-strict mode.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>this</h1>\n<p>A <code class=\"language-text\">this</code> behaves a little differently in JavaScript compared to other languages. It also has some differences between <a href=\"../strict_mode\">strict mode</a> and non-strict mode.</p>\n<p>In most cases, the value of <code class=\"language-text\">this</code> is determined by how a function is called (runtime binding). It can't be set by assignment during execution, and it may be different each time the function is called. ES5 introduced the <a href=\"../global_objects/function/bind\"><code class=\"language-text\">bind()</code></a> method to <a href=\"#The_bind_method\">set the value of a function's <code class=\"language-text\">this</code> regardless of how it's called</a>, and ES2015 introduced <a href=\"../functions/arrow_functions\">arrow functions</a> which don't provide their own <code class=\"language-text\">this</code> binding (it retains the <code class=\"language-text\">this</code> value of the enclosing lexical context).</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this</code></pre></div>\n<h3>Value</h3>\n<p>A property of an execution context (global, function or eval) that, in non-strict mode, is always a reference to an object and in strict mode can be any value.</p>\n<h2>Description</h2>\n<h3>Global context</h3>\n<p>In the global execution context (outside of any function), <code class=\"language-text\">this</code> refers to the global object whether in strict mode or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// In web browsers, the window object is also the global object:\nconsole.log(this === window); // true\n\na = 37;\nconsole.log(window.a); // 37\n\nthis.b = \"MDN\";\nconsole.log(window.b)  // \"MDN\"\nconsole.log(b)         // \"MDN\"</code></pre></div>\n<p><strong>Note:</strong> You can always easily get the global object using the global <a href=\"../global_objects/globalthis\"><code class=\"language-text\">globalThis</code></a> property, regardless of the current context in which your code is running.</p>\n<h3>Function context</h3>\n<p>Inside a function, the value of <code class=\"language-text\">this</code> depends on how the function is called.</p>\n<p>Since the following code is not in <a href=\"../strict_mode\">strict mode</a>, and because the value of <code class=\"language-text\">this</code> is not set by the call, <code class=\"language-text\">this</code> will default to the global object, which is <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window\"><code class=\"language-text\">window</code></a> in a browser.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function f1() {\n  return this;\n}\n\n// In a browser:\nf1() === window; // true\n\n// In Node:\nf1() === globalThis; // true</code></pre></div>\n<p>In strict mode, however, if the value of <code class=\"language-text\">this</code> is not set when entering an execution context, it remains as <code class=\"language-text\">undefined</code>, as shown in the following example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function f2() {\n  'use strict'; // see strict mode\n  return this;\n}\n\nf2() === undefined; // true</code></pre></div>\n<p><strong>Note:</strong> In the second example, <code class=\"language-text\">this</code> should be <a href=\"../global_objects/undefined\"><code class=\"language-text\">undefined</code></a>, because <code class=\"language-text\">f2</code> was called directly and not as a method or property of an object (e.g. <code class=\"language-text\">window.f2()</code>). This feature wasn't implemented in some browsers when they first started to support <a href=\"../strict_mode\">strict mode</a>. As a result, they incorrectly returned the <code class=\"language-text\">window</code> object.</p>\n<p>To set the value of <code class=\"language-text\">this</code> to a particular value when calling a function, use <a href=\"../global_objects/function/call\"><code class=\"language-text\">call()</code></a>, or <a href=\"../global_objects/function/apply\"><code class=\"language-text\">apply()</code></a> as in the examples below.</p>\n<h3>Class context</h3>\n<p>The behavior of <code class=\"language-text\">this</code> in <a href=\"../classes\">classes</a> and functions is similar, since classes are functions under the hood. But there are some differences and caveats.</p>\n<p>Within a class constructor, <code class=\"language-text\">this</code> is a regular object. All non-static methods within the class are added to the prototype of <code class=\"language-text\">this</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Example {\n  constructor() {\n    const proto = Object.getPrototypeOf(this);\n    console.log(Object.getOwnPropertyNames(proto));\n  }\n  first(){}\n  second(){}\n  static third(){}\n}\n\nnew Example(); // ['constructor', 'first', 'second']</code></pre></div>\n<p><strong>Note:</strong> Static methods are not properties of <code class=\"language-text\">this</code>. They are properties of the class itself.</p>\n<h3>Derived classes</h3>\n<p>Unlike base class constructors, derived constructors have no initial <code class=\"language-text\">this</code> binding. Calling <a href=\"super\"><code class=\"language-text\">super()</code></a> creates a <code class=\"language-text\">this</code> binding within the constructor and essentially has the effect of evaluating the following line of code, where Base is the inherited class:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this = new Base();</code></pre></div>\n<p><strong>Warning:</strong> Referring to <code class=\"language-text\">this</code> before calling <code class=\"language-text\">super()</code> will throw an error.</p>\n<p>Derived classes must not return before calling <code class=\"language-text\">super()</code>, unless they return an <code class=\"language-text\">Object</code> or have no constructor at all.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Base {}\nclass Good extends Base {}\nclass AlsoGood extends Base {\n  constructor() {\n    return {a: 5};\n  }\n}\nclass Bad extends Base {\n  constructor() {}\n}\n\nnew Good();\nnew AlsoGood();\nnew Bad(); // ReferenceError</code></pre></div>\n<h2>Examples</h2>\n<h3>this in function contexts</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// An object can be passed as the first argument to call or apply and this will be bound to it.\nvar obj = {a: 'Custom'};\n\n// We declare a variable and the variable is assigned to the global window as its property.\nvar a = 'Global';\n\nfunction whatsThis() {\n  return this.a;  // The value of this is dependent on how the function is called\n}\n\nwhatsThis();          // 'Global' as this in the function isn't set, so it defaults to the global/window object\nwhatsThis.call(obj);  // 'Custom' as this in the function is set to obj\nwhatsThis.apply(obj); // 'Custom' as this in the function is set to obj</code></pre></div>\n<h3>this and object conversion</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function add(c, d) {\n  return this.a + this.b + c + d;\n}\n\nvar o = {a: 1, b: 3};\n\n// The first parameter is the object to use as\n// 'this', subsequent parameters are passed as\n// arguments in the function call\nadd.call(o, 5, 7); // 16\n\n// The first parameter is the object to use as\n// 'this', the second is an array whose\n// members are used as the arguments in the function call\nadd.apply(o, [10, 20]); // 34</code></pre></div>\n<p>Note that in non-strict mode, with <code class=\"language-text\">call</code> and <code class=\"language-text\">apply</code>, if the value passed as <code class=\"language-text\">this</code> is not an object, an attempt will be made to convert it to an object. Values <code class=\"language-text\">null</code> and <code class=\"language-text\">undefined</code> become the global object. Primitives like <code class=\"language-text\">7</code> or <code class=\"language-text\">'foo'</code> will be converted to an Object using the related constructor, so the primitive number <code class=\"language-text\">7</code> is converted to an object as if by <code class=\"language-text\">new Number(7)</code> and the string <code class=\"language-text\">'foo'</code> to an object as if by <code class=\"language-text\">new String('foo')</code>, e.g.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function bar() {\n  console.log(Object.prototype.toString.call(this));\n}\n\nbar.call(7);     // [object Number]\nbar.call('foo'); // [object String]\nbar.call(undefined); // [object global]</code></pre></div>\n<h3>The <code class=\"language-text\">bind</code> method</h3>\n<p>ECMAScript 5 introduced <a href=\"../global_objects/function/bind\"><code class=\"language-text\">Function.prototype.bind()</code></a>. Calling <code class=\"language-text\">f.bind(someObject)</code> creates a new function with the same body and scope as <code class=\"language-text\">f</code>, but where <code class=\"language-text\">this</code> occurs in the original function, in the new function it is permanently bound to the first argument of <code class=\"language-text\">bind</code>, regardless of how the function is being used.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function f() {\n  return this.a;\n}\n\nvar g = f.bind({a: 'azerty'});\nconsole.log(g()); // azerty\n\nvar h = g.bind({a: 'yoo'}); // bind only works once!\nconsole.log(h()); // azerty\n\nvar o = {a: 37, f: f, g: g, h: h};\nconsole.log(o.a, o.f(), o.g(), o.h()); // 37,37, azerty, azerty</code></pre></div>\n<h3>Arrow functions</h3>\n<p>In <a href=\"../functions/arrow_functions\">arrow functions</a>, <code class=\"language-text\">this</code> retains the value of the enclosing lexical context's <code class=\"language-text\">this</code>. In global code, it will be set to the global object:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var globalObject = this;\nvar foo = (() => this);\nconsole.log(foo() === globalObject); // true</code></pre></div>\n<p><strong>Note:</strong> If <code class=\"language-text\">this</code> arg is passed to <code class=\"language-text\">call</code>, <code class=\"language-text\">bind</code>, or <code class=\"language-text\">apply</code> on invocation of an arrow function it will be ignored. You can still prepend arguments to the call, but the first argument (<code class=\"language-text\">thisArg</code>) should be set to <code class=\"language-text\">null</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Call as a method of an object\nvar obj = {func: foo};\nconsole.log(obj.func() === globalObject); // true\n\n// Attempt to set this using call\nconsole.log(foo.call(obj) === globalObject); // true\n\n// Attempt to set this using bind\nfoo = foo.bind(obj);\nconsole.log(foo() === globalObject); // true</code></pre></div>\n<p>No matter what, <code class=\"language-text\">foo</code>'s <code class=\"language-text\">this</code> is set to what it was when it was created (in the example above, the global object). The same applies to arrow functions created inside other functions: their <code class=\"language-text\">this</code> remains that of the enclosing lexical context.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Create obj with a method bar that returns a function that\n// returns its this. The returned function is created as\n// an arrow function, so its this is permanently bound to the\n// this of its enclosing function. The value of bar can be set\n// in the call, which in turn sets the value of the\n// returned function.\nvar obj = {\n  bar: function() {\n    var x = (() => this);\n    return x;\n  }\n};\n\n// Call bar as a method of obj, setting its this to obj\n// Assign a reference to the returned function to fn\nvar fn = obj.bar();\n\n// Call fn without setting this, would normally default\n// to the global object or undefined in strict mode\nconsole.log(fn() === obj); // true\n\n// But caution if you reference the method of obj without calling it\nvar fn2 = obj.bar;\n// Calling the arrow function's this from inside the bar method()\n// will now return window, because it follows the this from fn2.\nconsole.log(fn2()() == window); // true</code></pre></div>\n<p>In the above, the function (call it anonymous function A) assigned to <code class=\"language-text\">obj.bar</code> returns another function (call it anonymous function B) that is created as an arrow function. As a result, function B's <code class=\"language-text\">this</code> is permanently set to the <code class=\"language-text\">this</code> of <code class=\"language-text\">obj.bar</code> (function A) when called. When the returned function (function B) is called, its <code class=\"language-text\">this</code> will always be what it was set to initially. In the above code example, function B's <code class=\"language-text\">this</code> is set to function A's <code class=\"language-text\">this</code> which is <code class=\"language-text\">obj</code>, so it remains set to <code class=\"language-text\">obj</code> even when called in a manner that would normally set its <code class=\"language-text\">this</code> to <code class=\"language-text\">undefined</code> or the global object (or any other method as in the previous example in the global execution context).</p>\n<h3>As an object method</h3>\n<p>When a function is called as a method of an object, its <code class=\"language-text\">this</code> is set to the object the method is called on.</p>\n<p>In the following example, when <code class=\"language-text\">o.f()</code> is invoked, inside the function <code class=\"language-text\">this</code> is bound to the <code class=\"language-text\">o</code> object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var o = {\n  prop: 37,\n  f: function() {\n    return this.prop;\n  }\n};\n\nconsole.log(o.f()); // 37</code></pre></div>\n<p>Note that this behavior is not at all affected by how or where the function was defined. In the previous example, we defined the function inline as the <code class=\"language-text\">f</code> member during the definition of <code class=\"language-text\">o</code>. However, we could have just as easily defined the function first and later attached it to <code class=\"language-text\">o.f</code>. Doing so results in the same behavior:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var o = {prop: 37};\n\nfunction independent() {\n  return this.prop;\n}\n\no.f = independent;\n\nconsole.log(o.f()); // 37</code></pre></div>\n<p>This demonstrates that it matters only that the function was invoked from the <code class=\"language-text\">f</code> member of <code class=\"language-text\">o</code>.</p>\n<p>Similarly, the <code class=\"language-text\">this</code> binding is only affected by the most immediate member reference. In the following example, when we invoke the function, we call it as a method <code class=\"language-text\">g</code> of the object <code class=\"language-text\">o.b</code>. This time during execution, <code class=\"language-text\">this</code> inside the function will refer to <code class=\"language-text\">o.b</code>. The fact that the object is itself a member of <code class=\"language-text\">o</code> has no consequence; the most immediate reference is all that matters.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">o.b = {g: independent, prop: 42};\nconsole.log(o.b.g()); // 42</code></pre></div>\n<h4><code class=\"language-text\">this</code> on the object's prototype chain</h4>\n<p>The same notion holds true for methods defined somewhere on the object's prototype chain. If the method is on an object's prototype chain, <code class=\"language-text\">this</code> refers to the object the method was called on, as if the method were on the object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var o = {f: function() { return this.a + this.b; }};\nvar p = Object.create(o);\np.a = 1;\np.b = 4;\n\nconsole.log(p.f()); // 5</code></pre></div>\n<p>In this example, the object assigned to the variable <code class=\"language-text\">p</code> doesn't have its own <code class=\"language-text\">f</code> property, it inherits it from its prototype. But it doesn't matter that the lookup for <code class=\"language-text\">f</code> eventually finds a member with that name on <code class=\"language-text\">o</code>; the lookup began as a reference to <code class=\"language-text\">p.f</code>, so <code class=\"language-text\">this</code> inside the function takes the value of the object referred to as <code class=\"language-text\">p</code>. That is, since <code class=\"language-text\">f</code> is called as a method of <code class=\"language-text\">p</code>, its <code class=\"language-text\">this</code> refers to <code class=\"language-text\">p</code>. This is an interesting feature of JavaScript's prototype inheritance.</p>\n<h4><code class=\"language-text\">this</code> with a getter or setter</h4>\n<p>Again, the same notion holds true when a function is invoked from a getter or a setter. A function used as getter or setter has its <code class=\"language-text\">this</code> bound to the object from which the property is being set or gotten.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function sum() {\n  return this.a + this.b + this.c;\n}\n\nvar o = {\n  a: 1,\n  b: 2,\n  c: 3,\n  get average() {\n    return (this.a + this.b + this.c) / 3;\n  }\n};\n\nObject.defineProperty(o, 'sum', {\n    get: sum, enumerable: true, configurable: true});\n\nconsole.log(o.average, o.sum); // 2, 6</code></pre></div>\n<h3>As a constructor</h3>\n<p>When a function is used as a constructor (with the <a href=\"new\"><code class=\"language-text\">new</code></a> keyword), its <code class=\"language-text\">this</code> is bound to the new object being constructed.</p>\n<p><strong>Note:</strong> While the default for a constructor is to return the object referenced by <code class=\"language-text\">this</code>, it can instead return some other object (if the return value isn't an object, then the <code class=\"language-text\">this</code> object is returned).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/*\n * Constructors work like this:\n *\n * function MyConstructor(){\n *   // Actual function body code goes here.\n *   // Create properties on |this| as\n *   // desired by assigning to them.  E.g.,\n *   this.fum = \"nom\";\n *   // et cetera...\n *\n *   // If the function has a return statement that\n *   // returns an object, that object will be the\n *   // result of the |new| expression.  Otherwise,\n *   // the result of the expression is the object\n *   // currently bound to |this|\n *   // (i.e., the common case most usually seen).\n * }\n */\n\nfunction C() {\n  this.a = 37;\n}\n\nvar o = new C();\nconsole.log(o.a); // 37\n\nfunction C2() {\n  this.a = 37;\n  return {a: 38};\n}\n\no = new C2();\nconsole.log(o.a); // 38</code></pre></div>\n<p>In the last example (<code class=\"language-text\">C2</code>), because an object was returned during construction, the new object that <code class=\"language-text\">this</code> was bound to gets discarded. (This essentially makes the statement \"<code class=\"language-text\">this.a = 37;</code>\" dead code. It's not exactly dead because it gets executed, but it can be eliminated with no outside effects.)</p>\n<h3>As a DOM event handler</h3>\n<p>When a function is used as an event handler, its <code class=\"language-text\">this</code> is set to the element on which the listener is placed (some browsers do not follow this convention for listeners added dynamically with methods other than <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener\"><code class=\"language-text\">addEventListener()</code></a>).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// When called as a listener, turns the related element blue\nfunction bluify(e) {\n  // Always true\n  console.log(this === e.currentTarget);\n  // true when currentTarget and target are the same object\n  console.log(this === e.target);\n  this.style.backgroundColor = '#A5D9F3';\n}\n\n// Get a list of every element in the document\nvar elements = document.getElementsByTagName('*');\n\n// Add bluify as a click listener so when the\n// element is clicked on, it turns blue\nfor (var i = 0; i &lt; elements.length; i++) {\n  elements[i].addEventListener('click', bluify, false);\n}</code></pre></div>\n<h3>In an inline event handler</h3>\n<p>When the code is called from an inline <a href=\"https://developer.mozilla.org/en-US/docs/Web/Events/Event_handlers\">on-event handler</a>, its <code class=\"language-text\">this</code> is set to the DOM element on which the listener is placed:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;button onclick=\"alert(this.tagName.toLowerCase());\">\n  Show this\n&lt;/button></code></pre></div>\n<p>The above alert shows <code class=\"language-text\">button</code>. Note however that only the outer code has its <code class=\"language-text\">this</code> set this way:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;button onclick=\"alert((function() { return this; })());\">\n  Show inner this\n&lt;/button></code></pre></div>\n<p>In this case, the inner function's <code class=\"language-text\">this</code> isn't set so it returns the global/window object (i.e. the default object in non-strict mode where <code class=\"language-text\">this</code> isn't set by the call).</p>\n<h3>this in classes</h3>\n<p>Just like with regular functions, the value of <code class=\"language-text\">this</code> within methods depends on how they are called. Sometimes it is useful to override this behavior so that <code class=\"language-text\">this</code> within classes always refers to the class instance. To achieve this, bind the class methods in the constructor:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Car {\n  constructor() {\n    // Bind sayBye but not sayHi to show the difference\n    this.sayBye = this.sayBye.bind(this);\n  }\n  sayHi() {\n    console.log(`Hello from ${this.name}`);\n  }\n  sayBye() {\n    console.log(`Bye from ${this.name}`);\n  }\n  get name() {\n    return 'Ferrari';\n  }\n}\n\nclass Bird {\n  get name() {\n    return 'Tweety';\n  }\n}\n\nconst car = new Car();\nconst bird = new Bird();\n\n// The value of 'this' in methods depends on their caller\ncar.sayHi(); // Hello from Ferrari\nbird.sayHi = car.sayHi;\nbird.sayHi(); // Hello from Tweety\n\n// For bound methods, 'this' doesn't depend on the caller\nbird.sayBye = car.sayBye;\nbird.sayBye();  // Bye from Ferrari</code></pre></div>\n<p><strong>Note:</strong> Classes are always strict mode code. Calling methods with an undefined <code class=\"language-text\">this</code> will throw an error.</p>"},{"url":"/docs/leetcode/GeneratParentheses/","relativePath":"docs/leetcode/GeneratParentheses.md","relativeDir":"docs/leetcode","base":"GeneratParentheses.md","name":"GeneratParentheses","frontmatter":{"title":"Generate Parentheses","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"  Generate Parentheses ","description":" Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. ","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/generate-parentheses/description/\">22. Generate Parentheses</a></h2>\n<h3>Problem:</h3>\n<p>Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.</p>\n<p>For example, given n = 3, a solution set is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[\n  \"((()))\",\n  \"(()())\",\n  \"(())()\",\n  \"()(())\",\n  \"()()()\"\n]</code></pre></div>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<p>Recursive DFS backtracking.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} n\n * @return {string[]}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">generateParenthesis</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">dfs</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">dfs</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> nopen<span class=\"token punctuation\">,</span> nclose<span class=\"token punctuation\">,</span> path<span class=\"token punctuation\">,</span> result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>nopen <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">dfs</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> nopen <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> nclose<span class=\"token punctuation\">,</span> path <span class=\"token operator\">+</span> <span class=\"token string\">'('</span><span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>nclose <span class=\"token operator\">&lt;</span> nopen<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">dfs</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> nopen<span class=\"token punctuation\">,</span> nclose <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> path <span class=\"token operator\">+</span> <span class=\"token string\">')'</span><span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h4>TWO</h4>\n<p>BFS.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} n\n * @return {string[]}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">generateParenthesis</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> <span class=\"token string\">'('</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">open</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">close</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> path<span class=\"token punctuation\">,</span> open<span class=\"token punctuation\">,</span> close <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>open <span class=\"token operator\">+</span> close <span class=\"token operator\">===</span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> path<span class=\"token punctuation\">,</span> open<span class=\"token punctuation\">,</span> close <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>open <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> path <span class=\"token operator\">+</span> <span class=\"token string\">'('</span><span class=\"token punctuation\">,</span>\n                <span class=\"token literal-property property\">open</span><span class=\"token operator\">:</span> open <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n                close\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>close <span class=\"token operator\">&lt;</span> open<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> path <span class=\"token operator\">+</span> <span class=\"token string\">')'</span><span class=\"token punctuation\">,</span>\n                open<span class=\"token punctuation\">,</span>\n                <span class=\"token literal-property property\">close</span><span class=\"token operator\">:</span> close <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> x<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/DividTwIntegers/","relativePath":"docs/leetcode/DividTwIntegers.md","relativeDir":"docs/leetcode","base":"DividTwIntegers.md","name":"DividTwIntegers","frontmatter":{"title":"Divide Two Integers","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Divide Two Integers","description":"Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/divide-two-integers/description/\">29. Divide Two Integers</a></h2>\n<h3>Problem:</h3>\n<p>Given two integers <code class=\"language-text\">dividend</code> and <code class=\"language-text\">divisor</code>, divide two integers without using multiplication, division and mod operator.</p>\n<p>Return the quotient after dividing <code class=\"language-text\">dividend</code> by <code class=\"language-text\">divisor</code>.</p>\n<p>The integer division should truncate toward zero.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: dividend = 10, divisor = 3\nOutput: 3</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"txt\"><pre class=\"language-txt\"><code class=\"language-txt\">Input: dividend = 7, divisor = -3\nOutput: -2</code></pre></div>\n<p><strong>Note:</strong></p>\n<ul>\n<li>Both dividend and divisor will be 32-bit signed integers.</li>\n<li>The divisor will never be 0.</li>\n<li>Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.</li>\n</ul>\n<h3>Solution:</h3>\n<p>Every decimal number can be represented as <code class=\"language-text\">a0*2^0 + a1*2^1 + a2*2^2 + ... + an*2^n</code>.</p>\n<p>Replace multiplication and division with binary shifting.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} dividend\n * @param {number} divisor\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">divide</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">dividend<span class=\"token punctuation\">,</span> divisor</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>divisor <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>divisor <span class=\"token operator\">===</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">&amp;&amp;</span> dividend <span class=\"token operator\">&lt;</span> <span class=\"token operator\">-</span><span class=\"token number\">2147483647</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> dividend <span class=\"token operator\">></span> <span class=\"token number\">2147483647</span> <span class=\"token operator\">||</span> dividend <span class=\"token operator\">&lt;</span> <span class=\"token operator\">-</span><span class=\"token number\">2147483648</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">2147483647</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> isNegative <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>dividend <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> divisor <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>dividend <span class=\"token operator\">>=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> divisor <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> pDividend <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span>dividend<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> pDivisor <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span>divisor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>dividend <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> pDividend <span class=\"token operator\">&lt;</span> pDivisor<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> doubling <span class=\"token operator\">=</span> pDivisor<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>doubling <span class=\"token operator\">&lt;</span> pDividend <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>doubling <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;&lt;</span> <span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        doubling <span class=\"token operator\">&lt;&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        count <span class=\"token operator\">&lt;&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>doubling <span class=\"token operator\">></span> pDividend<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        doubling <span class=\"token operator\">>>>=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        count <span class=\"token operator\">>>>=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> count <span class=\"token operator\">+</span> <span class=\"token function\">divide</span><span class=\"token punctuation\">(</span>pDividend <span class=\"token operator\">-</span> doubling<span class=\"token punctuation\">,</span> pDivisor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> isNegative <span class=\"token operator\">?</span> <span class=\"token operator\">-</span>result <span class=\"token operator\">:</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/MediaoTwSorteArrays/","relativePath":"docs/leetcode/MediaoTwSorteArrays.md","relativeDir":"docs/leetcode","base":"MediaoTwSorteArrays.md","name":"MediaoTwSorteArrays","frontmatter":{"title":"Median of Two Sorted Arrays","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Median of Two Sorted Arrays","description":"There are two sorted arrays nums1 and nums2 of size m and n respectively.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/median-of-two-sorted-arrays/description/\">4. Median of Two Sorted Arrays</a></h2>\n<h3>Problem:</h3>\n<p>There are two sorted arrays nums1 and nums2 of size m and n respectively.</p>\n<p>Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).</p>\n<p>Example 1:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">nums1 = [1, 3]\nnums2 = [2]\n\nThe median is 2.0</code></pre></div>\n<p>Example 2:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">nums1 = [1, 2]\nnums2 = [3, 4]\n\nThe median is (2 + 3)/2 = 2.5</code></pre></div>\n<h3>Solution:</h3>\n<p>O(log (m+n)) means half of the sequence is ruled out on each loop. So obviously we need binary search.</p>\n<p>To do it on two sorted arrays, we need a formula to guide division.</p>\n<p>Let <code class=\"language-text\">nums3</code> be the sorted array combining all the items in <code class=\"language-text\">nums1</code> and <code class=\"language-text\">nums2</code>.</p>\n<p>If <code class=\"language-text\">nums2[j-1] &lt;= nums1[i] &lt;= nums2[j]</code>, then we know <code class=\"language-text\">nums1[i]</code> is at <code class=\"language-text\">num3[i+j]</code>. Same goes <code class=\"language-text\">nums1[i-1] &lt;= nums2[j] &lt;= nums1[i]</code>.</p>\n<p>Let <code class=\"language-text\">k</code> be <code class=\"language-text\">⌊(m+n-1)/2⌋</code>. We need to find <code class=\"language-text\">nums3[k]</code> (and also <code class=\"language-text\">nums3[k+1]</code> if m+n is even).</p>\n<p>Let <code class=\"language-text\">i + j = k</code>, if we find <code class=\"language-text\">nums2[j-1] &lt;= nums1[i] &lt;= nums2[j]</code> or <code class=\"language-text\">nums1[i-1] &lt;= nums2[j] &lt;= nums1[i]</code>, then we got <code class=\"language-text\">k</code>.</p>\n<p>Otherwise, if <code class=\"language-text\">nums1[i] &lt;= nums2[j]</code> then we know <code class=\"language-text\">nums1[i] &lt; nums2[j-1]</code> (because we did not find <code class=\"language-text\">k</code>).</p>\n<ul>\n<li>There are <code class=\"language-text\">i</code> items before <code class=\"language-text\">nums1[i]</code>, and <code class=\"language-text\">j-1</code> items brefor <code class=\"language-text\">nums2[j-1]</code>, which means <code class=\"language-text\">nums1[0...i]</code> are before <code class=\"language-text\">nums3[i+j-1]</code>. So we now know <code class=\"language-text\">nums1[0...i] &lt; nums3[k]</code>. They can be safely discarded.</li>\n<li></li>\n<li>We Also have <code class=\"language-text\">nums1[i] &lt; nums2[j]</code>, which means <code class=\"language-text\">nums2[j...n)</code> are after <code class=\"language-text\">nums3[i+j]</code>. So <code class=\"language-text\">nums2[j...n) > nums3[k]</code>.</li>\n</ul>\n<p>Same goes <code class=\"language-text\">nums1[i-1] &lt;= nums2[j] &lt;= nums1[i]</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">findMedianSortedArrays</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">nums1<span class=\"token punctuation\">,</span> nums2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> mid <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>nums1<span class=\"token punctuation\">.</span>length <span class=\"token operator\">+</span> nums2<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">|</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>nums1<span class=\"token punctuation\">.</span>length <span class=\"token operator\">+</span> nums2<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token function\">_find</span><span class=\"token punctuation\">(</span>nums1<span class=\"token punctuation\">,</span> nums2<span class=\"token punctuation\">,</span> mid<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">_find</span><span class=\"token punctuation\">(</span>nums1<span class=\"token punctuation\">,</span> nums2<span class=\"token punctuation\">,</span> mid <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token function\">_find</span><span class=\"token punctuation\">(</span>nums1<span class=\"token punctuation\">,</span> nums2<span class=\"token punctuation\">,</span> mid<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">_find</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">nums1<span class=\"token punctuation\">,</span> nums2<span class=\"token punctuation\">,</span> k</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>nums1<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> nums2<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// So that the `i` below is always smalller than k,</span>\n        <span class=\"token comment\">// which makes `j` always non-negative</span>\n        <span class=\"token punctuation\">[</span>nums1<span class=\"token punctuation\">,</span> nums2<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>nums2<span class=\"token punctuation\">,</span> nums1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">let</span> s1 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> s2 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> e1 <span class=\"token operator\">=</span> nums1<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> e2 <span class=\"token operator\">=</span> nums2<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>s1 <span class=\"token operator\">&lt;</span> e1 <span class=\"token operator\">||</span> s2 <span class=\"token operator\">&lt;</span> e2<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> i <span class=\"token operator\">=</span> s1 <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>e1 <span class=\"token operator\">-</span> s1<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">|</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> j <span class=\"token operator\">=</span> k <span class=\"token operator\">-</span> i<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> ni <span class=\"token operator\">=</span> i <span class=\"token operator\">>=</span> e1 <span class=\"token operator\">?</span> <span class=\"token number\">Infinity</span> <span class=\"token operator\">:</span> nums1<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> nj <span class=\"token operator\">=</span> j <span class=\"token operator\">>=</span> e2 <span class=\"token operator\">?</span> <span class=\"token number\">Infinity</span> <span class=\"token operator\">:</span> nums2<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> ni_1 <span class=\"token operator\">=</span> i <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span> <span class=\"token operator\">:</span> nums1<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> nj_1 <span class=\"token operator\">=</span> j <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span> <span class=\"token operator\">:</span> nums2<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>nj_1 <span class=\"token operator\">&lt;=</span> ni <span class=\"token operator\">&amp;&amp;</span> ni <span class=\"token operator\">&lt;=</span> nj<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> ni<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>ni_1 <span class=\"token operator\">&lt;=</span> nj <span class=\"token operator\">&amp;&amp;</span> nj <span class=\"token operator\">&lt;=</span> ni<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> nj<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>ni <span class=\"token operator\">&lt;=</span> nj<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            s1 <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            e2 <span class=\"token operator\">=</span> j<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            s2 <span class=\"token operator\">=</span> j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            e1 <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/LetteCombinationoPhonNumber/","relativePath":"docs/leetcode/LetteCombinationoPhonNumber.md","relativeDir":"docs/leetcode","base":"LetteCombinationoPhonNumber.md","name":"LetteCombinationoPhonNumber","frontmatter":{"title":"Letter Combinations of a Phone Number","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Letter Combinations of a Phone Number","description":"Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/\">17. Letter Combinations of a Phone Number</a></h2>\n<h3>Problem:</h3>\n<p>Given a string containing digits from <code class=\"language-text\">2-9</code> inclusive, return all possible letter combinations that the number could represent.</p>\n<p>A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.</p>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Telephone-keypad2.svg/200px-Telephone-keypad2.svg.png\" alt=\"200px-Telephone-keypad2\"></p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"23\"\nOutput: [\"ad\", \"ae\", \"af\", \"bd\", \"be\", \"bf\", \"cd\", \"ce\", \"cf\"].</code></pre></div>\n<p><strong>Note:</strong></p>\n<p>Although the above answer is in lexicographical order, your answer could be in any order you want.</p>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<p>JavaScript specific optimization.</p>\n<p><code class=\"language-text\">Array.prototype.push</code> accepts arbitrary arguments which enables tighter loops.</p>\n<p>Also, appending string is faster than prepending.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} digits\n * @return {string[]}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">letterCombinations</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">digits</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>digits<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> letters <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'d'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'e'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'f'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'g'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'h'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'i'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'j'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'k'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'l'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'m'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'o'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'p'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'q'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'r'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'s'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'t'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'u'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'v'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'w'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'x'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'y'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'z'</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">''</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> digits<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> letters<span class=\"token punctuation\">[</span>digits<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> newResult <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        arr<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> newResult<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>result<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">r</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> r <span class=\"token operator\">+</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        result <span class=\"token operator\">=</span> newResult<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>General recursive DFS solution.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} digits\n * @return {string[]}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">letterCombinations</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">digits</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> letters <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token string\">'abc'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'def'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'ghi'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'jkl'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mno'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pqrs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tuv'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'wxyz'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>digits<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">dfs</span><span class=\"token punctuation\">(</span>digits<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> letters<span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">dfs</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">digits<span class=\"token punctuation\">,</span> idigit<span class=\"token punctuation\">,</span> path<span class=\"token punctuation\">,</span> letters<span class=\"token punctuation\">,</span> result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>idigit <span class=\"token operator\">>=</span> digits<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">const</span> str <span class=\"token operator\">=</span> letters<span class=\"token punctuation\">[</span>digits<span class=\"token punctuation\">[</span>idigit<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> str<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">dfs</span><span class=\"token punctuation\">(</span>digits<span class=\"token punctuation\">,</span> idigit <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> path <span class=\"token operator\">+</span> str<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> letters<span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/LongesCommoPrefix/","relativePath":"docs/leetcode/LongesCommoPrefix.md","relativeDir":"docs/leetcode","base":"LongesCommoPrefix.md","name":"LongesCommoPrefix","frontmatter":{"title":"Leetcode","weight":0,"excerpt":"feel free to try the examples","seo":{"title":" Longest Common Prefix","description":"Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string ","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/longest-common-prefix/description/\">14. Longest Common Prefix</a></h2>\n<h3>Problem:</h3>\n<p>Write a function to find the longest common prefix string amongst an array of strings.</p>\n<p>If there is no common prefix, return an empty string <code class=\"language-text\">\"\"</code>.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [\"flower\",\"flow\",\"flight\"]\nOutput: \"fl\"</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [\"dog\",\"racecar\",\"car\"]\nOutput: \"\"\nExplanation: There is no common prefix among the input strings.</code></pre></div>\n<p><strong>Note:</strong></p>\n<p>All given inputs are in lowercase letters <code class=\"language-text\">a-z</code>.</p>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<p>JavaScript specific solution. Get the min len then narrow down the prefix.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string[]} strs\n * @return {string}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">longestCommonPrefix</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">strs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> minLen <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>strs<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> s<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> anyStr <span class=\"token operator\">=</span> strs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>minLen<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> prefix <span class=\"token operator\">=</span> anyStr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> minLen<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">.</span><span class=\"token function\">every</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> s<span class=\"token punctuation\">.</span><span class=\"token function\">startsWith</span><span class=\"token punctuation\">(</span>prefix<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string[]} strs\n * @return {string}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">longestCommonPrefix</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">strs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">.</span><span class=\"token function\">every</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> s<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> s<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> strs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> strs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>THREE</h4>\n<p>General solution. Build up the prefix.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string[]} strs\n * @return {string}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">longestCommonPrefix</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">strs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> prefix <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> c <span class=\"token operator\">=</span> strs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>c<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> strs<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> c<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n            prefix <span class=\"token operator\">+=</span> c<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/NexPermutation/","relativePath":"docs/leetcode/NexPermutation.md","relativeDir":"docs/leetcode","base":"NexPermutation.md","name":"NexPermutation","frontmatter":{"title":"Next Permutation","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Next Permutation","description":"Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/next-permutation/description/\">31. Next Permutation</a></h2>\n<h3>Problem:</h3>\n<p>Implement <strong>next permutation</strong>, which rearranges numbers into the lexicographically next greater permutation of numbers.</p>\n<p>If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).</p>\n<p>The replacement must be <strong>in-place</strong> and use only constant extra memory.</p>\n<p>Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.</p>\n<p><code class=\"language-text\">1,2,3</code> → <code class=\"language-text\">1,3,2</code><br>\n<code class=\"language-text\">3,2,1</code> → <code class=\"language-text\">1,2,3</code><br>\n<code class=\"language-text\">1,1,5</code> → <code class=\"language-text\">1,5,1</code></p>\n<h3>Solution:</h3>\n<p>Observe a few longer examples and the pattern is self-evident.</p>\n<p>Divide the list into two parts. The first half must be incremental and the second half must be decremental.</p>\n<p>Reverse the second half and find the smallest number in it that is greater the last number of the first half.</p>\n<p>Swap the two.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} nums\n * @return {void} Do not return anything, modify nums in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">nextPermutation</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">nums</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> len <span class=\"token operator\">=</span> nums<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>len <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> len <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>nums<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> nums<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> t<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> s <span class=\"token operator\">=</span> i<span class=\"token punctuation\">,</span> e <span class=\"token operator\">=</span> len <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> s <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">;</span> s<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> e<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                t <span class=\"token operator\">=</span> nums<span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                nums<span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> nums<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                nums<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> t<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> len <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>nums<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;=</span> nums<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                j<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            t <span class=\"token operator\">=</span> nums<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            nums<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> nums<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            nums<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> t<span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        nums<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/RemovDuplicatefroSorteArray/","relativePath":"docs/leetcode/RemovDuplicatefroSorteArray.md","relativeDir":"docs/leetcode","base":"RemovDuplicatefroSorteArray.md","name":"RemovDuplicatefroSorteArray","frontmatter":{"title":"Remove Duplicates from Sorted Array","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Remove Duplicates from Sorted Array","description":"Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/\">26. Remove Duplicates from Sorted Array</a></h2>\n<h3>Problem:</h3>\n<p>Given a sorted array <em>nums</em>, remove the duplicates <a href=\"https://en.wikipedia.org/wiki/In-place_algorithm\"><strong>in-place</strong></a> such that each element appear only <em>once</em> and return the new length.</p>\n<p>Do not allocate extra space for another array, you must do this by <strong>modifying the input array in-place</strong> with O(1) extra memory.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Given nums = [1,1,2],\n\nYour function should return length = 2, with the first two elements of nums being 1 and 2 respectively.\n\nIt doesn't matter what you leave beyond the returned length.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Given nums = [0,0,1,1,1,2,2,3,3,4],\n\nYour function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively.\n\nIt doesn't matter what values are set beyond the returned length.</code></pre></div>\n<p><strong>Clarification:</strong></p>\n<p>Confused why the returned value is an integer but your answer is an array?</p>\n<p>Note that the input array is passed in by <strong>reference</strong>, which means modification to the input array will be known to the caller as well.</p>\n<p>Internally you can think of this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// nums is passed in by reference. (i.e., without making a copy)\nint len = removeDuplicates(nums);\n\n// any modification to nums in your function would be known by the caller.\n// using the length returned by your function, it prints the first len elements.\nfor (int i = 0; i &lt; len; i++) {\n    print(nums[i]);\n}</code></pre></div>\n<h3>Solution:</h3>\n<p>The result array can only be shorter. That is why we can build the array in-place with the new length.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} nums\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">removeDuplicates</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">nums</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> len <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> nums<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>nums<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> nums<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            nums<span class=\"token punctuation\">[</span>len<span class=\"token operator\">++</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> nums<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> len<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/PalindromNumber/","relativePath":"docs/leetcode/PalindromNumber.md","relativeDir":"docs/leetcode","base":"PalindromNumber.md","name":"PalindromNumber","frontmatter":{"title":"Palindrome Number","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Palindrome Number","description":"Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/palindrome-number/description/\">9. Palindrome Number</a></h2>\n<h3>Problem:</h3>\n<p>Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: 121\nOutput: true</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: -121\nOutput: false\nExplanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: 10\nOutput: false\nExplanation: Reads 01 from right to left. Therefore it is not a palindrome.</code></pre></div>\n<p><strong>Follow up:</strong></p>\n<p>Coud you solve it without converting the integer to a string?</p>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<p>Easy to write but slow since it generates an array.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} x\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">x</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> x <span class=\"token operator\">==</span> <span class=\"token function\">String</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>A bit faster.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} x\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">x</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> s <span class=\"token operator\">=</span> <span class=\"token function\">String</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> j<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> s<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>THREE</h4>\n<p>General solution. Combining <a href=\"./007.%20Reverse%20Integer.md\">7. Reverse Integer</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} x\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">x</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>x <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> x <span class=\"token operator\">===</span> <span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/**\n * @param {number} x\n * @return {number}\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        result <span class=\"token operator\">=</span> result <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>x <span class=\"token operator\">%</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        x <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>x <span class=\"token operator\">/</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">|</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/RegulaExpressioMatching/","relativePath":"docs/leetcode/RegulaExpressioMatching.md","relativeDir":"docs/leetcode","base":"RegulaExpressioMatching.md","name":"RegulaExpressioMatching","frontmatter":{"title":"Regular Expression Matching","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Regular Expression Matching","description":"Given an input string (s) and a pattern (p), implement regular expression matching","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/regular-expression-matching/description/\">10. Regular Expression Matching</a></h2>\n<h3>Problem:</h3>\n<p>Given an input string (<code class=\"language-text\">s</code>) and a pattern (<code class=\"language-text\">p</code>), implement regular expression matching with support for <code class=\"language-text\">'.'</code> and <code class=\"language-text\">'*'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'.' Matches any single character.\n'*' Matches zero or more of the preceding element.</code></pre></div>\n<p>The matching should cover the <strong>entire</strong> input string (not partial).</p>\n<p><strong>Note:</strong></p>\n<p><code class=\"language-text\">s</code> could be empty and contains only lowercase letters <code class=\"language-text\">a-z</code>.\n<code class=\"language-text\">p</code> could be empty and contains only lowercase letters <code class=\"language-text\">a-z</code>, and characters like <code class=\"language-text\">.</code> or <code class=\"language-text\">*</code>.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\ns = \"aa\"\np = \"a\"\nOutput: false\nExplanation: \"a\" does not match the entire string \"aa\".</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\ns = \"aa\"\np = \"a*\"\nOutput: true\nExplanation: '*' means zero or more of the precedeng element, 'a'. Therefore, by repeating 'a' once, it becomes \"aa\".</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\ns = \"ab\"\np = \".*\"\nOutput: true\nExplanation: \".*\" means \"zero or more (*) of any character (.)\".</code></pre></div>\n<p><strong>Example 4:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\ns = \"aab\"\np = \"c*a*b\"\nOutput: true\nExplanation: c can be repeated 0 times, a can be repeated 1 time. Therefore it matches \"aab\".</code></pre></div>\n<p><strong>Example 5:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\ns = \"mississippi\"\np = \"mis*is*p*.\"\nOutput: false</code></pre></div>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<p>Cheating with real RegExp matching.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @param {string} p\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isMatch</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s<span class=\"token punctuation\">,</span> p</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'*'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">RegExp</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">^</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>p<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">$</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>Let f(i, j) be the matching result of s[0...i) and p[0...j).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span>\n    j <span class=\"token operator\">==</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> <span class=\"token comment\">// empty</span>\n    p<span class=\"token punctuation\">[</span>j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token string\">'*'</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> j<span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// matches 0 time, which matches empty string</span>\n\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span> <span class=\"token comment\">// pattern must cover the entire input string</span>\n\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span>\n    <span class=\"token keyword\">if</span> p<span class=\"token punctuation\">[</span>j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token string\">'.'</span>\n        <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> p<span class=\"token punctuation\">[</span>j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token string\">'*'</span>\n        <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> j<span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token comment\">// matches 0 time</span>\n        <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">[</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> p<span class=\"token punctuation\">[</span>j<span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> p<span class=\"token punctuation\">[</span>j<span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// matches 1 or multiple times</span>\n    <span class=\"token keyword\">else</span>\n        <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> s<span class=\"token punctuation\">[</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> p<span class=\"token punctuation\">[</span>j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @param {string} p\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isMatch</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s<span class=\"token punctuation\">,</span> p</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'*'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> dp <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;=</span> p<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        dp<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> p<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'*'</span> <span class=\"token operator\">&amp;&amp;</span> dp<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> s<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;=</span> p<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">case</span> <span class=\"token string\">'.'</span><span class=\"token operator\">:</span>\n                    dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> dp<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">case</span> <span class=\"token string\">'*'</span><span class=\"token operator\">:</span>\n                    dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>dp<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'.'</span> <span class=\"token operator\">||</span> s<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> p<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n                    dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> dp<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> s<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> p<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>dp<span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>p<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/RemovNtNodFroEnoList/","relativePath":"docs/leetcode/RemovNtNodFroEnoList.md","relativeDir":"docs/leetcode","base":"RemovNtNodFroEnoList.md","name":"RemovNtNodFroEnoList","frontmatter":{"title":"Remove Nth Node From End of List","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Remove Nth Node From End of List","description":"Given a linked list, remove the n-th node from the end of list and return its head.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/\">19. Remove Nth Node From End of List</a></h2>\n<h3>Problem:</h3>\n<p>Given a linked list, remove the <em>n</em>-th node from the end of list and return its head.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Given linked list: 1->2->3->4->5, and n = 2.\n\nAfter removing the second node from the end, the linked list becomes 1->2->3->5.</code></pre></div>\n<p><strong>Note:</strong></p>\n<p>Given <em>n</em> will always be valid.</p>\n<p><strong>Follow up:</strong></p>\n<p>Could you do this in one pass?</p>\n<h3>Solution:</h3>\n<p>Set a pointer <code class=\"language-text\">p1</code> for iterating, and <code class=\"language-text\">p2</code> which is <code class=\"language-text\">n</code> nodes behind, pointing at the (n+1)-th node from the end of list.</p>\n<p>Boundaries that should be awared of:</p>\n<ul>\n<li><code class=\"language-text\">p2</code> could be one node before <code class=\"language-text\">head</code>, which means the <code class=\"language-text\">head</code> should be removed.</li>\n<li><code class=\"language-text\">p2</code> could be larger than the length of the list (Though the description says <code class=\"language-text\">n</code> will always be valid, we take care of it anyway).</li>\n<li>It should be <code class=\"language-text\">p1.next</code> touches the end rather than <code class=\"language-text\">p1</code> because we want <code class=\"language-text\">p1</code> pointing at the last node.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for singly-linked list.\n * function ListNode(val) {\n *     this.val = val;\n *     this.next = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {ListNode} head\n * @param {number} n\n * @return {ListNode}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">removeNthFromEnd</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">head<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> p1 <span class=\"token operator\">=</span> head<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>p1 <span class=\"token operator\">&amp;&amp;</span> n<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        p1 <span class=\"token operator\">=</span> p1<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>p1<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> n <span class=\"token operator\">?</span> head <span class=\"token operator\">:</span> head<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> p2 <span class=\"token operator\">=</span> head<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>p1<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        p1 <span class=\"token operator\">=</span> p1<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n        p2 <span class=\"token operator\">=</span> p2<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    p2<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> p2<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> head<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/RomatInteger/","relativePath":"docs/leetcode/RomatInteger.md","relativeDir":"docs/leetcode","base":"RomatInteger.md","name":"RomatInteger","frontmatter":{"title":"Roman to Integer","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Roman to Integer","description":"Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/roman-to-integer/description/\">13. Roman to Integer</a></h2>\n<h3>Problem:</h3>\n<p>Roman numerals are represented by seven different symbols: <code class=\"language-text\">I</code>, <code class=\"language-text\">V</code>, <code class=\"language-text\">X</code>, <code class=\"language-text\">L</code>, <code class=\"language-text\">C</code>, <code class=\"language-text\">D</code> and <code class=\"language-text\">M</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Symbol       Value\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000</code></pre></div>\n<p>For example, two is written as <code class=\"language-text\">II</code> in Roman numeral, just two one's added together. Twelve is written as, <code class=\"language-text\">XII</code>, which is simply <code class=\"language-text\">X</code> + <code class=\"language-text\">II</code>. The number twenty seven is written as <code class=\"language-text\">XXVII</code>, which is <code class=\"language-text\">XX</code> + <code class=\"language-text\">V</code> + <code class=\"language-text\">II</code>.</p>\n<p>Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not <code class=\"language-text\">IIII</code>. Instead, the number four is written as <code class=\"language-text\">IV</code>. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as <code class=\"language-text\">IX</code>. There are six instances where subtraction is used:</p>\n<ul>\n<li><code class=\"language-text\">I</code> can be placed before <code class=\"language-text\">V</code> (5) and <code class=\"language-text\">X</code> (10) to make 4 and 9.</li>\n<li><code class=\"language-text\">X</code> can be placed before <code class=\"language-text\">L</code> (50) and <code class=\"language-text\">C</code> (100) to make 40 and 90.</li>\n<li><code class=\"language-text\">C</code> can be placed before <code class=\"language-text\">D</code> (500) and <code class=\"language-text\">M</code> (1000) to make 400 and 900.</li>\n</ul>\n<p>Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"III\"\nOutput: 3</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"IV\"\nOutput: 4</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"IX\"\nOutput: 9</code></pre></div>\n<p><strong>Example 4:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"LVIII\"\nOutput: 58\nExplanation: C = 100, L = 50, XXX = 30 and III = 3.</code></pre></div>\n<p><strong>Example 5:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"MCMXCIV\"\nOutput: 1994\nExplanation: M = 1000, CM = 900, XC = 90 and IV = 4.</code></pre></div>\n<h3>Solution:</h3>\n<p>Normally we just add up the digits, except when the digit is greater than its left (e.g. IV). In that case we need to fallback and remove the last digit then combine the two as new digit. That is why we subtract the last digit twice.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">romanToInt</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> rdigit <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token constant\">I</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n        <span class=\"token constant\">V</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span>\n        <span class=\"token constant\">X</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n        <span class=\"token constant\">L</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span>\n        <span class=\"token constant\">C</span><span class=\"token operator\">:</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span>\n        <span class=\"token constant\">D</span><span class=\"token operator\">:</span> <span class=\"token number\">500</span><span class=\"token punctuation\">,</span>\n        <span class=\"token constant\">M</span><span class=\"token operator\">:</span> <span class=\"token number\">1000</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> lastDigit <span class=\"token operator\">=</span> <span class=\"token number\">Infinity</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> s<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> digit <span class=\"token operator\">=</span> rdigit<span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        result <span class=\"token operator\">+=</span> digit <span class=\"token operator\">&lt;=</span> lastDigit <span class=\"token operator\">?</span> digit <span class=\"token operator\">:</span> digit <span class=\"token operator\">-</span> lastDigit <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n        lastDigit <span class=\"token operator\">=</span> digit<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/SearciRotateSorteArray/","relativePath":"docs/leetcode/SearciRotateSorteArray.md","relativeDir":"docs/leetcode","base":"SearciRotateSorteArray.md","name":"SearciRotateSorteArray","frontmatter":{"title":"Search in Rotated Sorted Array","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Search in Rotated Sorted Array","description":"Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/search-in-rotated-sorted-array/description/\">33. Search in Rotated Sorted Array</a></h2>\n<h3>Problem:</h3>\n<p>Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.</p>\n<p>(i.e., <code class=\"language-text\">[0,1,2,4,5,6,7]</code> might become <code class=\"language-text\">[4,5,6,7,0,1,2]</code>).</p>\n<p>You are given a target value to search. If found in the array return its index, otherwise return <code class=\"language-text\">-1</code>.</p>\n<p>You may assume no duplicate exists in the array.</p>\n<p>Your algorithm's runtime complexity must be in the order of <em>O</em>(log <em>n</em>).</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: nums = [4,5,6,7,0,1,2], target = 0\nOutput: 4</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: nums = [4,5,6,7,0,1,2], target = 3\nOutput: -1</code></pre></div>\n<h3>Solution:</h3>\n<p>Obviously the problem requires binary search.</p>\n<p>The core idea of binary search is to pick the middle item and then decide to keep which half.</p>\n<p>The precondition of it is the array must be sorted.</p>\n<p>But take a closer look and we realize that only one of the two halves needs to be sorted. This is sufficient for us to know if the target is in that half. If not, then it must be in the other.</p>\n<p>Whenever we choose a pivot, it must be in one of the two sorted parts of the rotated array.</p>\n<ul>\n<li>If the pivot is in the left part. We know that the begin of the left part to the pivot are sorted.</li>\n<li>Otherwise the pivot is in the right part. We know that the end of the right part to the pivot are sorted.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">search</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">nums<span class=\"token punctuation\">,</span> target</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> s <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> e <span class=\"token operator\">=</span> nums<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>s <span class=\"token operator\">&lt;=</span> e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> p <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>e <span class=\"token operator\">+</span> s<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">|</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> pivot <span class=\"token operator\">=</span> nums<span class=\"token punctuation\">[</span>p<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pivot <span class=\"token operator\">===</span> target<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> p<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pivot <span class=\"token operator\">&lt;</span> nums<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// right half is sorted</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">></span> pivot <span class=\"token operator\">&amp;&amp;</span> target <span class=\"token operator\">&lt;=</span> nums<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token comment\">// target is inside the right half</span>\n                s <span class=\"token operator\">=</span> p <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                e <span class=\"token operator\">=</span> p <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// left half is sorted</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">&lt;</span> pivot <span class=\"token operator\">&amp;&amp;</span> target <span class=\"token operator\">>=</span> nums<span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token comment\">// target is inside the left half</span>\n                e <span class=\"token operator\">=</span> p <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                s <span class=\"token operator\">=</span> p <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/StrintIntege(atoi)/","relativePath":"docs/leetcode/StrintIntege(atoi).md","relativeDir":"docs/leetcode","base":"StrintIntege(atoi).md","name":"StrintIntege(atoi)","frontmatter":{"title":"String to Integer (atoi)","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"String to Integer (atoi)","description":"The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/string-to-integer-atoi/description/\">8. String to Integer (atoi)</a></h2>\n<h3>Problem:</h3>\n<p>Implement <code class=\"language-text\">atoi</code> which converts a string to an integer.</p>\n<p>The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.</p>\n<p>The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.</p>\n<p>If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.</p>\n<p>If no valid conversion could be performed, a zero value is returned.</p>\n<p><strong>Note:</strong></p>\n<p>Only the space character <code class=\"language-text\">' '</code> is considered as whitespace character.\nAssume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. If the numerical value is out of the range of representable values, INT<em>MAX (231 − 1) or INT</em>MIN (−231) is returned.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"42\"\nOutput: 42</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"   -42\"\nOutput: -42\nExplanation: The first non-whitespace character is '-', which is the minus sign.\n             Then take as many numerical digits as possible, which gets 42.</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"4193 with words\"\nOutput: 4193\nExplanation: Conversion stops at digit '3' as the next character is not a numerical digit.</code></pre></div>\n<p><strong>Example 4:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"words and 987\"\nOutput: 0\nExplanation: The first non-whitespace character is 'w', which is not a numerical\n             digit or a +/- sign. Therefore no valid conversion could be performed.</code></pre></div>\n<p><strong>Example 5:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"-91283472332\"\nOutput: -2147483648\nExplanation: The number \"-91283472332\" is out of the range of a 32-bit signed integer.\n             Thefore INT_MIN (−231) is returned.</code></pre></div>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} str\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myAtoi</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">str</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">2147483647</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">2147483648</span><span class=\"token punctuation\">,</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>Looks like <code class=\"language-text\">Number()</code> is faster than <code class=\"language-text\">parseInt()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} str\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myAtoi</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">str</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">2147483647</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">2147483648</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^ *[-+]?\\d+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>THREE</h4>\n<p>General solution.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} str\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myAtoi</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">str</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> sign <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> str<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> cc <span class=\"token operator\">=</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>cc <span class=\"token operator\">===</span> <span class=\"token number\">45</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// -</span>\n            sign <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>cc <span class=\"token operator\">===</span> <span class=\"token number\">43</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// +</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>cc <span class=\"token operator\">>=</span> <span class=\"token number\">48</span> <span class=\"token operator\">&amp;&amp;</span> cc <span class=\"token operator\">&lt;=</span> <span class=\"token number\">57</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// 0-9</span>\n            i<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>cc <span class=\"token operator\">!==</span> <span class=\"token number\">32</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// space</span>\n            <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> str<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> digit <span class=\"token operator\">=</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token number\">48</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>digit <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> digit <span class=\"token operator\">></span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        result <span class=\"token operator\">=</span> result <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">+</span> digit<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">2147483647</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">2147483648</span><span class=\"token punctuation\">,</span> result <span class=\"token operator\">*</span> sign<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/","relativePath":"docs/leetcode/index.md","relativeDir":"docs/leetcode","base":"index.md","name":"index","frontmatter":{"title":"Leetcode","weight":0,"excerpt":"feel free to try the examples","seo":{"title":" Leetcode Practice  ","description":"  ","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<br>\n<h1>Leetcode </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://web-dev-collaborative.github.io/Leetcode-JS-PY-MD/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://web-dev-collaborative.github.io/Leetcode-JS-PY-MD/old_index.html\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>"},{"url":"/docs/leetcode/ValiParentheses/","relativePath":"docs/leetcode/ValiParentheses.md","relativeDir":"docs/leetcode","base":"ValiParentheses.md","name":"ValiParentheses","frontmatter":{"title":"Valid Parentheses","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Valid Parentheses","description":"determine if the input string is valid.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/valid-parentheses/description/\">20. Valid Parentheses</a></h2>\n<h3>Problem:</h3>\n<p>Given a string containing just the characters <code class=\"language-text\">'('</code>, <code class=\"language-text\">')'</code>, <code class=\"language-text\">'{'</code>, <code class=\"language-text\">'}'</code>, <code class=\"language-text\">'['</code> and <code class=\"language-text\">']'</code>, determine if the input string is valid.</p>\n<p>An input string is valid if:</p>\n<ol>\n<li>Open brackets must be closed by the same type of brackets.</li>\n<li>Open brackets must be closed in the correct order.</li>\n</ol>\n<p>Note that an empty string is also considered valid.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"()\"\nOutput: true</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"()[]{}\"\nOutput: true</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"(]\"\nOutput: false</code></pre></div>\n<p><strong>Example 4:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"([)]\"\nOutput: false</code></pre></div>\n<p><strong>Example 5:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"{[]}\"\nOutput: true</code></pre></div>\n<h3>Solution:</h3>\n<p>Stack 101.</p>\n<p>Whenever we meet a close bracket, we want to compare it to the last open bracket.</p>\n<p>That is why we use stack to store open brackets: first in, last out.</p>\n<p>And since there is only bracket characters, the last open bracket happens to be the last character.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isValid</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> stack <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> pairs <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string-property property\">'}'</span><span class=\"token operator\">:</span> <span class=\"token string\">'{'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string-property property\">']'</span><span class=\"token operator\">:</span> <span class=\"token string\">'['</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string-property property\">')'</span><span class=\"token operator\">:</span> <span class=\"token string\">'('</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> c <span class=\"token keyword\">of</span> s<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> open <span class=\"token operator\">=</span> pairs<span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>open<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>stack<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> open<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            stack<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> stack<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/leetcode/ZigZaConversion/","relativePath":"docs/leetcode/ZigZaConversion.md","relativeDir":"docs/leetcode","base":"ZigZaConversion.md","name":"ZigZaConversion","frontmatter":{"title":"ZigZag Conversion","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"ZigZag Conversion","description":"The string \"PAYPALISHIRING\" is written in a zigzag pattern on a given number of rows like this","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2><a href=\"https://leetcode.com/problems/zigzag-conversion/description/\">6. ZigZag Conversion</a></h2>\n<h3>Problem:</h3>\n<p>The string <code class=\"language-text\">\"PAYPALISHIRING\"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">P   A   H   N\nA P L S I I G\nY   I   R</code></pre></div>\n<p>And then read line by line: <code class=\"language-text\">\"PAHNAPLSIIGYIR\"</code></p>\n<p>Write the code that will take a string and make this conversion given a number of rows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">string convert(string s, int numRows);</code></pre></div>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: s = \"PAYPALISHIRING\", numRows = 3\nOutput: \"PAHNAPLSIIGYIR\"</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: s = \"PAYPALISHIRING\", numRows = 4\nOutput: \"PINALSIGYAHRPI\"\nExplanation:\n\nP     I    N\nA   L S  I G\nY A   H R\nP     I</code></pre></div>\n<h3>Solution:</h3>\n<p>Squeeze the zigzag pattern horizontally to form a matrix. Now deal with the odd and even columns respectively.</p>\n<p>For example let numRows be 5, if we list out the indecies:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">row\n 1    00    08    16\n 2    01 07 09 15 17\n 3    02 06 10 14 18\n 4    03 05 11 13 19\n 5    04    12    20</code></pre></div>\n<p>First calculate the matrix width:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pairs = floor( len(s) / (numRows + numRows - 2) )\nwidth = pairs * 2 + ceil( (len(s) - pairs * (numRows + numRows - 2)) / numRows )</code></pre></div>\n<p>We can easily make a observation that the direction of odd and even columns and different.</p>\n<p>Let the first column be index 0 and let i be the current position at column col.</p>\n<p>We need to count the items between matrix[row][col] and matrix[row][col+1], exclusive.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">next_i = i + (numRows - row) + (numRows - row), if col is even &amp;&amp; 1 &lt; row &lt; numRows\nnext_i = i + row - 2 + row, if col is odd &amp;&amp; 1 &lt; row &lt; numRows</code></pre></div>\n<p>If row == 1 or row == numRows, skip the odd columns.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">next_i = i + numRows + (numRows - 2), if col is even &amp;&amp; (row == 1 || row == numRows)</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @param {number} numRows\n * @return {string}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">convert</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s<span class=\"token punctuation\">,</span> numRows</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>numRows <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> s<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> pairs <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token punctuation\">(</span>numRows <span class=\"token operator\">+</span> numRows <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> width <span class=\"token operator\">=</span> pairs <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">ceil</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> pairs <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>numRows <span class=\"token operator\">+</span> numRows <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> numRows<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> row <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> row <span class=\"token operator\">&lt;=</span> numRows<span class=\"token punctuation\">;</span> row<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> row <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        result <span class=\"token operator\">+=</span> s<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> col <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> col <span class=\"token operator\">&lt;</span> width<span class=\"token punctuation\">;</span> col<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>row <span class=\"token operator\">===</span> <span class=\"token number\">1</span> <span class=\"token operator\">||</span> row <span class=\"token operator\">===</span> numRows<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>col <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    i <span class=\"token operator\">+=</span> numRows <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>numRows <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>col <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    i <span class=\"token operator\">+=</span> numRows <span class=\"token operator\">-</span> row <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>numRows <span class=\"token operator\">-</span> row<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    i <span class=\"token operator\">+=</span> row <span class=\"token operator\">-</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> row<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n            result <span class=\"token operator\">+=</span> s<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>\n<hr>\n<p>☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆☆<em>: .｡. o(≧▽≦)o .｡.:</em>☆</p>\n<hr>"},{"url":"/docs/netlify-cms-jamstack/","relativePath":"docs/netlify-cms-jamstack/index.md","relativeDir":"docs/netlify-cms-jamstack","base":"index.md","name":"index","frontmatter":{"title":"Netlify CMS","template":"docs","excerpt":"etlify CMS is an open source content management system for your Git workflow that enables you to provide editors with a friendly UI and intuitive workflows."},"html":"<p>Netlify CMS is an open source content management system for your Git workflow that enables you to provide editors with a friendly UI and intuitive workflows. You can use it with any static site generator to create faster, more flexible web projects. Content is stored in your Git repository alongside your code for easier versioning, multi-channel publishing, and the option to handle content updates directly in Git.</p>\n<p>At its core, Netlify CMS is an open-source React app that acts as a wrapper for the Git workflow, using the GitHub, GitLab, or Bitbucket API. This provides many advantages, including:</p>\n<ul>\n<li><strong>Fast, web-based UI:</strong> With rich-text editing, real-time preview, and drag-and-drop media uploads.</li>\n<li><strong>Platform agnostic:</strong> Works with most static site generators.</li>\n<li><strong>Easy installation:</strong> Add two files to your site and hook up the backend by including those files in your build process or linking to our Content Delivery Network (CDN).</li>\n<li><strong>Modern authentication:</strong> Using GitHub, GitLab, or Bitbucket and JSON web tokens.</li>\n<li><strong>Flexible content types:</strong> Specify an unlimited number of content types with custom fields.</li>\n<li><strong>Fully extensible:</strong> Create custom-styled previews, UI widgets, and editor plugins.</li>\n</ul>\n<h2><a href=\"https://www.netlifycms.org/docs/intro/#netlify-cms-vs-netlify\"></a>Netlify CMS vs. Netlify</h2>\n<p><a href=\"https://www.netlify.com/\">Netlify.com</a> is a platform you can use to automatically build, deploy, serve, and manage your frontend sites and web apps. It also provides a variety of other features like form processing, serverless functions, and split testing. Not all Netlify sites use Netlify CMS, and not all sites using Netlify CMS are on Netlify.</p>\n<p>The folks at Netlify created Netlify CMS to fill a gap in the static site generation pipeline. There were some great proprietary headless CMS options, but no real contenders that were open source and extensible—that could turn into a community-built ecosystem like WordPress or Drupal. For that reason, Netlify CMS is <em>made</em> to be community-driven, and has never been locked to the Netlify platform (despite the name).</p>\n<p>With this in mind, you can:</p>\n<ul>\n<li>Use Netlify CMS without Netlify and deploy your site where you always have, hooking up your own CI, site hosting, CDN, etc.</li>\n<li>Use Netlify without Netlify CMS and edit your static site in your code editor.</li>\n<li>Or, use them together and have a fully-working CMS-enabled site with <a href=\"https://www.netlifycms.org/docs/start-with-a-template/\">one click</a>!</li>\n</ul>\n<p>If you hook up Netlify CMS to your website, you're basically adding a tool for content editors to make commits to your site repository without touching code or learning Git.</p>\n<h3><a href=\"https://www.netlifycms.org/docs/intro/#find-out-more\"></a>Find out more</h3>\n<ul>\n<li>Get a feel for the UI in the <a href=\"https://cms-demo.netlify.com/\">demo site</a>. (No login required. Click the login button to go straight to the CMS editor UI.)</li>\n<li><a href=\"https://www.netlifycms.org/docs/start-with-a-template/\">Start with a template</a> to make a Netlify CMS-enabled site of your own.</li>\n<li>Configure your existing site by following a <a href=\"https://www.netlifycms.org/docs/add-to-your-site/\">tutorial</a> or checking <a href=\"https://www.netlifycms.org/docs/configuration-options\">configuration options</a>.</li>\n<li>Ask questions and share ideas in the Netlify CMS <a href=\"https://netlifycms.org/chat\">community chat</a>.</li>\n<li>Get involved in new developments and become a <a href=\"https://www.netlifycms.org/docs/contributor-guide/\">contributor</a>.</li>\n</ul>"},{"url":"/docs/netlify-cms-jamstack/jamstack-templates/","relativePath":"docs/netlify-cms-jamstack/jamstack-templates.md","relativeDir":"docs/netlify-cms-jamstack","base":"jamstack-templates.md","name":"jamstack-templates","frontmatter":{"title":"Jamstack","template":"docs","excerpt":"A collection of project starter templates for a variety of static site generators with one-click deployments to Netlify."},"html":"<h1>Jamstack Project Templates</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>A collection of project starter templates for a variety of static site generators with one-click deployments to Netlify.</p>\n</blockquote>\n<hr>\n<ul>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/artisan-static/\">Artisan Static</a></h3>\n<p><a href=\"https://artisanstatic.netlify.app/\">Artisan Static</a> is a starter template for building a static Jigsaw blog hosted on Netlify.</p>\n<p>This comes with code highlighting, share buttons, comments, analytics, an RSS feed, a contact form, a CMS and more.</p>\n<p>The HTML, CSS and JavaScript in this template are extremely minimal, which makes the code easy to build on top of or replace completely.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/awake-blog-template-nuxt/\">Awake, A Nuxt Blog Template</a></h3>\n<p>Awake is a Nuxt.js template for generating a beautifully robust static site with blog. It comes with support for site search, newsletter sign-up via mailchimp, comments via disqus and more. It's built with performance in mind (auto image resizing, lazy loading, and more).</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/bigcommerce-gatsby-netlify-cms-starter/\">BigCommerce Gatsby Starter w/ Netlify CMS</a></h3>\n<p>Example Gatsby, BigCommerce and Netlify CMS project meant to jump start Jamstack ecommerce sites.</p>\n<p>Through the use of Netlify Functions, supports a built-in cart and checkout flow (with 50+ payment gateways / methods, advanced tax and shipping providers, etc) that uses the BigCommerce APIs to provide a complete end-to-end shopper experience, without the need for a complex backend or middleware.</p>\n<p><em>Note: Requires a BigCommerce store, which you can get a free trial of via bigcommerce.com, which includes API access, if you don't already have an account. There is also an optional partner program which includes a sandbox account to play around in.</em></p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/commercejs-nextjs-demo-store/\">Commerce.js - Fully-fledged eCommerce store built with Next.js</a></h3>\n<p>A fully-fledged and customizable Jamstack eCommerce storefront built using Next.js as a frontend, Chec and Commerce.js as the eCommerce backend with production-ready deployment to Netlify.</p>\n<p>Being an API-first eCommerce platform, Chec/Commerce.js helps businesses to freely decouple and tool their websites. This template comes built with marketing pages, a product listing page, single product display pages, cart and checkout functionalities, and an order confirmation page.</p>\n<p><em>Note: You will need to sign up for a Chec account at commercejs.com which includes the API access. Please follow the guide in the github repo to configure your inital setup.</em></p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/commercelayer-sanity-starter/\">Commerce Layer Starter</a></h3>\n<p>A multi-country ecommerce starter that features the sanity studio built with <a href=\"https://commercelayer.io/\">Commerce Layer</a>, Next.js, and deployed to Netlify. The starter comes with an ecommerce storefront built with Nextjs, Commerce Layer react components library, and Tailwind CSS alongside international shopping capabilities powered by Commerce Layer APIs. You also get a micro CLI seeder to import Commerce Layer data, structured content on Sanity CMS, localization support, and deployment configuration to Netlify.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/delog-gatsby-netlifycms/\">Delog - GatsbyJS + Netlify CMS</a></h3>\n<p>Delog is developed for professional bloggers and web designers to build a website that has a lightning-fast navigation speed. Simply follow the steps given in the ‘Read Me’ document and your website all set with CMS and Contact form. With bacsic knowledge of CSS/SCSS you can also change the color scheme to match your style</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/eleventy-base-blog/\">Eleventy base blog template</a></h3>\n<p>This project template includes a simple blog structure using <a href=\"https://11ty.io/\">Eleventy</a>, It demonstrates how to collect pages into blog posts and provide a tagging structure.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/empress-blog-casper-template/\">empress-blog - Casper</a></h3>\n<p>A fully-functional, static site implementation of a blog system that is mostly compatible with Ghost and Ghost Templates.</p>\n<p>Built on EmberJS with fully working out of the box SEO friendly output and all content is authored using Markdown</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/foundation-gatsby-netlifycms-starter/\">Foundation - Gatsby and NetlifyCMS Starter</a></h3>\n<p>A starter to launch your blazing fast personal website and a blog, Built with Gatsby and Netlify CMS. Made with ❤ by Stackrole</p>\n</li>\n</ul>\n<h2>Features</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">-   A Blog and Personal website with Netlify CMS.\n-   Responsive Web Design\n-   Customize content of Homepage, About and Contact page.\n-   Add / Modify / Delete blog posts.\n-   Edit website settings, Add Google Analytics and make it your own all with in the CMS.\n-   SEO Optimized\n-   OpenGraph structured data\n-   Twitter Cards meta\n-   Beautiful XML Sitemaps\n-   Netlify Contact Form, Works right out of the box after deployment.\n-   Invite collaborators into Netlify CMS, without giving access to your Github account via Git Gateway\n-   For instructions, take a look at readme.md at Github repo.\n-   Gatsby Incremental Builds with Netlify.</code></pre></div>\n<ul>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/gatsby-blog-with-netlify-cms/\">Gatsby + Netlify CMS Starter</a></h3>\n<p>A starter project for using Gatsby to build a blog site backed with <a href=\"https://www.netlifycms.org/\">Netlify CMS</a> for content authoring.</p>\n<p>This example is the Kaldi coffee company template (adapted from One Click Hugo CMS).</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/gatsby-dev-blog-fitzgerald/\">Gatsby developer blog</a></h3>\n<p>A fully customizable blog template designed for developers (or anyone else) wanting to get into blogging. Easy to edit, customize and extended. The blog is completely statically generated via GatsbyJS, comes with syntax highlighting (via PrismJS) out of the box, and has server-side rendering built-in, among other things.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/gatsby-starter-blog/\">Gatsby starter blog</a></h3>\n<p>A static site generator which uses <a href=\"https://reactjs.com/\">React</a> and provides both pre-rendering and client-side hydration. Some interesting bonuses included such as easy service worker support and GraphQL built in for providing templates with their data.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/gatsby-starter-contentful/\">Gatsby Contentful Starter blog</a></h3>\n<p>Static sites are scalable, secure and have very little required maintenance. They come with a drawback though. Not everybody feels good editing files, building a project and uploading it somewhere. With Contentful and Gatsby you can connect your favorite static site generator with an API that provides an easy to use interface for people writing content and automate the publishing using services like Travis CI or Netlify.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/gatsby-starter-dafault/\">Gatsby default starter site</a></h3>\n<p>A static site generator which uses <a href=\"https://reactjs.com/\">React</a> and provides both pre-rendering and client-side hydration. Some interesting bonuses included such as easy service worker support and GraphQL built in for providing templates with their data.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/gatsby-starter-ecommerce/\">Gatsby Starter eCommerce</a></h3>\n<p>A GatsbyJS starter focused on creating an eCommerce site using Moltin eCommerce Api and stripe payment gateway.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/gatsby-starter-minimal-blog/\">Gatsby Starter Minimal Blog</a></h3>\n<p>A GatsbyJS starter focused on typography &#x26; minimalistic style. Write your blogposts in markdown and easily customize the look of the site. The blog has features like categories, PrismJS highlighting and previous/next notes. Because of the offline support, WebApp Manifest and extensive SEO the blog is a fully fledged PWA.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/hugo-novela-forestry/\">Hugo Novela with Forestry</a></h3>\n<p>With minimal styling and maximum features — including multiple homepage layouts, built-in social sharing and dark mode — Novela makes it easy to start publishing beautiful articles and stories with <a href=\"https://gohugo.io/\">Hugo</a> and <a href=\"https://forestry.io/\">Forestry</a>.</p>\n<p>Novela is built by the team at <a href=\"https://www.narative.co/\">Narative</a>, and built for everyone that loves the web.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/hugo-starter-blog-theme-casper/\">Hugo starter blog theme - Casper</a></h3>\n<p>A Hugo boilerplate for creating a blog site backed with <a href=\"https://www.netlifycms.org/\">NetlifyCMS</a> for content authoring.</p>\n<p>This site template has an asset pipeline using Gulp and Webpack for processing JavaScript with Babel, and CSS with PostCSS.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/indiego/\">Indiego Hugo starter kit</a></h3>\n<p>A socially aware Hugo blog starter kit, with Modular CSS Gulp workflow, for frontend developers.</p>\n<p>Publish your RSS feeds to your social networks, all blog and status posts marked up with microformats to display post previews.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/jamdocs/\">Jamdocs - a starter for documentations in Gridsome</a></h3>\n<p>The ultimate static generated documentation theme for the Jamstack. Highly customizable, based on Gridsome, ready to deploy to Netlify in one click. Jamdocs is optimized to be as fast as possible, right now generating 100/100/100/100 score in Google Lighthouse. And 100/100 score in Google Page Speed Insights.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/jamify-starter-ghost/\">Jamify Starter for publishing Blogs with Gatsby &#x26; Ghost</a></h3>\n<p>Publish flaring fast blogs with <a href=\"https://gatsbyjs.org/\">Gatsby</a> and <a href=\"https://ghost.org/\">Ghost</a>.</p>\n<p>This starter template is for professional publishers who are looking for a fully functional front-end with infinite-scroll, flexible routing, multi-language support and a rich plugin eco-system. It's built with performance in mind (auto image resizing, lazy loading with gatsby-image, and more) and comes with support for newsletter sign-up, easy comments integration and more. This starter features support for incremental builds thereby delivering the fastest build times ever seen.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/jekyll-and-alembic-theme-starter/\">Jekyll &#x26; Alembic theme starter</a></h3>\n<p><a href=\"https://alembic.darn.es/\">Alembic</a> is a starting point for Jekyll projects, giving all sorts of bells and whistles but with reduced complexity. This is a starter kit for you to deploy a Jekyll site immediately to Netlify.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/jekyll-with-netlify-cms-boilerplate/\">Jekyll + Netlify CMS Boilerplate</a></h3>\n<p>A simple Jekyll boilerplate for creating a fast, static website on Netlify with a continuous deployment workflow and <a href=\"https://www.netlifycms.org/\">Netlify CMS</a> for content editing.</p>\n<p>This template provides sample pages, blog posts and a working contact form powered by <a href=\"https://www.netlify.com/docs/form-handling\">Netlify Forms</a>.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/nextjs-planetscale-starter/\">Next.js starter app with NextAuth.js and a PlanetScale serverless database</a></h3>\n<p>This starter app combines the powers of <a href=\"https://planetscale.com/\">PlanetScale</a>’s serverless databases with Prisma’s next-gen ORM and NextAuth.js for authentication to create a Next.js starter app that can scale with you. In this starter app, any users that sign up or log in are automatically stored in your PlanetScale database. There is also a built-in admin page, where you can see your users table without having to write database queries.</p>\n<p><em>Note: After you deploy to Netlify, you will need to follow the instructions in the <a href=\"https://github.com/planetscale/nextjs-planetscale-starter\">documentation</a> to get your PlanetScale database up and running.</em></p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/nextjs-starter-blog/\">Nextjs Starter for Blog</a></h3>\n</li>\n</ul>\n<h2>Nextjs Starter for Blog</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">🚀 Nextjs Starter is boilerplate code for your blog based on Next.js framework. ⚡️ Made with Next.js, TypeScript, ESLint, Prettier, PostCSS, Tailwind CSS.\n\nYou can find a [Nextjs Starter demo](https://creativedesignsguru.com/demo/Nextjs-Blog-Boilerplate/).\n\nYou can also check our [Nextjs Themes](https://creativedesignsguru.com/category/nextjs/) or if you want to see all our [React Themes](https://creativedesignsguru.com/category/react/). You can see all our other [premium themes](https://creativedesignsguru.com/) using other static static generator like Eleventyjs.</code></pre></div>\n<h3>Features</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Blog feature:\n\n-   🎈 Syntax Highlighting with Prism.js\n-   🤖 SEO metadata and Open Graph tags\n-   ⚙️ JSON-LD for richer indexing\n-   📖 Pagination\n-   🌈 Include a FREE minimalist blog theme\n-   ⬇️ Markdown\n-   💯 Maximize lighthouse score\n\nDeveloper experience first:\n\n-   🔥 Next.js for Static Site Generator\n-   🎨 Integrate with Tailwind CSS\n-   💅 PostCSS for processing Tailwind CSS\n-   🎉 Type checking TypeScript\n-   ✏️ Linter with ESLint\n-   🛠 Code Formatter with Prettier\n-   🦊 SEO metadata, JSON-LD and Open Graph tags with Next SEO\n\nBuilt-in feature from Next.js:\n\n-   ☕ Minify HTML &amp; CSS\n-   💨 Live reload\n-   ✅ Cache busting</code></pre></div>\n<h3>Philosophy</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">-   Minimal code\n-   SEO-friendly\n-   🚀 Production-ready</code></pre></div>\n<ul>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/nuxt-bael-blog-template/\">Bael Blog Template with Netlify CMS and Serverless Function</a></h3>\n<p>Bael is a free template that gives you an easy way to start a blog that uses modern technologies like static-site Jamstack architecture, CSS grid layout, responsive design, a serverless function that handles emails newsletter signup with Sendgrid, and fuzzy search — all wrapped up in a brutalist aesthetic.</p>\n<p>Bael runs using <a href=\"https://nuxtjs.org/\">Nuxt.js</a>, <a href=\"https://vuejs.org/\">Vue.js</a>, <a href=\"https://netlifycms.org/\">Netlify CMS</a>, and is hosted by <a href=\"https://netlify.com/\">Netlify</a>.</p>\n<p>A free Sendgrid account and API key is needed to setup the newsletter signup feature.</p>\n<p>Made by <a href=\"https://jake101.com/\">jake101</a></p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/nuxt-starter-netlify-cms/\">Nuxt &#x26; Netlify CMS Boilerplate</a></h3>\n<p>A super unopinionated starter project, built off the <code class=\"language-text\">create-nuxt-app</code> CLI tool, and leveraging Netlify CMS to generate content in the Nuxt API from flat files.</p>\n</li>\n<li>\n<h3><a href=\"https://templates.netlify.com/template/platframe-default-starter/\">Platframe default starter</a></h3>\n<p><a href=\"https://platframe.com/\">Platframe's</a> default (responsive) starter template takes the form of a landing page that can be personalized in a jiffy, or be extensively adapted to suit variable project scopes.</p>\n<p>Multipage sites are well-supported with a growth-proof, scalable architecture. The template allows for granular control, and is powered by an extensible, feature-rich build-system.</p>\n</li>\n</ul>"},{"url":"/docs/overflow/emmet/","relativePath":"docs/overflow/emmet.md","relativeDir":"docs/overflow","base":"emmet.md","name":"emmet","frontmatter":{"title":"Emmet Cheat Sheet","template":"docs","excerpt":"The a toolkit for web-developer"},"html":"<p><em>The a toolkit for web-developers</em></p>\n<h3>Introduction</h3>\n<p>Emmet is a productivity toolkit for web developers that uses expressions to generate HTML snippets.</p>\n<h3>Installation</h3>\n<p>Normally, installation for Emmet should be a straight-forward process from the package-manager, as most of the modern text editors support Emmet.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">### Usage\n\nYou can use Emmet in two ways:\n\n- &lt;span id=\"856f\">Tab Expand Way: Type your emmet code and press `Tab` key&lt;/span>\n- &lt;span id=\"9aea\">Interactive Method: Press `alt + ctrl + Enter` and start typing your expressions. This should automatically generate HTML snippets on the fly.&lt;/span>\n\n**This cheatsheet will assume that you press** `Tab` **after each expressions.**</code></pre></div>\n<h3>HTML</h3>\n<hr>\n<h3>Generating HTML 5 DOCTYPE</h3>\n<p>html:5`\nWill generate</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\">    <span class=\"token doctype\"><span class=\"token punctuation\">&lt;!</span><span class=\"token doctype-tag\">DOCTYPE</span> <span class=\"token name\">html</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>html</span> <span class=\"token attr-name\">lang</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>en<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>head</span><span class=\"token punctuation\">></span></span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>meta</span> <span class=\"token attr-name\">charset</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>UTF-8<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>meta</span> <span class=\"token attr-name\">name</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>viewport<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">content</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>width=device-width, initial-scale=1.0<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>meta</span> <span class=\"token attr-name\">http-equiv</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>X-UA-Compatible<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">content</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>ie=edge<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>title</span><span class=\"token punctuation\">></span></span>Document<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>title</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>head</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>body</span><span class=\"token punctuation\">></span></span>\n\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>body</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>html</span><span class=\"token punctuation\">></span></span>\n\n---\n\n\n### Child items\n\nChild items are created using `>`\n\n```html\nul>li>p`\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>ul</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>p</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>p</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>ul</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h3>Sibling Items</h3>\n<p>Sibling items are created using <code class=\"language-text\">+</code></p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\">html>head+body`\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>html</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>head</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>head</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>body</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>body</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>html</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h3>Multiplication</h3>\n<p>Items can be multiplied by <code class=\"language-text\">*</code></p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\">ul>li*5`\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>ul</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>ul</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h3>Grouping</h3>\n<p>Items can be grouped together using <code class=\"language-text\">()</code></p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\">table>(tr>th*5)+tr>t*5`\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>table</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>t</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>t</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>t</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>t</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>t</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>t</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>t</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>t</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>t</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>t</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>table</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h3>Class and ID</h3>\n<p>Class and Id in Emmet can be done using <code class=\"language-text\">.</code> and <code class=\"language-text\">#</code></p>\n<hr>\n<p>html\ndiv.heading`</p>\n<div class=\"heading\">\n</div>\n<p>`<code class=\"language-text\"></code>html div#heading`</p>\n<div id=\"heading\">\n</div>\n<p>ID and Class can also be combined together `<code class=\"language-text\"></code>html div#heading.center`</p>\n<div id=\"heading\" class=\"center\">\n</div>\n<hr>\n<h3>Adding Content inside tags</h3>\n<p>Contents inside tags can be added using <code class=\"language-text\">{}</code></p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\">h1{Emmet is awesome}+h2{Every front end developers should use this}+p{This is\nparagraph}*2`\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span>Emmet is awesome<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h2</span><span class=\"token punctuation\">></span></span>Every front end developers should use this<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h2</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>p</span><span class=\"token punctuation\">></span></span>This is paragraph<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>p</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>p</span><span class=\"token punctuation\">></span></span>This is paragraph<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>p</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h3>Attributes inside HTML tags</h3>\n<p>Attributes can be added using <code class=\"language-text\">[]</code></p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\">a[href=https://?google.com data-toggle=something target=_blank]`\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>a</span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://?google.com<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">data-toggle</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>something<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">target</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>_blank<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>a</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<h3>Numbering</h3>\n<p>Numbering can be done using <code class=\"language-text\">$</code><br>\nYou can use this inside tag or contents.</p>\n<hr>\n<p>html\nh${This is so awesome $}*6`</p>\n<h1>This is so awesome 1</h1>\n<h2>This is so awesome 2</h2>\n<h3>This is so awesome 3</h3>\n<h4>This is so awesome 4</h4>\n<h5>This is so awesome 5</h5>\n<h6>This is so awesome 6</h6>\n<p>Use <code class=\"language-text\">@-</code> to reverse the Numbering `<code class=\"language-text\"></code>html img[src=image$$@-.jpg]*5`</p>\n<img src=\"image05.jpg\" alt=\"\" />\n<img src=\"image04.jpg\" alt=\"\" />\n<img src=\"image03.jpg\" alt=\"\" />\n<img src=\"image02.jpg\" alt=\"\" />\n<img src=\"image01.jpg\" alt=\"\" />\n<p>To start the numbering from specific number, use this way `<code class=\"language-text\"></code>html\nimg[src=emmet$@100.jpg]*5`</p>\n<img src=\"emmet100.jpg\" alt=\"\" />\n<img src=\"emmet101.jpg\" alt=\"\" />\n<img src=\"emmet102.jpg\" alt=\"\" />\n<img src=\"emmet103.jpg\" alt=\"\" />\n<img src=\"emmet104.jpg\" alt=\"\" />\n<hr>\n<h3>Tips</h3>\n<ul>\n<li><span id=\"b708\">Use <code class=\"language-text\">:</code> to expand known abbreviations</span></li>\n</ul>\n<hr>\n<p>html\ninput:date`</p>\n<input type=\"date\" name=\"\" id=\"\" />\n<p>`<code class=\"language-text\"></code>html form:post`</p>\n<form action=\"\" method=\"post\">\n</form>\n<p>`<code class=\"language-text\"></code>html link:css`</p>\n<link rel=\"stylesheet\" href=\"style.css\" />\n<ul>\n<li><span id=\"d43e\">Building Navbar</span></li>\n</ul>\n<p>`<code class=\"language-text\"></code>html .navbar>ul>li*3>a[href=#]{Item $@-}`</p>\n<div class=\"navbar\">\n  <ul>\n    <li>\n<a href=\"#\">Item 3</a>\n</li>\n    <li>\n<a href=\"#\">Item 2</a>\n</li>\n    <li>\n<a href=\"#\">Item 1</a>\n</li>\n  </ul>\n</div>\n<hr>\n<h3>CSS</h3>\n<p>Emmet works surprisingly well with css as well.</p>\n<ul>\n<li><span id=\"68eb\"><code class=\"language-text\">f:l</code></span></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\">    <span class=\"token property\">float</span><span class=\"token punctuation\">:</span> left<span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can also use any options n/r/l</p>\n<ul>\n<li><span id=\"d9cc\"><code class=\"language-text\">pos:a­</code></span></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\">    <span class=\"token property\">position</span><span class=\"token punctuation\">:</span> absolute<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Also use any options, pos:a/r/f</p>\n<ul>\n<li><span id=\"5b67\"><code class=\"language-text\">d:n/b­/f/­i/ib</code></span></li>\n</ul>\n<hr>\n<p>html\nd:ib` display: inline-block; -\n&#x3C;span id=\"26f6\"</p>\n<blockquote>\n<p>You can use <code class=\"language-text\">m</code> for margin and <code class=\"language-text\">p</code> for padding followed by direction&#x3C;/span</p>\n</blockquote>\n<p><code class=\"language-text\">html mr` -&amp;gt; `margin-right`</code>html pr<code class=\"language-text\">-&amp;gt;</code>padding-right<code class=\"language-text\">-\n&lt;span id=\"01cc\"></code>@f` will result in</span></p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token atrule\"><span class=\"token rule\">@font-face</span></span> <span class=\"token punctuation\">{</span> <span class=\"token property\">font-family</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">;</span> <span class=\"token property\">src</span><span class=\"token punctuation\">:</span><span class=\"token url\"><span class=\"token function\">url</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span> You can also use these shorthands</code></pre></div>\n<figure>\n  <img\n    src=\"https://cdn-images-1.medium.com/max/800/1*h8hsUrJNyVRLYqBQP63DCA.png\"\n    class=\"graf-image\"\n  />\n</figure>"},{"url":"/docs/overflow/","relativePath":"docs/overflow/index.md","relativeDir":"docs/overflow","base":"index.md","name":"index","frontmatter":{"title":"Overflow","weight":0,"excerpt":"feel free to try the examples","seo":{"title":"Overflow","description":"Overflow or outdated content from other sections","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":""},{"url":"/docs/overflow/http/","relativePath":"docs/overflow/http.md","relativeDir":"docs/overflow","base":"http.md","name":"http","frontmatter":{"title":"The HTTP Protocol","weight":0,"excerpt":"The HTTP Protocol","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>The HTTP Protocol\n\n</h2>\n<ul>\n<li>Requires: a connection between client and server</li>\n<li></li>\n<li>Stateless: no login process, each request is independent</li>\n<li></li>\n<li>Simple format: request header, blank line, possible payload</li>\n<li>Symmetrical: allows data to be sent and recieved</li>\n<li>Very easy to implement but scales very well</li>\n</ul>\n<h2>Example HTTP Request</h2>\n<p>Note lines folded for display.</p>\n<p>What do each of these headers mean? Which are required? Many are defined in the <a href=\"ftp://ftp.isi.edu/in-notes/rfc2616.txt\">HTTP standard</a> but others can be defined via the HTTP extension framework.</p>\n<h2>Example HTTP Response</h2>\n<h2>Example HTTP POST Request</h2>\n<p>Note lines folded for display.</p>\n<p>This is a POST request, note how the data is encoded in the request body.</p>\n<h2>Example HTTP GET Request</h2>\n<p>Note lines folded for display.</p>\n<p>This is the same form submitted via a GET request, here the data is encoded in request URL. Note also the If-Modified-Since header in this request, sent because my browser has just asked for the same resource.</p>\n<h2>HTTP Redirect</h2>\n<p>Alternately</p>\n<p>The HTTP redirect is a server response that can be used to indicate that a resource has moved to a new location. An alternate is to include the above meta tag in a page header to force a redirect from the current page.</p>\n<h2>HTTP Verbs</h2>\n<ul>\n<li>GET - get a resource, <em>Idempotent</em></li>\n<li></li>\n<li>POST - send some data to a resource</li>\n<li></li>\n<li>HEAD - get headers for a resource</li>\n<li>PUT - create a new resource</li>\n<li>DELETE - delete a resource</li>\n</ul>\n<h2>Common HTTP Response Status Codes</h2>\n<p>Some notable response codes:</p>\n<ul>\n<li><a href=\"http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success\">200 OK</a> - Request succeeded and everything went well</li>\n<li></li>\n<li><a href=\"http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection\">301 Moved Permanently</a> - Requested resource has moved and all future requ</li>\n<li></li>\n<li><a href=\"http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error\">403 Forbidden</a> - Response refused by server (even if request is valid)</li>\n<li><a href=\"http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error\">404 Not Found</a> - Server could not find requested resource (though it may be available in the future)</li>\n<li><a href=\"http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error\">500 Internal Server Error</a> - Generic error message response when server encountered an error</li>\n</ul>\n<p>See also: <a href=\"http://en.wikipedia.org/wiki/List_of_HTTP_status_codes\">full list of HTTP status codes</a></p>\n<h2>Resources</h2>\n<ul>\n<li>Use <a href=\"https://addons.mozilla.org/en-US/firefox/addon/3829\">Live HTTP Headers</a> in Firefox to view headers of requests that you make. Also available as a <a href=\"https://chrome.google.com/webstore/detail/live-http-headers/iaiioopjkcekapmldfgbebdclcnpgnlo\">Chrome Extension</a>.</li>\n<li></li>\n<li>Similarly, in Google Chrome, the <a href=\"http://www.chromium.org/devtools/google-chrome-developer-tools-tutorial#resources\">Resources panel</a> in the Developer tools allows you to view the request headers and content for each request that was made when you're looking at a page.</li>\n<li>Wikipedia's <a href=\"http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol\">entry on HTTP</a> gives a good overview of the protocol.</li>\n</ul>"},{"url":"/docs/overflow/install/","relativePath":"docs/overflow/install.md","relativeDir":"docs/overflow","base":"install.md","name":"install","frontmatter":{"title":"Install","excerpt":"Web-Dev-Hubis a Unibit theme created for project documentations. You can use it for your project.","seo":{"title":"Install","description":"This is the Install page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Install","keyName":"property"},{"name":"og:description","value":"This is the Install page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Install"},{"name":"twitter:description","value":"This is the Install page"}]},"template":"docs"},"html":"<p>Node.js can be installed in different ways. This post highlights the most common and convenient ones.</p>\n<p>Official packages for all the major platforms are available at <a href=\"https://nodejs.org/en/download/\">https://nodejs.org/en/download/</a>.</p>\n<p>One very convenient way to install Node.js is through a package manager. In this case, every operating system has its own.</p>\n<p>On macOS, <a href=\"https://brew.sh/\">Homebrew</a> is the de-facto standard, and - once installed - allows you to install Node.js very easily, by running this command in the CLI:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">brew <span class=\"token function\">install</span> <span class=\"token function\">node</span></code></pre></div>\n<p>Other package managers for Linux and Windows are listed in <a href=\"https://nodejs.org/en/download/package-manager/\">https://nodejs.org/en/download/package-manager/</a></p>\n<p><code class=\"language-text\">nvm</code> is a popular way to run Node.js. It allows you to easily switch the Node.js version, and install new versions to try and easily rollback if something breaks, for example.</p>\n<p>It is also very useful to test your code with old Node.js versions.</p>\n<p>See <a href=\"https://github.com/creationix/nvm\">https://github.com/creationix/nvm</a> for more information about this option.</p>\n<p>My suggestion is to use the official installer if you are just starting out and you don't use Homebrew already, otherwise, Homebrew is my favorite solution.</p>\n<p>In any case, when Node.js is installed you'll have access to the <code class=\"language-text\">node</code> executable program in the command line.</p>"},{"url":"/docs/overflow/modules/","relativePath":"docs/overflow/modules.md","relativeDir":"docs/overflow","base":"modules.md","name":"modules","frontmatter":{"title":"Node Modules System","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"page","image":"images/theme.png","subtitle":"how we introduce modularity into our code in the node ecosystem"},"html":"<p>Node.js has a built-in module system.</p>\n<p>A Node.js file can import functionality exposed by other Node.js files.</p>\n<p>When you want to import something you use</p>\n<p>to import the functionality exposed in the library.js file that resides in the current file folder.</p>\n<p>In this file, functionality must be exposed before it can be imported by other files.</p>\n<p>Any other object or variable defined in the file by default is private and not exposed to the outer world.</p>\n<p>This is what the module.exports API offered by the <a href=\"https://nodejs.org/api/modules.html\">module system</a> allows us to do.</p>\n<p>When you assign an object or a function as a new exports property, that is the thing that's being exposed, and as such, it can be imported in other parts of your app, or in other apps as well.</p>\n<p>You can do so in 2 ways.</p>\n<p>The first is to assign an object to module.exports, which is an object provided out of the box by the module system, and this will make your file export <em>just that object</em>:</p>\n<p>The second way is to add the exported object as a property of exports. This way allows you to export multiple objects, functions or data:</p>\n<p>or directly</p>\n<p>And in the other file, you'll use it by referencing a property of your import:</p>\n<p>or</p>\n<p>What's the difference between module.exports and exports?</p>\n<p>The first exposes the object it points to. The latter exposes <em>the properties</em> of the object it points to.</p>\n<h1>Modules in Javascript</h1>\n<p>Differences between Node.js and browsers</p>\n<hr>\n<h3>Modules in Javascript</h3>\n<h4><strong>Differences between Node.js and browsers</strong></h4>\n<p>There are many differences between Node.js and browser environments, but many of them are small and inconsequential in practice. For example, in our <em>Asynchronous</em> lesson, we noted how <a href=\"https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args\" class=\"markup--anchor markup--p-anchor\">Node's setTimeout</a> has a slightly different return value from <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout\" class=\"markup--anchor markup--p-anchor\">a browser's setTimeout</a>. Let's go over a few notable differences between the two environments.</p>\n<p><strong>Global vs Window</strong></p>\n<p>In the Node.js runtime, the <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Global_object\" class=\"markup--anchor markup--p-anchor\">global object</a> is the object where global variables are stored. In browsers, the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window\" class=\"markup--anchor markup--p-anchor\">window object</a> is where global variables are stored. The window also includes properties and methods that deal with drawing things on the screen like images, links, and buttons. Node doesn't need to draw anything, and so it does not come with such properties. This means that you can't reference window in Node.</p>\n<p><em>Most browsers allow you to reference global but it is really the same object as window.</em></p>\n<p><strong>Document</strong></p>\n<p>Browsers have access to a document object that contains the HTML of a page that will be rendered to the browser window. There is no document in Node.</p>\n<p><strong>Location</strong></p>\n<p>Browsers have access to a location that contains information about the web address being visited in the browser. There is no location in Node, since it is not on the web.</p>\n<p><strong>Require and module.exports</strong></p>\n<p>Node has a predefined require function that we can use to import installed modules like readline. We can also import and export across our own files using require and module.exports. For example, say we had two different files, animals.js and cat.js, that existed in the same directory:</p>\n<p>If we execute animals.js in Node, the program would print ‘Sennacy is a great pet!'.</p>\n<p>Browsers don't have a notion of a file system so we cannot use require or module.exports in the same way.</p>\n<h3>The fs module</h3>\n<p>Node comes with an <a href=\"https://nodejs.org/api/fs.html\" class=\"markup--anchor markup--p-anchor\">fs module</a> that contains methods that allow us to interact with our computer's <strong>F</strong>ile <strong>S</strong>ystem through JavaScript. No additional installations are required; to access this module we can simply <code class=\"language-text\">require</code> it. We recommend that you code along with this reading. Let's begin with a <code class=\"language-text\">change-some-files.js</code> script that imports the module:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// change-some-files.js\n\nconst fs = require(\"fs\");</code></pre></div>\n<p>Similar to what we saw in the <code class=\"language-text\">readline</code> lesson, <code class=\"language-text\">require</code> will return to us a object with many properties that will enable us to do file I/O.</p>\n<p><strong><em>Did you know?</em></strong> <em>I/O is short for input/output. It's usage is widespread and all the hip tech companies are using it, like.io.</em></p>\n<p>The <code class=\"language-text\">fs</code> module contains tons of functionality! Chances are that if there is some operation you need to perform regarding files, the <code class=\"language-text\">fs</code> module supports it. The module also offers both synchronous and asynchronous implementations of these methods. We prefer to not block the thread and so we'll opt for the asynchronous flavors of these methods.</p>\n<h3>Creating a new file</h3>\n<p>To create a file, we can use the <code class=\"language-text\">writeFile</code> method. According to the documentation, there are a few ways to use it. The most straight forward way is:</p>\n<p>The code a<a href=\"https://gist.github.com/bgoonz/8898ad673bd2ecee9d93f8ec267cf213\" class=\"markup--anchor markup--p-anchor\">create-a-nnew-file.js (github.com)</a>bove will create a new file called <code class=\"language-text\">foo.txt</code> in the same directory as our <code class=\"language-text\">change-some-file.js</code> script. It will write the string <code class=\"language-text\">'Hello world!'</code> into that newly created file. The third argument specifies the encoding of the characters. There are different ways to encode characters; <a href=\"https://en.wikipedia.org/wiki/UTF-8\" class=\"markup--anchor markup--p-anchor\">UTF-8</a> is the most common and you'll use this in most scenarios. The fourth argument to <code class=\"language-text\">writeFile</code> is a callback that will be invoked when the write operation is complete. The docs indicate that if there is an error during the operation (such as an invalid encoding argument), an error object will be passed into the callback. This type of error handling is quite common for asynchronous functions. Like we are used to, since <code class=\"language-text\">writeFile</code> is asynchronous, we need to utilize <em>callback chaining</em> if we want to guarantee that commands occur <em>after</em> the write is complete or fails.</p>\n<p><em>Beware! If the file name specified to</em> <code class=\"language-text\">writeFile</code> <em>already exists, it will completely overwrite the contents of that file.</em></p>\n<p>We won't be using the <code class=\"language-text\">foo.txt</code> file in the rest of this reading.</p>\n<h3>Reading existing files</h3>\n<p>To explore how to read a file, we'll use VSCode to manually create a <code class=\"language-text\">poetry.txt</code> file within the same directory as our <code class=\"language-text\">change-some-file.js</code> script. Be sure to create this if you are following along.</p>\n<p>Our <code class=\"language-text\">poetry.txt</code> file will contain the following lines:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">My code fails\n\nI do not know why\n\nMy code works\n\nI do not know why</code></pre></div>\n<p>We can use the <code class=\"language-text\">readFile</code> method to read the contents of this file. The method accepts very similar arguments to <code class=\"language-text\">writeFile</code>, except that the callback may be passed an error object and string containing the file contents. In the snippet below, we have replaced our previous <code class=\"language-text\">writeFile</code> code with <code class=\"language-text\">readFile</code>:</p>\n<blockquote>\n<p>Running the code above would print the following in the terminal:</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">THE CONTENTS ARE:\n\nMy code fails\n\nI do not know why\n\nMy code works\n\nI do not know why</code></pre></div>\n<p>Success! From here, you can do anything you please with the data read from the file. For example, since <code class=\"language-text\">data</code> is a string, we could split the string on the newline character <code class=\"language-text\">\\n</code> to obtain an array of the file's lines:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">THE CONTENTS ARE:\n\n[ 'My code fails',\n\n'I do not know why',\n\n'My code works',\n\n'I do not know why' ]\n\nThe third line is My code works</code></pre></div>\n<h3>File I/O</h3>\n<p><em>Using the same</em> <code class=\"language-text\">poetry.txt</code> <em>file from before:</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">My code fails\n\nI do not know why\n\nMy code works\n\nI do not know why</code></pre></div>\n<p>Let's replace occurrences of the phrase ‘do not' with the word ‘should'.</p>\n<p>We can read the contents of the file as a string, manipulate this string, then write this new string back into the file.</p>\n<p>We'll need to utilize callback chaining in order for this to work since our file I/O is asynchronous:</p>\n<p>Executing the script above will edit the <code class=\"language-text\">poetry.txt</code> file to contain:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">My code fails\n\nI should know why\n\nMy code works\n\nI should know why</code></pre></div>\n<h4>Refactor:</h4>\n<h4>If you found this guide helpful feel free to checkout my github/gists where I host similar content:</h4>\n<p><a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--p-anchor\">bgoonz's gists · GitHub</a></p>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>"},{"url":"/docs/overflow/node-js-language/","relativePath":"docs/overflow/node-js-language.md","relativeDir":"docs/overflow","base":"node-js-language.md","name":"node-js-language","frontmatter":{"title":"packagejson","weight":0,"excerpt":"The package.json file is a key element in lots of app codebases based on the Node.js ecosystem.","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>If you work with JavaScript, or you've ever interacted with a JavaScript project, Node.js or a frontend project, you surely met the package.json file.</p>\n<p>What's that for? What should you know about it, and what are some of the cool things you can do with it?</p>\n<p>The package.json file is kind of a manifest for your project. It can do a lot of things, completely unrelated. It's a central repository of configuration for tools, for example. It's also where npm and yarn store the names and versions for all the installed packages.</p>\n<h2>The file structure</h2>\n<p>Here's an example package.json file:</p>\n<p>It's empty! There are no fixed requirements of what should be in a package.json file, for an application. The only requirement is that it respects the JSON format, otherwise it cannot be read by programs that try to access its properties programmatically.</p>\n<p>If you're building a Node.js package that you want to distribute over npm things change radically, and you must have a set of properties that will help other people use it. We'll see more about this later on.</p>\n<p>This is another package.json:</p>\n<p>It defines a name property, which tells the name of the app, or package, that's contained in the same folder where this file lives.</p>\n<p>Here's a much more complex example, which was extracted from a sample Vue.js application:</p>\n<p>there are <em>lots</em> of things going on here:</p>\n<ul>\n<li>version indicates the current version</li>\n<li></li>\n<li>name sets the application/package name</li>\n<li></li>\n<li>description is a brief description of the app/package</li>\n<li></li>\n<li>main set the entry point for the application</li>\n<li></li>\n<li>private if set to true prevents the app/package to be accidentally</li>\n<li></li>\n<li>scripts defines a set of node scripts you can run</li>\n<li>dependencies sets a list of npm packages installed as dependencies</li>\n<li>devDependencies sets a list of npm packages installed as development dependencies</li>\n<li>engines sets which versions of Node.js this package/app works on</li>\n<li>browserslist is used to tell which browsers (and their versions) you want to support</li>\n</ul>\n<p>All those properties are used by either npm or other tools that we can use.</p>\n<h2>Properties breakdown</h2>\n<p>This section describes the properties you can use in detail. We refer to \"package\" but the same thing applies to local applications which you do not use as packages.</p>\n<p>Most of those properties are only used on <a href=\"https://www.npmjs.com/\">https://www.npmjs.com/</a>, others by scripts that interact with your code, like npm or others.</p>\n<h3>name</h3>\n<p>Sets the package name.</p>\n<p>Example:</p>\n<p>The name must be less than 214 characters, must not have spaces, it can only contain lowercase letters, hyphens (-) or underscores (_).</p>\n<p>This is because when a package is published on npm, it gets its own URL based on this property.</p>\n<p>If you published this package publicly on GitHub, a good value for this property is the GitHub repository name.</p>\n<h3>author</h3>\n<p>Lists the package author name</p>\n<p>Example:</p>\n<p>Can also be used with this format:</p>\n<h3>contributors</h3>\n<p>As well as the author, the project can have one or more contributors. This property is an array that lists them.</p>\n<p>Example:</p>\n<p>Can also be used with this format:</p>\n<h3>bugs</h3>\n<p>Links to the package issue tracker, most likely a GitHub issues page</p>\n<p>Example:</p>\n<h3>homepage</h3>\n<p>Sets the package homepage</p>\n<p>Example:</p>\n<h3>version</h3>\n<p>Indicates the current version of the package.</p>\n<p>Example:</p>\n<p>This property follows the semantic versioning (semver) notation for versions, which means the version is always expressed with 3 numbers: x.x.x.</p>\n<p>The first number is the major version, the second the minor version and the third is the patch version.</p>\n<p>There is a meaning in these numbers: a release that only fixes bugs is a patch release, a release that introduces backward-compatible changes is a minor release, a major release can have breaking changes.</p>\n<h3>license</h3>\n<p>Indicates the license of the package.</p>\n<p>Example:</p>\n<h3>keywords</h3>\n<p>This property contains an array of keywords that associate with what your package does.</p>\n<p>Example:</p>\n<p>This helps people find your package when navigating similar packages, or when browsing the <a href=\"https://www.npmjs.com/\">https://www.npmjs.com/</a> website.</p>\n<h3>description</h3>\n<p>This property contains a brief description of the package</p>\n<p>Example:</p>\n<p>This is especially useful if you decide to publish your package to npm so that people can find out what the package is about.</p>\n<h3>repository</h3>\n<p>This property specifies where this package repository is located.</p>\n<p>Example:</p>\n<p>Notice the github prefix. There are other popular services baked in:</p>\n<p>You can explicitly set the version control system:</p>\n<p>You can use different version control systems:</p>\n<h3>main</h3>\n<p>Sets the entry point for the package.</p>\n<p>When you import this package in an application, that's where the application will search for the module exports.</p>\n<p>Example:</p>\n<h3>private</h3>\n<p>if set to true prevents the app/package to be accidentally published on npm</p>\n<p>Example:</p>\n<h3>scripts</h3>\n<p>Defines a set of node scripts you can run</p>\n<p>Example:</p>\n<p>These scripts are command line applications. You can run them by calling npm run XXXX or yarn XXXX, where XXXX is the command name. Example: npm run dev.</p>\n<p>You can use any name you want for a command, and scripts can do literally anything you want.</p>\n<h3>dependencies</h3>\n<p>Sets a list of npm packages installed as dependencies.</p>\n<p>When you install a package using npm or yarn:</p>\n<p>that package is automatically inserted in this list.</p>\n<p>Example:</p>\n<h3>devDependencies</h3>\n<p>Sets a list of npm packages installed as development dependencies.</p>\n<p>They differ from dependencies because they are meant to be installed only on a development machine, not needed to run the code in production.</p>\n<p>When you install a package using npm or yarn:</p>\n<p>that package is automatically inserted in this list.</p>\n<p>Example:</p>\n<h3>engines</h3>\n<p>Sets which versions of Node.js and other commands this package/app work on</p>\n<p>Example:</p>\n<h3>browserslist</h3>\n<p>Is used to tell which browsers (and their versions) you want to support. It's referenced by Babel, Autoprefixer, and other tools, to only add the polyfills and fallbacks needed to the browsers you target.</p>\n<p>Example:</p>\n<p>This configuration means you want to support the last 2 major versions of all browsers with at least 1% of usage (from the <a href=\"https://caniuse.com/\">CanIUse.com</a> stats), except IE8 and lower.</p>\n<p>(<a href=\"https://www.npmjs.com/package/browserslist\">see more</a>)</p>\n<h3>Command-specific properties</h3>\n<p>The package.json file can also host command-specific configuration, for example for Babel, ESLint, and more.</p>\n<p>Each has a specific property, like eslintConfig, babel and others. Those are command-specific, and you can find how to use those in the respective command/project documentation.</p>\n<h2>Package versions</h2>\n<p>You have seen in the description above version numbers like these: ~3.0.0 or ^0.13.0. What do they mean, and which other version specifiers can you use?</p>\n<p>That symbol specifies which updates your package accepts, from that dependency.</p>\n<p>Given that using semver (semantic versioning) all versions have 3 digits, the first being the major release, the second the minor release and the third is the patch release, you have these \"<a href=\"https://nodejs.dev/learn/semantic-versioning-using-npm/\">Rules</a>\".</p>\n<p>You can combine most of the versions in ranges, like this: 1.0.0 || >=1.1.0 &#x3C;1.2.0, to either use 1.0.0 or one release from 1.1.0 up, but lower than 1.2.0.</p>\n<h1>Cheat Sheet:</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * SYNOPSIS\n * http://nodejs.org/api/synopsis.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token keyword\">var</span> http <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'http'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// An example of a web server written with Node which responds with 'Hello World'.</span>\n<span class=\"token comment\">// To run the server, put the code into a file called example.js and execute it with the node program.</span>\nhttp<span class=\"token punctuation\">.</span><span class=\"token function\">createServer</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">request<span class=\"token punctuation\">,</span> response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  response<span class=\"token punctuation\">.</span><span class=\"token function\">writeHead</span><span class=\"token punctuation\">(</span><span class=\"token number\">200</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token string-property property\">'Content-Type'</span><span class=\"token operator\">:</span> <span class=\"token string\">'text/plain'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  response<span class=\"token punctuation\">.</span><span class=\"token function\">end</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello World\\n'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">listen</span><span class=\"token punctuation\">(</span><span class=\"token number\">8124</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Server running at http://127.0.0.1:8124/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * GLOBAL OBJECTS\n * http://nodejs.org/api/globals.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// In browsers, the top-level scope is the global scope.</span>\n<span class=\"token comment\">// That means that in browsers if you're in the global scope var something will define a global variable.</span>\n<span class=\"token comment\">// In Node this is different. The top-level scope is not the global scope; var something inside a Node module will be local to that module.</span>\n\n__filename<span class=\"token punctuation\">;</span>  <span class=\"token comment\">// The filename of the code being executed. (absolute path)</span>\n__dirname<span class=\"token punctuation\">;</span>   <span class=\"token comment\">// The name of the directory that the currently executing script resides in. (absolute path)</span>\nmodule<span class=\"token punctuation\">;</span>      <span class=\"token comment\">// A reference to the current module. In particular module.exports is used for defining what a module exports and makes available through require().</span>\nexports<span class=\"token punctuation\">;</span>     <span class=\"token comment\">// A reference to the module.exports that is shorter to type.</span>\nprocess<span class=\"token punctuation\">;</span>     <span class=\"token comment\">// The process object is a global object and can be accessed from anywhere. It is an instance of EventEmitter.</span>\nBuffer<span class=\"token punctuation\">;</span>      <span class=\"token comment\">// The Buffer class is a global type for dealing with binary data directly.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * CONSOLE\n * http://nodejs.org/api/console.html\n * ******************************************************************************************* */</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>data<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Prints to stdout with newline.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">info</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>data<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Same as console.log.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>data<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Same as console.log but prints to stderr.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">warn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>data<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Same as console.error.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">dir</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                       <span class=\"token comment\">// Uses util.inspect on obj and prints resulting string to stdout.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">time</span><span class=\"token punctuation\">(</span>label<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                    <span class=\"token comment\">// Mark a time.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">timeEnd</span><span class=\"token punctuation\">(</span>label<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                 <span class=\"token comment\">// Finish timer, record output.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">trace</span><span class=\"token punctuation\">(</span>label<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                   <span class=\"token comment\">// Print a stack trace to stderr of the current position.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">assert</span><span class=\"token punctuation\">(</span>expression<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Same as assert.ok() where if the expression evaluates as false throw an AssertionError with message.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * TIMERS\n * http://nodejs.org/api/timers.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>arg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// To schedule execution of a one-time callback after delay milliseconds. Optionally you can also pass arguments to the callback.</span>\n<span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                             <span class=\"token comment\">// Stop a timer that was previously created with setTimeout().</span>\n<span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>arg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// To schedule the repeated execution of callback every delay milliseconds. Optionally you can also pass arguments to the callback.</span>\n<span class=\"token function\">clearInterval</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                            <span class=\"token comment\">// Stop a timer that was previously created with setInterval().</span>\n<span class=\"token function\">setImmediate</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>arg<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// To schedule the \"immediate\" execution of callback after I/O events callbacks and before setTimeout and setInterval.</span>\n<span class=\"token function\">clearImmediate</span><span class=\"token punctuation\">(</span>immediateObject<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Stop a timer that was previously created with setImmediate().</span>\n\n<span class=\"token function\">unref</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Allow you to create a timer that is active but if it is the only item left in the event loop, node won't keep the program running.</span>\n<span class=\"token function\">ref</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// If you had previously unref()d a timer you can call ref() to explicitly request the timer hold the program open.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * MODULES\n * http://nodejs.org/api/modules.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token keyword\">var</span> module <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./module.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// Loads the module module.js in the same directory.</span>\nmodule<span class=\"token punctuation\">.</span><span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./another_module.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// load another_module as if require() was called from the module itself.</span>\n\nmodule<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">;</span>        <span class=\"token comment\">// The identifier for the module. Typically this is the fully resolved filename.</span>\nmodule<span class=\"token punctuation\">.</span>filename<span class=\"token punctuation\">;</span>  <span class=\"token comment\">// The fully resolved filename to the module.</span>\nmodule<span class=\"token punctuation\">.</span>loaded<span class=\"token punctuation\">;</span>    <span class=\"token comment\">// Whether or not the module is done loading, or is in the process of loading.</span>\nmodule<span class=\"token punctuation\">.</span>parent<span class=\"token punctuation\">;</span>    <span class=\"token comment\">// The module that required this one.</span>\nmodule<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">;</span>  <span class=\"token comment\">// The module objects required by this one.</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">area</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token constant\">PI</span> <span class=\"token operator\">*</span> r <span class=\"token operator\">*</span> r<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// If you want the root of your module's export to be a function (such as a constructor)</span>\n<span class=\"token comment\">// or if you want to export a complete object in one assignment instead of building it one property at a time,</span>\n<span class=\"token comment\">// assign it to module.exports instead of exports.</span>\nmodule<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">width</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">area</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> width <span class=\"token operator\">*</span> width<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * PROCESS\n * http://nodejs.org/api/process.html\n * ******************************************************************************************* */</span>\n\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'exit'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">code</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>              <span class=\"token comment\">// Emitted when the process is about to exit</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'uncaughtException'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Emitted when an exception bubbles all the way back to the event loop. (should not be used)</span>\n\nprocess<span class=\"token punctuation\">.</span>stdout<span class=\"token punctuation\">;</span>           <span class=\"token comment\">// A writable stream to stdout.</span>\nprocess<span class=\"token punctuation\">.</span>stderr<span class=\"token punctuation\">;</span>           <span class=\"token comment\">// A writable stream to stderr.</span>\nprocess<span class=\"token punctuation\">.</span>stdin<span class=\"token punctuation\">;</span>            <span class=\"token comment\">// A readable stream for stdin.</span>\n\nprocess<span class=\"token punctuation\">.</span>argv<span class=\"token punctuation\">;</span>             <span class=\"token comment\">// An array containing the command line arguments.</span>\nprocess<span class=\"token punctuation\">.</span>env<span class=\"token punctuation\">;</span>              <span class=\"token comment\">// An object containing the user environment.</span>\nprocess<span class=\"token punctuation\">.</span>execPath<span class=\"token punctuation\">;</span>         <span class=\"token comment\">// This is the absolute pathname of the executable that started the process.</span>\nprocess<span class=\"token punctuation\">.</span>execArgv<span class=\"token punctuation\">;</span>         <span class=\"token comment\">// This is the set of node-specific command line options from the executable that started the process.</span>\n\nprocess<span class=\"token punctuation\">.</span>arch<span class=\"token punctuation\">;</span>             <span class=\"token comment\">// What processor architecture you're running on: 'arm', 'ia32', or 'x64'.</span>\nprocess<span class=\"token punctuation\">.</span>config<span class=\"token punctuation\">;</span>           <span class=\"token comment\">// An Object containing the JavaScript representation of the configure options that were used to compile the current node executable.</span>\nprocess<span class=\"token punctuation\">.</span>pid<span class=\"token punctuation\">;</span>              <span class=\"token comment\">// The PID of the process.</span>\nprocess<span class=\"token punctuation\">.</span>platform<span class=\"token punctuation\">;</span>         <span class=\"token comment\">// What platform you're running on: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'.</span>\nprocess<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Getter/setter to set what is displayed in 'ps'.</span>\nprocess<span class=\"token punctuation\">.</span>version<span class=\"token punctuation\">;</span>          <span class=\"token comment\">// A compiled-in property that exposes NODE_VERSION.</span>\nprocess<span class=\"token punctuation\">.</span>versions<span class=\"token punctuation\">;</span>         <span class=\"token comment\">// A property exposing version strings of node and its dependencies.</span>\n\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">abort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// This causes node to emit an abort. This will cause node to exit and generate a core file.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">chdir</span><span class=\"token punctuation\">(</span>dir<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>       <span class=\"token comment\">// Changes the current working directory of the process or throws an exception if that fails.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">cwd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Returns the current working directory of the process.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">exit</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>code<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>     <span class=\"token comment\">// Ends the process with the specified code. If omitted, exit uses the 'success' code 0.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">getgid</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Gets the group identity of the process.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">setgid</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>       <span class=\"token comment\">// Sets the group identity of the process.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">getuid</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Gets the user identity of the process.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">setuid</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>       <span class=\"token comment\">// Sets the user identity of the process.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">getgroups</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>      <span class=\"token comment\">// Returns an array with the supplementary group IDs.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">setgroups</span><span class=\"token punctuation\">(</span>grps<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Sets the supplementary group IDs.</span>\n\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">initgroups</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">,</span> extra_grp<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Reads /etc/group and initializes the group access list, using all groups of which the user is a member.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">kill</span><span class=\"token punctuation\">(</span>pid<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>signal<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// Send a signal to a process. pid is the process id and signal is the string describing the signal to send.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">memoryUsage</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                <span class=\"token comment\">// Returns an object describing the memory usage of the Node process measured in bytes.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">nextTick</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// On the next loop around the event loop call this callback.</span>\nprocess<span class=\"token punctuation\">.</span>maxTickDepth<span class=\"token punctuation\">;</span>                 <span class=\"token comment\">// Callbacks passed to process.nextTick will usually be called at the end of the current flow of execution, and are thus approximately as fast as calling a function synchronously.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">umask</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>mask<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                <span class=\"token comment\">// Sets or reads the process's file mode creation mask.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">uptime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                     <span class=\"token comment\">// Number of seconds Node has been running.</span>\nprocess<span class=\"token punctuation\">.</span><span class=\"token function\">hrtime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                     <span class=\"token comment\">// Returns the current high-resolution real time in a [seconds, nanoseconds] tuple Array.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * CHILD PROCESS\n * http://nodejs.org/api/child_process.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Node provides a tri-directional popen facility through the child_process module.</span>\n<span class=\"token comment\">// It is possible to stream data through a child's stdin, stdout, and stderr in a fully non-blocking way.</span>\n\nChildProcess<span class=\"token punctuation\">;</span>                                                 <span class=\"token comment\">// Class. ChildProcess is an EventEmitter.</span>\n\nchild<span class=\"token punctuation\">.</span>stdin<span class=\"token punctuation\">;</span>                                                  <span class=\"token comment\">// A Writable Stream that represents the child process's stdin</span>\nchild<span class=\"token punctuation\">.</span>stdout<span class=\"token punctuation\">;</span>                                                 <span class=\"token comment\">// A Readable Stream that represents the child process's stdout</span>\nchild<span class=\"token punctuation\">.</span>stderr<span class=\"token punctuation\">;</span>                                                 <span class=\"token comment\">// A Readable Stream that represents the child process's stderr.</span>\nchild<span class=\"token punctuation\">.</span>pid<span class=\"token punctuation\">;</span>                                                    <span class=\"token comment\">// The PID of the child process</span>\nchild<span class=\"token punctuation\">.</span>connected<span class=\"token punctuation\">;</span>                                              <span class=\"token comment\">// If .connected is false, it is no longer possible to send messages</span>\nchild<span class=\"token punctuation\">.</span><span class=\"token function\">kill</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>signal<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                         <span class=\"token comment\">// Send a signal to the child process</span>\nchild<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>sendHandle<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                            <span class=\"token comment\">// When using child_process.fork() you can write to the child using child.send(message, [sendHandle]) and messages are received by a 'message' event on the child.</span>\nchild<span class=\"token punctuation\">.</span><span class=\"token function\">disconnect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                           <span class=\"token comment\">// Close the IPC channel between parent and child, allowing the child to exit gracefully once there are no other connections keeping it alive.</span>\nchild_process<span class=\"token punctuation\">.</span><span class=\"token function\">spawn</span><span class=\"token punctuation\">(</span>command<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>args<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>              <span class=\"token comment\">// Launches a new process with the given command, with command line arguments in args. If omitted, args defaults to an empty Array.</span>\nchild_process<span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>command<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Runs a command in a shell and buffers the output.</span>\nchild_process<span class=\"token punctuation\">.</span><span class=\"token function\">execFile</span><span class=\"token punctuation\">(</span>file<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>args<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Runs a command in a shell and buffers the output.</span>\nchild_process<span class=\"token punctuation\">.</span><span class=\"token function\">fork</span><span class=\"token punctuation\">(</span>modulePath<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>args<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// This is a special case of the spawn() functionality for spawning Node processes. In addition to having all the methods in a normal ChildProcess instance, the returned object has a communication channel built-in.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * UTIL\n * http://nodejs.org/api/util.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// These functions are in the module 'util'. Use require('util') to access them.</span>\n\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">format</span><span class=\"token punctuation\">(</span>format<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// Returns a formatted string using the first argument as a printf-like format. (%s, %d, %j)</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">debug</span><span class=\"token punctuation\">(</span>string<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// A synchronous output function. Will block the process and output string immediately to stderr.</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Same as util.debug() except this will output all arguments immediately to stderr.</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">puts</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>              <span class=\"token comment\">// A synchronous output function. Will block the process and output all arguments to stdout with newlines after each argument.</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// A synchronous output function. Will block the process, cast each argument to a string then output to stdout. (no newlines)</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>string<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>              <span class=\"token comment\">// Output with timestamp on stdout.</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">inspect</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>opts<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Return a string representation of object, which is useful for debugging. (options: showHidden, depth, colors, customInspect)</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// Returns true if the given \"object\" is an Array. false otherwise.</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">isRegExp</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Returns true if the given \"object\" is a RegExp. false otherwise.</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">isDate</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Returns true if the given \"object\" is a Date. false otherwise.</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">isError</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// Returns true if the given \"object\" is an Error. false otherwise.</span>\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">promisify</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span>             <span class=\"token comment\">// Takes a function whose last argument is a callback and returns a version that returns promises.</span>\n\nutil<span class=\"token punctuation\">.</span><span class=\"token function\">inherits</span><span class=\"token punctuation\">(</span>constructor<span class=\"token punctuation\">,</span> superConstructor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Inherit the prototype methods from one constructor into another.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * EVENTS\n * http://nodejs.org/api/events.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// All objects which emit events are instances of events.EventEmitter. You can access this module by doing: require(\"events\");</span>\n<span class=\"token comment\">// To access the EventEmitter class, require('events').EventEmitter.</span>\n<span class=\"token comment\">// All EventEmitters emit the event 'newListener' when new listeners are added and 'removeListener' when a listener is removed.</span>\n\nemitter<span class=\"token punctuation\">.</span><span class=\"token function\">addListener</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">,</span> listener<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Adds a listener to the end of the listeners array for the specified event.</span>\nemitter<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">,</span> listener<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                 <span class=\"token comment\">// Same as emitter.addListener().</span>\nemitter<span class=\"token punctuation\">.</span><span class=\"token function\">once</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">,</span> listener<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>               <span class=\"token comment\">// Adds a one time listener for the event. This listener is invoked only the next time the event is fired, after which it is removed.</span>\nemitter<span class=\"token punctuation\">.</span><span class=\"token function\">removeListener</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">,</span> listener<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>     <span class=\"token comment\">// Remove a listener from the listener array for the specified event.</span>\nemitter<span class=\"token punctuation\">.</span><span class=\"token function\">removeAllListeners</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>event<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Removes all listeners, or those of the specified event.</span>\nemitter<span class=\"token punctuation\">.</span><span class=\"token function\">setMaxListeners</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                  <span class=\"token comment\">// By default EventEmitters will print a warning if more than 10 listeners are added for a particular event.</span>\nemitter<span class=\"token punctuation\">.</span><span class=\"token function\">listeners</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                    <span class=\"token comment\">// Returns an array of listeners for the specified event.</span>\nemitter<span class=\"token punctuation\">.</span><span class=\"token function\">emit</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>arg1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>arg2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Execute each of the listeners in order with the supplied arguments. Returns true if event had listeners, false otherwise.</span>\n\nEventEmitter<span class=\"token punctuation\">.</span><span class=\"token function\">listenerCount</span><span class=\"token punctuation\">(</span>emitter<span class=\"token punctuation\">,</span> event<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Return the number of listeners for a given event.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * STREAM\n * http://nodejs.org/api/stream.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// A stream is an abstract interface implemented by various objects in Node. For example a request to an HTTP server is a stream, as is stdout.</span>\n<span class=\"token comment\">// Streams are readable, writable, or both. All streams are instances of EventEmitter.</span>\n\n<span class=\"token comment\">// The Readable stream interface is the abstraction for a source of data that you are reading from.</span>\n<span class=\"token comment\">// In other words, data comes out of a Readable stream.</span>\n<span class=\"token comment\">// A Readable stream will not start emitting data until you indicate that you are ready to receive it.</span>\n<span class=\"token comment\">// Examples of readable streams include: http responses on the client, http requests on the server, fs read streams</span>\n<span class=\"token comment\">// zlib streams, crypto streams, tcp sockets, child process stdout and stderr, process.stdin.</span>\n\n<span class=\"token keyword\">var</span> readable <span class=\"token operator\">=</span> <span class=\"token function\">getReadableStreamSomehow</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readable'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// When a chunk of data can be read from the stream, it will emit a 'readable' event.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">chunk</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// If you attach a data event listener, then it will switch the stream into flowing mode, and data will be passed to your handler as soon as it is available.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'end'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// This event fires when there will be no more data to read.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'close'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>      <span class=\"token comment\">// Emitted when the underlying resource (for example, the backing file descriptor) has been closed. Not all streams will emit this.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'error'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>      <span class=\"token comment\">// Emitted if there was an error receiving data.</span>\n\n<span class=\"token comment\">// The read() method pulls some data out of the internal buffer and returns it. If there is no data available, then it will return null.</span>\n<span class=\"token comment\">// This method should only be called in non-flowing mode. In flowing-mode, this method is called automatically until the internal buffer is drained.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">read</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>size<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">setEncoding</span><span class=\"token punctuation\">(</span>encoding<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Call this function to cause the stream to return strings of the specified encoding instead of Buffer objects.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">resume</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                        <span class=\"token comment\">// This method will cause the readable stream to resume emitting data events.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">pause</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                         <span class=\"token comment\">// This method will cause a stream in flowing-mode to stop emitting data events.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">pipe</span><span class=\"token punctuation\">(</span>destination<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// This method pulls all the data out of a readable stream, and writes it to the supplied destination, automatically managing the flow so that the destination is not overwhelmed by a fast readable stream.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">unpipe</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>destination<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// This method will remove the hooks set up for a previous pipe() call. If the destination is not specified, then all pipes are removed.</span>\nreadable<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span>chunk<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                  <span class=\"token comment\">// This is useful in certain cases where a stream is being consumed by a parser, which needs to \"un-consume\" some data that it has optimistically pulled out of the source, so that the stream can be passed on to some other party.</span>\n\n<span class=\"token comment\">// The Writable stream interface is an abstraction for a destination that you are writing data to.</span>\n<span class=\"token comment\">// Examples of writable streams include: http requests on the client, http responses on the server, fs write streams,</span>\n<span class=\"token comment\">// zlib streams, crypto streams, tcp sockets, child process stdin, process.stdout, process.stderr.</span>\n\n<span class=\"token keyword\">var</span> writer <span class=\"token operator\">=</span> <span class=\"token function\">getWritableStreamSomehow</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nwritable<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span>chunk<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// This method writes some data to the underlying system, and calls the supplied callback once the data has been fully handled.</span>\nwriter<span class=\"token punctuation\">.</span><span class=\"token function\">once</span><span class=\"token punctuation\">(</span><span class=\"token string\">'drain'</span><span class=\"token punctuation\">,</span> write<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                    <span class=\"token comment\">// If a writable.write(chunk) call returns false, then the drain event will indicate when it is appropriate to begin writing more data to the stream.</span>\n\nwritable<span class=\"token punctuation\">.</span><span class=\"token function\">end</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>chunk<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Call this method when no more data will be written to the stream.</span>\nwriter<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'finish'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// When the end() method has been called, and all data has been flushed to the underlying system, this event is emitted.</span>\nwriter<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'pipe'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">src</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// This is emitted whenever the pipe() method is called on a readable stream, adding this writable to its set of destinations.</span>\nwriter<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'unpipe'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">src</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// This is emitted whenever the unpipe() method is called on a readable stream, removing this writable from its set of destinations.</span>\nwriter<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'error'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">src</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Emitted if there was an error when writing or piping data.</span>\n\n<span class=\"token comment\">// Duplex streams are streams that implement both the Readable and Writable interfaces. See above for usage.</span>\n<span class=\"token comment\">// Examples of Duplex streams include: tcp sockets, zlib streams, crypto streams.</span>\n\n<span class=\"token comment\">// Transform streams are Duplex streams where the output is in some way computed from the input. They implement both the Readable and Writable interfaces. See above for usage.</span>\n<span class=\"token comment\">// Examples of Transform streams include: zlib streams, crypto streams.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * FILE SYSTEM\n * http://nodejs.org/api/fs.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// To use this module do require('fs').</span>\n<span class=\"token comment\">// All the methods have asynchronous and synchronous forms.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">rename</span><span class=\"token punctuation\">(</span>oldPath<span class=\"token punctuation\">,</span> newPath<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Asynchronous rename. No arguments other than a possible exception are given to the completion callback.Asynchronous ftruncate. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">renameSync</span><span class=\"token punctuation\">(</span>oldPath<span class=\"token punctuation\">,</span> newPath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Synchronous rename.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">ftruncate</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> len<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Asynchronous ftruncate. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">ftruncateSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> len<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>              <span class=\"token comment\">// Synchronous ftruncate.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">truncate</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> len<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>       <span class=\"token comment\">// Asynchronous truncate. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">truncateSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> len<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Synchronous truncate.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">chown</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> uid<span class=\"token punctuation\">,</span> gid<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>     <span class=\"token comment\">// Asynchronous chown. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">chownSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> uid<span class=\"token punctuation\">,</span> gid<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Synchronous chown.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">fchown</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> uid<span class=\"token punctuation\">,</span> gid<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>      <span class=\"token comment\">// Asynchronous fchown. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">fchownSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> uid<span class=\"token punctuation\">,</span> gid<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Synchronous fchown.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">lchown</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> uid<span class=\"token punctuation\">,</span> gid<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// Asynchronous lchown. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">lchownSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> uid<span class=\"token punctuation\">,</span> gid<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// Synchronous lchown.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">chmod</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> mode<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Asynchronous chmod. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">chmodSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> mode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>               <span class=\"token comment\">// Synchronous chmod.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">fchmod</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> mode<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// Asynchronous fchmod. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">fchmodSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> mode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                <span class=\"token comment\">// Synchronous fchmod.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">lchmod</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> mode<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Asynchronous lchmod. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">lchmodSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> mode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>              <span class=\"token comment\">// Synchronous lchmod.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">stat</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                <span class=\"token comment\">// Asynchronous stat. The callback gets two arguments (err, stats) where stats is a fs.Stats object.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">statSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                      <span class=\"token comment\">// Synchronous stat. Returns an instance of fs.Stats.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">lstat</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>               <span class=\"token comment\">// Asynchronous lstat. The callback gets two arguments (err, stats) where stats is a fs.Stats object. lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">lstatSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                     <span class=\"token comment\">// Synchronous lstat. Returns an instance of fs.Stats.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">fstat</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                 <span class=\"token comment\">// Asynchronous fstat. The callback gets two arguments (err, stats) where stats is a fs.Stats object. fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor fd.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">fstatSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                       <span class=\"token comment\">// Synchronous fstat. Returns an instance of fs.Stats.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">link</span><span class=\"token punctuation\">(</span>srcpath<span class=\"token punctuation\">,</span> dstpath<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Asynchronous link. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">linkSync</span><span class=\"token punctuation\">(</span>srcpath<span class=\"token punctuation\">,</span> dstpath<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                   <span class=\"token comment\">// Synchronous link.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">symlink</span><span class=\"token punctuation\">(</span>srcpath<span class=\"token punctuation\">,</span> dstpath<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>type<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Asynchronous symlink. No arguments other than a possible exception are given to the completion callback. The type argument can be set to 'dir', 'file', or 'junction' (default is 'file') and is only available on Windows (ignored on other platforms)</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">symlinkSync</span><span class=\"token punctuation\">(</span>srcpath<span class=\"token punctuation\">,</span> dstpath<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>type<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Synchronous symlink.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readlink</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                     <span class=\"token comment\">// Asynchronous readlink. The callback gets two arguments (err, linkString).</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readlinkSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                           <span class=\"token comment\">// Synchronous readlink. Returns the symbolic link's string value.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">unlink</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                       <span class=\"token comment\">// Asynchronous unlink. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">unlinkSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                             <span class=\"token comment\">// Synchronous unlink.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">realpath</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>cache<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>     <span class=\"token comment\">// Asynchronous realpath. The callback gets two arguments (err, resolvedPath).</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">realpathSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>cache<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Synchronous realpath. Returns the resolved path.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">rmdir</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                 <span class=\"token comment\">// Asynchronous rmdir. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">rmdirSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                       <span class=\"token comment\">// Synchronous rmdir.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">mkdir</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>mode<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Asynchronous mkdir. No arguments other than a possible exception are given to the completion callback. mode defaults to 0777.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">mkdirSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>mode<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>               <span class=\"token comment\">// Synchronous mkdir.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readdir</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>               <span class=\"token comment\">// Asynchronous readdir. Reads the contents of a directory. The callback gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readdirSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                     <span class=\"token comment\">// Synchronous readdir. Returns an array of filenames excluding '.' and '..'.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">close</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                   <span class=\"token comment\">// Asynchronous close. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">closeSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                         <span class=\"token comment\">// Synchronous close.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">open</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> flags<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>mode<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Asynchronous file open.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">openSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> flags<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>mode<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Synchronous version of fs.open().</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">utimes</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> atime<span class=\"token punctuation\">,</span> mtime<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Change file timestamps of the file referenced by the supplied path.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">utimesSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> atime<span class=\"token punctuation\">,</span> mtime<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Synchronous version of fs.utimes().</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">futimes</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> atime<span class=\"token punctuation\">,</span> mtime<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Change the file timestamps of a file referenced by the supplied file descriptor.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">futimesSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> atime<span class=\"token punctuation\">,</span> mtime<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Synchronous version of fs.futimes().</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">fsync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                   <span class=\"token comment\">// Asynchronous fsync. No arguments other than a possible exception are given to the completion callback.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">fsyncSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                         <span class=\"token comment\">// Synchronous fsync.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> buffer<span class=\"token punctuation\">,</span> offset<span class=\"token punctuation\">,</span> length<span class=\"token punctuation\">,</span> position<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Write buffer to the file specified by fd.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> buffer<span class=\"token punctuation\">,</span> offset<span class=\"token punctuation\">,</span> length<span class=\"token punctuation\">,</span> position<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Synchronous version of fs.write(). Returns the number of bytes written.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">read</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> buffer<span class=\"token punctuation\">,</span> offset<span class=\"token punctuation\">,</span> length<span class=\"token punctuation\">,</span> position<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Read data from the file specified by fd.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readSync</span><span class=\"token punctuation\">(</span>fd<span class=\"token punctuation\">,</span> buffer<span class=\"token punctuation\">,</span> offset<span class=\"token punctuation\">,</span> length<span class=\"token punctuation\">,</span> position<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Synchronous version of fs.read. Returns the number of bytesRead.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readFile</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                <span class=\"token comment\">// Asynchronously reads the entire contents of a file.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readFileSync</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                      <span class=\"token comment\">// Synchronous version of fs.readFile. Returns the contents of the filename. If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFileSync</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// The synchronous version of fs.writeFile.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">appendFile</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Asynchronously append data to a file, creating the file if it not yet exists. data can be a string or a buffer.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">appendFileSync</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// The synchronous version of fs.appendFile.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">watch</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>listener<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Watch for changes on filename, where filename is either a file or a directory. The returned object is a fs.FSWatcher. The listener callback gets two arguments (event, filename). event is either 'rename' or 'change', and filename is the name of the file which triggered the event.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">exists</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                           <span class=\"token comment\">// Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false. (should not be used)</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">existsSync</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                 <span class=\"token comment\">// Synchronous version of fs.exists. (should not be used)</span>\n\n<span class=\"token comment\">// fs.Stats: objects returned from fs.stat(), fs.lstat() and fs.fstat() and their synchronous counterparts are of this type.</span>\nstats<span class=\"token punctuation\">.</span><span class=\"token function\">isFile</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nstats<span class=\"token punctuation\">.</span><span class=\"token function\">isDirectory</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nstats<span class=\"token punctuation\">.</span><span class=\"token function\">isBlockDevice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nstats<span class=\"token punctuation\">.</span><span class=\"token function\">isCharacterDevice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nstats<span class=\"token punctuation\">.</span><span class=\"token function\">isSymbolicLink</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\">// (only valid with fs.lstat())</span>\nstats<span class=\"token punctuation\">.</span><span class=\"token function\">isFIFO</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nstats<span class=\"token punctuation\">.</span><span class=\"token function\">isSocket</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">createReadStream</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Returns a new ReadStream object.</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">createWriteStream</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Returns a new WriteStream object.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * PATH\n * http://nodejs.org/api/fs.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Use require('path') to use this module.</span>\n<span class=\"token comment\">// This module contains utilities for handling and transforming file paths.</span>\n<span class=\"token comment\">// Almost all these methods perform only string transformations.</span>\n<span class=\"token comment\">// The file system is not consulted to check whether paths are valid.</span>\n\npath<span class=\"token punctuation\">.</span><span class=\"token function\">normalize</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                    <span class=\"token comment\">// Normalize a string path, taking care of '..' and '.' parts.</span>\npath<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>path1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>path2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Join all arguments together and normalize the resulting path.</span>\npath<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>from <span class=\"token operator\">...</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> to<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Resolves 'to' to an absolute path.</span>\npath<span class=\"token punctuation\">.</span><span class=\"token function\">relative</span><span class=\"token punctuation\">(</span>from<span class=\"token punctuation\">,</span> to<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>              <span class=\"token comment\">// Solve the relative path from 'from' to 'to'.</span>\npath<span class=\"token punctuation\">.</span><span class=\"token function\">dirname</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                      <span class=\"token comment\">// Return the directory name of a path. Similar to the Unix dirname command.</span>\npath<span class=\"token punctuation\">.</span><span class=\"token function\">basename</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>ext<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>              <span class=\"token comment\">// Return the last portion of a path. Similar to the Unix basename command.</span>\npath<span class=\"token punctuation\">.</span><span class=\"token function\">extname</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                      <span class=\"token comment\">// Return the extension of the path, from the last '.' to end of string in the last portion of the path.</span>\n\npath<span class=\"token punctuation\">.</span>sep<span class=\"token punctuation\">;</span>                             <span class=\"token comment\">// The platform-specific file separator. '\\\\' or '/'.</span>\npath<span class=\"token punctuation\">.</span>delimiter<span class=\"token punctuation\">;</span>                       <span class=\"token comment\">// The platform-specific path delimiter, ';' or ':'.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * HTTP\n * http://nodejs.org/api/http.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// To use the HTTP server and client one must require('http').</span>\n\nhttp<span class=\"token punctuation\">.</span><span class=\"token constant\">STATUS_CODES</span><span class=\"token punctuation\">;</span>                                             <span class=\"token comment\">// A collection of all the standard HTTP response status codes, and the short description of each.</span>\nhttp<span class=\"token punctuation\">.</span><span class=\"token function\">request</span><span class=\"token punctuation\">(</span>options<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                             <span class=\"token comment\">// This function allows one to transparently issue requests.</span>\nhttp<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>options<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                 <span class=\"token comment\">// Set the method to GET and calls req.end() automatically.</span>\n\nserver <span class=\"token operator\">=</span> http<span class=\"token punctuation\">.</span><span class=\"token function\">createServer</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>requestListener<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                 <span class=\"token comment\">// Returns a new web server object. The requestListener is a function which is automatically added to the 'request' event.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">listen</span><span class=\"token punctuation\">(</span>port<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>hostname<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>backlog<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Begin accepting connections on the specified port and hostname.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">listen</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                               <span class=\"token comment\">// Start a UNIX socket server listening for connections on the given path.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">listen</span><span class=\"token punctuation\">(</span>handle<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                             <span class=\"token comment\">// The handle object can be set to either a server or socket (anything with an underlying _handle member), or a {fd: &lt;n>} object.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">close</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                      <span class=\"token comment\">// Stops the server from accepting new connections.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>msecs<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                            <span class=\"token comment\">// Sets the timeout value for sockets, and emits a 'timeout' event on the Server object, passing the socket as an argument, if a timeout occurs.</span>\n\nserver<span class=\"token punctuation\">.</span>maxHeadersCount<span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Limits maximum incoming headers count, equal to 1000 by default. If set to 0 - no limit will be applied.</span>\nserver<span class=\"token punctuation\">.</span>timeout<span class=\"token punctuation\">;</span>          <span class=\"token comment\">// The number of milliseconds of inactivity before a socket is presumed to have timed out.</span>\n\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'request'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">request<span class=\"token punctuation\">,</span> response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Emitted each time there is a request.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'connection'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">socket</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                <span class=\"token comment\">// When a new TCP stream is established.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'close'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                           <span class=\"token comment\">// Emitted when the server closes.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'checkContinue'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">request<span class=\"token punctuation\">,</span> response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Emitted each time a request with an http Expect: 100-continue is received.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'connect'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">request<span class=\"token punctuation\">,</span> socket<span class=\"token punctuation\">,</span> head</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// Emitted each time a client requests a http CONNECT method.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'upgrade'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">request<span class=\"token punctuation\">,</span> socket<span class=\"token punctuation\">,</span> head</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// Emitted each time a client requests a http upgrade.</span>\nserver<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'clientError'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">exception<span class=\"token punctuation\">,</span> socket</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// If a client connection emits an 'error' event - it will forwarded here.</span>\n\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span>chunk<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                              <span class=\"token comment\">// Sends a chunk of the body.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">end</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>data<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                               <span class=\"token comment\">// Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">abort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                               <span class=\"token comment\">// Aborts a request.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>timeout<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                       <span class=\"token comment\">// Once a socket is assigned to this request and is connected socket.setTimeout() will be called.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">setNoDelay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>noDelay<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                 <span class=\"token comment\">// Once a socket is assigned to this request and is connected socket.setNoDelay() will be called.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">setSocketKeepAlive</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>enable<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>initialDelay<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>          <span class=\"token comment\">// Once a socket is assigned to this request and is connected socket.setKeepAlive() will be called.</span>\n\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'response'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                <span class=\"token comment\">// Emitted when a response is received to this request. This event is emitted only once.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'socket'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">socket</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                    <span class=\"token comment\">// Emitted after a socket is assigned to this request.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'connect'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response<span class=\"token punctuation\">,</span> socket<span class=\"token punctuation\">,</span> head</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Emitted each time a server responds to a request with a CONNECT method. If this event isn't being listened for, clients receiving a CONNECT method will have their connections closed.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'upgrade'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response<span class=\"token punctuation\">,</span> socket<span class=\"token punctuation\">,</span> head</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Emitted each time a server responds to a request with an upgrade. If this event isn't being listened for, clients receiving an upgrade header will have their connections closed.</span>\nrequest<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'continue'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                        <span class=\"token comment\">// Emitted when the server sends a '100 Continue' HTTP response, usually because the request contained 'Expect: 100-continue'. This is an instruction that the client should send the request body.</span>\n\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span>chunk<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                             <span class=\"token comment\">// This sends a chunk of the response body. If this merthod is called and response.writeHead() has not been called, it will switch to implicit header mode and flush the implicit headers.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">writeContinue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                      <span class=\"token comment\">// Sends a HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">writeHead</span><span class=\"token punctuation\">(</span>statusCode<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>reasonPhrase<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>headers<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>     <span class=\"token comment\">// Sends a response header to the request.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>msecs<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                          <span class=\"token comment\">// Sets the Socket's timeout value to msecs. If a callback is provided, then it is added as a listener on the 'timeout' event on the response object.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">setHeader</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                               <span class=\"token comment\">// Sets a single header value for implicit headers. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here if you need to send multiple headers with the same name.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">getHeader</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                      <span class=\"token comment\">// Reads out a header that's already been queued but not sent to the client. Note that the name is case insensitive.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">removeHeader</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                   <span class=\"token comment\">// Removes a header that's queued for implicit sending.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">addTrailers</span><span class=\"token punctuation\">(</span>headers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                 <span class=\"token comment\">// This method adds HTTP trailing headers (a header but at the end of the message) to the response.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">end</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>data<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                              <span class=\"token comment\">// This method signals to the server that all of the response headers and body have been sent; that server should consider this message complete. The method, response.end(), MUST be called on each response.</span>\n\nresponse<span class=\"token punctuation\">.</span>statusCode<span class=\"token punctuation\">;</span>                                           <span class=\"token comment\">// When using implicit headers (not calling response.writeHead() explicitly), this property controls the status code that will be sent to the client when the headers get flushed.</span>\nresponse<span class=\"token punctuation\">.</span>headersSent<span class=\"token punctuation\">;</span>                                          <span class=\"token comment\">// Boolean (read-only). True if headers were sent, false otherwise.</span>\nresponse<span class=\"token punctuation\">.</span>sendDate<span class=\"token punctuation\">;</span>                                             <span class=\"token comment\">// When true, the Date header will be automatically generated and sent in the response if it is not already present in the headers. Defaults to true.</span>\n\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'close'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Indicates that the underlying connection was terminated before response.end() was called or able to flush.</span>\nresponse<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'finish'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Emitted when the response has been sent.</span>\n\nmessage<span class=\"token punctuation\">.</span>httpVersion<span class=\"token punctuation\">;</span>                    <span class=\"token comment\">// In case of server request, the HTTP version sent by the client. In the case of client response, the HTTP version of the connected-to server.</span>\nmessage<span class=\"token punctuation\">.</span>headers<span class=\"token punctuation\">;</span>                        <span class=\"token comment\">// The request/response headers object.</span>\nmessage<span class=\"token punctuation\">.</span>trailers<span class=\"token punctuation\">;</span>                       <span class=\"token comment\">// The request/response trailers object. Only populated after the 'end' event.</span>\nmessage<span class=\"token punctuation\">.</span>method<span class=\"token punctuation\">;</span>                         <span class=\"token comment\">// The request method as a string. Read only. Example: 'GET', 'DELETE'.</span>\nmessage<span class=\"token punctuation\">.</span>url<span class=\"token punctuation\">;</span>                            <span class=\"token comment\">// Request URL string. This contains only the URL that is present in the actual HTTP request.</span>\nmessage<span class=\"token punctuation\">.</span>statusCode<span class=\"token punctuation\">;</span>                     <span class=\"token comment\">// The 3-digit HTTP response status code. E.G. 404.</span>\nmessage<span class=\"token punctuation\">.</span>socket<span class=\"token punctuation\">;</span>                         <span class=\"token comment\">// The net.Socket object associated with the connection.</span>\n\nmessage<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>msecs<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// Calls message.connection.setTimeout(msecs, callback).</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * URL\n * http://nodejs.org/api/url.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// This module has utilities for URL resolution and parsing. Call require('url') to use it.</span>\n\nurl<span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>urlStr<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>parseQueryString<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>slashesDenoteHost<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Take a URL string, and return an object.</span>\nurl<span class=\"token punctuation\">.</span><span class=\"token function\">format</span><span class=\"token punctuation\">(</span>urlObj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                          <span class=\"token comment\">// Take a parsed URL object, and return a formatted URL string.</span>\nurl<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span>from<span class=\"token punctuation\">,</span> to<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                       <span class=\"token comment\">// Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * QUERY STRING\n * http://nodejs.org/api/querystring.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// This module provides utilities for dealing with query strings. Call require('querystring') to use it.</span>\n\nquerystring<span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>sep<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>eq<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Serialize an object to a query string. Optionally override the default separator ('&amp;') and assignment ('=') characters.</span>\nquerystring<span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>sep<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>eq<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Deserialize a query string to an object. Optionally override the default separator ('&amp;') and assignment ('=') characters.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * ASSERT\n * http://nodejs.org/api/assert.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// This module is used for writing unit tests for your applications, you can access it with require('assert').</span>\n\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">fail</span><span class=\"token punctuation\">(</span>actual<span class=\"token punctuation\">,</span> expected<span class=\"token punctuation\">,</span> message<span class=\"token punctuation\">,</span> operator<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>     <span class=\"token comment\">// Throws an exception that displays the values for actual and expected separated by the provided operator.</span>\n<span class=\"token function\">assert</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> assert<span class=\"token punctuation\">.</span><span class=\"token function\">ok</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message);</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">equal</span><span class=\"token punctuation\">(</span>actual<span class=\"token punctuation\">,</span> expected<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Tests shallow, coercive equality with the equal comparison operator ( == ).</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">notEqual</span><span class=\"token punctuation\">(</span>actual<span class=\"token punctuation\">,</span> expected<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Tests shallow, coercive non-equality with the not equal comparison operator ( != ).</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">deepEqual</span><span class=\"token punctuation\">(</span>actual<span class=\"token punctuation\">,</span> expected<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>        <span class=\"token comment\">// Tests for deep equality.</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">notDeepEqual</span><span class=\"token punctuation\">(</span>actual<span class=\"token punctuation\">,</span> expected<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>     <span class=\"token comment\">// Tests for any deep inequality.</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">strictEqual</span><span class=\"token punctuation\">(</span>actual<span class=\"token punctuation\">,</span> expected<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>      <span class=\"token comment\">// Tests strict equality, as determined by the strict equality operator ( === )</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">notStrictEqual</span><span class=\"token punctuation\">(</span>actual<span class=\"token punctuation\">,</span> expected<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>   <span class=\"token comment\">// Tests strict non-equality, as determined by the strict not equal operator ( !== )</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">throws</span><span class=\"token punctuation\">(</span>block<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>error<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Expects block to throw an error. error can be constructor, RegExp or validation function.</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">doesNotThrow</span><span class=\"token punctuation\">(</span>block<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                <span class=\"token comment\">// Expects block not to throw an error, see assert.throws for details.</span>\nassert<span class=\"token punctuation\">.</span><span class=\"token function\">ifError</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                <span class=\"token comment\">// Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * OS\n * http://nodejs.org/api/os.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Provides a few basic operating-system related utility functions.</span>\n<span class=\"token comment\">// Use require('os') to access this module.</span>\n\nos<span class=\"token punctuation\">.</span><span class=\"token function\">tmpdir</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Returns the operating system's default directory for temp files.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">endianness</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>         <span class=\"token comment\">// Returns the endianness of the CPU. Possible values are \"BE\" or \"LE\".</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">hostname</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Returns the hostname of the operating system.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">type</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>               <span class=\"token comment\">// Returns the operating system name.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">platform</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Returns the operating system platform.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">arch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>               <span class=\"token comment\">// Returns the operating system CPU architecture.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">release</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Returns the operating system release.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">uptime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>             <span class=\"token comment\">// Returns the system uptime in seconds.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">loadavg</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Returns an array containing the 1, 5, and 15 minute load averages.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">totalmem</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>           <span class=\"token comment\">// Returns the total amount of system memory in bytes.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">freemem</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>            <span class=\"token comment\">// Returns the amount of free system memory in bytes.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">cpus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>               <span class=\"token comment\">// Returns an array of objects containing information about each CPU/core installed: model, speed (in MHz), and times (an object containing the number of milliseconds the CPU/core spent in: user, nice, sys, idle, and irq).</span>\nos<span class=\"token punctuation\">.</span><span class=\"token function\">networkInterfaces</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Get a list of network interfaces.</span>\nos<span class=\"token punctuation\">.</span><span class=\"token constant\">EOL</span><span class=\"token punctuation\">;</span>                  <span class=\"token comment\">// A constant defining the appropriate End-of-line marker for the operating system.</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * BUFFER\n * http://nodejs.org/api/buffer.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Buffer is used to dealing with binary data</span>\n<span class=\"token comment\">// Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap</span>\n\nBuffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span>size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                                  <span class=\"token comment\">// Allocates a new buffer of size octets.</span>\nBuffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                                 <span class=\"token comment\">// Allocates a new buffer using an array of octets.</span>\nBuffer<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                       <span class=\"token comment\">// Allocates a new buffer containing the given str. encoding defaults to 'utf8'.</span>\n\nBuffer<span class=\"token punctuation\">.</span><span class=\"token function\">isEncoding</span><span class=\"token punctuation\">(</span>encoding<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                        <span class=\"token comment\">// Returns true if the encoding is a valid encoding argument, or false otherwise.</span>\nBuffer<span class=\"token punctuation\">.</span><span class=\"token function\">isBuffer</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                               <span class=\"token comment\">// Tests if obj is a Buffer</span>\nBuffer<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>totalLength<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                 <span class=\"token comment\">// Returns a buffer which is the result of concatenating all the buffers in the list together.</span>\nBuffer<span class=\"token punctuation\">.</span><span class=\"token function\">byteLength</span><span class=\"token punctuation\">(</span>string<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                              <span class=\"token comment\">// Gives the actual byte length of a string.</span>\n\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span>string<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>offset<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>length<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                  <span class=\"token comment\">// Writes string to the buffer at offset using the given encoding</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>encoding<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>end<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                           <span class=\"token comment\">// Decodes and returns a string from buffer data encoded with encoding (defaults to 'utf8') beginning at start (defaults to 0) and ending at end (defaults to buffer.length).</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">toJSON</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                                       <span class=\"token comment\">// Returns a JSON-representation of the Buffer instance, which is identical to the output for JSON Arrays</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">copy</span><span class=\"token punctuation\">(</span>targetBuffer<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>targetStart<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>sourceStart<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>sourceEnd<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token comment\">// Does copy between buffers. The source and target regions can be overlapped</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>end<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                          <span class=\"token comment\">// Returns a new buffer which references the same memory as the old, but offset and cropped by the start (defaults to 0) and end (defaults to buffer.length) indexes. Negative indexes start from the end of the buffer.</span>\nbuf<span class=\"token punctuation\">.</span><span class=\"token function\">fill</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>offset<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>end<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>                                   <span class=\"token comment\">// Fills the buffer with the specified value</span>\nbuf<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>                                                         <span class=\"token comment\">// Get and set the octet at index</span>\nbuf<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>                                                         <span class=\"token comment\">// The size of the buffer in bytes, Note that this is not necessarily the size of the contents</span>\n\nbuffer<span class=\"token punctuation\">.</span><span class=\"token constant\">INSPECT_MAX_BYTES</span><span class=\"token punctuation\">;</span>                                           <span class=\"token comment\">// How many bytes will be returned when buffer.inspect() is called. This can be overridden by user modules.</span></code></pre></div>"},{"url":"/docs/overflow/node-run-cli/","relativePath":"docs/overflow/node-run-cli.md","relativeDir":"docs/overflow","base":"node-run-cli.md","name":"node-run-cli","frontmatter":{"title":"node-cli-args","weight":0,"excerpt":"How to accept arguments in a Node.js program passed from the command line","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>You can pass any number of arguments when invoking a Node.js application using</p>\n<p>Arguments can be standalone or have a key and a value.</p>\n<p>For example:</p>\n<p>or</p>\n<p>This changes how you will retrieve this value in the Node.js code.</p>\n<p>The way you retrieve it is using the process object built into Node.js.</p>\n<p>It exposes an argv property, which is an array that contains all the command line invocation arguments.</p>\n<p>The first element is the full path of the node command.</p>\n<p>The second element is the full path of the file being executed.</p>\n<p>All the additional arguments are present from the third position going forward.</p>\n<p>You can iterate over all the arguments (including the node path and the file path) using a loop:</p>\n<p>You can get only the additional arguments by creating a new array that excludes the first 2 params:</p>\n<p>If you have one argument without an index name, like this:</p>\n<p>you can access it using</p>\n<p>In this case:</p>\n<p>args[0] is name=joe, and you need to parse it. The best way to do so is by using the <a href=\"https://www.npmjs.com/package/minimist\">minimist</a> library, which helps dealing with arguments:</p>\n<p>This time you need to use double dashes before each argument name:</p>"},{"url":"/docs/overflow/node-repl/","relativePath":"docs/overflow/node-repl.md","relativeDir":"docs/overflow","base":"node-repl.md","name":"node-repl","frontmatter":{"title":"The-package-lock.json-file","weight":0,"seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs","excerpt":"The package-lock.json file is automatically generated when installing node packages"},"html":"<p>The <code class=\"language-text\">node</code> command is the one we use to run our Node.js scripts:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">node</span> script.js</code></pre></div>\n<p>If we omit the filename, we use it in REPL mode:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">node</span></code></pre></div>\n<blockquote>\n<p>Note: REPL also known as Read Evaluate Print Loop is a programming language environment(Basically a console window) that takes single expression as user input and returns the result back to the console after execution.</p>\n</blockquote>\n<p>If you try it now in your terminal, this is what happens:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">❯ <span class=\"token function\">node</span>\n<span class=\"token operator\">></span></code></pre></div>\n<p>the command stays in idle mode and waits for us to enter something.</p>\n<blockquote>\n<p>Tip: if you are unsure how to open your terminal, google \"How to open terminal on &#x3C;your-operating-system>\".</p>\n</blockquote>\n<p>The REPL is waiting for us to enter some JavaScript code, to be more precise.</p>\n<p>Start simple and enter</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token operator\">></span> console.log<span class=\"token punctuation\">(</span><span class=\"token string\">'test'</span><span class=\"token punctuation\">)</span>\n<span class=\"token builtin class-name\">test</span>\nundefined\n<span class=\"token operator\">></span></code></pre></div>\n<p>The first value, <code class=\"language-text\">test</code>, is the output we told the console to print, then we get undefined which is the return value of running <code class=\"language-text\">console.log()</code>.</p>\n<p>We can now enter a new line of JavaScript.</p>\n<h2>Use the tab to autocomplete</h2>\n<p>The cool thing about the REPL is that it's interactive.</p>\n<p>As you write your code, if you press the <code class=\"language-text\">tab</code> key the REPL will try to autocomplete what you wrote to match a variable you already defined or a predefined one.</p>\n<h2>Exploring JavaScript objects</h2>\n<p>Try entering the name of a JavaScript class, like <code class=\"language-text\">Number</code>, add a dot and press <code class=\"language-text\">tab</code>.</p>\n<p>The REPL will print all the properties and methods you can access on that class:</p>\n<p><img src=\"tab.png\" alt=\"Pressing tab reveals object properties\"></p>\n<h2>Explore global objects</h2>\n<p>You can inspect the globals you have access to by typing <code class=\"language-text\">global.</code> and pressing <code class=\"language-text\">tab</code>:</p>\n<p><img src=\"globals.png\" alt=\"Globals\"></p>\n<h2>The _ special variable</h2>\n<p>If after some code you type <code class=\"language-text\">_</code>, that is going to print the result of the last operation.</p>\n<h2>Dot commands</h2>\n<p>The REPL has some special commands, all starting with a dot <code class=\"language-text\">.</code>. They are</p>\n<ul>\n<li><code class=\"language-text\">.help</code>: shows the dot commands help</li>\n<li><code class=\"language-text\">.editor</code>: enables editor mode, to write multiline JavaScript code with ease. Once you are in this mode, enter ctrl-D to run the code you wrote.</li>\n<li><code class=\"language-text\">.break</code>: when inputting a multi-line expression, entering the .break command will abort further input. Same as pressing ctrl-C.</li>\n<li><code class=\"language-text\">.clear</code>: resets the REPL context to an empty object and clears any multi-line expression currently being input.</li>\n<li><code class=\"language-text\">.load</code>: loads a JavaScript file, relative to the current working directory</li>\n<li><code class=\"language-text\">.save</code>: saves all you entered in the REPL session to a file (specify the filename)</li>\n<li><code class=\"language-text\">.exit</code>: exits the repl (same as pressing ctrl-C two times)</li>\n</ul>\n<p>The REPL knows when you are typing a multi-line statement without the need to invoke <code class=\"language-text\">.editor</code>.</p>\n<p>For example if you start typing an iteration like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">num</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span></code></pre></div>\n<p>and you press <code class=\"language-text\">enter</code>, the REPL will go to a new line that starts with 3 dots, indicating you can now continue to work on that block.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">...</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">...</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>If you type <code class=\"language-text\">.break</code> at the end of a line, the multiline mode will stop and the statement will not be executed.</p>"},{"url":"/docs/overflow/node-cli-args/","relativePath":"docs/overflow/node-cli-args.md","relativeDir":"docs/overflow","base":"node-cli-args.md","name":"node-cli-args","frontmatter":{"title":"where-is-npm-pack","weight":0,"excerpt":"How to find out where npm installs the packages","seo":{"title":"npm packages","description":"When you install a package using npm you can perform 2 types of installation:\na local install\na global install\n\nBy default, when you type an npm install command, like:\nthe package is installed in the current file tree, under the node_modules subfolder.\n","robots":[],"extra":[{"name":"og:description","value":"When you install a package using npm you can perform 2 types of installation:\na local install\na global install\n\nBy default, when you type an npm install command, like:\nthe package is installed in the current file tree, under the node_modules subfolder.\n","keyName":"property","relativeUrl":false}],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>When you install a package using npm you can perform 2 types of installation:</p>\n<ul>\n<li>a local install</li>\n<li></li>\n<li>a global install</li>\n</ul>\n<p>By default, when you type an npm install command, like:</p>\n<p>the package is installed in the current file tree, under the node_modules subfolder.</p>\n<p>As this happens, npm also adds the lodash entry in the dependencies property of the package.json file present in the current folder.</p>\n<p>A global installation is performed using the -g flag:</p>\n<p>When this happens, npm won't install the package under the local folder, but instead, it will use a global location.</p>\n<p>Where, exactly?</p>\n<p>The npm root -g command will tell you where that exact location is on your machine.</p>\n<p>On macOS or Linux this location could be /usr/local/lib/node<em>modules. On Windows it could be C:\\Users\\YOU\\AppData\\Roaming\\npm\\node</em>modules</p>\n<p>If you use nvm to manage Node.js versions, however, that location would differ.</p>\n<p>I for example use nvm and my packages location was shown as /Users/joe/.nvm/versions/node/v8.9.0/lib/node_modules.</p>"},{"url":"/docs/overflow/node-package-manager/","relativePath":"docs/overflow/node-package-manager.md","relativeDir":"docs/overflow","base":"node-package-manager.md","name":"node-package-manager","frontmatter":{"title":"Sorting Algorithms","weight":0,"excerpt":"Sorting Algorithms","seo":{"title":"","description":"","robots":[],"extra":[{"name":"og:title","value":"Sorting Algorithms","keyName":"property","relativeUrl":false},{"name":"og:description","value":"We are creating the same number of variables with an exact size, independent of our input. No new arrays are created.","keyName":"property","relativeUrl":false},{"name":"og:type","value":"website","keyName":"property","relativeUrl":false},{"name":"twitter:image","value":"images/Classical-2D-floorplanning-data-structures-left-and-their-3D.png","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"sorting algos","keyName":"name","relativeUrl":false},{"name":"og:image","value":"images/image (9).png","keyName":"property","relativeUrl":true}],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Sorting Algorithms</h2>\n<h3>Sorting Algorithms</h3>\n<ol>\n<li>Explain the complexity of and write a function that performs bubble sort on an array of numbers.</li>\n<li>Time Complexity: O(n^2)</li>\n<li>\n<ul>\n<li>In our worst case, our input is in the opposite order. We have to perform n swaps and loop through our input n times because a swap is made each</li>\n</ul>\n</li>\n<li>\n<p>Space Complexity: O(1)</p>\n<ul>\n<li>We are creating the same number of variables with an exact size, independent of our input. No new arrays are created.</li>\n</ul>\n</li>\n<li>Code example for bubbleSort:</li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">bubbleSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// We could have also had a 'sorted = false' flag and flipped our logic below</span>\n    <span class=\"token keyword\">let</span> swapped <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>swapped<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        swapped <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span>\n                <span class=\"token comment\">// The above three lines could also be in a helper swap function</span>\n                <span class=\"token comment\">// swap(array, i, i+1);</span>\n                swapped <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ol start=\"2\">\n<li>Explain the complexity of and write a function that performs selection sort on an array of numbers.</li>\n<li>\n<p>Time Complexity: O(n^2)</p>\n<ul>\n<li>Our nested loop structure is dependent on the size of our input.</li>\n<li>The outer loop always occurs n times.</li>\n<li>For each of those iterations, we have another loop that runs (n - i) times. This just means that the inner loop runs one less time each iteration, but this averages out to (n/2).</li>\n<li>Our nested structure is then T(n * n/2) = O(n^2)</li>\n</ul>\n</li>\n<li>Space Complexity: O(1)</li>\n<li>\n<ul>\n<li>We are creating the same number of variables with an exact size, independent of our input. No new arrays are created.</li>\n</ul>\n</li>\n<li>Code example for selectSort:</li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">selectionSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> minIndex <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>minIndex<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                minIndex <span class=\"token operator\">=</span> j<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>minIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        arr<span class=\"token punctuation\">[</span>minIndex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// The above three lines could also be in a helper swap function</span>\n        <span class=\"token comment\">// swap(arr, i, minIndex);</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ol start=\"3\">\n<li>Explain the complexity of and write a function that performs insertion sort on an array of numbers.</li>\n<li>\n<p>Time Complexity: O(n^2)</p>\n<ul>\n<li>Our nested loop structure is dependent on the size of our input.</li>\n<li>The outer loop always occurs n times.</li>\n<li>For each of those iterations, we have another loop that runs a maximum of (i - 1) times. This just means that the inner loop runs one more time each iteration, but this averages out to (n/2).</li>\n<li>Our nested structure is then T(n * n/2) = O(n^2)</li>\n</ul>\n</li>\n<li>Space Complexity: O(1)</li>\n<li>\n<ul>\n<li>We are creating the same number of variables with an exact size, independent of our input. No new arrays are created.</li>\n</ul>\n</li>\n<li>Code example for insertionSort:</li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">insertionSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> currElement <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">>=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> currElement <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> currElement<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ol start=\"4\">\n<li>Explain the complexity of and write a function that performs merge sort on an array of numbers.</li>\n<li>\n<p>Time Complexity: O(n log n)</p>\n<ul>\n<li>Our mergeSort function divides our input in half at each step, recursively calling itself with smaller and smaller input. This results in log n stack frames.</li>\n<li>On each stack frame, our worst case scenario is having to make n comparisons in our merge function in order to determine which element should come next in our sorted array.</li>\n<li>Since we have log n stack frames and n operations on each frame, we end up with an O(n log n) time complexity</li>\n</ul>\n</li>\n<li>Space Complexity: O(n)</li>\n<li>\n<ul>\n<li>We are ultimately creating n subarrays, making our space complexity linear to our input size.</li>\n</ul>\n</li>\n<li>Code example for mergeSort:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// The merge function is what is combining our sorted sub-arrays</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array1<span class=\"token punctuation\">,</span> array2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> merged <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// keep running while either array still contains elements</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>array1<span class=\"token punctuation\">.</span>length <span class=\"token operator\">||</span> array2<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// if array1 is nonempty, take its the first element as ele1</span>\n        <span class=\"token comment\">// otherwise array1 is empty, so take Infinity as ele1</span>\n        <span class=\"token keyword\">let</span> ele1 <span class=\"token operator\">=</span> array1<span class=\"token punctuation\">.</span>length <span class=\"token operator\">?</span> array1<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token number\">Infinity</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token comment\">// do the same for array2, ele2</span>\n        <span class=\"token keyword\">let</span> ele2 <span class=\"token operator\">=</span> array2<span class=\"token punctuation\">.</span>length <span class=\"token operator\">?</span> array2<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token number\">Infinity</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> next<span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// remove the smaller of the eles from it's array</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>ele1 <span class=\"token operator\">&lt;</span> ele2<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            next <span class=\"token operator\">=</span> array1<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            next <span class=\"token operator\">=</span> array2<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token comment\">// and add that ele to the new array</span>\n        merged<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>next<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> merged<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// The mergeSort function breaks apart our input into smaller sub-arrays until we have an input of length &lt;= 1, which is inherently sorted.</span>\n<span class=\"token comment\">// Once we have a left and right subarray that's sorted, we can merge them together to get our sorted result of this sub-problem, passing the sorted version back up the call stack.</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> midIdx <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> leftHalf <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> midIdx<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> rightHalf <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>midIdx<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> sortedLeft <span class=\"token operator\">=</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span>leftHalf<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> sortedRight <span class=\"token operator\">=</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span>rightHalf<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span>sortedLeft<span class=\"token punctuation\">,</span> sortedRight<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ol start=\"5\">\n<li>Explain the complexity of and write a function that performs quick sort on an array of numbers.</li>\n<li>\n<p>Time Complexity: Average O(n log n), Worst O(n^2)</p>\n<ul>\n<li>In our worst case, the pivot that we select results in every element going into either the left or right array. If this happens we end up making n recursive calls to quickSort, with n comparisons at each call.</li>\n<li>In our average case, we pick something that more evenly splits the arrays, resulting in approximately log n recursive calls and an overall complexity of O(n log n).</li>\n<li>Quick sort is unique in that the worst case is so exceedingly rare that it is often considered an O(n log n) complexity, even though this is not technically accurate.</li>\n</ul>\n</li>\n<li>\n<p>Space Complexity: Our implementation O(n), Possible implementation O(log n)</p>\n<ul>\n<li>The partition arrays that we create are directly proportional to the size of the input, resulting in O(n) space complexity.</li>\n<li>With some tweaking, we could implement an in-place quick sort, which would eliminate the creation of new arrays. In this case, the log n stack frames from the recursion are the only proportional amount of space that is used, resulting in O(log n) space complexity.</li>\n</ul>\n</li>\n<li>Code example for quickSort:</li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> pivot <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// This implementation uses filter, which returns a new array with any element that passes the criteria (ie the callback returns true).</span>\n    <span class=\"token comment\">// We also could have iterated over the array (array.forEach(el => ...)) and pushed each value into the appropriate left/right subarray as we encountered it.</span>\n    <span class=\"token keyword\">let</span> left <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">el</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> el <span class=\"token operator\">&lt;</span> pivot<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> right <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">el</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> el <span class=\"token operator\">>=</span> pivot<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> leftSorted <span class=\"token operator\">=</span> <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> rightSorted <span class=\"token operator\">=</span> <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>leftSorted<span class=\"token punctuation\">,</span> pivot<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rightSorted<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// We also could have concatenated the arrays instead of spreading their contents</span>\n    <span class=\"token comment\">// return leftSorted.concat([pivot]).concat(rightSorted);</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ol start=\"6\">\n<li>Explain the complexity of and write a function that performs a binary search on a sorted array of numbers.</li>\n<li>Time Complexity: O(log n)</li>\n<li>\n<ul>\n<li>With each recursive call, we split our input in half. This means we have to make at most log n checks to know if the element is in our array.</li>\n</ul>\n</li>\n<li>\n<p>Space Complexity: Our implementation O(n), Possible implementation O(1)</p>\n<ul>\n<li>We have to make a subarray for each recursive call. In the worst case (we don't find the element), the total length of these arrays is approximately equal to the length of the original (n).</li>\n<li>If we kept references to the beginning and end index of the portion of the array that we are searching, we could eliminate the need for creating new subarrays. We could also use a while loop to perform this functionality until we either found our target or our beginning and end indices crossed. This would eliminate the space required for recursive calls (adding stack frames). Ultimately we would be using the same number of variables independent of input size, resulting in O(1).</li>\n</ul>\n</li>\n<li>Code example for binarySearch and binarySearchIndex:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Returns simply true/false for presence</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> target</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> midIdx <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> leftHalf <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> midIdx<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> rightHalf <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>midIdx <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">[</span>midIdx<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span>leftHalf<span class=\"token punctuation\">,</span> target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">></span> array<span class=\"token punctuation\">[</span>midIdx<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span>rightHalf<span class=\"token punctuation\">,</span> target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Returns the index or -1 if not found</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">binarySearchIndex</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> target</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> midIdx <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> midEl <span class=\"token operator\">=</span> array<span class=\"token punctuation\">[</span>midIdx<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">&lt;</span> midEl<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">binarySearchIndex</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> midIdx<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">></span> midEl<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Since our recursive call will have new indices for the subarray, we have to adjust the return value to align it with the indices of our original array.</span>\n        <span class=\"token comment\">// If the recursive call returns -1, it was not found and we can immediately return -1</span>\n        <span class=\"token comment\">// If it was found in the subarray, we have to add on the number of elements that were removed from the beginning of our larger original array.</span>\n        <span class=\"token comment\">// For example, if we try to find 15 in an array of [5, 10, 15]:</span>\n        <span class=\"token comment\">// - Our first call to binarySearchIndex will check our middle element of 10</span>\n        <span class=\"token comment\">// - Since our target is greater, we will recursively call our search on elements to the right, being the subarray [15]</span>\n        <span class=\"token comment\">// - On our recursive call we found our target! It's index in this call is 0.</span>\n        <span class=\"token comment\">// - When we return 0 to where binarySearchIndex was called, we need to adjust it to line up with this larger array (the 0th element of this larger array is 5, but our target was at the 0th index of the subarray)</span>\n        <span class=\"token comment\">// - Since we sliced off 2 elements from the beginning before making our recursive call, we add 2 to the return value to adjust it back to line up with our original array.</span>\n        <span class=\"token keyword\">const</span> idxShift <span class=\"token operator\">=</span> <span class=\"token function\">binarySearchIndex</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>midIdx <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> idxShift <span class=\"token operator\">===</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">?</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">:</span> idxShift <span class=\"token operator\">+</span> midIdx <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> midIdx<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>"},{"url":"/docs/overflow/nodejs/","relativePath":"docs/overflow/nodejs.md","relativeDir":"docs/overflow","base":"nodejs.md","name":"nodejs","frontmatter":{"title":"Javascript and Node","excerpt":"Web-Dev-Hubis a Unibit theme created for project documentations. You can use it for your project.","seo":{"title":"Javascript and Node","description":"This is the Javascript and Node page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Javascript and Node","keyName":"property"},{"name":"og:description","value":"This is the Javascript and Node page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Javascript and Node"},{"name":"twitter:description","value":"This is the Javascript and Node page"}]},"template":"docs"},"html":"<p>As a beginner, it's hard to get to a point where you are confident enough in your programming abilities.</p>\n<p>While learning to code, you might also be confused at where does JavaScript end, and where Node.js begins, and vice versa.</p>\n<p>I would recommend you to have a good grasp of the main JavaScript concepts before diving into Node.js:</p>\n<ul>\n<li>Lexical Structure</li>\n<li>Expressions</li>\n<li>Types</li>\n<li>Variables</li>\n<li>Functions</li>\n<li>this</li>\n<li>Arrow Functions</li>\n<li>Loops</li>\n<li>Scopes</li>\n<li>Arrays</li>\n<li>Template Literals</li>\n<li>Semicolons</li>\n<li>Strict Mode</li>\n<li>ECMAScript 6, 2016, 2017</li>\n</ul>\n<p>With those concepts in mind, you are well on your road to become a proficient JavaScript developer, in both the browser and in Node.js.</p>\n<p>The following concepts are also key to understand asynchronous programming, which is one fundamental part of Node.js:</p>\n<ul>\n<li>Asynchronous programming and callbacks</li>\n<li>Timers</li>\n<li>Promises</li>\n<li>Async and Await</li>\n<li>Closures</li>\n<li>The Event Loop</li>\n</ul>"},{"url":"/docs/overflow/v8/","relativePath":"docs/overflow/v8.md","relativeDir":"docs/overflow","base":"v8.md","name":"v8","frontmatter":{"title":"npm global or local packages","weight":0,"excerpt":"npm packages","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>The main difference between local and global packages is this:</p>\n<ul>\n<li><strong>local packages</strong> are installed in the directory where you run npm install &#x3C;package-name>, and they are put in the node_modules folder under this directory</li>\n<li></li>\n<li><strong>global packages</strong> are all put in a single place in your system (exactly where depends on your setup), regardless of where you run npm install -g &#x3C;package-name></li>\n</ul>\n<p>In your code you can only require local packages:</p>\n<p>so when should you install in one way or another?</p>\n<p>In general, <strong>all packages should be installed locally</strong>.</p>\n<p>This makes sure you can have dozens of applications in your computer, all running a different version of each package if needed.</p>\n<p>Updating a global package would make all your projects use the new release, and as you can imagine this might cause nightmares in terms of maintenance, as some packages might break compatibility with further dependencies, and so on.</p>\n<p>All projects have their own local version of a package, even if this might appear like a waste of resources, it's minimal compared to the possible negative consequences.</p>\n<p>A package <strong>should be installed globally</strong> when it provides an executable command that you run from the shell (CLI), and it's reused across projects.</p>\n<p>You can also install executable commands locally and run them using npx, but some packages are just better installed globally.</p>\n<p>Great examples of popular global packages which you might know are</p>\n<ul>\n<li>npm</li>\n<li></li>\n<li>create-r</li>\n<li></li>\n<li>vue-cl</li>\n<li></li>\n<li>grunt-cli</li>\n<li></li>\n<li>mocha</li>\n<li>react-native-cli</li>\n<li>gatsby-cli</li>\n<li>forever</li>\n<li>nodemon</li>\n</ul>\n<p>You probably have some packages installed globally already on your system. You can see them by running</p>\n<p>on your command line.</p>"},{"url":"/docs/overflow/nodevsbrowser/","relativePath":"docs/overflow/nodevsbrowser.md","relativeDir":"docs/overflow","base":"nodevsbrowser.md","name":"nodevsbrowser","frontmatter":{"title":"Node vs Browser","excerpt":"Web-Dev-Hubis a Unibit theme created for project documentations. You can use it for your project.","seo":{"title":"Node vs Browser","description":"Both the browser and Node.js use JavaScript as their programming language.You can pass any number of arguments when invoking a Node.js application using\n","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Node vs Browser","keyName":"property"},{"name":"og:description","value":"Both the browser and Node.js use JavaScript as their programming language. Building apps that run in the browser","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Node vs Browser"},{"name":"twitter:description","value":"This is the Node vs Browser page"},{"name":"og:image","value":"images/node.jpg","keyName":"property","relativeUrl":true}]},"template":"docs"},"html":"<p>Both the browser and Node.js use JavaScript as their programming language.</p>\n<ul>\n<li>Building apps that run in the browser is a completely different thing than building a Node.js application.</li>\n<li>Despite the fact that it's always JavaScript, there are some key differences that make the experience radically different.</li>\n<li>From the perspective of a frontend developer who extensively uses JavaScript, Node.js apps bring with them a huge advantage: the comfort of programming everything - the frontend and the backend - in a single language.</li>\n<li>You have a huge opportunity because we know how hard it is to fully, deeply learn a programming language, and by using the same language to perform all your work on the web - both on the client and on the server, you're in a unique position of advantage.</li>\n<li>What changes is the ecosystem.</li>\n<li>In the browser, most of the time what you are doing is interacting with the DOM, or other Web Platform APIs like Cookies. Those do not exist in Node.js, of course. You don't have the <code class=\"language-text\">document</code>, <code class=\"language-text\">window</code> and all the other objects that are provided by the browser.</li>\n<li>And in the browser, we don't have all the nice APIs that Node.js provides through its modules, like the filesystem access functionality.</li>\n<li>Another big difference is that in Node.js you control the environment. Unless you are building an open source application that anyone can deploy anywhere, you know which version of Node.js you will run the application on. Compared to the browser environment, where you don't get the luxury to choose what browser your visitors will use, this is very convenient.</li>\n<li>This means that you can write all the modern ES6-7-8-9 JavaScript that your Node.js version supports.</li>\n<li>Since JavaScript moves so fast, but browsers can be a bit slow and users a bit slow to upgrade, sometimes on the web, you are stuck with using older JavaScript / ECMAScript releases.</li>\n<li>You can use Babel to transform your code to be ES5-compatible before shipping it to the browser, but in Node.js, you won't need that.</li>\n<li>Another difference is that Node.js uses the CommonJS module system, while in the browser we are starting to see the ES Modules standard being implemented.</li>\n<li>In practice, this means that for the time being you use <code class=\"language-text\">require()</code> in Node.js and <code class=\"language-text\">import</code> in the browser.</li>\n</ul>"},{"url":"/docs/projects/figma/","relativePath":"docs/projects/figma.md","relativeDir":"docs/projects","base":"figma.md","name":"figma","frontmatter":{"title":"Figma","template":"docs","excerpt":"iframe embeds"},"html":"<p> <iframe style=\"border: 1px solid rgba(0, 0, 0, 0.1);\" width=\"800\" height=\"450\" src=\"https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FbOwyinWBikQ5jdEpSx5WcI%2FFamily-Promise-Copy%3Fnode-id%3D0%253A1\" allowfullscreen></iframe></p>\n<br>\n<iframe style=\"border: 1px solid rgba(0, 0, 0, 0.1);\" width=\"800\" height=\"450\" src=\"https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FbOwyinWBikQ5jdEpSx5WcI%2FFamily-Promise-Copy%3Fnode-id%3D0%253A1\" allowfullscreen></iframe>"},{"url":"/docs/projects/embeded-websites/","relativePath":"docs/projects/embeded-websites.md","relativeDir":"docs/projects","base":"embeded-websites.md","name":"embeded-websites","frontmatter":{"title":"Family Promise Project","weight":0,"seo":{"title":"Gatsby Plugins For This Sites Content Model","description":"This is my markdown notes tempate","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Gatsby Plugins For This Sites Content Model","keyName":"property"},{"name":"og:description","value":"This is the Gatsby Plugins For This Sites Content Model page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Gatsby Plugins For This Sites Content Model"},{"name":"twitter:description","value":"This is the Gatsby Plugins For This Sites Content Model page"}]},"template":"docs","excerpt":"Family Promise organizes congregations, social service agencies and community members into volunteer coalitions called Affiliates that provide emergency shelter and wraparound services to homeless and at-risk families. The model of the core program emphasizes sustainability and relies on resources that are already available to the locales served. Though each Affiliate coordinates its own programming for transitional housing, case management, family mentoring, financial literacy classes and childcare, all receive staff training and program assistance from the national office. Built a way to track and visualize the services they provide external to the shelter to gain actionable insights."},"html":"<br>\n<br>\n<br>\n<h1>Family Promise Project:</h1>\n<h1>Table of contents</h1>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/README\">Home</a></li>\n</ul>\n<h2>navigation</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/navigation\">NAVIGATION</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/calendar\">Calendar</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/youtube\">Youtube:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/roadmap\">Roadmap:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/team-members\">TEAM MEMBERS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/running-list-of-notes-links-and-pertinent-info-from-meetings\">Running List Of Notes Links &#x26; Pertinent Info From Meetings</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/trello/README\">Trello</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/trello/github-trello-integration\">Github/Trello Integration</a></li>\n</ul>\n</li>\n</ul>\n<h2>UX</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/README\">UX_TOPICS</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/action-items\">Action Items:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/accessibility\">Accessibility</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/README\">Figma Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/notes\">Notes</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/prototyping-in-figma\">Prototyping In Figma</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/more-notes\">More Notes</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ux-design/README\">UX-Design</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ux-design/facebook-graph-api\">Facebook Graph API</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/README\">Ant Design</a></p>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-components/README\">ANT Components</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-components/buttons\">Buttons</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-docs\">ANT DOCS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/application-codesandbox\">Application (Codesandbox)</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/examples\">Examples</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/how-to-add-external-url-links-to-your-prototype\">How to add external URL links to your prototype</a></li>\n</ul>\n</li>\n</ul>\n<h2>CANVAS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/README\">Design</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/whats-inclusive-design\">What's Inclusive Design?</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/accessibility\">Accessibility</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/what-are-design-systems\">What are Design Systems?</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/canvas\">Canvas</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/README\">Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/user-experience-design\">User Experience Design</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/user-research\">User Research</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/interaction-design\">Interaction Design</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/README\">UX-Engineer</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/patterns\">Patterns</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/design-tools\">Design Tools</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/design-critiques\">Design Critiques</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/product-review\">Product Review</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/quiz\">Quiz</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/seven-principles-of-design\">Seven Principles of Design</a></li>\n</ul>\n</li>\n</ul>\n<h2>Front End</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/front-end/untitled\">Frontend:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/front-end/redux\">Redux</a></li>\n</ul>\n<h2>Back End</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/back-end/untitled/README\">Backend:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/back-end/untitled/api\">API</a></li>\n</ul>\n</li>\n</ul>\n<h2>Research</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/README\">Research Navigation</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/front-end\">Front End</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/back-end\">Back End</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/ux\">UX</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/ptm\">PTM</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/general\">General</a></li>\n</ul>\n</li>\n</ul>\n<h2>DS_API</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ds_api/untitled\">Data Science API</a></li>\n</ul>\n<h2>ROLES</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/roles/untitled/README\">TEAM ROLES</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/roles/untitled/bryan-guner\">Bryan Guner</a></li>\n</ul>\n</li>\n</ul>\n<h2>Action Items</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/action-items/untitled\">Trello</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/action-items/maps\">Maps</a></li>\n</ul>\n<h2>ARCHITECTURE</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/dns\">DNS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/aws\">AWS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/heroku\">Heroku</a></li>\n</ul>\n<h2>Questions</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/questions/from-previous-cohort\">From Previous Cohort</a></li>\n</ul>\n<h2>Standup Notes</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/README\">Meeting Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/overview\">Stakeholder Meeting 1</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/9-29-2021\">9/29/2021</a></li>\n</ul>\n</li>\n</ul>\n<h2>GitHub &#x26; Project Practice</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/README\">GitHub</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/untitled\">Github Guide</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/github-actions\">Github Actions:</a></li>\n</ul>\n</li>\n</ul>\n<h2>MISC</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/misc/untitled\">MISCELLANEOUS</a></li>\n</ul>\n<h2>Background Information</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/README\">Background Info</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/swagger-open-api-specification\">Swagger OPEN API SPECIFICATION</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/README\">GITHUB:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/git-bash\">Git Bash</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/git-prune\">Git Prune:</a></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<h2>DOCS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/README\">Coding</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/environment-variables\">Environment Variables</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/git-rebase\">Git Rebase:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/git-workflow\">Git Workflow:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/linting-and-formatting\">Linting and Formatting</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/README\">Project Docs</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/eng-docs-home\">Eng-Docs-Home</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/basic-node-api\">Basic Node API</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/contributing-to-this-scaffold-project\">Contributing to this scaffold project</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/examples\">Examples:</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-description\">PROJECT DESCRIPTION (Feature List)</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-learners-guide\">Labs Learners Guide</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/README\">REACT</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/untitled\">Create React App</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/awesome-react\">Awesome React</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/untitled\">Links</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/README\">Labs Engineering Docs</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/okta-basics\">Okta Basics</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/roadmap\">Roadmap</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/repositories\">Repositories</a></li>\n</ul>\n</li>\n</ul>\n<h2>Workflow</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/workflow/workflow\">Workflow</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/workflow/advice\">Advice</a></li>\n</ul>\n<h2>AWS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/README\">AWS</a></p>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/elastic-beanstalk/README\">Elastic Beanstalk</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/elastic-beanstalk/elastic-beanstalk-dns\">Elastic Beanstalk DNS</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/amplify/README\">Amplify:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/amplify/amplify-dns\">Amplify-DNS</a></li>\n</ul>\n</li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/untitled-1\">Account Basics</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws-networking\">AWS-Networking</a></li>\n</ul>\n<h2>Career &#x26; Job Hunt</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/career-and-job-hunt/career\">Career</a></li>\n</ul>\n<h2>Group 1</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/group-1/live-implementation\">Live Implementation</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FbOwyinWBikQ5jdEpSx5WcI%2FFamily-Promise-Copy\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"Family_Promise_embed\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/family-promise-embed-b434z?autoresize=1&fontsize=12&hidenavigation=1&theme=dark&view=preview\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"Family_Promise_embed\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Family-Promise Application</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://a.familypromiseservicetracker.dev/dashboard\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/projects/mini-projects2/","relativePath":"docs/projects/mini-projects2.md","relativeDir":"docs/projects","base":"mini-projects2.md","name":"mini-projects2","frontmatter":{"title":"Mini Projects","excerpt":"In this section you'll learn how to add syntax highlighting, examples, callouts and much more.","seo":{"title":"Mini Projects","description":"This is the Mini Projects page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Mini Projects","keyName":"property"},{"name":"og:description","value":"This is the Mini Projects page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Mini Projects"},{"name":"twitter:description","value":"This is the Mini Projects page"}]},"template":"docs","weight":0},"html":"<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Random Embedable Content  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://random-list-of-embedable-content.vercel.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://futuristic-rosemary-d4acc.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://iframeshowcase.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bgoonz.blogspot.com/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://www.youtube.com/embed/xGZSWvFess8\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://ds-unit-5-lambda.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://sanity-gatsby-blog-web-skwx3b17.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://kguner-fractions-website.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://dev-journal42.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://sanity-gatsby-hey-sugar-5.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://friendly-amaranth-51833.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://sidebar-blog.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://markdown-templates-42.netlify.app/\" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"  \" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"  \" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"  \" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"  \" width=\"1000px\" height=\"800px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/overflow/understanding-firebase/","relativePath":"docs/overflow/understanding-firebase.md","relativeDir":"docs/overflow","base":"understanding-firebase.md","name":"understanding-firebase","frontmatter":{"title":"Firebase","weight":0,"excerpt":"Firebasics","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Understand Firebase projects</h1>\n<p><strong>Note:</strong> If you're using the <a href=\"https://firebase.google.com/docs/projects/api/reference/rest?authuser=0\">Firebase Management REST API</a> to programmatically create a Firebase project, you must first <a href=\"https://cloud.google.com/resource-manager/reference/rest/v1/projects?authuser=0\">create a Google Cloud project</a>, then <a href=\"https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects/addFirebase?authuser=0\">add Firebase services</a> to the existing project.<strong>Note:</strong> The <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#project-number\">project number</a> and the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#project-id\">project ID</a> are the truly <em>unique identifiers</em> for a project across all of Firebase and Google Cloud.<strong>After Firebase provisions resources for a Firebase project, you cannot change its project ID.</strong> To use a specific identifier for Firebase resources, you must edit the project ID during the initial creation of the project.<strong>Caution:</strong> We do not recommend manually modifying an app's Firebase config file or object. If you initialize an app with invalid or missing values for any of these required \"Firebase options\", then your end users may experience serious issues.<strong>Note:</strong> For each Android app, if you provide a SHA-1 key for the app, you need to provide a package name and SHA-1 key combination that is globally unique across all of Google Cloud.</p>\n<p>This page offers brief overviews of several important concepts about Firebase projects. When available, follow the links to find more detailed information about features, services, and even other platforms. At the bottom of this page, find a listing of <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#best-practices\">general best practices</a> for Firebase projects.</p>\n<h2>Relationship between Firebase projects, apps, and products</h2>\n<p>A Firebase project is the top-level entity for Firebase. In a project, you create Firebase apps by registering your iOS, Android, or web apps. After you register your apps with Firebase, you can add the Firebase SDKs for any number of <a href=\"https://firebase.google.com/products/?authuser=0\">Firebase products</a>, like Analytics, Cloud Firestore, Performance Monitoring, or Remote Config.</p>\n<p>Learn more detailed information about this process in the Getting Started guides (<a href=\"https://firebase.google.com/docs/ios/setup?authuser=0\">iOS</a> | <a href=\"https://firebase.google.com/docs/android/setup?authuser=0\">Android</a> | <a href=\"https://firebase.google.com/docs/web/setup?authuser=0\">web</a> | <a href=\"https://firebase.google.com/docs/unity/setup?authuser=0\">Unity</a> | <a href=\"https://firebase.google.com/docs/cpp/setup?authuser=0\">C++</a>).</p>\n<h2>Relationship between Firebase projects and Google Cloud</h2>\n<p>When you create a new Firebase project in the Firebase console, you're actually creating a <a href=\"https://cloud.google.com/docs/overview/?authuser=0#projects\">Google Cloud project</a> behind the scenes. You can think of a Google Cloud project as a virtual container for data, code, configuration, and services. <strong>A Firebase project is a Google Cloud project that has additional Firebase-specific configurations and services.</strong> You can even create a Google Cloud project first, then add Firebase to the project later.</p>\n<p>Since a Firebase project <strong><em>is</em></strong> a Google Cloud project:</p>\n<ul>\n<li>Projects that appear in the <a href=\"https://console.firebase.google.com/?authuser=0\">Firebase console</a> also appear in the <a href=\"https://cloud.google.com/docs/overview/?authuser=0#google-cloud-console\">Google Cloud Console</a> and <a href=\"https://console.cloud.google.com/apis/?authuser=0\">Google APIs console</a>.</li>\n<li></li>\n<li><a href=\"https://firebase.google.com/pricing/?authuser=0\">Billing</a> and <a href=\"https://firebase.google.com/docs/projects/iam/overview?authuser=0\">permissions</a> for projects are shared across Firebase and Google Cloud.</li>\n<li></li>\n<li>Unique identifiers for a project (like the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#project-number\">project number</a> and the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#project-id\">project ID</a>) are shared across Firebase and Google Cloud.</li>\n<li>You can use products and APIs from both Firebase and Google Cloud in a project.</li>\n<li>Deleting a project deletes it across Firebase and Google Cloud.</li>\n</ul>\n<h2>Setting up a Firebase project and registering apps</h2>\n<p>You can set up a Firebase project and register apps in the <a href=\"https://console.firebase.google.com/?authuser=0\">Firebase console</a> (or, for advanced use cases, via the <a href=\"https://firebase.google.com/docs/projects/api/reference/rest?authuser=0\">Firebase Management REST API</a> or the <a href=\"https://firebase.google.com/docs/cli?authuser=0#management-commands\">Firebase CLI</a>). When you set up a project and register apps, you need to make some organizational decisions and add Firebase-specific configuration information to your local projects.</p>\n<p>Make sure to review some <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#best-practices\">general project-level best practices</a> (at the bottom of this page) before setting up a project and registering apps.</p>\n<h3>The project name</h3>\n<p>When you create a project, you provide a <strong>project name</strong>. This identifier is the <em>internal-only name</em> for a project in the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#manage-console\">Firebase console</a>, the <a href=\"https://cloud.google.com/docs/overview/?authuser=0#google-cloud-console\">Google Cloud Console</a>, and the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#manage-cli\">Firebase CLI</a>. The project name is not exposed in any publicly visible Firebase or Google Cloud product, service, or resource; it simply serves to help you more easily distinguish among multiple projects.</p>\n<p>You can edit a project name at any time in the settings <a href=\"https://console.firebase.google.com/project/_/settings/general/?authuser=0\"><strong>Project settings</strong></a> of the Firebase console. The project name is displayed in the top pane.</p>\n<h3>The project number</h3>\n<p>A Firebase project (and its <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#firebase-cloud-relationship\">associated Google Cloud project</a>) has a <strong>project number</strong>. This is the Google-assigned globally unique canonical identifier for the project. Use this identifier when configuring integrations and/or making API calls to Firebase, Google, or third-party services.</p>\n<h4>API calls and the project number</h4>\n<p>For many API calls, you need to include a unique identifier for a project. Although many APIs accept the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#project-id\">project ID</a>, it's recommended that you use the <strong>project number</strong> for making API calls to Firebase, Google, or third-party services.</p>\n<p>Learn more about using project identifiers, especially the project number, in Google's <a href=\"https://google.aip.dev/cloud/2510\">AIP 2510 standard</a>.</p>\n<h4>Find the project number</h4>\n<ul>\n<li>Firebase console: Click settings <a href=\"https://console.firebase.google.com/project/_/settings/general/?authuser=0\"><strong>Project settings</strong></a>. The project number is displayed in the top pane.</li>\n<li></li>\n<li>Firebase CLI: Run firebase projects:list. The project number is displayed along with all the Firebase projects associated with your account.</li>\n<li>Firebase Management REST API: Call <a href=\"https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects/list?authuser=0\">projects.list</a>. The response body contains the project number in the <a href=\"https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects?authuser=0#FirebaseProject\">FirebaseProject</a> object.</li>\n</ul>\n<h3>The project ID</h3>\n<p>A Firebase project (and its <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#firebase-cloud-relationship\">associated Google Cloud project</a>) has a <strong>project ID</strong>. This is a user-defined unique identifier for the project across all of Firebase and Google Cloud. When you create a Firebase project, Firebase automatically assigns a unique ID to the project, but you can edit it during project setup. This identifier should generally be treated as a convenience alias to reference the project.</p>\n<p>If you delete a project, the project ID is also deleted and can never be used again by any other project.</p>\n<h4>Firebase resources and the project ID</h4>\n<p>The project ID displays in publicly visible Firebase resources, for example:</p>\n<ul>\n<li>Default Hosting subdomain — <strong>PROJECT_ID</strong>.web.app and <strong>PROJECT_ID</strong>.firebaseapp.com</li>\n<li></li>\n<li>Default Realtime Database URL — <strong>PROJECT_ID</strong>-default-rtdb.firebaseio.com or <strong>PROJECT_ID</strong>-default-rtdb.<strong>REGION_CODE</strong>.firebasedatabase.app</li>\n<li>Default Cloud Storage bucket name — <strong>PROJECT_ID</strong>.appspot.com</li>\n</ul>\n<p>For all of the aforementioned resources, you can create non-default instances. The publicly visible names of non-defaults are fully-customizable. You can <a href=\"https://firebase.google.com/docs/hosting/custom-domain?authuser=0\">connect custom domains</a> to a Firebase-hosted site, <a href=\"https://firebase.google.com/docs/database/usage/sharding?authuser=0\">shard the Realtime Database</a>, and <a href=\"https://firebase.google.com/docs/storage?authuser=0\">create multiple Cloud Storage buckets</a> (visit the platform-specific Get Started page).</p>\n<h4>The Firebase CLI and the project ID</h4>\n<p>For some use cases, you might have multiple Firebase projects associated with the same local app directory. In these situations, when you use the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#manage-cli\">Firebase CLI</a>, you need to pass the --project flag with the firebase commands to communicate which Firebase project you want to interact with.</p>\n<p>You can also set up a <a href=\"https://firebase.google.com/docs/cli?authuser=0#project_aliases\">project alias</a> for each Firebase project so that you don't have to remember project IDs.</p>\n<h4>API calls and the project ID</h4>\n<p>For many API calls, you need to include a unique identifier for a project. Although many APIs accept the project ID, it's recommended that you use the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#project-number\"><strong>project number</strong></a> for making API calls to Firebase, Google, or third-party services.</p>\n<p>Learn more about using project identifiers, especially the project number, in Google's <a href=\"https://google.aip.dev/cloud/2510\">AIP 2510 standard</a>.</p>\n<h4>Find the project ID</h4>\n<ul>\n<li>Firebase console: Click settings <a href=\"https://console.firebase.google.com/project/_/settings/general/?authuser=0\"><strong>Project settings</strong></a>. The project ID is displayed in the top pane.</li>\n<li></li>\n<li>Firebase CLI: Run firebase projects:list. The project ID is displayed along with all the Firebase projects associated with your account.</li>\n<li>Firebase Management REST API: Call <a href=\"https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects/list?authuser=0\">projects.list</a>. The response body contains the project ID in the <a href=\"https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects?authuser=0#FirebaseProject\">FirebaseProject</a> object.</li>\n</ul>\n<h3>Firebase config files and objects</h3>\n<p>When you register an app with a Firebase project, the Firebase console provides a Firebase configuration file (iOS/Android apps) or a configuration object (web apps) that you add directly to your local app directory.</p>\n<ul>\n<li>For iOS apps, you add a GoogleService-Info.plist configuration file.</li>\n<li></li>\n<li>For Android apps, you add a google-services.json configuration file.</li>\n<li>For web apps, you add a Firebase configuration object.</li>\n</ul>\n<p>At any time, you can <a href=\"https://support.google.com/firebase/answer/7015592?authuser=0\">obtain an app's Firebase config file or object</a>.</p>\n<p>A Firebase config file or object associates an app with a specific Firebase project and its resources (databases, storage buckets, etc.). The configuration includes \"Firebase options\", which are parameters required by Firebase and Google services to communicate with Firebase server APIs and to associate client data with the Firebase project and Firebase app. Here are the required, minimum \"Firebase options\":</p>\n<ul>\n<li><a href=\"https://cloud.google.com/docs/authentication/api-keys?authuser=0\"><strong>API key</strong></a>: a simple encrypted string used when calling certain APIs that don't need to access private user data (example value: AIzaSyDOCAbC123dEf456GhI789jKl012-MnO)</li>\n<li></li>\n<li><a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#project-id\"><strong>Project ID</strong></a>: a user-defined unique identifier for the project across all of Firebase and Google Cloud. This identifier may appear in URLs or names for some Firebase resources, but it should generally be treated as a convenience alias to reference the project. (example value: myapp-project-123)</li>\n<li>\n<p><strong>Application ID (\"AppID\")</strong>: the unique identifier for the Firebase app across all of Firebase with a platform-specific format:</p>\n<ul>\n<li>Firebase iOS apps: GOOGLE<em>APP</em>ID (example value: 1:1234567890:ios:321abc456def7890)\nThis is <em>not</em> an Apple bundle ID.</li>\n<li>Firebase Android apps: mobilesdk<em>app</em>id (example value: 1:1234567890:android:321abc456def7890)\nThis is <em>not</em> an Android package name or Android application ID.</li>\n<li>Firebase Web apps: appId (example value: 1:65211879909:web:3ae38ef1cdcb2e01fe5f0c)</li>\n</ul>\n</li>\n</ul>\n<p>The content of the Firebase config file or object is considered public, including the app's platform-specific ID (iOS bundle ID or Android package name) and the Firebase project-specific values, like the API Key, project ID, Realtime Database URL, and Cloud Storage bucket name. Given this, <strong>use Firebase Security Rules</strong> to protect your data and files in <a href=\"https://firebase.google.com/docs/database/security?authuser=0\">Realtime Database</a>, <a href=\"https://firebase.google.com/docs/firestore/security/get-started?authuser=0\">Cloud Firestore</a>, and <a href=\"https://firebase.google.com/docs/storage/security?authuser=0\">Cloud Storage</a>.</p>\n<p>For open source projects, we generally do not recommend including the app's Firebase config file or object in source control because, in most cases, your users should create their own Firebase projects and point their apps to their own Firebase resources (via their own Firebase config file or object).</p>\n<h2>Managing a Firebase project</h2>\n<p>Make sure to review the <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#best-practices\">general project-level best practices</a> (at the bottom of this page) for considerations that might affect how you manage a Firebase project.</p>\n<h3>Tools to manage a project</h3>\n<h4>Firebase console</h4>\n<p>The <a href=\"https://console.firebase.google.com/?authuser=0\">Firebase console</a> offers the richest environment for managing Firebase products, apps, and project-level settings.</p>\n<p><img src=\"https://firebase.google.com/docs/projects/images/firebase_console_overview.png?authuser=0\" alt=\"image\"></p>\n<p>The left-side panel of the console lists the Firebase products, organized by top-level categories. At the top of the left-side panel, access a project's settings by clicking settings. A project's settings include <a href=\"https://firebase.google.com/integrations?authuser=0\">integrations</a>, <a href=\"https://firebase.google.com/docs/projects/iam/overview?authuser=0\">access permissions</a>, and <a href=\"https://firebase.google.com/pricing?authuser=0\">billing</a>.</p>\n<p>The middle of the console displays buttons that launch setup workflows to register various types of apps. After you start using Firebase, the main area of the console changes into a dashboard that displays stats on the products you use.</p>\n<h4>Firebase CLI (a command line tool)</h4>\n<p>Firebase also offers the <a href=\"https://firebase.google.com/docs/cli?authuser=0\">Firebase CLI</a> for configuring and managing specific Firebase products, like Firebase Hosting and Cloud Functions for Firebase.</p>\n<p>After installing the CLI, you have access to the <a href=\"https://firebase.google.com/docs/cli?authuser=0#command_reference\">global firebase command</a>. Use the CLI to <a href=\"https://firebase.google.com/docs/cli?authuser=0#initialize_a_firebase_project\">link your local app directory to a Firebase project</a>, then <a href=\"https://firebase.google.com/docs/cli?authuser=0#deployment\">deploy</a> new versions of Firebase-hosted content or updates to functions.</p>\n<h4>Firebase Management REST API</h4>\n<p>Using the <a href=\"https://firebase.google.com/docs/projects/api/reference/rest?authuser=0\">Firebase Management REST API</a>, you can programmatically manage a Firebase project. For example, you can programmatically register an app with a project or list the apps that are already registered (<a href=\"https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects.iosApps?authuser=0#methods\">iOS</a> | <a href=\"https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects.androidApps?authuser=0#methods\">Android</a> | <a href=\"https://firebase.google.com/docs/projects/api/reference/rest/v1beta1/projects.webApps?authuser=0#methods\">web</a>).</p>\n<h2>General best practices</h2>\n<h3>Adding apps to a project</h3>\n<p><strong>Ensure that all apps within a project are platform variants of the same application</strong> from an end-user perspective. It's advisable to register the iOS, Android, and web versions of the same app or game with the same Firebase project. All the apps in a project generally share the same Firebase resources (database, storage buckets, etc.).</p>\n<p>If you have <strong><em>multiple build variants</em></strong> with different iOS bundle IDs or Android package names defined, you can register each variant with a separate Firebase project. However, if you have variants that share the <em>same</em> Firebase resources, register them with the <em>same</em> Firebase project.</p>\n<p>Here are some general limits for Firebase projects, apps, and sites:</p>\n<ul>\n<li>\n<p><strong>Number of projects per account</strong></p>\n<ul>\n<li>Spark pricing plan — Project-creation quota is limited to a lower count of projects (usually around 5-10).</li>\n<li>Blaze pricing plan — Project-creation quota per account increases substantially as long as the associated Cloud Billing account is in good standing.</li>\n</ul>\n<p>The limit on project-creation quota is rarely a concern for most developers, but if needed, you can <a href=\"https://support.google.com/cloud/answer/6330231?authuser=0\">request an increase in project quota</a>.</p>\n<p>Be aware that the complete deletion of a project requires 30 days and counts toward project quota until the project is fully deleted.</p>\n</li>\n<li>\n<p><strong>Number of apps per project</strong></p>\n<p>Firebase restricts the total number of Firebase Apps within a Firebase project to 30.</p>\n<p>You should ensure that all Firebase Apps within a single Firebase project are platform variants of the same application from an end-user perspective. Read more about best practices for <a href=\"https://firebase.google.com/docs/projects/learn-more?authuser=0#multi-tenancy\">multi-tenancy</a> below.</p>\n<p>Learn more about the <a href=\"https://firebase.google.com/support/faq?authuser=0#apps-per-project\">limit on apps per project</a> in the FAQ.</p>\n</li>\n<li>\n<p><strong>Number of Hosting sites per project</strong></p>\n<p>The <a href=\"https://firebase.google.com/docs/hosting/multisites?authuser=0\">Firebase Hosting multisite feature</a> supports a maximum of 36 sites per project.</p>\n</li>\n</ul>\n<h3>Multi-tenancy</h3>\n<p>Connecting several different logically independent apps and/or web sites to a single Firebase project (often called \"multi-tenancy\") is not recommended. Multi-tenancy can lead to serious configuration and data privacy concerns problems, including unintended issues with analytics aggregation, shared authentication, overly-complex database structures, and difficulties with security rules.</p>\n<p>Generally, <strong>if a set of apps don't share the same data and configurations, strongly consider registering each app with a different Firebase project.</strong></p>\n<p>For example, if you develop a white label application, each independently labelled app should have its own Firebase project, but the iOS and Android versions of that label can be in the same project. Each independently labeled app shouldn't (for privacy reasons) share data with the others.</p>\n<h2>Launching your app</h2>\n<ul>\n<li>Set up <a href=\"https://firebase.google.com/docs/projects/billing/avoid-surprise-bills?authuser=0#set-up-budget-alert-emails\">budget alerts</a> for your project in the Google Cloud Console.</li>\n<li></li>\n<li>Monitor the <a href=\"https://console.firebase.google.com/project/_/usage?authuser=0\"><em>Usage and billing</em> dashboard</a> in the Firebase console to get an overall picture of your project's usage across multiple Firebase services.</li>\n<li>Review the <a href=\"https://firebase.google.com/support/guides/launch-checklist?authuser=0\">Firebase launch checklist</a>.</li>\n</ul>"},{"url":"/docs/projects/my-websites/","relativePath":"docs/projects/my-websites.md","relativeDir":"docs/projects","base":"my-websites.md","name":"my-websites","frontmatter":{"title":"My Websites","template":"docs","excerpt":"Data Structures Websites"},"html":"<h1> Data Structures Website </h1>"},{"url":"/docs/projects/","relativePath":"docs/projects/index.md","relativeDir":"docs/projects","base":"index.md","name":"index","frontmatter":{"title":"Projects","excerpt":"We'd love it if you participate in the Web-Dev-Hubcommunity. Find out how to get connected.","seo":{"title":"Projects","description":"introductory-react-part-2\na-very-quick-guide-to-calculating-big-o-computational-complexity\nintroduction-to-react css-animations\n","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Projects Articles","keyName":"property"},{"name":"og:description","value":"","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Projectss"},{"name":"twitter:description","value":"This is the community page"},{"name":"og:image","value":"images/beige-maple.png","keyName":"property","relativeUrl":true}]},"template":"docs","weight":0},"html":"<p><a href=\"https://bgoonz-blog-v3-0.netlify.app/embeds/\">https://bgoonz-blog-v3-0.netlify.app/embeds/</a></p>\n<br>\n<h1>  Links: </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://links4242.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h1> Static Assets Server </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://lambda-static-assets.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<h1>  Search Awesome Lists      </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://search-awesome.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Project Showcase  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://project-showcase-bgoonz.netlify.app//\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h1>  Useful Resource Archive #3   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://useful-resource-repo3-0.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Anywhere Fitness </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://frontend-iota.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Project Image Portfolio   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://project-portfolio42.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Web Audio DAW      </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://mihirbeg28.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>React & Shopify Ecommerce Site (Norwex)     </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://friendly-amaranth-51833.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>Bgoonz Bookmarks   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bgoonz-bookmarks.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>Portfolio </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bg-portfolio.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h1>Goal Tracker  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://splendid-onion-b0ec3.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Potluck Planner </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://potluck-landing.netlify.app/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Useful Snippets </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bgoonz.github.io/Useful-Snippets/\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"\n       frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>Meditation App </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://meditate42app.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<h2>List:</h2>\n<ul>\n<li><a href=\"https://admiring-montalcini-965c0b.netlify.app/\">https://admiring-montalcini-965c0b.netlify.app/</a></li>\n<li><a href=\"https://adoring-nobel-85c068.netlify.app/\">https://adoring-nobel-85c068.netlify.app/</a></li>\n<li><a href=\"https://amazing-hodgkin-33aea6.netlify.app/\">https://amazing-hodgkin-33aea6.netlify.app/</a></li>\n<li><a href=\"https://angry-fermat-dcf5dd.netlify.app/\">https://angry-fermat-dcf5dd.netlify.app/</a></li>\n<li><a href=\"https://bg-portfolio.netlify.app/\">https://bg-portfolio.netlify.app/</a></li>\n<li><a href=\"https://bg-resume.netlify.app/\">https://bg-resume.netlify.app/</a></li>\n<li><a href=\"https://bgoonz-blog-v3-0.netlify.app/\">https://bgoonz-blog-v3-0.netlify.app/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a></li>\n<li><a href=\"https://bgoonz-bookmarks.netlify.app/\">https://bgoonz-bookmarks.netlify.app/</a></li>\n<li><a href=\"https://bgoonz-cv.netlify.app/\">https://bgoonz-cv.netlify.app/</a></li>\n<li><a href=\"https://bgoonz-games.netlify.app/\">https://bgoonz-games.netlify.app/</a></li>\n<li><a href=\"https://bgoonzblog20-backup.netlify.app/\">https://bgoonzblog20-backup.netlify.app/</a></li>\n<li><a href=\"https://bgoonzblog20-redo.netlify.app/\">https://bgoonzblog20-redo.netlify.app/</a></li>\n<li><a href=\"https://bgoonzblog20starter.netlify.app/\">https://bgoonzblog20starter.netlify.app/</a></li>\n<li><a href=\"https://bgoonzconnekt4.netlify.app/\">https://bgoonzconnekt4.netlify.app/</a></li>\n<li><a href=\"https://bgoonzmedium.netlify.app/\">https://bgoonzmedium.netlify.app/</a></li>\n<li><a href=\"https://bicknborty.netlify.app/\">https://bicknborty.netlify.app/</a></li>\n<li><a href=\"https://blog-v42-31eba.netlify.app/\">https://blog-v42-31eba.netlify.app/</a></li>\n<li><a href=\"https://blog3-backup-dd7df.netlify.app/\">https://blog3-backup-dd7df.netlify.app/</a></li>\n<li><a href=\"https://code-playground.netlify.app/\">https://code-playground.netlify.app/</a></li>\n<li><a href=\"https://condescending-lewin-c96727.netlify.app/\">https://condescending-lewin-c96727.netlify.app/</a></li>\n<li><a href=\"https://curious-rabbit-f33af.netlify.app/\">https://curious-rabbit-f33af.netlify.app/</a></li>\n<li><a href=\"https://determined-dijkstra-ee7390.netlify.app/\">https://determined-dijkstra-ee7390.netlify.app/</a></li>\n<li><a href=\"https://dev-journal42.netlify.app/\">https://dev-journal42.netlify.app/</a></li>\n<li><a href=\"https://devtools42.netlify.app/\">https://devtools42.netlify.app/</a></li>\n<li><a href=\"https://docs42.netlify.app/\">https://docs42.netlify.app/</a></li>\n<li><a href=\"https://ds-algo-official.netlify.app/\">https://ds-algo-official.netlify.app/</a></li>\n<li><a href=\"https://ds-unit-5-lambda.netlify.app/\">https://ds-unit-5-lambda.netlify.app/</a></li>\n<li><a href=\"https://eager-northcutt-456076.netlify.app/\">https://eager-northcutt-456076.netlify.app/</a></li>\n<li><a href=\"https://elite-cabbage-3551b.netlify.app/\">https://elite-cabbage-3551b.netlify.app/</a></li>\n<li><a href=\"https://exploring-next-sanity.netlify.app/\">https://exploring-next-sanity.netlify.app/</a></li>\n<li><a href=\"https://festive-borg-e4d856.netlify.app/\">https://festive-borg-e4d856.netlify.app/</a></li>\n<li><a href=\"https://festive-elion-13b19c.netlify.app/\">https://festive-elion-13b19c.netlify.app/</a></li>\n<li><a href=\"https://fourm-builder-gui.netlify.app/\">https://fourm-builder-gui.netlify.app/</a></li>\n<li><a href=\"https://friendly-amaranth-51833.netlify.app/\">https://friendly-amaranth-51833.netlify.app/</a></li>\n<li><a href=\"https://friendly-poincare-a11e2f.netlify.app/\">https://friendly-poincare-a11e2f.netlify.app/</a></li>\n<li><a href=\"https://futuristic-rosemary-d4acc.netlify.app/\">https://futuristic-rosemary-d4acc.netlify.app/</a></li>\n<li><a href=\"https://gists42.netlify.app/\">https://gists42.netlify.app/</a></li>\n<li><a href=\"https://githtmlpreview.netlify.app/\">https://githtmlpreview.netlify.app/</a></li>\n<li><a href=\"https://goofy-curran-95aa66.netlify.app/\">https://goofy-curran-95aa66.netlify.app/</a></li>\n<li><a href=\"https://gracious-raman-474030.netlify.app/\">https://gracious-raman-474030.netlify.app/</a></li>\n<li><a href=\"https://happy-mestorf-0f8e75.netlify.app/\">https://happy-mestorf-0f8e75.netlify.app/</a></li>\n<li><a href=\"https://hardcore-hamilton-c5b45e.netlify.app/\">https://hardcore-hamilton-c5b45e.netlify.app/</a></li>\n<li><a href=\"https://hardcore-lamport-7eb855.netlify.app/\">https://hardcore-lamport-7eb855.netlify.app/</a></li>\n<li><a href=\"https://hopeful-shockley-150bee.netlify.app/\">https://hopeful-shockley-150bee.netlify.app/</a></li>\n<li><a href=\"https://hugo-cms-42.netlify.app/\">https://hugo-cms-42.netlify.app/</a></li>\n<li><a href=\"https://hungry-shaw-30d504.netlify.app/\">https://hungry-shaw-30d504.netlify.app/</a></li>\n<li><a href=\"https://iframeshowcase.netlify.app/\">https://iframeshowcase.netlify.app/</a></li>\n<li><a href=\"https://interesting-aspen-ce986.netlify.app/\">https://interesting-aspen-ce986.netlify.app/</a></li>\n<li><a href=\"https://jovial-agnesi-8ec8b1.netlify.app/\">https://jovial-agnesi-8ec8b1.netlify.app/</a></li>\n<li><a href=\"https://jovial-keller-063835.netlify.app/\">https://jovial-keller-063835.netlify.app/</a></li>\n<li><a href=\"https://kguner-fractions-website.netlify.app/\">https://kguner-fractions-website.netlify.app/</a></li>\n<li><a href=\"https://kind-petunia-e8f9f.netlify.app/\">https://kind-petunia-e8f9f.netlify.app/</a></li>\n<li><a href=\"https://lambda-prep.netlify.app/\">https://lambda-prep.netlify.app/</a></li>\n<li><a href=\"https://lambda-resources.netlify.app/\">https://lambda-resources.netlify.app/</a></li>\n<li><a href=\"https://links4242.netlify.app/\">https://links4242.netlify.app/</a></li>\n<li><a href=\"https://live-form.netlify.app/\">https://live-form.netlify.app/</a></li>\n<li><a href=\"https://markdown-templates-42.netlify.app/\">https://markdown-templates-42.netlify.app/</a></li>\n<li><a href=\"https://marvelous-aluminum-11a84.netlify.app/\">https://marvelous-aluminum-11a84.netlify.app/</a></li>\n<li><a href=\"https://meditate42app.netlify.app/\">https://meditate42app.netlify.app/</a></li>\n<li><a href=\"https://memes42069.netlify.app/\">https://memes42069.netlify.app/</a></li>\n<li><a href=\"https://mihirbeg28.netlify.app/\">https://mihirbeg28.netlify.app/</a></li>\n<li><a href=\"https://mihirbegmusic.netlify.app/\">https://mihirbegmusic.netlify.app/</a></li>\n<li><a href=\"https://mihirbegmusiclab.netlify.app/\">https://mihirbegmusiclab.netlify.app/</a></li>\n<li><a href=\"https://modest-booth-4e17df.netlify.app/\">https://modest-booth-4e17df.netlify.app/</a></li>\n<li><a href=\"https://modest-torvalds-34afbc.netlify.app/\">https://modest-torvalds-34afbc.netlify.app/</a></li>\n<li><a href=\"https://modest-varahamihira-772b59.netlify.app/\">https://modest-varahamihira-772b59.netlify.app/</a></li>\n<li><a href=\"https://nervous-swartz-0ab2cc.netlify.app/\">https://nervous-swartz-0ab2cc.netlify.app/</a></li>\n<li><a href=\"https://norwex-next-js.netlify.app/\">https://norwex-next-js.netlify.app/</a></li>\n<li><a href=\"https://objective-borg-a327cd.netlify.app/\">https://objective-borg-a327cd.netlify.app/</a></li>\n<li><a href=\"https://objective-rosalind-d4ff71.netlify.app/\">https://objective-rosalind-d4ff71.netlify.app/</a></li>\n<li><a href=\"https://objective-torvalds-1c12dd.netlify.app/\">https://objective-torvalds-1c12dd.netlify.app/</a></li>\n<li><a href=\"https://optimistic-curie-ddd352.netlify.app/\">https://optimistic-curie-ddd352.netlify.app/</a></li>\n<li><a href=\"https://oval-cabbage-354f6.netlify.app/\">https://oval-cabbage-354f6.netlify.app/</a></li>\n<li><a href=\"https://pedantic-wing-adbf82.netlify.app/\">https://pedantic-wing-adbf82.netlify.app/</a></li>\n<li><a href=\"https://pensive-meitner-1ea8c4.netlify.app/\">https://pensive-meitner-1ea8c4.netlify.app/</a></li>\n<li><a href=\"https://portfolio42.netlify.app/\">https://portfolio42.netlify.app/</a></li>\n<li><a href=\"https://potluck-landing.netlify.app/\">https://potluck-landing.netlify.app/</a></li>\n<li><a href=\"https://priceless-shaw-86ccb2.netlify.app/\">https://priceless-shaw-86ccb2.netlify.app/</a></li>\n<li><a href=\"https://project-portfolio42.netlify.app/\">https://project-portfolio42.netlify.app/</a></li>\n<li><a href=\"https://project-showcase-bgoonz.netlify.app/\">https://project-showcase-bgoonz.netlify.app/</a></li>\n<li><a href=\"https://py-prac-42.netlify.app/\">https://py-prac-42.netlify.app/</a></li>\n<li><a href=\"https://python-playground42.netlify.app/\">https://python-playground42.netlify.app/</a></li>\n<li><a href=\"https://quirky-meninsky-4181b5.netlify.app/\">https://quirky-meninsky-4181b5.netlify.app/</a></li>\n<li><a href=\"https://quizzical-mcnulty-fa09f2.netlify.app/\">https://quizzical-mcnulty-fa09f2.netlify.app/</a></li>\n<li><a href=\"https://random-embedable-content.netlify.app/\">https://random-embedable-content.netlify.app/</a></li>\n<li><a href=\"https://random-list-of-embedable-content.vercel.app/\">https://random-list-of-embedable-content.vercel.app/</a></li>\n<li><a href=\"https://random-static-html-deploys.netlify.app/\">https://random-static-html-deploys.netlify.app/</a></li>\n<li><a href=\"https://react-blog-1.netlify.app/\">https://react-blog-1.netlify.app/</a></li>\n<li><a href=\"https://react-calculator2.vercel.app/\">https://react-calculator2.vercel.app/</a></li>\n<li><a href=\"https://recursion-prompts.netlify.app/\">https://recursion-prompts.netlify.app/</a></li>\n<li><a href=\"https://relaxed-bhaskara-dc85ec.netlify.app/\">https://relaxed-bhaskara-dc85ec.netlify.app/</a></li>\n<li><a href=\"https://romantic-hamilton-514b79.netlify.app/\">https://romantic-hamilton-514b79.netlify.app/</a></li>\n<li><a href=\"https://sanity-catalyst-studio-njajg3jt.netlify.app/\">https://sanity-catalyst-studio-njajg3jt.netlify.app/</a></li>\n<li><a href=\"https://sanity-commercelayer-1-studio-rkmntw55.netlify.app/\">https://sanity-commercelayer-1-studio-rkmntw55.netlify.app/</a></li>\n<li><a href=\"https://sanity-commercelayer-web-56265s29.netlify.app/\">https://sanity-commercelayer-web-56265s29.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-blog-3-studio-ch48ysi1.netlify.app/\">https://sanity-gatsby-blog-3-studio-ch48ysi1.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-blog-3-web-dnkdb4p7.netlify.app/\">https://sanity-gatsby-blog-3-web-dnkdb4p7.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-blog-4-studio-p6qrh84r.netlify.app/\">https://sanity-gatsby-blog-4-studio-p6qrh84r.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-blog-4-web-mobyn8k4.netlify.app/\">https://sanity-gatsby-blog-4-web-mobyn8k4.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-blog-studio-m195df5o.netlify.app/\">https://sanity-gatsby-blog-studio-m195df5o.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-blog-web-skwx3b17.netlify.app/\">https://sanity-gatsby-blog-web-skwx3b17.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-2-web.netlify.app/\">https://sanity-gatsby-hey-sugar-2-web.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-5-studio.netlify.app/\">https://sanity-gatsby-hey-sugar-5-studio.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-5.netlify.app/\">https://sanity-gatsby-hey-sugar-5.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-studio-rkg94h5e.netlify.app/\">https://sanity-gatsby-hey-sugar-studio-rkg94h5e.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-3-studio-bit6zuzq.netlify.app/\">https://sanity-gatsby-portfolio-3-studio-bit6zuzq.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-studio-89chyji1.netlify.app/\">https://sanity-gatsby-portfolio-studio-89chyji1.netlify.app/</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-web-1wwhtk8k.netlify.app/\">https://sanity-gatsby-portfolio-web-1wwhtk8k.netlify.app/</a></li>\n<li><a href=\"https://sanity-jigsaw-blog-studio-mgk1nds9.netlify.app/\">https://sanity-jigsaw-blog-studio-mgk1nds9.netlify.app/</a></li>\n<li><a href=\"https://sanity-kitchen-sink-2-studio-71rv9mea.netlify.app/\">https://sanity-kitchen-sink-2-studio-71rv9mea.netlify.app/</a></li>\n<li><a href=\"https://sanity-kitchen-sink-3-studio-qpaz93e3.netlify.app/\">https://sanity-kitchen-sink-3-studio-qpaz93e3.netlify.app/</a></li>\n<li><a href=\"https://sanity-kitchen-sink-5-web.netlify.app/\">https://sanity-kitchen-sink-5-web.netlify.app/</a></li>\n<li><a href=\"https://sanity-kitchen-sink-studio-us5ymc5z.netlify.app/\">https://sanity-kitchen-sink-studio-us5ymc5z.netlify.app/</a></li>\n<li><a href=\"https://sanity-kitchen-sink-web-geaa75ie.netlify.app/\">https://sanity-kitchen-sink-web-geaa75ie.netlify.app/</a></li>\n<li><a href=\"https://sanity-nuxt-events-studio-zd46wiji.netlify.app/\">https://sanity-nuxt-events-studio-zd46wiji.netlify.app/</a></li>\n<li><a href=\"https://sanity-nuxt-events-web-i78cd7mw.netlify.app/\">https://sanity-nuxt-events-web-i78cd7mw.netlify.app/</a></li>\n<li><a href=\"https://sanity-signup.netlify.app/\">https://sanity-signup.netlify.app/</a></li>\n<li><a href=\"https://sanity-translation-examples-studio-u93wc5ox.netlify.app/\">https://sanity-translation-examples-studio-u93wc5ox.netlify.app/</a></li>\n<li><a href=\"https://scopeclosurecontext.netlify.app/\">https://scopeclosurecontext.netlify.app/</a></li>\n<li><a href=\"https://side-bar-blog-4.netlify.app/\">https://side-bar-blog-4.netlify.app/</a></li>\n<li><a href=\"https://sidebar-blog.netlify.app/\">https://sidebar-blog.netlify.app/</a></li>\n<li><a href=\"https://silly-lichterman-b22b5f.netlify.app/\">https://silly-lichterman-b22b5f.netlify.app/</a></li>\n<li><a href=\"https://silly-shirley-ec955e.netlify.app/\">https://silly-shirley-ec955e.netlify.app/</a></li>\n<li><a href=\"https://site-analysis.netlify.app/%5D\">https://site-analysis.netlify.app/%5D</a></li>\n<li><a href=\"https://site-analysis.netlify.app/\">https://site-analysis.netlify.app/</a></li>\n<li><a href=\"https://splendid-onion-b0ec3.netlify.app/\">https://splendid-onion-b0ec3.netlify.app/</a></li>\n<li><a href=\"https://starter-520d2.netlify.app/\">https://starter-520d2.netlify.app/</a></li>\n<li><a href=\"https://stoic-mccarthy-2c335f.netlify.app/\">https://stoic-mccarthy-2c335f.netlify.app/</a></li>\n<li><a href=\"https://stupefied-wilson-2bc726.netlify.app/\">https://stupefied-wilson-2bc726.netlify.app/</a></li>\n<li><a href=\"https://synth-music-theory.netlify.app/\">https://synth-music-theory.netlify.app/</a></li>\n<li><a href=\"https://ternary42.netlify.app/\">https://ternary42.netlify.app/</a></li>\n<li><a href=\"https://tetris42.netlify.app/\">https://tetris42.netlify.app/</a></li>\n<li><a href=\"https://trusting-aryabhata-e5438d.netlify.app/\">https://trusting-aryabhata-e5438d.netlify.app/</a></li>\n<li><a href=\"https://trusting-dijkstra-4d3b17.netlify.app/\">https://trusting-dijkstra-4d3b17.netlify.app/</a></li>\n<li><a href=\"https://unruffled-bhabha-2ea500.netlify.app/\">https://unruffled-bhabha-2ea500.netlify.app/</a></li>\n<li><a href=\"https://upbeat-mayer-92c10b.netlify.app/\">https://upbeat-mayer-92c10b.netlify.app/</a></li>\n<li><a href=\"https://vibrant-noether-dbe366.netlify.app/\">https://vibrant-noether-dbe366.netlify.app/</a></li>\n<li><a href=\"https://web-dev-interview-prep-quiz-website.netlify.app/intro-js2.html%5D\">https://web-dev-interview-prep-quiz-website.netlify.app/intro-js2.html%5D</a></li>\n<li><a href=\"https://web-dev-interview-prep-quiz-website.netlify.app/\">https://web-dev-interview-prep-quiz-website.netlify.app/</a></li>\n<li><a href=\"https://web-dev-resource-hub-manual-deploy.netlify.app/\">https://web-dev-resource-hub-manual-deploy.netlify.app/</a></li>\n<li><a href=\"https://web-dev-resource-hub.netlify.app/\">https://web-dev-resource-hub.netlify.app/</a></li>\n<li><a href=\"https://wizardly-hermann-c9ade8.netlify.app/\">https://wizardly-hermann-c9ade8.netlify.app/</a></li>\n<li><a href=\"https://wonderful-pasteur-392fbe.netlify.app/\">https://wonderful-pasteur-392fbe.netlify.app/</a></li>\n<li><a href=\"https://zen-bhabha-bd046f.netlify.app/\">https://zen-bhabha-bd046f.netlify.app/</a></li>\n</ul>"},{"url":"/docs/projects/mini-projects/","relativePath":"docs/projects/mini-projects.md","relativeDir":"docs/projects","base":"mini-projects.md","name":"mini-projects","frontmatter":{"title":"Mini Projects","excerpt":"We'd love it if you participate in the Web-Dev-Hubcommunity. Find out how to get connected.","seo":{"title":"Mini Projects","description":"introductory-react-part-2\na-very-quick-guide-to-calculating-big-o-computational-complexity\nintroduction-to-react css-animations\n","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Mini Projects Articles","keyName":"property"},{"name":"og:description","value":"","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Mini Projectss"},{"name":"twitter:description","value":"This is the community page"},{"name":"og:image","value":"images/beige-maple.png","keyName":"property","relativeUrl":true}]},"template":"docs","weight":0},"html":"<h1> Network Visualization </h1>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/NWjrEWV?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/MWpRXzb?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/BaWEVqg?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/WNpqNYG?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/MWpMWzE?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/rNyENQJ?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/zYZVYMj?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/YzZozOM?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/gOmVErj?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/vYmYzqw?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/dyvBYNj?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/ExWBVWb?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/XWMELYy?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/QWpmXxq?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/eYvMKwe?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/QWpmmom?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/QWpmmPm?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/JjWLLqj?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/MWpVVLP?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/gOmeeEm?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/NWgdZyq?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/RwKYRoo?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/LYyBwEp?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/QWgYoBp?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/ExZvGoZ?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/MWbxYme?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/dyOaoXb?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/ExZxMPN?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/ZEKOmYW?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/bGWgLaR?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/QWvMQrb?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/JjNXROo?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/abWNmqo?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/bGWpwvv?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/mdmPrwR?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/BaRKLZw?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/RwVaGZo?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/BaRdabZ?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/OJWzbRa?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/KKaJwgo?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/ExZrayM?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/yLgZLrp?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/dyNayLB?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/PoWVovN?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/VwPgwgo?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/YzNBzbK?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/NWdoWVp?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/mdRvdzd?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/LYxqYMa?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/wvgNvYW?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/LYxqYBq?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/jOydOvm?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/ZELwEMv?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/oNBmNPV?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/WNRPbeO?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/poRGvzp?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/WNRPNpw?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/NWdoWvN?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/LYxqEZP?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/wvgNByP?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/eYgxmyx?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/JjExopj?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/GRrzRGR?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/vYxGLao?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/abwzxKP?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/XWgJQYP?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/powvBZp?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/wveBJBM?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/QWgwpGv?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/powvegw?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/eYRmvJV?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/GREgWEp?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/NWgdVOJ?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/QWgdVaa?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/MWmGPvO?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/rNmJMaz?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/MWmQjYJ?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe\n  height=\"300\"\n  style=\"width: 100%\"\n  scrolling=\"no\"\n  title=\"Neural Network Visualization (animated SVG)\"\n  src=\"https://codepen.io/bgoonz/embed/eYWVdmR?default-tab=html%2Cresult\"\n  frameborder=\"no\"\n  loading=\"lazy\"\n  allowtransparency=\"true\"\n  allowfullscreen=\"true\"\n>\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  title=\"searchblog2.0\"\nsrc=\"https://codepen.io/bgoonz/embed/LYyBwEp?default-tab=result&theme-id=dark\"   frameborder=\"yes\" loading=\"lazy\"\n allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/LYyBwEp\">\nsearchblog2.0</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  title=\"Fibonacci Carousel\" src=\"\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href=\"https://replit.com/@bgoonz/Comments-1#index.html\">\nFibonacci Carousel</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    scrolling=\"yes\" src=\"https://goonlinetools.com/covid19/global\" style=\"border: 0px none;height: 540px; margin-top: -110px; margin-bottom: -220px; width: 100%;\"> </iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  title=\"Fibonacci Carousel\"\nsrc=\"https://codepen.io/bgoonz/embed/JjNagJo?default-tab=result&theme-id=dark\"   frameborder=\"yes\" loading=\"lazy\"\n allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/JjNagJo\">\nFibonacci Carousel</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  title=\"embed-twitter-feed\"\nsrc=\"https://codepen.io/bgoonz/embed/poPOqEO?default-tab=result&theme-id=dark\"   frameborder=\"yes\" loading=\"lazy\"\n allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/poPOqEO\">\nembed-twitter-feed</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  src=\"//jsfiddle.net/bgoonz/j4xt839d/embedded/result/\"\nallowfullscreen=\"allowfullscreen\" frameborder=\"0\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  src=\"//jsfiddle.net/bgoonz/76osauer/1/embedded/result/\"\nallowfullscreen=\"allowfullscreen\" frameborder=\"0\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  src=\"//jsfiddle.net/bgoonz/vtz7820m/embedded/result/dark/\"\nallowfullscreen=\"allowfullscreen\" frameborder=\"0\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\nsrc=\"//jsfiddle.net/bgoonz/1dye9uws/2/embedded/js,html,css,result/dark/\" allowfullscreen=\"allowfullscreen\"\nframeborder=\"0\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    height=\"300\" style=\"width: 90%;\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\"  src=\"//jsfiddle.net/bgoonz/3mpgzkx7/1/embedded/\"\nallowfullscreen=\"allowfullscreen\" frameborder=\"0\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" src=\"https://codepen.io/bgoonz/embed/zYwJQaw?default-tab=html%2Cresult\"\nstyle=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"hvbrd-sockets (forked)\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" src=\"https://codesandbox.io/embed/bigo-3wqy4?fontsize=14&hidenavigation=1&theme=dark\"\nstyle=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"hvbrd-sockets (forked)\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\"\nsrc=\"https://codesandbox.io/embed/hvbrd-sockets-forked-vsi2o?fontsize=14&hidenavigation=1&theme=dark\"\nstyle=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"hvbrd-sockets (forked)\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" src=\"https://codesandbox.io/embed/summer-surf-p6dei?fontsize=14&hidenavigation=1&theme=dark\"\nstyle=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"summer-surf-p6dei\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n<!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n<br> <br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\"\nsrc=\"https://codesandbox.io/embed/sharp-feistel-x8bvv?fontsize=14&hidenavigation=1&theme=dark\"\nstyle=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"sharp-feistel-x8bvv\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n<!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\ntitle=\"3D Cover Flow in React! | @keyframers 3.7\"\nsrc=\"https://codepen.io/bgoonz/embed/ExZvGoZ?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"\n allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz42/pen/RwpeaWr'>3D Cover Flow in React! | @keyframers\n3.7</a> by Bryan\nC Guner\n(<a href='https://codepen.io/bgoonz42'>@bgoonz42</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Simple Typing Carousel \"\nsrc=\"https://codepen.io/bgoonz/embed/ExZvGoZ?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"\n allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/ExZvGoZ\">\nSimple Typing Carousel </a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\ntitle=\"3D Cover Flow in React! | @keyframers 3.7\"\nsrc=\"https://codepen.io/bgoonz42/embed/RwpeaWr?height=375&theme=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz42/pen/RwpeaWr'>3D Cover Flow in React! | @keyframers\n3.7</a> by Bryan\nC Guner\n(<a href='https://codepen.io/bgoonz42'>@bgoonz42</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Video Background 1\"\nsrc=\"https://codesandbox.io/embed/bgoonzblog20-oo3x5?fontsize=14&hidenavigation=1&theme=dark\"\nstyle=\"width:90%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"bgoonzblog2.0\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Video Background 1\"\nsrc=\"https://codepen.io/bgoonz/embed/BaRLKBd?default-tab=html%2Cresult&theme-id=dark\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/BaRLKBd\">\nVideo Background 1</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\ntitle=\"CSS-only Colorful Calendar Concept\" src=\"https://documentation-site-react2.vercel.app/\"\n  frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/vYmKQYj\">\n  CSS-only Colorful Calendar Concept</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"FullTextSearchjs\"\nsrc=\"https://codepen.io/bgoonz/embed/QWvMWoQ?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"\n allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/QWvMWoQ\">\n  FullTextSearchjs</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"CSS Grid: Info Card\"\nsrc=\"https://codepen.io/bgoonz42/embed/MWmpjmy?default-tab=html%2Cresult\"   frameborder=\"yes\" loading=\"lazy\"\n allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz42/pen/MWmpjmy\">\n  CSS Grid: Info Card</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz42\">@bgoonz42</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\ntitle=\"CSS-only Colorful Calendar Concept\"\nsrc=\"https://codepen.io/bgoonz/embed/vYmKQYj?default-tab=html%2Cresult&theme-id=dark\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/vYmKQYj\">\n  CSS-only Colorful Calendar Concept</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Dashed Border Generator\"\nsrc=\"https://random-static-html-deploys.netlify.app/dashed-border-generator.html\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href=\"https://codepen.io/bgoonz/pen/wvdgypd\">\n  Dashed Border Generator</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\non <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Particle tornado\"\nsrc=\"https://codepen.io/bgoonz/embed/VwPwRvr?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/VwPwRvr'>Particle tornado</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"A Simple Fade Effect on Scroll\"\nsrc=\"https://codepen.io/bgoonz/embed/OJWzbRa?height=375&theme-id=dark&default-tab=html,result\"\n  frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/OJWzbRa'>A Simple Fade Effect on Scroll</a> by Bryan C\nGuner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Controlled Text Example\"\nsrc=\"https://codepen.io/bgoonz/embed/oNZYbjZ?height=375&theme=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/oNZYbjZ'>Controlled Text Example</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"MatrixCode\"\nsrc=\"https://codepen.io/bgoonz/embed/KKaKbQX?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/KKaKbQX'>MatrixCode</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"TroisJS InstancedMesh Test\"\nsrc=\"https://codepen.io/bgoonz/embed/oNBNJMK?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/oNBNJMK'>TroisJS InstancedMesh Test</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"What's behind ?\"\nsrc=\"https://codepen.io/bgoonz/embed/mdRdaQV?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/mdRdaQV'>What's behind ?</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------Vector Swarm------------------------------------------->\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"VectorSwarm\"\nsrc=\"https://codepen.io/bgoonz/embed/BapavbW?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/BapavbW'>VectorSwarm</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Canvas Sparkly Circle Loader\"\nsrc=\"https://codepen.io/bgoonz/embed/ExZxMPN?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/ExZxMPN'>Canvas Sparkly Circle Loader</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Canvas particles\"\nsrc=\"https://codepen.io/bgoonz/embed/bGgGZEZ?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/bGgGZEZ'>Canvas particles</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Inline Styles with React\"\nsrc=\"https://codepen.io/bgoonz/embed/WNRjBoO?height=375&theme=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/WNRjBoO'>Inline Styles with React</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Constellation\"\nsrc=\"https://codepen.io/bgoonz/embed/zYNYbqK?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/zYNYbqK'>Constellation</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"95 000 particles\"\nsrc=\"https://codepen.io/bgoonz/embed/PoWoLNy?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/PoWoLNy'>95 000 particles</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<p class=\"codepen\" data-height=\"575\" data-theme-id=\"dark\" data-default-tab=\"html,result\" data-user=\"bgoonz\"\ndata-slug-hash=\"DmnlJ\"\nstyle=\"height: 375px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;\"\ndata-pen-title=\"Simple Responsive Form\">\n<span>See the Pen <a href=\"https://codepen.io/chriscoyier/pen/DmnlJ\">\n    Simple Responsive Form</a> by Bryan Guner (<a href=\"https://codepen.io/chriscoyier\">@bgoonz</a>)\n  on <a href=\"https://codepen.io\">CodePen</a>.</span>\n</p>\n<script async src=\"https://cpwebassets.codepen.io/assets/embed/ei.js\">\n</script>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Smooth Page Scrolling in jQuery\"\nsrc=\"https://codepen.io/bgoonz/embed/KKamLNy?height=375&theme=dark&default-tab=html,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/KKamLNy'>Smooth Page Scrolling in jQuery</a> by Bryan C\nGuner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Demo Flexbox 3\"\nsrc=\"https://codepen.io/bgoonz/embed/ZELKNBo?height=375&theme=dark&default-tab=css,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/ZELKNBo'>Demo Flexbox 3</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Scroll Drawing\"\nsrc=\"https://codepen.io/bgoonz/embed/abpWrBP?height=375&theme=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/abpWrBP'>Scroll Drawing</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Light Javascript Table Filter\"\nsrc=\"https://codepen.io/bgoonz/embed/qBRmGqw?height=375&theme=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/qBRmGqw'>Light Javascript Table Filter</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\"\nsrc=\"https://codesandbox.io/embed/cold-firefly-si5u1?fontsize=14&hidenavigation=1&theme=dark\"\nstyle=\"width:95%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"cold-firefly-si5u1\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\"\nsrc=\"https://codesandbox.io/embed/determined-star-57xlk?fontsize=14&hidenavigation=1&theme=dark\"\nstyle=\"width:95%; height:575px; border:0; border-radius: 4px; overflow:hidden;\" title=\"determined-star-57xlk\"\nsandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\">\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"CSS Grid: Excel Spreadsheet\"\nsrc=\"https://codepen.io/bgoonz/embed/abJYgGX?height=375&theme=dark&default-tab=css,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/abJYgGX'>CSS Grid: Excel Spreadsheet</a> by Bryan C\nGuner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"3D Drag out menu with guitar\"\nsrc=\"https://codepen.io/bgoonz/embed/QWpmXxq?height=375&theme=dark&default-tab=css,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/QWpmXxq'>3D Drag out menu with guitar</a> by Bryan C\nGuner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\"\ntitle=\"Navigation bar with circle flexible highlight POC\"\nsrc=\"https://codepen.io/bgoonz/embed/eYvMwKL?height=375&theme=dark&default-tab=css,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/eYvMwKL'>Navigation bar with circle flexible highlight\n  POC</a> by\nBryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"gsuiOscilloscope\"\nsrc=\"https://codepen.io/bgoonz/embed/eYvrgpe?height=375&theme=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/eYvrgpe'>gsuiOscilloscope</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"510\" style=\"width: 90%;\" scrolling=\"no\" title=\"random quote(React.js)\"\nsrc=\"https://codepen.io/bgoonz/embed/ZEeoyKv?height=510&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/ZEeoyKv'>random quote(React.js)</a> by Bryan C Guner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<!-------------------------------------------------------------------------------------->\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    loading=\"lazy\" height=\"575\" style=\"width: 90%;\" scrolling=\"no\" title=\"Web Audio API: Lightning Talk\"\nsrc=\"https://codepen.io/bgoonz/embed/GRWdvNm?height=375&theme-id=dark&default-tab=js,result\" frameborder=\"no\"\nloading=\"lazy\"  allowfullscreen=\"true\">\nSee the Pen <a href='https://codepen.io/bgoonz/pen/GRWdvNm'>Web Audio API: Lightning Talk</a> by Bryan C\nGuner\n(<a href='https://codepen.io/bgoonz'>@bgoonz</a>) on <a href='https://codepen.io'>CodePen</a>.\n</iframe>\n<br>\n <br>\n <br>\n<br>\n<br>\n<br>\n<br>\n <br>\n <br>\n<br>\n<br>"},{"url":"/docs/projects/recent/","relativePath":"docs/projects/recent.md","relativeDir":"docs/projects","base":"recent.md","name":"recent","frontmatter":{"title":"recent","template":"docs","excerpt":"recent projects and websites"},"html":"<h1>Recent Projects:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://iframeshowcase.netlify.app/\" style=\"border:1px #ffffff solid;\" name=\"myiFrame\" scrolling=\"yes\" frameborder=\"1\" marginheight=\"0px\" marginwidth=\"0px\" height=\"800px\" width=\"1200px\" allowfullscreen>\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://bgoonz.github.io/pure-html-pages-blog/\" style=\"border:1px #ffffff solid;\" name=\"myiFrame\" scrolling=\"yes\" frameborder=\"1\" marginheight=\"0px\" marginwidth=\"0px\" height=\"800px\" width=\"1200px\" allowfullscreen>\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://lambda-static-assets.netlify.app/\" style=\"border:1px #ffffff solid;\" name=\"myiFrame\" scrolling=\"yes\" frameborder=\"1\" marginheight=\"0px\" marginwidth=\"0px\" height=\"800px\" width=\"1200px\" allowfullscreen>\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://notion-nro8y8drl-bgoonz.vercel.app/\" style=\"border:1px #ffffff solid;\" name=\"myiFrame\" scrolling=\"yes\" frameborder=\"1\" marginheight=\"0px\" marginwidth=\"0px\" height=\"800px\" width=\"1200px\" allowfullscreen>\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://web-dev-utility-tools-bgoonz.netlify.app/\" style=\"border:1px #ffffff solid;\" name=\"myiFrame\" scrolling=\"yes\" frameborder=\"1\" marginheight=\"0px\" marginwidth=\"0px\" height=\"800px\" width=\"1200px\" allowfullscreen>\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://bgoonz.github.io/Project-Showcase/\" style=\"border:1px #ffffff solid;\" name=\"myiFrame\" scrolling=\"yes\" frameborder=\"1\" marginheight=\"0px\" marginwidth=\"0px\" height=\"800px\" width=\"1200px\" allowfullscreen>\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://bryan-guner.gitbook.io/job-search/\" style=\"border:1px #ffffff solid;\" name=\"myiFrame\" scrolling=\"yes\" frameborder=\"1\" marginheight=\"0px\" marginwidth=\"0px\" height=\"800px\" width=\"1200px\" allowfullscreen>\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://bg-portfolio.netlify.app/\" style=\"border:1px #ffffff solid;\" name=\"myiFrame\" scrolling=\"yes\" frameborder=\"1\" marginheight=\"0px\" marginwidth=\"0px\" height=\"800px\" width=\"1200px\" allowfullscreen>\n</iframe>\n<br>\n<h2>Embeds:</h2>\n<!----------------------------------google form---------------------------------------->\n <iframe src=\"https://docs.google.com/forms/d/e/1FAIpQLSfCfTOg1FRiAQwvQg-OkqVbvcZu-_up_iWJoUwRefZWJjWaeA/viewform?embedded=true\" width=\"640\" height=\"845\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\">Loading…</iframe>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/YzZozOM?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/gOmVErj?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/vYmYzqw?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\" https://codesandbox.io/embed/bigo-3wqy4?fontsize=14&hidenavigation=1&theme=dark\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://documentation-site-react2.vercel.app/\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://bgoonz-blog.netlify.app/\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://bgoonz-blog.netlify.app/blog/\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://bgoonz-blog.netlify.app/blog/data-structures/\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/MWpMWzE?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/rNyENQJ?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/zYZVYMj?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/XWMELYy?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/QWpmXxq?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/eYvMKwe?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/QWpmmom?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/QWpmmPm?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/JjWLLqj?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/MWpVVLP?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/gOmeeEm?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/NWgdZyq?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/RwKYRoo?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/LYyBwEp?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/QWgYoBp?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/ExZvGoZ?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/MWbxYme?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/dyOaoXb?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/ExZxMPN?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/ZEKOmYW?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/bGWgLaR?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/QWvMQrb?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/JjNXROo?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/abWNmqo?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/bGWpwvv?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/mdmPrwR?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/BaRKLZw?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/RwVaGZo?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/BaRdabZ?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/OJWzbRa?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/KKaJwgo?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/ExZrayM?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/yLgZLrp?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/dyNayLB?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/PoWVovN?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/VwPgwgo?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/YzNBzbK?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/NWdoWVp?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/mdRvdzd?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/LYxqYMa?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/wvgNvYW?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/LYxqYBq?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/jOydOvm?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/ZELwEMv?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/oNBmNPV?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/WNRPbeO?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/poRGvzp?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/WNRPNpw?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/NWdoWvN?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/LYxqEZP?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/wvgNByP?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/eYgxmyx?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/JjExopj?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/GRrzRGR?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/vYxGLao?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/abwzxKP?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/XWgJQYP?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/powvBZp?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/wveBJBM?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/QWgwpGv?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/powvegw?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/eYRmvJV?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/GREgWEp?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/NWgdVOJ?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/QWgdVaa?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/MWmGPvO?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/rNmJMaz?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/MWmQjYJ?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n <iframe src=\"https://codepen.io/bgoonz/embed/eYWVdmR?default-tab=result\" style=\"width:1000px; height:1200px;\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen></iframe>\n<hr>\n<hr>\n</div>\n<h1>Text Tools</h1>\n<h3>Ternary Converter\n\n</h3>\n<p>\\ <iframe src=\" <https://ternary42.netlify.app />\" height=\"800px\" width=\"600px!important\" scrolling=\"yes\"\nframeborder=\"no\" loading=\"lazy\" allowtransparency=\"true\" allowfullscreen=\"true\" title=\"YouTube video player\"\nframeborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\"\nallowfullscreen>&#x3C;/iframe></p>"},{"url":"/docs/projects/project-list/","relativePath":"docs/projects/project-list.md","relativeDir":"docs/projects","base":"project-list.md","name":"project-list","frontmatter":{"title":"Projects ","excerpt":"We'd love it if you participate in the Web-Dev-Hubcommunity. Find out how to get connected.","seo":{"title":"List Of Projects","description":"introductory-react-part-2\na-very-quick-guide-to-calculating-big-o-computational-complexity\nintroduction-to-react css-animations\n","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"List Of Projects Articles","keyName":"property"},{"name":"og:description","value":"","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"List Of Projectss"},{"name":"twitter:description","value":"This is the community page"},{"name":"og:image","value":"images/beige-maple.png","keyName":"property","relativeUrl":true}]},"template":"docs","weight":0},"html":"<ol>\n<li><a href=\"https://web-dev-resource-hub.netlify.app\">WEB DEV RESOURCE HUB</a></li>\n<li><a href=\"https://learning-redux42.netlify.app/\">Learn Redux</a></li>\n<li><a href=\"https://trusting-dijkstra-4d3b17.netlify.app\">Data Structures Website</a></li>\n<li><a href=\"https://web-dev-interview-prep-quiz-website.netlify.app/intro-js2.html\">Web-Dev-Quizzes</a></li>\n<li><a href=\"https://zen-lamport-5aab2c.netlify.app\">Recursion</a></li>\n<li><a href=\"https://csb-ov0d1-bgoonz.vercel.app/\">React Documentation Site</a></li>\n<li><a href=\"https://amazing-hodgkin-33aea6.netlify.app\">Blogs-from-webdevhub</a></li>\n<li><a href=\"https://angry-fermat-dcf5dd.netlify.app\">Realty Website Demo</a></li>\n<li><a href=\"https://boring-heisenberg-f425d8.netlify.app\">Best-Prac &#x26; Tools</a></li>\n<li><a href=\"https://site-analysis.netlify.app/\">site-analysis</a></li>\n<li><a href=\"https://clever-bartik-b5ba19.netlify.app\">a/AOpen Notes</a></li>\n<li><a href=\"https://code-playground.netlify.app\">Iframe Embed Playground</a></li>\n<li><a href=\"https://condescending-lewin-c96727.netlify.app\">Triggered Effects Guitar Platform</a></li>\n<li><a href=\"https://determined-dijkstra-666766.netlify.app\">Live Form</a></li>\n<li><a href=\"https://determined-dijkstra-ee7390.netlify.app\">Interview Questions</a></li>\n<li><a href=\"https://eager-northcutt-456076.netlify.app\">Resources Compilation</a></li>\n<li><a href=\"https://ecstatic-jang-593fd1.netlify.app\">React Blog Depreciated</a></li>\n<li><a href=\"https://eloquent-sammet-ba1810.netlify.app\">MihirBeg.com</a></li>\n<li><a href=\"https://embedable-content.netlify.app\">Embeded Html Projects</a></li>\n<li><a href=\"https://festive-borg-e4d856.netlify.app\">Cheat Sheets</a></li>\n<li><a href=\"https://focused-pasteur-0faac8.netlify.app\">Early Version Of WebDevHub</a></li>\n<li><a href=\"https://gists42.netlify.app\">My Gists</a></li>\n<li><a href=\"https://gracious-raman-474030.netlify.app\">DS-Algo-Links</a></li>\n<li><a href=\"https://happy-mestorf-0f8e75.netlify.app\">Video Chat App</a></li>\n<li><a href=\"https://hungry-shaw-30d504.netlify.app\">Ciriculumn</a></li>\n<li><a href=\"https://inspiring-jennings-d14689.netlify.app\">Cheat Sheets</a></li>\n<li><a href=\"https://links4242.netlify.app\">Links</a></li>\n<li><a href=\"https://modest-booth-4e17df.netlify.app\">Medium Articles</a></li>\n<li><a href=\"https://modest-torvalds-34afbc.netlify.app\">NextJS Blog Template</a></li>\n<li><a href=\"https://modest-varahamihira-772b59.netlify.app\">React Demo</a></li>\n<li><a href=\"https://nervous-swartz-0ab2cc.netlify.app\">Ecomerce Norwex V1</a></li>\n<li><a href=\"https://objective-borg-a327cd.netlify.app\">Gifs</a></li>\n<li><a href=\"https://pedantic-wing-adbf82.netlify.app\">Excel2HTML</a></li>\n<li><a href=\"https://pensive-meitner-1ea8c4.netlify.app\">Data Structures Site</a></li>\n<li><a href=\"https://portfolio42.netlify.app\">Portfolio</a></li>\n<li><a href=\"https://priceless-shaw-86ccb2.netlify.app\">Page Templates</a></li>\n<li><a href=\"https://quizzical-mcnulty-fa09f2.netlify.app\">Photo Gallary</a></li>\n<li><a href=\"https://relaxed-bhaskara-dc85ec.netlify.app\">Coffee Website</a></li>\n<li><a href=\"https://romantic-hamilton-514b79.netlify.app\">Awesome Resources</a></li>\n<li><a href=\"https://silly-lichterman-b22b5f.netlify.app\">Cheat Sheets</a></li>\n<li><a href=\"https://silly-shirley-ec955e.netlify.app\">Link City</a></li>\n<li><a href=\"https://stoic-mccarthy-2c335f.netlify.app\">VSCODE Extensions</a></li>\n<li><a href=\"https://web-dev-resource-hub-manual-deploy.netlify.app\">webdevhub manual attempt</a></li>\n<li><a href=\"https://wonderful-pasteur-392fbe.netlify.app\">Norwex Resources</a></li>\n<li><a href=\"https://zen-bhabha-bd046f.netlify.app\">idk</a></li>\n<li><a href=\"https://getting-started42.herokuapp.com/\">heroku bare bones template</a></li>\n<li><a href=\"https://bad-reads42.herokuapp.com/\">bad reads</a></li>\n<li><a href=\"https://documentation-site-react2.vercel.app/\">docusaurus</a></li>\n<li><a href=\"https://app.stackbit.com/studio/609b2d7c71a5dd0016f36326\">stackbit</a></li>\n</ol>\n<hr>\n<h1>More</h1>\n<ul>\n<li><a href=\"https://admiring-montalcini-965c0b.netlify.app\">https://admiring-montalcini-965c0b</a></li>\n<li><a href=\"https://adoring-carson-fac9fb.netlify.app\">https://adoring-carson-fac9fb</a></li>\n<li><a href=\"https://adoring-nobel-85c068.netlify.app\">https://adoring-nobel-85c068</a></li>\n<li><a href=\"https://bg-portfolio.netlify.app\">https://bg-portfolio</a></li>\n<li><a href=\"https://bg-resume.netlify.app\">https://bg-resume</a></li>\n<li><a href=\"https://bgoonz-blog-v3-0.netlify.app\">https://bgoonz-blog-v3-0</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app\">https://bgoonz-blog</a></li>\n<li><a href=\"https://bgoonz-bookmarks.netlify.app\">https://bgoonz-bookmarks</a></li>\n<li><a href=\"https://bgoonz-cv.netlify.app\">https://bgoonz-cv</a></li>\n<li><a href=\"https://bgoonz-games.netlify.app\">https://bgoonz-games</a></li>\n<li><a href=\"https://bgoonzblog20-backup.netlify.app\">https://bgoonzblog20-backup</a></li>\n<li><a href=\"https://bgoonzblog20-redo.netlify.app\">https://bgoonzblog20-redo</a></li>\n<li><a href=\"https://bgoonzblog20starter.netlify.app\">https://bgoonzblog20starter</a></li>\n<li><a href=\"https://bgoonzblog30.netlify.app\">https://bgoonzblog30</a></li>\n<li><a href=\"https://bgoonzconnekt4.netlify.app\">https://bgoonzconnekt4</a></li>\n<li><a href=\"https://bgoonzgist\">https://bgoonzgist</a></li>\n<li><a href=\"https://bgoonzmedium.netlify.app\">https://bgoonzmedium</a></li>\n<li><a href=\"https://bicknborty.netlify.app\">https://bicknborty</a></li>\n<li><a href=\"https://blog-v42-31eba.netlify.app\">https://blog-v42-31eba</a></li>\n<li><a href=\"https://blog3-backup-dd7df.netlify.app\">https://blog3-backup-dd7df</a></li>\n<li><a href=\"https://cheatsheets42\">https://cheatsheets42</a></li>\n<li><a href=\"https://clever-ramanujan-f9ce0a.netlify.app\">https://clever-ramanujan-f9ce0a</a></li>\n<li><a href=\"https://code-playground.netlify.app\">https://code-playground</a></li>\n<li><a href=\"https://condescending-lewin-c96727.netlify.app\">https://condescending-lewin-c96727</a></li>\n<li><a href=\"https://curious-rabbit-f33af.netlify.app\">https://curious-rabbit-f33af</a></li>\n<li><a href=\"https://determined-dijkstra-ee7390\">https://determined-dijkstra-ee7390</a></li>\n<li><a href=\"https://dev-journal42.netlify.app\">https://dev-journal42</a></li>\n<li><a href=\"https://devtools42.netlify.app\">https://devtools42</a></li>\n<li><a href=\"https://docs42.netlify.app\">https://docs42</a></li>\n<li><a href=\"https://ds-algo-official.netlify.app\">https://ds-algo-official</a></li>\n<li><a href=\"https://ds-unit-5-lambda\">https://ds-unit-5-lambda</a></li>\n<li><a href=\"https://elegant-goodall-566182\">https://elegant-goodall-566182</a></li>\n<li><a href=\"https://elite-cabbage-3551b.netlify.app\">https://elite-cabbage-3551b</a></li>\n<li><a href=\"https://enthusiastic-tomato-a7ebc\">https://enthusiastic-tomato-a7ebc</a></li>\n<li><a href=\"https://exploring-next-sanity.netlify.app\">https://exploring-next-sanity</a></li>\n<li><a href=\"https://festive-elion-13b19c.netlify.app\">https://festive-elion-13b19c</a></li>\n<li><a href=\"https://festive-kilby-f0a784\">https://festive-kilby-f0a784</a></li>\n<li><a href=\"https://flamboyant-northcutt-14b025.netlify.app\">https://flamboyant-northcutt-14b025</a></li>\n<li><a href=\"https://fourm-builder-gui.netlify.app\">https://fourm-builder-gui</a></li>\n<li><a href=\"https://friendly-amaranth-51833.netlify.app\">https://friendly-amaranth-51833</a></li>\n<li><a href=\"https://friendly-poincare-a11e2f.netlify.app\">https://friendly-poincare-a11e2f</a></li>\n<li><a href=\"https://githtmlpreview.netlify.app\">https://githtmlpreview</a></li>\n<li><a href=\"https://github.com/bgoonz/alternate-blog-theme\">https://github.com/bgoonz/alternate-blog-theme</a></li>\n<li><a href=\"https://github.com/bgoonz/atlassian-templates\">https://github.com/bgoonz/atlassian-templates</a></li>\n<li><a href=\"https://github.com/bgoonz/bgoonz.github.io\">https://github.com/bgoonz/bgoonz.github.io</a></li>\n<li><a href=\"https://github.com/bgoonz/BGOONZBLOG2.0STABLE\">https://github.com/bgoonz/BGOONZBLOG2.0STABLE</a></li>\n<li><a href=\"https://github.com/bgoonz/bgoonzblog3.0\">https://github.com/bgoonz/bgoonzblog3.0</a></li>\n<li><a href=\"https://github.com/bgoonz/blog-research\">https://github.com/bgoonz/blog-research</a></li>\n<li><a href=\"https://github.com/bgoonz/blog-v42\">https://github.com/bgoonz/blog-v42</a></li>\n<li><a href=\"https://github.com/bgoonz/blog3-backup\">https://github.com/bgoonz/blog3-backup</a></li>\n<li><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store42\">https://github.com/bgoonz/commercejs-nextjs-demo-store42</a></li>\n<li><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store\">https://github.com/bgoonz/commercejs-nextjs-demo-store</a></li>\n<li><a href=\"https://github.com/bgoonz/Common-npm-Readme-Compilation\">https://github.com/bgoonz/Common-npm-Readme-Compilation</a></li>\n<li><a href=\"https://github.com/bgoonz/Connect-Four-Final-Version\">https://github.com/bgoonz/Connect-Four-Final-Version</a></li>\n<li><a href=\"https://github.com/bgoonz/cool-hickory\">https://github.com/bgoonz/cool-hickory</a></li>\n<li><a href=\"https://github.com/bgoonz/Cumulative-Resource-List\">https://github.com/bgoonz/Cumulative-Resource-List</a></li>\n<li><a href=\"https://github.com/bgoonz/curious-eggplant\">https://github.com/bgoonz/curious-eggplant</a></li>\n<li><a href=\"https://github.com/bgoonz/curious-zebra\">https://github.com/bgoonz/curious-zebra</a></li>\n<li><a href=\"https://github.com/bgoonz/Data-Struc-Static\">https://github.com/bgoonz/Data-Struc-Static</a></li>\n<li><a href=\"https://github.com/bgoonz/docs-collection\">https://github.com/bgoonz/docs-collection</a></li>\n<li><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">https://github.com/bgoonz/DS-ALGO-OFFICIAL</a></li>\n<li><a href=\"https://github.com/bgoonz/ecommerce-interactive\">https://github.com/bgoonz/ecommerce-interactive</a></li>\n<li><a href=\"https://github.com/bgoonz/ecommerce-react\">https://github.com/bgoonz/ecommerce-react</a></li>\n<li><a href=\"https://github.com/bgoonz/elite-cabbage\">https://github.com/bgoonz/elite-cabbage</a></li>\n<li><a href=\"https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground\">https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground</a></li>\n<li><a href=\"https://github.com/bgoonz/excel2html-table\">https://github.com/bgoonz/excel2html-table</a></li>\n<li><a href=\"https://github.com/bgoonz/form-builder-vanilla-js\">https://github.com/bgoonz/form-builder-vanilla-js</a></li>\n<li><a href=\"https://github.com/bgoonz/friendly-amaranth\">https://github.com/bgoonz/friendly-amaranth</a></li>\n<li><a href=\"https://github.com/bgoonz/Games\">https://github.com/bgoonz/Games</a></li>\n<li><a href=\"https://github.com/bgoonz/gatsby-netlify-cms\">https://github.com/bgoonz/gatsby-netlify-cms</a></li>\n<li><a href=\"https://github.com/bgoonz/gatsby-starter-portfolio-cara\">https://github.com/bgoonz/gatsby-starter-portfolio-cara</a></li>\n<li><a href=\"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL\">https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL</a></li>\n<li><a href=\"https://github.com/bgoonz/graceful-pine\">https://github.com/bgoonz/graceful-pine</a></li>\n<li><a href=\"https://github.com/bgoonz/html-resume\">https://github.com/bgoonz/html-resume</a></li>\n<li><a href=\"https://github.com/bgoonz/https___mihirbeg.com_\">https://github.com/bgoonz/https<em>__mihirbeg.com</em></a></li>\n<li><a href=\"https://github.com/bgoonz/hugo-cms\">https://github.com/bgoonz/hugo-cms</a></li>\n<li><a href=\"https://github.com/bgoonz/iframe-showcase\">https://github.com/bgoonz/iframe-showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/interesting-aspen\">https://github.com/bgoonz/interesting-aspen</a></li>\n<li><a href=\"https://github.com/bgoonz/jamstack-comments-engine1\">https://github.com/bgoonz/jamstack-comments-engine1</a></li>\n<li><a href=\"https://github.com/bgoonz/jamstack-comments-engine2\">https://github.com/bgoonz/jamstack-comments-engine2</a></li>\n<li><a href=\"https://github.com/bgoonz/jamstack-comments-engine\">https://github.com/bgoonz/jamstack-comments-engine</a></li>\n<li><a href=\"https://github.com/bgoonz/kind-petunia\">https://github.com/bgoonz/kind-petunia</a></li>\n<li><a href=\"https://github.com/bgoonz/lambda-prep\">https://github.com/bgoonz/lambda-prep</a></li>\n<li><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\">https://github.com/bgoonz/Lambda-Resource-Static-Assets</a></li>\n<li><a href=\"https://github.com/bgoonz/Lambda\">https://github.com/bgoonz/Lambda</a></li>\n<li><a href=\"https://github.com/bgoonz/Links-Shortcut-Site\">https://github.com/bgoonz/Links-Shortcut-Site</a></li>\n<li><a href=\"https://github.com/bgoonz/live-form\">https://github.com/bgoonz/live-form</a></li>\n<li><a href=\"https://github.com/bgoonz/Live-htmlRendered-Mocha-Spec--Recursion-Practice\">https://github.com/bgoonz/Live-htmlRendered-Mocha-Spec--Recursion-Practice</a></li>\n<li><a href=\"https://github.com/bgoonz/marvelous-aluminum\">https://github.com/bgoonz/marvelous-aluminum</a></li>\n<li><a href=\"https://github.com/bgoonz/meditation-app\">https://github.com/bgoonz/meditation-app</a></li>\n<li><a href=\"https://github.com/bgoonz/Medium_Articles\">https://github.com/bgoonz/Medium_Articles</a></li>\n<li><a href=\"https://github.com/bgoonz/MihirBegMusicLab\">https://github.com/bgoonz/MihirBegMusicLab</a></li>\n<li><a href=\"https://github.com/bgoonz/Mihir_Beg_Final\">https://github.com/bgoonz/Mihir<em>Beg</em>Final</a></li>\n<li><a href=\"https://github.com/bgoonz/mini-project-showcase\">https://github.com/bgoonz/mini-project-showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/modern-triceratops\">https://github.com/bgoonz/modern-triceratops</a></li>\n<li><a href=\"https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard\">https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard</a></li>\n<li><a href=\"https://github.com/bgoonz/My-Medium-Blog\">https://github.com/bgoonz/My-Medium-Blog</a></li>\n<li><a href=\"https://github.com/bgoonz/nervous-parsley\">https://github.com/bgoonz/nervous-parsley</a></li>\n<li><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template2\">https://github.com/bgoonz/nextjs-netlify-blog-template2</a></li>\n<li><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template42\">https://github.com/bgoonz/nextjs-netlify-blog-template42</a></li>\n<li><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template\">https://github.com/bgoonz/nextjs-netlify-blog-template</a></li>\n<li><a href=\"https://github.com/bgoonz/norwex-react\">https://github.com/bgoonz/norwex-react</a></li>\n<li><a href=\"https://github.com/bgoonz/ntn-boilerplate\">https://github.com/bgoonz/ntn-boilerplate</a></li>\n<li><a href=\"https://github.com/bgoonz/oval-cabbage\">https://github.com/bgoonz/oval-cabbage</a></li>\n<li><a href=\"https://github.com/bgoonz/panoramic-eggplant\">https://github.com/bgoonz/panoramic-eggplant</a></li>\n<li><a href=\"https://github.com/bgoonz/Potluck-Planner\">https://github.com/bgoonz/Potluck-Planner</a></li>\n<li><a href=\"https://github.com/bgoonz/Project-Showcase\">https://github.com/bgoonz/Project-Showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/python-playground-embed\">https://github.com/bgoonz/python-playground-embed</a></li>\n<li><a href=\"https://github.com/bgoonz/PYTHON_PRAC\">https://github.com/bgoonz/PYTHON_PRAC</a></li>\n<li><a href=\"https://github.com/bgoonz/random-list-of-embedable-content\">https://github.com/bgoonz/random-list-of-embedable-content</a></li>\n<li><a href=\"https://github.com/bgoonz/random-static-html-page-deploy\">https://github.com/bgoonz/random-static-html-page-deploy</a></li>\n<li><a href=\"https://github.com/bgoonz/React-Practice\">https://github.com/bgoonz/React-Practice</a></li>\n<li><a href=\"https://github.com/bgoonz/react-web-anki-flash-cards\">https://github.com/bgoonz/react-web-anki-flash-cards</a></li>\n<li><a href=\"https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering\">https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-catalyst\">https://github.com/bgoonz/sanity-catalyst</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-commercelayer1\">https://github.com/bgoonz/sanity-commercelayer1</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-commercelayer\">https://github.com/bgoonz/sanity-commercelayer</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-blog3\">https://github.com/bgoonz/sanity-gatsby-blog3</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-blog4\">https://github.com/bgoonz/sanity-gatsby-blog4</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-blog\">https://github.com/bgoonz/sanity-gatsby-blog</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-hey-sugar2\">https://github.com/bgoonz/sanity-gatsby-hey-sugar2</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-hey-sugar5\">https://github.com/bgoonz/sanity-gatsby-hey-sugar5</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-hey-sugar\">https://github.com/bgoonz/sanity-gatsby-hey-sugar</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-portfolio3\">https://github.com/bgoonz/sanity-gatsby-portfolio3</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-gatsby-portfolio\">https://github.com/bgoonz/sanity-gatsby-portfolio</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-jigsaw-blog\">https://github.com/bgoonz/sanity-jigsaw-blog</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-kitchen-sink2\">https://github.com/bgoonz/sanity-kitchen-sink2</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-kitchen-sink3\">https://github.com/bgoonz/sanity-kitchen-sink3</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-kitchen-sink5\">https://github.com/bgoonz/sanity-kitchen-sink5</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-kitchen-sink\">https://github.com/bgoonz/sanity-kitchen-sink</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-nuxt-events\">https://github.com/bgoonz/sanity-nuxt-events</a></li>\n<li><a href=\"https://github.com/bgoonz/sanity-translation-examples\">https://github.com/bgoonz/sanity-translation-examples</a></li>\n<li><a href=\"https://github.com/bgoonz/scope-closure-context\">https://github.com/bgoonz/scope-closure-context</a></li>\n<li><a href=\"https://github.com/bgoonz/searching-bick-n-borty-api\">https://github.com/bgoonz/searching-bick-n-borty-api</a></li>\n<li><a href=\"https://github.com/bgoonz/site-analysis\">https://github.com/bgoonz/site-analysis</a></li>\n<li><a href=\"https://github.com/bgoonz/smart-artichoke\">https://github.com/bgoonz/smart-artichoke</a></li>\n<li><a href=\"https://github.com/bgoonz/Standalone-Metranome\">https://github.com/bgoonz/Standalone-Metranome</a></li>\n<li><a href=\"https://github.com/bgoonz/starter\">https://github.com/bgoonz/starter</a></li>\n<li><a href=\"https://github.com/bgoonz/successful-cabbage\">https://github.com/bgoonz/successful-cabbage</a></li>\n<li><a href=\"https://github.com/bgoonz/Ternary-converter\">https://github.com/bgoonz/Ternary-converter</a></li>\n<li><a href=\"https://github.com/bgoonz/terrific-dolphin\">https://github.com/bgoonz/terrific-dolphin</a></li>\n<li><a href=\"https://github.com/bgoonz/TetrisJS\">https://github.com/bgoonz/TetrisJS</a></li>\n<li><a href=\"https://github.com/bgoonz/TexTools\">https://github.com/bgoonz/TexTools</a></li>\n<li><a href=\"https://github.com/bgoonz/vscode-Extension-readmes\">https://github.com/bgoonz/vscode-Extension-readmes</a></li>\n<li><a href=\"https://github.com/bgoonz/web-dev-interview-prep-quiz-website\">https://github.com/bgoonz/web-dev-interview-prep-quiz-website</a></li>\n<li><a href=\"https://github.com/bgoonz/web-dev-notes-backup\">https://github.com/bgoonz/web-dev-notes-backup</a></li>\n<li><a href=\"https://github.com/bgoonz/week-10-take-2\">https://github.com/bgoonz/week-10-take-2</a></li>\n<li><a href=\"https://github.com/bgoonz/yellowcake-mailchimp\">https://github.com/bgoonz/yellowcake-mailchimp</a></li>\n<li><a href=\"https://github.com/bgoonz/zumzi-chat-messenger\">https://github.com/bgoonz/zumzi-chat-messenger</a></li>\n<li><a href=\"https://github.com/my-lambda-projects/peer\">https://github.com/my-lambda-projects/peer</a></li>\n<li><a href=\"https://github.com/side-projects-42/DS-Bash-Examples-Deploy\">https://github.com/side-projects-42/DS-Bash-Examples-Deploy</a></li>\n<li><a href=\"https://github.com/side-projects-42/friendly-panda\">https://github.com/side-projects-42/friendly-panda</a></li>\n<li><a href=\"https://github.com/side-projects-42/superb-celery\">https://github.com/side-projects-42/superb-celery</a></li>\n<li><a href=\"https://github.com/stackbit-projects/best-celery-b2d7c\">https://github.com/stackbit-projects/best-celery-b2d7c</a></li>\n<li><a href=\"https://github.com/stackbit-projects/curious-rabbit-f33af\">https://github.com/stackbit-projects/curious-rabbit-f33af</a></li>\n<li><a href=\"https://github.com/stackbit-projects/oceanic-pluto-4029d\">https://github.com/stackbit-projects/oceanic-pluto-4029d</a></li>\n<li><a href=\"https://github.com/stackbit-projects/splendid-onion-b0ec3\">https://github.com/stackbit-projects/splendid-onion-b0ec3</a></li>\n<li><a href=\"https://github.com/Web-Dev-Collaborative/fractions-visualizations-n-resources\">https://github.com/Web-Dev-Collaborative/fractions-visualizations-n-resources</a></li>\n<li><a href=\"https://gitlab.com/bryan.guner.dev/algo-prac\">https://gitlab.com/bryan.guner.dev/algo-prac</a></li>\n<li><a href=\"https://gitlab.com/bryan.guner.dev/one-click-hugo-cms\">https://gitlab.com/bryan.guner.dev/one-click-hugo-cms</a></li>\n<li><a href=\"https://gitlab.com/bryan.guner.dev/starter-hugo-online-course\">https://gitlab.com/bryan.guner.dev/starter-hugo-online-course</a></li>\n<li><a href=\"https://goofy-curran-95aa66.netlify.app\">https://goofy-curran-95aa66</a></li>\n<li><a href=\"https://gracious-raman-474030.netlify.app\">https://gracious-raman-474030</a></li>\n<li><a href=\"https://happy-mestorf-0f8e75.netlify.app\">https://happy-mestorf-0f8e75</a></li>\n<li><a href=\"https://hardcore-hamilton-c5b45e.netlify.app\">https://hardcore-hamilton-c5b45e</a></li>\n<li><a href=\"https://hardcore-lamport-7eb855.netlify.app\">https://hardcore-lamport-7eb855</a></li>\n<li><a href=\"https://hopeful-shockley-150bee.netlify.app\">https://hopeful-shockley-150bee</a></li>\n<li><a href=\"https://hugo-cms-42.netlify.app\">https://hugo-cms-42</a></li>\n<li><a href=\"https://hungry-shaw-30d504\">https://hungry-shaw-30d504</a></li>\n<li><a href=\"https://iframeshowcase.netlify.app\">https://iframeshowcase</a></li>\n<li><a href=\"https://interesting-aspen-ce986.netlify.app\">https://interesting-aspen-ce986</a></li>\n<li><a href=\"https://jovial-agnesi-8ec8b1.netlify.app\">https://jovial-agnesi-8ec8b1</a></li>\n<li><a href=\"https://jovial-keller-063835.netlify.app\">https://jovial-keller-063835</a></li>\n<li><a href=\"https://keen-williams-48be7c\">https://keen-williams-48be7c</a></li>\n<li><a href=\"https://kguner-fractions-website.netlify.app\">https://kguner-fractions-website</a></li>\n<li><a href=\"https://kind-petunia-e8f9f.netlify.app\">https://kind-petunia-e8f9f</a></li>\n<li><a href=\"https://lambda-prep.netlify.app\">https://lambda-prep</a></li>\n<li><a href=\"https://lambda-resources.netlify.app\">https://lambda-resources</a></li>\n<li><a href=\"https://learning-redux42\">https://learning-redux42</a></li>\n<li><a href=\"https://links4242.netlify.app\">https://links4242</a></li>\n<li><a href=\"https://live-form.netlify.app\">https://live-form</a></li>\n<li><a href=\"https://marvelous-aluminum-11a84.netlify.app\">https://marvelous-aluminum-11a84</a></li>\n<li><a href=\"https://meditate42app.netlify.app\">https://meditate42app</a></li>\n<li><a href=\"https://memes42069.netlify.app\">https://memes42069</a></li>\n<li><a href=\"https://mihirbeg28.netlify.app\">https://mihirbeg28</a></li>\n<li><a href=\"https://mihirbegmusiclab.netlify.app\">https://mihirbegmusiclab</a></li>\n<li><a href=\"https://mihirbegmusic.netlify.app\">https://mihirbegmusic</a></li>\n<li><a href=\"https://modest-booth-4e17df.netlify.app\">https://modest-booth-4e17df</a></li>\n<li><a href=\"https://nervous-swartz-0ab2cc.netlify.app\">https://nervous-swartz-0ab2cc</a></li>\n<li><a href=\"https://norwex-next-js.netlify.app\">https://norwex-next-js</a></li>\n<li><a href=\"https://objective-rosalind-d4ff71.netlify.app\">https://objective-rosalind-d4ff71</a></li>\n<li><a href=\"https://objective-torvalds-1c12dd.netlify.app\">https://objective-torvalds-1c12dd</a></li>\n<li><a href=\"https://optimistic-curie-ddd352.netlify.app\">https://optimistic-curie-ddd352</a></li>\n<li><a href=\"https://oval-cabbage-354f6.netlify.app\">https://oval-cabbage-354f6</a></li>\n<li><a href=\"https://pedantic-wing-adbf82.netlify.app\">https://pedantic-wing-adbf82</a></li>\n<li><a href=\"https://portfolio42.netlify.app\">https://portfolio42</a></li>\n<li><a href=\"https://potluck-landing.netlify.app\">https://potluck-landing</a></li>\n<li><a href=\"https://priceless-shaw-86ccb2.netlify.app\">https://priceless-shaw-86ccb2</a></li>\n<li><a href=\"https://project-portfolio42.netlify.app\">https://project-portfolio42</a></li>\n<li><a href=\"https://project-showcase-bgoonz.netlify.app\">https://project-showcase-bgoonz</a></li>\n<li><a href=\"https://py-prac-42.netlify.app\">https://py-prac-42</a></li>\n<li><a href=\"https://python-playground42.netlify.app\">https://python-playground42</a></li>\n<li><a href=\"https://python-playground43\">https://python-playground43</a></li>\n<li><a href=\"https://quirky-meninsky-4181b5.netlify.app\">https://quirky-meninsky-4181b5</a></li>\n<li><a href=\"https://random-embedable-content.netlify.app\">https://random-embedable-content</a></li>\n<li><a href=\"https://random-static-html-deploys.netlify.app\">https://random-static-html-deploys</a></li>\n<li><a href=\"https://react-blog-1.netlify.app\">https://react-blog-1</a></li>\n<li><a href=\"https://recursion-prompts.netlify.app\">https://recursion-prompts</a></li>\n<li><a href=\"https://resourcerepo2\">https://resourcerepo2</a></li>\n<li><a href=\"https://romantic-hamilton-514b79.netlify.app\">https://romantic-hamilton-514b79</a></li>\n<li><a href=\"https://sad-ramanujan-235384\">https://sad-ramanujan-235384</a></li>\n<li><a href=\"https://sanity-catalyst-studio-njajg3jt.netlify.app\">https://sanity-catalyst-studio-njajg3jt</a></li>\n<li><a href=\"https://sanity-catalyst-web-1zjgvx2t\">https://sanity-catalyst-web-1zjgvx2t</a></li>\n<li><a href=\"https://sanity-commercelayer-1-studio-rkmntw55.netlify.app\">https://sanity-commercelayer-1-studio-rkmntw55</a></li>\n<li><a href=\"https://sanity-commercelayer-1-web\">https://sanity-commercelayer-1-web</a></li>\n<li><a href=\"https://sanity-commercelayer-studio-nzbh7yx7\">https://sanity-commercelayer-studio-nzbh7yx7</a></li>\n<li><a href=\"https://sanity-commercelayer-web-56265s29.netlify.app\">https://sanity-commercelayer-web-56265s29</a></li>\n<li><a href=\"https://sanity-gatsby-blog-3-studio-ch48ysi1.netlify.app\">https://sanity-gatsby-blog-3-studio-ch48ysi1</a></li>\n<li><a href=\"https://sanity-gatsby-blog-3-web-dnkdb4p7.netlify.app\">https://sanity-gatsby-blog-3-web-dnkdb4p7</a></li>\n<li><a href=\"https://sanity-gatsby-blog-4-studio-p6qrh84r.netlify.app\">https://sanity-gatsby-blog-4-studio-p6qrh84r</a></li>\n<li><a href=\"https://sanity-gatsby-blog-4-web-mobyn8k4.netlify.app\">https://sanity-gatsby-blog-4-web-mobyn8k4</a></li>\n<li><a href=\"https://sanity-gatsby-blog-studio-m195df5o.netlify.app\">https://sanity-gatsby-blog-studio-m195df5o</a></li>\n<li><a href=\"https://sanity-gatsby-blog-web-skwx3b17.netlify.app\">https://sanity-gatsby-blog-web-skwx3b17</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-2-studio-1dm9vw5o\">https://sanity-gatsby-hey-sugar-2-studio-1dm9vw5o</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-2-web.netlify.app\">https://sanity-gatsby-hey-sugar-2-web</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-5-studio.netlify.app\">https://sanity-gatsby-hey-sugar-5-studio</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-5.netlify.app\">https://sanity-gatsby-hey-sugar-5</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-studio-rkg94h5e.netlify.app\">https://sanity-gatsby-hey-sugar-studio-rkg94h5e</a></li>\n<li><a href=\"https://sanity-gatsby-hey-sugar-web-666eqtdv\">https://sanity-gatsby-hey-sugar-web-666eqtdv</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-3-studio-bit6zuzq.netlify.app\">https://sanity-gatsby-portfolio-3-studio-bit6zuzq</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-3-web-4dmiq19t\">https://sanity-gatsby-portfolio-3-web-4dmiq19t</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-studio-89chyji1.netlify.app\">https://sanity-gatsby-portfolio-studio-89chyji1</a></li>\n<li><a href=\"https://sanity-gatsby-portfolio-web-1wwhtk8k.netlify.app\">https://sanity-gatsby-portfolio-web-1wwhtk8k</a></li>\n<li><a href=\"https://sanity-jigsaw-blog-studio-mgk1nds9.netlify.app\">https://sanity-jigsaw-blog-studio-mgk1nds9</a></li>\n<li><a href=\"https://sanity-jigsaw-blog-web-cy6y69s7\">https://sanity-jigsaw-blog-web-cy6y69s7</a></li>\n<li><a href=\"https://sanity-kitchen-sink-2-studio-71rv9mea.netlify.app\">https://sanity-kitchen-sink-2-studio-71rv9mea</a></li>\n<li><a href=\"https://sanity-kitchen-sink-2-web-p1dc8gro\">https://sanity-kitchen-sink-2-web-p1dc8gro</a></li>\n<li><a href=\"https://sanity-kitchen-sink-3-studio-qpaz93e3.netlify.app\">https://sanity-kitchen-sink-3-studio-qpaz93e3</a></li>\n<li><a href=\"https://sanity-kitchen-sink-3-web-v2fb8vmv\">https://sanity-kitchen-sink-3-web-v2fb8vmv</a></li>\n<li><a href=\"https://sanity-kitchen-sink-5-studio-9hogian6\">https://sanity-kitchen-sink-5-studio-9hogian6</a></li>\n<li><a href=\"https://sanity-kitchen-sink-5-web.netlify.app\">https://sanity-kitchen-sink-5-web</a></li>\n<li><a href=\"https://sanity-kitchen-sink-studio-us5ymc5z.netlify.app\">https://sanity-kitchen-sink-studio-us5ymc5z</a></li>\n<li><a href=\"https://sanity-kitchen-sink-web-geaa75ie.netlify.app\">https://sanity-kitchen-sink-web-geaa75ie</a></li>\n<li><a href=\"https://sanity-nuxt-events-studio-zd46wiji.netlify.app\">https://sanity-nuxt-events-studio-zd46wiji</a></li>\n<li><a href=\"https://sanity-nuxt-events-web-i78cd7mw.netlify.app\">https://sanity-nuxt-events-web-i78cd7mw</a></li>\n<li><a href=\"https://sanity-signup.netlify.app\">https://sanity-signup</a></li>\n<li><a href=\"https://sanity-translation-examples-studio-u93wc5ox.netlify.app\">https://sanity-translation-examples-studio-u93wc5ox</a></li>\n<li><a href=\"https://scopeclosurecontext.netlify.app\">https://scopeclosurecontext</a></li>\n<li><a href=\"https://side-bar-blog-4.netlify.app\">https://side-bar-blog-4</a></li>\n<li><a href=\"https://sidebar-blog.netlify.app\">https://sidebar-blog</a></li>\n<li><a href=\"https://silly-lichterman-b22b5f\">https://silly-lichterman-b22b5f</a></li>\n<li><a href=\"https://site-analysis.netlify.app\">https://site-analysis</a></li>\n<li><a href=\"https://splendid-onion-b0ec3.netlify.app\">https://splendid-onion-b0ec3</a></li>\n<li><a href=\"https://starter-520d2.netlify.app\">https://starter-520d2</a></li>\n<li><a href=\"https://stupefied-wilson-2bc726.netlify.app\">https://stupefied-wilson-2bc726</a></li>\n<li><a href=\"https://synth-music-theory.netlify.app\">https://synth-music-theory</a></li>\n<li><a href=\"https://ternary42.netlify.app\">https://ternary42</a></li>\n<li><a href=\"https://tetris42.netlify.app\">https://tetris42</a></li>\n<li><a href=\"https://thealgorithms\">https://thealgorithms</a></li>\n<li><a href=\"https://trusting-aryabhata-e5438d.netlify.app\">https://trusting-aryabhata-e5438d</a></li>\n<li><a href=\"https://unruffled-bhabha-2ea500.netlify.app\">https://unruffled-bhabha-2ea500</a></li>\n<li><a href=\"https://upbeat-mayer-92c10b.netlify.app\">https://upbeat-mayer-92c10b</a></li>\n<li><a href=\"https://vibrant-noether-dbe366.netlify.app\">https://vibrant-noether-dbe366</a></li>\n<li><a href=\"https://web-dev-interview-prep-quiz-website.netlify.app\">https://web-dev-interview-prep-quiz-website</a></li>\n<li><a href=\"https://web-dev-resource-hub.netlify.app\">https://web-dev-resource-hub</a></li>\n<li><a href=\"https://wizardly-hermann-c9ade8.netlify.app\">https://wizardly-hermann-c9ade8</a></li>\n<li><a href=\"https://wonderful-pasteur-392fbe.netlify.app\">https://wonderful-pasteur-392fbe</a></li>\n<li><a href=\"https://zen-bhabha-bd046f.netlify.app\">https://zen-bhabha-bd046f</a></li>\n</ul>"},{"url":"/docs/python/flow-control/","relativePath":"docs/python/flow-control.md","relativeDir":"docs/python","base":"flow-control.md","name":"flow-control","frontmatter":{"title":"Flow Control","weight":0,"excerpt":"These operators evaluate to True or False depending on the values you give them.","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Flow Control:</h2>\n<h2>Read It</h2>\n<ul>\n<li><a href=\"https://www.pythoncheatsheet.org\">Website</a></li>\n<li><a href=\"https://github.com/wilfredinni/python-cheatsheet\">Github</a></li>\n<li><a href=\"https://github.com/wilfredinni/Python-cheatsheet/raw/master/python_cheat_sheet.pdf\">PDF</a></li>\n<li><a href=\"https://mybinder.org/v2/gh/wilfredinni/python-cheatsheet/master?filepath=jupyter_notebooks\">Jupyter Notebook</a></li>\n</ul>\n<h2>Flow Control</h2>\n<h3>Comparison Operators</h3>\n<table>\n<thead>\n<tr>\n<th>Operator</th>\n<th>Meaning</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">==</code></td>\n<td>Equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">!=</code></td>\n<td>Not equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">&lt;</code></td>\n<td>Less than</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">></code></td>\n<td>Greater Than</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">&lt;=</code></td>\n<td>Less than or Equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">>=</code></td>\n<td>Greater than or Equal to</td>\n</tr>\n</tbody>\n</table>\n<p>These operators evaluate to True or False depending on the values you give them.</p>\n<p>Examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token number\">42</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">40</span> <span class=\"token operator\">==</span> <span class=\"token number\">42</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'hello'</span> <span class=\"token operator\">==</span> <span class=\"token string\">'hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'hello'</span> <span class=\"token operator\">==</span> <span class=\"token string\">'Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'dog'</span> <span class=\"token operator\">!=</span> <span class=\"token string\">'cat'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token number\">42.0</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token string\">'42'</span></code></pre></div>\n<h3>Boolean evaluation</h3>\n<p>Never use <code class=\"language-text\">==</code> or <code class=\"language-text\">!=</code> operator to evaluate boolean operation. Use the <code class=\"language-text\">is</code> or <code class=\"language-text\">is not</code> operators,\nor use implicit boolean evaluation.</p>\n<p>NO (even if they are valid Python):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token operator\">!=</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>YES (even if they are valid Python):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>These statements are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span></code></pre></div>\n<p>And these as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> a<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span></code></pre></div>\n<h3>Boolean Operators</h3>\n<p>There are three Boolean operators: and, or, and not.</p>\n<p>The <em>and</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>True and True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>True and False</td>\n<td>False</td>\n</tr>\n<tr>\n<td>False and True</td>\n<td>False</td>\n</tr>\n<tr>\n<td>False and False</td>\n<td>False</td>\n</tr>\n</tbody>\n</table>\n<p>The <em>or</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>True or True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>True or False</td>\n<td>True</td>\n</tr>\n<tr>\n<td>False or True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>False or False</td>\n<td>False</td>\n</tr>\n</tbody>\n</table>\n<p>The <em>not</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>not True</td>\n<td>False</td>\n</tr>\n<tr>\n<td>not False</td>\n<td>True</td>\n</tr>\n</tbody>\n</table>\n<h3>Mixing Boolean and Comparison Operators</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token number\">9</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">or</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can also use multiple Boolean operators in an expression, along with the comparison operators:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">4</span> <span class=\"token keyword\">and</span> <span class=\"token keyword\">not</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">5</span> <span class=\"token keyword\">and</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span></code></pre></div>\n<h3>if Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>else Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, stranger.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>elif Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are not Alice, kiddo.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are not Alice, kiddo.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are neither Alice nor a little kid.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>while Loop Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n<span class=\"token keyword\">while</span> spam <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, world.'</span><span class=\"token punctuation\">)</span>\n    spam <span class=\"token operator\">=</span> spam <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<h3>break Statements</h3>\n<p>If the execution reaches a break statement, it immediately exits the while loop's clause:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Please type your name.'</span><span class=\"token punctuation\">)</span>\n    name <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'your name'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">break</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Thank you!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>continue Statements</h3>\n<p>When the program execution reaches a continue statement, the program execution immediately jumps back to the start of the loop.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Who are you?'</span><span class=\"token punctuation\">)</span>\n    name <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> name <span class=\"token operator\">!=</span> <span class=\"token string\">'Joe'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">continue</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, Joe. What is the password? (It is a fish.)'</span><span class=\"token punctuation\">)</span>\n    password <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> password <span class=\"token operator\">==</span> <span class=\"token string\">'swordfish'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">break</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Access granted.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>for Loops and the range() Function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'My name is'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Jimmy Five Times ({})'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <em>range()</em> function can also be called with three arguments. The first two arguments will be the start and stop values, and the third will be the step argument. The step is the amount that the variable is increased by after each iteration.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can even use a negative number for the step argument to make the for loop count down instead of up.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>For else statement</h3>\n<p>This allows you to specify a statement to execute after the full loop has been executed. Only\nuseful when a <code class=\"language-text\">break</code> condition can occur in the loop:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">if</span> i <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n       <span class=\"token keyword\">break</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"only executed when no item of the list is equal to 3\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Importing Modules</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random<span class=\"token punctuation\">,</span> sys<span class=\"token punctuation\">,</span> os<span class=\"token punctuation\">,</span> math</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> random <span class=\"token keyword\">import</span> <span class=\"token operator\">*</span></code></pre></div>\n<h3>Ending a Program with sys.exit</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> sys\n\n<span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Type exit to exit.'</span><span class=\"token punctuation\">)</span>\n    response <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> response <span class=\"token operator\">==</span> <span class=\"token string\">'exit'</span><span class=\"token punctuation\">:</span>\n        sys<span class=\"token punctuation\">.</span>exit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You typed {}.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>"},{"url":"/docs/python/examples/","relativePath":"docs/python/examples.md","relativeDir":"docs/python","base":"examples.md","name":"examples","frontmatter":{"title":"Python Practice","weight":0,"excerpt":"Example Problems","seo":{"title":"Python Examples","description":"Python Problems & Solutions For Beginners","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Python Practice:</h2>\n<h1>Python Problems &#x26; Solutions For Beginners</h1>\n<p>Introduction to python taught through example problems. Solutions are included in embedded repl.it at the bottom of this page for you to…</p>\n<hr>\n<h3>Python Problems &#x26; Solutions For Beginners</h3>\n<h4>Introduction to python taught through example problems. Solutions are included in embedded repl.it at the bottom of this page for you to practice and refactor.</h4>\n<h3>Python Practice Problems</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*dMdMGwOJKHJ-5sOP.gif\" class=\"graf-image\" />\n</figure>\n<hr>\n<h4>Here are some other articles for reference if you need them:</h4>\n<a href=\"https://medium.com/geekculture/beginners-guide-to-python-e5a59b5bb64d\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://medium.com/geekculture/beginners-guide-to-python-e5a59b5bb64d\">\n<strong>Beginners Guide To Python</strong>\n<br />\n<em>My favorite language for maintainability is Python. It has simple, clean syntax, object encapsulation, good library…</em>medium.com</a>\n<a href=\"https://medium.com/geekculture/beginners-guide-to-python-e5a59b5bb64d\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<a href=\"https://levelup.gitconnected.com/python-study-guide-for-a-native-javascript-developer-5cfdf3d2bdfb\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://levelup.gitconnected.com/python-study-guide-for-a-native-javascript-developer-5cfdf3d2bdfb\">\n<strong>Python Study Guide for a JavaScript Programmer</strong>\n<br />\n<em>A guide to commands in Python from what you know in JavaScript</em>levelup.gitconnected.com</a>\n<a href=\"https://levelup.gitconnected.com/python-study-guide-for-a-native-javascript-developer-5cfdf3d2bdfb\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<hr>\n<h3>Here are the problems without solutions for you to practice with:</h3>\n<hr>\n<h3>Problem 1</h3>\n<p>Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn <code class=\"language-text\">100</code> years old.</p>\n<p>The <code class=\"language-text\">datetime</code> module supplies classes for manipulating dates and times.</p>\n<p>While date and time arithmetic is supported, the focus of the implementation is on efficient attribute extraction for output formatting and manipulation.</p>\n<a href=\"https://docs.python.org/3/library/datetime.html\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://docs.python.org/3/library/datetime.html\">\n<strong>datetime - Basic date and time types - Python 3.9.6 documentation</strong>\n<br />\n<em>Only one concrete class, the class, is supplied by the module. The class can represent simple timezones with fixed…</em>docs.python.org</a>\n<a href=\"https://docs.python.org/3/library/datetime.html\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<h3>Problem 2</h3>\n<p>Ask the user for a number. Depending on whether the number is <code class=\"language-text\">even</code> or <code class=\"language-text\">odd</code>, print out an appropriate message to the user.</p>\n<h4>Bonus:</h4>\n<ol>\n<li><span id=\"eebc\">If the number is a multiple of <code class=\"language-text\">4</code>, print out a different message.</span></li>\n<li><span id=\"306e\">Ask the user for two numbers: one number to check (call it num) and one number to divide by (check). If check divides evenly into num, tell that to the user. If not, print a different appropriate message.</span></li>\n</ol>\n<h3>Problem 3</h3>\n<p>Take a list and write a program that prints out all the elements of the list that are <code class=\"language-text\">less</code> than <code class=\"language-text\">5</code>.</p>\n<p>Extras:</p>\n<ol>\n<li><span id=\"fe03\">Instead of printing the elements one by one, make a new list that has all the elements less than <code class=\"language-text\">5</code> from this list in it and print out this new list.</span></li>\n<li><span id=\"186b\">Write this in one line of Python.</span></li>\n<li><span id=\"9cd1\">Ask the user for a number and return a list that contains only elements from the original list a that are smaller than that number given by the user.</span></li>\n</ol>\n<h3>Problem 4</h3>\n<p>Create a program that asks the user for a number and then prints out a list of all the divisors of that number. (If you don't know what a divisor is, it is a number that divides evenly into another number.</p>\n<p>For example, <code class=\"language-text\">13</code> is a divisor of <code class=\"language-text\">26</code> because <code class=\"language-text\">26 / 13</code> has no remainder.)</p>\n<h3>Problem 5</h3>\n<p>Take two lists, and write a program that returns a list that contains only the elements that are <code class=\"language-text\">common between the lists (without duplicates)</code>. Make sure your program works on two lists of different sizes.</p>\n<a href=\"https://docs.python.org/3/library/random.html\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://docs.python.org/3/library/random.html\">\n<strong>random - Generate pseudo-random numbers - Python 3.9.6 documentation</strong>\n<br />\n<em>Source code: Lib/random.py This module implements pseudo-random number generators for various distributions. For…</em>docs.python.org</a>\n<a href=\"https://docs.python.org/3/library/random.html\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<p>Bonus:</p>\n<ol>\n<li><span id=\"e18a\">Randomly generate two lists to test this.</span></li>\n<li><span id=\"148a\">Write this in one line of Python.</span></li>\n</ol>\n<h3>Problem 6</h3>\n<p>Ask the user for a string and print out whether this string is a <code class=\"language-text\">palindrome</code> or not. (A palindrome is a string that reads the same forwards and backwards.)</p>\n<blockquote>\n<p>Here's 5 ways to reverse a string (courtesy of <a href=\"https://www.geeksforgeeks.org/reverse-string-python-5-different-ways/\" class=\"markup--anchor markup--pullquote-anchor\">geeksforgeeks</a>)</p>\n</blockquote>\n<hr>\n<h3>Problem 7</h3>\n<p>Let's say I give you a list saved in a variable: a = <code class=\"language-text\">[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]</code>.</p>\n<p>Write one line of Python that takes this list a and makes a new list that has only the <code class=\"language-text\">even</code> elements of this list in it.</p>\n<h3>Problem 8</h3>\n<p>Make a two-player <code class=\"language-text\">Rock-Paper-Scissors</code> game.</p>\n<p><strong>Hint:</strong><br>\nAsk for player plays (using input), compare them. Print out a message of congratulations to the winner, and ask if the players want to start a new game.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*1_4w6u4D7EDi2r4h.png\" class=\"graf-image\" />\n</figure>### Problem 9\n<p>Generate a random number between <code class=\"language-text\">1 and 100 (including 1 and 100)</code>. Ask the user to guess the number, then tell them whether they guessed <code class=\"language-text\">too low</code>, <code class=\"language-text\">too high</code>, or <code class=\"language-text\">exactly right</code>.</p>\n<blockquote>\n<p><strong>Hint:</strong><br>\nRemember to use the user input from the very first exercise.</p>\n</blockquote>\n<p><strong>Extras:</strong><br>\nKeep the game going until the user types <code class=\"language-text\">\"exit\"</code>.<br>\nKeep track of how many guesses the user has taken, and when the game ends, print this out.</p>\n<h3>Problem 10</h3>\n<p>Write a program that asks the user how many Fibonacci numbers to generate and then generates them. Take this opportunity to think about how you can use functions. Make sure to ask the user to enter the number of numbers in the sequence to generate.</p>\n<p><strong>Hint:</strong><br>\nThe Fibonacci sequence is a sequence of numbers where the next number in the sequence is the sum of the previous two numbers in the sequence. The sequence looks like this: <code class=\"language-text\">1, 1, 2, 3, 5, 8, 13, …</code></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*2xJsVLGikF6dg7qc.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Intermediate Problems:</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*hTU58jGsgkrszi76.gif\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Problem 11</h3>\n<p>In linear algebra, <em>a Toeplitz matrix is one in which the elements on any given diagonal from top left to bottom right are identical.</em><br>\nHere is an example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1 2 3 4 8\n5 1 2 3 4\n4 5 1 2 3\n7 4 5 1 2</code></pre></div>\n<p>Write a program to determine whether a given input is a <code class=\"language-text\">Toeplitz</code> matrix.</p>\n<h3>Problem 12</h3>\n<p>Given a positive integer <code class=\"language-text\">N</code>, find the smallest number of steps it will take to reach <code class=\"language-text\">1</code>.</p>\n<p>There are two kinds of permitted steps:<br>\n— -> You may decrement N to N — 1.<br>\n— -> If <code class=\"language-text\">a * b = N</code>, you may decrement <code class=\"language-text\">N to the larger of a and b</code>.</p>\n<p>For example, given 100, you can reach 1 in 5 steps with the following route:<br>\n<code class=\"language-text\">100 -> 10 -> 9 -> 3 -> 2 -> 1.</code></p>\n<h3>Problem 13</h3>\n<p>Consider the following scenario: there are <code class=\"language-text\">N</code> mice and <code class=\"language-text\">N</code> holes placed at integer points along a line. Given this, find a method that maps mice to holes such that the largest number of steps any mouse takes is minimized.</p>\n<p>Each move consists of moving one mouse <code class=\"language-text\">one</code> unit to the <code class=\"language-text\">left</code> or <code class=\"language-text\">right</code>, and only <code class=\"language-text\">one</code> mouse can fit inside each hole.</p>\n<p>For example, suppose the mice are positioned at <code class=\"language-text\">[1, 4, 9, 15]</code>, and the holes are located at <code class=\"language-text\">[10, -5, 0, 16]</code>. In this case, the best pairing would require us to send the mouse at <code class=\"language-text\">1</code> to the hole at <code class=\"language-text\">-5</code>, so our function should return <code class=\"language-text\">6</code>.</p>\n<h3>My Blog:</h3>\n<a href=\"https://master--bgoonz-blog.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://master--bgoonz-blog.netlify.app/\">\n<strong>Web-Dev-Hub</strong>\n<br />\n<em>Memoization, Tabulation, and Sorting Algorithms by Example Why is looking at runtime not a reliable method of…</em>master--bgoonz-blog.netlify.app</a>\n<a href=\"https://master--bgoonz-blog.netlify.app/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\">\n<strong>A list of all of my articles to link to future posts</strong>\n<br />\n<em>You should probably skip this one… seriously it's just for internal use!</em>bryanguner.medium.com</a>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<hr>\n<h1>Python</h1>\n<ul>\n<li>Python is an interpreted, high-level and general-purpose, dynamically typed programming language</li>\n<li>-</li>\n<li>It is also Object oriented, modular oriented and a</li>\n<li>-</li>\n<li>In Python, everything is considered as an Object.</li>\n<li>-</li>\n<li>A python file has an extension of .py</li>\n<li>Python follows Indentation to separate code blocks instead of flower brackets({}).</li>\n<li>\n<p>We can run a python file by the following command in cmd(Windows) or shell(mac/linux).</p>\n<p><code class=\"language-text\">python &lt;filename.py></code></p>\n</li>\n</ul>\n<h4>By default, the python doesn't require any imports to run a python file.</h4>\n<h2>Create and execute a program</h2>\n<ol>\n<li>Open up a terminal/cmd</li>\n<li>Create the program: nano/cat > nameProgram.py</li>\n<li>Write the program and save it</li>\n<li>python nameProgram.py</li>\n</ol>\n<br>\n<h3>Basic Datatypes</h3>\n<table>\n<thead>\n<tr>\n<th>Data Type</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>int</td>\n<td>Integer values [0, 1, -2, 3]</td>\n</tr>\n<tr>\n<td>float</td>\n<td>Floating point values [0.1, 4.532, -5.092]</td>\n</tr>\n<tr>\n<td>char</td>\n<td>Characters [a, b, @, !, `]</td>\n</tr>\n<tr>\n<td>str</td>\n<td>Strings [abc, AbC, A@B, sd!, `asa]</td>\n</tr>\n<tr>\n<td>bool</td>\n<td>Boolean Values [True, False]</td>\n</tr>\n<tr>\n<td>char</td>\n<td>Characters [a, b, @, !, `]</td>\n</tr>\n<tr>\n<td>complex</td>\n<td>Complex numbers [2+3j, 4-1j]</td>\n</tr>\n</tbody>\n</table>\n<br>\n<h2>Keywords</h2>\n<br>\n<table>\n<thead>\n<tr>\n<th>Keyword</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>break</td>\n<td>used to exit loop and used to exit</td>\n</tr>\n<tr>\n<td>char</td>\n<td>basic declaration of a type character</td>\n</tr>\n<tr>\n<td>const</td>\n<td>prefix declaration meaning variable can not be changed</td>\n</tr>\n<tr>\n<td>continue</td>\n<td>go to bottom of loop in for, while loops</td>\n</tr>\n<tr>\n<td>class</td>\n<td>to define a class</td>\n</tr>\n<tr>\n<td>def</td>\n<td>to define a function</td>\n</tr>\n<tr>\n<td>elif</td>\n<td>shortcut for (else if) used in else if ladder</td>\n</tr>\n<tr>\n<td>else</td>\n<td>executable statement, part of \"if\" structure</td>\n</tr>\n<tr>\n<td>float</td>\n<td>basic declaration of floating point</td>\n</tr>\n<tr>\n<td>for</td>\n<td>executable statement, for loop</td>\n</tr>\n<tr>\n<td>from</td>\n<td>executable statement, used to import only specific objects from a package</td>\n</tr>\n<tr>\n<td>if</td>\n<td>executable statement</td>\n</tr>\n<tr>\n<td>import</td>\n<td>to import modules</td>\n</tr>\n<tr>\n<td>pass</td>\n<td>keyword to specify noting is happening in the codeblock, generally used in classes</td>\n</tr>\n<tr>\n<td>return</td>\n<td>executable statement with or without a value</td>\n</tr>\n<tr>\n<td>while</td>\n<td>executable statement, while loop</td>\n</tr>\n</tbody>\n</table>\n<br>\n<h2>Operators</h2>\n<br>\n<table>\n<thead>\n<tr>\n<th>Operator</th>\n<th>Description</th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>( )</td>\n<td>grouping parenthesis, function call, tuple declaration</td>\n<td></td>\n</tr>\n<tr>\n<td>[ ]</td>\n<td>array indexing, also declaring lists etc.</td>\n<td></td>\n</tr>\n<tr>\n<td>!</td>\n<td>relational not, complement, ! a yields true or false</td>\n<td></td>\n</tr>\n<tr>\n<td>~</td>\n<td>bitwise not, ones complement, ~a</td>\n<td></td>\n</tr>\n<tr>\n<td>-</td>\n<td>unary minus, - a</td>\n<td></td>\n</tr>\n<tr>\n<td>+</td>\n<td>unary plus, + a</td>\n<td></td>\n</tr>\n<tr>\n<td>*</td>\n<td>multiply, a * b</td>\n<td></td>\n</tr>\n<tr>\n<td>/</td>\n<td>divide, a / b</td>\n<td></td>\n</tr>\n<tr>\n<td>%</td>\n<td>modulo, a % b</td>\n<td></td>\n</tr>\n<tr>\n<td>+</td>\n<td>add, a + b</td>\n<td></td>\n</tr>\n<tr>\n<td>-</td>\n<td>subtract, a - b</td>\n<td></td>\n</tr>\n<tr>\n<td>&#x3C;&#x3C;</td>\n<td>shift left, left operand is shifted left by right operand bits</td>\n<td></td>\n</tr>\n<tr>\n<td>>></td>\n<td>shift right, left operand is shifted right by right operand bits</td>\n<td></td>\n</tr>\n<tr>\n<td>&#x3C;</td>\n<td>less than, result is true or false, a %lt; b</td>\n<td></td>\n</tr>\n<tr>\n<td>&#x3C;=</td>\n<td>less than or equal, result is true or false, a &#x3C;= b</td>\n<td></td>\n</tr>\n<tr>\n<td>></td>\n<td>greater than, result is true or false, a > b</td>\n<td></td>\n</tr>\n<tr>\n<td>>=</td>\n<td>greater than or equal, result is true or false, a >= b</td>\n<td></td>\n</tr>\n<tr>\n<td>==</td>\n<td>equal, result is true or false, a == b</td>\n<td></td>\n</tr>\n<tr>\n<td>!=</td>\n<td>not equal, result is true or false, a != b</td>\n<td></td>\n</tr>\n<tr>\n<td>&#x26;</td>\n<td>bitwise and, a &#x26; b</td>\n<td></td>\n</tr>\n<tr>\n<td>^</td>\n<td>bitwise exclusive or XOR, a ^ b</td>\n<td></td>\n</tr>\n<tr>\n<td>|</td>\n<td>bitwise or, a</td>\n<td>b</td>\n</tr>\n<tr>\n<td>&#x26;&#x26;, and</td>\n<td>relational and, result is true or false, a &#x3C; b &#x26;&#x26; c >= d</td>\n<td></td>\n</tr>\n<tr>\n<td>||, or</td>\n<td>relational or, result is true or false, a &#x3C; b || c >= d</td>\n<td></td>\n</tr>\n<tr>\n<td>=</td>\n<td>store or assignment</td>\n<td></td>\n</tr>\n<tr>\n<td>+=</td>\n<td>add and store</td>\n<td></td>\n</tr>\n<tr>\n<td>-=</td>\n<td>subtract and store</td>\n<td></td>\n</tr>\n<tr>\n<td>*=</td>\n<td>multiply and store</td>\n<td></td>\n</tr>\n<tr>\n<td>/=</td>\n<td>divide and store</td>\n<td></td>\n</tr>\n<tr>\n<td>%=</td>\n<td>modulo and store</td>\n<td></td>\n</tr>\n<tr>\n<td>&#x3C;&#x3C;=</td>\n<td>shift left and store</td>\n<td></td>\n</tr>\n<tr>\n<td>>>=</td>\n<td>shift right and store</td>\n<td></td>\n</tr>\n<tr>\n<td>&#x26;=</td>\n<td>bitwise and and store</td>\n<td></td>\n</tr>\n<tr>\n<td>^=</td>\n<td>bitwise exclusive or and store</td>\n<td></td>\n</tr>\n<tr>\n<td>|=</td>\n<td>bitwise or and store</td>\n<td></td>\n</tr>\n<tr>\n<td>,</td>\n<td>separator as in ( y=x,z=++x )</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h3>Basic Data Structures</h3>\n<h3>List</h3>\n<ul>\n<li>List is a collection which is ordered and changeable. Allows duplicate members.</li>\n<li>-</li>\n<li>Lists are created using square brackets:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thislist <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>List items are ordered, changeable, and allow duplicate values.</li>\n<li>-</li>\n<li>List items are indexed, the first item has index <code class=\"language-text\">[0]</code>, the second item has index <code class=\"language-text\">[1]</code> etc.</li>\n<li>-</li>\n<li>The list is changeable, meaning that we can change, add, and remove items in a list after it has been created.</li>\n<li>To determine how many items a list has, use the <code class=\"language-text\">len()</code> function.</li>\n<li>A list can contain different data types:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">list1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">34</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token number\">40</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"male\"</span><span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>It is also possible to use the list() constructor when creating a new list</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thislist <span class=\"token operator\">=</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># note the double round-brackets</span></code></pre></div>\n<h3>Tuple</h3>\n<ul>\n<li>Tuple is a collection which is ordered and unchangeable. Allows duplicate members.</li>\n<li>A tuple is a collection which is ordered and unchangeable.</li>\n<li>Tuples are written with round brackets.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thistuple <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>Tuple items are ordered, unchangeable, and allow duplicate values.</li>\n<li>Tuple items are indexed, the first item has index <code class=\"language-text\">[0]</code>, the second item has index <code class=\"language-text\">[1]</code> etc.</li>\n<li>When we say that tuples are ordered, it means that the items have a defined order, and that order will not change.</li>\n<li>-</li>\n<li>Tuples are unchangeable, meaning that we cannot change, add or remo</li>\n<li>Since tuple are indexed, tuples can have items with the same value:</li>\n<li>Tuples allow duplicate values:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thistuple <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>To determine how many items a tuple has, use the <code class=\"language-text\">len()</code>function:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thistuple <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>thistuple<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>To create a tuple with only one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thistuple <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>thistuple<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">#NOT a tuple</span>\nthistuple <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>thistuple<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>It is also possible to use the tuple() constructor to make a tuple.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thistuple <span class=\"token operator\">=</span> <span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># note the double round-brackets</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>thistuple<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Set</h3>\n<ul>\n<li>Set is a collection which is unordered and unindexed. No duplicate members.</li>\n<li>A set is a collection which is both unordered and unindexed.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thisset <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Set items are unordered, unchangeable, and do not allow duplicate values.</li>\n<li>Unordered means that the items in a set do not have a defined order.</li>\n<li>-</li>\n<li>Set items can appear in a different order every time you use them, and cannot be referred to b</li>\n<li>-</li>\n<li>Sets are unchangeable, meaning that we cannot change the items after the set has been created.</li>\n<li>Duplicate values will be ignored.</li>\n<li>To determine how many items a set has, use the <code class=\"language-text\">len()</code> method.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thisset <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>thisset<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>Set items can be of any data type:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">set1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">}</span>\nset2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\nset3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">}</span>\nset4 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">34</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token number\">40</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"male\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>It is also possible to use the <code class=\"language-text\">set()</code> constructor to make a set.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thisset <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># note the double round-brackets</span></code></pre></div>\n<h3>Dictionary</h3>\n<ul>\n<li>Dictionary is a collection which is unordered and changeable. No duplicate members.</li>\n<li>Dictionaries are used to store data values in key:value pairs.</li>\n<li>Dictionaries are written with curly brackets, and have keys and values:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thisdict <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">\"brand\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Ford\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"model\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Mustang\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"year\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1964</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Dictionary items are presented in key:value pairs, and can be referred to by using the key name.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thisdict <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">\"brand\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Ford\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"model\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Mustang\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"year\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1964</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>thisdict<span class=\"token punctuation\">[</span><span class=\"token string\">\"brand\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>Dictionaries are changeable, meaning that we can change, add or remove items after the dictionary has been created.</li>\n<li>Dictionaries cannot have two items with the same key.</li>\n<li>Duplicate values will overwrite existing values.</li>\n<li>To determine how many items a dictionary has, use the <code class=\"language-text\">len()</code> function.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>thisdict<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>The values in dictionary items can be of any data type</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">thisdict <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">\"brand\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Ford\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"electric\"</span><span class=\"token punctuation\">:</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"year\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1964</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"colors\"</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"white\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"blue\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Conditional branching</h3>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">    <span class=\"token keyword\">if</span> condition<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">pass</span>\n    <span class=\"token keyword\">elif</span> condition2<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">pass</span>\n    <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">pass</span></code></pre></div>\n<h3>Loops</h3>\n<p>Python has two primitive loop commands:</p>\n<ol>\n<li>while loops</li>\n<li>for loops</li>\n</ol>\n<h4>While loop</h4>\n<ul>\n<li>With the <code class=\"language-text\">while</code> loop we can execute a set of statements as long as a condition is true.</li>\n<li>Example: Print i as long as i is less than 6</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">while</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n  i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span></code></pre></div>\n<ul>\n<li>The while loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1.</li>\n<li>With the <code class=\"language-text\">break</code> statement we can stop the loop even if the while condition is true</li>\n<li>With the continue statement we can stop the current iteration, and continue with the next.</li>\n<li>-</li>\n<li>With the else statement we can run a block of code once when the condition no longer is true.</li>\n</ul>\n<h4>For loop</h4>\n<ul>\n<li>A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).</li>\n<li>-</li>\n<li>This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages.</li>\n<li>With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">fruits <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> fruits<span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>The for loop does not require an indexing variable to set beforehand.</li>\n<li>To loop through a set of code a specified number of times, we can use the range() function.</li>\n<li>The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.</li>\n<li>The range() function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: range(2, 30, 3).</li>\n<li>The else keyword in a for loop specifies a block of code to be executed when the loop is finished.\nA nested loop is a loop inside a loop.</li>\n<li>The \"inner loop\" will be executed one time for each iteration of the \"outer loop\":</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">adj <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"big\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tasty\"</span><span class=\"token punctuation\">]</span>\nfruits <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"banana\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cherry\"</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> adj<span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">for</span> y <span class=\"token keyword\">in</span> fruits<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>for loops cannot be empty, but if you for some reason have a for loop with no content, put in the pass statement to avoid getting an error.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">pass</span></code></pre></div>\n<h3>Function definition</h3>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">function_name</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span></code></pre></div>\n<h3>Function call</h3>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">function_name<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>We need not to specify the return type of the function.</li>\n<li>Functions by default return <code class=\"language-text\">None</code></li>\n<li>We can return any datatype.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">say_hi</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"&lt;---- Multi-Line Comments and Docstrings\n    This is where you put your content for help() to inform the user\n    about what your function does and how to use it\n    \"\"\"</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"Hello </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span></span><span class=\"token string\">!\"</span></span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>say_hi<span class=\"token punctuation\">(</span><span class=\"token string\">\"Bryan\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Should get the print inside the function, then None</span>\n<span class=\"token comment\"># Boolean Values</span>\n<span class=\"token comment\"># Work the same as in JS, except they are title case: True and False</span>\na <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span>\nb <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span>\n<span class=\"token comment\"># Logical Operators</span>\n<span class=\"token comment\"># ! = not, || = or, &amp;&amp; = and</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Truthiness - Everything is True except...</span>\n<span class=\"token comment\"># False - None, False, '', [], (), set(), range(0)</span>\n<span class=\"token comment\"># Number Values</span>\n<span class=\"token comment\"># Integers are numbers without a floating decimal point</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># type returns the type of whatever argument you pass in</span>\n<span class=\"token comment\"># Floating Point values are numbers with a floating decimal point</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">3.5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Type Casting</span>\n<span class=\"token comment\"># You can convert between ints and floats (along with other types...)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># If you convert a float to an int, it will truncate the decimal</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Python does not automatically convert types like JS</span>\n<span class=\"token comment\"># print(17.0 + ' heyooo ' + 17)  # TypeError</span>\n<span class=\"token comment\"># Arithmetic Operators</span>\n<span class=\"token comment\"># ** - exponent (comparable to Math.pow(num, pow))</span>\n<span class=\"token comment\"># // - integer division</span>\n<span class=\"token comment\"># There is no ++ or -- in Python</span>\n<span class=\"token comment\"># String Values</span>\n<span class=\"token comment\"># We can use single quotes, double quotes, or f'' for string formats</span>\n<span class=\"token comment\"># We can use triple single quotes for multiline strings</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"This here's a story\nAll about how\nMy life got twist\nTurned upside down\n\"\"\"</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Three double quotes can also be used, but we typically reserve these for</span>\n<span class=\"token comment\"># multi-line comments and function docstrings (refer to lines 6-9)(Nice :D)</span>\n<span class=\"token comment\"># We use len() to get the length of something</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Bryan G\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># 7 characters</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"hey\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"ho\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hey\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hey\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"ho\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># 5 list items</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># 8 set items</span>\n<span class=\"token comment\"># We can index into strings, list, etc..self.</span>\nname <span class=\"token operator\">=</span> <span class=\"token string\">\"Bryan\"</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># B, r, y, a, n</span>\n<span class=\"token comment\"># We can index starting from the end as well, with negatives</span>\noccupation <span class=\"token operator\">=</span> <span class=\"token string\">\"Full Stack Software Engineer\"</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># e</span>\n<span class=\"token comment\"># We can also get ranges in the index with the [start:stop:step] syntax</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token number\">4</span><span class=\"token punctuation\">:</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># step and stop are optional, stop is exclusive</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># beginning to end, every 4th letter</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">:</span><span class=\"token number\">14</span><span class=\"token punctuation\">:</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Let's get weird with it!</span>\n<span class=\"token comment\"># NOTE: Indexing out of range will give you an IndexError</span>\n<span class=\"token comment\"># We can also get the index og things with the .index() method, similar to indexOf()</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span><span class=\"token string\">\"Stack\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Barry\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Cole\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"James\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mark\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span><span class=\"token string\">\"Cole\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can count how many times a substring/item appears in something as well</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span><span class=\"token string\">\"S\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"Now this here's a story all about how\nMy life got twist turned upside down\nI forget the rest but the the the potato\nsmells like the potato\"\"\"</span><span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>\n        <span class=\"token string\">\"the\"</span>\n    <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We concatenate the same as Javascript, but we can also multiply strings</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"dog \"</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"show\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"ha\"</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can use format for a multitude of things, from spaces to decimal places</span>\nfirst_name <span class=\"token operator\">=</span> <span class=\"token string\">\"Bryan\"</span>\nlast_name <span class=\"token operator\">=</span> <span class=\"token string\">\"Guner\"</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Your name is {0} {1}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>first_name<span class=\"token punctuation\">,</span> last_name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Useful String Methods</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># HELLO</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># hello</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"HELLO\"</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"HELLO\"</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">\"he\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">\"lo\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello There\"</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># [Hello, There]</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hello1\"</span><span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False,  must consist only of letters</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hello1\"</span><span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True, must consist of only letters and numbers</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"3215235123\"</span><span class=\"token punctuation\">.</span>isdecimal<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True, must be all numbers</span>\n<span class=\"token comment\"># True, must consist of only spaces/tabs/newlines</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"       \\n     \"</span><span class=\"token punctuation\">.</span>isspace<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># False, index 0 must be upper case and the rest lower</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Bryan Guner\"</span><span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Michael Lee\"</span><span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True!</span>\n<span class=\"token comment\"># Duck Typing - If it walks like a duck, and talks like a duck, it must be a duck</span>\n<span class=\"token comment\"># Assignment - All like JS, but there are no special keywords like let or const</span>\na <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\nb <span class=\"token operator\">=</span> a\nc <span class=\"token operator\">=</span> <span class=\"token string\">\"heyoo\"</span>\nb <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"reassignment\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"is\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"fine\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"G!\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token comment\"># Comparison Operators - Python uses the same equality operators as JS, but no ===</span>\n<span class=\"token comment\"># &lt; - Less than</span>\n<span class=\"token comment\"># > - Greater than</span>\n<span class=\"token comment\"># &lt;= - Less than or Equal</span>\n<span class=\"token comment\"># >= - Greater than or Equal</span>\n<span class=\"token comment\"># == - Equal to</span>\n<span class=\"token comment\"># != - Not equal to</span>\n<span class=\"token comment\"># is - Refers to exact same memory location</span>\n<span class=\"token comment\"># not - !</span>\n<span class=\"token comment\"># Precedence - Negative Signs(not) are applied first(part of each number)</span>\n<span class=\"token comment\">#            - Multiplication and Division(and) happen next</span>\n<span class=\"token comment\">#            - Addition and Subtraction(or) are the last step</span>\n<span class=\"token comment\">#  NOTE: Be careful when using not along with ==</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">not</span> a <span class=\"token operator\">==</span> b<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token comment\"># print(a == not b) # Syntax Error</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">==</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">not</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># This fixes it. Answer: False</span>\n<span class=\"token comment\"># Python does short-circuit evaluation</span>\n<span class=\"token comment\"># Assignment Operators - Mostly the same as JS except Python has **= and //= (int division)</span>\n<span class=\"token comment\"># Flow Control Statements - if, while, for</span>\n<span class=\"token comment\"># Note: Python smushes 'else if' into 'elif'!</span>\n<span class=\"token keyword\">if</span> <span class=\"token number\">10</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"We don't get here\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> <span class=\"token number\">10</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Nor here...\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hey there!\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Looping over a string</span>\n<span class=\"token keyword\">for</span> c <span class=\"token keyword\">in</span> <span class=\"token string\">\"abcdefgh\"</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Looping over a range</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Looping over a list</span>\nlst <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Looping over a dictionary</span>\nspam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"color\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"age\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"items\"</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hey\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hooo!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">for</span> v <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Loop over a list of tuples and destructuring the values</span>\n<span class=\"token comment\"># Assuming spam.items returns a list of tuples each containing two items (k, v)</span>\n<span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>k<span class=\"token punctuation\">}</span></span><span class=\"token string\">: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>v<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># While loops as long as the condition is True</span>\n<span class=\"token comment\">#  - Exit loop early with break</span>\n<span class=\"token comment\">#  - Exit iteration early with continue</span>\nspam <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n<span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Sike That's the wrong Numba\"</span><span class=\"token punctuation\">)</span>\n    spam <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">if</span> spam <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">continue</span>\n    <span class=\"token keyword\">break</span>\n\n<span class=\"token comment\"># Functions - use def keyword to define a function in Python</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">printCopyright</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Copyright 2021, Bgoonz\"</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Lambdas are one liners! (Should be at least, you can use parenthesis to disobey)</span>\navg <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> num1<span class=\"token punctuation\">,</span> num2<span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>num1 <span class=\"token operator\">+</span> num2<span class=\"token punctuation\">)</span>\navg<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Calling it with keyword arguments, order does not matter</span>\navg<span class=\"token punctuation\">(</span>num2<span class=\"token operator\">=</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> num1<span class=\"token operator\">=</span><span class=\"token number\">1252</span><span class=\"token punctuation\">)</span>\nprintCopyright<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can give parameters default arguments like JS</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">greeting</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> saying<span class=\"token operator\">=</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>saying<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">)</span>\n\ngreeting<span class=\"token punctuation\">(</span><span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Hello Mike</span>\ngreeting<span class=\"token punctuation\">(</span><span class=\"token string\">\"Bryan\"</span><span class=\"token punctuation\">,</span> saying<span class=\"token operator\">=</span><span class=\"token string\">\"Hello there...\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># A common gotcha is using a mutable object for a default parameter</span>\n<span class=\"token comment\"># All invocations of the function reference the same mutable object</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">append_item</span><span class=\"token punctuation\">(</span>item_name<span class=\"token punctuation\">,</span> item_list<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>  <span class=\"token comment\"># Will it obey and give us a new list?</span>\n    item_list<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>item_name<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span> item_list\n\n<span class=\"token comment\"># Uses same item list unless otherwise stated which is counterintuitive</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>append_item<span class=\"token punctuation\">(</span><span class=\"token string\">\"notebook\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>append_item<span class=\"token punctuation\">(</span><span class=\"token string\">\"notebook\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>append_item<span class=\"token punctuation\">(</span><span class=\"token string\">\"notebook\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Errors - Unlike JS, if we pass the incorrect amount of arguments to a function,</span>\n<span class=\"token comment\">#          it will throw an error</span>\n<span class=\"token comment\"># avg(1)  # TypeError</span>\n<span class=\"token comment\"># avg(1, 2, 2) # TypeError</span>\n<span class=\"token comment\"># ----------------------------------- DAY 2 ----------------------------------------</span>\n<span class=\"token comment\"># Functions - * to get rest of position arguments as tuple</span>\n<span class=\"token comment\">#           - ** to get rest of keyword arguments as a dictionary</span>\n<span class=\"token comment\"># Variable Length positional arguments</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># args is a tuple of the rest of the arguments</span>\n    total <span class=\"token operator\">=</span> a <span class=\"token operator\">+</span> b\n    <span class=\"token keyword\">for</span> n <span class=\"token keyword\">in</span> args<span class=\"token punctuation\">:</span>\n        total <span class=\"token operator\">+=</span> n\n    <span class=\"token keyword\">return</span> total\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>add<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># args is None, returns 3</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>add<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># args is (3, 4, 5, 6), returns 21</span>\n<span class=\"token comment\"># Variable Length Keyword Arguments</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">print_names_and_countries</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># kwargs is a dictionary of the rest of the keyword arguments</span>\n    <span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> kwargs<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> k<span class=\"token punctuation\">,</span> <span class=\"token string\">\"from\"</span><span class=\"token punctuation\">,</span> v<span class=\"token punctuation\">)</span>\n\nprint_names_and_countries<span class=\"token punctuation\">(</span>\n    <span class=\"token string\">\"Hey there\"</span><span class=\"token punctuation\">,</span> Monica<span class=\"token operator\">=</span><span class=\"token string\">\"Sweden\"</span><span class=\"token punctuation\">,</span> Mike<span class=\"token operator\">=</span><span class=\"token string\">\"The United States\"</span><span class=\"token punctuation\">,</span> Mark<span class=\"token operator\">=</span><span class=\"token string\">\"China\"</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can combine all of these together</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">example2</span><span class=\"token punctuation\">(</span>arg1<span class=\"token punctuation\">,</span> arg2<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> kw_1<span class=\"token operator\">=</span><span class=\"token string\">\"cheese\"</span><span class=\"token punctuation\">,</span> kw_2<span class=\"token operator\">=</span><span class=\"token string\">\"horse\"</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span>\n\n<span class=\"token comment\"># Lists are mutable arrays</span>\nempty_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\nroomates <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"Beau\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Delynn\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token comment\"># List built-in function makes a list too</span>\nspecials <span class=\"token operator\">=</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can use 'in' to test if something is in the list, like 'includes' in JS</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token comment\"># Dictionaries - Similar to JS POJO's or Map, containing key value pairs</span>\na <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"three\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\nb <span class=\"token operator\">=</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>one<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> two<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> three<span class=\"token operator\">=</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Can use 'in' on dictionaries too (for keys)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"one\"</span> <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span> <span class=\"token keyword\">in</span> b<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token comment\"># Sets - Just like JS, unordered collection of distinct objects</span>\nbedroom <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"bed\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tv\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"computer\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"clothes\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"playstation 4\"</span><span class=\"token punctuation\">}</span>\n<span class=\"token comment\"># bedroom = set(\"bed\", \"tv\", \"computer\", \"clothes\", \"playstation 5\")</span>\nschool_bag <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">\"book\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"paper\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"pencil\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"pencil\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"book\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"book\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"book\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"eraser\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>school_bag<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>bedroom<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can use 'in' on sets as wel</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token comment\"># Tuples are immutable lists of items</span>\ntime_blocks <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"AM\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"PM\"</span><span class=\"token punctuation\">)</span>\ncolors <span class=\"token operator\">=</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"green\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"blue\"</span>  <span class=\"token comment\"># Parenthesis not needed but encouraged</span>\n<span class=\"token comment\"># The tuple built-in function can be used to convert things to tuples</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># 'in' may be used on tuples as well</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token comment\"># Ranges are immutable lists of numbers, often used with for loops</span>\n<span class=\"token comment\">#   - start - default: 0, first number in sequence</span>\n<span class=\"token comment\">#   - stop - required, next number past last number in sequence</span>\n<span class=\"token comment\">#   - step - default: 1, difference between each number in sequence</span>\nrange1 <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># [0,1,2,3,4]</span>\nrange2 <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># [1,2,3,4]</span>\nrange3 <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># [0,5,10,15,20]</span>\nrange4 <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># []</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> range1<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Built-in functions:</span>\n<span class=\"token comment\"># Filter</span>\nisOdd <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> num<span class=\"token punctuation\">:</span> num <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span>\nfiltered <span class=\"token operator\">=</span> <span class=\"token builtin\">filter</span><span class=\"token punctuation\">(</span>isOdd<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>filtered<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> num <span class=\"token keyword\">in</span> filtered<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"first way: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>num<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"--\"</span> <span class=\"token operator\">*</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"list comprehension: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">]</span> <span class=\"token keyword\">if</span> i <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token comment\"># Map</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">toUpper</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\nupperCased <span class=\"token operator\">=</span> <span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>toUpper<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"d\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>upperCased<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Sorted</span>\nsorted_items <span class=\"token operator\">=</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"john\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tom\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sonny\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>sorted_items<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Notice uppercase comes before lowercase</span>\n<span class=\"token comment\"># Using a key function to control the sorting and make it case insensitive</span>\nsorted_items <span class=\"token operator\">=</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"john\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tom\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sonny\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> key<span class=\"token operator\">=</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>sorted_items<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># You can also reverse the sort</span>\nsorted_items <span class=\"token operator\">=</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"john\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tom\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sonny\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> key<span class=\"token operator\">=</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">,</span> reverse<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>sorted_items<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Enumerate creates a tuple with an index for what you're enumerating</span>\nquarters <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"First\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Second\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Third\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Fourth\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>quarters<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>quarters<span class=\"token punctuation\">,</span> start<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Zip takes list and combines them as key value pairs, or really however you need</span>\nkeys <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"Name\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Email\"</span><span class=\"token punctuation\">)</span>\nvalues <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"Buster\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cheetoh@johhnydepp.com\"</span><span class=\"token punctuation\">)</span>\nzipped <span class=\"token operator\">=</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>keys<span class=\"token punctuation\">,</span> values<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>zipped<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># You can zip more than 2</span>\nx_coords <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\ny_coords <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span>\nz_coords <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\ncoords <span class=\"token operator\">=</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>x_coords<span class=\"token punctuation\">,</span> y_coords<span class=\"token punctuation\">,</span> z_coords<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>coords<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Len reports the length of strings along with list and any other object data type</span>\nprint_len <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> item<span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># doing this to save myself some typing</span>\nprint_len<span class=\"token punctuation\">(</span><span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">)</span>\nprint_len<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\nprint_len<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># 4 because there is a duplicate here (10)</span>\nprint_len<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Max will return the max number in a given scenario</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">35</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1012</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Min</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Sum</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Any</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">any</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">any</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># All</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Dir returns all the attributes of an object including it's methods and dunder methods</span>\nuser <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"Name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Bob\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Email\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"bob@bob.com\"</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">dir</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Importing packages and modules</span>\n<span class=\"token comment\">#  - Module - A Python code in a file or directory</span>\n<span class=\"token comment\">#  - Package - A module which is a directory containing an __init__.py file</span>\n<span class=\"token comment\">#  - Submodule - A module which is contained within a package</span>\n<span class=\"token comment\">#  - Name - An exported function, class, or variable in a module</span>\n<span class=\"token comment\"># Unlike JS, modules export ALL names contained within them without any special export key</span>\n<span class=\"token comment\"># Assuming we have the following package with four submodules</span>\n<span class=\"token comment\">#  math</span>\n<span class=\"token comment\">#  |  __init__.py</span>\n<span class=\"token comment\">#  | addition.py</span>\n<span class=\"token comment\">#  | subtraction.py</span>\n<span class=\"token comment\">#  | multiplication.py</span>\n<span class=\"token comment\">#  | division.py</span>\n<span class=\"token comment\"># If we peek into the addition.py file we see there's an add function</span>\n<span class=\"token comment\"># addition.py</span>\n<span class=\"token comment\"># We can import 'add' from other places because it's a 'name' and is automatically exported</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>num1<span class=\"token punctuation\">,</span> num2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> num1 <span class=\"token operator\">+</span> num2\n\n<span class=\"token comment\"># Notice the . syntax because this package can import it's own submodules.</span>\n<span class=\"token comment\"># Our __init__.py has the following files</span>\n<span class=\"token comment\"># This imports the 'add' function</span>\n<span class=\"token comment\"># And now it's also re-exported in here as well</span>\n<span class=\"token comment\"># from .addition import add</span>\n<span class=\"token comment\"># These import and re-export the rest of the functions from the submodule</span>\n<span class=\"token comment\"># from .subtraction import subtract</span>\n<span class=\"token comment\"># from .division import divide</span>\n<span class=\"token comment\"># from .multiplication import multiply</span>\n<span class=\"token comment\"># So if we have a script.py and want to import add, we could do it many ways</span>\n<span class=\"token comment\"># This will load and execute the 'math/__init__.py' file and give</span>\n<span class=\"token comment\"># us an object with the exported names in 'math/__init__.py'</span>\n<span class=\"token keyword\">import</span> math\n<span class=\"token comment\"># print(math.add(1,2))</span>\n<span class=\"token comment\"># This imports JUST the add from 'math/__init__.py'</span>\n<span class=\"token comment\"># from math import add</span>\n<span class=\"token comment\"># print(add(1, 2))</span>\n<span class=\"token comment\"># This skips importing from 'math/__init__.py' (although it still runs)</span>\n<span class=\"token comment\"># and imports directly from the addition.py file</span>\n<span class=\"token comment\"># from math.addition import add</span>\n<span class=\"token comment\"># This imports all the functions individually from 'math/__init__.py'</span>\n<span class=\"token comment\"># from math import add, subtract, multiply, divide</span>\n<span class=\"token comment\"># print(add(1, 2))</span>\n<span class=\"token comment\"># print(subtract(2, 1))</span>\n<span class=\"token comment\"># This imports 'add' renames it to 'add_some_numbers'</span>\n<span class=\"token comment\"># from math import add as add_some_numbers</span>\n<span class=\"token comment\"># --------------------------------------- DAY 3 ---------------------------------------</span>\n<span class=\"token comment\"># Classes, Methods, and Properties</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">AngryBird</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># Slots optimize property access and memory usage and prevent you</span>\n    <span class=\"token comment\"># from arbitrarily assigning new properties the instance</span>\n    __slots__ <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"_x\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"_y\"</span><span class=\"token punctuation\">]</span>\n    <span class=\"token comment\"># Constructor</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> x<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> y<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token comment\"># Doc String</span>\n        <span class=\"token triple-quoted-string string\">\"\"\"\n        Construct a new AngryBird by setting it's position to (0, 0)\n        \"\"\"</span>\n        <span class=\"token comment\">## Instance Variables</span>\n        self<span class=\"token punctuation\">.</span>_x <span class=\"token operator\">=</span> x\n        self<span class=\"token punctuation\">.</span>_y <span class=\"token operator\">=</span> y\n    <span class=\"token comment\"># Instance Method</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">move_up_by</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> delta<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        self<span class=\"token punctuation\">.</span>_y <span class=\"token operator\">+=</span> delta\n    <span class=\"token comment\"># Getter</span>\n    <span class=\"token decorator annotation punctuation\">@property</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">x</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> self<span class=\"token punctuation\">.</span>_x\n    <span class=\"token comment\"># Setter</span>\n    <span class=\"token decorator annotation punctuation\">@x<span class=\"token punctuation\">.</span>setter</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">x</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">if</span> value <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n            value <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n        self<span class=\"token punctuation\">.</span>_x <span class=\"token operator\">=</span> value\n    <span class=\"token decorator annotation punctuation\">@property</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">y</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> self<span class=\"token punctuation\">.</span>_y\n    <span class=\"token decorator annotation punctuation\">@y<span class=\"token punctuation\">.</span>setter</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">y</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        self<span class=\"token punctuation\">.</span>_y <span class=\"token operator\">=</span> value\n    <span class=\"token comment\"># Dunder Repr... called by 'print'</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__repr__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string-interpolation\"><span class=\"token string\">f\"&lt;AngryBird (</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>self<span class=\"token punctuation\">.</span>_x<span class=\"token punctuation\">}</span></span><span class=\"token string\">, </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>self<span class=\"token punctuation\">.</span>_y<span class=\"token punctuation\">}</span></span><span class=\"token string\">)>\"</span></span>\n\n<span class=\"token comment\"># JS to Python Classes cheat table</span>\n<span class=\"token comment\">#        JS                    Python</span>\n<span class=\"token comment\">#   constructor()         def __init__(self):</span>\n<span class=\"token comment\">#      super()            super().__init__()</span>\n<span class=\"token comment\">#   this.property           self.property</span>\n<span class=\"token comment\">#    this.method            self.method()</span>\n<span class=\"token comment\"># method(arg1, arg2){}    def method(self, arg1, ...)</span>\n<span class=\"token comment\"># get someProperty(){}    @property</span>\n<span class=\"token comment\"># set someProperty(){}    @someProperty.setter</span>\n<span class=\"token comment\"># List Comprehensions are a way to transform a list from one format to another</span>\n<span class=\"token comment\">#  - Pythonic Alternative to using map or filter</span>\n<span class=\"token comment\">#  - Syntax of a list comprehension</span>\n<span class=\"token comment\">#     - new_list = [value loop condition]</span>\n<span class=\"token comment\"># Using a for loop</span>\nsquares <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    squares<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>i <span class=\"token operator\">**</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>squares<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># value = i ** 2</span>\n<span class=\"token comment\"># loop = for i in range(10)</span>\nsquares <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>i <span class=\"token operator\">**</span> <span class=\"token number\">2</span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>squares<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nsentence <span class=\"token operator\">=</span> <span class=\"token string\">\"the rocket came back from mars\"</span>\nvowels <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>character <span class=\"token keyword\">for</span> character <span class=\"token keyword\">in</span> sentence <span class=\"token keyword\">if</span> character <span class=\"token keyword\">in</span> <span class=\"token string\">\"aeiou\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>vowels<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># You can also use them on dictionaries. We can use the items() method</span>\n<span class=\"token comment\"># for the dictionary to loop through it getting the keys and values out at once</span>\nperson <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Corina\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"age\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">32</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"height\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1.4</span><span class=\"token punctuation\">}</span>\n<span class=\"token comment\"># This loops through and capitalizes the first letter of all keys</span>\nnewPerson <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>key<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> value <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> person<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>newPerson<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>"},{"url":"/docs/python/","relativePath":"docs/python/index.md","relativeDir":"docs/python","base":"index.md","name":"index","frontmatter":{"title":"Python","weight":0,"excerpt":"Python","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<br>\n<h1>  Python Resources</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    class=\"inner\" src=\"https://ds-unit-5-lambda.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h2>My Python Docs:</h2>\n<h2><a href=\"https://bgoonz42.gitbook.io/datastructures-in-pytho/\">My Python Website</a></h2>\n<h1>Python Study Guide for a JavaScript Programmer</h1>\n<p>A guide to commands in Python from what you know in JavaScript</p>\n<hr>\n<h3>Python Study Guide for a JavaScript Programmer</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*3V9VOfPk_hrFdbEAd3j-QQ.png\" class=\"graf-image\" />\n</figure>### Applications of Tutorial & Cheat Sheet Respectivley (At Bottom Of Tutorial):\n<h3>Basics</h3>\n<ul>\n<li><span id=\"f893\"><strong>PEP8</strong> : Python Enhancement Proposals, style-guide for Python.</span></li>\n<li><span id=\"c0bf\"><code class=\"language-text\">print</code> is the equivalent of <code class=\"language-text\">console.log</code>.</span></li>\n</ul>\n<blockquote>\n<p>'print() == console.log()'</p>\n</blockquote>\n<h3><code class=\"language-text\">#</code> is used to make comments in your code.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def foo():\n    \"\"\"\n    The foo function does many amazing things that you\n    should not question. Just accept that it exists and\n    use it with caution.\n    \"\"\"\n    secretThing()</code></pre></div>\n<blockquote>\n<p><em>Python has a built in help function that let's you see a description of the source code without having to navigate to it… \"-SickNasty … Autor Unknown\"</em></p>\n</blockquote>\n<hr>\n<h3>Numbers</h3>\n<ul>\n<li><span id=\"4060\">Python has three types of numbers:</span></li>\n<li><span id=\"8aef\"><strong>Integer</strong></span></li>\n<li><span id=\"723f\"><strong>Positive and Negative Counting Numbers.</strong></span></li>\n</ul>\n<p>No Decimal Point</p>\n<blockquote>\n<p>Created by a literal non-decimal point number … <strong>or</strong> … with the <code class=\"language-text\">int()</code> constructor.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(3) # => 3\nprint(int(19)) # => 19\nprint(int()) # => 0</code></pre></div>\n<p><strong>3. Complex Numbers</strong></p>\n<blockquote>\n<p>Consist of a real part and imaginary part.</p>\n</blockquote>\n<h4>Boolean is a subtype of integer in Python.🤷‍♂️</h4>\n<blockquote>\n<p>If you came from a background in JavaScript and learned to accept the premise(s) of the following meme…</p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*eC4EvZcv6hhH88jX.png\" class=\"graf-image\" />\n</figure>Than I am sure you will find the means to suspend your disbelief.\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(2.24) # => 2.24\nprint(2.) # => 2.0\nprint(float()) # => 0.0\nprint(27e-5) # => 0.00027</code></pre></div>\n<h3>KEEP IN MIND:</h3>\n<blockquote>\n<p><strong>The</strong> <code class=\"language-text\">i</code> <strong>is switched to a</strong> <code class=\"language-text\">j</code> <strong>in programming.</strong></p>\n</blockquote>\n<p><span class=\"graf-dropCap\">T</span>*his is because the letter i is common place as the de facto index for any and all enumerable entities so it just makes sense not to compete for name-*<strong><em>space</em></strong> <em>when there's another 25 letters that don't get used for every loop under the sun. My most medium apologies to Leonhard Euler.</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(7j) # => 7j\nprint(5.1+7.7j)) # => 5.1+7.7j\nprint(complex(3, 5)) # => 3+5j\nprint(complex(17)) # => 17+0j\nprint(complex()) # => 0j</code></pre></div>\n<ul>\n<li><span id=\"2579\"><strong>Type Casting</strong> : The process of converting one number to another.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Using Float\nprint(17)               # => 17\nprint(float(17))        # => 17.0\n\n# Using Int\nprint(17.0)             # => 17.0\nprint(int(17.0))        # => 17\n\n# Using Str\nprint(str(17.0) + ' and ' + str(17))        # => 17.0 and 17</code></pre></div>\n<p><strong>The arithmetic operators are the same between JS and Python, with two additions:</strong></p>\n<ul>\n<li><span id=\"8cf4\"><em>\"**\" : Double asterisk for exponent.</em></span></li>\n<li><span id=\"03b4\"><em>\"//\" : Integer Division.</em></span></li>\n<li><span id=\"2ce5\"><strong>There are no spaces between math operations in Python.</strong></span></li>\n<li><span id=\"1686\"><strong>Integer Division gives the other part of the number from Module; it is a way to do round down numbers replacing</strong> <code class=\"language-text\">Math.floor()</code> <strong>in JS.</strong></span></li>\n<li><span id=\"a6a3\"><strong>There are no</strong> <code class=\"language-text\">++</code> <strong>and</strong> <code class=\"language-text\">--</code> <strong>in Python, the only shorthand operators are:</strong></span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/0*Ez_1PZ93N4FfvkRr.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Strings</h3>\n<ul>\n<li><span id=\"e98c\">Python uses both single and double quotes.</span></li>\n<li><span id=\"225e\">You can escape strings like so <code class=\"language-text\">'Jodi asked, \"What\\'s up, Sam?\"'</code></span></li>\n<li><span id=\"9f74\">Multiline strings use triple quotes.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print('''My instructions are very long so to make them\nmore readable in the code I am putting them on\nmore than one line. I can even include \"quotes\"\nof any kind because they won't get confused with\nthe end of the string!''')</code></pre></div>\n<p><strong>Use the</strong> <code class=\"language-text\">len()</code> <strong>function to get the length of a string.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(len(\"Spaghetti\")) # => 9</code></pre></div>\n<h3><strong>Python uses</strong> <code class=\"language-text\">zero-based indexing</code></h3>\n<h4>Python allows negative indexing (thank god!)</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Spaghetti\"[-1]) # => i\n\nprint(\"Spaghetti\"[-4]) # => e</code></pre></div>\n<ul>\n<li><span id=\"7567\">Python let's you use ranges</span></li>\n</ul>\n<p>You can think of this as roughly equivalent to the slice method called on a JavaScript object or string… <em>(mind you that in JS … strings are wrapped in an object (under the hood)… upon which the string methods are actually called. As a immutable privative type</em> <strong>*by textbook definition**</strong>, a string literal could not hope to invoke most of it's methods without violating the state it was bound to on initialization if it were not for this bit of syntactic sugar.)*</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Spaghetti\"[1:4]) # => pag\nprint(\"Spaghetti\"[4:-1]) # => hett\nprint(\"Spaghetti\"[4:4]) # => (empty string)</code></pre></div>\n<ul>\n<li><span id=\"1366\">The end range is exclusive just like <code class=\"language-text\">slice</code> in JS.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Shortcut to get from the beginning of a string to a certain index.\nprint(\"Spaghetti\"[:4])  # => Spag\nprint(\"Spaghetti\"[:-1])    # => Spaghett\n\n# Shortcut to get from a certain index to the end of a string.\nprint(\"Spaghetti\"[1:])  # => paghetti\nprint(\"Spaghetti\"[-4:])    # => etti</code></pre></div>\n<ul>\n<li><span id=\"c786\">The <code class=\"language-text\">index</code> string function is the equiv. of <code class=\"language-text\">indexOf()</code> in JS</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Spaghetti\".index(\"h\"))    # => 4\nprint(\"Spaghetti\".index(\"t\"))    # => 6</code></pre></div>\n<ul>\n<li><span id=\"fbb6\">The <code class=\"language-text\">count</code> function finds out how many times a substring appears in a string… pretty nifty for a hard coded feature of the language.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Spaghetti\".count(\"h\"))    # => 1\nprint(\"Spaghetti\".count(\"t\"))    # => 2\nprint(\"Spaghetti\".count(\"s\"))    # => 0\nprint('''We choose to go to the moon in this decade and do the other things,\nnot because they are easy, but because they are hard, because that goal will\nserve to organize and measure the best of our energies and skills, because that\nchallenge is one that we are willing to accept, one we are unwilling to\npostpone, and one which we intend to win, and the others, too.\n'''.count('the '))                # => 4</code></pre></div>\n<ul>\n<li><span id=\"7816\"><strong>You can use</strong> <code class=\"language-text\">+</code> <strong>to concatenate strings, just like in JS.</strong></span></li>\n<li><span id=\"ed0a\"><strong>You can also use \"*\" to repeat strings or multiply strings.</strong></span></li>\n<li><span id=\"f95c\"><strong>Use the</strong> <code class=\"language-text\">format()</code> <strong>function to use placeholders in a string to input values later on.</strong></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">first_name = \"Billy\"\nlast_name = \"Bob\"\nprint('Your name is {0} {1}'.format(first_name, last_name))  # => Your name is Billy Bob</code></pre></div>\n<ul>\n<li><span id=\"445b\"><em>Shorthand way to use format function is:\n_`print(f'Your name is {first</em>name} {last_name}')`</span></li>\n</ul>\n<h4>Some useful string methods.</h4>\n<ul>\n<li><span id=\"118c\"><strong>Note that in JS</strong> <code class=\"language-text\">join</code> <strong>is used on an Array, in Python it is used on String.</strong></span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*eE3E5H0AoqkhqK1z.png\" class=\"graf-image\" />\n</figure>- <span id=\"e95e\">There are also many handy testing methods.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Q0CMqFd4PozLDFPB.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Variables and Expressions</h3>\n<ul>\n<li><span id=\"a255\"><strong>Duck-Typing</strong> : Programming Style which avoids checking an object's type to figure out what it can do.</span></li>\n<li><span id=\"6e70\">Duck Typing is the fundamental approach of Python.</span></li>\n<li><span id=\"5666\">Assignment of a value automatically declares a variable.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 7\nb = 'Marbles'\nprint(a)         # => 7\nprint(b)         # => Marbles</code></pre></div>\n<ul>\n<li><span id=\"f6cf\"><strong><em>You can chain variable assignments to give multiple var names the same value.</em></strong></span></li>\n</ul>\n<h4>Use with caution as this is highly unreadable</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">count = max = min = 0\nprint(count)           # => 0\nprint(max)             # => 0\nprint(min)             # => 0</code></pre></div>\n<h4>The value and type of a variable can be re-assigned at any time.</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 17\nprint(a)         # => 17\na = 'seventeen'\nprint(a)         # => seventeen</code></pre></div>\n<ul>\n<li><span id=\"4605\"><code class=\"language-text\">NaN</code> _does not exist in Python, but you can 'create' it like so:</li>\n<li>_<code class=\"language-text\">print(float(\"nan\"))</code></span></li>\n<li><span id=\"d150\"><em>Python replaces</em> <code class=\"language-text\">null</code> <em>with</em> <code class=\"language-text\">none</code><em>.</em></span></li>\n<li><span id=\"6fa7\"><code class=\"language-text\">none</code> <strong><em>is an object</em></strong> <em>and can be directly assigned to a variable.</em></span></li>\n</ul>\n<blockquote>\n<p>Using none is a convenient way to check to see why an action may not be operating correctly in your program.</p>\n</blockquote>\n<hr>\n<h3>Boolean Data Type</h3>\n<ul>\n<li><span id=\"b843\">One of the biggest benefits of Python is that it reads more like English than JS does.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*HQpndNhm1Z_xSoHb.png\" class=\"graf-image\" />\n</figure># Logical AND\n    print(True and True)    # => True\n    print(True and False)   # => False\n    print(False and False)  # => False\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Logical OR\nprint(True or True)     # => True\nprint(True or False)    # => True\nprint(False or False)   # => False\n\n# Logical NOT\nprint(not True)             # => False\nprint(not False and True)   # => True\nprint(not True or False)    # => False</code></pre></div>\n<ul>\n<li><span id=\"18cc\">By default, Python considers an object to be true UNLESS it is one of the following:</span></li>\n<li><span id=\"6e0a\">Constant <code class=\"language-text\">None</code> or <code class=\"language-text\">False</code></span></li>\n<li><span id=\"9552\">Zero of any numeric type.</span></li>\n<li><span id=\"e7ce\">Empty Sequence or Collection.</span></li>\n<li><span id=\"11d6\"><code class=\"language-text\">True</code> and <code class=\"language-text\">False</code> must be capitalized</span></li>\n</ul>\n<hr>\n<h3>Comparison Operators</h3>\n<ul>\n<li><span id=\"a4fa\">Python uses all the same equality operators as JS.</span></li>\n<li><span id=\"7f98\">In Python, equality operators are processed from left to right.</span></li>\n<li><span id=\"fb68\">Logical operators are processed in this order:</span></li>\n<li><span id=\"bf08\"><strong>NOT</strong></span></li>\n<li><span id=\"4888\"><strong>AND</strong></span></li>\n<li><span id=\"2c55\"><strong>OR</strong></span></li>\n</ul>\n<blockquote>\n<p>Just like in JS, you can use <code class=\"language-text\">parentheses</code> to change the inherent order of operations.</p>\n</blockquote>\n<blockquote>\n<p><strong>Short Circuit</strong> : Stopping a program when a <code class=\"language-text\">true</code> or <code class=\"language-text\">false</code> has been reached.</p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*qHzGRLTOMTf30miT.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Identity vs Equality</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print (2 == '2')    # => False\nprint (2 is '2')    # => False\n\nprint (\"2\" == '2')    # => True\nprint (\"2\" is '2')    # => True\n\n# There is a distinction between the number types.\nprint (2 == 2.0)    # => True\nprint (2 is 2.0)    # => False</code></pre></div>\n<ul>\n<li><span id=\"c5a5\">In the Python community it is better to use <code class=\"language-text\">is</code> and <code class=\"language-text\">is not</code> over <code class=\"language-text\">==</code> or <code class=\"language-text\">!=</code></span></li>\n</ul>\n<hr>\n<h3>If Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if name == 'Monica':\n    print('Hi, Monica.')\n\nif name == 'Monica':\n    print('Hi, Monica.')\nelse:\n    print('Hello, stranger.')\n\nif name == 'Monica':\n    print('Hi, Monica.')\nelif age &lt; 12:\n    print('You are not Monica, kiddo.')\nelif age > 2000:\n   print('Unlike you, Monica is not an undead, immortal vampire.')\nelif age > 100:\n   print('You are not Monica, grannie.')</code></pre></div>\n<blockquote>\n<p>Remember the order of <code class=\"language-text\">elif</code> statements matter.</p>\n</blockquote>\n<hr>\n<h3>While Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">spam = 0\nwhile spam &lt; 5:\n  print('Hello, world.')\n  spam = spam + 1</code></pre></div>\n<ul>\n<li><span id=\"c7f3\"><code class=\"language-text\">Break</code> statement also exists in Python.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">spam = 0\nwhile True:\n  print('Hello, world.')\n  spam = spam + 1\n  if spam >= 5:\n    break</code></pre></div>\n<ul>\n<li><span id=\"7a99\">As are <code class=\"language-text\">continue</code> statements</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">spam = 0\nwhile True:\n  print('Hello, world.')\n  spam = spam + 1\n  if spam &lt; 5:\n    continue\n  break</code></pre></div>\n<hr>\n<h3>Try/Except Statements</h3>\n<ul>\n<li><span id=\"72ec\">Python equivalent to <code class=\"language-text\">try/catch</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 321\ntry:\n    print(len(a))\nexcept:\n    print('Silently handle error here')\n\n    # Optionally include a correction to the issue\n    a = str(a)\n    print(len(a)\n\na = '321'\ntry:\n    print(len(a))\nexcept:\n    print('Silently handle error here')\n\n    # Optionally include a correction to the issue\n    a = str(a)\n    print(len(a))</code></pre></div>\n<ul>\n<li><span id=\"dcd1\">You can name an error to give the output more specificity.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 100\nb = 0\ntry:\n    c = a / b\nexcept ZeroDivisionError:\n    c = None\nprint(c)</code></pre></div>\n<ul>\n<li><span id=\"4027\">You can also use the <code class=\"language-text\">pass</code> commmand to by pass a certain error.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 100\nb = 0\ntry:\n    print(a / b)\nexcept ZeroDivisionError:\n    pass</code></pre></div>\n<ul>\n<li><span id=\"030b\">The <code class=\"language-text\">pass</code> method won't allow you to bypass every single error so you can chain an exception series like so:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 100\n# b = \"5\"\ntry:\n    print(a / b)\nexcept ZeroDivisionError:\n    pass\nexcept (TypeError, NameError):\n    print(\"ERROR!\")</code></pre></div>\n<ul>\n<li><span id=\"bf45\">You can use an <code class=\"language-text\">else</code> statement to end a chain of <code class=\"language-text\">except</code> statements.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># tuple of file names\nfiles = ('one.txt', 'two.txt', 'three.txt')\n\n# simple loop\nfor filename in files:\n    try:\n        # open the file in read mode\n        f = open(filename, 'r')\n    except OSError:\n        # handle the case where file does not exist or permission is denied\n        print('cannot open file', filename)\n    else:\n        # do stuff with the file object (f)\n        print(filename, 'opened successfully')\n        print('found', len(f.readlines()), 'lines')\n        f.close()</code></pre></div>\n<ul>\n<li><span id=\"0e91\"><code class=\"language-text\">finally</code> is used at the end to clean up all actions under any circumstance.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def divide(x, y):\n    try:\n        result = x / y\n    except ZeroDivisionError:\n        print(\"Cannot divide by zero\")\n    else:\n        print(\"Result is\", result)\n    finally:\n        print(\"Finally...\")</code></pre></div>\n<ul>\n<li><span id=\"84ee\">Using duck typing to check to see if some value is able to use a certain method.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Try a number - nothing will print out\na = 321\nif hasattr(a, '__len__'):\n    print(len(a))\n\n# Try a string - the length will print out (4 in this case)\nb = \"5555\"\nif hasattr(b, '__len__'):\n    print(len(b))</code></pre></div>\n<hr>\n<h3>Pass</h3>\n<ul>\n<li><span id=\"2b80\">Pass Keyword is required to write the JS equivalent of :</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if (true) {\n}\n\nwhile (true) {}\n\nif True:\n  pass\n\nwhile True:\n  pass</code></pre></div>\n<hr>\n<h3>Functions</h3>\n<ul>\n<li><span id=\"7091\"><strong>Function definition includes:</strong></span></li>\n<li><span id=\"1f11\"><strong>The</strong> <code class=\"language-text\">def</code> <strong>keyword</strong></span></li>\n<li><span id=\"ec14\"><strong>The name of the function</strong></span></li>\n<li><span id=\"7733\"><strong>A list of parameters enclosed in parentheses.</strong></span></li>\n<li><span id=\"1516\"><strong>A colon at the end of the line.</strong></span></li>\n<li><span id=\"b2dd\"><strong>One tab indentation for the code to run.</strong></span></li>\n<li><span id=\"bcef\"><strong>You can use default parameters just like in JS</strong></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def greeting(name, saying=\"Hello\"):\n    print(saying, name)\n\ngreeting(\"Monica\")\n# Hello Monica\n\ngreeting(\"Barry\", \"Hey\")\n# Hey Barry</code></pre></div>\n<h4><strong>Keep in mind, default parameters must always come after regular parameters.</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># THIS IS BAD CODE AND WILL NOT RUN\ndef increment(delta=1, value):\n    return delta + value</code></pre></div>\n<ul>\n<li><span id=\"c1aa\"><em>You can specify arguments by name without destructuring in Python.</em></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def greeting(name, saying=\"Hello\"):\n    print(saying, name)\n\n# name has no default value, so just provide the value\n# saying has a default value, so use a keyword argument\ngreeting(\"Monica\", saying=\"Hi\")</code></pre></div>\n<ul>\n<li><span id=\"54ac\">The <code class=\"language-text\">lambda</code> keyword is used to create anonymous functions and are supposed to be <code class=\"language-text\">one-liners</code>.</span></li>\n</ul>\n<p><code class=\"language-text\">toUpper = lambda s: s.upper()</code></p>\n<hr>\n<h3>Notes</h3>\n<h4>Formatted Strings</h4>\n<blockquote>\n<p>Remember that in Python join() is called on a string with an array/list passed in as the argument.\nPython has a very powerful formatting engine.\nformat() is also applied directly to strings.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">shopping_list = ['bread','milk','eggs']\nprint(','.join(shopping_list))</code></pre></div>\n<h3>Comma Thousands Separator</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print('{:,}'.format(1234567890))\n'1,234,567,890'</code></pre></div>\n<h3>Date and Time</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">d = datetime.datetime(2020, 7, 4, 12, 15, 58)\nprint('{:%Y-%m-%d %H:%M:%S}'.format(d))\n'2020-07-04 12:15:58'</code></pre></div>\n<h3>Percentage</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">points = 190\ntotal = 220\nprint('Correct answers: {:.2%}'.format(points/total))\nCorrect answers: 86.36%</code></pre></div>\n<h3>Data Tables</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">width=8\nprint(' decimal hex binary')\nprint('-'*27)\nfor num in range(1,16):\nfor base in 'dXb':\nprint('{0:{width}{base}}'.format(num, base=base, width=width), end=' ')\nprint()\nGetting Input from the Command Line\nPython runs synchronously, all programs and processes will stop when listening for a user input.\nThe input function shows a prompt to a user and waits for them to type 'ENTER'.\nScripts vs Programs\nProgramming Script : A set of code that runs in a linear fashion.\nThe largest difference between scripts and programs is the level of complexity and purpose. Programs typically have many UI's.</code></pre></div>\n<p><strong>Python can be used to display html, css, and JS.</strong>\n<em>It is common to use Python as an API (Application Programming Interface)</em></p>\n<h4>Structured Data</h4>\n<h4>Sequence : The most basic data structure in Python where the index determines the order.</h4>\n<blockquote>\n<p>List\nTuple\nRange\nCollections : Unordered data structures, hashable values.</p>\n</blockquote>\n<hr>\n<h4>Dictionaries Sets</h4>\n<h4>Iterable : Generic name for a sequence or collection; any object that can be iterated through.</h4>\n<h4>Can be mutable or immutable. Built In Data Types</h4>\n<hr>\n<h3>Lists are the python equivalent of arrays.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">empty_list = []\ndepartments = ['HR','Development','Sales','Finance','IT','Customer Support']</code></pre></div>\n<h3>You can instantiate</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">specials = list()</code></pre></div>\n<h4>Test if a value is in a list.</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(1 in [1, 2, 3]) #> True\nprint(4 in [1, 2, 3]) #> False\n# Tuples : Very similar to lists, but they are immutable</code></pre></div>\n<h4>Instantiated with parentheses</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">time_blocks = ('AM','PM')</code></pre></div>\n<h4>Sometimes instantiated without</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">colors = 'red','blue','green'\nnumbers = 1, 2, 3</code></pre></div>\n<h4>Tuple() built in can be used to convert other data into a tuple</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">tuple('abc') # returns ('a', 'b', 'c')\ntuple([1,2,3]) # returns (1, 2, 3)\n# Think of tuples as constant variables.</code></pre></div>\n<h4>Ranges : A list of numbers which can't be changed; often used with for loops.</h4>\n<p><strong>Declared using one to three parameters</strong>.</p>\n<blockquote>\n<p>Start : opt. default 0, first # in sequence.\nStop : required next number past the last number in the sequence.\nStep : opt. default 1, difference between each number in the sequence.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">range(5) # [0, 1, 2, 3, 4]\nrange(1,5) # [1, 2, 3, 4]\nrange(0, 25, 5) # [0, 5, 10, 15, 20]\nrange(0) # [ ]\nfor let (i = 0; i &lt; 5; i++)\nfor let (i = 1; i &lt; 5; i++)\nfor let (i = 0; i &lt; 25; i+=5)\nfor let(i = 0; i = 0; i++)\n# Keep in mind that stop is not included in the range.</code></pre></div>\n<h4>Dictionaries : Mappable collection where a hashable value is used as a key to ref. an object stored in the dictionary.</h4>\n<h4>Mutable.</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = {'one':1, 'two':2, 'three':3}\nb = dict(one=1, two=2, three=3)\nc = dict([('two', 2), ('one', 1), ('three', 3)])\n# a, b, and c are all equal</code></pre></div>\n<p><strong><em>Declared with curly braces of the built in dict()</em></strong></p>\n<blockquote>\n<p><em>Benefit of dictionaries in Python is that it doesn't matter how it is defined, if the keys and values are the same the dictionaries are considered equal.</em></p>\n</blockquote>\n<p><strong>Use the in operator to see if a key exists in a dictionary.</strong></p>\n<p><span class=\"graf-dropCap\">S</span><strong>ets : Unordered collection of distinct objects; objects that need to be hashable.</strong></p>\n<blockquote>\n<p><em>Always be unique, duplicate items are auto dropped from the set.</em></p>\n</blockquote>\n<h4>Common Uses:</h4>\n<blockquote>\n<p>Removing Duplicates\nMembership Testing\nMathematical Operators: Intersection, Union, Difference, Symmetric Difference.</p>\n</blockquote>\n<p><strong>Standard Set is mutable, Python has a immutable version called frozenset.\nSets created by putting comma seperated values inside braces:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">school_bag = {'book','paper','pencil','pencil','book','book','book','eraser'}\nprint(school_bag)</code></pre></div>\n<h4>Also can use set constructor to automatically put it into a set.</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">letters = set('abracadabra')\nprint(letters)\n#Built-In Functions\n#Functions using iterables</code></pre></div>\n<p><strong>filter(function, iterable) : creates new iterable of the same type which includes each item for which the function returns true.</strong></p>\n<p><strong>map(function, iterable) : creates new iterable of the same type which includes the result of calling the function on every item of the iterable.</strong></p>\n<p><strong>sorted(iterable, key=None, reverse=False) : creates a new sorted list from the items in the iterable.</strong></p>\n<p><strong>Output is always a list</strong></p>\n<p><strong>key: opt function which coverts and item to a value to be compared.</strong></p>\n<p><strong>reverse: optional boolean.</strong></p>\n<p><strong>enumerate(iterable, start=0) : starts with a sequence and converts it to a series of tuples</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">quarters = ['First', 'Second', 'Third', 'Fourth']\nprint(enumerate(quarters))\nprint(enumerate(quarters, start=1))</code></pre></div>\n<h4>(0, 'First'), (1, 'Second'), (2, 'Third'), (3, 'Fourth')</h4>\n<h4>(1, 'First'), (2, 'Second'), (3, 'Third'), (4, 'Fourth')</h4>\n<blockquote>\n<p>zip(*iterables) : creates a zip object filled with tuples that combine 1 to 1 the items in each provided iterable.\nFunctions that analyze iterable</p>\n</blockquote>\n<p><strong>len(iterable) : returns the count of the number of items.</strong></p>\n<p><strong>max(*args, key=None) : returns the largest of two or more arguments.</strong></p>\n<p><strong>max(iterable, key=None) : returns the largest item in the iterable.</strong></p>\n<p><em>key optional function which converts an item to a value to be compared.\nmin works the same way as max</em></p>\n<p><strong>sum(iterable) : used with a list of numbers to generate the total.</strong></p>\n<p><em>There is a faster way to concatenate an array of strings into one string, so do not use sum for that.</em></p>\n<p><strong>any(iterable) : returns True if any items in the iterable are true.</strong></p>\n<p><strong>all(iterable) : returns True is all items in the iterable are true.</strong></p>\n<h3>Working with dictionaries</h3>\n<p><strong>dir(dictionary) : returns the list of keys in the dictionary.\nWorking with sets</strong></p>\n<p><strong>Union : The pipe | operator or union(*sets) function can be used to produce a new set which is a combination of all elements in the provided set.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = {1, 2, 3}\nb = {2, 4, 6}\nprint(a | b) # => {1, 2, 3, 4, 6}</code></pre></div>\n<h4>Intersection : The &#x26; operator ca be used to produce a new set of only the elements that appear in all sets.</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = {1, 2, 3}\nb = {2, 4, 6}\nprint(a &amp; b) # => {2}\nDifference : The — operator can be used to produce a new set of only the elements that appear in the first set and NOT the others.</code></pre></div>\n<p><strong>Symmetric Difference : The ^ operator can be used to produce a new set of only the elements that appear in exactly one set and not in both.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = {1, 2, 3}\nb = {2, 4, 6}\nprint(a — b) # => {1, 3}\nprint(b — a) # => {4, 6}\nprint(a ^ b) # => {1, 3, 4, 6}</code></pre></div>\n<hr>\n<h3><strong>For Statements In python, there is only one for loop.</strong></h3>\n<p>Always Includes:</p>\n<blockquote>\n<ol>\n<li>The for keyword</li>\n<li>A variable name</li>\n<li>The 'in' keyword</li>\n<li>An iterable of some kid</li>\n<li>A colon</li>\n<li>On the next line, an indented block of code called the for clause.</li>\n</ol>\n</blockquote>\n<p><strong>You can use break and continue statements inside for loops as well.</strong></p>\n<p><strong>You can use the range function as the iterable for the for loop.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print('My name is')\nfor i in range(5):\nprint('Carlita Cinco (' + str(i) + ')')\n\ntotal = 0\nfor num in range(101):\ntotal += num\nprint(total)\nLooping over a list in Python\nfor c in ['a', 'b', 'c']:\nprint(c)\n\nlst = [0, 1, 2, 3]\nfor i in lst:\nprint(i)</code></pre></div>\n<p><strong><em>Common technique is to use the len() on a pre-defined list with a for loop to iterate over the indices of the list.</em></strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">supplies = ['pens', 'staplers', 'flame-throwers', 'binders']\nfor i in range(len(supplies)):\nprint('Index ' + str(i) + ' in supplies is: ' + supplies[i])</code></pre></div>\n<p><strong>You can loop and destructure at the same time.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">l = 1, 2], [3, 4], [5, 6\nfor a, b in l:\nprint(a, ', ', b)</code></pre></div>\n<blockquote>\n<p>Prints 1, 2</p>\n</blockquote>\n<blockquote>\n<p>Prints 3, 4</p>\n</blockquote>\n<blockquote>\n<p>Prints 5, 6</p>\n</blockquote>\n<p><strong>You can use values() and keys() to loop over dictionaries.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">spam = {'color': 'red', 'age': 42}\nfor v in spam.values():\nprint(v)</code></pre></div>\n<p><em>Prints red</em></p>\n<p><em>Prints 42</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for k in spam.keys():\nprint(k)</code></pre></div>\n<p><em>Prints color</em></p>\n<p><em>Prints age</em></p>\n<p><strong>For loops can also iterate over both keys and values.</strong></p>\n<p><strong>Getting tuples</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for i in spam.items():\nprint(i)</code></pre></div>\n<p><em>Prints ('color', 'red')</em></p>\n<p><em>Prints ('age', 42)</em></p>\n<p><em>Destructuring to values</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for k, v in spam.items():\nprint('Key: ' + k + ' Value: ' + str(v))</code></pre></div>\n<p><em>Prints Key: age Value: 42</em></p>\n<p><em>Prints Key: color Value: red</em></p>\n<p><strong>Looping over string</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for c in \"abcdefg\":\nprint(c)</code></pre></div>\n<p><strong>When you order arguments within a function or function call, the args need to occur in a particular order:</strong></p>\n<p><em>formal positional args.</em></p>\n<p>*args</p>\n<p><em>keyword args with default values</em></p>\n<p>**kwargs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def example(arg_1, arg_2, *args, **kwargs):\npass\n\ndef example2(arg_1, arg_2, *args, kw_1=\"shark\", kw_2=\"blowfish\", **kwargs):\npass</code></pre></div>\n<hr>\n<h3><strong>Importing in Python</strong></h3>\n<p><strong>Modules are similar to packages in Node.js</strong>\nCome in different types:</p>\n<p>Built-In,</p>\n<p>Third-Party,</p>\n<p>Custom.</p>\n<p><strong>All loaded using import statements.</strong></p>\n<hr>\n<h3><strong>Terms</strong></h3>\n<blockquote>\n<p>module : Python code in a separate file.\npackage : Path to a directory that contains modules.\n<a href=\"http://init.py\" class=\"markup--anchor markup--blockquote-anchor\">\n<strong>init.py</strong>\n</a> : Default file for a package.\nsubmodule : Another file in a module's folder.\nfunction : Function in a module.</p>\n</blockquote>\n<p><strong>A module can be any file but it is usually created by placing a special file init.py into a folder. pic</strong></p>\n<p><em>Try to avoid importing with wildcards in Python.</em></p>\n<p><em>Use multiple lines for clarity when importing.</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from urllib.request import (\nHTTPDefaultErrorHandler as ErrorHandler,\nHTTPRedirectHandler as RedirectHandler,\nRequest,\npathname2url,\nurl2pathname,\nurlopen,\n)</code></pre></div>\n<hr>\n<h3>Watching Out for Python 2</h3>\n<p><strong>Python 3 removed &#x3C;> and only uses !=</strong></p>\n<p><strong>format() was introduced with P3</strong></p>\n<p><strong>All strings in P3 are unicode and encoded.\nmd5 was removed.</strong></p>\n<p><strong>ConfigParser was renamed to configparser\nsets were killed in favor of set() class.</strong></p>\n<h4><strong>print was a statement in P2, but is a function in P3.</strong></h4>\n<h3>Topics revisited (in python syntax)</h3>\n<h3>Cheat Sheet:</h3>\n<h4>If you found this guide helpful feel free to checkout my github/gists where I host similar content:</h4>\n<p><a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--p-anchor\">bgoonz's gists · GitHub</a></p>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>Or Checkout my personal Resource Site:</p>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\">\n<strong>a/A-Student-Resources</strong>\n<br />\n<em>Edit description</em>goofy-euclid-1cd736.netlify.app</a>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>Python Cheat Sheet:</h3>\n<h3>If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content:</h3>\n<a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://gist.github.com/bgoonz\">\n<strong>bgoonz's gists</strong>\n<br />\n<em>Instantly share code, notes, and snippets. Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python |…</em>gist.github.com</a>\n<a href=\"https://gist.github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>"},{"url":"/docs/python/functions/","relativePath":"docs/python/functions.md","relativeDir":"docs/python","base":"functions.md","name":"functions","frontmatter":{"title":"Python Functions","weight":0,"excerpt":"When creating a function using the def statement, you can specify what the return value should be with a return statement. A return statement consists of the following","seo":{"title":"Python Functions","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Functions</h2>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Return Values and return Statements</h3>\n<p>When creating a function using the def statement, you can specify what the return value should be with a return statement. A return statement consists of the following:</p>\n<ul>\n<li>The return keyword.</li>\n<li>-</li>\n<li>The value or expression that the function should return.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n<span class=\"token keyword\">def</span> <span class=\"token function\">getAnswer</span><span class=\"token punctuation\">(</span>answerNumber<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'It is certain'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'It is decidedly so'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Yes'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Reply hazy try again'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Ask again later'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Concentrate and ask again'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">7</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'My reply is no'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">8</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Outlook not so good'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">9</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Very doubtful'</span>\n\nr <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span>\nfortune <span class=\"token operator\">=</span> getAnswer<span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>fortune<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The None Value</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello!'</span><span class=\"token punctuation\">)</span>\nspam <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span></code></pre></div>\n<p>Note: never compare to <code class=\"language-text\">None</code> with the <code class=\"language-text\">==</code> operator. Always use <code class=\"language-text\">is</code>.</p>\n<h3>print Keyword Arguments</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'World'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mice'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mice'</span><span class=\"token punctuation\">,</span> sep<span class=\"token operator\">=</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Local and Global Scope</h3>\n<ul>\n<li>Code in the global scope cannot use any local variables.</li>\n<li>-</li>\n<li>However, a local scope can access global variables.</li>\n<li>-</li>\n<li>Code in a function's local scope cannot use variables in any other local scope.</li>\n<li>You can use the same name for different variables if they are in different scopes. That is, there can be a local variable named spam and a global variable also named spam.</li>\n</ul>\n<h3>The global Statement</h3>\n<p>If you need to modify a global variable from within a function, use the global statement:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">spam</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">global</span> eggs\n    eggs <span class=\"token operator\">=</span> <span class=\"token string\">'spam'</span>\n\neggs <span class=\"token operator\">=</span> <span class=\"token string\">'global'</span>\nspam<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>eggs<span class=\"token punctuation\">)</span></code></pre></div>\n<p>There are four rules to tell whether a variable is in a local scope or global scope:</p>\n<ol>\n<li>If a variable is being used in the global scope (that is, outside of all functions), then it is always a global variable.</li>\n<li>If there is a global statement for that variable in a function, it is a global variable.</li>\n<li>Otherwise, if the variable is used in an assignment statement in the function, it is a local variable.</li>\n<li>But if the variable is not used in an assignment statement, it is a global variable.</li>\n</ol>"},{"url":"/docs/python/modules/","relativePath":"docs/python/modules.md","relativeDir":"docs/python","base":"modules.md","name":"modules","frontmatter":{"title":"Python Modules","template":"docs","excerpt":"If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost"},"html":"<!--StartFragment-->\n<h1>6. Modules<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#modules\" title=\"Permalink to this headline\"></a></h1>\n<p>If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a <em>script</em>. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program.</p>\n<p>To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a <em>module</em>; definitions from a module can be <em>imported</em> into other modules or into the <em>main</em> module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).</p>\n<p>A module is a file containing Python definitions and statements. The file name is the module name with the suffix <code class=\"language-text\">.py</code> appended. Within a module, the module’s name (as a string) is available as the value of the global variable <code class=\"language-text\">__name__</code>. For instance, use your favorite text editor to create a file called <code class=\"language-text\">fibo.py</code> in the current directory with the following contents:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Fibonacci numbers module</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token comment\"># write Fibonacci series up to n</span>\n    a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">while</span> a <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span>\n        a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> b<span class=\"token punctuation\">,</span> a<span class=\"token operator\">+</span>b\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">fib2</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>   <span class=\"token comment\"># return Fibonacci series up to n</span>\n    result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n    a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">while</span> a <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">:</span>\n        result<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span>\n        a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> b<span class=\"token punctuation\">,</span> a<span class=\"token operator\">+</span>b\n    <span class=\"token keyword\">return</span> result</code></pre></div>\n<p>Now enter the Python interpreter and import this module with the following command:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> fibo.fib(1000)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987\n>>> fibo.fib2(100)\n[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n>>> fibo.__name__\n'fibo'</code></pre></div>\n<p>This does not enter the names of the functions defined in <code class=\"language-text\">fibo</code> directly in the current symbol table; it only enters the module name <code class=\"language-text\">fibo</code> there. Using the module name you can access the functions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> fib = fibo.fib\n>>> fib(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<p>If you intend to use a function often you can assign it to a local name:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> from fibo import fib, fib2\n>>> fib(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<h2>6.1. More on Modules<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#more-on-modules\" title=\"Permalink to this headline\"></a></h2>\n<p>A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the <em>first</em> time the module name is encountered in an import statement. <a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#id2\">1</a> (They are also run if the file is executed as a script.)</p>\n<p>Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. Thus, the author of a module can use global variables in the module without worrying about accidental clashes with a user’s global variables. On the other hand, if you know what you are doing you can touch a module’s global variables with the same notation used to refer to its functions, <code class=\"language-text\">modname.itemname</code>.</p>\n<p>Modules can import other modules. It is customary but not required to place all <a href=\"https://docs.python.org/3/reference/simple_stmts.html#import\"><code class=\"language-text\">import</code></a> statements at the beginning of a module (or script, for that matter). The imported module names are placed in the importing module’s global symbol table.</p>\n<p>There is a variant of the <a href=\"https://docs.python.org/3/reference/simple_stmts.html#import\"><code class=\"language-text\">import</code></a> statement that imports names from a module directly into the importing module’s symbol table. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> from fibo import *\n>>> fib(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<p>This does not introduce the module name from which the imports are taken in the local symbol table (so in the example, <code class=\"language-text\">fibo</code> is not defined).</p>\n<p>There is even a variant to import all names that a module defines:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import fibo as fib\n>>> fib.fib(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<p>This imports all names except those beginning with an underscore (<code class=\"language-text\">_</code>). In most cases Python programmers do not use this facility since it introduces an unknown set of names into the interpreter, possibly hiding some things you have already defined.</p>\n<p>Note that in general the practice of importing <code class=\"language-text\">*</code> from a module or package is frowned upon, since it often causes poorly readable code. However, it is okay to use it to save typing in interactive sessions.</p>\n<p>If the module name is followed by <code class=\"language-text\">as</code>, then the name following <code class=\"language-text\">as</code> is bound directly to the imported module.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> from fibo import fib as fibonacci\n>>> fibonacci(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<p>This is effectively importing the module in the same way that <code class=\"language-text\">import fibo</code> will do, with the only difference of it being available as <code class=\"language-text\">fib</code>.</p>\n<p>It can also be used when utilising <a href=\"https://docs.python.org/3/reference/simple_stmts.html#from\"><code class=\"language-text\">from</code></a> with similar effects:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Note</p>\n<p>For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter – or, if it’s just one module you want to test interactively, use <a href=\"https://docs.python.org/3/library/importlib.html#importlib.reload\" title=\"importlib.reload\"><code class=\"language-text\">importlib.reload()</code></a>, e.g. <code class=\"language-text\">import importlib; importlib.reload(modulename)</code>.</p>\n<h3>6.1.1. Executing modules as scripts<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#executing-modules-as-scripts\" title=\"Permalink to this headline\">¶</a></h3>\n<p>When you run a Python module with</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">python fibo.py &lt;arguments></code></pre></div>\n<p>the code in the module will be executed, just as if you imported it, but with the <code class=\"language-text\">__name__</code> set to <code class=\"language-text\">\"__main__\"</code>. That means that by adding this code at the end of your module:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if __name__ == \"__main__\":\n    import sys\n    fib(int(sys.argv[1]))</code></pre></div>\n<p>you can make the file usable as a script as well as an importable module, because the code that parses the command line only runs if the module is executed as the “main” file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ python fibo.py 50\n0 1 1 2 3 5 8 13 21 34</code></pre></div>\n<p>If the module is imported, the code is not run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import fibo\n>>></code></pre></div>\n<p>This is often used either to provide a convenient user interface to a module, or for testing purposes (running the module as a script executes a test suite).</p>\n<h3>6.1.2. The Module Search Path<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#the-module-search-path\" title=\"Permalink to this headline\">¶</a></h3>\n<p>When a module named <code class=\"language-text\">spam</code> is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named <code class=\"language-text\">spam.py</code> in a list of directories given by the variable <a href=\"https://docs.python.org/3/library/sys.html#sys.path\" title=\"sys.path\"><code class=\"language-text\">sys.path</code></a>. <a href=\"https://docs.python.org/3/library/sys.html#sys.path\" title=\"sys.path\"><code class=\"language-text\">sys.path</code></a> is initialized from these locations:</p>\n<ul>\n<li>The directory containing the input script (or the current directory when no file is specified).</li>\n<li><a href=\"https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH\"><code class=\"language-text\">PYTHONPATH</code></a> (a list of directory names, with the same syntax as the shell variable <code class=\"language-text\">PATH</code>).</li>\n<li>The installation-dependent default.</li>\n</ul>\n<p>Note</p>\n<p>On file systems which support symlinks, the directory containing the input script is calculated after the symlink is followed. In other words the directory containing the symlink is <strong>not</strong> added to the module search path.</p>\n<p>After initialization, Python programs can modify <a href=\"https://docs.python.org/3/library/sys.html#sys.path\" title=\"sys.path\"><code class=\"language-text\">sys.path</code></a>. The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended. See section <a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#tut-standardmodules\">Standard Modules</a> for more information.</p>\n<h3>6.1.3. “Compiled” Python files<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#compiled-python-files\" title=\"Permalink to this headline\">¶</a></h3>\n<p>To speed up loading modules, Python caches the compiled version of each module in the <code class=\"language-text\">__pycache__</code> directory under the name <code class=\"language-text\">module.version.pyc</code>, where the version encodes the format of the compiled file; it generally contains the Python version number. For example, in CPython release 3.3 the compiled version of spam.py would be cached as <code class=\"language-text\">__pycache__/spam.cpython-33.pyc</code>. This naming convention allows compiled modules from different releases and different versions of Python to coexist.</p>\n<p>Python checks the modification date of the source against the compiled version to see if it’s out of date and needs to be recompiled. This is a completely automatic process. Also, the compiled modules are platform-independent, so the same library can be shared among systems with different architectures.</p>\n<p>Python does not check the cache in two circumstances. First, it always recompiles and does not store the result for the module that’s loaded directly from the command line. Second, it does not check the cache if there is no source module. To support a non-source (compiled only) distribution, the compiled module must be in the source directory, and there must not be a source module.</p>\n<p>Some tips for experts:</p>\n<ul>\n<li>You can use the <a href=\"https://docs.python.org/3/using/cmdline.html#cmdoption-o\"><code class=\"language-text\">-O</code></a> or <a href=\"https://docs.python.org/3/using/cmdline.html#cmdoption-oo\"><code class=\"language-text\">-OO</code></a> switches on the Python command to reduce the size of a compiled module. The <code class=\"language-text\">-O</code> switch removes assert statements, the <code class=\"language-text\">-OO</code> switch removes both assert statements and __doc__ strings. Since some programs may rely on having these available, you should only use this option if you know what you’re doing. “Optimized” modules have an <code class=\"language-text\">opt-</code> tag and are usually smaller. Future releases may change the effects of optimization.</li>\n<li>A program doesn’t run any faster when it is read from a <code class=\"language-text\">.pyc</code> file than when it is read from a <code class=\"language-text\">.py</code> file; the only thing that’s faster about <code class=\"language-text\">.pyc</code> files is the speed with which they are loaded.</li>\n<li>The module <a href=\"https://docs.python.org/3/library/compileall.html#module-compileall\" title=\"compileall: Tools for byte-compiling all Python source files in a directory tree.\"><code class=\"language-text\">compileall</code></a> can create .pyc files for all modules in a directory.</li>\n<li>There is more detail on this process, including a flow chart of the decisions, in <strong><a href=\"https://www.python.org/dev/peps/pep-3147\">PEP 3147</a></strong>.</li>\n</ul>\n<h2>6.2. Standard Modules<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#standard-modules\" title=\"Permalink to this headline\">¶</a></h2>\n<p>Python comes with a library of standard modules, described in a separate document, the Python Library Reference (“Library Reference” hereafter). Some modules are built into the interpreter; these provide access to operations that are not part of the core of the language but are nevertheless built in, either for efficiency or to provide access to operating system primitives such as system calls. The set of such modules is a configuration option which also depends on the underlying platform. For example, the <a href=\"https://docs.python.org/3/library/winreg.html#module-winreg\" title=\"winreg: Routines and objects for manipulating the Windows registry. (Windows)\"><code class=\"language-text\">winreg</code></a> module is only provided on Windows systems. One particular module deserves some attention: <a href=\"https://docs.python.org/3/library/sys.html#module-sys\" title=\"sys: Access system-specific parameters and functions.\"><code class=\"language-text\">sys</code></a>, which is built into every Python interpreter. The variables <code class=\"language-text\">sys.ps1</code> and <code class=\"language-text\">sys.ps2</code> define the strings used as primary and secondary prompts:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import sys\n>>> sys.ps1\n'>>> '\n>>> sys.ps2\n'... '\n>>> sys.ps1 = 'C> '\nC> print('Yuck!')\nYuck!\nC></code></pre></div>\n<p>These two variables are only defined if the interpreter is in interactive mode.</p>\n<p>The variable <code class=\"language-text\">sys.path</code> is a list of strings that determines the interpreter’s search path for modules. It is initialized to a default path taken from the environment variable <a href=\"https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH\"><code class=\"language-text\">PYTHONPATH</code></a>, or from a built-in default if <a href=\"https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH\"><code class=\"language-text\">PYTHONPATH</code></a> is not set. You can modify it using standard list operations:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import sys\n>>> sys.path.append('/ufs/guido/lib/python')</code></pre></div>\n<h2>6.3. The <a href=\"https://docs.python.org/3/library/functions.html#dir\" title=\"dir\"><code class=\"language-text\">dir()</code></a> Function<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#the-dir-function\" title=\"Permalink to this headline\">¶</a></h2>\n<p>The built-in function <a href=\"https://docs.python.org/3/library/functions.html#dir\" title=\"dir\"><code class=\"language-text\">dir()</code></a> is used to find out which names a module defines. It returns a sorted list of strings:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> fibo<span class=\"token punctuation\">,</span> sys\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">dir</span><span class=\"token punctuation\">(</span>fibo<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'__name__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'fib'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'fib2'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">dir</span><span class=\"token punctuation\">(</span>sys<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'__breakpointhook__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__displayhook__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__doc__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__excepthook__'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'__interactivehook__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__loader__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__name__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__package__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__spec__'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'__stderr__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__stdin__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__stdout__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__unraisablehook__'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'_clear_type_cache'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_current_frames'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_debugmallocstats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_framework'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'_getframe'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_git'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_home'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_xoptions'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'abiflags'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'addaudithook'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'api_version'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'argv'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'audit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'base_exec_prefix'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'base_prefix'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'breakpointhook'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'builtin_module_names'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'byteorder'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'call_tracing'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'callstats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'copyright'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'displayhook'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dont_write_bytecode'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'exc_info'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'excepthook'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'exec_prefix'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'executable'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'exit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'flags'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'float_info'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'float_repr_style'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'get_asyncgen_hooks'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'get_coroutine_origin_tracking_depth'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'getallocatedblocks'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getdefaultencoding'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getdlopenflags'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'getfilesystemencodeerrors'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getfilesystemencoding'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getprofile'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'getrecursionlimit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getrefcount'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getsizeof'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getswitchinterval'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'gettrace'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hash_info'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hexversion'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'implementation'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'int_info'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'intern'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is_finalizing'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'last_traceback'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'last_type'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'last_value'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'maxsize'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'maxunicode'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'meta_path'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'modules'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'path'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'path_hooks'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'path_importer_cache'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'platform'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'prefix'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'ps1'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'ps2'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pycache_prefix'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'set_asyncgen_hooks'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'set_coroutine_origin_tracking_depth'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'setdlopenflags'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'setprofile'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'setrecursionlimit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'setswitchinterval'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'settrace'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'stderr'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'stdin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'stdout'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'thread_info'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'unraisablehook'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'version'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'version_info'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'warnoptions'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Without arguments, <a href=\"https://docs.python.org/3/library/functions.html#dir\" title=\"dir\"><code class=\"language-text\">dir()</code></a> lists the names you have defined currently:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> a = [1, 2, 3, 4, 5]\n>>> import fibo\n>>> fib = fibo.fib\n>>> dir()\n['__builtins__', '__name__', 'a', 'fib', 'fibo', 'sys']</code></pre></div>\n<p>Note that it lists all types of names: variables, modules, functions, etc.</p>\n<p><a href=\"https://docs.python.org/3/library/functions.html#dir\" title=\"dir\"><code class=\"language-text\">dir()</code></a> does not list the names of built-in functions and variables. If you want a list of those, they are defined in the standard module <a href=\"https://docs.python.org/3/library/builtins.html#module-builtins\" title=\"builtins: The module that provides the built-in namespace.\"><code class=\"language-text\">builtins</code></a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import builtins\n>>> dir(builtins)\n['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',\n 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning',\n 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError',\n 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning',\n 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False',\n 'FileExistsError', 'FileNotFoundError', 'FloatingPointError',\n 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError',\n 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError',\n 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError',\n 'MemoryError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented',\n 'NotImplementedError', 'OSError', 'OverflowError',\n 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError',\n 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning',\n 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError',\n 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError',\n 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError',\n 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning',\n 'ValueError', 'Warning', 'ZeroDivisionError', '_', '__build_class__',\n '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs',\n 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable',\n 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits',\n 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit',\n 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr',\n 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass',\n 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview',\n 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property',\n 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice',\n 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars',\n 'zip']</code></pre></div>\n<h2>6.4. Packages<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#packages\" title=\"Permalink to this headline\">¶</a></h2>\n<p>Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name <code class=\"language-text\">A.B</code> designates a submodule named <code class=\"language-text\">B</code> in a package named <code class=\"language-text\">A</code>. Just like the use of modules saves the authors of different modules from having to worry about each other’s global variable names, the use of dotted module names saves the authors of multi-module packages like NumPy or Pillow from having to worry about each other’s module names.</p>\n<p>Suppose you want to design a collection of modules (a “package”) for the uniform handling of sound files and sound data. There are many different sound file formats (usually recognized by their extension, for example: <code class=\"language-text\">.wav</code>, <code class=\"language-text\">.aiff</code>, <code class=\"language-text\">.au</code>), so you may need to create and maintain a growing collection of modules for the conversion between the various file formats. There are also many different operations you might want to perform on sound data (such as mixing, adding echo, applying an equalizer function, creating an artificial stereo effect), so in addition you will be writing a never-ending stream of modules to perform these operations. Here’s a possible structure for your package (expressed in terms of a hierarchical filesystem):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sound/                          Top-level package\n      __init__.py               Initialize the sound package\n      formats/                  Subpackage for file format conversions\n              __init__.py\n              wavread.py\n              wavwrite.py\n              aiffread.py\n              aiffwrite.py\n              auread.py\n              auwrite.py\n              ...\n      effects/                  Subpackage for sound effects\n              __init__.py\n              echo.py\n              surround.py\n              reverse.py\n              ...\n      filters/                  Subpackage for filters\n              __init__.py\n              equalizer.py\n              vocoder.py\n              karaoke.py\n              ...</code></pre></div>\n<p>When importing the package, Python searches through the directories on <code class=\"language-text\">sys.path</code> looking for the package subdirectory.</p>\n<p>The <code class=\"language-text\">__init__.py</code> files are required to make Python treat directories containing the file as packages. This prevents directories with a common name, such as <code class=\"language-text\">string</code>, unintentionally hiding valid modules that occur later on the module search path. In the simplest case, <code class=\"language-text\">__init__.py</code> can just be an empty file, but it can also execute initialization code for the package or set the <code class=\"language-text\">__all__</code> variable, described later.</p>\n<p>Users of the package can import individual modules from the package, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import sound.effects.echo</code></pre></div>\n<p>This loads the submodule <code class=\"language-text\">sound.effects.echo</code>. It must be referenced with its full name.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)</code></pre></div>\n<p>An alternative way of importing the submodule is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from sound.effects import echo</code></pre></div>\n<p>This also loads the submodule <code class=\"language-text\">echo</code>, and makes it available without its package prefix, so it can be used as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">echo.echofilter(input, output, delay=0.7, atten=4)</code></pre></div>\n<p>Yet another variation is to import the desired function or variable directly:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from sound.effects.echo import echofilter</code></pre></div>\n<p>Again, this loads the submodule <code class=\"language-text\">echo</code>, but this makes its function <code class=\"language-text\">echofilter()</code> directly available:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">echofilter(input, output, delay=0.7, atten=4)</code></pre></div>\n<p>Note that when using <code class=\"language-text\">from package import item</code>, the item can be either a submodule (or subpackage) of the package, or some other name defined in the package, like a function, class or variable. The <code class=\"language-text\">import</code> statement first tests whether the item is defined in the package; if not, it assumes it is a module and attempts to load it. If it fails to find it, an <a href=\"https://docs.python.org/3/library/exceptions.html#ImportError\" title=\"ImportError\"><code class=\"language-text\">ImportError</code></a> exception is raised.</p>\n<p>Contrarily, when using syntax like <code class=\"language-text\">import item.subitem.subsubitem</code>, each item except for the last must be a package; the last item can be a module or a package but can’t be a class or function or variable defined in the previous item.</p>\n<h3>6.4.1. Importing * From a Package<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#importing-from-a-package\" title=\"Permalink to this headline\">¶</a></h3>\n<p>Now what happens when the user writes <code class=\"language-text\">from sound.effects import *</code>? Ideally, one would hope that this somehow goes out to the filesystem, finds which submodules are present in the package, and imports them all. This could take a long time and importing sub-modules might have unwanted side-effects that should only happen when the sub-module is explicitly imported.</p>\n<p>The only solution is for the package author to provide an explicit index of the package. The <a href=\"https://docs.python.org/3/reference/simple_stmts.html#import\"><code class=\"language-text\">import</code></a> statement uses the following convention: if a package’s <code class=\"language-text\">__init__.py</code> code defines a list named <code class=\"language-text\">__all__</code>, it is taken to be the list of module names that should be imported when <code class=\"language-text\">from package import *</code> is encountered. It is up to the package author to keep this list up-to-date when a new version of the package is released. Package authors may also decide not to support it, if they don’t see a use for importing * from their package. For example, the file <code class=\"language-text\">sound/effects/__init__.py</code> could contain the following code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">__all__ = [\"echo\", \"surround\", \"reverse\"]</code></pre></div>\n<p>This would mean that <code class=\"language-text\">from sound.effects import *</code> would import the three named submodules of the <code class=\"language-text\">sound</code> package.</p>\n<p>If <code class=\"language-text\">__all__</code> is not defined, the statement <code class=\"language-text\">from sound.effects import *</code> does <em>not</em> import all submodules from the package <code class=\"language-text\">sound.effects</code> into the current namespace; it only ensures that the package <code class=\"language-text\">sound.effects</code> has been imported (possibly running any initialization code in <code class=\"language-text\">__init__.py</code>) and then imports whatever names are defined in the package. This includes any names defined (and submodules explicitly loaded) by <code class=\"language-text\">__init__.py</code>. It also includes any submodules of the package that were explicitly loaded by previous <a href=\"https://docs.python.org/3/reference/simple_stmts.html#import\"><code class=\"language-text\">import</code></a> statements. Consider this code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import sound.effects.echo\nimport sound.effects.surround\nfrom sound.effects import *</code></pre></div>\n<p>In this example, the <code class=\"language-text\">echo</code> and <code class=\"language-text\">surround</code> modules are imported in the current namespace because they are defined in the <code class=\"language-text\">sound.effects</code> package when the <code class=\"language-text\">from...import</code> statement is executed. (This also works when <code class=\"language-text\">__all__</code> is defined.)</p>\n<p>Although certain modules are designed to export only names that follow certain patterns when you use <code class=\"language-text\">import *</code>, it is still considered bad practice in production code.</p>\n<p>Remember, there is nothing wrong with using <code class=\"language-text\">from package import specific_submodule</code>! In fact, this is the recommended notation unless the importing module needs to use submodules with the same name from different packages.</p>\n<h3>6.4.2. Intra-package References<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#intra-package-references\" title=\"Permalink to this headline\">¶</a></h3>\n<p>When packages are structured into subpackages (as with the <code class=\"language-text\">sound</code> package in the example), you can use absolute imports to refer to submodules of siblings packages. For example, if the module <code class=\"language-text\">sound.filters.vocoder</code> needs to use the <code class=\"language-text\">echo</code> module in the <code class=\"language-text\">sound.effects</code> package, it can use <code class=\"language-text\">from sound.effects import echo</code>.</p>\n<p>You can also write relative imports, with the <code class=\"language-text\">from module import name</code> form of import statement. These imports use leading dots to indicate the current and parent packages involved in the relative import. From the <code class=\"language-text\">surround</code> module for example, you might use:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Note that relative imports are based on the name of the current module. Since the name of the main module is always <code class=\"language-text\">\"__main__\"</code>, modules intended for use as the main module of a Python application must always use absolute imports.</p>\n<h3>6.4.3. Packages in Multiple Directories<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#packages-in-multiple-directories\" title=\"Permalink to this headline\">¶</a></h3>\n<p>Packages support one more special attribute, <a href=\"https://docs.python.org/3/reference/import.html#__path__\" title=\"__path__\"><code class=\"language-text\">path</code></a>. This is initialized to be a list containing the name of the directory holding the package’s <code class=\"language-text\">__init__.py</code> before the code in that file is executed. This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.</p>\n<p>While this feature is not often needed, it can be used to extend the set of modules found in a package.</p>\n<p>Footnotes</p>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#id1\">1</a><br>\nIn fact function definitions are also ‘statements’ that are ‘executed’; the execution of a module-level function definition enters the function name in the module’s global symbol table.</p>\n<h3><a href=\"https://docs.python.org/3/contents.html\">Table of Contents</a></h3>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#\">6. Modules</a></p>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#more-on-modules\">6.1. More on Modules</a></p>\n<ul>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#executing-modules-as-scripts\">6.1.1. Executing modules as scripts</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#the-module-search-path\">6.1.2. The Module Search Path</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#compiled-python-files\">6.1.3. “Compiled” Python files</a></li>\n</ul>\n</li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#standard-modules\">6.2. Standard Modules</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#the-dir-function\">6.3. The <code class=\"language-text\">dir()</code> Function</a></li>\n<li>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#packages\">6.4. Packages</a></p>\n<ul>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#importing-from-a-package\">6.4.1. Importing * From a Package</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#intra-package-references\">6.4.2. Intra-package References</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#packages-in-multiple-directories\">6.4.3. Packages in Multiple Directories</a></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<h4>Previous topic</h4>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/datastructures.html\" title=\"previous chapter\">5. Data Structures</a></p>\n<h4>Next topic</h4>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/inputoutput.html\" title=\"next chapter\">7. Input and Output</a></p>\n<h3>This Page</h3>\n<ul>\n<li><a href=\"https://docs.python.org/3/bugs.html\">Report a Bug</a></li>\n<li><a href=\"https://github.com/python/cpython/blob/3.9/Doc/tutorial/modules.rst\">Show Source</a></li>\n</ul>\n<h3>Navigation</h3>\n<ul>\n<li><a href=\"https://docs.python.org/3/genindex.html\" title=\"General Index\">index</a></li>\n<li><a href=\"https://docs.python.org/3/py-modindex.html\" title=\"Python Module Index\">modules</a> |</li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/inputoutput.html\" title=\"7. Input and Output\">next</a> |</li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/datastructures.html\" title=\"5. Data Structures\">previous</a> |</li>\n<li><img src=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/_static/py.png\" alt=\"image\"></li>\n<li><a href=\"https://www.python.org/\">Python</a> »</li>\n<li><a href=\"https://docs.python.org/3/index.html\">3.9.5 Documentation</a> »</li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/index.html\">The Python Tutorial</a> »</li>\n<li>-</li>\n</ul>"},{"url":"/docs/python/intro-for-js-devs/","relativePath":"docs/python/intro-for-js-devs.md","relativeDir":"docs/python","base":"intro-for-js-devs.md","name":"intro-for-js-devs","frontmatter":{"title":"lorem-ipsum","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Lorem ipsum</h2>\n<p>Lorem ipsum dolor sit amet, <strong>consectetur adipiscing elit</strong>, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>\n<ul>\n<li>Lorem ipsum</li>\n<li>dolor sit amet</li>\n</ul>"},{"url":"/docs/quick-ref/Emmet/","relativePath":"docs/quick-ref/Emmet.md","relativeDir":"docs/quick-ref","base":"Emmet.md","name":"Emmet","frontmatter":{"title":"Emmet Cheat Sheet","excerpt":"In this section you'll find basic information about Web-Dev-Huband how to use it.","seo":{"title":"Emmet Cheat Sheet","description":"This is the Emmet Cheat Sheet page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Emmet Cheat Sheet","keyName":"property"},{"name":"og:description","value":"This is the Emmet Cheat Sheet page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Emmet Cheat Sheet"},{"name":"twitter:description","value":"This is the Emmet Cheat Sheet page"}]},"template":"docs"},"html":"<h1>Emmet Cheat Sheet</h1>\n<p>EMMET</p>\n<hr>\n<h3>Emmet Cheat Sheet</h3>\n<h3>EMMET</h3>\n<p><em>The a toolkit for web-developers</em></p>\n<h3>Introduction</h3>\n<p>Emmet is a productivity toolkit for web developers that uses expressions to generate HTML snippets.</p>\n<h3>Installation</h3>\n<p>Normally, installation for Emmet should be a straight-forward process from the package-manager, as most of the modern text editors support Emmet.</p>\n<h3>Usage</h3>\n<p>You can use Emmet in two ways:</p>\n<ul>\n<li><span id=\"856f\">Tab Expand Way: Type your emmet code and press <code class=\"language-text\">Tab</code> key</span></li>\n<li><span id=\"9aea\">Interactive Method: Press <code class=\"language-text\">alt + ctrl + Enter</code> and start typing your expressions. This should automatically generate HTML snippets on the fly.</span></li>\n</ul>\n<p><strong>This cheatsheet will assume that you press</strong><code class=\"language-text\">Tab</code><strong>after each expressions.</strong></p>\n<h3>HTML</h3>\n<h3>Generating HTML 5 DOCTYPE</h3>\n<p><code class=\"language-text\">html:5</code></p>\n<p>Will generate</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n  &lt;meta charset=\"UTF-8\">\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  &lt;meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">\n  &lt;title>Document&lt;/title>\n&lt;/head>\n&lt;body>\n\n&lt;/body>\n&lt;/html></code></pre></div>\n<h3>Child items</h3>\n<p>Child items are created using <code class=\"language-text\">></code></p>\n<p><code class=\"language-text\">ul>li>p</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;ul>\n  &lt;li>\n    &lt;p></code></pre></div>\n</p>\n      </li>\n    </ul>\n<h3>Sibling Items</h3>\n<p>Sibling items are created using <code class=\"language-text\">+</code></p>\n<p><code class=\"language-text\">html>head+body</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;html>\n&lt;head></code></pre></div>\n</head>\n    <body>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;/body>\n&lt;/html></code></pre></div>\n<h3>Multiplication</h3>\n<p>Items can be multiplied by <code class=\"language-text\">*</code></p>\n<p><code class=\"language-text\">ul>li*5</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;ul>\n  &lt;li></code></pre></div>\n</li>\n      <li>\n</li>\n      <li>\n</li>\n      <li>\n</li>\n      <li>\n</li>\n    </ul>\n<h3>Grouping</h3>\n<p>Items can be grouped together using <code class=\"language-text\">()</code></p>\n<p><code class=\"language-text\">table>(tr>th*5)+tr>t*5</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;table>\n  &lt;tr>\n    &lt;th></code></pre></div>\n</th>\n        <th>\n</th>\n        <th>\n</th>\n        <th>\n</th>\n        <th>\n</th>\n      </tr>\n      <tr>\n        <t>\n</t>\n        <t>\n</t>\n        <t>\n</t>\n        <t>\n</t>\n        <t>\n</t>\n      </tr>\n    </table>\n<h3>Class and ID</h3>\n<p>Class and Id in Emmet can be done using <code class=\"language-text\">.</code> and <code class=\"language-text\">#</code></p>\n<p><code class=\"language-text\">div.heading</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"heading\"></code></pre></div>\n</div>\n<p><code class=\"language-text\">div#heading</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div id=\"heading\"></code></pre></div>\n</div>\n<p>ID and Class can also be combined together</p>\n<p><code class=\"language-text\">div#heading.center</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div id=\"heading\" class=\"center\"></code></pre></div>\n</div>\n<h3>Adding Content inside tags</h3>\n<p>Contents inside tags can be added using <code class=\"language-text\">{}</code></p>\n<p><code class=\"language-text\">h1{Emmet is awesome}+h2{Every front end developers should use this}+p{This is paragraph}*2</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;h1>Emmet is awesome&lt;/h1>\n&lt;h2>Every front end developers should use this&lt;/h2>\n&lt;p>This is paragraph&lt;/p>\n&lt;p>This is paragraph&lt;/p></code></pre></div>\n<h3>Attributes inside HTML tags</h3>\n<p>Attributes can be added using <code class=\"language-text\">[]</code></p>\n<p><code class=\"language-text\">a[href=https://?google.com data-toggle=something target=_blank]</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;a href=\"https://?google.com\" data-toggle=\"something\" target=\"_blank\"></code></pre></div>\n</a>\n<h3>Numbering</h3>\n<p>Numbering can be done using <code class=\"language-text\">$</code></p>\n<p>You can use this inside tag or contents.</p>\n<p><code class=\"language-text\">h${This is so awesome $}*6</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;h1>This is so awesome 1&lt;/h1>\n&lt;h2>This is so awesome 2&lt;/h2>\n&lt;h3>This is so awesome 3&lt;/h3>\n&lt;h4>This is so awesome 4&lt;/h4>\n&lt;h5>This is so awesome 5&lt;/h5>\n&lt;h6>This is so awesome 6&lt;/h6></code></pre></div>\n<p>Use <code class=\"language-text\">@-</code> to reverse the Numbering</p>\n<p><code class=\"language-text\">img[src=image$$@-.jpg]*5</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;img src=\"image05.jpg\" alt=\"\">\n&lt;img src=\"image04.jpg\" alt=\"\">\n&lt;img src=\"image03.jpg\" alt=\"\">\n&lt;img src=\"image02.jpg\" alt=\"\">\n&lt;img src=\"image01.jpg\" alt=\"\"></code></pre></div>\n<p>To start the numbering from specific number, use this way</p>\n<p><code class=\"language-text\">img[src=emmet$@100.jpg]*5</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;img src=\"emmet100.jpg\" alt=\"\">\n&lt;img src=\"emmet101.jpg\" alt=\"\">\n&lt;img src=\"emmet102.jpg\" alt=\"\">\n&lt;img src=\"emmet103.jpg\" alt=\"\">\n&lt;img src=\"emmet104.jpg\" alt=\"\"></code></pre></div>\n<h3>Tips</h3>\n<ul>\n<li><span id=\"b708\">Use <code class=\"language-text\">:</code> to expand known abbreviations</span></li>\n</ul>\n<p><code class=\"language-text\">input:date</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;input type=\"date\" name=\"\" id=\"\"></code></pre></div>\n<p><code class=\"language-text\">form:post</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;form action=\"\" method=\"post\"></code></pre></div>\n</form>\n<p><code class=\"language-text\">link:css</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;link rel=\"stylesheet\" href=\"style.css\"></code></pre></div>\n<ul>\n<li><span id=\"d43e\">Building Navbar</span></li>\n</ul>\n<p><code class=\"language-text\">.navbar>ul>li*3>a[href=#]{Item $@-}</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"navbar\">\n  &lt;ul>\n    &lt;li></code></pre></div>\n<p><a href=\"#\">Item 3</a></p>\n</li>\n        <li>\n<a href=\"#\">Item 2</a>\n</li>\n        <li>\n<a href=\"#\">Item 1</a>\n</li>\n      </ul>\n    </div>\n<h3>CSS</h3>\n<p>Emmet works surprisingly well with css as well.</p>\n<ul>\n<li><span id=\"68eb\"><code class=\"language-text\">f:l</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">float: left;</code></pre></div>\n<p>You can also use any options n/r/l</p>\n<ul>\n<li><span id=\"d9cc\"><code class=\"language-text\">pos:a­</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">position: absolute;</code></pre></div>\n<p>Also use any options, pos:a/r/f</p>\n<ul>\n<li><span id=\"5b67\"><code class=\"language-text\">d:n/b­/f/­i/ib</code></span></li>\n</ul>\n<p><code class=\"language-text\">d:ib</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">display: inline-block;</code></pre></div>\n<ul>\n<li><span id=\"26f6\">You can use <code class=\"language-text\">m</code> for margin and <code class=\"language-text\">p</code> for padding followed by direction</span></li>\n</ul>\n<p><code class=\"language-text\">mr</code> -> <code class=\"language-text\">margin-right</code></p>\n<p><code class=\"language-text\">pr</code> -> <code class=\"language-text\">padding-right</code></p>\n<ul>\n<li><span id=\"01cc\"><code class=\"language-text\">@f</code> will result in</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">@font-face {\n  font-family:;\n  src:url();\n}</code></pre></div>\n<p>You can also use these shorthands</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*h8hsUrJNyVRLYqBQP63DCA.png\" class=\"graf-image\" />\n</figure>#### If you found this guide helpful feel free to checkout my github/gists where I host similar content:\n<p><a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--p-anchor\">bgoonz's gists · GitHub</a></p>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>Or Checkout my personal Resource Site:</p>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\">\n<strong>a/A-Student-Resources</strong>\n<br />\n<em>Edit description</em>goofy-euclid-1cd736.netlify.app</a>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/24758e628d37\">March 6, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/emmet-cheat-sheet-24758e628d37\" class=\"p-canonical\">Canonical link</a></p>\n<p>May 23, 2021.</p>"},{"url":"/docs/python/python-ds/","relativePath":"docs/python/python-ds.md","relativeDir":"docs/python","base":"python-ds.md","name":"python-ds","frontmatter":{"title":"Python General Notes","weight":0,"excerpt":"Python General Notes & Resources","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Python Notes</h2>\n<table>\n<thead>\n<tr>\n<th align=\"center\"><a href=\"https://lambda-6.gitbook.io/python/\">https://lambda-6.gitbook.io/python/</a></th>\n<th align=\"left\">This Gitbook As A Website</th>\n</tr>\n</thead>\n<tbody>\n</tbody>\n</table>\n<blockquote>\n<hr>\n<p><a href=\"https://ds-unit-5-lambda.netlify.app/\"><strong><em>https://ds-unit-5-lambda.netlify.app</em></strong></a></p>\n<p><strong><em>/</em></strong></p>\n</blockquote>\n<blockquote>\n<hr>\n<p><a href=\"https://bryan-guner.gitbook.io/datastructures-in-pytho/\"><strong><em>https://bryan-guner.gitbook.io/datastructures-in-pytho/</em></strong></a></p>\n<hr>\n</blockquote>\n<blockquote>\n<hr>\n<hr>\n<p><a href=\"https://replit.com/@bgoonz/DATASTRUCPYTHONNOTES-2\"><strong><em>https://replit.com/@bgoonz/DATASTRUCPYTHONNOTES-2</em></strong></a></p>\n</blockquote>\n<p><strong>Keywords</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">**</span><span class=\"token operator\">*</span><span class=\"token keyword\">and</span>       <span class=\"token keyword\">del</span>       <span class=\"token keyword\">for</span>       <span class=\"token keyword\">is</span>        <span class=\"token keyword\">raise</span>\n<span class=\"token keyword\">assert</span>    <span class=\"token keyword\">elif</span>      <span class=\"token keyword\">from</span>      <span class=\"token keyword\">lambda</span>    <span class=\"token keyword\">return</span>\n<span class=\"token keyword\">break</span>     <span class=\"token keyword\">else</span>      <span class=\"token keyword\">global</span>    <span class=\"token keyword\">not</span>       <span class=\"token keyword\">try</span>\n<span class=\"token keyword\">class</span>     <span class=\"token class-name\">except</span>    <span class=\"token keyword\">if</span>        <span class=\"token keyword\">or</span>        <span class=\"token keyword\">while</span>\n<span class=\"token keyword\">continue</span>  <span class=\"token keyword\">exec</span>      <span class=\"token keyword\">import</span>    <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">def</span>       <span class=\"token keyword\">finally</span>   <span class=\"token keyword\">in</span>        <span class=\"token keyword\">print</span><span class=\"token operator\">**</span><span class=\"token operator\">*</span></code></pre></div>\n<p><a href=\"https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1c25bca5-0198-42ad-aa8b-7668cb904571/py-notes.pdf\">py-notes.pdf</a></p>\n<p><a href=\"https://bryan-guner.gitbook.io/notesarchive/\">https://bryan-guner.gitbook.io/notesarchive/</a></p>\n<h2>DOCS:</h2>\n<p><a href=\"https://docs.python.org/3/\">https://docs.python.org/3/</a></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> math\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">say_hi</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"&lt;---- Multi-Line Comments and Docstrings\n    This is where you put your content for help() to inform the user\n    about what your function does and how to use it\n    \"\"\"</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"Hello </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span></span><span class=\"token string\">!\"</span></span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>say_hi<span class=\"token punctuation\">(</span><span class=\"token string\">\"Bryan\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Should get the print inside the function, then None</span>\n<span class=\"token comment\"># Boolean Values</span>\n<span class=\"token comment\"># Work the same as in JS, except they are title case: True and False</span>\na <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span>\nb <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span>\n<span class=\"token comment\"># Logical Operators</span>\n<span class=\"token comment\"># ! = not, || = or, &amp;&amp; = and</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Truthiness - Everything is True except...</span>\n<span class=\"token comment\"># False - None, False, '', [], (), set(), range(0)</span>\n<span class=\"token comment\"># Number Values</span>\n<span class=\"token comment\"># Integers are numbers without a floating decimal point</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># type returns the type of whatever argument you pass in</span>\n<span class=\"token comment\"># Floating Point values are numbers with a floating decimal point</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">3.5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Type Casting</span>\n<span class=\"token comment\"># You can convert between ints and floats (along with other types...)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># If you convert a float to an int, it will truncate the decimal</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token number\">4.5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Python does not automatically convert types like JS</span>\n<span class=\"token comment\"># print(17.0 + ' heyooo ' + 17)  # TypeError</span>\n<span class=\"token comment\"># Arithmetic Operators</span>\n<span class=\"token comment\"># ** - exponent (comparable to Math.pow(num, pow))</span>\n<span class=\"token comment\"># // - integer division</span>\n<span class=\"token comment\"># There is no ++ or -- in Python</span>\n<span class=\"token comment\"># String Values</span>\n<span class=\"token comment\"># We can use single quotes, double quotes, or f'' for string formats</span>\n<span class=\"token comment\"># We can use triple single quotes for multiline strings</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"This here's a story\nAll about how\nMy life got twist\nTurned upside down\n\"\"\"</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Three double quotes can also be used, but we typically reserve these for</span>\n<span class=\"token comment\"># multi-line comments and function docstrings (refer to lines 6-9)(Nice :D)</span>\n<span class=\"token comment\"># We use len() to get the length of something</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Bryan G\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># 7 characters</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"hey\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"ho\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hey\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hey\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"ho\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># 5 list items</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># 8 set items</span>\n<span class=\"token comment\"># We can index into strings, list, etc..self.</span>\nname <span class=\"token operator\">=</span> <span class=\"token string\">\"Bryan\"</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># B, r, y, a, n</span>\n<span class=\"token comment\"># We can index starting from the end as well, with negatives</span>\noccupation <span class=\"token operator\">=</span> <span class=\"token string\">\"Full Stack Software Engineer\"</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># e</span>\n<span class=\"token comment\"># We can also get ranges in the index with the [start:stop:step] syntax</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token number\">4</span><span class=\"token punctuation\">:</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># step and stop are optional, stop is exclusive</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># beginning to end, every 4th letter</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">:</span><span class=\"token number\">14</span><span class=\"token punctuation\">:</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Let's get weird with it!</span>\n<span class=\"token comment\"># NOTE: Indexing out of range will give you an IndexError</span>\n<span class=\"token comment\"># We can also get the index og things with the .index() method, similar to indexOf()</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span><span class=\"token string\">\"Stack\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Barry\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Cole\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"James\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mark\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span><span class=\"token string\">\"Cole\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can count how many times a substring/item appears in something as well</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>occupation<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span><span class=\"token string\">\"S\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"Now this here's a story all about how\nMy life got twist turned upside down\nI forget the rest but the the the potato\nsmells like the potato\"\"\"</span><span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>\n        <span class=\"token string\">\"the\"</span>\n    <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We concatenate the same as Javascript, but we can also multiply strings</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"dog \"</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"show\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"ha\"</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can use format for a multitude of things, from spaces to decimal places</span>\nfirst_name <span class=\"token operator\">=</span> <span class=\"token string\">\"Bryan\"</span>\nlast_name <span class=\"token operator\">=</span> <span class=\"token string\">\"Guner\"</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Your name is {0} {1}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>first_name<span class=\"token punctuation\">,</span> last_name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Useful String Methods</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># HELLO</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># hello</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"HELLO\"</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"HELLO\"</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">\"he\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">\"lo\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello There\"</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># [Hello, There]</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hello1\"</span><span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False,  must consist only of letters</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hello1\"</span><span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True, must consist of only letters and numbers</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"3215235123\"</span><span class=\"token punctuation\">.</span>isdecimal<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True, must be all numbers</span>\n<span class=\"token comment\"># True, must consist of only spaces/tabs/newlines</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"       \\\\n     \"</span><span class=\"token punctuation\">.</span>isspace<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># False, index 0 must be upper case and the rest lower</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Bryan Guner\"</span><span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Michael Lee\"</span><span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True!</span>\n<span class=\"token comment\"># Duck Typing - If it walks like a duck, and talks like a duck, it must be a duck</span>\n<span class=\"token comment\"># Assignment - All like JS, but there are no special keywords like let or const</span>\na <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\nb <span class=\"token operator\">=</span> a\nc <span class=\"token operator\">=</span> <span class=\"token string\">\"heyoo\"</span>\nb <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"reassignment\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"is\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"fine\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"G!\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token comment\"># Comparison Operators - Python uses the same equality operators as JS, but no ===</span>\n<span class=\"token comment\"># &lt; - Less than</span>\n<span class=\"token comment\"># > - Greater than</span>\n<span class=\"token comment\"># &lt;= - Less than or Equal</span>\n<span class=\"token comment\"># >= - Greater than or Equal</span>\n<span class=\"token comment\"># == - Equal to</span>\n<span class=\"token comment\"># != - Not equal to</span>\n<span class=\"token comment\"># is - Refers to exact same memory location</span>\n<span class=\"token comment\"># not - !</span>\n<span class=\"token comment\"># Precedence - Negative Signs(not) are applied first(part of each number)</span>\n<span class=\"token comment\">#            - Multiplication and Division(and) happen next</span>\n<span class=\"token comment\">#            - Addition and Subtraction(or) are the last step</span>\n<span class=\"token comment\">#  NOTE: Be careful when using not along with ==</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">not</span> a <span class=\"token operator\">==</span> b<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token comment\"># print(a == not b) # Syntax Error</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">==</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">not</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># This fixes it. Answer: False</span>\n<span class=\"token comment\"># Python does short-circuit evaluation</span>\n<span class=\"token comment\"># Assignment Operators - Mostly the same as JS except Python has **= and //= (int division)</span>\n<span class=\"token comment\"># Flow Control Statements - if, while, for</span>\n<span class=\"token comment\"># Note: Python smushes 'else if' into 'elif'!</span>\n<span class=\"token keyword\">if</span> <span class=\"token number\">10</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"We don't get here\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> <span class=\"token number\">10</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Nor here...\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hey there!\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Looping over a string</span>\n<span class=\"token keyword\">for</span> c <span class=\"token keyword\">in</span> <span class=\"token string\">\"abcdefgh\"</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Looping over a range</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Looping over a list</span>\nlst <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Looping over a dictionary</span>\nspam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"color\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"age\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"items\"</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hey\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"hooo!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">for</span> v <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Loop over a list of tuples and destructuring the values</span>\n<span class=\"token comment\"># Assuming spam.items returns a list of tuples each containing two items (k, v)</span>\n<span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>k<span class=\"token punctuation\">}</span></span><span class=\"token string\">: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>v<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># While loops as long as the condition is True</span>\n<span class=\"token comment\">#  - Exit loop early with break</span>\n<span class=\"token comment\">#  - Exit iteration early with continue</span>\nspam <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n<span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Sike That's the wrong Numba\"</span><span class=\"token punctuation\">)</span>\n    spam <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">if</span> spam <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">continue</span>\n    <span class=\"token keyword\">break</span>\n\n<span class=\"token comment\"># Functions - use def keyword to define a function in Python</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">printCopyright</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Copyright 2021, Bgoonz\"</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># Lambdas are one liners! (Should be at least, you can use parenthesis to disobey)</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">avg</span><span class=\"token punctuation\">(</span>num1<span class=\"token punctuation\">,</span> num2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>num1 <span class=\"token operator\">+</span> num2<span class=\"token punctuation\">)</span>\n\navg<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Calling it with keyword arguments, order does not matter</span>\navg<span class=\"token punctuation\">(</span>num2<span class=\"token operator\">=</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> num1<span class=\"token operator\">=</span><span class=\"token number\">1252</span><span class=\"token punctuation\">)</span>\nprintCopyright<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can give parameters default arguments like JS</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">greeting</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> saying<span class=\"token operator\">=</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>saying<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">)</span>\n\ngreeting<span class=\"token punctuation\">(</span><span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Hello Mike</span>\ngreeting<span class=\"token punctuation\">(</span><span class=\"token string\">\"Bryan\"</span><span class=\"token punctuation\">,</span> saying<span class=\"token operator\">=</span><span class=\"token string\">\"Hello there...\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># A common gotcha is using a mutable object for a default parameter</span>\n<span class=\"token comment\"># All invocations of the function reference the same mutable object</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">append_item</span><span class=\"token punctuation\">(</span>item_name<span class=\"token punctuation\">,</span> item_list<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>  <span class=\"token comment\"># Will it obey and give us a new list?</span>\n    item_list<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>item_name<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span> item_list\n\n<span class=\"token comment\"># Uses same item list unless otherwise stated which is counterintuitive</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>append_item<span class=\"token punctuation\">(</span><span class=\"token string\">\"notebook\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>append_item<span class=\"token punctuation\">(</span><span class=\"token string\">\"notebook\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>append_item<span class=\"token punctuation\">(</span><span class=\"token string\">\"notebook\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Errors - Unlike JS, if we pass the incorrect amount of arguments to a function,</span>\n<span class=\"token comment\">#          it will throw an error</span>\n<span class=\"token comment\"># avg(1)  # TypeError</span>\n<span class=\"token comment\"># avg(1, 2, 2) # TypeError</span>\n<span class=\"token comment\"># ----------------------------------- DAY 2 ----------------------------------------</span>\n<span class=\"token comment\"># Functions - * to get rest of position arguments as tuple</span>\n<span class=\"token comment\">#           - ** to get rest of keyword arguments as a dictionary</span>\n<span class=\"token comment\"># Variable Length positional arguments</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># args is a tuple of the rest of the arguments</span>\n    total <span class=\"token operator\">=</span> a <span class=\"token operator\">+</span> b\n    <span class=\"token keyword\">for</span> n <span class=\"token keyword\">in</span> args<span class=\"token punctuation\">:</span>\n        total <span class=\"token operator\">+=</span> n\n    <span class=\"token keyword\">return</span> total\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>add<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># args is None, returns 3</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>add<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># args is (3, 4, 5, 6), returns 21</span>\n<span class=\"token comment\"># Variable Length Keyword Arguments</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">print_names_and_countries</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># kwargs is a dictionary of the rest of the keyword arguments</span>\n    <span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> kwargs<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> k<span class=\"token punctuation\">,</span> <span class=\"token string\">\"from\"</span><span class=\"token punctuation\">,</span> v<span class=\"token punctuation\">)</span>\n\nprint_names_and_countries<span class=\"token punctuation\">(</span>\n    <span class=\"token string\">\"Hey there\"</span><span class=\"token punctuation\">,</span> Monica<span class=\"token operator\">=</span><span class=\"token string\">\"Sweden\"</span><span class=\"token punctuation\">,</span> Mike<span class=\"token operator\">=</span><span class=\"token string\">\"The United States\"</span><span class=\"token punctuation\">,</span> Mark<span class=\"token operator\">=</span><span class=\"token string\">\"China\"</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can combine all of these together</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">example2</span><span class=\"token punctuation\">(</span>arg1<span class=\"token punctuation\">,</span> arg2<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> kw_1<span class=\"token operator\">=</span><span class=\"token string\">\"cheese\"</span><span class=\"token punctuation\">,</span> kw_2<span class=\"token operator\">=</span><span class=\"token string\">\"horse\"</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span>\n\n<span class=\"token comment\"># Lists are mutable arrays</span>\nempty_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\nroomates <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"Beau\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Delynn\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token comment\"># List built-in function makes a list too</span>\nspecials <span class=\"token operator\">=</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can use 'in' to test if something is in the list, like 'includes' in JS</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token comment\"># Dictionaries - Similar to JS POJO's or Map, containing key value pairs</span>\na <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"three\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\nb <span class=\"token operator\">=</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>one<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> two<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> three<span class=\"token operator\">=</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Can use 'in' on dictionaries too (for keys)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"one\"</span> <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span> <span class=\"token keyword\">in</span> b<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token comment\"># Sets - Just like JS, unordered collection of distinct objects</span>\nbedroom <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"bed\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tv\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"computer\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"clothes\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"playstation 4\"</span><span class=\"token punctuation\">}</span>\n<span class=\"token comment\"># bedroom = set(\"bed\", \"tv\", \"computer\", \"clothes\", \"playstation 5\")</span>\nschool_bag <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">\"book\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"paper\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"pencil\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"pencil\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"book\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"book\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"book\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"eraser\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>school_bag<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>bedroom<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># We can use 'in' on sets as wel</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token comment\"># Tuples are immutable lists of items</span>\ntime_blocks <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"AM\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"PM\"</span><span class=\"token punctuation\">)</span>\ncolors <span class=\"token operator\">=</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"green\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"blue\"</span>  <span class=\"token comment\"># Parenthesis not needed but encouraged</span>\n<span class=\"token comment\"># The tuple built-in function can be used to convert things to tuples</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># 'in' may be used on tuples as well</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># False</span>\n<span class=\"token comment\"># Ranges are immutable lists of numbers, often used with for loops</span>\n<span class=\"token comment\">#   - start - default: 0, first number in sequence</span>\n<span class=\"token comment\">#   - stop - required, next number past last number in sequence</span>\n<span class=\"token comment\">#   - step - default: 1, difference between each number in sequence</span>\nrange1 <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># [0,1,2,3,4]</span>\nrange2 <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># [1,2,3,4]</span>\nrange3 <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># [0,5,10,15,20]</span>\nrange4 <span class=\"token operator\">=</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># []</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> range1<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Built-in functions:</span>\n<span class=\"token comment\"># Filter</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">isOdd</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> num <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span>\n\nfiltered <span class=\"token operator\">=</span> <span class=\"token builtin\">filter</span><span class=\"token punctuation\">(</span>isOdd<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>filtered<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> num <span class=\"token keyword\">in</span> filtered<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"first way: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>num<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"--\"</span> <span class=\"token operator\">*</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"list comprehension: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">]</span> <span class=\"token keyword\">if</span> i <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token comment\"># Map</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">toUpper</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\nupperCased <span class=\"token operator\">=</span> <span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>toUpper<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"d\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>upperCased<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Sorted</span>\nsorted_items <span class=\"token operator\">=</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"john\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tom\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sonny\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>sorted_items<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># Notice uppercase comes before lowercase</span>\n<span class=\"token comment\"># Using a key function to control the sorting and make it case insensitive</span>\nsorted_items <span class=\"token operator\">=</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"john\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tom\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sonny\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> key<span class=\"token operator\">=</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>sorted_items<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># You can also reverse the sort</span>\nsorted_items <span class=\"token operator\">=</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"john\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"tom\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sonny\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                      key<span class=\"token operator\">=</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">,</span> reverse<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>sorted_items<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Enumerate creates a tuple with an index for what you're enumerating</span>\nquarters <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"First\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Second\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Third\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Fourth\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>quarters<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>quarters<span class=\"token punctuation\">,</span> start<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Zip takes list and combines them as key value pairs, or really however you need</span>\nkeys <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"Name\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Email\"</span><span class=\"token punctuation\">)</span>\nvalues <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"Buster\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"cheetoh@johhnydepp.com\"</span><span class=\"token punctuation\">)</span>\nzipped <span class=\"token operator\">=</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>keys<span class=\"token punctuation\">,</span> values<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>zipped<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># You can zip more than 2</span>\nx_coords <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\ny_coords <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span>\nz_coords <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\ncoords <span class=\"token operator\">=</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>x_coords<span class=\"token punctuation\">,</span> y_coords<span class=\"token punctuation\">,</span> z_coords<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>coords<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Len reports the length of strings along with list and any other object data type</span>\n<span class=\"token comment\"># doing this to save myself some typing</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">print_len</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nprint_len<span class=\"token punctuation\">(</span><span class=\"token string\">\"Mike\"</span><span class=\"token punctuation\">)</span>\nprint_len<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\nprint_len<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># 4 because there is a duplicate here (10)</span>\nprint_len<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Max will return the max number in a given scenario</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">35</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1012</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Min</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Sum</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Any</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">any</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">any</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># All</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Dir returns all the attributes of an object including it's methods and dunder methods</span>\nuser <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"Name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Bob\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Email\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"bob@bob.com\"</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">dir</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Importing packages and modules</span>\n<span class=\"token comment\">#  - Module - A Python code in a file or directory</span>\n<span class=\"token comment\">#  - Package - A module which is a directory containing an __init__.py file</span>\n<span class=\"token comment\">#  - Submodule - A module which is contained within a package</span>\n<span class=\"token comment\">#  - Name - An exported function, class, or variable in a module</span>\n<span class=\"token comment\"># Unlike JS, modules export ALL names contained within them without any special export key</span>\n<span class=\"token comment\"># Assuming we have the following package with four submodules</span>\n<span class=\"token comment\">#  math</span>\n<span class=\"token comment\">#  |  __init__.py</span>\n<span class=\"token comment\">#  | addition.py</span>\n<span class=\"token comment\">#  | subtraction.py</span>\n<span class=\"token comment\">#  | multiplication.py</span>\n<span class=\"token comment\">#  | division.py</span>\n<span class=\"token comment\"># If we peek into the addition.py file we see there's an add function</span>\n<span class=\"token comment\"># addition.py</span>\n<span class=\"token comment\"># We can import 'add' from other places because it's a 'name' and is automatically exported</span>\n\n<span class=\"token comment\"># def add(num1, num2):</span>\n<span class=\"token comment\">#     return num1 + num2</span>\n\n<span class=\"token comment\"># Notice the . syntax because this package can import it's own submodules.</span>\n<span class=\"token comment\"># Our __init__.py has the following files</span>\n<span class=\"token comment\"># This imports the 'add' function</span>\n<span class=\"token comment\"># And now it's also re-exported in here as well</span>\n<span class=\"token comment\"># from .addition import add</span>\n<span class=\"token comment\"># These import and re-export the rest of the functions from the submodule</span>\n<span class=\"token comment\"># from .subtraction import subtract</span>\n<span class=\"token comment\"># from .division import divide</span>\n<span class=\"token comment\"># from .multiplication import multiply</span>\n<span class=\"token comment\"># So if we have a script.py and want to import add, we could do it many ways</span>\n<span class=\"token comment\"># This will load and execute the 'math/__init__.py' file and give</span>\n<span class=\"token comment\"># us an object with the exported names in 'math/__init__.py'</span>\n<span class=\"token comment\"># print(math.add(1,2))</span>\n<span class=\"token comment\"># This imports JUST the add from 'math/__init__.py'</span>\n<span class=\"token comment\"># from math import add</span>\n<span class=\"token comment\"># print(add(1, 2))</span>\n<span class=\"token comment\"># This skips importing from 'math/__init__.py' (although it still runs)</span>\n<span class=\"token comment\"># and imports directly from the addition.py file</span>\n<span class=\"token comment\"># from math.addition import add</span>\n<span class=\"token comment\"># This imports all the functions individually from 'math/__init__.py'</span>\n<span class=\"token comment\"># from math import add, subtract, multiply, divide</span>\n<span class=\"token comment\"># print(add(1, 2))</span>\n<span class=\"token comment\"># print(subtract(2, 1))</span>\n<span class=\"token comment\"># This imports 'add' renames it to 'add_some_numbers'</span>\n<span class=\"token comment\"># from math import add as add_some_numbers</span>\n<span class=\"token comment\"># --------------------------------------- DAY 3 ---------------------------------------</span>\n<span class=\"token comment\"># Classes, Methods, and Properties</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">AngryBird</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># Slots optimize property access and memory usage and prevent you</span>\n    <span class=\"token comment\"># from arbitrarily assigning new properties the instance</span>\n    __slots__ <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"_x\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"_y\"</span><span class=\"token punctuation\">]</span>\n    <span class=\"token comment\"># Constructor</span>\n\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> x<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> y<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token comment\"># Doc String</span>\n        <span class=\"token triple-quoted-string string\">\"\"\"\n        Construct a new AngryBird by setting it's position to (0, 0)\n        \"\"\"</span>\n        <span class=\"token comment\"># Instance Variables</span>\n        self<span class=\"token punctuation\">.</span>_x <span class=\"token operator\">=</span> x\n        self<span class=\"token punctuation\">.</span>_y <span class=\"token operator\">=</span> y\n\n    <span class=\"token comment\"># Instance Method</span>\n\n    <span class=\"token keyword\">def</span> <span class=\"token function\">move_up_by</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> delta<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        self<span class=\"token punctuation\">.</span>_y <span class=\"token operator\">+=</span> delta\n\n    <span class=\"token comment\"># Getter</span>\n\n    <span class=\"token decorator annotation punctuation\">@property</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">x</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> self<span class=\"token punctuation\">.</span>_x\n\n    <span class=\"token comment\"># Setter</span>\n\n    <span class=\"token decorator annotation punctuation\">@x<span class=\"token punctuation\">.</span>setter</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">x</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">if</span> value <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n            value <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n        self<span class=\"token punctuation\">.</span>_x <span class=\"token operator\">=</span> value\n\n    <span class=\"token decorator annotation punctuation\">@property</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">y</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> self<span class=\"token punctuation\">.</span>_y\n\n    <span class=\"token decorator annotation punctuation\">@y<span class=\"token punctuation\">.</span>setter</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">y</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        self<span class=\"token punctuation\">.</span>_y <span class=\"token operator\">=</span> value\n\n    <span class=\"token comment\"># Dunder Repr... called by 'print'</span>\n\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__repr__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string-interpolation\"><span class=\"token string\">f\"&lt;AngryBird (</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>self<span class=\"token punctuation\">.</span>_x<span class=\"token punctuation\">}</span></span><span class=\"token string\">, </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>self<span class=\"token punctuation\">.</span>_y<span class=\"token punctuation\">}</span></span><span class=\"token string\">)>\"</span></span>\n\n<span class=\"token comment\"># JS to Python Classes cheat table</span>\n<span class=\"token comment\">#        JS                    Python</span>\n<span class=\"token comment\">#   constructor()         def __init__(self):</span>\n<span class=\"token comment\">#      super()            super().__init__()</span>\n<span class=\"token comment\">#   this.property           self.property</span>\n<span class=\"token comment\">#    this.method            self.method()</span>\n<span class=\"token comment\"># method(arg1, arg2){}    def method(self, arg1, ...)</span>\n<span class=\"token comment\"># get someProperty(){}    @property</span>\n<span class=\"token comment\"># set someProperty(){}    @someProperty.setter</span>\n<span class=\"token comment\"># List Comprehensions are a way to transform a list from one format to another</span>\n<span class=\"token comment\">#  - Pythonic Alternative to using map or filter</span>\n<span class=\"token comment\">#  - Syntax of a list comprehension</span>\n<span class=\"token comment\">#     - new_list = [value loop condition]</span>\n<span class=\"token comment\"># Using a for loop</span>\nsquares <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    squares<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>i <span class=\"token operator\">**</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>squares<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># value = i ** 2</span>\n<span class=\"token comment\"># loop = for i in range(10)</span>\nsquares <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>i <span class=\"token operator\">**</span> <span class=\"token number\">2</span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>squares<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nsentence <span class=\"token operator\">=</span> <span class=\"token string\">\"the rocket came back from mars\"</span>\nvowels <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>character <span class=\"token keyword\">for</span> character <span class=\"token keyword\">in</span> sentence <span class=\"token keyword\">if</span> character <span class=\"token keyword\">in</span> <span class=\"token string\">\"aeiou\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>vowels<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># You can also use them on dictionaries. We can use the items() method</span>\n<span class=\"token comment\"># for the dictionary to loop through it getting the keys and values out at once</span>\nperson <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Corina\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"age\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">32</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"height\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1.4</span><span class=\"token punctuation\">}</span>\n<span class=\"token comment\"># This loops through and capitalizes the first letter of all keys</span>\nnewPerson <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>key<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> value <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> person<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>newPerson<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2><strong>2.1.7 Indentation</strong></h2>\n<p>Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements.</p>\n<p>First, tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight (this is intended to be the same rule as used by Unix). The total number of spaces preceding the first non-blank character then determines the line's indentation. Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation.</p>\n<p><strong>Cross-platform compatibility note:</strong> because of the nature of text editors on non-UNIX platforms, it is unwise to use a mixture of spaces and tabs for the indentation in a single source file.</p>\n<p>A formfeed character may be present at the start of the line; it will be ignored for the indentation calculations above. Formfeed characters occurring elsewhere in the leading whitespace have an undefined effect (for instance, they may reset the space count to zero).</p>\n<p>The indentation levels of consecutive lines are used to generate INDENT and DEDENT tokens, using a stack, as follows.</p>\n<p>Before the first line of the file is read, a single zero is pushed on the stack; this will never be popped off again. The numbers pushed on the stack will always be strictly increasing from bottom to top. At the beginning of each logical line, the line's indentation level is compared to the top of the stack. If it is equal, nothing happens. If it is larger, it is pushed on the stack, and one INDENT token is generated. If it is smaller, it must be one of the numbers occurring on the stack; all numbers on the stack that are larger are popped off, and for each number popped off a DEDENT token is generated. At the end of the file, a DEDENT token is generated for each number remaining on the stack that is larger than zero.</p>\n<p>Here is an example of a correctly (though confusingly) indented piece of Python code:</p>\n<p><code class=\"language-text\">def perm(l): # Compute the list of all permutations of l if len(l) &lt;= 1: return [l] r = [] for i in range(len(l)): s = l[:i] + l[i+1:] p = perm(s) for x in p: r.append(l[i:i+1] + x) return r</code></p>\n<p>The following example shows various indentation errors:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> `def perm(l):                       # error: first line indented\nfor i in range(len(l)):             # error: not indented\n    s = l[:i] + l[i+1:]\n        p = perm(l[:i] + l[i+1:])   # error: unexpected indent\n        for x in p:\n                r.append(l[i:i+1] + x)\n            return r                # error: inconsistent dedent`</code></pre></div>\n<p>(Actually, the first three errors are detected by the parser; only the last error is found by the lexical analyzer -- the indentation of <code class=\"language-text\">return r</code> does not match a level popped off the stack.)</p>\n<p><a href=\"https://ds-unit-5-lambda.netlify.app/\">https://ds-unit-5-lambda.netlify.app/</a></p>\n<h2>Python Study Guide for a JavaScript Programmer</h2>\n<p><a href=\"https://bryanguner.medium.com/?source=post_page-----5cfdf3d2bdfb--------------------------------\">Bryan Guner</a></p>\n<p><a href=\"https://levelup.gitconnected.com/python-study-guide-for-a-native-javascript-developer-5cfdf3d2bdfb?source=post_page-----5cfdf3d2bdfb--------------------------------\">Mar 5</a> · 15 min read</p>\n<p><img src=\"https://miro.medium.com/max/1400/1*3V9VOfPk_hrFdbEAd3j-QQ.png\" alt=\"https://miro.medium.com/max/1400/1*3V9VOfPk_hrFdbEAd3j-QQ.png\"></p>\n<h2><strong>Applications of Tutorial &#x26; Cheat Sheet Respectivley (At Bottom Of Tutorial):</strong></h2>\n<h2><strong>Basics</strong></h2>\n<ul>\n<li><strong>PEP8</strong> : Python Enhancement Proposals, style-guide for Python.</li>\n<li><code class=\"language-text\">print</code> is the equivalent of <code class=\"language-text\">console.log</code>.</li>\n</ul>\n<blockquote>\n<p>'print() == console.log()'</p>\n</blockquote>\n<h2><code class=\"language-text\"></code>** is used to make comments in your code.**</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def foo():\n    \"\"\"\n    The foo function does many amazing things that you\n    should not question. Just accept that it exists and\n    use it with caution.\n    \"\"\"\n    secretThing()</code></pre></div>\n<blockquote>\n<p>Python has a built in help function that let's you see a description of the source code without having to navigate to it… \"-SickNasty … Autor Unknown\"</p>\n</blockquote>\n<h2><strong>Numbers</strong></h2>\n<ul>\n<li>Python has three types of numbers:</li>\n<li><strong>Integer</strong></li>\n<li><strong>Positive and Negative Counting Numbers.</strong></li>\n</ul>\n<p>No Decimal Point</p>\n<blockquote>\n<p>Created by a literal non-decimal point number … or … with the int() constructor.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(3) # => 3\nprint(int(19)) # => 19\nprint(int()) # => 0</code></pre></div>\n<p><strong>3. Complex Numbers</strong></p>\n<blockquote>\n<p>Consist of a real part and imaginary part.</p>\n</blockquote>\n<h3><strong>Boolean is a subtype of integer in Python.🤷‍♂️</strong></h3>\n<blockquote>\n<p>If you came from a background in JavaScript and learned to accept the premise(s) of the following meme…</p>\n</blockquote>\n<blockquote>\n<p>Than I am sure you will find the means to suspend your disbelief.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(2.24) # => 2.24\nprint(2.) # => 2.0\nprint(float()) # => 0.0\nprint(27e-5) # => 0.00027</code></pre></div>\n<h2><strong>KEEP IN MIND:</strong></h2>\n<blockquote>\n<p>The i is switched to a j in programming.</p>\n</blockquote>\n<p><strong>T*</strong>his is because the letter i is common place as the de facto index for any and all enumerable entities so it just makes sense not to compete for name-<strong>space</strong> when there's another 25 letters that don't get used for every loop under the sun. My most medium apologies to Leonhard Euler.*</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(7j) # => 7j\nprint(5.1+7.7j)) # => 5.1+7.7j\nprint(complex(3, 5)) # => 3+5j\nprint(complex(17)) # => 17+0j\nprint(complex()) # => 0j</code></pre></div>\n<ul>\n<li><strong>Type Casting</strong> : The process of converting one number to another.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Using Float\nprint(17)               # => 17\nprint(float(17))        # => 17.0# Using Int\nprint(17.0)             # => 17.0\nprint(int(17.0))        # => 17# Using Str\nprint(str(17.0) + ' and ' + str(17))        # => 17.0 and 17</code></pre></div>\n<p><strong>The arithmetic operators are the same between JS and Python, with two additions:</strong></p>\n<ul>\n<li><em>\"**\" : Double asterisk for exponent.</em></li>\n<li><em>\"//\" : Integer Division.</em></li>\n<li><strong>There are no spaces between math operations in Python.</strong></li>\n<li><strong>Integer Division gives the other part of the number from Module; it is a way to do round down numbers replacing <code class=\"language-text\">Math.floor()</code> in JS.</strong></li>\n<li><strong>There are no <code class=\"language-text\">++</code> and <code class=\"language-text\">-</code> in Python, the only shorthand operators are:</strong></li>\n</ul>\n<h2><strong>Strings</strong></h2>\n<ul>\n<li>Python uses both single and double quotes.</li>\n<li>You can escape strings like so <code class=\"language-text\">'Jodi asked, \"What\\\\'s up, Sam?\"'</code></li>\n<li>Multiline strings use triple quotes.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print('''My instructions are very long so to make them\nmore readable in the code I am putting them on\nmore than one line. I can even include \"quotes\"\nof any kind because they won't get confused with\nthe end of the string!''')</code></pre></div>\n<p><strong>Use the <code class=\"language-text\">len()</code> function to get the length of a string.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(len(\"Spaghetti\")) # => 9</code></pre></div>\n<h2><strong>Python uses <code class=\"language-text\">zero-based indexing</code></strong></h2>\n<h3><strong>Python allows negative indexing (thank god!)</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Spaghetti\"[-1]) # => i print(\"Spaghetti\"[-4]) # => e</code></pre></div>\n<ul>\n<li>Python let's you use ranges</li>\n</ul>\n<p>You can think of this as roughly equivalent to the slice method called on a JavaScript object or string… <em>(mind you that in JS … strings are wrapped in an object (under the hood)… upon which the string methods are actually called. As a immutable privative type <strong>by textbook definition</strong>, a string literal could not hope to invoke most of it's methods without violating the state it was bound to on initialization if it were not for this bit of syntactic sugar.)</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Spaghetti\"[1:4]) # => pag\nprint(\"Spaghetti\"[4:-1]) # => hett\nprint(\"Spaghetti\"[4:4]) # => (empty string)</code></pre></div>\n<ul>\n<li>The end range is exclusive just like <code class=\"language-text\">slice</code> in JS.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Shortcut to get from the beginning of a string to a certain index.\nprint(\"Spaghetti\"[:4])  # => Spag\nprint(\"Spaghetti\"[:-1])    # => Spaghett# Shortcut to get from a certain index to the end of a string.\nprint(\"Spaghetti\"[1:])  # => paghetti\nprint(\"Spaghetti\"[-4:])    # => etti</code></pre></div>\n<ul>\n<li>The <code class=\"language-text\">index</code> string function is the equiv. of <code class=\"language-text\">indexOf()</code> in JS</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Spaghetti\".index(\"h\"))    # => 4\nprint(\"Spaghetti\".index(\"t\"))    # => 6</code></pre></div>\n<ul>\n<li>The <code class=\"language-text\">count</code> function finds out how many times a substring appears in a string… pretty nifty for a hard coded feature of the language.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(\"Spaghetti\".count(\"h\"))    # => 1\nprint(\"Spaghetti\".count(\"t\"))    # => 2\nprint(\"Spaghetti\".count(\"s\"))    # => 0\nprint('''We choose to go to the moon in this decade and do the other things,\nnot because they are easy, but because they are hard, because that goal will\nserve to organize and measure the best of our energies and skills, because that\nchallenge is one that we are willing to accept, one we are unwilling to\npostpone, and one which we intend to win, and the others, too.\n'''.count('the '))                # => 4</code></pre></div>\n<ul>\n<li><strong>You can use <code class=\"language-text\">+</code> to concatenate strings, just like in JS.</strong></li>\n<li><strong>You can also use \"*\" to repeat strings or multiply strings.</strong></li>\n<li><strong>Use the <code class=\"language-text\">format()</code> function to use placeholders in a string to input values later on.</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">first_name = \"Billy\"\nlast_name = \"Bob\"\nprint('Your name is {0} {1}'.format(first_name, last_name))  # => Your name is Billy Bob</code></pre></div>\n<ul>\n<li><em>Shorthand way to use format function is:</em><code class=\"language-text\">print(f'Your name is {first_name} {last_name}')</code></li>\n</ul>\n<h3><strong>Some useful string methods.</strong></h3>\n<ul>\n<li><strong>Note that in JS <code class=\"language-text\">join</code> is used on an Array, in Python it is used on String.</strong></li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/630/0*eE3E5H0AoqkhqK1z.png\" alt=\"https://miro.medium.com/max/630/0*eE3E5H0AoqkhqK1z.png\"></p>\n<ul>\n<li>There are also many handy testing methods.</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/630/0*Q0CMqFd4PozLDFPB.png\" alt=\"https://miro.medium.com/max/630/0*Q0CMqFd4PozLDFPB.png\"></p>\n<h2><strong>Variables and Expressions</strong></h2>\n<ul>\n<li><strong>Duck-Typing</strong> : Programming Style which avoids checking an object's type to figure out what it can do.</li>\n<li>Duck Typing is the fundamental approach of Python.</li>\n<li>Assignment of a value automatically declares a variable.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 7\nb = 'Marbles'\nprint(a)         # => 7\nprint(b)         # => Marbles</code></pre></div>\n<ul>\n<li><strong><em>You can chain variable assignments to give multiple var names the same value.</em></strong></li>\n</ul>\n<h3><strong>Use with caution as this is highly unreadable</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">count = max = min = 0\nprint(count)           # => 0\nprint(max)             # => 0\nprint(min)             # => 0</code></pre></div>\n<h3><strong>The value and type of a variable can be re-assigned at any time.</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 17\nprint(a)         # => 17\na = 'seventeen'\nprint(a)         # => seventeen</code></pre></div>\n<ul>\n<li><code class=\"language-text\">* does not exist in Python, but you can 'create' it like so:</code>*</li>\n<li><em>Python replaces <code class=\"language-text\">null</code> with <code class=\"language-text\">none</code>.</em></li>\n<li><code class=\"language-text\"></code><strong>* is an object</strong> and can be directly assigned to a variable.*</li>\n</ul>\n<blockquote>\n<p>Using none is a convenient way to check to see why an action may not be operating correctly in your program.</p>\n</blockquote>\n<h2><strong>Boolean Data Type</strong></h2>\n<ul>\n<li>One of the biggest benefits of Python is that it reads more like English than JS does.</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/1400/0*HQpndNhm1Z_xSoHb.png\" alt=\"https://miro.medium.com/max/1400/0*HQpndNhm1Z_xSoHb.png\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Logical AND\nprint(True and True)    # => True\nprint(True and False)   # => False\nprint(False and False)  # => False# Logical OR\nprint(True or True)     # => True\nprint(True or False)    # => True\nprint(False or False)   # => False# Logical NOT\nprint(not True)             # => False\nprint(not False and True)   # => True\nprint(not True or False)    # => False</code></pre></div>\n<ul>\n<li>By default, Python considers an object to be true UNLESS it is one of the following:</li>\n<li>Constant <code class=\"language-text\">None</code> or <code class=\"language-text\">False</code></li>\n<li>Zero of any numeric type.</li>\n<li>Empty Sequence or Collection.</li>\n<li><code class=\"language-text\">True</code> and <code class=\"language-text\">False</code> must be capitalized</li>\n</ul>\n<h2><strong>Comparison Operators</strong></h2>\n<ul>\n<li>Python uses all the same equality operators as JS.</li>\n<li>In Python, equality operators are processed from left to right.</li>\n<li>Logical operators are processed in this order:</li>\n<li><strong>NOT</strong></li>\n<li><strong>AND</strong></li>\n<li><strong>OR</strong></li>\n</ul>\n<blockquote>\n<p>Just like in JS, you can use parentheses to change the inherent order of operations.Short Circuit : Stopping a program when a true or false has been reached.</p>\n</blockquote>\n<p><img src=\"https://miro.medium.com/max/630/0*qHzGRLTOMTf30miT.png\" alt=\"https://miro.medium.com/max/630/0*qHzGRLTOMTf30miT.png\"></p>\n<h2><strong>Identity vs Equality</strong></h2>\n<p>****</p>\n<table>\n<thead>\n<tr>\n<th align=\"center\"></th>\n<th align=\"left\"></th>\n</tr>\n</thead>\n<tbody>\n</tbody>\n</table>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print (2 == '2')    # => False\nprint (2 is '2')    # => Falseprint (\"2\" == '2')    # => True\nprint (\"2\" is '2')    # => True# There is a distinction between the number types.\nprint (2 == 2.0)    # => True\nprint (2 is 2.0)    # => False</code></pre></div>\n<ul>\n<li>In the Python community it is better to use <code class=\"language-text\">is</code> and <code class=\"language-text\">is not</code> over <code class=\"language-text\">==</code> or <code class=\"language-text\">!=</code></li>\n</ul>\n<p><strong>If Statements</strong></p>\n<p><code class=\"language-text\">if name == 'Monica': print('Hi, Monica.')if name == 'Monica': print('Hi, Monica.')else: print('Hello, stranger.')if name == 'Monica': print('Hi, Monica.')elif age &lt; 12: print('You are not Monica, kiddo.')elif age > 2000: print('Unlike you, Monica is not an undead, immortal vampire.')elif age > 100: print('You are not Monica, grannie.')</code><em>Remember the order of <code class=\"language-text\">elif</code> statements matter.</em></p>\n<h2><strong>While Statements</strong></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">spam = 0\nwhile spam &lt; 5:\n  print('Hello, world.')\n  spam = spam + 1</code></pre></div>\n<ul>\n<li><code class=\"language-text\">Break</code> statement also exists in Python.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">spam = 0\nwhile True:\n  print('Hello, world.')\n  spam = spam + 1\n  if spam >= 5:\n    break</code></pre></div>\n<ul>\n<li>As are <code class=\"language-text\">continue</code> statements</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">spam = 0\nwhile True:\n  print('Hello, world.')\n  spam = spam + 1\n  if spam &lt; 5:\n    continue\n  break</code></pre></div>\n<h2><strong>Try/Except Statements</strong></h2>\n<ul>\n<li>Python equivalent to <code class=\"language-text\">try/catch</code></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 321\ntry:\n    print(len(a))\nexcept:\n    print('Silently handle error here')    # Optionally include a correction to the issue\n    a = str(a)\n    print(len(a)a = '321'\ntry:\n    print(len(a))\nexcept:\n    print('Silently handle error here')    # Optionally include a correction to the issue\n    a = str(a)\n    print(len(a))</code></pre></div>\n<ul>\n<li>You can name an error to give the output more specificity.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 100\nb = 0\ntry:\n    c = a / b\nexcept ZeroDivisionError:\n    c = None\nprint(c)</code></pre></div>\n<ul>\n<li>You can also use the <code class=\"language-text\">pass</code> commmand to by pass a certain error.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 100\nb = 0\ntry:\n    print(a / b)\nexcept ZeroDivisionError:\n    pass</code></pre></div>\n<ul>\n<li>The <code class=\"language-text\">pass</code> method won't allow you to bypass every single error so you can chain an exception series like so:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = 100\n# b = \"5\"\ntry:\n    print(a / b)\nexcept ZeroDivisionError:\n    pass\nexcept (TypeError, NameError):\n    print(\"ERROR!\")</code></pre></div>\n<ul>\n<li>You can use an <code class=\"language-text\">else</code> statement to end a chain of <code class=\"language-text\">except</code> statements.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># tuple of file names\nfiles = ('one.txt', 'two.txt', 'three.txt')# simple loop\nfor filename in files:\n    try:\n        # open the file in read mode\n        f = open(filename, 'r')\n    except OSError:\n        # handle the case where file does not exist or permission is denied\n        print('cannot open file', filename)\n    else:\n        # do stuff with the file object (f)\n        print(filename, 'opened successfully')\n        print('found', len(f.readlines()), 'lines')\n        f.close()</code></pre></div>\n<ul>\n<li><code class=\"language-text\">finally</code> is used at the end to clean up all actions under any circumstance.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def divide(x, y):\n    try:\n        result = x / y\n    except ZeroDivisionError:\n        print(\"Cannot divide by zero\")\n    else:\n        print(\"Result is\", result)\n    finally:\n        print(\"Finally...\")</code></pre></div>\n<ul>\n<li>Using duck typing to check to see if some value is able to use a certain method.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Try a number - nothing will print out\na = 321\nif hasattr(a, '__len__'):\n    print(len(a))# Try a string - the length will print out (4 in this case)\nb = \"5555\"\nif hasattr(b, '__len__'):\n    print(len(b))</code></pre></div>\n<h2><strong>Pass</strong></h2>\n<ul>\n<li>Pass Keyword is required to write the JS equivalent of :</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if (true) {\n}while (true) {}if True:\n  passwhile True:\n  pass</code></pre></div>\n<h2><strong>Functions</strong></h2>\n<ul>\n<li><strong>Function definition includes:</strong></li>\n<li><strong>The <code class=\"language-text\">def</code> keyword</strong></li>\n<li><strong>The name of the function</strong></li>\n<li><strong>A list of parameters enclosed in parentheses.</strong></li>\n<li><strong>A colon at the end of the line.</strong></li>\n<li><strong>One tab indentation for the code to run.</strong></li>\n<li><strong>You can use default parameters just like in JS</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def greeting(name, saying=\"Hello\"):\n    print(saying, name)greeting(\"Monica\")\n# Hello Monicagreeting(\"Barry\", \"Hey\")\n# Hey Barry</code></pre></div>\n<h3><strong>Keep in mind, default parameters must always come after regular parameters.</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># THIS IS BAD CODE AND WILL NOT RUN\ndef increment(delta=1, value):\n    return delta + value</code></pre></div>\n<ul>\n<li><em>You can specify arguments by name without destructuring in Python.</em></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def greeting(name, saying=\"Hello\"):\n    print(saying, name)# name has no default value, so just provide the value\n# saying has a default value, so use a keyword argument\ngreeting(\"Monica\", saying=\"Hi\")</code></pre></div>\n<ul>\n<li>The <code class=\"language-text\">lambda</code> keyword is used to create anonymous functions and are supposed to be <code class=\"language-text\">one-liners</code>.</li>\n</ul>\n<p><code class=\"language-text\">toUpper = lambda s: s.upper()</code></p>\n<h2><strong>Notes</strong></h2>\n<h3><strong>Formatted Strings</strong></h3>\n<blockquote>\n<p>Remember that in Python join() is called on a string with an array/list passed in as the argument.Python has a very powerful formatting engine.format() is also applied directly to strings.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">shopping_list = ['bread','milk','eggs']\nprint(','.join(shopping_list))</code></pre></div>\n<h2><strong>Comma Thousands Separator</strong></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print('{:,}'.format(1234567890))\n'1,234,567,890'</code></pre></div>\n<h2><strong>Date and Time</strong></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">d = datetime.datetime(2020, 7, 4, 12, 15, 58)\nprint('{:%Y-%m-%d %H:%M:%S}'.format(d))\n'2020-07-04 12:15:58'</code></pre></div>\n<h2><strong>Percentage</strong></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">points = 190\ntotal = 220\nprint('Correct answers: {:.2%}'.format(points/total))\nCorrect answers: 86.36%</code></pre></div>\n<h2><strong>Data Tables</strong></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">width=8\nprint(' decimal hex binary')\nprint('-'*27)\nfor num in range(1,16):\nfor base in 'dXb':\nprint('{0:{width}{base}}'.format(num, base=base, width=width), end=' ')\nprint()\nGetting Input from the Command Line\nPython runs synchronously, all programs and processes will stop when listening for a user input.\nThe input function shows a prompt to a user and waits for them to type 'ENTER'.\nScripts vs Programs\nProgramming Script : A set of code that runs in a linear fashion.\nThe largest difference between scripts and programs is the level of complexity and purpose. Programs typically have many UI's.</code></pre></div>\n<p>**Python can be used to display html, css, and JS.**<em>It is common to use Python as an API (Application Programming Interface)</em></p>\n<h3><strong>Structured Data</strong></h3>\n<h3><strong>Sequence : The most basic data structure in Python where the index determines the order.</strong></h3>\n<blockquote>\n<p>List-Tuple-Range-Collections : Unordered data structures, hashable values.</p>\n</blockquote>\n<h3><strong>Dictionaries-Sets-Iterable : Generic name for a sequence or collection; any object that can be iterated through.Can be mutable or immutable.Built In Data Types</strong></h3>\n<h2><strong>Lists are the python equivalent of arrays.</strong></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">empty_list = []\ndepartments = ['HR','Development','Sales','Finance','IT','Customer Support']</code></pre></div>\n<h2><strong>You can instantiate</strong></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">specials = list()</code></pre></div>\n<h3><strong>Test if a value is in a list.</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">print(1 in [1, 2, 3]) #> True\nprint(4 in [1, 2, 3]) #> False\n# Tuples : Very similar to lists, but they are immutable</code></pre></div>\n<h3><strong>Instantiated with parentheses</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">time_blocks = ('AM','PM')</code></pre></div>\n<h3><strong>Sometimes instantiated without</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">colors = 'red','blue','green'\nnumbers = 1, 2, 3</code></pre></div>\n<h3><strong>Tuple() built in can be used to convert other data into a tuple</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">tuple('abc') # returns ('a', 'b', 'c')\ntuple([1,2,3]) # returns (1, 2, 3)\n# Think of tuples as constant variables.</code></pre></div>\n<h3><strong>Ranges : A list of numbers which can't be changed; often used with for loops.</strong></h3>\n<p><strong>Declared using one to three parameters</strong>.</p>\n<blockquote>\n<p>Start : opt. default 0, first # in sequence.Stop : required next number past the last number in the sequence.Step : opt. default 1, difference between each number in the sequence.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [0, 1, 2, 3, 4]</span>\n<span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3, 4]</span>\n<span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [0, 5, 10, 15, 20]</span>\n<span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [ ]</span>\n<span class=\"token keyword\">for</span> let <span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">+</span><span class=\"token operator\">+</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> let <span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">+</span><span class=\"token operator\">+</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> let <span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">25</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">+=</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> let<span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">+</span><span class=\"token operator\">+</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># Keep in mind that stop is not included in the range.</span></code></pre></div>\n<h3><strong>Dictionaries : Mappable collection where a hashable value is used as a key to ref. an object stored in the dictionary.</strong></h3>\n<h3><strong>Mutable.</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = {'one':1, 'two':2, 'three':3}\nb = dict(one=1, two=2, three=3)\nc = dict([('two', 2), ('one', 1), ('three', 3)])\n# a, b, and c are all equal</code></pre></div>\n<p><strong><em>Declared with curly braces of the built in dict()</em></strong></p>\n<blockquote>\n<p>Benefit of dictionaries in Python is that it doesn't matter how it is defined, if the keys and values are the same the dictionaries are considered equal.</p>\n</blockquote>\n<p><strong>Use the in operator to see if a key exists in a dictionary.</strong></p>\n<p><strong>Sets : Unordered collection of distinct objects; objects that need to be hashable.</strong></p>\n<blockquote>\n<p>Always be unique, duplicate items are auto dropped from the set.</p>\n</blockquote>\n<h3><strong>Common Uses:</strong></h3>\n<blockquote>\n<p>Removing DuplicatesMembership TestingMathematical Operators: Intersection, Union, Difference, Symmetric Difference.</p>\n</blockquote>\n<p><strong>Standard Set is mutable, Python has a immutable version called frozenset.Sets created by putting comma seperated values inside braces:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">school_bag = {'book','paper','pencil','pencil','book','book','book','eraser'}\nprint(school_bag)</code></pre></div>\n<h3><strong>Also can use set constructor to automatically put it into a set.</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">letters = set('abracadabra')\nprint(letters)\n#Built-In Functions\n#Functions using iterables</code></pre></div>\n<p><strong>filter(function, iterable) : creates new iterable of the same type which includes each item for which the function returns true.</strong></p>\n<p><strong>map(function, iterable) : creates new iterable of the same type which includes the result of calling the function on every item of the iterable.</strong></p>\n<p><strong>sorted(iterable, key=None, reverse=False) : creates a new sorted list from the items in the iterable.</strong></p>\n<p><strong>Output is always a list</strong></p>\n<p><strong>key: opt function which coverts and item to a value to be compared.</strong></p>\n<p><strong>reverse: optional boolean.</strong></p>\n<p><strong>enumerate(iterable, start=0) : starts with a sequence and converts it to a series of tuples</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">quarters = ['First', 'Second', 'Third', 'Fourth']\nprint(enumerate(quarters))\nprint(enumerate(quarters, start=1))</code></pre></div>\n<h3><strong>(0, 'First'), (1, 'Second'), (2, 'Third'), (3, 'Fourth')</strong></h3>\n<h3><strong>(1, 'First'), (2, 'Second'), (3, 'Third'), (4, 'Fourth')</strong></h3>\n<blockquote>\n<p>zip(*iterables) : creates a zip object filled with tuples that combine 1 to 1 the items in each provided iterable.Functions that analyze iterable</p>\n</blockquote>\n<p><strong>len(iterable) : returns the count of the number of items.</strong></p>\n<p>*<em>max(args, key=None) : returns the largest of two or more arguments.</em></p>\n<p><strong>max(iterable, key=None) : returns the largest item in the iterable.</strong></p>\n<p><em>key optional function which converts an item to a value to be compared.min works the same way as max</em></p>\n<p><strong>sum(iterable) : used with a list of numbers to generate the total.</strong></p>\n<p><em>There is a faster way to concatenate an array of strings into one string, so do not use sum for that.</em></p>\n<p><strong>any(iterable) : returns True if any items in the iterable are true.</strong></p>\n<p><strong>all(iterable) : returns True is all items in the iterable are true.</strong></p>\n<h2><strong>Working with dictionaries</strong></h2>\n<p><strong>dir(dictionary) : returns the list of keys in the dictionary.Working with sets</strong></p>\n<p>*<em>Union : The pipe | operator or union(sets) function can be used to produce a new set which is a combination of all elements in the provided set.</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = {1, 2, 3}\nb = {2, 4, 6}\nprint(a | b) # => {1, 2, 3, 4, 6}</code></pre></div>\n<h3><strong>Intersection : The &#x26; operator ca be used to produce a new set of only the elements that appear in all sets.</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = {1, 2, 3}\nb = {2, 4, 6}\nprint(a &amp; b) # => {2}\nDifference : The — operator can be used to produce a new set of only the elements that appear in the first set and NOT the others.</code></pre></div>\n<p><strong>Symmetric Difference : The ^ operator can be used to produce a new set of only the elements that appear in exactly one set and not in both.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\nb <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a — b<span class=\"token punctuation\">)</span> <span class=\"token comment\"># => {1, 3}</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>b — a<span class=\"token punctuation\">)</span> <span class=\"token comment\"># => {4, 6}</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">^</span> b<span class=\"token punctuation\">)</span> <span class=\"token comment\"># => {1, 3, 4, 6}</span></code></pre></div>\n<h2><strong>For StatementsIn python, there is only one for loop.</strong></h2>\n<p>Always Includes:</p>\n<blockquote>\n<ol>\n<li>The for keyword2. A variable name3. The 'in' keyword4. An iterable of some kid5. A colon6. On the next line, an indented block of code called the for clause.</li>\n</ol>\n</blockquote>\n<p><strong>You can use break and continue statements inside for loops as well.</strong></p>\n<p><strong>You can use the range function as the iterable for the for loop.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'My name is'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Carlita Cinco ('</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">')'</span><span class=\"token punctuation\">)</span>total <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n<span class=\"token keyword\">for</span> num <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">101</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\ntotal <span class=\"token operator\">+=</span> num\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>total<span class=\"token punctuation\">)</span>\nLooping over a <span class=\"token builtin\">list</span> <span class=\"token keyword\">in</span> Python\n<span class=\"token keyword\">for</span> c <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span>lst <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">:</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong><em>Common technique is to use the len() on a pre-defined list with a for loop to iterate over the indices of the list.</em></strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">supplies <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'pens'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'staplers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'flame-throwers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'binders'</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>supplies<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Index '</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' in supplies is: '</span> <span class=\"token operator\">+</span> supplies<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>****</p>\n<p><strong>You can loop and destructure at the same time.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">l = 1, 2], [3, 4], [5, 6\nfor a, b in l:\nprint(a, ', ', b)</code></pre></div>\n<blockquote>\n<p>Prints 1, 2Prints 3, 4Prints 5, 6</p>\n</blockquote>\n<p><strong>You can use values() and keys() to loop over dictionaries.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">spam = {'color': 'red', 'age': 42}\nfor v in spam.values():\nprint(v)</code></pre></div>\n<p><em>Prints red</em></p>\n<p><em>Prints 42</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for k in spam.keys():\nprint(k)</code></pre></div>\n<p><em>Prints color</em></p>\n<p><em>Prints age</em></p>\n<p><strong>For loops can also iterate over both keys and values.</strong></p>\n<p><strong>Getting tuples</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for i in spam.items():\nprint(i)</code></pre></div>\n<p><em>Prints ('color', 'red')</em></p>\n<p><em>Prints ('age', 42)</em></p>\n<p><em>Destructuring to values</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for k, v in spam.items():\nprint('Key: ' + k + ' Value: ' + str(v))</code></pre></div>\n<p><em>Prints Key: age Value: 42</em></p>\n<p><em>Prints Key: color Value: red</em></p>\n<p><strong>Looping over string</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for c in \"abcdefg\":\nprint(c)</code></pre></div>\n<p><strong>When you order arguments within a function or function call, the args need to occur in a particular order:</strong></p>\n<p><em>formal positional args.</em></p>\n<ul>\n<li>args</li>\n</ul>\n<p><em>keyword args with default values</em></p>\n<ul>\n<li>*kwargs</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def example(arg_1, arg_2, *args, **kwargs):\npassdef example2(arg_1, arg_2, *args, kw_1=\"shark\", kw_2=\"blowfish\", **kwargs):\npass</code></pre></div>\n<h2><strong>Importing in Python</strong></h2>\n<p><strong>Modules are similar to packages in Node.js</strong>Come in different types:</p>\n<p>Built-In,</p>\n<p>Third-Party,</p>\n<p>Custom.</p>\n<p><strong>All loaded using import statements.</strong></p>\n<h2><strong>Terms</strong></h2>\n<blockquote>\n<p>module : Python code in a separate file.package : Path to a directory that contains <a href=\"http://modules.init.py\">modules.init.py</a> : Default file for a package.submodule : Another file in a module's folder.function : Function in a module.</p>\n</blockquote>\n<p><strong>A module can be any file but it is usually created by placing a special file</strong> <a href=\"http://init.py\"><strong>init.py</strong></a> <strong>into a folder. pic</strong></p>\n<p><em>Try to avoid importing with wildcards in Python.</em></p>\n<p><em>Use multiple lines for clarity when importing.</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from urllib.request import (\nHTTPDefaultErrorHandler as ErrorHandler,\nHTTPRedirectHandler as RedirectHandler,\nRequest,\npathname2url,\nurl2pathname,\nurlopen,\n)</code></pre></div>\n<h2><strong>Watching Out for Python 2</strong></h2>\n<p><strong>Python 3 removed &#x3C;> and only uses !=</strong></p>\n<p><strong>format() was introduced with P3</strong></p>\n<p><strong>All strings in P3 are unicode and encoded.md5 was removed.</strong></p>\n<p><strong>ConfigParser was renamed to configparsersets were killed in favor of set() class.</strong></p>\n<h3><strong>print was a statement in P2, but is a function in P3.</strong></h3>\n<p><a href=\"https://gist.github.com/bgoonz/82154f50603f73826c27377ebaa498b5#file-python-study-guide-py\">https://gist.github.com/bgoonz/82154f50603f73826c27377ebaa498b5#file-python-study-guide-py</a></p>\n<p><a href=\"https://gist.github.com/bgoonz/282774d28326ff83d8b42ae77ab1fee3#file-python-cheatsheet-py\">https://gist.github.com/bgoonz/282774d28326ff83d8b42ae77ab1fee3#file-python-cheatsheet-py</a></p>\n<p><a href=\"https://gist.github.com/bgoonz/999163a278b987fe47fb247fd4d66904#file-python-cheat-sheet-md\">https://gist.github.com/bgoonz/999163a278b987fe47fb247fd4d66904#file-python-cheat-sheet-md</a></p>\n<p><img src=\"https://s3-us-west-2.amazonaws.com/secure.notion-static.com/be5715e2-c834-458f-8c5b-ea185717fe37/Untitled.png\" alt=\"https://s3-us-west-2.amazonaws.com/secure.notion-static.com/be5715e2-c834-458f-8c5b-ea185717fe37/Untitled.png\"></p>\n<h2>Built-in Functions</h2>"},{"url":"/docs/python/python-quiz/","relativePath":"docs/python/python-quiz.md","relativeDir":"docs/python","base":"python-quiz.md","name":"python-quiz","frontmatter":{"title":"Python Quiz","weight":0,"excerpt":"Python Quiz","seo":{"title":"Python Quiz","description":"Python Quiz cheat sheet for python developers","robots":[],"extra":[{"name":"og:image","value":"images/py-code.png","keyName":"property","relativeUrl":true},{"name":"twitter:title","value":"python cheat sheet","keyName":"name","relativeUrl":false}]},"template":"docs"},"html":"<h3>zQ1. What is an abstract class?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> An abstract class is the name for any class from which you can instantiate an object.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstract classes must be redefined any time an object is instantiated from them.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstract classes must inherit from concrete classes.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] An abstract class exists only so that other \"concrete\" classes can inherit from the abstract class.</li>\n</ul>\n<p><a href=\"https://www.geeksforgeeks.org/abstract-classes-in-python/\">reference</a></p>\n<h3>Q2. What happens when you use the build-in function <code class=\"language-text\">any()</code> on a list?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">any()</code> function will randomly return any item from the list.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <code class=\"language-text\">any()</code> function returns True if any item in the list evaluates to True. Otherwise, it returns False.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">any()</code> function takes as arguments the list to check inside, and the item to check for. If \"any\" of the items in the list match the item to check for, the function returns True.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">any()</code> function returns a Boolean value that answers the question \"Are there any items in this list?\"</li>\n</ul>\n<p><strong>example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> <span class=\"token builtin\">any</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Yes, there is True'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Yes<span class=\"token punctuation\">,</span> there <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span></code></pre></div>\n<h3>Q3. What data structure does a binary tree degenerate to if it isn't balanced properly?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] linked list</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> queue</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> set</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> OrderedDict</li>\n</ul>\n<h3>Q4. What statement about static methods is true?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods are called static because they always return <code class=\"language-text\">None</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods can be bound to either a class or an instance of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Static methods serve mostly as utility methods or helper methods, since they can't access or modify a class's state.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods can access and modify the state of a class or an instance of a class.</li>\n</ul>\n<p><a href=\"https://www.geeksforgeeks.org/class-method-vs-static-method-python\">reference</a></p>\n<h3>Q5. What are attributes?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Attributes are long-form version of an <code class=\"language-text\">if/else</code> statement, used when testing for equality between objects.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Attributes are a way to hold data or describe a state for a class or an instance of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Attributes are strings that describe characteristics of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Function arguments are called \"attributes\" in the context of class methods and instance methods.</li>\n</ul>\n<p><strong>Explanation</strong> Attributes defined under the class, arguments goes under the functions. arguments usually refer as parameter, whereas attributes are the constructor of the class or an instance of a class.</p>\n<h3>Q6. What is the term to describe this code?</h3>\n<p><code class=\"language-text\">count, fruit, price = (2, 'apple', 3.5)</code></p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">tuple assignment</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">tuple unpacking</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">tuple matching</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">tuple duplication</code></li>\n</ul>\n<h3>Q7. What built-in list method would you use to remove items from a list?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">.delete()</code> method</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">pop(my_list)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">del(my_list)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">.pop()</code> method</li>\n</ul>\n<p><strong>example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">my_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\nmy_list<span class=\"token punctuation\">.</span>pop<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\nmy_list\n<span class=\"token operator\">>></span><span class=\"token operator\">></span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3>Q8. What is one of the most common use of Python's sys library?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] to capture command-line arguments given at a file's runtime</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to connect various systems, such as connecting a web front end, an API service, a database, and a mobile app</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to take a snapshot of all the packages and libraries in your virtual environment</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to scan the health of your Python ecosystem while inside a virtual environment</li>\n</ul>\n<h3>Q9. What is the runtime of accessing a value in a dictionary by using its key?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(n), also called linear time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(log n), also called logarithmic time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(n^2), also called quadratic time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] O(1), also called constant time.</li>\n</ul>\n<h3>Q10. What is the correct syntax for defining a class called Game, if it inherits from a parent class called LogicGame?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">class Game(LogicGame): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def Game(LogicGame): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def Game.LogicGame(): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">class Game.LogicGame(): pass</code></li>\n</ul>\n<p><strong>Explanation:</strong> <code class=\"language-text\">The parent class which is inherited is passed as an argument to the child class. Therefore, here the first option is the right answer.</code></p>\n<h3>Q11. What is the correct way to write a doctest?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    sum(4, 3)\n    7\n\n    sum(-4, 5)\n    1\n    \"\"\"</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li>[✅] B</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    >>> sum(4, 3)\n    7\n\n    >>> sum(-4, 5)\n    1\n    \"\"\"</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> C</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    # >>> sum(4, 3)\n    # 7\n\n    # >>> sum(-4, 5)\n    # 1\n    \"\"\"</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> D</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\">###</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">7</span>\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token comment\">###</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<p><strong>explanation</strong> - use ''' to start the doc and add output of the cell after >>></p>\n<h3>Q12. What built-in Python data type is commonly used to represent a stack?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">set</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">list</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">None</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">dictionary</code></li>\n</ul>\n<p><code class=\"language-text\">. You can only build a stack from scratch.</code></p>\n<h3>Q13. What would this expression return?</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">college_years <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Freshman'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Sophomore'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Junior'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Senior'</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>college_years<span class=\"token punctuation\">,</span> <span class=\"token number\">2019</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">[('Freshman', 2019), ('Sophomore', 2020), ('Junior', 2021), ('Senior', 2022)]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">[(2019, 2020, 2021, 2022), ('Freshman', 'Sophomore', 'Junior', 'Senior')]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">[('Freshman', 'Sophomore', 'Junior', 'Senior'), (2019, 2020, 2021, 2022)]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">[(2019, 'Freshman'), (2020, 'Sophomore'), (2021, 'Junior'), (2022, 'Senior')]</code></li>\n</ul>\n<h3>Q14. How does <code class=\"language-text\">defaultdict</code> work?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> will automatically create a dictionary for you that has keys which are the integers 0-10.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> forces a dictionary to only accept keys that are of the data type specified when you created the <code class=\"language-text\">defaultdict</code> (such as strings or integers).</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] If you try to read from a <code class=\"language-text\">defaultdict</code> with a nonexistent key, a new default key-value pair will be created for you instead of throwing a <code class=\"language-text\">KeyError</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> stores a copy of a dictionary in memory that you can default to if the original gets unintentionally modified.</li>\n</ul>\n<h3>Q15. What is the correct syntax for defining a class called \"Game\", if it inherits from a parent class called \"LogicGame\"?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">class Game.LogicGame(): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def Game(LogicGame): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">class Game(LogicGame): pass</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def Game.LogicGame(): pass</code></li>\n</ul>\n<p><code class=\"language-text\">repeated but labels will be different</code></p>\n<h3>Q16. What is the purpose of the \"self\" keyword when defining or calling instance methods?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">self</code> means that no other arguments are required to be passed into the method.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no real purpose for the <code class=\"language-text\">self</code> method; it's just historic computer science jargon that Python keeps to stay consistent with other programming languages.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">self</code> refers to the instance whose method was called.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">self</code> refers to the class that was inherited from to create the object using <code class=\"language-text\">self</code>.</li>\n</ul>\n<p><strong>Simple example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">my_secrets</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> password<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        self<span class=\"token punctuation\">.</span>password <span class=\"token operator\">=</span> password\n        <span class=\"token keyword\">pass</span>\ninstance <span class=\"token operator\">=</span> my_secrets<span class=\"token punctuation\">(</span><span class=\"token string\">'1234'</span><span class=\"token punctuation\">)</span>\ninstance<span class=\"token punctuation\">.</span>password\n<span class=\"token operator\">>></span><span class=\"token operator\">></span><span class=\"token string\">'1234'</span></code></pre></div>\n<h3>Q17. Which of these is NOT a characteristic of namedtuples?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You can assign a name to each of the <code class=\"language-text\">namedtuple</code> members and refer to them that way, similarly to how you would access keys in <code class=\"language-text\">dictionary</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Each member of a namedtuple object can be indexed to directly, just like in a regular <code class=\"language-text\">tuple</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">namedtuples</code> are just as memory efficient as regular <code class=\"language-text\">tuples</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] No import is needed to use <code class=\"language-text\">namedtuples</code> because they are available in the standard library.</li>\n</ul>\n<p>**We need to import it using <code class=\"language-text\">from collections import namedtuple</code> **</p>\n<h3>Q18. What is an instance method?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Instance methods can modify the state of an instance or the state of its parent class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Instance methods hold data related to the instance.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> An instance method is any class method that doesn't take any arguments.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> An instance method is a regular function that belongs to a class, but it must return <code class=\"language-text\">None</code>.</li>\n</ul>\n<h3>Q19. Which choice is the most syntactically correct example of the conditional branching?</h3>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are a few people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are a few people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are a few people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are a few people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Also see Question 85 for the same question with different answers.</p>\n<h3>Q20. Which statement does NOT describe the object-oriented programming concept of encapsulation?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It protects the data from outside interference.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A parent class is encapsulated and no data from the parent class passes on to the child class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It keeps data and the methods that can manipulate that data in one place.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It only allows the data to be changed by methods.</li>\n</ul>\n<h3>Q21. What is the purpose of an if/else statement?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It tells the computer which chunk of code to run if the instructions you coded are incorrect.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It runs one chunk of code if all the imports were successful, and another chunk of code if the imports were not successful.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It executes one chunk of code if a condition is true, but a different chunk of code if the condition is false.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It tells the computer which chunk of code to run if the is enough memory to handle it, and which chunk of code to run if there is not enough memory to handle it.</li>\n</ul>\n<h3>Q22. What built-in Python data type is best suited for implementing a queue?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> dictionary</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> set</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> None. You can only build a queue from scratch.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] list</li>\n</ul>\n<h3>Q23. What is the correct syntax for instantiating a new object of the type Game?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_game = class.Game()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_game = class(Game)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">my_game = Game()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_game = Game.create()</code></li>\n</ul>\n<h3>Q24. What does the built-in <code class=\"language-text\">map()</code> function do?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It creates a path from multiple values in an iterable to a single value.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It applies a function to each item in an iterable and returns the value of that function.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It converts a complex value type into simpler value types.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It creates a mapping between two different elements of different iterables.</li>\n</ul>\n<p><strong>Explanation:</strong> - The synax for <code class=\"language-text\">map()</code> function is <code class=\"language-text\">list(map(function,iterable)</code>. the simple area finder using map would be like this</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> math\nradius <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\narea <span class=\"token operator\">=</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span>math<span class=\"token punctuation\">.</span>pi<span class=\"token operator\">*</span><span class=\"token punctuation\">(</span>x<span class=\"token operator\">**</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> radius<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\narea\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span><span class=\"token number\">3.14</span><span class=\"token punctuation\">,</span> <span class=\"token number\">12.57</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28.27</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3>Q25. If you don't explicitly return a value from a function, what happens?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The function will return a RuntimeError if you don't return a value.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] If the return keyword is absent, the function will return <code class=\"language-text\">None</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> If the return keyword is absent, the function will return <code class=\"language-text\">True</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The function will enter an infinite loop because it won't know when to stop executing its code.</li>\n</ul>\n<h3>Q26. What is the purpose of the <code class=\"language-text\">pass</code> statement in Python?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is used to skip the <code class=\"language-text\">yield</code> statement of a generator and return a value of None.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It is a null operation used mainly as a placeholder in functions, classes, etc.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is used to pass control from one statement block to another.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is used to skip the rest of a <code class=\"language-text\">while</code> or <code class=\"language-text\">for loop</code> and return to the start of the loop.</li>\n</ul>\n<h3>Q27. What is the term used to describe items that may be passed into a function?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] arguments</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> paradigms</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> attributes</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> decorators</li>\n</ul>\n<h3>Q28. Which collection type is used to associate values with unique keys?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">slot</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">dictionary</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">queue</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">sorted list</code></li>\n</ul>\n<h3>Q29. When does a for loop stop iterating?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when it encounters an infinite loop</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when it encounters an if/else statement that contains a break keyword</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] when it has assessed each item in the iterable it is working on or a break keyword is encountered</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when the runtime for the loop exceeds O(n^2)</li>\n</ul>\n<h3>Q30. Assuming the node is in a singly linked list, what is the runtime complexity of searching for a specific node within a singly linked list?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The runtime is O(n) because in the worst case, the node you are searching for is the last node, and every node in the linked list must be visited.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime is O(nk), with n representing the number of nodes and k representing the amount of time it takes to access each node in memory.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime cannot be determined unless you know how many nodes are in the singly linked list.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime is O(1) because you can index directly to a node in a singly linked list.</li>\n</ul>\n<h3>Q31. Given the following three list, how would you create a new list that matches the desired output printed below?</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">fruits <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Apples'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Oranges'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Bananas'</span><span class=\"token punctuation\">]</span>\nquantities <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\nprices <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.50</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.25</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.89</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token comment\">#Desired output</span>\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Apples'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Oranges'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Bananas'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.89</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">output <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n\nfruit_tuple_0 <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> quantities<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> price<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\noutput<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>fruit_tuple<span class=\"token punctuation\">)</span>\n\nfruit_tuple_1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> quantities<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> price<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\noutput<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>fruit_tuple<span class=\"token punctuation\">)</span>\n\nfruit_tuple_2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> quantities<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> price<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\noutput<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>fruit_tuple<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">return</span> output</code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">i <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\noutput <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> fruit <span class=\"token keyword\">in</span> fruits<span class=\"token punctuation\">:</span>\n    temp_qty <span class=\"token operator\">=</span> quantities<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span>\n    temp_price <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span>\n    output<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>fruit<span class=\"token punctuation\">,</span> temp_qty<span class=\"token punctuation\">,</span> temp_price<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">return</span> output</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">groceries <span class=\"token operator\">=</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>fruits<span class=\"token punctuation\">,</span> quantities<span class=\"token punctuation\">,</span> prices<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">return</span> groceries\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Apples'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Oranges'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'Bananas'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.89</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">i <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\noutput <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> fruit <span class=\"token keyword\">in</span> fruits<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> qty <span class=\"token keyword\">in</span> quantities<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">for</span> price <span class=\"token keyword\">in</span> prices<span class=\"token punctuation\">:</span>\n            output<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>fruit<span class=\"token punctuation\">,</span> qty<span class=\"token punctuation\">,</span> price<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">return</span> output</code></pre></div>\n<h3>Q32. What happens when you use the built-in function all() on a list?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">all()</code> function returns a Boolean value that answers the question \"Are all the items in this list the same?</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">all()</code> function returns True if all the items in the list can be converted to strings. Otherwise, it returns False.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">all()</code> function will return all the values in the list.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <code class=\"language-text\">all()</code> function returns True if all items in the list evaluate to True. Otherwise, it returns False.</li>\n</ul>\n<p><strong>Explaination</strong> - <code class=\"language-text\">all()</code> returns true if all in the list are True, see example below</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">test <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">if</span> <span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span>test<span class=\"token punctuation\">)</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Yeah all are True'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'There is an imposter'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> There <span class=\"token keyword\">is</span> an imposter</code></pre></div>\n<h3>Q33. What is the correct syntax for calling an instance method on a class named Game?</h3>\n<p><em>(Answer format may vary. Game and roll (or dice</em>roll) should each be called with no parameters.)_</p>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> dice <span class=\"token operator\">=</span> Game<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> dice<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> dice <span class=\"token operator\">=</span> Game<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> dice<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> dice <span class=\"token operator\">=</span> Game<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> dice<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> dice <span class=\"token operator\">=</span> Game<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> dice<span class=\"token punctuation\">.</span>roll<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Q34. What is the algorithmic paradigm of quick sort?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> backtracking</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> dynamic programming</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> decrease and conquer</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] divide and conquer</li>\n</ul>\n<h3>Q35. What is runtime complexity of the list's built-in <code class=\"language-text\">.append()</code> method?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] O(1), also called constant time</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(log n), also called logarithmic time</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(n^2), also called quadratic time</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> O(n), also called linear time</li>\n</ul>\n<h3>Q36. What is key difference between a <code class=\"language-text\">set</code> and a <code class=\"language-text\">list</code>?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A set is an ordered collection unique items. A list is an unordered collection of non-unique items.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Elements can be retrieved from a list but they cannot be retrieved from a set.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A set is an ordered collection of non-unique items. A list is an unordered collection of unique items.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A set is an unordered collection unique items. A list is an ordered collection of non-unique items.</li>\n</ul>\n<h3>Q37. What is the definition of abstraction as applied to object-oriented Python?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstraction means that a different style of code can be used, since many details are already known to the program behind the scenes.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Abstraction means the implementation is hidden from the user, and only the relevant data or information is shown.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstraction means that the data and the functionality of a class are combined into one entity.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Abstraction means that a class can inherit from more than one parent class.</li>\n</ul>\n<h3>Q38. What does this function print?</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">print_alpha_nums</span><span class=\"token punctuation\">(</span>abc_list<span class=\"token punctuation\">,</span> num_list<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> abc_list<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">for</span> num <span class=\"token keyword\">in</span> num_list<span class=\"token punctuation\">:</span>\n            <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">,</span> num<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span>\n\nprint_alpha_nums<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token number\">1</span>\na <span class=\"token number\">2</span>\na <span class=\"token number\">3</span>\nb <span class=\"token number\">1</span>\nb <span class=\"token number\">2</span>\nb <span class=\"token number\">3</span>\nc <span class=\"token number\">1</span>\nc <span class=\"token number\">2</span>\nc <span class=\"token number\">3</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">aaa\nbbb\nccc\n<span class=\"token number\">111</span>\n<span class=\"token number\">222</span>\n<span class=\"token number\">333</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>\nb <span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>\nc <span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span></code></pre></div>\n<h3>Q39. Correct representation of doctest for function in Python</h3>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># a = 1</span>\n    <span class=\"token comment\"># b = 2</span>\n    <span class=\"token comment\"># sum(a, b) = 3</span>\n\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    a = 1\n    b = 2\n    sum(a, b) = 3\n    \"\"\"</span>\n\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    >>> a = 1\n    >>> b = 2\n    >>> sum(a, b)\n    3\n    \"\"\"</span>\n\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">'''\n    a = 1\n    b = 2\n    sum(a, b) = 3\n    '''</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b</code></pre></div>\n<p><strong>Explanation:</strong> Use \"\"\" to start and end the docstring and use >>> to represent the output. If you write this correctly you can also run the doctest using build-in doctest module</p>\n<h3>Q40. Suppose a Game class inherits from two parent classes: BoardGame and LogicGame. Which statement is true about the methods of an object instantiated from the Game class?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When instantiating an object, the object doesn't inherit any of the parent class's methods.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When instantiating an object, the object will inherit the methods of whichever parent class has more methods.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When instantiating an object, the programmer must specify which parent class to inherit methods from.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] An instance of the Game class will inherit whatever methods the BoardGame and LogicGame classes have.</li>\n</ul>\n<h3>Q41. What does calling namedtuple on a collection type return?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a generic object class with iterable parameter fields</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a generic object class with non-iterable named fields</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a tuple subclass with non-iterable parameter fields</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a tuple subclass with iterable named fields</li>\n</ul>\n<p><strong>Example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> math\nradius <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\narea <span class=\"token operator\">=</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span>math<span class=\"token punctuation\">.</span>pi<span class=\"token operator\">*</span><span class=\"token punctuation\">(</span>x<span class=\"token operator\">**</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> radius<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\narea\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span><span class=\"token number\">3.14</span><span class=\"token punctuation\">,</span> <span class=\"token number\">12.57</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28.27</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3>Q42. What symbol(s) do you use to assess equality between two elements?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&amp;&amp;</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">=</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">==</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">||</code></li>\n</ul>\n<h3>Q43. Review the code below. What is the correct syntax for changing the price to 1.5?</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">fruit_info <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'fruit'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'apple'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'count'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'price'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3.5</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">fruit_info ['price'] = 1.5</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_list [3.5] = 1.5</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">1.5 = fruit_info ['price]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_list['price'] == 1.5</code></li>\n</ul>\n<h3>Q44. What value would be returned by this check for equality?</h3>\n<p><code class=\"language-text\">5 != 6</code></p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">yes</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">False</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">True</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">None</code></li>\n</ul>\n<p><strong>Explanation</strong> - <code class=\"language-text\">!=</code> is equivalent to <strong>not equal to</strong> in python</p>\n<h3>Q45. What does a class's <code class=\"language-text\">init()</code> method do?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">__init__</code> method makes classes aware of each other if more than one class is defined in a single code file.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The<code class=\"language-text\">__init__</code> method is included to preserve backwards compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <code class=\"language-text\">__init__</code> method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">__init__</code> method initializes any imports you may have included at the top of your file.</li>\n</ul>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">test</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I came here without your permission lol'</span><span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">pass</span>\nt1 <span class=\"token operator\">=</span> test<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'I came here without your permission lol'</span></code></pre></div>\n<h3>Q46. What is meant by the phrase \"space complexity\"?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">How many microprocessors it would take to run your code in less than one second</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">How many lines of code are in your code file</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">The amount of space taken up in memory as a function of the input size</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">How many copies of the code file could fit in 1 GB of memory</code></li>\n</ul>\n<h3>Q47. What is the correct syntax for creating a variable that is bound to a dictionary?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">fruit_info = {'fruit': 'apple', 'count': 2, 'price': 3.5}</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_info =('fruit': 'apple', 'count': 2,'price': 3.5 ).dict()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_info = ['fruit': 'apple', 'count': 2,'price': 3.5 ].dict()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_info = to_dict('fruit': 'apple', 'count': 2, 'price': 3.5)</code></li>\n</ul>\n<h3>Q48. What is the proper way to write a list comprehension that represents all the keys in this dictionary?</h3>\n<p><code class=\"language-text\">fruits = {'Apples': 5, 'Oranges': 3, 'Bananas': 4}</code></p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_names = [x in fruits.keys() for x]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_names = for x in fruits.keys() *</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">fruit_names = [x for x in fruits.keys()]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_names = x for x in fruits.keys()</code></li>\n</ul>\n<h3>Q49. What is the purpose of the <code class=\"language-text\">self</code> keyword when defining or calling methods on an instance of an object?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">self</code> refers to the class that was inherited from to create the object using <code class=\"language-text\">self</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no real purpose for the <code class=\"language-text\">self</code> method. It's just legacy computer science jargon that Python keeps to stay consistent with other programming languages.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">self</code> means that no other arguments are required to be passed into the method.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">self</code> refers to the instance whose method was called.</li>\n</ul>\n<p><strong>Explanation:</strong> - Try running the example of the Q45 without passing <code class=\"language-text\">self</code> argument inside the <code class=\"language-text\">__init__</code>, you'll understand the reason. You'll get the error like this <code class=\"language-text\">__init__() takes 0 positional arguments but 1 was given</code>, this means that something is going inside even if haven't specified, which is instance itself.</p>\n<h3>Q50. What statement about the class methods is true?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method is a regular function that belongs to a class, but it must return None.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A class method can modify the state of the class, but they can't directly modify the state of an instance that inherits from that class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method is similar to a regular function, but a class method doesn't take any arguments.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method hold all of the data for a particular class.</li>\n</ul>\n<h3>Q51. What does it mean for a function to have linear runtime?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You did not use very many advanced computer programming concepts in your code.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The difficulty level your code is written at is not that high.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It will take your program less than half a second to run.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The amount of time it takes the function to complete grows linearly as the input size increases.</li>\n</ul>\n<h3>Q52. What is the proper way to define a function?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">def getMaxNum(list_of_nums): # body of function goes here</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">func get_max_num(list_of_nums): # body of function goes here</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">func getMaxNum(list_of_nums): # body of function goes here</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">def get_max_num(list_of_nums): # body of function goes here</code></li>\n</ul>\n<p><a href=\"https://www.python.org/dev/peps/pep-0008/\">explanation for 52 &#x26; 53</a></p>\n<h3>Q53. According to the PEP 8 coding style guidelines, how should constant values be named in Python?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> in camel case without using underscores to separate words -- e.g. <code class=\"language-text\">maxValue = 255</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> in lowercase with underscores to separate words -- e.g. <code class=\"language-text\">max_value = 255</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] in all caps with underscores separating words -- e.g. <code class=\"language-text\">MAX_VALUE = 255</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> in mixed case without using underscores to separate words -- e.g. <code class=\"language-text\">MaxValue = 255</code></li>\n</ul>\n<h3>Q54. Describe the functionality of a deque.</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A deque adds items to one side and remove items from the other side.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A deque adds items to either or both sides, but only removes items from the top.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A deque adds items at either or both ends, and remove items at either or both ends.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A deque adds items only to the top, but remove from either or both sides.</li>\n</ul>\n<p><strong>Explanation</strong> - <code class=\"language-text\">deque</code> is used to create block chanin and in that there is <em>first in first out</em> approch, which means the last element to enter will be the first to leave.</p>\n<h3>Q55. What is the correct syntax for creating a variable that is bound to a set?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">my_set = {0, 'apple', 3.5}</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_set = to_set(0, 'apple', 3.5)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_set = (0, 'apple', 3.5).to_set()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">my_set = (0, 'apple', 3.5).set()</code></li>\n</ul>\n<h3>Q56. What is the correct syntax for defining an <code class=\"language-text\">__init__()</code> method that takes no parameters?</h3>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">__init__</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<h3>Q57. Which of the following is TRUE About how numeric data would be organised in a binary Search tree?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] For any given Node in a binary Search Tree, the child node to the left is less than the value of the given node and the child node to its right is greater than the given node.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Binary Search Tree cannot be used to organize and search through numeric data, given the complication that arise with very deep trees.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The top node of the binary search tree would be an arbitrary number. All the nodes to the left of the top node need to be less than the top node's number, but they don't need to ordered in any particular way.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The smallest numeric value would go in the top most node. The next highest number would go in its left child node, the the next highest number after that would go in its right child node. This pattern would continue until all numeric values were in their own node.</li>\n</ul>\n<h3>Q58. Why would you use a decorator?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A decorator is similar to a class and should be used if you are doing functional programming instead of object oriented programming.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A decorator is a visual indicator to someone reading your code that a portion of your code is critical and should not be changed.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] You use the decorator to alter the functionality of a function without having to modify the functions code.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> An import statement is preceded by a decorator, python knows to import the most recent version of whatever package or library is being imported.</li>\n</ul>\n<h3>Q59. When would you use a for loop?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Only in some situations, as loops are used only for certain type of programming.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] When you need to check every element in an iterable of known length.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When you want to minimize the use of strings in your code.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> When you want to run code in one file for a function in another file.</li>\n</ul>\n<h3>Q60. What is the most self-descriptive way to define a function that calculates sales tax on a purchase?</h3>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">tax</span><span class=\"token punctuation\">(</span>my_float<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">'''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.'''</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">tx</span><span class=\"token punctuation\">(</span>amt<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">'''Gets the tax on an amount.'''</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sales_tax</span><span class=\"token punctuation\">(</span>amount<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">'''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.'''</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">calculate_sales_tax</span><span class=\"token punctuation\">(</span>subtotal<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">pass</span></code></pre></div>\n<h3>Q61. What would happen if you did not alter the state of the element that an algorithm is operating on recursively?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You do not have to alter the state of the element the algorithm is recursing on.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You would eventually get a KeyError when the recursive portion of the code ran out of items to recurse on.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] You would get a RuntimeError: maximum recursion depth exceeded.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The function using recursion would return None.</li>\n</ul>\n<p><a href=\"https://www.python-course.eu/python3_recursive_functions.php#Definition-of-Recursion\">explanation</a></p>\n<h3>Q62. What is the runtime complexity of searching for an item in a binary search tree?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime for searching in a binary search tree is O(1) because each node acts as a key, similar to a dictionary.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime for searching in a binary search tree is O(n!) because every node must be compared to every other node.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The runtime for searching in a binary search tree is generally O(h), where h is the height of the tree.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The runtime for searching in a binary search tree is O(n) because every node in the tree must be visited.</li>\n</ul>\n<p><a href=\"https://www.geeksforgeeks.org/binary-search-tree-data-structure/\">explanation</a></p>\n<h3>Q63. Why would you use <code class=\"language-text\">mixin</code>?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You use a <code class=\"language-text\">mixin</code> to force a function to accept an argument at runtime even if the argument wasn't included in the function's definition.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You use a <code class=\"language-text\">mixin</code> to allow a decorator to accept keyword arguments.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You use a <code class=\"language-text\">mixin</code> to make sure that a class's attributes and methods don't interfere with global variables and functions.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] If you have many classes that all need to have the same functionality, you'd use a <code class=\"language-text\">mixin</code> to define that functionality.</li>\n</ul>\n<p><a href=\"https://www.youtube.com/watch?v=zVFLBfqV-q0\">explanation</a></p>\n<h3>Q64. What is the runtime complexity of adding an item to a stack and removing an item from a stack?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add items to a stack in O(1) time and remove items from a stack on O(n) time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Add items to a stack in O(1) time and remove items from a stack in O(1) time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add items to a stack in O(n) time and remove items from a stack on O(1) time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add items to a stack in O(n) time and remove items from a stack on O(n) time.</li>\n</ul>\n<h3>Q65. Which statement accurately describes how items are added to and removed from a stack?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a stacks adds items to one side and removes items from the other side.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a stacks adds items to the top and removes items from the top.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a stacks adds items to the top and removes items from anywhere in the stack.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a stacks adds items to either end and removes items from either end.</li>\n</ul>\n<p><strong>Explanation</strong> Stack uses the <em>first in first out</em> approach</p>\n<h3>Q66. What is a base case in a recursive function?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A base case is the condition that allows the algorithm to stop recursing. It is usually a problem that is small enough to solve directly.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The base case is summary of the overall problem that needs to be solved.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The base case is passed in as an argument to a function whose body makes use of recursion.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The base case is similar to a base class, in that it can be inherited by another object.</li>\n</ul>\n<h3>Q67. Why is it considered good practice to open a file from within a Python script by using the <code class=\"language-text\">with</code> keyword?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">with</code> keyword lets you choose which application to open the file in.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">with</code> keyword acts like a <code class=\"language-text\">for</code> loop, and lets you access each line in the file one by one.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no benefit to using the <code class=\"language-text\">with</code> keyword for opening a file in Python.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] When you open a file using the <code class=\"language-text\">with</code> keyword in Python, Python will make sure the file gets closed, even if an exception or error is thrown.</li>\n</ul>\n<p><a href=\"https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files\">explanation</a></p>\n<h3>Q68. Why would you use a virtual environment?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Virtual environments create a \"bubble\" around your project so that any libraries or packages you install within it don't affect your entire machine.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Teams with remote employees use virtual environments so they can share code, do code reviews, and collaborate remotely.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Virtual environments were common in Python 2 because they augmented missing features in the language. Virtual environments are not necessary in Python 3 due to advancements in the language.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Virtual environments are tied to your GitHub or Bitbucket account, allowing you to access any of your repos virtually from any machine.</li>\n</ul>\n<h3>Q69. What is the correct way to run all the doctests in a given file from the command line?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] python3 -m doctest &#x3C;<em>filename</em>></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> python3 &#x3C;<em>filename</em>></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> python3 &#x3C;<em>filename</em>> rundoctests</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> python3 doctest</li>\n</ul>\n<p><a href=\"https://www.youtube.com/watch?v=P8qm0VAbbww&#x26;t=180s\">tutorial video</a></p>\n<h3>Q70. What is a lambda function ?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> any function that makes use of scientific or mathematical constants, often represented by Greek letters in academic writing</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a function that get executed when decorators are used</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> any function whose definition is contained within five lines of code or fewer</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a small, anonymous function that can take any number of arguments but has only expression to evaluate</li>\n</ul>\n<p><a href=\"https://www.guru99.com/python-lambda-function.html\">Reference</a></p>\n<p><strong>Explanation:</strong> <code class=\"language-text\">the lambda notation is basically an anonymous function that can take any number of arguments with only single expression (i.e, cannot be overloaded). It has been introducted in other programming languages, such as C++ and Java. The lambda notation allows programmers to \"bypass\" function declaration.</code></p>\n<h3>Q71. What is the primary difference between lists and tuples?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You can access a specifc element in a list by indexing to its position, but you cannot access a specific element in a tuple unless you iterate through the tuple</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Lists are mutable, meaning you can change the data that is inside them at any time. Tuples are immutable, meaning you cannot change the data that is inside them once you have created the tuple.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Lists are immutable, meaning you cannot change the data that is inside them once you have created the list. Tuples are mutable, meaning you can change the data that is inside them at any time.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Lists can hold several data types inside them at once, but tuples can only hold the same data type if multiple elements are present.</li>\n</ul>\n<h3>Q72. Which statement about static method is true?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods can be bound to either a class or an instance of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods can access and modify the state of a class or an instance of a class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Static methods serve mostly as utility or helper methods, since they cannot access or modify a class's state.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Static methods are called static because they always return None.</li>\n</ul>\n<h3>Q73. What does a generator return?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> None</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] An iterable object</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A linked list data structure from a non-empty list</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> All the keys of the given dictionary</li>\n</ul>\n<h3>Q74. What is the difference between class attributes and instance attributes?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Instance attributes can be changed, but class attributes cannot be changed</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Class attributes are shared by all instances of the class. Instance attributes may be unique to just that instance</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no difference between class attributes and instance attributes</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Class attributes belong just to the class, not to instance of that class. Instance attributes are shared among all instances of a class</li>\n</ul>\n<h3>Q75. What is the correct syntax of creating an instance method?</h3>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">get_next_card</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token comment\"># method body goes here</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">get_next_card</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token comment\"># method body goes here</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> self<span class=\"token punctuation\">.</span>get_next_card<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token comment\"># method body goes here</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> self<span class=\"token punctuation\">.</span>get_next_card<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token comment\"># method body goes here</span></code></pre></div>\n<h3>Q76. What is the correct way to call a function?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] get<em>max</em>num([57, 99, 31, 18])</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> call.(get<em>max</em>num)</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def get<em>max</em>num([57, 99, 31, 18])</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> call.get<em>max</em>num([57, 99, 31, 18])</li>\n</ul>\n<h3>Q77. How is comment created?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">-- This is a comment</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\"># This is a comment</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">/_ This is a comment _\\</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">// This is a comment</code></li>\n</ul>\n<h3>Q78. What is the correct syntax for replacing the string apple in the list with the string orange?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> orange = my_list[1]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] my_list[1] = 'orange'</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my_list['orange'] = 1</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my_list[1] == orange</li>\n</ul>\n<h3>Q79. What will happen if you use a while loop and forget to include logic that eventually causes the while loop to stop?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Nothing will happen; your computer knows when to stop running the code in the while loop.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You will get a KeyError.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Your code will get stuck in an infinite loop.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> You will get a WhileLoopError.</li>\n</ul>\n<h3>Q80. Describe the functionality of a queue?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A queue adds items to either end and removes items from either end.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A queue adds items to the top and removes items from the top.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A queue adds items to the top, and removes items from anywhere in, a list.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A queue adds items to the top and removes items from anywhere in the queue.</li>\n</ul>\n<h3>Q81. Which choice is the most syntactically correct example of the conditional branching?</h3>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_people <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is a lot of people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num_people <span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There are some people in the pool.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"There is no one in the pool.\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This question seems to be an updated version of Question 19.</p>\n<h3>Q82. How does <code class=\"language-text\">defaultdict</code> work?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> will automatically create a dictionary for you that has keys which are the integers 0-10.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> forces a dictionary to only accept keys that are of the types specified when you created the <code class=\"language-text\">defaultdict</code> (such as strings or integers).</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] If you try to read from a <code class=\"language-text\">defaultdict</code> with a nonexistent key, a new default key-value pair will be created for you instead of throwing a <code class=\"language-text\">KeyError</code>.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">defaultdict</code> stores a copy of a dictionary in memory that you can default to if the original gets unintentionally modified.</li>\n</ul>\n<p>Updated version of Question 14.</p>\n<h3>Q83. What is the correct syntax for adding a key called <code class=\"language-text\">variety</code> to the <code class=\"language-text\">fruit_info</code> dictionary that has a value of <code class=\"language-text\">Red Delicious</code>?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">fruit_info['variety'] == 'Red Delicious'</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">fruit_info['variety'] = 'Red Delicious'</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">red_delicious = fruit_info['variety']</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">red_delicious == fruit_info['variety']</code></li>\n</ul>\n<h3>Q84. When would you use a <code class=\"language-text\">while</code> loop?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you want to minimize the use of strings in your code</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you want to run code in one file while code in another file is also running</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] when you want some code to continue running as long as some condition is true</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you need to run two or more chunks of code at once within the same file</li>\n</ul>\n<p><strong>Simple Example</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">while</span> i<span class=\"token operator\">&lt;</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Countdown:'</span><span class=\"token punctuation\">,</span>i<span class=\"token punctuation\">)</span>\n    i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<h3>Q85. What is the correct syntax for defining an <code class=\"language-text\">__init__()</code> method that sets instance-specific attributes upon creation of a new class instance?</h3>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> attr1<span class=\"token punctuation\">,</span> attr2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    attr1 <span class=\"token operator\">=</span> attr1\n    attr2 <span class=\"token operator\">=</span> attr2</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>attr1<span class=\"token punctuation\">,</span> attr2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    attr1 <span class=\"token operator\">=</span> attr1\n    attr2 <span class=\"token operator\">=</span> attr2</code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> attr1<span class=\"token punctuation\">,</span> attr2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    self<span class=\"token punctuation\">.</span>attr1 <span class=\"token operator\">=</span> attr1\n    self<span class=\"token punctuation\">.</span>attr2 <span class=\"token operator\">=</span> attr2</code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>attr1<span class=\"token punctuation\">,</span> attr2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    self<span class=\"token punctuation\">.</span>attr1 <span class=\"token operator\">=</span> attr1\n    self<span class=\"token punctuation\">.</span>attr2 <span class=\"token operator\">=</span> attr2</code></pre></div>\n<p><strong>Explanation</strong>: When instantiating a new object from a given class, the <code class=\"language-text\">__init__()</code> method will take both <code class=\"language-text\">attr1</code> and <code class=\"language-text\">attr2</code>, and set its values to their corresponding object attribute, that's why the need of using <code class=\"language-text\">self.attr1 = attr1</code> instead of <code class=\"language-text\">attr1 = attr1</code>.</p>\n<h3>Q86. What would this recursive function print if it is called with no parameters?</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">count_recursive</span><span class=\"token punctuation\">(</span>n<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> n <span class=\"token operator\">></span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span>\n\ncount_recursive<span class=\"token punctuation\">(</span>n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">3</span>\n<span class=\"token number\">3</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">3</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">1</span></code></pre></div>\n<ul>\n<li>[ ]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">3</span>\n<span class=\"token number\">3</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">1</span></code></pre></div>\n<ul>\n<li>[✅]</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">3</span></code></pre></div>\n<h3>Q87. In Python, when using sets, you use <strong>_ to calculate the intersection between two sets and _</strong> to calculate the union.</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">Intersect;union</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> |; &#x26;</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] &#x26;; |</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> &#x26;&#x26;; ||</li>\n</ul>\n<h3>Q88. What will this code fragment return?</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> numpy <span class=\"token keyword\">as</span> np\nnp<span class=\"token punctuation\">.</span>ones<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It returns a 5x5 matric; each row will have the values 1,2,3,4,5.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It returns an array with the values 1,2,3,4,5</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It returns five different square matrices filled with ones. The first is 1x1, the second 2x2, and so on to 5x5</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It returns a 5-dimensional array of size 1x2x3x4x5 filled with 1s.</li>\n</ul>\n<p><a href=\"https://www.geeksforgeeks.org/numpy-ones-python/\">Reference</a></p>\n<h3>Q89. You encounter a FileNotFoundException while using just the filename in the <code class=\"language-text\">open</code> function. What might be the easiest solution?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Make sure the file is on the system PATH</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Create a symbolic link to allow better access to the file</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Copy the file to the same directory as where the script is running from</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add the path to the file to the PYTHONPATH environment variable</li>\n</ul>\n<h3>Q90. what will this command return?</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">{</span>x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> x<span class=\"token operator\">%</span><span class=\"token number\">3</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a set of all the multiples of 3 less then 100</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a set of all the number from 0 to 100 multiplied by 3</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a list of all the multiples of 3 less then 100</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a set of all the multiples of 3 less then 100 excluding 0</li>\n</ul>\n<h3>Q91. What does the // operator in Python 3 allow you to do?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Perform integer division</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Perform operations on exponents</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Find the remainder of a division operation</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Perform floating point division</li>\n</ul>\n<h3>Q92. This code provides the _ of the list of numbers</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">21</span><span class=\"token punctuation\">,</span><span class=\"token number\">13</span><span class=\"token punctuation\">,</span><span class=\"token number\">19</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">18</span><span class=\"token punctuation\">]</span>\nnum_list<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nnum_list<span class=\"token punctuation\">[</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>num_list<span class=\"token punctuation\">)</span><span class=\"token operator\">//</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> mean</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> mode</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] median</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> average</li>\n</ul>\n<h3>Q93. Which statement about the class methods is true?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method holds all of the data for a particular class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A class method can modify the state of the class, but it cannot directly modify the state of an instance that inherits from that class.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method is a regular function that belongs to a class, but it must return None</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A class method is similar to a regular function, but a class method does not take any arguments.</li>\n</ul>\n<h3>Q94. What file is imported to use dates in python?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] datetime</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> dateday</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> daytime</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> timedate</li>\n</ul>\n<h3>Q95. What is the correct syntax for defining a class called Game?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def Game(): pass</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def Game: pass</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] class Game: pass</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> class Game(): pass</li>\n</ul>\n<p><a href=\"https://docs.python.org/3/tutorial/classes.html\">reference here</a></p>\n<h3>Q96. What does a class's init() method do?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <strong>init</strong> method makes classes aware of each other if more than one class is defined in a single code file.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <strong>init</strong> method is included to preserve backward compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <strong>init</strong> method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <strong>init</strong> method initializes any imports you may have included at the top of your file.</li>\n</ul>\n<p><a href=\"https://stackoverflow.com/questions/625083/what-init-and-self-do-in-python\">reference here</a></p>\n<h3>Q97. What is the correct syntax for calling an instance method on a class named Game?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my<em>game = Game(self) self.my</em>game.roll_dice()</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] my<em>game = Game() self.my</em>game.roll_dice()</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my<em>game = Game() my</em>game.roll_dice()</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> my<em>game = Game(self) my</em>game.roll_dice(self)</li>\n</ul>\n<h3>Q98. What is the output of this code? (NumPy has been imported as np.)?</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">a = np.array([1,2,3,4])\nprint(a[[False, True, False, False]])</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> {0,2}</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] [2]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> {2}</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [0,2,0,0]</li>\n</ul>\n<h3>Q99. Suppose you have a string variable defined as y=\"stuff;thing;junk;\". What would be the output from this code?</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Z = y.split(‘;')\nlen(z)</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> 17</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] 4</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> 0</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> 3</li>\n</ul>\n<p>explanation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">y=\"stuff;thing;junk\"\n\tlen(z) ==> 3\n\ny=\"stuff;thing;junk;\"\n\tlen(z) ==> 4</code></pre></div>\n<h3>Q100. What is the output of this code?</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">num_list = [1,2,3,4,5]\nnum_list.remove(2)\nprint(num_list)</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [1,2,4,5]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] [1,3,4,5]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [3,4,5]</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [1,2,3]</li>\n</ul>\n<p>explanation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">num_list = [1,2,3,4,5]\n\nnum_list.pop(2)\n\t[1,2,4,5]\n\nnum_list.remove(2)\n\t[1,3,4,5]</code></pre></div>\n<h3>Q101. What is the correct syntax for creating an instance method?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def get<em>next</em>card(): # method body goes here</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def self.get<em>next</em>card(): # method body goes here</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] def get<em>next</em>card(self): # method body goes here</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> def self.get<em>next</em>card(self): # method body goes here</li>\n</ul>"},{"url":"/docs/quick-ref/create-react-app/","relativePath":"docs/quick-ref/create-react-app.md","relativeDir":"docs/quick-ref","base":"create-react-app.md","name":"create-react-app","frontmatter":{"title":"Getting Started W Create React App","excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Getting Started with Create React App</h1>\n<p>This project was bootstrapped with <a href=\"https://github.com/facebook/create-react-app\">Create React App</a>.</p>\n<h2>Available Scripts</h2>\n<p>In the project directory, you can run:</p>\n<h3><code class=\"language-text\">yarn start</code></h3>\n<p>Runs the app in the development mode.<br>\nOpen <a href=\"http://localhost:3000\">http://localhost:3000</a> to view it in the browser.</p>\n<p>The page will reload if you make edits.<br>\nYou will also see any lint errors in the console.</p>\n<h3><code class=\"language-text\">yarn test</code></h3>\n<p>Launches the test runner in the interactive watch mode.<br>\nSee the section about <a href=\"https://facebook.github.io/create-react-app/docs/running-tests\">running tests</a> for more information.</p>\n<h3><code class=\"language-text\">yarn build</code></h3>\n<p>Builds the app for production to the <code class=\"language-text\">build</code> folder.<br>\nIt correctly bundles React in production mode and optimizes the build for the best performance.</p>\n<p>The build is minified and the filenames include the hashes.<br>\nYour app is ready to be deployed!</p>\n<p>See the section about <a href=\"https://facebook.github.io/create-react-app/docs/deployment\">deployment</a> for more information.</p>\n<h3><code class=\"language-text\">yarn eject</code></h3>\n<p><strong>Note: this is a one-way operation. Once you <code class=\"language-text\">eject</code>, you can't go back!</strong></p>\n<p>If you aren't satisfied with the build tool and configuration choices, you can <code class=\"language-text\">eject</code> at any time. This command will remove the single build dependency from your project.</p>\n<p>Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except <code class=\"language-text\">eject</code> will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.</p>\n<p>You don't have to ever use <code class=\"language-text\">eject</code>. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.</p>\n<h2>Learn More</h2>\n<p>You can learn more in the <a href=\"https://facebook.github.io/create-react-app/docs/getting-started\">Create React App documentation</a>.</p>\n<p>To learn React, check out the <a href=\"https://reactjs.org/\">React documentation</a>.</p>\n<h3>Code Splitting</h3>\n<p>This section has moved here: <a href=\"https://facebook.github.io/create-react-app/docs/code-splitting\">https://facebook.github.io/create-react-app/docs/code-splitting</a></p>\n<h3>Analyzing the Bundle Size</h3>\n<p>This section has moved here: <a href=\"https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size\">https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size</a></p>\n<h3>Making a Progressive Web App</h3>\n<p>This section has moved here: <a href=\"https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app\">https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app</a></p>\n<h3>Advanced Configuration</h3>\n<p>This section has moved here: <a href=\"https://facebook.github.io/create-react-app/docs/advanced-configuration\">https://facebook.github.io/create-react-app/docs/advanced-configuration</a></p>\n<h3>Deployment</h3>\n<p>This section has moved here: <a href=\"https://facebook.github.io/create-react-app/docs/deployment\">https://facebook.github.io/create-react-app/docs/deployment</a></p>\n<h3><code class=\"language-text\">yarn build</code> fails to minify</h3>\n<p>This section has moved here: <a href=\"https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify\">https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify</a></p>"},{"url":"/docs/quick-ref/fetch/","relativePath":"docs/quick-ref/fetch.md","relativeDir":"docs/quick-ref","base":"fetch.md","name":"fetch","frontmatter":{"title":"Fetch Quick Ref","weight":0,"excerpt":"Fetch Quick Ref","seo":{"title":"Fetch Quick Ref","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<details>\n<summary> Description</summary>   \n<blockquote>\n<h2>Excerpt</h2>\n<p>The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.</p>\n</blockquote>\n<hr>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\">Fetch API</a> provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/fetch\"><code class=\"language-text\">fetch()</code></a> method that provides an easy, logical way to fetch resources asynchronously across the network.</p>\n<p>This kind of functionality was previously achieved using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\"><code class=\"language-text\">XMLHttpRequest</code></a>. Fetch provides a better alternative that can be easily used by other technologies such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API\" title=\"Service Workers\"><code class=\"language-text\">Service Workers</code></a>. Fetch also provides a single logical place to define other HTTP-related concepts such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS\">CORS</a> and extensions to HTTP.</p>\n<p>The <code class=\"language-text\">fetch</code> specification differs from <code class=\"language-text\">jQuery.ajax()</code> in the following significant ways:</p>\n<ul>\n<li>The Promise returned from <code class=\"language-text\">fetch()</code> <strong>won't reject on HTTP error status</strong> even if the response is an HTTP 404 or 500. Instead, as soon as the server responds with headers, the Promise will resolve normally (with the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Response/ok\" title=\"ok\"><code class=\"language-text\">ok</code></a> property of the response set to false if the response isn't in the range 200 -299), and it will only reject on network failure or if anything prevented the request from completing.</li>\n<li><code class=\"language-text\">fetch()</code> <strong>won't send cross-origin cookies</strong> unless you set the <em>credentials</em> <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters\">init option</a>. (Since <a href=\"https://github.com/whatwg/fetch/pull/585\">April 2018</a>. The spec changed the default credentials policy to <code class=\"language-text\">same-origin</code>. Firefox changed since 61.0b13.)</li>\n</ul>\n<p>A basic fetch request is really simple to set up. Have a look at the following code:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'http://example.com/movies.json'</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span> <span class=\"token operator\">=></span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here we are fetching a JSON file across the network and printing it to the console. The simplest use of <code class=\"language-text\">fetch()</code> takes one argument — the path to the resource you want to fetch — and does not directly return the JSON response body but instead returns a promise that resolves with a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Response\"><code class=\"language-text\">Response</code></a> object.</p>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Response\"><code class=\"language-text\">Response</code></a> object, in turn, does not directly contain the actual JSON response body but is instead a representation of the entire HTTP response. So, to extract the JSON body content from the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Response\"><code class=\"language-text\">Response</code></a> object, we use the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Response/json\" title=\"json()\"><code class=\"language-text\">json()</code></a> method, which returns a second promise that resolves with the result of parsing the response body text as JSON.</p>\n<p><strong>Note:</strong> See the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#body\">Body</a> section for similar methods to extract other types of body content.</p>\n<p>Fetch requests are controlled by the <code class=\"language-text\">connect-src</code> directive of <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy\">Content Security Policy</a> rather than the directive of the resources it's retrieving.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options\" title=\"Permalink to Supplying request options\">Supplying request options</a></h3>\n<p>The <code class=\"language-text\">fetch()</code> method can optionally accept a second parameter, an <code class=\"language-text\">init</code> object that allows you to control a number of different settings:</p>\n<p>See <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/fetch\"><code class=\"language-text\">fetch()</code></a> for the full options available, and more details.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\njs\n<span class=\"token comment\">// Example POST method implementation:</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">postData</span><span class=\"token punctuation\">(</span>url <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Default options are marked with *</span>\n  <span class=\"token keyword\">const</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">method</span><span class=\"token operator\">:</span> <span class=\"token string\">'POST'</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// *GET, POST, PUT, DELETE, etc.</span>\n    <span class=\"token literal-property property\">mode</span><span class=\"token operator\">:</span> <span class=\"token string\">'cors'</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// no-cors, *cors, same-origin</span>\n    <span class=\"token literal-property property\">cache</span><span class=\"token operator\">:</span> <span class=\"token string\">'no-cache'</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// *default, no-cache, reload, force-cache, only-if-cached</span>\n    <span class=\"token literal-property property\">credentials</span><span class=\"token operator\">:</span> <span class=\"token string\">'same-origin'</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// include, *same-origin, omit</span>\n    <span class=\"token literal-property property\">headers</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token string-property property\">'Content-Type'</span><span class=\"token operator\">:</span> <span class=\"token string\">'application/json'</span>\n      <span class=\"token comment\">// 'Content-Type': 'application/x-www-form-urlencoded',</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">redirect</span><span class=\"token operator\">:</span> <span class=\"token string\">'follow'</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// manual, *follow, error</span>\n    <span class=\"token literal-property property\">referrerPolicy</span><span class=\"token operator\">:</span> <span class=\"token string\">'no-referrer'</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url</span>\n    <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span> <span class=\"token comment\">// body data type must match \"Content-Type\" header</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// parses JSON response into native JavaScript objects</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">postData</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://example.com/answer'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">answer</span><span class=\"token operator\">:</span> <span class=\"token number\">42</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// JSON data parsed by `data.json()` call</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Note that <code class=\"language-text\">mode: \"no-cors\"</code> only allows a limited set of headers in the request:</p>\n<ul>\n<li><code class=\"language-text\">Accept</code></li>\n<li><code class=\"language-text\">Accept-Language</code></li>\n<li><code class=\"language-text\">Content-Language</code></li>\n<li><code class=\"language-text\">Content-Type</code> with a value of <code class=\"language-text\">application/x-www-form-urlencoded</code>, <code class=\"language-text\">multipart/form-data</code>, or <code class=\"language-text\">text/plain</code></li>\n</ul>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#sending_a_request_with_credentials_included\" title=\"Permalink to Sending a request with credentials included\">Sending a request with credentials included</a></h3>\n<p>To cause browsers to send a request with credentials included on both same-origin and cross-origin calls, add <code class=\"language-text\">credentials: 'include'</code> to the <code class=\"language-text\">init</code> object you pass to the <code class=\"language-text\">fetch()</code> method.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://example.com'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">credentials</span><span class=\"token operator\">:</span> <span class=\"token string\">'include'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Note:</strong> <code class=\"language-text\">Access-Control-Allow-Origin</code> is prohibited from using a wildcard for requests with <code class=\"language-text\">credentials: 'include'</code>. In such cases, the exact origin must be provided; even if you are using a CORS unblocker extension, the requests will still fail.</p>\n<p><strong>Note:</strong> Browsers should not send credentials in <em>preflight requests</em> irrespective of this setting. For more information see: <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#requests_with_credentials\">CORS > Requests with credentials</a>.</p>\n<p>If you only want to send credentials if the request URL is on the same origin as the calling script, add <code class=\"language-text\">credentials: 'same-origin'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token comment\">// The calling script is on the origin 'https://example.com'</span>\n\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://example.com'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">credentials</span><span class=\"token operator\">:</span> <span class=\"token string\">'same-origin'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To instead ensure browsers don't include credentials in the request, use <code class=\"language-text\">credentials: 'omit'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://example.com'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">credentials</span><span class=\"token operator\">:</span> <span class=\"token string\">'omit'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#uploading_json_data\" title=\"Permalink to Uploading JSON data\">Uploading JSON data</a></h3>\n<p>Use <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/fetch\"><code class=\"language-text\">fetch()</code></a> to POST JSON-encoded data.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">username</span><span class=\"token operator\">:</span> <span class=\"token string\">'example'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://example.com/profile'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">method</span><span class=\"token operator\">:</span> <span class=\"token string\">'POST'</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// or 'PUT'</span>\n  <span class=\"token literal-property property\">headers</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string-property property\">'Content-Type'</span><span class=\"token operator\">:</span> <span class=\"token string\">'application/json'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span> <span class=\"token operator\">=></span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Success:'</span><span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Error:'</span><span class=\"token punctuation\">,</span> error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#uploading_a_file\" title=\"Permalink to Uploading a file\">Uploading a file</a></h3>\n<p>Files can be uploaded using an HTML <code class=\"language-text\">&lt;input type=\"file\" /></code> input element, <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData\" title=\"FormData()\"><code class=\"language-text\">FormData()</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/fetch\"><code class=\"language-text\">fetch()</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> formData <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">FormData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> fileField <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input[type=\"file\"]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nformData<span class=\"token punctuation\">.</span><span class=\"token function\">append</span><span class=\"token punctuation\">(</span><span class=\"token string\">'username'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'abc123'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nformData<span class=\"token punctuation\">.</span><span class=\"token function\">append</span><span class=\"token punctuation\">(</span><span class=\"token string\">'avatar'</span><span class=\"token punctuation\">,</span> fileField<span class=\"token punctuation\">.</span>files<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://example.com/profile/avatar'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">method</span><span class=\"token operator\">:</span> <span class=\"token string\">'PUT'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> formData\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span> <span class=\"token operator\">=></span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Success:'</span><span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Error:'</span><span class=\"token punctuation\">,</span> error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#uploading_multiple_files\" title=\"Permalink to Uploading multiple files\">Uploading multiple files</a></h3>\n<p>Files can be uploaded using an HTML <code class=\"language-text\">&lt;input type=\"file\" multiple /></code> input element, <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData\" title=\"FormData()\"><code class=\"language-text\">FormData()</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/fetch\"><code class=\"language-text\">fetch()</code></a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> formData <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">FormData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> photos <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input[type=\"file\"][multiple]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nformData<span class=\"token punctuation\">.</span><span class=\"token function\">append</span><span class=\"token punctuation\">(</span><span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'My Vegas Vacation'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> photos<span class=\"token punctuation\">.</span>files<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  formData<span class=\"token punctuation\">.</span><span class=\"token function\">append</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">photos_</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span> photos<span class=\"token punctuation\">.</span>files<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://example.com/posts'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">method</span><span class=\"token operator\">:</span> <span class=\"token string\">'POST'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> formData<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span> <span class=\"token operator\">=></span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Success:'</span><span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Error:'</span><span class=\"token punctuation\">,</span> error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#processing_a_text_file_line_by_line\" title=\"Permalink to Processing a text file line by line\">Processing a text file line by line</a></h3>\n<p>The chunks that are read from a response are not broken neatly at line boundaries and are Uint8Arrays, not strings. If you want to fetch a text file and process it line by line, it is up to you to handle these complications. The following example shows one way to do this by creating a line iterator (for simplicity, it assumes the text is UTF-8, and doesn't handle fetch errors).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">makeTextFileLineIterator</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">fileURL</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> utf8Decoder <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TextDecoder</span><span class=\"token punctuation\">(</span><span class=\"token string\">'utf-8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> response <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>fileURL<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> reader <span class=\"token operator\">=</span> response<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">getReader</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> chunk<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">done</span><span class=\"token operator\">:</span> readerDone <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> reader<span class=\"token punctuation\">.</span><span class=\"token function\">read</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  chunk <span class=\"token operator\">=</span> chunk <span class=\"token operator\">?</span> utf8Decoder<span class=\"token punctuation\">.</span><span class=\"token function\">decode</span><span class=\"token punctuation\">(</span>chunk<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">const</span> re <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\n|\\r|\\r\\n</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">gm</span></span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> startIndex <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> result<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>chunk<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>result<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>readerDone<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n      <span class=\"token keyword\">let</span> remainder <span class=\"token operator\">=</span> chunk<span class=\"token punctuation\">.</span><span class=\"token function\">substr</span><span class=\"token punctuation\">(</span>startIndex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> chunk<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">done</span><span class=\"token operator\">:</span> readerDone <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> reader<span class=\"token punctuation\">.</span><span class=\"token function\">read</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      chunk <span class=\"token operator\">=</span> remainder <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>chunk <span class=\"token operator\">?</span> utf8Decoder<span class=\"token punctuation\">.</span><span class=\"token function\">decode</span><span class=\"token punctuation\">(</span>chunk<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      startIndex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span>lastIndex <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">yield</span> chunk<span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span>startIndex<span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    startIndex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span>lastIndex<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>startIndex <span class=\"token operator\">&lt;</span> chunk<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// last line didn't end in a newline char</span>\n    <span class=\"token keyword\">yield</span> chunk<span class=\"token punctuation\">.</span><span class=\"token function\">substr</span><span class=\"token punctuation\">(</span>startIndex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">for</span> <span class=\"token keyword\">await</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> line <span class=\"token keyword\">of</span> <span class=\"token function\">makeTextFileLineIterator</span><span class=\"token punctuation\">(</span>urlOfFile<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">processLine</span><span class=\"token punctuation\">(</span>line<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#checking_that_the_fetch_was_successful\" title=\"Permalink to Checking that the fetch was successful\">Checking that the fetch was successful</a></h3>\n<p>A <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/fetch\"><code class=\"language-text\">fetch()</code></a> promise will reject with a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError\"><code class=\"language-text\">TypeError</code></a> when a network error is encountered or CORS is misconfigured on the server-side, although this usually means permission issues or similar — a 404 does not constitute a network error, for example. An accurate check for a successful <code class=\"language-text\">fetch()</code> would include checking that the promise resolved, then checking that the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Response/ok\"><code class=\"language-text\">Response.ok</code></a> property has a value of true. The code would look something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fetch('flowers.jpg')\n  .then(response => {\n    if (!response.ok) {\n      throw new Error('Network response was not OK');\n    }\n    return response.blob();\n  })\n  .then(myBlob => {\n    myImage.src = URL.createObjectURL(myBlob);\n  })\n  .catch(error => {\n    console.error('There has been a problem with your fetch operation:', error);\n  });</code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_your_own_request_object\" title=\"Permalink to Supplying your own request object\">Supplying your own request object</a></h3>\n<p>Instead of passing a path to the resource you want to request into the <code class=\"language-text\">fetch()</code> call, you can create a request object using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Request/Request\" title=\"Request()\"><code class=\"language-text\">Request()</code></a> constructor, and pass that in as a <code class=\"language-text\">fetch()</code> method argument:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myHeaders = new Headers();\n\nconst myRequest = new Request('flowers.jpg', {\n  method: 'GET',\n  headers: myHeaders,\n  mode: 'cors',\n  cache: 'default',\n});\n\nfetch(myRequest)\n  .then(response => response.blob())\n  .then(myBlob => {\n    myImage.src = URL.createObjectURL(myBlob);\n  });</code></pre></div>\n<p><code class=\"language-text\">Request()</code> accepts exactly the same parameters as the <code class=\"language-text\">fetch()</code> method. You can even pass in an existing request object to create a copy of it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const anotherRequest = new Request(myRequest, myInit);</code></pre></div>\n<p>This is pretty useful, as request and response bodies are one use only. Making a copy like this allows you to make use of the request/response again while varying the <code class=\"language-text\">init</code> options if desired. The copy must be made before the body is read, and reading the body in the copy will also mark it as read in the original request.</p>\n<p><strong>Note:</strong> There is also a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Request/clone\" title=\"clone()\"><code class=\"language-text\">clone()</code></a> method that creates a copy. Both methods of creating a copy will fail if the body of the original request or response has already been read, but reading the body of a cloned response or request will not cause it to be marked as read in the original.</p>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Headers\"><code class=\"language-text\">Headers</code></a> interface allows you to create your own headers object via the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers\" title=\"Headers()\"><code class=\"language-text\">Headers()</code></a> constructor. A headers object is a simple multi-map of names to values:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const content = 'Hello World';\nconst myHeaders = new Headers();\nmyHeaders.append('Content-Type', 'text/plain');\nmyHeaders.append('Content-Length', content.length.toString());\nmyHeaders.append('X-Custom-Header', 'ProcessThisImmediately');</code></pre></div>\n<p>The same can be achieved by passing an array of arrays or an object literal to the constructor:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myHeaders = new Headers({\n  'Content-Type': 'text/plain',\n  'Content-Length': content.length.toString(),\n  'X-Custom-Header': 'ProcessThisImmediately'\n});</code></pre></div>\n<p>The contents can be queried and retrieved:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(myHeaders.has('Content-Type')); // true\nconsole.log(myHeaders.has('Set-Cookie')); // false\nmyHeaders.set('Content-Type', 'text/html');\nmyHeaders.append('X-Custom-Header', 'AnotherValue');\n\nconsole.log(myHeaders.get('Content-Length')); // 11\nconsole.log(myHeaders.get('X-Custom-Header')); // ['ProcessThisImmediately', 'AnotherValue']\n\nmyHeaders.delete('X-Custom-Header');\nconsole.log(myHeaders.get('X-Custom-Header')); // null</code></pre></div>\n<p>Some of these operations are only useful in <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API\" title=\"ServiceWorkers\"><code class=\"language-text\">ServiceWorkers</code></a>, but they provide a much nicer API for manipulating headers.</p>\n<p>All of the Headers methods throw a <code class=\"language-text\">TypeError</code> if a header name is used that is not a valid HTTP Header name. The mutation operations will throw a <code class=\"language-text\">TypeError</code> if there is an immutable guard (<a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#guard\">see below</a>). Otherwise, they fail silently. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myResponse = Response.error();\ntry {\n  myResponse.headers.set('Origin', 'http://mybank.com');\n} catch (e) {\n  console.log('Cannot pretend to be a bank!');\n}</code></pre></div>\n<p>A good use case for headers is checking whether the content type is correct before you process it further. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fetch(myRequest)\n  .then(response => {\n     const contentType = response.headers.get('content-type');\n     if (!contentType || !contentType.includes('application/json')) {\n       throw new TypeError(\"Oops, we haven't got JSON!\");\n     }\n     return response.json();\n  })\n  .then(data => {\n      /* process your data further */\n  })\n  .catch(error => console.error(error));</code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#guard\" title=\"Permalink to Guard\">Guard</a></h3>\n<p>Since headers can be sent in requests and received in responses, and have various limitations about what information can and should be mutable, headers' objects have a <em>guard</em> property. This is not exposed to the Web, but it affects which mutation operations are allowed on the headers object.</p>\n</details>\n<h1>Fetch</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/data.json'</span><span class=\"token punctuation\">)</span>  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span> <span class=\"token operator\">=></span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span>  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span> <span class=\"token operator\">=></span> <span class=\"token operator\">...</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Response</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/data.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">res</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>  res<span class=\"token punctuation\">.</span><span class=\"token function\">text</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>       <span class=\"token comment\">// response body (=> Promise)  res.json()       // parse via JSON (=> Promise)  res.status       //=> 200  res.statusText   //=> 'OK'  res.redirected   //=> false  res.ok           //=> true  res.url          //=> 'http://site.com/data.json'  res.type         //=> 'basic'                   //   ('cors' 'default' 'error'                   //    'opaque' 'opaqueredirect')</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  res<span class=\"token punctuation\">.</span>headers<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Content-Type'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Request options</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/data.json'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>  <span class=\"token literal-property property\">method</span><span class=\"token operator\">:</span> <span class=\"token string\">'post'</span><span class=\"token punctuation\">,</span>  <span class=\"token literal-property property\">body</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">FormData</span><span class=\"token punctuation\">(</span>form<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// post body  body: JSON.stringify(...),</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token literal-property property\">headers</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>    <span class=\"token string-property property\">'Accept'</span><span class=\"token operator\">:</span> <span class=\"token string\">'application/json'</span>  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token literal-property property\">credentials</span><span class=\"token operator\">:</span> <span class=\"token string\">'same-origin'</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// send cookies  credentials: 'include',     // send cookies, even in CORS</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Catching errors</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/data.json'</span><span class=\"token punctuation\">)</span>  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>checkStatus<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">checkStatus</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">res</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>res<span class=\"token punctuation\">.</span>status <span class=\"token operator\">>=</span> <span class=\"token number\">200</span> <span class=\"token operator\">&amp;&amp;</span> res<span class=\"token punctuation\">.</span>status <span class=\"token operator\">&lt;</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>    <span class=\"token keyword\">return</span> res  <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>    <span class=\"token keyword\">let</span> err <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span>res<span class=\"token punctuation\">.</span>statusText<span class=\"token punctuation\">)</span>    err<span class=\"token punctuation\">.</span>response <span class=\"token operator\">=</span> res    <span class=\"token keyword\">throw</span> err  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>Non-2xx responses are still successful requests. Use another function to turn them to errors.</p>\n<h3>Using with node.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fetch <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'isomorphic-fetch'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>See: <a href=\"https://npmjs.com/package/isomorphic-fetch\">isomorphic-fetch</a> <em>(npmjs.com)</em></p>"},{"url":"/docs/quick-ref/google-firebase/","relativePath":"docs/quick-ref/google-firebase.md","relativeDir":"docs/quick-ref","base":"google-firebase.md","name":"google-firebase","frontmatter":{"title":"Firebase (Firebasics)","weight":0,"excerpt":"Add Firebase to your JavaScript project Note","seo":{"title":"Add Firebase to your JavaScript project Note:","description":"Add Firebase to your JavaScript project Note:","robots":[],"extra":[]},"template":"docs"},"html":"<p>Add Firebase to your JavaScript project <strong>Note:</strong> Upgrading from the version 8 Firebase SDK? Check out our <a href=\"https://firebase.google.com/docs/web/modular-upgrade\">upgrade guide</a>.<a href=\"\">#### <strong>Create a Firebase project</strong> </a><strong>Note:</strong> Using the v9 SDK is strongly recommended, especially for production apps. If you need support for other SDK management options, like <strong>window.firebase</strong>, see <a href=\"https://firebase.google.com/docs/web/modular-upgrade#window-compat\">Upgrade from version 8 to the modular Web SDK</a>.<strong>Note:</strong> You can skip this step if you are using a JavaScript framework CLI tool like the <a href=\"https://angular.io/cli\">Angular CLI</a>, <a href=\"https://nextjs.org/\">Next.js</a>, <a href=\"https://cli.vuejs.org/\">Vue CLI</a>, or <a href=\"https://reactjs.org/docs/create-a-new-react-app.html\">Create React App</a>. Check out <a href=\"https://firebase.google.com/docs/web/module-bundling\">our guide on module bundling</a> for more information.</p>\n<p>Follow this guide to use the Firebase JavaScript SDK in your web app or as a client for end-user access, for example, in a Node.js desktop or IoT application.</p>\n<h2><strong>Step 1</strong>: Create a Firebase project and register your app</h2>\n<p>Before you can add Firebase to your JavaScript app, you need to create a Firebase project and register your app with that project. When you register your app with Firebase, you'll get a Firebase configuration object that you'll use to connect your app with your Firebase project resources.</p>\n<p>Visit <a href=\"https://firebase.google.com/docs/projects/learn-more\">Understand Firebase Projects</a> to learn more about Firebase projects and best practices for adding apps to projects.</p>\n<p>If you don't already have a JavaScript project and just want to try out a Firebase product, you can download one of our <a href=\"https://firebase.google.com/docs/samples\">quickstart samples</a>.</p>\n<h2><strong>Step 2</strong>: Install the SDK and initialize Firebase</h2>\n<p>This page describes setup instructions for version 9 of the Firebase JS SDK, which uses a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules\">JavaScript Module</a> format.</p>\n<p>This workflow uses npm and requires module bundlers or JavaScript framework tooling because the v9 SDK is optimized to work with <a href=\"https://firebase.google.com/docs/web/module-bundling\">module bundlers</a> to eliminate unused code (tree-shaking) and decrease SDK size.</p>\n<ol>\n<li>Install Firebase using npm:</li>\n<li>\n<p>Initialize Firebase in your app and create a Firebase App object:</p>\n<p>A Firebase App is a container-like object that stores common configuration and shares authentication across Firebase services. After you initialize a Firebase App object in your code, you can add and start using Firebase services.</p>\n<p>Do you use ESM and want to use browser modules? Replace all your</p>\n<p><strong>import</strong></p>\n<p>lines to use the following pattern:</p>\n<p><strong>import { } from '<a href=\"https://www.gstatic.com/firebasejs/9.0.2/firebase-SERVICE.js\">https://www.gstatic.com/firebasejs/9.0.2/firebase-SERVICE.js</a>'</strong></p>\n<p>(where</p>\n<p><strong>SERVICE</strong></p>\n<p>is an SDK name such as</p>\n<p><strong>firebase-firestore</strong></p>\n<p>).</p>\n<p>Using browser modules is a quick way to get started, but we recommend using a module bundler for production.</p>\n</li>\n</ol>\n<h2><strong>Step 3</strong>: Access Firebase in your app</h2>\n<p>Firebase services (like Cloud Firestore, Authentication, Realtime Database, Remote Config, and more) are available to import within individual sub-packages.</p>\n<p>The example below shows how you could use the Cloud Firestore Lite SDK to retrieve a list of data.</p>\n<h2><strong>Step 4</strong>: Use a module bundler (webpack/Rollup) for size reduction</h2>\n<p>The Firebase Web SDK is designed to work with module bundlers to remove any unused code (tree-shaking). We strongly recommend using this approach for production apps. Tools such as the <a href=\"https://angular.io/cli\">Angular CLI</a>, <a href=\"https://nextjs.org/\">Next.js</a>, <a href=\"https://cli.vuejs.org/\">Vue CLI</a>, or <a href=\"https://reactjs.org/docs/create-a-new-react-app.html\">Create React App</a> automatically handle module bundling for libraries installed through npm and imported into your codebase.</p>\n<p>See our guide <a href=\"https://firebase.google.com/docs/web/module-bundling\">Using module bundlers with Firebase</a> for more information.</p>"},{"url":"/docs/quick-ref/git-bash/","relativePath":"docs/quick-ref/git-bash.md","relativeDir":"docs/quick-ref","base":"git-bash.md","name":"git-bash","frontmatter":{"title":"Git Bash","weight":0,"excerpt":"Git Bash","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Git Bash‌‌‌‌‌‌‌‌‌‌‌‌‌‌‌\n\n</h1>\n<p>At its core, Git is a set of command line utility programs that are designed to execute on a Unix style command-line environment. Modern operating systems like Linux and macOS both include built-in Unix command line terminals. This makes Linux and macOS complementary operating systems when working with Git. Microsoft Windows instead uses Windows command prompt, a non-Unix terminal environment.</p>\n<p>In Windows environments, Git is often packaged as part of higher level GUI applications. GUIs for Git may attempt to abstract and hide the underlying version control system primitives. This can be a great aid for Git beginners to rapidly contribute to a project. Once a project's collaboration requirements grow with other team members, it is critical to be aware of how the actual raw Git methods work. This is when it can be beneficial to drop a GUI version for the command line tools. Git Bash is offered to provide a terminal Git experience.</p>\n<h2>What is Git Bash?</h2>\n<p>Git Bash is an application for Microsoft Windows environments which provides an emulation layer for a Git command line experience. Bash is an acronym for Bourne Again Shell. A shell is a terminal application used to interface with an operating system through written commands. Bash is a popular default shell on Linux and macOS. Git Bash is a package that installs Bash, some common bash utilities, and Git on a Windows operating system.</p>\n<h2>How to install Git Bash</h2>\n<p>Git Bash comes included as part of the <a href=\"https://gitforwindows.org/\">Git For Windows</a> package. Download and install Git For Windows like other Windows applications. Once downloaded find the included .exe file and open to execute Git Bash.</p>\n<h2>How to use Git Bash</h2>\n<p>Git Bash has the same operations as a standard Bash experience. It will be helpful to review basic Bash usage. Advanced usage of Bash is outside the scope of this Git focused document.</p>\n<h2>How to navigate folders</h2>\n<p>The Bash command pwd is used to print the 'present working directory'. pwd is equivalent to executing cd on a DOS(Windows console host) terminal. This is the folder or path that the current Bash session resides in.</p>\n<p>The Bash command ls is used to 'list' contents of the current working directory. ls is equivalent to DIR on a Windows console host terminal.</p>\n<p>Both Bash and Windows console host have a cd command. cd is an acronym for 'Change Directory'. cd is invoked with an appended directory name. Executing cd will change the terminal sessions current working directory to the passed directory argument.</p>\n<h2>Git Bash Commands</h2>\n<p>Git Bash is packaged with additional commands that can be found in the /usr/bin directory of the Git Bash emulation. Git Bash can actually provide a fairly robust shell experience on Windows. Git Bash comes packaged with the following shell commands which are outside the scope of this document: <a href=\"https://man.openbsd.org/ssh.1\">Ssh</a>, <a href=\"https://linux.die.net/man/1/scp\">scp</a>, <a href=\"http://man7.org/linux/man-pages/man1/cat.1.html\">cat</a>, <a href=\"https://linux.die.net/man/1/find\">find</a>.</p>\n<p>In addition the previously discussed set of Bash commands, Git Bash includes the full set of Git core commands discussed through out this site. Learn more at the corresponding documentation pages for <a href=\"https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone\">git clone</a>, <a href=\"https://www.atlassian.com/git/tutorials/saving-changes/git-commit\">git commit</a>, <a href=\"https://www.atlassian.com/git/tutorials/using-branches/git-checkout\">git checkout</a>, <a href=\"https://www.atlassian.com/git/tutorials/syncing/git-push\">git push</a>, and more.</p>"},{"url":"/docs/quick-ref/all-emojis/","relativePath":"docs/quick-ref/all-emojis.md","relativeDir":"docs/quick-ref","base":"all-emojis.md","name":"all-emojis","frontmatter":{"title":"All Emojis","weight":0,"excerpt":"All Emojis","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>All Emojis</h2>\n<p>😀 😃 😄 😁 😆 😅 😂 🤣 🥲 ☺️ 😊 😇 🙂 🙃 😉 😌 😍 🥰 😘 😗 😙 😚 😋 😛 😝 😜 🤪 🤨 🧐 🤓 😎 🥸 🤩 🥳 😏 😒 😞 😔 😟 😕 🙁 ☹️ 😣 😖 😫 😩 🥺 😢 😭 😤 😠 😡 🤬 🤯 😳 🥵 🥶 😱 😨 😰 😥 😓 🤗 🤔 🤭 🤫 🤥 😶 😐 😑 😬 🙄 😯 😦 😧 😮 😲 🥱 😴 🤤 😪 😵 🤐 🥴 🤢 🤮 🤧 😷 🤒 🤕 🤑 🤠 😈 👿 👹 👺 🤡 💩 👻 💀 ☠️ 👽 👾 🤖 🎃 😺 😸 😹 😻 😼 😽 🙀 😿 😾</p>\n<h3><a href=\"https://emojipedia.org/people/\" title=\"List of people and fantasy emojis\">Gestures and Body Parts</a></h3>\n<p>👋 🤚 🖐 ✋ 🖖 👌 🤌 🤏 ✌️ 🤞 🤟 🤘 🤙 👈 👉 👆 🖕 👇 ☝️ 👍 👎 ✊ 👊 🤛 🤜 👏 🙌 👐 🤲 🤝 🙏 ✍️ 💅 🤳 💪 🦾 🦵 🦿 🦶 👣 👂 🦻 👃 🫀 🫁 🧠 🦷 🦴 👀 👁 👅 👄 💋 🩸</p>\n<h3><a href=\"https://emojipedia.org/people/\" title=\"List of people and fantasy emojis\">People and Fantasy</a></h3>\n<p>👶 👧 🧒 👦 👩 🧑 👨 👩‍🦱 🧑‍🦱 👨‍🦱 👩‍🦰 🧑‍🦰 👨‍🦰 👱‍♀️ 👱 👱‍♂️ 👩‍🦳 🧑‍🦳 👨‍🦳 👩‍🦲 🧑‍🦲 👨‍🦲 🧔 👵 🧓 👴 👲 👳‍♀️ 👳 👳‍♂️ 🧕 👮‍♀️ 👮 👮‍♂️ 👷‍♀️ 👷 👷‍♂️ 💂‍♀️ 💂 💂‍♂️ 🕵️‍♀️ 🕵️ 🕵️‍♂️ 👩‍⚕️ 🧑‍⚕️ 👨‍⚕️ 👩‍🌾 🧑‍🌾 👨‍🌾 👩‍🍳 🧑‍🍳 👨‍🍳 👩‍🎓 🧑‍🎓 👨‍🎓 👩‍🎤 🧑‍🎤 👨‍🎤 👩‍🏫 🧑‍🏫 👨‍🏫 👩‍🏭 🧑‍🏭 👨‍🏭 👩‍💻 🧑‍💻 👨‍💻 👩‍💼 🧑‍💼 👨‍💼 👩‍🔧 🧑‍🔧 👨‍🔧 👩‍🔬 🧑‍🔬 👨‍🔬 👩‍🎨 🧑‍🎨 👨‍🎨 👩‍🚒 🧑‍🚒 👨‍🚒 👩‍✈️ 🧑‍✈️ 👨‍✈️ 👩‍🚀 🧑‍🚀 👨‍🚀 👩‍⚖️ 🧑‍⚖️ 👨‍⚖️ 👰‍♀️ 👰 👰‍♂️ 🤵‍♀️ 🤵 🤵‍♂️ 👸 🤴 🥷 🦸‍♀️ 🦸 🦸‍♂️ 🦹‍♀️ 🦹 🦹‍♂️ 🤶 🧑‍🎄 🎅 🧙‍♀️ 🧙 🧙‍♂️ 🧝‍♀️ 🧝 🧝‍♂️ 🧛‍♀️ 🧛 🧛‍♂️ 🧟‍♀️ 🧟 🧟‍♂️ 🧞‍♀️ 🧞 🧞‍♂️ 🧜‍♀️ 🧜 🧜‍♂️ 🧚‍♀️ 🧚 🧚‍♂️ 👼 🤰 🤱 👩‍🍼 🧑‍🍼 👨‍🍼 🙇‍♀️ 🙇 🙇‍♂️ 💁‍♀️ 💁 💁‍♂️ 🙅‍♀️ 🙅 🙅‍♂️ 🙆‍♀️ 🙆 🙆‍♂️ 🙋‍♀️ 🙋 🙋‍♂️ 🧏‍♀️ 🧏 🧏‍♂️ 🤦‍♀️ 🤦 🤦‍♂️ 🤷‍♀️ 🤷 🤷‍♂️ 🙎‍♀️ 🙎 🙎‍♂️ 🙍‍♀️ 🙍 🙍‍♂️ 💇‍♀️ 💇 💇‍♂️ 💆‍♀️ 💆 💆‍♂️ 🧖‍♀️ 🧖 🧖‍♂️ 💅 🤳 💃 🕺 👯‍♀️ 👯 👯‍♂️ 🕴 👩‍🦽 🧑‍🦽 👨‍🦽 👩‍🦼 🧑‍🦼 👨‍🦼 🚶‍♀️ 🚶 🚶‍♂️ 👩‍🦯 🧑‍🦯 👨‍🦯 🧎‍♀️ 🧎 🧎‍♂️ 🏃‍♀️ 🏃 🏃‍♂️ 🧍‍♀️ 🧍 🧍‍♂️ 👭 🧑‍🤝‍🧑 👬 👫 👩‍❤️‍👩 💑 👨‍❤️‍👨 👩‍❤️‍👨 👩‍❤️‍💋‍👩 💏 👨‍❤️‍💋‍👨 👩‍❤️‍💋‍👨 👪 👨‍👩‍👦 👨‍👩‍👧 👨‍👩‍👧‍👦 👨‍👩‍👦‍👦 👨‍👩‍👧‍👧 👨‍👨‍👦 👨‍👨‍👧 👨‍👨‍👧‍👦 👨‍👨‍👦‍👦 👨‍👨‍👧‍👧 👩‍👩‍👦 👩‍👩‍👧 👩‍👩‍👧‍👦 👩‍👩‍👦‍👦 👩‍👩‍👧‍👧 👨‍👦 👨‍👦‍👦 👨‍👧 👨‍👧‍👦 👨‍👧‍👧 👩‍👦 👩‍👦‍👦 👩‍👧 👩‍👧‍👦 👩‍👧‍👧 🗣 👤 👥 🫂</p>\n<h3><a href=\"https://emojipedia.org/people/\" title=\"List of clothing emojis\">Clothing and Accessories</a></h3>\n<p>🧳 🌂 ☂️ 🧵 🪡 🪢 🧶 👓 🕶 🥽 🥼 🦺 👔 👕 👖 🧣 🧤 🧥 🧦 👗 👘 🥻 🩴 🩱 🩲 🩳 👙 👚 👛 👜 👝 🎒 👞 👟 🥾 🥿 👠 👡 🩰 👢 👑 👒 🎩 🎓 🧢 ⛑ 🪖 💄 💍 💼</p>\n<h3><a href=\"https://emojipedia.org/light-skin-tone/\" title=\"List of light skin tone emojis\">Pale Emojis</a></h3>\n<p>👋🏻 🤚🏻 🖐🏻 ✋🏻 🖖🏻 👌🏻 🤌🏻 🤏🏻 ✌🏻 🤞🏻 🤟🏻 🤘🏻 🤙🏻 👈🏻 👉🏻 👆🏻 🖕🏻 👇🏻 ☝🏻 👍🏻 👎🏻 ✊🏻 👊🏻 🤛🏻 🤜🏻 👏🏻 🙌🏻 👐🏻 🤲🏻 🙏🏻 ✍🏻 💅🏻 🤳🏻 💪🏻 🦵🏻 🦶🏻 👂🏻 🦻🏻 👃🏻 👶🏻 👧🏻 🧒🏻 👦🏻 👩🏻 🧑🏻 👨🏻 👩🏻‍🦱 🧑🏻‍🦱 👨🏻‍🦱 👩🏻‍🦰 🧑🏻‍🦰 👨🏻‍🦰 👱🏻‍♀️ 👱🏻 👱🏻‍♂️ 👩🏻‍🦳 🧑🏻‍🦳 👨🏻‍🦳 👩🏻‍🦲 🧑🏻‍🦲 👨🏻‍🦲 🧔🏻 👵🏻 🧓🏻 👴🏻 👲🏻 👳🏻‍♀️ 👳🏻 👳🏻‍♂️ 🧕🏻 👮🏻‍♀️ 👮🏻 👮🏻‍♂️ 👷🏻‍♀️ 👷🏻 👷🏻‍♂️ 💂🏻‍♀️ 💂🏻 💂🏻‍♂️ 🕵🏻‍♀️ 🕵🏻 🕵🏻‍♂️ 👩🏻‍⚕️ 🧑🏻‍⚕️ 👨🏻‍⚕️ 👩🏻‍🌾 🧑🏻‍🌾 👨🏻‍🌾 👩🏻‍🍳 🧑🏻‍🍳 👨🏻‍🍳 👩🏻‍🎓 🧑🏻‍🎓 👨🏻‍🎓 👩🏻‍🎤 🧑🏻‍🎤 👨🏻‍🎤 👩🏻‍🏫 🧑🏻‍🏫 👨🏻‍🏫 👩🏻‍🏭 🧑🏻‍🏭 👨🏻‍🏭 👩🏻‍💻 🧑🏻‍💻 👨🏻‍💻 👩🏻‍💼 🧑🏻‍💼 👨🏻‍💼 👩🏻‍🔧 🧑🏻‍🔧 👨🏻‍🔧 👩🏻‍🔬 🧑🏻‍🔬 👨🏻‍🔬 👩🏻‍🎨 🧑🏻‍🎨 👨🏻‍🎨 👩🏻‍🚒 🧑🏻‍🚒 👨🏻‍🚒 👩🏻‍✈️ 🧑🏻‍✈️ 👨🏻‍✈️ 👩🏻‍🚀 🧑🏻‍🚀 👨🏻‍🚀 👩🏻‍⚖️ 🧑🏻‍⚖️ 👨🏻‍⚖️ 👰🏻‍♀️ 👰🏻 👰🏻‍♂️ 🤵🏻‍♀️ 🤵🏻 🤵🏻‍♂️ 👸🏻 🤴🏻 🥷🏻 🦸🏻‍♀️ 🦸🏻 🦸🏻‍♂️ 🦹🏻‍♀️ 🦹🏻 🦹🏻‍♂️ 🤶🏻 🧑🏻‍🎄 🎅🏻 🧙🏻‍♀️ 🧙🏻 🧙🏻‍♂️ 🧝🏻‍♀️ 🧝🏻 🧝🏻‍♂️ 🧛🏻‍♀️ 🧛🏻 🧛🏻‍♂️ 🧜🏻‍♀️ 🧜🏻 🧜🏻‍♂️ 🧚🏻‍♀️ 🧚🏻 🧚🏻‍♂️ 👼🏻 🤰🏻 🤱🏻 👩🏻‍🍼 🧑🏻‍🍼 👨🏻‍🍼 🙇🏻‍♀️ 🙇🏻 🙇🏻‍♂️ 💁🏻‍♀️ 💁🏻 💁🏻‍♂️ 🙅🏻‍♀️ 🙅🏻 🙅🏻‍♂️ 🙆🏻‍♀️ 🙆🏻 🙆🏻‍♂️ 🙋🏻‍♀️ 🙋🏻 🙋🏻‍♂️ 🧏🏻‍♀️ 🧏🏻 🧏🏻‍♂️ 🤦🏻‍♀️ 🤦🏻 🤦🏻‍♂️ 🤷🏻‍♀️ 🤷🏻 🤷🏻‍♂️ 🙎🏻‍♀️ 🙎🏻 🙎🏻‍♂️ 🙍🏻‍♀️ 🙍🏻 🙍🏻‍♂️ 💇🏻‍♀️ 💇🏻 💇🏻‍♂️ 💆🏻‍♀️ 💆🏻 💆🏻‍♂️ 🧖🏻‍♀️ 🧖🏻 🧖🏻‍♂️ 💃🏻 🕺🏻 🕴🏻 👩🏻‍🦽 🧑🏻‍🦽 👨🏻‍🦽 👩🏻‍🦼 🧑🏻‍🦼 👨🏻‍🦼 🚶🏻‍♀️ 🚶🏻 🚶🏻‍♂️ 👩🏻‍🦯 🧑🏻‍🦯 👨🏻‍🦯 🧎🏻‍♀️ 🧎🏻 🧎🏻‍♂️ 🏃🏻‍♀️ 🏃🏻 🏃🏻‍♂️ 🧍🏻‍♀️ 🧍🏻 🧍🏻‍♂️ 👭🏻 🧑🏻‍🤝‍🧑🏻 👬🏻 👫🏻 🧗🏻‍♀️ 🧗🏻 🧗🏻‍♂️ 🏇🏻 🏂🏻 🏌🏻‍♀️ 🏌🏻 🏌🏻‍♂️ 🏄🏻‍♀️ 🏄🏻 🏄🏻‍♂️ 🚣🏻‍♀️ 🚣🏻 🚣🏻‍♂️ 🏊🏻‍♀️ 🏊🏻 🏊🏻‍♂️ ⛹🏻‍♀️ ⛹🏻 ⛹🏻‍♂️ 🏋🏻‍♀️ 🏋🏻 🏋🏻‍♂️ 🚴🏻‍♀️ 🚴🏻 🚴🏻‍♂️ 🚵🏻‍♀️ 🚵🏻 🚵🏻‍♂️ 🤸🏻‍♀️ 🤸🏻 🤸🏻‍♂️ 🤽🏻‍♀️ 🤽🏻 🤽🏻‍♂️ 🤾🏻‍♀️ 🤾🏻 🤾🏻‍♂️ 🤹🏻‍♀️ 🤹🏻 🤹🏻‍♂️ 🧘🏻‍♀️ 🧘🏻 🧘🏻‍♂️ 🛀🏻 🛌🏻</p>\n<h3><a href=\"https://emojipedia.org/medium-light-skin-tone/\" title=\"List of medium light skin tone emojis\">Cream White Emojis</a></h3>\n<p>👋🏼 🤚🏼 🖐🏼 ✋🏼 🖖🏼 👌🏼 🤌🏼 🤏🏼 ✌🏼 🤞🏼 🤟🏼 🤘🏼 🤙🏼 👈🏼 👉🏼 👆🏼 🖕🏼 👇🏼 ☝🏼 👍🏼 👎🏼 ✊🏼 👊🏼 🤛🏼 🤜🏼 👏🏼 🙌🏼 👐🏼 🤲🏼 🙏🏼 ✍🏼 💅🏼 🤳🏼 💪🏼 🦵🏼 🦶🏼 👂🏼 🦻🏼 👃🏼 👶🏼 👧🏼 🧒🏼 👦🏼 👩🏼 🧑🏼 👨🏼 👩🏼‍🦱 🧑🏼‍🦱 👨🏼‍🦱 👩🏼‍🦰 🧑🏼‍🦰 👨🏼‍🦰 👱🏼‍♀️ 👱🏼 👱🏼‍♂️ 👩🏼‍🦳 🧑🏼‍🦳 👨🏼‍🦳 👩🏼‍🦲 🧑🏼‍🦲 👨🏼‍🦲 🧔🏼 👵🏼 🧓🏼 👴🏼 👲🏼 👳🏼‍♀️ 👳🏼 👳🏼‍♂️ 🧕🏼 👮🏼‍♀️ 👮🏼 👮🏼‍♂️ 👷🏼‍♀️ 👷🏼 👷🏼‍♂️ 💂🏼‍♀️ 💂🏼 💂🏼‍♂️ 🕵🏼‍♀️ 🕵🏼 🕵🏼‍♂️ 👩🏼‍⚕️ 🧑🏼‍⚕️ 👨🏼‍⚕️ 👩🏼‍🌾 🧑🏼‍🌾 👨🏼‍🌾 👩🏼‍🍳 🧑🏼‍🍳 👨🏼‍🍳 👩🏼‍🎓 🧑🏼‍🎓 👨🏼‍🎓 👩🏼‍🎤 🧑🏼‍🎤 👨🏼‍🎤 👩🏼‍🏫 🧑🏼‍🏫 👨🏼‍🏫 👩🏼‍🏭 🧑🏼‍🏭 👨🏼‍🏭 👩🏼‍💻 🧑🏼‍💻 👨🏼‍💻 👩🏼‍💼 🧑🏼‍💼 👨🏼‍💼 👩🏼‍🔧 🧑🏼‍🔧 👨🏼‍🔧 👩🏼‍🔬 🧑🏼‍🔬 👨🏼‍🔬 👩🏼‍🎨 🧑🏼‍🎨 👨🏼‍🎨 👩🏼‍🚒 🧑🏼‍🚒 👨🏼‍🚒 👩🏼‍✈️ 🧑🏼‍✈️ 👨🏼‍✈️ 👩🏼‍🚀 🧑🏼‍🚀 👨🏼‍🚀 👩🏼‍⚖️ 🧑🏼‍⚖️ 👨🏼‍⚖️ 👰🏼‍♀️ 👰🏼 👰🏼‍♂️ 🤵🏼‍♀️ 🤵🏼 🤵🏼‍♂️ 👸🏼 🤴🏼 🥷🏼 🦸🏼‍♀️ 🦸🏼 🦸🏼‍♂️ 🦹🏼‍♀️ 🦹🏼 🦹🏼‍♂️ 🤶🏼 🧑🏼‍🎄 🎅🏼 🧙🏼‍♀️ 🧙🏼 🧙🏼‍♂️ 🧝🏼‍♀️ 🧝🏼 🧝🏼‍♂️ 🧛🏼‍♀️ 🧛🏼 🧛🏼‍♂️ 🧜🏼‍♀️ 🧜🏼 🧜🏼‍♂️ 🧚🏼‍♀️ 🧚🏼 🧚🏼‍♂️ 👼🏼 🤰🏼 🤱🏼 👩🏼‍🍼 🧑🏼‍🍼 👨🏼‍🍼 🙇🏼‍♀️ 🙇🏼 🙇🏼‍♂️ 💁🏼‍♀️ 💁🏼 💁🏼‍♂️ 🙅🏼‍♀️ 🙅🏼 🙅🏼‍♂️ 🙆🏼‍♀️ 🙆🏼 🙆🏼‍♂️ 🙋🏼‍♀️ 🙋🏼 🙋🏼‍♂️ 🧏🏼‍♀️ 🧏🏼 🧏🏼‍♂️ 🤦🏼‍♀️ 🤦🏼 🤦🏼‍♂️ 🤷🏼‍♀️ 🤷🏼 🤷🏼‍♂️ 🙎🏼‍♀️ 🙎🏼 🙎🏼‍♂️ 🙍🏼‍♀️ 🙍🏼 🙍🏼‍♂️ 💇🏼‍♀️ 💇🏼 💇🏼‍♂️ 💆🏼‍♀️ 💆🏼 💆🏼‍♂️ 🧖🏼‍♀️ 🧖🏼 🧖🏼‍♂️ 💃🏼 🕺🏼 🕴🏼 👩🏼‍🦽 🧑🏼‍🦽 👨🏼‍🦽 👩🏼‍🦼 🧑🏼‍🦼 👨🏼‍🦼 🚶🏼‍♀️ 🚶🏼 🚶🏼‍♂️ 👩🏼‍🦯 🧑🏼‍🦯 👨🏼‍🦯 🧎🏼‍♀️ 🧎🏼 🧎🏼‍♂️ 🏃🏼‍♀️ 🏃🏼 🏃🏼‍♂️ 🧍🏼‍♀️ 🧍🏼 🧍🏼‍♂️ 👭🏼 🧑🏼‍🤝‍🧑🏼 👬🏼 👫🏼 🧗🏼‍♀️ 🧗🏼 🧗🏼‍♂️ 🏇🏼 🏂🏼 🏌🏼‍♀️ 🏌🏼 🏌🏼‍♂️ 🏄🏼‍♀️ 🏄🏼 🏄🏼‍♂️ 🚣🏼‍♀️ 🚣🏼 🚣🏼‍♂️ 🏊🏼‍♀️ 🏊🏼 🏊🏼‍♂️ ⛹🏼‍♀️ ⛹🏼 ⛹🏼‍♂️ 🏋🏼‍♀️ 🏋🏼 🏋🏼‍♂️ 🚴🏼‍♀️ 🚴🏼 🚴🏼‍♂️ 🚵🏼‍♀️ 🚵🏼 🚵🏼‍♂️ 🤸🏼‍♀️ 🤸🏼 🤸🏼‍♂️ 🤽🏼‍♀️ 🤽🏼 🤽🏼‍♂️ 🤾🏼‍♀️ 🤾🏼 🤾🏼‍♂️ 🤹🏼‍♀️ 🤹🏼 🤹🏼‍♂️ 🧘🏼‍♀️ 🧘🏼 🧘🏼‍♂️ 🛀🏼 🛌🏼</p>\n<h3><a href=\"https://emojipedia.org/medium-skin-tone/\" title=\"List of medium skin tone emojis\">Brown Emojis</a></h3>\n<p>👋🏽 🤚🏽 🖐🏽 ✋🏽 🖖🏽 👌🏽 🤌🏽 🤏🏽 ✌🏽 🤞🏽 🤟🏽 🤘🏽 🤙🏽 👈🏽 👉🏽 👆🏽 🖕🏽 👇🏽 ☝🏽 👍🏽 👎🏽 ✊🏽 👊🏽 🤛🏽 🤜🏽 👏🏽 🙌🏽 👐🏽 🤲🏽 🙏🏽 ✍🏽 💅🏽 🤳🏽 💪🏽 🦵🏽 🦶🏽 👂🏽 🦻🏽 👃🏽 👶🏽 👧🏽 🧒🏽 👦🏽 👩🏽 🧑🏽 👨🏽 👩🏽‍🦱 🧑🏽‍🦱 👨🏽‍🦱 👩🏽‍🦰 🧑🏽‍🦰 👨🏽‍🦰 👱🏽‍♀️ 👱🏽 👱🏽‍♂️ 👩🏽‍🦳 🧑🏽‍🦳 👨🏽‍🦳 👩🏽‍🦲 🧑🏽‍🦲 👨🏽‍🦲 🧔🏽 👵🏽 🧓🏽 👴🏽 👲🏽 👳🏽‍♀️ 👳🏽 👳🏽‍♂️ 🧕🏽 👮🏽‍♀️ 👮🏽 👮🏽‍♂️ 👷🏽‍♀️ 👷🏽 👷🏽‍♂️ 💂🏽‍♀️ 💂🏽 💂🏽‍♂️ 🕵🏽‍♀️ 🕵🏽 🕵🏽‍♂️ 👩🏽‍⚕️ 🧑🏽‍⚕️ 👨🏽‍⚕️ 👩🏽‍🌾 🧑🏽‍🌾 👨🏽‍🌾 👩🏽‍🍳 🧑🏽‍🍳 👨🏽‍🍳 👩🏽‍🎓 🧑🏽‍🎓 👨🏽‍🎓 👩🏽‍🎤 🧑🏽‍🎤 👨🏽‍🎤 👩🏽‍🏫 🧑🏽‍🏫 👨🏽‍🏫 👩🏽‍🏭 🧑🏽‍🏭 👨🏽‍🏭 👩🏽‍💻 🧑🏽‍💻 👨🏽‍💻 👩🏽‍💼 🧑🏽‍💼 👨🏽‍💼 👩🏽‍🔧 🧑🏽‍🔧 👨🏽‍🔧 👩🏽‍🔬 🧑🏽‍🔬 👨🏽‍🔬 👩🏽‍🎨 🧑🏽‍🎨 👨🏽‍🎨 👩🏽‍🚒 🧑🏽‍🚒 👨🏽‍🚒 👩🏽‍✈️ 🧑🏽‍✈️ 👨🏽‍✈️ 👩🏽‍🚀 🧑🏽‍🚀 👨🏽‍🚀 👩🏽‍⚖️ 🧑🏽‍⚖️ 👨🏽‍⚖️ 👰🏽‍♀️ 👰🏽 👰🏽‍♂️ 🤵🏽‍♀️ 🤵🏽 🤵🏽‍♂️ 👸🏽 🤴🏽 🥷🏽 🦸🏽‍♀️ 🦸🏽 🦸🏽‍♂️ 🦹🏽‍♀️ 🦹🏽 🦹🏽‍♂️ 🤶🏽 🧑🏽‍🎄 🎅🏽 🧙🏽‍♀️ 🧙🏽 🧙🏽‍♂️ 🧝🏽‍♀️ 🧝🏽 🧝🏽‍♂️ 🧛🏽‍♀️ 🧛🏽 🧛🏽‍♂️ 🧜🏽‍♀️ 🧜🏽 🧜🏽‍♂️ 🧚🏽‍♀️ 🧚🏽 🧚🏽‍♂️ 👼🏽 🤰🏽 🤱🏽 👩🏽‍🍼 🧑🏽‍🍼 👨🏽‍🍼 🙇🏽‍♀️ 🙇🏽 🙇🏽‍♂️ 💁🏽‍♀️ 💁🏽 💁🏽‍♂️ 🙅🏽‍♀️ 🙅🏽 🙅🏽‍♂️ 🙆🏽‍♀️ 🙆🏽 🙆🏽‍♂️ 🙋🏽‍♀️ 🙋🏽 🙋🏽‍♂️ 🧏🏽‍♀️ 🧏🏽 🧏🏽‍♂️ 🤦🏽‍♀️ 🤦🏽 🤦🏽‍♂️ 🤷🏽‍♀️ 🤷🏽 🤷🏽‍♂️ 🙎🏽‍♀️ 🙎🏽 🙎🏽‍♂️ 🙍🏽‍♀️ 🙍🏽 🙍🏽‍♂️ 💇🏽‍♀️ 💇🏽 💇🏽‍♂️ 💆🏽‍♀️ 💆🏽 💆🏽‍♂️ 🧖🏽‍♀️ 🧖🏽 🧖🏽‍♂️ 💃🏽 🕺🏽 🕴🏽 👩🏽‍🦽 🧑🏽‍🦽 👨🏽‍🦽 👩🏽‍🦼 🧑🏽‍🦼 👨🏽‍🦼 🚶🏽‍♀️ 🚶🏽 🚶🏽‍♂️ 👩🏽‍🦯 🧑🏽‍🦯 👨🏽‍🦯 🧎🏽‍♀️ 🧎🏽 🧎🏽‍♂️ 🏃🏽‍♀️ 🏃🏽 🏃🏽‍♂️ 🧍🏽‍♀️ 🧍🏽 🧍🏽‍♂️ 👭🏽 🧑🏽‍🤝‍🧑🏽 👬🏽 👫🏽 🧗🏽‍♀️ 🧗🏽 🧗🏽‍♂️ 🏇🏽 🏂🏽 🏌🏽‍♀️ 🏌🏽 🏌🏽‍♂️ 🏄🏽‍♀️ 🏄🏽 🏄🏽‍♂️ 🚣🏽‍♀️ 🚣🏽 🚣🏽‍♂️ 🏊🏽‍♀️ 🏊🏽 🏊🏽‍♂️ ⛹🏽‍♀️ ⛹🏽 ⛹🏽‍♂️ 🏋🏽‍♀️ 🏋🏽 🏋🏽‍♂️ 🚴🏽‍♀️ 🚴🏽 🚴🏽‍♂️ 🚵🏽‍♀️ 🚵🏽 🚵🏽‍♂️ 🤸🏽‍♀️ 🤸🏽 🤸🏽‍♂️ 🤽🏽‍♀️ 🤽🏽 🤽🏽‍♂️ 🤾🏽‍♀️ 🤾🏽 🤾🏽‍♂️ 🤹🏽‍♀️ 🤹🏽 🤹🏽‍♂️ 🧘🏽‍♀️ 🧘🏽 🧘🏽‍♂️ 🛀🏽 🛌🏽</p>\n<h3><a href=\"https://emojipedia.org/medium-dark-skin-tone/\" title=\"List of medium dark skin tone emojis\">Dark Brown Emojis</a></h3>\n<p>👋🏾 🤚🏾 🖐🏾 ✋🏾 🖖🏾 👌🏾 🤌🏾 🤏🏾 ✌🏾 🤞🏾 🤟🏾 🤘🏾 🤙🏾 👈🏾 👉🏾 👆🏾 🖕🏾 👇🏾 ☝🏾 👍🏾 👎🏾 ✊🏾 👊🏾 🤛🏾 🤜🏾 👏🏾 🙌🏾 👐🏾 🤲🏾 🙏🏾 ✍🏾 💅🏾 🤳🏾 💪🏾 🦵🏾 🦶🏾 👂🏾 🦻🏾 👃🏾 👶🏾 👧🏾 🧒🏾 👦🏾 👩🏾 🧑🏾 👨🏾 👩🏾‍🦱 🧑🏾‍🦱 👨🏾‍🦱 👩🏾‍🦰 🧑🏾‍🦰 👨🏾‍🦰 👱🏾‍♀️ 👱🏾 👱🏾‍♂️ 👩🏾‍🦳 🧑🏾‍🦳 👨🏾‍🦳 👩🏾‍🦲 🧑🏾‍🦲 👨🏾‍🦲 🧔🏾 👵🏾 🧓🏾 👴🏾 👲🏾 👳🏾‍♀️ 👳🏾 👳🏾‍♂️ 🧕🏾 👮🏾‍♀️ 👮🏾 👮🏾‍♂️ 👷🏾‍♀️ 👷🏾 👷🏾‍♂️ 💂🏾‍♀️ 💂🏾 💂🏾‍♂️ 🕵🏾‍♀️ 🕵🏾 🕵🏾‍♂️ 👩🏾‍⚕️ 🧑🏾‍⚕️ 👨🏾‍⚕️ 👩🏾‍🌾 🧑🏾‍🌾 👨🏾‍🌾 👩🏾‍🍳 🧑🏾‍🍳 👨🏾‍🍳 👩🏾‍🎓 🧑🏾‍🎓 👨🏾‍🎓 👩🏾‍🎤 🧑🏾‍🎤 👨🏾‍🎤 👩🏾‍🏫 🧑🏾‍🏫 👨🏾‍🏫 👩🏾‍🏭 🧑🏾‍🏭 👨🏾‍🏭 👩🏾‍💻 🧑🏾‍💻 👨🏾‍💻 👩🏾‍💼 🧑🏾‍💼 👨🏾‍💼 👩🏾‍🔧 🧑🏾‍🔧 👨🏾‍🔧 👩🏾‍🔬 🧑🏾‍🔬 👨🏾‍🔬 👩🏾‍🎨 🧑🏾‍🎨 👨🏾‍🎨 👩🏾‍🚒 🧑🏾‍🚒 👨🏾‍🚒 👩🏾‍✈️ 🧑🏾‍✈️ 👨🏾‍✈️ 👩🏾‍🚀 🧑🏾‍🚀 👨🏾‍🚀 👩🏾‍⚖️ 🧑🏾‍⚖️ 👨🏾‍⚖️ 👰🏾‍♀️ 👰🏾 👰🏾‍♂️ 🤵🏾‍♀️ 🤵🏾 🤵🏾‍♂️ 👸🏾 🤴🏾 🥷🏾 🦸🏾‍♀️ 🦸🏾 🦸🏾‍♂️ 🦹🏾‍♀️ 🦹🏾 🦹🏾‍♂️ 🤶🏾 🧑🏾‍🎄 🎅🏾 🧙🏾‍♀️ 🧙🏾 🧙🏾‍♂️ 🧝🏾‍♀️ 🧝🏾 🧝🏾‍♂️ 🧛🏾‍♀️ 🧛🏾 🧛🏾‍♂️ 🧜🏾‍♀️ 🧜🏾 🧜🏾‍♂️ 🧚🏾‍♀️ 🧚🏾 🧚🏾‍♂️ 👼🏾 🤰🏾 🤱🏾 👩🏾‍🍼 🧑🏾‍🍼 👨🏾‍🍼 🙇🏾‍♀️ 🙇🏾 🙇🏾‍♂️ 💁🏾‍♀️ 💁🏾 💁🏾‍♂️ 🙅🏾‍♀️ 🙅🏾 🙅🏾‍♂️ 🙆🏾‍♀️ 🙆🏾 🙆🏾‍♂️ 🙋🏾‍♀️ 🙋🏾 🙋🏾‍♂️ 🧏🏾‍♀️ 🧏🏾 🧏🏾‍♂️ 🤦🏾‍♀️ 🤦🏾 🤦🏾‍♂️ 🤷🏾‍♀️ 🤷🏾 🤷🏾‍♂️ 🙎🏾‍♀️ 🙎🏾 🙎🏾‍♂️ 🙍🏾‍♀️ 🙍🏾 🙍🏾‍♂️ 💇🏾‍♀️ 💇🏾 💇🏾‍♂️ 💆🏾‍♀️ 💆🏾 💆🏾‍♂️ 🧖🏾‍♀️ 🧖🏾 🧖🏾‍♂️ 💃🏾 🕺🏾 🕴🏿 👩🏾‍🦽 🧑🏾‍🦽 👨🏾‍🦽 👩🏾‍🦼 🧑🏾‍🦼 👨🏾‍🦼 🚶🏾‍♀️ 🚶🏾 🚶🏾‍♂️ 👩🏾‍🦯 🧑🏾‍🦯 👨🏾‍🦯 🧎🏾‍♀️ 🧎🏾 🧎🏾‍♂️ 🏃🏾‍♀️ 🏃🏾 🏃🏾‍♂️ 🧍🏾‍♀️ 🧍🏾 🧍🏾‍♂️ 👭🏾 🧑🏾‍🤝‍🧑🏾 👬🏾 👫🏾 🧗🏾‍♀️ 🧗🏾 🧗🏾‍♂️ 🏇🏾 🏂🏾 🏌🏾‍♀️ 🏌🏾 🏌🏾‍♂️ 🏄🏾‍♀️ 🏄🏾 🏄🏾‍♂️ 🚣🏾‍♀️ 🚣🏾 🚣🏾‍♂️ 🏊🏾‍♀️ 🏊🏾 🏊🏾‍♂️ ⛹🏾‍♀️ ⛹🏾 ⛹🏾‍♂️ 🏋🏾‍♀️ 🏋🏾 🏋🏾‍♂️ 🚴🏾‍♀️ 🚴🏾 🚴🏾‍♂️ 🚵🏾‍♀️ 🚵🏾 🚵🏾‍♂️ 🤸🏾‍♀️ 🤸🏾 🤸🏾‍♂️ 🤽🏾‍♀️ 🤽🏾 🤽🏾‍♂️ 🤾🏾‍♀️ 🤾🏾 🤾🏾‍♂️ 🤹🏾‍♀️ 🤹🏾 🤹🏾‍♂️ 🧘🏾‍♀️ 🧘🏾 🧘🏾‍♂️ 🛀🏾 🛌🏾</p>\n<h3><a href=\"https://emojipedia.org/dark-skin-tone/\" title=\"List of dark skin tone emojis\">Black Emojis</a></h3>\n<p>👋🏿 🤚🏿 🖐🏿 ✋🏿 🖖🏿 👌🏿 🤌🏿 🤏🏿 ✌🏿 🤞🏿 🤟🏿 🤘🏿 🤙🏿 👈🏿 👉🏿 👆🏿 🖕🏿 👇🏿 ☝🏿 👍🏿 👎🏿 ✊🏿 👊🏿 🤛🏿 🤜🏿 👏🏿 🙌🏿 👐🏿 🤲🏿 🙏🏿 ✍🏿 💅🏿 🤳🏿 💪🏿 🦵🏿 🦶🏿 👂🏿 🦻🏿 👃🏿 👶🏿 👧🏿 🧒🏿 👦🏿 👩🏿 🧑🏿 👨🏿 👩🏿‍🦱 🧑🏿‍🦱 👨🏿‍🦱 👩🏿‍🦰 🧑🏿‍🦰 👨🏿‍🦰 👱🏿‍♀️ 👱🏿 👱🏿‍♂️ 👩🏿‍🦳 🧑🏿‍🦳 👨🏿‍🦳 👩🏿‍🦲 🧑🏿‍🦲 👨🏿‍🦲 🧔🏿 👵🏿 🧓🏿 👴🏿 👲🏿 👳🏿‍♀️ 👳🏿 👳🏿‍♂️ 🧕🏿 👮🏿‍♀️ 👮🏿 👮🏿‍♂️ 👷🏿‍♀️ 👷🏿 👷🏿‍♂️ 💂🏿‍♀️ 💂🏿 💂🏿‍♂️ 🕵🏿‍♀️ 🕵🏿 🕵🏿‍♂️ 👩🏿‍⚕️ 🧑🏿‍⚕️ 👨🏿‍⚕️ 👩🏿‍🌾 🧑🏿‍🌾 👨🏿‍🌾 👩🏿‍🍳 🧑🏿‍🍳 👨🏿‍🍳 👩🏿‍🎓 🧑🏿‍🎓 👨🏿‍🎓 👩🏿‍🎤 🧑🏿‍🎤 👨🏿‍🎤 👩🏿‍🏫 🧑🏿‍🏫 👨🏿‍🏫 👩🏿‍🏭 🧑🏿‍🏭 👨🏿‍🏭 👩🏿‍💻 🧑🏿‍💻 👨🏿‍💻 👩🏿‍💼 🧑🏿‍💼 👨🏿‍💼 👩🏿‍🔧 🧑🏿‍🔧 👨🏿‍🔧 👩🏿‍🔬 🧑🏿‍🔬 👨🏿‍🔬 👩🏿‍🎨 🧑🏿‍🎨 👨🏿‍🎨 👩🏿‍🚒 🧑🏿‍🚒 👨🏿‍🚒 👩🏿‍✈️ 🧑🏿‍✈️ 👨🏿‍✈️ 👩🏿‍🚀 🧑🏿‍🚀 👨🏿‍🚀 👩🏿‍⚖️ 🧑🏿‍⚖️ 👨🏿‍⚖️ 👰🏿‍♀️ 👰🏿 👰🏿‍♂️ 🤵🏿‍♀️ 🤵🏿 🤵🏿‍♂️ 👸🏿 🤴🏿 🥷🏿 🦸🏿‍♀️ 🦸🏿 🦸🏿‍♂️ 🦹🏿‍♀️ 🦹🏿 🦹🏿‍♂️ 🤶🏿 🧑🏿‍🎄 🎅🏿 🧙🏿‍♀️ 🧙🏿 🧙🏿‍♂️ 🧝🏿‍♀️ 🧝🏿 🧝🏿‍♂️ 🧛🏿‍♀️ 🧛🏿 🧛🏿‍♂️ 🧜🏿‍♀️ 🧜🏿 🧜🏿‍♂️ 🧚🏿‍♀️ 🧚🏿 🧚🏿‍♂️ 👼🏿 🤰🏿 🤱🏿 👩🏿‍🍼 🧑🏿‍🍼 👨🏿‍🍼 🙇🏿‍♀️ 🙇🏿 🙇🏿‍♂️ 💁🏿‍♀️ 💁🏿 💁🏿‍♂️ 🙅🏿‍♀️ 🙅🏿 🙅🏿‍♂️ 🙆🏿‍♀️ 🙆🏿 🙆🏿‍♂️ 🙋🏿‍♀️ 🙋🏿 🙋🏿‍♂️ 🧏🏿‍♀️ 🧏🏿 🧏🏿‍♂️ 🤦🏿‍♀️ 🤦🏿 🤦🏿‍♂️ 🤷🏿‍♀️ 🤷🏿 🤷🏿‍♂️ 🙎🏿‍♀️ 🙎🏿 🙎🏿‍♂️ 🙍🏿‍♀️ 🙍🏿 🙍🏿‍♂️ 💇🏿‍♀️ 💇🏿 💇🏿‍♂️ 💆🏿‍♀️ 💆🏿 💆🏿‍♂️ 🧖🏿‍♀️ 🧖🏿 🧖🏿‍♂️ 💃🏿 🕺🏿 🕴🏿 👩🏿‍🦽 🧑🏿‍🦽 👨🏿‍🦽 👩🏿‍🦼 🧑🏿‍🦼 👨🏿‍🦼 🚶🏿‍♀️ 🚶🏿 🚶🏿‍♂️ 👩🏿‍🦯 🧑🏿‍🦯 👨🏿‍🦯 🧎🏿‍♀️ 🧎🏿 🧎🏿‍♂️ 🏃🏿‍♀️ 🏃🏿 🏃🏿‍♂️ 🧍🏿‍♀️ 🧍🏿 🧍🏿‍♂️ 👭🏿 🧑🏿‍🤝‍🧑🏿 👬🏿 👫🏿 🧗🏿‍♀️ 🧗🏿 🧗🏿‍♂️ 🏇🏿 🏂🏿 🏌🏿‍♀️ 🏌🏿 🏌🏿‍♂️ 🏄🏿‍♀️ 🏄🏿 🏄🏿‍♂️ 🚣🏿‍♀️ 🚣🏿 🚣🏿‍♂️ 🏊🏿‍♀️ 🏊🏿 🏊🏿‍♂️ ⛹🏿‍♀️ ⛹🏿 ⛹🏿‍♂️ 🏋🏿‍♀️ 🏋🏿 🏋🏿‍♂️ 🚴🏿‍♀️ 🚴🏿 🚴🏿‍♂️ 🚵🏿‍♀️ 🚵🏿 🚵🏿‍♂️ 🤸🏿‍♀️ 🤸🏿 🤸🏿‍♂️ 🤽🏿‍♀️ 🤽🏿 🤽🏿‍♂️ 🤾🏿‍♀️ 🤾🏿 🤾🏿‍♂️ 🤹🏿‍♀️ 🤹🏿 🤹🏿‍♂️ 🧘🏿‍♀️ 🧘🏿 🧘🏿‍♂️ 🛀🏿 🛌🏿</p>\n<h2><a href=\"https://emojipedia.org/nature/\" title=\"Names and meanings of animal and nature emojis\">Animals &#x26; Nature</a></h2>\n<p>🐶 🐱 🐭 🐹 🐰 🦊 🐻 🐼 🐻‍❄️ 🐨 🐯 🦁 🐮 🐷 🐽 🐸 🐵 🙈 🙉 🙊 🐒 🐔 🐧 🐦 🐤 🐣 🐥 🦆 🦅 🦉 🦇 🐺 🐗 🐴 🦄 🐝 🪱 🐛 🦋 🐌 🐞 🐜 🪰 🪲 🪳 🦟 🦗 🕷 🕸 🦂 🐢 🐍 🦎 🦖 🦕 🐙 🦑 🦐 🦞 🦀 🐡 🐠 🐟 🐬 🐳 🐋 🦈 🐊 🐅 🐆 🦓 🦍 🦧 🦣 🐘 🦛 🦏 🐪 🐫 🦒 🦘 🦬 🐃 🐂 🐄 🐎 🐖 🐏 🐑 🦙 🐐 🦌 🐕 🐩 🦮 🐕‍🦺 🐈 🐈‍⬛ 🪶 🐓 🦃 🦤 🦚 🦜 🦢 🦩 🕊 🐇 🦝 🦨 🦡 🦫 🦦 🦥 🐁 🐀 🐿 🦔 🐾 🐉 🐲 🌵 🎄 🌲 🌳 🌴 🪵 🌱 🌿 ☘️ 🍀 🎍 🪴 🎋 🍃 🍂 🍁 🍄 🐚 🪨 🌾 💐 🌷 🌹 🥀 🌺 🌸 🌼 🌻 🌞 🌝 🌛 🌜 🌚 🌕 🌖 🌗 🌘 🌑 🌒 🌓 🌔 🌙 🌎 🌍 🌏 🪐 💫 ⭐️ 🌟 ✨ ⚡️ ☄️ 💥 🔥 🌪 🌈 ☀️ 🌤 ⛅️ 🌥 ☁️ 🌦 🌧 ⛈ 🌩 🌨 ❄️ ☃️ ⛄️ 🌬 💨 💧 💦 ☔️ ☂️ 🌊 🌫</p>\n<h2><a href=\"https://emojipedia.org/food-drink/\" title=\"Names and meanings of food and drink emojis\">Food &#x26; Drink</a></h2>\n<p>🍏 🍎 🍐 🍊 🍋 🍌 🍉 🍇 🍓 🫐 🍈 🍒 🍑 🥭 🍍 🥥 🥝 🍅 🍆 🥑 🥦 🥬 🥒 🌶 🫑 🌽 🥕 🫒 🧄 🧅 🥔 🍠 🥐 🥯 🍞 🥖 🥨 🧀 🥚 🍳 🧈 🥞 🧇 🥓 🥩 🍗 🍖 🦴 🌭 🍔 🍟 🍕 🫓 🥪 🥙 🧆 🌮 🌯 🫔 🥗 🥘 🫕 🥫 🍝 🍜 🍲 🍛 🍣 🍱 🥟 🦪 🍤 🍙 🍚 🍘 🍥 🥠 🥮 🍢 🍡 🍧 🍨 🍦 🥧 🧁 🍰 🎂 🍮 🍭 🍬 🍫 🍿 🍩 🍪 🌰 🥜 🍯 🥛 🍼 🫖 ☕️ 🍵 🧃 🥤 🧋 🍶 🍺 🍻 🥂 🍷 🥃 🍸 🍹 🧉 🍾 🧊 🥄 🍴 🍽 🥣 🥡 🥢 🧂</p>\n<h2><a href=\"https://emojipedia.org/activity/\" title=\"Names and meanings of sport and activity emojis\">Activity and Sports</a></h2>\n<p>⚽️ 🏀 🏈 ⚾️ 🥎 🎾 🏐 🏉 🥏 🎱 🪀 🏓 🏸 🏒 🏑 🥍 🏏 🪃 🥅 ⛳️ 🪁 🏹 🎣 🤿 🥊 🥋 🎽 🛹 🛼 🛷 ⛸ 🥌 🎿 ⛷ 🏂 🪂 🏋️‍♀️ 🏋️ 🏋️‍♂️ 🤼‍♀️ 🤼 🤼‍♂️ 🤸‍♀️ 🤸 🤸‍♂️ ⛹️‍♀️ ⛹️ ⛹️‍♂️ 🤺 🤾‍♀️ 🤾 🤾‍♂️ 🏌️‍♀️ 🏌️ 🏌️‍♂️ 🏇 🧘‍♀️ 🧘 🧘‍♂️ 🏄‍♀️ 🏄 🏄‍♂️ 🏊‍♀️ 🏊 🏊‍♂️ 🤽‍♀️ 🤽 🤽‍♂️ 🚣‍♀️ 🚣 🚣‍♂️ 🧗‍♀️ 🧗 🧗‍♂️ 🚵‍♀️ 🚵 🚵‍♂️ 🚴‍♀️ 🚴 🚴‍♂️ 🏆 🥇 🥈 🥉 🏅 🎖 🏵 🎗 🎫 🎟 🎪 🤹 🤹‍♂️ 🤹‍♀️ 🎭 🩰 🎨 🎬 🎤 🎧 🎼 🎹 🥁 🪘 🎷 🎺 🪗 🎸 🪕 🎻 🎲 ♟ 🎯 🎳 🎮 🎰 🧩</p>\n<h2><a href=\"https://emojipedia.org/travel-places/\" title=\"Names and meanings of travel and place emojis\">Travel &#x26; Places</a></h2>\n<p>🚗 🚕 🚙 🚌 🚎 🏎 🚓 🚑 🚒 🚐 🛻 🚚 🚛 🚜 🦯 🦽 🦼 🛴 🚲 🛵 🏍 🛺 🚨 🚔 🚍 🚘 🚖 🚡 🚠 🚟 🚃 🚋 🚞 🚝 🚄 🚅 🚈 🚂 🚆 🚇 🚊 🚉 ✈️ 🛫 🛬 🛩 💺 🛰 🚀 🛸 🚁 🛶 ⛵️ 🚤 🛥 🛳 ⛴ 🚢 ⚓️ 🪝 ⛽️ 🚧 🚦 🚥 🚏 🗺 🗿 🗽 🗼 🏰 🏯 🏟 🎡 🎢 🎠 ⛲️ ⛱ 🏖 🏝 🏜 🌋 ⛰ 🏔 🗻 🏕 ⛺️ 🛖 🏠 🏡 🏘 🏚 🏗 🏭 🏢 🏬 🏣 🏤 🏥 🏦 🏨 🏪 🏫 🏩 💒 🏛 ⛪️ 🕌 🕍 🛕 🕋 ⛩ 🛤 🛣 🗾 🎑 🏞 🌅 🌄 🌠 🎇 🎆 🌇 🌆 🏙 🌃 🌌 🌉 🌁</p>\n<h2><a href=\"https://emojipedia.org/objects/\" title=\"Names and meanings of object emojis\">Objects</a></h2>\n<p>⌚️ 📱 📲 💻 ⌨️ 🖥 🖨 🖱 🖲 🕹 🗜 💽 💾 💿 📀 📼 📷 📸 📹 🎥 📽 🎞 📞 ☎️ 📟 📠 📺 📻 🎙 🎚 🎛 🧭 ⏱ ⏲ ⏰ 🕰 ⌛️ ⏳ 📡 🔋 🔌 💡 🔦 🕯 🪔 🧯 🛢 💸 💵 💴 💶 💷 🪙 💰 💳 💎 ⚖️ 🪜 🧰 🪛 🔧 🔨 ⚒ 🛠 ⛏ 🪚 🔩 ⚙️ 🪤 🧱 ⛓ 🧲 🔫 💣 🧨 🪓 🔪 🗡 ⚔️ 🛡 🚬 ⚰️ 🪦 ⚱️ 🏺 🔮 📿 🧿 💈 ⚗️ 🔭 🔬 🕳 🩹 🩺 💊 💉 🩸 🧬 🦠 🧫 🧪 🌡 🧹 🪠 🧺 🧻 🚽 🚰 🚿 🛁 🛀 🧼 🪥 🪒 🧽 🪣 🧴 🛎 🔑 🗝 🚪 🪑 🛋 🛏 🛌 🧸 🪆 🖼 🪞 🪟 🛍 🛒 🎁 🎈 🎏 🎀 🪄 🪅 🎊 🎉 🎎 🏮 🎐 🧧 ✉️ 📩 📨 📧 💌 📥 📤 📦 🏷 🪧 📪 📫 📬 📭 📮 📯 📜 📃 📄 📑 🧾 📊 📈 📉 🗒 🗓 📆 📅 🗑 📇 🗃 🗳 🗄 📋 📁 📂 🗂 🗞 📰 📓 📔 📒 📕 📗 📘 📙 📚 📖 🔖 🧷 🔗 📎 🖇 📐 📏 🧮 📌 📍 ✂️ 🖊 🖋 ✒️ 🖌 🖍 📝 ✏️ 🔍 🔎 🔏 🔐 🔒 🔓</p>\n<h2><a href=\"https://emojipedia.org/objects/\" title=\"Names and meanings of hearts and symbol emojis\">Symbols</a></h2>\n<p>❤️ 🧡 💛 💚 💙 💜 🖤 🤍 🤎 💔 ❣️ 💕 💞 💓 💗 💖 💘 💝 💟 ☮️ ✝️ ☪️ 🕉 ☸️ ✡️ 🔯 🕎 ☯️ ☦️ 🛐 ⛎ ♈️ ♉️ ♊️ ♋️ ♌️ ♍️ ♎️ ♏️ ♐️ ♑️ ♒️ ♓️ 🆔 ⚛️ 🉑 ☢️ ☣️ 📴 📳 🈶 🈚️ 🈸 🈺 🈷️ ✴️ 🆚 💮 🉐 ㊙️ ㊗️ 🈴 🈵 🈹 🈲 🅰️ 🅱️ 🆎 🆑 🅾️ 🆘 ❌ ⭕️ 🛑 ⛔️ 📛 🚫 💯 💢 ♨️ 🚷 🚯 🚳 🚱 🔞 📵 🚭 ❗️ ❕ ❓ ❔ ‼️ ⁉️ 🔅 🔆 〽️ ⚠️ 🚸 🔱 ⚜️ 🔰 ♻️ ✅ 🈯️ 💹 ❇️ ✳️ ❎ 🌐 💠 Ⓜ️ 🌀 💤 🏧 🚾 ♿️ 🅿️ 🛗 🈳 🈂️ 🛂 🛃 🛄 🛅 🚹 🚺 🚼 ⚧ 🚻 🚮 🎦 📶 🈁 🔣 ℹ️ 🔤 🔡 🔠 🆖 🆗 🆙 🆒 🆕 🆓 0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 🔟 🔢 #️⃣ *️⃣ ⏏️ ▶️ ⏸ ⏯ ⏹ ⏺ ⏭ ⏮ ⏩ ⏪ ⏫ ⏬ ◀️ 🔼 🔽 ➡️ ⬅️ ⬆️ ⬇️ ↗️ ↘️ ↙️ ↖️ ↕️ ↔️ ↪️ ↩️ ⤴️ ⤵️ 🔀 🔁 🔂 🔄 🔃 🎵 🎶 ➕ ➖ ➗ ✖️ ♾ 💲 💱 ™️ ©️ ®️ 〰️ ➰ ➿ 🔚 🔙 🔛 🔝 🔜 ✔️ ☑️ 🔘 🔴 🟠 🟡 🟢 🔵 🟣 ⚫️ ⚪️ 🟤 🔺 🔻 🔸 🔹 🔶 🔷 🔳 🔲 -️ ▫️ ◾️ ◽️ ◼️ ◻️ 🟥 🟧 🟨 🟩 🟦 🟪 ⬛️ ⬜️ 🟫 🔈 🔇 🔉 🔊 🔔 🔕 📣 📢 👁‍🗨 💬 💭 🗯 ♠️ ♣️ ♥️ ♦️ 🃏 🎴 🀄️ 🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 🕛 🕜 🕝 🕞 🕟 🕠 🕡 🕢 🕣 🕤 🕥 🕦 🕧</p>\n<h2><a href=\"https://getsymbols.com/\">Non-Emoji Symbols</a></h2>\n<p>More <a href=\"https://getsymbols.com/\">Unicode symbols, Hieroglpyhs and Pictographs to copy and paste</a>.</p>\n<p>✢ ✣ ✤ ✥ ✦ ✧ ★ ☆ ✯ ✡︎ ✩ ✪ ✫ ✬ ✭ ✮ ✶ ✷ ✵ ✸ ✹ → ⇒ ⟹ ⇨ ⇾ ➾ ⇢ ☛ ☞ ➔ ➜ ➙ ➛ ➝ ➞ ♠︎ ♣︎ ♥︎ ♦︎ ♤ ♧ ♡ ♢ ♚ ♛ ♜ ♝ ♞ ♟ ♔ ♕ ♖ ♗ ♘ ♙ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ 🂠 ⚈ ⚉ ⚆ ⚇ 𓀀 𓀁 𓀂 𓀃 𓀄 𓀅 𓀆 𓀇 𓀈 𓀉 𓀊 𓀋 𓀌 𓀍 𓀎 𓀏 𓀐 𓀑 𓀒 𓀓 𓀔 𓀕 𓀖 𓀗 𓀘 𓀙 𓀚 𓀛 𓀜 𓀝</p>\n<h2><a href=\"https://emojipedia.org/flags/\" title=\"Names and meanings of Flag Emojis\">Flags</a></h2>\n<p>Note: Windows has <a href=\"https://blog.getemoji.com/post/620280709025841152/how-to-use-flag-emojis-on-windows\">limited flag emoji support</a>.</p>\n<p>🏳️ 🏴 🏁 🚩 🏳️‍🌈 🏳️‍⚧️ 🏴‍☠️ 🇦🇫 🇦🇽 🇦🇱 🇩🇿 🇦🇸 🇦🇩 🇦🇴 🇦🇮 🇦🇶 🇦🇬 🇦🇷 🇦🇲 🇦🇼 🇦🇺 🇦🇹 🇦🇿 🇧🇸 🇧🇭 🇧🇩 🇧🇧 🇧🇾 🇧🇪 🇧🇿 🇧🇯 🇧🇲 🇧🇹 🇧🇴 🇧🇦 🇧🇼 🇧🇷 🇮🇴 🇻🇬 🇧🇳 🇧🇬 🇧🇫 🇧🇮 🇰🇭 🇨🇲 🇨🇦 🇮🇨 🇨🇻 🇧🇶 🇰🇾 🇨🇫 🇹🇩 🇨🇱 🇨🇳 🇨🇽 🇨🇨 🇨🇴 🇰🇲 🇨🇬 🇨🇩 🇨🇰 🇨🇷 🇨🇮 🇭🇷 🇨🇺 🇨🇼 🇨🇾 🇨🇿 🇩🇰 🇩🇯 🇩🇲 🇩🇴 🇪🇨 🇪🇬 🇸🇻 🇬🇶 🇪🇷 🇪🇪 🇪🇹 🇪🇺 🇫🇰 🇫🇴 🇫🇯 🇫🇮 🇫🇷 🇬🇫 🇵🇫 🇹🇫 🇬🇦 🇬🇲 🇬🇪 🇩🇪 🇬🇭 🇬🇮 🇬🇷 🇬🇱 🇬🇩 🇬🇵 🇬🇺 🇬🇹 🇬🇬 🇬🇳 🇬🇼 🇬🇾 🇭🇹 🇭🇳 🇭🇰 🇭🇺 🇮🇸 🇮🇳 🇮🇩 🇮🇷 🇮🇶 🇮🇪 🇮🇲 🇮🇱 🇮🇹 🇯🇲 🇯🇵 🎌 🇯🇪 🇯🇴 🇰🇿 🇰🇪 🇰🇮 🇽🇰 🇰🇼 🇰🇬 🇱🇦 🇱🇻 🇱🇧 🇱🇸 🇱🇷 🇱🇾 🇱🇮 🇱🇹 🇱🇺 🇲🇴 🇲🇰 🇲🇬 🇲🇼 🇲🇾 🇲🇻 🇲🇱 🇲🇹 🇲🇭 🇲🇶 🇲🇷 🇲🇺 🇾🇹 🇲🇽 🇫🇲 🇲🇩 🇲🇨 🇲🇳 🇲🇪 🇲🇸 🇲🇦 🇲🇿 🇲🇲 🇳🇦 🇳🇷 🇳🇵 🇳🇱 🇳🇨 🇳🇿 🇳🇮 🇳🇪 🇳🇬 🇳🇺 🇳🇫 🇰🇵 🇲🇵 🇳🇴 🇴🇲 🇵🇰 🇵🇼 🇵🇸 🇵🇦 🇵🇬 🇵🇾 🇵🇪 🇵🇭 🇵🇳 🇵🇱 🇵🇹 🇵🇷 🇶🇦 🇷🇪 🇷🇴 🇷🇺 🇷🇼 🇼🇸 🇸🇲 🇸🇦 🇸🇳 🇷🇸 🇸🇨 🇸🇱 🇸🇬 🇸🇽 🇸🇰 🇸🇮 🇬🇸 🇸🇧 🇸🇴 🇿🇦 🇰🇷 🇸🇸 🇪🇸 🇱🇰 🇧🇱 🇸🇭 🇰🇳 🇱🇨 🇵🇲 🇻🇨 🇸🇩 🇸🇷 🇸🇿 🇸🇪 🇨🇭 🇸🇾 🇹🇼 🇹🇯 🇹🇿 🇹🇭 🇹🇱 🇹🇬 🇹🇰 🇹🇴 🇹🇹 🇹🇳 🇹🇷 🇹🇲 🇹🇨 🇹🇻 🇻🇮 🇺🇬 🇺🇦 🇦🇪 🇬🇧 🏴󠁧󠁢󠁥󠁮󠁧󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁷󠁬󠁳󠁿 🇺🇳 🇺🇸 🇺🇾 🇺🇿 🇻🇺 🇻🇦 🇻🇪 🇻🇳 🇼🇫 🇪🇭 🇾🇪 🇿🇲 🇿🇼</p>\n<p><a href=\"https://getemoji.com/#smileys\">😃💁 People</a> - <a href=\"https://getemoji.com/#animals-nature\">🐻🌻 Animals</a> - <a href=\"https://getemoji.com/#food-drink\">🍔🍹 Food</a> - <a href=\"https://getemoji.com/#activities\">🎷⚽️ Activities</a> - <a href=\"https://getemoji.com/#travel-places\">🚘🌇 Travel</a> - <a href=\"https://getemoji.com/#objects\">💡🎉 Objects</a> - <a href=\"https://getemoji.com/#symbols\">💖🔣 Symbols</a> - <a href=\"https://getemoji.com/#flags\">🎌🏳️‍🌈 Flags</a></p>\n<h2><a href=\"https://emojipedia.org/new/\" title=\"New 2019 Emojis\">New Emojis</a></h2>\n<p>Emojis from <a href=\"https://emojipedia.org/emoji-13.0/\" title=\"New 2020 Emojis\">Emoji 13.0</a>: Added in 2020.</p>\n<p>🥲 🥸 🤌 🤌🏻 🤌🏼 🤌🏽 🤌🏾 🤌🏿 🫀 🫁 🥷 🤵‍♀️ 🤵🏻‍♀️ 🤵🏼‍♀️ 🤵🏽‍♀️ 🤵🏾‍♀️ 🤵🏿‍♀️ 🤵‍♂️ 🤵🏻‍♂️ 🤵🏼‍♂️ 🤵🏽‍♂️ 🤵🏾‍♂️ 🤵🏿‍♂️ 👰‍♀️ 👰🏻‍♀️ 👰🏼‍♀️ 👰🏽‍♀️ 👰🏾‍♀️ 👰🏿‍♀️ 👰‍♂️ 👰🏻‍♂️ 👰🏼‍♂️ 👰🏽‍♂️ 👰🏾‍♂️ 👰🏿‍♂️ 👩‍🍼 👩🏻‍🍼 👩🏼‍🍼 👩🏽‍🍼 👩🏾‍🍼 👩🏿‍🍼 🧑‍🍼 🧑🏻‍🍼 🧑🏼‍🍼 🧑🏽‍🍼 🧑🏾‍🍼 🧑🏿‍🍼 👨‍🍼 👨🏻‍🍼 👨🏼‍🍼 👨🏽‍🍼 👨🏾‍🍼 👨🏿‍🍼 🧑‍🎄 🧑🏻‍🎄 🧑🏼‍🎄 🧑🏽‍🎄 🧑🏾‍🎄 🧑🏿‍🎄 🫂 🐈‍⬛ 🦬 🦣 🦫 🐻‍❄️ 🦤 🪶 🦭 🪲 🪳 🪰 🪱 🪴 🫐 🫒 🫑 🫓 🫔 🫕 🫖 🧋 🪨 🪵 🛖 🛻 🛼 🪄 🪅 🪆 🪡 🪢 🩴 🪖 🪗 🪘 🪙 🪃 🪚 🪛 🪝 🪜 🛗 🪞 🪟 🪠 🪤 🪣 🪥 🪦 🪧 🏳️‍⚧️</p>\n<p>Emojis from <a href=\"https://emojipedia.org/emoji-13.1/\" title=\"New 2021 Emojis\">Emoji 13.1</a>: Added in 2021.</p>\n<p>😮‍💨 😵‍💫 😶‍🌫️ ❤️‍🔥 ❤️‍🩹 🧔‍♀️ 🧔🏻‍♀️ 🧔🏼‍♀️ 🧔🏽‍♀️ 🧔🏾‍♀️ 🧔🏿‍♀️ 🧔‍♂️ 🧔🏻‍♂️ 🧔🏼‍♂️ 🧔🏽‍♂️ 🧔🏾‍♂️ 🧔🏿‍♂️ 💑🏻 💑🏼 💑🏽 💑🏾 💑🏿 💏🏻 💏🏼 💏🏽 💏🏾 💏🏿 👨🏻‍❤️‍👨🏻 👨🏻‍❤️‍👨🏼 👨🏻‍❤️‍👨🏽 👨🏻‍❤️‍👨🏾 👨🏻‍❤️‍👨🏿 👨🏼‍❤️‍👨🏻 👨🏼‍❤️‍👨🏼 👨🏼‍❤️‍👨🏽 👨🏼‍❤️‍👨🏾 👨🏼‍❤️‍👨🏿 👨🏽‍❤️‍👨🏻 👨🏽‍❤️‍👨🏼 👨🏽‍❤️‍👨🏽 👨🏽‍❤️‍👨🏾 👨🏽‍❤️‍👨🏿 👨🏾‍❤️‍👨🏻 👨🏾‍❤️‍👨🏼 👨🏾‍❤️‍👨🏽 👨🏾‍❤️‍👨🏾 👨🏾‍❤️‍👨🏿 👨🏿‍❤️‍👨🏻 👨🏿‍❤️‍👨🏼 👨🏿‍❤️‍👨🏽 👨🏿‍❤️‍👨🏾 👨🏿‍❤️‍👨🏿 👩🏻‍❤️‍👨🏻 👩🏻‍❤️‍👨🏼 👩🏻‍❤️‍👨🏽 👩🏻‍❤️‍👨🏾 👩🏻‍❤️‍👨🏿 👩🏻‍❤️‍👩🏻 👩🏻‍❤️‍👩🏼 👩🏻‍❤️‍👩🏽 👩🏻‍❤️‍👩🏾 👩🏻‍❤️‍👩🏿 👩🏼‍❤️‍👨🏻 👩🏼‍❤️‍👨🏼 👩🏼‍❤️‍👨🏽 👩🏼‍❤️‍👨🏾 👩🏼‍❤️‍👨🏿 👩🏼‍❤️‍👩🏻 👩🏼‍❤️‍👩🏼 👩🏼‍❤️‍👩🏽 👩🏼‍❤️‍👩🏾 👩🏼‍❤️‍👩🏿 👩🏽‍❤️‍👨🏻 👩🏽‍❤️‍👨🏼 👩🏽‍❤️‍👨🏽 👩🏽‍❤️‍👨🏾 👩🏽‍❤️‍👨🏿 👩🏽‍❤️‍👩🏻 👩🏽‍❤️‍👩🏼 👩🏽‍❤️‍👩🏽 👩🏽‍❤️‍👩🏾 👩🏽‍❤️‍👩🏿 👩🏾‍❤️‍👨🏻 👩🏾‍❤️‍👨🏼 👩🏾‍❤️‍👨🏽 👩🏾‍❤️‍👨🏾 👩🏾‍❤️‍👨🏿 👩🏾‍❤️‍👩🏻 👩🏾‍❤️‍👩🏼 👩🏾‍❤️‍👩🏽 👩🏾‍❤️‍👩🏾 👩🏾‍❤️‍👩🏿 👩🏿‍❤️‍👨🏻 👩🏿‍❤️‍👨🏼 👩🏿‍❤️‍👨🏽 👩🏿‍❤️‍👨🏾 👩🏿‍❤️‍👨🏿 👩🏿‍❤️‍👩🏻 👩🏿‍❤️‍👩🏼 👩🏿‍❤️‍👩🏽 👩🏿‍❤️‍👩🏾 👩🏿‍❤️‍👩🏿 🧑🏻‍❤️‍🧑🏼 🧑🏻‍❤️‍🧑🏽 🧑🏻‍❤️‍🧑🏾 🧑🏻‍❤️‍🧑🏿 🧑🏼‍❤️‍🧑🏻 🧑🏼‍❤️‍🧑🏽 🧑🏼‍❤️‍🧑🏾 🧑🏼‍❤️‍🧑🏿 🧑🏽‍❤️‍🧑🏻 🧑🏽‍❤️‍🧑🏼 🧑🏽‍❤️‍🧑🏾 🧑🏽‍❤️‍🧑🏿 🧑🏾‍❤️‍🧑🏻 🧑🏾‍❤️‍🧑🏼 🧑🏾‍❤️‍🧑🏽 🧑🏾‍❤️‍🧑🏿 🧑🏿‍❤️‍🧑🏻 🧑🏿‍❤️‍🧑🏼 🧑🏿‍❤️‍🧑🏽 🧑🏿‍❤️‍🧑🏾 👨🏻‍❤️‍💋‍👨🏻 👨🏻‍❤️‍💋‍👨🏼 👨🏻‍❤️‍💋‍👨🏽 👨🏻‍❤️‍💋‍👨🏾 👨🏻‍❤️‍💋‍👨🏿 👨🏼‍❤️‍💋‍👨🏻 👨🏼‍❤️‍💋‍👨🏼 👨🏼‍❤️‍💋‍👨🏽 👨🏼‍❤️‍💋‍👨🏾 👨🏼‍❤️‍💋‍👨🏿 👨🏽‍❤️‍💋‍👨🏻 👨🏽‍❤️‍💋‍👨🏼 👨🏽‍❤️‍💋‍👨🏽 👨🏽‍❤️‍💋‍👨🏾 👨🏽‍❤️‍💋‍👨🏿 👨🏾‍❤️‍💋‍👨🏻 👨🏾‍❤️‍💋‍👨🏼 👨🏾‍❤️‍💋‍👨🏽 👨🏾‍❤️‍💋‍👨🏾 👨🏾‍❤️‍💋‍👨🏿 👨🏿‍❤️‍💋‍👨🏻 👨🏿‍❤️‍💋‍👨🏼 👨🏿‍❤️‍💋‍👨🏽 👨🏿‍❤️‍💋‍👨🏾 👨🏿‍❤️‍💋‍👨🏿 👩🏻‍❤️‍💋‍👨🏻 👩🏻‍❤️‍💋‍👨🏼 👩🏻‍❤️‍💋‍👨🏽 👩🏻‍❤️‍💋‍👨🏾 👩🏻‍❤️‍💋‍👨🏿 👩🏻‍❤️‍💋‍👩🏻 👩🏻‍❤️‍💋‍👩🏼 👩🏻‍❤️‍💋‍👩🏽 👩🏻‍❤️‍💋‍👩🏾 👩🏻‍❤️‍💋‍👩🏿 👩🏼‍❤️‍💋‍👨🏻 👩🏼‍❤️‍💋‍👨🏼 👩🏼‍❤️‍💋‍👨🏽 👩🏼‍❤️‍💋‍👨🏾 👩🏼‍❤️‍💋‍👨🏿 👩🏼‍❤️‍💋‍👩🏻 👩🏼‍❤️‍💋‍👩🏼 👩🏼‍❤️‍💋‍👩🏽 👩🏼‍❤️‍💋‍👩🏾 👩🏼‍❤️‍💋‍👩🏿 👩🏽‍❤️‍💋‍👨🏻 👩🏽‍❤️‍💋‍👨🏼 👩🏽‍❤️‍💋‍👨🏽 👩🏽‍❤️‍💋‍👨🏾 👩🏽‍❤️‍💋‍👨🏿 👩🏽‍❤️‍💋‍👩🏻 👩🏽‍❤️‍💋‍👩🏼 👩🏽‍❤️‍💋‍👩🏽 👩🏽‍❤️‍💋‍👩🏾 👩🏽‍❤️‍💋‍👩🏿 👩🏾‍❤️‍💋‍👨🏻 👩🏾‍❤️‍💋‍👨🏼 👩🏾‍❤️‍💋‍👨🏽 👩🏾‍❤️‍💋‍👨🏾 👩🏾‍❤️‍💋‍👨🏿 👩🏾‍❤️‍💋‍👩🏻 👩🏾‍❤️‍💋‍👩🏼 👩🏾‍❤️‍💋‍👩🏽 👩🏾‍❤️‍💋‍👩🏾 👩🏾‍❤️‍💋‍👩🏿 👩🏿‍❤️‍💋‍👨🏻 👩🏿‍❤️‍💋‍👨🏼 👩🏿‍❤️‍💋‍👨🏽 👩🏿‍❤️‍💋‍👨🏾 👩🏿‍❤️‍💋‍👨🏿 👩🏿‍❤️‍💋‍👩🏻 👩🏿‍❤️‍💋‍👩🏼 👩🏿‍❤️‍💋‍👩🏽 👩🏿‍❤️‍💋‍👩🏾 👩🏿‍❤️‍💋‍👩🏿 🧑🏻‍❤️‍💋‍🧑🏼 🧑🏻‍❤️‍💋‍🧑🏽 🧑🏻‍❤️‍💋‍🧑🏾 🧑🏻‍❤️‍💋‍🧑🏿 🧑🏼‍❤️‍💋‍🧑🏻 🧑🏼‍❤️‍💋‍🧑🏽 🧑🏼‍❤️‍💋‍🧑🏾 🧑🏼‍❤️‍💋‍🧑🏿 🧑🏽‍❤️‍💋‍🧑🏻 🧑🏽‍❤️‍💋‍🧑🏼 🧑🏽‍❤️‍💋‍🧑🏾 🧑🏽‍❤️‍💋‍🧑🏿 🧑🏾‍❤️‍💋‍🧑🏻 🧑🏾‍❤️‍💋‍🧑🏼 🧑🏾‍❤️‍💋‍🧑🏽 🧑🏾‍❤️‍💋‍🧑🏿 🧑🏿‍❤️‍💋‍🧑🏻 🧑🏿‍❤️‍💋‍🧑🏼 🧑🏿‍❤️‍💋‍🧑🏽 🧑🏿‍❤️‍💋‍🧑🏾</p>"},{"url":"/docs/quick-ref/","relativePath":"docs/quick-ref/index.md","relativeDir":"docs/quick-ref","base":"index.md","name":"index","frontmatter":{"title":"QuickRef","excerpt":"In this section you'll find basic information about Web-Dev-Hub and how to use it.","seo":{"title":"Cheat Sheets","description":"This is the Cheat Sheets page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Cheat Sheets","keyName":"property"},{"name":"og:description","value":"This is the Cheat Sheets page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Cheat Sheets"},{"name":"twitter:description","value":"This is the Cheat Sheets page"}]},"template":"docs"},"html":"<h1>Quick Reference</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://cheatsheets-42.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bgoonz-bookmarks.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://search-awesome.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://sidebar-blog.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>"},{"url":"/docs/quick-ref/google-sheets-api/","relativePath":"docs/quick-ref/google-sheets-api.md","relativeDir":"docs/quick-ref","base":"google-sheets-api.md","name":"google-sheets-api","frontmatter":{"title":"google-sheets-api","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<p><strong>If you're maintaining a dataset that frequently has to be updated in a predictable and consistent manner, automating that process has obvious benefits. It might cost some time to set up the code to automate the work, but you'll likely save time in the long run. And, if you're like me, writing the code will be less mind-numbing than repeatedly updating the same spreadsheet over and over again!</strong><img src=\"https://miro.medium.com/max/30/1*5RtrFThuAvHiqxxwPp5Ptg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/709/1*5RtrFThuAvHiqxxwPp5Ptg.png\" alt=\"medium blog image\"></p>\n<p>Screenshot of Google Cloud Console edited by the author.<img src=\"https://miro.medium.com/max/30/1*ahdHCrx8ngiDP0dBANKvgg.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/709/1*ahdHCrx8ngiDP0dBANKvgg.png\" alt=\"medium blog image\"></p>\n<p>taken after successfully running the quickstart script.<img src=\"https://miro.medium.com/max/30/1*E_PHwbLycJ7mQSad2QszKw.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/709/1*E_PHwbLycJ7mQSad2QszKw.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/709/1*cN14i55zhZfg_X63kQcBEw.png\" alt=\"medium blog image\"></p>\n<p>.<img src=\"https://miro.medium.com/max/30/1*wH0Dop5RSg3tS3sEnfIY4g.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/709/1*wH0Dop5RSg3tS3sEnfIY4g.png\" alt=\"medium blog image\"></p>\n<p>Google spreadsheets provide excellent functionality for maintaining basic datasets. Some of the obvious advantages are that they are free, easy to access, and easy to share. Moreover, Google spreadsheets can be especially powerful because of their ability to connect with tools like <a href=\"https://zapier.com/\">Zapier</a> or <a href=\"https://phantombuster.com/\">Phantombuster</a> that can create automated workflows between a plethora of different online applications.</p>\n<p>Although these kinds of tools usually offer functionalities to automatically manipulate Google spreadsheets as well, I've experienced a lack of flexibility on how to update your spreadsheets. A customized Python script can offer way more flexibility and possibilities.</p>\n<p>To update your Google spreadsheets with Python, you can use the Google sheets API. Google offers free API access to several of their workspace apps, like Gmail, Google Calendar, Google Drive, and Google Sheets. You can check out their API library <a href=\"https://console.cloud.google.com/apis/library?project=cellular-axon-327013\">here</a>.</p>\n<p>Below I'll walk you through the steps to set up the Google Sheets API with Python and show a couple of basic examples of how to manipulate spreadsheets using the API.</p>\n<h1>Setting Up the API</h1>\n<h2>Step 1: Create a Google Cloud Platform project</h2>\n<p>To get started with any of the Google workspace APIs, you need to have a so-called Google Cloud Platform (GCP) project. A GCP project forms the basis for all of Google's cloud computing services, including their API library. Setting up a project and using the APIs is completely free. Follow the steps outlined <a href=\"https://developers.google.com/workspace/guides/create-project\">here</a> to create your GCP project. It should be pretty straightforward.</p>\n<h2>Step 2: Create Credentials</h2>\n<p>After creating a GCP project (step 1), we need to set up our credentials for accessing the API. Our credentials are like a key for the API to know who is requesting access to its data and services. You can follow the steps listed <a href=\"https://developers.google.com/workspace/guides/create-credentials\">here</a> to <em>create desktop application credentials</em>. In my experience, some steps were missing in this tutorial, so I'm giving the detailed version below.</p>\n<ul>\n<li>Start by navigating back to your <a href=\"https://console.cloud.google.com/home/dashboard\">Google Cloud Console</a>.</li>\n<li>-</li>\n<li>Find the <em>APIs &#x26; Services</em> tab, and then select the <em>Credentials</em> page</li>\n<li>Click on *+Create Credentials *and select <em>OAuth client ID</em>.</li>\n</ul>\n<!---->\n<ul>\n<li>Select <em>Desktop app</em> as the application type and give your app a name. Then click create.</li>\n<li>-</li>\n<li>You will be prompted to set up your OAuth consent screen. Follow the steps you are prom</li>\n<li>-</li>\n<li>After generating your client ID, you will be able to see it on your credentials page.</li>\n<li>Click the download button to download a JSON file with your credentials. Rename it to <em>credentials.json</em>. You will need this in the next step.</li>\n</ul>\n<h2>Step 3: Set up the API</h2>\n<p>After creating a GCP project and generating your credentials, it is time to connect to the API with Python for the first time. You can follow the steps outlined <a href=\"https://developers.google.com/sheets/api/quickstart/python\">here</a>. The steps given on the Google developers page are pretty self-explanatory. Three things I want to add:</p>\n<ul>\n<li>Make sure to have a look at the prerequisites before diving in.</li>\n<li>-</li>\n<li>Don't forget to move your <em>credentials.json</em> file to the same folder where your <em>quickstart.py</em> file is.</li>\n<li>Change the URL in the SCOPE list in the quickstart script to <em><a href=\"https://www.googleapis.com/auth/spreadsheets\">https://www.googleapis.com/auth/spreadsheets</a></em> to make sure that you have both read and write access.</li>\n</ul>\n<p>If everything goes as expected, you should see this in your browser after running the sample script:</p>\n<p>After successfully running the sample, you will also find a <em>token.json</em> file in your workspace. This file is used for authentication on any of your future calls to the API. You're now ready to use the API!</p>\n<h1>Using the API</h1>\n<p>Now that we have set up the API connection, we can use the API to create, read, and edit Google spreadsheets! Extensive documentation on how to use the API can be found <a href=\"https://developers.google.com/sheets/api/guides/create#python\">here</a>. I'll run through a few basic examples below.</p>\n<h2>Reading from an existing spreadsheet</h2>\n<p>Reading from an existing spreadsheet is a key functionality if you want to automate your spreadsheets. Let's create a new spreadsheet in the Google workspace and input some data. Below is a screenshot of the table I created.</p>\n<p>The API identifies spreadsheets using a spreadsheet ID. To connect to a spreadsheet that already exists, you can find the spreadsheet ID in the Google Sheets URL as follows:</p>\n<p>After identifying the spreadsheet ID of the spreadsheet we just created, we can use the API to connect to the spreadsheet and to read its data. Below is a code example of how to do this. The main functionalities to retrieve data from an existing spreadsheet are provided by sheet.values().get().execute()* <em>on line 17</em>. *Note that this is where we pass the spreadsheet ID and the range of values in the sheet we want to retrieve. All code before that establishes the connection to the API and is very similar to the <em>quickstart.py</em> file we used to connect to the API for the first time.</p>\n<p>The code returns a list of lists containing the data of our spreadsheet. Note that the data is returned row-by-row this way.</p>\n<h2>Writing to an existing spreadsheet</h2>\n<p>Next, let's try to add a new value to the spreadsheet. After all, this is the second key bit we need to automatically update our spreadsheets.</p>\n<p>The code below shows how to add a row to the existing data with the values [6, f]. Similar to reading values from an existing sheet, we need to start with establishing the connection to the API and identifying the spreadsheet ID. Because we are now writing new data to the spreadsheet, it is essential to make sure that you have not specified read-only permission in your SCOPES list (line 5).</p>\n<p>The main functionalities to append new data to an existing spreadsheet are provided by *sheet.values().append().execute() <em>on lines 17-22</em>. *Note that this is where we pass the spreadsheet ID, spreadsheet range, and several other parameters that specify how the data has to be inserted and what data has to be inserted. The <em>body</em> parameter takes a dictionary with values to append to the existing data table, using the same list-of-list format we saw before.</p>\n<p>After running the code, the spreadsheet is automatically updated with our new entry. The new row is neatly appended to the data that we manually wrote in the spreadsheet.</p>\n<h1>Final Thoughts</h1>\n<p>The Google workspace API library is a really powerful and relatively user-friendly way to automate workflows related to any of the Google workspace applications. In this tutorial, I walked you through setting up the Google Sheets API with Python and showed a few examples of how to manipulate spreadsheets using this API. The possibilities of how to use this are endless.</p>\n<p>Setting up access to the other APIs involves a very similar process and would allow for even more elaborate and complex automation flows.</p>"},{"url":"/docs/quick-ref/heroku-error-codes/","relativePath":"docs/quick-ref/heroku-error-codes.md","relativeDir":"docs/quick-ref","base":"heroku-error-codes.md","name":"heroku-error-codes","frontmatter":{"title":"Heroku Error Codes","weight":0,"excerpt":"Full List Of Heroku Error Codes","seo":{"title":"","description":"embeded developer tools and utilities","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Heroku Error Codes</h1>\n<p>Last updated August 04, 2021</p>\n<h2>Table of Contents</h2>\n<ul>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h10-app-crashed\">H10 - App crashed</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h11-backlog-too-deep\">H11 - Backlog too deep</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h12-request-timeout\">H12 - Request timeout</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h13-connection-closed-without-response\">H13 - Connection closed without response</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h14-no-web-dynos-running\">H14 - No web dynos running</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h15-idle-connection\">H15 - Idle connection</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h16-no-longer-in-use\">H16 - (No Longer in Use)</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h17-poorly-formatted-http-response\">H17 - Poorly formatted HTTP response</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h18-server-request-interrupted\">H18 - Server Request Interrupted</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h19-backend-connection-timeout\">H19 - Backend connection timeout</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h20-app-boot-timeout\">H20 - App boot timeout</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h21-backend-connection-refused\">H21 - Backend connection refused</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h22-connection-limit-reached\">H22 - Connection limit reached</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h23-endpoint-misconfigured\">H23 - Endpoint misconfigured</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h24-forced-close\">H24 - Forced close</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h25-http-restriction\">H25 - HTTP Restriction</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h26-request-error\">H26 - Request Error</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h27-client-request-interrupted\">H27 - Client Request Interrupted</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h28-client-connection-idle\">H28 - Client Connection Idle</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h31-misdirected-request\">H31 - Misdirected Request</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h80-maintenance-mode\">H80 - Maintenance mode</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h81-blank-app\">H81 - Blank app</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h82-free-dyno-quota-exhausted\">H82 - Free dyno quota exhausted</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#h99-platform-error\">H99 - Platform error</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#r10-boot-timeout\">R10 - Boot timeout</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#r12-exit-timeout\">R12 - Exit timeout</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#r13-attach-error\">R13 - Attach error</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#r14-memory-quota-exceeded\">R14 - Memory quota exceeded</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#r15-memory-quota-vastly-exceeded\">R15 - Memory quota vastly exceeded</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#r16-detached\">R16 - Detached</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#r17-checksum-error\">R17 - Checksum error</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#r99-platform-error\">R99 - Platform error</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#l10-drain-buffer-overflow\">L10 - Drain buffer overflow</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#l11-tail-buffer-overflow\">L11 - Tail buffer overflow</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#l12-local-buffer-overflow\">L12 - Local buffer overflow</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#l13-local-delivery-error\">L13 - Local delivery error</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#l14-certificate-validation-error\">L14 - Certificate validation error</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/error-codes#l15-tail-buffer-temporarily-unavailable\">L15 - Tail buffer temporarily unavailable</a></li>\n</ul>\n<p>Whenever your app experiences an error, Heroku will return a standard error page with the HTTP status code 503. To help you debug the underlying error, however, the platform will also add custom error information to your logs. Each type of error gets its own error code, with all HTTP errors starting with the letter H and all runtime errors starting with R. Logging errors start with L.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h10-app-crashed\">H10 - App crashed</a></h2>\n<p>A crashed web dyno or a boot timeout on the web dyno will present this error.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:04-07:00 heroku[web.1]: State changed from down to starting\n2010-10-06T21:51:07-07:00 app[web.1]: Starting process with command: `bundle exec rails server -p 22020`\n2010-10-06T21:51:09-07:00 app[web.1]: >> Using rails adapter\n2010-10-06T21:51:09-07:00 app[web.1]: Missing the Rails 2.3.5 gem. Please `gem install -v=2.3.5 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.\n2010-10-06T21:51:10-07:00 heroku[web.1]: Process exited\n2010-10-06T21:51:12-07:00 heroku[router]: at=error code=H10 desc=\"App crashed\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h11-backlog-too-deep\">H11 - Backlog too deep</a></h2>\n<p>When HTTP requests arrive faster than your application can process them, they can form a large backlog on a number of routers. When the backlog on a particular router passes a threshold, the router determines that your application isn't keeping up with its incoming request volume. You'll see an H11 error for each incoming request as long as the backlog is over this size. The exact value of this threshold may change depending on various factors, such as the number of dynos in your app, response time for individual requests, and your app's normal request volume.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=error code=H11 desc=\"Backlog too deep\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<p>The solution is to increase your app's throughput by adding more dynos, tuning your database (for example, adding an index), or making the code itself faster. As always, increasing performance is highly application-specific and requires profiling.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h12-request-timeout\">H12 - Request timeout</a></h2>\n<p>For more information on request timeouts (including recommendations for resolving them), take a look at <a href=\"https://devcenter.heroku.com/articles/request-timeout\">our article on the topic</a>.</p>\n<p>An HTTP <a href=\"https://devcenter.heroku.com/articles/request-timeout\">request took longer than 30 seconds</a> to complete. In the example below, a Rails app takes 37 seconds to render the page; the HTTP router returns a 503 prior to Rails completing its request cycle, but the Rails process continues and the completion message shows after the router message.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 app[web.2]: Processing PostController#list (for 75.36.147.245 at 2010-10-06 21:51:07) [GET]\n2010-10-06T21:51:08-07:00 app[web.2]: Rendering template within layouts/application\n2010-10-06T21:51:19-07:00 app[web.2]: Rendering post/list\n2010-10-06T21:51:37-07:00 heroku[router]: at=error code=H12 desc=\"Request timeout\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=6ms service=30001ms status=503 bytes=0\n2010-10-06T21:51:42-07:00 app[web.2]: Completed in 37000ms (View: 27, DB: 21) | 200 OK [http://myapp.heroku.com/]</code></pre></div>\n<p>This 30-second limit is measured by the router, and includes all time spent in the dyno, including the kernel's incoming connection queue and the app itself.</p>\n<p>See <a href=\"https://devcenter.heroku.com/articles/request-timeout\">Request Timeout</a> for more, as well as a language-specific article on this error:</p>\n<ul>\n<li><a href=\"https://devcenter.heroku.com/articles/h12-request-timeout-in-ruby-mri\">H12 - Request Timeout in Ruby (MRI)</a></li>\n</ul>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h13-connection-closed-without-response\">H13 - Connection closed without response</a></h2>\n<p>This error is thrown when a process in your web dyno accepts a connection but then closes the socket without writing anything to it.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:37-07:00 heroku[router]: at=error code=H13 desc=\"Connection closed without response\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=3030ms service=9767ms status=503 bytes=0</code></pre></div>\n<p>One example where this might happen is when a <a href=\"https://devcenter.heroku.com/articles/rails-unicorn\">Unicorn web server</a> is configured with a timeout shorter than 30s and a request has not been processed by a worker before the timeout happens. In this case, Unicorn closes the connection before any data is written, resulting in an H13.</p>\n<p>An <a href=\"https://github.com/hunterloftis/heroku-node-errcodes/tree/master/h13\">example of an H13 can be found here</a>.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h14-no-web-dynos-running\">H14 - No web dynos running</a></h2>\n<p>This is most likely the result of scaling your web dynos down to 0 dynos. To fix it, scale your web dynos to 1 or more dynos:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ heroku ps:scale web=1</code></pre></div>\n<p>Use the <code class=\"language-text\">heroku ps</code> command to determine the state of your web dynos.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:37-07:00 heroku[router]: at=error code=H14 desc=\"No web processes running\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h15-idle-connection\">H15 - Idle connection</a></h2>\n<p>The dyno did not send a full response and was <a href=\"https://devcenter.heroku.com/articles/request-timeout\">terminated due to 55 seconds of inactivity</a>. For example, the response indicated a <code class=\"language-text\">Content-Length</code> of 50 bytes which were not sent in time.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:37-07:00 heroku[router]: at=error code=H15 desc=\"Idle connection\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=1ms service=55449ms status=503 bytes=18</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h16-no-longer-in-use\">H16 - (No Longer in Use)</a></h2>\n<p>Heroku no longer emits H16 errors</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h17-poorly-formatted-http-response\">H17 - Poorly formatted HTTP response</a></h2>\n<p>Our HTTP routing stack has no longer accepts responses that are missing a reason phrase in the <a href=\"https://datatracker.ietf.org/doc/html/rfc7230#section-3.1.2\">status line</a>. 'HTTP/1.1 200 OK' will work with the new router, but 'HTTP/1.1 200' will not.</p>\n<p>This error message is logged when a router detects a malformed HTTP response coming from a dyno.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:37-07:00 heroku[router]: at=error code=H17 desc=\"Poorly formatted HTTP response\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=1ms service=1ms status=503 bytes=0</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h18-server-request-interrupted\">H18 - Server Request Interrupted</a></h2>\n<p>An H18 signifies that the socket connected, some data was sent as part of a response by the app, but then the socket was destroyed without completing the response.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:37-07:00 heroku[router]: sock=backend at=error code=H18 desc=\"Server Request Interrupted\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=1ms service=1ms status=503 bytes=0</code></pre></div>\n<p>An <a href=\"https://github.com/hunterloftis/heroku-node-errcodes/tree/master/h18\">example of an H18 can be found here</a>.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h19-backend-connection-timeout\">H19 - Backend connection timeout</a></h2>\n<p>A router received a connection timeout error after 5 seconds attempting to open a socket to a web dyno. This is usually a symptom of your app being overwhelmed and failing to accept new connections in a timely manner. If you have multiple dynos, the router will retry multiple dynos before logging H19 and serving a standard error page.</p>\n<p>If your app has a single web dyno, it is possible to see H19 errors if the runtime instance running your web dyno fails and is replaced. Once the failure is detected and the instance is terminated your web dyno will be restarted somewhere else, but in the meantime, H19s may be served as the router fails to establish a connection to your dyno. This can be mitigated by running more than one web dyno.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=error code=H19 desc=\"Backend connection timeout\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=5001ms service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h20-app-boot-timeout\">H20 - App boot timeout</a></h2>\n<p>The router will enqueue requests for 75 seconds while waiting for starting processes to reach an \"up\" state. If after 75 seconds, no web dynos have reached an \"up\" state, the router logs H20 and serves a standard error page.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=error code=H20 desc=\"App boot timeout\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<p>The Ruby on Rails <a href=\"http://guides.rubyonrails.org/asset_pipeline.html\">asset pipeline</a> can sometimes fail to run during <a href=\"https://devcenter.heroku.com/articles/git\">git push</a>, and will instead attempt to run when your app's <a href=\"https://devcenter.heroku.com/articles/dynos\">dynos</a> boot. Since the Rails asset pipeline is a slow process, this can cause H20 boot timeout errors.</p>\n<p>This error differs from <a href=\"https://devcenter.heroku.com/articles/error-codes#r10-boot-timeout\">R10</a> in that the H20 75-second timeout includes platform tasks such as internal state propagation, requests between internal components, slug download, unpacking, container preparation, etc... The R10 60-second timeout applies solely to application startup tasks.</p>\n<p>If your application requires more time to boot, you may use the <a href=\"https://tools.heroku.support/limits/boot_timeout\">boot timeout tool</a> to increase the limit. However, in general, slow boot times will make it harder to deploy your application and will make recovery from dyno failures slower, so this should be considered a <em>temporary solution</em>.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h21-backend-connection-refused\">H21 - Backend connection refused</a></h2>\n<p>A router received a connection refused error when attempting to open a socket to your web process. This is usually a symptom of your app being overwhelmed and failing to accept new connections. If you have multiple dynos, the router will retry multiple dynos before logging H21 and serving a standard error page.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=error code=H21 desc=\"Backend connection refused\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=1ms service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h22-connection-limit-reached\">H22 - Connection limit reached</a></h2>\n<p>A routing node has detected an elevated number of HTTP client connections attempting to reach your app. Reaching this threshold most likely means your app is under heavy load and is not responding quickly enough to keep up. The exact value of this threshold may change depending on various factors, such as the number of dynos in your app, response time for individual requests, and your app's normal request volume.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=error code=H22 desc=\"Connection limit reached\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h23-endpoint-misconfigured\">H23 - Endpoint misconfigured</a></h2>\n<p>A routing node has detected a <a href=\"https://tools.ietf.org/html/rfc6455#section-1.3\">websocket handshake</a>, specifically the 'Sec-Websocket-Version' header in the request, that came from an endpoint (upstream proxy) that does not support websockets.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=error code=H23 desc=\"Endpoint misconfigured\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h24-forced-close\">H24 - Forced close</a></h2>\n<p>The routing node serving this request was either shutdown for maintenance or terminated before the request completed.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=error code=H24 desc=\"Forced close\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=1ms service=80000ms status= bytes=18</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h25-http-restriction\">H25 - HTTP Restriction</a></h2>\n<p>This error is logged when a routing node detects and blocks a valid HTTP response that is judged risky or too large to be safely parsed. The error comes in four types.</p>\n<p>Currently, this functionality is experimental, and is only made available to a subset of applications on the platform.</p>\n<h3><a href=\"https://devcenter.heroku.com/articles/error-codes#invalid-content-length\">Invalid content length</a></h3>\n<p>The response has multiple content lengths declared within the same response, with varying lengths.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2014-03-20T14:22:00.203382+00:00 heroku[router]: at=error code=H25 desc=\"HTTP restriction: invalid content length\" method=GET path=\"/\" host=myapp.herokuapp.com request_id=3f336f1a-9be3-4791-afe3-596a1f2a481f fwd=\"17.17.17.17\" dyno=web.1 connect=0 service=1 status=502 bytes=537</code></pre></div>\n<h3><a href=\"https://devcenter.heroku.com/articles/error-codes#oversized-cookies\">Oversized cookies</a></h3>\n<p>The cookie in the response will be too large to be used again in a request to the Heroku router or SSL endpoints.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2014-03-20T14:18:57.403882+00:00 heroku[router]: at=error code=H25 desc=\"HTTP restriction: oversized cookie\" method=GET path=\"/\" host=myapp.herokuapp.com request_id=90cfbbd2-0397-4bab-828f-193050a076c4 fwd=\"17.17.17.17\" dyno=web.1 connect=0 service=2 status=502 bytes=537</code></pre></div>\n<h3><a href=\"https://devcenter.heroku.com/articles/error-codes#oversized-header\">Oversized header</a></h3>\n<p>A single header line is deemed too long (over 512kb) and the response is discarded on purpose.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2014-03-20T14:12:28.555073+00:00 heroku[router]: at=error code=H25 desc=\"HTTP restriction: oversized header\" method=GET path=\"/\" host=myapp.herokuapp.com request_id=ab66646e-84eb-47b8-b3bb-2031ecc1bc2c fwd=\"17.17.17.17\" dyno=web.1 connect=0 service=397 status=502 bytes=542</code></pre></div>\n<h3><a href=\"https://devcenter.heroku.com/articles/error-codes#oversized-status-line\">Oversized status line</a></h3>\n<p>The status line is judged too long (8kb) and the response is discarded on purpose.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2014-03-20T13:54:44.423083+00:00 heroku[router]: at=error code=H25 desc=\"HTTP restriction: oversized status line\" method=GET path=\"/\" host=myapp.herokuapp.com request_id=208588ac-1a66-44c1-b665-fe60c596241b fwd=\"17.17.17.17\" dyno=web.1 connect=0 service=3 status=502 bytes=537</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h26-request-error\">H26 - Request Error</a></h2>\n<p>This error is logged when a request has been identified as belonging to a specific Heroku application, but cannot be delivered entirely to a dyno due to HTTP protocol errors in the request. Multiple possible causes can be identified in the log message.</p>\n<h3><a href=\"https://devcenter.heroku.com/articles/error-codes#unsupported-expect-header-value\">Unsupported expect header value</a></h3>\n<p>The request has an <code class=\"language-text\">expect</code> header, and its value is not <code class=\"language-text\">100-Continue</code>, the only expect value handled by the router. A request with an unsupported <code class=\"language-text\">expect</code> value is terminated with the status code <code class=\"language-text\">417 Expectation Failed</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2014-05-14T17:17:37.456997+00:00 heroku[router]: at=error code=H26 desc=\"Request Error\" cause=\"unsupported expect header value\" method=GET path=\"/\" host=myapp.herokuapp.com request_id=3f336f1a-9be3-4791-afe3-596a1f2a481f fwd=\"17.17.17.17\" dyno= connect= service= status=417 bytes=</code></pre></div>\n<h3><a href=\"https://devcenter.heroku.com/articles/error-codes#bad-header\">Bad header</a></h3>\n<p>The request has an HTTP header with a value that is either impossible to parse, or not handled by the router, such as <code class=\"language-text\">connection: ,</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2014-05-14T17:17:37.456997+00:00 heroku[router]: at=error code=H26 desc=\"Request Error\" cause=\"bad header\" method=GET path=\"/\" host=myapp.herokuapp.com request_id=3f336f1a-9be3-4791-afe3-596a1f2a481f fwd=\"17.17.17.17\" dyno= connect= service= status=400 bytes=</code></pre></div>\n<h3><a href=\"https://devcenter.heroku.com/articles/error-codes#bad-chunk\">Bad chunk</a></h3>\n<p>The request has a chunked transfer-encoding, but with a chunk that was invalid or couldn't be parsed correctly. A request with this status code will be interrupted during transfer to the dyno.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2014-05-14T17:17:37.456997+00:00 heroku[router]: at=error code=H26 desc=\"Request Error\" cause=\"bad chunk\" method=GET path=\"/\" host=myapp.herokuapp.com request_id=3f336f1a-9be3-4791-afe3-596a1f2a481f fwd=\"17.17.17.17\" dyno=web.1 connect=1 service=0 status=400 bytes=537</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h27-client-request-interrupted\">H27 - Client Request Interrupted</a></h2>\n<p>The client socket was closed either in the middle of the request or before a response could be returned. For example, the client closed their browser session before the request was able to complete.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:37-07:00 heroku[router]: sock=client at=warning code=H27 desc=\"Client Request Interrupted\" method=POST path=\"/submit/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=1ms service=0ms status=499 bytes=0</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h28-client-connection-idle\">H28 - Client Connection Idle</a></h2>\n<p>The client did not send a full request and was <a href=\"https://devcenter.heroku.com/articles/request-timeout#long-polling-and-streaming-responses\">terminated due to 55 seconds of inactivity</a>. For example, the client indicated a <code class=\"language-text\">Content-Length</code> of 50 bytes which were not sent in time.</p>\n<p><code class=\"language-text\">2010-10-06T21:51:37-07:00 heroku[router]: at=warning code=H28 desc=\"Client Connection Idle\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno=web.1 connect=1ms service=55449ms status=499 bytes=18</code></p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h31-misdirected-request\">H31 - Misdirected Request</a></h2>\n<p>The client sent a request to the wrong endpoint. This could be because the client used stale DNS information or is accessing the app through a CDN that has stale DNS information. Verify that <a href=\"https://devcenter.heroku.com/articles/custom-domains\">DNS is correctly configured for your app</a>. If a CDN is configured for the app, consider contacting your CDN provider.</p>\n<p>If you and your app users can successfully access the app in a browser (or however the app is used), this may not be cause for concern. The errors may be caused by clients (typically web-crawlers) with cached DNS entries trying to access a now-invalid endpoint or IP address for your app.</p>\n<p>You can verify the validity of user agent through the app log error message as shown in the example below:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">error code=H31 desc=\"Misdirected Request\" method=GET path=\"/\" host=[host.com] request_id=[guid] fwd=\"[IP]\" dyno= connect= service= status=421 bytes= protocol=http agent=\"&lt;agent>\"</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h80-maintenance-mode\">H80 - Maintenance mode</a></h2>\n<p>This is not an error, but we give it a code for the sake of completeness. Note the log formatting is the same but without the word \"Error\".</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=info code=H80 desc=\"Maintenance mode\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h81-blank-app\">H81 - Blank app</a></h2>\n<p>No code has been pushed to this application. To get rid of this message you need to do one <a href=\"https://devcenter.heroku.com/articles/git#deploying-code\">deploy</a>. This is not an error, but we give it a code for the sake of completeness.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=info code=H81 desc=\"Blank app\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h82-free-dyno-quota-exhausted\">H82 - Free dyno quota exhausted</a></h2>\n<p>This indicates that an account's <a href=\"https://devcenter.heroku.com/articles/free-dyno-hours\">free dyno hour quota</a> is exhausted and that apps running free dynos are sleeping. You can view your app's free dyno usage in the <a href=\"https://dashboard.heroku.com/account/billing\">Heroku dashboard</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2015-10-06T21:51:07-07:00 heroku[router]: at=info code=H82 desc=\"Free dyno quota exhausted\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#h99-platform-error\">H99 - Platform error</a></h2>\n<p>H99 and R99 are the only error codes that represent errors in the Heroku platform.</p>\n<p>This indicates an internal error in the Heroku platform. Unlike all of the other errors which will require action from you to correct, this one does not require action from you. Try again in a minute, or check <a href=\"http://status.heroku.com/\">the status site</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2010-10-06T21:51:07-07:00 heroku[router]: at=error code=H99 desc=\"Platform error\" method=GET path=\"/\" host=myapp.herokuapp.com fwd=17.17.17.17 dyno= connect= service= status=503 bytes=</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#r10-boot-timeout\">R10 - Boot timeout</a></h2>\n<p>A web process took longer than 60 seconds to bind to its assigned <code class=\"language-text\">$PORT</code>. When this happens, the dyno's process is killed and the dyno is considered crashed. Crashed dynos are restarted according to the dyno manager's <a href=\"https://devcenter.heroku.com/articles/dynos#automatic-dyno-restarts\">restart policy</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2011-05-03T17:31:38+00:00 heroku[web.1]: State changed from created to starting\n2011-05-03T17:31:40+00:00 heroku[web.1]: Starting process with command: `bundle exec rails server -p 22020 -e production`\n2011-05-03T17:32:40+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch\n2011-05-03T17:32:40+00:00 heroku[web.1]: Stopping process with SIGKILL\n2011-05-03T17:32:40+00:00 heroku[web.1]: Process exited\n2011-05-03T17:32:41+00:00 heroku[web.1]: State changed from starting to crashed</code></pre></div>\n<p>This error is often caused by a process being unable to reach an external resource, such as a database, or the application doing too much work, such as parsing and evaluating numerous, large code dependencies, during startup.</p>\n<p>Common solutions are to access external resources asynchronously, so they don't block startup, and to reduce the amount of application code or its dependencies.</p>\n<p>If your application requires more time to boot, you may use the <a href=\"https://tools.heroku.support/limits/boot_timeout\">boot timeout tool</a> to increase the limit. However, in general, slow boot times will make it harder to deploy your application and will make recovery from dyno failures slower, so this should be considered a <em>temporary solution</em>.</p>\n<p>One exception is for apps using the <a href=\"https://devcenter.heroku.com/articles/java-support\">Java buildpack</a>, <a href=\"https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku\">Gradle buildpack</a>, <a href=\"https://devcenter.heroku.com/articles/war-deployment#deployment-with-the-heroku-cli\">heroku-deploy toolbelt plugin</a>, or <a href=\"https://devcenter.heroku.com/articles/deploying-java-applications-with-the-heroku-maven-plugin\">Heroku Maven plugin</a>, which will be allowed 90 seconds to bind to their assigned port.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#r12-exit-timeout\">R12 - Exit timeout</a></h2>\n<p>A process failed to exit within 30 seconds of being sent a SIGTERM indicating that it should stop. The process is sent SIGKILL to force an exit.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2011-05-03T17:40:10+00:00 app[worker.1]: Working\n2011-05-03T17:40:11+00:00 heroku[worker.1]: Stopping process with SIGTERM\n2011-05-03T17:40:11+00:00 app[worker.1]: Ignoring SIGTERM\n2011-05-03T17:40:14+00:00 app[worker.1]: Working\n2011-05-03T17:40:18+00:00 app[worker.1]: Working\n2011-05-03T17:40:21+00:00 heroku[worker.1]: Error R12 (Exit timeout) -> Process failed to exit within 30 seconds of SIGTERM\n2011-05-03T17:40:21+00:00 heroku[worker.1]: Stopping process with SIGKILL\n2011-05-03T17:40:21+00:00 heroku[worker.1]: Process exited</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#r13-attach-error\">R13 - Attach error</a></h2>\n<p>A dyno started with <code class=\"language-text\">heroku run</code> failed to attach to the invoking client.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2011-06-29T02:13:29+00:00 app[run.3]: Awaiting client\n2011-06-29T02:13:30+00:00 heroku[run.3]: State changed from starting to up\n2011-06-29T02:13:59+00:00 app[run.3]: Error R13 (Attach error) -> Failed to attach to process\n2011-06-29T02:13:59+00:00 heroku[run.3]: Process exited</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#r14-memory-quota-exceeded\">R14 - Memory quota exceeded</a></h2>\n<p>A dyno requires memory in excess of its <a href=\"https://devcenter.heroku.com/articles/dynos#memory-behavior\">quota</a>. If this error occurs, the dyno will <a href=\"http://en.wikipedia.org/wiki/Paging\">page to swap space</a> to continue running, which may cause degraded process performance. The R14 error is calculated by total memory swap, rss and cache.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2011-05-03T17:40:10+00:00 app[worker.1]: Working\n2011-05-03T17:40:10+00:00 heroku[worker.1]: Process running mem=1028MB(103.3%)\n2011-05-03T17:40:11+00:00 heroku[worker.1]: Error R14 (Memory quota exceeded)\n2011-05-03T17:41:52+00:00 app[worker.1]: Working</code></pre></div>\n<p>If you are getting a large number of R14 errors, your application performance is likely severely degraded. Resolving R14 memory errors are language specific:</p>\n<ul>\n<li><a href=\"https://devcenter.heroku.com/articles/ruby-memory-use\">R14 - Memory Quota Exceeded in Ruby (MRI)</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/java-memory-issues\">Troubleshooting Memory Issues in Java Applications</a></li>\n<li><a href=\"https://devcenter.heroku.com/articles/node-memory-use\">Troubleshooting Node.js Memory Use</a></li>\n</ul>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#r15-memory-quota-vastly-exceeded\">R15 - Memory quota vastly exceeded</a></h2>\n<p>A dyno requires vastly more memory than its <a href=\"https://devcenter.heroku.com/articles/dynos#memory-behavior\">quota</a> and is consuming excessive swap space. If this error occurs, the dyno will be forcibly killed with <code class=\"language-text\">SIGKILL</code> (which cannot be caught or handled) by the platform. The R15 error is calculated by total memory swap and rss; cache is not included.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2011-05-03T17:40:10+00:00 app[worker.1]: Working\n2011-05-03T17:40:10+00:00 heroku[worker.1]: Process running mem=1029MB(201.0%)\n2011-05-03T17:40:11+00:00 heroku[worker.1]: Error R15 (Memory quota vastly exceeded)\n2011-05-03T17:40:11+00:00 heroku[worker.1]: Stopping process with SIGKILL\n2011-05-03T17:40:12+00:00 heroku[worker.1]: Process exited</code></pre></div>\n<p>In Private Spaces, dynos exceeding their memory quota do not use swap space and thus do not emit R14 errors.</p>\n<p>Private Space dynos vastly exceeding their memory quota generally will emit R15 errors but occasionally the platform may shut down the dyno before the R15 is sent, causing the error to be dropped. <em>If</em> an R15 is emitted it will only be visible in the app log stream but not in the dashboard <a href=\"https://devcenter.heroku.com/articles/metrics\">Application Metrics</a> interface. Other non-R15 types of errors from Private Space dynos are correctly surfaced in the Application Metrics interface.</p>\n<p>For Private Space dynos vastly exceeding their memory quota the platform kills dyno processes consuming large amounts of memory, but may not kill the dyno itself.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#r16-detached\">R16 - Detached</a></h2>\n<p>An attached dyno is continuing to run after being sent <code class=\"language-text\">SIGHUP</code> when its external connection was closed. This is usually a mistake, though some apps might want to do this intentionally.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2011-05-03T17:32:03+00:00 heroku[run.1]: Awaiting client\n2011-05-03T17:32:03+00:00 heroku[run.1]: Starting process with command `bash`\n2011-05-03T17:40:11+00:00 heroku[run.1]: Client connection closed. Sending SIGHUP to all processes\n2011-05-03T17:40:16+00:00 heroku[run.1]: Client connection closed. Sending SIGHUP to all processes\n2011-05-03T17:40:21+00:00 heroku[run.1]: Client connection closed. Sending SIGHUP to all processes\n2011-05-03T17:40:26+00:00 heroku[run.1]: Error R16 (Detached) -> An attached process is not responding to SIGHUP after its external connection was closed.</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#r17-checksum-error\">R17 - Checksum error</a></h2>\n<p>This indicates an error with runtime <a href=\"https://devcenter.heroku.com/articles/slug-checksums\">slug checksum</a> verification. If the checksum does not match or there is another problem with the checksum when launch a dyno, an R17 error will occur and the dyno will fail to launch. Check the log stream for details about the error.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2016-08-16T12:39:56.439438+00:00 heroku[web.1]: State changed from provisioning to starting\n2016-08-16T12:39:57.110759+00:00 heroku[web.1]: Error R17 (Checksum error) -> Checksum does match expected value. Expected: SHA256:ed5718e83475c780145609cbb2e4f77ec8076f6f59ebc8a916fb790fbdb1ae64 Actual: SHA256:9ca15af16e06625dfd123ebc3472afb0c5091645512b31ac3dd355f0d8cc42c1\n2016-08-16T12:39:57.212053+00:00 heroku[web.1]: State changed from starting to crashed</code></pre></div>\n<p>If this error occurs, try deploying a new release with a correct checksum or rolling back to an older release. Ensure the checksum is <a href=\"https://devcenter.heroku.com/articles/slug-checksums\">formatted and calculated correctly</a> with the SHA256 algorithm. The checksum must start with <code class=\"language-text\">SHA256:</code> followed by the calculated SHA256 value for the compressed slug. If you did not manually calculate the checksum and error continues to occur, please contact Heroku support.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#r99-platform-error\">R99 - Platform error</a></h2>\n<p>R99 and H99 are the only error codes that represent errors in the Heroku platform.</p>\n<p>This indicates an internal error in the Heroku platform. Unlike all of the other errors which will require action from you to correct, this one does not require action from you. Try again in a minute, or check <a href=\"http://status.heroku.com/\">the status site</a>.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#l10-drain-buffer-overflow\">L10 - Drain buffer overflow</a></h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2013-04-17T19:04:46+00:00 d.1234-drain-identifier-567 heroku logplex - - Error L10 (output buffer overflow): 500 messages dropped since 2013-04-17T19:04:46+00:00.</code></pre></div>\n<p>The number of log messages being generated has temporarily exceeded the rate at which they can be received by a drain consumer (such as a log management add-on) and Logplex, <a href=\"https://devcenter.heroku.com/articles/logging\">Heroku's logging system</a>, has discarded some messages in order to handle the rate difference.</p>\n<p>A common cause of L10 error messages is the exhaustion of capacity in a log consumer. If a log management add-on or similar system can only accept so many messages per time period, your application may experience L10s after crossing that threshold.</p>\n<p>Another common cause of L10 error messages is a sudden burst of log messages from a dyno. As each line of dyno output (e.g. a line of a stack trace) is a single log message, and Logplex limits the total number of un-transmitted log messages it will keep in memory to 1024 messages, a burst of lines from a dyno can overflow buffers in Logplex. In order to allow the log stream to catch up, Logplex will discard messages where necessary, keeping newer messages in favor of older ones.</p>\n<p>You may need to investigate reducing the volume of log lines output by your application (e.g. condense multiple log lines into a smaller, single-line entry). You can also use the <code class=\"language-text\">heroku logs -t</code> command to get a live feed of logs and find out where your problem might be. A single dyno stuck in a loop that generates log messages can force an L10 error, as can a problematic code path that causes all dynos to generate a multi-line stack trace for some code paths.</p>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#l11-tail-buffer-overflow\">L11 - Tail buffer overflow</a></h2>\n<p>A heroku logs --tail session cannot keep up with the volume of logs generated by the application or log channel, and Logplex has discarded some log lines necessary to catch up. To avoid this error you will need run the command on a faster internet connection (increase the rate at which you can receive logs) or you will need to modify your application to reduce the logging volume (decrease the rate at which logs are generated).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2011-05-03T17:40:10+00:00 heroku[logplex]: L11 (Tail buffer overflow) -> This tail session dropped 1101 messages since 2011-05-03T17:35:00+00:00</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#l12-local-buffer-overflow\">L12 - Local buffer overflow</a></h2>\n<p>The application is producing logs faster than the local delivery process (log-shuttle) can deliver them to logplex and has discarded some log lines in order to keep up. If this error is sustained you will need to reduce the logging volume of your application.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2013-11-04T21:31:32.125756+00:00 app[log-shuttle]: Error L12: 222 messages dropped since 2013-11-04T21:31:32.125756+00:00.</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#l13-local-delivery-error\">L13 - Local delivery error</a></h2>\n<p>The local log delivery process (log-shuttle) was unable to deliver some logs to Logplex and has discarded them. This can happen during transient network errors or during logplex service degradation. If this error is sustained please contact support.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2013-11-04T21:31:32.125756+00:00 app[log-shuttle]: Error L13: 111 messages lost since 2013-11-04T21:31:32.125756+00:00.</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#l14-certificate-validation-error\">L14 - Certificate validation error</a></h2>\n<p>The application is configured with a TLS syslog drain that doesn't have a valid TLS certificate.</p>\n<p>You should check that:</p>\n<ol>\n<li>You're not using a self-signed certificate.</li>\n<li>The certificate is up to date.</li>\n<li>The certificate is signed by a known and trusted CA.</li>\n<li>The CN hostname embedded in the certificate matches the hostname being connected to.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">2015-09-04T23:28:48+00:00 heroku[logplex]: Error L14 (certificate validation): error=\"bad certificate\" uri=\"syslog+tls://logs.example.com:6514/\"</code></pre></div>\n<h2><a href=\"https://devcenter.heroku.com/articles/error-codes#l15-tail-buffer-temporarily-unavailable\">L15 - Tail buffer temporarily unavailable</a></h2>\n<p>The tail buffer that stores the last 1500 lines of your logs is temporarily unavailable. Run <code class=\"language-text\">heroku logs</code> again. If you still encounter the error, run <code class=\"language-text\">heroku logs -t</code> to stream your logs (which does not use the tail buffer).</p>"},{"url":"/docs/quick-ref/markdown-dropdowns/","relativePath":"docs/quick-ref/markdown-dropdowns.md","relativeDir":"docs/quick-ref","base":"markdown-dropdowns.md","name":"markdown-dropdowns","frontmatter":{"title":"Markdown Dropdown","weight":0,"excerpt":"Markdown Dropdown","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Markdown Dropdown:</h1>\n<details>\n<summary>How do I dropdown?</summary>\n<br>\nThis is how you dropdown.\n<br>\n<br>\n<pre>\n&lt;details&gt;\n&lt;summary&gt;How do I dropdown?&lt;&#47;summary&gt;\n&lt;br&gt;\nThis is how you dropdown.\n&lt;&#47;details&gt;\n</pre>\n</details>\n<hr>\n<details open>\n<summary>Want to ruin the surprise?</summary>\n<br>\nWell, you asked for it!\n<br>\n<br>\n<pre>\n&lt;details open&gt;\n&lt;summary&gt;Want to ruin the surprise?&lt;&#47;summary&gt;\n&lt;br&gt;\nWell, you asked for it!\n&lt;&#47;details&gt;\n</pre>\n</details>"},{"url":"/docs/quick-ref/git-tricks/","relativePath":"docs/quick-ref/git-tricks.md","relativeDir":"docs/quick-ref","base":"git-tricks.md","name":"git-tricks","frontmatter":{"title":"Git Tricks","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Useful config <a href=\"https://w3c.github.io/git.html#config\">🔗</a>\n\n</h2>\n<ul>\n<li>branch.autosetuprebase=always (<a href=\"https://git-scm.com/docs/git-config#git-config-branchautoSetupRebase\">documentation</a>): I find it easier to work with Git this way</li>\n<li></li>\n<li>core.editor=emacs -nw (<a href=\"https://git-scm.com/docs/git-config#git-config-coreeditor\">documentation</a>): that's the editor that will be invoked every time Git needs to ask you about a commit message, when you're squashing commits, etc (and of course, you want emacs for that)</li>\n<li>commit.gpgsign=true (<a href=\"https://git-scm.com/docs/git-config#git-config-commitgpgSign\">documentation</a>) and gpg.program=gpg2 (<a href=\"https://git-scm.com/docs/git-config#git-config-gpgprogram\">documentation</a>): you will need to set up these variables (and possibly a couple other) if you want to <a href=\"https://help.github.com/articles/signing-commits-with-gpg/\">sign your commits to GitHub using GPG (recommended)</a></li>\n</ul>\n<h2>Safest way to \"update\" a local copy <a href=\"https://w3c.github.io/git.html#update\">🔗</a></h2>\n<p>I find this sequence of commands the \"safest\" way to quickly \"refresh\" a clone of some remote repo, and at the same time check its status (where \"safest\" means <em>\"reducing to the minimum the probability of messing up things with conflicts, outdated branches, uncommitted changes, etc\"</em>):</p>\n<ul>\n<li>$ git branch -a displays information about <em>all</em> branches, both local and <em>remote</em></li>\n<li></li>\n<li>$ git pull -r fetches changes from the <em>remote</em> and [\"rebases the current branch on top of the upstream branch after fetching\"](https:</li>\n<li></li>\n<li>$ git status shows you the status of your copy: whether there are new files, missing files, unstaged changes, or commits pending push</li>\n<li>$ git remote prune origin --dry tells you if any branch in the <em>remote</em> has been recently removed. (Submit the same command <em>without</em> the --dry part to actually remove those remotes from your local origin. That will still <em>not</em> remove local branches automatically, but you can do that yourself with git branch -d &#x3C;BRANCH> if you see some branch is no longer necessary.)</li>\n</ul>\n<p>You can have those four lines as an <em>alias</em>, or inside a <em>script</em> somewhere.</p>\n<p>Even better: if you set up <a href=\"https://w3c.github.io/git.html#aliases\">the aliases suggested above</a>, the whole thing becomes:</p>\n<p>You can then type it and run it just once, and, from that moment on, simply recover the line from your shell history.</p>\n<p>For example, if you're using Bash: press Ctrl+r, then start typing a distinctive chunk of the line (eg, r;, or st;gi); if you used it not too long ago for the last time, the entire line should appear, and you can simply press Enter.</p>\n<h2>An alias to view the history of the repo <a href=\"https://w3c.github.io/git.html#lg\">🔗</a></h2>\n<p>Then, simply type</p>\n<p>for a colourful graph of commits, tags and branches.</p>"},{"url":"/docs/quick-ref/minifiction/","relativePath":"docs/quick-ref/minifiction.md","relativeDir":"docs/quick-ref","base":"minifiction.md","name":"minifiction","frontmatter":{"title":"Minification","weight":0,"excerpt":"How To Minify Code For Better Web Performance","seo":{"title":"Minification","description":"How To Minify Code For Better Web Performance","robots":[],"extra":[]},"template":"docs"},"html":"<p>In production, it is recommended to minify any JavaScript code that is included with your application. <strong>Minification can help your website load several times faster,</strong> especially as the size of your JavaScript source code grows.</p>\n<p>Here's one way to set it up:</p>\n<ol>\n<li><a href=\"https://nodejs.org/\">Install Node.js</a></li>\n<li>Run npm init -y in your project folder (<strong>don't skip this step!</strong>)</li>\n<li>Run npm install terser</li>\n</ol>\n<p>Now, to minify a file called like_button.js, run in the terminal:</p>\n<p>This will produce a file called like_button.min.js with the minified code in the same directory. If you're typing this often, you can <a href=\"https://medium.freecodecamp.org/introduction-to-npm-scripts-1dbb2ae01633\">create an npm script</a> to give this command a name.</p>\n<h2>How to Minify Your Minify your HTML, CSS and JavaScript Using an Online Tool\n\n</h2>\n<p>Many of these online tools have a similar process which involve the following steps:</p>\n<p>Paste in your source code or upload the source code file.\nOptimize the settings for a specific output (if options are available)\nClick a button to minify or compress the code.\nCopy the minified code output or download the minified code file.</p>\n<p>For this example, I'm going to use the minify tools from minifycode.com.</p>\n<p>First, locate the css file (commonly named style.css) in your site files and open the file using a page editor. Then copy the entire css code to your clipboard.</p>\n<p><img src=\"https://www.elegantthemes.com/blog/wp-content/uploads/2018/12/min4.png\" alt=\"image\"></p>\n<p>Go to <a href=\"http://minifycode.com/css-minifier/\">minifycode.com</a> and click the CSS minifier tab. Then paste the CSS code into the input box and click the Minify CSS button.</p>\n<p><img src=\"https://www.elegantthemes.com/blog/wp-content/uploads/2018/12/min5.png\" alt=\"image\"></p>\n<p>After the new minified code is generated, copy the code.</p>\n<p><img src=\"https://www.elegantthemes.com/blog/wp-content/uploads/2018/12/min6.png\" alt=\"image\"></p>\n<p>Then go back to the css file of your website and replace the code with the new minified version.</p>\n<p>That's it!</p>\n<p>Repeat the same process to minify your site's JavaScript and Html file(s) as well.</p>\n<h3>Overview\n\n</h3>\n<p>Minification refers to the process of removing unnecessary or redundant data without affecting how the resource is processed by the browser - e.g. code comments and formatting, removing unused code, using shorter variable and function names, and so on.</p>\n<p>See <a href=\"https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/optimize-encoding-and-transfer#minification-preprocessing--context-specific-optimizations\">preprocessing &#x26; context-specific optimizations</a> to learn more.</p>\n<h3>Recommendations</h3>\n<p>You should minify your HTML, CSS, and JavaScript resources:</p>\n<ul>\n<li>To minify HTML, try <a href=\"https://github.com/kangax/html-minifier\">HTMLMinifier</a></li>\n<li>-</li>\n<li>To minify CSS, try <a href=\"https://github.com/ben-eb/cssnano\">CSSNano</a> and <a href=\"https://github.com/css/csso\">csso</a>.</li>\n<li>To minify JavaScript, try <a href=\"https://github.com/mishoo/UglifyJS2\">UglifyJS</a>. The <a href=\"https://developers.google.com/closure/compiler\">Closure Compiler</a> is also <a href=\"https://github.com/samccone/The-cost-of-transpiling-es2015-in-2016#summary-of-findings\">very effective</a>. You can create a build process that uses these tools to minify and rename the development files and save them to a production directory.</li>\n</ul>\n<p>Alternatively, the <a href=\"https://developers.google.com/speed/pagespeed/module\">PageSpeed Module</a>, integrates with an Apache or Nginx web server to automatically optimize your site, including resource minification.</p>"},{"url":"/docs/quick-ref/new-repo-instructions/","relativePath":"docs/quick-ref/new-repo-instructions.md","relativeDir":"docs/quick-ref","base":"new-repo-instructions.md","name":"new-repo-instructions","frontmatter":{"title":"new-repo-git","weight":0,"seo":{"title":"new-repo-git","description":"This is the new-repo-git page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"new-repo-git","keyName":"property"},{"name":"og:description","value":"This is the new-repo-git page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"new-repo-git"},{"name":"twitter:description","value":"This is the new-repo-git page"}]},"template":"docs"},"html":"<h3>...or create a new repository on the command line</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">echo \"# React-Self-Study\" >> README.md\ngit init\ngit add README.md\ngit commit -m \"first commit\"\ngit branch -M master\ngit remote add origin https://github.com/bgoonz/React-Self-Study.git\ngit push -u origin master</code></pre></div>\n<h3>...or push an existing repository from the command line</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git remote add origin https://github.com/bgoonz/React-Self-Study.git\ngit branch -M master\ngit push -u origin master</code></pre></div>\n<h3>...or import code from another repository</h3>\n<p>You can initialize this repository with code from a Subversion, Mercurial, or TFS project.</p>"},{"url":"/docs/quick-ref/installation/","relativePath":"docs/quick-ref/installation.md","relativeDir":"docs/quick-ref","base":"installation.md","name":"installation","frontmatter":{"title":"Installation","weight":0,"seo":{"title":"Installation","description":"This is the installation page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Installation","keyName":"property"},{"name":"og:description","value":"This is the installation page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Installation"},{"name":"twitter:description","value":"This is the installation page"}]},"template":"docs"},"html":"<h1>Basic Web Development Environment Setup</h1>\n<blockquote>\n<p>Windows Subsystem for Linux (WSL) and Ubuntu</p>\n</blockquote>\n<h2>Windows Subsystem for Linux (WSL) and Ubuntu</h2>\n<p><a href=\"https://bryanguner.medium.com/?source=post_page-----9f36c3f15afe--------------------------------\"><img src=\"https://miro.medium.com/fit/c/96/96/1*ao1cHo7EQ4faDV8YNJwh_Q.png\" alt=\"Bryan Guner\"></a></p>\n<p><img src=\"https://miro.medium.com/max/60/0*aqKP1drNHmNm34zz.jpg?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/1600/0*aqKP1drNHmNm34zz.jpg\" alt=\"medium blog image\"></p>\n<p>Test if you have Ubuntu installed by typing \"Ubuntu\" in the search box in the bottom app bar that reads \"Type here to search\". If you see a search result that reads <strong>\"Ubuntu 20.04 LTS\"</strong> with \"App\" under it, then you have it installed.</p>\n<ol>\n<li>In the application search box in the bottom bar, type \"PowerShell\" to find the application named \"Windows PowerShell\"</li>\n<li>Right-click on \"Windows PowerShell\" and choose \"Run as administrator\" from the popup menu</li>\n<li>In the blue PowerShell window, type the following: <code class=\"language-text\">Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux</code></li>\n<li>Restart your computer</li>\n<li>In the application search box in the bottom bar, type \"Store\" to find the application named \"Microsoft Store\"</li>\n<li>Click \"Microsoft Store\"</li>\n<li>Click the \"Search\" button in the upper-right corner of the window</li>\n<li>Type in \"Ubuntu\"</li>\n<li>Click \"Run Linux on Windows (Get the apps)\"</li>\n<li>Click the orange tile labeled <strong>\"Ubuntu\"</strong> Note that there are 3 versions in the Microsoft Store… you want the one just entitled 'Ubuntu'</li>\n<li>Click \"Install\"</li>\n<li>After it downloads, click \"Launch\"</li>\n<li>If you get the option, pin the application to the task bar. Otherwise, right-click on the orange Ubuntu icon in the task bar and choose \"Pin to taskbar\"</li>\n<li>When prompted to \"Enter new UNIX username\", type your first name with no spaces</li>\n<li>When prompted, enter and retype a password for this UNIX user (it can be the same as your Windows password)</li>\n<li>Confirm your installation by typing the command <code class=\"language-text\">whoami 'as in who-am-i'</code>followed by Enter at the prompt (it should print your first name)</li>\n<li>You need to update your packages, so type <code class=\"language-text\">sudo apt update</code> (if prompted for your password, enter it)</li>\n<li>You need to upgrade your packages, so type <code class=\"language-text\">sudo apt upgrade</code> (if prompted for your password, enter it)</li>\n</ol>\n<p>Git comes with Ubuntu, so there's nothing to install. However, you should configure it using the following instructions.</p>\n<p>‌Open an Ubuntu terminal if you don't have one open already.</p>\n<ol>\n<li>You need to configure Git, so type <code class=\"language-text\">git config --global user.name \"Your Name\"</code> with replacing \"Your Name\" with your real name.</li>\n<li>You need to configure Git, so type <code class=\"language-text\">git config --global user.email your@email.com</code> with replacing \"<a href=\"mailto:your@email.com\">your@email.com</a>\" with your real email.</li>\n</ol>\n<p><strong>Note: if you want git to remember your login credentials type:</strong></p>\n<p>$ git config --global credential.helper store</p>\n<p>Test if you have Chrome installed by typing \"Chrome\" in the search box in the bottom app bar that reads \"Type here to search\". If you see a search result that reads \"Chrome\" with \"App\" under it, then you have it installed. Otherwise, follow these instructions to install Google Chrome.</p>\n<ol>\n<li>Open Microsoft Edge, the blue \"e\" in the task bar, and type in <a href=\"http://chrome.google.com/\">http://chrome.google.com</a>. Click the \"Download Chrome\" button. Click the \"Accept and Install\" button after reading the terms of service. Click \"Save\" in the \"What do you want to do with ChromeSetup.exe\" dialog at the bottom of the window. When you have the option to \"Run\" it, do so. Answer the questions as you'd like. Set it as the default browser.</li>\n<li>Right-click on the Chrome icon in the task bar and choose \"Pin to taskbar\".</li>\n</ol>\n<p>Test if you have Node.js installed by opening an Ubuntu terminal and typing <code class=\"language-text\">node --version</code>. If it reports \"Command 'node' not found\", then you need to follow these directions.</p>\n<ol>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">sudo apt update</code> and press Enter</li>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">sudo apt install build-essential</code> and press Enter</li>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash</code> and press Enter</li>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">. ./.bashrc</code> and press Enter</li>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">nvm install --lts</code> and press Enter</li>\n<li>Confirm that <strong>node</strong> is installed by typing <code class=\"language-text\">node --version</code> and seeing it print something that is not \"Command not found\"!</li>\n</ol>\n<p>You will often have to download a zip file and unzip it. It is easier to do this from the command line. So we need to install a linux unzip utility.</p>\n<p>‌In the Ubuntu terminal type: <code class=\"language-text\">sudo apt install unzip</code> and press Enter</p>\n<p>‌Mocha.js</p>\n<p>Test if you have Mocha.js installed by opening an Ubuntu terminal and typing <code class=\"language-text\">which mocha</code>. If it prints a path, then you're good. Otherwise, if it prints nothing, install Mocha.js by typing <code class=\"language-text\">npm install -g mocha</code>.</p>\n<p>Ubuntu does not come with Python 3. Install it using the command <code class=\"language-text\">sudo apt install python3</code>. Test it by typing <code class=\"language-text\">python3 --version</code> and seeing it print a number.</p>\n<p>‌</p>\n<p>As of the time of writing of this document, WSL has an issue renaming or deleting files if Visual Studio Code is open. So before doing any linux commands which manipulate files, make sure you <strong>close</strong> Visual Studio Code before running those commands in the Ubuntu terminal.</p>\n<p># Installing build essentials<br>\nsudo apt-get install -y build-essential libssl-dev<br>\n# Nodejs and NVM<br>\ncurl -o- <a href=\"https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh\">https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh</a> | bash<br>\nsource ~/.profile<br>\nsudo nvm install 7.10.0<br>\nsudo nvm use 7.10.0<br>\nnode -v  </p>\n<h1>nodemon</h1>\n<p>sudo npm install -g nodemon<br>\nsudo npm install -g loopback-cli<br>\n# Forever to run nodejs scripts forever<br>\nsudo npm install forever -g<br>\n# Git - a version control system<br>\nsudo apt-get update<br>\nsudo apt-get install -y git xclip<br>\n# Grunt - an automated task runner<br>\nsudo npm install -g grunt-cli<br>\n# Bower - a dependency manager<br>\nsudo npm install -g bower<br>\n# Yeoman - for generators<br>\nsudo npm install -g yo<br>\n# maven<br>\nsudo apt-get install maven -y<br>\n# Gulp - an automated task runner<br>\nsudo npm install -g gulp-cli<br>\n# Angular FullStack - My favorite MEAN boilerplate (MEAN = MongoDB, Express, Angularjs, Nodejs)<br>\nsudo npm install -g generator-angular-fullstack<br>\n# Vim, Curl, Python - Some random useful stuff<br>\nsudo apt-get install -y vim curl python-software-properties<br>\nsudo apt-get install -y python-dev, python-pip<br>\nsudo apt-get install -y libkrb5-dev<br>\n# Installing JDK and JRE<br>\nsudo apt-get install -y default-jre<br>\nsudo apt-get install -y default-jdk<br>\n# Archive Extractors<br>\nsudo apt-get install -y unace unrar zip unzip p7zip-full p7zip-rar sharutils rar uudeview mpack arj cabextract file-roller<br>\n# FileZilla - a FTP client<br>\nsudo apt-get install -y filezilla</p>\n<h2>If you found this guide helpful feel free to checkout my github/gists where I host similar content:</h2>\n<p><a href=\"https://gist.github.com/bgoonz\">bgoonz's gists · GitHub</a></p>\n<p>Or Checkout my personal Resource Site:</p>\n<p><a href=\"https://levelup.gitconnected.com/basic-web-development-environment-setup-9f36c3f15afe\">Source</a></p>"},{"url":"/docs/quick-ref/quick-links/","relativePath":"docs/quick-ref/quick-links.md","relativeDir":"docs/quick-ref","base":"quick-links.md","name":"quick-links","frontmatter":{"title":"Quick Links","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Gitbook Websites:</h1>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/datastructures-in-pytho/\">Python</a></li>\n<li></li>\n<li><a href=\"https://bryan-guner.gitbook.io/web-dev-hub-docs/\">General</a></li>\n<li></li>\n<li><a href=\"https://bryan-guner.gitbook.io/solidarity-blockchain-nfts/\">Blockchain &#x26; NFTs</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/mynotes/\">React</a></li>\n</ul>\n<h1>Sites I Wish To Revisit:</h1>\n<ul>\n<li><a href=\"https://hasura.io/learn/\">Hasura</a></li>\n</ul>"},{"url":"/docs/quick-ref/python-builtin-functions/","relativePath":"docs/quick-ref/python-builtin-functions.md","relativeDir":"docs/quick-ref","base":"python-builtin-functions.md","name":"python-builtin-functions","frontmatter":{"title":"Python Builtin Functions","weight":0,"excerpt":"Python Builtin Functions","seo":{"title":"Python Builtin Functions","description":"Python Builtin Functions","robots":[],"extra":[]},"template":"docs"},"html":"<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the absolute value of a number</span>\n<span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns True if all items in an iterable object are true</span>\n<span class=\"token builtin\">any</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns True if any item in an iterable object is true</span>\n<span class=\"token builtin\">ascii</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a readable version of an object. Replaces none-ascii characters with escape character</span>\n<span class=\"token builtin\">bin</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the binary version of a number</span>\n<span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the boolean value of the specified object</span>\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns an array of bytes</span>\n<span class=\"token builtin\">bytes</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a bytes object</span>\n<span class=\"token builtin\">callable</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns True if the specified object is callable, otherwise False</span>\n<span class=\"token builtin\">chr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a character from the specified Unicode code.</span>\n<span class=\"token builtin\">classmethod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t<span class=\"token comment\">#Converts a method into a class method</span>\n<span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns the specified source as an object, ready to be executed</span>\n<span class=\"token builtin\">complex</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns a complex number</span>\n<span class=\"token builtin\">delattr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Deletes the specified attribute (property or method) from the specified object</span>\n<span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a dictionary (Array)</span>\n<span class=\"token builtin\">dir</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a list of the specified object's properties and methods</span>\n<span class=\"token builtin\">divmod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns the quotient and the remainder when argument1 is divided by argument2</span>\n<span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Takes a collection (e.g. a tuple) and returns it as an enumerate object</span>\n<span class=\"token builtin\">eval</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Evaluates and executes an expression</span>\n<span class=\"token keyword\">exec</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Executes the specified code (or object)</span>\n<span class=\"token builtin\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Use a filter function to exclude items in an iterable object</span>\n<span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a floating point number</span>\n<span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Formats a specified value</span>\n<span class=\"token builtin\">frozenset</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns a frozenset object</span>\n<span class=\"token builtin\">getattr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns the value of the specified attribute (property or method)</span>\n<span class=\"token builtin\">globals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns the current global symbol table as a dictionary</span>\n<span class=\"token builtin\">hasattr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns True if the specified object has the specified attribute (property/method)</span>\n<span class=\"token builtin\">hash</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the hash value of a specified object</span>\n<span class=\"token builtin\">help</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Executes the built-in help system</span>\n<span class=\"token builtin\">hex</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Converts a number into a hexadecimal value</span>\n<span class=\"token builtin\">id</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the id of an object</span>\n<span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Allowing user input</span>\n<span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns an integer number</span>\n<span class=\"token builtin\">isinstance</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t<span class=\"token comment\">#Returns True if a specified object is an instance of a specified object</span>\n<span class=\"token builtin\">issubclass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t<span class=\"token comment\">#Returns True if a specified class is a subclass of a specified object</span>\n<span class=\"token builtin\">iter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns an iterator object</span>\n<span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the length of an object</span>\n<span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a list</span>\n<span class=\"token builtin\">locals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns an updated dictionary of the current local symbol table</span>\n<span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the specified iterator with the specified function applied to each item</span>\n<span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the largest item in an iterable</span>\n<span class=\"token builtin\">memoryview</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t<span class=\"token comment\">#Returns a memory view object</span>\n<span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the smallest item in an iterable</span>\n<span class=\"token builtin\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the next item in an iterable</span>\n<span class=\"token builtin\">object</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns a new object</span>\n<span class=\"token builtin\">oct</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Converts a number into an octal</span>\n<span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Opens a file and returns a file object</span>\n<span class=\"token builtin\">ord</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Convert an integer representing the Unicode of the specified character</span>\n<span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the value of x to the power of y</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Prints to the standard output device</span>\n<span class=\"token builtin\">property</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Gets, sets, deletes a property</span>\n<span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a sequence of numbers, starting from 0 and increments by 1 (by default)</span>\n<span class=\"token builtin\">repr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a readable version of an object</span>\n<span class=\"token builtin\">reversed</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns a reversed iterator</span>\n<span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Rounds a numbers</span>\n<span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a new set object</span>\n<span class=\"token builtin\">setattr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Sets an attribute (property/method) of an object</span>\n<span class=\"token builtin\">slice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a slice object</span>\n<span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t<span class=\"token comment\">#Returns a sorted list</span>\n<span class=\"token builtin\">staticmethod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t<span class=\"token comment\">#Converts a method into a static method</span>\n<span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a string object</span>\n<span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Sums the items of an iterator</span>\n<span class=\"token builtin\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns an object that represents the parent class</span>\n<span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns a tuple</span>\n<span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the type of an object</span>\n<span class=\"token builtin\">vars</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns the __dict__ property of an object</span>\n<span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\t\t\t<span class=\"token comment\">#Returns an iterator, from two or more iterators</span></code></pre></div>"},{"url":"/docs/quick-ref/topRepos/","relativePath":"docs/quick-ref/topRepos.md","relativeDir":"docs/quick-ref","base":"topRepos.md","name":"topRepos","frontmatter":{"title":"Top Repos","weight":0,"seo":{"title":"Top Repos","description":"This is the Top Repos page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Top Repos","keyName":"property"},{"name":"og:description","value":"This is the Top Repos page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Top Repos"},{"name":"twitter:description","value":"This is the Top Repos page"}]},"template":"docs"},"html":"<h1>My Top Repos / Websites:</h1>\n<ul>\n<li><a href=\"https://github.com/bgoonz/PYTHON_PRAC\">Python Practice</a></li>\n<li><a href=\"https://lambda-resources.netlify.app/\">Lambda Bootcamp Website</a></li>\n<li><a href=\"https://github.com/bgoonz/React_Notes_V3\">React Notes</a></li>\n<li><a href=\"https://github.com/bgoonz/Project-Showcase\">Project Showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">Data Structures &#x26; Algorithms</a></li>\n<li><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\">Lambda Site Static Content Server</a></li>\n<li><a href=\"https://github.com/bgoonz/mini-project-showcase\">Mini-Project Showcase</a></li>\n<li><a href=\"https://github.com/bgoonz/Useful-Snippets-js\">Useful Snippets</a></li>\n<li><a href=\"https://github.com/bgoonz/Markdown-Templates\">Markdown Templates</a></li>\n<li><a href=\"https://github.com/bgoonz/zumzi-chat-messenger\">Zumzi Video Conferencing App (mesibo api backend)</a></li>\n</ul>\n<p><a href=\"https://pages.databricks.com/rs/094-YMS-629/images/dynamic-time-warping-background.html\">https://pages.databricks.com/rs/094-YMS-629/images/dynamic-time-warping-background.html</a></p>"},{"url":"/docs/quick-ref/pull-request-rubric/","relativePath":"docs/quick-ref/pull-request-rubric.md","relativeDir":"docs/quick-ref","base":"pull-request-rubric.md","name":"pull-request-rubric","frontmatter":{"title":"Pull Request Template","weight":0,"excerpt":"Does the pull request consist of small commits with clear titles","seo":{"title":"Pull Request Template","description":"s it clear why the pull request exists","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Pull Requests</h2>\n<table>\n<thead>\n<tr>\n<th>Objective</th>\n<th>Description</th>\n<th>1-3 (Not Passing)</th>\n<th>4 (Passing)</th>\n<th>5-7 (Exceptional)</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://www.notion.so/Clearly-documents-the-motivation-and-what-changed-0c7f5d04d7f9401e8e861ce93312d503\">Clearly documents the motivation and what changed</a></td>\n<td>Is it clear why the pull request exists? Does it link to supporting documentation (user story, product roadmap, design) to give broader context? Is the code itself appropriately commented?</td>\n<td>The PR description is either blank or only contains the boilerplate PR template or unchecked checklist items. Code comments aren't used, even when they would be helpful.</td>\n<td>The PR description outlines the motivation for the feature and/or links to a user story or other document describing the purpose of the feature.</td>\n<td>The PR description includes a clear rationale for the feature, or a screenshot showing either the intended state or completed state of the feature, and gives additional context about changes made in the PR.</td>\n</tr>\n<tr>\n<td><a href=\"https://www.notion.so/Atomic-well-named-commits-67085273f3b945beb14af73e51c61522\">Atomic, well-named commits</a></td>\n<td>Does the pull request consist of small commits with clear titles? Do all commits have relevant and sensible messages of what was changed?</td>\n<td>Commits are not named appropriately. Commits have sensible messages. Example. \"Updated\", \"Fixed a bug\"</td>\n<td>Commits are well named. Commits have descriptive messages relevant to what changed. Some commits are not atomic.</td>\n<td>Commits are well named. Commits have descriptive messages. Each commit introduces atomic changes.</td>\n</tr>\n<tr>\n<td><a href=\"https://www.notion.so/Appropriately-Scoped-3b6f396ee76d4075b0b66c702624f05e\">Appropriately Scoped</a></td>\n<td>Is the pull request small enough to review easily? Is it focused on solving a single cohesive problem?</td>\n<td>Pull request introduces multiple features or solves multiple problems. PR is unreasonably big with many changed files. Some code changes that are not related to the purpose of the PR</td>\n<td>PR is relatively small. PR has some minor changes not related to the feature or primary change being introduced.</td>\n<td>PR is focused on a single problem. PR is small enough and easy to review.</td>\n</tr>\n<tr>\n<td><a href=\"https://www.notion.so/Adequately-reviewed-44cf640022d94c35a23589263a943d76\">Adequately reviewed</a></td>\n<td>Has the pull request been reviewed by at least two team members? Your release manager will be the final reviewer of the pull request. Did they leave any comments or suggestions? Were those suggestions acted on?</td>\n<td>PR was merged by the same developer who requested it. The reviewer rejected PR with no comments. PR was initiated again and suggested changes were not addressed.</td>\n<td>At least two team members reviewed PRs. Appropriate comments were left in the PR. Suggestions were acted upon.</td>\n<td>PRs were reviewed by more than one team member. PR requests were sent to multiple reviewers. Active high-quality discussions are evident in PRs.</td>\n</tr>\n<tr>\n<td><a href=\"https://www.notion.so/Code-is-clear-and-maintainable-de9ef74e969b47f5bab234f5a346c407\">Code is clear and maintainable</a></td>\n<td>Is the code formatted appropriately? Is there dead code? <strong><em>logs and print statements have no place in your main branches!</em></strong> Are there instances of duplicate code? Does code have TODOs committed to main?</td>\n<td>Code has inconsistent formatting. Significant amount of dead code across the codebase. Multiple instances on TODOs in main. Significant amount of duplicated code.</td>\n<td>Code is consistently formatted. Functions are relatively small. Few instances of duplicate code. Few instances of dead code.</td>\n<td>Code is consistently formatted. Has config files to enforce linting and formatting. No instance on duplicate code.</td>\n</tr>\n<tr>\n<td><a href=\"https://www.notion.so/Code-is-idiomatic-c8d7786458b9430d9b6bad50cd904c9c\">Code is idiomatic</a></td>\n<td>Does the code follow industry standards for the language, framework, and libraries used?</td>\n<td>Code consistently does not adhere to best practices for the language, framework or libraries used.</td>\n<td>Code has apparent minor deviations from industry standards.</td>\n<td>Code follows best practices of language, framework and libraries use. Effort has been made to improve on those practices.</td>\n</tr>\n</tbody>\n</table>"},{"url":"/docs/quick-ref/understanding-path/","relativePath":"docs/quick-ref/understanding-path.md","relativeDir":"docs/quick-ref","base":"understanding-path.md","name":"understanding-path","frontmatter":{"title":"Understanding PATH","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h3>Understanding PATH</h3>\n<p><img src=\"images/pypath.jpeg\" alt=\"image\"></p>\n<p><img src=\"images/pypath2.png\" alt=\"image\"></p>\n<p>When you run a command like python or pip, your operating system searches through a list of directories to find an executable file with that name. This list of directories lives in an environment variable called PATH, with each directory in the list separated by a colon:</p>\n<p>Directories in PATH are searched from left to right, so a matching executable in a directory at the beginning of the list takes precedence over another one at the end. In this example, the /usr/local/bin directory will be searched first, then /usr/bin, then /bin.</p>\n<h3>Understanding Shims</h3>\n<p>pyenv works by inserting a directory of shims at the front of your PATH:</p>\n<p>Through a process called rehashing, pyenv maintains shims in that directory to match every Python command across every installed version of Python---python, pip, and so on.</p>\n<p>Shims are lightweight executables that simply pass your command along to pyenv. So with pyenv installed, when you run, say, pip, your operating system will do the following:</p>\n<ul>\n<li>Search your PATH for an executable file named pip</li>\n<li>-</li>\n<li>Find the pyenv shim named pip at the beginning of your PATH</li>\n<li>Run the shim named pip, which in turn passes the command along to pyenv</li>\n</ul>\n<h3>Choosing the Python Version</h3>\n<p>When you execute a shim, pyenv determines which Python version to use by reading it from the following sources, in this order:</p>\n<ol>\n<li>The PYENV_VERSION environment variable (if specified). You can use the <a href=\"https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell\">pyenv shell</a> command to set this environment variable in your current shell session.</li>\n<li>The application-specific .python-version file in the current directory (if present). You can modify the current directory's .python-version file with the <a href=\"https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local\">pyenv local</a> command.</li>\n<li>The first .python-version file found (if any) by searching each parent directory, until reaching the root of your filesystem.</li>\n<li>The global $(pyenv root)/version file. You can modify this file using the <a href=\"https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global\">pyenv global</a> command. If the global version file is not present, pyenv assumes you want to use the \"system\" Python. (In other words, whatever version would run if pyenv weren't in your PATH.)</li>\n</ol>\n<p><strong>NOTE:</strong> You can activate multiple versions at the same time, including multiple versions of Python2 or Python3 simultaneously. This allows for parallel usage of Python2 and Python3, and is required with tools like tox. For example, to set your path to first use your system Python and Python3 (set to 2.7.9 and 3.4.2 in this example), but also have Python 3.3.6, 3.2, and 2.5 available on your PATH, one would first pyenv install the missing versions, then set pyenv global system 3.3.6 3.2 2.5. At this point, one should be able to find the full executable path to each of these using pyenv which, e.g. pyenv which python2.5 (should display $(pyenv root)/versions/2.5/bin/python2.5), or pyenv which python3.4 (should display path to system Python3). You can also specify multiple versions in a .python-version file, separated by newlines. Lines starting with a # are ignored.</p>\n<h3>Locating the Python Installation</h3>\n<p>Once pyenv has determined which version of Python your application has specified, it passes the command along to the corresponding Python installation.</p>\n<p>Each Python version is installed into its own directory under $(pyenv root)/versions.</p>\n<p>For example, you might have these versions installed:</p>\n<ul>\n<li>$(pyenv root)/versions/2.7.8/</li>\n<li>-</li>\n<li>$(pyenv root)/versions/3.4.2/</li>\n<li>$(pyenv root)/versions/pypy-2.4.0/</li>\n</ul>\n<p>As far as Pyenv is concerned, version names are simply directories under $(pyenv root)/versions.</p>\n<h3>Managing Virtual Environments</h3>\n<p>There is a pyenv plugin named <a href=\"https://github.com/pyenv/pyenv-virtualenv\">pyenv-virtualenv</a> which comes with various features to help pyenv users to manage virtual environments created by virtualenv or Anaconda. Because the activate script of those virtual environments are relying on mutating $PATH variable of user's interactive shell, it will intercept pyenv's shim style command execution hooks. We'd recommend to install pyenv-virtualenv as well if you have some plan to play with those virtual environments.\n<img src=\"https://i.imgur.com/0hQBL4d.png\" alt=\"image\">\n<img src=\"https://i.imgur.com/0hQBL4d.png\" alt=\"image\">\n<img src=\"images/festive-zebra.png\" alt=\"image\"></p>"},{"url":"/docs/quick-ref/vscode-themes/","relativePath":"docs/quick-ref/vscode-themes.md","relativeDir":"docs/quick-ref","base":"vscode-themes.md","name":"vscode-themes","frontmatter":{"title":"vscode-themes","excerpt":"To make it easy to write documentation in plain Markdown, most vscode-themes are styled using Markdown elements with few additional CSS classes.","seo":{"title":"vscode-themes","description":"This is the vscode-themes page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"vscode-themes","keyName":"property"},{"name":"og:description","value":"This is the vscode-themes page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"vscode-themes"},{"name":"twitter:description","value":"This is the vscode-themes page"}]},"template":"docs"},"html":"<h1>My Favorite VSCode Themes</h1>\n<p>Themes</p>\n<hr>\n<h3>My Favorite VSCode Themes</h3>\n<h3>Product Icon Themes:</h3>\n<h3>Fluent Icons</h3>\n<p>A product icon theme for Visual Studio Code</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*wE_xUE1f0GU8GBGo.png\" class=\"graf-image\" />\n</figure>\n<a href=\"https://code.visualstudio.com/api/extension-guides/product-icon-theme\" class=\"markup--anchor markup--p-anchor\">Product icons themes</a> allow theme authors to customize the icons used in VS Code's built-in views: all icons except file icons (covered by file icon themes) and icons contributed by extensions. This extension uses <a href=\"https://www.figma.com/community/file/836835755999342788/Microsoft-Fluent-System-Icons\" class=\"markup--anchor markup--p-anchor\">Fluent Icons</a>.\n<h3>Install</h3>\n<ol>\n<li><span id=\"5f77\">Install the icon theme from the <a href=\"https://marketplace.visualstudio.com/items?itemName=miguelsolorio.fluent-icons\" class=\"markup--anchor markup--li-anchor\">Marketplace</a>\n</span></li>\n<li><span id=\"6411\">Open the command palette (<code class=\"language-text\">Ctrl/Cmd + Shift + P</code>) and search for <code class=\"language-text\">Preferences: Product Icon Theme</code></span></li>\n<li><span id=\"0613\">Select <code class=\"language-text\">Fluent Icons</code></span></li>\n</ol>\n<h3>TBC…</h3>\n<hr>\n<h3><a href=\"https://vscodethemes.com/e/pushqrdx.theme-monokai-oblique-vscode\" class=\"markup--anchor markup--h3-anchor\">Monokai Oblique by pushqrdx</a></h3>\n<p>Monokai inspired theme for <a href=\"https://vscodethemes.com/e/pushqrdx.theme-monokai-oblique-vscode\" class=\"markup--anchor markup--p-anchor\">Visual Studio Code</a> and <a href=\"https://github.com/pushqrdx/monokai\" class=\"markup--anchor markup--p-anchor\">Visual Studio IDE</a>.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*43PXQoFMOr28C7_B.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/monokai.theme-monokai-pro-vscode\" class=\"markup--anchor markup--h3-anchor\">Monokai Pro by monokai (commercial)</a>\n<p>Beautiful functionality for professional developers, from the author of the original Monokai color scheme.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*qwLfKRWuJl0hLZ2m.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/sdras.night-owl\" class=\"markup--anchor markup--h3-anchor\">Night Owl by Sarah Drasner</a>\n<p>A VS Code theme for the night owls out there. Works well in the daytime, too, but this theme is fine-tuned for those of us who like to code late into the night. Color choices have taken into consideration what is accessible to people with color blindness and in low-light circumstances. Decisions were also based on meaningful contrast for reading comprehension and for optimal razzle dazzle. ✨</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*w4jwUZlACQz-ndRu.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/will-stone.plastic\" class=\"markup--anchor markup--h3-anchor\">Plastic by Will Stone</a>\n<p>A simple theme.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*xr3ul5T1_CAsnyWR.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/arcticicestudio.nord-visual-studio-code\" class=\"markup--anchor markup--h3-anchor\">Nord by arcticicestudio</a>\n<p>An arctic, north-bluish clean and elegant Visual Studio Code theme.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*yQMVpYfepk53HNxN.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/daylerees.rainglow\" class=\"markup--anchor markup--h3-anchor\">Rainglow by Dayle Rees</a>\n<p>Collection of 320+ beautiful syntax and UI themes.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*FpJBK3DBT1FUmuLF.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/mischah.relaxed-theme\" class=\"markup--anchor markup--h3-anchor\">Relaxed Theme by Michael Kühnel</a>\n<p>A relaxed theme to take a more relaxed view of things.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*bdPe8FIrL8F9qFqx.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/ahmadawais.shades-of-purple\" class=\"markup--anchor markup--h3-anchor\">Shades of Purple by Ahmad Awais</a>\n<p>⚡ A professional theme with hand-picked &#x26; bold shades of purple 💜 to go along with your VS Code. A custom VS Code theme with style.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*lyNNDrSPE5fpaMBZ.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/Endormi.2077-theme\" class=\"markup--anchor markup--h3-anchor\">2077 theme by Endormi</a>\n<p>Cyberpunk 2077 inspired theme</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*1VdJDagHs-YTIicE.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/dustinsanders.an-old-hope-theme-vscode\" class=\"markup--anchor markup--h3-anchor\">An Old Hope Theme by Dustin Sanders</a>\n<p>VSCode theme inspired by a galaxy far far away…</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*8JZCxiWSVdupy-HQ.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/wart.ariake-dark\" class=\"markup--anchor markup--h3-anchor\">Ariake Dark by wart</a>\n<p>Dark VSCode theme inspired by Japanese traditional colors and the poetry composed 1000 years ago.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Pm8gFuyXa_xNniuP.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/akamud.vscode-theme-onedark\" class=\"markup--anchor markup--h3-anchor\">Atom One Dark Theme by Mahmoud Ali</a>\n<p>One Dark Theme based on Atom.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*YBzFlHIhCnEXPKsb.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/emroussel.atomize-atom-one-dark-theme\" class=\"markup--anchor markup--h3-anchor\">Atomize by emroussel</a>\n<p>A detailed and accurate Atom One Dark Theme.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*trGkLz0fLzZMjNX_.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/teabyii.ayu\" class=\"markup--anchor markup--h3-anchor\">Ayu by teabyii</a>\n<p>A simple theme with bright colors and comes in three versions — dark, light and mirage for all day long comfortable work.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*YL26P4BF0Kz-0ck9.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/eckertalex.borealis\" class=\"markup--anchor markup--h3-anchor\">Borealis Theme by Alexander Eckert</a>\n<p>VS Code theme inspired by the calm colors of the aurora borealis in Alaska.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Df5XXUX50azLyP7K.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/ultradracula.captain-sweetheart\" class=\"markup--anchor markup--h3-anchor\">Captain Sweetheart by ultradracula</a>\n<p>Tuff but sweet theme.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*93oi3wFSt7uH62VR.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/Yummygum.city-lights-theme\" class=\"markup--anchor markup--h3-anchor\">City Lights by Yummygum</a>\n<p>🏙 Yummygum's Official City Lights suite</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*LwpZlufyoKuCVjqn.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/wesbos.theme-cobalt2\" class=\"markup--anchor markup--h3-anchor\">Cobalt2 Theme Official by Wes Bos</a>\n<p>🔥 Official theme by Wes Bos.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*8KsnUfTVU-A9Aqcl.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/dracula-theme.theme-dracula\" class=\"markup--anchor markup--h3-anchor\">Dracula Official by Dracula Theme</a>\n<p>Official Dracula Theme. A dark theme for many editors, shells, and more.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*xGaF3Cs8iHoC5gUr.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/bogdanlazar.edge\" class=\"markup--anchor markup--h3-anchor\">Edge by Bogdan Lazar</a>\n<p>A simple theme with bright colors in three variants — Night Sky, Serene and Ocean for all day long comfortable work.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*qELxjfUYJNuRISgB.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/fisheva.eva-theme\" class=\"markup--anchor markup--h3-anchor\">Eva Theme by fisheva</a>\n<p>A colorful and semantic coloring code theme.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Dzw_28GVEGa10m-9.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/nopjmp.fairyfloss\" class=\"markup--anchor markup--h3-anchor\">Fairy Floss by nopjmp and sailorhg</a>\n<p>A fun, purple-based pastel/candy/daydream fairyfloss theme made by sailorhg.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*wJkmVL0w1tz4n4_H.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/thomaspink.theme-github\" class=\"markup--anchor markup--h3-anchor\">GitHub Theme by Thomas Pink</a>\n<p>GitHub Theme for Visual Studio Code.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*H4ZAOtLrAniVho93.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/DimitarNonov.jellybeans-theme\" class=\"markup--anchor markup--h3-anchor\">Jellybeans Theme by Dimitar Nonov</a>\n<p>Jellybeans Theme for Visual Studio Code.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*oMhZGGsUfm8rqLtJ.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/whizkydee.material-palenight-theme\" class=\"markup--anchor markup--h3-anchor\">Material Palenight Theme by whizkydee</a>\n<p>An elegant and juicy material-like theme for Visual Studio Code.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*cw3IGUQSFahiPgiH.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/Equinusocio.vsc-material-theme\" class=\"markup--anchor markup--h3-anchor\">Material Theme by Mattia Astorino</a>\n<p>The most epic theme now for Visual Studio Code.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*2YvsABxfZ4Cv1Y_j.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/u29dc.mno\" class=\"markup--anchor markup--h3-anchor\">Mno by u29dc</a>\n<p>Minimal monochrome theme.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*_NT4CQBGRRlFQl9q.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/smlombardi.slime\" class=\"markup--anchor markup--h3-anchor\">Slime Theme by smlombardi</a>\n<p>A dark syntax/workbench theme for Visual Studio Code — optimized for SCSS, HTML, JS, TS, Markdown, and PHP files.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*-ldv4DoOVntnZbBt.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://vscodethemes.com/e/selfrefactor.niketa-theme\" class=\"markup--anchor markup--h3-anchor\">Niketa Theme by Dejan Toteff</a>\n<p>Collection of 18 light themes separated in 4 groups by background's brightness.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*n_iRSy_1IDOgajFu.png\" class=\"graf-image\" />\n</figure>### If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content:\n<a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://gist.github.com/bgoonz\">\n<strong>bgoonz's gists</strong>\n<br />\n<em>Instantly share code, notes, and snippets. Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python |…</em>gist.github.com</a>\n<a href=\"https://gist.github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/9bab65af3f0f\">March 18, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/my-favorite-vscode-themes-9bab65af3f0f\" class=\"p-canonical\">Canonical link</a></p>\n<p> August 6, 2021.</p>"},{"url":"/docs/react/accessibility/","relativePath":"docs/react/accessibility.md","relativeDir":"docs/react","base":"accessibility.md","name":"accessibility","frontmatter":{"title":"Accessibility in React","weight":0,"excerpt":"At this point, we have accomplished all of the features we set out to implement. A user can add a new task, check and uncheck tasks, delete tasks, or edit task names. And they can filter their task list by all, active, or completed tasks.","seo":{"title":"Accessibility in React","description":"At this point, we have accomplished all of the features we set out to implement. A user can add a new task, check and uncheck tasks, delete tasks, or edit task names. And they can filter their task list by all, active, or completed tasks.","robots":[],"extra":[]},"template":"docs"},"html":"<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#including_keyboard_users\" title=\"Permalink to Including keyboard users\">Including keyboard users</a></h2>\n<p>At this point, we've accomplished all of the features we set out to implement. A user can add a new task, check and uncheck tasks, delete tasks, or edit task names. And they can filter their task list by all, active, or completed tasks.</p>\n<p>Or, at least: they can do all of these things with a mouse. Unfortunately, these features are not very accessible to keyboard-only users. Let's explore this now.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#exploring_the_keyboard_usability_problem\" title=\"Permalink to Exploring the keyboard usability problem\">Exploring the keyboard usability problem</a></h2>\n<p>Start by clicking on the input at the top of our app, as if you're going to add a new task. You'll see a thick, dashed outline around that input. This outline is your visual indicator that the browser is currently focused on this element. Press the Tab key, and you will see the outline appear around the \"Add\" button beneath the input. This shows you that the browser's focus has moved.</p>\n<p>Press Tab a few more times, and you will see this dashed focus indicator move between each of the filter buttons. Keep going until the focus indicator is around the first \"Edit\" button. Press Enter.</p>\n<p>The <code class=\"language-text\">&lt;Todo /></code> component will switch templates, as we designed, and you'll see a form that lets us edit the name of the task.</p>\n<p>But where did our focus indicator go?</p>\n<p>When we switch between templates in our <code class=\"language-text\">&lt;Todo /></code> component, we completely remove the elements that were there before to replace them with something else. That means the element that we were focused on vanishes, and nothing is in focus at all. This could confuse a wide variety of users — particularly users who rely on the keyboard, or users who use a screen reader.</p>\n<p>To improve the experience for keyboard and screen-reader users, we should manage the browser's focus ourselves.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#focusing_between_templates\" title=\"Permalink to Focusing between templates\">Focusing between templates</a></h2>\n<p>When a user toggles a <code class=\"language-text\">&lt;Todo/></code> template from viewing to editing, we should focus on the <code class=\"language-text\">&lt;input></code> used to rename it; when they toggle back from editing to viewing, we should move focus back to the \"Edit\" button.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#targeting_our_elements\" title=\"Permalink to Targeting our elements\">Targeting our elements</a></h3>\n<p>In order to focus on an element in our DOM, we need to tell React which element we want to focus on and how to find it. React's <a href=\"https://reactjs.org/docs/hooks-reference.html#useref\"><code class=\"language-text\">useRef</code></a> hook creates an object with a single property: <code class=\"language-text\">current</code>. This property can be a reference to anything we want and look that reference up later. It's particularly useful for referring to DOM elements.</p>\n<p>Change the <code class=\"language-text\">import</code> statement at the top of <code class=\"language-text\">Todo.js</code> so that it includes <code class=\"language-text\">useRef</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useRef, useState } from \"react\";</code></pre></div>\n<p>Then, create two new constants beneath the hooks in your <code class=\"language-text\">Todo()</code> function. Each should be a ref - one for the \"Edit\" button in the view template and one for the edit field in the editing template.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const editFieldRef = useRef(null);\nconst editButtonRef = useRef(null);</code></pre></div>\n<p>These refs have a default value of <code class=\"language-text\">null</code> because they will not have value until we attach them to their respective elements. To do that, we'll add an attribute of <code class=\"language-text\">ref</code> to each element, and set their values to the appropriately named <code class=\"language-text\">ref</code> objects.</p>\n<p>The textbox <code class=\"language-text\">&lt;input></code> in your editing template should be updated like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;input\n  id={props.id}\n  className=\"todo-text\"\n  type=\"text\"\n  value={newName}\n  onChange={handleChange}\n  ref={editFieldRef}\n/></code></pre></div>\n<p>The \"Edit\" button in your view template should read like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;button\n  type=\"button\"\n  className=\"btn\"\n  onClick={() => setEditing(true)}\n  ref={editButtonRef}\n>\n  Edit &lt;span className=\"visually-hidden\">{props.name}&lt;/span>\n&lt;/button></code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#focusing_on_our_refs_with_useeffect\" title=\"Permalink to Focusing on our refs with useEffect\">Focusing on our refs with useEffect</a></h3>\n<p>To use our refs for their intended purpose, we need to import another React hook: <a href=\"https://reactjs.org/docs/hooks-reference.html#useeffect\"><code class=\"language-text\">useEffect()</code></a>. <code class=\"language-text\">useEffect()</code> is so named because it runs after React renders a given component, and will run any side-effects that we'd like to add to the render process, which we can't run inside the main function body. <code class=\"language-text\">useEffect()</code> is useful in the current situation because we cannot focus on an element until after the <code class=\"language-text\">&lt;Todo /></code> component renders and React knows where our refs are.</p>\n<p>Change the import statement of <code class=\"language-text\">Todo.js</code> again to add <code class=\"language-text\">useEffect</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useEffect, useRef, useState } from \"react\";</code></pre></div>\n<p><code class=\"language-text\">useEffect()</code> takes a function as an argument; this function is executed after the component renders. Let's see this in action; put the following <code class=\"language-text\">useEffect()</code> call just above the <code class=\"language-text\">return</code> statement in the body of <code class=\"language-text\">Todo()</code>, and pass into it a function that logs the words \"side effect\" to your console:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">useEffect(() => {\n  console.log(\"side effect\");\n});</code></pre></div>\n<p>To illustrate the difference between the main render process and code run inside <code class=\"language-text\">useEffect()</code>, add another log - put this one below the previous addition:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(\"main render\");</code></pre></div>\n<p>Now, open the app in your browser. You should see both messages in your console, with each one repeating three times. Note how \"main render\" logged first, and \"side effect\" logged second, even though the \"side effect\" log appears first in the code.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">main render (3)                                     Todo.js:100\nside effect (3)                                     Todo.js:98</code></pre></div>\n<p>That's it for our experimentation for now. Delete <code class=\"language-text\">console.log(\"main render\")</code> now, and lets move on to implementing our focus management.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#focusing_on_our_editing_field\" title=\"Permalink to Focusing on our editing field\">Focusing on our editing field</a></h3>\n<p>Now that we know our <code class=\"language-text\">useEffect()</code> hook works, we can manage focus with it. As a reminder, we want to focus on the editing field when we switch to the editing template.</p>\n<p>Update your existing <code class=\"language-text\">useEffect()</code> hook so that it reads like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">useEffect(() => {\n  if (isEditing) {\n    editFieldRef.current.focus();\n  }\n}, [isEditing]);</code></pre></div>\n<p>These changes make it so that, if <code class=\"language-text\">isEditing</code> is true, React reads the current value of the <code class=\"language-text\">editFieldRef</code> and moves browser focus to it. We also pass an array into <code class=\"language-text\">useEffect()</code> as a second argument. This array is a list of values <code class=\"language-text\">useEffect()</code> should depend on. With these values included, <code class=\"language-text\">useEffect()</code> will only run when one of those values changes. We only want to change focus when the value of <code class=\"language-text\">isEditing</code> changes.</p>\n<p>Try it now, and you'll see that when you click an \"Edit\" button, focus moves to the corresponding edit <code class=\"language-text\">&lt;input></code>!</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#moving_focus_back_to_the_edit_button\" title=\"Permalink to Moving focus back to the edit button\">Moving focus back to the edit button</a></h3>\n<p>At first glance, getting React to move focus back to our \"Edit\" button when the edit is saved or cancelled appears deceptively easy. Surely we could add a condition to our <code class=\"language-text\">useEffect</code> to focus on the edit button if <code class=\"language-text\">isEditing</code> is <code class=\"language-text\">false</code>? Let's try it now — update your <code class=\"language-text\">useEffect()</code> call like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">useEffect(() => {\n  if (isEditing) {\n    editFieldRef.current.focus();\n  } else {\n    editButtonRef.current.focus();\n  }\n}, [isEditing]);</code></pre></div>\n<p>This kind of mostly works. Head back to your browser and you'll see that your focus moves between Edit <code class=\"language-text\">&lt;input></code> and \"Edit\" button as you start and end an edit. However, you may have noticed a new problem — the \"Edit\" button in the final <code class=\"language-text\">&lt;Todo /></code> component is focussed immediately on page load, before we even interact with the app!</p>\n<p>Our <code class=\"language-text\">useEffect()</code> hook is behaving exactly as we designed it: it runs as soon as the component renders, sees that <code class=\"language-text\">isEditing</code> is <code class=\"language-text\">false</code>, and focuses the \"Edit\" button. Because there are three instances of <code class=\"language-text\">&lt;Todo /></code>, we see focus on the last \"Edit\" button.</p>\n<p>We need to refactor our approach so that focus changes only when <code class=\"language-text\">isEditing</code> changes from one value to another.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#more_robust_focus_management\" title=\"Permalink to More robust focus management\">More robust focus management</a></h2>\n<p>In order to meet our refined criteria, we need to know not just the value of <code class=\"language-text\">isEditing</code>, but also <em>when that value has changed</em>. In order to do that, we need to be able to read the previous value of the <code class=\"language-text\">isEditing</code> constant. Using pseudocode, our logic should be something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if (wasNotEditingBefore &amp;&amp; isEditingNow) {\n  focusOnEditField()\n}\nif (wasEditingBefore &amp;&amp; isNotEditingNow) {\n  focusOnEditButton()\n}</code></pre></div>\n<p>The React team had discussed <a href=\"https://reactjs.org/docs/hooks-faq.html#how-to-get-the-previous-props-or-state\">ways to get a component's previous state</a>, and has provided an example custom hook we can use for the job.</p>\n<p>Paste the following code near the top of <code class=\"language-text\">Todo.js</code>, above your <code class=\"language-text\">Todo()</code> function.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function usePrevious(value) {\n  const ref = useRef();\n  useEffect(() => {\n    ref.current = value;\n  });\n  return ref.current;\n}</code></pre></div>\n<p>Now we'll define a <code class=\"language-text\">wasEditing</code> constant beneath the hooks at the top of <code class=\"language-text\">Todo()</code>. We want this constant to track the previous value of <code class=\"language-text\">isEditing</code>, so we call <code class=\"language-text\">usePrevious</code> with <code class=\"language-text\">isEditing</code> as an argument:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const wasEditing = usePrevious(isEditing);</code></pre></div>\n<p>With this constant, we can update our <code class=\"language-text\">useEffect()</code> hook to implement the pseudocode we discussed before — update it as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">useEffect(() => {\n  if (!wasEditing &amp;&amp; isEditing) {\n    editFieldRef.current.focus();\n  }\n  if (wasEditing &amp;&amp; !isEditing) {\n    editButtonRef.current.focus();\n  }\n}, [wasEditing, isEditing]);</code></pre></div>\n<p>Note that the logic of <code class=\"language-text\">useEffect()</code> now depends on <code class=\"language-text\">wasEditing</code>, so we provide it in the array of dependencies.</p>\n<p>Again try using the \"Edit\" and \"Cancel\" buttons to toggle between the templates of your <code class=\"language-text\">&lt;Todo /></code> component; you'll see the browser focus indicator move appropriately, without the problem we discussed at the start of this section.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#focusing_when_the_user_deletes_a_task\" title=\"Permalink to Focusing when the user deletes a task\">Focusing when the user deletes a task</a></h2>\n<p>There's one last keyboard experience gap: when a user deletes a task from the list, the focus vanishes. We're going to follow a pattern similar to our previous changes: we'll make a new ref, and utilize our <code class=\"language-text\">usePrevious()</code> hook, so that we can focus on the list heading whenever a user deletes a task.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#why_the_list_heading\" title=\"Permalink to Why the list heading?\">Why the list heading?</a></h3>\n<p>Sometimes, the place we want to send our focus to is obvious: when we toggled our <code class=\"language-text\">&lt;Todo /></code> templates, we had an origin point to \"go back\" to — the \"Edit\" button. In this case however, since we're completely removing elements from the DOM, we have no place to go back to. The next best thing is an intuitive location somewhere nearby. The list heading is our best choice because it's close to the list item the user will delete, and focusing on it will tell the user how many tasks are left.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#creating_our_ref\" title=\"Permalink to Creating our ref\">Creating our ref</a></h3>\n<p>Import the <code class=\"language-text\">useRef()</code> and <code class=\"language-text\">useEffect()</code> hooks into <code class=\"language-text\">App.js</code> — you'll need them both below:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useState, useRef, useEffect } from \"react\";</code></pre></div>\n<p>Then declare a new ref inside the <code class=\"language-text\">App()</code> function. Just above the <code class=\"language-text\">return</code> statement is a good place:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const listHeadingRef = useRef(null);</code></pre></div>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#prepare_the_heading\" title=\"Permalink to Prepare the heading\">Prepare the heading</a></h3>\n<p>Heading elements like our <code class=\"language-text\">&lt;h2></code> are not usually focusable. This isn't a problem — we can make any element programmatically focusable by adding the attribute <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex\"><code class=\"language-text\">tabindex=\"-1\"</code></a> to it. This means <em>only focusable with JavaScript</em>. You can't press Tab to focus on an element with a tabindex of <code class=\"language-text\">-1</code> the same way you could do with a <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button\"><code class=\"language-text\">&lt;button></code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a\"><code class=\"language-text\">&lt;a></code></a> element (this can be done using <code class=\"language-text\">tabindex=\"0\"</code>, but that's not really appropriate in this case).</p>\n<p>Let's add the <code class=\"language-text\">tabindex</code> attribute — written as <code class=\"language-text\">tabIndex</code> in JSX — to the heading above our list of tasks, along with our <code class=\"language-text\">headingRef</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;h2 id=\"list-heading\" tabIndex=\"-1\" ref={listHeadingRef}>\n  {headingText}\n&lt;/h2></code></pre></div>\n<p><strong>Note:</strong> The <code class=\"language-text\">tabindex</code> attribute is great for accessibility edge-cases, but you should take <strong>great care</strong> to not overuse it. Only apply a <code class=\"language-text\">tabindex</code> to an element when you're absolutely sure that making it focusable will benefit your user in some way. In most cases, you should be utilizing elements that can naturally take focus, such as buttons, anchors, and inputs. Irresponsible usage of <code class=\"language-text\">tabindex</code> could have a profoundly negative impact on keyboard and screen-reader users!</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#getting_previous_state\" title=\"Permalink to Getting previous state\">Getting previous state</a></h3>\n<p>We want to focus on the element associated with our ref (via the <code class=\"language-text\">ref</code> attribute) only when our user deletes a task from their list. That's going to require the <code class=\"language-text\">usePrevious()</code> hook we already used earlier on. Add it to the top of your <code class=\"language-text\">App.js</code> file, just below the imports:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function usePrevious(value) {\n  const ref = useRef();\n  useEffect(() => {\n    ref.current = value;\n  });\n  return ref.current;\n}</code></pre></div>\n<p>Now add the following, above the <code class=\"language-text\">return</code> statement inside the <code class=\"language-text\">App()</code> function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const prevTaskLength = usePrevious(tasks.length);</code></pre></div>\n<p>Here we are invoking <code class=\"language-text\">usePrevious()</code> to track the length of the tasks state, like so:</p>\n<p><strong>Note:</strong> Since we're now utilizing <code class=\"language-text\">usePrevious()</code> in two files, a good efficiency refactor would be to move the <code class=\"language-text\">usePrevious()</code> function into its own file, export it from that file, and import it where you need it. Try doing this as an exercise once you've got to the end.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#using_useeffect_to_control_our_heading_focus\" title=\"Permalink to Using useEffect() to control our heading focus\">Using <code class=\"language-text\">useEffect()</code> to control our heading focus</a></h3>\n<p>Now that we've stored how many tasks we previously had, we can set up a <code class=\"language-text\">useEffect()</code> hook to run when our number of tasks changes, which will focus the heading if the number of tasks we have now is less than with it previously was — i.e. we deleted a task!</p>\n<p>Add the following into the body of your <code class=\"language-text\">App()</code> function, just below your previous additions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">useEffect(() => {\n  if (tasks.length - prevTaskLength === -1) {\n    listHeadingRef.current.focus();\n  }\n}, [tasks.length, prevTaskLength]);</code></pre></div>\n<p>We only try to focus on our list heading if we have fewer tasks now than we did before. The dependencies passed into this hook ensure it will only try to re-run when either of those values (the number of current tasks, or the number of previous tasks) changes.</p>\n<p>Now, when you delete a task in your browser, you will see our dashed focus outline appear around the heading above the list.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Client-side_JavaScript_frameworks/React_accessibility#finished!\" title=\"Permalink to Finished!\">Finished!</a></h2>\n<p>You've just finished building a React app from the ground up! Congratulations! The skills you've learned here will be a great foundation to build on as you continue working with React.</p>\n<p>Most of the time, you can be an effective contributor to a React project even if all you do is think carefully about components and their state and props. Remember to always write the best HTML you can.</p>\n<p><code class=\"language-text\">useRef()</code> and <code class=\"language-text\">useEffect()</code> are somewhat advanced features, and you should be proud of yourself for using them! Look out for opportunities to practice them more, because doing so will allow you to create inclusive experiences for users. Remember: our app would have been inaccessible to keyboard users without them!</p>"},{"url":"/docs/react/cheatsheet/","relativePath":"docs/react/cheatsheet.md","relativeDir":"docs/react","base":"cheatsheet.md","name":"cheatsheet","frontmatter":{"title":"React Cheat Sheets:","weight":0,"excerpt":"cheat sheet","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>React Patterns:</h1>\n<iframe height=\"600px\" width=\"1000px\" sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/lucid-pateu-ln8ex?fontsize=14&hidenavigation=1&theme=dark&view=preview\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"react patterns\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>\n<h2>React Cheat Sheet</h2>\n<hr>\n<hr>\n<details>\n<summary>  See More </summary>\n<h3>Components</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Hello</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"message-box\"</span><span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const el = document.body\nReactDOM.render(&lt;Hello name='John' />, el)</code></pre></div>\n<p>Use the <a href=\"https://jsfiddle.net/reactjs/69z2wepo/\">React.js jsfiddle</a> to start hacking. (or the unofficial <a href=\"http://jsbin.com/yafixat/edit?js,output\">jsbin</a>)</p>\n<h3>Import multiple exports</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, {Component} from 'react'\nimport ReactDOM from 'react-dom'</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Hello extends Component {\n  ...\n}</code></pre></div>\n<h3>Properties</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Video fullscreen={true} autoplay={false} /></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render () {\n  this.props.fullscreen\n  const { fullscreen, autoplay } = this.props\n  ···\n}</code></pre></div>\n<p>Use <code class=\"language-text\">this.props</code> to access properties passed to the component.</p>\n<p>See: <a href=\"https://reactjs.org/docs/tutorial.html#using-props\">Properties</a></p>\n<h3>States</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">constructor(props) {\n  super(props)\n  this.state = { username: undefined }\n}</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.setState({ username: 'rstacruz' })</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render () {\n  this.state.username\n  const { username } = this.state\n  ···\n}</code></pre></div>\n<p>Use states (<code class=\"language-text\">this.state</code>) to manage dynamic data.</p>\n<p>With <a href=\"https://babeljs.io/\">Babel</a> you can use <a href=\"https://github.com/tc39/proposal-class-fields\">proposal-class-fields</a> and get rid of constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Hello extends Component {\n  state = { username: undefined };\n  ...\n}</code></pre></div>\n<p>See: <a href=\"https://reactjs.org/docs/tutorial.html#reactive-state\">States</a></p>\n<h3>Nesting</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Info extends Component {\n  render () {\n    const { avatar, username } = this.props\n\n    return &lt;div>\n      &lt;UserAvatar src={avatar} />\n      &lt;UserProfile username={username} />\n    &lt;/div>\n  }\n}</code></pre></div>\n<p>As of React v16.2.0, fragments can be used to return multiple children without adding extra wrapping nodes to the DOM.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, {\n  Component,\n  Fragment\n} from 'react'\n\nclass Info extends Component {\n  render () {\n    const { avatar, username } = this.props\n\n    return (\n      &lt;Fragment>\n        &lt;UserAvatar src={avatar} />\n        &lt;UserProfile username={username} />\n      &lt;/Fragment>\n    )\n  }\n}</code></pre></div>\n<p>Nest components to separate concerns.</p>\n<p>See: <a href=\"https://reactjs.org/docs/components-and-props.html#composing-components\">Composing Components</a></p>\n<h3>Children</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;AlertBox>\n  &lt;h1>You have pending notifications&lt;/h1>\n&lt;/AlertBox></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class AlertBox extends Component {\n  render () {\n    return &lt;div className='alert-box'>\n      {this.props.children}\n    &lt;/div>\n  }\n}</code></pre></div>\n<p>Children are passed as the <code class=\"language-text\">children</code> property.</p>\n<h2><a href=\"https://devhints.io/react#defaults\">#</a>Defaults</h2>\n<h3>Setting default props</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Hello.defaultProps = {\n  color: 'blue'\n}</code></pre></div>\n<p>See: <a href=\"https://reactjs.org/docs/react-component.html#defaultprops\">defaultProps</a></p>\n<h3>Setting default state</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Hello extends Component {\n  constructor (props) {\n    super(props)\n    this.state = { visible: true }\n  }\n}</code></pre></div>\n<p>Set the default state in the <code class=\"language-text\">constructor()</code>.</p>\n<p>And without constructor using <a href=\"https://babeljs.io/\">Babel</a> with <a href=\"https://github.com/tc39/proposal-class-fields\">proposal-class-fields</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Hello extends Component {\n  state = { visible: true }\n}</code></pre></div>\n<p>See: <a href=\"https://reactjs.org/docs/react-without-es6.html#setting-the-initial-state\">Setting the default state</a></p>\n<h2><a href=\"https://devhints.io/react#other-components\">#</a>Other components</h2>\n<h3>Functional components</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function MyComponent ({ name }) {\n  return &lt;div className='message-box'>\n    Hello {name}\n  &lt;/div>\n}</code></pre></div>\n<p>Functional components have no state. Also, their <code class=\"language-text\">props</code> are passed as the first parameter to a function.</p>\n<p>See: <a href=\"https://reactjs.org/docs/components-and-props.html#functional-and-class-components\">Function and Class Components</a></p>\n<h3>Pure components</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, {PureComponent} from 'react'\n\nclass MessageBox extends PureComponent {\n  ···\n}</code></pre></div>\n<p>Performance-optimized version of <code class=\"language-text\">React.Component</code>. Doesn't rerender if props/state hasn't changed.</p>\n<p>See: <a href=\"https://reactjs.org/docs/react-api.html#react.purecomponent\">Pure components</a></p>\n<h3>Component API</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.forceUpdate()</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.setState({ ... })\nthis.setState(state => { ... })</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.state\nthis.props</code></pre></div>\n<p>These methods and properties are available for <code class=\"language-text\">Component</code> instances.</p>\n<p>See: <a href=\"https://facebook.github.io/react/docs/component-api.html\">Component API</a></p>\n<h2><a href=\"https://devhints.io/react#lifecycle\">#</a>Lifecycle</h2>\n<h3>Mounting</h3>\n<table>\n<thead>\n<tr>\n<th>Method</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">constructor</code> <em>(props)</em></td>\n<td>Before rendering <a href=\"https://reactjs.org/docs/react-component.html#constructor\">#</a></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">componentWillMount()</code></td>\n<td><em>Don't use this</em> <a href=\"https://reactjs.org/docs/react-component.html#componentwillmount\">#</a></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">render()</code></td>\n<td>Render <a href=\"https://reactjs.org/docs/react-component.html#render\">#</a></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">componentDidMount()</code></td>\n<td>After rendering (DOM available) <a href=\"https://reactjs.org/docs/react-component.html#componentdidmount\">#</a></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">componentWillUnmount()</code></td>\n<td>Before DOM removal <a href=\"https://reactjs.org/docs/react-component.html#componentwillunmount\">#</a></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">componentDidCatch()</code></td>\n<td>Catch errors (16+) <a href=\"https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html\">#</a></td>\n</tr>\n</tbody>\n</table>\n<p>Set initial the state on <code class=\"language-text\">constructor()</code>. Add DOM event handlers, timers (etc) on <code class=\"language-text\">componentDidMount()</code>, then remove them on <code class=\"language-text\">componentWillUnmount()</code>.</p>\n<h3>Updating</h3>\n<table>\n<thead>\n<tr>\n<th>Method</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">componentDidUpdate</code> <em>(prevProps, prevState, snapshot)</em></td>\n<td>Use <code class=\"language-text\">setState()</code> here, but remember to compare props</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">shouldComponentUpdate</code> <em>(newProps, newState)</em></td>\n<td>Skips <code class=\"language-text\">render()</code> if returns false</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">render()</code></td>\n<td>Render</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">componentDidUpdate</code> <em>(prevProps, prevState)</em></td>\n<td>Operate on the DOM here</td>\n</tr>\n</tbody>\n</table>\n<p>Called when parents change properties and <code class=\"language-text\">.setState()</code>. These are not called for initial renders.</p>\n<p>See: <a href=\"https://facebook.github.io/react/docs/component-specs.html#updating-componentwillreceiveprops\">Component specs</a></p>\n<h2><a href=\"https://devhints.io/react#hooks-new\">#</a>Hooks (New)</h2>\n<h3>State Hook</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useState } from 'react';\n\nfunction Example() {\n  // Declare a new state variable, which we'll call \"count\"\n  const [count, setCount] = useState(0);\n\n  return (\n    &lt;div>\n      &lt;p>You clicked {count} times&lt;/p>\n      &lt;button onClick={() => setCount(count + 1)}>\n        Click me\n      &lt;/button>\n    &lt;/div>\n  );\n}</code></pre></div>\n<p>Hooks are a new addition in React 16.8.</p>\n<p>See: <a href=\"https://reactjs.org/docs/hooks-overview.html\">Hooks at a Glance</a></p>\n<h3>Declaring multiple state variables</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function ExampleWithManyStates() {\n  // Declare multiple state variables!\n  const [age, setAge] = useState(42);\n  const [fruit, setFruit] = useState('banana');\n  const [todos, setTodos] = useState([{ text: 'Learn Hooks' }]);\n  // ...\n}</code></pre></div>\n<h3>Effect hook</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useState, useEffect } from 'react';\n\nfunction Example() {\n  const [count, setCount] = useState(0);\n\n  // Similar to componentDidMount and componentDidUpdate:\n  useEffect(() => {\n    // Update the document title using the browser API\n    document.title = `You clicked ${count} times`;\n  }, [count]);\n\n  return (\n    &lt;div>\n      &lt;p>You clicked {count} times&lt;/p>\n      &lt;button onClick={() => setCount(count + 1)}>\n        Click me\n      &lt;/button>\n    &lt;/div>\n  );\n}</code></pre></div>\n<p>If you're familiar with React class lifecycle methods, you can think of <code class=\"language-text\">useEffect</code> Hook as <code class=\"language-text\">componentDidMount</code>, <code class=\"language-text\">componentDidUpdate</code>, and <code class=\"language-text\">componentWillUnmount</code> combined.</p>\n<p>By default, React runs the effects after every render — including the first render.</p>\n<h3>Building your own hooks</h3>\n<h4>Define FriendStatus</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useState, useEffect } from 'react';\n\nfunction FriendStatus(props) {\n  const [isOnline, setIsOnline] = useState(null);\n\n  useEffect(() => {\n    function handleStatusChange(status) {\n      setIsOnline(status.isOnline);\n    }\n\n    ChatAPI.subscribeToFriendStatus(props.friend.id, handleStatusChange);\n    return () => {\n      ChatAPI.unsubscribeFromFriendStatus(props.friend.id, handleStatusChange);\n    };\n  }, [props.friend.id]);\n\n  if (isOnline === null) {\n    return 'Loading...';\n  }\n  return isOnline ? 'Online' : 'Offline';\n}</code></pre></div>\n<p>Effects may also optionally specify how to “clean up” after them by returning a function.</p>\n<h4>Use FriendStatus</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function FriendStatus(props) {\n  const isOnline = useFriendStatus(props.friend.id);\n\n  if (isOnline === null) {\n    return 'Loading...';\n  }\n  return isOnline ? 'Online' : 'Offline';\n}</code></pre></div>\n<p>See: <a href=\"https://reactjs.org/docs/hooks-custom.html\">Building Your Own Hooks</a></p>\n<h3>Hooks API Reference</h3>\n<p>Also see: <a href=\"https://reactjs.org/docs/hooks-faq.html\">Hooks FAQ</a></p>\n<h4>Basic Hooks</h4>\n<table>\n<thead>\n<tr>\n<th>Hook</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">useState</code><em>(initialState)</em></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">useEffect</code><em>(() => { … })</em></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">useContext</code><em>(MyContext)</em></td>\n<td>value returned from <code class=\"language-text\">React.createContext</code></td>\n</tr>\n</tbody>\n</table>\n<p>Full details: <a href=\"https://reactjs.org/docs/hooks-reference.html#basic-hooks\">Basic Hooks</a></p>\n<h4>Additional Hooks</h4>\n<table>\n<thead>\n<tr>\n<th>Hook</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">useReducer</code><em>(reducer, initialArg, init)</em></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">useCallback</code><em>(() => { … })</em></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">useMemo</code><em>(() => { … })</em></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">useRef</code><em>(initialValue)</em></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">useImperativeHandle</code><em>(ref, () => { … })</em></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">useLayoutEffect</code></td>\n<td>identical to <code class=\"language-text\">useEffect</code>, but it fires synchronously after all DOM mutations</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">useDebugValue</code><em>(value)</em></td>\n<td>display a label for custom hooks in React DevTools</td>\n</tr>\n</tbody>\n</table>\n<p>Full details: <a href=\"https://reactjs.org/docs/hooks-reference.html#additional-hooks\">Additional Hooks</a></p>\n<h2><a href=\"https://devhints.io/react#dom-nodes\">#</a>DOM nodes</h2>\n<h3>References</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class MyComponent extends Component {\n  render () {\n    return &lt;div>\n      &lt;input ref={el => this.input = el} />\n    &lt;/div>\n  }\n\n  componentDidMount () {\n    this.input.focus()\n  }\n}</code></pre></div>\n<p>Allows access to DOM nodes.</p>\n<p>See: <a href=\"https://reactjs.org/docs/refs-and-the-dom.html\">Refs and the DOM</a></p>\n<h3>DOM Events</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class MyComponent extends Component {\n  render () {\n    &lt;input type=\"text\"\n        value={this.state.value}\n        onChange={event => this.onChange(event)} />\n  }\n\n  onChange (event) {\n    this.setState({ value: event.target.value })\n  }\n}</code></pre></div>\n<p>Pass functions to attributes like <code class=\"language-text\">onChange</code>.</p>\n<p>See: <a href=\"https://reactjs.org/docs/events.html\">Events</a></p>\n<h2><a href=\"https://devhints.io/react#other-features\">#</a>Other features</h2>\n<h3>Transferring props</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;VideoPlayer src=\"video.mp4\" /></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class VideoPlayer extends Component {\n  render () {\n    return &lt;VideoEmbed {...this.props} />\n  }\n}</code></pre></div>\n<p>Propagates <code class=\"language-text\">src=\"...\"</code> down to the sub-component.</p>\n<p>See <a href=\"https://facebook.github.io/react/docs/transferring-props.html\">Transferring props</a></p>\n<h3>Top-level API</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">React.createClass({ ... })\nReact.isValidElement(c)</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(&lt;Component />, domnode, [callback])\nReactDOM.unmountComponentAtNode(domnode)</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOMServer.renderToString(&lt;Component />)\nReactDOMServer.renderToStaticMarkup(&lt;Component />)</code></pre></div>\n<p>There are more, but these are most common.</p>\n<p>See: <a href=\"https://reactjs.org/docs/react-api.html\">React top-level API</a></p>\n<h2><a href=\"https://devhints.io/react#jsx-patterns\">#</a>JSX patterns</h2>\n<h3>Style shorthand</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const style = { height: 10 }\nreturn &lt;div style={style}>\n&lt;/div></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">return &lt;div style={{ margin: 0, padding: 0 }}>\n&lt;/div></code></pre></div>\n<p>See: <a href=\"https://reactjs.org/tips/inline-styles.html\">Inline styles</a></p>\n<h3>Inner HTML</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function markdownify() { return \"&lt;p>...&lt;/p>\"; }\n&lt;div dangerouslySetInnerHTML={{__html: markdownify()}} /></code></pre></div>\n<p>See: <a href=\"https://reactjs.org/tips/dangerously-set-inner-html.html\">Dangerously set innerHTML</a></p>\n<h3>Lists</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class TodoList extends Component {\n  render () {\n    const { items } = this.props\n\n    return &lt;ul>\n      {items.map(item =>\n        &lt;TodoItem item={item} key={item.key} />)}\n    &lt;/ul>\n  }\n}</code></pre></div>\n<p>Always supply a <code class=\"language-text\">key</code> property.</p>\n<h3>Conditionals</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Fragment>\n  {showMyComponent\n    ? &lt;MyComponent />\n    : &lt;OtherComponent />}\n&lt;/Fragment></code></pre></div>\n<h3>Short-circuit evaluation</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Fragment>\n  {showPopup &amp;&amp; &lt;Popup />}\n  ...\n&lt;/Fragment></code></pre></div>\n<h2><a href=\"https://devhints.io/react#new-features\">#</a>New features</h2>\n<h3>Returning multiple elements</h3>\n<p>You can return multiple elements as arrays or fragments.</p>\n<h4>Arrays</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render () {\n  // Don't forget the keys!\n  return [\n    &lt;li key=\"A\">First item&lt;/li>,\n    &lt;li key=\"B\">Second item&lt;/li>\n  ]\n}</code></pre></div>\n<h4>Fragments</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render () {\n  // Fragments don't require keys!\n  return (\n    &lt;Fragment>\n      &lt;li>First item&lt;/li>\n      &lt;li>Second item&lt;/li>\n    &lt;/Fragment>\n  )\n}</code></pre></div>\n<p>See: <a href=\"https://reactjs.org/blog/2017/09/26/react-v16.0.html#new-render-return-types-fragments-and-strings\">Fragments and strings</a></p>\n<h3>Returning strings</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render() {\n  return 'Look ma, no spans!';\n}</code></pre></div>\n<p>You can return just a string.</p>\n<p>See: <a href=\"https://reactjs.org/blog/2017/09/26/react-v16.0.html#new-render-return-types-fragments-and-strings\">Fragments and strings</a></p>\n<h3>Errors</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class MyComponent extends Component {\n  ···\n  componentDidCatch (error, info) {\n    this.setState({ error })\n  }\n}</code></pre></div>\n<p>Catch errors via <code class=\"language-text\">componentDidCatch</code>. (React 16+)</p>\n<p>See: <a href=\"https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html\">Error handling in React 16</a></p>\n<h3>Portals</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render () {\n  return React.createPortal(\n    this.props.children,\n    document.getElementById('menu')\n  )\n}</code></pre></div>\n<p>This renders <code class=\"language-text\">this.props.children</code> into any location in the DOM.</p>\n<p>See: <a href=\"https://reactjs.org/docs/portals.html\">Portals</a></p>\n<h3>Hydration</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const el = document.getElementById('app')\nReactDOM.hydrate(&lt;App />, el)</code></pre></div>\n<p>Use <code class=\"language-text\">ReactDOM.hydrate</code> instead of using <code class=\"language-text\">ReactDOM.render</code> if you're rendering over the output of <a href=\"https://reactjs.org/docs/react-dom-server.html\">ReactDOMServer</a>.</p>\n<p>See: <a href=\"https://reactjs.org/docs/react-dom.html#hydrate\">Hydrate</a></p>\n<h2><a href=\"https://devhints.io/react#property-validation\">#</a>Property validation</h2>\n<h3>PropTypes</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import PropTypes from 'prop-types'</code></pre></div>\n<p>See: <a href=\"https://reactjs.org/docs/typechecking-with-proptypes.html\">Typechecking with PropTypes</a></p>\n<table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">any</code></td>\n<td>Anything</td>\n</tr>\n</tbody>\n</table>\n<h4>Basic</h4>\n<table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">string</code></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">number</code></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">func</code></td>\n<td>Function</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">bool</code></td>\n<td>True or false</td>\n</tr>\n</tbody>\n</table>\n<h4>Enum</h4>\n<table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">oneOf</code><em>(any)</em></td>\n<td>Enum types</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">oneOfType</code><em>(type array)</em></td>\n<td>Union</td>\n</tr>\n</tbody>\n</table>\n<h4>Array</h4>\n<table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">array</code></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">arrayOf</code><em>(…)</em></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h4>Object</h4>\n<table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">object</code></td>\n<td></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">objectOf</code><em>(…)</em></td>\n<td>Object with values of a certain type</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">instanceOf</code><em>(…)</em></td>\n<td>Instance of a class</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">shape</code><em>(…)</em></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h4>Elements</h4>\n<table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">element</code></td>\n<td>React element</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">node</code></td>\n<td>DOM node</td>\n</tr>\n</tbody>\n</table>\n<h4>Required</h4>\n<table>\n<thead>\n<tr>\n<th>Key</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">(···).isRequired</code></td>\n<td>Required</td>\n</tr>\n</tbody>\n</table>\n<h3>Basic types</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">MyComponent.propTypes = {\n  email:      PropTypes.string,\n  seats:      PropTypes.number,\n  callback:   PropTypes.func,\n  isClosed:   PropTypes.bool,\n  any:        PropTypes.any\n}</code></pre></div>\n<h3>Required types</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">MyCo.propTypes = {\n  name:  PropTypes.string.isRequired\n}</code></pre></div>\n<h3>Elements</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">MyCo.propTypes = {\n  // React element\n  element: PropTypes.element,\n\n  // num, string, element, or an array of those\n  node: PropTypes.node\n}</code></pre></div>\n<h3>Enumerables (oneOf)</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">MyCo.propTypes = {\n  direction: PropTypes.oneOf([\n    'left', 'right'\n  ])\n}</code></pre></div>\n<h3>Arrays and objects</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">MyCo.propTypes = {\n  list: PropTypes.array,\n  ages: PropTypes.arrayOf(PropTypes.number),\n  user: PropTypes.object,\n  user: PropTypes.objectOf(PropTypes.number),\n  message: PropTypes.instanceOf(Message)\n}</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">MyCo.propTypes = {\n  user: PropTypes.shape({\n    name: PropTypes.string,\n    age:  PropTypes.number\n  })\n}</code></pre></div>\n<p>Use <code class=\"language-text\">.array[Of]</code>, <code class=\"language-text\">.object[Of]</code>, <code class=\"language-text\">.instanceOf</code>, <code class=\"language-text\">.shape</code>.</p>\n<h3>Custom validation</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">MyCo.propTypes = {\n  customProp: (props, key, componentName) => {\n    if (!/matchme/.test(props[key])) {\n      return new Error('Validation failed!')\n    }\n  }\n}</code></pre></div>\n<hr>\n<hr>\n<h1>React:</h1>\n<ul>\n<li><code class=\"language-text\">&lt;script src=\"https://unpkg.com/react@15/dist/react.js\"> &lt;/script></code></li>\n<li><code class=\"language-text\">$ npm install react --save</code></li>\n<li><code class=\"language-text\">$ bower install react --save</code></li>\n</ul>\n<p>React DOM:</p>\n<ul>\n<li><code class=\"language-text\">&lt;script src=\"https://unpkg.com/react-dom@15/dist/react-dom.js\"> &lt;/script></code></li>\n<li><code class=\"language-text\">$ npm install react-dom</code></li>\n<li><code class=\"language-text\">$ bower install react-dom --save</code></li>\n</ul>\n<h2>Rendering</h2>\n<h3>Rendering (ES5)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>Link<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'HackHall.com'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'menu'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Rendering (ES5+JSX)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Link name<span class=\"token operator\">=</span><span class=\"token string\">\"HackHall.com\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'menu'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Server-side Rendering</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> ReactDOMServer <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'react-dom/server'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToString</span><span class=\"token punctuation\">(</span>Link<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'HackHall.com'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToStaticMarkup</span><span class=\"token punctuation\">(</span>Link<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'HackHall.com'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Components</h2>\n<h3>ES5</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> Link <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">displayName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Link'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">className</span><span class=\"token operator\">:</span> <span class=\"token string\">'btn'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Click ->'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>ES5 + JSX</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> Link <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>a className<span class=\"token operator\">=</span><span class=\"token string\">\"btn\"</span> title<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                Click <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>ES6 + JSX</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Link</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>a className<span class=\"token operator\">=</span><span class=\"token string\">\"btn\"</span> title<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                Click <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</details>\n<hr>\n<hr>\n<details>\n<summary>  </summary>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> <span class=\"token parameter variable\">--save</span> react       // declarative and flexible JavaScript library <span class=\"token keyword\">for</span> building UI\n<span class=\"token function\">npm</span> <span class=\"token function\">install</span> <span class=\"token parameter variable\">--save</span> react-dom   // serves as the entry point of the DOM-related rendering paths\n<span class=\"token function\">npm</span> <span class=\"token function\">install</span> <span class=\"token parameter variable\">--save</span> prop-types  // runtime <span class=\"token builtin class-name\">type</span> checking <span class=\"token keyword\">for</span> React props and similar objects</code></pre></div>\n<p>// notes: don't forget the command lines</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * REACT\n * https://reactjs.org/docs/react-api.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Create and return a new React element of the given type.</span>\n<span class=\"token comment\">// Code written with JSX will be converted to use React.createElement().</span>\n<span class=\"token comment\">// You will not typically invoke React.createElement() directly if you are using JSX.</span>\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n  type<span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span>props<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>children<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Clone and return a new React element using element as the starting point.</span>\n<span class=\"token comment\">// The resulting element will have the original element's props with the new props merged in shallowly.</span>\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">cloneElement</span><span class=\"token punctuation\">(</span>\n  element<span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span>props<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>children<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Verifies the object is a React element. Returns true or false.</span>\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">isValidElement</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span>\n\nReact<span class=\"token punctuation\">.</span>Children  <span class=\"token comment\">// provides utilities for dealing with the this.props.children opaque data structure.</span>\n\n<span class=\"token comment\">// Invokes a function on every immediate child contained within children with this set to thisArg.</span>\nReact<span class=\"token punctuation\">.</span>Children<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>children<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span>thisArg<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Like React.Children.map() but does not return an array.</span>\nReact<span class=\"token punctuation\">.</span>Children<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span>children<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span>thisArg<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Returns the total number of components in children,</span>\n<span class=\"token comment\">// equal to the number of times that a callback passed to map or forEach would be invoked.</span>\nReact<span class=\"token punctuation\">.</span>Children<span class=\"token punctuation\">.</span><span class=\"token function\">count</span><span class=\"token punctuation\">(</span>children<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Verifies that children has only one child (a React element) and returns it.</span>\n<span class=\"token comment\">// Otherwise this method throws an error.</span>\nReact<span class=\"token punctuation\">.</span>Children<span class=\"token punctuation\">.</span><span class=\"token function\">only</span><span class=\"token punctuation\">(</span>children<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Returns the children opaque data structure as a flat array with keys assigned to each child.</span>\n<span class=\"token comment\">// Useful if you want to manipulate collections of children in your render methods,</span>\n<span class=\"token comment\">// especially if you want to reorder or slice this.props.children before passing it down.</span>\nReact<span class=\"token punctuation\">.</span>Children<span class=\"token punctuation\">.</span><span class=\"token function\">toArray</span><span class=\"token punctuation\">(</span>children<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// The React.Fragment component lets you return multiple elements in a render() method without creating an additional DOM element</span>\n<span class=\"token comment\">// You can also use it with the shorthand &lt;></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span><span class=\"token operator\">></span> syntax<span class=\"token punctuation\">.</span>\nReact<span class=\"token punctuation\">.</span>Fragment\n\n<span class=\"token comment\">/* *******************************************************************************************\n * REACT.COMPONENT\n * React.Component is an abstract base class, so it rarely makes sense to refer to React.Component\n * directly. Instead, you will typically subclass it, and define at least a render() method.\n * https://reactjs.org/docs/react-component.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Component</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Will be called before it is mounted</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Call this method before any other statement</span>\n    <span class=\"token comment\">// or this.props will be undefined in the constructor</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// The constructor is also often used to bind event handlers to the class instance.</span>\n    <span class=\"token comment\">// Binding makes sure the method has access to component attributes like this.props and this.state</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>method <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">method</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// The constructor is the right place to initialize state.</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">active</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n\n      <span class=\"token comment\">// In rare cases, it's okay to initialize state based on props.</span>\n      <span class=\"token comment\">// This effectively \"forks\" the props and sets the state with the initial props.</span>\n      <span class=\"token comment\">// If you \"fork\" props by using them for state, you might also want to implement componentWillReceiveProps(nextProps)</span>\n      <span class=\"token comment\">// to keep the state up-to-date with them. But lifting state up is often easier and less bug-prone.</span>\n      <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> props<span class=\"token punctuation\">.</span>initialColor\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Enqueues changes to the component state and</span>\n  <span class=\"token comment\">// tells React that this component and its children need to be re-rendered with the updated state.</span>\n  <span class=\"token comment\">// setState() does not always immediately update the component. It may batch or defer the update until later.</span>\n  <span class=\"token comment\">// This makes reading this.state right after calling setState() a potential pitfall.</span>\n  <span class=\"token comment\">// Instead, use componentDidUpdate or a setState callback.</span>\n  <span class=\"token comment\">// You may optionally pass an object as the first argument to setState() instead of a function.</span>\n  <span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">updater<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Invoked just before mounting occurs (before render())</span>\n  <span class=\"token comment\">// This is the only lifecycle hook called on server rendering.</span>\n  <span class=\"token function\">componentWillMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Invoked immediately after a component is mounted.</span>\n  <span class=\"token comment\">// Initialization that requires DOM nodes should go here.</span>\n  <span class=\"token comment\">// If you need to load data from a remote endpoint, this is a good place to instantiate the network request.</span>\n  <span class=\"token comment\">// This method is a good place to set up any subscriptions. If you do that, don't forget to unsubscribe in componentWillUnmount().</span>\n  <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Invoked before a mounted component receives new props.</span>\n  <span class=\"token comment\">// If you need to update the state in response to prop changes (for example, to reset it),</span>\n  <span class=\"token comment\">// you may compare this.props and nextProps and perform state transitions using this.setState() in this method.</span>\n  <span class=\"token function\">componentWillReceiveProps</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">nextProps</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Let React know if a component's output is not affected by the current change in state or props.</span>\n  <span class=\"token comment\">// The default behavior is to re-render on every state change, and in the vast majority of cases you should rely on the default behavior.</span>\n  <span class=\"token comment\">// shouldComponentUpdate() is invoked before rendering when new props or state are being received. Defaults to true.</span>\n  <span class=\"token comment\">// This method is not called for the initial render or when forceUpdate() is used.</span>\n  <span class=\"token comment\">// Returning false does not prevent child components from re-rendering when their state changes.</span>\n  <span class=\"token function\">shouldComponentUpdate</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">nextProps<span class=\"token punctuation\">,</span> nextState</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Invoked just before rendering when new props or state are being received.</span>\n  <span class=\"token comment\">// Use this as an opportunity to perform preparation before an update occurs. This method is not called for the initial render.</span>\n  <span class=\"token comment\">// Note that you cannot call this.setState() here; nor should you do anything else</span>\n  <span class=\"token comment\">// (e.g. dispatch a Redux action) that would trigger an update to a React component before componentWillUpdate() returns.</span>\n  <span class=\"token comment\">// If you need to update state in response to props changes, use componentWillReceiveProps() instead.</span>\n  <span class=\"token function\">componentWillUpdate</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">nextProps<span class=\"token punctuation\">,</span> nextState</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Invoked immediately after updating occurs. This method is not called for the initial render.</span>\n  <span class=\"token comment\">// Use this as an opportunity to operate on the DOM when the component has been updated.</span>\n  <span class=\"token comment\">// This is also a good place to do network requests as long as you compare the current props to previous props (e.g. a network request may not be necessary if the props have not changed).</span>\n  <span class=\"token function\">componentDidUpdate</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">prevProps<span class=\"token punctuation\">,</span> prevState</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Invoked immediately before a component is unmounted and destroyed.</span>\n  <span class=\"token comment\">// Perform any necessary cleanup in this method, such as invalidating timers, canceling network requests,</span>\n  <span class=\"token comment\">// or cleaning up any subscriptions that were created in componentDidMount().</span>\n  <span class=\"token function\">componentWillUnmount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// Error boundaries are React components that catch JavaScript errors anywhere in their child component tree,</span>\n  <span class=\"token comment\">// log those errors, and display a fallback UI instead of the component tree that crashed.</span>\n  <span class=\"token comment\">// Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.</span>\n  <span class=\"token function\">componentDidCatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// This method is required.</span>\n  <span class=\"token comment\">// It should be pure, meaning that it does not modify component state,</span>\n  <span class=\"token comment\">// it returns the same result each time it's invoked, and</span>\n  <span class=\"token comment\">// it does not directly interact with the browser (use lifecycle methods for this)</span>\n  <span class=\"token comment\">// It must return one of the following types: react elements, string and numbers, portals, null or booleans.</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Contains the props that were defined by the caller of this component.</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Contains data specific to this component that may change over time.</span>\n    <span class=\"token comment\">// The state is user-defined, and it should be a plain JavaScript object.</span>\n    <span class=\"token comment\">// If you don't use it in render(), it shouldn't be in the state.</span>\n    <span class=\"token comment\">// For example, you can put timer IDs directly on the instance.</span>\n    <span class=\"token comment\">// Never mutate this.state directly, as calling setState() afterwards may replace the mutation you made.</span>\n    <span class=\"token comment\">// Treat this.state as if it were immutable.</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">{</span><span class=\"token comment\">/* Comment goes here */</span><span class=\"token punctuation\">}</span>\n        Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">!</span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Can be defined as a property on the component class itself, to set the default props for the class.</span>\n<span class=\"token comment\">// This is used for undefined props, but not for null props.</span>\nComponent<span class=\"token punctuation\">.</span>defaultProps <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'blue'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\ncomponent <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Component</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// By default, when your component's state or props change, your component will re-render.</span>\n<span class=\"token comment\">// If your render() method depends on some other data, you can tell React that the component needs re-rendering by calling forceUpdate().</span>\n<span class=\"token comment\">// Normally you should try to avoid all uses of forceUpdate() and only read from this.props and this.state in render().</span>\ncomponent<span class=\"token punctuation\">.</span><span class=\"token function\">forceUpdate</span><span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * REACT.DOM\n * The react-dom package provides DOM-specific methods that can be used at the top level of\n * your app and as an escape hatch to get outside of the React model if you need to.\n * Most of your components should not need to use this module.\n * https://reactjs.org/docs/react-dom.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Render a React element into the DOM in the supplied container and return a reference</span>\n<span class=\"token comment\">// to the component (or returns null for stateless components).</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Same as render(), but is used to hydrate a container whose HTML contents were rendered</span>\n<span class=\"token comment\">// by ReactDOMServer. React will attempt to attach event listeners to the existing markup.</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">hydrate</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Remove a mounted React component from the DOM and clean up its event handlers and state.</span>\n<span class=\"token comment\">// If no component was mounted in the container, calling this function does nothing.</span>\n<span class=\"token comment\">// Returns true if a component was unmounted and false if there was no component to unmount.</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">unmountComponentAtNode</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// If this component has been mounted into the DOM, this returns the corresponding native browser</span>\n<span class=\"token comment\">// DOM element. This method is useful for reading values out of the DOM, such as form field values</span>\n<span class=\"token comment\">// and performing DOM measurements. In most cases, you can attach a ref to the DOM node and avoid</span>\n<span class=\"token comment\">// using findDOMNode at all.</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">findDOMNode</span><span class=\"token punctuation\">(</span>component<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Creates a portal. Portals provide a way to render children into a DOM node that exists outside</span>\n<span class=\"token comment\">// the hierarchy of the DOM component.</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">createPortal</span><span class=\"token punctuation\">(</span>child<span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * REACTDOMSERVER\n * The ReactDOMServer object enables you to render components to static markup.\n * https://reactjs.org/docs/react-dom.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token comment\">// Render a React element to its initial HTML. React will return an HTML string.</span>\n<span class=\"token comment\">// You can use this method to generate HTML on the server and send the markup down on the initial</span>\n<span class=\"token comment\">// request for faster page loads and to allow search engines to crawl your pages for SEO purposes.</span>\nReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToString</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Similar to renderToString, except this doesn't create extra DOM attributes that React uses</span>\n<span class=\"token comment\">// internally, such as data-reactroot. This is useful if you want to use React as a simple static</span>\n<span class=\"token comment\">// page generator, as stripping away the extra attributes can save some bytes.</span>\nReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToStaticMarkup</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Render a React element to its initial HTML. Returns a Readable stream that outputs an HTML string.</span>\n<span class=\"token comment\">// The HTML output by this stream is exactly equal to what ReactDOMServer.renderToString would return.</span>\n<span class=\"token comment\">// You can use this method to generate HTML on the server and send the markup down on the initial</span>\n<span class=\"token comment\">// request for faster page loads and to allow search engines to crawl your pages for SEO purposes.</span>\nReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToNodeStream</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Similar to renderToNodeStream, except this doesn't create extra DOM attributes that React uses</span>\n<span class=\"token comment\">// internally, such as data-reactroot. This is useful if you want to use React as a simple static</span>\n<span class=\"token comment\">// page generator, as stripping away the extra attributes can save some bytes.</span>\nReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToStaticNodeStream</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">/* *******************************************************************************************\n * TYPECHECKING WITH PROPTYPES\n * https://reactjs.org/docs/typechecking-with-proptypes.html\n * ******************************************************************************************* */</span>\n\n<span class=\"token keyword\">import</span> PropTypes <span class=\"token keyword\">from</span> <span class=\"token string\">'prop-types'</span><span class=\"token punctuation\">;</span>\n\nMyComponent<span class=\"token punctuation\">.</span>propTypes <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// You can declare that a prop is a specific JS type. By default, these</span>\n  <span class=\"token comment\">// are all optional.</span>\n  <span class=\"token literal-property property\">optionalArray</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">optionalBool</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>bool<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">optionalFunc</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>func<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">optionalNumber</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>number<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">optionalObject</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>object<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">optionalString</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>string<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">optionalSymbol</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>symbol<span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// Anything that can be rendered: numbers, strings, elements or an array</span>\n  <span class=\"token comment\">// (or fragment) containing these types.</span>\n  <span class=\"token literal-property property\">optionalNode</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// A React element.</span>\n  <span class=\"token literal-property property\">optionalElement</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// You can also declare that a prop is an instance of a class. This uses</span>\n  <span class=\"token comment\">// JS's instanceof operator.</span>\n  <span class=\"token literal-property property\">optionalMessage</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">instanceOf</span><span class=\"token punctuation\">(</span>Message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// You can ensure that your prop is limited to specific values by treating</span>\n  <span class=\"token comment\">// it as an enum.</span>\n  <span class=\"token literal-property property\">optionalEnum</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">oneOf</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'News'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Photos'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// An object that could be one of many types</span>\n  <span class=\"token literal-property property\">optionalUnion</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">oneOfType</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>\n    PropTypes<span class=\"token punctuation\">.</span>string<span class=\"token punctuation\">,</span>\n    PropTypes<span class=\"token punctuation\">.</span>number<span class=\"token punctuation\">,</span>\n    PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">instanceOf</span><span class=\"token punctuation\">(</span>Message<span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// An array of a certain type</span>\n  <span class=\"token literal-property property\">optionalArrayOf</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">arrayOf</span><span class=\"token punctuation\">(</span>PropTypes<span class=\"token punctuation\">.</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// An object with property values of a certain type</span>\n  <span class=\"token literal-property property\">optionalObjectOf</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">objectOf</span><span class=\"token punctuation\">(</span>PropTypes<span class=\"token punctuation\">.</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// An object taking on a particular shape</span>\n  <span class=\"token literal-property property\">optionalObjectWithShape</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">shape</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>string<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">fontSize</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>number\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// You can chain any of the above with `isRequired` to make sure a warning</span>\n  <span class=\"token comment\">// is shown if the prop isn't provided.</span>\n  <span class=\"token literal-property property\">requiredFunc</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>func<span class=\"token punctuation\">.</span>isRequired<span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// A value of any data type</span>\n  <span class=\"token literal-property property\">requiredAny</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>any<span class=\"token punctuation\">.</span>isRequired<span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// You can also specify a custom validator. It should return an Error</span>\n  <span class=\"token comment\">// object if the validation fails. Don't `console.warn` or throw, as this</span>\n  <span class=\"token comment\">// won't work inside `oneOfType`.</span>\n  <span class=\"token function-variable function\">customProp</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props<span class=\"token punctuation\">,</span> propName<span class=\"token punctuation\">,</span> componentName</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">matchme</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">[</span>propName<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span>\n        <span class=\"token string\">'Invalid prop `'</span> <span class=\"token operator\">+</span> propName <span class=\"token operator\">+</span> <span class=\"token string\">'` supplied to'</span> <span class=\"token operator\">+</span>\n        <span class=\"token string\">' `'</span> <span class=\"token operator\">+</span> componentName <span class=\"token operator\">+</span> <span class=\"token string\">'`. Validation failed.'</span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token comment\">// You can also supply a custom validator to `arrayOf` and `objectOf`.</span>\n  <span class=\"token comment\">// It should return an Error object if the validation fails. The validator</span>\n  <span class=\"token comment\">// will be called for each key in the array or object. The first two</span>\n  <span class=\"token comment\">// arguments of the validator are the array or object itself, and the</span>\n  <span class=\"token comment\">// current item's key.</span>\n  <span class=\"token literal-property property\">customArrayProp</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">arrayOf</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">propValue<span class=\"token punctuation\">,</span> key<span class=\"token punctuation\">,</span> componentName<span class=\"token punctuation\">,</span> location<span class=\"token punctuation\">,</span> propFullName</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">matchme</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>propValue<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span>\n        <span class=\"token string\">'Invalid prop `'</span> <span class=\"token operator\">+</span> propFullName <span class=\"token operator\">+</span> <span class=\"token string\">'` supplied to'</span> <span class=\"token operator\">+</span>\n        <span class=\"token string\">' `'</span> <span class=\"token operator\">+</span> componentName <span class=\"token operator\">+</span> <span class=\"token string\">'`. Validation failed.'</span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<h2>Advanced Components</h2>\n<h3>Options (ES5)</h3>\n<ul>\n<li><code class=\"language-text\">propTypes object</code>: Type validation in development mode</li>\n<li><code class=\"language-text\">getDefaultProps function()</code>: object of default props</li>\n<li><code class=\"language-text\">getInitialState function()</code>: object of the initial state</li>\n</ul>\n<p>ES5:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> Link <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">propTypes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>PropTypes<span class=\"token punctuation\">.</span>string <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getDefaultProps</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">initialCount</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getInitialState</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>initialCount <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">tick</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>count <span class=\"token operator\">+</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n            <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">className</span><span class=\"token operator\">:</span> <span class=\"token string\">'btn'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">href</span><span class=\"token operator\">:</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">onClick</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">tick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token string\">'Click ->'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name <span class=\"token operator\">?</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name <span class=\"token operator\">:</span> <span class=\"token string\">'webapplog.com'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token string\">' (Clicked: '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>count <span class=\"token operator\">+</span> <span class=\"token string\">')'</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>ES5 + JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> Link <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">propTypes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>PropTypes<span class=\"token punctuation\">.</span>string <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getDefaultProps</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">initialCount</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getInitialState</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>initialCount <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">tick</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>count <span class=\"token operator\">+</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>a onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">tick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> href<span class=\"token operator\">=</span><span class=\"token string\">\"#\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"btn\"</span> title<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                Click <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name <span class=\"token operator\">?</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name <span class=\"token operator\">:</span> <span class=\"token string\">'webapplog.com'</span><span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">(</span>Clicked<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>ES6 + JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Link</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> props<span class=\"token punctuation\">.</span>initialCount <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>count <span class=\"token operator\">+</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>a onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">tick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> href<span class=\"token operator\">=</span><span class=\"token string\">\"#\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"btn\"</span> title<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                Click <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name <span class=\"token operator\">?</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name <span class=\"token operator\">:</span> <span class=\"token string\">'webapplog.com'</span><span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">(</span>Clicked<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nLink<span class=\"token punctuation\">.</span>propTypes <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">initialCount</span><span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>PropTypes<span class=\"token punctuation\">.</span>number <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nLink<span class=\"token punctuation\">.</span>defaultProps <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">initialCount</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Lifecycle Events</h2>\n<p>Modern React lifecycle methods (v16+)</p>\n<p><img src=\"DZ-97vzW4AAbcZj.jpg\" alt=\"image\"></p>\n<p>Legacy Lifecycle Events:</p>\n<ul>\n<li><code class=\"language-text\">componentWillMount function()</code></li>\n<li><code class=\"language-text\">componentDidMount function()</code></li>\n<li><code class=\"language-text\">componentWillReceiveProps function(nextProps)</code></li>\n<li><code class=\"language-text\">shouldComponentUpdate function(nextProps, nextState)-> bool</code></li>\n<li><code class=\"language-text\">componentWillUpdate function(nextProps, nextState)</code></li>\n<li><code class=\"language-text\">componentDidUpdate function(prevProps, prevState)</code></li>\n<li><code class=\"language-text\">componentWillUnmount function()</code></li>\n</ul>\n<p>Sequence of lifecycle events:</p>\n<p><img src=\"lifecycle-events.png\" alt=\"image\"></p>\n<p>Inspired by <a href=\"http://react.tips\">http://react.tips</a></p>\n<h2>Special Props</h2>\n<ul>\n<li><code class=\"language-text\">key</code>: Unique identifier for an element to turn arrays/lists into hashes for better performance, e.g., <code class=\"language-text\">key={id}</code></li>\n<li><code class=\"language-text\">ref</code>: Reference to an element via <code class=\"language-text\">this.refs.NAME</code>, e.g., <code class=\"language-text\">ref=\"email\"</code> will create <code class=\"language-text\">this.refs.email</code> DOM node or <code class=\"language-text\">ReactDOM.findDOMNode(this.refs.email)</code></li>\n<li><code class=\"language-text\">style</code>: Accept an object of styles, instead of a string (immutable since v0.14), e.g., <code class=\"language-text\">style={{color: red}}</code></li>\n<li><code class=\"language-text\">className</code>: the HTML <code class=\"language-text\">class</code> attribute, e.g., <code class=\"language-text\">className=\"btn\"</code></li>\n<li><code class=\"language-text\">htmlFor</code>: the HTML <code class=\"language-text\">for</code> attribute, e.g., <code class=\"language-text\">htmlFor=\"email\"</code></li>\n<li><code class=\"language-text\">dangerouslySetInnerHTML</code>: raw HTML by providing an object with the key <code class=\"language-text\">__html</code></li>\n<li><code class=\"language-text\">children</code>: content of the element via <code class=\"language-text\">this.props.children</code>, e.g., <code class=\"language-text\">this.props.children[0]</code></li>\n<li><code class=\"language-text\">data-NAME</code>: custom attribute, e.g., <code class=\"language-text\">data-tooltip-text=\"...\"</code></li>\n</ul>\n<h2>propTypes</h2>\n<p>Types available under <code class=\"language-text\">React.PropTypes</code>:</p>\n<ul>\n<li><code class=\"language-text\">any</code></li>\n<li><code class=\"language-text\">array</code></li>\n<li><code class=\"language-text\">bool</code></li>\n<li><code class=\"language-text\">element</code></li>\n<li><code class=\"language-text\">func</code></li>\n<li><code class=\"language-text\">node</code></li>\n<li><code class=\"language-text\">number</code></li>\n<li><code class=\"language-text\">object</code></li>\n<li><code class=\"language-text\">string</code></li>\n</ul>\n<p>To make required, append <code class=\"language-text\">.isRequired</code>.</p>\n<p>More methods:</p>\n<ul>\n<li><code class=\"language-text\">instanceOf(constructor)</code></li>\n<li><code class=\"language-text\">oneOf(['News', 'Photos'])</code></li>\n<li><code class=\"language-text\">oneOfType([propType, propType])</code></li>\n</ul>\n<h3>Custom Validation</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token literal-property property\">propTypes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function-variable function\">customProp</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props<span class=\"token punctuation\">,</span> propName<span class=\"token punctuation\">,</span> componentName</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">regExPattern</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">[</span>propName<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Validation failed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Component Properties and Methods</h2>\n<p>Properties:</p>\n<ul>\n<li><code class=\"language-text\">this.refs</code>: Lists components with a <code class=\"language-text\">ref</code> prop</li>\n<li><code class=\"language-text\">this.props</code>: Any props passed to an element (immutable)</li>\n<li><code class=\"language-text\">this.state</code>: State set by setState and getInitialState (muttable) — avoid setting state manually with <code class=\"language-text\">this.state=...</code></li>\n<li><code class=\"language-text\">this.isMounted</code>: Flag whether the element has a corresponding DOM node or not</li>\n</ul>\n<p>Methods:</p>\n<ul>\n<li><code class=\"language-text\">setState(changes)</code>: Change state (partially) to <code class=\"language-text\">this.state</code> and trigger re-render</li>\n<li><code class=\"language-text\">replaceState(newState)</code>: Replace <code class=\"language-text\">this.state</code> and trigger re-render</li>\n<li><code class=\"language-text\">forceUpdate()</code>: Trigger DOM re-render immediately</li>\n</ul>\n<h2>React Addons</h2>\n<p>As npm modules:</p>\n<ul>\n<li><a href=\"http://facebook.github.io/react/docs/animation.html\"><code class=\"language-text\">react-addons-css-transition-group</code></a></li>\n<li><a href=\"http://facebook.github.io/react/docs/perf.html\"><code class=\"language-text\">react-addons-perf</code></a></li>\n<li><a href=\"http://facebook.github.io/react/docs/test-utils.html\"><code class=\"language-text\">react-addons-test-utils</code></a></li>\n<li><a href=\"http://facebook.github.io/react/docs/pure-render-mixin.html\"><code class=\"language-text\">react-addons-pure-render-mixin</code></a></li>\n<li><a href=\"http://facebook.github.io/react/docs/two-way-binding-helpers.html\"><code class=\"language-text\">react-addons-linked-state-mixin</code></a></li>\n<li><code class=\"language-text\">react-addons-clone-with-props</code></li>\n<li><code class=\"language-text\">react-addons-create-fragment</code></li>\n<li><code class=\"language-text\">react-addons-css-transition-group</code></li>\n<li><code class=\"language-text\">react-addons-linked-state-mixin</code></li>\n<li><code class=\"language-text\">react-addons-pure-render-mixin</code></li>\n<li><code class=\"language-text\">react-addons-shallow-compare</code></li>\n<li><code class=\"language-text\">react-addons-transition-group</code></li>\n<li><a href=\"http://facebook.github.io/react/docs/update.html\"><code class=\"language-text\">react-addons-update</code></a></li>\n</ul>\n<h2>React Components</h2>\n<ul>\n<li><a href=\"https://github.com/brillout/awesome-react-components\">https://github.com/brillout/awesome-react-components</a> and <a href=\"http://devarchy.com/react-components\">http://devarchy.com/react-components</a>: List of React components</li>\n<li><a href=\"http://www.material-ui.com\">Material-UI</a>: Material design React components</li>\n<li><a href=\"http://react-toolbox.com\">http://react-toolbox.com</a>: Set of React components that implement Google Material Design specification</li>\n<li><a href=\"https://js.coach\">https://js.coach</a>: Opinionated catalog of open source JS (mostly React) packages</li>\n<li><a href=\"https://react.rocks\">https://react.rocks</a>: Catalog of React components</li>\n<li><a href=\"https://khan.github.io/react-components\">https://khan.github.io/react-components</a>: Khan Academy React components</li>\n<li><a href=\"http://www.reactjsx.com\">http://www.reactjsx.com</a>: Registry of React components</li>\n</ul>"},{"url":"/docs/react/ajax-n-apis/","relativePath":"docs/react/ajax-n-apis.md","relativeDir":"docs/react","base":"ajax-n-apis.md","name":"ajax-n-apis","frontmatter":{"title":"AJAX and APIs","weight":0,"excerpt":"AJAX and APIs","seo":{"title":"AJAX and APIs","description":"You can use any AJAX library you like with React. Some popular ones are Axios, jQuery AJAX, and the browser built-in window.fetch.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>AJAX and APIs - React</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>A JavaScript library for building user interfaces</p>\n</blockquote>\n<hr>\n<h3><a href=\"https://reactjs.org/docs/lists-and-keys.html#how-can-i-make-an-ajax-call\"></a>How can I make an AJAX call?</h3>\n<p>You can use any AJAX library you like with React. Some popular ones are <a href=\"https://github.com/axios/axios\">Axios</a>, <a href=\"https://api.jquery.com/jQuery.ajax/\">jQuery AJAX</a>, and the browser built-in <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\">window.fetch</a>.</p>\n<h3><a href=\"https://reactjs.org/docs/lists-and-keys.html#where-in-the-component-lifecycle-should-i-make-an-ajax-call\"></a>Where in the component lifecycle should I make an AJAX call?</h3>\n<p>You should populate data with AJAX calls in the <a href=\"https://reactjs.org/docs/react-component.html#mounting\"><code class=\"language-text\">componentDidMount</code></a> lifecycle method. This is so you can use <code class=\"language-text\">setState</code> to update your component when the data is retrieved.</p>\n<h3><a href=\"https://reactjs.org/docs/lists-and-keys.html#example-using-ajax-results-to-set-local-state\"></a>Example: Using AJAX results to set local state</h3>\n<p>The component below demonstrates how to make an AJAX call in <code class=\"language-text\">componentDidMount</code> to populate local component state.</p>\n<p>The example API returns a JSON object like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">{</span>\n  <span class=\"token string-property property\">\"items\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token string-property property\">\"id\"</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string-property property\">\"name\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Apples\"</span><span class=\"token punctuation\">,</span>  <span class=\"token string-property property\">\"price\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"$2\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token string-property property\">\"id\"</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string-property property\">\"name\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Peaches\"</span><span class=\"token punctuation\">,</span> <span class=\"token string-property property\">\"price\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"$5\"</span> <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MyComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">error</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">isLoaded</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">items</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://api.example.com/items'</span><span class=\"token punctuation\">)</span>\n            <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">res</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> res<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n            <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>\n                <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">isLoaded</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token literal-property property\">items</span><span class=\"token operator\">:</span> result<span class=\"token punctuation\">.</span>items\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">isLoaded</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n                        error\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> error<span class=\"token punctuation\">,</span> isLoaded<span class=\"token punctuation\">,</span> items <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>Error<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>error<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>isLoaded<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>Loading<span class=\"token operator\">...</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>price<span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Here is the equivalent with <a href=\"https://reactjs.org/docs/hooks-intro.html\">Hooks</a>:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">MyComponent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>error<span class=\"token punctuation\">,</span> setError<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>isLoaded<span class=\"token punctuation\">,</span> setIsLoaded<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>items<span class=\"token punctuation\">,</span> setItems<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span><span class=\"token string\">'https://api.example.com/items'</span><span class=\"token punctuation\">)</span>\n            <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">res</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> res<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n            <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>\n                <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">setIsLoaded</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token function\">setItems</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">setIsLoaded</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token function\">setError</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>Error<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>error<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>isLoaded<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>Loading<span class=\"token operator\">...</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>price<span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>"},{"url":"/docs/react/createReactApp/","relativePath":"docs/react/createReactApp.md","relativeDir":"docs/react","base":"createReactApp.md","name":"createReactApp","frontmatter":{"title":"npx-create-react-app","weight":0,"seo":{"title":"npx-create-react-app","description":"This is the npx-create-react-app page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"npx-create-react-app","keyName":"property"},{"name":"og:description","value":"This is the npx-create-react-app page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"npx-create-react-app"},{"name":"twitter:description","value":"This is the npx-create-react-app page"}]},"template":"docs"},"html":"<hr>\n<h2>description: takes soooo much time!</h2>\n<h1>Generating React Project</h1>\n<p>takes soooo much time!</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npx create-react-app my-app\ncd my-app\nnpm start</code></pre></div>\n<h4>Babel can translate between different versions of javascript so that your code can run on browsers that are limited to ES5 compatibility... included by default with every new react project.</h4>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token operator\">|</span><span class=\"token number\">15</span>:25:30<span class=\"token operator\">|</span>bryan@LAPTOP-9LGJ3JGS:<span class=\"token punctuation\">[</span>05-installing-nodejs<span class=\"token punctuation\">]</span> 05-installing-nodejs_exitstatus:0__________________________________________________________o<span class=\"token operator\">></span>\n\nnpx create-react-app my-app\ny-app\n<span class=\"token function\">npm</span> start\nCreating a new React app <span class=\"token keyword\">in</span> /mnt/c/MY-WEB-DEV/10-React-V3/05-installing-nodejs/my-app.\n\nInstalling packages. This might take a couple of minutes.\nInstalling react, react-dom, and react-scripts with cra-template<span class=\"token punctuation\">..</span>.\n\n<span class=\"token function\">yarn</span> <span class=\"token function\">add</span> v1.22.5\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span>/4<span class=\"token punctuation\">]</span> Resolving packages<span class=\"token punctuation\">..</span>.\n<span class=\"token punctuation\">[</span><span class=\"token number\">2</span>/4<span class=\"token punctuation\">]</span> Fetching packages<span class=\"token punctuation\">..</span>.\ninfo fsevents@1.2.13: The platform <span class=\"token string\">\"linux\"</span> is incompatible with this module.\ninfo <span class=\"token string\">\"fsevents@1.2.13\"</span> is an optional dependency and failed compatibility check. Excluding it from installation.\ninfo fsevents@2.3.2: The platform <span class=\"token string\">\"linux\"</span> is incompatible with this module.\ninfo <span class=\"token string\">\"fsevents@2.3.2\"</span> is an optional dependency and failed compatibility check. Excluding it from installation.\n<span class=\"token punctuation\">[</span><span class=\"token number\">3</span>/4<span class=\"token punctuation\">]</span> Linking dependencies<span class=\"token punctuation\">..</span>.\nwarning <span class=\"token string\">\"react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.20.0\"</span> has unmet peer dependency <span class=\"token string\">\"typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta\"</span><span class=\"token builtin class-name\">.</span>\n<span class=\"token punctuation\">[</span>----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<span class=\"token punctuation\">[</span><span class=\"token number\">4</span>/4<span class=\"token punctuation\">]</span> Building fresh packages<span class=\"token punctuation\">..</span>.\nsuccess Saved lockfile.\nsuccess Saved <span class=\"token number\">7</span> new dependencies.\ninfo Direct dependencies\n├─ cra-template@1.1.2\n├─ react-dom@17.0.2\n├─ react-scripts@4.0.3\n└─ react@17.0.2\ninfo All dependencies\n├─ cra-template@1.1.2\n├─ immer@8.0.1\n├─ react-dev-utils@11.0.4\n├─ react-dom@17.0.2\n├─ react-scripts@4.0.3\n├─ react@17.0.2\n└─ scheduler@0.20.2\nDone <span class=\"token keyword\">in</span> <span class=\"token number\">768</span>.43s.\n\nInstalling template dependencies using yarnpkg<span class=\"token punctuation\">..</span>.\n<span class=\"token function\">yarn</span> <span class=\"token function\">add</span> v1.22.5\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span>/4<span class=\"token punctuation\">]</span> Resolving packages<span class=\"token punctuation\">..</span>.\n<span class=\"token punctuation\">[</span><span class=\"token number\">2</span>/4<span class=\"token punctuation\">]</span> Fetching packages<span class=\"token punctuation\">..</span>.\ninfo fsevents@2.3.2: The platform <span class=\"token string\">\"linux\"</span> is incompatible with this module.\ninfo <span class=\"token string\">\"fsevents@2.3.2\"</span> is an optional dependency and failed compatibility check. Excluding it from installation.\ninfo fsevents@1.2.13: The platform <span class=\"token string\">\"linux\"</span> is incompatible with this module.\ninfo <span class=\"token string\">\"fsevents@1.2.13\"</span> is an optional dependency and failed compatibility check. Excluding it from installation.\n<span class=\"token punctuation\">[</span><span class=\"token number\">3</span>/4<span class=\"token punctuation\">]</span> Linking dependencies<span class=\"token punctuation\">..</span>.\nwarning <span class=\"token string\">\"react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.20.0\"</span> has unmet peer dependency <span class=\"token string\">\"typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta\"</span><span class=\"token builtin class-name\">.</span>\nwarning <span class=\"token string\">\" > @testing-library/user-event@12.8.3\"</span> has unmet peer dependency <span class=\"token string\">\"@testing-library/dom@>=7.21.4\"</span><span class=\"token builtin class-name\">.</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">4</span>/4<span class=\"token punctuation\">]</span> Building fresh packages<span class=\"token punctuation\">..</span>.\nsuccess Saved lockfile.\nsuccess Saved <span class=\"token number\">17</span> new dependencies.\ninfo Direct dependencies\n├─ @testing-library/jest-dom@5.11.10\n├─ @testing-library/react@11.2.5\n├─ @testing-library/user-event@12.8.3\n├─ react-dom@17.0.2\n├─ react@17.0.2\n└─ web-vitals@1.1.1\ninfo All dependencies\n├─ @testing-library/dom@7.30.1\n├─ @testing-library/jest-dom@5.11.10\n├─ @testing-library/react@11.2.5\n├─ @testing-library/user-event@12.8.3\n├─ @types/aria-query@4.2.1\n├─ @types/jest@26.0.22\n├─ @types/testing-library__jest-dom@5.9.5\n├─ css.escape@1.5.1\n├─ css@3.0.0\n├─ dom-accessibility-api@0.5.4\n├─ lz-string@1.4.4\n├─ min-indent@1.0.1\n├─ react-dom@17.0.2\n├─ react@17.0.2\n├─ redent@3.0.0\n├─ strip-indent@3.0.0\n└─ web-vitals@1.1.1\nDone <span class=\"token keyword\">in</span> <span class=\"token number\">706</span>.12s.\nRemoving template package using yarnpkg<span class=\"token punctuation\">..</span>.\n\n<span class=\"token function\">yarn</span> remove v1.22.5\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span>/2<span class=\"token punctuation\">]</span> Removing module cra-template<span class=\"token punctuation\">..</span>.\n<span class=\"token punctuation\">[</span><span class=\"token number\">2</span>/2<span class=\"token punctuation\">]</span> Regenerating lockfile and installing missing dependencies<span class=\"token punctuation\">..</span>.\ninfo fsevents@2.3.2: The platform <span class=\"token string\">\"linux\"</span> is incompatible with this module.\ninfo <span class=\"token string\">\"fsevents@2.3.2\"</span> is an optional dependency and failed compatibility check. Excluding it from installation.\ninfo fsevents@1.2.13: The platform <span class=\"token string\">\"linux\"</span> is incompatible with this module.\ninfo <span class=\"token string\">\"fsevents@1.2.13\"</span> is an optional dependency and failed compatibility check. Excluding it from installation.\nwarning <span class=\"token string\">\" > @testing-library/user-event@12.8.3\"</span> has unmet peer dependency <span class=\"token string\">\"@testing-library/dom@>=7.21.4\"</span><span class=\"token builtin class-name\">.</span>\nwarning <span class=\"token string\">\"react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.20.0\"</span> has unmet peer dependency <span class=\"token string\">\"typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta\"</span><span class=\"token builtin class-name\">.</span>\nsuccess Uninstalled packages.\nDone <span class=\"token keyword\">in</span> <span class=\"token number\">619</span>.62s.\n\nSuccess<span class=\"token operator\">!</span> Created my-app at /mnt/c/MY-WEB-DEV/10-React-V3/05-installing-nodejs/my-app\nInside that directory, you can run several commands:\n\n  <span class=\"token function\">yarn</span> start\n    Starts the development server.\n\n  <span class=\"token function\">yarn</span> build\n    Bundles the app into static files <span class=\"token keyword\">for</span> production.\n\n  <span class=\"token function\">yarn</span> <span class=\"token builtin class-name\">test</span>\n    Starts the <span class=\"token builtin class-name\">test</span> runner.\n\n  <span class=\"token function\">yarn</span> <span class=\"token function\">eject</span>\n    Removes this tool and copies build dependencies, configuration files\n    and scripts into the app directory. If you <span class=\"token keyword\">do</span> this, you can't go back<span class=\"token operator\">!</span>\n\nWe suggest that you begin by typing:\n\n  <span class=\"token builtin class-name\">cd</span> my-app\n  <span class=\"token function\">yarn</span> start\n\nCompiled successfully<span class=\"token operator\">!</span>\n\nYou can now view my-app <span class=\"token keyword\">in</span> the browser.\n\n  Local:            http://localhost:3000\n  On Your Network:  http://172.25.168.12:3000\n\nNote that the development build is not optimized.\nTo create a production build, use <span class=\"token function\">yarn</span> build.</code></pre></div>"},{"url":"/docs/react/demo/","relativePath":"docs/react/demo.md","relativeDir":"docs/react","base":"demo.md","name":"demo","frontmatter":{"title":"React Class Components Demo","weight":0,"excerpt":"React Class Components Demo","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>React Class Components Demo</h2>\n<h2>React Demo <a id=\"b2b8\"></h2>\n</a>\n<ul>\n<li>ex1 — A Basic React Component</li>\n<li>ex2 — A Basic React Class Component</li>\n<li>ex3 — A Class Component with State</li>\n<li>ex4 — A Class Component that Updates State</li>\n<li>ex5 — A Class Component that Iterates through State</li>\n<li>ex6 — An Example of Parent and Child Components</li>\n</ul>\n<p>With regards to converting an existing HTML, CSS, and JS site into React, first you'll want to think about how to break up your site into components,</p>\n<ul>\n<li>as well as think about what the general hierarchical component structure of your site will look like.</li>\n<li>From there, it's a simple matter of copying the relevant HTML for that component and throwing it into the <strong>render method of your component file.</strong></li>\n<li><em>Any methods that are needed for that component to function properly can added onto your new component.</em></li>\n</ul>\n<p>Once you've refactored your HTML components into React components, you'll want to lay them out in the desired hierarchical structure</p>\n<ul>\n<li>with children components being rendered by their parents, as well as ensuring that the parent components are passing down the necessary data as props to their children components.</li>\n</ul>\n<p>ex.)</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">!</span><span class=\"token operator\">--</span> Hello world <span class=\"token operator\">--</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>div <span class=\"token keyword\">class</span><span class=\"token operator\">=</span><span class=\"token string\">\"awesome\"</span> style<span class=\"token operator\">=</span><span class=\"token string\">\"border: 1px solid red\"</span><span class=\"token operator\">></span>\n  <span class=\"token operator\">&lt;</span>label <span class=\"token keyword\">for</span><span class=\"token operator\">=</span><span class=\"token string\">\"name\"</span><span class=\"token operator\">></span>Enter your name<span class=\"token operator\">:</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span>\n  <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> id<span class=\"token operator\">=</span><span class=\"token string\">\"name\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Enter your <span class=\"token constant\">HTML</span> here<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span></code></pre></div>\n<p>Is equivalent to:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">let</span> NewComponent <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token comment\">/* Hello world */</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"awesome\"</span> style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token string\">'1px solid red'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>label htmlFor<span class=\"token operator\">=</span><span class=\"token string\">\"name\"</span><span class=\"token operator\">></span>Enter your name<span class=\"token operator\">:</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> id<span class=\"token operator\">=</span><span class=\"token string\">\"name\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Enter your <span class=\"token constant\">HTML</span> here<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>A Basic Component <a id=\"fa4c\"></h2>\n</a>\n<p>Acomponent is some thing that is being rendered in the browser. It could be a button, a form with a bunch of fields in it…etc.…</p>\n<p>React doesn't place any restrictions on how large or small a component can be.</p>\n<p>You <em>could</em> have an entire static site encapsulated in a single React component, but that would defeat the purpose of using React.</p>\n<p>So the first thing to remember about a component is that a <strong>component must</strong> <strong><em>render</em></strong> <strong>something.</strong></p>\n<p><em>If nothing is being rendered from a component, then React will throw an error.</em></p>\n<p>Inside of <code class=\"language-text\">BasicComponent.js</code> , first import React at the top of the file. Our most basic of components looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">BasicComponent</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>Hello World<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> BasicComponent<span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p><em>This is a component that simply returns a div tag with the words Hello World! inside.</em></p>\n<p><em>The last line simply exports our component so that it can be imported</em><br>\n<em>by another file.</em></p>\n</blockquote>\n<p>Notice that this component looks exactly like an anonymous arrow function that we've named <code class=\"language-text\">BasicComponent</code> .</p>\n<p>In fact, that is literally what this is.</p>\n<p>The arrow function then is simply returning the div tag. When a component is written as a function like this one is, it is called a <em>functional</em> component.</p>\n<h2>A Basic Class Component <a id=\"8d7d\"></h2>\n</a>\n<p>The above component is an example of a functional component, which is appropriate since that component is literally nothing more than a function that returns some HTML.</p>\n<p><em>Functional components are great when all you want a component to do is to render some stuff.</em></p>\n<p><em>Components can also be written as classes (although this paradigm is becoming outdated and you should strive to write your components functionally!</em></p>\n<p>For this exercise, we're going to write a class component that does exactly the same thing as the functional component we just wrote.</p>\n<p>We'll again need to import React at the top of the file, but we'll also need to add a little something. Our import statement will look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { Component } from 'react';</code></pre></div>\n<p><strong>So, in addition to importing React, we're also importing the base Component class that is included in the React library.</strong></p>\n<h3>React lets you define components as classes or functions. <a id=\"ed09\"></h3>\n</a>\n<p>Components defined as classes currently provide more features . To define a React component class, you need to extend <code class=\"language-text\">React.Component</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Welcome</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>The only method you</strong> <strong><em>must</em></strong> <strong>define in a <code class=\"language-text\">React.Component</code> subclass is called</strong> [``](https://reactjs.org/docs/react-component.html#render)<strong>.</strong></p>\n<h2><code class=\"language-text\">render()</code> <a id=\"2c45\"></h2>\n</a>\n<p>The <code class=\"language-text\">render()</code> method is the only required method in a class component.</p>\n<p>When called, it should examine <code class=\"language-text\">this.props</code> and <code class=\"language-text\">this.state</code> and return one of the following types:</p>\n<ul>\n<li><strong>React elements.</strong> Typically created via [JSX](https://reactjs.org/docs/introducing-jsx.html). For example, <code class=\"language-text\">&lt;div /></code> and <code class=\"language-text\">&lt;MyComponent /></code> are React elements that instruct React to render a DOM node, or another user-defined component, respectively.</li>\n<li><strong>Arrays and fragments.</strong> Let you return multiple elements from render. See the documentation on [fragments](https://reactjs.org/docs/fragments.html) for more details.</li>\n<li><strong>Portals</strong>. Let you render children into a different DOM subtree. See the documentation on [portals](https://reactjs.org/docs/portals.html) for more details.</li>\n<li><strong>String and numbers.</strong> These are rendered as text nodes in the DOM.</li>\n<li><strong>Booleans or <code class=\"language-text\">null</code></strong>. Render nothing. (Mostly exists to support <code class=\"language-text\">return test &amp;&amp; &lt;Child /></code> pattern, where <code class=\"language-text\">test</code> is boolean.)</li>\n</ul>\n<p>The <code class=\"language-text\">render()</code> function should be pure, meaning that it does not modify component state, it returns the same result each time it's invoked, and it does not directly interact with the browser.</p>\n<p>If you need to interact with the browser, perform your work in <code class=\"language-text\">componentDidMount()</code> or the other lifecycle methods instead. Keeping <code class=\"language-text\">render()</code> pure makes components easier to think about.</p>\n<blockquote>\n<p><em>Note</em></p>\n<p><code class=\"language-text\">* will not be invoked if* [</code>](https://reactjs.org/docs/react-component.html#shouldcomponentupdate) <em>returns false.</em></p>\n</blockquote>\n<p>The export statement at the bottom of the file also stays, completely unchanged. Our class component will thus look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">BasicClassComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>Hello World<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> BasicClassComponent<span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Notice that our <code class=\"language-text\">BasicClassComponent</code> inherits from the base <code class=\"language-text\">Component</code> class that we imported from the React library, by virtue of the 'extends' keyword.</strong></p>\n<p><em>That being said, there's nothing in this minimal component that takes advantage of any of those inherited methods.</em></p>\n<p><strong>All we have is a method on our component class called <code class=\"language-text\">render</code> that returns the same div tag.</strong></p>\n<p>If we really were deciding between whether to use a functional component versus a class component to render a simple div tag, then the functional style is more appropriate to use.</p>\n<p>This is because class components are much better suited for handling component state and triggering events based on the component's [lifecycle.](https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/)</p>\n<h3>The important takeaways at this point are that there are two types of components, functional and class components, and that functional components are well-suited if you're just looking to render some HTML. <a id=\"66ab\"></h3>\n</a>\n<p><em>Class components, on the other hand, are much better suited for handling components that require more complex functionality, need to exhibit more varied behavior, and/or need to keep track of some state that may change throughout said component's lifecycle.</em></p>\n<h2>A Class Component with Some State <a id=\"da0a\"></h2>\n</a>\n<p><strong>Component state is any dynamic data that we want the component to keep track of.</strong></p>\n<blockquote>\n<p>For example, let's say we have a form component. This form has some input fields that we'd like users to fill out. When a user types characters into an input field, how is that input persisted from the point of view of our form component?</p>\n</blockquote>\n<p><strong>The answer is by using component state!</strong></p>\n<p>There are a few important concepts regarding component state, such as how to update it, pass it to another component, render it, etc.</p>\n<p><strong>Only class components have the ability to persist state, so if at any time you realize that a component needs to keep track of some state, you know that you'll automatically need a class component instead of a functional component.</strong></p>\n<blockquote>\n<p>It is possible to handle state with functional components but that requires the use of something called the [useState() hook](https://reactjs.org/docs/hooks-state.html). Hooks were added in React 16.8; prior to this release, there was no mechanism to add state to functional components.</p>\n</blockquote>\n<p>Here's what the above component looks like as a functional component:</p>\n<p>Our class component with state will look a lot like the basic class component we just wrote, but with some exceptions:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ClassComponentWithState</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>Hello World<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ClassComponentWithState<span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>So far, the only new thing going on here is the constructor block. If you recall how classes in JavaScript work, classes need constructors.</strong></p>\n<p><strong>Additionally, if a class is extending off of another class and wants access to its parent class's methods and properties, then the <code class=\"language-text\">super</code> function needs to be called inside the class's constructor function.</strong></p>\n<h3>Point being, the constructor function and the call to the <code class=\"language-text\">super</code> function are <em>not</em> associated with React, they are associated with all JavaScript classes. <a id=\"7791\"></h3>\n</a>\n<ul>\n<li>Then there is the ``** property inside the constructor function that is set as an empty object**.</li>\n<li>We're adding a property called <code class=\"language-text\">state</code> to our class and setting it to an empty object.</li>\n</ul>\n<h3>State objects in React are always just plain old objects. <a id=\"2e40\"></h3>\n</a>\n<h3><strong>So why is it that the basic class component we wrote in the previous exercise had no constructor function within its body?</strong> <a id=\"a76e\"></h3>\n</a>\n<p>That is because we had no need for them since all our class component was doing was rendering some HTML.</p>\n<p><strong>The constructor is needed here because that is where we need to initialize our state object.</strong></p>\n<p><strong>The call to <code class=\"language-text\">super</code> is needed because we can't reference <code class=\"language-text\">this</code> inside of our constructor without a call to <code class=\"language-text\">super</code> first.</strong></p>\n<p>Ok, now let's actually use this state object.</p>\n<p><em>One very common application of state objects in React components is to render the data being stored inside them within our component's render function.</em></p>\n<h3>Refactoring our component class to do that: <a id=\"6929\"></h3>\n</a>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ClassComponentWithState</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">someData</span><span class=\"token operator\">:</span> <span class=\"token number\">8</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Here's some data to render: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>someData<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ClassComponentWithState<span class=\"token punctuation\">;</span></code></pre></div>\n<p>We added a key-value pair to our state object inside our constructor.</p>\n<ul>\n<li>Then we changed the contents of the render function.</li>\n<li>Now, it's actually rendering the data that we have inside the state object.</li>\n<li>Notice that inside the div tags we're using a template string literal so that we can access the value of <code class=\"language-text\">this.state.someData</code> straight inside of our rendered content.</li>\n</ul>\n<p><strong>With Reacts newest version, we can actually now add state to a component without explicitly defining a constructor on the class. We can refactor our class component to look like this:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ClassComponentWithState</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">someData</span><span class=\"token operator\">:</span> <span class=\"token number\">8</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Here's some data to render: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>someData<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ClassComponentWithState<span class=\"token punctuation\">;</span></code></pre></div>\n<p><img src=\"https://miro.medium.com/max/3064/1*6sYhFUNpUkt6xN9kkn4pJQ.png\" alt=\"medium blog image\"></p>\n<p>This new syntax is what is often referred to as 'syntactic sugar': under the hood, the React library translates this back into the old constructor code that we first started with, so that the JavaScript remains valid to the JavaScript interpreter.</p>\n<p>The clue to this is the fact that when we want to access some data from the state object, we still need to call it with <code class=\"language-text\">this.state.someData</code> ; changing it to just <code class=\"language-text\">state.someData</code> does not work.</p>\n<h2>Class Component Updating State <a id=\"3e29\"></h2>\n</a>\n<p>Great, so we can render some state that our component persists for us.</p>\n<p>However, we said an important use case of component state is to handle <em>dynamic</em> data.</p>\n<p>A single static number isn't very dynamic at all.</p>\n<p>So now let's walk through how to update component state.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ClassComponentUpdatingState</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">aNumber</span><span class=\"token operator\">:</span> <span class=\"token number\">8</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function-variable function\">increment</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">aNumber</span><span class=\"token operator\">:</span> <span class=\"token operator\">++</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>aNumber <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function-variable function\">decrement</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">aNumber</span><span class=\"token operator\">:</span> <span class=\"token operator\">--</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>aNumber <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Our number: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>aNumber<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>increment<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token operator\">+</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>decrement<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token operator\">-</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ClassComponentUpdatingState<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Notice that we've added two methods to our class: <code class=\"language-text\">increment</code> and <code class=\"language-text\">decrement</code> .</p>\n<p><code class=\"language-text\">increment</code> and <code class=\"language-text\">decrement</code> are methods that <em>we</em> are adding to our class component.</p>\n<p>Unlike the <code class=\"language-text\">render</code> method, <code class=\"language-text\">increment</code> and <code class=\"language-text\">decrement</code> were not already a part of our class component.</p>\n<p>This is why <code class=\"language-text\">increment</code> and <code class=\"language-text\">decrement</code> are written as arrow functions, <strong><em>so that they are automatically bound to our class component.</em></strong></p>\n<p>The alternative is using a declaration syntax function with the bind method to bind the context of our methods to the class component.</p>\n<p>The more interesting thing is what is going on within the bodies of these methods.</p>\n<h3>Each calls the <code class=\"language-text\">setState</code> function. <a id=\"3d7e\"></h3>\n</a>\n<ul>\n<li><code class=\"language-text\">setState</code> in fact <em>is</em> provided to us by React.</li>\n</ul>\n<p>It is the standard way to update a component's state.</p>\n<p>It's the <em>only</em> way you should ever update a component's state. It may seem more verbose than necessary, but there are good reasons for why you should be doing it this way.</p>\n<p>Unlike the lifecycle methods above (which React calls for you), the methods below are the methods <em>you</em> can call from your components.</p>\n<p>There are just two of them: <code class=\"language-text\">setState()</code> and <code class=\"language-text\">forceUpdate()</code>.</p>\n<h4><code class=\"language-text\">setState()</code></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">setState(updater, [callback])</code></pre></div>\n<p><code class=\"language-text\">setState()</code> enqueues changes to the component state and tells React that this component and its children need to be re-rendered with the updated state. This is the primary method you use to update the user interface in response to event handlers and server responses.</p>\n<p>Think of <code class=\"language-text\">setState()</code> as a <em>request</em> rather than an immediate command to update the component. For better perceived performance, React may delay it, and then update several components in a single pass. React does not guarantee that the state changes are applied immediately.</p>\n<p><code class=\"language-text\">setState()</code> does not always immediately update the component. It may batch or defer the update until later. This makes reading <code class=\"language-text\">this.state</code> right after calling <code class=\"language-text\">setState()</code> a potential pitfall. Instead, use <code class=\"language-text\">componentDidUpdate</code> or a <code class=\"language-text\">setState</code> callback (<code class=\"language-text\">setState(updater, callback)</code>), either of which are guaranteed to fire after the update has been applied. If you need to set the state based on the previous state, read about the <code class=\"language-text\">updater</code> argument below.</p>\n<p><code class=\"language-text\">setState()</code> will always lead to a re-render unless <code class=\"language-text\">shouldComponentUpdate()</code> returns <code class=\"language-text\">false</code>. If mutable objects are being used and conditional rendering logic cannot be implemented in <code class=\"language-text\">shouldComponentUpdate()</code>, calling <code class=\"language-text\">setState()</code> only when the new state differs from the previous state will avoid unnecessary re-renders.</p>\n<p>The first argument is an <code class=\"language-text\">updater</code> function with the signature:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(state, props) => stateChange</code></pre></div>\n<p><code class=\"language-text\">state</code> is a reference to the component state at the time the change is being applied. It should not be directly mutated. Instead, changes should be represented by building a new object based on the input from <code class=\"language-text\">state</code> and <code class=\"language-text\">props</code>. For instance, suppose we wanted to increment a value in state by <code class=\"language-text\">props.step</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.setState((state, props) => {\n  return {counter: state.counter + props.step};\n});</code></pre></div>\n<p>Both <code class=\"language-text\">state</code> and <code class=\"language-text\">props</code> received by the updater function are guaranteed to be up-to-date. The output of the updater is shallowly merged with <code class=\"language-text\">state</code>.</p>\n<p>The second parameter to <code class=\"language-text\">setState()</code> is an optional callback function that will be executed once <code class=\"language-text\">setState</code> is completed and the component is re-rendered. Generally we recommend using <code class=\"language-text\">componentDidUpdate()</code> for such logic instead.</p>\n<p>You may optionally pass an object as the first argument to <code class=\"language-text\">setState()</code> instead of a function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">setState(stateChange[, callback])</code></pre></div>\n<p>This performs a shallow merge of <code class=\"language-text\">stateChange</code> into the new state, e.g., to adjust a shopping cart item quantity:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.setState({quantity: 2})</code></pre></div>\n<p>This form of <code class=\"language-text\">setState()</code> is also asynchronous, and multiple calls during the same cycle may be batched together. For example, if you attempt to increment an item quantity more than once in the same cycle, that will result in the equivalent of:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object.assign(\n  previousState,\n  {quantity: state.quantity + 1},\n  {quantity: state.quantity + 1},\n  ...\n)</code></pre></div>\n<p>Subsequent calls will override values from previous calls in the same cycle, so the quantity will only be incremented once. If the next state depends on the current state, we recommend using the updater function form, instead:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.setState((state) => {\n  return {quantity: state.quantity + 1};\n});</code></pre></div>\n<h3>So the way to use <code class=\"language-text\">setState</code> to update a component's state is to pass it an object with each of the state keys you wish to update, along with the updated value. <a id=\"bd27\"></h3>\n</a>\n<p>In our <code class=\"language-text\">increment</code> method we said \"I would like to update the <code class=\"language-text\">aNumber</code> property on my component state by adding one to it and then setting the new value as my new <code class=\"language-text\">aNumber</code> \".</p>\n<p>The same thing happens in our <code class=\"language-text\">decrement</code> method, only we're subtracting instead of adding.</p>\n<p>Then the other new concept we're running into here is how to actually call these methods we've added to our class.<img src=\"https://miro.medium.com/max/60/1*k8t5QBcMvHDX521sd4pC4g.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/856/1*k8t5QBcMvHDX521sd4pC4g.png\" alt=\"medium blog image\"></p>\n<p>We added two HTML button tags within our <code class=\"language-text\">render</code> function, then in their respective <code class=\"language-text\">onClick</code> handlers, we specify the method that should be called whenever this button gets clicked. So whenever we click either of the buttons, our state gets updated appropriately and our component will re-render to show the correct value we're expecting.</p>\n<h2>Class Component Iterating State <a id=\"e859\"></h2>\n</a>\n<p>Another common state pattern you'll see being used in React components is iterating over an array in our state object and rendering each array element in its own tag.</p>\n<blockquote>\n<p>This is often used in order to render lists.</p>\n</blockquote>\n<p>Additionally, we want to be able to easily update lists and have React re-render our updated list.</p>\n<p>We'll see how both of these are done and how they work together within a single component in order to create the behavior of a dynamic list.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ClassComponentIteratingState</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">ingredients</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'flour'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'eggs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'milk'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'sugar'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'vanilla extract'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">newIngredient</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function-variable function\">handleIngredientInput</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">newIngredient</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function-variable function\">addIngredient</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        event<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> ingredientsList <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>ingredients<span class=\"token punctuation\">;</span>\n        ingredientsList<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>newIngredient<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">newIngredient</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">ingredients</span><span class=\"token operator\">:</span> ingredientsList\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>ingredients<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">ingredient</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>ingredient<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>form onSubmit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>addIngredient<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleIngredientInput<span class=\"token punctuation\">}</span> placeholder<span class=\"token operator\">=</span><span class=\"token string\">\"Add a new ingredient\"</span> value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>newIngredient<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ClassComponentIteratingState<span class=\"token punctuation\">;</span></code></pre></div>\n<p>The first change to note is that our state object now has an 'ingredients' array, and a 'newIngredient' field that has been initialized to an empty string.</p>\n<p>The ingredients array contains the elements that we'll want to render in our list.</p>\n<p>The <code class=\"language-text\">addIngredient</code> and <code class=\"language-text\">handleIngredientInput</code> methods we've added to our class receives a parameter called 'event'.</p>\n<p>This event object is part of the browser's API.</p>\n<p>When we interact with some DOM element, <strong>such as clicking on an HTML button, the</strong> <strong><em>function that is invoked upon that button being clicked</em></strong> <strong>actually receives the event object.</strong></p>\n<ul>\n<li>So when we type some input into an input tag, we're able grab each character that was typed into the input field through the event object parameter.</li>\n<li>The <code class=\"language-text\">handleIngredientInput</code> method is what gets invoked every time the user presses a key to enter text in the input box for adding a new ingredient.</li>\n<li>Every character the user types gets persisted in the <code class=\"language-text\">newIngredient</code> field on the state object.</li>\n</ul>\n<p>We're able to grab the text in the input box using <code class=\"language-text\">event.target.value</code></p>\n<p><strong>Which holds the value of the string text that is currently in the input box</strong>.</p>\n<blockquote>\n<p>We use that to update our <code class=\"language-text\">newIngredient</code> string field.</p>\n</blockquote>\n<p>Breaking down the <code class=\"language-text\">addIngredient</code> method, we see this <code class=\"language-text\">event.preventDefault()</code> invocation.</p>\n<p>This is because this method will be used upon submitting a form, and it turns out that submitting a form triggers some default form behavior that we don't want to trigger when we submit the form (<strong>namely refreshing the entire page</strong>).</p>\n<blockquote>\n<p><code class=\"language-text\">event.preventDefault()</code> will prevent this default form behavior, meaning our form will only do what we want it to do when it is submitted.</p>\n</blockquote>\n<p><img src=\"https://miro.medium.com/max/894/1*RN_y7Bk4tb-LLG8vNqGHHA.png\" alt=\"medium blog image\"></p>\n<p>Next, we store a reference to <code class=\"language-text\">this.state.ingredients</code> in a variable called <code class=\"language-text\">ingredientsList</code> .</p>\n<p>So we now have a copy of the array that is stored in our state object.</p>\n<p><strong>We want to update the copy of the ingredients array first instead of directly updating the actual array itself in state.</strong></p>\n<p>Now we push whatever value is being stored at our <code class=\"language-text\">newIngredient</code> field onto the <code class=\"language-text\">ingredientsList</code> array so that our <code class=\"language-text\">ingredientsList</code> array is now more up-to-date than our <code class=\"language-text\">this.state.ingredients</code> array.</p>\n<p>So all we have to do now is call <code class=\"language-text\">setState</code> appropriately in order to update the value in our state object.</p>\n<p>Additionally, we also set the <code class=\"language-text\">newIngredient</code> field back to an empty string in order to clear out the input field once we submit a new ingredient.</p>\n<p>Now it's ready to accept more user input!</p>\n<p><img src=\"https://miro.medium.com/max/60/1*LXx7WeP_5wFRfYa45snSEA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/478/1*LXx7WeP_5wFRfYa45snSEA.png\" alt=\"medium blog image\"></p>\n<p>Looking at our render function, first note the <code class=\"language-text\">this.state.ingredients.map</code> call.</p>\n<p>This is looping through each ingredient in our <code class=\"language-text\">ingredients</code> array and returning each one within its own div tag.</p>\n<p>This is a very common pattern for rendering everything inside an array.</p>\n<p>Then we have an HTML form which contains an input field.</p>\n<p>The purpose of this form is to allow a user to add new ingredients to the list. Note that we're passing our <code class=\"language-text\">addIngredient</code> method to the form's <code class=\"language-text\">onSubmit</code> handler.</p>\n<p>This means that our <code class=\"language-text\">addIngredient</code> method gets invoked whenever our form is submitted.</p>\n<p>Lastly, the input field has an <code class=\"language-text\">onChange</code> handler that invokes our <code class=\"language-text\">handleIngredientInput</code> method whenever there is some sort of change in the input field, namely when a user types into it.<img src=\"https://miro.medium.com/max/60/1*S7s9FfaPVlKGyaSwFeId_w.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/816/1*S7s9FfaPVlKGyaSwFeId_w.png\" alt=\"medium blog image\"></p>\n<p>Notice that the <code class=\"language-text\">value</code> field in our input tag reads off of <code class=\"language-text\">this.state.newIngredient</code> in order to know what value to display.</p>\n<p>So when a user enters text into the input field, the <code class=\"language-text\">onChange</code> handler is invoked every time, which updates our <code class=\"language-text\">this.state.newIngredient</code> field, which the input field and then renders.</p>\n<h2>Parent and Child Components <a id=\"413c\"></h2>\n</a>\n<p>A single isolated component isn't going to do us much good.</p>\n<blockquote>\n<p>The beauty of React lies in the fact that it allows us to compose modular components together.</p>\n<p>Let's start off with the component we just saw, but let's change its name to `` .</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ChildComponent <span class=\"token keyword\">from</span> <span class=\"token string\">'./ChildComponent'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ParentComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">ingredients</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'flour'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'eggs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'milk'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'sugar'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'vanilla'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">newIngredient</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function-variable function\">handleIngredientInput</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">newIngredient</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function-variable function\">addIngredient</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        event<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> ingredientsList <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>ingredients<span class=\"token punctuation\">;</span>\n        ingredientsList<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>newIngredient<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">newIngredient</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">ingredients</span><span class=\"token operator\">:</span> ingredientsList\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>ingredients<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">ingredient</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>ChildComponent thing<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>ingredient<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>form onSubmit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>addIngredient<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleIngredientInput<span class=\"token punctuation\">}</span> placeholder<span class=\"token operator\">=</span><span class=\"token string\">\"Add a new ingredient\"</span> value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>newIngredient<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ParentComponent<span class=\"token punctuation\">;</span></code></pre></div>\n<p>The only two other differences in this component are that we're importing a <code class=\"language-text\">ChildComponent</code> and then using it inside our <code class=\"language-text\">this.state.ingredients.map</code> call.</p>\n<p><code class=\"language-text\">ChildComponent</code> is another React component.</p>\n<p>Notice that we're using it just as if it were any other HTML tag.</p>\n<p><strong>This is how we lay out our component hierarchy: the ChildComponent is rendered within the ParentComponent.</strong></p>\n<p>We can see this to be the case if we open up the developer console and inspect these elements.<strong>child-left: parent-right</strong></p>\n<p><img src=\"https://miro.medium.com/max/2602/1*q_XLnJ2h1L5yZjNnSKzj5w.png\" alt=\"medium blog image\"></p>\n<p>Note also that we're passing each ingredient as a 'thing' to the ChildComponent component.</p>\n<p>This is how a parent component passes data to a child component. It doesn't need to be called 'thing'; you can call it whatever you want.</p>\n<p>Conceptually though, <strong>every piece of data that a parent component passes down to a child component is called a 'prop' in React lingo.</strong></p>\n<p>Let's take a look now at the Child Component. It serves two purposes:</p>\n<ol>\n<li>to render the props data that it gets from a parent component,</li>\n<li>to add the ability for a user to click on it and have it toggle a strikethrough, indicating that the item is 'complete'.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ChildComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">clicked</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function-variable function\">handleClick</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">clicked</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>clicked <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> styles <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>clicked <span class=\"token operator\">?</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">textDecoration</span><span class=\"token operator\">:</span> <span class=\"token string\">'line-through'</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">textDecoration</span><span class=\"token operator\">:</span> <span class=\"token string\">'none'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>styles<span class=\"token punctuation\">}</span> onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>thing<span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> ChildComponent<span class=\"token punctuation\">;</span></code></pre></div>\n<p>The overall structure of the child component is nothing we haven't seen. It's just another class component with its own s<strong>tate object and a method called <code class=\"language-text\">handleClick</code> .</strong></p>\n<p><strong>A component accesses its props via the <code class=\"language-text\">this.props</code> object.</strong></p>\n<p><em>Any prop a parent component passes down to a child component is accessible inside the child component's <code class=\"language-text\">this.prop</code> object.</em></p>\n<p>So our child component keeps its own state that tracks whether the component has been clicked or not.</p>\n<p>Then at the top of the <code class=\"language-text\">render</code> function, it uses a ternary condition to determine whether the div tag that is being rendered should have a strikethrough or not.</p>\n<p>The <code class=\"language-text\">handleClick</code> method is then invoked via an <code class=\"language-text\">onClick</code> handler on the div tag; it does the work of toggling the <code class=\"language-text\">this.state.clicked</code> Boolean.</p>\n<p>The overall structure of React applications can be represented as a hierarchical tree structure, just like how the DOM itself is structure. There is an overarching root component at the top of the hierarchy that every other component sits underneath. Specifying that a component should be a child of some parent component is as simple as throwing it in the parent component's render function, just like how we did it in this example<img src=\"https://miro.medium.com/max/60/0*aqqfHMjBXT8PWYJC?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/490/0*aqqfHMjBXT8PWYJC\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1000/0*j9aPKza7Y4htBeQ-.gif\" alt=\"medium blog image\"></p>\n<h2><strong>Core Concepts:</strong> <a id=\"c45d\"></h2>\n</a>\n<h3>1. What is react? <a id=\"068e\"></h3>\n</a>\n<h3>React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It uses components to update and render as your data changes. <a id=\"a7cb\"></h3>\n</a>\n<blockquote>\n<p>React manages the <strong>creation and continuous updating of DOM nodes in your Web page</strong>.</p>\n</blockquote>\n<ul>\n<li><em>It does not handle</em> [<em>AJAX</em> ](https://skillcrush.com/blog/what-is-ajax/)<em>requests, Local Storage or style your website. IT is just a tool to dynamically render content on a webpage as a result of changes in 'state'. Because it's function is so limited in scope you may hear it referred to as a library… (not a framework … like Angular for example) and you may also hear it described as unopinionated.</em></li>\n</ul>\n<h3>2. Why use react? <a id=\"643d\"></h3>\n</a>\n<ul>\n<li>Works for teams and helps UI workflow patterns</li>\n<li>The components can be reusable</li>\n<li>Componentized UI is the future of web dev</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*pFe_v7Ea--vfdmvR3UcunA.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/846/1*pFe_v7Ea--vfdmvR3UcunA.png\" alt=\"medium blog image\"></p>\n<h2>Declarative programming <a id=\"994b\"></h2>\n</a>\n<p>In the same way that you use HTML to <em>declare</em> what the user interface should<br>\nlook like, React provides the same mechanism in its `` method or the higher-level language known as JSX.<img src=\"https://miro.medium.com/max/60/0*MW-A5Dp_v1T0BB1s.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1338/0*MW-A5Dp_v1T0BB1s.png\" alt=\"medium blog image\">React… like HTML is Declarative</p>\n<p>[Declarative programming](https://en.wikipedia.org/wiki/Declarative<em>programming) is often defined as any style of programming that is not [imperative](https://en.wikipedia.org/wiki/Imperative</em>programming).</p>\n<p>A number of other common definitions attempt to define it by simply contrasting it with imperative programming. For example:</p>\n<ul>\n<li>A high-level program that describes what a computation should perform.</li>\n<li>Any programming language that lacks [side effects](https://en.wikipedia.org/wiki/Side<em>effect</em>%28computer_science%29)</li>\n<li>A language with a clear correspondence to [mathematical logic](https://en.wikipedia.org/wiki/Mathematical<em>logic).[[5]](https://en.wikipedia.org/wiki/Declarative</em>programming#cite_note-5)</li>\n</ul>\n<p>These definitions overlap substantially.</p>\n<p>D<strong>eclarative programming is a non-imperative style of programming in which programs describe their desired results without explicitly listing commands or steps that must be performed.</strong></p>\n<p>[Functional](https://en.wikipedia.org/wiki/Functional<em>programming) and [logical programming](https://en.wikipedia.org/wiki/Logical</em>programming) languages are characterized by a declarative programming style.</p>\n<p><em>In a</em> [<em>pure functional language</em>](https://en.wikipedia.org/wiki/Pure<em>functional</em>language)<em>, such as</em> [<em>Haskell</em>](https://en.wikipedia.org/wiki/Haskell<em>%28programming</em>language%29)<em>, all functions are</em> [<em>without side effects</em>](https://en.wikipedia.org/wiki/Pure<em>function)</em>, and state changes are only represented as functions that transform the state, which is explicitly represented as a_ [<em>first-class</em>](https://en.wikipedia.org/wiki/First-class<em>citizen) _object in the program.</em></p>\n<p>— Wikipedia</p>\n<h2>What is a React pure component? <a id=\"abbb\"></h2>\n</a>\n<p>[Based on the concept of purity in functional programming paradigms, a function is said to be pure if:](https://blog.logrocket.com/react-pure-components-functional/#whatisareactpurecomponent)</p>\n<ul>\n<li>Its return value is only determined by its input values</li>\n<li>Its return value is always the same for the same input values</li>\n</ul>\n<p>A React component is considered pure if it renders the same output for the same state and props. For class components like this, React provides the <code class=\"language-text\">PureComponent</code> base class. Class components that extend the <code class=\"language-text\">React.PureComponent</code> class are treated as pure components.</p>\n<p>Pure components have some performance improvements and render optimizations since React implements the <code class=\"language-text\">shouldComponentUpdate()</code> method for them with a shallow comparison for props and state.</p>\n<h2>Are React functional components pure? <a id=\"e24e\"></h2>\n</a>\n<p>Functional components are very useful in React, especially when you want to isolate state management from the component. That's why they are often called stateless components.</p>\n<p>However, functional components cannot leverage the performance improvements and render optimizations that come with <code class=\"language-text\">React.PureComponent</code> since they are not classes by definition.</p>\n<p>If you want React to treat a functional component as a pure component, you'll have to convert the functional component to a class component that extends <code class=\"language-text\">React.PureComponent</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">PercentageStat</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> label<span class=\"token punctuation\">,</span> score <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> total <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> score<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>h6<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>label<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h6<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>span<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">round</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>score <span class=\"token operator\">/</span> total<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">%</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// CONVERTED TO PURE COMPONENT</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">PercentageStat</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>PureComponent</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> label<span class=\"token punctuation\">,</span> score <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> total <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> score<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>h6<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>label<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h6<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>span<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">round</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>score <span class=\"token operator\">/</span> total<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">%</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Reusability <a id=\"9c36\"></h2>\n</a>\n<p>React encourages you to think in terms of reusability as you construct the user<br>\ninterface from elements and components that you create. When you<br>\nmake a list or a button, you can then reuse those components to show different data 'state' in the same UI structure as you have built for different data previously.<img src=\"https://miro.medium.com/max/60/0*cBLQ5aBP2qihrT59.jpeg?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1885/0*cBLQ5aBP2qihrT59.jpeg\" alt=\"medium blog image\"></p>\n<h3>Component-Based <a id=\"a38d\"></h3>\n</a>\n<p>Build encapsulated components that manage their own state, then compose them to make complex UIs.</p>\n<p>Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.</p>\n<h3>Learn Once, Write Anywhere <a id=\"fc7f\"></h3>\n</a>\n<p>We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code.</p>\n<p>React can also render on the server using Node and power mobile apps using [React Native](https://reactnative.dev/).</p>\n<h2>Speed <a id=\"345f\"></h2>\n</a>\n<p>Due to the use of a virtual DOM, React handles changes to a Web page more<br>\nintelligently than just string manipulation. It is constantly monitors the<br>\nvirtual DOM for changes. It very efficiently reconciles changes in the virtual<br>\nDOM with what it has already produced in the real DOM. This is what<br>\nmakes React one of the speediest front-end libraries available.<img src=\"https://miro.medium.com/max/60/0*OdOq6pmpXBJhjj7k.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/810/0*OdOq6pmpXBJhjj7k.png\" alt=\"medium blog image\"></p>\n<h3>3. Who uses react? <a id=\"c395\"></h3>\n</a>\n<ul>\n<li>Companies such as Facebook app for android and Instagram</li>\n<li>[Here](https://facebook.github.io/react-native/showcase.html) is a link to a list of other companies who use react.</li>\n</ul>\n<p><img src=\"https://miro.medium.com/max/60/1*Cn9JvaSmkxdLwgXIO9Y8iQ.png?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1027/1*Cn9JvaSmkxdLwgXIO9Y8iQ.png\" alt=\"medium blog image\">Who uses react</p>\n<h3>4. Setting up react <a id=\"ba44\"></h3>\n</a>\n<ul>\n<li>React can be set up in CodePen for quick practice development by adding react.js, react-dom and babel.</li>\n<li>It can also be set up by downloading a react starter project from GitHub installing node and following these [instructions](https://github.com/hjb23/ReduxSimpleStarter).</li>\n<li>Alternatively it can be set up through NPM like [this](https://www.codementor.io/tamizhvendan/beginner-guide-setup-reactjs-environment-npm-babel-6-webpack-du107r9zr).</li>\n</ul>\n<h3>5. Intro to eco system <a id=\"6ef8\"></h3>\n</a>\n<ul>\n<li>Composition, being able to wrap up sections of code into there own containers so they can be re used.</li>\n<li>How to make a large application? by combining small components to create a larger complex application.</li>\n</ul>\n<h3>6. Imperative vs Declarative [(React is Declarative)](https://medium.com/trabe/why-is-react-declarative-a-story-about-function-components-aaae83198f79) <a id=\"ea7a\"></h3>\n</a>\n<ul>\n<li><strong>Imperative, 'telling to computer HOW to do something' e.g looping over an array of numbers using a for loop.</strong></li>\n<li><strong>Declarative, is concerned about WHAT we want to happen. e.g using a reduce method on an array.</strong></li>\n<li>Benefits of using declarative code:</li>\n<li>Reduce side effects</li>\n<li>Minimize mutability</li>\n<li>Less Bugs</li>\n</ul>\n<h3>7. Unidirectional Data Flow <a id=\"e6f2\"></h3>\n</a>\n<ul>\n<li>As the state collects from user interaction, the UI gets updated.</li>\n<li>Explicit Mutations</li>\n<li>Whenever the state needs to be updated in our application setState has to be called.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.setState({\n  highlight: !this.state.highlight,\n})</code></pre></div>\n<h3>7.1. First component <a id=\"d1c5\"></h3>\n</a>\n<ul>\n<li>Components are the building blocks of React.</li>\n<li>They are similar to a collection of HTML,CSS, JS and data specific to that component.</li>\n<li>They can be defined in pure JavaScript or JSX.</li>\n<li>Data is either received from a component's parent component, or it's contained in the component itself.</li>\n<li>Applications can be separated into smaller components like this…</li>\n<li>React components can be created using ES6 class like this.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react';class Hello extends React.Component {\n  render () {\n    return &lt;h1>Hello, {this.props.name}!&lt;/h1>;\n  }\n}export default Hello;</code></pre></div>\n<ul>\n<li>At the top with have the code to bring react and react dom libraries in.</li>\n<li>React library is used for the react syntax.</li>\n<li>React DOM is used to update the DOM.</li>\n<li>We then have the Class section which creates the component.</li>\n<li>Render() describes the specific UI for the component.</li>\n<li>Return is used to return the JSX</li>\n<li>And Finally ReactDOM.render is used to update the DOM.</li>\n</ul>\n<h3>8. Data flow with props <a id=\"91ff\"></h3>\n</a>\n<p>Small examples of data flow, see if you can get the code to work.</p>\n<p>&#x3C;https://codepen.io/bgoonz/embed/WNpoLbg?default-tab=&#x26;theme-id=></p>\n<p>{% embed url=\"https://codepen.io/bgoonz/embed/BaWQGQp?default-tab=&#x26;theme-id=\" %}</p>\n<h3>9. Creating lists with map <a id=\"6790\"></h3>\n</a>\n<p>{% embed url=\"https://codepen.io/bgoonz/embed/XWMNoJr?default-tab=&#x26;theme-id=\" %}</p>\n<p>The parent component passes down to the child component as props.</p>\n<p>Using props to access names and map to loop through each list item. Then passing this by using props.</p>\n<p>{% embed url=\"https://codepen.io/bgoonz/embed/gOmLZbX?default-tab=&#x26;theme-id=\" %}</p>\n<p>Checking data to see if Boolean is true then adding detail to the list.</p>\n<p>{% embed url=\"https://codepen.io/bgoonz/embed/WNpoLbg?default-tab=&#x26;theme-id=\" %}</p>\n<h3>10. Prop types <a id=\"18ed\"></h3>\n</a>\n<p>PropTypes allow you to declare the type (string, number, function, etc) of each prop being passed to a component. Then if a prop passed in isn't of the declared type you'll get a warning in the console.</p>\n<h2>Excerpt from the React website: <a id=\"7094\"></h2>\n</a>\n<h2>React — A JavaScript library for building user interfaces <a id=\"5047\"></h2>\n</a>\n<blockquote>\n<p><em>A JavaScript library for building user interfaces</em></p>\n</blockquote>\n<h3>Declarative <a id=\"cae4\"></h3>\n</a>\n<p>React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.</p>\n<p>Declarative views make your code more predictable and easier to debug.</p>\n<h3>A Simple Component <a id=\"b36a\"></h3>\n</a>\n<p>React components implement a <code class=\"language-text\">render()</code> method that takes input data and returns what to display. This example uses an XML-like syntax called JSX. Input data that is passed into the component can be accessed by <code class=\"language-text\">render()</code> via <code class=\"language-text\">this.props</code>.</p>\n<p>JSX is optional and not required to use React. Try the [Babel REPL](https://babeljs.io/repl/#?presets=react&#x26;code<em>lz=MYewdgzgLgBApgGzgWzmWBeGAeAFgRgD4AJRBEAGhgHcQAnBAEwEJsB6AwgbgChRJY</em>KAEMAlmDh0YWRiGABXVOgB0AczhQAokiVQAQgE8AkowAUAcjogQUcwEpeAJTjDgUACIB5ALLK6aRklTRBQ0KCohMQk6Bx4gA) to see the raw JavaScript code produced by the JSX compilation step.</p>\n<p>In addition to taking input data (accessed via <code class=\"language-text\">this.props</code>), a component can maintain internal state data (accessed via <code class=\"language-text\">this.state</code>). When a component's state data changes, the rendered markup will be updated by re-invoking <code class=\"language-text\">render()</code>.</p>\n<h3>An Application <a id=\"2936\"></h3>\n</a>\n<p>Using <code class=\"language-text\">props</code> and <code class=\"language-text\">state</code>, we can put together a small Todo application. This example uses <code class=\"language-text\">state</code> to track the current list of items as well as the text that the user has entered. Although event handlers appear to be rendered inline, they will be collected and implemented using event delegation.</p>\n<h3>A Component Using External Plugins <a id=\"2276\"></h3>\n</a>\n<p>React allows you to interface with other libraries and frameworks. This example uses remarkable, an external Markdown library, to convert the <code class=\"language-text\">&lt;textarea></code>'s value in real time.</p>"},{"url":"/docs/react/dont-use-index-as-keys/","relativePath":"docs/react/dont-use-index-as-keys.md","relativeDir":"docs/react","base":"dont-use-index-as-keys.md","name":"dont-use-index-as-keys","frontmatter":{"title":"Index as a key is an anti-pattern","weight":0,"excerpt":"So many times I have seen developers use the index of an item as its key when they render a list.","seo":{"title":"Lists and Keys","description":"Let me explain, a _key_ is the only thing React uses to identify DOM elements. What happens if you push an item to the list or remove something in the middle? If the _key_ is same as before React assumes that the DOM element represents the same component as before. But that is no longer true.","robots":[],"extra":[]},"template":"docs"},"html":"<h2>> ## Excerpt</h2>\n<blockquote>\n</blockquote>\n<hr>\n<h1>Lists and Keys - React</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>A JavaScript library for building user interfaces</p>\n</blockquote>\n<hr>\n<p>First, let's review how you transform lists in JavaScript.</p>\n<p>Given the code below, we use the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map\"><code class=\"language-text\">map()</code></a> function to take an array of <code class=\"language-text\">numbers</code> and double their values. We assign the new array returned by <code class=\"language-text\">map()</code> to the variable <code class=\"language-text\">doubled</code> and log it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const numbers = [1, 2, 3, 4, 5];\nconst doubled = numbers.map((number) => number * 2);console.log(doubled);</code></pre></div>\n<p>This code logs <code class=\"language-text\">[2, 4, 6, 8, 10]</code> to the console.</p>\n<p>In React, transforming arrays into lists of <a href=\"https://reactjs.org/docs/rendering-elements.html\">elements</a> is nearly identical.</p>\n<h3><a href=\"https://reactjs.org/docs/lists-and-keys.html#rendering-multiple-components\"></a>Rendering Multiple Components</h3>\n<p>You can build collections of elements and <a href=\"https://reactjs.org/docs/introducing-jsx.html#embedding-expressions-in-jsx\">include them in JSX</a> using curly braces <code class=\"language-text\">{}</code>.</p>\n<p>Below, we loop through the <code class=\"language-text\">numbers</code> array using the JavaScript <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map\"><code class=\"language-text\">map()</code></a> function. We return a <code class=\"language-text\">&lt;li></code> element for each item. Finally, we assign the resulting array of elements to <code class=\"language-text\">listItems</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const numbers = [1, 2, 3, 4, 5];\nconst listItems = numbers.map((number) =>  &lt;li>{number}&lt;/li>);</code></pre></div>\n<p>We include the entire <code class=\"language-text\">listItems</code> array inside a <code class=\"language-text\">&lt;ul></code> element, and <a href=\"https://reactjs.org/docs/rendering-elements.html#rendering-an-element-into-the-dom\">render it to the DOM</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(\n  &lt;ul>{listItems}&lt;/ul>,  document.getElementById('root')\n);</code></pre></div>\n<p><a href=\"https://codepen.io/gaearon/pen/GjPyQr?editors=0011\"><strong>Try it on CodePen</strong></a></p>\n<p>This code displays a bullet list of numbers between 1 and 5.</p>\n<h3><a href=\"https://reactjs.org/docs/lists-and-keys.html#basic-list-component\"></a>Basic List Component</h3>\n<p>Usually you would render lists inside a <a href=\"https://reactjs.org/docs/components-and-props.html\">component</a>.</p>\n<p>We can refactor the previous example into a component that accepts an array of <code class=\"language-text\">numbers</code> and outputs a list of elements.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function NumberList(props) {\n  const numbers = props.numbers;\n  const listItems = numbers.map((number) =>    &lt;li>{number}&lt;/li>  );  return (\n    &lt;ul>{listItems}&lt;/ul>  );\n}\n\nconst numbers = [1, 2, 3, 4, 5];\nReactDOM.render(\n  &lt;NumberList numbers={numbers} />,  document.getElementById('root')\n);</code></pre></div>\n<p>When you run this code, you'll be given a warning that a key should be provided for list items. A \"key\" is a special string attribute you need to include when creating lists of elements. We'll discuss why it's important in the next section.</p>\n<p>Let's assign a <code class=\"language-text\">key</code> to our list items inside <code class=\"language-text\">numbers.map()</code> and fix the missing key issue.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function NumberList(props) {\n  const numbers = props.numbers;\n  const listItems = numbers.map((number) =>\n    &lt;li key={number.toString()}>      {number}\n    &lt;/li>\n  );\n  return (\n    &lt;ul>{listItems}&lt;/ul>\n  );\n}\n\nconst numbers = [1, 2, 3, 4, 5];\nReactDOM.render(\n  &lt;NumberList numbers={numbers} />,\n  document.getElementById('root')\n);</code></pre></div>\n<p><a href=\"https://codepen.io/gaearon/pen/jrXYRR?editors=0011\"><strong>Try it on CodePen</strong></a></p>\n<h2><a href=\"https://reactjs.org/docs/lists-and-keys.html#keys\"></a>Keys</h2>\n<p>Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const numbers = [1, 2, 3, 4, 5];\nconst listItems = numbers.map((number) =>\n  &lt;li key={number.toString()}>    {number}\n  &lt;/li>\n);</code></pre></div>\n<p>The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const todoItems = todos.map((todo) =>\n  &lt;li key={todo.id}>    {todo.text}\n  &lt;/li>\n);</code></pre></div>\n<p>When you don't have stable IDs for rendered items, you may use the item index as a key as a last resort:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const todoItems = todos.map((todo, index) =>\n    &lt;li key={index}>    {todo.text}\n  &lt;/li>\n);</code></pre></div>\n<p>We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny's article for an <a href=\"https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318\">in-depth explanation on the negative impacts of using an index as a key</a>. If you choose not to assign an explicit key to list items then React will default to using indexes as keys.</p>\n<p>Here is an <a href=\"https://reactjs.org/docs/reconciliation.html#recursing-on-children\">in-depth explanation about why keys are necessary</a> if you're interested in learning more.</p>\n<p>Keys only make sense in the context of the surrounding array.</p>\n<p>For example, if you <a href=\"https://reactjs.org/docs/components-and-props.html#extracting-components\">extract</a> a <code class=\"language-text\">ListItem</code> component, you should keep the key on the <code class=\"language-text\">&lt;ListItem /></code> elements in the array rather than on the <code class=\"language-text\">&lt;li></code> element in the <code class=\"language-text\">ListItem</code> itself.</p>\n<p><strong>Example: Incorrect Key Usage</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function ListItem(props) {\n  const value = props.value;\n  return (\n        &lt;li key={value.toString()}>      {value}\n    &lt;/li>\n  );\n}\n\nfunction NumberList(props) {\n  const numbers = props.numbers;\n  const listItems = numbers.map((number) =>\n        &lt;ListItem value={number} />  );\n  return (\n    &lt;ul>\n      {listItems}\n    &lt;/ul>\n  );\n}\n\nconst numbers = [1, 2, 3, 4, 5];\nReactDOM.render(\n  &lt;NumberList numbers={numbers} />,\n  document.getElementById('root')\n);</code></pre></div>\n<p><strong>Example: Correct Key Usage</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function ListItem(props) {\n    return &lt;li>{props.value}&lt;/li>;}\n\nfunction NumberList(props) {\n  const numbers = props.numbers;\n  const listItems = numbers.map((number) =>\n        &lt;ListItem key={number.toString()} value={number} />  );\n  return (\n    &lt;ul>\n      {listItems}\n    &lt;/ul>\n  );\n}\n\nconst numbers = [1, 2, 3, 4, 5];\nReactDOM.render(\n  &lt;NumberList numbers={numbers} />,\n  document.getElementById('root')\n);</code></pre></div>\n<p><a href=\"https://codepen.io/gaearon/pen/ZXeOGM?editors=0010\"><strong>Try it on CodePen</strong></a></p>\n<p>A good rule of thumb is that elements inside the <code class=\"language-text\">map()</code> call need keys.</p>\n<h3><a href=\"https://reactjs.org/docs/lists-and-keys.html#keys-must-only-be-unique-among-siblings\"></a>Keys Must Only Be Unique Among Siblings</h3>\n<p>Keys used within arrays should be unique among their siblings. However, they don't need to be globally unique. We can use the same keys when we produce two different arrays:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Blog(props) {\n  const sidebar = (    &lt;ul>\n      {props.posts.map((post) =>\n        &lt;li key={post.id}>          {post.title}\n        &lt;/li>\n      )}\n    &lt;/ul>\n  );\n  const content = props.posts.map((post) =>    &lt;div key={post.id}>      &lt;h3>{post.title}&lt;/h3>\n      &lt;p>{post.content}&lt;/p>\n    &lt;/div>\n  );\n  return (\n    &lt;div>\n      {sidebar}      &lt;hr />\n      {content}    &lt;/div>\n  );\n}\n\nconst posts = [\n  {id: 1, title: 'Hello World', content: 'Welcome to learning React!'},\n  {id: 2, title: 'Installation', content: 'You can install React from npm.'}\n];\nReactDOM.render(\n  &lt;Blog posts={posts} />,\n  document.getElementById('root')\n);</code></pre></div>\n<p><a href=\"https://codepen.io/gaearon/pen/NRZYGN?editors=0010\"><strong>Try it on CodePen</strong></a></p>\n<p>Keys serve as a hint to React but they don't get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const content = posts.map((post) =>\n  &lt;Post\n    key={post.id}    id={post.id}    title={post.title} />\n);</code></pre></div>\n<p>With the example above, the <code class=\"language-text\">Post</code> component can read <code class=\"language-text\">props.id</code>, but not <code class=\"language-text\">props.key</code>.</p>\n<h3><a href=\"https://reactjs.org/docs/lists-and-keys.html#embedding-map-in-jsx\"></a>Embedding map() in JSX</h3>\n<p>In the examples above we declared a separate <code class=\"language-text\">listItems</code> variable and included it in JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function NumberList(props) {\n  const numbers = props.numbers;\n  const listItems = numbers.map((number) =>    &lt;ListItem key={number.toString()}              value={number} />  );  return (\n    &lt;ul>\n      {listItems}\n    &lt;/ul>\n  );\n}</code></pre></div>\n<p>JSX allows <a href=\"https://reactjs.org/docs/introducing-jsx.html#embedding-expressions-in-jsx\">embedding any expression</a> in curly braces so we could inline the <code class=\"language-text\">map()</code> result:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function NumberList(props) {\n  const numbers = props.numbers;\n  return (\n    &lt;ul>\n      {numbers.map((number) =>        &lt;ListItem key={number.toString()}                  value={number} />      )}    &lt;/ul>\n  );\n}</code></pre></div>\n<p><a href=\"https://codepen.io/gaearon/pen/BLvYrB?editors=0010\"><strong>Try it on CodePen</strong></a></p>\n<p>Sometimes this results in clearer code, but this style can also be abused. Like in JavaScript, it is up to you to decide whether it is worth extracting a variable for readability. Keep in mind that if the <code class=\"language-text\">map()</code> body is too nested, it might be a good time to <a href=\"https://reactjs.org/docs/components-and-props.html#extracting-components\">extract a component</a>.</p>\n<p>So many times I have seen developers use the <em>index</em> of an item as its <em>key</em> when they render a list.</p>\n<p>todos.map((todo, index) => (<br>\n&#x3C;Todo {...todo} key={index} /><br>\n));<br>\n}</p>\n<p>It looks elegant and it does get rid of the warning (which was the ‘real' issue, right?). What is the danger here?</p>\n<blockquote>\n<p>It may break your application and display wrong data!</p>\n</blockquote>\n<p>Let me explain, a <em>key</em> is the only thing React uses to identify DOM elements. What happens if you push an item to the list or remove something in the middle? If the <em>key</em> is same as before React assumes that the DOM element represents the same component as before. But that is no longer true.</p>\n<p><img src=\"https://miro.medium.com/max/27/1*9N62zUlyJcQet8kr7e_FVg.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*9N62zUlyJcQet8kr7e_FVg.png\" alt=\"medium blog image\"></p>\n<p>Stephen describes the problem he run into on <a href=\"https://egghead.io/forums/lesson-discussion/topics/break-up-components-into-smaller-pieces-using-functional-components#post-6310\">egghead.io</a></p>\n<p>To demonstrate the potential danger I created <a href=\"https://jsbin.com/wohima/edit?output\">a simple example</a> (<a href=\"http://jsbin.com/wohima/edit?js,output\">with source</a>).</p>\n<p><img src=\"https://miro.medium.com/max/630/1*GFYGPdDFLYcLFzx-E-GEcw.jpeg\" alt=\"medium blog image\"></p>\n<p>Screenshot of the example showing the danger of using the index as key.</p>\n<p>It turns out, when nothing is passed React uses the <em>index</em> as <em>key</em> because it is the best guess at the moment. Moreover, it will warn you that it is suboptimal (it says that in a bit confusing words, yes). If you provide it by yourself React just thinks that you know what you are doing which — remember the example — can lead to unpredictable results.</p>\n<h2>Better</h2>\n<p>Each such item should have a <em>permanent</em> and <em>unique</em> property. Ideally, it should be assigned when the item is created. Of course, I am speaking about an <em>id</em>. Then we can use it the following way:</p>\n<p>{<br>\ntodos.map((todo) => (<br>\n&#x3C;Todo {...todo} key={todo.id} /><br>\n));<br>\n}</p>\n<blockquote>\n<p><strong>Note:</strong> First look at the existing properties of the items. It is possible they already have something that can be used as an <em>id</em>.</p>\n</blockquote>\n<p>One way to do so it to just move the numbering one step up in the abstraction. Using a global index makes sure any two items would have different _id_s.</p>\n<p>let todoCounter = 1;const createNewTodo = (text) => ({<br>\ncompleted: false,<br>\nid: todoCounter++,<br>\ntext<br>\n}</p>\n<h2>Much better</h2>\n<p>A production solution should use a more robust approach that would handle a distributed creation of items. For such, I recommend <a href=\"https://github.com/ai/nanoid/\">nanoid</a>. It quickly generates short non-sequential url-friendly unique ids. The code could look like the following:</p>\n<p>import { nanoid } from 'nanoid';const createNewTodo = (text) => ({<br>\ncompleted: false,<br>\nid: nanoid(),<br>\ntext<br>\n}</p>\n<blockquote>\n<p><strong>TL;DR:</strong> Generate a unique <em>id</em> for every item and use it as <em>key</em> when rendering the list.</p>\n</blockquote>\n<h2>Update: Exception from the rule</h2>\n<p>Many people asked if they always, <em>always</em> have to generate ids. Others have suggested use cases when using the index as a key seems justifiable.</p>\n<p>It is true that sometimes generating new ids is redundant and may be avoided. For example translation of license terms or list of contributors.</p>\n<p>To help you decide, I put together three conditions which these examples have in common:</p>\n<ol>\n<li>the list and items are static-they are not computed and do not change;</li>\n<li>the items in the list have no ids;</li>\n<li>the list is <em>never</em> reordered or filtered.</li>\n</ol>\n<p>When <em>all</em> of them are met, you <strong>may safely use the index as a key</strong>.</p>\n<h2>Update 2: React, Preact, and *react</h2>\n<p>Although in this article I write about React, the problem is not exclusive to it. In similar libraries, like Preact, the danger is present, too. However, the effects can be different.</p>\n<p>See the following StackOverflow question, where the last element disappears. Also please note the explanation in the answers provided by the creator of Preact,</p>"},{"url":"/docs/react/","relativePath":"docs/react/index.md","relativeDir":"docs/react","base":"index.md","name":"index","frontmatter":{"title":"React","excerpt":"To make it easy to write documentation in plain Markdown, most React are styled using Markdown elements with few additional CSS classes.","seo":{"title":"React","description":"This is the React page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"React","keyName":"property"},{"name":"og:description","value":"This is the React page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"React"},{"name":"twitter:description","value":"This is the React page"}]},"template":"docs"},"html":"<h1>React</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://onedrive.live.com/embed?cid=D21009FDD967A241&resid=D21009FDD967A241%21600362&authkey=AC6_5JbdGjSF4mU&em=2\" height=\"800px\" width=\"100%\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"   allowfullscreen>\n</iframe>\n<br>\n<h1>Examples</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/react-embeds-w6oec?fontsize=14&hidenavigation=1&theme=dark\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"   allowfullscreen>\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/thirsty-cori-c9qxq?fontsize=14&hidenavigation=1&theme=dark\"\n    height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"   allowfullscreen>\n</iframe>\n<br>\n<h3>For more resources visit:</h3>\n<p><a href=\"https://github.com/bgoonz/React_Notes_V3\">bgoonz/React<em>Notes</em>V3A JavaScript library for building user interfaces React makes it painless to create interactive UIs. Design simple…github.com</a></p>\n<p><a href=\"https://gist.github.com/bgoonz/e07d9e7917ae9e98807358d1e7cc4a67\">Use this appendix to get any prerequisite concepts and terminology under your belt:</a></p>\n<p>Here I will walk through a demo…. skip down below for more fundamental examples and resources…</p>\n<h2>Learn Redux:</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     src=\"https://learning-redux42.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"   allowfullscreen>\n</iframe>\n<br>\n<hr>\n<script src=\"https://gist.github.com/bgoonz/0e9d7ba47f02d41d8cecfd23beecd2b1.js\">\n</script>\n<h2>ALL CODE:</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span></code></pre></div>\n<h2>React Cheat Sheet: <a id=\"8738\"></h2>\n</a>\n<p>React-Tutorial-1:[react-tutorial-1A React repl by bgoonzreplit.com](https://replit.com/@bgoonz/react-tutorial-1)</p>\n<p>React Boilerplate:[React.js + Babel + Webpack BoilerplateCreated by @eankeen | The ultimate trifecta - React, Babel, and Webpack - complete with hot module reloading and a…replit.com](https://replit.com/@bgoonz/Reactjs-Babel-Webpack-Boilerplate#index.js)</p>"},{"url":"/docs/react/render-elements/","relativePath":"docs/react/render-elements.md","relativeDir":"docs/react","base":"render-elements.md","name":"render-elements","frontmatter":{"title":"Rendering Elements With React","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Rendering Elements\n\n</h1>\n<p>Elements are the smallest building blocks of React apps.</p>\n<p>An element describes what you want to see on the screen:</p>\n<p>Unlike browser DOM elements, React elements are plain objects, and are cheap to create. React DOM takes care of updating the DOM to match the React elements.</p>\n<blockquote>\n<p><strong>Note:</strong></p>\n</blockquote>\n<blockquote>\n</blockquote>\n<blockquote>\n<p>One might confuse elements with a more widely known concept of \"components\". We will introduce components in the <a href=\"https://reactjs.org/docs/components-and-props.html\">next section</a>. Elements are what components are \"made of\", and we encourage you to read this section before jumping ahead.</p>\n</blockquote>\n<h2>Rendering an Element into the DOM</h2>\n<p>Let's say there is a &#x3C;div> somewhere in your HTML file:</p>\n<p>We call this a \"root\" DOM node because everything inside it will be managed by React DOM.</p>\n<p>Applications built with just React usually have a single root DOM node. If you are integrating React into an existing app, you may have as many isolated root DOM nodes as you like.</p>\n<p>To render a React element into a root DOM node, pass both to <a href=\"https://reactjs.org/docs/react-dom.html#render\">ReactDOM.render()</a>:</p>\n<p><a href=\"https://reactjs.org/redirect-to-codepen/rendering-elements/render-an-element\">Try it on CodePen</a></p>\n<p>It displays \"Hello, world\" on the page.</p>\n<h2>Updating the Rendered Element</h2>\n<p>React elements are <a href=\"https://en.wikipedia.org/wiki/Immutable_object\">immutable</a>. Once you create an element, you can't change its children or attributes. An element is like a single frame in a movie: it represents the UI at a certain point in time.</p>\n<p>With our knowledge so far, the only way to update the UI is to create a new element, and pass it to <a href=\"https://reactjs.org/docs/react-dom.html#render\">ReactDOM.render()</a>.</p>\n<p>Consider this ticking clock example:</p>\n<p><a href=\"https://reactjs.org/redirect-to-codepen/rendering-elements/update-rendered-element\">Try it on CodePen</a></p>\n<p>It calls <a href=\"https://reactjs.org/docs/react-dom.html#render\">ReactDOM.render()</a> every second from a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval\">setInterval()</a> callback.</p>\n<blockquote>\n<p><strong>Note:</strong></p>\n</blockquote>\n<blockquote>\n</blockquote>\n<blockquote>\n<p>In practice, most React apps only call <a href=\"https://reactjs.org/docs/react-dom.html#render\">ReactDOM.render()</a> once. In the next sections we will learn how such code gets encapsulated into <a href=\"https://reactjs.org/docs/state-and-lifecycle.html\">stateful components</a>.</p>\n</blockquote>\n<blockquote>\n</blockquote>\n<blockquote>\n<p>We recommend that you don't skip topics because they build on each other.</p>\n</blockquote>\n<h2>React Only Updates What's Necessary</h2>\n<p>React DOM compares the element and its children to the previous one, and only applies the DOM updates necessary to bring the DOM to the desired state.</p>\n<p>You can verify by inspecting the <a href=\"https://reactjs.org/redirect-to-codepen/rendering-elements/update-rendered-element\">last example</a> with the browser tools:</p>\n<p><img src=\"https://reactjs.org/c158617ed7cc0eac8f58330e49e48224/granular-dom-updates.gif\" alt=\"image\"></p>\n<p>Even though we create an element describing the whole UI tree on every tick, only the text node whose contents have changed gets updated by React DOM.</p>\n<p>In our experience, thinking about how the UI should look at any given moment, rather than how to change it over time, eliminates a whole class of bugs.</p>"},{"url":"/docs/react/jsx/","relativePath":"docs/react/jsx.md","relativeDir":"docs/react","base":"jsx.md","name":"jsx","frontmatter":{"title":"Introducing JSX","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Introducing JSX</h1>\n<h6>JSX is an XML/HTML-like syntax used by React that extends ECMAScript so that XML/HTML-like text can co-exist with JavaScript/React code. The syntax is intended to be used by preprocessors (i.e., transpilers like Babel) to transform HTML-like text found in JavaScript files into standard JavaScript objects that a JavaScript engine will parse.</h6>\n<p><strong>Basically, by using JSX you can write concise HTML/XML-like structures (e.g., DOM like tree structures) in the same file as you write JavaScript code, then Babel will transform these expressions into actual JavaScript code. Unlike the past, instead of putting JavaScript into HTML, JSX allows us to put HTML into JavaScript.</strong></p>\n<p>By using JSX one can write the following JSX/JavaScript code:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> nav <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>ul id<span class=\"token operator\">=</span><span class=\"token string\">\"nav\"</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>a href<span class=\"token operator\">=</span><span class=\"token string\">\"#\"</span><span class=\"token operator\">></span>Home<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>a href<span class=\"token operator\">=</span><span class=\"token string\">\"#\"</span><span class=\"token operator\">></span>About<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>a href<span class=\"token operator\">=</span><span class=\"token string\">\"#\"</span><span class=\"token operator\">></span>Clients<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>a href<span class=\"token operator\">=</span><span class=\"token string\">\"#\"</span><span class=\"token operator\">></span>Contact Us<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>And Babel will transform it into this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> nav <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n   <span class=\"token string\">\"ul\"</span><span class=\"token punctuation\">,</span>\n   <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token string\">\"nav\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n   React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n      <span class=\"token string\">\"li\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n      React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n         <span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span>\n         <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">href</span><span class=\"token operator\">:</span> <span class=\"token string\">\"#\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n         <span class=\"token string\">\"Home\"</span>\n      <span class=\"token punctuation\">)</span>\n   <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n   React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n      <span class=\"token string\">\"li\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n      React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n         <span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span>\n         <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">href</span><span class=\"token operator\">:</span> <span class=\"token string\">\"#\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n         <span class=\"token string\">\"About\"</span>\n      <span class=\"token punctuation\">)</span>\n   <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n   React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n      <span class=\"token string\">\"li\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n      React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n         <span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span>\n         <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">href</span><span class=\"token operator\">:</span> <span class=\"token string\">\"#\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n         <span class=\"token string\">\"Clients\"</span>\n      <span class=\"token punctuation\">)</span>\n   <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n   React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n      <span class=\"token string\">\"li\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n      React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n         <span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span>\n         <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">href</span><span class=\"token operator\">:</span> <span class=\"token string\">\"#\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n         <span class=\"token string\">\"Contact Us\"</span>\n      <span class=\"token punctuation\">)</span>\n   <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can think of JSX as a shorthand for calling <code class=\"language-text\">React.createElement()</code>.</p>\n<p>The idea of mixing HTML and JavaScript in the same file can be a rather contentious topic. Ignore the debate. Use it if you find it helpful. If not, write the React code required to create React nodes. Your choice. My opinion is that JSX provides a concise and familiar syntax for defining a tree structure with attributes that does not require learning a templating language or leaving JavaScript. Both of which are can be a win when building large applications.</p>\n<p>It should be obvious but JSX is easier to read and write over large pyramids of JavaScript function calls or object literals (e.g., contrast the two code samples in this section). Additionally the React team clearly believes JSX is better suited for defining UI's than a traditional templating (e.g., Handlebars) solution:</p>\n<blockquote>\n<p>markup and the code that generates it are intimately tied together. Additionally, display logic is often very complex and using template languages to express it becomes cumbersome. We've found that the best solution for this problem is to generate HTML and component trees directly from the JavaScript code such that you can use all of the expressive power of a real programming language to build UIs.</p>\n</blockquote>\n<p>Consider this variable declaration:</p>\n<p>This funny tag syntax is neither a string nor HTML.</p>\n<p>It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript.</p>\n<p>JSX produces React \"elements\". We will explore rendering them to the DOM in the <a href=\"https://reactjs.org/docs/rendering-elements.html\">next section</a>. Below, you can find the basics of JSX necessary to get you started.</p>\n<h3>Why JSX?</h3>\n<p>React embraces the fact that rendering logic is inherently coupled with other UI logic: how events are handled, how the state changes over time, and how the data is prepared for display.</p>\n<p>Instead of artificially separating <em>technologies</em> by putting markup and logic in separate files, React <a href=\"https://en.wikipedia.org/wiki/Separation_of_concerns\">separates <em>concerns</em></a> with loosely coupled units called \"components\" that contain both. We will come back to components in a <a href=\"https://reactjs.org/docs/components-and-props.html\">further section</a>, but if you're not yet comfortable putting markup in JS, <a href=\"https://www.youtube.com/watch?v=x7cQ3mrcKaY\">this talk</a> might convince you otherwise.</p>\n<p>React <a href=\"https://reactjs.org/docs/react-without-jsx.html\">doesn't require</a> using JSX, but most people find it helpful as a visual aid when working with UI inside the JavaScript code. It also allows React to show more useful error and warning messages.</p>\n<p>With that out of the way, let's get started!</p>\n<h3>Embedding Expressions in JSX</h3>\n<p>In the example below, we declare a variable called name and then use it inside JSX by wrapping it in curly braces:</p>\n<p>You can put any valid <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions\">JavaScript expression</a> inside the curly braces in JSX. For example, 2 + 2, user.firstName, or formatName(user) are all valid JavaScript expressions.</p>\n<p>In the example below, we embed the result of calling a JavaScript function, formatName(user), into an &#x3C;h1> element.</p>\n<p><a href=\"https://reactjs.org/redirect-to-codepen/introducing-jsx\">Try it on CodePen</a></p>\n<p>We split JSX over multiple lines for readability. While it isn't required, when doing this, we also recommend wrapping it in parentheses to avoid the pitfalls of <a href=\"https://stackoverflow.com/q/2846283\">automatic semicolon insertion</a>.</p>\n<h3>JSX is an Expression Too</h3>\n<p>After compilation, JSX expressions become regular JavaScript function calls and evaluate to JavaScript objects.</p>\n<p>This means that you can use JSX inside of if statements and for loops, assign it to variables, accept it as arguments, and return it from functions:</p>\n<h3>Specifying Attributes with JSX</h3>\n<p>You may use quotes to specify string literals as attributes:</p>\n<p>You may also use curly braces to embed a JavaScript expression in an attribute:</p>\n<p>Don't put quotes around curly braces when embedding a JavaScript expression in an attribute. You should either use quotes (for string values) or curly braces (for expressions), but not both in the same attribute.</p>\n<blockquote>\n<p><strong>Warning:</strong></p>\n</blockquote>\n<blockquote>\n</blockquote>\n<blockquote>\n<p>Since JSX is closer to JavaScript than to HTML, React DOM uses camelCase property naming convention instead of HTML attribute names.</p>\n</blockquote>\n<blockquote>\n</blockquote>\n<blockquote>\n<p>For example, class becomes <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Element/className\">className</a> in JSX, and tabindex becomes <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/tabIndex\">tabIndex</a>.</p>\n</blockquote>\n<h3>Specifying Children with JSX</h3>\n<p>If a tag is empty, you may close it immediately with />, like XML:</p>\n<p>JSX tags may contain children:</p>\n<h3>JSX Prevents Injection Attacks</h3>\n<p>It is safe to embed user input in JSX:</p>\n<p>By default, React DOM <a href=\"https://stackoverflow.com/questions/7381974/which-characters-need-to-be-escaped-on-html\">escapes</a> any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that's not explicitly written in your application. Everything is converted to a string before being rendered. This helps prevent <a href=\"https://en.wikipedia.org/wiki/Cross-site_scripting\">XSS (cross-site-scripting)</a> attacks.</p>\n<h3>JSX Represents Objects</h3>\n<p>Babel compiles JSX down to React.createElement() calls.</p>\n<p>These two examples are identical:</p>\n<p>React.createElement() performs a few checks to help you write bug-free code but essentially it creates an object like this:</p>\n<p>These objects are called \"React elements\". You can think of them as descriptions of what you want to see on the screen. React reads these objects and uses them to construct the DOM and keep it up to date.</p>\n<p>We will explore rendering React elements to the DOM in the <a href=\"https://reactjs.org/docs/rendering-elements.html\">next section</a>.</p>\n<blockquote>\n<p><strong>Tip:</strong></p>\n</blockquote>\n<blockquote>\n</blockquote>\n<blockquote>\n<p>We recommend using the <a href=\"https://babeljs.io/docs/en/next/editors\">\"Babel\" language definition</a> for your editor of choice so that both ES6 and JSX code is properly highlighted.</p>\n</blockquote>"},{"url":"/docs/react/quiz/","relativePath":"docs/react/quiz.md","relativeDir":"docs/react","base":"quiz.md","name":"quiz","frontmatter":{"title":"React Quiz Questions","weight":0,"excerpt":"cheat sheet","seo":{"title":"React Quiz Questions","description":"Of course, if you get a DOM node for the component via refs, you can do anything you want with the DOM nodes of other components, but it will likely mess up React.","robots":[],"extra":[]},"template":"docs"},"html":"<p><strong>What we know:</strong></p>\n<p>A top-level <code class=\"language-text\">App</code> component returns <code class=\"language-text\">&lt;Button /></code> from its <code class=\"language-text\">render()</code> method.</p>\n<p><strong>Question:</strong></p>\n<blockquote>\n<p>What is the relationship between <code class=\"language-text\">&lt;Button /></code> and <code class=\"language-text\">this</code> in that <code class=\"language-text\">Button</code>'s <code class=\"language-text\">render()</code>?</p>\n</blockquote>\n<p><strong>Answer:</strong></p>\n<p><code class=\"language-text\">&lt;Button></code> is a React \"element\".<br>\nIf you log it, you will see a plain object like <code class=\"language-text\">{ type: Button, props: {} }</code>.</p>\n<p>The element does not represent anything on the screen at that point.<br>\nIt is a <em>description</em> of what <code class=\"language-text\">App</code> wants to be rendered.</p>\n<p>At some point, React will look at that description and think: \"Hmm, there was no <code class=\"language-text\">Button</code> here but now there should be. So I'll create a <code class=\"language-text\">Button</code> instance.\"</p>\n<p>This <code class=\"language-text\">Button</code> instance created by React is <code class=\"language-text\">this</code> value in the <code class=\"language-text\">render()</code> and lifecycle methods. It's only useful for calling <code class=\"language-text\">setState()</code> or reading the props and state.</p>\n<p>If <code class=\"language-text\">App</code> gets re-rendered and React sees a <code class=\"language-text\">&lt;Button /></code> in its output again, it will think: \"Hmm, I already have a <code class=\"language-text\">Button</code> instance exactly at the same spot. Rather than create a new one, I will just update props on the existing one and re-render it.\"</p>\n<p>Let's recap.</p>\n<p><code class=\"language-text\">&lt;Button /></code> is an element, a description of what should be rendered. <code class=\"language-text\">this</code> inside the <code class=\"language-text\">Button</code> is the actual instance React created based on that description.</p>\n<p><code class=\"language-text\">App</code> can return a different <code class=\"language-text\">&lt;Button /></code> element every time but as long as its key doesn't change, and it is still a <code class=\"language-text\">&lt;Button /></code> and not a <code class=\"language-text\">&lt;Door /></code>, React will keep using the same instance.</p>\n<p><strong>Question:</strong></p>\n<blockquote>\n<p>Does rendering <code class=\"language-text\">&lt;Button>\n&lt;Icon />\n&lt;/Button></code> guarantee that an <code class=\"language-text\">Icon</code> mounts?</p>\n</blockquote>\n<p>It doesn't. Ultimately it's always up to the component to decide what to do with its children. For example, the <code class=\"language-text\">Button</code> implementation could completely ignore them and render something else:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Button</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span><span class=\"token constant\">I</span> render whatever <span class=\"token constant\">I</span> want<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Interestingly, it could also render <code class=\"language-text\">children</code> multiple times:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Button</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token constant\">I</span> like to repeat things<span class=\"token punctuation\">.</span>\n            <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Ultimately, <code class=\"language-text\">children</code> is not a special prop in any way except for JSX sugar syntax. <code class=\"language-text\">&lt;Button>\n&lt;Icon />\n&lt;/Button></code> is technically the same as <code class=\"language-text\">&lt;Button children={&lt;Icon />} /></code>, and it's up to the component how to treat its input props.</p>\n<p><strong>Question:</strong></p>\n<blockquote>\n<p>Can the <code class=\"language-text\">App</code> change anything in the <code class=\"language-text\">Button</code> output? What and how?</p>\n</blockquote>\n<p><strong>Answer:</strong></p>\n<p>There have been a few fun answers in the <a href=\"https://gist.github.com/gaearon/8fa9fdd2c4197ee0b52894877bf587a4\">quiz comments</a> so I will direct you to them. Indeed, since JavaScript doesn't provide any guarantees, technically you can hijack <code class=\"language-text\">Button</code> before React gets a chance to render it.</p>\n<p>However, normally there is no way for a parent component to control the child output except by two mechanisms: passing props and providing context. You probably already know about props, and I won't talk about the context because it's an experimental API and has a few pitfalls. Don't use context in apps unless <a href=\"https://medium.com/@mweststrate/how-to-safely-use-react-context-b7e343eff076\">you know its pitfalls well</a>.</p>\n<p>Of course, if you get a DOM node for the component via refs, you can do anything you want with the DOM nodes of other components, but it will likely mess up React.</p>\n<h1>React.js</h1>\n<h3>Q1. If you want to import just the Component from the React library, what syntax do you use?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">import React.Component from 'react'</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">import [ Component ] from 'react'</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">import Component from 'react'</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">import { Component } from 'react'</code></li>\n</ul>\n<h3>Q2. If a function component should always render the same way given the same props, what is a simple performance optimization available for it?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Wrap it in the <code class=\"language-text\">React.memo</code> higher-order component.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Implement the <code class=\"language-text\">useReducer</code> Hook.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Implement the <code class=\"language-text\">useMemo</code> Hook.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Implement the <code class=\"language-text\">shouldComponentUpdate</code> lifecycle method.</li>\n</ul>\n<h3>Q3. How do you fix the syntax error that results from running this code?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">person</span> <span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">firstName<span class=\"token punctuation\">,</span> lastName</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n<span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">first</span><span class=\"token operator\">:</span> firstName<span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">last</span><span class=\"token operator\">:</span> lastName\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">person</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Jill\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Wilson\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Wrap the object in parentheses.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Call the function from another file.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add a return statement before the first curly brace.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Replace the object with an array.</li>\n</ul>\n<h3>Q4. If you see the following import in a file, what is being used for state management in the component?</h3>\n<p><code class=\"language-text\">import React, {useState} from 'react';</code></p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] React Hooks</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> stateful components</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> math</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> class components</li>\n</ul>\n<h3>Q5. Using object literal enhancement, you can put values back into an object. When you log person to the console, what is the output?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> name <span class=\"token operator\">=</span> <span class=\"token string\">'Rachel'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> age <span class=\"token operator\">=</span> <span class=\"token number\">31</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> name<span class=\"token punctuation\">,</span> age <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>person<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">{{name: \"Rachel\", age: 31}}</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">{name: \"Rachel\", age: 31}</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">{person: \"Rachel\", person: 31}}</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">{person: {name: \"Rachel\", age: 31}}</code></li>\n</ul>\n<h3>Q6. What is the testing library most often associated with React?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Mocha</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Chai</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Sinon</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Jest</li>\n</ul>\n<h3>Q7. To get the first item from the array (\"cooking\") using array destructuring, how do you adjust this line?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> topics <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cooking'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'art'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'history'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">const first = [\"cooking\", \"art\", \"history\"]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">const [] = [\"cooking\", \"art\", \"history\"]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">const [, first][\"cooking\", \"art\", \"history\"]</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">const [first] = [\"cooking\", \"art\", \"history\"]</code></li>\n</ul>\n<h3>Q8. How do you handle passing through the component tree without having to pass props down manually at every level?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> React Send</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> React Pinpoint</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> React Router</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] React Context</li>\n</ul>\n<h3>Q9. What should the console read when the following code is run?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> animal<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Horse'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Mouse'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Cat'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>animal<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Horse</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Cat</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Mouse</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> undefined</li>\n</ul>\n<h3>10. What is the name of the tool used to take JSX and turn it into createElement calls?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> JSX Editor</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> ReactDOM</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Browser Buddy</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Babel</li>\n</ul>\n<h3>11. Why might you use useReducer over useState in a React component?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you want to replace Redux</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] when you need to manage more complex state in an app</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you want to improve performance</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you want to break your production app</li>\n</ul>\n<h3>12. Which props from the props object is available to the component with the following syntax?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>Message <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> any that have not changed</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] all of them</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> child props</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> any that have changed</li>\n</ul>\n<h3>13. Consider the following code from React Router. What do you call :id in the path prop?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>Route path<span class=\"token operator\">=</span><span class=\"token string\">\"/:id\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> This is a route modal</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] This is a route parameter</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> This is a route splitter</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> This is a route link</li>\n</ul>\n<h3>14. If you created a component called Dish and rendered it to the DOM, what type of element would be rendered?</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Dish</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Mac and Cheese<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Dish <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">div</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> section</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> component</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">h1</code></li>\n</ul>\n<h3>15. What does this React element look like given the following function? (Alternative: Given the following code, what does this React element look like?)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'h1'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"What's happening?\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;h1 props={null}>What's happening?&lt;/h1></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">&lt;h1>What's happening?&lt;/h1></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;h1 id=\"component\">What's happening?&lt;/h1></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;h1 id=\"element\">What's happening?&lt;/h1></code></li>\n</ul>\n<h3>16. What property do you need to add to the Suspense component in order to display a spinner or loading state?</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">MyComponent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>Suspense<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>Message <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Suspense<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> lazy</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> loading</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] fallback</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> spinner</li>\n</ul>\n<h3>17. What do you call the message wrapped in curly braces below?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> message <span class=\"token operator\">=</span> <span class=\"token string\">'Hi there'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>message<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a JS function</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a JS element</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a JS expression</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a JSX wrapper</li>\n</ul>\n<h3>18. What can you use to handle code splitting?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">React.memo</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">React.split</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">React.lazy</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">React.fallback</code></li>\n</ul>\n<h3>19. When do you use <code class=\"language-text\">useLayoutEffect</code>?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to optimize for all devices</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to complete the update</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to change the layout of the screen</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] when you need the browser to paint before the effect runs</li>\n</ul>\n<h3>20. What is the difference between the click behaviors of these two buttons (assuming that this.handleClick is bound correctly)?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token constant\">A</span><span class=\"token punctuation\">.</span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Click Me<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n<span class=\"token constant\">B</span><span class=\"token punctuation\">.</span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token parameter\">event</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Click Me<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Button A will not have access to the event object on click of the button.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Button B will not fire the handler this.handleClick successfully.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Button A will not fire the handler this.handleClick successfully.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] There is no difference.</li>\n</ul>\n<h3>21. How do you destructure the properties that are sent to the Dish component?</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Dish</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>cookingTime<span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">function Dish([name, cookingTime]) { return &lt;h1>{name} {cookingTime}&lt;/h1>; }</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">function Dish({name, cookingTime}) { return &lt;h1>{name} {cookingTime}&lt;/h1>; }</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">function Dish(props) { return &lt;h1>{name} {cookingTime}&lt;/h1>; }</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">function Dish(...props) { return &lt;h1>{name} {cookingTime}&lt;/h1>; }</code></li>\n</ul>\n<h3>22. When might you use <code class=\"language-text\">React.PureComponent</code>?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you do not want your component to have props</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you have sibling components that need to be compared</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] when you want a default implementation of <code class=\"language-text\">shouldComponentUpdate()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when you do not want your component to have state</li>\n</ul>\n<h3>23. Why is it important to avoid copying the values of props into a component's state where possible?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> because you should never mutate state</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> because <code class=\"language-text\">getDerivedStateFromProps()</code> is an unsafe method to use</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] because you want to allow a component to update in response to changes in the props</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> because you want to allow data to flow back up to the parent</li>\n</ul>\n<h3>24. What is the children prop?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a property that adds child components to state</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a property that lets you pass components as data to other components</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a property that lets you set an array as a property</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a property that lets you pass data to child elements</li>\n</ul>\n<h3>25. Which attribute do you use to replace innerHTML in the browser DOM?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> injectHTML</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] dangerouslySetInnerHTML</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> weirdSetInnerHTML</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> strangeHTML</li>\n</ul>\n<h3>26. Which of these terms commonly describe React applications?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] declarative</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> integrated</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> closed</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> imperative</li>\n</ul>\n<h3>27. When using webpack, why would you need to use a loader?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to put together physical file folders</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] to preprocess files</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to load external data</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to load the website into everyone's phone</li>\n</ul>\n<h3>28. A representation of a user interface that is kept in memory and is synced with the \"real\" DOM is called what?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] virtual DOM</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> DOM</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> virtual elements</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> shadow DOM</li>\n</ul>\n<h3>29. You have written the following code but nothing is rendering. How do you fix this problem?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Heading</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add a render function.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Change the curly braces to parentheses or add a return statement before the <code class=\"language-text\">h1</code> tag.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Move the <code class=\"language-text\">h1</code> to another component.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Surround the <code class=\"language-text\">h1</code> in a <code class=\"language-text\">div</code>.</li>\n</ul>\n<h3>Q30. To create a constant in JavaScript, which keyword do you use?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] const</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> let</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> constant</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> var</li>\n</ul>\n<h3>Q31. What do you call a React component that catches JavaScript errors anywhere in the child component tree?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> error bosses</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> error catchers</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> error helpers</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] error boundaries</li>\n</ul>\n<h3>Q32. In which lifecycle method do you make requests for data in a class component?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> constructor</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] componentDidMount</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> componentWillReceiveProps</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> componentWillMount</li>\n</ul>\n<h3>Q33. React components are composed to create a user interface. How are components composed?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> by putting them in the same file</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] by nesting components</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> with webpack</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> with code splitting</li>\n</ul>\n<h3>Q34. All React components must act like <strong>_</strong> with respect to their props.</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> monads</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] pure functions</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> recursive functions</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> higher-order functions</li>\n</ul>\n<h3>Q35. Why might you use a ref?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] to directly access the DOM node</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to refer to another JS file</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to call a function</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> to bind the function</li>\n</ul>\n<h3>Q36. What is <code class=\"language-text\">[e.target.id]</code> called in the following code snippet?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a computed property name</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a set value</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a dynamic key</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a JSX code string</li>\n</ul>\n<h3>Q37. What is the name of this component?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Clock</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Look at the time<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>time<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Clock</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It does not have a name prop.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> React.Component</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Component</li>\n</ul>\n<h3>Q38. What is sent to an <code class=\"language-text\">Array.map()</code> function?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a callback function that is called once for each element in the array</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the name of another array to iterate over</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the number of times you want to call the function</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a string describing what the function should do</li>\n</ul>\n<h3>Q39. Why is it a good idea to pass a function to <code class=\"language-text\">setState</code> instead of an object?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It provides better encapsulation.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It makes sure that the object is not mutated.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It automatically updates a component.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">setState</code> is asynchronous and might result in out of sync values.</li>\n</ul>\n<h3>Q40. What package contains the render() function that renders a React element tree to the DOM?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">React</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">ReactDOM</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">Render</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">DOM</code></li>\n</ul>\n<h3>Q41. How do you set a default value for an uncontrolled form field?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Use the <code class=\"language-text\">value</code> property.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Use the <code class=\"language-text\">defaultValue</code> property.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Use the <code class=\"language-text\">default</code> property.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It assigns one automatically.</li>\n</ul>\n<h3>Q42. What do you need to change about this code to get it to run?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">clock</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Look at the time<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>time<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Add quotes around the return value</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Remove <code class=\"language-text\">this</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Remove the render method</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Capitalize <code class=\"language-text\">clock</code></li>\n</ul>\n<p><strong>Explanation:</strong> In JSX, lower-case tag names are considered to be HTML tags. Read <a href=\"https://reactjs.org/docs/jsx-in-depth.html#html-tags-vs.-react-components\">this article</a></p>\n<h3>Q43. Which Hook could be used to update the document's title?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">useEffect(function updateTitle() { document.title = name + ' ' + lastname; });</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">useEffect(() => { title = name + ' ' + lastname; });</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">useEffect(function updateTitle() { name + ' ' + lastname; });</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">useEffect(function updateTitle() { title = name + ' ' + lastname; });</code></li>\n</ul>\n<h3>Q44. What can you use to wrap Component imports in order to load them lazily?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">React.fallback</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">React.split</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">React.lazy</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">React.memo</code></li>\n</ul>\n<h3>Q45. How do you invoke setDone only when component mounts, using hooks?</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">MyComponent</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>done<span class=\"token punctuation\">,</span> setDone<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Done<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>done<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">useEffect(() => { setDone(true); });</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">useEffect(() => { setDone(true); }, []);</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">useEffect(() => { setDone(true); }, [setDone]);</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">useEffect(() => { setDone(true); }, [done, setDone]);</code></li>\n</ul>\n<h3>Q46. Which of the following click event handlers will allow you to pass the name of the person to be hugged?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Huggable</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">hug</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">id</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hugging \"</span> <span class=\"token operator\">+</span> id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> name <span class=\"token operator\">=</span> <span class=\"token string\">\"kitteh\"</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> button <span class=\"token operator\">=</span> <span class=\"token comment\">// Missing Code</span>\n    <span class=\"token keyword\">return</span> button<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;button onClick={(name) => this.hug(name)}>Hug Button&lt;/button></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;button onClick={this.hug(e, name)}>Hug Button&lt;/button></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;button onClick={(e) => hug(e, name)}>Hug Button&lt;/button></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">&lt;button onClick={(e) => this.hug(name,e)}>Hug Button&lt;/button></code></li>\n</ul>\n<h3>Q47. Currently, <code class=\"language-text\">handleClick</code> is being called instead of passed as a reference. How do you fix this?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Click <span class=\"token keyword\">this</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;button onClick={this.handleClick.bind(handleClick)}>Click this&lt;/button></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;button onClick={handleClick()}>Click this&lt;/button></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">&lt;button onClick={this.handleClick}>Click this&lt;/button></code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">&lt;button onclick={this.handleClick}>Click this&lt;/button></code></li>\n</ul>\n<h3>Q48. Which answer best describes a function component?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A function component is the same as a class component.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] A function component accepts a single props object and returns a React element.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A function component is the only way to create a component.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A function component is required to create a React component.</li>\n</ul>\n<h3>Q49. Which library does the <code class=\"language-text\">fetch()</code> function come from?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> FetchJS</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> ReactDOM</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] No library. <code class=\"language-text\">fetch()</code> is supported by most browsers.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> React</li>\n</ul>\n<h3>Q50. What will happen when this useEffect Hook is executed, assuming name is not already equal to John?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>name<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It will cause an error immediately.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It will execute the code inside the function, but only after waiting to ensure that no other component is accessing the name variable.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It will update the value of name once and not run again until name is changed from the outside.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It will cause an infinite loop.</li>\n</ul>\n<h3>Q51. Which choice will not cause a React component to rerender?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> if the component calls <code class=\"language-text\">this.setState(...)</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the value of one of the component's props changes</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> if the component calls <code class=\"language-text\">this.forceUpdate()</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] one of the component's siblings rerenders</li>\n</ul>\n<h3>Q52. You have created a new method in a class component called handleClick, but it is not working. Which code is missing?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Button</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span><span class=\"token punctuation\">{</span>\n\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// Missing line</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">this.handleClick.bind(this);</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">props.bind(handleClick);</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">this.handleClick.bind();</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">this.handleClick = this.handleClick.bind(this);</code></li>\n</ul>\n<h3>Q53. React does not render two sibling elements unless they are wrapped in a fragment. Below is one way to render a fragment. What is the shorthand for this?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Our Staff<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Our staff is available <span class=\"token number\">9</span><span class=\"token operator\">-</span><span class=\"token number\">5</span> to answer your questions<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">...</span><span class=\"token operator\">></span>\n  <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Our Staff<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n  <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Our staff is available <span class=\"token number\">9</span><span class=\"token operator\">-</span><span class=\"token number\">5</span> to answer your questions<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span><span class=\"token operator\">...</span><span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> B</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span><span class=\"token comment\">//></span>\n  <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Our Staff<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n  <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Our staff is available <span class=\"token number\">9</span><span class=\"token operator\">-</span><span class=\"token number\">5</span> to answer your questions<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token comment\">///></span></code></pre></div>\n<ul>\n<li>[✅] C</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Our Staff<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Our staff is available <span class=\"token number\">9</span><span class=\"token operator\">-</span><span class=\"token number\">5</span> to answer your questions<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> D</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>Frag<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Our Staff<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Our staff is available <span class=\"token number\">9</span><span class=\"token operator\">-</span><span class=\"token number\">5</span> to answer your questions<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Frag<span class=\"token operator\">></span></code></pre></div>\n<h3>Q54. If you wanted to display the count state value in the component, what do you need to add to the curly braces in the <code class=\"language-text\">h1</code>?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Ticker</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] this.state.count</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> count</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> state</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> state.count</li>\n</ul>\n<h3>Q55. Per the following code, when is the Hello component displayed?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> greeting <span class=\"token operator\">=</span> isLoggedIn <span class=\"token operator\">?</span> <span class=\"token operator\">&lt;</span>Hello <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> never</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] when <code class=\"language-text\">isLoggedIn</code> is true</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when a user logs in</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> when the Hello function is called</li>\n</ul>\n<h3>Q56. In the following code block, what type is orderNumber?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Message orderNumber<span class=\"token operator\">=</span><span class=\"token string\">\"16\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] string</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> boolean</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> object</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> number</li>\n</ul>\n<h3>Q57. You have added a style property to the <code class=\"language-text\">h1</code> but there is an unexpected token error when it runs. How do you fix this?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>h1 style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">backgroundColor</span><span class=\"token operator\">:</span> <span class=\"token string\">\"blue\"</span> <span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Hi<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">const element = &lt;h1 style=\"backgroundColor: \"blue\"\"}>Hi&lt;/h1>;</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">const element = &lt;h1 style={{backgroundColor: \"blue\"}}>Hi&lt;/h1>;</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">const element = &lt;h1 style={blue}>Hi&lt;/h1>;</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">const element = &lt;h1 style=\"blue\">Hi&lt;/h1>;</code></li>\n</ul>\n<h3>Q58. Which function is used to update state variables in a React class component?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">replaceState</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">refreshState</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">updateState</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">setState</code></li>\n</ul>\n<h3>Q59. Consider the following component. What is the default color for the star?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Star</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> selected <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>Icon color<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>selected <span class=\"token operator\">?</span> <span class=\"token string\">'red'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'grey'</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> black</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> red</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] grey</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> white</li>\n</ul>\n<h3>Q60. Which answer best describes a function component?(Not sure answer)</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">A function component is the same as a class component.</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">A function component accepts a single props object and returns a React element.</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">A function component is the only way to create a component.</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">A function component is required to create a React component.</code></li>\n</ul>\n<h3>Q61.Which library does the fetch() function come from?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">FetchJS</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">ReactDOM</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">No library. fetch() is supported by most browsers.</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">React</code></li>\n</ul>\n<h3>Q62.What is the difference between the click behaviors of these two buttons(assuming that this.handleClick is bound correctly)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token constant\">A</span><span class=\"token punctuation\">.</span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick<span class=\"token operator\">></span>Click Me<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n  <span class=\"token constant\">B</span><span class=\"token punctuation\">.</span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token parameter\">event</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Click Me<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">Button A will not have access to the event object on click of the button</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">Button A will not fire the handler this.handleClick successfully</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">There is no difference</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">Button B will not fire the handler this.handleClick successfully</code></li>\n</ul>\n<h3>Q63.What will happen when this useEffect Hook is executed, assuming name is not already equal to John?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>name<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">It will cause an error immediately.</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">It will execute the code inside the function, but only after waiting to ensure that no other component is accessing the name variable.</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] <code class=\"language-text\">It will update the value of name once and not run again until name is changed from the outside.</code></li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> <code class=\"language-text\">It will cause an infinite loop.</code></li>\n</ul>\n<h3>Q64. How would you add to this code, from React Router, to display a component called About?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>Route path<span class=\"token operator\">=</span><span class=\"token string\">\"/:id\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li>[✅] A</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>Route path<span class=\"token operator\">=</span><span class=\"token string\">\"/:id\"</span><span class=\"token operator\">></span>\n    <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&lt;</span>About <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Route<span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> B</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>Route path<span class=\"token operator\">=</span><span class=\"token string\">\"/tid\"</span> about<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>Component<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> C</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>Route path<span class=\"token operator\">=</span><span class=\"token string\">\"/:id\"</span> route<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>About<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> D</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>Route<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>About path<span class=\"token operator\">=</span><span class=\"token string\">\"/:id\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Route<span class=\"token operator\">></span></code></pre></div>\n<h3>Q65. Which class-based component is equivalent to this function component?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function\">Greeting</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> name <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> A</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Greeting</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> B</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Greeting</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>[✅] C</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Greeting</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> D</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Greeting</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> name <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello <span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Q66. Give the code below, what does the second argument that is sent to the render function describe?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hi<span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] where the React element should be added to the DOM</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> where to call the function</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> where the root component is</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> where to create a new JavaScript file</li>\n</ul>\n<h3>Q67. Why should you use React Router's Link component instead of a basic <code class=\"language-text\">&lt;a></code> tag in React?</h3>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The link component allows the user to use the browser's <code class=\"language-text\">Back</code> button.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> There is no difference--the <code class=\"language-text\">Link</code> component is just another name for the <code class=\"language-text\">&lt;a></code> tag.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The <code class=\"language-text\">&lt;a></code> tag will cause an error when used in React.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] The <code class=\"language-text\">&lt;a></code> tag triggers a full page reload, while the <code class=\"language-text\">Link</code> component does not.</li>\n</ul>\n<h3>Q68. What is the first argument, <code class=\"language-text\">x</code>, that is sent to the <code class=\"language-text\">createElement</code> function?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> z<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] the element that should be created</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the order in which this element should be placed on the page</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the properties of the element</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> data that should be displayed in the element</li>\n</ul>\n<h3>Q69. Which class-based lifecycle method would be called at the same time as this effect Hook?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// do things</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> componentWillUnmount</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] componentDidMount</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> render</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> componentDidUpdate</li>\n</ul>\n<h3>Q70. Given the code below, what does the second argument that is sent to the render function describe?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hi<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] where the React element should be added to the DOM</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> where to call the function</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> where the root component is</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> where to create a new JavaScript file</li>\n</ul>\n<h3>Q71. What is the first argument, x, that is sent to the <code class=\"language-text\">createElement</code> function?</h3>\n<p><code class=\"language-text\">React.createElement(x,y,z);</code></p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] the element that should be created</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the order in which this element should be placed on the page</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the properties of the element</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> data that should be displayed in the element.</li>\n</ul>\n<h3>Q72. What is the name of this component?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Comp</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Look at the time<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>time<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] Comp</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> h1</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> React.Component</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Component</li>\n</ul>\n<p>This question might be an updated version of Q37.</p>\n<h3>Q73. When using a portal, what is the first argument?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">createPortal</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the current state</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] the element to render</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the App component</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the page</li>\n</ul>\n<p><strong>Explanation:</strong> From official docs: <a href=\"https://reactjs.org/docs/portals.html\">Portals</a></p>\n<h3>Q74. What is <code class=\"language-text\">setCount</code>?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>count<span class=\"token punctuation\">,</span> setCount<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the initial state value</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a variable</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> a state object</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] a function to update the state</li>\n</ul>\n<p><strong>Reference:</strong> From official docs: <a href=\"https://reactjs.org/docs/hooks-state.html#:~:text=If%20we%20want%20to%20update%20the%20current\">Hooks-State</a></p>\n<h3>Q75. What is the use of map function below?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> database <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>user1<span class=\"token operator\">:</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span><span class=\"token literal-property property\">user2</span><span class=\"token operator\">:</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span><span class=\"token literal-property property\">user3</span><span class=\"token operator\">:</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\ndatabase<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">user</span><span class=\"token punctuation\">)</span><span class=\"token operator\">=></span>\n<span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>user<span class=\"token punctuation\">.</span>data<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> gives a map of all the entries in database</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] returns a heading tag for every entry in the database containing it's data</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> returns one heading tag for all the entries in database</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> checks which entry in the database is suitable for heading tag</li>\n</ul>\n<h3>Q76. Describe what is happening in this code?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> firstName <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> person<span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is creating a new object that contains the same name property as the person object.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is assigning the value of the person object's firstName property to a constant called name.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It is retrieving the value of person.name.firstName.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] It is assigning the value of the person object's name property to a constant called firstName.</li>\n</ul>\n<h3>Q77. What is wrong with this code?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">MyComponent</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> names <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n  <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Hello again<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> React components cannot be defined using functions.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] React does not allow components to return more than one element.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> The component needs to use the return keyword.</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> String literals must be surrounded by quotes.</li>\n</ul>\n<h3>Q78. When using a portal, what is the second argument?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">createPortal</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the App component</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the page</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> the current state</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] the DOM element that exists outside of the parent component</li>\n</ul>\n<h3>Q79. Given this code, what will be printed in the</h3>\n<p><strong>tag?</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">MyComponent</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> children <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token operator\">...</span>\n<span class=\"token operator\">&lt;</span>MyComponent<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Hello<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Goodbye<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyComponent<span class=\"token operator\">></span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> It will produce an error saying \"cannot read property \"length\" of undefined.\"</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> 1</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> undefined</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] 2</li>\n</ul>\n<h2>Q80. What is this pattern called?</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>count<span class=\"token punctuation\">,</span> setCount<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> object destructuring</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> [✅] array destructuring</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> spread operating</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> code pushing</li>\n</ul>"},{"url":"/docs/reference/awesome-static/","relativePath":"docs/reference/awesome-static.md","relativeDir":"docs/reference","base":"awesome-static.md","name":"awesome-static","frontmatter":{"title":"Awesome Static Site Resources","weight":0,"excerpt":"inspired by Awesome Lists","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Awesome Static Site Resources</h1>\n<h2>Table of Contents</h2>\n<ul>\n<li><a href=\"#audio\">Audio</a></li>\n<li><a href=\"#books\">Books</a></li>\n<li><a href=\"#calendar-and-scheduling\">Calendar and Scheduling</a></li>\n<li><a href=\"#images\">Images</a></li>\n<li><a href=\"#maps\">Maps</a></li>\n<li><a href=\"#presentations\">Presentations</a></li>\n<li><a href=\"#video\">Video</a></li>\n<li><a href=\"#code\">Code</a></li>\n<li><a href=\"#functions-as-a-service\">Functions as a Service FaaS</a></li>\n<li><a href=\"#GraphQL\">GraphQL</a></li>\n<li>\n<p><a href=\"#community\">Community</a></p>\n<ul>\n<li><a href=\"#comments\">Comments</a></li>\n<li><a href=\"#forms\">Forms</a></li>\n<li><a href=\"#live-chat\">Live Chat</a></li>\n<li><a href=\"#newsletters\">Newsletters</a></li>\n<li><a href=\"#social-media\">Social Media</a></li>\n<li><a href=\"#surveys\">Surveys</a></li>\n</ul>\n</li>\n<li><a href=\"#e-commerce\">E-Commerce</a></li>\n<li><a href=\"#payments\">Payments</a></li>\n<li><a href=\"#search\">Search</a></li>\n<li><a href=\"#analytics\">Analytics</a></li>\n<li><a href=\"#authentication\">Authentication</a></li>\n<li><a href=\"#other\">Other</a></li>\n<li><a href=\"#related-lists\">Related Lists</a></li>\n</ul>\n<hr>\n<h2>Audio</h2>\n<ul>\n<li><a href=\"https://soundcloud.com/\">SoundCloud</a> - Audio hosting with an embeddable player. Up to 3 hours of content is free.</li>\n<li><a href=\"https://www.mixcloud.com/\">Mixcloud</a> - Audio hosting with unlimited uploads and an embeddable player.</li>\n<li><a href=\"https://www.spotify.com/\">Spotify</a> - You can embed any song, album, or playlist with a <a href=\"https://developer.spotify.com/documentation/widgets/guides/adding-a-spotify-embed/\">Spotify Play Button</a>.</li>\n</ul>\n<h2>Books</h2>\n<ul>\n<li><a href=\"https://github.com/aharris88/google-bookshelves-widget\">Google Books</a> - Allows you to display the books in your Google Books Library.</li>\n<li><a href=\"https://www.goodreads.com/api\">Goodreads API and widgets</a> - Allows you to access any of the Goodreads data. Widgets are found on the widgets tab on your <a href=\"https://www.goodreads.com/user/edit\">settings page</a>.</li>\n</ul>\n<h2>Calendar and Scheduling</h2>\n<ul>\n<li><a href=\"http://calendar.google.com/\">Google Calendar</a> - Embeddable calendar that you can collaborate with other people.</li>\n<li><a href=\"http://booking.timekit.io/\">Booking.js</a> - Beautiful embeddable booking widget.</li>\n<li><a href=\"http://zenplanner.com/\">zenplanner</a> - Paid - Online scheduling for fitness.</li>\n</ul>\n<h2>Images</h2>\n<ul>\n<li><a href=\"https://www.flickr.com/\">Flickr</a> - Online photo hosting by Yahoo.</li>\n<li><a href=\"https://cloudinary.com/\">Cloudinary</a> - Image hosting, manipulation and delivery.</li>\n</ul>\n<h2>Maps</h2>\n<ul>\n<li><a href=\"http://maps.google.com/\">Google Maps</a> - Google maps are easily embeddable.</li>\n<li><a href=\"https://www.mapbox.com/\">Mapbox</a> - Really nice looking embeddable maps.</li>\n</ul>\n<h2>Presentations</h2>\n<ul>\n<li><a href=\"https://prezi.com/\">Prezi</a> - Online presentations with really transitions that can zoom and rotate.</li>\n<li><a href=\"http://lab.hakim.se/reveal-js/\">Reveal.js</a> - HTML presentation framework.</li>\n<li><a href=\"http://slides.com/\">Slides.com</a> - A place for creating, presenting and sharing slide decks.</li>\n<li><a href=\"https://speakerdeck.com/\">SpeakerDeck</a> - Upload your slides as a PDF, and get an online, shareable presentation.</li>\n</ul>\n<h2>Video</h2>\n<ul>\n<li><a href=\"https://mux.com/\">Mux</a> - Paid - An API to play videos directly to the client. Can also power live streams.</li>\n<li><a href=\"https://www.youtube.com/\">YouTube</a> - Embeddable videos with unlimited uploads.</li>\n<li><a href=\"https://vimeo.com/\">Vimeo</a> - Paid - Embeddable videos with no ads.</li>\n<li><a href=\"http://www.vevo.com/\">Vevo</a> - Embeddable music videos.</li>\n<li><a href=\"http://wistia.com/\">Wistia</a> - Free plan has a limit of 25 videos.</li>\n</ul>\n<h3>Code</h3>\n<ul>\n<li><a href=\"http://codepen.io/\">Codepen</a> - A playground of embeddable front-end code examples.</li>\n<li><a href=\"http://jsbin.com/\">JS Bin</a> - Embeddable front-end code examples.</li>\n<li><a href=\"http://jsfiddle.net/\">JSFiddle</a> - Embeddable front-end code examples.</li>\n<li><a href=\"https://highlightjs.org/\">highlight.js</a> - Syntax highlighting for the web.</li>\n</ul>\n<h2>Functions as a Service</h2>\n<ul>\n<li><a href=\"https://github.com/1backend/1backend\">1Backend</a> - Deploy your backend in seconds. Free tier included. Open source.</li>\n<li><a href=\"https://aws.amazon.com/lambda/\">AWS Lambda</a> - AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume</li>\n<li><a href=\"https://cloud.google.com/functions/\">Google Cloud Functions</a> - Create single-purpose, stand-alone functions that respond to Cloud events without the need to manage a server or runtime environment</li>\n<li><a href=\"https://webtask.io/\">Webtask by Auth0</a> - Call code on the server with simple HTTP, easier to set up by far than Lambda or Google's</li>\n<li><a href=\"https://azure.microsoft.com/services/functions/\">Azure Functions</a> - by Microsoft - same premise as Lambda on the Azure cloud</li>\n<li><a href=\"https://www.iron.io/platform/ironworker/\">IronWorkers</a> - by Iron.io - Run code in a multilanguage containerized environment with unlimited scale and simple pricing</li>\n<li><a href=\"http://open.iron.io/\">IronFunctions</a> - by Iron.io - IronFunctions is an open source serverless computing platform for any cloud - private, public, or hybrid.</li>\n<li><a href=\"https://console.ng.bluemix.net/openwhisk/\">OpenWhisk by IBM</a> - part of their BlueMix hosting platform, and open source, ties into their Watson AI ecosystem nicely</li>\n<li><a href=\"https://www.stackpath.com/products/edgeengine/\">StackPath EdgeEngine</a> - Write functions as a service in the language of your choice and deploy them to a global network of data centers. All the networking, including intelligent routing and load balancing, is managed by StackPath over a private backbone.</li>\n<li><a href=\"https://vercel.com/home#features\">Vercel</a> - Vercel lets people write functions as a service in their language of choice and deploy as part of a monorepo.</li>\n<li><a href=\"https://azure.microsoft.com/services/app-service/static/#features\">Azure Static Web Apps</a> - Full-stack static app hosting including serverless Functions, authentication, CDN and more</li>\n</ul>\n<h2>GraphQL</h2>\n<ul>\n<li><a href=\"https://fauna.com\">FaunaDB</a> - Serverless GraphQL database. Free tier with no time limit. Easily included in Netlify apps.</li>\n</ul>\n<h2>Community</h2>\n<h3>Comments</h3>\n<ul>\n<li><a href=\"https://github.com/eduardoboucas/staticman\">Staticman</a> - Staticman is a Node.js application that receives user-generated content and uploads it as data files to a GitHub repository. In practice, this allows you to have dynamic content (e.g. blog post comments) as part of a fully static website, as long as your site automatically deploys on every push to GitHub, as seen on GitHub Pages, Netlify and others.</li>\n<li><a href=\"https://disqus.com/\">Disqus</a> - Easily embeddable comments with nested replies, multiple login methods, and email notifications.</li>\n<li><a href=\"https://developers.facebook.com/docs/plugins/comments\">Facebook Comments</a> - Embeddable comments for your site by Facebook.</li>\n<li><a href=\"http://www.intensedebate.com/\">IntenseDebate Comments</a> - Embeddable comments with nested replies, multiple login methods, and email notifications.</li>\n<li><a href=\"http://web.livefyre.com/apps/comments/\">LiveFyre</a> - Real-time comments, SEO-optimized, stocked with social features, and beautiful on both desktop and mobile.</li>\n<li><a href=\"http://embed.redditjs.com/\">Redditjs Embed Widget</a> - Embed Reddit comments on your site. If it hasn't been posted, it will show a link to encourage the user to submit.</li>\n<li><a href=\"https://muut.com/\">Muut.com</a> - Embeddable comments, forum and private messaging. A lot of functionality, but really low footprint left on your website.</li>\n<li><a href=\"https://github.com/imsun/gitment\">Gitment</a> - Comment system based on GitHub Issues, which can be used in the frontend without any server-side implementation.</li>\n<li><a href=\"https://github.com/laymonage/giscus\">giscus</a> - A comments widget built on GitHub Discussions.</li>\n</ul>\n<h3>Forms</h3>\n<h4>Really Simple Forms</h4>\n<ul>\n<li><a href=\"http://formspree.io/\">Formspree</a> - Receive emails from a form on your static website.</li>\n<li><a href=\"https://www.elformo.com/\">elFormo</a> - Simple form processing and response retrieval via email.</li>\n<li><a href=\"http://flipmail.co/\">Flipmail</a> - Simple form processing and response retrieval via email.</li>\n<li><a href=\"http://mailthis.to/\">MailThis</a> - Simple form submissions via email with optional attachments.</li>\n<li><a href=\"https://getsimpleform.com/\">Simple Form</a> - Simple forms with optional file attachments, email notifications, and online submission viewing.</li>\n<li><a href=\"https://github.com/stevensona/briskforms\">Brisk Forms</a> - Free form submission service emails you responses while keeping your email address private and is open source.</li>\n<li><a href=\"https://www.99inbound.com\">99 Inbound</a> - Form endpoint service with email/Slack notifications and third party app integrations (e.g. MailChimp)</li>\n<li><a href=\"http://getform.io/\">Getform</a> - Form backend platform for designers and developers, with email and integrations.</li>\n<li><a href=\"https://form.taxi/\">Form.taxi</a> - Backend to handle form submissions easily and reliably, with email notifications, file uploads and GDPR-compliant data processing.</li>\n</ul>\n<h4>Normal Forms</h4>\n<ul>\n<li><a href=\"https://formcarry.com\">Formcarry</a> - Hassle-free HTML form endpoints for your form, powerful dashboard, reliable spam blocking, attachment uploads and Zapier integrations.</li>\n<li><a href=\"https://formcake.com\">Formcake</a> - The form backend built for developers: Zapier integrations, simple endpoint API, unlimited forms.</li>\n<li><a href=\"https://www.google.com/forms/about/\">Google Forms</a> - Saves results into Google Sheets and can email you when there is a submission.</li>\n<li><a href=\"https://formkeep.com/\">FormKeep</a> - Paid - View form submissions in a beautiful web interface. It has spam filtering and it integrates with webhooks such as Gmail, Trello, and Basecamp.</li>\n<li><a href=\"http://www.123contactform.com/\">123 Contact Form</a> - Connects to other online services such at MailChimp, Salesforce, and Google Drive. It also integrates with payment Processers and includes security and analytics.</li>\n<li><a href=\"http://www.formassembly.com/\">FormAssembly</a> - Allows you to build any kind of form that can include complex branching logic and multiple pages.</li>\n<li><a href=\"https://www.formsite.com/\">FormSite</a> - Form builder with payments and form management.</li>\n<li><a href=\"https://www.formstack.com/\">FormStack</a> - Forms with A/B testing, partial submission, analytics, and integrations.</li>\n<li><a href=\"https://sheetsu.com/\">Sheetsu</a> - POST and GET your data to Google Spreadsheet.</li>\n<li><a href=\"http://www.typeform.com/\">Typeform</a> - Awesome forms that can be embedded.</li>\n<li><a href=\"http://www.wufoo.com/\">Wufoo</a> - Free or Paid - Forms that you can build with a form designer, with notifications, reports, and payments.</li>\n<li><a href=\"https://www.zoho.com/crm/help/web-forms/set-up-web-forms.html\">Zoho</a> - Forms with file upload and captcha.</li>\n<li><a href=\"https://help.github.com/articles/about-issues/\">GitHub Issues</a> - This is an interesting way for developers to get comments/questions. See <a href=\"https://github.com/sindresorhus/ama\">github.com/sindresorhus/ama</a> for an example.</li>\n<li><a href=\"https://github.com/utterance/utterances\">Utterences</a> - A lightweight comments widget built on GitHub issues.</li>\n<li><a href=\"https://www.formbackend.com\">FormBackend</a> - Create form-backends and submit your HTML forms to our backend. View the entries online and connect to other services. Receive an email every time a new entry is submitted.</li>\n<li><a href=\"https://pageclip.co\">Pageclip</a> - A flexible server / backend for HTML forms. View your data in the realtime web interface, or use the API to get CSV and JSON output.</li>\n<li><a href=\"https://www.formester.com\">Formester</a> - Forms and email marketing (lead collection, email campaigns, and newsletters) with integrations.</li>\n<li><a href=\"https://statickit.com\">StaticKit</a> - Modern forms for static sites, with native support for React.</li>\n<li><a href=\"https://sheetdb.io/\">SheetDB</a> - Turn a Google Spreadsheet into a JSON API.</li>\n</ul>\n<h4>Provided by the Host</h4>\n<ul>\n<li><a href=\"https://www.netlify.com/docs/form-handling/\">Netlify</a> - Netlify comes with built-in form handling.</li>\n</ul>\n<h3>Live Chat</h3>\n<ul>\n<li><a href=\"https://www.jivochat.com/\">jivochat</a> - JivoSite is a professional live chat for websites that was specifically designed to increase your online sales.</li>\n<li><a href=\"https://www.livechatinc.com/\">LiveChat</a> - Live chat on your website.</li>\n<li><a href=\"https://www.olark.com/\">Olark</a> - Live chat on your website. You can also see who's on your website and what they're doing.</li>\n<li><a href=\"https://snapengage.com/\">SnapEngage</a> - Live chat with integrations and custom styles.</li>\n<li><a href=\"https://www.tawk.to/\">tawk.co</a> - Lets you monitor and chat with visitors on your website.</li>\n<li><a href=\"https://www.websitealive.com/\">WebsiteAlive</a> - Live chat for your website &#x26; social networks.</li>\n<li><a href=\"https://www.zopim.com/\">Zopim</a> - Live chat with free trial.</li>\n</ul>\n<h3>Newsletters</h3>\n<ul>\n<li><a href=\"http://mailchimp.com/\">MailChimp</a> - Free email marketing. You can pay to add more features.</li>\n<li><a href=\"http://www.constantcontact.com/\">Constant Contact</a> - Email marketing with campaigns, autoresponders, and analytics.</li>\n<li><a href=\"http://www.aweber.com/\">AWeber</a> - Email marketing with campaigns, autoresponders, and analytics.</li>\n<li><a href=\"https://www.campaignmonitor.com/\">Campaign Monitor</a> - Email marketing with campaigns, autoresponders, and analytics.</li>\n<li><a href=\"https://www.mailerlite.com/\">MailerLite</a> - Free email marketing. You can pay for more subscribers.</li>\n</ul>\n<h3>Social Media</h3>\n<ul>\n<li><a href=\"https://developers.pinterest.com/\">Pinterest</a> - Pin It Button.</li>\n<li><a href=\"https://dev.twitter.com/web/embedded-tweets\">Twitter</a> - Embedded tweets.</li>\n<li><a href=\"https://developers.facebook.com/docs/plugins\">Facebook</a> - Facebook embedded plugins.</li>\n<li><a href=\"http://www.sharethis.com/\">ShareThis</a> - Sharing buttons for multiple social networks.</li>\n<li><a href=\"https://www.kontaktify.com/\">Kontaktify</a> - A contact widget that provides an easy way for visitors to get in touch.</li>\n</ul>\n<h3>Surveys</h3>\n<ul>\n<li><a href=\"https://www.google.co.nz/forms/about/\">Google Forms</a> - You can use Google forms for surveys or for forms on your site.</li>\n<li><a href=\"https://www.surveymonkey.com/\">SurveyMonkey</a> - Easy to use and free surveys.</li>\n<li><a href=\"http://www.typeform.com/\">Typeform</a> - Really beautiful forms.</li>\n<li><a href=\"https://qualaroo.com/\">Qualaroo</a> - Embed surveys anywhere on your website that comes up from the bottom right side of the screen.</li>\n<li><a href=\"https://insightstash.com/\">Insight Stash</a> - Fast, Simple survey forms.</li>\n</ul>\n<h2>E-Commerce</h2>\n<ul>\n<li><a href=\"https://www.ecwid.com/\">Ecwid</a> - Embeddable shopping cart.</li>\n<li><a href=\"http://www.foxycart.com/\">FoxyCart</a> - Add a shopping cart with basic html code.</li>\n<li><a href=\"https://snipcart.com/\">Snipcart</a> - Include a few lines of code for a full online shop.</li>\n<li><a href=\"https://gumroad.com/\">Gumroad</a> - An all-in-one solution to sell your work.</li>\n<li><a href=\"https://payhip.com/\">Payhip</a> - An embeddable way to sell digital downloads &#x26; memberships</li>\n<li><a href=\"https://moltin.com/\">Moltin</a> - Add eCommerce functionality to anything.</li>\n<li><a href=\"https://trolley.link/\">Trolley</a> - Add a popup cart to any website - designed for static &#x26; JAMstack sites.</li>\n<li><a href=\"https://commercelayer.io/\">Commerce Layer</a> - Add enterprise ecommerce to your JAMstack.</li>\n</ul>\n<h2>Payments</h2>\n<ul>\n<li><a href=\"https://www.moneybutton.com/\">MoneyButton</a> - Website payments and donations using Bitcoin (Satoshi's Vision).</li>\n<li><a href=\"https://info.shapeshift.io/tools/shifty-button\">ShapeShift Shifty Button</a> - Accept payments using various cryptocurrencies.</li>\n</ul>\n<h2>Search</h2>\n<p>Self-hosted:</p>\n<ul>\n<li><a href=\"http://lunrjs.com/\">lunr.js</a> - Simple full-text search in your browser.</li>\n<li><a href=\"https://github.com/itemsapi/itemsjs\">itemsjs</a> - Full text, faceted, almost dependency free search engine in javascript</li>\n<li><a href=\"https://github.com/lucaong/minisearch\">minisearch</a> - Tiny and powerful JavaScript full-text search engine for browser and Node</li>\n<li><a href=\"https://github.com/nextapps-de/flexsearch\">flexsearch</a> - Next-Generation full text search library for Browser and Node.js</li>\n<li><a href=\"https://fusejs.io/\">fuse.js</a> - Powerful, lightweight fuzzy-search library, with zero dependencies</li>\n<li><a href=\"https://github.com/dchest/static-search\">static-search</a> - A Go program to generate JSON index of HTML files, and a JavaScript component with optional UI to search this index</li>\n<li><a href=\"http://elasticlunr.com/docs/index.html\">elasticlunr</a> - Lightweight full-text search engine developed in JavaScript for browser search and offline search based on Lunr.js</li>\n<li><a href=\"https://github.com/tinysearch/tinysearch\">tinysearch</a> - Tiny, full-text search engine for static websites built with Rust and Wasm</li>\n<li><a href=\"https://www.npmjs.com/package/js-search\">js-search</a> - Client-side searches of JavaScript and JSON objects, ES5 compatible and does not require jQuery or any other third-party libraries</li>\n<li><a href=\"https://github.com/fergiemcdowall/search-index\">search-index</a> - A persistent, network resilient, full text search library for the browser and Node.js</li>\n<li><a href=\"https://github.com/bevacqua/fuzzysearch\">fuzzysearch</a> - Tiny and blazing-fast fuzzy search in JavaScript</li>\n<li><a href=\"https://github.com/mattyork/fuzzy\">fuzzy</a> - Fuzzy search / filter for browser and node</li>\n<li><a href=\"https://reyesr.github.io/fullproof/\">fullproof</a> - Javascript library that provides high-quality full-text search in the browser</li>\n<li><a href=\"https://jets.js.org/\">Jets.js</a> - Native CSS search engine</li>\n</ul>\n<p>Third party integration:</p>\n<ul>\n<li><a href=\"https://cse.google.com/cse/\">Google Custom Search Engine</a> - Search your site with a custom Google Search.</li>\n<li><a href=\"https://www.algolia.com/\">Algolia</a> - Hosted Search API that delivers instant and relevant results from the first keystroke.</li>\n<li><a href=\"https://cloudsh.com/\">CloudSh</a> - Powerful search for your website with a few lines of JavaScript.</li>\n</ul>\n<h2>Analytics</h2>\n<ul>\n<li><a href=\"http://www.google.com/analytics/\">Google Analytics</a> - Freemium web analytics service offered by Google.</li>\n<li><a href=\"https://simpleanalytics.io/\">Simple Analytics</a> - 💲 - Simple, clean, and friendly analytics.</li>\n</ul>\n<h2>Authentication</h2>\n<ul>\n<li><a href=\"https://uthentic.net\">Uthentic</a> - Serverless, passwordless login for static sites in 2 lines of code.</li>\n</ul>\n<h2>Other</h2>\n<ul>\n<li><a href=\"https://sketchfab.com/\">Sketch Fab</a> - Embeddable 3D content.</li>\n</ul>\n<h2>Related Lists</h2>\n<ul>\n<li><a href=\"https://github.com/b-long/awesome-static-hosting\">Awesome Static Hosting</a></li>\n<li><a href=\"https://github.com/staticwebdev/awesome-azure-static-web-apps\">Awesome Azure Static Web Apps</a></li>\n</ul>"},{"url":"/docs/reference/art-of-command-line/","relativePath":"docs/reference/art-of-command-line.md","relativeDir":"docs/reference","base":"art-of-command-line.md","name":"art-of-command-line","frontmatter":{"title":"Command Line Basics","weight":0,"excerpt":"Learn basic Bash. Actually, type man bash and at least skim the whole thing; it's pretty easy to follow and not that long. Alternate shells can be nice, but Bash is powerful and always available (learning *only* zsh, fish, etc., while tempting on your own laptop, restricts you in many situations, such as using existing servers).","seo":{"title":"Command Line Basics","description":"This guide is for both beginners and experienced users.","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Meta</h2>\n<p>Scope:</p>\n<ul>\n<li>This guide is for both beginners and experienced users. The goals are <em>breadth</em> (everything important), <em>specificity</em> (give concrete examples of the most common case), and <em>brevity</em> (avoid things that aren't essential or digressions you can easily look up elsewhere). Every tip is essential in some situation or significantly saves time over alternatives.</li>\n<li>This is written for Linux, with the exception of the \"<a href=\"#macos-only\">macOS only</a>\" and \"<a href=\"#windows-only\">Windows only</a>\" sections. Many of the other items apply or can be installed on other Unices or macOS (or even Cygwin).</li>\n<li>The focus is on interactive Bash, though many tips apply to other shells and to general Bash scripting.</li>\n<li>It includes both \"standard\" Unix commands as well as ones that require special package installs -- so long as they are important enough to merit inclusion.</li>\n</ul>\n<p>Notes:</p>\n<ul>\n<li>To keep this to one page, content is implicitly included by reference. You're smart enough to look up more detail elsewhere once you know the idea or command to Google. Use <code class=\"language-text\">apt</code>, <code class=\"language-text\">yum</code>, <code class=\"language-text\">dnf</code>, <code class=\"language-text\">pacman</code>, <code class=\"language-text\">pip</code> or <code class=\"language-text\">brew</code> (as appropriate) to install new programs.</li>\n<li>Use <a href=\"http://explainshell.com/\">Explainshell</a> to get a helpful breakdown of what commands, options, pipes etc. do.</li>\n</ul>\n<h2>Basics</h2>\n<ul>\n<li>Learn basic Bash. Actually, type <code class=\"language-text\">man bash</code> and at least skim the whole thing; it's pretty easy to follow and not that long. Alternate shells can be nice, but Bash is powerful and always available (learning <em>only</em> zsh, fish, etc., while tempting on your own laptop, restricts you in many situations, such as using existing servers).</li>\n<li>-</li>\n<li>Learn at least one text-based editor well. The <code class=\"language-text\">nano</code> editor is one of the simplest for basic editing (opening, editing, saving, searching). However, for the power user in a text terminal, there is no substitute for Vim (<code class=\"language-text\">vi</code>), the hard-to-learn but venerable, fast, and full-featured editor. Many people also use the classic Emacs, particularly for larger editing tasks. (Of course, any modern software developer working on an extensive project is unlikely to use only a pure text-based editor and should also be familiar with modern graphical IDEs and tools.)</li>\n<li>\n<p>Finding documentation:</p>\n<ul>\n<li>Know how to read official documentation with <code class=\"language-text\">man</code> (for the inquisitive, <code class=\"language-text\">man man</code> lists the section numbers, e.g. 1 is \"regular\" commands, 5 is files/conventions, and 8 are for administration). Find man pages with <code class=\"language-text\">apropos</code>.</li>\n<li>Know that some commands are not executables, but Bash builtins, and that you can get help on them with <code class=\"language-text\">help</code> and <code class=\"language-text\">help -d</code>. You can find out whether a command is an executable, shell builtin or an alias by using <code class=\"language-text\">type command</code>.</li>\n<li><code class=\"language-text\">curl cheat.sh/command</code> will give a brief \"cheat sheet\" with common examples of how to use a shell command.</li>\n</ul>\n</li>\n<li>Learn about redirection of output and input using <code class=\"language-text\">></code> and <code class=\"language-text\">&lt;</code> and pipes using <code class=\"language-text\">|</code>. Know <code class=\"language-text\">></code> overwrites the output file and <code class=\"language-text\">>></code> appends. Learn about stdout and stderr.</li>\n<li>-</li>\n<li>Learn about file glob expansion with <code class=\"language-text\">*</code> (and perhaps <code class=\"language-text\">?</code> and <code class=\"language-text\">[</code>...<code class=\"language-text\">]</code>) and quoting and the differen</li>\n<li>-</li>\n<li>Be familiar with Bash job management: <code class=\"language-text\">&amp;</code>, <strong>ctrl-z</strong>, <strong>ctrl-c</strong>, <code class=\"language-text\">jobs</code>, <code class=\"language-text\">fg</code>, <code class=\"language-text\">bg</code>, <code class=\"language-text\">kill</code>, etc.</li>\n<li>-</li>\n<li>Know <code class=\"language-text\">ssh</code>, and the basics of passwordless authentication, via `ssh</li>\n<li>-</li>\n<li>Basic file management: <code class=\"language-text\">ls</code> and <code class=\"language-text\">ls -l</code> (in particular, learn what every column in <code class=\"language-text\">ls -l</code> means), <code class=\"language-text\">less</code>, <code class=\"language-text\">head</code>, <code class=\"language-text\">tail</code> and <code class=\"language-text\">tail -f</code> (or even better, <code class=\"language-text\">less +F</code>), <code class=\"language-text\">ln</code> and <code class=\"language-text\">ln -s</code> (learn the differences and advantages of hard versus soft links), <code class=\"language-text\">chown</code>, <code class=\"language-text\">chmod</code>, <code class=\"language-text\">du</code> (for a quick summary of disk usage: <code class=\"language-text\">du -hs *</code>). For filesystem management, <code class=\"language-text\">df</code>, <code class=\"language-text\">mount</code>, <code class=\"language-text\">fdisk</code>, <code class=\"language-text\">mkfs</code>, <code class=\"language-text\">lsblk</code>. Learn what an inode is (<code class=\"language-text\">ls -i</code> or <code class=\"language-text\">df -i</code>).</li>\n<li>Basic network management: <code class=\"language-text\">ip</code> or <code class=\"language-text\">ifconfig</code>, <code class=\"language-text\">dig</code>, <code class=\"language-text\">traceroute</code>, <code class=\"language-text\">route</code>.</li>\n<li>Learn and use a version control management system, such as <code class=\"language-text\">git</code>.</li>\n<li>Know regular expressions well, and the various flags to <code class=\"language-text\">grep</code>/<code class=\"language-text\">egrep</code>. The <code class=\"language-text\">-i</code>, <code class=\"language-text\">-o</code>, <code class=\"language-text\">-v</code>, <code class=\"language-text\">-A</code>, <code class=\"language-text\">-B</code>, and <code class=\"language-text\">-C</code> options are worth knowing.</li>\n<li>Learn to use <code class=\"language-text\">apt-get</code>, <code class=\"language-text\">yum</code>, <code class=\"language-text\">dnf</code> or <code class=\"language-text\">pacman</code> (depending on distro) to find and install packages. And make sure you have <code class=\"language-text\">pip</code> to install Python-based command-line tools (a few below are easiest to install via <code class=\"language-text\">pip</code>).</li>\n</ul>\n<h2>Everyday use</h2>\n<ul>\n<li>In Bash, use <strong>Tab</strong> to complete arguments or list all available commands and <strong>ctrl-r</strong> to search through command history (after pressing, type to search, press <strong>ctrl-r</strong> repeatedly to cycle through more matches, press <strong>Enter</strong> to execute the found command, or hit the right arrow to put the result in the current line to allow editing).</li>\n<li>-</li>\n<li>In Bash, use <strong>ctrl-w</strong> to delete the last word, and <strong>ctrl-u</strong> to delete the content from current curso</li>\n<li>-</li>\n<li>Alternatively, if you love vi-style key-bindings, use <code class=\"language-text\">set -o vi</code> (and <code class=\"language-text\">set -o emacs</code> to put it back).</li>\n<li>-</li>\n<li>For editing long commands, after setting your editor (f</li>\n<li>-</li>\n<li>To see recent commands, use <code class=\"language-text\">history</code>. Follow with <code class=\"language-text\">!n</code> (where <code class=\"language-text\">n</code> is the command number) to execute again. There are also many abbreviations you can use, the most useful probably being <code class=\"language-text\">!$</code> for last argument and <code class=\"language-text\">!!</code> for last command (see \"HISTORY EXPANSION\" in the man page). However, these are often easily replaced with <strong>ctrl-r</strong> and <strong>alt-.</strong>.</li>\n<li>Go to your home directory with <code class=\"language-text\">cd</code>. Access files relative to your home directory with the <code class=\"language-text\">~</code> prefix (e.g. <code class=\"language-text\">~/.bashrc</code>). In <code class=\"language-text\">sh</code> scripts refer to the home directory as <code class=\"language-text\">$HOME</code>.</li>\n<li>To go back to the previous working directory: <code class=\"language-text\">cd -</code>.</li>\n<li>If you are halfway through typing a command but change your mind, hit <strong>alt-#</strong> to add a <code class=\"language-text\">#</code> at the beginning and enter it as a comment (or use <strong>ctrl-a</strong>, <strong>#</strong>, <strong>enter</strong>). You can then return to it later via command history.</li>\n<li>Use <code class=\"language-text\">xargs</code> (or <code class=\"language-text\">parallel</code>). It's very powerful. Note you can control how many items execute per line (<code class=\"language-text\">-L</code>) as well as parallelism (<code class=\"language-text\">-P</code>). If you're not sure if it'll do the right thing, use <code class=\"language-text\">xargs echo</code> first. Also, <code class=\"language-text\">-I{}</code> is handy. Examples:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'*.py'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token function\">grep</span> some_function\n      <span class=\"token function\">cat</span> hosts <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> -I<span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token function\">ssh</span> root@<span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token function\">hostname</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">pstree -p</code> is a helpful display of the process tree.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">pgrep</code> and <code class=\"language-text\">pkill</code> to find or signal processes by name (<code class=\"language-text\">-f</code> is helpful).</li>\n<li>-</li>\n<li>Know the various signals you can send processes. For example, to suspend a process, use <code class=\"language-text\">kill -STOP [pid]</code>. For the full list, see <code class=\"language-text\">man 7 signal</code></li>\n<li>-</li>\n<li>Use <code class=\"language-text\">nohup</code> or <code class=\"language-text\">disown</code> if you want a background process to keep ru</li>\n<li>-</li>\n<li>Check what processes are listening via <code class=\"language-text\">netstat -lntp</code> or <code class=\"language-text\">ss -plat</code> (for TCP; add <code class=\"language-text\">-u</code> for UDP) or <code class=\"language-text\">lsof -iTCP -sTCP:LISTEN -P -n</code> (which also works on macOS).</li>\n<li>-</li>\n<li>See also <code class=\"language-text\">lsof</code> and <code class=\"language-text\">fuser</code> for open sockets and files.</li>\n<li>-</li>\n<li>See <code class=\"language-text\">uptime</code> or <code class=\"language-text\">w</code> to know how long the system has been running.</li>\n<li>Use <code class=\"language-text\">alias</code> to create shortcuts for commonly used commands. For example, <code class=\"language-text\">alias ll='ls -latr'</code> creates a new alias <code class=\"language-text\">ll</code>.</li>\n<li>Save aliases, shell settings, and functions you commonly use in <code class=\"language-text\">~/.bashrc</code>, and <a href=\"http://superuser.com/a/183980/7106\">arrange for login shells to source it</a>. This will make your setup available in all your shell sessions.</li>\n<li>Put the settings of environment variables as well as commands that should be executed when you login in <code class=\"language-text\">~/.bash_profile</code>. Separate configuration will be needed for shells you launch from graphical environment logins and <code class=\"language-text\">cron</code> jobs.</li>\n<li>Synchronize your configuration files (e.g. <code class=\"language-text\">.bashrc</code> and <code class=\"language-text\">.bash_profile</code>) among various computers with Git.</li>\n<li>Understand that care is needed when variables and filenames include whitespace. Surround your Bash variables with quotes, e.g. <code class=\"language-text\">\"$FOO\"</code>. Prefer the <code class=\"language-text\">-0</code> or <code class=\"language-text\">-print0</code> options to enable null characters to delimit filenames, e.g. <code class=\"language-text\">locate -0 pattern | xargs -0 ls -al</code> or <code class=\"language-text\">find / -print0 -type d | xargs -0 ls -al</code>. To iterate on filenames containing whitespace in a for loop, set your IFS to be a newline only using <code class=\"language-text\">IFS=$'\\n'</code>.</li>\n<li>In Bash scripts, use <code class=\"language-text\">set -x</code> (or the variant <code class=\"language-text\">set -v</code>, which logs raw input, including unexpanded variables and comments) for debugging output. Use strict modes unless you have a good reason not to: Use <code class=\"language-text\">set -e</code> to abort on errors (nonzero exit code). Use <code class=\"language-text\">set -u</code> to detect unset variable usages. Consider <code class=\"language-text\">set -o pipefail</code> too, to abort on errors within pipes (though read up on it more if you do, as this topic is a bit subtle). For more involved scripts, also use <code class=\"language-text\">trap</code> on EXIT or ERR. A useful habit is to start a script like this, which will make it detect and abort on common errors and print a message:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token builtin class-name\">set</span> <span class=\"token parameter variable\">-euo</span> pipefail\n      <span class=\"token builtin class-name\">trap</span> <span class=\"token string\">\"echo 'error: Script failed: see failed command above'\"</span> ERR</code></pre></div>\n<ul>\n<li>In Bash scripts, subshells (written with parentheses) are convenient ways to group commands. A common example is to temporarily move to a different working directory, e.g.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token comment\"># do something in current dir</span>\n      <span class=\"token punctuation\">(</span>cd /some/other/dir <span class=\"token operator\">&amp;&amp;</span> other-command<span class=\"token punctuation\">)</span>\n      <span class=\"token comment\"># continue in original dir</span></code></pre></div>\n<ul>\n<li>In Bash, note there are lots of kinds of variable expansion. Checking a variable exists: <code class=\"language-text\">${name:?error message}</code>. For example, if a Bash script requires a single argument, just write <code class=\"language-text\">input_file=${1:?usage: $0 input_file}</code>. Using a default value if a variable is empty: <code class=\"language-text\">${name:-default}</code>. If you want to have an additional (optional) parameter added to the previous example, you can use something like <code class=\"language-text\">output_file=${2:-logfile}</code>. If <code class=\"language-text\">$2</code> is omitted and thus empty, <code class=\"language-text\">output_file</code> will be set to <code class=\"language-text\">logfile</code>. Arithmetic expansion: <code class=\"language-text\">i=$(( (i + 1) % 5 ))</code>. Sequences: <code class=\"language-text\">{1..10}</code>. Trimming of strings: <code class=\"language-text\">${var%suffix}</code> and <code class=\"language-text\">${var#prefix}</code>. For example if <code class=\"language-text\">var=foo.pdf</code>, then <code class=\"language-text\">echo ${var%.pdf}.txt</code> prints <code class=\"language-text\">foo.txt</code>.</li>\n<li>-</li>\n<li>Brace expansion using <code class=\"language-text\">{</code>...<code class=\"language-text\">}</code> can reduce having to re-type similar text and automate combinations of items. This is helpful in examples like <code class=\"language-text\">mv foo.{txt,pdf} some-dir</code> (which moves both files), <code class=\"language-text\">cp somefile{,.bak}</code> (which expands to <code class=\"language-text\">cp somefile somefile.bak</code>) or <code class=\"language-text\">mkdir -p test-{a,b,c}/subtest-{1,2,3}</code> (which expands all possible combinations and creates a directory tree). Brace expansion is performe</li>\n<li>-</li>\n<li>The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; and filename expansion. (For example, a range like <code class=\"language-text\">{1..20}</code> cannot be expressed with variables using <code class=\"language-text\">{$a..$b}</code>. Use <code class=\"language-text\">seq</code> or a <code class=\"language-text\">for</code> loop instead, e.g., <code class=\"language-text\">seq $a $b</code> or <code class=\"language-text\">for((i=a; i&lt;=b; i++)); do ... ; done</code>.)</li>\n<li>The output of a command can be treated like a file via <code class=\"language-text\">&lt;(some command)</code> (known as process substitution). For example, compare local <code class=\"language-text\">/etc/hosts</code> with a remote one:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">diff</span> /etc/hosts <span class=\"token operator\">&lt;</span><span class=\"token punctuation\">(</span><span class=\"token function\">ssh</span> somehost <span class=\"token function\">cat</span> /etc/hosts<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>When writing scripts you may want to put all of your code in curly braces. If the closing brace is missing, your script will be prevented from executing due to a syntax error. This makes sense when your script is going to be downloaded from the web, since it prevents partially downloaded scripts from executing:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token punctuation\">{</span>\n      <span class=\"token comment\"># Your code here</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>A \"here document\" allows <a href=\"https://www.tldp.org/LDP/abs/html/here-docs.html\">redirection of multiple lines of input</a> as if from a file:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cat &lt;&lt;EOF\ninput\non multiple lines\nEOF</code></pre></div>\n<ul>\n<li>In Bash, redirect both standard output and standard error via: <code class=\"language-text\">some-command >logfile 2>&amp;1</code> or <code class=\"language-text\">some-command &amp;>logfile</code>. Often, to ensure a command does not leave an open file handle to standard input, tying it to the terminal you are in, it is also good practice to add <code class=\"language-text\">&lt;/dev/null</code>.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">man ascii</code> for a good ASCII table, with hex and decimal values. For general encoding info, <code class=\"language-text\">man unicode</code>, <code class=\"language-text\">man utf-8</code>, and <code class=\"language-text\">man latin1</code> are helpful.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">screen</code> or <a href=\"https://tmux.github.io/\"><code class=\"language-text\">tmux</code></a> to multiplex the screen, especially useful on remote ssh sessions and to detach and re-attach to a session. <code class=\"language-text\">byobu</code> can enhance screen or tmux by providing more information and easier management. A more minimal alternative for session persistence only is <a href=\"https://github.com/bogner/dtach\"><code class=\"language-text\">dtach</code></a>.</li>\n<li>In ssh, knowing how to port tunnel with <code class=\"language-text\">-L</code> or <code class=\"language-text\">-D</code> (and occasionally <code class=\"language-text\">-R</code>) is useful, e.g. to access web sites from a remote server.</li>\n<li>It can be useful to make a few optimizations to your ssh configuration; for example, this <code class=\"language-text\">~/.ssh/config</code> contains settings to avoid dropped connections in certain network environments, uses compression (which is helpful with scp over low-bandwidth connections), and multiplex channels to the same server with a local control file:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">      TCPKeepAlive=yes\n      ServerAliveInterval=15\n      ServerAliveCountMax=6\n      Compression=yes\n      ControlMaster auto\n      ControlPath /tmp/%r@%h:%p\n      ControlPersist yes</code></pre></div>\n<ul>\n<li>A few other options relevant to ssh are security sensitive and should be enabled with care, e.g. per subnet or host or in trusted networks: <code class=\"language-text\">StrictHostKeyChecking=no</code>, <code class=\"language-text\">ForwardAgent=yes</code></li>\n<li>-</li>\n<li>Consider <a href=\"https://mosh.mit.edu/\"><code class=\"language-text\">mosh</code></a> an alternative to ssh that uses UDP, avoiding dropped connections and adding convenience on the road (requires server-side setup).</li>\n<li>To get the permissions on a file in octal form, which is useful for system configuration but not available in <code class=\"language-text\">ls</code> and easy to bungle, use something like</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">stat</span> <span class=\"token parameter variable\">-c</span> <span class=\"token string\">'%A %a %n'</span> /etc/timezone</code></pre></div>\n<ul>\n<li>For interactive selection of values from the output of another command, use <a href=\"https://github.com/mooz/percol\"><code class=\"language-text\">percol</code></a> or <a href=\"https://github.com/junegunn/fzf\"><code class=\"language-text\">fzf</code></a>.</li>\n<li>-</li>\n<li>For interaction with files based on the output of another command (like <code class=\"language-text\">git</code>), use <code class=\"language-text\">fpp</code> (<a href=\"https://github.com/facebook/PathPicker\">PathPicker</a>).</li>\n<li>For a simple web server for all files in the current directory (and subdirs), available to anyone on your network, use:\n<code class=\"language-text\">python -m SimpleHTTPServer 7777</code> (for port 7777 and Python 2) and <code class=\"language-text\">python -m http.server 7777</code> (for port 7777 and Python 3).</li>\n<li>For running a command as another user, use <code class=\"language-text\">sudo</code>. Defaults to running as root; use <code class=\"language-text\">-u</code> to specify another user. Use <code class=\"language-text\">-i</code> to login as that user (you will be asked for <em>your</em> password).</li>\n<li>-</li>\n<li>For switching the shell to another user, use <code class=\"language-text\">su username</code> or <code class=\"language-text\">su - username</code>. The latter with \"-\" gets an environment as if another user just logged in. Omitting the username defaults to root. You will be asked for the password <em>of the user you are switching to</em>.</li>\n<li>-</li>\n<li>Know about the <a href=\"https://wiki.debian.org/CommonErrorMessages/ArgumentListTooLong\">128K limit</a> on command lines. This \"Argument list too long\" error is common when wildcard matching large numbers of files. (When this happens alternatives like <code class=\"language-text\">find</code> and <code class=\"language-text\">xargs</code> may help.)</li>\n<li>For a basic calculator (and of course access to Python in general), use the <code class=\"language-text\">python</code> interpreter. For example,</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> 2+3\n5</code></pre></div>\n<h2>Processing files and data</h2>\n<ul>\n<li>To locate a file by name in the current directory, <code class=\"language-text\">find . -iname '*something*'</code> (or similar). To find a file anywhere by name, use <code class=\"language-text\">locate something</code> (but bear in mind <code class=\"language-text\">updatedb</code> may not have indexed recently created files).</li>\n<li>-</li>\n<li>For general searching through source or data f</li>\n<li>-</li>\n<li>To convert HTML to text: <code class=\"language-text\">lynx -dump -stdin</code></li>\n<li>-</li>\n<li>For Markdown, HTML, and all kinds of document conversion,</li>\n<li>-</li>\n<li>If you must handle XML, <code class=\"language-text\">xmlstarlet</code> is old but good.</li>\n<li>-</li>\n<li>For JSON, use <a href=\"http://stedolan.github.io/jq/\"><code class=\"language-text\">jq</code></a>. For interactive use, also see [<code class=\"language-text\">jid</code>](<a href=\"https://github.com/si\">https://github.com/si</a></li>\n<li>-</li>\n<li>For YAML, use <a href=\"https://github.com/0k/shyaml\"><code class=\"language-text\">shyaml</code></a>.</li>\n<li>-</li>\n<li>For Excel or CSV files, <a href=\"https://github.com/onyxfish/csvkit\">csvkit</a> provides <code class=\"language-text\">in2csv</code>, <code class=\"language-text\">csvcut</code>, <code class=\"language-text\">csvjoin</code>, <code class=\"language-text\">csvgrep</code>, etc.</li>\n<li>-</li>\n<li>For Amazon S3, <a href=\"https://github.com/s3tools/s3cmd\"><code class=\"language-text\">s3cmd</code></a> is convenient and [<code class=\"language-text\">s4cmd</code>](<a href=\"https://gi\">https://gi</a></li>\n<li>-</li>\n<li>Know about <code class=\"language-text\">sort</code> and <code class=\"language-text\">uniq</code>, including uniq's <code class=\"language-text\">-u</code> and <code class=\"language-text\">-d</code> options -- see one-liners below. See also <code class=\"language-text\">comm</code>.</li>\n<li>Know about <code class=\"language-text\">cut</code>, <code class=\"language-text\">paste</code>, and <code class=\"language-text\">join</code> to manipulate text files. Many people use <code class=\"language-text\">cut</code> but forget about <code class=\"language-text\">join</code>.</li>\n<li>Know about <code class=\"language-text\">wc</code> to count newlines (<code class=\"language-text\">-l</code>), characters (<code class=\"language-text\">-m</code>), words (<code class=\"language-text\">-w</code>) and bytes (<code class=\"language-text\">-c</code>).</li>\n<li>Know about <code class=\"language-text\">tee</code> to copy from stdin to a file and also to stdout, as in <code class=\"language-text\">ls -al | tee file.txt</code>.</li>\n<li>For more complex calculations, including grouping, reversing fields, and statistical calculations, consider <a href=\"https://www.gnu.org/software/datamash/\"><code class=\"language-text\">datamash</code></a>.</li>\n<li>Know that locale affects a lot of command line tools in subtle ways, including sorting order (collation) and performance. Most Linux installations will set <code class=\"language-text\">LANG</code> or other locale variables to a local setting like US English. But be aware sorting will change if you change locale. And know i18n routines can make sort or other commands run <em>many times</em> slower. In some situations (such as the set operations or uniqueness operations below) you can safely ignore slow i18n routines entirely and use traditional byte-based sort order, using <code class=\"language-text\">export LC_ALL=C</code>.</li>\n<li>You can set a specific command's environment by prefixing its invocation with the environment variable settings, as in <code class=\"language-text\">TZ=Pacific/Fiji date</code>.</li>\n<li>Know basic <code class=\"language-text\">awk</code> and <code class=\"language-text\">sed</code> for simple data munging. See <a href=\"#one-liners\">One-liners</a> for examples.</li>\n<li>To replace all occurrences of a string in place, in one or more files:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      perl <span class=\"token parameter variable\">-pi.bak</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'s/old-string/new-string/g'</span> my-files-*.txt</code></pre></div>\n<ul>\n<li>To rename multiple files and/or search and replace within files, try <a href=\"https://github.com/jlevy/repren\"><code class=\"language-text\">repren</code></a>. (In some cases the <code class=\"language-text\">rename</code> command also allows multiple renames, but be careful as its functionality is not the same on all Linux distributions.)</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token comment\"># Full rename of filenames, directories, and contents foo -> bar:</span>\n      repren <span class=\"token parameter variable\">--full</span> --preserve-case <span class=\"token parameter variable\">--from</span> foo <span class=\"token parameter variable\">--to</span> bar <span class=\"token builtin class-name\">.</span>\n      <span class=\"token comment\"># Recover backup files whatever.bak -> whatever:</span>\n      repren <span class=\"token parameter variable\">--renames</span> <span class=\"token parameter variable\">--from</span> <span class=\"token string\">'(.*)\\.bak'</span> <span class=\"token parameter variable\">--to</span> <span class=\"token string\">'\\1'</span> *.bak\n      <span class=\"token comment\"># Same as above, using rename, if available:</span>\n      <span class=\"token function\">rename</span> <span class=\"token string\">'s/\\.bak$//'</span> *.bak</code></pre></div>\n<ul>\n<li>As the man page says, <code class=\"language-text\">rsync</code> really is a fast and extraordinarily versatile file copying tool. It's known for synchronizing between machines but is equally useful locally. When security restrictions allow, using <code class=\"language-text\">rsync</code> instead of <code class=\"language-text\">scp</code> allows recovery of a transfer without restarting from scratch. It also is among the <a href=\"https://web.archive.org/web/20130929001850/http://linuxnote.net/jianingy/en/linux/a-fast-way-to-remove-huge-number-of-files.html\">fastest ways</a> to delete large numbers of files:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">mkdir</span> empty <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">rsync</span> <span class=\"token parameter variable\">-r</span> <span class=\"token parameter variable\">--delete</span> empty/ some-dir <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">rmdir</span> some-dir</code></pre></div>\n<ul>\n<li>For monitoring progress when processing files, use <a href=\"http://www.ivarch.com/programs/pv.shtml\"><code class=\"language-text\">pv</code></a>, <a href=\"https://github.com/dmerejkowsky/pycp\"><code class=\"language-text\">pycp</code></a>, <a href=\"https://github.com/dspinellis/pmonitor\"><code class=\"language-text\">pmonitor</code></a>, <a href=\"https://github.com/Xfennec/progress\"><code class=\"language-text\">progress</code></a>, <code class=\"language-text\">rsync --progress</code>, or, for block-level copying, <code class=\"language-text\">dd status=progress</code>.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">shuf</code> to shuffle or select random lines from a file.</li>\n<li>-</li>\n<li>Know <code class=\"language-text\">sort</code>'s options. For numbers, use <code class=\"language-text\">-n</code>, or <code class=\"language-text\">-h</code> for handling human-readable numbers (e.g. from <code class=\"language-text\">du -h</code>). Know how keys work (<code class=\"language-text\">-t</code> and <code class=\"language-text\">-k</code>). In particular, watch out that you need to write <code class=\"language-text\">-k1,1</code> to sort by only the first field; <code class=\"language-text\">-k1</code> means sort according to the whole line. Stable sort (<code class=\"language-text\">sort -s</code>) ca</li>\n<li>-</li>\n<li>If you ever need to write a tab literal in a command line in Bash (e.g. for the -t</li>\n<li>-</li>\n<li>The standard tools for patching source code are <code class=\"language-text\">diff</code> and <code class=\"language-text\">patch</code>. See also <code class=\"language-text\">diffstat</code> for summary statistics of a diff and <code class=\"language-text\">sdiff</code> for a side-by-side diff. Note <code class=\"language-text\">diff -r</code> works for entire directories. Use <code class=\"language-text\">diff -r tree1 tree2 | diffstat</code> for a summary of changes. Use <code class=\"language-text\">vimdiff</code> to compare and edit files.</li>\n<li>For binary files, use <code class=\"language-text\">hd</code>, <code class=\"language-text\">hexdump</code> or <code class=\"language-text\">xxd</code> for simple hex dumps and <code class=\"language-text\">bvi</code>, <code class=\"language-text\">hexedit</code> or <code class=\"language-text\">biew</code> for binary editing.</li>\n<li>Also for binary files, <code class=\"language-text\">strings</code> (plus <code class=\"language-text\">grep</code>, etc.) lets you find bits of text.</li>\n<li>For binary diffs (delta compression), use <code class=\"language-text\">xdelta3</code>.</li>\n<li>To convert text encodings, try <code class=\"language-text\">iconv</code>. Or <code class=\"language-text\">uconv</code> for more advanced use; it supports some advanced Unicode things. For example:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token comment\"># Displays hex codes or actual names of characters (useful for debugging):</span>\n      uconv <span class=\"token parameter variable\">-f</span> utf-8 <span class=\"token parameter variable\">-t</span> utf-8 <span class=\"token parameter variable\">-x</span> <span class=\"token string\">'::Any-Hex;'</span> <span class=\"token operator\">&lt;</span> input.txt\n      uconv <span class=\"token parameter variable\">-f</span> utf-8 <span class=\"token parameter variable\">-t</span> utf-8 <span class=\"token parameter variable\">-x</span> <span class=\"token string\">'::Any-Name;'</span> <span class=\"token operator\">&lt;</span> input.txt\n      <span class=\"token comment\"># Lowercase and removes all accents (by expanding and dropping them):</span>\n      uconv <span class=\"token parameter variable\">-f</span> utf-8 <span class=\"token parameter variable\">-t</span> utf-8 <span class=\"token parameter variable\">-x</span> <span class=\"token string\">'::Any-Lower; ::Any-NFD; [:Nonspacing Mark:] >; ::Any-NFC;'</span> <span class=\"token operator\">&lt;</span> input.txt <span class=\"token operator\">></span> output.txt</code></pre></div>\n<ul>\n<li>To split files into pieces, see <code class=\"language-text\">split</code> (to split by size) and <code class=\"language-text\">csplit</code> (to split by a pattern).</li>\n<li>-</li>\n<li>Date and time: To get the current date and time in the helpful [ISO 8601](h</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">zless</code>, <code class=\"language-text\">zmore</code>, <code class=\"language-text\">zcat</code>, and <code class=\"language-text\">zgrep</code> to operate on compressed files.</li>\n<li>File attributes are settable via <code class=\"language-text\">chattr</code> and offer a lower-level alternative to file permissions. For example, to protect against accidental file deletion the immutable flag: <code class=\"language-text\">sudo chattr +i /critical/directory/or/file</code></li>\n<li>Use <code class=\"language-text\">getfacl</code> and <code class=\"language-text\">setfacl</code> to save and restore file permissions. For example:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">   getfacl <span class=\"token parameter variable\">-R</span> /some/path <span class=\"token operator\">></span> permissions.txt\n   setfacl <span class=\"token parameter variable\">--restore</span><span class=\"token operator\">=</span>permissions.txt</code></pre></div>\n<ul>\n<li>To create empty files quickly, use <code class=\"language-text\">truncate</code> (creates <a href=\"https://en.wikipedia.org/wiki/Sparse_file\">sparse file</a>), <code class=\"language-text\">fallocate</code> (ext4, xfs, btrfs and ocfs2 filesystems), <code class=\"language-text\">xfs_mkfile</code> (almost any filesystems, comes in xfsprogs package), <code class=\"language-text\">mkfile</code> (for Unix-like systems like Solaris, Mac OS).</li>\n</ul>\n<h2>System debugging</h2>\n<ul>\n<li>For web debugging, <code class=\"language-text\">curl</code> and <code class=\"language-text\">curl -I</code> are handy, or their <code class=\"language-text\">wget</code> equivalents, or the more modern <a href=\"https://github.com/jkbrzt/httpie\"><code class=\"language-text\">httpie</code></a>.</li>\n<li>-</li>\n<li>To know current cpu/disk status, the classic tools are `t</li>\n<li>-</li>\n<li>For network connection details, use <code class=\"language-text\">netstat</code> and <code class=\"language-text\">ss</code>.</li>\n<li>-</li>\n<li>For a quick overview of what's happening on a system, <code class=\"language-text\">dstat</code> is especially useful. For broades</li>\n<li>-</li>\n<li>To know memory status, run and understand the output of <code class=\"language-text\">free</code> and <code class=\"language-text\">vmstat</code>. In particular, be aware the \"cached\" value is memory held by the Linux kernel a</li>\n<li>-</li>\n<li>Java system debugging is a different kettle of fish, but a simple trick on Oracle's and some other JVMs is that you can run <code class=\"language-text\">kill -3 &lt;pid></code> and a full stack trace and heap summary (including generational</li>\n<li>-</li>\n<li>Use <a href=\"http://www.bitwizard.nl/mtr/\"><code class=\"language-text\">mtr</code></a> as a better traceroute, to identify network issues.</li>\n<li>-</li>\n<li>For looking at why a disk is full, <a href=\"https://dev.yorhel.nl/ncdu\"><code class=\"language-text\">ncdu</code></a> saves time over the usual commands like <code class=\"language-text\">du -sh *</code>.</li>\n<li>-</li>\n<li>To find which socket or process is using bandwidth, try <a href=\"http://www.ex-parrot.com/~pdw/iftop/\"><code class=\"language-text\">iftop</code></a> or <a href=\"https://github.com/raboof/nethogs\"><code class=\"language-text\">nethogs</code></a>.</li>\n<li>-</li>\n<li>The <code class=\"language-text\">ab</code> tool (comes with Apache) is helpful for quick-and-dirty checking of web server perform</li>\n<li>-</li>\n<li>For more serious network debugging, <a href=\"https://wireshark.org/\"><code class=\"language-text\">wireshark</code></a>, <a href=\"https://www.wireshark.org/docs/wsug_html_chunked/AppToolstshark.html\"><code class=\"language-text\">tshark</code></a>, or <a href=\"http://ngrep.sourceforge.net/\"><code class=\"language-text\">ngrep</code></a>.</li>\n<li>Know about <code class=\"language-text\">strace</code> and <code class=\"language-text\">ltrace</code>. These can be helpful if a program is failing, hanging, or crashing, and you don't know why, or if you want to get a general idea of performance. Note the profiling option (<code class=\"language-text\">-c</code>), and the ability to attach to a running process (<code class=\"language-text\">-p</code>). Use trace child option (<code class=\"language-text\">-f</code>) to avoid missing important calls.</li>\n<li>Know about <code class=\"language-text\">ldd</code> to check shared libraries etc — but <a href=\"http://www.catonmat.net/blog/ldd-arbitrary-code-execution/\">never run it on untrusted files</a>.</li>\n<li>Know how to connect to a running process with <code class=\"language-text\">gdb</code> and get its stack traces.</li>\n<li>Use <code class=\"language-text\">/proc</code>. It's amazingly helpful sometimes when debugging live problems. Examples: <code class=\"language-text\">/proc/cpuinfo</code>, <code class=\"language-text\">/proc/meminfo</code>, <code class=\"language-text\">/proc/cmdline</code>, <code class=\"language-text\">/proc/xxx/cwd</code>, <code class=\"language-text\">/proc/xxx/exe</code>, <code class=\"language-text\">/proc/xxx/fd/</code>, <code class=\"language-text\">/proc/xxx/smaps</code> (where <code class=\"language-text\">xxx</code> is the process id or pid).</li>\n<li>When debugging why something went wrong in the past, <a href=\"http://sebastien.godard.pagesperso-orange.fr/\"><code class=\"language-text\">sar</code></a> can be very helpful. It shows historic statistics on CPU, memory, network, etc.</li>\n<li>For deeper systems and performance analyses, look at <code class=\"language-text\">stap</code> (<a href=\"https://sourceware.org/systemtap/wiki\">SystemTap</a>), <a href=\"https://en.wikipedia.org/wiki/Perf_%28Linux%29\"><code class=\"language-text\">perf</code></a>, and <a href=\"https://github.com/draios/sysdig\"><code class=\"language-text\">sysdig</code></a>.</li>\n<li>Check what OS you're on with <code class=\"language-text\">uname</code> or <code class=\"language-text\">uname -a</code> (general Unix/kernel info) or <code class=\"language-text\">lsb_release -a</code> (Linux distro info).</li>\n<li>Use <code class=\"language-text\">dmesg</code> whenever something's acting really funny (it could be hardware or driver issues).</li>\n<li>If you delete a file and it doesn't free up expected disk space as reported by <code class=\"language-text\">du</code>, check whether the file is in use by a process:\n<code class=\"language-text\">lsof | grep deleted | grep \"filename-of-my-big-file\"</code></li>\n</ul>\n<h2>One-liners</h2>\n<p>A few examples of piecing together commands:</p>\n<ul>\n<li>It is remarkably helpful sometimes that you can do set intersection, union, and difference of text files via <code class=\"language-text\">sort</code>/<code class=\"language-text\">uniq</code>. Suppose <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> are text files that are already uniqued. This is fast, and works on files of arbitrary size, up to many gigabytes. (Sort is not limited by memory, though you may need to use the <code class=\"language-text\">-T</code> option if <code class=\"language-text\">/tmp</code> is on a small root partition.) See also the note about <code class=\"language-text\">LC_ALL</code> above and <code class=\"language-text\">sort</code>'s <code class=\"language-text\">-u</code> option (left out for clarity below).</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">sort</span> a b <span class=\"token operator\">|</span> <span class=\"token function\">uniq</span> <span class=\"token operator\">></span> c   <span class=\"token comment\"># c is a union b</span>\n      <span class=\"token function\">sort</span> a b <span class=\"token operator\">|</span> <span class=\"token function\">uniq</span> <span class=\"token parameter variable\">-d</span> <span class=\"token operator\">></span> c   <span class=\"token comment\"># c is a intersect b</span>\n      <span class=\"token function\">sort</span> a b b <span class=\"token operator\">|</span> <span class=\"token function\">uniq</span> <span class=\"token parameter variable\">-u</span> <span class=\"token operator\">></span> c   <span class=\"token comment\"># c is set difference a - b</span></code></pre></div>\n<ul>\n<li>Pretty-print two JSON files, normalizing their syntax, then coloring and paginating the result:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">      diff &lt;(jq --sort-keys . &lt; file1.json) &lt;(jq --sort-keys . &lt; file2.json) | colordiff | less -R</code></pre></div>\n<ul>\n<li>Use <code class=\"language-text\">grep . *</code> to quickly examine the contents of all files in a directory (so each line is paired with the filename), or <code class=\"language-text\">head -100 *</code> (so each file has a heading). This can be useful for directories filled with config settings like those in <code class=\"language-text\">/sys</code>, <code class=\"language-text\">/proc</code>, <code class=\"language-text\">/etc</code>.</li>\n<li>-</li>\n<li>Summing all numbers in the third column of a text file (this is probably 3X faster and 3X less code than equivalent Python):</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">awk</span> <span class=\"token string\">'{ x += $3 } END { print x }'</span> myfile</code></pre></div>\n<ul>\n<li>To see sizes/dates on a tree of files, this is like a recursive <code class=\"language-text\">ls -l</code> but is easier to read than <code class=\"language-text\">ls -lR</code>:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-ls</span></code></pre></div>\n<ul>\n<li>Say you have a text file, like a web server log, and a certain value that appears on some lines, such as an <code class=\"language-text\">acct_id</code> parameter that is present in the URL. If you want a tally of how many requests for each <code class=\"language-text\">acct_id</code>:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">egrep</span> <span class=\"token parameter variable\">-o</span> <span class=\"token string\">'acct_id=[0-9]+'</span> access.log <span class=\"token operator\">|</span> <span class=\"token function\">cut</span> <span class=\"token parameter variable\">-d</span><span class=\"token operator\">=</span> <span class=\"token parameter variable\">-f2</span> <span class=\"token operator\">|</span> <span class=\"token function\">sort</span> <span class=\"token operator\">|</span> <span class=\"token function\">uniq</span> <span class=\"token parameter variable\">-c</span> <span class=\"token operator\">|</span> <span class=\"token function\">sort</span> <span class=\"token parameter variable\">-rn</span></code></pre></div>\n<ul>\n<li>To continuously monitor changes, use <code class=\"language-text\">watch</code>, e.g. check changes to files in a directory with <code class=\"language-text\">watch -d -n 2 'ls -rtlh | tail'</code> or to network settings while troubleshooting your wifi settings with <code class=\"language-text\">watch -d -n 2 ifconfig</code>.</li>\n<li>-</li>\n<li>Run this function to get a random tip from this document (parses Markdown and extracts an item):</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token keyword\">function</span> <span class=\"token function-name function\">taocl</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">curl</span> <span class=\"token parameter variable\">-s</span> https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README.md <span class=\"token operator\">|</span>\n          <span class=\"token function\">sed</span> <span class=\"token string\">'/cowsay[.]png/d'</span> <span class=\"token operator\">|</span>\n          pandoc <span class=\"token parameter variable\">-f</span> markdown <span class=\"token parameter variable\">-t</span> html <span class=\"token operator\">|</span>\n          xmlstarlet fo <span class=\"token parameter variable\">--html</span> <span class=\"token parameter variable\">--dropdtd</span> <span class=\"token operator\">|</span>\n          xmlstarlet sel <span class=\"token parameter variable\">-t</span> <span class=\"token parameter variable\">-v</span> <span class=\"token string\">\"(html/body/ul/li[count(p)>0])[<span class=\"token environment constant\">$RANDOM</span> mod last()+1]\"</span> <span class=\"token operator\">|</span>\n          xmlstarlet unesc <span class=\"token operator\">|</span> <span class=\"token function\">fmt</span> <span class=\"token parameter variable\">-80</span> <span class=\"token operator\">|</span> <span class=\"token function\">iconv</span> <span class=\"token parameter variable\">-t</span> US\n      <span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Obscure but useful</h2>\n<ul>\n<li><code class=\"language-text\">expr</code>: perform arithmetic or boolean operations or evaluate regular expressions</li>\n<li>-</li>\n<li><code class=\"language-text\">m4</code>: simple macro processor</li>\n<li>-</li>\n<li><code class=\"language-text\">yes</code>: print a string a lot</li>\n<li>-</li>\n<li><code class=\"language-text\">cal</code>: nice calendar</li>\n<li>-</li>\n<li><code class=\"language-text\">env</code>: run a command (useful in</li>\n<li>-</li>\n<li><code class=\"language-text\">printenv</code>: print out enviro</li>\n<li>-</li>\n<li><code class=\"language-text\">look</code>: find English words (or lines in a file) beginning</li>\n<li>-</li>\n<li><code class=\"language-text\">cut</code>, <code class=\"language-text\">paste</code> and `jo</li>\n<li>-</li>\n<li><code class=\"language-text\">fmt</code>: format text paragrap</li>\n<li>-</li>\n<li><code class=\"language-text\">pr</code>: format text into pages/colum</li>\n<li>-</li>\n<li><code class=\"language-text\">fold</code>: wrap lines of text</li>\n<li>-</li>\n<li><code class=\"language-text\">column</code>: format text fields into aligned, f</li>\n<li>-</li>\n<li><code class=\"language-text\">expand</code> and <code class=\"language-text\">unexpand</code>: convert between tabs and spaces</li>\n<li>-</li>\n<li><code class=\"language-text\">nl</code>: add line numbers</li>\n<li>-</li>\n<li><code class=\"language-text\">seq</code>: print numbers</li>\n<li>-</li>\n<li><code class=\"language-text\">bc</code>: calculator</li>\n<li>-</li>\n<li><code class=\"language-text\">factor</code>: factor integers</li>\n<li>-</li>\n<li><a href=\"https://gnupg.org/\"><code class=\"language-text\">gpg</code></a>: encrypt and si</li>\n<li>-</li>\n<li><code class=\"language-text\">toe</code>: table of terminfo entries</li>\n<li>-</li>\n<li><code class=\"language-text\">nc</code>: network debugging and data transfer</li>\n<li>-</li>\n<li><code class=\"language-text\">socat</code>: socket relay and tcp port</li>\n<li>-</li>\n<li>[<code class=\"language-text\">slurm</code>](<a href=\"https://github.com/\">https://github.com/</a></li>\n<li>-</li>\n<li><code class=\"language-text\">dd</code>: moving data between files or devices</li>\n<li>-</li>\n<li><code class=\"language-text\">file</code>: identify type of a file</li>\n<li>-</li>\n<li><code class=\"language-text\">tree</code>: display directories and subdirectories as a nesting tree;</li>\n<li>-</li>\n<li><code class=\"language-text\">stat</code>: file info</li>\n<li>-</li>\n<li><code class=\"language-text\">time</code>: execute and time a command</li>\n<li>-</li>\n<li><code class=\"language-text\">timeout</code>: execute a command for specified amount of time and stop the process when the s</li>\n<li>-</li>\n<li><code class=\"language-text\">lockfile</code>: create semaphor</li>\n<li>-</li>\n<li><code class=\"language-text\">logrotate</code>: rotate, compress and</li>\n<li>-</li>\n<li><code class=\"language-text\">watch</code>: run a command</li>\n<li>-</li>\n<li><a href=\"https://github.com/joh/when-changed\"><code class=\"language-text\">when-changed</code></a>: runs any command you spe</li>\n<li>-</li>\n<li><code class=\"language-text\">tac</code>: print files in rev</li>\n<li>-</li>\n<li><code class=\"language-text\">comm</code>: compare sorted files line by line</li>\n<li>-</li>\n<li><code class=\"language-text\">strings</code>: extract text from binary files</li>\n<li>-</li>\n<li><code class=\"language-text\">tr</code>: character translation or manipulation</li>\n<li>-</li>\n<li><code class=\"language-text\">iconv</code> or <code class=\"language-text\">uconv</code>: conversion for text encodings</li>\n<li><code class=\"language-text\">split</code> and <code class=\"language-text\">csplit</code>: splitting files</li>\n<li><code class=\"language-text\">sponge</code>: read all input before writing it, useful for reading from then writing to the same file, e.g., <code class=\"language-text\">grep -v something some-file | sponge some-file</code></li>\n<li><code class=\"language-text\">units</code>: unit conversions and calculations; converts furlongs per fortnight to twips per blink (see also <code class=\"language-text\">/usr/share/units/definitions.units</code>)</li>\n<li><code class=\"language-text\">apg</code>: generates random passwords</li>\n<li><code class=\"language-text\">xz</code>: high-ratio file compression</li>\n<li><code class=\"language-text\">ldd</code>: dynamic library info</li>\n<li><code class=\"language-text\">nm</code>: symbols from object files</li>\n<li><code class=\"language-text\">ab</code> or <a href=\"https://github.com/wg/wrk\"><code class=\"language-text\">wrk</code></a>: benchmarking web servers</li>\n<li><code class=\"language-text\">strace</code>: system call debugging</li>\n<li><a href=\"http://www.bitwizard.nl/mtr/\"><code class=\"language-text\">mtr</code></a>: better traceroute for network debugging</li>\n<li><code class=\"language-text\">cssh</code>: visual concurrent shell</li>\n<li><code class=\"language-text\">rsync</code>: sync files and folders over SSH or in local file system</li>\n<li><a href=\"https://wireshark.org/\"><code class=\"language-text\">wireshark</code></a> and <a href=\"https://www.wireshark.org/docs/wsug_html_chunked/AppToolstshark.html\"><code class=\"language-text\">tshark</code></a>: packet capture and network debugging</li>\n<li><a href=\"http://ngrep.sourceforge.net/\"><code class=\"language-text\">ngrep</code></a>: grep for the network layer</li>\n<li><code class=\"language-text\">host</code> and <code class=\"language-text\">dig</code>: DNS lookups</li>\n<li><code class=\"language-text\">lsof</code>: process file descriptor and socket info</li>\n<li><code class=\"language-text\">dstat</code>: useful system stats</li>\n<li><a href=\"https://github.com/nicolargo/glances\"><code class=\"language-text\">glances</code></a>: high level, multi-subsystem overview</li>\n<li><code class=\"language-text\">iostat</code>: Disk usage stats</li>\n<li><code class=\"language-text\">mpstat</code>: CPU usage stats</li>\n<li><code class=\"language-text\">vmstat</code>: Memory usage stats</li>\n<li><code class=\"language-text\">htop</code>: improved version of top</li>\n<li><code class=\"language-text\">last</code>: login history</li>\n<li><code class=\"language-text\">w</code>: who's logged on</li>\n<li><code class=\"language-text\">id</code>: user/group identity info</li>\n<li><a href=\"http://sebastien.godard.pagesperso-orange.fr/\"><code class=\"language-text\">sar</code></a>: historic system stats</li>\n<li><a href=\"http://www.ex-parrot.com/~pdw/iftop/\"><code class=\"language-text\">iftop</code></a> or <a href=\"https://github.com/raboof/nethogs\"><code class=\"language-text\">nethogs</code></a>: network utilization by socket or process</li>\n<li><code class=\"language-text\">ss</code>: socket statistics</li>\n<li><code class=\"language-text\">dmesg</code>: boot and system error messages</li>\n<li><code class=\"language-text\">sysctl</code>: view and configure Linux kernel parameters at run time</li>\n<li><code class=\"language-text\">hdparm</code>: SATA/ATA disk manipulation/performance</li>\n<li><code class=\"language-text\">lsblk</code>: list block devices: a tree view of your disks and disk partitions</li>\n<li><code class=\"language-text\">lshw</code>, <code class=\"language-text\">lscpu</code>, <code class=\"language-text\">lspci</code>, <code class=\"language-text\">lsusb</code>, <code class=\"language-text\">dmidecode</code>: hardware information, including CPU, BIOS, RAID, graphics, devices, etc.</li>\n<li><code class=\"language-text\">lsmod</code> and <code class=\"language-text\">modinfo</code>: List and show details of kernel modules.</li>\n<li><code class=\"language-text\">fortune</code>, <code class=\"language-text\">ddate</code>, and <code class=\"language-text\">sl</code>: um, well, it depends on whether you consider steam locomotives and Zippy quotations \"useful\"</li>\n</ul>\n<h2>macOS only</h2>\n<p>These are items relevant <em>only</em> on macOS.</p>\n<ul>\n<li>Package management with <code class=\"language-text\">brew</code> (Homebrew) and/or <code class=\"language-text\">port</code> (MacPorts). These can be used to install on macOS many of the above commands.</li>\n<li>-</li>\n<li>Copy output of any command to a desktop app with <code class=\"language-text\">pbcopy</code> and paste input from one with <code class=\"language-text\">pbpaste</code>.</li>\n<li>-</li>\n<li>To enable the Option key in macOS Terminal as an alt key (such as used in the commands above lik</li>\n<li>-</li>\n<li>To open a file with a desktop app, use <code class=\"language-text\">open</code> or <code class=\"language-text\">open -a /Applications/Whatever.app</code>.</li>\n<li>Spotlight: Search files with <code class=\"language-text\">mdfind</code> and list metadata (such as photo EXIF info) with <code class=\"language-text\">mdls</code>.</li>\n<li>Be aware macOS is based on BSD Unix, and many commands (for example <code class=\"language-text\">ps</code>, <code class=\"language-text\">ls</code>, <code class=\"language-text\">tail</code>, <code class=\"language-text\">awk</code>, <code class=\"language-text\">sed</code>) have many subtle variations from Linux, which is largely influenced by System V-style Unix and GNU tools. You can often tell the difference by noting a man page has the heading \"BSD General Commands Manual.\" In some cases GNU versions can be installed, too (such as <code class=\"language-text\">gawk</code> and <code class=\"language-text\">gsed</code> for GNU awk and sed). If writing cross-platform Bash scripts, avoid such commands (for example, consider Python or <code class=\"language-text\">perl</code>) or test carefully.</li>\n<li>To get macOS release information, use <code class=\"language-text\">sw_vers</code>.</li>\n</ul>\n<h2>Windows only</h2>\n<p>These items are relevant <em>only</em> on Windows.</p>\n<h3>Ways to obtain Unix tools under Windows</h3>\n<ul>\n<li>Access the power of the Unix shell under Microsoft Windows by installing <a href=\"https://cygwin.com/\">Cygwin</a>. Most of the things described in this document will work out of the box.</li>\n<li>-</li>\n<li>On Windows 10, you can use <a href=\"https://msdn.microsoft.com/commandline/wsl/about\">Windows Subsystem for Linux (WSL)</a>, which provides a familiar Bash environment with Unix command line utilities.</li>\n<li>-</li>\n<li>If you mainly want to use GNU developer tools (such as GCC) on Windows, consider <a href=\"http://www.mingw.org/\">MinGW</a> and its <a href=\"http://www.mingw.org/wiki/msys\">MSYS</a> package, which provides utilities such as bash, gawk, make and grep. MSYS doesn't have all the features compared to Cygwin. MinGW is particularly useful for creating native Windows ports of Unix tools.</li>\n<li>Another option to get Unix look and feel under Windows is <a href=\"https://github.com/dthree/cash\">Cash</a>. Note that only very few Unix commands and command-line options are available in this environment.</li>\n</ul>\n<h3>Useful Windows command-line tools</h3>\n<ul>\n<li>You can perform and script most Windows system administration tasks from the command line by learning and using <code class=\"language-text\">wmic</code>.</li>\n<li>-</li>\n<li>Native command-line Windows networking tools you may find useful include <code class=\"language-text\">ping</code>, <code class=\"language-text\">ipconfig</code>, <code class=\"language-text\">tracert</code>, and <code class=\"language-text\">netstat</code>.</li>\n<li>You can perform <a href=\"http://www.thewindowsclub.com/rundll32-shortcut-commands-windows\">many useful Windows tasks</a> by invoking the <code class=\"language-text\">Rundll32</code> command.</li>\n</ul>\n<h3>Cygwin tips and tricks</h3>\n<ul>\n<li>Install additional Unix programs with the Cygwin's package manager.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">mintty</code> as your command-line window.</li>\n<li>-</li>\n<li>Access the Windows clipboard through `/dev/cl</li>\n<li>-</li>\n<li>Run <code class=\"language-text\">cygstart</code> to open an arbitrary file through its registered application.</li>\n<li>Access the Windows registry with <code class=\"language-text\">regtool</code>.</li>\n<li>Note that a <code class=\"language-text\">C:\\</code> Windows drive path becomes <code class=\"language-text\">/cygdrive/c</code> under Cygwin, and that Cygwin's <code class=\"language-text\">/</code> appears under <code class=\"language-text\">C:\\cygwin</code> on Windows. Convert between Cygwin and Windows-style file paths with <code class=\"language-text\">cygpath</code>. This is most useful in scripts that invoke Windows programs.</li>\n</ul>\n<h2>More resources</h2>\n<ul>\n<li><a href=\"https://github.com/alebcay/awesome-shell\">awesome-shell</a>: A curated list of shell tools and resources.</li>\n<li><a href=\"https://github.com/herrbischoff/awesome-osx-command-line\">awesome-osx-command-line</a>: A more in-depth guide for the macOS command line.</li>\n<li><a href=\"http://redsymbol.net/articles/unofficial-bash-strict-mode/\">Strict mode</a> for writing better shell scripts.</li>\n<li><a href=\"https://github.com/koalaman/shellcheck\">shellcheck</a>: A shell script static analysis tool. Essentially, lint for bash/sh/zsh.</li>\n<li><a href=\"http://www.dwheeler.com/essays/filenames-in-shell.html\">Filenames and Pathnames in Shell</a>: The sadly complex minutiae on how to handle filenames correctly in shell scripts.</li>\n<li><a href=\"http://datascienceatthecommandline.com/#tools\">Data Science at the Command Line</a>: More commands and tools helpful for doing data science, from the book of the same name</li>\n</ul>"},{"url":"/docs/reference/embed-the-web/","relativePath":"docs/reference/embed-the-web.md","relativeDir":"docs/reference","base":"embed-the-web.md","name":"embed-the-web","frontmatter":{"title":"Embed The Web","weight":0,"excerpt":"Embed The Web","seo":{"title":"embeding content","description":"A long time ago on the Web, it was popular to use **frames** to create websites ","robots":[],"extra":[]},"template":"docs"},"html":"<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#a_short_history_of_embedding\" title=\"Permalink to A short history of embedding\">A short history of embedding</a></h2>\n<p>A long time ago on the Web, it was popular to use <strong>frames</strong> to create websites — small parts of a website stored in individual HTML pages. These were embedded in a master document called a <strong>frameset</strong>, which allowed you to specify the area on the screen that each frame filled, rather like sizing the columns and rows of a table. These were considered the height of coolness in the mid to late 90s, and there was evidence that having a webpage split up into smaller chunks like this was better for download speeds — especially noticeable with network connections being so slow back then. They did however have many problems, which far outweighed any positives as network speeds got faster, so you don't see them being used anymore.</p>\n<p>A little while later (late 90s, early 2000s), plugin technologies became very popular, such as <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Java\">Java Applets</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Adobe_Flash\">Flash</a> — these allowed web developers to embed rich content into webpages such as videos and animations, which just weren't available through HTML alone. Embedding these technologies was achieved through elements like <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a>, and the lesser-used <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a>, and they were very useful at the time. They have since fallen out of fashion due to many problems, including accessibility, security, file size, and more. These days major browsers have stopped supporting plugins such as Flash.</p>\n<p>Finally, the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a> element appeared (along with other ways of embedding content, such as <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas\"><code class=\"language-text\">&lt;canvas></code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a>, etc.) This provides a way to embed an entire web document inside another one, as if it were an <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img\"><code class=\"language-text\">&lt;img></code></a> or other such element, and is used regularly today.</p>\n<p>With the history lesson out of the way, let's move on and see how to use some of these.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#active_learning_classic_embedding_uses\" title=\"Permalink to Active learning: classic embedding uses\">Active learning: classic embedding uses</a></h2>\n<p>In this article we are going to jump straight into an active learning section, to immediately give you a real idea of just what embedding technologies are useful for. The online world is very familiar with <a href=\"https://www.youtube.com/\">YouTube</a>, but many people don't know about some of the sharing facilities it has available. Let's look at how YouTube allows us to embed a video in any page we like using an <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a>.</p>\n<ol>\n<li>First, go to YouTube and find a video you like.</li>\n<li>Below the video, you'll find a <em>Share</em> button — select this to display the sharing options.</li>\n<li>Select the <em>Embed</em> button and you'll be given some <code class=\"language-text\">&lt;iframe></code> code — copy this.</li>\n<li>Insert it into the <em>Input</em> box below, and see what the result is in the <em>Output</em>.</li>\n</ol>\n<p>For bonus points, you could also try embedding a <a href=\"https://www.google.com/maps/\">Google Map</a> in the example:</p>\n<ol>\n<li>Go to Google Maps and find a map you like.</li>\n<li>Click on the \"Hamburger Menu\" (three horizontal lines) in the top left of the UI.</li>\n<li>Select the <em>Share or embed map</em> option.</li>\n<li>Select the Embed map option, which will give you some <code class=\"language-text\">&lt;iframe></code> code — copy this.</li>\n<li>Insert it into the <em>Input</em> box below, and see what the result is in the <em>Output</em>.</li>\n</ol>\n<p>If you make a mistake, you can always reset it using the <em>Reset</em> button. If you get really stuck, press the <em>Show solution</em> button to see an answer.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;h2>Live output&lt;/h2>\n\n&lt;div class=\"output\" style=\"min-height: 250px;\">\n&lt;/div>\n\n&lt;h2>Editable code&lt;/h2>\n&lt;p class=\"a11y-label\">Press Esc to move focus away from the code area (Tab inserts a tab character).&lt;/p>\n\n&lt;textarea id=\"code\" class=\"input\" style=\"width: 95%;min-height: 100px;\">\n&lt;/textarea>\n\n&lt;div class=\"playable-buttons\">\n  &lt;input id=\"reset\" type=\"button\" value=\"Reset\">\n  &lt;input id=\"solution\" type=\"button\" value=\"Show solution\">\n&lt;/div></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">html {\n  font-family: sans-serif;\n}\n\nh2 {\n  font-size: 16px;\n}\n\n.a11y-label {\n  margin: 0;\n  text-align: right;\n  font-size: 0.7rem;\n  width: 98%;\n}\n\nbody {\n  margin: 10px;\n  background: #f5f9fa;\n}</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const textarea = document.getElementById('code');\nconst reset = document.getElementById('reset');\nconst solution = document.getElementById('solution');\nconst output = document.querySelector('.output');\nlet code = textarea.value;\nlet userEntry = textarea.value;\n\nfunction updateCode() {\n  output.innerHTML = textarea.value;\n}\n\nreset.addEventListener('click', function() {\n  textarea.value = code;\n  userEntry = textarea.value;\n  solutionEntry = htmlSolution;\n  solution.value = 'Show solution';\n  updateCode();\n});\n\nsolution.addEventListener('click', function() {\n  if(solution.value === 'Show solution') {\n    textarea.value = solutionEntry;\n    solution.value = 'Hide solution';\n  } else {\n    textarea.value = userEntry;\n    solution.value = 'Show solution';\n  }\n  updateCode();\n});\n\nconst htmlSolution = '&lt;iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/QH2-TGUlwu4\" frameborder=\"0\" allowfullscreen>\\n&lt;/iframe>\n&lt;br>\\n\\n&lt;iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d37995.65748333395!2d-2.273568166412784!3d53.473310471916975!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x487bae6c05743d3d%3A0xf82fddd1e49fc0a1!2sThe+Lowry!5e0!3m2!1sen!2suk!4v1518171785211\" width=\"600\" height=\"450\" frameborder=\"0\" style=\"border:0\" allowfullscreen>\\n&lt;/iframe>\n&lt;br>';\nlet solutionEntry = htmlSolution;\n\ntextarea.addEventListener('input', updateCode);\nwindow.addEventListener('load', updateCode);\n\ntextarea.onkeydown = function(e){\n  if (e.keyCode === 9) {\n    e.preventDefault();\n    insertAtCaret('\\t');\n  }\n\n  if (e.keyCode === 27) {\n    textarea.blur();\n  }\n};\n\nfunction insertAtCaret(text) {\n  const scrollPos = textarea.scrollTop;\n  let caretPos = textarea.selectionStart;\n\n  const front = (textarea.value).substring(0, caretPos);\n  const back = (textarea.value).substring(textarea.selectionEnd, textarea.value.length);\n  textarea.value = front + text + back;\n  caretPos = caretPos + text.length;\n  textarea.selectionStart = caretPos;\n  textarea.selectionEnd = caretPos;\n  textarea.focus();\n  textarea.scrollTop = scrollPos;\n}\n\ntextarea.onkeyup = function(){\n\n  if(solution.value === 'Show solution') {\n    userEntry = textarea.value;\n  } else {\n    solutionEntry = textarea.value;\n  }\n\n  updateCode();\n};</code></pre></div>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#iframes_in_detail\" title=\"Permalink to iframes in detail\">iframes in detail</a></h2>\n<p>So, that was easy and fun, right? <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a> elements are designed to allow you to embed other web documents into the current document. This is great for incorporating third-party content into your website that you might not have direct control over and don't want to have to implement your own version of — such as video from online video providers, commenting systems like <a href=\"https://disqus.com/\">Disqus</a>, maps from online map providers, advertising banners, etc. The live editable examples you've been using through this course are implemented using <code class=\"language-text\">&lt;iframe></code>s.</p>\n<p>There are some serious <a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#security_concerns\">Security concerns</a> to consider with <code class=\"language-text\">&lt;iframe></code>s, as we'll discuss below, but this doesn't mean that you shouldn't use them in your websites — it just requires some knowledge and careful thinking. Let's explore the code in a bit more detail. Say you wanted to include the MDN glossary on one of your web pages — you could try something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;head>\n  &lt;style> iframe { border: none } &lt;/style>\n&lt;/head>\n&lt;body>\n  &lt;iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://developer.mozilla.org/en-US/docs/Glossary\"\n          width=\"100%\" height=\"500\" allowfullscreen sandbox>\n    &lt;p>\n      &lt;a href=\"/en-US/docs/Glossary\">\n         Fallback link for browsers that don't support iframes\n      &lt;/a>\n    &lt;/p>\n  &lt;/iframe>\n&lt;br>\n&lt;/body></code></pre></div>\n<p>This example includes the basic essentials needed to use an <code class=\"language-text\">&lt;iframe></code>:</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border\"><code class=\"language-text\">border: none</code></a></p>\n<p>If used, the <code class=\"language-text\">&lt;iframe></code> is displayed without a surrounding border. Otherwise, by default, browsers display the <code class=\"language-text\">&lt;iframe></code> with a surrounding border (which is generally undesirable).</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-allowfullscreen\"><code class=\"language-text\">allowfullscreen</code></a></p>\n<p>If set, the <code class=\"language-text\">&lt;iframe></code> is able to be placed in fullscreen mode using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API\">Fullscreen API</a> (somewhat beyond the scope of this article.)</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-src\"><code class=\"language-text\">src</code></a></p>\n<p>This attribute, as with <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a>/<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img\"><code class=\"language-text\">&lt;img></code></a>, contains a path pointing to the URL of the document to be embedded.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-width\"><code class=\"language-text\">width</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-height\"><code class=\"language-text\">height</code></a></p>\n<p>These attributes specify the width and height you want the iframe to be.</p>\n<p>Fallback content</p>\n<p>In the same way as other similar elements like <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video\"><code class=\"language-text\">&lt;video></code></a>, you can include fallback content between the opening and closing `<iframe></p>\n</iframe>\n<br>` tags that will appear if the browser doesn't support the `<iframe>`. In this case, we have included a link to the page instead. It is unlikely that you'll come across any browser that doesn't support `<iframe>`s these days.\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\"><code class=\"language-text\">sandbox</code></a></p>\n<p>This attribute, which works in slightly more modern browsers than the rest of the <code class=\"language-text\">&lt;iframe></code> features (e.g. IE 10 and above) requests heightened security settings; we'll say more about this in the next section.</p>\n<p><strong>Note:</strong> In order to improve speed, it's a good idea to set the iframe's <code class=\"language-text\">src</code> attribute with JavaScript after the main content is done with loading. This makes your page usable sooner and decreases your official page load time (an important <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/SEO\">SEO</a> metric.)</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#security_concerns\" title=\"Permalink to Security concerns\">Security concerns</a></h3>\n<p>Above we mentioned security concerns — let's go into this in a bit more detail now. We are not expecting you to understand all of this content perfectly the first time; we just want to make you aware of this concern, and provide a reference to come back to as you get more experienced and start considering using <code class=\"language-text\">&lt;iframe></code>s in your experiments and work. Also, there is no need to be scared and not use <code class=\"language-text\">&lt;iframe></code>s — you just need to be careful. Read on...</p>\n<p>Browser makers and Web developers have learned the hard way that iframes are a common target (official term: <strong>attack vector</strong>) for bad people on the Web (often termed <strong>hackers</strong>, or more accurately, <strong>crackers</strong>) to attack if they are trying to maliciously modify your webpage, or trick people into doing something they don't want to do, such as reveal sensitive information like usernames and passwords. Because of this, spec engineers and browser developers have developed various security mechanisms for making <code class=\"language-text\">&lt;iframe></code>s more secure, and there are also best practices to consider — we'll cover some of these below.</p>\n<p><strong>Note:</strong> <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Clickjacking\">Clickjacking</a> is one kind of common iframe attack where hackers embed an invisible iframe into your document (or embed your document into their own malicious website) and use it to capture users' interactions. This is a common way to mislead users or steal sensitive data.</p>\n<p>A quick example first though — try loading the previous example we showed above into your browser — you can <a href=\"https://mdn.github.io/learning-area/html/multimedia-and-embedding/other-embedding-technologies/iframe-detail.html\">find it live on GitHub</a> (<a href=\"https://github.com/mdn/learning-area/blob/gh-pages/html/multimedia-and-embedding/other-embedding-technologies/iframe-detail.html\">see the source code</a> too.) Instead of the page you expected, you'll probably see some kind of message to the effect of \"I can't open this page\", and if you look at the <em>Console</em> in the <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools\">browser developer tools</a>, you'll see a message telling you why. In Firefox, you'll get told something like <em>The loading of \"<a href=\"https://developer.mozilla.org/en-US/docs/Glossary\">https://developer.mozilla.org/en-US/docs/Glossary</a>\" in a frame is denied by \"X-Frame-Options\" directive set to \"DENY\".</em>. This is because the developers that built MDN have included a setting on the server that serves the website pages to disallow them from being embedded inside <code class=\"language-text\">&lt;iframe></code>s (see <a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#configure_csp_directives\">Configure CSP directives</a>, below.) This makes sense — an entire MDN page doesn't really make sense to be embedded in other pages unless you want to do something like embed them on your site and claim them as your own — or attempt to steal data via <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Clickjacking\">clickjacking</a>, which are both really bad things to do. Plus if everybody started to do this, all the additional bandwidth would start to cost Mozilla a lot of money.</p>\n<h4>Only embed when necessary</h4>\n<p>Sometimes it makes sense to embed third-party content — like youtube videos and maps — but you can save yourself a lot of headaches if you only embed third-party content when completely necessary. A good rule of thumb for web security is <em>\"You can never be too cautious. If you made it, double-check it anyway. If someone else made it, assume it's dangerous until proven otherwise.\"</em></p>\n<p>Besides security, you should also be aware of intellectual property issues. Most content is copyrighted, offline and online, even content you might not expect (for example, most images on <a href=\"https://commons.wikimedia.org/wiki/Main_Page\">Wikimedia Commons</a>). Never display content on your webpage unless you own it or the owners have given you written, unequivocal permission. Penalties for copyright infringement are severe. Again, you can never be too cautious.</p>\n<p>If the content is licensed, you must obey the license terms. For example, the content on MDN is <a href=\"https://developer.mozilla.org/en-US/docs/MDN/About#copyrights_and_licenses\">licensed under CC-BY-SA</a>. That means, you must <a href=\"https://wiki.creativecommons.org/wiki/Best_practices_for_attribution\">credit us properly</a> when you quote our content, even if you make substantial changes.</p>\n<h4>Use HTTPS</h4>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/https\">HTTPS</a> is the encrypted version of <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/HTTP\">HTTP</a>. You should serve your websites using HTTPS whenever possible:</p>\n<ol>\n<li>HTTPS reduces the chance that remote content has been tampered with in transit,</li>\n<li>HTTPS prevents embedded content from accessing content in your parent document, and vice versa.</li>\n</ol>\n<p>HTTPS-enabling your site requires a special security certificate to be installed. Many hosting providers offer HTTPS-enabled hosting without you needing to do any setup on your own to put a certificate in place. But if you <em>do</em> need to set up HTTPS support for your site on your own, <a href=\"https://letsencrypt.org/\">Let's Encrypt</a> provides tools and instructions you can use for automatically creating and installing the necessary certificate — with built-in support for the most widely-used web servers, including the Apache web server, Nginx, and others. The Let's Encrypt tooling is designed to make the process as easy as possible, so there's really no good reason to avoid using it or other available means to HTTPS-enable your site.</p>\n<p><strong>Note:</strong> <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Using_Github_pages\">GitHub pages</a> allow content to be served via HTTPS by default, so it is useful for hosting content. If you are using a different hosting provider and are not sure, ask them about it.</p>\n<h4>Always use the <code class=\"language-text\">sandbox</code> attribute</h4>\n<p>You want to give attackers as little power as you can to do bad things on your website, therefore you should give embedded content <em>only the permissions needed for doing its job.</em> Of course, this applies to your own content, too. A container for code where it can be used appropriately — or for testing — but can't cause any harm to the rest of the codebase (either accidental or malicious) is called a <a href=\"https://en.wikipedia.org/wiki/Sandbox_(computer_security)\">sandbox</a>.</p>\n<p>Unsandboxed content can do way too much (executing JavaScript, submitting forms, popup windows, etc.) By default, you should impose all available restrictions by using the <code class=\"language-text\">sandbox</code> attribute with no parameters, as shown in our previous example.</p>\n<p>If absolutely required, you can add permissions back one by one (inside the <code class=\"language-text\">sandbox=\"\"</code> attribute value) — see the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\"><code class=\"language-text\">sandbox</code></a> reference entry for all the available options. One important note is that you should <em>never</em> add both <code class=\"language-text\">allow-scripts</code> and <code class=\"language-text\">allow-same-origin</code> to your <code class=\"language-text\">sandbox</code> attribute — in that case, the embedded content could bypass the <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Same-origin_policy\">Same-origin policy</a> that stops sites from executing scripts, and use JavaScript to turn off sandboxing altogether.</p>\n<p><strong>Note:</strong> Sandboxing provides no protection if attackers can fool people into visiting malicious content directly (outside an <code class=\"language-text\">iframe</code>). If there's any chance that certain content may be malicious (e.g., user-generated content), please serve it from a different <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Domain\">domain</a> to your main site.</p>\n<h4>Configure CSP directives</h4>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/CSP\">CSP</a> stands for <strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP\">content security policy</a></strong> and provides <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy\">a set of HTTP Headers</a> (metadata sent along with your web pages when they are served from a web server) designed to improve the security of your HTML document. When it comes to securing <code class=\"language-text\">&lt;iframe></code>s, you can <em><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options\">configure your server to send an appropriate <code class=\"language-text\">X-Frame-Options</code> header.</a></em> This can prevent other websites from embedding your content in their web pages (which would enable <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Clickjacking\">clickjacking</a> and a host of other attacks), which is exactly what the MDN developers have done, as we saw earlier on.</p>\n<p><strong>Note:</strong> You can read Frederik Braun's post <a href=\"https://blog.mozilla.org/security/2013/12/12/on-the-x-frame-options-security-header/\">On the X-Frame-Options Security Header</a> for more background information on this topic. Obviously, it's rather out of scope for a full explanation in this article.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Other_embedding_technologies#the_embed_and_object_elements\" title=\"Permalink to The <embed> and <object> elements\">The <embed> and <object> elements</a></h2>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a> elements serve a different function to <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe\"><code class=\"language-text\">&lt;iframe></code></a> — these elements are general purpose embedding tools for embedding external content, such as PDFs.</p>\n<p>However, you are unlikely to use these elements very much. If you need to display PDFs, it's usually better to link to them, rather than embedding them in the page.</p>\n<p>Historically these elements have also been used for embedding content handled by browser <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Plugin\">plugins</a> such as <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Adobe_Flash\">Adobe Flash</a>, but this technology is now obsolete and is not supported by modern browsers.</p>\n<p>If you find yourself needing to embed plugin content, this is the kind of information you'll need, at a minimum:</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed\"><code class=\"language-text\">&lt;embed></code></a></p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object\"><code class=\"language-text\">&lt;object></code></a></p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/URL\">URL</a> of the embedded content</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed#attr-src\"><code class=\"language-text\">src</code></a></p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attr-data\"><code class=\"language-text\">data</code></a></p>\n<p><em>accurate</em> <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/MIME_type\">media type</a> of the embedded content</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed#attr-type\"><code class=\"language-text\">type</code></a></p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attr-type\"><code class=\"language-text\">type</code></a></p>\n<p>height and width (in CSS pixels) of the box controlled by the plugin</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed#attr-height\"><code class=\"language-text\">height</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed#attr-width\"><code class=\"language-text\">width</code></a></p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attr-height\"><code class=\"language-text\">height</code></a>\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object#attr-width\"><code class=\"language-text\">width</code></a></p>\n<p>names and values, to feed the plugin as parameters</p>\n<p>ad hoc attributes with those names and values</p>\n<p>single-tag <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/param\"><code class=\"language-text\">&lt;param></code></a> elements, contained within <code class=\"language-text\">&lt;object></code></p>\n<p>independent HTML content as fallback for an unavailable resource</p>\n<p>not supported (<code class=\"language-text\">&lt;noembed></code> is obsolete)</p>\n<p>contained within <code class=\"language-text\">&lt;object></code>, after <code class=\"language-text\">&lt;param></code> elements</p>\n<p>Let's look at an <code class=\"language-text\">&lt;object></code> example that embeds a PDF into a page (see the <a href=\"https://mdn.github.io/learning-area/html/multimedia-and-embedding/other-embedding-technologies/object-pdf.html\">live example</a> and the <a href=\"https://github.com/mdn/learning-area/blob/gh-pages/html/multimedia-and-embedding/other-embedding-technologies/object-pdf.html\">source code</a>):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;object data=\"mypdf.pdf\" type=\"application/pdf\"\n        width=\"800\" height=\"1200\">\n  &lt;p>You don't have a PDF plugin, but you can\n    &lt;a href=\"mypdf.pdf\">download the PDF file.\n    &lt;/a>\n  &lt;/p>\n&lt;/object></code></pre></div>\n<p>PDFs were a necessary stepping stone between paper and digital, but they pose many <a href=\"https://webaim.org/techniques/acrobat/acrobat\">accessibility challenges</a> and can be hard to read on small screens. They do still tend to be popular in some circles, but it is much better to link to them so they can be downloaded or read on a separate page, rather than embedding them in a webpage.</p>"},{"url":"/docs/reference/bash-commands/","relativePath":"docs/reference/bash-commands.md","relativeDir":"docs/reference","base":"bash-commands.md","name":"bash-commands","frontmatter":{"title":"Bash-Commands","weight":0,"seo":{"title":"Bash-Commands","description":"This is the Bash-Commands page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Bash-Commands","keyName":"property"},{"name":"og:description","value":"This is the Bash-Commands page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Bash-Commands"},{"name":"twitter:description","value":"This is the Bash-Commands page"}]},"template":"docs"},"html":"<h2>My Commands:</h2>\n<h4>Find:</h4>\n<h1>To find files by case-insensitive extension (ex: .jpg, .jpg, .jpG):</h1>\n<p>find . -iname \"*.jpg\"</p>\n<h1>To find directories:</h1>\n<p>find . -type d</p>\n<h1>To find files:</h1>\n<p>find . -type f</p>\n<h1>To find files by octal permission:</h1>\n<p>find . -type f -perm 777</p>\n<h1>To find files with setuid bit set:</h1>\n<p>find . -xdev ( -perm -4000 ) -type f -print0 | xargs -0 ls -l</p>\n<h1>To find files with extension '.txt' and remove them:</h1>\n<p>find ./path/ -name '*.txt' -exec rm '{}' ;</p>\n<h1>To find files with extension '.txt' and look for a string into them:</h1>\n<p>find ./path/ -name '*.txt' | xargs grep 'string'</p>\n<h1>To find files with size bigger than 5 Mebibyte and sort them by size:</h1>\n<p>find . -size +5M -type f -print0 | xargs -0 ls -Ssh | sort -z</p>\n<h1>To find files bigger than 2 Megabyte and list them:</h1>\n<p>find . -type f -size +200000000c -exec ls -lh {} ; | awk '{ print $9 \": \" $5 }'</p>\n<h1>To find files modified more than 7 days ago and list file information:</h1>\n<p>find . -type f -mtime +7d -ls</p>\n<h1>To find symlinks owned by a user and list file information:</h1>\n<p>find . -type l -user <username-or-userid> -ls</p>\n<h1>To search for and delete empty directories:</h1>\n<p>find . -type d -empty -exec rmdir {} ;</p>\n<h1>To search for directories named build at a max depth of 2 directories:</h1>\n<p>find . -maxdepth 2 -name build -type d</p>\n<h1>To search all files who are not in .git directory:</h1>\n<p>find . ! -iwholename '<em>.git</em>' -type f</p>\n<h1>To find all files that have the same node (hard link) as MY<em>FILE</em>HERE:</h1>\n<p>find . -type f -samefile MY<em>FILE</em>HERE 2>/dev/null</p>\n<h1>To find all files in the current directory and modify their permissions:</h1>\n<p>find . -type f -exec chmod 644 {} ;</p>\n<hr>\n<h1>1. Remove spaces from file and folder names and then remove numbers from files and folder names....</h1>\n<h3>Description: need to : <code class=\"language-text\">sudo apt install rename</code></h3>\n<blockquote>\n<p>Notes: Issue when renaming file without numbers collides with existing file name...</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/ /_/g'</span>\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/ /_/g'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">``<span class=\"token variable\"><span class=\"token variable\">`</span>shell\n<span class=\"token function\">find</span> $dir <span class=\"token parameter variable\">-type</span> f <span class=\"token operator\">|</span> <span class=\"token function\">sed</span> <span class=\"token string\">'s|\\(.*/\\)[^A-Z]*\\([A-Z].*\\)|mv \\\"&amp;\\\" \\\"\\1\\2\\\"|'</span> <span class=\"token operator\">|</span> <span class=\"token function\">sh</span>\n\n<span class=\"token function\">find</span> $dir <span class=\"token parameter variable\">-type</span> d <span class=\"token operator\">|</span> <span class=\"token function\">sed</span> <span class=\"token string\">'s|\\(.*/\\)[^A-Z]*\\([A-Z].*\\)|mv \\\"&amp;\\\" \\\"\\1\\2\\\"|'</span> <span class=\"token operator\">|</span> <span class=\"token function\">sh</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">i</span> <span class=\"token keyword\">in</span> *.html<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">$i</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${i<span class=\"token operator\">%</span>-*}</span>.html\"</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">i</span> <span class=\"token keyword\">in</span> *.*<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">$i</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${i<span class=\"token operator\">%</span>-*}</span>.<span class=\"token variable\">${i<span class=\"token operator\">##</span>*.}</span>\"</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span>\n\n---\n<span class=\"token comment\">### Description: combine the contents of every file in the contaning directory.</span>\n\n<span class=\"token operator\">></span>Notes: this includes the contents of the <span class=\"token function\">file</span> it's self<span class=\"token punctuation\">..</span>.\n\n<span class=\"token comment\">###### code:</span>\n\n<span class=\"token variable\">`</span></span>``js\n//\n//APPEND-DIR.js\nconst fs <span class=\"token operator\">=</span> require<span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token builtin class-name\">let</span> <span class=\"token function\">cat</span> <span class=\"token operator\">=</span> require<span class=\"token punctuation\">(</span><span class=\"token string\">'child_process'</span><span class=\"token punctuation\">)</span>\n  .execSync<span class=\"token punctuation\">(</span><span class=\"token string\">'cat *'</span><span class=\"token punctuation\">)</span>\n  .toString<span class=\"token punctuation\">(</span><span class=\"token string\">'UTF-8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nfs.writeFile<span class=\"token punctuation\">(</span><span class=\"token string\">'output.md'</span>, cat, err <span class=\"token operator\">=</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> throw err<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h1>2. Download Website Using Wget:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes: ==> sudo apt install wget</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">wget</span> --limit-rate<span class=\"token operator\">=</span>200k --no-clobber --convert-links --random-wait <span class=\"token parameter variable\">-r</span> <span class=\"token parameter variable\">-p</span> <span class=\"token parameter variable\">-E</span> <span class=\"token parameter variable\">-e</span> <span class=\"token assign-left variable\">robots</span><span class=\"token operator\">=</span>off <span class=\"token parameter variable\">-U</span> mozilla https://bootcamp42.gitbook.io/python/</code></pre></div>\n<hr>\n<h1>3. Clean Out Messy Git Repo:</h1>\n<h3>Description: recursively removes git related folders as well as internal use files / attributions in addition to empty folders</h3>\n<blockquote>\n<p>Notes: To clear up clutter in repositories that only get used on your local machine.</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-empty</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-print</span> <span class=\"token parameter variable\">-delete</span>\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">(</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\".git\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\".gitignore\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\".gitmodules\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\".gitattributes\"</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">)</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> -- <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">(</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*SECURITY.txt\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*RELEASE.txt\"</span> <span class=\"token parameter variable\">-o</span>  <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CHANGELOG.txt\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*LICENSE.txt\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CONTRIBUTING.txt\"</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*HISTORY.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*LICENSE\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*SECURITY.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*RELEASE.md\"</span> <span class=\"token parameter variable\">-o</span>  <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CHANGELOG.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*LICENSE.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CODE_OF_CONDUCT.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CONTRIBUTING.md\"</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">)</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> -- <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<hr>\n<h1>4. clone all of a user's git repositories</h1>\n<h3>Description: clone all of a user or organization's git repositories.</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<h1>Generalized:</h1>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token assign-left variable\">CNTX</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>users<span class=\"token operator\">|</span>orgs<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">NAME</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>username<span class=\"token operator\">|</span>orgname<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">PAGE</span><span class=\"token operator\">=</span><span class=\"token number\">1</span>\n<span class=\"token function\">curl</span> <span class=\"token string\">\"https://api.github.com/<span class=\"token variable\">$CNTX</span>/<span class=\"token variable\">$NAME</span>/repos?page=<span class=\"token variable\">$PAGE</span>&amp;per_page=100\"</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'git_url*'</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">cut</span> <span class=\"token parameter variable\">-d</span> <span class=\"token punctuation\">\\</span>\" <span class=\"token parameter variable\">-f</span> <span class=\"token number\">4</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-L1</span> <span class=\"token function\">git</span> clone</code></pre></div>\n<h1>Clone all Git User</h1>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token assign-left variable\">CNTX</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>users<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">NAME</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>bgoonz<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">PAGE</span><span class=\"token operator\">=</span><span class=\"token number\">1</span>\n<span class=\"token function\">curl</span> <span class=\"token string\">\"https://api.github.com/<span class=\"token variable\">$CNTX</span>/<span class=\"token variable\">$NAME</span>/repos?page=<span class=\"token variable\">$PAGE</span>&amp;per_page=200\"</span>?branch<span class=\"token operator\">=</span>master <span class=\"token operator\">|</span>\n  <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'git_url*'</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">cut</span> <span class=\"token parameter variable\">-d</span> <span class=\"token punctuation\">\\</span>\" <span class=\"token parameter variable\">-f</span> <span class=\"token number\">4</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-L1</span> <span class=\"token function\">git</span> clone</code></pre></div>\n<h1>Clone all Git Organization:</h1>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token assign-left variable\">CNTX</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>organizations<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">NAME</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>TheAlgorithms<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">PAGE</span><span class=\"token operator\">=</span><span class=\"token number\">1</span>\n<span class=\"token function\">curl</span> <span class=\"token string\">\"https://api.github.com/<span class=\"token variable\">$CNTX</span>/<span class=\"token variable\">$NAME</span>/repos?page=<span class=\"token variable\">$PAGE</span>&amp;per_page=200\"</span>?branch<span class=\"token operator\">=</span>master <span class=\"token operator\">|</span>\n  <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'git_url*'</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">cut</span> <span class=\"token parameter variable\">-d</span> <span class=\"token punctuation\">\\</span>\" <span class=\"token parameter variable\">-f</span> <span class=\"token number\">4</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-L1</span> <span class=\"token function\">git</span> clone</code></pre></div>\n<hr>\n<h1>5. Git Workflow</h1>\n<h3>Description:</h3>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> pull\n<span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin master</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin main</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin bryan-guner</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin gh-pages</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin preview</code></pre></div>\n<hr>\n<h1>6. Recursive Unzip In Place</h1>\n<h3>Description: recursively unzips folders and then deletes the zip file by the same name.</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*.zip\"</span> <span class=\"token operator\">|</span> <span class=\"token keyword\">while</span> <span class=\"token builtin class-name\">read</span> filename<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">unzip</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-d</span> <span class=\"token string\">\"<span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token function\">dirname</span> <span class=\"token string\">\"<span class=\"token variable\">$filename</span>\"</span><span class=\"token variable\">`</span></span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">$filename</span>\"</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*.zip\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-print</span> <span class=\"token parameter variable\">-delete</span></code></pre></div>\n<hr>\n<h1>7. git pull keeping local changes:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> stash\n<span class=\"token function\">git</span> pull\n<span class=\"token function\">git</span> stash pop</code></pre></div>\n<hr>\n<h1>8. Prettier Code Formatter:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">npm</span> i prettier <span class=\"token parameter variable\">-g</span>\n\nprettier <span class=\"token parameter variable\">--write</span> <span class=\"token builtin class-name\">.</span></code></pre></div>\n<hr>\n<h1>9. Pandoc</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> ./ <span class=\"token parameter variable\">-iname</span> <span class=\"token string\">\"*.md\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sh</span> <span class=\"token parameter variable\">-c</span> <span class=\"token string\">'pandoc --standalone \"${0}\" -o \"${0%.md}.html\"'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">find</span> ./ <span class=\"token parameter variable\">-iname</span> <span class=\"token string\">\"*.html\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sh</span> <span class=\"token parameter variable\">-c</span> <span class=\"token string\">'pandoc --wrap=none --from html --to markdown_strict \"${0}\" -o \"${0%.html}.md\"'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">find</span> ./ <span class=\"token parameter variable\">-iname</span> <span class=\"token string\">\"*.docx\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sh</span> <span class=\"token parameter variable\">-c</span> <span class=\"token string\">'pandoc \"${0}\" -o \"${0%.docx}.md\"'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h1>10. Gitpod Installs</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> tree\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> pandoc <span class=\"token parameter variable\">-y</span>\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">rename</span> <span class=\"token parameter variable\">-y</span>\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> black <span class=\"token parameter variable\">-y</span>\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">wget</span> <span class=\"token parameter variable\">-y</span>\n<span class=\"token function\">npm</span> i lebab <span class=\"token parameter variable\">-g</span>\n<span class=\"token function\">npm</span> i prettier <span class=\"token parameter variable\">-g</span>\n<span class=\"token function\">npm</span> i npm-recursive-install <span class=\"token parameter variable\">-g</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">black <span class=\"token builtin class-name\">.</span>\n\nprettier <span class=\"token parameter variable\">--write</span> <span class=\"token builtin class-name\">.</span>\nnpm-recursive-install</code></pre></div>\n<hr>\n<h1>11. Repo Utils Package:</h1>\n<h3>Description: my standard repo utis package</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> i @bgoonz11/repoutils</code></pre></div>\n<hr>\n<h1>12. Unix Tree Package Usage:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">tree <span class=\"token parameter variable\">-d</span> <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span>\n\ntree  <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span>\n\ntree <span class=\"token parameter variable\">-f</span>  <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span> <span class=\"token operator\">></span>TREE.md\n\ntree <span class=\"token parameter variable\">-f</span> <span class=\"token parameter variable\">-L</span> <span class=\"token number\">2</span>  <span class=\"token operator\">></span>README.md\n\ntree <span class=\"token parameter variable\">-f</span>  <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span> <span class=\"token operator\">></span>listing-path.md\n\ntree <span class=\"token parameter variable\">-f</span>  <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span> <span class=\"token parameter variable\">-d</span> <span class=\"token operator\">></span>TREE.md\n\ntree <span class=\"token parameter variable\">-f</span> <span class=\"token operator\">></span>README.md</code></pre></div>\n<hr>\n<h1>13. Find &#x26; Replace string in file &#x26; folder names recursively..</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/string1/string2/g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/-master//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/\\.download//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/-main//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">rename</span> <span class=\"token string\">'s/\\.js\\.download$/.js/'</span> *.js<span class=\"token punctuation\">\\</span>.download\n\n<span class=\"token function\">rename</span> <span class=\"token string\">'s/\\.html\\.markdown$/.md/'</span> *.html<span class=\"token punctuation\">\\</span>.markdown\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/es6//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<hr>\n<h1>14. Remove double extensions :</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *.md.md\n<span class=\"token keyword\">do</span>\n    <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">${file}</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${file<span class=\"token operator\">%</span>.md}</span>\"</span>\n<span class=\"token keyword\">done</span>\n\n<span class=\"token comment\">#!/bin/bash</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *.html.html\n<span class=\"token keyword\">do</span>\n    <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">${file}</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${file<span class=\"token operator\">%</span>.html}</span>\"</span>\n<span class=\"token keyword\">done</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *.html.png\n<span class=\"token keyword\">do</span>\n    <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">${file}</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${file<span class=\"token operator\">%</span>.png}</span>\"</span>\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *.jpg.jpg\n<span class=\"token keyword\">do</span>\n    <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">${file}</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${file<span class=\"token operator\">%</span>.png}</span>\"</span>\n<span class=\"token keyword\">done</span></code></pre></div>\n<hr>\n<h1>15. Truncate folder names down to 12 characters:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">d</span> <span class=\"token keyword\">in</span> ./*<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token variable\">$d</span> <span class=\"token variable\">${d<span class=\"token operator\">:</span>0<span class=\"token operator\">:</span>12}</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span></code></pre></div>\n<hr>\n<h1>16.Appendir.js</h1>\n<h3>Description: combine the contents of every file in the contaning directory.</h3>\n<blockquote>\n<p>Notes: this includes the contents of the file it's self...</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">//APPEND-DIR.js</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> cat <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'child_process'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">execSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cat *'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token string\">'UTF-8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'output.md'</span><span class=\"token punctuation\">,</span> cat<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> err<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h1>17. Replace space in filename with underscore</h1>\n<h3>Description: followed by replace <code class=\"language-text\">'#' with '_'</code> in directory name</h3>\n<blockquote>\n<p>Notes: Can be re-purposed to find and replace any set of strings in file or folder names.</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/_//g'</span>\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/#/_/g'</span></code></pre></div>\n<hr>\n<h1>18. Filter &#x26; delete files by name and extension</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'.bin'</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'*.html'</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'nav-index'</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'node-gyp'</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'deleteme.txt'</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'right.html'</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'left.html'</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +</code></pre></div>\n<hr>\n<h1>19. Remove lines containing string:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes: Remove lines not containing <code class=\"language-text\">'.js'</code></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/\\.js/!d'</span> ./*scrap2.md</code></pre></div>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/githubusercontent/d'</span> ./*sandbox.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/githubusercontent/d'</span> ./*scrap2.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/github\\.com/d'</span> ./*out.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/author/d'</span> ./*</code></pre></div>\n<hr>\n<h1>20. Remove duplicate lines from a text file</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:\n//...syntax of uniq...//\n$uniq [OPTION] [INPUT[OUTPUT]]\nThe syntax of this is quite easy to understand. Here, INPUT refers to the input file in which repeated lines need to be filtered out and if INPUT isn't specified then uniq reads from the standard input. OUTPUT refers to the output file in which you can store the filtered output generated by uniq command and as in case of INPUT if OUTPUT isn't specified then uniq writes to the standard output.</p>\n</blockquote>\n<p>Now, let's understand the use of this with the help of an example. Suppose you have a text file named kt.txt which contains repeated lines that needs to be omitted. This can simply be done with uniq.</p>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">uniq</span>\n<span class=\"token function\">uniq</span> <span class=\"token parameter variable\">-u</span> input.txt output.txt</code></pre></div>\n<hr>\n<h1>21. Remove lines containing string:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/githubusercontent/d'</span> ./*sandbox.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/githubusercontent/d'</span> ./*scrap2.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/github\\.com/d'</span> ./*out.md\n\n---\ntitle: add_days\ntags: date,intermediate\nfirstSeen: <span class=\"token number\">2020</span>-10-28T16:19:04+02:00\nlastUpdated: <span class=\"token number\">2020</span>-10-28T16:19:04+02:00\n---\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/title:/d'</span> ./*output.md\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/firstSeen/d'</span> ./*output.md\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/lastUpdated/d'</span> ./*output.md\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/tags:/d'</span> ./*output.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/badstring/d'</span> ./*\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/stargazers/d'</span> ./repo.txt\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/node_modules/d'</span> ./index.html\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/right\\.html/d'</span> ./index.html\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/right\\.html/d'</span> ./right.html</code></pre></div>\n<hr>\n<h1>22. Zip directory excluding .git and node_modules all the way down (Linux)</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n<span class=\"token assign-left variable\">TSTAMP</span><span class=\"token operator\">=</span><span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token function\">date</span> <span class=\"token string\">'+%Y%m%d-%H%M%S'</span><span class=\"token variable\">`</span></span>\n<span class=\"token function\">zip</span> <span class=\"token parameter variable\">-r</span> <span class=\"token variable\">$1</span><span class=\"token builtin class-name\">.</span><span class=\"token variable\">$TSTAMP</span>.zip <span class=\"token variable\">$1</span> <span class=\"token parameter variable\">-x</span> <span class=\"token string\">\"**.git/*\"</span> <span class=\"token parameter variable\">-x</span> <span class=\"token string\">\"**node_modules/*\"</span> <span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token builtin class-name\">shift</span><span class=\"token punctuation\">;</span> <span class=\"token builtin class-name\">echo</span> $@<span class=\"token punctuation\">;</span><span class=\"token variable\">`</span></span>\n\n<span class=\"token builtin class-name\">printf</span> <span class=\"token string\">\"<span class=\"token entity\" title=\"\\n\">\\n</span>Created: <span class=\"token variable\">$1</span>.<span class=\"token variable\">$TSTAMP</span>.zip<span class=\"token entity\" title=\"\\n\">\\n</span>\"</span>\n\n<span class=\"token comment\"># usage:</span>\n<span class=\"token comment\"># - zipdir thedir</span>\n<span class=\"token comment\"># - zip thedir -x \"**anotherexcludedsubdir/*\"    (important the double quotes to prevent glob expansion)</span>\n\n<span class=\"token comment\"># if in windows/git-bash, add 'zip' command this way:</span>\n<span class=\"token comment\"># https://stackoverflow.com/a/55749636/1482990</span></code></pre></div>\n<hr>\n<h1>23. Delete files containing a certain string:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-l</span> www.redhat.com <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> <span class=\"token string\">'{print \"rm \"$1}'</span> <span class=\"token operator\">></span> doit.sh\n<span class=\"token function\">vi</span> doit.sh // check <span class=\"token keyword\">for</span> murphy and his law\n<span class=\"token builtin class-name\">source</span> doit.sh</code></pre></div>\n<hr>\n<h1>24.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/sh</span>\n\n<span class=\"token comment\"># find ./ | grep -i \"\\.*$\" >files</span>\n<span class=\"token function\">find</span> ./ <span class=\"token operator\">|</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-E</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'s/([^ ]+[ ]+){8}//'</span> <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">\"\\.*$\"</span><span class=\"token operator\">></span>files\n<span class=\"token assign-left variable\">listing</span><span class=\"token operator\">=</span><span class=\"token string\">\"files\"</span>\n\n<span class=\"token assign-left variable\">out</span><span class=\"token operator\">=</span><span class=\"token string\">\"\"</span>\n\n<span class=\"token assign-left variable\">html</span><span class=\"token operator\">=</span><span class=\"token string\">\"sitemap.html\"</span>\n<span class=\"token assign-left variable\">out</span><span class=\"token operator\">=</span><span class=\"token string\">\"basename <span class=\"token variable\">$out</span>.html\"</span>\n<span class=\"token assign-left variable\">html</span><span class=\"token operator\">=</span><span class=\"token string\">\"sitemap.html\"</span>\n<span class=\"token function-name function\">cmd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;!DOCTYPE html>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;html>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;head>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;meta http-equiv=\"Content-Type\" content=\"text/html\">'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;meta name=\"Author\" content=\"Bryan Guner\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;link rel=\"stylesheet\" href=\"./assets/prism.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">' &lt;link rel=\"stylesheet\" href=\"./assets/style.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">' &lt;script async defer src=\"./assets/prism.js\">\n&lt;/script>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"  &lt;title> directory &lt;/title>\"</span>\n    <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/bgoonz/GIT-CDN-FILES/mdn-article.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/bgoonz/GIT-CDN-FILES/markdown-to-html-style.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;style>'</span>\n\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    a {'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      color: black;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    }'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">''</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    li {'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border: 1px solid black !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      font-size: 20px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      letter-spacing: 0px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      font-weight: 700;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      line-height: 16px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-decoration: none !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-transform: uppercase;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      background: #194ccdaf !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      color: black !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border: none;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      cursor: pointer;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      justify-content: center;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      padding: 30px 60px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      height: 48px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-align: center;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      white-space: normal;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      min-width: 45em;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      padding: 1.2em 1em 0;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      box-shadow: 0 0 5px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      margin: 1em;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      display: grid;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -webkit-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -moz-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -ms-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -o-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    }'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;/style>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;/head>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;body>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token comment\"># continue with the HTML stuff</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;ul>\"</span>\n\n  <span class=\"token function\">awk</span> <span class=\"token string\">'{print \"&lt;li>\n&lt;a href=\\\"\"$1\"\\\">\",$1,\"&amp;nbsp;&lt;/a>\n&lt;/li>\"}'</span> <span class=\"token variable\">$listing</span>\n\n  <span class=\"token comment\"># awk '{print \"&lt;li>\"};</span>\n\n  <span class=\"token comment\"># \t{print \" &lt;a href=\\\"\"$1\"\\\">\",$1,\"&lt;/a></span>\n<span class=\"token operator\">&lt;</span>/li<span class=\"token operator\">>&amp;</span>nbsp<span class=\"token punctuation\">;</span><span class=\"token string\">\"}' \\ <span class=\"token variable\">$listing</span>\n\n  echo \"</span>\"\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/ul>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/body>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/html>\"</span>\n\n<span class=\"token punctuation\">}</span>\n\ncmd <span class=\"token variable\">$listing</span> <span class=\"token parameter variable\">--sort</span><span class=\"token operator\">=</span>extension <span class=\"token operator\">>></span><span class=\"token variable\">$html</span></code></pre></div>\n<hr>\n<h1>25. Index of Iframes</h1>\n<h3>Description: Creates an index.html file that contains all the files in the working directory or any of it's sub folders as iframes instead of anchor tags.</h3>\n<blockquote>\n<p>Notes: Useful Follow up Code:</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/sh</span>\n\n<span class=\"token comment\"># find ./ | grep -i \"\\.*$\" >files</span>\n<span class=\"token function\">find</span> ./ <span class=\"token operator\">|</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-E</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'s/([^ ]+[ ]+){8}//'</span> <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">\"\\.*$\"</span><span class=\"token operator\">></span>files\n<span class=\"token assign-left variable\">listing</span><span class=\"token operator\">=</span><span class=\"token string\">\"files\"</span>\n\n<span class=\"token assign-left variable\">out</span><span class=\"token operator\">=</span><span class=\"token string\">\"\"</span>\n\n<span class=\"token assign-left variable\">html</span><span class=\"token operator\">=</span><span class=\"token string\">\"index.html\"</span>\n<span class=\"token assign-left variable\">out</span><span class=\"token operator\">=</span><span class=\"token string\">\"basename <span class=\"token variable\">$out</span>.html\"</span>\n<span class=\"token assign-left variable\">html</span><span class=\"token operator\">=</span><span class=\"token string\">\"index.html\"</span>\n<span class=\"token function-name function\">cmd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;!DOCTYPE html>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;html>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;head>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;meta http-equiv=\"Content-Type\" content=\"text/html\">'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;meta name=\"Author\" content=\"Bryan Guner\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;link rel=\"stylesheet\" href=\"./assets/prism.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">' &lt;link rel=\"stylesheet\" href=\"./assets/style.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">' &lt;script async defer src=\"./assets/prism.js\">\n&lt;/script>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"  &lt;title> directory &lt;/title>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;style>'</span>\n\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    a {'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      color: black;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    }'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">''</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    li {'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border: 1px solid black !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      font-size: 20px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      letter-spacing: 0px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      font-weight: 700;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      line-height: 16px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-decoration: none !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-transform: uppercase;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      background: #194ccdaf !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      color: black !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border: none;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      cursor: pointer;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      justify-content: center;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      padding: 30px 60px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      height: 48px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-align: center;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      white-space: normal;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      min-width: 45em;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      padding: 1.2em 1em 0;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      box-shadow: 0 0 5px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      margin: 1em;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      display: grid;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -webkit-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -moz-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -ms-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -o-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    }'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;/style>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;/head>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;body>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token comment\"># continue with the HTML stuff</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;ul>\"</span>\n\n  <span class=\"token function\">awk</span> <span class=\"token string\">'{print \"&lt;iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\\\"\"$1\"\\\">\",\"&lt;/iframe>\n&lt;br>\"}'</span> <span class=\"token variable\">$listing</span>\n\n  <span class=\"token comment\"># awk '{print \"&lt;li>\"};</span>\n\n  <span class=\"token comment\"># \t{print \" &lt;a href=\\\"\"$1\"\\\">\",$1,\"&lt;/a></span>\n<span class=\"token operator\">&lt;</span>/li<span class=\"token operator\">>&amp;</span>nbsp<span class=\"token punctuation\">;</span><span class=\"token string\">\"}' \\ <span class=\"token variable\">$listing</span>\n\n  echo \"</span>\"\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/ul>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/body>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/html>\"</span>\n\n<span class=\"token punctuation\">}</span>\n\ncmd <span class=\"token variable\">$listing</span> <span class=\"token parameter variable\">--sort</span><span class=\"token operator\">=</span>extension <span class=\"token operator\">>></span><span class=\"token variable\">$html</span></code></pre></div>\n<hr>\n<h1>26. Filter Corrupted Git Repo For Troublesome File:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> filter-branch --index-filter <span class=\"token string\">'git rm -r --cached --ignore-unmatch assets/_index.html'</span> HEAD</code></pre></div>\n<hr>\n<h1>27. OVERWRITE LOCAL CHANGES:</h1>\n<h3>Description:</h3>\n<p>Important: If you have any local changes, they will be lost. With or without --hard option, any local commits that haven't been pushed will be lost.[*]\nIf you have any files that are not tracked by Git (e.g. uploaded user content), these files will not be affected.</p>\n<blockquote>\n<p>Notes:\nFirst, run a fetch to update all origin/<branch> refs to latest:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> fetch <span class=\"token parameter variable\">--all</span>\n<span class=\"token comment\"># Backup your current branch:</span>\n\n<span class=\"token function\">git</span> branch backup-master\n<span class=\"token comment\"># Then, you have two options:</span>\n\n<span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> origin/master\n<span class=\"token comment\"># OR If you are on some other branch:</span>\n\n<span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> origin/<span class=\"token operator\">&lt;</span>branch_name<span class=\"token operator\">></span>\n<span class=\"token comment\"># Explanation:</span>\n<span class=\"token comment\"># git fetch downloads the latest from remote without trying to merge or rebase anything.</span>\n\n<span class=\"token comment\"># Then the git reset resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/master</span>\n<span class=\"token function\">git</span> fetch <span class=\"token parameter variable\">--all</span>\n<span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> origin/master</code></pre></div>\n<hr>\n<h1>28. Remove Submodules:</h1>\n<h3>Description: To remove a submodule you need to:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<blockquote>\n<p>Delete the relevant section from the .gitmodules file.\nStage the .gitmodules changes git add .gitmodules\nDelete the relevant section from .git/config.\nRun git rm --cached path<em>to</em>submodule (no trailing slash).\nRun rm -rf .git/modules/path<em>to</em>submodule (no trailing slash).\nCommit git commit -m \"Removed submodule \"\nDelete the now untracked submodule files rm -rf path<em>to</em>submodule</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> submodule deinit</code></pre></div>\n<hr>\n<h1>29. GET GISTS</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">wget</span>\n\n<span class=\"token function\">wget</span> <span class=\"token parameter variable\">-q</span> <span class=\"token parameter variable\">-O</span> - https://api.github.com/users/bgoonz/gists <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> raw_url <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> -F<span class=\"token punctuation\">\\</span>\" <span class=\"token string\">'{print $4}'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-n3</span> <span class=\"token function\">wget</span>\n\n<span class=\"token function\">wget</span> <span class=\"token parameter variable\">-q</span> <span class=\"token parameter variable\">-O</span> - https://api.github.com/users/amitness/gists <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> raw_url <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> -F<span class=\"token punctuation\">\\</span>\" <span class=\"token string\">'{print $4}'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-n3</span> <span class=\"token function\">wget</span>\n\n<span class=\"token function\">wget</span> <span class=\"token parameter variable\">-q</span> <span class=\"token parameter variable\">-O</span> - https://api.github.com/users/drodsou/gists <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> raw_url <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> -F<span class=\"token punctuation\">\\</span>\" <span class=\"token string\">'{print $4}'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-n1</span> <span class=\"token function\">wget</span>\n\n<span class=\"token function\">wget</span> <span class=\"token parameter variable\">-q</span> <span class=\"token parameter variable\">-O</span> - https://api.github.com/users/thomasmb/gists <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> raw_url <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> -F<span class=\"token punctuation\">\\</span>\" <span class=\"token string\">'{print $4}'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-n1</span> <span class=\"token function\">wget</span></code></pre></div>\n<hr>\n<h1>30. Remove Remote OriginL</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> remote remove origin</code></pre></div>\n<hr>\n<h1>31. just clone .git folder:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> clone <span class=\"token parameter variable\">--bare</span> <span class=\"token parameter variable\">--branch</span><span class=\"token operator\">=</span>master --single-branch https://github.com/bgoonz/My-Web-Dev-Archive.git</code></pre></div>\n<hr>\n<h1>32. Undo recent pull request:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> master@<span class=\"token punctuation\">{</span><span class=\"token string\">\"10 minutes ago\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h1>33. Lebab</h1>\n<h3>Description: ES5 --> ES6</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Safe:</span>\n\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arrow\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arrow-return\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-of\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-each\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-rest\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-spread\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> obj-method\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> obj-shorthand\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> multi-var\n\n<span class=\"token comment\"># ALL:</span>\n\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> obj-method\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> class\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arrow\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> <span class=\"token builtin class-name\">let</span>\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-spread\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-rest\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-each\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-of\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> commonjs\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> exponent\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> multi-var\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> template\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> default-param\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span>  destruct-param\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> includes\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> obj-method\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> class\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arrow\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-spread\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-rest\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-each\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-of\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> commonjs\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> exponent\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> multi-var\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> template\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> default-param\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span>  destruct-param\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> includes</code></pre></div>\n<hr>\n<h1>34. Troubleshoot Ubuntu Input/Output Error</h1>\n<h3>Description: Open Powershell as Administrator...</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> wsl.exe --shutdown\n\n Get-Service LxssManager | Restart-Service</code></pre></div>\n<hr>\n<h1>35. Export Medium as Markdown</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> i mediumexporter <span class=\"token parameter variable\">-g</span>\n\nmediumexporter https://medium.com/codex/fundamental-data-structures-in-javascript-8f9f709c15b4 <span class=\"token operator\">></span>ds.md</code></pre></div>\n<hr>\n<h1>36. Delete files in violation of a given size range (100MB for git)</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-size</span> +75M <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-print</span> <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-f</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-size</span> +98M <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-print</span> <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-f</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h1>37. download all links of given file type</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">wget</span> <span class=\"token parameter variable\">-r</span> <span class=\"token parameter variable\">-A.pdf</span> https://overapi.com/git</code></pre></div>\n<hr>\n<h1>38. Kill all node processes</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">killall</span> <span class=\"token parameter variable\">-s</span> KILL <span class=\"token function\">node</span></code></pre></div>\n<hr>\n<h1>39. Remove string from file names recursively</h1>\n<h3>Description: In the example below I am using this command to remove the string \"-master\" from all file names in the working directory and all of it's sub directories.</h3>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token operator\">&lt;</span>mydir<span class=\"token operator\">></span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'s/&lt;string1>/&lt;string2>/g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/-master//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<blockquote>\n<p>Notes: The same could be done for folder names by changing the <em>-type f</em> flag (for file) to a <em>-type d</em> flag (for directory)</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token operator\">&lt;</span>mydir<span class=\"token operator\">></span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'s/&lt;string1>/&lt;string2>/g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/-master//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<hr>\n<h1>40. Remove spaces from file and folder names recursively</h1>\n<h3>Description: replaces spaces in file and folder names with an <code class=\"language-text\">_</code> underscore</h3>\n<blockquote>\n<p>Notes: need to run <code class=\"language-text\">sudo apt install rename</code> to use this command</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/ /_/g'</span>\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/ /_/g'</span></code></pre></div>\n<hr>\n<h1>41. Zip Each subdirectories in a given directory into their own zip file</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">i</span> <span class=\"token keyword\">in</span> */<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">zip</span> <span class=\"token parameter variable\">-r</span> <span class=\"token string\">\"<span class=\"token variable\">${i<span class=\"token operator\">%</span><span class=\"token operator\">/</span>}</span>.zip\"</span> <span class=\"token string\">\"<span class=\"token variable\">$i</span>\"</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span></code></pre></div>\n<hr>\n<h1>42.</h1>\n<h1>43.</h1>\n<h1>44.</h1>\n<h1>45.</h1>\n<h1>46.</h1>\n<h1>47.</h1>\n<h1>48.</h1>\n<h1>49.</h1>\n<h1>50.</h1>\n<h1>51.</h1>\n<h1>52.</h1>\n<h1>53.</h1>\n<h1>54.</h1>\n<h1>55.</h1>\n<h1>56.</h1>\n<h1>57.</h1>\n<h1>58.</h1>\n<h1>59.</h1>\n<h1>60.</h1>\n<h1>61.</h1>\n<h1>62.</h1>\n<h1>63.</h1>\n<h1>64.</h1>\n<h1>65.</h1>\n<h1>66.</h1>\n<h1>67.</h1>\n<h1>68.</h1>\n<h1>69.</h1>\n<h1>70.</h1>\n<h1>71.</h1>\n<h1>72.</h1>\n<h1>73.</h1>\n<h1>74.</h1>\n<h1>75.</h1>\n<h1>76.</h1>\n<h1>77.</h1>\n<h1>78.</h1>\n<h1>79.</h1>\n<h1>80.</h1>\n<h1>81.</h1>\n<h1>82.</h1>\n<h1>83.</h1>\n<h1>84.</h1>\n<h1>85.</h1>\n<h1>86.</h1>\n<h1>87.</h1>\n<h1>88.</h1>\n<h1>89.</h1>\n<h1>90.</h1>\n<h1>91. Unzip PowerShell</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PARAM (\n    [string] $ZipFilesPath = \"./\",\n    [string] $UnzipPath = \"./RESULT\"\n)\n\n$Shell = New-Object -com Shell.Application\n$Location = $Shell.NameSpace($UnzipPath)\n\n$ZipFiles = Get-Childitem $ZipFilesPath -Recurse -Include *.ZIP\n\n$progress = 1\nforeach ($ZipFile in $ZipFiles) {\n    Write-Progress -Activity \"Unzipping to $($UnzipPath)\" -PercentComplete (($progress / ($ZipFiles.Count + 1)) * 100) -CurrentOperation $ZipFile.FullName -Status \"File $($Progress) of $($ZipFiles.Count)\"\n    $ZipFolder = $Shell.NameSpace($ZipFile.fullname)\n\n    $Location.Copyhere($ZipFolder.items(), 1040) # 1040 - No msgboxes to the user - https://msdn.microsoft.com/library/bb787866%28VS.85%29.aspx\n    $progress++\n}</code></pre></div>\n<hr>\n<h1>92. return to bash from zsh</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"> <span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token parameter variable\">--purge</span> remove <span class=\"token function\">zsh</span></code></pre></div>\n<hr>\n<h1>93. Symbolic Link</h1>\n<h3>Description: to working directory</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">ln</span> <span class=\"token parameter variable\">-s</span> <span class=\"token string\">\"<span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token builtin class-name\">pwd</span><span class=\"token variable\">)</span></span>\"</span> ~/NameOfLink\n\n<span class=\"token function\">ln</span> <span class=\"token parameter variable\">-s</span> <span class=\"token string\">\"<span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token builtin class-name\">pwd</span><span class=\"token variable\">)</span></span>\"</span> ~/Downloads</code></pre></div>\n<hr>\n<h1>94. auto generate readme</h1>\n<h3>Description: rename existing readme to blueprint.md</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">npx @appnest/readme generate</code></pre></div>\n<hr>\n<h1>95. Log into postgres:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token parameter variable\">-u</span> postgres psql</code></pre></div>\n<hr>\n<h1>96. URL To Subscribe To YouTube Channel</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"txt\"><pre class=\"language-txt\"><code class=\"language-txt\">https://www.youtube.com/channel/UC1HDa0wWnIKUf-b4yY9JecQ?sub_confirmation=1</code></pre></div>\n<hr>\n<h1>97. Embed Repl.it In Medium Post:</h1>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"txt\"><pre class=\"language-txt\"><code class=\"language-txt\">https://repl.it/@bgoonz/Data-Structures-Algos-Codebase?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com\n\nhttps://repl.it/@bgoonz/node-db1-project?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com\n\nhttps://repl.it/@bgoonz/interview-prac?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com\n\nhttps://repl.it/@bgoonz/Database-Prac?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com</code></pre></div>\n<hr>\n<h1>98.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> *right.html  <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'s/target=\"_parent\"//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> *right.html  <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'s/target=\"_parent\"//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<hr>\n<h1>99. Cheat Sheet</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token comment\"># SHORTCUTS and HISTORY</span>\n\n\nCTRL+A  <span class=\"token comment\"># move to beginning of line</span>\nCTRL+B  <span class=\"token comment\"># moves backward one character</span>\nCTRL+C  <span class=\"token comment\"># halts the current command</span>\nCTRL+D  <span class=\"token comment\"># deletes one character backward or logs out of current session, similar to exit</span>\nCTRL+E  <span class=\"token comment\"># moves to end of line</span>\nCTRL+F  <span class=\"token comment\"># moves forward one character</span>\nCTRL+G  <span class=\"token comment\"># aborts the current editing command and ring the terminal bell</span>\nCTRL+H  <span class=\"token comment\"># deletes one character under cursor (same as DELETE)</span>\nCTRL+J  <span class=\"token comment\"># same as RETURN</span>\nCTRL+K  <span class=\"token comment\"># deletes (kill) forward to end of line</span>\nCTRL+L  <span class=\"token comment\"># clears screen and redisplay the line</span>\nCTRL+M  <span class=\"token comment\"># same as RETURN</span>\nCTRL+N  <span class=\"token comment\"># next line in command history</span>\nCTRL+O  <span class=\"token comment\"># same as RETURN, then displays next line in history file</span>\nCTRL+P  <span class=\"token comment\"># previous line in command history</span>\nCTRL+Q  <span class=\"token comment\"># resumes suspended shell output</span>\nCTRL+R  <span class=\"token comment\"># searches backward</span>\nCTRL+S  <span class=\"token comment\"># searches forward or suspends shell output</span>\nCTRL+T  <span class=\"token comment\"># transposes two characters</span>\nCTRL+U  <span class=\"token comment\"># kills backward from point to the beginning of line</span>\nCTRL+V  <span class=\"token comment\"># makes the next character typed verbatim</span>\nCTRL+W  <span class=\"token comment\"># kills the word behind the cursor</span>\nCTRL+X  <span class=\"token comment\"># lists the possible filename completions of the current word</span>\nCTRL+Y  <span class=\"token comment\"># retrieves (yank) last item killed</span>\nCTRL+Z  <span class=\"token comment\"># stops the current command, resume with fg in the foreground or bg in the background</span>\n\nALT+B   <span class=\"token comment\"># moves backward one word</span>\nALT+D   <span class=\"token comment\"># deletes next word</span>\nALT+F   <span class=\"token comment\"># moves forward one word</span>\nALT+H   <span class=\"token comment\"># deletes one character backward</span>\nALT+T   <span class=\"token comment\"># transposes two words</span>\nALT+.   <span class=\"token comment\"># pastes last word from the last command. Pressing it repeatedly traverses through command history.</span>\nALT+U   <span class=\"token comment\"># capitalizes every character from the current cursor position to the end of the word</span>\nALT+L   <span class=\"token comment\"># uncapitalizes every character from the current cursor position to the end of the word</span>\nALT+C   <span class=\"token comment\"># capitalizes the letter under the cursor. The cursor then moves to the end of the word.</span>\nALT+R   <span class=\"token comment\"># reverts any changes to a command you've pulled from your history if you've edited it.</span>\nALT+?   <span class=\"token comment\"># list possible completions to what is typed</span>\nALT+^   <span class=\"token comment\"># expand line to most recent match from history</span>\n\nCTRL+X <span class=\"token keyword\">then</span> <span class=\"token punctuation\">(</span>   <span class=\"token comment\"># start recording a keyboard macro</span>\nCTRL+X <span class=\"token keyword\">then</span> <span class=\"token punctuation\">)</span>   <span class=\"token comment\"># finish recording keyboard macro</span>\nCTRL+X <span class=\"token keyword\">then</span> E   <span class=\"token comment\"># recall last recorded keyboard macro</span>\nCTRL+X <span class=\"token keyword\">then</span> CTRL+E   <span class=\"token comment\"># invoke text editor (specified by $EDITOR) on current command line then execute resultes as shell commands</span>\n\nBACKSPACE  <span class=\"token comment\"># deletes one character backward</span>\nDELETE     <span class=\"token comment\"># deletes one character under cursor</span>\n\n<span class=\"token function\">history</span>   <span class=\"token comment\"># shows command line history</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">!</span>        <span class=\"token comment\"># repeats the last command</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span>n<span class=\"token operator\">></span>      <span class=\"token comment\"># refers to command line 'n'</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span>string<span class=\"token operator\">></span> <span class=\"token comment\"># refers to command starting with 'string'</span>\n\n<span class=\"token builtin class-name\">exit</span>      <span class=\"token comment\"># logs out of current session</span>\n\n\n<span class=\"token comment\"># BASH BASICS</span>\n\n\n<span class=\"token function\">env</span>                 <span class=\"token comment\"># displays all environment variables</span>\n\n<span class=\"token builtin class-name\">echo</span> <span class=\"token environment constant\">$SHELL</span>         <span class=\"token comment\"># displays the shell you're using</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token environment constant\">$BASH_VERSION</span>  <span class=\"token comment\"># displays bash version</span>\n\n<span class=\"token function\">bash</span>                <span class=\"token comment\"># if you want to use bash (type exit to go back to your previously opened shell)</span>\n<span class=\"token function\">whereis</span> <span class=\"token function\">bash</span>        <span class=\"token comment\"># locates the binary, source and manual-page for a command</span>\n<span class=\"token function\">which</span> <span class=\"token function\">bash</span>          <span class=\"token comment\"># finds out which program is executed as 'bash' (default: /bin/bash, can change across environments)</span>\n\n<span class=\"token function\">clear</span>               <span class=\"token comment\"># clears content on window (hide displayed lines)</span>\n\n\n<span class=\"token comment\"># FILE COMMANDS</span>\n\n\n<span class=\"token function\">ls</span>                            <span class=\"token comment\"># lists your files in current directory, ls &lt;dir> to print files in a specific directory</span>\n<span class=\"token function\">ls</span> <span class=\"token parameter variable\">-l</span>                         <span class=\"token comment\"># lists your files in 'long format', which contains the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified</span>\n<span class=\"token function\">ls</span> <span class=\"token parameter variable\">-a</span>                         <span class=\"token comment\"># lists all files in 'long format', including hidden files (name beginning with '.')</span>\n<span class=\"token function\">ln</span> <span class=\"token parameter variable\">-s</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>link<span class=\"token operator\">></span>       <span class=\"token comment\"># creates symbolic link to file</span>\nreadlink <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>           <span class=\"token comment\"># shows where a symbolic links points to</span>\ntree                          <span class=\"token comment\"># show directories and subdirectories in easilly readable file tree</span>\n<span class=\"token function\">mc</span>                            <span class=\"token comment\"># terminal file explorer (alternative to ncdu)</span>\n<span class=\"token function\">touch</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>              <span class=\"token comment\"># creates or updates (edit) your file</span>\nmktemp <span class=\"token parameter variable\">-t</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>            <span class=\"token comment\"># make a temp file in /tmp/ which is deleted at next boot (-d to make directory)</span>\n<span class=\"token function\">cat</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                <span class=\"token comment\"># prints file raw content (will not be interpreted)</span>\nany_command <span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>      <span class=\"token comment\"># '>' is used to perform redirections, it will set any_command's stdout to file instead of \"real stdout\" (generally /dev/stdout)</span>\n<span class=\"token function\">more</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># shows the first part of a file (move with space and type q to quit)</span>\n<span class=\"token function\">head</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># outputs the first lines of file (default: 10 lines)</span>\n<span class=\"token function\">tail</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># outputs the last lines of file (useful with -f option) (default: 10 lines)</span>\n<span class=\"token function\">vim</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                <span class=\"token comment\"># opens a file in VIM (VI iMproved) text editor, will create it if it doesn't exist</span>\n<span class=\"token function\">mv</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>dest<span class=\"token operator\">></span>         <span class=\"token comment\"># moves a file to destination, behavior will change based on 'dest' type (dir: file is placed into dir; file: file will replace dest (tip: useful for renaming))</span>\n<span class=\"token function\">cp</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>dest<span class=\"token operator\">></span>         <span class=\"token comment\"># copies a file</span>\n<span class=\"token function\">rm</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                 <span class=\"token comment\"># removes a file</span>\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token operator\">&lt;</span>name<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>type<span class=\"token operator\">></span>    <span class=\"token comment\"># searches for a file or a directory in the current directory and all its sub-directories by its name</span>\n<span class=\"token function\">diff</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span>  <span class=\"token comment\"># compares files, and shows where they differ</span>\n<span class=\"token function\">wc</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                 <span class=\"token comment\"># tells you how many lines, words and characters there are in a file. Use -lwc (lines, word, character) to ouput only 1 of those informations</span>\n<span class=\"token function\">sort</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># sorts the contents of a text file line by line in alphabetical order, use -n for numeric sort and -r for reversing order.</span>\n<span class=\"token function\">sort</span> <span class=\"token parameter variable\">-t</span> <span class=\"token parameter variable\">-k</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>         <span class=\"token comment\"># sorts the contents on specific sort key field starting from 1, using the field separator t.</span>\n<span class=\"token function\">rev</span>                           <span class=\"token comment\"># reverse string characters (hello becomes olleh)</span>\n<span class=\"token function\">chmod</span> <span class=\"token parameter variable\">-options</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>     <span class=\"token comment\"># lets you change the read, write, and execute permissions on your files (more infos: SUID, GUID)</span>\n<span class=\"token function\">gzip</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># compresses files using gzip algorithm</span>\ngunzip <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>             <span class=\"token comment\"># uncompresses files compressed by gzip</span>\ngzcat <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>              <span class=\"token comment\"># lets you look at gzipped file without actually having to gunzip it</span>\n<span class=\"token function\">lpr</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                <span class=\"token comment\"># prints the file</span>\nlpq                           <span class=\"token comment\"># checks out the printer queue</span>\n<span class=\"token function\">lprm</span> <span class=\"token operator\">&lt;</span>jobnumber<span class=\"token operator\">></span>              <span class=\"token comment\"># removes something from the printer queue</span>\ngenscript                     <span class=\"token comment\"># converts plain text files into postscript for printing and gives you some options for formatting</span>\ndvips <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>              <span class=\"token comment\"># prints .dvi files (i.e. files produced by LaTeX)</span>\n<span class=\"token function\">grep</span> <span class=\"token operator\">&lt;</span>pattern<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>filenames<span class=\"token operator\">></span>    <span class=\"token comment\"># looks for the string in the files</span>\n<span class=\"token function\">grep</span> <span class=\"token parameter variable\">-r</span> <span class=\"token operator\">&lt;</span>pattern<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\">></span>       <span class=\"token comment\"># search recursively for pattern in directory</span>\n<span class=\"token function\">head</span> <span class=\"token parameter variable\">-n</span> file_name <span class=\"token operator\">|</span> <span class=\"token function\">tail</span> +n   <span class=\"token comment\"># Print nth line from file.</span>\n<span class=\"token function\">head</span> <span class=\"token parameter variable\">-y</span> lines.txt <span class=\"token operator\">|</span> <span class=\"token function\">tail</span> +x   <span class=\"token comment\"># want to display all the lines from x to y. This includes the xth and yth lines.</span>\n\n\n<span class=\"token comment\"># DIRECTORY COMMANDS</span>\n\n\n<span class=\"token function\">mkdir</span> <span class=\"token operator\">&lt;</span>dirname<span class=\"token operator\">></span>               <span class=\"token comment\"># makes a new directory</span>\n<span class=\"token function\">rmdir</span> <span class=\"token operator\">&lt;</span>dirname<span class=\"token operator\">></span>               <span class=\"token comment\"># remove an empty directory</span>\n<span class=\"token function\">rmdir</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token operator\">&lt;</span>dirname<span class=\"token operator\">></span>           <span class=\"token comment\"># remove a non-empty directory</span>\n<span class=\"token function\">mv</span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span>              <span class=\"token comment\"># rename a directory from &lt;dir1> to &lt;dir2></span>\n<span class=\"token builtin class-name\">cd</span>                            <span class=\"token comment\"># changes to home</span>\n<span class=\"token builtin class-name\">cd</span> <span class=\"token punctuation\">..</span>                         <span class=\"token comment\"># changes to the parent directory</span>\n<span class=\"token builtin class-name\">cd</span> <span class=\"token operator\">&lt;</span>dirname<span class=\"token operator\">></span>                  <span class=\"token comment\"># changes directory</span>\n<span class=\"token function\">cp</span> <span class=\"token parameter variable\">-r</span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span>           <span class=\"token comment\"># copy &lt;dir1> into &lt;dir2> including sub-directories</span>\n<span class=\"token builtin class-name\">pwd</span>                           <span class=\"token comment\"># tells you where you currently are</span>\n<span class=\"token builtin class-name\">cd</span> ~                          <span class=\"token comment\"># changes to home.</span>\n<span class=\"token builtin class-name\">cd</span> -                        <span class=\"token comment\"># changes to previous working directory</span>\n\n\n<span class=\"token comment\"># SSH, SYSTEM INFO &amp; NETWORK COMMANDS</span>\n\n\n<span class=\"token function\">ssh</span> user@host            <span class=\"token comment\"># connects to host as user</span>\n<span class=\"token function\">ssh</span> <span class=\"token parameter variable\">-p</span> <span class=\"token operator\">&lt;</span>port<span class=\"token operator\">></span> user@host  <span class=\"token comment\"># connects to host on specified port as user</span>\nssh-copy-id user@host    <span class=\"token comment\"># adds your ssh key to host for user to enable a keyed or passwordless login</span>\n\n<span class=\"token function\">whoami</span>                   <span class=\"token comment\"># returns your username</span>\n<span class=\"token function\">passwd</span>                   <span class=\"token comment\"># lets you change your password</span>\n<span class=\"token function\">quota</span> <span class=\"token parameter variable\">-v</span>                 <span class=\"token comment\"># shows what your disk quota is</span>\n<span class=\"token function\">date</span>                     <span class=\"token comment\"># shows the current date and time</span>\n<span class=\"token function\">cal</span>                      <span class=\"token comment\"># shows the month's calendar</span>\n<span class=\"token function\">uptime</span>                   <span class=\"token comment\"># shows current uptime</span>\nw                        <span class=\"token comment\"># displays whois online</span>\nfinger <span class=\"token operator\">&lt;</span>user<span class=\"token operator\">></span>            <span class=\"token comment\"># displays information about user</span>\n<span class=\"token function\">uname</span> <span class=\"token parameter variable\">-a</span>                 <span class=\"token comment\"># shows kernel information</span>\n<span class=\"token function\">man</span> <span class=\"token operator\">&lt;</span>command<span class=\"token operator\">></span>            <span class=\"token comment\"># shows the manual for specified command</span>\n<span class=\"token function\">df</span>                       <span class=\"token comment\"># shows disk usage</span>\n<span class=\"token function\">du</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>            <span class=\"token comment\"># shows the disk usage of the files and directories in filename (du -s give only a total)</span>\nlast <span class=\"token operator\">&lt;</span>yourUsername<span class=\"token operator\">></span>      <span class=\"token comment\"># lists your last logins</span>\n<span class=\"token function\">ps</span> <span class=\"token parameter variable\">-u</span> yourusername       <span class=\"token comment\"># lists your processes</span>\n<span class=\"token function\">kill</span> <span class=\"token operator\">&lt;</span>PID<span class=\"token operator\">></span>               <span class=\"token comment\"># kills the processes with the ID you gave</span>\n<span class=\"token function\">killall</span> <span class=\"token operator\">&lt;</span>processname<span class=\"token operator\">></span>    <span class=\"token comment\"># kill all processes with the name</span>\n<span class=\"token function\">top</span>                      <span class=\"token comment\"># displays your currently active processes</span>\n<span class=\"token function\">lsof</span>                     <span class=\"token comment\"># lists open files</span>\n<span class=\"token function\">bg</span>                       <span class=\"token comment\"># lists stopped or background jobs ; resume a stopped job in the background</span>\n<span class=\"token function\">fg</span>                       <span class=\"token comment\"># brings the most recent job in the foreground</span>\n<span class=\"token function\">fg</span> <span class=\"token operator\">&lt;</span>job<span class=\"token operator\">></span>                 <span class=\"token comment\"># brings job to the foreground</span>\n\n<span class=\"token function\">ping</span> <span class=\"token operator\">&lt;</span>host<span class=\"token operator\">></span>              <span class=\"token comment\"># pings host and outputs results</span>\nwhois <span class=\"token operator\">&lt;</span>domain<span class=\"token operator\">></span>           <span class=\"token comment\"># gets whois information for domain</span>\n<span class=\"token function\">dig</span> <span class=\"token operator\">&lt;</span>domain<span class=\"token operator\">></span>             <span class=\"token comment\"># gets DNS information for domain</span>\n<span class=\"token function\">dig</span> <span class=\"token parameter variable\">-x</span> <span class=\"token operator\">&lt;</span>host<span class=\"token operator\">></span>            <span class=\"token comment\"># reverses lookup host</span>\n<span class=\"token function\">wget</span> <span class=\"token operator\">&lt;</span>file<span class=\"token operator\">></span>              <span class=\"token comment\"># downloads file</span>\n\n<span class=\"token function\">time</span> <span class=\"token operator\">&lt;</span>command<span class=\"token operator\">></span>             <span class=\"token comment\"># report time consumed by command execution</span>\n\n\n<span class=\"token comment\"># VARIABLES</span>\n\n\n<span class=\"token assign-left variable\">varname</span><span class=\"token operator\">=</span>value                <span class=\"token comment\"># defines a variable</span>\n<span class=\"token assign-left variable\">varname</span><span class=\"token operator\">=</span>value <span class=\"token builtin class-name\">command</span>        <span class=\"token comment\"># defines a variable to be in the environment of a particular subprocess</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$varname</span>                <span class=\"token comment\"># checks a variable's value</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$$</span>                      <span class=\"token comment\"># prints process ID of the current shell</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$!</span>                      <span class=\"token comment\"># prints process ID of the most recently invoked background job</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$?</span>                      <span class=\"token comment\"># displays the exit status of the last command</span>\n<span class=\"token builtin class-name\">read</span> <span class=\"token operator\">&lt;</span>varname<span class=\"token operator\">></span>               <span class=\"token comment\"># reads a string from the input and assigns it to a variable</span>\n<span class=\"token builtin class-name\">read</span> <span class=\"token parameter variable\">-p</span> <span class=\"token string\">\"prompt\"</span> <span class=\"token operator\">&lt;</span>varname<span class=\"token operator\">></span>   <span class=\"token comment\"># same as above but outputs a prompt to ask user for value</span>\n<span class=\"token function\">column</span> <span class=\"token parameter variable\">-t</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>         <span class=\"token comment\"># display info in pretty columns (often used with pipe)</span>\n<span class=\"token builtin class-name\">let</span> <span class=\"token operator\">&lt;</span>varname<span class=\"token operator\">></span> <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>equation<span class=\"token operator\">></span>   <span class=\"token comment\"># performs mathematical calculation using operators like +, -, *, /, %</span>\n<span class=\"token builtin class-name\">export</span> <span class=\"token assign-left variable\">VARNAME</span><span class=\"token operator\">=</span>value         <span class=\"token comment\"># defines an environment variable (will be available in subprocesses)</span>\n\narray<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valA                <span class=\"token comment\"># how to define an array</span>\narray<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valB\narray<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valC\n<span class=\"token assign-left variable\">array</span><span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valC <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valA <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valB<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># another way</span>\n<span class=\"token assign-left variable\">array</span><span class=\"token operator\">=</span><span class=\"token punctuation\">(</span>valA valB valC<span class=\"token punctuation\">)</span>              <span class=\"token comment\"># and another</span>\n\n<span class=\"token variable\">${array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span>}</span>                  <span class=\"token comment\"># displays array's value for this index. If no index is supplied, array element 0 is assumed</span>\n<span class=\"token variable\">${<span class=\"token operator\">#</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span>}</span>                 <span class=\"token comment\"># to find out the length of any element in the array</span>\n<span class=\"token variable\">${<span class=\"token operator\">#</span>array<span class=\"token punctuation\">[</span>@<span class=\"token punctuation\">]</span>}</span>                 <span class=\"token comment\"># to find out how many values there are in the array</span>\n\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-a</span>                   <span class=\"token comment\"># the variables are treated as arrays</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-f</span>                   <span class=\"token comment\"># uses function names only</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-F</span>                   <span class=\"token comment\"># displays function names without definitions</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-i</span>                   <span class=\"token comment\"># the variables are treated as integers</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-r</span>                   <span class=\"token comment\"># makes the variables read-only</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-x</span>                   <span class=\"token comment\"># marks the variables for export via the environment</span>\n\n<span class=\"token variable\">${varname<span class=\"token operator\">:-</span>word}</span>             <span class=\"token comment\"># if varname exists and isn't null, return its value; otherwise return word</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:</span>word}</span>              <span class=\"token comment\"># if varname exists and isn't null, return its value; otherwise return word</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:=</span>word}</span>             <span class=\"token comment\"># if varname exists and isn't null, return its value; otherwise set it word and then return its value</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:?</span>message}</span>          <span class=\"token comment\"># if varname exists and isn't null, return its value; otherwise print varname, followed by message and abort the current command or script</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:+</span>word}</span>             <span class=\"token comment\"># if varname exists and isn't null, return word; otherwise return null</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:</span>offset<span class=\"token operator\">:</span>length}</span>     <span class=\"token comment\"># performs substring expansion. It returns the substring of $varname starting at offset and up to length characters</span>\n\n<span class=\"token variable\">${variable<span class=\"token operator\">#</span>pattern}</span>          <span class=\"token comment\"># if the pattern matches the beginning of the variable's value, delete the shortest part that matches and return the rest</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">##</span>pattern}</span>         <span class=\"token comment\"># if the pattern matches the beginning of the variable's value, delete the longest part that matches and return the rest</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">%</span>pattern}</span>          <span class=\"token comment\"># if the pattern matches the end of the variable's value, delete the shortest part that matches and return the rest</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">%%</span>pattern}</span>         <span class=\"token comment\"># if the pattern matches the end of the variable's value, delete the longest part that matches and return the rest</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">/</span>pattern<span class=\"token operator\">/</span>string}</span>   <span class=\"token comment\"># the longest match to pattern in variable is replaced by string. Only the first match is replaced</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">/</span><span class=\"token operator\">/</span>pattern<span class=\"token operator\">/</span>string}</span>  <span class=\"token comment\"># the longest match to pattern in variable is replaced by string. All matches are replaced</span>\n\n<span class=\"token variable\">${<span class=\"token operator\">#</span>varname}</span>                  <span class=\"token comment\"># returns the length of the value of the variable as a character string</span>\n\n*<span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches zero or more occurrences of the given patterns</span>\n+<span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches one or more occurrences of the given patterns</span>\n?<span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches zero or one occurrence of the given patterns</span>\n@<span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches exactly one of the given patterns</span>\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches anything except one of the given patterns</span>\n\n<span class=\"token variable\"><span class=\"token variable\">$(</span>UNIX <span class=\"token builtin class-name\">command</span><span class=\"token variable\">)</span></span>              <span class=\"token comment\"># command substitution: runs the command and returns standard output</span>\n\n\n<span class=\"token comment\"># FUNCTIONS</span>\n\n\n<span class=\"token comment\"># The function refers to passed arguments by position (as if they were positional parameters), that is, $1, $2, and so forth.</span>\n<span class=\"token comment\"># $@ is equal to \"$1\" \"$2\"... \"$N\", where N is the number of positional parameters. $# holds the number of positional parameters.</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">functname</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  shell commands\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token builtin class-name\">unset</span> <span class=\"token parameter variable\">-f</span> functname  <span class=\"token comment\"># deletes a function definition</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-f</span>          <span class=\"token comment\"># displays all defined functions in your login session</span>\n\n\n<span class=\"token comment\"># FLOW CONTROLS</span>\n\n\nstatement1 <span class=\"token operator\">&amp;&amp;</span> statement2  <span class=\"token comment\"># and operator</span>\nstatement1 <span class=\"token operator\">||</span> statement2  <span class=\"token comment\"># or operator</span>\n\n<span class=\"token parameter variable\">-a</span>                        <span class=\"token comment\"># and operator inside a test conditional expression</span>\n<span class=\"token parameter variable\">-o</span>                        <span class=\"token comment\"># or operator inside a test conditional expression</span>\n\n<span class=\"token comment\"># STRINGS</span>\n\nstr1 <span class=\"token operator\">==</span> str2               <span class=\"token comment\"># str1 matches str2</span>\nstr1 <span class=\"token operator\">!=</span> str2               <span class=\"token comment\"># str1 does not match str2</span>\nstr1 <span class=\"token operator\">&lt;</span> str2                <span class=\"token comment\"># str1 is less than str2 (alphabetically)</span>\nstr1 <span class=\"token operator\">></span> str2                <span class=\"token comment\"># str1 is greater than str2 (alphabetically)</span>\nstr1 <span class=\"token punctuation\">\\</span><span class=\"token operator\">></span> str2               <span class=\"token comment\"># str1 is sorted after str2</span>\nstr1 <span class=\"token punctuation\">\\</span><span class=\"token operator\">&lt;</span> str2               <span class=\"token comment\"># str1 is sorted before str2</span>\n<span class=\"token parameter variable\">-n</span> str1                    <span class=\"token comment\"># str1 is not null (has length greater than 0)</span>\n<span class=\"token parameter variable\">-z</span> str1                    <span class=\"token comment\"># str1 is null (has length 0)</span>\n\n<span class=\"token comment\"># FILES</span>\n\n<span class=\"token parameter variable\">-a</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists or its compilation is successful</span>\n<span class=\"token parameter variable\">-d</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists and is a directory</span>\n<span class=\"token parameter variable\">-e</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists; same -a</span>\n<span class=\"token parameter variable\">-f</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists and is a regular file (i.e., not a directory or other special type of file)</span>\n<span class=\"token parameter variable\">-r</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># you have read permission</span>\n<span class=\"token parameter variable\">-s</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists and is not empty</span>\n<span class=\"token parameter variable\">-w</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># your have write permission</span>\n<span class=\"token parameter variable\">-x</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># you have execute permission on file, or directory search permission if it is a directory</span>\n<span class=\"token parameter variable\">-N</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file was modified since it was last read</span>\n<span class=\"token parameter variable\">-O</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># you own file</span>\n<span class=\"token parameter variable\">-G</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file's group ID matches yours (or one of yours, if you are in multiple groups)</span>\nfile1 <span class=\"token parameter variable\">-nt</span> file2           <span class=\"token comment\"># file1 is newer than file2</span>\nfile1 <span class=\"token parameter variable\">-ot</span> file2           <span class=\"token comment\"># file1 is older than file2</span>\n\n<span class=\"token comment\"># NUMBERS</span>\n\n<span class=\"token parameter variable\">-lt</span>                       <span class=\"token comment\"># less than</span>\n<span class=\"token parameter variable\">-le</span>                       <span class=\"token comment\"># less than or equal</span>\n<span class=\"token parameter variable\">-eq</span>                       <span class=\"token comment\"># equal</span>\n<span class=\"token parameter variable\">-ge</span>                       <span class=\"token comment\"># greater than or equal</span>\n<span class=\"token parameter variable\">-gt</span>                       <span class=\"token comment\"># greater than</span>\n<span class=\"token parameter variable\">-ne</span>                       <span class=\"token comment\"># not equal</span>\n\n<span class=\"token keyword\">if</span> condition\n<span class=\"token keyword\">then</span>\n  statements\n<span class=\"token punctuation\">[</span>elif condition\n  <span class=\"token keyword\">then</span> statements<span class=\"token punctuation\">..</span>.<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span>else\n  statements<span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">fi</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">x</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">..</span><span class=\"token number\">10</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">do</span>\n  statements\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> name <span class=\"token punctuation\">[</span>in list<span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">do</span>\n  statements that can use <span class=\"token variable\">$name</span>\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token variable\"><span class=\"token punctuation\">((</span> initialisation <span class=\"token punctuation\">;</span> ending condition <span class=\"token punctuation\">;</span> update <span class=\"token punctuation\">))</span></span>\n<span class=\"token keyword\">do</span>\n  statements<span class=\"token punctuation\">..</span>.\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">case</span> expression <span class=\"token keyword\">in</span>\n  pattern1 <span class=\"token punctuation\">)</span>\n    statements <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n  pattern2 <span class=\"token punctuation\">)</span>\n    statements <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">esac</span>\n\n<span class=\"token keyword\">select</span> name <span class=\"token punctuation\">[</span>in list<span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">do</span>\n  statements that can use <span class=\"token variable\">$name</span>\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">while</span> condition<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span>\n  statements\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">until</span> condition<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span>\n  statements\n<span class=\"token keyword\">done</span>\n\n\n<span class=\"token comment\"># COMMAND-LINE PROCESSING CYCLE</span>\n\n\n<span class=\"token comment\"># The default order for command lookup is functions, followed by built-ins, with scripts and executables last.</span>\n<span class=\"token comment\"># There are three built-ins that you can use to override this order: `command`, `builtin` and `enable`.</span>\n\n<span class=\"token builtin class-name\">command</span>  <span class=\"token comment\"># removes alias and function lookup. Only built-ins and commands found in the search path are executed</span>\n<span class=\"token builtin class-name\">builtin</span>  <span class=\"token comment\"># looks up only built-in commands, ignoring functions and commands found in PATH</span>\n<span class=\"token builtin class-name\">enable</span>   <span class=\"token comment\"># enables and disables shell built-ins</span>\n\n<span class=\"token builtin class-name\">eval</span>     <span class=\"token comment\"># takes arguments and run them through the command-line processing steps all over again</span>\n\n\n<span class=\"token comment\"># INPUT/OUTPUT REDIRECTORS</span>\n\n\ncmd1<span class=\"token operator\">|</span>cmd2  <span class=\"token comment\"># pipe; takes standard output of cmd1 as standard input to cmd2</span>\n<span class=\"token operator\">&lt;</span> <span class=\"token function\">file</span>     <span class=\"token comment\"># takes standard input from file</span>\n<span class=\"token operator\">></span> <span class=\"token function\">file</span>     <span class=\"token comment\"># directs standard output to file</span>\n<span class=\"token operator\">>></span> <span class=\"token function\">file</span>    <span class=\"token comment\"># directs standard output to file; append to file if it already exists</span>\n<span class=\"token operator\">>|</span><span class=\"token function\">file</span>     <span class=\"token comment\"># forces standard output to file even if noclobber is set</span>\nn<span class=\"token operator\">>|</span><span class=\"token function\">file</span>    <span class=\"token comment\"># forces output to file from file descriptor n even if noclobber is set</span>\n<span class=\"token operator\">&lt;></span> <span class=\"token function\">file</span>    <span class=\"token comment\"># uses file as both standard input and standard output</span>\nn<span class=\"token operator\">&lt;></span>file    <span class=\"token comment\"># uses file as both input and output for file descriptor n</span>\nn<span class=\"token operator\">></span>file     <span class=\"token comment\"># directs file descriptor n to file</span>\nn<span class=\"token operator\">&lt;</span>file     <span class=\"token comment\"># takes file descriptor n from file</span>\nn<span class=\"token operator\">>></span>file    <span class=\"token comment\"># directs file description n to file; append to file if it already exists</span>\nn<span class=\"token operator\">>&amp;</span>        <span class=\"token comment\"># duplicates standard output to file descriptor n</span>\nn<span class=\"token operator\">&lt;&amp;</span>        <span class=\"token comment\"># duplicates standard input from file descriptor n</span>\nn<span class=\"token operator\">>&amp;</span>m       <span class=\"token comment\"># file descriptor n is made to be a copy of the output file descriptor</span>\nn<span class=\"token operator\">&lt;&amp;</span>m       <span class=\"token comment\"># file descriptor n is made to be a copy of the input file descriptor</span>\n<span class=\"token operator\">&amp;></span>file     <span class=\"token comment\"># directs standard output and standard error to file</span>\n<span class=\"token operator\">&lt;&amp;</span>-      <span class=\"token comment\"># closes the standard input</span>\n<span class=\"token operator\">>&amp;</span>-      <span class=\"token comment\"># closes the standard output</span>\nn<span class=\"token operator\">>&amp;</span>-     <span class=\"token comment\"># closes the ouput from file descriptor n</span>\nn<span class=\"token operator\">&lt;&amp;</span>-     <span class=\"token comment\"># closes the input from file descripor n</span>\n\n<span class=\"token operator\">|</span><span class=\"token function\">tee</span> <span class=\"token operator\">&lt;</span>file<span class=\"token operator\">></span><span class=\"token comment\"># output command to both terminal and a file (-a to append to file)</span>\n\n\n<span class=\"token comment\"># PROCESS HANDLING</span>\n\n\n<span class=\"token comment\"># To suspend a job, type CTRL+Z while it is running. You can also suspend a job with CTRL+Y.</span>\n<span class=\"token comment\"># This is slightly different from CTRL+Z in that the process is only stopped when it attempts to read input from terminal.</span>\n<span class=\"token comment\"># Of course, to interrupt a job, type CTRL+C.</span>\n\nmyCommand <span class=\"token operator\">&amp;</span>  <span class=\"token comment\"># runs job in the background and prompts back the shell</span>\n\n<span class=\"token function\">jobs</span>         <span class=\"token comment\"># lists all jobs (use with -l to see associated PID)</span>\n\n<span class=\"token function\">fg</span>           <span class=\"token comment\"># brings a background job into the foreground</span>\n<span class=\"token function\">fg</span> %+        <span class=\"token comment\"># brings most recently invoked background job</span>\n<span class=\"token function\">fg</span> %-      <span class=\"token comment\"># brings second most recently invoked background job</span>\n<span class=\"token function\">fg</span> %N        <span class=\"token comment\"># brings job number N</span>\n<span class=\"token function\">fg</span> %string   <span class=\"token comment\"># brings job whose command begins with string</span>\n<span class=\"token function\">fg</span> %?string  <span class=\"token comment\"># brings job whose command contains string</span>\n\n<span class=\"token function\">kill</span> <span class=\"token parameter variable\">-l</span>               <span class=\"token comment\"># returns a list of all signals on the system, by name and number</span>\n<span class=\"token function\">kill</span> PID              <span class=\"token comment\"># terminates process with specified PID</span>\n<span class=\"token function\">kill</span> <span class=\"token parameter variable\">-s</span> SIGKILL <span class=\"token number\">4500</span>  <span class=\"token comment\"># sends a signal to force or terminate the process</span>\n<span class=\"token function\">kill</span> <span class=\"token parameter variable\">-15</span> <span class=\"token number\">913</span>          <span class=\"token comment\"># Ending PID 913 process with signal 15 (TERM)</span>\n<span class=\"token function\">kill</span> %1               <span class=\"token comment\"># Where %1 is the number of job as read from 'jobs' command.</span>\n\n<span class=\"token function\">ps</span>           <span class=\"token comment\"># prints a line of information about the current running login shell and any processes running under it</span>\n<span class=\"token function\">ps</span> <span class=\"token parameter variable\">-a</span>        <span class=\"token comment\"># selects all processes with a tty except session leaders</span>\n\n<span class=\"token builtin class-name\">trap</span> cmd sig1 sig2  <span class=\"token comment\"># executes a command when a signal is received by the script</span>\n<span class=\"token builtin class-name\">trap</span> <span class=\"token string\">\"\"</span> sig1 sig2   <span class=\"token comment\"># ignores that signals</span>\n<span class=\"token builtin class-name\">trap</span> - sig1 sig2    <span class=\"token comment\"># resets the action taken when the signal is received to the default</span>\n\ndisown <span class=\"token operator\">&lt;</span>PID<span class=\"token operator\">|</span>JID<span class=\"token operator\">></span>    <span class=\"token comment\"># removes the process from the list of jobs</span>\n\n<span class=\"token function\">wait</span>                <span class=\"token comment\"># waits until all background jobs have finished</span>\n<span class=\"token function\">sleep</span> <span class=\"token operator\">&lt;</span>number<span class=\"token operator\">></span>      <span class=\"token comment\"># wait # of seconds before continuing</span>\n\n<span class=\"token function\">pv</span>                  <span class=\"token comment\"># display progress bar for data handling commands. often used with pipe like |pv</span>\n<span class=\"token function\">yes</span>                 <span class=\"token comment\"># give yes response everytime an input is requested from script/process</span>\n\n\n<span class=\"token comment\"># TIPS &amp; TRICKS</span>\n\n\n<span class=\"token comment\"># set an alias</span>\n<span class=\"token builtin class-name\">cd</span><span class=\"token punctuation\">;</span> <span class=\"token function\">nano</span> .bash_profile\n<span class=\"token operator\">></span> <span class=\"token builtin class-name\">alias</span> <span class=\"token assign-left variable\">gentlenode</span><span class=\"token operator\">=</span><span class=\"token string\">'ssh admin@gentlenode.com -p 3404'</span>  <span class=\"token comment\"># add your alias in .bash_profile</span>\n\n<span class=\"token comment\"># to quickly go to a specific directory</span>\n<span class=\"token builtin class-name\">cd</span><span class=\"token punctuation\">;</span> <span class=\"token function\">nano</span> .bashrc\n<span class=\"token operator\">></span> <span class=\"token builtin class-name\">shopt</span> <span class=\"token parameter variable\">-s</span> cdable_vars\n<span class=\"token operator\">></span> <span class=\"token builtin class-name\">export</span> <span class=\"token assign-left variable\">websites</span><span class=\"token operator\">=</span><span class=\"token string\">\"/Users/mac/Documents/websites\"</span>\n\n<span class=\"token builtin class-name\">source</span> .bashrc\n<span class=\"token builtin class-name\">cd</span> <span class=\"token variable\">$websites</span>\n\n\n<span class=\"token comment\"># DEBUGGING SHELL PROGRAMS</span>\n\n\n<span class=\"token function\">bash</span> <span class=\"token parameter variable\">-n</span> scriptname  <span class=\"token comment\"># don't run commands; check for syntax errors only</span>\n<span class=\"token builtin class-name\">set</span> <span class=\"token parameter variable\">-o</span> noexec       <span class=\"token comment\"># alternative (set option in script)</span>\n\n<span class=\"token function\">bash</span> <span class=\"token parameter variable\">-v</span> scriptname  <span class=\"token comment\"># echo commands before running them</span>\n<span class=\"token builtin class-name\">set</span> <span class=\"token parameter variable\">-o</span> verbose      <span class=\"token comment\"># alternative (set option in script)</span>\n\n<span class=\"token function\">bash</span> <span class=\"token parameter variable\">-x</span> scriptname  <span class=\"token comment\"># echo commands after command-line processing</span>\n<span class=\"token builtin class-name\">set</span> <span class=\"token parameter variable\">-o</span> xtrace       <span class=\"token comment\"># alternative (set option in script)</span>\n\n<span class=\"token builtin class-name\">trap</span> <span class=\"token string\">'echo $varname'</span> EXIT  <span class=\"token comment\"># useful when you want to print out the values of variables at the point that your script exits</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">errtrap</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token assign-left variable\">es</span><span class=\"token operator\">=</span><span class=\"token variable\">$?</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"ERROR line <span class=\"token variable\">$1</span>: Command exited with status <span class=\"token variable\">$es</span>.\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token builtin class-name\">trap</span> <span class=\"token string\">'errtrap $LINENO'</span> ERR  <span class=\"token comment\"># is run whenever a command in the surrounding script or function exits with non-zero status</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">dbgtrap</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"badvar is <span class=\"token variable\">$badvar</span>\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token builtin class-name\">trap</span> dbgtrap DEBUG  <span class=\"token comment\"># causes the trap code to be executed before every statement in a function or script</span>\n<span class=\"token comment\"># ...section of code in which the problem occurs...</span>\n<span class=\"token builtin class-name\">trap</span> - DEBUG  <span class=\"token comment\"># turn off the DEBUG trap</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">returntrap</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"A return occurred\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token builtin class-name\">trap</span> returntrap RETURN  <span class=\"token comment\"># is executed each time a shell function or a script executed with the . or source commands finishes executing</span>\n\n\n<span class=\"token comment\"># COLORS AND BACKGROUNDS</span>\n\n<span class=\"token comment\"># note: \\e or \\x1B also work instead of \\033</span>\n<span class=\"token comment\"># Reset</span>\n<span class=\"token assign-left variable\">Color_Off</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0m'</span> <span class=\"token comment\"># Text Reset</span>\n\n<span class=\"token comment\"># Regular Colors</span>\n<span class=\"token assign-left variable\">Black</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;30m'</span>  <span class=\"token comment\"># Black</span>\n<span class=\"token assign-left variable\">Red</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;31m'</span>    <span class=\"token comment\"># Red</span>\n<span class=\"token assign-left variable\">Green</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;32m'</span>  <span class=\"token comment\"># Green</span>\n<span class=\"token assign-left variable\">Yellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;33m'</span> <span class=\"token comment\"># Yellow</span>\n<span class=\"token assign-left variable\">Blue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;34m'</span>   <span class=\"token comment\"># Blue</span>\n<span class=\"token assign-left variable\">Purple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;35m'</span> <span class=\"token comment\"># Purple</span>\n<span class=\"token assign-left variable\">Cyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;36m'</span>   <span class=\"token comment\"># Cyan</span>\n<span class=\"token assign-left variable\">White</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;97m'</span>  <span class=\"token comment\"># White</span>\n\n<span class=\"token comment\"># Additional colors</span>\n<span class=\"token assign-left variable\">LGrey</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;37m'</span>  <span class=\"token comment\"># Ligth Gray</span>\n<span class=\"token assign-left variable\">DGrey</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;90m'</span>  <span class=\"token comment\"># Dark Gray</span>\n<span class=\"token assign-left variable\">LRed</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;91m'</span>   <span class=\"token comment\"># Ligth Red</span>\n<span class=\"token assign-left variable\">LGreen</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;92m'</span> <span class=\"token comment\"># Ligth Green</span>\n<span class=\"token assign-left variable\">LYellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;93m'</span><span class=\"token comment\"># Ligth Yellow</span>\n<span class=\"token assign-left variable\">LBlue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;94m'</span>  <span class=\"token comment\"># Ligth Blue</span>\n<span class=\"token assign-left variable\">LPurple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;95m'</span><span class=\"token comment\"># Light Purple</span>\n<span class=\"token assign-left variable\">LCyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;96m'</span>  <span class=\"token comment\"># Ligth Cyan</span>\n\n<span class=\"token comment\"># Bold</span>\n<span class=\"token assign-left variable\">BBlack</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;30m'</span> <span class=\"token comment\"># Black</span>\n<span class=\"token assign-left variable\">BRed</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;31m'</span>   <span class=\"token comment\"># Red</span>\n<span class=\"token assign-left variable\">BGreen</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;32m'</span> <span class=\"token comment\"># Green</span>\n<span class=\"token assign-left variable\">BYellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;33m'</span><span class=\"token comment\"># Yellow</span>\n<span class=\"token assign-left variable\">BBlue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;34m'</span>  <span class=\"token comment\"># Blue</span>\n<span class=\"token assign-left variable\">BPurple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;35m'</span><span class=\"token comment\"># Purple</span>\n<span class=\"token assign-left variable\">BCyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;36m'</span>  <span class=\"token comment\"># Cyan</span>\n<span class=\"token assign-left variable\">BWhite</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;37m'</span> <span class=\"token comment\"># White</span>\n\n<span class=\"token comment\"># Underline</span>\n<span class=\"token assign-left variable\">UBlack</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;30m'</span> <span class=\"token comment\"># Black</span>\n<span class=\"token assign-left variable\">URed</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;31m'</span>   <span class=\"token comment\"># Red</span>\n<span class=\"token assign-left variable\">UGreen</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;32m'</span> <span class=\"token comment\"># Green</span>\n<span class=\"token assign-left variable\">UYellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;33m'</span><span class=\"token comment\"># Yellow</span>\n<span class=\"token assign-left variable\">UBlue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;34m'</span>  <span class=\"token comment\"># Blue</span>\n<span class=\"token assign-left variable\">UPurple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;35m'</span><span class=\"token comment\"># Purple</span>\n<span class=\"token assign-left variable\">UCyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;36m'</span>  <span class=\"token comment\"># Cyan</span>\n<span class=\"token assign-left variable\">UWhite</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;37m'</span> <span class=\"token comment\"># White</span>\n\n<span class=\"token comment\"># Background</span>\n<span class=\"token assign-left variable\">On_Black</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[40m'</span> <span class=\"token comment\"># Black</span>\n<span class=\"token assign-left variable\">On_Red</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[41m'</span>   <span class=\"token comment\"># Red</span>\n<span class=\"token assign-left variable\">On_Green</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[42m'</span> <span class=\"token comment\"># Green</span>\n<span class=\"token assign-left variable\">On_Yellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[43m'</span><span class=\"token comment\"># Yellow</span>\n<span class=\"token assign-left variable\">On_Blue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[44m'</span>  <span class=\"token comment\"># Blue</span>\n<span class=\"token assign-left variable\">On_Purple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[45m'</span><span class=\"token comment\"># Purple</span>\n<span class=\"token assign-left variable\">On_Cyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[46m'</span>  <span class=\"token comment\"># Cyan</span>\n<span class=\"token assign-left variable\">On_White</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[47m'</span> <span class=\"token comment\"># White</span>\n\n<span class=\"token comment\"># Example of usage</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">\"<span class=\"token variable\">${Green}</span>This is GREEN text<span class=\"token variable\">${Color_Off}</span> and normal text\"</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">\"<span class=\"token variable\">${Red}</span><span class=\"token variable\">${On_White}</span>This is Red test on White background<span class=\"token variable\">${Color_Off}</span>\"</span>\n<span class=\"token comment\"># option -e is mandatory, it enable interpretation of backslash escapes</span>\n<span class=\"token builtin class-name\">printf</span> <span class=\"token string\">\"<span class=\"token variable\">${Red}</span> This is red <span class=\"token entity\" title=\"\\n\">\\n</span>\"</span></code></pre></div>"},{"url":"/docs/reference/how-2-reinstall-npm/","relativePath":"docs/reference/how-2-reinstall-npm.md","relativeDir":"docs/reference","base":"how-2-reinstall-npm.md","name":"how-2-reinstall-npm","frontmatter":{"title":"How To Reinstall NPM and Node.js On Your System","weight":0,"excerpt":"How To Reinstall NPM and Node.js On Your System","seo":{"title":"How To Reinstall NPM and Node.js On Your System","description":"How To Reinstall NPM and Node.js On Your System","robots":[],"extra":[]},"template":"docs"},"html":"<p>The Node Package Manager (usually shortened to npm) and Node.js are popular technologies among JavaScript developers. npm is the default package management utility that is installed automatically on your machine when you download and install Node.js.</p>\n<p>npm assists in building, consuming, managing, and sharing small pieces of code. On the other hand, Node.js provides a server-side environment for creating powerful applications.</p>\n<p>However, at times, npm can get corrupted, become incompatible with other programs, or just experience performance issues. In such cases, it may help to reinstall npm on your system and save yourself the hassles. Similarly, reinstalling Node.js may assist you in clearing out any performance errors.</p>\n<p>And since npm is shipped with Node.js by default, installing Node.js will also install npm on your system.</p>\n<h2>How to check if reinstallation succeeded</h2>\n<p>Note that after completing the reinstallation process, you can check if it was successful by running the following commands on the terminal:</p>\n<p>Then, if everything went well, the system will output your installed versions.</p>\n<p>Something like this:</p>\n<p>Since npm is usually updated more frequently than Node.js, your installation may not come with the latest npm version.</p>\n<p>So, if your installed npm version is not the latest, you can update it by running the following command:</p>\n<p>The above command will install the latest, stable npm version. However, if you want to experiment with things by using a version that will be released in the future, you can run the following:</p>\n<p>If you want to update Node.js to the latest version, <a href=\"https://renovate.whitesourcesoftware.com/blog/update-node-js/\">you can read this article.</a></p>\n<h2>How to reinstall npm and Node.js on Windows</h2>\n<p>If the npm or Node.js running on your Windows environment is broken, you can reinstall and get the most out of them.</p>\n<p>You can use any of the following methods:</p>\n<ul>\n<li>Reinstalling using a Node version manager</li>\n<li>Reinstalling using a Node installer</li>\n</ul>\n<p>Let's talk about each of them.</p>\n<h3>a) Reinstalling using a Node version manager</h3>\n<p>A Node version manager is a tool you can use to install various versions of Node.js and npm and shift between them seamlessly.</p>\n<p>A popular Node version management tool you can use is <a href=\"https://github.com/coreybutler/nvm-windows/\">nvm-windows</a>. It's a powerful command line utility that allows you to manage multiple installations of Node.js comfortably.</p>\n<p>Before installing the utility, it is recommended to remove all the existing versions of Node.js and npm from your Windows computer. This will prevent any conflict issues when installing the software.</p>\n<p>You can uninstall them by doing the following:</p>\n<ul>\n<li>Go to the Windows Control Panel and uninstall the Node.js program.</li>\n<li>If any Node.js installation directories are still remaining, delete them. An example is C:\\Program Files\\mynodejs.</li>\n<li>If any npm install location is still remaining, delete it. An example is C:\\Users\\&#x3C;username>\\AppData\\Roaming\\npm.</li>\n</ul>\n<p>Then, once your system is clean, go to <a href=\"https://github.com/coreybutler/nvm-windows/releases\">this page</a> and download and run the latest nvm-windows installer. After it has been installed, you can start the Command Prompt or Powershell as an Administrator and use the tool to reinstall Node.js and npm.</p>\n<p>If you want to reinstall a specific Node.js version, you can run the following command:</p>\n<p>Let's say you want to reinstall Node.js version 12.18.0, you can run:</p>\n<p>If you want to reinstall the latest stable Node.js version, you can run:</p>\n<p>If you want to check the list of Node.js versions available for download, you can run:</p>\n<p>To use the installed Node.js version in your project, you can switch to it:</p>\n<h3>b) Reinstalling using a Node installer</h3>\n<p>Using the official Node installer is the easiest way to reinstall Node.js and npm on your Windows environment.</p>\n<p>To use this option, you can go to the <a href=\"https://nodejs.org/en/download/\">Node.js download page</a> and reinstall the latest Node.js version.</p>\n<p>It is recommended to download the version labeled LTS (Long-term Supported) because it has been tested with npm. Although the version labeled Current comes with the latest features, it may be unstable and unreliable.</p>\n<p><img src=\"https://www.whitesourcesoftware.com/wp-content/media/2020/09/12121.png\" alt=\"image\"></p>\n<p>After selecting the version you want to download, and clicking the Windows Installer option, the installation wizard will magically complete the installation process for you.</p>\n<p>Ultimately, the installer will automatically overwrite your existing, malfunctioned Node.js version with a new one.</p>\n<h2>How to reinstall npm and Node.js on macOS</h2>\n<p>Before reinstalling Node.js and npm on your macOS system, you'll need to remove any previously installed versions.</p>\n<p>Here are some ways you can use to uninstall them:</p>\n<ul>\n<li>Manually—this involves manually removing any references of Node and npm from your system. Unfortunately, this process is difficult since there may be several directories with Node resources. For example, you may need to delete the node executable and node_modules from /usr/local/lib, delete .npm from the home directory, and delete many other directories.</li>\n<li>Using a script—this involves running a script to uninstall Node.js and npm automatically from your macOS system. You can find a simple script to use <a href=\"https://gist.github.com/nicerobot/2697848\">here</a>.</li>\n<li>Using <a href=\"https://brew.sh/\">Homebrew</a>—this package management utility lets you complete the uninstallation process fast and easily. You can run the following command:</li>\n</ul>\n<p>Then, once your system is clean, you can use any of the following methods to reinstall Node.js and npm on macOS:</p>\n<ul>\n<li>Reinstalling using a Node installer</li>\n<li>Reinstalling using Homebrew</li>\n<li>Reinstalling using a Node version manager</li>\n</ul>\n<p>Let's talk about each of them.</p>\n<h3>a) Reinstalling using a Node installer</h3>\n<p>To use the official Node installer for reinstalling the tools, go to the <a href=\"https://nodejs.org/en/download/\">Node.js download page</a> and select the version you want to install—just as we described previously.</p>\n<p>Remember to choose the macOS installer option. If you run the installer, it will complete the reinstallation process for you automatically.</p>\n<h3>b) Reinstalling using Homebrew</h3>\n<p>To reinstall using Homebrew, just run the following command on the macOS terminal:</p>\n<h3>c) Reinstalling using a Node version manager</h3>\n<p>You can also reinstall the two tools using the <a href=\"https://github.com/nvm-sh/nvm\">nvm</a> Node version manager. Since the process for using nvm is the same for both macOS and Linux, we'll describe how to use it in the next section.</p>\n<h2>How to reinstall npm and Node.js on Linux</h2>\n<p>Just like in the previous cases, you'll need to remove any installed version of Node.js and npm before reinstalling them on a Linux distribution, such as Ubuntu.</p>\n<p>Here are some ways you can use to uninstall them:</p>\n<ul>\n<li>Using the apt package manager—you can remove Node.js by running the following command:</li>\n</ul>\n<p>The above command will delete the distro-stable version while retaining the configuration files for later use. However, if you intend to remove the package as well as its configuration files, run the following:</p>\n<p>Finally, you can delete any unused packages that were installed automatically with the deleted package:</p>\n<ul>\n<li>Using nvm—you can also use the nvm Node version manager to uninstall Node.js from your system. We'll illustrate how to do this in the next section.</li>\n</ul>\n<p>Then, once your machine is clean, you can use any of the following methods to reinstall Node.js and npm on Linux:</p>\n<ul>\n<li>Reinstalling using a Node version manager</li>\n<li>Reinstalling using the apt package manager</li>\n</ul>\n<p>Let's talk about each of them.</p>\n<h3>a) Reinstalling using a Node version manager</h3>\n<p>As earlier mentioned, you can use the <a href=\"https://github.com/nvm-sh/nvm/\">nvm</a> Node version manager to reinstall Node.js and npm on both macOS and Linux.</p>\n<p>To install the script-based tool, you can use either Wget or cURL.</p>\n<p>If using Wget, execute the following on the terminal:</p>\n<p>If using cURL, execute this:</p>\n<p>The above commands will install nvm version 0.35.0 on your system. Remember to check <a href=\"https://github.com/nvm-sh/nvm/releases\">the latest version</a> and refer to it accordingly on the command you want to run.</p>\n<p>To verify if it was installed successfully, run the following:</p>\n<p>If all went well, it would output nvm.</p>\n<p>After installing nvm, you can use it to reinstall Node.js on your system.</p>\n<p>Simply, execute the following command:</p>\n<p>To reinstall a specific Node.js version, run:</p>\n<p>For example, to reinstall Node.js version 12.18.0, execute:</p>\n<p>Once reinstallation is complete, you can set that Node.js version for use as the system-wide default version:</p>\n<p>Furthermore, you can check the list of Node.js versions available for download by executing the following:</p>\n<p>To remove a Node.js version that you've set up using nvm, start by establishing if the version is currently active on your system:</p>\n<p>If it is not actively running, execute the following to uninstall it:</p>\n<p>On the other hand, if the version targeted for removal is the current active version, you'll need to deactivate nvm first:</p>\n<p>Then, you can use the above uninstall command to remove it from your system.</p>\n<h3>b) Reinstalling using the apt package manager</h3>\n<p>A simpler way to reinstall Node.js and npm on a Linux distribution, such as Ubuntu, is to use the apt package manager.</p>\n<p>To do so, you can start by refreshing your local package index:</p>\n<p>Then, reinstall the distro-stable Node.js version from the repositories:</p>\n<p>In most cases, this is all you need to get up and running with Node.js. Also, you may want to reinstall npm by running the following command:</p>\n<h2>Conclusion</h2>\n<p>That's how to reinstall npm and Node.js on Windows, macOS, and Linux.</p>\n<p>After completing the reinstallation, you'll avoid any performance issues that often arise from using malfunctioned versions of the technologies.</p>\n<p>---</p>\n<p>---</p>\n<p>Node.js is a popular open-source, cross-platform server-side environment for building robust applications. Since a vibrant community of contributors backs it, the platform is continuously updated to introduce new features, security patches, and other performance improvements. node -version node -v wget -qO- <a href=\"https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh\">https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh</a> | bash curl -o- <a href=\"https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh\">https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh</a> | bash command -v nvm nvm install node nvm install -lts nvm install &#x3C;version-number> nvm install 12.18.3 nvm use 12.18.3 nvm lsnvm ls-remotenpm install -g nn &#x3C;version-number>n 12.18.3 nn ltsn latestnvm install &#x3C;version-number>nvm install 12.18.3nvm use 12.18.3nvm install latestnvm listnvm list availablewget <a href=\"https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xzsudo\">https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xzsudo</a> apt-get install xz-utilstar -C /usr/local -strip-components 1 -xJf node-v12.18.3-linux-x64.tar.xzbrew install nodebrew update #ensure Homebrew is up to date firstbrew upgrade nodebrew switch node 12.18.3</p>\n<p>So, updating to the latest Node.js version can help you to make the most of the technology. You can decide to work with the Long-term Supported (LTS) version or the Current version that comes with the latest features.</p>\n<p>Typically, LTS is recommended for most users because it is a stable version that provides predictable update releases as well as a slower introduction of substantial changes.</p>\n<p>In this article, you will learn how to quickly and easily update Node.js on different operating systems—macOS, Linux, and Windows.</p>\n<p>As we'll demonstrate, there are many ways of updating to the next version of Node.js. So, you can choose the option that best meets your system requirements and preferences.</p>\n<p>These are the updating options we'll talk about:</p>\n<ul>\n<li>Updating using a Node version manager on macOS or Linux</li>\n<li>Updating using a Node version manager on Windows</li>\n<li>Updating using a Node installer on Linux</li>\n<li>Updating using a Node installer on macOS and Windows</li>\n<li>Updating using Homebrew on macOS</li>\n</ul>\n<h2>Checking your version of Node.js</h2>\n<p>Before getting started, you can check the version of Node.js currently deployed on your system by running the following command on the terminal:</p>\n<p>or (shortened method):</p>\n<p>Let's now talk about the different ways on how to update Node.js.</p>\n<h2>1. Updating using a Node version manager on macOS or Linux</h2>\n<p>A Node version manager is a utility that lets you install different Node.js versions and switch flawlessly between them on your machine. You can also use it to update your version of Node.js.</p>\n<p>On macOS or Linux, you can use either of the following Node version managers:</p>\n<ul>\n<li>nvm</li>\n<li>n</li>\n</ul>\n<p>Let's talk about each of them.</p>\n<p>a) nvm</p>\n<p><a href=\"https://github.com/nvm-sh/nvm\">nvm</a> is a script-based version manager for Node.js. To install it on macOS or Linux, you can use either Wget or cURL.</p>\n<p>For Wget, run the following command on the terminal:</p>\n<p>For cURL, run the following:</p>\n<p>The above commands assume that you're installing nvm version 0.35.3. So, you'll need to check <a href=\"https://github.com/nvm-sh/nvm/releases\">the latest version</a> before installing it on your machine.</p>\n<p>With these commands, you can clone the repository to ~/.nvm. This way, you can make changes to your bash profile, allowing you to access nvm system-wide.</p>\n<p>To confirm if the installation was successful, you can run the following command:</p>\n<p>If everything went well, it'd output nvm.</p>\n<p>Next, you can simply download and update to the latest Node.js version by running the following:</p>\n<p>Note that node refers to an alias of the latest Node.js version.</p>\n<p>You can also reference LTS versions in aliases as well as .nvmrc files using the notation lts/* for the most recent LTS releases.</p>\n<p>Here is an example:</p>\n<p>If you want to install and upgrade to a specific version, you can run the following:</p>\n<p>For example, if you want to update Node.js to version 12.18.3, you can run:</p>\n<p>After the upgrade, you can set that version to be the default version to use throughout your system:</p>\n<p>You can see the list of installed Node.js versions by running this command:</p>\n<p>Also, you can see the list of versions available for installation by running this command:</p>\n<p>b) n</p>\n<p><a href=\"https://www.npmjs.com/package/n\">n</a> is another useful Node version manager you can use for updating Node.js on macOS and Linux.</p>\n<p>Since it's an <a href=\"https://renovate.whitesourcesoftware.com/blog/updating-npm-packages/\">npm-based package</a>, if you already have Node.js available on your environment, you can simply install it by running this command:</p>\n<p>Then, to download and update to your desired Node.js version, execute the following:</p>\n<p>For example, if you want to update Node.js to version 12.18.3, you can run:</p>\n<p>To see a list of your downloaded Node.js versions, run n on its own:</p>\n<p>You can specify to update to the newest LTS version by running:</p>\n<p>You can also specify to update to the latest current version by running:</p>\n<p>You can specify to update to the newest LTS version by running:</p>\n<h2></h2>\n<h2>2. Updating using a Node version manager on Windows</h2>\n<p>On Windows, you can use the following Node version manager:</p>\n<ul>\n<li>nvm-windows</li>\n</ul>\n<p>Let's talk about it.</p>\n<p><strong>a) nvm-windows</strong></p>\n<p><a href=\"https://github.com/coreybutler/nvm-windows/\">nvm-windows</a> is a Node version management tool for the Windows operating system. While it's not the same as nvm, both tools share several usage similarities for Node.js version management.</p>\n<p>Before installing nvm-windows, it's recommended to uninstall any available Node.js versions from your machine. This will avoid potential conflict issues during installation.</p>\n<p>Next, you can download and run the latest <a href=\"https://github.com/coreybutler/nvm-windows/releases\">nvm-setup.zip</a> installer.</p>\n<p>Also, since the utility runs in an Admin shell, you'll need to begin the Command Prompt or Powershell as an Administrator before using it.</p>\n<p>If you want to install and upgrade to a specific version, you can run the following:</p>\n<p>You can specify to update to the newest LTS version by running:</p>\n<p>For example, if you want to update Node.js to version 12.18.3, you can run:</p>\n<p>After the upgrade, you can switch to that version:</p>\n<p>You can also specify to update to the latest stable Node.js version:</p>\n<p>You can see the list of installed Node.js versions by running this command:</p>\n<p>Also, you can see the list of versions available for download by running this command:</p>\n<h2></h2>\n<h2>3. Updating using a Node installer on Linux</h2>\n<p>Using a Node installer is the least recommended way of upgrading Node.js on Linux. Nonetheless, if it's the only route you can use, then follow the following steps:</p>\n<ul>\n<li>Go to the official <a href=\"https://nodejs.org/en/download/\">Node.js downloads site</a>, which has different Linux binary packages, and select your preferred built-in installer or source code. You can choose either the LTS releases or the latest current releases.</li>\n<li>Download the binary package using your browser. Or, you can download it using the following Wget command on the terminal:</li>\n</ul>\n<p><img src=\"https://www.whitesourcesoftware.com/wp-content/media/2020/08/node-js-linux.png\" alt=\"image\"></p>\n<ul>\n<li>Download the binary package using your browser. Or, you can download it using the following Wget command on the terminal:</li>\n</ul>\n<p>Remember to change the version number on the Wget command depending on the one you want.</p>\n<ul>\n<li>Install the xz-utils utility using the following command:</li>\n</ul>\n<p>This utility will be used for unpacking the binary package.</p>\n<ul>\n<li>Finally, run the following command to unpack and install the binary package on usr/local:</li>\n</ul>\n<h2></h2>\n<h2>4. Updating using a Node installer on macOS and Windows</h2>\n<p>Another way of updating your Node.js on macOS and Windows is to go to the official <a href=\"https://nodejs.org/en/download/\">download site</a> and install the most recent version. This way, it'll overwrite your existing old version with the latest one.</p>\n<p>You can follow the following steps to update it using this method:</p>\n<ul>\n<li>On the Node.js download page, select either the LTS version or the latest current version.</li>\n</ul>\n<p><img src=\"https://www.whitesourcesoftware.com/wp-content/media/2020/08/node-js-mac-windows.png\" alt=\"node-js-mac-windows.png\"></p>\n<ul>\n<li>Depending on your system, click either the Windows Installer option or the macOS installer option.</li>\n<li>Run the installation wizard. It will magically complete the installation process and upgrade your Node.js version by replacing it with the new, updated one.</li>\n</ul>\n<h2>5. Updating using Homebrew on macOS</h2>\n<p><a href=\"https://brew.sh/\">Homebrew</a> is a popular package management utility for macOS.</p>\n<p>To use it for installing Node.js, run the following command on your macOS terminal:</p>\n<p>Later, if you'd like to update it, run the following commands:</p>\n<p>Furthermore, you can switch between installed Node.js versions:</p>"},{"url":"/docs/reference/how-to-kill-a-process/","relativePath":"docs/reference/how-to-kill-a-process.md","relativeDir":"docs/reference","base":"how-to-kill-a-process.md","name":"how-to-kill-a-process","frontmatter":{"title":"Kill a Process in Linux","weight":0,"excerpt":"Kill a Process in Linux","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>How to Kill a Process in Linux</h1>\n<p><strong><em>Learn how to kill errant processes in this tutorial.</em></strong></p>\n<p>Picture this: You've launched an application (be it from your favorite desktop menu or from the command line) and you start using that launched app, only to have it lock up on you, stop performing, or unexpectedly die. You try to run the app again, but it turns out the original never truly shut down completely.</p>\n<p>What do you do? You kill the process. But how? Believe it or not, your best bet most often lies within the command line. Thankfully, Linux has every tool necessary to empower you, the user, to kill an errant process. However, before you immediately launch that command to kill the process, you first have to know what the process is. How do you take care of this layered task? It's actually quite simple...once you know the tools at your disposal.</p>\n<p>Let me introduce you to said tools.</p>\n<p>The steps I'm going to outline will work on almost every Linux distribution, whether it is a desktop or a server. I will be dealing strictly with the command line, so open up your terminal and prepare to type.</p>\n<h3>Locating the process</h3>\n<p>The first step in killing the unresponsive process is locating it. There are two commands I use to locate a process: *top *and <em>ps</em>. Top is a tool every administrator should get to know. With <em>top</em>, you get a full listing of currently running process. From the command line, issue <em>top</em> to see a list of your running processes (Figure 1).</p>\n<p><img src=\"https://lcom.static.linuxfound.org/sites/lcom/files/killa.jpg\" alt=\"image\"></p>\n<p>Figure 1: The top command gives you plenty of information.</p>\n<p>From this list you will see some rather important information. Say, for example, Chrome has become unresponsive. According to our <em>top</em> display, we can discern there are four instances of chrome running with Process IDs (PID) 3827, 3919, 10764, and 11679. This information will be important to have with one particular method of killing the process.</p>\n<p>Although <em>top</em> is incredibly handy, it's not always the most efficient means of getting the information you need. Let's say you know the Chrome process is what you need to kill, and you don't want to have to glance through the real-time information offered by <em>top</em>. For that, you can make use of the *ps *command and filter the output through <em>grep</em>. The <em>ps</em> command reports a snapshot of a current process and *grep *prints lines matching a pattern. The reason why we filter <em>ps</em> through <em>grep</em> is simple: If you issue the <em>ps</em> command by itself, you will get a snapshot listing of all current processes. We only want the listing associated with Chrome. So this command would look like:</p>\n<p>ps aux | grep chrome</p>\n<p>The <em>aux</em> options are as follows:</p>\n<ul>\n<li>a = show processes for all users</li>\n<li>-</li>\n<li>u = display the process's user/owner</li>\n<li>x = also show processes not attached to a terminal</li>\n</ul>\n<p>The <em>x</em> option is important when you're hunting for information regarding a graphical application.</p>\n<p>When you issue the command above, you'll be given more information than you need (Figure 2) for the killing of a process, but it is sometimes more efficient than using top.</p>\n<p><img src=\"https://lcom.static.linuxfound.org/sites/lcom/files/killb.jpg\" alt=\"image\"></p>\n<p>Figure 2: Locating the necessary information with the ps command.</p>\n<h3>Killing the process</h3>\n<p>Now we come to the task of killing the process. We have two pieces of information that will help us kill the errant process:</p>\n<ul>\n<li>Process name</li>\n<li>-</li>\n<li>Process ID</li>\n</ul>\n<p>Which you use will determine the command used for termination. There are two commands used to kill a process:</p>\n<ul>\n<li>kill -- Kill a process by ID</li>\n<li>-</li>\n<li>killall -- Kill a process by name</li>\n</ul>\n<p>There are also different signals that can be sent to both kill commands. What signal you send will be determined by what results you want from the kill command. For instance, you can send the HUP (hang up) signal to the kill command, which will effectively restart the process. This is always a wise choice when you need the process to immediately restart (such as in the case of a daemon). You can get a list of all the signals that can be sent to the kill command by issuing kill -l. You'll find quite a large number of signals (Figure 3).</p>\n<p><img src=\"https://lcom.static.linuxfound.org/sites/lcom/files/killc.jpg\" alt=\"image\"></p>\n<p>Figure 3: The available kill signals.</p>\n<p>The most common kill signals are:</p>\n<p>|</p>\n<p>Signal Name</p>\n<p>|</p>\n<p>Single Value</p>\n<p>|</p>\n<p>Effect</p>\n<p>|\n|</p>\n<p>SIGHUP</p>\n<p>|</p>\n<p>1</p>\n<p>|</p>\n<p>Hangup</p>\n<p>|\n|</p>\n<p>SIGINT</p>\n<p>|</p>\n<p>2</p>\n<p>|</p>\n<p>Interrupt from keyboard</p>\n<p>|\n|</p>\n<p>SIGKILL</p>\n<p>|</p>\n<p>9</p>\n<p>|</p>\n<p>Kill signal</p>\n<p>|\n|</p>\n<p>SIGTERM</p>\n<p>|</p>\n<p>15</p>\n<p>|</p>\n<p>Termination signal</p>\n<p>|\n|</p>\n<p>SIGSTOP</p>\n<p>|</p>\n<p>17, 19, 23</p>\n<p>|</p>\n<p>Stop the process</p>\n<p>|</p>\n<p>What's nice about this is that you can use the Signal Value in place of the Signal Name. So you don't have to memorize all of the names of the various signals.<br>\nSo, let's now use the *kill *command to kill our instance of chrome. The structure for this command would be:</p>\n<p>kill SIGNAL PID</p>\n<p>Where SIGNAL is the signal to be sent and PID is the Process ID to be killed. We already know, from our <em>ps</em> command that the IDs we want to kill are 3827, 3919, 10764, and 11679. So to send the kill signal, we'd issue the commands:</p>\n<p>kill -9 3827</p>\n<p>kill -9 3919</p>\n<p>kill -9 10764</p>\n<p>kill -9 11679</p>\n<p>Once we've issued the above commands, all of the chrome processes will have been successfully killed.</p>\n<p>Let's take the easy route! If we already know the process we want to kill is named chrome, we can make use of the *killall *command and send the same signal the process like so:</p>\n<p><em>killall -9 chrome</em></p>\n<p>The only caveat to the above command is that it may not catch all of the running chrome processes. If, after running the above command, you issue the ps aux|grep chrome command and see remaining processes running, your best bet is to go back to the *kill *command and send signal 9 to terminate the process by PID.</p>\n<h3>Ending processes made easy</h3>\n<p>As you can see, killing errant processes isn't nearly as challenging as you might have thought. When I wind up with a stubborn process, I tend to start off with the *killall *command as it is the most efficient route to termination. However, when you wind up with a really feisty process, the *kill *command is the way to go.</p>"},{"url":"/docs/reference/github-resources/","relativePath":"docs/reference/github-resources.md","relativeDir":"docs/reference","base":"github-resources.md","name":"github-resources","frontmatter":{"title":"Github Resources","weight":0,"excerpt":"Github Resources","seo":{"title":"Github","description":"awesome github resources","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Github Resources:</h1>\n<ul>\n<li>\n<p><a href=\"#github-resources\">Github Resources:</a></p>\n<ul>\n<li>\n<p><a href=\"#github\">GitHub</a></p>\n<ul>\n<li><a href=\"#ignore-whitespace\">Ignore Whitespace</a></li>\n<li><a href=\"#adjust-tab-space\">Adjust Tab Space</a></li>\n<li><a href=\"#commit-history-by-author\">Commit History by Author</a></li>\n<li><a href=\"#cloning-a-repository\">Cloning a Repository</a></li>\n<li>\n<p><a href=\"#branch\">Branch</a></p>\n<ul>\n<li><a href=\"#compare-all-branches-to-another-branch\">Compare all Branches to Another Branch</a></li>\n<li><a href=\"#comparing-branches\">Comparing Branches</a></li>\n<li><a href=\"#compare-branches-across-forked-repositories\">Compare Branches across Forked Repositories</a></li>\n</ul>\n</li>\n<li><a href=\"#gists\">Gists</a></li>\n<li><a href=\"#gitio\">Git.io</a></li>\n<li><a href=\"#keyboard-shortcuts\">Keyboard Shortcuts</a></li>\n<li><a href=\"#line-highlighting-in-repositories\">Line Highlighting in Repositories</a></li>\n<li><a href=\"#closing-issues-via-commit-messages\">Closing Issues via Commit Messages</a></li>\n<li><a href=\"#cross-link-issues\">Cross-Link Issues</a></li>\n<li><a href=\"#locking-conversations\">Locking Conversations</a></li>\n<li><a href=\"#ci-status-on-pull-requests\">CI Status on Pull Requests</a></li>\n<li><a href=\"#filters\">Filters</a></li>\n<li><a href=\"#syntax-highlighting-in-markdown-files\">Syntax Highlighting in Markdown Files</a></li>\n<li><a href=\"#emojis\">Emojis</a></li>\n<li>\n<p><a href=\"#imagesgifs\">Images/GIFs</a></p>\n<ul>\n<li><a href=\"#embedding-images-in-github-wiki\">Embedding Images in GitHub Wiki</a></li>\n</ul>\n</li>\n<li><a href=\"#quick-quoting\">Quick Quoting</a></li>\n<li><a href=\"#pasting-clipboard-image-to-comments\">Pasting Clipboard Image to Comments</a></li>\n<li><a href=\"#quick-licensing\">Quick Licensing</a></li>\n<li>\n<p><a href=\"#task-lists\">Task Lists</a></p>\n<ul>\n<li><a href=\"#task-lists-in-markdown-documents\">Task Lists in Markdown Documents</a></li>\n</ul>\n</li>\n<li><a href=\"#relative-links\">Relative Links</a></li>\n<li><a href=\"#metadata-and-plugin-support-for-github-pages\">Metadata and Plugin Support for GitHub Pages</a></li>\n<li><a href=\"#viewing-yaml-metadata-in-your-documents\">Viewing YAML Metadata in your Documents</a></li>\n<li><a href=\"#rendering-tabular-data\">Rendering Tabular Data</a></li>\n<li><a href=\"#rendering-pdf\">Rendering PDF</a></li>\n<li><a href=\"#revert-a-pull-request\">Revert a Pull Request</a></li>\n<li>\n<p><a href=\"#diffs\">Diffs</a></p>\n<ul>\n<li><a href=\"#rendered-prose-diffs\">Rendered Prose Diffs</a></li>\n<li><a href=\"#diffable-maps\">Diffable Maps</a></li>\n<li><a href=\"#expanding-context-in-diffs\">Expanding Context in Diffs</a></li>\n<li><a href=\"#diff-or-patch-of-pull-request\">Diff or Patch of Pull Request</a></li>\n<li><a href=\"#rendering-and-diffing-images\">Rendering and diffing images</a></li>\n</ul>\n</li>\n<li><a href=\"#hub\">Hub</a></li>\n<li>\n<p><a href=\"#contribution-guidelines\">Contribution Guidelines</a></p>\n<ul>\n<li><a href=\"#contributing-file\">CONTRIBUTING File</a></li>\n<li><a href=\"#issue_template-file\">ISSUE_TEMPLATE file</a></li>\n<li><a href=\"#pull_request_template-file\">PULL<em>REQUEST</em>TEMPLATE file</a></li>\n</ul>\n</li>\n<li><a href=\"#octicons\">Octicons</a></li>\n<li><a href=\"#github-student-developer-pack\">GitHub Student Developer Pack</a></li>\n<li>\n<p><a href=\"#github-resources-1\">GitHub Resources</a></p>\n<ul>\n<li><a href=\"#github-talks\">GitHub Talks</a></li>\n</ul>\n</li>\n<li><a href=\"#ssh-keys\">SSH keys</a></li>\n<li><a href=\"#profile-image\">Profile Image</a></li>\n<li><a href=\"#repository-templates\">Repository Templates</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#git\">Git</a></p>\n<ul>\n<li><a href=\"#remove-all-deleted-files-from-the-working-tree\">Remove All Deleted Files from the Working Tree</a></li>\n<li><a href=\"#previous-branch\">Previous Branch</a></li>\n<li><a href=\"#stripspace\">Stripspace</a></li>\n<li><a href=\"#checking-out-pull-requests\">Checking out Pull Requests</a></li>\n<li><a href=\"#empty-commits\">Empty Commits</a></li>\n<li><a href=\"#styled-git-status\">Styled Git Status</a></li>\n<li><a href=\"#styled-git-log\">Styled Git Log</a></li>\n<li><a href=\"#git-query\">Git Query</a></li>\n<li><a href=\"#git-grep\">Git Grep</a></li>\n<li><a href=\"#merged-branches\">Merged Branches</a></li>\n<li><a href=\"#fixup-and-autosquash\">Fixup and Autosquash</a></li>\n<li><a href=\"#web-server-for-browsing-local-repositories\">Web Server for Browsing Local Repositories</a></li>\n<li>\n<p><a href=\"#git-configurations\">Git Configurations</a></p>\n<ul>\n<li><a href=\"#aliases\">Aliases</a></li>\n<li><a href=\"#auto-correct\">Auto-Correct</a></li>\n<li><a href=\"#color\">Color</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#git-resources\">Git Resources</a></p>\n<ul>\n<li><a href=\"#git-books\">Git Books</a></li>\n<li><a href=\"#git-videos\">Git Videos</a></li>\n<li><a href=\"#git-articles\">Git Articles</a></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<h2>GitHub</h2>\n<h3>Ignore Whitespace</h3>\n<p>Adding <code class=\"language-text\">?w=1</code> to any diff URL will remove any changes only in whitespace, enabling you to see only the code that has changed.</p>\n<p><img src=\"https://camo.githubusercontent.com/797184940defadec00393e6559b835358a863eeb/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f776869746573706163652e706e67\" alt=\"Diff without whitespace\"></p>\n<p><a href=\"https://github.com/blog/967-github-secrets\"><em>Read more about GitHub secrets.</em></a></p>\n<h3>Adjust Tab Space</h3>\n<p>Adding <code class=\"language-text\">?ts=4</code> to a diff or file URL will display tab characters as 4 spaces wide instead of the default 8. The number after <code class=\"language-text\">ts</code> can be adjusted to suit your preference. This does not work on Gists, or raw file views, but a <a href=\"https://chrome.google.com/webstore/detail/tab-size-on-github/ofjbgncegkdemndciafljngjbdpfmbkn\">Chrome extension</a> can automate this.</p>\n<p>Here is a Go source file before adding <code class=\"language-text\">?ts=4</code>:</p>\n<p><img src=\"https://i.imgur.com/GIT1Fr0.png\" alt=\"Before, tab space example\"></p>\n<p>...and this is after adding <code class=\"language-text\">?ts=4</code>:</p>\n<p><img src=\"https://i.imgur.com/70FL4H9.png\" alt=\"After, tab space example\"></p>\n<h3>Commit History by Author</h3>\n<p>To view all commits on a repo by author add <code class=\"language-text\">?author={user}</code> to the URL.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/rails/rails/commits/master?author=dhh</code></pre></div>\n<p><img src=\"https://i.imgur.com/S7AE29b.png\" alt=\"DHH commit history\"></p>\n<p><a href=\"https://help.github.com/articles/differences-between-commit-views/\"><em>Read more about the differences between commits views.</em></a></p>\n<h3>Cloning a Repository</h3>\n<p>When cloning a repository the <code class=\"language-text\">.git</code> can be left off the end.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> clone https://github.com/tiimgreen/github-cheat-sheet</code></pre></div>\n<p><a href=\"http://git-scm.com/docs/git-clone\"><em>Read more about the Git <code class=\"language-text\">clone</code> command.</em></a></p>\n<h3>Branch</h3>\n<h4>Compare all Branches to Another Branch</h4>\n<p>If you go to the repo's <a href=\"https://github.com/tiimgreen/github-cheat-sheet/branches\">Branches</a> page, next to the Commits button:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/{user}/{repo}/branches</code></pre></div>\n<p>... you would see a list of all branches which are not merged into the main branch.</p>\n<p>From here you can access the compare page or delete a branch with a click of a button.</p>\n<p><img src=\"https://i.imgur.com/0FEe30z.png\" alt=\"Compare branches not merged into master in rails/rails repo - https://github.com/rails/rails/branches\"></p>\n<h4>Comparing Branches</h4>\n<p>To use GitHub to compare branches, change the URL to look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/{user}/{repo}/compare/{range}</code></pre></div>\n<p>where <code class=\"language-text\">{range} = master...4-1-stable</code></p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/rails/rails/compare/master...4-1-stable</code></pre></div>\n<p><img src=\"https://i.imgur.com/tIRCOsK.png\" alt=\"Rails branch compare example\"></p>\n<p><code class=\"language-text\">{range}</code> can be changed to things like:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/rails/rails/compare/master@{1.day.ago}...master\nhttps://github.com/rails/rails/compare/master@{2014-10-04}...master</code></pre></div>\n<p><em>Here, dates are in the format <code class=\"language-text\">YYYY-MM-DD</code></em></p>\n<p><img src=\"https://i.imgur.com/5dtzESz.png\" alt=\"Another compare example\"></p>\n<p>Branches can also be compared in <code class=\"language-text\">diff</code> and <code class=\"language-text\">patch</code> views:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/rails/rails/compare/master...4-1-stable.diff\nhttps://github.com/rails/rails/compare/master...4-1-stable.patch</code></pre></div>\n<p><a href=\"https://help.github.com/articles/comparing-commits-across-time/\"><em>Read more about comparing commits across time.</em></a></p>\n<h4>Compare Branches across Forked Repositories</h4>\n<p>To use GitHub to compare branches across forked repositories, change the URL to look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/{user}/{repo}/compare/{foreign-user}:{branch}...{own-branch}</code></pre></div>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/rails/rails/compare/byroot:master...master</code></pre></div>\n<p><img src=\"https://i.imgur.com/Q1W6qcB.png\" alt=\"Forked branch compare\"></p>\n<h3>Gists</h3>\n<p><a href=\"https://gist.github.com/\">Gists</a> are an easy way to work with small bits of code without creating a fully fledged repository.</p>\n<p><img src=\"https://i.imgur.com/VkKI1LC.png?1\" alt=\"Gist\"></p>\n<p>Add <code class=\"language-text\">.pibb</code> to the end of any Gist URL (<a href=\"https://gist.github.com/tiimgreen/10545817.pibb\">like this</a>) in order to get the <em>HTML-only</em> version suitable for embedding in any other site.</p>\n<p>Gists can be treated as a repository so they can be cloned like any other:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> clone https://gist.github.com/tiimgreen/10545817</code></pre></div>\n<p><img src=\"https://i.imgur.com/BcFzabp.png\" alt=\"Gists\"></p>\n<p>This means you also can modify and push updates to Gists:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> commit\n$ <span class=\"token function\">git</span> push\nUsername <span class=\"token keyword\">for</span> <span class=\"token string\">'https://gist.github.com'</span><span class=\"token builtin class-name\">:</span>\nPassword <span class=\"token keyword\">for</span> <span class=\"token string\">'https://tiimgreen@gist.github.com'</span><span class=\"token builtin class-name\">:</span></code></pre></div>\n<p>However, Gists do not support directories. All files need to be added to the repository root.\n<a href=\"https://help.github.com/articles/creating-gists/\"><em>Read more about creating Gists.</em></a></p>\n<h3>Git.io</h3>\n<p><a href=\"http://git.io\">Git.io</a> is a simple URL shortener for GitHub.</p>\n<p><img src=\"https://i.imgur.com/6JUfbcG.png?1\" alt=\"Git.io\"></p>\n<p>You can also use it via pure HTTP using Curl:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">curl</span> <span class=\"token parameter variable\">-i</span> http://git.io <span class=\"token parameter variable\">-F</span> <span class=\"token string\">\"url=https://github.com/...\"</span>\nHTTP/1.1 <span class=\"token number\">201</span> Created\nLocation: http://git.io/abc123\n\n$ <span class=\"token function\">curl</span> <span class=\"token parameter variable\">-i</span> http://git.io/abc123\nHTTP/1.1 <span class=\"token number\">302</span> Found\nLocation: https://github.com/<span class=\"token punctuation\">..</span>.</code></pre></div>\n<p><a href=\"https://github.com/blog/985-git-io-github-url-shortener\"><em>Read more about Git.io.</em></a></p>\n<h3>Keyboard Shortcuts</h3>\n<p>When on a repository page, keyboard shortcuts allow you to navigate easily.</p>\n<ul>\n<li>Pressing <code class=\"language-text\">t</code> will bring up a file explorer.</li>\n<li>Pressing <code class=\"language-text\">w</code> will bring up the branch selector.</li>\n<li>Pressing <code class=\"language-text\">s</code> will focus the search field for the current repository. Pressing ↓ to select the \"All GitHub\" option changes the field to search all of GitHub.</li>\n<li>Pressing <code class=\"language-text\">l</code> will edit labels on existing Issues.</li>\n<li>Pressing <code class=\"language-text\">y</code> <strong>when looking at a file</strong> (e.g., <code class=\"language-text\">https://github.com/tiimgreen/github-cheat-sheet/blob/master/README.md</code>) will change your URL to one which, in effect, freezes the page you are looking at. If this code changes, you will still be able to see what you saw at that current time.</li>\n</ul>\n<p>To see all of the shortcuts for the current page press <code class=\"language-text\">?</code>:</p>\n<p><img src=\"https://i.imgur.com/y5ZfNEm.png\" alt=\"Keyboard shortcuts\"></p>\n<p><a href=\"https://help.github.com/articles/search-syntax/\">Read more about search syntax you can use.</a></p>\n<h3>Line Highlighting in Repositories</h3>\n<p>Either adding, e.g., <code class=\"language-text\">#L52</code> to the end of a code file URL or simply clicking the line number will highlight that line number.</p>\n<p>It also works with ranges, e.g., <code class=\"language-text\">#L53-L60</code>, to select ranges, hold <code class=\"language-text\">shift</code> and click two lines:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/rails/rails/blob/master/activemodel/lib/active_model.rb#L53-L60</code></pre></div>\n<p><img src=\"https://i.imgur.com/8AhjrCz.png\" alt=\"Line Highlighting\"></p>\n<h3>Closing Issues via Commit Messages</h3>\n<p>If a particular commit fixes an issue, any of the keywords <code class=\"language-text\">fix/fixes/fixed</code>, <code class=\"language-text\">close/closes/closed</code> or <code class=\"language-text\">resolve/resolves/resolved</code>, followed by the issue number, will close the issue once it is committed to the repository's default branch.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> commit <span class=\"token parameter variable\">-m</span> <span class=\"token string\">\"Fix screwup, fixes #12\"</span></code></pre></div>\n<p>This closes the issue and references the closing commit.</p>\n<p><img src=\"https://i.imgur.com/Uh1gZdx.png\" alt=\"Closing Repo\"></p>\n<p><a href=\"https://help.github.com/articles/closing-issues-via-commit-messages/\"><em>Read more about closing Issues via commit messages.</em></a></p>\n<h3>Cross-Link Issues</h3>\n<p>If you want to link to another issue in the same repository, simply type hash <code class=\"language-text\">#</code> then the issue number, and it will be auto-linked.</p>\n<p>To link to an issue in another repository, <code class=\"language-text\">{user}/{repo}#ISSUE_NUMBER</code>, e.g., <code class=\"language-text\">tiimgreen/toc#12</code>.</p>\n<p><img src=\"https://camo.githubusercontent.com/447e39ab8d96b553cadc8d31799100190df230a8/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f626c6f672f323031312f736563726574732f7265666572656e6365732e706e67\" alt=\"Cross-Link Issues\"></p>\n<h3>Locking Conversations</h3>\n<p>Pull Requests and Issues can now be locked by owners or collaborators of the repo.</p>\n<p><img src=\"https://cloud.githubusercontent.com/assets/2723/3221693/bf54dd44-f00d-11e3-8eb6-bb51e825bc2c.png\" alt=\"Lock conversation\"></p>\n<p>This means that users who are not collaborators on the project will no longer be able to comment.</p>\n<p><img src=\"https://cloud.githubusercontent.com/assets/2723/3221775/d6e513b0-f00e-11e3-9721-2131cb37c906.png\" alt=\"Comments locked\"></p>\n<p><a href=\"https://github.com/blog/1847-locking-conversations\"><em>Read more about locking conversations.</em></a></p>\n<h3>CI Status on Pull Requests</h3>\n<p>If set up correctly, every time you receive a Pull Request, <a href=\"https://travis-ci.org/\">Travis CI</a> will build that Pull Request just like it would every time you make a new commit. Read more about how to <a href=\"http://docs.travis-ci.com/user/getting-started/\">get started with Travis CI</a>.</p>\n<p><a href=\"https://github.com/octokit/octokit.rb/pull/452\"><img src=\"https://cloud.githubusercontent.com/assets/1687642/2700187/3a88838c-c410-11e3-9a46-e65e2a0458cd.png\" alt=\"Travis CI status\"></a></p>\n<p><a href=\"https://github.com/blog/1227-commit-status-api\"><em>Read more about the commit status API.</em></a></p>\n<h3>Filters</h3>\n<p>Both issues and pull requests allow filtering in the user interface.</p>\n<p>For the Rails repo: <a href=\"https://github.com/rails/rails/issues\">https://github.com/rails/rails/issues</a>, the following filter is built by selecting the label \"activerecord\":</p>\n<p><code class=\"language-text\">is:issue label:activerecord</code></p>\n<p>But, you can also find all issues that are NOT labeled activerecord:</p>\n<p><code class=\"language-text\">is:issue -label:activerecord</code></p>\n<p>Additionally, this also works for pull requests:</p>\n<p><code class=\"language-text\">is:pr -label:activerecord</code></p>\n<p>Github has tabs for displaying open or closed issues and pull requests but you\ncan also see merged pull requests. Just put the following in the filter:</p>\n<p><code class=\"language-text\">is:merged</code></p>\n<p><a href=\"https://help.github.com/articles/searching-issues/\"><em>Read more about searching issues.</em></a></p>\n<p>Finally, github now allows you to filter by the Status API's status.</p>\n<p>Pull requests with only successful statuses:</p>\n<p><code class=\"language-text\">status:success</code></p>\n<p><a href=\"https://github.com/blog/2014-filter-pull-requests-by-status\"><em>Read more about searching on the Status API.</em></a></p>\n<h3>Syntax Highlighting in Markdown Files</h3>\n<p>For example, to syntax highlight Ruby code in your Markdown files write:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">```ruby\nrequire 'tabbit'\ntable = Tabbit.new('Name', 'Email')\ntable.add_row('Tim Green', 'tiimgreen@gmail.com')\nputs table.to_s\n```</code></pre></div>\n<p>This will produce:</p>\n<div class=\"gatsby-highlight\" data-language=\"ruby\"><pre class=\"language-ruby\"><code class=\"language-ruby\"><span class=\"token keyword\">require</span> <span class=\"token string-literal\"><span class=\"token string\">'tabbit'</span></span>\ntable <span class=\"token operator\">=</span> <span class=\"token class-name\">Tabbit</span><span class=\"token punctuation\">.</span><span class=\"token keyword\">new</span><span class=\"token punctuation\">(</span><span class=\"token string-literal\"><span class=\"token string\">'Name'</span></span><span class=\"token punctuation\">,</span> <span class=\"token string-literal\"><span class=\"token string\">'Email'</span></span><span class=\"token punctuation\">)</span>\ntable<span class=\"token punctuation\">.</span>add_row<span class=\"token punctuation\">(</span><span class=\"token string-literal\"><span class=\"token string\">'Tim Green'</span></span><span class=\"token punctuation\">,</span> <span class=\"token string-literal\"><span class=\"token string\">'tiimgreen@gmail.com'</span></span><span class=\"token punctuation\">)</span>\nputs table<span class=\"token punctuation\">.</span>to_s</code></pre></div>\n<p>GitHub uses <a href=\"https://github.com/github/linguist\">Linguist</a> to perform language detection and syntax highlighting. You can find out which keywords are valid by perusing the <a href=\"https://github.com/github/linguist/blob/master/lib/linguist/languages.yml\">languages YAML file</a>.</p>\n<p><a href=\"https://help.github.com/articles/github-flavored-markdown/\"><em>Read more about GitHub Flavored Markdown.</em></a></p>\n<h3>Emojis</h3>\n<p>Emojis can be added to Pull Requests, Issues, commit messages, repository descriptions, etc. using <code class=\"language-text\">:name_of_emoji:</code>.</p>\n<p>The full list of supported Emojis on GitHub can be found at <a href=\"http://www.emoji-cheat-sheet.com/\">emoji-cheat-sheet.com</a> or <a href=\"https://github.com/scotch-io/All-Github-Emoji-Icons\">scotch-io/All-Github-Emoji-Icons</a>.\nA handy emoji search engine can be found at <a href=\"http://emoji.muan.co/\">emoji.muan.co</a>.</p>\n<p>The top 5 used Emojis on GitHub are:</p>\n<ol>\n<li><code class=\"language-text\">:shipit:</code></li>\n<li><code class=\"language-text\">:sparkles:</code></li>\n<li><code class=\"language-text\">:-1:</code></li>\n<li><code class=\"language-text\">:+1:</code></li>\n<li><code class=\"language-text\">:clap:</code></li>\n</ol>\n<h3>Images/GIFs</h3>\n<p>Images and GIFs can be added to comments, READMEs etc.:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">![Alt Text](http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif)</code></pre></div>\n<p>Raw images from the repo can be used by calling them directly.:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">![Alt Text](https://github.com/{user}/{repo}/raw/master/path/to/image.gif)</code></pre></div>\n<p><img src=\"http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif\" alt=\"Peter don&#x27;t care\"></p>\n<p>All images are cached on GitHub, so if your host goes down, the image will remain available.</p>\n<h4>Embedding Images in GitHub Wiki</h4>\n<p>There are multiple ways of embedding images in Wiki pages. There's the standard Markdown syntax (shown above). But there's also a syntax that allows things like specifying the height or width of the image:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">[[http://www.sheawong.com/wp-content/uploads/2013/08/keephatin.gif | height = 100px]]</code></pre></div>\n<p>Which produces:</p>\n<p><img src=\"https://i.imgur.com/J5bMf7S.png\" alt=\"Just a screenshot\"></p>\n<h3>Quick Quoting</h3>\n<p>When on a comment thread and you want to quote something someone previously said, highlight the text and press <code class=\"language-text\">r</code>, this will copy it into your text box in the block-quote format.</p>\n<p><img src=\"https://f.cloud.github.com/assets/296432/124483/b0fa6204-6ef0-11e2-83c3-256c37fa7abc.gif\" alt=\"Quick Quote\"></p>\n<p><a href=\"https://github.com/blog/1399-quick-quotes\"><em>Read more about quick quoting.</em></a></p>\n<h3>Pasting Clipboard Image to Comments</h3>\n<p><em>(Works on Chrome browsers only)</em></p>\n<p>After taking a screenshot and adding it to the clipboard (mac: <code class=\"language-text\">cmd-ctrl-shift-4</code>), you can simply paste (<code class=\"language-text\">cmd-v / ctrl-v</code>) the image into the comment section and it will be auto-uploaded to github.</p>\n<p><img src=\"https://cloud.githubusercontent.com/assets/39191/5794265/39c9b65a-9f1b-11e4-9bc7-04e41f59ea5f.png\" alt=\"Pasting Clipboard Image to Comments\"></p>\n<p><a href=\"https://help.github.com/articles/issue-attachments/\"><em>Read more about issue attachments.</em></a></p>\n<h3>Quick Licensing</h3>\n<p>When creating a repository, GitHub gives you the option of adding in a pre-made license:</p>\n<p><img src=\"https://i.imgur.com/Chqj4Fg.png\" alt=\"License\"></p>\n<p>You can also add them to existing repositories by creating a new file through the web interface. When the name <code class=\"language-text\">LICENSE</code> is typed in you will get an option to use a template:</p>\n<p><img src=\"https://i.imgur.com/fTjQict.png\" alt=\"License\"></p>\n<p>Also works for <code class=\"language-text\">.gitignore</code>.</p>\n<p><a href=\"https://help.github.com/articles/open-source-licensing/\"><em>Read more about open source licensing.</em></a></p>\n<h3>Task Lists</h3>\n<p>In Issues and Pull requests check boxes can be added with the following syntax (notice the space):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">- [ ] Be awesome\n- [ ] Prepare dinner\n  - [ ] Research recipe\n  - [ ] Buy ingredients\n  - [ ] Cook recipe\n- [ ] Sleep</code></pre></div>\n<p><img src=\"https://i.imgur.com/jJBXhsY.png\" alt=\"Task List\"></p>\n<p>When they are clicked, they will be updated in the pure Markdown:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">- [x] Be awesome\n- [ ] Prepare dinner\n  - [x] Research recipe\n  - [x] Buy ingredients\n  - [ ] Cook recipe\n- [ ] Sleep</code></pre></div>\n<p><a href=\"https://help.github.com/articles/writing-on-github/#task-lists\"><em>Read more about task lists.</em></a></p>\n<h4>Task Lists in Markdown Documents</h4>\n<p>In full Markdown documents <strong>read-only</strong> checklists can now be added using the following syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">- [ ] Mercury\n- [x] Venus\n- [x] Earth\n  - [x] Moon\n- [x] Mars\n  - [ ] Deimos\n  - [ ] Phobos</code></pre></div>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Mercury</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" checked disabled> Venus</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" checked disabled> Earth</li>\n<li>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" checked disabled> Moon</li>\n</ul>\n</li>\n<li class=\"task-list-item\">\n<p><input type=\"checkbox\" checked disabled> Mars</p>\n<ul>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Deimos</li>\n<li class=\"task-list-item\"><input type=\"checkbox\" disabled> Phobos</li>\n</ul>\n</li>\n</ul>\n<p><a href=\"https://github.com/blog/1825-task-lists-in-all-markdown-documents\"><em>Read more about task lists in markdown documents.</em></a></p>\n<h3>Relative Links</h3>\n<p>Relative links are recommended in your Markdown files when linking to internal content.</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\">[<span class=\"token content\">Link to a header</span>](<span class=\"token url\">#awesome-section</span>)</span>\n<span class=\"token url\">[<span class=\"token content\">Link to a file</span>](<span class=\"token url\">docs/readme</span>)</span></code></pre></div>\n<p>Absolute links have to be updated whenever the URL changes (e.g., repository renamed, username changed, project forked). Using relative links makes your documentation easily stand on its own.</p>\n<p><a href=\"https://help.github.com/articles/relative-links-in-readmes/\"><em>Read more about relative links.</em></a></p>\n<h3>Metadata and Plugin Support for GitHub Pages</h3>\n<p>Within Jekyll pages and posts, repository information is available within the <code class=\"language-text\">site.github</code> namespace, and can be displayed, for example, using <code class=\"language-text\">{{ site.github.project_title }}</code>.</p>\n<p>The Jemoji and jekyll-mentions plugins enable <a href=\"#emojis\">emoji</a> and <a href=\"https://github.com/blog/821\">@mentions</a> in your Jekyll posts and pages to work just like you'd expect when interacting with a repository on GitHub.com.</p>\n<p><a href=\"https://github.com/blog/1797-repository-metadata-and-plugin-support-for-github-pages\"><em>Read more about repository metadata and plugin support for GitHub Pages.</em></a></p>\n<h3>Viewing YAML Metadata in your Documents</h3>\n<p>Many blogging websites, like <a href=\"http://jekyllrb.com/\">Jekyll</a> with <a href=\"https://pages.github.com\">GitHub Pages</a>, depend on some YAML-formatted metadata at the beginning of your post. GitHub will render this metadata as a horizontal table, for easier reading</p>\n<p><img src=\"https://camo.githubusercontent.com/47245aa16728e242f74a9a324ce0d24c0b916075/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f36343035302f313232383236372f65303439643063362d323761302d313165332d396464382d6131636432323539393334342e706e67\" alt=\"YAML metadata\"></p>\n<p><a href=\"https://github.com/blog/1647-viewing-yaml-metadata-in-your-documents\"><em>Read more about viewing YAML metadata in your documents.</em></a></p>\n<h3>Rendering Tabular Data</h3>\n<p>GitHub supports rendering tabular data in the form of <code class=\"language-text\">.csv</code> (comma-separated) and <code class=\"language-text\">.tsv</code> (tab-separated) files.</p>\n<p><img src=\"https://camo.githubusercontent.com/1b6dd0157ffb45d9939abf14233a0cb13b3b4dfe/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3238323735392f3937363436322f33323038336463652d303638642d313165332d393262322d3566323863313061353035392e706e67\" alt=\"Tabular data\"></p>\n<p><a href=\"https://github.com/blog/1601-see-your-csvs\"><em>Read more about rendering tabular data.</em></a></p>\n<h3>Rendering PDF</h3>\n<p>GitHub supports rendering PDF:</p>\n<p><img src=\"https://cloud.githubusercontent.com/assets/1000669/7492902/f8493160-f42e-11e4-8cea-1cb4f02757e7.png\" alt=\"PDF\"></p>\n<p><a href=\"https://github.com/blog/1974-pdf-viewing\"><em>Read more about rendering PDF.</em></a></p>\n<h3>Revert a Pull Request</h3>\n<p>After a pull request is merged, you may find it does not help anything or it was a bad decision to merge the pull request.</p>\n<p>You can revert it by clicking the <strong>Revert</strong> button on the right side of a commit in the pull request page to create a pull request with reverted changes to this specific pull request.</p>\n<p><img src=\"https://camo.githubusercontent.com/0d3350caf2bb1cba53123ffeafc00ca702b1b164/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f68656c702f70756c6c5f72657175657374732f7265766572742d70756c6c2d726571756573742d6c696e6b2e706e67\" alt=\"Revert button\"></p>\n<p><a href=\"https://github.com/blog/1857-introducing-the-revert-button\"><em>Read more about reverting pull requests</em></a></p>\n<h3>Diffs</h3>\n<h4>Rendered Prose Diffs</h4>\n<p>Commits and pull requests, including rendered documents supported by GitHub (e.g., Markdown), feature <em>source</em> and <em>rendered</em> views.</p>\n<p><img src=\"https://github-images.s3.amazonaws.com/help/repository/rendered_prose_diff.png\" alt=\"Source / Rendered view\"></p>\n<p>Click the \"rendered\" button to see the changes as they'll appear in the rendered document. Rendered prose view is handy when you're adding, removing, and editing text:</p>\n<p><img src=\"https://f.cloud.github.com/assets/17715/2003056/3997edb4-862b-11e3-90be-5e9586edecd7.png\" alt=\"Rendered Prose Diffs\"></p>\n<p><a href=\"https://github.com/blog/1784-rendered-prose-diffs\"><em>Read more about rendered prose diffs.</em></a></p>\n<h4>Diffable Maps</h4>\n<p>Any time you view a commit or pull request on GitHub that includes geodata, GitHub will render a visual representation of what was changed.</p>\n<p><a href=\"https://github.com/benbalter/congressional-districts/commit/2233c76ca5bb059582d796f053775d8859198ec5\"><img src=\"https://f.cloud.github.com/assets/282759/2090660/63f2e45a-8e97-11e3-9d8b-d4c8078b004e.gif\" alt=\"Diffable Maps\"></a></p>\n<p><a href=\"https://github.com/blog/1772-diffable-more-customizable-maps\"><em>Read more about diffable maps.</em></a></p>\n<h4>Expanding Context in Diffs</h4>\n<p>Using the <em>unfold</em> button in the gutter of a diff, you can reveal additional lines of context with a click. You can keep clicking <em>unfold</em> until you've revealed the whole file, and the feature is available anywhere GitHub renders diffs.</p>\n<p><img src=\"https://f.cloud.github.com/assets/22635/1610539/863c1f64-5584-11e3-82bf-151b406a272f.gif\" alt=\"Expanding Context in Diffs\"></p>\n<p><a href=\"https://github.com/blog/1705-expanding-context-in-diffs\"><em>Read more about expanding context in diffs.</em></a></p>\n<h4>Diff or Patch of Pull Request</h4>\n<p>You can get the diff of a Pull Request by adding a <code class=\"language-text\">.diff</code> or <code class=\"language-text\">.patch</code>\nextension to the end of the URL. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/tiimgreen/github-cheat-sheet/pull/15\nhttps://github.com/tiimgreen/github-cheat-sheet/pull/15.diff\nhttps://github.com/tiimgreen/github-cheat-sheet/pull/15.patch</code></pre></div>\n<p>The <code class=\"language-text\">.diff</code> extension would give you this in plain text:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">diff --git a/README.md b/README.md\nindex 88fcf69..8614873 100644\n--- a/README.md\n+++ b/README.md\n@@ -28,6 +28,7 @@ All the hidden and not hidden features of Git and GitHub. This cheat sheet was i\n - [Merged Branches](#merged-branches)\n - [Quick Licensing](#quick-licensing)\n - [TODO Lists](#todo-lists)\n+- [Relative Links](#relative-links)\n - [.gitconfig Recommendations](#gitconfig-recommendations)\n     - [Aliases](#aliases)\n     - [Auto-correct](#auto-correct)\n@@ -381,6 +382,19 @@ When they are clicked, they will be updated in the pure Markdown:\n - [ ] Sleep\n\n(...)</code></pre></div>\n<h4>Rendering and diffing images</h4>\n<p>GitHub can display several common image formats, including PNG, JPG, GIF, and PSD. In addition, there are several ways to compare differences between versions of those image formats.</p>\n<p><a href=\"https://github.com/blog/1845-psd-viewing-diffing\"><img src=\"https://cloud.githubusercontent.com/assets/2546/3165594/55f2798a-eb56-11e3-92e7-b79ad791a697.gif\" alt=\"Diffable PSD\"></a></p>\n<p><a href=\"https://help.github.com/articles/rendering-and-diffing-images/\"><em>Read more about rendering and diffing images.</em></a></p>\n<h3>Hub</h3>\n<p><a href=\"https://github.com/github/hub\">Hub</a> is a command line Git wrapper that gives you extra features and commands that make working with GitHub easier.</p>\n<p>This allows you to do things like:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ hub clone tiimgreen/toc</code></pre></div>\n<p><a href=\"https://github.com/github/hub#commands\"><em>Check out some more cool commands Hub has to offer.</em></a></p>\n<h3>Contribution Guidelines</h3>\n<p>GitHub supports adding 3 different files which help users contribute to your project.\nThese files can either be placed in the root of your repository or a <code class=\"language-text\">.github</code> directory under the root.</p>\n<h4>CONTRIBUTING File</h4>\n<p>Adding a <code class=\"language-text\">CONTRIBUTING</code> or <code class=\"language-text\">CONTRIBUTING.md</code> file to either the root of your repository or a <code class=\"language-text\">.github</code> directory will add a link to your file when a contributor creates an Issue or opens a Pull Request.</p>\n<p><img src=\"https://camo.githubusercontent.com/71995d6b0e620a9ef1ded00a04498241c69dd1bf/68747470733a2f2f6769746875622d696d616765732e73332e616d617a6f6e6177732e636f6d2f736b697463682f6973737565732d32303132303931332d3136323533392e6a7067\" alt=\"Contributing Guidelines\"></p>\n<p><a href=\"https://github.com/blog/1184-contributing-guidelines\"><em>Read more about contributing guidelines.</em></a></p>\n<h4>ISSUE_TEMPLATE file</h4>\n<p>You can define a template for all new issues opened in your project. The content of this file will pre-populate the new issue box when users create new issues. Add an <code class=\"language-text\">ISSUE_TEMPLATE</code> or <code class=\"language-text\">ISSUE_TEMPLATE.md</code> file to either the root of your repository or a <code class=\"language-text\">.github</code> directory.</p>\n<p><a href=\"https://github.com/blog/2111-issue-and-pull-request-templates\"><em>Read more about issue templates.</em></a></p>\n<p><a href=\"https://www.talater.com/open-source-templates/\">Issue template file generator</a></p>\n<p><img src=\"https://cloud.githubusercontent.com/assets/25792/13120859/733479fe-d564-11e5-8a1f-a03f95072f7a.png\" alt=\"GitHub Issue template\"></p>\n<h4>PULL<em>REQUEST</em>TEMPLATE file</h4>\n<p>You can define a template for all new pull requests opened in your project. The content of this file will pre-populate the text area when users create pull requests. Add a <code class=\"language-text\">PULL_REQUEST_TEMPLATE</code> or <code class=\"language-text\">PULL_REQUEST_TEMPLATE.md</code> file to either the root of your repository or a <code class=\"language-text\">.github</code> directory.</p>\n<p><a href=\"https://github.com/blog/2111-issue-and-pull-request-templates\"><em>Read more about pull request templates.</em></a></p>\n<p><a href=\"https://www.talater.com/open-source-templates/\">Pull request template file generator</a></p>\n<h3>Octicons</h3>\n<p>GitHubs icons (Octicons) have now been open sourced.</p>\n<p><img src=\"https://og.github.com/octicons/octicons@1200x630.png\" alt=\"Octicons\"></p>\n<p><a href=\"https://octicons.github.com\"><em>Read more about GitHub's Octicons</em></a></p>\n<h3>GitHub Student Developer Pack</h3>\n<p>If you are a student you will be eligible for the GitHub Student Developer Pack. This gives you free credit, free trials and early access to software that will help you when developing.</p>\n<p><img src=\"https://i.imgur.com/9ru3K43.png\" alt=\"GitHub Student Developer Pack\"></p>\n<p><a href=\"https://education.github.com/pack\"><em>Read more about GitHub's Student Developer Pack</em></a></p>\n<h3>GitHub Resources</h3>\n<table>\n<thead>\n<tr>\n<th>Title</th>\n<th>Link</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>GitHub Explore</td>\n<td><a href=\"https://github.com/explore\">https://github.com/explore</a></td>\n</tr>\n<tr>\n<td>GitHub Blog</td>\n<td><a href=\"https://github.com/blog\">https://github.com/blog</a></td>\n</tr>\n<tr>\n<td>GitHub Help</td>\n<td><a href=\"https://help.github.com/\">https://help.github.com/</a></td>\n</tr>\n<tr>\n<td>GitHub Training</td>\n<td><a href=\"https://training.github.com/\">https://training.github.com/</a></td>\n</tr>\n<tr>\n<td>GitHub Developer</td>\n<td><a href=\"https://developer.github.com/\">https://developer.github.com/</a></td>\n</tr>\n<tr>\n<td>Github Education (Free Micro Account and other stuff for students)</td>\n<td><a href=\"https://education.github.com/\">https://education.github.com/</a></td>\n</tr>\n<tr>\n<td>GitHub Best Practices</td>\n<td><a href=\"https://www.datree.io/resources/github-best-practices\">Best Practices List</a></td>\n</tr>\n</tbody>\n</table>\n<h4>GitHub Talks</h4>\n<table>\n<thead>\n<tr>\n<th>Title</th>\n<th>Link</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>How GitHub Uses GitHub to Build GitHub</td>\n<td><a href=\"https://www.youtube.com/watch?v=qyz3jkOBbQY\">https://www.youtube.com/watch?v=qyz3jkOBbQY</a></td>\n</tr>\n<tr>\n<td>Introduction to Git with Scott Chacon of GitHub</td>\n<td><a href=\"https://www.youtube.com/watch?v=ZDR433b0HJY\">https://www.youtube.com/watch?v=ZDR433b0HJY</a></td>\n</tr>\n<tr>\n<td>How GitHub No Longer Works</td>\n<td><a href=\"https://www.youtube.com/watch?v=gXD1ITW7iZI\">https://www.youtube.com/watch?v=gXD1ITW7iZI</a></td>\n</tr>\n<tr>\n<td>Git and GitHub Secrets</td>\n<td><a href=\"https://www.youtube.com/watch?v=Foz9yvMkvlA\">https://www.youtube.com/watch?v=Foz9yvMkvlA</a></td>\n</tr>\n<tr>\n<td>More Git and GitHub Secrets</td>\n<td><a href=\"https://www.youtube.com/watch?v=p50xsL-iVgU\">https://www.youtube.com/watch?v=p50xsL-iVgU</a></td>\n</tr>\n</tbody>\n</table>\n<h3>SSH keys</h3>\n<p>You can get a list of public ssh keys in plain text format by visiting:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/{user}.keys</code></pre></div>\n<p>e.g. <a href=\"https://github.com/tiimgreen.keys\">https://github.com/tiimgreen.keys</a></p>\n<p><a href=\"https://changelog.com/github-exposes-public-ssh-keys-for-its-users/\"><em>Read more about accessing public ssh keys.</em></a></p>\n<h3>Profile Image</h3>\n<p>You can get a user's profile image by visiting:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://github.com/{user}.png</code></pre></div>\n<p>e.g. <a href=\"https://github.com/tiimgreen.png\">https://github.com/tiimgreen.png</a></p>\n<h3>Repository Templates</h3>\n<p>You can enable templating on your repository which allows anyone to copy the directory structure and files, allowing them to instantly use the files (e.g. for a tutorial or if writing boilerplate code). This can be enabled in the settings of your repository.</p>\n<p><img src=\"https://i.postimg.cc/hGCrVm9F/Template.gif\" alt=\"Convert\"></p>\n<p>Changing to a template repository will give a new URL endpoint which can be shared and instantly allows users to use your repository as a template. Alternatively, they can go to your repository and click the 'Use as template' button.</p>\n<p><img src=\"https://i.postimg.cc/L8PKCHx0/New-Template.gif\" alt=\"Template\"></p>\n<p><a href=\"https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/\"><em>Read more about using repositories as templates</em></a></p>\n<h2>Git</h2>\n<h3>Remove All Deleted Files from the Working Tree</h3>\n<p>When you delete a lot of files using <code class=\"language-text\">/bin/rm</code> you can use the following command to remove them from the working tree and from the index, eliminating the need to remove each one individually:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> <span class=\"token function\">rm</span> <span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token function\">git</span> ls-files <span class=\"token parameter variable\">-d</span><span class=\"token variable\">)</span></span></code></pre></div>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> status\nOn branch master\nChanges not staged <span class=\"token keyword\">for</span> commit:\n\tdeleted:    a\n\tdeleted:    c\n\n$ <span class=\"token function\">git</span> <span class=\"token function\">rm</span> <span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token function\">git</span> ls-files <span class=\"token parameter variable\">-d</span><span class=\"token variable\">)</span></span>\n<span class=\"token function\">rm</span> <span class=\"token string\">'a'</span>\n<span class=\"token function\">rm</span> <span class=\"token string\">'c'</span>\n\n$ <span class=\"token function\">git</span> status\nOn branch master\nChanges to be committed:\n\tdeleted:    a\n\tdeleted:    c</code></pre></div>\n<h3>Previous Branch</h3>\n<p>To move to the previous branch in Git:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> checkout -\n<span class=\"token comment\"># Switched to branch 'master'</span>\n\n$ <span class=\"token function\">git</span> checkout -\n<span class=\"token comment\"># Switched to branch 'next'</span>\n\n$ <span class=\"token function\">git</span> checkout -\n<span class=\"token comment\"># Switched to branch 'master'</span></code></pre></div>\n<p><a href=\"http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging\"><em>Read more about Git branching.</em></a></p>\n<h3>Stripspace</h3>\n<p>Git Stripspace:</p>\n<ul>\n<li>Strips trailing whitespace</li>\n<li>Collapses newlines</li>\n<li>Adds newline to end of file</li>\n</ul>\n<p>A file must be passed when calling the command, e.g.:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> stripspace <span class=\"token operator\">&lt;</span> README.md</code></pre></div>\n<p><a href=\"http://git-scm.com/docs/git-stripspace\"><em>Read more about the Git <code class=\"language-text\">stripspace</code> command.</em></a></p>\n<h3>Checking out Pull Requests</h3>\n<p>Pull Requests are special branches on the GitHub repository which can be retrieved locally in several ways:</p>\n<p>Retrieve a specific Pull Request and store it temporarily in <code class=\"language-text\">FETCH_HEAD</code> for quickly <code class=\"language-text\">diff</code>-ing or <code class=\"language-text\">merge</code>-ing:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> fetch origin refs/pull/<span class=\"token punctuation\">[</span>PR-Number<span class=\"token punctuation\">]</span>/head</code></pre></div>\n<p>Acquire all Pull Request branches as local remote branches by refspec:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> fetch origin <span class=\"token string\">'+refs/pull/*/head:refs/remotes/origin/pr/*'</span></code></pre></div>\n<p>Or setup the remote to fetch Pull Requests automatically by adding these corresponding lines in your repository's <code class=\"language-text\">.git/config</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[remote \"origin\"]\n    fetch = +refs/heads/*:refs/remotes/origin/*\n    url = git@github.com:tiimgreen/github-cheat-sheet.git</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[remote \"origin\"]\n    fetch = +refs/heads/*:refs/remotes/origin/*\n    url = git@github.com:tiimgreen/github-cheat-sheet.git\n    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*</code></pre></div>\n<p>For Fork-based Pull Request contributions, it's useful to <code class=\"language-text\">checkout</code> a remote branch representing the Pull Request and create a local branch from it:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> checkout pr/42 pr-42</code></pre></div>\n<p>Or should you work on more repositories, you can globally configure fetching pull requests in the global git config instead.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> <span class=\"token parameter variable\">--add</span> remote.origin.fetch <span class=\"token string\">\"+refs/pull/*/head:refs/remotes/origin/pr/*\"</span></code></pre></div>\n<p>This way, you can use the following short commands in all your repositories:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> fetch origin</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> checkout pr/42</code></pre></div>\n<p><a href=\"https://help.github.com/articles/checking-out-pull-requests-locally/\"><em>Read more about checking out pull requests locally.</em></a></p>\n<h3>Empty Commits</h3>\n<p>Commits can be pushed with no code changes by adding <code class=\"language-text\">--allow-empty</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> commit <span class=\"token parameter variable\">-m</span> <span class=\"token string\">\"Big-ass commit\"</span> --allow-empty</code></pre></div>\n<p>Some use-cases for this (that make sense), include:</p>\n<ul>\n<li>Annotating the start of a new bulk of work or a new feature.</li>\n<li>Documenting when you make changes to the project that aren't code related.</li>\n<li>Communicating with people using your repository.</li>\n<li>The first commit of a repository: <code class=\"language-text\">git commit -m \"Initial commit\" --allow-empty</code>.</li>\n</ul>\n<h3>Styled Git Status</h3>\n<p>Running:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> status</code></pre></div>\n<p>produces:</p>\n<p><img src=\"https://i.imgur.com/qjPyvXb.png\" alt=\"git status\"></p>\n<p>By adding <code class=\"language-text\">-sb</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> status <span class=\"token parameter variable\">-sb</span></code></pre></div>\n<p>this is produced:</p>\n<p><img src=\"https://i.imgur.com/K0OY3nm.png\" alt=\"git status -sb\"></p>\n<p><a href=\"http://git-scm.com/docs/git-status\"><em>Read more about the Git <code class=\"language-text\">status</code> command.</em></a></p>\n<h3>Styled Git Log</h3>\n<p>Running:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> log <span class=\"token parameter variable\">--all</span> <span class=\"token parameter variable\">--graph</span> <span class=\"token parameter variable\">--pretty</span><span class=\"token operator\">=</span>format:<span class=\"token string\">'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an>%Creset'</span> --abbrev-commit <span class=\"token parameter variable\">--date</span><span class=\"token operator\">=</span>relative</code></pre></div>\n<p>produces:</p>\n<p><img src=\"https://i.imgur.com/58eOtkW.png\" alt=\"git log --all --graph --pretty=format:&#x27;%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset&#x27; --abbrev-commit --date=relative\"></p>\n<p>Credit to <a href=\"http://stackoverflow.com/users/88355/palesz\">Palesz</a></p>\n<p><em>This can be aliased using the instructions found <a href=\"https://github.com/tiimgreen/github-cheat-sheet#aliases\">here</a>.</em></p>\n<p><a href=\"http://git-scm.com/docs/git-log\"><em>Read more about the Git <code class=\"language-text\">log</code> command.</em></a></p>\n<h3>Git Query</h3>\n<p>A Git query allows you to search all your previous commit messages and find the most recent one matching the query.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> show :/query</code></pre></div>\n<p>where <code class=\"language-text\">query</code> (case-sensitive) is the term you want to search, this then finds the last one and gives details on the lines that were changed.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> show :/typo</code></pre></div>\n<p><img src=\"https://i.imgur.com/icaGiNt.png\" alt=\"git show :/query\"></p>\n<p><em>Press <code class=\"language-text\">q</code> to quit.</em></p>\n<h3>Git Grep</h3>\n<p>Git Grep will return a list of lines matching a pattern.</p>\n<p>Running:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> <span class=\"token function\">grep</span> aliases</code></pre></div>\n<p>will show all the files containing the string <em>aliases</em>.</p>\n<p><img src=\"https://i.imgur.com/DL2zpQ9.png\" alt=\"git grep aliases\"></p>\n<p><em>Press <code class=\"language-text\">q</code> to quit.</em></p>\n<p>You can also use multiple flags for more advanced search. For example:</p>\n<ul>\n<li><code class=\"language-text\">-e</code> The next parameter is the pattern (e.g., regex)</li>\n<li><code class=\"language-text\">--and</code>, <code class=\"language-text\">--or</code> and <code class=\"language-text\">--not</code> Combine multiple patterns.</li>\n</ul>\n<p>Use it like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"> $ <span class=\"token function\">git</span> <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-e</span> pattern <span class=\"token parameter variable\">--and</span> <span class=\"token parameter variable\">-e</span> anotherpattern</code></pre></div>\n<p><a href=\"http://git-scm.com/docs/git-grep\"><em>Read more about the Git <code class=\"language-text\">grep</code> command.</em></a></p>\n<h3>Merged Branches</h3>\n<p>Running:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> branch <span class=\"token parameter variable\">--merged</span></code></pre></div>\n<p>will give you a list of all branches that have been merged into your current branch.</p>\n<p>Conversely:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> branch --no-merged</code></pre></div>\n<p>will give you a list of branches that have not been merged into your current branch.</p>\n<p><a href=\"http://git-scm.com/docs/git-branch\"><em>Read more about the Git <code class=\"language-text\">branch</code> command.</em></a></p>\n<h3>Fixup and Autosquash</h3>\n<p>If there is something wrong with a previous commit (can be one or more from HEAD), for example <code class=\"language-text\">abcde</code>, run the following command after you've amended the problem:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> commit <span class=\"token parameter variable\">--fixup</span><span class=\"token operator\">=</span>abcde\n$ <span class=\"token function\">git</span> rebase abcde^ <span class=\"token parameter variable\">--autosquash</span> <span class=\"token parameter variable\">-i</span></code></pre></div>\n<p><a href=\"http://git-scm.com/docs/git-commit\"><em>Read more about the Git <code class=\"language-text\">commit</code> command.</em></a>\n<a href=\"http://git-scm.com/docs/git-rebase\"><em>Read more about the Git <code class=\"language-text\">rebase</code> command.</em></a></p>\n<h3>Web Server for Browsing Local Repositories</h3>\n<p>Use the Git <code class=\"language-text\">instaweb</code> command to instantly browse your working repository in <code class=\"language-text\">gitweb</code>. This command is a simple script to set up <code class=\"language-text\">gitweb</code> and a web server for browsing the local repository.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> instaweb</code></pre></div>\n<p>opens:</p>\n<p><img src=\"https://i.imgur.com/Dxekmqc.png\" alt=\"Git instaweb\"></p>\n<p><a href=\"http://git-scm.com/docs/git-instaweb\"><em>Read more about the Git <code class=\"language-text\">instaweb</code> command.</em></a></p>\n<h3>Git Configurations</h3>\n<p>Your <code class=\"language-text\">.gitconfig</code> file contains all your Git configurations.</p>\n<h4>Aliases</h4>\n<p>Aliases are helpers that let you define your own git calls. For example you could set <code class=\"language-text\">git a</code> to run <code class=\"language-text\">git add --all</code>.</p>\n<p>To add an alias, either navigate to <code class=\"language-text\">~/.gitconfig</code> and fill it out in the following format:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[alias]\n  co = checkout\n  cm = commit\n  p = push\n  # Show verbose output about tags, branches or remotes\n  tags = tag -l\n  branches = branch -a\n  remotes = remote -v</code></pre></div>\n<p>...or type in the command-line:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> alias.new_alias git_function</code></pre></div>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> alias.cm commit</code></pre></div>\n<p>For an alias with multiple functions use quotes:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> alias.ac <span class=\"token string\">'add -A . &amp;&amp; commit'</span></code></pre></div>\n<p>Some useful aliases include:</p>\n<table>\n<thead>\n<tr>\n<th>Alias</th>\n<th>Command</th>\n<th>What to Type</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">git cm</code></td>\n<td><code class=\"language-text\">git commit</code></td>\n<td><code class=\"language-text\">git config --global alias.cm commit</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">git co</code></td>\n<td><code class=\"language-text\">git checkout</code></td>\n<td><code class=\"language-text\">git config --global alias.co checkout</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">git ac</code></td>\n<td><code class=\"language-text\">git add . -A</code> <code class=\"language-text\">git commit</code></td>\n<td><code class=\"language-text\">git config --global alias.ac '!git add -A &amp;&amp; git commit'</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">git st</code></td>\n<td><code class=\"language-text\">git status -sb</code></td>\n<td><code class=\"language-text\">git config --global alias.st 'status -sb'</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">git tags</code></td>\n<td><code class=\"language-text\">git tag -l</code></td>\n<td><code class=\"language-text\">git config --global alias.tags 'tag -l'</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">git branches</code></td>\n<td><code class=\"language-text\">git branch -a</code></td>\n<td><code class=\"language-text\">git config --global alias.branches 'branch -a'</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">git cleanup</code></td>\n<td><code class=\"language-text\">git branch --merged \\| grep -v '*' \\| xargs git branch -d</code></td>\n<td><code class=\"language-text\">git config --global alias.cleanup \"!git branch --merged \\| grep -v '*' \\| xargs git branch -d\"</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">git remotes</code></td>\n<td><code class=\"language-text\">git remote -v</code></td>\n<td><code class=\"language-text\">git config --global alias.remotes 'remote -v'</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">git lg</code></td>\n<td><code class=\"language-text\">git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an>%Creset' --abbrev-commit --</code></td>\n<td><code class=\"language-text\">git config --global alias.lg \"log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an>%Creset' --abbrev-commit --\"</code></td>\n</tr>\n</tbody>\n</table>\n<p><em>Some Aliases are taken from <a href=\"https://github.com/mathiasbynens\">@mathiasbynens</a> dotfiles: <a href=\"https://github.com/mathiasbynens/dotfiles/blob/master/.gitconfig\">https://github.com/mathiasbynens/dotfiles/blob/master/.gitconfig</a></em></p>\n<h4>Auto-Correct</h4>\n<p>Git gives suggestions for misspelled commands and if auto-correct is enabled the command can be fixed and executed automatically. Auto-correct is enabled by specifying an integer which is the delay in tenths of a second before git will run the corrected command. Zero is the default value where no correcting will take place, and a negative value will run the corrected command with no delay.</p>\n<p>For example, if you type <code class=\"language-text\">git comit</code> you will get this:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> comit <span class=\"token parameter variable\">-m</span> <span class=\"token string\">\"Message\"</span>\n<span class=\"token comment\"># git: 'comit' is not a git command. See 'git --help'.</span>\n\n<span class=\"token comment\"># Did you mean this?</span>\n<span class=\"token comment\">#   commit</span></code></pre></div>\n<p>Auto-correct can be enabled like this (with a 1.5 second delay):</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> help.autocorrect <span class=\"token number\">15</span></code></pre></div>\n<p>So now the command <code class=\"language-text\">git comit</code> will be auto-corrected to <code class=\"language-text\">git commit</code> like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> comit <span class=\"token parameter variable\">-m</span> <span class=\"token string\">\"Message\"</span>\n<span class=\"token comment\"># WARNING: You called a Git command named 'comit', which does not exist.</span>\n<span class=\"token comment\"># Continuing under the assumption that you meant 'commit'</span>\n<span class=\"token comment\"># in 1.5 seconds automatically...</span></code></pre></div>\n<p>The delay before git will rerun the command is so the user has time to abort.</p>\n<h4>Color</h4>\n<p>To add more color to your Git output:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">$ <span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> color.ui <span class=\"token number\">1</span></code></pre></div>\n<p><a href=\"http://git-scm.com/docs/git-config\"><em>Read more about the Git <code class=\"language-text\">config</code> command.</em></a></p>\n<h3>Git Resources</h3>\n<table>\n<thead>\n<tr>\n<th>Title</th>\n<th>Link</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Official Git Site</td>\n<td><a href=\"http://git-scm.com/\">http://git-scm.com/</a></td>\n</tr>\n<tr>\n<td>Official Git Video Tutorials</td>\n<td><a href=\"http://git-scm.com/videos\">http://git-scm.com/videos</a></td>\n</tr>\n<tr>\n<td>Code School Try Git</td>\n<td><a href=\"http://try.github.com/\">http://try.github.com/</a></td>\n</tr>\n<tr>\n<td>Introductory Reference &#x26; Tutorial for Git</td>\n<td><a href=\"http://gitref.org/\">http://gitref.org/</a></td>\n</tr>\n<tr>\n<td>Official Git Tutorial</td>\n<td><a href=\"http://git-scm.com/docs/gittutorial\">http://git-scm.com/docs/gittutorial</a></td>\n</tr>\n<tr>\n<td>Everyday Git</td>\n<td><a href=\"http://git-scm.com/docs/everyday\">http://git-scm.com/docs/everyday</a></td>\n</tr>\n<tr>\n<td>Git Immersion</td>\n<td><a href=\"http://gitimmersion.com/\">http://gitimmersion.com/</a></td>\n</tr>\n<tr>\n<td>Git God</td>\n<td><a href=\"https://github.com/gorosgobe/git-god\">https://github.com/gorosgobe/git-god</a></td>\n</tr>\n<tr>\n<td>Git for Computer Scientists</td>\n<td><a href=\"http://eagain.net/articles/git-for-computer-scientists/\">http://eagain.net/articles/git-for-computer-scientists/</a></td>\n</tr>\n<tr>\n<td>Git Magic</td>\n<td><a href=\"http://www-cs-students.stanford.edu/~blynn/gitmagic/\">http://www-cs-students.stanford.edu/~blynn/gitmagic/</a></td>\n</tr>\n<tr>\n<td>Git Visualization Playground</td>\n<td><a href=\"http://onlywei.github.io/explain-git-with-d3/#freeplay\">http://onlywei.github.io/explain-git-with-d3/#freeplay</a></td>\n</tr>\n<tr>\n<td>Learn Git Branching</td>\n<td><a href=\"http://pcottle.github.io/learnGitBranching/\">http://pcottle.github.io/learnGitBranching/</a></td>\n</tr>\n<tr>\n<td>A collection of useful .gitignore templates</td>\n<td><a href=\"https://github.com/github/gitignore\">https://github.com/github/gitignore</a></td>\n</tr>\n<tr>\n<td>Unixorn's git-extra-commands collection of git scripts</td>\n<td><a href=\"https://github.com/unixorn/git-extra-commands\">https://github.com/unixorn/git-extra-commands</a></td>\n</tr>\n</tbody>\n</table>\n<h4>Git Books</h4>\n<table>\n<thead>\n<tr>\n<th>Title</th>\n<th>Link</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Pragmatic Version Control Using Git</td>\n<td><a href=\"https://pragprog.com/titles/tsgit/pragmatic-version-control-using-git\">https://pragprog.com/titles/tsgit/pragmatic-version-control-using-git</a></td>\n</tr>\n<tr>\n<td>Pro Git</td>\n<td><a href=\"http://git-scm.com/book\">http://git-scm.com/book</a></td>\n</tr>\n<tr>\n<td>Git Internals PluralSight</td>\n<td><a href=\"https://github.com/pluralsight/git-internals-pdf\">https://github.com/pluralsight/git-internals-pdf</a></td>\n</tr>\n<tr>\n<td>Git in the Trenches</td>\n<td><a href=\"http://cbx33.github.io/gitt/\">http://cbx33.github.io/gitt/</a></td>\n</tr>\n<tr>\n<td>Version Control with Git</td>\n<td><a href=\"http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387\">http://www.amazon.com/Version-Control-Git-collaborative-development/dp/1449316387</a></td>\n</tr>\n<tr>\n<td>Pragmatic Guide to Git</td>\n<td><a href=\"https://pragprog.com/titles/pg_git/pragmatic-guide-to-git\">https://pragprog.com/titles/pg_git/pragmatic-guide-to-git</a></td>\n</tr>\n<tr>\n<td>Git: Version Control for Everyone</td>\n<td><a href=\"https://www.packtpub.com/application-development/git-version-control-everyone\">https://www.packtpub.com/application-development/git-version-control-everyone</a></td>\n</tr>\n</tbody>\n</table>\n<h4>Git Videos</h4>\n<table>\n<thead>\n<tr>\n<th>Title</th>\n<th>Link</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Linus Torvalds on Git</td>\n<td><a href=\"https://www.youtube.com/watch?v=4XpnKHJAok8\">https://www.youtube.com/watch?v=4XpnKHJAok8</a></td>\n</tr>\n<tr>\n<td>Introduction to Git with Scott Chacon</td>\n<td><a href=\"https://www.youtube.com/watch?v=ZDR433b0HJY\">https://www.youtube.com/watch?v=ZDR433b0HJY</a></td>\n</tr>\n<tr>\n<td>Git From the Bits Up</td>\n<td><a href=\"https://www.youtube.com/watch?v=MYP56QJpDr4\">https://www.youtube.com/watch?v=MYP56QJpDr4</a></td>\n</tr>\n<tr>\n<td>Graphs, Hashes, and Compression, Oh My!</td>\n<td><a href=\"https://www.youtube.com/watch?v=ig5E8CcdM9g\">https://www.youtube.com/watch?v=ig5E8CcdM9g</a></td>\n</tr>\n<tr>\n<td>GitHub Training &#x26; Guides</td>\n<td><a href=\"https://www.youtube.com/watch?list=PLg7s6cbtAD15G8lNyoaYDuKZSKyJrgwB-&#x26;v=FyfwLX4HAxM\">https://www.youtube.com/watch?list=PLg7s6cbtAD15G8lNyoaYDuKZSKyJrgwB-&#x26;v=FyfwLX4HAxM</a></td>\n</tr>\n</tbody>\n</table>\n<h4>Git Articles</h4>\n<table>\n<thead>\n<tr>\n<th>Title</th>\n<th>Link</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>GitHub Flow</td>\n<td><a href=\"http://scottchacon.com/2011/08/31/github-flow.html\">http://scottchacon.com/2011/08/31/github-flow.html</a></td>\n</tr>\n<tr>\n<td>Migrating to Git Large File Storate (Git LFS)</td>\n<td><a href=\"http://vooban.com/en/tips-articles-geek-stuff/migrating-to-git-lfs-for-developing-deep-learning-applications-with-large-files/\">http://vooban.com/en/tips-articles-geek-stuff/migrating-to-git-lfs-for-developing-deep-learning-applications-with-large-files/</a></td>\n</tr>\n</tbody>\n</table>"},{"url":"/docs/reference/google-cloud/","relativePath":"docs/reference/google-cloud.md","relativeDir":"docs/reference","base":"google-cloud.md","name":"google-cloud","frontmatter":{"title":"Google Cloud","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<p>The gcloud command-line tool cheat sheet</p>\n<h2>The gcloud cheat sheet</h2>\n<p>A roster of go-to gcloud commands for the gcloud tool, Google Cloud's primary command-line tool.</p>\n<p>(Also included: <a href=\"https://cloud.google.com/sdk/docs/cheatsheet#introductory_primer\">introductory primer</a>, <a href=\"https://cloud.google.com/sdk/docs/cheatsheet#understanding_commands\">understanding commands</a>, and a <a href=\"https://cloud.google.com/sdk/docs/images/gcloud-cheat-sheet.pdf\">printable PDF</a>.)</p>\n<h2>Cheat sheet</h2>\n<h3>Getting started</h3>\n<p>Get going with the gcloud command-line tool.</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/init\">gcloud init</a>: Initialize, authorize, and configure the gcloud tool.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/version\">gcloud version</a>: Display version and installed components.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/components/install\">gcloud components install</a>: Install specific components.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/components/update\">gcloud components update</a>: Update your Cloud SDK to the latest version.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/config/set\">gcloud config set project</a>: Set a default Google Cloud project to work on.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/info\">gcloud info</a>: Display current gcloud tool environment details.</li>\n</ul>\n<h3>Help</h3>\n<p>Cloud SDK is happy to help.</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/help\">gcloud help</a>: Search the gcloud tool reference documents for specific terms.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/feedback\">gcloud feedback</a>: Provide feedback for the Cloud SDK team.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/topic\">gcloud topic</a>: Supplementary help material for non-command topics like accessibility, filtering, and formatting.</li>\n</ul>\n<h3>Personalization</h3>\n<p>Make the Cloud SDK your own; personalize your configuration with properties.</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/config/set\">gcloud config set</a>: Define a property (like compute/zone) for the current configuration.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/config/get-value\">gcloud config get-value</a>: Fetch value of a Cloud SDK property.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/config/list\">gcloud config list</a>: Display all the properties for the current configuration.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/config/configurations/create\">gcloud config configurations create</a>: Create a new named configuration.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/config/configurations/list\">gcloud config configurations list</a>: Display a list of all available configurations.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/config/configurations/activate\">gcloud config configurations activate</a>: Switch to an existing named configuration.</li>\n</ul>\n<h3>Credentials</h3>\n<p>Grant and revoke authorization to Cloud SDK</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/auth/login\">gcloud auth login</a>: Authorize Google Cloud access for the gcloud tool with Google user credentials and set current account as active.</li>\n<li></li>\n<li>[gcloud auth activate-service-account](<a href=\"https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-acc\">https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-acc</a></li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/auth/list\">gcloud auth list</a>: List all credentialed accounts.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/auth/print-access-token\">gcloud auth print-access-token</a>: Display the current account's access token.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/auth/revoke\">gcloud auth revoke</a>: Remove access credentials for an account.</li>\n</ul>\n<h3>Projects</h3>\n<p>Manage project access policies</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/projects/describe\">gcloud projects describe</a>: Display metadata for a project (including its ID).</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/projects/add-iam-policy-binding\">gcloud projects add-iam-policy-binding</a>: Add an IAM policy binding to a specified project.</li>\n</ul>\n<h3>Identity &#x26; Access Management</h3>\n<p>Configuring Cloud Identity &#x26; Access Management (IAM) preferences and service accounts</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/iam/list-grantable-roles\">gcloud iam list-grantable-roles</a>: List IAM grantable roles for a resource.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/iam/roles/create\">gcloud iam roles create</a>: Create a custom role for a project or org.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/iam/service-accounts/create\">gcloud iam service-accounts create</a>: Create a service account for a project.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/iam/service-accounts/add-iam-policy-binding\">gcloud iam service-accounts add-iam-policy-binding</a>: Add an IAM policy binding to a service account.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/iam/service-accounts/set-iam-policy\">gcloud iam service-accounts set-iam-policy-binding</a>: Replace existing IAM policy binding.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/iam/service-accounts/keys/list\">gcloud iam service-accounts keys list</a>: List a service account's keys.</li>\n</ul>\n<h3>Docker &#x26; Google Kubernetes Engine (GKE)</h3>\n<p>Manage containerized applications on Kubernetes</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/auth/configure-docker\">gcloud auth configure-docker</a>: Register the gcloud tool as a Docker credential helper.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/container/clusters/create\">gcloud container clusters create</a>: Create a cluster to run GKE containers.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/container/clusters/list\">gcloud container clusters list</a>: List clusters for running GKE containers.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials\">gcloud container clusters get-credentials</a>: Update kubeconfig to get kubectl to use a GKE cluster.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/container/images/list-tags\">gcloud container images list-tags</a>: List tag and digest metadata for a container image.</li>\n</ul>\n<h3>Virtual Machines &#x26; Compute Engine</h3>\n<p>Create, run, and manage VMs on Google infrastructure</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/compute/zones/list\">gcloud compute zones list</a>: List Compute Engine zones.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/compute/instances/describe\">gcloud compute instances describe</a>: Display a VM instance's detai</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/compute/instances/list\">gcloud compute instances list</a>: List all VM instances in a project.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/compute/disks/snapshot\">gcloud compute disks snapshot</a>: Create snapshot of persistent disks.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/compute/snapshots/describe\">gcloud compute snapshots describe</a>: Display a snapshot's details.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/compute/snapshots/delete\">gcloud compute snapshots delete</a>: Delete a snapshot.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/compute/ssh\">gcloud compute ssh</a>: Connect to a VM instance by using SSH.</li>\n</ul>\n<h3>Serverless &#x26; App Engine</h3>\n<p>Build highly scalable applications on a fully managed serverless platform</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/app/deploy\">gcloud app deploy</a>: Deploy your app's code and configuration to the App Engine server.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/app/versions/list\">gcloud app versions list</a>: List all versions of all s</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/app/browse\">gcloud app browse</a>: Open the current app in a web browser.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/app/create\">gcloud app create</a>: Create an App Engine app within your current project.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/app/logs/read\">gcloud app logs read</a>: Display the latest App Engine app logs.</li>\n</ul>\n<h3>Miscellaneous</h3>\n<p>Commands that might come in handy</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/kms/decrypt\">gcloud kms decrypt</a>: Decrypt ciphertext (to a plaintext file) using a Cloud Key Management Service (Cloud KMS) key.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/logging/logs/list\">gcloud logging logs list</a>: List your project's logs.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/sql/backups/describe\">gcloud sql backups describe</a>: Display info about a Cloud SQL instance backup.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference/sql/export/sql\">gcloud sql export sql</a>: Export data from a Cloud SQL instance to a SQL file.</li>\n</ul>\n<h2>Introductory primer</h2>\n<p>A quick primer for getting started with the gcloud command-line tool.</p>\n<h3>Installing the Cloud SDK</h3>\n<p>Install the Cloud SDK with these <a href=\"https://cloud.google.com/sdk/docs/install\">installation instructions</a>.</p>\n<h3>Flags, arguments, and other wondrous additions</h3>\n<p>Arguments can be Positional args or Flags</p>\n<ul>\n<li><strong>Positional args:</strong> Set after command name; must respect order of positional args.</li>\n<li></li>\n<li>\n<p><strong>Flags:</strong> Set after positional args; order of flags doesn't matter.</p>\n<p>A flag can be either a:</p>\n<ul>\n<li><em>Name-value pair</em> (--foo=bar), or</li>\n<li><em>Boolean</em> (--force/no-force).</li>\n</ul>\n<p>Additionally, flags can either be:</p>\n<ul>\n<li><em>Required</em></li>\n<li><em>Optional:</em> in which case, the default value is used, if the flag is not defined</li>\n</ul>\n</li>\n</ul>\n<h3>Global flags</h3>\n<p>Some flags are available throughout the gcloud command-line tool experience, like:</p>\n<ul>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference#--help\">--help</a>: For when in doubt; display detailed help for a command.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference#--project\">--project</a>: If using a project other than the current one.</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference#--quiet\">--quiet</a>: Disabling interactive prompting (and appl</li>\n<li></li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference#--verbosity\">--verbosity</a>: Can set verbosity levels at debug, info, warning, error, critical, and none.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference#--version\">--version</a>: Display gcloud version information.</li>\n<li><a href=\"https://cloud.google.com/sdk/gcloud/reference#--format\">--format</a>: Set output format as config, csv, default, diff, disable, flattened, get, json, list, multi, none, object, table, text, value, or yaml.</li>\n</ul>\n<h3>Cleaning up results</h3>\n<p>Extricate the most from your output with the <a href=\"https://cloud.google.com/sdk/gcloud/reference/topic/filters\">filter</a>, <a href=\"https://cloud.google.com/sdk/gcloud/reference/topic/formats\">format</a>, limit, and sort-by flags.</p>\n<p>For Compute Engine instances with prefix us and not machine type f1-micro:</p>\n<p>For a list of projects created on or after 15 January 2018, sorted from oldest to newest, presented as a table with project number, project id and creation time columns with dates and times in local timezone:</p>\n<p>For a list of ten Compute Engine instances with a label my-label (of any value):</p>\n<h2>Understanding commands</h2>\n<p>The underlying patterns for gcloud commands; to aid self-discovery of commands.</p>\n<h3>Finding gcloud commands</h3>\n<p>The gcloud command-line tool is a tree; non-leaf nodes are command groups and leaf nodes are commands. (Also, tab completion works for commands and resources!)</p>\n<p>Most gcloud commands follow the following format:</p>\n<p>For example: gcloud + compute + instances + create + example-instance-1 + --zone=us-central1-a</p>\n<h4>Release level</h4>\n<p><em>Release Level</em> refers to the command's release status.</p>\n<p><em>Example:</em> alpha for alpha commands, beta for beta commands, no release level needed for GA commands.</p>\n<h4>Component</h4>\n<p><em>Component</em> refers to the different Google Cloud services.</p>\n<p><em>Example:</em> compute for Compute Engine, app for App Engine, etc.</p>\n<h4>Entity</h4>\n<p><em>Entity</em> refers to the plural form of an element or collection of elements under a component.</p>\n<p><em>Example:</em> disks, firewalls, images, instances, regions, zones for compute</p>\n<h4>Operation</h4>\n<p><em>Operation</em> refers to the imperative verb form of the operation to be performed on the entity.</p>\n<p><em>Example:</em> Common operations are describe, list, create/update, delete/clear, import, export, copy, remove, add, reset, restart, restore, run, and deploy.</p>\n<h4>Positional args</h4>\n<p><em>Positional args</em> refer to the required, order-specific arguments needed to execute the command.</p>\n<p><em>Example:</em> &#x3C;INSTANCE_NAMES> is the required positional argument for gcloud compute instances create.</p>\n<h4>Flags</h4>\n<p><em>Flags</em> refer to the additional arguments, --flag-name(=value), passed in to the command after positional args.</p>\n<p><em>Example:</em> --machine-type=&#x3C;MACHINE_TYPE> and --preemptible are optional flags for gcloud compute instances create.</p>"},{"url":"/docs/reference/","relativePath":"docs/reference/index.md","relativeDir":"docs/reference","base":"index.md","name":"index","frontmatter":{"title":"Reference","weight":0,"excerpt":"helpful reference guides","seo":{"title":"helpful reference guides","description":"helpful reference guides","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Reference:</h1>\n<ul>\n<li>[SITEMAP🗺🟈](<a href=\"https://bgoonz-blog.netlify.app/docs/sitemap/\">https://bgoonz-blog.netlify.app/docs/sitemap/</a>)</li>\n</ul>\n<h1>Bookmarks:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://bgoonz-bookmarks.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<h1>SearchAwesome:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://search-awesome.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<h1>Job Search:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://web-dev-collaborative.github.io/gitpod-job-search-html-static/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>"},{"url":"/docs/reference/installing-node/","relativePath":"docs/reference/installing-node.md","relativeDir":"docs/reference","base":"installing-node.md","name":"installing-node","frontmatter":{"title":"Installing Node","weight":0,"excerpt":"Installing Node","seo":{"title":"Installing Node","description":"Installing Node","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Android<a href=\"https://nodejs.org/en/download/package-manager/#android\"></a></h2>\n<p>Android support is still experimental in Node.js, so precompiled binaries are not yet provided by Node.js developers.</p>\n<p>However, there are some third-party solutions. For example, <a href=\"https://termux.com/\">Termux</a> community provides terminal emulator and Linux environment for Android, as well as own package manager and <a href=\"https://github.com/termux/termux-packages\">extensive collection</a> of many precompiled applications. This command in Termux app will install the last available Node.js version:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pkg install nodejs</code></pre></div>\n<p>Currently, Termux Node.js binaries are linked against <code class=\"language-text\">system-icu</code> (depending on <code class=\"language-text\">libicu</code> package).</p>\n<h2>Arch Linux<a href=\"https://nodejs.org/en/download/package-manager/#arch-linux\"></a></h2>\n<p>Node.js and npm packages are available in the Community Repository.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pacman -S nodejs npm</code></pre></div>\n<h2>CentOS, Fedora and Red Hat Enterprise Linux<a href=\"https://nodejs.org/en/download/package-manager/#centos-fedora-and-red-hat-enterprise-linux\"></a></h2>\n<p>Node.js is available as a module called <code class=\"language-text\">nodejs</code> in CentOS/RHEL 8 and Fedora.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">dnf module install nodejs:&lt;stream></code></pre></div>\n<p>where <code class=\"language-text\">&lt;stream></code> corresponds to the major version of Node.js. To see a list of available streams:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">dnf module list nodejs</code></pre></div>\n<p>For example, to install Node.js 12:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">dnf module install nodejs:12</code></pre></div>\n<p>For CentOS/RHEL 7 Node.js is available via <a href=\"https://www.softwarecollections.org/en/scls/?search=NodeJS\">Software Collections</a>.</p>\n<h3>Alternatives<a href=\"https://nodejs.org/en/download/package-manager/#alternatives\"></a></h3>\n<p>These resources provide packages compatible with CentOS, Fedora, and RHEL.</p>\n<ul>\n<li><a href=\"https://nodejs.org/en/download/package-manager/#snap\">Node.js snaps</a> maintained and supported at <a href=\"https://github.com/nodejs/snap\">https://github.com/nodejs/snap</a></li>\n<li><a href=\"https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions\">Node.js binary distributions</a> maintained and supported by <a href=\"https://github.com/nodesource/distributions\">NodeSource</a></li>\n</ul>\n<h2>Debian and Ubuntu based Linux distributions<a href=\"https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions\"></a></h2>\n<p><a href=\"https://github.com/nodesource/distributions/blob/master/README.md\">Node.js binary distributions</a> are available from NodeSource.</p>\n<h3>Alternatives<a href=\"https://nodejs.org/en/download/package-manager/#alternatives-1\"></a></h3>\n<p>Packages compatible with Debian and Ubuntu based Linux distributions are available via <a href=\"https://nodejs.org/en/download/package-manager/#snap\">Node.js snaps</a>.</p>\n<h2>fnm<a href=\"https://nodejs.org/en/download/package-manager/#fnm\"></a></h2>\n<p>Fast and simple Node.js version manager built in Rust used to manage multiple released Node.js versions. It allows you to perform operations like install, uninstall, switch Node versions automatically based on the current directory, etc. To install fnm, use this <a href=\"https://github.com/Schniz/fnm#using-a-script-macoslinux\">install script</a>.</p>\n<p>fnm has cross-platform support (macOS, Windows, Linux) &#x26; all popular shells (Bash, Zsh, Fish, PowerShell, Windows Command Line Prompt). fnm is built with speed in mind and compatibility support for <code class=\"language-text\">.node-version</code> and <code class=\"language-text\">.nvmrc</code> files.</p>\n<h2>FreeBSD<a href=\"https://nodejs.org/en/download/package-manager/#freebsd\"></a></h2>\n<p>The most recent release of Node.js is available via the <a href=\"https://www.freshports.org/www/node\">www/node</a> port.</p>\n<p>Install a binary package via <a href=\"https://www.freebsd.org/cgi/man.cgi?pkg\">pkg</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pkg install node</code></pre></div>\n<p>Or compile it on your own using <a href=\"https://www.freebsd.org/cgi/man.cgi?ports\">ports</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cd /usr/ports/www/node &amp;&amp; make install</code></pre></div>\n<h2>Gentoo<a href=\"https://nodejs.org/en/download/package-manager/#gentoo\"></a></h2>\n<p>Node.js is available in the portage tree.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">emerge nodejs</code></pre></div>\n<h2>IBM i<a href=\"https://nodejs.org/en/download/package-manager/#ibm-i\"></a></h2>\n<p>LTS versions of Node.js are available from IBM, and are available via <a href=\"https://ibm.biz/ibmi-rpms\">the 'yum' package manager</a>. The package name is <code class=\"language-text\">nodejs</code> followed by the major version number (for instance, <code class=\"language-text\">nodejs12</code>, <code class=\"language-text\">nodejs14</code> etc)</p>\n<p>To install Node.js 14.x from the command line, run the following as a user with *ALLOBJ special authority:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yum install nodejs14</code></pre></div>\n<p>Node.js can also be installed with the IBM i Access Client Solutions product. See <a href=\"http://www-01.ibm.com/support/docview.wss?uid=nas8N1022619\">this support document</a> for more details</p>\n<h2>macOS<a href=\"https://nodejs.org/en/download/package-manager/#macos\"></a></h2>\n<p>Download the <a href=\"https://nodejs.org/en/#home-downloadhead\">macOS Installer</a> directly from the <a href=\"https://nodejs.org/\">nodejs.org</a> web site.</p>\n<p><em>If you want to download the package with bash:</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl \"https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\\.pkg&lt;/a>.*|\\1|p')}.pkg\" > \"$HOME/Downloads/node-latest.pkg\" &amp;&amp; sudo installer -store -pkg \"$HOME/Downloads/node-latest.pkg\" -target \"/\"</code></pre></div>\n<h3>Alternatives<a href=\"https://nodejs.org/en/download/package-manager/#alternatives-2\"></a></h3>\n<p>Using <a href=\"https://brew.sh/\">Homebrew</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">brew install node</code></pre></div>\n<p>Using <a href=\"https://www.macports.org/\">MacPorts</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">port install nodejs&lt;major version>\n\n# Example\nport install nodejs7</code></pre></div>\n<p>Using <a href=\"https://pkgsrc.joyent.com/install-on-osx/\">pkgsrc</a>:</p>\n<p>Install the binary package:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pkgin -y install nodejs</code></pre></div>\n<p>Or build manually from pkgsrc:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cd pkgsrc/lang/nodejs &amp;&amp; bmake install</code></pre></div>\n<h2>n<a href=\"https://nodejs.org/en/download/package-manager/#n\"></a></h2>\n<p><code class=\"language-text\">n</code> is a simple to use Node.js version manager for Mac and Linux. Specify the target version to install using a rich syntax, or select from a menu of previously downloaded versions. The versions are installed system-wide or user-wide, and for more targeted use you can run a version directly from the cached downloads.</p>\n<p>See the <a href=\"https://github.com/tj/n\">homepage</a> for install methods (boostrap, npm, Homebrew, third-party), and all the usage details.</p>\n<p>If you already have <code class=\"language-text\">npm</code> then installing <code class=\"language-text\">n</code> and then the newest LTS <code class=\"language-text\">node</code> version is as simple as:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install -g n\nn lts</code></pre></div>\n<h2>NetBSD<a href=\"https://nodejs.org/en/download/package-manager/#netbsd\"></a></h2>\n<p>Node.js is available in the pkgsrc tree:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cd /usr/pkgsrc/lang/nodejs &amp;&amp; make install</code></pre></div>\n<p>Or install a binary package (if available for your platform) using pkgin:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pkgin -y install nodejs</code></pre></div>\n<h2>Nodenv<a href=\"https://nodejs.org/en/download/package-manager/#nodenv\"></a></h2>\n<p><code class=\"language-text\">nodenv</code> is a lightweight node version manager, similar to <code class=\"language-text\">nvm</code>. It's simple and predictable. A rich plugin ecosystem lets you tailor it to suit your needs. Use <code class=\"language-text\">nodenv</code> to pick a Node version for your application and guarantee that your development environment matches production.</p>\n<p>Nodenv installation instructions are maintained <a href=\"https://github.com/nodenv/nodenv#installation\">on its Github page</a>. Please visit that page to ensure you're following the latest version of the installation steps.</p>\n<h2>nvm<a href=\"https://nodejs.org/en/download/package-manager/#nvm\"></a></h2>\n<p>Node Version Manager is a bash script used to manage multiple released Node.js versions. It allows you to perform operations like install, uninstall, switch version, etc. To install nvm, use this <a href=\"https://github.com/nvm-sh/nvm#install--update-script\">install script</a>.</p>\n<p>On Unix / OS X systems Node.js built from source can be installed using <a href=\"https://github.com/creationix/nvm\">nvm</a> by installing into the location that nvm expects:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">env VERSION=`python tools/getnodeversion.py` make install DESTDIR=`nvm_version_path v$VERSION` PREFIX=\"\"</code></pre></div>\n<p>After this you can use <code class=\"language-text\">nvm</code> to switch between released versions and versions built from source. For example, if the version of Node.js is v8.0.0-pre:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">nvm use 8</code></pre></div>\n<p>Once the official release is out you will want to uninstall the version built from source:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">nvm uninstall 8</code></pre></div>\n<h2>nvs<a href=\"https://nodejs.org/en/download/package-manager/#nvs\"></a></h2>\n<h4>Windows<a href=\"https://nodejs.org/en/download/package-manager/#windows\"></a></h4>\n<p>The <code class=\"language-text\">nvs</code> version manager is cross-platform and can be used on Windows, macOS, and Unix-like systems</p>\n<p>To install <code class=\"language-text\">nvs</code> on Windows go to the <a href=\"https://github.com/jasongin/nvs/releases\">release page</a> here and download the MSI installer file of the latest release.</p>\n<p>You can also use <code class=\"language-text\">chocolatey</code> to install it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">choco install nvs</code></pre></div>\n<h4>macOS,UnixLike<a href=\"https://nodejs.org/en/download/package-manager/#macos-unixlike\"></a></h4>\n<p>You can find the documentation regarding the installation steps of <code class=\"language-text\">nvs</code> in macOS/Unix-like systems <a href=\"https://github.com/jasongin/nvs/blob/master/doc/SETUP.md#mac-linux\">here</a></p>\n<h4>Usage<a href=\"https://nodejs.org/en/download/package-manager/#usage\"></a></h4>\n<p>After this you can use <code class=\"language-text\">nvs</code> to switch between different versions of node.</p>\n<p>To add the latest version of node:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">nvs add latest</code></pre></div>\n<p>Or to add the latest LTS version of node:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">nvs add lts</code></pre></div>\n<p>Then run the <code class=\"language-text\">nvs use</code> command to add a version of node to your <code class=\"language-text\">PATH</code> for the current shell:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ nvs use lts\nPATH -= %LOCALAPPDATA%\\nvs\\default\nPATH += %LOCALAPPDATA%\\nvs\\node\\14.17.0\\x64</code></pre></div>\n<p>To add it to <code class=\"language-text\">PATH</code> permanently, use <code class=\"language-text\">nvs link</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">nvs link lts</code></pre></div>\n<h2>OpenBSD<a href=\"https://nodejs.org/en/download/package-manager/#openbsd\"></a></h2>\n<p>Node.js is available through the ports system.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/usr/ports/lang/node</code></pre></div>\n<p>Using <a href=\"https://man.openbsd.org/OpenBSD-current/man1/pkg_add.1\">pkg_add</a> on OpenBSD:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pkg_add node</code></pre></div>\n<h2>openSUSE and SLE<a href=\"https://nodejs.org/en/download/package-manager/#opensuse-and-sle\"></a></h2>\n<p>Node.js is available in the main repositories under the following packages:</p>\n<ul>\n<li>openSUSE Leap 15.2: <code class=\"language-text\">nodejs10</code>, <code class=\"language-text\">nodejs12</code>, <code class=\"language-text\">nodejs14</code></li>\n<li>openSUSE Tumbleweed: <code class=\"language-text\">nodejs16</code></li>\n<li>SUSE Linux Enterprise Server (SLES) 12: <code class=\"language-text\">nodejs10</code>, <code class=\"language-text\">nodejs12</code>, and <code class=\"language-text\">nodejs14</code> (The \"Web and Scripting Module\" must be <a href=\"https://www.suse.com/releasenotes/x86_64/SUSE-SLES/12-SP5/#intro-modulesExtensionsRelated\">enabled</a>.)</li>\n<li>SUSE Linux Enterprise Server (SLES) 15 SP2: <code class=\"language-text\">nodejs10</code>, <code class=\"language-text\">nodejs12</code>, and <code class=\"language-text\">nodejs14</code> (The \"Web and Scripting Module\" must be <a href=\"https://www.suse.com/releasenotes/x86_64/SUSE-SLES/15/#Intro.Module\">enabled</a>.)</li>\n</ul>\n<p>For example, to install Node.js 14.x on openSUSE Leap 15.2, run the following as root:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">zypper install nodejs14</code></pre></div>\n<p>Different major versions of Node can be installed and used concurrently.</p>\n<h2>SmartOS and illumos<a href=\"https://nodejs.org/en/download/package-manager/#smartos-and-illumos\"></a></h2>\n<p>SmartOS images come with pkgsrc pre-installed. On other illumos distributions, first install <a href=\"https://pkgsrc.joyent.com/install-on-illumos/\">pkgsrc</a>, then you may install the binary package as normal:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pkgin -y install nodejs</code></pre></div>\n<p>Or build manually from pkgsrc:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cd pkgsrc/lang/nodejs &amp;&amp; bmake install</code></pre></div>\n<h2>Snap<a href=\"https://nodejs.org/en/download/package-manager/#snap\"></a></h2>\n<p><a href=\"https://github.com/nodejs/snap\">Node.js snaps</a> are available as <a href=\"https://snapcraft.io/node\"><code class=\"language-text\">node</code></a> on the Snap store.</p>\n<h2>Solus<a href=\"https://nodejs.org/en/download/package-manager/#solus\"></a></h2>\n<p>Solus provides Node.js in its main repository.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sudo eopkg install nodejs</code></pre></div>\n<h2>Void Linux<a href=\"https://nodejs.org/en/download/package-manager/#void-linux\"></a></h2>\n<p>Void Linux ships Node.js stable in the main repository.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">xbps-install -Sy nodejs</code></pre></div>\n<h2>Windows<a href=\"https://nodejs.org/en/download/package-manager/#windows-1\"></a></h2>\n<p>Download the <a href=\"https://nodejs.org/en/#home-downloadhead\">Windows Installer</a> directly from the <a href=\"https://nodejs.org/\">nodejs.org</a> web site.</p>\n<h3>Alternatives<a href=\"https://nodejs.org/en/download/package-manager/#alternatives-3\"></a></h3>\n<p>Using <a href=\"https://chocolatey.org/\">Chocolatey</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cinst nodejs\n# or for full install with npm\ncinst nodejs.install</code></pre></div>\n<p>Using <a href=\"https://scoop.sh/\">Scoop</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">scoop install nodejs</code></pre></div>"},{"url":"/docs/react/react-patterns-by-usecase/","relativePath":"docs/react/react-patterns-by-usecase.md","relativeDir":"docs/react","base":"react-patterns-by-usecase.md","name":"react-patterns-by-usecase","frontmatter":{"title":"React By Usecase","weight":0,"excerpt":"cheat sheet","seo":{"title":"React By Usecase","description":"Of course, if you get a DOM node for the component via refs, you can do anything you want with the DOM nodes of other components, but it will likely mess up React.","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Wrapping/Mirroring</h2>\n<h3>Wrapping/Mirroring a HTML Element</h3>\n<p>Usecase: you want to make a <code class=\"language-text\">&lt;Button></code> that takes all the normal props of <code class=\"language-text\">&lt;button></code> and does extra stuff.</p>\n<p>Strategy: extend <code class=\"language-text\">React.ComponentPropsWithoutRef&lt;'button'></code></p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// usage</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Type '\"foo\"' is not assignable to type '\"button\" | \"submit\" | \"reset\" | undefined'.(2322)</span>\n    <span class=\"token comment\">// return &lt;Button type=\"foo\"> sldkj &lt;/Button></span>\n\n    <span class=\"token comment\">// no error</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Button</span></span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\"> text </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Button</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// implementation</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">ButtonProps</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>ComponentPropsWithoutRef<span class=\"token operator\">&lt;</span><span class=\"token string\">'button'</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n    specialProp<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Button</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> ButtonProps<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> specialProp<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// do something with specialProp</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwCwAUI4wPQtwCuqyA5lowQ4A7fMAhC4AQTBgAFAEo4Ab0Zw4bOABUAnmCzkARAQgQDZOMHRCI8NKmA8hyAEYAbfTAhwYu-WQPOHDCeQgZwAD5wBqgcziDAMGGRBpSoWIkRnEIAJlgEwEJY2WQAdLIATADM5eXyqurslDAcUBIAPABCQSHevgC8RiYGAHxwqK7ZANYAVnBtLF3B4sP19RrWcFhQxFD1TS3tiz0+egOBS6GjMFgAHvDzR8uMAL7MDBqgYO4gWEIwyDAxEJGLdILALH8tgQ8PpHkIAArEMDoW7XHLobB4GAlADCJEghT+iIgyLaZHOITIoxUDDUqD0uGAyFcxLAAH4AFxjGBQAo8egMV4MUHQQjCUTiOBw2RgJGoLlw1moRQ0tS4cSoeBKMYMpkspEAGjgJRNqXgzzgfTgspJqAFag02S8qBI6QAFny4AB3BJunVYRnM1l7dIHOYUyVKE0lM0WljDAXPIA\"><em>See this in the TS Playground</em></a></p>\n<p><strong>Forwarding Refs</strong>: As <a href=\"https://reactjs.org/docs/forwarding-refs.html\">the React docs themselves note</a>, most usecases will not need to obtain a ref to the inner element. But for people making reusable component libraries, you will need to <code class=\"language-text\">forwardRef</code> the underlying element, and then you can use <code class=\"language-text\">ComponentPropsWithRef</code> to grab props for your wrapper component. Check <a href=\"https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/forward_and_create_ref/\">our docs on forwarding Refs</a> for more.</p>\n<p>In future, the need to <code class=\"language-text\">forwardRef</code> may go away in React 17+, but for now we still have to deal with this. 🙃</p>\n<details>\n<summary>\n<p>Why not <code class=\"language-text\">ComponentProps</code> or <code class=\"language-text\">IntrinsicElements</code> or <code class=\"language-text\">[Element]HTMLAttributes</code> or <code class=\"language-text\">HTMLProps</code> or <code class=\"language-text\">HTMLAttributes</code>?</p>\n</summary>\n<h2><code class=\"language-text\">ComponentProps</code></h2>\n<p>You CAN use <code class=\"language-text\">ComponentProps</code> in place of <code class=\"language-text\">ComponentPropsWithRef</code>, but you may prefer to be explicit about whether or not the component's refs are forwarded, which is what we have chosen to demonstrate. The tradeoff is slightly more intimidating terminology.</p>\n<p>More info: <a href=\"https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/forward_and_create_ref/\">https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/forward_and_create_ref/</a></p>\n<h3>Maybe <code class=\"language-text\">JSX.IntrinsicElements</code> or <code class=\"language-text\">React.[Element]HTMLAttributes</code></h3>\n<p>There are at least 2 other equivalent ways to do this, but they are more verbose:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// Method 1: JSX.IntrinsicElements</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">btnType</span> <span class=\"token operator\">=</span> <span class=\"token constant\">JSX</span><span class=\"token punctuation\">.</span>IntrinsicElements<span class=\"token punctuation\">[</span><span class=\"token string\">\"button\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// cannot inline or will error</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">ButtonProps</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">btnType</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token comment\">// etc</span>\n\n<span class=\"token comment\">// Method 2: React.[Element]HTMLAttributes</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">ButtonProps</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>ButtonHTMLAttributes<span class=\"token operator\">&lt;</span>HTMLButtonElement<span class=\"token operator\">></span></code></pre></div>\n<p>Looking at <a href=\"https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f3134f4897c8473f590cbcdd5788da8d59796f45/types/react/index.d.ts#L821\">the source for <code class=\"language-text\">ComponentProps</code></a> shows that this is a clever wrapper for <code class=\"language-text\">JSX.IntrinsicElements</code>, whereas the second method relies on specialized interfaces with unfamiliar naming/capitalization.</p>\n<blockquote>\n<p>Note: There are over 50 of these specialized interfaces available - look for <code class=\"language-text\">HTMLAttributes</code> in our <a href=\"https://react-typescript-cheatsheet.netlify.app/docs/advanced/types_react_api#typesreact\"><code class=\"language-text\">@types/react</code> commentary</a>.</p>\n</blockquote>\n<p>Ultimately, <a href=\"https://github.com/typescript-cheatsheets/react/pull/276\">we picked the <code class=\"language-text\">ComponentProps</code> method</a> as it involves the least TS specific jargon and has the most ease of use. But you'll be fine with either of these methods if you prefer.</p>\n<h3>Definitely not <code class=\"language-text\">React.HTMLProps</code> or <code class=\"language-text\">React.HTMLAttributes</code></h3>\n<p>This is what happens when you use <code class=\"language-text\">React.HTMLProps</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">ButtonProps</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>HTMLProps<span class=\"token operator\">&lt;</span>HTMLButtonElement<span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n    specialProp<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">function</span> <span class=\"token function\">Button</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> ButtonProps<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> specialProp<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ERROR: Type 'string' is not assignable to type '\"button\" | \"submit\" | \"reset\" | undefined'.</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>It infers a too-wide type of <code class=\"language-text\">string</code> for <code class=\"language-text\">type</code>, because it <a href=\"https://github.com/typescript-cheatsheets/react/issues/128#issuecomment-508103558\">uses <code class=\"language-text\">AllHTMLAttributes</code> under the hood</a>.</p>\n<p>This is what happens when you use <code class=\"language-text\">React.HTMLAttributes</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">ButtonProps</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>HTMLAttributes<span class=\"token operator\">&lt;</span>HTMLButtonElement<span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">/* etc */</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// usage</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Property 'type' does not exist on type 'IntrinsicAttributes &amp; ButtonProps'</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Button</span></span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>submit<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\"> text </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Button</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</details>\n<h3>Wrapping/Mirroring a Component</h3>\n<blockquote>\n<p>TODO: this section needs work to make it simplified.</p>\n</blockquote>\n<p>Usecase: same as above, but for a React Component you don't have access to the underlying props</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Box</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>CSSProperties<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">style</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> Card <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">{</span> title<span class=\"token punctuation\">,</span> children<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>props <span class=\"token punctuation\">}</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> title<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">&amp;</span> $ElementProps<span class=\"token operator\">&lt;</span><span class=\"token keyword\">typeof</span> Box<span class=\"token operator\">></span> <span class=\"token comment\">// new utility, see below</span>\n<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Box</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token punctuation\">{</span>title<span class=\"token punctuation\">}</span><span class=\"token plain-text\">: </span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Box</span></span><span class=\"token punctuation\">></span></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Strategy: extract a component's props by inferring them</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// ReactUtilityTypes.d.ts</span>\n<span class=\"token keyword\">declare</span> <span class=\"token keyword\">type</span> <span class=\"token class-name\">$ElementProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token operator\">=</span> <span class=\"token constant\">T</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>ComponentType<span class=\"token operator\">&lt;</span><span class=\"token keyword\">infer</span> Props<span class=\"token operator\">></span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>Props <span class=\"token keyword\">extends</span> <span class=\"token class-name\">object</span> <span class=\"token operator\">?</span> Props <span class=\"token operator\">:</span> <span class=\"token builtin\">never</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token builtin\">never</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Usage:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">import</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> Recompose <span class=\"token keyword\">from</span> <span class=\"token string\">'recompose'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> defaultProps <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span><span class=\"token constant\">C</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>ComponentType<span class=\"token punctuation\">,</span> <span class=\"token constant\">D</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Partial<span class=\"token operator\">&lt;</span>$ElementProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">C</span><span class=\"token operator\">>></span></span><span class=\"token operator\">></span><span class=\"token punctuation\">(</span>\n    defaults<span class=\"token operator\">:</span> <span class=\"token constant\">D</span><span class=\"token punctuation\">,</span>\n    Component<span class=\"token operator\">:</span> <span class=\"token constant\">C</span>\n<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ComponentType<span class=\"token operator\">&lt;</span>$ElementProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">C</span><span class=\"token operator\">></span> <span class=\"token operator\">&amp;</span> Partial<span class=\"token operator\">&lt;</span><span class=\"token constant\">D</span><span class=\"token operator\">>></span> <span class=\"token operator\">=></span> Recompose<span class=\"token punctuation\">.</span><span class=\"token function\">defaultProps</span><span class=\"token punctuation\">(</span>defaults<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>Component<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><em>thanks <a href=\"https://github.com/typescript-cheatsheets/react/issues/23\">dmisdm</a></em></p>\n<p>:new: You should also consider whether to explicitly forward refs:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// base button, with ref forwarding</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">Props</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> children<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span> type<span class=\"token operator\">:</span> <span class=\"token string\">'submit'</span> <span class=\"token operator\">|</span> <span class=\"token string\">'button'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">type</span> <span class=\"token class-name\">Ref</span> <span class=\"token operator\">=</span> HTMLButtonElement<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> FancyButton <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token generic-function\"><span class=\"token function\">forwardRef</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span>Ref<span class=\"token punctuation\">,</span> Props<span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">,</span> ref<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">ref</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>ref<span class=\"token punctuation\">}</span></span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>MyCustomButtonClass<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">type</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// second layer button, no need for forwardRef (TODO: doublecheck this)</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">DoubleWrappedProps</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>ComponentPropsWithRef<span class=\"token operator\">&lt;</span><span class=\"token keyword\">typeof</span> FancyButton<span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n    specialProp<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">function</span> <span class=\"token function\">DoubleWrappedButton</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> DoubleWrappedProps<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> specialProp<span class=\"token punctuation\">,</span> ref<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">ref</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>ref<span class=\"token punctuation\">}</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// usage</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> btnRef <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token generic-function\"><span class=\"token function\">useRef</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span>HTMLButtonElement<span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token operator\">!</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">DoubleWrappedButton</span></span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">ref</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>btnRef<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            text</span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">DoubleWrappedButton</span></span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><em><a href=\"https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwCwAUIwPTNwBGaWHArjDBAB2AGjgB3YDAAWcSgTgFoY5FAAmwQQHNGMAJ5huABWJh0AXjgBvOLinAANqsqCAXJiowAdNjwwAchCqWDRwegZuAESoPOwgkhFwAD5wEex8AoIJAL70DFgAHpCwofrc2PIWABIAKgCyADIAQulCAKL2WCBYgjC5BUXwuEKo8ABiyIK4us38QnAWPvieilDKauUAPOWixhCmAHwAFIdgJqiicgCU8-twh4xwcBtps4KyWARmlnJZNvZoqD8yC6ZgitV0AGF-qhAcCsAkwlgvqc9qhPIisvsHo8rCjTJ5bA4nN0stiNswXhksQxLpdcowWGxUFghoJVHB-rosFBeK9GP1oPANDBuQQ8NwACIQGIdADqUGQYAMql2pjgBRFbPQiy8EJIkEE3RgqtQsskUk2iIg8nGk2mLUEt0s2NQBlwwGQ9lVAH43CMoBpNLlSXlCoKFDxJjBgHMpTKsPLFcqZhkTmc3HH2HKFUqsCqztdnQxHqyRlY4K6WR6vSYLh9RJ5G5Qy78LHjULlHpQYDwoG9ng73p9vh9fpZG55mzBfsx9sGGQxWHAeKhkJosIwCJH8DG3gBBJWHQvY0vwdgwQTlebuXyeFdYTY1BoptodLo9I6CHj2ewAQku2Ldr2-aZtmSZ5i+byIqClJCAkchfOel6jrcIr5PA5KgQmObJg61IhkAA\">TS Playground link</a></em></p>\n<h2>Polymorphic Components (e.g. with <code class=\"language-text\">as</code> props)</h2>\n<blockquote>\n<p>\"Polymorphic Components\" = passing a component to be rendered, e.g. with <code class=\"language-text\">as</code> props</p>\n</blockquote>\n<p><code class=\"language-text\">ElementType</code> is pretty useful to cover most types that can be passed to createElement e.g.</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">function</span> <span class=\"token function\">PassThrough</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">as</span><span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ElementType<span class=\"token operator\">&lt;</span><span class=\"token builtin\">any</span><span class=\"token operator\">></span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">as</span><span class=\"token operator\">:</span> Component <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Component</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>You might also see this with React Router:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">PrivateRoute</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> component<span class=\"token operator\">:</span> Component<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span><span class=\"token operator\">:</span> PrivateRouteProps<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> isLoggedIn <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token function\">useAuth</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> isLoggedIn <span class=\"token operator\">?</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Component</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span> <span class=\"token operator\">:</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Redirect</span></span> <span class=\"token attr-name\">to</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>/<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>For more info you can refer to these resources:</p>\n<ul>\n<li><a href=\"https://blog.andrewbran.ch/polymorphic-react-components/\">https://blog.andrewbran.ch/polymorphic-react-components/</a></li>\n<li><a href=\"https://github.com/kripod/react-polymorphic-box\">https://github.com/kripod/react-polymorphic-box</a></li>\n<li><a href=\"https://stackoverflow.com/questions/58200824/generic-react-typescript-component-with-as-prop-able-to-render-any-valid-dom\">https://stackoverflow.com/questions/58200824/generic-react-typescript-component-with-as-prop-able-to-render-any-valid-dom</a></li>\n</ul>\n<p><a href=\"https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/pull/69\">Thanks @eps1lon</a> and <a href=\"https://github.com/typescript-cheatsheets/react/issues/151\">@karol-majewski</a> for thoughts!</p>\n<h2>Generic Components</h2>\n<p>Just as you can make generic functions and classes in TypeScript, you can also make generic components to take advantage of the type system for reusable type safety. Both Props and State can take advantage of the same generic types, although it probably makes more sense for Props than for State. You can then use the generic type to annotate types of any variables defined inside your function / class scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    items<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function-variable function\">renderItem</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token generic-function\"><span class=\"token function\">List</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> items<span class=\"token punctuation\">,</span> renderItem <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>state<span class=\"token punctuation\">,</span> setState<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token generic-function\"><span class=\"token function\">useState</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// You can use type T in List function scope.</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>renderItem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">onClick</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setState</span><span class=\"token punctuation\">(</span>items<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Clone</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>state<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>You can then use the generic components and get nice type safety through type inference:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\">ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">List</span></span>\n        <span class=\"token attr-name\">items</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span></span> <span class=\"token comment\">// type of 'string' inferred</span>\n        <span class=\"token attr-name\">renderItem</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n            <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span> <span class=\"token attr-name\">key</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n                </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/* Error: Property 'toPrecision' does not exist on type 'string'. */</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n                </span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span><span class=\"token function\">toPrecision</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span>\n    <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span>\n    document<span class=\"token punctuation\">.</span>body\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>As of <a href=\"#typescript-29\">TS 2.9</a>, you can also supply the type parameter in your JSX to opt out of type inference:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\">ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>List<span class=\"token operator\">&lt;</span><span class=\"token builtin\">number</span><span class=\"token operator\">></span>\n        items<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span> <span class=\"token comment\">// Error: Type 'string' is not assignable to type 'number'.</span>\n        renderItem<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span> <span class=\"token attr-name\">key</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span><span class=\"token function\">toPrecision</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\n    document<span class=\"token punctuation\">.</span>body\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can also use Generics using fat arrow function style:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    items<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function-variable function\">renderItem</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Note the &lt;T extends unknown> before the function definition.</span>\n<span class=\"token comment\">// You can't use just `&lt;T>` as it will confuse the TSX parser whether it's a JSX tag or a Generic Declaration.</span>\n<span class=\"token comment\">// You can also use &lt;T,> https://github.com/microsoft/TypeScript/issues/15713#issuecomment-499474386</span>\n<span class=\"token keyword\">const</span> List <span class=\"token operator\">=</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">T</span></span> <span class=\"token attr-name\">extends</span> <span class=\"token attr-name\">unknown</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">(props: Props&lt;T>) => </span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> items<span class=\"token punctuation\">,</span> renderItem <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>state<span class=\"token punctuation\">,</span> setState<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token generic-function\"><span class=\"token function\">useState</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// You can use type T in List function scope.</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>renderItem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">onClick</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setState</span><span class=\"token punctuation\">(</span>items<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Clone</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>state<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token plain-text\">;</span></code></pre></div>\n<p>The same for using classes: (Credit: <a href=\"https://twitter.com/WrocTypeScript/status/1163234064343736326\">Karol Majewski</a>'s <a href=\"https://gist.github.com/karol-majewski/befaf05af73c7cb3248b4e084ae5df71\">gist</a>)</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    items<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function-variable function\">renderItem</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">interface</span> <span class=\"token class-name\">State<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    items<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">List<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>PureComponent<span class=\"token operator\">&lt;</span>Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> State<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">>></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// You can use type T inside List class.</span>\n    state<span class=\"token operator\">:</span> Readonly<span class=\"token operator\">&lt;</span>State<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">>></span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        items<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> items<span class=\"token punctuation\">,</span> renderItem <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// You can use type T inside List class.</span>\n        <span class=\"token keyword\">const</span> clone<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> items<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n                </span><span class=\"token punctuation\">{</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>renderItem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n                </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">onClick</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">items</span><span class=\"token operator\">:</span> clone <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Clone</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n                </span><span class=\"token punctuation\">{</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Though you can't use Generic Type Parameters for Static Members:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">List<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>PureComponent<span class=\"token operator\">&lt;</span>Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> State<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">>></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Static members cannot reference class type parameters.ts(2302)</span>\n    <span class=\"token keyword\">static</span> <span class=\"token function\">getDerivedStateFromProps</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> state<span class=\"token operator\">:</span> State<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> items<span class=\"token operator\">:</span> props<span class=\"token punctuation\">.</span>items <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To fix this you need to convert your static function to a type inferred function:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">List<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React</span><span class=\"token punctuation\">.</span>PureComponent<span class=\"token operator\">&lt;</span>Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> State<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">>></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">static</span> <span class=\"token generic-function\"><span class=\"token function\">getDerivedStateFromProps</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> Props<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> state<span class=\"token operator\">:</span> State<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> items<span class=\"token operator\">:</span> props<span class=\"token punctuation\">.</span>items <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Generic components with children</h3>\n<p><code class=\"language-text\">children</code> is usually not defined as a part of the props type. Unless <code class=\"language-text\">children</code> are explicitly defined as a part of the <code class=\"language-text\">props</code> type, an attempt to use <code class=\"language-text\">props.children</code> in JSX or in the function body will fail:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">WrapperProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function-variable function\">renderItem</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Property 'children' does not exist on type 'WrapperProps&lt;T>'. */</span>\n<span class=\"token keyword\">const</span> Wrapper <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span> <span class=\"token keyword\">extends</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> WrapperProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span><span class=\"token function\">renderItem</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/*\nType '{ children: string; item: string; renderItem: (item: string) => string; }' is not assignable to type 'IntrinsicAttributes &amp; WrapperProps&lt;string>'.\n  Property 'children' does not exist on type 'IntrinsicAttributes &amp; WrapperProps&lt;string>'.\n*/</span>\n\n<span class=\"token keyword\">const</span> wrapper <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Wrapper</span></span> <span class=\"token attr-name\">item</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>test<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">renderItem</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> item<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token punctuation\">{</span>test<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Wrapper</span></span><span class=\"token punctuation\">></span></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><a href=\"https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoC4AOxiSk3STgHUoUwx6AFHMAZwA8AFQB8cAN4U4cYHRAAuOMIDc0uEWoATegEl5SgBRyki5QEo4AXnHJ0MAHR2MAOQg615GWgAWwADZamkrOjqFuHhQAvhQUAPQAVHC8EFywAJ4EvgFBSNT4cFoQSPxw1BDwSAAewPzwENRwMOlcBGwcaSkCIqL4DnAJcRRoDXWs7Jz01nAicNV02qUSUaKGYHz8Su2TUF1CYpY2kupEMACuUI2G6jKCWsAAbqI3MpLrqfwOmjpQ+qZrGwcJhA5hiXleMgk7wEDmygU0YIhgji9ye6nMniinniCQowhazHwEjgcNy1CUdSgNAA5ipZAY4JSaXTvnoGcYGUzqNTDuIubS4FECrUyhU4Ch+PxgNTqCgAEb+ZgwCBNAkEXS0KnUKVoACCMBgVLlZzopQAZOMOjwNoJ+b0HOouvRmlk-PC8gUiiVRZUamMGqrWvgNYaaDr9aHjaa4Bbtp0bXa+hRBrFyCNtfBTfArHBDLyZqjRAAJJD+fwqrPIwvDUbwADuEzS02u4MEcamwKsACIs12NHkfn8QFYJMDrOJgSsXhIs4iZnF21BnuQMUA\">View in the TypeScript Playground</a></p>\n<p>To work around that, either add <code class=\"language-text\">children</code> to the <code class=\"language-text\">WrapperProps</code> definition (possibly narrowing down its type, as needed):</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">WrapperProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function-variable function\">renderItem</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n    children<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// The component will only accept a single string child</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> Wrapper <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span> <span class=\"token keyword\">extends</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> WrapperProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span><span class=\"token function\">renderItem</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>or wrap the type of the props in <code class=\"language-text\">React.PropsWithChildren</code> (this is what <code class=\"language-text\">React.FC&lt;></code> does):</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">WrapperProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function-variable function\">renderItem</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>item<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> Wrapper <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span> <span class=\"token keyword\">extends</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>PropsWithChildren<span class=\"token operator\">&lt;</span>WrapperProps<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">>></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span><span class=\"token function\">renderItem</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Typing Children</h2>\n<p>Some API designs require some restriction on <code class=\"language-text\">children</code> passed to a parent component. It is common to want to enforce these in types, but you should be aware of limitations to this ability.</p>\n<h3>What You CAN Do</h3>\n<p>You can type the <strong>structure</strong> of your children: just one child, or a tuple of children.</p>\n<p>The following are valid:</p>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">OneChild</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span>ReactElement<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">TwoChildren</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>React<span class=\"token punctuation\">.</span>ReactElement<span class=\"token punctuation\">,</span> React<span class=\"token punctuation\">.</span>ReactElement<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">ArrayOfProps</span> <span class=\"token operator\">=</span> SomeProp<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">NumbersChildren</span> <span class=\"token operator\">=</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">TwoNumbersChildren</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token builtin\">number</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<details>\n<summary>\nDon't forget that you can also use `prop-types` if TS fails you.\n</summary>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\">Parent<span class=\"token punctuation\">.</span>propTypes <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    children<span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">shape</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        props<span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token function\">shape</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// could share `propTypes` to the child</span>\n            value<span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span><span class=\"token builtin\">string</span><span class=\"token punctuation\">.</span>isRequired\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>isRequired\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</details>\n<h3>What You CANNOT Do</h3>\n<p>The thing you cannot do is <strong>specify which components</strong> the children are, e.g. If you want to express the fact that \"React Router <code class=\"language-text\">&lt;Routes></code> can only have <code class=\"language-text\">&lt;Route></code> as children, nothing else is allowed\" in TypeScript.</p>\n<p>This is because when you write a JSX expression (<code class=\"language-text\">const foo = &lt;MyComponent foo='foo' /></code>), the resultant type is blackboxed into a generic JSX.Element type. (<em><a href=\"https://github.com/typescript-cheatsheets/react/issues/271\">thanks @ferdaber</a></em>)</p>\n<h2>Type Narrowing based on Props</h2>\n<p>What you want:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// Usage</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/* 😎 All good */</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Button</span></span> <span class=\"token attr-name\">target</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>_blank<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://www.google.com<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n                Test\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Button</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/* 😭 Error, `disabled` doesnt exist on anchor element */</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Button</span></span> <span class=\"token attr-name\">disabled</span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>x<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n                Test\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Button</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span></span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>How to implement: Use <a href=\"https://basarat.gitbooks.io/typescript/docs/types/typeGuard.html#user-defined-type-guards\">type guards</a>!</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// Button props</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">ButtonProps</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span>ButtonHTMLAttributes<span class=\"token operator\">&lt;</span>HTMLButtonElement<span class=\"token operator\">></span> <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">{</span>\n    href<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Anchor props</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">AnchorProps</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span>AnchorHTMLAttributes<span class=\"token operator\">&lt;</span>HTMLAnchorElement<span class=\"token operator\">></span> <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">{</span>\n    href<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Input/output options</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">Overload</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> ButtonProps<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSX</span><span class=\"token punctuation\">.</span>Element<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> AnchorProps<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSX</span><span class=\"token punctuation\">.</span>Element<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Guard to check if href exists in props</span>\n<span class=\"token keyword\">const</span> hasHref <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> ButtonProps <span class=\"token operator\">|</span> AnchorProps<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> props <span class=\"token keyword\">is</span> AnchorProps <span class=\"token operator\">=></span> <span class=\"token string\">'href'</span> <span class=\"token keyword\">in</span> props<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Component</span>\n<span class=\"token keyword\">const</span> Button<span class=\"token operator\">:</span> <span class=\"token function-variable function\">Overload</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> ButtonProps <span class=\"token operator\">|</span> AnchorProps<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// anchor render</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">hasHref</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>a</span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// button render</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><a href=\"https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoAekrgCEBXGGCAOzjBzAGcKYBPMEjqNmLAAqcucALyJiMAHQMmrABIAVALIAZAIJMowAEaMkXADwady0QFEANkhBIWMAHxwAZHADeFOHAAFkSYAPwAXHD0LAAmSJjALEgxANwUAL5p5BTUcLosaIHQ7JK8AkL5hdASENwycuiKlUVQVnoGxqYWbc3QDk4u7l6+-kEhEXBcMIYsAOZZmRQ5NACSLGCMlBCMG-C1MMCsPOT8gnAA8gBuSFD2ECgx9X7kAQAUHLVckTasNdwAlJEAFIAZQAGgp+s5XFk3h9uJFelA-lxAXBQRCoYMFlllnAAOL0FBQR7MOCFJBoADWcGAmDG8TgSAAHsAplJEiVPhQ0Ed4IEUFxVCF6u9JN8RL9JHAAD55AotFFo+EcqRIlEyNyjABEwXi2tpbBVuKoNAAwrhIElXDy+cIVCxIlcbncHqKVRKHRq5erJP9NSMXnBcigFcUiLEbqM6XBXgKhSExZ9-v6iDB6FA2OYUL4FHmVelg25YcGaCYHXAI3EoKM0xms+XRLn85JC5RixkTbkAKpcFCzJAUTDRDCHNi6MBgV7+54BOuZ2OjALmLVBgIBHyUABUcEAvBuAOD28vZ7HBZhAII8t5R0kv1+YfmwYMSBzBpNqAPpGeyhqkGvWYN9AiYBFqAAd3AhQzwgWZHAUXkQG1Vd12QuB1DMGBb2XSgHyQlDNx3XdAFo9uBbCgHAoAAGjgAADGI2RQL9kmouAYggMxXCZVkpjgVg4FDKooCZRxoXgK8bzXO8HxY+jGMef832ZRDMPXNCpmU8xsMlFhcKw3D-gWIA\">View in the TypeScript Playground</a></p>\n<p>Components, and JSX in general, are analogous to functions. When a component can render differently based on their props, it's similar to how a function can be overloaded to have multiple call signatures. In the same way, you can overload a function component's call signature to list all of its different \"versions\".</p>\n<p>A very common use case for this is to render something as either a button or an anchor, based on if it receives a <code class=\"language-text\">href</code> attribute.</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">ButtonProps</span> <span class=\"token operator\">=</span> <span class=\"token constant\">JSX</span><span class=\"token punctuation\">.</span>IntrinsicElements<span class=\"token punctuation\">[</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">AnchorProps</span> <span class=\"token operator\">=</span> <span class=\"token constant\">JSX</span><span class=\"token punctuation\">.</span>IntrinsicElements<span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// optionally use a custom type guard</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">isPropsForAnchorElement</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> ButtonProps <span class=\"token operator\">|</span> AnchorProps<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> props <span class=\"token keyword\">is</span> AnchorProps <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token string\">'href'</span> <span class=\"token keyword\">in</span> props<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Clickable</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> ButtonProps <span class=\"token operator\">|</span> AnchorProps<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">isPropsForAnchorElement</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>a</span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>They don't even need to be completely different props, as long as they have at least one difference in properties:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">LinkProps</span> <span class=\"token operator\">=</span> Omit<span class=\"token operator\">&lt;</span><span class=\"token constant\">JSX</span><span class=\"token punctuation\">.</span>IntrinsicElements<span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'href'</span><span class=\"token operator\">></span> <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">{</span> to<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token builtin\">string</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">RouterLink</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> LinkProps <span class=\"token operator\">|</span> AnchorProps<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'href'</span> <span class=\"token keyword\">in</span> props<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>a</span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Link</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<details>\n  <summary>\n<b>Approach: Generic Components</b>\n</summary>\n<p>Here is an example solution, see the further discussion for other solutions. <em>thanks to <a href=\"https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/issues/12#issuecomment-394440577\">@jpavon</a></em></p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">LinkProps</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">AnchorProps</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span>AnchorHTMLAttributes<span class=\"token operator\">&lt;</span>HTMLAnchorElement<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">RouterLinkProps</span> <span class=\"token operator\">=</span> Omit<span class=\"token operator\">&lt;</span>NavLinkProps<span class=\"token punctuation\">,</span> <span class=\"token string\">'href'</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> Link <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span> <span class=\"token keyword\">extends</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> LinkProps <span class=\"token operator\">&amp;</span> <span class=\"token constant\">T</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">RouterLinkProps</span> <span class=\"token operator\">?</span> RouterLinkProps <span class=\"token operator\">:</span> AnchorProps<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>props <span class=\"token keyword\">as</span> RouterLinkProps<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>to<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">NavLink</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token punctuation\">(</span>props <span class=\"token keyword\">as</span> RouterLinkProps<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>a</span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token punctuation\">(</span>props <span class=\"token keyword\">as</span> AnchorProps<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>Link<span class=\"token operator\">&lt;</span>RouterLinkProps<span class=\"token operator\">></span> to<span class=\"token operator\">=</span><span class=\"token string\">\"/\"</span><span class=\"token operator\">></span>My link<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Link</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ok</span>\n<span class=\"token operator\">&lt;</span>Link<span class=\"token operator\">&lt;</span>AnchorProps<span class=\"token operator\">></span> href<span class=\"token operator\">=</span><span class=\"token string\">\"/\"</span><span class=\"token operator\">></span>My link<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Link</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ok</span>\n<span class=\"token operator\">&lt;</span>Link<span class=\"token operator\">&lt;</span>RouterLinkProps<span class=\"token operator\">></span> to<span class=\"token operator\">=</span><span class=\"token string\">\"/\"</span> href<span class=\"token operator\">=</span><span class=\"token string\">\"/\"</span><span class=\"token operator\">></span>\n    My link\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Link</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// error</span></code></pre></div>\n</details>\n<details>\n  <summary>\n<b>Approach: Composition</b>\n</summary>\n<p>If you want to conditionally render a component, sometimes is better to use <a href=\"https://reactjs.org/docs/composition-vs-inheritance.html\">React's composition model</a> to have simpler components and better to understand typings:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">AnchorProps</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span>AnchorHTMLAttributes<span class=\"token operator\">&lt;</span>HTMLAnchorElement<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">RouterLinkProps</span> <span class=\"token operator\">=</span> Omit<span class=\"token operator\">&lt;</span>AnchorProps<span class=\"token punctuation\">,</span> <span class=\"token string\">'href'</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">interface</span> <span class=\"token class-name\">Button</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">as</span><span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ComponentClass <span class=\"token operator\">|</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> Button<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>FunctionComponent<span class=\"token operator\">&lt;</span>Button<span class=\"token operator\">></span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">as</span><span class=\"token operator\">:</span> Component<span class=\"token punctuation\">,</span> children<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Component</span></span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Component</span></span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> AnchorButton<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>FunctionComponent<span class=\"token operator\">&lt;</span>AnchorProps<span class=\"token operator\">></span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Button</span></span> <span class=\"token attr-name\">as</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>a<span class=\"token punctuation\">\"</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> LinkButton<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>FunctionComponent<span class=\"token operator\">&lt;</span>RouterLinkProps<span class=\"token operator\">></span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Button</span></span> <span class=\"token attr-name\">as</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>NavLink<span class=\"token punctuation\">}</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">LinkButton</span></span> <span class=\"token attr-name\">to</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>/login<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Login</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">LinkButton</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">AnchorButton</span></span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>/login<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Login</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">AnchorButton</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">AnchorButton</span></span> <span class=\"token attr-name\">href</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>/login<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">to</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>/test<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    Login\n</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">AnchorButton</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Error: Property 'to' does not exist on type...</span></code></pre></div>\n</details>\n<p>You may also want to use Discriminated Unions, please check out <a href=\"https://blog.andrewbran.ch/expressive-react-component-apis-with-discriminated-unions/\">Expressive React Component APIs with Discriminated Unions</a>.</p>\n<p>Here is a brief intuition for <strong>Discriminated Union Types</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">UserTextEvent</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    type<span class=\"token operator\">:</span> <span class=\"token string\">'TextEvent'</span><span class=\"token punctuation\">;</span>\n    value<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n    target<span class=\"token operator\">:</span> HTMLInputElement<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">UserMouseEvent</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    type<span class=\"token operator\">:</span> <span class=\"token string\">'MouseEvent'</span><span class=\"token punctuation\">;</span>\n    value<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token builtin\">number</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    target<span class=\"token operator\">:</span> HTMLElement<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">UserEvent</span> <span class=\"token operator\">=</span> UserTextEvent <span class=\"token operator\">|</span> UserMouseEvent<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">handle</span><span class=\"token punctuation\">(</span>event<span class=\"token operator\">:</span> UserEvent<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>type <span class=\"token operator\">===</span> <span class=\"token string\">'TextEvent'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        event<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span> <span class=\"token comment\">// string</span>\n        event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">;</span> <span class=\"token comment\">// HTMLInputElement</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    event<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span> <span class=\"token comment\">// [number, number]</span>\n    event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">;</span> <span class=\"token comment\">// HTMLElement</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<details>\n  <summary>\n  Take care: TypeScript does not narrow the type of a Discriminated Union on the basis of typeof checks. The type guard has to be on the value of a key and not it's type.\n  </summary>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">UserTextEvent</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> value<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span> target<span class=\"token operator\">:</span> HTMLInputElement <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">UserMouseEvent</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> value<span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token builtin\">number</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">number</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> target<span class=\"token operator\">:</span> HTMLElement <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">UserEvent</span> <span class=\"token operator\">=</span> UserTextEvent <span class=\"token operator\">|</span> UserMouseEvent<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">handle</span><span class=\"token punctuation\">(</span>event<span class=\"token operator\">:</span> UserEvent<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> event<span class=\"token punctuation\">.</span>value <span class=\"token operator\">===</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        event<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span> <span class=\"token comment\">// string</span>\n        event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">;</span> <span class=\"token comment\">// HTMLInputElement | HTMLElement (!!!!)</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    event<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span> <span class=\"token comment\">// [number, number]</span>\n    event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">;</span> <span class=\"token comment\">// HTMLInputElement | HTMLElement (!!!!)</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The above example does not work as we are not checking the value of <code class=\"language-text\">event.value</code> but only it's type. Read more about it <a href=\"https://github.com/microsoft/TypeScript/issues/30506#issuecomment-474858198\">microsoft/TypeScript#30506 (comment)</a></p>\n</details>\n<details>\n  <summary>\n  Discriminated Unions in TypeScript can also work with hook dependencies in React. The type matched is automatically updated when the corresponding union member based on which a hook depends, changes. Expand more to see an example usecase.\n   <br/>\n<br/>\n  </summary>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">SingleElement</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    isArray<span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n    value<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">MultiElement</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    isArray<span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    value<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">Props</span> <span class=\"token operator\">=</span> SingleElement <span class=\"token operator\">|</span> MultiElement<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Sequence</span><span class=\"token punctuation\">(</span>p<span class=\"token operator\">:</span> Props<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useMemo</span><span class=\"token punctuation\">(</span>\n        <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n            <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n                value(s):\n                </span><span class=\"token punctuation\">{</span>p<span class=\"token punctuation\">.</span>isArray <span class=\"token operator\">&amp;&amp;</span> p<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n                </span><span class=\"token punctuation\">{</span><span class=\"token operator\">!</span>p<span class=\"token punctuation\">.</span>isArray <span class=\"token operator\">&amp;&amp;</span> p<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span>p<span class=\"token punctuation\">.</span>isArray<span class=\"token punctuation\">,</span> p<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">]</span> <span class=\"token comment\">// TypeScript automatically matches the corresponding value type based on dependency change</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Sequence</span></span> <span class=\"token attr-name\">isArray</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">}</span></span> <span class=\"token attr-name\">value</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Sequence</span></span> <span class=\"token attr-name\">isArray</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">}</span></span> <span class=\"token attr-name\">value</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">[</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bar'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'baz'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<a href=\"https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQdMAnmFnAArFjoC8dccAD5wA3vwETgqAIJQoyJgC44MKAFcs9CRIBuyADYblqVcAB2AcwDaAXRpxxAgL7jhY7QKmz5SuAQOomo66BkZwJlDmFloSTvS4EGYmcAAacDxwABRgypwQ3ACU6QB8ouKUMGpQZphUMAB0aoEAslggEJnBmUU8pZ0ecAA8ACbAOsXB2nqGWJmoBYqTEiJg9V5yCnAAZFtwq9Ma9QBWEOaZZAA0ZAUuAwIiAISr6z7bu-uhWLcegwD0o+NggULsErM8ZBsmBc9vUDlgbNDfr84AAVFhYVC4SJgeDINQwEjIGDAXAGfRMOAgIm4AAWGJUdLgCTkGMgZlGljgcJU6PEBXocToBDUZnwwEScGkYDA3TKAgqVRq-QkIzGTP0aFQADlkCAsDwAERSsAGiYDQZpF4KHgifz6QJOLmfG1kAgQCBkR2-M0-S0Qnw21QaR1wm1WV3uy7kABGyCgUbIsYAXmQbF6fQI-gCffy6E4gA\">\n<i>See this in TS Playground</i>\n</a>\n<p>In the above example, based on the <code class=\"language-text\">isArray</code> union member, the type of the <code class=\"language-text\">value</code> hook dependency changes.</p>\n </details>\n<p>To streamline this you may also combine this with the concept of <strong>User-Defined Type Guards</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\"><span class=\"token keyword\">function</span> <span class=\"token function\">isString</span><span class=\"token punctuation\">(</span>a<span class=\"token operator\">:</span> <span class=\"token builtin\">unknown</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> a <span class=\"token keyword\">is</span> <span class=\"token builtin\">string</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">typeof</span> a <span class=\"token operator\">===</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards\">Read more about User-Defined Type Guards in the Handbook</a>.</p>\n<h2>Props: One or the Other but not Both</h2>\n<p>Use the <code class=\"language-text\">in</code> keyword, function overloading, and union types to make components that take either one or another sets of props, but not both:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">Props1</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> foo<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">Props2</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> bar<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">MyComponent</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> Props1 <span class=\"token operator\">|</span> Props2<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'foo'</span> <span class=\"token keyword\">in</span> props<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// props.bar // error</span>\n        <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>foo<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// props.foo // error</span>\n        <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>bar<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> UsageComponent<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">FC</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">MyComponent</span></span> <span class=\"token attr-name\">foo</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>foo<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">MyComponent</span></span> <span class=\"token attr-name\">bar</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>bar<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n        </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/* &lt;MyComponent foo=\"foo\" bar=\"bar\"/> // invalid */</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><a href=\"https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoCmATzCTgAUcwBnARjgF44BvOTCBABccFjCjAAdgHM4AXwDcVWvSYRWAJi684AIxRQRYiTPlLK5TAFdJGYBElwAstQDCuSJKSSYACjDMLCJqrBwAPoyBGgCUvBRwcMCYcL4ARAIQqYmOAeossTzxCXAA9CVwuawAdPpQpeVIUDhQRQlEMFZQjgA8ACbAAG4AfDyVLFUZct0l-cPmCXJwSAA2LPSF5MX1FYETgtuNza1w7Z09syNjNQZTM4ND8-IUchRoDmJwAKosKNJI7uAHN4YCJkOgYFUAGKubS+WKcIYpIp9e7HbouAGeYH8QScdKCLIlIZojEeIE+PQGPG1QnEzbFHglABUcHRbjJXgpGTxGSytWpBlSRO2UgGKGWwF6cCZJRe9OmFwo0QUQA\">View in the TypeScript Playground</a></p>\n<p>Further reading: <a href=\"http://www.javiercasas.com/articles/typescript-impossible-states-irrepresentable\">how to ban passing <code class=\"language-text\">{}</code> if you have a <code class=\"language-text\">NoFields</code> type.</a></p>\n<h2>Props: Must Pass Both</h2>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">OneOrAnother<span class=\"token operator\">&lt;</span><span class=\"token constant\">T1</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">T2</span><span class=\"token operator\">></span></span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">T1</span> <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span><span class=\"token constant\">K</span> <span class=\"token keyword\">in</span> <span class=\"token keyword\">keyof</span> <span class=\"token constant\">T2</span><span class=\"token punctuation\">]</span><span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token keyword\">undefined</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">|</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">T2</span> <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span><span class=\"token constant\">K</span> <span class=\"token keyword\">in</span> <span class=\"token keyword\">keyof</span> <span class=\"token constant\">T1</span><span class=\"token punctuation\">]</span><span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token keyword\">undefined</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">Props</span> <span class=\"token operator\">=</span> OneOrAnother<span class=\"token operator\">&lt;</span><span class=\"token punctuation\">{</span> a<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span> b<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> a<span class=\"token operator\">:</span> Props <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> a<span class=\"token operator\">:</span> <span class=\"token string\">'a'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// error</span>\n<span class=\"token keyword\">const</span> b<span class=\"token operator\">:</span> Props <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> b<span class=\"token operator\">:</span> <span class=\"token string\">'b'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// error</span>\n<span class=\"token keyword\">const</span> ab<span class=\"token operator\">:</span> Props <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> a<span class=\"token operator\">:</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> b<span class=\"token operator\">:</span> <span class=\"token string\">'b'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ok</span></code></pre></div>\n<p>Thanks <a href=\"https://twitter.com/kentcdodds/status/1085655423611367426\">diegohaz</a></p>\n<h2>Props: Pass One ONLY IF the Other Is Passed</h2>\n<p>Say you want a Text component that gets truncated if <code class=\"language-text\">truncate</code> prop is passed but expands to show the full text when <code class=\"language-text\">expanded</code> prop is passed (e.g. when the user clicks the text).</p>\n<p>You want to allow <code class=\"language-text\">expanded</code> to be passed only if <code class=\"language-text\">truncate</code> is also passed, because there is no use for <code class=\"language-text\">expanded</code> if the text is not truncated.</p>\n<p>Usage example:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">const</span> App<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">FC</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/* these all typecheck */</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Text</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">not truncated</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Text</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Text</span></span> <span class=\"token attr-name\">truncate</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">truncated</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Text</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Text</span></span> <span class=\"token attr-name\">truncate</span> <span class=\"token attr-name\">expanded</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            truncate-able but expanded\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Text</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token punctuation\">{</span><span class=\"token comment\">/* TS error: Property 'truncate' is missing in type '{ children: string; expanded: true; }' but required in type '{ truncate: true; expanded?: boolean | undefined; }'. */</span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Text</span></span> <span class=\"token attr-name\">expanded</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">truncate-able but expanded</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span><span class=\"token class-name\">Text</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span></span><span class=\"token punctuation\">></span></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can implement this by function overloads:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">type</span> <span class=\"token class-name\">CommonProps</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    children<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n    miscProps<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token builtin\">any</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">NoTruncateProps</span> <span class=\"token operator\">=</span> CommonProps <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">{</span> truncate<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">TruncateProps</span> <span class=\"token operator\">=</span> CommonProps <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">{</span> truncate<span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span> expanded<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token builtin\">boolean</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Function overloads to accept both prop types NoTruncateProps &amp; TruncateProps</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Text</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> NoTruncateProps<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSX</span><span class=\"token punctuation\">.</span>Element<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Text</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> TruncateProps<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSX</span><span class=\"token punctuation\">.</span>Element<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Text</span><span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> CommonProps <span class=\"token operator\">&amp;</span> <span class=\"token punctuation\">{</span> truncate<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token builtin\">boolean</span><span class=\"token punctuation\">;</span> expanded<span class=\"token operator\">?</span><span class=\"token operator\">:</span> <span class=\"token builtin\">boolean</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> children<span class=\"token punctuation\">,</span> truncate<span class=\"token punctuation\">,</span> expanded<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>otherProps <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> classNames <span class=\"token operator\">=</span> truncate <span class=\"token operator\">?</span> <span class=\"token string\">'.truncate'</span> <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>classNames<span class=\"token punctuation\">}</span></span> <span class=\"token attr-name\">aria-expanded</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token operator\">!</span><span class=\"token operator\">!</span>expanded<span class=\"token punctuation\">}</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>otherProps<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Props: Omit prop from a type</h2>\n<p>Note: <a href=\"https://www.typescriptlang.org/docs/handbook/utility-types.html#omittk\">Omit was added as a first class utility in TS 3.5</a>! 🎉</p>\n<p>Sometimes when intersecting types, we want to define our own version of a prop. For example, I want my component to have a <code class=\"language-text\">label</code>, but the type I am intersecting with also has a <code class=\"language-text\">label</code> prop. Here's how to extract that out:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">Props</span> <span class=\"token punctuation\">{</span>\n    label<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span> <span class=\"token comment\">// this will conflict with the InputElement's label</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// this comes inbuilt with TS 3.5</span>\n<span class=\"token keyword\">type</span> <span class=\"token class-name\">Omit<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">K</span> <span class=\"token keyword\">extends</span> <span class=\"token keyword\">keyof</span> <span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token operator\">=</span> Pick<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token punctuation\">,</span> Exclude<span class=\"token operator\">&lt;</span><span class=\"token keyword\">keyof</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">K</span><span class=\"token operator\">>></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// usage</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> Checkbox <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> Props <span class=\"token operator\">&amp;</span> Omit<span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>HTMLProps<span class=\"token operator\">&lt;</span>HTMLInputElement<span class=\"token operator\">></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'label'</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> label <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>Checkbox<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>label</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>Checkbox-label<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n                </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>input</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>checkbox<span class=\"token punctuation\">\"</span></span> <span class=\"token spread\"><span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>label</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>span</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>label<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>span</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>When your component defines multiple props, chances of those conflicts increase. However you can explicitly state that all your fields should be removed from the underlying component using the <code class=\"language-text\">keyof</code> operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">Props</span> <span class=\"token punctuation\">{</span>\n    label<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span> <span class=\"token comment\">// conflicts with the InputElement's label</span>\n    <span class=\"token function-variable function\">onChange</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>text<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">void</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// conflicts with InputElement's onChange</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Textbox</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> Props <span class=\"token operator\">&amp;</span> Omit<span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>HTMLProps<span class=\"token operator\">&lt;</span>HTMLInputElement<span class=\"token operator\">></span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">keyof</span> Props<span class=\"token operator\">></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// implement Textbox component ...</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>As you can see from the Omit example above, you can write significant logic in your types as well. <a href=\"https://github.com/pelotom/type-zoo\">type-zoo</a> is a nice toolkit of operators you may wish to check out (includes Omit), as well as <a href=\"https://github.com/piotrwitek/utility-types\">utility-types</a> (especially for those migrating from Flow).</p>\n<h2>Props: Extracting Prop Types of a Component</h2>\n<p>Sometimes you want the prop types of a component, but it isn't exported.</p>\n<p>A simple solution is to use <code class=\"language-text\">React.ComponentProps</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token comment\">// a Modal component defined elsewhere</span>\n<span class=\"token keyword\">const</span> defaultProps<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ComponentProps<span class=\"token operator\">&lt;</span><span class=\"token keyword\">typeof</span> Modal<span class=\"token operator\">></span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    title<span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">,</span>\n    visible<span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n    onClick<span class=\"token operator\">:</span> jest<span class=\"token punctuation\">.</span><span class=\"token function\">fn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>There are advanced edge cases if you want to extract the prop types of a component taking into account internal props, <code class=\"language-text\">propTypes</code>, and <code class=\"language-text\">defaultProps</code> - <a href=\"https://github.com/typescript-cheatsheets/react/issues/63\">check our issue here for helper utilities that resolve these</a>.</p>\n<h2>Props: Render Props</h2>\n<blockquote>\n<p>Advice: Where possible, you should try to use Hooks instead of Render Props. We include this merely for completeness.</p>\n</blockquote>\n<p>Sometimes you will want to write a function that can take a React element or a string or something else as a prop. The best Type to use for such a situation is <code class=\"language-text\">React.ReactNode</code> which fits anywhere a normal, well, React Node would fit:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">Props</span> <span class=\"token punctuation\">{</span>\n    label<span class=\"token operator\">?</span><span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n    children<span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Card</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token operator\">:</span> Props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>label <span class=\"token operator\">&amp;&amp;</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>label<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n            </span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If you are using a function-as-a-child render prop:</p>\n<div class=\"gatsby-highlight\" data-language=\"tsx\"><pre class=\"language-tsx\"><code class=\"language-tsx\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">interface</span> <span class=\"token class-name\">Props</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>foo<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/issues/new/choose\">Something to add? File an issue</a>.</p>\n<h2>Handling Exceptions</h2>\n<p>You can provide good information when bad things happen.</p>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">InvalidDateFormatError</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">RangeError</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">DateIsInFutureError</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">RangeError</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/**\n * // optional docblock\n * @throws {InvalidDateFormatError} The user entered date incorrectly\n * @throws {DateIsInFutureError} The user entered date in future\n *\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>date<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">isValid</span><span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">InvalidDateFormatError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'not a valid date format'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">isInFuture</span><span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">DateIsInFutureError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'date is in the future'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// call parse(date) somewhere</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">InvalidDateFormatError</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'invalid date format'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">DateIsInFutureError</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">warn</span><span class=\"token punctuation\">(</span><span class=\"token string\">'date is in future'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">throw</span> e<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoCtAGxQGc64BJAOwDcVrgATAERRhIAYtBACAolBxQ4SAB6CW3RghQsA5kknS4AbwC+VWgzj9BTOqyEBXGNaLboshUiUq1mxzIMUKmaywYwBAscMB0AGqcPAAU3AJIAFxwdDBQwBoAlHoUcHBEdlCh8YJwAPxwadZIcMmYnHRIANwUhpTk-oEwwaHhVrb2SHEJyanpWTnkeWghqXAlSAByEADucAC8cCxIa2ZDmS1TcDMsc2j2RCwwextbO6YJw4KZuXCvBfah51Ku1wkAdJoYAAVUD7OAAPnmCWWK0BSBBYJiB1avnIAHoAFSY3KYuDo9FwCBgbohTjzCBoABG1EpAGtcXAAAIwAAWOBWjF0rA4XD4CREUDEMC8+jgwNZNWsjRkvyQRG40NKGRmPww1AAnoyWezVly9hZ+oUtFJoGKJVKZbIrvKkIqFmFQv5jbjcei-AEgiE4GAUFBGk8kik0hl1NldK9gJg4DEAIThKJ8wOZF5HPJsjl3NY86L8wSC4VeGIAIhYEHgKDgvJ4SpqmFEAmLKKOUZjfRYNmNyeyGdWWYe5ksHYGDlNUBLDvCjsqkrgzsGTcOeQJcH+a9R7TSGsmy8JaE41B9foDC2ydFwO0lRFaxwEaFZMaQ4cj0ZiNQyqTUaCQEGjOb5ewFhIY7PmmxyzBA1BIP88rSCWGTVvaCRzg2MDFgANLIzZ5GKSDUI0YSvu+pwwF+P7RgaQ6doMXigXk0wQVB-wrH6LATshU4ZHOI5IBhWFLnAuH4TUEZgb2azNK8bT6EAA\">View in TypeScript Playground</a></p>\n<p>Simply throwing an exception is fine, however it would be nice to make TypeScript remind the consumer of your code to handle your exception. We can do that just by returning instead of throwing:</p>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\"><span class=\"token keyword\">function</span> <span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>date<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> Date <span class=\"token operator\">|</span> InvalidDateFormatError <span class=\"token operator\">|</span> DateIsInFutureError <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">isValid</span><span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">InvalidDateFormatError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'not a valid date format'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">isInFuture</span><span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">DateIsInFutureError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'date is in the future'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// now consumer *has* to handle the errors</span>\n<span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token function\">parse</span><span class=\"token punctuation\">(</span><span class=\"token string\">'mydate'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>result <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">InvalidDateFormatError</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'invalid date format'</span><span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>result <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">DateIsInFutureError</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">warn</span><span class=\"token punctuation\">(</span><span class=\"token string\">'date is in future'</span><span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">/// use result safely</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// alternately you can just handle all errors</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>result <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token builtin\">console</span><span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'error'</span><span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">/// use result safely</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>You can also describe exceptions with special-purpose data types (don't say monads...) like the <code class=\"language-text\">Try</code>, <code class=\"language-text\">Option</code> (or <code class=\"language-text\">Maybe</code>), and <code class=\"language-text\">Either</code> data types:</p>\n<div class=\"gatsby-highlight\" data-language=\"ts\"><pre class=\"language-ts\"><code class=\"language-ts\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">Option<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token generic-function\"><span class=\"token function\">flatMap</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token function-variable function\">f</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> None<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> None<span class=\"token punctuation\">;</span>\n    <span class=\"token generic-function\"><span class=\"token function\">flatMap</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token function-variable function\">f</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> Option<span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> FormikOption<span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">getOrElse</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Some<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token keyword\">implements</span> <span class=\"token class-name\">Option<span class=\"token operator\">&lt;</span><span class=\"token constant\">T</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">private</span> value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token generic-function\"><span class=\"token function\">flatMap</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token function-variable function\">f</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> None<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> None<span class=\"token punctuation\">;</span>\n    <span class=\"token generic-function\"><span class=\"token function\">flatMap</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token function-variable function\">f</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> Some<span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> Some<span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token generic-function\"><span class=\"token function\">flatMap</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token function-variable function\">f</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> Option<span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> Option<span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">getOrElse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token constant\">T</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">None</span> <span class=\"token keyword\">implements</span> <span class=\"token class-name\">Option<span class=\"token operator\">&lt;</span><span class=\"token builtin\">never</span><span class=\"token operator\">></span></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token generic-function\"><span class=\"token function\">flatMap</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> None <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token generic-function\"><span class=\"token function\">getOrElse</span><span class=\"token generic class-name\"><span class=\"token operator\">&lt;</span><span class=\"token constant\">U</span><span class=\"token operator\">></span></span></span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> <span class=\"token constant\">U</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token constant\">U</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// now you can use it like:</span>\n<span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token function\">Option</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// Some&lt;number></span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">flatMap</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">Option</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">*</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// Some&lt;number></span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">flatMap</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">None</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// None</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">getOrElse</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// or:</span>\n<span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token function\">ask</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// Option&lt;string></span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">flatMap</span><span class=\"token punctuation\">(</span>parse<span class=\"token punctuation\">)</span> <span class=\"token comment\">// Option&lt;Date></span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">flatMap</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Some</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">toISOString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// Option&lt;string></span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">getOrElse</span><span class=\"token punctuation\">(</span><span class=\"token string\">'error parsing string'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/docs/reference/intro-to-nodejs/","relativePath":"docs/reference/intro-to-nodejs.md","relativeDir":"docs/reference","base":"intro-to-nodejs.md","name":"intro-to-nodejs","frontmatter":{"title":"Intro To NodeJS","weight":0,"excerpt":"A Node.js app runs in a single process, without creating a new thread for every request.","seo":{"title":"Intro To NodeJS","description":"Node.js is an open-source and cross-platform JavaScript runtime environment. It is a popular tool for almost any kind of project!","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Enter the NodeJS</h2>\n<p>Node.js is an open-source and cross-platform JavaScript runtime environment. It is a popular tool for almost any kind of project!</p>\n<p>Node.js runs the V8 JavaScript engine, the core of Google Chrome, outside of the browser. This allows Node.js to be very performant.</p>\n<p>A Node.js app runs in a single process, without creating a new thread for every request. Node.js provides a set of asynchronous I/O primitives in its standard library that prevent JavaScript code from blocking and generally, libraries in Node.js are written using non-blocking paradigms, making blocking behavior the exception rather than the norm.</p>\n<p>When Node.js performs an I/O operation, like reading from the network, accessing a database or the filesystem, instead of blocking the thread and wasting CPU cycles waiting, Node.js will resume the operations when the response comes back.</p>\n<p>This allows Node.js to handle thousands of concurrent connections with a single server without introducing the burden of managing thread concurrency, which could be a significant source of bugs.</p>\n<p>Node.js has a unique advantage because millions of frontend developers that write JavaScript for the browser are now able to write the server-side code in addition to the client-side code without the need to learn a completely different language.</p>\n<p>In Node.js the new ECMAScript standards can be used without problems, as you don't have to wait for all your users to update their browsers - you are in charge of deciding which ECMAScript version to use by changing the Node.js version, and you can also enable specific experimental features by running Node.js with flags.</p>\n<h2><a href=\"https://nodejs.dev/learn#a-vast-number-of-libraries\"></a>A Vast Number of Libraries</h2>\n<p>npm with its simple structure helped the ecosystem of Node.js proliferate, and now the npm registry hosts over 1,000,000 open source packages you can freely use.</p>\n<h2><a href=\"https://nodejs.dev/learn#an-example-nodejs-application\"></a>An Example Node.js Application</h2>\n<p>The most common example Hello World of Node.js is a web server:</p>\n<p>This code first includes the Node.js <a href=\"https://nodejs.org/api/http.html\"><code class=\"language-text\">http</code> module</a>.</p>\n<p>Node.js has a fantastic <a href=\"https://nodejs.org/api/\">standard library</a>, including first-class support for networking.</p>\n<p>The <code class=\"language-text\">createServer()</code> method of <code class=\"language-text\">http</code> creates a new HTTP server and returns it.</p>\n<p>The server is set to listen on the specified port and host name. When the server is ready, the callback function is called, in this case informing us that the server is running.</p>\n<p>Whenever a new request is received, the <a href=\"https://nodejs.org/api/http.html#http_event_request\"><code class=\"language-text\">request</code> event</a> is called, providing two objects: a request (an <a href=\"https://nodejs.org/api/http.html#http_class_http_incomingmessage\"><code class=\"language-text\">http.IncomingMessage</code></a> object) and a response (an <a href=\"https://nodejs.org/api/http.html#http_class_http_serverresponse\"><code class=\"language-text\">http.ServerResponse</code></a> object).</p>\n<p>Those 2 objects are essential to handle the HTTP call.</p>\n<p>The first provides the request details. In this simple example, this is not used, but you could access the request headers and request data.</p>\n<p>The second is used to return data to the caller.</p>\n<p>In this case with:</p>\n<p>JScopy</p>\n<p>res.statusCode = 200</p>\n<p>we set the statusCode property to 200, to indicate a successful response.</p>\n<p>We set the Content-Type header:</p>\n<p>JScopy</p>\n<p>res.setHeader('Content-Type', 'text/plain')</p>\n<p>and we close the response, adding the content as an argument to <code class=\"language-text\">end()</code>:</p>\n<p>JScopy</p>\n<p>res.end('Hello World\\n')</p>\n<h2><a href=\"https://nodejs.dev/learn#nodejs-frameworks-and-tools\"></a>Node.js Frameworks and Tools</h2>\n<p>Node.js is a low-level platform. In order to make things easy and exciting for developers, thousands of libraries were built upon Node.js by the community.</p>\n<p>Many of those established over time as popular options. Here is a non-comprehensive list of the ones worth learning:</p>\n<ul>\n<li><a href=\"https://adonisjs.com/\"><strong>AdonisJS</strong></a>: A TypeScript-based fully featured framework highly focused on developer ergonomics, stability, and confidence. Adonis is one of the fastest Node.js web frameworks.</li>\n<li><a href=\"https://eggjs.org/en/\"><strong>Egg.js</strong></a>: A framework to build better enterprise frameworks and apps with Node.js &#x26; Koa.</li>\n<li><a href=\"https://expressjs.com/\"><strong>Express</strong></a>: It provides one of the most simple yet powerful ways to create a web server. Its minimalist approach, unopinionated, focused on the core features of a server, is key to its success.</li>\n<li><a href=\"https://fastify.io/\"><strong>Fastify</strong></a>: A web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture. Fastify is one of the fastest Node.js web frameworks.</li>\n<li><a href=\"https://feathersjs.com/\"><strong>FeatherJS</strong></a>: Feathers is a lightweight web-framework for creating real-time applications and REST APIs using JavaScript or TypeScript. Build prototypes in minutes and production-ready apps in days.</li>\n<li><a href=\"https://www.gatsbyjs.com/\"><strong>Gatsby</strong></a>: A <a href=\"https://reactjs.org/\">React</a>-based, <a href=\"https://graphql.org/\">GraphQL</a> powered, static site generator with a very rich ecosystem of plugins and starters.</li>\n<li><a href=\"https://hapijs.com/\"><strong>hapi</strong></a>: A rich framework for building applications and services that enables developers to focus on writing reusable application logic instead of spending time building infrastructure.</li>\n<li><a href=\"http://koajs.com/\"><strong>koa</strong></a>: It is built by the same team behind Express, aims to be even simpler and smaller, building on top of years of knowledge. The new project born out of the need to create incompatible changes without disrupting the existing community.</li>\n<li><a href=\"https://loopback.io/\"><strong>Loopback.io</strong></a>: Makes it easy to build modern applications that require complex integrations.</li>\n<li><a href=\"https://meteor.com/\"><strong>Meteor</strong></a>: An incredibly powerful full-stack framework, powering you with an isomorphic approach to building apps with JavaScript, sharing code on the client and the server. Once an off-the-shelf tool that provided everything, now integrates with frontend libs <a href=\"https://reactjs.org/\">React</a>, <a href=\"https://vuejs.org/\">Vue</a>, and <a href=\"https://angular.io/\">Angular</a>. Can be used to create mobile apps as well.</li>\n<li><a href=\"https://github.com/zeit/micro\"><strong>Micro</strong></a>: It provides a very lightweight server to create asynchronous HTTP microservices.</li>\n<li><a href=\"https://nestjs.com/\"><strong>NestJS</strong></a>: A TypeScript based progressive Node.js framework for building enterprise-grade efficient, reliable and scalable server-side applications.</li>\n<li><a href=\"https://nextjs.org/\"><strong>Next.js</strong></a>: <a href=\"https://reactjs.org/\">React</a> framework that gives you the best developer experience with all the features you need for production: hybrid static &#x26; server rendering, TypeScript support, smart bundling, route pre-fetching, and more.</li>\n<li><a href=\"https://nx.dev/\"><strong>Nx</strong></a>: A toolkit for full-stack monorepo development using NestJS, Express, <a href=\"https://reactjs.org/\">React</a>, <a href=\"https://angular.io/\">Angular</a>, and more! Nx helps scale your development from one team building one application to many teams collaborating on multiple applications!</li>\n<li><a href=\"https://sapper.svelte.dev/\"><strong>Sapper</strong></a>: Sapper is a framework for building web applications of all sizes, with a beautiful development experience and flexible filesystem-based routing. Offers SSR and more!</li>\n<li><a href=\"https://socket.io/\"><strong>Socket.io</strong></a>: A real-time communication engine to build network applications.</li>\n<li><a href=\"https://strapi.io/\"><strong>Strapi</strong></a>: Strapi is a flexible, open-source Headless CMS that gives developers the freedom to choose their favorite tools and frameworks while also allowing editors to easily manage and distribute their content. By making the admin panel and API extensible through a plugin system, Strapi enables the world's largest companies to accelerate content delivery while building beautiful digital experiences.</li>\n</ul>\n<h1>Extended Version:</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/nodejs-examples-4ohjz?autoresize=1&expanddevtools=1&fontsize=13&hidenavigation=1&theme=light&view=editor\"\n     style=\"width:100%; height:400px; border:2; border-radius: 15px; overflow:auto;resize:both;\"\n     title=\"nodejs-examples\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>\n<h1>Introduction to JavaScript</h1>\n<p>JavaScript is dynamically typed single-threaded interpreted languages for the Web. That means if you are doing web development, you can use this language to perform some operating on the web page, like running some JavaScript code when a button is clicked by the user.</p>\n<p>JavaScript is a dynamically typed language which means a variable can hold any data type like String or Number in its lifetime and JavaScript interpreter won't complain about it. It's single-threaded which means your JavaScript code runs synchronously or sequentially line by line. It's interpreted which means you don't need to compile your JavaScript code.</p>\n<p>JavaScript is interactive, which means you can directly feed JavaScript code to the interpreter and it will be executed immediately. You can try this by opening <a href=\"https://developers.google.com/web/tools/chrome-devtools/\">DevTools</a> in the browser (_in Chrome, press _<code class=\"language-text\">*command** + **option** + **i*</code>) or right-click anywhere on the page and click inspect. Then go to the console tab, here you can type any valid JavaScript code and press enter to run it. Use <code class=\"language-text\">shift + enter</code> to add a new-line in your code.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*iSdHW-r4lmJ41vrpm_0lxQ.png\" alt=\"medium blog image\"></p>\n<p>(interacting with JavaScript interpreter)</p>\n<p>Every browser ships a JavaScript Interpreter also called a JavaScript Engine. <a href=\"https://v8.dev/\">V8</a> is the JavaScript engine designed by Google and used in the Google Chrome browser while <a href=\"https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey\">SpiderMonkey</a> is a JavaScript engine developed by Mozilla for their Firefox browser.</p>\n<p>Since JavaScript engine designed by every browser is different, <a href=\"https://en.wikipedia.org/wiki/Ecma_International\">ECMA</a> standardizes features of JavaScript. This standard is known as <a href=\"https://en.wikipedia.org/wiki/ECMAScript\">ECMAScript</a> (<em>pronounced as ek-ma-script</em>). Whenever ECMA adds a feature to this JavaScript standard, the browser has to add it in their JavaScript engine to stay in the competition (<em>though this process is very slow</em>).</p>\n<p>JavaScript is a very easy language to learn and fun to write. Every year, new features are added to ECMAScript which brings JavaScript one more step closer to dominate the planet. The latest major revision of JavaScript is <a href=\"http://es6-features.org/\">ES6</a> or ECMAScript 6 or ECMAScript 2015 which has dumped a ton of features to make it more fun to code in. At the moment, JavaScript supports the OOP paradigm very well and can be used in functional programming as well.</p>\n<p><a href=\"https://en.wikipedia.org/wiki/Mozilla\">Mozilla</a> is an open-source foundation that documents JavaScript very well on their developer documentation AKA <a href=\"https://developer.mozilla.org/en-US/\">Mozilla Developer Network</a> or <a href=\"https://developer.mozilla.org/en-US/\">MDN</a>. It is one of the top online destinations to learn JavaScript, though there are other online resources as well. If you want to take a look at the JavaScript specifications and learn simple tutorials, visit <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript\">MDN Documentation</a>.</p>\n<p>JavaScript is sometimes abbreviated as JS or .js/.JS (<em>dot J S</em>) to state that an entity is related to JavaScript, like Node.js or ReactJS or AngularJS. But in no ways, JavaScript is related to Java, or so you think 👻. If you need a history lesson about JavaScript and its evolution, watch this amazing video.</p>\n<p><a href=\"https://www.youtube.com/watch?v=Sh6lK57Cuk4\">https://www.youtube.com/watch?v=Sh6lK57Cuk4</a></p>\n<p>Assuming that you are familiar with JavaScript and gained a good amount of knowledge, we can move forward. But if you don't know JavaScript at all, learn basic JavaScript from the MDN documentation I explained earlier. Because learning about Node.js without knowledge of JavaScript is like understanding web development without HTML.</p>\n<h1>What is server-side JavaScript?</h1>\n<p>JavaScript is a single-threaded language, it knows how to get things done one at a time. It can't do asynchronous tasks or run JavaScript code in multiple threads for efficiency. It just knows about JavaScript as defined in ECMAScript specification and nothing more.</p>\n<p>Since JavaScript is used on the web, it needs to be secure. Hence, using JavaScript, you can't access the computer it is running on, like File System, IO, Networking, etc. and neither ECMAScript has specifications for that.</p>\n<p>So it is up to the browser vendors to extend JavaScript engine with APIs that can do other things. For example, DOM API is responsible to print an HTML code into actual pixels on the screen, I have explained this process in <a href=\"https://itnext.io/how-the-browser-renders-a-web-page-dom-cssom-and-rendering-df10531c9969?source=your_stories_page---------------------------\">my Medium article</a>. Also, the <a href=\"https://javascript.info/xmlhttprequest\">XMLHttpRequest</a> API gives us the ability to send network requests to fetch data from a remote server in the background.</p>\n<p>These sorts of APIs are responsible to perform other operations that JavaScript is not designed to perform. These APIs are provided by the browser and they are called <a href=\"https://developer.mozilla.org/en-US/docs/Web/API\">Web APIs</a>. These APIs are written in some Low-Level languages like C or C++ but their interface is made available through JavaScript.</p>\n<p>These Web APIs sometimes do their job in separate thread allowing other JavaScript code to run normally while the job is running in the background. Once the job is done, it then informs the main JavaScript thread.</p>\n<blockquote>\n<p>So through JavaScript, you are executing C++ code and returning result back to the JavaScript, that doesn't sound so difficult.</p>\n</blockquote>\n<p>For example, <code class=\"language-text\">[setTimeout(callback, delay)](https://www.w3schools.com/jsref/met_win_settimeout.asp)</code> function is not part of ECMAScript specification, it is provided by the browser to perform an asynchronous operation. The <code class=\"language-text\">callback</code> function is executed in the main JavaScript thread once <code class=\"language-text\">delay</code> milliseconds has elapsed.</p>\n<p><img src=\"https://miro.medium.com/max/20/1*Lyq6NipNFEgLwjXs0-BDgA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/473/1*Lyq6NipNFEgLwjXs0-BDgA.png\" alt=\"medium blog image\"></p>\n<p>(an oversimplification of how JavaScript runs in a browser)</p>\n<p>So far we know that JavaScript is essential in a browser. But if you think about JavaScript engine alone, it can exist anywhere. You can take the V8 JavaScript engine and install it on your computer (<em>let's call it as a server</em>). With some fiddling, you can feed JavaScript code to it and it will run that code for you and may return the result. In theory, it looks pretty simple.</p>\n<p>The concept of server-side JavaScript comes from this simple idea. You can take any JavaScript engine, wrap inside an application that gives a clean interface to take the user's JavaScript code and execute it in the JavaScript engine. You can also provide APIs to perform operations like File System IO, Networking, etc. which do not run on JavaScript engine.</p>\n<p><img src=\"https://miro.medium.com/max/20/1*i1b-kgRTc9KPvHjvBifoyA.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/473/1*i1b-kgRTc9KPvHjvBifoyA.png\" alt=\"medium blog image\"></p>\n<p>(an oversimplification of how JavaScript runs on a server)</p>\n<p><a href=\"https://en.wikipedia.org/wiki/Ryan_Dahl\">Ryan Dahl</a> took this idea and made Node.js.</p>\n<blockquote>\n<p>To understand more about how a JavaScript engine works in a browser, you should read my article on <a href=\"https://itnext.io/how-javascript-works-in-browser-and-node-ab7d0d09ac2f\">How JavaScript engine works in browser and Node</a>. This article also explain concept of Web APIs in depth.</p>\n</blockquote>\n<h1>How Node.js works?</h1>\n<p>Sometimes, Node.js is also called simply Node or node.</p>\n<p>Node.js is a framework that contains the V8 JavaScript engine, the standard library of packages, and some binaries. In reality, it is more complex than that as explained in the below diagram (<em>follow the link for more details</em>).</p>\n<p><img src=\"https://miro.medium.com/max/405/1*iTdvBPVxYZdJZQKsP3yILw.jpeg\" alt=\"medium blog image\"></p>\n<p>(Source: <a href=\"https://stackoverflow.com/questions/36766696/which-is-correct-node-js-architecture\">Stackoverflow</a>)</p>\n<p>Like Web APIs in the browser, Node.js has a standard library that contains JavaScript packages (<em>we will learn about packages later</em>) which may also provide an interface to low-level APIs. For example, Node.js comes with <code class=\"language-text\">fs</code> package which contains <code class=\"language-text\">readFile</code> function among many. This function reads the file on the disk of the machine and returns file content back.</p>\n<p>Most of these packages contain code written in a low-level programming language to communicate with the device, like for file system access. These packages export JavaScript functions and other types to run this code. Since JavaScript can not talk to C++ or some other language, Node.js has to create a binding to facilitate this communication. The process to create such packages is very tricky, but it is explained <a href=\"https://medium.com/the-node-js-collection/native-extensions-for-node-js-767e221b3d26\">here</a> in-depth.</p>\n<p>Node.js uses different threads to perform low-level non-JavaScript time-taking operations. This way, our JavaScript is not blocked while a time taking operation like reading a file is in progress. Since these operations are running in the background once initiated, we need a confirmation or a callback when the operation is finished. This callback is a JavaScript function that will execute as soon as the operation is finished.</p>\n<p>const fs = require('fs'); // fs is built-in packagefs.readFile('/path/to/file.txt', function(error, data){<br>\n// if error is not empty, show error log<br>\n// read data and do something with it<br>\n});</p>\n<p>The Node.js architecture is very complex and made of different parts as seen in the earlier diagram. It also contains an event loop that facilitates the execution of these callback functions. You should watch the below video on the event loop, though it is in the context of the browser but things are pretty similar in Node.js as well. This will clear your remaining doubts.</p>\n<h1>Installing Node.js</h1>\n<p>You should install Node.js from their official website at <a href=\"https://nodejs.org/en/\">nodejs.org</a>. If you are using Windows, Mac OS, or Linux, you can get precompiled binaries and installers. The best way to go is by using an installer.</p>\n<p>When you install Node.js, you get <code class=\"language-text\">node</code> and <code class=\"language-text\">npm</code> binaries added to your path. That means, now you can use <code class=\"language-text\">node</code> and <code class=\"language-text\">npm</code> command. We will talk about <code class=\"language-text\">npm</code> later, but for now, let's focus on the <code class=\"language-text\">node</code>.</p>\n<p><img src=\"https://miro.medium.com/max/459/1*jjZ-5MLgkPDNd-6j6x52rQ.png\" alt=\"medium blog image\"></p>\n<p>Using <code class=\"language-text\">-v</code> or <code class=\"language-text\">--version</code> flag, we can check the version of the Node installed. The latest node will have the latest V8 engine, hence latest JavaScript features. If you need the flexibility to change Node version at any given time, in that case, you should not install Node.js using above method. Instead, you should use Node Version Manager or <a href=\"https://github.com/nvm-sh/nvm\">NVM</a>.</p>\n<blockquote>\n<p><a href=\"https://nodejs.org/en/download/releases/\">Here</a> is the list of Node.js releases with V8 engine versions.</p>\n</blockquote>\n<p>Like we saw in DevTools of the browser, using the simple command <code class=\"language-text\">node</code> will open a JavaScript interpreter in the terminal. This way we can run some simple JavaScript code to amuse yourself.</p>\n<p><img src=\"https://miro.medium.com/max/20/1*yfvMB7k2KBIylz_ISFUL-Q.png?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/459/1*yfvMB7k2KBIylz_ISFUL-Q.png\" alt=\"medium blog image\"></p>\n<p>(node interpreter)</p>\n<h1>Running JavaScript code with Node.js</h1>\n<p>Now that we have a good understanding of what Node.js is and how JavaScript engine works, we can start messing with it.</p>\n<p>Using an interpreter we can perform some basic arithmetics and other basic stuff. But most of the time, your actual JavaScript code will be in a <code class=\"language-text\">.js</code> file. Instead of giving one line at a time to the interpreter, we need to give whole file content at once. We can do that by using <code class=\"language-text\">node /path/to/file.js</code> command.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*UdmQcaaaqcGtbzgWUFtE2A.png\" alt=\"medium blog image\"></p>\n<p>(<a href=\"https://github.com/course-one/node-js-introduction/blob/master/hello-world.js\">hello-world.js</a>)</p>\n<p>In the above example, we have created <code class=\"language-text\">hello-world.js</code> file and it contains <code class=\"language-text\">hello</code> function. This function is executed after it was defined in the same file. Using the terminal, we executed <code class=\"language-text\">node ./hello-world.js</code> command. <code class=\"language-text\">node</code> will pick up <code class=\"language-text\">hello-world.js</code> file from the directory where the terminal is opened and run it using the V8 JavaScript engine.</p>\n<p>Since <code class=\"language-text\">node</code> can only execute <code class=\"language-text\">.js</code> files, adding <code class=\"language-text\">.js</code> extension to the file path is optional. If we provide a directory path instead of file path to <code class=\"language-text\">node</code>, Node.js will try to resolve <code class=\"language-text\">index.js</code> file inside that directory.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*J1cd4WNICvBUcuDpUfvecA.png\" alt=\"medium blog image\"></p>\n<p>(executing index.js in the current directory with Node)</p>\n<h1>Importing scripts in the program</h1>\n<p>Normally our application is broken down to different parts. For example, if a set of functions are used over and over, we would like them to be contained in a separate file and import that file wherever those functions are to be used.</p>\n<p>Node.js supports this functionality natively. When you import a file inside another file, that file is called a module. Node.js uses the CommonJS module system syntax to import modules and packages.</p>\n<blockquote>\n<p>Though <a href=\"https://medium.com/backticks-tildes/introduction-to-es6-modules-49956f580da\">ES6+</a> supports new module system, it is yet to be implemented in Node.</p>\n</blockquote>\n<p>Let's create a <code class=\"language-text\">lib</code> directory and place <code class=\"language-text\">math.js</code> file inside it. This file contains some common math functions like <code class=\"language-text\">add</code> and <code class=\"language-text\">multiply</code>. We will import this file inside <code class=\"language-text\">calculate.js</code> file situated in the main directory. Hence <code class=\"language-text\">math.js</code> is a module, since we are importing it and not executing it directly with Node.</p>\n<p>To import a module, we need to use <code class=\"language-text\">require</code> function provided by the Node.js and available globally everywhere in the program. This function takes a relative or an absolute path of the module file and returns what module is exporting. Hence, we need to save it inside a variable.</p>\n<p>// calculate.js<br>\nvar math = require( './lib/math.js' ); // <code class=\"language-text\">.js</code> is optional</p>\n<blockquote>\n<p><code class=\"language-text\">require()</code> statement sometimes also called as import statement.</p>\n</blockquote>\n<p>Now let's take a look at <code class=\"language-text\">math.js</code> file. We need to provide AKA export some values to the <code class=\"language-text\">require()</code> function call. This is done using <code class=\"language-text\">exports</code> variable. This variable is also globally available everywhere.</p>\n<p>This variable is actually an object which is empty <code class=\"language-text\">{}</code> at the beginning. When we import this module using <code class=\"language-text\">require</code> function, this is the object <code class=\"language-text\">require()</code> call will return.</p>\n<p>// calculate.js<br>\nvar math = require( './lib/math' );console.log(math); // {}</p>\n<p>Since we know that <code class=\"language-text\">exports</code> is an object that will be exported from the module, we can stuff it with whatever we want. As objects go, an object is a collection of key-value pairs. So let's add some math functions to it.</p>\n<p>// lib/math.js// add <code class=\"language-text\">add</code> function to <code class=\"language-text\">exports</code><br>\nexports.add = function( num1, num2 ) {<br>\nreturn num1 + num2<br>\n};</p>\n<p>From <code class=\"language-text\">math</code> module, we are exporting <code class=\"language-text\">add</code> function which returns the sum of the two numbers (<em>arguments</em>). Let's see what <code class=\"language-text\">math</code> variable looks like.</p>\n<p>// calculate.js<br>\nvar math = require( './lib/math' );console.log(math);<br>\n{ add: [Function] }</p>\n<p>It shows that <code class=\"language-text\">math</code> variable is an object that contains <code class=\"language-text\">add</code> key which has a <code class=\"language-text\">Function</code> value. Let's execute that function and see the result.</p>\n<p>// calculate.js<br>\nvar math = require( './lib/math' );// add 1 + 2<br>\nvar result = math.add(1, 2);<br>\nconsole.log( result ); // 3</p>\n<h2>What the heck is module.exports then?</h2>\n<p>I kind of skipped over this part so that you can understand module import with ease. I have a simple question, what if my <code class=\"language-text\">math</code> module exports only one function like <code class=\"language-text\">add</code> but I don't want to export it inside an object. This is the only function my module is exporting, so I want <code class=\"language-text\">require()</code> call to return this function only so that I can start using it like below.</p>\n<p>// calculate.js<br>\nvar math = require( './lib/math' );// add 1 + 2<br>\nvar result = math(1, 2); // math is a function<br>\nconsole.log( result ); // 3</p>\n<p>This is where <code class=\"language-text\">module</code> global variable comes into the picture. Like <code class=\"language-text\">exports</code>, <code class=\"language-text\">module</code> is also globally available everywhere. <code class=\"language-text\">module</code> is an object and it contains information about module (<em>auto injected by Node.js in key-value pairs</em>). The important key in this object we should know about is <code class=\"language-text\">exports</code>.</p>\n<p><code class=\"language-text\">exports</code> variable inside a module points to <code class=\"language-text\">exports</code> property on the <code class=\"language-text\">module</code> object, as you can prove in the below test.</p>\n<p>// lib/math.js<br>\nconsole.log(exports === module.exports); // true</p>\n<p>That means when we were setting <code class=\"language-text\">exports.add</code>, we were actually setting <code class=\"language-text\">module.exports.add</code>. So if we want our module to export only one function, we can just assign <code class=\"language-text\">module.exports</code> to that function.</p>\n<blockquote>\n<p>We could say that since <code class=\"language-text\">exports</code> and <code class=\"language-text\">module.exports</code> is the same, why not just set <code class=\"language-text\">exports</code> to the function. The reason is how objects are handled in JavaScript. Read <a href=\"https://stackoverflow.com/a/16383925\">this answer</a> to explore this topic in details.</p>\n</blockquote>\n<p>// lib/math.js// export function only<br>\nmodule.exports = function( num1, num2 ) {<br>\nreturn num1 + num2<br>\n};</p>\n<p>If your module import path is a directory, then <code class=\"language-text\">require</code> function will resolve <code class=\"language-text\">index.js</code> file inside it. Using this feature, you can have multiple .<code class=\"language-text\">js</code> files in a directory that contains different exports and you can import them inside <code class=\"language-text\">index.js</code> to exports them again from a single point.</p>\n<p>└── lib/<br>\n├── index.js (import <code class=\"language-text\">math</code> and <code class=\"language-text\">graph</code> and export them)<br>\n├── math.js<br>\n└── graph.js</p>\n<p>This way, the importer does not need to target individual module files in a directory. The importer can just point to <code class=\"language-text\">index.js</code> file.</p>\n<p>// lib/math.js<br>\nexports.add = function( num1, num2 ) {<br>\nreturn num1 + num2<br>\n};// lib/index.js<br>\nvar math = require('./math');<br>\nexports.add = math.add<br>\n// calculate.js<br>\nconst lib = require('./lib'); // points to './lib/index.js'<br>\nlib.add(1, 2) // 3</p>\n<p>In Node.js, a module or a package is loaded only once (<em>per thread or session</em>) even when you <code class=\"language-text\">require()</code> them multiple times in the program. Once loaded, it will be cached by the Node for performance enhancement.</p>\n<p>There are other tricks with CommonJS module system and sometimes we also need to be careful. Read <a href=\"https://www.sitepoint.com/understanding-module-exports-exports-node-js/\">this article</a> to understand more about imports.</p>\n<h1>Packages in Node.js</h1>\n<p>A package is nothing but a directory that contains a bunch of modules. Like for example <code class=\"language-text\">lib</code> in our previous example can be called a package but not quite yet. The most important feature about a node package is that, from anywhere in the program, we should be able to import it, without providing a relative or an absolute path.</p>\n<p>Well, that sounds absurd. If our <code class=\"language-text\">.js</code> files are nested, the import path will also change. Let's say that, we have a <code class=\"language-text\">src</code> directory and it contains <code class=\"language-text\">compute.js</code>. If we need to import <code class=\"language-text\">lib</code> package, the import path will be <code class=\"language-text\">../lib</code>.</p>\n<p>├── lib/<br>\n| ├── index.js<br>\n| └── math.js<br>\n└── src/<br>\n├── compute.js // require( '../lib')<br>\n└── deep/<br>\n└── nested.js // require( '../../lib')</p>\n<p>As we nest our files deeper, the import path is very difficult to track. What would be easy is instead of the relative path, we would just use <code class=\"language-text\">lib</code> and Node.js just finds the path to that package for us.</p>\n<p>// src/compute.js<br>\nconst lib = require('lib'); // points to '../lib/index.js'<br>\nlib.add(1, 2) // 3</p>\n<p>This might sound like a fantasy but it is actually very real. Node.js can do this for us, just that we need to create <code class=\"language-text\">node_modules</code> directory and clone <code class=\"language-text\">lib</code> directory inside it. This way, when we call <code class=\"language-text\">require('lib')</code>, it will point to the <code class=\"language-text\">lib</code> directory inside <code class=\"language-text\">node_modules</code>. Now, <code class=\"language-text\">lib</code> is a package.</p>\n<blockquote>\n<p>You might wonder, why they are called <code class=\"language-text\">node_modules</code> and not <code class=\"language-text\">node_packages</code>? In a conventional sense, a module is a file and package is a collection of modules. But when it comes to <code class=\"language-text\">require</code> function, they are ambiguous. Hence, let's stick to a common name, module. But normally, when people say node module, it is a package inside <code class=\"language-text\">node_modules</code> directory.</p>\n</blockquote>\n<p>But the real question is, how does Node knows where the <code class=\"language-text\">node_modules</code> directory is. The answer is, it doesn't. When we import a package, it searches that package inside <code class=\"language-text\">node_modules</code> directory of the current file path (<em>where import statement is written</em>). If it doesn't find <code class=\"language-text\">node_modules</code> directory or the package directory, it performs a similar search in the parent directory.</p>\n<p>This continues until the last directory in the file system is reached. If it doesn't find the package, it throws <code class=\"language-text\">Error: Cannot find module 'lib'</code> error.</p>\n<p>Let's create <code class=\"language-text\">node_modules</code> directory in our project and clone <code class=\"language-text\">lib</code> directory there. From <code class=\"language-text\">src/compute.js</code>, we will call the <code class=\"language-text\">add</code> function as before.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*o2PkxJ468fIvuQaZojV-sw.png\" alt=\"medium blog image\"></p>\n<p>(<a href=\"https://github.com/course-one/node-js-introduction/tree/master/lib\">package introduction</a>)</p>\n<p>In the above example, we are importing <code class=\"language-text\">math.js</code> file from <code class=\"language-text\">lib</code> package. If we just use <code class=\"language-text\">require('lib')</code>, Node.js will point to <code class=\"language-text\">index.js</code> file inside <code class=\"language-text\">lib</code> package directory. If <code class=\"language-text\">math.js</code> is missing, <code class=\"language-text\">require</code> will try to resolve <code class=\"language-text\">math/index.js</code> file treating <code class=\"language-text\">math</code> as a directory.</p>\n<p>Even though packages seems easy, their management if done manually is very difficult. Like what if we needed a 3rd-party package? I mean, should we clone the remote source code and put it inside <code class=\"language-text\">node_module</code> directory manually? Do you know how hard that would be for multiple people in the team? And whenever package version changes, it would be a mess to update.</p>\n<p>This is where NPM comes into the picture.</p>\n<blockquote>\n<p>This whole modules and packages theory might sound familiar to you if you are a python developer. But you don't need <strong>init</strong>.py like file in Node.js 😉</p>\n</blockquote>\n<h1>What is NPM?</h1>\n<p>When we installed Node.js, we also got <code class=\"language-text\">npm</code> command. <a href=\"https://www.npmjs.com/\">NPM</a> or <a href=\"https://www.npmjs.com/\">Node Package Manager</a> is the default package manager for Node.js. A role of a package manager is to download and install remote package, with ease.</p>\n<blockquote>\n<p>BTW, we can also install packages from a local directory.</p>\n</blockquote>\n<p>Node.js has a wide community that develop good packages for everybody to use. For example, <code class=\"language-text\">lodash</code> is the package that is used widely. This package contains useful utility functions like <code class=\"language-text\">add</code> in our earlier example. These utility functions are very well documented on their <a href=\"https://lodash.com/docs/4.17.15\">official website</a>.</p>\n<p>When we have a remote package in our project, it is called as a dependency since our project depends on it. We need to keep track of our dependencies or at least list them down somewhere. We list all our dependencies inside a <code class=\"language-text\">package.json</code> file which is a JSON file that contains some information about our project and dependencies it needs.</p>\n<p>This file is essential for NPM. To create this file using <code class=\"language-text\">npm</code>, use <code class=\"language-text\">npm init</code> command. This command will ask you some question to fill project-specific data in <code class=\"language-text\">package.json</code> and eventually create <code class=\"language-text\">package.json</code> file. You can bypass the questions using <code class=\"language-text\">-y</code> flag.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*QIqW9G-YXcvQAs0xl0zh2A.png\" alt=\"medium blog image\"></p>\n<p>(Initializing <a href=\"https://github.com/course-one/node-js-introduction/blob/master/package.json\">package.json</a>)</p>\n<p>Note <code class=\"language-text\">dependencies</code> section in the <code class=\"language-text\">package.json</code> file, it is empty at the moment. This means, our project at the moment does not depend on any of the remote packages.</p>\n<p>To install a package, we use <code class=\"language-text\">npm install &lt;packagename></code> command. For example, to install <code class=\"language-text\">lodash</code> package, we use <code class=\"language-text\">npm install --save lodash</code> command. Using <code class=\"language-text\">--save</code> flag, we can make entry of this package inside <code class=\"language-text\">dependencies</code> section of the <code class=\"language-text\">package.json</code> file.</p>\n<p>This command will do the following things.</p>\n<ol>\n<li>At first, it searches for this package on <code class=\"language-text\">[registry.npm.com](http://registry.npmjs.org/)</code> which contains the database of all packages. You can see the documentation of a package by visiting <code class=\"language-text\">[https://www.npmjs.com/package/&lt;packagename>](https://www.npmjs.com/package/lodash)</code> URL.</li>\n<li>Then it downloads the compressed zip (<em>or tar</em>) file that contains all the source code of the package. If a version of the package was not specified in the command, it will download the latest version.</li>\n<li>Then it adds the package entry to the <code class=\"language-text\">dependencies</code> section of <code class=\"language-text\">package.json</code> with the version of the package. If the entry of the package already exists, it will just override the version of the package downloaded.</li>\n<li>Then it creates <code class=\"language-text\">node_modules</code> folder in the same directory if it doesn't already exist.</li>\n<li>Then it will copy all the files from the downloaded compressed file in the directory with the name of the package inside <code class=\"language-text\">node_modules</code>.</li>\n</ol>\n<p>Let's actually install <code class=\"language-text\">lodash</code> package and see how <code class=\"language-text\">node_modules</code> and <code class=\"language-text\">package.json</code> file looks like after the install.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*xPtGu4bjhl4YJlH9PvwH9A.png\" alt=\"medium blog image\"></p>\n<p>(npm install -- save lodash)</p>\n<p>From the above example, <code class=\"language-text\">npm</code> installed the version <code class=\"language-text\">4.17.15</code> of the <code class=\"language-text\">lodash</code>. This type of version number system is called as <a href=\"https://devhints.io/semver\">Semantic Versioning</a>. We can also specify a specific version of a package to install using the command like <code class=\"language-text\">npm install --save lodash@4.17.10</code>.</p>\n<p>Now that we have installed <code class=\"language-text\">lodash</code>, let's use its <code class=\"language-text\">_.toUpper</code> function to change the case of a string. But first, we need to import the package.</p>\n<p>// src/transform.js<br>\nvar lodash = require( 'lodash' );var result = lodash.toUpper( 'hello world!' );<br>\nconsole.log( result ); // HELLO WORLD!</p>\n<p>When we run this file using the command <code class=\"language-text\">node src/transform.js</code>, we get <code class=\"language-text\">HELLO WORLD!</code> printed in the terminal.</p>\n<p>When you install a package, NPM also creates <code class=\"language-text\">package-lock.json</code> file if not already present. This file contains a list of dependency packages with their versions that your project has installed as well as dependencies of those packages (<em>because a package might use other packages and so on</em>). This file including <code class=\"language-text\">package.json</code> should be tracked by your <a href=\"https://en.wikipedia.org/wiki/Version_control\">VCS</a> while <code class=\"language-text\">node_module</code> directory should be ignored (<em>reasons explained later</em>).</p>\n<blockquote>\n<p>NPM and package management is far more sophisticated (and for good) than this but we will discuss it later in details.</p>\n</blockquote>\n<h1>Built-in Packages AKA Built-in Modules</h1>\n<p>Node.js ships with a collection of built-in packages called as a Node Standard Library. These packages are essential to perform low-level operations like File System I/O and Networking. We do not have to install them using NPM.</p>\n<p>Since these packages contain code in a low-level programming language tailored to a specific version of Node.js, they have to be shipped as a part of the installation process. <a href=\"https://nodejs.org/api/index.html\">Here</a> is a list of built-in modules in Node.js.</p>\n<p>These packages do not exist on disk like <code class=\"language-text\">lodash</code>. They are compiled into low-level or intermediate stuff (<a href=\"https://stackoverflow.com/a/42892065\">explained here</a>) but their sources are listed <a href=\"https://github.com/nodejs/node/tree/master/lib\">here</a>.</p>\n<p><code class=\"language-text\">[fs](https://nodejs.org/api/fs.html)</code> package is used to perform File System operations like file read and write while <code class=\"language-text\">[path](https://nodejs.org/api/path.html)</code> package is used to resolve a file or directory path on the system. Let's use these packages to demonstrate a cool example.</p>\n<p>├── res<br>\n| └── hello-world.txt<br>\n└── fs-example.js</p>\n<p>According to the above project structure, we have <code class=\"language-text\">hello-world.txt</code> file which contains <code class=\"language-text\">Hello World!</code> text. Using <code class=\"language-text\">fs-example.js</code>, we want to read the text in the file and log in to the console.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*78ejxNXflo4CGZ18gRXPhQ.png\" alt=\"medium blog image\"></p>\n<p>(Sample <code class=\"language-text\">fs</code> and <code class=\"language-text\">path</code> module introduction)</p>\n<p>In the above program, we imported the <code class=\"language-text\">fs</code> and <code class=\"language-text\">path</code> built-in modules.</p>\n<blockquote>\n<p>When we <code class=\"language-text\">require(name)</code> a package, Node.js first searches for the package <code class=\"language-text\">name</code> in the built-in packages. If it doesn't find it in the standard library, then it searches for it in <code class=\"language-text\">node_modules</code> as explained earlier.</p>\n</blockquote>\n<p><code class=\"language-text\">__dirname</code> is a globally available variable that resolves to the absolute path of the current file on the disk. <code class=\"language-text\">[path.resolve](https://nodejs.org/api/path.html#path_path_resolve_paths)</code> function takes multiple path segments and joins them. This is a safe way to create an absolute path of a file on the disk, as Windows and Unix systems use different path delimiter.</p>\n<blockquote>\n<p>You can also use a relative path like <code class=\"language-text\">var filePath = './res/hello-world.txt';</code> in the above example but <code class=\"language-text\">path.resolve</code> is safer. <code class=\"language-text\">process</code> is a globally available object that contains information about environment variables and current process context in general. Unlike <code class=\"language-text\">__dirname</code>, <code class=\"language-text\">[process.cwd()](https://nodejs.org/api/process.html#process_process_cwd)</code> function returns the path of the directory from where the <code class=\"language-text\">node</code> command was executed in the terminal (or the current directory in the terminal).</p>\n</blockquote>\n<p>Let's talk about the example in detail. Inside <code class=\"language-text\">fs-example.js</code> file, we imported built-in modules <code class=\"language-text\">fs</code> and <code class=\"language-text\">path</code>. Then we constructed a <code class=\"language-text\">filePath</code> which points to <code class=\"language-text\">hello-world.txt</code> on the disk.</p>\n<p><code class=\"language-text\">[fs.readFile](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback)</code> function takes below arguments in series</p>\n<ol>\n<li>filePath: A absolute or relative path to the file we are trying to read.</li>\n<li>options: An object that contains a configuration about reading. In the above example, we set <code class=\"language-text\">encoding</code> to <code class=\"language-text\">utf-8</code> which converts binary data to Text format. This will convert file content to Text.</li>\n<li>callback: Sync file read operation using <code class=\"language-text\">readFile</code> function is asynchronous, we need a callback function to execute when the file is read completely. This function will receive read error (<em>if any</em>) as the first argument and file data as the second argument.</li>\n</ol>\n<p>Notice the console log. The first <code class=\"language-text\">-end-of-the-program-</code> statement got printed as <code class=\"language-text\">fs.readFile</code> was reading the file in the background. Once file reading was completed, the callback function was called.</p>\n<p>Node.js can also perform synchronous (blocking) operations. For example, using <code class=\"language-text\">[fs.readFileSync](https://nodejs.org/api/fs.html#fs_fs_readfilesync_path_options)</code>, we can block the JavaScript thread until the file is read. This way, we can make sure, JavaScript code run sequentially.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*FmUCo0e0Cs_QKxEGZ509nQ.png\" alt=\"medium blog image\"></p>\n<p>(<a href=\"https://github.com/course-one/node-js-introduction/blob/master/fs-example.js\">Reading a file synchronously</a>)</p>\n<h1>Creating an HTTP server in Node.js</h1>\n<p>Node.js can do anything, literally anything. Node.js has built-in <code class=\"language-text\">[http](https://nodejs.org/api/http.html)</code> module as well as <code class=\"language-text\">[https](https://nodejs.org/api/https.html)</code> module to create an HTTP/HTTPS server. But their implementation is kind of hard.</p>\n<p>ExpressJS is a 3rd-party package that wraps the built-in <code class=\"language-text\">http</code> module and provide a cleaner interface to create an HTTP server. This package is listed on NPM registry under <code class=\"language-text\">[express](https://www.npmjs.com/package/express)</code> name. Let's create a basic HTTP server.</p>\n<p>First, we need to install <code class=\"language-text\">express</code> package using NPM.</p>\n<p>npm install --save express</p>\n<p>Then we will import this package and create a basic HTTP server inside <code class=\"language-text\">server.js</code> file. We will follow their <a href=\"https://github.com/expressjs/express\">startup documentation</a>.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*6yP5kysrs9UIKk8RYnR0AQ.png\" alt=\"medium blog image\"></p>\n<p>(<a href=\"https://github.com/course-one/node-js-introduction/blob/master/server.js\">Sample express HTTP server</a>)</p>\n<p>When we executed <code class=\"language-text\">server.js</code> file with <code class=\"language-text\">node</code>, ExpressJS will lock the Node process as we want the server to be running forever. Now that server is running on the port <code class=\"language-text\">9000</code>, we can open the browser and access URL <code class=\"language-text\">&lt;http://localhost:9000/></code> which will execute the <code class=\"language-text\">.get</code> callback.</p>\n<p><img src=\"https://miro.medium.com/max/473/1*evvJp-ynknMqnUTbW4dssw.png\" alt=\"medium blog image\"></p>\n<p><code class=\"language-text\">(&lt;http://localhost:9000/>)</code></p>\n<p>This was just a basic example of how we can create an HTTP server in Node.js. But with express.js, we can create more complex servers which can send HTML file content using <code class=\"language-text\">response.sendFile(filePath)</code> function or send JSON using <code class=\"language-text\">response.json(object)</code> function. We can also create an endpoint that <a href=\"https://expressjs.com/en/starter/static-files.html\">serves static files</a> like images from the disk using <a href=\"https://expressjs.com/en/guide/writing-middleware.html\">middlewares</a>.</p>\n<p>To stop the server, we need to stop the locked Node.js process. We can do that by pressing <code class=\"language-text\">ctrl+c</code> in the terminal. But what if we need to actually run the server on the production literally forever. In that case, we can't have terminal open for years. This is where the process managers comes in.</p>\n<p><a href=\"http://pm2.keymetrics.io/\">PM2</a> is one of the best process managers that can run a Node process in the background. When you install it, it will give you a clean command-line interface to start a Node.js process and PM2 will monitor it.</p>\n<h1>Execute a Bash command from Node.js</h1>\n<p>If you make Node.js your life and want to do everything from Node, then this topic is very important. Let's say that from a JavaScript program, you want to execute a BASH command. A Bash command would be <code class=\"language-text\">echo Hello World!</code>. You can try this command in the terminal and it will print <code class=\"language-text\">Hello World!</code>.</p>\n<p>Node.js provides a built-in <code class=\"language-text\">[child_process](https://nodejs.org/api/child_process.html)</code> command to run Bash command in a separate process. <code class=\"language-text\">[child_process.exec](https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)</code> function takes a Bash command and executes it. It takes an optional callback function to execute (<em>with some process information</em>) when the process is terminated.</p>\n<p>Let's create a <code class=\"language-text\">echo.js</code> file that executes <code class=\"language-text\">echo Hello World!</code> Bash command.</p>\n<p><img src=\"https://miro.medium.com/max/675/1*NGwvmLnmj436x2EXbWAJvg.png\" alt=\"medium blog image\"></p>\n<p>(<a href=\"https://github.com/course-one/node-js-introduction/blob/master/echo.js\">child_process example</a>)</p>\n<p>In the above program, the callback function to <code class=\"language-text\">child_process.exec</code> receives the <a href=\"https://www.computerhope.com/jargon/s/stdout.htm\">standard output</a> of the program.</p>\n<p><code class=\"language-text\">child_process</code> module can do many things, like execute a Bash file using <code class=\"language-text\">[child_process.execFile](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback)</code> function. It also supports synchronous variants to run a bash command synchronously, like <code class=\"language-text\">[child_process.execSync](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options)</code> function.</p>\n<h1>How to ship your code to Production?</h1>\n<p>Now that we have a good understanding of Node.js and NPM, we can move forward to this most important topic.</p>\n<p><code class=\"language-text\">package.json</code> and <code class=\"language-text\">package-lock.json</code> files are very important as they contain information about dependencies our project has. Those dependencies are stored inside <code class=\"language-text\">node_modules</code> directory by the NPM.</p>\n<p>So if our project is managed using a VCS like Git then should we commit all our code? The answer is, 😱 NOOOOOOOOOOO. <code class=\"language-text\">node_modules</code> directory can be very large as it contains deeply nested dependencies. Hence it should be ignored by the VCS. Use <code class=\"language-text\">.gitignore</code> file to do that.</p>\n<h1>.gitignore\\</h1>\n<p>node_modules</p>\n<p>But then when your buddy takes the clone or a pull of the project, he/she won't get <code class=\"language-text\">node_modules</code>. Nothing to worry about here because NPM can take care of that.</p>\n<p>When we used <code class=\"language-text\">npm install &lt;packagename></code> command for the first time, NPM created <code class=\"language-text\">node_modules</code> directory and install <code class=\"language-text\">packagename</code> package. Using <code class=\"language-text\">npm install</code> command (<em>without a package name</em>), NPM will look at <code class=\"language-text\">pakage.json</code> to install all the dependencies listed inside it.</p>\n<blockquote>\n<p>Actually, since NPM v.5, <code class=\"language-text\">npm install</code> command looks at <code class=\"language-text\">package-lock.json</code> command to install the dependencies since it contains the exact versions of the packages and their dependencies (which were installed by the developer of the project). This minimizes the conflict of versions between the development machine and production machine.</p>\n</blockquote>\n<p>By ignoring <code class=\"language-text\">node_modules</code>, we are actually saving a lot of time and bandwidth of transferring the project from a development machine to production.</p>\n<p><a href=\"https://codesandbox.io/s/nodejs-examples-4ohjz?autoresize=1&#x26;expanddevtools=1&#x26;fontsize=13&#x26;hidenavigation=1&#x26;theme=light&#x26;view=editor\"><img src=\"https://codesandbox.io/static/img/play-codesandbox.svg\" alt=\"Edit nodejs-examples\"></a></p>"},{"url":"/docs/reference/psql/","relativePath":"docs/reference/psql.md","relativeDir":"docs/reference","base":"psql.md","name":"psql","frontmatter":{"title":"Postgresql Cheat Sheet","weight":0,"excerpt":"Postgresql Cheat Sheet","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Postgresql Cheat Sheet</h1>\n<p>PostgreSQL commands</p>\n<hr>\n<h4><a href=\"http://medium.com/codex\" class=\"markup--anchor markup--h4-anchor\">CODEX</a></h4>\n<h3>PostgreSQL Cheat Sheet</h3>\n<h4><strong>Each table is made up of rows and columns. If you think of a table as a grid, the column go from left to right across the grid and each entry of data is listed down as a row.</strong></h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ZLWhY1d1jdboZh_s.png\" class=\"graf-image\" />\n</figure>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\">\n<strong>ALLOFMYOTHERARTICLES</strong>\n<br />\nbryanguner.medium.com</a>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<p>Each row in a relational is uniquely identified by a primary key. This can be by one or more sets of column values. In most scenarios it is a single column, such as employeeID.</p>\n<p>Every relational table has one primary key. Its purpose is to uniquely identify each row in the database. No two rows can have the same primary key value. The practical result of this is that you can select every single row by just knowing its primary key.</p>\n<p>SQL Server UNIQUE constraints allow you to ensure that the data stored in a column, or a group of columns, is unique among the rows in a table.</p>\n<p>Although both UNIQUE and <a href=\"https://www.sqlservertutorial.net/sql-server-basics/sql-server-primary-key/\" class=\"markup--anchor markup--p-anchor\">PRIMARY KEY</a> constraints enforce the uniqueness of data, you should use the UNIQUE constraint instead of PRIMARY KEY constraint when you want to enforce the uniqueness of a column, or a group of columns, that are not the primary key columns.</p>\n<p>Different from PRIMARY KEY constraints, UNIQUE constraints allow NULL. Moreover, UNIQUE constraints treat the NULL as a regular value, therefore, it only allows one NULL per column.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*kgzq5NoL5ejBGvuZ4qLDaQ.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*hr8DccnpiR2Uj5UI3iLsOQ.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*RiWJpwpVMdge3Sqofn3srA.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*GN5aSwENOvntpfk90rHYFg.png\" class=\"graf-image\" />\n</figure>Create a new <a href=\"https://www.postgresqltutorial.com/postgresql-roles/\" class=\"markup--anchor markup--p-anchor\">role</a>:\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE ROLE role_name;</code></pre></div>\n<p>Create a new role with a <code class=\"language-text\">username</code> and <code class=\"language-text\">password</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE ROLE username NOINHERIT LOGIN PASSWORD password;</code></pre></div>\n<p>Change role for the current session to the <code class=\"language-text\">new_role</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SET ROLE new_role;</code></pre></div>\n<p>Allow <code class=\"language-text\">role_1</code> to set its role as <code class=\"language-text\">role_2:</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">GRANT role_2 TO role_1;</code></pre></div>\n<h3>Managing databases</h3>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-create-database/\" class=\"markup--anchor markup--p-anchor\">Create a new database</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE DATABASE [IF NOT EXISTS] db_name;</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-drop-database/\" class=\"markup--anchor markup--p-anchor\">Delete a database permanently</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">DROP DATABASE [IF EXISTS] db_name;</code></pre></div>\n<h3>Managing tables</h3>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-create-table/\" class=\"markup--anchor markup--p-anchor\">Create a new table</a> or a <a href=\"https://www.postgresqltutorial.com/postgresql-temporary-table/\" class=\"markup--anchor markup--p-anchor\">temporary table</a></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE [TEMP] TABLE [IF NOT EXISTS] table_name(\n       pk SERIAL PRIMARY KEY,\n   c1 type(size) NOT NULL,\n   c2 type(size) NULL,\n   ...\n);</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-add-column/\" class=\"markup--anchor markup--p-anchor\">Add a new column</a> to a table:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ALTER TABLE table_name ADD COLUMN new_column_name TYPE;</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-drop-column/\" class=\"markup--anchor markup--p-anchor\">Drop a column</a> in a table:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ALTER TABLE table_name DROP COLUMN column_name;</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-rename-column/\" class=\"markup--anchor markup--p-anchor\">Rename a column</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ALTER TABLE table_name RENAME column_name TO new_column_name;</code></pre></div>\n<p>Set or remove a default value for a column:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ALTER TABLE table_name ALTER COLUMN [SET DEFAULT value | DROP DEFAULT]</code></pre></div>\n<p>Add a <a href=\"https://www.postgresqltutorial.com/postgresql-primary-key/\" class=\"markup--anchor markup--p-anchor\">primary key</a> to a table.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ALTER TABLE table_name ADD PRIMARY KEY (column,...);</code></pre></div>\n<p>Remove the primary key from a table.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ALTER TABLE table_name\nDROP CONSTRAINT primary_key_constraint_name;</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-rename-table/\" class=\"markup--anchor markup--p-anchor\">Rename a table</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ALTER TABLE table_name RENAME TO new_table_name;</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-drop-table/\" class=\"markup--anchor markup--p-anchor\">Drop a table</a> and its dependent objects:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">DROP TABLE [IF EXISTS] table_name CASCADE;</code></pre></div>\n<h3>Managing views</h3>\n<p><a href=\"https://www.postgresqltutorial.com/managing-postgresql-views/\" class=\"markup--anchor markup--p-anchor\">Create a view</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE OR REPLACE view_name AS\nquery;</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-recursive-view/\" class=\"markup--anchor markup--p-anchor\">Create a recursive view</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE RECURSIVE VIEW view_name(column_list) AS\nSELECT column_list;</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-materialized-views/\" class=\"markup--anchor markup--p-anchor\">Create a materialized view</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE MATERIALIZED VIEW view_name\nAS\nquery\nWITH [NO] DATA;</code></pre></div>\n<p>Refresh a materialized view:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">REFRESH MATERIALIZED VIEW CONCURRENTLY view_name;</code></pre></div>\n<p>Drop a view:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">DROP VIEW [ IF EXISTS ] view_name;</code></pre></div>\n<p>Drop a materialized view:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">DROP MATERIALIZED VIEW view_name;</code></pre></div>\n<p>Rename a view:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ALTER VIEW view_name RENAME TO new_name;</code></pre></div>\n<h3>Managing indexes</h3>\n<p>Creating an index with the specified name on a table</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE [UNIQUE] INDEX index_name\nON table (column,...)</code></pre></div>\n<p>Removing a specified index from a table</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">DROP INDEX index_name;</code></pre></div>\n<h3>Querying data from tables</h3>\n<p>Query all data from a table:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM table_name;</code></pre></div>\n<p>Query data from specified columns of all rows in a table:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT column_list\nFROM table;</code></pre></div>\n<p>Query data and select only unique rows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT DISTINCT (column)\nFROM table;</code></pre></div>\n<p>Query data from a table with a filter:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT *\nFROM table\nWHERE condition;</code></pre></div>\n<p>Assign an <a href=\"https://www.postgresqltutorial.com/postgresql-alias/\" class=\"markup--anchor markup--p-anchor\">alias</a> to a column in the result set:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT column_1 AS new_column_1, ...\nFROM table;</code></pre></div>\n<p>Query data using the <code class=\"language-text\">LIKE</code> operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM table_name\nWHERE column LIKE '%value%'</code></pre></div>\n<p>Query data using the <code class=\"language-text\">BETWEEN</code>operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM table_name\nWHERE column BETWEEN low AND high;</code></pre></div>\n<p>Query data using the <code class=\"language-text\">IN</code>operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM table_name\nWHERE column IN (value1, value2,...);</code></pre></div>\n<p>Constrain the returned rows with the <code class=\"language-text\">LIMIT</code> clause:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM table_name\nLIMIT limit OFFSET offset\nORDER BY column_name;</code></pre></div>\n<p>Query data from multiple using the <a href=\"https://www.postgresqltutorial.com/postgresql-inner-join/\" class=\"markup--anchor markup--p-anchor\">inner join</a>, <a href=\"https://www.postgresqltutorial.com/postgresql-left-join/\" class=\"markup--anchor markup--p-anchor\">left join</a>, <a href=\"https://www.postgresqltutorial.com/postgresql-full-outer-join/\" class=\"markup--anchor markup--p-anchor\">full outer join</a>, <a href=\"https://www.postgresqltutorial.com/postgresql-cross-join/\" class=\"markup--anchor markup--p-anchor\">cross join</a> and <a href=\"https://www.postgresqltutorial.com/postgresql-natural-join/\" class=\"markup--anchor markup--p-anchor\">natural join</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT *\nFROM table1\nINNER JOIN table2 ON conditions\nSELECT *\nFROM table1\nLEFT JOIN table2 ON conditions\nSELECT *\nFROM table1\nFULL OUTER JOIN table2 ON conditions\nSELECT *\nFROM table1\nCROSS JOIN table2;\nSELECT *\nFROM table1\nNATURAL JOIN table2;</code></pre></div>\n<p>Return the number of rows of a table.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT COUNT (*)\nFROM table_name;</code></pre></div>\n<p>Sort rows in ascending or descending order:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT select_list\nFROM table\nORDER BY column ASC [DESC], column2 ASC [DESC],...;</code></pre></div>\n<p>Group rows using <code class=\"language-text\">GROUP BY</code> clause.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT *\nFROM table\nGROUP BY column_1, column_2, ...;</code></pre></div>\n<p>Filter groups using the <code class=\"language-text\">HAVING</code> clause.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT *\nFROM table\nGROUP BY column_1\nHAVING condition;</code></pre></div>\n<h3>Set operations</h3>\n<p>Combine the result set of two or more queries with <code class=\"language-text\">UNION</code> operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM table1\nUNION\nSELECT * FROM table2;</code></pre></div>\n<p>Minus a result set using <code class=\"language-text\">EXCEPT</code> operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM table1\nEXCEPT\nSELECT * FROM table2;</code></pre></div>\n<p>Get intersection of the result sets of two queries:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM table1\nINTERSECT\nSELECT * FROM table2;</code></pre></div>\n<h3>Modifying data</h3>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-insert/\" class=\"markup--anchor markup--p-anchor\">Insert a new row into a table</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">INSERT INTO table(column1,column2,...)\nVALUES(value_1,value_2,...);</code></pre></div>\n<p>Insert multiple rows into a table:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">INSERT INTO table_name(column1,column2,...)\nVALUES(value_1,value_2,...),\n      (value_1,value_2,...),\n      (value_1,value_2,...)...</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-update/\" class=\"markup--anchor markup--p-anchor\">Update</a> data for all rows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">UPDATE table_name\nSET column_1 = value_1,\n    ...;</code></pre></div>\n<p>Update data for a set of rows specified by a condition in the <code class=\"language-text\">WHERE</code> clause.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">UPDATE table\nSET column_1 = value_1,\n    ...\nWHERE condition;</code></pre></div>\n<p><a href=\"https://www.postgresqltutorial.com/postgresql-delete/\" class=\"markup--anchor markup--p-anchor\">Delete all rows</a> of a table:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">DELETE FROM table_name;</code></pre></div>\n<p>Delete specific rows based on a condition:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">DELETE FROM table_name\nWHERE condition;</code></pre></div>\n<h3>Performance</h3>\n<p>Show the query plan for a query:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">EXPLAIN query;</code></pre></div>\n<p>Show and execute the query plan for a query:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">EXPLAIN ANALYZE query;</code></pre></div>\n<p>Collect statistics:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ANALYZE table_name;</code></pre></div>\n<hr>\n<h3>Postgres &#x26; JSON:</h3>\n<h3>Creating the DB and the Table</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">DROP DATABASE IF EXISTS books_db;\nCREATE DATABASE books_db WITH ENCODING='UTF8' TEMPLATE template0;\n\nDROP TABLE IF EXISTS books;\n\nCREATE TABLE books (\n  id SERIAL PRIMARY KEY,\n  client VARCHAR NOT NULL,\n  data JSONb NOT NULL\n);</code></pre></div>\n<h3>Populating the DB</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">INSERT INTO books(client, data) values( 'Joe', '{ \"title\": \"Siddhartha\", \"author\": { \"first_name\": \"Herman\", \"last_name\": \"Hesse\" } }' ); INSERT INTO books(client, data) values('Jenny', '{ \"title\": \"Bryan Guner\", \"author\": { \"first_name\": \"Jack\", \"last_name\": \"Kerouac\" } }'); INSERT INTO books(client, data) values('Jenny', '{ \"title\": \"100 años de soledad\", \"author\": { \"first_name\": \"Gabo\", \"last_name\": \"Marquéz\" } }');</code></pre></div>\n<p>Lets see everything inside the table books:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM books;</code></pre></div>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*GOQQ0qNGak2yIrtQ\" class=\"graf-image\" />\n</figure>### `->` operator returns values out of JSON columns\n<p>Selecting 1 column:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT client,\n    data->'title' AS title\n    FROM books;</code></pre></div>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*OIVYOfYcbVh65Mt5\" class=\"graf-image\" />\n</figure>Selecting 2 columns:\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT client,\n   data->'title' AS title, data->'author' AS author\n   FROM books;</code></pre></div>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*fEzPkSY8yGexKOk4\" class=\"graf-image\" />\n</figure>### `->` vs `->>`\n<p>The <code class=\"language-text\">-></code> operator returns the original JSON type (which might be an object), whereas <code class=\"language-text\">->></code> returns text.</p>\n<h3>Return NESTED objects</h3>\n<p>You can use the <code class=\"language-text\">-></code> to return a nested object and thus chain the operators:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT client,\n   data->'author'->'last_name' AS author\n   FROM books;</code></pre></div>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*lwy8bR7igaroMXeb\" class=\"graf-image\" />\n</figure>### Filtering\n<p>Select rows based on a value inside your JSON:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT\n client,\n data->'title' AS title\n FROM books\n  WHERE data->'title' = '\"Bryan Guner\"';</code></pre></div>\n<p>Notice WHERE uses <code class=\"language-text\">-></code> so we must compare to JSON <code class=\"language-text\">'\"Bryan Guner\"'</code></p>\n<p>Or we could use <code class=\"language-text\">->></code> and compare to <code class=\"language-text\">'Bryan Guner'</code></p>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*poASndLoU71qlXqE\" class=\"graf-image\" />\n</figure>### Nested filtering\n<p>Find rows based on the value of a nested JSON object:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT\n client,\n data->'title' AS title\n FROM books\n  WHERE data->'author'->>'last_name' = 'Kerouac';</code></pre></div>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*R1kOhDK19ntdUYkq\" class=\"graf-image\" />\n</figure>### A real world example\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">CREATE TABLE events (\n  name varchar(200),\n  visitor_id varchar(200),\n  properties json,\n  browser json\n);</code></pre></div>\n<p>We're going to store events in this table, like pageviews. Each event has properties, which could be anything (e.g. current page) and also sends information about the browser (like OS, screen resolution, etc). Both of these are completely free form and could change over time (as we think of extra stuff to track).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">INSERT INTO events VALUES (\n  'pageview', '1',\n  '{ \"page\": \"/\" }',\n  '{ \"name\": \"Chrome\", \"os\": \"Mac\", \"resolution\": { \"x\": 1440, \"y\": 900 } }'\n);\nINSERT INTO events VALUES (\n  'pageview', '2',\n  '{ \"page\": \"/\" }',\n  '{ \"name\": \"Firefox\", \"os\": \"Windows\", \"resolution\": { \"x\": 1920, \"y\": 1200 } }'\n);\nINSERT INTO events VALUES (\n  'pageview', '1',\n  '{ \"page\": \"/account\" }',\n  '{ \"name\": \"Chrome\", \"os\": \"Mac\", \"resolution\": { \"x\": 1440, \"y\": 900 } }'\n);\nINSERT INTO events VALUES (\n  'purchase', '5',\n  '{ \"amount\": 10 }',\n  '{ \"name\": \"Firefox\", \"os\": \"Windows\", \"resolution\": { \"x\": 1024, \"y\": 768 } }'\n);\nINSERT INTO events VALUES (\n  'purchase', '15',\n  '{ \"amount\": 200 }',\n  '{ \"name\": \"Firefox\", \"os\": \"Windows\", \"resolution\": { \"x\": 1280, \"y\": 800 } }'\n);\nINSERT INTO events VALUES (\n  'purchase', '15',\n  '{ \"amount\": 500 }',\n  '{ \"name\": \"Firefox\", \"os\": \"Windows\", \"resolution\": { \"x\": 1280, \"y\": 800 } }'\n);</code></pre></div>\n<p>Now lets select everything:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM events;</code></pre></div>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ZPHfB4FxjSIlAVxL\" class=\"graf-image\" />\n</figure>### JSON operators + PostgreSQL aggregate functions\n<p>Using the JSON operators, combined with traditional PostgreSQL aggregate functions, we can pull out whatever we want. You have the full might of an RDBMS at your disposal.</p>\n<ul>\n<li><span id=\"4ffd\">Lets see browser usage:</span></li>\n<li><span id=\"261c\"><code class=\"language-text\">SELECT browser->>'name' AS browser, count(browser) FROM events GROUP BY browser->>'name';</code></span></li>\n</ul>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*4lEv2DgUk33FeUgo\" class=\"graf-image\" />\n</figure>- <span id=\"946c\">Total revenue per visitor:</span>\n<p><code class=\"language-text\">SELECT visitor_id, SUM(CAST(properties->>'amount' AS integer)) AS total FROM events WHERE CAST(properties->>'amount' AS integer) > 0 GROUP BY visitor_id;</code></p>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*HxOS3CgwXBJ6A2FP\" class=\"graf-image\" />\n</figure>- <span id=\"9850\">Average screen resolution</span>\n- <span id=\"132f\">`SELECT AVG(CAST(browser->'resolution'->>'x' AS integer)) AS width, AVG(CAST(browser->'resolution'->>'y' AS integer)) AS height FROM events;`</span>\n<p>Output:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*iyv4Iv4Rc8M8mwt1\" class=\"graf-image\" />\n</figure>#### If you found this guide helpful feel free to checkout my github/gists where I host similar content:\n<p><a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--p-anchor\">bgoonz's gists · GitHub</a></p>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>Or Checkout my personal Resource Site:</p>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\">\n<strong>a/A-Student-Resources</strong>\n<br />\n<em>Edit description</em>goofy-euclid-1cd736.netlify.app</a>\n<a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content:</h3>\n<a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://gist.github.com/bgoonz\">\n<strong>bgoonz's gists</strong>\n<br />\n<em>Instantly share code, notes, and snippets. Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python |…</em>gist.github.com</a>\n<a href=\"https://gist.github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>Or Checkout my personal Resource Site:</h3>"},{"url":"/docs/reference/markdown-styleguide/","relativePath":"docs/reference/markdown-styleguide.md","relativeDir":"docs/reference","base":"markdown-styleguide.md","name":"markdown-styleguide","frontmatter":{"title":"Markdown Lint Styleguide","weight":0,"excerpt":"Markdown Lint Styleguide","seo":{"title":"Markdown Lint Styleguide","description":"This document contains a description of all rules, what they are checking for, as well as examples of documents that break the rule and corrected versions of the examples.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Rules</h1>\n<p>This document contains a description of all rules, what they are checking for,\nas well as examples of documents that break the rule and corrected\nversions of the examples. Any rule whose heading is <del>struck through</del> is\ndeprecated, but still provided for backward-compatibility.</p>\n<a name=\"md001\">\n</a>\n<h2>MD001 - Heading levels should only increment by one level at a time</h2>\n<p>Tags: headings, headers</p>\n<p>Aliases: heading-increment, header-increment</p>\n<p>This rule is triggered when you skip heading levels in a markdown document, for\nexample:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Heading 3</span>\n\nWe skipped out a 2nd level heading in this document</code></pre></div>\n<p>When using multiple heading levels, nested headings should increase by only one\nlevel at a time:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Heading 3</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">####</span> Heading 4</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Another Heading 2</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Another Heading 3</span></code></pre></div>\n<p>Rationale: Headings represent the structure of a document and can be confusing\nwhen skipped - especially for accessibility scenarios. More information:\n<a href=\"https://www.w3.org/WAI/tutorials/page-structure/headings/\">https://www.w3.org/WAI/tutorials/page-structure/headings/</a>.</p>\n<a name=\"md002\">\n</a>\n<h2><del>MD002 - First heading should be a top-level heading</del></h2>\n<p>Tags: headings, headers</p>\n<p>Aliases: first-heading-h1, first-header-h1</p>\n<p>Parameters: level (number; default 1)</p>\n<blockquote>\n<p>Note: <em>MD002 has been deprecated and is disabled by default.</em> > <a href=\"#md041\">MD041/first-line-heading</a> offers an improved implementation.</p>\n</blockquote>\n<p>This rule is intended to ensure document headings start at the top level and\nis triggered when the first heading in the document isn't an h1 heading:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">##</span> This isn't an H1 heading</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Another heading</span></code></pre></div>\n<p>The first heading in the document should be an h1 heading:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Start with an H1 heading</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Then use an H2 for subsections</span></code></pre></div>\n<p>Note: The <code class=\"language-text\">level</code> parameter can be used to change the top-level (ex: to h2) in\ncases where an h1 is added externally.</p>\n<p>Rationale: The top-level heading often acts as the title of a document. More\ninformation: <a href=\"https://cirosantilli.com/markdown-style-guide#top-level-header\">https://cirosantilli.com/markdown-style-guide#top-level-header</a>.</p>\n<a name=\"md003\">\n</a>\n<h2>MD003 - Heading style</h2>\n<p>Tags: headings, headers</p>\n<p>Aliases: heading-style, header-style</p>\n<p>Parameters: style (\"consistent\", \"atx\", \"atx<em>closed\", \"setext\",\n\"setext</em>with<em>atx\", \"setext</em>with<em>atx</em>closed\"; default \"consistent\")</p>\n<p>This rule is triggered when different heading styles (atx, setext, and 'closed'\natx) are used in the same document:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> ATX style H1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Closed ATX style H2</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">#</span> Setext style H1</span></code></pre></div>\n<p>Be consistent with the style of heading used in a document:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> ATX style H1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> ATX style H2</span></code></pre></div>\n<p>The setext<em>with</em>atx and setext<em>with</em>atx_closed doc styles allow atx-style\nheadings of level 3 or more in documents with setext style headings:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Setext style H1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Setext style H2</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> ATX style H3</span></code></pre></div>\n<p>Note: the configured heading style can be a specific style to use (atx,\natx<em>closed, setext, setext</em>with<em>atx, setext</em>with<em>atx</em>closed), or simply require\nthat the usage is consistent within the document.</p>\n<p>Rationale: Consistent formatting makes it easier to understand a document.</p>\n<a name=\"md004\">\n</a>\n<h2>MD004 - Unordered list style</h2>\n<p>Tags: bullet, ul</p>\n<p>Aliases: ul-style</p>\n<p>Parameters: style (\"consistent\", \"asterisk\", \"plus\", \"dash\", \"sublist\"; default\n\"consistent\")</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when the symbols used in the document for unordered\nlist items do not match the configured unordered list style:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   Item 1\n\n<span class=\"token list punctuation\">*</span>   Item 2\n\n<span class=\"token list punctuation\">-</span>   Item 3</code></pre></div>\n<p>To fix this issue, use the configured style for list items throughout the\ndocument:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   Item 1\n<span class=\"token list punctuation\">-</span>   Item 2\n<span class=\"token list punctuation\">-</span>   Item 3</code></pre></div>\n<p>The configured list style can be a specific symbol to use (asterisk, plus, dash),\nto ensure that all list styling is consistent, or to ensure that each\nsublist has a consistent symbol that differs from its parent list.</p>\n<p>For example, the following is valid for the <code class=\"language-text\">sublist</code> style because the outer-most\nindent uses asterisk, the middle indent uses plus, and the inner-most indent uses\ndash:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   Item 1\n    <span class=\"token list punctuation\">-</span>   Item 2\n        <span class=\"token list punctuation\">-</span>   Item 3\n    <span class=\"token list punctuation\">-</span>   Item 4\n<span class=\"token list punctuation\">-</span>   Item 4\n    <span class=\"token list punctuation\">-</span>   Item 5</code></pre></div>\n<p>Rationale: Consistent formatting makes it easier to understand a document.</p>\n<a name=\"md005\">\n</a>\n<h2>MD005 - Inconsistent indentation for list items at the same level</h2>\n<p>Tags: bullet, ul, indentation</p>\n<p>Aliases: list-indent</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when list items are parsed as being at the same level,\nbut don't have the same indentation:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   Item 1\n    <span class=\"token list punctuation\">-</span>   Nested Item 1\n    <span class=\"token list punctuation\">-</span>   Nested Item 2\n    <span class=\"token list punctuation\">-</span>   A misaligned item</code></pre></div>\n<p>Usually, this rule will be triggered because of a typo. Correct the indentation\nfor the list to fix it:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   Item 1\n    <span class=\"token list punctuation\">-</span>   Nested Item 1\n    <span class=\"token list punctuation\">-</span>   Nested Item 2\n    <span class=\"token list punctuation\">-</span>   Nested Item 3</code></pre></div>\n<p>Sequentially-ordered list markers are usually left-aligned such that all items\nhave the same starting column:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">... 8. Item 9. Item 10. Item 11. Item\n...</code></pre></div>\n<p>This rule also supports right-alignment of list markers such that all items have\nthe same ending column:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">... 8. Item 9. Item 10. Item 11. Item\n...</code></pre></div>\n<p>Rationale: Violations of this rule can lead to improperly rendered content.</p>\n<a name=\"md006\">\n</a>\n<h2><del>MD006 - Consider starting bulleted lists at the beginning of the line</del></h2>\n<p>Tags: bullet, ul, indentation</p>\n<p>Aliases: ul-start-left</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when top-level lists don't start at the beginning of a\nline:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text\n\n<span class=\"token list punctuation\">-</span>   List item\n<span class=\"token list punctuation\">-</span>   List item</code></pre></div>\n<p>To fix, ensure that top-level list items are not indented:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some test\n\n<span class=\"token list punctuation\">-</span>   List item\n<span class=\"token list punctuation\">-</span>   List item</code></pre></div>\n<p>Note: This rule is triggered for the following scenario because the unordered\nsublist is not recognized as such by the parser. Not being nested 3 characters\nas required by the outer ordered list, it creates a top-level unordered list\ninstead.</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">1.</span> List item\n\n<span class=\"token list punctuation\">-</span>   List item\n<span class=\"token list punctuation\">-</span>   List item\n\n<span class=\"token list punctuation\">1.</span> List item</code></pre></div>\n<p>Rationale: Starting lists at the beginning of the line means that nested list\nitems can all be indented by the same amount when an editor's indent function\nor the tab key is used to indent. Starting a list 1 space in means that the\nindent of the first nested list is less than the indent of the second level (3\ncharacters if you use 4 space tabs, or 1 character if you use 2 space tabs).</p>\n<a name=\"md007\">\n</a>\n<h2>MD007 - Unordered list indentation</h2>\n<p>Tags: bullet, ul, indentation</p>\n<p>Aliases: ul-indent</p>\n<p>Parameters: indent, start_indented (number; default 2, boolean; default false)</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when list items are not indented by the configured\nnumber of spaces (default: 2).</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   List item\n    <span class=\"token list punctuation\">-</span>   Nested list item indented by 3 spaces</code></pre></div>\n<p>Corrected Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   List item\n    <span class=\"token list punctuation\">-</span>   Nested list item indented by 2 spaces</code></pre></div>\n<p>Note: This rule applies to a sublist only if its parent lists are all also\nunordered (otherwise, extra indentation of ordered lists interferes with the\nrule).</p>\n<p>The <code class=\"language-text\">start_indented</code> parameter allows the first level of lists to be indented by\nthe configured number of spaces rather than starting at zero (the inverse of\nMD006).</p>\n<p>Rationale: Indenting by 2 spaces allows the content of a nested list to be in\nline with the start of the content of the parent list when a single space is\nused after the list marker. Indenting by 4 spaces is consistent with code blocks\nand simpler for editors to implement. Additionally, this can be a compatibility\nissue for multi-markdown parsers, which require 4-space indents. More information:\n<a href=\"https://cirosantilli.com/markdown-style-guide#indentation-of-content-inside-lists\">https://cirosantilli.com/markdown-style-guide#indentation-of-content-inside-lists</a>\nand <a href=\"http://support.markedapp.com/discussions/problems/21-sub-lists-not-indenting\">http://support.markedapp.com/discussions/problems/21-sub-lists-not-indenting</a>.</p>\n<p>Note: See <a href=\"Prettier.md\">Prettier.md</a> for compatibility information.</p>\n<a name=\"md009\">\n</a>\n<h2>MD009 - Trailing spaces</h2>\n<p>Tags: whitespace</p>\n<p>Aliases: no-trailing-spaces</p>\n<!-- markdownlint-disable line-length -->\n<p>Parameters: br<em>spaces, list</em>item<em>empty</em>lines, strict (number; default 2, boolean; default false, boolean; default false)</p>\n<!-- markdownlint-restore -->\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered on any lines that end with unexpected whitespace. To fix this,\nremove the trailing space from the end of the line.</p>\n<p>Note: Trailing space is allowed in indented and fenced code blocks because some\nlanguages require it.</p>\n<p>The <code class=\"language-text\">br_spaces</code> parameter allows an exception to this rule for a specific number\nof trailing spaces, typically used to insert an explicit line break. The default\nvalue allows 2 spaces to indicate a hard break (&#x3C;br> element).</p>\n<p>Note: You must set <code class=\"language-text\">br_spaces</code> to a value >= 2 for this parameter to take effect.\nSetting <code class=\"language-text\">br_spaces</code> to 1 behaves the same as 0, disallowing any trailing spaces.</p>\n<p>By default, this rule will not trigger when the allowed number of spaces is used,\neven when it doesn't create a hard break (for example, at the end of a paragraph).\nTo report such instances as well, set the <code class=\"language-text\">strict</code> parameter to <code class=\"language-text\">true</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Text text text\ntext[2 spaces]</code></pre></div>\n<p>Using spaces to indent blank lines inside a list item is usually not necessary,\nbut some parsers require it. Set the <code class=\"language-text\">list_item_empty_lines</code> parameter to <code class=\"language-text\">true</code>\nto allow this (even when <code class=\"language-text\">strict</code> is <code class=\"language-text\">true</code>):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   list item text\n    [2 spaces]\n    list item text</code></pre></div>\n<p>Rationale: Except when being used to create a line break, trailing whitespace\nhas no purpose and does not affect the rendering of content.</p>\n<a name=\"md010\">\n</a>\n<h2>MD010 - Hard tabs</h2>\n<p>Tags: whitespace, hard_tab</p>\n<p>Aliases: no-hard-tabs</p>\n<p>Parameters: code<em>blocks, spaces</em>per_tab (boolean; default true, number; default 1)</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered by any lines that contain hard tab characters instead\nof using spaces for indentation. To fix this, replace any hard tab characters\nwith spaces instead.</p>\n<p>Example:</p>\n<!-- markdownlint-disable no-hard-tabs -->\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text\n\n<span class=\"token code keyword\">    * hard tab character used to indent the list item</span></code></pre></div>\n<!-- markdownlint-restore -->\n<p>Corrected example:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text\n\n<span class=\"token code keyword\">    * Spaces used to indent the list item instead</span></code></pre></div>\n<p>You have the option to exclude this rule for code blocks. To do so, set the\n<code class=\"language-text\">code_blocks</code> parameter to <code class=\"language-text\">false</code>. Code blocks are included by default since\nhandling of tabs by tools is often inconsistent (ex: using 4 vs. 8 spaces).</p>\n<p>If you would like the fixer to change tabs to x spaces, then configure the <code class=\"language-text\">spaces_per_tab</code>\nparameter to the number x. The default value would be 1.</p>\n<p>Rationale: Hard tabs are often rendered inconsistently by different editors and\ncan be harder to work with than spaces.</p>\n<a name=\"md011\">\n</a>\n<h2>MD011 - Reversed link syntax</h2>\n<p>Tags: links</p>\n<p>Aliases: no-reversed-links</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when text that appears to be a link is encountered, but\nwhere the syntax appears to have been reversed (the <code class=\"language-text\">[]</code> and <code class=\"language-text\">()</code> are\nreversed):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">(Incorrect link syntax)[https://www.example.com/]</code></pre></div>\n<p>To fix this, swap the <code class=\"language-text\">[]</code> and <code class=\"language-text\">()</code> around:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\">[<span class=\"token content\">Correct link syntax</span>](<span class=\"token url\">https://www.example.com/</span>)</span></code></pre></div>\n<p>Note: <a href=\"https://en.wikipedia.org/wiki/Markdown_Extra\">Markdown Extra</a>-style\nfootnotes do not trigger this rule:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">For (example)[^1]</code></pre></div>\n<p>Rationale: Reversed links are not rendered as usable links.</p>\n<a name=\"md012\">\n</a>\n<h2>MD012 - Multiple consecutive blank lines</h2>\n<p>Tags: whitespace, blank_lines</p>\n<p>Aliases: no-multiple-blanks</p>\n<p>Parameters: maximum (number; default 1)</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when there are multiple consecutive blank lines in the\ndocument:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text here\n\nSome more text here</code></pre></div>\n<p>To fix this, delete the offending lines:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text here\n\nSome more text here</code></pre></div>\n<p>Note: this rule will not be triggered if there are multiple consecutive blank\nlines inside code blocks.</p>\n<p>Note: The <code class=\"language-text\">maximum</code> parameter can be used to configure the maximum number of\nconsecutive blank lines.</p>\n<p>Rationale: Except in a code block, blank lines serve no purpose and do not\naffect the rendering of content.</p>\n<a name=\"md013\">\n</a>\n<h2>MD013 - Line length</h2>\n<p>Tags: line_length</p>\n<p>Aliases: line-length</p>\n<!-- markdownlint-disable line-length -->\n<p>Parameters: line<em>length, heading</em>line<em>length, code</em>block<em>line</em>length, code<em>blocks, tables, headings, headers, strict, stern (number; default 80 for *\\</em>length, boolean; default true (except strict/stern which default false))</p>\n<!-- markdownlint-restore -->\n<blockquote>\n<p>If <code class=\"language-text\">headings</code> is not provided, <code class=\"language-text\">headers</code> (deprecated) will be used.</p>\n</blockquote>\n<p>This rule is triggered when there are lines that are longer than the\nconfigured <code class=\"language-text\">line_length</code> (default: 80 characters). To fix this, split the line\nup into multiple lines. To set a different maximum length for headings, use\n<code class=\"language-text\">heading_line_length</code>. To set a different maximum length for code blocks, use\n<code class=\"language-text\">code_block_line_length</code></p>\n<p>This rule has an exception when there is no whitespace beyond the configured\nline length. This allows you to still include items such as long URLs without\nbeing forced to break them in the middle. To disable this exception, set the\n<code class=\"language-text\">strict</code> parameter to <code class=\"language-text\">true</code> to report an issue when any line is too long.\nTo warn for lines that are too long and could be fixed but allow lines without\nspaces, set the <code class=\"language-text\">stern</code> parameter to <code class=\"language-text\">true</code>.</p>\n<p>For example (assuming normal behavior):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">IF THIS LINE IS THE MAXIMUM LENGTH\nThis line is okay because there are-no-spaces-beyond-that-length\nAnd this line is a violation because there are\nThis-line-is-also-okay-because-there-are-no-spaces</code></pre></div>\n<p>In <code class=\"language-text\">strict</code> or <code class=\"language-text\">stern</code> modes, the two middle lines above are a violation. The\nthird line is a violation in <code class=\"language-text\">strict</code> mode but allowed in <code class=\"language-text\">stern</code> mode.</p>\n<p>You have the option to exclude this rule for code blocks, tables, or headings.\nTo do so, set the <code class=\"language-text\">code_blocks</code>, <code class=\"language-text\">tables</code>, or <code class=\"language-text\">headings</code> parameter(s) to false.</p>\n<p>Code blocks are included in this rule by default since it is often a\nrequirement for document readability, and tentatively compatible with code\nrules. Still, some languages do not lend themselves to short lines.</p>\n<p>Rationale: Extremely long lines can be difficult to work with in some editors.\nMore information: <a href=\"https://cirosantilli.com/markdown-style-guide#line-wrapping\">https://cirosantilli.com/markdown-style-guide#line-wrapping</a>.</p>\n<a name=\"md014\">\n</a>\n<h2>MD014 - Dollar signs used before commands without showing output</h2>\n<p>Tags: code</p>\n<p>Aliases: commands-show-output</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when there are code blocks showing shell commands to be\ntyped, and <em>all</em> of the shell commands are preceded by dollar signs ($):</p>\n<!-- markdownlint-disable commands-show-output -->\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">$ ls\n$ cat foo\n$ less bar</code></pre></div>\n<!-- markdownlint-restore -->\n<p>The dollar signs are unnecessary in this situation, and should not be\nincluded:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">ls\ncat foo\nless bar</code></pre></div>\n<p>Showing output for commands preceded by dollar signs does not trigger this rule:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">$ ls\nfoo bar\n$ cat foo\nHello world\n$ cat bar\nbaz</code></pre></div>\n<p>Because some commands do not produce output, it is not a violation if <em>some</em>\ncommands do not have output:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">$ mkdir test\nmkdir: created directory 'test'\n$ ls test</code></pre></div>\n<p>Rationale: It is easier to copy/paste and less noisy if the dollar signs\nare omitted when they are not needed. See\n<a href=\"https://cirosantilli.com/markdown-style-guide#dollar-signs-in-shell-code\">https://cirosantilli.com/markdown-style-guide#dollar-signs-in-shell-code</a>\nfor more information.</p>\n<a name=\"md018\">\n</a>\n<h2>MD018 - No space after hash on atx style heading</h2>\n<p>Tags: headings, headers, atx, spaces</p>\n<p>Aliases: no-missing-space-atx</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when spaces are missing after the hash characters\nin an atx style heading:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span>Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span>Heading 2</span></code></pre></div>\n<p>To fix this, separate the heading text from the hash character by a single\nspace:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span></code></pre></div>\n<p>Rationale: Violations of this rule can lead to improperly rendered content.</p>\n<a name=\"md019\">\n</a>\n<h2>MD019 - Multiple spaces after hash on atx style heading</h2>\n<p>Tags: headings, headers, atx, spaces</p>\n<p>Aliases: no-multiple-space-atx</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when more than one space is used to separate the\nheading text from the hash characters in an atx style heading:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span></code></pre></div>\n<p>To fix this, separate the heading text from the hash character by a single\nspace:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span></code></pre></div>\n<p>Rationale: Extra space has no purpose and does not affect the rendering of\ncontent.</p>\n<a name=\"md020\">\n</a>\n<h2>MD020 - No space inside hashes on closed atx style heading</h2>\n<p>Tags: headings, headers, atx_closed, spaces</p>\n<p>Aliases: no-missing-space-closed-atx</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when spaces are missing inside the hash characters\nin a closed atx style heading:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span>Heading 1<span class=\"token punctuation\">#</span></span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span>Heading 2<span class=\"token punctuation\">##</span></span></code></pre></div>\n<p>To fix this, separate the heading text from the hash character by a single\nspace:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span></code></pre></div>\n<p>Note: this rule will fire if either side of the heading is missing spaces.</p>\n<p>Rationale: Violations of this rule can lead to improperly rendered content.</p>\n<a name=\"md021\">\n</a>\n<h2>MD021 - Multiple spaces inside hashes on closed atx style heading</h2>\n<p>Tags: headings, headers, atx_closed, spaces</p>\n<p>Aliases: no-multiple-space-closed-atx</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when more than one space is used to separate the\nheading text from the hash characters in a closed atx style heading:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span></code></pre></div>\n<p>To fix this, separate the heading text from the hash character by a single\nspace:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span></code></pre></div>\n<p>Note: this rule will fire if either side of the heading contains multiple\nspaces.</p>\n<p>Rationale: Extra space has no purpose and does not affect the rendering of\ncontent.</p>\n<a name=\"md022\">\n</a>\n<h2>MD022 - Headings should be surrounded by blank lines</h2>\n<p>Tags: headings, headers, blank_lines</p>\n<p>Aliases: blanks-around-headings, blanks-around-headers</p>\n<p>Parameters: lines<em>above, lines</em>below (number; default 1)</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when headings (any style) are either not preceded or not\nfollowed by at least one blank line:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\nSome text\n\nSome more text\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span></code></pre></div>\n<p>To fix this, ensure that all headings have a blank line both before and after\n(except where the heading is at the beginning or end of the document):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading 1</span>\n\nSome text\n\nSome more text\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading 2</span></code></pre></div>\n<p>The <code class=\"language-text\">lines_above</code> and <code class=\"language-text\">lines_below</code> parameters can be used to specify a different\nnumber of blank lines (including 0) above or below each heading.</p>\n<p>Note: If <code class=\"language-text\">lines_above</code> or <code class=\"language-text\">lines_below</code> are configured to require more than one\nblank line, <a href=\"#md012\">MD012/no-multiple-blanks</a> should also be customized.</p>\n<p>Rationale: Aside from aesthetic reasons, some parsers, including <code class=\"language-text\">kramdown</code>, will\nnot parse headings that don't have a blank line before, and will parse them as\nregular text.</p>\n<a name=\"md023\">\n</a>\n<h2>MD023 - Headings must start at the beginning of the line</h2>\n<p>Tags: headings, headers, spaces</p>\n<p>Aliases: heading-start-left, header-start-left</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when a heading is indented by one or more spaces:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text\n\n<span class=\"token title important\"><span class=\"token punctuation\">#</span> Indented heading</span></code></pre></div>\n<p>To fix this, ensure that all headings start at the beginning of the line:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text\n\n<span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading</span></code></pre></div>\n<p>Rationale: Headings that don't start at the beginning of the line will not be\nparsed as headings, and will instead appear as regular text.</p>\n<a name=\"md024\">\n</a>\n<h2>MD024 - Multiple headings with the same content</h2>\n<p>Tags: headings, headers</p>\n<p>Aliases: no-duplicate-heading, no-duplicate-header</p>\n<p>Parameters: siblings<em>only, allow</em>different_nesting (boolean; default <code class=\"language-text\">false</code>)</p>\n<p>This rule is triggered if there are multiple headings in the document that have\nthe same text:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Some text</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Some text</span></code></pre></div>\n<p>To fix this, ensure that the content of each heading is different:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Some text</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Some more text</span></code></pre></div>\n<p>If the parameter <code class=\"language-text\">siblings_only</code> (alternatively <code class=\"language-text\">allow_different_nesting</code>) is\nset to <code class=\"language-text\">true</code>, heading duplication is allowed for non-sibling headings (common\nin changelogs):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Change log</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> 1.0.0</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Features</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> 2.0.0</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Features</span></code></pre></div>\n<p>Rationale: Some markdown parsers generate anchors for headings based on the\nheading name; headings with the same content can cause problems with that.</p>\n<a name=\"md025\">\n</a>\n<h2>MD025 - Multiple top-level headings in the same document</h2>\n<p>Tags: headings, headers</p>\n<p>Aliases: single-title, single-h1</p>\n<p>Parameters: level, front<em>matter</em>title (number; default 1, string; default \"^\\s<em>\"?title\"?\\s</em>[:=]\")</p>\n<p>This rule is triggered when a top-level heading is in use (the first line of\nthe file is an h1 heading), and more than one h1 heading is in use in the\ndocument:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Top level heading</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">#</span> Another top-level heading</span></code></pre></div>\n<p>To fix, structure your document so there is a single h1 heading that is\nthe title for the document. Subsequent headings must be\nlower-level headings (h2, h3, etc.):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Title</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Heading</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Another heading</span></code></pre></div>\n<p>Note: The <code class=\"language-text\">level</code> parameter can be used to change the top-level (ex: to h2) in\ncases where an h1 is added externally.</p>\n<p>If <a href=\"https://en.wikipedia.org/wiki/YAML\">YAML</a> front matter is present and contains\na <code class=\"language-text\">title</code> property (commonly used with blog posts), this rule treats that as a top\nlevel heading and will report a violation for any subsequent top-level headings.\nTo use a different property name in the front matter, specify the text of a regular\nexpression via the <code class=\"language-text\">front_matter_title</code> parameter. To disable the use of front\nmatter by this rule, specify <code class=\"language-text\">\"\"</code> for <code class=\"language-text\">front_matter_title</code>.</p>\n<p>Rationale: A top-level heading is an h1 on the first line of the file, and\nserves as the title for the document. If this convention is in use, then there\ncan not be more than one title for the document, and the entire document\nshould be contained within this heading.</p>\n<a name=\"md026\">\n</a>\n<h2>MD026 - Trailing punctuation in heading</h2>\n<p>Tags: headings, headers</p>\n<p>Aliases: no-trailing-punctuation</p>\n<p>Parameters: punctuation (string; default \".,;:!。，；：！\")</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered on any heading that has one of the specified normal or\nfull-width punctuation characters as the last character in the line:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> This is a heading.</span></code></pre></div>\n<p>To fix this, remove the trailing punctuation:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> This is a heading</span></code></pre></div>\n<p>Note: The <code class=\"language-text\">punctuation</code> parameter can be used to specify what characters count\nas punctuation at the end of a heading. For example, you can change it to\n<code class=\"language-text\">\".,;:\"</code> to allow headings that end with an exclamation point. <code class=\"language-text\">?</code> is\nallowed by default because of how common it is in headings of FAQ-style documents.\nSetting the <code class=\"language-text\">punctuation</code> parameter to <code class=\"language-text\">\"\"</code> allows all characters - and is\nequivalent to disabling the rule.</p>\n<p>Note: The trailing semicolon of\n<a href=\"https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references\">HTML entity references</a>\nlike <code class=\"language-text\">&amp;copy;</code>, <code class=\"language-text\">&amp;#169;</code>, and <code class=\"language-text\">&amp;#x000A9;</code> is ignored by this rule.</p>\n<p>Rationale: Headings are not meant to be full sentences. More information:\n<a href=\"https://cirosantilli.com/markdown-style-guide#punctuation-at-the-end-of-headers\">https://cirosantilli.com/markdown-style-guide#punctuation-at-the-end-of-headers</a></p>\n<a name=\"md027\">\n</a>\n<h2>MD027 - Multiple spaces after blockquote symbol</h2>\n<p>Tags: blockquote, whitespace, indentation</p>\n<p>Aliases: no-multiple-space-blockquote</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when blockquotes have more than one space after the\nblockquote (<code class=\"language-text\">></code>) symbol:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token blockquote punctuation\">></span> This is a blockquote with bad indentation\n<span class=\"token blockquote punctuation\">></span> there should only be one.</code></pre></div>\n<p>To fix, remove any extraneous space:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token blockquote punctuation\">></span> This is a blockquote with correct\n<span class=\"token blockquote punctuation\">></span> indentation.</code></pre></div>\n<p>Rationale: Consistent formatting makes it easier to understand a document.</p>\n<a name=\"md028\">\n</a>\n<h2>MD028 - Blank line inside blockquote</h2>\n<p>Tags: blockquote, whitespace</p>\n<p>Aliases: no-blanks-blockquote</p>\n<p>This rule is triggered when two blockquote blocks are separated by nothing\nexcept for a blank line:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token blockquote punctuation\">></span> This is a blockquote\n<span class=\"token blockquote punctuation\">></span> which is immediately followed by\n\n<span class=\"token blockquote punctuation\">></span> this blockquote. Unfortunately\n<span class=\"token blockquote punctuation\">></span> In some parsers, these are treated as the same blockquote.</code></pre></div>\n<p>To fix this, ensure that any blockquotes that are right next to each other\nhave some text in between:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token blockquote punctuation\">></span> This is a blockquote.\n\nAnd Jimmy also said:\n\n<span class=\"token blockquote punctuation\">></span> This too is a blockquote.</code></pre></div>\n<p>Alternatively, if they are supposed to be the same quote, then add the\nblockquote symbol at the beginning of the blank line:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token blockquote punctuation\">></span> This is a blockquote.\n<span class=\"token blockquote punctuation\">></span>\n<span class=\"token blockquote punctuation\">></span> This is the same blockquote.</code></pre></div>\n<p>Rationale: Some markdown parsers will treat two blockquotes separated by one\nor more blank lines as the same blockquote, while others will treat them as\nseparate blockquotes.</p>\n<a name=\"md029\">\n</a>\n<h2>MD029 - Ordered list item prefix</h2>\n<p>Tags: ol</p>\n<p>Aliases: ol-prefix</p>\n<p>Parameters: style (\"one\", \"ordered\", \"one<em>or</em>ordered\", \"zero\"; default \"one<em>or</em>ordered\")</p>\n<p>This rule is triggered for ordered lists that do not either start with '1.' or\ndo not have a prefix that increases in numerical order (depending on the\nconfigured style). The less-common pattern of using '0.' as a first prefix or\nfor all prefixes is also supported.</p>\n<p>Example valid list if the style is configured as 'one':</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">1.</span> Do this.\n<span class=\"token list punctuation\">1.</span> Do that.\n<span class=\"token list punctuation\">1.</span> Done.</code></pre></div>\n<p>Examples of valid lists if the style is configured as 'ordered':</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">1.</span> Do this.\n<span class=\"token list punctuation\">2.</span> Do that.\n<span class=\"token list punctuation\">3.</span> Done.</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">0.</span> Do this.\n<span class=\"token list punctuation\">1.</span> Do that.\n<span class=\"token list punctuation\">2.</span> Done.</code></pre></div>\n<p>All three examples are valid when the style is configured as 'one<em>or</em>ordered'.</p>\n<p>Example valid list if the style is configured as 'zero':</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">0.</span> Do this.\n<span class=\"token list punctuation\">1.</span> Do that.\n<span class=\"token list punctuation\">2.</span> Done.</code></pre></div>\n<p>Example invalid list for all styles:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">1.</span> Do this.\n<span class=\"token list punctuation\">2.</span> Done.</code></pre></div>\n<p>This rule supports 0-prefixing ordered list items for uniform indentation:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">... 08. Item 09. Item 10. Item 11. Item\n...</code></pre></div>\n<p>Note: This rule will report violations for cases like the following where an\nimproperly-indented code block (or similar) appears between two list items and\n\"breaks\" the list in two:</p>\n<!-- markdownlint-disable code-fence-style -->\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">1.</span> First list\n\n<span class=\"token code\"><span class=\"token punctuation\">```</span><span class=\"token code-language\">text</span>\n<span class=\"token code-block language-text\">Code block</span>\n<span class=\"token punctuation\">```</span></span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. Second list</code></pre></div>\n<p>The fix is to indent the code block so it becomes part of the preceding list\nitem as intended:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">1.</span> First list\n\n<span class=\"token code keyword\">    ```text\n    Code block\n    ```</span>\n\n<span class=\"token list punctuation\">2.</span> Still first list</code></pre></div>\n<!-- markdownlint-restore -->\n<p>Rationale: Consistent formatting makes it easier to understand a document.</p>\n<a name=\"md030\">\n</a>\n<h2>MD030 - Spaces after list markers</h2>\n<p>Tags: ol, ul, whitespace</p>\n<p>Aliases: list-marker-space</p>\n<p>Parameters: ul<em>single, ol</em>single, ul<em>multi, ol</em>multi (number; default 1)</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule checks for the number of spaces between a list marker (e.g. '<code class=\"language-text\">-</code>',\n'<code class=\"language-text\">*</code>', '<code class=\"language-text\">+</code>' or '<code class=\"language-text\">1.</code>') and the text of the list item.</p>\n<p>The number of spaces checked for depends on the document style in use, but the\ndefault is 1 space after any list marker:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   Foo\n<span class=\"token list punctuation\">-</span>   Bar\n<span class=\"token list punctuation\">-</span>   Baz\n\n<span class=\"token list punctuation\">1.</span> Foo\n<span class=\"token list punctuation\">1.</span> Bar\n<span class=\"token list punctuation\">1.</span> Baz\n\n<span class=\"token list punctuation\">1.</span> Foo\n    <span class=\"token list punctuation\">-</span> Bar\n<span class=\"token list punctuation\">1.</span> Baz</code></pre></div>\n<p>A document style may change the number of spaces after unordered list items\nand ordered list items independently, as well as based on whether the content\nof every item in the list consists of a single paragraph or multiple\nparagraphs (including sub-lists and code blocks).</p>\n<p>For example, the style guide at\n<a href=\"https://cirosantilli.com/markdown-style-guide#spaces-after-list-marker\">https://cirosantilli.com/markdown-style-guide#spaces-after-list-marker</a>\nspecifies that 1 space after the list marker should be used if every item in\nthe list fits within a single paragraph, but to use 2 or 3 spaces (for ordered\nand unordered lists respectively) if there are multiple paragraphs of content\ninside the list:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   Foo\n<span class=\"token list punctuation\">-</span>   Bar\n<span class=\"token list punctuation\">-</span>   Baz</code></pre></div>\n<p>vs.</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">-</span>   Foo\n\n<span class=\"token code keyword\">    Second paragraph</span>\n\n<span class=\"token list punctuation\">-</span>   Bar</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token list punctuation\">1.</span>  Foo\n\n<span class=\"token code keyword\">    Second paragraph</span>\n\n<span class=\"token list punctuation\">1.</span>  Bar</code></pre></div>\n<p>To fix this, ensure the correct number of spaces are used after the list marker\nfor your selected document style.</p>\n<p>Rationale: Violations of this rule can lead to improperly rendered content.</p>\n<p>Note: See <a href=\"Prettier.md\">Prettier.md</a> for compatibility information.</p>\n<a name=\"md031\">\n</a>\n<h2>MD031 - Fenced code blocks should be surrounded by blank lines</h2>\n<p>Tags: code, blank_lines</p>\n<p>Aliases: blanks-around-fences</p>\n<p>Parameters: list_items (boolean; default true)</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when fenced code blocks are either not preceded or not\nfollowed by a blank line:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text</code></pre></div>\n<p>Code block</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Another code block</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some more text</code></pre></div>\n<p>To fix this, ensure that all fenced code blocks have a blank line both before\nand after (except where the block is at the beginning or end of the document):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text</code></pre></div>\n<p>Code block</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Another code block</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some more text</code></pre></div>\n<p>Set the <code class=\"language-text\">list_items</code> parameter to <code class=\"language-text\">false</code> to disable this rule for list items.\nDisabling this behavior for lists can be useful if it is necessary to create a\n<a href=\"https://spec.commonmark.org/0.29/#tight\">tight</a> list containing a code fence.</p>\n<p>Rationale: Aside from aesthetic reasons, some parsers, including kramdown, will\nnot parse fenced code blocks that don't have blank lines before and after them.</p>\n<a name=\"md032\">\n</a>\n<h2>MD032 - Lists should be surrounded by blank lines</h2>\n<p>Tags: bullet, ul, ol, blank_lines</p>\n<p>Aliases: blanks-around-lists</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when lists (of any kind) are either not preceded or not\nfollowed by a blank line:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text\n\n<span class=\"token list punctuation\">-</span>   Some\n<span class=\"token list punctuation\">-</span>   List\n\n<span class=\"token list punctuation\">1.</span> Some\n<span class=\"token list punctuation\">2.</span> List\n   Some text</code></pre></div>\n<p>To fix this, ensure that all lists have a blank line both before and after\n(except where the block is at the beginning or end of the document):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Some text\n\n<span class=\"token list punctuation\">-</span>   Some\n<span class=\"token list punctuation\">-</span>   List\n\n<span class=\"token list punctuation\">1.</span> Some\n<span class=\"token list punctuation\">2.</span> List\n\nSome text</code></pre></div>\n<p>Rationale: Aside from aesthetic reasons, some parsers, including kramdown, will\nnot parse lists that don't have blank lines before and after them.</p>\n<a name=\"md033\">\n</a>\n<h2>MD033 - Inline HTML</h2>\n<p>Tags: html</p>\n<p>Aliases: no-inline-html</p>\n<p>Parameters: allowed_elements (array of string; default empty)</p>\n<p>This rule is triggered whenever raw HTML is used in a markdown document:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span>Inline HTML heading<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>To fix this, use 'pure' markdown instead of including raw HTML:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Markdown heading</span></code></pre></div>\n<p>Note: To allow specific HTML elements, use the 'allowed_elements' parameter.</p>\n<p>Rationale: Raw HTML is allowed in markdown, but this rule is included for\nthose who want their documents to only include \"pure\" markdown, or for those\nwho are rendering markdown documents in something other than HTML.</p>\n<a name=\"md034\">\n</a>\n<h2>MD034 - Bare URL used</h2>\n<p>Tags: links, url</p>\n<p>Aliases: no-bare-urls</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered whenever a URL is given that isn't surrounded by angle\nbrackets:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">For more information, see https://www.example.com/.</code></pre></div>\n<p>To fix this, add angle brackets around the URL:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">For more information, see &lt;https://www.example.com/>.</code></pre></div>\n<p>Note: To use a bare URL without it being converted into a link, enclose it in\na code block, otherwise in some markdown parsers it <em>will</em> be converted:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token code-snippet code keyword\">`https://www.example.com`</span></code></pre></div>\n<p>Note: The following scenario does <em>not</em> trigger this rule to avoid conflicts\nwith <code class=\"language-text\">MD011</code>/<code class=\"language-text\">no-reversed-links</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">[https://www.example.com]</code></pre></div>\n<p>The use of quotes around a bare link will <em>not</em> trigger this rule, either:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">\"https://www.example.com\"\n'https://www.example.com'</code></pre></div>\n<p>Rationale: Without angle brackets, the URL isn't converted into a link by many\nmarkdown parsers.</p>\n<a name=\"md035\">\n</a>\n<h2>MD035 - Horizontal rule style</h2>\n<p>Tags: hr</p>\n<p>Aliases: hr-style</p>\n<p>Parameters: style (\"consistent\", \"---\", \"***\", or other string specifying the\nhorizontal rule; default \"consistent\")</p>\n<p>This rule is triggered when inconsistent styles of horizontal rules are used\nin the document:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token front-matter-block\"><span class=\"token punctuation\">---</span>\n<span class=\"token punctuation\">---</span></span>\n\n<span class=\"token hr punctuation\">---</span>\n\n<span class=\"token hr punctuation\">---</span>\n\n<span class=\"token hr punctuation\">---</span></code></pre></div>\n<p>To fix this, ensure any horizontal rules used in the document are consistent,\nor match the given style if the rule is so configured:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token front-matter-block\"><span class=\"token punctuation\">---</span>\n<span class=\"token punctuation\">---</span></span></code></pre></div>\n<p>Note: by default, this rule is configured to just require that all horizontal\nrules in the document are the same and will trigger if any of the horizontal\nrules are different than the first one encountered in the document. If you\nwant to configure the rule to match a specific style, the parameter given to\nthe 'style' option is a string containing the exact horizontal rule text that\nis allowed.</p>\n<p>Rationale: Consistent formatting makes it easier to understand a document.</p>\n<a name=\"md036\">\n</a>\n<h2>MD036 - Emphasis used instead of a heading</h2>\n<p>Tags: headings, headers, emphasis</p>\n<p>Aliases: no-emphasis-as-heading, no-emphasis-as-header</p>\n<p>Parameters: punctuation (string; default \".,;:!?。，；：！？\")</p>\n<p>This check looks for instances where emphasized (i.e. bold or italic) text is\nused to separate sections, where a heading should be used instead:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token bold\"><span class=\"token punctuation\">**</span><span class=\"token content\">My document</span><span class=\"token punctuation\">**</span></span>\n\nLorem ipsum dolor sit amet...\n\n<span class=\"token italic\"><span class=\"token punctuation\">_</span><span class=\"token content\">Another section</span><span class=\"token punctuation\">_</span></span>\n\nConsectetur adipiscing elit, sed do eiusmod.</code></pre></div>\n<p>To fix this, use markdown headings instead of emphasized text to denote\nsections:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> My document</span>\n\nLorem ipsum dolor sit amet...\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Another section</span>\n\nConsectetur adipiscing elit, sed do eiusmod.</code></pre></div>\n<p>Note: This rule looks for single-line paragraphs that consist entirely\nof emphasized text. It won't fire on emphasis used within regular text,\nmulti-line emphasized paragraphs, or paragraphs ending in punctuation\n(normal or full-width). Similarly to rule MD026, you can configure what\ncharacters are recognized as punctuation.</p>\n<p>Rationale: Using emphasis instead of a heading prevents tools from inferring\nthe structure of a document. More information:\n<a href=\"https://cirosantilli.com/markdown-style-guide#emphasis-vs-headers\">https://cirosantilli.com/markdown-style-guide#emphasis-vs-headers</a>.</p>\n<a name=\"md037\">\n</a>\n<h2>MD037 - Spaces inside emphasis markers</h2>\n<p>Tags: whitespace, emphasis</p>\n<p>Aliases: no-space-in-emphasis</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when emphasis markers (bold, italic) are used, but they\nhave spaces between the markers and the text:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Here is some <span class=\"token bold\"><span class=\"token punctuation\">**</span><span class=\"token content\"> bold </span><span class=\"token punctuation\">**</span></span> text.\n\nHere is some <span class=\"token italic\"><span class=\"token punctuation\">_</span><span class=\"token content\"> italic </span><span class=\"token punctuation\">_</span></span> text.\n\nHere is some more <span class=\"token bold\"><span class=\"token punctuation\">**</span><span class=\"token content\"> bold </span><span class=\"token punctuation\">**</span></span> text.\n\nHere is some more <span class=\"token italic\"><span class=\"token punctuation\">_</span><span class=\"token content\"> italic </span><span class=\"token punctuation\">_</span></span> text.</code></pre></div>\n<p>To fix this, remove the spaces around the emphasis markers:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">Here is some <span class=\"token bold\"><span class=\"token punctuation\">**</span><span class=\"token content\">bold</span><span class=\"token punctuation\">**</span></span> text.\n\nHere is some <span class=\"token italic\"><span class=\"token punctuation\">_</span><span class=\"token content\">italic</span><span class=\"token punctuation\">_</span></span> text.\n\nHere is some more <span class=\"token bold\"><span class=\"token punctuation\">**</span><span class=\"token content\">bold</span><span class=\"token punctuation\">**</span></span> text.\n\nHere is some more <span class=\"token italic\"><span class=\"token punctuation\">_</span><span class=\"token content\">italic</span><span class=\"token punctuation\">_</span></span> text.</code></pre></div>\n<p>Rationale: Emphasis is only parsed as such when the asterisks/underscores\naren't surrounded by spaces. This rule attempts to detect where\nthey were surrounded by spaces, but it appears that emphasized text was\nintended by the author.</p>\n<a name=\"md038\">\n</a>\n<h2>MD038 - Spaces inside code span elements</h2>\n<p>Tags: whitespace, code</p>\n<p>Aliases: no-space-in-code</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered for code span elements that have spaces adjacent to the\nbackticks:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token code-snippet code keyword\">`some text `</span>\n\n<span class=\"token code-snippet code keyword\">` some text`</span></code></pre></div>\n<p>To fix this, remove any spaces adjacent to the backticks:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token code-snippet code keyword\">`some text`</span></code></pre></div>\n<p>Note: A single leading and trailing space is allowed by the specification and\nautomatically trimmed (to allow for embedded backticks):</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token code-snippet code keyword\">`` `backticks` ``</span></code></pre></div>\n<p>Note: A single leading or trailing space is allowed if used to separate code span\nmarkers from an embedded backtick:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token code-snippet code keyword\">`` ` embedded backtick``</span></code></pre></div>\n<p>Rationale: Violations of this rule can lead to improperly rendered content.</p>\n<a name=\"md039\">\n</a>\n<h2>MD039 - Spaces inside link text</h2>\n<p>Tags: whitespace, links</p>\n<p>Aliases: no-space-in-links</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered on links that have spaces surrounding the link text:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\">[<span class=\"token content\"> a link </span>](<span class=\"token url\">https://www.example.com/</span>)</span></code></pre></div>\n<p>To fix this, remove the spaces surrounding the link text:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\">[<span class=\"token content\">a link</span>](<span class=\"token url\">https://www.example.com/</span>)</span></code></pre></div>\n<p>Rationale: Consistent formatting makes it easier to understand a document.</p>\n<a name=\"md040\">\n</a>\n<h2>MD040 - Fenced code blocks should have a language specified</h2>\n<p>Tags: code, language</p>\n<p>Aliases: fenced-code-language</p>\n<p>This rule is triggered when fenced code blocks are used, but a language isn't\nspecified:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"></code></pre></div>\n<h1>!/bin/bash</h1>\n<p>echo Hello world</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To fix this, add a language specifier to the code block:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token code\"><span class=\"token punctuation\">```</span><span class=\"token code-language\">shell</span>\n<span class=\"token code-block language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n<span class=\"token builtin class-name\">echo</span> Hello world</span>\n<span class=\"token punctuation\">```</span></span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">To display a code block without syntax highlighting, use:\n\n```markdown\n```text\nPlain text in a code block</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Rationale: Specifying a language improves content rendering by using the\ncorrect syntax highlighting for code. More information:\n<a href=\"https://cirosantilli.com/markdown-style-guide#option-code-fenced\">https://cirosantilli.com/markdown-style-guide#option-code-fenced</a>.</p>\n<a name=\"md041\">\n</a>\n<h2>MD041 - First line in a file should be a top-level heading</h2>\n<p>Tags: headings, headers</p>\n<p>Aliases: first-line-heading, first-line-h1</p>\n<p>Parameters: level, front<em>matter</em>title (number; default 1, string; default \"^\\s<em>\"?title\"?\\s</em>[:=]\")</p>\n<p>This rule is intended to ensure documents have a title and is triggered when\nthe first line in the file isn't a top-level (h1) heading:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">This is a file without a heading</code></pre></div>\n<p>To fix this, add a top-level heading to the beginning of the file:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> File with heading</span>\n\nThis is a file with a top-level heading</code></pre></div>\n<p>Because it is common for projects on GitHub to use an image for the heading of\n<code class=\"language-text\">README.md</code> and that is not well-supported by Markdown, HTML headings are also\npermitted by this rule. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span> <span class=\"token attr-name\">align</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>center<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>img</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://placekitten.com/300/150<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">/></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span>\n\nThis is a file with a top-level HTML heading</code></pre></div>\n<p>Note: The <code class=\"language-text\">level</code> parameter can be used to change the top-level (ex: to h2) in cases\nwhere an h1 is added externally.</p>\n<p>If <a href=\"https://en.wikipedia.org/wiki/YAML\">YAML</a> front matter is present and\ncontains a <code class=\"language-text\">title</code> property (commonly used with blog posts), this rule will not\nreport a violation. To use a different property name in the front matter,\nspecify the text of a regular expression via the <code class=\"language-text\">front_matter_title</code> parameter.\nTo disable the use of front matter by this rule, specify <code class=\"language-text\">\"\"</code> for <code class=\"language-text\">front_matter_title</code>.</p>\n<p>Rationale: The top-level heading often acts as the title of a document. More\ninformation: <a href=\"https://cirosantilli.com/markdown-style-guide#top-level-header\">https://cirosantilli.com/markdown-style-guide#top-level-header</a>.</p>\n<a name=\"md042\">\n</a>\n<h2>MD042 - No empty links</h2>\n<p>Tags: links</p>\n<p>Aliases: no-empty-links</p>\n<p>This rule is triggered when an empty link is encountered:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\">[an empty link]()</code></pre></div>\n<p>To fix the violation, provide a destination for the link:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\">[<span class=\"token content\">a valid link</span>](<span class=\"token url\">https://example.com/</span>)</span></code></pre></div>\n<p>Empty fragments will trigger this rule:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\">[<span class=\"token content\">an empty fragment</span>](<span class=\"token url\">#</span>)</span></code></pre></div>\n<p>But non-empty fragments will not:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\">[<span class=\"token content\">a valid fragment</span>](<span class=\"token url\">#fragment</span>)</span></code></pre></div>\n<p>Rationale: Empty links do not lead anywhere and therefore don't function as links.</p>\n<a name=\"md043\">\n</a>\n<h2>MD043 - Required heading structure</h2>\n<p>Tags: headings, headers</p>\n<p>Aliases: required-headings, required-headers</p>\n<p>Parameters: headings, headers (array of string; default <code class=\"language-text\">null</code> for disabled)</p>\n<blockquote>\n<p>If <code class=\"language-text\">headings</code> is not provided, <code class=\"language-text\">headers</code> (deprecated) will be used.</p>\n</blockquote>\n<p>This rule is triggered when the headings in a file do not match the array of\nheadings passed to the rule. It can be used to enforce a standard heading\nstructure for a set of files.</p>\n<p>To require exactly the following structure:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Head</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Item</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Detail</span></code></pre></div>\n<p>Set the <code class=\"language-text\">headings</code> parameter to:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//on</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'# Head'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'## Item'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'### Detail'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To allow optional headings as with the following structure:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Head</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Item</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Detail (optional)</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">##</span> Foot</span>\n\n<span class=\"token title important\"><span class=\"token punctuation\">###</span> Notes (optional)</span></code></pre></div>\n<p>Use the special value <code class=\"language-text\">\"*\"</code> meaning \"zero or more unspecified headings\" or the\nspecial value <code class=\"language-text\">\"+\"</code> meaning \"one or more unspecified headings\" and set the\n<code class=\"language-text\">headings</code> parameter to:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//on</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'# Head'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'## Item'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'*'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'## Foot'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'*'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>When an error is detected, this rule outputs the line number of the first\nproblematic heading (otherwise, it outputs the last line number of the file).</p>\n<p>Note that while the <code class=\"language-text\">headings</code> parameter uses the \"## Text\" ATX heading style for\nsimplicity, a file may use any supported heading style.</p>\n<p>Rationale: Projects may wish to enforce a consistent document structure across\na set of similar content.</p>\n<a name=\"md044\">\n</a>\n<h2>MD044 - Proper names should have the correct capitalization</h2>\n<p>Tags: spelling</p>\n<p>Aliases: proper-names</p>\n<p>Parameters: names, code_blocks (string array; default <code class=\"language-text\">null</code>, boolean; default <code class=\"language-text\">true</code>)</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when any of the strings in the <code class=\"language-text\">names</code> array do not have\nthe specified capitalization. It can be used to enforce a standard letter case\nfor the names of projects and products.</p>\n<p>For example, the language \"JavaScript\" is usually written with both the 'J' and\n'S' capitalized - though sometimes the 's' or 'j' appear in lower-case. To enforce\nthe proper capitalization, specify the desired letter case in the <code class=\"language-text\">names</code> array:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//on</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'JavaScript'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Set the <code class=\"language-text\">code_blocks</code> parameter to <code class=\"language-text\">false</code> to disable this rule for code blocks.</p>\n<p>Rationale: Incorrect capitalization of proper names is usually a mistake.</p>\n<a name=\"md045\">\n</a>\n<h2>MD045 - Images should have alternate text (alt text)</h2>\n<p>Tags: accessibility, images</p>\n<p>Aliases: no-alt-text</p>\n<p>This rule is triggered when an image is missing alternate text (alt text) information.</p>\n<p>Alternate text is commonly specified inline as:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\"><span class=\"token operator\">!</span>[<span class=\"token content\">Alternate text</span>](<span class=\"token url\">image.jpg</span>)</span></code></pre></div>\n<p>Or with reference syntax as:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token url\"><span class=\"token operator\">!</span>[<span class=\"token content\">Alternate text</span>][<span class=\"token variable\">ref</span>]</span>\n\n...\n\n<span class=\"token url-reference url\"><span class=\"token punctuation\">[</span><span class=\"token variable\">ref</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span> image.jpg <span class=\"token string\">'Optional title'</span></span></code></pre></div>\n<p>Guidance for writing alternate text is available from the <a href=\"https://www.w3.org/WAI/alt/\">W3C</a>,\n<a href=\"https://en.wikipedia.org/wiki/Alt_attribute\">Wikipedia</a>, and\n<a href=\"https://www.phase2technology.com/blog/no-more-excuses\">other locations</a>.</p>\n<p>Rationale: Alternate text is important for accessibility and describes the\ncontent of an image for people who may not be able to see it.</p>\n<a name=\"md046\">\n</a>\n<h2>MD046 - Code block style</h2>\n<p>Tags: code</p>\n<p>Aliases: code-block-style</p>\n<p>Parameters: style (\"consistent\", \"fenced\", \"indented\"; default \"consistent\")</p>\n<p>This rule is triggered when unwanted or different code block styles are used in\nthe same document.</p>\n<p>In the default configuration this rule reports a violation for the following document:</p>\n<!-- markdownlint-disable code-block-style -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some text.\n\n    # Indented code\n\nMore text.\n\n```ruby\n# Fenced code\n```\n\nMore text.</code></pre></div>\n<!-- markdownlint-restore -->\n<p>To fix violations of this rule, use a consistent style (either indenting or code\nfences).</p>\n<p>The specified style can be specific (<code class=\"language-text\">fenced</code>, <code class=\"language-text\">indented</code>) or simply require\nthat usage be consistent within the document (<code class=\"language-text\">consistent</code>).</p>\n<p>Rationale: Consistent formatting makes it easier to understand a document.</p>\n<a name=\"md047\">\n</a>\n<h2>MD047 - Files should end with a single newline character</h2>\n<p>Tags: blank_lines</p>\n<p>Aliases: single-trailing-newline</p>\n<p>Fixable: Most violations can be fixed by tooling</p>\n<p>This rule is triggered when there is not a single newline character at the end\nof a file.</p>\n<p>An example that triggers the rule:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading</span>\n\nThis file ends without a newline.[EOF]</code></pre></div>\n<p>To fix the violation, add a newline character to the end of the file:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token title important\"><span class=\"token punctuation\">#</span> Heading</span>\n\nThis file ends with a newline.\n[EOF]</code></pre></div>\n<p>Rationale: Some programs have trouble with files that do not end with a newline.\nMore information: <a href=\"https://unix.stackexchange.com/questions/18743/whats-the-point-in-adding-a-new-line-to-the-end-of-a-file\">https://unix.stackexchange.com/questions/18743/whats-the-point-in-adding-a-new-line-to-the-end-of-a-file</a>.</p>\n<a name=\"md048\">\n</a>\n<h2>MD048 - Code fence style</h2>\n<p>Tags: code</p>\n<p>Aliases: code-fence-style</p>\n<p>Parameters: style (\"consistent\", \"tilde\", \"backtick\"; default \"consistent\")</p>\n<p>This rule is triggered when the symbols used in the document for fenced code\nblocks do not match the configured code fence style:</p>\n<div class=\"gatsby-highlight\" data-language=\"markdown\"><pre class=\"language-markdown\"><code class=\"language-markdown\"><span class=\"token code\"><span class=\"token punctuation\">```</span><span class=\"token code-language\">ruby</span>\n<span class=\"token code-block language-ruby\"><span class=\"token comment\"># Fenced code</span></span>\n<span class=\"token punctuation\">```</span></span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"ruby\"><pre class=\"language-ruby\"><code class=\"language-ruby\"><span class=\"token comment\"># Fenced code</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">To fix this issue, use the configured code fence style throughout the\ndocument:\n\n```markdown\n```ruby\n# Fenced code</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"ruby\"><pre class=\"language-ruby\"><code class=\"language-ruby\"><span class=\"token comment\"># Fenced code</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The configured list style can be a specific symbol to use (backtick, tilde), or\ncan require that usage be consistent within the document.\n\nRationale: Consistent formatting makes it easier to understand a document.</code></pre></div>"},{"url":"/docs/reference/vscode/","relativePath":"docs/reference/vscode.md","relativeDir":"docs/reference","base":"vscode.md","name":"vscode","frontmatter":{"title":"Getting Started With VSCode","weight":0,"seo":{"title":"Getting Started With VSCode","description":"This is the Getting Started With VSCode page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Getting Started With VSCode","keyName":"property"},{"name":"og:description","value":"This is the Getting Started With VSCode page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Getting Started With VSCode"},{"name":"twitter:description","value":"This is the Getting Started With VSCode page"}]},"template":"docs"},"html":"<h1>Everything You Need to Get Started With VSCode + Extensions &#x26; Resources</h1>\n<p>Commands:</p>\n<hr>\n<h3>Everything You Need to Get Started With VSCode + Extensions &#x26; Resources</h3>\n<h4>Every extension or tool you could possibly need</h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*gcp0kkiWQY6qd1Y4qEcqxw.png\" class=\"graf-image\" />\n</figure>\n<h3>Here's a rudimentary static site I made that goes into more detail on the extensions I use…</h3>\n<a href=\"https://5fff5b9a2430bb564bfd451d--stoic-mccarthy-2c335f.netlify.app/#h18\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://5fff5b9a2430bb564bfd451d--stoic-mccarthy-2c335f.netlify.app/#h18\">\n<strong>VSCodeExtensions</strong>\n<br />\n5fff5b9a2430bb564bfd451d--stoic-mccarthy-2c335f.netlify.app</a>\n<a href=\"https://5fff5b9a2430bb564bfd451d--stoic-mccarthy-2c335f.netlify.app/#h18\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>Here's the repo it was deployed from:</h3>\n<p><a href=\"https://github.com/bgoonz/vscode-Extension-readmes\" class=\"markup--anchor markup--p-anchor\">https://github.com/bgoonz/vscode-Extension-readmes</a></p>\n<hr>\n<h3>Commands:</h3>\n<blockquote>\n<p>Command Palette</p>\n</blockquote>\n<blockquote>\n<p>Access all available commands based on your current context.</p>\n</blockquote>\n<blockquote>\n<p>Keyboard Shortcut: <strong>Ctrl+Shift+P</strong></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*BByhnDoVQdRPdO4F.gif\" class=\"graf-image\" />\n</figure>### Command palette\n<p><code class=\"language-text\">⇧⌘P</code> Show all commands <code class=\"language-text\">⌘P</code> Show files</p>\n<h3>Sidebars</h3>\n<p><code class=\"language-text\">⌘B</code> Toggle sidebar <code class=\"language-text\">⇧⌘E</code> Explorer <code class=\"language-text\">⇧⌘F</code> Search <code class=\"language-text\">⇧⌘D</code> Debug <code class=\"language-text\">⇧⌘X</code> Extensions <code class=\"language-text\">⇧^G</code> Git (SCM)</p>\n<h3>Search</h3>\n<p><code class=\"language-text\">⌘F</code> Find <code class=\"language-text\">⌥⌘F</code> Replace <code class=\"language-text\">⇧⌘F</code> Find in files <code class=\"language-text\">⇧⌘H</code> Replace in files</p>\n<h3>Panel</h3>\n<p><code class=\"language-text\">⌘J</code> Toggle panel <code class=\"language-text\">⇧⌘M</code> Problems <code class=\"language-text\">⇧⌘U</code> Output <code class=\"language-text\">⇧⌘Y</code> Debug console<code class=\"language-text\"></code> ^` <code class=\"language-text\"></code>Terminal</p>\n<h3>View</h3>\n<p><code class=\"language-text\">⌘k</code> <code class=\"language-text\">z</code> Zen mode <code class=\"language-text\">⌘k</code> <code class=\"language-text\">u</code> Close unmodified <code class=\"language-text\">⌘k</code> <code class=\"language-text\">w</code> Close all</p>\n<h3>Debug</h3>\n<p><code class=\"language-text\">F5</code> Start <code class=\"language-text\">⇧F5</code> Stop <code class=\"language-text\">⇧⌘F5</code> Restart <code class=\"language-text\">^F5</code> Start without debugging <code class=\"language-text\">F9</code> Toggle breakpoint <code class=\"language-text\">F10</code> Step over <code class=\"language-text\">F11</code> Step into <code class=\"language-text\">⇧F11</code> Step out <code class=\"language-text\">⇧⌘D</code> Debug sidebar <code class=\"language-text\">⇧⌘Y</code> Debug panel</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/0*llpkl5jsIMhWMucR.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Tips-N-Tricks:</h3>\n<p>Here is a selection of common features for editing code. If the keyboard shortcuts aren't comfortable for you, consider installing a <a href=\"https://marketplace.visualstudio.com/search?target=VSCode&amp;category=Keymaps&amp;sortBy=Downloads\" class=\"markup--anchor markup--p-anchor\">keymap extension</a> for your old editor.</p>\n<p>Tip: You can see recommended keymap extensions in the Extensions view with Ctrl+K Ctrl+M which filters the search to <code class=\"language-text\">@recommended:keymaps</code> .</p>\n<h3>Multi cursor selection</h3>\n<p>To add cursors at arbitrary positions, select a position with your mouse and use Alt+Click (Option+click on macOS).</p>\n<p>To set cursors above or below the current position use:</p>\n<p>Keyboard Shortcut: Ctrl+Alt+Up or Ctrl+Alt+Down</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Le_oEOiYnEBmFfig.gif\" class=\"graf-image\" />\n</figure>You can add additional cursors to all occurrences of the current selection with Ctrl+Shift+L.\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*WcrfwIln6NIG3zNW.gif\" class=\"graf-image\" />\n</figure>*Note: You can also change the modifier to Ctrl/Cmd for applying multiple cursors with the* `editor.multiCursorModifier` <a href=\"https://code.visualstudio.com/docs/getstarted/settings\" class=\"markup--anchor markup--blockquote-anchor\">\n<em>setting</em>\n</a>* . See* <a href=\"https://code.visualstudio.com/docs/editor/codebasics#_multicursor-modifier\" class=\"markup--anchor markup--blockquote-anchor\">\n<em>Multi-cursor Modifier</em>\n</a> *for details.*\n<p>If you do not want to add all occurrences of the current selection, you can use Ctrl+D instead. This only selects the next occurrence after the one you selected so you can add selections one by one.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*09EveaKtpZEKFEpO.gif\" class=\"graf-image\" />\n</figure>### Column (box) selection\n<p>You can select blocks of text by holding Shift+Alt (Shift+Option on macOS) while you drag your mouse. A separate cursor will be added to the end of each selected line.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*LrsOBXP4MVqr7aes.gif\" class=\"graf-image\" />\n</figure>You can also use <a href=\"https://code.visualstudio.com/docs/editor/codebasics#_column-box-selection\" class=\"markup--anchor markup--p-anchor\">keyboard shortcuts</a> to trigger column selection.\n<hr>\n<h3>Extensions:</h3>\n<h4><a href=\"https://marketplace.visualstudio.com/items?itemName=cweijan.vscode-autohotkey-plus\" class=\"markup--anchor markup--h4-anchor\">AutoHotkey Plus</a></h4>\n<blockquote>\n<p><em>Syntax Highlighting, Snippets, Go to Definition, Signature helper and Code formatter</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=rogalmic.bash-debug\" class=\"markup--anchor markup--h3-anchor\">Bash Debug</a></h3>\n<blockquote>\n<p><em>A debugger extension for Bash scripts based on</em> <code class=\"language-text\">bashdb</code></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*8j2gGGs0WHcuFIwY.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=Remisa.shellman\" class=\"markup--anchor markup--h3-anchor\">Shellman</a>\n<blockquote>\n<p><em>Bash script snippets extension</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*wyimtX27gWygAeOb.gif\" class=\"graf-image\" />\n</figure>### C++\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools\" class=\"markup--anchor markup--blockquote-anchor\">C/C++</a> — Preview C/C++ extension by <a href=\"https://www.microsoft.com/\" class=\"markup--anchor markup--blockquote-anchor\">Microsoft</a>, read <a href=\"https://blogs.msdn.microsoft.com/vcblog/2016/03/31/cc-extension-for-visual-studio-code/\" class=\"markup--anchor markup--blockquote-anchor\">official blog post</a> for the details</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd\" class=\"markup--anchor markup--blockquote-anchor\">Clangd</a> — Provides C/C++ language IDE features for VS Code using clangd: code completion, compile errors and warnings, go-to-definition and cross references, include management, code formatting, simple refactorings.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=austin.code-gnu-global\" class=\"markup--anchor markup--blockquote-anchor\">gnu-global-tags</a> — Provide Intellisense for C/C++ with the help of the GNU Global tool.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=RichardHe.you-complete-me\" class=\"markup--anchor markup--blockquote-anchor\">YouCompleteMe</a> — Provides semantic completions for C/C++ (and TypeScript, JavaScript, Objective-C, Golang, Rust) using <a href=\"http://ycm-core.github.io/YouCompleteMe/\" class=\"markup--anchor markup--blockquote-anchor\">YouCompleteMe</a>.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://github.com/mitaki28/vscode-clang\" class=\"markup--anchor markup--blockquote-anchor\">C/C++ Clang Command Adapter</a> — Completion and Diagnostic for C/C++/Objective-C using Clang command.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://github.com/cquery-project/vscode-cquery\" class=\"markup--anchor markup--blockquote-anchor\">CQuery</a> — <a href=\"https://github.com/jacobdufault/cquery\" class=\"markup--anchor markup--blockquote-anchor\">C/C++ language server</a> supporting multi-million line code base, powered by libclang. Cross references, completion, diagnostics, semantic highlighting and more.</p>\n</blockquote>\n<h4>More</h4>\n<ul>\n<li>\n<span id=\"4dd9\">\n<a href=\"https://devblogs.microsoft.com/cppblog/vscode-cpp-may-2019-update/\" class=\"markup--anchor markup--li-anchor\">Microsoft's tutorial on using VSCode for remote C/C++ development</a>\n</span>\n</li>\n</ul>\n<h3>C#, ASP . NET and . NET Core</h3>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp\" class=\"markup--anchor markup--blockquote-anchor\">C#</a> — C# extension by <a href=\"https://www.microsoft.com/\" class=\"markup--anchor markup--blockquote-anchor\">Microsoft</a>, read <a href=\"https://code.visualstudio.com/docs/languages/csharp\" class=\"markup--anchor markup--blockquote-anchor\">official documentation</a> for the details</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=Leopotam.csharpfixformat\" class=\"markup--anchor markup--blockquote-anchor\">C# FixFormat</a> — Fix format of usings / indents / braces / empty lines</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=jchannon.csharpextensions\" class=\"markup--anchor markup--blockquote-anchor\">C# Extensions</a> — Provides extensions to the IDE that will speed up your development workflow.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=tintoy.msbuild-project-tools\" class=\"markup--anchor markup--blockquote-anchor\">MSBuild Project Tools</a></p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=fernandoescolar.vscode-solution-explorer\" class=\"markup--anchor markup--blockquote-anchor\">VSCode Solution Explorer</a></p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.dotnet-test-explorer\" class=\"markup--anchor markup--blockquote-anchor\">. NET Core Test Explorer</a></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ZG5W4_VVBv89zO_g.gif\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>CSS</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=pranaygp.vscode-css-peek\" class=\"markup--anchor markup--h3-anchor\">CSS Peek</a></h3>\n<blockquote>\n<p><em>Peek or Jump to a CSS definition directly from HTML, just like in Brackets!</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*MN4pNqxDw4FyRk8g.gif\" class=\"graf-image\" />\n</figure>- <span id=\"7261\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=stylelint.vscode-stylelint\" class=\"markup--anchor markup--li-anchor\">stylelint</a> — Lint CSS/SCSS.</span>\n<ul>\n<li>\n<span id=\"e8d5\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=mrmlnc.vscode-autoprefixer\" class=\"markup--anchor markup--li-anchor\">Autoprefixer</a> Parse CSS, SCSS, LESS and add vendor prefixes automatically.</span>\n</li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*edXaUlo7z9TRDQnC.gif\" class=\"graf-image\" />\n</figure>- <span id=\"b1b1\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=Zignd.html-css-class-completion\" class=\"markup--anchor markup--li-anchor\">Intellisense for CSS class names</a> — Provides CSS class name completion for the HTML class attribute based on the CSS files in your workspace. Also supports React's className attribute.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*AHJJrCMfkLWLHLH4.gif\" class=\"graf-image\" />\n</figure>### Groovy\n<ul>\n<li>\n<span id=\"e453\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=NicolasVuillamy.vscode-groovy-lint\" class=\"markup--anchor markup--li-anchor\">VsCode Groovy Lint</a> — Groovy lint, format, prettify and auto-fix</span>\n</li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*jmi5_-erJj7WOMq7.gif\" class=\"graf-image\" />\n</figure>### Haskell\n<ul>\n<li>\n<span id=\"66eb\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=hoovercj.haskell-linter\" class=\"markup--anchor markup--li-anchor\">haskell-linter</a>\n</span>\n</li>\n<li>\n<span id=\"fd71\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=alanz.vscode-hie-server\" class=\"markup--anchor markup--li-anchor\">Haskell IDE engine</a> — provides <a href=\"https://github.com/haskell/haskell-ide-engine\" class=\"markup--anchor markup--li-anchor\">language server</a> for stack and cabal projects.</span>\n</li>\n<li>\n<span id=\"cbfe\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=truman.autocomplate-shell\" class=\"markup--anchor markup--li-anchor\">autocomplate-shell</a>\n</span>\n</li>\n</ul>\n<hr>\n<h3>Java</h3>\n<ul>\n<li>\n<span id=\"cf71\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=redhat.java\" class=\"markup--anchor markup--li-anchor\">Language Support for Java(TM) by Red Hat</a>\n</span>\n</li>\n<li>\n<span id=\"d93f\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug\" class=\"markup--anchor markup--li-anchor\">Debugger for Java</a>\n</span>\n</li>\n<li>\n<span id=\"3c8c\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-maven\" class=\"markup--anchor markup--li-anchor\">Maven for Java</a>\n</span>\n</li>\n<li>\n<span id=\"2d5c\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=GabrielBB.vscode-lombok\" class=\"markup--anchor markup--li-anchor\">Lombok</a>\n</span>\n</li>\n</ul>\n<hr>\n<h3>JavaScript</h3>\n<ul>\n<li>\n<span id=\"8516\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=mgmcdermott.vscode-language-babel\" class=\"markup--anchor markup--li-anchor\">Babel JavaScript</a>\n</span>\n</li>\n<li>\n<span id=\"aa22\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode\" class=\"markup--anchor markup--li-anchor\">Visual Studio IntelliCode</a> — This extension provides AI-assisted development features including autocomplete and other insights based on understanding your code context.</span>\n</li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*i7CZbSbHqsWqEM4w.gif\" class=\"graf-image\" />\n</figure>See the difference between these two <a href=\"https://github.com/michaelgmcd/vscode-language-babel/issues/1\" class=\"markup--anchor markup--p-anchor\">here</a>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-tslint-plugin\" class=\"markup--anchor markup--blockquote-anchor\">tslint</a> — TSLint for Visual Studio Code (with <code class=\"language-text\">\"tslint.jsEnable\": true</code> ).</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint\" class=\"markup--anchor markup--blockquote-anchor\">eslint</a> — Linter for <a href=\"https://eslint.org/\" class=\"markup--anchor markup--blockquote-anchor\">eslint</a>.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=samverschueren.linter-xo\" class=\"markup--anchor markup--blockquote-anchor\">XO</a> — Linter for <a href=\"https://github.com/xojs/xo\" class=\"markup--anchor markup--blockquote-anchor\">XO</a>.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=samverschueren.ava\" class=\"markup--anchor markup--blockquote-anchor\">AVA</a> — Snippets for <a href=\"https://github.com/avajs/ava\" class=\"markup--anchor markup--blockquote-anchor\">AVA</a>.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode\" class=\"markup--anchor markup--blockquote-anchor\">Prettier</a> — Linter, Formatter and Pretty printer for <a href=\"https://github.com/prettier/prettier-vscode\" class=\"markup--anchor markup--blockquote-anchor\">Prettier</a>.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=austinleegordon.vscode-schema-dot-org\" class=\"markup--anchor markup--blockquote-anchor\">Schema.org Snippets</a> — Snippets for <a href=\"https://schema.org/\" class=\"markup--anchor markup--blockquote-anchor\">Schema.org</a>.</p>\n</blockquote>\n<blockquote>\n<p><a href=\"https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker\" class=\"markup--anchor markup--blockquote-anchor\">Code Spell Checker</a> — Spelling Checker for Visual Studio Code.</p>\n</blockquote>\n<p>Framework-specific:</p>\n<h4><a href=\"https://marketplace.visualstudio.com/items?itemName=octref.vetur\" class=\"markup--anchor markup--h4-anchor\">Vetur</a> — Toolkit for Vue.js</h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*F7J_vW0ISbVMTXIZ.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome\" class=\"markup--anchor markup--h3-anchor\">Debugger for Chrome</a></h3>\n<blockquote>\n<p><em>A VS Code extension to debug your JavaScript code in the Chrome browser, or other targets that support the Chrome Debugging Protocol.</em></p>\n</blockquote>\n<h3>Facebook Flow</h3>\n<ul>\n<li>\n<span id=\"155f\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=flowtype.flow-for-vscode\" class=\"markup--anchor markup--li-anchor\">Flow Language Support</a> — provides all the functionality you would expect — linting, intellisense, type tooltips and click-to-definition</span>\n</li>\n<li>\n<span id=\"ac2f\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=gcazaciuc.vscode-flow-ide\" class=\"markup--anchor markup--li-anchor\">vscode-flow-ide</a> — an alternative Flowtype extension for Visual Studio Code</span>\n</li>\n</ul>\n<h3>TypeScript</h3>\n<ul>\n<li>\n<span id=\"8883\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=eg2.tslint\" class=\"markup--anchor markup--li-anchor\">tslint</a> — TSLint for Visual Studio Code</span>\n</li>\n<li>\n<span id=\"9665\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero\" class=\"markup--anchor markup--li-anchor\">TypeScript Hero</a> — Code outline view of your open TS, sort and organize your imports.</span>\n</li>\n</ul>\n<hr>\n<h3>Markdown</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint\" class=\"markup--anchor markup--h3-anchor\">markdownlint</a></h3>\n<blockquote>\n<p><em>Linter for</em> <a href=\"https://github.com/DavidAnson/markdownlint\" class=\"markup--anchor markup--blockquote-anchor\">\n<em>markdownlint</em>\n</a><em>.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one\" class=\"markup--anchor markup--h3-anchor\">Markdown All in One</a></h3>\n<blockquote>\n<p><em>All-in-one markdown plugin (keyboard shortcuts, table of contents, auto preview, list editing and more)</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*8oVrYuZ9kLRNSuBs.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=bierner.markdown-emoji\" class=\"markup--anchor markup--h3-anchor\">Markdown Emoji</a>\n<blockquote>\n<p><em>Adds emoji syntax support to VS Code's built-in Markdown preview</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*rckUMIIZ9Jh7UE5q.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>PHP</h3>\n<h3>IntelliSense</h3>\n<p>These extensions provide slightly different sets of features. While the first one offers better autocompletion support, the second one seems to have more features overall.</p>\n<ul>\n<li>\n<span id=\"94df\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client\" class=\"markup--anchor markup--li-anchor\">PHP Intelephense</a>\n</span>\n</li>\n<li>\n<span id=\"b2b4\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-intellisense\" class=\"markup--anchor markup--li-anchor\">PHP IntelliSense</a>\n</span>\n</li>\n</ul>\n<h3>Laravel</h3>\n<ul>\n<li>\n<span id=\"687e\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel5-snippets\" class=\"markup--anchor markup--li-anchor\">Laravel 5 Snippets</a> — Laravel 5 snippets for Visual Studio Code</span>\n</li>\n<li>\n<span id=\"42ab\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=onecentlin.laravel-blade\" class=\"markup--anchor markup--li-anchor\">Laravel Blade Snippets</a> — Laravel blade snippets and syntax highlight support</span>\n</li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*f4hMFe1l7NpJTG8v.gif\" class=\"graf-image\" />\n</figure>- <span id=\"bf66\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=ahinkle.laravel-model-snippets\" class=\"markup--anchor markup--li-anchor\">Laravel Model Snippets</a> — Quickly get models up and running with Laravel Model Snippets.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*1xydH2CgYGDSMZtB.gif\" class=\"graf-image\" />\n</figure>- <span id=\"fa58\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=ryannaddy.laravel-artisan\" class=\"markup--anchor markup--li-anchor\">Laravel Artisan</a> — Laravel Artisan commands within Visual Studio Code</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*rzK952c4UgikNNPR.gif\" class=\"graf-image\" />\n</figure>- <span id=\"1e4d\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=mikestead.dotenv\" class=\"markup--anchor markup--li-anchor\">DotENV</a> — Support for dotenv file syntax</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*fSAaqpXfBx1Sgztf.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Other extensions</h3>\n<ul>\n<li>\n<span id=\"8443\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=rifi2k.format-html-in-php\" class=\"markup--anchor markup--li-anchor\">Format HTML in PHP</a> — Formatting for the HTML in PHP files. Runs before the save action so you can still have a PHP formatter.</span>\n</li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*6gF0K20iKes7I9ZF.gif\" class=\"graf-image\" />\n</figure>- <span id=\"f3f0\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=ikappas.composer\" class=\"markup--anchor markup--li-anchor\">Composer</a>\n</span>\n<ul>\n<li>\n<span id=\"e5ba\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug\" class=\"markup--anchor markup--li-anchor\">PHP Debug</a> — XDebug extension for Visual Studio Code</span>\n</li>\n<li>\n<span id=\"6a3c\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=neilbrayfield.php-docblocker\" class=\"markup--anchor markup--li-anchor\">PHP DocBlocker</a>\n</span>\n</li>\n<li>\n<span id=\"a4ca\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=junstyle.php-cs-fixer\" class=\"markup--anchor markup--li-anchor\">php cs fixer</a> — PHP CS Fixer extension for VS Code, php formatter, php code beautify tool</span>\n</li>\n<li>\n<span id=\"30f1\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=ikappas.phpcs\" class=\"markup--anchor markup--li-anchor\">phpcs</a> — PHP CodeSniffer for Visual Studio Code</span>\n</li>\n<li>\n<span id=\"d82e\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=kokororin.vscode-phpfmt\" class=\"markup--anchor markup--li-anchor\">phpfmt</a> — phpfmt for Visual Studio Code</span>\n</li>\n</ul>\n<hr>\n<h3>Python</h3>\n<ul>\n<li>\n<span id=\"0136\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=ms-python.python\" class=\"markup--anchor markup--li-anchor\">Python</a> — Linting, Debugging (multi threaded, web apps), Intellisense, auto-completion, code formatting, snippets, unit testing, and more.</span>\n</li>\n</ul>\n<h3>TensorFlow</h3>\n<ul>\n<li>\n<span id=\"402b\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=vahidk.tensorflow-snippets\" class=\"markup--anchor markup--li-anchor\">TensorFlow Snippets</a> — This extension includes a set of useful code snippets for developing TensorFlow models in Visual Studio Code.</span>\n</li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*stmhgQ3sGvJBTvf2.gif\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>Rust</h3>\n<ul>\n<li>\n<span id=\"cec4\">\n<a href=\"https://marketplace.visualstudio.com/items?itemName=rust-lang.rust\" class=\"markup--anchor markup--li-anchor\">Rust</a> — Linting, auto-completion, code formatting, snippets and more</span>\n</li>\n</ul>\n<hr>\n<h3>Productivity</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=bencoleman.armview\" class=\"markup--anchor markup--h3-anchor\">ARM Template Viewer</a></h3>\n<blockquote>\n<p><em>Displays a graphical preview of Azure Resource Manager (ARM) templates. The view will show all resources with the official Azure icons and also linkage between the resources.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*p8bvCI9DXF44m4z3.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-cosmosdb\" class=\"markup--anchor markup--h3-anchor\">Azure Cosmos DB</a>\n<blockquote>\n<p><em>Browse your database inside the vs code editor</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*VWvSU6Hbf20Kfc_P.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-toolkit\" class=\"markup--anchor markup--h3-anchor\">Azure IoT Toolkit</a>\n<blockquote>\n<p><em>Everything you need for the Azure IoT development: Interact with Azure IoT Hub, manage devices connected to Azure IoT Hub, and develop with code snippets for Azure IoT Hub</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*AobtCd80fICrbQPI.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks\" class=\"markup--anchor markup--h3-anchor\">Bookmarks</a>\n<blockquote>\n<p><em>Mark lines and jump to them</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=orepor.color-tabs-vscode-ext\" class=\"markup--anchor markup--h3-anchor\">Color Tabs</a></h3>\n<blockquote>\n<p><em>An extension for big projects or monorepos that colors your tab/titlebar based on the current package</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*SEp-hgfDLlubNRyc.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=hardikmodha.create-tests\" class=\"markup--anchor markup--h3-anchor\">Create tests</a>\n<blockquote>\n<p><em>An extension to quickly generate test files.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*DLZLYmrBiui0YOBt.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=mkloubert.vs-deploy\" class=\"markup--anchor markup--h3-anchor\">Deploy</a>\n<blockquote>\n<p><em>Commands for upload or copy files of a workspace to a destination.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*lLasjzlmWnBwdbAT.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=mrmlnc.vscode-duplicate\" class=\"markup--anchor markup--h3-anchor\">Duplicate Action</a>\n<blockquote>\n<p><em>Ability to duplicate files and directories.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens\" class=\"markup--anchor markup--h3-anchor\">Error Lens</a></h3>\n<blockquote>\n<p><em>Show language diagnostics inline (errors/warnings/…).</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*1tJJkV0p2Ka_W06r.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=dsznajder.es7-react-js-snippets\" class=\"markup--anchor markup--h3-anchor\">ES7 React/Redux/GraphQL/React-Native snippets</a>\n<blockquote>\n<p><em>Provides Javascript and React/Redux snippets in ES7</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*W3N0kbgEumWYa-m4.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=rubbersheep.gi\" class=\"markup--anchor markup--h3-anchor\">Gi</a>\n<blockquote>\n<p><em>Generating .gitignore files made easy</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*sfddghz8B1D362UB.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=vsls-contrib.gistfs\" class=\"markup--anchor markup--h3-anchor\">GistPad</a>\n<blockquote>\n<p><em>Allows you to manage GitHub Gists entirely within the editor. You can open, create, delete, fork, star and clone gists, and then seamlessly begin editing files as if they were local. It's like your very own developer library for building and referencing code snippets, commonly used config/scripts, programming-related notes/documentation, and interactive samples.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*1MiBQ0u4Z8TPNaG9.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory\" class=\"markup--anchor markup--h3-anchor\">Git History</a>\n<blockquote>\n<p><em>View git log, file or line History</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=felipecaputo.git-project-manager\" class=\"markup--anchor markup--h3-anchor\">Git Project Manager</a></h3>\n<blockquote>\n<p><em>Automatically indexes your git projects and lets you easily toggle between them</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=qezhu.gitlink\" class=\"markup--anchor markup--h3-anchor\">GitLink</a></h3>\n<blockquote>\n<p><em>GoTo current file's online link in browser and Copy the link in clipboard.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Acgfn2rmhinuIPjk.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens\" class=\"markup--anchor markup--h3-anchor\">GitLens</a>\n<blockquote>\n<p><em>Provides Git CodeLens information (most recent commit, # of authors), on-demand inline blame annotations, status bar blame information, file and blame history explorers, and commands to compare changes with the working tree or previous versions.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*MZu4GV7SOCW88UQQ.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=lamartire.git-indicators\" class=\"markup--anchor markup--h3-anchor\">Git Indicators</a>\n<blockquote>\n<p><em>Atom-like git indicators on active panel</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*vitZrD9ZU0_eWckU.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*0BHxQOLMx09FFuWZ.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*x8F97F4AdSvvtehT.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=KnisterPeter.vscode-github\" class=\"markup--anchor markup--h3-anchor\">GitHub</a>\n<blockquote>\n<p><em>Provides GitHub workflow support. For example browse project, issues, file (the current line), create and manage pull request. Support for other providers (e.g. gitlab or bitbucket) is planned. Have a look at the</em> <a href=\"https://github.com/KnisterPeter/vscode-github/blob/master/README.md\" class=\"markup--anchor markup--blockquote-anchor\">\n<em>README.md</em>\n</a> <em>on how to get started with the setup for this extension.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=erichbehrens.pull-request-monitor\" class=\"markup--anchor markup--h3-anchor\">GitHub Pull Request Monitor</a></h3>\n<blockquote>\n<p><em>This extension uses the GitHub api to monitor the state of your pull requests and let you know when it's time to merge or if someone requested changes.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*TOq5OERkgQNETGPK.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=gitlab.gitlab-workflow\" class=\"markup--anchor markup--h3-anchor\">GitLab Workflow</a>\n<blockquote>\n<p><em>Adds a GitLab sidebar icon to view issues, merge requests and other GitLab resources. You can also view the results of your GitLab CI/CD pipeline and check the syntax of your _<code class=\"language-text\">.gitlab-ci.yml</code></em>._</p>\n</blockquote>\n<h4><a href=\"https://marketplace.visualstudio.com/items?itemName=richardwillis.vscode-gradle\" class=\"markup--anchor markup--h4-anchor\">Gradle Tasks</a></h4>\n<blockquote>\n<p><em>Run gradle tasks in VS Code.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Vx-3DIT22BJpEnJr.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=idleberg.icon-fonts\" class=\"markup--anchor markup--h3-anchor\">Icon Fonts</a>\n<blockquote>\n<p><em>Snippets for popular icon fonts such as Font Awesome, Ionicons, Glyphicons, Octicons, Material Design Icons and many more!</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost\" class=\"markup--anchor markup--h3-anchor\">Import Cost</a></h3>\n<blockquote>\n<p><em>This extension will display inline in the editor the size of the imported package. The extension utilizes webpack with babili-webpack-plugin in order to detect the imported size.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=Atlassian.atlascode\" class=\"markup--anchor markup--h3-anchor\">Jira and Bitbucket</a></h3>\n<blockquote>\n<p><em>Bringing the power of Jira and Bitbucket to VS Code — With Atlassian for VS Code you can create and view issues, start work on issues, create pull requests, do code reviews, start builds, get build statuses and more!</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*T6iuH2VnPYj93YqW.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=lannonbr.vscode-js-annotations\" class=\"markup--anchor markup--h3-anchor\">JS Parameter Annotations</a>\n<blockquote>\n<p><em>Provides annotations on function calls in JS/TS files to provide parameter names to arguments.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*zHffPsYWln4dxhus.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=wmaurer.vscode-jumpy\" class=\"markup--anchor markup--h3-anchor\">Jumpy</a>\n<blockquote>\n<p><em>Provides fast cursor movement, inspired by Atom's package of the same name.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*uPOceUJ4eMjCP_Qt.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=mkloubert.vscode-kanban\" class=\"markup--anchor markup--h3-anchor\">Kanban</a>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*SzUG3UU1fl5ub7bA.gif\" class=\"graf-image\" />\n</figure>*Simple Kanban board for use in Visual Studio Code, with time tracking and Markdown support.*\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer\" class=\"markup--anchor markup--h3-anchor\">Live Server</a></h3>\n<blockquote>\n<p><em>Launch a development local Server with live reload feature for static &#x26; dynamic pages.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Oj5zPrWwMbCBViBi.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=slevesque.vscode-multiclip\" class=\"markup--anchor markup--h3-anchor\">Multiple clipboards</a>\n<blockquote>\n<p><em>Override the regular Copy and Cut commands to keep selections in a clipboard ring</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=philnash.ngrok-for-vscode\" class=\"markup--anchor markup--h3-anchor\">ngrok for VSCode</a></h3>\n<blockquote>\n<p><em>ngrok allows you to expose a web server running on your local machine to the internet. Just tell ngrok what port your web server is listening on. This extension allows you to control</em> <a href=\"https://ngrok.com/\" class=\"markup--anchor markup--blockquote-anchor\">\n<em>ngrok</em>\n</a> <em>from the VSCode command palette</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*IX15MuJrEVBcTd0F.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=dbankier.vscode-instant-markdown\" class=\"markup--anchor markup--h3-anchor\">Instant Markdown</a>\n<blockquote>\n<p><em>Simply, edit markdown documents in vscode and instantly preview it in your browser as you type.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*jBw9vP9cAtvv2IcV.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=christian-kohler.npm-intellisense\" class=\"markup--anchor markup--h3-anchor\">npm Intellisense</a>\n<blockquote>\n<p><em>Visual Studio Code plugin that autocompletes npm modules in import statements.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*iVJamJugt_b7-VsV.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=DominicVonk.parameter-hints\" class=\"markup--anchor markup--h3-anchor\">Parameter Hints</a>\n<blockquote>\n<p><em>Provides parameter hints on function calls in JS/TS/PHP files.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*BSj8-Qt7xtVTsl1Z.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=ryu1kn.partial-diff\" class=\"markup--anchor markup--h3-anchor\">Partial Diff</a>\n<blockquote>\n<p><em>Compare (diff) text selections within a file, across different files, or to the clipboard</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*KHki85jdv1hZeY3V.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=quicktype.quicktype\" class=\"markup--anchor markup--h3-anchor\">Paste JSON as Code</a>\n<blockquote>\n<p><em>Infer the structure of JSON and paste is as types in many programming languages</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*K2GCRMGsYjpsK8OX.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=christian-kohler.path-intellisense\" class=\"markup--anchor markup--h3-anchor\">Path IntelliSense</a>\n<blockquote>\n<p><em>Visual Studio Code plugin that autocompletes filenames</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*xwxU_1ffZvZ6DeoO.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=ego-digital.vscode-powertools\" class=\"markup--anchor markup--h3-anchor\">Power Tools</a>\n<blockquote>\n<p><em>Extends Visual Studio Code via things like Node.js based scripts or shell commands, without writing separate extensions</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Cb7J6-PYsXsnjqSN.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=nobuhito.printcode\" class=\"markup--anchor markup--h3-anchor\">PrintCode</a>\n<blockquote>\n<p><em>PrintCode converts the code being edited into an HTML file, displays it by browser and prints it.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*2spvNSEEHM-ETd_F.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager\" class=\"markup--anchor markup--h3-anchor\">Project Manager</a>\n<blockquote>\n<p><em>Easily switch between projects.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=kruemelkatze.vscode-dashboard\" class=\"markup--anchor markup--h3-anchor\">Project Dashboard</a></h3>\n<blockquote>\n<p><em>VSCode Project Dashboard is a Visual Studio Code extension that lets you organize your projects in a speed-dial like manner. Pin your frequently visited folders, files, and SSH remotes onto a dashboard to access them quickly.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*PxOoARROhi1rf63R.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=mechatroner.rainbow-csv\" class=\"markup--anchor markup--h3-anchor\">Rainbow CSV</a>\n<blockquote>\n<p><em>Highlight columns in comma, tab, semicolon and pipe separated files, consistency check and linting with CSVLint, multi-cursor column editing, column trimming and realignment, and SQL-style querying with RBQL.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*XAb9jlOfGWlEaCEM.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack\" class=\"markup--anchor markup--h3-anchor\">Remote Development</a>\n<blockquote>\n<p><em>Allows users to open any folder in a container, on a remote machine, container or in Windows Subsystem for Linux(WSL) and take advantage of VS Code's full feature set.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*b6XEPh9PJzeWDB_z.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=rafaelmaiolla.remote-vscode\" class=\"markup--anchor markup--h3-anchor\">Remote VSCode</a>\n<blockquote>\n<p><em>Allow user to edit files from Remote server in Visual Studio Code directly.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=humao.rest-client\" class=\"markup--anchor markup--h3-anchor\">REST Client</a></h3>\n<blockquote>\n<p><em>Allows you to send HTTP request and view the response in Visual Studio Code directly.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*zGne78bniDbTXzyf.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync\" class=\"markup--anchor markup--h3-anchor\">Settings Sync</a>\n<blockquote>\n<p><em>Synchronize settings, snippets, themes, file icons, launch, key bindings, workspaces and extensions across multiple machines using GitHub Gist</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ilH91MRgGnMF6C8c.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=qcz.text-power-tools\" class=\"markup--anchor markup--h3-anchor\">Text Power Tools</a>\n<blockquote>\n<p><em>All-in-one extension for text manipulation: filtering (grep), remove lines, insert number sequences and GUIDs, format content as table, change case, converting numbers and more. Great for finding information in logs and manipulating text.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Pfp4noD5OeQRbmsZ.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree\" class=\"markup--anchor markup--h3-anchor\">Todo Tree</a>\n<blockquote>\n<p><em>Custom keywords, highlighting, and colors for TODO comments. As well as a sidebar to view all your current tags.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*6utz502-rPCa0Xcg.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=BriteSnow.vscode-toggle-quotes\" class=\"markup--anchor markup--h3-anchor\">Toggle Quotes</a>\n<blockquote>\n<p><em>Cycle between single, double and backtick quotes</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*7kZFpggvGAVkvoYa\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=tusaeff.vscode-typescript-destructure-plugin\" class=\"markup--anchor markup--h3-anchor\">Typescript Destructure</a>\n<blockquote>\n<p><em>TypeScript Language Service Plugin providing a set of source actions for easy objects destructuring</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*sEi0imXK2Yx69m7H.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=WakaTime.vscode-wakatime\" class=\"markup--anchor markup--h3-anchor\">WakaTime</a>\n<blockquote>\n<p><em>Automatic time tracker and productivity dashboard showing how long you coded in each project, file, branch, and language.</em></p>\n</blockquote>\n<hr>\n<h3>Formatting &#x26; Beautification</h3>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=wwm.better-align\" class=\"markup--anchor markup--h3-anchor\">Better Align</a></h3>\n<blockquote>\n<p><em>Align your code by colon(:), assignment(=, +=, -=, *=, /=) and arrow(=> ). It has additional support for comma-first coding style and trailing comment.</em></p>\n</blockquote>\n<blockquote>\n<p><em>And it doesn't require you to select what to be aligned, the extension will figure it out by itself.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*5maDjvvH57MAks1l.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-close-tag\" class=\"markup--anchor markup--h3-anchor\">Auto Close Tag</a>\n<blockquote>\n<p><em>Automatically add HTML/XML close tag, same as Visual Studio IDE or Sublime Text</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*h6Q6HLQ8jfHLnPlJ.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag\" class=\"markup--anchor markup--h3-anchor\">Auto Rename Tag</a>\n<blockquote>\n<p><em>Auto rename paired HTML/XML tags</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*uRKX2-umhSQzlESv.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify\" class=\"markup--anchor markup--h3-anchor\">beautify</a>\n<blockquote>\n<p><em>Beautify code in place for VS Code</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=dbalas.vscode-html2pug\" class=\"markup--anchor markup--h3-anchor\">html2pug</a></h3>\n<blockquote>\n<p><em>Transform html to pug inside your Visual Studio Code, forget about using an external page anymore.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=vilicvane.es-quotes\" class=\"markup--anchor markup--h3-anchor\">ECMAScript Quotes Transformer</a></h3>\n<blockquote>\n<p><em>Transform quotes of ECMAScript string literals</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*W1Z1fIvOGgPclFMJ.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=Rubymaniac.vscode-paste-and-indent\" class=\"markup--anchor markup--h3-anchor\">Paste and Indent</a>\n<blockquote>\n<p><em>Paste code with \"correct\" indentation</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=Tyriar.sort-lines\" class=\"markup--anchor markup--h3-anchor\">Sort Lines</a></h3>\n<blockquote>\n<p><em>Sorts lines of text in specific order</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*a4wPhA7VjJqkp3lu.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=yatki.vscode-surround\" class=\"markup--anchor markup--h3-anchor\">Surround</a>\n<blockquote>\n<p><em>A simple yet powerful extension to add wrapper templates around your code blocks.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*lyjRgfSrvdmhGFXd.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=konstantin.wrapSelection\" class=\"markup--anchor markup--h3-anchor\">Wrap Selection</a>\n<blockquote>\n<p><em>Wraps selection or multiple selections with symbol or multiple symbols</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=tombonnike.vscode-status-bar-format-toggle\" class=\"markup--anchor markup--h3-anchor\">Formatting Toggle</a></h3>\n<blockquote>\n<p><em>Allows you to toggle your formatter on and off with a simple click</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer\" class=\"markup--anchor markup--h3-anchor\">Bracket Pair Colorizer</a></h3>\n<blockquote>\n<p><em>This extension allows matching brackets to be identified with colours. The user can define which characters to match, and which colours to use.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*m3nU-5UxgUxX4-eJ.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=steoates.autoimport\" class=\"markup--anchor markup--h3-anchor\">Auto Import</a>\n<blockquote>\n<p><em>Automatically finds, parses and provides code actions and code completion for all available imports. Works with Typescript and TSX.</em></p>\n</blockquote>\n<h3><a href=\"https://github.com/foxundermoon/vs-shell-format\" class=\"markup--anchor markup--h3-anchor\">shell-format</a></h3>\n<blockquote>\n<p><em>shell script &#x26; Dockerfile &#x26; dotenv format</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*TThlkfK1KgQm5AKU.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=funkyremi.vscode-google-translate\" class=\"markup--anchor markup--h3-anchor\">Vscode Google Translate</a>\n<blockquote>\n<p><em>Quickly translate selected text right in your code</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*JF8NuxAFDxXiTn_u.gif\" class=\"graf-image\" />\n</figure>### Explorer Icons\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme\" class=\"markup--anchor markup--h3-anchor\">Material Icon Theme</a></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*67ZZ9mhoISPk_lM4.png\" class=\"graf-image\" />\n</figure>### Uncategorized\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=auchenberg.vscode-browser-preview\" class=\"markup--anchor markup--h3-anchor\">Browser Preview</a></h3>\n<blockquote>\n<p><em>Browser Preview for VS Code enables you to open a real browser preview inside your editor that you can debug. Browser Preview is powered by Chrome Headless, and works by starting a headless Chrome instance in a new process. This enables a secure way to render web content inside VS Code, and enables interesting features such as in-editor debugging and more!</em></p>\n</blockquote>\n<blockquote>\n<p><strong><em>FYI:… I HAVE TRIED ENDLESSLEY TO GET THE DEBUGGER TO WORK IN VSCODE BUT IT DOES NOT… I SUSPECT THAT'S WHY IT HAS A 3 STAR RATING FOR AN OTHERWISE PHENOMINAL EXTENSION.</em></strong></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Oilwsi7EKGpCZb46.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=CodeRoad.coderoad\" class=\"markup--anchor markup--h3-anchor\">CodeRoad</a>\n<blockquote>\n<p><em>Play interactive tutorials in your favorite editor.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*iV8P93QMmWdYfnrQ.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner\" class=\"markup--anchor markup--h3-anchor\">Code Runner</a>\n<blockquote>\n<p><em>Run code snippet or code file for multiple languages: C, C++, Java, JavaScript, PHP, Python, Perl, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, C# Script, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*hMsM_IEyBklQXchd.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=softwaredotcom.swdc-vscode\" class=\"markup--anchor markup--h3-anchor\">Code Time</a>\n<blockquote>\n<p><em>Automatic time reports by project and other programming metrics right in VS Code.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Uo1BYexJenprpgLa\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=naumovs.color-highlight\" class=\"markup--anchor markup--h3-anchor\">Color Highlight</a>\n<blockquote>\n<p><em>Highlight web colors in your editor</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*ZwE7OHKR5opvDCJJOw9KeQ.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=IBM.output-colorizer\" class=\"markup--anchor markup--h3-anchor\">Output Colorizer</a>\n<blockquote>\n<p><em>Syntax highlighting for the VS Code Output Panel and log files</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*9DpzVZ9cUNp2TMyD.jpg\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=deerawan.vscode-dash\" class=\"markup--anchor markup--h3-anchor\">Dash</a>\n<blockquote>\n<p><em>Dash integration in Visual Studio Code</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*sqGllC-pgXNaEBfB-cxG9Q.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=ryu1kn.edit-with-shell\" class=\"markup--anchor markup--h3-anchor\">Edit with Shell Command</a>\n<blockquote>\n<p><em>Leverage your favourite shell commands to edit text</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*2wW31HJ1nUCjORZe.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig\" class=\"markup--anchor markup--h3-anchor\">Editor Config for VS Code</a>\n<blockquote>\n<p><em>Editor Config for VS Code</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=lukasz-wronski.ftp-sync\" class=\"markup--anchor markup--h3-anchor\">ftp-sync</a></h3>\n<blockquote>\n<p><em>Auto-sync your work to remote FTP server</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*-viKhwxpeYQdWHRE.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=vincaslt.highlight-matching-tag\" class=\"markup--anchor markup--h3-anchor\">Highlight JSX/HTML tags</a>\n<blockquote>\n<p><em>Highlights matching tags in the file.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow\" class=\"markup--anchor markup--h3-anchor\">Indent Rainbow</a></h3>\n<blockquote>\n<p><em>A simple extension to make indentation more readable.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*GK_yEd-50SU3yc_y.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=ftonato.password-generator\" class=\"markup--anchor markup--h3-anchor\">Password Generator</a>\n<blockquote>\n<p><em>Create a secure password using our generator tool. Help prevent a security threat by getting a strong password today.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*qPJAZk9-NcYgsx7H.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=formulahendry.platformio\" class=\"markup--anchor markup--h3-anchor\">PlatformIO</a>\n<blockquote>\n<p><em>An open source ecosystem for IoT development: supports 350+ embedded boards, 20+ development platforms, 10+ frameworks. Arduino and ARM mbed compatible.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*RywVt_vikqB-5urO.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=pnp.polacode\" class=\"markup--anchor markup--h3-anchor\">Polacode</a>\n<blockquote>\n<p><em>Polaroid for your code 📸.</em></p>\n</blockquote>\n<blockquote>\n<p><strong><em>Note: Polacode no longer works as of the most recent update… go for Polacode2020 or CodeSnap…</em></strong></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Io4fPojDRrDf5CmW.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=WallabyJs.quokka-vscode\" class=\"markup--anchor markup--h3-anchor\">Quokka</a>\n<h4>This one is super cool!</h4>\n<blockquote>\n<p><em>Rapid prototyping playground for JavaScript and TypeScript in VS Code, with access to your project's files, inline reporting, code coverage and rich output formatting.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Q9kp8EWZHTD0Hfru.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=sozercan.slack\" class=\"markup--anchor markup--h3-anchor\">Slack</a>\n<blockquote>\n<p><em>Send messages and code snippets, upload files to Slack</em></p>\n</blockquote>\n<p>Personally I found this extension to slow down my editor in addition to confliction with other extensions: (I have over 200 as of this writing)….. <strong>yes I have been made fully aware that I have a problem and need to get help</strong></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*9-xxjXzdPCh_46kZ.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=shyykoserhiy.vscode-spotify\" class=\"markup--anchor markup--h3-anchor\">Spotify</a>\n<p><em>No real advantage over just using Spotify normally… it's problematic enough in implementation that you won't save any time using it. Further, it's a bit tricky to configure … or at least it was the last time I tried syncing it with my spotify account.</em></p>\n<blockquote>\n<p><em>Provides integration with Spotify Desktop client. Shows the currently playing song in status bar, search lyrics and provides commands for controlling Spotify with buttons and hotkeys.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*IqsxXiGpZQWbQbfD.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=jock.svg\" class=\"markup--anchor markup--h3-anchor\">SVG</a>\n<blockquote>\n<p><em>A Powerful SVG Language Support Extension(beta). Almost all the features you need to handle SVG.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*SC6zCXGaBnM_LkgC.png\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=cssho.vscode-svgviewer\" class=\"markup--anchor markup--h3-anchor\">SVG Viewer</a>\n<blockquote>\n<p><em>View an SVG in the editor and export it as data URI scheme or PNG.</em></p>\n</blockquote>\n<h3><a href=\"https://marketplace.visualstudio.com/items?itemName=ryu1kn.text-marker\" class=\"markup--anchor markup--h3-anchor\">Text Marker (Highlighter)</a></h3>\n<blockquote>\n<p><em>Highlight multiple text patterns with different colors at the same time. Highlighting a single text pattern can be done with the editor's search functionality, but it cannot highlight multiple patterns at the same time, and this is where this extension comes handy.</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*YDreVyGNjZmqj_KC.gif\" class=\"graf-image\" />\n</figure>### <a href=\"https://marketplace.visualstudio.com/items?itemName=samundrak.esdoc-mdn\" class=\"markup--anchor markup--h3-anchor\">ESDOC MDN</a>\n<h3>THIS IS A MUST HAVE</h3>\n<blockquote>\n<p><em>Quickly bring up helpful MDN documentation in the editor</em></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*xiUfWBsz8x8beY70.gif\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*mMBU6d1iCkt5VHq2.gif\" class=\"graf-image\" />\n</figure>### Themes:\n<p>In the interest of not making the reader scroll endlessly as I often do… I've made a separate post for that here. If you've made it this far, I thank you!</p>\n<a href=\"https://bryanguner.medium.com/my-favorite-vscode-themes-9bab65af3f0f\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bryanguner.medium.com/my-favorite-vscode-themes-9bab65af3f0f\">\n<strong>My Favorite VSCode <em>Themes</em>\n</strong>\n<br />\nThemesbryanguner.medium.com</a>\n<a href=\"https://bryanguner.medium.com/my-favorite-vscode-themes-9bab65af3f0f\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<hr>\n<h3>If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content:</h3>\n<a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://gist.github.com/bgoonz\">\n<strong>bgoonz's gists</strong>\n<br />\n<em>Instantly share code, notes, and snippets. Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python |…</em>gist.github.com</a>\n<a href=\"https://gist.github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>Or Checkout my personal Resource Site:</h3>\n<a href=\"https://web-dev-resource-hub.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://web-dev-resource-hub.netlify.app/\">\n<strong>Web-Dev-Resource-Hub</strong>\n<br />\n<em>Edit description</em>web-dev-resource-hub.netlify.app</a>\n<a href=\"https://web-dev-resource-hub.netlify.app/\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/b9f4c8d91931\">March 18, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/everything-you-need-to-get-started-with-vscode-extensions-resources-b9f4c8d91931\" class=\"p-canonical\">Canonical link</a></p>\n<p> May 23, 2021.</p>"},{"url":"/docs/reference/notes-template/","relativePath":"docs/reference/notes-template.md","relativeDir":"docs/reference","base":"notes-template.md","name":"notes-template","frontmatter":{"title":"Notes Template","weight":0,"seo":{"title":"Gatsby Plugins For This Sites Content Model","description":"This is my markdown notes tempate","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Gatsby Plugins For This Sites Content Model","keyName":"property"},{"name":"og:description","value":"This is the Gatsby Plugins For This Sites Content Model page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Gatsby Plugins For This Sites Content Model"},{"name":"twitter:description","value":"This is the Gatsby Plugins For This Sites Content Model page"}]},"template":"docs"},"html":"<p><img src=\"images/0001-76d89ef6.jpg\" alt=\"image\"></p>\n<h1>Title</h1>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<ul>\n<li>\n<p>Description:</p>\n<blockquote>\n<p>/_ Description here _/</p>\n</blockquote>\n</li>\n</ul>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>ToC:</h2>\n<ul>\n<li>\n<p><a href=\"#title\">Title</a></p>\n<ul>\n<li><a href=\"#toc\">ToC:</a></li>\n<li><a href=\"#main-notes\">Main Notes:</a></li>\n<li><a href=\"#resource-links\">Resource Links:</a></li>\n<li><a href=\"#10-x-10-table\">10 X 10 Table</a></li>\n<li><a href=\"#headers\">Headers</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#h1\">H1</a></p>\n<ul>\n<li>\n<p><a href=\"#h2\">H2</a></p>\n<ul>\n<li>\n<p><a href=\"#h3\">H3</a></p>\n<ul>\n<li>\n<p><a href=\"#h4\">H4</a></p>\n<ul>\n<li>\n<p><a href=\"#h5\">H5</a></p>\n<ul>\n<li><a href=\"#h6\">H6</a></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><a href=\"#alt-h1\">Alt-H1</a></p>\n<ul>\n<li><a href=\"#alt-h2\">Alt-H2</a></li>\n<li><a href=\"#emphasis\">Emphasis</a></li>\n<li><a href=\"#lists\">Lists</a></li>\n<li><a href=\"#links\">Links</a></li>\n<li><a href=\"#images\">Images</a></li>\n<li><a href=\"#code-and-syntax-highlighting\">Code and Syntax Highlighting</a></li>\n<li><a href=\"#tables\">Tables</a></li>\n<li><a href=\"#blockquotes\">Blockquotes</a></li>\n<li><a href=\"#inline-html\">Inline HTML</a></li>\n<li><a href=\"#horizontal-rule\">Horizontal Rule</a></li>\n<li><a href=\"#line-breaks\">Line Breaks</a></li>\n<li><a href=\"#youtube-videos\">YouTube Videos</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#this-is-an-h1\">This is an H1</a></p>\n<ul>\n<li>\n<p><a href=\"#this-is-an-h2\">This is an H2</a></p>\n<ul>\n<li>\n<p><a href=\"#this-is-an-h3\">This is an H3</a></p>\n<ul>\n<li><a href=\"#this-is-an-h4\">This is an H4</a></li>\n</ul>\n</li>\n</ul>\n</li>\n<li><a href=\"#quoting\">Quoting</a></li>\n<li><a href=\"#unordered-lists\">Unordered Lists</a></li>\n<li><a href=\"#ordered-lists\">Ordered Lists</a></li>\n<li><a href=\"#video-embeds\">Video Embeds</a></li>\n<li><a href=\"#code-blocks\">Code Blocks</a></li>\n<li><a href=\"#tables-1\">Tables</a></li>\n</ul>\n</li>\n</ul>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>Main Notes:</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>Resource Links:</h2>\n<ol>\n<li><a href=\"\"></a></li>\n<li><a href=\"\"></a></li>\n<li><a href=\"\"></a></li>\n<li><a href=\"\"></a></li>\n<li><a href=\"\"></a></li>\n<li><a href=\"\"></a></li>\n</ol>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>10 X 10 Table</h2>\n<table>\n<tbody>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n<tr>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n<td>&nbsp;</td>\n</tr>\n</tbody>\n</table>\n<a name=\"headers\"/>\n<h2>Headers</h2>\n<h1>H1</h1>\n<h2>H2</h2>\n<h3>H3</h3>\n<h4>H4</h4>\n<h5>H5</h5>\n<h6>H6</h6>\n<p>Alternatively, for H1 and H2, an underline-ish style:</p>\n<h1>Alt-H1</h1>\n<h2>Alt-H2</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># H1\n\n## H2\n\n### H3\n\n#### H4\n\n##### H5\n\n###### H6\n\nAlternatively, for H1 and H2, an underline-ish style:\n\n# Alt-H1\n\n## Alt-H2\n\n&lt;a name=\"emphasis\"/>\n\n## Emphasis\n\n\n\nEmphasis, aka italics, with *asterisks* or _underscores_.\n\nStrong emphasis, aka bold, with **asterisks** or __underscores__.\n\nCombined emphasis with **asterisks and _underscores_**.\n\nStrikethrough uses two tildes. ~~Scratch this.~~</code></pre></div>\n<p>Emphasis, aka italics, with <em>asterisks</em> or <em>underscores</em>.</p>\n<p>Strong emphasis, aka bold, with <strong>asterisks</strong> or <strong>underscores</strong>.</p>\n<p>Combined emphasis with <strong>asterisks and <em>underscores</em></strong>.</p>\n<p>Strikethrough uses two tildes. <del>Scratch this.</del></p>\n<a name=\"lists\"/>\n<h2>Lists</h2>\n<p>(In this example, leading and trailing spaces are shown with with dots: ⋅)</p>\n<ol>\n<li>First ordered list item</li>\n<li>Another item\n⋅⋅* Unordered sub-list.</li>\n<li>Actual numbers don't matter, just that it's a number\n⋅⋅1. Ordered sub-list</li>\n<li>And another item.</li>\n</ol>\n<p>⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).</p>\n<p>⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅\n⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅\n⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)</p>\n<ul>\n<li>Unordered list can use asterisks</li>\n<li>Or minuses</li>\n<li>Or pluses</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1.  First ordered list item\n2.  Another item\n\n-   Unordered sub-list.\n\n1.  Actual numbers don't matter, just that it's a number\n2.  Ordered sub-list\n3.  And another item.\n\n    You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).\n\n    To have a line break without a paragraph, you will need to use two trailing spaces.\\\n    Note that this line is separate, but within the same paragraph.\\\n    (This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)\n\n-   Unordered list can use asterisks\n\n&lt;!---->\n\n-   Or minuses\n\n&lt;!---->\n\n-   Or pluses\n\n&lt;a name=\"links\"/>\n\n## Links\n\nThere are two ways to create links.\n\n\n\n[I'm an inline-style link](https://www.google.com)\n\n[I'm an inline-style link with title](https://www.google.com \"Google's Homepage\")\n\n[I'm a reference-style link][Arbitrary case-insensitive reference text]\n\n[I'm a relative reference to a repository file](../blob/master/LICENSE)\n\n[You can use numbers for reference-style link definitions][1]\n\nOr leave it empty and use the [link text itself].\n\nURLs and URLs in angle brackets will automatically get turned into links.\nhttp://www.example.com or &lt;http://www.example.com> and sometimes\nexample.com (but not on Github, for example).\n\nSome text to show that the reference links can follow later.\n\n[arbitrary case-insensitive reference text]: https://www.mozilla.org\n[1]: http://slashdot.org\n[link text itself]: http://www.reddit.com</code></pre></div>\n<p><a href=\"https://www.google.com\">I'm an inline-style link</a></p>\n<p><a href=\"https://www.google.com\" title=\"Google&#x27;s Homepage\">I'm an inline-style link with title</a></p>\n<p><a href=\"https://www.mozilla.org\">I'm a reference-style link</a></p>\n<p><a href=\"../blob/master/LICENSE\">I'm a relative reference to a repository file</a></p>\n<p><a href=\"http://slashdot.org\">You can use numbers for reference-style link definitions</a></p>\n<p>Or leave it empty and use the <a href=\"http://www.reddit.com\">link text itself</a>.</p>\n<p>URLs and URLs in angle brackets will automatically get turned into links.\n<a href=\"http://www.example.com\">http://www.example.com</a> or <a href=\"http://www.example.com\">http://www.example.com</a> and sometimes\nexample.com (but not on Github, for example).</p>\n<p>Some text to show that the reference links can follow later.</p>\n<a name=\"images\"/>\n<h2>Images</h2>\n<p><img src=\"images/md-cheat-sheet-42411273.png\" alt=\"image\"></p>\n<p>Here's our logo (hover to see the title text):</p>\n<p>Inline-style:\n<img src=\"https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png\" alt=\"alt text\" title=\"Logo Title Text 1\"></p>\n<p>Reference-style:\n<img src=\"https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png\" alt=\"alt text\" title=\"Logo Title Text 2\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Here's our logo (hover to see the title text):\n\nInline-style:\n![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png 'Logo Title Text 1')\n\nReference-style:\n![alt text][logo]\n\n[logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png 'Logo Title Text 2'\n\n&lt;a name=\"code\"/>\n\n## Code and Syntax Highlighting\n\nCode blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and _Markdown Here_ -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. _Markdown Here_ supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the [highlight.js demo page](http://softwaremaniacs.org/media/soft/highlight/test.html).\n\n\n\nInline `code` has `back-ticks around` it.</code></pre></div>\n<p>Inline <code class=\"language-text\">code</code> has <code class=\"language-text\">back-ticks around</code> it.</p>\n<p>Blocks of code are either fenced by lines with three back-ticks <code>```</code>, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.</p>\n<pre lang=\"no-highlight\">\n<code>```js\n//\nvar s = \"JavaScript syntax highlighting\";\nalert(s);\n```\n\n```python\ns = \"Python syntax highlighting\"\nprint s\n```\n\n```\nNo language indicated, so no syntax highlighting.\nBut let's throw in a &lt;b&gt;tag&lt;/b&gt;.\n```\n</code>\n</pre>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> <span class=\"token string\">'JavaScript syntax highlighting'</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">alert</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token string\">\"Python syntax highlighting\"</span>\n<span class=\"token keyword\">print</span> s</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No language indicated, so no syntax highlighting in Markdown Here (varies on Github).\nBut let's throw in a &lt;b>tag&lt;/b>.</code></pre></div>\n<a name=\"tables\"/>\n<h2>Tables</h2>\n<p>Tables aren't part of the core Markdown spec, but they are part of GFM and <em>Markdown Here</em> supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.</p>\n<p>Colons can be used to align columns.</p>\n<table>\n<thead>\n<tr>\n<th>Tables</th>\n<th align=\"center\">Are</th>\n<th align=\"right\">Cool</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>col 3 is</td>\n<td align=\"center\">right-aligned</td>\n<td align=\"right\">$1600</td>\n</tr>\n<tr>\n<td>col 2 is</td>\n<td align=\"center\">centered</td>\n<td align=\"right\">$12</td>\n</tr>\n<tr>\n<td>zebra stripes</td>\n<td align=\"center\">are neat</td>\n<td align=\"right\">$1</td>\n</tr>\n</tbody>\n</table>\n<p>There must be at least 3 dashes separating each header cell.\nThe outer pipes (|) are optional, and you don't need to make the\nraw Markdown line up prettily. You can also use inline Markdown.</p>\n<table>\n<thead>\n<tr>\n<th>Markdown</th>\n<th>Less</th>\n<th>Pretty</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><em>Still</em></td>\n<td><code class=\"language-text\">renders</code></td>\n<td><strong>nicely</strong></td>\n</tr>\n<tr>\n<td>1</td>\n<td>2</td>\n<td>3</td>\n</tr>\n</tbody>\n</table>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Colons can be used to align columns.\n\n| Tables        |      Are      |  Cool |\n| ------------- | :-----------: | ----: |\n| col 3 is      | right-aligned | $1600 |\n| col 2 is      |   centered    |   $12 |\n| zebra stripes |   are neat    |    $1 |\n\nThere must be at least 3 dashes separating each header cell. The outer pipes (|) are optional, and you don't need to make the raw Markdown line up prettily. You can also use inline Markdown.\n\n| Markdown | Less      | Pretty     |\n| -------- | --------- | ---------- |\n| _Still_  | `renders` | **nicely** |\n| 1        | 2         | 3          |\n\n&lt;a name=\"blockquotes\"/>\n\n## Blockquotes\n\n\n\n> Blockquotes are very handy in email to emulate reply text.\n> This line is part of the same quote.\n\nQuote break.\n\n> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote.</code></pre></div>\n<blockquote>\n<p>Blockquotes are very handy in email to emulate reply text.\nThis line is part of the same quote.</p>\n</blockquote>\n<p>Quote break.</p>\n<blockquote>\n<p>This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can <em>put</em> <strong>Markdown</strong> into a blockquote.</p>\n</blockquote>\n<a name=\"html\"/>\n<h2>Inline HTML</h2>\n<p>You can also use raw HTML in your Markdown, and it'll mostly work pretty well.</p>\n<dl>\n  <dt>Definition list</dt>\n  <dd>Is something people use sometimes.</dd>\n  <dt>Markdown in HTML</dt>\n  <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>\n</dl>\n```\n<dl>\n  <dt>Definition list</dt>\n  <dd>Is something people use sometimes.</dd>\n  <dt>Markdown in HTML</dt>\n  <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>\n</dl>\n<a name=\"hr\"/>\n<h2>Horizontal Rule</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Three or more...\n\n[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png)](#-)\n\nHyphens\n\n***\n\nAsterisks\n\n___\n\nUnderscores</code></pre></div>\n<p>Three or more...</p>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<p>Hyphens</p>\n<hr>\n<p>Asterisks</p>\n<hr>\n<p>Underscores</p>\n<a name=\"lines\"/>\n<h2>Line Breaks</h2>\n<p>My basic recommendation for learning how line breaks work is to experiment and discover -- hit &#x3C;Enter> once (i.e., insert one newline), then hit it twice (i.e., insert two newlines), see what happens. You'll soon learn to get what you want. \"Markdown Toggle\" is your friend.</p>\n<p>Here are some things to try out:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Here's a line for us to start with.\n\nThis line is separated from the one above by two newlines, so it will be a *separate paragraph*.\n\nThis line is also a separate paragraph, but...\nThis line is only separated by a single newline, so it's a separate line in the *same paragraph*.</code></pre></div>\n<p>Here's a line for us to start with.</p>\n<p>This line is separated from the one above by two newlines, so it will be a <em>separate paragraph</em>.</p>\n<p>This line is also begins a separate paragraph, but...<br>\nThis line is only separated by a single newline, so it's a separate line in the <em>same paragraph</em>.</p>\n<p>(Technical note: <em>Markdown Here</em> uses GFM line breaks, so there's no need to use MD's two-space line breaks.)</p>\n<a name=\"videos\"/>\n<h2>YouTube Videos</h2>\n<p>They can't be added directly but you can add an image with a link to the video like this:</p>\n<p><a href=\"http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE\n\" target=\"_blank\">\n<img src=\"http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg\"\nalt=\"IMAGE ALT TEXT HERE\" width=\"240\" height=\"180\" border=\"10\" />\n</a></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Or, in pure Markdown, but losing the image sizing and border:\n\n\n\n[![IMAGE ALT TEXT HERE](http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg)](http://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID_HERE)</code></pre></div>\n<p><strong>This is a paragraph</strong>. Pellentesque habitant morbi <em>tristique senectus et netus et malesuada</em> fames ac turpis egestas. Vestibulum <a href=\"https://www.google.com\">tortor quam</a>, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit <mark>amet est et sapien ullamcorper</mark> pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi.</p>\n<h1>This is an H1</h1>\n<p>Quisque facilisis erat a dui. Nam malesuada ornare dolor. Cras gravida, this is marked text ornare, erat elit consectetuer erat, id egestas pede nibh eget odio. Proin tincidunt, velit vel porta elementum, magna diam molestie sapien, non aliquet massa pede eu diam. Aliquam iaculis. Fusce et ipsum et nulla tristique facilisis.</p>\n<h2>This is an H2</h2>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat. Sed quis velit. Nulla facilisi. Nulla libero.</p>\n<h3>This is an H3</h3>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat. Sed quis velit. Nulla facilisi. Nulla libero.</p>\n<h4>This is an H4</h4>\n<p>Quisque facilisis erat a dui. Nam malesuada ornare dolor. Cras gravida, diam sit amet rhoncus ornare, erat elit consectetuer erat, id egestas pede nibh eget odio. Proin tincidunt, velit vel porta elementum, magna diam molestie sapien, non aliquet massa pede eu diam. Aliquam iaculis.</p>\n<h2>Quoting</h2>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>\n<blockquote>\n<p>Creativity is allowing yourself to make mistakes. Design is knowing which ones to keep. - Scott Adams</p>\n</blockquote>\n<p>Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat. Sed quis velit. Nulla facilisi. Nulla libero.</p>\n<hr />\n<h2>Unordered Lists</h2>\n<ul>\n<li>Donec non tortor in arcu mollis feugiat</li>\n<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</li>\n<li>Donec id eros eget quam aliquam gravida</li>\n<li>Vivamus convallis urna id felis</li>\n<li>Nulla porta tempus sapien</li>\n</ul>\n<h2>Ordered Lists</h2>\n<ol>\n<li>Donec non tortor in arcu mollis feugiat</li>\n<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</li>\n<li>Donec id eros eget quam aliquam gravida</li>\n<li>Vivamus convallis urna id felis</li>\n<li>Nulla porta tempus sapien</li>\n</ol>\n<h2>Video Embeds</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/8uuFIi-ghPI\"  allowfullscreen>\n</iframe>\n<br>\n<h2>Code Blocks</h2>\n<p>Blocks of code are either fenced by <code class=\"language-text\">lines with three back-ticks</code>, or are indented with four spaces.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;!-- Some example CSS code -->\nbody {\n  color:red;\n}</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nwindow<span class=\"token punctuation\">.</span>$docsify <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">coverpage</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token comment\">// Custom file name</span>\n    <span class=\"token literal-property property\">coverpage</span><span class=\"token operator\">:</span> <span class=\"token string\">'cover.md'</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token comment\">// mutiple covers</span>\n    <span class=\"token literal-property property\">coverpage</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/zh-cn/'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token comment\">// mutiple covers and custom file name</span>\n    <span class=\"token literal-property property\">coverpage</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string-property property\">'/'</span><span class=\"token operator\">:</span> <span class=\"token string\">'cover.md'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string-property property\">'/zh-cn/'</span><span class=\"token operator\">:</span> <span class=\"token string\">'cover.md'</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Tables</h2>\n<div class=\"responsive-table\">\n  <table>\n      <caption>Table with thead, tfoot, and tbody</caption>\n    <thead>\n      <tr>\n        <th>Header content 1</th>\n        <th>Header content 2</th>\n      </tr>\n    </thead>\n    <tbody>\n      <tr>\n        <td>Body content 1</td>\n        <td>Body content 2</td>\n      </tr>\n    </tbody>\n    <tfoot>\n      <tr>\n        <td>Footer content 1</td>\n        <td>Footer content 2</td>\n      </tr>\n    </tfoot>\n  </table>\n</div>\n<div class=\"note\">\n<strong>Note:</strong> Both of the features you used above are parts of the Document Object Model (DOM) API, which allows you to manipulate documents.</div>\n<div class=\"important\">\n<strong>Important:</strong> In this article, try entering the example code lines into your JavaScript console to see what happens. For more details on JavaScript consoles, see Discover browser developer tools.</div>"},{"url":"/docs/resources/","relativePath":"docs/resources/index.md","relativeDir":"docs/resources","base":"index.md","name":"index","frontmatter":{"title":"Resources","template":"docs"},"html":"<p>hi</p>"},{"url":"/docs/tips/","relativePath":"docs/tips/index.md","relativeDir":"docs/tips","base":"index.md","name":"index","frontmatter":{"title":"Tips","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Lorem ipsum</h2>"},{"url":"/docs/tips/regex-tips/","relativePath":"docs/tips/regex-tips.md","relativeDir":"docs/tips","base":"regex-tips.md","name":"regex-tips","frontmatter":{"title":"Regex Tricks","weight":0,"excerpt":"Regex Tricks","seo":{"title":"Regex Tricks","description":"Regular expressions make light work of single-character delimiters which is why its so easy to remove markup from a string","robots":[],"extra":[]},"template":"docs"},"html":"<p>Regular expressions make light work of <strong>single-character delimiters</strong>, which is why it's so easy to remove markup from a string:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">str = str.replace(/(&lt;[\\/]?[^>]+>)/g, '');</code></pre></div>\n<p>It's the negation in the character class that does the real work:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[^>]</code></pre></div>\n<p>Which means <em>\"anything except <code class=\"language-text\">&lt;</code>\"</em>. So the expression looks for the starting tag-delimiter and possible slash, then anything except the closing tag-delimiter, and then the delimiter itself. Easy.</p>\n<p>However comments are not so simple, because comment delimiters are comprised of <strong>more than one character</strong>. Multi-line comments in CSS and JavaScript, for example, start with <code class=\"language-text\">/*</code> and end with <code class=\"language-text\">*/</code>, but between those two delimiters there could be <strong>any number of unrelated stars</strong>.</p>\n<p>I often use multiple stars in comments, to indicate the severity of a bug I've just noticed, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/*** this is a bug with 3-star severity ***/</code></pre></div>\n<p>But if we tried to parse that with a single negation character, it would fail:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">str = str.replace(/(\\/\\*[^\\*]+\\*\\/)/g, '');</code></pre></div>\n<p>Yet it's not possible with regular expressions to say: <em>\"anything except [this sequence of characters]\"</em>, we can only say: <em>\"anything except [one of these single characters]\"</em>.</p>\n<p>So here's the regular expression we need instead:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">str = str.replace(/(\\/\\*([^*]|(\\*+[^*\\/]))*\\*+\\/)/gm, '');</code></pre></div>\n<p>The expression handles unrelated characters by <strong>looking at what comes after them</strong> — stars are allowed as long as they're not followed by a slash, until we find one that is, and that's the end of the comment.</p>\n<p>So it says: \"<code class=\"language-text\">/</code> then <code class=\"language-text\">*</code> (then anything except <code class=\"language-text\">*</code> OR any number of <code class=\"language-text\">*</code> followed by anything except <code class=\"language-text\">/</code>)(and any number of instances of that) then any number of <code class=\"language-text\">*</code> then <code class=\"language-text\">/</code>\".</p>\n<p>(The syntax looks particular convoluted, because <code class=\"language-text\">*</code> and <code class=\"language-text\">/</code> are both special characters in regular expressions, so the ambiguous literal ones have to be escaped. Also note the <code class=\"language-text\">m</code> flag at the end of the expression, which means <strong>multi-line</strong>, and specifies that the regular expression should search across more than one line of text.)</p>\n<p>Using the same principle then, we can adapt the expression to search for any kind of complex delimiters. Here's another one that matches HTML comments:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">str = str.replace(/(&lt;!\\-\\-([^\\-]|(\\-+[^>]))*\\-+>)/gm, '');</code></pre></div>\n<p>And here's one for <code class=\"language-text\">CDATA</code> sections:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">str = str.replace(/(&lt;\\!\\[CDATA\\[([^\\]]|(\\]+[^>]))*\\]+>)/gm, '');</code></pre></div>\n<h2>2. Using Replacement Callbacks</h2>\n<p>The <code class=\"language-text\">replace</code> function can also be <strong>passed a callback</strong> as its second parameter, and this is invaluable in cases where the replacement you want can't be described in a simple expression. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nisocode <span class=\"token operator\">=</span> isocode<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^([a-z]+)(\\-[a-z]+)?$</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">match<span class=\"token punctuation\">,</span> lang<span class=\"token punctuation\">,</span> country</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> lang<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>country <span class=\"token operator\">?</span> country<span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>That example normalizes the capitalisation in language codes — so <code class=\"language-text\">\"EN\"</code> would become <code class=\"language-text\">\"en\"</code>, while <code class=\"language-text\">\"en-us\"</code> would become <code class=\"language-text\">\"en-US\"</code>.</p>\n<p>The first argument that's passed to the callback is always the complete match, then each subsequent argument corresponds with the backreferences (i.e. <code class=\"language-text\">arguments[1]</code> is what a string replacement would refer to as <code class=\"language-text\">$1</code>, and so on).</p>\n<p>So taking <code class=\"language-text\">\"en-us\"</code> as the input, we'd get the three arguments:</p>\n<ol start=\"0\">\n<li><code class=\"language-text\">\"en-us\"</code></li>\n<li><code class=\"language-text\">\"en\"</code></li>\n<li><code class=\"language-text\">\"-us\"</code></li>\n</ol>\n<p>Then all the function has to do is enforce the appropriate cases, re-combine the parts and return them. Whatever the callback returns is what the replacement itself returns.</p>\n<p>But we don't actually have to assign the return value (or return at all), and if we don't, then the original string will be unaffected. This means we can use <code class=\"language-text\">replace</code> as a <strong>general-purpose string processor</strong> — to extract data from a string without changing it.</p>\n<p>Here's another example, that combines the multi-line comment expression from the previous section, with a callback that extracts and saves the text of each comment:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let comments = [];\nstr.replace(/(\\/\\*([^*]|(\\*+[^*\\/]))*\\*+\\/)/gm,\n  function(match)\n  {\n    comments.push(match);\n  });</code></pre></div>\n<p>Since nothing is returned, the original string remains unchanged. Although if we wanted to extract <em>and</em> remove the comments, we could simply return and assign an empty-string:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> comments <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nstr <span class=\"token operator\">=</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(\\/\\*([^*]|(\\*+[^*\\/]))*\\*+\\/)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">gm</span></span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">match</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    comments<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>match<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>3. Working With Invisible Delimiters</h2>\n<p>Extracting content is all very well when it uses standard delimiters, but what if you're using <strong>custom delimiters</strong> that only your program knows about? The problem there is that <strong>the string might already contain your delimiter</strong>, literally character for character, and then what do you?</p>\n<p>Well, recently I came up with a very cute trick, that not only avoids this problem, it's also as simple to use as the single-character class we saw at the start! The trick is to use <strong>unicode characters that the document can't contain</strong>.</p>\n<p>Originally I tried this with <em>undefined</em> characters, and that certainly worked, but it's not safe to assume that any such character will always be undefined (or that the document won't already contain it anyway). Then I discovered that Unicode actually reserves a set of code-points specifically for this kind of thing — so-called <a href=\"http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Noncharacters\" title=\"Mapping of Unicode Characters (wikipedia.org)\">noncharacters</a>, which will never be used to define actual characters. A valid Unicode document is not allowed to contain noncharacters, but a program can use them internally for its own purposes.</p>\n<p>I was working on CSS processor, and I needed to remove all the comments before parsing the selectors, so they wouldn't confuse the selector-matching expressions. But they had to be replaced in the source with something that took up the same number of lines, so that the line-numbers would remain accurate. Then later they would have to be added back to the source, for final output.</p>\n<p>So first we use a regex callback to extract and save the comments. The callback returns a copy of the match in which all non-whitespace is converted to space, and which is delimited with a noncharacter either side:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let comments = [];\ncsstext = csstext.replace(/(\\/\\*([^*]|(\\*+([^*\\/])))*\\*+\\/)/gm,\n  function(match)\n  {\n    comments.push(match);\n    return '\\ufddf' + match.replace(/[\\S]/gim, ' ') + '\\ufddf';\n  });</code></pre></div>\n<p>That creates an array of comments in the same source-order as the spaces they leave behind, while the spaces themselves take-up as many lines as the original comment.</p>\n<p>Then the originals can be restored simply by replacing each delimited space with its corresponding saved comment — and since the delimiters are single characters, we only need a <strong>simple character class</strong> to match each pair:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">csstext = csstext.replace(/(\\ufddf[^\\ufddf]+\\ufddf)/gim,\n  function()\n  {\n    return comments.shift();\n  });</code></pre></div>\n<p>How easy is that!</p>"},{"url":"/docs/tips/ubuntu-setup/","relativePath":"docs/tips/ubuntu-setup.md","relativeDir":"docs/tips","base":"ubuntu-setup.md","name":"ubuntu-setup","frontmatter":{"title":"ubuntu setup","weight":1,"excerpt":"ubuntu setup","seo":{"title":"ubuntu setup","description":"ubuntu setup","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Fresh Ubuntu Setup:</h1>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> update <span class=\"token parameter variable\">-y</span>\n\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> upgrade <span class=\"token parameter variable\">-y</span>\n\n<span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> user.name  bryan\n\n<span class=\"token function\">git</span> config <span class=\"token parameter variable\">--global</span> user.email bryan.guner@gmail.com\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> update\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> build-essential\n\n<span class=\"token function\">curl</span> -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh <span class=\"token operator\">|</span> <span class=\"token function\">bash</span>\n<span class=\"token builtin class-name\">.</span> ./.bashrc\n\nnvm <span class=\"token function\">install</span> <span class=\"token parameter variable\">--lts</span>\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">unzip</span>\n\n<span class=\"token function\">npm</span> <span class=\"token function\">install</span> <span class=\"token parameter variable\">-g</span> mocha\n\n\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> update\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> upgrade\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> python3</code></pre></div>"},{"url":"/docs/tools/dev-utilities/","relativePath":"docs/tools/dev-utilities.md","relativeDir":"docs/tools","base":"dev-utilities.md","name":"dev-utilities","frontmatter":{"title":"General Utilities","weight":0,"excerpt":"General Utilities","seo":{"title":"General Utilities","description":"General Utilities Tools","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>General Utilities</h2>\n<br>\n<br>\n<br>\n<h1> Search </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://www.algolia.com/interface-demos/6ed0c3de-f9e4-4cc8-a7b2-c6c7c979cc5e\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Photo Editor   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://onlinephotoeditor.goonlinetools.com/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> PDF Tools   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://pdf-tools-xi.vercel.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Text Tools     </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://bgoonz.github.io/Web_Utility_Tools/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Ternary Converter   </h1>\n<br>\n<iframe height=\"1000px\" width=\"1200px\" scrolling=\"yes\" src=\"https://ternary42.netlify.app/\"     loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe height=\"1000px\" width=\"1200px\" scrolling=\"yes\" title=\"Dashed Border Generator\" src=\"https://codepen.io/bgoonz/embed/preview/zYwLVmb?default-tab=result&editable=true&theme-id=dark\"    loading=\"lazy\"  allowfullscreen=\"true\">\n  See the Pen <a href=\"https://codepen.io/bgoonz/pen/zYwLVmb\">\n  Dashed Border Generator</a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n  on <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<br>"},{"url":"/docs/tools/markdown-html/","relativePath":"docs/tools/markdown-html.md","relativeDir":"docs/tools","base":"markdown-html.md","name":"markdown-html","frontmatter":{"title":"md and html","weight":1,"excerpt":"Tools For Markdown & Html","seo":{"title":"md and html","description":"md and html","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Tools For Markdown &#x26; Html</h2>\n<br>\n<br>\n<br>\n<br>\n<h1>   Paste To Markdown </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://bgoonz.github.io/paste-2-markdown-web/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n        \n        \n   \n<br>\n<br>\n<h1>   Paste Excel Tabel To Markdown </h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://codepen.io/bgoonz/embed/JjNaPpL?default-tab=result&theme-id=light\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1>Paste excel to HTML</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://pedantic-wing-adbf82.netlify.app/\" height=\"1000px\" width=\"1200px\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>"},{"url":"/docs/tools/","relativePath":"docs/tools/index.md","relativeDir":"docs/tools","base":"index.md","name":"index","frontmatter":{"title":"Tools","excerpt":"See some interesting tools developed by the Web-Dev-Hubcommunity to help automate parts of your workflow.","seo":{"title":"Tools","description":"paste to markdown, excel table to markdown, excel to html, cloud storage, text manipulation, ternary converter, github html preview, form builder, border","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Tools","keyName":"property"},{"name":"og:description","value":"paste to markdown, excel table to markdown, excel to html, cloud storage, text manipulation, ternary converter, github html preview, form builder, border","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Tools"},{"name":"twitter:description","value":"This is the tools page"},{"name":"og:image","value":"images/tex.png","keyName":"property","relativeUrl":true}]},"template":"docs"},"html":"<h1>   Markdown tools  </h1>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://random-static-html-deploys.netlify.app/markdow-tools-embed.html\" height=\"800px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://drive.google.com/embeddedfolderview?id=1DHyQsPLziqSUODclplhnNX1eknzbZrL8#grid\" style=\"width:100%; height:600px; border:0;\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> HTML TO Markdown Converter  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://bgoonz.github.io/html-2-md-converter/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> PDF Tools   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://pdf-tools-xi.vercel.app/\" height=\"8000px\" width=\"100%\" style=\"\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Number Base Converter  </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://number-base-converter-react.vercel.app/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n  <h1>  Text Tools </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://devtools42.netlify.app/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n  <h1>  Other Tools </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://bgoonz.github.io/more-tools-textool-template-format/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<h1>  Awesome Search </h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://codepen.io/bgoonz/embed/JjNaPpL?default-tab=result&theme-id=light\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1>Paste excel to HTML</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://pedantic-wing-adbf82.netlify.app/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<h1>  Cloud Storage </h1>\n<br>\n<h2> Up to 1TB of cloud Storage for file sharing!</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://onedrive.live.com/embed?cid=D21009FDD967A241&resid=D21009FDD967A241%21538729&authkey=AHSDSyoYqzg2K2E\" height=\"800px\" width=\"100%\" style=\"zoom:0.69; align-self:center;display:auto;display: block;border:2px solid gold;\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://resourcerepo2.netlify.app/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1> Text Tools     </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://devtools42.netlify.app/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Ternary Converter   </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://ternary42.netlify.app/\" height=\"8000px\" width=\"100%\" style=\"\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Github HTML Render from link </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://githtmlpreview.netlify.app/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1> Form Builder GUI </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://fourm-builder-gui.netlify.app/\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<!-- <br>\n<h1> Border Builder </h1>\n<br>\n\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://random-static-html-deploys.netlify.app/web-speech-api-master/speak-easy-synthesis/index.html\" height=\"8000px\" width=\"100%\" style=\"\"scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n\n<br>\n\n\n<br>\n<br>\n<br>\n<br>\n\n\n<br>\n<br>\n<br>\n -->\n<br>\n<br>\n<h1>                </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" src=\"https://ds-algo-official.netlify.app/\" height=\"800px\" style=\"width: 100%;\" scrolling=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\">\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1>                </h1>\n<br>\n <iframe height=\"800\" style=\"width: 100%;\" scrolling=\"yes\" title=\"Simple Typing Carousel \" src=\"https://codepen.io/bgoonz/embed/ExZvGoZ?default-tab=html%2Cresult\"    loading=\"lazy\"  allowfullscreen=\"true\">\n  See the Pen <a href=\"https://codepen.io/bgoonz/pen/ExZvGoZ\">\n  Simple Typing Carousel </a> by Bryan C Guner (<a href=\"https://codepen.io/bgoonz\">@bgoonz</a>)\n  on <a href=\"https://codepen.io\">CodePen</a>.\n</iframe>\n<b"},{"url":"/docs/tools/this-website/","relativePath":"docs/tools/this-website.md","relativeDir":"docs/tools","base":"this-website.md","name":"this-website","frontmatter":{"title":"Backup Of This Website","template":"docs","excerpt":"Link for this backup"},"html":"<p><strong><a href=\"https://app.box.com/s/gjls3z2e6lqx595tadegrhhvnaxv5fgp\">Website Backup</a></strong> </p>\n<blockquote>\n<p><strong><em><a href=\"https://airtable.com/app5K5kOhjKyHufeW/tblny8xk6qhZ0ODmp/viwm3BToyzFB19StX?blocks=bipS1civhoKx9cNVB\">https://airtable.com/app5K5kOhjKyHufeW/tblny8xk6qhZ0ODmp/viwm3BToyzFB19StX?blocks=bipS1civhoKx9cNVB</a></em></strong></p>\n</blockquote>\n<iframe class=\"airtable-embed\" src=\"https://airtable.com/embed/shrkaYQUeFrOYwlrU?backgroundColor=blue&viewControls=on\" frameborder=\"0\" onmousewheel=\"\" width=\"100%\" height=\"533\" style=\"background: transparent; border: 1px solid #ccc;\"></iframe>\n<iframe class=\"airtable-embed\" src=\"https://airtable.com/embed/shrBvax906SQL0tRa?backgroundColor=blue&layout=card&viewControls=on\" frameborder=\"0\" onmousewheel=\"\" width=\"100%\" height=\"533\" style=\"background: transparent; border: 1px solid #ccc;\"></iframe>\n <iframe src=\"https://app.box.com/embed/s/gjls3z2e6lqx595tadegrhhvnaxv5fgp?sortColumn=name&view=icon\" width=\"100%\" height=\"650\" frameborder=\"0\" allowfullscreen webkitallowfullscreen msallowfullscreen></iframe> \n<iframe src=\"https://codesandbox.io/embed/github/bgoonz/gatsby-libris/tree/master/?fontsize=14&hidenavigation=1&theme=dark\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"stackbit-libris-theme\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   ></iframe>"},{"url":"/docs/tutorials/bash-cheat-sheet/","relativePath":"docs/tutorials/bash-cheat-sheet.md","relativeDir":"docs/tutorials","base":"bash-cheat-sheet.md","name":"bash-cheat-sheet","frontmatter":{"title":"Bash Cheat Sheet","template":"docs","excerpt":"A cheat sheet for bash commands."},"html":"<h2>Bash Cheat Sheet</h2>\n<p> A cheat sheet for bash commands.</p>\n<h2>Command History</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token operator\">!</span><span class=\"token operator\">!</span>            <span class=\"token comment\"># Run the last command</span>\n\n<span class=\"token function\">touch</span> foo.sh\n<span class=\"token function\">chmod</span> +x <span class=\"token operator\">!</span>$   <span class=\"token comment\"># !$ is the last argument of the last command i.e. foo.sh</span></code></pre></div>\n<h2>Navigating Directories</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">pwd</span>                       <span class=\"token comment\"># Print current directory path</span>\n<span class=\"token function\">ls</span>                        <span class=\"token comment\"># List directories</span>\n<span class=\"token function\">ls</span> -a<span class=\"token operator\">|</span>--all               <span class=\"token comment\"># List directories including hidden</span>\n<span class=\"token function\">ls</span> <span class=\"token parameter variable\">-l</span>                     <span class=\"token comment\"># List directories in long form</span>\n<span class=\"token function\">ls</span> <span class=\"token parameter variable\">-l</span> -h<span class=\"token operator\">|</span>--human-readable <span class=\"token comment\"># List directories in long form with human readable sizes</span>\n<span class=\"token function\">ls</span> <span class=\"token parameter variable\">-t</span>                     <span class=\"token comment\"># List directories by modification time, newest first</span>\n<span class=\"token function\">stat</span> foo.txt              <span class=\"token comment\"># List size, created and modified timestamps for a file</span>\n<span class=\"token function\">stat</span> foo                  <span class=\"token comment\"># List size, created and modified timestamps for a directory</span>\ntree                      <span class=\"token comment\"># List directory and file tree</span>\ntree <span class=\"token parameter variable\">-a</span>                   <span class=\"token comment\"># List directory and file tree including hidden</span>\ntree <span class=\"token parameter variable\">-d</span>                   <span class=\"token comment\"># List directory tree</span>\n<span class=\"token builtin class-name\">cd</span> foo                    <span class=\"token comment\"># Go to foo sub-directory</span>\n<span class=\"token builtin class-name\">cd</span>                        <span class=\"token comment\"># Go to home directory</span>\n<span class=\"token builtin class-name\">cd</span> ~                      <span class=\"token comment\"># Go to home directory</span>\n<span class=\"token builtin class-name\">cd</span> -                      <span class=\"token comment\"># Go to last directory</span>\n<span class=\"token function\">pushd</span> foo                 <span class=\"token comment\"># Go to foo sub-directory and add previous directory to stack</span>\n<span class=\"token function\">popd</span>                      <span class=\"token comment\"># Go back to directory in stack saved by `pushd`</span></code></pre></div>\n<h2>Creating Directories</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">mkdir</span> foo                        <span class=\"token comment\"># Create a directory</span>\n<span class=\"token function\">mkdir</span> foo bar                    <span class=\"token comment\"># Create multiple directories</span>\n<span class=\"token function\">mkdir</span> -p<span class=\"token operator\">|</span>--parents foo/bar       <span class=\"token comment\"># Create nested directory</span>\n<span class=\"token function\">mkdir</span> -p<span class=\"token operator\">|</span>--parents <span class=\"token punctuation\">{</span>foo,bar<span class=\"token punctuation\">}</span>/baz <span class=\"token comment\"># Create multiple nested directories</span>\n\nmktemp -d<span class=\"token operator\">|</span>--directory            <span class=\"token comment\"># Create a temporary directory</span></code></pre></div>\n<h2>Moving Directories</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">cp</span> -R<span class=\"token operator\">|</span>--recursive foo bar                               <span class=\"token comment\"># Copy directory</span>\n<span class=\"token function\">mv</span> foo bar                                              <span class=\"token comment\"># Move directory</span>\n\n<span class=\"token function\">rsync</span> -z<span class=\"token operator\">|</span>--compress -v<span class=\"token operator\">|</span>--verbose /foo /bar              <span class=\"token comment\"># Copy directory, overwrites destination</span>\n<span class=\"token function\">rsync</span> -a<span class=\"token operator\">|</span>--archive -z<span class=\"token operator\">|</span>--compress -v<span class=\"token operator\">|</span>--verbose /foo /bar <span class=\"token comment\"># Copy directory, without overwriting destination</span>\n<span class=\"token function\">rsync</span> <span class=\"token parameter variable\">-avz</span> /foo username@hostname:/bar                  <span class=\"token comment\"># Copy local directory to remote directory</span>\n<span class=\"token function\">rsync</span> <span class=\"token parameter variable\">-avz</span> username@hostname:/foo /bar                  <span class=\"token comment\"># Copy remote directory to local directory</span></code></pre></div>\n<h2>Deleting Directories</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">rmdir</span> foo                        <span class=\"token comment\"># Delete non-empty directory</span>\n<span class=\"token function\">rm</span> -r<span class=\"token operator\">|</span>--recursive foo            <span class=\"token comment\"># Delete directory including contents</span>\n<span class=\"token function\">rm</span> -r<span class=\"token operator\">|</span>--recursive -f<span class=\"token operator\">|</span>--force foo <span class=\"token comment\"># Delete directory including contents, ignore nonexistent files and never prompt</span></code></pre></div>\n<h2>Creating Files</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">touch</span> foo.txt          <span class=\"token comment\"># Create file or update existing files modified timestamp</span>\n<span class=\"token function\">touch</span> foo.txt bar.txt  <span class=\"token comment\"># Create multiple files</span>\n<span class=\"token function\">touch</span> <span class=\"token punctuation\">{</span>foo,bar<span class=\"token punctuation\">}</span>.txt    <span class=\"token comment\"># Create multiple files</span>\n<span class=\"token function\">touch</span> test<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">..</span><span class=\"token number\">3</span><span class=\"token punctuation\">}</span>       <span class=\"token comment\"># Create test1, test2 and test3 files</span>\n<span class=\"token function\">touch</span> test<span class=\"token punctuation\">{</span>a<span class=\"token punctuation\">..</span>c<span class=\"token punctuation\">}</span>       <span class=\"token comment\"># Create testa, testb and testc files</span>\n\nmktemp                 <span class=\"token comment\"># Create a temporary file</span></code></pre></div>\n<h2>Standard Output, Standard Error and Standard Input</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"foo\"</span> <span class=\"token operator\">></span> bar.txt       <span class=\"token comment\"># Overwrite file with content</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"foo\"</span> <span class=\"token operator\">>></span> bar.txt      <span class=\"token comment\"># Append to file with content</span>\n\n<span class=\"token function\">ls</span> exists <span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> stdout.txt    <span class=\"token comment\"># Redirect the standard output to a file</span>\n<span class=\"token function\">ls</span> noexist <span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span> stderror.txt <span class=\"token comment\"># Redirect the standard error output to a file</span>\n<span class=\"token function\">ls</span> <span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span><span class=\"token file-descriptor important\">&amp;1</span> out.txt            <span class=\"token comment\"># Redirect standard output and error to a file</span>\n<span class=\"token function\">ls</span> <span class=\"token operator\">></span> /dev/null             <span class=\"token comment\"># Discard standard output and error</span>\n\n<span class=\"token builtin class-name\">read</span> foo                   <span class=\"token comment\"># Read from standard input and write to the variable foo</span></code></pre></div>\n<h2>Moving Files</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">cp</span> foo.txt bar.txt                                <span class=\"token comment\"># Copy file</span>\n<span class=\"token function\">mv</span> foo.txt bar.txt                                <span class=\"token comment\"># Move file</span>\n\n<span class=\"token function\">rsync</span> -z<span class=\"token operator\">|</span>--compress -v<span class=\"token operator\">|</span>--verbose /foo.txt /bar    <span class=\"token comment\"># Copy file quickly if not changed</span>\n<span class=\"token function\">rsync</span> z<span class=\"token operator\">|</span>--compress -v<span class=\"token operator\">|</span>--verbose /foo.txt /bar.txt <span class=\"token comment\"># Copy and rename file quickly if not changed</span></code></pre></div>\n<h2>Deleting Files</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">rm</span> foo.txt            <span class=\"token comment\"># Delete file</span>\n<span class=\"token function\">rm</span> -f<span class=\"token operator\">|</span>--force foo.txt <span class=\"token comment\"># Delete file, ignore nonexistent files and never prompt</span></code></pre></div>\n<h2>Reading Files</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">cat</span> foo.txt            <span class=\"token comment\"># Print all contents</span>\n<span class=\"token function\">less</span> foo.txt           <span class=\"token comment\"># Print some contents at a time (g - go to top of file, SHIFT+g, go to bottom of file, /foo to search for 'foo')</span>\n<span class=\"token function\">head</span> foo.txt           <span class=\"token comment\"># Print top 10 lines of file</span>\n<span class=\"token function\">tail</span> foo.txt           <span class=\"token comment\"># Print bottom 10 lines of file</span>\n<span class=\"token function\">open</span> foo.txt           <span class=\"token comment\"># Open file in the default editor</span>\n<span class=\"token function\">wc</span> foo.txt             <span class=\"token comment\"># List number of lines words and characters in the file</span></code></pre></div>\n<h2>File Permissions</h2>\n<table>\n<thead>\n<tr>\n<th>#</th>\n<th>Permission</th>\n<th>rwx</th>\n<th>Binary</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>7</td>\n<td>read, write and execute</td>\n<td>rwx</td>\n<td>111</td>\n</tr>\n<tr>\n<td>6</td>\n<td>read and write</td>\n<td>rw-</td>\n<td>110</td>\n</tr>\n<tr>\n<td>5</td>\n<td>read and execute</td>\n<td>r-x</td>\n<td>101</td>\n</tr>\n<tr>\n<td>4</td>\n<td>read only</td>\n<td>r--</td>\n<td>100</td>\n</tr>\n<tr>\n<td>3</td>\n<td>write and execute</td>\n<td>-wx</td>\n<td>011</td>\n</tr>\n<tr>\n<td>2</td>\n<td>write only</td>\n<td>-w-</td>\n<td>010</td>\n</tr>\n<tr>\n<td>1</td>\n<td>execute only</td>\n<td>--x</td>\n<td>001</td>\n</tr>\n<tr>\n<td>0</td>\n<td>none</td>\n<td>---</td>\n<td>000</td>\n</tr>\n</tbody>\n</table>\n<p>For a directory, execute means you can enter a directory.</p>\n<table>\n<thead>\n<tr>\n<th>User</th>\n<th>Group</th>\n<th>Others</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>6</td>\n<td>4</td>\n<td>4</td>\n<td>User can read and write, everyone else can read (Default file permissions)</td>\n</tr>\n<tr>\n<td>7</td>\n<td>5</td>\n<td>5</td>\n<td>User can read, write and execute, everyone else can read and execute (Default directory permissions)</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>u - User</li>\n<li>g - Group</li>\n<li>o - Others</li>\n<li>a - All of the above</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">ls</span> <span class=\"token parameter variable\">-l</span> /foo.sh            <span class=\"token comment\"># List file permissions</span>\n<span class=\"token function\">chmod</span> +100 foo.sh        <span class=\"token comment\"># Add 1 to the user permission</span>\n<span class=\"token function\">chmod</span> <span class=\"token parameter variable\">-100</span> foo.sh        <span class=\"token comment\"># Subtract 1 from the user permission</span>\n<span class=\"token function\">chmod</span> u+x foo.sh         <span class=\"token comment\"># Give the user execute permission</span>\n<span class=\"token function\">chmod</span> g+x foo.sh         <span class=\"token comment\"># Give the group execute permission</span>\n<span class=\"token function\">chmod</span> u-x,g-x foo.sh     <span class=\"token comment\"># Take away the user and group execute permission</span>\n<span class=\"token function\">chmod</span> u+x,g+x,o+x foo.sh <span class=\"token comment\"># Give everybody execute permission</span>\n<span class=\"token function\">chmod</span> a+x foo.sh         <span class=\"token comment\"># Give everybody execute permission</span>\n<span class=\"token function\">chmod</span> +x foo.sh          <span class=\"token comment\"># Give everybody execute permission</span></code></pre></div>\n<h2>Finding Files</h2>\n<p>Find binary files for a command.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">type</span> <span class=\"token function\">wget</span>                                  <span class=\"token comment\"># Find the binary</span>\n<span class=\"token function\">which</span> <span class=\"token function\">wget</span>                                 <span class=\"token comment\"># Find the binary</span>\n<span class=\"token function\">whereis</span> <span class=\"token function\">wget</span>                               <span class=\"token comment\"># Find the binary, source, and manual page files</span></code></pre></div>\n<p><code class=\"language-text\">locate</code> uses an index and is fast.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">updatedb                                   <span class=\"token comment\"># Update the index</span>\n\n<span class=\"token function\">locate</span> foo.txt                             <span class=\"token comment\"># Find a file</span>\n<span class=\"token function\">locate</span> --ignore-case                       <span class=\"token comment\"># Find a file and ignore case</span>\n<span class=\"token function\">locate</span> f*.txt                              <span class=\"token comment\"># Find a text file starting with 'f'</span></code></pre></div>\n<p><code class=\"language-text\">find</code> doesn't use an index and is slow.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-name</span> foo.txt                   <span class=\"token comment\"># Find a file</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-iname</span> foo.txt                  <span class=\"token comment\"># Find a file with case insensitive search</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*.txt\"</span>                   <span class=\"token comment\"># Find all text files</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-name</span> foo.txt <span class=\"token parameter variable\">-delete</span>           <span class=\"token comment\"># Find a file and delete it</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*.png\"</span> <span class=\"token parameter variable\">-exec</span> pngquant <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token comment\"># Find all .png files and execute pngquant on it</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-name</span> foo.txt           <span class=\"token comment\"># Find a file</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-name</span> foo               <span class=\"token comment\"># Find a directory</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-type</span> l <span class=\"token parameter variable\">-name</span> foo.txt           <span class=\"token comment\"># Find a symbolic link</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-mtime</span> +30              <span class=\"token comment\"># Find files that haven't been modified in 30 days</span>\n<span class=\"token function\">find</span> /path <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-mtime</span> +30 <span class=\"token parameter variable\">-delete</span>      <span class=\"token comment\"># Delete files that haven't been modified in 30 days</span></code></pre></div>\n<h2>Find in Files</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar.txt                         <span class=\"token comment\"># Search for 'foo' in file 'bar.txt'</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -r<span class=\"token operator\">|</span>--recursive              <span class=\"token comment\"># Search for 'foo' in directory 'bar'</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -R<span class=\"token operator\">|</span>--dereference-recursive  <span class=\"token comment\"># Search for 'foo' in directory 'bar' and follow symbolic links</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -l<span class=\"token operator\">|</span>--files-with-matches     <span class=\"token comment\"># Show only files that match</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -L<span class=\"token operator\">|</span>--files-without-match    <span class=\"token comment\"># Show only files that don't match</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'Foo'</span> /bar -i<span class=\"token operator\">|</span>--ignore-case            <span class=\"token comment\"># Case insensitive search</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -x<span class=\"token operator\">|</span>--line-regexp            <span class=\"token comment\"># Match the entire line</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -C<span class=\"token operator\">|</span>--context <span class=\"token number\">1</span>              <span class=\"token comment\"># Add N line of context above and below each search result</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -v<span class=\"token operator\">|</span>--invert-match           <span class=\"token comment\"># Show only lines that don't match</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -c<span class=\"token operator\">|</span>--count                  <span class=\"token comment\"># Count the number lines that match</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar -n<span class=\"token operator\">|</span>--line-number            <span class=\"token comment\"># Add line numbers</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo'</span> /bar <span class=\"token parameter variable\">--colour</span>                    <span class=\"token comment\"># Add colour to output</span>\n<span class=\"token function\">grep</span> <span class=\"token string\">'foo\\|bar'</span> /baz <span class=\"token parameter variable\">-R</span>                     <span class=\"token comment\"># Search for 'foo' or 'bar' in directory 'baz'</span>\n<span class=\"token function\">grep</span> --extended-regexp<span class=\"token operator\">|</span>-E <span class=\"token string\">'foo|bar'</span> /baz <span class=\"token parameter variable\">-R</span> <span class=\"token comment\"># Use regular expressions</span>\n<span class=\"token function\">egrep</span> <span class=\"token string\">'foo|bar'</span> /baz <span class=\"token parameter variable\">-R</span>                     <span class=\"token comment\"># Use regular expressions</span></code></pre></div>\n<h3>Replace in Files</h3>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">sed</span> <span class=\"token string\">'s/fox/bear/g'</span> foo.txt               <span class=\"token comment\"># Replace fox with bear in foo.txt and output to console</span>\n<span class=\"token function\">sed</span> <span class=\"token string\">'s/fox/bear/gi'</span> foo.txt              <span class=\"token comment\"># Replace fox (case insensitive) with bear in foo.txt and output to console</span>\n<span class=\"token function\">sed</span> <span class=\"token string\">'s/red fox/blue bear/g'</span> foo.txt      <span class=\"token comment\"># Replace red with blue and fox with bear in foo.txt and output to console</span>\n<span class=\"token function\">sed</span> <span class=\"token string\">'s/fox/bear/g'</span> foo.txt <span class=\"token operator\">></span> bar.txt     <span class=\"token comment\"># Replace fox with bear in foo.txt and save in bar.txt</span>\n<span class=\"token function\">sed</span> <span class=\"token string\">'s/fox/bear/g'</span> foo.txt -i<span class=\"token operator\">|</span>--in-place <span class=\"token comment\"># Replace fox with bear and overwrite foo.txt</span></code></pre></div>\n<h2>Symbolic Links</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">ln</span> -s<span class=\"token operator\">|</span>--symbolic foo bar            <span class=\"token comment\"># Create a link 'bar' to the 'foo' folder</span>\n<span class=\"token function\">ln</span> -s<span class=\"token operator\">|</span>--symbolic -f<span class=\"token operator\">|</span>--force foo bar <span class=\"token comment\"># Overwrite an existing symbolic link 'bar'</span>\n<span class=\"token function\">ls</span> <span class=\"token parameter variable\">-l</span>                               <span class=\"token comment\"># Show where symbolic links are pointing</span></code></pre></div>\n<h2>Compressing Files</h2>\n<h3>zip</h3>\n<p>Compresses one or more files into *.zip files.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">zip</span> foo.zip /bar.txt                <span class=\"token comment\"># Compress bar.txt into foo.zip</span>\n<span class=\"token function\">zip</span> foo.zip /bar.txt /baz.txt       <span class=\"token comment\"># Compress bar.txt and baz.txt into foo.zip</span>\n<span class=\"token function\">zip</span> foo.zip /<span class=\"token punctuation\">{</span>bar,baz<span class=\"token punctuation\">}</span>.txt          <span class=\"token comment\"># Compress bar.txt and baz.txt into foo.zip</span>\n<span class=\"token function\">zip</span> -r<span class=\"token operator\">|</span>--recurse-paths foo.zip /bar <span class=\"token comment\"># Compress directory bar into foo.zip</span></code></pre></div>\n<h3>gzip</h3>\n<p>Compresses a single file into *.gz files.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">gzip</span> /bar.txt foo.gz           <span class=\"token comment\"># Compress bar.txt into foo.gz and then delete bar.txt</span>\n<span class=\"token function\">gzip</span> -k<span class=\"token operator\">|</span>--keep /bar.txt foo.gz <span class=\"token comment\"># Compress bar.txt into foo.gz</span></code></pre></div>\n<h3>tar -c</h3>\n<p>Compresses (optionally) and combines one or more files into a single *.tar, *.tar.gz, *.tpz or *.tgz file.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">tar</span> -c<span class=\"token operator\">|</span>--create -z<span class=\"token operator\">|</span>--gzip -f<span class=\"token operator\">|</span>--file<span class=\"token operator\">=</span>foo.tgz /bar.txt /baz.txt <span class=\"token comment\"># Compress bar.txt and baz.txt into foo.tgz</span>\n<span class=\"token function\">tar</span> -c<span class=\"token operator\">|</span>--create -z<span class=\"token operator\">|</span>--gzip -f<span class=\"token operator\">|</span>--file<span class=\"token operator\">=</span>foo.tgz /<span class=\"token punctuation\">{</span>bar,baz<span class=\"token punctuation\">}</span>.txt    <span class=\"token comment\"># Compress bar.txt and baz.txt into foo.tgz</span>\n<span class=\"token function\">tar</span> -c<span class=\"token operator\">|</span>--create -z<span class=\"token operator\">|</span>--gzip -f<span class=\"token operator\">|</span>--file<span class=\"token operator\">=</span>foo.tgz /bar              <span class=\"token comment\"># Compress directory bar into foo.tgz</span></code></pre></div>\n<h2>Decompressing Files</h2>\n<h3>unzip</h3>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">unzip</span> foo.zip          <span class=\"token comment\"># Unzip foo.zip into current directory</span></code></pre></div>\n<h3>gunzip</h3>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">gunzip foo.gz           <span class=\"token comment\"># Unzip foo.gz into current directory and delete foo.gz</span>\ngunzip -k<span class=\"token operator\">|</span>--keep foo.gz <span class=\"token comment\"># Unzip foo.gz into current directory</span></code></pre></div>\n<h3>tar -x</h3>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">tar</span> -x<span class=\"token operator\">|</span>--extract -z<span class=\"token operator\">|</span>--gzip -f<span class=\"token operator\">|</span>--file<span class=\"token operator\">=</span>foo.tar.gz <span class=\"token comment\"># Un-compress foo.tar.gz into current directory</span>\n<span class=\"token function\">tar</span> -x<span class=\"token operator\">|</span>--extract -f<span class=\"token operator\">|</span>--file<span class=\"token operator\">=</span>foo.tar              <span class=\"token comment\"># Un-combine foo.tar into current directory</span></code></pre></div>\n<h2>Disk Usage</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">df</span>                     <span class=\"token comment\"># List disks, size, used and available space</span>\n<span class=\"token function\">df</span> -h<span class=\"token operator\">|</span>--human-readable <span class=\"token comment\"># List disks, size, used and available space in a human readable format</span>\n\n<span class=\"token function\">du</span>                     <span class=\"token comment\"># List current directory, subdirectories and file sizes</span>\n<span class=\"token function\">du</span> /foo/bar            <span class=\"token comment\"># List specified directory, subdirectories and file sizes</span>\n<span class=\"token function\">du</span> -h<span class=\"token operator\">|</span>--human-readable <span class=\"token comment\"># List current directory, subdirectories and file sizes in a human readable format</span>\n<span class=\"token function\">du</span> -d<span class=\"token operator\">|</span>--max-depth      <span class=\"token comment\"># List current directory, subdirectories and file sizes within the max depth</span>\n<span class=\"token function\">du</span> <span class=\"token parameter variable\">-d</span> <span class=\"token number\">0</span>                <span class=\"token comment\"># List current directory size</span></code></pre></div>\n<h2>Memory Usage</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">free</span>                   <span class=\"token comment\"># Show memory usage</span>\n<span class=\"token function\">free</span> -h<span class=\"token operator\">|</span>--human        <span class=\"token comment\"># Show human readable memory usage</span>\n<span class=\"token function\">free</span> -h<span class=\"token operator\">|</span>--human <span class=\"token parameter variable\">--si</span>   <span class=\"token comment\"># Show human readable memory usage in power of 1000 instead of 1024</span>\n<span class=\"token function\">free</span> -s<span class=\"token operator\">|</span>--seconds <span class=\"token number\">5</span>    <span class=\"token comment\"># Show memory usage and update continuously every five seconds</span></code></pre></div>\n<h2>Packages</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">apt</span> update             <span class=\"token comment\"># Refreshes repository index</span>\n<span class=\"token function\">apt</span> search <span class=\"token function\">wget</span>        <span class=\"token comment\"># Search for a package</span>\n<span class=\"token function\">apt</span> show <span class=\"token function\">wget</span>          <span class=\"token comment\"># List information about the wget package</span>\n<span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">wget</span>       <span class=\"token comment\"># Install the wget package</span>\n<span class=\"token function\">apt</span> remove <span class=\"token function\">wget</span>        <span class=\"token comment\"># Removes the wget package</span>\n<span class=\"token function\">apt</span> upgrade            <span class=\"token comment\"># Upgrades all upgradable packages</span></code></pre></div>\n<h2>Shutdown and Reboot</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">shutdown</span>                     <span class=\"token comment\"># Shutdown in 1 minute</span>\n<span class=\"token function\">shutdown</span> now <span class=\"token string\">\"Cya later\"</span>     <span class=\"token comment\"># Immediately shut down</span>\n<span class=\"token function\">shutdown</span> +5 <span class=\"token string\">\"Cya later\"</span>      <span class=\"token comment\"># Shutdown in 5 minutes</span>\n\n<span class=\"token function\">shutdown</span> <span class=\"token parameter variable\">--reboot</span>            <span class=\"token comment\"># Reboot in 1 minute</span>\n<span class=\"token function\">shutdown</span> <span class=\"token parameter variable\">-r</span> now <span class=\"token string\">\"Cya later\"</span>  <span class=\"token comment\"># Immediately reboot</span>\n<span class=\"token function\">shutdown</span> <span class=\"token parameter variable\">-r</span> +5 <span class=\"token string\">\"Cya later\"</span>   <span class=\"token comment\"># Reboot in 5 minutes</span>\n\n<span class=\"token function\">shutdown</span> <span class=\"token parameter variable\">-c</span>                  <span class=\"token comment\"># Cancel a shutdown or reboot</span>\n\n<span class=\"token function\">reboot</span>                       <span class=\"token comment\"># Reboot now</span>\n<span class=\"token function\">reboot</span> <span class=\"token parameter variable\">-f</span>                    <span class=\"token comment\"># Force a reboot</span></code></pre></div>\n<h2>Identifying Processes</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">top</span>                    <span class=\"token comment\"># List all processes interactively</span>\n<span class=\"token function\">htop</span>                   <span class=\"token comment\"># List all processes interactively</span>\n<span class=\"token function\">ps</span> all                 <span class=\"token comment\"># List all processes</span>\npidof foo              <span class=\"token comment\"># Return the PID of all foo processes</span>\n\nCTRL+Z                 <span class=\"token comment\"># Suspend a process running in the foreground</span>\n<span class=\"token function\">bg</span>                     <span class=\"token comment\"># Resume a suspended process and run in the background</span>\n<span class=\"token function\">fg</span>                     <span class=\"token comment\"># Bring the last background process to the foreground</span>\n<span class=\"token function\">fg</span> <span class=\"token number\">1</span>                   <span class=\"token comment\"># Bring the background process with the PID to the foreground</span>\n\n<span class=\"token function\">sleep</span> <span class=\"token number\">30</span> <span class=\"token operator\">&amp;</span>             <span class=\"token comment\"># Sleep for 30 seconds and move the process into the background</span>\n<span class=\"token function\">jobs</span>                   <span class=\"token comment\"># List all background jobs</span>\n<span class=\"token function\">jobs</span> <span class=\"token parameter variable\">-p</span>                <span class=\"token comment\"># List all background jobs with their PID</span>\n\n<span class=\"token function\">lsof</span>                   <span class=\"token comment\"># List all open files and the process using them</span>\n<span class=\"token function\">lsof</span> <span class=\"token parameter variable\">-itcp:4000</span>        <span class=\"token comment\"># Return the process listening on port 4000</span></code></pre></div>\n<h2>Process Priority</h2>\n<p>Process priorities go from -20 (highest) to 19 (lowest).</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">nice</span> <span class=\"token parameter variable\">-n</span> <span class=\"token parameter variable\">-20</span> foo        <span class=\"token comment\"># Change process priority by name</span>\n<span class=\"token function\">renice</span> <span class=\"token number\">20</span> PID          <span class=\"token comment\"># Change process priority by PID</span>\n<span class=\"token function\">ps</span> <span class=\"token parameter variable\">-o</span> ni PID           <span class=\"token comment\"># Return the process priority of PID</span></code></pre></div>\n<h2>Killing Processes</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">CTRL+C                 <span class=\"token comment\"># Kill a process running in the foreground</span>\n<span class=\"token function\">kill</span> PID               <span class=\"token comment\"># Shut down process by PID gracefully. Sends TERM signal.</span>\n<span class=\"token function\">kill</span> <span class=\"token parameter variable\">-9</span> PID            <span class=\"token comment\"># Force shut down of process by PID. Sends SIGKILL signal.</span>\n<span class=\"token function\">pkill</span> foo              <span class=\"token comment\"># Shut down process by name gracefully. Sends TERM signal.</span>\n<span class=\"token function\">pkill</span> <span class=\"token parameter variable\">-9</span> foo           <span class=\"token comment\"># force shut down process by name. Sends SIGKILL signal.</span>\n<span class=\"token function\">killall</span> foo            <span class=\"token comment\"># Kill all process with the specified name gracefully.</span></code></pre></div>\n<h2>Date &#x26; Time</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">date</span>                   <span class=\"token comment\"># Print the date and time</span>\n<span class=\"token function\">date</span> --iso-8601        <span class=\"token comment\"># Print the ISO8601 date</span>\n<span class=\"token function\">date</span> --iso-8601<span class=\"token operator\">=</span>ns     <span class=\"token comment\"># Print the ISO8601 date and time</span>\n\n<span class=\"token function\">time</span> tree              <span class=\"token comment\"># Time how long the tree command takes to execute</span></code></pre></div>\n<h2>Scheduled Tasks</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">   *      *         *         *           *\nMinute, Hour, Day of month, Month, Day of the week</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">crontab</span> <span class=\"token parameter variable\">-l</span>                 <span class=\"token comment\"># List cron tab</span>\n<span class=\"token function\">crontab</span> <span class=\"token parameter variable\">-e</span>                 <span class=\"token comment\"># Edit cron tab in Vim</span>\n<span class=\"token function\">crontab</span> /path/crontab      <span class=\"token comment\"># Load cron tab from a file</span>\n<span class=\"token function\">crontab</span> <span class=\"token parameter variable\">-l</span> <span class=\"token operator\">></span> /path/crontab <span class=\"token comment\"># Save cron tab to a file</span>\n\n* * * * * foo              <span class=\"token comment\"># Run foo every minute</span>\n*/15 * * * * foo           <span class=\"token comment\"># Run foo every 15 minutes</span>\n<span class=\"token number\">0</span> * * * * foo              <span class=\"token comment\"># Run foo every hour</span>\n<span class=\"token number\">15</span> <span class=\"token number\">6</span> * * * foo             <span class=\"token comment\"># Run foo daily at 6:15 AM</span>\n<span class=\"token number\">44</span> <span class=\"token number\">4</span> * * <span class=\"token number\">5</span> foo             <span class=\"token comment\"># Run foo every Friday at 4:44 AM</span>\n<span class=\"token number\">0</span> <span class=\"token number\">0</span> <span class=\"token number\">1</span> * * foo              <span class=\"token comment\"># Run foo at midnight on the first of the month</span>\n<span class=\"token number\">0</span> <span class=\"token number\">0</span> <span class=\"token number\">1</span> <span class=\"token number\">1</span> * foo              <span class=\"token comment\"># Run foo at midnight on the first of the year</span>\n\nat <span class=\"token parameter variable\">-l</span>                      <span class=\"token comment\"># List scheduled tasks</span>\nat <span class=\"token parameter variable\">-c</span> <span class=\"token number\">1</span>                    <span class=\"token comment\"># Show task with ID 1</span>\nat <span class=\"token parameter variable\">-r</span> <span class=\"token number\">1</span>                    <span class=\"token comment\"># Remove task with ID 1</span>\nat now + <span class=\"token number\">2</span> minutes         <span class=\"token comment\"># Create a task in Vim to execute in 2 minutes</span>\nat <span class=\"token number\">12</span>:34 PM next month     <span class=\"token comment\"># Create a task in Vim to execute at 12:34 PM next month</span>\nat tomorrow                <span class=\"token comment\"># Create a task in Vim to execute tomorrow</span></code></pre></div>\n<h2>HTTP Requests</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">curl</span> https://example.com                               <span class=\"token comment\"># Return response body</span>\n<span class=\"token function\">curl</span> -i<span class=\"token operator\">|</span>--include https://example.com                  <span class=\"token comment\"># Include status code and HTTP headers</span>\n<span class=\"token function\">curl</span> -L<span class=\"token operator\">|</span>--location https://example.com                 <span class=\"token comment\"># Follow redirects</span>\n<span class=\"token function\">curl</span> -o<span class=\"token operator\">|</span>--remote-name foo.txt https://example.com      <span class=\"token comment\"># Output to a text file</span>\n<span class=\"token function\">curl</span> -H<span class=\"token operator\">|</span>--header <span class=\"token string\">\"User-Agent: Foo\"</span> https://example.com <span class=\"token comment\"># Add a HTTP header</span>\n<span class=\"token function\">curl</span> -X<span class=\"token operator\">|</span>--request POST <span class=\"token parameter variable\">-H</span> <span class=\"token string\">\"Content-Type: application/json\"</span> -d<span class=\"token operator\">|</span>--data <span class=\"token string\">'{\"foo\":\"bar\"}'</span> https://example.com <span class=\"token comment\"># POST JSON</span>\n<span class=\"token function\">curl</span> <span class=\"token parameter variable\">-X</span> POST <span class=\"token parameter variable\">-H</span> --data-urlencode <span class=\"token assign-left variable\">foo</span><span class=\"token operator\">=</span><span class=\"token string\">\"bar\"</span> http://example.com                           <span class=\"token comment\"># POST URL Form Encoded</span>\n\n<span class=\"token function\">wget</span> https://example.com/file.txt <span class=\"token builtin class-name\">.</span>                            <span class=\"token comment\"># Download a file to the current directory</span>\n<span class=\"token function\">wget</span> -O<span class=\"token operator\">|</span>--output-document foo.txt https://example.com/file.txt <span class=\"token comment\"># Output to a file with the specified name</span></code></pre></div>\n<h2>Network Troubleshooting</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">ping</span> example.com            <span class=\"token comment\"># Send multiple ping requests using the ICMP protocol</span>\n<span class=\"token function\">ping</span> <span class=\"token parameter variable\">-c</span> <span class=\"token number\">10</span> <span class=\"token parameter variable\">-i</span> <span class=\"token number\">5</span> example.com <span class=\"token comment\"># Make 10 attempts, 5 seconds apart</span>\n\n<span class=\"token function\">ip</span> addr                     <span class=\"token comment\"># List IP addresses on the system</span>\n<span class=\"token function\">ip</span> route show               <span class=\"token comment\"># Show IP addresses to router</span>\n\n<span class=\"token function\">netstat</span> -i<span class=\"token operator\">|</span>--interfaces     <span class=\"token comment\"># List all network interfaces and in/out usage</span>\n<span class=\"token function\">netstat</span> -l<span class=\"token operator\">|</span>--listening      <span class=\"token comment\"># List all open ports</span>\n\n<span class=\"token function\">traceroute</span> example.com      <span class=\"token comment\"># List all servers the network traffic goes through</span>\n\n<span class=\"token function\">mtr</span> -w<span class=\"token operator\">|</span>--report-wide example.com                                    <span class=\"token comment\"># Continually list all servers the network traffic goes through</span>\n<span class=\"token function\">mtr</span> -r<span class=\"token operator\">|</span>--report -w<span class=\"token operator\">|</span>--report-wide -c<span class=\"token operator\">|</span>--report-cycles <span class=\"token number\">100</span> example.com <span class=\"token comment\"># Output a report that lists network traffic 100 times</span>\n\nnmap <span class=\"token number\">0.0</span>.0.0                <span class=\"token comment\"># Scan for the 1000 most common open ports on localhost</span>\nnmap <span class=\"token number\">0.0</span>.0.0 -p1-65535      <span class=\"token comment\"># Scan for open ports on localhost between 1 and 65535</span>\nnmap <span class=\"token number\">192.168</span>.4.3            <span class=\"token comment\"># Scan for the 1000 most common open ports on a remote IP address</span>\nnmap <span class=\"token parameter variable\">-sP</span> <span class=\"token number\">192.168</span>.1.1/24     <span class=\"token comment\"># Discover all machines on the network by ping'ing them</span></code></pre></div>\n<h2>DNS</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">host</span> example.com            <span class=\"token comment\"># Show the IPv4 and IPv6 addresses</span>\n\n<span class=\"token function\">dig</span> example.com             <span class=\"token comment\"># Show complete DNS information</span>\n\n<span class=\"token function\">cat</span> /etc/resolv.conf        <span class=\"token comment\"># resolv.conf lists nameservers</span></code></pre></div>\n<h2>Hardware</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">lsusb                  <span class=\"token comment\"># List USB devices</span>\nlspci                  <span class=\"token comment\"># List PCI hardware</span>\nlshw                   <span class=\"token comment\"># List all hardware</span></code></pre></div>\n<h2>Terminal Multiplexers</h2>\n<p>Start multiple terminal sessions. Active sessions persist reboots. <code class=\"language-text\">tmux</code> is more modern than <code class=\"language-text\">screen</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">tmux             <span class=\"token comment\"># Start a new session (CTRL-b + d to detach)</span>\ntmux <span class=\"token function\">ls</span>          <span class=\"token comment\"># List all sessions</span>\ntmux attach <span class=\"token parameter variable\">-t</span> <span class=\"token number\">0</span> <span class=\"token comment\"># Reattach to a session</span>\n\n<span class=\"token function\">screen</span>           <span class=\"token comment\"># Start a new session (CTRL-a + d to detach)</span>\n<span class=\"token function\">screen</span> <span class=\"token parameter variable\">-ls</span>       <span class=\"token comment\"># List all sessions</span>\n<span class=\"token function\">screen</span> <span class=\"token parameter variable\">-R</span> <span class=\"token number\">31166</span>  <span class=\"token comment\"># Reattach to a session</span>\n\n<span class=\"token builtin class-name\">exit</span>             <span class=\"token comment\"># Exit a session</span></code></pre></div>\n<h2>Secure Shell Protocol (SSH)</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">ssh</span> <span class=\"token function\">hostname</span>                 <span class=\"token comment\"># Connect to hostname using your current user name over the default SSH port 22</span>\n<span class=\"token function\">ssh</span> <span class=\"token parameter variable\">-i</span> foo.pem <span class=\"token function\">hostname</span>      <span class=\"token comment\"># Connect to hostname using the identity file</span>\n<span class=\"token function\">ssh</span> user@hostname            <span class=\"token comment\"># Connect to hostname using the user over the default SSH port 22</span>\n<span class=\"token function\">ssh</span> user@hostname <span class=\"token parameter variable\">-p</span> <span class=\"token number\">8765</span>    <span class=\"token comment\"># Connect to hostname using the user over a custom port</span>\n<span class=\"token function\">ssh</span> ssh://user@hostname:8765 <span class=\"token comment\"># Connect to hostname using the user over a custom port</span></code></pre></div>\n<p>Set default user and port in <code class=\"language-text\">~/.ssh/config</code>, so you can just enter the name next time:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">cat</span> ~/.ssh/config\nHost name\n  User foo\n  Hostname <span class=\"token number\">127.0</span>.0.1\n  Port <span class=\"token number\">8765</span>\n$ <span class=\"token function\">ssh</span> name</code></pre></div>\n<h2>Secure Copy</h2>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">scp</span> foo.txt ubuntu@hostname:/home/ubuntu <span class=\"token comment\"># Copy foo.txt into the specified remote directory</span></code></pre></div>\n<h2>Bash Profile</h2>\n<ul>\n<li>bash - <code class=\"language-text\">.bashrc</code></li>\n<li>zsh - <code class=\"language-text\">.zshrc</code></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token comment\"># Always run ls after cd</span>\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">cd</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token builtin class-name\">builtin</span> <span class=\"token builtin class-name\">cd</span> <span class=\"token string\">\"<span class=\"token variable\">$@</span>\"</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">ls</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\"># Prompt user before overwriting any files</span>\n<span class=\"token builtin class-name\">alias</span> <span class=\"token assign-left variable\">cp</span><span class=\"token operator\">=</span><span class=\"token string\">'cp --interactive'</span>\n<span class=\"token builtin class-name\">alias</span> <span class=\"token assign-left variable\">mv</span><span class=\"token operator\">=</span><span class=\"token string\">'mv --interactive'</span>\n<span class=\"token builtin class-name\">alias</span> <span class=\"token assign-left variable\">rm</span><span class=\"token operator\">=</span><span class=\"token string\">'rm --interactive'</span>\n\n<span class=\"token comment\"># Always show disk usage in a human readable format</span>\n<span class=\"token builtin class-name\">alias</span> <span class=\"token assign-left variable\">df</span><span class=\"token operator\">=</span><span class=\"token string\">'df -h'</span>\n<span class=\"token builtin class-name\">alias</span> <span class=\"token assign-left variable\">du</span><span class=\"token operator\">=</span><span class=\"token string\">'du -h'</span></code></pre></div>\n<h2>Bash Script</h2>\n<h3>Variables</h3>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token assign-left variable\">foo</span><span class=\"token operator\">=</span><span class=\"token number\">123</span>                <span class=\"token comment\"># Initialize variable foo with 123</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-i</span> <span class=\"token assign-left variable\">foo</span><span class=\"token operator\">=</span><span class=\"token number\">123</span>     <span class=\"token comment\"># Initialize an integer foo with 123</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-r</span> <span class=\"token assign-left variable\">foo</span><span class=\"token operator\">=</span><span class=\"token number\">123</span>     <span class=\"token comment\"># Initialize readonly variable foo with 123</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$foo</span>              <span class=\"token comment\"># Print variable foo</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">${foo}</span>_<span class=\"token string\">'bar'</span>      <span class=\"token comment\"># Print variable foo followed by _bar</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">${foo<span class=\"token operator\">:-</span>'default'}</span> <span class=\"token comment\"># Print variable foo if it exists otherwise print default</span>\n\n<span class=\"token builtin class-name\">export</span> foo             <span class=\"token comment\"># Make foo available to child processes</span>\n<span class=\"token builtin class-name\">unset</span> foo              <span class=\"token comment\"># Make foo unavailable to child processes</span></code></pre></div>\n<h3>Environment Variables</h3>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token function\">env</span>        <span class=\"token comment\"># List all environment variables</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token environment constant\">$PATH</span> <span class=\"token comment\"># Print PATH environment variable</span></code></pre></div>\n<h3>Functions</h3>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token function-name function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token builtin class-name\">local</span> world <span class=\"token operator\">=</span> <span class=\"token string\">\"World\"</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"<span class=\"token variable\">$1</span> <span class=\"token variable\">$world</span>\"</span>\n  <span class=\"token builtin class-name\">return</span> <span class=\"token string\">\"<span class=\"token variable\">$1</span> <span class=\"token variable\">$world</span>\"</span>\n<span class=\"token punctuation\">}</span>\ngreet <span class=\"token string\">\"Hello\"</span>\n<span class=\"token assign-left variable\">greeting</span><span class=\"token operator\">=</span><span class=\"token variable\"><span class=\"token variable\">$(</span>greet <span class=\"token string\">\"Hello\"</span><span class=\"token variable\">)</span></span></code></pre></div>\n<h3>Exit Codes</h3>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token builtin class-name\">exit</span> <span class=\"token number\">0</span>   <span class=\"token comment\"># Exit the script successfully</span>\n<span class=\"token builtin class-name\">exit</span> <span class=\"token number\">1</span>   <span class=\"token comment\"># Exit the script unsuccessfully</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$?</span>  <span class=\"token comment\"># Print the last exit code</span></code></pre></div>\n<h3>Conditional Statements</h3>\n<h4>Boolean Operators</h4>\n<ul>\n<li><code class=\"language-text\">$foo</code> - Is true</li>\n<li><code class=\"language-text\">!$foo</code> - Is false</li>\n</ul>\n<h4>Numeric Operators</h4>\n<ul>\n<li><code class=\"language-text\">-eq</code> - Equals</li>\n<li><code class=\"language-text\">-ne</code> - Not equals</li>\n<li><code class=\"language-text\">-gt</code> - Greater than</li>\n<li><code class=\"language-text\">-ge</code> - Greater than or equal to</li>\n<li><code class=\"language-text\">-lt</code> - Less than</li>\n<li><code class=\"language-text\">-le</code> - Less than or equal to</li>\n<li><code class=\"language-text\">-e</code> foo.txt - Check file exists</li>\n<li><code class=\"language-text\">-z</code> foo - Check if variable exists</li>\n</ul>\n<h4>String Operators</h4>\n<ul>\n<li><code class=\"language-text\">=</code> - Equals</li>\n<li><code class=\"language-text\">==</code> - Equals</li>\n<li><code class=\"language-text\">-z</code> - Is null</li>\n<li><code class=\"language-text\">-n</code> - Is not null</li>\n<li><code class=\"language-text\">&lt;</code> - Is less than in ASCII alphabetical order</li>\n<li><code class=\"language-text\">></code> - Is greater than in ASCII alphabetical order</li>\n</ul>\n<h4>If Statements</h4>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token variable\">$foo</span> <span class=\"token operator\">=</span> <span class=\"token string\">'bar'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">then</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'one'</span>\n<span class=\"token keyword\">elif</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token variable\">$foo</span> <span class=\"token operator\">=</span> <span class=\"token string\">'bar'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token variable\">$foo</span> <span class=\"token operator\">=</span> <span class=\"token string\">'baz'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">then</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'two'</span>\n<span class=\"token keyword\">elif</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token variable\">$foo</span> <span class=\"token operator\">=</span> <span class=\"token string\">'ban'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token environment constant\">$USER</span> <span class=\"token operator\">=</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">then</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'three'</span>\n<span class=\"token keyword\">else</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'four'</span>\n<span class=\"token keyword\">fi</span></code></pre></div>\n<h4>Inline If Statements</h4>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span> <span class=\"token environment constant\">$USER</span> <span class=\"token operator\">=</span> <span class=\"token string\">'rehan'</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'yes'</span> <span class=\"token operator\">||</span> <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'no'</span></code></pre></div>\n<h4>While Loops</h4>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-i</span> counter\n<span class=\"token assign-left variable\">counter</span><span class=\"token operator\">=</span><span class=\"token number\">10</span>\n<span class=\"token keyword\">while</span> <span class=\"token punctuation\">[</span><span class=\"token variable\">$counter</span> <span class=\"token parameter variable\">-gt</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span>\n  <span class=\"token builtin class-name\">echo</span> The counter is <span class=\"token variable\">$counter</span>\n  <span class=\"token assign-left variable\">counter</span><span class=\"token operator\">=</span>counter-1\n<span class=\"token keyword\">done</span></code></pre></div>\n<h4>For Loops</h4>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">i</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span><span class=\"token number\">0</span><span class=\"token punctuation\">..</span><span class=\"token number\">10</span><span class=\"token punctuation\">..</span><span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">do</span>\n    <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"Index: <span class=\"token variable\">$i</span>\"</span>\n  <span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">filename</span> <span class=\"token keyword\">in</span> file1 file2 file3\n  <span class=\"token keyword\">do</span>\n    <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"Content: \"</span> <span class=\"token operator\">>></span> <span class=\"token variable\">$filename</span>\n  <span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">filename</span> <span class=\"token keyword\">in</span> *<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">do</span>\n    <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"Content: \"</span> <span class=\"token operator\">>></span> <span class=\"token variable\">$filename</span>\n  <span class=\"token keyword\">done</span></code></pre></div>\n<h4>Case Statements</h4>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"What's the weather like tomorrow?\"</span>\n<span class=\"token builtin class-name\">read</span> weather\n\n<span class=\"token keyword\">case</span> <span class=\"token variable\">$weather</span> <span class=\"token keyword\">in</span>\n  sunny <span class=\"token operator\">|</span> warm <span class=\"token punctuation\">)</span> <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"Nice weather: \"</span> <span class=\"token variable\">$weather</span>\n  <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n  cloudy <span class=\"token operator\">|</span> cool <span class=\"token punctuation\">)</span> <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"Not bad weather: \"</span> <span class=\"token variable\">$weather</span>\n  <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n  rainy <span class=\"token operator\">|</span> cold <span class=\"token punctuation\">)</span> <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"Terrible weather: \"</span> <span class=\"token variable\">$weather</span>\n  <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n  * <span class=\"token punctuation\">)</span> <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"Don't understand\"</span>\n  <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">esac</span></code></pre></div>"},{"url":"/docs/tutorials/bash-commands-my/","relativePath":"docs/tutorials/bash-commands-my.md","relativeDir":"docs/tutorials","base":"bash-commands-my.md","name":"bash-commands-my","frontmatter":{"title":"Bash Commands Tutorial","weight":0,"excerpt":"Here's a list of bash commands that stand between me and insanity.","seo":{"title":"Bash Commands Tutorial","description":"Bash Commands That Save Me Time and Frustration","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Bash Commands That Save Me Time and Frustration</h1>\n<p>Here's a list of bash commands that stand between me and insanity.</p>\n<hr>\n<h3>Bash Commands That Save Me Time and Frustration</h3>\n<h4>Here's a list of bash commands that stand between me and insanity</h4>\n<p><a href=\"https://camo.githubusercontent.com/22b34f635d2c806b42121947a66b17cb69fe0b64d935cbdeabe81c3bccc74e8e/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a77304a3875366a5754696b59565a7a572e6a7067\">\n<img src=\"https://camo.githubusercontent.com/22b34f635d2c806b42121947a66b17cb69fe0b64d935cbdeabe81c3bccc74e8e/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a77304a3875366a5754696b59565a7a572e6a7067\" alt=\"image\"></a></p>\n<p><strong>This article will be accompanied by the following</strong> <a href=\"https://github.com/bgoonz/bash-commands-walkthrough\"><strong>github repository</strong></a> <strong>which will contain all the commands listed as well as folders that demonstrate before and after usage!</strong></p>\n<p><a href=\"https://github.com/bgoonz/bash-commands-walkthrough\" title=\"https://github.com/bgoonz/bash-commands-walkthrough\"><strong>bgoonz/bash-commands-walkthrough</strong><br>\n<em>to accompany the medium article I am writing. Contribute to bgoonz/bash-commands-walkthrough development by creating an...</em>github.com</a><a href=\"https://github.com/bgoonz/bash-commands-walkthrough\"></a></p>\n<blockquote>\n<p>The <a href=\"https://github.com/bgoonz/bash-commands-walkthrough#readme\">readme</a> for this git repo will provide a much more condensed list... whereas this article will break up the commands with explanations... images &#x26; links!</p>\n</blockquote>\n<p><strong>I will include the code examples as both github gists (for proper syntax highlighting) and as code snippets adjacent to said gists so that they can easily be copied and pasted... or ... if you're like me for instance; and like to use an extension to grab the markdown content of a page... the code will be included rather than just a link to the gist!</strong></p>\n<p><a href=\"https://camo.githubusercontent.com/a3dd21a18d0fcf7ac3c80b09877c193ba4f84657dcebde6487aea381d9aba9bf/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a336d5f5563514f41794b7449704851366a394a7a5a772e676966\">\n<img src=\"https://camo.githubusercontent.com/a3dd21a18d0fcf7ac3c80b09877c193ba4f84657dcebde6487aea381d9aba9bf/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a336d5f5563514f41794b7449704851366a394a7a5a772e676966\" alt=\"image\"></a></p>\n<h3>Here's a Cheatsheet</h3>\n<h3>Getting Started (Advanced Users Skip Section)</h3>\n<hr>\n<h4>✔ Check the Current Directory ➡ <code class=\"language-text\">pwd</code></h4>\n<p>On the command line, it's important to know the directory we are currently working on. For that, we can use <code class=\"language-text\">pwd</code> command.</p>\n<p><a href=\"https://camo.githubusercontent.com/ede56713024434b9c0c8008f54475a7f4fcdcd15427580cbc504793e43a15b6d/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a64696d7a4c55726d44493455666576362e676966\">\n<img src=\"https://camo.githubusercontent.com/ede56713024434b9c0c8008f54475a7f4fcdcd15427580cbc504793e43a15b6d/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a64696d7a4c55726d44493455666576362e676966\" alt=\"image\"></a></p>\n<p>It shows that I'm working on my Desktop directory.</p>\n<h4>✔ Display List of Files ➡ <code class=\"language-text\">ls</code></h4>\n<p>To see the list of files and directories in the current directory use <code class=\"language-text\">ls</code> command in your CLI.</p>\n<p><a href=\"https://camo.githubusercontent.com/e9cfe3bfa6f8d2ff3cc9f7959a7896facb58708e7e707d012ad989edb589b6ec/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a48487a56724b324374545077546459542e676966\">\n<img src=\"https://camo.githubusercontent.com/e9cfe3bfa6f8d2ff3cc9f7959a7896facb58708e7e707d012ad989edb589b6ec/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a48487a56724b324374545077546459542e676966\" alt=\"image\"></a></p>\n<p>Shows all of my files and directories of my Desktop directory.</p>\n<ul>\n<li>To show the contents of a directory pass the directory name to the <code class=\"language-text\">ls</code> command i.e. <code class=\"language-text\">ls directory_name</code>.</li>\n<li>Some useful <code class=\"language-text\">ls</code> command options:-</li>\n</ul>\n<p>OptionDescriptionls -alist all files including hidden file starting with '.'ls -llist with the long formatls -lalist long format including hidden files</p>\n<h4>✔ Create a Directory ➡ <code class=\"language-text\">mkdir</code></h4>\n<p>We can create a new folder using the <code class=\"language-text\">mkdir</code> command. To use it type <code class=\"language-text\">mkdir folder_name</code>.</p>\n<p><a href=\"https://camo.githubusercontent.com/8c10a898b8f52be59dc0723ab2dd0784c22c12a325ffe5cc64a38f07341ef90e/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a6d33644479433976524a42555a5378522e676966\">\n<img src=\"https://camo.githubusercontent.com/8c10a898b8f52be59dc0723ab2dd0784c22c12a325ffe5cc64a38f07341ef90e/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a6d33644479433976524a42555a5378522e676966\" alt=\"image\"></a></p>\n<p>Use <code class=\"language-text\">ls</code> command to see the directory is created or not.</p>\n<p>I created a cli-practice directory in my working directory i.e. Desktop directory.</p>\n<h4>✔ Move Between Directories ➡ <code class=\"language-text\">cd</code></h4>\n<p>It's used to change directory or to move other directories. To use it type <code class=\"language-text\">cd directory_name</code>.</p>\n<p><a href=\"https://camo.githubusercontent.com/d78e325dda59d59be4bd151dd85d3b1966324cb205da2eb540f1372e8195b280/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a33344b4778543247386f4e4d446e49632e676966\">\n<img src=\"https://camo.githubusercontent.com/d78e325dda59d59be4bd151dd85d3b1966324cb205da2eb540f1372e8195b280/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a33344b4778543247386f4e4d446e49632e676966\" alt=\"image\"></a></p>\n<p>Can use <code class=\"language-text\">pwd</code> command to confirm your directory name.</p>\n<p>Changed my directory to the cli-practice directory. And the rest of the tutorial I'm gonna work within this directory.</p>\n<h4>✔ Parent Directory ➡ <code class=\"language-text\">..</code></h4>\n<p>We have seen <code class=\"language-text\">cd</code> command to change directory but if we want to move back or want to move to the parent directory we can use a special symbol <code class=\"language-text\">..</code> after <code class=\"language-text\">cd</code> command, like <code class=\"language-text\">cd ..</code></p>\n<h4>✔ Create Files ➡ <code class=\"language-text\">touch</code></h4>\n<p>We can create an empty file by typing <code class=\"language-text\">touch file_name</code>. It's going to create a new file in the current directory (the directory you are currently in) with your provided name.</p>\n<p><a href=\"https://camo.githubusercontent.com/97e82f91cb8cfcf342cf97e8b572b49d1bc264cbe9929c7e23d0f72589d6708d/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a78753177747637674a324e4d765036302e676966\">\n<img src=\"https://camo.githubusercontent.com/97e82f91cb8cfcf342cf97e8b572b49d1bc264cbe9929c7e23d0f72589d6708d/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a78753177747637674a324e4d765036302e676966\" alt=\"image\"></a></p>\n<p>I created a hello.txt file in my current working directory. Again you can use <code class=\"language-text\">ls</code> command to see the file is created or not.</p>\n<p>Now open your hello.txt file in your text editor and write <em>Hello Everyone!</em> into your hello.txt file and save it.</p>\n<h4>✔ Display the Content of a File ➡ <code class=\"language-text\">cat</code></h4>\n<p>We can display the content of a file using the <code class=\"language-text\">cat</code> command. To use it type <code class=\"language-text\">cat file_name</code>.</p>\n<p><a href=\"https://camo.githubusercontent.com/ffe71e48a1a9bd9b118265c18a81e0b49a515cf40453416134dfca52567bb82c/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a694b6635773951464e43654c527638612e676966\">\n<img src=\"https://camo.githubusercontent.com/ffe71e48a1a9bd9b118265c18a81e0b49a515cf40453416134dfca52567bb82c/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a694b6635773951464e43654c527638612e676966\" alt=\"image\"></a></p>\n<p>Shows the content of my hello.txt file.</p>\n<h4>✔ Move Files &#x26; Directories ➡ <code class=\"language-text\">mv</code></h4>\n<p>To move a file and directory, we use <code class=\"language-text\">mv</code> command.</p>\n<p>By typing <code class=\"language-text\">mv file_to_move destination_directory</code>, you can move a file to the specified directory.</p>\n<p>By entering <code class=\"language-text\">mv directory_to_move destination_directory</code>, you can move all the files and directories under that directory.</p>\n<p>Before using this command, we are going to create two more directories and another txt file in our cli-practice directory.</p>\n<p><code class=\"language-text\">mkdir html css touch bye.txt</code></p>\n<p><a href=\"https://camo.githubusercontent.com/7197994733b63ae597fb12ba8c29509ed3c714f274d4e51542c64a942c069336/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a70696141517a5f4d51707a6f374450482e676966\">\n<img src=\"https://camo.githubusercontent.com/7197994733b63ae597fb12ba8c29509ed3c714f274d4e51542c64a942c069336/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a70696141517a5f4d51707a6f374450482e676966\" alt=\"image\"></a></p>\n<p>Yes, we can use multiple directories &#x26; files names one after another to create multiple directories &#x26; files in one command.</p>\n<p><a href=\"https://camo.githubusercontent.com/5db5a79472f5bffa91c5bfd8c892437523b68072d930c7b4334c8b622ecb55de/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a356a6d6a5f5a794e7a34364775514b7a2e676966\">\n<img src=\"https://camo.githubusercontent.com/5db5a79472f5bffa91c5bfd8c892437523b68072d930c7b4334c8b622ecb55de/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a356a6d6a5f5a794e7a34364775514b7a2e676966\" alt=\"image\"></a></p>\n<p>Moved my bye.txt file into my css directory and then moved my css directory into my html directory.</p>\n<h4>✔ Rename Files &#x26; Directories ➡ <code class=\"language-text\">mv</code></h4>\n<p><code class=\"language-text\">mv</code> command can also be used to rename a file and a directory.</p>\n<p>You can rename a file by typing <code class=\"language-text\">mv old_file_name new_file_name</code> &#x26; also rename a directory by typing <code class=\"language-text\">mv old_directory_name new_directory_name</code>.</p>\n<p><a href=\"https://camo.githubusercontent.com/3feb1289a79b907796c1d736e119730dc3d2dbcd60c6ba072ee226cc8cb69b75/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a575456753164643667722d6e6d5768442e676966\">\n<img src=\"https://camo.githubusercontent.com/3feb1289a79b907796c1d736e119730dc3d2dbcd60c6ba072ee226cc8cb69b75/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a575456753164643667722d6e6d5768442e676966\" alt=\"image\"></a></p>\n<p>Renamed my hello.txt file to the hi.txt file and html directory to the folder directory.</p>\n<h4>✔ Copy Files &#x26; Directories ➡ <code class=\"language-text\">cp</code></h4>\n<p>To do this, we use the <code class=\"language-text\">cp</code> command.</p>\n<ul>\n<li>You can copy a file by entering <code class=\"language-text\">cp file_to_copy new_file_name</code>.</li>\n</ul>\n<p><a href=\"https://camo.githubusercontent.com/9b67b2ef374ba0f1457b24007824ea5b65ca861a100397322d1a13f30a70818f/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a6b434c56744b4e396f4b5062486652462e676966\">\n<img src=\"https://camo.githubusercontent.com/9b67b2ef374ba0f1457b24007824ea5b65ca861a100397322d1a13f30a70818f/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a6b434c56744b4e396f4b5062486652462e676966\" alt=\"image\"></a></p>\n<p>Copied my hi.txt file content into hello.txt file. For confirmation open your hello.txt file in your text editor.</p>\n<ul>\n<li>You can also copy a directory by adding the <code class=\"language-text\">-r</code> option, like <code class=\"language-text\">cp -r directory_to_copy new_directory_name</code>.</li>\n</ul>\n<p><em>The</em> <code class=\"language-text\">-r</code> <em>option for \"recursive\" means that it will copy all of the files including the files inside of subfolders.</em></p>\n<p><a href=\"https://camo.githubusercontent.com/b914824b683c77cb019300487919155d05a805fb82b0a743ecdce67fd22bab55/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a4d6e6d7a4d69696f495943754b3932422e676966\">\n<img src=\"https://camo.githubusercontent.com/b914824b683c77cb019300487919155d05a805fb82b0a743ecdce67fd22bab55/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a4d6e6d7a4d69696f495943754b3932422e676966\" alt=\"image\"></a></p>\n<p>Here I copied all of the files from the folder to folder-copy.</p>\n<h4>✔ Remove Files &#x26; Directories ➡ <code class=\"language-text\">rm</code></h4>\n<p>To do this, we use the <code class=\"language-text\">rm</code> command.</p>\n<ul>\n<li>To remove a file, you can use the command like <code class=\"language-text\">rm file_to_remove</code>.</li>\n</ul>\n<p><a href=\"https://camo.githubusercontent.com/e35ef5a179966ed8271639d381b997455862bb77794f0b8c219f7ffada7168da/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a6f68436d6474686439325f4841365a652e676966\">\n<img src=\"https://camo.githubusercontent.com/e35ef5a179966ed8271639d381b997455862bb77794f0b8c219f7ffada7168da/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a6f68436d6474686439325f4841365a652e676966\" alt=\"image\"></a></p>\n<p>Here I removed my hi.txt file.</p>\n<ul>\n<li>To remove a directory, use the command like <code class=\"language-text\">rm -r directory_to_remove</code>.</li>\n</ul>\n<p><a href=\"https://camo.githubusercontent.com/5622af09767bfd626db8e52f5e040afeaf16be692b75a3069f7b01d74c1c4ee6/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a766f44627a7753707732344132526a512e676966\">\n<img src=\"https://camo.githubusercontent.com/5622af09767bfd626db8e52f5e040afeaf16be692b75a3069f7b01d74c1c4ee6/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a766f44627a7753707732344132526a512e676966\" alt=\"image\"></a></p>\n<p>I removed my folder-copy directory from my cli-practice directory i.e. current working directory.</p>\n<h4>✔ Clear Screen ➡ <code class=\"language-text\">clear</code></h4>\n<p>Clear command is used to clear the terminal screen.</p>\n<h4>✔ Home Directory ➡ <code class=\"language-text\">~</code></h4>\n<p>The Home directory is represented by <code class=\"language-text\">~</code>. The Home directory refers to the base directory for the user. If we want to move to the Home directory we can use <code class=\"language-text\">cd ~</code> command. Or we can only use <code class=\"language-text\">cd</code> command.</p>\n<hr>\n<h3>MY COMMANDS</h3>\n<h3>1.) Recursively unzip zip files and then delete the archives when finished</h3>\n<p><strong>here is a</strong> <a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/1-recursive-unzip\"><strong>folde</strong></a><strong>r containing the before and after... I had to change folder names slightly due to a limit on the length of file-paths in a github repo.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -name \"*.zip\" | while read filename; do unzip -o -d \"`dirname \"$filename\"`\" \"$filename\"; done;\n\nfind . -name \"*.zip\" -type f -print -delete</code></pre></div>\n<hr>\n<h3>2.) Install node modules recursively</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm i -g recursive-install\n\nnpm-recursive-install</code></pre></div>\n<hr>\n<h3>3.) Clean up unnecessary files/folders in git repo</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -empty -type f -print -delete #Remove empty files\n\n# -------------------------------------------------------\nfind . -empty -type d -print -delete #Remove empty folders\n\n# -------------------------------------------------------\n\n# This will remove .git folders...    .gitmodule files as well as .gitattributes and .gitignore files.\n\nfind . \\( -name \".git\" -o -name \".gitignore\" -o -name \".gitmodules\" -o -name \".gitattributes\" \\) -exec rm -rf -- {} +\n\n# -------------------------------------------------------\n\n# This will remove the filenames you see listed below that just take up space if a repo has been downloaded for use exclusively in your personal file system (in which case the following files just take up space)# Disclaimer... you should not use this command in a repo that you intend to use with your work as it removes files that attribute the work to their original creators!\n\nfind . \\( -name \"*SECURITY.txt\" -o -name \"*RELEASE.txt\" -o -name \"*CHANGELOG.txt\" -o -name \"*LICENSE.txt\" -o -name \"*CONTRIBUTING.txt\" -name \"*HISTORY.md\" -o -name \"*LICENSE\" -o -name \"*SECURITY.md\" -o -name \"*RELEASE.md\" -o -name \"*CHANGELOG.md\" -o -name \"*LICENSE.md\" -o -name \"*CODE_OF_CONDUCT.md\" -o -name \"\\*CONTRIBUTING.md\" \\) -exec rm -rf -- {} +</code></pre></div>\n<h4>In Action</h4>\n<p>The following output from my bash shell corresponds to the directory:</p>\n<p><a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/3-clean-up-fluf/DS-ALGO-OFFICIAL-master\" title=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/3-clean-up-fluf/DS-ALGO-OFFICIAL-master\"><strong>bgoonz/bash-commands-walkthrough</strong><br>\n<em>Deployment github-pages Navigation Big O notation is the language we use for talking about how long an algorithm takes...</em>github.com</a><a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/3-clean-up-fluf/DS-ALGO-OFFICIAL-master\"></a></p>\n<h4>which was created by running the aforementioned commands in in a perfect copy of this directory</h4>\n<p><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\" title=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\"><strong>bgoonz/DS-ALGO-OFFICIAL</strong><br>\n<em>Deployment github-pages Navigation Big O notation is the language we use for talking about how long an algorithm takes...</em>github.com</a><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\"></a></p>\n<blockquote>\n<p><strong>.....below is the terminal output for the following commands:</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pwd\n/mnt/c/Users/bryan/Downloads/bash-commands/steps/3-clean-up-fluf/DS-ALGO-OFFICIAL-master</code></pre></div>\n<blockquote>\n<p><strong>After printing the working directory for good measure:</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -empty -type f -print -delete</code></pre></div>\n<blockquote>\n<p><strong>The above command deletes empty files recursively starting from the directory in which it was run:</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">./CONTENT/DS-n-Algos/File-System/file-utilities/node_modules/line-reader/test/data/empty_file.txt\n./CONTENT/DS-n-Algos/_Extra-Practice/free-code-camp/nodejs/http-collect.js\n./CONTENT/Resources/Comments/node_modules/mime/.npmignore\n./markdown/tree2.md\n./node_modules/loadashes6/lodash/README.md\n./node_modules/loadashes6/lodash/release.md\n./node_modules/web-dev-utils/Markdown-Templates/Markdown-Templates-master/filled-out-readme.md\n|01:33:16|bryan@LAPTOP-9LGJ3JGS:[DS-ALGO-OFFICIAL-master] DS-ALGO-OFFICIAL-master_exitstatus:0[╗___________o></code></pre></div>\n<blockquote>\n<p><strong>The command seen below deletes empty folders recursively starting from the directory in which it was run:</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -empty -type d -print -delete</code></pre></div>\n<blockquote>\n<p>The resulting directories....</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">|01:33:16|bryan@LAPTOP-9LGJ3JGS:[DS-ALGO-OFFICIAL-master] DS-ALGO-OFFICIAL-master_exitstatus:0[╗___________o>\n\nfind . -empty -type d -print -delete\n./.git/branches\n./.git/objects/info\n./.git/refs/tags\n|01:33:31|bryan@LAPTOP-9LGJ3JGS:[DS-ALGO-OFFICIAL-master] DS-ALGO-OFFICIAL-master_exitstatus:0[╗___________o></code></pre></div>\n<blockquote>\n<p><strong>The command seen below deletes .git folders as well as .gitignore, .gitattributes, .gitmodule files</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . \\( -name \".git\" -o -name \".gitignore\" -o -name \".gitmodules\" -o -name \".gitattributes\" \\) -exec rm -rf -- {} +</code></pre></div>\n<p><strong>The command seen below deletes most SECURITY, RELEASE, CHANGELOG, LICENSE, CONTRIBUTING, &#x26; HISTORY files that take up pointless space in repo's you wish to keep exclusively for your own reference.</strong></p>\n<h3>!!!Use with caution as this command removes the attribution of the work from it's original authors</h3>\n<p><a href=\"https://camo.githubusercontent.com/ea68eea425581d8683031170810ceb578f8bafb975c1d5323100965dd912a3fa/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a72356447687462655a3456644f353455\"><img src=\"https://camo.githubusercontent.com/ea68eea425581d8683031170810ceb578f8bafb975c1d5323100965dd912a3fa/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a72356447687462655a3456644f353455\" alt=\"!!!Use with caution as this command removes the attribution of the work from it&#x27;s original authors!!!!!\"></a></p>\n<p>!!!Use with caution as this command removes the attribution of the work from it's original authors!!!!!find . ( -name \"<em>SECURITY.txt\" -o -name \"</em>RELEASE.txt\" -o -name \"<em>CHANGELOG.txt\" -o -name \"</em>LICENSE.txt\" -o -name \"<em>CONTRIBUTING.txt\" -name \"</em>HISTORY.md\" -o -name \"<em>LICENSE\" -o -name \"</em>SECURITY.md\" -o -name \"<em>RELEASE.md\" -o -name \"</em>CHANGELOG.md\" -o -name \"<em>LICENSE.md\" -o -name \"</em>CODE<em>OF</em>CONDUCT.md\" -o -name \"*CONTRIBUTING.md\" ) -exec rm -rf -- {} +</p>\n<hr>\n<h3>4.) Generate index.html file that links to all other files in working directory</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#!/bin/sh\n# find ./ | grep -i \"\\.*$\" >files\nfind ./ | sed -E -e 's/([^ ]+[ ]+){8}//' | grep -i \"\\.*$\">files\nlisting=\"files\"\nout=\"\"\nhtml=\"index.html\"\nout=\"basename $out.html\"\nhtml=\"index.html\"\ncmd() {\n  echo '  &lt;!DOCTYPE html>'\n  echo '&lt;html>'\n  echo '&lt;head>'\n  echo '  &lt;meta http-equiv=\"Content-Type\" content=\"text/html\">'\n  echo '  &lt;meta name=\"Author\" content=\"Bryan Guner\">'\n  echo '&lt;link rel=\"stylesheet\" href=\"./assets/prism.css\">'\n  echo ' &lt;link rel=\"stylesheet\" href=\"./assets/style.css\">'\n  echo ' &lt;script async defer src=\"./assets/prism.js\">\n&lt;/script>'\n  echo \"  &lt;title> directory &lt;/title>\"\n  echo \"\"\n  echo '&lt;style>'\necho '    a {'\necho '      color: black;'\necho '    }'\necho ''\necho '    li {'\necho '      border: 1px solid black !important;'\necho '      font-size: 20px;'\necho '      letter-spacing: 0px;'\necho '      font-weight: 700;'\necho '      line-height: 16px;'\necho '      text-decoration: none !important;'\necho '      text-transform: uppercase;'\necho '      background: #194ccdaf !important;'\necho '      color: black !important;'\necho '      border: none;'\necho '      cursor: pointer;'\necho '      justify-content: center;'\necho '      padding: 30px 60px;'\necho '      height: 48px;'\necho '      text-align: center;'\necho '      white-space: normal;'\necho '      border-radius: 10px;'\necho '      min-width: 45em;'\necho '      padding: 1.2em 1em 0;'\necho '      box-shadow: 0 0 5px;'\necho '      margin: 1em;'\necho '      display: grid;'\necho '      -webkit-border-radius: 10px;'\necho '      -moz-border-radius: 10px;'\necho '      -ms-border-radius: 10px;'\necho '      -o-border-radius: 10px;'\necho '    }'\necho '  &lt;/style>'\n  echo '&lt;/head>'\n  echo '&lt;body>'\n  echo \"\"\n  # continue with the HTML stuff\n  echo \"\"\n  echo \"\"\n  echo \"&lt;ul>\"\n  awk '{print \"&lt;li>\n&lt;a href=\\\"\"$1\"\\\">\",$1,\"&amp;nbsp;&lt;/a>\n&lt;/li>\"}' $listing\n  # awk '{print \"&lt;li>\"};\n  #  {print \" &lt;a href=\\\"\"$1\"\\\">\",$1,\"&lt;/a>\n&lt;/li>&amp;nbsp;\"}' \\ $listing\n  echo \"\"\n  echo \"&lt;/ul>\"\n  echo \"&lt;/body>\"\n  echo \"&lt;/html>\"\n}\ncmd $listing --sort=extension >>$html</code></pre></div>\n<h4>In Action</h4>\n<p><strong>I will use this copy of my Data Structures Practice Site to demonstrate the result:</strong></p>\n<p><a href=\"https://github.com/side-projects-42/DS-Bash-Examples-Deploy\" title=\"https://github.com/side-projects-42/DS-Bash-Examples-Deploy\"><strong>side-projects-42/DS-Bash-Examples-Deploy</strong><br>\n<em>Deployment github-pages Navigation Big O notation is the language we use for talking about how long an algorithm takes...</em>github.com</a><a href=\"https://github.com/side-projects-42/DS-Bash-Examples-Deploy\"></a></p>\n<p><a href=\"https://camo.githubusercontent.com/0f97bdb9d1167b14f340044bcdca3eb0472acc4c80dcc9c1db4f13ad6900bf20/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a5075754454557669583547366d6a612d35654b5549772e706e67\">\n<img src=\"https://camo.githubusercontent.com/0f97bdb9d1167b14f340044bcdca3eb0472acc4c80dcc9c1db4f13ad6900bf20/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a5075754454557669583547366d6a612d35654b5549772e706e67\" alt=\"image\"></a></p>\n<h4>The result is a index.html file that contains a list of links to each file in the directory</h4>\n<blockquote>\n<p>here is a link to and photo of the resulting html file:</p>\n</blockquote>\n<p><a href=\"https://quirky-meninsky-4181b5.netlify.app/\" title=\"https://quirky-meninsky-4181b5.netlify.app/\"><strong>index.html</strong><br>\n<em>CONTENT/DS-n-Algos/</em>quirky-meninsky-4181b5.netlify.app</a><a href=\"https://quirky-meninsky-4181b5.netlify.app/\"></a></p>\n<p><a href=\"https://camo.githubusercontent.com/ce04a06e4fc2c23c62fd6a9dbea96125b5920b8c53a1c62434325989768cd1a7/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a414f5962577655474e39794a3463654e7a41474773772e706e67\">\n<img src=\"https://camo.githubusercontent.com/ce04a06e4fc2c23c62fd6a9dbea96125b5920b8c53a1c62434325989768cd1a7/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a414f5962577655474e39794a3463654e7a41474773772e706e67\" alt=\"image\"></a></p>\n<hr>\n<h3>5.) Download all links to a files of a specified extension on a user provided (url) webpage</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">wget -r -A.pdf https://overapi.com/gitwget --wait=2 --level=inf --limit-rate=20K --recursive --page-requisites --user-agent=Mozilla --no-parent --convert-links --adjust-extension --no-clobber -e robots=off</code></pre></div>\n<blockquote>\n<p>The result is stored in <a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/5-download-all-pdf\">this directory:</a></p>\n</blockquote>\n<p><a href=\"https://camo.githubusercontent.com/02861c1b49280db7ab6c017bc4dc93f0d22b7385e2b33e2154fc3e734b1da3c7/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a38657656504f5f7a2d5f5441547a6b634454703135512e706e67\">\n<img src=\"https://camo.githubusercontent.com/02861c1b49280db7ab6c017bc4dc93f0d22b7385e2b33e2154fc3e734b1da3c7/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a38657656504f5f7a2d5f5441547a6b634454703135512e706e67\" alt=\"image\"></a></p>\n<hr>\n<h3>6.)Recursively remove lines of text containing the string badFolder from files in the working directory</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -type f -exec sed -i '/badFolder/d' ./* {} \\;\n\n# OR\n\nfind . -name 'result.md'  -type f -exec sed -i '/badFolder/d' ./* {} \\;</code></pre></div>\n<p><strong>As an example I will run this command on a file containing the text:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Hacks Blog\n\nRead more at hacks.mozilla.org\n\nbadFolder\n\nbadFolder Implementing Private Fields for JavaScript\n\nWhen implementing a language feature for JavaScript, an implementer must make decisions about how the language in the specification maps to the implementation. Private fields is an example of where the specification language and implementation reality diverge, at least in SpiderMonkey-- the JavaScript engine which powers Firefox. To understand more, I'll explain what private fields are, a couple of models for thinking about them, and explain why our implementation diverges from the specification language.The post Implementing Private Fields for JavaScript appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Tuesday, June 8, 2021 by Matthew Gaudet\n\nLooking fine with Firefox 89\n\nFirefox 89 has smartened up and brings with it a slimmed-down, slightly more minimalist interface.badFolder Along with this new look, we get some great styling features including a force-colours feature for media queries and better control over how fonts are displayed. The long-awaited top-level await keyword for JavaScript modules is now enabled, as well as the PerformanceEventTiming interface, which is another addition to the performance suite of APIs: 89 really has been working out!The post Looking fine with Firefox 89 appeared first on Mozilla Hacks - the Web developer blog.\n\nbadFolder\n\nPosted Tuesday, June 1, 2021 by Chris Mills\n\nbadFolder\n\nImproving Firefox stability on Linux\n\nRoughly a year ago at Mozilla we started an effort to improve Firefox stability on Linux. This effort quickly became an example of good synergies between FOSS projects.The post Improving Firefox stability on Linux appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Wednesday, May 19, 2021 by Gabriele Svelto badFolder\n\nIntroducing Firefox's new Site Isolation Security Architecture\n\nLike any web browser, Firefox loads code from untrusted and potentially hostile websites and runs it on your computer. To protect you against new types of attacks from malicious sites and to meet the security principles of Mozilla, we set out to redesign Firefox on desktop.The post Introducing Firefox's new Site Isolation Security Architecture appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Tuesday, May 18, 2021 by Anny Gakhokidze\n\nPyodide Spin Out and 0.17 Release\n\nWe are happy to announce that Pyodide has become an independent and community-driven project. We are also pleased to announce the 0.17 release for Pyodide with many new features and improvements. Pyodide consists of the CPython 3.8 interpreter compiled to WebAssembly which allows Python to run in the browser.The post Pyodide Spin Out and 0.17 Release appeared first on Mozilla Hacks - the Web developer blog. badFolder\n\nPosted Thursday, April 22, 2021 by Teon Brooks</code></pre></div>\n<p><strong><em>I modified the command slightly to apply only to files called 'result.md':</em></strong></p>\n<blockquote>\n<p>The result is :</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Hacks Blog\n\nRead more at hacks.mozilla.org\n\nWhen implementing a language feature for JavaScript, an implementer must make decisions about how the language in the specification maps to the implementation. Private fields is an example of where the specification language and implementation reality diverge, at least in SpiderMonkey-- the JavaScript engine which powers Firefox. To understand more, I'll explain what private fields are, a couple of models for thinking about them, and explain why our implementation diverges from the specification language.The post Implementing Private Fields for JavaScript appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Tuesday, June 8, 2021 by Matthew Gaudet\n\nLooking fine with Firefox 89\n\nPosted Tuesday, June 1, 2021 by Chris Mills\n\nImproving Firefox stability on Linux\n\nRoughly a year ago at Mozilla we started an effort to improve Firefox stability on Linux. This effort quickly became an example of good synergies between FOSS projects.The post Improving Firefox stability on Linux appeared first on Mozilla Hacks - the Web developer blog.\n\nIntroducing Firefox's new Site Isolation Security Architecture\n\nLike any web browser, Firefox loads code from untrusted and potentially hostile websites and runs it on your computer. To protect you against new types of attacks from malicious sites and to meet the security principles of Mozilla, we set out to redesign Firefox on desktop.The post Introducing Firefox's new Site Isolation Security Architecture appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Tuesday, May 18, 2021 by Anny Gakhokidze\n\nPyodide Spin Out and 0.17 Release\n\nPosted Thursday, April 22, 2021 by Teon Brooks</code></pre></div>\n<p><a href=\"https://camo.githubusercontent.com/4308e370c8f20afdfd06a497dcd7eb257b61b498a18c23a3c9584675b38b1a10/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a55703561732d4d6b4863486276495f715831417150772e706e67\">\n<img src=\"https://camo.githubusercontent.com/4308e370c8f20afdfd06a497dcd7eb257b61b498a18c23a3c9584675b38b1a10/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a55703561732d4d6b4863486276495f715831417150772e706e67\" alt=\"image\"></a></p>\n<p><strong>the test.txt and result.md files can be found here:</strong></p>\n<p><a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/6-remove-lines-contaning-bad-text\" title=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/6-remove-lines-contaning-bad-text\"><strong>bgoonz/bash-commands-walkthrough</strong><br>\n<em>to accompany the medium article I am writing. Contribute to bgoonz/bash-commands-walkthrough development by creating an...</em>github.com</a><a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/6-remove-lines-contaning-bad-text\"></a></p>\n<hr>\n<h3>7.) Execute command recursively</h3>\n<p><strong>Here I have modified the command I wish to run recursively to account for the fact that the 'find' command already works recursively, by appending the -maxdepth 1 flag...</strong></p>\n<blockquote>\n<p><strong>I am essentially removing the recursive action of the find command...</strong></p>\n</blockquote>\n<p><strong>That way, if the command affects the more deeply nested folders we know the outer RecurseDirs function we are using to run the <em>find/pandoc</em> line once in every subfolder of the working directory... is working properly!</strong></p>\n<p><a href=\"https://camo.githubusercontent.com/b514da1e3cfcfeda7a09f9d691618ee89526a7ebe8ded7dd7140a5c88f5f9d3e/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3630302f312a35435f757a4c6e7543536c5469696f693245746e55412e706e67\">\n<img src=\"https://camo.githubusercontent.com/b514da1e3cfcfeda7a09f9d691618ee89526a7ebe8ded7dd7140a5c88f5f9d3e/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3630302f312a35435f757a4c6e7543536c5469696f693245746e55412e706e67\" alt=\"image\"></a></p>\n<p><strong>Run in the folder shown to the left... we would expect every .md file to be accompanied by a newly generated html file by the same name.</strong></p>\n<p><strong>The results of said operation can be found in the</strong> <a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/7-recursive-run\"><strong>following directory</strong></a></p>\n<h4>In Action</h4>\n<p>🢃 Below 🢃</p>\n<p><a href=\"https://camo.githubusercontent.com/5f6bdf3692deea17ec807a6bb770b7474de94190813abae568dde34f9f8b5422/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a6b39633151524b593037544c4a6e7039536538396c512e676966\">\n<img src=\"https://camo.githubusercontent.com/5f6bdf3692deea17ec807a6bb770b7474de94190813abae568dde34f9f8b5422/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a6b39633151524b593037544c4a6e7039536538396c512e676966\" alt=\"image\"></a></p>\n<h4>The final result is</h4>\n<p><a href=\"https://camo.githubusercontent.com/1d5d06c2c92fbb7a3f42080beacb2ae8e3e0e9887220cfe81ba851eff627c753/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a6a71726a4e654275526d5472447433766d5135304c512e706e67\">\n<img src=\"https://camo.githubusercontent.com/1d5d06c2c92fbb7a3f42080beacb2ae8e3e0e9887220cfe81ba851eff627c753/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313230302f312a6a71726a4e654275526d5472447433766d5135304c512e706e67\" alt=\"image\"></a></p>\n<p><em>If you want to run any bash script recursively all you have to do is substitue out line #9 with the command you want to run once in every sub-folder.</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function RecurseDirs ()\n{\n    oldIFS=$IFS\n    IFS=$'\\n'\n    for f in \"$@\"\n    do\n\n#Replace the line below with your own command!\n\n#find ./ -iname \"*.md\" -maxdepth 1 -type f -exec sh -c 'pandoc --standalone \"${0}\" -o \"${0%.md}.html\"' {} \\;\n\n#####################################################\n# YOUR CODE BELOW!\n\n#####################################################\n\nif [[ -d \"${f}\" ]]; then\n            cd \"${f}\"\n            RecurseDirs $(ls -1 \".\")\n            cd ..\n        fi\n    done\n    IFS=$oldIFS\n}\nRecurseDirs \"./\"</code></pre></div>\n<hr>\n<h3>TBC</h3>\n<p><strong>Here are some of the other commands I will cover in greater detail... at a later time:</strong></p>\n<h3>9. Copy any text between <script> tags in a file called example.html to be inserted into a new file: out.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sed -n -e '/&lt;script>/,/&lt;\\/script>/p' example.html >out.js</code></pre></div>\n<hr>\n<h3>10. Recursively Delete node_modules folders</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -name 'node_modules' -type d -print -prune -exec rm -rf '{}' +</code></pre></div>\n<hr>\n<h3>11. Sanatize file and folder names to remove illegal characters and reserved words</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sanitize() {\n  shopt -s extglob;\n\n  filename=$(basename \"$1\")\n  directory=$(dirname \"$1\")\n\n  filename_clean=$(echo \"$filename\" | sed -e 's/[\\\\/:\\*\\?\"&lt;>\\|\\x01-\\x1F\\x7F]//g' -e 's/^\\(nul\\|prn\\|con\\|lpt[0-9]\\|com[0-9]\\|aux\\)\\(\\.\\|$\\)//i' -e 's/^\\.*$//' -e 's/^$/NONAME/')\n\n  if (test \"$filename\" != \"$filename_clean\")\n  then\n    mv -v \"$1\" \"$directory/$filename_clean\"\n  fi\n}\n\nexport -f sanitize\n\nsanitize_dir() {\n  find \"$1\" -depth -exec bash -c 'sanitize \"$0\"' {} \\;\n\n}\n\nsanitize_dir '/path/to/somewhere'</code></pre></div>\n<hr>\n<h3>12. Start postgresql in terminal</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sudo -u postgres psql</code></pre></div>\n<hr>\n<h3>13. Add closing body and script tags to each html file in working directory</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for f in * ; do\n  mv \"$f\" \"$f.html\"\ndoneecho \"&lt;form>\n &lt;input type=\"button\" value=\"Go back!\" onclick=\"history.back()\">\n&lt;/form>\n  &lt;/body>\n&lt;/html>\" | tee -a *.html</code></pre></div>\n<hr>\n<h3>14. Batch Download Videos</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#!/bin/bash\n\nlink=\"#insert url here#\"\n#links were a set of strings with just the index of the video as the variable\n\nnum=3\n#first video was numbered 3 - weird.\n\next=\".mp4\"\n\nwhile [ $num -le 66 ]\ndo\n      wget $link$num$ext -P ~/Downloads/\n      num=$(($num+1))\ndone</code></pre></div>\n<hr>\n<h3>15. Change File Extension from '.txt' to .doc for all files in working directory</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sudo apt install rename\n\nrename 's/\\.txt$/.doc/' *.txt</code></pre></div>\n<h3>16. Recursivley change any file with extension .js.download to .js</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -name \"*.\\.js\\.download\" -exec rename 's/\\.js\\.download$/.js/' '{}' +</code></pre></div>\n<hr>\n<h3>17. Copy folder structure including only files of a specific extension into an ouput Folder</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -name '*.md' | cpio -pdm './../outputFolder'</code></pre></div>\n<hr>\n<h3>Discover More</h3>\n<p><a href=\"https://bgoonz-blog.netlify.app/\" title=\"https://bgoonz-blog.netlify.app/\"><strong>Web-Dev-Hub</strong><br>\n<em>Memoization, Tabulation, and Sorting Algorithms by Example Why is looking at runtime not a reliable method of...</em>bgoonz-blog.netlify.app</a><a href=\"https://bgoonz-blog.netlify.app/\"></a></p>\n<h3>Part 2 of this series</h3>\n<p><a href=\"https://medium.com/@bryanguner/life-saving-bash-scripts-part-2-b40c8ee22682\" title=\"https://medium.com/@bryanguner/life-saving-bash-scripts-part-2-b40c8ee22682\"><strong>Medium</strong><br>\n<em>Continued!!!medium.com</em></a><a href=\"https://medium.com/@bryanguner/life-saving-bash-scripts-part-2-b40c8ee22682\"></a></p>\n<hr>\n<p>By <a href=\"https://medium.com/@bryanguner\">Bryan Guner</a> on <a href=\"https://medium.com/p/920fb6ab9d0a\">June 29, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/bash-commands-that-save-time-920fb6ab9d0a\">Canonical link</a></p>\n<p>Exported from <a href=\"https://medium.com/\">Medium</a> on July 13, 2021.</p>\n<p><a href=\"https://gist.github.com/bgoonz/674c3f169d75d5ab9453d4c7ffbdd821/raw/6df51b57737eabd32d1c68c57e110600f471619a/Bash-Comma.md\">view raw</a><a href=\"https://gist.github.com/bgoonz/674c3f169d75d5ab9453d4c7ffbdd821#file-bash-comma-md\">Bash-Comma.md</a> hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h1>Basic Web Development Environment Setup</h1>\n<p>Windows Subsystem for Linux (WSL) and Ubuntu</p>\n<hr>\n<h3>Basic Web Development Environment Setup</h3>\n<h4>Windows Subsystem for Linux (WSL) and Ubuntu</h4>\n<p><a href=\"https://camo.githubusercontent.com/305c753492ee50b499a95b10c6a817c07821f73ff6c734b45b073b8a7aeafebd/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a61714b503164724e486d4e6d33347a7a2e6a7067\">\n<img src=\"https://camo.githubusercontent.com/305c753492ee50b499a95b10c6a817c07821f73ff6c734b45b073b8a7aeafebd/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f302a61714b503164724e486d4e6d33347a7a2e6a7067\" alt=\"image\"></a></p>\n<p>Test if you have Ubuntu installed by typing \"Ubuntu\" in the search box in the bottom app bar that reads \"Type here to search\". If you see a search result that reads <strong>\"Ubuntu 20.04 LTS\"</strong> with \"App\" under it, then you have it installed.</p>\n<ol>\n<li>In the application search box in the bottom bar, type \"PowerShell\" to find the application named \"Windows PowerShell\"</li>\n<li>Right-click on \"Windows PowerShell\" and choose \"Run as administrator\" from the popup menu</li>\n<li>In the blue PowerShell window, type the following: <code class=\"language-text\">Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux</code></li>\n<li>Restart your computer</li>\n<li>In the application search box in the bottom bar, type \"Store\" to find the application named \"Microsoft Store\"</li>\n<li>Click \"Microsoft Store\"</li>\n<li>Click the \"Search\" button in the upper-right corner of the window</li>\n<li>Type in \"Ubuntu\"</li>\n<li>Click \"Run Linux on Windows (Get the apps)\"</li>\n<li>Click the orange tile labeled <strong>\"Ubuntu\"</strong> Note that there are 3 versions in the Microsoft Store... you want the one just entitled 'Ubuntu'</li>\n<li>Click \"Install\"</li>\n<li>After it downloads, click \"Launch\"</li>\n<li>If you get the option, pin the application to the task bar. Otherwise, right-click on the orange Ubuntu icon in the task bar and choose \"Pin to taskbar\"</li>\n<li>When prompted to \"Enter new UNIX username\", type your first name with no spaces</li>\n<li>When prompted, enter and retype a password for this UNIX user (it can be the same as your Windows password)</li>\n<li>Confirm your installation by typing the command <code class=\"language-text\">whoami 'as in who-am-i'</code>followed by Enter at the prompt (it should print your first name)</li>\n<li>You need to update your packages, so type <code class=\"language-text\">sudo apt update</code> (if prompted for your password, enter it)</li>\n<li>You need to upgrade your packages, so type <code class=\"language-text\">sudo apt upgrade</code> (if prompted for your password, enter it)</li>\n</ol>\n<h3>Git</h3>\n<p>Git comes with Ubuntu, so there's nothing to install. However, you should configure it using the following instructions.</p>\n<p>‌Open an Ubuntu terminal if you don't have one open already.</p>\n<ol>\n<li>You need to configure Git, so type <code class=\"language-text\">git config --global user.name \"Your Name\"</code> with replacing \"Your Name\" with your real name.</li>\n<li>You need to configure Git, so type <code class=\"language-text\">git config --global user.email your@email.com</code> with replacing \"<a href=\"mailto:your@email.com\"></a><a href=\"mailto:your@email.com\">your@email.com</a>\" with your real email.</li>\n</ol>\n<p><strong>Note: if you want git to remember your login credentials type:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">git config --global credential.helper store</code></pre></div>\n<h3>Google Chrome</h3>\n<p>Test if you have Chrome installed by typing \"Chrome\" in the search box in the bottom app bar that reads \"Type here to search\". If you see a search result that reads \"Chrome\" with \"App\" under it, then you have it installed. Otherwise, follow these instructions to install Google Chrome.</p>\n<ol>\n<li>Open Microsoft Edge, the blue \"e\" in the task bar, and type in <a href=\"http://chrome.google.com/\"></a><a href=\"http://chrome.google.com/\">http://chrome.google.com</a>. Click the \"Download Chrome\" button. Click the \"Accept and Install\" button after reading the terms of service. Click \"Save\" in the \"What do you want to do with ChromeSetup.exe\" dialog at the bottom of the window. When you have the option to \"Run\" it, do so. Answer the questions as you'd like. Set it as the default browser.</li>\n<li>Right-click on the Chrome icon in the task bar and choose \"Pin to taskbar\".</li>\n</ol>\n<h3>Node.js</h3>\n<p>Test if you have Node.js installed by opening an Ubuntu terminal and typing <code class=\"language-text\">node --version</code>. If it reports \"Command 'node' not found\", then you need to follow these directions.</p>\n<ol>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">sudo apt update</code> and press Enter</li>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">sudo apt install build-essential</code> and press Enter</li>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash</code> and press Enter</li>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">. ./.bashrc</code> and press Enter</li>\n<li>In the Ubuntu terminal, type <code class=\"language-text\">nvm install --lts</code> and press Enter</li>\n<li>Confirm that <strong>node</strong> is installed by typing <code class=\"language-text\">node --version</code> and seeing it print something that is not \"Command not found\"!</li>\n</ol>\n<h3>Unzip</h3>\n<p>You will often have to download a zip file and unzip it. It is easier to do this from the command line. So we need to install a linux unzip utility.</p>\n<p>‌In the Ubuntu terminal type: <code class=\"language-text\">sudo apt install unzip</code> and press Enter</p>\n<p>‌Mocha.js</p>\n<p>Test if you have Mocha.js installed by opening an Ubuntu terminal and typing <code class=\"language-text\">which mocha</code>. If it prints a path, then you're good. Otherwise, if it prints nothing, install Mocha.js by typing <code class=\"language-text\">npm install -g mocha</code>.</p>\n<h3>Python 3</h3>\n<p>Ubuntu does not come with Python 3. Install it using the command <code class=\"language-text\">sudo apt install python3</code>. Test it by typing <code class=\"language-text\">python3 --version</code> and seeing it print a number.</p>\n<h3>Note about WSL</h3>\n<p>As of the time of writing of this document, WSL has an issue renaming or deleting files if Visual Studio Code is open. So before doing any linux commands which manipulate files, make sure you <strong>close</strong> Visual Studio Code before running those commands in the Ubuntu terminal.</p>\n<p>‌</p>"},{"url":"/docs/tutorials/bash/","relativePath":"docs/tutorials/bash.md","relativeDir":"docs/tutorials","base":"bash.md","name":"bash","frontmatter":{"title":"Basic Bash Proficiency","weight":0,"excerpt":null,"seo":{"title":"","description":"bash shell tutorial","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Basic Bash Proficiency:</h1>\n<h2>Everyday use</h2>\n<ul>\n<li>In Bash, use <strong>Tab</strong> to complete arguments or list all available commands and <strong>ctrl-r</strong> to search through command history (after pressing, type to search, press <strong>ctrl-r</strong> repeatedly to cycle through more matches, press <strong>Enter</strong> to execute the found command, or hit the right arrow to put the result in the current line to allow editing).</li>\n<li>-</li>\n<li>In Bash, use <strong>ctrl-w</strong> to delete the last word, and <strong>ctrl-u</strong> to delete the content from current curso</li>\n<li>-</li>\n<li>Alternatively, if you love vi-style key-bindings, use <code class=\"language-text\">set -o vi</code> (and <code class=\"language-text\">set -o emacs</code> to put it back).</li>\n<li>-</li>\n<li>For editing long commands, after setting your editor (f</li>\n<li>-</li>\n<li>To see recent commands, use <code class=\"language-text\">history</code>. Follow with <code class=\"language-text\">!n</code> (where <code class=\"language-text\">n</code> is the command number) to execute again. There are also many abbreviations you can use, the most useful probably being <code class=\"language-text\">!$</code> for last argument and <code class=\"language-text\">!!</code> for last command (see \"HISTORY EXPANSION\" in the man page). However, these are often easily replaced with <strong>ctrl-r</strong> and <strong>alt-.</strong>.</li>\n<li>Go to your home directory with <code class=\"language-text\">cd</code>. Access files relative to your home directory with the <code class=\"language-text\">~</code> prefix (e.g. <code class=\"language-text\">~/.bashrc</code>). In <code class=\"language-text\">sh</code> scripts refer to the home directory as <code class=\"language-text\">$HOME</code>.</li>\n<li>To go back to the previous working directory: <code class=\"language-text\">cd -</code>.</li>\n<li>If you are halfway through typing a command but change your mind, hit <strong>alt-#</strong> to add a <code class=\"language-text\">#</code> at the beginning and enter it as a comment (or use <strong>ctrl-a</strong>, <strong>#</strong>, <strong>enter</strong>). You can then return to it later via command history.</li>\n<li>Use <code class=\"language-text\">xargs</code> (or <code class=\"language-text\">parallel</code>). It's very powerful. Note you can control how many items execute per line (<code class=\"language-text\">-L</code>) as well as parallelism (<code class=\"language-text\">-P</code>). If you're not sure if it'll do the right thing, use <code class=\"language-text\">xargs echo</code> first. Also, <code class=\"language-text\">-I{}</code> is handy. Examples:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'*.py'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token function\">grep</span> some_function\n      <span class=\"token function\">cat</span> hosts <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> -I<span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token function\">ssh</span> root@<span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token function\">hostname</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">pstree -p</code> is a helpful display of the process tree.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">pgrep</code> and <code class=\"language-text\">pkill</code> to find or signal processes by name (<code class=\"language-text\">-f</code> is helpful).</li>\n<li>-</li>\n<li>Know the various signals you can send processes. For example, to suspend a process, use <code class=\"language-text\">kill -STOP [pid]</code>. For the full list, see <code class=\"language-text\">man 7 signal</code></li>\n<li>-</li>\n<li>Use <code class=\"language-text\">nohup</code> or <code class=\"language-text\">disown</code> if you want a background process to keep ru</li>\n<li>-</li>\n<li>Check what processes are listening via <code class=\"language-text\">netstat -lntp</code> or <code class=\"language-text\">ss -plat</code> (for TCP; add <code class=\"language-text\">-u</code> for UDP) or <code class=\"language-text\">lsof -iTCP -sTCP:LISTEN -P -n</code> (which also works on macOS).</li>\n<li>-</li>\n<li>See also <code class=\"language-text\">lsof</code> and <code class=\"language-text\">fuser</code> for open sockets and files.</li>\n<li>-</li>\n<li>See <code class=\"language-text\">uptime</code> or <code class=\"language-text\">w</code> to know how long the system has been running.</li>\n<li>Use <code class=\"language-text\">alias</code> to create shortcuts for commonly used commands. For example, <code class=\"language-text\">alias ll='ls -latr'</code> creates a new alias <code class=\"language-text\">ll</code>.</li>\n<li>Save aliases, shell settings, and functions you commonly use in <code class=\"language-text\">~/.bashrc</code>, and <a href=\"http://superuser.com/a/183980/7106\">arrange for login shells to source it</a>. This will make your setup available in all your shell sessions.</li>\n<li>Put the settings of environment variables as well as commands that should be executed when you login in <code class=\"language-text\">~/.bash_profile</code>. Separate configuration will be needed for shells you launch from graphical environment logins and <code class=\"language-text\">cron</code> jobs.</li>\n<li>Synchronize your configuration files (e.g. <code class=\"language-text\">.bashrc</code> and <code class=\"language-text\">.bash_profile</code>) among various computers with Git.</li>\n<li>Understand that care is needed when variables and filenames include whitespace. Surround your Bash variables with quotes, e.g. <code class=\"language-text\">\"$FOO\"</code>. Prefer the <code class=\"language-text\">-0</code> or <code class=\"language-text\">-print0</code> options to enable null characters to delimit filenames, e.g. <code class=\"language-text\">locate -0 pattern | xargs -0 ls -al</code> or <code class=\"language-text\">find / -print0 -type d | xargs -0 ls -al</code>. To iterate on filenames containing whitespace in a for loop, set your IFS to be a newline only using <code class=\"language-text\">IFS=$'\\n'</code>.</li>\n<li>In Bash scripts, use <code class=\"language-text\">set -x</code> (or the variant <code class=\"language-text\">set -v</code>, which logs raw input, including unexpanded variables and comments) for debugging output. Use strict modes unless you have a good reason not to: Use <code class=\"language-text\">set -e</code> to abort on errors (nonzero exit code). Use <code class=\"language-text\">set -u</code> to detect unset variable usages. Consider <code class=\"language-text\">set -o pipefail</code> too, to abort on errors within pipes (though read up on it more if you do, as this topic is a bit subtle). For more involved scripts, also use <code class=\"language-text\">trap</code> on EXIT or ERR. A useful habit is to start a script like this, which will make it detect and abort on common errors and print a message:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token builtin class-name\">set</span> <span class=\"token parameter variable\">-euo</span> pipefail\n      <span class=\"token builtin class-name\">trap</span> <span class=\"token string\">\"echo 'error: Script failed: see failed command above'\"</span> ERR</code></pre></div>\n<ul>\n<li>In Bash scripts, subshells (written with parentheses) are convenient ways to group commands. A common example is to temporarily move to a different working directory, e.g.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token comment\"># do something in current dir</span>\n      <span class=\"token punctuation\">(</span>cd /some/other/dir <span class=\"token operator\">&amp;&amp;</span> other-command<span class=\"token punctuation\">)</span>\n      <span class=\"token comment\"># continue in original dir</span></code></pre></div>\n<ul>\n<li>In Bash, note there are lots of kinds of variable expansion. Checking a variable exists: <code class=\"language-text\">${name:?error message}</code>. For example, if a Bash script requires a single argument, just write <code class=\"language-text\">input_file=${1:?usage: $0 input_file}</code>. Using a default value if a variable is empty: <code class=\"language-text\">${name:-default}</code>. If you want to have an additional (optional) parameter added to the previous example, you can use something like <code class=\"language-text\">output_file=${2:-logfile}</code>. If <code class=\"language-text\">$2</code> is omitted and thus empty, <code class=\"language-text\">output_file</code> will be set to <code class=\"language-text\">logfile</code>. Arithmetic expansion: <code class=\"language-text\">i=$(( (i + 1) % 5 ))</code>. Sequences: <code class=\"language-text\">{1..10}</code>. Trimming of strings: <code class=\"language-text\">${var%suffix}</code> and <code class=\"language-text\">${var#prefix}</code>. For example if <code class=\"language-text\">var=foo.pdf</code>, then <code class=\"language-text\">echo ${var%.pdf}.txt</code> prints <code class=\"language-text\">foo.txt</code>.</li>\n<li>-</li>\n<li>Brace expansion using <code class=\"language-text\">{</code>...<code class=\"language-text\">}</code> can reduce having to re-type similar text and automate combinations of items. This is helpful in examples like <code class=\"language-text\">mv foo.{txt,pdf} some-dir</code> (which moves both files), <code class=\"language-text\">cp somefile{,.bak}</code> (which expands to <code class=\"language-text\">cp somefile somefile.bak</code>) or <code class=\"language-text\">mkdir -p test-{a,b,c}/subtest-{1,2,3}</code> (which expands all possible combinations and creates a directory tree). Brace expansion is performe</li>\n<li>-</li>\n<li>The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; and filename expansion. (For example, a range like <code class=\"language-text\">{1..20}</code> cannot be expressed with variables using <code class=\"language-text\">{$a..$b}</code>. Use <code class=\"language-text\">seq</code> or a <code class=\"language-text\">for</code> loop instead, e.g., <code class=\"language-text\">seq $a $b</code> or <code class=\"language-text\">for((i=a; i&lt;=b; i++)); do ... ; done</code>.)</li>\n<li>The output of a command can be treated like a file via <code class=\"language-text\">&lt;(some command)</code> (known as process substitution). For example, compare local <code class=\"language-text\">/etc/hosts</code> with a remote one:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">diff</span> /etc/hosts <span class=\"token operator\">&lt;</span><span class=\"token punctuation\">(</span><span class=\"token function\">ssh</span> somehost <span class=\"token function\">cat</span> /etc/hosts<span class=\"token punctuation\">)</span></code></pre></div>\n<ul>\n<li>When writing scripts you may want to put all of your code in curly braces. If the closing brace is missing, your script will be prevented from executing due to a syntax error. This makes sense when your script is going to be downloaded from the web, since it prevents partially downloaded scripts from executing:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token punctuation\">{</span>\n      <span class=\"token comment\"># Your code here</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>A \"here document\" allows <a href=\"https://www.tldp.org/LDP/abs/html/here-docs.html\">redirection of multiple lines of input</a> as if from a file:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cat &lt;&lt;EOF\ninput\non multiple lines\nEOF</code></pre></div>\n<ul>\n<li>In Bash, redirect both standard output and standard error via: <code class=\"language-text\">some-command >logfile 2>&amp;1</code> or <code class=\"language-text\">some-command &amp;>logfile</code>. Often, to ensure a command does not leave an open file handle to standard input, tying it to the terminal you are in, it is also good practice to add <code class=\"language-text\">&lt;/dev/null</code>.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">man ascii</code> for a good ASCII table, with hex and decimal values. For general encoding info, <code class=\"language-text\">man unicode</code>, <code class=\"language-text\">man utf-8</code>, and <code class=\"language-text\">man latin1</code> are helpful.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">screen</code> or <a href=\"https://tmux.github.io/\"><code class=\"language-text\">tmux</code></a> to multiplex the screen, especially useful on remote ssh sessions and to detach and re-attach to a session. <code class=\"language-text\">byobu</code> can enhance screen or tmux by providing more information and easier management. A more minimal alternative for session persistence only is <a href=\"https://github.com/bogner/dtach\"><code class=\"language-text\">dtach</code></a>.</li>\n<li>In ssh, knowing how to port tunnel with <code class=\"language-text\">-L</code> or <code class=\"language-text\">-D</code> (and occasionally <code class=\"language-text\">-R</code>) is useful, e.g. to access web sites from a remote server.</li>\n<li>It can be useful to make a few optimizations to your ssh configuration; for example, this <code class=\"language-text\">~/.ssh/config</code> contains settings to avoid dropped connections in certain network environments, uses compression (which is helpful with scp over low-bandwidth connections), and multiplex channels to the same server with a local control file:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">      TCPKeepAlive=yes\n      ServerAliveInterval=15\n      ServerAliveCountMax=6\n      Compression=yes\n      ControlMaster auto\n      ControlPath /tmp/%r@%h:%p\n      ControlPersist yes</code></pre></div>\n<ul>\n<li>A few other options relevant to ssh are security sensitive and should be enabled with care, e.g. per subnet or host or in trusted networks: <code class=\"language-text\">StrictHostKeyChecking=no</code>, <code class=\"language-text\">ForwardAgent=yes</code></li>\n<li>-</li>\n<li>Consider <a href=\"https://mosh.mit.edu/\"><code class=\"language-text\">mosh</code></a> an alternative to ssh that uses UDP, avoiding dropped connections and adding convenience on the road (requires server-side setup).</li>\n<li>To get the permissions on a file in octal form, which is useful for system configuration but not available in <code class=\"language-text\">ls</code> and easy to bungle, use something like</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">stat</span> <span class=\"token parameter variable\">-c</span> <span class=\"token string\">'%A %a %n'</span> /etc/timezone</code></pre></div>\n<ul>\n<li>For interactive selection of values from the output of another command, use <a href=\"https://github.com/mooz/percol\"><code class=\"language-text\">percol</code></a> or <a href=\"https://github.com/junegunn/fzf\"><code class=\"language-text\">fzf</code></a>.</li>\n<li>-</li>\n<li>For interaction with files based on the output of another command (like <code class=\"language-text\">git</code>), use <code class=\"language-text\">fpp</code> (<a href=\"https://github.com/facebook/PathPicker\">PathPicker</a>).</li>\n<li>For a simple web server for all files in the current directory (and subdirs), available to anyone on your network, use:\n<code class=\"language-text\">python -m SimpleHTTPServer 7777</code> (for port 7777 and Python 2) and <code class=\"language-text\">python -m http.server 7777</code> (for port 7777 and Python 3).</li>\n<li>For running a command as another user, use <code class=\"language-text\">sudo</code>. Defaults to running as root; use <code class=\"language-text\">-u</code> to specify another user. Use <code class=\"language-text\">-i</code> to login as that user (you will be asked for <em>your</em> password).</li>\n<li>-</li>\n<li>For switching the shell to another user, use <code class=\"language-text\">su username</code> or <code class=\"language-text\">su - username</code>. The latter with \"-\" gets an environment as if another user just logged in. Omitting the username defaults to root. You will be asked for the password <em>of the user you are switching to</em>.</li>\n<li>-</li>\n<li>Know about the <a href=\"https://wiki.debian.org/CommonErrorMessages/ArgumentListTooLong\">128K limit</a> on command lines. This \"Argument list too long\" error is common when wildcard matching large numbers of files. (When this happens alternatives like <code class=\"language-text\">find</code> and <code class=\"language-text\">xargs</code> may help.)</li>\n<li>For a basic calculator (and of course access to Python in general), use the <code class=\"language-text\">python</code> interpreter. For example,</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> 2+3\n5</code></pre></div>\n<h2>Processing files and data</h2>\n<ul>\n<li>To locate a file by name in the current directory, <code class=\"language-text\">find . -iname '*something*'</code> (or similar). To find a file anywhere by name, use <code class=\"language-text\">locate something</code> (but bear in mind <code class=\"language-text\">updatedb</code> may not have indexed recently created files).</li>\n<li>-</li>\n<li>For general searching through source or data f</li>\n<li>-</li>\n<li>To convert HTML to text: <code class=\"language-text\">lynx -dump -stdin</code></li>\n<li>-</li>\n<li>For Markdown, HTML, and all kinds of document conversion,</li>\n<li>-</li>\n<li>If you must handle XML, <code class=\"language-text\">xmlstarlet</code> is old but good.</li>\n<li>-</li>\n<li>For JSON, use <a href=\"http://stedolan.github.io/jq/\"><code class=\"language-text\">jq</code></a>. For interactive use, also see [<code class=\"language-text\">jid</code>](<a href=\"https://github.com/si\">https://github.com/si</a></li>\n<li>-</li>\n<li>For YAML, use <a href=\"https://github.com/0k/shyaml\"><code class=\"language-text\">shyaml</code></a>.</li>\n<li>-</li>\n<li>For Excel or CSV files, <a href=\"https://github.com/onyxfish/csvkit\">csvkit</a> provides <code class=\"language-text\">in2csv</code>, <code class=\"language-text\">csvcut</code>, <code class=\"language-text\">csvjoin</code>, <code class=\"language-text\">csvgrep</code>, etc.</li>\n<li>-</li>\n<li>For Amazon S3, <a href=\"https://github.com/s3tools/s3cmd\"><code class=\"language-text\">s3cmd</code></a> is convenient and [<code class=\"language-text\">s4cmd</code>](<a href=\"https://gi\">https://gi</a></li>\n<li>-</li>\n<li>Know about <code class=\"language-text\">sort</code> and <code class=\"language-text\">uniq</code>, including uniq's <code class=\"language-text\">-u</code> and <code class=\"language-text\">-d</code> options -- see one-liners below. See also <code class=\"language-text\">comm</code>.</li>\n<li>Know about <code class=\"language-text\">cut</code>, <code class=\"language-text\">paste</code>, and <code class=\"language-text\">join</code> to manipulate text files. Many people use <code class=\"language-text\">cut</code> but forget about <code class=\"language-text\">join</code>.</li>\n<li>Know about <code class=\"language-text\">wc</code> to count newlines (<code class=\"language-text\">-l</code>), characters (<code class=\"language-text\">-m</code>), words (<code class=\"language-text\">-w</code>) and bytes (<code class=\"language-text\">-c</code>).</li>\n<li>Know about <code class=\"language-text\">tee</code> to copy from stdin to a file and also to stdout, as in <code class=\"language-text\">ls -al | tee file.txt</code>.</li>\n<li>For more complex calculations, including grouping, reversing fields, and statistical calculations, consider <a href=\"https://www.gnu.org/software/datamash/\"><code class=\"language-text\">datamash</code></a>.</li>\n<li>Know that locale affects a lot of command line tools in subtle ways, including sorting order (collation) and performance. Most Linux installations will set <code class=\"language-text\">LANG</code> or other locale variables to a local setting like US English. But be aware sorting will change if you change locale. And know i18n routines can make sort or other commands run <em>many times</em> slower. In some situations (such as the set operations or uniqueness operations below) you can safely ignore slow i18n routines entirely and use traditional byte-based sort order, using <code class=\"language-text\">export LC_ALL=C</code>.</li>\n<li>You can set a specific command's environment by prefixing its invocation with the environment variable settings, as in <code class=\"language-text\">TZ=Pacific/Fiji date</code>.</li>\n<li>Know basic <code class=\"language-text\">awk</code> and <code class=\"language-text\">sed</code> for simple data munging. See <a href=\"#one-liners\">One-liners</a> for examples.</li>\n<li>To replace all occurrences of a string in place, in one or more files:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      perl <span class=\"token parameter variable\">-pi.bak</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'s/old-string/new-string/g'</span> my-files-*.txt</code></pre></div>\n<ul>\n<li>To rename multiple files and/or search and replace within files, try <a href=\"https://github.com/jlevy/repren\"><code class=\"language-text\">repren</code></a>. (In some cases the <code class=\"language-text\">rename</code> command also allows multiple renames, but be careful as its functionality is not the same on all Linux distributions.)</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token comment\"># Full rename of filenames, directories, and contents foo -> bar:</span>\n      repren <span class=\"token parameter variable\">--full</span> --preserve-case <span class=\"token parameter variable\">--from</span> foo <span class=\"token parameter variable\">--to</span> bar <span class=\"token builtin class-name\">.</span>\n      <span class=\"token comment\"># Recover backup files whatever.bak -> whatever:</span>\n      repren <span class=\"token parameter variable\">--renames</span> <span class=\"token parameter variable\">--from</span> <span class=\"token string\">'(.*)\\.bak'</span> <span class=\"token parameter variable\">--to</span> <span class=\"token string\">'\\1'</span> *.bak\n      <span class=\"token comment\"># Same as above, using rename, if available:</span>\n      <span class=\"token function\">rename</span> <span class=\"token string\">'s/\\.bak$//'</span> *.bak</code></pre></div>\n<ul>\n<li>As the man page says, <code class=\"language-text\">rsync</code> really is a fast and extraordinarily versatile file copying tool. It's known for synchronizing between machines but is equally useful locally. When security restrictions allow, using <code class=\"language-text\">rsync</code> instead of <code class=\"language-text\">scp</code> allows recovery of a transfer without restarting from scratch. It also is among the <a href=\"https://web.archive.org/web/20130929001850/http://linuxnote.net/jianingy/en/linux/a-fast-way-to-remove-huge-number-of-files.html\">fastest ways</a> to delete large numbers of files:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">mkdir</span> empty <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">rsync</span> <span class=\"token parameter variable\">-r</span> <span class=\"token parameter variable\">--delete</span> empty/ some-dir <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">rmdir</span> some-dir</code></pre></div>\n<ul>\n<li>For monitoring progress when processing files, use <a href=\"http://www.ivarch.com/programs/pv.shtml\"><code class=\"language-text\">pv</code></a>, <a href=\"https://github.com/dmerejkowsky/pycp\"><code class=\"language-text\">pycp</code></a>, <a href=\"https://github.com/dspinellis/pmonitor\"><code class=\"language-text\">pmonitor</code></a>, <a href=\"https://github.com/Xfennec/progress\"><code class=\"language-text\">progress</code></a>, <code class=\"language-text\">rsync --progress</code>, or, for block-level copying, <code class=\"language-text\">dd status=progress</code>.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">shuf</code> to shuffle or select random lines from a file.</li>\n<li>-</li>\n<li>Know <code class=\"language-text\">sort</code>'s options. For numbers, use <code class=\"language-text\">-n</code>, or <code class=\"language-text\">-h</code> for handling human-readable numbers (e.g. from <code class=\"language-text\">du -h</code>). Know how keys work (<code class=\"language-text\">-t</code> and <code class=\"language-text\">-k</code>). In particular, watch out that you need to write <code class=\"language-text\">-k1,1</code> to sort by only the first field; <code class=\"language-text\">-k1</code> means sort according to the whole line. Stable sort (<code class=\"language-text\">sort -s</code>) ca</li>\n<li>-</li>\n<li>If you ever need to write a tab literal in a command line in Bash (e.g. for the -t</li>\n<li>-</li>\n<li>The standard tools for patching source code are <code class=\"language-text\">diff</code> and <code class=\"language-text\">patch</code>. See also <code class=\"language-text\">diffstat</code> for summary statistics of a diff and <code class=\"language-text\">sdiff</code> for a side-by-side diff. Note <code class=\"language-text\">diff -r</code> works for entire directories. Use <code class=\"language-text\">diff -r tree1 tree2 | diffstat</code> for a summary of changes. Use <code class=\"language-text\">vimdiff</code> to compare and edit files.</li>\n<li>For binary files, use <code class=\"language-text\">hd</code>, <code class=\"language-text\">hexdump</code> or <code class=\"language-text\">xxd</code> for simple hex dumps and <code class=\"language-text\">bvi</code>, <code class=\"language-text\">hexedit</code> or <code class=\"language-text\">biew</code> for binary editing.</li>\n<li>Also for binary files, <code class=\"language-text\">strings</code> (plus <code class=\"language-text\">grep</code>, etc.) lets you find bits of text.</li>\n<li>For binary diffs (delta compression), use <code class=\"language-text\">xdelta3</code>.</li>\n<li>To convert text encodings, try <code class=\"language-text\">iconv</code>. Or <code class=\"language-text\">uconv</code> for more advanced use; it supports some advanced Unicode things. For example:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token comment\"># Displays hex codes or actual names of characters (useful for debugging):</span>\n      uconv <span class=\"token parameter variable\">-f</span> utf-8 <span class=\"token parameter variable\">-t</span> utf-8 <span class=\"token parameter variable\">-x</span> <span class=\"token string\">'::Any-Hex;'</span> <span class=\"token operator\">&lt;</span> input.txt\n      uconv <span class=\"token parameter variable\">-f</span> utf-8 <span class=\"token parameter variable\">-t</span> utf-8 <span class=\"token parameter variable\">-x</span> <span class=\"token string\">'::Any-Name;'</span> <span class=\"token operator\">&lt;</span> input.txt\n      <span class=\"token comment\"># Lowercase and removes all accents (by expanding and dropping them):</span>\n      uconv <span class=\"token parameter variable\">-f</span> utf-8 <span class=\"token parameter variable\">-t</span> utf-8 <span class=\"token parameter variable\">-x</span> <span class=\"token string\">'::Any-Lower; ::Any-NFD; [:Nonspacing Mark:] >; ::Any-NFC;'</span> <span class=\"token operator\">&lt;</span> input.txt <span class=\"token operator\">></span> output.txt</code></pre></div>\n<ul>\n<li>To split files into pieces, see <code class=\"language-text\">split</code> (to split by size) and <code class=\"language-text\">csplit</code> (to split by a pattern).</li>\n<li>-</li>\n<li>Date and time: To get the current date and time in the helpful [ISO 8601](h</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">zless</code>, <code class=\"language-text\">zmore</code>, <code class=\"language-text\">zcat</code>, and <code class=\"language-text\">zgrep</code> to operate on compressed files.</li>\n<li>File attributes are settable via <code class=\"language-text\">chattr</code> and offer a lower-level alternative to file permissions. For example, to protect against accidental file deletion the immutable flag: <code class=\"language-text\">sudo chattr +i /critical/directory/or/file</code></li>\n<li>Use <code class=\"language-text\">getfacl</code> and <code class=\"language-text\">setfacl</code> to save and restore file permissions. For example:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">   getfacl <span class=\"token parameter variable\">-R</span> /some/path <span class=\"token operator\">></span> permissions.txt\n   setfacl <span class=\"token parameter variable\">--restore</span><span class=\"token operator\">=</span>permissions.txt</code></pre></div>\n<ul>\n<li>To create empty files quickly, use <code class=\"language-text\">truncate</code> (creates <a href=\"https://en.wikipedia.org/wiki/Sparse_file\">sparse file</a>), <code class=\"language-text\">fallocate</code> (ext4, xfs, btrfs and ocfs2 filesystems), <code class=\"language-text\">xfs_mkfile</code> (almost any filesystems, comes in xfsprogs package), <code class=\"language-text\">mkfile</code> (for Unix-like systems like Solaris, Mac OS).</li>\n</ul>\n<h2>System debugging</h2>\n<ul>\n<li>For web debugging, <code class=\"language-text\">curl</code> and <code class=\"language-text\">curl -I</code> are handy, or their <code class=\"language-text\">wget</code> equivalents, or the more modern <a href=\"https://github.com/jkbrzt/httpie\"><code class=\"language-text\">httpie</code></a>.</li>\n<li>-</li>\n<li>To know current cpu/disk status, the classic tools are `t</li>\n<li>-</li>\n<li>For network connection details, use <code class=\"language-text\">netstat</code> and <code class=\"language-text\">ss</code>.</li>\n<li>-</li>\n<li>For a quick overview of what's happening on a system, <code class=\"language-text\">dstat</code> is especially useful. For broades</li>\n<li>-</li>\n<li>To know memory status, run and understand the output of <code class=\"language-text\">free</code> and <code class=\"language-text\">vmstat</code>. In particular, be aware the \"cached\" value is memory held by the Linux kernel a</li>\n<li>-</li>\n<li>Java system debugging is a different kettle of fish, but a simple trick on Oracle's and some other JVMs is that you can run <code class=\"language-text\">kill -3 &lt;pid></code> and a full stack trace and heap summary (including generational</li>\n<li>-</li>\n<li>Use <a href=\"http://www.bitwizard.nl/mtr/\"><code class=\"language-text\">mtr</code></a> as a better traceroute, to identify network issues.</li>\n<li>-</li>\n<li>For looking at why a disk is full, <a href=\"https://dev.yorhel.nl/ncdu\"><code class=\"language-text\">ncdu</code></a> saves time over the usual commands like <code class=\"language-text\">du -sh *</code>.</li>\n<li>-</li>\n<li>To find which socket or process is using bandwidth, try <a href=\"http://www.ex-parrot.com/~pdw/iftop/\"><code class=\"language-text\">iftop</code></a> or <a href=\"https://github.com/raboof/nethogs\"><code class=\"language-text\">nethogs</code></a>.</li>\n<li>-</li>\n<li>The <code class=\"language-text\">ab</code> tool (comes with Apache) is helpful for quick-and-dirty checking of web server perform</li>\n<li>-</li>\n<li>For more serious network debugging, <a href=\"https://wireshark.org/\"><code class=\"language-text\">wireshark</code></a>, <a href=\"https://www.wireshark.org/docs/wsug_html_chunked/AppToolstshark.html\"><code class=\"language-text\">tshark</code></a>, or <a href=\"http://ngrep.sourceforge.net/\"><code class=\"language-text\">ngrep</code></a>.</li>\n<li>Know about <code class=\"language-text\">strace</code> and <code class=\"language-text\">ltrace</code>. These can be helpful if a program is failing, hanging, or crashing, and you don't know why, or if you want to get a general idea of performance. Note the profiling option (<code class=\"language-text\">-c</code>), and the ability to attach to a running process (<code class=\"language-text\">-p</code>). Use trace child option (<code class=\"language-text\">-f</code>) to avoid missing important calls.</li>\n<li>Know about <code class=\"language-text\">ldd</code> to check shared libraries etc — but <a href=\"http://www.catonmat.net/blog/ldd-arbitrary-code-execution/\">never run it on untrusted files</a>.</li>\n<li>Know how to connect to a running process with <code class=\"language-text\">gdb</code> and get its stack traces.</li>\n<li>Use <code class=\"language-text\">/proc</code>. It's amazingly helpful sometimes when debugging live problems. Examples: <code class=\"language-text\">/proc/cpuinfo</code>, <code class=\"language-text\">/proc/meminfo</code>, <code class=\"language-text\">/proc/cmdline</code>, <code class=\"language-text\">/proc/xxx/cwd</code>, <code class=\"language-text\">/proc/xxx/exe</code>, <code class=\"language-text\">/proc/xxx/fd/</code>, <code class=\"language-text\">/proc/xxx/smaps</code> (where <code class=\"language-text\">xxx</code> is the process id or pid).</li>\n<li>When debugging why something went wrong in the past, <a href=\"http://sebastien.godard.pagesperso-orange.fr/\"><code class=\"language-text\">sar</code></a> can be very helpful. It shows historic statistics on CPU, memory, network, etc.</li>\n<li>For deeper systems and performance analyses, look at <code class=\"language-text\">stap</code> (<a href=\"https://sourceware.org/systemtap/wiki\">SystemTap</a>), <a href=\"https://en.wikipedia.org/wiki/Perf_%28Linux%29\"><code class=\"language-text\">perf</code></a>, and <a href=\"https://github.com/draios/sysdig\"><code class=\"language-text\">sysdig</code></a>.</li>\n<li>Check what OS you're on with <code class=\"language-text\">uname</code> or <code class=\"language-text\">uname -a</code> (general Unix/kernel info) or <code class=\"language-text\">lsb_release -a</code> (Linux distro info).</li>\n<li>Use <code class=\"language-text\">dmesg</code> whenever something's acting really funny (it could be hardware or driver issues).</li>\n<li>If you delete a file and it doesn't free up expected disk space as reported by <code class=\"language-text\">du</code>, check whether the file is in use by a process:\n<code class=\"language-text\">lsof | grep deleted | grep \"filename-of-my-big-file\"</code></li>\n</ul>\n<h2>One-liners</h2>\n<p>A few examples of piecing together commands:</p>\n<ul>\n<li>It is remarkably helpful sometimes that you can do set intersection, union, and difference of text files via <code class=\"language-text\">sort</code>/<code class=\"language-text\">uniq</code>. Suppose <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> are text files that are already uniqued. This is fast, and works on files of arbitrary size, up to many gigabytes. (Sort is not limited by memory, though you may need to use the <code class=\"language-text\">-T</code> option if <code class=\"language-text\">/tmp</code> is on a small root partition.) See also the note about <code class=\"language-text\">LC_ALL</code> above and <code class=\"language-text\">sort</code>'s <code class=\"language-text\">-u</code> option (left out for clarity below).</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">sort</span> a b <span class=\"token operator\">|</span> <span class=\"token function\">uniq</span> <span class=\"token operator\">></span> c   <span class=\"token comment\"># c is a union b</span>\n      <span class=\"token function\">sort</span> a b <span class=\"token operator\">|</span> <span class=\"token function\">uniq</span> <span class=\"token parameter variable\">-d</span> <span class=\"token operator\">></span> c   <span class=\"token comment\"># c is a intersect b</span>\n      <span class=\"token function\">sort</span> a b b <span class=\"token operator\">|</span> <span class=\"token function\">uniq</span> <span class=\"token parameter variable\">-u</span> <span class=\"token operator\">></span> c   <span class=\"token comment\"># c is set difference a - b</span></code></pre></div>\n<ul>\n<li>Pretty-print two JSON files, normalizing their syntax, then coloring and paginating the result:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">      diff &lt;(jq --sort-keys . &lt; file1.json) &lt;(jq --sort-keys . &lt; file2.json) | colordiff | less -R</code></pre></div>\n<ul>\n<li>Use <code class=\"language-text\">grep . *</code> to quickly examine the contents of all files in a directory (so each line is paired with the filename), or <code class=\"language-text\">head -100 *</code> (so each file has a heading). This can be useful for directories filled with config settings like those in <code class=\"language-text\">/sys</code>, <code class=\"language-text\">/proc</code>, <code class=\"language-text\">/etc</code>.</li>\n<li>-</li>\n<li>Summing all numbers in the third column of a text file (this is probably 3X faster and 3X less code than equivalent Python):</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">awk</span> <span class=\"token string\">'{ x += $3 } END { print x }'</span> myfile</code></pre></div>\n<ul>\n<li>To see sizes/dates on a tree of files, this is like a recursive <code class=\"language-text\">ls -l</code> but is easier to read than <code class=\"language-text\">ls -lR</code>:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-ls</span></code></pre></div>\n<ul>\n<li>Say you have a text file, like a web server log, and a certain value that appears on some lines, such as an <code class=\"language-text\">acct_id</code> parameter that is present in the URL. If you want a tally of how many requests for each <code class=\"language-text\">acct_id</code>:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token function\">egrep</span> <span class=\"token parameter variable\">-o</span> <span class=\"token string\">'acct_id=[0-9]+'</span> access.log <span class=\"token operator\">|</span> <span class=\"token function\">cut</span> <span class=\"token parameter variable\">-d</span><span class=\"token operator\">=</span> <span class=\"token parameter variable\">-f2</span> <span class=\"token operator\">|</span> <span class=\"token function\">sort</span> <span class=\"token operator\">|</span> <span class=\"token function\">uniq</span> <span class=\"token parameter variable\">-c</span> <span class=\"token operator\">|</span> <span class=\"token function\">sort</span> <span class=\"token parameter variable\">-rn</span></code></pre></div>\n<ul>\n<li>To continuously monitor changes, use <code class=\"language-text\">watch</code>, e.g. check changes to files in a directory with <code class=\"language-text\">watch -d -n 2 'ls -rtlh | tail'</code> or to network settings while troubleshooting your wifi settings with <code class=\"language-text\">watch -d -n 2 ifconfig</code>.</li>\n<li>-</li>\n<li>Run this function to get a random tip from this document (parses Markdown and extracts an item):</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">      <span class=\"token keyword\">function</span> <span class=\"token function-name function\">taocl</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">curl</span> <span class=\"token parameter variable\">-s</span> https://raw.githubusercontent.com/jlevy/the-art-of-command-line/master/README.md <span class=\"token operator\">|</span>\n          <span class=\"token function\">sed</span> <span class=\"token string\">'/cowsay[.]png/d'</span> <span class=\"token operator\">|</span>\n          pandoc <span class=\"token parameter variable\">-f</span> markdown <span class=\"token parameter variable\">-t</span> html <span class=\"token operator\">|</span>\n          xmlstarlet fo <span class=\"token parameter variable\">--html</span> <span class=\"token parameter variable\">--dropdtd</span> <span class=\"token operator\">|</span>\n          xmlstarlet sel <span class=\"token parameter variable\">-t</span> <span class=\"token parameter variable\">-v</span> <span class=\"token string\">\"(html/body/ul/li[count(p)>0])[<span class=\"token environment constant\">$RANDOM</span> mod last()+1]\"</span> <span class=\"token operator\">|</span>\n          xmlstarlet unesc <span class=\"token operator\">|</span> <span class=\"token function\">fmt</span> <span class=\"token parameter variable\">-80</span> <span class=\"token operator\">|</span> <span class=\"token function\">iconv</span> <span class=\"token parameter variable\">-t</span> US\n      <span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Obscure but useful</h2>\n<ul>\n<li><code class=\"language-text\">expr</code>: perform arithmetic or boolean operations or evaluate regular expressions</li>\n<li>-</li>\n<li><code class=\"language-text\">m4</code>: simple macro processor</li>\n<li>-</li>\n<li><code class=\"language-text\">yes</code>: print a string a lot</li>\n<li>-</li>\n<li><code class=\"language-text\">cal</code>: nice calendar</li>\n<li>-</li>\n<li><code class=\"language-text\">env</code>: run a command (useful in</li>\n<li>-</li>\n<li><code class=\"language-text\">printenv</code>: print out enviro</li>\n<li>-</li>\n<li><code class=\"language-text\">look</code>: find English words (or lines in a file) beginning</li>\n<li>-</li>\n<li><code class=\"language-text\">cut</code>, <code class=\"language-text\">paste</code> and `jo</li>\n<li>-</li>\n<li><code class=\"language-text\">fmt</code>: format text paragrap</li>\n<li>-</li>\n<li><code class=\"language-text\">pr</code>: format text into pages/colum</li>\n<li>-</li>\n<li><code class=\"language-text\">fold</code>: wrap lines of text</li>\n<li>-</li>\n<li><code class=\"language-text\">column</code>: format text fields into aligned, f</li>\n<li>-</li>\n<li><code class=\"language-text\">expand</code> and <code class=\"language-text\">unexpand</code>: convert between tabs and spaces</li>\n<li>-</li>\n<li><code class=\"language-text\">nl</code>: add line numbers</li>\n<li>-</li>\n<li><code class=\"language-text\">seq</code>: print numbers</li>\n<li>-</li>\n<li><code class=\"language-text\">bc</code>: calculator</li>\n<li>-</li>\n<li><code class=\"language-text\">factor</code>: factor integers</li>\n<li>-</li>\n<li><a href=\"https://gnupg.org/\"><code class=\"language-text\">gpg</code></a>: encrypt and si</li>\n<li>-</li>\n<li><code class=\"language-text\">toe</code>: table of terminfo entries</li>\n<li>-</li>\n<li><code class=\"language-text\">nc</code>: network debugging and data transfer</li>\n<li>-</li>\n<li><code class=\"language-text\">socat</code>: socket relay and tcp port</li>\n<li>-</li>\n<li>[<code class=\"language-text\">slurm</code>](<a href=\"https://github.com/\">https://github.com/</a></li>\n<li>-</li>\n<li><code class=\"language-text\">dd</code>: moving data between files or devices</li>\n<li>-</li>\n<li><code class=\"language-text\">file</code>: identify type of a file</li>\n<li>-</li>\n<li><code class=\"language-text\">tree</code>: display directories and subdirectories as a nesting tree;</li>\n<li>-</li>\n<li><code class=\"language-text\">stat</code>: file info</li>\n<li>-</li>\n<li><code class=\"language-text\">time</code>: execute and time a command</li>\n<li>-</li>\n<li><code class=\"language-text\">timeout</code>: execute a command for specified amount of time and stop the process when the s</li>\n<li>-</li>\n<li><code class=\"language-text\">lockfile</code>: create semaphor</li>\n<li>-</li>\n<li><code class=\"language-text\">logrotate</code>: rotate, compress and</li>\n<li>-</li>\n<li><code class=\"language-text\">watch</code>: run a command</li>\n<li>-</li>\n<li><a href=\"https://github.com/joh/when-changed\"><code class=\"language-text\">when-changed</code></a>: runs any command you spe</li>\n<li>-</li>\n<li><code class=\"language-text\">tac</code>: print files in rev</li>\n<li>-</li>\n<li><code class=\"language-text\">comm</code>: compare sorted files line by line</li>\n<li>-</li>\n<li><code class=\"language-text\">strings</code>: extract text from binary files</li>\n<li>-</li>\n<li><code class=\"language-text\">tr</code>: character translation or manipulation</li>\n<li>-</li>\n<li><code class=\"language-text\">iconv</code> or <code class=\"language-text\">uconv</code>: conversion for text encodings</li>\n<li><code class=\"language-text\">split</code> and <code class=\"language-text\">csplit</code>: splitting files</li>\n<li><code class=\"language-text\">sponge</code>: read all input before writing it, useful for reading from then writing to the same file, e.g., <code class=\"language-text\">grep -v something some-file | sponge some-file</code></li>\n<li><code class=\"language-text\">units</code>: unit conversions and calculations; converts furlongs per fortnight to twips per blink (see also <code class=\"language-text\">/usr/share/units/definitions.units</code>)</li>\n<li><code class=\"language-text\">apg</code>: generates random passwords</li>\n<li><code class=\"language-text\">xz</code>: high-ratio file compression</li>\n<li><code class=\"language-text\">ldd</code>: dynamic library info</li>\n<li><code class=\"language-text\">nm</code>: symbols from object files</li>\n<li><code class=\"language-text\">ab</code> or <a href=\"https://github.com/wg/wrk\"><code class=\"language-text\">wrk</code></a>: benchmarking web servers</li>\n<li><code class=\"language-text\">strace</code>: system call debugging</li>\n<li><a href=\"http://www.bitwizard.nl/mtr/\"><code class=\"language-text\">mtr</code></a>: better traceroute for network debugging</li>\n<li><code class=\"language-text\">cssh</code>: visual concurrent shell</li>\n<li><code class=\"language-text\">rsync</code>: sync files and folders over SSH or in local file system</li>\n<li><a href=\"https://wireshark.org/\"><code class=\"language-text\">wireshark</code></a> and <a href=\"https://www.wireshark.org/docs/wsug_html_chunked/AppToolstshark.html\"><code class=\"language-text\">tshark</code></a>: packet capture and network debugging</li>\n<li><a href=\"http://ngrep.sourceforge.net/\"><code class=\"language-text\">ngrep</code></a>: grep for the network layer</li>\n<li><code class=\"language-text\">host</code> and <code class=\"language-text\">dig</code>: DNS lookups</li>\n<li><code class=\"language-text\">lsof</code>: process file descriptor and socket info</li>\n<li><code class=\"language-text\">dstat</code>: useful system stats</li>\n<li><a href=\"https://github.com/nicolargo/glances\"><code class=\"language-text\">glances</code></a>: high level, multi-subsystem overview</li>\n<li><code class=\"language-text\">iostat</code>: Disk usage stats</li>\n<li><code class=\"language-text\">mpstat</code>: CPU usage stats</li>\n<li><code class=\"language-text\">vmstat</code>: Memory usage stats</li>\n<li><code class=\"language-text\">htop</code>: improved version of top</li>\n<li><code class=\"language-text\">last</code>: login history</li>\n<li><code class=\"language-text\">w</code>: who's logged on</li>\n<li><code class=\"language-text\">id</code>: user/group identity info</li>\n<li><a href=\"http://sebastien.godard.pagesperso-orange.fr/\"><code class=\"language-text\">sar</code></a>: historic system stats</li>\n<li><a href=\"http://www.ex-parrot.com/~pdw/iftop/\"><code class=\"language-text\">iftop</code></a> or <a href=\"https://github.com/raboof/nethogs\"><code class=\"language-text\">nethogs</code></a>: network utilization by socket or process</li>\n<li><code class=\"language-text\">ss</code>: socket statistics</li>\n<li><code class=\"language-text\">dmesg</code>: boot and system error messages</li>\n<li><code class=\"language-text\">sysctl</code>: view and configure Linux kernel parameters at run time</li>\n<li><code class=\"language-text\">hdparm</code>: SATA/ATA disk manipulation/performance</li>\n<li><code class=\"language-text\">lsblk</code>: list block devices: a tree view of your disks and disk partitions</li>\n<li><code class=\"language-text\">lshw</code>, <code class=\"language-text\">lscpu</code>, <code class=\"language-text\">lspci</code>, <code class=\"language-text\">lsusb</code>, <code class=\"language-text\">dmidecode</code>: hardware information, including CPU, BIOS, RAID, graphics, devices, etc.</li>\n<li><code class=\"language-text\">lsmod</code> and <code class=\"language-text\">modinfo</code>: List and show details of kernel modules.</li>\n<li><code class=\"language-text\">fortune</code>, <code class=\"language-text\">ddate</code>, and <code class=\"language-text\">sl</code>: um, well, it depends on whether you consider steam locomotives and Zippy quotations \"useful\"</li>\n</ul>\n<h2>macOS only</h2>\n<p>These are items relevant <em>only</em> on macOS.</p>\n<ul>\n<li>Package management with <code class=\"language-text\">brew</code> (Homebrew) and/or <code class=\"language-text\">port</code> (MacPorts). These can be used to install on macOS many of the above commands.</li>\n<li>-</li>\n<li>Copy output of any command to a desktop app with <code class=\"language-text\">pbcopy</code> and paste input from one with <code class=\"language-text\">pbpaste</code>.</li>\n<li>-</li>\n<li>To enable the Option key in macOS Terminal as an alt key (such as used in the commands above lik</li>\n<li>-</li>\n<li>To open a file with a desktop app, use <code class=\"language-text\">open</code> or <code class=\"language-text\">open -a /Applications/Whatever.app</code>.</li>\n<li>Spotlight: Search files with <code class=\"language-text\">mdfind</code> and list metadata (such as photo EXIF info) with <code class=\"language-text\">mdls</code>.</li>\n<li>Be aware macOS is based on BSD Unix, and many commands (for example <code class=\"language-text\">ps</code>, <code class=\"language-text\">ls</code>, <code class=\"language-text\">tail</code>, <code class=\"language-text\">awk</code>, <code class=\"language-text\">sed</code>) have many subtle variations from Linux, which is largely influenced by System V-style Unix and GNU tools. You can often tell the difference by noting a man page has the heading \"BSD General Commands Manual.\" In some cases GNU versions can be installed, too (such as <code class=\"language-text\">gawk</code> and <code class=\"language-text\">gsed</code> for GNU awk and sed). If writing cross-platform Bash scripts, avoid such commands (for example, consider Python or <code class=\"language-text\">perl</code>) or test carefully.</li>\n<li>To get macOS release information, use <code class=\"language-text\">sw_vers</code>.</li>\n</ul>\n<h2>Windows only</h2>\n<p>These items are relevant <em>only</em> on Windows.</p>\n<h3>Ways to obtain Unix tools under Windows</h3>\n<ul>\n<li>Access the power of the Unix shell under Microsoft Windows by installing <a href=\"https://cygwin.com/\">Cygwin</a>. Most of the things described in this document will work out of the box.</li>\n<li>-</li>\n<li>On Windows 10, you can use <a href=\"https://msdn.microsoft.com/commandline/wsl/about\">Windows Subsystem for Linux (WSL)</a>, which provides a familiar Bash environment with Unix command line utilities.</li>\n<li>-</li>\n<li>If you mainly want to use GNU developer tools (such as GCC) on Windows, consider <a href=\"http://www.mingw.org/\">MinGW</a> and its <a href=\"http://www.mingw.org/wiki/msys\">MSYS</a> package, which provides utilities such as bash, gawk, make and grep. MSYS doesn't have all the features compared to Cygwin. MinGW is particularly useful for creating native Windows ports of Unix tools.</li>\n<li>Another option to get Unix look and feel under Windows is <a href=\"https://github.com/dthree/cash\">Cash</a>. Note that only very few Unix commands and command-line options are available in this environment.</li>\n</ul>\n<h3>Useful Windows command-line tools</h3>\n<ul>\n<li>You can perform and script most Windows system administration tasks from the command line by learning and using <code class=\"language-text\">wmic</code>.</li>\n<li>-</li>\n<li>Native command-line Windows networking tools you may find useful include <code class=\"language-text\">ping</code>, <code class=\"language-text\">ipconfig</code>, <code class=\"language-text\">tracert</code>, and <code class=\"language-text\">netstat</code>.</li>\n<li>You can perform <a href=\"http://www.thewindowsclub.com/rundll32-shortcut-commands-windows\">many useful Windows tasks</a> by invoking the <code class=\"language-text\">Rundll32</code> command.</li>\n</ul>\n<h3>Cygwin tips and tricks</h3>\n<ul>\n<li>Install additional Unix programs with the Cygwin's package manager.</li>\n<li>-</li>\n<li>Use <code class=\"language-text\">mintty</code> as your command-line window.</li>\n<li>-</li>\n<li>Access the Windows clipboard through `/dev/cl</li>\n<li>-</li>\n<li>Run <code class=\"language-text\">cygstart</code> to open an arbitrary file through its registered application.</li>\n<li>Access the Windows registry with <code class=\"language-text\">regtool</code>.</li>\n<li>Note that a <code class=\"language-text\">C:\\</code> Windows drive path becomes <code class=\"language-text\">/cygdrive/c</code> under Cygwin, and that Cygwin's <code class=\"language-text\">/</code> appears under <code class=\"language-text\">C:\\cygwin</code> on Windows. Convert between Cygwin and Windows-style file paths with <code class=\"language-text\">cygpath</code>. This is most useful in scripts that invoke Windows programs.</li>\n</ul>\n<h2>More resources</h2>\n<ul>\n<li><a href=\"https://github.com/alebcay/awesome-shell\">awesome-shell</a>: A curated list of shell tools and resources.</li>\n<li><a href=\"https://github.com/herrbischoff/awesome-osx-command-line\">awesome-osx-command-line</a>: A more in-depth guide for the macOS command line.</li>\n<li><a href=\"http://redsymbol.net/articles/unofficial-bash-strict-mode/\">Strict mode</a> for writing better shell scripts.</li>\n<li><a href=\"https://github.com/koalaman/shellcheck\">shellcheck</a>: A shell script static analysis tool. Essentially, lint for bash/sh/zsh.</li>\n<li><a href=\"http://www.dwheeler.com/essays/filenames-in-shell.html\">Filenames and Pathnames in Shell</a>: The sadly complex minutiae on how to handle filenames correctly in shell scripts.</li>\n<li><a href=\"http://datascienceatthecommandline.com/#tools\">Data Science at the Command Line</a>: More commands and tools helpful for doing data science, from the book of the same name</li>\n</ul>"},{"url":"/docs/typescript/","relativePath":"docs/typescript/index.md","relativeDir":"docs/typescript","base":"index.md","name":"index","frontmatter":{"title":"typescript","weight":0,"excerpt":"Walkthroughs of various development activities and skills","seo":{"title":"typescript","description":"This section is dedicated to coding walkthroughs","robots":[],"extra":[]},"template":"docs"},"html":"<iframe src=\"https://codesandbox.io/embed/gists-forked-zf8wb6?autoresize=1&fontsize=14&hidenavigation=1&theme=dark&view=preview\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"typescript for js developers\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   ></iframe>"},{"url":"/docs/tutorials/get-file-extension/","relativePath":"docs/tutorials/get-file-extension.md","relativeDir":"docs/tutorials","base":"get-file-extension.md","name":"get-file-extension","frontmatter":{"title":"How to get the file extension","weight":0,"excerpt":"How to get the file extension","seo":{"title":"","description":"How to get the file extension","robots":[],"extra":[]},"template":"docs"},"html":"<h3>Question: How to get the file extension?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> file1 <span class=\"token operator\">=</span> <span class=\"token string\">'50.xsl'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> file2 <span class=\"token operator\">=</span> <span class=\"token string\">'30.doc'</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">getFileExtension</span><span class=\"token punctuation\">(</span>file1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//returs xsl</span>\n<span class=\"token function\">getFileExtension</span><span class=\"token punctuation\">(</span>file2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//returs doc</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getFileExtension</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">filename</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">/*TODO*/</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Solution 1: Regular Expression</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getFileExtension1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">filename</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[.]</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^.]+$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Solution 2: String <code class=\"language-text\">split</code> method</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getFileExtension2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">filename</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> filename<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Those two solutions couldnot handle some edge cases, here is another more robust solution.</p>\n<h3>Solution3: String <code class=\"language-text\">slice</code>, <code class=\"language-text\">lastIndexOf</code> methods</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getFileExtension3</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">filename</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> filename<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">.</span><span class=\"token function\">lastIndexOf</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">>>></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">getFileExtension3</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ''</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">getFileExtension3</span><span class=\"token punctuation\">(</span><span class=\"token string\">'filename'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ''</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">getFileExtension3</span><span class=\"token punctuation\">(</span><span class=\"token string\">'filename.txt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 'txt'</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">getFileExtension3</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.hiddenfile'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ''</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">getFileExtension3</span><span class=\"token punctuation\">(</span><span class=\"token string\">'filename.with.many.dots.ext'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 'ext'</span></code></pre></div>\n<p><em>How does it works?</em></p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf\">String.lastIndexOf()</a> method returns the last occurrence of the specified value (<code class=\"language-text\">'.'</code> in this case). Returns <code class=\"language-text\">-1</code> if the value is not found.</li>\n<li>The return values of <code class=\"language-text\">lastIndexOf</code> for parameter <code class=\"language-text\">'filename'</code> and <code class=\"language-text\">'.hiddenfile'</code> are <code class=\"language-text\">-1</code> and <code class=\"language-text\">0</code> respectively. <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#%3E%3E%3E_%28Zero-fill_right_shift%29\">Zero-fill right shift operator (>>>)</a> will transform <code class=\"language-text\">-1</code> to <code class=\"language-text\">4294967295</code> and <code class=\"language-text\">-2</code> to <code class=\"language-text\">4294967294</code>, here is one trick to insure the filename unchanged in those edge cases.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice\">String.prototype.slice()</a> extracts file extension from the index that was calculated above. If the index is more than the length of the filename, the result is <code class=\"language-text\">\"\"</code>.</li>\n</ul>\n<h3>Comparison</h3>\n<table>\n<thead>\n<tr>\n<th>Solution</th>\n<th align=\"center\">Paramters</th>\n<th align=\"center\">Results</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Solution 1: Regular Expression</td>\n<td align=\"center\">''<br> 'filename' <br> 'filename.txt' <br> '.hiddenfile' <br> 'filename.with.many.dots.ext'</td>\n<td align=\"center\">undefined <br> undefined <br> 'txt' <br> 'hiddenfile' <br> 'ext' <br></td>\n</tr>\n<tr>\n<td>Solution 2: String <code class=\"language-text\">split</code></td>\n<td align=\"center\">''<br> 'filename' <br> 'filename.txt' <br> '.hiddenfile' <br> 'filename.with.many.dots.ext'</td>\n<td align=\"center\">'' <br> 'filename' <br> 'txt' <br> 'hiddenfile' <br> 'ext' <br></td>\n</tr>\n<tr>\n<td>Solution 3: String <code class=\"language-text\">slice</code>, <code class=\"language-text\">lastIndexOf</code></td>\n<td align=\"center\">''<br> 'filename' <br> 'filename.txt' <br> '.hiddenfile' <br> 'filename.with.many.dots.ext'</td>\n<td align=\"center\">'' <br> '' <br> 'txt' <br> '' <br> 'ext' <br></td>\n</tr>\n</tbody>\n</table>\n<h3>Live Demo and Performance</h3>\n<p><a href=\"https://jsbin.com/tipofu/edit?js,console\">Here</a> is the live demo of the above codes.</p>\n<p><a href=\"http://jsperf.com/extract-file-extension\">Here</a> is the performance test of those 3 solutions.</p>"},{"url":"/docs/tutorials/","relativePath":"docs/tutorials/index.md","relativeDir":"docs/tutorials","base":"index.md","name":"index","frontmatter":{"title":"Tutorials","weight":0,"excerpt":"Walkthroughs of various development activities and skills","seo":{"title":"Tutorials","description":"This section is dedicated to coding walkthroughs","robots":[],"extra":[]},"template":"docs"},"html":"<p>This section is dedicated to coding walkthroughs:</p>"},{"url":"/docs/tutorials/how-2-ubuntu/","relativePath":"docs/tutorials/how-2-ubuntu.md","relativeDir":"docs/tutorials","base":"how-2-ubuntu.md","name":"how-2-ubuntu","frontmatter":{"title":"How To Ubuntu","weight":0,"excerpt":"How To Ubuntu","seo":{"title":"Ubuntu","description":"How To Ubuntu","robots":[],"extra":[]},"template":"docs"},"html":"<h1>How do I completely uninstall Ubuntu?</h1>\n<ul>\n<li>Just boot into Windows and head to Control Panel > Programs and Features. Find Ubuntu in the list of installed programs, and then uninstall it like you would any other program. The uninstaller automatically removes the Ubuntu files and boot loader entry from your computer.</li>\n</ul>\n<p><strong>Go to Start, right click Computer, then select Manage. Then select Disk Management from the sidebar. Right-click your Ubuntu partitions and select \"Delete\". Check before you delete!</strong>.</p>\n<h3>How do I remove Linux from my laptop?</h3>\n<blockquote>\n<p><strong>To remove Linux, open the Disk Management utility, select the partition(s) where Linux is installed and then format them or delete them. If you delete the partitions, the device will have all its space freed. To make good use of the free space, create a new partition and format it.</strong></p>\n</blockquote>\n<h3>How do I remove unwanted OS from Boot menu?</h3>\n<blockquote>\n<p><strong>Follow these steps: Click Start. Type msconfig in the search box or open Run. Go to Boot. Select which Windows version you'd like to boot into directly. Press Set as Default. You can delete the earlier version by selecting it and then clicking Delete. Click Apply. Click OK.</strong></p>\n</blockquote>\n<h3>Does dual boot slow down laptop?</h3>\n<blockquote>\n<p>**Essentially, dual booting will slow down your computer or laptop. While a Linux OS may use the hardware more efficiently overall, as the secondary OS it is at a disadvantage.</p>\n</blockquote>\n<h3>How do I completely remove Ubuntu and install Windows 10?</h3>\n<blockquote>\n<p><strong>More Information Remove native, swap, and boot partitions used by Linux: Start your computer with the Linux setup floppy disk, type fdisk at the command prompt, and then press ENTER. Install Windows. Follow the installation instructions for the Windows operating system you want to install on your computer.</strong></p>\n</blockquote>\n<h3>How do I uninstall an operating system?</h3>\n<blockquote>\n<p><strong>In System Configuration, go to the Boot tab, and check whether the Windows that you want to keep is set as default. To do that, select it and then press \"Set as default.\" Next, select the Windows that you want to uninstall, click Delete, and then Apply or OK.</strong></p>\n</blockquote>\n<h3>How do I remove my OS from my hard drive?</h3>\n<blockquote>\n<p><strong>Press the \"D\" key on your keyboard and then press the \"L\" key to confirm your decision to delete the operating system. Depending on the amount of data on the hard drive, the deletion process could take up to 30 minutes to complete.</strong></p>\n</blockquote>\n<h4>How do I uninstall a package in Linux?</h4>\n<blockquote>\n<p><strong>Include the -e option on the rpm command to remove installed packages; the command syntax is: rpm -e package_name [package_name…] To instruct rpm to remove multiple packages, provide a list of packages you wish to remove when invoking the command.</strong></p>\n</blockquote>\n<h4>What happens if I delete my operating system?</h4>\n<blockquote>\n<p><strong>When the operating system is deleted, you can't boot your computer as expected and the files stored on your computer hard drive are inaccessible. To eliminate this annoying issue, you need to recover the deleted operating system and make your computer boot normally again.</strong></p>\n</blockquote>\n<h3>How do I uninstall Windows 11?</h3>\n<blockquote>\n<p><strong>How to Uninstall Windows 11 Navigate to Settings->System->Recovery. Click Go back next to Previous version of Windows. Check off one or more reasons for your uninstall when prompted. Click \"No, thanks\" when asked to check for updates instead of rolling back. Click Next.</strong></p>\n</blockquote>\n<h4>How do I remove a Windows hard drive without formatting?</h4>\n<blockquote>\n<p><strong>How to remove windows OS from another drive without formatting Press Windows +R keys. Now you need to type msconfig and hit enter. Now you should select Windows 10/7/8 and select \"Delete\" You should delete all the Windows directory from your drive (C, D, E).</strong></p>\n</blockquote>\n<h3>How do I remove OS boot manager?</h3>\n<blockquote>\n<p><strong>Through System Configuration Press the Windows + R keys to open the Run dialog, type msconfig, and press Enter. Click/tap on the Boot tab. ( Select the operating system you want to delete that is not set as the Default OS, and click/tap on Delete. ( Check the Make all boot settings permanent box, and click/tap on OK. (.</strong></p>\n</blockquote>\n<h3>How do I remove old OS from BIOS?</h3>\n<blockquote>\n<p><strong>Boot with it. A window (Boot-Repair) will appear, close it. Then launch OS-Uninstaller from the bottom left menu. In the OS Uninstaller window, select the OS you want to remove and click the OK button, then click the Apply button in the confirmation window that opens up.</strong></p>\n</blockquote>\n<h4>How do I remove the boot menu in Windows 10?</h4>\n<blockquote>\n<p><strong>Delete Windows 10 Boot Menu Entry with msconfig.exe Press Win + R on the keyboard and type msconfig into the Run box. In System Configuration, switch to the Boot tab. Select an entry you want to delete in the list. Click on the Delete button. Click Apply and OK. Now you can close the System Configuration app.</strong></p>\n</blockquote>\n<h3>Does dual-boot affect RAM?</h3>\n<blockquote>\n<p><strong>The fact that only one operating system will run in a dual-boot setup, hardware resources like CPU and memory is not shared on both Operating Systems (Windows and Linux) therefore making the operating system currently running use the maximum hardware specification.</strong></p>\n</blockquote>\n<h3>Is dual booting a good idea?</h3>\n<blockquote>\n<p>**If your system does not quite have the resources to effectively run a virtual machine (which can be very taxing), and you have a need to work between the two systems, then dual booting is probably a good option for you. \"The take-away from this however, and generally good advice for most things, would be to plan ahead.</p>\n</blockquote>\n<h3>Can I run two OS on my laptop?</h3>\n<blockquote>\n<p><strong>Yes, most likely. Most computers can be configured to run more than one operating system. Windows, macOS, and Linux (or multiple copies of each) can happily coexist on one physical computer.</strong></p>\n</blockquote>\n<h3>Can I replace Ubuntu with Windows 10?</h3>\n<blockquote>\n<p><strong>You can definitely have Windows 10 as your operating system. Since your previous operating system is not from Windows, you will need to purchase Windows 10 from a retail store and clean install it over Ubuntu.</strong></p>\n</blockquote>\n<h3>How do I switch from Ubuntu to Windows without restarting?</h3>\n<blockquote>\n<p>**From a workspace: Press Super + Tab to bring up the window switcher. Release Super to select the next (highlighted) window in the switcher. Otherwise, still holding down the Super key, press Tab to cycle through the list of open windows, or Shift + Tab to cycle backwards.</p>\n</blockquote>"},{"url":"/docs/tutorials/psql-setup/","relativePath":"docs/tutorials/psql-setup.md","relativeDir":"docs/tutorials","base":"psql-setup.md","name":"psql-setup","frontmatter":{"title":"PostgreSQL Setup","weight":0,"excerpt":"PostgreSQL Setup","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>PostgreSQL Setup For Windows &#x26; WSL/Ubuntu</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://onedrive.live.com/embed?cid=D21009FDD967A241&amp;resid=D21009FDD967A241%21538624&amp;authkey=ALjsoYXNZpaUagA&amp;em=2&amp;wdAr=1.7777777777777777\" width=\"1186px\" height=\"691px\" frameborder=\"0\">This is an embedded <a target=\"_blank\" href=\"https://office.com\">Microsoft Office</a> presentation, powered by <a target=\"_blank\" href=\"https://office.com/webapps\">Office</a>.</iframe>\n<br>\n<p>If you follow this guide to a tee… you will install PostgreSQL itself on your Windows installation. Then, you will install psql in your…</p>\n<hr>\n<h3>PostgreSQL Setup For Windows &#x26; WSL/Ubuntu</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/0*mhTM08D1J612VW7J\" class=\"graf-image\" />\n</figure>If you follow this guide to a tee… you will install PostgreSQL itself on your Windows installation. Then, you will install `psql` in your Ubuntu installation. Then you will also install Postbird, a cross-platform graphical user interface that makes working with SQL and PostgreSQL 'allegedly' …(personally I prefer to just use the command line but PG Admin makes for an immeasurably more complicated tutorial than postbird)… better than just using the **command line tool** `psql`**.**\n<h3>Important Distinction: PSQL is the frontend interface for PostgreSQL … they are not synonymous!</h3>\n<p><strong>Postgres</strong>, is a <a href=\"https://en.wikipedia.org/wiki/Free_and_open-source_software\" class=\"markup--anchor markup--p-anchor\" title=\"Free and open-source software\">free and open-source</a> <a href=\"https://en.wikipedia.org/wiki/Relational_database_management_system\" class=\"markup--anchor markup--p-anchor\" title=\"Relational database management system\">relational database management system</a> (RDBMS)</p>\n<p><strong>PSQL:</strong></p>\n<p>The primary <a href=\"https://en.wikipedia.org/wiki/Front_and_back_ends\" class=\"markup--anchor markup--p-anchor\" title=\"Front and back ends\">front-end</a> for PostgreSQL is the <code class=\"language-text\">psql</code> <a href=\"https://en.wikipedia.org/wiki/Command-line_program\" class=\"markup--anchor markup--p-anchor\" title=\"Command-line program\">command-line program</a>, which can be used to enter SQL queries directly, or execute them from a file.</p>\n<p>In addition, psql provides a number of meta-commands and various shell-like features to facilitate writing scripts and automating a wide variety of tasks; for example tab completion of object names and SQL syntax.</p>\n<p><strong>pgAdmin:</strong></p>\n<p>The pgAdmin package is a free and open-source <a href=\"https://en.wikipedia.org/wiki/Graphical_user_interface\" class=\"markup--anchor markup--p-anchor\" title=\"Graphical user interface\">graphical user interface</a> (GUI) administration tool for PostgreSQL.</p>\n<p>When you read \"installation\", that means the actual OS that's running on your machine. So, you have a Windows installation, Windows 10, that's running when you boot your computer. Then, when you start the Ubuntu installation, it's as if there's a completely separate computer running inside your computer. It's like having two completely different laptops.</p>\n<h3>Other Noteworthy Distinctions:</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*um8fm6FDTYYOXZrLudddpg.png\" class=\"graf-image\" />\n</figure>### Installing PostgreSQL 12\n<p>To install PostgreSQL 12, you need to download the installer from the Internet. PostgreSQL's commercial company, Enterprise DB, offers installers for PostgreSQL for every major platform.</p>\n<p>Open <a href=\"https://www.enterprisedb.com/downloads/postgres-postgresql-downloads\" class=\"markup--anchor markup--p-anchor\">https://www.enterprisedb.com/downloads/postgres-postgresql-downloads</a>. Click the link for PostgreSQL 12 for Windows x86-64.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*wi4EbaVo-mamG_tH.png\" class=\"graf-image\" />\n</figure>Once that installer downloads, run it. You need to go through the normal steps of installing software.\n<ul>\n<li><span id=\"a223\">Yes, Windows, let the installer make changes to <em>my</em> device.</span></li>\n<li><span id=\"d4d0\">Thanks for the welcome. Next.</span></li>\n<li><span id=\"1283\">Yeah, that's a good place to install it. Next.</span></li>\n<li><span id=\"79cc\">I don't want that pgAdmin nor the Stack Builder things. Uncheck. Uncheck. Next.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*PSDmTsaD37MgFJ-A.png\" class=\"graf-image\" />\n</figure>- <span id=\"e09d\">Also, great looking directory. Thanks. Next.</span>\n<h3>Oooh! A password! I'll enter <strong>****</strong>. I sure won't forget that because, if I do, I'll have to uninstall and reinstall PostgreSQL and lose all of my hard work. <strong>Seriously, write down this password or use one you will not forget!!!!!!!!!!!!!!!</strong></h3>\n<h3>I REALLY CANNOT STRESS THE ABOVE POINT ENOUGH… Experience is a great teacher but in this case … it's not worth it.</h3>\n<ul>\n<li><span id=\"25b7\">Sure. 5432. Good to go. Next.</span></li>\n<li><span id=\"28be\">Not even sure what that means. Default! Next.</span></li>\n<li><span id=\"b378\">Yep. Looks good. Next.</span></li>\n</ul>\n<p>Insert pop culture reference to pass the time</p>\n<h3>Installing PostgreSQL Client Tools on Ubuntu</h3>\n<p>Now, to install the PostgreSQL Client tools for Ubuntu. You need to do this so that the Node.js (and later Python) programs running on your Ubuntu installation can access the PostgreSQL server running on your Windows installation. You need to tell <code class=\"language-text\">apt</code>, the package manager, that you want it to go find the PostgreSQL 12 client tools from PostgreSQL itself rather than the common package repositories. You do that by issuing the following two commands. Copy and paste them one at a time into your shell. (If your Ubuntu shell isn't running, start one.)</p>\n<p><strong>Pro-tip</strong>: Copy those commands because you're not going to type them, right? After you copy one of them, you can just right-click on the Ubuntu shell. That should paste them in there for you.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -</code></pre></div>\n<p>If prompted for your password, type it.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">echo \"deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main\" | sudo tee  /etc/apt/sources.list.d/pgdg.list</code></pre></div>\n<p>The last line of output of those two commands running should read \"OK\". If it does not, try copying and pasting them one at a time.</p>\n<p>Now that you've registered the PostgreSQL repositories as a source to look for PostgreSQL, you need to update the <code class=\"language-text\">apt</code> registry. You should do this before you install <em>any</em> software on Ubuntu.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sudo apt update</code></pre></div>\n<p>Once that's finished running, the new entries for PostgreSQL 12 should be in the repository. Now, you can install them with the following command.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sudo apt install postgresql-client-12 postgresql-common</code></pre></div>\n<p>If it asks you if you want to install them, please tell it \"Y\".</p>\n<p>Test that it installed by typing <code class=\"language-text\">psql --version</code>. You should see it print out information about the version of the installed tools. If it tells you that it can't find the command, try these instructions over.</p>\n<h3>Configuring the client tools</h3>\n<p>Since you're going to be accessing the PosgreSQL installation from your Ubuntu installation on your Windows installation, you're going to have to type that you want to access it over and over, which means extra typing. To prevent you from having to do this, you can customize your shell to always add the extra commands for you.</p>\n<p>This assumes you're still using Bash. If you changed the shell that your Ubuntu installation uses, please follow that shell's directions for adding an alias to its startup file.</p>\n<p>Make sure you're in your Ubuntu home directory. You can do that by typing <code class=\"language-text\">cd</code> and hitting enter. Use <code class=\"language-text\">ls</code> to find out if you have a <code class=\"language-text\">.bashrc</code> file. Type <code class=\"language-text\">ls .bashrc</code>. If it shows you that one exists, that's the one you will add the alias to. If it tells you that there is no file named that, then type <code class=\"language-text\">ls .profile</code>. If it shows you that one exists, that's the one you will add the alias to. If it shows you that it does not exist, then use the file name <code class=\"language-text\">.bashrc</code> in the following section.</p>\n<p>Now that you know which profile file to use, type <code class=\"language-text\">code «profile file name»</code> where \"profile file name\" is the name of the file you determined from the last section. Once Visual Studio Code starts up with your file, at the end of it (or if you've already added aliases, in that section), type the following.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">alias psql=\"psql -h localhost\"</code></pre></div>\n<p>When you run <code class=\"language-text\">psql</code> from the command line, it will now always add the part about wanting to connect to <em>localhost</em> every time. You would have to type that each time, otherwise.</p>\n<p>To make sure that you set that up correctly, type <code class=\"language-text\">psql -U postgres postgres</code>. This tells the <code class=\"language-text\">psql</code> client that you want to connect as the user \"postgres\" (<code class=\"language-text\">-U postgres</code>) to the database postgres (<code class=\"language-text\">postgres</code> at the end), which is the default database created when PostgreSQL is installed. It will prompt you for a password. Type the password that you used when you installed PostgrSQL, earlier. If the alias works correctly and you type the correct password, then you should see something like the following output.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">psql (12.2 (Ubuntu 12.2-2.pgdg18.04+1))\nType \"help\" for help.\n\npostgres=#</code></pre></div>\n<p>Type <code class=\"language-text\">\\q</code> and hit Enter to exit the PostgreSQL client tool.</p>\n<p>Now, you will add a user for your Ubuntu identity so that you don't have to specify it all the time. Then, you will create a file that PostgreSQL will use to automatically send your password every time.</p>\n<p>Copy and paste the following into your Ubuntu shell. Think of a password that you want to use for your user. <strong>Replace the password in the single quotes in the command with the password that you want.</strong> It <em>has</em> to be a non-empty string. PostgreSQL doesn't like it when it's not.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">psql -U postgres -c \"CREATE USER `whoami` WITH PASSWORD 'password' SUPERUSER\"</code></pre></div>\n<p>It should prompt you for a password. Type the password that you created when you installed PostgreSQL. Once you type the correct password, you should see \"CREATE ROLE\".</p>\n<p>Now you will create your PostgreSQL password file. Type the following into your Ubuntu shell to open Visual Studio Code and create a new file.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">code ~/.pgpass</code></pre></div>\n<p>In that file, you will add this line, which tells it that on localhost for port 5432 (where PostgreSQL is running), for all databases (*), <strong>use your Ubuntu user name and the password that you just created for that user with the</strong> <code class=\"language-text\">psql</code> <strong>command you just typed.</strong> (If you have forgotten your Ubuntu user name, type <code class=\"language-text\">whoami</code> on the command line.) Your entry in the file should have this format.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">localhost:5432:*:«your Ubuntu user name»:«the password you just used»</code></pre></div>\n<p>Once you have that information in the file, save it, and close Visual Studio Code.</p>\n<p>The last step you have to take is change the permission on that file so that it is only readable by your user. PostgreSQL will ignore it if just anyone can read and write to it. This is for <em>your</em> security. Change the file permissions so only you can read and write to it. You did this once upon a time. Here's the command.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">chmod go-rw ~/.pgpass</code></pre></div>\n<p>You can confirm that only you have read/write permission by typing <code class=\"language-text\">ls -al ~/.pgpass</code>. That should return output that looks like this, <strong>with your Ubuntu user name instead of \"web-dev-hub\".</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">-rw------- 1 web-dev-hub web-dev-hub 37 Mar 28 21:20 /home/web-dev-hub/.pgpass</code></pre></div>\n<p>Now, try connecting to PostreSQL by typing <code class=\"language-text\">psql postgres</code>. Because you added the alias to your startup script, and because you created your <strong>.pgpass</strong> file, it should now connect without prompting you for any credentials! Type <code class=\"language-text\">\\q</code> and press Enter to exit the PostgreSQL command line client.</p>\n<h3>Installing Postbird</h3>\n<p>Head over to the <a href=\"https://github.com/Paxa/postbird/releases\" class=\"markup--anchor markup--p-anchor\">Postbird releases page on GitHub</a>. Click the installer for Windows which you can recognize because it's the only file in the list that ends with \".exe\".</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ZdKurvQ4bHs3vDLT.png\" class=\"graf-image\" />\n</figure>After that installer downloads, run it. You will get a warning from Windows that this is from an unidentified developer. If you don't want to install this, find a PostgreSQL GUI client that you do trust and install it or do everything from the command line.\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*EWpFEwM0YUDQCW_i.png\" class=\"graf-image\" />\n</figure>You should get used to seeing this because many open-source applications aren't signed with the Microsoft Store for monetary and philosophical reasons.\n<p>Otherwise, if you trust Paxa like web-dev-hub and tens of thousands of other developers do, then click the link that reads \"More info\" and the \"Run anyway\" button.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*9pDpx8XsYt2KnMku.png\" class=\"graf-image\" />\n</figure>When it's done installing, it will launch itself. Test it out by typing the \"postgres\" into the \"Username\" field and the password from your installation in the \"Password\" field. Click the Connect button. It should properly connect to the running\n<p>You can close it for now. It also installed an icon on your desktop. You can launch it from there or your Start Menu at any time.</p>\n<h3>Now.. if you still have some gas in the tank… let's put our new tools to work:</h3>\n<h3>The node-postgres</h3>\n<p>The node-postgres is a collection of Node.js modules for interfacing with the PostgreSQL database. It has support for callbacks, promises, async/await, connection pooling, prepared statements, cursors, and streaming results.</p>\n<p>In our examples we also use the Ramda library. See Ramda tutorial for more information.</p>\n<h3>Setting up node-postgres</h3>\n<p>First, we install node-postgres.</p>\n<p>$ node -v\nv14.2</p>\n<p>$ npm init -y</p>\n<p>We initiate a new Node application.</p>\n<p>npm i pg</p>\n<p>We install node-postgres with <code class=\"language-text\">nmp i pg</code>.</p>\n<p>npm i ramda</p>\n<p>In addition, we install Ramda for beautiful work with data.</p>\n<p>cars.sql</p>\n<p>DROP TABLE IF EXISTS cars;</p>\n<p>CREATE TABLE cars(id SERIAL PRIMARY KEY, name VARCHAR(255), price INT);\nINSERT INTO cars(name, price) VALUES('Audi', 52642);\nINSERT INTO cars(name, price) VALUES('Mercedes', 57127);\nINSERT INTO cars(name, price) VALUES('Skoda', 9000);\nINSERT INTO cars(name, price) VALUES('Volvo', 29000);\nINSERT INTO cars(name, price) VALUES('Bentley', 350000);\nINSERT INTO cars(name, price) VALUES('Citroen', 21000);\nINSERT INTO cars(name, price) VALUES('Hummer', 41400);\nINSERT INTO cars(name, price) VALUES('Volkswagen', 21600);</p>\n<p>In some of the examples, we use this <code class=\"language-text\">cars</code> table.</p>\n<h3>The node-postgres first example</h3>\n<p>In the first example, we connect to the PostgreSQL database and return a simple SELECT query result.</p>\n<p>first.js</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const pg = require('pg');\nconst R = require('ramda');\nconst cs = 'postgres://postgres:s$cret@localhost:5432/ydb';\nconst client = new pg.Client(cs);\nclient.connect();\nclient.query('SELECT 1 + 4').then(res => {\n\nconst result = R.head(R.values(R.head(res.rows)))\n\nconsole.log(result)\n}).finally(() => client.end());</code></pre></div>\n<p>The example connects to the database and issues a SELECT statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const pg = require('pg');\nconst R = require('ramda');</code></pre></div>\n<p>We include the <code class=\"language-text\">pg</code> and <code class=\"language-text\">ramda</code> modules.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const cs = 'postgres://postgres:s$cret@localhost:5432/ydb';</code></pre></div>\n<p>This is the PostgreSQL connection string. It is used to build a connection to the database.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const client = new pg.Client(cs);\nclient.connect();</code></pre></div>\n<p>A client is created. We connect to the database with <code class=\"language-text\">connect()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">client.query('SELECT 1 + 4').then(res => {\n\nconst result = R.head(R.values(R.head(res.rows)));\n\nconsole.log(result);\n\n}).finally(() => client.end());</code></pre></div>\n<p>We issue a simple SELECT query. We get the result and output it to the console. The <code class=\"language-text\">res.rows</code> is an array of objects; we use Ramda to get the returned scalar value. In the end, we close the connection with <code class=\"language-text\">end()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">node first.js\n5</code></pre></div>\n<p>This is the output.</p>\n<h3>The node-postgres column names</h3>\n<p>In the following example, we get the columns names of a database.</p>\n<blockquote>\n<p>column_names.js</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const pg = require('pg');\n\nconst cs = 'postgres://postgres:s$cret@localhost:5432/ydb';\n\nconst client = new pg.Client(cs);\n\nclient.connect();\n\nclient.query('SELECT * FROM cars').then(res => {\n\nconst fields = res.fields.map(field => field.name);\n\nconsole.log(fields);\n\n}).catch(err => {\nconsole.log(err.stack);\n}).finally(() => {\nclient.end()\n});</code></pre></div>\n<p>The column names are retrieved with <code class=\"language-text\">res.fields</code> attribute. We also use the <code class=\"language-text\">catch</code> clause to output potential errors.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">node column_names.js\n'id', 'name', 'price'′id′,′name′,′price′</code></pre></div>\n<p>The output shows three column names of the <code class=\"language-text\">cars</code> table.</p>\n<h3>Selecting all rows</h3>\n<p>In the next example, we select all rows from the database table.</p>\n<blockquote>\n<p>all_rows.js</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const pg = require('pg');\nconst R = require('ramda');\n\nconst cs = 'postgres://postgres:s$cret@localhost:5432/ydb';\n\nconst client = new pg.Client(cs);\n\nclient.connect();\n\nclient.query('SELECT * FROM cars').then(res => {\n\nconst data = res.rows;\n\nconsole.log('all data');\ndata.forEach(row => {\n    console.log(\\`Id: ${row.id} Name: ${row.name} Price: ${row.price}\\`);\n})\n\nconsole.log('Sorted prices:');\nconst prices = R.pluck('price', R.sortBy(R.prop('price'), data));\nconsole.log(prices);\n\n}).finally(() => {\nclient.end()\n});</code></pre></div>\n<p><strong>TBC…</strong></p>\n<h4>If you found this guide helpful feel free to checkout my github/gists where I host similar content:</h4>\n<p><a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--p-anchor\">bgoonz's gists · GitHub</a></p>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>Or Checkout my personal Resource Site:</p>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonz-blog.netlify.app/\">\n<strong>Stackbit Web-Dev-HubTheme</strong>\n<br />\n<em>Memoization, Tabulation, and Sorting Algorithms by Example Why is looking at runtime not a reliable method of…</em>bgoonz-blog.netlify.app</a>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/801672ab7089\">March 6, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/postgresql-setup-for-windows-wsl-ubuntu-801672ab7089\" class=\"p-canonical\">Canonical link</a></p>\n<p>August 6, 2021.</p>"},{"url":"/docs/about/portfolio/","relativePath":"docs/about/portfolio/index.md","relativeDir":"docs/about/portfolio","base":"index.md","name":"index","frontmatter":{"title":"Portfolio ","template":"docs","excerpt":"Eng portfolio "},"html":"<p>Hi</p>"},{"url":"/docs/tutorials/webdev-review/","relativePath":"docs/tutorials/webdev-review.md","relativeDir":"docs/tutorials","base":"webdev-review.md","name":"webdev-review","frontmatter":{"title":"Web Dev Review","sections":[],"seo":{"title":"","description":"Review-Of-Previous-Concepts","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<hr>\n<h2>description: Review</h2>\n<h1>Review-Of-Previous-Concepts</h1>\n<h3>Review of Concepts</h3>\n<h3>Running JS Locally Concepts</h3>\n<ul>\n<li>\n<p>Match the commands <code class=\"language-text\">ls</code>, <code class=\"language-text\">cd</code>, <code class=\"language-text\">pwd</code> to their descriptions</p>\n<ul>\n<li><code class=\"language-text\">ls</code> lists contents of current directory</li>\n<li>\n<p><code class=\"language-text\">cd</code> changes current directory</p>\n<ul>\n<li><code class=\"language-text\">cd ..</code> takes you up one level</li>\n<li><code class=\"language-text\">cd</code> alone takes you back home</li>\n</ul>\n</li>\n<li><code class=\"language-text\">pwd</code> returns current directory</li>\n</ul>\n</li>\n<li>Given a folder structure diagram, a list of 'cd (path)' commands and target files, match the paths to the target files.</li>\n<li>Use VSCode to create a folder. Within the folder create a .js file containing <code class=\"language-text\">console.log('hello new world');</code> and save it.</li>\n<li>Use node to execute a JavaScript file in the terminal</li>\n</ul>\n<h3>Plain Old JS Object Lesson Concepts</h3>\n<ul>\n<li>\n<p>Label variables as either Primitive vs. Reference</p>\n<ul>\n<li>\n<p>primitives: strings, booleans, numbers, null and undefined</p>\n<ul>\n<li>primitives are immutable</li>\n</ul>\n</li>\n<li>\n<p>refereces: objects (including arrays)</p>\n<ul>\n<li>references are mutable</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p>Identify when to use <code class=\"language-text\">.</code> vs <code class=\"language-text\">[]</code> when accessing values of an object</p>\n<ul>\n<li>\n<p>dot syntax <code class=\"language-text\">object.key</code></p>\n<ul>\n<li>easier to read</li>\n<li>easier to write</li>\n<li>cannot use variables as keys</li>\n<li>keys cannot begin with a number</li>\n</ul>\n</li>\n<li>\n<p>bracket notation <code class=\"language-text\">object[\"key]</code></p>\n<ul>\n<li>allows variables as keys</li>\n<li>strings that start with numbers can be use as keys</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p>Write an object literal with a variable key using interpolation</p>\n<ul>\n<li>\n<p>put it in brackets to access the value of the variable, rather than just make the value that string</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> a <span class=\"token operator\">=</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token string\">'letter_a'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token string\">'letter b'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n</ul>\n</li>\n<li>Use the <code class=\"language-text\">obj[key] !== undefined</code> pattern to check if a given variable that contains a key exists in an object</li>\n<li>\n<ul>\n<li>can also use <code class=\"language-text\">(key in object)</code> syntax interchangeably (returns a boolean)</li>\n</ul>\n</li>\n<li>\n<p>Utilize Object.keys and Object.values in a function</p>\n<ul>\n<li><code class=\"language-text\">Object.keys(obj)</code> returns an array of all the keys in <code class=\"language-text\">obj</code></li>\n<li><code class=\"language-text\">Object.values(obj)</code> returns an array of the values in <code class=\"language-text\">obj</code></li>\n</ul>\n</li>\n<li>\n<p>Iterate through an object using a <code class=\"language-text\">for in</code> loop</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">printValues</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">obj</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> key <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> value <span class=\"token operator\">=</span> obj<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>Define a function that utilizes <code class=\"language-text\">...rest</code> syntax to accept an arbitrary number of arguments</p>\n<ul>\n<li><code class=\"language-text\">...rest</code> syntax will store all additional arguments in an array</li>\n<li>\n<p>array will be empty if there are no additional arguments</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myFunction</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">str<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>strs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The first string is '</span> <span class=\"token operator\">+</span> str<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The rest of the strings are:'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    strs<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">str</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n</ul>\n</li>\n</ul>\n<h3></h3>\n<ul>\n<li>\n<p>Use <code class=\"language-text\">...spread</code> syntax for Object literals and Array literals</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> arr1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> longer <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>arr1<span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'e'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [\"a\", \"b\", \"c\", \"d\", \"e\"]</span>\n<span class=\"token comment\">// without spread syntax, this would give you a nested array</span>\n<span class=\"token keyword\">let</span> withoutRest <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>arr1<span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'e'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [[\"a\", \"b\", \"c\"], \"d\", \"e\"]</span></code></pre></div>\n</li>\n<li>\n<p>Destructure an array to reference specific elements</p>\n<p>```javascript</p>\n<p>let array = [35,9];</p>\n<p>let [firstEl, secondEl] = array;</p>\n<p>console.log(firstEl); // => 35</p>\n<p>console.log(secondEl); // => 9</p>\n</li>\n</ul>\n<p>// can also destructure using ... syntax let array = [35,9,14]; let [head, ...tail] = array; console.log(head); // => 35 console.log(tail); // => [9, 14]</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">-</span> Destructure an object to reference specific values\n   <span class=\"token operator\">-</span> <span class=\"token keyword\">if</span> you want to use variable names that don't match the keys<span class=\"token punctuation\">,</span> you can use aliasing\n      <span class=\"token operator\">-</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">let { oldkeyname: newkeyname } = object</span><span class=\"token template-punctuation string\">`</span></span>\n   <span class=\"token operator\">-</span> rule <span class=\"token keyword\">of</span> thumb—only destructure values from objects that are two levels deep\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Wilfred\"</span><span class=\"token punctuation\">,</span>\n   <span class=\"token literal-property property\">appearance</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"short\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"mustache\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n   <span class=\"token literal-property property\">favorites</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">\"mauve\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">food</span><span class=\"token operator\">:</span> <span class=\"token string\">\"spaghetti squash\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">number</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span>\n   <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// with variable names that match keys</span>\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span> name<span class=\"token punctuation\">,</span> appearance <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> obj<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"Wilfred\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>appearance<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [\"short\", \"mustache\"]</span>\n\n<span class=\"token comment\">// with new variable names (aliasing)</span>\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> myName<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">appearance</span><span class=\"token operator\">:</span> myAppearance<span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> obj<span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"Wilfred\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myAppearance<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [\"short\", \"mustache\"]</span>\n\n<span class=\"token comment\">// in a function call</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">sayHello</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello, \"</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"Hello Wilfred\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// nested objects + aliasing</span>\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">favorites</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>color<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">food</span><span class=\"token operator\">:</span> vegetable<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> obj<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>color<span class=\"token punctuation\">,</span> vegetable<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//=> mauve spaghetti squash</span></code></pre></div>\n<ul>\n<li>\n<p>Write a function that accepts a array as an argument and returns an object representing the count of each character in the array</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">elementCounts</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">el</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>el <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">)</span> obj<span class=\"token punctuation\">[</span>el<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">else</span> obj<span class=\"token punctuation\">[</span>el<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> obj<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">elementCounts</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'e'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'g'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'f'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => Object {e: 1, f: 2, g: 1}</span></code></pre></div>\n</li>\n</ul>\n<h3>Callbacks Lesson Concepts</h3>\n<ul>\n<li>\n<p>Given multiple plausible reasons, identify why functions are called \"First Class Objects\" in JavaScript.</p>\n<ul>\n<li>they can be stored in variables, passed as arguments to other functions, and serve as return value for a function</li>\n<li>supports same basic operations as other types (strings, bools, numbers)</li>\n<li>higher-order functions take functions as arguments or return functions as values</li>\n</ul>\n</li>\n<li>Given a code snippet containing an anonymous callback, a named callback, and multiple <code class=\"language-text\">console.log</code>s, predict what will be printed</li>\n<li>\n<ul>\n<li>what is this referring to?</li>\n</ul>\n</li>\n<li>Write a function that takes in a value and two callbacks. The function should return the result of the callback that is greater.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">greaterCB</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">val<span class=\"token punctuation\">,</span> callback1<span class=\"token punctuation\">,</span> callback2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">callback1</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> <span class=\"token function\">callback2</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">callback1</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">callback2</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">greaterCB</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">val<span class=\"token punctuation\">,</span> callback1<span class=\"token punctuation\">,</span> callback2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">callback1</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> <span class=\"token function\">callback2</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">callback1</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">callback2</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>// shorter version let greaterCB = function(val, callback1, callback2) { return Math.max(callback1(val), callback2(val)); } // even shorter, cause why not let greaterCB = (val, cb1, cb2) => Math.max(cb1(val), cb2(val));</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">-</span> Write a <span class=\"token keyword\">function</span><span class=\"token punctuation\">,</span> myMap<span class=\"token punctuation\">,</span> that takes <span class=\"token keyword\">in</span> an array and a callback <span class=\"token keyword\">as</span> arguments<span class=\"token punctuation\">.</span> The <span class=\"token keyword\">function</span> should mimic the behavior <span class=\"token keyword\">of</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Array#map</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">.</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myMap</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> newArr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i <span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      mapped <span class=\"token operator\">=</span> <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      newArr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>mapped<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> newArr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span> <span class=\"token function\">myMap</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">16</span><span class=\"token punctuation\">,</span><span class=\"token number\">25</span><span class=\"token punctuation\">,</span><span class=\"token number\">36</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span>sqrt<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => [4, 5, 6];</span>\n\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myMapArrow</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> newArr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">ele<span class=\"token punctuation\">,</span> ind<span class=\"token punctuation\">,</span> array</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      newArr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>ele<span class=\"token punctuation\">,</span> ind<span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n   <span class=\"token keyword\">return</span> newArr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">myMapArrow</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">16</span><span class=\"token punctuation\">,</span><span class=\"token number\">25</span><span class=\"token punctuation\">,</span><span class=\"token number\">36</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span>sqrt<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => [4, 5, 6];</span></code></pre></div>\n<ul>\n<li>\n<p>Write a function, myFilter, that takes in an array and a callback as arguments. The function should mimic the behavior of <code class=\"language-text\">Array#filter</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myFilter</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> filtered <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            filtered<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>Write a function, myEvery, that takes in an array and a callback as arguments. The function should mimic the behavior of <code class=\"language-text\">Array#every</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myEvery</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// with arrow function syntax</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">myEvery</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n</ul>\n<h3>Scope Lesson Concepts</h3>\n<ul>\n<li>\n<p>Identify the difference between <code class=\"language-text\">const</code>, <code class=\"language-text\">let</code>, and <code class=\"language-text\">var</code> declarations</p>\n<ul>\n<li><code class=\"language-text\">const</code> - cannot reassign variable, scoped to block</li>\n<li><code class=\"language-text\">let</code> - can reassign variable, scoped to block</li>\n<li><code class=\"language-text\">var</code> - outdated, may or may not be reassigned, scoped to function. can be not just reassigned, but also redeclared!</li>\n<li>a variable will always evaluate to the value it contains regardless of how it was declared</li>\n</ul>\n</li>\n<li>\n<p>Explain the difference between <code class=\"language-text\">const</code>, <code class=\"language-text\">let</code>, and <code class=\"language-text\">var</code> declarations</p>\n<ul>\n<li>\n<p><code class=\"language-text\">var</code> is function scoped—so if you declare it anywhere in a function, the declaration (but not assignment) is \"hoisted\"</p>\n<ul>\n<li>so it will exist in memory as \"undefined\" which is bad and unpredictable</li>\n</ul>\n</li>\n<li><code class=\"language-text\">var</code> will also allow you to redeclare a variable, while <code class=\"language-text\">let</code> or <code class=\"language-text\">const</code> will raise a syntax error. you shouldn't be able to do that!</li>\n<li><code class=\"language-text\">const</code> won't let you reassign a variable, but if it points to a mutable object, you will still be able to change the value by mutating the object</li>\n<li>block-scoped variables allow new variables with the same name in new scopes</li>\n<li>block-scoped still performs hoisting of all variables within the block, but it doesn't initialize to the value of <code class=\"language-text\">undefined</code> like <code class=\"language-text\">var</code> does, so it throws a specific reference error if you try to access the value before it has been declared</li>\n<li>\n<p>if you do not use <code class=\"language-text\">var</code> or <code class=\"language-text\">let</code> or <code class=\"language-text\">const</code> when initializing, it will be declared as global—THIS IS BAD</p>\n<ul>\n<li>if you assign a value without a declaration, it exists in the global scope (so then it would be accessible by all outer scopes, so bad). however, there's no hoisting, so it doesn't exist in the scope until after the line is run</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p>Predict the evaluation of code that utilizes function scope, block scope, lexical scope, and scope chaining</p>\n<ul>\n<li>scope of a program means the set of variables that are available for use within the program</li>\n<li>\n<p>global scope is represented by the <code class=\"language-text\">window</code> object in the browser and the <code class=\"language-text\">global</code> object in Node.js</p>\n<ul>\n<li>global variables are available everywhere, and so increase the risk of name collisions</li>\n</ul>\n</li>\n<li>\n<p>local scope is the set of variables available for use within the function</p>\n<ul>\n<li>when we enter a function, we enter a new scope</li>\n<li>includes functions arguments, local variables declared inside function, and any variables that were already declared when the function is defined (hmm about that last one)</li>\n</ul>\n</li>\n<li>for blocks (denoted by curly braces <code class=\"language-text\">{}</code>, as in conditionals or <code class=\"language-text\">for</code> loops), variables can be block scoped</li>\n<li>\n<p>inner scope does not have access to variables in the outer scope</p>\n<ul>\n<li>scope chaining—if a given variable is not found in immediate scope, javascript will search all accessible outer scopes until variable is found</li>\n<li>so an inner scope can access outer scope variables</li>\n<li>but an outer scope can never access inner scope variables</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p>Define an arrow function</p>\n<p>```javascript</p>\n<p>let arrowFunction = (param1, param2) => {</p>\n<p>let sum = param1 + param2;</p>\n<p>return sum;</p>\n<p>}</p>\n</li>\n</ul>\n<p>// with 1 param you can remove parens around parameters let arrowFunction = param => { param += 1; return param; }</p>\n<p>// if your return statement is one line, you can use implied return let arrowFunction = param => param + 1;</p>\n<p>// you don't have to assign to variable, can be anonymous // if you never need to use it again param => param + 1;</p>\n<p>```</p>\n<ul>\n<li>\n<p>Given an arrow function, deduce the value of <code class=\"language-text\">this</code> without executing the code</p>\n<ul>\n<li>arrow functions are automatically bound to the context they were declared in</li>\n<li>unlike regular function which use the context they are invoked in (unless they have been bound using <code class=\"language-text\">Function#bind</code>)</li>\n<li>if you implement an arrow function as a method in an object the context it will be bound to is NOT the object itself, but the global context</li>\n<li>\n<p>so you can't use an arrow function to define a method directly</p>\n<p>```javascript</p>\n<p>let obj = {</p>\n<p>name: \"my object\",</p>\n<p>unboundFunc: function () {</p>\n<p>return this.name;</p>\n<p>// this function will be able to be called on different objects</p>\n<p>},</p>\n</li>\n</ul>\n</li>\n</ul>\n<h3></h3>\n<p>boundToGlobal: () => { return this.name; // this function, no matter how you call it, will be called // on the global object, and it cannot be rebound // this is because it was defined using arrow syntax },</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function-variable function\">makeFuncBoundToObj</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">// this function will return a function that will be bound</span>\n    <span class=\"token comment\">// to the object where we call the outer method</span>\n    <span class=\"token comment\">// because the arrow syntax is nested inside one of this</span>\n    <span class=\"token comment\">// function's methods, it cannot be rebound</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">makeUnboundFunc</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">//this function will return a function that will still be unbound</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">immediatelyInvokedFunc</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token comment\">// this property will be set to the return value of this anonymous function,</span>\n<span class=\"token comment\">// which is invoked during the object definition;</span>\n<span class=\"token comment\">// basically, it's a way to check the context inside of an object, at this moment</span>\n\n<span class=\"token literal-property property\">innerObj</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"inner object\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">innerArrowFunc</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>  <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token comment\">// the context inside a nested object is not the parent, it's still</span>\n    <span class=\"token comment\">// the global object. entering an object definition doesn't change the context</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token keyword\">let</span> otherObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"my other object\"</span> <span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// call unboundFunc on obj, we get \"my object\" console.log(\"unboundFunc: \", obj.unboundFunc()); // => \"my object\" // assign unboundFunc to a variable and call it let newFunc = obj.unboundFunc; // this newFunc will default to being called on global object console.log(\"newFunc: \",newFunc()); // => undefined // but you could bind it directly to a different object if you wanted console.log(\"newFunc: \", newFunc.bind(otherObj)()); // \"my other object\"</span>\n<span class=\"token comment\">// meanwhile, obj.boundToGlobal will only ever be called on global object console.log(\"boundToGlobal: \", obj.boundToGlobal()); //=> undefined let newBoundFunc = obj.boundToGlobal; console.log(\"newBoundFunc: \", newBoundFunc()); // => undefined // even if you try to directly bind to another object, it won't work! console.log(\"newBoundFunc: \", newBoundFunc.bind(otherObj)()); // => undefined</span>\n<span class=\"token comment\">// let's make a new function that will always be bound to the context // where we call our function maker let boundFunc = obj.makeFuncBoundToObj();// note that we're invoking, not just assigning console.log(\"boundFunc: \", boundFunc()); // => \"my object\" // we can't rebind this function console.log(\"boundFunc: \", boundFunc.bind(otherObj)()) // =>\"my object\"</span>\n<span class=\"token comment\">// but if I call makeFuncBoundToObj on another context // the new bound function is stuck with that other context let boundToOther = obj.makeFuncBoundToObj.bind(otherObj)(); console.log(\"boundToOther: \", boundToOther()); // => \"my other object\" console.log(\"boundToOther: \", boundToOther.bind(obj)()) // \"my other object\"</span>\n<span class=\"token comment\">// the return value of my immediately invoked function // shows that the context inside of the object is the // global object, not the object itself // context only changes inside a function that is called // on an object console.log(\"immediatelyInvokedFunc: \", obj.immediatelyInvokedFunc); // => undefined</span>\n<span class=\"token comment\">// even though we're inside a nested object, the context is // still the same as it was outside the outer object // in this case, the global object console.log(\"innerArrowFunc: \", obj.innerObj.innerArrowFunc()); // => undefined</span></code></pre></div>\n<p>}</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">-</span> Implement a closure and explain how the closure effects scope\n   <span class=\"token operator\">-</span> a closure is <span class=\"token string\">\"the combination of a function and the lexical environment within which that function was declared\"</span>\n      <span class=\"token operator\">-</span> alternatively<span class=\"token punctuation\">,</span> <span class=\"token string\">\"when an inner function uses or changes variables in an outer function\"</span>\n   <span class=\"token operator\">-</span> closures have access to any variables within their own scope <span class=\"token operator\">+</span> scope <span class=\"token keyword\">of</span> outer functions <span class=\"token operator\">+</span> global scope — the <span class=\"token keyword\">set</span> <span class=\"token keyword\">of</span> all these available variables is <span class=\"token string\">\"lexical environemnt\"</span>\n   <span class=\"token operator\">-</span> closure keeps reference to all variables <span class=\"token operator\">**</span>even <span class=\"token keyword\">if</span> the outer <span class=\"token keyword\">function</span> has returned<span class=\"token operator\">**</span>\n      <span class=\"token operator\">-</span> each <span class=\"token keyword\">function</span> has a <span class=\"token keyword\">private</span> mutable state that cannot be accessed externally\n      <span class=\"token operator\">-</span> the inner <span class=\"token keyword\">function</span> will maintain a reference to the scope <span class=\"token keyword\">in</span> which it was declared<span class=\"token punctuation\">.</span> so it has access to variables that were initialized <span class=\"token keyword\">in</span> any outer scope—even <span class=\"token keyword\">if</span> that scope\n      <span class=\"token operator\">-</span> <span class=\"token keyword\">if</span> a variable exists <span class=\"token keyword\">in</span> the scope <span class=\"token keyword\">of</span> what could have been accessed by a <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">.</span>g<span class=\"token punctuation\">.</span> global scope<span class=\"token punctuation\">,</span> outer <span class=\"token keyword\">function</span><span class=\"token punctuation\">,</span> etc</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> does that variable wind up <span class=\"token keyword\">in</span> the closure even <span class=\"token keyword\">if</span> it never got accessed<span class=\"token operator\">?</span>\n      <span class=\"token operator\">-</span> <span class=\"token keyword\">if</span> you change the value <span class=\"token keyword\">of</span> a <span class=\"token function\">variable</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>g<span class=\"token punctuation\">.</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> you will change the value <span class=\"token keyword\">of</span> that variable <span class=\"token keyword\">in</span> the scope that it was declared <span class=\"token keyword\">in</span>\n\n<span class=\"token operator\">--</span><span class=\"token operator\">-</span>\n\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">createCounter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token comment\">// this function starts a counter at 0, then returns a</span>\n   <span class=\"token comment\">// new function that can access and change that counter</span>\n   <span class=\"token comment\">//</span>\n   <span class=\"token comment\">// each new counter you create will have a single internal</span>\n   <span class=\"token comment\">// state, that can be changed only by calling the function.</span>\n   <span class=\"token comment\">// you can't access that state from outside of the function,</span>\n   <span class=\"token comment\">// even though the count variable in question is initialized</span>\n   <span class=\"token comment\">// by the outer function, and it remains accessible to the</span>\n   <span class=\"token comment\">// inner function after the outer function returns.</span>\n   <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      count <span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">return</span> count<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token function\">createCounter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">counter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//=> 1</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">counter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//=> 2</span>\n<span class=\"token comment\">// so the closure here comes into play because</span>\n<span class=\"token comment\">// an inner function is accessing and changing</span>\n<span class=\"token comment\">// a variable from an outer function</span>\n\n<span class=\"token comment\">// the closure is the combination of the counter</span>\n<span class=\"token comment\">// function and the all the variables that existed</span>\n<span class=\"token comment\">// in the scope that it was declared in. because</span>\n<span class=\"token comment\">// inner blocks/functions have access to outer</span>\n<span class=\"token comment\">// scopes, that includes the scope of the outer</span>\n<span class=\"token comment\">// function.</span>\n\n<span class=\"token comment\">// so counter variable is a closure, in that</span>\n<span class=\"token comment\">// it contains the inner count value that was</span>\n<span class=\"token comment\">// initialized by the outer createCounter() function</span>\n<span class=\"token comment\">// count has been captured or closed over</span>\n\n<span class=\"token comment\">// this state is private, so if i run createCounter again</span>\n<span class=\"token comment\">// i get a totally separate count that doesn't interact</span>\n<span class=\"token comment\">// with the previous one and each of the new functions</span>\n<span class=\"token comment\">// will have their own internal state based on the</span>\n<span class=\"token comment\">// initial declaration in the now-closed outer function</span>\n\n<span class=\"token keyword\">let</span> counter2 <span class=\"token operator\">=</span> <span class=\"token function\">createCounter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">counter2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 1</span>\n\n<span class=\"token comment\">// if i set a new function equal to my existing counter</span>\n<span class=\"token comment\">// the internal state is shared with the new function</span>\n<span class=\"token keyword\">let</span> counter3 <span class=\"token operator\">=</span> counter2<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">counter3</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>\n<p>Define a method that references <code class=\"language-text\">this</code> on an object literal</p>\n<ul>\n<li>\n<p>when we use <code class=\"language-text\">this</code> in a method it refers to the object that the method is invoked on</p>\n<ul>\n<li>it will let you access other pieces of information from within that object, or even other methods</li>\n<li>method style invocation - <code class=\"language-text\">object.method(args)</code> (e.g. built in examples like <code class=\"language-text\">Array#push</code>, or <code class=\"language-text\">String#toUpperCase</code>)</li>\n</ul>\n</li>\n<li>context is set every time we invoke a function</li>\n<li>function style invocation sets the context to the global object no matter what</li>\n<li>being inside an object does not make the context that object! you still have to use method-style invocation</li>\n</ul>\n</li>\n<li>\n<p>Utilize the built in <code class=\"language-text\">Function#bind</code> on a callback to maintain the context of this</p>\n<ul>\n<li>when we call bind on a function, we get an exotic function back—so the context will always be the same for that new function</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cat = {\npurr: function () {\nconsole.log(\"meow\");\n},\npurrMore: function () {\nthis.purr();\n},\n};\nlet sayMeow = cat.purrMore; console.log(sayMeow()); // TypeError: this.purr is not a function\n\n// we can use the built in Function.bind to ensure our context, our this, // is the cat object let boundCat = sayMeow.bind(cat);\nboundCat(); // prints \"meow\"</code></pre></div>\n<p>``</p>\n</li>\n</ul>\n<h3></h3>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token operator\">-</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">bind</span><span class=\"token template-punctuation string\">`</span></span> can also work <span class=\"token keyword\">with</span> arguments<span class=\"token punctuation\">,</span> so you can have a version <span class=\"token keyword\">of</span> a <span class=\"token keyword\">function</span> <span class=\"token keyword\">with</span> particular arguments and a particular context<span class=\"token punctuation\">.</span> the first arg will be the context aka the <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">this</span><span class=\"token template-punctuation string\">`</span></span> you want it to use<span class=\"token punctuation\">.</span> the next arguments will be the functions arguments that you are binding\n      <span class=\"token operator\">-</span> <span class=\"token keyword\">if</span> you just want to bind it to those arguments <span class=\"token keyword\">in</span> particular<span class=\"token punctuation\">,</span> you can use <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">null</span><span class=\"token template-punctuation string\">`</span></span> <span class=\"token keyword\">as</span> the first argument<span class=\"token punctuation\">,</span> so the context won't be bound<span class=\"token punctuation\">,</span> just the arguments\n<span class=\"token operator\">-</span> Given a code snippet<span class=\"token punctuation\">,</span> identify what <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">this</span><span class=\"token template-punctuation string\">`</span></span> refers to\n   <span class=\"token operator\">-</span> important to recognize the difference between scope and context\n      <span class=\"token operator\">-</span> scope works like a dictionary that has all the variables that are available within a given block<span class=\"token punctuation\">,</span> plus a pointer back the next outer <span class=\"token function\">scope</span> <span class=\"token punctuation\">(</span>which itself has pointers to <span class=\"token keyword\">new</span> <span class=\"token class-name\">scopes</span> until you reach the global scope<span class=\"token punctuation\">.</span> so you can think about a whole given block's scope <span class=\"token keyword\">as</span> a kind <span class=\"token keyword\">of</span> linked list <span class=\"token keyword\">of</span> dictionaries<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">(</span>also<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span> is not to say that scope is actually implemented <span class=\"token keyword\">in</span> <span class=\"token keyword\">this</span> way<span class=\"token punctuation\">,</span> that is just the schema that i can use to understand it<span class=\"token punctuation\">)</span>\n      <span class=\"token operator\">-</span> context refers to the value <span class=\"token keyword\">of</span> the <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">this</span><span class=\"token template-punctuation string\">`</span></span> keyword\n   <span class=\"token operator\">-</span> the keyword <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">this</span><span class=\"token template-punctuation string\">`</span></span> exists <span class=\"token keyword\">in</span> every <span class=\"token keyword\">function</span> and it evaluates to the object that is currently invoking that <span class=\"token keyword\">function</span>\n   <span class=\"token operator\">-</span> so the context is fairly straightforward when we talk about methods being called on specific objects\n   <span class=\"token operator\">-</span> you could<span class=\"token punctuation\">,</span> however<span class=\"token punctuation\">,</span> call an object's method on something other than that object<span class=\"token punctuation\">,</span> and then <span class=\"token keyword\">this</span> would refer to the context where<span class=\"token operator\">/</span>how it was called<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>g<span class=\"token punctuation\">.</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> dog <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Bowser\"</span><span class=\"token punctuation\">,</span>\n   <span class=\"token function-variable function\">changeName</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">\"Layla\"</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// note this is **not invoked** - we are assigning the function itself</span>\n<span class=\"token keyword\">let</span> change <span class=\"token operator\">=</span> dog<span class=\"token punctuation\">.</span>changeName<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">change</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// undefined</span>\n\n<span class=\"token comment\">// our dog still has the same name</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>dog<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// { name: 'Bowser', changeName: [Function: changeName] }</span>\n\n<span class=\"token comment\">// instead of changing the dog we changed the global name!!!</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Object [global] {etc, etc, etc,  name: 'Layla'}</span></code></pre></div>\n<ul>\n<li>\n<p>CALLING SOMETHING IN THE WRONG CONTEXT CAN MESS YOU UP!</p>\n<ul>\n<li>could throw an error if it expects this to have some other method or whatever that doesn't exist</li>\n<li>you could also overwrite values or assign values to exist in a space where they should not exist</li>\n</ul>\n</li>\n<li>\n<p>if you call a function as a callback, it will set <code class=\"language-text\">this</code> to be the outer function itself, even if the function you were calling is a method that was called on a particular object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cat = {\npurr: function () {\nconsole.log(\"meow\");\n},\npurrMore: function () {\nthis.purr();\n},\n};\nglobal.setTimeout(cat.purrMore, 5000); // 5 seconds later: TypeError: this.purr is not a function</code></pre></div>\n</li>\n</ul>\n<p>we can use strict mode with <code class=\"language-text\">\"use strict\";</code> this will prevent you from accessing the global object with <code class=\"language-text\">this</code> in functions, so if you try to call <code class=\"language-text\">this</code> in the global context and change a value, you will get a type error, and the things you try to access will be undefined</p>\n<h3></h3>\n<p>let sayMeow = cat.purrMore; console.log(sayMeow()); // TypeError: this.purr is not a function</p>\n<p>// we can use the built in Function.bind to ensure our context, our <code class=\"language-text\">this</code>, // is the cat object let boundCat = sayMeow.bind(cat);</p>\n<p>boundCat(); // prints \"meow\"</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">   - `bind` can also work with arguments, so you can have a version of a function with particular arguments and a particular context. the first arg will be the context aka the `this` you want it to use. the next arguments will be the functions arguments that you are binding\n      - if you just want to bind it to those arguments in particular, you can use `null` as the first argument, so the context won't be bound, just the arguments\n- Given a code snippet, identify what `this` refers to\n   - important to recognize the difference between scope and context\n      - scope works like a dictionary that has all the variables that are available within a given block, plus a pointer back the next outer scope (which itself has pointers to new scopes until you reach the global scope. so you can think about a whole given block's scope as a kind of linked list of dictionaries) (also, this is not to say that scope is actually implemented in this way, that is just the schema that i can use to understand it)\n      - context refers to the value of the `this` keyword\n   - the keyword `this` exists in every function and it evaluates to the object that is currently invoking that function\n   - so the context is fairly straightforward when we talk about methods being called on specific objects\n   - you could, however, call an object's method on something other than that object, and then this would refer to the context where/how it was called, e.g.\n```js\n//\nlet dog = {\n   name: \"Bowser\",\n   changeName: function () {\n      this.name = \"Layla\";\n  },\n};\n\n// note this is **not invoked** - we are assigning the function itself\nlet change = dog.changeName;\nconsole.log(change()); // undefined\n\n// our dog still has the same name\nconsole.log(dog); // { name: 'Bowser', changeName: [Function: changeName] }\n\n// instead of changing the dog we changed the global name!!!\nconsole.log(this); // Object [global] {etc, etc, etc,  name: 'Layla'}</code></pre></div>\n<ul>\n<li>\n<p>CALLING SOMETHING IN THE WRONG CONTEXT CAN MESS YOU UP!</p>\n<ul>\n<li>could throw an error if it expects this to have some other method or whatever that doesn't exist</li>\n<li>you could also overwrite values or assign values to exist in a space where they should not exist</li>\n</ul>\n</li>\n<li>\n<p>if you call a function as a callback, it will set <code class=\"language-text\">this</code> to be the outer function itself, even if the function you were calling is a method that was called on a particular object</p>\n<p>```javascript</p>\n<p>let cat = {</p>\n<p>purr: function () {</p>\n<p>console.log(\"meow\");</p>\n<p>},</p>\n<p>purrMore: function () {</p>\n<p>this.purr();</p>\n<p>},</p>\n<p>};</p>\n</li>\n</ul>\n<p>global.setTimeout(cat.purrMore, 5000); // 5 seconds later: TypeError: this.purr is not a function</p>\n<p>```</p>\n<ul>\n<li>we can use strict mode with <code class=\"language-text\">\"use strict\";</code> this will prevent you from accessing the global object with <code class=\"language-text\">this</code> in functions, so if you try to call <code class=\"language-text\">this</code> in the global context and change a value, you will get a type error, and the things you try to access will be undefined</li>\n</ul>\n<h3>POJOs</h3>\n<h4>1. Label variables as either Primitive vs. Reference</h4>\n<p>Javascript considers most data types to be 'primitive', these data types are immutable, and are passed by value. The more complex data types: Array and Object are mutable, are considered 'reference' data types, and are passed by reference.</p>\n<ul>\n<li>Boolean - Primitive</li>\n<li>Null - Primitive</li>\n<li>Undefined - Primitive</li>\n<li>Number - Primitive</li>\n<li>String - Primitive</li>\n<li>Array - Reference</li>\n<li>Object - Reference</li>\n<li>Function - Reference</li>\n</ul>\n<h4>2. Identify when to use . vs [] when accessing values of an object</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">one</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">two</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Choose the square brackets property accessor when the property name is determined at</span>\n<span class=\"token comment\">// runtime, or if the property name is not a valid identifier</span>\n<span class=\"token keyword\">let</span> myKey <span class=\"token operator\">=</span> <span class=\"token string\">'one'</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">[</span>myKey<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Choose the dot property accessor when the property name is known ahead of time.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span>two<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>3. Write an object literal with a variable key using interpolation</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> keyName <span class=\"token operator\">=</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// If the key is not known, you can use an alternative `[]` syntax for</span>\n<span class=\"token comment\">// object initialization only</span>\n<span class=\"token keyword\">let</span> obj2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>keyName<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>4. Use the obj[key] !== undefined pattern to check if a given variable that contains a key exists in an object</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">doesKeyExist</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">obj<span class=\"token punctuation\">,</span> key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// obj[key] !== undefined</span>\n    <span class=\"token comment\">// or:</span>\n    <span class=\"token keyword\">return</span> key <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> course <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">bootcamp</span><span class=\"token operator\">:</span> <span class=\"token string\">'Lambda'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">course</span><span class=\"token operator\">:</span> <span class=\"token string\">'Bootcamp Prep'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">doesKeyExist</span><span class=\"token punctuation\">(</span>course<span class=\"token punctuation\">,</span> <span class=\"token string\">'course'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">doesKeyExist</span><span class=\"token punctuation\">(</span>course<span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => false</span></code></pre></div>\n<h4>5. Utilize Object.keys and Object.values in a function</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">printKeys</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">object</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">printValues</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">object</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">printKeys</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">dog</span><span class=\"token operator\">:</span> <span class=\"token string\">'Strelka'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">dog2</span><span class=\"token operator\">:</span> <span class=\"token string\">'Belka'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">printValues</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">dog</span><span class=\"token operator\">:</span> <span class=\"token string\">'Strelka'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">dog2</span><span class=\"token operator\">:</span> <span class=\"token string\">'Belka'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>6. Iterate through an object using a for in loop</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> player <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Sergey'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">skill</span><span class=\"token operator\">:</span> <span class=\"token string\">'hockey'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> key <span class=\"token keyword\">in</span> player<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> player<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span>player<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>7. Define a function that utilizes ...rest syntax to accept an arbitrary number of arguments</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">restSum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>otherNums</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> sum <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>otherNums<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    otherNums<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">num</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        sum <span class=\"token operator\">+=</span> num<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> sum<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">restSum</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 14</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">restSum</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 45</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">restSum</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 0</span></code></pre></div>\n<h4>8. Use ...spread syntax for Object literals and Array literals</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> numArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> moreNums <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>numArray<span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>moreNums<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> shoe <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">size</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> newShoe <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>shoe<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">brand</span><span class=\"token operator\">:</span> <span class=\"token string\">'Nike'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">size</span><span class=\"token operator\">:</span> <span class=\"token number\">12</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newShoe<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nnewShoe<span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> <span class=\"token string\">'black'</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>newShoe<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>shoe<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>9. Destructure an array to reference specific elements</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>first<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>10. Destructure an object to reference specific values</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> me <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Ian'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">instruments</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'bass'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'synth'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'guitar'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">siblings</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">brothers</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Alistair'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">sisters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Meghan'</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span>\n    name<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">instruments</span><span class=\"token operator\">:</span> musical_instruments<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">siblings</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> sisters <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> me<span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>musical_instruments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sisters<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>11. Write a function that accepts a string as an argument and returns an object representing the count of each character in the array</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">charCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">inputString</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> res <span class=\"token operator\">=</span> inputString<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">accum<span class=\"token punctuation\">,</span> el</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>el <span class=\"token keyword\">in</span> accum<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            accum<span class=\"token punctuation\">[</span>el<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> accum<span class=\"token punctuation\">[</span>el<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            accum<span class=\"token punctuation\">[</span>el<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> accum<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> res<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">charCount</span><span class=\"token punctuation\">(</span><span class=\"token string\">'aaabbbeebbcdkjfalksdfjlkasdfasdfiiidkkdingds'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3></h3>\n<h3>Review of Concepts</h3>\n<h4>1. Identify the difference between const, let, and var declarations</h4>\n<h4>2. Explain the difference between const, let, and var declarations</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">var</code> is the historical keyword used for variable declaration.</li>\n<li><code class=\"language-text\">var</code> declares variables in function scope, or global scope if not inside a function.</li>\n<li>We consider <code class=\"language-text\">var</code> to be <em>deprecated</em> and it is never used in this course.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> b <span class=\"token operator\">=</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">let</code> is the keyword we use most often for variable declaration.</li>\n<li><code class=\"language-text\">let</code> declares variables in block scope.</li>\n<li>variables declared with <code class=\"language-text\">let</code> are re-assignable.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> c <span class=\"token operator\">=</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">const</code> is a specialized form of <code class=\"language-text\">let</code> that can only be used to <strong>initialize</strong> a variable.</li>\n<li>Except when it is declared, you cannot assign to a <code class=\"language-text\">const</code> variable.</li>\n<li><code class=\"language-text\">const</code> scopes variables the same way that <code class=\"language-text\">let</code> does.</li>\n</ul>\n<h4>3. Predict the evaluation of code that utilizes function scope, block scope, lexical scope, and scope chaining</h4>\n<p>Consider this <code class=\"language-text\">run</code> function, inside which <code class=\"language-text\">foo</code> and <code class=\"language-text\">bar</code> have <code class=\"language-text\">function scope</code>. <code class=\"language-text\">i</code> and <code class=\"language-text\">baz</code> are scoped to the block expression.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// function and block scope in this example</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> foo <span class=\"token operator\">=</span> <span class=\"token string\">'Foo'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> bar <span class=\"token operator\">=</span> <span class=\"token string\">'Bar'</span><span class=\"token punctuation\">;</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>foo<span class=\"token punctuation\">,</span> bar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>foo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> baz <span class=\"token operator\">=</span> <span class=\"token string\">'Bazz'</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>baz<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>baz<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ReferenceError</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Notice that referencing <code class=\"language-text\">baz</code> from outside it's block results in JavaScript throwing a ReferenceError.</p>\n<p>Consider this <code class=\"language-text\">run</code> function, inside of which <code class=\"language-text\">foo</code> has <code class=\"language-text\">function scope</code>.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>foo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// undefined</span>\n    <span class=\"token keyword\">var</span> foo <span class=\"token operator\">=</span> <span class=\"token string\">'Foo'</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>foo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Foo</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Consider this <code class=\"language-text\">func1</code> function and it's nested scopes.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// global scope</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">func1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arg1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// func1 scope</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arg2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// func2 scope</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func3</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arg3</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// func3 scope</span>\n\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>arg1<span class=\"token punctuation\">,</span> arg2<span class=\"token punctuation\">,</span> arg3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h4>6. Implement a closure and explain how the closure effects scope</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">adder</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arg1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arg2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> arg1 <span class=\"token operator\">+</span> arg2<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> func2 <span class=\"token operator\">=</span> <span class=\"token function\">adder</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token function\">func2</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 4;</span></code></pre></div>\n<h4>4. Define an arrow function</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">returnValue</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">val</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> val<span class=\"token punctuation\">;</span></code></pre></div>\n<p>This simple construct will create a function that accepts <code class=\"language-text\">val</code> as a parameter, and returns <code class=\"language-text\">val</code> immediately. We do not need to type <code class=\"language-text\">return val</code>, because this is a single-line function.</p>\n<p>Identically, we could write</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">returnValue</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">val</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> val<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>5. Given an arrow function, deduce the value of <code class=\"language-text\">this</code> without executing the code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">fDAdder</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">acc<span class=\"token punctuation\">,</span> ele</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> acc <span class=\"token operator\">+</span> ele<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">fDAdder</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If we use a <em>function declaration</em> style function, the <code class=\"language-text\">this</code> variable is set to the <code class=\"language-text\">global</code> object (i.e. <code class=\"language-text\">Object [global]</code> in Node.JS and <code class=\"language-text\">Window</code> in your browser).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">adder</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    arr<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">acc<span class=\"token punctuation\">,</span> ele</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>sum <span class=\"token operator\">+=</span> ele<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">adder</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In this example, we use a <em>fat arrow</em> style function. Note that when we declare a funciton like this <code class=\"language-text\">this</code> becomes</p>\n<h4>7. Define a method that references this on an object literal</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> pokemon <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">firstname</span><span class=\"token operator\">:</span> <span class=\"token string\">'Pika'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">lastname</span><span class=\"token operator\">:</span> <span class=\"token string\">'Chu'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getPokeName</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> fullname <span class=\"token operator\">=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>firstname<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>lastname<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> fullname<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>pokemon<span class=\"token punctuation\">.</span><span class=\"token function\">getPokeName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>8. Utilize the built in Function#bind on a callback to maintain the context of <code class=\"language-text\">this</code></h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> pokemon <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">firstname</span><span class=\"token operator\">:</span> <span class=\"token string\">'Pika'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">lastname</span><span class=\"token operator\">:</span> <span class=\"token string\">'Chu'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">getPokeName</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> fullname <span class=\"token operator\">=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>firstname<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>lastname<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> fullname<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> logPokemon <span class=\"token operator\">=</span> pokemon<span class=\"token punctuation\">.</span><span class=\"token function\">getPokename</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>pokemon<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">logPokemon</span><span class=\"token punctuation\">(</span><span class=\"token string\">'sushi'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'algorithms'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Pika Chu loves sushi and algorithms</span></code></pre></div>\n<h4>9. Given a code snippet, identify what <code class=\"language-text\">this</code> refers to</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// this.name = name;</span>\n    <span class=\"token comment\">// let that = this;</span>\n\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// console.log(this); // => Window</span>\n        <span class=\"token comment\">// console.log(that); // => [Function] => Person</span>\n        <span class=\"token comment\">// this.sayName(); // => no method error</span>\n        that<span class=\"token punctuation\">.</span><span class=\"token function\">sayName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">sayName</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> jane <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Jane'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/docs/community/list-of-things-you-can-embed-in-your-website/","relativePath":"docs/community/list-of-things-you-can-embed-in-your-website/index.md","relativeDir":"docs/community/list-of-things-you-can-embed-in-your-website","base":"index.md","name":"index","frontmatter":{"title":" List of things you can embed in your website","template":"docs","excerpt":"How to Embed a Tweet"},"html":"<!--StartFragment-->\n<p>Bryan Guner</p>\n<p><img src=\"https://cdn.sanity.io/images/ke5fae8i/production/7283067481ec408b1a5e28083a07596aacbff496-1863x732.gif?rect=91,0,1681,732&#x26;w=1240&#x26;h=540\" alt=\"Cover Image for List of things you can embed in your website\"></p>\n<h2>How to Embed a Tweet</h2>\n<ol>\n<li>Find the tweet you'd like to embed.</li>\n<li>Click the downward arrow on the top-right of your tweet.</li>\n<li>Choose \"Embed Tweet.\"</li>\n<li>Copy the code that appears and paste it into your website's HTML editor.</li>\n<li>Add 'tw-align-center' after the words \"twitter-tweet\" in the embed code.</li>\n</ol>\n<h3>1. Find the tweet you'd like to embed.</h3>\n<p>To embed a tweet onto your blog or website, you'll need to first find the tweet you want to display in its natural habitat -- Twitter. Locate the tweet in your Twitter newsfeed or on the Twitter user's profile. For this example, we'll embed a tweet from <a href=\"https://twitter.com/HubSpot\">HubSpot's Twitter feed</a>, as shown in the screenshots below.</p>\n<h3>2. Click the downward arrow on the top-right of the tweet.</h3>\n<p>Once you've found the tweet you want to embed, click the downward-facing arrow icon, located on the top-right of the tweet, as shown below.</p>\n<h3>3. Choose \"Embed Tweet.\"</h3>\n<p>Clicking this arrow icon will reveal a dropdown menu of options, including one called \"Embed Tweet.\" Click this option.</p>\n<h3>4. Copy the code that appears and paste it into your website's HTML editor.</h3>\n<p>Clicking \"Embed Tweet\" from the dropdown menu shown above will open the code box shown below. Under \"Embed this Tweet,\" you'll see a string of text highlighted in blue. Use Command+C on your keyboard (or Control+C, if you're using a PC) to copy this code to your clipboard.</p>\n<p>With this embed code copied to your clipboard, return to the website where you want to embed this tweet. Open the source code of this website (some content management systems have a <strong>\"&#x3C;/>\"</strong> icon where you can access this source code). Here, you'll paste the tweet's embed code into your HTML precisely where you want the tweet to appear.</p>\n<h3>5. Add 'tw-align-center' after the words \"twitter-tweet\" in the embed code.</h3>\n<p>Once you pasted this code into your HTML, however, you'll want to center-align this tweet so it doesn't automatically appear pushed up against the left or right side of your webpage. To correct this, add the text, 'tw-align-center' (without quotation marks) directly after \"twitter-tweet\" in the embed code. <a href=\"https://blog.hubspot.com/blog/tabid/6307/bid/34273/How-to-Center-Align-Your-Embedded-Tweets-Quick-Tip.aspx\">You can learn more about this method here</a>.</p>\n<p>Here's what the final code should look like:</p>\n<blockquote class=\"twitter-tweet\" **tw-align-center** data-lang=\"en\"><p lang=\"en\" dir=\"ltr\">Let us know! 👂<br>What type of content would you like to see from us this year?</p>&mdash; HubSpot (@HubSpot) <a href=\"https://twitter.com/HubSpot/status/1085634067679322114?ref_src=twsrc%5Etfw\">January 16, 2019</a></blockquote>\\\n<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n<p>That's it! This is what your embedded tweet will look like when you're done:</p>\n<h2>Embed Facebook Post or Video</h2>\n<h3>1. Find the Facebook post you'd like to embed.</h3>\n<p>Similar to the steps to embed a tweet (listed above), embedding a Facebook post onto your blog or website starts on Facebook. Navigate to the post you want to embed from Facebook, on the Facebook user's profile page or your newsfeed. For this example, we'll embed a Facebook post from the <a href=\"https://www.facebook.com/thehubspotacademy/\">HubSpot Academy</a>, as shown in the screenshots below.</p>\n<h3>2. Click the ellipsis (\"...\") icon on the top-right of the post.</h3>\n<p>On the top-right of the Facebook post you want to embed, you'll see an ellipsis icon consisting of three small dots. Click this icon, as shown below.</p>\n<h3>3. Click \"Embed.\"</h3>\n<p>Clicking the ellipsis icon shown below will reveal a dropdown menu of options, including one labeled \"Embed.\" If the post you want to embed is a video, a similar option labeled \"&#x3C;/> Embed\" will appear further down on this menu. Click either option.</p>\n<p>If you don't see an option to embed the post, then the post is not public and is not embeddable.</p>\n<h3>4. Copy the code that appears and paste it into your website's HTML editor.</h3>\n<p>Clicking the \"Embed\" option shown above will open the box shown below. At the top of this box, just above the \"Hide Preview\" and \"Advanced Settings\" buttons, you'll see a line of coded text. Highlight and copy this code onto your computer's clipboard.</p>\n<p>With this embed code copied to your clipboard, return to the website where you want to embed this Facebook post. Open the source code of this website (some content management systems have a <strong>\"&#x3C;/>\"</strong> icon where you can access this source code). Here, you'll paste the Facebook post's embed code into your HTML precisely where you want the post to appear.</p>\n<h3>5. Add <center> and </center> tags around the entire HTML snippet to center-align your post.</h3>\n<p>Once you pasted this code into your HTML, however, you'll want to center-align the post so it doesn't automatically appear pushed up against the left or right side of your webpage. To correct this, wrap the code with '<center>' and '</center>' tags so the Facebook post displays in the center of your article or webpage.</p>\n<p>Here's what the final code should look like:</p>\n<p><strong><center></strong><iframe src=\"https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fthehubspotacademy%2Fposts%2F741606746226328%3A0&width=500\" width=\"500\" height=\"448\" style=\"border:none;overflow:hidden\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" allow=\"encrypted-media\"></iframe><strong></center></strong></p>\n<p>That's it! Here's what it'll look like when you're done:</p>\n<h2>Embed Facebook Feed</h2>\n<p>Believe it or not, embedding a Facebook profile's entire feed onto your website is as easy as embedding a single post or video. And there's more than one way to do it.</p>\n<h3>Using a WordPress Plugin</h3>\n<p>The first way is to install a plugin or widget into your content management system (CMS). WordPress users, for example, have several Facebook feed plugins at their disposal. Here's how to use one:</p>\n<ol>\n<li>The Custom Facebook Feed, by Smash Balloon, is one such WordPress plugin you can download through your WordPress account. <a href=\"https://wordpress.org/plugins/custom-facebook-feed/\">You can download this plugin here</a>.</li>\n<li>With this plugin downloaded, log into your WordPress account and activate this plugin from within the \"Plugins\" menu.</li>\n<li>Use the \"Facebook Feed\" settings of your CMS to select and configure the specific Facebook feed you want to display on your website.</li>\n<li>Enter the text, '[custom-facebook-feed]' in the HTML editor of your website to generate your chosen Facebook feed.</li>\n</ol>\n<h3>Using Facebook's Page Plugin</h3>\n<p>Facebook has its very own Page Plugin, allowing you to produce embed code for any profile's individual Facebook feed and enter it into the HTML of your website. Here's how to use it:</p>\n<h4>1. Open Facebook's Page Plugin tool.</h4>\n<p>To embed a Facebook feed into your blog or website, open Facebook's native Page Plugin tool <a href=\"https://developers.facebook.com/docs/plugins/page-plugin/\">here</a>. Scroll down on this page until you see the section shown below.</p>\n<h4>2. Enter the URL of the Facebook Page you want to embed.</h4>\n<p>With this tool opened, create a new tab in your web browser and navigate to the Facebook profile whose feed you want to embed. Press Command+C on your keyboard (or Control+C, if you're using a PC) to copy the URL of this page to your computer's clipboard.</p>\n<p>Return to the browser tab that has Facebook's Page Plugin open. Paste the URL from your clipboard into the top-left field, as shown in the screenshot below. For this example, we'll embed the Facebook feed of HubSpot's Facebook Business Page.</p>\n<h4>3. Add the tabs you want displayed alongside your embedded feed.</h4>\n<p>In addition to showing a profile's entire timeline, Facebook's Page Plugin also lets you display tabs to that profile's Events and/or Messenger account. By default, the Page Plugin tool will have \"timeline\" entered by itself.</p>\n<p>To add either Events or Messenger tabs to your embedded Facebook feed, click over to the \"Tabs\" field on the top-right of the Page Plugin tool, as shown below. Add the words \"events\" and/or \"messages\" next to the word \"timeline,\" all separated by commas.</p>\n<h4>4. Customize the dimensions of your Facebook feed.</h4>\n<p>If your website has specific dimensions that restrict the size of the media you embed, and you know what these dimensions are, enter them into the bottom two fields of the Facebook Page Plugin tool. You can enter a specific width in the left field and a specific height in the right.</p>\n<p>By default, your Facebook feed will display at roughly 340x500, although you'll see recommended dimensions in the tool's preview text.</p>\n<h4>5. Click \"Get Code.\"</h4>\n<p>With all four of these fields filled in, simply click the blue \"Get Code\" button at the bottom of the tool, as shown in the screenshot above. This will open the code box shown below.</p>\n<h4>6. Click the 'IFrame' tab.</h4>\n<p>Be careful which code you select, though ... unless you're coding your website from scratch, the first tab (labeled \"JavaScript SDK\") does <em>not</em> have the code you want. Toggle over to the tab labeled \"IFrame,\" as shown below. This text is ready-made for embedding into your blog or website's HTML editor.</p>\n<h4>7. Copy and paste this embed code into your website's HTML editor.</h4>\n<p>Copy the code shown above to your clipboard. Then, navigate to the website where you want to embed this Facebook feed. Open the source code of your website (some content management systems have a <strong>\"&#x3C;/>\"</strong> icon where you can access this source code). Here, you'll paste the feed's embed code into your HTML precisely where you want it to appear.</p>\n<h4>8. Add <center> and </center> tags around the entire IFrame snippet to center-align the feed.</h4>\n<p>Once you pasted this code into your HTML, however, you'll want to center-align the post so it doesn't automatically appear pushed up against the left or right side of your webpage. To correct this, wrap the code with '<center>' and '</center>' tags so the Facebook feed displays in the center of your article or webpage.</p>\n<p>Here's what the final code should look like:</p>\n<p><strong><center></strong><iframe style=\"border: none; overflow: hidden;\" allow=\"encrypted-media\" xml=\"lang\" src=\"https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Fhubspot&amp;tabs=timeline%2C%20events%2C%20messages&amp;width=340&amp;height=500&amp;small_header=false&amp;adapt_container_width=true&amp;hide_cover=false&amp;show_facepile=true&amp;appId\" width=\"340\" height=\"500\" frameborder=\"0\" scrolling=\"no\"></iframe><strong></center></strong></p>\n<p>That's it! Here's what it'll look like when you're done:</p>\n<h2>Embed Instagram Feed and Posts</h2>\n<p>Instagram is a favorite among marketers, but embedding an entire Instagram feed can be difficult. Here's how to embed an Instagram feed as well as individual posts to your website.</p>\n<h3>The Instagram Feed WordPress Plugin</h3>\n<p>From the makers of the Custom Facebook Feed comes the Instagram Feed. Developed by Smash Balloon, this WordPress plugin makes it easy for WordPress-based websites to embed entire Instagram feeds from specific Instagram accounts. Here's how to use it:</p>\n<ol>\n<li>Download the Instagram Feed plugin for WordPress <a href=\"https://en-gb.wordpress.org/plugins/instagram-feed/\">here</a>.</li>\n<li>With this plugin downloaded, log into your WordPress account and activate this plugin from within the \"Plugins\" menu.</li>\n<li>Use the \"Instagram Feed\" settings of your CMS to select your Instagram Access Token and user ID.</li>\n<li>Enter the text, '[instagram-feed]' in the HTML editor of your website to generate your chosen Instagram feed.</li>\n</ol>\n<p>According to this plugin's instructions on WordPress, you can display multiple Instagram feeds at the same time by entering text in the format of: '[instagram-feed num=6 cols=3]'. In that example, you would effectively embed <em>six</em> images each for <em>three</em> separate Instagram feeds.</p>\n<h3>Instagram's Embedding Feature</h3>\n<p>To embed individual Instagram pictures, you need not look further than the native features of Instagram. Here's how to do it:</p>\n<p><strong><em>Important:</em></strong> <em>In order to embed specific Instagram posts onto a blog or website, the Instagram account it belongs to cannot be set to private. To set an account to public, navigate to this profile and click \"Edit Profile\" > Privacy and Security. From this page, uncheck the \"Private Account\" option and you should be all set.</em></p>\n<h4>1. Click on the Instagram image you want to embed.</h4>\n<p>Navigate to the Instagram post you want to embed onto your website and click on it to enlarge the image. For this example, we'll embed an image from HubSpot's culture account, <a href=\"https://www.instagram.com/hubspotlife/\">hubspotlife</a>, as shown in the screenshots below.</p>\n<h4>2. Click the ellipsis (\"...\") icon on the bottom-right corner of the post.</h4>\n<p>With the post in its full view, look to the bottom-right of the comments section. Click the ellipsis icon, consisting of three small dots, as shown below.</p>\n<h4>3. Select \"Embed.\"</h4>\n<p>Clicking the ellipsis icon shown above will open the box of options shown below. In this menu, select \"Embed,\" the third button from the top.</p>\n<h4>4. Copy and paste the embed code into your website's HTML editor.</h4>\n<p>Much like the instructions for Twitter and Facebook (listed above), this \"Embed\" button will produce another box carrying a sting of coded text. Once this box opens on your screen, highlight the code at the top, as shown below. Then, click the blue \"Copy Embed Code\" button at the bottom to copy this text to your computer's clipboard.</p>\n<h4>5. Add <center> and </center> tags around the entire HTML snippet to center-align the post.</h4>\n<p>Once you pasted this code into your HTML, however, you'll want to center-align the Instagram post so it doesn't automatically appear pushed up against the left or right side of your webpage. To correct this, wrap the code with '<center>' and '</center>' tags so the image displays in the center of your article or webpage.</p>\n<p>That's it! Here's what your embedded Instagram post will look like:</p>\n<h2>Embed Pinterest Pins</h2>\n<h3>1. Open Pinterest's widget builder.</h3>\n<p>To embed pinned content from Pinterest onto your blog or website, open Pinterest's widget builder, <a href=\"https://business.pinterest.com/en/pinterest-widget-builder\">available here</a>.</p>\n<h3>2. Select \"Pin Widget\" in the left-hand column.</h3>\n<p>Scroll down until you see the Pin Widget option, as shown in the screenshot below.</p>\n<h3>3. Paste in the URL of the pin you'd like to embed.</h3>\n<p>Start by filling in the \"Pin URL\" field at the top of the tool with the URL of the pin you want to embed onto your website, as shown below.</p>\n<h3>4. Copy and paste the code from this section into your website's HTML editor.</h3>\n<p>While in Pinterest's Pin Widget, scroll down to the section just beneath the preview image of your pin, where you'll find two lines of coded text -- as shown below.</p>\n<p>Open your website's HTML editor, and copy and paste the first line exactly where you'd like your Pinterest pin to appear on the page. Then, copy the second line of text and paste it into your website's HTML editor at the very bottom of the page.</p>\n<p>Be careful not to paste this entire snippet more than once on a single webpage. If you want the pin to appear multiple times, you just need to copy the <em>first</em> line of code and paste it wherever you'd like it to appear on the page. And don't forget to repeat the following steps in each instance of the pin you decide to embed.</p>\n<h3>5. Copy the snippet of code provided below.</h3>\n<!--pinterest-->\n<h3>6. Paste that snippet of code between the opening <a> tag and the closing </a> tag.</h3>\n<p>The code should look like this:</p>\n<p><a data-pin-do=\"embedPin\" href=\"http://www.pinterest.com/pin/99360735500167749/\"><strong><!--pinterest--></strong></a><br>\n...</p>\n<p>At bottom of page:\\</p>\n<script type=\"text/javascript\" async src=\"//assets.pinterest.com/js/pinit.js\"></script>\n<h3>7. Add <center> and </center> tags around the entire HTML snippet to center-align the pin.</h3>\n<p>Here's what the final code should look like:</p>\n<p><strong><center></strong><a data-pin-do=\"embedPin\" href=\"http://www.pinterest.com/pin/99360735500167749/\"><!--pinterest--></a>\\</p>\n<!-- Please call pinit.js only once per page -->\\\n<script type=\"text/javascript\" async src=\"//assets.pinterest.com/js/pinit.js\"></script>**</center>**\n<p>That's it! Here's what it'll look like when you're done:</p>\n<p>SaveNext stop: Pinterest!by kentbrewLove my Pinterest t-shirt!</p>\n<h2>Embed Pinterest Boards</h2>\n<p>To add Pinterest Boards, the steps are generally the same as they are to embed individual pins -- explained above. Here's how it's done:</p>\n<ol>\n<li>Open Pinterest's widget builder.</li>\n<li>Select \"Board Widget\" in the lefthand column, just beneath the \"Pin Widget\" builder.</li>\n<li>When the Board Widget open, follow the same steps as you would for adding pins, listed above.</li>\n</ol>\n<p>Copy and paste the bottom two lines of code into your website's HTML editor, and that's it! Here's what an embedded board looks like:</p>\n<p>HubSpotMarketing InfographicsFollow On</p>\n<h2>Embed Google+ Post</h2>\n<h4><strong>1. Find the Google+ post you'd like to embed. Hover your mouse over the top right corner and click the grey arrow that appears to pull down more options.</strong></h4>\n<h4><strong>2. Choose \"Embed Post.\"</strong></h4>\n<h4><strong>3.</strong> <strong>Copy the entirety of the code that appears, and paste it in the HTML view of your website.</strong></h4>\n<h4><strong>4.</strong> <strong>Center the embedded post by adding <center> and </center> around the whole HTML snippet.</strong></h4>\n<p>Here's what the final code should look like:</p>\n<p><strong><center></strong><!-- Place this tag in your head or just before your close body tag. -->\\</p>\n<script type=\"text/javascript\" src=\"https://apis.google.com/js/plusone.js\"></script>\\\n<p>\\</p>\n<!-- Place this tag where you want the widget to render. -->\\\n<div class=\"g-post\" data-href=\"https://plus.google.com/110490539670062886957/posts/be2TCKDBMsG\"></div>**</center>**\n<p>That's it! Here's what it'll look like when you're done:</p>\n<h2>How to Embed Google Calendar</h2>\n<p>To embed a particular Google Calendar onto your blog or website, you'll need to use the web version of Google Calendar, rather than the mobile app.</p>\n<p>Got it open? Let's embed it.</p>\n<h3>1. Click the gear icon to open your settings.</h3>\n<p>At the top of your Google Calendar, click the gear icon and select \"Settings,\" as shown below.</p>\n<h3>2. Select the calendar you want to embed and scroll down to \"Integrate calendar.\"</h3>\n<p>Once you're in your calendar settings, look to the lefthand sidebar for the specific calendar you want to embed onto your website. For this example, we'll embed HubSpot's National Holidays calendar.</p>\n<p>Once you have your calendar selected, look to the right side of your settings and scroll down until you see the \"Integrate calendar\" section. (You can also simply click the option of the same name on the lefthand side under your chosen calendar.)</p>\n<h3>3. Click \"Customize\" and configure the size and color of your calendar.</h3>\n<p>In the \"Integrate calendar\" section of your settings, find and click the \"Customize\" button, just above the \"Embed code\" line of text. This will open a larger window of options where you can change the size and color scheme of your calendar before embedding it.</p>\n<p>If you're happy with how the calendar currently looks and don't need to make any aesthetic changes, you can simply copy this embed code to your clipboard.</p>\n<h3>4. Copy your embed code at the top and paste it into your website's HTML editor.</h3>\n<p>Copy your embed code, from either inside the Customize window or from the Settings page, and paste it into your website's HTML editor. If you'd like, you can wrap this embed code in <center> and </center> tags to center-align your calendar within the margins of your website.</p>\n<h2>How to Embed a YouTube Video</h2>\n<ol>\n<li>Find the YouTube video you'd like to embed.</li>\n<li>Under the video, choose \"Share.\"</li>\n<li>In the menu that appears, choose \"Embed.\"</li>\n<li>Copy the code that appears and paste into your website's HTML editor.</li>\n</ol>\n<h3>1. Find the YouTube video you'd like to embed.</h3>\n<p>Embedding a YouTube video onto your blog or website is incredibly easy. To start, open YouTube and navigate to the video you want to embed. For this example, we'll embed a video about inbound marketing from HubSpot's INBOUND YouTube channel -- as shown in the screenshots below.</p>\n<h3>2. Under the video, choose \"Share.\"</h3>\n<p>Beneath the video itself, look for the \"Share\" button, as shown below.</p>\n<h3>3. In the menu that appears, choose \"Embed.\"</h3>\n<p>Clicking the \"Share\" button below your chosen YouTube video will open a small menu of options where you can share the video to various social networks. To the far left of these options, however, you'll also see a circular \"Embed\" button. Click this button.</p>\n<h3>3. Copy the code that appears and paste it into your website's HTML editor.</h3>\n<p>The next window to appear will produce a large of box of coded text, as well as a few options to customize your video before you embed it. Under the embed code, for instance, you can set whether you want your video to start at a particular timestamp.</p>\n<p>Once you have your settings exactly the way you want them, highlight the coded text at the top of the window. Then, click \"Copy\" on the bottom-right.</p>\n<h3>4. Add <center> and </center> tags around the entire HTML snippet to center-align your video.</h3>\n<p>Here's what the final code should look like:</p>\n<p><strong><center></strong><iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/mZxa3lrLhXM\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe><strong></center></strong></p>\n<p>That's it! Here's what it'll look like when you're done:</p>\n<h2>Embed SlideShare Presentations and Infographics</h2>\n<h3>1. Find the SlideShare presentation or infographic you'd like to embed on SlideShare.net.</h3>\n<h3>2. Click \"Embed\" in the navigation bar at the top.</h3>\n<h3>2. Click \"Customize.\"</h3>\n<p>If you want to customize your embedded SlideShare presentation or infographic, click \"Customize\" and the following options will appear, shown below. Choose the options you'd like, then copy the code in the \"Embed\" section and paste it in the HTML view of your website.</p>\n<h3>3. Center the embedded Slideshare by adding <center> and </center> around the whole HTML snippet.</h3>\n<p>Here's what the final code should look like:</p>\n<p><strong><center></strong><iframe src=\"//www.slideshare.net/slideshow/embed_code/31128788\" width=\"427\" height=\"356\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" allowfullscreen> </iframe> <div> <strong> <a href=\"https://www.slideshare.net/HubSpot/a-sales-and-marketing-love-story\" title=\"A Sales and Marketing Love Story\" target=\"_blank\">A Sales and Marketing Love Story</a> </strong> from <strong><a href=\"http://www.slideshare.net/HubSpot\" target=\"_blank\">HubSpot</a></strong></div><strong></center></strong></p>\n<p>That's it! Here's what it'll look like when you're done:</p>\n<p><strong><a href=\"https://www.slideshare.net/HubSpot/a-sales-and-marketing-love-story\">A Sales and Marketing Love Story</a></strong> from <strong><a href=\"http://www.slideshare.net/HubSpot\">HubSpot</a></strong></p>\n<p>Some of these embed codes may need a little tweaking to look perfect on your blog or website, but using these steps, you should be off to great start. Happy embedding!</p>\n<!--EndFragment-->"},{"url":"/docs/css/media-querries/","relativePath":"docs/css/media-querries/index.md","relativeDir":"docs/css/media-querries","base":"index.md","name":"index","frontmatter":{"title":"CSS Introduction","excerpt":"CSS is among the core languages of the open web","template":"docs"},"html":"<hr>\n<!--StartFragment-->\n<h1>CSS</h1>\n<p>CSS is among the core languages of the <strong>open web</strong> and is standardized across Web browsers according to <a href=\"https://w3.org/Style/CSS/#specs\">W3C specifications</a>. Previously, development of various parts of CSS specification was done synchronously, which allowed versioning of the latest recommendations. You might have heard about CSS1, CSS2.1, CSS3. However, CSS4 has never become an official version.</p>\n<p>From CSS3, the scope of the specification increased significantly and the progress on different CSS modules started to differ so much, that it became more effective to <a href=\"https://www.w3.org/Style/CSS/current-work\">develop and release recommendations separately per module</a>. Instead of versioning the CSS specification, W3C now periodically takes a snapshot of <a href=\"https://www.w3.org/TR/css/\">the latest stable state of the CSS specification</a>.</p>\n<h2><a href=\"https://webdevhub.us/docs/css/#key_resources\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS#key_resources\" title=\"Permalink to Key resources\">Key resources</a></h2>\n<p>CSS Introduction</p>\n<p>If you're new to web development, be sure to read our <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/CSS_basics\">CSS basics</a> article to learn what CSS is and how to use it.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps\">CSS first steps</a></p>\n<p>CSS (Cascading Style Sheets) is used to style and layout web pages — for example, to alter the font, color, size, and spacing of your content, split it into multiple columns, or add animations and other decorative features. This module provides a gentle beginning to your path towards CSS mastery with the basics of how it works, what the syntax looks like, and how you can start using it to add styling to HTML.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks\">CSS building blocks</a></p>\n<p>This module carries on where <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/First_steps\">CSS first steps</a> left off — now you've gained familiarity with the language and its syntax, and got some basic experience with using it, it's time to dive a bit deeper. This module looks at the cascade and inheritance, all the selector types we have available, units, sizing, styling backgrounds and borders, debugging, and lots more.</p>\n<p>The aim here is to provide you with a toolkit for writing competent CSS and help you understand all the essential theory, before moving on to more specific disciplines like <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text\">text styling</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout\">CSS layout</a>.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text\">Styling text</a></p>\n<p>With the basics of the CSS language covered, the next CSS topic for you to concentrate on is styling text — one of the most common things you'll do with CSS. Here we look at text styling fundamentals, including setting font, boldness, italics, line and letter spacing, drop shadows, and other text features. We round off the module by looking at applying custom fonts to your page, and styling lists and links.</p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout\">CSS layout</a></p>\n<p>At this point we've already looked at CSS fundamentals, how to style text, and how to style and manipulate the boxes that your content sits inside. Now it's time to look at how to place your boxes in the right place in relation to the viewport, and to each other. We have covered the necessary prerequisites so we can now dive deep into CSS layout, looking at different display settings, modern layout tools like flexbox, CSS grid, and positioning, and some of the legacy techniques you might still want to know about.</p>\n<ul>\n<li>The <strong>property</strong> which is an identifier, that is a human-readable <em>name</em>, that defines which feature is considered.</li>\n<li>The <strong>value</strong> which describe how the feature must be handled by the engine. Each property has a set of valid values, defined by a formal grammar, as well as a semantic meaning, implemented by the browser engine.</li>\n</ul>\n<h2><a href=\"https://webdevhub.us/docs/css/#css_declarations\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declarations\" title=\"Permalink to CSS declarations\">CSS declarations</a></h2>\n<p>Setting CSS properties to specific values is the core function of the CSS language. A property and value pair is called a <strong>declaration</strong>, and any CSS engine calculates which declarations apply to every single element of a page in order to appropriately lay it out, and to style it.</p>\n<p>Both properties and values are case-insensitive by default in CSS. The pair is separated by a colon, '<code class=\"language-text\">:</code>' (<code class=\"language-text\">U+003A COLON</code>), and white spaces before, between, and after properties and values, but not necessarily inside, are ignored.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/css_syntax_-_declaration.png\" alt=\"css syntax - declaration.png\"></p>\n<p>There are more than <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference\">100 different properties</a> in CSS and a nearly infinite number of different values. Not all pairs of properties and values are allowed and each property defines what are the valid values. When a value is not valid for a given property, the declaration is deemed <em>invalid</em> and is wholly ignored by the CSS engine.</p>\n<h2><a href=\"https://webdevhub.us/docs/css/#css_declaration_blocks\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declaration_blocks\" title=\"Permalink to CSS declaration blocks\">CSS declaration blocks</a></h2>\n<p>Declarations are grouped in <strong>blocks</strong>, that is in a structure delimited by an opening brace, '<code class=\"language-text\">{</code>' (<code class=\"language-text\">U+007B LEFT CURLY BRACKET</code>), and a closing one, '<code class=\"language-text\">}</code>' (<code class=\"language-text\">U+007D RIGHT CURLY BRACKET</code>). Blocks sometimes can be nested, so opening and closing braces must be matched.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/css_syntax_-_block.png\" alt=\"css syntax - block.png\"></p>\n<p>Such blocks are naturally called <strong>declaration blocks</strong> and declarations inside them are separated by a semi-colon, '<code class=\"language-text\">;</code>' (<code class=\"language-text\">U+003B SEMICOLON</code>). A declaration block may be empty, that is containing null declaration. White spaces around declarations are ignored. The last declaration of a block doesn't need to be terminated by a semi-colon, though it is often considered <em>good style</em> to do it as it prevents forgetting to add it when extending the block with another declaration.</p>\n<p>A CSS declaration block is visualized in the diagram below.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/declaration-block.png\" alt=\"css syntax - declarations block.png\"></p>\n<p><strong>Note:</strong> The content of a CSS declaration block, that is a list of semi-colon-separated declarations, without the initial and closing braces, can be put inside an HTML <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#attr-style\"><code class=\"language-text\">style</code></a> attribute.</p>\n<h2><a href=\"https://webdevhub.us/docs/css/#css_rulesets\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_rulesets\" title=\"Permalink to CSS rulesets\">CSS rulesets</a></h2>\n<p>If style sheets could only apply a declaration to each element of a Web page, they would be pretty useless. The real goal is to apply different declarations to different parts of the document.</p>\n<p>CSS allows this by associating conditions with declarations blocks. Each (valid) declaration block is preceded by one or more comma-separated <strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors\">selectors</a></strong>, which are conditions selecting some elements of the page. A <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Selector_list\">selector group</a> and an associated declarations block, together, are called a <strong>ruleset</strong>, or often a <strong>rule</strong>.</p>\n<p>A CSS ruleset (or rule) is visualized in the diagram below.</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/ruleset.png\" alt=\"css syntax - ruleset.png\"></p>\n<p>As an element of the page may be matched by several selectors, and therefore by several rules potentially containing a given property several times, with different values, the CSS standard defines which one has precedence over the other and must be applied: this is called the <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance\">cascade</a> algorithm.</p>\n<p><strong>Note:</strong> It is important to note that even if a ruleset characterized by a group of selectors is a kind of shorthand replacing rulesets with a single selector each, this doesn't apply to the validity of the ruleset itself.</p>\n<p>This leads to an important consequence: if one single basic selector is invalid, like when using an unknown pseudo-element or pseudo-class, the whole <em>selector</em> is invalid and therefore the entire rule is ignored (as invalid too).</p>\n<h2><a href=\"https://webdevhub.us/docs/css/#css_statements\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_statements\" title=\"Permalink to CSS statements\">CSS statements</a></h2>\n<p>Rulesets are the main building blocks of a style sheet, which often consists of only a big list of them. But there is other information that a Web author wants to convey in the style sheet, like the character set, other external style sheets to import, font face or list counter descriptions and many more. It will use other and specific kinds of statements to do that.</p>\n<p>A <strong>statement</strong> is a building block that begins with any non-space characters and ends at the first closing brace or semi-colon (outside a string, non-escaped and not included into another {}, () or [] pair).</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax/css_syntax_-_statements_venn_diag.png\" alt=\"css syntax - statements Venn diag.png\"></p>\n<p>There are two kinds of statements:</p>\n<ul>\n<li><strong>Rulesets</strong> (or <em>rules</em>) that, as seen, associate a collection of CSS declarations to a condition described by a <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors\">selector</a>.</li>\n<li><strong>At-rules</strong> that start with an at sign, '<code class=\"language-text\">@</code>' (<code class=\"language-text\">U+0040 COMMERCIAL AT</code>), followed by an identifier and then continuing up to the end of the statement, that is up to the next semi-colon (;) outside of a block, or the end of the next block. Each type of <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule\">at-rules</a>, defined by the identifier, may have its own internal syntax, and semantics of course. They are used to convey meta-data information (like <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@charset\"><code class=\"language-text\">@charset</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@import\"><code class=\"language-text\">@import</code></a>), conditional information (like <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@media\"><code class=\"language-text\">@media</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@document\"><code class=\"language-text\">@document</code></a>), or descriptive information (like <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face\"><code class=\"language-text\">@font-face</code></a>).</li>\n</ul>\n<p>Any statement which isn't a ruleset or an at-rule is invalid and ignored.</p>\n<h3><a href=\"https://webdevhub.us/docs/css/#nested_statements\">Copy</a><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#nested_statements\" title=\"Permalink to Nested statements\">Nested statements</a></h3>\n<p>There is another group of statements – the <strong>nested statements</strong>. These are statements that can be used in a specific subset of at-rules – the <em>conditional group rules</em>. These statements only apply if a specific condition is matched: the <code class=\"language-text\">@media</code> at-rule content is applied only if the device on which the browser runs matches the expressed condition; the <code class=\"language-text\">@document</code> at-rule content is applied only if the current page matches some conditions, and so on. In CSS1 and CSS2.1, only <em>rulesets</em> could be used inside conditional group rules. That was very restrictive and this restriction was lifted in <em><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS3#Conditionals\" title=\"This is a link to an unwritten page\">CSS Conditionals Level 3</a></em>. Now, though still experimental and not supported by every browser, conditional group rules can contain a wider range of content: rulesets but also some, but not all, at-rules.</p>\n<!--EndFragment-->"},{"url":"/docs/css/css-selector-specificity/","relativePath":"docs/css/css-selector-specificity/index.md","relativeDir":"docs/css/css-selector-specificity","base":"index.md","name":"index","frontmatter":{"title":"CSS Selector Specificity","template":"docs","excerpt":"Specificity is a weight that is applied to a given CSS declaration"},"html":"<h1>Specificity</h1>\n<p><strong>Specificity</strong> is the means by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied. Specificity is based on the matching rules which are composed of different sorts of <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Reference#selectors\">CSS selectors</a>.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#how_is_specificity_calculated\" title=\"Permalink to How is specificity calculated?\">How is specificity calculated?</a></h2>\n<p>Specificity is a weight that is applied to a given CSS declaration, determined by the number of each <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#selector_types\">selector type</a> in the matching selector. When multiple declarations have equal specificity, the last declaration found in the CSS is applied to the element. Specificity only applies when the same element is targeted by multiple declarations. As per CSS rules, <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#directly_targeted_elements_vs._inherited_styles\">directly targeted elements</a> will always take precedence over rules which an element inherits from its ancestor.</p>\n<p><strong>Note:</strong> <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#tree_proximity_ignorance\">Proximity of elements</a> in the document tree has no effect on the specificity.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#selector_types\" title=\"Permalink to Selector Types\">Selector Types</a></h3>\n<p>The following list of selector types increases by specificity:</p>\n<ol>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors\">Type selectors</a> (e.g., <code class=\"language-text\">h1</code>) and pseudo-elements (e.g., <code class=\"language-text\">::before</code>).</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors\">Class selectors</a> (e.g., <code class=\"language-text\">.example</code>), attributes selectors (e.g., <code class=\"language-text\">[type=\"radio\"]</code>) and pseudo-classes (e.g., <code class=\"language-text\">:hover</code>).</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors\">ID selectors</a> (e.g., <code class=\"language-text\">#example</code>).</li>\n</ol>\n<p>Universal selector (<a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors\"><code class=\"language-text\">*</code></a>), combinators (<a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator\"><code class=\"language-text\">+</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator\"><code class=\"language-text\">></code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator\"><code class=\"language-text\">~</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator\">\" \"</a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Column_combinator\"><code class=\"language-text\">||</code></a>) and negation pseudo-class (<a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/:not\"><code class=\"language-text\">:not()</code></a>) have no effect on specificity. (The selectors declared <em>inside</em> <code class=\"language-text\">:not()</code> do, however.)</p>\n<p>For more information, visit: <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance#specificity_2\">\"Specificity\" in \"Cascade and inheritance\"</a>, you can also visit: <a href=\"https://specifishity.com\">https://specifishity.com</a></p>\n<p>Inline styles added to an element (e.g., <code class=\"language-text\">style=\"font-weight: bold;\"</code>) always overwrite any styles in external stylesheets, and thus can be thought of as having the highest specificity.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#the_!important_exception\" title=\"Permalink to The !important exception\">The !important exception</a></h3>\n<p>When an <code class=\"language-text\">important</code> rule is used on a style declaration, this declaration overrides any other declarations. Although technically <code class=\"language-text\">!important</code> has nothing to do with specificity, it interacts directly with it. Using <code class=\"language-text\">!important,</code> however, is <strong>bad practice</strong> and should be avoided because it makes debugging more difficult by breaking the natural <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade\">cascading</a> in your stylesheets. When two conflicting declarations with the <code class=\"language-text\">!important</code> rule are applied to the same element, the declaration with a greater specificity will be applied.</p>\n<p><strong>Recommended guidelines:</strong></p>\n<ul>\n<li><strong>Always</strong> look for a way to use specificity before even considering <code class=\"language-text\">!important</code></li>\n<li><strong>Only</strong> use <code class=\"language-text\">!important</code> on page-specific CSS that overrides foreign CSS (from external libraries, like Bootstrap or normalize.css).</li>\n<li><strong>Never</strong> use <code class=\"language-text\">!important</code> when you're writing a plugin/mashup.</li>\n<li><strong>Never</strong> use <code class=\"language-text\">!important</code> on site-wide CSS.</li>\n</ul>\n<p><strong>Instead of using <code class=\"language-text\">!important</code>, consider:</strong></p>\n<ol>\n<li>Make better use of the CSS cascade</li>\n<li>\n<p>Use more specific rules. By indicating one or more elements before the element you're selecting, the rule becomes more specific and gets higher priority:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div id=\"test\">\n  &lt;span>Text&lt;/span>\n&lt;/div></code></pre></div>\n<p>Copy to Clipboard</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">div#test span { color: green; }\ndiv span { color: blue; }\nspan { color: red; }</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>No matter the order, text will be green because that rule is most specific. (Also, the rule for blue overwrites the rule for red, notwithstanding the order of the rules)</p>\n</li>\n<li>\n<p>As a nonsense special case for (2), duplicate simple selectors to increase specificity when you have nothing more to specify.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#myId#myId span { color: yellow; }\n.myClass.myClass span { color: orange; }</code></pre></div>\n<p>Copy to Clipboard</p>\n</li>\n</ol>\n<h4>How !important can be used:</h4>\n<h5>A) Overriding inline styles</h5>\n<p>Your global CSS file that sets visual aspects of your site globally may be overwritten by inline styles defined directly on individual elements. Both inline styles and !important are considered bad practice, but sometimes you need the latter to override the former.</p>\n<p>In this case, you could set certain styles in your global CSS file as !important, thus overriding inline styles set directly on elements.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"foo\" style=\"color: red;\">What color am I?&lt;/div></code></pre></div>\n<p>Copy to Clipboard</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.foo[style*=\"color: red\"] {\n  color: firebrick !important;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>Many JavaScript frameworks and libraries add inline styles. Using <code class=\"language-text\">!important</code> with a very targeted selector is one way to override these inline styles.</p>\n<h5>B) Overriding high specificity</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#someElement p {\n  color: blue;\n}\n\np.awesome {\n  color: red;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>How do you make <code class=\"language-text\">awesome</code> paragraphs always turn red, even ones inside <code class=\"language-text\">#someElement</code>? Without <code class=\"language-text\">!important</code>, the first rule will have more specificity and will win over the second rule.</p>\n<h4>How to override <code class=\"language-text\">!important</code></h4>\n<p>A) Add another CSS rule with <code class=\"language-text\">!important</code>, and either give the selector a higher specificity (adding a tag, id or class to the selector), or add a CSS rule with the same selector at a later point than the existing one. This works because in a specificity tie, the last rule defined wins.</p>\n<p>Some examples with a higher specificity:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">table td    { height: 50px !important; }\n.myTable td { height: 50px !important; }\n#myTable td { height: 50px !important; }</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>B) Or add the same selector after the existing one:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">td { height: 50px !important; }</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>C) Or, preferably, rewrite the original rule to avoid the use of <code class=\"language-text\">!important</code> altogether.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[id=\"someElement\"] p {\n  color: blue;\n}\n\np.awesome {\n  color: red;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>Including an id as part of an attribute selector instead of as an id selector gives it the same specificity as a class. Both selectors above now have the same weight. In a specificity tie, the last rule defined wins.</p>\n<h4>For more information, visit:</h4>\n<ul>\n<li><a href=\"https://stackoverflow.com/questions/3706819/what-are-the-implications-of-using-important-in-css\">https://stackoverflow.com/questions/3706819/what-are-the-implications-of-using-important-in-css</a></li>\n<li><a href=\"https://stackoverflow.com/questions/9245353/what-does-important-in-css-mean\">https://stackoverflow.com/questions/9245353/what-does-important-in-css-mean</a></li>\n<li><a href=\"https://stackoverflow.com/questions/5701149/when-to-use-important-property-in-css\">https://stackoverflow.com/questions/5701149/when-to-use-important-property-in-css</a></li>\n<li><a href=\"https://stackoverflow.com/questions/11178673/how-to-override-important\">https://stackoverflow.com/questions/11178673/how-to-override-important</a></li>\n<li><a href=\"https://stackoverflow.com/questions/2042497/when-to-use-important-to-save-the-day-when-working-with-css\">https://stackoverflow.com/questions/2042497/when-to-use-important-to-save-the-day-when-working-with-css</a></li>\n</ul>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#the_is_and_not_exceptions\" title=\"Permalink to The :is() and :not() exceptions\">The :is() and :not() exceptions</a></h3>\n<p>The matches-any pseudo-class <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/:is\"><code class=\"language-text\">:is()</code></a> Experimental and the negation pseudo-class <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/:not\"><code class=\"language-text\">:not()</code></a> are <em>not</em> considered a pseudo-class in the specificity calculation. But selectors placed into the pseudo-class count as normal selectors when determining the count of <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#selector_types\">selector types</a>.</p>\n<p>This chunk of CSS ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">div.outer p {\n  color: orange;\n}\n\ndiv:not(.outer) p {\n  color: blueviolet;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... when used with the following HTML ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"outer\">\n  &lt;p>This is in the outer div.&lt;/p>\n  &lt;div class=\"inner\">\n    &lt;p>This text is in the inner div.&lt;/p>\n  &lt;/div>\n&lt;/div></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... appears on the screen like this:</p>\n<iframe class=\"sample-code-frame\" title=\"The is and not exceptions sample\" id=\"frame_the_is_and_not_exceptions\" src=\"https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Web/CSS/Specificity/_sample_.the_is_and_not_exceptions.html\" loading=\"lazy\">\n</iframe>\n<br>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#the_where_exception\" title=\"Permalink to The :where() exception\">The :where() exception</a></h3>\n<p>The specificity-adjustment pseudo-class <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/:where\"><code class=\"language-text\">:where()</code></a> Experimental always has its specificity replaced with zero.</p>\n<p>This chunk of CSS ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">div:where(.outer) p {\n  color: orange;\n}\n\ndiv p {\n  color: blueviolet;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#no-where-support {\n  margin: 0.5em;\n  border: 1px solid red;\n}\n\n#no-where-support:where(*) {\n  display: none !important;\n}</code></pre></div>\n<p>... when used with the following HTML ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div id=\"no-where-support\">\n⚠️ Your browser doesn't support the &lt;code>\n&lt;a href=\"https://developer.mozilla.org/docs/Web/CSS/:where\" target=\"_top\">:where()&lt;/a>\n&lt;/code> pseudo-class.\n&lt;/div></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"outer\">\n  &lt;p>This is in the outer div.&lt;/p>\n  &lt;div class=\"inner\">\n    &lt;p>This text is in the inner div.&lt;/p>\n  &lt;/div>\n&lt;/div></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... appears on the screen like this:</p>\n<iframe class=\"sample-code-frame\" title=\"The where exception sample\" id=\"frame_the_where_exception\" src=\"https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Web/CSS/Specificity/_sample_.the_where_exception.html\" loading=\"lazy\">\n</iframe>\n<br>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#form-based_specificity\" title=\"Permalink to Form-based specificity\">Form-based specificity</a></h3>\n<p>Specificity is based on the form of a selector. In the following case, the selector <code class=\"language-text\">*[id=\"foo\"]</code> counts as an attribute selector for the purpose of determining the selector's specificity, even though it selects an ID.</p>\n<p>The following CSS styles ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">*#foo {\n  color: green;\n}\n\n*[id=\"foo\"] {\n  color: purple;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... when used with this markup ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p id=\"foo\">I am a sample text.&lt;/p></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... end up looking like this:</p>\n<iframe class=\"sample-code-frame\" title=\"Form-based specificity sample\" id=\"frame_form-based_specificity\" src=\"https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Web/CSS/Specificity/_sample_.form-based_specificity.html\" loading=\"lazy\">\n</iframe>\n<br>\n<p>This is because it matches the same element but the ID selector has a higher specificity.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#tree_proximity_ignorance\" title=\"Permalink to Tree proximity ignorance\">Tree proximity ignorance</a></h3>\n<p>The proximity of an element to other elements that are referenced in a given selector has no impact on specificity. The following style declaration ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">body h1 {\n  color: green;\n}\n\nhtml h1 {\n  color: purple;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... with the following HTML ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;html>\n  &lt;body>\n    &lt;h1>Here is a title!&lt;/h1>\n  &lt;/body>\n&lt;/html></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... will render as:</p>\n<iframe class=\"sample-code-frame\" title=\"Tree proximity ignorance sample\" id=\"frame_tree_proximity_ignorance\" src=\"https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Web/CSS/Specificity/_sample_.tree_proximity_ignorance.html\" loading=\"lazy\">\n</iframe>\n<br>\n<p>This is because the two declarations have equal <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#selector_types\">selector type</a> counts, but the <code class=\"language-text\">html h1</code> selector is declared last.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity#directly_targeted_elements_vs._inherited_styles\" title=\"Permalink to Directly targeted elements vs. inherited styles\">Directly targeted elements vs. inherited styles</a></h3>\n<p>Styles for a directly targeted element will always take precedence over inherited styles, regardless of the specificity of the inherited rule. This CSS ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#parent {\n  color: green;\n}\n\nh1 {\n  color: purple;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... with the following HTML ...</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;html>\n  &lt;body id=\"parent\">\n    &lt;h1>Here is a title!&lt;/h1>\n  &lt;/body>\n&lt;/html></code></pre></div>\n<p>Copy to Clipboard</p>\n<p>... will also render as:</p>\n<iframe class=\"sample-code-frame\" title=\"Directly targeted elements vs. inherited styles sample\" id=\"frame_directly_targeted_elements_vs._inherited_styles\" src=\"https://yari-demos.prod.mdn.mozit.cloud/en-US/docs/Web/CSS/Specificity/_sample_.directly_targeted_elements_vs._inherited_styles.html\" loading=\"lazy\">\n</iframe>\n<br>\n<p>This is because the <code class=\"language-text\">h1</code> selector targets the element specifically, but the green selector is only inherited from its parent.</p>"},{"url":"/docs/css/the-box-model/","relativePath":"docs/css/the-box-model/index.md","relativeDir":"docs/css/the-box-model","base":"index.md","name":"index","frontmatter":{"title":"The Box Model","template":"docs","excerpt":"In CSS we broadly have two types of boxes"},"html":"<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#block_and_inline_boxes\" title=\"Permalink to Block and inline boxes\">Block and inline boxes</a></h2>\n<p>In CSS we broadly have two types of boxes — <strong>block boxes</strong> and <strong>inline boxes</strong>. These characteristics refer to how the box behaves in terms of page flow and in relation to other boxes on the page. Boxes also have an <strong>inner display type</strong> and an <strong>outer display type</strong>. First, we will explain what we mean by block box and inline box. We will then explain what is meant by an inner and outer display type.</p>\n<p>If a box has an outer display type of <code class=\"language-text\">block</code>, it will behave in the following ways:</p>\n<ul>\n<li>The box will break onto a new line.</li>\n<li>The box will extend in the inline direction to fill the space available in its container. In most cases this means that the box will become as wide as its container, filling up 100% of the space available.</li>\n<li>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/width\"><code class=\"language-text\">width</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/height\"><code class=\"language-text\">height</code></a> properties are respected.</li>\n<li>Padding, margin and border will cause other elements to be pushed away from the box.</li>\n</ul>\n<p>Some HTML elements, such as <code class=\"language-text\">&lt;h1></code> and <code class=\"language-text\">&lt;p></code>, use <code class=\"language-text\">block</code> as their outer display type by default.</p>\n<p>If a box has an outer display type of <code class=\"language-text\">inline</code>, then:</p>\n<ul>\n<li>The box will not break onto a new line.</li>\n<li>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/width\"><code class=\"language-text\">width</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/height\"><code class=\"language-text\">height</code></a> properties will not apply.</li>\n<li>Vertical padding, margins, and borders will apply but will not cause other inline boxes to move away from the box.</li>\n<li>Horizontal padding, margins, and borders will apply and will cause other inline boxes to move away from the box.</li>\n</ul>\n<p>Some HTML elements, such as <code class=\"language-text\">&lt;a></code>, <code class=\"language-text\">&lt;span></code>, <code class=\"language-text\">&lt;em></code> and <code class=\"language-text\">&lt;strong></code> use <code class=\"language-text\">inline</code> as their outer display type by default.</p>\n<p>The type of box applied to an element is defined by <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/display\"><code class=\"language-text\">display</code></a> property values such as <code class=\"language-text\">block</code> and <code class=\"language-text\">inline</code>, and relates to the <strong>outer</strong> value of <code class=\"language-text\">display</code>.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#aside_inner_and_outer_display_types\" title=\"Permalink to Aside: Inner and outer display types\">Aside: Inner and outer display types</a></h2>\n<p>At this point, we'd better also explain <strong>inner</strong> and <strong>outer</strong> display types. As mentioned above, boxes in CSS have an <em>outer</em> display type, which details whether the box is block or inline.</p>\n<p>Boxes also have an <em>inner</em> display type, however, which dictates how elements inside that box are laid out. By default, the elements inside a box are laid out in <strong><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Normal_Flow\">normal flow</a></strong>, which means that they behave just like any other block and inline elements (as explained above).</p>\n<p>We can, however, change the inner display type by using <code class=\"language-text\">display</code> values like <code class=\"language-text\">flex</code>. If we set <code class=\"language-text\">display: flex;</code> on an element, the outer display type is <code class=\"language-text\">block</code>, but the inner display type is changed to <code class=\"language-text\">flex</code>. Any direct children of this box will become flex items and will be laid out according to the rules set out in the <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox\">Flexbox</a> spec, which you'll learn about later on.</p>\n<p><strong>Note:</strong> To read more about the values of display, and how boxes work in block and inline layout, take a look at the MDN guide to <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flow_Layout/Block_and_Inline_Layout_in_Normal_Flow\">Block and Inline Layout</a>.</p>\n<p>When you move on to learn about CSS Layout in more detail, you will encounter <code class=\"language-text\">flex</code>, and various other inner values that your boxes can have, for example <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids\"><code class=\"language-text\">grid</code></a>.</p>\n<p>Block and inline layout, however, is the default way that things on the web behave — as we said above, it is sometimes referred to as <em>normal flow</em>, because without any other instruction, our boxes lay out as block or inline boxes.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#examples_of_different_display_types\" title=\"Permalink to Examples of different display types\">Examples of different display types</a></h2>\n<p>Let's move on and have a look at some examples. Below we have three different HTML elements, all of which have an outer display type of <code class=\"language-text\">block</code>. The first is a paragraph, which has a border added in CSS. The browser renders this as a block box, so the paragraph begins on a new line, and expands to the full width available to it.</p>\n<p>The second is a list, which is laid out using <code class=\"language-text\">display: flex</code>. This establishes flex layout for the items inside the container, however, the list itself is a block box and — like the paragraph — expands to the full container width and breaks onto a new line.</p>\n<p>Below this, we have a block-level paragraph, inside which are two <code class=\"language-text\">&lt;span></code> elements. These elements would normally be <code class=\"language-text\">inline</code>, however, one of the elements has a class of block, and we have set it to <code class=\"language-text\">display: block</code>.</p>\n<iframe width=\"100%\" height=\"1100\" src=\"https://mdn.github.io/css-examples/learn/box-model/block.html\" loading=\"lazy\">\n</iframe>\n<br>\n<p>In the next example, we can see how <code class=\"language-text\">inline</code> elements behave. The <code class=\"language-text\">&lt;span></code> elements in the first paragraph are inline by default and so do not force line breaks.</p>\n<p>We also have a <code class=\"language-text\">&lt;ul></code> element which is set to <code class=\"language-text\">display: inline-flex</code>, creating an inline box around some flex items.</p>\n<p>Finally, we have two paragraphs both set to <code class=\"language-text\">display: inline</code>. The inline flex container and paragraphs all run together on one line rather than breaking onto new lines as they would do if they were displaying as block-level elements.</p>\n<p><strong>In the example, you can change <code class=\"language-text\">display: inline</code> to <code class=\"language-text\">display: block</code> or <code class=\"language-text\">display: inline-flex</code> to <code class=\"language-text\">display: flex</code> to toggle between these display modes.</strong></p>\n<iframe width=\"100%\" height=\"1100\" src=\"https://mdn.github.io/css-examples/learn/box-model/inline.html\" loading=\"lazy\">\n</iframe>\n<br>\n<p>You will encounter things like flex layout later in these lessons; the key thing to remember for now is that changing the value of the <code class=\"language-text\">display</code> property can change whether the outer display type of a box is block or inline, which changes the way it displays alongside other elements in the layout.</p>\n<p>In the rest of the lesson, we will concentrate on the outer display type.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#what_is_the_css_box_model\" title=\"Permalink to What is the CSS box model?\">What is the CSS box model?</a></h2>\n<p>The CSS box model as a whole applies to block boxes. Inline boxes use just <em>some</em> of the behavior defined in the box model. The model defines how the different parts of a box — margin, border, padding, and content — work together to create a box that you can see on a page. To add some additional complexity, there is a standard and an alternate box model.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#parts_of_a_box\" title=\"Permalink to Parts of a box\">Parts of a box</a></h3>\n<p>Making up a block box in CSS we have the:</p>\n<ul>\n<li><strong>Content box</strong>: The area where your content is displayed, which can be sized using properties like <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/width\"><code class=\"language-text\">width</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/height\"><code class=\"language-text\">height</code></a>.</li>\n<li><strong>Padding box</strong>: The padding sits around the content as white space; its size can be controlled using <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/padding\"><code class=\"language-text\">padding</code></a> and related properties.</li>\n<li><strong>Border box</strong>: The border box wraps the content and any padding. Its size and style can be controlled using <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border\"><code class=\"language-text\">border</code></a> and related properties.</li>\n<li><strong>Margin box</strong>: The margin is the outermost layer, wrapping the content, padding, and border as whitespace between this box and other elements. Its size can be controlled using <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/margin\"><code class=\"language-text\">margin</code></a> and related properties.</li>\n</ul>\n<p>The below diagram shows these layers:</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model/box-model.png\" alt=\"Diagram of the box model\"></p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#the_standard_css_box_model\" title=\"Permalink to The standard CSS box model\">The standard CSS box model</a></h3>\n<p>In the standard box model, if you give a box a <code class=\"language-text\">width</code> and a <code class=\"language-text\">height</code> attribute, this defines the width and height of the <em>content box</em>. Any padding and border is then added to that width and height to get the total size taken up by the box. This is shown in the image below.</p>\n<p>If we assume that a box has the following CSS defining <code class=\"language-text\">width</code>, <code class=\"language-text\">height</code>, <code class=\"language-text\">margin</code>, <code class=\"language-text\">border</code>, and <code class=\"language-text\">padding</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.box {\n  width: 350px;\n  height: 150px;\n  margin: 10px;\n  padding: 25px;\n  border: 5px solid black;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>The <em>actual</em> space taken up by the box will be 410px wide (350 + 25 + 25 + 5 + 5) and 210px high (150 + 25 + 25 + 5 + 5).</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model/standard-box-model.png\" alt=\"Showing the size of the box when the standard box model is being used.\"></p>\n<p><strong>Note:</strong> The margin is not counted towards the actual size of the box — sure, it affects the total space that the box will take up on the page, but only the space outside the box. The box's area stops at the border — it does not extend into the margin.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#the_alternative_css_box_model\" title=\"Permalink to The alternative CSS box model\">The alternative CSS box model</a></h3>\n<p>You might think it is rather inconvenient to have to add up the border and padding to get the real size of the box, and you would be right! For this reason, CSS had an alternative box model introduced some time after the standard box model. Using this model, any width is the width of the visible box on the page, therefore the content area width is that width minus the width for the padding and border. The same CSS as used above would give the below result (width = 350px, height = 150px).</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model/alternate-box-model.png\" alt=\"Showing the size of the box when the alternate box model is being used.\"></p>\n<p>By default, browsers use the standard box model. If you want to turn on the alternative model for an element, you do so by setting <code class=\"language-text\">box-sizing: border-box</code> on it. By doing this, you are telling the browser to use the border box, as shown above, as your defined area.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.box {\n  box-sizing: border-box;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p>If you want all of your elements to use the alternative box model, and this is a common choice among developers, set the <code class=\"language-text\">box-sizing</code> property on the <code class=\"language-text\">&lt;html></code> element, then set all other elements to inherit that value, as seen in the snippet below. If you want to understand the thinking behind this, see <a href=\"https://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/\">the CSS Tricks article on box-sizing</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">html {\n  box-sizing: border-box;\n}\n*, *::before, *::after {\n  box-sizing: inherit;\n}</code></pre></div>\n<p>Copy to Clipboard</p>\n<p><strong>Note:</strong> An interesting bit of history — Internet Explorer used to default to the alternative box model, with no mechanism available to switch.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#playing_with_box_models\" title=\"Permalink to Playing with box models\">Playing with box models</a></h2>\n<p>In the example below, you can see two boxes. Both have a class of <code class=\"language-text\">.box</code>, which gives them the same <code class=\"language-text\">width</code>, <code class=\"language-text\">height</code>, <code class=\"language-text\">margin</code>, <code class=\"language-text\">border</code>, and <code class=\"language-text\">padding</code>. The only difference is that the second box has been set to use the alternative box model.</p>\n<p><strong>Can you change the size of the second box (by adding CSS to the <code class=\"language-text\">.alternate</code> class) to make it match the first box in width and height?</strong></p>\n<iframe width=\"100%\" height=\"1100\" src=\"https://mdn.github.io/css-examples/learn/box-model/box-models.html\" loading=\"lazy\">\n</iframe>\n<br>\n<p><strong>Note:</strong> You can find a solution for this task <a href=\"https://github.com/mdn/css-examples/blob/main/learn/solutions.md#the-box-model\">here</a>.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#use_browser_devtools_to_view_the_box_model\" title=\"Permalink to Use browser DevTools to view the box model\">Use browser DevTools to view the box model</a></h3>\n<p>Your <a href=\"https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools\">browser developer tools</a> can make understanding the box model far easier. If you inspect an element in Firefox's DevTools, you can see the size of the element plus its margin, padding, and border. Inspecting an element in this way is a great way to find out if your box is really the size you think it is!</p>\n<p><img src=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model/box-model-devtools.png\" alt=\"Inspecting the box model of an element using Firefox DevTools\"></p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#margins_padding_and_borders\" title=\"Permalink to Margins, padding, and borders\">Margins, padding, and borders</a></h2>\n<p>You've already seen the <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/margin\"><code class=\"language-text\">margin</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/padding\"><code class=\"language-text\">padding</code></a>, and <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border\"><code class=\"language-text\">border</code></a> properties at work in the example above. The properties used in that example are <strong>shorthands</strong> and allow us to set all four sides of the box at once. These shorthands also have equivalent longhand properties, which allow control over the different sides of the box individually.</p>\n<p>Let's explore these properties in more detail.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#margin\" title=\"Permalink to Margin\">Margin</a></h3>\n<p>The margin is an invisible space around your box. It pushes other elements away from the box. Margins can have positive or negative values. Setting a negative margin on one side of your box can cause it to overlap other things on the page. Whether you are using the standard or alternative box model, the margin is always added after the size of the visible box has been calculated.</p>\n<p>We can control all margins of an element at once using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/margin\"><code class=\"language-text\">margin</code></a> property, or each side individually using the equivalent longhand properties:</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/margin-top\"><code class=\"language-text\">margin-top</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/margin-right\"><code class=\"language-text\">margin-right</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/margin-bottom\"><code class=\"language-text\">margin-bottom</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/margin-left\"><code class=\"language-text\">margin-left</code></a></li>\n</ul>\n<p><strong>In the example below, try changing the margin values to see how the box is pushed around due to the margin creating or removing space (if it is a negative margin) between this element and the containing element.</strong></p>\n<iframe width=\"100%\" height=\"800\" src=\"https://mdn.github.io/css-examples/learn/box-model/margin.html\" loading=\"lazy\">\n</iframe>\n<br>\n<h4>Margin collapsing</h4>\n<p>A key thing to understand about margins is the concept of <strong>margin collapsing</strong>. If you have two elements whose margins touch, and both margins are positive, those margins will combine to become one margin, and its size will be equal to the largest individual margin. If one margin is negative, its value will be <em>subtracted</em> from the total. Where both are negative, the margins will collapse and the smallest (furthest from zero) value will be used.</p>\n<p>In the example below, we have two paragraphs. The top paragraph has a <code class=\"language-text\">margin-bottom</code> of 50 pixels. The second paragraph has a <code class=\"language-text\">margin-top</code> of 30 pixels. The margins have collapsed together so the actual margin between the boxes is 50 pixels and not the total of the two margins.</p>\n<p><strong>You can test this by setting the <code class=\"language-text\">margin-top</code> of paragraph two to 0. The visible margin between the two paragraphs will not change — it retains the 50 pixels set in the <code class=\"language-text\">margin-bottom</code> of paragraph one. If you set it to -10px, you'll see that the overall margin becomes 40px — it subtracts from the 50px.</strong></p>\n<iframe width=\"100%\" height=\"800\" src=\"https://mdn.github.io/css-examples/learn/box-model/margin-collapse.html\" loading=\"lazy\">\n</iframe>\n<br>\n<p>There are a number of rules that dictate when margins do and do not collapse. For further information see the detailed page on <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Mastering_margin_collapsing\">mastering margin collapsing</a>. The main thing to remember for now is that margin collapsing is a thing that happens. If you are creating space with margins and don't get the space you expect, this is probably what is happening.</p>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#borders\" title=\"Permalink to Borders\">Borders</a></h3>\n<p>The border is drawn between the margin and the padding of a box. If you are using the standard box model, the size of the border is added to the <code class=\"language-text\">width</code> and <code class=\"language-text\">height</code> of the box. If you are using the alternative box model then the size of the border makes the content box smaller as it takes up some of that available <code class=\"language-text\">width</code> and <code class=\"language-text\">height</code>.</p>\n<p>For styling borders, there are a large number of properties — there are four borders, and each border has a style, width, and color that we might want to manipulate.</p>\n<p>You can set the width, style, or color of all four borders at once using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border\"><code class=\"language-text\">border</code></a> property.</p>\n<p>To set the properties of each side individually, you can use:</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-top\"><code class=\"language-text\">border-top</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-right\"><code class=\"language-text\">border-right</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-bottom\"><code class=\"language-text\">border-bottom</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-left\"><code class=\"language-text\">border-left</code></a></li>\n</ul>\n<p>To set the width, style, or color of all sides, use the following:</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-width\"><code class=\"language-text\">border-width</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-style\"><code class=\"language-text\">border-style</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-color\"><code class=\"language-text\">border-color</code></a></li>\n</ul>\n<p>To set the width, style, or color of a single side, you can use one of the more granular longhand properties:</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-top-width\"><code class=\"language-text\">border-top-width</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-top-style\"><code class=\"language-text\">border-top-style</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-top-color\"><code class=\"language-text\">border-top-color</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-right-width\"><code class=\"language-text\">border-right-width</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-right-style\"><code class=\"language-text\">border-right-style</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-right-color\"><code class=\"language-text\">border-right-color</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-bottom-width\"><code class=\"language-text\">border-bottom-width</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-bottom-style\"><code class=\"language-text\">border-bottom-style</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-bottom-color\"><code class=\"language-text\">border-bottom-color</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-left-width\"><code class=\"language-text\">border-left-width</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-left-style\"><code class=\"language-text\">border-left-style</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/border-left-color\"><code class=\"language-text\">border-left-color</code></a></li>\n</ul>\n<p>In the example below, we have used various shorthands and longhands to create borders. Play around with the different properties to check that you understand how they work. The MDN pages for the border properties give you information about the different styles of border you can choose from.</p>\n<iframe width=\"100%\" height=\"700\" src=\"https://mdn.github.io/css-examples/learn/box-model/border.html\" loading=\"lazy\">\n</iframe>\n<br>\n<h3><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#padding\" title=\"Permalink to Padding\">Padding</a></h3>\n<p>The padding sits between the border and the content area. Unlike margins, you cannot have negative amounts of padding, so the value must be 0 or a positive value. Padding is typically used to push the content away from the border. Any background applied to your element will display behind the padding.</p>\n<p>We can control the padding on all sides of an element using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/padding\"><code class=\"language-text\">padding</code></a> property, or on each side individually using the equivalent longhand properties:</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/padding-top\"><code class=\"language-text\">padding-top</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/padding-right\"><code class=\"language-text\">padding-right</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/padding-bottom\"><code class=\"language-text\">padding-bottom</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/padding-left\"><code class=\"language-text\">padding-left</code></a></li>\n</ul>\n<p><strong>If you change the values for padding on the class <code class=\"language-text\">.box</code> in the example below, you can see that this changes where the text begins in relation to the box.</strong></p>\n<p><strong>You can also change the padding on the class <code class=\"language-text\">.container,</code> which will make space between the container and the box. Padding can be changed on any element, and will make space between its border and whatever is inside the element.</strong></p>\n<iframe width=\"100%\" height=\"700\" src=\"https://mdn.github.io/css-examples/learn/box-model/padding.html\" loading=\"lazy\">\n</iframe>\n<br>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#the_box_model_and_inline_boxes\" title=\"Permalink to The box model and inline boxes\">The box model and inline boxes</a></h2>\n<p>All of the above applies fully to block boxes. Some of the properties can apply to inline boxes too, such as those created by a <code class=\"language-text\">&lt;span></code> element.</p>\n<p>In the example below, we have a <code class=\"language-text\">&lt;span></code> inside a paragraph and have applied a <code class=\"language-text\">width</code>, <code class=\"language-text\">height</code>, <code class=\"language-text\">margin</code>, <code class=\"language-text\">border</code>, and <code class=\"language-text\">padding</code> to it. You can see that the width and height are ignored. The vertical margin, padding, and border are respected but they do not change the relationship of other content to our inline box and so the padding and border overlaps other words in the paragraph. Horizontal padding, margins, and borders are respected and will cause other content to move away from the box.</p>\n<iframe width=\"100%\" height=\"700\" src=\"https://mdn.github.io/css-examples/learn/box-model/inline-box-model.html\" loading=\"lazy\">\n</iframe>\n<br>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#using_display_inline-block\" title=\"Permalink to Using display: inline-block\">Using display: inline-block</a></h2>\n<p>There is a special value of <code class=\"language-text\">display</code>, which provides a middle ground between <code class=\"language-text\">inline</code> and <code class=\"language-text\">block</code>. This is useful for situations where you do not want an item to break onto a new line, but do want it to respect <code class=\"language-text\">width</code> and <code class=\"language-text\">height</code> and avoid the overlapping seen above.</p>\n<p>An element with <code class=\"language-text\">display: inline-block</code> does a subset of the block things we already know about:</p>\n<ul>\n<li>The <code class=\"language-text\">width</code> and <code class=\"language-text\">height</code> properties are respected.</li>\n<li><code class=\"language-text\">padding</code>, <code class=\"language-text\">margin</code>, and <code class=\"language-text\">border</code> will cause other elements to be pushed away from the box.</li>\n</ul>\n<p>It does not, however, break onto a new line, and will only become larger than its content if you explicitly add <code class=\"language-text\">width</code> and <code class=\"language-text\">height</code> properties.</p>\n<p><strong>In this next example, we have added <code class=\"language-text\">display: inline-block</code> to our <code class=\"language-text\">&lt;span></code> element. Try changing this to <code class=\"language-text\">display: block</code> or removing the line completely to see the difference in display models.</strong></p>\n<iframe width=\"100%\" height=\"800\" src=\"https://mdn.github.io/css-examples/learn/box-model/inline-block.html\" loading=\"lazy\">\n</iframe>\n<br>\n<p>Where this can be useful is when you want to give a link a larger hit area by adding <code class=\"language-text\">padding</code>. <code class=\"language-text\">&lt;a></code> is an inline element like <code class=\"language-text\">&lt;span></code>; you can use <code class=\"language-text\">display: inline-block</code> to allow padding to be set on it, making it easier for a user to click the link.</p>\n<p>You see this fairly frequently in navigation bars. The navigation below is displayed in a row using flexbox and we have added padding to the <code class=\"language-text\">&lt;a></code> element as we want to be able to change the <code class=\"language-text\">background-color</code> when the <code class=\"language-text\">&lt;a></code> is hovered. The padding appears to overlap the border on the <code class=\"language-text\">&lt;ul></code> element. This is because the <code class=\"language-text\">&lt;a></code> is an inline element.</p>\n<p><strong>Add <code class=\"language-text\">display: inline-block</code> to the rule with the <code class=\"language-text\">.links-list a</code> selector, and you will see how it fixes this issue by causing the padding to be respected by other elements.</strong></p>\n<iframe width=\"100%\" height=\"700\" src=\"https://mdn.github.io/css-examples/learn/box-model/inline-block-nav.html\" loading=\"lazy\">\n</iframe>\n<br>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#test_your_skills!\" title=\"Permalink to Test your skills!\">Test your skills!</a></h2>\n<p>You've reached the end of this article, but can you remember the most important information? You can find some further tests to verify that you've retained this information before you move on — see <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Box_Model_Tasks\">Test your skills: The Box Model</a>.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model#summary\" title=\"Permalink to Summary\">Summary</a></h2>\n<p>That's most of what you need to understand about the box model. You may want to return to this lesson in the future if you ever find yourself confused about how big boxes are in your layout.</p>\n<p>In the next article, we'll take a look at how <a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Backgrounds_and_borders\">backgrounds and borders</a> can be used to make your plain boxes look more interesting.</p>"},{"url":"/docs/javascript/asynchronous-javascript-and-xml/","relativePath":"docs/javascript/asynchronous-javascript-and-xml/index.md","relativeDir":"docs/javascript/asynchronous-javascript-and-xml","base":"index.md","name":"index","frontmatter":{"title":"Asynchronous JavaScript and XML","template":"docs","excerpt":"This article guides you through the Ajax basics "},"html":"<!--StartFragment-->\n<p><strong>Asynchronous JavaScript and XML</strong>, while not a technology in itself, is a term coined in 2005 by Jesse James Garrett, that describes a \"new\" approach to using a number of existing technologies together, including <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML\">HTML</a> or <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/XHTML\">XHTML</a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS\">CSS</a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript\">JavaScript</a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model\">DOM</a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/XML\">XML</a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/XSLT\">XSLT</a>, and most importantly the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\"><code class=\"language-text\">XMLHttpRequest</code></a> object. When these technologies are combined in the Ajax model, web applications are able to make quick, incremental updates to the user interface without reloading the entire browser page. This makes the application faster and more responsive to user actions.</p>\n<p>Although X in Ajax stands for XML, <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/JSON\">JSON</a> is preferred over XML nowadays because of its many advantages such as being a part of JavaScript, thus being lighter in size. Both JSON and XML are used for packaging information in the Ajax model.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX#documentation\" title=\"Permalink to Documentation\">Documentation</a></h2>\n<p>This article guides you through the Ajax basics and gives you two simple hands-on examples to get you started.</p>\n<ul>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest\">Using the <code class=\"language-text\">XMLHttpRequest</code> API</a></p>\n<p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\"><code class=\"language-text\">XMLHttpRequest</code></a> API is the core of Ajax. This article will explain how to use some Ajax techniques, like:</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#handling_responses\">Analyzing and manipulating the response of the server</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#monitoring_progress\">Monitoring the progress of a request</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#submitting_forms_and_uploading_files\">Submitting forms and upload binary files</a> – in <em>pure</em> Ajax, or using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FormData\"><code class=\"language-text\">FormData</code></a> objects</li>\n<li>Using Ajax within <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Worker\">Web workers</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\">Fetch API</a></p>\n<p>The Fetch API provides an interface for fetching resources. It will seem familiar to anyone who has used <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\"><code class=\"language-text\">XMLHTTPRequest</code></a>, but this API provides a more powerful and flexible feature set.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events\">Server-sent events</a></p>\n<p>Traditionally, a web page has to send a request to the server to receive new data; that is, the page requests data from the server. With server-sent events, it's possible for a server to send new data to a web page at any time, by pushing messages to the web page. These incoming messages can be treated as <em><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Event\">Events</a> + data</em> inside the web page. See also: <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events\">Using server-sent events</a>.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API/Example\"><em>Pure-Ajax</em> navigation example</a></p>\n<p>This article provides a working (minimalist) example of a <em>pure-Ajax</em> website composed only of three pages.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data\">Sending and Receiving Binary Data</a></p>\n<p>The <code class=\"language-text\">responseType</code> property of the <code class=\"language-text\">XMLHttpRequest</code> object can be set to change the expected response type from the server. Possible values are the empty string (default), <code class=\"language-text\">arraybuffer</code>, <code class=\"language-text\">blob</code>, <code class=\"language-text\">document</code>, <code class=\"language-text\">json</code>, and <code class=\"language-text\">text</code>. The <code class=\"language-text\">response</code> property will contain the entity body according to <code class=\"language-text\">responseType</code>, as an <code class=\"language-text\">ArrayBuffer</code>, <code class=\"language-text\">Blob</code>, <code class=\"language-text\">Document</code>, <code class=\"language-text\">JSON</code>, or string. This article will show some Ajax I/O techniques.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/XML\">XML</a></p>\n<p>The <strong>Extensible Markup Language (XML)</strong> is a W3C-recommended general-purpose markup language for creating special-purpose markup languages. It is a simplified subset of SGML, capable of describing many different kinds of data. Its primary purpose is to facilitate the sharing of data across different systems, particularly systems connected via the Internet.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/Guide/Parsing_and_serializing_XML\">Parsing and serializing XML</a></p>\n<p>How to parse an XML document from a string, a file or via JavaScript and how to serialize XML documents to strings, Javascript Object trees (JXON) or files.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/XPath\">XPath</a></p>\n<p>XPath stands for <strong>X</strong>ML <strong>Path</strong> Language, it uses a non-XML syntax that provides a flexible way of addressing (pointing to) different parts of an <a href=\"https://developer.mozilla.org/en-US/docs/Web/XML\">XML</a> document. As well as this, it can also be used to test addressed nodes within a document to determine whether they match a pattern or not.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileReader\"><code class=\"language-text\">FileReader</code></a> API</p>\n<p>The <code class=\"language-text\">FileReader</code> API lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/File\"><code class=\"language-text\">File</code></a> or <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Blob\"><code class=\"language-text\">Blob</code></a> objects to specify the file or data to read. File objects may be obtained from a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileList\"><code class=\"language-text\">FileList</code></a> object returned as a result of a user selecting files using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input\"><code class=\"language-text\">&lt;input></code></a> element, from a drag and drop operation's <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer\"><code class=\"language-text\">DataTransfer</code></a> object, or from the <code class=\"language-text\">mozGetAsFile()</code> API on an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement\"><code class=\"language-text\">HTMLCanvasElement</code></a>.</p>\n</li>\n<li>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/HTML_in_XMLHttpRequest\">HTML in XMLHttpRequest</a></p>\n<p>The <a href=\"https://xhr.spec.whatwg.org/\">XMLHttpRequest</a> specification adds HTML parsing support to <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\"><code class=\"language-text\">XMLHttpRequest</code></a>, which originally supported only XML parsing. This feature allows Web apps to obtain an HTML resource as a parsed DOM using <code class=\"language-text\">XMLHttpRequest</code>.</p>\n</li>\n</ul>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX#tools\" title=\"Permalink to Tools\">Tools</a></h2>\n<ul>\n<li>\n<p><a href=\"https://github.com/axios/axios\">axios</a></p>\n<p><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\"><code class=\"language-text\">Promise</code></a> based <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/HTTP\">HTTP</a> client, which uses <code class=\"language-text\">XMLHttpRequest</code> internally.</p>\n</li>\n</ul>\n<!--EndFragment-->"},{"url":"/docs/ds-algo/big-o/","relativePath":"docs/ds-algo/big-o/index.md","relativeDir":"docs/ds-algo/big-o","base":"index.md","name":"index","frontmatter":{"title":"Big O","template":"docs","excerpt":" big picture, broad strokes, not details"},"html":"<!--StartFragment-->\n<h1>A Very Quick Guide To Calculating Big O Computational Complexity</h1>\n<h1>A Very Quick Guide To Calculating Big O Computational Complexity</h1>\n<p><strong>Big O</strong>: big picture, broad strokes, not details</p>\n<p><img src=\"https://miro.medium.com/max/630/0*lte81mEvgEPYXodB.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/304/1*5t2u8n1uKhioIzZIXX2zbg.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/563/1*HhXmG2cNdg8y4ZCCQGTyuQ.png\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/1*ULeXxVCDkF73GwhsxyM_2g.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/900/1*hkZWlUgFyOSaLD5Uskv0tQ.png\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1115/1*COjzunj0-FsMJ0d7v7Z-6g.png\" alt=\"medium blog image\"></p>\n<p>For a more complete guide… checkout :</p>\n<ul>\n<li>way we analyze how efficient algorithms are without getting too mired in details</li>\n<li>*</li>\n<li>can model how much time any function will take given n inputs</li>\n<li>*</li>\n<li>interested in order of magnitude of number of the exact figure</li>\n<li>O absorbs all fluff and n = biggest term</li>\n<li>Big O of 3x^2 +x + 1 = O(n^2)</li>\n</ul>\n<h1>Time Complexity</h1>\n<p>no loops or exit &#x26; return = O(1)</p>\n<p>0 nested loops = O(n) 1 nested loops = O(n^2) 2 nested loops = O(n^3) 3 nested loops = O(n^4)</p>\n<p><strong>recursive</strong>: as you add more terms, increase in time as you add input diminishes <strong>recursion</strong>: when you define something in terms of itself, a function that calls itself</p>\n<ul>\n<li>used because of ability to maintain state at diffferent levels of recursion</li>\n<li>*</li>\n<li>inherently carries large footprint</li>\n<li>every time function called, you add call to stack</li>\n</ul>\n<p><strong>iterative</strong>: use loops instead of recursion (preferred) - favor readability over performance</p>\n<p>O(n log(n)) &#x26; O(log(n)): dividing/halving</p>\n<ul>\n<li>if code employs recursion/divide-and-conquer strategy</li>\n<li>*</li>\n<li>what power do i need to power my base to get n</li>\n</ul>\n<h1>Time Definitions</h1>\n<ul>\n<li><strong>constant</strong>: does not scale with input, will take same amount of time</li>\n<li>*</li>\n<li>for any input size n, constant time performs same number of operations every time</li>\n<li>*</li>\n<li>**logarit</li>\n<li>*</li>\n<li>function log n grows very slowly, so as n gets longer, number of operations the algorithm needs to perform</li>\n<li>*</li>\n<li>halving</li>\n<li>*</li>\n<li><strong>linear</strong>: increases number of operations it performs as linear function of input size n</li>\n<li>*</li>\n<li>number of additional operations needed to perform grows in direct proportion to increase in</li>\n<li>*</li>\n<li><strong>log-linear</strong>: increases number of operations it performs as log-linear function of input size n</li>\n<li>looking over every element and doing work on each one</li>\n<li><strong>quadratic</strong>: increases number of operations it performs as quadratic function of input size n</li>\n<li><strong>exponential</strong>: increases number of operations it performs as exponential function of input size n</li>\n<li>number of nested loops increases as function of n</li>\n<li><strong>polynomial</strong>: as size of input increases, runtime/space used will grow at a faster rate</li>\n<li><strong>factorial</strong>: as size of input increases, runtime/space used will grow astronomically even with relatively small inputs</li>\n<li><strong>rate of growth</strong>: how fast a function grows with input size</li>\n</ul>\n<h1>Space Complexity</h1>\n<ul>\n<li>How does the space usage scale/change as input gets very large?</li>\n<li>*</li>\n<li>What auxiliary space does your algorithm use or is it in place (constant)?</li>\n<li>Runtime stack space counts as part of space complexity unless told otherwise.</li>\n</ul>\n<h1>Data Structures &#x26; Algos In JS</h1>\n<!--EndFragment-->"},{"url":"/docs/archive/archive/embeded-websites/","relativePath":"docs/archive/archive/embeded-websites.md","relativeDir":"docs/archive/archive","base":"embeded-websites.md","name":"embeded-websites","frontmatter":{"title":"Family Promise Project","weight":0,"seo":{"title":"Gatsby Plugins For This Sites Content Model","description":"This is my markdown notes tempate","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Gatsby Plugins For This Sites Content Model","keyName":"property"},{"name":"og:description","value":"This is the Gatsby Plugins For This Sites Content Model page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Gatsby Plugins For This Sites Content Model"},{"name":"twitter:description","value":"This is the Gatsby Plugins For This Sites Content Model page"}]},"template":"docs","excerpt":"Family Promise organizes congregations, social service agencies and community members into volunteer coalitions called Affiliates that provide emergency shelter and wraparound services to homeless and at-risk families. The model of the core program emphasizes sustainability and relies on resources that are already available to the locales served. Though each Affiliate coordinates its own programming for transitional housing, case management, family mentoring, financial literacy classes and childcare, all receive staff training and program assistance from the national office. Built a way to track and visualize the services they provide external to the shelter to gain actionable insights."},"html":"<br>\n<br>\n<br>\n<h1>Family Promise Project:</h1>\n<h1>Table of contents</h1>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/README\">Home</a></li>\n</ul>\n<h2>navigation</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/navigation\">NAVIGATION</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/calendar\">Calendar</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/youtube\">Youtube:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/roadmap\">Roadmap:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/team-members\">TEAM MEMBERS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/running-list-of-notes-links-and-pertinent-info-from-meetings\">Running List Of Notes Links &#x26; Pertinent Info From Meetings</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/trello/README\">Trello</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/trello/github-trello-integration\">Github/Trello Integration</a></li>\n</ul>\n</li>\n</ul>\n<h2>UX</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/README\">UX_TOPICS</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/action-items\">Action Items:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/accessibility\">Accessibility</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/README\">Figma Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/notes\">Notes</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/prototyping-in-figma\">Prototyping In Figma</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/figma-notes/more-notes\">More Notes</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ux-design/README\">UX-Design</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ux-design/facebook-graph-api\">Facebook Graph API</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/README\">Ant Design</a></p>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-components/README\">ANT Components</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-components/buttons\">Buttons</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/ant-docs\">ANT DOCS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/ant-design/application-codesandbox\">Application (Codesandbox)</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/examples\">Examples</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ux/untitled/how-to-add-external-url-links-to-your-prototype\">How to add external URL links to your prototype</a></li>\n</ul>\n</li>\n</ul>\n<h2>CANVAS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/README\">Design</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/whats-inclusive-design\">What's Inclusive Design?</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/accessibility\">Accessibility</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/design/what-are-design-systems\">What are Design Systems?</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/canvas\">Canvas</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/README\">Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/user-experience-design\">User Experience Design</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/user-research\">User Research</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/notes/interaction-design\">Interaction Design</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/README\">UX-Engineer</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/patterns\">Patterns</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/design-tools\">Design Tools</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/design-critiques\">Design Critiques</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/product-review\">Product Review</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/quiz\">Quiz</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/canvas/ux-engineer/seven-principles-of-design\">Seven Principles of Design</a></li>\n</ul>\n</li>\n</ul>\n<h2>Front End</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/front-end/untitled\">Frontend:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/front-end/redux\">Redux</a></li>\n</ul>\n<h2>Back End</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/back-end/untitled/README\">Backend:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/back-end/untitled/api\">API</a></li>\n</ul>\n</li>\n</ul>\n<h2>Research</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/README\">Research Navigation</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/front-end\">Front End</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/back-end\">Back End</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/ux\">UX</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/ptm\">PTM</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/research/untitled/general\">General</a></li>\n</ul>\n</li>\n</ul>\n<h2>DS_API</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/ds_api/untitled\">Data Science API</a></li>\n</ul>\n<h2>ROLES</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/roles/untitled/README\">TEAM ROLES</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/roles/untitled/bryan-guner\">Bryan Guner</a></li>\n</ul>\n</li>\n</ul>\n<h2>Action Items</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/action-items/untitled\">Trello</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/action-items/maps\">Maps</a></li>\n</ul>\n<h2>ARCHITECTURE</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/dns\">DNS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/aws\">AWS</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/architecture/heroku\">Heroku</a></li>\n</ul>\n<h2>Questions</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/questions/from-previous-cohort\">From Previous Cohort</a></li>\n</ul>\n<h2>Standup Notes</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/README\">Meeting Notes</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/overview\">Stakeholder Meeting 1</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/standup-notes/meeting-notes/9-29-2021\">9/29/2021</a></li>\n</ul>\n</li>\n</ul>\n<h2>GitHub &#x26; Project Practice</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/README\">GitHub</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/untitled\">Github Guide</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/github-and-project-practice/untitled/github-actions\">Github Actions:</a></li>\n</ul>\n</li>\n</ul>\n<h2>MISC</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/misc/untitled\">MISCELLANEOUS</a></li>\n</ul>\n<h2>Background Information</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/README\">Background Info</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/swagger-open-api-specification\">Swagger OPEN API SPECIFICATION</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/README\">GITHUB:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/git-bash\">Git Bash</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/background-information/background-info/github/git-prune\">Git Prune:</a></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<h2>DOCS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/README\">Coding</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/environment-variables\">Environment Variables</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/git-rebase\">Git Rebase:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/git-workflow\">Git Workflow:</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/coding/linting-and-formatting\">Linting and Formatting</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/README\">Project Docs</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/eng-docs-home\">Eng-Docs-Home</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/basic-node-api\">Basic Node API</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/contributing-to-this-scaffold-project\">Contributing to this scaffold project</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-docs/examples\">Examples:</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/project-description\">PROJECT DESCRIPTION (Feature List)</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-learners-guide\">Labs Learners Guide</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/README\">REACT</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/untitled\">Create React App</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/react/awesome-react\">Awesome React</a></li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/untitled\">Links</a></li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/README\">Labs Engineering Docs</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/okta-basics\">Okta Basics</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/roadmap\">Roadmap</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/docs/labs-engineering-docs/repositories\">Repositories</a></li>\n</ul>\n</li>\n</ul>\n<h2>Workflow</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/workflow/workflow\">Workflow</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/workflow/advice\">Advice</a></li>\n</ul>\n<h2>AWS</h2>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/README\">AWS</a></p>\n<ul>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/elastic-beanstalk/README\">Elastic Beanstalk</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/elastic-beanstalk/elastic-beanstalk-dns\">Elastic Beanstalk DNS</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/amplify/README\">Amplify:</a></p>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws/amplify/amplify-dns\">Amplify-DNS</a></li>\n</ul>\n</li>\n</ul>\n</li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/untitled-1\">Account Basics</a></li>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/aws/aws-networking\">AWS-Networking</a></li>\n</ul>\n<h2>Career &#x26; Job Hunt</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/career-and-job-hunt/career\">Career</a></li>\n</ul>\n<h2>Group 1</h2>\n<ul>\n<li><a href=\"https://bryan-guner.gitbook.io/lambda-labs/group-1/live-implementation\">Live Implementation</a></li>\n</ul>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://www.figma.com/embed?embed_host=share&url=https%3A%2F%2Fwww.figma.com%2Ffile%2FbOwyinWBikQ5jdEpSx5WcI%2FFamily-Promise-Copy\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"Family_Promise_embed\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/family-promise-embed-b434z?autoresize=1&fontsize=12&hidenavigation=1&theme=dark&view=preview\"\n     style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n     title=\"Family_Promise_embed\"\n     allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n     sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n   >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Family-Promise Application</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://a.familypromiseservicetracker.dev/dashboard\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>"},{"url":"/docs/css/css-flexbox/","relativePath":"docs/css/css-flexbox/index.md","relativeDir":"docs/css/css-flexbox","base":"index.md","name":"index","frontmatter":{"title":"CSS Flexbox","template":"docs","excerpt":"Since flexbox is a whole module and not a single property"},"html":"<h3>Basics and terminology</h3>\n<p>Since flexbox is a whole module and not a single property, it involves a lot of things including its whole set of properties. Some of them are meant to be set on the container (parent element, known as “flex container”) whereas the others are meant to be set on the children (said “flex items”).</p>\n<p>If “regular” layout is based on both block and inline flow directions, the flex layout is based on “flex-flow directions”. Please have a look at this figure from the specification, explaining the main idea behind the flex layout.</p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/11/00-basic-terminology.svg\" alt=\"A diagram explaining flexbox terminology. The size across the main axis of flexbox is called the main size, the other direction is the cross size. Those sizes have a main start, main end, cross start, and cross end.\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/11/00-basic-terminology.svg\" alt=\"A diagram explaining flexbox terminology. The size across the main axis of flexbox is called the main size, the other direction is the cross size. Those sizes have a main start, main end, cross start, and cross end.\"></p>\n<p>Items will be laid out following either the <code class=\"language-text\">main axis</code> (from <code class=\"language-text\">main-start</code> to <code class=\"language-text\">main-end</code>) or the cross axis (from <code class=\"language-text\">cross-start</code> to <code class=\"language-text\">cross-end</code>).</p>\n<ul>\n<li><strong>main axis</strong> – The main axis of a flex container is the primary axis along which flex items are laid out. Beware, it is not necessarily horizontal; it depends on the <code class=\"language-text\">flex-direction</code> property (see below).</li>\n<li><strong>main-start | main-end</strong> – The flex items are placed within the container starting from main-start and going to main-end.</li>\n<li><strong>main size</strong> – A flex item’s width or height, whichever is in the main dimension, is the item’s main size. The flex item’s main size property is either the ‘width’ or ‘height’ property, whichever is in the main dimension.</li>\n<li><strong>cross axis</strong> – The axis perpendicular to the main axis is called the cross axis. Its direction depends on the main axis direction.</li>\n<li><strong>cross-start | cross-end</strong> – Flex lines are filled with items and placed into the container starting on the cross-start side of the flex container and going toward the cross-end side.</li>\n<li><strong>cross size</strong> – The width or height of a flex item, whichever is in the cross dimension, is the item’s cross size. The cross size property is whichever of ‘width’ or ‘height’ that is in the cross dimension.</li>\n</ul>\n<h3><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flexbox-properties\"></a>Flexbox properties</h3>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/01-container.svg\" alt=\"image\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/01-container.svg\" alt=\"image\"></p>\n<h2><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-properties-for-the-parentflex-container\"></a>Properties for the Parent</h2>\n<p>(flex container)</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-display\"></a>display</h4>\n<p>This defines a flex container; inline or block depending on the given value. It enables a flex context for all its direct children.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span> <span class=\"token comment\">/* or inline-flex */</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Note that CSS columns have no effect on a flex container.</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flex-direction\"></a>flex-direction</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/flex-direction.svg\" alt=\"the four possible values of flex-direction being shown: top to bottom, bottom to top, right to left, and left to right\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/flex-direction.svg\" alt=\"the four possible values of flex-direction being shown: top to bottom, bottom to top, right to left, and left to right\"></p>\n<p>This establishes the main-axis, thus defining the direction flex items are placed in the flex container. Flexbox is (aside from optional wrapping) a single-direction layout concept. Think of flex items as primarily laying out either in horizontal rows or vertical columns.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">flex-direction</span><span class=\"token punctuation\">:</span> row | row-reverse | column | column-reverse<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">row</code> (default): left to right in <code class=\"language-text\">ltr</code>; right to left in <code class=\"language-text\">rtl</code></li>\n<li><code class=\"language-text\">row-reverse</code>: right to left in <code class=\"language-text\">ltr</code>; left to right in <code class=\"language-text\">rtl</code></li>\n<li><code class=\"language-text\">column</code>: same as <code class=\"language-text\">row</code> but top to bottom</li>\n<li><code class=\"language-text\">column-reverse</code>: same as <code class=\"language-text\">row-reverse</code> but bottom to top</li>\n</ul>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flex-wrap\"></a>flex-wrap</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/flex-wrap.svg\" alt=\"two rows of boxes, the first wrapping down onto the second\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/flex-wrap.svg\" alt=\"two rows of boxes, the first wrapping down onto the second\"></p>\n<p>By default, flex items will all try to fit onto one line. You can change that and allow the items to wrap as needed with this property.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">flex-wrap</span><span class=\"token punctuation\">:</span> nowrap | wrap | wrap-reverse<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">nowrap</code> (default): all flex items will be on one line</li>\n<li><code class=\"language-text\">wrap</code>: flex items will wrap onto multiple lines, from top to bottom.</li>\n<li><code class=\"language-text\">wrap-reverse</code>: flex items will wrap onto multiple lines from bottom to top.</li>\n</ul>\n<p>There are some <a href=\"https://css-tricks.com/almanac/properties/f/flex-wrap/\">visual demos of <code class=\"language-text\">flex-wrap</code> here</a>.</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flex-flow\"></a>flex-flow</h4>\n<p>This is a shorthand for the <code class=\"language-text\">flex-direction</code> and <code class=\"language-text\">flex-wrap</code> properties, which together define the flex container’s main and cross axes. The default value is <code class=\"language-text\">row nowrap</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">flex-flow</span><span class=\"token punctuation\">:</span> column wrap<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-justify-content\"></a>justify-content</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/justify-content.svg\" alt=\"flex items within a flex container demonstrating the different spacing options\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/justify-content.svg\" alt=\"flex items within a flex container demonstrating the different spacing options\"></p>\n<p>This defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow the line.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">justify-content</span><span class=\"token punctuation\">:</span> flex-start | flex-end | center | space-between | space-around | space-evenly | start | end | left | right ... + safe | unsafe<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">flex-start</code> (default): items are packed toward the start of the flex-direction.</li>\n<li><code class=\"language-text\">flex-end</code>: items are packed toward the end of the flex-direction.</li>\n<li><code class=\"language-text\">start</code>: items are packed toward the start of the <code class=\"language-text\">writing-mode</code> direction.</li>\n<li><code class=\"language-text\">end</code>: items are packed toward the end of the <code class=\"language-text\">writing-mode</code> direction.</li>\n<li><code class=\"language-text\">left</code>: items are packed toward left edge of the container, unless that doesn’t make sense with the <code class=\"language-text\">flex-direction</code>, then it behaves like <code class=\"language-text\">start</code>.</li>\n<li><code class=\"language-text\">right</code>: items are packed toward right edge of the container, unless that doesn’t make sense with the <code class=\"language-text\">flex-direction</code>, then it behaves like <code class=\"language-text\">start</code>.</li>\n<li><code class=\"language-text\">center</code>: items are centered along the line</li>\n<li><code class=\"language-text\">space-between</code>: items are evenly distributed in the line; first item is on the start line, last item on the end line</li>\n<li><code class=\"language-text\">space-around</code>: items are evenly distributed in the line with equal space around them. Note that visually the spaces aren’t equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies.</li>\n<li><code class=\"language-text\">space-evenly</code>: items are distributed so that the spacing between any two items (and the space to the edges) is equal.</li>\n</ul>\n<p>Note that that browser support for these values is nuanced. For example, <code class=\"language-text\">space-between</code> never got support from some versions of Edge, and start/end/left/right aren’t in Chrome yet. MDN <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content\">has detailed charts</a>. The safest values are <code class=\"language-text\">flex-start</code>, <code class=\"language-text\">flex-end</code>, and <code class=\"language-text\">center</code>.</p>\n<p>There are also two additional keywords you can pair with these values: <code class=\"language-text\">safe</code> and <code class=\"language-text\">unsafe</code>. Using <code class=\"language-text\">safe</code> ensures that however you do this type of positioning, you can’t push an element such that it renders off-screen (e.g. off the top) in such a way the content can’t be scrolled too (called “data loss”).</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-align-items\"></a>align-items</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/align-items.svg\" alt=\"demonstration of differnet alignment options, like all boxes stuck to the top of a flex parent, the bottom, stretched out, or along a baseline\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/align-items.svg\" alt=\"demonstration of differnet alignment options, like all boxes stuck to the top of a flex parent, the bottom, stretched out, or along a baseline\"></p>\n<p>This defines the default behavior for how flex items are laid out along the <strong>cross axis</strong> on the current line. Think of it as the <code class=\"language-text\">justify-content</code> version for the cross-axis (perpendicular to the main-axis).</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">align-items</span><span class=\"token punctuation\">:</span> stretch | flex-start | flex-end | center | baseline | first baseline | last baseline | start | end | self-start | self-end + ... safe | unsafe<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">stretch</code> (default): stretch to fill the container (still respect min-width/max-width)</li>\n<li><code class=\"language-text\">flex-start</code> / <code class=\"language-text\">start</code> / <code class=\"language-text\">self-start</code>: items are placed at the start of the cross axis. The difference between these is subtle, and is about respecting the <code class=\"language-text\">flex-direction</code> rules or the <code class=\"language-text\">writing-mode</code> rules.</li>\n<li><code class=\"language-text\">flex-end</code> / <code class=\"language-text\">end</code> / <code class=\"language-text\">self-end</code>: items are placed at the end of the cross axis. The difference again is subtle and is about respecting <code class=\"language-text\">flex-direction</code> rules vs. <code class=\"language-text\">writing-mode</code> rules.</li>\n<li><code class=\"language-text\">center</code>: items are centered in the cross-axis</li>\n<li><code class=\"language-text\">baseline</code>: items are aligned such as their baselines align</li>\n</ul>\n<p>The <code class=\"language-text\">safe</code> and <code class=\"language-text\">unsafe</code> modifier keywords can be used in conjunction with all the rest of these keywords (although note <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/align-items\">browser support</a>), and deal with helping you prevent aligning elements such that the content becomes inaccessible.</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-align-content\"></a>align-content</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/align-content.svg\" alt=\"examples of the align-content property where a group of items cluster at the top or bottom, or stretch out to fill the space, or have spacing.\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/align-content.svg\" alt=\"examples of the align-content property where a group of items cluster at the top or bottom, or stretch out to fill the space, or have spacing.\"></p>\n<p>This aligns a flex container’s lines within when there is extra space in the cross-axis, similar to how <code class=\"language-text\">justify-content</code> aligns individual items within the main-axis.</p>\n<p><strong>Note:</strong> This property only takes effect on multi-line flexible containers, where <code class=\"language-text\">flex-wrap</code> is set to either <code class=\"language-text\">wrap</code> or <code class=\"language-text\">wrap-reverse</code>). A single-line flexible container (i.e. where <code class=\"language-text\">flex-wrap</code> is set to its default value, <code class=\"language-text\">no-wrap</code>) will not reflect <code class=\"language-text\">align-content</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">align-content</span><span class=\"token punctuation\">:</span> flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | start | end | baseline | first baseline | last baseline + ... safe | unsafe<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li><code class=\"language-text\">normal</code> (default): items are packed in their default position as if no value was set.</li>\n<li><code class=\"language-text\">flex-start</code> / <code class=\"language-text\">start</code>: items packed to the start of the container. The (more supported) <code class=\"language-text\">flex-start</code> honors the <code class=\"language-text\">flex-direction</code> while <code class=\"language-text\">start</code> honors the <code class=\"language-text\">writing-mode</code> direction.</li>\n<li><code class=\"language-text\">flex-end</code> / <code class=\"language-text\">end</code>: items packed to the end of the container. The (more support) <code class=\"language-text\">flex-end</code> honors the <code class=\"language-text\">flex-direction</code> while end honors the <code class=\"language-text\">writing-mode</code> direction.</li>\n<li><code class=\"language-text\">center</code>: items centered in the container</li>\n<li><code class=\"language-text\">space-between</code>: items evenly distributed; the first line is at the start of the container while the last one is at the end</li>\n<li><code class=\"language-text\">space-around</code>: items evenly distributed with equal space around each line</li>\n<li><code class=\"language-text\">space-evenly</code>: items are evenly distributed with equal space around them</li>\n<li><code class=\"language-text\">stretch</code>: lines stretch to take up the remaining space</li>\n</ul>\n<p>The <code class=\"language-text\">safe</code> and <code class=\"language-text\">unsafe</code> modifier keywords can be used in conjunction with all the rest of these keywords (although note <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/align-items\">browser support</a>), and deal with helping you prevent aligning elements such that the content becomes inaccessible.</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-gap-row-gap-column-gap\"></a>gap, row-gap, column-gap</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2021/09/gap-1.svg\" alt=\"image\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2021/09/gap-1.svg\" alt=\"image\"></p>\n<p><a href=\"https://css-tricks.com/almanac/properties/g/gap/\">The <code class=\"language-text\">gap</code> property</a> explicitly controls the space between flex items. It applies that spacing <em>only between items</em> not on the outer edges.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span>\n  ...\n  <span class=\"token property\">gap</span><span class=\"token punctuation\">:</span> 10px<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">gap</span><span class=\"token punctuation\">:</span> 10px 20px<span class=\"token punctuation\">;</span> <span class=\"token comment\">/* row-gap column gap */</span>\n  <span class=\"token property\">row-gap</span><span class=\"token punctuation\">:</span> 10px<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">column-gap</span><span class=\"token punctuation\">:</span> 20px<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The behavior could be thought of as a <em>minimum</em> gutter, as if the gutter is bigger somehow (because of something like <code class=\"language-text\">justify-content: space-between;</code>) then the gap will only take effect if that space would end up smaller.</p>\n<p>It is not exclusively for flexbox, <code class=\"language-text\">gap</code> works in grid and multi-column layout as well.</p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/02-items.svg\" alt=\"image\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/02-items.svg\" alt=\"image\"></p>\n<h2><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-properties-for-the-childrenflex-items\"></a>Properties for the Children</h2>\n<p>(flex items)</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-order\"></a>order</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/order.svg\" alt=\"Diagram showing flexbox order. A container with the items being 1 1 1 2 3, -1 1 2 5, and 2 2 99.\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/order.svg\" alt=\"Diagram showing flexbox order. A container with the items being 1 1 1 2 3, -1 1 2 5, and 2 2 99.\" title=\"flexbox order\"></p>\n<p>By default, flex items are laid out in the source order. However, the <code class=\"language-text\">order</code> property controls the order in which they appear in the flex container.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.item</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">order</span><span class=\"token punctuation\">:</span> 5<span class=\"token punctuation\">;</span> <span class=\"token comment\">/* default is 0 */</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Items with the same <code class=\"language-text\">order</code> revert to source order.</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flex-grow\"></a>flex-grow</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/flex-grow.svg\" alt=\"two rows of items, the first has all equally-sized items with equal flex-grow numbers, the second with the center item at twice the width because its value is 2 instead of 1.\" title=\"flex grow\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/flex-grow.svg\" alt=\"two rows of items, the first has all equally-sized items with equal flex-grow numbers, the second with the center item at twice the width because its value is 2 instead of 1.\"></p>\n<p>This defines the ability for a flex item to grow if necessary. It accepts a unitless value that serves as a proportion. It dictates what amount of the available space inside the flex container the item should take up.</p>\n<p>If all items have <code class=\"language-text\">flex-grow</code> set to <code class=\"language-text\">1</code>, the remaining space in the container will be distributed equally to all children. If one of the children has a value of <code class=\"language-text\">2</code>, that child would take up twice as much of the space either one of the others (or it will try, at least).</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.item</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">flex-grow</span><span class=\"token punctuation\">:</span> 4<span class=\"token punctuation\">;</span> <span class=\"token comment\">/* default 0 */</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Negative numbers are invalid.</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flex-shrink\"></a>flex-shrink</h4>\n<p>This defines the ability for a flex item to shrink if necessary.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.item</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">flex-shrink</span><span class=\"token punctuation\">:</span> 3<span class=\"token punctuation\">;</span> <span class=\"token comment\">/* default 1 */</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Negative numbers are invalid.</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flex-basis\"></a>flex-basis</h4>\n<p>This defines the default size of an element before the remaining space is distributed. It can be a length (e.g. 20%, 5rem, etc.) or a keyword. The <code class=\"language-text\">auto</code> keyword means “look at my width or height property” (which was temporarily done by the <code class=\"language-text\">main-size</code> keyword until deprecated). The <code class=\"language-text\">content</code> keyword means “size it based on the item’s content” – this keyword isn’t well supported yet, so it’s hard to test and harder to know what its brethren <code class=\"language-text\">max-content</code>, <code class=\"language-text\">min-content</code>, and <code class=\"language-text\">fit-content</code> do.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.item</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">flex-basis</span><span class=\"token punctuation\">:</span>  | auto<span class=\"token punctuation\">;</span> <span class=\"token comment\">/* default auto */</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>If set to <code class=\"language-text\">0</code>, the extra space around content isn’t factored in. If set to <code class=\"language-text\">auto</code>, the extra space is distributed based on its <code class=\"language-text\">flex-grow</code> value. <a href=\"http://www.w3.org/TR/css3-flexbox/images/rel-vs-abs-flex.svg\">See this graphic.</a></p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flex\"></a>flex</h4>\n<p>This is the shorthand for <code class=\"language-text\">flex-grow,</code> <code class=\"language-text\">flex-shrink</code> and <code class=\"language-text\">flex-basis</code> combined. The second and third parameters (<code class=\"language-text\">flex-shrink</code> and <code class=\"language-text\">flex-basis</code>) are optional. The default is <code class=\"language-text\">0 1 auto</code>, but if you set it with a single number value, like <code class=\"language-text\">flex: 5;</code>, that changes the <code class=\"language-text\">flex-basis</code> to 0%, so it’s like setting <code class=\"language-text\">flex-grow: 5; flex-shrink: 1; flex-basis: 0%;</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.item</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">flex</span><span class=\"token punctuation\">:</span> none | [ &lt;<span class=\"token string\">'flex-grow'</span>> &lt;<span class=\"token string\">'flex-shrink'</span>>? || &lt;<span class=\"token string\">'flex-basis'</span>> ]\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>It is recommended that you use this shorthand property</strong> rather than set the individual properties. The shorthand sets the other values intelligently.</p>\n<h4><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-align-self\"></a>align-self</h4>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/align-self.svg\" alt=\"One item with a align-self value is positioned along the bottom of a flex parent instead of the top where all the rest of the items are.\" title=\"align self\"></p>\n<p><img src=\"https://css-tricks.com/wp-content/uploads/2018/10/align-self.svg\" alt=\"One item with a align-self value is positioned along the bottom of a flex parent instead of the top where all the rest of the items are.\"></p>\n<p>This allows the default alignment (or the one specified by <code class=\"language-text\">align-items</code>) to be overridden for individual flex items.</p>\n<p>Please see the <code class=\"language-text\">align-items</code> explanation to understand the available values.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.item</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">align-self</span><span class=\"token punctuation\">:</span> auto | flex-start | flex-end | center | baseline | stretch<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Note that <code class=\"language-text\">float</code>, <code class=\"language-text\">clear</code> and <code class=\"language-text\">vertical-align</code> have no effect on a flex item.</p>\n<h3><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-prefixing-flexbox\"></a>Prefixing Flexbox</h3>\n<p>Flexbox requires some vendor prefixing to support the most browsers possible. It doesn’t just include prepending properties with the vendor prefix, but there are actually entirely different property and value names. This is because the Flexbox spec has changed over time, creating an <a href=\"https://css-tricks.com/old-flexbox-and-new-flexbox/\">“old”, “tweener”, and “new”</a> versions.</p>\n<p>Perhaps the best way to handle this is to write in the new (and final) syntax and run your CSS through <a href=\"https://css-tricks.com/autoprefixer/\">Autoprefixer</a>, which handles the fallbacks very well.</p>\n<p>Alternatively, here’s a Sass <code class=\"language-text\">@mixin</code> to help with some of the prefixing, which also gives you an idea of what kind of things need to be done:</p>\n<div class=\"gatsby-highlight\" data-language=\"scss\"><pre class=\"language-scss\"><code class=\"language-scss\"><span class=\"token keyword\">@mixin</span> <span class=\"token function\">flexbox</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> -webkit-box<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> -moz-box<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> -ms-flexbox<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> -webkit-flex<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">@mixin</span> <span class=\"token function\">flex</span><span class=\"token punctuation\">(</span><span class=\"token variable\">$values</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">-webkit-box-flex</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$values</span><span class=\"token punctuation\">;</span>\n  <span class=\"token property\">-moz-box-flex</span><span class=\"token punctuation\">:</span>  <span class=\"token variable\">$values</span><span class=\"token punctuation\">;</span>\n  <span class=\"token property\">-webkit-flex</span><span class=\"token punctuation\">:</span>  <span class=\"token variable\">$values</span><span class=\"token punctuation\">;</span>\n  <span class=\"token property\">-ms-flex</span><span class=\"token punctuation\">:</span>  <span class=\"token variable\">$values</span><span class=\"token punctuation\">;</span>\n  <span class=\"token property\">flex</span><span class=\"token punctuation\">:</span>  <span class=\"token variable\">$values</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">@mixin</span> <span class=\"token function\">order</span><span class=\"token punctuation\">(</span><span class=\"token variable\">$val</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">-webkit-box-ordinal-group</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$val</span><span class=\"token punctuation\">;</span>  \n  <span class=\"token property\">-moz-box-ordinal-group</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$val</span><span class=\"token punctuation\">;</span>     \n  <span class=\"token property\">-ms-flex-order</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$val</span><span class=\"token punctuation\">;</span>     \n  <span class=\"token property\">-webkit-order</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$val</span><span class=\"token punctuation\">;</span>  \n  <span class=\"token property\">order</span><span class=\"token punctuation\">:</span> <span class=\"token variable\">$val</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">.wrapper </span><span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">@include</span> <span class=\"token function\">flexbox</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">.item </span><span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">@include</span> <span class=\"token function\">flex</span><span class=\"token punctuation\">(</span>1 200px<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">@include</span> <span class=\"token function\">order</span><span class=\"token punctuation\">(</span>2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-examples\"></a>Examples</h3>\n<p>Let’s start with a very very simple example, solving an almost daily problem: perfect centering. It couldn’t be any simpler if you use flexbox.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.parent</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">height</span><span class=\"token punctuation\">:</span> 300px<span class=\"token punctuation\">;</span> <span class=\"token comment\">/* Or whatever */</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token selector\">.child</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">width</span><span class=\"token punctuation\">:</span> 100px<span class=\"token punctuation\">;</span>  <span class=\"token comment\">/* Or whatever */</span>\n  <span class=\"token property\">height</span><span class=\"token punctuation\">:</span> 100px<span class=\"token punctuation\">;</span> <span class=\"token comment\">/* Or whatever */</span>\n  <span class=\"token property\">margin</span><span class=\"token punctuation\">:</span> auto<span class=\"token punctuation\">;</span>  <span class=\"token comment\">/* Magic! */</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>This relies on the fact a margin set to <code class=\"language-text\">auto</code> in a flex container absorb extra space. So setting a margin of <code class=\"language-text\">auto</code> will make the item perfectly centered in both axes.</p>\n<p>Now let’s use some more properties. Consider a list of 6 items, all with fixed dimensions, but can be auto-sized. We want them to be evenly distributed on the horizontal axis so that when we resize the browser, everything scales nicely, and without media queries.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.flex-container</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">/* We first create a flex layout context */</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span>\n\n  <span class=\"token comment\">/* Then we define the flow direction \n     and if we allow the items to wrap \n   * Remember this is the same as:\n   * flex-direction: row;\n   * flex-wrap: wrap;\n   */</span>\n  <span class=\"token property\">flex-flow</span><span class=\"token punctuation\">:</span> row wrap<span class=\"token punctuation\">;</span>\n\n  <span class=\"token comment\">/* Then we define how is distributed the remaining space */</span>\n  <span class=\"token property\">justify-content</span><span class=\"token punctuation\">:</span> space-around<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Done. Everything else is just some styling concern. Below is a pen featuring this example. Be sure to go to CodePen and try resizing your windows to see what happens.</p>\n<iframe id=\"cp_embed_EKEYob\" src=\"//codepen.io/anon/embed/EKEYob?height=450&amp;theme-id=1&amp;slug-hash=EKEYob&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen=\"\" allowpaymentrequest=\"\" name=\"CodePen Embed EKEYob\" title=\"CodePen Embed EKEYob\" class=\"cp_embed_iframe\" style=\"width: 100%; overflow: hidden; height: 100%;\">CodePen Embed Fallback</iframe>\n<p>Let’s try something else. Imagine we have a right-aligned navigation element on the very top of our website, but we want it to be centered on medium-sized screens and single-columned on small devices. Easy enough.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token comment\">/* Large */</span>\n<span class=\"token selector\">.navigation</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">flex-flow</span><span class=\"token punctuation\">:</span> row wrap<span class=\"token punctuation\">;</span>\n  <span class=\"token comment\">/* This aligns items to the end line on main-axis */</span>\n  <span class=\"token property\">justify-content</span><span class=\"token punctuation\">:</span> flex-end<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Medium screens */</span>\n<span class=\"token atrule\"><span class=\"token rule\">@media</span> all <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token property\">max-width</span><span class=\"token punctuation\">:</span> 800px<span class=\"token punctuation\">)</span></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token selector\">.navigation</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">/* When on medium sized screens, we center it by evenly distributing empty space around items */</span>\n    <span class=\"token property\">justify-content</span><span class=\"token punctuation\">:</span> space-around<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Small screens */</span>\n<span class=\"token atrule\"><span class=\"token rule\">@media</span> all <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token property\">max-width</span><span class=\"token punctuation\">:</span> 500px<span class=\"token punctuation\">)</span></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token selector\">.navigation</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">/* On small screens, we are no longer using row direction but column */</span>\n    <span class=\"token property\">flex-direction</span><span class=\"token punctuation\">:</span> column<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<iframe id=\"cp_embed_YqaKYR\" src=\"//codepen.io/anon/embed/YqaKYR?height=250&amp;theme-id=1&amp;slug-hash=YqaKYR&amp;default-tab=result\" height=\"250\" scrolling=\"no\" frameborder=\"0\" allowfullscreen=\"\" allowpaymentrequest=\"\" name=\"CodePen Embed YqaKYR\" title=\"CodePen Embed YqaKYR\" class=\"cp_embed_iframe\" style=\"width: 100%; overflow: hidden; height: 100%;\">CodePen Embed Fallback</iframe>\n<p>Let’s try something even better by playing with flex items flexibility! What about a mobile-first 3-columns layout with full-width header and footer. And independent from source order.</p>\n<div class=\"gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.wrapper</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">display</span><span class=\"token punctuation\">:</span> flex<span class=\"token punctuation\">;</span>\n  <span class=\"token property\">flex-flow</span><span class=\"token punctuation\">:</span> row wrap<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* We tell all items to be 100% width, via flex-basis */</span>\n<span class=\"token selector\">.wrapper > *</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token property\">flex</span><span class=\"token punctuation\">:</span> 1 100%<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* We rely on source order for mobile-first approach\n * in this case:\n * 1. header\n * 2. article\n * 3. aside 1\n * 4. aside 2\n * 5. footer\n */</span>\n\n<span class=\"token comment\">/* Medium screens */</span>\n<span class=\"token atrule\"><span class=\"token rule\">@media</span> all <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token property\">min-width</span><span class=\"token punctuation\">:</span> 600px<span class=\"token punctuation\">)</span></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">/* We tell both sidebars to share a row */</span>\n  <span class=\"token selector\">.aside</span> <span class=\"token punctuation\">{</span> <span class=\"token property\">flex</span><span class=\"token punctuation\">:</span> 1 auto<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Large screens */</span>\n<span class=\"token atrule\"><span class=\"token rule\">@media</span> all <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token property\">min-width</span><span class=\"token punctuation\">:</span> 800px<span class=\"token punctuation\">)</span></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">/* We invert order of first sidebar and main\n   * And tell the main element to take twice as much width as the other two sidebars \n   */</span>\n  <span class=\"token selector\">.main</span> <span class=\"token punctuation\">{</span> <span class=\"token property\">flex</span><span class=\"token punctuation\">:</span> 3 0px<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span>\n  <span class=\"token selector\">.aside-1</span> <span class=\"token punctuation\">{</span> <span class=\"token property\">order</span><span class=\"token punctuation\">:</span> 1<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span>\n  <span class=\"token selector\">.main</span>    <span class=\"token punctuation\">{</span> <span class=\"token property\">order</span><span class=\"token punctuation\">:</span> 2<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span>\n  <span class=\"token selector\">.aside-2</span> <span class=\"token punctuation\">{</span> <span class=\"token property\">order</span><span class=\"token punctuation\">:</span> 3<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span>\n  <span class=\"token selector\">.footer</span>  <span class=\"token punctuation\">{</span> <span class=\"token property\">order</span><span class=\"token punctuation\">:</span> 4<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<iframe id=\"cp_embed_vWEMWw\" src=\"//codepen.io/anon/embed/vWEMWw?height=350&amp;theme-id=1&amp;slug-hash=vWEMWw&amp;default-tab=result\" height=\"350\" scrolling=\"no\" frameborder=\"0\" allowfullscreen=\"\" allowpaymentrequest=\"\" name=\"CodePen Embed vWEMWw\" title=\"CodePen Embed vWEMWw\" class=\"cp_embed_iframe\" style=\"width: 100%; overflow: hidden; height: 100%;\">CodePen Embed Fallback</iframe>\n<h3><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox//#aa-flexbox-tricks\"></a>Flexbox Tricks</h3>"},{"url":"/docs/netlify-cms-jamstack/get-started-with-gatsby/","relativePath":"docs/netlify-cms-jamstack/get-started-with-gatsby/index.md","relativeDir":"docs/netlify-cms-jamstack/get-started-with-gatsby","base":"index.md","name":"index","frontmatter":{"title":"Get Started With Gatsby","template":"docs","excerpt":"Get Started With Gatsby"},"html":"<ol>\n<li>Create a new site</li>\n</ol>\n<p>It’ll ask for a site title and the name of the project’s directory. Continue following the prompts to choose your preferred language (JavaScript or TypeScript), CMS, styling tools and additional features.</p>\n<ol start=\"2\">\n<li>Once everything is downloaded you will see a message with instructions for navigating to your site and running it locally.</li>\n</ol>\n<p>The CLI created the site as a new folder with the name you chose in step 1.</p>\n<p>Start by going to the directory with</p>\n<p>Start the local development server with</p>\n<p>Gatsby will start a hot-reloading development environment accessible by default at <code class=\"language-text\">http://localhost:8000</code>.</p>\n<ol start=\"3\">\n<li>Now you’re ready to make changes to your site!</li>\n</ol>\n<p>Try editing the home page in <code class=\"language-text\">src/pages/index.js</code>. Saved changes will live reload in the browser.</p>\n<h2><a href=\"https://www.gatsbyjs.com/docs/quick-start/#whats-next\"></a>What’s next?</h2>\n<h3><a href=\"https://www.gatsbyjs.com/docs/quick-start/#use-flags\"></a>Use flags</h3>\n<p>The CLI also supports two flags:</p>\n<ul>\n<li><code class=\"language-text\">-y</code> skips the questionnaire</li>\n<li><code class=\"language-text\">-ts</code> initializes your project with the <a href=\"https://github.com/gatsbyjs/gatsby-starter-minimal-ts\">minimal TypeScript starter</a> instead of the <a href=\"https://github.com/gatsbyjs/gatsby-starter-minimal\">minimal JavaScript starter</a></li>\n</ul>\n<p>Flags are not positional, so these commands are equivalent:</p>\n<ul>\n<li><code class=\"language-text\">npm init gatsby -y -ts my-site-name</code></li>\n<li><code class=\"language-text\">npm init gatsby my-site-name -y -ts</code></li>\n</ul>\n<h2>Create a Gatsby site</h2>\n<p>To create your first Gatsby site, you're going to use a command from the Gatsby command line interface (CLI): <code class=\"language-text\">gatsby new</code>. This command brings up an interactive prompt that asks you questions about the site you want to build. After you enter all the information, the CLI uses your answers to automatically generate your new Gatsby site.</p>\n<p><a href=\"https://www.gatsbyjs.com/static/eab322d4f0a5a12bdc749ef0992c4e7c/e92cd/gatsby-new-cli.png\">![The welcome message for the interactive \"gatsby new\" command.](https://www.gatsbyjs.com/static/eab322d4f0a5a12bdc749ef0992c4e7c/321ea/gatsby-new-cli.png \"The welcome message for the interactive \"gatsby new\" command.\")</a></p>\n<p><strong>Note:</strong> For this Tutorial, your Gatsby CLI should be v4.8 or newer. To check what version you have installed, run the following command:</p>\n<p>Copycopy code to clipboard`</p>\n<p>gatsby --version</p>\n<p>`</p>\n<p>Need to update? Run the command below to get the latest version of the Gatsby CLI:</p>\n<p>Copycopy code to clipboard`</p>\n<p>npm  install -g gatsby-cli</p>\n<p>`</p>\n<p>Let's take a closer look at the process:</p>\n<ol>\n<li>Open the command line, and use the <code class=\"language-text\">cd</code> command to change directories into the folder where you want to create your new Gatsby site. For example, if you wanted to create your new site on your desktop, you might type:</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>cd Desktop</p>\n<p>`</p>\n<ol>\n<li>Run the following command from the command line. This will start up the interactive prompt to help you create a new Gatsby site.</li>\n</ol>\n<p>Desktop</p>\n<p>CopyDesktop: copy code to clipboard`</p>\n<p>gatsby new</p>\n<p>`</p>\n<p><strong>Having trouble with <code class=\"language-text\">gatsby new</code>?</strong> If you had trouble globally installing <code class=\"language-text\">gatsby-cli</code> in Part 0, you can also create a new site by running <code class=\"language-text\">npm init gatsby</code> from the command line instead of <code class=\"language-text\">gatsby new</code>.</p>\n<ol>\n<li>When the prompt asks, <strong>\"What would you like to call your site?\"</strong> enter a name for your site.</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>What would you like to call your site?</p>\n<p>✔ - My First Gatsby Site</p>\n<p>`</p>\n<ol>\n<li>When the prompt asks, <strong>\"What would you like to name the folder where your site will be created?\"</strong> use the default folder name, which will be based on the site name you chose.</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>What would you like to name the folder where your site will be created?</p>\n<p>✔ Desktop/ my-first-gatsby-site</p>\n<p>`</p>\n<ol>\n<li>When the prompt asks, <strong>\"Will you be using JavaScript or TypeScript?\"</strong> choose <strong>JavaScript</strong>.</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>Will you be using JavaScript or TypeScript?</p>\n<p>❯ JavaScript</p>\n<p> TypeScript</p>\n<p>`</p>\n<p>This tutorial doesn't require any prior TypeScript knowledge as it uses JavaScript. If you're familiar with TypeScript you can read the <a href=\"https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/\">Gatsby and TypeScript guide</a> to learn about typings, files, and conventions. If you want to use TypeScript we recommend going through the tutorial first and then only afterwards convert the project to TypeScript.</p>\n<ol>\n<li>When the prompt asks, <strong>\"Will you be using a CMS?\"</strong> select <strong>\"No (or I'll add it later)\"</strong>.</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>✔ Will you be using a CMS?</p>\n<ul>\n<li>No (or I'll add it later)</li>\n</ul>\n<p>`</p>\n<p>In the future, you can use these options to tell <code class=\"language-text\">gatsby new</code> what features you want to add to your site, and <code class=\"language-text\">gatsby new</code> will automatically configure them for you. It's a much quicker way to set up new projects.</p>\n<p>But in this first site, you'll set things up manually to learn about how Gatsby's pieces fit together.</p>\n<ol>\n<li>When the prompt asks, <strong>\"Would you like to install a styling system?\"</strong> select <strong>\"No (or I'll add it later)\"</strong>. (You'll add styles manually later.)</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>✔ Would you like to install a styling system?</p>\n<ul>\n<li>No (or I'll add it later)</li>\n</ul>\n<p>`</p>\n<ol>\n<li>When the prompt asks, <strong>\"Would you like to install additional features with other plugins?\"</strong> use the arrow and Enter keys to select <strong>\"Done\"</strong>.</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>✔ Would you like to install additional features with other plugins?</p>\n<ul>\n<li>Done</li>\n</ul>\n<p>`</p>\n<ol>\n<li>The prompt will show you a summary of what <code class=\"language-text\">gatsby new</code> will do. It should look something like the output below.</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>Thanks! Here's what we'll now do:</p>\n<p> 🛠  Create a new Gatsby site in the folder my-first-gatsby-site</p>\n<p>? Shall we do this? (Y/n) › Yes</p>\n<p>`</p>\n<ol>\n<li>When the prompt asks, <strong>\"Shall we do this?\"</strong> enter <strong>\"Y\"</strong>. The <code class=\"language-text\">gatsby new</code> command will start building your site. Your internet download speed will affect how long this command takes to run. After it finishes, you should see a message like this:</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>🎉  Your new Gatsby site My First Gatsby Site has been successfully</p>\n<p>created at ~/Desktop/my-first-gatsby-site.</p>\n<p>Start by going to the directory with</p>\n<p>  cd my-first-gatsby-site</p>\n<p>Start the local development server with</p>\n<p>  npm run develop</p>\n<p>See all commands at</p>\n<p> <a href=\"https://www.gatsbyjs.com/docs/gatsby-cli/\">https://www.gatsbyjs.com/docs/gatsby-cli/</a></p>\n<p>`</p>\n<p>Congratulations, you're now the owner of a brand-new Gatsby site!</p>\n<h2><a href=\"https://www.gatsbyjs.com/docs/tutorial/part-1/#run-your-site-locally\"></a>Run your site locally</h2>\n<p>So far, you've generated the code for your site, but what does it actually look like in a web browser like Firefox or Google Chrome? To find out, you'll first need to start up your site's local development server.</p>\n<p>The <strong>development server</strong> is a useful tool for when you're working on your site locally (from your own computer). When your development server is running, you can use a web browser to interact with your local copy of your site. That way, you can test out changes to your code, to make sure they work before you actually publish a new version of your site to the internet.</p>\n<p>To start up your development server, do the following:</p>\n<ol>\n<li>In the command line, change into the directory you created for your site:</li>\n</ol>\n<p>~/Desktop</p>\n<p>Copy~/Desktop: copy code to clipboard`</p>\n<p>cd my-first-gatsby-site</p>\n<p>`</p>\n<p><strong>Tip:</strong> Whenever you want to run any commands for your site, you need to be in the context for that site. That is, your command line needs to be pointed at the directory where your site's code lives.</p>\n<ol>\n<li>From your site directory, start the development server by running the following command:</li>\n</ol>\n<p>~/Desktop/my-first-gatsby-site</p>\n<p>Copy~/Desktop/my-first-gatsby-site: copy code to clipboard`</p>\n<p>gatsby develop</p>\n<p>`</p>\n<p>If you weren't able to install the Gatsby command line interface globally, you can start your development server using the following command instead:</p>\n<p>Copycopy code to clipboard`</p>\n<p>npm run develop</p>\n<p>`</p>\n<ol>\n<li>After a few moments, the command line should output a message like the following, telling you your development server is ready to go!</li>\n</ol>\n<p>Copycopy code to clipboard`</p>\n<p>You can now view my-first-gatsby-site in the browser.</p>\n<p>⠀</p>\n<p> <a href=\"http://localhost:8000/\">http://localhost:8000/</a></p>\n<p>⠀</p>\n<p>View GraphiQL, an in-browser IDE, to explore your site's data and</p>\n<p>schema</p>\n<p>⠀</p>\n<p> <a href=\"http://localhost:8000/___graphql\">http://localhost:8000/___graphql</a></p>\n<p>`</p>\n<ol>\n<li>Open your favorite web browser and navigate to <code class=\"language-text\">http://localhost:8000</code>.</li>\n</ol>\n<p><a href=\"https://www.gatsbyjs.com/static/b79cb66545b144295a8c6a5efeaafb20/94cea/localhost-new-site.png\">![The default home page generated by the \"gatsby new\" command.](https://www.gatsbyjs.com/static/b79cb66545b144295a8c6a5efeaafb20/321ea/localhost-new-site.png \"The default home page generated by the \"gatsby new\" command.\")</a></p>\n<p>And there it is: your very first Gatsby site! 🎉</p>\n<p>You'll be able to visit the site locally at <code class=\"language-text\">http://localhost:8000/</code> for as long as your development server is running. (That's the process you started by running the <code class=\"language-text\">gatsby develop</code> command.) To stop running that process (or to \"stop running the development server\"), go back to your terminal window, hold down the \"control\" key, and then hit \"c\" (<code class=\"language-text\">ctrl-c</code>). To start it again, run <code class=\"language-text\">gatsby develop</code> again!</p>\n<p><strong>Note:</strong> If you are using VM setup like vagrant and/or would like to listen on your local IP address, run <code class=\"language-text\">gatsby develop --host=0.0.0.0</code>. Now, the development server listens on both <code class=\"language-text\">http://localhost</code> and your local IP.</p>\n<h2><a href=\"https://www.gatsbyjs.com/docs/tutorial/part-1/#set-up-a-github-repo-for-your-site\"></a>Set up a GitHub repo for your site</h2>\n<p>GitHub is a website that many developers use to back up and share their code online. By uploading your code to GitHub, you'll be able to work on the same codebase from multiple computers. You'll also be able to use Gatsby Cloud to build and host your site.</p>\n<ol>\n<li>\n<p>Each codebase on GitHub is stored in its own <strong>repository</strong> (also called a \"repo\", for short). To create a new repository for your blog, click the plus icon in the top-right corner of the navigation bar. Select \"New repository\".</p>\n<p><a href=\"https://www.gatsbyjs.com/static/bf74830c88d3f8b0287b58cf397be992/18539/new-repo-button.png\">![A dropdown in the navigation bar reveals the \"New repository\" button.](https://www.gatsbyjs.com/static/bf74830c88d3f8b0287b58cf397be992/321ea/new-repo-button.png \"A dropdown in the navigation bar reveals the \"New repository\" button.\")</a></p>\n</li>\n<li>\n<p>When filling out the form for your new repo, you can make it public or private. (This only affects the visibility of your code on GitHub. Your site will still be visible to everyone once you deploy it with Gatsby Cloud.) Leave the initialization option checkboxes unchecked.</p>\n<p><a href=\"https://www.gatsbyjs.com/static/94ec685d2adefdf4d2aac5b3364acba9/3d68f/new-repo-options.png\">![The GitHub form to create a new repository. It's set to create a public repo called \"my-first-gatsby-site\". The options to add a README, .gitignore file, and license are unchecked.](https://www.gatsbyjs.com/static/94ec685d2adefdf4d2aac5b3364acba9/321ea/new-repo-options.png \"The GitHub form to create a new repository. It's set to create a public repo called \"my-first-gatsby-site\". The options to add a README, .gitignore file, and license are unchecked.\")</a></p>\n</li>\n<li>\n<p>To push your existing code from your computer to your new GitHub repository, enter the commands below in the command line. Be sure to swap out <code class=\"language-text\">YOUR_GITHUB_USERNAME</code> for your actual username and <code class=\"language-text\">YOUR_GITHUB_REPO_NAME</code> with the name you gave your GitHub repo (like <code class=\"language-text\">my-first-gatsby-site</code>).</p>\n<p>Copycopy code to clipboard`</p>\n<p>git remote add origin <a href=\"https://github.com/YOUR_GITHUB_USERNAME/YOUR_GITHUB_REPO_NAME.git\">https://github.com/YOUR_GITHUB_USERNAME/YOUR_GITHUB_REPO_NAME.git</a></p>\n<p>git branch -M main</p>\n<p>git push -u origin main</p>\n<p>`</p>\n</li>\n</ol>\n<p><strong>Using GitHub for the first time?</strong></p>\n<p>If you get an error about permissions when you try to push your code to GitHub for the first time, you might need to set up a <strong>personal access token</strong> for your GitHub account. This lets GitHub know that your computer has permission to push code changes to your remote repos.</p>\n<p>For instructions on how to set up a personal access token, follow GitHub's guide: <a href=\"https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token\">Creating a personal access token</a>. Your personal access token will need the <strong>repo</strong> scope to be able to push changes to your repository.</p>\n<p>Now you have a copy of your code saved on GitHub's servers. In the next step, you'll connect your Gatsby Cloud account to the GitHub repo you just created.</p>\n<h2><a href=\"https://www.gatsbyjs.com/docs/tutorial/part-1/#build-your-site-with-gatsby-cloud\"></a>Build your site with Gatsby Cloud</h2>\n<p>Gatsby Cloud is an infrastructure platform that is specifically optimized for building, deploying, and hosting Gatsby sites. Once you connect your Gatsby Cloud account to your GitHub repository, Gatsby Cloud will build your site and make it available for others on the internet to see.</p>\n<p>To connect your code on GitHub to your Gatsby Cloud account, do the following:</p>\n<ol>\n<li>\n<p>Go to your <a href=\"https://www.gatsbyjs.com/dashboard/\">Gatsby Cloud Dashboard</a>. Click on the <strong>\"Add a site\"</strong> button.</p>\n<p><a href=\"https://www.gatsbyjs.com/static/9c130998b561f1770834309715c99d5b/2b36a/01-create-a-site-button.png\"><img src=\"https://www.gatsbyjs.com/static/9c130998b561f1770834309715c99d5b/321ea/01-create-a-site-button.png\" alt=\"An empty Gatsby Cloud dashboard\" title=\"An empty Gatsby Cloud dashboard\"></a></p>\n</li>\n<li>\n<p>The next few steps will help you add your site to Gatsby Cloud. First, in the <strong>\"Import from a Git repository\"</strong> card click the <strong>\"GitHub\"</strong> icon to select GitHub as your Git provider.</p>\n<p><a href=\"https://www.gatsbyjs.com/static/ff5dd96106160a1c11eaa25af6becdda/0f688/02-import-a-git-repo.png\">![The \"Add a site\" screen. Select the option for \"Import from a Git repository\".](https://www.gatsbyjs.com/static/ff5dd96106160a1c11eaa25af6becdda/321ea/02-import-a-git-repo.png \"The \"Add a site\" screen. Select the option for \"Import from a Git repository\".\")</a></p>\n</li>\n<li>\n<p>If this is your first time connecting GitHub to Gatsby Cloud, you'll need to give Gatsby Cloud permission to access your GitHub account.</p>\n<p><strong>Note:</strong> If you are part of more than one GitHub organization, you will need to first select the organization with which the repository resides at this step before selecting the repository itself.</p>\n</li>\n<li>\n<p>A new browser window should open, where GitHub will ask you whether you want to give Gatsby Cloud permission to your GitHub repositories. You can choose whether to give Gatsby Cloud access to all of your GitHub repositories or to only the repository you created (<code class=\"language-text\">my-first-gatsby-site</code>). Then click <strong>\"Install\"</strong>.</p>\n<p><a href=\"https://www.gatsbyjs.com/static/4fd11cb2e4af910ca099f70d12aa8421/0f96c/03-github-gatsby-cloud-permissions.png\">![The GitHub permissions page, asking whether you want to give Gatsby Cloud access to your repos. The \"All repositories\" option is selected.](https://www.gatsbyjs.com/static/4fd11cb2e4af910ca099f70d12aa8421/321ea/03-github-gatsby-cloud-permissions.png \"The GitHub permissions page, asking whether you want to give Gatsby Cloud access to your repos. The \"All repositories\" option is selected.\")</a></p>\n</li>\n<li>\n<p>Now, when you go back to the Gatsby Cloud window, the repository list should contain your GitHub repository. Select it.</p>\n<p><a href=\"https://www.gatsbyjs.com/static/5fb2c6c66c2d25426b180ee40917fd83/65781/04-select-repository.png\">![The \"Select a Repository\" dropdown in Gatsby Cloud lists the \"my-first-gatsby-site\" GitHub repository.](https://www.gatsbyjs.com/static/5fb2c6c66c2d25426b180ee40917fd83/321ea/04-select-repository.png \"The \"Select a Repository\" dropdown in Gatsby Cloud lists the \"my-first-gatsby-site\" GitHub repository.\")</a></p>\n</li>\n<li>\n<p>Once you select your repo, you'll be navigated to the configuration step which presents you with a few more inputs. These let you tell Gatsby Cloud where to look in your GitHub repo for your Gatsby site. You can also change what Gatsby Cloud will name your site. <strong>Leave the default settings</strong> and click the <strong>\"Next\"</strong> button.</p>\n<p><a href=\"https://www.gatsbyjs.com/static/61bb418dbf509217b076a19507374eef/65781/05-add-site-details.png\">![The new fields. \"Base Branch\" is set to \"main\", \"Base Directory\" is set to \"/\", and \"Site Name\" is set to \"my-first-gatsby-site-main\".](https://www.gatsbyjs.com/static/61bb418dbf509217b076a19507374eef/321ea/05-add-site-details.png \"The new fields. \"Base Branch\" is set to \"main\", \"Base Directory\" is set to \"/\", and \"Site Name\" is set to \"my-first-gatsby-site-main\".\")</a></p>\n</li>\n<li>\n<p>Gatsby Cloud will ask you if you want to add any integrations to your site. For future projects, this might be useful if you want to use a CMS. Gatsby Cloud will also ask if you want to add any environment variables. Again, this may useful for future projects, but for now, scroll past and click the <strong>\"Build Site\"</strong> button.</p>\n<p><a href=\"https://www.gatsbyjs.com/static/c36f2eede71bb383cf02e73a7a8cf320/65781/06-integrations-and-environment-variables.png\">![The \"Integrations\" tab of the \"Add a site\" screen.](https://www.gatsbyjs.com/static/c36f2eede71bb383cf02e73a7a8cf320/321ea/06-integrations-and-environment-variables.png \"The \"Integrations\" tab of the \"Add a site\" screen.\")</a></p>\n</li>\n<li>\n<p>Now that your site has been created, you'll be taken to a site dashboard where you can see the status of your builds. Gatsby Cloud should start building your site automatically. You'll see a link to your new site, which is automatically hosted on Gatsby Cloud. You can share this link with anyone, and they'll be able to see your site online!</p>\n<p><a href=\"https://www.gatsbyjs.com/static/d82ecf06f74d4195697a9a4c9253049d/65781/07-site-page.png\"><img src=\"https://www.gatsbyjs.com/static/d82ecf06f74d4195697a9a4c9253049d/321ea/07-site-page.png\" alt=\"The Gatsby Cloud dashboard for a new site.\" title=\"The Gatsby Cloud dashboard for a new site.\"></a></p>\n</li>\n</ol>\n<p>You did it! Your Gatsby site is now online! 👏</p>\n<p>Every time you push a new change to the main branch of your GitHub repo, Gatsby Cloud will see the changes and automatically start a build for the new version of your site.</p>\n<p><strong>Tip:</strong> There will be a unique URL for each build (like <code class=\"language-text\">https://build-49535320-b3ae-4761-bbeb-f8f7fa07e0fc.gtsb.io/</code>), and a URL that always has the latest build (like <code class=\"language-text\">my-first-gatsby-site-main.gatsbyjs.io</code>). You'll mostly want to share the human-readable URL, so that people can always see the most up-to-date version of your site. But in some cases (like when you're trying to debug a specific build of your site) it can be helpful to use the unique build URL.</p>\n<h2><a href=\"https://www.gatsbyjs.com/docs/tutorial/part-1/#summary\"></a>Summary</h2>\n<p>In this section, you learned how to create a new Gatsby site and deploy it online using Gatsby Cloud. As a quick review, here's the diagram outlining the process:</p>\n<p><a href=\"https://www.gatsbyjs.com/static/0fd27b745c1de708f034eaf97c4416e0/d61c2/deployment-workflow.png\"><img src=\"https://www.gatsbyjs.com/static/0fd27b745c1de708f034eaf97c4416e0/321ea/deployment-workflow.png\" alt=\"The workflow for how your code gets from your computer to your users. Extended description below.\" title=\"The workflow for how your code gets from your computer to your users. Extended description below.\"></a></p>\n<p><em>Expand for detailed description</em></p>\n<h3><a href=\"https://www.gatsbyjs.com/docs/tutorial/part-1/#key-takeaways\"></a>Key takeaways</h3>\n<ul>\n<li>To create a new Gatsby site from the command line, you can run the <code class=\"language-text\">gatsby new</code> command.</li>\n<li>To run your site locally, use the <code class=\"language-text\">gatsby develop</code> command. You can view your site in a web browser at <code class=\"language-text\">localhost:8000</code>.</li>\n<li>\n<p>Gatsby Cloud is an infrastructure platform specifically optimized for building, deploying, and hosting Gatsby sites.</p>\n<ul>\n<li>When you push a new commit to the <code class=\"language-text\">main</code> branch of the GitHub repository for your site, Gatsby Cloud will detect the changes, rebuild a new version of your site, and then redeploy it.</li>\n</ul>\n</li>\n</ul>"},{"url":"/docs/netlify-cms-jamstack/serverlessjs/","relativePath":"docs/netlify-cms-jamstack/serverlessjs/index.md","relativeDir":"docs/netlify-cms-jamstack/serverlessjs","base":"index.md","name":"index","frontmatter":{"title":"ServerlessJS","template":"docs","excerpt":"How does serverless JavaScript work"},"html":"<h1>How does serverless JavaScript work? | Service workers and Cloudflare Workers | Cloudflare</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>Serverless JavaScript is used to build serverless architecture at the network edge. Learn what serverless JavaScript is and how it works.</p>\n</blockquote>\n<hr>\n<h2>What is serverless JavaScript?</h2>\n<p>Serverless JavaScript is JavaScript code that comprises all or part of an application, is only run when requested, and is not hosted on proprietary servers. It enables developers to build high-performance, low-latency serverless applications (such as <a href=\"https://www.cloudflare.com/learning/performance/what-is-jamstack/\">JAMstack applications</a>) that run on a network and avoid many issues associated with other serverless applications, such as cold starts.</p>\n<p><a href=\"https://www.cloudflare.com/learning/serverless/what-is-serverless/\">Serverless</a> JavaScript is hosted in an edge network or by an HTTP caching service, which stores content to respond quickly to HTTP requests. Developers can write and deploy JavaScript functions that process HTTP requests before they travel all the way to the <a href=\"https://www.cloudflare.com/learning/cdn/glossary/origin-server/\">origin server</a>.</p>\n<p><img src=\"https://www.cloudflare.com/img/learning/serverless/serverless-javascript/serverless-javascript-running-on-edge-server.svg\" alt=\"Serverless JavaScript on Edge Server\" title=\"Serverless JavaScript on Edge Server\"></p>\n<p>Using serverless JavaScript, it is possible to expand the functionality and improve the user experience of existing applications by running code at the edge, or to create a new, fully serverless application that is fast and highly scalable. <a href=\"https://www.cloudflare.com/products/cloudflare-workers/\">Cloudflare Workers</a> is a serverless JavaScript platform.</p>\n<h2>What is Varnish?</h2>\n<p>Varnish is a web accelerator designed to speed up web applications and improve website performance. It is a caching HTTP <a href=\"https://www.cloudflare.com/learning/cdn/glossary/reverse-proxy/\">reverse proxy</a>, meaning it sits in front of any web server and accelerates HTTP traffic to and from that server by caching, or storing, any content that is frequently requested by web clients. Varnish Configuration Language, or VCL, is used in conjunction with Varnish to allow developers to customize how Varnish manages web requests.</p>\n<h2>What is the advantage of using JavaScript instead of VCL in a serverless architecture?</h2>\n<p>VCL is a configuration language designed to make the Varnish cache easy to configure; it’s not a full-fledged programming language. VCL is not flexible enough for building or expanding robust applications. It is limited in what it can do compared to JavaScript. In addition, VCL is not used outside of Varnish implementations, and as a result most developers are not familiar with it. In contrast, JavaScript is ubiquitous and already widely used for building applications. Using JavaScript in a serverless architecture allows developers to build full applications in a language they are familiar with.</p>\n<p>Serverless JavaScript allows a wider group of developers to leverage serverless computing on the edge, and allows those developers to build a greater variety of applications.</p>\n<h2>How does building an application with serverless JavaScript help reduce latency?</h2>\n<p>Serverless JavaScript runs in an HTTP caching network, which is closer to the end user than code hosted on an origin server. As a result, requests don't have to travel all the way to the origin server and back, and the application responds much more quickly to user interactions. The more geographically distributed edge locations that a caching network has, the more latency will be reduced.</p>\n<h2>When does serverless JavaScript run?</h2>\n<p>In a serverless model, applications are broken up into functions, and function code runs in response to certain events. It does not run otherwise. The event that triggers serverless JavaScript to execute is an HTTP request. Developers can customize the kind of HTTP requests that their JavaScript functions respond to, and how the HTTP request will be altered or fulfilled.</p>\n<h2>What is an HTTP request?</h2>\n<p>This is a request sent via <a href=\"https://www.cloudflare.com/learning/ddos/glossary/hypertext-transfer-protocol-http/\">HTTP (hypertext transfer protocol)</a> from a client to a server. Browsers translate user actions, such as clicking on a hyperlink or submitting a form, into HTTP requests. The request is then sent on to the server, and the server sends an HTTP response to fulfill the request. An HTTP request also occurs when an application makes an API call.</p>\n<h2>What is HTTP caching?</h2>\n<p>HTTP caching is when a server or a browser saves a copy of a response to a user's HTTP request in order to produce quicker replies to future requests. A <a href=\"https://www.cloudflare.com/learning/cdn/what-is-a-cdn/\">CDN</a> server is an example of an HTTP cache. Some HTTP caching services enable developers to customize how HTTP caching works for their applications.</p>\n<p>Cloudflare is an HTTP caching edge network with data centers all over the world, and it allows developers to write and deploy their own JavaScript at the network edge. In the Cloudflare network, HTTP caching does not take place in any specific server, but rather within whatever data center is closest to the source of the HTTP request.</p>\n<h2>What are service workers?</h2>\n<p>Service workers are scripts that browsers download and run in order to create customized experiences for users. Service workers make features like push notifications, background syncing, and offline functionality possible in the browser. Written in JavaScript, they intercept, modify, and respond to HTTP requests before the requests reach the Internet.</p>\n<h2>Two ways service workers can handle HTTP traffic:</h2>\n<p><img src=\"https://www.cloudflare.com/img/learning/serverless/serverless-javascript/service-worker-responds-http-request.svg\" alt=\"Service Worker Responds\" title=\"Service Worker Responds\"></p>\n<p>Service workers can respond to HTTP requests without contacting the web server</p>\n<p><img src=\"https://www.cloudflare.com/img/learning/serverless/serverless-javascript/service-worker-modifies-http-request-response.svg\" alt=\"Service Worker Modifies Request\" title=\"Service Worker Modifies Request\"></p>\n<p>Service workers can modify HTTP requests and responses</p>\n<h2>What are Cloudflare Workers?</h2>\n<p>Cloudflare Workers are a platform for enabling serverless functions to run as close as possible to the end user. In essence, the serverless code itself is 'cached' on the network, and runs when it receives the right type of request. Cloudflare Workers are written in JavaScript against the service workers API, meaning they can use all the functionality offered by service workers. They leverage the Chrome V8 engine for execution. Cloudflare Workers code is hosted in Cloudflare's vast network of data centers around the world.</p>\n<h2>What is Chrome V8?</h2>\n<p><a href=\"https://www.cloudflare.com/learning/serverless/glossary/what-is-chrome-v8/\">Chrome V8</a>, also known as just 'V8,' is a JavaScript engine Google developed for compiling, optimizing, and executing JavaScript. By using V8 for JavaScript code execution, startup time for JavaScript workers is greatly reduced, eliminating the issue of 'cold starts' in most cases. V8 is also heavily analyzed for security vulnerabilities, making it ideal for running JavaScript code securely.</p>"},{"url":"/docs/javascript/javascript-examples/","relativePath":"docs/javascript/javascript-examples/index.md","relativeDir":"docs/javascript/javascript-examples","base":"index.md","name":"index","frontmatter":{"title":"JavaScript Examples","template":"docs","excerpt":"Data structures examples in JavaScript"},"html":"<h1>JavaScript Examples</h1>\n<p><strong>Hello World</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">output</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">write</span><span class=\"token punctuation\">(</span><span class=\"token string\">'&lt;p>'</span> <span class=\"token operator\">+</span> t <span class=\"token operator\">+</span> <span class=\"token string\">'&lt;/p>'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, World!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, World!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">output</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, World!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Variables</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> num <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {1}</span>\nnum <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {2}</span>\n\n<span class=\"token keyword\">var</span> price <span class=\"token operator\">=</span> <span class=\"token number\">1.5</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {3}</span>\n<span class=\"token keyword\">var</span> myName <span class=\"token operator\">=</span> <span class=\"token string\">'Packt'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {4}</span>\n<span class=\"token keyword\">var</span> trueValue <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {5}</span>\n<span class=\"token keyword\">var</span> nullVar <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {6}</span>\n<span class=\"token keyword\">var</span> und<span class=\"token punctuation\">;</span> <span class=\"token comment\">// {7}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num: '</span> <span class=\"token operator\">+</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'myName: '</span> <span class=\"token operator\">+</span> myName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'trueValue: '</span> <span class=\"token operator\">+</span> trueValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'price: '</span> <span class=\"token operator\">+</span> price<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'nullVar: '</span> <span class=\"token operator\">+</span> nullVar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'und: '</span> <span class=\"token operator\">+</span> und<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// ******* Variable Scope</span>\n\n<span class=\"token keyword\">var</span> myVariable <span class=\"token operator\">=</span> <span class=\"token string\">'global'</span><span class=\"token punctuation\">;</span>\nmyOtherVariable <span class=\"token operator\">=</span> <span class=\"token string\">'global'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> myVariable <span class=\"token operator\">=</span> <span class=\"token string\">'local'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> myVariable<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">myOtherFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    myOtherVariable <span class=\"token operator\">=</span> <span class=\"token string\">'local'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> myOtherVariable<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myVariable<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//{1}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//{2}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myOtherVariable<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//{3}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">myOtherFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//{4}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myOtherVariable<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//{5}</span></code></pre></div>\n<ul>\n<li><strong>Arithmetic operators</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> num <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {1}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num value is '</span> <span class=\"token operator\">+</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nnum <span class=\"token operator\">=</span> num <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'New num value is '</span> <span class=\"token operator\">+</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nnum <span class=\"token operator\">=</span> num <span class=\"token operator\">*</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'New num value is '</span> <span class=\"token operator\">+</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nnum <span class=\"token operator\">=</span> num <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'New num value is '</span> <span class=\"token operator\">+</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nnum<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\nnum<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'New num value is '</span> <span class=\"token operator\">+</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num mod 2 value is '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">%</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* Assignment operators */</span>\nnum <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\nnum <span class=\"token operator\">-=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\nnum <span class=\"token operator\">*=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\nnum <span class=\"token operator\">/=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\nnum <span class=\"token operator\">%=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'New num value is '</span> <span class=\"token operator\">+</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* Assignment operators */</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num == 1 : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num === 1 : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num != 1 : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">!=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num > 1 : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num &lt; 1 : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">&lt;</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num >= 1 : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">>=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num &lt;= 1 : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* Logical operators */</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'true &amp;&amp; false : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'true || false : '</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'!true : '</span> <span class=\"token operator\">+</span> <span class=\"token operator\">!</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* Bitwise operators */</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'5 &amp; 1:'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span> <span class=\"token operator\">&amp;</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// same as 0101 &amp; 0001 (result 0001 / 1)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'5 | 1:'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span> <span class=\"token operator\">|</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// same as 0101 | 0001 (result 0101 / 5)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'~ 5:'</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">~</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// same as ~0101 (result 1010 / 10)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'5 ^ 1:'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span> <span class=\"token operator\">^</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// same as 0101 ^ 0001 (result 0100 / 4)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'5 &lt;&lt; 1:'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span> <span class=\"token operator\">&lt;&lt;</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// same as 0101 &lt;&lt; 1 (result 1010 / 10)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'5 >> 1:'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span> <span class=\"token operator\">>></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// same as 0101 >> 1 (result 0010 / 2)</span>\n\n<span class=\"token comment\">/* typeOf */</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'typeof num:'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'typeof Packt:'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> <span class=\"token string\">'Packt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'typeof true:'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'typeof [1,2,3]:'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'typeof {name:John}:'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* delete */</span>\n<span class=\"token keyword\">let</span> myObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">21</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">delete</span> myObj<span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myObj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Object {name: \"John\"}</span></code></pre></div>\n<ul>\n<li><strong>Truthy &#x26; Falsey</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">val</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> val <span class=\"token operator\">?</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'truthy'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'falsy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Boolean</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true (object is always true)</span>\n\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Packt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">String</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true (object is always true)</span>\n\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true (object is always true)</span>\n\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true (object is always true)</span>\n\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n<span class=\"token function\">testTruthy</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false (property is undefined)</span></code></pre></div>\n<ul>\n<li><strong>Equals Operator:</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'packt'</span> <span class=\"token operator\">?</span> <span class=\"token boolean\">true</span> <span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// outputs true</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'packt'</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 1 - converts Boolean using toNumber</span>\n<span class=\"token comment\">// 'packt' == 1</span>\n<span class=\"token comment\">// 2 - converts String using toNumber</span>\n<span class=\"token comment\">// NaN == 1</span>\n<span class=\"token comment\">// outputs false</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'packt'</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 1 - converts Boolean using toNumber</span>\n<span class=\"token comment\">// 'packt' == 0</span>\n<span class=\"token comment\">// 2 - converts String using toNumber</span>\n<span class=\"token comment\">// NaN == 0</span>\n<span class=\"token comment\">// outputs false</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 1 - converts Boolean using toNumber</span>\n<span class=\"token comment\">// [0] == 1</span>\n<span class=\"token comment\">// 2 - converts Object using toPrimitive</span>\n<span class=\"token comment\">// 2.1 - [0].valueOf() is not primitive</span>\n<span class=\"token comment\">// 2.2 - [0].toString is 0</span>\n<span class=\"token comment\">// 0 == 1</span>\n<span class=\"token comment\">// outputs false</span>\n\n<span class=\"token comment\">//* ****************************** ===</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'packt'</span> <span class=\"token operator\">===</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'packt'</span> <span class=\"token operator\">===</span> <span class=\"token string\">'packt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n\n<span class=\"token keyword\">let</span> person1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> person2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>person1 <span class=\"token operator\">===</span> person2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false, different objects</span></code></pre></div>\n<ul>\n<li>\n<h4><strong>:</strong></h4>\n</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">/* Example 01 - if */</span>\n<span class=\"token keyword\">let</span> num <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num is equal to 1'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Example 02 - if-else */</span>\n<span class=\"token keyword\">let</span> num <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num is equal to 1'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num is not equal to 1, the value of num is '</span> <span class=\"token operator\">+</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Example 03 - if-else-if-else... */</span>\n<span class=\"token keyword\">let</span> month <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>month <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'January'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>month <span class=\"token operator\">===</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'February'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>month <span class=\"token operator\">===</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'March'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Month is not January, February or March'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Example 04 - switch */</span>\n<span class=\"token keyword\">let</span> month <span class=\"token operator\">=</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>month<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">1</span><span class=\"token operator\">:</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'January'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">2</span><span class=\"token operator\">:</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'February'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">3</span><span class=\"token operator\">:</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'March'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Month is not January, February or March'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">/* Example 05 - ternary operator - if..else */</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    num<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    num<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// is the same as</span>\nnum <span class=\"token operator\">===</span> <span class=\"token number\">1</span> <span class=\"token operator\">?</span> num<span class=\"token operator\">--</span> <span class=\"token operator\">:</span> num<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Loops</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'**** for example ****'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/* for - example */</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'**** while example ****'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/* while - example */</span>\n<span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'**** do-while example ****'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/* do-while - example */</span>\n<span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">do</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Functions:</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">sayHello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">sayHello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* function with parameter */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">output</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">text</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">output</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">output</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello!'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Other text'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">output</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* function using the return statement */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">num1<span class=\"token punctuation\">,</span> num2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> num1 <span class=\"token operator\">+</span> num2<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">output</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Object Orientation:</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">/* Object example 1 */</span>\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* Object example 2 */</span>\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nobj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">first</span><span class=\"token operator\">:</span> <span class=\"token string\">'Gandalf'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">last</span><span class=\"token operator\">:</span> <span class=\"token string\">'the Grey'</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">address</span><span class=\"token operator\">:</span> <span class=\"token string\">'Middle Earth'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* Object example 3 */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Book</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> pages<span class=\"token punctuation\">,</span> isbn</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>pages <span class=\"token operator\">=</span> pages<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>isbn <span class=\"token operator\">=</span> isbn<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">printIsbn</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>isbn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> book <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pag'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'isbn'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>book<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// outputs the book title</span>\n\nbook<span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> <span class=\"token string\">'new title'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// update the value of the book title</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>book<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// outputs the updated value</span>\n\n<span class=\"token class-name\">Book</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">printTitle</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nbook<span class=\"token punctuation\">.</span><span class=\"token function\">printTitle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nbook<span class=\"token punctuation\">.</span><span class=\"token function\">printIsbn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Let &#x26; Const:</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): let and const keywords</span>\n\n<span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): let is the new var (https://goo.gl/he0udZ)</span>\n<span class=\"token keyword\">var</span> framework <span class=\"token operator\">=</span> <span class=\"token string\">'Angular'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> framework <span class=\"token operator\">=</span> <span class=\"token string\">'React'</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>framework<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> language <span class=\"token operator\">=</span> <span class=\"token string\">'JavaScript!'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {1}</span>\n<span class=\"token comment\">// let language = 'Ruby!'; // {2} - throws error</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>language<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): const (https://goo.gl/YUQj3r)</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">PI</span> <span class=\"token operator\">=</span> <span class=\"token number\">3.141593</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// PI = 3.0; //throws error</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">PI</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> jsFramework <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Angular'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\njsFramework<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'React'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// error, cannot reassign object reference</span>\n<span class=\"token comment\">/*\njsFramework = {\n  name: 'Vue'\n};\n*/</span></code></pre></div>\n<ul>\n<li>\n<h4><strong>11-ES2015-ES6-variableScope:</strong></h4>\n</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): variables scope (https://goo.gl/NbsVvg)</span>\n<span class=\"token keyword\">let</span> movie <span class=\"token operator\">=</span> <span class=\"token string\">'Lord of the Rings'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {1}</span>\n<span class=\"token comment\">// let movie = 'Batman v Superman'; //throws error, variable movie already declared</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">starWarsFan</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> movie <span class=\"token operator\">=</span> <span class=\"token string\">'Star Wars'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {2}</span>\n    <span class=\"token keyword\">return</span> movie<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">marvelFan</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    movie <span class=\"token operator\">=</span> <span class=\"token string\">'The Avengers'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {3}</span>\n    <span class=\"token keyword\">return</span> movie<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">blizzardFan</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> isFan <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> phrase <span class=\"token operator\">=</span> <span class=\"token string\">'Warcraft'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {4}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Before if: '</span> <span class=\"token operator\">+</span> phrase<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>isFan<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> phrase <span class=\"token operator\">=</span> <span class=\"token string\">'initial text'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {5}</span>\n        phrase <span class=\"token operator\">=</span> <span class=\"token string\">'For the Horde!'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {6}</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Inside if: '</span> <span class=\"token operator\">+</span> phrase<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    phrase <span class=\"token operator\">=</span> <span class=\"token string\">'For the Alliance!'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {7}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'After if: '</span> <span class=\"token operator\">+</span> phrase<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>movie<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {8}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">starWarsFan</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {9}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">marvelFan</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {10}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>movie<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {11}</span>\n<span class=\"token function\">blizzardFan</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {12}</span>\n\n<span class=\"token comment\">// output</span>\n<span class=\"token comment\">// Lord of the Rings</span>\n<span class=\"token comment\">// Star Wars</span>\n<span class=\"token comment\">// The Avengers</span>\n<span class=\"token comment\">// The Avengers</span>\n<span class=\"token comment\">// Before if: Warcraft</span>\n<span class=\"token comment\">// Inside if: For the Horde!</span>\n<span class=\"token comment\">// After if: For the Alliance!</span></code></pre></div>\n<ul>\n<li><strong>String Templates:</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): Template literals (https://goo.gl/4N36CS)</span>\n<span class=\"token keyword\">const</span> book <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Learning JavaScript DataStructures and Algorithms'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are reading '</span> <span class=\"token operator\">+</span> book<span class=\"token punctuation\">.</span>name <span class=\"token operator\">+</span> <span class=\"token string\">'.,\\n\tand this is a new line\\n\tand so is this.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">You are reading </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>book<span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">.,\n   and this is a new line\n    and so is this.</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Arrow Functions:</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): arrow functions (https://goo.gl/nM414v)</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">circleAreaES5</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token function\">circleArea</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> <span class=\"token constant\">PI</span> <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> area <span class=\"token operator\">=</span> <span class=\"token constant\">PI</span> <span class=\"token operator\">*</span> r <span class=\"token operator\">*</span> r<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> area<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">circleAreaES5</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">circleArea</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">r</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// {1}</span>\n    <span class=\"token keyword\">const</span> <span class=\"token constant\">PI</span> <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> area <span class=\"token operator\">=</span> <span class=\"token constant\">PI</span> <span class=\"token operator\">*</span> r <span class=\"token operator\">*</span> r<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> area<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">circleArea</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">circleArea2</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">r</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token number\">3.14</span> <span class=\"token operator\">*</span> r <span class=\"token operator\">*</span> r<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">circleArea2</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">hello</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hello!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">hello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Parameter Handlers:</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): Default Parameter Values (https://goo.gl/AP5EYb)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> y <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> z <span class=\"token operator\">=</span> <span class=\"token number\">3</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> x <span class=\"token operator\">+</span> y <span class=\"token operator\">+</span> z<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// outputs 9</span>\n\n<span class=\"token comment\">// function above is the same as</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">sum2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> z</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>x <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> x <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> y <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>z <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> z <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> x <span class=\"token operator\">+</span> y <span class=\"token operator\">+</span> z<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">sum2</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// outputs 9</span>\n\n<span class=\"token comment\">// or</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">sum3</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> x <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">&amp;&amp;</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> z <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token operator\">&amp;&amp;</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> x <span class=\"token operator\">+</span> y <span class=\"token operator\">+</span> z<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">sum3</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// outputs 9</span>\n\n<span class=\"token comment\">//* ****** EcmaScript 6: spread operator ('...') (https://goo.gl/8equk5)</span>\n<span class=\"token keyword\">let</span> params <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>params<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ES2015</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">sum</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> params<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ES5</span>\n\n<span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>params<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// pushing values into array</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//* ****** EcmaScript 6: rest parameter ('...') (https://goo.gl/LaJZqU)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">restParamaterFunction</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>x <span class=\"token operator\">+</span> y<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> a<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">restParamaterFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// outputs 9;</span>\n\n<span class=\"token comment\">// code above is the same as ES5:</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">restParamaterFunction2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>x <span class=\"token operator\">+</span> y<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> a<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">restParamaterFunction2</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Destructuring Assignment</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): Destructuring Assignment + Property Shorthand (https://goo.gl/VsLecp )</span>\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> x<span class=\"token punctuation\">,</span> y <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// { x: \"a\", y: \"b\" }</span>\n\n<span class=\"token comment\">// swap (https://goo.gl/EyFAII)</span>\n<span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>y<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> temp <span class=\"token operator\">=</span> x<span class=\"token punctuation\">;</span>\nx <span class=\"token operator\">=</span> y<span class=\"token punctuation\">;</span>\ny <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// code above is the same as</span>\n<span class=\"token keyword\">var</span> x2 <span class=\"token operator\">=</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> y2 <span class=\"token operator\">=</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> obj2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">x2</span><span class=\"token operator\">:</span> x2<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">y2</span><span class=\"token operator\">:</span> y2 <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// { x: \"a\", y: \"b\" }</span>\n\n<span class=\"token comment\">// Method Properties (https://goo.gl/DKU2PN)</span>\n<span class=\"token keyword\">const</span> hello <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'abcdef'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">printHello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>hello<span class=\"token punctuation\">.</span><span class=\"token function\">printHello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// code above is the same as:</span>\n<span class=\"token keyword\">var</span> hello2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'abcdef'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">printHello</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">printHello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>hello2<span class=\"token punctuation\">.</span><span class=\"token function\">printHello</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li><strong>Classes &#x26; More:</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//* ****** EcmaScript 2015 (ES6): classes (https://goo.gl/UhK1n4)</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Book</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> pages<span class=\"token punctuation\">,</span> isbn</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>pages <span class=\"token operator\">=</span> pages<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>isbn <span class=\"token operator\">=</span> isbn<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">printIsbn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>isbn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> book <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pag'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'isbn'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>book<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// outputs the book title</span>\n\nbook<span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> <span class=\"token string\">'new title'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// update the value of the book title</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>book<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// outputs the book title</span>\n\n<span class=\"token comment\">// inheritance (https://goo.gl/hgQvo9)</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ITBook</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Book</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// {1}</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title<span class=\"token punctuation\">,</span> pages<span class=\"token punctuation\">,</span> isbn<span class=\"token punctuation\">,</span> technology</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>title<span class=\"token punctuation\">,</span> pages<span class=\"token punctuation\">,</span> isbn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {2}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>technology <span class=\"token operator\">=</span> technology<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">printTechnology</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>technology<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> jsBook <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ITBook</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Learning JS Algorithms'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'200'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'1234567890'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'JavaScript'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>jsBook<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>jsBook<span class=\"token punctuation\">.</span><span class=\"token function\">printTechnology</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// getter and setters (https://goo.gl/SMRYsv)</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Person</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span> <span class=\"token comment\">// {1}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">name</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// {2}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">set</span> <span class=\"token function\">name</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// {3}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_name <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> lotrChar <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Frodo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>lotrChar<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {4}</span>\nlotrChar<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Gandalf'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {5}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>lotrChar<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nlotrChar<span class=\"token punctuation\">.</span>_name <span class=\"token operator\">=</span> <span class=\"token string\">'Sam'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {6}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>lotrChar<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// using symbols for private atributes</span>\n<span class=\"token keyword\">var</span> _name <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Person2</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">[</span>_name<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">name</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">[</span>_name<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">set</span> <span class=\"token function\">name</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">[</span>_name<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">let</span> lotrChar2 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person2</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Frodo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>lotrChar2<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nlotrChar2<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Gandalf'</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>lotrChar2<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertySymbols</span><span class=\"token punctuation\">(</span>lotrChar2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>More:</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Book</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">title</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> title<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">printTitle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">circleArea</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">r</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token number\">3.14</span> <span class=\"token operator\">*</span> r <span class=\"token operator\">**</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">squareArea</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> s <span class=\"token operator\">*</span> s<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// export { circleArea, squareArea }; // {1}</span>\n<span class=\"token keyword\">export</span> <span class=\"token punctuation\">{</span> circleArea <span class=\"token keyword\">as</span> circle<span class=\"token punctuation\">,</span> squareArea <span class=\"token keyword\">as</span> square <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> area <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./lib/17-CalcArea'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> Book <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./lib/17-Book'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>area<span class=\"token punctuation\">.</span><span class=\"token function\">circle</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>area<span class=\"token punctuation\">.</span><span class=\"token function\">square</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> myBook <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'some title'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmyBook<span class=\"token punctuation\">.</span><span class=\"token function\">printTitle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/* Different way of importing the module  */</span>\n<span class=\"token comment\">// import * as area from './17-CalcArea';</span>\n<span class=\"token comment\">// import Book from './17-Book';</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> area <span class=\"token keyword\">from</span> <span class=\"token string\">'./17-CalcArea.js'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// we need the .js to run this code in the browser</span>\n<span class=\"token keyword\">import</span> Book <span class=\"token keyword\">from</span> <span class=\"token string\">'./17-Book.js'</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>area<span class=\"token punctuation\">.</span><span class=\"token function\">circle</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>area<span class=\"token punctuation\">.</span><span class=\"token function\">square</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> myBook <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Book</span><span class=\"token punctuation\">(</span><span class=\"token string\">'some title'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmyBook<span class=\"token punctuation\">.</span><span class=\"token function\">printTitle</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//* ****** EcmaScript 2016 (ES7): Exponentiation operator (https://goo.gl/Z6dCFB)</span>\n<span class=\"token keyword\">let</span> r <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> area <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span> <span class=\"token operator\">*</span> r <span class=\"token operator\">*</span> r<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> area2 <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span> <span class=\"token operator\">*</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">pow</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> area3 <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span> <span class=\"token operator\">*</span> r <span class=\"token operator\">**</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>area<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>area2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>area3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>"},{"url":"/docs/css/the-ultimate-guide-for-advanced-css-hacks/","relativePath":"docs/css/the-ultimate-guide-for-advanced-css-hacks/index.md","relativeDir":"docs/css/the-ultimate-guide-for-advanced-css-hacks","base":"index.md","name":"index","frontmatter":{"title":"The Ultimate guide for advanced CSS hacks","template":"docs","excerpt":" It covers the following CSS topics"},"html":"<!--StartFragment-->\n<p>If you have ever considered learning some advanced CSS tricks, than this guide is a great place start. It covers the following CSS topics;</p>\n<ul>\n<li>Animate CSS</li>\n<li>Refactoring CSS Code</li>\n<li>Native CSS3 Animations</li>\n<li>Using Color Gradients in CSS3</li>\n<li>An Overview of CSS Positioning</li>\n<li>An overview of CSS Selectors</li>\n<li>Understanding specificity in CSS</li>\n<li>Using WOW.js and Animate.css for Scroll-Triggered Animations</li>\n<li>Introduction to CSS flexbox &#x26; Advanced CSS Selectors</li>\n</ul>\n<h2>What is Animate.CSS [Tutorial]</h2>\n<p>This section explains how getting started with Animate.css better supports web developers in creating creative and function animate designs through simple and efficient programming. To upgrade web content and improve application designs, Getting Started with Animate.css [Tutorial] is a great way to make unique content. Developers gain an advantage over other competing sites with creative and different features, faster and better quality content, and better cross-browser compatibility when sharing web site content across the digital environment. The Animate.CSS library extension provides the tools, simplicity, and flexibility for all web and <a href=\"https://sunlightmedia.org/services/mobile-app-development/\">mobile app development services</a>.</p>\n<p>CSS animation is an extension of Cascading Style Sheets (CSS) with different animation features. The module embeds a library of designs for websites an offers users with convenience, creativity, and professional web applications. Web developers Getting Started with Animate.css [Tutorial] apply animation designs, edit CSS sequences, and improve website design through the Cascading Style Sheet extension. The extension simplifies developer interaction when implementing animation designs with straightforward configurations to specific HTML elements that require less processing and memory usage from Flash or JavaScript.</p>\n<h3>Advantages</h3>\n<p>Without a doubt, Animate.CSS gains popularity from the developer community for simplicity and compatibility. Primarily, Animate.CSS has simple and ready to use style sheet scripts that copy and paste into developer website documents for high developer convenience. Also, the module is built to prevent users from settling for generic GIFS or Flash images that limit developer creativity and require additional steps that slow down project development completion times. Additionally, there are are a lot of shorthand animation design style scripts for animation properties when Getting Started with Animate.css. Importantly, the Cascading Styles Sheet (CSS) Animate.CSS program includes advanced keyframes extensions that better equip developers with design customization developer tools needed for creative and functional animated designs. Along with an easy to use the module, Animate also proves compatible for additional upgrades or improvements with Javascript.</p>\n<h3>How do Animations Work in Animate.CSS</h3>\n<p>CSS animate is a unique library module built from a simple and <a href=\"https://dev.to/iamdejean/basic-css-animation-3b86\">effective design</a>. To explain, Animate.CSS includes two main components for styling websites. The first component styles and stores information for CSS animations. However, the second component uses “keyframes” to signal web developers the beginning and end of sequences for animation designs. Also, this component uses advanced transition points to allow better animation configuration.</p>\n<h3>Creating an Animation</h3>\n<p>CSS animations include primary and sub-property components. Usually, web developers getting started with Animate.css using Animate.CSS style-specific script elements and include additional designing styles for animation properties. More specifically, properties work between different stye functions to equip websites with functional and simple animations. Animation properties include wide criteria of style elements such as animation-name, duration, timing, and delays. Other forms include animation count, direction, fill, and play. Fortunately, the library module enables <a href=\"https://sunlightmedia.org/services/web-design/\">responsive web designers</a> to apply these properties to website animations with simple text sequences, rather than formatting and testing numerous codes with functional uncertainty.</p>\n<h3>Keyframes</h3>\n<p>Through the.CSS Animate extension, users work with “keyframes” to create animation with component elements. For the benefit of users, the “keyframes” are setup through Cascading Style Sheets to offer users gradual editing capabilities to CSS style sets while allowing web developers to focus on important animation features. To elaborate, the “keystones” help users perform configurations within timing, duration, and in-depth detailing elements within a different design sequence.</p>\n<h3><strong>Keyframes At-rule</strong></h3>\n<p>Additionally, the display of the animations requires users to operate “keyframes at-rule” to better connect with component elements. For more specific property configurations, the extension corrects animation values between design “keyframes.” For identification purposes, web developers value “keyframes at-rule” to edit multiple names within sequences and locate elements that do not have value to the CSS style set. Furthermore, the “keyframes at-rule” expands editing capabilities for web developers with useful code indicators for animations to better render elements during design styles.</p>\n<h3>Annimate.CSS Transform</h3>\n<p>Equally important, Cascading Style Sheets (CSS) Animate.CSS features offer “transforming” properties for better element editing. Elements not compatible with CSS designs alter with the transform tool. Beneficially, developers using transform tools such as scale, rotate, skew, and translate will configure elements to better design on web applications. Transform properties, either 2d or 3d, provide users with additional designing creativity and functionality when creating websites.</p>\n<h3>Scale</h3>\n<p>With scale, users of Animate.CSS adjust the dimensions of designs to better fit web content. The specific CSS transform function corrects width and heights of elements to better scale content on web apps. By default, scale values start with an attribute of one, which adjusts to a value greater or less than one form more or less scalability for elements. Put simply, the attributes on CSS enable proportionate corrections when handling scaling configurations to element and content design.</p>\n<h3>Skew</h3>\n<p>To continue, the transform tools on Animate.CSS consists of a skew function for web developers. The design of element properties aligns with a horizontal and vertical axis on web apps which may be skew. Typically, the skew functions include “x” and “y” values to assist developers to distort elements on the axis.</p>\n<h3>Translate</h3>\n<p>Another transform feature is CSS translate. Similarly, the translate function also shares “x” and “y” values to assist better design functionality for developers. Unlike the CSS skew function, they translate tool allows users to position a particular element within both the horizontal and vertical axis.</p>\n<h3>Rotate</h3>\n<p>In addition, developers getting started with Animate.css use the transform tool also includes a rotate function for elements. With ease, users may adjust the angle of an element in any direction. The rotation values are positive when rotating content clockwise and drop off to negative values when adjusting an element counter-clockwise.</p>\n<h3>Matrix</h3>\n<p>Finally, CSS transform features include matrix functions for elements. Especially useful for developers, the matrix tool joins 2d configurations onto a single element for universal editing applications.</p>\n<h2>Just-add-water CSS Animation</h2>\n<p>The Animate.CSS system refers to “Just-Add-Water.” The module classifies as a “cross-browser” animations source which indicates its user-friendliness and simple design for new or established web developers.</p>\n<h3>Installation</h3>\n<p>To begin, the administrators require installation of the Just Add Water Cascading Style Sheets Animation program. First, installation occurs via NPM. To define, the Node Package Manager collaborates with <a href=\"https://sunlightmedia.org/javascript-tips/\">JavaScript</a> script, which shares the design of Animate.CSS. By default, the programming language operates with Node.JS as a stable premise for web development. Next, users use this code “$ Node Package Manager install animate.css –save,” to install the program.</p>\n<p>Alternatively, the sequence follows “$ yarn add animate.css.” To further explain, a yarn installation also assists administrators with project installations. Ordinarily, “Yarn” associates installations with dependencies that use codes or another decency for installation. Unlike, the Node Packaging Manager (npm) install method, the “yarn” alternative does not apply a “–save” or “–sav-dev” when adding new programs. In-depth, a dependency can not operate unless with support from another more prominent program. The combination of the module and installation extensions collaborate with innovative new library models.</p>\n<h2>Using Animate.CSS [Tutorial]</h2>\n<p>On the Animate.CSS website, open-source codes are available for web developers. The user may select the <a href=\"https://raw.github.com/daneden/animate.css/master/animate.css\">Download Animate.css</a> to access different Cascading Style Sheet animation text. The list includes a wide variety of design styles and may apply directly to the user website. Additionally, the <a href=\"https://raw.githubusercontent.com/daneden/animate.css/master/animate.css\">download</a> code is another method for getting started with Animate.Css.</p>\n<h3>Getting started on Animate.CSS on Websites</h3>\n<p>Applying the Cascading Style Sheets (CSS) stylesheets onto the developer website is easy, fast, and effective. However, text implementation requires user attention to detail. First, the Cascading Style Sheets (CSS) animate.CSS stylesheet must be correctly placed within the developer’s document “<head>.” Next, the administrator applies the “animated” stylesheet class to an element within the web application document. Also, the animated script follows CSS names to perform specific animation functions for the element. Alternatively, users may switch over to other versions, like CDNJS, as another host for Annimate.CSS element configurations. The format is shown below:</p>\n<h2>Animations on Animate.CSS</h2>\n<p>Web designers getting started with Animate.css value simple and quality animation that differentiates content on web applications. The animation stylesheets provided on Animate.CSS includes an abundance of Cascading Style Sheet (CSS) animation styles that customize document elements. Moreover, to create an animation design to an element, the developer must input the “animated” tag. The class embeds within a document element and requires additional instruction to better define content attributes. Commonly, developers rely on an active element with a feature set to “infinite” to enable multiple cycles of animation designs within a web site. Also highly regarded, the duration constraints on animations, along with delays and user animation interaction are available within the Animate.CSS style sheets list.</p>\n<p>Shown below are animation classes for web developers getting started with Animate.css [Tutorial] to implement into web application documents.</p>\n<h2>Start Timing Animations</h2>\n<p>For the most part, web developers getting started with Annimate.CSS seek animation designs to improve the content on web sites. Reasonably, the animation should have the ability to perform as a method to attract site visitors to particular information on sites. Therefore, developers should understand how to configure elements in regard to animation delays, speed, and timing.</p>\n<h3>Delay</h3>\n<p>Presently, Animate.CSS assists developers with delay features with a particular stylesheet. For example, a stylesheet with a delay function might appear like this: “&#x3C;div class=”animated bounce delay-2s”>Example</div>.” In this scenario, a delay of two seconds occurs for an element that has a bounce animate class attached. Delay classes identify as “delay” and can alter delay functions from one to five seconds. Further delay periods are acceptable if users add Cascading Style Sheet (CSS) texts especially the code.</p>\n<h3>Speed</h3>\n<p>Additionally, element designs on Annimate.CSS have speed time values. The developer may correct the speed of an animation using a specific stylesheet for the class. For instance, an animation time sequence may look like this: “&#x3C;div class=”animate bounce faster”>Example</div>.” Moreover, the developer enables the animate element to bounce and creates a speed function of “faster.” Additionally, class names may refer to as “slow,” “slower,” “fast,” and “faster.” Along with class names, speed times like “2 seconds,” “3 seconds,” “800 milliseconds,” and “500 milliseconds” address the rate of the elements function. By default, the element rates set to a standard value of one second. Users, with additional extensions, may alter timings by manual text editing within the Cascading Style Sheets (CSS) Annimate.CSS stylesheets.</p>\n<h2>Start Custom Builds</h2>\n<p>Previously mentioned, developers can manually adjust the Animate.CSS stylesheets to develop new animations separate from the standard defaults. Another source, such as “<a href=\"https://gulpjs.com/\">gulp.js</a>,” is Animate.CSS compatible and offers easy to set up custom animation builds. More specifically, the cross-browser platform is an automation program for task development. For web developers and programmers, The Gulp extension analyzes and organizes a variety of pipe-driven files to support plug-ins on user servers. In this case, Gulp interacts with dependencies for the creation of personalized animation builds and functions.</p>\n<p>As an example, the initial phase calls developers to input the stylesheet script “$ cd path/to/animate.css/.” Once again, the administrator addresses the document with a “$ npm install.” After, web developers will join the builds into the “NPX Gulp” packaging program. As a plus, the packaging within Gulp is adjustable to include animate design styles to fit the web content. Users would edit this package with an “animate-config.json” script to select and choose appropriate builds. Selecting through the build options with values of “true” and “false” determine which builds are added or removed from the NPX Gulp list.</p>\n<h2>Animate.CSS with Javascript</h2>\n<p>With Javascript, the Animate.CSS library module enables users with additional features for designing web applications. The features include more specific animation functions with specific directional instructions, animation timing signals, adding and removal animation keys, and post animation effects. Also, <a href=\"https://sunlightmedia.org/javascript-tips/\">Javascript offers better cross-browser functionality</a> for the Animate.CSS extension and allows users more flexibility on which decelerations perform best for user software.</p>\n<h2>Summary</h2>\n<p>In summary, Animate.css is a cross-browser library module with simple and effective Cascading Style Sheet (CSS) programming. The design encourages developer creativity with compatibility for alternative dependencies and includes numerous animate design features. Along with different versions of design stylesheets, animation behavior also changes through programmer text interaction. Web application developers, with the support of Annimate.CSS, create more <a href=\"https://sunlightmedia.org/portfolio/\">responsive websites</a> with quality animations that are easy to maintain and provide unique website interaction.</p>\n<h2>Refactoring CSS Code</h2>\n<p>Writing good code is about more than just getting the results you want on a webpage. Good code should be as efficient and concise as possible. While there are often numerous ways to achieve the same results, the most succinct and simple method is, with few exceptions, the ideal choice.</p>\n<p>There are two major benefits of writing good, clean code. Firstly, it can dramatically <a href=\"https://sunlightmedia.org/speed-up-wordpress/\">improve site speed and performance</a>. The smaller your file is (and the fewer external requests you are sending) the less time it will take for your website to load in the browser. Secondly, writing good code has the invaluable benefit of making it easier to maintain. Whether you are coding a project on your own or with other developers involved, the more lean your code is (ideally with good documentation), the less it’s going to be a headache for anyone having to revisit the codebase.</p>\n<p>Best practices for writing good code are often applicable to all programming languages, although this post will specifically be tailored to improving the CSS on your website.</p>\n<h3>Remove unnecessary HTTP Requests</h3>\n<p>Many times in the process of developing a website, you may end up with multiple external files and dependencies linked to from your HTML document or CSS files. You may try out multiple different fonts or CSS frameworks, hosted on an external CDN. Each one of these dependencies represents an HTTP request your site is making each time it is loaded in the browser. This puts a great strain on site load time, and all of these requests add up pretty quickly.</p>\n<p>If you added a bunch of external font files to your project, but are currently only referencing 1 or 2 in your CSS file, go through and remove any of these linked dependencies from the <code class=\"language-text\">&lt;head></code> of your HTML document.</p>\n<p>Are you only using a CSS framework for just a few lines of code? Consider copying and pasting these lines to your main <code class=\"language-text\">.css</code> stylesheet, and remove the link to the original CSS framework code.</p>\n<h3>Simplify &#x26; Consolidate CSS Rules</h3>\n<p>While writing CSS, you may end up repeatedly writing the same rules for various different elements and selectors. In computer programming, the oft-repeated concept of “DRY” (Don’t Repeat Yourself) applies to CSS as well. Anytime you find yourself writing the same CSS rules for different selectors, find a way to consolidate them.</p>\n<p>For example, instead of writing:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Consider writing:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Or even better:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>While this may not seem like a big difference (at least in terms of lines of code), the total count of characters has been significantly reduced, which will have an impact on page load times. Additionally, it consolidates elements and selectors that are utilizing the same styles, making it clearer to see what common styles are being applied to different elements.</p>\n<h3>Reasses your ID &#x26; Class values</h3>\n<p>It’s often tempting to assign an aspect of style presentation as your class or ID values, but this is far from ideal. For example, for an error message, it can often seem to make sense to use <code class=\"language-text\">red</code> as the class or ID value, like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>But what happens if you change the color or other styles of this class? This class will no longer have a direct relation to its content or presentation, and will most likely cause confusion. A better choice in this situation would be to use a class value that explains its function, rather than its stylistic presentation:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>It’s always a good idea to use class and ID values that describe the content or function of that element, rather than any stylistic descriptions. Style can change many times throughout the process of creating a site, but using descriptors for functions will make the code much more readable and easy to maintain.</p>\n<h3>Reasses your selector choices</h3>\n<p>There are often many different ways of selecting an element, but there are often more efficient ways than others. While it is possible to nest selectors inside of each other in order to get to a specific element, if you find yourself having to go too many levels in, it might be best to reassess if a class or ID value would function better.</p>\n<h3>Check for redundancies</h3>\n<p>In the process of styling your webpage, you may try out a variety of different colors, for example many shades of the same color. It’s easy to leave these different rule sets in your code, without deciding on a definitive single color. A good tool to use to check for these types of redundancies is <a href=\"http://cssstats.com/\">cssstats.com</a>.</p>\n<p>Not only will this simplify your code, it will also make your overal design much more consistent, rather than having 40 different shades of a color on the site.</p>\n<h3>Minify your CSS files</h3>\n<p>Once your CSS files are fully ready for production and deployment to a live server, it’s a good idea to minify them for best performance. A minifier will remove all white space from your source code, significantly reducing the file size. Since source code does not rely on white space for its functionality (only its readability), this will have no negative affect on how your site runs.</p>\n<p>There are many free tools for minifying CSS (and JS files). One option is <a href=\"https://cssminifier.com/\">cssminifier.com</a>.</p>\n<h3>Consolidate your CSS files</h3>\n<p>As was briefly touched on in the last post, it is a good idea to consolidate your resources as much as possible. While there is a good argument for keeping CSS modular during the development stage (such as keeping layout rules in one CSS file, color options in another, etc.) — ultimately you will want to consolidate all of these CSS rules into a single file for best performance.</p>\n<h2>Native CSS3 Animations</h2>\n<p>Although popular libraries like <a href=\"https://daneden.github.io/animate.css/\">Animate.css</a> make it easy to add CSS animations to your project, they are largely comprised of common motions such as “bounce”, “shake” and other stock movements that can feel rather stale when overused. By taking advantage of the animation properties built in to CSS, you can create much more complex and customized animations far beyond just motion. CSS animations can effect element color, size, position or any other property available in the CSS3 specification. This post will give an introduction to getting started with the native CSS3 properties and some examples of possible uses for them.</p>\n<h3>Adding animation to an element</h3>\n<p>To give an HTML element animation, the first two steps are to declare a name for the animation and a duration. This is done with the <code class=\"language-text\">animation-name</code> and <code class=\"language-text\">animation-duration</code> properties:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><code class=\"language-text\">animation-duration</code> can accept any value in seconds or milliseconds (declared using <code class=\"language-text\">s</code> or <code class=\"language-text\">ms</code> after an integer).</p>\n<h3>Creating the animation</h3>\n<p>Once you have declared a name and duration, it’s time to build the animation. This is done using the <code class=\"language-text\">@keyframes</code> rule, followed by the animation name:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Inside of the <code class=\"language-text\">@keyframes</code> rule will be a rule for each “frame” of the animation, designated by a percentage value from <code class=\"language-text\">0%</code> to <code class=\"language-text\">100%</code>. <code class=\"language-text\">0%</code> is the very beginning of the animation, <code class=\"language-text\">100%</code> being the end, with any percentage values possible in between. This can be thought of much like a video or flipbook, where each page of the book is a unique frame that when combined, creates motion:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>In the example above, the <code class=\"language-text\">color-change</code> animation will change the <code class=\"language-text\">background-color</code> of the <code class=\"language-text\">#myAnimation</code> element from <code class=\"language-text\">black</code> at <code class=\"language-text\">0%</code>, to <code class=\"language-text\">gray</code> at <code class=\"language-text\">50%</code> then finally to <code class=\"language-text\">white</code> at <code class=\"language-text\">100%</code>.</p>\n<p>The power of using custom animations, though, is that you can change absolutely any CSS properties, with any level of incremental change in frames. A good example of this is for <code class=\"language-text\">:hover</code> pseudo-classes. CSS <code class=\"language-text\">:hover</code> states are often used to apply a color or minor stylistic change when an element is hovered over with a mouse, but animations allow these changes to be much more detailed.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>In the example above the <code class=\"language-text\">button-anim</code> animation effects any <code class=\"language-text\">button</code> element when it’s hovered over. Its <code class=\"language-text\">background-color</code> changes in four equal steps over a duration of 5 seconds, with the size of the element itself changing in discreet, unique steps as well (original, to 2.1x, to 2.5x, to then 1.5x the original).</p>\n<p>One additional property included in the example above is the <code class=\"language-text\">animation-fill-mode</code> property. This property can be used to indicate how styles should be applied before (and after) the duration of the animation has completed. Using <code class=\"language-text\">animation-fill-mode: forwards</code> indicates that the styles in the last frame of the animation (those in the <code class=\"language-text\">100%</code> rule) will remain applied. Without the addition of the <code class=\"language-text\">animation-fill-mode</code> property, the styles of <code class=\"language-text\">button</code> would revert back to their original state after the animation had completed.</p>\n<h3>Conclusion</h3>\n<p>CSS animations can be very complex and detailed, with up to 100 distinct frames able to be specified. Considering this feature is available natively in vanilla CSS, they are a great way to add visual interest and complexity to a web project, well-supported in all modern browsers.</p>\n<h2>Using Color Gradients in CSS3</h2>\n<p>Since the introduction of CSS3, it has been possible to use color gradients as a background, with 2 or more colors gradually fading into each other. Previously, creating gradients had to be done using Photoshop or other image editing software. Used effectively, this is a great way to add interest and even texture to webpage designs, beyond just static background colors. While legacy versions of Internet Explorer do not support this feature, you can safely add them to a project, as all modern browsers do support it. This post will take a look at using gradient backgrounds, and the available customization options.</p>\n<h3>Basic Linear Gradients</h3>\n<p>To set the background of an element (whether it be the <code class=\"language-text\">body</code>, a <code class=\"language-text\">div</code>, or other element), the <code class=\"language-text\">background</code> property is used, typically with a color value:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To use a linear gradient instead of a solid color, include at least two colors (using either hex, rgb, hsl, or named colors values), separated by commas, inside of the <code class=\"language-text\">linear-gradient()</code> value:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Vendor prefixes</h3>\n<p>Since different browsers handle the <code class=\"language-text\">linear-gradient</code> value differently, it is highly recommended to use vendor prefixes along with it. This will ensure that the value is understood by Safari, Firefox, Chrome, and Opera. To use vendor prefixes, simply add 2 additional <code class=\"language-text\">background</code> rules with the <code class=\"language-text\">linear-gradient</code> value prefixed with <code class=\"language-text\">-webkit-</code> and <code class=\"language-text\">-moz-</code>. They should also appear before the regular rule without any vendor prefix:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>It’s a bit extra typing, but it ensures that your gradients will be supported across all major browsers.</p>\n<h3>Controlling direction</h3>\n<p>By default, gradients will transition from top to bottom, with the first color included in the <code class=\"language-text\">linear-gradient</code> value being the top color.</p>\n<p>You can change the direction of the gradient, though, by adding some direction keywords before the colors (i.e. <code class=\"language-text\">to top</code>, <code class=\"language-text\">to bottom</code>, <code class=\"language-text\">to right</code>, <code class=\"language-text\">to left</code>, <code class=\"language-text\">to right top</code>, etc.)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>When setting the direction to a corner, either the x- or y- axis can be stated first (i.e. <code class=\"language-text\">to right bottom</code> and <code class=\"language-text\">to bottom right</code> are the same).</p>\n<h3>Multiple colors</h3>\n<p>You can utilize more than two colors in a gradient, simply by comma separating them:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Color Stops</h3>\n<p>Sometimes you will want to control where a certain color begins, allowing for certain colors to take up more space or have a wider space to transition. To add these “color stops”, just add a percentage value after a given color, to designate where that color should begin:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>This is great for having finer control over your transitions, and can be used for interesting effects.</p>\n<h3>Radial Gradients</h3>\n<p>One available variation on linear gradients are radial gradients. Radial gradients will transition from the center of the element, transitioning outward like a circle. They use almost the exact same syntax as linear gradients, just with the <code class=\"language-text\">radial-gradient</code> value instead:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h2>An Overview of CSS Positioning</h2>\n<p>One of the most important properties in CSS to understand is the <code class=\"language-text\">position</code> property. While much can be done to layout elements on a page without explicitly changing values for the <code class=\"language-text\">position</code> property, most <a href=\"https://sunlightmedia.org/web-design-trends-2020/\">advanced layout issues</a> will require knowing the different values available for this property. This blog post will take a look at the four main values for <code class=\"language-text\">position</code>, and the instances in which you might use each of them.</p>\n<h3>Position Static</h3>\n<p><code class=\"language-text\">static</code> is the default value of <code class=\"language-text\">position</code>, meaning that for any element you don’t explictly set any value for <code class=\"language-text\">position</code>, it will be <code class=\"language-text\">static</code> by default. Elements with a <code class=\"language-text\">position</code> of <code class=\"language-text\">static</code> will not accept any box offset properties, such as <code class=\"language-text\">margin</code> or <code class=\"language-text\">padding</code> .</p>\n<p>In the example below, each <code class=\"language-text\">div</code> will be stacked on top of each other, since each is a block-level element:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Position Relative</h3>\n<p>Elements with a <code class=\"language-text\">position</code> of <code class=\"language-text\">relative</code> are very similar to the value of <code class=\"language-text\">static</code>, although with one major difference: they can accept box offset properties of <code class=\"language-text\">top</code>, <code class=\"language-text\">right</code>, <code class=\"language-text\">bottom</code>, and <code class=\"language-text\">left</code>.</p>\n<p>In the case of an element with a <code class=\"language-text\">position</code> of <code class=\"language-text\">relative</code>, these offset properties set the distance from the elements normal position. In other words, if you were to set an element with a <code class=\"language-text\">position</code> of <code class=\"language-text\">relative</code> to have a <code class=\"language-text\">top</code> value of <code class=\"language-text\">10px</code>, the element would appear <code class=\"language-text\">10px</code> lower than where it would normally appear if its <code class=\"language-text\">position</code> were <code class=\"language-text\">static</code>.</p>\n<p>Elements with a <code class=\"language-text\">position</code> of <code class=\"language-text\">relative</code> stay within the normal “flow” of elements, the box offset properties simply shifting the elements from its normal flow:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Position Absolute</h3>\n<p>Elements with a <code class=\"language-text\">position</code> of <code class=\"language-text\">absolute</code> also accept box offset properties, although they are removed from the normal flow of elements. Using box offset properties on an <code class=\"language-text\">absolute</code> positioned element will position that element in direct relation to its parent element.</p>\n<p>Taking the exact same CSS as the <code class=\"language-text\">position: relative;</code> example above, but simply changing the <code class=\"language-text\">position</code> to <code class=\"language-text\">absolute</code> will result in entirely different positioning of the individual elements:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Position Fixed</h3>\n<p>An element with a <code class=\"language-text\">position</code> of <code class=\"language-text\">fixed</code> is very similar to <code class=\"language-text\">position: relative;</code>, although the position is relative to the browser viewport, rather than any parent element. Additionally, the element will not scroll with the page, remaining “fixed” and always visible, regardless of where the user is at on the page. This is often used to “fix” headers and footers to the page, in order to always remain visible.</p>\n<h2>An overview of CSS Selectors</h2>\n<p>In web development there are often numerous ways to achieve the same result. A key to writing good code (regardless of the language), is using the most efficient method possible, writing as little code as necessary and keeping the codebase to the absolute minimum. This will result in both faster page load times, as well as clarity in the source code for yourself and other developers. In writing CSS, it is important to know how to select the elements you want to target, and the best method to do so. This section will take a look at some of the most common CSS selectors, and the best instances in which to use each of them.</p>\n<h3>Type Selectors</h3>\n<p>For every HTML element, there is a corresponding selector for that element type. Whether it be a <code class=\"language-text\">div</code>, <code class=\"language-text\">p</code>, <code class=\"language-text\">img</code> or any other HTML element, the corresponding CSS selector is exactly the same, minus the angle brackets used in the tag:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Type selectors are ideal when you want to target <em>every</em> instance of a given element type and apply the same styles for all of them.</p>\n<h3>Class Selectors</h3>\n<p>Class selectors utilize a class name associated with specific elements. This selector is ideal when you want to apply certain styles to a variety of a different elements, regardless of the element type. For example, you may have a class of <code class=\"language-text\">.responsive</code> applied to a <code class=\"language-text\">p</code>, <code class=\"language-text\">div</code> and <code class=\"language-text\">img</code> element:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The following CSS code block will target all of these elements with the same class:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Class selectors are always designated in a stylesheet using a period (<code class=\"language-text\">.</code>) before the class name.</p>\n<h3>ID Selectors</h3>\n<p>ID selectors are similar to class selectors, although they can only be applied to a single element in a given HTML document. This is useful when you <em>only</em> want to target a single element:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>ID selectors are always designated in a stylesheet using the pound or hash sign (<code class=\"language-text\">#</code>) before the ID name.</p>\n<h3>Universal Selector</h3>\n<p>The universal selector will target every single element in an HTML document. This is often used for CSS resets, such as removing default margin, padding and other styles from all elements:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The universal selector is designated using the asterisk (<code class=\"language-text\">*</code>).</p>\n<h2><code class=\"language-text\">:hover</code></h2>\n<p>Another common selector (and one of the many CSS “pseudo-classes”) is <code class=\"language-text\">:hover</code>. Adding this pseudo-class to any selector will target the element’s hover state. This means that these styles will <em>only</em> be applied when a user hovers over that element with their mouse:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><code class=\"language-text\">:hover</code> is often used for links or any element you want to highlight when the user is hovering over it. This pseudo-class works well for laptop and desktop users, although has no real use for mobile devices, due to the lack of a mouse cursor.</p>\n<h2>Understanding specificity in CSS</h2>\n<p>In the process of writing CSS code, you will invariably run into situations where the code you just wrote seems to have absolutely no effect at all on the page. This can be frustrating, confusing and difficult to troubleshoot without the aid of something like <a href=\"https://developer.chrome.com/devtools\">Chrome Developer Tools</a>. However, having a better understanding of how specificity and the cascade in CSS works can go a long way in mitigating these issues altogether. This section will aim to point out some of the main issues that typically come up when trying to determine which piece of code is blocking what you’re trying to do.</p>\n<p>It is well known that CSS (which stands for Cascading Style Sheets) works from the top down. This means that, generally speaking, code that is further down in the document takes precedence over other code higher up. A simple example of this is having two declarations targeting the same element:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The color of paragraph elements in this example will always be green, since it appears after the declaration assigning the color of blue to paragraphs.</p>\n<p>The problem is that selectors beyond just element selectors have varying levels of specificity, and combining selectors will increase their specificity, overriding other rules.</p>\n<h3>Elements and pseudo-elements</h3>\n<p>Elements and pseudo-elements have the lowest level of specificity. Since they target <em>all</em> instances of a given element, using element selectors should only be used when you really want those styles to be applied to <em>all</em> instances of paragraphs, divs, headers, etc. For example, the following code will apply a 1px solid black border to all paragraph elements in the document.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Classes, attributes and pseudo-classes</h3>\n<p>Classes, attributes and pseudo-classes have a higher level of specificity, and will only apply to elements associated with them. They are reusable, in the sense that you can have classes applied to multiple different elements, whenever you want them to share the same styles. These styles will also override styles that conflict with those at the element level. In the example below, all paragraph elements will be green, except for any with the class of <code class=\"language-text\">alert</code>, which will be red:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>IDs</h3>\n<p>IDs have one of the highest levels of specificity, and will override almost anything. Unlike classes which can be reused as many times as you want, IDs are only supposed to be applied to a <em>single</em> element on the page.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Even though there are two further declarations for paragraphs underneath the <code class=\"language-text\">p#myParagraph</code> declaration, the ID of <code class=\"language-text\">#myParagraph</code> will always be black.</p>\n<h3>Inline styles</h3>\n<p>Inline styles have an even higher level of specificity than IDs. While it is generally very frowned upon to apply any styles inline, as it makes it difficult to find and manage the styles applied to elements, there are situations where it can be justified.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The above inline style will always be red, regardless of what styles are applied elsewhere.*</p>\n<h2><code class=\"language-text\">!important</code></h2>\n<p>The one caveat to the above, even including inline styles, is the use of <code class=\"language-text\">!important</code>. Whenever <code class=\"language-text\">!important</code> is added to a CSS rule, this rule will take precedence over all else, always, no matter what:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><code class=\"language-text\">!important</code> can be a lifesaver when you cannot figure out what is blocking your CSS, but it can also be easily abused and just make your code more of a mess. As a general rule, use <code class=\"language-text\">!important</code> only when all else fails.</p>\n<p>An extremely handy tool for better understanding and checking specificity is <a href=\"https://specificity.keegan.st/\">Keegan Street’s Specificity Calculator</a>. Whenever in doubt, it can very useful to check your selectors here.</p>\n<h2>Using WOW.js and Animate.css for Scroll-Triggered Animations</h2>\n<p>Animations are a great way to add visual excitement and motion to your websites, and the popular <a href=\"https://daneden.github.io/animate.css/\">animate.css</a> library has provided an easy way to add CSS-based animations to any website. What if you want to only trigger these animations once the user has scrolled to a specific section of your website, though?</p>\n<p>This can of course be accomplished via jQuery, but using the JavaScript library for that function alone adds unnecessary bulk for a function that can otherwise be accomplished by a simple script. WOW.js solves this problem, offering an easy-to-use library for adding animations triggering by scrolling, with no jQuery required, in only 3kB.</p>\n<p><a href=\"https://twitter.com/share?text=This+post+will+provide+a+guide+on+using+WOW.js+and+animate.css+for+your+web+projects%2C+including+various+options+available+for+installing+it.&#x26;url=https://sunlightmedia.org/css-tricks/\">This post will provide a guide on using WOW.js and animate.css for your web projects, including various options available for installing it.Click To Tweet</a></p>\n<p>If you are interested in learning about different animations besides scroll effects, head to the last section of this blog post for a list of other CSS and Javascript animation libraries.</p>\n<h3>About animate.css</h3>\n<p>Using CSS animations is a straightforward and easy method to add eye-catching visual effects to any HTML website. One of the most popular libraries for CSS animations is animate.css. While the library may be small, it is a perfect tool for novice web developers who are looking to add more spunk to their website without the complex use of keyframing. While this blog post will mainly be discussing how to use WOW.js, the animate.css file is extremely versatile and can be used with other files as well.</p>\n<p>Some of the many animations that you can add to elements on your site include:</p>\n<ul>\n<li><strong>Static animations</strong>: These types of animations appear right when you load and open up a webpage. In other words, no scrolling (WOW.js) involved!</li>\n<li><strong>Scroll animations</strong>: These types of animations appear when the user scrolls into the element’s view on a webpage. This is the type of animation we will be focusing on with WOW.js. This animation can also be created with jQuery.</li>\n<li><strong>Click animations</strong>: With a combination of jQuery and Javascript programming, you can create animations on your website that run when the user clicks on a certain element.</li>\n<li><strong>“Special” animations</strong>: These quirkier animations can be used on elements when you really want to capture the user’s attention instantly with an eye-catching animation.</li>\n</ul>\n<h3>About WOW.js</h3>\n<p>WOW.js is a Javascript file that, when added to your HTML document, can create compelling and dynamic effects on a site. This scroll effect is one of the most popular options for web designers, as it used to be licensed as open-source code under MIT. When you are on a website that implements WOW.js, the animated elements will magically appear as you scroll down the site. For an example of this effect, visit the official website for <a href=\"https://wowjs.uk/\">WOW.js</a>. It is a great design tool to utilize with animate.css.</p>\n<p>Compared to other animation options with Javascript, WOW.js is extremely popular for its simple, bulk-free code. Note that you can use other CSS animation libraries to activate WOW.js; WOW.js just treats animate.css as its default library. This includes libraries such as CSShake or DynCSS. WOW.js is free to use for open source project, although requires purchase of a license for any commercial projects.</p>\n<h3>Adding animate.css and WOW.js to your project</h3>\n<p>In order to start animating your website, the first step is to add animate.css and WOW.js to your HTML document. There are a few ways you can go about adding the files into your HTML project. You can download the distribution for animate.css and WOW.js from each of their respective official sites, or simply link to the files available from <a href=\"https://cdnjs.com/\">CDN</a>. CDN hosts a vast collection of libraries for Javascript and CSS.</p>\n<p>A major benefit of using animate.css for your website is that the CSS code is held in just one file, which simplifies your project <em>immensely</em>. Once you add the CSS file to your project, all you must do is link it to your HTML in the head of the document. Alternatively, you can simply link the CDN file to your HTML document. Depending on whether you directly add the animate.css file or simply link to the CDN file, only the href will slightly vary:</p>\n<head>\n<link rel=“stylesheet” type=“text/css” href=“animate.css”>\n<link rel=“stylesheet” type=“text/css” href=“[https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.css”](https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.css%E2%80%9D)>\n</head>\n<h3>Install animate.css and WOW.js</h3>\n<p>Click the links below to view the animate.css and WOW.js files on CDN:</p>\n<ul>\n<li>animate.css Non-minified Version: <a href=\"https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.css\"></a><a href=\"https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.css\">https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.css</a></li>\n<li>animate.css Minified Version: <a href=\"https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css\"></a><a href=\"https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css\">https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css</a></li>\n<li>WOW.js Non-Minified Version: <a href=\"https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.js\"></a><a href=\"https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.js\">https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.js</a></li>\n<li>WOW.js Minified Version: <a href=\"https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js\"></a><a href=\"https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js\">https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.min.js</a></li>\n</ul>\n<p>(Note: “Minified” code refers to the removal of white space and shorter characters in order to preserve functionality but create more compact file sizes. This will make the code more difficult to read and edit for those who want to customize or make changes to the code.)</p>\n<h3>Using npm to install animate.css and WOW.js</h3>\n<p>Alternatively, you can use a package manager such as npm (Javascript package manager) to install both animate.css and WOW.js just by merely typing a few keywords into the command line. From the root of your project directory, run the following command from the command line:</p>\n<p><strong>npm install wowjs</strong></p>\n<p>One benefit of installing WOW.js via npm is that it automatically also installs animate.css as a dependency. This way, you do not need to concern yourself over following the instructions of downloading animate.css with one of the options discussed above. Similar to adding the file directly or using CDN, animate.css will be linked in theof your document (the href path will differ depending on the file location):</p>\n<link rel=“stylesheet” href=“node_modules/animate.css/animate.css”>\n<p>For the script, you can add WOW.js to your website by linking it at the bottom of your HTML document, just below the closing tag. This must be followed by a <script> tag to activate WOW.js, as demonstrated below:</p>\n<script src=“node_modules/wowjs/dist/wow.min.js”></script>\n<script>\n\nnew WOW().init();\n\n</script>\n<h3>Adding animations to elements</h3>\n<p>Once both files are added to the project, it’s time to select the HTML elements that you’d like to animate upon scrolling. Any element with a class of .wow will remain hidden until the user reaches it on the page. You can apply this class to headings, text, images, or even a larger portion of your website enclosed in a <div> tag.</p>\n<p>Add a class of .wow to any HTML element you’d like to animate with WOW.js, such as an h1 element:</p>\n<h1 class=“wow”>Welcome to my site!</h1>\n<p>Animate.css has 75 different animation styles to choose from, all of which can be demoed on the official site (see above). Once you’ve selected an animation you’d like to use, add its name as a CSS class on the element to animate, along with the class “wow.” Here are a few examples of animate.css and WOW.js in action on your HTML document:</p>\n<h1 class=“wow fadeInRight”>Welcome to my site!</h1>\n<p>The h1 element will now fade in right once the user has scrolled to it on the page.</p>\n<div class=“wow pulse”>Click here</div>\n<p>The content enclosed in the <div> tag will now create a pulsing effect on the site once the user has scrolled to it on the page.</p>\n<h3>Alterations to WOW.js Animations</h3>\n<p>There are slight adjustments that can be made to the CSS animations through some in-line editing on your HTML document. You can add these four properties after <strong>class = “wow”</strong> and even combine them within any HTML tag. Essentially, these simply properties are a great and effortless way for users to add versatility to the scroll animations. Below are descriptions of the four properties you can alter when animating an HTML element with WOW.js:</p>\n<ul>\n<li><strong>data-wow-delay=“_s”</strong>: Typically, the element automatically appears when the user scrolls to its location. With this property, you can delay the animation for _ seconds.</li>\n<li><strong>data-wow-duration=“_s”</strong>: You can make the animation last _ seconds, which is useful for speeding up or slowing down the element’s appearance.</li>\n<li><strong>data-wow-iteration=“_”</strong>: With this property, you can make the animation repeat, or iterate, _ times before it turns static on your page.</li>\n<li><strong>data-wow-offset=“_”</strong>: This property allows the animation to start _ pixels from the browser edge before animating.</li>\n</ul>\n<h3>Alternative Animation Libraries to animate.css and WOW.js</h3>\n<h2><a href=\"http://bouncejs.com/\">Bounce.js</a></h2>\n<p>Bounce.js is an easy-to-use tool to create stunning CSS3 and Javascript animations for your website in just minutes. Developers can experiment with a list of various animations on the Bounce.js web tool to generate static keyframes and even customize the animations directly in the web browser. When the animation satisfies your standards, you can export the CSS code directly from the site and paste it into your project. Then, you can use the animations that you created in the web browser and directly apply it to elements on your HTML document. The web tool even generates a unique, shortened URL that allows you to access your animation on a new web browser in case you want to make edits to it at any time.</p>\n<p>To learn more about creating animations with Javascript and installing the Bounce.js library into your project, you can follow the instructions for installing the Bounce.js library on its <a href=\"https://github.com/tictail/bounce.js\">Github site</a>.</p>\n<h2><a href=\"http://animejs.com/\">Anime.js</a></h2>\n<p>Another popular animation library is Anime.js, which utilizes CSS properties, Javascript objects, SVG, and DOM attributes to create impressive animations. Julian Garnier’s collection features dozens of seamless animations that you can directly add to your own site. You can view the various animations created with Anime.js on the Anime.js Codepen collection. Unlike WOW.js, this animation library is not necessarily used to animate HTML elements on a site. Rather, Anime.js is used to create separate animated “illustrations” for your website altogether to add to its visual appeal. Some of my favorites include Garnier’s <a href=\"https://codepen.io/juliangarnier/pen/ZeEpgd\">line drawing animation</a> and the <a href=\"https://codepen.io/juliangarnier/pen/LMrddV\">layered animations demonstration</a>. To add the Anime.js library to your project, you can install via npm.</p>\n<p>View the directions and documentation for using Anime.js on the <a href=\"https://github.com/juliangarnier/anime\">Github site</a>.</p>\n<h2><a href=\"http://ianlunn.github.io/Hover/\">Hover.css</a></h2>\n<p>Hover.css produces eye-catching effects on your website by simply hovering your mouse over animated elements. You can use this animation library to add more spunk to ordinary, 2D elements such as buttons, logos, or images. On the Hover.css website, you can browse and test the various animations such as background, 2D, shadow, and outline transitions by hovering your mouse over each button. Those who plan on using one or few Hover.css animations can simply download the file and copy/paste the specific animation into their own stylesheets. However, if you plan on using many Hover.css animations, then you can essentially follow the same procedure of installing and linking the Hover.css stylesheet to your HTML document. You will have access to all Hover.css effect to animate any appropriate HTML element on your site.</p>\n<p>To view the specific instructions and documentations for installing and using Hover.css, go to the official <a href=\"https://github.com/IanLunn/Hover/blob/master/README.md#hovercss\">Github site</a>.</p>\n<h2><a href=\"https://mattboldt.com/demos/typed-js/\">Typed.js</a></h2>\n<p>To create the iconic typewriter or typing effect, a popular option for web developers is to use Typed.js. Many websites use this animation library to create string-typing effects on pages, including the popular group workspace platform, Slack. Simply install the Hover.css library via npm or link the CDN file to your HTML document. With essentially one <script> tag, you can animate an HTML text tag with the typewriter effect. With enough tweaking, you can create more advanced typing effects on your website for an even more stunning effect. For instance, you can create the effect of the computer pausing as it types or the effect of deleting letters in a word.</p>\n<p>The official <a href=\"https://github.com/mattboldt/typed.js/\">Github site</a> includes all of the source code and detailed documentation on how you can customize the typing animation to meet your personal preferences.</p>\n<h2><a href=\"https://elrumordelaluz.github.io/csshake/\">CSShake</a></h2>\n<p>As the title implies, this CSS library is a collection of animations that all “shake” HTML elements on your website. This quirky animation is perfect if you want to draw attention to a certain image or section of your website. It also makes the elements of your website more interactive, which is always a plus for front-end development. You can experiment with the variation of shake animations yourself on the CSShake website by hovering over different elements on the page. The source code on CSShake Github also includes detailed documentation that describes how to create your own custom shake animations. You will have to understand and learn to adjust the jQuery properties by reading the documentation.</p>\n<p>When you are ready to install CSShake onto your own project, follow the instructions for installation on the <a href=\"https://github.com/elrumordelaluz/csshake\">Github site</a>.</p>\n<h2>Introduction to CSS flexbox &#x26; Advanced CSS Selectors</h2>\n<p>CSS <code class=\"language-text\">Flexbox</code> (or Flexible Box Layout) was a late addition to the CSS3 specification, aiming to address many of the layout issues of a webpage, especially when working with multiple device sizes and responsive web design. While the more recent CSS <code class=\"language-text\">grid</code> properties are capable of creating complex grid-based layouts, <code class=\"language-text\">flexbox</code> is often a better choice for laying out small groups of components within a larger layout, generally with far less code than when using <code class=\"language-text\">grid</code>. This post will give a short introduction to using the flexbox properties for common layout issues.</p>\n<h3><code class=\"language-text\">display: flex</code></h3>\n<p>The first step to creating a flexbox is applying a <code class=\"language-text\">display: flex</code> property to a parent element that will act as a container for all flex items within it.</p>\n<p>While most layouts will require the use of additional properties. A simple 2-column layout can be created using this property alone.</p>\n<p>For example, we can take a container with 2 <code class=\"language-text\">div</code> elements stacked on top of each other, and transform it into a 2-column layout with the addition of the <code class=\"language-text\">display: flex</code> property:</p>\n<p><strong>Original Code</strong>:</p>\n<p><strong>HTML</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><strong>CSS</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><strong>CSS with flexbox</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3><code class=\"language-text\">flex-direction</code></h3>\n<p>We can add additional control over the flow of elements in our flex container via the <code class=\"language-text\">flex-direction</code> property. By default all elements within a flex container will flow in a <code class=\"language-text\">row</code> from left to right, although we can also set this property to have values of <code class=\"language-text\">column</code>, <code class=\"language-text\">row-reverse</code> or <code class=\"language-text\">column-reverse</code>.</p>\n<h3>Adjusting spacing and alignment with <code class=\"language-text\">justify-content</code></h3>\n<p>Oftentimes there will be more space in a container than what the elements within it take up, so it is likely that you’ll want to justify the spacing of the elements in a certain way. By default, all elements within a flex container will align to the very beginning of the container (referred to as <code class=\"language-text\">flex-start</code>) but there are a variety of other options. Note that the actual position will vary depending on the the setting of <code class=\"language-text\">flex-direction</code>: if the direction is set as <code class=\"language-text\">row</code> then <code class=\"language-text\">flex-start</code> will indicate all the way to the left of the container, while a direction of <code class=\"language-text\">column</code> would indicate the very top of the container for <code class=\"language-text\">flex-start</code>.</p>\n<p>Returning to our original code example, we’ll increase the <code class=\"language-text\">width</code> of our container a bit to better show the different <code class=\"language-text\">justify-content</code> settings.</p>\n<p><code class=\"language-text\">justify-content: center</code> will place all of the elements directly in the center of the column:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><code class=\"language-text\">justify-content: flex-end</code> is the opposite of <code class=\"language-text\">justify-content: flex-start</code>, placing the elements at the very end of the container:</p>\n<p><code class=\"language-text\">justify-content: space-between</code> will place all elements on each end of the container, leaving whatever space remains at the center of the container, as well as around any additional elements inside (in instances of a container with 3 or more elements):</p>\n<p><code class=\"language-text\">justify-content: space-around</code> is just like <code class=\"language-text\">spae-between</code>, although there is additional space on the very ends of the container:</p>\n<p>There are numerous other more advanced selectors though, for the purpose of targeting elements with a greater level of specificity. Being familiar with the right selector for the job is one of the most important aspects of learning CSS. This post will highlight some of the most useful advanced selectors for targeting elements.</p>\n<h3>Child Selectors</h3>\n<p>Child selectors are used to target elements nested in one another. There are two different kinds of Child selectors, descendant and direct child selectors.</p>\n<h3>Descendant Selectors</h3>\n<p>Descendant selectors are used to to target a given element (or group of elements), regardless of where they are nested in their parent element. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>would target both instances of the <code class=\"language-text\">p</code> element in the following HTML:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Direct Child Selectors</h3>\n<p>If you only want to target elements that are in the next level down from the parent element, the Direct Child selector is the one to use.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>would only select the first <code class=\"language-text\">p</code> element in the following HTML:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Sibling Selectors</h3>\n<h3>General Sibling Selectors</h3>\n<p>General Sibling selectors will select any element on the same nested level that appears after the first sibling. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>will target the 2 noted <code class=\"language-text\">div</code> elements that appear after the <code class=\"language-text\">h1</code>, but not the one before it, or any that might be nested on further levels:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Adjacent Sibling Selectors</h3>\n<p>The Adjacent Sibling selector is used to target elements that appear <em>directly</em> after a given element. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>will only target the <code class=\"language-text\">p</code> element right after the <code class=\"language-text\">h1</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3>Pseudo-classes</h3>\n<p>In the previous CSS selectors post, we touched on pseudo-classes via the <code class=\"language-text\">:hover</code> selector. There are many other pseudo-classes, however, such as <code class=\"language-text\">:link</code>, <code class=\"language-text\">:visited</code>, <code class=\"language-text\">:active</code> and more.</p>\n<p>To style an <code class=\"language-text\">a</code> link that hasn’t been visited yet, use the <code class=\"language-text\">:link</code> selector:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To stlye an <code class=\"language-text\">a</code> link that has been visited, use the <code class=\"language-text\">:visited</code> selector:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The <code class=\"language-text\">:active</code> selector can be used for whenever a user engages with an element, such as clicking on it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><code class=\"language-text\">:focus</code> is used whenever an element has “focus”, such as a form element when the user has entered it via a mouse or keyboard click:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h2>Conclusion</h2>\n<p>Do you find something useful CSS tricks in this post? Please share your comments below.</p>\n<p><strong>Author Bio</strong></p>\n<p>Angelo has been involved in the creative IT world for over 20 years. He built his first website back in 1998 using Dreamweaver, Flash and Photoshop. He expanded his knowledge and expertise by learning a wider range of programming skills, such as HTML/CSS, Flash ActionScript and XML.</p>\n<p>Angelo completed formal training with the CIW (Certified Internet Webmasters) program in Sydney Australia, learning the core fundamentals of computer networking and how it relates to the infrastructure of the world wide web.</p>\n<p>Apart from running Sunlight Media, Angelo enjoys writing informative content related to web &#x26; app development, digital marketing and other tech related topics.</p>\n<!--EndFragment-->"},{"url":"/docs/react/react-dev-tools-profiler/","relativePath":"docs/react/react-dev-tools-profiler/index.md","relativeDir":"docs/react/react-dev-tools-profiler","base":"index.md","name":"index","frontmatter":{"title":"React Dev Tools Profiler","template":"docs","excerpt":"DevTools will show a “Profiler” tab for applications that support the new profiling API:"},"html":"<!--StartFragment-->\n<h2>Profiling an application</h2>\n<p>DevTools will show a “Profiler” tab for applications that support the new profiling API:</p>\n<p><a href=\"https://reactjs.org/static/4da6b55fc3c98de04c261cd902c14dc3/ad997/devtools-profiler-tab.png\"><img src=\"https://reactjs.org/static/4da6b55fc3c98de04c261cd902c14dc3/1e088/devtools-profiler-tab.png\" alt=\"New DevTools \"></a></p>\n<blockquote>\n<p>Note:</p>\n<p><code class=\"language-text\">react-dom</code> 16.5+ supports profiling in DEV mode. A production profiling bundle is also available as <code class=\"language-text\">react-dom/profiling</code>. Read more about how to use this bundle at <a href=\"https://fb.me/react-profiling\">fb.me/react-profiling</a></p>\n</blockquote>\n<p>The “Profiler” panel will be empty initially. Click the record button to start profiling:</p>\n<p><a href=\"https://reactjs.org/static/bae8d10e17f06eeb8c512c91c0153cff/ad997/start-profiling.png\"><img src=\"https://reactjs.org/static/bae8d10e17f06eeb8c512c91c0153cff/1e088/start-profiling.png\" alt=\"Click \"></a></p>\n<p>Once you’ve started recording, DevTools will automatically collect performance information each time your application renders. Use your app as you normally would. When you are finished profiling, click the “Stop” button.</p>\n<p><a href=\"https://reactjs.org/static/45619de03bed468869f7a0878f220586/ad997/stop-profiling.png\"><img src=\"https://reactjs.org/static/45619de03bed468869f7a0878f220586/1e088/stop-profiling.png\" alt=\"Click \"></a></p>\n<p>Assuming your application rendered at least once while profiling, DevTools will show several ways to view the performance data. We’ll <a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#reading-performance-data\">take a look at each of these below</a>.</p>\n<h2><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#reading-performance-data\"></a>Reading performance data</h2>\n<h3><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#browsing-commits\"></a>Browsing commits</h3>\n<p>Conceptually, React does work in two phases:</p>\n<ul>\n<li>The <strong>render</strong> phase determines what changes need to be made to e.g. the DOM. During this phase, React calls <code class=\"language-text\">render</code> and then compares the result to the previous render.</li>\n<li>The <strong>commit</strong> phase is when React applies any changes. (In the case of React DOM, this is when React inserts, updates, and removes DOM nodes.) React also calls lifecycles like <code class=\"language-text\">componentDidMount</code> and <code class=\"language-text\">componentDidUpdate</code> during this phase.</li>\n</ul>\n<p>The DevTools profiler groups performance info by commit. Commits are displayed in a bar chart near the top of the profiler:</p>\n<p><a href=\"https://reactjs.org/static/bd72dec045515d59be51c944e902d263/d8f62/commit-selector.png\"><img src=\"https://reactjs.org/static/bd72dec045515d59be51c944e902d263/d8f62/commit-selector.png\" alt=\"Bar chart of profiled commits\"></a></p>\n<p>Each bar in the chart represents a single commit with the currently selected commit colored black. You can click on a bar (or the left/right arrow buttons) to select a different commit.</p>\n<p>The color and height of each bar corresponds to how long that commit took to render. (Taller, yellow bars took longer than shorter, blue bars.)</p>\n<h3><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#filtering-commits\"></a>Filtering commits</h3>\n<p>The longer you profile, the more times your application will render. In some cases you may end up with <em>too many commits</em> to easily process. The profiler offers a filtering mechanism to help with this. Use it to specify a threshold and the profiler will hide all commits that were <em>faster</em> than that value.</p>\n<p><img src=\"https://reactjs.org/683b9d860ef722e1505e5e629df7ef7e/filtering-commits.gif\" alt=\"Filtering commits by time\"></p>\n<h3><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#flame-chart\"></a>Flame chart</h3>\n<p>The flame chart view represents the state of your application for a particular commit. Each bar in the chart represents a React component (e.g. <code class=\"language-text\">App</code>, <code class=\"language-text\">Nav</code>). The size and color of the bar represents how long it took to render the component and its children. (The width of a bar represents how much time was spent <em>when the component last rendered</em> and the color represents how much time was spent <em>as part of the current commit</em>.)</p>\n<p><a href=\"https://reactjs.org/static/3046f500b9bfc052bde8b7b3b3cfc243/ad997/flame-chart.png\"><img src=\"https://reactjs.org/static/3046f500b9bfc052bde8b7b3b3cfc243/1e088/flame-chart.png\" alt=\"Example flame chart\"></a></p>\n<blockquote>\n<p>Note:</p>\n<p>The width of a bar indicates how long it took to render the component (and its children) when they last rendered. If the component did not re-render as part of this commit, the time represents a previous render. The wider a component is, the longer it took to render.</p>\n<p>The color of a bar indicates how long the component (and its children) took to render in the selected commit. Yellow components took more time, blue components took less time, and gray components did not render at all during this commit.</p>\n</blockquote>\n<p>For example, the commit shown above took a total of 18.4ms to render. The <code class=\"language-text\">Router</code> component was the “most expensive” to render (taking 18.4ms). Most of this time was due to two of its children, <code class=\"language-text\">Nav</code> (8.4ms) and <code class=\"language-text\">Route</code> (7.9ms). The rest of the time was divided between its remaining children or spent in the component’s own render method.</p>\n<p>You can zoom in or out on a flame chart by clicking on components: <img src=\"https://reactjs.org/39ba82394205242af7c37ccb3a631f4d/zoom-in-and-out.gif\" alt=\"Click on a component to zoom in or out\"></p>\n<p>Clicking on a component will also select it and show information in the right side panel which includes its <code class=\"language-text\">props</code> and <code class=\"language-text\">state</code> at the time of this commit. You can drill into these to learn more about what the component actually rendered during the commit:</p>\n<p><img src=\"https://reactjs.org/1f4d023f1a0f281386625f28df87c78f/props-and-state.gif\" alt=\"Viewing a component&#x27;s props and state for a commit\"></p>\n<p>In some cases, selecting a component and stepping between commits may also provide a hint as to <em>why</em> the component rendered:</p>\n<p><img src=\"https://reactjs.org/cc2a8b37bbce52c49a11c2f8e55dccbc/see-which-props-changed.gif\" alt=\"Seeing which values changed between commits\"></p>\n<p>The above image shows that <code class=\"language-text\">state.scrollOffset</code> changed between commits. This is likely what caused the <code class=\"language-text\">List</code> component to re-render.</p>\n<h3><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#ranked-chart\"></a>Ranked chart</h3>\n<p>The ranked chart view represents a single commit. Each bar in the chart represents a React component (e.g. <code class=\"language-text\">App</code>, <code class=\"language-text\">Nav</code>). The chart is ordered so that the components which took the longest to render are at the top.</p>\n<p><a href=\"https://reactjs.org/static/0c81347535e28c9cdef0e94fab887b89/ad997/ranked-chart.png\"><img src=\"https://reactjs.org/static/0c81347535e28c9cdef0e94fab887b89/1e088/ranked-chart.png\" alt=\"Example ranked chart\"></a></p>\n<blockquote>\n<p>Note:</p>\n<p>A component’s render time includes the time spent rendering its children, so the components which took the longest to render are generally near the top of the tree.</p>\n</blockquote>\n<p>As with the flame chart, you can zoom in or out on a ranked chart by clicking on components.</p>\n<h3><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#component-chart\"></a>Component chart</h3>\n<p>Sometimes it’s useful to see how many times a particular component rendered while you were profiling. The component chart provides this information in the form of a bar chart. Each bar in the chart represents a time when the component rendered. The color and height of each bar corresponds to how long the component took to render <em>relative to other components</em> in a particular commit.</p>\n<p><a href=\"https://reactjs.org/static/d71275b42c6109e222fbb0932a0c8c09/ad997/component-chart.png\"><img src=\"https://reactjs.org/static/d71275b42c6109e222fbb0932a0c8c09/1e088/component-chart.png\" alt=\"Example component chart\"></a></p>\n<p>The chart above shows that the <code class=\"language-text\">List</code> component rendered 11 times. It also shows that each time it rendered, it was the most “expensive” component in the commit (meaning that it took the longest).</p>\n<p>To view this chart, either double-click on a component <em>or</em> select a component and click on the blue bar chart icon in the right detail pane. You can return to the previous chart by clicking the “x” button in the right detail pane. You can also double click on a particular bar to view more information about that commit.</p>\n<p><img src=\"https://reactjs.org/99cb4321ded8eb0c21ae5fc673878563/see-all-commits-for-a-fiber.gif\" alt=\"How to view all renders for a specific component\"></p>\n<p>If the selected component did not render at all during the profiling session, the following message will be shown:</p>\n<p><a href=\"https://reactjs.org/static/8eb0c37a13353ef5d9e61ae8fc040705/ad997/no-render-times-for-selected-component.png\"><img src=\"https://reactjs.org/static/8eb0c37a13353ef5d9e61ae8fc040705/1e088/no-render-times-for-selected-component.png\" alt=\"No render times for the selected component\"></a></p>\n<h3><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#interactions\"></a>Interactions</h3>\n<p>React recently added another <a href=\"https://fb.me/react-interaction-tracing\">experimental API</a> for tracing the <em>cause</em> of an update. “Interactions” traced with this API will also be shown in the profiler:</p>\n<p><a href=\"https://reactjs.org/static/a91a39ac076b71aa7a202aaf46f8bd5a/ad997/interactions.png\"><img src=\"https://reactjs.org/static/a91a39ac076b71aa7a202aaf46f8bd5a/1e088/interactions.png\" alt=\"The interactions panel\"></a></p>\n<p>The image above shows a profiling session that traced four interactions. Each row represents an interaction that was traced. The colored dots along the row represent commits that were related to that interaction.</p>\n<p>You can also see which interactions were traced for a particular commit from the flame chart and ranked chart views as well:</p>\n<p><a href=\"https://reactjs.org/static/9847e78f930cb7cf2b0f9682853a5dbc/ad997/interactions-for-commit.png\"><img src=\"https://reactjs.org/static/9847e78f930cb7cf2b0f9682853a5dbc/1e088/interactions-for-commit.png\" alt=\"List of interactions for a commit\"></a></p>\n<p>You can navigate between interactions and commits by clicking on them:</p>\n<p><img src=\"https://reactjs.org/7c66e7686b5242473c87b3d0b4576cf3/navigate-between-interactions-and-commits.gif\" alt=\"Navigate between interactions and commits\"></p>\n<p>The tracing API is still new and we will cover it in more detail in a future blog post.</p>\n<h2><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#troubleshooting\"></a>Troubleshooting</h2>\n<h3><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#no-profiling-data-has-been-recorded-for-the-selected-root\"></a>No profiling data has been recorded for the selected root</h3>\n<p>If your application has multiple “roots”, you may see the following message after profiling:<a href=\"https://reactjs.org/static/0755492a211f5bbb775285c0ff2fdfda/ad997/no-profiler-data-multi-root.png\"><img src=\"https://reactjs.org/static/0755492a211f5bbb775285c0ff2fdfda/1e088/no-profiler-data-multi-root.png\" alt=\"No profiling data has been recorded for the selected root\"></a></p>\n<p>This message indicates that no performance data was recorded for the root that’s selected in the “Elements” panel. In this case, try selecting a different root in that panel to view profiling information for that root:</p>\n<p><img src=\"https://reactjs.org/bdc30593d414b5c8d2ae92027ed11940/select-a-root-to-view-profiling-data.gif\" alt=\"Select a root in the &#x22;Elements&#x22; panel to view its performance data\"></p>\n<h3><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#no-timing-data-to-display-for-the-selected-commit\"></a>No timing data to display for the selected commit</h3>\n<p>Sometimes a commit may be so fast that <code class=\"language-text\">performance.now()</code> doesn’t give DevTools any meaningful timing information. In this case, the following message will be shown:</p>\n<p><a href=\"https://reactjs.org/static/63b2fb6298feecb179272c467020ed95/ad997/no-timing-data-for-commit.png\"><img src=\"https://reactjs.org/static/63b2fb6298feecb179272c467020ed95/1e088/no-timing-data-for-commit.png\" alt=\"No timing data to display for the selected commit\"></a></p>\n<h2><a href=\"https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html#deep-dive-video\"></a>Deep dive video</h2>\n<p>The following video demonstrates how the React profiler can be used to detect and improve performance bottlenecks in an actual React application.</p>\n<!--EndFragment-->"},{"url":"/docs/python/data-structures-in-python/","relativePath":"docs/python/data-structures-in-python/index.md","relativeDir":"docs/python/data-structures-in-python","base":"index.md","name":"index","frontmatter":{"title":"Data Structures In Python","template":"docs","excerpt":"Dictionaries, Maps, and Hash Tables"},"html":"<h1>Common Python Data Structures (Guide) – Real Python</h1>\n<hr>\n<h2>Dictionaries, Maps, and Hash Tables</h2>\n<p>In Python, <strong>dictionaries(or dicts for short) are a central data structure. Dicts store an arbitrary number of objects, each identified by a unique dictionary</strong> <strong>key</strong>.</p>\n<p>Dictionaries are also often called <strong>maps</strong>, <strong>hashmaps</strong>, <strong>lookup tables</strong>, or <strong>associative arrays</strong>. They allow for the efficient lookup, insertion, and deletion of any object associated with a given key.</p>\n<p>Phone books make a decent real-world analog for dictionary objects. They allow you to quickly retrieve the information (phone number) associated with a given key (a person’s name). Instead of having to read a phone book front to back to find someone’s number, you can jump more or less directly to a name and look up the associated information.</p>\n<p>This analogy breaks down somewhat when it comes to <em>how</em> the information is organized to allow for fast lookups. But the fundamental performance characteristics hold. Dictionaries allow you to quickly find the information associated with a given key.</p>\n<p>Dictionaries are one of the most important and frequently used data structures in computer science. So, how does Python handle dictionaries? Let’s take a tour of the dictionary implementations available in core Python and the Python standard library.</p>\n<h3><code class=\"language-text\">dict</code>: Your Go-To Dictionary</h3>\n<p>Because dictionaries are so important, Python features a robust dictionary implementation that’s built directly into the core language: the <a href=\"https://docs.python.org/3/library/stdtypes.html#mapping-types-dict\"><code class=\"language-text\">dict</code></a> data type.</p>\n<p>Python also provides some useful <strong>syntactic sugar</strong> for working with dictionaries in your programs. For example, the curly-brace ({ }) dictionary expression syntax and <a href=\"https://realpython.com/iterate-through-dictionary-python/#using-comprehensions\">dictionary comprehensions</a> allow you to conveniently define new dictionary objects:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> phonebook <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"bob\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">7387</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"alice\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3719</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"jack\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">7052</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token punctuation\">}</span>\n\n squares <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">*</span> x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n phonebook<span class=\"token punctuation\">[</span><span class=\"token string\">\"alice\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">3719</span>\n\n squares\n<span class=\"token punctuation\">{</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span> <span class=\"token number\">16</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span> <span class=\"token number\">25</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>There are some restrictions on which objects can be used as valid keys.</p>\n<p>Python’s dictionaries are indexed by keys that can be of any <a href=\"https://docs.python.org/3/glossary.html#term-hashable\">hashable</a> type. A <strong>hashable</strong> object has a hash value that never changes during its lifetime (see <code class=\"language-text\">__hash__</code>), and it can be compared to other objects (see <code class=\"language-text\">__eq__</code>). Hashable objects that compare as equal must have the same hash value.</p>\n<p><a href=\"https://realpython.com/courses/immutability-python/\"><strong>Immutable</strong> types</a> like <a href=\"https://realpython.com/python-strings/\">strings</a> and <a href=\"https://realpython.com/python-data-types/\">numbers</a> are hashable and work well as dictionary keys. You can also use <a href=\"https://realpython.com/python-lists-tuples/#python-tuples\"><code class=\"language-text\">tuple</code> objects</a> as dictionary keys as long as they contain only hashable types themselves.</p>\n<p>For most use cases, Python’s built-in dictionary implementation will do everything you need. Dictionaries are highly optimized and underlie many parts of the language. For example, <a href=\"https://realpython.com/python-scope-legb-rule/#class-and-instance-attributes-scope\">class attributes</a> and variables in a <a href=\"https://en.wikipedia.org/wiki/Call_stack#Structure\">stack frame</a> are both stored internally in dictionaries.</p>\n<p>Python dictionaries are based on a well-tested and finely tuned <a href=\"https://realpython.com/python-hash-table/\">hash table</a> implementation that provides the performance characteristics you’d expect: <em>O</em>(1) time complexity for lookup, insert, update, and delete operations in the average case.</p>\n<p>There’s little reason not to use the standard <code class=\"language-text\">dict</code> implementation included with Python. However, specialized third-party dictionary implementations exist, such as <a href=\"https://en.wikipedia.org/wiki/Skip_list\">skip lists</a> or <a href=\"https://en.wikipedia.org/wiki/B-tree\">B-tree–based</a> dictionaries.</p>\n<p>Besides plain <code class=\"language-text\">dict</code> objects, Python’s standard library also includes a number of specialized dictionary implementations. These specialized dictionaries are all based on the built-in dictionary class (and share its performance characteristics) but also include some additional convenience features.</p>\n<p>Let’s take a look at them.</p>\n<h3><code class=\"language-text\">collections.OrderedDict</code>: Remember the Insertion Order of Keys<a href=\"#collectionsordereddict-remember-the-insertion-order-of-keys\" title=\"Permanent link\"></a></h3>\n<p>Python includes a specialized <code class=\"language-text\">dict</code> subclass that remembers the insertion order of keys added to it: <a href=\"https://realpython.com/python-ordereddict/\"><code class=\"language-text\">collections.OrderedDict</code></a>.</p>\n<p><strong>Note:</strong> <code class=\"language-text\">OrderedDict</code> is not a built-in part of the core language and must be imported from the <code class=\"language-text\">collections</code> module in the standard library.</p>\n<p>While standard <code class=\"language-text\">dict</code> instances preserve the insertion order of keys in CPython 3.6 and above, this was simply a <a href=\"https://mail.python.org/pipermail/python-dev/2016-September/146327.html\">side effect</a> of the CPython implementation and was not defined in the language spec until Python 3.7. So, if key order is important for your algorithm to work, then it’s best to communicate this clearly by explicitly using the <code class=\"language-text\">OrderedDict</code> class:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">import</span> collections\n d <span class=\"token operator\">=</span> collections<span class=\"token punctuation\">.</span>OrderedDict<span class=\"token punctuation\">(</span>one<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> two<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> three<span class=\"token operator\">=</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n\n d\nOrderedDict<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n d<span class=\"token punctuation\">[</span><span class=\"token string\">\"four\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">4</span>\n d\nOrderedDict<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n             <span class=\"token punctuation\">(</span><span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'four'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n d<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nodict_keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'four'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Until <a href=\"https://realpython.com/python38-new-features/\">Python 3.8</a>, you couldn’t iterate over dictionary items in reverse order using <code class=\"language-text\">reversed()</code>. Only <code class=\"language-text\">OrderedDict</code> instances offered that functionality. Even in Python 3.8, <code class=\"language-text\">dict</code> and <code class=\"language-text\">OrderedDict</code> objects aren’t exactly the same. <code class=\"language-text\">OrderedDict</code> instances have a <a href=\"https://realpython.com/python-data-types/\"><code class=\"language-text\">.move_to_end()</code> method</a> that is unavailable on plain <code class=\"language-text\">dict</code> instance, as well as a more customizable <a href=\"https://docs.python.org/3/library/collections.html#collections.OrderedDict.popitem\"><code class=\"language-text\">.popitem()</code> method</a> than the one plain <code class=\"language-text\">dict</code> instances.</p>\n<h3><code class=\"language-text\">collections.defaultdict</code>: Return Default Values for Missing Keys<a href=\"#collectionsdefaultdict-return-default-values-for-missing-keys\" title=\"Permanent link\"></a></h3>\n<p>The <a href=\"https://docs.python.org/3/library/collections.html#collections.defaultdict\"><code class=\"language-text\">defaultdict</code></a> class is another dictionary subclass that accepts a callable in its constructor whose return value will be used if a requested key cannot be found.</p>\n<p>This can save you some typing and make your intentions clearer as compared to using <code class=\"language-text\">get()</code> or catching a <a href=\"https://realpython.com/python-keyerror/\"><code class=\"language-text\">KeyError</code> exception</a> in regular dictionaries:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> defaultdict\n dd <span class=\"token operator\">=</span> defaultdict<span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Accessing a missing key creates it and</span>\n <span class=\"token comment\"># initializes it using the default factory,</span>\n <span class=\"token comment\"># i.e. list() in this example:</span>\n dd<span class=\"token punctuation\">[</span><span class=\"token string\">\"dogs\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">\"Rufus\"</span><span class=\"token punctuation\">)</span>\n dd<span class=\"token punctuation\">[</span><span class=\"token string\">\"dogs\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">\"Kathrin\"</span><span class=\"token punctuation\">)</span>\n dd<span class=\"token punctuation\">[</span><span class=\"token string\">\"dogs\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">\"Mr Sniffles\"</span><span class=\"token punctuation\">)</span>\n\n dd<span class=\"token punctuation\">[</span><span class=\"token string\">\"dogs\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'Rufus'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Kathrin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Mr Sniffles'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"https://srv.realpython.net/click/33172000876/?c=43772654581&#x26;p=58946116052&#x26;r=75987\">\n<img src=\"https://img.realpython.net/c34848d05efe728b284c7a87c7fcd5c9\" alt=\"image\"></a></p>\n<p><a href=\"https://realpython.com/account/join/\">Remove ads</a></p>\n<h3><code class=\"language-text\">collections.ChainMap</code>: Search Multiple Dictionaries as a Single Mapping<a href=\"#collectionschainmap-search-multiple-dictionaries-as-a-single-mapping\" title=\"Permanent link\"></a></h3>\n<p>The <a href=\"https://docs.python.org/3/library/collections.html#collections.ChainMap\"><code class=\"language-text\">collections.ChainMap</code></a> data structure groups multiple dictionaries into a single mapping. Lookups search the underlying mappings one by one until a key is found. Insertions, updates, and deletions only affect the first mapping added to the chain:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> ChainMap\n dict1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n dict2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"three\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"four\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\n chain <span class=\"token operator\">=</span> ChainMap<span class=\"token punctuation\">(</span>dict1<span class=\"token punctuation\">,</span> dict2<span class=\"token punctuation\">)</span>\n\n chain\nChainMap<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'three'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'four'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># ChainMap searches each collection in the chain</span>\n <span class=\"token comment\"># from left to right until it finds the key (or fails):</span>\n chain<span class=\"token punctuation\">[</span><span class=\"token string\">\"three\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">3</span>\n chain<span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1</span>\n chain<span class=\"token punctuation\">[</span><span class=\"token string\">\"missing\"</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nKeyError<span class=\"token punctuation\">:</span> <span class=\"token string\">'missing'</span></code></pre></div>\n<h3><code class=\"language-text\">types.MappingProxyType</code>: A Wrapper for Making Read-Only Dictionaries<a href=\"#typesmappingproxytype-a-wrapper-for-making-read-only-dictionaries\" title=\"Permanent link\"></a></h3>\n<p><a href=\"https://docs.python.org/3/library/types.html#types.MappingProxyType\"><code class=\"language-text\">MappingProxyType</code></a> is a wrapper around a standard dictionary that provides a read-only view into the wrapped dictionary’s data. This class was added in Python 3.3 and can be used to create immutable proxy versions of dictionaries.</p>\n<p><code class=\"language-text\">MappingProxyType</code> can be helpful if, for example, you’d like to return a dictionary carrying internal state from a class or module while discouraging write access to this object. Using <code class=\"language-text\">MappingProxyType</code> allows you to put these restrictions in place without first having to create a full copy of the dictionary:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">from</span> types <span class=\"token keyword\">import</span> MappingProxyType\n writable <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n read_only <span class=\"token operator\">=</span> MappingProxyType<span class=\"token punctuation\">(</span>writable<span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># The proxy is read-only:</span>\n read_only<span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1</span>\n read_only<span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">23</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'mappingproxy'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support item assignment\n\n <span class=\"token comment\"># Updates to the original are reflected in the proxy:</span>\n writable<span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">42</span>\n read_only\nmappingproxy<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Dictionaries in Python: Summary<a href=\"#dictionaries-in-python-summary\" title=\"Permanent link\"></a></h3>\n<p>All the Python dictionary implementations listed in this tutorial are valid implementations that are built into the Python standard library.</p>\n<p>If you’re looking for a general recommendation on which mapping type to use in your programs, I’d point you to the built-in <code class=\"language-text\">dict</code> data type. It’s a versatile and optimized hash table implementation that’s built directly into the core language.</p>\n<p>I would recommend that you use one of the other data types listed here only if you have special requirements that go beyond what’s provided by <code class=\"language-text\">dict</code>.</p>\n<p>All the implementations are valid options, but your code will be clearer and easier to maintain if it relies on standard Python dictionaries most of the time.</p>\n<h2>Array Data Structures<a href=\"#array-data-structures\" title=\"Permanent link\"></a></h2>\n<p>An <strong>array</strong> is a fundamental data structure available in most programming languages, and it has a wide range of uses across different algorithms.</p>\n<p>In this section, you’ll take a look at array implementations in Python that use only core language features or functionality that’s included in the Python standard library. You’ll see the strengths and weaknesses of each approach so you can decide which implementation is right for your use case.</p>\n<p>But before we jump in, let’s cover some of the basics first. How do arrays work, and what are they used for? Arrays consist of fixed-size data records that allow each element to be efficiently located based on its index:</p>\n<p><a href=\"https://files.realpython.com/media/python-linked-list-array-visualization.5b9f4c4040cb.jpeg\"><img src=\"https://files.realpython.com/media/python-linked-list-array-visualization.5b9f4c4040cb.jpeg\" alt=\"Visual representation of an array\"></a></p>\n<p>Because arrays store information in adjoining blocks of memory, they’re considered <strong>contiguous</strong> data structures (as opposed to <strong>linked</strong> data structures like linked lists, for example).</p>\n<p>A real-world analogy for an array data structure is a parking lot. You can look at the parking lot as a whole and treat it as a single object, but inside the lot there are parking spots indexed by a unique number. Parking spots are containers for vehicles—each parking spot can either be empty or have a car, a motorbike, or some other vehicle parked on it.</p>\n<p>But not all parking lots are the same. Some parking lots may be restricted to only one type of vehicle. For example, a motor home parking lot wouldn’t allow bikes to be parked on it. A restricted parking lot corresponds to a <strong>typed</strong> array data structure that allows only elements that have the same data type stored in them.</p>\n<p>Performance-wise, it’s very fast to look up an element contained in an array given the element’s index. A proper array implementation guarantees a constant <em>O</em>(1) access time for this case.</p>\n<p>Python includes several array-like data structures in its standard library that each have slightly different characteristics. Let’s take a look.</p>\n<h3><code class=\"language-text\">list</code>: Mutable Dynamic Arrays<a href=\"#list-mutable-dynamic-arrays\" title=\"Permanent link\"></a></h3>\n<p><a href=\"https://docs.python.org/3.6/library/stdtypes.html#lists\">Lists</a> are a part of the core Python language. Despite their name, Python’s lists are implemented as <strong>dynamic arrays</strong> behind the scenes.</p>\n<p>This means a list allows elements to be added or removed, and the list will automatically adjust the backing store that holds these elements by allocating or releasing memory.</p>\n<p>Python lists can hold arbitrary elements—everything is an object in Python, including functions. Therefore, you can mix and match different kinds of data types and store them all in a single list.</p>\n<p>This can be a powerful feature, but the downside is that supporting multiple data types at the same time means that data is generally less tightly packed. As a result, the whole structure takes up more space:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"three\"</span><span class=\"token punctuation\">]</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'one'</span>\n\n <span class=\"token comment\"># Lists have a nice repr:</span>\n arr\n<span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span>\n\n <span class=\"token comment\"># Lists are mutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\n arr\n<span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span>\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n arr\n<span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span>\n\n <span class=\"token comment\"># Lists can hold arbitrary data types:</span>\n arr<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token number\">23</span><span class=\"token punctuation\">)</span>\n arr\n<span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3><code class=\"language-text\">tuple</code>: Immutable Containers<a href=\"#tuple-immutable-containers\" title=\"Permanent link\"></a></h3>\n<p>Just like lists, <a href=\"https://docs.python.org/3/library/stdtypes.html#tuple\">tuples</a> are part of the Python core language. Unlike lists, however, Python’s <code class=\"language-text\">tuple</code> objects are immutable. This means elements can’t be added or removed dynamically—all elements in a tuple must be defined at creation time.</p>\n<p>Tuples are another data structure that can hold elements of arbitrary data types. Having this flexibility is powerful, but again, it also means that data is less tightly packed than it would be in a typed array:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"one\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"two\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"three\"</span><span class=\"token punctuation\">)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'one'</span>\n\n <span class=\"token comment\"># Tuples have a nice repr:</span>\n arr\n<span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Tuples are immutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'tuple'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support item assignment\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'tuple'</span> <span class=\"token builtin\">object</span> doesn't support item deletion\n\n <span class=\"token comment\"># Tuples can hold arbitrary data types:</span>\n <span class=\"token comment\"># (Adding elements creates a copy of the tuple)</span>\n arr <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token number\">23</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3><code class=\"language-text\">array.array</code>: Basic Typed Arrays<a href=\"#arrayarray-basic-typed-arrays\" title=\"Permanent link\"></a></h3>\n<p>Python’s <code class=\"language-text\">array</code> module provides space-efficient storage of basic C-style data types like bytes, 32-bit integers, floating-point numbers, and so on.</p>\n<p>Arrays created with the <a href=\"https://docs.python.org/3/library/array.html\"><code class=\"language-text\">array.array</code></a> class are mutable and behave similarly to lists except for one important difference: they’re <strong>typed arrays</strong> constrained to a single data type.</p>\n<p>Because of this constraint, <code class=\"language-text\">array.array</code> objects with many elements are more space efficient than lists and tuples. The elements stored in them are tightly packed, and this can be useful if you need to store many elements of the same type.</p>\n<p>Also, arrays support many of the same methods as regular lists, and you might be able to use them as a drop-in replacement without requiring other changes to your application code.</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> <span class=\"token keyword\">import</span> array\n arr <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span>array<span class=\"token punctuation\">(</span><span class=\"token string\">\"f\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1.5</span>\n\n <span class=\"token comment\"># Arrays have a nice repr:</span>\n arr\narray<span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Arrays are mutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">23.0</span>\n arr\narray<span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n arr\narray<span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n arr<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token number\">42.0</span><span class=\"token punctuation\">)</span>\n arr\narray<span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">42.0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Arrays are \"typed\":</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> must be real number<span class=\"token punctuation\">,</span> <span class=\"token keyword\">not</span> <span class=\"token builtin\">str</span></code></pre></div>\n<h3><code class=\"language-text\">str</code>: Immutable Arrays of Unicode Characters<a href=\"#str-immutable-arrays-of-unicode-characters\" title=\"Permanent link\"></a></h3>\n<p>Python 3.x uses <a href=\"https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str\"><code class=\"language-text\">str</code></a> objects to store textual data as immutable sequences of <a href=\"https://realpython.com/python-encodings-guide/\">Unicode characters</a>. Practically speaking, that means a <code class=\"language-text\">str</code> is an immutable array of characters. Oddly enough, it’s also a <a href=\"https://realpython.com/python-thinking-recursively/\">recursive</a> data structure—each character in a string is itself a <code class=\"language-text\">str</code> object of length 1.</p>\n<p>String objects are space efficient because they’re tightly packed and they specialize in a single data type. If you’re storing Unicode text, then you should use a string.</p>\n<p>Because strings are immutable in Python, modifying a string requires creating a modified copy. The closest equivalent to a mutable string is storing individual characters inside a list:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token string\">\"abcd\"</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'b'</span>\n\n arr\n<span class=\"token string\">'abcd'</span>\n\n <span class=\"token comment\"># Strings are immutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"e\"</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'str'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support item assignment\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'str'</span> <span class=\"token builtin\">object</span> doesn't support item deletion\n\n <span class=\"token comment\"># Strings can be unpacked into a list to</span>\n <span class=\"token comment\"># get a mutable representation:</span>\n <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abcd\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">]</span>\n <span class=\"token string\">\"\"</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abcd\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'abcd'</span>\n\n <span class=\"token comment\"># Strings are recursive data structures:</span>\n <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">\"&lt;class 'str'>\"</span>\n <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">\"&lt;class 'str'>\"</span></code></pre></div>\n<h3><code class=\"language-text\">bytes</code>: Immutable Arrays of Single Bytes<a href=\"#bytes-immutable-arrays-of-single-bytes\" title=\"Permanent link\"></a></h3>\n<p><a href=\"https://docs.python.org/3/library/stdtypes.html#bytes-objects\"><code class=\"language-text\">bytes</code></a> objects are immutable sequences of single bytes, or integers in the range 0 ≤ <em>x</em> ≤ 255. Conceptually, <code class=\"language-text\">bytes</code> objects are similar to <code class=\"language-text\">str</code> objects, and you can also think of them as immutable arrays of bytes.</p>\n<p>Like strings, <code class=\"language-text\">bytes</code> have their own literal syntax for creating objects and are space efficient. <code class=\"language-text\">bytes</code> objects are immutable, but unlike strings, there’s a dedicated mutable byte array data type called <code class=\"language-text\">bytearray</code> that they can be unpacked into:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token builtin\">bytes</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1</span>\n\n <span class=\"token comment\"># Bytes literals have their own syntax:</span>\n arr\n<span class=\"token string\">b'\\x00\\x01\\x02\\x03'</span>\n arr <span class=\"token operator\">=</span> <span class=\"token string\">b\"\\x00\\x01\\x02\\x03\"</span>\n\n <span class=\"token comment\"># Only valid `bytes` are allowed:</span>\n <span class=\"token builtin\">bytes</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nValueError<span class=\"token punctuation\">:</span> <span class=\"token builtin\">bytes</span> must be <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">256</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Bytes are immutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">23</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'bytes'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support item assignment\n\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'bytes'</span> <span class=\"token builtin\">object</span> doesn't support item deletion</code></pre></div>\n<h3><code class=\"language-text\">bytearray</code>: Mutable Arrays of Single Bytes<a href=\"#bytearray-mutable-arrays-of-single-bytes\" title=\"Permanent link\"></a></h3>\n<p>The <a href=\"https://docs.python.org/3.1/library/functions.html#bytearray\"><code class=\"language-text\">bytearray</code></a> type is a mutable sequence of integers in the range 0 ≤ <em>x</em> ≤ 255. The <code class=\"language-text\">bytearray</code> object is closely related to the <code class=\"language-text\">bytes</code> object, with the main difference being that a <code class=\"language-text\">bytearray</code> can be modified freely—you can overwrite elements, remove existing elements, or add new ones. The <code class=\"language-text\">bytearray</code> object will grow and shrink accordingly.</p>\n<p>A <code class=\"language-text\">bytearray</code> can be converted back into immutable <code class=\"language-text\">bytes</code> objects, but this involves copying the stored data in full—a slow operation taking <em>O</em>(<em>n</em>) time:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> arr <span class=\"token operator\">=</span> <span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">1</span>\n\n <span class=\"token comment\"># The bytearray repr:</span>\n arr\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token string\">b'\\x00\\x01\\x02\\x03'</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Bytearrays are mutable:</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">23</span>\n arr\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token string\">b'\\x00\\x17\\x02\\x03'</span><span class=\"token punctuation\">)</span>\n\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">23</span>\n\n <span class=\"token comment\"># Bytearrays can grow and shrink in size:</span>\n <span class=\"token keyword\">del</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n arr\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token string\">b'\\x00\\x02\\x03'</span><span class=\"token punctuation\">)</span>\n\n arr<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token number\">42</span><span class=\"token punctuation\">)</span>\n arr\n<span class=\"token builtin\">bytearray</span><span class=\"token punctuation\">(</span><span class=\"token string\">b'\\x00\\x02\\x03*'</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Bytearrays can only hold `bytes`</span>\n <span class=\"token comment\"># (integers in the range 0 &lt;= x &lt;= 255)</span>\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'str'</span> <span class=\"token builtin\">object</span> cannot be interpreted <span class=\"token keyword\">as</span> an integer\n\n arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">300</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nValueError<span class=\"token punctuation\">:</span> byte must be <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">256</span><span class=\"token punctuation\">)</span>\n\n <span class=\"token comment\"># Bytearrays can be converted back into bytes objects:</span>\n <span class=\"token comment\"># (This will copy the data)</span>\n <span class=\"token builtin\">bytes</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span>\n<span class=\"token string\">b'\\x00\\x02\\x03*'</span></code></pre></div>\n<h3>Arrays in Python: Summary<a href=\"#arrays-in-python-summary\" title=\"Permanent link\"></a></h3>\n<p>There are a number of built-in data structures you can choose from when it comes to implementing arrays in Python. In this section, you’ve focused on core language features and data structures included in the standard library.</p>\n<p>If you’re willing to go beyond the Python standard library, then third-party packages like <a href=\"https://realpython.com/numpy-array-programming/\">NumPy</a> and <a href=\"https://realpython.com/pandas-dataframe/\">pandas</a> offer a wide range of fast array implementations for scientific computing and data science.</p>\n<p>If you want to restrict yourself to the array data structures included with Python, then here are a few guidelines:</p>\n<ul>\n<li>If you need to store arbitrary objects, potentially with mixed data types, then use a <code class=\"language-text\">list</code> or a <code class=\"language-text\">tuple</code>, depending on whether or not you want an immutable data structure.</li>\n<li>If you have numeric (integer or floating-point) data and tight packing and performance is important, then try out <code class=\"language-text\">array.array</code>.</li>\n<li>If you have textual data represented as Unicode characters, then use Python’s built-in <code class=\"language-text\">str</code>. If you need a mutable string-like data structure, then use a <code class=\"language-text\">list</code> of characters.</li>\n<li>If you want to store a contiguous block of bytes, then use the immutable <code class=\"language-text\">bytes</code> type or a <code class=\"language-text\">bytearray</code> if you need a mutable data structure.</li>\n</ul>\n<p>In most cases, I like to start out with a simple <code class=\"language-text\">list</code>. I’ll only specialize later on if performance or storage space becomes an issue. Most of the time, using a general-purpose array data structure like <code class=\"language-text\">list</code> gives you the fastest development speed and the most programming convenience.</p>\n<p>I’ve found that this is usually much more important in the beginning than trying to squeeze out every last drop of performance right from the start.</p>\n<h2>Records, Structs, and Data Transfer Objects<a href=\"#records-structs-and-data-transfer-objects\" title=\"Permanent link\"></a></h2>\n<p>Compared to arrays, <strong>record</strong> data structures provide a fixed number of fields. Each field can have a name and may also have a different type.</p>\n<p>In this section, you’ll see how to implement records, structs, and plain old data objects in Python using only built-in data types and classes from the standard library.</p>\n<p><strong>Note:</strong> I’m using the definition of a record loosely here. For example, I’m also going to discuss types like Python’s built-in <code class=\"language-text\">tuple</code> that may or may not be considered records in a strict sense because they don’t provide named fields.</p>\n<p>Python offers several data types that you can use to implement records, structs, and data transfer objects. In this section, you’ll get a quick look at each implementation and its unique characteristics. At the end, you’ll find a summary and a decision-making guide that will help you make your own picks.</p>\n<p><strong>Note:</strong> This tutorial is adapted from the chapter “Common Data Structures in Python” in <a href=\"https://realpython.com/products/python-tricks-book/\"><em>Python Tricks: The Book</em></a>. If you enjoy what you’re reading, then be sure to check out <a href=\"https://realpython.com/products/python-tricks-book/\">the rest of the book</a>.</p>\n<p>Alright, let’s get started!</p>\n<h3><code class=\"language-text\">dict</code>: Simple Data Objects<a href=\"#dict-simple-data-objects\" title=\"Permanent link\"></a></h3>\n<p>As mentioned <a href=\"#dictionaries-maps-and-hash-tables\">previously</a>, Python dictionaries store an arbitrary number of objects, each identified by a unique key. Dictionaries are also often called <strong>maps</strong> or <strong>associative arrays</strong> and allow for efficient lookup, insertion, and deletion of any object associated with a given key.</p>\n<p>Using dictionaries as a record data type or data object in Python is possible. Dictionaries are easy to create in Python as they have their own syntactic sugar built into the language in the form of <strong>dictionary literals</strong>. The dictionary syntax is concise and quite convenient to type.</p>\n<p>Data objects created using dictionaries are mutable, and there’s little protection against misspelled field names as fields can be added and removed freely at any time. Both of these properties can introduce surprising bugs, and there’s always a trade-off to be made between convenience and error resilience:</p>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"> car1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"color\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"mileage\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3812.4</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"automatic\"</span><span class=\"token punctuation\">:</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token punctuation\">}</span>\n car2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"color\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"blue\"</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"mileage\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">40231</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token string\">\"automatic\"</span><span class=\"token punctuation\">:</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token punctuation\">}</span>\n\n <span class=\"token comment\"># Dicts have a nice repr:</span>\n car2</code></pre></div>"},{"url":"/docs/quick-ref/general-structured-data-guidelines/","relativePath":"docs/quick-ref/general-structured-data-guidelines/index.md","relativeDir":"docs/quick-ref/general-structured-data-guidelines","base":"index.md","name":"index","frontmatter":{"title":"General structured data guidelines","template":"docs","excerpt":"Google guidelines "},"html":"<h1>General structured data guidelines</h1>\n<p>These are the general guidelines that apply to all structured data. These guidelines must be followed to enable structured data to be eligible for inclusion in Google Search results. Pages or sites that violate these content guidelines may receive less favorable ranking or be marked as ineligible for rich results in Google Search in order to maintain a high-quality search experience for our users. If we find that your page contains spammy structured data or content, we will apply a manual action to your page. To check if you have a manual action, open the <a href=\"https://search.google.com/search-console/manual-actions\">Manual Actions report in Search Console</a>.</p>\n<p><strong>Important: Google does not guarantee that your structured data will show up in search results,</strong> even if your page is marked up correctly according to the <a href=\"https://search.google.com/test/rich-results\">Rich Results Test</a>. Here are some common reasons why:</p>\n<ul>\n<li>Using structured data <em>enables</em> a feature to be present, it does not <em>guarantee</em> that it will be present. The Google algorithm tailors search results to create what it thinks is the best search experience for a user, depending on many variables, including search history, location, and device type. In some cases it may determine that one feature is more appropriate than another, or even that a plain blue link is best.</li>\n<li>The structured data is not representative of the main content of the page, or is potentially misleading.</li>\n<li>The structured data is incorrect in a way that the Rich Results Test was not able to catch.</li>\n<li>The content referred to by the structured data is hidden from the user.</li>\n<li>The page does not meet the guidelines for structured data described here, the type-specific guidelines, or the <a href=\"https://developers.google.com/search/docs/advanced/guidelines/webmaster-guidelines\">general webmaster guidelines</a>.</li>\n</ul>\n<h2>Technical guidelines</h2>\n<p>You can test compliance with technical guidelines using the <a href=\"https://search.google.com/test/rich-results\">Rich Results Test</a> and the <a href=\"https://support.google.com/webmasters/answer/9012289\">URL Inspection tool</a>, which catch most technical errors.</p>\n<h3>Format</h3>\n<p>In order to be eligible for rich results, mark up your site's pages using one of <a href=\"https://developers.google.com/search/docs/advanced/structured-data/intro-structured-data#structured-data-format\">three supported formats</a>:</p>\n<ul>\n<li>JSON-LD (recommended)</li>\n<li>Microdata</li>\n<li>RDFa</li>\n</ul>\n<h3>Access</h3>\n<p>Do not block your structured data pages to Googlebot using robots.txt, the <code class=\"language-text\">noindex</code> tag, or any other access control methods.</p>\n<h2><a href=\"\"></a>Quality guidelines</h2>\n<p>These guidelines are not easily testable using an automated tool. Violating a quality guideline can prevent syntactically correct structured data from being displayed as a rich result in Google Search, or possibly cause it to be <a href=\"https://support.google.com/webmasters/answer/3498001\">marked as spam</a>.</p>\n<h3>Content</h3>\n<ul>\n<li>Follow the <a href=\"https://developers.google.com/search/docs/advanced/guidelines/webmaster-guidelines#quality_guidelines\">Google webmasters quality guidelines</a>.</li>\n<li>Provide up-to-date information. We won't show a rich result for time-sensitive content that is no longer relevant.</li>\n<li>Provide original content that you or your users have generated.</li>\n<li><strong>Don't</strong> mark up content that is not visible to readers of the page. For example, if the JSON-LD markup describes a performer, the HTML body must describe that same performer.</li>\n<li><strong>Don't</strong> mark up irrelevant or misleading content, such as fake reviews or content unrelated to the focus of a page.</li>\n<li><strong>Don't</strong> use structured data to deceive or mislead users. Don't impersonate any person or organization, or misrepresent your ownership, affiliation, or primary purpose.</li>\n<li>Content must not promote pedophilia, bestiality, sexual violence, violent or cruel acts, targeted hatred, or dangerous activities.</li>\n<li><strong>Don't</strong> mark up content that engages in illegal activities or promotes goods, services, or information that facilitates serious and immediate harm to others. Marking up content that provides information about such content for educational purposes is permitted.</li>\n<li>Content in structured data must also follow the additional content guidelines or policies, as documented in the specific feature guide. For example, content in <code class=\"language-text\">JobPosting</code> structured data must follow the <a href=\"https://developers.google.com/search/docs/advanced/structured-data/job-posting#content-policies\">job posting content policies</a>. Content in Practice problems structured data must follow the <a href=\"https://developers.google.com/search/docs/advanced/structured-data/practice-problems#content-guidelines\">Practice problems content guidelines</a>.</li>\n</ul>\n<h3>Relevance</h3>\n<p>Your structured data must be a true representation of the page content. Here are some examples of irrelevant data:</p>\n<ul>\n<li>A sports live streaming site labeling broadcasts as local events.</li>\n<li>A woodworking site labeling instructions as recipes.</li>\n</ul>\n<h3>Completeness</h3>\n<ul>\n<li>Specify all required properties listed in the <a href=\"https://developers.google.com/search/docs/guides/search-gallery\">documentation for your specific rich result type</a>. Items that are missing required properties are not eligible for rich results.</li>\n<li>The more recommended properties that you provide, the higher quality the result is to users. For example: users prefer job postings with explicitly stated salaries than those without; users prefer recipes with actual user reviews and genuine star ratings (note that reviews or ratings not by actual users are considered<a href=\"https://developers.google.com/search/docs/guides/prototype#self-review\">spammy</a>). Rich result ranking takes extra information into consideration.</li>\n</ul>\n<h3>Location</h3>\n<ul>\n<li>Put the structured data on the page that it describes, unless specified otherwise by the documentation.</li>\n<li>If you have duplicate pages for the same content, we recommend placing the same structured data on all page duplicates, not just on the canonical page.</li>\n</ul>\n<h3>Specificity</h3>\n<ul>\n<li>Try to use the most specific applicable type and property names defined by schema.org for your markup.</li>\n<li>Follow all additional guidelines given in the <a href=\"https://developers.google.com/search/docs/guides/search-gallery\">documentation for your specific rich result type</a>.</li>\n</ul>\n<h3>Images</h3>\n<ul>\n<li>When specifying an image as a structured data property, make sure that the image is relevant to the page that it's on. For example, if you define the <code class=\"language-text\">image</code> property of <code class=\"language-text\">NewsArticle</code>, the image must be relevant to that news article.</li>\n<li>All image URLs must be crawlable and indexable. Otherwise, Google Search can't find and display them on the search results page. To check if Google can access your URLs, use the <a href=\"https://support.google.com/webmasters/answer/9012289\">URL Inspection tool</a>.</li>\n</ul>"},{"url":"/docs/tips/decrement/","relativePath":"docs/tips/decrement/index.md","relativeDir":"docs/tips/decrement","base":"index.md","name":"index","frontmatter":{"title":"Decrement","template":"docs","excerpt":"The decrement operator (--) decrements (subtracts one from) its operand and returns a value."},"html":"<h1>Decrement (--)</h1>\n<p>The decrement operator (<code class=\"language-text\">--</code>) decrements (subtracts one from) its operand and returns a value.</p>\n<h2>Syntax</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Operator: x-- or --x</code></pre></div>\n<h2>Description</h2>\n<p>If used postfix, with operator after operand (for example, <code class=\"language-text\">x--</code>), the decrement operator decrements and returns the value before decrementing.</p>\n<p>If used prefix, with operator before operand (for example, <code class=\"language-text\">--x</code>), the decrement operator decrements and returns the value after decrementing.</p>\n<h2>Examples</h2>\n<h3>Postfix decrement</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let x = 3;\ny = x--;\n\n// y = 3\n// x = 2</code></pre></div>\n<h3>Prefix decrement</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let a = 2;\nb = --a;\n\n// a = 1\n// b = 1</code></pre></div>\n<h2>Specifications</h2>\n<table>\n<thead>\n<tr class=\"header\">\n<th>Specification</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td>\n<a href=\"https://tc39.es/ecma262/#sec-postfix-decrement-operator\">ECMAScript Language Specification (ECMAScript) \n<br/>\n<p><span class=\"small\">#sec-postfix-decrement-operator</span>\n</a></p>\n</td>\n</tr>\n</tbody>\n</table>\n<p><code class=\"language-text\">Decrement</code></p>"},{"url":"/docs/react/higher-order-components/","relativePath":"docs/react/higher-order-components/index.md","relativeDir":"docs/react/higher-order-components","base":"index.md","name":"index","frontmatter":{"title":"Higher Order Components","template":"docs","excerpt":"advanced techniques in react"},"html":"<!--StartFragment-->\n<h1>Higher-Order Components</h1>\n<p>A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per se. They are a pattern that emerges from React’s compositional nature.</p>\n<p>Concretely, <strong>a higher-order component is a function that takes a component and returns a new component.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Whereas a component transforms props into UI, a higher-order component transforms a component into another component.</p>\n<p>HOCs are common in third-party React libraries, such as Redux’s <a href=\"https://github.com/reduxjs/react-redux/blob/master/docs/api/connect.md#connect\"><code class=\"language-text\">connect</code></a> and Relay’s <a href=\"https://relay.dev/docs/v10.1.3/fragment-container/#createfragmentcontainer\"><code class=\"language-text\">createFragmentContainer</code></a>.</p>\n<p>In this document, we’ll discuss why higher-order components are useful, and how to write your own.</p>\n<h2><a href=\"https://reactjs.org/docs/higher-order-components.html#use-hocs-for-cross-cutting-concerns\"></a>Use HOCs For Cross-Cutting Concerns</h2>\n<blockquote>\n<p><strong>Note</strong></p>\n<p>We previously recommended mixins as a way to handle cross-cutting concerns. We’ve since realized that mixins create more trouble than they are worth. <a href=\"https://reactjs.org/blog/2016/07/13/mixins-considered-harmful.html\">Read more</a> about why we’ve moved away from mixins and how you can transition your existing components.</p>\n</blockquote>\n<p>Components are the primary unit of code reuse in React. However, you’ll find that some patterns aren’t a straightforward fit for traditional components.</p>\n<p>For example, say you have a <code class=\"language-text\">CommentList</code> component that subscribes to an external data source to render a list of comments:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Later, you write a component for subscribing to a single blog post, which follows a similar pattern:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><code class=\"language-text\">CommentList</code> and <code class=\"language-text\">BlogPost</code> aren’t identical — they call different methods on <code class=\"language-text\">DataSource</code>, and they render different output. But much of their implementation is the same:</p>\n<ul>\n<li>On mount, add a change listener to <code class=\"language-text\">DataSource</code>.</li>\n<li>Inside the listener, call <code class=\"language-text\">setState</code> whenever the data source changes.</li>\n<li>On unmount, remove the change listener.</li>\n</ul>\n<p>You can imagine that in a large app, this same pattern of subscribing to <code class=\"language-text\">DataSource</code> and calling <code class=\"language-text\">setState</code> will occur over and over again. We want an abstraction that allows us to define this logic in a single place and share it across many components. This is where higher-order components excel.</p>\n<p>We can write a function that creates components, like <code class=\"language-text\">CommentList</code> and <code class=\"language-text\">BlogPost</code>, that subscribe to <code class=\"language-text\">DataSource</code>. The function will accept as one of its arguments a child component that receives the subscribed data as a prop. Let’s call the function <code class=\"language-text\">withSubscription</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The first parameter is the wrapped component. The second parameter retrieves the data we’re interested in, given a <code class=\"language-text\">DataSource</code> and the current props.</p>\n<p>When <code class=\"language-text\">CommentListWithSubscription</code> and <code class=\"language-text\">BlogPostWithSubscription</code> are rendered, <code class=\"language-text\">CommentList</code> and <code class=\"language-text\">BlogPost</code> will be passed a <code class=\"language-text\">data</code> prop with the most current data retrieved from <code class=\"language-text\">DataSource</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Note that a HOC doesn’t modify the input component, nor does it use inheritance to copy its behavior. Rather, a HOC <em>composes</em> the original component by <em>wrapping</em> it in a container component. A HOC is a pure function with zero side-effects.</p>\n<p>And that’s it! The wrapped component receives all the props of the container, along with a new prop, <code class=\"language-text\">data</code>, which it uses to render its output. The HOC isn’t concerned with how or why the data is used, and the wrapped component isn’t concerned with where the data came from.</p>\n<p>Because <code class=\"language-text\">withSubscription</code> is a normal function, you can add as many or as few arguments as you like. For example, you may want to make the name of the <code class=\"language-text\">data</code> prop configurable, to further isolate the HOC from the wrapped component. Or you could accept an argument that configures <code class=\"language-text\">shouldComponentUpdate</code>, or one that configures the data source. These are all possible because the HOC has full control over how the component is defined.</p>\n<p>Like components, the contract between <code class=\"language-text\">withSubscription</code> and the wrapped component is entirely props-based. This makes it easy to swap one HOC for a different one, as long as they provide the same props to the wrapped component. This may be useful if you change data-fetching libraries, for example.</p>\n<h2><a href=\"https://reactjs.org/docs/higher-order-components.html#dont-mutate-the-original-component-use-composition\"></a>Don’t Mutate the Original Component. Use Composition.</h2>\n<p>Resist the temptation to modify a component’s prototype (or otherwise mutate it) inside a HOC.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>There are a few problems with this. One is that the input component cannot be reused separately from the enhanced component. More crucially, if you apply another HOC to <code class=\"language-text\">EnhancedComponent</code> that <em>also</em> mutates <code class=\"language-text\">componentDidUpdate</code>, the first HOC’s functionality will be overridden! This HOC also won’t work with function components, which do not have lifecycle methods.</p>\n<p>Mutating HOCs are a leaky abstraction—the consumer must know how they are implemented in order to avoid conflicts with other HOCs.</p>\n<p>Instead of mutation, HOCs should use composition, by wrapping the input component in a container component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>This HOC has the same functionality as the mutating version while avoiding the potential for clashes. It works equally well with class and function components. And because it’s a pure function, it’s composable with other HOCs, or even with itself.</p>\n<p>You may have noticed similarities between HOCs and a pattern called <strong>container components</strong>. Container components are part of a strategy of separating responsibility between high-level and low-level concerns. Containers manage things like subscriptions and state, and pass props to components that handle things like rendering UI. HOCs use containers as part of their implementation. You can think of HOCs as parameterized container component definitions.</p>\n<h2><a href=\"https://reactjs.org/docs/higher-order-components.html#convention-pass-unrelated-props-through-to-the-wrapped-component\"></a>Convention: Pass Unrelated Props Through to the Wrapped Component</h2>\n<p>HOCs add features to a component. They shouldn’t drastically alter its contract. It’s expected that the component returned from a HOC has a similar interface to the wrapped component.</p>\n<p>HOCs should pass through props that are unrelated to its specific concern. Most HOCs contain a render method that looks something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>This convention helps ensure that HOCs are as flexible and reusable as possible.</p>\n<h2><a href=\"https://reactjs.org/docs/higher-order-components.html#convention-maximizing-composability\"></a>Convention: Maximizing Composability</h2>\n<p>Not all HOCs look the same. Sometimes they accept only a single argument, the wrapped component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Usually, HOCs accept additional arguments. In this example from Relay, a config object is used to specify a component’s data dependencies:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The most common signature for HOCs looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p><em>What?!</em> If you break it apart, it’s easier to see what’s going on.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>In other words, <code class=\"language-text\">connect</code> is a higher-order function that returns a higher-order component!</p>\n<p>This form may seem confusing or unnecessary, but it has a useful property. Single-argument HOCs like the one returned by the <code class=\"language-text\">connect</code> function have the signature <code class=\"language-text\">Component => Component</code>. Functions whose output type is the same as its input type are really easy to compose together.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>(This same property also allows <code class=\"language-text\">connect</code> and other enhancer-style HOCs to be used as decorators, an experimental JavaScript proposal.)</p>\n<p>The <code class=\"language-text\">compose</code> utility function is provided by many third-party libraries including lodash (as <a href=\"https://lodash.com/docs/#flowRight\"><code class=\"language-text\">lodash.flowRight</code></a>), <a href=\"https://redux.js.org/api/compose\">Redux</a>, and <a href=\"https://ramdajs.com/docs/#compose\">Ramda</a>.</p>\n<h2><a href=\"https://reactjs.org/docs/higher-order-components.html#convention-wrap-the-display-name-for-easy-debugging\"></a>Convention: Wrap the Display Name for Easy Debugging</h2>\n<p>The container components created by HOCs show up in the <a href=\"https://github.com/facebook/react/tree/main/packages/react-devtools\">React Developer Tools</a> like any other component. To ease debugging, choose a display name that communicates that it’s the result of a HOC.</p>\n<p>The most common technique is to wrap the display name of the wrapped component. So if your higher-order component is named <code class=\"language-text\">withSubscription</code>, and the wrapped component’s display name is <code class=\"language-text\">CommentList</code>, use the display name <code class=\"language-text\">WithSubscription(CommentList)</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h2><a href=\"https://reactjs.org/docs/higher-order-components.html#caveats\"></a>Caveats</h2>\n<p>Higher-order components come with a few caveats that aren’t immediately obvious if you’re new to React.</p>\n<h3><a href=\"https://reactjs.org/docs/higher-order-components.html#dont-use-hocs-inside-the-render-method\"></a>Don’t Use HOCs Inside the render Method</h3>\n<p>React’s diffing algorithm (called <a href=\"https://reactjs.org/docs/reconciliation.html\">Reconciliation</a>) uses component identity to determine whether it should update the existing subtree or throw it away and mount a new one. If the component returned from <code class=\"language-text\">render</code> is identical (<code class=\"language-text\">===</code>) to the component from the previous render, React recursively updates the subtree by diffing it with the new one. If they’re not equal, the previous subtree is unmounted completely.</p>\n<p>Normally, you shouldn’t need to think about this. But it matters for HOCs because it means you can’t apply a HOC to a component within the render method of a component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>The problem here isn’t just about performance — remounting a component causes the state of that component and all of its children to be lost.</p>\n<p>Instead, apply HOCs outside the component definition so that the resulting component is created only once. Then, its identity will be consistent across renders. This is usually what you want, anyway.</p>\n<p>In those rare cases where you need to apply a HOC dynamically, you can also do it inside a component’s lifecycle methods or its constructor.</p>\n<h3><a href=\"https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over\"></a>Static Methods Must Be Copied Over</h3>\n<p>Sometimes it’s useful to define a static method on a React component. For example, Relay containers expose a static method <code class=\"language-text\">getFragment</code> to facilitate the composition of GraphQL fragments.</p>\n<p>When you apply a HOC to a component, though, the original component is wrapped with a container component. That means the new component does not have any of the static methods of the original component.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>To solve this, you could copy the methods onto the container before returning it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>However, this requires you to know exactly which methods need to be copied. You can use <a href=\"https://github.com/mridgway/hoist-non-react-statics\">hoist-non-react-statics</a> to automatically copy all non-React static methods:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Another possible solution is to export the static method separately from the component itself.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<h3><a href=\"https://reactjs.org/docs/higher-order-components.html#refs-arent-passed-through\"></a>Refs Aren’t Passed Through</h3>\n<p>While the convention for higher-order components is to pass through all props to the wrapped component, this does not work for refs. That’s because <code class=\"language-text\">ref</code> is not really a prop — like <code class=\"language-text\">key</code>, it’s handled specially by React. If you add a ref to an element whose component is the result of a HOC, the ref refers to an instance of the outermost container component, not the wrapped component.</p>\n<!--EndFragment-->"},{"url":"/docs/react/react-router/","relativePath":"docs/react/react-router/index.md","relativeDir":"docs/react/react-router","base":"index.md","name":"index","frontmatter":{"title":"React Router","template":"docs","excerpt":" full user interface that maps to the URL"},"html":"<h2>Main Concepts</h2>\n<p>This document is a deep dive into the core concepts behind routing as implemented in React Router. It's pretty long, so if you're looking for a more practical guide check out our <a href=\"https://reactrouter.com/docs/en/v6/getting-started/tutorial\">quick start tutorial</a>.</p>\n<p>You might be wondering what exactly React Router does. How can it help you build your app? What exactly is a <strong>router</strong>, anyway?</p>\n<p>If you've ever had any of these questions, or you'd just like to dig into the fundamental pieces of routing, you're in the right place. This document contains detailed explanations of all the core concepts behind routing as implemented in React Router.</p>\n<p>Please don't let this document overwhelm you! For everyday use, React Router is pretty simple. You don't need to go this deep to use it.</p>\n<p>React Router isn't just about matching a url to a function or component: it's about building a full user interface that maps to the URL, so it might have more concepts in it than you're used to. We'll go into detail on the three main jobs of React Router:</p>\n<ol>\n<li>Subscribing and manipulating the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-stack\">history stack</a></li>\n<li>Matching the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> to your <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">routes</a></li>\n<li>Rendering a nested UI from the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#matches\">route matches</a></li>\n</ol>\n<h2>Definitions</h2>\n<p>But first, some definitions! There are a lot of different ideas around routing from back and front end frameworks. Sometimes a word in one context might have different meaning than another.</p>\n<p>Here are some words we use a lot when we talk about React Router. The rest of this guide will go into more detail on each one.</p>\n<ul>\n<li><strong>URL</strong> - The URL in the address bar. A lot of people use the term \"URL\" and \"route\" interchangeably, but this is not a route in React Router, it's just a URL.</li>\n<li><strong>Location</strong> - This is a React Router specific object that is based on the built-in browser's <code class=\"language-text\">window.location</code> object. It represents \"where the user is at\". It's mostly an object representation of the URL but has a bit more to it than that.</li>\n<li><strong>Location State</strong> - A value that persists with a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a> that isn't encoded in the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>. Much like hash or search params (data encoded in the URL), but stored invisibly in the browser's memory.</li>\n<li><strong>History Stack</strong> - As the user navigates, the browser keeps track of each <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a> in a stack. If you click and hold the back button in a browser you can see the browser's history stack right there.</li>\n<li><strong>Client Side Routing (CSR)</strong> - A plain HTML document can link to other documents and the browser handles the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-stack\">history stack</a> itself. Client Side Routing enables developers to manipulate the browser history stack without making a document request to the server.</li>\n<li><strong>History</strong> - An object that allows React Router to subscribe to changes in the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> as well as providing APIs to manipulate the browser <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-stack\">history stack</a> programmatically.</li>\n<li><strong>History Action</strong> - One of <code class=\"language-text\">POP</code>, <code class=\"language-text\">PUSH</code>, or <code class=\"language-text\">REPLACE</code>. Users can arrive at a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> for one of these three reasons. A push when a new entry is added to the history stack (typically a link click or the programmer forced a navigation). A replace is similar except it replaces the current entry on the stack instead of pushing a new one. Finally, a pop happens when the user clicks the back or forward buttons in the browser chrome.</li>\n<li><strong>Segment</strong> - The parts of a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> or <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#path-pattern\">path pattern</a> between the <code class=\"language-text\">/</code> characters. For example, \"/users/123\" has two segments.</li>\n<li><strong>Path Pattern</strong> - These look like URLs but can have special characters for matching URLs to routes, like <strong>dynamic segments</strong> (<code class=\"language-text\">\"/users/:userId\"</code>) or <strong>star segments</strong> (<code class=\"language-text\">\"/docs/*\"</code>). They aren't URLs, they're patterns that React Router will match.</li>\n<li><strong>Dynamic Segment</strong> - A segment of a path pattern that is dynamic, meaning it can match any values in the segment. For example the pattern <code class=\"language-text\">/users/:userId</code> will match URLs like <code class=\"language-text\">/users/123</code></li>\n<li><strong>URL Params</strong> - The parsed values from the URL that matched a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#dynamic-segment\">dynamic segment</a>.</li>\n<li><strong>Router</strong> - Stateful, top-level component that makes all the other components and hooks work.</li>\n<li><strong>Route Config</strong> - A tree of <strong>routes objects</strong> that will be ranked and matched (with nesting) against the current location to create a branch of <strong>route matches</strong>.</li>\n<li><strong>Route</strong> - An object or Route Element typically with a shape of <code class=\"language-text\">{ path, element }</code> or <code class=\"language-text\">&lt;Route path element></code>. The <code class=\"language-text\">path</code> is a path pattern. When the path pattern matches the current URL, the element will be rendered.</li>\n<li><strong>Route Element</strong> - Or <code class=\"language-text\">&lt;Route></code>. This element's props are read to create a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route\">route</a> by <code class=\"language-text\">&lt;Routes></code>, but otherwise does nothing.</li>\n<li><strong>Nested Routes</strong> - Because routes can have children and each route defines a portion of the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> through <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#segment\">segments</a>, a single URL can match multiple routes in a nested \"branch\" of the tree. This enables automatic layout nesting through <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#outlet\">outlet</a>, <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#relative-links\">relative links</a>, and more.</li>\n<li><strong>Relative links</strong> - Links that don't start with <code class=\"language-text\">/</code> will inherit the closest route in which they are rendered. This makes it easy to link to deeper URLs without having to know and build up the entire path.</li>\n<li><strong>Match</strong> - An object that holds information when a route matches the URL, like the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url-params\">url params</a> and pathname that matched.</li>\n<li><strong>Matches</strong> - An array of routes (or branch of the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">route config</a>) that matches the current <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a>. This structure enables <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#nested-routes\">nested routes</a>.</li>\n<li><strong>Parent Route</strong> - A route with child routes.</li>\n<li><strong>Outlet</strong> - A component that renders the next match in a set of <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#match\">matches</a>.</li>\n<li><strong>Index Route</strong> - A child route with no path that renders in the parent's <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#outlet\">outlet</a> at the parent's <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>.</li>\n<li><strong>Layout Route</strong> - A <strong>parent route</strong> without a path, used exclusively for grouping child routes inside a specific layout.</li>\n</ul>\n<h2>History and Locations</h2>\n<p>Before React Router can do anything, it has to be able to subscribe to changes in the browser <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-stack\">history stack</a>.</p>\n<p>Browsers maintain their own history stack as the user navigates around. That's how the back and forward buttons can work. In a traditional website (HTML documents without JavaScript) the browser will make requests to the server every time the user clicks a link, submits a form, or clicks the back and forward buttons.</p>\n<p>For example, consider the user:</p>\n<ol>\n<li>clicks a link to <code class=\"language-text\">/dashboard</code></li>\n<li>clicks a link to <code class=\"language-text\">/accounts</code></li>\n<li>clicks a link to <code class=\"language-text\">/customers/123</code></li>\n<li>clicks the back button</li>\n<li>clicks a link to <code class=\"language-text\">/dashboard</code></li>\n</ol>\n<p>The history stack will change as follows where <strong>bold</strong> entries denote the current <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>:</p>\n<ol>\n<li><strong><code class=\"language-text\">/dashboard</code></strong></li>\n<li><code class=\"language-text\">/dashboard</code>, <strong><code class=\"language-text\">/accounts</code></strong></li>\n<li><code class=\"language-text\">/dashboard</code>, <code class=\"language-text\">/accounts</code>, <strong><code class=\"language-text\">/customers/123</code></strong></li>\n<li><code class=\"language-text\">/dashboard</code>, <strong><code class=\"language-text\">/accounts</code></strong>, <code class=\"language-text\">/customers/123</code></li>\n<li><code class=\"language-text\">/dashboard</code>, <code class=\"language-text\">/accounts</code>, <strong><code class=\"language-text\">/dashboard</code></strong></li>\n</ol>\n<h3>History Object</h3>\n<p>With <strong>client side routing</strong>, developers are able to manipulate the browser <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-stack\">history stack</a> programmatically. For example, we can write some code like this to change the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> without the browsers default behavior of making a request to the server:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;a\n  href=\"/contact\"\n  onClick={(event) => {\n    // stop the browser from changing the URL and requesting the new document\n    event.preventDefault();\n    // push an entry into the browser history stack and change the URL\n    window.history.pushState({}, undefined, \"/contact\");\n  }}\n/></code></pre></div>\n<p>For illustration only, don't use <code class=\"language-text\">window.history.pushState</code> directly in React Router</p>\n<p>This code changes the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> but doesn't do anything for the UI. We would need to write some more code that changed some state somewhere to get the UI to change to the contact page. The trouble is, the browser doesn't give us a way to \"listen to the URL\" and subscribe to changes like this.</p>\n<p>Well, that's not totally true. We can listen for changes to the URL via <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-actions\">pop</a> events:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">window.addEventListener(\"popstate\", () => {\n  // URL changed!\n});</code></pre></div>\n<p>But that only fires when the user clicks the back or forward buttons. There is no event for when the programmer called <code class=\"language-text\">window.history.pushState</code> or <code class=\"language-text\">window.history.replaceState</code>.</p>\n<p>That's where a React Router specific <code class=\"language-text\">history</code> object comes into play. It provides a way to \"listen for <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>\" changes whether the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-actions\">history action</a> is <strong>push</strong>, <strong>pop</strong>, or <strong>replace</strong>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let history = createBrowserHistory();\nhistory.listen(({ location, action }) => {\n  // this is called whenever new locations come in\n  // the action is POP, PUSH, or REPLACE\n});</code></pre></div>\n<p>Apps don't need to set up their own history objects--that's job of <code class=\"language-text\">&lt;Router></code>. It sets up one of these objects, subscribe to changes in the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-stack\">history stack</a>, and finally updates its state when the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> changes. This causes the app to re-render and the correct UI to display. The only thing it needs to put on state is a <code class=\"language-text\">location</code>, everything else works from that single object.</p>\n<h3>Locations</h3>\n<p>The browser has a location object on <code class=\"language-text\">window.location</code>. It tells you information about the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> but also has some methods to change it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">window.location.pathname; // /getting-started/concepts/\nwindow.location.hash; // #location\nwindow.location.reload(); // force a refresh w/ the server\n// and a lot more</code></pre></div>\n<p>For illustration. You don't typically work with <code class=\"language-text\">window.location</code> in a React Router app</p>\n<p>Instead of using <code class=\"language-text\">window.location</code>, React Router has the concept of a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a> that's patterned after <code class=\"language-text\">window.location</code> but is much simpler. It looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  pathname: \"/bbq/pig-pickins\",\n  search: \"?campaign=instagram\",\n  hash: \"#menu\",\n  state: null,\n  key: \"aefz24ie\"\n}</code></pre></div>\n<p>The first three: <code class=\"language-text\">{ pathname, search, hash }</code> are exactly like <code class=\"language-text\">window.location</code>. If you just add up the three you'll get the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> the user sees in the browser:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">location.pathname + location.search + location.hash;\n// /bbq/pig-pickins?campaign=instagram#menu</code></pre></div>\n<p>The last two, <code class=\"language-text\">{ state, key }</code>, are React Router specific.</p>\n<p><strong>Location Pathname</strong></p>\n<p>This is the part of <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> after the origin, so for <code class=\"language-text\">https://example.com/teams/hotspurs</code> the pathname is <code class=\"language-text\">/teams/hostspurs</code>. This is the only part of the location that routes match against.</p>\n<p><strong>Location Search</strong></p>\n<p>People use a lot of different terms for this part of the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>:</p>\n<ul>\n<li>location search</li>\n<li>search params</li>\n<li>URL search params</li>\n<li>query string</li>\n</ul>\n<p>In React Router we call it the \"location search\". However, location search is a serialized version of <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\"><code class=\"language-text\">URLSearchParams</code></a>. So sometimes we might call it \"URL search params\" as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// given a location like this:\nlet location = {\n  pathname: \"/bbq/pig-pickins\",\n  search: \"?campaign=instagram&amp;popular=true\",\n  hash: \"\",\n  state: null,\n  key: \"aefz24ie\",\n};\n\n// we can turn the location.search into URLSearchParams\nlet params = new URLSearchParams(location.search);\nparams.get(\"campaign\"); // \"instagram\"\nparams.get(\"popular\"); // \"true\"\nparams.toString(); // \"campaign=instagram&amp;popular=true\",</code></pre></div>\n<p>When being precise, refer to the serialized string version as \"search\" and the parsed version as \"search params\", but it's common to use the terms interchangeably when precision isn't important.</p>\n<p><strong>Location Hash</strong></p>\n<p>Hashes in URLs indicate a scroll position <em>on the current page</em>. Before the <code class=\"language-text\">window.history.pushState</code> API was introduced, web developers did client side routing exclusively with the hash portion of the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>, it was the only part we could manipulate without making a new request to the server. However, today we can use it for its designed purpose.</p>\n<p><strong>Location State</strong></p>\n<p>You may have wondered why the <code class=\"language-text\">window.history.pushState()</code> API is called \"push state\". State? Aren't we just changing the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>? Shouldn't it be <code class=\"language-text\">history.push</code>? Well, we weren't in the room when the API was designed, so we're not sure why \"state\" was the focus, but it is a cool feature of browsers nonetheless.</p>\n<p>Browsers let us persist information about a transition by passing a value to <code class=\"language-text\">pushState</code>. When the user clicks back, the value on <code class=\"language-text\">history.state</code> changes to whatever was \"pushed\" before.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">window.history.pushState(\"look ma!\", undefined, \"/contact\");\nwindow.history.state; // \"look ma!\"\n// user clicks back\nwindow.history.state; // undefined\n// user clicks forward\nwindow.history.state; // \"look ma!\"</code></pre></div>\n<p>For illustration. You don't read <code class=\"language-text\">history.state</code> directly in React Router apps</p>\n<p>React Router takes advantage of this browser feature, abstracts it a bit, and surfaces the values on the <code class=\"language-text\">location</code> instead of <code class=\"language-text\">history</code>.</p>\n<p>You can think about <code class=\"language-text\">location.state</code> just like <code class=\"language-text\">location.hash</code> or <code class=\"language-text\">location.search</code> except instead of putting the values in the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> it's hidden--like a super secret piece of the URL only the programmer knows about.</p>\n<p>A couple of great use-cases for location state are:</p>\n<ul>\n<li>Telling the next page where the user came from and branching the UI. The most popular implementation here is showing a record in a modal if the user clicked on an item in a grid view, but if they show up to the URL directly, show the record in its own layout (pinterest, old instagram).</li>\n<li>Sending a partial record from a list to the next screen so it can render the partial data immediately and then fetching the rest of the data afterward.</li>\n</ul>\n<p>You set location state in two ways: on <code class=\"language-text\">&lt;Link></code> or <code class=\"language-text\">navigate</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Link to=\"/pins/123\" state={{ fromDashboard: true }} />;\n\nlet navigate = useNavigate();\nnavigate(\"/users/123\", { state: partialUser });</code></pre></div>\n<p>And on the next page you can access it with <code class=\"language-text\">useLocation</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let location = useLocation();\nlocation.state;</code></pre></div>\n<p>Location state values will get serialized, so something like <code class=\"language-text\">new Date()</code> will be turned into a string.</p>\n<p><strong>Location Key</strong></p>\n<p>Each location gets a unique key. This is useful for advanced cases like location-based scroll management, client side data caching, and more. Because each new location gets a unique key, you can build abstractions that store information in a plain object, <code class=\"language-text\">new Map()</code>, or even <code class=\"language-text\">locationStorage</code>.</p>\n<p>For example, a very basic client side data cache could store values by location key (and the fetch <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>) and skip fetching the data when the user clicks back into it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let cache = new Map();\n\nfunction useFakeFetch(URL) {\n  let location = useLocation();\n  let cacheKey = location.key + URL;\n  let cached = cache.get(cacheKey);\n\n  let [data, setData] = useState(() => {\n    // initialize from the cache\n    return cached || null;\n  });\n\n  let [state, setState] = useState(() => {\n    // avoid the fetch if cached\n    return cached ? \"done\" : \"loading\";\n  });\n\n  useEffect(() => {\n    if (state === \"loading\") {\n      let controller = new AbortController();\n      fetch(URL, { signal: controller.signal })\n        .then((res) => res.json())\n        .then((data) => {\n          if (controller.signal.aborted) return;\n          // set the cache\n          cache.set(cacheKey, data);\n          setData(data);\n        });\n      return () => controller.abort();\n    }\n  }, [state, cacheKey]);\n\n  useEffect(() => {\n    setState(\"loading\");\n  }, [URL]);\n\n  return data;\n}</code></pre></div>\n<h2>Matching</h2>\n<p>On the initial render, and when the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-stack\">history stack</a> changes, React Router will match the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a> against your <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">route config</a> to come up with a set of <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#match\">matches</a> to render.</p>\n<h3>Defining Routes</h3>\n<p>A route config is a tree of <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route\">routes</a> that looks something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Routes>\n  &lt;Route path=\"/\" element={&lt;App />}>\n    &lt;Route index element={&lt;Home />} />\n    &lt;Route path=\"teams\" element={&lt;Teams />}>\n      &lt;Route path=\":teamId\" element={&lt;Team />} />\n      &lt;Route path=\":teamId/edit\" element={&lt;EditTeam />} />\n      &lt;Route path=\"new\" element={&lt;NewTeamForm />} />\n      &lt;Route index element={&lt;LeagueStandings />} />\n    &lt;/Route>\n  &lt;/Route>\n  &lt;Route element={&lt;PageLayout />}>\n    &lt;Route path=\"/privacy\" element={&lt;Privacy />} />\n    &lt;Route path=\"/tos\" element={&lt;Tos />} />\n  &lt;/Route>\n  &lt;Route path=\"contact-us\" element={&lt;Contact />} />\n&lt;/Routes></code></pre></div>\n<p>The <code class=\"language-text\">&lt;Routes></code> component recurses through its <code class=\"language-text\">props.children</code>, strips their props, and generates an object like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let routes = [\n  {\n    element: &lt;App />,\n    path: \"/\",\n    children: [\n      {\n        index: true,\n        element: &lt;Home />,\n      },\n      {\n        path: \"teams\",\n        element: &lt;Teams />,\n        children: [\n          {\n            index: true,\n            element: &lt;LeagueStandings />,\n          },\n          {\n            path: \":teamId\",\n            element: &lt;Team />,\n          },\n          {\n            path: \":teamId/edit\",\n            element: &lt;EditTeam />,\n          },\n          {\n            path: \"new\",\n            element: &lt;NewTeamForm />,\n          },\n        ],\n      },\n    ],\n  },\n  {\n    element: &lt;PageLayout />,\n    children: [\n      {\n        element: &lt;Privacy />,\n        path: \"/privacy\",\n      },\n      {\n        element: &lt;Tos />,\n        path: \"/tos\",\n      },\n    ],\n  },\n  {\n    element: &lt;Contact />,\n    path: \"/contact-us\",\n  },\n];</code></pre></div>\n<p>In fact, instead of <code class=\"language-text\">&lt;Routes></code> you can use the hook <code class=\"language-text\">useRoutes(routesGoHere)</code> instead. That's all <code class=\"language-text\">&lt;Routes></code> is doing.</p>\n<p>As you can see, routes can define multiple <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#segment\">segments</a> like <code class=\"language-text\">:teamId/edit</code>, or just one like <code class=\"language-text\">:teamId</code>. All of the segments down a branch of the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">route config</a> are added together to create a final <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#path-pattern\">path pattern</a> for a route.</p>\n<h3>Match Params</h3>\n<p>Note the <code class=\"language-text\">:teamId</code> segments. This is what we call a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#dynamic-segment\">dynamic segment</a> of the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#path-pattern\">path pattern</a>, meaning it doesn't match the URL statically (the actual characters) but it matches it dynamically. Any value can fill in for <code class=\"language-text\">:teamId</code>. Both <code class=\"language-text\">/teams/123</code> or <code class=\"language-text\">/teams/cupcakes</code> will match. We call the parsed values <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url-params\">URL params</a>. So in this case our <code class=\"language-text\">teamId</code> param would be <code class=\"language-text\">\"123\"</code> or <code class=\"language-text\">\"cupcakes\"</code>. We'll see how to use them in your app in the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#rendering\">Rendering</a> section.</p>\n<h3>Ranking Routes</h3>\n<p>If we add up all the segments of all the branches of our <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">route config</a>, we end up with the following path patterns that our app responds to:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[\n  \"/\",\n  \"/teams\",\n  \"/teams/:teamId\",\n  \"/teams/:teamId/edit\",\n  \"/teams/new\",\n  \"/privacy\",\n  \"/tos\",\n  \"/contact-us\",\n];</code></pre></div>\n<p>Now this is where things get really interesting. Consider the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> <code class=\"language-text\">/teams/new</code>. Which pattern in that list matches the URL?</p>\n<p>That's right, two of them!</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/teams/new\n/teams/:teamId</code></pre></div>\n<p>React Router has to make a decision here, there can be only one. Many routers, both client side and server side, will simply process the patterns in the order in which they were defined. First to match wins. In this case we would match <code class=\"language-text\">/</code> and render the <code class=\"language-text\">&lt;Home/></code> component. Definitely not what we wanted. These kinds of routers require us to order our routes perfectly to get the expected result. This is how React Router has worked up until v6, but now it's much smarter.</p>\n<p>Looking at those patterns, you intuitively know that we want <code class=\"language-text\">/teams/new</code> to match the URL <code class=\"language-text\">/teams/new</code>. It's a perfect match! React Router also knows that. When matching, it will rank your routes according the number of segments, static segments, dynamic segments, star patterns, etc. and pick the most specific match. You'll never have to think about ordering your routes.</p>\n<h3>Pathless Routes</h3>\n<p>You may have noticed the weird routes from earlier:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Route index element={&lt;Home />} />\n&lt;Route index element={&lt;LeagueStandings />} />\n&lt;Route element={&lt;PageLayout />} /></code></pre></div>\n<p>They don't even have a path, how can they be a route? This is where the word \"route\" in React Router is used pretty loosely. <code class=\"language-text\">&lt;Home/></code> and <code class=\"language-text\">&lt;LeagueStandings/></code> are <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#index-route\">index routes</a> and <code class=\"language-text\">&lt;PageLayout/></code> is a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#layout-route\">layout route</a>. We'll discuss how they work in the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#rendering\">Rendering</a> section. Neither really has much to do with matching.</p>\n<h3>Route Matches</h3>\n<p>When a route matches the URL, it's represented by a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#match\">match</a> object. A match for <code class=\"language-text\">&lt;Route path=\":teamId\" element={&lt;Team/>}/></code> would look something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  pathname: \"/teams/firebirds\",\n  params: {\n    teamId: \"firebirds\"\n  },\n  route: {\n    element: &lt;Team />,\n    path: \":teamId\"\n  }\n}</code></pre></div>\n<p><code class=\"language-text\">pathname</code> holds the portion of the URL that matched this route (in our case it's all of it). <code class=\"language-text\">params</code> holds the parsed values from any <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#dynamic-segment\">dynamic segments</a> that matched. Note that the param's object keys map directly to the name of the segment: <code class=\"language-text\">:teamId</code> becomes <code class=\"language-text\">params.teamId</code>.</p>\n<p>Because our routes are a tree, a single URL can match an entire branch of the tree. Consider the URL <code class=\"language-text\">/teams/firebirds</code>, it would be the following route branch:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Routes>\n  &lt;Route path=\"/\" element={&lt;App />}>\n    &lt;Route index element={&lt;Home />} />\n    &lt;Route path=\"teams\" element={&lt;Teams />}>\n      &lt;Route path=\":teamId\" element={&lt;Team />} />\n      &lt;Route path=\":teamId/edit\" element={&lt;EditTeam />} />\n      &lt;Route path=\"new\" element={&lt;NewTeamForm />} />\n      &lt;Route index element={&lt;LeagueStandings />} />\n    &lt;/Route>\n  &lt;/Route>\n  &lt;Route element={&lt;PageLayout />}>\n    &lt;Route path=\"/privacy\" element={&lt;Privacy />} />\n    &lt;Route path=\"/tos\" element={&lt;Tos />} />\n  &lt;/Route>\n  &lt;Route path=\"contact-us\" element={&lt;Contact />} />\n&lt;/Routes></code></pre></div>\n<p>React Router will create an array of <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#match\">matches</a> from these routes and the url so it can render a nested UI that matches the route nesting.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[\n  {\n    pathname: \"/\",\n    params: null,\n    route: {\n      element: &lt;App />,\n      path: \"/\",\n    },\n  },\n  {\n    pathname: \"/teams\",\n    params: null,\n    route: {\n      element: &lt;Teams />,\n      path: \"teams\",\n    },\n  },\n  {\n    pathname: \"/teams/firebirds\",\n    params: {\n      teamId: \"firebirds\",\n    },\n    route: {\n      element: &lt;Team />,\n      path: \":teamId\",\n    },\n  },\n];</code></pre></div>\n<h2>Rendering</h2>\n<p>The final concept is rendering. Consider that the entry to your app looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(\n  &lt;BrowserRouter>\n    &lt;Routes>\n      &lt;Route path=\"/\" element={&lt;App />}>\n        &lt;Route index element={&lt;Home />} />\n        &lt;Route path=\"teams\" element={&lt;Teams />}>\n          &lt;Route path=\":teamId\" element={&lt;Team />} />\n          &lt;Route path=\"new\" element={&lt;NewTeamForm />} />\n          &lt;Route index element={&lt;LeagueStandings />} />\n        &lt;/Route>\n      &lt;/Route>\n      &lt;Route element={&lt;PageLayout />}>\n        &lt;Route path=\"/privacy\" element={&lt;Privacy />} />\n        &lt;Route path=\"/tos\" element={&lt;Tos />} />\n      &lt;/Route>\n      &lt;Route path=\"contact-us\" element={&lt;Contact />} />\n    &lt;/Routes>\n  &lt;/BrowserRouter>,\n  document.getElementById(\"root\")\n);</code></pre></div>\n<p>Let's use the <code class=\"language-text\">/teams/firebirds</code> URL as an example again. <code class=\"language-text\">&lt;Routes></code> will match the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a> to your <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">route config</a>, get a set of <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#match\">matches</a>, and then render a React element tree like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;App>\n  &lt;Teams>\n    &lt;Team />\n  &lt;/Teams>\n&lt;/App></code></pre></div>\n<p>Each match rendered inside the parent route's element is a really powerful abstraction. Most websites and apps share this characteristic: boxes inside of boxes inside of boxes, each with a navigation section that changes a child section of the page.</p>\n<h3>Outlets</h3>\n<p>This nested element tree won't happen automatically. <code class=\"language-text\">&lt;Routes></code> will render the first match's element for you (In our case that's <code class=\"language-text\">&lt;App/></code>). The next match's element is <code class=\"language-text\">&lt;Teams></code>. In order to render that, <code class=\"language-text\">App</code> needs to render an <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#outlet\">outlet</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function App() {\n  return (\n    &lt;div>\n      &lt;GlobalNav />\n      &lt;Outlet />\n      &lt;GlobalFooter />\n    &lt;/div>\n  );\n}</code></pre></div>\n<p>The <code class=\"language-text\">Outlet</code> component will always render the next match. That means <code class=\"language-text\">&lt;Teams></code> also needs an outlet to render <code class=\"language-text\">&lt;Team/></code>.</p>\n<p>If the URL were <code class=\"language-text\">/contact-us</code>, the element tree would change to:</p>\n<p>Because the contact form is not under the main <code class=\"language-text\">&lt;App></code> route.</p>\n<p>If the URL were <code class=\"language-text\">/teams/firebirds/edit</code>, the element tree would change to:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;App>\n  &lt;Teams>\n    &lt;EditTeam />\n  &lt;/Teams>\n&lt;/App></code></pre></div>\n<p>The outlet swaps out the child for the new child that matches, but the parent layout persists. It's subtle but very effective at cleaning up your components.</p>\n<h3>Index Routes</h3>\n<p>Remember the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">route config</a> for <code class=\"language-text\">/teams</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Route path=\"teams\" element={&lt;Teams />}>\n  &lt;Route path=\":teamId\" element={&lt;Team />} />\n  &lt;Route path=\"new\" element={&lt;NewTeamForm />} />\n  &lt;Route index element={&lt;LeagueStandings />} />\n&lt;/Route></code></pre></div>\n<p>If the URL were <code class=\"language-text\">/teams/firebirds</code>, the element tree would be:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;App>\n  &lt;Teams>\n    &lt;Team />\n  &lt;/Teams>\n&lt;/App></code></pre></div>\n<p>But if the URL were <code class=\"language-text\">/teams</code>, the element tree would be:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;App>\n  &lt;Teams>\n    &lt;LeagueStandings />\n  &lt;/Teams>\n&lt;/App></code></pre></div>\n<p>League standings? How the heck did <code class=\"language-text\">&lt;Route index element={&lt;LeagueStandings>}/></code> pop in there? It doesn't even have a path! The reason is that it's an <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#index-route\">index route</a>. Index routes render in their parent route's <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#outlet\">outlet</a> at the parent route's path.</p>\n<p>Think of it this way, if you're not at one of the child routes' paths, the <code class=\"language-text\">&lt;Outlet></code> will render nothing in the UI:</p>\n<p>If all the teams are in a list on the left then an empty outlet means you've got a blank page on the right! Your UI needs something to fill the space: index routes to the rescue.</p>\n<p>Another way to think of an index route is that it's the default child route when the parent matches but none of its children do.</p>\n<p>Depending on the user interface, you might not need an index route, but if there is any sort of persistent navigation in the parent route you'll most likely want index route to fill the space when the user hasn't clicked one of the items yet.</p>\n<h3>Layout Routes</h3>\n<p>Here's a part of our route config we haven't matched yet: <code class=\"language-text\">/privacy</code>. Let's look at the route config again, highlighting the matched routes:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Routes>\n  &lt;Route path=\"/\" element={&lt;App />}>\n    &lt;Route index element={&lt;Home />} />\n    &lt;Route path=\"teams\" element={&lt;Teams />}>\n      &lt;Route path=\":teamId\" element={&lt;Team />} />\n      &lt;Route path=\":teamId/edit\" element={&lt;EditTeam />} />\n      &lt;Route path=\"new\" element={&lt;NewTeamForm />} />\n      &lt;Route index element={&lt;LeagueStandings />} />\n    &lt;/Route>\n  &lt;/Route>\n  &lt;Route element={&lt;PageLayout />}>\n    &lt;Route path=\"/privacy\" element={&lt;Privacy />} />\n    &lt;Route path=\"/tos\" element={&lt;Tos />} />\n  &lt;/Route>\n  &lt;Route path=\"contact-us\" element={&lt;Contact />} />\n&lt;/Routes></code></pre></div>\n<p>And the resulting element tree rendered will be:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;App>\n  &lt;PageLayout>\n    &lt;Privacy />\n  &lt;/PageLayout>\n&lt;/App></code></pre></div>\n<p>The <code class=\"language-text\">PageLayout</code> route is admittedly weird. We call it a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#layout-route\">layout route</a> because it doesn't participate in the matching at all (though its children do). It only exists to make wrapping multiple child routes in the same layout simpler. If we didn't allow this then you'd have to handle layouts in two different ways: sometimes your routes do it for you, sometimes you do it manually with lots of layout component repetition throughout your app:</p>\n<p>You can do it like this, but we recommend using a layout route</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Routes>\n  &lt;Route path=\"/\" element={&lt;App />}>\n    &lt;Route index element={&lt;Home />} />\n    &lt;Route path=\"teams\" element={&lt;Teams />}>\n      &lt;Route path=\":teamId\" element={&lt;Team />} />\n      &lt;Route path=\":teamId/edit\" element={&lt;EditTeam />} />\n      &lt;Route path=\"new\" element={&lt;NewTeamForm />} />\n      &lt;Route index element={&lt;LeagueStandings />} />\n    &lt;/Route>\n  &lt;/Route>\n  &lt;Route\n    path=\"/privacy\"\n    element={\n      &lt;PageLayout>\n        &lt;Privacy />\n      &lt;/PageLayout>\n    }\n  />\n  &lt;Route\n    path=\"/tos\"\n    element={\n      &lt;PageLayout>\n        &lt;Tos />\n      &lt;/PageLayout>\n    }\n  />\n  &lt;Route path=\"contact-us\" element={&lt;Contact />} />\n&lt;/Routes></code></pre></div>\n<p>So, yeah, the semantics of a layout \"route\" is a bit silly since it has nothing to do with the URL matching, but it's just too convenient to disallow.</p>\n<h2>Navigating</h2>\n<p>When the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a> changes we call that a \"navigation\". There are two ways to navigate in React Router:</p>\n<ul>\n<li><code class=\"language-text\">&lt;Link></code></li>\n<li><code class=\"language-text\">navigate</code></li>\n</ul>\n<h3>Link</h3>\n<p>This is the primary means of navigation. Rendering a <code class=\"language-text\">&lt;Link></code> allows the user to change the URL when they click it. React Router will prevent the browser's default behavior and tell the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history\">history</a> to push a new entry into the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history-stack\">history stack</a>. The <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a> changes and the new <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#match\">matches</a> will render.</p>\n<p>However, links are accessible in that they:</p>\n<ul>\n<li>Still render a <code class=\"language-text\">&lt;a href></code> so all default accessibility concerns are met (like keyboard, focusability, SEO, etc.)</li>\n<li>Don't prevent the browser's default behavior if it's a right click or command/control click to \"open in new tab\"</li>\n</ul>\n<p><a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#nested-routes\">Nested routes</a> aren't just about rendering layouts; they also enable \"relative links\". Consider our <code class=\"language-text\">teams</code> route from before:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Route path=\"teams\" element={&lt;Teams />}>\n  &lt;Route path=\":teamId\" element={&lt;Team />} />\n&lt;/Route></code></pre></div>\n<p>The <code class=\"language-text\">&lt;Teams></code> component can render links like:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Link to=\"psg\" />\n&lt;Link to=\"new\" /></code></pre></div>\n<p>The full path it links to will be <code class=\"language-text\">/teams/psg</code> and <code class=\"language-text\">/teams/new</code>. They inherit the route within which they are rendered. This makes it so your route components don't have to really know anything about the rest of the routes in the app. A very large amount of links just go one more <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#segment\">segment</a> deeper. You can rearrange your whole <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">route config</a> and these links will likely still work just fine. This is very valuable when building out a site in the beginning and the designs and layouts are shifting around.</p>\n<h3>Navigate Function</h3>\n<p>This function is returned from the <code class=\"language-text\">useNavigate</code> hook and allows you, the programmer, to change the URL whenever you want. You could do it on a timeout:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let navigate = useNavigate();\nuseEffect(() => {\n  setTimeout(() => {\n    navigate(\"/logout\");\n  }, 30000);\n}, []);</code></pre></div>\n<p>Or after a form is submitted:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;form onSubmit={event => {\n  event.preventDefault();\n  let data = new FormData(event.target)\n  let urlEncoded = new URLSearchParams(data)\n  navigate(\"/create\", { state: urlEncoded })\n}}></code></pre></div>\n<p>Like <code class=\"language-text\">Link</code>, <code class=\"language-text\">navigate</code> works with nested \"to\" values as well.</p>\n<p>You should have a good reason to use <code class=\"language-text\">navigate</code> instead of <code class=\"language-text\">&lt;Link></code>. This makes us very sad:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;li onClick={() => navigate(\"/somewhere\")} /></code></pre></div>\n<p>Aside from links and forms, very few interactions should change the URL because it introduces complexity around accessibility and user expectations.</p>\n<h2>Data Access</h2>\n<p>Finally, an application is going to want to ask React Router for a few pieces of information in order to build out the full UI. For this, React Router has a pile of hooks</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let location = useLocation();\nlet urlParams = useParams();\nlet [urlSearchParams] = useSearchParams();</code></pre></div>\n<h2>Review</h2>\n<p>Let's put it all together from the top!</p>\n<ol>\n<li>\n<p>You render your app:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(\n  &lt;BrowserRouter>\n    &lt;Routes>\n      &lt;Route path=\"/\" element={&lt;App />}>\n        &lt;Route index element={&lt;Home />} />\n        &lt;Route path=\"teams\" element={&lt;Teams />}>\n          &lt;Route path=\":teamId\" element={&lt;Team />} />\n          &lt;Route path=\"new\" element={&lt;NewTeamForm />} />\n          &lt;Route index element={&lt;LeagueStandings />} />\n        &lt;/Route>\n      &lt;/Route>\n      &lt;Route element={&lt;PageLayout />}>\n        &lt;Route path=\"/privacy\" element={&lt;Privacy />} />\n        &lt;Route path=\"/tos\" element={&lt;Tos />} />\n      &lt;/Route>\n      &lt;Route path=\"contact-us\" element={&lt;Contact />} />\n    &lt;/Routes>\n  &lt;/BrowserRouter>,\n  document.getElementById(\"root\")\n);</code></pre></div>\n</li>\n<li><code class=\"language-text\">&lt;BrowserRouter></code> creates a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history\">history</a>, puts the initial <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a> in to state, and subscribes to the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#url\">URL</a>.</li>\n<li><code class=\"language-text\">&lt;Routes></code> recurses it's <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#child-route\">child routes</a> to build a <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#route-config\">route config</a>, matches those routes against the <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#location\">location</a>, creates some route <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#match\">matches</a>, and renders the first match's route element.</li>\n<li>You render an <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#outlet\"><code class=\"language-text\">&lt;Outlet/></code></a> in each <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#parent-route\">parent route</a>.</li>\n<li>The outlets render the next match in the route <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#match\">matches</a>.</li>\n<li>The user clicks a link</li>\n<li>The link calls <code class=\"language-text\">navigate()</code></li>\n<li>The <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts#history\">history</a> changes the URL and notifies <code class=\"language-text\">&lt;BrowserRouter></code>.</li>\n<li><code class=\"language-text\">&lt;BrowserRouter></code> rerenders, start over at (2)!</li>\n</ol>\n<p>That's it! We hope this guide has helped you gain a deeper understanding of the main concepts in React Router.</p>\n<p>Url: <a href=\"https://reactrouter.com/docs/en/v6/getting-started/concepts\">https://reactrouter.com/docs/en/v6/getting-started/concepts</a></p>"},{"url":"/docs/python/python-modules/","relativePath":"docs/python/python-modules/index.md","relativeDir":"docs/python/python-modules","base":"index.md","name":"index","frontmatter":{"title":"Python Modules","template":"docs","excerpt":"If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost"},"html":"<!--StartFragment-->\n<h1>6. Modules<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#modules\" title=\"Permalink to this headline\"></a></h1>\n<p>If you quit from the Python interpreter and enter it again, the definitions you have made (functions and variables) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a <em>script</em>. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program.</p>\n<p>To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a <em>module</em>; definitions from a module can be <em>imported</em> into other modules or into the <em>main</em> module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).</p>\n<p>A module is a file containing Python definitions and statements. The file name is the module name with the suffix <code class=\"language-text\">.py</code> appended. Within a module, the module’s name (as a string) is available as the value of the global variable <code class=\"language-text\">__name__</code>. For instance, use your favorite text editor to create a file called <code class=\"language-text\">fibo.py</code> in the current directory with the following contents:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Fibonacci numbers module</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token comment\"># write Fibonacci series up to n</span>\n    a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">while</span> a <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span>\n        a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> b<span class=\"token punctuation\">,</span> a<span class=\"token operator\">+</span>b\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">fib2</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>   <span class=\"token comment\"># return Fibonacci series up to n</span>\n    result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n    a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">while</span> a <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">:</span>\n        result<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span>\n        a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> b<span class=\"token punctuation\">,</span> a<span class=\"token operator\">+</span>b\n    <span class=\"token keyword\">return</span> result</code></pre></div>\n<p>Now enter the Python interpreter and import this module with the following command:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> fibo.fib(1000)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987\n>>> fibo.fib2(100)\n[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\n>>> fibo.__name__\n'fibo'</code></pre></div>\n<p>This does not enter the names of the functions defined in <code class=\"language-text\">fibo</code> directly in the current symbol table; it only enters the module name <code class=\"language-text\">fibo</code> there. Using the module name you can access the functions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> fib = fibo.fib\n>>> fib(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<p>If you intend to use a function often you can assign it to a local name:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> from fibo import fib, fib2\n>>> fib(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<h2>6.1. More on Modules<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#more-on-modules\" title=\"Permalink to this headline\"></a></h2>\n<p>A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the <em>first</em> time the module name is encountered in an import statement. <a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#id2\">1</a> (They are also run if the file is executed as a script.)</p>\n<p>Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. Thus, the author of a module can use global variables in the module without worrying about accidental clashes with a user’s global variables. On the other hand, if you know what you are doing you can touch a module’s global variables with the same notation used to refer to its functions, <code class=\"language-text\">modname.itemname</code>.</p>\n<p>Modules can import other modules. It is customary but not required to place all <a href=\"https://docs.python.org/3/reference/simple_stmts.html#import\"><code class=\"language-text\">import</code></a> statements at the beginning of a module (or script, for that matter). The imported module names are placed in the importing module’s global symbol table.</p>\n<p>There is a variant of the <a href=\"https://docs.python.org/3/reference/simple_stmts.html#import\"><code class=\"language-text\">import</code></a> statement that imports names from a module directly into the importing module’s symbol table. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> from fibo import *\n>>> fib(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<p>This does not introduce the module name from which the imports are taken in the local symbol table (so in the example, <code class=\"language-text\">fibo</code> is not defined).</p>\n<p>There is even a variant to import all names that a module defines:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import fibo as fib\n>>> fib.fib(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<p>This imports all names except those beginning with an underscore (<code class=\"language-text\">_</code>). In most cases Python programmers do not use this facility since it introduces an unknown set of names into the interpreter, possibly hiding some things you have already defined.</p>\n<p>Note that in general the practice of importing <code class=\"language-text\">*</code> from a module or package is frowned upon, since it often causes poorly readable code. However, it is okay to use it to save typing in interactive sessions.</p>\n<p>If the module name is followed by <code class=\"language-text\">as</code>, then the name following <code class=\"language-text\">as</code> is bound directly to the imported module.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> from fibo import fib as fibonacci\n>>> fibonacci(500)\n0 1 1 2 3 5 8 13 21 34 55 89 144 233 377</code></pre></div>\n<p>This is effectively importing the module in the same way that <code class=\"language-text\">import fibo</code> will do, with the only difference of it being available as <code class=\"language-text\">fib</code>.</p>\n<p>It can also be used when utilising <a href=\"https://docs.python.org/3/reference/simple_stmts.html#from\"><code class=\"language-text\">from</code></a> with similar effects:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Note</p>\n<p>For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter – or, if it’s just one module you want to test interactively, use <a href=\"https://docs.python.org/3/library/importlib.html#importlib.reload\" title=\"importlib.reload\"><code class=\"language-text\">importlib.reload()</code></a>, e.g. <code class=\"language-text\">import importlib; importlib.reload(modulename)</code>.</p>\n<h3>6.1.1. Executing modules as scripts<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#executing-modules-as-scripts\" title=\"Permalink to this headline\">¶</a></h3>\n<p>When you run a Python module with</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">python fibo.py &lt;arguments></code></pre></div>\n<p>the code in the module will be executed, just as if you imported it, but with the <code class=\"language-text\">__name__</code> set to <code class=\"language-text\">\"__main__\"</code>. That means that by adding this code at the end of your module:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if __name__ == \"__main__\":\n    import sys\n    fib(int(sys.argv[1]))</code></pre></div>\n<p>you can make the file usable as a script as well as an importable module, because the code that parses the command line only runs if the module is executed as the “main” file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ python fibo.py 50\n0 1 1 2 3 5 8 13 21 34</code></pre></div>\n<p>If the module is imported, the code is not run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import fibo\n>>></code></pre></div>\n<p>This is often used either to provide a convenient user interface to a module, or for testing purposes (running the module as a script executes a test suite).</p>\n<h3>6.1.2. The Module Search Path<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#the-module-search-path\" title=\"Permalink to this headline\">¶</a></h3>\n<p>When a module named <code class=\"language-text\">spam</code> is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named <code class=\"language-text\">spam.py</code> in a list of directories given by the variable <a href=\"https://docs.python.org/3/library/sys.html#sys.path\" title=\"sys.path\"><code class=\"language-text\">sys.path</code></a>. <a href=\"https://docs.python.org/3/library/sys.html#sys.path\" title=\"sys.path\"><code class=\"language-text\">sys.path</code></a> is initialized from these locations:</p>\n<ul>\n<li>The directory containing the input script (or the current directory when no file is specified).</li>\n<li><a href=\"https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH\"><code class=\"language-text\">PYTHONPATH</code></a> (a list of directory names, with the same syntax as the shell variable <code class=\"language-text\">PATH</code>).</li>\n<li>The installation-dependent default.</li>\n</ul>\n<p>Note</p>\n<p>On file systems which support symlinks, the directory containing the input script is calculated after the symlink is followed. In other words the directory containing the symlink is <strong>not</strong> added to the module search path.</p>\n<p>After initialization, Python programs can modify <a href=\"https://docs.python.org/3/library/sys.html#sys.path\" title=\"sys.path\"><code class=\"language-text\">sys.path</code></a>. The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended. See section <a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#tut-standardmodules\">Standard Modules</a> for more information.</p>\n<h3>6.1.3. “Compiled” Python files<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#compiled-python-files\" title=\"Permalink to this headline\">¶</a></h3>\n<p>To speed up loading modules, Python caches the compiled version of each module in the <code class=\"language-text\">__pycache__</code> directory under the name <code class=\"language-text\">module.version.pyc</code>, where the version encodes the format of the compiled file; it generally contains the Python version number. For example, in CPython release 3.3 the compiled version of spam.py would be cached as <code class=\"language-text\">__pycache__/spam.cpython-33.pyc</code>. This naming convention allows compiled modules from different releases and different versions of Python to coexist.</p>\n<p>Python checks the modification date of the source against the compiled version to see if it’s out of date and needs to be recompiled. This is a completely automatic process. Also, the compiled modules are platform-independent, so the same library can be shared among systems with different architectures.</p>\n<p>Python does not check the cache in two circumstances. First, it always recompiles and does not store the result for the module that’s loaded directly from the command line. Second, it does not check the cache if there is no source module. To support a non-source (compiled only) distribution, the compiled module must be in the source directory, and there must not be a source module.</p>\n<p>Some tips for experts:</p>\n<ul>\n<li>You can use the <a href=\"https://docs.python.org/3/using/cmdline.html#cmdoption-o\"><code class=\"language-text\">-O</code></a> or <a href=\"https://docs.python.org/3/using/cmdline.html#cmdoption-oo\"><code class=\"language-text\">-OO</code></a> switches on the Python command to reduce the size of a compiled module. The <code class=\"language-text\">-O</code> switch removes assert statements, the <code class=\"language-text\">-OO</code> switch removes both assert statements and __doc__ strings. Since some programs may rely on having these available, you should only use this option if you know what you’re doing. “Optimized” modules have an <code class=\"language-text\">opt-</code> tag and are usually smaller. Future releases may change the effects of optimization.</li>\n<li>A program doesn’t run any faster when it is read from a <code class=\"language-text\">.pyc</code> file than when it is read from a <code class=\"language-text\">.py</code> file; the only thing that’s faster about <code class=\"language-text\">.pyc</code> files is the speed with which they are loaded.</li>\n<li>The module <a href=\"https://docs.python.org/3/library/compileall.html#module-compileall\" title=\"compileall: Tools for byte-compiling all Python source files in a directory tree.\"><code class=\"language-text\">compileall</code></a> can create .pyc files for all modules in a directory.</li>\n<li>There is more detail on this process, including a flow chart of the decisions, in <strong><a href=\"https://www.python.org/dev/peps/pep-3147\">PEP 3147</a></strong>.</li>\n</ul>\n<h2>6.2. Standard Modules<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#standard-modules\" title=\"Permalink to this headline\">¶</a></h2>\n<p>Python comes with a library of standard modules, described in a separate document, the Python Library Reference (“Library Reference” hereafter). Some modules are built into the interpreter; these provide access to operations that are not part of the core of the language but are nevertheless built in, either for efficiency or to provide access to operating system primitives such as system calls. The set of such modules is a configuration option which also depends on the underlying platform. For example, the <a href=\"https://docs.python.org/3/library/winreg.html#module-winreg\" title=\"winreg: Routines and objects for manipulating the Windows registry. (Windows)\"><code class=\"language-text\">winreg</code></a> module is only provided on Windows systems. One particular module deserves some attention: <a href=\"https://docs.python.org/3/library/sys.html#module-sys\" title=\"sys: Access system-specific parameters and functions.\"><code class=\"language-text\">sys</code></a>, which is built into every Python interpreter. The variables <code class=\"language-text\">sys.ps1</code> and <code class=\"language-text\">sys.ps2</code> define the strings used as primary and secondary prompts:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import sys\n>>> sys.ps1\n'>>> '\n>>> sys.ps2\n'... '\n>>> sys.ps1 = 'C> '\nC> print('Yuck!')\nYuck!\nC></code></pre></div>\n<p>These two variables are only defined if the interpreter is in interactive mode.</p>\n<p>The variable <code class=\"language-text\">sys.path</code> is a list of strings that determines the interpreter’s search path for modules. It is initialized to a default path taken from the environment variable <a href=\"https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH\"><code class=\"language-text\">PYTHONPATH</code></a>, or from a built-in default if <a href=\"https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH\"><code class=\"language-text\">PYTHONPATH</code></a> is not set. You can modify it using standard list operations:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import sys\n>>> sys.path.append('/ufs/guido/lib/python')</code></pre></div>\n<h2>6.3. The <a href=\"https://docs.python.org/3/library/functions.html#dir\" title=\"dir\"><code class=\"language-text\">dir()</code></a> Function<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#the-dir-function\" title=\"Permalink to this headline\">¶</a></h2>\n<p>The built-in function <a href=\"https://docs.python.org/3/library/functions.html#dir\" title=\"dir\"><code class=\"language-text\">dir()</code></a> is used to find out which names a module defines. It returns a sorted list of strings:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> fibo<span class=\"token punctuation\">,</span> sys\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">dir</span><span class=\"token punctuation\">(</span>fibo<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'__name__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'fib'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'fib2'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">dir</span><span class=\"token punctuation\">(</span>sys<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'__breakpointhook__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__displayhook__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__doc__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__excepthook__'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'__interactivehook__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__loader__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__name__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__package__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__spec__'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'__stderr__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__stdin__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__stdout__'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'__unraisablehook__'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'_clear_type_cache'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_current_frames'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_debugmallocstats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_framework'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'_getframe'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_git'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_home'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_xoptions'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'abiflags'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'addaudithook'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'api_version'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'argv'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'audit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'base_exec_prefix'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'base_prefix'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'breakpointhook'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'builtin_module_names'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'byteorder'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'call_tracing'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'callstats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'copyright'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'displayhook'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dont_write_bytecode'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'exc_info'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'excepthook'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'exec_prefix'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'executable'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'exit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'flags'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'float_info'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'float_repr_style'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'get_asyncgen_hooks'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'get_coroutine_origin_tracking_depth'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'getallocatedblocks'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getdefaultencoding'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getdlopenflags'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'getfilesystemencodeerrors'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getfilesystemencoding'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getprofile'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'getrecursionlimit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getrefcount'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getsizeof'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'getswitchinterval'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'gettrace'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hash_info'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hexversion'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'implementation'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'int_info'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'intern'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is_finalizing'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'last_traceback'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'last_type'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'last_value'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'maxsize'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'maxunicode'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'meta_path'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'modules'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'path'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'path_hooks'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'path_importer_cache'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'platform'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'prefix'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'ps1'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'ps2'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pycache_prefix'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'set_asyncgen_hooks'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'set_coroutine_origin_tracking_depth'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'setdlopenflags'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'setprofile'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'setrecursionlimit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'setswitchinterval'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'settrace'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'stderr'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'stdin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'stdout'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'thread_info'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'unraisablehook'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'version'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'version_info'</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'warnoptions'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Without arguments, <a href=\"https://docs.python.org/3/library/functions.html#dir\" title=\"dir\"><code class=\"language-text\">dir()</code></a> lists the names you have defined currently:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> a = [1, 2, 3, 4, 5]\n>>> import fibo\n>>> fib = fibo.fib\n>>> dir()\n['__builtins__', '__name__', 'a', 'fib', 'fibo', 'sys']</code></pre></div>\n<p>Note that it lists all types of names: variables, modules, functions, etc.</p>\n<p><a href=\"https://docs.python.org/3/library/functions.html#dir\" title=\"dir\"><code class=\"language-text\">dir()</code></a> does not list the names of built-in functions and variables. If you want a list of those, they are defined in the standard module <a href=\"https://docs.python.org/3/library/builtins.html#module-builtins\" title=\"builtins: The module that provides the built-in namespace.\"><code class=\"language-text\">builtins</code></a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>>> import builtins\n>>> dir(builtins)\n['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException',\n 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning',\n 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError',\n 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning',\n 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False',\n 'FileExistsError', 'FileNotFoundError', 'FloatingPointError',\n 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError',\n 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError',\n 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError',\n 'MemoryError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented',\n 'NotImplementedError', 'OSError', 'OverflowError',\n 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError',\n 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning',\n 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError',\n 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError',\n 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError',\n 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning',\n 'ValueError', 'Warning', 'ZeroDivisionError', '_', '__build_class__',\n '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs',\n 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable',\n 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits',\n 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit',\n 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr',\n 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass',\n 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview',\n 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property',\n 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice',\n 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars',\n 'zip']</code></pre></div>\n<h2>6.4. Packages<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#packages\" title=\"Permalink to this headline\">¶</a></h2>\n<p>Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name <code class=\"language-text\">A.B</code> designates a submodule named <code class=\"language-text\">B</code> in a package named <code class=\"language-text\">A</code>. Just like the use of modules saves the authors of different modules from having to worry about each other’s global variable names, the use of dotted module names saves the authors of multi-module packages like NumPy or Pillow from having to worry about each other’s module names.</p>\n<p>Suppose you want to design a collection of modules (a “package”) for the uniform handling of sound files and sound data. There are many different sound file formats (usually recognized by their extension, for example: <code class=\"language-text\">.wav</code>, <code class=\"language-text\">.aiff</code>, <code class=\"language-text\">.au</code>), so you may need to create and maintain a growing collection of modules for the conversion between the various file formats. There are also many different operations you might want to perform on sound data (such as mixing, adding echo, applying an equalizer function, creating an artificial stereo effect), so in addition you will be writing a never-ending stream of modules to perform these operations. Here’s a possible structure for your package (expressed in terms of a hierarchical filesystem):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sound/                          Top-level package\n      __init__.py               Initialize the sound package\n      formats/                  Subpackage for file format conversions\n              __init__.py\n              wavread.py\n              wavwrite.py\n              aiffread.py\n              aiffwrite.py\n              auread.py\n              auwrite.py\n              ...\n      effects/                  Subpackage for sound effects\n              __init__.py\n              echo.py\n              surround.py\n              reverse.py\n              ...\n      filters/                  Subpackage for filters\n              __init__.py\n              equalizer.py\n              vocoder.py\n              karaoke.py\n              ...</code></pre></div>\n<p>When importing the package, Python searches through the directories on <code class=\"language-text\">sys.path</code> looking for the package subdirectory.</p>\n<p>The <code class=\"language-text\">__init__.py</code> files are required to make Python treat directories containing the file as packages. This prevents directories with a common name, such as <code class=\"language-text\">string</code>, unintentionally hiding valid modules that occur later on the module search path. In the simplest case, <code class=\"language-text\">__init__.py</code> can just be an empty file, but it can also execute initialization code for the package or set the <code class=\"language-text\">__all__</code> variable, described later.</p>\n<p>Users of the package can import individual modules from the package, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import sound.effects.echo</code></pre></div>\n<p>This loads the submodule <code class=\"language-text\">sound.effects.echo</code>. It must be referenced with its full name.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)</code></pre></div>\n<p>An alternative way of importing the submodule is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from sound.effects import echo</code></pre></div>\n<p>This also loads the submodule <code class=\"language-text\">echo</code>, and makes it available without its package prefix, so it can be used as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">echo.echofilter(input, output, delay=0.7, atten=4)</code></pre></div>\n<p>Yet another variation is to import the desired function or variable directly:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from sound.effects.echo import echofilter</code></pre></div>\n<p>Again, this loads the submodule <code class=\"language-text\">echo</code>, but this makes its function <code class=\"language-text\">echofilter()</code> directly available:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">echofilter(input, output, delay=0.7, atten=4)</code></pre></div>\n<p>Note that when using <code class=\"language-text\">from package import item</code>, the item can be either a submodule (or subpackage) of the package, or some other name defined in the package, like a function, class or variable. The <code class=\"language-text\">import</code> statement first tests whether the item is defined in the package; if not, it assumes it is a module and attempts to load it. If it fails to find it, an <a href=\"https://docs.python.org/3/library/exceptions.html#ImportError\" title=\"ImportError\"><code class=\"language-text\">ImportError</code></a> exception is raised.</p>\n<p>Contrarily, when using syntax like <code class=\"language-text\">import item.subitem.subsubitem</code>, each item except for the last must be a package; the last item can be a module or a package but can’t be a class or function or variable defined in the previous item.</p>\n<h3>6.4.1. Importing * From a Package<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#importing-from-a-package\" title=\"Permalink to this headline\">¶</a></h3>\n<p>Now what happens when the user writes <code class=\"language-text\">from sound.effects import *</code>? Ideally, one would hope that this somehow goes out to the filesystem, finds which submodules are present in the package, and imports them all. This could take a long time and importing sub-modules might have unwanted side-effects that should only happen when the sub-module is explicitly imported.</p>\n<p>The only solution is for the package author to provide an explicit index of the package. The <a href=\"https://docs.python.org/3/reference/simple_stmts.html#import\"><code class=\"language-text\">import</code></a> statement uses the following convention: if a package’s <code class=\"language-text\">__init__.py</code> code defines a list named <code class=\"language-text\">__all__</code>, it is taken to be the list of module names that should be imported when <code class=\"language-text\">from package import *</code> is encountered. It is up to the package author to keep this list up-to-date when a new version of the package is released. Package authors may also decide not to support it, if they don’t see a use for importing * from their package. For example, the file <code class=\"language-text\">sound/effects/__init__.py</code> could contain the following code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">__all__ = [\"echo\", \"surround\", \"reverse\"]</code></pre></div>\n<p>This would mean that <code class=\"language-text\">from sound.effects import *</code> would import the three named submodules of the <code class=\"language-text\">sound</code> package.</p>\n<p>If <code class=\"language-text\">__all__</code> is not defined, the statement <code class=\"language-text\">from sound.effects import *</code> does <em>not</em> import all submodules from the package <code class=\"language-text\">sound.effects</code> into the current namespace; it only ensures that the package <code class=\"language-text\">sound.effects</code> has been imported (possibly running any initialization code in <code class=\"language-text\">__init__.py</code>) and then imports whatever names are defined in the package. This includes any names defined (and submodules explicitly loaded) by <code class=\"language-text\">__init__.py</code>. It also includes any submodules of the package that were explicitly loaded by previous <a href=\"https://docs.python.org/3/reference/simple_stmts.html#import\"><code class=\"language-text\">import</code></a> statements. Consider this code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import sound.effects.echo\nimport sound.effects.surround\nfrom sound.effects import *</code></pre></div>\n<p>In this example, the <code class=\"language-text\">echo</code> and <code class=\"language-text\">surround</code> modules are imported in the current namespace because they are defined in the <code class=\"language-text\">sound.effects</code> package when the <code class=\"language-text\">from...import</code> statement is executed. (This also works when <code class=\"language-text\">__all__</code> is defined.)</p>\n<p>Although certain modules are designed to export only names that follow certain patterns when you use <code class=\"language-text\">import *</code>, it is still considered bad practice in production code.</p>\n<p>Remember, there is nothing wrong with using <code class=\"language-text\">from package import specific_submodule</code>! In fact, this is the recommended notation unless the importing module needs to use submodules with the same name from different packages.</p>\n<h3>6.4.2. Intra-package References<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#intra-package-references\" title=\"Permalink to this headline\">¶</a></h3>\n<p>When packages are structured into subpackages (as with the <code class=\"language-text\">sound</code> package in the example), you can use absolute imports to refer to submodules of siblings packages. For example, if the module <code class=\"language-text\">sound.filters.vocoder</code> needs to use the <code class=\"language-text\">echo</code> module in the <code class=\"language-text\">sound.effects</code> package, it can use <code class=\"language-text\">from sound.effects import echo</code>.</p>\n<p>You can also write relative imports, with the <code class=\"language-text\">from module import name</code> form of import statement. These imports use leading dots to indicate the current and parent packages involved in the relative import. From the <code class=\"language-text\">surround</code> module for example, you might use:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n<p>Note that relative imports are based on the name of the current module. Since the name of the main module is always <code class=\"language-text\">\"__main__\"</code>, modules intended for use as the main module of a Python application must always use absolute imports.</p>\n<h3>6.4.3. Packages in Multiple Directories<a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#packages-in-multiple-directories\" title=\"Permalink to this headline\">¶</a></h3>\n<p>Packages support one more special attribute, <a href=\"https://docs.python.org/3/reference/import.html#__path__\" title=\"__path__\"><code class=\"language-text\">path</code></a>. This is initialized to be a list containing the name of the directory holding the package’s <code class=\"language-text\">__init__.py</code> before the code in that file is executed. This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.</p>\n<p>While this feature is not often needed, it can be used to extend the set of modules found in a package.</p>\n<p>Footnotes</p>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#id1\">1</a><br>\nIn fact function definitions are also ‘statements’ that are ‘executed’; the execution of a module-level function definition enters the function name in the module’s global symbol table.</p>\n<h3><a href=\"https://docs.python.org/3/contents.html\">Table of Contents</a></h3>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#\">6. Modules</a></p>\n<ul>\n<li>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#more-on-modules\">6.1. More on Modules</a></p>\n<ul>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#executing-modules-as-scripts\">6.1.1. Executing modules as scripts</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#the-module-search-path\">6.1.2. The Module Search Path</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#compiled-python-files\">6.1.3. “Compiled” Python files</a></li>\n</ul>\n</li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#standard-modules\">6.2. Standard Modules</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#the-dir-function\">6.3. The <code class=\"language-text\">dir()</code> Function</a></li>\n<li>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#packages\">6.4. Packages</a></p>\n<ul>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#importing-from-a-package\">6.4.1. Importing * From a Package</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#intra-package-references\">6.4.2. Intra-package References</a></li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/modules.html#packages-in-multiple-directories\">6.4.3. Packages in Multiple Directories</a></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<h4>Previous topic</h4>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/datastructures.html\" title=\"previous chapter\">5. Data Structures</a></p>\n<h4>Next topic</h4>\n<p><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/inputoutput.html\" title=\"next chapter\">7. Input and Output</a></p>\n<h3>This Page</h3>\n<ul>\n<li><a href=\"https://docs.python.org/3/bugs.html\">Report a Bug</a></li>\n<li><a href=\"https://github.com/python/cpython/blob/3.9/Doc/tutorial/modules.rst\">Show Source</a></li>\n</ul>\n<h3>Navigation</h3>\n<ul>\n<li><a href=\"https://docs.python.org/3/genindex.html\" title=\"General Index\">index</a></li>\n<li><a href=\"https://docs.python.org/3/py-modindex.html\" title=\"Python Module Index\">modules</a> |</li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/inputoutput.html\" title=\"7. Input and Output\">next</a> |</li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/datastructures.html\" title=\"5. Data Structures\">previous</a> |</li>\n<li><img src=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/_static/py.png\" alt=\"image\"></li>\n<li><a href=\"https://www.python.org/\">Python</a> »</li>\n<li><a href=\"https://docs.python.org/3/index.html\">3.9.5 Documentation</a> »</li>\n<li><a href=\"https://bgoonz-docs-collection-69gqwqgppf5gg9-5500.githubpreview.dev/python/tutorial/index.html\">The Python Tutorial</a> »</li>\n<li>-</li>\n</ul>"},{"url":"/docs/tips/7-tips-to-become-a-better-web-developer/","relativePath":"docs/tips/7-tips-to-become-a-better-web-developer/index.md","relativeDir":"docs/tips/7-tips-to-become-a-better-web-developer","base":"index.md","name":"index","frontmatter":{"title":"7 tips to become a better web developer","template":"docs","excerpt":"Never stop learning"},"html":"<h3>1. Never stop learning</h3>\n<p>No matter how experienced a web developer you are, programming is a process of constantly learning. As new technologies and frameworks are released, you’ll have to keep yourself informed to remain competitive.</p>\n<p>Dive into Stack Overflow and GitHub to find the answers to questions you have, or just to scan through the questions other developers are asking. Develop a reading list of industry blogs and magazines. We like these resources:</p>\n<ul>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/www.smashingmagazine.com/%E2%80%9C\">Smashing Magazine</a></li>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/blog.codepen.io/%E2%80%9C\">CodePen Blog</a></li>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/github.blog/%E2%80%9C\">GitHub Blog</a></li>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/blog.codinghorror.com/%E2%80%9C\">Coding Horror</a></li>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/css-weekly.com/%E2%80%9C\">CSS Weekly</a></li>\n<li><a href=\"https://www.freelancer.com/web-development\">Freelancer</a> (OK, we’re slightly biased)</li>\n</ul>\n<h3>2. Contribute to open-source</h3>\n<p>Working solely on your own projects can give you tunnel vision. Furthermore, leaving coding to work hours limits your opportunity for development. If you really want to mature as a developer, get into coding as a hobby for the pure joy of it. In other words, get involved in open-source.</p>\n<p>Jump on GitHub and start contributing to open-source projects. Helping other developers solve problems will help nurture your own creativity and problem-solving skills. As a side bonus, it also raises your profile as a developer. When you do good work on open-source projects, you start to develop a strong reputation in the development community. This can open up new opportunities in the future.</p>\n<h3>3. Conduct code review</h3>\n<p>Most companies already have a culture of code review. Before code gets pushed, the development team shares it with each other for a sanity check. If you’re fortunate, this process is already in place where you work. If it’s not, you can be the one to start it.</p>\n<p>Code review not only helps pick up problems in your code before they turn into bugs on your site. It also makes you put more thought into why you wrote your code the way you did. When you have to explain and defend the way you chose to solve a problem, it helps you reflect on the “why” behind your choices. Ultimately, this can help identify and eliminate bad habits, and teach you new skills.</p>\n<h3>4. Document properly</h3>\n<p>We can’t emphasize this strongly enough: <strong>comment your damn code</strong>. In a perfect world, documentation wouldn’t be necessary. Code would always be written for human readability first, and machine interpretation second. This is not a perfect world.</p>\n<p>There are times when code cannot be further simplified or made more readable. It’s these times that commenting is imperative. Your comments explain to other developers the what, how and why of your codebase. It also helps <em>you</em> understand.</p>\n<p>Not only does commenting provide time for self-reflection and assessment of your code. It also provides a useful guide for you in the future should you have to set a project aside and come back to it later. Trust us. Future you will thank present you for taking the time to comment.</p>\n<h3>5. Build on the work of others</h3>\n<p>The great thing about web development is that you have a vast community of intellectual capital to draw from. Web developers have done and are continuing to do amazing things that push the boundaries of the internet experience.</p>\n<p>Find sites that you like, that have done unique and exciting things. Then learn from them and shamelessly rip them off. It’s as simple as inspecting the source code for the site to see how they’ve accomplished what they’ve accomplished.</p>\n<p>The work of other developers is an invaluable teaching tool. Build yourself a “swipe file” of websites that excite you, ones with features and functionality you want to emulate. Learn from their code. Or even go the extra mile and reach out to their developers.</p>\n<h3>6. Code for a purpose</h3>\n<p>Writing code is a means to an end, not an end in itself. It’s important to identify <em>why</em> you’re writing code for your site. What are you trying to achieve?</p>\n<p>Any coding effort is actually a business effort. If you’re working on a freelance project, make sure you understand the client’s business goals and aspirations before you start coding. It’s the best way to determine if what you’re producing is going to help achieve the desired outcome.</p>\n<p>Likewise, if you’re writing code for your own site, think about the big picture. What are your goals for the site? What is its reason for being? In a landscape with nearly 200 million websites, you have to do something to make yours stand apart. Having a clear idea of the outcome you want will bring more focus to your web development.</p>\n<h3>7. Sandbox your experiments</h3>\n<p>When you’re learning web development, front end or back end, you’re going to make mistakes. A lot of them, in all likelihood. Sandboxing your experimentation ensures those mistakes won’t have dire consequences.</p>\n<p>You can sandbox your code by setting up a server environment on your computer. We’d go with MAMP for Mac users, WAMP for Windows users or LAMP for Linux users.</p>\n<p>Keeping experimental code confined to a server environment on your machine means that any mistakes you make can be easily identified and won’t impact your entire codebase. It gives you the freedom to play around, and to fail. And failing is an important part of learning.</p>"},{"url":"/docs/tips/7-tips-to-become-a-better-web-developer/7tips/","relativePath":"docs/tips/7-tips-to-become-a-better-web-developer/7tips.md","relativeDir":"docs/tips/7-tips-to-become-a-better-web-developer","base":"7tips.md","name":"7tips","frontmatter":{"title":"7 tips to become a better web developer","template":"docs","excerpt":"Never stop learning"},"html":"<h3>1. Never stop learning</h3>\n<p>No matter how experienced a web developer you are, programming is a process of constantly learning. As new technologies and frameworks are released, you’ll have to keep yourself informed to remain competitive.</p>\n<p>Dive into Stack Overflow and GitHub to find the answers to questions you have, or just to scan through the questions other developers are asking. Develop a reading list of industry blogs and magazines. We like these resources:</p>\n<ul>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/www.smashingmagazine.com/%E2%80%9C\">Smashing Magazine</a></li>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/blog.codepen.io/%E2%80%9C\">CodePen Blog</a></li>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/github.blog/%E2%80%9C\">GitHub Blog</a></li>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/blog.codinghorror.com/%E2%80%9C\">Coding Horror</a></li>\n<li><a href=\"https://www.freelancer.com/community/%E2%80%9Chttps:/css-weekly.com/%E2%80%9C\">CSS Weekly</a></li>\n<li><a href=\"https://www.freelancer.com/web-development\">Freelancer</a> (OK, we’re slightly biased)</li>\n</ul>\n<h3>2. Contribute to open-source</h3>\n<p>Working solely on your own projects can give you tunnel vision. Furthermore, leaving coding to work hours limits your opportunity for development. If you really want to mature as a developer, get into coding as a hobby for the pure joy of it. In other words, get involved in open-source.</p>\n<p>Jump on GitHub and start contributing to open-source projects. Helping other developers solve problems will help nurture your own creativity and problem-solving skills. As a side bonus, it also raises your profile as a developer. When you do good work on open-source projects, you start to develop a strong reputation in the development community. This can open up new opportunities in the future.</p>\n<h3>3. Conduct code review</h3>\n<p>Most companies already have a culture of code review. Before code gets pushed, the development team shares it with each other for a sanity check. If you’re fortunate, this process is already in place where you work. If it’s not, you can be the one to start it.</p>\n<p>Code review not only helps pick up problems in your code before they turn into bugs on your site. It also makes you put more thought into why you wrote your code the way you did. When you have to explain and defend the way you chose to solve a problem, it helps you reflect on the “why” behind your choices. Ultimately, this can help identify and eliminate bad habits, and teach you new skills.</p>\n<h3>4. Document properly</h3>\n<p>We can’t emphasize this strongly enough: <strong>comment your damn code</strong>. In a perfect world, documentation wouldn’t be necessary. Code would always be written for human readability first, and machine interpretation second. This is not a perfect world.</p>\n<p>There are times when code cannot be further simplified or made more readable. It’s these times that commenting is imperative. Your comments explain to other developers the what, how and why of your codebase. It also helps <em>you</em> understand.</p>\n<p>Not only does commenting provide time for self-reflection and assessment of your code. It also provides a useful guide for you in the future should you have to set a project aside and come back to it later. Trust us. Future you will thank present you for taking the time to comment.</p>\n<h3>5. Build on the work of others</h3>\n<p>The great thing about web development is that you have a vast community of intellectual capital to draw from. Web developers have done and are continuing to do amazing things that push the boundaries of the internet experience.</p>\n<p>Find sites that you like, that have done unique and exciting things. Then learn from them and shamelessly rip them off. It’s as simple as inspecting the source code for the site to see how they’ve accomplished what they’ve accomplished.</p>\n<p>The work of other developers is an invaluable teaching tool. Build yourself a “swipe file” of websites that excite you, ones with features and functionality you want to emulate. Learn from their code. Or even go the extra mile and reach out to their developers.</p>\n<h3>6. Code for a purpose</h3>\n<p>Writing code is a means to an end, not an end in itself. It’s important to identify <em>why</em> you’re writing code for your site. What are you trying to achieve?</p>\n<p>Any coding effort is actually a business effort. If you’re working on a freelance project, make sure you understand the client’s business goals and aspirations before you start coding. It’s the best way to determine if what you’re producing is going to help achieve the desired outcome.</p>\n<p>Likewise, if you’re writing code for your own site, think about the big picture. What are your goals for the site? What is its reason for being? In a landscape with nearly 200 million websites, you have to do something to make yours stand apart. Having a clear idea of the outcome you want will bring more focus to your web development.</p>\n<h3>7. Sandbox your experiments</h3>\n<p>When you’re learning web development, front end or back end, you’re going to make mistakes. A lot of them, in all likelihood. Sandboxing your experimentation ensures those mistakes won’t have dire consequences.</p>\n<p>You can sandbox your code by setting up a server environment on your computer. We’d go with MAMP for Mac users, WAMP for Windows users or LAMP for Linux users.</p>\n<p>Keeping experimental code confined to a server environment on your machine means that any mistakes you make can be easily identified and won’t impact your entire codebase. It gives you the freedom to play around, and to fail. And failing is an important part of learning.</p>"},{"url":"/docs/tips/how-to-ask-questions/","relativePath":"docs/tips/how-to-ask-questions/index.md","relativeDir":"docs/tips/how-to-ask-questions","base":"index.md","name":"index","frontmatter":{"title":"How to Ask Questions","template":"docs","excerpt":"Many students find it hard to ask questions during the classes and online"},"html":"<!--StartFragment-->\n<h1><a href=\"https://bgoonz.github.io/webdevbook/#/learning/how-to-ask-questions?id=how-to-ask-questions\">How to Ask Questions</a></h1>\n<p>Many students find it hard to ask questions during the classes and online (through Slack or otherwise). However, to become a good programmer means you dare to ask questions, lots of questions. In fact, some companies even have a rule on this: If you are stuck, you have ​one hour t​o solve the problem. If you cannot, you ​have to ask for help.</p>\n<p>In bgoonz there are several ways to ask for help:</p>\n<ul>\n<li>Ask your classmate or a student from another class</li>\n<li>Ask in Slack (preferably in your classroom channel)</li>\n<li>Approach a teacher during breaks or through slack in a group</li>\n<li>Ask HYF staff to connect you to a graduate or teacher for individual sessions</li>\n</ul>\n<p>Nevertheless, we often notice students not asking for help is the prime reason for them dropping out of our program.</p>\n<p>Let’s take a classic example we often encounter in bgoonz:</p>\n<p>During class the teacher explains a concept. At some point the students do not understand what the teacher is trying to explain. One or two students ask questions. However, these students already understand most of the concepts and are therefore comfortable to ask questions to improve their knowledge. Yet, most classmates remain silent and do not ask any questions, even though they can hardly keep up with the teacher. What are the reasons? Below we discuss 3 reasons and some suggestions on how to ask questions anyway.</p>\n<p><strong>Reason 1:</strong> You do not want to take the risk of looking stupid in front of the class.</p>\n<p><em>Solution:</em></p>\n<p>Fun story:​ ​A woman, recounting a story about an old man who used to answer all her \"stupid questions\", explained: \"If you ask a question it makes you look stupid for 5 minutes – but if you don't ask – you stay stupid for fifty years, so always ask questions in your life\".</p>\n<p>If reason 1 is your reason for not asking, we say: you are wasting your own time. Instead of asking the teacher, you are telling yourself you will understand it by yourself later on. What often happens is that you will only understand 50% of it when you look it up yourself, and this will cost you much more time than just asking the teacher and getting a clear answer directly.</p>\n<p>Also, in your job you will need to be capable of asking questions in front of people: start practicing now!</p>\n<p><strong>Reason 2:</strong></p>\n<p>You know you are not completely understanding the concept/explanation but do not know how to transform this into a useful question.</p>\n<p><em>Solution</em></p>\n<p>There are several ways to ask a question when you are not sure how to frame it:</p>\n<p>Recap what you understood, and share where you lost the teacher</p>\n<ul>\n<li>“I Understood how it worked until this point, but after that you lost me. Can you explain part X again?”</li>\n</ul>\n<p>How does X work:</p>\n<ul>\n<li>“How does part x work? I still don’t really understand it.”</li>\n</ul>\n<p>Why do we do X?</p>\n<ul>\n<li>“Why do you use X to solve problem Y?”</li>\n</ul>\n<p>Check your own understanding</p>\n<ul>\n<li>“Do I understand correctly that X does Y and Z?”</li>\n</ul>\n<p>Ask for an example:</p>\n<ul>\n<li>“Can you give an example of how X works?”</li>\n</ul>\n<p><strong>Reason 3:</strong></p>\n<p>You lack a fundamental understanding of a basic concept, which prevents you from understanding the new information.</p>\n<p><em>Solution</em></p>\n<p>This situation applies when you have not mastered the underlying basic concepts yet and therefore cannot understand the explanation of the teacher (or reading materials) when discussing more advanced concepts.</p>\n<p>For instance, the teacher is explaining ​callback functions​ with a practical example. However, you do not grasp his/her explanation since you are still not completely comfortable with basic functions, which are explained and used in the JS1/JS2 modules.</p>\n<p>If this happens, it is probably a good idea to take some time apart with the teacher, a graduate student or someone else ​who is good at explaining the basics​.</p>\n<p>We can always provide you with some help, for instance by organizing individual video calls or appointments with former students or teachers. Moreover, it is important to revisit the basic concepts that you struggle and ​practice, practice, practice u​ ntil you dream of Javascript functions. After that, you can try to revisit the more advanced concepts (for instance by re-watching the lecture on YouTube).</p>\n<p>If you feel reason 3 applies to you, it is crucial not to wait and hope things get better with time. As the speed of our curriculum is very high, ​you have to take initiative and reach out to us for HELP.​ Again, good programmers ask for help. Those that do not ask for help, will never become good programmers.</p>\n<!--EndFragment-->"},{"url":"/docs/tips/firebase-hosting/","relativePath":"docs/tips/firebase-hosting/index.md","relativeDir":"docs/tips/firebase-hosting","base":"index.md","name":"index","frontmatter":{"title":"Firebase Hosting","template":"docs","excerpt":"Firebase Hosting integrates with serverless computing options, including Cloud Functions for Firebase and Cloud Ru"},"html":"<!--StartFragment-->\n<h1>Serve dynamic content and host microservices using Firebase Hosting</h1>\n<p>[ ]</p>\n<p>Firebase Hosting integrates with serverless computing options, including Cloud Functions for Firebase and Cloud Run. Using Firebase Hosting with these options, you can host microservices by directing HTTPS requests to trigger your functions and containerized apps to run in a managed, secure environment.</p>\n<p><strong><a href=\"https://firebase.google.com/docs/hosting/functions\">Cloud Functions for Firebase</a></strong>: You write and deploy a function, which is backend code that responds to a specific trigger. Then, using Firebase Hosting, you can direct HTTPS requests to trigger your function to run.</p>\n<p><strong><a href=\"https://firebase.google.com/docs/hosting/cloud-run\">Cloud Run</a></strong>: You write and deploy an application packaged in a container image. Then, using Firebase Hosting, you can direct HTTPS requests to trigger your containerized app to run.</p>\n<h2>Use cases</h2>\n<p>How can you use serverless computing options with Firebase Hosting?</p>\n<ul>\n<li>\n<p><strong>Serve dynamic content</strong> — In addition to serving static content on your Hosting site, you can serve dynamically generated responses from a function or containerized app that is performing server-side logic.</p>\n<p>For example, you can point a URL pattern (like <code class=\"language-text\">/blog/&lt;blog-post-id></code>) to a function that uses the URL's blog post ID parameter to retrieve content dynamically from your database.</p>\n</li>\n<li>\n<p><strong>Build REST APIs</strong> — You can create a microservice API using functions.</p>\n<p>For instance, functions can handle the sign-in functionality for your website. While your website is hosted at <code class=\"language-text\">/</code>, any request to <code class=\"language-text\">/api</code> is redirected to your microservice API. For an example, check out <a href=\"https://github.com/firebase/functions-samples/tree/Node-8/authenticated-json-api\">this open-source sample</a>.</p>\n</li>\n<li>\n<p><strong>Cache dynamic content</strong> — You can <a href=\"https://firebase.google.com/docs/hosting/manage-cache\">configure caching</a> of your dynamic content on a global CDN.</p>\n<p>For example, if a function generates new content only periodically, you can speed up your app by caching the generated content for at least a short period of time. You can also potentially reduce execution costs because the content is served from the CDN rather than via a triggered function or containerized app.</p>\n</li>\n<li><strong>Prerender your single-page apps</strong> — You can improve SEO and optimize sharing across various social networks by creating dynamic <code class=\"language-text\">meta</code> tags. To learn more, watch this <a href=\"https://www.youtube.com/watch?v=82tZAPMHfT4\">video</a> or check out <a href=\"https://github.com/firebase/functions-samples/tree/Node-8/isomorphic-react-app\">this open-source sample</a>.</li>\n</ul>\n<h2>Choosing a serverless option</h2>\n<p>While both <strong><a href=\"https://firebase.google.com/docs/hosting/functions\">Cloud Functions for Firebase</a></strong> and <strong><a href=\"https://firebase.google.com/docs/hosting/cloud-run\">Cloud Run</a></strong> integrate with Firebase Hosting and offer a fully managed, autoscaling, and secure serverless environment, the two options can be leveraged for different use cases and desired level of customized configuration.</p>\n<p>The following table describes some basic considerations for using Cloud Functions for Firebase versus Cloud Run. For a full listing of quotas, limits, and metrics, refer to each product's detailed documentation (<a href=\"https://firebase.google.com/docs/functions/quotas\">Cloud Functions for Firebase</a> or <a href=\"https://cloud.google.com/run/quotas\">Cloud Run</a>).</p>\n<table>\n<thead>\n<tr>\n<th><strong>Consideration</strong></th>\n<th><strong>Cloud Functions for Firebase</strong></th>\n<th><strong>Cloud Run</strong></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><strong>Setup</strong></td>\n<td>The Firebase CLI bundles multiple tasks into single commands, from initializing to building and deploying.</td>\n<td>Containers offer more customizable options, so setup, build, and deployment tasks involve discrete steps.</td>\n</tr>\n<tr>\n<td><strong>Runtime environment</strong></td>\n<td>Requires Node.js, but you can specify <a href=\"https://firebase.google.com/docs/functions/manage-functions#set_runtime_options\">which version</a> of Node.js to use.</td>\n<td>When <a href=\"https://firebase.google.com/docs/hosting/cloud-run#containerize\">building your container</a>, you specify the runtime environment.</td>\n</tr>\n<tr>\n<td><strong>Language and frameworks support</strong></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td><strong>Timeout for Hosting request</strong></td>\n<td>60 seconds (see Note below)</td>\n<td>60 seconds (see Note below)</td>\n</tr>\n<tr>\n<td><strong>Concurrency</strong></td>\n<td>1 request per function instance (no concurrency per instance)</td>\n<td>Up to 1,000 concurrent requests per container instance</td>\n</tr>\n<tr>\n<td><strong>Billing</strong></td>\n<td><a href=\"https://firebase.google.com/pricing\">Cloud Functions usage</a></td>\n<td><a href=\"https://cloud.google.com/run/pricing\">Cloud Run usage</a> + <a href=\"https://cloud.google.com/container-registry/\">Container Registry storage</a></td>\n</tr>\n</tbody>\n</table>\n<!--EndFragment-->"},{"url":"/docs/tips/storybook/","relativePath":"docs/tips/storybook/index.md","relativeDir":"docs/tips/storybook","base":"index.md","name":"index","frontmatter":{"title":"Storybook","template":"docs","excerpt":"Storybook is a great tool for developing and demoing components. "},"html":"<h1>Storybook</h1>\n<p><a href=\"https://storybook.js.org/\">Storybook</a> is a great tool for developing and demoing components. By default, it is based on Webpack and Webpack dev server.</p>\n<p>The <a href=\"../../docs/dev-server/plugins/storybook.md\">@web/dev-server-storybook</a> plugin uses an <a href=\"https://github.com/modernweb-dev/storybook-prebuilt\">opinionated build</a> of Storybook, making it possible to use it with Web Dev Server for es modules and buildless workflows.</p>\n<h2>Setup</h2>\n<p>Install the package:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm i --save-dev @web/dev-server-storybook</code></pre></div>\n<p>Add the plugin and set the project type. See below for supported project types.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> storybookPlugin <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@web/dev-server-storybook'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// type can be 'web-components' or 'preact'</span>\n  <span class=\"token literal-property property\">plugins</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token function\">storybookPlugin</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'web-components'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Add a <code class=\"language-text\">.storybook/main.js</code> file:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">stories</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'../stories/**/*.stories.@(js|jsx|ts|tsx)'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Add a story: <code class=\"language-text\">stories/MyButton.stories.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">'Example/Button'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">argTypes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">backgroundColor</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">control</span><span class=\"token operator\">:</span> <span class=\"token string\">'color'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> Button <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> backgroundColor <span class=\"token operator\">=</span> <span class=\"token string\">'white'</span><span class=\"token punctuation\">,</span> text <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n    &lt;button type=\"button\" style=\"background-color: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>backgroundColor<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">\">\n      </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>text<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">\n    &lt;/button>\n  </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> ButtonA <span class=\"token operator\">=</span> <span class=\"token function\">Button</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nButtonA<span class=\"token punctuation\">.</span>args <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Button A'</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">const</span> ButtonB <span class=\"token operator\">=</span> <span class=\"token function\">Button</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nButtonB<span class=\"token punctuation\">.</span>args <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Button B'</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>See the <a href=\"../../docs/dev-server/plugins/storybook.md\">plugin documentation</a> for more features and all configuration options.</p>"},{"url":"/docs/tips/top-10-money-tips/","relativePath":"docs/tips/top-10-money-tips/index.md","relativeDir":"docs/tips/top-10-money-tips","base":"index.md","name":"index","frontmatter":{"title":"Top 10 Money Tips","template":"docs","excerpt":"Despite taking math for a majority of my life, I never learned much about financial planning. While I could tell you the base 10 logarithm of 1,000, I was not  taught how to set up a good budget."},"html":"<!--StartFragment-->\n<h3>1. Earn a decent living.</h3>\n<p>Research has shown that earning more than you need to live comfortably (e.g., paying for rent/mortgage, transportation, groceries, and the occasional vacation) actually doesn't increase your happiness. But earning less than you need to live comfortably will make you stressed and even unhappy.</p>\n<h3>2. Create a budget to ensure that you're spending less than you make.</h3>\n<p>Go over your monthly spending to find savings. Ask your wireless and cable providers to \"audit\" your bills. Contact insurers about discounts and raising your deductibles. Cancel subscription services you're not really using. Often, just tracking your spending can save hundreds of dollars.</p>\n<h3>3. Plan to eliminate high-rate debts (and chip away at lower-rate, long-term ones).</h3>\n<p>The fastest, cheapest way out of debt is to put all your extra cash toward paying off those with the highest interest rates, while making minimum payments on the rest. Refinancing your mortgage, student loans, and car loans—and transferring credit card balances to lower-rate cards—can speed the process.</p>\n<h3>4. Start an emergency fund.</h3>\n<p>Nothing derails your finances quicker than an emergency. Two-income households should aim to put away three to six months of living expenses; one-income households need to double that. Consider putting this money into a savings or money market account, where you can access it, without penalty, if and when you need it.</p>\n<h3>5. Start—or continue to—invest for retirement.</h3>\n<p>While you're starting your emergency fund, you'll also want to take advantage of any matching dollars your employer is offering you for contributing to a workplace retirement plan. Matching dollars are \"free\" money and you don't want to leave them on the table.</p>\n<h3>6. Assess your investment approach at least once a year.</h3>\n<p>Consider investing any money you're not planning on using for at least three years in a diversified portfolio. Choose investments based on your age and risk tolerance, and rebalance twice a year. Or, take the easier road. You could invest your money in a target-date retirement fund in line with your approximate retirement year, choose a target allocation fund based on the level of risk and return that you're comfortable with, or go with a managed account and let an advisor help you make decisions.</p>\n<h3>7. Make investing a continuing priority.</h3>\n<p>Timing the market rarely works. What does is investing regularly, first in tax-advantaged accounts (retirement accounts, 529 college savings accounts, health savings accounts) and then in discretionary ones. Then every year, assess your progress. </p>\n<h3>8. Have a family conversation to prevent surprises.</h3>\n<p>Ask your parents how their long-term planning is going. Do they have plans to insure a lifetime income? Have they put an estate plan in place (and do they have instructions for how you'll need to execute it)? What are their wishes should they need long-term health care—and will they need help from you along the way? Simultaneously, share your plans for meeting your own financial goals. They may step in with advice, financial help, or both.</p>\n<h3>9. Protect what you've built for yourself with the right insurance and a basic estate plan.</h3>\n<p>You need life insurance when others in your life depend on your income for support. No dependents? Long-term disability insurance is an important protection for being able to take care of yourself (purchasing a group plan through your employer is typically best). A basic estate plan consists of a will (where you'll name guardians for minor children), a living will (which stipulates whether or not you'd want life support), and durable powers of attorney for health and finance (which allow other people to make decisions on your behalf).</p>\n<h3>10. Schedule a repeat performance next year.</h3>\n<p>Just as you go to the doctor every year for a physical, you should sit down annually and go over the items on this list. It's a good time to think about what you want your money to do for you this year, in five years, and in 10 years. You'll be surprised at how good tracking your progress will make you feel!</p>\n<!--EndFragment-->"},{"url":"/docs/tips/web-accessibility/","relativePath":"docs/tips/web-accessibility/index.md","relativeDir":"docs/tips/web-accessibility","base":"index.md","name":"index","frontmatter":{"title":"web-accessibility","template":"docs","excerpt":"### Plan Heading Structure Early"},"html":"<a href=\"http://webaim.org/resources/designers/\">\n<img src=\"http://webaim.org/resources/designers/media/designers.svg\" alt=\"Web Accessibility for Designers infographic with link to text version at WebAIM.org\">\n</a>\n<h2>Text Version</h2>\n<h3>Plan Heading Structure Early</h3>\n<p>Ensure all content and design fits into a <a href=\"https://webaim.org/techniques/semanticstructure/\">logical heading structure</a>.</p>\n<h3>Ensure Logical Reading Order</h3>\n<p>The <a href=\"https://webaim.org/techniques/screenreader/\">reading order for screen reader users</a> should align with the visual order.</p>\n<h3>Provide Good Contrast</h3>\n<p>Be especially careful with shades of orange, yellow, and light gray. Check your contrast levels with our <a href=\"https://webaim.org/resources/contrastchecker/\">color contrast checker</a>.</p>\n<h3>Use True Text Instead of Images of Text</h3>\n<p><a href=\"https://webaim.org/techniques/images/text_graphic\">True text</a> enlarges better, loads faster, and is easier to translate and customize.</p>\n<h3>Use Adequate Font Size</h3>\n<p>Small text is difficult for all users to see. Ensure text is optimally readable.</p>\n<h3>Remember Line Length</h3>\n<p>Don’t make lines too long or too short.</p>\n<h3>Make Sure Links are Recognizable</h3>\n<p>Distinguish <a href=\"https://webaim.org/techniques/hypertext/\">links</a> from body text using more than just color (e.g., underline).</p>\n<h3>Design Keyboard Focus Indicators</h3>\n<p>When navigating with the keyboard, the focused item must be visually distinctive.</p>\n<h3>Design a \"Skip to Main Content\" Link</h3>\n<p>A keyboard accessible <a href=\"https://webaim.org/techniques/skipnav/\">link for users to skip navigation</a> should be at the top of the page.</p>\n<h3>Ensure Link Text Makes Sense on Its Own</h3>\n<p>Avoid \"Click Here\" or other ambiguous <a href=\"https://webaim.org/techniques/hypertext/\">link text</a> such as \"More\" or \"Continue\".</p>\n<h3>Design Usable Widgets and Controls</h3>\n<p>Dialogs, tooltips, menus, carousels, etc. must be easy to use and accessible.</p>\n<h3>Use Animation, Video, and Audio Carefully</h3>\n<p>Provide play/pause buttons. Avoid distracting movement.</p>\n<h3>Don’t Convey Content Using Only Color</h3>\n<p>Users may override or may not be able to see differences between colors.</p>\n<h3>Design Accessible Form Controls</h3>\n<p>Ensure <a href=\"https://webaim.org/techniques/forms/\">form controls</a> have descriptive labels, instructions, and error messages.</p>"},{"url":"/docs/javascript/javascript-examples/flattening-arrays-in-javascript/","relativePath":"docs/javascript/javascript-examples/flattening-arrays-in-javascript/index.md","relativeDir":"docs/javascript/javascript-examples/flattening-arrays-in-javascript","base":"index.md","name":"index","frontmatter":{"title":"Flattening arrays in JavaScript","template":"docs","excerpt":"Flattening arrays may not be an everyday need but, it is still an important need enough to be part of most utility libraries in JavaScript."},"html":"<!--StartFragment-->\n<h1>Flattening arrays in JavaScript</h1>\n<p>Flattening arrays may not be an everyday need but, it is still an important need enough to be part of most utility libraries in JavaScript.</p>\n<p>If you have looked at this very simple problem before you have probably noticed that most of the time we only see one kind of implementation for it, the recursive way.</p>\n<p>Here, I would like to present another way of doing it, iteratively. I am not saying that the iterative way is better than the recursive way, although it has its advantages, but just that sometimes I think it is good to try solving problem with other approaches.</p>\n<h2>The classical recursive way</h2>\n<p>The classical recursive way is based on a function calling itself if the <code class=\"language-text\">i</code> element in the array that we are looping through is also an array.</p>\n<p>This method is the one used in <code class=\"language-text\">lodash</code> for example.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">baseFlatten</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> depth<span class=\"token punctuation\">,</span> predicate<span class=\"token punctuation\">,</span> isStrict<span class=\"token punctuation\">,</span> result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// lots of code here</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>depth <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Recursively flatten arrays (susceptible to call stack limits).</span>\n        <span class=\"token function\">baseFlatten</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> depth <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> predicate<span class=\"token punctuation\">,</span> isStrict<span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">arrayPush</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">// lots of code here</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Note the original comment in the source code to remind us about recursion limitations in JavaScript.</p>\n<p>Then, here is the basic version that you would have probably implemented if you had to.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">var</span> array <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        array <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => [1,2,3,4]</span></code></pre></div>\n<h2>The iterative way</h2>\n<p>Now, let’s look at another way of solving that problem. The new idea is to loop through the array and either concatenate the nested arrays to the original array or add the element to a resulting array as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> array <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> value <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// this line preserve the order</span>\n            arr <span class=\"token operator\">=</span> value<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            array<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => [1,2,3,4]</span></code></pre></div>\n<h1>Practice your “outside the box” thinking</h1>\n<p>I think it is nice to force ourselves to approach problems differently sometimes.</p>\n<p>First, you will have to forget about what you know and start thinking outside of “your” box. We all know how hard it is to forget about something we know to think differently but that a very good exercise, it keeps our mind flexible.</p>\n<p>Secondly, it reminds us that a solution to a problem is only one solution amongst others. It forces us to evaluate our solutions compared to others and not taking for granted the first idea that came to our mind.</p>\n<!--EndFragment-->"},{"url":"/docs/react/react-getting-started/","relativePath":"docs/react/react-getting-started/index.md","relativeDir":"docs/react/react-getting-started","base":"index.md","name":"index","frontmatter":{"title":"React Getting Started","template":"docs","excerpt":"There are a few ways to set up React, and I'll show you two so you get a good idea of how it works"},"html":"<h1>Setup and Installation</h1>\n<p>There are a few ways to set up React, and I'll show you two so you get a good idea of how it works.</p>\n<h2><a href=\"getting-started-with-react//#static-html-file\">Static HTML File</a></h2>\n<p>This first method is not a popular way to set up React and is not how we'll be doing the rest of our tutorial, but it will be familiar and easy to understand if you've ever used a library like jQuery, and it's the least scary way to get started if you're not familiar with Webpack, Babel, and Node.js.</p>\n<p>Let's start by making a basic <code class=\"language-text\">index.html</code> file. We're going to load in three CDNs in the <code class=\"language-text\">head</code> - React, React DOM, and Babel. We're also going to make a <code class=\"language-text\">div</code> with an id called <code class=\"language-text\">root</code>, and finally we'll create a <code class=\"language-text\">script</code> tag where your custom code will live.</p>\n<p>index.html</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token doctype\"><span class=\"token punctuation\">&lt;!</span><span class=\"token doctype-tag\">DOCTYPE</span> <span class=\"token name\">html</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>html</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>head</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>meta</span> <span class=\"token attr-name\">charset</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>utf-8<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span>\n\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>title</span><span class=\"token punctuation\">></span></span>Hello React!<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>title</span><span class=\"token punctuation\">></span></span>\n\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://unpkg.com/react@^16/umd/react.production.min.js<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://unpkg.com/react-dom@16.13.0/umd/react-dom.production.min.js<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://unpkg.com/babel-standalone@6.26.0/babel.js<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>head</span><span class=\"token punctuation\">></span></span>\n\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>body</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>root<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>text/babel<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"><span class=\"token language-javascript\">\n      <span class=\"token comment\">// React code will go here</span>\n    </span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>body</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>html</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>I'm loading in the latest stable versions of the libraries as of the time of this writing.</p>\n<ul>\n<li><a href=\"https://reactjs.org/docs/react-api.html\">React</a> - the React top level API</li>\n<li><a href=\"https://reactjs.org/docs/react-dom.html\">React DOM</a> - adds DOM-specific methods</li>\n<li><a href=\"https://babeljs.io/\">Babel</a> - a JavaScript compiler that lets us use ES6+ in old browsers</li>\n</ul>\n<p>The entry point for our app will be the <code class=\"language-text\">root</code> div element, which is named by convention. You'll also notice the <code class=\"language-text\">text/babel</code> script type, which is mandatory for using Babel.</p>\n<p>Now, let's write our first code block of React. We're going to use ES6 classes to create a React component called <code class=\"language-text\">App</code>.</p>\n<p>index.html</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">//...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now we'll add the <a href=\"https://reactjs.org/docs/react-component.html#render\"><code class=\"language-text\">render()</code></a> method, the only required method in a class component, which is used to render DOM nodes.</p>\n<p>index.html</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n          <span class=\"token comment\">//...</span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Inside the <code class=\"language-text\">return</code>, we're going to put what looks like a simple HTML element. Note that we're not returning a string here, so don't use quotes around the element. This is called <code class=\"language-text\">JSX</code>, and we'll learn more about it soon.</p>\n<p>index.html</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Hello world!</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Finally, we're going to use the React DOM <code class=\"language-text\">render()</code> method to render the <code class=\"language-text\">App</code> class we created into the <code class=\"language-text\">root</code> div in our HTML.</p>\n<p>index.html</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\">ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">App</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here is the full code for our <code class=\"language-text\">index.html</code>.</p>\n<p>index.html</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token doctype\"><span class=\"token punctuation\">&lt;!</span><span class=\"token doctype-tag\">DOCTYPE</span> <span class=\"token name\">html</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>html</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>head</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>meta</span> <span class=\"token attr-name\">charset</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>utf-8<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span>\n\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>title</span><span class=\"token punctuation\">></span></span>Hello React!<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>title</span><span class=\"token punctuation\">></span></span>\n\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://unpkg.com/react@16/umd/react.development.js<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://unpkg.com/react-dom@16/umd/react-dom.development.js<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">src</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>https://unpkg.com/babel-standalone@6.26.0/babel.js<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>head</span><span class=\"token punctuation\">></span></span>\n\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>body</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>root<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>text/babel<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token script\"><span class=\"token language-javascript\">\n      <span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">}</span>\n\n      ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>App <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    </span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>body</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>html</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>Now if you view your <code class=\"language-text\">index.html</code> in the browser, you'll see the <code class=\"language-text\">h1</code> tag we created rendered to the DOM.</p>\n<p><a href=\"static/deb38c3270204d12d046797731ce7ee8/0ef7e/Screen-Shot-2018-08-18-at-10.34.09-AM.png\"><img src=\"static/deb38c3270204d12d046797731ce7ee8/5a190/Screen-Shot-2018-08-18-at-10.34.09-AM.png\" alt=\"Screen Shot 2018 08 18 at 10 34 09 AM\" title=\"Screen Shot 2018 08 18 at 10 34 09 AM\"></a></p>\n<p>Cool! Now that you've done this, you can see that React isn't so insanely scary to get started with. It's just some JavaScript helper libraries that we can load into our HTML.</p>\n<p>We've done this for demonstration purposes, but from here out we're going to use another method: Create React App.</p>\n<h3><a href=\"getting-started-with-react//#create-react-app\"></a>Create React App</h3>\n<p>The method I just used of loading JavaScript libraries into a static HTML page and rendering the React and Babel on the fly is not very efficient, and is hard to maintain.</p>\n<p>Fortunately, Facebook has created <a href=\"https://github.com/facebook/create-react-app\">Create React App</a>, an environment that comes pre-configured with everything you need to build a React app. It will create a live development server, use Webpack to automatically compile React, JSX, and ES6, auto-prefix CSS files, and use ESLint to test and warn about mistakes in the code.</p>\n<p>To set up <code class=\"language-text\">create-react-app</code>, run the following code in your terminal, one directory up from where you want the project to live.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">npx create-react-app react-tutorial</code></pre></div>\n<p>Once that finishes installing, move to the newly created directory and start the project.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token builtin class-name\">cd</span> react-tutorial <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">npm</span> start</code></pre></div>\n<p>Once you run this command, a new window will popup at <code class=\"language-text\">localhost:3000</code> with your new React app.</p>\n<p><a href=\"static/1c5a36e06f57edfc718276e9ddf9a9c1/e3729/Screen-Shot-2018-08-18-at-11.37.59-AM.png\"><img src=\"static/1c5a36e06f57edfc718276e9ddf9a9c1/5a190/Screen-Shot-2018-08-18-at-11.37.59-AM.png\" alt=\"Screen Shot 2018 08 18 at 11 37 59 AM\" title=\"Screen Shot 2018 08 18 at 11 37 59 AM\"></a></p>\n<blockquote>\n<p>Create React App is very good for getting started for beginners as well as large-scale enterprise applications, but it's not perfect for every workflow. You can also create your own Webpack setup for React.</p>\n</blockquote>\n<p>If you look into the project structure, you'll see a <code class=\"language-text\">/public</code> and <code class=\"language-text\">/src</code> directory, along with the regular <code class=\"language-text\">node_modules</code>, <code class=\"language-text\">.gitignore</code>, <code class=\"language-text\">README.md</code>, and <code class=\"language-text\">package.json</code>.</p>\n<p>In <code class=\"language-text\">/public</code>, our important file is <code class=\"language-text\">index.html</code>, which is very similar to the static <code class=\"language-text\">index.html</code> file we made earlier - just a <code class=\"language-text\">root</code> div. This time, no libraries or scripts are being loaded in. The <code class=\"language-text\">/src</code> directory will contain all our React code.</p>\n<p>To see how the environment automatically compiles and updates your React code, find the line that looks like this in <code class=\"language-text\">/src/App.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\">To get started, edit `src/App.js` and save to reload.</code></pre></div>\n<p>And replace it with any other text. Once you save the file, you'll notice <code class=\"language-text\">localhost:3000</code> compiles and refreshes with the new data.</p>\n<p>Go ahead and delete all the files out of the <code class=\"language-text\">/src</code> directory, and we'll create our own boilerplate file without any bloat. We'll just keep <code class=\"language-text\">index.css</code> and <code class=\"language-text\">index.js</code>.</p>\n<p>For <code class=\"language-text\">index.css</code>, I just copy-and-pasted the contents of <a href=\"https://taniarascia.github.io/primitive/css/main.css\">Primitive CSS</a> into the file. If you want, you can use Bootstrap or whatever CSS framework you want, or nothing at all. I just find it easier to work with.</p>\n<p>Now in <code class=\"language-text\">index.js</code>, we're importing React, ReactDOM, and the CSS file.</p>\n<p>src/index.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">\"react-dom\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./index.css\"</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Let's create our <code class=\"language-text\">App</code> component again. Before, we just had an <code class=\"language-text\">&lt;h1></code>, but now I'm adding in a div element with a class as well. You'll notice that we use <code class=\"language-text\">className</code> instead of <code class=\"language-text\">class</code>. This is our first hint that the code being written here is JavaScript, and not actually HTML.</p>\n<p>src/index.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>App<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Hello, React!</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Finally, we'll render the <code class=\"language-text\">App</code> to the root as before.</p>\n<p>src/index.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\">ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">App</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here's our full <code class=\"language-text\">index.js</code>. This time, we're loading the <code class=\"language-text\">Component</code> as a property of React, so we no longer need to extend <code class=\"language-text\">React.Component</code>.</p>\n<p>src/index.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">\"react-dom\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./index.css\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>App<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Hello, React!</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">App</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If you go back to <code class=\"language-text\">localhost:3000</code>, you'll see \"Hello, React!\" just like before. We have the beginnings of a React app now.</p>\n<h3><a href=\"getting-started-with-react//#react-developer-tools\"></a>React Developer Tools</h3>\n<p>There is an extension called React Developer Tools that will make your life much easier when working with React. Download <a href=\"https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi\">React DevTools for Chrome</a>, or whatever browser you prefer to work on.</p>\n<p>After you install it, when you open DevTools, you'll see a tab for React. Click on it, and you'll be able to inspect components as they're written. You can still go to the Elements tab to see the actual DOM output. It may not seem like that much of a deal now, but as the app gets more complicated, it will become increasingly necessary to use.</p>\n<p><a href=\"static/888c5b815dcc80ec278cc2c46b563afc/d2782/Screen-Shot-2018-08-18-at-3.45.11-PM.png\"><img src=\"static/888c5b815dcc80ec278cc2c46b563afc/5a190/Screen-Shot-2018-08-18-at-3.45.11-PM.png\" alt=\"Screen Shot 2018 08 18 at 3 45 11 PM\" title=\"Screen Shot 2018 08 18 at 3 45 11 PM\"></a></p>\n<p>Now we have all the tools and setup we need to actually begin working with React.</p>\n<h2><a href=\"getting-started-with-react//#jsx-javascript--xml\"></a>JSX: JavaScript + XML</h2>\n<p>As you've seen, we've been using what looks like HTML in our React code, but it's not quite HTML. This is <strong>JSX</strong>, which stands for JavaScript XML.</p>\n<p>With JSX, we can write what looks like HTML, and also we can create and use our own XML-like tags. Here's what JSX looks like assigned to a variable.</p>\n<p>JSX</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> heading <span class=\"token operator\">=</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>site-heading<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Hello, React</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Using JSX is not mandatory for writing React. Under the hood, it's running <code class=\"language-text\">createElement</code>, which takes the tag, object containing the properties, and children of the component and renders the same information. The below code will have the same output as the JSX above.</p>\n<p>No JSX</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> heading <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n  <span class=\"token string\">\"h1\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">className</span><span class=\"token operator\">:</span> <span class=\"token string\">\"site-heading\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">\"Hello, React!\"</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>JSX is actually closer to JavaScript, not HTML, so there are a few key differences to note when writing it.</p>\n<ul>\n<li><code class=\"language-text\">className</code> is used instead of <code class=\"language-text\">class</code> for adding CSS classes, as <code class=\"language-text\">class</code> is a reserved keyword in JavaScript.</li>\n<li>Properties and methods in JSX are camelCase - <code class=\"language-text\">onclick</code> will become <code class=\"language-text\">onClick</code>.</li>\n<li>Self-closing tags <em>must</em> end in a slash - e.g. <code class=\"language-text\">&lt;img /></code></li>\n</ul>\n<p>JavaScript expressions can also be embedded inside JSX using curly braces, including variables, functions, and properties.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> name <span class=\"token operator\">=</span> <span class=\"token string\">\"Tania\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> heading <span class=\"token operator\">=</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Hello, </span><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>JSX is easier to write and understand than creating and appending many elements in vanilla JavaScript, and is one of the reasons people love React so much.</p>\n<h2><a href=\"getting-started-with-react//#components\"></a>Components</h2>\n<p>So far, we've created one component - the <code class=\"language-text\">App</code> component. Almost everything in React consists of components, which can be <strong>class components</strong> or <strong>simple components</strong>.</p>\n<p>Most React apps have many small components, and everything loads into the main <code class=\"language-text\">App</code> component. Components also often get their own file, so let's change up our project to do so.</p>\n<p>Remove the <code class=\"language-text\">App</code> class from <code class=\"language-text\">index.js</code>, so it looks like this.</p>\n<p>src/index.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">\"react-dom\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> App <span class=\"token keyword\">from</span> <span class=\"token string\">\"./App\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token string\">\"./index.css\"</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">App</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"root\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We'll create a new file called <code class=\"language-text\">App.js</code> and put the component in there.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>App<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Hello, React!</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>h1</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> App<span class=\"token punctuation\">;</span></code></pre></div>\n<p>We export the component as <code class=\"language-text\">App</code> and load it in <code class=\"language-text\">index.js</code>. It's not mandatory to separate components into files, but an application will start to get unwieldy and out-of-hand if you don't.</p>\n<h3><a href=\"getting-started-with-react//#class-components\">Class Component</a></h3>\n<p>Let's create another component. We're going to create a table. Make <code class=\"language-text\">Table.js</code>, and fill it with the following data.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Table</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>table</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>thead</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Name</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Job</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>thead</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tbody</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Charlie</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Janitor</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Mac</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Bouncer</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Dee</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Aspiring actress</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Dennis</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n            </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Bartender</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n          </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tbody</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>table</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Table<span class=\"token punctuation\">;</span></code></pre></div>\n<p>This component we created is a custom class component. We capitalize custom components to differentiate them from regular HTML elements. Back in <code class=\"language-text\">App.js</code>, we can load in the Table, first by importing it in:</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> Table <span class=\"token keyword\">from</span> <span class=\"token string\">\"./Table\"</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Then by loading it into the <code class=\"language-text\">render()</code> of <code class=\"language-text\">App</code>, where before we had \"Hello, React!\". I also changed the class of the outer container.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> Table <span class=\"token keyword\">from</span> <span class=\"token string\">\"./Table\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>container<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Table</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> App<span class=\"token punctuation\">;</span></code></pre></div>\n<p>If you check back on your live environment, you'll see the <code class=\"language-text\">Table</code> loaded in.</p>\n<p><a href=\"static/2b0e0f127e4d959b70f8d325f368f196/569c6/Screen-Shot-2018-08-18-at-6.10.55-PM.png\"><img src=\"static/2b0e0f127e4d959b70f8d325f368f196/5a190/Screen-Shot-2018-08-18-at-6.10.55-PM.png\" alt=\"Screen Shot 2018 08 18 at 6 10 55 PM\" title=\"Screen Shot 2018 08 18 at 6 10 55 PM\"></a></p>\n<p>Now we've seen what a custom class component is. We could reuse this component over and over. However, since the data is hard-coded into it, it wouldn't be too useful at the moment.</p>\n<h3><a href=\"getting-started-with-react//#simple-components\">Simple Components</a></h3>\n<p>The other type of component in React is the <strong>simple component</strong>, which is a function. This component doesn't use the <code class=\"language-text\">class</code> keyword. Let's take our <code class=\"language-text\">Table</code> and make two simple components for it - a table header, and a table body.</p>\n<p>We're going to use ES6 arrow functions to create these simple components. First, the table header.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">TableHeader</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>thead</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Name</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>th</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Job</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>th</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>thead</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Then the body.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">TableBody</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tbody</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Charlie</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Janitor</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Mac</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Bouncer</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Dee</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Aspiring actress</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Dennis</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Bartender</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tbody</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Now our <code class=\"language-text\">Table</code> file will look like this. Note that the <code class=\"language-text\">TableHeader</code> and <code class=\"language-text\">TableBody</code> components are all in the same file, and being used by the <code class=\"language-text\">Table</code> class component.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">TableHeader</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span> <span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">TableBody</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span> <span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Table</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>table</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">TableHeader</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">TableBody</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>table</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Everything should appear as it did before. As you can see, components can be nested in other components, and simple and class components can be mixed.</p>\n<blockquote>\n<p>A class component must include <code class=\"language-text\">render()</code>, and the <code class=\"language-text\">return</code> can only return one parent element.</p>\n</blockquote>\n<p>As a wrap up, let's compare a simple component with a class component.</p>\n<p>Simple Component</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">SimpleComponent</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Example</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Class Component</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">ClassComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Example</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Note that if the <code class=\"language-text\">return</code> is contained to one line, it does not need parentheses.</p>\n<h2><a href=\"getting-started-with-react//#props\">Props</a></h2>\n<p>Right now, we have a cool <code class=\"language-text\">Table</code> component, but the data is being hard-coded. One of the big deals about React is how it handles data, and it does so with properties, referred to as <strong>props</strong>, and with state. Now, we'll focus on handling data with props.</p>\n<p>First, let's remove all the data from our <code class=\"language-text\">TableBody</code> component.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">TableBody</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tbody</span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Then let's move all that data to an array of objects, as if we were bringing in a JSON-based API. We'll have to create this array inside our <code class=\"language-text\">render()</code>.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> characters <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n      <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Charlie\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">job</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Janitor\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Mac\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">job</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Bouncer\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Dee\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">job</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Aspring actress\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Dennis\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">job</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Bartender\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>container<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Table</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now, we're going to pass the data through to the child component (<code class=\"language-text\">Table</code>) with properties, kind of how you might pass data through using <code class=\"language-text\">data-</code> attributes. We can call the property whatever we want, as long as it's not a reserved keyword, so I'll go with <code class=\"language-text\">characterData</code>. The data I'm passing through is the <code class=\"language-text\">characters</code> variable, and I'll put curly braces around it as it's a JavaScript expression.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>container<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Table</span></span> <span class=\"token attr-name\">characterData</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>characters<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n  </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Now that data is being passed through to <code class=\"language-text\">Table</code>, we have to work on accessing it from the other side.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Table</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> characterData <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>table</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">TableHeader</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">TableBody</span></span> <span class=\"token attr-name\">characterData</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>characterData<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>table</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>If you open up React DevTools and inspect the <code class=\"language-text\">Table</code> component, you'll see the array of data in the property. The data that's stored here is known as the <strong>virtual DOM</strong>, which is a fast and efficient way of syncing data with the actual DOM.</p>\n<p><a href=\"static/4a473290bef5435fb9aa878316de06ef/aea0a/Screen-Shot-2018-08-19-at-5.43.39-PM.png\"><img src=\"static/4a473290bef5435fb9aa878316de06ef/5a190/Screen-Shot-2018-08-19-at-5.43.39-PM.png\" alt=\"Screen Shot 2018 08 19 at 5 43 39 PM\" title=\"Screen Shot 2018 08 19 at 5 43 39 PM\"></a></p>\n<p>This data is not in the actual DOM yet, though. In <code class=\"language-text\">Table</code>, we can access all props through <code class=\"language-text\">this.props</code>. We're only passing one props through, characterData, so we'll use <code class=\"language-text\">this.props.characterData</code> to retrieve that data.</p>\n<p>I'm going to use the ES6 property shorthand to create a variable that contains <code class=\"language-text\">this.props.characterData</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> characterData <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Since our <code class=\"language-text\">Table</code> component actually consists of two smaller simple components, I'm going to pass it through to the <code class=\"language-text\">TableBody</code>, once again through props.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Table</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> characterData <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>table</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">TableHeader</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">TableBody</span></span> <span class=\"token attr-name\">characterData</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>characterData<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>table</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Right now, <code class=\"language-text\">TableBody</code> takes no parameters and returns a single tag.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">TableBody</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tbody</span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We're going to pass the props through as a parameter, and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map\">map through the array</a> to return a table row for each object in the array. This map will be contained in the <code class=\"language-text\">rows</code> variable, which we'll return as an expression.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">TableBody</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> rows <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>characterData<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">row<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span> <span class=\"token attr-name\">key</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>index<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>row<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n        </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>row<span class=\"token punctuation\">.</span>job<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tbody</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>rows<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tbody</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If you view the front end of the app, all the data is loading in now.</p>\n<p>You'll notice I've added a key index to each table row. You should always use <a href=\"https://reactjs.org/docs/lists-and-keys.html#keys\">keys</a> when making lists in React, as they help identify each list item. We'll also see how this is necessary in a moment when we want to manipulate list items.</p>\n<p>Props are an effective way to pass existing data to a React component, however the component cannot change the props - they're read-only. In the next section, we'll learn how to use state to have further control over handling data in React.</p>\n<h2><a href=\"getting-started-with-react//#state\">State</a></h2>\n<p>Right now, we're storing our character data in an array in a variable, and passing it through as props. This is good to start, but imagine if we want to be able to delete an item from the array. With props, we have a one way data flow, but with state we can update private data from a component.</p>\n<p>You can think of state as any data that should be saved and modified without necessarily being added to a database - for example, adding and removing items from a shopping cart before confirming your purchase.</p>\n<p>To start, we're going to create a <code class=\"language-text\">state</code> object.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The object will contain properties for everything you want to store in the state. For us, it's <code class=\"language-text\">characters</code>.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">characters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Move the entire array of objects we created earlier into <code class=\"language-text\">state.characters</code>.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">characters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n      <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Charlie\"</span><span class=\"token punctuation\">,</span>\n        <span class=\"token comment\">// the rest of the data</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Our data is officially contained in the state. Since we want to be able to remove a character from the table, we're going to create a <code class=\"language-text\">removeCharacter</code> method on the parent <code class=\"language-text\">App</code> class.</p>\n<p>To retrieve the state, we'll get <code class=\"language-text\">this.state.characters</code> using the same ES6 method as before. To update the state, we'll use <code class=\"language-text\">this.setState()</code>, a built-in method for manipulating state. We'll <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter\">filter the array</a> based on an <code class=\"language-text\">index</code> that we pass through, and return the new array.</p>\n<blockquote>\n<p>You must use <code class=\"language-text\">this.setState()</code> to modify an array. Simply applying a new value to <code class=\"language-text\">this.state.property</code> will not work.</p>\n</blockquote>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token function-variable function\">removeCharacter</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">index</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> characters <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">characters</span><span class=\"token operator\">:</span> characters<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">character<span class=\"token punctuation\">,</span> i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> i <span class=\"token operator\">!==</span> index<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">filter</code> does not mutate but rather creates a new array, and is a preferred method for modifying arrays in JavaScript. This particular method is testing an index vs. all the indices in the array, and returning all but the one that is passed through.</p>\n<p>Now we have to pass that function through to the component, and render a button next to each character that can invoke the function. We'll pass the <code class=\"language-text\">removeCharacter</code> function through as a prop to <code class=\"language-text\">Table</code>.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> characters <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>container<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Table</span></span> <span class=\"token attr-name\">characterData</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>characters<span class=\"token punctuation\">}</span></span> <span class=\"token attr-name\">removeCharacter</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>removeCharacter<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Since we're passing it down to <code class=\"language-text\">TableBody</code> from <code class=\"language-text\">Table</code>, we're going to have to pass it through again as a prop, just like we did with the character data.</p>\n<p>In addition, since it turns out that the only components having their own states in our project are <code class=\"language-text\">App</code> and <code class=\"language-text\">Form</code>, it would be best practice to transform <code class=\"language-text\">Table</code> into a simple component from the class component it currently is.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Table</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> characterData<span class=\"token punctuation\">,</span> removeCharacter <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>table</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">TableHeader</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">TableBody</span></span>\n        <span class=\"token attr-name\">characterData</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>characterData<span class=\"token punctuation\">}</span></span>\n        <span class=\"token attr-name\">removeCharacter</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>removeCharacter<span class=\"token punctuation\">}</span></span>\n      <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>table</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here's where that index we defined in the <code class=\"language-text\">removeCharacter()</code> method comes in. In the <code class=\"language-text\">TableBody</code> component, we'll pass the key/index through as a parameter, so the filter function knows which item to remove. We'll create a button with an <code class=\"language-text\">onClick</code> and pass it through.</p>\n<p>src/Table.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>tr</span> <span class=\"token attr-name\">key</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>index<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n  </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>row<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n  </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>row<span class=\"token punctuation\">.</span>job<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n  </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>button</span> <span class=\"token attr-name\">onClick</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> props<span class=\"token punctuation\">.</span><span class=\"token function\">removeCharacter</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Delete</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>button</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n  </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>td</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>tr</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<blockquote>\n<p>The <code class=\"language-text\">onClick</code> function must pass through a function that returns the <code class=\"language-text\">removeCharacter()</code> method, otherwise it will try to run automatically.</p>\n</blockquote>\n<p>Awesome. Now we have delete buttons, and we can modify our state by deleting a character.</p>\n<p><a href=\"static/a314736828868b35d906cd426cbb7234/f69df/Screen-Shot-2018-08-19-at-6.37.09-PM.png\"><img src=\"static/a314736828868b35d906cd426cbb7234/5a190/Screen-Shot-2018-08-19-at-6.37.09-PM.png\" alt=\"Screen Shot 2018 08 19 at 6 37 09 PM\" title=\"Screen Shot 2018 08 19 at 6 37 09 PM\"></a></p>\n<p>I deleted Mac.</p>\n<p>Now you should understand how state gets initialized and how it can be modified.</p>\n<h2><a href=\"getting-started-with-react//#submitting-form-data\">Submitting Form Data</a></h2>\n<p>Now we have data stored in state, and we can remove any item from the state. However, what if we wanted to be able to add new data to state? In a real world application, you'd more likely start with empty state and add to it, such as with a to-do list or a shopping cart.</p>\n<p>Before anything else, let's remove all the hard-coded data from <code class=\"language-text\">state.characters</code>, as we'll be updating that through the form now.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">characters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now let's go ahead and create a <code class=\"language-text\">Form</code> component in a new file called <code class=\"language-text\">Form.js</code>.</p>\n<p>We're going to set the initial state of the <code class=\"language-text\">Form</code> to be an object with some empty properties, and assign that initial state to <code class=\"language-text\">this.state</code>.</p>\n<p>src/Form.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Form</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  initialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">job</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n  state <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>initialState<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<blockquote>\n<p>Previously, it was necessary to include a <code class=\"language-text\">constructor()</code> on React class components, but it's not required anymore.</p>\n</blockquote>\n<p>Our goal for this form will be to update the state of <code class=\"language-text\">Form</code> every time a field is changed in the form, and when we submit, all that data will pass to the <code class=\"language-text\">App</code> state, which will then update the <code class=\"language-text\">Table</code>.</p>\n<p>First, we'll make the function that will run every time a change is made to an input. The <code class=\"language-text\">event</code> will be passed through, and we'll set the state of <code class=\"language-text\">Form</code> to have the <code class=\"language-text\">name</code> (key) and <code class=\"language-text\">value</code> of the inputs.</p>\n<p>src/Form.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token function-variable function\">handleChange</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> name<span class=\"token punctuation\">,</span> value <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token punctuation\">[</span>name<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> value<span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Let's get this working before we move on to submitting the form. In the render, let's get our two properties from state, and assign them as the values that correspond to the proper form keys. We'll run the <code class=\"language-text\">handleChange()</code> method as the <code class=\"language-text\">onChange</code> of the input, and finally we'll export the <code class=\"language-text\">Form</code> component.</p>\n<p>src/Form.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> name<span class=\"token punctuation\">,</span> job <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>form</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>label</span> <span class=\"token attr-name\">htmlFor</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>name<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Name</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>label</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>input</span>\n        <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>text<span class=\"token punctuation\">\"</span></span>\n        <span class=\"token attr-name\">name</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>name<span class=\"token punctuation\">\"</span></span>\n        <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>name<span class=\"token punctuation\">\"</span></span>\n        <span class=\"token attr-name\">value</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span></span>\n        <span class=\"token attr-name\">onChange</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>label</span> <span class=\"token attr-name\">htmlFor</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>job<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Job</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>label</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>input</span>\n        <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>text<span class=\"token punctuation\">\"</span></span>\n        <span class=\"token attr-name\">name</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>job<span class=\"token punctuation\">\"</span></span>\n        <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>job<span class=\"token punctuation\">\"</span></span>\n        <span class=\"token attr-name\">value</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>job<span class=\"token punctuation\">}</span></span>\n        <span class=\"token attr-name\">onChange</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>form</span><span class=\"token punctuation\">></span></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> Form<span class=\"token punctuation\">;</span></code></pre></div>\n<p>In <code class=\"language-text\">App.js</code>, we can render the form below the table.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> Form <span class=\"token keyword\">from</span> <span class=\"token string\">\"./Form\"</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">className</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>container<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Table</span></span> <span class=\"token attr-name\">characterData</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>characters<span class=\"token punctuation\">}</span></span> <span class=\"token attr-name\">removeCharacter</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>removeCharacter<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Form</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token plain-text\">\n  </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Now if we go to the front end of our app, we'll see a form that doesn't have a submit yet. Update some fields and you'll see the local state of <code class=\"language-text\">Form</code> being updated.</p>\n<p><a href=\"static/faf2c33e4383a065a6d5d0705b48658c/71dc1/Screen-Shot-2018-08-19-at-7.55.56-PM.png\"><img src=\"static/faf2c33e4383a065a6d5d0705b48658c/5a190/Screen-Shot-2018-08-19-at-7.55.56-PM.png\" alt=\"Screen Shot 2018 08 19 at 7 55 56 PM\" title=\"Screen Shot 2018 08 19 at 7 55 56 PM\"></a></p>\n<p>Cool. Last step is to allow us to actually submit that data and update the parent state. We'll create a function called <code class=\"language-text\">handleSubmit()</code> on <code class=\"language-text\">App</code> that will update the state by taking the existing <code class=\"language-text\">this.state.characters</code> and adding the new <code class=\"language-text\">character</code> parameter, using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax\">ES6 spread operator</a>.</p>\n<p>src/App.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token function-variable function\">handleSubmit</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">character</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">characters</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>characters<span class=\"token punctuation\">,</span> character<span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Let's make sure we pass that through as a parameter on <code class=\"language-text\">Form</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">Form</span></span> <span class=\"token attr-name\">handleSubmit</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSubmit<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span></code></pre></div>\n<p>Now in <code class=\"language-text\">Form</code>, we'll create a method called <code class=\"language-text\">submitForm()</code> that will call that function, and pass the <code class=\"language-text\">Form</code> state through as the <code class=\"language-text\">character</code> parameter we defined earlier. It will also reset the state to the initial state, to clear the form after submit.</p>\n<p>src/Form.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token function-variable function\">submitForm</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span><span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>initialState<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Finally, we'll add a submit button to submit the form. We're using an <code class=\"language-text\">onClick</code> instead of an <code class=\"language-text\">onSubmit</code> since we're not using the standard submit functionality. The click will call the <code class=\"language-text\">submitForm</code> we just made.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>input</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">value</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>Submit<span class=\"token punctuation\">\"</span></span> <span class=\"token attr-name\">onClick</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>submitForm<span class=\"token punctuation\">}</span></span> <span class=\"token punctuation\">/></span></span></code></pre></div>\n<p>And that's it! The app is complete. We can create, add, and remove users from our table. Since the <code class=\"language-text\">Table</code> and <code class=\"language-text\">TableBody</code> were already pulling from the state, it will display properly.</p>\n<p><a href=\"static/5d0c857d6373c593016654a4f40fe9f3/b2313/Screen-Shot-2018-08-19-at-9.33.59-PM.png\"><img src=\"static/5d0c857d6373c593016654a4f40fe9f3/5a190/Screen-Shot-2018-08-19-at-9.33.59-PM.png\" alt=\"Screen Shot 2018 08 19 at 9 33 59 PM\" title=\"Screen Shot 2018 08 19 at 9 33 59 PM\"></a></p>\n<p>If you got lost anywhere along the way, you can view <a href=\"https://github.com/taniarascia/react-tutorial\">the complete source on GitHub</a>.</p>\n<h2><a href=\"getting-started-with-react//#pulling-in-api-data\"></a>Pulling in API Data</h2>\n<p>One very common usage of React is pulling in data from an API. If you're not familiar with what an API is or how to connect to one, I would recommend reading <a href=\"how-to-connect-to-an-api-with-javascript/\">How to Connect to an API with JavaScript</a>, which will walk you through what APIs are and how to use them with vanilla JavaScript.</p>\n<p>As a little test, we can create a new <code class=\"language-text\">Api.js</code> file, and create a new <code class=\"language-text\">App</code> in there. A public API we can test with is the <a href=\"https://en.wikipedia.org/w/api.php\">Wikipedia API</a>, and I have a <a href=\"https://en.wikipedia.org/w/api.php?action=opensearch&#x26;search=Seona+Dancing&#x26;format=json&#x26;origin=*\">URL endpoint right here</a> for a random* search. You can go to that link to see the API - and make sure you have <a href=\"https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc\">JSONView</a> installed on your browser.</p>\n<p>We're going to use <a href=\"how-to-use-the-javascript-fetch-api-to-get-json-data/\">JavaScript's built-in Fetch</a> to gather the data from that URL endpoint and display it. You can switch between the app we created and this test file by just changing the URL in <code class=\"language-text\">index.js</code> - <code class=\"language-text\">import App from './Api';</code>.</p>\n<p>I'm not going to explain this code line-by-line, as we've already learned about creating a component, rendering, and mapping through a state array. The new aspect to this code is <code class=\"language-text\">componentDidMount()</code>, a React lifecycle method. <strong>Lifecycle</strong> is the order in which methods are called in React. <strong>Mounting</strong> refers to an item being inserted into the DOM.</p>\n<p>When we pull in API data, we want to use <code class=\"language-text\">componentDidMount</code>, because we want to make sure the component has rendered to the DOM before we bring in the data. In the below snippet, you'll see how we bring in data from the Wikipedia API, and display it on the page</p>\n<p>Api.js</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"language-jsx\"><code class=\"language-jsx\"><span class=\"token keyword\">import</span> React<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> Component <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">\"react\"</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">data</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token comment\">// Code is invoked after the component is mounted/inserted into the DOM tree.</span>\n  <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> url <span class=\"token operator\">=</span>\n      <span class=\"token string\">\"https://en.wikipedia.org/w/api.php?action=opensearch&amp;search=Seona+Dancing&amp;format=json&amp;origin=*\"</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span>\n      <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> result<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n      <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n          <span class=\"token literal-property property\">data</span><span class=\"token operator\">:</span> result<span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> data <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> data<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">entry<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>li</span> <span class=\"token attr-name\">key</span><span class=\"token script language-javascript\"><span class=\"token script-punctuation punctuation\">=</span><span class=\"token punctuation\">{</span>index<span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>entry<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>li</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>ul</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">{</span>result<span class=\"token punctuation\">}</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>ul</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> App<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Once you save and run this file in the local server, you'll see the Wikipedia API data displayed in the DOM.</p>\n<p><a href=\"static/a76c1cea3c47b440f00a75fb2d004084/b2313/Screen-Shot-2018-08-19-at-10.12.41-PM.png\"><img src=\"static/a76c1cea3c47b440f00a75fb2d004084/5a190/Screen-Shot-2018-08-19-at-10.12.41-PM.png\" alt=\"Screen Shot 2018 08 19 at 10 12 41 PM\" title=\"Screen Shot 2018 08 19 at 10 12 41 PM\"></a></p>\n<p>There are other lifecycle methods, but going over them will be beyond the scope of this article. You can <a href=\"https://reactjs.org/docs/react-component.html\">read more about React components here</a>.</p>\n<p><em>*Wikipedia search choice may not be random. It might be an article that I spearheaded back in 2005.</em></p>\n<h2><a href=\"getting-started-with-react//#building-and-deploying-a-react-app\"></a>Building and Deploying a React App</h2>\n<p>Everything we've done so far has been in a development environment. We've been compiling, hot-reloading, and updating on the fly. For production, we're going to want to have static files loading in - none of the source code. We can do this by making a build and deploying it.</p>\n<p>Now, if you just want to compile all the React code and place it in the root of a directory somewhere, all you need to do is run the following line:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> run build</code></pre></div>\n<p>This will create a <code class=\"language-text\">build</code> folder which will contain your app. Put the contents of that folder anywhere, and you're done!</p>\n<p>We can also take it a step further, and have npm deploy for us. We're going to build to GitHub pages, so you'll already have to <a href=\"getting-started-with-git/\">be familiar with Git</a> and getting your code up on GitHub.</p>\n<p>Make sure you've exited out of your local React environment, so the code isn't currently running. First, we're going to add a <code class=\"language-text\">homepage</code> field to <code class=\"language-text\">package.json</code>, that has the URL we want our app to live on.</p>\n<p>package.json</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token string-property property\">\"homepage\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">,</span></code></pre></div>\n<p>We'll also add these two lines to the <code class=\"language-text\">scripts</code> property.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token string-property property\">\"scripts\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// ...</span>\n  <span class=\"token string-property property\">\"predeploy\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"npm run build\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string-property property\">\"deploy\"</span><span class=\"token operator\">:</span> <span class=\"token string\">\"gh-pages -d build\"</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>In your project, you'll add <code class=\"language-text\">gh-pages</code> to the devDependencies.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> --save-dev gh-pages</code></pre></div>\n<p>We'll create the <code class=\"language-text\">build</code>, which will have all the compiled, static files.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> run build</code></pre></div>\n<p>Finally, we'll deploy to <code class=\"language-text\">gh-pages</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> run deploy</code></pre></div>\n<p>And we're done! The app is now available live at</p>"},{"url":"/blog/eslint-rules/","relativePath":"blog/eslint-rules.md","relativeDir":"blog","base":"eslint-rules.md","name":"eslint-rules","frontmatter":{"title":" ESLint Rules","template":"post","subtitle":"Rules in ESLint are grouped by type to help you understand their purpose","excerpt":"These rules relate to possible logic errors in cod","date":"2022-05-22T22:42:01.526Z","image":"https://i.ytimg.com/vi/SydnKbGc7W8/maxresdefault.jpg","thumb_image":"https://i.ytimg.com/vi/SydnKbGc7W8/maxresdefault.jpg","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/js.yaml","src/data/categories/git.yaml"],"tags":["src/data/tags/cms.yaml","src/data/tags/javascript.yaml","src/data/tags/links.yaml","src/data/tags/resources.yaml"],"show_author_bio":true,"cmseditable":true},"html":"<!--StartFragment-->\n<h1>Rules</h1>\n<p>Rules in ESLint are grouped by type to help you understand their purpose. Each rule has emojis denoting:</p>\n<p>if the <code class=\"language-text\">\"extends\": \"eslint:recommended\"</code> property in a <a href=\"https://eslint.org/docs/user-guide/configuring#extending-configuration-files\">configuration file</a> enables the rule</p>\n<p>if some problems reported by the rule are automatically fixable by the <code class=\"language-text\">--fix</code> <a href=\"https://eslint.org/docs/user-guide/command-line-interface#--fix\">command line</a> option</p>\n<p>if some problems reported by the rule are manually fixable by editor <a href=\"https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions\">suggestions</a></p>\n<h2>Possible Problems<a href=\"https://eslint.org/docs/rules/#possible-problems\"></a></h2>\n<p>These rules relate to possible logic errors in code:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/array-callback-return\">array-callback-return</a></td>\n<td>enforce `return` statements in callbacks of array methods</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/constructor-super\">constructor-super</a></td>\n<td>require `super()` calls in constructors</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/for-direction\">for-direction</a></td>\n<td>enforce \"for\" loop update clause moving the counter in the right direction.</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/getter-return\">getter-return</a></td>\n<td>enforce `return` statements in getters</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-async-promise-executor\">no-async-promise-executor</a></td>\n<td>disallow using an async function as a Promise executor</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-await-in-loop\">no-await-in-loop</a></td>\n<td>disallow `await` inside of loops</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-class-assign\">no-class-assign</a></td>\n<td>disallow reassigning class members</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-compare-neg-zero\">no-compare-neg-zero</a></td>\n<td>disallow comparing against -0</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-cond-assign\">no-cond-assign</a></td>\n<td>disallow assignment operators in conditional expressions</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-const-assign\">no-const-assign</a></td>\n<td>disallow reassigning `const` variables</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-constant-binary-expression\">no-constant-binary-expression</a></td>\n<td>disallow expressions where the operation doesn't affect the value</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-constant-condition\">no-constant-condition</a></td>\n<td>disallow constant expressions in conditions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-constructor-return\">no-constructor-return</a></td>\n<td>disallow returning value from constructor</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-control-regex\">no-control-regex</a></td>\n<td>disallow control characters in regular expressions</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-debugger\">no-debugger</a></td>\n<td>disallow the use of `debugger`</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-dupe-args\">no-dupe-args</a></td>\n<td>disallow duplicate arguments in `function` definitions</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-dupe-class-members\">no-dupe-class-members</a></td>\n<td>disallow duplicate class members</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-dupe-else-if\">no-dupe-else-if</a></td>\n<td>disallow duplicate conditions in if-else-if chains</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-dupe-keys\">no-dupe-keys</a></td>\n<td>disallow duplicate keys in object literals</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-duplicate-case\">no-duplicate-case</a></td>\n<td>disallow duplicate case labels</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-duplicate-imports\">no-duplicate-imports</a></td>\n<td>disallow duplicate module imports</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-empty-character-class\">no-empty-character-class</a></td>\n<td>disallow empty character classes in regular expressions</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-empty-pattern\">no-empty-pattern</a></td>\n<td>disallow empty destructuring patterns</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-ex-assign\">no-ex-assign</a></td>\n<td>disallow reassigning exceptions in `catch` clauses</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-fallthrough\">no-fallthrough</a></td>\n<td>disallow fallthrough of `case` statements</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-func-assign\">no-func-assign</a></td>\n<td>disallow reassigning `function` declarations</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-import-assign\">no-import-assign</a></td>\n<td>disallow assigning to imported bindings</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-inner-declarations\">no-inner-declarations</a></td>\n<td>disallow variable or `function` declarations in nested blocks</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-invalid-regexp\">no-invalid-regexp</a></td>\n<td>disallow invalid regular expression strings in `RegExp` constructors</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-irregular-whitespace\">no-irregular-whitespace</a></td>\n<td>disallow irregular whitespace</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-loss-of-precision\">no-loss-of-precision</a></td>\n<td>disallow literal numbers that lose precision</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td>💡</td>\n<td><a href=\"https://eslint.org/docs/rules/no-misleading-character-class\">no-misleading-character-class</a></td>\n<td>disallow characters which are made with multiple code points in character class syntax</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-new-symbol\">no-new-symbol</a></td>\n<td>disallow `new` operators with the `Symbol` object</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-obj-calls\">no-obj-calls</a></td>\n<td>disallow calling global object properties as functions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-promise-executor-return\">no-promise-executor-return</a></td>\n<td>disallow returning values from Promise executor functions</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-prototype-builtins\">no-prototype-builtins</a></td>\n<td>disallow calling some `Object.prototype` methods directly on objects</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-self-assign\">no-self-assign</a></td>\n<td>disallow assignments where both sides are exactly the same</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-self-compare\">no-self-compare</a></td>\n<td>disallow comparisons where both sides are exactly the same</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-setter-return\">no-setter-return</a></td>\n<td>disallow returning values from setters</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-sparse-arrays\">no-sparse-arrays</a></td>\n<td>disallow sparse arrays</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-template-curly-in-string\">no-template-curly-in-string</a></td>\n<td>disallow template literal placeholder syntax in regular strings</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-this-before-super\">no-this-before-super</a></td>\n<td>disallow `this`/`super` before calling `super()` in constructors</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-undef\">no-undef</a></td>\n<td>disallow the use of undeclared variables unless mentioned in `/*global */` comments</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unexpected-multiline\">no-unexpected-multiline</a></td>\n<td>disallow confusing multiline expressions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unmodified-loop-condition\">no-unmodified-loop-condition</a></td>\n<td>disallow unmodified loop conditions</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unreachable\">no-unreachable</a></td>\n<td>disallow unreachable code after `return`, `throw`, `continue`, and `break` statements</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unreachable-loop\">no-unreachable-loop</a></td>\n<td>disallow loops with a body that allows only one iteration</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unsafe-finally\">no-unsafe-finally</a></td>\n<td>disallow control flow statements in `finally` blocks</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td>💡</td>\n<td><a href=\"https://eslint.org/docs/rules/no-unsafe-negation\">no-unsafe-negation</a></td>\n<td>disallow negating the left operand of relational operators</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unsafe-optional-chaining\">no-unsafe-optional-chaining</a></td>\n<td>disallow use of optional chaining in contexts where the `undefined` value is not allowed</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unused-private-class-members\">no-unused-private-class-members</a></td>\n<td>disallow unused private class members</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unused-vars\">no-unused-vars</a></td>\n<td>disallow unused variables</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-use-before-define\">no-use-before-define</a></td>\n<td>disallow the use of variables before they are defined</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-backreference\">no-useless-backreference</a></td>\n<td>disallow useless backreferences in regular expressions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/require-atomic-updates\">require-atomic-updates</a></td>\n<td>disallow assignments that can lead to race conditions due to usage of `await` or `yield`</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/use-isnan\">use-isnan</a></td>\n<td>require calls to `isNaN()` when checking for `NaN`</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td>💡</td>\n<td><a href=\"https://eslint.org/docs/rules/valid-typeof\">valid-typeof</a></td>\n<td>enforce comparing `typeof` expressions against valid strings</td>\n</tr>\n</tbody>\n</table>\n<h2>Suggestions<a href=\"https://eslint.org/docs/rules/#suggestions\"></a></h2>\n<p>These rules suggest alternate ways of doing things:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/accessor-pairs\">accessor-pairs</a></td>\n<td>enforce getter and setter pairs in objects and classes</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/arrow-body-style\">arrow-body-style</a></td>\n<td>require braces around arrow function bodies</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/block-scoped-var\">block-scoped-var</a></td>\n<td>enforce the use of variables within the scope they are defined</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/camelcase\">camelcase</a></td>\n<td>enforce camelcase naming convention</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/capitalized-comments\">capitalized-comments</a></td>\n<td>enforce or disallow capitalization of the first letter of a comment</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/class-methods-use-this\">class-methods-use-this</a></td>\n<td>enforce that class methods utilize `this`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/complexity\">complexity</a></td>\n<td>enforce a maximum cyclomatic complexity allowed in a program</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/consistent-return\">consistent-return</a></td>\n<td>require `return` statements to either always or never specify values</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/consistent-this\">consistent-this</a></td>\n<td>enforce consistent naming when capturing the current execution context</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/curly\">curly</a></td>\n<td>enforce consistent brace style for all control statements</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/default-case\">default-case</a></td>\n<td>require `default` cases in `switch` statements</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/default-case-last\">default-case-last</a></td>\n<td>enforce default clauses in switch statements to be last</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/default-param-last\">default-param-last</a></td>\n<td>enforce default parameters to be last</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/dot-notation\">dot-notation</a></td>\n<td>enforce dot notation whenever possible</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/eqeqeq\">eqeqeq</a></td>\n<td>require the use of `===` and `!==`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/func-name-matching\">func-name-matching</a></td>\n<td>require function names to match the name of the variable or property to which they are assigned</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/func-names\">func-names</a></td>\n<td>require or disallow named `function` expressions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/func-style\">func-style</a></td>\n<td>enforce the consistent use of either `function` declarations or expressions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/grouped-accessor-pairs\">grouped-accessor-pairs</a></td>\n<td>require grouped accessor pairs in object literals and classes</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/guard-for-in\">guard-for-in</a></td>\n<td>require `for-in` loops to include an `if` statement</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/id-denylist\">id-denylist</a></td>\n<td>disallow specified identifiers</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/id-length\">id-length</a></td>\n<td>enforce minimum and maximum identifier lengths</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/id-match\">id-match</a></td>\n<td>require identifiers to match a specified regular expression</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/init-declarations\">init-declarations</a></td>\n<td>require or disallow initialization in variable declarations</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-classes-per-file\">max-classes-per-file</a></td>\n<td>enforce a maximum number of classes per file</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-depth\">max-depth</a></td>\n<td>enforce a maximum depth that blocks can be nested</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-lines\">max-lines</a></td>\n<td>enforce a maximum number of lines per file</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-lines-per-function\">max-lines-per-function</a></td>\n<td>enforce a maximum number of lines of code in a function</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-nested-callbacks\">max-nested-callbacks</a></td>\n<td>enforce a maximum depth that callbacks can be nested</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-params\">max-params</a></td>\n<td>enforce a maximum number of parameters in function definitions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-statements\">max-statements</a></td>\n<td>enforce a maximum number of statements allowed in function blocks</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/multiline-comment-style\">multiline-comment-style</a></td>\n<td>enforce a particular style for multiline comments</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/new-cap\">new-cap</a></td>\n<td>require constructor names to begin with a capital letter</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-alert\">no-alert</a></td>\n<td>disallow the use of `alert`, `confirm`, and `prompt`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-array-constructor\">no-array-constructor</a></td>\n<td>disallow `Array` constructors</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-bitwise\">no-bitwise</a></td>\n<td>disallow bitwise operators</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-caller\">no-caller</a></td>\n<td>disallow the use of `arguments.caller` or `arguments.callee`</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-case-declarations\">no-case-declarations</a></td>\n<td>disallow lexical declarations in case clauses</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-confusing-arrow\">no-confusing-arrow</a></td>\n<td>disallow arrow functions where they could be confused with comparisons</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-console\">no-console</a></td>\n<td>disallow the use of `console`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-continue\">no-continue</a></td>\n<td>disallow `continue` statements</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-delete-var\">no-delete-var</a></td>\n<td>disallow deleting variables</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-div-regex\">no-div-regex</a></td>\n<td>disallow division operators explicitly at the beginning of regular expressions</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-else-return\">no-else-return</a></td>\n<td>disallow `else` blocks after `return` statements in `if` statements</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-empty\">no-empty</a></td>\n<td>disallow empty block statements</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-empty-function\">no-empty-function</a></td>\n<td>disallow empty functions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-eq-null\">no-eq-null</a></td>\n<td>disallow `null` comparisons without type-checking operators</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-eval\">no-eval</a></td>\n<td>disallow the use of `eval()`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-extend-native\">no-extend-native</a></td>\n<td>disallow extending native types</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-extra-bind\">no-extra-bind</a></td>\n<td>disallow unnecessary calls to `.bind()`</td>\n</tr>\n<tr>\n<td>✓</td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-extra-boolean-cast\">no-extra-boolean-cast</a></td>\n<td>disallow unnecessary boolean casts</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-extra-label\">no-extra-label</a></td>\n<td>disallow unnecessary labels</td>\n</tr>\n<tr>\n<td>✓</td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-extra-semi\">no-extra-semi</a></td>\n<td>disallow unnecessary semicolons</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-floating-decimal\">no-floating-decimal</a></td>\n<td>disallow leading or trailing decimal points in numeric literals</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-global-assign\">no-global-assign</a></td>\n<td>disallow assignments to native objects or read-only global variables</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-implicit-coercion\">no-implicit-coercion</a></td>\n<td>disallow shorthand type conversions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-implicit-globals\">no-implicit-globals</a></td>\n<td>disallow declarations in the global scope</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-implied-eval\">no-implied-eval</a></td>\n<td>disallow the use of `eval()`-like methods</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-inline-comments\">no-inline-comments</a></td>\n<td>disallow inline comments after code</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-invalid-this\">no-invalid-this</a></td>\n<td>disallow use of `this` in contexts where the value of `this` is `undefined`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-iterator\">no-iterator</a></td>\n<td>disallow the use of the `__iterator__` property</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-label-var\">no-label-var</a></td>\n<td>disallow labels that share a name with a variable</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-labels\">no-labels</a></td>\n<td>disallow labeled statements</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-lone-blocks\">no-lone-blocks</a></td>\n<td>disallow unnecessary nested blocks</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-lonely-if\">no-lonely-if</a></td>\n<td>disallow `if` statements as the only statement in `else` blocks</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-loop-func\">no-loop-func</a></td>\n<td>disallow function declarations that contain unsafe references inside loop statements</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-magic-numbers\">no-magic-numbers</a></td>\n<td>disallow magic numbers</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-mixed-operators\">no-mixed-operators</a></td>\n<td>disallow mixed binary operators</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-multi-assign\">no-multi-assign</a></td>\n<td>disallow use of chained assignment expressions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-multi-str\">no-multi-str</a></td>\n<td>disallow multiline strings</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-negated-condition\">no-negated-condition</a></td>\n<td>disallow negated conditions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-nested-ternary\">no-nested-ternary</a></td>\n<td>disallow nested ternary expressions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-new\">no-new</a></td>\n<td>disallow `new` operators outside of assignments or comparisons</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-new-func\">no-new-func</a></td>\n<td>disallow `new` operators with the `Function` object</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-new-object\">no-new-object</a></td>\n<td>disallow `Object` constructors</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-new-wrappers\">no-new-wrappers</a></td>\n<td>disallow `new` operators with the `String`, `Number`, and `Boolean` objects</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td>💡</td>\n<td><a href=\"https://eslint.org/docs/rules/no-nonoctal-decimal-escape\">no-nonoctal-decimal-escape</a></td>\n<td>disallow `\\8` and `\\9` escape sequences in string literals</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-octal\">no-octal</a></td>\n<td>disallow octal literals</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-octal-escape\">no-octal-escape</a></td>\n<td>disallow octal escape sequences in string literals</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-param-reassign\">no-param-reassign</a></td>\n<td>disallow reassigning `function` parameters</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-plusplus\">no-plusplus</a></td>\n<td>disallow the unary operators `++` and `--`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-proto\">no-proto</a></td>\n<td>disallow the use of the `__proto__` property</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-redeclare\">no-redeclare</a></td>\n<td>disallow variable redeclaration</td>\n</tr>\n<tr>\n<td>✓</td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-regex-spaces\">no-regex-spaces</a></td>\n<td>disallow multiple spaces in regular expressions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-restricted-exports\">no-restricted-exports</a></td>\n<td>disallow specified names in exports</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-restricted-globals\">no-restricted-globals</a></td>\n<td>disallow specified global variables</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-restricted-imports\">no-restricted-imports</a></td>\n<td>disallow specified modules when loaded by `import`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-restricted-properties\">no-restricted-properties</a></td>\n<td>disallow certain properties on certain objects</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-restricted-syntax\">no-restricted-syntax</a></td>\n<td>disallow specified syntax</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-return-assign\">no-return-assign</a></td>\n<td>disallow assignment operators in `return` statements</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-return-await\">no-return-await</a></td>\n<td>disallow unnecessary `return await`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-script-url\">no-script-url</a></td>\n<td>disallow `javascript:` urls</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-sequences\">no-sequences</a></td>\n<td>disallow comma operators</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-shadow\">no-shadow</a></td>\n<td>disallow variable declarations from shadowing variables declared in the outer scope</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-shadow-restricted-names\">no-shadow-restricted-names</a></td>\n<td>disallow identifiers from shadowing restricted names</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-ternary\">no-ternary</a></td>\n<td>disallow ternary operators</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-throw-literal\">no-throw-literal</a></td>\n<td>disallow throwing literals as exceptions</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-undef-init\">no-undef-init</a></td>\n<td>disallow initializing variables to `undefined`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-undefined\">no-undefined</a></td>\n<td>disallow the use of `undefined` as an identifier</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-underscore-dangle\">no-underscore-dangle</a></td>\n<td>disallow dangling underscores in identifiers</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unneeded-ternary\">no-unneeded-ternary</a></td>\n<td>disallow ternary operators when simpler alternatives exist</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unused-expressions\">no-unused-expressions</a></td>\n<td>disallow unused expressions</td>\n</tr>\n<tr>\n<td>✓</td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unused-labels\">no-unused-labels</a></td>\n<td>disallow unused labels</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-call\">no-useless-call</a></td>\n<td>disallow unnecessary calls to `.call()` and `.apply()`</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-catch\">no-useless-catch</a></td>\n<td>disallow unnecessary `catch` clauses</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-computed-key\">no-useless-computed-key</a></td>\n<td>disallow unnecessary computed property keys in objects and classes</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-concat\">no-useless-concat</a></td>\n<td>disallow unnecessary concatenation of literals or template literals</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-constructor\">no-useless-constructor</a></td>\n<td>disallow unnecessary constructors</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td>💡</td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-escape\">no-useless-escape</a></td>\n<td>disallow unnecessary escape characters</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-rename\">no-useless-rename</a></td>\n<td>disallow renaming import, export, and destructured assignments to the same name</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-useless-return\">no-useless-return</a></td>\n<td>disallow redundant return statements</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-var\">no-var</a></td>\n<td>require `let` or `const` instead of `var`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-void\">no-void</a></td>\n<td>disallow `void` operators</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-warning-comments\">no-warning-comments</a></td>\n<td>disallow specified warning terms in comments</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-with\">no-with</a></td>\n<td>disallow `with` statements</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/object-shorthand\">object-shorthand</a></td>\n<td>require or disallow method and property shorthand syntax for object literals</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/one-var\">one-var</a></td>\n<td>enforce variables to be declared either together or separately in functions</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/one-var-declaration-per-line\">one-var-declaration-per-line</a></td>\n<td>require or disallow newlines around variable declarations</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/operator-assignment\">operator-assignment</a></td>\n<td>require or disallow assignment operator shorthand where possible</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-arrow-callback\">prefer-arrow-callback</a></td>\n<td>require using arrow functions for callbacks</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-const\">prefer-const</a></td>\n<td>require `const` declarations for variables that are never reassigned after declared</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-destructuring\">prefer-destructuring</a></td>\n<td>require destructuring from arrays and/or objects</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-exponentiation-operator\">prefer-exponentiation-operator</a></td>\n<td>disallow the use of `Math.pow` in favor of the `**` operator</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-named-capture-group\">prefer-named-capture-group</a></td>\n<td>enforce using named capture group in regular expression</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-numeric-literals\">prefer-numeric-literals</a></td>\n<td>disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-object-has-own\">prefer-object-has-own</a></td>\n<td>disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-object-spread\">prefer-object-spread</a></td>\n<td>disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-promise-reject-errors\">prefer-promise-reject-errors</a></td>\n<td>require using Error objects as Promise rejection reasons</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td>💡</td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-regex-literals\">prefer-regex-literals</a></td>\n<td>disallow use of the `RegExp` constructor in favor of regular expression literals</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-rest-params\">prefer-rest-params</a></td>\n<td>require rest parameters instead of `arguments`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-spread\">prefer-spread</a></td>\n<td>require spread operators instead of `.apply()`</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/prefer-template\">prefer-template</a></td>\n<td>require template literals instead of string concatenation</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/quote-props\">quote-props</a></td>\n<td>require quotes around object literal property names</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td>💡</td>\n<td><a href=\"https://eslint.org/docs/rules/radix\">radix</a></td>\n<td>enforce the consistent use of the radix argument when using `parseInt()`</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/require-await\">require-await</a></td>\n<td>disallow async functions which have no `await` expression</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/require-unicode-regexp\">require-unicode-regexp</a></td>\n<td>enforce the use of `u` flag on RegExp</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/require-yield\">require-yield</a></td>\n<td>require generator functions to contain `yield`</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/sort-imports\">sort-imports</a></td>\n<td>enforce sorted import declarations within modules</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/sort-keys\">sort-keys</a></td>\n<td>require object keys to be sorted</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/sort-vars\">sort-vars</a></td>\n<td>require variables within the same declaration block to be sorted</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/spaced-comment\">spaced-comment</a></td>\n<td>enforce consistent spacing after the `//` or `/*` in a comment</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/strict\">strict</a></td>\n<td>require or disallow strict mode directives</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/symbol-description\">symbol-description</a></td>\n<td>require symbol descriptions</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/vars-on-top\">vars-on-top</a></td>\n<td>require `var` declarations be placed at the top of their containing scope</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/yoda\">yoda</a></td>\n<td>require or disallow \"Yoda\" conditions</td>\n</tr>\n</tbody>\n</table>\n<h2>Layout &#x26; Formatting<a href=\"https://eslint.org/docs/rules/#layout-formatting\"></a></h2>\n<p>These rules care about how the code looks rather than how it executes:</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/array-bracket-newline\">array-bracket-newline</a></td>\n<td>enforce linebreaks after opening and before closing array brackets</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/array-bracket-spacing\">array-bracket-spacing</a></td>\n<td>enforce consistent spacing inside array brackets</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/array-element-newline\">array-element-newline</a></td>\n<td>enforce line breaks after each array element</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/arrow-parens\">arrow-parens</a></td>\n<td>require parentheses around arrow function arguments</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/arrow-spacing\">arrow-spacing</a></td>\n<td>enforce consistent spacing before and after the arrow in arrow functions</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/block-spacing\">block-spacing</a></td>\n<td>disallow or enforce spaces inside of blocks after opening block and before closing block</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/brace-style\">brace-style</a></td>\n<td>enforce consistent brace style for blocks</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/comma-dangle\">comma-dangle</a></td>\n<td>require or disallow trailing commas</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/comma-spacing\">comma-spacing</a></td>\n<td>enforce consistent spacing before and after commas</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/comma-style\">comma-style</a></td>\n<td>enforce consistent comma style</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/computed-property-spacing\">computed-property-spacing</a></td>\n<td>enforce consistent spacing inside computed property brackets</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/dot-location\">dot-location</a></td>\n<td>enforce consistent newlines before and after dots</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/eol-last\">eol-last</a></td>\n<td>require or disallow newline at the end of files</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/func-call-spacing\">func-call-spacing</a></td>\n<td>require or disallow spacing between function identifiers and their invocations</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/function-call-argument-newline\">function-call-argument-newline</a></td>\n<td>enforce line breaks between arguments of a function call</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/function-paren-newline\">function-paren-newline</a></td>\n<td>enforce consistent line breaks inside function parentheses</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/generator-star-spacing\">generator-star-spacing</a></td>\n<td>enforce consistent spacing around `*` operators in generator functions</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/implicit-arrow-linebreak\">implicit-arrow-linebreak</a></td>\n<td>enforce the location of arrow function bodies</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/indent\">indent</a></td>\n<td>enforce consistent indentation</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/jsx-quotes\">jsx-quotes</a></td>\n<td>enforce the consistent use of either double or single quotes in JSX attributes</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/key-spacing\">key-spacing</a></td>\n<td>enforce consistent spacing between keys and values in object literal properties</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/keyword-spacing\">keyword-spacing</a></td>\n<td>enforce consistent spacing before and after keywords</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/line-comment-position\">line-comment-position</a></td>\n<td>enforce position of line comments</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/linebreak-style\">linebreak-style</a></td>\n<td>enforce consistent linebreak style</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/lines-around-comment\">lines-around-comment</a></td>\n<td>require empty lines around comments</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/lines-between-class-members\">lines-between-class-members</a></td>\n<td>require or disallow an empty line between class members</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-len\">max-len</a></td>\n<td>enforce a maximum line length</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/max-statements-per-line\">max-statements-per-line</a></td>\n<td>enforce a maximum number of statements allowed per line</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/multiline-ternary\">multiline-ternary</a></td>\n<td>enforce newlines between operands of ternary expressions</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/new-parens\">new-parens</a></td>\n<td>enforce or disallow parentheses when invoking a constructor with no arguments</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/newline-per-chained-call\">newline-per-chained-call</a></td>\n<td>require a newline after each call in a method chain</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-extra-parens\">no-extra-parens</a></td>\n<td>disallow unnecessary parentheses</td>\n</tr>\n<tr>\n<td>✓</td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-mixed-spaces-and-tabs\">no-mixed-spaces-and-tabs</a></td>\n<td>disallow mixed spaces and tabs for indentation</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-multi-spaces\">no-multi-spaces</a></td>\n<td>disallow multiple spaces</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-multiple-empty-lines\">no-multiple-empty-lines</a></td>\n<td>disallow multiple empty lines</td>\n</tr>\n<tr>\n<td></td>\n<td></td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-tabs\">no-tabs</a></td>\n<td>disallow all tabs</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-trailing-spaces\">no-trailing-spaces</a></td>\n<td>disallow trailing whitespace at the end of lines</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/no-whitespace-before-property\">no-whitespace-before-property</a></td>\n<td>disallow whitespace before properties</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/nonblock-statement-body-position\">nonblock-statement-body-position</a></td>\n<td>enforce the location of single-line statements</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/object-curly-newline\">object-curly-newline</a></td>\n<td>enforce consistent line breaks after opening and before closing braces</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/object-curly-spacing\">object-curly-spacing</a></td>\n<td>enforce consistent spacing inside braces</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/object-property-newline\">object-property-newline</a></td>\n<td>enforce placing object properties on separate lines</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/operator-linebreak\">operator-linebreak</a></td>\n<td>enforce consistent linebreak style for operators</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/padded-blocks\">padded-blocks</a></td>\n<td>require or disallow padding within blocks</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/padding-line-between-statements\">padding-line-between-statements</a></td>\n<td>require or disallow padding lines between statements</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/quotes\">quotes</a></td>\n<td>enforce the consistent use of either backticks, double, or single quotes</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/rest-spread-spacing\">rest-spread-spacing</a></td>\n<td>enforce spacing between rest and spread operators and their expressions</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/semi\">semi</a></td>\n<td>require or disallow semicolons instead of ASI</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/semi-spacing\">semi-spacing</a></td>\n<td>enforce consistent spacing before and after semicolons</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/semi-style\">semi-style</a></td>\n<td>enforce location of semicolons</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/space-before-blocks\">space-before-blocks</a></td>\n<td>enforce consistent spacing before blocks</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/space-before-function-paren\">space-before-function-paren</a></td>\n<td>enforce consistent spacing before `function` definition opening parenthesis</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/space-in-parens\">space-in-parens</a></td>\n<td>enforce consistent spacing inside parentheses</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/space-infix-ops\">space-infix-ops</a></td>\n<td>require spacing around infix operators</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/space-unary-ops\">space-unary-ops</a></td>\n<td>enforce consistent spacing before or after unary operators</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/switch-colon-spacing\">switch-colon-spacing</a></td>\n<td>enforce spacing around colons of switch statements</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/template-curly-spacing\">template-curly-spacing</a></td>\n<td>require or disallow spacing around embedded expressions of template strings</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/template-tag-spacing\">template-tag-spacing</a></td>\n<td>require or disallow spacing between template tags and their literals</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/unicode-bom\">unicode-bom</a></td>\n<td>require or disallow Unicode byte order mark (BOM)</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/wrap-iife\">wrap-iife</a></td>\n<td>require parentheses around immediate `function` invocations</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/wrap-regex\">wrap-regex</a></td>\n<td>require parenthesis around regex literals</td>\n</tr>\n<tr>\n<td></td>\n<td>🔧</td>\n<td></td>\n<td><a href=\"https://eslint.org/docs/rules/yield-star-spacing\">yield-star-spacing</a></td>\n<td>require or disallow spacing around the `*` in `yield*` expressions</td>\n</tr>\n</tbody>\n</table>\n<h2>Deprecated<a href=\"https://eslint.org/docs/rules/#deprecated\"></a></h2>\n<p>These rules have been deprecated in accordance with the <a href=\"https://eslint.org/docs/user-guide/rule-deprecation\">deprecation policy</a>, and replaced by newer rules:</p>\n<table>\n<thead>\n<tr>\n<th>Deprecated rule</th>\n<th>Replaced by</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/callback-return\">callback-return</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/global-require\">global-require</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/handle-callback-err\">handle-callback-err</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/id-blacklist\">id-blacklist</a></td>\n<td><a href=\"https://eslint.org/docs/rules/id-denylist\">id-denylist</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/indent-legacy\">indent-legacy</a></td>\n<td><a href=\"https://eslint.org/docs/rules/indent\">indent</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/lines-around-directive\">lines-around-directive</a></td>\n<td><a href=\"https://eslint.org/docs/rules/padding-line-between-statements\">padding-line-between-statements</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/newline-after-var\">newline-after-var</a></td>\n<td><a href=\"https://eslint.org/docs/rules/padding-line-between-statements\">padding-line-between-statements</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/newline-before-return\">newline-before-return</a></td>\n<td><a href=\"https://eslint.org/docs/rules/padding-line-between-statements\">padding-line-between-statements</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-buffer-constructor\">no-buffer-constructor</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-catch-shadow\">no-catch-shadow</a></td>\n<td><a href=\"https://eslint.org/docs/rules/no-shadow\">no-shadow</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-mixed-requires\">no-mixed-requires</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-native-reassign\">no-native-reassign</a></td>\n<td><a href=\"https://eslint.org/docs/rules/no-global-assign\">no-global-assign</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-negated-in-lhs\">no-negated-in-lhs</a></td>\n<td><a href=\"https://eslint.org/docs/rules/no-unsafe-negation\">no-unsafe-negation</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-new-require\">no-new-require</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-path-concat\">no-path-concat</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-process-env\">no-process-env</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-process-exit\">no-process-exit</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-restricted-modules\">no-restricted-modules</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-spaced-func\">no-spaced-func</a></td>\n<td><a href=\"https://eslint.org/docs/rules/func-call-spacing\">func-call-spacing</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-sync\">no-sync</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/prefer-reflect\">prefer-reflect</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/require-jsdoc\">require-jsdoc</a></td>\n<td></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/valid-jsdoc\">valid-jsdoc</a></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h2>Removed<a href=\"https://eslint.org/docs/rules/#removed\"></a></h2>\n<p>These rules from older versions of ESLint (before the <a href=\"https://eslint.org/docs/user-guide/rule-deprecation\">deprecation policy</a> existed) have been replaced by newer rules:</p>\n<table>\n<thead>\n<tr>\n<th>Removed rule</th>\n<th>Replaced by</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/generator-star\">generator-star</a></td>\n<td><a href=\"https://eslint.org/docs/rules/generator-star-spacing\">generator-star-spacing</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/global-strict\">global-strict</a></td>\n<td><a href=\"https://eslint.org/docs/rules/strict\">strict</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-arrow-condition\">no-arrow-condition</a></td>\n<td><a href=\"https://eslint.org/docs/rules/no-confusing-arrow\">no-confusing-arrow</a> <a href=\"https://eslint.org/docs/rules/no-constant-condition\">no-constant-condition</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-comma-dangle\">no-comma-dangle</a></td>\n<td><a href=\"https://eslint.org/docs/rules/comma-dangle\">comma-dangle</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-empty-class\">no-empty-class</a></td>\n<td><a href=\"https://eslint.org/docs/rules/no-empty-character-class\">no-empty-character-class</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-empty-label\">no-empty-label</a></td>\n<td><a href=\"https://eslint.org/docs/rules/no-labels\">no-labels</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-extra-strict\">no-extra-strict</a></td>\n<td><a href=\"https://eslint.org/docs/rules/strict\">strict</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-reserved-keys\">no-reserved-keys</a></td>\n<td><a href=\"https://eslint.org/docs/rules/quote-props\">quote-props</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-space-before-semi\">no-space-before-semi</a></td>\n<td><a href=\"https://eslint.org/docs/rules/semi-spacing\">semi-spacing</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/no-wrap-func\">no-wrap-func</a></td>\n<td><a href=\"https://eslint.org/docs/rules/no-extra-parens\">no-extra-parens</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/space-after-function-name\">space-after-function-name</a></td>\n<td><a href=\"https://eslint.org/docs/rules/space-before-function-paren\">space-before-function-paren</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/space-after-keywords\">space-after-keywords</a></td>\n<td><a href=\"https://eslint.org/docs/rules/keyword-spacing\">keyword-spacing</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/space-before-function-parentheses\">space-before-function-parentheses</a></td>\n<td><a href=\"https://eslint.org/docs/rules/space-before-function-paren\">space-before-function-paren</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/space-before-keywords\">space-before-keywords</a></td>\n<td><a href=\"https://eslint.org/docs/rules/keyword-spacing\">keyword-spacing</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/space-in-brackets\">space-in-brackets</a></td>\n<td><a href=\"https://eslint.org/docs/rules/object-curly-spacing\">object-curly-spacing</a> <a href=\"https://eslint.org/docs/rules/array-bracket-spacing\">array-bracket-spacing</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/space-return-throw-case\">space-return-throw-case</a></td>\n<td><a href=\"https://eslint.org/docs/rules/keyword-spacing\">keyword-spacing</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/space-unary-word-ops\">space-unary-word-ops</a></td>\n<td><a href=\"https://eslint.org/docs/rules/space-unary-ops\">space-unary-ops</a></td>\n</tr>\n<tr>\n<td><a href=\"https://eslint.org/docs/rules/spaced-line-comment\">spaced-line-comment</a></td>\n<td><a href=\"https://eslint.org/docs/rules/spaced-comment\">spaced-comment</a></td>\n</tr>\n</tbody>\n</table>\n<!--EndFragment-->"},{"url":"/blog/useful-stock-images/","relativePath":"blog/useful-stock-images.md","relativeDir":"blog","base":"useful-stock-images.md","name":"useful-stock-images","frontmatter":{"title":"Useful Stock Images","template":"post","subtitle":"images","excerpt":"from upwork","date":"2022-05-19T08:39:54.360Z","image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/0beuahctjrs_qcqgv.jpg?raw=true","thumb_image":"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/0beuahctjrs_qcqgv.jpg?raw=true","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/git.yaml"],"tags":["src/data/tags/links.yaml"],"show_author_bio":true,"cmseditable":true},"html":"<h2>Images:</h2>\n<blockquote>\n<p>0beuahctjrs_qcqgv.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/0beuahctjrs_qcqgv.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/0beuahctjrs_qcqgv.jpg?raw=true\"></p>\n<blockquote>\n<p>893fd416-b7a7-45b9-9fb9-007aaf56fb49.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/893fd416-b7a7-45b9-9fb9-007aaf56fb49.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/893fd416-b7a7-45b9-9fb9-007aaf56fb49.jpeg?raw=true\"></p>\n<blockquote>\n<p>94ccd765-3bda-4e0f-adcf-98d9d97cd3e8.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/94ccd765-3bda-4e0f-adcf-98d9d97cd3e8.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/94ccd765-3bda-4e0f-adcf-98d9d97cd3e8.jpeg?raw=true\"></p>\n<blockquote>\n<p>Capture.PNG</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Capture.PNG?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Capture.PNG?raw=true\"></p>\n<blockquote>\n<p>Handlebars.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Handlebars.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Handlebars.png?raw=true\"></p>\n<blockquote>\n<p>My%20Post.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/My%20Post.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/My%20Post.png?raw=true\">\n![https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Screenshot%202022-03-30%20at%2012-37-24%20Website%20Speed%20Test%20Tool%20-%20Testmysite.io%20by%20Netlify.png?raw=true](<a href=\"https://raw.githubusercontent.com/\">https://raw.githubusercontent.com/</a></p>\n<blockquote>\n<p>Screenshot%202022-03-30%20at%2012-37-24%20Website%20Speed%20Test%20Tool%20-%20Testmysite.io%20by%20Netlify.png\nbgoo\nnz/BGOONZ<em>BLOG</em>2.0/master/static/images/Screenshot%202022-03-30%20at%2012-37-24%20Website%20Speed%20Test%20Tool%20-%20Testmysite.io%20by%20Netlify.png?raw=true)</p>\n</blockquote>\n<blockquote>\n<p>Visual<em>Studio</em>Code_logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Visual_Studio_Code_logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Visual_Studio_Code_logo.png?raw=true\"></p>\n<blockquote>\n<p>algolia.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/algolia.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/algolia.png?raw=true\"></p>\n<blockquote>\n<p>amazon-cloudwatch.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/amazon-cloudwatch.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/amazon-cloudwatch.png?raw=true\"></p>\n<blockquote>\n<p>amazon-ses.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/amazon-ses.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/amazon-ses.png?raw=true\"></p>\n<blockquote>\n<p>analytics.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/analytics.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/analytics.jpg?raw=true\"></p>\n<blockquote>\n<p>android.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/android.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/android.jpeg?raw=true\"></p>\n<blockquote>\n<p>android.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/android.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/android.png?raw=true\"></p>\n<blockquote>\n<p>angular.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/angular.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/angular.png?raw=true\"></p>\n<blockquote>\n<p>apache.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apache.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apache.jpg?raw=true\"></p>\n<blockquote>\n<p>api.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/api.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/api.gif?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-114x114.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-114x114.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-114x114.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-120x120.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-120x120.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-120x120.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-144x144.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-144x144.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-144x144.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-152x152.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-152x152.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-152x152.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-180x180.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-180x180.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-180x180.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-57x57.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-57x57.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-57x57.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-57x58.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-57x58.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-57x58.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-72x72.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-72x72.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-72x72.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-76x76.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-76x76.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-76x76.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-76x77.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-76x77.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-76x77.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon.png?raw=true\"></p>\n<blockquote>\n<p>atom.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/atom.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/atom.png?raw=true\"></p>\n<blockquote>\n<p>aws-lambda.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/aws-lambda.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/aws-lambda.png?raw=true\"></p>\n<blockquote>\n<p>aws.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/aws.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/aws.png?raw=true\"></p>\n<blockquote>\n<p>azure.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/azure.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/azure.png?raw=true\"></p>\n<blockquote>\n<p>babel-light-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/babel-light-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/babel-light-logo.png?raw=true\"></p>\n<blockquote>\n<p>babel-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/babel-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/babel-logo.png?raw=true\"></p>\n<blockquote>\n<p>back.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/back.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/back.jpeg?raw=true\"></p>\n<blockquote>\n<p>background.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/background.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/background.gif?raw=true\"></p>\n<blockquote>\n<p>badge-comment_heart.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/badge-comment_heart.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/badge-comment_heart.png?raw=true\"></p>\n<blockquote>\n<p>bash-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bash-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bash-logo.png?raw=true\"></p>\n<blockquote>\n<p>bassist.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bassist.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bassist.gif?raw=true\"></p>\n<blockquote>\n<p>battle-station.1.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/battle-station.1.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/battle-station.1.jpeg?raw=true\"></p>\n<blockquote>\n<p>battle-station.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/battle-station.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/battle-station.jpeg?raw=true\"></p>\n<blockquote>\n<p>bg-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bg-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bg-logo.png?raw=true\"></p>\n<blockquote>\n<p>big-o-chart.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/big-o-chart.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/big-o-chart.png?raw=true\"></p>\n<blockquote>\n<p>bigo.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bigo.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bigo.jpg?raw=true\"></p>\n<blockquote>\n<p>bigo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bigo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bigo.png?raw=true\"></p>\n<blockquote>\n<p>binary-files.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/binary-files.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/binary-files.png?raw=true\"></p>\n<blockquote>\n<p>bitbucket.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bitbucket.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bitbucket.png?raw=true\"></p>\n<blockquote>\n<p>blog-form.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-form.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-form.png?raw=true\"></p>\n<blockquote>\n<p>blog-may-2022.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-may-2022.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-may-2022.png?raw=true\"></p>\n<blockquote>\n<p>blog-may-2023.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-may-2023.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-may-2023.png?raw=true\"></p>\n<blockquote>\n<p>blog-preview.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-preview.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-preview.png?raw=true\"></p>\n<blockquote>\n<p>blog-recent.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-recent.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-recent.png?raw=true\"></p>\n<blockquote>\n<p>blog-screenshot-jan.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-screenshot-jan.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-screenshot-jan.png?raw=true\"></p>\n<blockquote>\n<p>blog.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog.jpg?raw=true\"></p>\n<blockquote>\n<p>blogspot.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blogspot.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blogspot.png?raw=true\"></p>\n<blockquote>\n<p>blue-plankton.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blue-plankton.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blue-plankton.png?raw=true\"></p>\n<blockquote>\n<p>blur-popover-close.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blur-popover-close.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blur-popover-close.gif?raw=true\"></p>\n<blockquote>\n<p>bootstrap-plain-wordmark.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bootstrap-plain-wordmark.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bootstrap-plain-wordmark.png?raw=true\"></p>\n<blockquote>\n<p>brown-papersq.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/brown-papersq.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/brown-papersq.png?raw=true\"></p>\n<blockquote>\n<p>bullets-1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bullets-1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bullets-1.png?raw=true\"></p>\n<blockquote>\n<p>call-stack-first-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-first-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-first-example.png?raw=true\"></p>\n<blockquote>\n<p>call-stack-second-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-second-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-second-example.png?raw=true\"></p>\n<blockquote>\n<p>call-stack-third-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-third-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-third-example.png?raw=true\"></p>\n<blockquote>\n<p>cdn-cors-header.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cdn-cors-header.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cdn-cors-header.png?raw=true\"></p>\n<blockquote>\n<p>checklist.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/checklist.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/checklist.png?raw=true\"></p>\n<blockquote>\n<p>chrome_E0QUXhDFv8.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_E0QUXhDFv8.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_E0QUXhDFv8.png?raw=true\"></p>\n<blockquote>\n<p>chrome_ajdk5oqXGC.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_ajdk5oqXGC.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_ajdk5oqXGC.png?raw=true\"></p>\n<blockquote>\n<p>chrome_nzhECqyCjh.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_nzhECqyCjh.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_nzhECqyCjh.png?raw=true\"></p>\n<blockquote>\n<p>circle-ci.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/circle-ci.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/circle-ci.jpg?raw=true\"></p>\n<blockquote>\n<p>circle-cropped.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/circle-cropped.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/circle-cropped.png?raw=true\"></p>\n<blockquote>\n<p>cm-steps-simple.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cm-steps-simple.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cm-steps-simple.png?raw=true\"></p>\n<blockquote>\n<p>code.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code.png?raw=true\"></p>\n<blockquote>\n<p>code_mg4k5cd9s4.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code_mg4k5cd9s4.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code_mg4k5cd9s4.png?raw=true\"></p>\n<blockquote>\n<p>code_mg4k5cd9s5.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code_mg4k5cd9s5.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code_mg4k5cd9s5.png?raw=true\"></p>\n<blockquote>\n<p>codewinds-004.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/codewinds-004.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/codewinds-004.png?raw=true\"></p>\n<blockquote>\n<p>command-line-basics.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/command-line-basics.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/command-line-basics.png?raw=true\"></p>\n<blockquote>\n<p>confluence.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/confluence.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/confluence.jpg?raw=true\"></p>\n<blockquote>\n<p>confluence.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/confluence.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/confluence.png?raw=true\"></p>\n<blockquote>\n<p>console-log-browser-expanded.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/console-log-browser-expanded.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/console-log-browser-expanded.png?raw=true\"></p>\n<blockquote>\n<p>console-log-browser.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/console-log-browser.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/console-log-browser.png?raw=true\"></p>\n<blockquote>\n<p>contact.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/contact.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/contact.png?raw=true\"></p>\n<blockquote>\n<p>cool-background.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cool-background.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cool-background.png?raw=true\"></p>\n<blockquote>\n<p>cool-comet.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cool-comet.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cool-comet.png?raw=true\"></p>\n<blockquote>\n<p>cover-letter.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cover-letter.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cover-letter.png?raw=true\"></p>\n<blockquote>\n<p>cow-say.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cow-say.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cow-say.png?raw=true\"></p>\n<blockquote>\n<p>cplusplus.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cplusplus.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cplusplus.png?raw=true\"></p>\n<blockquote>\n<p>css.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/css.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/css.png?raw=true\"></p>\n<blockquote>\n<p>cube.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cube.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cube.gif?raw=true\"></p>\n<blockquote>\n<p>curious-eggplant.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/curious-eggplant.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/curious-eggplant.jpg?raw=true\"></p>\n<blockquote>\n<p>data-struc2.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc2.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc2.gif?raw=true\"></p>\n<blockquote>\n<p>data-struc3.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc3.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc3.gif?raw=true\"></p>\n<blockquote>\n<p>daw.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/daw.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/daw.jpg?raw=true\"></p>\n<blockquote>\n<p>demo.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/demo.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/demo.gif?raw=true\"></p>\n<blockquote>\n<p>dense-js-code.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dense-js-code.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dense-js-code.jpg?raw=true\"></p>\n<blockquote>\n<p>devtools-dev.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/devtools-dev.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/devtools-dev.png?raw=true\"></p>\n<blockquote>\n<p>devtools-prod.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/devtools-prod.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/devtools-prod.png?raw=true\"></p>\n<blockquote>\n<p>digital-ocean.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/digital-ocean.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/digital-ocean.jpg?raw=true\"></p>\n<blockquote>\n<p>display.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/display.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/display.png?raw=true\"></p>\n<blockquote>\n<p>django.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/django.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/django.png?raw=true\"></p>\n<blockquote>\n<p>docker.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docker.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docker.png?raw=true\"></p>\n<blockquote>\n<p>docker2.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docker2.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docker2.png?raw=true\"></p>\n<blockquote>\n<p>docs.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docs.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docs.png?raw=true\"></p>\n<blockquote>\n<p>dom.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dom.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dom.png?raw=true\"></p>\n<blockquote>\n<p>drive.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/drive.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/drive.png?raw=true\"></p>\n<blockquote>\n<p>dropbox.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dropbox.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dropbox.jpg?raw=true\"></p>\n<blockquote>\n<p>ds-algo.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.gif?raw=true\"></p>\n<blockquote>\n<p>ds-algo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.png?raw=true\"></p>\n<blockquote>\n<p>ds-whiteboard.1.webp</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-whiteboard.1.webp?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-whiteboard.1.webp?raw=true\"></p>\n<blockquote>\n<p>ds-whiteboard.webp</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-whiteboard.webp?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-whiteboard.webp?raw=true\"></p>\n<blockquote>\n<p>ds.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds.png?raw=true\"></p>\n<blockquote>\n<p>dtw-algo.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-algo.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-algo.jpg?raw=true\"></p>\n<blockquote>\n<p>dtw-grid.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-grid.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-grid.png?raw=true\"></p>\n<blockquote>\n<p>dtw-slideshow.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-slideshow.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-slideshow.gif?raw=true\"></p>\n<blockquote>\n<p>dtw.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.gif?raw=true\"></p>\n<blockquote>\n<p>dtw.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.jpg?raw=true\"></p>\n<blockquote>\n<p>dtw.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.png?raw=true\"></p>\n<blockquote>\n<p>e40e889a-00fa-4786-a498-8990185b3698.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/e40e889a-00fa-4786-a498-8990185b3698.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/e40e889a-00fa-4786-a498-8990185b3698.jpeg?raw=true\"></p>\n<blockquote>\n<p>eaf976e3-e635-43a6-a123-bece3ed69898.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eaf976e3-e635-43a6-a123-bece3ed69898.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eaf976e3-e635-43a6-a123-bece3ed69898.jpeg?raw=true\"></p>\n<blockquote>\n<p>elastic-cloud.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/elastic-cloud.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/elastic-cloud.png?raw=true\"></p>\n<blockquote>\n<p>embedded-media.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embedded-media.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embedded-media.png?raw=true\"></p>\n<blockquote>\n<p>embeds.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embeds.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embeds.jpg?raw=true\"></p>\n<blockquote>\n<p>embeds.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embeds.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embeds.png?raw=true\"></p>\n<blockquote>\n<p>ember-original-wordmark.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ember-original-wordmark.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ember-original-wordmark.png?raw=true\"></p>\n<blockquote>\n<p>equation.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/equation.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/equation.gif?raw=true\"></p>\n<blockquote>\n<p>error-boundaries-stack-trace-line-numbers.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/error-boundaries-stack-trace-line-numbers.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/error-boundaries-stack-trace-line-numbers.png?raw=true\"></p>\n<blockquote>\n<p>error-boundaries-stack-trace.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/error-boundaries-stack-trace.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/error-boundaries-stack-trace.png?raw=true\"></p>\n<blockquote>\n<p>es6.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/es6.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/es6.jpg?raw=true\"></p>\n<blockquote>\n<p>es6.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/es6.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/es6.png?raw=true\"></p>\n<blockquote>\n<p>eventloop.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eventloop.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eventloop.gif?raw=true\"></p>\n<blockquote>\n<p>exception-call-stack.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/exception-call-stack.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/exception-call-stack.png?raw=true\"></p>\n<blockquote>\n<p>execution-order-first-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/execution-order-first-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/execution-order-first-example.png?raw=true\"></p>\n<blockquote>\n<p>execution-order-second-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/execution-order-second-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/execution-order-second-example.png?raw=true\"></p>\n<blockquote>\n<p>express-original-wordmark.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/express-original-wordmark.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/express-original-wordmark.png?raw=true\"></p>\n<blockquote>\n<p>express.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/express.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/express.png?raw=true\"></p>\n<blockquote>\n<p>ezgif.com-gif-maker.mp4</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ezgif.com-gif-maker.mp4?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ezgif.com-gif-maker.mp4?raw=true\"></p>\n<blockquote>\n<p>fairlawn.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fairlawn.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fairlawn.png?raw=true\"></p>\n<blockquote>\n<p>favicon.1.ico</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.1.ico?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.1.ico?raw=true\"></p>\n<blockquote>\n<p>favicon.ico</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.ico?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.ico?raw=true\"></p>\n<blockquote>\n<p>favicon.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.png?raw=true\"></p>\n<blockquote>\n<p>festive-zebra.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/festive-zebra.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/festive-zebra.png?raw=true\"></p>\n<blockquote>\n<p>fft.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fft.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fft.jpg?raw=true\"></p>\n<blockquote>\n<p>file-system.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/file-system.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/file-system.jpg?raw=true\"></p>\n<blockquote>\n<p>fillmurray.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fillmurray.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fillmurray.jpg?raw=true\"></p>\n<blockquote>\n<p>firebase.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/firebase.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/firebase.png?raw=true\"></p>\n<blockquote>\n<p>firebase3.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/firebase3.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/firebase3.jpg?raw=true\"></p>\n<blockquote>\n<p>flow-control-py.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/flow-control-py.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/flow-control-py.jpg?raw=true\"></p>\n<blockquote>\n<p>gatsby-cli.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-cli.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-cli.png?raw=true\"></p>\n<blockquote>\n<p>gatsby-graphiql-explorer.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-graphiql-explorer.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-graphiql-explorer.png?raw=true\"></p>\n<blockquote>\n<p>gatsby-paginate.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-paginate.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-paginate.png?raw=true\"></p>\n<blockquote>\n<p>gatsby-sourcery.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-sourcery.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-sourcery.png?raw=true\"></p>\n<blockquote>\n<p>gatsby.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby.png?raw=true\"></p>\n<blockquote>\n<p>gh-pages.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gh-pages.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gh-pages.png?raw=true\"></p>\n<blockquote>\n<p>gif-4mb.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gif-4mb.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gif-4mb.gif?raw=true\"></p>\n<blockquote>\n<p>git-banner.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-banner.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-banner.png?raw=true\"></p>\n<blockquote>\n<p>git-html-preview.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-html-preview.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-html-preview.gif?raw=true\"></p>\n<blockquote>\n<p>git-merge.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-merge.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-merge.jpeg?raw=true\"></p>\n<blockquote>\n<p>git-preview.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-preview.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-preview.gif?raw=true\"></p>\n<blockquote>\n<p>git.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git.png?raw=true\"></p>\n<blockquote>\n<p>globals.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/globals.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/globals.png?raw=true\"></p>\n<blockquote>\n<p>goals.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/goals.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/goals.jpg?raw=true\"></p>\n<blockquote>\n<p>google-adds.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-adds.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-adds.jpg?raw=true\"></p>\n<blockquote>\n<p>google-analytics.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-analytics.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-analytics.jpg?raw=true\"></p>\n<blockquote>\n<p>google-api.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-api.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-api.png?raw=true\"></p>\n<blockquote>\n<p>google-cloud%20(2).png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-cloud%20(2).png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-cloud%20(2).png?raw=true\"></p>\n<blockquote>\n<p>google-cloud.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-cloud.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-cloud.png?raw=true\"></p>\n<blockquote>\n<p>google-drive.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-drive.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-drive.jpg?raw=true\"></p>\n<blockquote>\n<p>googleTagManager.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/googleTagManager.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/googleTagManager.png?raw=true\"></p>\n<blockquote>\n<p>googlemaps.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/googlemaps.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/googlemaps.png?raw=true\"></p>\n<blockquote>\n<p>gradients_3.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gradients_3.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gradients_3.png?raw=true\"></p>\n<blockquote>\n<p>granular-dom-updates.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/granular-dom-updates.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/granular-dom-updates.gif?raw=true\"></p>\n<blockquote>\n<p>graphql-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/graphql-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/graphql-logo.png?raw=true\"></p>\n<blockquote>\n<p>graphql.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/graphql.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/graphql.png?raw=true\"></p>\n<blockquote>\n<p>gulp.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gulp.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gulp.png?raw=true\"></p>\n<blockquote>\n<p>heroku.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/heroku.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/heroku.png?raw=true\"></p>\n<blockquote>\n<p>home-button.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home-button.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home-button.png?raw=true\"></p>\n<blockquote>\n<p>home2022-01-20-23<em>58</em>59.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home2022-01-20-23_58_59.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home2022-01-20-23_58_59.png?raw=true\"></p>\n<blockquote>\n<p>home2022-01-20-23<em>58</em>60.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home2022-01-20-23_58_60.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home2022-01-20-23_58_60.png?raw=true\"></p>\n<blockquote>\n<p>html.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html.png?raw=true\"></p>\n<blockquote>\n<p>html2.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html2.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html2.png?raw=true\"></p>\n<blockquote>\n<p>html5.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html5.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html5.png?raw=true\"></p>\n<blockquote>\n<p>iconifier-readme.txt</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iconifier-readme.txt?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iconifier-readme.txt?raw=true\"></p>\n<blockquote>\n<p>iframes.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iframes.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iframes.gif?raw=true\"></p>\n<blockquote>\n<p>image-of-resume.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/image-of-resume.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/image-of-resume.png?raw=true\"></p>\n<blockquote>\n<p>implementation-notes-tree.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/implementation-notes-tree.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/implementation-notes-tree.png?raw=true\"></p>\n<blockquote>\n<p>iter.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iter.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iter.jpg?raw=true\"></p>\n<blockquote>\n<p>jam.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jam.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jam.png?raw=true\"></p>\n<blockquote>\n<p>jamstack.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jamstack.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jamstack.png?raw=true\"></p>\n<blockquote>\n<p>java.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/java.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/java.png?raw=true\"></p>\n<blockquote>\n<p>javascript-jabber.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript-jabber.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript-jabber.png?raw=true\"></p>\n<blockquote>\n<p>javascript.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript.gif?raw=true\"></p>\n<blockquote>\n<p>javascript.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript.jpeg?raw=true\"></p>\n<blockquote>\n<p>jenkins.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jenkins.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jenkins.png?raw=true\"></p>\n<blockquote>\n<p>jest.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jest.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jest.png?raw=true\"></p>\n<blockquote>\n<p>jira.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jira.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jira.jpg?raw=true\"></p>\n<blockquote>\n<p>jquery-logo-no-title.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery-logo-no-title.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery-logo-no-title.jpg?raw=true\"></p>\n<blockquote>\n<p>jquery.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery.jpg?raw=true\"></p>\n<blockquote>\n<p>jquery.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery.png?raw=true\"></p>\n<blockquote>\n<p>jquery2.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery2.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery2.png?raw=true\"></p>\n<blockquote>\n<p>js-code-spiral-num.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/js-code-spiral-num.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/js-code-spiral-num.png?raw=true\"></p>\n<blockquote>\n<p>js-questions-n-answers.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/js-questions-n-answers.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/js-questions-n-answers.png?raw=true\"></p>\n<blockquote>\n<p>keep-calm.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/keep-calm.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/keep-calm.png?raw=true\"></p>\n<blockquote>\n<p>keyboard-focus.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/keyboard-focus.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/keyboard-focus.png?raw=true\"></p>\n<blockquote>\n<p>kind-whale.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/kind-whale.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/kind-whale.gif?raw=true\"></p>\n<blockquote>\n<p>kub.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/kub.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/kub.png?raw=true\"></p>\n<blockquote>\n<p>lambda-demo.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/lambda-demo.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/lambda-demo.gif?raw=true\"></p>\n<blockquote>\n<p>lambda.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/lambda.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/lambda.png?raw=true\"></p>\n<blockquote>\n<p>linux-original.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux-original.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux-original.png?raw=true\"></p>\n<blockquote>\n<p>linux.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux.png?raw=true\"></p>\n<blockquote>\n<p>logo-animated-1-.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-animated-1-.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-animated-1-.gif?raw=true\"></p>\n<blockquote>\n<p>logo-circle.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-circle.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-circle.png?raw=true\"></p>\n<blockquote>\n<p>logo-final-touchup.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-final-touchup.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-final-touchup.png?raw=true\"></p>\n<blockquote>\n<p>logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo.png?raw=true\"></p>\n<blockquote>\n<p>macos.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/macos.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/macos.png?raw=true\"></p>\n<blockquote>\n<p>madewith.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/madewith.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/madewith.png?raw=true\"></p>\n<blockquote>\n<p>main-blog.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/main-blog.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/main-blog.png?raw=true\"></p>\n<blockquote>\n<p>map.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/map.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/map.jpg?raw=true\"></p>\n<blockquote>\n<p>markdown.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/markdown.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/markdown.png?raw=true\"></p>\n<blockquote>\n<p>maroon-onion.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/maroon-onion.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/maroon-onion.gif?raw=true\"></p>\n<blockquote>\n<p>may-15-snap.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/may-15-snap.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/may-15-snap.png?raw=true\"></p>\n<blockquote>\n<p>md.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/md.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/md.png?raw=true\"></p>\n<blockquote>\n<p>media-querry.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/media-querry.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/media-querry.png?raw=true\"></p>\n<blockquote>\n<p>medium-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/medium-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/medium-logo.png?raw=true\"></p>\n<blockquote>\n<p>medium.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/medium.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/medium.png?raw=true\"></p>\n<blockquote>\n<p>mihir-about.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir-about.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir-about.png?raw=true\"></p>\n<blockquote>\n<p>mihir.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir.jpg?raw=true\"></p>\n<blockquote>\n<p>mihir.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir.png?raw=true\"></p>\n<blockquote>\n<p>mini-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mini-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mini-logo.png?raw=true\"></p>\n<blockquote>\n<p>mocha.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mocha.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mocha.png?raw=true\"></p>\n<blockquote>\n<p>my-back.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/my-back.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/my-back.png?raw=true\"></p>\n<blockquote>\n<p>nasa<em>earth</em>grid.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_earth_grid.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_earth_grid.jpg?raw=true\"></p>\n<blockquote>\n<p>nasa<em>new</em>york<em>city</em>grid.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_new_york_city_grid.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_new_york_city_grid.jpg?raw=true\"></p>\n<blockquote>\n<p>nasa<em>space</em>shuttle_challenger.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_space_shuttle_challenger.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_space_shuttle_challenger.jpg?raw=true\"></p>\n<blockquote>\n<p>nasa<em>the</em>blue_marble-1-.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_the_blue_marble-1-.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_the_blue_marble-1-.jpg?raw=true\"></p>\n<blockquote>\n<p>needle.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/needle.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/needle.jpg?raw=true\"></p>\n<blockquote>\n<p>netlify.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/netlify.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/netlify.png?raw=true\"></p>\n<blockquote>\n<p>netlifycms.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/netlifycms.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/netlifycms.png?raw=true\"></p>\n<blockquote>\n<p>neural.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/neural.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/neural.png?raw=true\"></p>\n<blockquote>\n<p>nextjs.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nextjs.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nextjs.png?raw=true\"></p>\n<blockquote>\n<p>nj-devils.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nj-devils.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nj-devils.jpg?raw=true\"></p>\n<blockquote>\n<p>njdev.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/njdev.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/njdev.jpg?raw=true\"></p>\n<blockquote>\n<p>node-express.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-express.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-express.png?raw=true\"></p>\n<blockquote>\n<p>node-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-logo.png?raw=true\"></p>\n<blockquote>\n<p>node-package-manager.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-package-manager.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-package-manager.png?raw=true\"></p>\n<blockquote>\n<p>node.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node.jpg?raw=true\"></p>\n<blockquote>\n<p>node_modules-content.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node_modules-content.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node_modules-content.png?raw=true\"></p>\n<blockquote>\n<p>octocat.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/octocat.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/octocat.png?raw=true\"></p>\n<blockquote>\n<p>original-webdevhub-log.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/original-webdevhub-log.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/original-webdevhub-log.png?raw=true\"></p>\n<blockquote>\n<p>outdated-packages.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outdated-packages.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outdated-packages.png?raw=true\"></p>\n<blockquote>\n<p>outerclick-with-keyboard.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outerclick-with-keyboard.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outerclick-with-keyboard.gif?raw=true\"></p>\n<blockquote>\n<p>outerclick-with-mouse.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outerclick-with-mouse.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outerclick-with-mouse.gif?raw=true\"></p>\n<blockquote>\n<p>perf-dom.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-dom.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-dom.png?raw=true\"></p>\n<blockquote>\n<p>perf-exclusive.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-exclusive.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-exclusive.png?raw=true\"></p>\n<blockquote>\n<p>perf-inclusive.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-inclusive.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-inclusive.png?raw=true\"></p>\n<blockquote>\n<p>perf-wasted.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-wasted.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-wasted.png?raw=true\"></p>\n<blockquote>\n<p>php.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/php.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/php.jpg?raw=true\"></p>\n<blockquote>\n<p>pleasant-birch.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pleasant-birch.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pleasant-birch.png?raw=true\"></p>\n<blockquote>\n<p>pojoaque.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pojoaque.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pojoaque.jpg?raw=true\"></p>\n<blockquote>\n<p>portfolio-cover.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio-cover.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio-cover.png?raw=true\"></p>\n<blockquote>\n<p>portfolio.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio.gif?raw=true\"></p>\n<blockquote>\n<p>portfolio.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio.jpg?raw=true\"></p>\n<blockquote>\n<p>postman.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/postman.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/postman.png?raw=true\"></p>\n<blockquote>\n<p>posts.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/posts.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/posts.png?raw=true\"></p>\n<blockquote>\n<p>potluck-planner.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/potluck-planner.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/potluck-planner.jpg?raw=true\"></p>\n<blockquote>\n<p>printing-press.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/printing-press.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/printing-press.jpg?raw=true\"></p>\n<blockquote>\n<p>profile.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/profile.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/profile.png?raw=true\"></p>\n<blockquote>\n<p>programmable-search-engine.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/programmable-search-engine.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/programmable-search-engine.png?raw=true\"></p>\n<blockquote>\n<p>projects.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/projects.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/projects.jpeg?raw=true\"></p>\n<blockquote>\n<p>projects.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/projects.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/projects.jpg?raw=true\"></p>\n<blockquote>\n<p>psql-diagram.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-diagram.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-diagram.jpg?raw=true\"></p>\n<blockquote>\n<p>psql-postgres.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-postgres.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-postgres.png?raw=true\"></p>\n<blockquote>\n<p>psql-schema.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-schema.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-schema.jpg?raw=true\"></p>\n<blockquote>\n<p>psql.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql.jpg?raw=true\"></p>\n<blockquote>\n<p>pug.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pug.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pug.png?raw=true\"></p>\n<blockquote>\n<p>pull-request-blog.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pull-request-blog.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pull-request-blog.png?raw=true\"></p>\n<blockquote>\n<p>pull-request.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pull-request.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pull-request.jpg?raw=true\"></p>\n<blockquote>\n<p>puppetter.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/puppetter.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/puppetter.png?raw=true\"></p>\n<blockquote>\n<p>pure-data.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pure-data.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pure-data.png?raw=true\"></p>\n<blockquote>\n<p>py.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/py.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/py.jpg?raw=true\"></p>\n<blockquote>\n<p>python-language.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-language.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-language.jpg?raw=true\"></p>\n<blockquote>\n<p>python-logo-simple.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-logo-simple.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-logo-simple.png?raw=true\"></p>\n<blockquote>\n<p>python.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python.jpg?raw=true\"></p>\n<blockquote>\n<p>python.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python.png?raw=true\"></p>\n<blockquote>\n<p>python1-00990432.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python1-00990432.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python1-00990432.jpg?raw=true\"></p>\n<blockquote>\n<p>python2-15e88a3a.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python2-15e88a3a.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python2-15e88a3a.jpg?raw=true\"></p>\n<blockquote>\n<p>python2.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python2.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python2.jpg?raw=true\"></p>\n<blockquote>\n<p>python3-15e88a3a.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python3-15e88a3a.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python3-15e88a3a.jpg?raw=true\"></p>\n<blockquote>\n<p>react%20(1).png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react%20(1).png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react%20(1).png?raw=true\"></p>\n<blockquote>\n<p>react-banner.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-banner.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-banner.jpg?raw=true\"></p>\n<blockquote>\n<p>react-dark.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-dark.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-dark.jpg?raw=true\"></p>\n<blockquote>\n<p>react-devtools-state.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-devtools-state.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-devtools-state.gif?raw=true\"></p>\n<blockquote>\n<p>react-fancy-logo.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-fancy-logo.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-fancy-logo.jpg?raw=true\"></p>\n<blockquote>\n<p>react.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.gif?raw=true\"></p>\n<blockquote>\n<p>react.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.jpg?raw=true\"></p>\n<blockquote>\n<p>react.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.png?raw=true\"></p>\n<blockquote>\n<p>recording-studio.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/recording-studio.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/recording-studio.jpg?raw=true\"></p>\n<blockquote>\n<p>recursive-settimeout.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/recursive-settimeout.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/recursive-settimeout.png?raw=true\"></p>\n<blockquote>\n<p>redis.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redis.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redis.png?raw=true\"></p>\n<blockquote>\n<p>redu-squarex.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redu-squarex.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redu-squarex.jpg?raw=true\"></p>\n<blockquote>\n<p>redux.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redux.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redux.gif?raw=true\"></p>\n<blockquote>\n<p>resume-bg.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/resume-bg.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/resume-bg.png?raw=true\"></p>\n<blockquote>\n<p>resume.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/resume.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/resume.jpg?raw=true\"></p>\n<blockquote>\n<p>royal-kangaroo.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/royal-kangaroo.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/royal-kangaroo.jpg?raw=true\"></p>\n<blockquote>\n<p>ruby.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ruby.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ruby.png?raw=true\"></p>\n<blockquote>\n<p>sass.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sass.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sass.png?raw=true\"></p>\n<blockquote>\n<p>scala.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/scala.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/scala.png?raw=true\"></p>\n<blockquote>\n<p>school-book.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/school-book.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/school-book.1.png?raw=true\"></p>\n<blockquote>\n<p>school-book.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/school-book.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/school-book.png?raw=true\"></p>\n<blockquote>\n<p>scope-closure.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/scope-closure.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/scope-closure.jpg?raw=true\"></p>\n<blockquote>\n<p>screenshots.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/screenshots.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/screenshots.png?raw=true\"></p>\n<blockquote>\n<p>selenium.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/selenium.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/selenium.jpg?raw=true\"></p>\n<blockquote>\n<p>senic.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/senic.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/senic.png?raw=true\"></p>\n<blockquote>\n<p>sequelize.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sequelize.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sequelize.png?raw=true\"></p>\n<blockquote>\n<p>setinterval-ok.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-ok.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-ok.png?raw=true\"></p>\n<blockquote>\n<p>setinterval-overlapping.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-overlapping.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-overlapping.1.png?raw=true\"></p>\n<blockquote>\n<p>setinterval-overlapping.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-overlapping.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-overlapping.png?raw=true\"></p>\n<blockquote>\n<p>setinterval-varying-duration.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-varying-duration.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-varying-duration.png?raw=true\"></p>\n<blockquote>\n<p>shopify.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/shopify.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/shopify.png?raw=true\"></p>\n<blockquote>\n<p>should-component-update.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/should-component-update.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/should-component-update.png?raw=true\"></p>\n<blockquote>\n<p>showcase.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/showcase.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/showcase.1.png?raw=true\"></p>\n<blockquote>\n<p>showcase.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/showcase.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/showcase.png?raw=true\"></p>\n<blockquote>\n<p>sine-wav-bak%20(1).gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sine-wav-bak%20(1).gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sine-wav-bak%20(1).gif?raw=true\"></p>\n<blockquote>\n<p>skype.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/skype.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/skype.png?raw=true\"></p>\n<blockquote>\n<p>slack.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/slack.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/slack.jpg?raw=true\"></p>\n<blockquote>\n<p>sourcetree.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sourcetree.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sourcetree.png?raw=true\"></p>\n<blockquote>\n<p>sql_server.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sql_server.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sql_server.png?raw=true\"></p>\n<blockquote>\n<p>sqlite.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sqlite.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sqlite.jpg?raw=true\"></p>\n<blockquote>\n<p>static-server.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/static-server.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/static-server.1.png?raw=true\"></p>\n<blockquote>\n<p>static-server.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/static-server.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/static-server.png?raw=true\"></p>\n<blockquote>\n<p>sublime.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sublime.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sublime.jpg?raw=true\"></p>\n<blockquote>\n<p>superb-panda.PNG</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/superb-panda.PNG?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/superb-panda.PNG?raw=true\"></p>\n<blockquote>\n<p>swift.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/swift.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/swift.png?raw=true\"></p>\n<blockquote>\n<p>tetris.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tetris.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tetris.png?raw=true\"></p>\n<blockquote>\n<p>tex.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tex.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tex.png?raw=true\"></p>\n<blockquote>\n<p>textools.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/textools.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/textools.png?raw=true\"></p>\n<blockquote>\n<p>theme.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/theme.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/theme.1.png?raw=true\"></p>\n<blockquote>\n<p>theme.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/theme.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/theme.png?raw=true\"></p>\n<blockquote>\n<p>thinking-in-react-tagtree.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/thinking-in-react-tagtree.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/thinking-in-react-tagtree.png?raw=true\"></p>\n<blockquote>\n<p>thoughtful-neptune.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/thoughtful-neptune.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/thoughtful-neptune.png?raw=true\"></p>\n<blockquote>\n<p>tomcat.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tomcat.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tomcat.png?raw=true\"></p>\n<blockquote>\n<p>tools.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tools.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tools.1.png?raw=true\"></p>\n<blockquote>\n<p>tools.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tools.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tools.png?raw=true\"></p>\n<blockquote>\n<p>top-half-mihir.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/top-half-mihir.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/top-half-mihir.png?raw=true\"></p>\n<blockquote>\n<p>travis.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/travis.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/travis.png?raw=true\"></p>\n<blockquote>\n<p>ts.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ts.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ts.jpg?raw=true\"></p>\n<blockquote>\n<p>ubuntu.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ubuntu.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ubuntu.jpg?raw=true\"></p>\n<blockquote>\n<p>updated-packages.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/updated-packages.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/updated-packages.1.png?raw=true\"></p>\n<blockquote>\n<p>updated-packages.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/updated-packages.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/updated-packages.png?raw=true\"></p>\n<blockquote>\n<p>usage.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/usage.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/usage.png?raw=true\"></p>\n<blockquote>\n<p>using-the-dom.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/using-the-dom.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/using-the-dom.png?raw=true\"></p>\n<blockquote>\n<p>version-control.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/version-control.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/version-control.png?raw=true\"></p>\n<blockquote>\n<p>vim_logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vim_logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vim_logo.png?raw=true\"></p>\n<blockquote>\n<p>violet-pluto.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/violet-pluto.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/violet-pluto.png?raw=true\"></p>\n<blockquote>\n<p>virtual-box.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/virtual-box.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/virtual-box.png?raw=true\"></p>\n<blockquote>\n<p>visual-studio.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/visual-studio.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/visual-studio.png?raw=true\"></p>\n<blockquote>\n<p>vscode-extensions-list.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode-extensions-list.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode-extensions-list.png?raw=true\"></p>\n<blockquote>\n<p>vscode.1.webp</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.1.webp?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.1.webp?raw=true\"></p>\n<blockquote>\n<p>vscode.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.png?raw=true\"></p>\n<blockquote>\n<p>vscode.webp</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.webp?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.webp?raw=true\"></p>\n<blockquote>\n<p>web-dev-back.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/web-dev-back.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/web-dev-back.jpg?raw=true\"></p>\n<blockquote>\n<p>web-development.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/web-development.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/web-development.gif?raw=true\"></p>\n<blockquote>\n<p>webdev.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webdev.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webdev.png?raw=true\"></p>\n<blockquote>\n<p>webpack.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webpack.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webpack.png?raw=true\"></p>\n<blockquote>\n<p>webscraping.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webscraping.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webscraping.1.png?raw=true\"></p>\n<blockquote>\n<p>webscraping.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webscraping.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webscraping.png?raw=true\"></p>\n<blockquote>\n<p>windows.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/windows.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/windows.png?raw=true\"></p>\n<blockquote>\n<p>woodcuts_1.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/woodcuts_1.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/woodcuts_1.jpg?raw=true\"></p>\n<blockquote>\n<p>wordpress-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/wordpress-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/wordpress-logo.png?raw=true\"></p>\n<blockquote>\n<p>xcode%20(1).png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/xcode%20(1).png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/xcode%20(1).png?raw=true\"></p>\n<blockquote>\n<p>zumzi-video-chat.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi-video-chat.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi-video-chat.1.png?raw=true\"></p>\n<blockquote>\n<p>zumzi-video-chat.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi-video-chat.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi-video-chat.png?raw=true\"></p>\n<blockquote>\n<p>zumzi.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi.png?raw=true\"></p>"},{"url":"/docs/about/internal-use/","relativePath":"docs/about/internal-use.md","relativeDir":"docs/about","base":"internal-use.md","name":"internal-use","frontmatter":{"title":"Internal Use","excerpt":"Web-Dev-Hub is my personal blogand documentation site","seo":{"title":"Internal Use","description":"Bryan Guner personal blog Internal Use page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Internal Use","keyName":"property"},{"name":"og:description","value":"This is the Internal Use page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Internal Use"},{"name":"twitter:description","value":"This is the Internal Use page"}]},"template":"docs"},"html":"<ul>\n<li><a href=\"https://backup-april-4-2022--bgoonz-blog.netlify.app/\">april backup</a></li>\n</ul>\n<table>\n<thead>\n<tr>\n<th>URL</th>\n<th>Miscellaneous</th>\n<th>Widgets</th>\n<th>Analytics</th>\n<th>Comment systems</th>\n<th>Security</th>\n<th>Font scripts</th>\n<th>CDN</th>\n<th>Marketing automation</th>\n<th>Advertising</th>\n<th>Webcams</th>\n<th>Tag managers</th>\n<th>Live chat</th>\n<th>JavaScript libraries</th>\n<th>Cookie compliance</th>\n<th>Accessibility</th>\n<th>SSL/TLS certificate authorities</th>\n<th>Affiliate programs</th>\n<th>Appointment scheduling</th>\n<th>Surveys</th>\n<th>A/B testing</th>\n<th>Email</th>\n<th>Personalisation</th>\n<th>Retargeting</th>\n<th>RUM</th>\n<th>Geolocation</th>\n<th>Browser fingerprinting</th>\n<th>Loyalty &#x26; rewards</th>\n<th>Feature management</th>\n<th>Segmentation</th>\n<th>Hosting</th>\n<th>Translation</th>\n<th>Reviews</th>\n<th>Buy now pay later</th>\n<th>Performance</th>\n<th>Reservations &#x26; delivery</th>\n<th>Referral marketing</th>\n<th>Digital asset management</th>\n<th>Content curation</th>\n<th>Customer data platform</th>\n<th>Cart abandonment</th>\n<th>Shipping carriers</th>\n<th>Recruitment &#x26; staffing</th>\n<th>Returns</th>\n<th>Livestreaming</th>\n<th>Ticket booking</th>\n<th>Augmented reality</th>\n<th>JavaScript frameworks</th>\n<th>Web servers</th>\n<th>Mobile frameworks</th>\n<th>Payment processors</th>\n<th>SEO</th>\n<th>User onboarding</th>\n<th>Containers</th>\n<th>PaaS</th>\n<th>IaaS</th>\n<th>WordPress plugins</th>\n<th>Shopify apps</th>\n<th>Video players</th>\n<th>Web frameworks</th>\n<th>Caching</th>\n<th>Web server extensions</th>\n<th>Reverse proxies</th>\n<th>Load balancers</th>\n<th>UI frameworks</th>\n<th>WordPress themes</th>\n<th>Shopify themes</th>\n<th>Drupal themes</th>\n<th>JavaScript graphics</th>\n<th>Operating systems</th>\n<th>Maps</th>\n<th>Authentication</th>\n<th>Cross border ecommerce</th>\n<th>Rich text editors</th>\n<th>Programming languages</th>\n<th>Databases</th>\n<th>CRM</th>\n<th>Cryptominers</th>\n<th>Editor</th>\n<th>Search engines</th>\n<th>CI</th>\n<th>Database managers</th>\n<th>Documentation tools</th>\n<th>Hosting panels</th>\n<th>Issue trackers</th>\n<th>Webmail</th>\n<th>Network services</th>\n<th></th>\n<th>Development</th>\n<th>Network storage</th>\n<th>Page builder</th>\n<th>CMS</th>\n<th>Message boards</th>\n<th>Ecommerce</th>\n<th>Photo galleries</th>\n<th>Wikis</th>\n<th>Blogs</th>\n<th>LMS</th>\n<th>Media servers</th>\n<th>Remote Access</th>\n<th>Feed readers</th>\n<th>DMS</th>\n<th>Accounting</th>\n<th>Static site generators</th>\n<th>Phone number</th>\n<th>Skype</th>\n<th>WhatsApp</th>\n<th>Email address</th>\n<th>Email address (verified)</th>\n<th>Email address (safe)</th>\n<th>Twitter</th>\n<th>Facebook</th>\n<th>Instagram</th>\n<th>GitHub</th>\n<th>TikTok</th>\n<th>YouTube</th>\n<th>Pinterest</th>\n<th>LinkedIn</th>\n<th>Owler</th>\n<th>Title</th>\n<th>Description</th>\n<th>Copyright</th>\n<th>Copyright year</th>\n<th>Responsive</th>\n<th>schema.org types</th>\n<th>Cert organisation</th>\n<th>Cert country</th>\n<th>Cert state</th>\n<th>Cert locality</th>\n<th>Cert issuer</th>\n<th>Cert protocol</th>\n<th>Cert expiry</th>\n<th>SPF record</th>\n<th>DMARC record</th>\n<th>SSL/TLS enabled</th>\n<th>Google Analytics</th>\n<th>Google AdSense</th>\n<th>Medianet</th>\n<th>Facebook</th>\n<th>Optimizely</th>\n<th>Company name</th>\n<th>Inferred company name</th>\n<th>Industry</th>\n<th>About</th>\n<th>Locations</th>\n<th>Company size</th>\n<th>Company type</th>\n<th>Company founded</th>\n<th>People</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app\">https://bgoonz-blog.netlify.app</a></td>\n<td>webpack</td>\n<td>AddThis</td>\n<td>Plausible ; Moat ; Google Analytics</td>\n<td>Disqus</td>\n<td></td>\n<td>Google Font API</td>\n<td>Cloudflare ; Unpkg ; jsDelivr ; cdnjs ; Netlify</td>\n<td></td>\n<td>Taboola</td>\n<td></td>\n<td>Google Tag Manager</td>\n<td></td>\n<td>MobX ; Lodash ; core-js ; Highlight.js</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td>Emotion ; React ; Gatsby</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td>Netlify</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td>Emotion</td>\n<td></td>\n<td></td>\n<td>DatoCMS</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td>Gatsby</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p><a href=\"https://blog20-preview.netlify.app/\">https://blog20-preview.netlify.app/</a></p>\n<h2>Images</h2>\n<blockquote>\n<p>0beuahctjrs_qcqgv.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/0beuahctjrs_qcqgv.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/0beuahctjrs_qcqgv.jpg?raw=true\"></p>\n<blockquote>\n<p>893fd416-b7a7-45b9-9fb9-007aaf56fb49.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/893fd416-b7a7-45b9-9fb9-007aaf56fb49.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/893fd416-b7a7-45b9-9fb9-007aaf56fb49.jpeg?raw=true\"></p>\n<blockquote>\n<p>94ccd765-3bda-4e0f-adcf-98d9d97cd3e8.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/94ccd765-3bda-4e0f-adcf-98d9d97cd3e8.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/94ccd765-3bda-4e0f-adcf-98d9d97cd3e8.jpeg?raw=true\"></p>\n<blockquote>\n<p>Capture.PNG</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Capture.PNG?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Capture.PNG?raw=true\"></p>\n<blockquote>\n<p>Handlebars.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Handlebars.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Handlebars.png?raw=true\"></p>\n<blockquote>\n<p>My%20Post.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/My%20Post.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/My%20Post.png?raw=true\"></p>\n<blockquote>\n<p>Visual<em>Studio</em>Code_logo.png</p>\n</blockquote>\n<p>![https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Screenshot%202022-03-30%20at%2012-37-24%20Website%20Speed%20Test%20Tool%20-%20Testmysite.io%20by%20Netlify.png?raw=true](<a href=\"https://raw.githubusercontent.com/\">https://raw.githubusercontent.com/</a></p>\n<blockquote>\n<p>Screenshot%202022-03-30%20at%2012-37-24%20Website%20Speed%20Test%20Tool%20-%20Testmysite.io%20by%20Netlify.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Visual_Studio_Code_logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/Visual_Studio_Code_logo.png?raw=true\"></p>\n<blockquote>\n<p>algolia.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/algolia.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/algolia.png?raw=true\"></p>\n<blockquote>\n<p>amazon-cloudwatch.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/amazon-cloudwatch.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/amazon-cloudwatch.png?raw=true\"></p>\n<blockquote>\n<p>amazon-ses.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/amazon-ses.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/amazon-ses.png?raw=true\"></p>\n<blockquote>\n<p>analytics.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/analytics.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/analytics.jpg?raw=true\"></p>\n<blockquote>\n<p>android.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/android.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/android.jpeg?raw=true\"></p>\n<blockquote>\n<p>android.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/android.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/android.png?raw=true\"></p>\n<blockquote>\n<p>angular.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/angular.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/angular.png?raw=true\"></p>\n<blockquote>\n<p>apache.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apache.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apache.jpg?raw=true\"></p>\n<blockquote>\n<p>api.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/api.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/api.gif?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-114x114.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-114x114.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-114x114.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-120x120.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-120x120.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-120x120.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-144x144.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-144x144.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-144x144.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-152x152.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-152x152.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-152x152.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-180x180.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-180x180.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-180x180.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-57x57.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-57x57.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-57x57.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-57x58.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-57x58.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-57x58.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-72x72.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-72x72.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-72x72.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-76x76.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-76x76.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-76x76.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon-76x77.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-76x77.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon-76x77.png?raw=true\"></p>\n<blockquote>\n<p>apple-touch-icon.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/apple-touch-icon.png?raw=true\"></p>\n<blockquote>\n<p>atom.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/atom.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/atom.png?raw=true\"></p>\n<blockquote>\n<p>aws-lambda.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/aws-lambda.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/aws-lambda.png?raw=true\"></p>\n<blockquote>\n<p>aws.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/aws.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/aws.png?raw=true\"></p>\n<blockquote>\n<p>azure.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/azure.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/azure.png?raw=true\"></p>\n<blockquote>\n<p>babel-light-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/babel-light-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/babel-light-logo.png?raw=true\"></p>\n<blockquote>\n<p>babel-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/babel-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/babel-logo.png?raw=true\"></p>\n<blockquote>\n<p>back.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/back.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/back.jpeg?raw=true\"></p>\n<blockquote>\n<p>background.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/background.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/background.gif?raw=true\"></p>\n<blockquote>\n<p>badge-comment_heart.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/badge-comment_heart.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/badge-comment_heart.png?raw=true\"></p>\n<blockquote>\n<p>bash-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bash-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bash-logo.png?raw=true\"></p>\n<blockquote>\n<p>bassist.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bassist.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bassist.gif?raw=true\"></p>\n<blockquote>\n<p>battle-station.1.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/battle-station.1.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/battle-station.1.jpeg?raw=true\"></p>\n<blockquote>\n<p>battle-station.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/battle-station.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/battle-station.jpeg?raw=true\"></p>\n<blockquote>\n<p>bg-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bg-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bg-logo.png?raw=true\"></p>\n<blockquote>\n<p>big-o-chart.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/big-o-chart.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/big-o-chart.png?raw=true\"></p>\n<blockquote>\n<p>bigo.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bigo.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bigo.jpg?raw=true\"></p>\n<blockquote>\n<p>bigo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bigo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bigo.png?raw=true\"></p>\n<blockquote>\n<p>binary-files.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/binary-files.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/binary-files.png?raw=true\"></p>\n<blockquote>\n<p>bitbucket.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bitbucket.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bitbucket.png?raw=true\"></p>\n<blockquote>\n<p>blog-form.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-form.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-form.png?raw=true\"></p>\n<blockquote>\n<p>blog-may-2022.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-may-2022.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-may-2022.png?raw=true\"></p>\n<blockquote>\n<p>blog-may-2023.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-may-2023.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-may-2023.png?raw=true\"></p>\n<blockquote>\n<p>blog-preview.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-preview.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-preview.png?raw=true\"></p>\n<blockquote>\n<p>blog-recent.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-recent.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-recent.png?raw=true\"></p>\n<blockquote>\n<p>blog-screenshot-jan.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-screenshot-jan.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog-screenshot-jan.png?raw=true\"></p>\n<blockquote>\n<p>blog.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blog.jpg?raw=true\"></p>\n<blockquote>\n<p>blogspot.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blogspot.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blogspot.png?raw=true\"></p>\n<blockquote>\n<p>blue-plankton.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blue-plankton.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blue-plankton.png?raw=true\"></p>\n<blockquote>\n<p>blur-popover-close.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blur-popover-close.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/blur-popover-close.gif?raw=true\"></p>\n<blockquote>\n<p>bootstrap-plain-wordmark.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bootstrap-plain-wordmark.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bootstrap-plain-wordmark.png?raw=true\"></p>\n<blockquote>\n<p>brown-papersq.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/brown-papersq.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/brown-papersq.png?raw=true\"></p>\n<blockquote>\n<p>bullets-1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bullets-1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/bullets-1.png?raw=true\"></p>\n<blockquote>\n<p>call-stack-first-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-first-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-first-example.png?raw=true\"></p>\n<blockquote>\n<p>call-stack-second-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-second-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-second-example.png?raw=true\"></p>\n<blockquote>\n<p>call-stack-third-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-third-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/call-stack-third-example.png?raw=true\"></p>\n<blockquote>\n<p>cdn-cors-header.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cdn-cors-header.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cdn-cors-header.png?raw=true\"></p>\n<blockquote>\n<p>checklist.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/checklist.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/checklist.png?raw=true\"></p>\n<blockquote>\n<p>chrome_E0QUXhDFv8.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_E0QUXhDFv8.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_E0QUXhDFv8.png?raw=true\"></p>\n<blockquote>\n<p>chrome_ajdk5oqXGC.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_ajdk5oqXGC.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_ajdk5oqXGC.png?raw=true\"></p>\n<blockquote>\n<p>chrome_nzhECqyCjh.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_nzhECqyCjh.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/chrome_nzhECqyCjh.png?raw=true\"></p>\n<blockquote>\n<p>circle-ci.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/circle-ci.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/circle-ci.jpg?raw=true\"></p>\n<blockquote>\n<p>circle-cropped.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/circle-cropped.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/circle-cropped.png?raw=true\"></p>\n<blockquote>\n<p>cm-steps-simple.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cm-steps-simple.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cm-steps-simple.png?raw=true\"></p>\n<blockquote>\n<p>code.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code.png?raw=true\"></p>\n<blockquote>\n<p>code_mg4k5cd9s4.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code_mg4k5cd9s4.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code_mg4k5cd9s4.png?raw=true\"></p>\n<blockquote>\n<p>code_mg4k5cd9s5.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code_mg4k5cd9s5.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/code_mg4k5cd9s5.png?raw=true\"></p>\n<blockquote>\n<p>codewinds-004.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/codewinds-004.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/codewinds-004.png?raw=true\"></p>\n<blockquote>\n<p>command-line-basics.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/command-line-basics.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/command-line-basics.png?raw=true\"></p>\n<blockquote>\n<p>confluence.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/confluence.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/confluence.jpg?raw=true\"></p>\n<blockquote>\n<p>confluence.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/confluence.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/confluence.png?raw=true\"></p>\n<blockquote>\n<p>console-log-browser-expanded.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/console-log-browser-expanded.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/console-log-browser-expanded.png?raw=true\"></p>\n<blockquote>\n<p>console-log-browser.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/console-log-browser.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/console-log-browser.png?raw=true\"></p>\n<blockquote>\n<p>contact.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/contact.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/contact.png?raw=true\"></p>\n<blockquote>\n<p>cool-background.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cool-background.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cool-background.png?raw=true\"></p>\n<blockquote>\n<p>cool-comet.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cool-comet.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cool-comet.png?raw=true\"></p>\n<blockquote>\n<p>cover-letter.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cover-letter.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cover-letter.png?raw=true\"></p>\n<blockquote>\n<p>cow-say.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cow-say.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cow-say.png?raw=true\"></p>\n<blockquote>\n<p>cplusplus.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cplusplus.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cplusplus.png?raw=true\"></p>\n<blockquote>\n<p>css.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/css.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/css.png?raw=true\"></p>\n<blockquote>\n<p>cube.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cube.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/cube.gif?raw=true\"></p>\n<blockquote>\n<p>curious-eggplant.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/curious-eggplant.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/curious-eggplant.jpg?raw=true\"></p>\n<blockquote>\n<p>data-struc2.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc2.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc2.gif?raw=true\"></p>\n<blockquote>\n<p>data-struc3.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc3.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/data-struc3.gif?raw=true\"></p>\n<blockquote>\n<p>daw.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/daw.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/daw.jpg?raw=true\"></p>\n<blockquote>\n<p>demo.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/demo.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/demo.gif?raw=true\"></p>\n<blockquote>\n<p>dense-js-code.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dense-js-code.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dense-js-code.jpg?raw=true\"></p>\n<blockquote>\n<p>devtools-dev.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/devtools-dev.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/devtools-dev.png?raw=true\"></p>\n<blockquote>\n<p>devtools-prod.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/devtools-prod.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/devtools-prod.png?raw=true\"></p>\n<blockquote>\n<p>digital-ocean.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/digital-ocean.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/digital-ocean.jpg?raw=true\"></p>\n<blockquote>\n<p>display.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/display.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/display.png?raw=true\"></p>\n<blockquote>\n<p>django.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/django.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/django.png?raw=true\"></p>\n<blockquote>\n<p>docker.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docker.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docker.png?raw=true\"></p>\n<blockquote>\n<p>docker2.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docker2.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docker2.png?raw=true\"></p>\n<blockquote>\n<p>docs.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docs.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/docs.png?raw=true\"></p>\n<blockquote>\n<p>dom.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dom.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dom.png?raw=true\"></p>\n<blockquote>\n<p>drive.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/drive.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/drive.png?raw=true\"></p>\n<blockquote>\n<p>dropbox.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dropbox.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dropbox.jpg?raw=true\"></p>\n<blockquote>\n<p>ds-algo.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.gif?raw=true\"></p>\n<blockquote>\n<p>ds-algo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-algo.png?raw=true\"></p>\n<blockquote>\n<p>ds-whiteboard.1.webp</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-whiteboard.1.webp?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-whiteboard.1.webp?raw=true\"></p>\n<blockquote>\n<p>ds-whiteboard.webp</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-whiteboard.webp?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds-whiteboard.webp?raw=true\"></p>\n<blockquote>\n<p>ds.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ds.png?raw=true\"></p>\n<blockquote>\n<p>dtw-algo.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-algo.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-algo.jpg?raw=true\"></p>\n<blockquote>\n<p>dtw-grid.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-grid.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-grid.png?raw=true\"></p>\n<blockquote>\n<p>dtw-slideshow.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-slideshow.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw-slideshow.gif?raw=true\"></p>\n<blockquote>\n<p>dtw.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.gif?raw=true\"></p>\n<blockquote>\n<p>dtw.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.jpg?raw=true\"></p>\n<blockquote>\n<p>dtw.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/dtw.png?raw=true\"></p>\n<blockquote>\n<p>e40e889a-00fa-4786-a498-8990185b3698.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/e40e889a-00fa-4786-a498-8990185b3698.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/e40e889a-00fa-4786-a498-8990185b3698.jpeg?raw=true\"></p>\n<blockquote>\n<p>eaf976e3-e635-43a6-a123-bece3ed69898.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eaf976e3-e635-43a6-a123-bece3ed69898.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eaf976e3-e635-43a6-a123-bece3ed69898.jpeg?raw=true\"></p>\n<blockquote>\n<p>elastic-cloud.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/elastic-cloud.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/elastic-cloud.png?raw=true\"></p>\n<blockquote>\n<p>embedded-media.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embedded-media.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embedded-media.png?raw=true\"></p>\n<blockquote>\n<p>embeds.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embeds.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embeds.jpg?raw=true\"></p>\n<blockquote>\n<p>embeds.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embeds.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/embeds.png?raw=true\"></p>\n<blockquote>\n<p>ember-original-wordmark.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ember-original-wordmark.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ember-original-wordmark.png?raw=true\"></p>\n<blockquote>\n<p>equation.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/equation.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/equation.gif?raw=true\"></p>\n<blockquote>\n<p>error-boundaries-stack-trace-line-numbers.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/error-boundaries-stack-trace-line-numbers.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/error-boundaries-stack-trace-line-numbers.png?raw=true\"></p>\n<blockquote>\n<p>error-boundaries-stack-trace.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/error-boundaries-stack-trace.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/error-boundaries-stack-trace.png?raw=true\"></p>\n<blockquote>\n<p>es6.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/es6.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/es6.jpg?raw=true\"></p>\n<blockquote>\n<p>es6.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/es6.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/es6.png?raw=true\"></p>\n<blockquote>\n<p>eventloop.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eventloop.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/eventloop.gif?raw=true\"></p>\n<blockquote>\n<p>exception-call-stack.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/exception-call-stack.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/exception-call-stack.png?raw=true\"></p>\n<blockquote>\n<p>execution-order-first-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/execution-order-first-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/execution-order-first-example.png?raw=true\"></p>\n<blockquote>\n<p>execution-order-second-example.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/execution-order-second-example.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/execution-order-second-example.png?raw=true\"></p>\n<blockquote>\n<p>express-original-wordmark.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/express-original-wordmark.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/express-original-wordmark.png?raw=true\"></p>\n<blockquote>\n<p>express.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/express.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/express.png?raw=true\"></p>\n<blockquote>\n<p>ezgif.com-gif-maker.mp4</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ezgif.com-gif-maker.mp4?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ezgif.com-gif-maker.mp4?raw=true\"></p>\n<blockquote>\n<p>fairlawn.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fairlawn.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fairlawn.png?raw=true\"></p>\n<blockquote>\n<p>favicon.1.ico</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.1.ico?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.1.ico?raw=true\"></p>\n<blockquote>\n<p>favicon.ico</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.ico?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.ico?raw=true\"></p>\n<blockquote>\n<p>favicon.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/favicon.png?raw=true\"></p>\n<blockquote>\n<p>festive-zebra.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/festive-zebra.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/festive-zebra.png?raw=true\"></p>\n<blockquote>\n<p>fft.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fft.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fft.jpg?raw=true\"></p>\n<blockquote>\n<p>file-system.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/file-system.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/file-system.jpg?raw=true\"></p>\n<blockquote>\n<p>fillmurray.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fillmurray.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/fillmurray.jpg?raw=true\"></p>\n<blockquote>\n<p>firebase.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/firebase.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/firebase.png?raw=true\"></p>\n<blockquote>\n<p>firebase3.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/firebase3.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/firebase3.jpg?raw=true\"></p>\n<blockquote>\n<p>flow-control-py.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/flow-control-py.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/flow-control-py.jpg?raw=true\"></p>\n<blockquote>\n<p>gatsby-cli.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-cli.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-cli.png?raw=true\"></p>\n<blockquote>\n<p>gatsby-graphiql-explorer.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-graphiql-explorer.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-graphiql-explorer.png?raw=true\"></p>\n<blockquote>\n<p>gatsby-paginate.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-paginate.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-paginate.png?raw=true\"></p>\n<blockquote>\n<p>gatsby-sourcery.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-sourcery.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby-sourcery.png?raw=true\"></p>\n<blockquote>\n<p>gatsby.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gatsby.png?raw=true\"></p>\n<blockquote>\n<p>gh-pages.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gh-pages.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gh-pages.png?raw=true\"></p>\n<blockquote>\n<p>gif-4mb.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gif-4mb.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gif-4mb.gif?raw=true\"></p>\n<blockquote>\n<p>git-banner.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-banner.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-banner.png?raw=true\"></p>\n<blockquote>\n<p>git-html-preview.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-html-preview.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-html-preview.gif?raw=true\"></p>\n<blockquote>\n<p>git-merge.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-merge.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-merge.jpeg?raw=true\"></p>\n<blockquote>\n<p>git-preview.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-preview.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git-preview.gif?raw=true\"></p>\n<blockquote>\n<p>git.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/git.png?raw=true\"></p>\n<blockquote>\n<p>globals.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/globals.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/globals.png?raw=true\"></p>\n<blockquote>\n<p>goals.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/goals.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/goals.jpg?raw=true\"></p>\n<blockquote>\n<p>google-adds.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-adds.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-adds.jpg?raw=true\"></p>\n<blockquote>\n<p>google-analytics.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-analytics.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-analytics.jpg?raw=true\"></p>\n<blockquote>\n<p>google-api.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-api.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-api.png?raw=true\"></p>\n<blockquote>\n<p>google-cloud%20(2).png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-cloud%20(2).png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-cloud%20(2).png?raw=true\"></p>\n<blockquote>\n<p>google-cloud.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-cloud.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-cloud.png?raw=true\"></p>\n<blockquote>\n<p>google-drive.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-drive.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/google-drive.jpg?raw=true\"></p>\n<blockquote>\n<p>googleTagManager.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/googleTagManager.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/googleTagManager.png?raw=true\"></p>\n<blockquote>\n<p>googlemaps.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/googlemaps.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/googlemaps.png?raw=true\"></p>\n<blockquote>\n<p>gradients_3.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gradients_3.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gradients_3.png?raw=true\"></p>\n<blockquote>\n<p>granular-dom-updates.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/granular-dom-updates.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/granular-dom-updates.gif?raw=true\"></p>\n<blockquote>\n<p>graphql-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/graphql-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/graphql-logo.png?raw=true\"></p>\n<blockquote>\n<p>graphql.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/graphql.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/graphql.png?raw=true\"></p>\n<blockquote>\n<p>gulp.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gulp.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/gulp.png?raw=true\"></p>\n<blockquote>\n<p>heroku.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/heroku.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/heroku.png?raw=true\"></p>\n<blockquote>\n<p>home-button.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home-button.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home-button.png?raw=true\"></p>\n<blockquote>\n<p>home2022-01-20-23<em>58</em>59.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home2022-01-20-23_58_59.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home2022-01-20-23_58_59.png?raw=true\"></p>\n<blockquote>\n<p>home2022-01-20-23<em>58</em>60.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home2022-01-20-23_58_60.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/home2022-01-20-23_58_60.png?raw=true\"></p>\n<blockquote>\n<p>html.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html.png?raw=true\"></p>\n<blockquote>\n<p>html2.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html2.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html2.png?raw=true\"></p>\n<blockquote>\n<p>html5.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html5.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/html5.png?raw=true\"></p>\n<blockquote>\n<p>iconifier-readme.txt</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iconifier-readme.txt?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iconifier-readme.txt?raw=true\"></p>\n<blockquote>\n<p>iframes.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iframes.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iframes.gif?raw=true\"></p>\n<blockquote>\n<p>image-of-resume.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/image-of-resume.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/image-of-resume.png?raw=true\"></p>\n<blockquote>\n<p>implementation-notes-tree.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/implementation-notes-tree.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/implementation-notes-tree.png?raw=true\"></p>\n<blockquote>\n<p>iter.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iter.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/iter.jpg?raw=true\"></p>\n<blockquote>\n<p>jam.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jam.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jam.png?raw=true\"></p>\n<blockquote>\n<p>jamstack.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jamstack.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jamstack.png?raw=true\"></p>\n<blockquote>\n<p>java.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/java.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/java.png?raw=true\"></p>\n<blockquote>\n<p>javascript-jabber.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript-jabber.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript-jabber.png?raw=true\"></p>\n<blockquote>\n<p>javascript.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript.gif?raw=true\"></p>\n<blockquote>\n<p>javascript.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/javascript.jpeg?raw=true\"></p>\n<blockquote>\n<p>jenkins.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jenkins.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jenkins.png?raw=true\"></p>\n<blockquote>\n<p>jest.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jest.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jest.png?raw=true\"></p>\n<blockquote>\n<p>jira.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jira.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jira.jpg?raw=true\"></p>\n<blockquote>\n<p>jquery-logo-no-title.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery-logo-no-title.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery-logo-no-title.jpg?raw=true\"></p>\n<blockquote>\n<p>jquery.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery.jpg?raw=true\"></p>\n<blockquote>\n<p>jquery.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery.png?raw=true\"></p>\n<blockquote>\n<p>jquery2.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery2.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/jquery2.png?raw=true\"></p>\n<blockquote>\n<p>js-code-spiral-num.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/js-code-spiral-num.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/js-code-spiral-num.png?raw=true\"></p>\n<blockquote>\n<p>js-questions-n-answers.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/js-questions-n-answers.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/js-questions-n-answers.png?raw=true\"></p>\n<blockquote>\n<p>keep-calm.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/keep-calm.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/keep-calm.png?raw=true\"></p>\n<blockquote>\n<p>keyboard-focus.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/keyboard-focus.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/keyboard-focus.png?raw=true\"></p>\n<blockquote>\n<p>kind-whale.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/kind-whale.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/kind-whale.gif?raw=true\"></p>\n<blockquote>\n<p>kub.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/kub.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/kub.png?raw=true\"></p>\n<blockquote>\n<p>lambda-demo.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/lambda-demo.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/lambda-demo.gif?raw=true\"></p>\n<blockquote>\n<p>lambda.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/lambda.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/lambda.png?raw=true\"></p>\n<blockquote>\n<p>linux-original.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux-original.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux-original.png?raw=true\"></p>\n<blockquote>\n<p>linux.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/linux.png?raw=true\"></p>\n<blockquote>\n<p>logo-animated-1-.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-animated-1-.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-animated-1-.gif?raw=true\"></p>\n<blockquote>\n<p>logo-circle.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-circle.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-circle.png?raw=true\"></p>\n<blockquote>\n<p>logo-final-touchup.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-final-touchup.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo-final-touchup.png?raw=true\"></p>\n<blockquote>\n<p>logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/logo.png?raw=true\"></p>\n<blockquote>\n<p>macos.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/macos.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/macos.png?raw=true\"></p>\n<blockquote>\n<p>madewith.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/madewith.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/madewith.png?raw=true\"></p>\n<blockquote>\n<p>main-blog.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/main-blog.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/main-blog.png?raw=true\"></p>\n<blockquote>\n<p>map.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/map.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/map.jpg?raw=true\"></p>\n<blockquote>\n<p>markdown.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/markdown.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/markdown.png?raw=true\"></p>\n<blockquote>\n<p>maroon-onion.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/maroon-onion.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/maroon-onion.gif?raw=true\"></p>\n<blockquote>\n<p>may-15-snap.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/may-15-snap.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/may-15-snap.png?raw=true\"></p>\n<blockquote>\n<p>md.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/md.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/md.png?raw=true\"></p>\n<blockquote>\n<p>media-querry.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/media-querry.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/media-querry.png?raw=true\"></p>\n<blockquote>\n<p>medium-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/medium-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/medium-logo.png?raw=true\"></p>\n<blockquote>\n<p>medium.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/medium.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/medium.png?raw=true\"></p>\n<blockquote>\n<p>mihir-about.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir-about.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir-about.png?raw=true\"></p>\n<blockquote>\n<p>mihir.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir.jpg?raw=true\"></p>\n<blockquote>\n<p>mihir.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mihir.png?raw=true\"></p>\n<blockquote>\n<p>mini-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mini-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mini-logo.png?raw=true\"></p>\n<blockquote>\n<p>mocha.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mocha.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/mocha.png?raw=true\"></p>\n<blockquote>\n<p>my-back.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/my-back.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/my-back.png?raw=true\"></p>\n<blockquote>\n<p>nasa<em>earth</em>grid.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_earth_grid.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_earth_grid.jpg?raw=true\"></p>\n<blockquote>\n<p>nasa<em>new</em>york<em>city</em>grid.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_new_york_city_grid.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_new_york_city_grid.jpg?raw=true\"></p>\n<blockquote>\n<p>nasa<em>space</em>shuttle_challenger.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_space_shuttle_challenger.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_space_shuttle_challenger.jpg?raw=true\"></p>\n<blockquote>\n<p>nasa<em>the</em>blue_marble-1-.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_the_blue_marble-1-.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nasa_the_blue_marble-1-.jpg?raw=true\"></p>\n<blockquote>\n<p>needle.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/needle.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/needle.jpg?raw=true\"></p>\n<blockquote>\n<p>netlify.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/netlify.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/netlify.png?raw=true\"></p>\n<blockquote>\n<p>netlifycms.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/netlifycms.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/netlifycms.png?raw=true\"></p>\n<blockquote>\n<p>neural.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/neural.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/neural.png?raw=true\"></p>\n<blockquote>\n<p>nextjs.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nextjs.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nextjs.png?raw=true\"></p>\n<blockquote>\n<p>nj-devils.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nj-devils.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/nj-devils.jpg?raw=true\"></p>\n<blockquote>\n<p>njdev.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/njdev.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/njdev.jpg?raw=true\"></p>\n<blockquote>\n<p>node-express.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-express.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-express.png?raw=true\"></p>\n<blockquote>\n<p>node-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-logo.png?raw=true\"></p>\n<blockquote>\n<p>node-package-manager.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-package-manager.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node-package-manager.png?raw=true\"></p>\n<blockquote>\n<p>node.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node.jpg?raw=true\"></p>\n<blockquote>\n<p>node_modules-content.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node_modules-content.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/node_modules-content.png?raw=true\"></p>\n<blockquote>\n<p>octocat.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/octocat.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/octocat.png?raw=true\"></p>\n<blockquote>\n<p>original-webdevhub-log.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/original-webdevhub-log.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/original-webdevhub-log.png?raw=true\"></p>\n<blockquote>\n<p>outdated-packages.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outdated-packages.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outdated-packages.png?raw=true\"></p>\n<blockquote>\n<p>outerclick-with-keyboard.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outerclick-with-keyboard.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outerclick-with-keyboard.gif?raw=true\"></p>\n<blockquote>\n<p>outerclick-with-mouse.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outerclick-with-mouse.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/outerclick-with-mouse.gif?raw=true\"></p>\n<blockquote>\n<p>perf-dom.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-dom.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-dom.png?raw=true\"></p>\n<blockquote>\n<p>perf-exclusive.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-exclusive.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-exclusive.png?raw=true\"></p>\n<blockquote>\n<p>perf-inclusive.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-inclusive.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-inclusive.png?raw=true\"></p>\n<blockquote>\n<p>perf-wasted.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-wasted.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/perf-wasted.png?raw=true\"></p>\n<blockquote>\n<p>php.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/php.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/php.jpg?raw=true\"></p>\n<blockquote>\n<p>pleasant-birch.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pleasant-birch.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pleasant-birch.png?raw=true\"></p>\n<blockquote>\n<p>pojoaque.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pojoaque.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pojoaque.jpg?raw=true\"></p>\n<blockquote>\n<p>portfolio-cover.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio-cover.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio-cover.png?raw=true\"></p>\n<blockquote>\n<p>portfolio.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio.gif?raw=true\"></p>\n<blockquote>\n<p>portfolio.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/portfolio.jpg?raw=true\"></p>\n<blockquote>\n<p>postman.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/postman.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/postman.png?raw=true\"></p>\n<blockquote>\n<p>posts.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/posts.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/posts.png?raw=true\"></p>\n<blockquote>\n<p>potluck-planner.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/potluck-planner.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/potluck-planner.jpg?raw=true\"></p>\n<blockquote>\n<p>printing-press.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/printing-press.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/printing-press.jpg?raw=true\"></p>\n<blockquote>\n<p>profile.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/profile.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/profile.png?raw=true\"></p>\n<blockquote>\n<p>programmable-search-engine.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/programmable-search-engine.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/programmable-search-engine.png?raw=true\"></p>\n<blockquote>\n<p>projects.jpeg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/projects.jpeg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/projects.jpeg?raw=true\"></p>\n<blockquote>\n<p>projects.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/projects.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/projects.jpg?raw=true\"></p>\n<blockquote>\n<p>psql-diagram.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-diagram.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-diagram.jpg?raw=true\"></p>\n<blockquote>\n<p>psql-postgres.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-postgres.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-postgres.png?raw=true\"></p>\n<blockquote>\n<p>psql-schema.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-schema.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql-schema.jpg?raw=true\"></p>\n<blockquote>\n<p>psql.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/psql.jpg?raw=true\"></p>\n<blockquote>\n<p>pug.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pug.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pug.png?raw=true\"></p>\n<blockquote>\n<p>pull-request-blog.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pull-request-blog.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pull-request-blog.png?raw=true\"></p>\n<blockquote>\n<p>pull-request.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pull-request.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pull-request.jpg?raw=true\"></p>\n<blockquote>\n<p>puppetter.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/puppetter.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/puppetter.png?raw=true\"></p>\n<blockquote>\n<p>pure-data.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pure-data.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/pure-data.png?raw=true\"></p>\n<blockquote>\n<p>py.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/py.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/py.jpg?raw=true\"></p>\n<blockquote>\n<p>python-language.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-language.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-language.jpg?raw=true\"></p>\n<blockquote>\n<p>python-logo-simple.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-logo-simple.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python-logo-simple.png?raw=true\"></p>\n<blockquote>\n<p>python.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python.jpg?raw=true\"></p>\n<blockquote>\n<p>python.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python.png?raw=true\"></p>\n<blockquote>\n<p>python1-00990432.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python1-00990432.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python1-00990432.jpg?raw=true\"></p>\n<blockquote>\n<p>python2-15e88a3a.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python2-15e88a3a.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python2-15e88a3a.jpg?raw=true\"></p>\n<blockquote>\n<p>python2.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python2.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python2.jpg?raw=true\"></p>\n<blockquote>\n<p>python3-15e88a3a.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python3-15e88a3a.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/python3-15e88a3a.jpg?raw=true\"></p>\n<blockquote>\n<p>react%20(1).png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react%20(1).png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react%20(1).png?raw=true\"></p>\n<blockquote>\n<p>react-banner.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-banner.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-banner.jpg?raw=true\"></p>\n<blockquote>\n<p>react-dark.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-dark.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-dark.jpg?raw=true\"></p>\n<blockquote>\n<p>react-devtools-state.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-devtools-state.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-devtools-state.gif?raw=true\"></p>\n<blockquote>\n<p>react-fancy-logo.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-fancy-logo.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react-fancy-logo.jpg?raw=true\"></p>\n<blockquote>\n<p>react.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.gif?raw=true\"></p>\n<blockquote>\n<p>react.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.jpg?raw=true\"></p>\n<blockquote>\n<p>react.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/react.png?raw=true\"></p>\n<blockquote>\n<p>recording-studio.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/recording-studio.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/recording-studio.jpg?raw=true\"></p>\n<blockquote>\n<p>recursive-settimeout.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/recursive-settimeout.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/recursive-settimeout.png?raw=true\"></p>\n<blockquote>\n<p>redis.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redis.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redis.png?raw=true\"></p>\n<blockquote>\n<p>redu-squarex.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redu-squarex.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redu-squarex.jpg?raw=true\"></p>\n<blockquote>\n<p>redux.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redux.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/redux.gif?raw=true\"></p>\n<blockquote>\n<p>resume-bg.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/resume-bg.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/resume-bg.png?raw=true\"></p>\n<blockquote>\n<p>resume.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/resume.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/resume.jpg?raw=true\"></p>\n<blockquote>\n<p>royal-kangaroo.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/royal-kangaroo.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/royal-kangaroo.jpg?raw=true\"></p>\n<blockquote>\n<p>ruby.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ruby.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ruby.png?raw=true\"></p>\n<blockquote>\n<p>sass.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sass.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sass.png?raw=true\"></p>\n<blockquote>\n<p>scala.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/scala.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/scala.png?raw=true\"></p>\n<blockquote>\n<p>school-book.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/school-book.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/school-book.1.png?raw=true\"></p>\n<blockquote>\n<p>school-book.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/school-book.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/school-book.png?raw=true\"></p>\n<blockquote>\n<p>scope-closure.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/scope-closure.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/scope-closure.jpg?raw=true\"></p>\n<blockquote>\n<p>screenshots.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/screenshots.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/screenshots.png?raw=true\"></p>\n<blockquote>\n<p>selenium.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/selenium.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/selenium.jpg?raw=true\"></p>\n<blockquote>\n<p>senic.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/senic.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/senic.png?raw=true\"></p>\n<blockquote>\n<p>sequelize.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sequelize.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sequelize.png?raw=true\"></p>\n<blockquote>\n<p>setinterval-ok.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-ok.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-ok.png?raw=true\"></p>\n<blockquote>\n<p>setinterval-overlapping.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-overlapping.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-overlapping.1.png?raw=true\"></p>\n<blockquote>\n<p>setinterval-overlapping.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-overlapping.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-overlapping.png?raw=true\"></p>\n<blockquote>\n<p>setinterval-varying-duration.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-varying-duration.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/setinterval-varying-duration.png?raw=true\"></p>\n<blockquote>\n<p>shopify.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/shopify.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/shopify.png?raw=true\"></p>\n<blockquote>\n<p>should-component-update.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/should-component-update.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/should-component-update.png?raw=true\"></p>\n<blockquote>\n<p>showcase.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/showcase.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/showcase.1.png?raw=true\"></p>\n<blockquote>\n<p>showcase.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/showcase.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/showcase.png?raw=true\"></p>\n<blockquote>\n<p>sine-wav-bak%20(1).gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sine-wav-bak%20(1).gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sine-wav-bak%20(1).gif?raw=true\"></p>\n<blockquote>\n<p>skype.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/skype.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/skype.png?raw=true\"></p>\n<blockquote>\n<p>slack.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/slack.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/slack.jpg?raw=true\"></p>\n<blockquote>\n<p>sourcetree.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sourcetree.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sourcetree.png?raw=true\"></p>\n<blockquote>\n<p>sql_server.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sql_server.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sql_server.png?raw=true\"></p>\n<blockquote>\n<p>sqlite.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sqlite.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sqlite.jpg?raw=true\"></p>\n<blockquote>\n<p>static-server.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/static-server.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/static-server.1.png?raw=true\"></p>\n<blockquote>\n<p>static-server.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/static-server.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/static-server.png?raw=true\"></p>\n<blockquote>\n<p>sublime.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sublime.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/sublime.jpg?raw=true\"></p>\n<blockquote>\n<p>superb-panda.PNG</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/superb-panda.PNG?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/superb-panda.PNG?raw=true\"></p>\n<blockquote>\n<p>swift.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/swift.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/swift.png?raw=true\"></p>\n<blockquote>\n<p>tetris.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tetris.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tetris.png?raw=true\"></p>\n<blockquote>\n<p>tex.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tex.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tex.png?raw=true\"></p>\n<blockquote>\n<p>textools.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/textools.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/textools.png?raw=true\"></p>\n<blockquote>\n<p>theme.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/theme.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/theme.1.png?raw=true\"></p>\n<blockquote>\n<p>theme.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/theme.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/theme.png?raw=true\"></p>\n<blockquote>\n<p>thinking-in-react-tagtree.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/thinking-in-react-tagtree.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/thinking-in-react-tagtree.png?raw=true\"></p>\n<blockquote>\n<p>thoughtful-neptune.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/thoughtful-neptune.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/thoughtful-neptune.png?raw=true\"></p>\n<blockquote>\n<p>tomcat.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tomcat.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tomcat.png?raw=true\"></p>\n<blockquote>\n<p>tools.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tools.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tools.1.png?raw=true\"></p>\n<blockquote>\n<p>tools.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tools.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/tools.png?raw=true\"></p>\n<blockquote>\n<p>top-half-mihir.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/top-half-mihir.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/top-half-mihir.png?raw=true\"></p>\n<blockquote>\n<p>travis.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/travis.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/travis.png?raw=true\"></p>\n<blockquote>\n<p>ts.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ts.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ts.jpg?raw=true\"></p>\n<blockquote>\n<p>ubuntu.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ubuntu.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/ubuntu.jpg?raw=true\"></p>\n<blockquote>\n<p>updated-packages.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/updated-packages.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/updated-packages.1.png?raw=true\"></p>\n<blockquote>\n<p>updated-packages.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/updated-packages.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/updated-packages.png?raw=true\"></p>\n<blockquote>\n<p>usage.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/usage.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/usage.png?raw=true\"></p>\n<blockquote>\n<p>using-the-dom.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/using-the-dom.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/using-the-dom.png?raw=true\"></p>\n<blockquote>\n<p>version-control.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/version-control.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/version-control.png?raw=true\"></p>\n<blockquote>\n<p>vim_logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vim_logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vim_logo.png?raw=true\"></p>\n<blockquote>\n<p>violet-pluto.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/violet-pluto.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/violet-pluto.png?raw=true\"></p>\n<blockquote>\n<p>virtual-box.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/virtual-box.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/virtual-box.png?raw=true\"></p>\n<blockquote>\n<p>visual-studio.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/visual-studio.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/visual-studio.png?raw=true\"></p>\n<blockquote>\n<p>vscode-extensions-list.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode-extensions-list.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode-extensions-list.png?raw=true\"></p>\n<blockquote>\n<p>vscode.1.webp</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.1.webp?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.1.webp?raw=true\"></p>\n<blockquote>\n<p>vscode.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.png?raw=true\"></p>\n<blockquote>\n<p>vscode.webp</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.webp?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/vscode.webp?raw=true\"></p>\n<blockquote>\n<p>web-dev-back.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/web-dev-back.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/web-dev-back.jpg?raw=true\"></p>\n<blockquote>\n<p>web-development.gif</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/web-development.gif?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/web-development.gif?raw=true\"></p>\n<blockquote>\n<p>webdev.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webdev.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webdev.png?raw=true\"></p>\n<blockquote>\n<p>webpack.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webpack.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webpack.png?raw=true\"></p>\n<blockquote>\n<p>webscraping.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webscraping.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webscraping.1.png?raw=true\"></p>\n<blockquote>\n<p>webscraping.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webscraping.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/webscraping.png?raw=true\"></p>\n<blockquote>\n<p>windows.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/windows.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/windows.png?raw=true\"></p>\n<blockquote>\n<p>woodcuts_1.jpg</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/woodcuts_1.jpg?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/woodcuts_1.jpg?raw=true\"></p>\n<blockquote>\n<p>wordpress-logo.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/wordpress-logo.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/wordpress-logo.png?raw=true\"></p>\n<blockquote>\n<p>xcode%20(1).png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/xcode%20(1).png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/xcode%20(1).png?raw=true\"></p>\n<blockquote>\n<p>zumzi-video-chat.1.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi-video-chat.1.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi-video-chat.1.png?raw=true\"></p>\n<blockquote>\n<p>zumzi-video-chat.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi-video-chat.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi-video-chat.png?raw=true\"></p>\n<blockquote>\n<p>zumzi.png</p>\n</blockquote>\n<p><img src=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi.png?raw=true\" alt=\"https://raw.githubusercontent.com/bgoonz/BGOONZ_BLOG_2.0/master/static/images/zumzi.png?raw=true\"></p>"},{"url":"/docs/about/","relativePath":"docs/about/index.md","relativeDir":"docs/about","base":"index.md","name":"index","frontmatter":{"title":"About","excerpt":"Web-Dev-Hub is my personal blogand documentation site","seo":{"title":"About","description":"Bryan Guner personal blog about page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"About","keyName":"property"},{"name":"og:description","value":"This is the About page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"About"},{"name":"twitter:description","value":"This is the About page"}]},"template":"docs"},"html":"<div align=\"center\">\n<h1>Hi 👋, I'm Bryan</h1>\n  \n## ➤ _📧_ [bryan.guner@gmail.com](📲) _☎️_ [551-254-5505](551-254-5505)\n<p><img src=\"https://views.whatilearened.today/views/github/bgoonz/views.svg\" alt=\"Profile views\"><a href=\"https://gitter.im/bgoonz/community?utm_source=badge&#x26;utm_medium=badge&#x26;utm_campaign=pr-badge\"><img src=\"https://badges.gitter.im/bgoonz/community.svg\" alt=\"Gitter\"></a><a href=\"https://hackmd.io/5DeYj2oXTvGJ1-Xvp1Jo2Q\"><img src=\"https://hackmd.io/5DeYj2oXTvGJ1-Xvp1Jo2Q/badge\" alt=\"hackmd-github-sync-badge\"></a><a href=\"https://github.com/bgoonz?tab=followers\"><img src=\"https://img.shields.io/github/followers/bgoonz.svg?style=social&#x26;label=Follow&#x26;maxAge=2592000\" alt=\"GitHub followers\"></a></p>\n<h3><a href=\"https://bgoonz-blog.netlify.app/\">💻WEBSITE💻</a> ⇄ <a href=\"https://bg-portfolio.netlify.app/\">Portfolio</a> ⇄ <a href=\"https://bgoonz.github.io/github-stats-website/\">Recent Work</a> ⇄ <a href=\"https://bryan-guner.gitbook.io/my-docs/\">MY DOCS📚</a></h3>\n<p> <a href=\"https://github.com/bgoonz/bgoonz/raw/master/bryan_guner_resume_2021_V9.pdf\"><strong>📁DOWNLOAD RESUME📁</strong></a></p>\n<p><a href=\"https://bgoonzblog20master.gatsbyjs.io/\"><img src=\"https://img.shields.io/badge/-%E2%9D%A4_Portfolio-f58?style=flat-square&#x26;logo=a&#x26;logoColor=white&#x26;link=https://bgoonzblog20master.gatsbyjs.io/\" alt=\"Portfolio\"></a>\n<a href=\"https://1drv.ms/b/s!AkGiZ9n9CRDSquIDCW3sdtgIghzpeg?e=GcgN10\" download><img src=\"https://img.shields.io/badge/-Resume-f00?style=flat-square&#x26;logo=adobe-acrobat-reader&#x26;logoColor=white\" alt=\"Resume PDF\"></a>\n<a href=\"mailto:bryan.guner@gmail.com\"><img src=\"https://img.shields.io/badge/bryan.guner@gmail.com-f4b400?style=flat-square&#x26;logo=gmail&#x26;logoColor=black&#x26;link=mailto:bryan.guner@gmail.com\" alt=\"Bryan&#x27;s email\"></a>\n<a href=\"https://web-dev-hub.com/\"><img src=\"https://img.shields.io/badge/-Blog-21759b?style=flat-square&#x26;logo=WordPress&#x26;logoColor=white&#x26;link=https://bgoonzblog20master.gatsbyjs.io/\" alt=\"Blog\"></a>\n<a href=\"https://www.linkedin.com/in/bryan-guner-046199128/\"><img src=\"https://img.shields.io/badge/-LinkedIn-0077b5?style=flat-square&#x26;logo=Linkedin&#x26;logoColor=white&#x26;link=https://www.linkedin.com/in/bryan-guner-046199128/\" alt=\"Linkedin\"></a>\n<a href=\"https://angel.co/u/bryan-guner\"><img src=\"https://img.shields.io/badge/-AngelList-black?style=flat-square&#x26;logo=AngelList&#x26;logoColor=white&#x26;link=https://angel.co/u/bryan-guner\" alt=\"AngelList\"></a>\n<a href=\"https://github.com/bgoonz\"><img src=\"https://img.shields.io/github/followers/bgoonz?label=follow&#x26;style=social\" alt=\"GitHub bgoonz\"></a></p>\n<p align=\"center\">\n  \n  <a href=\"mailto:bryan.guner@gmail.com\"><img src=\"https://img.icons8.com/color/96/000000/gmail.png\" alt=\"email\"/></a><a href=\"https://www.facebook.com/bryan.guner/\"><img src=\"https://img.icons8.com/color/96/000000/facebook.png\" alt=\"facebook\"/></a><a href=\"https://twitter.com/bgooonz\"><img src=\"https://img.icons8.com/color/96/000000/twitter-squared.png\" alt=\"twitter\"/></a><a href=\"https://www.youtube.com/channel/UC9-rYyUMsnEBK8G8fCyrXXA/videos\"><img src=\"https://img.icons8.com/color/96/000000/youtube.png\" alt=\"youtube\"/></a><a href=\"https://www.instagram.com/bgoonz/?hl=en\"><img src=\"https://img.icons8.com/color/96/000000/instagram-new.png\" alt=\"instagram\"/></a><a href=\"https://www.linkedin.com/in/bryan-guner-046199128/\"><img src=\"https://img.icons8.com/color/96/000000/linkedin.png\" alt=\"linkedin\"/></a>\n  <a href=\"https://bryanguner.medium.com/\"><img src=\"https://img.icons8.com/color/96/000000/medium-logo.png\" alt=\"medium\"/></a><a href=\"https://open.spotify.com/user/bgoonz?si=ShH9wYbIQWab5Jz_30BKFw\"><img src=\"https://img.icons8.com/color/96/000000/spotify--v1.png\" alt=\"spotify\"/></a>\n  </p>\n<h2>Bgoonz</h2>\n<div align=center>\n  \n![--bgoonz's GitHub followers](https://img.shields.io/github/followers/bgoonz?color=00bbbb&style=for-the-badge&logo=github&logoColor=fff)\n</div>\n<p>Hi there everyone! Welcome to my GitHub profile!</p>\n<h2> <img src=\"https://static.thenounproject.com/png/5639-200.png\" alt=\"Statistics Icons - Download Free Vector Icons | Noun Project\" width=\"15px\"/> My stats</h2>\n<p><img src=\"https://github-readme-stats.vercel.app/api?username=bgoonz&#x26;include_all_commits=true&#x26;show_icons=true&#x26;theme=prussian&#x26;count_private=true&#x26;cache_seconds=5\" alt=\"stats\">\n<a href=\"#\"><img src=\"https://github-readme-stats.vercel.app/api/top-langs/?username=bgoonz&#x26;theme=prussian&#x26;layout=compact\" alt=\"Top Langs\"></a></p>\n<h2> <img src=\"http://cdn.onlinewebfonts.com/svg/img_256848.png\" width=\"15px\"> About me</h2>\n<p align=center><img align=\"center\" src=\"https://github-readme-streak-stats.herokuapp.com/?user=bgoonz&\" alt=\"bgoonz\" /></p>\n<h1  align=\"center\">💻 Check Out My Repos ⬇️ </h1>  \n  \n<!-- if you want it to default to open then use <details open>  instead-->\n<h3>Repo List: <em><strong>CLICK The Arrow Below To See Repo List</strong></em></h3>\n<details>\n<summary><span style=\"align-self: center; margin: auto; font-family: papyrus; font-size: 2em;\"> ===➤(_CLICK TO SEE MORE_)➤</span></summary>\n<table>\n<thead>\n<tr>\n<th><a href=\"https://github.com/bgoonz/a-whole-bunch-o-gatsby-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=a-whole-bunch-o-gatsby-templates\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/Comments\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Comments\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/EXPRESS-NOTES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=EXPRESS-NOTES\" alt=\"ReadMe Card\"></a></th>\n<th><a href=\"https://github.com/bgoonz/INTERVIEW-PREP-COMPLETE\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=INTERVIEW-PREP-COMPLETE\" alt=\"ReadMe Card\"></a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://github.com/bgoonz/alternate-blog-theme\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=alternate-blog-theme\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/commercejs-nextjs-demo-store\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=commercejs-nextjs-demo-store\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/fast-fourier-transform-\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=fast-fourier-transform-\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/JAMSTACK-TEMPLATES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=JAMSTACK-TEMPLATES\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/anki-cards\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=anki-cards\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Common-npm-Readme-Compilation\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Common-npm-Readme-Compilation\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/form-builder-vanilla-js\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=form-builder-vanilla-js\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Javascript-Best-Practices_--Tools\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Javascript-Best-Practices_--Tools\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/ask-me-anything\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=ask-me-anything\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Connect-Four-Final-Version\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Connect-Four-Final-Version\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Front-End-Frameworks-Practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Front-End-Frameworks-Practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/jsanimate\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=jsanimate\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/atlassian-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=atlassian-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/convert-folder-contents-2-website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=convert-folder-contents-2-website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/full-stack-react-redux\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=full-stack-react-redux\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Jupyter-Notebooks\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Jupyter-Notebooks\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Authentication-Notes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Authentication-Notes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Copy-2-Clipboard-jQuery\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Copy-2-Clipboard-jQuery\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Full-Text-Search\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Full-Text-Search\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Lambda\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Lambda\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-commands-walkthrough\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-commands-walkthrough\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Data-Structures-Algos-Codebase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Data-Structures-Algos-Codebase\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Games\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Games\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Lambda-Resource-Static-Assets\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Lambda-Resource-Static-Assets\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-config-backup\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-config-backup\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DATA_STRUC_PYTHON_NOTES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DATA_STRUC_PYTHON_NOTES\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gatsby-netlify-cms-norwex\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gatsby-netlify-cms-norwex\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/learning-nextjs\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=learning-nextjs\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bash-shell-utility-functions\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bash-shell-utility-functions\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/design-home-page-with-routes-bq5v7k\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=design-home-page-with-routes-bq5v7k\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gatsby-react-portfolio\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gatsby-react-portfolio\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Learning-Redux\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Learning-Redux\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bass-station\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bass-station\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/docs-collection\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=docs-collection\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GIT-CDN-FILES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GIT-CDN-FILES\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Links-Shortcut-Site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Links-Shortcut-Site\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bgoonz\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bgoonz\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Documentation-site-react\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Documentation-site-react\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GIT-HTML-PREVIEW-TOOL\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GIT-HTML-PREVIEW-TOOL\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/live-examples\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=live-examples\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZBLOG2.0STABLE\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=BGOONZBLOG2.0STABLE\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DS-ALGO-OFFICIAL\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/gitbook\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=gitbook\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/live-form\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=live-form\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=BGOONZ_BLOG_2.0\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/DS-AND-ALGO-Notes-P2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DS-AND-ALGO-Notes-P2\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/github-readme-stats\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=github-readme-stats\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/loadash-es6-refactor\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=loadash-es6-refactor\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Binary-Search\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Binary-Search\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/ecommerce-interactive\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=ecommerce-interactive\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/github-reference-repo\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=github-reference-repo\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/markdown-css\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=markdown-css\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-2.o-versions\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-2.o-versions\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/embedable-repl-and-integrated-code-space-playground\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=embedable-repl-and-integrated-code-space-playground\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/GoalsTracker\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=GoalsTracker\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Markdown-Templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Markdown-Templates\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/excel2html-table\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=excel2html-table\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/graphql-experimentation\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=graphql-experimentation\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/meditation-app\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=meditation-app\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/blog-w-comments\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=blog-w-comments\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Exploring-Promises\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Exploring-Promises\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/https___mihirbeg.com_\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=https___mihirbeg.com_\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/MihirBegMusicLab\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=MihirBegMusicLab\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/Blog2.0-August-Super-Stable\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Blog2.0-August-Super-Stable\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/express-API-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=express-API-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/iframe-showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=iframe-showcase\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/MihirBegMusicV3\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=MihirBegMusicV3\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/bootstrap-sidebar-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=bootstrap-sidebar-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Express-basic-server-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Express-basic-server-template\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Image-Archive-Traning-Data\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Image-Archive-Traning-Data\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Mihir_Beg_Final\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Mihir_Beg_Final\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://github.com/bgoonz/callbacks\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=callbacks\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/express-knex-postgres-boilerplate\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=express-knex-postgres-boilerplate\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Independent-Blog-Entries\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Independent-Blog-Entries\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Project-Showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Project-Showcase\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Shell-Script-Practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Shell-Script-Practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/promises-with-async-and-await\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=promises-with-async-and-await\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-notes-v5\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-notes-v5\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/mini-project-showcase\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=mini-project-showcase\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/site-analysis\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=site-analysis\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/psql-practice\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=psql-practice\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-registration-login-example\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-registration-login-example\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/Music-Theory-n-Web-Synth-Keyboard\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Music-Theory-n-Web-Synth-Keyboard\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sorting-algorithms\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sorting-algorithms\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-playground-embed\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-playground-embed\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/React_Notes_V3\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=React_Notes_V3\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/my-gists\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=my-gists\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sorting-algos\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sorting-algos\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-practice-notes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-practice-notes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Recursion-Practice-Website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Recursion-Practice-Website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/My-Medium-Blog\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=My-Medium-Blog\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/sqlite3-nodejs-demo\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=sqlite3-nodejs-demo\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/python-scripts\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=python-scripts\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Regex-and-Express-JS\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Regex-and-Express-JS\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/nextjs-netlify-blog-template\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=nextjs-netlify-blog-template\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/stalk-photos-web-assets\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=stalk-photos-web-assets\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/PYTHON_PRAC\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=PYTHON_PRAC\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/repo-utils\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=repo-utils\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/norwex-coff-ecom\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=norwex-coff-ecom\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Standalone-Metranome\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Standalone-Metranome\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/random-list-of-embedable-content\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=random-list-of-embedable-content\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/resume-cv-portfolio-samples\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=resume-cv-portfolio-samples\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/old-c-and-cpp-repos-from-undergrad\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=old-c-and-cpp-repos-from-undergrad\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Star-wars-API-Promise-take2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Star-wars-API-Promise-take2\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/random-static-html-page-deploy\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=random-static-html-page-deploy\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Revamped-Automatic-Guitar-Effect-Triggering\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/old-code-from-undergrad\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=old-code-from-undergrad\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/Static-Study-Site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Static-Study-Site\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/React-movie-app\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=React-movie-app\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/supertemp\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=supertemp\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://github.com/bgoonz/picture-man-bob-v2\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=picture-man-bob-v2\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/styling-templates\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=styling-templates\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/react-redux-medium-clone\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=react-redux-medium-clone\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Ternary-converter\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Ternary-converter\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/scope-closure-context\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=scope-closure-context\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/TetrisJS\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TetrisJS\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/The-Algorithms\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=The-Algorithms\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Triggered-Guitar-Effects-Platform\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Triggered-Guitar-Effects-Platform\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/UsefulResourceRepo2.0\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=UsefulResourceRepo2.0\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/TexTools\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TexTools\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/TRASH\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=TRASH\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/Useful-Snippets-js\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Useful-Snippets-js\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/vscode-customized-config\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=vscode-customized-config\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/vscode-Extension-readmes\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=vscode-Extension-readmes\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-interview-prep-quiz-website\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-interview-prep-quiz-website\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-setup-checker\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-setup-checker\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-utils-package\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-utils-package\" alt=\"ReadMe Card\"></a></td>\n</tr>\n<tr>\n<td><a href=\"https://hub.com/bgoonz/web-crawler-node\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-crawler-node\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/web-dev-notes-resource-site\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=web-dev-notes-resource-site\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/WEB-DEV-TOOLS-HUB\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=WEB-DEV-TOOLS-HUB\" alt=\"ReadMe Card\"></a></td>\n<td><a href=\"https://hub.com/bgoonz/WebAudioDaw\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=WebAudioDaw\" alt=\"ReadMe Card\"></a></td>\n</tr>\n</tbody>\n</table>\n</details>  \n  \n<br>\n<br>\n  \n[![Bryan's github activity graph](https://activity-graph.herokuapp.com/graph?username=bgoonz&bg_color=000000&color=700069&line=ff0000&point=0cad00&area=true&hide_border=true)](https://github.com/bgoonz/github-readme-activity-graph)\n<h4 align=\"center\">A passionate Web Developer, Electrical Engineer, Musician & Producer</h4>\n<img align=\"center\" src=\"https://readme-jokes.vercel.app/api\" stye=\"width:770; height:420;\">\n<h3>🛠</h3>\n<!-- -->\n<center>\n<p><img src=\"https://github.com/bgoonz/bgoonz/blob/master/chrome_zX9bqxsy9y.png?raw=true\" alt=\"Graduation\"></p>\n</center>\n<div align=\"center\">\n<h3 align=\"center\">Languages and Tools:</h3>\n<p align=\"left\"> <a href=\"https://www.arduino.cc/\" target=\"_blank\"> <img src=\"https://cdn.worldvectorlogo.com/logos/arduino-1.svg\" alt=\"arduino\" width=\"40\" height=\"40\"/> </a> <a href=\"https://aws.amazon.com\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/amazonwebservices/amazonwebservices-original-wordmark.svg\" alt=\"aws\" width=\"40\" height=\"40\"/> </a> <a href=\"https://azure.microsoft.com/en-in/\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/microsoft_azure/microsoft_azure-icon.svg\" alt=\"azure\" width=\"40\" height=\"40\"/> </a> <a href=\"https://babeljs.io/\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/babeljs/babeljs-icon.svg\" alt=\"babel\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.gnu.org/software/bash/\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/gnu_bash/gnu_bash-icon.svg\" alt=\"bash\" width=\"40\" height=\"40\"/> </a> <a href=\"https://getbootstrap.com\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/bootstrap/bootstrap-plain-wordmark.svg\" alt=\"bootstrap\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.w3schools.com/cpp/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/cplusplus/cplusplus-original.svg\" alt=\"cplusplus\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.w3schools.com/css/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/css3/css3-original-wordmark.svg\" alt=\"css3\" width=\"40\" height=\"40\"/> </a> <a href=\"https://d3js.org/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/d3js/d3js-original.svg\" alt=\"d3js\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.docker.com/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/docker/docker-original-wordmark.svg\" alt=\"docker\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.elastic.co\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/elastic/elastic-icon.svg\" alt=\"elasticsearch\" width=\"40\" height=\"40\"/> </a> <a href=\"https://emberjs.com/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/ember/ember-original-wordmark.svg\" alt=\"ember\" width=\"40\" height=\"40\"/> </a> <a href=\"https://expressjs.com\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/express/express-original-wordmark.svg\" alt=\"express\" width=\"40\" height=\"40\"/> </a> <a href=\"https://firebase.google.com/\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/firebase/firebase-icon.svg\" alt=\"firebase\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.gatsbyjs.com/\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/gatsbyjs/gatsbyjs-icon.svg\" alt=\"gatsby\" width=\"40\" height=\"40\"/> </a> <a href=\"https://cloud.google.com\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/google_cloud/google_cloud-icon.svg\" alt=\"gcp\" width=\"40\" height=\"40\"/> </a> <a href=\"https://git-scm.com/\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/git-scm/git-scm-icon.svg\" alt=\"git\" width=\"40\" height=\"40\"/> </a> <a href=\"https://heroku.com\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/heroku/heroku-icon.svg\" alt=\"heroku\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.w3.org/html/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/html5/html5-original-wordmark.svg\" alt=\"html5\" width=\"40\" height=\"40\"/> </a> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/javascript/javascript-original.svg\" alt=\"javascript\" width=\"40\" height=\"40\"/> </a> <a href=\"https://jekyllrb.com/\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/jekyllrb/jekyllrb-icon.svg\" alt=\"jekyll\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.linux.org/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/linux/linux-original.svg\" alt=\"linux\" width=\"40\" height=\"40\"/> </a> <a href=\"https://mochajs.org\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/mochajs/mochajs-icon.svg\" alt=\"mocha\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.mongodb.com/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/mongodb/mongodb-original-wordmark.svg\" alt=\"mongodb\" width=\"40\" height=\"40\"/> </a> <a href=\"https://nextjs.org/\" target=\"_blank\"> <img src=\"https://cdn.worldvectorlogo.com/logos/nextjs-3.svg\" alt=\"nextjs\" width=\"40\" height=\"40\"/> </a> <a href=\"https://nodejs.org\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/nodejs/nodejs-original-wordmark.svg\" alt=\"nodejs\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.photoshop.com/en\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/photoshop/photoshop-line.svg\" alt=\"photoshop\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.postgresql.org\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/postgresql/postgresql-original-wordmark.svg\" alt=\"postgresql\" width=\"40\" height=\"40\"/> </a> <a href=\"https://postman.com\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/getpostman/getpostman-icon.svg\" alt=\"postman\" width=\"40\" height=\"40\"/> </a> <a href=\"https://pugjs.org\" target=\"_blank\"> <img src=\"https://cdn.worldvectorlogo.com/logos/pug.svg\" alt=\"pug\" width=\"40\" height=\"40\"/> </a> <a href=\"https://github.com/puppeteer/puppeteer\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/pptrdev/pptrdev-official.svg\" alt=\"puppeteer\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.python.org\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/python/python-original.svg\" alt=\"python\" width=\"40\" height=\"40\"/> </a> <a href=\"https://reactjs.org/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/react/react-original-wordmark.svg\" alt=\"react\" width=\"40\" height=\"40\"/> </a> <a href=\"https://reactnative.dev/\" target=\"_blank\"> <img src=\"https://reactnative.dev/img/header_logo.svg\" alt=\"reactnative\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.typescriptlang.org/\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/master/icons/typescript/typescript-original.svg\" alt=\"typescript\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.vagrantup.com/\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/vagrantup/vagrantup-icon.svg\" alt=\"vagrant\" width=\"40\" height=\"40\"/> </a> <a href=\"https://webpack.js.org\" target=\"_blank\"> <img src=\"https://raw.githubusercontent.com/devicons/devicon/d00d0969292a6569d45b06d3f350f463a0107b0d/icons/webpack/webpack-original-wordmark.svg\" alt=\"webpack\" width=\"40\" height=\"40\"/> </a> <a href=\"https://www.adobe.com/products/xd.html\" target=\"_blank\"> <img src=\"https://cdn.worldvectorlogo.com/logos/adobe-xd.svg\" alt=\"xd\" width=\"40\" height=\"40\"/> </a> <a href=\"https://zapier.com\" target=\"_blank\"> <img src=\"https://www.vectorlogo.zone/logos/zapier/zapier-icon.svg\" alt=\"zapier\" width=\"40\" height=\"40\"/> </a> </p>  \n  \n  </div>\n<div align=\"center\">\n  \n  | [GitHub](https://github.com/bgoonz)       | [Gitlab](https://gitlab.com/bryan.guner.dev)      | [Bitbucket](https://bitbucket.org/bgoonz/)      | [Medium](https://bryanguner.medium.com/)      | [code pen](https://codepen.io/bgoonz)       |\n|---    |---    |---    |---    |---    |\n| [Replit](https://repl.it/@bgoonz/)      |  [Quora](https://www.quora.com/q/webdevresourcehub?invite_code=qwZOqbpAhgQ6hjjGl8NN)     | [Redit](https://www.reddit.com/user/bgoonz1)       | [webcomponents.dev](https://webcomponents.dev/user/bgoonz)      |  [dev.to](https://dev.to/bgoonz)     |\n| [runkit](https://runkit.com/bgoonz)        | [Observable Notebooks](https://observablehq.com/@bgoonz?tab=profile)      | [npm](https://www.npmjs.com/~bgoonz11)      | [stack-exchange](https://meta.stackexchange.com/users/936785/bryan-guner)      | [Observable Notebooks](https://observablehq.com/@bgoonz?tab=profile)      |\n| [Upwork](https://www.upwork.com/freelancers/~01bb1a3627e1e9c630?viewMode=1&s=1110580755057594368)      | [Notion](https://www.notion.so/Overview-Of-Css-5d88b0bc9a73422a9be1481d599a56ba)      |  [AngelList](https://angel.co/u/bryan-guner)      | [StackShare](https://stackshare.io/bryanguner)      | [Plunk](http://plnkr.co/account/plunks)       | [Tealfeed](https://tealfeed.com/bryan_759844)\n| [giphy](https://giphy.com/channel/bryanguner)      | [kofi](https://ko-fi.com/bgoonz)        | [Codewars](https://www.codewars.com/users/bgoonz)       | [Dribble](https://dribbble.com/bgoonz4242?onboarding=true)       | [Glitch](https://glitch.com/@bgoonz)       | [YHYPE](https://yhype.me/github/accounts/bgoonz)\n| [contentful](https://app.contentful.com/spaces/lelpu0ihaz11/assets?id=MocOPmmNliLn6PPv)        | [Netlify](https://app.netlify.com/user/settings#profile)      | [Stackblitz](https://stackblitz.com/@bgoonz)      | [Vercel](https://vercel.com/bgoonz)      | [Youtube](https://www.youtube.com/channel/UC9-rYyUMsnEBK8G8fCyrXXA/featured)      | [Free Code Camp](https://www.freecodecamp.org/bgoonz)\n| [wordpress](https://web-dev-hub.com/)       | [Edabit](https://edabit.com/user/dsRcx6yCwAgYwZbRB)      | [Vinmeo](https://vimeo.com/user128661018)      |  [js fiddle](https://jsfiddle.net/user/bgoonz/)     | [hashnode](https://hashnode.com/@bgoonz/joinme)      |\n| [Google Developer Profile](https://developers.google.com/profile/u/100803355943326309646?utm_source=developers.google.com)       | [Gittee](https://gitee.com/bgoonz)      |  [Wakatime](https://wakatime.com/@bgoonz42)      |  [Hubpages](https://hubpages.com/@bryanguner)     | [Gitbook](https://bryan-guner.gitbook.io/web-dev-hub-docs/)      |\n<p><a href=\"https://github.com/my-lambda-projects/LAMBDA_LABS_FAMILY_PROMISE\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=my-lambda-projects&#x26;repo=LAMBDA_LABS_FAMILY_PROMISE\" alt=\"ReadMe Card\"></a>\n<a href=\"https://github.com/bgoonz/Leetcode-JS-PY-MD\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Leetcode-JS-PY-MD\" alt=\"ReadMe Card\"></a>\n<a href=\"https://github.com/bgoonz/Lambda\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=Lambda\" alt=\"ReadMe Card\"></a>\n<a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DS-ALGO-OFFICIAL\" alt=\"ReadMe Card\"></a>\n<a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=BGOONZ_BLOG_2.0\" alt=\"ReadMe Card\"></a><a href=\"https://github.com/bgoonz/DATA_STRUC_PYTHON_NOTES\"><img src=\"https://github-readme-stats.vercel.app/api/pin/?username=bgoonz&#x26;repo=DATA_STRUC_PYTHON_NOTES\" alt=\"ReadMe Card\"></a></p>\n<p><a href=\"https://github.com/bgoonz/github-profile-trophy\"><img src=\"https://github-profile-trophy.vercel.app/?username=bgoonz&#x26;row=1\" alt=\"trophy\"></a></p>\n<p><img align=\"center\" src=\"https://github-readme-streak-stats.herokuapp.com/?user=bgoonz&\" alt=\"bgoonz\" /><img align=\"center\" src=\"https://github-readme-stats.vercel.app/api?username=bgoonz&show_icons=true&locale=en\" alt=\"bgoonz\" /></p>\n<p><a href=\"https://github.com/bgoonz/github-readme-stats\"><img src=\"https://github-readme-stats.vercel.app/api/top-langs/?username=bgoonz&#x26;layout=compact&#x26;hide=html,mathematica&#x26;langs_count=16\" alt=\"Top Langs\"></a></p>\n</div>\n</div>\n<details>\n<summary>About Me</summary>\n  \n![statistics](https://github.com/bgoonz/bgoonz/blob/master/summary_50.png?raw=true)\n<ul>\n<li>🔭 Contract Web Development <strong>Relational Concepts</strong></li>\n<li>🌱 I'm currently learning <strong>React/Redux, Python, Java, Express, jQuery</strong></li>\n<li>👯 I'm looking to collaborate on <a href=\"https://goofy-euclid-1cd736.netlify.app/core-site/index.html\">Any web audio or open source educational tools.</a></li>\n<li>🤝 I'm looking for help with <a href=\"https://github.com/bgoonz/React-Practice\">Learning React</a></li>\n<li>👨‍💻 All of my projects are available at <a href=\"https://bgoonz.github.io/\">https://bgoonz.github.io/</a></li>\n<li>📝 I regularly write articles on <a href=\"https://bryanguner.medium.com/\">medium</a> &#x26;&#x26; <a href=\"https://web-dev-resource-hub.netlify.app/\">Web-Dev-Resource-Hub</a></li>\n<li>💬 Ask me about <strong>Anything:</strong></li>\n<li>📫 How to reach me <strong>bryan.guner@gmail.com</strong></li>\n<li>⚡ Fun fact <strong>I played Bamboozle Music Festival at the Meadowlands Stadium Complex when I was 14.</strong></li>\n</ul>\n<h3>i really like music :headphones</h3>\n<h4>What's the most useful business-related book you've ever read?</h4>\n<blockquote>\n<p>A Random Walk Down Wall Street</p>\n</blockquote>\n<h4>What's your favorite non-business book?</h4>\n<blockquote>\n<p>Hitchhiker's Guide To The Galaxy</p>\n</blockquote>\n<h4>If money were not an issue, what would you be doing right now?</h4>\n<blockquote>\n<p>Designing recording software/hardware and using it</p>\n</blockquote>\n<h4>What words of advice would you give your younger self?</h4>\n<blockquote>\n<p>Try harder and listen to your parents more (the latter bit of advice would be almost certain to fall on deaf ears lol)</p>\n</blockquote>\n<h4>What's the most creative thing you've ever done?</h4>\n<blockquote>\n<p>I built a platform that listens to a guitarist's performance and automatically triggers guitar effects at the appropriate time in the song.</p>\n</blockquote>\n<h4>Which founders or startups do you most admire?</h4>\n<blockquote>\n<p>Is it to basic to say Tesla... I know they're prevalent now but I've been an avid fan since as early as 2012.</p>\n</blockquote>\n<h4>What's your super power?</h4>\n<blockquote>\n<p>Having really good ideas and forgetting them moments later.</p>\n</blockquote>\n<h4>What's the best way for people to get in touch with you?</h4>\n<blockquote>\n<p>A text</p>\n</blockquote>\n<h4>What aspects of your work are you most passionate about?</h4>\n<p>Creating things that change my every day life.</p>\n<h4>What was the most impactful class you took in school?</h4>\n<blockquote>\n<p>Modern Physics... almost changed my major after that class... but at the end of the day engineering was a much more fiscally secure avenue.</p>\n</blockquote>\n<h4>What's something you wish you had done years earlier?</h4>\n<blockquote>\n<p>Learned to code ... and sing</p>\n</blockquote>\n<h4>What words of wisdom do you live by?</h4>\n<blockquote>\n<p>*Disclaimer: The following wisdom is very cliche ... but... \"Be the change that you wish to see in the world.\"</p>\n</blockquote>\n<blockquote>\n<p>Mahatma Gandhi</p>\n</blockquote>\n<p>| | ## Portfolio:</p>\n<h1><a href=\"https://portfolio42.netlify.app/\">netlify</a></h1>\n</div>\n</details>\n<!-- start work experience section -->\n<details>\n<summary> Resume </summary>\n<div align=\"center\">\n<h1><strong>Bryan</strong> <strong>Guner</strong></h1>\n<h2><em>551-254-5505 | <a href=\"mailto:bryan.guner@gmail.com\">bryan.guner@gmail.com</a></em></h2>\n</div>\n<br>\n<hr>\n<h2>⦿===➤Skills</h2>\n<table>\n<thead>\n<tr>\n<th>Languages:</th>\n<th>JavaScript ES-6, NodeJS, HTML5, CSS3, SCSS, Bash Shell, SQL, MATLAB, Python, C++, Mathematica, JSON</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Frameworks / Libraries:</td>\n<td>React, Redux, ExpressJS, Gatsby, NextJS, Ant-Design, Loadash, Sequelize, GraphQL, AJAX, Jest, Mocha, jQuery, Electron</td>\n</tr>\n<tr>\n<td>Databases:</td>\n<td>PostgreSQL, MongoDB, SQlite3</td>\n</tr>\n<tr>\n<td>Tools:</td>\n<td>Figma, Adobe XD, GitHub, GitLab, Excel, VSCode, Sublime Text, Atom, Google Analytics, Bootstrap, Tailwind, FontAwesome</td>\n</tr>\n<tr>\n<td>Tools (continued):</td>\n<td>Docker, Firebase, Postman, Wordpress, Chrome Dev Tools, Jira, Trello, Confluence, Firebase, AWS S3, Okta, Algolia, Loadash</td>\n</tr>\n<tr>\n<td>Hosting:</td>\n<td>Heroku, Netlify, Vercel, Wordpress, Cloudfare, AWS, Firebase, Digital Ocean</td>\n</tr>\n<tr>\n<td>Operating Systems:</td>\n<td>Linux, Windows (WSL), IOS</td>\n</tr>\n</tbody>\n</table>\n<hr>\n<h2>⦿===➤Projects</h2>\n<p><strong>Gatsby</strong> <strong>GraphQL-Blog</strong> <strong><a href=\"https://bgoonzblog20master.gatsbyjs.io/\">Live Site |</a><a href=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\">GitHub</a></strong></p>\n<p><strong>Stack:</strong> <em>JavaScript, React / Gatsby | GraphQL | SCSS | Lodash | Jamstack | Facebook Comments API | jQuery | Firebase</em></p>\n<p><em><strong>A</strong></em><a href=\"https://bgoonzblog20master.gatsbyjs.io/\"><em><strong>web development blog</strong></em></a><em><strong>featuring convenient web development tools and interactive content</strong></em></p>\n<ul>\n<li>Implemented 4 Gatsby page models and GraphQL schema to fetch markdown content and feed it into react components.</li>\n<li>Designed and integrated a set of convenient web-hosted <a href=\"https://bgoonzblog20master.gatsbyjs.io/docs/tools/\">developer tools</a> and GUI interfaces.</li>\n<li>Added interactive content including comments, <a href=\"https://bgoonzblog20master.gatsbyjs.io/docs/interact/video-chat/\">video conferencing</a>, <a href=\"https://bgoonzblog20master.gatsbyjs.io/docs/interact/other-sites/\">data-structure visualization</a>, <a href=\"https://bgoonzblog20master.gatsbyjs.io/docs/interact/\">games</a> and full text search.</li>\n</ul>\n<hr>\n<p><strong>Autonomously Triggered Guitar Effects Platform**</strong> <a href=\"https://bgoonz.github.io/Revamped-Automatic-Guitar-Effect-Triggering/\">Live Site</a>| <a href=\"https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering/tree/master/Triggered-Guitar-Effects-Platform\">GitHub</a>**</p>\n<p><strong>Stack:</strong> <em>C++ | Python | MATLAB | PureData</em></p>\n<p><a href=\"https://bgoonz.github.io/Revamped-Automatic-Guitar-Effect-Triggering/SR%20Project%20II%20Presentation.pdf\"><em><strong>Platform</strong></em></a><em><strong>designed to analyze a time sequence of notes and autonomously trigger guitar effects at</strong></em><a href=\"https://youtu.be/pRKjaprdWx4\"><em><strong>a predetermined point in the song</strong></em></a></p>\n<ul>\n<li>Used pure data to filter a guitar signal before executing frequency domain analysis and implementing <a href=\"https://youtu.be/krRVGoK9NcA\">custom built guitar effects.</a></li>\n<li>Implemented the Dynamic Time Warping algorithm in C++ and Python to generate a time agnostic measure of similarity between performances.</li>\n<li>Autonomously activated or adjusted guitar effects at multiple pre-designated sections of performance.</li>\n</ul>\n<hr>\n<p><strong>Data Structures</strong> <a href=\"https://ds-algo-official.netlify.app/\"><strong>Interactive Teaching Tool</strong></a><a href=\"https://ds-algo-official.netlify.app/\"><strong>Live Site</strong></a> <strong>|**</strong> <a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">GitHub</a>**</p>\n<p><strong>Stack:</strong> <em>jQuery | ExpressJS | Google Analytics |Algolia Full Text Search | Amazon S3</em></p>\n<p><em><strong>A</strong></em><a href=\"https://youtu.be/onquAh1Bl0g\"><em><strong>website</strong></em></a><em><strong>for visualizing and practicing data structures and algorithms in JavaScript &#x26; Python</strong></em></p>\n<ul>\n<li>Implemented an repl.it backend to enable commenting using express and the fs <strong>module</strong> to write user comments to a storage.json file.</li>\n<li>Developed proprietary npm package to recursively walk the project directory structure and generate a <a href=\"https://ds-algo-official.netlify.app/sitemap.html\">site navigation page</a>.</li>\n<li>Created multiple embedded data structure visualizations that interact with user input.</li>\n<li>Automated the generation and submission of a <a href=\"https://ds-algo-official.netlify.app/sitemap.xml\">sitemap</a>to (Google, Bing, and Yandex) on every build.</li>\n</ul>\n<hr>\n<br>\n<hr>\n<h2>⦿===➤ Experience</h2>\n<p><strong>Product Development Engineer |</strong> <a href=\"https://www.cembre.com/\"><em><strong>Cembre</strong></em></a><em><strong>, Edison, NJ</strong>\\</em>_|_<strong>Oct 2019 - Mar 2020</strong></p>\n<ul>\n<li>Converted client's product needs into <a href=\"https://www.cembre.com/family/details/5202\">technical specs</a> to be sent to the development team in Italy.</li>\n<li>Reorganized internal file server structure and conducted system integration and product demonstrations.</li>\n<li>Presided over internal and end user software trainings in addition to producing customer facing documentation.</li>\n<li>Conducted <a href=\"https://drive.google.com/drive/folders/1USAQtiQ3jLm3fiRCxIm4TEkWGlq4fO6j?usp=sharing\">electrical conductivity &#x26; tensile testing of electrical components</a> and presided over troubleshooting railroad hardware and software in North America.</li>\n</ul>\n<p><a href=\"https://familypromise.org/\"><strong>Family Promise</strong></a> <strong>Service Tracker</strong></p>\n<p><strong>Full Stack Web Development Intern | Remote | Sept 2021 - Present</strong> <strong><a href=\"https://a.familypromiseservicetracker.dev/\">Live Site |</a><a href=\"https://github.com/Lambda-School-Labs/family-promise-service-tracker-fe-a\">GitHub</a></strong></p>\n<p><strong>Stack:</strong> <em>React | Redux | ExpressJS | Figma | Okta | AWS</em></p>\n<p><em><strong>An</strong></em><a href=\"https://bryan-guner.gitbook.io/lambda-labs/navigation/roadmap\"><em><strong>app</strong></em></a><em><strong>built to helps local communities provide services to address the root causes of family homelessness</strong></em></p>\n<ul>\n<li>Collaborated on state management using Redux to handle application state and middleware using redux-promise &#x26; redux-thunk.</li>\n<li>Built two graphic visuals of the user hierarchy and the scope of their permissions as well as maintained the team's <a href=\"https://bryan-guner.gitbook.io/my-docs/v/lambda-labs/\">docs</a>.</li>\n<li>Created Figma UI mockups for possible future developments, such as displaying metrics data and map pinpoint functionality.</li>\n</ul>\n<br>\n<hr>\n<h2>⦿===➤ Education</h2>\n<h4><a href=\"https://www.credly.com/badges/bd145ba3-0f09-42fc-8d1f-a3bc4e0a46b4/public_url\"><strong>Lambda School</strong></a> , <em><strong>Full Stack Web Development</strong></em></h4>\n<blockquote>\n<p><em><strong>May 2020 - Nov 2021</strong></em></p>\n</blockquote>\n<p>Six-month immersive software development course with a focus on <a href=\"https://gist.github.com/bgoonz/17494dab0042a6f70eda7929c08c878f\">full stack web development</a>. Over 2000 hours of work invested including class time, homework, and projects.</p>\n<p><strong>B.S.</strong> <a href=\"https://electrical-computerengineering.tcnj.edu/\"><strong>Electrical Engineering</strong></a> <strong>, TCNJ, Ewing NJ</strong> <strong>2014 – 2019</strong></p>\n<p><a href=\"https://github.com/bgoonz/random-static-html-page-deploy/blob/master/ElectricalEngineeringCurriculum.pdf\">2 <strong>Curriculum link</strong></a></p>\n<blockquote>\n<p><a href=\"https://bryan-guner.gitbook.io/my-docs/v/electrical-engineering/\">Knowledge of</a> circuit boards, processors, chips, electronic equipment, and computer hardware and software, including applications and programming.</p>\n</blockquote>\n<div align=\"center\">\n<p><em><strong>References &#x26; further work experience available upon request.</strong></em></p>\n</div>\n</details>\n<details>\n<summary> My Projects</summary>\n<table>\n  <thead>\n    <tr>\n      <th>Project Name</th>\n      <th>Skills used</th>\n      <th>Description</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td><a href='https://web-dev-resource-hub.netlify.app/'>Web-Dev-Resource-Hub (blog)</a></td>\n      <td>Html, Css, javascript, Python, jQuery,  React,  FireBase,  AWS S3,  Netlify,  Heroku,  NodeJS,  PostgreSQL,  C++,  Web Audio API</td>\n      <td>My blog site contains my resource sharing and blog site ... centered mostly on web development and just a bit of audio production / generally nerdy things I find interesting.</td>\n    </tr>\n       <tr>\n      <td><a href='https://project-showcase-bgoonz.netlify.app/'>Dynamic Guitar Effects Triggering Using A Modified Dynamic Time Warping Algorithm</a></td>\n      <td>C, C++, Python, Java, Pure Data, Matlab</td>\n      <td>Successfully completed and delivered a platform to digitize a guitar signal and perform filtering before executing frequency & time domain analysis to track a current performance against prerecorded performance.Implemented the Dynamic Time Warping algorithm in C++ and Python to autonomously activate or adjust guitar effect at multiple pre-designated section of performance.</td>\n    </tr>\n    <tr>\n      <td><a href=\"https://trusting-dijkstra-4d3b17.netlify.app/\">Data Structures & Algorithms Interactive Learning Site</a></td>\n      <td>HTML, CSS, Javascript,  Python,  Java,  jQuery,  Repl.it-Database API</td>\n      <td>A interactive and comprehensive guide and learning tool for DataStructures and Algorithms ... concentrated on JS but with some examples in Python,  C++ and Java as well</td>\n    </tr>\n    <tr>\n      <td><a href='https://mihirbegmusic.netlify.app/'>MihirBeg.com</a></td>\n      <td>Html, Css, Javascript,  Bootstrap,  FontAwesome,  jQuery</td>\n      <td>A responsive and mobile friendly content promotion site for an Audio Engineer to engage with fans and potential clients</td>\n    </tr>\n    <tr>\n      <td><a href='https://tetris42.netlify.app/'>Tetris-JS</a></td>\n      <td>Html, Css, Javascript</td>\n      <td>The classic game of tetris implemented in plain javascipt and styled with a retro-futureistic theme</td>\n    </tr>\n    <tr>\n      <td><a href=\"https://githtmlpreview.netlify.app/\">Git Html Preview Tool</a></td>\n      <td>Git,  Javascript,  CSS3,  HTML5,  Bootstrap,  BitBucket</td>\n      <td>Loads HTML using CORS proxy,  then process all links,  frames,  scripts and styles,  and load each of them using CORS proxy,  so they can be evaluated by the browser.</td>\n    </tr>\n    <tr>\n      <td><a href='https://project-showcase-bgoonz.netlify.app/'>Mini Project Showcase</a></td>\n      <td>HTML, HTML5, CSS, CSS3, Javascript, jQuery</td>\n      <td>add songs and play music, it also uses to store data in  INDEXEDB Database by which we can play songs, if we not clear the catch then song will remain stored in database.</td>\n    </tr>\n  </tbody>\n<p align=\"center\">\n<hr>\n<hr>\n<h2>➤ Weekly-Quick-Snips</h2>\n<h3>replaceAll</h3>\n<p>the method string.replaceAll(search, replaceWith) replaces all appearances of search string with replaceWith.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> str <span class=\"token operator\">=</span> <span class=\"token string\">'this is a JSsnippets example'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> updatedStr <span class=\"token operator\">=</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token string\">'example'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'snippet'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 'this is a  JSsnippets snippet'</span>\n\n\nThe tricky part is that replace method replaces only the very first match <span class=\"token keyword\">of</span> the substring we have passed<span class=\"token operator\">:</span>\n\n\n<span class=\"token keyword\">const</span> str <span class=\"token operator\">=</span> <span class=\"token string\">'this is a JSsnippets example and examples are great'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> updatedStr <span class=\"token operator\">=</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token string\">'example'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'snippet'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//'this is a JSsnippets snippet and examples are great'</span>\n\nIn order to go through <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> we need to use a global regexp instead<span class=\"token operator\">:</span>\n\n\n<span class=\"token keyword\">const</span> str <span class=\"token operator\">=</span> <span class=\"token string\">'this is a JSsnippets example and examples are great'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> updatedStr <span class=\"token operator\">=</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">example</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'snippet'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//'this is a JSsnippets snippet and snippets are greatr'</span>\n\nbut now we have <span class=\"token keyword\">new</span> <span class=\"token class-name\">friend</span> <span class=\"token keyword\">in</span> town<span class=\"token punctuation\">,</span> replaceAll\n\n<span class=\"token keyword\">const</span> str <span class=\"token operator\">=</span> <span class=\"token string\">'this is a JSsnippets example and examples are great'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> updatedStr <span class=\"token operator\">=</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replaceAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'example'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'snippet'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//'this is a JSsnippets snippet and snippets are greatr'</span></code></pre></div>\n<hr>\n<h3>Fibonacci in Python</h3>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">fib_iter</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> n <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span>\n    <span class=\"token keyword\">if</span> n <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">1</span>\n    p0 <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n    p1 <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>n<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        next_val <span class=\"token operator\">=</span> p0 <span class=\"token operator\">+</span> p1\n        p0 <span class=\"token operator\">=</span> p1\n        p1 <span class=\"token operator\">=</span> next_val\n    <span class=\"token keyword\">return</span> next_val\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f'</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\">: </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>fib_iter<span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span><span class=\"token string\">'</span></span><span class=\"token punctuation\">)</span></code></pre></div>\n<hr>\n<h4>Yesterday's Snippet of the day</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">quicksort</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># One of our base cases is an empty list or list with one element</span>\n    <span class=\"token keyword\">if</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span> <span class=\"token keyword\">or</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> l\n    <span class=\"token comment\"># If we have a left list, a pivot point and a right list...</span>\n    <span class=\"token comment\"># assigns the return values of the partition() function</span>\n    left<span class=\"token punctuation\">,</span> pivot<span class=\"token punctuation\">,</span> right <span class=\"token operator\">=</span> partition<span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span>\n    <span class=\"token comment\"># Our sorted list looks like left + pivot + right, but sorted.</span>\n    <span class=\"token comment\"># Pivot has to be in brackets to be a list, so python can concatenate all the elements to a single list</span>\n    <span class=\"token keyword\">return</span> quicksort<span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span>pivot<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> quicksort<span class=\"token punctuation\">(</span>right<span class=\"token punctuation\">)</span>\n\n\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>quicksort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>quicksort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>quicksort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>quicksort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>quicksort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>quicksort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">7</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>quicksort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span><span class=\"token number\">7</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>quicksort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<hr>\n<details>\n  \n  <summary>See Older Snippets!</summary>\n  \n#### This Week's snippets\n  \n  ---\n  \n   >will replace any spaces in file names with an underscore!\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"> <span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">$file</span>\"</span> <span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token builtin class-name\">echo</span> $file <span class=\"token operator\">|</span> <span class=\"token function\">tr</span> <span class=\"token string\">' '</span> <span class=\"token string\">'_'</span><span class=\"token variable\">`</span></span> <span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span>\n  <span class=\"token comment\">## TAKING IT A STEP FURTHER:</span>\n <span class=\"token comment\"># Let's do it recursivley:</span>\n  <span class=\"token keyword\">function</span> <span class=\"token function-name function\">RecurseDirs</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">{</span>\n    <span class=\"token assign-left variable\">oldIFS</span><span class=\"token operator\">=</span><span class=\"token environment constant\">$IFS</span>\n    <span class=\"token assign-left variable\"><span class=\"token environment constant\">IFS</span></span><span class=\"token operator\">=</span><span class=\"token string\">$'<span class=\"token entity\" title=\"\\n\">\\n</span>'</span>\n    <span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">f</span> <span class=\"token keyword\">in</span> <span class=\"token string\">\"<span class=\"token variable\">$@</span>\"</span>\n    <span class=\"token keyword\">do</span>\n  <span class=\"token comment\"># YOUR CODE HERE!</span>\n\n<span class=\"token punctuation\">[</span><span class=\"token operator\">!</span><span class=\"token punctuation\">[</span>-----------------------------------------------------<span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span>https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">\\</span>*<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">$file</span>\"</span> <span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token builtin class-name\">echo</span> $file <span class=\"token operator\">|</span> <span class=\"token function\">tr</span> <span class=\"token string\">' '</span> <span class=\"token string\">'_'</span><span class=\"token variable\">`</span></span> <span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span> <span class=\"token parameter variable\">-d</span> <span class=\"token string\">\"<span class=\"token variable\">${f}</span>\"</span> <span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">then</span>\n<span class=\"token builtin class-name\">cd</span> <span class=\"token string\">\"<span class=\"token variable\">${f}</span>\"</span>\n            RecurseDirs <span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token function\">ls</span> <span class=\"token parameter variable\">-1</span> <span class=\"token string\">\".\"</span><span class=\"token variable\">)</span></span>\n            <span class=\"token builtin class-name\">cd</span> <span class=\"token punctuation\">..</span>\n        <span class=\"token keyword\">fi</span>\n    <span class=\"token keyword\">done</span>\n    <span class=\"token assign-left variable\"><span class=\"token environment constant\">IFS</span></span><span class=\"token operator\">=</span><span class=\"token variable\">$oldIFS</span>\n<span class=\"token punctuation\">}</span>\nRecurseDirs <span class=\"token string\">\"./\"</span></code></pre></div>\n<hr>\n<h3>Copy to clipboard jQuerry</h3>\n<blockquote>\n<p>Language: Javascript/Jquery</p>\n</blockquote>\n<blockquote>\n<p>In combination with the script tag :  <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js\"></script> , this snippet will add a copy to clipboard button to all of your embedded <code> blocks.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token function\">$</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">ready</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token string\">'code, pre'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">append</span><span class=\"token punctuation\">(</span><span class=\"token string\">'&lt;span class=\"command-copy\" >&lt;i class=\"fa fa-clipboard\" aria-hidden=\"true\">&lt;/i>&lt;/span>'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token string\">'code span.command-copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">click</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> text <span class=\"token operator\">=</span> <span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">parent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">text</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//.text();</span>\n    <span class=\"token keyword\">var</span> copyHex <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    copyHex<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> text\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    copyHex<span class=\"token punctuation\">.</span><span class=\"token function\">select</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">execCommand</span><span class=\"token punctuation\">(</span><span class=\"token string\">'copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token string\">'pre span.command-copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">click</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> text <span class=\"token operator\">=</span> <span class=\"token function\">$</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">parent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">text</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> copyHex <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    copyHex<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> text\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    copyHex<span class=\"token punctuation\">.</span><span class=\"token function\">select</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">execCommand</span><span class=\"token punctuation\">(</span><span class=\"token string\">'copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>copyHex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code></pre></div>\n<hr>\n<h3>Append Files in PWD</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//APPEND-DIR.js</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"fs\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> cat <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"child_process\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">execSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"cat *\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"UTF-8\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"output.md\"</span><span class=\"token punctuation\">,</span> cat<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> err<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3>doesUserFrequentStarbucks.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> isAppleDevice <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">Mac|iPod|iPhone|iPad</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>navigator<span class=\"token punctuation\">.</span>platform<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>isAppleDevice<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Result: will return true if user is on an Apple device</span></code></pre></div>\n<hr>\n<h3>arr-intersection.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">/*\n function named intersection(firstArr) that takes in an array and\nreturns a function. \nWhen the function returned by intersection is invoked\npassing in an array (secondArr) it returns a new array containing the elements\ncommon to both firstArr and secondArr.\n*/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">firstArr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">secondArr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> common <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> firstArr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">let</span> el <span class=\"token operator\">=</span> firstArr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>secondArr<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        common<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> common<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">let</span> abc <span class=\"token operator\">=</span> <span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a function</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">abc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"d\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [ 'b', 'c' ]</span>\n\n<span class=\"token keyword\">let</span> fame <span class=\"token operator\">=</span> <span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"f\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"m\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"e\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a function</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fame</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"f\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"z\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [ 'f', 'a' ]</span></code></pre></div>\n<hr>\n<h3>arr-of-cum-partial-sums.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">/*\nFirst is recurSum(arr, start) which returns the sum of the elements of arr from the index start till the very end.\nSecond is partrecurSum() that recursively concatenates the required sum into an array and when we reach the end of the array, it returns the concatenated array.\n*/</span>\n<span class=\"token comment\">//arr.length -1 = 5</span>\n<span class=\"token comment\">//                   arr   [    1,    7,    12,   6,    5,    10   ]</span>\n<span class=\"token comment\">//                   ind   [    0     1     2     3     4      5   ]</span>\n<span class=\"token comment\">//                              ↟                              ↟</span>\n<span class=\"token comment\">//                            start                           end</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">recurSum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> sum <span class=\"token operator\">=</span> <span class=\"token number\">0</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>start <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">recurSum</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> start <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> sum <span class=\"token operator\">+</span> arr<span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> sum<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">rPartSumsArr</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> partSum <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>start <span class=\"token operator\">&lt;=</span> end<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">rPartSumsArr</span><span class=\"token punctuation\">(</span>\n      arr<span class=\"token punctuation\">,</span>\n      partSum<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token function\">recurSum</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n      <span class=\"token operator\">++</span>start<span class=\"token punctuation\">,</span>\n      end\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> partSum<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>\n  <span class=\"token string\">\"------------------------------------------------rPartSumArr------------------------------------------------\"</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"rPartSumsArr(arr)=[ 1, 1, 5, 2, 6, 10 ]: \"</span><span class=\"token punctuation\">,</span> <span class=\"token function\">rPartSumsArr</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"rPartSumsArr(arr1)=[ 1, 7, 12, 6, 5, 10 ]: \"</span><span class=\"token punctuation\">,</span> <span class=\"token function\">rPartSumsArr</span><span class=\"token punctuation\">(</span>arr1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>\n  <span class=\"token string\">\"------------------------------------------------rPartSumArr------------------------------------------------\"</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/*\n------------------------------------------------rPartSumArr------------------------------------------------\nrPartSumsArr(arr)=[ 1, 1, 5, 2, 6, 10 ]:  [ 10, 16, 18, 23, 24, 25 ]\nrPartSumsArr(arr1)=[ 1, 7, 12, 6, 5, 10 ]:  [ 10, 15, 21, 33, 40, 41 ]\n------------------------------------------------rPartSumArr------------------------------------------------\n*/</span></code></pre></div>\n<hr>\n<h3>camel2Kabab.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">function</span> <span class=\"token function\">camelToKebab</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> value<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">([a-z])([A-Z])</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"$1-$2\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h3>camelCase.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">function</span> <span class=\"token function\">camel</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">str</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(?:^\\w|[A-Z]|\\b\\w|\\s+)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">match<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">+</span>match <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// or if (/\\s+/.test(match)) for white spaces</span>\n    <span class=\"token keyword\">return</span> index <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> match<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> match<span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h3>concatLinkedLists.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">function</span> <span class=\"token function\">addTwoNumbers</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">l1<span class=\"token punctuation\">,</span> l2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ListNode</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> currentNode <span class=\"token operator\">=</span> result<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> carryOver <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>l1 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">||</span> l2 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> v1 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> v2 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l1 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> v1 <span class=\"token operator\">=</span> l1<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l2 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> v2 <span class=\"token operator\">=</span> l2<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> sum <span class=\"token operator\">=</span> v1 <span class=\"token operator\">+</span> v2 <span class=\"token operator\">+</span> carryOver<span class=\"token punctuation\">;</span>\n    carryOver <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>sum <span class=\"token operator\">/</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    sum <span class=\"token operator\">=</span> sum <span class=\"token operator\">%</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n    currentNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ListNode</span><span class=\"token punctuation\">(</span>sum<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l1 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> l1 <span class=\"token operator\">=</span> l1<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l2 <span class=\"token operator\">!=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> l2 <span class=\"token operator\">=</span> l2<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>carryOver <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    currentNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ListNode</span><span class=\"token punctuation\">(</span>carryOver<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h3>fast-is-alpha-numeric.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//Function to test if a character is alpha numeric that is faster than a regular</span>\n<span class=\"token comment\">//expression in JavaScript</span>\n\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isAlphaNumeric</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">char</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  char <span class=\"token operator\">=</span> char<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> id <span class=\"token operator\">=</span> char<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>id <span class=\"token operator\">></span> <span class=\"token number\">47</span> <span class=\"token operator\">&amp;&amp;</span> id <span class=\"token operator\">&lt;</span> <span class=\"token number\">58</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token comment\">// if not numeric(0-9)</span>\n    <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>id <span class=\"token operator\">></span> <span class=\"token number\">64</span> <span class=\"token operator\">&amp;&amp;</span> id <span class=\"token operator\">&lt;</span> <span class=\"token number\">91</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token comment\">// if not letter(A-Z)</span>\n    <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>id <span class=\"token operator\">></span> <span class=\"token number\">96</span> <span class=\"token operator\">&amp;&amp;</span> id <span class=\"token operator\">&lt;</span> <span class=\"token number\">123</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// if not letter(a-z)</span>\n  <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"A\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"z\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//false</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//false</span></code></pre></div>\n<hr>\n<h3>find-n-replace.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">function</span> <span class=\"token function\">replaceWords</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">str<span class=\"token punctuation\">,</span> before<span class=\"token punctuation\">,</span> after</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[A-Z]</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>before<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    after <span class=\"token operator\">=</span> after<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> after<span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    after <span class=\"token operator\">=</span> after<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> after<span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> str<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span>before<span class=\"token punctuation\">,</span> after<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">replaceWords</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Let us go to the store\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"store\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"mall\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//\"Let us go to the mall\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">replaceWords</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"He is Sleeping on the couch\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Sleeping\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"sitting\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//\"He is Sitting on the couch\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">replaceWords</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"His name is Tom\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Tom\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"john\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//\"His name is John\"</span></code></pre></div>\n<hr>\n<h3>flatten-arr.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">/*Simple Function to flatten an array into a single layer */</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">flatten</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n  array<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">accum<span class=\"token punctuation\">,</span> ele</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> accum<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>ele<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span>ele<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> ele<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3>isWeekDay.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">isWeekday</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">date</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> date<span class=\"token punctuation\">.</span><span class=\"token function\">getDay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">%</span> <span class=\"token number\">6</span> <span class=\"token operator\">!==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isWeekday</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token number\">2021</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Result: true (Monday)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">isWeekday</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token number\">2021</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Result: false (Sunday)</span></code></pre></div>\n<hr>\n<h3>longest-common-prefix.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">function</span> <span class=\"token function\">longestCommonPrefix</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">strs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> prefix <span class=\"token operator\">=</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> strs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> character <span class=\"token operator\">=</span> strs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> strs<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>strs<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> character<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    prefix <span class=\"token operator\">=</span> prefix <span class=\"token operator\">+</span> character<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> prefix<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</details>\n<hr>\n<h1>➤ Github Gists</h1>\n<h2><a href=\"https://bgoonzgist.netlify.app/\">Github Gists</a></h2>\n<p><a href=\"https://gist.github.com/bgoonz/659a9b81ac45453bedc0a1a36275b580\">list-of-my-websites</a></p>\n<p><a href=\"https://github.com/sindresorhus/awesome\"><img src=\"https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg\" alt=\"Awesome\"></a> <a href=\"https://github.com/chetanraj/awesome-github-badges\"><img src=\"https://img.shields.io/badge/Made%20With-Love-orange.svg\" alt=\"Made With Love\"></a></p>\n<p><a href=\"https://forthebadge.com\"><img src=\"https://forthebadge.com/images/badges/certified-snoop-lion.svg\" alt=\"forthebadge\"></a><a href=\"https://forthebadge.com\"><img src=\"https://forthebadge.com/images/badges/60-percent-of-the-time-works-every-time.svg\" alt=\"forthebadge\"></a></p>\n<p><a href=\"https://github.com/bgoonz/blog-w-comments\"><img src=\"https://img.shields.io/website-up-down-green-red/http/shields.io.svg\" alt=\"Website shields.io\"></a><a href=\"https://GitHub.com/bgoonz/ask-me-anything\"><img src=\"https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg\" alt=\"Ask Me Anything !\"></a><a href=\"https://gitter.im/bgoonz/community?utm_source=badge&#x26;utm_medium=badge&#x26;utm_campaign=pr-badge\"><img src=\"https://badges.gitter.im/bgoonz/community.svg\" alt=\"Gitter\"></a><a href=\"https://pypi.python.org/pypi/ansicolortags/\"><img src=\"https://img.shields.io/pypi/l/ansicolortags.svg\" alt=\"PyPI license\"></a></p>\n<p><a href=\"https://GitHub.com/bgoonz/bgoonz/graphs/commit-activity\"><img src=\"https://img.shields.io/badge/Maintained%3F-yes-green.svg\" alt=\"Maintenance\"></a><a href=\"https://github.com/ellerbrock/open-source-badges/\"><img src=\"https://badges.frapsoft.com/os/v1/open-source.png?v=103\" alt=\"Open Source Love\"></a> <a href=\"https://github.com/ellerbrock/open-source-badges/\"><img src=\"https://badges.frapsoft.com/bash/v1/bash.png?v=103\" alt=\"Bash Shell\"></a></p>\n<p><img src=\"https://img.shields.io/badge/-React-black?style=flat&#x26;logo=react\" alt=\"React\"> <img src=\"https://img.shields.io/badge/-Redux-lightblue?style=flat&#x26;logo=redux\" alt=\"Redux\">\n<img src=\"https://img.shields.io/badge/-HTML5-E34F26?style=flat&#x26;logo=html5&#x26;logoColor=white\" alt=\"HTML5\"> <img src=\"https://img.shields.io/badge/-CSS3-1572B6?style=flat&#x26;logo=css3\" alt=\"CSS3\"> <img src=\"https://img.shields.io/badge/-Sass-black?style=flat&#x26;logo=sass\" alt=\"Sass\"><img src=\"https://img.shields.io/badge/-Docker-black?style=flat&#x26;logo=docker\" alt=\"Docker\"> <img src=\"https://img.shields.io/badge/-MySQL-black?style=flat&#x26;logo=mysql\" alt=\"MySQL\"> <img src=\"https://img.shields.io/badge/-PostgreSQL-blue?style=flat&#x26;logo=postgresql\" alt=\"PostgresQL\"> <img src=\"https://img.shields.io/badge/-Git-black?style=flat&#x26;logo=git\" alt=\"Git\"> <img src=\"https://img.shields.io/badge/-Ruby-darkred?style=flat&#x26;logo=ruby\" alt=\"Ruby\"> <img src=\"https://img.shields.io/badge/-MaterialUI-0081CB?style=flat&#x26;logo=Material-UI&#x26;logoColor=white\" alt=\"Material-UI\"></p>\n<p><img src=\"https://img.shields.io/badge/-Express-blue?style=flat&#x26;logo=express\" alt=\"Express\"> <img src=\"https://img.shields.io/badge/-Nodejs-green?style=flat&#x26;logo=Node.js\" alt=\"Nodejs\"><img src=\"https://img.shields.io/badge/-Python-lightyellow?style=flat&#x26;logo=python&#x26;logoColor=blue\" alt=\"Python\"> <img src=\"https://img.shields.io/badge/-Bootstrap-7952B3?style=flat&#x26;logo=bootstrap&#x26;logoColor=white\" alt=\"Bootstrap\"> <img src=\"https://img.shields.io/badge/-JavaScript-black?style=flat&#x26;logo=javascript\" alt=\"JavaScript\"></p>\n</details>\n  \n![Python](https://img.shields.io/badge/-Python-05122A?style=flat&logo=python)&nbsp;![HTML](https://img.shields.io/badge/-HTML-05122A?style=flat&logo=HTML5)&nbsp;\n![CSS](https://img.shields.io/badge/-CSS-05122A?style=flat&logo=CSS3&logoColor=1572B6)&nbsp;\n![JavaScript](https://img.shields.io/badge/-JavaScript-05122A?style=flat&logo=javascript)&nbsp;\n![React](https://img.shields.io/badge/-React-05122A?style=flat&logo=react)&nbsp;\n![Node.js](https://img.shields.io/badge/-Node.js-05122A?style=flat&logo=node.js)&nbsp;\n![Visual Studio Code](https://img.shields.io/badge/-Visual%20Studio%20Code-05122A?style=flat&logo=visual-studio-code&logoColor=007ACC)&nbsp;\n![Docker](https://img.shields.io/badge/-Docker-05122A?style=flat&logo=Docker)&nbsp;\n![MongoDB](https://img.shields.io/badge/-MongoDB-05122A?style=flat&logo=mongodb)&nbsp;\n![PostgreSQL](https://img.shields.io/badge/-PostgreSQL-05122A?style=flat&logo=postgresql)&nbsp;\n![Git](https://img.shields.io/badge/-Git-05122A?style=flat&logo=git)&nbsp;\n![GitHub](https://img.shields.io/badge/-GitHub-05122A?style=flat&logo=github)&nbsp;\n![GitLab](https://img.shields.io/badge/-GitLab-05122A?style=flat&logo=gitlab)&nbsp;\n![Markdown](https://img.shields.io/badge/-Markdown-05122A?style=flat&logo=markdown)\n  \n# Useful Links\n<https://www.jsdelivr.com/github>\n<https://giters.com/bgoonz?page=6>\n<https://webdevhub.ghost.io/ghost/#/tags/new>\n<https://app.archbee.io/public/lI1AR-3-Ys9iITwuhct3i/treT9kilaJkzSjozhixGi>\n<https://shields.io/>\n  <https://frontendmasters.com/guides/front-end-handbook/2019/>"},{"url":"/docs/articles/node-api-express/","relativePath":"docs/articles/node-api-express.md","relativeDir":"docs/articles","base":"node-api-express.md","name":"node-api-express","frontmatter":{"title":"Node APIs With Express","sections":[],"seo":{"title":" Node APIs With Express","description":"Review-Of-Previous-Concepts","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h3>Overview</h3>\n<p><code class=\"language-text\">REST</code> is a generally agreed-upon set of principles and constraints. They are <strong>recommendations</strong>, not a standard.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// inside /api/apiRoutes.js &lt;- this can be place anywhere and called anything\nconst express = require('express');\n\n// if the other routers are not nested inside /api then the paths would change\nconst userRoutes = require('./users/userRoutes');\nconst productRoutes = require('./products/productRoutes');\nconst clientRoutes = require('./clients/clientRoutes');\n\nconst router = express.Router(); // notice the Uppercase R\n\n// this file will only be used when the route begins with \"/api\"\n// so we can remove that from the URLs, so \"/api/users\" becomes simply \"/users\"\nrouter.use('/users', userRoutes);\nrouter.use('/products', productRoutes);\nrouter.use('/clients', clientRoutes);\n\n// .. and any other endpoint related to the user's resource\n\n// after the route has been fully configured, we then export it so it can be required where needed\nmodule.exports = router; // standard convention dictates that this is the last line on the file</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### Objective 1 — explain the role of a foreign key\n<h3>Overview</h3>\n<p><strong>Foreign keys</strong> are a type of table field used for creating links between tables. Like <strong>primary keys</strong>, they are most often integers that identify (rather than store) data. However, whereas a primary key is used to id rows in a table, foreign keys are used to connect a record in one table to a record in a second table.</p>\n<h3>Follow Along</h3>\n<p>Consider the following <code class=\"language-text\">farms</code> and <code class=\"language-text\">ranchers</code> tables.</p>\n<p><a href=\"https://www.notion.so/b88ebcd8fa3a4fa3a36cf99c939f6067\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/a4ccaec69c484ce0bcd03d2e8a83e489\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>The <code class=\"language-text\">farm_id</code> in the <code class=\"language-text\">ranchers</code> table is an example of a <code class=\"language-text\">foreign key</code>. Each entry in the <code class=\"language-text\">farm_id</code> (foreign key) column corresponds to an <code class=\"language-text\">id</code> (primary key) in the <code class=\"language-text\">farms</code> table. This allows us to track which farm each rancher belongs to while keeping the tables normalized.</p>\n<p>If we could only see the <code class=\"language-text\">ranchers</code> table, we would know that John, Jane, and Jen all work together and that Jim and Jay also work together. However, to know where any of them work, we would need to look at the <code class=\"language-text\">farms</code> table.</p>\n<h3>Challenge</h3>\n<p>Open <a href=\"https://www.w3schools.com/sql/trysql.asp?filename=trysql_op_in\" class=\"markup--anchor markup--p-anchor\">SQLTryIT (Links to an external site.)</a>.</p>\n<p>How many records in the products table belong to the category \"confections\"?</p>\n<h3>Objective 2 — query data from multiple tables</h3>\n<p>Now that we understand the basics of querying data from a single table, let's move on to selecting data from multiple tables using JOIN operations.</p>\n<h3>Overview</h3>\n<p>We can use a <code class=\"language-text\">JOIN</code> to combine query data from multiple tables using a single <code class=\"language-text\">SELECT</code> statement.</p>\n<p>There are different types of joins; some are listed below:</p>\n<ul>\n<li><span id=\"9c7e\">inner joins.</span></li>\n<li><span id=\"7cd3\">outer joins.</span></li>\n<li><span id=\"96e6\">left joins.</span></li>\n<li><span id=\"0e55\">right joins.</span></li>\n<li><span id=\"d582\">cross joins.</span></li>\n<li><span id=\"6716\">non-equality joins.</span></li>\n<li><span id=\"b7f0\">self joins.</span></li>\n</ul>\n<p>Using <code class=\"language-text\">joins</code> requires that the two tables of interest contain at least one field with shared information. For example, if a <em>departments</em> table has an <em>id</em> field, and an employee table has a <em>department</em>id_ field, and the values that exist in the <em>id</em> column of the <em>departments</em> table live in the <em>department</em>id_ field of the employee table, we can use those fields to join both tables like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select * from employees\njoin departments on employees.department_id = departments.id</code></pre></div>\n<p>This query will return the data from both tables for every instance where the <code class=\"language-text\">ON</code> condition is true. If there are employees with no value for department<em>id or where the value stored in the field does not correspond to an existing id in the</em> departments <em>table, then that record will NOT be returned. In a similar fashion, any records from the</em> departments <em>table that don't have an employee associated with them will also be omitted from the results. Basically, if the</em> id* does not show as the value of department_id for an employee, it won't be able to join.</p>\n<p>We can shorten the condition by giving the table names an alias. This is a common practice. Below is the same example using aliases, picking which fields to return and sorting the results:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select d.id, d.name, e.id, e.first_name, e.last_name, e.salary\nfrom employees as e\njoin departments as d\n  on e.department_id = d.id\norder by d.name, e.last_name</code></pre></div>\n<p>Notice that we can take advantage of white space and indentation to make queries more readable.</p>\n<p>There are several ways of writing joins, but the one shown here should work on all database management systems and avoid some pitfalls, so we recommend it.</p>\n<p>The syntax for performing a similar join using Knex is as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db('employees as e')\n  .join('departments as d', 'e.department_id', 'd.id')\n  .select('d.id', 'd.name', 'e.first_name', 'e.last_name', 'e.salary')</code></pre></div>\n<h3>Follow Along</h3>\n<p>A good explanation of how the different types of joins can be seen <a href=\"https://www.w3resource.com/sql/joins/sql-joins.php\" class=\"markup--anchor markup--p-anchor\">in this article from w3resource.com (Links to an external site.)</a>.</p>\n<h3>Challenge</h3>\n<p>Use <a href=\"https://www.w3schools.com/Sql/tryit.asp?filename=trysql_select_top\" class=\"markup--anchor markup--p-anchor\">this online tool (Links to an external site.)</a> to write the following queries:</p>\n<ul>\n<li><span id=\"9ccf\">list the products, including their category name.</span></li>\n<li><span id=\"b07f\">list the products, including the supplier name.</span></li>\n<li><span id=\"7b08\">list the products, including both the category name and supplier name.</span></li>\n</ul>\n<h3>What is SQL Joins?</h3>\n<p>An SQL JOIN clause combines rows from two or more tables. It creates a set of rows in a temporary table.</p>\n<h3>How to Join two tables in SQL?</h3>\n<p>A JOIN works on two or more tables if they have at least one common field and have a relationship between them.</p>\n<p>JOIN keeps the base tables (structure and data) unchanged.</p>\n<h3>Join vs. Subquery</h3>\n<ul>\n<li><span id=\"eeea\">JOINs are faster than a subquery and it is very rare that the opposite.</span></li>\n<li><span id=\"3b2e\">In JOINs the RDBMS calculates an execution plan, that can predict, what data should be loaded and how much it will take to processed and as a result this process save some times, unlike the subquery there is no pre-process calculation and run all the queries and load all their data to do the processing.</span></li>\n<li><span id=\"84ce\">A JOIN is checked conditions first and then put it into table and displays; where as a subquery take separate temp table internally and checking condition.</span></li>\n<li><span id=\"3002\">When joins are using, there should be connection between two or more than two tables and each table has a relation with other while subquery means query inside another query, has no need to relation, it works on columns and conditions.</span></li>\n</ul>\n<h3>SQL JOINS: EQUI JOIN and NON EQUI JOIN</h3>\n<p>The are two types of SQL JOINS — EQUI JOIN and NON EQUI JOIN</p>\n<ol>\n<li><span id=\"31e6\">SQL EQUI JOIN :</span></li>\n</ol>\n<p>The SQL EQUI JOIN is a simple SQL join uses the equal sign(=) as the comparison operator for the condition. It has two types — SQL Outer join and SQL Inner join.</p>\n<ol>\n<li><span id=\"d86b\">SQL NON EQUI JOIN :</span></li>\n</ol>\n<p>The <strong>SQL NON EQUI JOIN</strong> is a join uses comparison operator other than the equal sign like >, &#x3C;, >=, &#x3C;= with the condition.</p>\n<p><strong>SQL EQUI JOIN : INNER JOIN and OUTER JOIN</strong></p>\n<p>The SQL EQUI JOIN can be classified into two types — INNER JOIN and OUTER JOIN</p>\n<ol>\n<li><span id=\"c9b5\">SQL INNER JOIN</span></li>\n</ol>\n<p>This type of EQUI JOIN returns all rows from tables where the key record of one table is equal to the key records of another table.</p>\n<ol>\n<li><span id=\"6bc6\">SQL OUTER JOIN</span></li>\n</ol>\n<p>This type of EQUI JOIN returns all rows from one table and only those rows from the secondary table where the joined condition is satisfying i.e. the columns are equal in both tables.</p>\n<p>In order to perform a JOIN query, the required information we need are:</p>\n<p><strong>a)</strong> The name of the tables<strong>b)</strong> Name of the columns of two or more tables, based on which a condition will perform.</p>\n<p><strong>Syntax:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">FROM table1\njoin_type table2\n[ON (join_condition)]</code></pre></div>\n<p><strong>Parameters:</strong></p>\n<p><a href=\"https://www.notion.so/3e2d9e2f028e4b7abf2da81156a54364\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p><strong>Pictorial Presentation of SQL Joins:</strong></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*bbwqJEpV2a9WZG-t.gif\" class=\"graf-image\" />\n</figure>**Example:**\n<p><strong>Sample table: company</strong></p>\n<p><strong>Sample table: foods</strong></p>\n<p>To join two tables 'company' and 'foods', the following SQL statement can be used :</p>\n<p><strong>SQL Code:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT  company.company_id,company.company_name,\nfoods.item_id,foods.item_name\nFROM company,foods;</code></pre></div>\n<p>Copy</p>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">COMPAN COMPANY_NAME              ITEM_ID  ITEM_NAME\n------ ------------------------- -------- ---------------\n18     Order All                 1        Chex Mix\n18     Order All                 6        Cheez-It\n18     Order All                 2        BN Biscuit\n18     Order All                 3        Mighty Munch\n18     Order All                 4        Pot Rice\n18     Order All                 5        Jaffa Cakes\n18     Order All                 7        Salt n Shake\n15     Jack Hill Ltd             1        Chex Mix\n15     Jack Hill Ltd             6        Cheez-It\n15     Jack Hill Ltd             2        BN Biscuit\n15     Jack Hill Ltd             3        Mighty Munch\n15     Jack Hill Ltd             4        Pot Rice\n15     Jack Hill Ltd             5        Jaffa Cakes\n15     Jack Hill Ltd             7        Salt n Shake\n16     Akas Foods                1        Chex Mix\n16     Akas Foods                6        Cheez-It\n16     Akas Foods                2        BN Biscuit\n16     Akas Foods                3        Mighty Munch\n16     Akas Foods                4        Pot Rice\n16     Akas Foods                5        Jaffa Cakes\n16     Akas Foods                7        Salt n Shake\n.........\n.........\n.........</code></pre></div>\n<p><strong>JOINS: Relational Databases</strong></p>\n<ul>\n<li>\n<span id=\"74c4\">\n<a href=\"https://www.w3resource.com/oracle/joins/index.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>Oracle JOINS</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"f8da\">\n<a href=\"https://www.w3resource.com/mysql/advance-query-in-mysql/mysql-joins.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>MySQL JOINS</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"33a5\">\n<a href=\"https://www.w3resource.com/PostgreSQL/postgresql-join.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>PostgreSQL JOINS</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"b578\">\n<a href=\"https://www.w3resource.com/sqlite/sqlite-inner-join.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQLite JOINS</strong>\n</a>\n</span>\n</li>\n</ul>\n<p><strong>Key points to remember:</strong></p>\n<p><em>Click on the following to get the slides presentation -</em></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*lP_nQo6VtVu_68nx.png\" class=\"graf-image\" />\n</figure>###\n<p><strong>Practice SQL Exercises</strong></p>\n<ul>\n<li>\n<span id=\"0765\">\n<a href=\"https://www.w3resource.com/sql-exercises/index.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL Exercises, Practice, Solution</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"4cd9\">\n<a href=\"https://www.w3resource.com/sql-exercises/sql-retrieve-from-table.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL Retrieve data from tables [33 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"7204\">\n<a href=\"https://www.w3resource.com/sql-exercises/sql-boolean-operators.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL Boolean and Relational operators [12 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"3d4e\">\n<a href=\"https://www.w3resource.com/sql-exercises/sql-wildcard-special-operators.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL Wildcard and Special operators [22 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"7afb\">\n<a href=\"https://www.w3resource.com/sql-exercises/sql-aggregate-functions.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL Aggregate Functions [25 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"cc71\">\n<a href=\"https://www.w3resource.com/sql-exercises/sql-fromatting-output-exercises.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL Formatting query output [10 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"77bf\">\n<a href=\"https://www.w3resource.com/sql/joins/s/sql-exercises/ql-exercises-quering-on-multiple-table.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL Quering on Multiple Tables [7 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"0bc2\">\n<a href=\"https://www.w3resource.com/sql-exercises/sorting-and-filtering-hr/index.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>FILTERING and SORTING on HR Database [38 Exercises]</strong>\n</a>\n</span>\n</li>\n<li><span id=\"e28a\">SQL JOINS</span></li>\n<li>\n<span id=\"84a2\">\n<a href=\"https://www.w3resource.com/sql-exercises/sql-joins-exercises.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL JOINS [29 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"f97b\">\n<a href=\"https://www.w3resource.com/sql-exercises/joins-hr/index.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL JOINS on HR Database [27 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"b33e\">  \n</li>\n<li>\n</span>\n</li>\n<li><span id=\"0983\">SQL SUBQUERIES</span></li>\n<li>\n<span id=\"423b\">\n<a href=\"https://www.w3resource.com/sql-exercises/subqueries/index.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL SUBQUERIES [39 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"a4d7\">\n<a href=\"https\n</li>\n<li>\n<span id=\"b63d\">  \n</li>\n<li>\n</span>\n</li>\n<li>\n<span id=\"2c29\">\n<a href=\"https://www.w3resource.com/sql-exercises/union/sql-union.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL Union[9 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"92c5\">\n<a href=\"https://www.\n</li>\n<li>\n<span id=\"d3e5\">\n<a href=\"https://www.w3resource.com/sql-exercises/sql-user-management.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SQL User Account Management [16 Exercise]</strong>\n</a>\n</span>\n</li>\n<li><span id=\"e280\">Movie Database</span></li>\n<li>\n<span id=\"5198\">\n<a href=\"https://www.w3resource.com/sql-exercises/movie-database-exercise/basic-exercises-on-movie-database.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>BASIC queries on movie Database [10 Exercises]</strong>\n</a\n</li>\n<li>\n<span id=\"ddd5\">\n<a href=\"https\n</li>\n<li>\n<span id=\"5363\">\n<a href=\"https://www.w\n</li>\n<li>\n<span id=\"b248\">  \n</li>\n<li>\n</span>\n</li>\n<li><span id=\"d5ba\">Soccer Database</span></li>\n<li>\n<span id=\"a586\">\n<a href=\"https://www.w3resource.com/sql-exercises/soccer-database-exercise/index.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>Introduction</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"d585\">\n<a href=\"https\n</li>\n<li>\n<span id=\"b626\">\n<a href=\"https://www.w3r\n</li>\n<li>\n<span id=\"95e1\">\n<a href=\"https://www.w3resource.com/sql-exercises/soccer-database-exercise/joins-exercises-on-soccer-database.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>JOINS\n</li>\n<li>\n<span id=\"05ba\">  \n</li>\n<li>\n</span>\n</li>\n<li><span id=\"2b7b\">Hospital Database</span></li>\n<li>\n<span id=\"788d\">\n<a href=\"https://www.w3resource.com/sql-exercises/hospital-database-exercise/index.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>Introduction</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"0c32\">\n<a href=\"https://www.w3resource.com/sql-exercises/hospital-database-exercise/sql-exercise-on-hospital-database.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>BASIC, SUBQUERIES, and JOINS [39 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"228b\">  \n</li>\n<li>\n</span>\n</li>\n<li><span id=\"54d4\">Employee Database</span></li>\n<li>\n<span id=\"c6fb\">\n<a href=\"https://www.w3resource.com/sql-exercises/employee-database-exercise/index.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>BASIC queries on employee Database [115 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"0419\">\n<a href=\"https://www.w3resource.com/sql-exercises/employee-database-exercise/subqueries-exercises-on-employee-database.php\" class=\"markup--anchor markup--li-anchor\">\n<strong>SUBQUERIES on employee Database [77 Exercises]</strong>\n</a>\n</span>\n</li>\n<li>\n<span id=\"cb3e\">  \n</span>\n</li>\n<li><span id=\"b3da\">More to come!</span></li>\n</ul>\n<h3>Objective 3 — write database access methods</h3>\n<h3>Overview</h3>\n<p>While we can write database code directly into our endpoints, best practices dictate that all database logic exists in separate, modular methods. These files containing database access helpers are often called <strong>models</strong></p>\n<h3>Follow Along</h3>\n<p>To handle CRUD operations for a single resource, we would want to create a <strong>model</strong> (or database access file) containing the following methods:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function find() {\n}\n\nfunction findById(id) {\n}\n\nfunction add(user) {\n}\n\nfunction update(changes, id) {\n}\n\nfunction remove(id) {\n}</code></pre></div>\n<p>Each of these functions would use Knex logic to perform the necessary database operation.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function find() {\n  return db('users');\n}</code></pre></div>\n<p>For each method, we can choose what value to return. For example, we may prefer <code class=\"language-text\">findById()</code> to return a single <code class=\"language-text\">user</code> object rather than an array.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function findById(id) {\n// first() returns the first entry in the db matching the query\n  return db('users').where({ id }).first();\n}</code></pre></div>\n<p>We can also use existing methods like <code class=\"language-text\">findById()</code> to help <code class=\"language-text\">add()</code> return the new user (instead of just the id).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function add(user) {\n  db('users').insert(user)\n    .then(ids => {\n      return findById(ids[0]);\n    });\n}</code></pre></div>\n<p>Once all methods are written as desired, we can export them like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  find,\n  findById,\n  add,\n  update,\n  delete,\n}</code></pre></div>\n<p>…and use the helpers in our endpoints</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const User = require('./user-model.js');\n\nrouter.get('/', (req, res) => {\n  User.find()\n    .then(users => {\n      res.json(users);\n    })\n    .catch(&amp;nbsp;err => {});\n});</code></pre></div>\n<p>There should no be <code class=\"language-text\">knex</code> code in the endpoints themselves.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### A database is a collection of data organized for easy retrieval and manipulation.\n<p>We're concerned only with digital databases, those that run on computers or other electronic devices. Digital databases have been around since the 1960s. Relational databases, those which store \"related\" data, are the oldest and most common type of database in use today.</p>\n<h3>Data Persistence</h3>\n<p>A database is often necessary because our application or code requires data persistence. This term refers to data that is infrequently accessed and not likely to be modified. In less technical terms, the information will be safely stored and remain untouched unless intentionally modified.</p>\n<p>A familiar example of non-persistent data would be JavaScript objects and arrays, which reset each time the code runs.</p>\n<h3>Relational Databases</h3>\n<p>In relational databases, <strong>the data is stored in tabular format grouped into rows and columns</strong> (similar to spreadsheets). A collection of rows is called a table. Each row represents a single record in the table and is made up of one or more columns.</p>\n<p>These kinds of databases are relational because a <em>relation</em> is a mathematical idea equivalent to a table. So relational databases are databases that store their data in tables.</p>\n<h3>Tables</h3>\n<p><strong>Below are some basic facts about tables:</strong></p>\n<blockquote>\n<p>Tables organize data in rows and columns.</p>\n</blockquote>\n<blockquote>\n<p>Each row in a table represents one distinct record.</p>\n</blockquote>\n<blockquote>\n<p>Each column represents a field or attribute that is common to all the records.</p>\n</blockquote>\n<blockquote>\n<p>Fields should have a descriptive name and a data type appropriate for the attribute it represents.</p>\n</blockquote>\n<blockquote>\n<p>Tables usually have more rows than columns.</p>\n</blockquote>\n<blockquote>\n<p>Tables have primary keys that uniquely identify each row.</p>\n</blockquote>\n<blockquote>\n<p>Foreign keys represent the relationships with other tables.</p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*7ZPYzWNRcs2PBL6p.jpg\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### SQL:\n<p>SQL is a standard language, which means that it almost certainly will be supported, no matter how your database is managed. That said, be aware that the SQL language can vary depending on database management tools. This lesson focuses on a set of core commands that never change. Learning the standard commands is an excellent introduction since the knowledge transfers between database products.</p>\n<p>The syntax for SQL is English-like and requires fewer symbols than programming languages like C, Java, and JavaScript.</p>\n<p>It is declarative and concise, which means there is a lot less to learn to use it effectively.</p>\n<p>When learning SQL, it is helpful to understand that each command is designed for a different purpose. If we classify the commands by purpose, we'll end up with the following sub-categories of SQL:</p>\n<ul>\n<li><span id=\"aba8\"><strong>Data Definition Language (DDL)</strong>: used to modify database objects. Some examples are: <code class=\"language-text\">CREATE TABLE</code>, <code class=\"language-text\">ALTER TABLE</code>, and <code class=\"language-text\">DROP TABLE</code>.</span></li>\n<li><span id=\"4f3f\"><strong>Data Manipulation Language (DML)</strong>: used to manipulate the data stored in the database. Some examples are: <code class=\"language-text\">INSERT</code>, <code class=\"language-text\">UPDATE</code>, and <code class=\"language-text\">DELETE</code>.</span></li>\n<li><span id=\"e1f2\"><strong>Data Query Language (DQL)</strong>: used to ask questions about the data stored in the database. The most commonly used SQL command is <code class=\"language-text\">SELECT</code>, and it falls in this category.</span></li>\n<li><span id=\"4474\"><strong>Data Control Language (DCL)</strong>: used to manage database security and user's access to data. These commands fall into the realm of Database Administrators. Some examples are <code class=\"language-text\">GRANT</code> and <code class=\"language-text\">REVOKE</code>.</span></li>\n<li><span id=\"921b\"><strong>Transaction Control Commands</strong>: used for managing groups of statements that must execute as a unit or not execute at all. Examples are <code class=\"language-text\">COMMIT</code> and <code class=\"language-text\">ROLLBACK</code>.</span></li>\n</ul>\n<p>As a developer, you'll need to get familiar with DDL and become proficient using DML and DQL. This lesson will cover only DML and DQL commands.</p>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>The four SQL operations covered in this section will allow a user to **query**, **insert**, and **modify** a database table.\n<h3>Query</h3>\n<p>A <strong>query</strong> is a SQL statement used to retrieve data from a database. The command used to write queries is <code class=\"language-text\">SELECT</code>, and it is one of the most commonly used SQL commands.</p>\n<p>The basic syntax for a <code class=\"language-text\">SELECT</code> statement is this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select &lt;selection> from &lt;table name>;</code></pre></div>\n<p>To see all the fields on a table, we can use a <code class=\"language-text\">*</code> as the <code class=\"language-text\">selection</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select * from employees;</code></pre></div>\n<p>The preceding statement would show all the records and all the columns for each record in the <code class=\"language-text\">employees</code> table.</p>\n<p>To pick the fields we want to see, we use a comma-separated list:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select first_name, last_name, salary from employees;</code></pre></div>\n<p>The return of that statement would hold all records from the listed fields.</p>\n<p>We can extend the <code class=\"language-text\">SELECT</code> command's capabilities using <code class=\"language-text\">clauses</code> for things like filtering, sorting, pagination, and more.</p>\n<p>It is possible to query multiple tables in a single query. But, in this section, we only perform queries on a single table. We will cover performing queries on multiple tables in another section.</p>\n<h3>Insert</h3>\n<p>To <strong>insert</strong> new data into a table, we'll use the <code class=\"language-text\">INSERT</code> command. The basic syntax for an <code class=\"language-text\">INSERT</code> statement is this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">insert into &lt;table name> (&lt;selection>) values (&lt;values>)</code></pre></div>\n<p>Using this formula, we can specify which values will be inserted into which fields like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">insert into Customers (Country, CustomerName, ContactName, Address, City, PostalCode)\nvalues ('USA', 'WebDev School', 'Austen Allred', '1 WebDev Court', 'Provo', '84601');</code></pre></div>\n<h3>Modify</h3>\n<p><strong>Modifying</strong> a database consists of updating and removing records. For these operations, we'll use <code class=\"language-text\">UPDATE</code> and <code class=\"language-text\">DELETE</code> commands, respectively.</p>\n<p>The basic syntax for an <code class=\"language-text\">UPDATE</code> statement is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">update &lt;table name> set &lt;field> = &lt;value> where &lt;condition>;</code></pre></div>\n<p>The basic syntax for a <code class=\"language-text\">DELETE</code> statement is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">delete from &lt;table name> where &lt;condition>;</code></pre></div>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### Filtering results using WHERE clause\n<p>When querying a database, the default result will be every entry in the given table. However, often, we are looking for a specific record or a set of records that meets certain criteria.</p>\n<p>A <code class=\"language-text\">WHERE</code> clause can help in both cases.</p>\n<p>Here's an example where we might only want to find customers living in Berlin.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select City, CustomerName, ContactName\nfrom Customers\nwhere City = 'Berlin'</code></pre></div>\n<p>We can also chain together <code class=\"language-text\">WHERE</code> clauses using <code class=\"language-text\">OR</code> and <code class=\"language-text\">AND</code> to limit our results further.</p>\n<p>The following query includes only records that match both criteria.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select City, CustomerName, ContactName\nfrom Customers\nwhere Country = 'France' and City = 'Paris'</code></pre></div>\n<p>And this query includes records that match either criteria.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select City, CustomerName, ContactName\nfrom Customers\nwhere Country = 'France' or City = 'Paris'</code></pre></div>\n<p>These operators can be combined and grouped with parentheses to add complex selection logic. They behave similarly to what you're used to in programming languages.</p>\n<p>You can read more about SQLite operators from <a href=\"https://www.w3resource.com/sqlite/operators.php\" class=\"markup--anchor markup--p-anchor\">w3resource (Links to an external site.)</a>.</p>\n<p>To select a single record, we can use a <code class=\"language-text\">WHERE</code> statement with a uniquely identifying field, like an id:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select * from Customers\nwhere CustomerId=3;</code></pre></div>\n<p>Other comparison operators also work in <code class=\"language-text\">WHERE</code> conditions, such as <code class=\"language-text\">></code>, <code class=\"language-text\">&lt;</code>, <code class=\"language-text\">&lt;=</code>, and <code class=\"language-text\">>=</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select * from employees where salary >= 50000</code></pre></div>\n<h3>Ordering results using the ORDER BY clause</h3>\n<p>Query results are shown in the same order the data was inserted. To control how the data is sorted, we can use the <code class=\"language-text\">ORDER BY</code> clause. Let's see an example.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">-- sorts the results first by salary in descending order, then by the last name in ascending order\nselect * from employees order by salary desc, last_name;</code></pre></div>\n<p>We can pass a list of field names to <code class=\"language-text\">order by</code> and optionally choose <code class=\"language-text\">asc</code> or <code class=\"language-text\">desc</code> for the sort direction. The default is <code class=\"language-text\">asc</code>, so it doesn't need to be specified.</p>\n<p>Some SQL engines also support using field abbreviations when sorting.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select name, salary, department from employees order by 3, 2 desc;</code></pre></div>\n<p>In this case, the results are sorted by the department in ascending order first and then by salary in descending order. The numbers refer to the fields' position in the <em>selection</em> portion of the query, so <code class=\"language-text\">1</code> would be <em>name</em>, <code class=\"language-text\">2</code> would be <em>salary</em>, and so on.</p>\n<p>Note that the <code class=\"language-text\">WHERE</code> clause should come after the <code class=\"language-text\">FROM</code> clause. The <code class=\"language-text\">ORDER BY</code> clause always goes last.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select * from employees where salary > 50000 order by last_name;</code></pre></div>\n<h3>Limiting results using the LIMIT clause</h3>\n<p>When we wish to see only a limited number of records, we can use a <code class=\"language-text\">LIMIT</code> clause.</p>\n<p>The following returns the first ten records in the products table:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select * from products\nlimit 10</code></pre></div>\n<p><code class=\"language-text\">LIMIT</code> clauses are often used in conjunction with <code class=\"language-text\">ORDER BY</code>. The following shows us the five cheapest products:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select * from products\norder by price desc\nlimit 5</code></pre></div>\n<h3>Inserting data using INSERT</h3>\n<p>An insert statement adds a new record to the database. All non-null fields must be listed out in the same order as their values. Some fields, like ids and timestamps, may be auto-generated and do not need to be included in an <code class=\"language-text\">INSERT</code> statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">-- we can add fields in any order; the values need to be in the same ordinal position\n-- the id will be assigned automatically\n  insert into Customers (Country, CustomerName, ContactName, Address, City, PostalCode)\n  values ('USA', 'WebDev School', 'Austen Allred', '1 WebDev Court', 'Provo', '84601');</code></pre></div>\n<p>The values in an insert statement must not violate any restrictions and constraints that the database has in place, such as expected datatypes. We will learn more about constraints and schema design in a later section.</p>\n<h3>Modifying recording using UPDATE</h3>\n<p>When modifying a record, we identify a single record or a set of records to update using a <code class=\"language-text\">WHERE</code> clause. Then we can set the new value(s) in place.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">update Customers\nset City = 'Silicon Valley', Country = 'USA'\nwhere CustomerName = 'WebDev School'</code></pre></div>\n<p>Technically the <code class=\"language-text\">WHERE</code> clause is not required, but leaving it off would result in every record within the table receiving the update.</p>\n<h3>Removing records using DELETE</h3>\n<p>When removing a record or set of records, we need only identify which record(s) to remove using a <code class=\"language-text\">WHERE</code> clause:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">delete from Customers\nwhere CustomerName = 'WebDev School`;</code></pre></div>\n<p>Once again, the <code class=\"language-text\">WHERE</code> clause is not required, but leaving it off would remove every record in the table, so it's essential.</p>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>Raw SQL is a critical baseline skill. However, Node developers generally use an **Object Relational Mapper (ORM)** or **query builder** to write database commands in a backend codebase. Both **ORMs** and **query builders** are JavaScript libraries that allow us to interface with the database using a JavaScript version of the SQL language.\n<p>For example, instead of a raw SQL <code class=\"language-text\">SELECT</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT * FROM users;</code></pre></div>\n<p>We could use a query builder to write the same logic in JavaScript:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db.select('*').from('users');</code></pre></div>\n<p><strong>Query builders</strong> are lightweight and easy to get off the ground, whereas <strong>ORMs</strong> use an object-oriented model and provide more heavy lifting within their rigid structure.</p>\n<p>We will use a <strong>query builder</strong> called <a href=\"https://knexjs.org/\" class=\"markup--anchor markup--p-anchor\">knex.js (Links to an external site.)</a>.</p>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### Knex Setup\n<p>To use Knex in a repository, we'll need to add two libraries:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install knex sqlite3</code></pre></div>\n<p><code class=\"language-text\">knex</code> is our query builder library, and <code class=\"language-text\">sqlite3</code> allows us to interface with a <code class=\"language-text\">sqlite</code> database. We'll learn more about <code class=\"language-text\">sqlite</code> and other <strong>database management systems</strong> in the following module. For now, know that you need both libraries.</p>\n<p>Next, we use Knex to set up a config file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const knex = require('knex');\n\nconst config = {\n  client: 'sqlite3',\n  connection: {\n    filename: './data/posts.db3',\n  },\n  useNullAsDefault: true,\n};\n\nmodule.exports = knex(config);</code></pre></div>\n<p>To use the query builder elsewhere in our code, we need to call <code class=\"language-text\">knex</code> and pass in a <code class=\"language-text\">config</code> object. We'll be discussing Knex configuration more in a future module. Still, we only need the <code class=\"language-text\">client</code>, <code class=\"language-text\">connection</code>, and <code class=\"language-text\">useNullAsDefault</code> keys as shown above. The <code class=\"language-text\">filename</code> should point towards the pre-existing database file, which can be recognized by the <code class=\"language-text\">.db3</code> extension.</p>\n<p><strong>GOTCHA</strong>: The file path to the database should be with respect to the <strong>root</strong> of the repo, not the configuration file itself.</p>\n<p>Once Knex is configured, we can import the above config file anywhere in our codebase to access the database.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const db = require('../data/db-config.js);</code></pre></div>\n<p>The <code class=\"language-text\">db</code> object provides methods that allow us to begin building queries.</p>\n<h3>SELECT using Knex</h3>\n<p>In Knex, the equivalent of <code class=\"language-text\">SELECT * FROM users</code> is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db.select('*').from('users');</code></pre></div>\n<p>There's a simpler way to write the same command:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db('users');</code></pre></div>\n<p>Using this, we could write a <code class=\"language-text\">GET</code> endpoint.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">router.get('/api/users', (req, res) => {\n  db('users')\n  .then(users => {\n    res.json(users);\n  })\n  .catch (err => {\n    res.status(500).json({ message: 'Failed to get users' });\n  });\n});</code></pre></div>\n<p><strong>NOTE</strong>: All Knex queries return promises.</p>\n<p>Knex also allows for a where clause. In Knex, we could write <code class=\"language-text\">SELECT * FROM users WHERE id=1</code> as</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db('users').where({ id: 1 });</code></pre></div>\n<p>This method will resolve to an array containing a single entry like so: <code class=\"language-text\">[{ id: 1, name: 'bill' }]</code>.</p>\n<p>Using this, we might add a <code class=\"language-text\">GET</code> endpoint where a specific user:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">server.get('api/users/:id', (req, res) => {\n  const { id } = req.params;\n\ndb('users').where({ id })\n  .then(users => {\n    // we must check the length to find our if our user exists\n    if (users.length) {\n      res.json(users);\n    } else {\n      res.status(404).json({ message: 'Could not find user with given id.' })\n   })\n  .catch (err => {\n    res.status(500).json({ message: 'Failed to get user' });\n  });\n});</code></pre></div>\n<h3>INSERT using Knex</h3>\n<p>In Knex, the equivalent of <code class=\"language-text\">INSERT INTO users (name, age) VALUES ('Eva', 32)</code> is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db('users').insert({ name: 'Eva', age: 32 });</code></pre></div>\n<p>The insert method in Knex will resolve to an array containing the newly created id for that user like so: <code class=\"language-text\">[3]</code>.</p>\n<h3>UPDATE using Knex</h3>\n<p>In knex, the equivalent of <code class=\"language-text\">UPDATE users SET name='Ava', age=33 WHERE id=3;</code> is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db('users').where({ id: 3 })\n.update({name: 'Ava', age: 33 });</code></pre></div>\n<p>Note that the <code class=\"language-text\">where</code> method comes before <code class=\"language-text\">update</code>, unlike in SQL.</p>\n<p>Update will resolve to a count of rows updated.</p>\n<h3>DELETE using Knex</h3>\n<p>In Knex, the equivalent of <code class=\"language-text\">DELETE FROM users WHERE age=33;</code> is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db('users').where({ age: 33}).del();</code></pre></div>\n<p>Once again, the <code class=\"language-text\">where</code> must come before the <code class=\"language-text\">del</code>. This method will resolve to a count of records removed.</p>\n<hr>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>###\n<h3>Here's a small project you can practice with.</h3>\n<p>SQLlite Studio is an application that allows us to create, open, view, and modify SQLite databases. To fully understand what SQLite Studio is and how it works, we must also understand the concept of the Database Management Systems (DBMS).</p>\n<h3>What is a DBMS?</h3>\n<p>To manage digital databases we use specialized software called <strong>D</strong>ata<strong>B</strong>ase <strong>M</strong>anagement <strong>S</strong>ystems (DBMS). These systems typically run on servers and are managed by <strong>D</strong>ata<strong>B</strong>ase <strong>A</strong>dministrators (DBAs).</p>\n<p>In less technical terms, we need a type of software that will allow us to create, access, and generally manage our databases. In the world of relational databases, we specifically use Relational Database Mangement Systems (RDBMs). Some examples are Postgres, SQLite, MySQL, and Oracle.</p>\n<p>Choosing a DBMS determines everything from how you set up your database, to where and how the data is stored, to what SQL commands you can use. Most systems share the core of the SQL language that you've already learned.</p>\n<p>In other words, you can expect <code class=\"language-text\">SELECT</code>, <code class=\"language-text\">UPDATE</code>, <code class=\"language-text\">INSERT</code>, <code class=\"language-text\">WHERE</code> , and the like to be the same across all DBMSs, but the subtleties of the language may vary.</p>\n<h3>What is SQLite?</h3>\n<p><strong>SQLite</strong> is the DBMS, as the name suggests, it is a more lightweight system and thus easier to get set up than some others.</p>\n<p>SQLite allows us to store databases as single files. SQLite projects have a <code class=\"language-text\">.db3</code> extension. That is the database.</p>\n<p>SQLite is <em>not a database</em> (like relational, graph, or document are databases) but rather <em>a database management system</em>.</p>\n<h3>Opening an existing database in SQLite Studio</h3>\n<p>One useful visual interface we might use with a SQLite database is called <strong>SQLite Studio</strong>. <a href=\"https://sqlitestudio.pl/\" class=\"markup--anchor markup--p-anchor\">Install SQLITE Studio here. (Links to an external site.)</a></p>\n<p>Once installed, we can use SQLite Studio to open any <code class=\"language-text\">.db3</code> file from a previous lesson. We may view the tables, view the data, and even make changes to the database.</p>\n<p>For a more detailed look at SQLite Studio, follow along in the video above.</p>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>A **database schema** is the shape of our database. It defines what tables we'll have, which columns should exist within the tables and any restrictions on each column.\n<p>A well-designed database schema keeps the data well organized and can help ensure high-quality data.</p>\n<p>Note that while schema design is usually left to Database Administrators (DBAs), understanding schema helps when designing APIs and database logic. And in a smaller team, this step may fall on the developer.</p>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>For a look at schema design in SQLite Studio, follow along in the video above.\n<p>When designing a single table, we need to ask three things:</p>\n<ul>\n<li><span id=\"2e1a\">What fields (or columns) are present?</span></li>\n<li><span id=\"52e7\">What type of data do we expect for each field?</span></li>\n<li><span id=\"8aff\">Are there other restrictions needed for each column?</span></li>\n</ul>\n<p>Looking at the following schema diagram for an <code class=\"language-text\">accounts</code> table, we can the answer to each other those questions:</p>\n<p><a href=\"https://www.notion.so/9790405dda624818822293a383eec2d2\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<h3>Table Fields</h3>\n<p>Choosing which fields to include in a table is relatively straight forward. What information needs to be tracked regarding this resource? In the real world, this is determined by the intended use of the product or app.</p>\n<p>However, this is one requirement every table should satisfy: a <strong>primary key</strong>. A primary key is a way to identify each entry in the database uniquely. It is most often represented as a auto-incrementing integer called <code class=\"language-text\">id</code> or <code class=\"language-text\">[tablename]Id</code>.</p>\n<h3>Datatypes</h3>\n<p>Each field must also have a specified datatype. The datatype available depends on our DBMS. Some supported datatype in SQLite include:</p>\n<ul>\n<li><span id=\"92fb\"><strong>Null:</strong> Missing or unknown information.</span></li>\n<li><span id=\"32ef\"><strong>Integer:</strong> Whole numbers.</span></li>\n<li><span id=\"181d\"><strong>Real:</strong> Any number, including decimals.</span></li>\n<li><span id=\"ebce\"><strong>Text:</strong> Character data.</span></li>\n<li><span id=\"c00e\"><strong>Blob:</strong> a large binary object that can be used to store miscellaneous data.</span></li>\n</ul>\n<p>Any data inserted into the table must match the datatypes determined in schema design.</p>\n<h3>Constraints</h3>\n<p>Beyond datatypes, we may add additional <strong>constraints</strong> on each field. Some examples include:</p>\n<ul>\n<li><span id=\"14ca\"><strong>Not Null:</strong> The field cannot be left empty</span></li>\n<li><span id=\"b533\"><strong>Unique:</strong> No two records can have the same value in this field</span></li>\n<li><span id=\"f0c4\"><strong>Primary key:</strong> — Indicates this field is the primary key. Both the not null and unique constraints will be enforced.</span></li>\n<li><span id=\"f116\"><strong>Default:</strong> — Sets a default value if none is provided.</span></li>\n</ul>\n<p>As with data types, any data that does not satisfy the schema constraints will be rejected from the database.</p>\n<h3></h3>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### Multi-Table Design\n<p>Another critical component of schema design is to understand how different tables relate to each other. This will be covered in later lesson.</p>\n<p>Knex provides a <strong>schema builder</strong>, which allows us to write code to design our database schema. However, beyond thinking about columns and constraints, we must also consider updates.</p>\n<p>When a schema needs to be updated, a developer must feel confident that the changes go into effect everywhere. This means schema updates on the developer's local machine, on any testing or staging versions, on the production database, and then on any other developer's local machines. This is where <strong>migrations</strong> come into play.</p>\n<p>A <code class=\"language-text\">database migration</code> describes changes made to the structure of a database. Migrations include things like adding new objects, adding new tables, and modifying existing objects or tables.</p>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### Knex Cli\n<p>To use migrations (and to make Knex setup easier), we need to use <strong>knex cli</strong>. Install knex globally with <code class=\"language-text\">npm install -g knex</code>.</p>\n<p>This allows you to use Knex commands within any repo that has <code class=\"language-text\">knex</code> as a local dependency. If you have any issues with this global install, you can use the <code class=\"language-text\">npx knex</code> command instead.</p>\n<h3>Initializing Knex</h3>\n<p>To start, add the <code class=\"language-text\">knex</code> and <code class=\"language-text\">sqlite3</code> libraries to your repository.</p>\n<p><code class=\"language-text\">npm install knex sqlite3</code></p>\n<p>We've seen how to use manually create a config object to get started with Knex, but the best practice is to use the following command:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">knex init</code></pre></div>\n<p>Or, if Knex isn't globally installed:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npx knex init</code></pre></div>\n<p>This command will generate a file in your root folder called <code class=\"language-text\">knexfile.js</code>. It will be auto populated with three config objects, based on different environments. We can delete all except for the development object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n\ndevelopment: {\n    client: 'sqlite3',\n    connection: {\n      filename: './dev.sqlite3'\n    }\n  }\n\n};</code></pre></div>\n<p>We'll need to update the location (or desired location) of the database as well as add the <code class=\"language-text\">useNullAsDefault</code> option. The latter option prevents crashes when working with <code class=\"language-text\">sqlite3</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n\ndevelopment: {\n    // our DBMS driver\n    client: 'sqlite3',\n    // the location of our db\n    connection: {\n      filename: './data/database_file.db3',\n    },\n    // necessary when using sqlite3\n    useNullAsDefault: true\n  }\n\n};</code></pre></div>\n<p>Now, wherever we configure our database, we may use the following syntax instead of hardcoding in a config object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const knex = require('knex');\n\nconst config = require('../knexfile.js');\n\n// we must select the development object from our knexfile\nconst db = knex(config.development);\n\n// export for use in codebase\nmodule.exports = db;</code></pre></div>\n<h3>Knex Migrations</h3>\n<p>Once our <code class=\"language-text\">knexfile</code> is set up, we can begin creating <strong>migrations</strong>. Though it's not required, we are going to add an <code class=\"language-text\">addition</code> option to the config object to specify a directory for the migration files.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">development: {\n    client: 'sqlite3',\n    connection: {\n      filename: './data/produce.db3',\n    },\n    useNullAsDefault: true,\n    // generates migration files in a data/migrations/ folder\n    migrations: {\n      directory: './data/migrations'\n    }\n  }</code></pre></div>\n<p>We can generate a new migration with the following command:</p>\n<p><code class=\"language-text\">knex migrate:make [migration-name]</code></p>\n<p>If we needed to create an accounts table, we might run:</p>\n<p><code class=\"language-text\">knex migrate:make create-accounts</code></p>\n<p>Note that inside <code class=\"language-text\">data/migrations/</code> a new file has appeared. Migrations have a timestamp in their filenames automatically. Wither you like this or not, <strong>do not edit migration names.</strong></p>\n<p>The migration file should have both an <code class=\"language-text\">up</code> and a <code class=\"language-text\">down</code> function. Within the <code class=\"language-text\">up</code> function, we write the ended database changes. Within the <code class=\"language-text\">down</code> function, we write the code to undo the <code class=\"language-text\">up</code> functions. This allows us to undo any changes made to the schema if necessary.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">exports.up = function(knex, Promise) {\n  // don't forget the return statement\n  return knex.schema.createTable('accounts', tbl => {\n    // creates a primary key called id\n    tbl.increments();\n    // creates a text field called name which is both required and unique\n    tbl.text('name', 128).unique().notNullable();\n    // creates a numeric field called budget which is required\n    tbl.decimal('budget').notNullable();\n  });\n};\n\nexports.down = function(knex, Promise) {\n  // drops the entire table\n  return knex.schema.dropTableIfExists('accounts');\n};</code></pre></div>\n<p>References for these methods are found in the <strong>schema builder</strong> section of the <a href=\"https://knexjs.org/\" class=\"markup--anchor markup--p-anchor\">Knex docs (Links to an external site.)</a>.</p>\n<p>At this point, the table is <strong>not</strong> yet created. To run this (and any other) migrations, use the command:</p>\n<p><code class=\"language-text\">knex migrate:latest</code></p>\n<p>Note if the database does not exist, this command will auto-generate one. We can use SQLite Studio to confirm that the accounts table has been created.</p>\n<h3>Changes and Rollbacks</h3>\n<p>If later down the road, we realize you need to update your schema, you shouldn't edit the migration file. Instead, you will want to create a new migration with the command:</p>\n<p><code class=\"language-text\">knex migrate:make accounts-schema-update</code></p>\n<p>Once we've written our updates into this file we save and close with:</p>\n<p><code class=\"language-text\">knex migrate:latest</code></p>\n<p>If we migrate our database and then quickly realize something isn't right, we can edit the migration file. However, first, we need to <strong>rolllback</strong> (or undo) our last migration with:</p>\n<p><code class=\"language-text\">knex migrate:rollback</code></p>\n<p>Finally, we are free to rerun that file with <code class=\"language-text\">knex migrate</code> latest.</p>\n<p><strong>NOTE</strong>: A rollback should not be used to edit an old migration file once that file has accepted into a main branch. However, an entire team may use a rollback to return to a previous version of a database.</p>\n<h3>Overview</h3>\n<p>Knex provides a <strong>schema builder</strong>, which allows us to write code to design our database schema. However, beyond thinking about columns and constraints, we must also consider updates.</p>\n<p>When a schema needs to be updated, a developer must feel confident that the changes go into effect everywhere. This means schema updates on the developer's local machine, on any testing or staging versions, on the production database, and then on any other developer's local machines. This is where <strong>migrations</strong> come into play.</p>\n<p>A <code class=\"language-text\">database migration</code> describes changes made to the structure of a database. Migrations include things like adding new objects, adding new tables, and modifying existing objects or tables.</p>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### Knex Cli\n<p>To use migrations (and to make Knex setup easier), we need to use <strong>knex cli</strong>. Install knex globally with <code class=\"language-text\">npm install -g knex</code>.</p>\n<p>This allows you to use Knex commands within any repo that has <code class=\"language-text\">knex</code> as a local dependency. If you have any issues with this global install, you can use the <code class=\"language-text\">npx knex</code> command instead.</p>\n<h3>Initializing Knex</h3>\n<p>To start, add the <code class=\"language-text\">knex</code> and <code class=\"language-text\">sqlite3</code> libraries to your repository.</p>\n<p><code class=\"language-text\">npm install knex sqlite3</code></p>\n<p>We've seen how to use manually create a config object to get started with Knex, but the best practice is to use the following command:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">knex init</code></pre></div>\n<p>Or, if Knex isn't globally installed:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npx knex init</code></pre></div>\n<p>This command will generate a file in your root folder called <code class=\"language-text\">knexfile.js</code>. It will be auto populated with three config objects, based on different environments. We can delete all except for the development object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n\ndevelopment: {\n    client: 'sqlite3',\n    connection: {\n      filename: './dev.sqlite3'\n    }\n  }\n\n};</code></pre></div>\n<p>We'll need to update the location (or desired location) of the database as well as add the <code class=\"language-text\">useNullAsDefault</code> option. The latter option prevents crashes when working with <code class=\"language-text\">sqlite3</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n\ndevelopment: {\n    // our DBMS driver\n    client: 'sqlite3',\n    // the location of our db\n    connection: {\n      filename: './data/database_file.db3',\n    },\n    // necessary when using sqlite3\n    useNullAsDefault: true\n  }\n\n};</code></pre></div>\n<p>Now, wherever we configure our database, we may use the following syntax instead of hardcoding in a config object.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const knex = require('knex');\n\nconst config = require('../knexfile.js');\n\n// we must select the development object from our knexfile\nconst db = knex(config.development);\n\n// export for use in codebase\nmodule.exports = db;</code></pre></div>\n<h3>Knex Migrations</h3>\n<p>Once our <code class=\"language-text\">knexfile</code> is set up, we can begin creating <strong>migrations</strong>. Though it's not required, we are going to add an <code class=\"language-text\">addition</code> option to the config object to specify a directory for the migration files.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">development: {\n    client: 'sqlite3',\n    connection: {\n      filename: './data/produce.db3',\n    },\n    useNullAsDefault: true,\n    // generates migration files in a data/migrations/ folder\n    migrations: {\n      directory: './data/migrations'\n    }\n  }</code></pre></div>\n<p>We can generate a new migration with the following command:</p>\n<p><code class=\"language-text\">knex migrate:make [migration-name]</code></p>\n<p>If we needed to create an accounts table, we might run:</p>\n<p><code class=\"language-text\">knex migrate:make create-accounts</code></p>\n<p>Note that inside <code class=\"language-text\">data/migrations/</code> a new file has appeared. Migrations have a timestamp in their filenames automatically. Wither you like this or not, <strong>do not edit migration names.</strong></p>\n<p>The migration file should have both an <code class=\"language-text\">up</code> and a <code class=\"language-text\">down</code> function. Within the <code class=\"language-text\">up</code> function, we write the ended database changes. Within the <code class=\"language-text\">down</code> function, we write the code to undo the <code class=\"language-text\">up</code> functions. This allows us to undo any changes made to the schema if necessary.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">exports.up = function(knex, Promise) {\n  // don't forget the return statement\n  return knex.schema.createTable('accounts', tbl => {\n    // creates a primary key called id\n    tbl.increments();\n    // creates a text field called name which is both required and unique\n    tbl.text('name', 128).unique().notNullable();\n    // creates a numeric field called budget which is required\n    tbl.decimal('budget').notNullable();\n  });\n};\n\nexports.down = function(knex, Promise) {\n  // drops the entire table\n  return knex.schema.dropTableIfExists('accounts');\n};</code></pre></div>\n<p>References for these methods are found in the <strong>schema builder</strong> section of the <a href=\"https://knexjs.org/\" class=\"markup--anchor markup--p-anchor\">Knex docs (Links to an external site.)</a>.</p>\n<p>At this point, the table is <strong>not</strong> yet created. To run this (and any other) migrations, use the command:</p>\n<p><code class=\"language-text\">knex migrate:latest</code></p>\n<p>Note if the database does not exist, this command will auto-generate one. We can use SQLite Studio to confirm that the accounts table has been created.</p>\n<h3>Changes and Rollbacks</h3>\n<p>If later down the road, we realize you need to update your schema, you shouldn't edit the migration file. Instead, you will want to create a new migration with the command:</p>\n<p><code class=\"language-text\">knex migrate:make accounts-schema-update</code></p>\n<p>Once we've written our updates into this file we save and close with:</p>\n<p><code class=\"language-text\">knex migrate:latest</code></p>\n<p>If we migrate our database and then quickly realize something isn't right, we can edit the migration file. However, first, we need to <strong>rolllback</strong> (or undo) our last migration with:</p>\n<p><code class=\"language-text\">knex migrate:rollback</code></p>\n<p>Finally, we are free to rerun that file with <code class=\"language-text\">knex migrate</code> latest.</p>\n<p><strong>NOTE</strong>: A rollback should not be used to edit an old migration file once that file has accepted into a main branch. However, an entire team may use a rollback to return to a previous version of a database.</p>\n<h3>Overview</h3>\n<p>Often we want to pre-populate our database with sample data for testing. <strong>Seeds</strong> allow us to add and reset sample data easily.</p>\n<h3>Follow Along</h3>\n<p>The Knex command-line tool offers a way to <strong>seed</strong> our database; in other words, pre-populate our tables.</p>\n<p>Similarly to migrations, we want to customize where our seed files are generated using our <code class=\"language-text\">knexfile</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">development: {\n    client: 'sqlite3',\n    connection: {\n      filename: './data/produce.db3',\n    },\n    useNullAsDefault: true,\n    // generates migration files in a data/migrations/ folder\n    migrations: {\n      directory: './data/migrations'\n    },\n    seeds: {\n      directory: './data/seeds'\n    }\n  }</code></pre></div>\n<p>To create a seed run: <code class=\"language-text\">knex seed:make 001-seedName</code></p>\n<p>Numbering is a good idea because Knex doesn't attach a timestamp to the name like migrate does. Adding numbers to the file name, we can control the order in which they run.</p>\n<p>We want to create seeds for our accounts table:</p>\n<p><code class=\"language-text\">knex seed:make 001-accounts</code></p>\n<p>A file will appear in the designated seed folder.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">exports.seed = function(knex, Promise) {\n  // we want to remove all data before seeding\n  // truncate will reset the primary key each time\n  return knex('accounts').truncate()\n    .then(function () {\n      // add data into insert\n      return knex('accounts').insert([\n        { name: 'Stephenson', budget: 10000 },\n        { name: 'Gordon &amp; Gale', budget: 40400 },\n      ]);\n    });\n};</code></pre></div>\n<p>Run the seed files by typing:</p>\n<p><code class=\"language-text\">knex seed:run</code></p>\n<p>You can now use SQLite Studio to confirm that the accounts table has two entries.</p>\n<hr>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>### SQL & PostgreSQL\n<p><strong>Foreign keys</strong> are a type of table field used for creating links between tables. Like <strong>primary keys</strong>, they are most often integers that identify (rather than store) data. However, whereas a primary key is used to id rows in a table, foreign keys are used to connect a record in one table to a record in a second table.</p>\n<h3></h3>\n<p>Consider the following <code class=\"language-text\">farms</code> and <code class=\"language-text\">ranchers</code> tables.</p>\n<p><a href=\"https://www.notion.so/5b20c5e233dd4a70a33d6ab2c2e1c8bb\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/0b0a909c24a9474fb9df80938546f12a\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>The <code class=\"language-text\">farm_id</code> in the <code class=\"language-text\">ranchers</code> table is an example of a <code class=\"language-text\">foreign key</code>. Each entry in the <code class=\"language-text\">farm_id</code> (foreign key) column corresponds to an <code class=\"language-text\">id</code> (primary key) in the <code class=\"language-text\">farms</code> table. This allows us to track which farm each rancher belongs to while keeping the tables normalized.</p>\n<p>If we could only see the <code class=\"language-text\">ranchers</code> table, we would know that John, Jane, and Jen all work together and that Jim and Jay also work together. However, to know where any of them work, we would need to look at the <code class=\"language-text\">farms</code> table.</p>\n<p>Now that we understand the basics of querying data from a single table, let's move on to selecting data from multiple tables using JOIN operations.</p>\n<h3>Overview</h3>\n<p>We can use a <code class=\"language-text\">JOIN</code> to combine query data from multiple tables using a single <code class=\"language-text\">SELECT</code> statement.</p>\n<p>There are different types of joins; some are listed below:</p>\n<ul>\n<li><span id=\"d886\">inner joins.</span></li>\n<li><span id=\"43f5\">outer joins.</span></li>\n<li><span id=\"882e\">left joins.</span></li>\n<li><span id=\"ad86\">right joins.</span></li>\n<li><span id=\"4d8b\">cross joins.</span></li>\n<li><span id=\"eb21\">non-equality joins.</span></li>\n<li><span id=\"fc6a\">self joins.</span></li>\n</ul>\n<p>Using <code class=\"language-text\">joins</code> requires that the two tables of interest contain at least one field with shared information. For example, if a <em>departments</em> table has an <em>id</em> field, and an employee table has a <em>department</em>id_ field, and the values that exist in the <em>id</em> column of the <em>departments</em> table live in the <em>department</em>id_ field of the employee table, we can use those fields to join both tables like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select * from employees\njoin departments on employees.department_id = departments.id</code></pre></div>\n<p>This query will return the data from both tables for every instance where the <code class=\"language-text\">ON</code> condition is true. If there are employees with no value for department<em>id or where the value stored in the field does not correspond to an existing id in the</em> departments <em>table, then that record will NOT be returned. In a similar fashion, any records from the</em> departments <em>table that don't have an employee associated with them will also be omitted from the results. Basically, if the</em> id* does not show as the value of department_id for an employee, it won't be able to join.</p>\n<p>We can shorten the condition by giving the table names an alias. This is a common practice. Below is the same example using aliases, picking which fields to return and sorting the results:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">select d.id, d.name, e.id, e.first_name, e.last_name, e.salary\nfrom employees as e\njoin departments as d\n  on e.department_id = d.id\norder by d.name, e.last_name</code></pre></div>\n<p>Notice that we can take advantage of white space and indentation to make queries more readable.</p>\n<p>There are several ways of writing joins, but the one shown here should work on all database management systems and avoid some pitfalls, so we recommend it.</p>\n<p>The syntax for performing a similar join using Knex is as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">db('employees as e')\n  .join('departments as d', 'e.department_id', 'd.id')\n  .select('d.id', 'd.name', 'e.first_name', 'e.last_name', 'e.salary')</code></pre></div>\n<h3>Follow Along</h3>\n<p>A good explanation of how the different types of joins can be seen <a href=\"https://www.w3resource.com/sql/joins/sql-joins.php\" class=\"markup--anchor markup--p-anchor\">in this article from w3resource.com (Links to an external site.)</a>.</p>\n<h3>What is SQL Joins?</h3>\n<p>An SQL JOIN clause combines rows from two or more tables. It creates a set of rows in a temporary table.</p>\n<h3>How to Join two tables in SQL?</h3>\n<p>A JOIN works on two or more tables if they have at least one common field and have a relationship between them.</p>\n<p>JOIN keeps the base tables (structure and data) unchanged.</p>\n<h3>Join vs. Subquery</h3>\n<ul>\n<li><span id=\"6fdc\">JOINs are faster than a subquery and it is very rare that the opposite.</span></li>\n<li><span id=\"c648\">In JOINs the RDBMS calculates an execution plan, that can predict, what data should be loaded and how much it will take to processed and as a result this process save some times, unlike the subquery there is no pre-process calculation and run all the queries and load all their data to do the processing.</span></li>\n<li><span id=\"d59c\">A JOIN is checked conditions first and then put it into table and displays; where as a subquery take separate temp table internally and checking condition.</span></li>\n<li><span id=\"08ff\">When joins are using, there should be connection between two or more than two tables and each table has a relation with other while subquery means query inside another query, has no need to relation, it works on columns and conditions.</span></li>\n</ul>\n<h3>SQL JOINS: EQUI JOIN and NON EQUI JOIN</h3>\n<p>The are two types of SQL JOINS — EQUI JOIN and NON EQUI JOIN</p>\n<ol>\n<li><span id=\"2bb1\">SQL EQUI JOIN :</span></li>\n</ol>\n<p>The SQL EQUI JOIN is a simple SQL join uses the equal sign(=) as the comparison operator for the condition. It has two types — SQL Outer join and SQL Inner join.</p>\n<ol>\n<li><span id=\"a9be\">SQL NON EQUI JOIN :</span></li>\n</ol>\n<p>The <strong>SQL NON EQUI JOIN</strong> is a join uses comparison operator other than the equal sign like >, &#x3C;, >=, &#x3C;= with the condition.</p>\n<p><strong>SQL EQUI JOIN : INNER JOIN and OUTER JOIN</strong></p>\n<p>The SQL EQUI JOIN can be classified into two types — INNER JOIN and OUTER JOIN</p>\n<ol>\n<li><span id=\"cf44\">SQL INNER JOIN</span></li>\n</ol>\n<p>This type of EQUI JOIN returns all rows from tables where the key record of one table is equal to the key records of another table.</p>\n<ol>\n<li><span id=\"22a6\">SQL OUTER JOIN</span></li>\n</ol>\n<p>This type of EQUI JOIN returns all rows from one table and only those rows from the secondary table where the joined condition is satisfying i.e. the columns are equal in both tables.</p>\n<p>In order to perform a JOIN query, the required information we need are:</p>\n<p><strong>a)</strong> The name of the tables<strong>b)</strong> Name of the columns of two or more tables, based on which a condition will perform.</p>\n<p><strong>Syntax:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">FROM table1\njoin_type table2\n[ON (join_condition)]</code></pre></div>\n<p><strong>Parameters:</strong></p>\n<p><a href=\"https://www.notion.so/5522c3e6d5d0443eb870f7a34f60c7ff\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p><strong>Pictorial Presentation of SQL Joins:</strong></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*2DcsnJXF_FOGhUtL.gif\" class=\"graf-image\" />\n</figure>**Example:**\n<p><strong>Sample table: company</strong></p>\n<p><strong>Sample table: foods</strong></p>\n<p>To join two tables 'company' and 'foods', the following SQL statement can be used :</p>\n<p><strong>SQL Code:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SELECT  company.company_id,company.company_name,\nfoods.item_id,foods.item_name\nFROM company,foods;</code></pre></div>\n<p>Copy</p>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">COMPAN COMPANY_NAME              ITEM_ID  ITEM_NAME\n------ ------------------------- -------- ---------------\n18     Order All                 1        Chex Mix\n18     Order All                 6        Cheez-It\n18     Order All                 2        BN Biscuit\n18     Order All                 3        Mighty Munch\n18     Order All                 4        Pot Rice\n18     Order All                 5        Jaffa Cakes\n18     Order All                 7        Salt n Shake\n15     Jack Hill Ltd             1        Chex Mix\n15     Jack Hill Ltd             6        Cheez-It\n15     Jack Hill Ltd             2        BN Biscuit\n15     Jack Hill Ltd             3        Mighty Munch\n15     Jack Hill Ltd             4        Pot Rice\n15     Jack Hill Ltd             5        Jaffa Cakes\n15     Jack Hill Ltd             7        Salt n Shake\n16     Akas Foods                1        Chex Mix\n16     Akas Foods                6        Cheez-It\n16     Akas Foods                2        BN Biscuit\n16     Akas Foods                3        Mighty Munch\n16     Akas Foods                4        Pot Rice\n16     Akas Foods                5        Jaffa Cakes\n16     Akas Foods                7        Salt n Shake\n.........\n.........\n.........</code></pre></div>\n<h3>Overview</h3>\n<p>While we can write database code directly into our endpoints, best practices dictate that all database logic exists in separate, modular methods. These files containing database access helpers are often called <strong>models</strong></p>\n<h3>Follow Along</h3>\n<p>To handle CRUD operations for a single resource, we would want to create a <strong>model</strong> (or database access file) containing the following methods:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function find() {\n}\n\nfunction findById(id) {\n}\n\nfunction add(user) {\n}\n\nfunction update(changes, id) {\n}\n\nfunction remove(id) {\n}</code></pre></div>\n<p>Each of these functions would use Knex logic to perform the necessary database operation.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function find() {\n  return db('users');\n}</code></pre></div>\n<p>For each method, we can choose what value to return. For example, we may prefer <code class=\"language-text\">findById()</code> to return a single <code class=\"language-text\">user</code> object rather than an array.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function findById(id) {\n// first() returns the first entry in the db matching the query\n  return db('users').where({ id }).first();\n}</code></pre></div>\n<p>We can also use existing methods like <code class=\"language-text\">findById()</code> to help <code class=\"language-text\">add()</code> return the new user (instead of just the id).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function add(user) {\n  db('users').insert(user)\n    .then(ids => {\n      return findById(ids[0]);\n    });\n}</code></pre></div>\n<p>Once all methods are written as desired, we can export them like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  find,\n  findById,\n  add,\n  update,\n  delete,\n}</code></pre></div>\n<p>…and use the helpers in our endpoints</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const User = require('./user-model.js');\n\nrouter.get('/', (req, res) => {\n  User.find()\n    .then(users => {\n      res.json(users);\n    })\n    .catch(&amp;nbsp;err => {});\n});</code></pre></div>\n<p>There should no be <code class=\"language-text\">knex</code> code in the endpoints themselves.</p>\n<hr>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>###\n<p><code class=\"language-text\">Normalization</code> is the process of designing or refactoring database tables for maximum consistency and minimum redundancy.</p>\n<p>With objects, we're used to <em>denormalized</em> data, stored with ease of use and speed in mind. Non-normalized tables are considered ineffective in relational databases.</p>\n<h3></h3>\n<p><strong>Data normalization</strong> is a deep topic in database design. To begin thinking about it, we'll explore a few basic guidelines and some data examples that violate these rules.</p>\n<h3>Normalization Guidelines</h3>\n<blockquote>\n<p>Each record has a primary key.</p>\n</blockquote>\n<blockquote>\n<p>No fields are repeated.</p>\n</blockquote>\n<blockquote>\n<p>All fields relate directly to the key data.</p>\n</blockquote>\n<blockquote>\n<p>Each field entry contains a single data point.</p>\n</blockquote>\n<blockquote>\n<p>There are no redundant entries.</p>\n</blockquote>\n<h3>Denormalized Data</h3>\n<p><a href=\"https://www.notion.so/19a01f68a659470fb85bbe6906fb4bad\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>This table has two issues. There is no proper id field (as multiple farms may have the same name), and multiple fields are representing the same type of data: animals.</p>\n<p><a href=\"https://www.notion.so/075ad6dd99ac48698625d7b56ca67bef\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>While we have now eliminated the first two issues, we now have multiple entries in one field, separated by commas. This isn't good either, as its another example of denormalization. There is no \"array\" data type in a relational database, so each field must contain only one data point.</p>\n<p><a href=\"https://www.notion.so/375a15b0cb3f444a8698cd6cb3a08fe0\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>Now we've solved the multiple fields issue, but we created repeating data (the farm field), which is also an example of denormalization. As well, we can see that if we were tracking additional ranch information (such as annual revenue), that field is only vaguely related to the animal information.</p>\n<p><strong>When these issues begin arising in your schema design, it means that you should separate information into two or more tables.</strong></p>\n<h3>Anomalies</h3>\n<p>Obeying the above guidelines prevent <strong>anomalies</strong> in your database when inserting, updating, or deleting. For example, imagine if the revenue of Beech Ranch changed. With our denormalized schema, it may get updated in some records but not others:</p>\n<p><a href=\"https://www.notion.so/e05f5b2e8ff141798adc6f188f56f31e\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>Similarly, if Beech Ranch shut down, there would be three (if not more) records that needed to be deleted to remove a single farm.</p>\n<p>Thus a denormalized table opens the door for contradictory, confusing, and unusable data.</p>\n<h3></h3>\n<p>What issues does the following table have?</p>\n<p><a href=\"https://www.notion.so/2793e8f6b70a47f48f9208779366e69e\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<h3></h3>\n<p>There are three types of relationships:</p>\n<blockquote>\n<p>One to one.</p>\n</blockquote>\n<blockquote>\n<p>One to many.</p>\n</blockquote>\n<blockquote>\n<p>Many to many.</p>\n</blockquote>\n<p>Determining how data is related can provide a set of guidelines for table representation and guides the use of foreign keys to connect said tables.</p>\n<h3></h3>\n<h3>One to One Relationships</h3>\n<p>Imagine we are storing the financial projections for a series of farms.</p>\n<p>We may wish to attach fields like farm name, address, description, projected revenue, and projected expenses. We could divide these fields into two categories: information related to the farm directly (name, address, description) and information related to the financial projections (revenue, expenses).</p>\n<p>We would say that <code class=\"language-text\">farms</code> and <code class=\"language-text\">projections</code> have a <strong>one-to-one</strong> relationship. This is to say that every farm has exactly one projection, and every project corresponds to exactly one farm.</p>\n<p>This data can be represented in two tables: <code class=\"language-text\">farms</code> and <code class=\"language-text\">projections</code></p>\n<p><a href=\"https://www.notion.so/944e594f3464473ea06383bfdea13265\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/de32fcf6760e45f284707274433fee92\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>The <code class=\"language-text\">farm_id</code> is the foreign key that links <code class=\"language-text\">farms</code> and <code class=\"language-text\">projections</code> together.</p>\n<p>Notes about one-to-one relationships:</p>\n<ul>\n<li><span id=\"198d\">The foreign key should always have a <code class=\"language-text\">unique</code> constraint to prevent duplicate entries. In the example above, we wouldn't want to allow multiple projections records for one farm.</span></li>\n<li><span id=\"25c6\">The foreign key can be in either table. For example, we may have had a <code class=\"language-text\">projection_id</code> in the <code class=\"language-text\">farms</code> table instead. A good rule of thumb is to put the foreign key in whichever table is more auxiliary to the other.</span></li>\n<li><span id=\"960d\">You can represent one-to-one data in a single table <em>without</em> creating anomalies. However, it is sometimes prudent to use two tables as shown above to keep separate concerns in separate tables.</span></li>\n</ul>\n<h3>One to Many Relationships</h3>\n<p>Now imagine, we are storing the full-time ranchers employed at each farm. In this case, each rancher would only work at one farm however, each farm may have multiple ranchers.</p>\n<p>This is called a <strong>one-to-many</strong> relationship.</p>\n<p>This is the most common type of relationship between entities. Some other examples:</p>\n<ul>\n<li><span id=\"5627\">One <code class=\"language-text\">customer</code> can have many <code class=\"language-text\">orders</code>.</span></li>\n<li><span id=\"cc42\">One <code class=\"language-text\">user</code> can have many <code class=\"language-text\">posts</code>.</span></li>\n<li><span id=\"dae3\">One <code class=\"language-text\">post</code> can have many <code class=\"language-text\">comments</code>.</span></li>\n</ul>\n<p>Manage this type of relationship by adding a foreign key on the \"many\" table of the relationship that points to the primary key on the \"one\" table. Consider the <code class=\"language-text\">farms</code> and <code class=\"language-text\">ranchers</code> tables.</p>\n<p><a href=\"https://www.notion.so/7dfd2e69c9804a01845f2e9b716a5ac2\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/c95f3d418db94ab4b4532eeba0e4f918\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>In a many-to-many relationship, the foreign key (in this case <code class=\"language-text\">farm_id</code>) should <em>not</em> be unique.</p>\n<h3>Many to Many Relationships</h3>\n<p>If we want to track animals on a farm as well, we must explore the <strong>many-to-many</strong> relationship. A farm has multiple animals, and multiple of each type of animal is present at multiple different farms.</p>\n<p>Some other examples:</p>\n<ul>\n<li><span id=\"d757\">an <code class=\"language-text\">order</code> can have many <code class=\"language-text\">products</code> and the same <code class=\"language-text\">product</code> will appear in many <code class=\"language-text\">orders</code>.</span></li>\n<li><span id=\"0256\">a <code class=\"language-text\">book</code> can have more than one <code class=\"language-text\">author</code>, and an <code class=\"language-text\">author</code> can write more than one <code class=\"language-text\">book</code>.</span></li>\n</ul>\n<p>To model this relationship, we need to introduce an <strong>intermediary table</strong> that holds foreign keys that reference the primary key on the related tables. We now have a <code class=\"language-text\">farms</code>, <code class=\"language-text\">animals</code>, and <code class=\"language-text\">farm_animals</code> table.</p>\n<p><a href=\"https://www.notion.so/3269812d7c2a4578b1a9f6bc27e485b1\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/c2642c7f632f489cb1b9639c80b8400d\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p><a href=\"https://www.notion.so/d0b0042c5e104edd9ed55e122af89084\" class=\"markup--anchor markup--p-anchor\">Untitled</a></p>\n<p>While each foreign key on the intermediary table is not unique, the combinations of keys should be unique.</p>\n<h3></h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*9xpwm_56lgvHkFTKsmoMqg.gif\" class=\"graf-image\" />\n</figure>The Knex query builder library also allows us to create multi-table schemas include foreign keys. However, there are a few extra things to keep in mind when designing a multi-table schema, such as using the correct order when creating tables, dropping tables, seeding data, and removing data.\n<p>We have to consider the way that <code class=\"language-text\">delete</code> and <code class=\"language-text\">updates</code> through our API will impact related data.</p>\n<h3></h3>\n<h3>Foreign Key Setup</h3>\n<p>In Knex, foreign key restrictions don't automatically work. Whenever using foreign keys in your schema, add the following code to your <code class=\"language-text\">knexfile</code>. This will prevent users from entering bad data into a foreign key column.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">development: {\n  client: 'sqlite3',\n  useNullAsDefault: true,\n  connection: {\n    filename: './data/database.db3',\n  },\n  // needed when using foreign keys\n  pool: {\n    afterCreate: (conn, done) => {\n      // runs after a connection is made to the sqlite engine\n      conn.run('PRAGMA foreign_keys = ON', done); // turn on FK enforcement\n    },\n  },\n},</code></pre></div>\n<h3>Migrations</h3>\n<p>Let's look at how we might track our <code class=\"language-text\">farms</code> and <code class=\"language-text\">ranchers</code> using Knex. In our migration file's <code class=\"language-text\">up</code> function, we would want to create two tables:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">exports.up = function(knex, Promise) {\n  return knex.schema\n    .createTable('farms', tbl => {\n      tbl.increments();\n      tbl.string('farm_name', 128)\n        .notNullable();\n    })\n    // we can chain together createTable\n    .createTable('ranchers', tbl => {\n      tbl.increments();\n      tbl.string('rancher_name', 128);\n      tbl.integer('farm_id')\n        // forces integer to be positive\n        .unsigned()\n        .notNullable()\n        .references('id')\n        // this table must exist already\n        .inTable('farms')\n    })\n};</code></pre></div>\n<p>Note that the foreign key can only be created <em>after</em> the reference table.</p>\n<p>In the down function, the opposite is true. We always want to drop a table with a foreign key <em>before</em> dropping the table it references.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">exports.down = function(knex, Promise) {\n  // drop in the opposite order\n  return knex.schema\n    .dropTableIfExists('ranchers')\n    .dropTableIfExists('farms')\n};</code></pre></div>\n<p>In the case of a many-to-many relationship, the syntax for creating an intermediary table is identical, except for one additional piece. We need a way to make sure our combination of foreign keys is unique.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.createTable('farm_animals', tbl => {\n  tbl.integer('farm_id')\n    .unsigned()\n    .notNullable()\n    .references('id')\n    // this table must exist already\n    .inTable('farms')\n  tbl.integer('animal_id')\n    .unsigned()\n    .notNullable()\n    .references('id')\n    // this table must exist already\n    .inTable('animals')\n\n// the combination of the two keys becomes our primary key\n  // will enforce unique combinations of ids\n  tbl.primary(['farm_id', 'animal_id']);\n});</code></pre></div>\n<h3>Seeds</h3>\n<p>Order is also a concern when seeding. We want to create seeds in the <strong>same</strong> order we created our tables. In other words, don't create a seed with a foreign key, until that reference record exists.</p>\n<p>In our example, make sure to write the <code class=\"language-text\">01-farms</code> seed file and then the <code class=\"language-text\">02-ranchers</code> seed file.</p>\n<p>However, we run into a problem with truncating our seeds, because we want to truncate <code class=\"language-text\">02-ranchers</code> <em>before</em> <code class=\"language-text\">01-farms</code>. A library called <code class=\"language-text\">knex-cleaner</code> provides an easy solution for us.</p>\n<p>Run <code class=\"language-text\">knex seed:make 00-cleanup</code> and <code class=\"language-text\">npm install knex-cleaner</code>. Inside the cleanup seed, use the following code.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const cleaner = require('knex-cleaner');\n\nexports.seed = function(knex) {\n  return cleaner.clean(knex, {\n    mode: 'truncate', // resets ids\n    ignoreTables: ['knex_migrations', 'knex_migrations_lock'], // don't empty migration tables\n  });\n};</code></pre></div>\n<p>This removes all tables (excluding the two tables that track migrations) in the correct order before any seed files run.</p>\n<h3>Cascading</h3>\n<p>If a user attempt to delete a record that is referenced by another record (such as attempting to delete <code class=\"language-text\">Morton Ranch</code> when entries in our <code class=\"language-text\">ranchers</code> table reference that record), by default, the database will block the action. The same thing can happen when updating a record when a foreign key reference.</p>\n<p>If we want that to override this default, we can delete or update with <strong>cascade</strong>. With cascade, deleting a record also deletes all referencing records, we can set that up in our schema.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.createTable('ranchers', tbl => {\n    tbl.increments();\n    tbl.string('rancher_name', 128);\n    tbl.integer('farm_id')\n    .unsigned()\n    .notNullable()\n    .references('id')\n    .inTable('farms')\n    .onUpdate('CASCADE');\n    .onDelete('CASCADE')\n})</code></pre></div>"},{"url":"/docs/ds-algo/big-o/","relativePath":"docs/ds-algo/big-o.md","relativeDir":"docs/ds-algo","base":"big-o.md","name":"big-o","frontmatter":{"title":"Big-O Notation","weight":0,"excerpt":"Why is looking at runtime not a reliable method of calculating time complexity?","seo":{"title":"Big-O Notation","description":"A Quick Guide to Big-O Notation, Memoization, Tabulation, and Sorting Algorithms by Example","robots":[],"extra":[]},"template":"docs"},"html":"<h1>A Quick Guide to Big-O Notation, Memoization, Tabulation, and Sorting Algorithms by Example</h1>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*yjlSk3T9c2_14in1.png\" alt=\"image\"></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    frameborder=\"0\" width=\"100%\" height=\"500px\" src=\"https://replit.com/@bgoonz/Medium-article-comp-complex?lite=true\">\n</iframe>\n<br>\n<ul>\n<li>Why is looking at runtime not a reliable method of calculating time complexity?</li>\n<li>Not all computers are made equal( some may be stronger and therefore boost our runtime speed )</li>\n<li>How many background processes ran concurrently with our program that was being tested?</li>\n<li>We also need to ask if our code remains performant if we increase the size of the input.</li>\n<li>\n<p>The real question we need to answering is: <code class=\"language-text\">How does our performance scale?</code>.</p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/bgoonz/embed/preview/RwKYRoo?height=600&amp;slug-hash=RwKYRoo&amp;default-tabs=js,result&amp;host=https://codepen.io\" width=\"100%\" height=\"500px\"  frameborder=\"0\" scrolling=\"no\">\n</iframe>\n<br>\n</li>\n</ul>\n<h3>big 'O' notation</h3>\n<ul>\n<li>Big O Notation is a tool for describing the efficiency of algorithms with respect to the size of the input arguments.</li>\n<li>Since we use mathematical functions in Big-O, there are a few big picture ideas that we'll want to keep in mind:</li>\n<li>The function should be defined by the size of the input.</li>\n<li><code class=\"language-text\">Smaller</code> Big O is better (lower time complexity)</li>\n<li>Big O is used to describe the worst case scenario.</li>\n<li>Big O is simplified to show only its most dominant mathematical term.</li>\n</ul>\n<h3>Simplifying Math Terms</h3>\n<ul>\n<li>We can use the following rules to simplify the our Big O functions:</li>\n<li><code class=\"language-text\">Simplify Products</code> : If the function is a product of many terms, we drop the terms that don't depend on n.</li>\n<li><code class=\"language-text\">Simplify Sums</code> : If the function is a sum of many terms, we drop the non-dominant terms.</li>\n<li><code class=\"language-text\">n</code> : size of the input</li>\n<li><code class=\"language-text\">T(f)</code> : unsimplified math function</li>\n<li><code class=\"language-text\">O(f)</code> : simplified math function.</li>\n</ul>\n<p><code class=\"language-text\">Putting it all together</code></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/1*TT8uuv1x3nmGUw5rvtoZ8A.png\" alt=\"image\"></p>\n<ul>\n<li>First we apply the product rule to drop all constants.</li>\n<li>Then we apply the sum rule to select the single most dominant term.</li>\n</ul>\n<hr>\n<h3>Complexity Classes</h3>\n<p>Common Complexity Classes</p>\n<h4>There are 7 major classes in Time Complexity</h4>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/1*6zKhmJoHkvDbrd8jfUDf3A.png\" alt=\"image\"></p>\n<h4><code class=\"language-text\">O(1) Constant</code></h4>\n<blockquote>\n<p><strong>The algorithm takes roughly the same number of steps for any input size.</strong></p>\n</blockquote>\n<h4><code class=\"language-text\">O(log(n)) Logarithmic</code></h4>\n<blockquote>\n<p><strong>In most cases our hidden base of Logarithmic time is 2, log complexity algorithm's will typically display 'halving' the size of the input (like binary search!)</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// O(log(n))</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logarithmic1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">logarithmic1</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// O(log(n))</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logarithmic2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> n<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        i <span class=\"token operator\">/=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/a1e6dec81f0639818db7f9a8e76b3992/raw/ee8d492025cc76e76c91cb15c3c2ec29b3ffb616/logorithmic.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/a1e6dec81f0639818db7f9a8e76b3992#file-logorithmic-js\">logorithmic.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h4><code class=\"language-text\">O(n) Linear</code></h4>\n<blockquote>\n<p><strong>Linear algorithm's will access each item of the input \"once\".</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// O(n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// O(n), where n is the length of the array</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// O(n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear3</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">linear3</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/cc953ba2bd6e1d6f524a6d8b297aad5b/raw/f3b470ce20d77e52bf25d0749149c5a724099ff2/linear.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/cc953ba2bd6e1d6f524a6d8b297aad5b#file-linear-js\">linear.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h3><code class=\"language-text\">O(nlog(n)) Log Linear Time</code></h3>\n<blockquote>\n<p><strong>Combination of linear and logarithmic behavior, we will see features from both classes.</strong></p>\n</blockquote>\n<blockquote>\n<p>Algorithm's that are log-linear will use** both recursion AND iteration.**</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// O(n * log(n))</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/e9bd6337c17f1623a4da088574ed0d8e/raw/7680dadbfd6dd058f4ecde2085d160019b782282/loglin.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/e9bd6337c17f1623a4da088574ed0d8e#file-loglin-js\">loglin.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h3><code class=\"language-text\">O(nc) Polynomial</code></h3>\n<blockquote>\n<p><strong>C is a fixed constant.</strong>\n`</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// O(n^2)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">quadratic</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//Example of Quadratic and Cubic runtime.</span>\n<span class=\"token comment\">// O(n^3)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">cubic</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> k <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> k <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> k<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/3e6096e66bac80b962435b7d873cdbe9/raw/255fae18df5ce42945ba19f9b83f122b83a4738b/poly.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/3e6096e66bac80b962435b7d873cdbe9#file-poly-js\">poly.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h3><code class=\"language-text\">O(c^n) Exponential</code></h3>\n<blockquote>\n<p><strong>C is now the number of recursive calls made in each stack frame.</strong></p>\n</blockquote>\n<blockquote>\n<p><strong>Algorithm's with exponential time are VERY SLOW.</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// O(2^n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">exponential2n</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">exponential_2n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">exponential_2n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// O(3^n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">exponential_3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">exponential_3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">exponential_3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/5dec7e3736d7b5e28a5f1c85b5b50705/raw/68270be48d6a30bb5d889ca83ee6810813018601/exponential.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/5dec7e3736d7b5e28a5f1c85b5b50705#file-exponential-js\">exponential.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<hr>\n<h3>Memoization</h3>\n<ul>\n<li>Memoization : a design pattern used to reduce the overall number of calculations that can occur in algorithms that use recursive strategies to solve.</li>\n<li>MZ stores the results of the sub-problems in some other data structure, so that we can avoid duplicate calculations and only 'solve' each problem once.</li>\n<li>Two features that comprise memoization:</li>\n<li>FUNCTION MUST BE RECURSIVE.</li>\n<li>Our additional Data Structure is usually an object (we refer to it as our memo... or sometimes cache!)</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/1*4U79jBMjU2wKE_tyYcD_3A.png\" alt=\"image\"></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/1*Qh42KZgcCxmVt6WrTasCVw.png\" alt=\"image\"></p>\n<h3>Memoizing Factorial</h3>\n<p>Our memo object is <em>mapping</em> out our arguments of factorial to it's return value.</p>\n<ul>\n<li>Keep in mind we didn't improve the speed of our algorithm.</li>\n</ul>\n<h3>Memoizing Fibonacci</h3>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*2XaPj7UGKZYFjYhb\" alt=\"image\"></p>\n<ul>\n<li>Our time complexity for Fibonacci goes from O(2^n) to O(n) after applying memoization.</li>\n</ul>\n<h3>The Memoization Formula</h3>\n<blockquote>\n<p><em>Rules:</em></p>\n</blockquote>\n<ol>\n<li><em>Write the unoptimized brute force recursion (make sure it works);</em></li>\n<li><em>Add memo object as an additional argument .</em></li>\n<li><em>Add a base case condition that returns the stored value if the function's argument is in the memo.</em></li>\n<li><em>Before returning the result of the recursive case, store it in the memo as a value and make the function's argument it's key.</em></li>\n</ol>\n<h4>Things to remember</h4>\n<ol>\n<li><em>When solving DP problems with Memoization, it is helpful to draw out the visual tree first.</em></li>\n<li><em>When you notice duplicate sub-tree's that means we can memoize.</em></li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> memo <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token keyword\">in</span> memo<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span> <span class=\"token operator\">||</span> n <span class=\"token operator\">===</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 8</span>\n<span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span><span class=\"token number\">50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 12586269025 |</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/c15feb228a51a3543625009c8fd0b6de/raw/2c3d2998221f0b375bcece6dab8916c598ff9e03/fastfib.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/c15feb228a51a3543625009c8fd0b6de#file-fastfib-js\">fastfib.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<hr>\n<h3>Tabulation</h3>\n<h4>Tabulation Strategy</h4>\n<blockquote>\n<p>Use When:</p>\n</blockquote>\n<ul>\n<li><strong>The function is iterative and not recursive.</strong></li>\n<li><em>The accompanying DS is usually an array.</em></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> mostRecentCalcs <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> mostRecentCalcs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>secondLast<span class=\"token punctuation\">,</span> last<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> mostRecentCalcs<span class=\"token punctuation\">;</span>\n   mostRecentCalcs <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>last<span class=\"token punctuation\">,</span> secondLast <span class=\"token operator\">+</span> last<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> mostRecentCalcs<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/a57bf449f5a8b16eedd1aa9fd71707e2/raw/9c6cff4bb301bc4f9a87ebb9c0399a8c56ccb083/tabfib.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/a57bf449f5a8b16eedd1aa9fd71707e2#file-tabfib-js\">tabfib.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h4>Steps for tabulation</h4>\n<ul>\n<li><em>Create a table array based off the size of the input.</em></li>\n<li><em>Initialize some values in the table to 'answer' the trivially small subproblem.</em></li>\n<li><em>Iterate through the array and fill in the remaining entries.</em></li>\n<li><em>Your final answer is usually the last entry in the table.</em></li>\n</ul>\n<hr>\n<h3>Memo and Tab Demo with Fibonacci</h3>\n<blockquote>\n<p><em>Normal Recursive Fibonacci</em></p>\n</blockquote>\n<p>function fibonacci(n) {<br>\nif (n &#x3C;= 2) return 1;<br>\nreturn fibonacci(n - 1) + fibonacci(n - 2);<br>\n}</p>\n<blockquote>\n<p><em>Memoization Fibonacci 1</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">fibMemo</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> memo <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token number\">0</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token keyword\">in</span> memo<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">fibMemo</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fibMemo</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/504a9120ca40bbb4a246549937c43a12/raw/5cb9cd921642d16ca1c86231c2387646dfad8daa/fib-memo.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/504a9120ca40bbb4a246549937c43a12#file-fib-memo-js\">fib-memo.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<blockquote>\n<p><em>Memoization Fibonacci 2</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> memo</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   memo <span class=\"token operator\">=</span> memo <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/07d315d92b3458a8640cee31bce9c236/raw/3425643262eb8389ce6fe4366c4ca7803dce2968/memo-fib2.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/07d315d92b3458a8640cee31bce9c236#file-memo-fib2-js\">memo-fib2.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<blockquote>\n<p><em>Tabulated Fibonacci</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">tabFib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> table <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   table<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n   table<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   table<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   table<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> table<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> table<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> table<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/b1b1f7e259193ecdc432350b6199f2d3/raw/dbaa48acf583535b11204569b7a0054bef5fe72e/tabfib.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/b1b1f7e259193ecdc432350b6199f2d3#file-tabfib-js\">tabfib.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h3>Example of Linear Search</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">search</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> term</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> term<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> i<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/e98354b287ce2f80da4ab943399eb555/raw/fed7adac0a75d080573e20e62d64080c4880c867/linsearch.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/e98354b287ce2f80da4ab943399eb555#file-linsearch-js\">linsearch.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<ul>\n<li><em>Worst Case Scenario: The term does not even exist in the array.</em></li>\n<li><em>Meaning: If it doesn't exist then our for loop would run until the end therefore making our time complexity O(n).</em></li>\n</ul>\n<hr>\n<h3>Sorting Algorithms</h3>\n<h3>Bubble Sort</h3>\n<p><code class=\"language-text\">Time Complexity</code>: Quadratic O(n^2)</p>\n<ul>\n<li>The inner for-loop contributes to O(n), however in a worst case scenario the while loop will need to run n times before bringing all n elements to their final resting spot.</li>\n</ul>\n<p><code class=\"language-text\">Space Complexity</code>: O(1)</p>\n<ul>\n<li>Bubble Sort will always use the same amount of memory regardless of n.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*Ck9aeGY-d5tbz7dT\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">swap</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> idx1<span class=\"token punctuation\">,</span> idx2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token punctuation\">[</span>array<span class=\"token punctuation\">[</span>idx1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">[</span>idx2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>array<span class=\"token punctuation\">[</span>idx2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">[</span>idx1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">bubbleSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> swapped <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>swapped<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   swapped <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token function\">swap</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   swapped <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token comment\">//Alt SLN-------------------------------------------------</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">bubbleSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> sorted <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>sorted<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   sorted <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span>\n   sorted <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/e67e56bed7c5a20a54851867ba5efef6/raw/f0005f56a012a38607e194c89ff796aaad217788/bub2.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/e67e56bed7c5a20a54851867ba5efef6#file-bub2-js\">bub2.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<ul>\n<li>The first major sorting algorithm one learns in introductory programming courses.</li>\n<li>Gives an intro on how to convert unsorted data into sorted data.</li>\n</ul>\n<blockquote>\n<p>It's almost never used in production code because:</p>\n</blockquote>\n<ul>\n<li><em>It's not efficient</em></li>\n<li><em>It's not commonly used</em></li>\n<li><em>There is stigma attached to it</em></li>\n<li><code class=\"language-text\">*Bubbling Up*</code>_ : Term that infers that an item is in motion, moving in some direction, and has some final resting destination._</li>\n<li><em>Bubble sort, sorts an array of integers by bubbling the largest integer to the top.</em></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token comment\">// Bubble Sort</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">bubble</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> sorted <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> num1 <span class=\"token operator\">=</span> array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> num2 <span class=\"token operator\">=</span> array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>num1 <span class=\"token operator\">></span> num2<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   array<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> num1<span class=\"token punctuation\">;</span>\n   array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> num2<span class=\"token punctuation\">;</span>\n   sorted <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>sorted<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> <span class=\"token function\">bubble</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/fd4acc0c89033bd219ebf9d3ec40b053/raw/14b00dabe615cdfaf39dce21b99edf038c345d94/bub.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/fd4acc0c89033bd219ebf9d3ec40b053#file-bub-js\">bub.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">bubbleSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">items</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> length <span class=\"token operator\">=</span> items<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> length <span class=\"token operator\">-</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>items<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> items<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> tmp <span class=\"token operator\">=</span> items<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   items<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> items<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   items<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> tmp<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/80934783c628c70ac2a5a48119a82d54/raw/b99e87081b1f89fd363805bb3dee7195046b758d/bubble.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/80934783c628c70ac2a5a48119a82d54#file-bubble-js\">bubble.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<ul>\n<li><em>Worst Case &#x26; Best Case are always the same because it makes nested loops.</em></li>\n<li><em>Double for loops are polynomial time complexity or more specifically in this case Quadratic (Big O) of: O(n²)</em></li>\n</ul>\n<h3>Selection Sort</h3>\n<p><code class=\"language-text\">Time Complexity</code>: Quadratic O(n^2)</p>\n<ul>\n<li>Our outer loop will contribute O(n) while the inner loop will contribute O(n / 2) on average. Because our loops are nested we will get O(n²);</li>\n</ul>\n<p><code class=\"language-text\">Space Complexity</code>: O(1)</p>\n<ul>\n<li>Selection Sort will always use the same amount of memory regardless of n.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*AByxtBjFrPVVYmyu\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">swap</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> idx1<span class=\"token punctuation\">,</span> idx2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token punctuation\">[</span>array<span class=\"token punctuation\">[</span>idx1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">[</span>idx2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>array<span class=\"token punctuation\">[</span>idx2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> array<span class=\"token punctuation\">[</span>idx2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">selectionSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> lowest <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> list<span class=\"token punctuation\">[</span>lowest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   lowest <span class=\"token operator\">=</span> j<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>place <span class=\"token operator\">!==</span> i<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token function\">swap</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> lowest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token comment\">//Alt Solution----------------------------------------------------</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">selectionSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> lowest <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   lowest <span class=\"token operator\">=</span> j<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>lowest <span class=\"token operator\">!==</span> i<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> array<span class=\"token punctuation\">[</span>lowest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   array<span class=\"token punctuation\">[</span>lowest<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/4abc0fe0bf01599b0c4104b0ba633402/raw/2199dc275f3d5b7f6b56b103201fee492044aa0b/selectionsort.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/4abc0fe0bf01599b0c4104b0ba633402#file-selectionsort-js\">selectionsort.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<ul>\n<li>Selection sort organizes the smallest elements to the start of the array.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*GeYNxlRcbt2cf0rY\" alt=\"image\"></p>\n<blockquote>\n<p>Summary of how Selection Sort should work:</p>\n</blockquote>\n<ol>\n<li><em>Set MIN to location 0</em></li>\n<li><em>Search the minimum element in the list.</em></li>\n<li><em>Swap with value at location Min</em></li>\n<li><em>Increment Min to point to next element.</em></li>\n<li><em>Repeat until list is sorted.</em></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">let</span> <span class=\"token function-variable function\">selectionSort</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> len <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> min <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>min<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   min <span class=\"token operator\">=</span> j<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>min <span class=\"token operator\">!==</span> i<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> tmp <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>min<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   arr<span class=\"token punctuation\">[</span>min<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> tmp<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/61f130c8e0097572ed908fe2629bdee0/raw/84be7efce4a0362fe9f6e34738c61769159f26f4/selectsort.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/61f130c8e0097572ed908fe2629bdee0#file-selectsort-js\">selectsort.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h3>Insertion Sort</h3>\n<p><code class=\"language-text\">Time Complexity</code>: Quadratic O(n^2)</p>\n<ul>\n<li>Our outer loop will contribute O(n) while the inner loop will contribute O(n / 2) on average. Because our loops are nested we will get O(n²);</li>\n</ul>\n<p><code class=\"language-text\">Space Complexity</code>: O(n)</p>\n<ul>\n<li>Because we are creating a subArray for each element in the original input, our Space Comlexity becomes linear.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*gbNU6wrszGPrfAZG\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">insertionSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> value <span class=\"token operator\">=</span> list<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> hole <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>hole <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> list<span class=\"token punctuation\">[</span>hole <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   list<span class=\"token punctuation\">[</span>hole<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> list<span class=\"token punctuation\">[</span>hole <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   hole<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   list<span class=\"token punctuation\">[</span>hole<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token comment\">//Alt Solution--------------------------------------------</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">insertionSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> current <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>j <span class=\"token operator\">></span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">&amp;&amp;</span> current <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   j<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> current<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/a9f4b8596c7546ac92746db659186d8c/raw/d8abcdb6ccc32e53120ec3a97a397cf4a032e225/insertionsort.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/a9f4b8596c7546ac92746db659186d8c#file-insertionsort-js\">insertionsort.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h3>Merge Sort</h3>\n<p><code class=\"language-text\">Time Complexity</code>: Log Linear O(nlog(n))</p>\n<ul>\n<li>Since our array gets split in half every single time we contribute O(log(n)). The while loop contained in our helper merge function contributes O(n) therefore our time complexity is O(nlog(n)); <code class=\"language-text\">Space Complexity</code>: O(n)</li>\n<li>We are linear O(n) time because we are creating subArrays.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*GeU8YwwCoK8GiSTD\" alt=\"image\"></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*IxqGb72XDVDeeiMl\" alt=\"image\"></p>\n<h3>Example of Merge Sort</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">leftArray<span class=\"token punctuation\">,</span> rightArray</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">const</span> sorted <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>letArray<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> rightArray<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">const</span> leftItem <span class=\"token operator\">=</span> leftArray<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">const</span> rightItem <span class=\"token operator\">=</span> rightArray<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>leftItem <span class=\"token operator\">></span> rightItem<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   sorted<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>rightItem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   rightArray<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n   sorted<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>leftItem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   leftArray<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>leftArray<span class=\"token punctuation\">.</span>length <span class=\"token operator\">!==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">const</span> value <span class=\"token operator\">=</span> leftArray<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   sorted<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>rightArray<span class=\"token punctuation\">.</span>length <span class=\"token operator\">!==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">const</span> value <span class=\"token operator\">=</span> rightArray<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   sorted<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> sorted<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">const</span> length <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>length <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">const</span> middleIndex <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">ceil</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">const</span> leftArray <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> middleIndex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">const</span> rightArray <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>middleIndex<span class=\"token punctuation\">,</span> length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   leftArray <span class=\"token operator\">=</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span>leftArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   rightArray <span class=\"token operator\">=</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span>rightArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">return</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span>leftArray<span class=\"token punctuation\">,</span> rightArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/18fbb7edc9f5c4820ccfcecacf3c5e48/raw/9e9157edcd1c4c2a795666eeff038bac405a9ff6/mergesort.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/18fbb7edc9f5c4820ccfcecacf3c5e48#file-mergesort-js\">mergesort.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr1<span class=\"token punctuation\">,</span> arr2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>arr1<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> arr2<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr1<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> arr2<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr1<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n   result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr2<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>result<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>arr1<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>arr2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">const</span> mid <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">const</span> left <span class=\"token operator\">=</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> mid<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">const</span> right <span class=\"token operator\">=</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>mid<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">return</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/cbb533137a7f957d3bc4077395c1ff64/raw/8e1b1d82bcc6ef7a8350632740ad1bf38e660ec4/merge2.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/cbb533137a7f957d3bc4077395c1ff64#file-merge2-js\">merge2.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*HMCR--9niDt5zY6M\" alt=\"image\"></p>\n<ul>\n<li><strong>Merge sort is O(nlog(n)) time.</strong></li>\n<li><em>We need a function for merging and a function for sorting.</em></li>\n</ul>\n<blockquote>\n<p>Steps:</p>\n</blockquote>\n<ol>\n<li><em>If there is only one element in the list, it is already sorted; return the array.</em></li>\n<li><em>Otherwise, divide the list recursively into two halves until it can no longer be divided.</em></li>\n<li><em>Merge the smallest lists into new list in a sorted order.</em></li>\n</ol>\n<h3>Quick Sort</h3>\n<p><code class=\"language-text\">Time Complexity</code>: Quadratic O(n^2)</p>\n<ul>\n<li>Even though the average time complexity O(nLog(n)), the worst case scenario is always quadratic.</li>\n</ul>\n<p><code class=\"language-text\">Space Complexity</code>: O(n)</p>\n<ul>\n<li>Our space complexity is linear O(n) because of the partition arrays we create.</li>\n<li>QS is another Divide and Conquer strategy.</li>\n<li>Some key ideas to keep in mind:</li>\n<li>It is easy to sort elements of an array relative to a particular target value.</li>\n<li>An array of 0 or 1 elements is already trivially sorted.</li>\n</ul>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*WLl_HpdBGXYx284T\" alt=\"image\"></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*-LyHJXGPTYsWLDZf\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> array<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> pivot <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> left <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> x <span class=\"token operator\">&lt;</span> pivot<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> right <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> x <span class=\"token operator\">>=</span> pivot<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> sortedLeft <span class=\"token operator\">=</span> <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> sortedRight <span class=\"token operator\">=</span> <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>sortedLeft<span class=\"token punctuation\">,</span> pivot<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>sortedRight<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/24bcbc5248a8c4e1671945e9512da57e/raw/3a1022625e327a8f4ce2da191179532124a0fb2a/quicksort.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/24bcbc5248a8c4e1671945e9512da57e#file-quicksort-js\">quicksort.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h3>Binary Search</h3>\n<p><code class=\"language-text\">Time Complexity</code>: Log Time O(log(n))</p>\n<p><code class=\"language-text\">Space Complexity</code>: O(1)</p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/0*-naVYGTXzE2Yoali\" alt=\"image\"></p>\n<blockquote>\n<p><em>Recursive Solution</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> target</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> midPt <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">[</span>midPt<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> target<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">[</span>midPt<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> target<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> mid<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span>list<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>midPt <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/c82c00a4bcba4b69b7d326d6cad3ac8c/raw/860f27bc6288ec672055b2d1becf3079b36486de/recur-bin-search.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/c82c00a4bcba4b69b7d326d6cad3ac8c#file-recur-bin-search-js\">recur-bin-search.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<blockquote>\n<p><em>Min Max Solution</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array<span class=\"token punctuation\">,</span> target</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> end <span class=\"token operator\">=</span> array<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>start <span class=\"token operator\">&lt;=</span> end<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> midpoint <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>start <span class=\"token operator\">+</span> end<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">===</span> array<span class=\"token punctuation\">[</span>midpoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> midpoint<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">></span> array<span class=\"token punctuation\">[</span>midpoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   start <span class=\"token operator\">=</span> midpoint <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">[</span>midpoint<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   end <span class=\"token operator\">=</span> midpoint <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/eb8d1e1684db15cc2c8af28e13f38751/raw/25f8dd3250bf27dff4215f23e5f693b4ab54ebb7/minmaxbinsearch.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/eb8d1e1684db15cc2c8af28e13f38751#file-minmaxbinsearch-js\">minmaxbinsearch.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">function</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> end</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>start <span class=\"token operator\">></span> end<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> mid <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>start <span class=\"token operator\">+</span> end<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>mid<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> x<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>mid<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> x<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> mid <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">return</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">,</span> mid <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token punctuation\">}</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/bc3f576b9795ccef12a108e36f9f820a/raw/341aedf69e77cde5a7ca8de3d80c4422ce0185b1/binsearch.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/bc3f576b9795ccef12a108e36f9f820a#file-binsearch-js\">binsearch.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<ul>\n<li><em>Must be conducted on a sorted array.</em></li>\n<li><em>Binary search is logarithmic time, not exponential b/c n is cut down by two, not growing.</em></li>\n<li><em>Binary Search is part of Divide and Conquer.</em></li>\n</ul>\n<h3>Insertion Sort</h3>\n<ul>\n<li><strong>Works by building a larger and larger sorted region at the left-most end of the array.</strong></li>\n</ul>\n<blockquote>\n<p>Steps:</p>\n</blockquote>\n<ol>\n<li><em>If it is the first element, and it is already sorted; return 1.</em></li>\n<li><em>Pick next element.</em></li>\n<li><em>Compare with all elements in the sorted sub list</em></li>\n<li><em>Shift all the elements in the sorted sub list that is greater than the value to be sorted.</em></li>\n<li><em>Insert the value</em></li>\n<li><em>Repeat until list is sorted.</em></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n   <span class=\"token keyword\">let</span> <span class=\"token function-variable function\">insertionSort</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">inputArr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> length <span class=\"token operator\">=</span> inputArr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token keyword\">let</span> key <span class=\"token operator\">=</span> inputArr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>j <span class=\"token operator\">>=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> inputArr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   inputArr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> inputArr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n   j <span class=\"token operator\">=</span> j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   inputArr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> key<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n   <span class=\"token keyword\">return</span> inputArr<span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token operator\">|</span></code></pre></div>\n<p><a href=\"https://gist.github.com/eengineergz/ffead1de0836c4bcc6445780a604f617/raw/1838b4ddb05f78930479f71a6d64e239b71f63c1/insertionsort.js\">view raw</a><a href=\"https://gist.github.com/eengineergz/ffead1de0836c4bcc6445780a604f617#file-insertionsort-js\">insertionsort.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<h3>If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content:</h3>\n<p><a href=\"https://gist.github.com/bgoonz\" title=\"https://gist.github.com/bgoonz\"><strong>bgoonz's gists</strong><br>\n<em>Instantly share code, notes, and snippets. Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python |...</em>gist.github.com</a><a href=\"https://gist.github.com/bgoonz\"></a></p>\n<p><a href=\"https://github.com/bgoonz\" title=\"https://github.com/bgoonz\"><strong>bgoonz --- Overview</strong><br>\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize...</em>github.com</a><a href=\"https://github.com/bgoonz\"></a></p>\n<h3>Or Checkout my personal Resource Site:</h3>\n<p><a href=\"https://bgoonz-blog.netlify.app/\" title=\"https://bgoonz-blog.netlify.app/\"><strong>Web-Dev-Hub</strong><br>\n<em>Memoization, Tabulation, and Sorting Algorithms by Example Why is looking at runtime not a reliable method of...</em>bgoonz-blog.netlify.app</a><a href=\"https://bgoonz-blog.netlify.app/\"></a></p>\n<p><img src=\"https://cdn-images-1.medium.com/max/800/1*VCmj_H9AHs41oC9Yx1hZFQ.png\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**************************************BIG-O***********************************/</span>\n<span class=\"token comment\">/***********************Common Algorithms for Analysis********************/</span>\n<span class=\"token comment\">//mdn Object;</span>\n<span class=\"token comment\">//-**************-recursive factorial:*********************/</span>\n<span class=\"token comment\">/* \n   Factorial: the product of a given positive integer multiplied by all lesser positive integers: \n   The quantity four factorial (4!) = 4 ⋅ 3 ⋅ 2 ⋅ 1 = 24. \n   Symbol:n!, where n is the given integer. \n   */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//* Base Case ... 1 * 1 = 1</span>\n    <span class=\"token keyword\">return</span> n <span class=\"token operator\">*</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//* n! = n * (n-1) * (n-2) * (n-3) * ... * 1</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//*5 * 4 * 3 * 2 * 1 = 120 &lt;----expected</span>\n<span class=\"token comment\">//console.log( \"factorial(5): \", factorial( 5 ) ); //- factorial(5): 120</span>\n<span class=\"token comment\">/* \n   Fibonacci numbers are the numbers such that every number in the series after the first two is the sum of the two preceding ones. \n   The series starts with 1, 1. Example -1, 1, 2, 3, 5, 8, 13, 21, 34, .... \n   Mathematical Expression: fib(n) = fib(n-1) + fib(n-2) \n   ! fib-tree-structure-diagram.png \n   https://miro.medium.com/max/700/1*svQ784qk1hvBE3iz7VGGgQ.jpeg \n   */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span> <span class=\"token operator\">||</span> n <span class=\"token operator\">===</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//console.log(\"fib(5): \", fibonacci(5)); //- fib(5): 5</span>\n<span class=\"token comment\">/* \n   the major differences between tabulation and memoization are: \n   1.) tabulation has to look through the entire search space; memoization does not \n   2.) tabulation requires careful ordering of the subproblems is; memoization doesn't care much about the order of recursive calls. \n   */</span>\n<span class=\"token keyword\">const</span> memo <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token number\">0</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n    <span class=\"token number\">1</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n    <span class=\"token number\">2</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">fib</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> n1 <span class=\"token operator\">=</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> n2 <span class=\"token operator\">=</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//console.log(\"fib(50): \", fib(20)); //- fib(50): 4181</span>\n<span class=\"token comment\">/******************End of Common Algorithms for Analysis*****************/</span>\n<span class=\"token comment\">/***********Comparing two functions that calculate the sum of all numbers from 1 up to n**********************/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">addUpTo</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> total <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//! Number of operations will grow with input n.</span>\n        total <span class=\"token operator\">+=</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> total<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">addUpTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//console.log(\"addUpTo( 4 ): \", addUpTo(4)); //- addUpTo( 4 ): 10</span>\n<span class=\"token comment\">//! Would be O(n) or Linear Time.</span>\n<span class=\"token comment\">//----------------------------------------------------------------</span>\n<span class=\"token comment\">/* \n   The infinite series whose terms are the natural numbers 1 + 2 + 3 + 4 + ⋯ is a divergent series. \n   The nth partial sum of the series is the triangular number( https://en.wikipedia.org/wiki/Triangular_number ) \n   addUpTo(n)=(n * (n + 1)) / 2 \n   https://wikimedia.org/api/rest_v1/media/math/render/svg/99476e25466549387c585cb4de44e90f6cbe4cf2 \n   */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">constantAddUpTo</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">constantAddUpTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//- constantAddUpTo(4): 10</span>\n<span class=\"token comment\">//console.log(\"constantAddUpTo(4): \", constantAddUpTo(4));</span>\n<span class=\"token comment\">//! Has three simple operations: 1 Multiplication 1 Addition 1 Division.</span>\n<span class=\"token comment\">//!(Regardless of n) Would be O(1) or Constant Time.</span>\n<span class=\"token comment\">/***********End of Comparing two functions that calculate the sum of all numbers from 1 up to n*******************/</span>\n<span class=\"token comment\">/* \n   !Simplifying Math Terms \n   We want our Big-O notation to describe the performance of our algorithm with respect to the input size and nothing else. \n   !Use the following rules to simplify our Big-O functions using the following rules: \n   1.) Simplify Products: if the function is a product of many terms, we drop the terms that don't depend on the size of the input. \n   2.) Simplify Sums: if the function is a sum of many terms, we keep the term with the largest growth rate and drop the other terms. \n   * n is the size of the input \n   * T(f) refers to an un-simplified mathematical function \n   * O(f) refers to the Big-O simplified mathematical function \n   * Simplifying a Product \n   If a function consists of a product of many factors, \n   !we drop the factors that don't depend on the size of the input, n. \n   The factors that we drop are called constant factors because their size remains consistent as we increase the size of the input. \n   examples-of-big-O-simplification.png \n   simplifying-a-sum.png \n   simp-examples.png \n   */</span>\n<span class=\"token comment\">/***********Comparing two functions with nested for loops*********************/</span>\n<span class=\"token comment\">// function countUpAndDown(n) {</span>\n<span class=\"token comment\">// console.log(\"going up!\");</span>\n<span class=\"token comment\">// for (let i = 0; i &lt; n; i++) {</span>\n<span class=\"token comment\">// console.log(i);</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// console.log(\"at the top, going down!\");</span>\n<span class=\"token comment\">// for (let j = n - 1; j >= 0; j--) {</span>\n<span class=\"token comment\">// console.log(j);</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// console.log(\"Back down, bye!\");</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// countUpAndDown(5);</span>\n<span class=\"token comment\">// console.log(\"countUpAndDown(5): \", countUpAndDown(5));</span>\n<span class=\"token comment\">/* \n   going up! \n   0 1 2 3 4 \n   at the top, going down! \n   4 3 2 1 0 \n   Back down, bye! \n   countUpAndDown(5): undefined //- because there was no return statment... only console.log \n   */</span>\n<span class=\"token comment\">//------------------------------------------------</span>\n<span class=\"token comment\">//!Both loops are O(n) but since we just want the big picture, O(n);</span>\n<span class=\"token comment\">//-----------------------------------------------</span>\n<span class=\"token comment\">// function printAllPairs(n) {</span>\n<span class=\"token comment\">// for (let i = 0; i &lt; n; i++) {</span>\n<span class=\"token comment\">// for (let j = 0; j &lt; n; j++) {</span>\n<span class=\"token comment\">// console.log(i, j);</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// printAllPairs(4);</span>\n<span class=\"token comment\">/* \n   0 0 0 1 0 2 0 3 1 0 1 1 1 2 1 3 2 0 2 1 2 2 2 3 3 0 3 1 3 2 3 3 \n   */</span>\n<span class=\"token comment\">//!Nested loops who's number of iterations depend on the size of the input are never a good thing when trying to write fast code.</span>\n<span class=\"token comment\">//!O(n^2) or Quadratic Time.</span>\n<span class=\"token comment\">/***********END of Comparing two functions with nested for loops**********************/</span>\n<span class=\"token comment\">/**************************Big-O-Operations**********************/</span>\n<span class=\"token comment\">//! Arithmetic Operations are Constant</span>\n<span class=\"token comment\">//! Variable assignment is constant</span>\n<span class=\"token comment\">//! Accessing elements in an array (by index) or by object (by key) is constant.</span>\n<span class=\"token comment\">//! In a loop, the complexity is the length of the loop times the complexity of whatever is inside of the loop.</span>\n<span class=\"token comment\">/**************************More Examples**********************/</span>\n<span class=\"token comment\">//---------------------logAtLeast5---------------------------------</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logAtLeast5</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(i);</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//! O(n) Linear Time</span>\n<span class=\"token comment\">//logAtLeast5(2);</span>\n<span class=\"token comment\">/* \n   1 2 3 4 5 \n   ---------------------------- \n   */</span>\n<span class=\"token comment\">//logAtLeast5(6);</span>\n<span class=\"token comment\">/* \n   ---------------------------- \n   1 2 3 4 5 6 \n   */</span>\n<span class=\"token comment\">//---------------------logAtMost5---------------------------------</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logAtMost5</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(i);</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">logAtMost5</span><span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//! O(1) Constant Time.</span>\n<span class=\"token comment\">/* \n   1 2 3 4 5 \n   */</span>\n<span class=\"token comment\">//***********************Big-O Complexity Classes*************************** */</span>\n<span class=\"token comment\">/* \n   //! O(1) Constant \n   The algorithm takes roughly the same number of steps for any input size. \n   */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">constant1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">constant1</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//constant1(5): 11</span>\n<span class=\"token comment\">//console.log(\"constant1(5): \", constant1(5));</span>\n<span class=\"token comment\">//--------</span>\n<span class=\"token comment\">//! O(1)</span>\n<span class=\"token comment\">//--------</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">constant2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//constant2(5);</span>\n<span class=\"token comment\">////console.log(\"constant2(5): \", constant2(5));</span>\n<span class=\"token comment\">//1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/* \n   O(log(n)) Logarithmic \n   In most cases our hidden base of Logarithmic time is 2, \n   log complexity algo's will typically display 'halving' the size of the input ?? \n   ? (like binary search!) \n   */</span>\n<span class=\"token comment\">// O(log(n))</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logarithmic1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'base case'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">logarithmic1</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//*Recursive call on **half** the input</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//! O(log(n))</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logarithmic2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> n<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        i <span class=\"token operator\">/=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">logarithmic1</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">////console.log(\"logarithmic1(5): \", logarithmic1(5)); //logarithmic1(5): base case</span>\n<span class=\"token function\">logarithmic2</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">////console.log(\"logarithmic2(6): \", logarithmic2(6)); //logarithmic2(6): 3</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/* \n   * O(n) Linear \n   Linear algo's will access each item of the input \"once\". \n   */</span>\n<span class=\"token comment\">// O(n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(\"linear1\", i);</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">linear1</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/* \n   linear1 1 \n   linear1 2 \n   linear1 3 \n   */</span>\n<span class=\"token comment\">// O(n), where n is the length of the array</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(\"linear2\", i);</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">linear2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/* \n   linear2 0 \n   linear2 1 \n   linear2 2 \n   */</span>\n<span class=\"token comment\">//! O(n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear3</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(`linear3(${n})--->`, linear3(n - 1));</span>\n        <span class=\"token comment\">/*\n         */</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//!linear3(6);</span>\n<span class=\"token comment\">//linear3(2)---> 1 linear3(3)---> undefined linear3(4)---> undefined</span>\n<span class=\"token comment\">//linear3(5)---> undefined linear3(6)---> undefined</span>\n<span class=\"token comment\">//!linear3(5);</span>\n<span class=\"token comment\">// linear3(2)---> 1 linear3(3)---> undefined linear3(4)---> undefined</span>\n<span class=\"token comment\">//linear3(5)---> undefined</span>\n<span class=\"token comment\">//// in the two function calls above we can see that size of output corresponds to a proportional change in the size of the input</span>\n<span class=\"token comment\">//console.log(\"linear3(4): \", linear3(4)); //// linear3(4): undefined</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/* \n   * O(nlog(n)) Log Linear Time \n   Combination of linear and logarithmic behavior, \n   we will see features from both classes. \n   !Algorithm's that are log-linear will use both recursion AND iteration. \n   */</span>\n<span class=\"token comment\">// O(n * log(n))</span>\n<span class=\"token comment\">// function loglinear(n) {</span>\n<span class=\"token comment\">// if (n &lt;= 1) return; // base case</span>\n<span class=\"token comment\">// for (let i = 1; i &lt;= n; i++) {</span>\n<span class=\"token comment\">// console.log(</span>\n<span class=\"token comment\">// `for an input (n=${n}):`,</span>\n<span class=\"token comment\">// `we are on the ${i}'th itteration where i = ${i}`</span>\n<span class=\"token comment\">// );</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// console.log(\" first call n('old n'):\", n);</span>\n<span class=\"token comment\">// loglinear(n / 2);</span>\n<span class=\"token comment\">// console.log(` new n is = (${n})`);</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// loglinear(4);</span>\n<span class=\"token comment\">/* \n   for an input (n=4): we are on the 1'th itteration where i = 1 \n   for an input (n=4): we are on the 2'th itteration where i = 2 \n   for an input (n=4): we are on the 3'th itteration where i = 3 \n   for an input (n=4): we are on the 4'th itteration where i = 4 \n   first call n('old n'): 4 \n   for an input (n=2): we are on the 1'th itteration where i = 1 \n   for an input (n=2): we are on the 2'th itteration where i = 2 \n   first call n('old n'): 2 \n   new n is = (2) \n   new n is = (4) \n   */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// base case</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">for an input (n=</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>n<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">):</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">we are on the </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">'th itteration where i = </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\" first call n('old n'):\"</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">new n is = (</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">)</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> new n is = (</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>n<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">)</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> Second Call : new n is = (</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>n<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">)</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//loglinear(4);</span>\n<span class=\"token comment\">/* \n   for an input (n=4): we are on the 1'th itteration where i = 1 \n   for an input (n=4): we are on the 2'th itteration where i = 2 \n   for an input (n=4): we are on the 3'th itteration where i = 3 \n   for an input (n=4): we are on the 4'th itteration where i = 4 \n   first call n('old n'): 4 new n is = (2) \n   for an input (n=2): we are on the 1'th itteration where i = 1 \n   for an input (n=2): we are on the 2'th itteration where i = 2 \n   first call n('old n'): 2 new n is = (1) \n   new n is = (2) \n   Second Call : new n is = (2) \n   new n is = (4) \n   for an input (n=2): we are on the 1'th itteration where i = 1 \n   for an input (n=2): we are on the 2'th itteration where i = 2 \n   first call n('old n'): 2 new n is = (1) \n   new n is = (2) \n   Second Call : new n is = (2) \n   Second Call : new n is = (4) \n   */</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/* \n   O(nc) Polynomial \n   C is a fixed constant. \n   */</span>\n<span class=\"token comment\">// O(n^3)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">cubic</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(`i is ${i}`, \"count:\", count);</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">//console.log(` for i: ${i} j is:${j}`);</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> k <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> k <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> k<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                count <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                <span class=\"token comment\">// console.log( ` itteration #${count}: i: is ${i}, j: is ${j}, k:is ${k}`);</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">cubic</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/* \n   i is 1 count: 0 \n   for i: 1 j is:1 \n   itteration #1: i: is 1, j: is 1, k: is 1 \n   itteration #2: i: is 1, j: is 1, k: is 2 \n   itteration #3: i: is 1, j: is 1, k: is 3 \n   for i: 1 j is:2 \n   itteration #4: i: is 1, j: is 2, k: is 1 \n   itteration #5: i: is 1, j: is 2, k: is 2 \n   itteration #6: i: is 1, j: is 2, k: is 3 \n   for i: 1 j is:3 \n   itteration #7: i: is 1, j: is 3, k: is 1 \n   itteration #8: i: is 1, j: is 3, k: is 2 \n   itteration #9: i: is 1, j: is 3, k: is 3 \n   i is 2 count: 9 \n   for i: 2 j is:1 \n   itteration #10: i: is 2, j: is 1, k: is 1 \n   itteration #11: i: is 2, j: is 1, k: is 2 \n   itteration #12: i: is 2, j: is 1, k: is 3 \n   for i: 2 j is:2 \n   itteration #13: i: is 2, j: is 2, k: is 1 \n   itteration #14: i: is 2, j: is 2, k: is 2 \n   itteration #15: i: is 2, j: is 2, k: is 3 \n   for i: 2 j is:3 \n   itteration #16: i: is 2, j: is 3, k: is 1 \n   itteration #17: i: is 2, j: is 3, k: is 2 \n   itteration #18: i: is 2, j: is 3, k: is 3 \n   i is 3 count: 18 \n   for i: 3 j is:1 \n   itteration #19: i: is 3, j: is 1, k: is 1 \n   itteration #20: i: is 3, j: is 1, k: is 2 \n   itteration #21: i: is 3, j: is 1, k: is 3 \n   for i: 3 j is:2 \n   itteration #22: i: is 3, j: is 2, k: is 1 \n   itteration #23: i: is 3, j: is 2, k: is 2 \n   itteration #24: i: is 3, j: is 2, k: is 3 \n   for i: 3 j is:3 \n   itteration #25: i: is 3, j: is 3, k: is 1 \n   itteration #26: i: is 3, j: is 3, k: is 2 \n   itteration #27: i: is 3, j: is 3, k: is 3 \n   */</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/* \n   Example of Quadratic and Cubic runtime. \n   !O(c^n) Exponential \n   C is now the number of recursive calls made in each stack frame. \n   -Algo's with exponential time are VERY SLOW. \n   */</span>\n<span class=\"token comment\">// O(3^n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">//console.log(\"1.) first call n('old n'):\", n, `....new n is = (${n - 1})`);</span>\n    <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// console.log(\"---------------------(__1__)---------------------------\", \"\\n\");</span>\n    <span class=\"token comment\">// console.log(</span>\n    <span class=\"token comment\">// \"2.) after first call ('old n'):\",</span>\n    <span class=\"token comment\">// n,</span>\n    <span class=\"token comment\">// `....new n is = (${n - 1})`</span>\n    <span class=\"token comment\">// );</span>\n\n    <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">//console.log(\"-------------------------(__2__)---------------------\", \"\\n\");</span>\n    <span class=\"token comment\">//console.log(</span>\n    <span class=\"token comment\">// \"3.) after second call ('old n'):\",</span>\n    <span class=\"token comment\">// n,</span>\n    <span class=\"token comment\">// `....new n is = (${n - 1})`</span>\n    <span class=\"token comment\">// );</span>\n\n    <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">//console.log(\"-----------------------(__3__)-------------------------\", \"\\n\");</span>\n    <span class=\"token comment\">//console.log(</span>\n    <span class=\"token comment\">// \"4.) after third call ('old n'):\",</span>\n    <span class=\"token comment\">// n,</span>\n    <span class=\"token comment\">// `....new n is = (${n - 1})`</span>\n    <span class=\"token comment\">//);</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//***********************__Memoization__*************************** */</span>\n<span class=\"token comment\">/* \n   Memoization : a design pattern used to reduce the overall number of calculations that can occur \n   in algorithms that use recursive strategies to solve. \n   MZ stores the results of the sub-problems in some other data structure, so that we can avoid \n   duplicate calculations and only 'solve' each problem once. \n   Two features that comprise memoization: \n   1\\. FUNCTION MUST BE RECURSIVE. \n   2\\. Our additional DS is usually an object (we refer to it as our memo!) \n   */</span>\n\n<span class=\"token comment\">//! _____Memoizing Factorial_____</span>\n\n<span class=\"token comment\">// function fib(n, memo = {}) {</span>\n<span class=\"token comment\">// if (n in memo) return memo[n]; // If we already calculated this value, return it</span>\n<span class=\"token comment\">// if (n === 1 || n === 2) return 1;</span>\n\n<span class=\"token comment\">// // Store the result in the memo first before returning</span>\n<span class=\"token comment\">// // Make sure to pass the memo in to your calls to fib!</span>\n<span class=\"token comment\">// memo[n] = fib(n - 1, memo) + fib(n - 2, memo);</span>\n<span class=\"token comment\">// return memo[n];</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> memo2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> key <span class=\"token operator\">=</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>key <span class=\"token keyword\">in</span> memo2<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo2<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    memo2<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> memo2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">//console.log(\"this is memo\", memo2);</span>\n    <span class=\"token keyword\">return</span> memo2<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">//console.log(memo2);</span>\n<span class=\"token comment\">// //factorial(6); // => 720, requires 6 calls</span>\n<span class=\"token comment\">//console.log(\"factorial(6): \", factorial(6));</span>\n<span class=\"token comment\">// //factorial(6); // => 720, requires 1 call</span>\n<span class=\"token comment\">// //factorial(5); // => 120, requires 1 call</span>\n<span class=\"token comment\">// console.log(\"factorial(5): \", factorial(5));</span>\n<span class=\"token comment\">//factorial(7); // => 5040, requires 2 calls</span>\n<span class=\"token comment\">//console.log(\"factorial(7): \", factorial(7));</span>\n<span class=\"token comment\">//console.log(\"factorial(20): \", factorial(20)); // 2432902008176640000</span>\n<span class=\"token comment\">/* \n   this is memo { '2': 2 } \n   this is memo { '2': 2, '3': 6 } \n   this is memo { '2': 2, '3': 6, '4': 24 } \n   this is memo { '2': 2, '3': 6, '4': 24, '5': 120 } \n   this is memo { '2': 2 } \n   this is memo { '2': 2, '3': 6 } \n   this is memo { '2': 2, '3': 6, '4': 24 } \n   this is memo { '2': 2, '3': 6, '4': 24, '5': 120 } \n   this is memo { '2': 2, '3': 6, '4': 24, '5': 120, '6': 720 } \n   factorial(6): 720 \n   this is memo { '2': 2 } \n   this is memo { '2': 2, '3': 6 } \n   this is memo { '2': 2, '3': 6, '4': 24 } \n   this is memo { '2': 2, '3': 6, '4': 24, '5': 120 } \n   this is memo { '2': 2, '3': 6, '4': 24, '5': 120, '6': 720 } \n   this is memo { '2': 2, '3': 6, '4': 24, '5': 120, '6': 720, '7': 5040 } \n   factorial(7): 5040 \n   */</span>\n\n<span class=\"token comment\">/* \n   The Memoization Formula \n   Rules \n   1\\. Write the unoptimized brute force recursion (make sure it works); \n   2\\. Add memo object as an additional arugmnt . \n   3\\. Add a base case condition that returns the stored value if the function's argument is in the memo. \n   4\\. Before returning the result of the recursive case, store it in the memo as a value and make the \n   function's argument it's key. \n    \n   !Things to remember \n   *1. When solving DP problems with Memoization, it is helpful to draw out the visual tree first. \n   *2. When you notice duplicate sub-tree's that means we can memoize. \n    \n   */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> memo <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token keyword\">in</span> memo<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span> <span class=\"token operator\">||</span> n <span class=\"token operator\">===</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//fastFib(6); // => 8</span>\n<span class=\"token comment\">//console.log(\"fastFib(6): \", fastFib(6)); //fastFib(6): 8</span>\n<span class=\"token comment\">//fastFib(50); // => 12586269025</span>\n<span class=\"token comment\">//console.log(\"fastFib(50): \", fastFib(50)); //fastFib(50): 12586269025</span>\n\n<span class=\"token comment\">//***********************__Tabulation__*************************** */</span>\n<span class=\"token comment\">/* \n   Tabulation Strategy \n   //Use When: \n   -The function is iterative and not recursive. \n   -The accompanying Data Structure is usually an array. \n   */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> table <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// if(n === 0 || n === 1){</span>\n    <span class=\"token comment\">// return 1;</span>\n    <span class=\"token comment\">// }</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        table<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">[</span>table<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> table<span class=\"token punctuation\">[</span>table<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> table<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//1</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//1</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//2</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//3</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//5</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//12586269025 |</span></code></pre></div>\n<p><a href=\"https://gist.github.com/bgoonz/af844eda5a20b0fdc0b813304401602b/raw/a5bd8a34d26c2b6cff9232c7f6218463122ff7ef/algo-time-complexity-by-example.js\">view raw</a><a href=\"https://gist.github.com/bgoonz/af844eda5a20b0fdc0b813304401602b#file-algo-time-complexity-by-example-js\">algo-time-complexity-by-example.js </a>hosted with ❤ by <a href=\"https://github.com/\">GitHub</a></p>\n<details>\n<summary> Big O Examples In JavaScript  </summary>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**************************************BIG-O***********************************/</span>\n<span class=\"token comment\">/***********************Common Algorithms for Analysis********************/</span>\n<span class=\"token comment\">//mdn Object;</span>\n<span class=\"token comment\">//-**************-recursive factorial:*********************/</span>\n<span class=\"token comment\">/*\nFactorial: the product of a given positive integer multiplied by all lesser positive integers:\nThe quantity four factorial (4!) = 4 ⋅ 3 ⋅ 2 ⋅ 1 = 24.\nSymbol:n!, where n is the given integer.\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//* Base Case ... 1 * 1 = 1</span>\n    <span class=\"token keyword\">return</span> n <span class=\"token operator\">*</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//*  n! = n * (n-1) *  (n-2) * (n-3) * ... * 1</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//*5 * 4 * 3 * 2 * 1 = 120 &lt;----expected</span>\n<span class=\"token comment\">//console.log( \"factorial(5): \", factorial( 5 ) ); //-  factorial(5):  120</span>\n<span class=\"token comment\">/*\nFibonacci numbers are the numbers such that every number in the series after the first two is the sum of the two preceding ones.\nThe series starts with 1, 1. Example −1, 1, 2, 3, 5, 8, 13, 21, 34, ….\nMathematical Expression: fib(n) = fib(n−1) + fib(n−2)\n! fib-tree-structure-diagram.png\nhttps://miro.medium.com/max/700/1*svQ784qk1hvBE3iz7VGGgQ.jpeg\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span> <span class=\"token operator\">||</span> n <span class=\"token operator\">===</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//console.log(\"fib(5): \", fibonacci(5)); //-  fib(5):  5</span>\n<span class=\"token comment\">/*\nthe major differences between tabulation and memoization are:\n1.)     tabulation has to look through the entire search space; memoization does not\n2.)     tabulation requires careful ordering of the subproblems is; memoization doesn't care much about the order of recursive calls.\n*/</span>\n<span class=\"token keyword\">const</span> memo <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token number\">0</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n    <span class=\"token number\">1</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n    <span class=\"token number\">2</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">fib</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> n1 <span class=\"token operator\">=</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> n2 <span class=\"token operator\">=</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//console.log(\"fib(50): \", fib(20));      //-  fib(50):  4181</span>\n<span class=\"token comment\">/******************End of Common Algorithms for Analysis*****************/</span>\n<span class=\"token comment\">/***********Comparing two functions that calculate the sum of all numbers from 1 up to n**********************/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">addUpTo</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> total <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//! Number of operations will grow with input n.</span>\n        total <span class=\"token operator\">+=</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> total<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">addUpTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//console.log(\"addUpTo( 4 ): \", addUpTo(4)); //-  addUpTo( 4 ):  10</span>\n<span class=\"token comment\">//! Would be O(n) or Linear Time.</span>\n<span class=\"token comment\">//----------------------------------------------------------------</span>\n<span class=\"token comment\">/*\nThe infinite series whose terms are the natural numbers 1 + 2 + 3 + 4 + ⋯ is a divergent series.\nThe nth partial sum of the series is the triangular number( https://en.wikipedia.org/wiki/Triangular_number )\naddUpTo(n)=(n * (n + 1)) / 2\nhttps://wikimedia.org/api/rest_v1/media/math/render/svg/99476e25466549387c585cb4de44e90f6cbe4cf2\n*/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">constantAddUpTo</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">constantAddUpTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//-  constantAddUpTo(4):  10</span>\n<span class=\"token comment\">//console.log(\"constantAddUpTo(4): \", constantAddUpTo(4));</span>\n<span class=\"token comment\">//! Has three simple operations: 1 Multiplication 1 Addition 1 Division.</span>\n<span class=\"token comment\">//!(Regardless of n) Would be O(1) or Constant Time.</span>\n<span class=\"token comment\">/***********End of Comparing two functions that calculate the sum of all numbers from 1 up to n*******************/</span>\n<span class=\"token comment\">/*\n!Simplifying Math Terms\nWe want our Big-O notation to describe the performance of our algorithm with respect to the input size and nothing else.\n !Use the following rules to simplify our Big-O functions using the following rules:\n1.)   Simplify Products: if the function is a product of many terms, we drop the terms that don't depend on the size of the input.\n2.)   Simplify Sums: if the function is a sum of many terms, we keep the term with the largest growth rate and drop the other terms.\n*   n is the size of the input\n*   T(f) refers to an un-simplified mathematical function\n*   O(f) refers to the Big-O simplified mathematical function\n*   Simplifying a Product\nIf a function consists of a product of many factors,\n!we drop the factors that don't depend on the size of the input, n.\nThe factors that we drop are called constant factors because their size remains consistent as we increase the size of the input.\nexamples-of-big-O-simplification.png\nsimplifying-a-sum.png\nsimp-examples.png\n*/</span>\n<span class=\"token comment\">/***********Comparing two functions with nested for loops*********************/</span>\n<span class=\"token comment\">// function countUpAndDown(n) {</span>\n<span class=\"token comment\">//   console.log(\"going up!\");</span>\n<span class=\"token comment\">//   for (let i = 0; i &lt; n; i++) {</span>\n<span class=\"token comment\">//     console.log(i);</span>\n<span class=\"token comment\">//   }</span>\n<span class=\"token comment\">//   console.log(\"at the top, going down!\");</span>\n<span class=\"token comment\">//   for (let j = n - 1; j >= 0; j--) {</span>\n<span class=\"token comment\">//     console.log(j);</span>\n<span class=\"token comment\">//   }</span>\n<span class=\"token comment\">//   console.log(\"Back down, bye!\");</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// countUpAndDown(5);</span>\n<span class=\"token comment\">// console.log(\"countUpAndDown(5): \", countUpAndDown(5));</span>\n<span class=\"token comment\">/*\ngoing up!\n0 1\t2\t3\t4\nat the top, going down!\n4\t3\t2\t1\t0\nBack down, bye!\ncountUpAndDown(5):  undefined //- because there was no return statment... only console.log\n*/</span>\n<span class=\"token comment\">//------------------------------------------------</span>\n<span class=\"token comment\">//!Both loops are O(n) but since we just want the big picture, O(n);</span>\n<span class=\"token comment\">//-----------------------------------------------</span>\n<span class=\"token comment\">// function printAllPairs(n) {</span>\n<span class=\"token comment\">//   for (let i = 0; i &lt; n; i++) {</span>\n<span class=\"token comment\">//     for (let j = 0; j &lt; n; j++) {</span>\n<span class=\"token comment\">//       console.log(i, j);</span>\n<span class=\"token comment\">//     }</span>\n<span class=\"token comment\">//   }</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// printAllPairs(4);</span>\n<span class=\"token comment\">/*\n0 0\t0 1\t0 2\t0 3\t1 0\t1 1\t1 2\t1 3\t2 0\t2 1\t2 2\t2 3\t3 0\t3 1\t3 2\t3 3\n*/</span>\n<span class=\"token comment\">//!Nested loops who's number of iterations depend on the size of the input are never a good thing when trying to write fast code.</span>\n<span class=\"token comment\">//!O(n^2) or Quadratic Time.</span>\n<span class=\"token comment\">/***********END of Comparing two functions with nested for loops**********************/</span>\n<span class=\"token comment\">/**************************Big-O-Operations**********************/</span>\n<span class=\"token comment\">//! Arithmetic Operations are Constant</span>\n<span class=\"token comment\">//! Variable assignment is constant</span>\n<span class=\"token comment\">//! Accessing elements in an array (by index) or by object (by key) is constant.</span>\n<span class=\"token comment\">//! In a loop, the complexity is the length of the loop times the complexity of whatever is inside of the loop.</span>\n<span class=\"token comment\">/**************************More Examples**********************/</span>\n<span class=\"token comment\">//---------------------logAtLeast5---------------------------------</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logAtLeast5</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(i);</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//!   O(n) Linear Time</span>\n<span class=\"token comment\">//logAtLeast5(2);</span>\n<span class=\"token comment\">/*\n1\t2\t3\t4\t5\n----------------------------\n*/</span>\n<span class=\"token comment\">//logAtLeast5(6);</span>\n<span class=\"token comment\">/*\n----------------------------\n1\t2\t3\t4\t5\t6\n*/</span>\n<span class=\"token comment\">//---------------------logAtMost5---------------------------------</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logAtMost5</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(i);</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">logAtMost5</span><span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//! O(1) Constant Time.</span>\n<span class=\"token comment\">/*\n1\t2\t3\t4\t5\n*/</span>\n<span class=\"token comment\">//***********************Big-O Complexity Classes*************************** */</span>\n<span class=\"token comment\">/*\n//! O(1) Constant\nThe algorithm takes roughly the same number of steps for any input size.\n*/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">constant1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">constant1</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//constant1(5):  11</span>\n<span class=\"token comment\">//console.log(\"constant1(5): \", constant1(5));</span>\n<span class=\"token comment\">//--------</span>\n<span class=\"token comment\">//! O(1)</span>\n<span class=\"token comment\">//--------</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">constant2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//constant2(5);</span>\n<span class=\"token comment\">////console.log(\"constant2(5): \", constant2(5));</span>\n<span class=\"token comment\">//1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\t26\t27\t28\t29\t30\t31\t32\t33\t34\t35\t36\t37\t38\t39\t40\t41\t42\t43\t44\t45\t46\t47\t48\t49\t50\t51\t52\t53\t54\t55\t56\t57\t58\t59\t60\t61\t62\t63\t64\t65\t66\t67\t68\t69\t70\t71\t72\t73\t74\t75\t76\t77\t78\t79\t80\t81\t82\t83\t84\t85\t86\t87\t88\t89\t90\t91\t92\t93\t94\t95\t96\t97\t98\t99\t100</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/*\nO(log(n)) Logarithmic\nIn most cases our hidden base of Logarithmic time is 2,\nlog complexity algo's will typically display 'halving' the size of the input ??\n? (like binary search!)\n*/</span>\n<span class=\"token comment\">// O(log(n))</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logarithmic1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'base case'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token function\">logarithmic1</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//*Recursive call on **half** the input</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//! O(log(n))</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">logarithmic2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> n<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        i <span class=\"token operator\">/=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">logarithmic1</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">////console.log(\"logarithmic1(5): \", logarithmic1(5)); //logarithmic1(5):  base case</span>\n<span class=\"token function\">logarithmic2</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">////console.log(\"logarithmic2(6): \", logarithmic2(6)); //logarithmic2(6):  3</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/*\n*  O(n) Linear\nLinear algo's will access each item of the input \"once\".\n */</span>\n<span class=\"token comment\">// O(n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear1</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(\"linear1\", i);</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">linear1</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/*\nlinear1 1\nlinear1 2\nlinear1 3\n*/</span>\n<span class=\"token comment\">// O(n), where n is the length of the array</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear2</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> array<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(\"linear2\", i);</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">linear2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/*\nlinear2 0\nlinear2 1\nlinear2 2\n*/</span>\n<span class=\"token comment\">//!  O(n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">linear3</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(`linear3(${n})--->`, linear3(n - 1));</span>\n        <span class=\"token comment\">/*\n         */</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//!linear3(6);</span>\n<span class=\"token comment\">//linear3(2)---> 1\tlinear3(3)---> undefined\tlinear3(4)---> undefined</span>\n<span class=\"token comment\">//linear3(5)---> undefined\tlinear3(6)---> undefined</span>\n<span class=\"token comment\">//!linear3(5);</span>\n<span class=\"token comment\">// linear3(2)---> 1\tlinear3(3)---> undefined\tlinear3(4)---> undefined</span>\n<span class=\"token comment\">//linear3(5)---> undefined</span>\n<span class=\"token comment\">//// in the two function calls above we can see that size of output corresponds to a proportional change in the size of the input</span>\n<span class=\"token comment\">//console.log(\"linear3(4): \", linear3(4)); //// linear3(4):  undefined</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/*\n* O(nlog(n)) Log Linear Time\nCombination of linear and logarithmic behavior,\nwe will see features from both classes.\n!Algorithm's that are log-linear will use both recursion AND iteration.\n */</span>\n<span class=\"token comment\">// O(n * log(n))</span>\n<span class=\"token comment\">// function loglinear(n) {</span>\n<span class=\"token comment\">//   if (n &lt;= 1) return; // base case</span>\n<span class=\"token comment\">//   for (let i = 1; i &lt;= n; i++) {</span>\n<span class=\"token comment\">//     console.log(</span>\n<span class=\"token comment\">//       `for an input (n=${n}):`,</span>\n<span class=\"token comment\">//       `we are on the ${i}'th itteration where i = ${i}`</span>\n<span class=\"token comment\">//     );</span>\n<span class=\"token comment\">//   }</span>\n<span class=\"token comment\">//   console.log(\" first call n('old n'):\", n);</span>\n<span class=\"token comment\">//   loglinear(n / 2);</span>\n<span class=\"token comment\">//   console.log(`   new n is = (${n})`);</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token comment\">// loglinear(4);</span>\n<span class=\"token comment\">/*\nfor an input (n=4): we are on the 1'th itteration where i = 1\nfor an input (n=4): we are on the 2'th itteration where i = 2\nfor an input (n=4): we are on the 3'th itteration where i = 3\nfor an input (n=4): we are on the 4'th itteration where i = 4\n first call n('old n'): 4\nfor an input (n=2): we are on the 1'th itteration where i = 1\nfor an input (n=2): we are on the 2'th itteration where i = 2\n first call n('old n'): 2\n   new n is = (2)\n   new n is = (4)\n*/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// base case</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">for an input (n=</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>n<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">):</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">we are on the </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">'th itteration where i = </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\" first call n('old n'):\"</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">new n is = (</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">)</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">   new n is = (</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>n<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">)</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">loglinear</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">   Second Call : new n is = (</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>n<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">)</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//loglinear(4);</span>\n<span class=\"token comment\">/*\nfor an input (n=4): we are on the 1'th itteration where i = 1\nfor an input (n=4): we are on the 2'th itteration where i = 2\nfor an input (n=4): we are on the 3'th itteration where i = 3\nfor an input (n=4): we are on the 4'th itteration where i = 4\n first call n('old n'): 4 new n is = (2)\nfor an input (n=2): we are on the 1'th itteration where i = 1\nfor an input (n=2): we are on the 2'th itteration where i = 2\n first call n('old n'): 2 new n is = (1)\n   new n is = (2)\n   Second Call : new n is = (2)\n   new n is = (4)\nfor an input (n=2): we are on the 1'th itteration where i = 1\nfor an input (n=2): we are on the 2'th itteration where i = 2\n first call n('old n'): 2 new n is = (1)\n   new n is = (2)\n   Second Call : new n is = (2)\n   Second Call : new n is = (4)\n*/</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/*\nO(nc) Polynomial\nC is a fixed constant.\n */</span>\n<span class=\"token comment\">// O(n^3)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">cubic</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">//console.log(`i is ${i}`, \"count:\", count);</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">//console.log(`  for i:    ${i}      j is:${j}`);</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> k <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> k <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> k<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                count <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                <span class=\"token comment\">// console.log(  `     itteration #${count}:       i: is  ${i},   j: is  ${j},     k:is   ${k}`);</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">cubic</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/*\ni is 1 count: 0\n  for i:    1      j is:1\n     itteration #1:       i: is  1,   j: is  1,     k: is   1\n     itteration #2:       i: is  1,   j: is  1,     k: is   2\n     itteration #3:       i: is  1,   j: is  1,     k: is   3\n  for i:    1      j is:2\n     itteration #4:       i: is  1,   j: is  2,     k: is   1\n     itteration #5:       i: is  1,   j: is  2,     k: is   2\n     itteration #6:       i: is  1,   j: is  2,     k: is   3\n  for i:    1      j is:3\n     itteration #7:       i: is  1,   j: is  3,     k: is   1\n     itteration #8:       i: is  1,   j: is  3,     k: is   2\n     itteration #9:       i: is  1,   j: is  3,     k: is   3\ni is 2 count: 9\n  for i:    2      j is:1\n     itteration #10:       i: is  2,   j: is  1,     k: is   1\n     itteration #11:       i: is  2,   j: is  1,     k: is   2\n     itteration #12:       i: is  2,   j: is  1,     k: is   3\n  for i:    2      j is:2\n     itteration #13:       i: is  2,   j: is  2,     k: is   1\n     itteration #14:       i: is  2,   j: is  2,     k: is   2\n     itteration #15:       i: is  2,   j: is  2,     k: is   3\n  for i:    2      j is:3\n     itteration #16:       i: is  2,   j: is  3,     k: is   1\n     itteration #17:       i: is  2,   j: is  3,     k: is   2\n     itteration #18:       i: is  2,   j: is  3,     k: is   3\ni is 3 count: 18\n  for i:    3      j is:1\n     itteration #19:       i: is  3,   j: is  1,     k: is   1\n     itteration #20:       i: is  3,   j: is  1,     k: is   2\n     itteration #21:       i: is  3,   j: is  1,     k: is   3\n  for i:    3      j is:2\n     itteration #22:       i: is  3,   j: is  2,     k: is   1\n     itteration #23:       i: is  3,   j: is  2,     k: is   2\n     itteration #24:       i: is  3,   j: is  2,     k: is   3\n  for i:    3      j is:3\n     itteration #25:       i: is  3,   j: is  3,     k: is   1\n     itteration #26:       i: is  3,   j: is  3,     k: is   2\n     itteration #27:       i: is  3,   j: is  3,     k: is   3\n*/</span>\n<span class=\"token comment\">//------------------------------------------</span>\n<span class=\"token comment\">/*\nExample of Quadratic and Cubic runtime.\n!O(c^n) Exponential\nC is now the number of recursive calls made in each stack frame.\n-Algo's with exponential time are VERY SLOW.\n*/</span>\n<span class=\"token comment\">// O(3^n)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">//console.log(\"1.)  first call n('old n'):\", n, `....new n is = (${n - 1})`);</span>\n    <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// console.log(\"---------------------(__1__)---------------------------\", \"\\n\");</span>\n    <span class=\"token comment\">// console.log(</span>\n    <span class=\"token comment\">//   \"2.)  after first call ('old n'):\",</span>\n    <span class=\"token comment\">//   n,</span>\n    <span class=\"token comment\">//   `....new n is = (${n - 1})`</span>\n    <span class=\"token comment\">// );</span>\n\n    <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">//console.log(\"-------------------------(__2__)---------------------\", \"\\n\");</span>\n    <span class=\"token comment\">//console.log(</span>\n    <span class=\"token comment\">//   \"3.)  after second call ('old n'):\",</span>\n    <span class=\"token comment\">//   n,</span>\n    <span class=\"token comment\">//   `....new n is = (${n - 1})`</span>\n    <span class=\"token comment\">// );</span>\n\n    <span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">//console.log(\"-----------------------(__3__)-------------------------\", \"\\n\");</span>\n    <span class=\"token comment\">//console.log(</span>\n    <span class=\"token comment\">//  \"4.)   after third call ('old n'):\",</span>\n    <span class=\"token comment\">//  n,</span>\n    <span class=\"token comment\">// `....new n is = (${n - 1})`</span>\n    <span class=\"token comment\">//);</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">exponential3n</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//***********************__Memoization__*************************** */</span>\n<span class=\"token comment\">/*\nMemoization : a design pattern used to reduce the overall number of calculations that can occur\nin algorithms that use recursive strategies to solve.\nMZ stores the results of the sub-problems in some other data structure, so that we can avoid\nduplicate calculations and only 'solve' each problem once.\nTwo features that comprise memoization:\n1. FUNCTION MUST BE RECURSIVE.\n2. Our additional DS is usually an object (we refer to it as our memo!)\n*/</span>\n\n<span class=\"token comment\">//!    _____Memoizing Factorial_____</span>\n\n<span class=\"token comment\">// function fib(n, memo = {}) {</span>\n<span class=\"token comment\">//   if (n in memo) return memo[n]; // If we already calculated this value, return it</span>\n<span class=\"token comment\">//   if (n === 1 || n === 2) return 1;</span>\n\n<span class=\"token comment\">//   // Store the result in the memo first before returning</span>\n<span class=\"token comment\">//   // Make sure to pass the memo in to your calls to fib!</span>\n<span class=\"token comment\">//   memo[n] = fib(n - 1, memo) + fib(n - 2, memo);</span>\n<span class=\"token comment\">//   return memo[n];</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> memo2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> key <span class=\"token operator\">=</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>key <span class=\"token keyword\">in</span> memo2<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo2<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    memo2<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> memo2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">//console.log(\"this is memo\", memo2);</span>\n    <span class=\"token keyword\">return</span> memo2<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">//console.log(memo2);</span>\n<span class=\"token comment\">// //factorial(6); // => 720, requires 6 calls</span>\n<span class=\"token comment\">//console.log(\"factorial(6): \", factorial(6));</span>\n<span class=\"token comment\">// //factorial(6); // => 720, requires 1 call</span>\n<span class=\"token comment\">// //factorial(5); // => 120, requires 1 call</span>\n<span class=\"token comment\">// console.log(\"factorial(5): \", factorial(5));</span>\n<span class=\"token comment\">//factorial(7); // => 5040, requires 2 calls</span>\n<span class=\"token comment\">//console.log(\"factorial(7): \", factorial(7));</span>\n<span class=\"token comment\">//console.log(\"factorial(20): \", factorial(20)); // 2432902008176640000</span>\n<span class=\"token comment\">/*\nthis is memo { '2': 2 }\nthis is memo { '2': 2, '3': 6 }\nthis is memo { '2': 2, '3': 6, '4': 24 }\nthis is memo { '2': 2, '3': 6, '4': 24, '5': 120 }\nthis is memo { '2': 2 }\nthis is memo { '2': 2, '3': 6 }\nthis is memo { '2': 2, '3': 6, '4': 24 }\nthis is memo { '2': 2, '3': 6, '4': 24, '5': 120 }\nthis is memo { '2': 2, '3': 6, '4': 24, '5': 120, '6': 720 }\nfactorial(6):  720\nthis is memo { '2': 2 }\nthis is memo { '2': 2, '3': 6 }\nthis is memo { '2': 2, '3': 6, '4': 24 }\nthis is memo { '2': 2, '3': 6, '4': 24, '5': 120 }\nthis is memo { '2': 2, '3': 6, '4': 24, '5': 120, '6': 720 }\nthis is memo { '2': 2, '3': 6, '4': 24, '5': 120, '6': 720, '7': 5040 }\nfactorial(7):  5040\n*/</span>\n\n<span class=\"token comment\">/*\nThe Memoization Formula\nRules\n1. Write the unoptimized brute force recursion (make sure it works);\n2. Add memo object as an additional arugmnt .\n3. Add a base case condition that returns the stored value if the function's argument is in the memo.\n4. Before returning the result of the recursive case, store it in the memo as a value and make the\nfunction's argument it's key.\n!Things to remember\n*1. When solving DP problems with Memoization, it is helpful to draw out the visual tree first.\n*2. When you notice duplicate sub-tree's that means we can memoize.\n*/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> memo <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token keyword\">in</span> memo<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">===</span> <span class=\"token number\">1</span> <span class=\"token operator\">||</span> n <span class=\"token operator\">===</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fastFib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//fastFib(6); // => 8</span>\n<span class=\"token comment\">//console.log(\"fastFib(6): \", fastFib(6)); //fastFib(6):  8</span>\n<span class=\"token comment\">//fastFib(50); // => 12586269025</span>\n<span class=\"token comment\">//console.log(\"fastFib(50): \", fastFib(50)); //fastFib(50):  12586269025</span>\n\n<span class=\"token comment\">//***********************__Tabulation__*************************** */</span>\n<span class=\"token comment\">/*\nTabulation Strategy\n//Use When:\n-The function is iterative and not recursive.\n-The accompanying Data Structure is usually an array.\n*/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> table <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// if(n === 0 || n === 1){</span>\n    <span class=\"token comment\">//    return 1;</span>\n    <span class=\"token comment\">// }</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        table<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">[</span>table<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> table<span class=\"token punctuation\">[</span>table<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> table<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//1</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//1</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//2</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//3</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//5</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">fibTab</span><span class=\"token punctuation\">(</span><span class=\"token number\">50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//12586269025</span></code></pre></div>\n</details>"},{"url":"/docs/docs/bash/","relativePath":"docs/docs/bash.md","relativeDir":"docs/docs","base":"bash.md","name":"bash","frontmatter":{"title":"Bash Commands That Save Me Time and Frustration","weight":0,"excerpt":"Bash Commands That Save Me Time and Frustration","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Bash Commands</h1>\n<h1>Bash Commands That Save Me Time and Frustration</h1>\n<p>Here's a list of bash commands that stand between me and insanity.</p>\n<hr>\n<h3>Bash Commands That Save Me Time and Frustration</h3>\n<h4>Here's a list of bash commands that stand between me and insanity.</h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*w0J8u6jWTikYVZzW.jpg\" class=\"graf-image\" />\n</figure>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"markup--anchor markup--p-anchor\">https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b</a>\n<blockquote>\n<p><strong>This article will be accompanied by the following</strong> <a href=\"https://github.com/bgoonz/bash-commands-walkthrough\" class=\"markup--anchor markup--pullquote-anchor\"> > <strong>github repository</strong> > </a> <strong>which will contain all the commands listed as well as folders that demonstrate before and after usage!</strong></p>\n</blockquote>\n<a href=\"https://github.com/bgoonz/bash-commands-walkthrough\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/bash-commands-walkthrough\">\n<strong>bgoonz/bash-commands-walkthrough</strong>\n<br />\n<em>to accompany the medium article I am writing. Contribute to bgoonz/bash-commands-walkthrough development by creating an…</em>github.com</a>\n<a href=\"https://github.com/bgoonz/bash-commands-walkthrough\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<blockquote>\n<p>The <a href=\"https://github.com/bgoonz/bash-commands-walkthrough#readme\" class=\"markup--anchor markup--pullquote-anchor\">readme</a> for this git repo will provide a much more condensed list… whereas this article will break up the commands with explanations… images &#x26; links!</p>\n</blockquote>\n<p><strong>I will include the code examples as both github gists (for proper syntax highlighting) and as code snippets adjacent to said gists so that they can easily be copied and pasted… or … if you're like me for instance; and like to use an extension to grab the markdown content of a page… the code will be included rather than just a link to the gist!</strong></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*3m_UcQOAyKtIpHQ6j9JzZw.gif\" class=\"graf-image\" />\n</figure>\n<h3>Here's a Cheatsheet:</h3>\n<h3>Getting Started (Advanced Users Skip Section):</h3>\n<hr>\n<h4>✔ Check the Current Directory ➡ <code class=\"language-text\">pwd</code>:</h4>\n<p>On the command line, it's important to know the directory we are currently working on. For that, we can use <code class=\"language-text\">pwd</code> command.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*dimzLUrmDI4Ufev6.gif\" class=\"graf-image\" />\n</figure>It shows that I'm working on my Desktop directory.\n<h4>✔ Display List of Files ➡ <code class=\"language-text\">ls</code>:</h4>\n<p>To see the list of files and directories in the current directory use <code class=\"language-text\">ls</code> command in your CLI.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*HHzVrK2CtTPwTdYT.gif\" class=\"graf-image\" />\n</figure>Shows all of my files and directories of my Desktop directory.\n<ul>\n<li><span id=\"20cb\">To show the contents of a directory pass the directory name to the <code class=\"language-text\">ls</code> command i.e. <code class=\"language-text\">ls directory_name</code>.</span></li>\n<li><span id=\"5cd8\">Some useful <code class=\"language-text\">ls</code> command options:-</span></li>\n</ul>\n<p>OptionDescriptionls -alist all files including hidden file starting with '.'ls -llist with the long formatls -lalist long format including hidden files</p>\n<h4>✔ Create a Directory ➡ <code class=\"language-text\">mkdir</code>:</h4>\n<p>We can create a new folder using the <code class=\"language-text\">mkdir</code> command. To use it type <code class=\"language-text\">mkdir folder_name</code>.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*m3dDyC9vRJBUZSxR.gif\" class=\"graf-image\" />\n</figure>Use `ls` command to see the directory is created or not.\n<p>I created a cli-practice directory in my working directory i.e. Desktop directory.</p>\n<h4>✔ Move Between Directories ➡ <code class=\"language-text\">cd</code>:</h4>\n<p>It's used to change directory or to move other directories. To use it type <code class=\"language-text\">cd directory_name</code>.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*34KGxT2G8oNMDnIc.gif\" class=\"graf-image\" />\n</figure>Can use `pwd` command to confirm your directory name.\n<p>Changed my directory to the cli-practice directory. And the rest of the tutorial I'm gonna work within this directory.</p>\n<h4>✔ Parent Directory ➡ <code class=\"language-text\">..</code>:</h4>\n<p>We have seen <code class=\"language-text\">cd</code> command to change directory but if we want to move back or want to move to the parent directory we can use a special symbol <code class=\"language-text\">..</code> after <code class=\"language-text\">cd</code> command, like <code class=\"language-text\">cd ..</code></p>\n<h4>✔ Create Files ➡ <code class=\"language-text\">touch</code>:</h4>\n<p>We can create an empty file by typing <code class=\"language-text\">touch file_name</code>. It's going to create a new file in the current directory (the directory you are currently in) with your provided name.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*xu1wtv7gJ2NMvP60.gif\" class=\"graf-image\" />\n</figure>I created a hello.txt file in my current working directory. Again you can use `ls` command to see the file is created or not.\n<p>Now open your hello.txt file in your text editor and write <em>Hello Everyone!</em> into your hello.txt file and save it.</p>\n<h4>✔ Display the Content of a File ➡ <code class=\"language-text\">cat</code>:</h4>\n<p>We can display the content of a file using the <code class=\"language-text\">cat</code> command. To use it type <code class=\"language-text\">cat file_name</code>.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*iKf5w9QFNCeLRv8a.gif\" class=\"graf-image\" />\n</figure>Shows the content of my hello.txt file.\n<h4>✔ Move Files &#x26; Directories ➡ <code class=\"language-text\">mv</code>:</h4>\n<p>To move a file and directory, we use <code class=\"language-text\">mv</code> command.</p>\n<p>By typing <code class=\"language-text\">mv file_to_move destination_directory</code>, you can move a file to the specified directory.</p>\n<p>By entering <code class=\"language-text\">mv directory_to_move destination_directory</code>, you can move all the files and directories under that directory.</p>\n<p>Before using this command, we are going to create two more directories and another txt file in our cli-practice directory.</p>\n<p><code class=\"language-text\">mkdir html css touch bye.txt</code></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*piaAQz_MQpzo7DPH.gif\" class=\"graf-image\" />\n</figure>Yes, we can use multiple directories & files names one after another to create multiple directories & files in one command.\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*5jmj_ZyNz46GuQKz.gif\" class=\"graf-image\" />\n</figure>Moved my bye.txt file into my css directory and then moved my css directory into my html directory.\n<h4>✔ Rename Files &#x26; Directories ➡ <code class=\"language-text\">mv</code>:</h4>\n<p><code class=\"language-text\">mv</code> command can also be used to rename a file and a directory.</p>\n<p>You can rename a file by typing <code class=\"language-text\">mv old_file_name new_file_name</code> &#x26; also rename a directory by typing <code class=\"language-text\">mv old_directory_name new_directory_name</code>.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*WTVu1dd6gr-nmWhD.gif\" class=\"graf-image\" />\n</figure>Renamed my hello.txt file to the hi.txt file and html directory to the folder directory.\n<h4>✔ Copy Files &#x26; Directories ➡ <code class=\"language-text\">cp</code>:</h4>\n<p>To do this, we use the <code class=\"language-text\">cp</code> command.</p>\n<ul>\n<li><span id=\"62fa\">You can copy a file by entering <code class=\"language-text\">cp file_to_copy new_file_name</code>.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*kCLVtKN9oKPbHfRF.gif\" class=\"graf-image\" />\n</figure>Copied my hi.txt file content into hello.txt file. For confirmation open your hello.txt file in your text editor.\n<ul>\n<li><span id=\"9bfc\">You can also copy a directory by adding the <code class=\"language-text\">-r</code> option, like <code class=\"language-text\">cp -r directory_to_copy new_directory_name</code>.</span></li>\n</ul>\n<p><em>The</em> <code class=\"language-text\">-r</code> <em>option for \"recursive\" means that it will copy all of the files including the files inside of subfolders.</em></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*MnmzMiioIYCuK92B.gif\" class=\"graf-image\" />\n</figure>Here I copied all of the files from the folder to folder-copy.\n<h4>✔ Remove Files &#x26; Directories ➡ <code class=\"language-text\">rm</code>:</h4>\n<p>To do this, we use the <code class=\"language-text\">rm</code> command.</p>\n<ul>\n<li><span id=\"487a\">To remove a file, you can use the command like <code class=\"language-text\">rm file_to_remove</code>.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*ohCmdthd92_HA6Ze.gif\" class=\"graf-image\" />\n</figure>Here I removed my hi.txt file.\n<ul>\n<li><span id=\"0e9a\">To remove a directory, use the command like <code class=\"language-text\">rm -r directory_to_remove</code>.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*voDbzwSpw24A2RjQ.gif\" class=\"graf-image\" />\n</figure>I removed my folder-copy directory from my cli-practice directory i.e. current working directory.\n<h4>✔ Clear Screen ➡ <code class=\"language-text\">clear</code>:</h4>\n<p>Clear command is used to clear the terminal screen.</p>\n<h4>✔ Home Directory ➡ <code class=\"language-text\">~</code>:</h4>\n<p>The Home directory is represented by <code class=\"language-text\">~</code>. The Home directory refers to the base directory for the user. If we want to move to the Home directory we can use <code class=\"language-text\">cd ~</code> command. Or we can only use <code class=\"language-text\">cd</code> command.</p>\n<hr>\n<h3>MY COMMANDS:</h3>\n<h3>1.) Recursively unzip zip files and then delete the archives when finished:</h3>\n<p><strong>here is a</strong> <a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/1-recursive-unzip\" class=\"markup--anchor markup--p-anchor\">\n<strong>folde</strong>\n</a><strong>r containing the before and after… I had to change folder names slightly due to a limit on the length of file-paths in a github repo.</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -name \"*.zip\" | while read filename; do unzip -o -d \"`dirname \"$filename\"`\" \"$filename\"; done;\n\nfind . -name \"*.zip\" -type f -print -delete</code></pre></div>\n<hr>\n<h3>2.) Install node modules recursively:</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm i -g recursive-install\n\nnpm-recursive-install</code></pre></div>\n<hr>\n<h3>3.) Clean up unnecessary files/folders in git repo:</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -empty -type f -print -delete #Remove empty files\n\n# -------------------------------------------------------\nfind . -empty -type d -print -delete #Remove empty folders\n\n# -------------------------------------------------------\n\n# This will remove .git folders...    .gitmodule files as well as .gitattributes and .gitignore files.\n\nfind . \\( -name \".git\" -o -name \".gitignore\" -o -name \".gitmodules\" -o -name \".gitattributes\" \\) -exec rm -rf -- {} +\n\n# -------------------------------------------------------\n\n# This will remove the filenames you see listed below that just take up space if a repo has been downloaded for use exclusively in your personal file system (in which case the following files just take up space)# Disclaimer... you should not use this command in a repo that you intend to use with your work as it removes files that attribute the work to their original creators!\n\nfind . \\( -name \"*SECURITY.txt\" -o -name \"*RELEASE.txt\" -o -name \"*CHANGELOG.txt\" -o -name \"*LICENSE.txt\" -o -name \"*CONTRIBUTING.txt\" -name \"*HISTORY.md\" -o -name \"*LICENSE\" -o -name \"*SECURITY.md\" -o -name \"*RELEASE.md\" -o -name \"*CHANGELOG.md\" -o -name \"*LICENSE.md\" -o -name \"*CODE_OF_CONDUCT.md\" -o -name \"\\*CONTRIBUTING.md\" \\) -exec rm -rf -- {} +</code></pre></div>\n<h4>In Action:</h4>\n<p>The following output from my bash shell corresponds to the directory:</p>\n<a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/3-clean-up-fluf/DS-ALGO-OFFICIAL-master\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/3-clean-up-fluf/DS-ALGO-OFFICIAL-master\">\n<strong>bgoonz/bash-commands-walkthrough</strong>\n<br />\n<em>Deployment github-pages Navigation Big O notation is the language we use for talking about how long an algorithm takes…</em>github.com</a>\n<a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/3-clean-up-fluf/DS-ALGO-OFFICIAL-master\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h4>which was created by running the aforementioned commands in in a perfect copy of this directory:</h4>\n<a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">\n<strong>bgoonz/DS-ALGO-OFFICIAL</strong>\n<br />\n<em>Deployment github-pages Navigation Big O notation is the language we use for talking about how long an algorithm takes…</em>github.com</a>\n<a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<blockquote>\n<p><strong>…..below is the terminal output for the following commands:</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pwd\n/mnt/c/Users/bryan/Downloads/bash-commands/steps/3-clean-up-fluf/DS-ALGO-OFFICIAL-master</code></pre></div>\n<blockquote>\n<p><strong>After printing the working directory for good measure:</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -empty -type f -print -delete</code></pre></div>\n<blockquote>\n<p><strong>The above command deletes empty files recursively starting from the directory in which it was run:</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">./CONTENT/DS-n-Algos/File-System/file-utilities/node_modules/line-reader/test/data/empty_file.txt\n./CONTENT/DS-n-Algos/_Extra-Practice/free-code-camp/nodejs/http-collect.js\n./CONTENT/Resources/Comments/node_modules/mime/.npmignore\n./markdown/tree2.md\n./node_modules/loadashes6/lodash/README.md\n./node_modules/loadashes6/lodash/release.md\n./node_modules/web-dev-utils/Markdown-Templates/Markdown-Templates-master/filled-out-readme.md\n|01:33:16|bryan@LAPTOP-9LGJ3JGS:[DS-ALGO-OFFICIAL-master] DS-ALGO-OFFICIAL-master_exitstatus:0[╗___________o></code></pre></div>\n<blockquote>\n<p><strong>The command seen below deletes empty folders recursively starting from the directory in which it was run:</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -empty -type d -print -delete</code></pre></div>\n<blockquote>\n<p>The resulting directories….</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">|01:33:16|bryan@LAPTOP-9LGJ3JGS:[DS-ALGO-OFFICIAL-master] DS-ALGO-OFFICIAL-master_exitstatus:0[╗___________o>\n\nfind . -empty -type d -print -delete\n./.git/branches\n./.git/objects/info\n./.git/refs/tags\n|01:33:31|bryan@LAPTOP-9LGJ3JGS:[DS-ALGO-OFFICIAL-master] DS-ALGO-OFFICIAL-master_exitstatus:0[╗___________o></code></pre></div>\n<blockquote>\n<p><strong>The command seen below deletes .git folders as well as .gitignore, .gitattributes, .gitmodule files</strong></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . \\( -name \".git\" -o -name \".gitignore\" -o -name \".gitmodules\" -o -name \".gitattributes\" \\) -exec rm -rf -- {} +</code></pre></div>\n<p><strong>The command seen below deletes most SECURITY, RELEASE, CHANGELOG, LICENSE, CONTRIBUTING, &#x26; HISTORY files that take up pointless space in repo's you wish to keep exclusively for your own reference.</strong></p>\n<h3>!!!Use with caution as this command removes the attribution of the work from it's original authors!!!!!</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*r5dGhtbeZ4VdO54U\" alt=\"!!!Use with caution as this command removes the attribution of the work from it's original authors!!!!!\" class=\"graf-image\" />\n<figcaption>!!!Use with caution as this command removes the attribution of the work from it's original authors!!!!!</figcaption>\n</figure>find . \\( -name \"*SECURITY.txt\" -o -name \"*RELEASE.txt\" -o  -name \"*CHANGELOG.txt\" -o -name \"*LICENSE.txt\" -o -name \"*CONTRIBUTING.txt\" -name \"*HISTORY.md\" -o -name \"*LICENSE\" -o -name \"*SECURITY.md\" -o -name \"*RELEASE.md\" -o  -name \"*CHANGELOG.md\" -o -name \"*LICENSE.md\" -o -name \"*CODE_OF_CONDUCT.md\" -o -name \"*CONTRIBUTING.md\" \\) -exec rm -rf -- {} +\n<hr>\n<h3>4.) Generate index.html file that links to all other files in working directory:</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#!/bin/sh\n# find ./ | grep -i \"\\.*$\" >files\nfind ./ | sed -E -e 's/([^ ]+[ ]+){8}//' | grep -i \"\\.*$\">files\nlisting=\"files\"\nout=\"\"\nhtml=\"index.html\"\nout=\"basename $out.html\"\nhtml=\"index.html\"\ncmd() {\n  echo '  &lt;!DOCTYPE html>'\n  echo '&lt;html>'\n  echo '&lt;head>'\n  echo '  &lt;meta http-equiv=\"Content-Type\" content=\"text/html\">'\n  echo '  &lt;meta name=\"Author\" content=\"Bryan Guner\">'\n  echo '&lt;link rel=\"stylesheet\" href=\"./assets/prism.css\">'\n  echo ' &lt;link rel=\"stylesheet\" href=\"./assets/style.css\">'\n  echo ' &lt;script async defer src=\"./assets/prism.js\"></code></pre></div>\n<p></script>'\necho \" <title> directory </title>\"\necho \"\"\necho '<style>'\necho ' a {'\necho ' color: black;'\necho ' }'\necho ''\necho ' li {'\necho ' border: 1px solid black !important;'\necho ' font-size: 20px;'\necho ' letter-spacing: 0px;'\necho ' font-weight: 700;'\necho ' line-height: 16px;'\necho ' text-decoration: none !important;'\necho ' text-transform: uppercase;'\necho ' background: #194ccdaf !important;'\necho ' color: black !important;'\necho ' border: none;'\necho ' cursor: pointer;'\necho ' justify-content: center;'\necho ' padding: 30px 60px;'\necho ' height: 48px;'\necho ' text-align: center;'\necho ' white-space: normal;'\necho ' border-radius: 10px;'\necho ' min-width: 45em;'\necho ' padding: 1.2em 1em 0;'\necho ' box-shadow: 0 0 5px;'\necho ' margin: 1em;'\necho ' display: grid;'\necho ' -webkit-border-radius: 10px;'\necho ' -moz-border-radius: 10px;'\necho ' -ms-border-radius: 10px;'\necho ' -o-border-radius: 10px;'\necho ' }'\necho ' </style>'\necho '</head>'\necho '<body>'\necho \"\" # continue with the HTML stuff\necho \"\"\necho \"\"\necho \"<ul>\"\nawk '{print \"<li>\n&#x3C;a href=\"\"$1\"\">\",$1,\" </a></p>\n</li>\"}' $listing\n      # awk '{print \"<li>\"};\n      #  {print \" <a href=\\\"\"$1\"\\\">\",$1,\"</a>\n</li>&nbsp;\"}' \\ $listing\n      echo \"\"\n      echo \"</ul>\"\n      echo \"</body>\"\n      echo \"</html>\"\n    }\n    cmd $listing --sort=extension >>$html\n<h4>In Action:</h4>\n<p><strong>I will use this copy of my Data Structures Practice Site to demonstrate the result:</strong></p>\n<a href=\"https://github.com/side-projects-42/DS-Bash-Examples-Deploy\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/side-projects-42/DS-Bash-Examples-Deploy\">\n<strong>side-projects-42/DS-Bash-Examples-Deploy</strong>\n<br />\n<em>Deployment github-pages Navigation Big O notation is the language we use for talking about how long an algorithm takes…</em>github.com</a>\n<a href=\"https://github.com/side-projects-42/DS-Bash-Examples-Deploy\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*PuuDTUviX5G6mja-5eKUIw.png\" class=\"graf-image\" />\n</figure>#### The result is a index.html file that contains a list of links to each file in the directory:\n<blockquote>\n<p>here is a link to and photo of the resulting html file:</p>\n</blockquote>\n<a href=\"https://quirky-meninsky-4181b5.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://quirky-meninsky-4181b5.netlify.app/\">\n<strong>index.html</strong>\n<br />\n<em>CONTENT/DS-n-Algos/</em>quirky-meninsky-4181b5.netlify.app</a>\n<a href=\"https://quirky-meninsky-4181b5.netlify.app/\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*AOYbWvUGN9yJ4ceNzAGGsw.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>5.) Download all links to a files of a specified extension on a user provided (url) webpage:</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">wget -r -A.pdf https://overapi.com/gitwget --wait=2 --level=inf --limit-rate=20K --recursive --page-requisites --user-agent=Mozilla --no-parent --convert-links --adjust-extension --no-clobber -e robots=off</code></pre></div>\n<blockquote>\n<p>The result is stored in <a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/5-download-all-pdf\" class=\"markup--anchor markup--blockquote-anchor\">this directory:</a></p>\n</blockquote>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*8evVPO_z-_TATzkcDTp15Q.png\" class=\"graf-image\" />\n</figure>\n<hr>\n<h3>6.)Recursively remove lines of text containing the string badFolder from files in the working directory.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -type f -exec sed -i '/badFolder/d' ./* {} \\;\n\n# OR\n\nfind . -name 'result.md'  -type f -exec sed -i '/badFolder/d' ./* {} \\;</code></pre></div>\n<p><strong>As an example I will run this command on a file containing the text:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Hacks Blog\n\nRead more at hacks.mozilla.org\n\nbadFolder\n\nbadFolder Implementing Private Fields for JavaScript\n\nWhen implementing a language feature for JavaScript, an implementer must make decisions about how the language in the specification maps to the implementation. Private fields is an example of where the specification language and implementation reality diverge, at least in SpiderMonkey- the JavaScript engine which powers Firefox. To understand more, I'll explain what private fields are, a couple of models for thinking about them, and explain why our implementation diverges from the specification language.The post Implementing Private Fields for JavaScript appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Tuesday, June 8, 2021 by Matthew Gaudet\n\nLooking fine with Firefox 89\n\nFirefox 89 has smartened up and brings with it a slimmed-down, slightly more minimalist interface.badFolder Along with this new look, we get some great styling features including a force-colours feature for media queries and better control over how fonts are displayed. The long-awaited top-level await keyword for JavaScript modules is now enabled, as well as the PerformanceEventTiming interface, which is another addition to the performance suite of APIs: 89 really has been working out!The post Looking fine with Firefox 89 appeared first on Mozilla Hacks - the Web developer blog.\n\nbadFolder\n\nPosted Tuesday, June 1, 2021 by Chris Mills\n\nbadFolder\n\nImproving Firefox stability on Linux\n\nRoughly a year ago at Mozilla we started an effort to improve Firefox stability on Linux. This effort quickly became an example of good synergies between FOSS projects.The post Improving Firefox stability on Linux appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Wednesday, May 19, 2021 by Gabriele Svelto badFolder\n\nIntroducing Firefox's new Site Isolation Security Architecture\n\nLike any web browser, Firefox loads code from untrusted and potentially hostile websites and runs it on your computer. To protect you against new types of attacks from malicious sites and to meet the security principles of Mozilla, we set out to redesign Firefox on desktop.The post Introducing Firefox's new Site Isolation Security Architecture appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Tuesday, May 18, 2021 by Anny Gakhokidze\n\nPyodide Spin Out and 0.17 Release\n\nWe are happy to announce that Pyodide has become an independent and community-driven project. We are also pleased to announce the 0.17 release for Pyodide with many new features and improvements. Pyodide consists of the CPython 3.8 interpreter compiled to WebAssembly which allows Python to run in the browser.The post Pyodide Spin Out and 0.17 Release appeared first on Mozilla Hacks - the Web developer blog. badFolder\n\nPosted Thursday, April 22, 2021 by Teon Brooks</code></pre></div>\n<p><strong><em>I modified the command slightly to apply only to files called 'result.md':</em></strong></p>\n<blockquote>\n<p>The result is :</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Hacks Blog\n\nRead more at hacks.mozilla.org\n\nWhen implementing a language feature for JavaScript, an implementer must make decisions about how the language in the specification maps to the implementation. Private fields is an example of where the specification language and implementation reality diverge, at least in SpiderMonkey- the JavaScript engine which powers Firefox. To understand more, I'll explain what private fields are, a couple of models for thinking about them, and explain why our implementation diverges from the specification language.The post Implementing Private Fields for JavaScript appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Tuesday, June 8, 2021 by Matthew Gaudet\n\nLooking fine with Firefox 89\n\nPosted Tuesday, June 1, 2021 by Chris Mills\n\nImproving Firefox stability on Linux\n\nRoughly a year ago at Mozilla we started an effort to improve Firefox stability on Linux. This effort quickly became an example of good synergies between FOSS projects.The post Improving Firefox stability on Linux appeared first on Mozilla Hacks - the Web developer blog.\n\nIntroducing Firefox's new Site Isolation Security Architecture\n\nLike any web browser, Firefox loads code from untrusted and potentially hostile websites and runs it on your computer. To protect you against new types of attacks from malicious sites and to meet the security principles of Mozilla, we set out to redesign Firefox on desktop.The post Introducing Firefox's new Site Isolation Security Architecture appeared first on Mozilla Hacks - the Web developer blog.\n\nPosted Tuesday, May 18, 2021 by Anny Gakhokidze\n\nPyodide Spin Out and 0.17 Release\n\nPosted Thursday, April 22, 2021 by Teon Brooks</code></pre></div>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*Up5as-MkHcHbvI_qX1AqPw.png\" class=\"graf-image\" />\n</figure>\n<p><strong>the test.txt and result.md files can be found here:</strong></p>\n<a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/6-remove-lines-contaning-bad-text\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/6-remove-lines-contaning-bad-text\">\n<strong>bgoonz/bash-commands-walkthrough</strong>\n<br />\n<em>to accompany the medium article I am writing. Contribute to bgoonz/bash-commands-walkthrough development by creating an…</em>github.com</a>\n<a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/6-remove-lines-contaning-bad-text\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<hr>\n<h3>7.) Execute command recursively:</h3>\n<p><strong>Here I have modified the command I wish to run recursively to account for the fact that the 'find' command already works recursively, by appending the -maxdepth 1 flag…</strong></p>\n<blockquote>\n<p><strong>I am essentially removing the recursive action of the find command…</strong></p>\n</blockquote>\n<p><strong>That way, if the command affects the more deeply nested folders we know the outer RecurseDirs function we are using to run the <em>find/pandoc</em> line once in every subfolder of the working directory… is working properly!</strong></p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/600/1*5C_uzLnuCSlTiioi2EtnUA.png\" class=\"graf-image\" />\n</figure>**Run in the folder shown to the left… we would expect every .md file to be accompanied by a newly generated html file by the same name.**\n<p><strong>The results of said operation can be found in the</strong> <a href=\"https://github.com/bgoonz/bash-commands-walkthrough/tree/master/steps/7-recursive-run\" class=\"markup--anchor markup--p-anchor\">\n<strong>following directory</strong>\n</a></p>\n<h4>In Action:</h4>\n<p>🢃 Below 🢃</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*k9c1QRKY07TLJnp9Se89lQ.gif\" class=\"graf-image\" />\n</figure>\n<h4>The final result is:</h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*jqrjNeBuRmTrDt3vmQ50LQ.png\" class=\"graf-image\" />\n</figure>\n<p><em>If you want to run any bash script recursively all you have to do is substitue out line #9 with the command you want to run once in every sub-folder.</em></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function RecurseDirs ()\n{\n    oldIFS=$IFS\n    IFS=$'\\n'\n    for f in \"$@\"\n    do\n\n#Replace the line below with your own command!\n\n#find ./ -iname \"*.md\" -maxdepth 1 -type f -exec sh -c 'pandoc --standalone \"${0}\" -o \"${0%.md}.html\"' {} \\;\n\n#####################################################\n# YOUR CODE BELOW!\n\n#####################################################\n\nif [[ -d \"${f}\" ]]; then\n            cd \"${f}\"\n            RecurseDirs $(ls -1 \".\")\n            cd ..\n        fi\n    done\n    IFS=$oldIFS\n}\nRecurseDirs \"./\"</code></pre></div>\n<hr>\n<h3>TBC….</h3>\n<p><strong>Here are some of the other commands I will cover in greater detail… at a later time:</strong></p>\n<h3>9. Copy any text between &#x3C;script> tags in a file called example.html to be inserted into a new file: out.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sed -n -e '/&lt;script>/,/&lt;\\/script>/p' example.html >out.js</code></pre></div>\n<hr>\n<h3>10. Recursively Delete node_modules folders</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -name 'node_modules' -type d -print -prune -exec rm -rf '{}' +</code></pre></div>\n<hr>\n<h3>11. Sanatize file and folder names to remove illegal characters and reserved words.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sanitize() {\n  shopt -s extglob;\n\n  filename=$(basename \"$1\")\n  directory=$(dirname \"$1\")\n\n  filename_clean=$(echo \"$filename\" | sed -e 's/[\\\\/:\\*\\?\"&lt;>\\|\\x01-\\x1F\\x7F]//g' -e 's/^\\(nul\\|prn\\|con\\|lpt[0-9]\\|com[0-9]\\|aux\\)\\(\\.\\|$\\)//i' -e 's/^\\.*$//' -e 's/^$/NONAME/')\n\n  if (test \"$filename\" != \"$filename_clean\")\n  then\n    mv -v \"$1\" \"$directory/$filename_clean\"\n  fi\n}\n\nexport -f sanitize\n\nsanitize_dir() {\n  find \"$1\" -depth -exec bash -c 'sanitize \"$0\"' {} \\;\n\n}\n\nsanitize_dir '/path/to/somewhere'</code></pre></div>\n<hr>\n<h3>12. Start postgresql in terminal</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sudo -u postgres psql</code></pre></div>\n<hr>\n<h3>13. Add closing body and script tags to each html file in working directory.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">for f in * ; do\n  mv \"$f\" \"$f.html\"\ndoneecho \"&lt;form>\n &lt;input type=\"button\" value=\"Go back!\" onclick=\"history.back()\">\n&lt;/form>\n  &lt;/body></code></pre></div>\n</html>\" | tee -a *.html\n<hr>\n<h3>14. Batch Download Videos</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">#!/bin/bash\n\nlink=\"#insert url here#\"\n#links were a set of strings with just the index of the video as the variable\n\nnum=3\n#first video was numbered 3 - weird.\n\next=\".mp4\"\n\nwhile [ $num -le 66 ]\ndo\n      wget $link$num$ext -P ~/Downloads/\n      num=$(($num+1))\ndone</code></pre></div>\n<hr>\n<h3>15. Change File Extension from '.txt' to .doc for all files in working directory.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">sudo apt install rename\n\nrename 's/\\.txt$/.doc/' *.txt</code></pre></div>\n<h3>16. Recursivley change any file with extension .js.download to .js</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -name \"*.\\.js\\.download\" -exec rename 's/\\.js\\.download$/.js/' '{}' +</code></pre></div>\n<hr>\n<h3>17. Copy folder structure including only files of a specific extension into an ouput Folder</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">find . -name '*.md' | cpio -pdm './../outputFolder'</code></pre></div>\n<hr>\n<h3>Discover More:</h3>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bgoonz-blog.netlify.app/\">\n<strong>Web-Dev-Hub</strong>\n<br />\n<em>Memoization, Tabulation, and Sorting Algorithms by Example Why is looking at runtime not a reliable method of…</em>bgoonz-blog.netlify.app</a>\n<a href=\"https://bgoonz-blog.netlify.app/\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>Part 2 of this series:</h3>\n<a href=\"https://medium.com/@bryanguner/life-saving-bash-scripts-part-2-b40c8ee22682\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://medium.com/@bryanguner/life-saving-bash-scripts-part-2-b40c8ee22682\">\n<strong>Medium</strong>\n<br />\n<em>Continued!!!medium.com</em>\n</a>\n<a href=\"https://medium.com/@bryanguner/life-saving-bash-scripts-part-2-b40c8ee22682\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<hr>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/920fb6ab9d0a\">June 29, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/bash-commands-that-save-time-920fb6ab9d0a\" class=\"p-canonical\">Canonical link</a></p>\n<p>August 31, 2021.</p>\n<h1>Resources:</h1>\n<ul>\n<li><a href=\"https://gist.github.com/bgoonz/df74dfa73bb5edd239ac738a14104eee\">holy grail</a></li>\n</ul>\n<h1>1. Remove spaces from file and folder names and then remove numbers from files and folder names....</h1>\n<h3>Description: need to : <code class=\"language-text\">sudo apt install rename</code></h3>\n<blockquote>\n<p>Notes: Issue when renaming file without numbers collides with existing file name...</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/ /_/g'</span>\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/ /_/g'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">``<span class=\"token variable\"><span class=\"token variable\">`</span>shell\n<span class=\"token function\">find</span> $dir <span class=\"token parameter variable\">-type</span> f <span class=\"token operator\">|</span> <span class=\"token function\">sed</span> <span class=\"token string\">'s|\\(.*/\\)[^A-Z]*\\([A-Z].*\\)|mv \\\"&amp;\\\" \\\"\\1\\2\\\"|'</span> <span class=\"token operator\">|</span> <span class=\"token function\">sh</span>\n\n<span class=\"token function\">find</span> $dir <span class=\"token parameter variable\">-type</span> d <span class=\"token operator\">|</span> <span class=\"token function\">sed</span> <span class=\"token string\">'s|\\(.*/\\)[^A-Z]*\\([A-Z].*\\)|mv \\\"&amp;\\\" \\\"\\1\\2\\\"|'</span> <span class=\"token operator\">|</span> <span class=\"token function\">sh</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">i</span> <span class=\"token keyword\">in</span> *.html<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">$i</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${i<span class=\"token operator\">%</span>-*}</span>.html\"</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">i</span> <span class=\"token keyword\">in</span> *.*<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">$i</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${i<span class=\"token operator\">%</span>-*}</span>.<span class=\"token variable\">${i<span class=\"token operator\">##</span>*.}</span>\"</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span>\n\n---\n<span class=\"token comment\">### Description: combine the contents of every file in the contaning directory.</span>\n\n<span class=\"token operator\">></span>Notes: this includes the contents of the <span class=\"token function\">file</span> it's self<span class=\"token punctuation\">..</span>.\n\n<span class=\"token comment\">###### code:</span>\n\n<span class=\"token variable\">`</span></span>``js\n//\n//APPEND-DIR.js\nconst fs <span class=\"token operator\">=</span> require<span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token builtin class-name\">let</span> <span class=\"token function\">cat</span> <span class=\"token operator\">=</span> require<span class=\"token punctuation\">(</span><span class=\"token string\">'child_process'</span><span class=\"token punctuation\">)</span>\n  .execSync<span class=\"token punctuation\">(</span><span class=\"token string\">'cat *'</span><span class=\"token punctuation\">)</span>\n  .toString<span class=\"token punctuation\">(</span><span class=\"token string\">'UTF-8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nfs.writeFile<span class=\"token punctuation\">(</span><span class=\"token string\">'output.md'</span>, cat, err <span class=\"token operator\">=</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> throw err<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h1>2. Download Website Using Wget:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes: ==> sudo apt install wget</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">wget</span> --limit-rate<span class=\"token operator\">=</span>200k --no-clobber --convert-links --random-wait <span class=\"token parameter variable\">-r</span> <span class=\"token parameter variable\">-p</span> <span class=\"token parameter variable\">-E</span> <span class=\"token parameter variable\">-e</span> <span class=\"token assign-left variable\">robots</span><span class=\"token operator\">=</span>off <span class=\"token parameter variable\">-U</span> mozilla https://bootcamp42.gitbook.io/python/</code></pre></div>\n<hr>\n<h1>3. Clean Out Messy Git Repo:</h1>\n<h3>Description: recursively removes git related folders as well as internal use files / attributions in addition to empty folders</h3>\n<blockquote>\n<p>Notes: To clear up clutter in repositories that only get used on your local machine.</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-empty</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-print</span> <span class=\"token parameter variable\">-delete</span>\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">(</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\".git\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\".gitignore\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\".gitmodules\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\".gitattributes\"</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">)</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> -- <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">(</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*SECURITY.txt\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*RELEASE.txt\"</span> <span class=\"token parameter variable\">-o</span>  <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CHANGELOG.txt\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*LICENSE.txt\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CONTRIBUTING.txt\"</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*HISTORY.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*LICENSE\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*SECURITY.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*RELEASE.md\"</span> <span class=\"token parameter variable\">-o</span>  <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CHANGELOG.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*LICENSE.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CODE_OF_CONDUCT.md\"</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*CONTRIBUTING.md\"</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">)</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> -- <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<hr>\n<h1>4. clone all of a user's git repositories</h1>\n<h3>Description: clone all of a user or organization's git repositories.</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<h1>Generalized:</h1>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token assign-left variable\">CNTX</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>users<span class=\"token operator\">|</span>orgs<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">NAME</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>username<span class=\"token operator\">|</span>orgname<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">PAGE</span><span class=\"token operator\">=</span><span class=\"token number\">1</span>\n<span class=\"token function\">curl</span> <span class=\"token string\">\"https://api.github.com/<span class=\"token variable\">$CNTX</span>/<span class=\"token variable\">$NAME</span>/repos?page=<span class=\"token variable\">$PAGE</span>&amp;per_page=100\"</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'git_url*'</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">cut</span> <span class=\"token parameter variable\">-d</span> <span class=\"token punctuation\">\\</span>\" <span class=\"token parameter variable\">-f</span> <span class=\"token number\">4</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-L1</span> <span class=\"token function\">git</span> clone</code></pre></div>\n<h1>Clone all Git User</h1>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token assign-left variable\">CNTX</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>users<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">NAME</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>bgoonz<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">PAGE</span><span class=\"token operator\">=</span><span class=\"token number\">1</span>\n<span class=\"token function\">curl</span> <span class=\"token string\">\"https://api.github.com/<span class=\"token variable\">$CNTX</span>/<span class=\"token variable\">$NAME</span>/repos?page=<span class=\"token variable\">$PAGE</span>&amp;per_page=200\"</span>?branch<span class=\"token operator\">=</span>master <span class=\"token operator\">|</span>\n  <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'git_url*'</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">cut</span> <span class=\"token parameter variable\">-d</span> <span class=\"token punctuation\">\\</span>\" <span class=\"token parameter variable\">-f</span> <span class=\"token number\">4</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-L1</span> <span class=\"token function\">git</span> clone</code></pre></div>\n<h1>Clone all Git Organization:</h1>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token assign-left variable\">CNTX</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>organizations<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">NAME</span><span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>TheAlgorithms<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token assign-left variable\">PAGE</span><span class=\"token operator\">=</span><span class=\"token number\">1</span>\n<span class=\"token function\">curl</span> <span class=\"token string\">\"https://api.github.com/<span class=\"token variable\">$CNTX</span>/<span class=\"token variable\">$NAME</span>/repos?page=<span class=\"token variable\">$PAGE</span>&amp;per_page=200\"</span>?branch<span class=\"token operator\">=</span>master <span class=\"token operator\">|</span>\n  <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'git_url*'</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">cut</span> <span class=\"token parameter variable\">-d</span> <span class=\"token punctuation\">\\</span>\" <span class=\"token parameter variable\">-f</span> <span class=\"token number\">4</span> <span class=\"token operator\">|</span>\n  <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-L1</span> <span class=\"token function\">git</span> clone</code></pre></div>\n<hr>\n<h1>5. Git Workflow</h1>\n<h3>Description:</h3>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> pull\n<span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin master</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin main</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin bryan-guner</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin gh-pages</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> init\n<span class=\"token function\">git</span> <span class=\"token function\">add</span> <span class=\"token builtin class-name\">.</span>\n<span class=\"token function\">git</span> commit -m<span class=\"token string\">\"update\"</span>\n<span class=\"token function\">git</span> push <span class=\"token parameter variable\">-u</span> origin preview</code></pre></div>\n<hr>\n<h1>6. Recursive Unzip In Place</h1>\n<h3>Description: recursively unzips folders and then deletes the zip file by the same name.</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*.zip\"</span> <span class=\"token operator\">|</span> <span class=\"token keyword\">while</span> <span class=\"token builtin class-name\">read</span> filename<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">unzip</span> <span class=\"token parameter variable\">-o</span> <span class=\"token parameter variable\">-d</span> <span class=\"token string\">\"<span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token function\">dirname</span> <span class=\"token string\">\"<span class=\"token variable\">$filename</span>\"</span><span class=\"token variable\">`</span></span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">$filename</span>\"</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"*.zip\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-print</span> <span class=\"token parameter variable\">-delete</span></code></pre></div>\n<hr>\n<h1>7. git pull keeping local changes:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> stash\n<span class=\"token function\">git</span> pull\n<span class=\"token function\">git</span> stash pop</code></pre></div>\n<hr>\n<h1>8. Prettier Code Formatter:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">npm</span> i prettier <span class=\"token parameter variable\">-g</span>\n\nprettier <span class=\"token parameter variable\">--write</span> <span class=\"token builtin class-name\">.</span></code></pre></div>\n<hr>\n<h1>9. Pandoc</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> ./ <span class=\"token parameter variable\">-iname</span> <span class=\"token string\">\"*.md\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sh</span> <span class=\"token parameter variable\">-c</span> <span class=\"token string\">'pandoc --standalone \"${0}\" -o \"${0%.md}.html\"'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">find</span> ./ <span class=\"token parameter variable\">-iname</span> <span class=\"token string\">\"*.html\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sh</span> <span class=\"token parameter variable\">-c</span> <span class=\"token string\">'pandoc --wrap=none --from html --to markdown_strict \"${0}\" -o \"${0%.html}.md\"'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">find</span> ./ <span class=\"token parameter variable\">-iname</span> <span class=\"token string\">\"*.docx\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sh</span> <span class=\"token parameter variable\">-c</span> <span class=\"token string\">'pandoc \"${0}\" -o \"${0%.docx}.md\"'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h1>10. Gitpod Installs</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> tree\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> pandoc <span class=\"token parameter variable\">-y</span>\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">rename</span> <span class=\"token parameter variable\">-y</span>\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> black <span class=\"token parameter variable\">-y</span>\n<span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">wget</span> <span class=\"token parameter variable\">-y</span>\n<span class=\"token function\">npm</span> i lebab <span class=\"token parameter variable\">-g</span>\n<span class=\"token function\">npm</span> i prettier <span class=\"token parameter variable\">-g</span>\n<span class=\"token function\">npm</span> i npm-recursive-install <span class=\"token parameter variable\">-g</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">black <span class=\"token builtin class-name\">.</span>\n\nprettier <span class=\"token parameter variable\">--write</span> <span class=\"token builtin class-name\">.</span>\nnpm-recursive-install</code></pre></div>\n<hr>\n<h1>11. Repo Utils Package:</h1>\n<h3>Description: my standard repo utis package</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> i @bgoonz11/repoutils</code></pre></div>\n<hr>\n<h1>12. Unix Tree Package Usage:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">tree <span class=\"token parameter variable\">-d</span> <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span>\n\ntree  <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span>\n\ntree <span class=\"token parameter variable\">-f</span>  <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span> <span class=\"token operator\">></span>TREE.md\n\ntree <span class=\"token parameter variable\">-f</span> <span class=\"token parameter variable\">-L</span> <span class=\"token number\">2</span>  <span class=\"token operator\">></span>README.md\n\ntree <span class=\"token parameter variable\">-f</span>  <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span> <span class=\"token operator\">></span>listing-path.md\n\ntree <span class=\"token parameter variable\">-f</span>  <span class=\"token parameter variable\">-I</span>  <span class=\"token string\">'node_modules'</span> <span class=\"token parameter variable\">-d</span> <span class=\"token operator\">></span>TREE.md\n\ntree <span class=\"token parameter variable\">-f</span> <span class=\"token operator\">></span>README.md</code></pre></div>\n<hr>\n<h1>13. Find &#x26; Replace string in file &#x26; folder names recursively..</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/string1/string2/g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/-master//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/\\.download//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/-main//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">rename</span> <span class=\"token string\">'s/\\.js\\.download$/.js/'</span> *.js<span class=\"token punctuation\">\\</span>.download\n\n<span class=\"token function\">rename</span> <span class=\"token string\">'s/\\.html\\.markdown$/.md/'</span> *.html<span class=\"token punctuation\">\\</span>.markdown\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/es6//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<hr>\n<h1>14. Remove double extensions :</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *.md.md\n<span class=\"token keyword\">do</span>\n    <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">${file}</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${file<span class=\"token operator\">%</span>.md}</span>\"</span>\n<span class=\"token keyword\">done</span>\n\n<span class=\"token comment\">#!/bin/bash</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *.html.html\n<span class=\"token keyword\">do</span>\n    <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">${file}</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${file<span class=\"token operator\">%</span>.html}</span>\"</span>\n<span class=\"token keyword\">done</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *.html.png\n<span class=\"token keyword\">do</span>\n    <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">${file}</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${file<span class=\"token operator\">%</span>.png}</span>\"</span>\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">file</span> <span class=\"token keyword\">in</span> *.jpg.jpg\n<span class=\"token keyword\">do</span>\n    <span class=\"token function\">mv</span> <span class=\"token string\">\"<span class=\"token variable\">${file}</span>\"</span> <span class=\"token string\">\"<span class=\"token variable\">${file<span class=\"token operator\">%</span>.png}</span>\"</span>\n<span class=\"token keyword\">done</span></code></pre></div>\n<hr>\n<h1>15. Truncate folder names down to 12 characters:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">d</span> <span class=\"token keyword\">in</span> ./*<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">mv</span> <span class=\"token variable\">$d</span> <span class=\"token variable\">${d<span class=\"token operator\">:</span>0<span class=\"token operator\">:</span>12}</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span></code></pre></div>\n<hr>\n<h1>16.Appendir.js</h1>\n<h3>Description: combine the contents of every file in the contaning directory.</h3>\n<blockquote>\n<p>Notes: this includes the contents of the file it's self...</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">//APPEND-DIR.js</span>\n<span class=\"token keyword\">const</span> fs <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'fs'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> cat <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'child_process'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">execSync</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cat *'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token string\">'UTF-8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">writeFile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'output.md'</span><span class=\"token punctuation\">,</span> cat<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> err<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h1>17. Replace space in filename with underscore</h1>\n<h3>Description: followed by replace <code class=\"language-text\">'#' with '_'</code> in directory name</h3>\n<blockquote>\n<p>Notes: Can be re-purposed to find and replace any set of strings in file or folder names.</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/_//g'</span>\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/#/_/g'</span></code></pre></div>\n<hr>\n<h1>18. Filter &#x26; delete files by name and extension</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'.bin'</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'*.html'</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'nav-index'</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'node-gyp'</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'deleteme.txt'</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'right.html'</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">'left.html'</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-prune</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token string\">'{}'</span> +</code></pre></div>\n<hr>\n<h1>19. Remove lines containing string:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes: Remove lines not containing <code class=\"language-text\">'.js'</code></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/\\.js/!d'</span> ./*scrap2.md</code></pre></div>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/githubusercontent/d'</span> ./*sandbox.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/githubusercontent/d'</span> ./*scrap2.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/github\\.com/d'</span> ./*out.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/author/d'</span> ./*</code></pre></div>\n<hr>\n<h1>20. Remove duplicate lines from a text file</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:\n//...syntax of uniq...//\n$uniq [OPTION] [INPUT[OUTPUT]]\nThe syntax of this is quite easy to understand. Here, INPUT refers to the input file in which repeated lines need to be filtered out and if INPUT isn't specified then uniq reads from the standard input. OUTPUT refers to the output file in which you can store the filtered output generated by uniq command and as in case of INPUT if OUTPUT isn't specified then uniq writes to the standard output.</p>\n</blockquote>\n<p>Now, let's understand the use of this with the help of an example. Suppose you have a text file named kt.txt which contains repeated lines that needs to be omitted. This can simply be done with uniq.</p>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">uniq</span>\n<span class=\"token function\">uniq</span> <span class=\"token parameter variable\">-u</span> input.txt output.txt</code></pre></div>\n<hr>\n<h1>21. Remove lines containing string:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/githubusercontent/d'</span> ./*sandbox.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/githubusercontent/d'</span> ./*scrap2.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/github\\.com/d'</span> ./*out.md\n\n---\ntitle: add_days\ntags: date,intermediate\nfirstSeen: <span class=\"token number\">2020</span>-10-28T16:19:04+02:00\nlastUpdated: <span class=\"token number\">2020</span>-10-28T16:19:04+02:00\n---\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/title:/d'</span> ./*output.md\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/firstSeen/d'</span> ./*output.md\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/lastUpdated/d'</span> ./*output.md\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/tags:/d'</span> ./*output.md\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/badstring/d'</span> ./*\n\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/stargazers/d'</span> ./repo.txt\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/node_modules/d'</span> ./index.html\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/right\\.html/d'</span> ./index.html\n<span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'/right\\.html/d'</span> ./right.html</code></pre></div>\n<hr>\n<h1>22. Zip directory excluding .git and node_modules all the way down (Linux)</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n<span class=\"token assign-left variable\">TSTAMP</span><span class=\"token operator\">=</span><span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token function\">date</span> <span class=\"token string\">'+%Y%m%d-%H%M%S'</span><span class=\"token variable\">`</span></span>\n<span class=\"token function\">zip</span> <span class=\"token parameter variable\">-r</span> <span class=\"token variable\">$1</span><span class=\"token builtin class-name\">.</span><span class=\"token variable\">$TSTAMP</span>.zip <span class=\"token variable\">$1</span> <span class=\"token parameter variable\">-x</span> <span class=\"token string\">\"**.git/*\"</span> <span class=\"token parameter variable\">-x</span> <span class=\"token string\">\"**node_modules/*\"</span> <span class=\"token variable\"><span class=\"token variable\">`</span><span class=\"token builtin class-name\">shift</span><span class=\"token punctuation\">;</span> <span class=\"token builtin class-name\">echo</span> $@<span class=\"token punctuation\">;</span><span class=\"token variable\">`</span></span>\n\n<span class=\"token builtin class-name\">printf</span> <span class=\"token string\">\"<span class=\"token entity\" title=\"\\n\">\\n</span>Created: <span class=\"token variable\">$1</span>.<span class=\"token variable\">$TSTAMP</span>.zip<span class=\"token entity\" title=\"\\n\">\\n</span>\"</span>\n\n<span class=\"token comment\"># usage:</span>\n<span class=\"token comment\"># - zipdir thedir</span>\n<span class=\"token comment\"># - zip thedir -x \"**anotherexcludedsubdir/*\"    (important the double quotes to prevent glob expansion)</span>\n\n<span class=\"token comment\"># if in windows/git-bash, add 'zip' command this way:</span>\n<span class=\"token comment\"># https://stackoverflow.com/a/55749636/1482990</span></code></pre></div>\n<hr>\n<h1>23. Delete files containing a certain string:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-l</span> www.redhat.com <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> <span class=\"token string\">'{print \"rm \"$1}'</span> <span class=\"token operator\">></span> doit.sh\n<span class=\"token function\">vi</span> doit.sh // check <span class=\"token keyword\">for</span> murphy and his law\n<span class=\"token builtin class-name\">source</span> doit.sh</code></pre></div>\n<hr>\n<h1>24.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/sh</span>\n\n<span class=\"token comment\"># find ./ | grep -i \"\\.*$\" >files</span>\n<span class=\"token function\">find</span> ./ <span class=\"token operator\">|</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-E</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'s/([^ ]+[ ]+){8}//'</span> <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">\"\\.*$\"</span><span class=\"token operator\">></span>files\n<span class=\"token assign-left variable\">listing</span><span class=\"token operator\">=</span><span class=\"token string\">\"files\"</span>\n\n<span class=\"token assign-left variable\">out</span><span class=\"token operator\">=</span><span class=\"token string\">\"\"</span>\n\n<span class=\"token assign-left variable\">html</span><span class=\"token operator\">=</span><span class=\"token string\">\"sitemap.html\"</span>\n<span class=\"token assign-left variable\">out</span><span class=\"token operator\">=</span><span class=\"token string\">\"basename <span class=\"token variable\">$out</span>.html\"</span>\n<span class=\"token assign-left variable\">html</span><span class=\"token operator\">=</span><span class=\"token string\">\"sitemap.html\"</span>\n<span class=\"token function-name function\">cmd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;!DOCTYPE html>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;html>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;head>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;meta http-equiv=\"Content-Type\" content=\"text/html\">'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;meta name=\"Author\" content=\"Bryan Guner\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;link rel=\"stylesheet\" href=\"./assets/prism.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">' &lt;link rel=\"stylesheet\" href=\"./assets/style.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">' &lt;script async defer src=\"./assets/prism.js\">\n&lt;/script>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"  &lt;title> directory &lt;/title>\"</span>\n    <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/bgoonz/GIT-CDN-FILES/mdn-article.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/gh/bgoonz/GIT-CDN-FILES/markdown-to-html-style.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;style>'</span>\n\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    a {'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      color: black;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    }'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">''</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    li {'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border: 1px solid black !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      font-size: 20px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      letter-spacing: 0px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      font-weight: 700;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      line-height: 16px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-decoration: none !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-transform: uppercase;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      background: #194ccdaf !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      color: black !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border: none;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      cursor: pointer;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      justify-content: center;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      padding: 30px 60px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      height: 48px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-align: center;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      white-space: normal;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      min-width: 45em;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      padding: 1.2em 1em 0;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      box-shadow: 0 0 5px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      margin: 1em;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      display: grid;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -webkit-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -moz-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -ms-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -o-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    }'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;/style>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;/head>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;body>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token comment\"># continue with the HTML stuff</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;ul>\"</span>\n\n  <span class=\"token function\">awk</span> <span class=\"token string\">'{print \"&lt;li>\n&lt;a href=\\\"\"$1\"\\\">\",$1,\"&amp;nbsp;&lt;/a>\n&lt;/li>\"}'</span> <span class=\"token variable\">$listing</span>\n\n  <span class=\"token comment\"># awk '{print \"&lt;li>\"};</span>\n\n  <span class=\"token comment\"># \t{print \" &lt;a href=\\\"\"$1\"\\\">\",$1,\"&lt;/a></span>\n<span class=\"token operator\">&lt;</span>/li<span class=\"token operator\">>&amp;</span>nbsp<span class=\"token punctuation\">;</span><span class=\"token string\">\"}' \\ <span class=\"token variable\">$listing</span>\n\n  echo \"</span>\"\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/ul>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/body>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/html>\"</span>\n\n<span class=\"token punctuation\">}</span>\n\ncmd <span class=\"token variable\">$listing</span> <span class=\"token parameter variable\">--sort</span><span class=\"token operator\">=</span>extension <span class=\"token operator\">>></span><span class=\"token variable\">$html</span></code></pre></div>\n<hr>\n<h1>25. Index of Iframes</h1>\n<h3>Description: Creates an index.html file that contains all the files in the working directory or any of it's sub folders as iframes instead of anchor tags.</h3>\n<blockquote>\n<p>Notes: Useful Follow up Code:</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/sh</span>\n\n<span class=\"token comment\"># find ./ | grep -i \"\\.*$\" >files</span>\n<span class=\"token function\">find</span> ./ <span class=\"token operator\">|</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-E</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">'s/([^ ]+[ ]+){8}//'</span> <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">\"\\.*$\"</span><span class=\"token operator\">></span>files\n<span class=\"token assign-left variable\">listing</span><span class=\"token operator\">=</span><span class=\"token string\">\"files\"</span>\n\n<span class=\"token assign-left variable\">out</span><span class=\"token operator\">=</span><span class=\"token string\">\"\"</span>\n\n<span class=\"token assign-left variable\">html</span><span class=\"token operator\">=</span><span class=\"token string\">\"index.html\"</span>\n<span class=\"token assign-left variable\">out</span><span class=\"token operator\">=</span><span class=\"token string\">\"basename <span class=\"token variable\">$out</span>.html\"</span>\n<span class=\"token assign-left variable\">html</span><span class=\"token operator\">=</span><span class=\"token string\">\"index.html\"</span>\n<span class=\"token function-name function\">cmd</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;!DOCTYPE html>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;html>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;head>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;meta http-equiv=\"Content-Type\" content=\"text/html\">'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;meta name=\"Author\" content=\"Bryan Guner\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;link rel=\"stylesheet\" href=\"./assets/prism.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">' &lt;link rel=\"stylesheet\" href=\"./assets/style.css\">'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">' &lt;script async defer src=\"./assets/prism.js\">\n&lt;/script>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"  &lt;title> directory &lt;/title>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;style>'</span>\n\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    a {'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      color: black;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    }'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">''</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    li {'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border: 1px solid black !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      font-size: 20px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      letter-spacing: 0px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      font-weight: 700;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      line-height: 16px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-decoration: none !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-transform: uppercase;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      background: #194ccdaf !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      color: black !important;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border: none;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      cursor: pointer;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      justify-content: center;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      padding: 30px 60px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      height: 48px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      text-align: center;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      white-space: normal;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      min-width: 45em;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      padding: 1.2em 1em 0;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      box-shadow: 0 0 5px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      margin: 1em;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      display: grid;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -webkit-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -moz-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -ms-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'      -o-border-radius: 10px;'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'    }'</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'  &lt;/style>'</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;/head>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">'&lt;body>'</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token comment\"># continue with the HTML stuff</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;ul>\"</span>\n\n  <span class=\"token function\">awk</span> <span class=\"token string\">'{print \"&lt;iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\\\"\"$1\"\\\">\",\"&lt;/iframe>\n&lt;br>\"}'</span> <span class=\"token variable\">$listing</span>\n\n  <span class=\"token comment\"># awk '{print \"&lt;li>\"};</span>\n\n  <span class=\"token comment\"># \t{print \" &lt;a href=\\\"\"$1\"\\\">\",$1,\"&lt;/a></span>\n<span class=\"token operator\">&lt;</span>/li<span class=\"token operator\">>&amp;</span>nbsp<span class=\"token punctuation\">;</span><span class=\"token string\">\"}' \\ <span class=\"token variable\">$listing</span>\n\n  echo \"</span>\"\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/ul>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/body>\"</span>\n\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"&lt;/html>\"</span>\n\n<span class=\"token punctuation\">}</span>\n\ncmd <span class=\"token variable\">$listing</span> <span class=\"token parameter variable\">--sort</span><span class=\"token operator\">=</span>extension <span class=\"token operator\">>></span><span class=\"token variable\">$html</span></code></pre></div>\n<hr>\n<h1>26. Filter Corrupted Git Repo For Troublesome File:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> filter-branch --index-filter <span class=\"token string\">'git rm -r --cached --ignore-unmatch assets/_index.html'</span> HEAD</code></pre></div>\n<hr>\n<h1>27. OVERWRITE LOCAL CHANGES:</h1>\n<h3>Description:</h3>\n<p>Important: If you have any local changes, they will be lost. With or without --hard option, any local commits that haven't been pushed will be lost.[*]\nIf you have any files that are not tracked by Git (e.g. uploaded user content), these files will not be affected.</p>\n<blockquote>\n<p>Notes:\nFirst, run a fetch to update all origin/<branch> refs to latest:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> fetch <span class=\"token parameter variable\">--all</span>\n<span class=\"token comment\"># Backup your current branch:</span>\n\n<span class=\"token function\">git</span> branch backup-master\n<span class=\"token comment\"># Then, you have two options:</span>\n\n<span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> origin/master\n<span class=\"token comment\"># OR If you are on some other branch:</span>\n\n<span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> origin/<span class=\"token operator\">&lt;</span>branch_name<span class=\"token operator\">></span>\n<span class=\"token comment\"># Explanation:</span>\n<span class=\"token comment\"># git fetch downloads the latest from remote without trying to merge or rebase anything.</span>\n\n<span class=\"token comment\"># Then the git reset resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/master</span>\n<span class=\"token function\">git</span> fetch <span class=\"token parameter variable\">--all</span>\n<span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> origin/master</code></pre></div>\n<hr>\n<h1>28. Remove Submodules:</h1>\n<h3>Description: To remove a submodule you need to:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<blockquote>\n<p>Delete the relevant section from the .gitmodules file.\nStage the .gitmodules changes git add .gitmodules\nDelete the relevant section from .git/config.\nRun git rm --cached path<em>to</em>submodule (no trailing slash).\nRun rm -rf .git/modules/path<em>to</em>submodule (no trailing slash).\nCommit git commit -m \"Removed submodule \"\nDelete the now untracked submodule files rm -rf path<em>to</em>submodule</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> submodule deinit</code></pre></div>\n<hr>\n<h1>29. GET GISTS</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token function\">install</span> <span class=\"token function\">wget</span>\n\n<span class=\"token function\">wget</span> <span class=\"token parameter variable\">-q</span> <span class=\"token parameter variable\">-O</span> - https://api.github.com/users/bgoonz/gists <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> raw_url <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> -F<span class=\"token punctuation\">\\</span>\" <span class=\"token string\">'{print $4}'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-n3</span> <span class=\"token function\">wget</span>\n\n<span class=\"token function\">wget</span> <span class=\"token parameter variable\">-q</span> <span class=\"token parameter variable\">-O</span> - https://api.github.com/users/amitness/gists <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> raw_url <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> -F<span class=\"token punctuation\">\\</span>\" <span class=\"token string\">'{print $4}'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-n3</span> <span class=\"token function\">wget</span>\n\n<span class=\"token function\">wget</span> <span class=\"token parameter variable\">-q</span> <span class=\"token parameter variable\">-O</span> - https://api.github.com/users/drodsou/gists <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> raw_url <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> -F<span class=\"token punctuation\">\\</span>\" <span class=\"token string\">'{print $4}'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-n1</span> <span class=\"token function\">wget</span>\n\n<span class=\"token function\">wget</span> <span class=\"token parameter variable\">-q</span> <span class=\"token parameter variable\">-O</span> - https://api.github.com/users/thomasmb/gists <span class=\"token operator\">|</span> <span class=\"token function\">grep</span> raw_url <span class=\"token operator\">|</span> <span class=\"token function\">awk</span> -F<span class=\"token punctuation\">\\</span>\" <span class=\"token string\">'{print $4}'</span> <span class=\"token operator\">|</span> <span class=\"token function\">xargs</span> <span class=\"token parameter variable\">-n1</span> <span class=\"token function\">wget</span></code></pre></div>\n<hr>\n<h1>30. Remove Remote OriginL</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> remote remove origin</code></pre></div>\n<hr>\n<h1>31. just clone .git folder:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> clone <span class=\"token parameter variable\">--bare</span> <span class=\"token parameter variable\">--branch</span><span class=\"token operator\">=</span>master --single-branch https://github.com/bgoonz/My-Web-Dev-Archive.git</code></pre></div>\n<hr>\n<h1>32. Undo recent pull request:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">git</span> reset <span class=\"token parameter variable\">--hard</span> master@<span class=\"token punctuation\">{</span><span class=\"token string\">\"10 minutes ago\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h1>33. Lebab</h1>\n<h3>Description: ES5 --> ES6</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># Safe:</span>\n\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arrow\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arrow-return\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-of\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-each\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-rest\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-spread\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> obj-method\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> obj-shorthand\n lebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> multi-var\n\n<span class=\"token comment\"># ALL:</span>\n\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> obj-method\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> class\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arrow\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> <span class=\"token builtin class-name\">let</span>\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-spread\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-rest\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-each\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-of\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> commonjs\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> exponent\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> multi-var\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> template\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> default-param\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span>  destruct-param\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> includes\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> obj-method\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> class\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arrow\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-spread\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> arg-rest\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-each\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> for-of\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> commonjs\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> exponent\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> multi-var\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> template\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> default-param\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span>  destruct-param\nlebab <span class=\"token parameter variable\">--replace</span> ./ <span class=\"token parameter variable\">--transform</span> includes</code></pre></div>\n<hr>\n<h1>34. Troubleshoot Ubuntu Input/Output Error</h1>\n<h3>Description: Open Powershell as Administrator...</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> wsl.exe --shutdown\n\n Get-Service LxssManager | Restart-Service</code></pre></div>\n<hr>\n<h1>35. Export Medium as Markdown</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">npm</span> i mediumexporter <span class=\"token parameter variable\">-g</span>\n\nmediumexporter https://medium.com/codex/fundamental-data-structures-in-javascript-8f9f709c15b4 <span class=\"token operator\">></span>ds.md</code></pre></div>\n<hr>\n<h1>36. Delete files in violation of a given size range (100MB for git)</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-size</span> +75M <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-print</span> <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-f</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-size</span> +98M <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-print</span> <span class=\"token parameter variable\">-a</span> <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rm</span> <span class=\"token parameter variable\">-f</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">\\</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h1>37. download all links of given file type</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">wget</span> <span class=\"token parameter variable\">-r</span> <span class=\"token parameter variable\">-A.pdf</span> https://overapi.com/git</code></pre></div>\n<hr>\n<h1>38. Kill all node processes</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">killall</span> <span class=\"token parameter variable\">-s</span> KILL <span class=\"token function\">node</span></code></pre></div>\n<hr>\n<h1>39. Remove string from file names recursively</h1>\n<h3>Description: In the example below I am using this command to remove the string \"-master\" from all file names in the working directory and all of it's sub directories.</h3>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token operator\">&lt;</span>mydir<span class=\"token operator\">></span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'s/&lt;string1>/&lt;string2>/g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/-master//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<blockquote>\n<p>Notes: The same could be done for folder names by changing the <em>-type f</em> flag (for file) to a <em>-type d</em> flag (for directory)</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token operator\">&lt;</span>mydir<span class=\"token operator\">></span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'s/&lt;string1>/&lt;string2>/g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/-master//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<hr>\n<h1>40. Remove spaces from file and folder names recursively</h1>\n<h3>Description: replaces spaces in file and folder names with an <code class=\"language-text\">_</code> underscore</h3>\n<blockquote>\n<p>Notes: need to run <code class=\"language-text\">sudo apt install rename</code> to use this command</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> d <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/ /_/g'</span>\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token string\">\"* *\"</span> <span class=\"token parameter variable\">-type</span> f <span class=\"token operator\">|</span> <span class=\"token function\">rename</span> <span class=\"token string\">'s/ /_/g'</span></code></pre></div>\n<hr>\n<h1>41. Zip Each subdirectories in a given directory into their own zip file</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">i</span> <span class=\"token keyword\">in</span> */<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span> <span class=\"token function\">zip</span> <span class=\"token parameter variable\">-r</span> <span class=\"token string\">\"<span class=\"token variable\">${i<span class=\"token operator\">%</span><span class=\"token operator\">/</span>}</span>.zip\"</span> <span class=\"token string\">\"<span class=\"token variable\">$i</span>\"</span><span class=\"token punctuation\">;</span> <span class=\"token keyword\">done</span></code></pre></div>\n<hr>\n<h1>42.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>43.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>44.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>45.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>46.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>47.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>48.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>49.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>50.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>51.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>52.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>53.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>54.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>55.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>56.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>57.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>58.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>59.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>60.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>61.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>62.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>63.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>64.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>65.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>66.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>67.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>68.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>69.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>70.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>71.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>72.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>73.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>74.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>75.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>76.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>77.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>78.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>79.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>80.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>81.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>82.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>83.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>84.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>85.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>86.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>87.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>88.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>89.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>90.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"></code></pre></div>\n<hr>\n<h1>91. Unzip PowerShell</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PARAM (\n    [string] $ZipFilesPath = \"./\",\n    [string] $UnzipPath = \"./RESULT\"\n)\n\n$Shell = New-Object -com Shell.Application\n$Location = $Shell.NameSpace($UnzipPath)\n\n$ZipFiles = Get-Childitem $ZipFilesPath -Recurse -Include *.ZIP\n\n$progress = 1\nforeach ($ZipFile in $ZipFiles) {\n    Write-Progress -Activity \"Unzipping to $($UnzipPath)\" -PercentComplete (($progress / ($ZipFiles.Count + 1)) * 100) -CurrentOperation $ZipFile.FullName -Status \"File $($Progress) of $($ZipFiles.Count)\"\n    $ZipFolder = $Shell.NameSpace($ZipFile.fullname)\n\n    $Location.Copyhere($ZipFolder.items(), 1040) # 1040 - No msgboxes to the user - https://msdn.microsoft.com/library/bb787866%28VS.85%29.aspx\n    $progress++\n}</code></pre></div>\n<hr>\n<h1>92. return to bash from zsh</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"> <span class=\"token function\">sudo</span> <span class=\"token function\">apt</span> <span class=\"token parameter variable\">--purge</span> remove <span class=\"token function\">zsh</span></code></pre></div>\n<hr>\n<h1>93. Symbolic Link</h1>\n<h3>Description: to working directory</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">ln</span> <span class=\"token parameter variable\">-s</span> <span class=\"token string\">\"<span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token builtin class-name\">pwd</span><span class=\"token variable\">)</span></span>\"</span> ~/NameOfLink\n\n<span class=\"token function\">ln</span> <span class=\"token parameter variable\">-s</span> <span class=\"token string\">\"<span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token builtin class-name\">pwd</span><span class=\"token variable\">)</span></span>\"</span> ~/Downloads</code></pre></div>\n<hr>\n<h1>94. auto generate readme</h1>\n<h3>Description: rename existing readme to blueprint.md</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">npx @appnest/readme generate</code></pre></div>\n<hr>\n<h1>95. Log into postgres:</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">sudo</span> <span class=\"token parameter variable\">-u</span> postgres psql</code></pre></div>\n<hr>\n<h1>96. URL To Subscribe To YouTube Channel</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"txt\"><pre class=\"language-txt\"><code class=\"language-txt\">https://www.youtube.com/channel/UC1HDa0wWnIKUf-b4yY9JecQ?sub_confirmation=1</code></pre></div>\n<hr>\n<h1>97. Embed Repl.it In Medium Post:</h1>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"txt\"><pre class=\"language-txt\"><code class=\"language-txt\">https://repl.it/@bgoonz/Data-Structures-Algos-Codebase?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com\n\nhttps://repl.it/@bgoonz/node-db1-project?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com\n\nhttps://repl.it/@bgoonz/interview-prac?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com\n\nhttps://repl.it/@bgoonz/Database-Prac?lite=true&amp;amp;referrer=https%3A%2F%2Fbryanguner.medium.com</code></pre></div>\n<hr>\n<h1>98.</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> *right.html  <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'s/target=\"_parent\"//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +\n\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> *right.html  <span class=\"token parameter variable\">-type</span> f <span class=\"token parameter variable\">-exec</span> <span class=\"token function\">sed</span> <span class=\"token parameter variable\">-i</span> <span class=\"token string\">'s/target=\"_parent\"//g'</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> +</code></pre></div>\n<hr>\n<h1>99. Cheat Sheet</h1>\n<h3>Description:</h3>\n<blockquote>\n<p>Notes:</p>\n</blockquote>\n<h6>code:</h6>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token shebang important\">#!/bin/bash</span>\n\n<span class=\"token comment\"># SHORTCUTS and HISTORY</span>\n\n\nCTRL+A  <span class=\"token comment\"># move to beginning of line</span>\nCTRL+B  <span class=\"token comment\"># moves backward one character</span>\nCTRL+C  <span class=\"token comment\"># halts the current command</span>\nCTRL+D  <span class=\"token comment\"># deletes one character backward or logs out of current session, similar to exit</span>\nCTRL+E  <span class=\"token comment\"># moves to end of line</span>\nCTRL+F  <span class=\"token comment\"># moves forward one character</span>\nCTRL+G  <span class=\"token comment\"># aborts the current editing command and ring the terminal bell</span>\nCTRL+H  <span class=\"token comment\"># deletes one character under cursor (same as DELETE)</span>\nCTRL+J  <span class=\"token comment\"># same as RETURN</span>\nCTRL+K  <span class=\"token comment\"># deletes (kill) forward to end of line</span>\nCTRL+L  <span class=\"token comment\"># clears screen and redisplay the line</span>\nCTRL+M  <span class=\"token comment\"># same as RETURN</span>\nCTRL+N  <span class=\"token comment\"># next line in command history</span>\nCTRL+O  <span class=\"token comment\"># same as RETURN, then displays next line in history file</span>\nCTRL+P  <span class=\"token comment\"># previous line in command history</span>\nCTRL+Q  <span class=\"token comment\"># resumes suspended shell output</span>\nCTRL+R  <span class=\"token comment\"># searches backward</span>\nCTRL+S  <span class=\"token comment\"># searches forward or suspends shell output</span>\nCTRL+T  <span class=\"token comment\"># transposes two characters</span>\nCTRL+U  <span class=\"token comment\"># kills backward from point to the beginning of line</span>\nCTRL+V  <span class=\"token comment\"># makes the next character typed verbatim</span>\nCTRL+W  <span class=\"token comment\"># kills the word behind the cursor</span>\nCTRL+X  <span class=\"token comment\"># lists the possible filename completions of the current word</span>\nCTRL+Y  <span class=\"token comment\"># retrieves (yank) last item killed</span>\nCTRL+Z  <span class=\"token comment\"># stops the current command, resume with fg in the foreground or bg in the background</span>\n\nALT+B   <span class=\"token comment\"># moves backward one word</span>\nALT+D   <span class=\"token comment\"># deletes next word</span>\nALT+F   <span class=\"token comment\"># moves forward one word</span>\nALT+H   <span class=\"token comment\"># deletes one character backward</span>\nALT+T   <span class=\"token comment\"># transposes two words</span>\nALT+.   <span class=\"token comment\"># pastes last word from the last command. Pressing it repeatedly traverses through command history.</span>\nALT+U   <span class=\"token comment\"># capitalizes every character from the current cursor position to the end of the word</span>\nALT+L   <span class=\"token comment\"># uncapitalizes every character from the current cursor position to the end of the word</span>\nALT+C   <span class=\"token comment\"># capitalizes the letter under the cursor. The cursor then moves to the end of the word.</span>\nALT+R   <span class=\"token comment\"># reverts any changes to a command you've pulled from your history if you've edited it.</span>\nALT+?   <span class=\"token comment\"># list possible completions to what is typed</span>\nALT+^   <span class=\"token comment\"># expand line to most recent match from history</span>\n\nCTRL+X <span class=\"token keyword\">then</span> <span class=\"token punctuation\">(</span>   <span class=\"token comment\"># start recording a keyboard macro</span>\nCTRL+X <span class=\"token keyword\">then</span> <span class=\"token punctuation\">)</span>   <span class=\"token comment\"># finish recording keyboard macro</span>\nCTRL+X <span class=\"token keyword\">then</span> E   <span class=\"token comment\"># recall last recorded keyboard macro</span>\nCTRL+X <span class=\"token keyword\">then</span> CTRL+E   <span class=\"token comment\"># invoke text editor (specified by $EDITOR) on current command line then execute resultes as shell commands</span>\n\nBACKSPACE  <span class=\"token comment\"># deletes one character backward</span>\nDELETE     <span class=\"token comment\"># deletes one character under cursor</span>\n\n<span class=\"token function\">history</span>   <span class=\"token comment\"># shows command line history</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">!</span>        <span class=\"token comment\"># repeats the last command</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span>n<span class=\"token operator\">></span>      <span class=\"token comment\"># refers to command line 'n'</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span>string<span class=\"token operator\">></span> <span class=\"token comment\"># refers to command starting with 'string'</span>\n\n<span class=\"token builtin class-name\">exit</span>      <span class=\"token comment\"># logs out of current session</span>\n\n\n<span class=\"token comment\"># BASH BASICS</span>\n\n\n<span class=\"token function\">env</span>                 <span class=\"token comment\"># displays all environment variables</span>\n\n<span class=\"token builtin class-name\">echo</span> <span class=\"token environment constant\">$SHELL</span>         <span class=\"token comment\"># displays the shell you're using</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token environment constant\">$BASH_VERSION</span>  <span class=\"token comment\"># displays bash version</span>\n\n<span class=\"token function\">bash</span>                <span class=\"token comment\"># if you want to use bash (type exit to go back to your previously opened shell)</span>\n<span class=\"token function\">whereis</span> <span class=\"token function\">bash</span>        <span class=\"token comment\"># locates the binary, source and manual-page for a command</span>\n<span class=\"token function\">which</span> <span class=\"token function\">bash</span>          <span class=\"token comment\"># finds out which program is executed as 'bash' (default: /bin/bash, can change across environments)</span>\n\n<span class=\"token function\">clear</span>               <span class=\"token comment\"># clears content on window (hide displayed lines)</span>\n\n\n<span class=\"token comment\"># FILE COMMANDS</span>\n\n\n<span class=\"token function\">ls</span>                            <span class=\"token comment\"># lists your files in current directory, ls &lt;dir> to print files in a specific directory</span>\n<span class=\"token function\">ls</span> <span class=\"token parameter variable\">-l</span>                         <span class=\"token comment\"># lists your files in 'long format', which contains the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified</span>\n<span class=\"token function\">ls</span> <span class=\"token parameter variable\">-a</span>                         <span class=\"token comment\"># lists all files in 'long format', including hidden files (name beginning with '.')</span>\n<span class=\"token function\">ln</span> <span class=\"token parameter variable\">-s</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>link<span class=\"token operator\">></span>       <span class=\"token comment\"># creates symbolic link to file</span>\nreadlink <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>           <span class=\"token comment\"># shows where a symbolic links points to</span>\ntree                          <span class=\"token comment\"># show directories and subdirectories in easilly readable file tree</span>\n<span class=\"token function\">mc</span>                            <span class=\"token comment\"># terminal file explorer (alternative to ncdu)</span>\n<span class=\"token function\">touch</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>              <span class=\"token comment\"># creates or updates (edit) your file</span>\nmktemp <span class=\"token parameter variable\">-t</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>            <span class=\"token comment\"># make a temp file in /tmp/ which is deleted at next boot (-d to make directory)</span>\n<span class=\"token function\">cat</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                <span class=\"token comment\"># prints file raw content (will not be interpreted)</span>\nany_command <span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>      <span class=\"token comment\"># '>' is used to perform redirections, it will set any_command's stdout to file instead of \"real stdout\" (generally /dev/stdout)</span>\n<span class=\"token function\">more</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># shows the first part of a file (move with space and type q to quit)</span>\n<span class=\"token function\">head</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># outputs the first lines of file (default: 10 lines)</span>\n<span class=\"token function\">tail</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># outputs the last lines of file (useful with -f option) (default: 10 lines)</span>\n<span class=\"token function\">vim</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                <span class=\"token comment\"># opens a file in VIM (VI iMproved) text editor, will create it if it doesn't exist</span>\n<span class=\"token function\">mv</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>dest<span class=\"token operator\">></span>         <span class=\"token comment\"># moves a file to destination, behavior will change based on 'dest' type (dir: file is placed into dir; file: file will replace dest (tip: useful for renaming))</span>\n<span class=\"token function\">cp</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>dest<span class=\"token operator\">></span>         <span class=\"token comment\"># copies a file</span>\n<span class=\"token function\">rm</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                 <span class=\"token comment\"># removes a file</span>\n<span class=\"token function\">find</span> <span class=\"token builtin class-name\">.</span> <span class=\"token parameter variable\">-name</span> <span class=\"token operator\">&lt;</span>name<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>type<span class=\"token operator\">></span>    <span class=\"token comment\"># searches for a file or a directory in the current directory and all its sub-directories by its name</span>\n<span class=\"token function\">diff</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span>  <span class=\"token comment\"># compares files, and shows where they differ</span>\n<span class=\"token function\">wc</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                 <span class=\"token comment\"># tells you how many lines, words and characters there are in a file. Use -lwc (lines, word, character) to ouput only 1 of those informations</span>\n<span class=\"token function\">sort</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># sorts the contents of a text file line by line in alphabetical order, use -n for numeric sort and -r for reversing order.</span>\n<span class=\"token function\">sort</span> <span class=\"token parameter variable\">-t</span> <span class=\"token parameter variable\">-k</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>         <span class=\"token comment\"># sorts the contents on specific sort key field starting from 1, using the field separator t.</span>\n<span class=\"token function\">rev</span>                           <span class=\"token comment\"># reverse string characters (hello becomes olleh)</span>\n<span class=\"token function\">chmod</span> <span class=\"token parameter variable\">-options</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>     <span class=\"token comment\"># lets you change the read, write, and execute permissions on your files (more infos: SUID, GUID)</span>\n<span class=\"token function\">gzip</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>               <span class=\"token comment\"># compresses files using gzip algorithm</span>\ngunzip <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>             <span class=\"token comment\"># uncompresses files compressed by gzip</span>\ngzcat <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>              <span class=\"token comment\"># lets you look at gzipped file without actually having to gunzip it</span>\n<span class=\"token function\">lpr</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>                <span class=\"token comment\"># prints the file</span>\nlpq                           <span class=\"token comment\"># checks out the printer queue</span>\n<span class=\"token function\">lprm</span> <span class=\"token operator\">&lt;</span>jobnumber<span class=\"token operator\">></span>              <span class=\"token comment\"># removes something from the printer queue</span>\ngenscript                     <span class=\"token comment\"># converts plain text files into postscript for printing and gives you some options for formatting</span>\ndvips <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>              <span class=\"token comment\"># prints .dvi files (i.e. files produced by LaTeX)</span>\n<span class=\"token function\">grep</span> <span class=\"token operator\">&lt;</span>pattern<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>filenames<span class=\"token operator\">></span>    <span class=\"token comment\"># looks for the string in the files</span>\n<span class=\"token function\">grep</span> <span class=\"token parameter variable\">-r</span> <span class=\"token operator\">&lt;</span>pattern<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\">></span>       <span class=\"token comment\"># search recursively for pattern in directory</span>\n<span class=\"token function\">head</span> <span class=\"token parameter variable\">-n</span> file_name <span class=\"token operator\">|</span> <span class=\"token function\">tail</span> +n   <span class=\"token comment\"># Print nth line from file.</span>\n<span class=\"token function\">head</span> <span class=\"token parameter variable\">-y</span> lines.txt <span class=\"token operator\">|</span> <span class=\"token function\">tail</span> +x   <span class=\"token comment\"># want to display all the lines from x to y. This includes the xth and yth lines.</span>\n\n\n<span class=\"token comment\"># DIRECTORY COMMANDS</span>\n\n\n<span class=\"token function\">mkdir</span> <span class=\"token operator\">&lt;</span>dirname<span class=\"token operator\">></span>               <span class=\"token comment\"># makes a new directory</span>\n<span class=\"token function\">rmdir</span> <span class=\"token operator\">&lt;</span>dirname<span class=\"token operator\">></span>               <span class=\"token comment\"># remove an empty directory</span>\n<span class=\"token function\">rmdir</span> <span class=\"token parameter variable\">-rf</span> <span class=\"token operator\">&lt;</span>dirname<span class=\"token operator\">></span>           <span class=\"token comment\"># remove a non-empty directory</span>\n<span class=\"token function\">mv</span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span>              <span class=\"token comment\"># rename a directory from &lt;dir1> to &lt;dir2></span>\n<span class=\"token builtin class-name\">cd</span>                            <span class=\"token comment\"># changes to home</span>\n<span class=\"token builtin class-name\">cd</span> <span class=\"token punctuation\">..</span>                         <span class=\"token comment\"># changes to the parent directory</span>\n<span class=\"token builtin class-name\">cd</span> <span class=\"token operator\">&lt;</span>dirname<span class=\"token operator\">></span>                  <span class=\"token comment\"># changes directory</span>\n<span class=\"token function\">cp</span> <span class=\"token parameter variable\">-r</span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\"><span class=\"token file-descriptor important\">1</span>></span> <span class=\"token operator\">&lt;</span>dir<span class=\"token operator\"><span class=\"token file-descriptor important\">2</span>></span>           <span class=\"token comment\"># copy &lt;dir1> into &lt;dir2> including sub-directories</span>\n<span class=\"token builtin class-name\">pwd</span>                           <span class=\"token comment\"># tells you where you currently are</span>\n<span class=\"token builtin class-name\">cd</span> ~                          <span class=\"token comment\"># changes to home.</span>\n<span class=\"token builtin class-name\">cd</span> -                        <span class=\"token comment\"># changes to previous working directory</span>\n\n\n<span class=\"token comment\"># SSH, SYSTEM INFO &amp; NETWORK COMMANDS</span>\n\n\n<span class=\"token function\">ssh</span> user@host            <span class=\"token comment\"># connects to host as user</span>\n<span class=\"token function\">ssh</span> <span class=\"token parameter variable\">-p</span> <span class=\"token operator\">&lt;</span>port<span class=\"token operator\">></span> user@host  <span class=\"token comment\"># connects to host on specified port as user</span>\nssh-copy-id user@host    <span class=\"token comment\"># adds your ssh key to host for user to enable a keyed or passwordless login</span>\n\n<span class=\"token function\">whoami</span>                   <span class=\"token comment\"># returns your username</span>\n<span class=\"token function\">passwd</span>                   <span class=\"token comment\"># lets you change your password</span>\n<span class=\"token function\">quota</span> <span class=\"token parameter variable\">-v</span>                 <span class=\"token comment\"># shows what your disk quota is</span>\n<span class=\"token function\">date</span>                     <span class=\"token comment\"># shows the current date and time</span>\n<span class=\"token function\">cal</span>                      <span class=\"token comment\"># shows the month's calendar</span>\n<span class=\"token function\">uptime</span>                   <span class=\"token comment\"># shows current uptime</span>\nw                        <span class=\"token comment\"># displays whois online</span>\nfinger <span class=\"token operator\">&lt;</span>user<span class=\"token operator\">></span>            <span class=\"token comment\"># displays information about user</span>\n<span class=\"token function\">uname</span> <span class=\"token parameter variable\">-a</span>                 <span class=\"token comment\"># shows kernel information</span>\n<span class=\"token function\">man</span> <span class=\"token operator\">&lt;</span>command<span class=\"token operator\">></span>            <span class=\"token comment\"># shows the manual for specified command</span>\n<span class=\"token function\">df</span>                       <span class=\"token comment\"># shows disk usage</span>\n<span class=\"token function\">du</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>            <span class=\"token comment\"># shows the disk usage of the files and directories in filename (du -s give only a total)</span>\nlast <span class=\"token operator\">&lt;</span>yourUsername<span class=\"token operator\">></span>      <span class=\"token comment\"># lists your last logins</span>\n<span class=\"token function\">ps</span> <span class=\"token parameter variable\">-u</span> yourusername       <span class=\"token comment\"># lists your processes</span>\n<span class=\"token function\">kill</span> <span class=\"token operator\">&lt;</span>PID<span class=\"token operator\">></span>               <span class=\"token comment\"># kills the processes with the ID you gave</span>\n<span class=\"token function\">killall</span> <span class=\"token operator\">&lt;</span>processname<span class=\"token operator\">></span>    <span class=\"token comment\"># kill all processes with the name</span>\n<span class=\"token function\">top</span>                      <span class=\"token comment\"># displays your currently active processes</span>\n<span class=\"token function\">lsof</span>                     <span class=\"token comment\"># lists open files</span>\n<span class=\"token function\">bg</span>                       <span class=\"token comment\"># lists stopped or background jobs ; resume a stopped job in the background</span>\n<span class=\"token function\">fg</span>                       <span class=\"token comment\"># brings the most recent job in the foreground</span>\n<span class=\"token function\">fg</span> <span class=\"token operator\">&lt;</span>job<span class=\"token operator\">></span>                 <span class=\"token comment\"># brings job to the foreground</span>\n\n<span class=\"token function\">ping</span> <span class=\"token operator\">&lt;</span>host<span class=\"token operator\">></span>              <span class=\"token comment\"># pings host and outputs results</span>\nwhois <span class=\"token operator\">&lt;</span>domain<span class=\"token operator\">></span>           <span class=\"token comment\"># gets whois information for domain</span>\n<span class=\"token function\">dig</span> <span class=\"token operator\">&lt;</span>domain<span class=\"token operator\">></span>             <span class=\"token comment\"># gets DNS information for domain</span>\n<span class=\"token function\">dig</span> <span class=\"token parameter variable\">-x</span> <span class=\"token operator\">&lt;</span>host<span class=\"token operator\">></span>            <span class=\"token comment\"># reverses lookup host</span>\n<span class=\"token function\">wget</span> <span class=\"token operator\">&lt;</span>file<span class=\"token operator\">></span>              <span class=\"token comment\"># downloads file</span>\n\n<span class=\"token function\">time</span> <span class=\"token operator\">&lt;</span>command<span class=\"token operator\">></span>             <span class=\"token comment\"># report time consumed by command execution</span>\n\n\n<span class=\"token comment\"># VARIABLES</span>\n\n\n<span class=\"token assign-left variable\">varname</span><span class=\"token operator\">=</span>value                <span class=\"token comment\"># defines a variable</span>\n<span class=\"token assign-left variable\">varname</span><span class=\"token operator\">=</span>value <span class=\"token builtin class-name\">command</span>        <span class=\"token comment\"># defines a variable to be in the environment of a particular subprocess</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$varname</span>                <span class=\"token comment\"># checks a variable's value</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$$</span>                      <span class=\"token comment\"># prints process ID of the current shell</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$!</span>                      <span class=\"token comment\"># prints process ID of the most recently invoked background job</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token variable\">$?</span>                      <span class=\"token comment\"># displays the exit status of the last command</span>\n<span class=\"token builtin class-name\">read</span> <span class=\"token operator\">&lt;</span>varname<span class=\"token operator\">></span>               <span class=\"token comment\"># reads a string from the input and assigns it to a variable</span>\n<span class=\"token builtin class-name\">read</span> <span class=\"token parameter variable\">-p</span> <span class=\"token string\">\"prompt\"</span> <span class=\"token operator\">&lt;</span>varname<span class=\"token operator\">></span>   <span class=\"token comment\"># same as above but outputs a prompt to ask user for value</span>\n<span class=\"token function\">column</span> <span class=\"token parameter variable\">-t</span> <span class=\"token operator\">&lt;</span>filename<span class=\"token operator\">></span>         <span class=\"token comment\"># display info in pretty columns (often used with pipe)</span>\n<span class=\"token builtin class-name\">let</span> <span class=\"token operator\">&lt;</span>varname<span class=\"token operator\">></span> <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>equation<span class=\"token operator\">></span>   <span class=\"token comment\"># performs mathematical calculation using operators like +, -, *, /, %</span>\n<span class=\"token builtin class-name\">export</span> <span class=\"token assign-left variable\">VARNAME</span><span class=\"token operator\">=</span>value         <span class=\"token comment\"># defines an environment variable (will be available in subprocesses)</span>\n\narray<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valA                <span class=\"token comment\"># how to define an array</span>\narray<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valB\narray<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valC\n<span class=\"token assign-left variable\">array</span><span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valC <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valA <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token operator\">=</span>valB<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># another way</span>\n<span class=\"token assign-left variable\">array</span><span class=\"token operator\">=</span><span class=\"token punctuation\">(</span>valA valB valC<span class=\"token punctuation\">)</span>              <span class=\"token comment\"># and another</span>\n\n<span class=\"token variable\">${array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span>}</span>                  <span class=\"token comment\"># displays array's value for this index. If no index is supplied, array element 0 is assumed</span>\n<span class=\"token variable\">${<span class=\"token operator\">#</span>array<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span>}</span>                 <span class=\"token comment\"># to find out the length of any element in the array</span>\n<span class=\"token variable\">${<span class=\"token operator\">#</span>array<span class=\"token punctuation\">[</span>@<span class=\"token punctuation\">]</span>}</span>                 <span class=\"token comment\"># to find out how many values there are in the array</span>\n\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-a</span>                   <span class=\"token comment\"># the variables are treated as arrays</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-f</span>                   <span class=\"token comment\"># uses function names only</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-F</span>                   <span class=\"token comment\"># displays function names without definitions</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-i</span>                   <span class=\"token comment\"># the variables are treated as integers</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-r</span>                   <span class=\"token comment\"># makes the variables read-only</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-x</span>                   <span class=\"token comment\"># marks the variables for export via the environment</span>\n\n<span class=\"token variable\">${varname<span class=\"token operator\">:-</span>word}</span>             <span class=\"token comment\"># if varname exists and isn't null, return its value; otherwise return word</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:</span>word}</span>              <span class=\"token comment\"># if varname exists and isn't null, return its value; otherwise return word</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:=</span>word}</span>             <span class=\"token comment\"># if varname exists and isn't null, return its value; otherwise set it word and then return its value</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:?</span>message}</span>          <span class=\"token comment\"># if varname exists and isn't null, return its value; otherwise print varname, followed by message and abort the current command or script</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:+</span>word}</span>             <span class=\"token comment\"># if varname exists and isn't null, return word; otherwise return null</span>\n<span class=\"token variable\">${varname<span class=\"token operator\">:</span>offset<span class=\"token operator\">:</span>length}</span>     <span class=\"token comment\"># performs substring expansion. It returns the substring of $varname starting at offset and up to length characters</span>\n\n<span class=\"token variable\">${variable<span class=\"token operator\">#</span>pattern}</span>          <span class=\"token comment\"># if the pattern matches the beginning of the variable's value, delete the shortest part that matches and return the rest</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">##</span>pattern}</span>         <span class=\"token comment\"># if the pattern matches the beginning of the variable's value, delete the longest part that matches and return the rest</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">%</span>pattern}</span>          <span class=\"token comment\"># if the pattern matches the end of the variable's value, delete the shortest part that matches and return the rest</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">%%</span>pattern}</span>         <span class=\"token comment\"># if the pattern matches the end of the variable's value, delete the longest part that matches and return the rest</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">/</span>pattern<span class=\"token operator\">/</span>string}</span>   <span class=\"token comment\"># the longest match to pattern in variable is replaced by string. Only the first match is replaced</span>\n<span class=\"token variable\">${variable<span class=\"token operator\">/</span><span class=\"token operator\">/</span>pattern<span class=\"token operator\">/</span>string}</span>  <span class=\"token comment\"># the longest match to pattern in variable is replaced by string. All matches are replaced</span>\n\n<span class=\"token variable\">${<span class=\"token operator\">#</span>varname}</span>                  <span class=\"token comment\"># returns the length of the value of the variable as a character string</span>\n\n*<span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches zero or more occurrences of the given patterns</span>\n+<span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches one or more occurrences of the given patterns</span>\n?<span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches zero or one occurrence of the given patterns</span>\n@<span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches exactly one of the given patterns</span>\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>patternlist<span class=\"token punctuation\">)</span>               <span class=\"token comment\"># matches anything except one of the given patterns</span>\n\n<span class=\"token variable\"><span class=\"token variable\">$(</span>UNIX <span class=\"token builtin class-name\">command</span><span class=\"token variable\">)</span></span>              <span class=\"token comment\"># command substitution: runs the command and returns standard output</span>\n\n\n<span class=\"token comment\"># FUNCTIONS</span>\n\n\n<span class=\"token comment\"># The function refers to passed arguments by position (as if they were positional parameters), that is, $1, $2, and so forth.</span>\n<span class=\"token comment\"># $@ is equal to \"$1\" \"$2\"... \"$N\", where N is the number of positional parameters. $# holds the number of positional parameters.</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">functname</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  shell commands\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token builtin class-name\">unset</span> <span class=\"token parameter variable\">-f</span> functname  <span class=\"token comment\"># deletes a function definition</span>\n<span class=\"token builtin class-name\">declare</span> <span class=\"token parameter variable\">-f</span>          <span class=\"token comment\"># displays all defined functions in your login session</span>\n\n\n<span class=\"token comment\"># FLOW CONTROLS</span>\n\n\nstatement1 <span class=\"token operator\">&amp;&amp;</span> statement2  <span class=\"token comment\"># and operator</span>\nstatement1 <span class=\"token operator\">||</span> statement2  <span class=\"token comment\"># or operator</span>\n\n<span class=\"token parameter variable\">-a</span>                        <span class=\"token comment\"># and operator inside a test conditional expression</span>\n<span class=\"token parameter variable\">-o</span>                        <span class=\"token comment\"># or operator inside a test conditional expression</span>\n\n<span class=\"token comment\"># STRINGS</span>\n\nstr1 <span class=\"token operator\">==</span> str2               <span class=\"token comment\"># str1 matches str2</span>\nstr1 <span class=\"token operator\">!=</span> str2               <span class=\"token comment\"># str1 does not match str2</span>\nstr1 <span class=\"token operator\">&lt;</span> str2                <span class=\"token comment\"># str1 is less than str2 (alphabetically)</span>\nstr1 <span class=\"token operator\">></span> str2                <span class=\"token comment\"># str1 is greater than str2 (alphabetically)</span>\nstr1 <span class=\"token punctuation\">\\</span><span class=\"token operator\">></span> str2               <span class=\"token comment\"># str1 is sorted after str2</span>\nstr1 <span class=\"token punctuation\">\\</span><span class=\"token operator\">&lt;</span> str2               <span class=\"token comment\"># str1 is sorted before str2</span>\n<span class=\"token parameter variable\">-n</span> str1                    <span class=\"token comment\"># str1 is not null (has length greater than 0)</span>\n<span class=\"token parameter variable\">-z</span> str1                    <span class=\"token comment\"># str1 is null (has length 0)</span>\n\n<span class=\"token comment\"># FILES</span>\n\n<span class=\"token parameter variable\">-a</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists or its compilation is successful</span>\n<span class=\"token parameter variable\">-d</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists and is a directory</span>\n<span class=\"token parameter variable\">-e</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists; same -a</span>\n<span class=\"token parameter variable\">-f</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists and is a regular file (i.e., not a directory or other special type of file)</span>\n<span class=\"token parameter variable\">-r</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># you have read permission</span>\n<span class=\"token parameter variable\">-s</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file exists and is not empty</span>\n<span class=\"token parameter variable\">-w</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># your have write permission</span>\n<span class=\"token parameter variable\">-x</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># you have execute permission on file, or directory search permission if it is a directory</span>\n<span class=\"token parameter variable\">-N</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file was modified since it was last read</span>\n<span class=\"token parameter variable\">-O</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># you own file</span>\n<span class=\"token parameter variable\">-G</span> <span class=\"token function\">file</span>                   <span class=\"token comment\"># file's group ID matches yours (or one of yours, if you are in multiple groups)</span>\nfile1 <span class=\"token parameter variable\">-nt</span> file2           <span class=\"token comment\"># file1 is newer than file2</span>\nfile1 <span class=\"token parameter variable\">-ot</span> file2           <span class=\"token comment\"># file1 is older than file2</span>\n\n<span class=\"token comment\"># NUMBERS</span>\n\n<span class=\"token parameter variable\">-lt</span>                       <span class=\"token comment\"># less than</span>\n<span class=\"token parameter variable\">-le</span>                       <span class=\"token comment\"># less than or equal</span>\n<span class=\"token parameter variable\">-eq</span>                       <span class=\"token comment\"># equal</span>\n<span class=\"token parameter variable\">-ge</span>                       <span class=\"token comment\"># greater than or equal</span>\n<span class=\"token parameter variable\">-gt</span>                       <span class=\"token comment\"># greater than</span>\n<span class=\"token parameter variable\">-ne</span>                       <span class=\"token comment\"># not equal</span>\n\n<span class=\"token keyword\">if</span> condition\n<span class=\"token keyword\">then</span>\n  statements\n<span class=\"token punctuation\">[</span>elif condition\n  <span class=\"token keyword\">then</span> statements<span class=\"token punctuation\">..</span>.<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span>else\n  statements<span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">fi</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token for-or-select variable\">x</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">..</span><span class=\"token number\">10</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">do</span>\n  statements\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> name <span class=\"token punctuation\">[</span>in list<span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">do</span>\n  statements that can use <span class=\"token variable\">$name</span>\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token variable\"><span class=\"token punctuation\">((</span> initialisation <span class=\"token punctuation\">;</span> ending condition <span class=\"token punctuation\">;</span> update <span class=\"token punctuation\">))</span></span>\n<span class=\"token keyword\">do</span>\n  statements<span class=\"token punctuation\">..</span>.\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">case</span> expression <span class=\"token keyword\">in</span>\n  pattern1 <span class=\"token punctuation\">)</span>\n    statements <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n  pattern2 <span class=\"token punctuation\">)</span>\n    statements <span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">esac</span>\n\n<span class=\"token keyword\">select</span> name <span class=\"token punctuation\">[</span>in list<span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">do</span>\n  statements that can use <span class=\"token variable\">$name</span>\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">while</span> condition<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span>\n  statements\n<span class=\"token keyword\">done</span>\n\n<span class=\"token keyword\">until</span> condition<span class=\"token punctuation\">;</span> <span class=\"token keyword\">do</span>\n  statements\n<span class=\"token keyword\">done</span>\n\n\n<span class=\"token comment\"># COMMAND-LINE PROCESSING CYCLE</span>\n\n\n<span class=\"token comment\"># The default order for command lookup is functions, followed by built-ins, with scripts and executables last.</span>\n<span class=\"token comment\"># There are three built-ins that you can use to override this order: `command`, `builtin` and `enable`.</span>\n\n<span class=\"token builtin class-name\">command</span>  <span class=\"token comment\"># removes alias and function lookup. Only built-ins and commands found in the search path are executed</span>\n<span class=\"token builtin class-name\">builtin</span>  <span class=\"token comment\"># looks up only built-in commands, ignoring functions and commands found in PATH</span>\n<span class=\"token builtin class-name\">enable</span>   <span class=\"token comment\"># enables and disables shell built-ins</span>\n\n<span class=\"token builtin class-name\">eval</span>     <span class=\"token comment\"># takes arguments and run them through the command-line processing steps all over again</span>\n\n\n<span class=\"token comment\"># INPUT/OUTPUT REDIRECTORS</span>\n\n\ncmd1<span class=\"token operator\">|</span>cmd2  <span class=\"token comment\"># pipe; takes standard output of cmd1 as standard input to cmd2</span>\n<span class=\"token operator\">&lt;</span> <span class=\"token function\">file</span>     <span class=\"token comment\"># takes standard input from file</span>\n<span class=\"token operator\">></span> <span class=\"token function\">file</span>     <span class=\"token comment\"># directs standard output to file</span>\n<span class=\"token operator\">>></span> <span class=\"token function\">file</span>    <span class=\"token comment\"># directs standard output to file; append to file if it already exists</span>\n<span class=\"token operator\">>|</span><span class=\"token function\">file</span>     <span class=\"token comment\"># forces standard output to file even if noclobber is set</span>\nn<span class=\"token operator\">>|</span><span class=\"token function\">file</span>    <span class=\"token comment\"># forces output to file from file descriptor n even if noclobber is set</span>\n<span class=\"token operator\">&lt;></span> <span class=\"token function\">file</span>    <span class=\"token comment\"># uses file as both standard input and standard output</span>\nn<span class=\"token operator\">&lt;></span>file    <span class=\"token comment\"># uses file as both input and output for file descriptor n</span>\nn<span class=\"token operator\">></span>file     <span class=\"token comment\"># directs file descriptor n to file</span>\nn<span class=\"token operator\">&lt;</span>file     <span class=\"token comment\"># takes file descriptor n from file</span>\nn<span class=\"token operator\">>></span>file    <span class=\"token comment\"># directs file description n to file; append to file if it already exists</span>\nn<span class=\"token operator\">>&amp;</span>        <span class=\"token comment\"># duplicates standard output to file descriptor n</span>\nn<span class=\"token operator\">&lt;&amp;</span>        <span class=\"token comment\"># duplicates standard input from file descriptor n</span>\nn<span class=\"token operator\">>&amp;</span>m       <span class=\"token comment\"># file descriptor n is made to be a copy of the output file descriptor</span>\nn<span class=\"token operator\">&lt;&amp;</span>m       <span class=\"token comment\"># file descriptor n is made to be a copy of the input file descriptor</span>\n<span class=\"token operator\">&amp;></span>file     <span class=\"token comment\"># directs standard output and standard error to file</span>\n<span class=\"token operator\">&lt;&amp;</span>-      <span class=\"token comment\"># closes the standard input</span>\n<span class=\"token operator\">>&amp;</span>-      <span class=\"token comment\"># closes the standard output</span>\nn<span class=\"token operator\">>&amp;</span>-     <span class=\"token comment\"># closes the ouput from file descriptor n</span>\nn<span class=\"token operator\">&lt;&amp;</span>-     <span class=\"token comment\"># closes the input from file descripor n</span>\n\n<span class=\"token operator\">|</span><span class=\"token function\">tee</span> <span class=\"token operator\">&lt;</span>file<span class=\"token operator\">></span><span class=\"token comment\"># output command to both terminal and a file (-a to append to file)</span>\n\n\n<span class=\"token comment\"># PROCESS HANDLING</span>\n\n\n<span class=\"token comment\"># To suspend a job, type CTRL+Z while it is running. You can also suspend a job with CTRL+Y.</span>\n<span class=\"token comment\"># This is slightly different from CTRL+Z in that the process is only stopped when it attempts to read input from terminal.</span>\n<span class=\"token comment\"># Of course, to interrupt a job, type CTRL+C.</span>\n\nmyCommand <span class=\"token operator\">&amp;</span>  <span class=\"token comment\"># runs job in the background and prompts back the shell</span>\n\n<span class=\"token function\">jobs</span>         <span class=\"token comment\"># lists all jobs (use with -l to see associated PID)</span>\n\n<span class=\"token function\">fg</span>           <span class=\"token comment\"># brings a background job into the foreground</span>\n<span class=\"token function\">fg</span> %+        <span class=\"token comment\"># brings most recently invoked background job</span>\n<span class=\"token function\">fg</span> %-      <span class=\"token comment\"># brings second most recently invoked background job</span>\n<span class=\"token function\">fg</span> %N        <span class=\"token comment\"># brings job number N</span>\n<span class=\"token function\">fg</span> %string   <span class=\"token comment\"># brings job whose command begins with string</span>\n<span class=\"token function\">fg</span> %?string  <span class=\"token comment\"># brings job whose command contains string</span>\n\n<span class=\"token function\">kill</span> <span class=\"token parameter variable\">-l</span>               <span class=\"token comment\"># returns a list of all signals on the system, by name and number</span>\n<span class=\"token function\">kill</span> PID              <span class=\"token comment\"># terminates process with specified PID</span>\n<span class=\"token function\">kill</span> <span class=\"token parameter variable\">-s</span> SIGKILL <span class=\"token number\">4500</span>  <span class=\"token comment\"># sends a signal to force or terminate the process</span>\n<span class=\"token function\">kill</span> <span class=\"token parameter variable\">-15</span> <span class=\"token number\">913</span>          <span class=\"token comment\"># Ending PID 913 process with signal 15 (TERM)</span>\n<span class=\"token function\">kill</span> %1               <span class=\"token comment\"># Where %1 is the number of job as read from 'jobs' command.</span>\n\n<span class=\"token function\">ps</span>           <span class=\"token comment\"># prints a line of information about the current running login shell and any processes running under it</span>\n<span class=\"token function\">ps</span> <span class=\"token parameter variable\">-a</span>        <span class=\"token comment\"># selects all processes with a tty except session leaders</span>\n\n<span class=\"token builtin class-name\">trap</span> cmd sig1 sig2  <span class=\"token comment\"># executes a command when a signal is received by the script</span>\n<span class=\"token builtin class-name\">trap</span> <span class=\"token string\">\"\"</span> sig1 sig2   <span class=\"token comment\"># ignores that signals</span>\n<span class=\"token builtin class-name\">trap</span> - sig1 sig2    <span class=\"token comment\"># resets the action taken when the signal is received to the default</span>\n\ndisown <span class=\"token operator\">&lt;</span>PID<span class=\"token operator\">|</span>JID<span class=\"token operator\">></span>    <span class=\"token comment\"># removes the process from the list of jobs</span>\n\n<span class=\"token function\">wait</span>                <span class=\"token comment\"># waits until all background jobs have finished</span>\n<span class=\"token function\">sleep</span> <span class=\"token operator\">&lt;</span>number<span class=\"token operator\">></span>      <span class=\"token comment\"># wait # of seconds before continuing</span>\n\n<span class=\"token function\">pv</span>                  <span class=\"token comment\"># display progress bar for data handling commands. often used with pipe like |pv</span>\n<span class=\"token function\">yes</span>                 <span class=\"token comment\"># give yes response everytime an input is requested from script/process</span>\n\n\n<span class=\"token comment\"># TIPS &amp; TRICKS</span>\n\n\n<span class=\"token comment\"># set an alias</span>\n<span class=\"token builtin class-name\">cd</span><span class=\"token punctuation\">;</span> <span class=\"token function\">nano</span> .bash_profile\n<span class=\"token operator\">></span> <span class=\"token builtin class-name\">alias</span> <span class=\"token assign-left variable\">gentlenode</span><span class=\"token operator\">=</span><span class=\"token string\">'ssh admin@gentlenode.com -p 3404'</span>  <span class=\"token comment\"># add your alias in .bash_profile</span>\n\n<span class=\"token comment\"># to quickly go to a specific directory</span>\n<span class=\"token builtin class-name\">cd</span><span class=\"token punctuation\">;</span> <span class=\"token function\">nano</span> .bashrc\n<span class=\"token operator\">></span> <span class=\"token builtin class-name\">shopt</span> <span class=\"token parameter variable\">-s</span> cdable_vars\n<span class=\"token operator\">></span> <span class=\"token builtin class-name\">export</span> <span class=\"token assign-left variable\">websites</span><span class=\"token operator\">=</span><span class=\"token string\">\"/Users/mac/Documents/websites\"</span>\n\n<span class=\"token builtin class-name\">source</span> .bashrc\n<span class=\"token builtin class-name\">cd</span> <span class=\"token variable\">$websites</span>\n\n\n<span class=\"token comment\"># DEBUGGING SHELL PROGRAMS</span>\n\n\n<span class=\"token function\">bash</span> <span class=\"token parameter variable\">-n</span> scriptname  <span class=\"token comment\"># don't run commands; check for syntax errors only</span>\n<span class=\"token builtin class-name\">set</span> <span class=\"token parameter variable\">-o</span> noexec       <span class=\"token comment\"># alternative (set option in script)</span>\n\n<span class=\"token function\">bash</span> <span class=\"token parameter variable\">-v</span> scriptname  <span class=\"token comment\"># echo commands before running them</span>\n<span class=\"token builtin class-name\">set</span> <span class=\"token parameter variable\">-o</span> verbose      <span class=\"token comment\"># alternative (set option in script)</span>\n\n<span class=\"token function\">bash</span> <span class=\"token parameter variable\">-x</span> scriptname  <span class=\"token comment\"># echo commands after command-line processing</span>\n<span class=\"token builtin class-name\">set</span> <span class=\"token parameter variable\">-o</span> xtrace       <span class=\"token comment\"># alternative (set option in script)</span>\n\n<span class=\"token builtin class-name\">trap</span> <span class=\"token string\">'echo $varname'</span> EXIT  <span class=\"token comment\"># useful when you want to print out the values of variables at the point that your script exits</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">errtrap</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token assign-left variable\">es</span><span class=\"token operator\">=</span><span class=\"token variable\">$?</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"ERROR line <span class=\"token variable\">$1</span>: Command exited with status <span class=\"token variable\">$es</span>.\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token builtin class-name\">trap</span> <span class=\"token string\">'errtrap $LINENO'</span> ERR  <span class=\"token comment\"># is run whenever a command in the surrounding script or function exits with non-zero status</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">dbgtrap</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"badvar is <span class=\"token variable\">$badvar</span>\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token builtin class-name\">trap</span> dbgtrap DEBUG  <span class=\"token comment\"># causes the trap code to be executed before every statement in a function or script</span>\n<span class=\"token comment\"># ...section of code in which the problem occurs...</span>\n<span class=\"token builtin class-name\">trap</span> - DEBUG  <span class=\"token comment\"># turn off the DEBUG trap</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function-name function\">returntrap</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"A return occurred\"</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token builtin class-name\">trap</span> returntrap RETURN  <span class=\"token comment\"># is executed each time a shell function or a script executed with the . or source commands finishes executing</span>\n\n\n<span class=\"token comment\"># COLORS AND BACKGROUNDS</span>\n\n<span class=\"token comment\"># note: \\e or \\x1B also work instead of \\033</span>\n<span class=\"token comment\"># Reset</span>\n<span class=\"token assign-left variable\">Color_Off</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0m'</span> <span class=\"token comment\"># Text Reset</span>\n\n<span class=\"token comment\"># Regular Colors</span>\n<span class=\"token assign-left variable\">Black</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;30m'</span>  <span class=\"token comment\"># Black</span>\n<span class=\"token assign-left variable\">Red</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;31m'</span>    <span class=\"token comment\"># Red</span>\n<span class=\"token assign-left variable\">Green</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;32m'</span>  <span class=\"token comment\"># Green</span>\n<span class=\"token assign-left variable\">Yellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;33m'</span> <span class=\"token comment\"># Yellow</span>\n<span class=\"token assign-left variable\">Blue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;34m'</span>   <span class=\"token comment\"># Blue</span>\n<span class=\"token assign-left variable\">Purple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;35m'</span> <span class=\"token comment\"># Purple</span>\n<span class=\"token assign-left variable\">Cyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;36m'</span>   <span class=\"token comment\"># Cyan</span>\n<span class=\"token assign-left variable\">White</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;97m'</span>  <span class=\"token comment\"># White</span>\n\n<span class=\"token comment\"># Additional colors</span>\n<span class=\"token assign-left variable\">LGrey</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;37m'</span>  <span class=\"token comment\"># Ligth Gray</span>\n<span class=\"token assign-left variable\">DGrey</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;90m'</span>  <span class=\"token comment\"># Dark Gray</span>\n<span class=\"token assign-left variable\">LRed</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;91m'</span>   <span class=\"token comment\"># Ligth Red</span>\n<span class=\"token assign-left variable\">LGreen</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;92m'</span> <span class=\"token comment\"># Ligth Green</span>\n<span class=\"token assign-left variable\">LYellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;93m'</span><span class=\"token comment\"># Ligth Yellow</span>\n<span class=\"token assign-left variable\">LBlue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;94m'</span>  <span class=\"token comment\"># Ligth Blue</span>\n<span class=\"token assign-left variable\">LPurple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;95m'</span><span class=\"token comment\"># Light Purple</span>\n<span class=\"token assign-left variable\">LCyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[0;96m'</span>  <span class=\"token comment\"># Ligth Cyan</span>\n\n<span class=\"token comment\"># Bold</span>\n<span class=\"token assign-left variable\">BBlack</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;30m'</span> <span class=\"token comment\"># Black</span>\n<span class=\"token assign-left variable\">BRed</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;31m'</span>   <span class=\"token comment\"># Red</span>\n<span class=\"token assign-left variable\">BGreen</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;32m'</span> <span class=\"token comment\"># Green</span>\n<span class=\"token assign-left variable\">BYellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;33m'</span><span class=\"token comment\"># Yellow</span>\n<span class=\"token assign-left variable\">BBlue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;34m'</span>  <span class=\"token comment\"># Blue</span>\n<span class=\"token assign-left variable\">BPurple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;35m'</span><span class=\"token comment\"># Purple</span>\n<span class=\"token assign-left variable\">BCyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;36m'</span>  <span class=\"token comment\"># Cyan</span>\n<span class=\"token assign-left variable\">BWhite</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[1;37m'</span> <span class=\"token comment\"># White</span>\n\n<span class=\"token comment\"># Underline</span>\n<span class=\"token assign-left variable\">UBlack</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;30m'</span> <span class=\"token comment\"># Black</span>\n<span class=\"token assign-left variable\">URed</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;31m'</span>   <span class=\"token comment\"># Red</span>\n<span class=\"token assign-left variable\">UGreen</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;32m'</span> <span class=\"token comment\"># Green</span>\n<span class=\"token assign-left variable\">UYellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;33m'</span><span class=\"token comment\"># Yellow</span>\n<span class=\"token assign-left variable\">UBlue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;34m'</span>  <span class=\"token comment\"># Blue</span>\n<span class=\"token assign-left variable\">UPurple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;35m'</span><span class=\"token comment\"># Purple</span>\n<span class=\"token assign-left variable\">UCyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;36m'</span>  <span class=\"token comment\"># Cyan</span>\n<span class=\"token assign-left variable\">UWhite</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[4;37m'</span> <span class=\"token comment\"># White</span>\n\n<span class=\"token comment\"># Background</span>\n<span class=\"token assign-left variable\">On_Black</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[40m'</span> <span class=\"token comment\"># Black</span>\n<span class=\"token assign-left variable\">On_Red</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[41m'</span>   <span class=\"token comment\"># Red</span>\n<span class=\"token assign-left variable\">On_Green</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[42m'</span> <span class=\"token comment\"># Green</span>\n<span class=\"token assign-left variable\">On_Yellow</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[43m'</span><span class=\"token comment\"># Yellow</span>\n<span class=\"token assign-left variable\">On_Blue</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[44m'</span>  <span class=\"token comment\"># Blue</span>\n<span class=\"token assign-left variable\">On_Purple</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[45m'</span><span class=\"token comment\"># Purple</span>\n<span class=\"token assign-left variable\">On_Cyan</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[46m'</span>  <span class=\"token comment\"># Cyan</span>\n<span class=\"token assign-left variable\">On_White</span><span class=\"token operator\">=</span><span class=\"token string\">'\\033[47m'</span> <span class=\"token comment\"># White</span>\n\n<span class=\"token comment\"># Example of usage</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">\"<span class=\"token variable\">${Green}</span>This is GREEN text<span class=\"token variable\">${Color_Off}</span> and normal text\"</span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token parameter variable\">-e</span> <span class=\"token string\">\"<span class=\"token variable\">${Red}</span><span class=\"token variable\">${On_White}</span>This is Red test on White background<span class=\"token variable\">${Color_Off}</span>\"</span>\n<span class=\"token comment\"># option -e is mandatory, it enable interpretation of backslash escapes</span>\n<span class=\"token builtin class-name\">printf</span> <span class=\"token string\">\"<span class=\"token variable\">${Red}</span> This is red <span class=\"token entity\" title=\"\\n\">\\n</span>\"</span></code></pre></div>\n<hr>"},{"url":"/docs/docs/no-whiteboarding/","relativePath":"docs/docs/no-whiteboarding.md","relativeDir":"docs/docs","base":"no-whiteboarding.md","name":"no-whiteboarding","frontmatter":{"title":"lorem-ipsum","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>A - C\n\n</h2>\n<ul>\n<li><a href=\"https://www.ableton.com/en/about\">Ableton</a> | Berlin, Germany | Take-home programming task (discussed via Skype), then pair programming and debugging session on-site</li>\n<li></li>\n<li><a href=\"https://angel.co/abstract/jobs\">Abstract</a> | San Francisco, CA</li>\n<li></li>\n<li><a href=\"https://www.accenture.com/us-en/careers\">Accenture</a> | San Francisco, CA / Los Angeles, CA / New York, NY | Technical phone discussion with architec</li>\n<li></li>\n<li><a href=\"https://www.accredible.com/careers\">Accredible</a> | Cambridge, UK / San Francisco, CA / Remote | Take home project, then a pair-programming and discussion onsite / Skype round.</li>\n<li></li>\n<li><a href=\"https://acko.com/\">Acko</a> | Mumbai, India | Phone interview, followed by a small take </li>\n<li></li>\n<li><a href=\"http://www.acumenci.com/joinourteam\">Acumen</a> | London, UK | Small take home test, and sit in on some sprint rit</li>\n<li></li>\n<li><a href=\"https://www.addstones.com/\">Addstones</a> | Paris, FR / Singapore, SG / Bucharest, RO / London, UK | Multiple interviews, discussio</li>\n<li></li>\n<li><a href=\"https://adnymics.com/\">Adnymics</a> | Munich, DE | Take home project, then work with the team for a day</li>\n<li></li>\n<li><a href=\"http://adthena.com/\">Adthena</a> | London, UK | Takehome project and discussion on-site</li>\n<li></li>\n<li><a href=\"https://angel.co/adwyze/jobs\">AdWyze</a> | Bangalore, India | Short takehome project + (for fulltime) onsite pairing</li>\n<li></li>\n<li><a href=\"https://www.aerofs.com/company/careers\">AeroFS</a> | San Francisco, CA | Short takehome project + phone interview</li>\n<li></li>\n<li><a href=\"https://affinity.recruiterbox.com/#content\">Affinity</a> | San Francisco, CA | Implementation of a children's game, then take-home project OR real-world</li>\n<li></li>\n<li><a href=\"https://ageno.pl/\">Ageno</a> | Bielsko-Biala, Poland | Simple Magento Take-home project and discussion on the real world problems.</li>\n<li></li>\n<li><a href=\"https://angel.co/agilemd/jobs\">AgileMD</a> | San Francisco, CA | Takehome project</li>\n<li></li>\n<li><a href=\"https://careersatagoda.com/departments/technology\">Agoda</a> | Bangkok, Thailand | Take-home project, then a discussion onsite ro</li>\n<li></li>\n<li><a href=\"https://agrilyst.com/\">Agrilyst</a> | New York, NY / Remote | Short takehome project &#x26; remote pairing</li>\n<li></li>\n<li><a href=\"https://airbrake.io/\">Airbrake</a> | San Francisco, CA / Remote | Take-home project &#x26; pair on a problem similar to daily work</li>\n<li></li>\n<li><a href=\"http://aiwip.com/\">Aiwip</a> | London, UK | Skype/phone interview followed by takehome project or worksample (or whiteboard)</li>\n<li></li>\n<li><a href=\"http://ajira.tech/\">Ajira</a> | Chennai, India / Austin, TX | Take home project, then pair programming, technical discussions, cultural fit</li>\n<li></li>\n<li><a href=\"https://www.algolia.com/careers\">Algolia</a> | Paris, France / San Francisco, CA | Takehome project &#x26; Onsite discussions and presentation</li>\n<li></li>\n<li><a href=\"https://www.allaboutapps.at/jobs\">all about apps GmbH</a> | Vienna, Austria | 2-phase technical discussion &#x26; examination with department heads and management.</li>\n<li></li>\n<li><a href=\"https://allegro.pl/praca\">Allegro</a> | Warsaw, Poland; Poznan, Poland; Torun, Poland; Wroclaw, Poland; Krakow, Poland | Take home, simple project. Series of 2 technical interviews (how to build things, how to solve specific, real world problem) and meeting with a team leader.</li>\n<li></li>\n<li><a href=\"https://alluvium.io/\">Alluvium</a> | Brooklyn, NY | Take-home assignment, on-site review dovetailing into collaborative </li>\n<li></li>\n<li><a href=\"https://engineering.alphasights.com/\">AlphaSights</a> | London, UK / New York, NY / Remote | Initial interview, pair programming then final ro</li>\n<li></li>\n<li><a href=\"https://amagi.io/\">AMAGI</a> | Makati, Philippines | 1) Review of your resume, portfolio, and/or GitHub profile; 2) 1 hour discussion (in-person or Skype) about your goals, experience, personal culture, and how to apply technical solutions</li>\n<li></li>\n<li><a href=\"https://gastrograph.com/\">Analytical Flavor Systems</a> | Manhattan, New York | Code sample or take-home project, both with discussion.</li>\n<li></li>\n<li><a href=\"https://apolloagriculture.com/\">Apollo Agriculture</a> | Nairobi, Kenya/Remote | Takehome project or Work</li>\n<li></li>\n<li><a href=\"https://www.beapplied.com/\">Applied</a> | London, UK | Situational judgement tests focusing on real-world soft skills (online then in structured interview)</li>\n<li></li>\n<li><a href=\"https://angel.co/arachnys/jobs/220465-software-engineer\">Arachnys</a> | London, UK | Take home test, real world pair programming</li>\n<li></li>\n<li><a href=\"https://articulate.com/company/careers\">Articulate</a> | Remote | Take-home project &#x26; pair program on a problem similar to daily work</li>\n<li></li>\n<li><a href=\"https://www.artsy.net/jobs#engineering\">Artsy</a> | New York, NY / London, UK / Berlin, Germany / Los Angeles, CA / Hong Kong, Hong Kong / Remote | Our process: 1) Informal chat 2) Application 3) Phone screen 4) In-p</li>\n<li></li>\n<li><a href=\"https://www.asidatascience.com/careers\">ASI Data Science</a> | London, UK | Project to work at home, general technical questions, pair programming with engineers</li>\n<li></li>\n<li><a href=\"https://jobs.asos.com/epostings/index.cfm?fuseaction=app.jobsearch&#x26;company_id=30071&#x26;version=1&#x26;byBusinessUnit=5\">ASOS</a> | London, UK | Take home or in-per</li>\n<li></li>\n<li><a href=\"https://jobs.ataccama.com/\">Ataccama</a> | Prague, Czech Republic | Face to face interview (skype or onsite), coding task for </li>\n<li></li>\n<li><a href=\"https://atech.media/\">aTech Media</a> | London, UK | Face to face interview, review of existing open source contributions or, if none are available, asked to write a library for something that i</li>\n<li></li>\n<li><a href=\"https://auraframes.com/jobs?gh_src=2ef5cfa32\">Aura Frames</a> | New York, NY / San Francisco, CA | Simplified real-world coding task on Coderpad.i</li>\n<li></li>\n<li><a href=\"https://www.aurorasolar.com/careers\">Aurora Solar</a> | San Francisco, CA | Our process: 1) Initial phone call 2) 1 hour take home project in CoderP</li>\n<li></li>\n<li><a href=\"https://auth0.com/blog/how-we-hire-engineers\">Auth0</a> | Bellevue, WA / Buenos Aires, Argentina / Remote | Series of interviews, go </li>\n<li></li>\n<li><a href=\"https://www.auto1-group.com/jobs\">Auto1</a> | Berlin, DE | Series of Skype interviews which covers general technical questions, f</li>\n<li></li>\n<li><a href=\"https://automattic.com/work-with-us\">Automattic</a> | Remote | short take-home real-world ta</li>\n<li></li>\n<li><a href=\"https://github.com/AutoScout24/hiring\">AutoScout24</a> | Munich, Germany | Skype interview followed by home assignment from our day-to</li>\n<li></li>\n<li><a href=\"https://avant.com/jobs\">Avant</a> | Chicago, IL | Pair programming interviews.</li>\n<li></li>\n<li><a href=\"https://www.avarteq.com/career\">Avarteq GmbH</a> | Berlin, Germany / Saarbrücken, Germany | Technical interview w</li>\n<li></li>\n<li><a href=\"https://www.avocarrot.com/company\">Avocarrot</a> | Athens, Greece | on-site real world problem discussion and pair programming</li>\n<li></li>\n<li><a href=\"https://www.axelerant.com/careers\">Axelerant</a> | Remote | Take-home project, interviews with hr and engineering team.</li>\n<li></li>\n<li><a href=\"https://axiacore.com/\">Axiacore</a> | Bogota, Colombia | We talk about on how is your process when solving problems.</li>\n<li></li>\n<li><a href=\"https://www.axios.com/about#jobs\">Axios</a> | Arlington, VA / New York, NY / San Francisco, CA / Remote | Take-home project, with discussion.</li>\n<li></li>\n<li><a href=\"https://boards.greenhouse.io/b12#.WMlLfRIrJTa\">B12</a> | New York, NY | Take-home exercises and pair-programming w</li>\n<li></li>\n<li><a href=\"http://somos.b2wdigital.com/bit\">B2W Digital</a> | Rio de Janeiro, Brazil; São Paulo, Brazil | Time-boxed coding exercise at home, on-site pair programming with engineers and live software architecture challenges based on real situations.</li>\n<li></li>\n<li><a href=\"https://github.com/Babylonpartners/iOS-Interview-Demo\">Babylon Health iOS Team</a> | London, UK | Take-home project, on-site presentation and discussion, design and product interview.</li>\n<li></li>\n<li><a href=\"http://careers.backbase.com/\">Backbase</a> | Amsterdam, Netherlands; Cardiff, Wales; London, UK; Atlanta, GA | Takehome project, interviews</li>\n<li></li>\n<li><a href=\"https://jobs.badi.com/\">Badi</a> | Barcelona, Spain | Phone Screen, Take-home project, then a discussion onsite round.</li>\n<li></li>\n<li><a href=\"https://team.badoo.com/jobs\">Badoo</a> | London, UK | Take-home project, then a discussion onsite round.</li>\n<li></li>\n<li><a href=\"https://career012.successfactors.eu/sfcareer/jobreqcareer?jobId=46145&#x26;company=BAE\">BAE Systems Applied Intelligence</a> | L</li>\n<li></li>\n<li><a href=\"https://bakkenbaeck.com/jobs\">Bakken &#x26; Bæck</a> | Oslo, Norway; Amsterdam, Netherlands; Bonn, Germany | Skype interview followed by take-home assignment and a visit to one of our offices</li>\n<li></li>\n<li><a href=\"https://career.balabit.com/\">Balabit</a> | Budapest, Hungary | Take-home project (medium size, with restrictions, e.g. only stdlib may be used), then discussion on-site</li>\n<li></li>\n<li><a href=\"https://www.barracuda.com/company/careers\">Barracuda View Team</a> | Chelmsford, MA / Remote | Phone screen, remote pair programming session, technical discussion interview, culture fit interview</li>\n<li></li>\n<li><a href=\"https://basecamp.com/about/jobs\">Basecamp</a> | Chicago, IL / Remote</li>\n<li></li>\n<li><a href=\"https://beam.dental/jobs\">Beam Dental</a> | Columbus, OH | Phone Screen, Take Home Project, In-Person Pairing and </li>\n<li></li>\n<li><a href=\"http://belka.us/lavora-con-no\">Belka</a> | Trento, Italy; Munich, Germany | We give you a small task that you can do alone and then we evaluate your work with you</li>\n<li></li>\n<li><a href=\"https://bemind.recruitee.com/\">Bemind Interactive</a> | Biella, Italy / Latina, Italy / Remote | Series of interviews, discussion about techn</li>\n<li></li>\n<li><a href=\"https://bendyworks.com/careers\">Bendyworks</a> | Madison, WI | Interviews and pair programming on personal projects</li>\n<li></li>\n<li><a href=\"https://www.betterment.com/careers\">Betterment</a> | New York, NY | Phone interview followed by on-site pair programming to simulate a Betterment feature build.</li>\n<li></li>\n<li><a href=\"https://www.betterpt.com/\">BetterPT</a> | New York, NY | Initial phone interview, project using our tech stack, on-site code review/pair programming and \"meet </li>\n<li></li>\n<li><a href=\"https://www.bignerdranch.com/about/careers\">Big Nerd Ranch</a> | Atlanta, GA &#x26; Remote | Interviews and pair programming on an internal project or problem.</li>\n<li></li>\n<li><a href=\"https://www.bioconnect.com/company/careers\">BioConnect</a> | Toronto, Canada | Take-home assignment &#x26; discussion</li>\n<li></li>\n<li><a href=\"https://www.bitexpert.de/karriere\">bitExpert AG</a> | Mannheim, Germany | Interview with experience based tec</li>\n<li></li>\n<li><a href=\"https://www.bitsoflove.be/careers\">Bits of Love</a> | Bruges, Belgium | In-person interview to evaluate experience and moti</li>\n<li></li>\n<li><a href=\"http://blackdotsolutions.com/\">Blackdot Solutions</a> | Cambridge, UK | Take-home project followed by on-site face-to-face walkthru of your code focusing on decisions/</li>\n<li></li>\n<li><a href=\"http://bleacherreport.com/\">Bleacher Report</a> | San Francisco, CA, USA | Take-home project; on-site discussion about the project and meeting with di</li>\n<li></li>\n<li><a href=\"https://blendle.homerun.co/?lang=en\">Blendle</a> | Utrecht, The Netherlands | Take-home pro</li>\n<li></li>\n<li><a href=\"https://github.com/blogfoster/join-the-engineering-team\">blogfoster</a> | Berlin, Germany | Take-home project, discussion on-site</li>\n<li><a href=\"https://www.bluebottlecoffee.com/careers\">Blue Bottle Coffee</a> | Oakland, CA | Technical Phone Screen, Take Home Challenge, Technical in-persons.</li>\n<li><a href=\"http://www.bluesoft.com.br/\">Bluesoft</a> | São Paulo, Brazil | Takehome project and an interview to evaluate the candidate's previous experience.</li>\n<li><a href=\"https://bocoup.com/careers\">Bocoup</a> | Boston, MA / Remote | Pair programming with personal laptop on typical problem seen at work</li>\n<li><a href=\"http://careers.bolste.com/\">Bolste</a> | Phoenix, AZ | Conversational in-person interviews with team members and pair programming through real world problems</li>\n<li><a href=\"https://www.bookingsync.com/en/jobs\">BookingSync</a> | Remote | Small takehome project, interviews over skype with team members.</li>\n<li><a href=\"http://boomtownroi.com/\">BoomTown</a> | Charleston, SC / Atlanta, GA / Remote | Conversational in-person interviews with potential team members and managers that revolve around past experience and how that could be applied to future work</li>\n<li><a href=\"http://www.bouvet.no/\">Bouvet</a> | Bergen, Norway | Pair programming with senior engineers</li>\n<li><a href=\"https://brainn.co/\">brainn.co</a> | São Paulo, BR | Zoom/On-site interview, take-home project and interview with a team leader.</li>\n<li><a href=\"http://brainstation-23.com/\">BrainStation-23</a> | Dhaka, BD | A practical project followed by series of in-person interview sessions</li>\n<li><a href=\"https://breather.com/jobs\">Breather</a> | Montreal, Canada | Series of interviews including a conversation about the candidate's experience and a technical discussion involving real world problems</li>\n<li><a href=\"http://www.brightbytes.net/careers\">BrightBytes</a> | San Francisco, CA | Time-boxed coding exercise at home and on-site pair programming with engineers</li>\n<li><a href=\"https://www.brighthr.com/careers\">BrightHR</a> | Manchester, UK | Telephone conversation, coding exercise at home, on-site pairing with a cultural interview, meet the team.</li>\n<li><a href=\"https://angel.co/brightwheel/jobs\">brightwheel</a> | San Francisco, CA | Take home exercise, and systems design.</li>\n<li><a href=\"https://www.broadinstitute.org/data-sciences-platform\">Broad Institute's Data Sciences Platform</a> | Cambridge, MA | Phone screen, small take home project, both a technical and non-technical discussion panel, and a panel following up on the take home project walking through the solution and making a modification to the original code</li>\n<li><a href=\"https://www.bubbl.in/about\">Bubblin Superbooks</a> | Remote | View code, projects, libraries or any other open source story that you have been a part of, a small take-home project with real code occasionally.</li>\n<li><a href=\"https://buffer.com/journey\">Buffer</a> | Remote | Interviews over video call, code walkthrough of real code focussing on decisions and reasoning, then a 45 day full time, fully paid contract project working on production code.</li>\n<li><a href=\"https://www.bugcrowd.com/about/careers/\">Bugcrowd</a> | San Francisco, CA / Sydney, NSW | Take home exercise, half-day onsite walking through code, and pair programming.</li>\n<li><a href=\"http://www.buhlergroup.com/\">Buhler Group</a> | Prague, CZ | Interview with a couple of technical questions. No task needed. Depending on the team there is another round with the guys in the HQ via skype.</li>\n<li><a href=\"https://www.bulb.co.uk/\">Bulb</a> | London, UK | Phone screening, followed by a 2-4 hours take home task. If successful, on-site interview to discuss and extend with the reviewer and one other engineer, followed by 2x informal \"Meet the team\" interviews.</li>\n<li><a href=\"https://www.busbud.com/en/careers\">Busbud</a> | Montreal, Canada | Phone screening, followed by a 2-4 hours take home assignment. If the challenge is a success, on-site or remote interview with team members, including someone who reviewed it, to talk about it and potential next steps if the challenge was a real life task.</li>\n<li><a href=\"https://www.bustle.com/labs\">Bustle</a> | New York City, Ny / Remote | Half day pair programming on a task for production or one of our Open Source projects. We'll also buy you lunch with the team.</li>\n<li><a href=\"https://www.busuu.com/jobs\">busuu</a> | London, UK | Video call to show real code as first stage. In office pair programming, white board real world problem that we've encountered before, and history/experience discussion.</li>\n<li><a href=\"https://buttercms.com/\">ButterCMS</a> | Chicago, IL; Remote | Take home exercise and half-day of pair programming</li>\n<li><a href=\"https://www.bybox.com/company/careers/\">ByBox</a> | Remote | Phone interview followed by interview with devs (ideally in person but sometimes Skype) covering technical experience and coding exercise with real code.</li>\n<li><a href=\"http://careers.caci.com/ListJobs/All/Search/location/rome/state/ny/country/us\">CACI Rome</a> | Rome, NY; Remote | Phone interview followed by in-person or Skype screen sharing interview with a coding exercise in either Java, web (Node.js + frontend), or both. Interview format is exclusive to the Rome, NY office and may not be shared by other regional CACI offices.</li>\n<li><a href=\"http://www.cakesolutions.net/careers\">Cake Solutions</a> | Manchester, UK; London, UK; New York, NY | Skype / Hangouts / phone call to explain the technical background, current position and set expectations about the salary, relocation, etc; if all good, what to expect next. Then take-home exercise for roughly 4 hours to demonstrate good thinking and ability to pick up new things, explain &#x26; document the solution, finishing with pair programming with senior developers (remote or in person); use the code as a talking point around the more difficult things after getting through the simple starter tasks.</li>\n<li><a href=\"https://www.uk.capgemini.com/\">Capgemini UK Java Team</a> | London, UK; Woking, UK; Bristol, UK; Cardiff, Wales; Birmingham, UK; Manchester, UK; Leeds, UK; Rotherham, UK; Liverpool, UK; Newcastle, UK; Edinburgh, Scotland; Glasgow, Scotland | Technical telephone interview (30 minutes), take-home non-CompSci coding exercise (3-4 hours), face-to-face role-played consulting scenario involving a solution architecture and a delivery plan (two hours)</li>\n<li><a href=\"http://www.caravelo.com/softdev\">Caravelo</a> | Barcelona, Spain | Take home project, then technical discussion about the code in-person or Skype and hang out with the team.</li>\n<li><a href=\"http://www.cartegraph.com/company/careers/\">Cartegraph</a> | Dubuque, IA / Remote | Phone screen, hiring manager interview, small take-home coding project, and team code review/interview</li>\n<li><a href=\"http://www.carto.com/careers/\">CARTO</a> | Madrid, Spain | Phone screen, take-home project, team code review/interview, hiring manager interview</li>\n<li><a href=\"https://casetext.com/jobs\">Casetext</a> | San Francisco, CA | Submit code sample for review/discussion, contract for one full day (paid)</li>\n<li><a href=\"https://cashlink.de/\">CASHLINK</a> | Frankfurt, Germany | Skype/phone interview, take-home project</li>\n<li><a href=\"http://www.causeway.com/content/opportunity\">Causeway</a> | United Kingdom, India | Skype or Telephonic discussion on approaches and experience in regards to solve projects related work, then face to face round to write small solutions to common problems in related field.</li>\n<li><a href=\"https://centroida.co/contact.html\">Centroida</a> | Sofia, Bulgaria | Series of interviews, pair programming and take-home projects</li>\n<li><a href=\"http://chainreaction.io/\">Chain.Reaction</a> | Budapest, Hungary | Partnership-fit discussion, code-review and trial days.</li>\n<li><a href=\"https://chargify.com/jobs\">Chargify</a> | San Antonio, TX / Remote | Take-home project &#x26; pair on a problem similar to daily work</li>\n<li><a href=\"https://checkout51.com/jobs\">Checkout 51</a> | Toronto, Canada | Phone conversation (15-20 minutes) followed by on-site pair programming and discussion focused on understanding decisions made during on-site work</li>\n<li><a href=\"http://ctic-inc.com/careers/\">Chesapeake Technology</a> | Denver, CO / Santa Barbara, CA / Camarillo, CA / Dulles, VA / California, MD / Remote | Phone screen (30 minutes), take home at leisure question based on real development followed by in person review of solution and general technical questions with actual team and opportunity for you to ask questions and provide feedback ( 2-3 hours)</li>\n<li><a href=\"https://circleci.com/\">CircleCI</a> | San Francisco, CA / Remote | Take-home project and discussion, followed by on-site interview that includes pair programming on actual CircleCI bugs/feature requests.</li>\n<li><a href=\"https://boston.gov/analytics\">City of Boston's Analytics Team</a> | Boston, MA | Take-home project and in-person or phone/Skype interviews</li>\n<li><a href=\"https://beta.phila.gov/departments/office-of-open-data-and-digital-transformation/jobs\">City of Philadelphia's Office of Open Data &#x26; Digital Transformation</a> | Philadelphia, PA | Take-home project</li>\n<li><a href=\"https://www.civisanalytics.com/careers\">Civis Analytics</a> | Chicago, IL | Take-home project and discussion via Skype, followed by pair programming exercise</li>\n<li><a href=\"http://jobs.cj.com/jobs/category/engineering/\">CJ Affiliate</a> | Los Angeles, CA &#x26; Westlake Village, CA | Phone coding design exercise (no algorithms), followed by an on-site final interview that includes pair programming on a realistic object-oriented design problem</li>\n<li><a href=\"https://clara.com/careers\">Clara Lending</a> | San Francisco, CA | Phone conversation around technical background and experience, followed by take-home project, pair programming and discussion</li>\n<li><a href=\"https://angel.co/clerkie/jobs\">Clerkie</a> | San Francisco, CA | Phone conversation followed by take-home project</li>\n<li><a href=\"https://www.clickmagick.com/\">ClickMagick</a> | Austin, TX / Remote | Phone conversations and examples of Free Software/Open Source work</li>\n<li><a href=\"https://clippings.com/\">Clippings</a> | Sofia, Bulgaria | Video screening first, then send us code they've recently wrote, then technical interview. We could ask questions about the code they wrote at home.</li>\n<li><a href=\"https://www.cwconsult.dk/\">Clockwork Consulting</a> | Copenhagen, Denmark | Interviews, discussion of technical background and experiences.</li>\n<li><a href=\"https://www.cloudistics.com/careers\">Cloudistics</a> | Reston, VA | Multiple interviews, discussion of technical background and experiences.</li>\n<li><a href=\"https://www.clubhouse.io/hiring\">Clubhouse</a> | New York, NY &#x26; Remote | Phone interview, followed by onsite discussions and pair programming</li>\n<li><a href=\"https://www.cogent.co.jp/\">Cogent Labs</a> | Tokyo, Japan | On-site or video call conversation around technical background and experience, followed by take-home project that resembles a problem Cogent Labs solves for. This project will serve as the base of discussion with the developers for the second interview.</li>\n<li><a href=\"https://www.cognitect.com/jobs\">Cognitect, Inc.</a> | Remote | Phone interview followed by pair programming.</li>\n<li><a href=\"http://www.cognitran.com/employment-opportunities\">Cognitran</a> | Essex, UK / Szczecin, Poland / Detroit, MI | Skype/phone interview followed by pair programming.</li>\n<li><a href=\"https://www.collabora.com/careers.html\">Collabora</a> | Cambridge, UK / Montreal, Canada / Remote | On-site or video interview, discussion of technical experience and sometimes approach for tackling a hypothetical problem.</li>\n<li><a href=\"https://www.compeon.de/karriere\">COMPEON</a> | Duesseldorf, Germany | Phone interview, followed by onsite discussions and pair programming with our developers</li>\n<li><a href=\"http://about.cph.org/careers.html\">Concordia Publishing House</a> | St Louis, MO | Take-home project followed by discussion of it on-site with future teammates.</li>\n<li><a href=\"http://contactlab.com/en/careers\">Contactlab</a> | Milan, Italy | Recruiter interview, tech interview (technical background and experiences), both on-site.</li>\n<li><a href=\"https://www.contentful.com/careers\">Contentful</a> | Berlin, Germany &#x26; SF, USA | Multiple interviews, discussion of technical background &#x26; live coding challenge (you can use the internet).</li>\n<li><a href=\"https://www.contentsquare.com/careers\">ContentSquare</a> | Paris, France | Real-world challenges with open discussions.</li>\n<li><a href=\"https://cookpad.com/us\">Cookpad</a> | Tokyo, Japan; Bristol, UK | Interviews, discussion of technical background and experiences, remotely pair with devs.</li>\n<li><a href=\"https://www.coorpacademy.com/\">Coorp Academy</a> | Paris, France | Technical interview as an open discussion</li>\n<li><a href=\"https://www.coverhound.com/\">CoverHound, Inc.</a> | San Francisco, CA | Open technical discussion, short on-site coding challenge.</li>\n<li><a href=\"https://creditkudos.com/jobs\">Credit Kudos</a> | London, UK | Take-home project and pair programming via Skype or on-site.</li>\n<li><a href=\"https://crossbrowsertesting.com/\">CrossBrowserTesting</a> | Memphis, TN | Take home project that resembles a problem support engineers deal with on a daily basis. On-Site interviews in a comfortable environement with a focus on hiring talented people vs exact skill-sets.</li>\n<li><a href=\"https://jobs.jobvite.com/careers/crowdstrike/jobs\">Crowdstrike</a> | Remote | Multiple interviews onsite or remote as appropriate followed by small take-home project.</li>\n<li><a href=\"https://crownstone.rocks/jobs\">Crownstone</a> | Rotterdam, Netherlands | Technical interaction using previously created Github projects, followed by in-person interview with a focus on someone's professional ambition in the short and long term.</li>\n<li><a href=\"https://www.cube19.com/work-with-us/\">cube19</a> | London, UK | Take-home project, then an on-site discussion about the code and previous experience.</li>\n<li><a href=\"https://cultivatehq.com/\">Cultivate</a> | Edinburgh, UK | 30 minute pair-programming screening interview on a simple exercise (remote or in-person). Half day pair programming, with 3 or 4 different team members plus informal chat, typically on-site.</li>\n<li><a href=\"https://www.culturefoundry.com/\">Culture Foundry</a> | Austin, TX | Paid take-home project</li>\n<li><a href=\"https://www.currencytransfer.com/\">CurrencyTransfer</a> | London, UK &#x26; Remote | Take-home project</li>\n</ul>\n<h2>D - F</h2>\n<ul>\n<li><a href=\"https://darksky.net/jobs\">Dark Sky</a> | Cambridge, MA | Phone interviews and a very short, real paid project</li>\n<li></li>\n<li><a href=\"http://www.datatheorem.com/\">Data Theorem</a> | Palo Alto, CA; Paris, Fr; Bangladesh, India | Phone interview, then a take home project and finally in-person interview.</li>\n<li></li>\n<li><a href=\"https://datalogue.github.io/recruiting\">Datalogue</a> | Montreal, Canada | We Ask candidates to contribute meaningfully to an Open source project that reflects the stack they will be wor</li>\n<li></li>\n<li><a href=\"https://datamade.us/\">DataMade</a> | Chicago, IL | After submitting an application, selected applicants are moved on to a round of interviews and will be asked to submit a piece of code </li>\n<li></li>\n<li><a href=\"https://datascope.co/careers\">Datascope</a> | Chicago, IL | Take home exploratory data project with public data, dis</li>\n<li></li>\n<li><a href=\"http://www.datlinq.com/en/vacancies\">Datlinq</a> | Rotterdam, Netherlands | Take-home project based on actual work on data done by the</li>\n<li></li>\n<li><a href=\"https://dealtap.ca/\">DealTap</a> | Toronto, Canada | Technical Interview, Solution Design, Take Home Assignment, then Culture fit interview with the team, and optional pa</li>\n<li></li>\n<li><a href=\"https://www.defmethod.com/\">Def Method</a> | NYC, NY | Take home test, pair programming with dev on test and client work, receive offer same day as pairing interview</li>\n<li></li>\n<li><a href=\"https://deliveroo.co.uk/careers\">Deliveroo</a> | London, UK &#x26; Remote | Short take-home project and pa</li>\n<li></li>\n<li><a href=\"https://angel.co/dentolo\">Dentolo</a> | Berlin, Germany | Phone interview with the HR department, take-home project and technical inte</li>\n<li></li>\n<li><a href=\"https://www.deskbookers.com/en-gb/jobs\">Deskbookers</a> | Amsterdam, Netherlands | Phone screen, take-home project, on-site interview</li>\n<li></li>\n<li><a href=\"https://www.desmart.com/\">DeSmart</a> | Gdynia, Poland | Technical interview, take-home project and talk about y</li>\n<li></li>\n<li><a href=\"https://despark.com/\">Despark</a> | Sofia, Bulgaria &#x26; Remote | Culture add interview, sample code review and paid pair programming with team member or take-home project.</li>\n<li></li>\n<li><a href=\"https://www.detroitlabs.com/careers\">Detroit Labs</a> | Detroit, MI | Our technical interview starts with a take-home assignment that we will look at during the </li>\n<li></li>\n<li><a href=\"https://www.devmynd.com/\">DevMynd</a> | Chicago, IL; San Francisco, CA | Take-home project, take-home project phone </li>\n<li></li>\n<li><a href=\"https://www.dg-i.net/\">DG-i</a> | Cologne, Germany | Take-home project and/or discussion on-site about past experiences</li>\n<li></li>\n<li><a href=\"http://www.dice.se/\">DICE</a> | Stockholm, Sweden | Take-home project and code review at the on-site</li>\n<li></li>\n<li><a href=\"http://www.di.fm/jobs\">Digitally Imported</a> | Denver, Colorado &#x26; Remote | Video meetings on past experience and high level tech questions, take-home project</li>\n<li></li>\n<li><a href=\"https://www.dollarshaveclub.com/\">Dollar Shave Club</a> | Venice, California | Phone interview, take-home projects, on-site interview</li>\n<li></li>\n<li><a href=\"http://door2door.io/\">door2door</a> | Berlin, Germany | Take home challenge + on-site interview + trial day</li>\n<li></li>\n<li><a href=\"https://doordash.com/careers\">DoorDash 🏃💨</a> | San Francisco, CA | Take home project + an on-site interview building of</li>\n<li></li>\n<li><a href=\"https://docs.google.com/document/d/1fC_-liTPpYQOoE_5iKj0O3AwSdPggQGnOsjUKahfbkQ/edit?usp=sharing\">Draft Fantasy</a> | Tel Aviv, Israel | Talk about past experience and what the developer has actua</li>\n<li></li>\n<li><a href=\"https://www.drawbotics.com/en/join-us\">Drawbotics</a> | Brussels, Belgium | Take-home project, bootcamp on-site</li>\n<li></li>\n<li><a href=\"https://www.drchrono.com/careers\">drchrono</a> | Mountain View, CA | Hackerrank test (but not CS trivia, it's real product problems) &#x26; on-site/take-home project w/ presentation</li>\n<li></li>\n<li><a href=\"https://www.drivy.com/\">Drivy</a> | Paris, France | Phone screening followed by a take-home as</li>\n<li></li>\n<li><a href=\"https://www.dronedeploy.com/careers.html\">DroneDeploy</a> | San Francisco, CA | Pair program on a problem similar to daily work</li>\n<li></li>\n<li><a href=\"https://www.droneseed.co/jobs/\">DroneSeed</a> | Seattle, WA | Take home assignment of a real problem we've worked on, group code review in subsequent interview.</li>\n<li></li>\n<li><a href=\"http://blog.dubizzle.com/uae/job-vacancies\">dubizzle</a> | Dubai, UAE | Take home assignment, general technical questions, pair programming with engineers or tech leads</li>\n<li></li>\n<li><a href=\"https://www.e-accent.com/\">E-accent</a> | Hilversum, Netherlands; Remote | Skype conversation, take-home assignment</li>\n<li></li>\n<li><a href=\"http://easytaxi.com.br/\">Easy Taxi</a> | São Paulo, Brazil | Take-home project, interview to evaluate the candidate's previous experience.</li>\n<li></li>\n<li><a href=\"https://eaze.com/careers\">Eaze</a> | San Francisco, CA | Take home project, on-site interview building off of the project</li>\n<li></li>\n<li>[eBay Kleinanzeigen](<a href=\"https://careers.ebayinc.com/join-our-team/start-your-search/find-jobs-by-lo\">https://careers.ebayinc.com/join-our-team/start-your-search/find-jobs-by-lo</a></li>\n<li></li>\n<li><a href=\"https://echobind.com/careers\">Echobind</a> | Boston, MA; Remote | Meet the entire team, share examples of previous work and pair with one team member</li>\n<li></li>\n<li><a href=\"https://jobs.edenspiekermann.com/\">Edenspiekermann</a> | Amsterdam, Netherlands / Berlin, Germany / Los Angeles, CA / San Francisco, CA / Singapore, Sin</li>\n<li></li>\n<li><a href=\"https://careers.ef.com/\">EF Education First</a> | London, UK; Boston, MA | Short phone interview, take-home project, discussion of project and real world engineering</li>\n<li></li>\n<li><a href=\"http://eidu.com/\">Eidu</a> | Berlin, Germany | Take-home project, discussion of results with team, and test days with pair programming</li>\n<li></li>\n<li><a href=\"http://www.elpassion.com/\">El Passion</a> | Warsaw, Poland | Take-home project, interview to 1) </li>\n<li></li>\n<li><a href=\"https://www.electricpulp.com/\">Electric Pulp</a> | Sioux Falls, SD, USA | Phone interviews with lead</li>\n<li></li>\n<li><a href=\"https://www.elements.nl/careers\">Elements Interactive</a> | Almere, The Netherlands &#x26; Barcelona, Spain | Take-home project &#x26; discussion via Skype or on-site</li>\n<li></li>\n<li><a href=\"https://www.ellucian.com/About-Us/Careers/\">Ellucian</a> | Reston, VA, USA | Discussion of real world problems (from resume, </li>\n<li></li>\n<li><a href=\"https://elmah.io/\">elmah.io</a> | Aarhus, Denmark / Remote | Discussion about code and looking at hobby projects (if</li>\n<li></li>\n<li><a href=\"https://www.elvie.com/\">Elvie</a> | London, England | Discussing real code, pairing and a paid day to see how you work with the team. No coding for free or time-restricted take-home projects, code challenges or abstract algorithm tests</li>\n<li><a href=\"https://goo.gl/N7SMKl\">eMarketer</a> | New York, NY | Short phone interview, then come in and meet the team, check out our space, and have a discussion with team members about real-world problems</li>\n<li><a href=\"https://www.emarsys.com/\">Emarsys</a> | Budapest, Hungary | Take-home project (small, 1-2 days to solve), then discussion on-site</li>\n<li><a href=\"http://www.endava.com/en/Careers\">Endava</a> | Belgrade, Serbia; Bucharest, Romania; Chisinau, Moldova; Cluj-Napoca, Romania; Iasi, Romania; Pitesti, Romania; Skopje, Macedonia; Sofia, Bulgaria; Frankfurt, Germany; Glasgow, Scotland; Hilversum, Netherlands; London, UK; Oxford, UK; Bogota, Colombia; Atlanta, GA; New Jersey, NJ; New York, NY | On-site discussion about previous experience and technical questions about the target technologies.</li>\n<li><a href=\"https://www.engelvoelkers.com/en/tech/\">Engel &#x26; Völkers Technology</a> | Hamburg, Germany | Remote technical interview with an Engineering Manager, followed by a practical coding challenge implemented in 5 hours, ending with a technical discussion with the team on the produced code either remotely or on-site based on geographical practicality.</li>\n<li><a href=\"https://enhancv.com/about.html\">Enhancv</a> | Sofia, Bulgaria | Talk is cheap, show us your code: github profile or other project examples. Explain them in person / remotely. Discuss habits and interests to see if we have a culture fit.</li>\n<li><a href=\"https://www.enigma.com/\">Enigma</a> | New York, NY | 2-part takehome project, followed by a pair programming exercise</li>\n<li><a href=\"https://enki.com/\">Enki</a> | London, UK | Skype/phone interview followed by takehome project</li>\n<li><a href=\"https://ento.com/blog/ento-interview-process-101\">Ento.com</a> | Melbourne, Australia | On-site interview to talk about your experiences and what you're looking for in your next role, followed by a take-home practical test relevant to the work you'll be undertaking at Ento.</li>\n<li><a href=\"https://www.equalexperts.com/\">Equal Experts</a> | London, UK; Manchester, UK; New York, NY; Pune, India; Lisbon, Portugal; Calgary, Canada | Fizzbuzz test done at home followed by Pair Programming session at office and finally face to face technical and attitude interview.</li>\n<li><a href=\"https://www.ericsson.com/\">Ericsson</a> | Dublin, Ireland | Skype/phone interview followed by Face 2 Face interview, discussions and architecture questions followed by final small project on a problem similar to daily work.</li>\n<li><a href=\"https://esharesinc.com/jobs\">eShares, Inc</a> | San Francisco, CA; Palo Alto, CA; Seattle, WA; Rio de Janeiro, Brazil; London, UK; New York, NY | Phone call, practical technical screen, on site to meet the team &#x26; explore the company</li>\n<li><a href=\"https://www.etixeverywhere.com/en/job-offers\">Etix Everywhere</a> | Luxembourg City, Luxembourg</li>\n<li><a href=\"https://euranova.eu/\">EURA NOVA</a> | Mont-Saint-Guibert, Belgium; Marseille, France; Tunis, Tunisia | attitude interview, unpaid take-home project, technical discussion with 1 or 2 technical employees (remote or face 2 face), face 2 face discussion with HR, partner, and technical staff to have a foretaste of the collaboration</li>\n<li><a href=\"http://www.europaymentgroup.com/\">Euro Payment Group</a> | Frankfurt, Germany | Take-home project followed by face to face interview</li>\n<li><a href=\"https://exoscale.ch/\">Exoscale</a> | Bern, Switzerland | Take-home project. Discussion and presentation. Then entire team meet.</li>\n<li><a href=\"https://fdex.com.br/\">F(x)</a> | São Paulo, Brazil | Skype interview, Take-home project and onsite interview to evaluate the candidate</li>\n<li><a href=\"https://www.falcon.io/jobs/\">Falcon.io</a> | Copenhagen, Denmark | Initial call/Skype culture interview. Take-home tech assignment (game) and code review. On-site Interview about your experience and meeting the team.</li>\n<li><a href=\"https://www.fatmap.com/\">FATMAP</a> | London, UK; Berlin, Germany; Vilnius, Lithuania | Skype discussion, Take-home project, Face to face</li>\n<li><a href=\"https://fauna.com/\">Fauna</a> | San Francisco, CA / Remote | Take home project, then follow up with interviews on-site or remote. Interviews are both technical and non-technical. Technical interviews comprehend the scope of the home project.</li>\n<li><a href=\"https://feather-cfm.com/\">Feather</a> | Remote | Take-home challenge, portfolio discussion &#x26; team meeting</li>\n<li><a href=\"https://blog.findy.us/findy-saiyo\">Findy</a> | Tokyo, Japan | Tech interview + On-site discussion</li>\n<li><a href=\"https://www.wearefine.com/careers\">FINE</a> | Portland, OR | Small take-home challenge + follow-up discussion</li>\n<li><a href=\"https://www.firemind.io/\">Firemind</a> | Maidstone, UK; London, UK; Remote | Small pre-interview challenge on github + discussion face to face in person or via video</li>\n<li><a href=\"https://thefitbot.com/careers.html\">Fitbot</a> | Boulder, CO | Pairing &#x26; writing code with the founders for a few hours</li>\n<li><a href=\"https://flatfox.ch/\">Flatfox</a> | Zurich, Switzerland | Informal conversation to check mutual fit, small (4h) take-home assignment, discussion in team</li>\n<li><a href=\"https://fluidly.com/\">Fluidly</a> | London, UK | Casual 30min phone call. ~1hr take home tech exercise (not pass or fail). 1 stage onsite interview - discussion about experience, 1 hour pair programming on the real code base, then your turn to interview us!</li>\n<li><a href=\"https://food52.com/jobs\">Food52</a> | New York, NY; Remote | Take-home project, discussion on-site or remote, interviews with both technical and non-technical staff</li>\n<li><a href=\"https://fooji.com/\">Fooji</a> | Lexington, KY; Remote | Take-home project</li>\n<li><a href=\"https://www.formidable.com/careers\">Formidable Labs</a> | Seattle, WA; London, UK; Remote | Take-home project, remote pair programming, discussion on-site or remote</li>\n<li><a href=\"https://fortumo.com/careers\">Fortumo</a> | Tallinn, Estonia; Tartu, Estonia | After a 30-min call you get a simplified version of a task that has recently been a challenge for the engineering team</li>\n<li><a href=\"https://founders.as/joinus\">Founders</a> | Copenhagen, Denmark | Take Home project + Interviews</li>\n<li><a href=\"http://www.foundryinteractive.com/contact\">Foundry Interactive</a> | Seattle, WA | On-site or remote discussion, paid trial project with pairing and code reviews</li>\n<li><a href=\"https://www.fournova.com/jobs\">fournova</a> | Remote | Take-home project, discussion via video call</li>\n<li><a href=\"https://www.freeagent.com/company/careers\">FreeAgent</a> | Edinburgh, UK | Take-home project, pair programming, discussion and interviews</li>\n<li><a href=\"https://www.freeletics.com/en/corporate/jobs\">Freeletics</a> | Munich, Germany | Small real-world challenge, multiple interviews on-site/remote and social gathering with team.</li>\n<li><a href=\"https://www.freetrade.io/careers\">Freetrade</a> | London, England | Initial hangout with fizz buzz style question followed by an on-site real world coding question and systems design conversation.</li>\n<li><a href=\"https://friday-jobs.personio.de/\">FRIDAY</a> | Berlin, Germany | Take-home real-world challenge, interview on-site or remote</li>\n<li><a href=\"https://frontside.io/careers\">Frontside</a> | Austin, Texas | Phone interview with remote pairing session. Followed by in person pairing (paid for the day) and lunch with the team.</li>\n<li><a href=\"https://www.funda.nl/vacatures\">Funda</a> | Amsterdam, The Netherlands | Take Home test + Discussion On-Site/Remote</li>\n<li><a href=\"https://www.fundapps.co/about-us/join-our-team\">FundApps</a> | London, UK | Coffee with an Engineer; take-home kata; code review + on-site pair programming exercise.</li>\n</ul>\n<h2>G - I</h2>\n<ul>\n<li><a href=\"https://www.gamevycareers.com/\">Gamevy</a> | London, UK; Bilbao, ES; Remote | Informal culture discussions, pair programming with our engineers</li>\n<li></li>\n<li><a href=\"https://www.garnercorp.com/\">Garner</a> | Toronto, Canada | step 1: online chat with hiring manager, step 2: at home assignment solving real-life problem, step</li>\n<li></li>\n<li><a href=\"https://gathercontent.com/careers/designer\">GatherContent</a> | Remote | Culture-first interviews, pair programming and remote, informal technical discussions</li>\n<li></li>\n<li><a href=\"https://generalui.com/\">GeneralUI</a> | Seattle, WA | A short phone screen with questions regarding general knowledge related to the</li>\n<li></li>\n<li><a href=\"http://jobs.ginetta.net/\">Ginetta</a> | Zurich, Switzerland; Braga, Portugal | Culture-first interviews, take home assignment that resembles a real-wor</li>\n<li></li>\n<li><a href=\"https://github.com/about/careers\">GitHub</a> | Remote; San Francisco, CA; Boulder, CO| Take-home exercise, code review and technical discussions.</li>\n<li></li>\n<li><a href=\"https://www.gitprime.com/\">GitPrime</a> | Denver, CO; Remote | small short term real-world projec</li>\n<li></li>\n<li><a href=\"https://glints.com/sg/inside/careers/\">Glints</a> | Singapore, Singapore; Jakarta, Indonesia | Culture </li>\n<li></li>\n<li><a href=\"https://gocardless.com/about/jobs\">GoCardless</a> | London, UK | Project to work at home, general technical questions, pair programming with</li>\n<li></li>\n<li><a href=\"https://www.godaddy.com/careers/overview\">GoDaddy</a> | Sunnyvale, CA | Pair programming with senior engineers</li>\n<li></li>\n<li><a href=\"https://www.gojek.io/\">GoJek</a> | Bangalore, India; Jakarta, Indonesia; Singapore, SG; Bangkok, Thailand | Take-home exercise, Pair programming wit</li>\n<li></li>\n<li><a href=\"http://gower.st/\">Gower Street Analytics</a> | Remote; London, UK | Initial telephone chat, then either a) work with us, fully p</li>\n<li></li>\n<li><a href=\"https://www.graffino.com/\">Graffino</a> | Sibiu, Romania | Take-home project, discussion on-site</li>\n<li></li>\n<li><a href=\"https://graftonstudio.com/\">Grafton Studio</a> | Boston, MA | Take-home project, discussion on-site</li>\n<li></li>\n<li><a href=\"http://www.gramercytech.com/\">Gramercy Tech</a> | New York, NY | Pair programming &#x26; discussion on-site</li>\n<li></li>\n<li><a href=\"https://www.grandcentrix.net/jobs\">grandcentrix</a> | Cologne, Germany | Take-home project, discussion on-site</li>\n<li></li>\n<li><a href=\"https://www.chatgrape.com/jobs/\">Grape</a> | Vienna, Austria / Remote | Github or code samples -> Pair</li>\n<li></li>\n<li><a href=\"https://www.graph.cool/\">Graphcool</a> | Berlin, Germany | On-site pair programming of a small, isolated real world task</li>\n<li></li>\n<li><a href=\"http://www.graphicacy.com/\">Graphicacy</a> | Washington, DC | Phone interview; in-person or virtual interview depending on locat</li>\n<li></li>\n<li><a href=\"https://www.graphistry.com/careers\">Graphistry</a> | Oakland, CA; San Francisco, CA; Remote | Engineering, culture, and product discussions, and for junior develop</li>\n<li></li>\n<li><a href=\"https://www.grok-interactive.com/\">Grok Interactive</a> | San Antonio, TX | Take-home project with code r</li>\n<li></li>\n<li><a href=\"http://www.gruntwork.io/\">Gruntwork</a> | Remote | Paid, take-home</li>\n<li></li>\n<li><a href=\"https://gtmsportswear.com/careers\">GTM Sportswear</a> | Manhattan, KS / Remote | Remote pairing session, then a ta</li>\n<li></li>\n<li><a href=\"https://happyteam.io/\">Happy Team</a> | Warsaw, Poland; Remote | General technical questions, takehome paid exercise with feedback/discussion during implementation</li>\n<li></li>\n<li><a href=\"http://www.happypie.com/\">Happypie</a> | Uppsala, Sweden | Takehome excercise with code review after, in-person int</li>\n<li></li>\n<li><a href=\"https://www.hash.com.br/index.html\">Hash</a> | Sao Paulo, Brazil | Take-home project and/or discussion (on-site or remote)</li>\n<li></li>\n<li><a href=\"https://hashrocket.com/\">Hashrocket</a> | Chicago, IL/Jacksonville Beach, FL | Remote pairing session,</li>\n<li></li>\n<li><a href=\"https://headspring.com/about/careers\">Headspring</a> | Austin, TX; Houston, TX; Monterrey, Mexico | Take-home situational questionnaire </li>\n<li></li>\n<li><a href=\"https://healthify.us/\">Healthify</a> | Remote &#x26; New York City, NY | Take-home project, discussion via Zoom, pair programmin</li>\n<li></li>\n<li><a href=\"https://www.heetch.com/\">Heetch</a> | Paris, France | Values-fit interview (via zoom.us), Take-home project with review, Team Discussions (via zoom.us), on-site day</li>\n<li></li>\n<li><a href=\"https://helabs.com/\">HE:labs</a> | Rio de Janeiro, Brazil &#x26; Remote | Take-home project and discussion via Skype.</li>\n<li></li>\n<li><a href=\"https://www.hellofresh.com/jobs\">HelloFresh</a> | Berlin, Germany | Take-home project, discussion via Skype or on-site</li>\n<li></li>\n<li><a href=\"https://www.heptio.com/jobs\">Heptio</a> | Seattle, WA; Remote | Take-home project, discussion on-site</li>\n<li><a href=\"http://www.hhcc.com/careers\">Hill Holliday</a> | Boston, MA | Take-home project on GitHub, in-person interview / culture fit interview</li>\n<li><a href=\"http://www.hireology.com/careers\">Hireology</a> | Chicago, IL; Remote | Walk through personal/work projects and discuss experience</li>\n<li><a href=\"https://www.hiventive.com/\">Hiventive</a> | Pessac, France | Phone interview, home coding challenge, on-site interview with general programming questions, discussion of proposed solutions and personal experience.</li>\n<li><a href=\"https://holidaypirates.group/en/jobs\">HolidayPirates</a> | Berlin, Germany | Take-home project, discussion via Skype or on-site</li>\n<li><a href=\"https://www.holobuilder.com/\">HoloBuilder</a> | Aachen, Germany | Take-home project, discussion via Skype or on-site</li>\n<li><a href=\"https://www.homechef.com/careers\">Home Chef</a> | Chicago, IL; Remote | Get-to-know-you meeting with the team, followed by a half-day collaborative coding session</li>\n<li><a href=\"https://www.homelight.com/engineering\">HomeLight</a> | San Francisco, CA; Scottsdale, AZ; Seattle, WA | Phone screen, take home that is close to production code, onsite with pair programming</li>\n<li><a href=\"https://jobs.hoxhunt.com/\">HoxHunt</a> | Helsinki, Finland | Take-home project, pair programming on-site</li>\n<li><a href=\"http://humanapi.co/company/careers\">Human API</a> | Redwood City, CA | Technical phone interview, then on-site pair programming and design discussion</li>\n<li><a href=\"https://io.co.za/opportunities\">I|O</a> | Cape Town, South Africa</li>\n<li><a href=\"http://icalialabs.com/\">Icalia Labs</a> | Monterrey, Mexico | Pair programming, cultural fit session</li>\n<li><a href=\"http://iconstituent.com/careers/\">iConstituent</a> | Washington, DC | Take-home project and code review in-person</li>\n<li><a href=\"https://ideamotive.co/\">Ideamotive</a> | Warsaw, Poland &#x26; Remote | Take-home project, technical interview with developer</li>\n<li><a href=\"https://www.ideo.com/jobs\">IDEO</a> | San Francisco, CA; New York, NY; Chicago, IL; Cambridge, MA | Take home project that resembles a problem IDEO solves for, then pairing session in person or over video chat.</li>\n<li><a href=\"https://boards.greenhouse.io/scout24\">ImmobilienScout24</a> | Berlin, Germany | Take-home project, discussion on-site</li>\n<li><a href=\"http://jobs.impraise.com/\">Impraise</a> | Amsterdam, The Netherlands | Take home test, real world pair programming</li>\n<li><a href=\"https://jobs.incloud.de/\">Incloud</a> | Darmstadt, Germany | Technical interview with developers, followed by a full day on site with a practical project</li>\n<li><a href=\"http://www.indellient.com/careers\">Indellient</a> | Oakville, Canada | Series of interviews both technical and non-technical</li>\n<li><a href=\"https://www.influxdata.com/careers\">InfluxData</a> | San Francisco, CA &#x26; Remote | Technical and non-technical interviews, pair programming, with prospective manager and multiple prospective teammates</li>\n<li><a href=\"https://www.infosum.com/\">InfoSum</a> | Basingstoke, UK | On-site unsupervised exercise &#x26; discussion.</li>\n<li><a href=\"https://inkindcapital.com/\">inKind Capital</a> | Boulder, CO | Discussing real-world problems, pair programming, dinner &#x26; drinks with the team</li>\n<li><a href=\"https://www.inmar.com/careers\">Inmar</a> | Winston-Salem, NC; Austin, TX &#x26; Remote | Take-home project and conversation-style interviews</li>\n<li><a href=\"https://www.innoplexus.com/careers/\">Innoplexus</a> | Pune, India; Frankfurt, Germany | Take-home projects and On-site pair programming assignment.</li>\n<li><a href=\"https://careers.instacart.com/\">Instacart</a> | San Francisco, CA | Take-home real world project, pair programming on-site</li>\n<li><a href=\"https://internshala.com/internships/internship-at-InstantPost\">InstantPost</a> | Bangaluru, India | Remote assignment followed by Technical and Team round interview</li>\n<li><a href=\"https://www.integral.io/\">Integral.</a> | Detroit, MI | Initial remote technical screen featuring test-driven development &#x26; pair programming, then on-site full day interview that involves pair programming on production code using test-driven development.</li>\n<li><a href=\"https://www.intelipost.com.br/\">Intelipost</a> | São Paulo, BR | Take-home project, on-site code review and presentation (skype available if needed), discussion involving real world problems and interviews with different teams</li>\n<li><a href=\"https://www.intercom.com/careers\">Intercom</a> | San Francisco, CA; Chicago, IL; Dublin, Ireland | Real-world technical design and problem discussion, pair programming on-site</li>\n<li><a href=\"https://interset.com/careers\">Interset</a> | Ottawa, Canada | Discussion of technical background and past experience. Relevant take-home project for junior developers</li>\n<li><a href=\"https://www.ithaka.travel/\">Ithaka</a> | Mumbai, India | Phone interview followed by a small development task. Finally a phone interview with CEO.</li>\n<li><a href=\"http://itrellis.com/\">iTrellis</a> | Seattle, WA | Phone screen, then a take-home project, then pairing (remote or on-site) with 3 developers on the take-home project.</li>\n<li><a href=\"https://jobs.izettle.com/jobs\">iZettle</a> | Stockholm, Sweden | Remote pair programming exercise, propose an architecture for an application and discuss about it in an informal format.</li>\n</ul>\n<h2>J - L</h2>\n<ul>\n<li><a href=\"http://www.jamasoftware.com/\">Jamasoftware</a> | Portland, OR | Initial phone screen with hiring manager. In person pairing on project similar to day-to-day work with a separate cultural interview</li>\n<li></li>\n<li><a href=\"https://jamitlabs.com/jobs\">Jamit Labs</a> | Karlsruhe, Germany | Phone interview or on-site interview &#x26; take-home</li>\n<li></li>\n<li><a href=\"https://www.jiminny.com/\">Jiminny</a> | Sofia, Bulgaria | Phone screen. Take-home exercise. Follow-up discussion.</li>\n<li></li>\n<li><a href=\"https://www.jitbit.com/\">Jitbit</a> | Remote; London, UK; Tel-Aviv, Israel | Take-home real-world task</li>\n<li></li>\n<li><a href=\"https://weare.jobtome.com/careers\">Jobtome</a> | Stabio, Switzerland | Phone screen introduction with hiring manager. In site (or screen call) with Engineer Manager for a talk on skills and cultural fit.</li>\n<li></li>\n<li><a href=\"https://journaltech.com/jobs\">Journal Tech</a> | Los Angeles, CA | Mini take-home project, phone interview, discussion on-site</li>\n<li></li>\n<li><a href=\"http://www.jplusplus.org/\">Journalism++</a> | Berlin, Germany | Apply through a <a href=\"http://internship.jplusplus.org/\">relevant online challenge</a> to show your technical skills and your capacity to investigate</li>\n<li></li>\n<li><a href=\"https://www.justwatch.com/us/talent\">JustWatch</a> | Berlin, Germany | Take-Home project, discussion on-site</li>\n<li></li>\n<li><a href=\"https://www.khealth.ai/\">K Health</a> | Tel Aviv, Israel | Phone screening to discuss technical background and past experience. Tak</li>\n<li></li>\n<li><a href=\"https://www.getkahoot.com/jobs\">Kahoot!</a> | London, UK / Oslo, Norway | Phone screening to discuss technical background and pa</li>\n<li></li>\n<li><a href=\"https://kata.ai/\">Kata.ai</a> | Malang, Indonesia / Jakarta, Indonesia | Take-home assignment, then invited to discuss the assignment and interview.</li>\n<li></li>\n<li><a href=\"https://www.kayako.com/\">Kayako</a> | London, UK / Gurgaon, India | Take-home assignment, series of experienc</li>\n<li></li>\n<li><a href=\"https://www.kentik.com/careers\">Kentik</a> | San Francisco, CA | Phone screening to discuss technical background and past experience. Take-home ass</li>\n<li></li>\n<li><a href=\"https://keymetrics.io/\">Keymetrics</a> | Paris, France | Phone Interview, Take-home project based on our <a href=\"https://github.com/keymetrics/keymetrics-api\">API</a>, IRL meeting with the whole team</li>\n<li></li>\n<li><a href=\"https://careers.kindredplc.com/\">Kindred Group, Native Apps Team</a> | Stockholm SE, London UK | On-site/Skype progra</li>\n<li></li>\n<li><a href=\"https://www.kinnek.com/jointeam\">Kinnek</a> | New York, NY | Phone screen, on-site pairing session, take-home project</li>\n<li></li>\n<li><a href=\"https://code.kiwi.com/\">Kiwi.com</a> | Brno, Czech Republic | Phone Interview, Take-home projects, On-site code review &#x26; interview</li>\n<li></li>\n<li><a href=\"https://knplabs.com/\">KNPLabs</a> | Nantes, France | First step: screening call directly with the CEO, to discuss company </li>\n<li></li>\n<li><a href=\"http://www.koddi.com/open-positions\">Koddi Inc.</a> | Fort Worth, TX | Phone Interview(s), take-home project, on-site i</li>\n<li></li>\n<li><a href=\"https://www.konghq.com/careers\">Kong</a> | San Francisco, CA | Phone interview. Pairing and technical interviews. </li>\n<li></li>\n<li><a href=\"http://www.kongregate.com/jobs\">Kongregate</a> | Portland, OR | Phone screening. Take home project. On-site pairing and conversational technical interviews.</li>\n<li></li>\n<li><a href=\"https://www.korbit.co.kr/about/jobs\">Korbit</a> | Seoul, South Korea | Take home assignment followed by on-site code review and i</li>\n<li></li>\n<li><a href=\"http://lab.coop/\">Lab.Coop</a> | Budapest, Hungary | Partnership-fit discussion, code-review and trial days.</li>\n<li></li>\n<li><a href=\"https://landing.jobs/at/landing-jobs\">Landing.jobs</a> | Lisbon, Portugal | Interviews (in-person or remote), Take home co</li>\n<li></li>\n<li><a href=\"http://engineering.lanetix.com/\">Lanetix</a> | San Francisco, CA | [Our Hiring Process](<a href=\"https://engineering.lanetix.com/201\">https://engineering.lanetix.com/201</a></li>\n<li></li>\n<li><a href=\"http://careers.laterooms.com/\">LateRooms</a> | Manchester, UK | Telephone interview followed by coding problem at home. Suitable submissions proceed to an onsite interview.</li>\n<li><a href=\"https://launchacademy.com/careers\">Launch Academy</a> | Boston, Philadelphia | Nontechnical phone screen, pair programming with team member, and potentially a \"guest lecture\" for our students</li>\n<li><a href=\"https://launchdarkly.com/careers\">LaunchDarkly</a> | Oakland, CA | Informational phone screen with Eng leadership, take home project, onsite interviews</li>\n<li><a href=\"https://learningbank.dk/\">Learningbank</a> | Copenhagen, DK | Take home assignment, followed by on-site code review.</li>\n<li><a href=\"https://www.legalstart.fr/\">Legalstart.fr</a> | Paris, France | Telephone interview followed by take-home challenges. Suitable applicants are asked to do further on-pair interviews on site.</li>\n<li><a href=\"https://www.leverton.ai/\">Leverton</a> | Berlin, Germany | Initial chat with the HR continued with 1-2 rounds chat with the team; followed by a technical test and finally a chat with the CTO/MD. <a href=\"http://leverton-jobs.personio.de/\">Jobs page</a></li>\n<li><a href=\"https://www.libertymutualgroup.com/careers\">Liberty Mutual</a> | Seattle, WA; Boston, MA; Indianapolis, IN | Initial interview, discussion on-site, interview with peers</li>\n<li><a href=\"https://www.librato.com/jobs\">Librato</a> | San Francisco, CA; Boston, MA; Austin, TX; Vancouver, Canada; Krakow, Poland | Take home coding project, conversational technical interviews on-site</li>\n<li><a href=\"http://lightningjar.agency/\">Lightning Jar</a> | San Antonio, Tx | Remote pairing session, Initial interview,discussion on-site</li>\n<li><a href=\"http://www.lightricks.com/\">Lightricks</a> | Jerusalem, Israel | Initial interview, Take home project, discussion on-site</li>\n<li><a href=\"http://jobs.linkresearchtools.com/job-offers\">LinkResearchTools</a> | Vienna, Austria | Skype interview, mini take-home exercise, discussion on-site / personal interview</li>\n<li><a href=\"https://listium.com/jobs\">Listium</a> | Melbourne, Australia | Design and code proof of concept features with the team</li>\n<li><a href=\"https://litmus.com/careers#openings\">Litmus</a> | Remote | General technical questions, take-home code challenge, discussion, on-site programming session, meet &#x26; greet with the team</li>\n<li><a href=\"https://www.littlethings.com/careers.html\">LittleThings</a> | New York, NY | Take home code challenge, Discussion</li>\n<li><a href=\"https://loanzen.in/team.html#Career\">LoanZen</a> | Bengaluru, India | Initial phone interview about experience, a solve-at-home project based on the kind of work we do at our company, on-site interview discussing the submitted solution and a general discussion with the whole team</li>\n<li><a href=\"https://lob.com/careers\">Lob</a> | San Francisco, CA | Initial phone screen followed by an on-site interview. Technical problems discussed during the interview are all simplified versions of problems we've had to solve in production. Our entire interview process and what we're looking for is described in our blog post <a href=\"https://lob.com/blog/how-we-interview-engineers\">How We Interview Engineers</a>.</li>\n<li><a href=\"https://www.locastic.com/posao\">Locastic</a> | Split, Croatia | Take-home code challenge, tehnical discussion &#x26; on-site programming session, meet &#x26; greet with the team</li>\n<li><a href=\"https://www.locaweb.com.br/carreira\">Locaweb</a> | São Paulo, Brazil | Skype interview, take-home project and discussion on-site</li>\n<li><a href=\"https://logiball.de/en/jobs/\">LOGIBALL GmbH</a> | Berlin, Hannover and Herne in Germany | Interviews and discussion</li>\n<li><a href=\"https://logicsoft.co.in/\">Logic Soft</a> | Chennai, India | Phone discussion, F2F pair programming exercise + discussion</li>\n<li><a href=\"https://www.lonres.com/public/working-us\">LonRes</a> | London, United Kingdom | Quick introduction call with tech (Skype), coding task for ≈1 hour, face-to-face interview (or via Skype) and meeting with team members.</li>\n<li><a href=\"http://www.lookbookhq.com/about/careers\">LookBookHQ</a> | Toronto, Canada | On-site discussion, pair programming exercise</li>\n<li><a href=\"https://www.useloom.com/careers\">Loom</a> | San Francisco, CA | Google Hangouts resume dive on past experience, take-home project OR architectural phone screen, on-site interviews (2 technical architecture related to work, 1 or 2 non-technical)</li>\n<li><a href=\"https://lydia-app.com/en/company/jobs\">Lydia</a> | Paris, FR | Mini take-home project, phone interview, discussion on-site</li>\n<li><a href=\"https://lyft.com/jobs\">Lyft</a> | San Francisco, CA | Pair programming on-site with your own personal laptop</li>\n<li><a href=\"http://www.lyoness-corporate.com/de-AT/Karriere/Jobangebote\">Lyoness Austria GmbH</a> | Graz, Austria | Take-Home project, discussion on-site</li>\n</ul>\n<h2>M - O</h2>\n<ul>\n<li><a href=\"https://www.madetech.com/careers\">Made Tech</a> | London, UK | <a href=\"https://github.com/madetech/handbook/tree/master/guides/hiring#20-minute-phone-conversation\">Our hiring process</a></li>\n<li></li>\n<li><a href=\"https://magnetis.workable.com/\">Magnetis</a> | São Paulo, Brazil &#x26; Remote | Phone interview + take home assignment, followed by pair programming and informal meeting with the team.</li>\n<li></li>\n<li><a href=\"https://careers-mlssoccer.icims.com/jobs/search?ss=1&#x26;searchCategory=20285\">Major League Soccer</a> | New York, NY |</li>\n<li></li>\n<li><a href=\"http://www.makemusic.com/careers/\">MakeMusic</a> | Boulder, CO; Denver, CO | Phone screen, take home project, remote and on-site interviews for technical and cultural fit</li>\n<li></li>\n<li><a href=\"https://maketime.workable.com/\">MakeTime</a> | Lexington, KY | Practical exercise and/or a pairing session on site</li>\n<li></li>\n<li><a href=\"http://www.mango-solutions.com/wp/about-mango/team\">Mango Solutions</a> | London (UK), Chippenham (UK) | Initial phone</li>\n<li></li>\n<li><a href=\"https://www.mapbox.com/jobs\">Mapbox</a> | San Francisco, CA; Washington, DC; Ayacucho, Peru; Bangalore, India; Berlin, Germany; Remote | Conversational interview</li>\n<li></li>\n<li><a href=\"https://www.mavenlink.com/careers\">Mavenlink</a> | San Francisco, CA; Irvine, CA; Salt Lake City, UT | On-site pairing with</li>\n<li></li>\n<li><a href=\"https://www.maxwellhealth.com/careers\">Maxwell Health</a> | Boston, MA | Take-home exercise or pairing session with team. Then conversational mee</li>\n<li></li>\n<li><a href=\"https://me-company.de/jobs/\">Me &#x26; Company</a> | Düsseldorf, Germany | You join us for one or two paid trial days to work on an assignment and to meet the team.</li>\n<li></li>\n<li><a href=\"https://mediapop.co/\">Media Pop</a> | Singapore, Singapore | Take-home or unsupervised (onsite) real-world assignment</li>\n<li></li>\n<li><a href=\"https://www.meetrics.com/\">Meetrics</a> | Berlin, Germany | Initial interview, take-home code challenge and review</li>\n<li></li>\n<li><a href=\"http://underthehood.meltwater.com/jobs\">Meltwater</a> | Manchester, NH | Small take home exercise that will be presented to the team during </li>\n<li></li>\n<li><a href=\"https://mention.workable.com/\">Mention</a> | Paris, FR | Take-home small exercise followed up by on site meetings with your future</li>\n<li></li>\n<li><a href=\"https://www.mercatus.com/company/careers\">Mercatus</a> | Toronto, Canada | Practical on-site project similar to dai</li>\n<li></li>\n<li><a href=\"https://www.mfind.pl/dolacz-do-nas/\">mfind</a> | Warsaw, PL | Phone call about technical experience, Take-home project or technical test(depends on experience), Onsite interview with technical lead.</li>\n<li></li>\n<li><a href=\"https://midrive.com/careers\">miDrive</a> | London, UK | Phone screen, Take-home project / technical test, Onsite interview with senior and peer.</li>\n<li></li>\n<li><a href=\"https://www.milchundzucker.de/\">milch &#x26; zucker</a> | Gießen, Germany | Interview with direct feedback, applicants providing working sample, code review (product code or personal code of applications)</li>\n<li></li>\n<li><a href=\"https://mimirhq.com/jobs/\">Mimir</a> | Indianapolis, Indiana | Take home interview, phone screen, in person interview where you decide how you wan</li>\n<li></li>\n<li><a href=\"http://www.minutemedia.com/careers/\">Minute Media</a> | Tel-Aviv, Israel | Phone screening with engineer. On-site r</li>\n<li></li>\n<li><a href=\"https://mirumee.com/jobs\">Mirumee</a> | Wroclaw, Poland; Remote | Pair programming and code review using one of the is</li>\n<li></li>\n<li><a href=\"https://mixmax.com/careers\">Mixmax</a> | San Francisco, CA | Takehome assignment purely based on their platform, followed by phone interview</li>\n<li></li>\n<li><a href=\"https://www.mobilecashout.com/\">MobileCashout</a> | Barcelona, Spain; Valencia, Spain | Quick introduction video call with a tech (less than 10-15 minutes). On-site open source contribution to a project of candidates choosing, paired with a tech from the team. Interview and a short questionaire about</li>\n<li></li>\n<li><a href=\"https://mobilethinking.ch/\">Mobilethinking</a> | Geneva, Switzerland | 1 hour discussion about technical b</li>\n<li></li>\n<li><a href=\"https://about.modeanalytics.com/careers\">Mode</a> | San Francisco, CA | Phone interview followed by onsite pair-architecting and discussion</li>\n<li></li>\n<li><a href=\"http://mokahr.com/\">MokaHR</a> | Beijing, China | Take home project/challenge, then on-site pr</li>\n<li></li>\n<li><a href=\"https://moneytree.jp/\">Moneytree Front-end Web Team</a> | Tokyo, Japan | Pair programming exercise and social ga</li>\n<li></li>\n<li><a href=\"https://monzo.com/\">Monzo</a> | London, UK &#x26; Remote | Phone interview with another engineer. Take-home assignment. Call to debrief on take-home assignment. Half-day interview (on-site or Hangouts) with three c</li>\n<li></li>\n<li><a href=\"https://www.moteefe.com/jobs\">Moteefe</a> | London, UK &#x26; Remote | Interview with CTO. Take</li>\n<li></li>\n<li><a href=\"https://mutualmobile.com/careers\">Mutual Mobile</a> | Austin, TX; Hyderabad, India | Technical discussion, code test based on actual work y</li>\n<li></li>\n<li><a href=\"http://www.mutualofomaha.com/careers\">Mutual of Omaha</a> | Omah</li>\n<li></li>\n<li><a href=\"https://www.mutuallyhuman.com/\">Mutually Human Software</a> | MI, OH, WA | Collaborative problem analysis and design exercise, pairing exercise</li>\n<li></li>\n<li><a href=\"https://nanobox.io/\">Nanobox</a> | Lehi, UT; Remote | A phone/video/person-to-person interview with a look at past projects (github, bitbucket, source code, etc.)</li>\n<li></li>\n<li><a href=\"https://www.native-instruments.com/\">Native Instruments</a> | Berlin, Germany | Takehome programming assignment and personal interviews with part of the hiring team.</li>\n<li></li>\n<li><a href=\"https://nearsoft.com/join-us/\">Nearsoft Inc</a> | Hermosillo, Mexico; Chihuahua, Mexico; Mexico City, Mexico | Takehome [logi</li>\n<li></li>\n<li><a href=\"http://lifeatnedap.com/vacatures\">Nedap</a> | Groenlo, Netherlands / Remote | A simple conversation, human</li>\n<li></li>\n<li><a href=\"https://neoteric.eu/career/\">Neoteric</a> | Gdańsk, Warsaw Poland; Remote | Face2</li>\n<li></li>\n<li><a href=\"https://jobs.netflix.com/jobs/867042\">Netflix</a> | Los Gatos, CA | Takehome exercise, series of r</li>\n<li></li>\n<li><a href=\"https://www.netguru.co/career\">Netguru</a> | Warsaw, Poland; Remote | Takehome exercise &#x26; pair programming session</li>\n<li></li>\n<li><a href=\"https://www.netlandish.com/\">Netlandish</a> | Los Angeles, CA; Remote | Takehome exercise, chat interview, video interview</li>\n<li></li>\n<li><a href=\"https://www.netlify.com/careers\">Netlify</a> | San Francisco, CA | Paid takehome project and online/onsite discussion</li>\n<li><a href=\"https://newrelic.com/about/careers\">New Relic</a> | San Francisco, CA | Takehome exercise &#x26;/ or pair programming session depending on the team</li>\n<li><a href=\"https://www.newstore.com/careers/\">NewStore</a> | Berlin, Germany; Hannover, Germany; Erfurt, Germany; Boston, MA | Telephone technical interview, code sample submission or takeaway coding exercise, on-site pair programming, design session (1/2 day)</li>\n<li><a href=\"https://www.newvoicemedia.com/about-newvoicemedia/careers\">NewVoiceMedia</a> | Basingstoke, England; Wroclaw, Poland | Telephone interview, takeaway coding exercise, on-site pair programming, code review &#x26; technical discussion (1/2 day)</li>\n<li><a href=\"https://nexcess.net/\">Nexcess.net</a> | Southfield, MI | We mostly chat to get a feel on both ends if there's a good cultural fit. We ask questions to see what experience you have and how you think as a programmer. At some point we look at some of your code or have you work on some of ours (1 hour).</li>\n<li><a href=\"https://www.workhiro.com/companies/nimbl3\">Nimbl3</a> | Bangkok, Thailand | Takehome exercise and specific role discussion</li>\n<li><a href=\"http://www.niteoweb.com/careers\">Niteoweb</a> | Ljubljana, Slovenia | Join us for a week to see if we fit</li>\n<li><a href=\"https://www.gonitro.com/about/jobs\">Nitro</a> | Dublin, Ireland; San Francisco, CA | Phone Call, Take Home Test, Hiring Manager Phone Interview followed by an onsite discussion</li>\n<li><a href=\"https://www.noa.one/\">Noa</a> | Berlin, Germany; San Francisco, CA | 1 technical chat, 2-3 cultural chats with colleagues from different departments in the team, if these work a pair programming exercise</li>\n<li><a href=\"http://nodesource.com/careers\">NodeSource</a> | Remote | A person-to-person walk through of a past project of yours</li>\n<li><a href=\"https://www.nomoko.world/jobs\">Nomoko,camera</a> | Zurich, Switzerland | Three interrogations</li>\n<li><a href=\"https://www.nordsoftware.com/en/jobs\">Nord Software</a> | Helsinki, Finland; Tampere, Finland; Stockholm, Sweden | Take-home exercise &#x26; interview with CEO and senior developer</li>\n<li><a href=\"https://www.noredink.com/jobs\">NoRedInk</a> | San Francisco, CA | Take-home exercise &#x26; pair programming session</li>\n<li><a href=\"https://novicap.com/en/careers.html\">NoviCap</a> | Barcelona, Spain | Takehome exercise &#x26; discussion on-site</li>\n<li><a href=\"https://novoda.com/hiring\">Novoda</a> | London, UK; Liverpool, UK; Berlin, Germany; Barcelona, Spain; Remote | 2 x Pairing sessions &#x26; conversational interviews <a href=\"https://github.com/novoda/dojos\">(public repo)</a></li>\n<li><a href=\"https://www.novus.com/jobs\">Novus Partners</a> | New York, NY | Take-home exercise &#x26; on-site exercises (choice of laptop or whiteboard)</li>\n<li><a href=\"https://nozbe.com/jobs\">Nozbe</a> | Remote | Take-home exercise &#x26; interview with the team</li>\n<li><a href=\"https://npmjs.com/jobs\">npm, Inc</a> | Oakland, CA / Remote | No technical challenges. Just interview conversations.</li>\n<li><a href=\"https://nubank.workable.com/\">Nubank</a> | São Paulo, BR | Phone conversation, take-home exercise, code walkthrough, on-site code pairing.</li>\n<li><a href=\"https://www.numberly.com/\">numberly</a> | Paris, France | Series of interviews, that go over technical background, past experiences and cultural knowledge</li>\n<li><a href=\"https://angel.co/numerai/jobs\">numer.ai</a> | San Francisco, CA</li>\n<li><a href=\"https://www.nutshell.com/jobs\">Nutshell</a> | Ann Arbor, MI, US | Email screen / take-home programming excercise (<a href=\"https://github.com/nutshellcrm/join-the-team\">public repo</a>)</li>\n<li><a href=\"https://www.nyon.nl/vacatures\">Nyon</a> | Amsterdam, The Netherlands | 1. Skype (or real life) interview 2. Take home exercise (3-4 hours) 3. Meet entire team and pair programming sessions</li>\n<li><a href=\"https://oreilly.com/jobs\">O'Reilly Media</a> | Sebastopol, CA; Boston, MA; Remote | Phone conversation, take-home exercise or pair programming session, team interview, all via Google Hangout</li>\n<li><a href=\"https://objectpartners.com/careers/\">Object Partners, Inc.</a> | Minneapolis, MN; Omaha, NE | Phone interview to gauge mutual interest, followed by a slightly more in-depth technical round-table interview</li>\n<li><a href=\"https://www.objectiveinc.com/careers\">Objective, Inc.</a> | Salt Lake City, UT | Take-home programming exercise, then onsite friendly chat with team</li>\n<li><a href=\"http://rejoins.octo.com/\">OCTO Technology</a> | Paris, France | HR interview to go over your experiences and cultural knowledge. Then more or less informal discussion with two future team members about architecture design, agile practices, take-home project, pair programming...</li>\n<li><a href=\"https://olist.com/\">Olist</a> | Curitiba, Brazil | Take-home project and remote or on-site interviews</li>\n<li><a href=\"https://www.omadahealth.com/jobs\">Omada Health</a> | San Francisco, CA | Take home exercise and/or pair programming session.</li>\n<li><a href=\"https://onfido.com/jobs\">Onfido</a> | London, UK; Lisbon, Portugal | Take-home exercise and on-site interview/discussion with potential team</li>\n<li><a href=\"https://ontame.io/\">Ontame.io</a> | Copenhagen, Denmark | Take home exercise and specific role discussion</li>\n<li><a href=\"https://opbeat.com/jobs#seniorbackendengineer\">Opbeat</a> | Copenhagen, Denmark | Pairing on a real-world problem</li>\n<li><a href=\"https://www.openmindonline.it/\">Openmind</a> | Monza, Italy | On-site interviews</li>\n<li><a href=\"http://www.optoro.com/open_position_item/?oid=134960\">Optoro</a> | Washington, DC | Take home exercise. Review your code onsite.</li>\n<li><a href=\"http://www.ostmodern.co.uk/\">Ostmodern</a> | London, UK | Take-home exercise &#x26; discussion on-site</li>\n<li><a href=\"https://www.outbrain.com/jobs\">Outbrain</a> | NYC, Israel | Take-home exercise &#x26; discussion</li>\n<li><a href=\"https://outlandish.com/\">Outlandish</a> | London, UK | Take-home exercise, real-world pair programming session, friendly chat with team</li>\n<li><a href=\"https://github.com/outlook/jobs\">Outlook iOS &#x26; Android</a> | San Francisco, CA / New York, NY | Take-home project &#x26; online / onsite discussion</li>\n<li><a href=\"https://www.nerdery.com/careers\">The Nerdery</a> | Minneapolis, MN; Chicago, IL; Phoenix, AZ; Kansas City, KS | Take-home exercise</li>\n<li><a href=\"https://boards.greenhouse.io/theoutline\">The Outline</a> | New York, NY | Take-home exercise</li>\n</ul>\n<h2>P - R</h2>\n<ul>\n<li><a href=\"https://www.pace.car/jobs\">PACE Telematics</a> | Karlsruhe, Germany | Culture and mindset check, on-site meet and great, small code challenge to see development style and strategy</li>\n<li></li>\n<li><a href=\"https://www.paessler.com/company/career/jobs\">Paessler AG</a> | Nuremberg, Germany | Pairing with different engineers on a real problem</li>\n<li></li>\n<li><a href=\"https://pagar.me/\">Pagar.me</a> | São Paulo, BR | Skype interview, on-site pairing task and-or real world problem solving process / presentat</li>\n<li></li>\n<li><a href=\"https://pager.com/\">Pager</a> | New York, NY; Remote | Short phone interview, conversational interviews, take-home exercise &#x26; discussion</li>\n<li></li>\n<li><a href=\"https://pagerduty.com/careers\">PagerDuty</a> | San Francisco, CA / Toronto, Canada / Atlanta, GA | Zoom</li>\n<li></li>\n<li><a href=\"https://tech.palatinategroup.com/\">Palatinate Tech</a> | London, UK | Hangout/Skype/phone followed by (normally) on-site pairing task</li>\n<li></li>\n<li><a href=\"http://parabol.co/\">Parabol</a> | New York, NY; Los Angeles, CA; Remote | Culture check followed by compensated, <a href=\"https://github.com/ParabolInc/action/projects\">open-source contribution</a> skills evaluation</li>\n<li></li>\n<li><a href=\"http://parivedasolutions.com/\">Pariveda Solutions</a> | Dallas, TX / Houston, TX / Atlana, GA </li>\n<li></li>\n<li><a href=\"https://passfort.com/about#jobs\">PassFort</a> | London, UK | Skype interview, and on-site pairing task</li>\n<li></li>\n<li><a href=\"https://paws.com/careers\">Paws</a> | London, UK | Phone screening, take-home project, on-site pairing/discussion on your solution and meet the team.</li>\n<li></li>\n<li><a href=\"https://paybase.io/\">Paybase</a> | London, UK | Phone screening, Take home project, On-site interview for technical and culture fit, Open Q&#x26;A session with team</li>\n<li></li>\n<li><a href=\"https://www.paybyphone.com/careers\">PayByPhone</a> | Vancouver, Canada | Remote programming interview, on-site \"meet the team\"</li>\n<li></li>\n<li><a href=\"https://peaksware.com/\">Peaksware Companies (TrainingPeaks, TrainHeroic, MakeMusic)</a> | Boulder, CO; Denver, CO | Phone screen, take home project, remote and on-si</li>\n<li></li>\n<li><a href=\"https://info.peerstreet.com/careers\">PeerStreet</a> | Los Angeles, CA | Phone, take home project &#x26; on-site to meet the team</li>\n<li></li>\n<li><a href=\"https://angel.co/pento/jobs\">Pento</a> | Remote | Quick personal interview, take ho</li>\n<li></li>\n<li><a href=\"https://www.persgroep.nl/werken-bij-it\">Persgroep, de</a> | Amsterdam, Netherlands | Tech interview (technical background and experienc</li>\n<li></li>\n<li><a href=\"https://angel.co/pexeso/jobs\">Pex</a> | Los Angeles, CA; Remote | 3 sessions: brief phone conversation (30 min); take home assignment</li>\n<li></li>\n<li><a href=\"https://www.phoodster.com/\">Phoodster</a> | Stockholm, Sweden | Take-home exercise + on-site discussion</li>\n<li></li>\n<li><a href=\"http://pillartechnology.com/careers\">Pillar Technology</a> | Ann Arbor, MI; Columbus, OH; Des Moines, IA | Phone, take home exercise, in-person pairing se</li>\n<li></li>\n<li><a href=\"https://pilot.co/become-a-partner\">Pilot</a> | Remote | Two calls. Introduction one (30m) + verification of communication skills and remote work experien</li>\n<li></li>\n<li><a href=\"https://pivotal.io/careers\">Pivotal</a> | San Francisco, CA; Los Angeles, CA; New York, NY; Boston, MA; Denver, CO; Atlanta, GA; Chicago, IL; Seattl</li>\n<li></li>\n<li><a href=\"https://platform.sh/\">Platform.sh</a> | Paris, International | Remote Interview, Wide-Ranging discussions on many diverse subjects. Remote interviews with team member</li>\n<li></li>\n<li><a href=\"https://platform45.com/\">Platform45</a> | Johannesburg, South Africa; Cape Town, South Africa | On-site interv</li>\n<li></li>\n<li><a href=\"https://getcatalyst.in/careers\">Playlyfe</a> | Bangalore, India | Short personal interview, on-site demonstration of programming in browser devtools followed by discussion about the problem</li>\n<li></li>\n<li><a href=\"https://www.pluralsight.com/careers\">Pluralsight</a> | Salt Lake City, UT; San Francisco, CA; Boston, MA; Orlando, FL | Takehome exercise &#x26; pair programming session</li>\n<li></li>\n<li><a href=\"http://pointman.bamboohr.com/jobs/\">Pointman</a> | Buffalo, NY | Takehome exercise + on-site discussion</li>\n<li></li>\n<li><a href=\"http://jobs.poki.com/\">Poki</a> | Amsterdam, The Netherlands | Pair programming on-site w/ two engineers where we focus on teamwork, googling relevant documentation and fixing things together.</li>\n<li></li>\n<li><a href=\"http://polar.me/company/careers\">Polar</a> | Toronto, Canada | Phone interview, followed by 1-2 onsite pair-programming interviews based on thei</li>\n<li></li>\n<li><a href=\"http://www.popstand.com/\">Popstand</a> | Los Angeles, CA | Build MVPs for startups</li>\n<li></li>\n<li><a href=\"http://www.popularpays.com/\">Popular Pays</a> | Chicago, IL | Phone chat/coffee to determine what will be worked </li>\n<li></li>\n<li><a href=\"https://pragma.team/talent\">Pragmateam</a> | Sydney, Australia | Engineering Consultancy And Delivery - Takehome exerc</li>\n<li></li>\n<li><a href=\"https://www.premiumbeat.com/careers\">PremiumBeat</a> | Montreal, Canada | Discussion and general, high level ques</li>\n<li></li>\n<li><a href=\"https://www.primary.com/jobs\">Primary</a> | New York, NY / Remote | Phone chat, take home exercise, pair prog</li>\n<li></li>\n<li><a href=\"https://www.promptworks.com/jobs\">PromptWorks</a> | Philadelphia, PA | Take-home project, pair programming, discussion on-site</li>\n<li><a href=\"https://pusher.com/jobs\">Pusher</a> | London, UK | Solve a real-world problem through a design session with our engineers</li>\n<li><a href=\"http://pygmalios.com/en\">Pygmalios</a> | Bratislava, Slovakia | Take-home project related to business and discussion with our engineers.</li>\n<li><a href=\"https://quietlightcom.com/positions-web.php\">Quiet Light Communications</a> | Rockford, IL, USA | Discussion, work samples and/or small freelance project</li>\n<li><a href=\"http://www.workatquintype.com/\">Quintype</a> | Bengaluru, India / San Mateo, USA | Take home project, pair programming, discussion on-site</li>\n<li><a href=\"https://quizizz.com/\">Quizizz</a> | Bengaluru, India | Phone chat, real world assignment, discussion w/ developers, pair programming, discussion on-site</li>\n<li><a href=\"https://ragnarson.com/\">Ragnarson</a> | Lodz, Poland; Remote | Take-home exercise &#x26; pair programming session</li>\n<li><a href=\"https://www.railslove.com/\">Railslove</a> | Cologne, Germany | Have a coffee in our office, casual chat with us, pair programming on a real project</li>\n<li><a href=\"https://www.raisingit.com/\">Raising IT</a> | London, UK | Coffee with a team member, on-site pair programming and discussion</li>\n<li><a href=\"https://jobs.rakuten.careers/careersection/rakuten_ext_cs/jobdetail.ftl?job=00000751&#x26;tz=GMT%2B09%3A00\">Rakuten</a> | Tokyo, Japan | Discuss about relevant experience</li>\n<li><a href=\"http://www.rapyuta-robotics.com/pages/jobs.html\">Rapyuta Robotics</a> | Bengaluru, India / Tokyo, Japan / Zurich, Switzerland | Take-home assignment related to our ongoing projects, series of technical / experience based interviews, candidate presentation</li>\n<li><a href=\"https://rayfeed.com/\">Rayfeed</a> | Vancouver, Warsaw | Video-call interview followed by a take-home exercise</li>\n<li><a href=\"https://razorpay.com/jobs\">Razorpay</a> | Bangalore, India | Phone screen, On-site pair programming, and ocassionally a take home project.</li>\n<li><a href=\"https://reactiveops.com/careers\">ReactiveOps</a> | Remote | Start with a brief talk with CTO or VP of Engineering, take home coding challenge, then remote interviews with several people on the engineering team</li>\n<li><a href=\"https://reaktor.com/careers\">Reaktor</a> | New York, NY; Amsterdam, Netherlands; Helsinki, Finland; Tokyo, Japan | Discussion, work samples from previous projects (work or hobby), take-home exercise if needed for further info</li>\n<li><a href=\"https://realhq.com/jobs\">Real HQ</a> | Austin, TX / Chicago, IL / Remote | Phone/video interviews, a take-home coding exercise, and a remote pair programming session.</li>\n<li><a href=\"https://realync.com/careers\">Realync</a> | Chicago, IL / Carmel, IN / Remote | Quick phone interview, then a take home project and finally in person interview (open discussions instead of quizzes - anything technical are real-world problems).</li>\n<li><a href=\"https://red-badger.com/about-us/join-us\">Red Badger</a> | London, UK | Phone &#x26; Skype interview, take home exercise, On-site interview</li>\n<li><a href=\"https://www.redcarpetup.com/jobs\">RedCarpet</a> | New Delhi, India | Interview, work sample/take-home project and discussion/code reviews</li>\n<li><a href=\"https://www.reflektive.com/careers/\">Reflektive</a> | San Francisco, CA; Bengaluru, India | A short take home project/assignment, followed by a couple of technical and non-technical discussions online and offline.</li>\n<li><a href=\"https://relabe.com/\">Relabe</a> | San Juan, PR | First we screen for cultural fit then check for technical proficiency. 2-3 Interviews max in SJ</li>\n<li><a href=\"https://www.rentify.com/jobs\">Rentify</a> | London, UK | Phone call, take home real-world project, on-site pair programming, product discussion</li>\n<li><a href=\"https://www.rentomojo.com/about/careers\">RentoMojo</a> | Bangalore, India | Short takehome project + phone interview</li>\n<li><a href=\"https://resin.io/\">Resin.io</a> | Remote | Take home real-world project and a couple of technical and non-technical discussions</li>\n<li><a href=\"https://www.respark.co.uk/\">ReSpark</a> | London, UK | Phone conversation followed by on-site interview w/ task relevant to daily role.</li>\n<li><a href=\"https://www.restaurantops.co/\">RestaurantOps</a> | Scottsdale, AZ | Take Home Project &#x26; pair programming session</li>\n<li><a href=\"https://revlv.net/\">Revlv</a> | Manila, Philippines | Discussion about developer skills, previous projects and experiences.</li>\n<li><a href=\"https://www.rexsoftware.com/careers\">Rex Software</a> | Brisbane, Australia | Take home project, feedback + interview</li>\n<li><a href=\"https://rizk.com/\">Rizk.com</a> | Ta' Xbiex, Malta | Take-home assignment, discussion w/ developers</li>\n<li><a href=\"http://www.rockode.com/\">Rockode</a> | Bangalore, India | Real world assignment, group hack session, discussions</li>\n<li><a href=\"http://rosedigital.co/\">Rose Digital</a> | New York, NY | Phone conversation followed by pair coding components that mirror day to day work, in person discussion about code, take home project if needed for more info</li>\n<li><a href=\"https://rubygarage.org/\">RubyGarage</a> | Dnipro, UA | Take-home project, code review and discussion on-site</li>\n<li><a href=\"https://www.runtastic.com/\">Runtastic</a> | Linz, Austria; Vienna, Austria | Video call with recruiting staff, take home project, video call for code review, discussion, questions</li>\n</ul>\n<h2>S - U</h2>\n<ul>\n<li><a href=\"https://www.sahajsoft.com/\">Sahaj Software Solutions</a> | Bangalore, India; Chennai, India; San Jose, CA | Take home code + Pairing + Discussion</li>\n<li></li>\n<li><a href=\"http://www.salesforce.org/\">Salesforce.org Tech &#x26; Products</a> | Remote | Phone screen, hands-on programming test solving real-world problems, Google Hangouts video sessions wit</li>\n<li></li>\n<li><a href=\"https://salesloft.com/\">Salesloft</a> | Atlanta, GA | Phone interview, take-home project, cultural-fit interview, technical interview where candidate modifies take-home project</li>\n<li></li>\n<li><a href=\"https://www.samsara.com/jobs\">Samsara</a> | San Francisco, CA; Atlanta, GA; London, UK | Phone interview, onsite interview (technical challenges based on real problems we've faced at Sams</li>\n<li></li>\n<li><a href=\"https://sc5.io/careers\">SC5 Online</a> | Helsinki, Finland; Jyväskylä, Finland | Take-home assignment (intentionally short, takes at most an hour to complete), discussion and review assignments</li>\n<li></li>\n<li><a href=\"https://segment.com/\">Segment</a> | San Francisco, CA; Vancouver, Canada | Phone interview, take-home assignment (small fun project),</li>\n<li></li>\n<li><a href=\"https://sensortower.com/jobs\">Sensor Tower</a> | San Francisco, CA | Phone call, on-site interview including discussion about projects/skills and a short real-worl</li>\n<li></li>\n<li><a href=\"https://sensu.io/\">Sensu</a> | Remote | Video call, choice of pairing session or take home programming assignment</li>\n<li></li>\n<li><a href=\"http://sentisis.com/trabaja-con-nosotros\">Séntisis</a> | Madrid, Spain; Mexico City, Mexico; Bogotá, Colombia; Santiago de Chile, Chile; Remote | Phone call, on-site/remote</li>\n<li></li>\n<li><a href=\"https://serpapi.com/\">SerpApi</a> | Austin, TX / Remote | Skype core value and culture interview, review of contr</li>\n<li></li>\n<li><a href=\"https://sertiscorp.com/\">Sertis</a> | Bangkok, Thailand | Technical &#x26; culture fit interview, take-home project, follow-up discussion</li>\n<li></li>\n<li><a href=\"https://setapp.pl/career\">Setapp Sp. z o.o.</a> | Poznan, Poland | Online/face-to-face discussion with developers about everyday programming dilemmas &#x26; reviewing your own code</li>\n<li></li>\n<li><a href=\"https://www.sharoo.com/jobs/\">Sharoo</a> | Zurich, Switzerland; Remote | Soft skills interview, take home project, technical interview based on take home project.</li>\n<li></li>\n<li><a href=\"https://getshogun.com/\">Shogun</a> | Remote | Discussion about software development and past experience, code samples, paid trial period.</li>\n<li></li>\n<li><a href=\"https://blog.showmax.com/engineering-careers\">Showmax</a> | Beroun, Czechia; Prague, Czechia; Remote | Take home project, then a pair-programming and discussion onsite / Hangouts round.</li>\n<li></li>\n<li><a href=\"https://shuttlecloud.com/jobs\">ShuttleCloud</a> | Chicago, IL / Madrid, Spain | Take-home project, then on-site code walk through and a real world problem discussion.</li>\n<li></li>\n<li><a href=\"https://www.signal-ai.com/about-us/careers\">Signal AI</a> | London, UK | Phone screen; take home code exercise; on-site code extension with pair programming and discussion</li>\n<li></li>\n<li><a href=\"https://www.simple.com/\">Simple</a> | Portland, OR | Discussion about software development and archite</li>\n<li></li>\n<li><a href=\"https://www.simpli.fi/about-us/careers\">Simpli.fi</a> | Fort Worth, TX, USA | Takehome code challenge and review</li>\n<li></li>\n<li><a href=\"http://www.welcometothejungle.co/companies/simplifield/jobs\">SimpliField</a> | Lille, France | Interview with the C</li>\n<li></li>\n<li><a href=\"https://www.simplybusiness.co.uk/about-us/careers/tech\">Simply Business</a> | London, UK / Remote | Three sta</li>\n<li></li>\n<li><a href=\"https://www.skyrisepro.com/\">Skyrise Pro</a> | Chicago, IL | Take-home coding project, on-site interview including coding enhancements to the take-home project, offsite group activity</li>\n<li></li>\n<li><a href=\"https://slack.com/jobs\">Slack</a> | San Francisco, CA | Call with recruiter, 1 week take-home project, call with hiring manager, on-site interview co</li>\n<li></li>\n<li><a href=\"https://www.small-improvements.com/careers\">Small Improvements</a> | Berlin, Germany</li>\n<li></li>\n<li><a href=\"http://www.socialtables.com/\">Social Tables</a> | Washington, DC | Chat about skills and past experiences + bring in a </li>\n<li></li>\n<li><a href=\"http://www.socialcops.com/\">SocialCops</a> | New Delhi, India | A mini project (to be done within 8 days), followed by a discussion with the team you're applying to. T</li>\n<li></li>\n<li><a href=\"http://nl.softwear.nl/vacatures\">Softwear</a> | Amsterdam, Netherlands | Writing software for the fashion industry - remot</li>\n<li></li>\n<li><a href=\"http://sogilis.com/\">Sogilis</a> | Grenoble, France | Discussion about interests, </li>\n<li></li>\n<li><a href=\"https://about.sourcegraph.com/jobs\">Sourcegraph</a> | San Francisco, CA &#x26; Remote | Tailored to the candidate, often consists of take-home</li>\n<li></li>\n<li><a href=\"https://jobs.splice.com/\">Splice</a> | New York, NY; Remote | Call with recruiter, 4 hr take-home project, video interview w two en</li>\n<li></li>\n<li><a href=\"https://www.spreedly.com/jobs\">Spreedly</a> | Durham, NC | Take-home project <a href=\"https://engineering.spreedly.com/blog/programming-puzzles-are-not-the-answer-how-spreedly-does-work-samples.html\">related to business</a></li>\n<li></li>\n<li><a href=\"https://www.natureasia.com/\">Springer Nature (Asia)</a> | Tokyo, Japan | Discussion &#x26; Pair programming session</li>\n<li></li>\n<li><a href=\"https://sndigital.springernature.com/\">Springer Nature Digital</a> | Berlin, Germany; London, UK | Phone chat; take-home proje</li>\n<li></li>\n<li><a href=\"https://www.spronq.nl/\">SpronQ</a> | Amsterdam, Netherlands | Takehome coding challenge</li>\n<li></li>\n<li><a href=\"https://squareup.com/careers\">Square</a> | San Francisco, CA | Pair programming in a work environment</li>\n<li></li>\n<li><a href=\"http://srijan.net/\">Srijan Technologies</a> | Delhi, India | General high level questions/discussion followed by Pair prog</li>\n<li></li>\n<li><a href=\"http://stardog.com/\">Stardog Union</a> | Washington, DC; Remote | Technical discussion and general interest conversations</li>\n<li></li>\n<li><a href=\"http://statflo.com/\">Statflo</a> | Toronto, Canada | Phone screening, take home project, on-sit</li>\n<li></li>\n<li><a href=\"https://www.store2be.com/de/jobs/tech\">store2be</a> | Berlin, Germany | Skype/on-site interview, take-home project</li>\n<li></li>\n<li><a href=\"https://www.stormx.io/about#jobs\">Storm</a> | Seattle, WA; Remote | Phone/skype screen --> Take-home coding assignment --> on-site/skype interview loop to discuss assignment; meet-and</li>\n<li></li>\n<li><a href=\"http://www.stylabs.in/\">STYLABS</a> | Mumbai, India | Phone Screen, Take-home project and discussion on-site</li>\n<li></li>\n<li><a href=\"https://verticalchange.com/job_posts\">Subvertical (VerticalChange)</a> | Remote | Phone screening, live pair programming &#x26; personal project code </li>\n<li></li>\n<li><a href=\"https://sulvo.com/careers\">Sulvo</a> | New York, NY / Remote | Interview over video call for cultural fit first, if you pass we proceed with technical interview that doesn't include coding games or challenges</li>\n<li></li>\n<li><a href=\"https://superplayer.fm/\">Superplayer</a> | Porto Alegre, Brazil | Skype/On-site interview, take-home pro</li>\n<li></li>\n<li><a href=\"https://surveysparrow.com/careers\">SurveySparrow</a> | Kochi, India | Skype interview, take home project and code review,</li>\n<li></li>\n<li><a href=\"http://svti.svt.se/\">SVTi (Sveriges Television)</a> | Stockholm, Sweden | On-site interview, take-home project, follow up interview where you walk through how you</li>\n<li></li>\n<li><a href=\"https://sweetiq.com/about/careers\">SweetIQ</a> | Montreal, Canada | Discussion and general, high level questions</li>\n<li></li>\n<li><a href=\"https://www.symphonycommerce.com/careers\">Symphony Commerce</a> | San Francisco, CA / Remote | Take-home project (phone), design discussion, review and criti</li>\n<li></li>\n<li><a href=\"https://www.symplicity.com/about/join-us\">Symplicity</a> | Arlington, VA | Take-home project and code review in-person</li>\n<li></li>\n<li><a href=\"http://sysgarage.com/\">SysGarage</a> | Buenos Aires, Argentina | Take-home project and real world pair programming</li>\n<li><a href=\"https://corp.tablecheck.com/en/jobs\">TableCheck</a> | Tokyo, Japan | Show us your code! Brief Skype interview and take-home project or pairing for those without code.</li>\n<li><a href=\"https://tailorbrands.com/jobs\">Tailor Brands</a> | Tel Aviv-Yafo, Israel | Discuss knowledge and interests, explore previous work experience, during the technical interview we discuss real-life problems.</li>\n<li><a href=\"https://tails.com/careers\">tails.com</a> | Richmond (London), UK | Live pair programming or take home project with review</li>\n<li><a href=\"http://tanookilabs.com/\">Tanooki Labs</a> | New York, NY | Paid half-day take home project with followup review and discussion</li>\n<li><a href=\"https://www.tattoodo.com/\">Tattoodo</a> | Copenhagen, Denmark | Takehome exercise</li>\n<li><a href=\"https://labs.telus.com/\">Telus Digital</a> | Toronto, Canada; Vancouver, Canada | Discuss knowledge and interest, explore previous work, pair with developers when possible, alternatively take home project.</li>\n<li><a href=\"https://tenthousandcoffees.com/\">Ten Thousand Coffees</a> | Toronto, Canada | Take home project, then explain how you solved the project</li>\n<li><a href=\"https://engineering.tes.com/recruitment/\">Tes</a> | Remote; London, UK | Remote pair programming session on React/Node kata with small takehome exercise as prep. Remote interview with senior engineers about previous experience, technical knowledge and interests.</li>\n<li><a href=\"https://www.tesco.com/\">Tesco PLC</a> | London, United Kingdom | Pair programming and casual hypothetical system design discussion</li>\n<li><a href=\"https://testdouble.com/join/developer\">Test Double</a> | Remote | Initial conversation, Consulting interview, Technical interview, Pair programming, Takehome exercise.</li>\n<li><a href=\"https://textio.com/careers/?utm_source=github&#x26;utm_medium=forum&#x26;utm_campaign=textio-careers-engineering&#x26;utm_content=poteto-hiring-without-whiteboards\">Textio</a> | Seattle, WA | Initial screen to discuss experience and interest in a role at Textio; then a take-home programming task is discussed during a 1-hour tech screen (on-site or remote); finally a larger take-home project, simulating real work, is discussed during an on-site presentation plus 1-1s; <a href=\"https://textio.ai/how-we-hire-a74cdbadd1e8\">How we hire</a></li>\n<li><a href=\"https://thebookofeveryone.workable.com/\">The Book of Everyone</a> | Barcelona, Spain | Quick interview, meet the team, pairing with developers on your own project</li>\n<li><a href=\"http://mobile.thescore.com/careers\">theScore</a> | Toronto, Canada | Coding challenge &#x26; systems design challenge</li>\n<li><a href=\"https://www.thinkmill.com.au/\">Thinkmill</a> | Sydney, Australia | Initial meet and greet interview with Thinkmillers from the relevant team, take home assignment followed by tech review on a followup interview.</li>\n<li><a href=\"http://www.thinslices.com/\">Thinslices</a> | Iasi, Romania | Takehome exercise &#x26; in person pair programming on a simple Kata.</li>\n<li><a href=\"https://thoughtbot.com/jobs\">thoughtbot</a> | San Francisco, CA; London, UK | <a href=\"https://thoughtbot.com/playbook/our-company/hiring#interviewing\">Our interview process</a></li>\n<li><a href=\"https://www.thoughtworks.com/careers\">ThoughtWorks</a> | San Francisco, CA | Interviews with ThoughtWorkers of diverse backgrounds and roles; take home assignment followed by in person pairing session.</li>\n<li><a href=\"https://www.thread.com/jobs\">Thread</a> | London, UK | Take home test, real world architecture design, real world pair programming.</li>\n<li><a href=\"https://www.threatspike.com/\">ThreatSpike Labs</a> | London, UK | Take home computing and security related challenges to be completed over a week.</li>\n<li><a href=\"http://www.tilde.io/\">Tilde</a> | Portland, OR | Pair programming sessions with each member of the team, working on problems similar to daily work.</li>\n<li><a href=\"https://www.timbuktutravel.com/\">Timbuktu</a> | Cape Town, South Africa | On site interview and pair programming exercise</li>\n<li><a href=\"https://titanium.codes/\">Titanium</a> | Moldova, Chisinau | High level review of public activity on GitHub/BitBucket/Gitlab (if applicable) and screening via phone, On-site technical &#x26; Team fit interview, Formal \"Meet the Team\" meeting</li>\n<li><a href=\"https://toggl.com/jobs\">Toggl</a> | Remote / Tallinn, Estonia | Online test on basic programming skills, followed by interview (typically includes get-to-know questions and technical skill testing). Depending on the team, there may be a take-home or live coding assignment. <strong>Paid test week</strong> to work with the team on actual bugs/features.</li>\n<li><a href=\"https://jobs.jointorii.co/\">Torii</a> | Raanana, Israel | Take-home fun full-stack-app exercise followed by an on-site review</li>\n<li><a href=\"http://toucantoco.com/fr/team#jobs\">Toucan Toco</a> | Paris, France | Pair-programming and TDD</li>\n<li><a href=\"https://gotouche.com/\">Touché</a> | Singapore, Singapore; Barcelona, Spain | Skype / Phone / on-site interview, take-home project, technical interview to discuss the project, team interview.</li>\n<li><a href=\"https://trademark.vision/\">TrademarkVision</a> | Brisbane, Australia | On site interview and quick take-home excercise</li>\n<li><a href=\"http://trainheroic.com/careers/\">TrainHeroic</a> | Boulder, CO; Denver, CO | Phone screen, take home project, remote and on-site interviews for technical and cultural fit</li>\n<li><a href=\"http://www.trainingpeaks.com/careers.html\">TrainingPeaks</a> | Boulder, CO; Denver, CO | Phone screen, take home project, remote and on-site interviews for technical and cultural fit</li>\n<li><a href=\"http://www.tripstack.com/company/careers/\">TripStack</a> | Toronto, Canada | Take-home assignment, followed up by a face to face code walk through</li>\n<li><a href=\"https://www.trivago.com/\">Trivago</a> | Düsseldorf, Germany | Case Study, Skype Interview, On site Interview with some code review exercises</li>\n<li><a href=\"https://boards.greenhouse.io/trov\">Trōv</a> | Remote | Take-home project with followup interview from actual prospective teammates</li>\n<li><a href=\"https://truefit.io/about/\">Truefit</a> | Pittsburgh, PA | Phone screen, Take-home project, In-person interview with the team that you would join</li>\n<li><a href=\"https://truora.com/\">Truora</a> | Bogotá, Colombia; Cali, Colombia; Remote | Take-home project, followed by phone interview with tech leads to discuss the project.</li>\n<li><a href=\"https://truss.works/jobs\">Truss</a> | San Francisco, CA; Remote | Phone screen/ Take-home project that resembles a problem Truss has seen many times before / Followup interview about the project / Closing Interview, all interviews done remotely</li>\n<li><a href=\"https://www.twistlock.com/\">Twistlock</a> | Tel Aviv, Israel | Takehome</li>\n<li><a href=\"https://uberall.com/en/careers\">uberall</a> | Berlin, Germany | 30-min coding on-site, then a trial day</li>\n<li><a href=\"https://ubiome.com/careers\">uBiome</a> | San Francisco, CA / Santiago, Chile | High level screening over the phone or on-site, take home project, code review and discussion</li>\n<li><a href=\"http://ubots.com.br/\">Ubots</a> | Porto Alegre, Brazil | Skype/On-site interview, take-home project, technical interview</li>\n<li><a href=\"https://unbounce.com/\">Unbounce</a> | Vancouver, BC | Phone screen, take-home project, project discussion, technical interview</li>\n<li><a href=\"https://unboxed.co/\">Unboxed</a> | London, UK | Take home feature requests, pairing with developers to extend solution, team-fit interviews, chat with a director</li>\n<li><a href=\"http://www.unearthlabs.com/careers\">Unearth</a> | Seattle, WA | Take home project, team-fit interviews, technical discussion</li>\n<li><a href=\"https://unito.io/careers/\">Unito</a> | Montreal, Canada | Team-fit interviews, technical discussion, take home project</li>\n<li><a href=\"https://www.untappd.com/\">Untappd</a> | Wilmington, NC; New York, NY; Los Angeles, CA | Review portfolio - What projects have you worked on? + personality assessment, + interview</li>\n<li><a href=\"http://www.updater.com/jobs/openings\">Updater</a> | New York, NY | Begin-at-home assignment highly relevant to role, presented and discussed during on-site.</li>\n<li><a href=\"http://uprise.se/\">Uprise</a> | Uppsala, Sweden | Take-home assignment, code review and discussion on-site</li>\n<li><a href=\"https://www.urbanmassage.com/jobs\">Urban Massage</a> | London, UK | Project done at home, in-person walk through. Meeting the team is an integral part.</li>\n<li><a href=\"https://www.usertesting.com/about-us/jobs\">UserTesting</a> | Atlanta, GA; San Francisco, CA; Mountain View, CA | Initial interview, pair programming, and offer</li>\n<li><a href=\"https://www.uswitch.com/vacancies\">uSwitch</a> | London, UK | Take-home project related to our business area, followed by pairing with developers to extend it</li>\n</ul>\n<h2>V - X</h2>\n<ul>\n<li><a href=\"http://www.valassis.com/digital-advertising\">Valassis Digital</a> | Seattle, WA; San Francisco, CA; Lansing, MI; Hamburg, Germany | Phone screen, on-site interview with group, paired whiteboard problem solving and discussion, take-home project and follow-up review</li>\n<li></li>\n<li><a href=\"https://valuemotive.com/en/career\">Valuemotive</a> | Helsinki, Finland | Code examples from previous projects (work or hobby) or take-home exercise</li>\n<li></li>\n<li><a href=\"https://www.varsitytutors.com/\">Varsity Tutors</a> | Remote | Take home assignment, presentation of assignment, live code review with team. Advanced / high-level chat with team based on skillset and role.</li>\n<li></li>\n<li><a href=\"http://vayu.com.au/\">Vayu Technology</a> | Sydney, Australia; Kathmandu, Nepal | Short interview, general programming questions and short take home challenge.</li>\n<li></li>\n<li><a href=\"https://www.venminder.com/\">Venminder, Inc.</a> | Elizabethtown, KY; Louisville, KY | Initial phone screen to explain position. If candida</li>\n<li></li>\n<li><a href=\"https://verve.co/careers\">Verve</a> | London, UK | An intentionally short, take home exercise that mirrors real project work and incorporates code</li>\n<li></li>\n<li><a href=\"https://careers.vingle.net/\">Vingle</a> | Seoul, Korea | Written interview, takehome project, in-person, conversational code review and interviews with e</li>\n<li></li>\n<li><a href=\"http://virtual7.de/de/karriere\">virtual7</a> | Kalrsruhe, Germany | Phone interview and on-site interview based on personal experience.</li>\n<li></li>\n<li><a href=\"https://www.e-conomic.dk/om/job\">Visma e-conomic</a> | Copenhagen, Denmark | Take home assignment, assignment presentatio</li>\n<li></li>\n<li><a href=\"https://voltra.co/\">Voltra Co.</a> | Amsterdam, Netherlands / New York, NY / Remote | Show us your github account, tell us what you know. Let's pair on an OSS PR!</li>\n<li></li>\n<li><a href=\"https://https//vsx.net/jobs\">VSX</a> | Dresden, Germany | On-site interview, home coding challenge, presentation/discussion o</li>\n<li></li>\n<li><a href=\"http://lab.vtex.com/careers\">VTEX</a> | Rio de Janeiro, Brazil | Take-home project, Skype interview and then in-person talk.</li>\n<li></li>\n<li><a href=\"https://buildingvts.com/\">VTS</a> | New York City, New York | Technical Phone Screen, Pair programming on-</li>\n<li></li>\n<li><a href=\"https://waymark.com/jobs\">Waymark</a> | Detroit, MI | Technical phone screen, take-home project, going over the project in person, follow up day in the office</li>\n<li></li>\n<li><a href=\"https://www.wealthsimple.com/work-with-us\">Wealthsimple</a> | Toronto, Canada | Pair programming on a</li>\n<li></li>\n<li><a href=\"http://www.wearehive.co.uk/\">WeAreHive</a> | London, UK | Just walk us through your best code or we give you a small real-world exercise to do at home.</li>\n<li><a href=\"https://webantic.co.uk/careers\">Webantic</a> | Manchester, UK | Basic TNA self-assessment and real-world problem-solving</li>\n<li><a href=\"https://webflow.com/\">Webflow</a> | San Francisco, CA &#x26; Remote | Short take-home challenge, followed by a paid 3-5 day freelance contract project</li>\n<li><a href=\"http://careers.weebly.com/\">Weebly</a> | San Francisco, CA; Scottsdale, AZ; New York, NY | Phone screens (30 min to 1 hour) by a recruiter, an engineering manager (focused on your past experiences), an engineer (focused on system / db / api design). Followed by a paid 3 day onsite where you work on a project and then present it to a team of engineers.</li>\n<li><a href=\"https://weedmaps.com/careers\">Weedmaps</a> | Irvine, CA; Denver, CO; Tucson, AZ; Madrid, Spain; Remote | Phone screen, Group interview, and possible code review</li>\n<li><a href=\"https://wemake.services/\">wemake.services</a> | Remote | Short unpaid take-home challenge, code review, portfolio discussion</li>\n<li><a href=\"https://www.weployapp.com/join-our-team/\">Weploy</a> | Melbourne, Australia; Sydney, Australia | Phase 1: Face to face interview to get to know the candidate. Phase 2: Problem solving session that involves designing a solution to a real-world problem followed by 1/2 day of pairing with a senior dev on implementing the proposed solution.</li>\n<li><a href=\"https://wetransfer.homerun.co/\">WeTransfer</a> | Amsterdam, Netherlands | Culture fit and fundamentals chat, skills interview - no whiteboarding! - and take-home project, communication and collaboration interview, meet with the VP of Engineering</li>\n<li><a href=\"https://wheely.com/en/careers\">Wheely</a> | Moscow, Russia | Get to know each other in under 30 minutes on-site or via Skype, take-home challenge, on-site review and interview with the team.</li>\n<li><a href=\"https://wildbit.com/\">Wildbit</a> | Philadelphia, PA &#x26; Remote | Take-home project followed by interviews.</li>\n<li><a href=\"https://wirecardbrasil.workable.com/\">Wirecard Brasil</a> | São Paulo, Brazil | Phone or on-site Cultural Fit interview, take-home coding challenge, code review and discussing in-person.</li>\n<li><a href=\"https://worldgaming.com/\">WorldGaming</a> | Toronto, Canada | Technical Interview, Solution Design, Take Home Assignment, then Culture fit interview with the team</li>\n<li><a href=\"https://woumedia.com/\">woumedia</a> | Remote | Getting to know each other and aligning expectations. Talking about past experiences, projects you are proud of and latest challenges you faced. It's followed by a use case study from one of our current projects.</li>\n<li><a href=\"https://wyeworks.com/\">WyeWorks</a> | Montevideo, Uruguay | Take-home project and discussion on-site</li>\n<li><a href=\"http://x-team.com/\">X-Team</a> | Remote | A short, fun Node.js challenge, followed by a series of culture-based interview questions, followed by a creative mock project with tons of freedom on how to approach, and follow-up questions about the approach they chose to discuss the tradeoffs. Usually a 10-30 day paid training is rewarded to top candidates to prep them for remote communication skills needed to join a team.</li>\n<li><a href=\"https://www.xing.com/\">XING</a> | Hamburg, Germany | Take-home coding challenge, on-site review and short interviews with future team.</li>\n</ul>\n<h2>Y -</h2>\n<ul>\n<li><a href=\"http://www.1000mercis.com/#!/careers/?lang=en\">1000mercis group</a> | Paris, France | Series of interviews, that go over technical background, past experiences and cultural knowledge</li>\n<li></li>\n<li><a href=\"https://18f.gsa.gov/join/\">18F</a> | Remote; Washington, DC; New York, NY; Chicago, IL; San Francisco, CA | take-home coding exercise (2-4 hours), technical and values-match interviews over video chat</li>\n<li></li>\n<li><a href=\"https://3dhubs.com/jobs\">3D Hubs</a> | Amsterdam, The Netherlands | Take-home code challenge from o</li>\n<li></li>\n<li><a href=\"http://500friends.com/who-we-are/careers\">500friends</a> | San Francisco, CA; Remote | Take home challenge followed by onsite ex</li>\n<li></li>\n<li><a href=\"https://500tech.com/\">500Tech</a> | Tel Aviv, Israel | Pair programming on a laptop in w</li>\n<li></li>\n<li><a href=\"https://8thlight.com/\">8th Light</a> | Chicago, IL; London, UK; Los Angeles, CA; New York, NY | Take home code challenge, discussion, pair programming session</li>\n<li></li>\n<li><a href=\"https://www.yhat.com/jobs\">Yhat</a> | Brooklyn, NY | Demo something cool you built and walk us thru the code + design decisions</li>\n<li></li>\n<li><a href=\"https://yld.breezy.hr/\">YLD</a> | London, UK | Take home-code challenge, pair-programming session and discussion about past experi</li>\n<li></li>\n<li><a href=\"https://yodas.com/\">Yodas</a> | Binyamina, Israel | Coding tasks over github repository</li>\n<li><a href=\"http://yoyowallet.com/\">Yoyo Wallet</a> | London, UK | Take home code challenge, discussion of the code challenge, and general, high level questions</li>\n<li><a href=\"http://www.yunojuno.com/\">YunoJuno</a> | London, UK | Code challenge based on a realistic feature request on a real open-source package created and used at YunoJuno; phone/video interview with members of the Product team to explore technical background, experiences, interests, cultural fit; on-site interview, usually with Product Manager and CTO</li>\n<li><a href=\"https://jobs.kenoby.com/grupozap/\">ZAP Group</a> | São Paulo, Brazil | Takehome exercise, series of real-world interviews with engineers, HR, engineering managers and product managers on site.</li>\n<li><a href=\"https://www.zencargo.com/careers\">Zencargo</a> | London, UK | Initial interview with CTO, covering professional experience interests and expectations, followed by one technical interview focused on fundamentals and familiarity with best practices. A further short chat with co-founders to get to know each other - - either onsite or remote.</li>\n<li><a href=\"https://www.zenefits.com/careers\">Zenefits (UI Team)</a> | San Francisco, CA | One technical phone screen focused on JS fundamentals and/or one timeboxed take-home challenge. The onsite is a series of interviews designed to test your understanding of JS, HTML/CSS, design, etc.</li>\n<li><a href=\"https://zerodha.com/careers\">Zerodha</a> | Bengaluru, India | Technical call at the beginning and one take home programming task.</li>\n<li><a href=\"https://boards.greenhouse.io/zype\">Zype</a> | New York, NY &#x26; Remote | Skype/Video call with VP of Product and a take-home challenge.</li>\n</ul>"},{"url":"/docs/ds-algo/free-code-camp/","relativePath":"docs/ds-algo/free-code-camp.md","relativeDir":"docs/ds-algo","base":"free-code-camp.md","name":"free-code-camp","frontmatter":{"title":"Map and Set","weight":0,"excerpt":"Data structures, at a high level, are techniques for storing and organizing data that make it easier to modify, navigate, and access. Data structures determine how data is collected, the functions we can use to access it, and the relationships between data.","seo":{"title":"Map and Set","description":"How to Use JavaScript Collections","robots":[],"extra":[]},"template":"docs"},"html":"<h1>How to Use JavaScript Collections - Map and Set</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>In JavaScript, objects are used to store multiple values as a complex data structure. An object is created with curly braces {…} and a list of properties. A property is a key-value pair where the key must be a string and the value can be of any type. On the other</p>\n</blockquote>\n<hr>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/size/w2000/2020/09/cover-5.png\" alt=\"How to Use JavaScript Collections  - Map and Set\"></p>\n<p>In JavaScript, <code class=\"language-text\">objects</code> are used to store multiple values as a complex data structure.</p>\n<p>An object is created with curly braces <code class=\"language-text\">{…}</code> and a list of properties. A property is a key-value pair where the <code class=\"language-text\">key</code> must be a string and the <code class=\"language-text\">value</code> can be of any type.</p>\n<p>On the other hand, <code class=\"language-text\">arrays</code> are an ordered collection that can hold data of any type. In JavaScript, arrays are created with square brackets <code class=\"language-text\">[...]</code> and allow duplicate elements.</p>\n<p>Until ES6 (ECMAScript 2015), JavaScript <code class=\"language-text\">objects</code> and <code class=\"language-text\">arrays</code> were the most important data structures to handle collections of data. The developer community didn't have many choices outside of that. Even so, a combination of objects and arrays was able to handle data in many scenarios.</p>\n<p>However, there were a few shortcomings,</p>\n<ul>\n<li>Object keys can only be of type <code class=\"language-text\">string</code>.</li>\n<li>Objects don't maintain the order of the elements inserted into them.</li>\n<li>Objects lack some useful methods, which makes them difficult to use in some situations. For example, you can't compute the size (<code class=\"language-text\">length</code>) of an object easily. Also, enumerating an object is not that straightforward.</li>\n<li>Arrays are collections of elements that allow duplicates. Supporting arrays that only have distinct elements requires extra logic and code.</li>\n</ul>\n<p>With the introduction of ES6, we got two new data structures that address the shortcomings mentioned above: <code class=\"language-text\">Map</code> and <code class=\"language-text\">Set</code>. In this article, we will look at both closely and understand how to use them in different situations.</p>\n<h2>Map in JavaScript</h2>\n<p><code class=\"language-text\">Map</code> is a collection of key-value pairs where the key can be of any type. <code class=\"language-text\">Map</code> remembers the original order in which the elements were added to it, which means data can be retrieved in the same order it was inserted in.</p>\n<p>In other words, <code class=\"language-text\">Map</code> has characteristics of both <code class=\"language-text\">Object</code> and <code class=\"language-text\">Array</code>:</p>\n<ul>\n<li>Like an object, it supports the key-value pair structure.</li>\n<li>Like an array, it remembers the insertion order.</li>\n</ul>\n<h3><strong>How to Create and Initialize a Map in JavaScript</strong></h3>\n<p>A new <code class=\"language-text\">Map</code> can be created like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> map <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Which returns an empty <code class=\"language-text\">Map</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">0</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>Another way of creating a <code class=\"language-text\">Map</code> is with initial values. Here's how to create a <code class=\"language-text\">Map</code> with three key-value pairs:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> freeCodeCampBlog <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'freeCodeCamp'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'type'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blog'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'writer'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Tapas Adhikary'</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Which returns a <code class=\"language-text\">Map</code> with three elements:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">3</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"freeCodeCamp\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"type\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"blog\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"writer\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"Tapas Adhikary\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3><strong>How to Add values to a Map in JavaScript</strong></h3>\n<p>To add value to a Map, use the <code class=\"language-text\">set(key, value)</code> method.</p>\n<p>The <code class=\"language-text\">set(key, value)</code> method takes two parameters, <code class=\"language-text\">key</code> and <code class=\"language-text\">value</code>, where the key and value can be of any type, a primitive (<code class=\"language-text\">boolean</code>, <code class=\"language-text\">string</code>, <code class=\"language-text\">number</code>, etc.) or an object:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\njs<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> map <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'freeCodeCamp'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'type'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blog'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'writer'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Tapas Adhikary'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">3</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"freeCodeCamp\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"type\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"blog\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"writer\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"Tapas Adhikary\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>Please note, if you use the same key to add a value to a <code class=\"language-text\">Map</code> multiple times, it'll always replace the previous value:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'writer'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Someone else!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>So the output would be:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">3</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"freeCodeCamp\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"type\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"blog\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"writer\"</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"Someone else!\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3><strong>How to Get values from a Map in JavaScript</strong></h3>\n<p>To get a value from a <code class=\"language-text\">Map</code>, use the <code class=\"language-text\">get(key)</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>All About Map Keys in JavaScript</strong></h3>\n<p><code class=\"language-text\">Map</code> keys can be of any type, a primitive, or an object. This is one of the major differences between <code class=\"language-text\">Map</code> and regular JavaScript objects where the key can only be a string:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\njs<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> funMap <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nfunMap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token number\">360</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'My House Number'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nfunMap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'I write blogs!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'tapas'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nfunMap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">,</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>funMap<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here is the output:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">3</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">{</span>\n  <span class=\"token number\">360</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"My House Number\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token parameter\"><span class=\"token boolean\">true</span></span> <span class=\"token operator\">=></span> <span class=\"token string\">\"I write blogs!\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span>…<span class=\"token punctuation\">}</span> <span class=\"token operator\">=></span> <span class=\"token boolean\">true</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>A regular JavaScript object always treats the key as a string. Even when you pass it a primitive or object, it internally converts the key into a string:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\njs<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> funObj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nfunObj<span class=\"token punctuation\">[</span><span class=\"token number\">360</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'My House Number'</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>funObj<span class=\"token punctuation\">[</span><span class=\"token number\">360</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> funObj<span class=\"token punctuation\">[</span><span class=\"token string\">'360'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>Map Properties and Methods in JavaScript</strong></h3>\n<p>JavaScript's <code class=\"language-text\">Map</code> has in-built properties and methods that make it easy to use. Here are some of the common ones:</p>\n<ul>\n<li>Use the <code class=\"language-text\">size</code> property to know how many elements are in a <code class=\"language-text\">Map</code>:</li>\n<li>Search an element with the <code class=\"language-text\">has(key)</code> method:</li>\n<li>Remove an element with the <code class=\"language-text\">delete(key)</code> method:</li>\n<li>Use the <code class=\"language-text\">clear()</code> method to remove all the elements from the <code class=\"language-text\">Map</code> at once:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'size of the map is'</span><span class=\"token punctuation\">,</span> map<span class=\"token punctuation\">.</span>size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>map<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>map<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Tapas'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Sam'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">clear</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nmap<span class=\"token punctuation\">.</span>size<span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>MapIterator: keys(), values(), and entries() in JavaScript</strong></h3>\n<p>The methods <code class=\"language-text\">keys()</code>, <code class=\"language-text\">values()</code> and <code class=\"language-text\">entries()</code> methods return a <code class=\"language-text\">MapIterator</code>, which is excellent because you can use a <code class=\"language-text\">for-of</code> or <code class=\"language-text\">forEach</code> loop directly on it.</p>\n<p>First, create a simple <code class=\"language-text\">Map</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> ageMap <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'Jack'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'Alan'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">34</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'Bill'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'Sam'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Get all the keys:</li>\n<li>Get all the values:</li>\n<li>Get all the entries (key-value pairs):</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ageMap<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ageMap<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ageMap<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>How to Iterate Over a Map in JavaScript</strong></h3>\n<p>You can use either the <code class=\"language-text\">forEach</code> or <code class=\"language-text\">for-of</code> loop to iterate over a <code class=\"language-text\">Map</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nageMap<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value<span class=\"token punctuation\">,</span> key</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>key<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> is </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>value<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> years old!</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span> <span class=\"token keyword\">of</span> ageMap<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>key<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> is </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>value<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> years old!</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The output is going to be the same in both cases:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nJack is <span class=\"token number\">20</span> years old<span class=\"token operator\">!</span>\nAlan is <span class=\"token number\">34</span> years old<span class=\"token operator\">!</span>\nBill is <span class=\"token number\">10</span> years old<span class=\"token operator\">!</span>\nSam is <span class=\"token number\">9</span> years old<span class=\"token operator\">!</span></code></pre></div>\n<h3><strong>How to Convert an Object into a Map in JavaScript</strong></h3>\n<p>You may encounter a situation where you need to convert an <code class=\"language-text\">object</code> to a <code class=\"language-text\">Map</code>-like structure. You can use the method <code class=\"language-text\">entries</code> of <code class=\"language-text\">Object</code> to do that:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> address <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">Tapas</span><span class=\"token operator\">:</span> <span class=\"token string\">'Bangalore'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">James</span><span class=\"token operator\">:</span> <span class=\"token string\">'Huston'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">Selva</span><span class=\"token operator\">:</span> <span class=\"token string\">'Srilanka'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> addressMap <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span>address<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>How to Convert a Map into an Object in JavaScript</strong></h3>\n<p>If you want to do the reverse, you can use the <code class=\"language-text\">fromEntries</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">fromEntries</span><span class=\"token punctuation\">(</span>map<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>How to Convert a Map into an Array in JavaScript</strong></h3>\n<p>There are a couple of ways to convert a map into an array:</p>\n<ul>\n<li>Using <code class=\"language-text\">Array.from(map)</code>:</li>\n<li>Using the spread operator:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> map <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'milk'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">200</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tea'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'coffee'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">500</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span>map<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>map<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>Map vs. Object: When should you use them?</strong></h3>\n<p><code class=\"language-text\">Map</code> has characteristics of both <code class=\"language-text\">object</code> and <code class=\"language-text\">array</code>. However, <code class=\"language-text\">Map</code> is more like an <code class=\"language-text\">object</code> than <code class=\"language-text\">array</code> due to the nature of storing data in the <code class=\"language-text\">key-value</code> format.</p>\n<p>The similarity with objects ends here though. As you've seen, <code class=\"language-text\">Map</code> is different in a lot of ways. So, which one should you use, and when? How do you decide?</p>\n<p>Use <code class=\"language-text\">Map</code> when:</p>\n<ul>\n<li>Your needs are not that simple. You may want to create keys that are non-strings. Storing an object as a key is a very powerful approach. <code class=\"language-text\">Map</code> gives you this ability by default.</li>\n<li>You need a data structure where elements can be ordered. Regular objects do not maintain the order of their entries.</li>\n<li>You are looking for flexibility without relying on an external library like lodash. You may end up using a library like lodash because we do not find methods like has(), values(), delete(), or a property like size with a regular object. Map makes this easy for you by providing all these methods by default.</li>\n</ul>\n<p>Use an object when:</p>\n<ul>\n<li>You do not have any of the needs listed above.</li>\n<li>You rely on <code class=\"language-text\">JSON.parse()</code> as a <code class=\"language-text\">Map</code> cannot be parsed with it.</li>\n</ul>\n<h2>Set in JavaScript</h2>\n<p>A <code class=\"language-text\">Set</code> is a collection of unique elements that can be of any type. <code class=\"language-text\">Set</code> is also an ordered collection of elements, which means that elements will be retrieved in the same order that they were inserted in.</p>\n<p>A <code class=\"language-text\">Set</code> in JavaScript behaves the same way as a mathematical set.</p>\n<h3>How to Create and Initialize a Set in JavaScript</h3>\n<p>A new <code class=\"language-text\">Set</code> can be created like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> set <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>set<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>And the output will be an empty <code class=\"language-text\">Set</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Set</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">0</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>Here's how to create a <code class=\"language-text\">Set</code> with some initial values:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> fruteSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'🍉'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍎'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍈'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍏'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>fruteSet<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Set</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">4</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"🍉\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"🍎\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"🍈\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"🍏\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3><strong>Set Properties and Methods in JavaScript</strong></h3>\n<p><code class=\"language-text\">Set</code> has methods to add an element to it, delete elements from it, check if an element exists in it, and to clear it completely:</p>\n<ul>\n<li>Use the <code class=\"language-text\">size</code> property to know the size of the <code class=\"language-text\">Set</code>. It returns the number of elements in it:</li>\n<li>Use the <code class=\"language-text\">add(element)</code> method to add an element to the <code class=\"language-text\">Set</code>:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nset<span class=\"token punctuation\">.</span>size<span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> saladSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nsaladSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🍅'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsaladSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🥑'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsaladSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🥕'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nsaladSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🥒'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>saladSet<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>I love cucumbers! How about adding one more?</p>\n<p>Oh no, I can't - <code class=\"language-text\">Set</code> is a collection of <strong>unique</strong> elements:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nsaladSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🥒'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>saladSet<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The output is the same as before - nothing got added to the <code class=\"language-text\">saladSet</code>.</p>\n<ul>\n<li>Use the <code class=\"language-text\">has(element)</code> method to search if we have a carrot (🥕) or broccoli (🥦) in the <code class=\"language-text\">Set</code>:</li>\n<li>Use the <code class=\"language-text\">delete(element)</code> method to remove the avocado(🥑) from the <code class=\"language-text\">Set</code>:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Does the salad have a carrot?'</span><span class=\"token punctuation\">,</span> saladSet<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🥕'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Does the salad have broccoli?'</span><span class=\"token punctuation\">,</span> saladSet<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🥦'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nsaladSet<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🥑'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I do not like 🥑, remove from the salad:'</span><span class=\"token punctuation\">,</span> saladSet<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Now our salad <code class=\"language-text\">Set</code> is as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Set</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">3</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"🍅\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"🥕\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"🥒\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Use the <code class=\"language-text\">clear()</code> method to remove all elements from a <code class=\"language-text\">Set</code>:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nsaladSet<span class=\"token punctuation\">.</span><span class=\"token function\">clear</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>**</strong>How to Iterate Over a Set*<strong>* in JavaScript</strong></h3>\n<p><code class=\"language-text\">Set</code> has a method called <code class=\"language-text\">values()</code> which returns a <code class=\"language-text\">SetIterator</code> to get all its values:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\njs<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> houseNos <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">360</span><span class=\"token punctuation\">,</span> <span class=\"token number\">567</span><span class=\"token punctuation\">,</span> <span class=\"token number\">101</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>houseNos<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nSetIterator <span class=\"token punctuation\">{</span><span class=\"token number\">360</span><span class=\"token punctuation\">,</span> <span class=\"token number\">567</span><span class=\"token punctuation\">,</span> <span class=\"token number\">101</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>We can use a <code class=\"language-text\">forEach</code> or <code class=\"language-text\">for-of</code> loop on this to retrieve the values.</p>\n<p>Interestingly, JavaScript tries to make <code class=\"language-text\">Set</code> compatible with <code class=\"language-text\">Map</code>. That's why we find two of the same methods as <code class=\"language-text\">Map</code>, <code class=\"language-text\">keys()</code> and <code class=\"language-text\">entries()</code>.</p>\n<p>As <code class=\"language-text\">Set</code> doesn't have keys, the <code class=\"language-text\">keys()</code> method returns a <code class=\"language-text\">SetIterator</code> to retrieve its values:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>houseNos<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>With <code class=\"language-text\">Map</code>, the <code class=\"language-text\">entries()</code> method returns an iterator to retrieve key-value pairs. Again there are no keys in a <code class=\"language-text\">Set</code>, so <code class=\"language-text\">entries()</code> returns a <code class=\"language-text\">SetIterator</code> to retrieve the value-value pairs:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>houseNos<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>How to Enumerate over a Set in JavaScript</strong></h3>\n<p>We can enumerate over a Set using <code class=\"language-text\">forEach</code> and <code class=\"language-text\">for-of</code> loops:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nhouseNos<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> houseNos<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The output of both is:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token number\">360</span><span class=\"token punctuation\">;</span>\n<span class=\"token number\">567</span><span class=\"token punctuation\">;</span>\n<span class=\"token number\">101</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>Sets and Arrays in JavaScript</strong></h3>\n<p>An array, like a <code class=\"language-text\">Set</code>, allows you to add and remove elements. But <code class=\"language-text\">Set</code> is quite different, and is not meant to replace arrays.</p>\n<p>The major difference between an array and a <code class=\"language-text\">Set</code> is that arrays allow you to have duplicate elements. Also, some of the <code class=\"language-text\">Set</code> operations like <code class=\"language-text\">delete()</code> are faster than array operations like <code class=\"language-text\">shift()</code> or <code class=\"language-text\">splice()</code>.</p>\n<p>Think of <code class=\"language-text\">Set</code> as an extension of a regular array, just with more muscles. The <code class=\"language-text\">Set</code> data structure is not a replacement of the <code class=\"language-text\">array</code>. Both can solve interesting problems.</p>\n<h3><strong>How to Convert a Set into an array in JavaScript</strong></h3>\n<p>Converting a <code class=\"language-text\">Set</code> into an array is simple:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>houseNos<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><strong>Unique values from an array using the Set in JavaScript</strong></h3>\n<p>Creating a <code class=\"language-text\">Set</code> is a really easy way to remove duplicate values from an array:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\njs<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> mixedFruit <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'🍉'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍎'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍉'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍈'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍏'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍎'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'🍈'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> mixedFruitSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>mixedFruit<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>mixedFruitSet<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Output:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">Set</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token number\">4</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"🍉\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"🍎\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"🍈\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"🍏\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3><strong>Set and Object in JavaScript</strong></h3>\n<p>A <code class=\"language-text\">Set</code> can have elements of any type, even objects:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\njs<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Alex'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">32</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> pSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\npSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>person<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>pSet<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Output:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/09/image-113.png\" alt=\"output\"></p>\n<p>No surprise here - the <code class=\"language-text\">Set</code> contains one element that is an object.</p>\n<p>Let's change a property of the object and add it to the set again:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nperson<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span><span class=\"token punctuation\">;</span>\n\npSet<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>person<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>pSet<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>What do you think the output will be? Two <code class=\"language-text\">person</code> objects or just one?</p>\n<p>Here is the output:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/09/image-114.png\" alt=\"output\"></p>\n<p><code class=\"language-text\">Set</code> is a collection of unique elements. By changing the property of the object, we haven't changed the object itself. Hence <code class=\"language-text\">Set</code> will not allow duplicate elements.</p>\n<p><code class=\"language-text\">Set</code> is a great data structure to use in addition to JavaScript arrays. It doesn't have a huge advantage over regular arrays, though.</p>\n<p>Use <code class=\"language-text\">Set</code> when you need to maintain a distinct set of data to perform set operations on like <code class=\"language-text\">union</code>, <code class=\"language-text\">intersection</code>, <code class=\"language-text\">difference</code>, and so on.</p>\n<h2><strong>In Summary</strong></h2>\n<p>Here is a GitHub repository to find all the source code used in this article. If you found it helpful, please show your support by giving it a star: <a href=\"https://github.com/atapas/js-collections-map-set\">https://github.com/atapas/js-collections-map-set</a></p>\n<p>You may also like some of my other articles:</p>\n<ul>\n<li><a href=\"https://blog.greenroots.info/my-favorite-javascript-tips-and-tricks-ckd60i4cq011em8s16uobcelc\">My Favorite JavaScript Tips and Tricks</a></li>\n<li><a href=\"https://blog.greenroots.info/javascript-equality-comparison-with-and-objectis-ckdpt2ryk01vel9s186ft8cwl\">JavaScript equality and similarity with ==, === and Object.is()</a></li>\n</ul>\n<p>If this article was useful, please share it so others can read it as well. You can @ me on Twitter (<a href=\"https://twitter.com/tapasadhikary\">@tapasadhikary</a>) with comments, or feel free to follow me.</p>\n<hr>\n<hr>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>Best Books for Data Structures and Algorithms in JavaScript</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>If you're trying to learn about data structures or algorithms, you're in luck - there are a lot of resources out there. Here are a few book recommendations - along with some other resources at the end - to get you started. Books about data structures and algorithmsData Structures in</p>\n</blockquote>\n<hr>\n<p><img src=\"https://cdn-media-2.freecodecamp.org/w1280/5f9c9e61740569d1a4ca3cce.jpg\" alt=\"Best Books for Data Structures and Algorithms in JavaScript\"></p>\n<p>If you're trying to learn about data structures or algorithms, you're in luck - there are a lot of resources out there.</p>\n<p>Here are a few book recommendations - along with some other resources at the end - to get you started.</p>\n<h2>Books about data structures and algorithms</h2>\n<p><em>Data Structures in JavaScript</em></p>\n<ul>\n<li>Free book which covers Data Structures in JavaScript (you can find the <a href=\"https://www.gitbook.com/book/pmary/data-structure-in-javascript/details\">GitBook</a> here).</li>\n</ul>\n<p><em>Learning JavaScript Data Structures and Algorithms - Second Edition,</em> by Loiane Groner</p>\n<ul>\n<li>Covers object oriented programming, prototypal inheritance, sorting &#x26; searching algorithms, quicksort, mergesort, binary search trees and advanced algorithm concepts</li>\n</ul>\n<p><em>Data Structures and Algorithms with JavaScript: Bringing classic computing approaches to the Web</em> by Michael McMillan</p>\n<ul>\n<li>Covers recursion, sorting and searching algorithms, linked lists and binary search trees.</li>\n</ul>\n<p><em>Data Structures</em> by Seymour Lipschutz</p>\n<ul>\n<li>A machine and language agnostic book which explains data structures in a clear and straightforward way. Includes examples, diagrams, and pseudo-code.</li>\n</ul>\n<p><em>Introduction to Algorithms</em> by Thomas H Cormen et al</p>\n<ul>\n<li>Another language agnostic book, contains examples in pseudo-code. Appropriate for both teaching and professional environments. Each chapter covers an algorithm - you don't have to read the whole book straight through from beginning to end.</li>\n</ul>\n<p><em>Data Structures in C</em>, by Noel Kalicharan</p>\n<ul>\n<li>Covers the basics and makes data structures seem easier than other books manage to do. Teaches introductory concepts like linked lists, stacks, sorting, binary trees, and searching. Great beginner's book, but useful to more advanced students as well.</li>\n</ul>\n<p><em>Algorithms in C</em>, by Robert Sedgewick</p>\n<ul>\n<li>Focuses on implementations of algorithms in C in areas of sorting, searching, string processing, graph, geometric, and mathematical algorithms. Discusses why certain algorithms are more effective than others. Numerous figures throughout the book help illustrate how these algorithms work.</li>\n</ul>\n<p>Please feel free to add more that you have found useful!</p>\n<h2>More resources about data structures and algorithms:</h2>\n<p><a href=\"https://www.freecodecamp.org/news/these-are-the-best-free-courses-to-learn-data-structures-and-algorithms-in-depth-4d52f0d6b35a/\">Great resources for learning data structures and algorithms</a></p>\n<p><a href=\"https://www.freecodecamp.org/news/an-intro-to-advanced-sorting-algorithms-merge-quick-radix-sort-in-javascript-b65842194597/\">An intro to advanced sorting algorithms in JavaScript</a></p>\n<p><a href=\"https://www.freecodecamp.org/news/data-structures-and-algorithms-in-javascript/\">Free video course on data structures and algorithms in JavaScript</a></p>\n<p><a href=\"https://www.freecodecamp.org/news/my-software-engineering-bookshelf/\">Algorithm basics and other book recommendations</a></p>\n<hr>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>Data Structures - freeCodeCamp.org</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice.</p>\n</blockquote>\n<hr>\n<p>freeCodeCamp is a donor-supported tax-exempt 501(c)(3) nonprofit organization (United States Federal Tax Identification Number: 82-0779546)</p>\n<p>Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons - all freely available to the public. We also have thousands of freeCodeCamp study groups around the world.</p>\n<p>Donations to freeCodeCamp go toward our education initiatives and help pay for servers, services, and staff.</p>\n<p>You can <a href=\"https://www.freecodecamp.org/donate/\">make a tax-deductible donation here</a>.</p>\n<hr>\n<hr>\n<h1>Binary Search Trees: BST Explained with Examples</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>What is a Binary Search Tree?A tree is a data structure composed of nodes that has the following characteristics: Each tree has a root node at the top (also known as Parent Node) containing some value (can be any datatype).The root node has zero or more child nodes.</p>\n</blockquote>\n<hr>\n<p><img src=\"https://cdn-media-2.freecodecamp.org/w1280/5f9c9f48740569d1a4ca41c4.jpg\" alt=\"Binary Search Trees: BST Explained with Examples\"></p>\n<h2>What is a Binary Search Tree?</h2>\n<p>A tree is a data structure composed of nodes that has the following characteristics:</p>\n<ol>\n<li>Each tree has a root node at the top (also known as Parent Node) containing some value (can be any datatype).</li>\n<li>The root node has zero or more child nodes.</li>\n<li>Each child node has zero or more child nodes, and so on. This creates a subtree in the tree. Every node has its own subtree made up of its children and their children, etc. This means that every node on its own can be a tree.</li>\n</ol>\n<p>A binary search tree (BST) adds these two characteristics:</p>\n<ol>\n<li>Each node has a maximum of up to two children.</li>\n<li>For each node, the values of its left descendent nodes are less than that of the current node, which in turn is less than the right descendent nodes (if any).</li>\n</ol>\n<p>The BST is built on the idea of the <a href=\"https://guide.freecodecamp.org/algorithms/search-algorithms/binary-search\">binary search</a> algorithm, which allows for fast lookup, insertion and removal of nodes. The way that they are set up means that, on average, each comparison allows the operations to skip about half of the tree, so that each lookup, insertion or deletion takes time proportional to the logarithm of the number of items stored in the tree, <code class=\"language-text\">O(log n)</code> . However, some times the worst case can happen, when the tree isn't balanced and the time complexity is <code class=\"language-text\">O(n)</code> for all three of these functions. That is why self-balancing trees (AVL, red-black, etc.) are a lot more effective than the basic BST.</p>\n<p><strong>Worst case scenario example:</strong> This can happen when you keep adding nodes that are <em>always</em> larger than the node before (its parent), the same can happen when you always add nodes with values lower than their parents.</p>\n<h3>Basic operations on a BST</h3>\n<ul>\n<li>Create: creates an empty tree.</li>\n<li>Insert: insert a node in the tree.</li>\n<li>Search: Searches for a node in the tree.</li>\n<li>Delete: deletes a node from the tree.</li>\n<li>Inorder: in-order traversal of the tree.</li>\n<li>Preorder: pre-order traversal of the tree.</li>\n<li>Postorder: post-order traversal of the tree.</li>\n</ul>\n<h4>Create</h4>\n<p>Initially an empty tree without any nodes is created. The variable/identifier which must point to the root node is initialized with a <code class=\"language-text\">NULL</code> value.</p>\n<h4>Search</h4>\n<p>You always start searching the tree at the root node and go down from there. You compare the data in each node with the one you are looking for. If the compared node doesn't match then you either proceed to the right child or the left child, which depends on the outcome of the following comparison: If the node that you are searching for is lower than the one you were comparing it with, you proceed to the left child, otherwise (if it's larger) you go to the right child. Why? Because the BST is structured (as per its definition), that the right child is always larger than the parent and the left child is always lesser.</p>\n<h6>Breadth-first search (BFS)</h6>\n<p>Breadth first search is an algorithm used to traverse a BST. It begins at the root node and travels in a lateral manner (side to side), searching for the desired node. This type of search can be described as O(n) given that each node is visited once and the size of the tree directly correlates to the length of the search.</p>\n<h6>Depth-first search (DFS)</h6>\n<p>With a Depth-first search approach, we start with the root node and travel down a single branch. If the desired node is found along that branch, great, but if not, continue upwards and search unvisited nodes. This type of search also has a big O notation of O(n).</p>\n<h4>Insert</h4>\n<p>It is very similar to the search function. You again start at the root of the tree and go down recursively, searching for the right place to insert our new node, in the same way as explained in the search function. If a node with the same value is already in the tree, you can choose to either insert the duplicate or not. Some trees allow duplicates, some don't. It depends on the certain implementation.</p>\n<h4>Deletion</h4>\n<p>There are 3 cases that can happen when you are trying to delete a node. If it has,</p>\n<ol>\n<li>No subtree (no children): This one is the easiest one. You can simply just delete the node, without any additional actions required.</li>\n<li>One subtree (one child): You have to make sure that after the node is deleted, its child is then connected to the deleted node's parent.</li>\n<li>Two subtrees (two children): You have to find and replace the node you want to delete with its inorder successor (the leftmost node in the right subtree).</li>\n</ol>\n<p>The time complexity for creating a tree is <code class=\"language-text\">O(1)</code> . The time complexity for searching, inserting or deleting a node depends on the height of the tree <code class=\"language-text\">h</code> , so the worst case is <code class=\"language-text\">O(h)</code> in case of skewed trees.</p>\n<h4>Predecessor of a node</h4>\n<p>Predecessors can be described as the node that would come right before the node you are currently at. To find the predecessor of the current node, look at the right-most/largest leaf node in the left subtree.</p>\n<h4>Successor of a node</h4>\n<p>Successors can be described as the node that would come right after the the current node. To find the successor of the current node, look at the left-most/smallest leaf node in the right subtree.</p>\n<h3>Special types of BT</h3>\n<ul>\n<li>Heap</li>\n<li>Red-black tree</li>\n<li>B-tree</li>\n<li>Splay tree</li>\n<li>N-ary tree</li>\n<li>Trie (Radix tree)</li>\n</ul>\n<h3>Runtime</h3>\n<p><strong>Data structure: BST</strong></p>\n<ul>\n<li>Worst-case performance: <code class=\"language-text\">O(n)</code></li>\n<li>Best-case performance: <code class=\"language-text\">O(1)</code></li>\n<li>Average performance: <code class=\"language-text\">O(log n)</code></li>\n<li>Worst-case space complexity: <code class=\"language-text\">O(1)</code></li>\n</ul>\n<p>Where <code class=\"language-text\">n</code> is the number of nodes in the BST. Worst case is O(n) since BST can be unbalanced.</p>\n<h3>Implementation of BST</h3>\n<p>Here's a definition for a BST node having some data, referencing to its left and right child nodes.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">struct node {\n   int data;\n   struct node *leftChild;\n   struct node *rightChild;\n};</code></pre></div>\n<h4>Search Operation</h4>\n<p>Whenever an element is to be searched, start searching from the root node. Then if the data is less than the key value, search for the element in the left subtree. Otherwise, search for the element in the right subtree. Follow the same algorithm for each node.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">struct node* search(int data){\n   struct node *current = root;\n   printf(\"Visiting elements: \");\n\n   while(current->data != data){\n\n      if(current != NULL) {\n         printf(\"%d \",current->data);\n\n         //go to left tree\n         if(current->data > data){\n            current = current->leftChild;\n         }//else go to right tree\n         else {\n            current = current->rightChild;\n         }\n\n         //not found\n         if(current == NULL){\n            return NULL;\n         }\n      }\n   }\n   return current;\n}</code></pre></div>\n<h4>Insert Operation</h4>\n<p>Whenever an element is to be inserted, first locate its proper location. Start searching from the root node, then if the data is less than the key value, search for the empty location in the left subtree and insert the data. Otherwise, search for the empty location in the right subtree and insert the data.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">void insert(int data) {\n   struct node *tempNode = (struct node*) malloc(sizeof(struct node));\n   struct node *current;\n   struct node *parent;\n\n   tempNode->data = data;\n   tempNode->leftChild = NULL;\n   tempNode->rightChild = NULL;\n\n   //if tree is empty\n   if(root == NULL) {\n      root = tempNode;\n   } else {\n      current = root;\n      parent = NULL;\n\n      while(1) {\n         parent = current;\n\n         //go to left of the tree\n         if(data &lt; parent->data) {\n            current = current->leftChild;\n            //insert to the left\n\n            if(current == NULL) {\n               parent->leftChild = tempNode;\n               return;\n            }\n         }//go to right of the tree\n         else {\n            current = current->rightChild;\n\n            //insert to the right\n            if(current == NULL) {\n               parent->rightChild = tempNode;\n               return;\n            }\n         }\n      }\n   }\n}</code></pre></div>\n<h4>Delete Operation</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">void deleteNode(struct node* root, int data){\n\n    if (root == NULL) root=tempnode;\n\n    if (data &lt; root->key)\n        root->left = deleteNode(root->left, key);\n\n\n    else if (key > root->key)\n        root->right = deleteNode(root->right, key);\n\n    else\n    {\n        if (root->left == NULL)\n        {\n            struct node *temp = root->right;\n            free(root);\n            return temp;\n        }\n        else if (root->right == NULL)\n        {\n            struct node *temp = root->left;\n            free(root);\n            return temp;\n        }\n\n        struct node* temp = minValueNode(root->right);\n\n        root->key = temp->key;\n\n        root->right = deleteNode(root->right, temp->key);\n    }\n    return root;\n\n}</code></pre></div>\n<p>Binary search trees (BSTs) also give us quick access to predecessors and successors. Predecessors can be described as the node that would come right before the node you are currently at.</p>\n<ul>\n<li>To find the predecessor of the current node, look at the rightmost/largest leaf node in the left subtree. Successors can be described as the node that would come right after the node you are currently at.</li>\n<li>To find the successor of the current node, look at the leftmost/smallest leaf node in the right subtree.</li>\n</ul>\n<h3>Let's look at a couple of procedures operating on trees.</h3>\n<p>Since trees are recursively defined, it's very common to write routines that operate on trees that are themselves recursive.</p>\n<p>So for instance, if we want to calculate the height of a tree, that is the height of a root node, We can go ahead and recursively do that, going through the tree. So we can say:</p>\n<ul>\n<li>For instance, if we have a nil tree, then its height is a 0.</li>\n<li>Otherwise, We're 1 plus the maximum of the left child tree and the right child tree.</li>\n<li>So if we look at a leaf for example, that height would be 1 because the height of the left child is nil, is 0, and the height of the nil right child is also 0. So the max of that is 0, then 1 plus 0.</li>\n</ul>\n<h4>Height(tree) algorithm</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if tree = nil:\n    return 0\nreturn 1 + Max(Height(tree.left),Height(tree.right))</code></pre></div>\n<h4>Here is the code in C++</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">int maxDepth(struct node* node)\n{\n    if (node==NULL)\n        return 0;\n   else\n   {\n       int rDepth = maxDepth(node->right);\n       int lDepth = maxDepth(node->left);\n\n       if (lDepth > rDepth)\n       {\n           return(lDepth+1);\n       }\n       else\n       {\n            return(rDepth+1);\n       }\n   }\n}</code></pre></div>\n<p>We could also look at calculating the size of a tree that is the number of nodes.</p>\n<ul>\n<li>Again, if we have a nil tree, we have zero nodes.</li>\n<li>Otherwise, we have the number of nodes in the left child plus 1 for ourselves plus the number of nodes in the right child. So 1 plus the size of the left tree plus the size of the right tree.</li>\n</ul>\n<h4>Size(tree) algorithm</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if tree = nil\n    return 0\nreturn 1 + Size(tree.left) + Size(tree.right)</code></pre></div>\n<h4>Here is the code in C++</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">int treeSize(struct node* node)\n{\n    if (node==NULL)\n        return 0;\n    else\n        return 1+(treeSize(node->left) + treeSize(node->right));\n}</code></pre></div>\n<h4>Traversal</h4>\n<p>There are 3 kinds of traversals that are done typically over a binary search tree. All these traversals have a somewhat common way of going over the nodes of the tree.</p>\n<h5>In-order</h5>\n<p>This traversal first goes over the left subtree of the root node, then accesses the current node, followed by the right subtree of the current node. The code represents the base case too, which says that an empty tree is also a binary search tree.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">void inOrder(struct node* root) {\n        // Base case\n        if (root == null) {\n                return;\n        }\n        // Travel the left sub-tree first.\n        inOrder(root.left);\n        // Print the current node value\n        printf(\"%d \", root.data);\n        // Travel the right sub-tree next.\n        inOrder(root.right);\n}</code></pre></div>\n<h3>Pre-order</h3>\n<p>This traversal first accesses the current node value, then traverses the left and right sub-trees respectively.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">void preOrder(struct node* root) {\n        if (root == null) {\n                return;\n        }\n        // Print the current node value\n        printf(\"%d \", root.data);\n        // Travel the left sub-tree first.\n        preOrder(root.left);\n        // Travel the right sub-tree next.\n        preOrder(root.right);\n}</code></pre></div>\n<h3>Post-order</h3>\n<p>This traversal puts the root value at last, and goes over the left and right sub-trees first. The relative order of the left and right sub-trees remain the same. Only the position of the root changes in all the above mentioned traversals.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">void postOrder(struct node* root) {\n        if (root == null) {\n                return;\n        }\n        // Travel the left sub-tree first.\n        postOrder(root.left);\n        // Travel the right sub-tree next.\n        postOrder(root.right);\n        // Print the current node value\n        printf(\"%d \", root.data);\n}</code></pre></div>\n<h3>Relevant videos on freeCodeCamp YouTube channel</h3>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://www.youtube.com/embed/5cU1ILGy6dM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" name=\"fitvid0\">\n</iframe>\n<br>\n<h2>And Binary Search Tree: Traversal and Height</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\"  src=\"https://www.youtube.com/embed/Aagf3RyK3Lw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" name=\"fitvid1\">\n</iframe>\n<br>\n<h3>Following are common types of Binary Trees:</h3>\n<p>Full Binary Tree/Strict Binary Tree: A Binary Tree is full or strict if every node has exactly 0 or 2 children.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">          18\n         /   \\\n       /       \\\n     15         30\n    /  \\       /  \\\n  40    50   100   40</code></pre></div>\n<p>In Full Binary Tree, number of leaf nodes is equal to number of internal nodes plus one.</p>\n<p>Complete Binary Tree: A Binary Tree is complete Binary Tree if all levels are completely filled except possibly the last level and the last level has all keys as left as possible</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">           18\n         /    \\\n       /        \\\n     15         30\n    /  \\       /  \\\n  40    50   100   40\n /  \\   /\n8    7 9</code></pre></div>\n<p>Perfect Binary Tree A Binary tree is Perfect Binary Tree in which all internal nodes have two children and all leaves are at the same level.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">          18\n         /  \\\n       /      \\\n     15        30\n    /  \\      /  \\\n  40    50  100   40</code></pre></div>\n<h3>Augmenting a BST</h3>\n<p>Sometimes we need to store some additional information with the traditional data structures to make our tasks easier. For example, consider a scenario where you are supposed to find the ith smallest number in a set. You can use brute force here but we can reduce the complexity of the problem to <code class=\"language-text\">O(lg n)</code> by augmenting a red-black or any self-balancing tree (where n is the number of elements in the set). We can also compute rank of any element in <code class=\"language-text\">O(lg n)</code> time. Let us consider a case where we are augmenting a red-black tree to store the additional information needed. Besides the usual attributes, we can store number of internal nodes in the subtree rooted at x(size of the subtree rooted at x including the node itself). Let x be any arbitrary node of a tree.</p>\n<p><code class=\"language-text\">x.size = x.left.size + x.right.size + 1</code></p>\n<p>While augmenting the tree, we should keep in mind, that we should be able to maintain the augmented information as well as do other operations like insertion, deletion, updating in <code class=\"language-text\">O(lg n)</code> time.</p>\n<p>Since, we know that the value of x.left.size will give us the number of nodes which proceed x in the order traversal of the tree. Thus, <code class=\"language-text\">x.left.size + 1</code> is the rank of x within the subtree rooted at x.</p>\n<hr>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>How to Implement a Linked List in JavaScript</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>If you are learning data structures, a linked list is one data structure you should know. If you do not really understand it or how it is implemented in JavaScript, this article is here to help you. In this article, we will discuss what a linked list is, how it</p>\n</blockquote>\n<hr>\n<p>If you are learning data structures, a linked list is one data structure you should know. If you do not really understand it or how it is implemented in JavaScript, this article is here to help you.</p>\n<p>In this article, we will discuss what a linked list is, how it is different from an array, and how to implement it in JavaScript. Let's get started.</p>\n<h2>What is a Linked List?</h2>\n<p>A linked list is a linear data structure similar to an array. However, unlike arrays, elements are not stored in a particular memory location or index. Rather each element is a separate object that contains a pointer or a link to the next object in that list.</p>\n<p>Each element (commonly called nodes) contains two items: the data stored and a link to the next node. The data can be any valid data type. You can see this illustrated in the diagram below.</p>\n<p><img src=\"https://res.cloudinary.com/dvj2hbywq/image/upload/v1590572188/Group_14_5_bvpwu0.png\" alt=\"Image of a linked list\"></p>\n<p>The entry point to a linked list is called the head. The head is a reference to the first node in the linked list. The last node on the list points to null. If a list is empty, the head is a null reference.</p>\n<p>In JavaScript, a linked list looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> list <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">head</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">6</span>\n        <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span>\n            <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">12</span>\n                <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span>\n                    <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>An advantage of Linked Lists</h2>\n<ul>\n<li>Nodes can easily be removed or added from a linked list without reorganizing the entire data structure. This is one advantage it has over arrays.</li>\n</ul>\n<h2>Disadvantages of Linked Lists</h2>\n<ul>\n<li>Search operations are slow in linked lists. Unlike arrays, random access of data elements is not allowed. Nodes are accessed sequentially starting from the first node.</li>\n<li>It uses more memory than arrays because of the storage of the pointers.</li>\n</ul>\n<h2>Types of Linked Lists</h2>\n<p>There are three types of linked lists:</p>\n<ul>\n<li><strong>Singly Linked Lists</strong>: Each node contains only one pointer to the next node. This is what we have been talking about so far.</li>\n<li><strong>Doubly Linked Lists</strong>: Each node contains two pointers, a pointer to the next node and a pointer to the previous node.</li>\n<li><strong>Circular Linked Lists</strong>: Circular linked lists are a variation of a linked list in which the last node points to the first node or any other node before it, thereby forming a loop.</li>\n</ul>\n<h2>Implementing a List Node in JavaScript</h2>\n<p>As stated earlier, a list node contains two items: the data and the pointer to the next node. We can implement a list node in JavaScript as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ListNode</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>data <span class=\"token operator\">=</span> data<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Implementing a Linked List in JavaScript</h2>\n<p>The code below shows the implementation of a linked list class with a constructor. Notice that if the head node is not passed, the head is initialised to null.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class LinkedList {\n    constructor(head = null) {\n        this.head = head\n    }\n}</code></pre></div>\n<h2>Putting it all together</h2>\n<p>Let's create a linked list with the class we just created. First, we create two list nodes, <code class=\"language-text\">node1</code> and <code class=\"language-text\">node2</code> and a pointer from node 1 to node 2.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let node1 = new ListNode(2)\nlet node2 = new ListNode(5)\nnode1.next = node2</code></pre></div>\n<p>Next, we'll create a Linked list with the <code class=\"language-text\">node1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let list = new LinkedList(node1)</code></pre></div>\n<p>Let's try to access the nodes in the list we just created.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(list.head.next.data)</code></pre></div>\n<h2>Some LinkedList methods</h2>\n<p>Next up, we will implement four helper methods for the linked list. They are:</p>\n<ol>\n<li>size()</li>\n<li>clear()</li>\n<li>getLast()</li>\n<li>getFirst()</li>\n</ol>\n<h3>1. size()</h3>\n<p>This method returns the number of nodes present in the linked list.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">size() {\n    let count = 0;\n    let node = this.head;\n    while (node) {\n        count++;\n        node = node.next\n    }\n    return count;\n}</code></pre></div>\n<h3>2. clear()</h3>\n<p>This method empties out the list.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">clear() {\n    this.head = null;\n}</code></pre></div>\n<h3>3. getLast()</h3>\n<p>This method returns the last node of the linked list.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">getLast() {\n    let lastNode = this.head;\n    if (lastNode) {\n        while (lastNode.next) {\n            lastNode = lastNode.next\n        }\n    }\n    return lastNode\n}</code></pre></div>\n<h3>4. getFirst()</h3>\n<p>This method returns the first node of the linked list.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">getFirst() {\n    return this.head;\n}</code></pre></div>\n<h2>Summary</h2>\n<p>In this article, we discussed what a linked list is and how it can be implemented in JavaScript. We also discussed the different types of linked lists as well as their overall advantages and disadvantages.</p>\n<p>I hope you enjoyed reading it.</p>\n<p><em>Want to get notified when I publish a new article? <a href=\"https://mailchi.mp/69ea601a3f64/join-sarahs-mailing-list\">Click here</a>.</em></p>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>How to Learn Tree Data Structures the Codeless Way</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>The tree data structure can form some of the most useful and complex data structures in all of programming. In fact the tree is so powerful that I can make the bold claim: Once you understand trees you'll be able to understand many other data structures and algorithms with ease.</p>\n</blockquote>\n<hr>\n<p>The tree data structure can form some of the most useful and complex data structures in all of programming. In fact the tree is so powerful that I can make the bold claim:</p>\n<p><strong>Once you understand trees you'll be able to understand many other data structures and algorithms with ease.</strong></p>\n<p>There is one caveat. There are so many types of trees it may be impossible to know where to start! There are B-trees, Red Black Trees, Binary Trees, AVL Trees and many others. There are abundant choices and each seems valuable to learn.</p>\n<p>This presents a problem. As someone learning about trees you may find yourself asking, which tree data structure do I learn about first? Which tree is most important for me? There are so many, where do I start?</p>\n<p>Learning about trees is like learning about the numerous marvels in our current world. We have a lot of choices, in fact we may even have too much choice.</p>\n<p>Psychologists call it <strong>Overchoice</strong> or \"<strong>choice overload</strong>\", that is when faced with many options, people have a difficult choice deciding on what to do. I call it a beginning coder's worst nightmare.</p>\n<p>However there is no need to panic. From my knowledge of using the tree data structure, as with most things in life, the Pareto principle (what we call the 80/20 rule) applies.</p>\n<p>What this means is that as a programmer, 80% of cases where you will need to use trees will be covered by approximately 20% of the types of trees that you will attempt to learn.</p>\n<p>For this reason we will focus only on these 20% which I think are the most important trees you need to understand. Don't get me wrong here, I'm not saying don't learn other types of trees. I'm saying learn these first, then focus on the others to really get that edge.</p>\n<p>Even when you do figure out which tree data structure you want to learn, you are faced with another problem.</p>\n<p>There are a lot of resources out there that teach you about trees, however they all present you with some code in a particular language be it JavaScript, Java, Python or others as part of the explanation.</p>\n<p><strong>In this post I break that status quo and teach you about the essential tree data structures, and all without having you write a single line of code.</strong></p>\n<p>Join me on a journey into the world of trees, regardless of which programming language you are using, you will be able to learn all the basics you need to know about the tree data structure.</p>\n<h2>Getting to the Root of Trees</h2>\n<p>Let's get to the root of our discussion (pun intended). The way I like to explain trees is by relating it to something we are all familiar with, that of the biological tree. In case you are not familiar, let's look at one right now:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/photography-of-tree-1067333.jpg\" alt=\"output\"></p>\n<p>A Biological Tree</p>\n<p>Look at our tree, isn't it beautiful!? We see that a tree is a giant plant with a trunk, a branch and leaves. There are also roots hidden beneath the ground that also form part of the organism.</p>\n<p>A tree in computer science isn't so different. Let's look at one here:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/image-23.png\" alt=\"output\"></p>\n<p>A Computer Science Tree</p>\n<p>A computer science tree is very similar to a regular tree - it resembles an upside down biological tree a little doesn't it? It not only looks similar, but it also has parts that are named similar to our good ol' tangible tree.</p>\n<p>Before we learn about the types of trees though, there are a few facts about trees you must know.</p>\n<h3>Here are 5 facts you need to know about trees:</h3>\n<p>1. Each of the circles in the tree is called a node and each line is called an edge.</p>\n<p>2. The root node is the part of the tree that all the other parts are built upon.</p>\n<p>3. There are parent nodes connected to other nodes in the direction of the root, and child nodes connected in the direction away from the root.</p>\n<p>4. The last nodes of the trees are called leaves</p>\n<p>5. The process of navigating a tree is called traversal.</p>\n<p>If you like to see things visually, here is a diagram of the tree we looked at earlier identifying the parts:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/image-25.png\" alt=\"output\"></p>\n<p>Our Labelled Tree</p>\n<p>You should also know that when a tree is the child of a node, it is called a subtree. Look at the diagram above, the node labelled \"Parent\" along with its two child nodes can be classified as a subtree.</p>\n<p>Great, now you have an idea about basic trees. So let's dive into some of the most useful type of trees you will encounter.</p>\n<h2>The General Tree</h2>\n<p>The first type of tree we need to know about is the general tree. The general tree is what we call a superset. This is because all other types of trees are derived from the general tree.</p>\n<p>Trees are hierarchical in the way they store data. Whereas simpler data structures may store data in a linear manner (think an array), trees are non-linear.</p>\n<p>The general tree is the embodiment of a hierarchical tree structure as it has no restrictions on how many children each node can have, and has no restraint imposed on the hierarchy of the tree.</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/image-29.png\" alt=\"output\"></p>\n<p>Example of A General Tree</p>\n<h2>The Binary Tree</h2>\n<p>It is impossible to talk about trees without talking about the binary tree (okay not totally impossible, but you know what I mean).</p>\n<p>Simply put, a binary tree is a type of tree that has a restriction. In the binary tree, each parent can only be linked to two child nodes within the tree.</p>\n<p>There is one binary tree type that illustrates this best: the binary search tree. Trees you see aren't just empty circles connected by lines. Each of the node in the tree has a value associated with it and the entirety of the tree is a key-value structure.</p>\n<p>Binary search trees keep their keys sorted. They sort it like this: all the nodes are greater that the nodes in their left subtree, but are smaller than the nodes in their right subtree. Confused? Maybe a picture will help:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/image-26.png\" alt=\"output\"></p>\n<p>A Binary Search Tree</p>\n<p>Look closely at this tree and you will learn a little secret. In the binary tree the smallest node is located at the leftmost subtree stemming from the root node. Wanna guess where we can find the largest node?</p>\n<h2>Red-Black Tree</h2>\n<p>Let's look at a variant of the binary search tree that people tend to over-complicate. I'm talking about the Red-Black Tree.</p>\n<p>There are many cases of trees where data may be inserted and deleted. So variations of the binary search tree have been created which makes this constant insertion and deletion more efficient.</p>\n<p>The Red-Black tree is one such configuration of the binary search tree that makes the insertion and deletion process more efficient.</p>\n<p>The tree does this by having a bit that adds an attribute to the node. This attribute that is added on the node is color, and this color can be interpreted as red or black. Hence the name Red-Black tree.</p>\n<p>Let's look at how a Red-Black tree many be arranged:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/image-28.png\" alt=\"output\"></p>\n<p>A Red-Black Tree</p>\n<p>In the Red-Black tree, the root node is usually black and each red node has children that are black.</p>\n<p>If you made it this far, then congratulations! You already understand enough to make a foray into the world of tree data structures.</p>\n<h2>Where Are Trees Used?</h2>\n<p>At this point you may be wondering what trees are used for. That's a good question! Trees are used in many facets of development including use in:</p>\n<ol>\n<li>Databases</li>\n<li>Compilers</li>\n<li>Networking</li>\n<li>Heaps</li>\n<li>Machine Learning Algorithms</li>\n</ol>\n<p>There are countless uses for trees and the only limit in their use is the imagination of the designer.</p>\n<h2>Wrapping Up</h2>\n<p>In this post we began our journey into the world of the tree. Even though we covered some ground, we merely scrapped the surface of this vast and intricate data structure.</p>\n<p>We whet our appetite for tree data structures by covering what trees are and looked at their structure. We then discussed three common types of trees including general trees, binary trees and red-black trees. Finally we looked at some places where trees may be used.</p>\n<p>By the end of this post you should have a solid foundation to venture into the world of trees!</p>\n<h2>Where to Go Next?</h2>\n<p>Want to learn about trees and other data structures without writing a single line of code? The pick up the book \"Codeless Data Structures and Algorithms\", where you'll learn all you need to know about data structures and algorithms without writing a single line of code!</p>\n<p>We will not only greatly expand on what we learned, but we'll cover juicy topics not covered here like tree balancing, AVL trees, B-Trees, Heaps and a ton of topics in the realm of data structures and algorithms!</p>\n<p>You can read the book here:</p>\n<p>[</p>\n<p>Codeless Data Structures and Algorithms - Learn DSA Without Writing a Single Line of Code | Armstrong Subero | Apress</p>\n<p>This book brings you a new perspective on algorithms and data structures, completely code free. Learn about data structure algorithms (DSAs) without ever having to open your code editor, use a compiler, or look at an integrated development environment (IDE)....</p>\n<p>Armstrong SuberoSearch Menu Cart V Your cart is currently empty. Login AccountBookshelf Login Apress Access</p>\n<p><img src=\"https://images.springer.com/sgw/books/medium/9781484257241.jpg\" alt=\"output\"></p>\n<p>](<a href=\"https://www.apress.com/gp/book/9781484257241\">https://www.apress.com/gp/book/9781484257241</a>)</p>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>Big O Notation Explained with Examples</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>Big O notation is a way to describe the speed or complexity of a given algorithm. If your current project demands a predefined algorithm, it's important to understand how fast or slow it is compared to other options. What is Big O notation and how does it work?Simply put,</p>\n</blockquote>\n<hr>\n<p>Big O notation is a way to describe the speed or complexity of a given algorithm. If your current project demands a predefined algorithm, it's important to understand how fast or slow it is compared to other options.</p>\n<h2>What is Big O notation and how does it work?</h2>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/31781171-74c6b48a-b500-11e7-9626-f715b37b10f0.png\" alt=\"output\"></p>\n<p>Simply put, Big O notation tells you the number of operations an algorithm will make. It gets its name from the literal \"Big O\" in front of the estimated number of operations.</p>\n<p>What Big O notation doesn't tell you is the speed of the algorithm in seconds. There are way too many factors that influence the time an algorithm takes to run. Instead, you'll use Big O notation to compare different algorithms by the number of operations they make.</p>\n<h3>Big O establishes a worst-case run time</h3>\n<p>Imagine that you're a teacher with a student named Jane. You want to find her records, so you use a simple search algorithm to go through your school district's database.</p>\n<p>You know that simple search takes O(n) times to run. This means that, in the worst case, you'll have to search through every single record (represented by n) to find Jane's.</p>\n<p>But when you run the simple search, you find that Jane's records are the very first entry in the database. You don't have to look at every entry - you found it on your first try.</p>\n<p><em>Did this algorithm take O(n) time? Or did it take O(1) time because you found Jane's records on the first try?</em></p>\n<p>In this case, 0(1) is the best-case scenario - you were lucky that Jane's records were at the top. But Big O notation focuses on the worst-case scenario, which is 0(n) for simple search. It's a reassurance that simple search will never be slower than O(n) time.</p>\n<h3>Algorithm running times grow at different rates</h3>\n<p>Assume that it takes 1 millisecond to check each element in the school district's database.</p>\n<p>With simple search, if you have to check 10 entries, it will take 10 ms to run. But with the <em>binary search algorithm</em>, you only have to check 3 elements, which takes 3 ms to run.</p>\n<p>In most cases, the list or database you need to search will have hundreds or thousands of elements.</p>\n<p>If there are 1 billion elements, using simple search will take up to 1 billion ms, or 11 days. On the other hand, using binary search will take just 32 ms in the worst-case scenario:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/31781165-723a053c-b500-11e7-937c-7b33db281efe.png\" alt=\"output\"></p>\n<p>Clearly the run times for simple search and binary search don't grow at nearly the same rate. As the list of entries gets larger, binary search takes just a little more time to run. Simple search's run time grows exponentially as the list of entries increases.</p>\n<p>This is why knowing how the running time increases in relation to a list size is so important. And this is exactly where Big O notation is so useful.</p>\n<h3>Big O notation shows the number of operations</h3>\n<p>As mentioned above, Big O notation doesn't show the <em>time</em> an algorithm will run. Instead, it shows the number of operations it will perform. It tells you how fast an algorithm grows and lets you compare it with others.</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2020/03/31781175-768c208e-b500-11e7-9718-e632d1391e2d.png\" alt=\"output\"></p>\n<p>Here are some common algorithms and their run times in Big O notation:</p>\n<p>Big O notation</p>\n<p>Example algorithm</p>\n<p>O(log n)</p>\n<p>Binary search</p>\n<p>O(n)</p>\n<p>Simple search</p>\n<p>O(n * log n)</p>\n<p>Quicksort</p>\n<p>O(n2)</p>\n<p>Selection sort</p>\n<p>O(n!)</p>\n<p>Traveling salesperson</p>\n<p>Now you know enough to be dangerous with Big O notation. Get out there and start comparing algorithms.</p>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>Python Dictionary Data Structure Explained</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>Dictionary is one of the most used data structures in Python. A dictionary is an unordered collection of items and we usually have keys and values stored in a dictionary. Let us look at a few examples for how the dictionary is usually used. # dictionary declaration 1 dict1 = dict() # dictionary</p>\n</blockquote>\n<hr>\n<p><img src=\"https://cdn-media-2.freecodecamp.org/w1280/5f9c9e33740569d1a4ca3bdc.jpg\" alt=\"Python Dictionary Data Structure Explained\"></p>\n<p>Dictionary is one of the most used data structures in Python. A dictionary is an unordered collection of items and we usually have keys and values stored in a dictionary. Let us look at a few examples for how the dictionary is usually used.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">dict1 = dict()\n\n\ndict2 = {}\n\n\n\nkey = \"X\"\nvalue = \"Y\"\ndict1[key] = value\n\n\n\ndict1[key] = dict2</code></pre></div>\n<p>Let's now look at some retrieval ways.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">value = dict1[key]\n\n\n\nvalue = dict1[\"random\"]</code></pre></div>\n<h3><strong>Avoiding KeyError: Use .get function</strong></h3>\n<p>In case the given key does not exist in the dictionary, Python will throw a <code class=\"language-text\">KeyError</code>. There is a simple workaround for this. Let's look at how we can avoid <code class=\"language-text\">KeyError</code> using the in-built <code class=\"language-text\">.get</code> function for dictionaries.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">dict_ = {}\n\n\nrandom_key = \"random\"\n\n\n\n\nif random_key in dict_:\n  print(dict_[random_key])\nelse:\n  print(\"Key = {} doesn't exist in the dictionary\".format(dict_))</code></pre></div>\n<p>A lot of times we are ok getting a default value when the key doesn't exist. For e.g. when building a counter. There is a better way to get default values from the dictionary in case of missing keys rather than relying on standard <code class=\"language-text\">if-else</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">arr = [1,2,3,1,2,3,4,1,2,1,4,1,2,3,1]\n\nfreq = {}\n\nfor item in arr:\n\n  freq[item] = freq.get(item, 0) + 1</code></pre></div>\n<p>So, the <code class=\"language-text\">get(&lt;key>, &lt;defaultval>)</code> is a handy operation for retrieving the default value for any given key from the dictionary. The problem with this method comes when we want to deal with mutable data structures as values e.g. <code class=\"language-text\">list</code> or <code class=\"language-text\">set</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">dict_ = {}\n\n\nrandom_key = \"random\"\n\ndict_[random_key] = dict_.get(random_key, []).append(\"Hello World!\")\nprint(dict_)\n\ndict_ = {}\ndict_[random_key] = dict_.get(random_key, set()).add(\"Hello World!\")\nprint(dict_)</code></pre></div>\n<p>Did you see the problem?</p>\n<p>The new <code class=\"language-text\">set</code> or the <code class=\"language-text\">list</code> doesn't get assigned to the dictionary's key. We should assign a new <code class=\"language-text\">list</code> or a <code class=\"language-text\">set</code> to the key in case of missing value and then <code class=\"language-text\">append</code> or <code class=\"language-text\">add</code> respectively. Ley's look at an example for this.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">dict_ = {}\ndict_[random_key] = dict_.get(random_key, set())\ndict_[random_key].add(\"Hello World!\")\nprint(dict_)</code></pre></div>\n<h3><strong>Avoiding KeyError: Use defaultdict</strong></h3>\n<p>This works most of the times. However, there is a better way to do this. A more <code class=\"language-text\">pythonic</code> way. The <code class=\"language-text\">defaultdict</code> is a subclass of the built-in dict class. The <code class=\"language-text\">defaultdict</code> simply assigns the default value that we specify in case of a missing key. So, the two steps:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\ndict_<span class=\"token punctuation\">[</span>random_key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> dict_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>random_key<span class=\"token punctuation\">,</span> <span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndict_<span class=\"token punctuation\">[</span>random_key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello World!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>can now be combined into one single step. For e.g.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from collections import defaultdict\n\n\nrandom_key = \"random_key\"\n\n\nlist_dict_ = defaultdict(list)\n\n\nset_dict_ = defaultdict(set)\n\n\nint_dict_ = defaultdict(int)\n\nlist_dict_[random_key].append(\"Hello World!\")\nset_dict_[random_key].add(\"Hello World!\")\nint_dict_[random_key] += 1\n\n\"\"\"\n  defaultdict(&lt;class 'list'>, {'random_key': ['Hello World!']})\n  defaultdict(&lt;class 'set'>, {'random_key': {'Hello World!'}})\n  defaultdict(&lt;class 'int'>, {'random_key': 1})\n\"\"\"\nprint(list_dict_, set_dict_, int_dict_)</code></pre></div>\n<p><a href=\"https://docs.python.org/2/library/collections.html\">Official Docs</a></p>\n<hr>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>Sign in to freeCodeCamp.org | freeCodeCamp.org</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>Authentication landing page for freecodecamp.org</p>\n</blockquote>\n<hr>\n<h3>or</h3>\n<p>freeCodeCamp is free and your account is private by default. We use your email address to store your curriculum progress. By continuing, you indicate that you have read and agree to freeCodeCamp.org's <a href=\"https://www.freecodecamp.org/terms\">Terms of Service</a> and <a href=\"https://www.freecodecamp.org/privacy\">Privacy Policy</a>.</p>\n<hr>\n<hr>\n<h1>JavaScript Hash Table - Associative Array Hashing in JS</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>Hash Tables are a data structure that allow you to create a list of paired values. You can then retrieve a certain value by using the key for that value, which you put into the table beforehand. A Hash Table transforms a key into an integer index using a hash</p>\n</blockquote>\n<hr>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/size/w2000/2021/05/JavaScript-Hash-Table.png\" alt=\"JavaScript Hash Table  - Associative Array Hashing in JS\"></p>\n<p>Hash Tables are a data structure that allow you to create a list of paired values. You can then retrieve a certain value by using the key for that value, which you put into the table beforehand.</p>\n<p>A Hash Table transforms a key into an integer index using a hash function, and the index will decide where to store the key/value pair in memory:</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/2021/05/g983.jpg\" alt=\"output\"></p>\n<p>Hash table for storing phone books (from <a href=\"https://en.wikipedia.org/wiki/Hash_table\">Wikipedia</a>)</p>\n<p>You'll commonly use a Hash Table because of its fast search, insertion, and delete operations:</p>\n<p>Hash Table time complexity in Big O Notation</p>\n<p>Algorithm</p>\n<p>Average</p>\n<p>Worst case</p>\n<p>Space</p>\n<p>O(n)</p>\n<p>O(n)</p>\n<p>Search</p>\n<p>O(1)</p>\n<p>O(n)</p>\n<p>Insert</p>\n<p>O(1)</p>\n<p>O(n)</p>\n<p>Delete</p>\n<p>O(1)</p>\n<p>O(n)</p>\n<p>Source from <a href=\"https://en.wikipedia.org/wiki/Hash_table\">Wikipedia</a></p>\n<p>This tutorial will help you understand Hash Table implementation in JavaScript as well as how you can build your own Hash Table class.</p>\n<p>First, let's look at JavaScript's <code class=\"language-text\">Object</code> and <code class=\"language-text\">Map</code> classes.</p>\n<h2>How to Use Hash Tables with Object and Map Classes in JavaScript</h2>\n<p>The most common example of a Hash Table in JavaScript is the <code class=\"language-text\">Object</code> data type, where you can pair the object's property value with a property key.</p>\n<p>In the following example, the key <code class=\"language-text\">Nathan</code> is paired with the phone number value of <code class=\"language-text\">\"555-0182\"</code> and the key <code class=\"language-text\">Jane</code> is paired with the value <code class=\"language-text\">\"315-0322\"</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">Nathan</span><span class=\"token operator\">:</span> <span class=\"token string\">'555-0182'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">Jane</span><span class=\"token operator\">:</span> <span class=\"token string\">'315-0322'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>JavaScript object is an example of Hash Table implementation</p>\n<p>But JavaScript's <code class=\"language-text\">Object</code> type is a special kind of Hash Table implementation for two reasons:</p>\n<ul>\n<li>It has properties added by the <code class=\"language-text\">Object</code> class. Keys you input may conflict and overwrite default properties inherited from the class.</li>\n<li>The size of the Hash Table is not tracked. You need to manually count how many properties are defined by the programmer instead of inherited from the prototype.</li>\n</ul>\n<p>For example, the <code class=\"language-text\">Object</code> prototype has the <code class=\"language-text\">hasOwnProperty()</code> method which allows you to check if a property is not inherited:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nobj<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Nathan'</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>JavaScript object inherited method call example</p>\n<p>JavaScript doesn't block an attempt to overwrite the <code class=\"language-text\">hasOwnProperty()</code> method, which may cause an error like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nobj<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Nathan'</span><span class=\"token punctuation\">;</span>\nobj<span class=\"token punctuation\">.</span>hasOwnProperty <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>JavaScript object inherited property gets overwritten</p>\n<p>To handle these shortcomings, JavaScript created another implementation of the Hash Table data structure which is called <code class=\"language-text\">Map</code></p>\n<p>Just like <code class=\"language-text\">Object</code>, <code class=\"language-text\">Map</code> allows you to store key-value pairs inside the data structure. Here's an example of <code class=\"language-text\">Map</code> in action:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> collection <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ncollection<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Nathan'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'555-0182'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ncollection<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Jane'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'555-0182'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>collection<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Nathan'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>collection<span class=\"token punctuation\">.</span>size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>JavaScript Map class is another implementation of Hash Table</p>\n<p>Unlike the <code class=\"language-text\">Object</code> type, <code class=\"language-text\">Map</code> requires you to use the <code class=\"language-text\">set()</code> and <code class=\"language-text\">get()</code> methods to define and retrieve any key-pair values that you want to be added to the data structure.</p>\n<p>You also can't overwrite <code class=\"language-text\">Map</code> inherited properties. For example, the following code tried to overwrite the <code class=\"language-text\">size</code> property value to <code class=\"language-text\">false</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> collection <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ncollection<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Nathan'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'555-0182'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ncollection<span class=\"token punctuation\">[</span><span class=\"token string\">'size'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>collection<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'size'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>collection<span class=\"token punctuation\">.</span>size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Map type property can't be overwritten</p>\n<p>As you can see from the code above, you can't add a new entry to the <code class=\"language-text\">Map</code> object without using the <code class=\"language-text\">set()</code> method.</p>\n<p>The <code class=\"language-text\">Map</code> data structure is also iterable, which means you can loop over the data as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> myMap <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nmyMap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Nathan'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'555-0182'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmyMap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Jane'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'315-0322'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span> <span class=\"token keyword\">of</span> myMap<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>key<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>value<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Iterating through a Map object</p>\n<p>Now that you've learned how JavaScript implements Hash Tables in the form of <code class=\"language-text\">Object</code> and <code class=\"language-text\">Map</code> data structures, let's see how you can create your own Hash Table implementation next.</p>\n<h2>How to Implement a Hash Table Data Structure in JavaScript</h2>\n<p>Although JavaScript already has two Hash Table implementations, writing your own Hash Table implementation is one of the most common JavaScript interview questions.</p>\n<p>You can implement a Hash Table in JavaScript in three steps:</p>\n<ul>\n<li>Create a <code class=\"language-text\">HashTable</code> class with <code class=\"language-text\">table</code> and <code class=\"language-text\">size</code> initial properties</li>\n<li>Add a <code class=\"language-text\">hash()</code> function to transform keys into indices</li>\n<li>Add the <code class=\"language-text\">set()</code> and <code class=\"language-text\">get()</code> methods for adding and retrieving key/value pairs from the table.</li>\n</ul>\n<p>Alright, let's start with creating the <code class=\"language-text\">HashTable</code> class. The code below will create a <code class=\"language-text\">table</code> of buckets with the size of <code class=\"language-text\">127</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">HashTable</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">127</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>HashTable class initial properties</p>\n<p>All your key/value pairs will be stored inside the <code class=\"language-text\">table</code> property.</p>\n<h3>How to write the hash() method</h3>\n<p>Next, you need to create the <code class=\"language-text\">hash()</code> method that will accept a <code class=\"language-text\">key</code> value and transform it into an index.</p>\n<p>A simple way to create the hash would be to sum the ASCII code of the characters in the key using the <code class=\"language-text\">charCodeAt()</code> method as follows. Note that the method is named using <code class=\"language-text\">_</code> to indicate that it's a private class:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> key<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    hash <span class=\"token operator\">+=</span> key<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> hash<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>But since the <code class=\"language-text\">HashTable</code> class only has 127 buckets, this means that the <code class=\"language-text\">_hash()</code> method must return a number between <code class=\"language-text\">0 and 127</code>.</p>\n<p>To ensure that the hash value doesn't exceed the bucket size, you need to use the modulo operator as shown below:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> key<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    hash <span class=\"token operator\">+=</span> key<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> hash <span class=\"token operator\">%</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now that you have the <code class=\"language-text\">_hash()</code> method completed, it's time to write the <code class=\"language-text\">set()</code> and <code class=\"language-text\">get()</code> methods.</p>\n<h3>How to write the set() method</h3>\n<p>To set the key/value pair in your Hash Table, you need to write a <code class=\"language-text\">set()</code> method that accepts <code class=\"language-text\">(key, value)</code> as its parameters:</p>\n<ul>\n<li>The <code class=\"language-text\">set()</code> method will call the <code class=\"language-text\">_hash()</code> method to get the <code class=\"language-text\">index</code> value.</li>\n<li>The <code class=\"language-text\">[key, value]</code> pair will be assigned to the <code class=\"language-text\">table</code> at the specified <code class=\"language-text\">index</code></li>\n<li>Then, the <code class=\"language-text\">size</code> property will be incremented by one</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">set(key, value) {\n  const index = this._hash(key);\n  this.table[index] = [key, value];\n  this.size++;\n}</code></pre></div>\n<p>Now that the <code class=\"language-text\">set()</code> method is complete, let's write the <code class=\"language-text\">get()</code> method to retrieve a value by its key.</p>\n<h3>How to write the get() method</h3>\n<p>To get a certain value from the Hash Table, you need to write a <code class=\"language-text\">get()</code> method that accepts a <code class=\"language-text\">key</code> value as its parameter:</p>\n<ul>\n<li>The method will call the <code class=\"language-text\">_hash()</code> method to once again retrieve the table <code class=\"language-text\">index</code></li>\n<li>Return the value stored at <code class=\"language-text\">table[index]</code></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">get(key) {\n  const index = this._hash(key);\n  return this.table[index];\n}</code></pre></div>\n<p>This way, the <code class=\"language-text\">get()</code> method will return either the key/value pair back or <code class=\"language-text\">undefined</code> when there is no key/value pair stored in the specified <code class=\"language-text\">index</code>.</p>\n<p>So far so good. Let's add another method to delete key/value pair from the Hash Table next.</p>\n<h3>How to write the remove() method</h3>\n<p>To delete a key/value pair from the Hash Table, you need to write a <code class=\"language-text\">remove()</code> method that accepts a <code class=\"language-text\">key</code> value as its parameter:</p>\n<ul>\n<li>Retrieve the right <code class=\"language-text\">index</code> using the <code class=\"language-text\">_hash()</code> method</li>\n<li>Check if the <code class=\"language-text\">table[index]</code> has a truthy value and the <code class=\"language-text\">length</code> property is greater than zero. Assign the <code class=\"language-text\">undefined</code> value to the right <code class=\"language-text\">index</code> and decrement the <code class=\"language-text\">size</code> property by one if it is.</li>\n<li>If not, simply return <code class=\"language-text\">false</code></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">remove(key) {\n  const index = this._hash(key);\n\n  if (this.table[index] &amp;&amp; this.table[index].length) {\n    this.table[index] = undefined;\n    this.size--;\n    return true;\n  } else {\n    return false;\n  }\n}</code></pre></div>\n<p>With that, you now have a working <code class=\"language-text\">remove()</code> method. Let's see if the <code class=\"language-text\">HashTable</code> class works properly.</p>\n<h2>How to Test the Hash Table Implementation</h2>\n<p>It's time to test the Hash Table implementation. Here's the full code for the Hash Table implementation again:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">HashTable</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">127</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> key<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            hash <span class=\"token operator\">+=</span> key<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> hash <span class=\"token operator\">%</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">set</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> target <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>target<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The HashTable implementation in JavaScript</p>\n<p>To test the <code class=\"language-text\">HashTable</code> class, I'm going to create a new instance of the <code class=\"language-text\">class</code> and set some key/value pairs as shown below. The key/value pairs below are just arbitrary number values paired with country names without any special meaning:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> ht <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">HashTable</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nht<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Canada'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nht<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'France'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nht<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">110</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Testing HashTable set() method</p>\n<p>Then, let's try to retrieve them using the <code class=\"language-text\">get()</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ht<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Canada'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ht<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'France'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ht<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Testing HashTable get() method</p>\n<p>Finally, let's try to delete one of these values with the <code class=\"language-text\">remove()</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ht<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ht<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Testing HashTable remove() method</p>\n<p>Alright, all the methods are working as expected. Let's try another insertion with a new <code class=\"language-text\">HashTable</code> instance and retrieve those values:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> ht <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">HashTable</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nht<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">110</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nht<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'ǻ'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">192</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ht<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ht<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'ǻ'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Hash Table index collision</p>\n<p>Oops! Looks like we got into some trouble here. 😨</p>\n<h2>How to Handle Index Collision</h2>\n<p>Sometimes, the hash function in a Hash Table may return the same <code class=\"language-text\">index</code> number. In the test case above, the string <code class=\"language-text\">\"Spain\"</code> and <code class=\"language-text\">\"ǻ\"</code> <strong>both return the same <code class=\"language-text\">hash</code> value</strong> because the number <code class=\"language-text\">507</code> is the sum of both of their ASCII code.</p>\n<p>The same <code class=\"language-text\">hash</code> value will cause the index to <em>collide</em>, overwriting the previous entry with the new one.</p>\n<p>Right now, the data stored in our Hash Table implementation looks as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">110</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'France'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">100</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To handle the <code class=\"language-text\">index</code> number collision, you need to store the key/value pair in a second array so that the end result looks as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">[</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">110</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token string\">'ǻ'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">192</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token string\">'France'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">100</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To create the second array, you need to update the <code class=\"language-text\">set()</code> method so that it will:</p>\n<ul>\n<li>Look to the <code class=\"language-text\">table[index]</code> and loop over the array values.</li>\n<li>If the key at one of the arrays is equal to the <code class=\"language-text\">key</code> passed to the method, replace the value at index <code class=\"language-text\">1</code> and stop any further execution with the <code class=\"language-text\">return</code> statement.</li>\n<li>If no matching <code class=\"language-text\">key</code> is found, push a new array of key and value to the second array.</li>\n<li>Else, initialize a new array and push the key/value pair to the specified <code class=\"language-text\">index</code></li>\n<li>Whenever a <code class=\"language-text\">push()</code> method is called, increment the <code class=\"language-text\">size</code> property by one.</li>\n</ul>\n<p>The complete <code class=\"language-text\">set()</code> method code will be as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">set</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Next, update the <code class=\"language-text\">get()</code> method so that it will also check the second-level array with a <code class=\"language-text\">for</code> loop and return the right key/value pair:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">get</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> target <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>target<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>target<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>target<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Finally, you need to update the <code class=\"language-text\">remove()</code> method so that it will loop over the second-level array and remove the array with the right <code class=\"language-text\">key</code> value using the <code class=\"language-text\">splice()</code> method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>With that, your <code class=\"language-text\">HashTable</code> class will be able to avoid any index number collision and store the key/value pair inside the second-level array.</p>\n<p>As a bonus, let's add a <code class=\"language-text\">display()</code> method that will display all key/value pairs stored in the Hash Table. You just need to use the <code class=\"language-text\">forEach()</code> method to iterate over the table and <code class=\"language-text\">map()</code> the values to a string as shown below:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token function\">display</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">values<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> chainedValues <span class=\"token operator\">=</span> values<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>\n      <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">[ </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>key<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>value<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> ]</span><span class=\"token template-punctuation string\">`</span></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>index<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>chainedValues<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Here's the complete <code class=\"language-text\">HashTable</code> class code again with the collision avoidance applied for your reference:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">HashTable</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">127</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> key<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            hash <span class=\"token operator\">+=</span> key<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> hash <span class=\"token operator\">%</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">set</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">key</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>size<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">display</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>table<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">values<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> chainedValues <span class=\"token operator\">=</span> values<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">[ </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>key<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>value<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> ]</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>index<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>chainedValues<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Complete HashTable class implementation</p>\n<p>You can test the implementation by creating a new <code class=\"language-text\">HashTable</code> instance and do some insertion and deletion:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> ht <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">HashTable</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nht<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'France'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">111</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nht<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">150</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nht<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'ǻ'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">192</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nht<span class=\"token punctuation\">.</span><span class=\"token function\">display</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>ht<span class=\"token punctuation\">.</span>size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nht<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Spain'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nht<span class=\"token punctuation\">.</span><span class=\"token function\">display</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Another HashTable test</p>\n<p>Now there's no collision inside the <code class=\"language-text\">HashTable</code> instance. Great work!</p>\n<h2>Conclusion</h2>\n<p>In this tutorial, you've learned what a Hash Table is and how JavaScript uses it to create the <code class=\"language-text\">Object</code> and <code class=\"language-text\">Map</code> data structure.</p>\n<p>You've also learned how to implement your own <code class=\"language-text\">HashTable</code> class as well as how to prevent the Hash Table's key indices from colliding by using the chaining technique.</p>\n<p>By using a Hash Table data structure, you will be able to create an associative array with fast search, insertion, and delete operations. 😉</p>\n<h2><strong>**</strong>**<strong>**</strong>Thanks for reading this tutorial<strong>**</strong>**<strong>**</strong></h2>\n<p>If you want to learn more about JavaScript, you may want to check out my site at sebhastian.com, where I have published <a href=\"https://sebhastian.com/javascript-tutorials/\">over 100 tutorials about programming with JavaScript</a>, all using easy-to-understand explanations and code examples.</p>\n<p>The tutorials include String manipulation, Date manipulation, Array and Object methods, JavaScript algorithm solutions, and many more.</p>\n<hr>\n<hr>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>Binary Search Tree Data Structure Explained with Examples</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>A tree is a data structure composed of nodes that has the following characteristics: Each tree has a root node (at the top) having some value.The root node has zero or more child nodes.Each child node has zero or more child nodes, and so on. This create a</p>\n</blockquote>\n<hr>\n<p><img src=\"https://cdn-media-2.freecodecamp.org/w1280/5f9c9e86740569d1a4ca3d95.jpg\" alt=\"Binary Search Tree Data Structure Explained with Examples\"></p>\n<p>A tree is a data structure composed of nodes that has the following characteristics:</p>\n<ol>\n<li>Each tree has a root node (at the top) having some value.</li>\n<li>The root node has zero or more child nodes.</li>\n<li>Each child node has zero or more child nodes, and so on. This create a subtree in the tree. Every node has it's own subtree made up of his children and their children, etc. This means that every node on its own can be a tree.</li>\n</ol>\n<p>A binary search tree (BST) adds these two characteristics:</p>\n<ol>\n<li>Each node has a maximum of up to two children.</li>\n<li>For each node, the values of its left descendent nodes are less than that of the current node, which in turn is less than the right descendent nodes (if any).</li>\n</ol>\n<p>The BST is built up on the idea of the <a href=\"https://guide.freecodecamp.org/algorithms/search-algorithms/binary-search\">binary search</a> algorithm, which allows for fast lookup, insertion and removal of nodes. The way that they are set up means that, on average, each comparison allows the operations to skip about half of the tree, so that each lookup, insertion or deletion takes time proportional to the logarithm of the number of items stored in the tree, <code class=\"language-text\">O(log n)</code>.</p>\n<p>However, some times the worst case can happen, when the tree isn't balanced and the time complexity is <code class=\"language-text\">O(n)</code> for all three of these functions. That is why self-balancing trees (AVL, red-black, etc.) are a lot more effective than the basic BST.</p>\n<p>*<strong>*Worst case scenario example:**</strong> This can happen when you keep adding nodes that are <em>always</em> larger than the node before (it's parent), the same can happen when you always add nodes with values lower than their parents.</p>\n<h2><strong>Basic operations on a BST</strong></h2>\n<ul>\n<li>Create: creates an empty tree.</li>\n<li>Insert: insert a node in the tree.</li>\n<li>Search: Searches for a node in the tree.</li>\n<li>Delete: deletes a node from the tree.</li>\n</ul>\n<h3>Create</h3>\n<p>Initially an empty tree without any nodes is created. The variable/identifier which must point to the root node is initialized with a <code class=\"language-text\">NULL</code> value.</p>\n<h3>Search</h3>\n<p>You always start searching the tree at the root node and go down from there. You compare the data in each node with the one you are looking for. If the compared node doesn't match then you either proceed to the right child or the left child, which depends on the outcome of the following comparison: If the node that you are searching for is lower than the one you were comparing it with, you proceed to to the left child, otherwise (if it's larger) you go to the right child. Why? Because the BST is structured (as per its definition), that the right child is always larger than the parent and the left child is always lesser.</p>\n<h3>Insert</h3>\n<p>It is very similar to the search function. You again start at the root of the tree and go down recursively, searching for the right place to insert our new node, in the same way as explained in the search function. If a node with the same value is already in the tree, you can choose to either insert the duplicate or not. Some trees allow duplicates, some don't. It depends on the certain implementation.</p>\n<h3>Delete</h3>\n<p>There are 3 cases that can happen when you are trying to delete a node. If it has,</p>\n<ol>\n<li>No subtree (no children): This one is the easiest one. You can simply just delete the node, without any additional actions required.</li>\n<li>One subtree (one child): You have to make sure that after the node is deleted, its child is then connected to the deleted node's parent.</li>\n<li>Two subtrees (two children): You have to find and replace the node you want to delete with its successor (the letfmost node in the right subtree).</li>\n</ol>\n<p>The time complexity for creating a tree is <code class=\"language-text\">O(1)</code>. The time complexity for searching, inserting or deleting a node depends on the height of the tree <code class=\"language-text\">h</code>, so the worst case is <code class=\"language-text\">O(h)</code>.</p>\n<h3>Predecessor of a node</h3>\n<p>Predecessors can be described as the node that would come right before the node you are currently at. To find the predecessor of the current node, look at the right-most/largest leaf node in the left subtree.</p>\n<h3>Successor of a node</h3>\n<p>Successors can be described as the node that would come right after the node you are currently at. To find the successor of the current node, look at the left-most/smallest leaf node in the right subtree.</p>\n<h2><strong>Special types of BT</strong></h2>\n<ul>\n<li>Heap</li>\n<li>Red-black tree</li>\n<li>B-tree</li>\n<li>Splay tree</li>\n<li>N-ary tree</li>\n<li>Trie (Radix tree)</li>\n</ul>\n<h2>Runtime</h2>\n<h3>*<strong>*Data structure: Array**</strong></h3>\n<ul>\n<li>Worst-case performance: <code class=\"language-text\">O(log n)</code></li>\n<li>Best-case performance: <code class=\"language-text\">O(1)</code></li>\n<li>Average performance: <code class=\"language-text\">O(log n)</code></li>\n<li>Worst-case space complexity: <code class=\"language-text\">O(1)</code></li>\n</ul>\n<p>Where <code class=\"language-text\">n</code> is the number of nodes in the BST.</p>\n<h2>Implementation of BST</h2>\n<p>Here's a definiton for a BST node having some data, referencing to its left and right child nodes.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">struct node {\n   int data;\n   struct node *leftChild;\n   struct node *rightChild;\n};</code></pre></div>\n<h3>Search Operation</h3>\n<p>Whenever an element is to be searched, start searching from the root node. Then if the data is less than the key value, search for the element in the left subtree. Otherwise, search for the element in the right subtree. Follow the same algorithm for each node.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">struct node* search(int data){\n   struct node *current = root;\n   printf(\"Visiting elements: \");\n\n   while(current->data != data){\n\n      if(current != NULL) {\n         printf(\"%d \",current->data);\n\n\n         if(current->data > data){\n            current = current->leftChild;\n         }\n         else {\n            current = current->rightChild;\n         }\n\n\n         if(current == NULL){\n            return NULL;\n         }\n      }\n   }\n   return current;\n}</code></pre></div>\n<h3>Insert Operation</h3>\n<p>Whenever an element is to be inserted, first locate its proper location. Start searching from the root node, then if the data is less than the key value, search for the empty location in the left subtree and insert the data. Otherwise, search for the empty location in the right subtree and insert the data.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">void insert(int data) {\n   struct node *tempNode = (struct node*) malloc(sizeof(struct node));\n   struct node *current;\n   struct node *parent;\n\n   tempNode->data = data;\n   tempNode->leftChild = NULL;\n   tempNode->rightChild = NULL;\n\n\n   if(root == NULL) {\n      root = tempNode;\n   } else {\n      current = root;\n      parent = NULL;\n\n      while(1) {\n         parent = current;\n\n\n         if(data &lt; parent->data) {\n            current = current->leftChild;\n\n\n            if(current == NULL) {\n               parent->leftChild = tempNode;\n               return;\n            }\n         }\n         else {\n            current = current->rightChild;\n\n\n            if(current == NULL) {\n               parent->rightChild = tempNode;\n               return;\n            }\n         }\n      }\n   }\n}</code></pre></div>\n<p>Binary search trees (BSTs) also give us quick access to predecessors and successors. Predecessors can be described as the node that would come right before the node you are currently at.</p>\n<ul>\n<li>To find the predecessor of the current node, look at the rightmost/largest leaf node in the left subtree. Successors can be described as the node that would come right after the node you are currently at.</li>\n<li>To find the successor of the current node, look at the leftmost/smallest leaf node in the right subtree.</li>\n</ul>\n<h2>Let's look at a couple of procedures operating on trees.</h2>\n<p>Since trees are recursively defined, it's very common to write routines that operate on trees that are themselves recursive.</p>\n<p>So for instance, if we want to calculate the height of a tree, that is the height of a root node, We can go ahead and recursively do that, going through the tree. So we can say:</p>\n<ul>\n<li>For instance, if we have a nil tree, then its height is a 0.</li>\n<li>Otherwise, We're 1 plus the maximum of the left child tree and the right child tree.</li>\n</ul>\n<p>So if we look at a leaf for example, that height would be 1 because the height of the left child is nil, is 0, and the height of the nil right child is also 0. So the max of that is 0, then 1 plus 0.</p>\n<h3>Height(tree) algorithm</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if tree = nil:\nreturn 0\nreturn 1 + Max(Height(tree.left),Height(tree.right))</code></pre></div>\n<h3>Here is the code in C++</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">int maxDepth(struct node* node)\n{\n    if (node==NULL)\n        return 0;\n   else\n   {\n       int rDepth = maxDepth(node->right);\n       int lDepth = maxDepth(node->left);\n\n       if (lDepth > rDepth)\n       {\n           return(lDepth+1);\n       }\n       else\n       {\n            return(rDepth+1);\n       }\n   }\n}</code></pre></div>\n<p>We could also look at calculating the size of a tree that is the number of nodes.</p>\n<ul>\n<li>Again, if we have a nil tree, we have zero nodes.</li>\n</ul>\n<p>Otherwise, we have the number of nodes in the left child plus 1 for ourselves plus the number of nodes in the right child. So 1 plus the size of the left tree plus the size of the right tree.</p>\n<h3>Size(tree) algorithm</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">if tree = nil\nreturn 0\nreturn 1 + Size(tree.left) + Size(tree.right)</code></pre></div>\n<h3>Here is the code in C++</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">int treeSize(struct node* node)\n{\n    if (node==NULL)\n        return 0;\n    else\n        return 1+(treeSize(node->left) + treeSize(node->right));\n}</code></pre></div>\n<h3><strong>Relevant videos on freeCodeCamp YouTube channel</strong></h3>\n<ul>\n<li><a href=\"https://youtu.be/5cU1ILGy6dM\">Binary Search Tree</a></li>\n<li><a href=\"https://youtu.be/Aagf3RyK3Lw\">Binary Search Tree: Traversal and Height</a></li>\n</ul>\n<h2>Following are common types of Binary Trees:</h2>\n<p>Full Binary Tree/Strict Binary Tree: A Binary Tree is full or strict if every node has exactly 0 or 2 children.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">           18\n       /       \\\n     15         30\n    /  \\        /  \\\n  40    50    100   40</code></pre></div>\n<p>In Full Binary Tree, number of leaf nodes is equal to number of internal nodes plus one.</p>\n<p>Complete Binary Tree: A Binary Tree is complete Binary Tree if all levels are completely filled except possibly the last level and the last level has all keys as left as possible</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">           18\n       /       \\\n     15         30\n    /  \\        /  \\\n  40    50    100   40\n /  \\   /\n8   7  9</code></pre></div>\n<hr>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>Learn Data Structures from a Google Engineer - A Free 8-hour Course</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>Learn and master the most common data structures in this free 8-hour video course from Google engineer William Fiset. This course teaches data structures using animations to represent the data structures visually. And it's designed with beginners in mind. You'll learn how to code various data structures and combine them</p>\n</blockquote>\n<hr>\n<p><a href=\"https://www.freecodecamp.org/news\"><img src=\"https://www.freecodecamp.org/news/content/images/2019/11/fcc_primary_large_24X210.svg\" alt=\"freeCodeCamp.org\"></a></p>\n<p>[</p>\n<p>Learn to code — free 3,000-hour curriculum</p>\n<p>](<a href=\"https://www.freecodecamp.org/\">https://www.freecodecamp.org/</a>)</p>\n<p><img src=\"https://www.freecodecamp.org/news/content/images/size/w2000/2020/09/datastructures8.png\" alt=\"Learn Data Structures from a Google Engineer - A Free 8-hour Course\"></p>\n<p>Learn and master the most common data structures in this free 8-hour video course from Google engineer William Fiset.</p>\n<p>This course teaches data structures using animations to represent the data structures visually. And it's designed with beginners in mind.</p>\n<p>You'll learn how to code various data structures and combine them through Finet's step-by-step instructions.</p>\n<p>Each data structure comes with working source code to help solidify your understanding. The code snippets are in Java, but if you know JavaScript or Python you will probably be able to understand these just fine on a conceptual level.</p>\n<p>You will learn about these data structures:</p>\n<ul>\n<li>Static and dynamic arrays</li>\n<li>Singly and doubly linked lists</li>\n<li>Stacks</li>\n<li>Queues</li>\n<li>Heaps/Priority Queues</li>\n<li>Binary Trees/Binary Search Trees</li>\n<li>Union find/Disjoint Set</li>\n<li>Hash tables</li>\n<li>Fenwick trees</li>\n<li>AVL trees</li>\n</ul>\n<p>You can watch the <a href=\"https://www.youtube.com/watch?v=RBSGKlAvoiM\">full video on the freeCodeCamp.org YouTube channel</a> (8 hour watch). As always, it's free, and there are no ads to interrupt you.</p>\n<hr>\n<hr>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>\n<hr>\n<hr>\n<h1>Data Structures Explained with Examples - Linked List</h1>\n<blockquote>\n<h2>Excerpt</h2>\n<p>Just like a garland is made with flowers, a linked list is made up of nodes. We call every flower on this particular garland to be a node. And each of the node points to the next node in this list as well as it has data (here it is</p>\n</blockquote>\n<hr>\n<p>Just like a garland is made with flowers, a linked list is made up of nodes. We call every flower on this particular garland to be a node. And each of the node points to the next node in this list as well as it has data (here it is type of flower).</p>\n<h2><strong>Types</strong></h2>\n<h3>Singly Linked List</h3>\n<p>Singly linked lists contain nodes which have a <code class=\"language-text\">data</code> field as well as a <code class=\"language-text\">next</code> field, which points to the next node in the sequence. Operations that can be performed on singly linked lists are insertion, deletion and traversal.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">   head\n    |\n    |\n  +-----+--+      +-----+--+      +-----+------+\n  |  1  |o----->  |  2  |o----->  |  3  | NULL |\n  +-----+--+      +-----+--+      +-----+------+</code></pre></div>\n<p>Internal implementation of CPython, the frames and evaluated variables are kept on a stack.</p>\n<p>For this we need to iterate only forward aur get the head, therefore singly linked-list is used.</p>\n<h3>Doubly Linked List</h3>\n<p>Doubly linked lists contain node which have <code class=\"language-text\">data</code> field, <code class=\"language-text\">next</code> field and another link field <code class=\"language-text\">prev</code> pointing to the previous node in the sequence.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">          head\n           |\n           |\n  +------+-----+--+    +--+-----+--+       +-----+------+\n  |      |     |o------>  |     |o------>  |     |      |\n  | NULL |  1  |          |  2  |          |  3  | NULL |\n  |      |     |  &lt;------o|     |  &lt;------o|     |      |\n  +------+-----+--+    +--+-----+--+       +-----+------+</code></pre></div>\n<p>The browser cache which allows you to hit the BACK and FORWARD button. Here we need to maintain a doubly linked list, with <code class=\"language-text\">URLs</code> as data field, to allow access in both direction. To go to previous URL we will use <code class=\"language-text\">prev</code> field and to go to next page we will use <code class=\"language-text\">next</code> field.</p>\n<h3>Circular Linked List</h3>\n<p>Circular linked lists is a singly linked list in which last node, <code class=\"language-text\">next</code> field points to first node in the sequence.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     head\n      |\n      |\n    +-----+--+      +-----+--+      +-----+--+\n    —> | 1 |o-----> | 2 |o----->    | 3 |o----|\n    +-----+--+      +-----+--+      +-----+--+</code></pre></div>\n<p>Timesharing problem solved by the operating system.</p>\n<p>In a timesharing environment, the operating system must maintain a list of present users and must alternately allow each user to use a small portion of CPU time, one user at a time. The operating system will pick a user, let him/her use a small amount of CPU time and then move on to the next user.</p>\n<p>For this application, there should be no NULL pointers unless there is absolutely no one requesting CPU time, i.e list is empty.</p>\n<h2><strong>Basic Operations</strong></h2>\n<h3>Insertion</h3>\n<p>To add a new element to the list.</p>\n<p>Insertion at the beginning:</p>\n<ul>\n<li>Create a new node with given data.</li>\n<li>Point new node's <code class=\"language-text\">next</code> to old <code class=\"language-text\">head</code>.</li>\n<li>Point <code class=\"language-text\">head</code> to this new node.</li>\n</ul>\n<p>Insertion in the middle/end.</p>\n<p>Insertion after node X.</p>\n<ul>\n<li>Create a new node with given data.</li>\n<li>Point new node's <code class=\"language-text\">next</code> to old X's <code class=\"language-text\">next</code>.</li>\n<li>Point X's <code class=\"language-text\">next</code> to this new node.</li>\n</ul>\n<p>*<strong>*Time Complexity: O(1)**</strong></p>\n<h3>Deletion</h3>\n<p>To delete existing element from the list.</p>\n<p>Deletion at the beginning</p>\n<ul>\n<li>Get the node pointed by <code class=\"language-text\">head</code> as Temp.</li>\n<li>Point <code class=\"language-text\">head</code> to Temp's <code class=\"language-text\">next</code>.</li>\n<li>Free memory used by Temp node.</li>\n</ul>\n<p>Deletion in the middle/end.</p>\n<p>Deletion after node X.</p>\n<ul>\n<li>Get the node pointed by <code class=\"language-text\">X</code> as Temp.</li>\n<li>Point X's <code class=\"language-text\">next</code> to Temp's <code class=\"language-text\">next</code>.</li>\n<li>Free memory used by Temp node.</li>\n</ul>\n<p>*<strong>*Time Complexity: O(1)**</strong></p>\n<h3>Traversing</h3>\n<p>To travel across the list.</p>\n<p>Traversal</p>\n<ul>\n<li>Get the node pointed by <code class=\"language-text\">head</code> as Current.</li>\n<li>Check if Current is not null and display it.</li>\n<li>Point Current to Current's <code class=\"language-text\">next</code> and move to above step.</li>\n</ul>\n<p>*<strong>*Time Complexity: O(n) // Here n is size of link-list**</strong></p>\n<h2><strong>Implementation</strong></h2>\n<h3><strong>C++ implementation of singly linked list</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Header files\n#include &lt;iostream>\n\nstruct node\n{\n    int data;\n    struct node *next;\n};\n\n// Head pointer always points to first element of the linked list\nstruct node *head = NULL;</code></pre></div>\n<h4><strong>Printing data in each node</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Display the list\nvoid printList()\n{\n    struct node *ptr = head;\n\n    // Start from the beginning\nwhile(ptr != NULL)\n{\n    std::cout &lt;&lt; ptr->data &lt;&lt; \" \";\n    ptr = ptr->next;\n}\n\nstd::cout &lt;&lt; std::endl;\n}</code></pre></div>\n<h4><strong>Insertion at the beginning</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Insert link at the beginning\nvoid insertFirst(int data)\n{\n    // Create a new node\n    struct node *new_node = new struct node;\n\n    new_node->data = data;\n\n// Point it to old head\nnew_node->next = head;\n\n// Point head to new node\nhead = new_node;\n\nstd::cout &lt;&lt; \"Inserted successfully\" &lt;&lt; std::endl;\n}</code></pre></div>\n<h4><strong>Deletion at the beginning</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Delete first item\nvoid deleteFirst()\n{\n    // Save reference to head\n    struct node *temp = head;\n\n    // Point head to head's next\nhead = head->next;\n\n// Free memory used by temp\ntemp = NULL:\ndelete temp;\n\nstd::cout &lt;&lt; \"Deleted successfully\" &lt;&lt; std::endl;\n}</code></pre></div>\n<h4><strong>Size</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Find no. of nodes in link list\nvoid size()\n{\n    int length = 0;\n    struct node *current;\n\n    for(current = head; current != NULL; current = current->next)\n{\n    length++;\n}\n\nstd::cout &lt;&lt; \"Size of Linked List is \" &lt;&lt; length &lt;&lt; std::endl;\n}</code></pre></div>\n<h4><strong>Searching</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Find node with given data\nvoid find(int data){\n\n    // Start from the head\nstruct node* current = head;\n\n// If list is empty\nif(head == NULL)\n{\n    std::cout &lt;&lt; \"List is empty\" &lt;&lt; std::endl;\n    return;\n}\n\n// Traverse through list\nwhile(current->data != data){\n\n    // If it is last node\n    if(current->next == NULL){\n        std::cout &lt;&lt; \"Not Found\" &lt;&lt; std::endl;\n        return;\n    }\n    else{\n        // Go to next node\n        current = current->next;\n    }\n}\n\n// If data found\nstd::cout &lt;&lt; \"Found\" &lt;&lt; std::endl;\n}</code></pre></div>\n<h4><strong>Deletion after a node</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Delete a node with given data\nvoid del(int data){\n\n    // Start from the first node\nstruct node* current = head;\nstruct node* previous = NULL;\n\n// If list is empty\nif(head == NULL){\n    std::cout &lt;&lt; \"List is empty\" &lt;&lt; std::endl;\n    return ;\n}\n\n// Navigate through list\nwhile(current->data != data){\n\n    // If it is last node\n    if(current->next == NULL){\n        std::cout &lt;&lt; \"Element not found\" &lt;&lt; std::endl;\n        return ;\n    }\n    else {\n        // Store reference to current node\n        previous = current;\n        // Move to next node\n        current = current->next;\n    }\n\n}\n\n// Found a match, update the node\nif(current == head) {\n    // Change head to point to next node\n    head = head->next;\n}\nelse {\n    // Skip the current node\n    previous->next = current->next;\n}\n\n// Free space used by deleted node\ncurrent = NULL;\ndelete current;\nstd::cout &lt;&lt; \"Deleted succesfully\" &lt;&lt; std::endl;\n}</code></pre></div>\n<h3><strong>Python Implementation of Singly Linked List</strong></h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Node(object):\n    # Constructor\n    def __init__(self, data=None, next=None):\n        self.data = data\n        self.next = next\n\n    # Function to get data\ndef get_data(self):\n    return self.data\n\n# Function to get next node\ndef get_next(self):\n    return self.next\n\n# Function to set next field\ndef set_next(self, new_next):\n    self.next = new_next\nclass LinkedList(object):\n    def __init__(self, head=None):\n        self.head = head</code></pre></div>\n<h4><strong>Insertion</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    # Function to insert data\ndef insert(self, data):\n    # new_node is a object of class Node\n    new_node = Node(data)\n    new_node.set_next(self.head)\n    self.head = new_node\n    print(\"Node with data \" + str(data) + \" is created succesfully\")</code></pre></div>\n<h4><strong>Size</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    # Function to get size\ndef size(self):\n    current = self.head\n    count = 0\n    while current:\n        count += 1\n        current = current.get_next()\n    print(\"Size of link list is \" + str(count))</code></pre></div>\n<h4><strong>Searching</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    # Function to search a data\ndef search(self, data):\n    current = self.head\n    found = False\n    while current and found is False:\n        if current.get_data() == data:\n            found = True\n        else:\n            current = current.get_next()\n    if current is None:\n        print(\"Node with data \" + str(data) + \" is not present\")\n    else:\n        print(\"Node with data \" + str(data) + \" is found\")</code></pre></div>\n<h4><strong>Deletion after a node</strong></h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    # Function to delete a node with data\ndef delete(self, data):\n    current = self.head\n    previous = None\n    found = False\n    while current and found is False:\n        if current.get_data() == data:\n            found = True\n        else:\n            previous = current\n            current = current.get_next()\n    if current is None:\n        print(\"Node with data \" + str(data) + \" is not in list\")\n    elif previous is None:\n        self.head = current.get_next()\n        print(\"Node with data \" + str(data) + \" is deleted successfully\")\n    else:\n        previous.set_next(current.get_next())\n        print(\"Node with data \" + str(data) + \" is deleted successfully\")</code></pre></div>\n<p>*<strong>*Advantages**</strong></p>\n<ol>\n<li>Linked lists are a dynamic data structure, which can grow and shrink, allocating and deallocating memory while the program is running.</li>\n<li>Insertion and deletion of node are easily implemented in a linked list at any position.</li>\n</ol>\n<p>*<strong>*Disadvantages**</strong></p>\n<ol>\n<li>They use more memory than arrays because of the memory used by their pointers (<code class=\"language-text\">next</code> and <code class=\"language-text\">prev</code>).</li>\n<li>Random access is not possible in linked list. We have to access nodes sequentially.</li>\n<li>It's more complex than array. If a language supports array bound check automatically, Arrays would serve you better.</li>\n</ol>\n<h4><strong>Note</strong></h4>\n<p>We have to use free() in C and delete in C++ to free the space used by deleted node, whereas, in Python and Java free space is collected automatically by garbage collector.</p>\n<p>Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. <a href=\"https://www.freecodecamp.org/learn/\">Get started</a></p>"},{"url":"/docs/ds-algo/","relativePath":"docs/ds-algo/index.md","relativeDir":"docs/ds-algo","base":"index.md","name":"index","frontmatter":{"title":"Data Structures","excerpt":"In this section you'll learn how to add syntax highlighting, examples, callouts and much more.","seo":{"title":"Data Structures","description":"This is the  Data Structures page","extra":[{"name":"og:type","value":"website","keyName":"property"},{"name":"og:title","value":"Data Structures","keyName":"property"},{"name":"og:description","value":"This is the  Data Structures page","keyName":"property"},{"name":"twitter:card","value":"summary"},{"name":"twitter:title","value":"Data Structures"},{"name":"twitter:description","value":"This is the  Data Structures page"}]},"template":"docs","weight":0},"html":"<p>Data structures</p>\n<p><br><a href=\"https://ds-unit-5-lambda.netlify.app/#\">https://ds-unit-5-lambda.netlify.app/#</a>.\n<br>\n<br>\n<br></p>\n<h1>   Algorithms </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bgoonz-branch-the-algos.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h1>  The Algos Bgoonz Branch </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://thealgorithms.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>  Python Data Structures</h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://ds-unit-5-lambda.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Leetcode </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bgoonz.github.io/Leetcode-JS-PY-MD/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<br>\n<h1>   Algorithms </h1>\n<br>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"     style=\"z-index:-1!important; overflow:scroll;resize:both;\"  src=\"https://bgoonz-branch-the-algos.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<br>\n<br>\n<br>\n<h3>Data structures in JavaScript</h3>\n<p><span class=\"graf-dropCap\">H</span>ere's a website I created to practice data structures!</p>\n<a href=\"https://ds-algo-official-c3dw6uapg-bgoonz.vercel.app/\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://ds-algo-official-c3dw6uapg-bgoonz.vercel.app/\">\n<strong>directory</strong>\n<br />\n<em>Edit description</em>ds-algo-official-c3dw6uapg-bgoonz.vercel.app</a>\n<a href=\"https://ds-algo-official-c3dw6uapg-bgoonz.vercel.app/\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<p><span class=\"graf-dropCap\">H</span>ere's the repo that the website is built on:</p>\n<a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\">\n<strong>bgoonz/DS-ALGO-OFFICIAL</strong>\n<br />\n<em>Navigation ####Author:Bryan Guner Big O notation is the language we use for talking about how long an algorithm takes…</em>github.com</a>\n<a href=\"https://github.com/bgoonz/DS-ALGO-OFFICIAL\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<p><span class=\"graf-dropCap\">H</span>ere's a live code editor where you can mess with any of the examples…</p>\n<h3>Resources (article content below):</h3>\n<h4>Videos</h4>\n<ul>\n<li>\n<span id=\"53c4\">\n<a href=\"https://www.youtube.com/watch?v=0IAPZzGSbME&amp;list=PLDN4rrl48XKpZkf03iYFl-O29szjTrs_O&amp;index=2&amp;t=0s\" class=\"markup--anchor markup--li-anchor\">Abdul Bari: YouTubeChannel for Algorithms</a>\n</span>\n</li>\n<li>\n<span id=\"ab93\">\n<a href=\"https://www.youtube.com/watch?v=lxja8wBwN0k&amp;list=PLKKfKV1b9e8ps6dD3QA5KFfHdiWj9cB1s\" class=\"markup--anchor markup--li-anchor\">Data Structures and algorithms</a>\n</span>\n</li>\n<li>\n<span id=\"e614\">\n<a href=\"https://www.youtube.com/playlist?list=PLmGElG-9wxc9Us6IK6Qy-KHlG_F3IS6Q9\" class=\"markup--anchor markup--li-anchor\">Data Structures and algorithms Course</a>\n</span>\n</li>\n<li>\n<span id=\"3d48\">\n<a href=\"https://www.khanacademy.org/computing/computer-science/algorithms\" class=\"markup--anchor markup--li-anchor\">Khan Academy</a>\n</span>\n</li>\n<li>\n<span id=\"ac90\">\n<a href=\"https://www.youtube.com/playlist?list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P\" class=\"markup--anchor markup--li-anchor\">Data structures by mycodeschool</a>Pre-requisite for this lesson is good understanding of pointers in C.</span>\n</li>\n<li>\n<span id=\"9bd9\">\n<a href=\"https://www.youtube.com/watch?v=HtSuA80QTyo&amp;list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb\" class=\"markup--anchor markup--li-anchor\">MIT 6.006: Intro to Algorithms(2011)</a>\n</span>\n</li>\n<li>\n<span id=\"71f0\">\n<a href=\"https://www.youtube.com/watch?v=5_5oE5lgrhw&amp;list=PLu0W_9lII9ahIappRPN0MCAgtOu3lQjQi\" class=\"markup--anchor markup--li-anchor\">Data Structures and Algorithms by Codewithharry</a>\n</span>\n</li>\n</ul>\n<h4>Books</h4>\n<ul>\n<li>\n<span id=\"2eac\">\n<a href=\"https://edutechlearners.com/download/Introduction_to_algorithms-3rd%20Edition.pdf\" class=\"markup--anchor markup--li-anchor\">Introduction to Algorithms</a> by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein</span>\n</li>\n<li>\n<span id=\"3e8d\">\n<a href=\"http://www.sso.sy/sites/default/files/competitive%20programming%203_1.pdf\" class=\"markup--anchor markup--li-anchor\">Competitive Programming 3</a> by Steven Halim and Felix Halim</span>\n</li>\n<li>\n<span id=\"3aa3\">\n<a href=\"https://cses.fi/book/book.pdf\" class=\"markup--anchor markup--li-anchor\">Competitive Programmers Hand Book</a> Beginner friendly hand book for competitive programmers.</span>\n</li>\n<li>\n<span id=\"3c02\">\n<a href=\"https://github.com/Amchuz/My-Data-Structures-and-Algorithms-Resources/raw/master/Books/Data%20Structures%20and%20Algorithms%20-%20Narasimha%20Karumanchi.pdf\" class=\"markup--anchor markup--li-anchor\">Data Structures and Algorithms Made Easy</a> by Narasimha Karumanchi</span>\n</li>\n<li>\n<span id=\"93ec\">\n<a href=\"https://github.com/Amchuz/My-Data-Structures-and-Algorithms-Resources/raw/master/Books/Learning%20Algorithms%20Through%20Programming%20and%20Puzzle%20Solving.pdf\" class=\"markup--anchor markup--li-anchor\">Learning Algorithms Through Programming and Puzzle Solving</a> by Alexander Kulikov and Pavel Pevzner</span>\n</li>\n</ul>\n<h4>Coding practice</h4>\n<ul>\n<li>\n<span id=\"824c\">\n<a href=\"https://leetcode.com/\" class=\"markup--anchor markup--li-anchor\">LeetCode</a>\n</span>\n</li>\n<li>\n<span id=\"a528\">\n<a href=\"https://www.interviewbit.com/\" class=\"markup--anchor markup--li-anchor\">InterviewBit</a>\n</span>\n</li>\n<li>\n<span id=\"fa41\">\n<a href=\"https://codility.com/\" class=\"markup--anchor markup--li-anchor\">Codility</a>\n</span>\n</li>\n<li>\n<span id=\"6c61\">\n<a href=\"https://www.hackerrank.com/\" class=\"markup--anchor markup--li-anchor\">HackerRank</a>\n</span>\n</li>\n<li>\n<span id=\"dff6\">\n<a href=\"https://projecteuler.net/\" class=\"markup--anchor markup--li-anchor\">Project Euler</a>\n</span>\n</li>\n<li>\n<span id=\"b2dd\">\n<a href=\"https://spoj.com/\" class=\"markup--anchor markup--li-anchor\">Spoj</a>\n</span>\n</li>\n<li>\n<span id=\"c8e8\">\n<a href=\"https://code.google.com/codejam/contests.html\" class=\"markup--anchor markup--li-anchor\">Google Code Jam practice problems</a>\n</span>\n</li>\n<li>\n<span id=\"e8bb\">\n<a href=\"https://www.hackerearth.com/\" class=\"markup--anchor markup--li-anchor\">HackerEarth</a>\n</span>\n</li>\n<li>\n<span id=\"e803\">\n<a href=\"https://www.topcoder.com/\" class=\"markup--anchor markup--li-anchor\">Top Coder</a>\n</span>\n</li>\n<li>\n<span id=\"294e\">\n<a href=\"https://www.codechef.com/\" class=\"markup--anchor markup--li-anchor\">CodeChef</a>\n</span>\n</li>\n<li>\n<span id=\"9c05\">\n<a href=\"https://www.codewars.com/\" class=\"markup--anchor markup--li-anchor\">Codewars</a>\n</span>\n</li>\n<li>\n<span id=\"356e\">\n<a href=\"https://codesignal.com/\" class=\"markup--anchor markup--li-anchor\">CodeSignal</a>\n</span>\n</li>\n<li>\n<span id=\"2d20\">\n<a href=\"http://codekata.com/\" class=\"markup--anchor markup--li-anchor\">CodeKata</a>\n</span>\n</li>\n<li>\n<span id=\"d3bf\">\n<a href=\"https://www.firecode.io/\" class=\"markup--anchor markup--li-anchor\">Firecode</a>\n</span>\n</li>\n</ul>\n<h4>Courses</h4>\n<ul>\n<li>\n<span id=\"eac2\">\n<a href=\"https://academy.zerotomastery.io/p/master-the-coding-interview-faang-interview-prep\" class=\"markup--anchor markup--li-anchor\">Master the Coding Interview: Big Tech (FAANG) Interviews</a> Course by Andrei and his team.</span>\n</li>\n<li>\n<span id=\"36ca\">\n<a href=\"https://realpython.com/python-data-structures\" class=\"markup--anchor markup--li-anchor\">Common Python Data Structures</a> Data structures are the fundamental constructs around which you build your programs. Each data structure provides a particular way of organizing data so it can be accessed efficiently, depending on your use case. Python ships with an extensive set of data structures in its standard library.</span>\n</li>\n<li>\n<span id=\"cdc9\">\n<a href=\"https://www.geeksforgeeks.org/fork-cpp-course-structure\" class=\"markup--anchor markup--li-anchor\">Fork CPP</a> A good course for beginners.</span>\n</li>\n<li>\n<span id=\"6d47\">\n<a href=\"https://codeforces.com/edu/course/2\" class=\"markup--anchor markup--li-anchor\">EDU</a> Advanced course.</span>\n</li>\n<li>\n<span id=\"8bb5\">\n<a href=\"https://www.udacity.com/course/c-for-programmers--ud210\" class=\"markup--anchor markup--li-anchor\">C++ For Programmers</a> Learn features and constructs for C++.</span>\n</li>\n</ul>\n<h4>Guides</h4>\n<ul>\n<li>\n<span id=\"e9e9\">\n<a href=\"http://www.geeksforgeeks.org/\" class=\"markup--anchor markup--li-anchor\">GeeksForGeeks — A CS portal for geeks</a>\n</span>\n</li>\n<li>\n<span id=\"a228\">\n<a href=\"https://www.learneroo.com/subjects/8\" class=\"markup--anchor markup--li-anchor\">Learneroo — Algorithms</a>\n</span>\n</li>\n<li>\n<span id=\"a2f0\">\n<a href=\"http://www.topcoder.com/tc?d1=tutorials&amp;d2=alg_index&amp;module=Static\" class=\"markup--anchor markup--li-anchor\">Top Coder tutorials</a>\n</span>\n</li>\n<li>\n<span id=\"f3ec\">\n<a href=\"http://www.infoarena.ro/training-path\" class=\"markup--anchor markup--li-anchor\">Infoarena training path</a> (RO)</span>\n</li>\n<li><span id=\"ec93\">Steven &#x26; Felix Halim — <a href=\"https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=118\" class=\"markup--anchor markup--li-anchor\">Increasing the Lower Bound of Programming Contests</a> (UVA Online Judge)</span></li>\n</ul>\n<h3><strong><em>space</em></strong></h3>\n<blockquote>\n<p><em>The space complexity represents the memory consumption of a data structure. As for most of the things in life, you can't have it all, so it is with the data structures. You will generally need to trade some time for space or the other way around.</em></p>\n</blockquote>\n<h3><em>time</em></h3>\n<blockquote>\n<p><em>The time complexity for a data structure is in general more diverse than its space complexity.</em></p>\n</blockquote>\n<h3><em>Several operations</em></h3>\n<blockquote>\n<p><em>In contrary to algorithms, when you look at the time complexity for data structures you need to express it for several operations that you can do with data structures. It can be adding elements, deleting elements, accessing an element or even searching for an element.</em></p>\n</blockquote>\n<h3><em>Dependent on data</em></h3>\n<blockquote>\n<p><em>Something that data structure and algorithms have in common when talking about time complexity is that they are both dealing with data. When you deal with data you become dependent on them and as a result the time complexity is also dependent of the data that you received. To solve this problem we talk about 3 different time complexity.</em></p>\n</blockquote>\n<ul>\n<li><span id=\"bc8d\"><strong>The best-case complexity: when the data looks the best</strong></span></li>\n<li><span id=\"8b06\"><strong>The worst-case complexity: when the data looks the worst</strong></span></li>\n<li><span id=\"881c\"><strong>The average-case complexity: when the data looks average</strong></span></li>\n</ul>\n<h3>Big O notation</h3>\n<p>The complexity is usually expressed with the Big O notation. The wikipedia page about this subject is pretty complex but you can find here a good summary of the different complexity for the most famous data structures and sorting algorithms.</p>\n<h3>The Array data structure</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*Qk3UYgeqXamRrFLR.gif\" class=\"graf-image\" />\n</figure>### Definition\n<p>An Array data structure, or simply an Array, is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. The simplest type of data structure is a linear array, also called one-dimensional array. From Wikipedia</p>\n<p>Arrays are among the oldest and most important data structures and are used by every program. They are also used to implement many other data structures.</p>\n<p><em>Complexity</em>\n<em>Average</em>\n<em>Access Search Insertion Deletion</em></p>\n<p>O(1) O(n) O(1) O(n)</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*-BJ2hU-CZO2kuzu4x5a53g.png\" class=\"graf-image\" />\n</figure>indexvalue0 … this is the first value, stored at zero position\n<ol>\n<li><span id=\"b953\">The index of an array <strong>runs in sequence</strong></span></li>\n<li>This could be useful for storing data that are required to be ordered, such as rankings or queues</li>\n<li>In JavaScript, array's value could be mixed; meaning value of each index could be of different data, be it String, Number or even Objects</li>\n</ol>\n<h3>2. Objects</h3>\n<p>Think of objects as a logical grouping of a bunch of properties.</p>\n<p>Properties could be some variable that it's storing or some methods that it's using.</p>\n<p>I also visualize an object as a table.</p>\n<p>The main difference is that object's \"index\" need not be numbers and is not necessarily sequenced.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/1*KVZkD2zrgEa_47igW8Hq8g.png\" class=\"graf-image\" />\n</figure>\n<h3>The Hash Table</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*avbxLAFocSV6vsl5.gif\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*3GJiRoLyEoZ_aIlO\" class=\"graf-image\" />\n</figure>### *Definition*\n<blockquote>\n<p><em>A Hash Table (Hash Map) is a data structure used to implement an associative array, a structure that can map keys to values. A Hash Table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found. From Wikipedia</em></p>\n</blockquote>\n<p>Hash Tables are considered the more efficient data structure for lookup and for this reason, they are widely used.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion</p>\n<ul>\n<li><span id=\"f63f\">O(1) O(1) O(1)</span></li>\n</ul>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<p>Note, here I am storing another object for every hash in my Hash Table.</p>\n<h3>The Set</h3>\n<h3>Sets</h3>\n<p>Sets are pretty much what it sounds like. It's the same intuition as Set in Mathematics. I visualize Sets as Venn Diagrams.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*AIQljh9p8Baw9TnE.png\" class=\"graf-image\" />\n</figure>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*gOE33ANZP2ujbjIG\" class=\"graf-image\" />\n</figure>### *Definition*\n<blockquote>\n<p><em>A Set is an abstract data type that can store certain values, without any particular order, and no repeated values. It is a computer implementation of the mathematical concept of a finite Set. From Wikipedia</em></p>\n</blockquote>\n<p>The Set data structure is usually used to test whether elements belong to set of values. Rather then only containing elements, Sets are more used to perform operations on multiple values at once with methods such as union, intersect, etc…</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion</p>\n<ul>\n<li><span id=\"daa6\">O(n) O(n) O(n)</span></li>\n</ul>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<h3>The Singly Linked List</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*fLs64rV-Xq19aVCA.gif\" class=\"graf-image\" />\n</figure>### *Definition*\n<blockquote>\n<p><em>A Singly Linked List is a linear collection of data elements, called nodes pointing to the next node by means of pointer. It is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of data and a reference (in other words, a link) to the next node in the sequence.</em></p>\n</blockquote>\n<p>Linked Lists are among the simplest and most common data structures because it allows for efficient insertion or removal of elements from any position in the sequence.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(1) O(1)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<hr>\n<h3>The Doubly Linked List</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*TQXiR-L_itiG3WP-.gif\" class=\"graf-image\" />\n</figure>### *Definition*\n<blockquote>\n<p><em>A Doubly Linked List is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes. From Wikipedia</em></p>\n</blockquote>\n<p>Having two node links allow traversal in either direction but adding or removing a node in a doubly linked list requires changing more links than the same operations on a Singly Linked List.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(1) O(1)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<h3>The Stack</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/0*qsjYW-Lvfo22ecLE.gif\" class=\"graf-image\" />\n</figure>\n<h3><em>Definition</em></h3>\n<blockquote>\n<p><em>A Stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed. The order in which elements come off a Stack gives rise to its alternative name, LIFO (for last in, first out). From Wikipedia</em></p>\n</blockquote>\n<p>A Stack often has a third method peek which allows to check the last pushed element without popping it.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(1) O(1)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<h3>The Queue</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*YvfuX5tKP7-V0p7v.gif\" class=\"graf-image\" />\n</figure>### *Definition*\n<blockquote>\n<p><em>A Queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal operations are the addition of entities to the rear terminal position, known as enqueue, and removal of entities from the front terminal position, known as dequeue. This makes the Queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the Queue will be the first one to be removed.</em></p>\n</blockquote>\n<p>As for the Stack data structure, a peek operation is often added to the Queue data structure. It returns the value of the front element without dequeuing it.</p>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(1) O(n)</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<h3>The Tree</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*yUiQ-NaPKeLQnN7n\" class=\"graf-image\" />\n</figure>### *Definition*\n<blockquote>\n<p><em>A Tree is a widely used data structure that simulates a hierarchical tree structure, with a root value and subtrees of children with a parent node. A tree data structure can be defined recursively as a collection of nodes (starting at a root node), where each node is a data structure consisting of a value, together with a list of references to nodes (the \"children\"), with the constraints that no reference is duplicated, and none points to the root node. From Wikipedia</em></p>\n</blockquote>\n<p>Complexity\nAverage\nAccess Search Insertion Deletion\nO(n) O(n) O(n) O(n)\nTo get a full overview of the time and space complexity of the Tree data structure, have a look to this excellent Big O cheat sheet.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*DCdQiB6XqBJCrFRz12BwqA.png\" class=\"graf-image\" />\n</figure>*The code*\n<h3>The Graph</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*q31mL1kjFWlIzw3l.gif\" class=\"graf-image\" />\n</figure>### *Definition*\n<blockquote>\n<p><em>A Graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected Graph or a set of ordered pairs for a directed Graph. These pairs are known as edges, arcs, or lines for an undirected Graph and as arrows, directed edges, directed arcs, or directed lines for a directed Graph. The vertices may be part of the Graph structure, or may be external entities represented by integer indices or references.</em></p>\n</blockquote>\n<ul>\n<li><span id=\"f896\">A graph is <strong>any</strong> collection of nodes and edges.</span></li>\n<li><span id=\"fbda\">Much more relaxed in structure than a tree.</span></li>\n<li><span id=\"5281\">It doesn't need to have a root node (not every node needs to be accessible from a single node)</span></li>\n<li><span id=\"0c79\">It can have cycles (a group of nodes whose paths begin and end at the same node)</span></li>\n<li><span id=\"4afc\">Cycles are not always \"isolated\", they can be one part of a larger graph. You can detect them by starting your search on a specific node and finding a path that takes you back to that same node.</span></li>\n<li><span id=\"8f45\">Any number of edges may leave a given node</span></li>\n<li><span id=\"51cf\">A Path is a sequence of nodes on a graph</span></li>\n</ul>\n<h3>Cycle Visual</h3>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/1*dn1BqCdXdFg4FCVSz6uArA.png\" class=\"graf-image\" />\n</figure>A Graph data structure may also associate to each edge some edge value, such as a symbolic label or a numeric attribute (cost, capacity, length, etc.).\n<p>Representation\nThere are different ways of representing a graph, each of them with its own advantages and disadvantages. Here are the main 2:</p>\n<p>Adjacency list: For every vertex a list of adjacent vertices is stored. This can be viewed as storing the list of edges. This data structure allows the storage of additional data on the vertices and edges.\nAdjacency matrix: Data are stored in a two-dimensional matrix, in which the rows represent source vertices and columns represent destination vertices. The data on the edges and vertices must be stored externally.</p>\n<p>Graph</p>\n<blockquote>\n<p><em>The code</em></p>\n</blockquote>\n<hr>\n<h1>Leetcode</h1>\n<h2>Data Structures &#x26; Algorithms</h2>\n<p><a href=\"https://github.com/bgoonz/Data-Structures-Algos-Codebase\">DS Algo Codebase</a></p>\n<p><a href=\"#115-distinct-subsequenceshttpsleetcodecomproblemsdistinct-subsequencesdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/distinct-subsequences/description/\">115. Distinct Subsequences</a></h2>\n<h3>Problem:</h3>\n<p>Given a string <strong>S</strong> and a string <strong>T</strong>, count the number of distinct subsequences of <strong>S</strong> which equals <strong>T</strong>.</p>\n<p>A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, <code class=\"language-text\">\"ACE\"</code> is a subsequence of <code class=\"language-text\">\"ABCDE\"</code> while <code class=\"language-text\">\"AEC\"</code> is not).</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: S = \"rabbbit\", T = \"rabbit\"\nOutput: 3\nExplanation:\n\nAs shown below, there are 3 ways you can generate \"rabbit\" from S.\n(The caret symbol ^ means the chosen letters)\n\nrabbbit\n^^^^ ^^\nrabbbit\n^^ ^^^^\nrabbbit\n^^^ ^^^</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: S = \"babgbag\", T = \"bag\"\nOutput: 5\nExplanation:\n\nAs shown below, there are 5 ways you can generate \"bag\" from S.\n(The caret symbol ^ means the chosen letters)\n\nbabgbag\n^^ ^\nbabgbag\n^^    ^\nbabgbag\n^    ^^\nbabgbag\n  ^  ^^\nbabgbag\n    ^^^</code></pre></div>\n<h3>Solution:</h3>\n<p>Define <code class=\"language-text\">f(i, j)</code> to be the number of ways that generate <code class=\"language-text\">T[0...j)</code> from <code class=\"language-text\">S[0...i)</code>.</p>\n<p>For <code class=\"language-text\">f(i, j)</code> you can always skip <code class=\"language-text\">S[i-1]</code>, but can only take it when <code class=\"language-text\">S[i-1] === T[j-1]</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token comment\">// nothing to delete</span>\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token comment\">// delete all</span>\n<span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">S</span><span class=\"token punctuation\">[</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token constant\">T</span><span class=\"token punctuation\">[</span>j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Dynamic array can be used.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @param {string} t\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">numDistinct</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> lens <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> lent <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> dp <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span>lent <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">fill</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    dp<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> lens<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> lent<span class=\"token punctuation\">;</span> j <span class=\"token operator\">>=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                dp<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> dp<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> dp<span class=\"token punctuation\">[</span>lent<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Tree\": <a href=\"https://leetcode.com/tag/tree\">https://leetcode.com/tag/tree</a>\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\nSimilar Questions:\n\"Populating Next Right Pointers in Each Node II\": <a href=\"https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii\">https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii</a>\n\"Binary Tree Right Side View\": <a href=\"https://leetcode.com/problems/binary-tree-right-side-view\">https://leetcode.com/problems/binary-tree-right-side-view</a></p>\n<hr>\n<p><a href=\"#116-populating-next-right-pointers-in-each-nodehttpsleetcodecomproblemspopulating-next-right-pointers-in-each-nodedescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/populating-next-right-pointers-in-each-node/description/\">116. Populating Next Right Pointers in Each Node</a></h2>\n<h3>Problem:</h3>\n<p>Given a binary tree</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">struct TreeLinkNode {\n  TreeLinkNode *left;\n  TreeLinkNode *right;\n  TreeLinkNode *next;\n}</code></pre></div>\n<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code class=\"language-text\">NULL</code>.</p>\n<p>Initially, all next pointers are set to <code class=\"language-text\">NULL</code>.</p>\n<p><strong>Note:</strong></p>\n<ul>\n<li>You may only use constant extra space.</li>\n<li>Recursive approach is fine, implicit stack space does not count as extra space for this problem.</li>\n<li>You may assume that it is a perfect binary tree (ie, all leaves are at the same level, and every parent has two children).</li>\n</ul>\n<p><strong>Example:</strong></p>\n<p>Given the following perfect binary tree,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1\n   /  \\\n  2    3\n / \\  / \\\n4  5  6  7</code></pre></div>\n<p>After calling your function, the tree should look like:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1 -> NULL\n   /  \\\n  2 -> 3 -> NULL\n / \\  / \\\n4->5->6->7 -> NULL</code></pre></div>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<p>Recursive.</p>\n<p>For every <code class=\"language-text\">node</code>:</p>\n<ul>\n<li>Left child: points to <code class=\"language-text\">node.right</code>.</li>\n<li>Right child: points to <code class=\"language-text\">node.next.left</code> if <code class=\"language-text\">node.next</code> exists.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for binary tree with next pointer.\n * function TreeLinkNode(val) {\n *     this.val = val;\n *     this.left = this.right = this.next = null;\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {TreeLinkNode} root\n * @return {void} Do not return anything, modify tree in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">connect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n        <span class=\"token function\">connect</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>next <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token function\">connect</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>Level order traversal.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for binary tree with next pointer.\n * function TreeLinkNode(val) {\n *     this.val = val;\n *     this.left = this.right = this.next = null;\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {TreeLinkNode} root\n * @return {void} Do not return anything, modify tree in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">connect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">,</span> root<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node <span class=\"token operator\">!==</span> node<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> queue<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Tree\": <a href=\"https://leetcode.com/tag/tree\">https://leetcode.com/tag/tree</a>\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\nSimilar Questions:\n\"Populating Next Right Pointers in Each Node\": <a href=\"https://leetcode.com/problems/populating-next-right-pointers-in-each-node\">https://leetcode.com/problems/populating-next-right-pointers-in-each-node</a></p>\n<hr>\n<p><a href=\"#117-populating-next-right-pointers-in-each-node-iihttpsleetcodecomproblemspopulating-next-right-pointers-in-each-node-iidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/description/\">117. Populating Next Right Pointers in Each Node II</a></h2>\n<h3>Problem:</h3>\n<p>Given a binary tree</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">struct TreeLinkNode {\n  TreeLinkNode *left;\n  TreeLinkNode *right;\n  TreeLinkNode *next;\n}</code></pre></div>\n<p>Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to <code class=\"language-text\">NULL</code>.</p>\n<p>Initially, all next pointers are set to <code class=\"language-text\">NULL</code>.</p>\n<p><strong>Note:</strong></p>\n<ul>\n<li>You may only use constant extra space.</li>\n<li>Recursive approach is fine, implicit stack space does not count as extra space for this problem.</li>\n</ul>\n<p><strong>Example:</strong></p>\n<p>Given the following binary tree,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1\n   /  \\\n  2    3\n / \\    \\\n4   5    7</code></pre></div>\n<p>After calling your function, the tree should look like:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1 -> NULL\n   /  \\\n  2 -> 3 -> NULL\n / \\    \\\n4-> 5 -> 7 -> NULL</code></pre></div>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<p>Recursive. See <a href=\"./116.%20Populating%20Next%20Right%20Pointers%20in%20Each%20Node.md\">116. Populating Next Right Pointers in Each Node</a>.</p>\n<p>The tree may not be perfect now. So keep finding <code class=\"language-text\">next</code> until there is a node with children, or <code class=\"language-text\">null</code>.</p>\n<p>This also means post-order traversal is required.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for binary tree with next pointer.\n * function TreeLinkNode(val) {\n *     this.val = val;\n *     this.left = this.right = this.next = null;\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {TreeLinkNode} root\n * @return {void} Do not return anything, modify tree in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">connect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">let</span> next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span> node <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span> node <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>right <span class=\"token operator\">||</span> next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">connect</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">connect</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>Level order traversal. Exact same as <a href=\"./116.%20Populating%20Next%20Right%20Pointers%20in%20Each%20Node.md\">116. Populating Next Right Pointers in Each Node</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for binary tree with next pointer.\n * function TreeLinkNode(val) {\n *     this.val = val;\n *     this.left = this.right = this.next = null;\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {TreeLinkNode} root\n * @return {void} Do not return anything, modify tree in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">connect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">,</span> root<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node <span class=\"token operator\">!==</span> node<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> queue<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">[</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\nSimilar Questions:\n\"Pascal's Triangle II\": <a href=\"https://leetcode.com/problems/pascals-triangle-ii\">https://leetcode.com/problems/pascals-triangle-ii</a></p>\n<hr>\n<p><a href=\"#118-pascals-trianglehttpsleetcodecomproblemspascals-triangledescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/pascals-triangle/description/\">118. Pascal's Triangle</a></h2>\n<h3>Problem:</h3>\n<p>Given a non-negative integer <em>numRows</em>, generate the first <em>numRows</em> of Pascal's triangle.</p>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAnimated2.gif\" alt=\"PascalTriangleAnimated2.gif\"></p>\n<p>In Pascal's triangle, each number is the sum of the two numbers directly above it.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: 5\nOutput:\n[\n     [1],\n    [1,1],\n   [1,2,1],\n  [1,3,3,1],\n [1,4,6,4,1]\n]</code></pre></div>\n<h3>Solution:</h3>\n<p>Dynamic Programming 101.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} numRows\n * @return {number[][]}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">generate</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">numRows</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>numRows <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> numRows<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> lastRow <span class=\"token operator\">=</span> result<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> row <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> i<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            row<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> lastRow<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> lastRow<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        row<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\nSimilar Questions:\n\"Pascal's Triangle\": <a href=\"https://leetcode.com/problems/pascals-triangle\">https://leetcode.com/problems/pascals-triangle</a></p>\n<hr>\n<p><a href=\"#119-pascals-triangle-iihttpsleetcodecomproblemspascals-triangle-iidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/pascals-triangle-ii/description/\">119. Pascal's Triangle II</a></h2>\n<h3>Problem:</h3>\n<p>Given a non-negative index <em>k</em> where <em>k</em> ≤ 33, return the <em>k</em>th index row of the Pascal's triangle.</p>\n<p>Note that the row index starts from 0.</p>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/0/0d/PascalTriangleAnimated2.gif\" alt=\"PascalTriangleAnimated2.gif\"></p>\n<p>In Pascal's triangle, each number is the sum of the two numbers directly above it.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: 3\nOutput: [1,3,3,1]</code></pre></div>\n<p><strong>Follow up:</strong></p>\n<p>Could you optimize your algorithm to use only <em>O</em>(<em>k</em>) extra space?</p>\n<h3>Solution:</h3>\n<p>Dynamic Programming 101 with dynamic array.</p>\n<p>State <code class=\"language-text\">(i, j)</code> depends on <code class=\"language-text\">(i-1, j)</code> and <code class=\"language-text\">(i-1, j-1)</code>. So to access <code class=\"language-text\">(i-1, j-1)</code> iteration must be from right to left.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number} rowIndex\n * @return {number[]}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">getRow</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">rowIndex</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rowIndex <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> row <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> rowIndex<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            row<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> row<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        row<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> row<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Dynamic Programming\": <a href=\"https://leetcode.com/tag/dynamic-programming\">https://leetcode.com/tag/dynamic-programming</a></p>\n<hr>\n<p><a href=\"#120-trianglehttpsleetcodecomproblemstriangledescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/triangle/description/\">120. Triangle</a></h2>\n<h3>Problem:</h3>\n<p>Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.</p>\n<p>For example, given the following triangle</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[\n     [2],\n    [3,4],\n   [6,5,7],\n  [4,1,8,3]\n]</code></pre></div>\n<p>The minimum path sum from top to bottom is <code class=\"language-text\">11</code> (i.e., <strong>2</strong> + <strong>3</strong> + <strong>5</strong> + <strong>1</strong> = 11).</p>\n<p><strong>Note:</strong></p>\n<p>Bonus point if you are able to do this using only <em>O</em>(<em>n</em>) extra space, where <em>n</em> is the total number of rows in the triangle.</p>\n<h3>Solution:</h3>\n<p>Define <code class=\"language-text\">f(i, j)</code> to be the minimum path sum from <code class=\"language-text\">triangle[0][0]</code> to <code class=\"language-text\">triangle[i][j]</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">f(i, 0) = f(i-1, j) + triangle[i][0]\nf(i, j) = min( f(i-1, j-1), f(i-1, j) ) + triangle[i][j], 0 &lt; j &lt; i\nf(i, i) = f(i-1, i-1) + triangle[i][i], i > 0</code></pre></div>\n<p>Dynamic array can be used.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[][]} triangle\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">minimumTotal</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">triangle</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>triangle<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> dp <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>triangle<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> triangle<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> dp<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> triangle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">>=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            dp<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>dp<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> dp<span class=\"token punctuation\">[</span>j <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> triangle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        dp<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> triangle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>dp<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Dynamic Programming\": <a href=\"https://leetcode.com/tag/dynamic-programming\">https://leetcode.com/tag/dynamic-programming</a>\nSimilar Questions:\n\"Maximum Subarray\": <a href=\"https://leetcode.com/problems/maximum-subarray\">https://leetcode.com/problems/maximum-subarray</a>\n\"Best Time to Buy and Sell Stock II\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii</a>\n\"Best Time to Buy and Sell Stock III\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii</a>\n\"Best Time to Buy and Sell Stock IV\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv</a>\n\"Best Time to Buy and Sell Stock with Cooldown\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown</a></p>\n<hr>\n<p><a href=\"#121-best-time-to-buy-and-sell-stockhttpsleetcodecomproblemsbest-time-to-buy-and-sell-stockdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/\">121. Best Time to Buy and Sell Stock</a></h2>\n<h3>Problem:</h3>\n<p>Say you have an array for which the <em>i</em>th element is the price of a given stock on day <em>i</em>.</p>\n<p>If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.</p>\n<p>Note that you cannot sell a stock before you buy one.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,1,5,3,6,4]\nOutput: 5\nExplanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5.\n             Not 7-1 = 6, as selling price needs to be larger than buying price.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0.</code></pre></div>\n<h3>Solution:</h3>\n<p>Only care about positive profits. Take the frist item as base and scan to the right. If we encounter an item <code class=\"language-text\">j</code> whose price <code class=\"language-text\">price[j]</code> is lower than the base (which means if we sell now the profit would be negative), we sell <code class=\"language-text\">j-1</code> instead and make <code class=\"language-text\">j</code> the new base.</p>\n<p>Because <code class=\"language-text\">price[j]</code> is lower that the base, using <code class=\"language-text\">j</code> as new base is guaranteed to gain more profit comparing to the old one.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} prices\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxProfit</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">prices</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> max <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> base <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> prices<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> profit <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">-</span> base<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>profit <span class=\"token operator\">></span> max<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            max <span class=\"token operator\">=</span> profit<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>profit <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            base <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> max<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Greedy\": <a href=\"https://leetcode.com/tag/greedy\">https://leetcode.com/tag/greedy</a>\nSimilar Questions:\n\"Best Time to Buy and Sell Stock\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock</a>\n\"Best Time to Buy and Sell Stock III\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii</a>\n\"Best Time to Buy and Sell Stock IV\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv</a>\n\"Best Time to Buy and Sell Stock with Cooldown\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown</a>\n\"Best Time to Buy and Sell Stock with Transaction Fee\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee</a></p>\n<hr>\n<p><a href=\"#122-best-time-to-buy-and-sell-stock-iihttpsleetcodecomproblemsbest-time-to-buy-and-sell-stock-iidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/\">122. Best Time to Buy and Sell Stock II</a></h2>\n<h3>Problem:</h3>\n<p>Say you have an array for which the <em>i</em>th element is the price of a given stock on day <em>i</em>.</p>\n<p>Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy one and sell one share of the stock multiple times).</p>\n<p><strong>Note:</strong> You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,1,5,3,6,4]\nOutput: 7\nExplanation: Buy on day 2 (price = 1) and sell on day 3 (price = 5), profit = 5-1 = 4.\n             Then buy on day 4 (price = 3) and sell on day 5 (price = 6), profit = 6-3 = 3.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\n             Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are\n             engaging multiple transactions at the same time. You must sell before buying again.</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0.</code></pre></div>\n<h3>Solution:</h3>\n<p>Sell immediately after the price drops. Or in other perspective, it is the sum of all the incremental pairs (buy in then immediately sell out).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} prices\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxProfit</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">prices</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> max <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> prices<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> prices<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            max <span class=\"token operator\">+=</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">-</span> prices<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> max<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Hard\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Dynamic Programming\": <a href=\"https://leetcode.com/tag/dynamic-programming\">https://leetcode.com/tag/dynamic-programming</a>\nSimilar Questions:\n\"Best Time to Buy and Sell Stock\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock</a>\n\"Best Time to Buy and Sell Stock II\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii</a>\n\"Best Time to Buy and Sell Stock IV\": <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv\">https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv</a>\n\"Maximum Sum of 3 Non-Overlapping Subarrays\": <a href=\"https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays\">https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays</a></p>\n<hr>\n<p><a href=\"#123-best-time-to-buy-and-sell-stock-iiihttpsleetcodecomproblemsbest-time-to-buy-and-sell-stock-iiidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/description/\">123. Best Time to Buy and Sell Stock III</a></h2>\n<h3>Problem:</h3>\n<p>Say you have an array for which the <em>i</em>th element is the price of a given stock on day <em>i</em>.</p>\n<p>Design an algorithm to find the maximum profit. You may complete at most <em>two</em> transactions.</p>\n<p>**Note:**You may not engage in multiple transactions at the same time (i.e., you must sell the stock before you buy again).</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [3,3,5,0,0,3,1,4]\nOutput: 6\nExplanation: Buy on day 4 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.\n             Then buy on day 7 (price = 1) and sell on day 8 (price = 4), profit = 4-1 = 3.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [1,2,3,4,5]\nOutput: 4\nExplanation: Buy on day 1 (price = 1) and sell on day 5 (price = 5), profit = 5-1 = 4.\n             Note that you cannot buy on day 1, buy on day 2 and sell them later, as you are\n             engaging multiple transactions at the same time. You must sell before buying again.</code></pre></div>\n<p><strong>Example 3:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [7,6,4,3,1]\nOutput: 0\nExplanation: In this case, no transaction is done, i.e. max profit = 0.</code></pre></div>\n<h3>Solution:</h3>\n<p>Multiple transactions may not be engaged in at the same time. That means if we view the days that involed in the same transaction as a group, there won't be any intersection. We may complete at most <em>two</em> transactions, so divide the days into two groups, <code class=\"language-text\">[0...k]</code> and <code class=\"language-text\">[k...n-1]</code>. Notice <code class=\"language-text\">k</code> exists in both groups because technically we can sell out then immediately buy in at the same day.</p>\n<p>Define <code class=\"language-text\">p1(i)</code> to be the max profit of day <code class=\"language-text\">[0...i]</code>. This is just like the problem of <a href=\"./121.%20Best%20Time%20to%20Buy%20and%20Sell%20Stock.md\">121. Best Time to Buy and Sell Stock</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">p1(0) = 0\np1(i) = max( p1(i-1), prices[i] - min(prices[0], ..., prices[i-1]) ), 0 &lt; i &lt;= n-1</code></pre></div>\n<p>Define <code class=\"language-text\">p2(i)</code> to be the max profit of day <code class=\"language-text\">[i...n-1]</code>. This is the mirror of <code class=\"language-text\">p1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">p2(n-1) = 0\np2(i) = max( p2(i+1), max(prices[i], ..., prices[n-1]) - prices[i] ), n-1 > i >= 0</code></pre></div>\n<p>Define <code class=\"language-text\">f(k)</code> to be <code class=\"language-text\">p1(k) + p2(k)</code>. We need to get <code class=\"language-text\">max( f(0), ..., f(n-1) )</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} prices\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxProfit</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">prices</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> len <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>len <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> dp <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> min <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>dp<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">-</span> min<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        min <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> min<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">let</span> p2 <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> max <span class=\"token operator\">=</span> prices<span class=\"token punctuation\">[</span>len <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> len <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        max <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> max<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        p2 <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>p2<span class=\"token punctuation\">,</span> max <span class=\"token operator\">-</span> prices<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        dp<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> p2<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>dp<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Hard\nRelated Topics:\n\"Tree\": <a href=\"https://leetcode.com/tag/tree\">https://leetcode.com/tag/tree</a>\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\nSimilar Questions:\n\"Path Sum\": <a href=\"https://leetcode.com/problems/path-sum\">https://leetcode.com/problems/path-sum</a>\n\"Sum Root to Leaf Numbers\": <a href=\"https://leetcode.com/problems/sum-root-to-leaf-numbers\">https://leetcode.com/problems/sum-root-to-leaf-numbers</a>\n\"Path Sum IV\": <a href=\"https://leetcode.com/problems/path-sum-iv\">https://leetcode.com/problems/path-sum-iv</a>\n\"Longest Univalue Path\": <a href=\"https://leetcode.com/problems/longest-univalue-path\">https://leetcode.com/problems/longest-univalue-path</a></p>\n<hr>\n<p><a href=\"#124-binary-tree-maximum-path-sumhttpsleetcodecomproblemsbinary-tree-maximum-path-sumdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/binary-tree-maximum-path-sum/description/\">124. Binary Tree Maximum Path Sum</a></h2>\n<h3>Problem:</h3>\n<p>Given a <strong>non-empty</strong> binary tree, find the maximum path sum.</p>\n<p>For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must contain <strong>at least one node</strong> and does not need to go through the root.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [1,2,3]\n\n       1\n      / \\\n     2   3\n\nOutput: 6</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [-10,9,20,null,null,15,7]\n\n   -10\n   / \\\n  9  20\n    /  \\\n   15   7\n\nOutput: 42</code></pre></div>\n<h3>Solution:</h3>\n<p>For every <code class=\"language-text\">node</code>, there are six possible ways to get the max path sum:</p>\n<ul>\n<li>\n<p>With <code class=\"language-text\">node.val</code></p>\n<ol>\n<li><code class=\"language-text\">node.val</code> plus the max sum of a path that ends with <code class=\"language-text\">node.left</code>.</li>\n<li><code class=\"language-text\">node.val</code> plus the max sum of a path that starts with <code class=\"language-text\">node.right</code>.</li>\n<li><code class=\"language-text\">node.val</code> plus the max sum of both paths.</li>\n<li>Just <code class=\"language-text\">node.val</code> (the max sum of both paths are negative).</li>\n</ol>\n</li>\n<li>\n<p>Without<code class=\"language-text\">node.val</code> (disconnected)</p>\n<ol>\n<li>The max-sum path is somewhere under the <code class=\"language-text\">node.left</code> subtree.</li>\n<li>The max-sum path is somewhere under the <code class=\"language-text\">node.right</code> subtree.</li>\n</ol>\n</li>\n</ul>\n<p>There are two ways to implement this.</p>\n<h4>ONE</h4>\n<p>Define a function that returns two values. The max sum of a path that may or may not end with <code class=\"language-text\">root</code> node, and the max sum of the path that ends with <code class=\"language-text\">root</code> node.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxPathSum</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span><span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {number[]}\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> left <span class=\"token operator\">=</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> right <span class=\"token operator\">=</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> root<span class=\"token punctuation\">.</span>val <span class=\"token operator\">+</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> left<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> left<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> right<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> root<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h4>TWO</h4>\n<p>Just return the later (max sum of a path that ends with <code class=\"language-text\">root</code>). Maintain a global variable to store the disconnected max sum.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">maxPathSum</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> global <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">max</span><span class=\"token operator\">:</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">,</span> global<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> global<span class=\"token punctuation\">.</span>max<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @param {object} global\n * @param {number} global.max\n * @return {number[]}\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">root<span class=\"token punctuation\">,</span> global</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> left <span class=\"token operator\">=</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">,</span> global<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> right <span class=\"token operator\">=</span> <span class=\"token function\">_maxPathSum</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">,</span> global<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> localMax <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> root<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">;</span>\n    global<span class=\"token punctuation\">.</span>max <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>global<span class=\"token punctuation\">.</span>max<span class=\"token punctuation\">,</span> localMax<span class=\"token punctuation\">,</span> root<span class=\"token punctuation\">.</span>val <span class=\"token operator\">+</span> left <span class=\"token operator\">+</span> right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> localMax<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<p>Difficulty: Easy\nRelated Topics:\n\"Two Pointers\": <a href=\"https://leetcode.com/tag/two-pointers\">https://leetcode.com/tag/two-pointers</a>\n\"String\": <a href=\"https://leetcode.com/tag/string\">https://leetcode.com/tag/string</a>\nSimilar Questions:\n\"Palindrome Linked List\": <a href=\"https://leetcode.com/problems/palindrome-linked-list\">https://leetcode.com/problems/palindrome-linked-list</a>\n\"Valid Palindrome II\": <a href=\"https://leetcode.com/problems/valid-palindrome-ii\">https://leetcode.com/problems/valid-palindrome-ii</a></p>\n<hr>\n<p><a href=\"#125-valid-palindromehttpsleetcodecomproblemsvalid-palindromedescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/valid-palindrome/description/\">125. Valid Palindrome</a></h2>\n<h3>Problem:</h3>\n<p>Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.</p>\n<p><strong>Note:</strong> For the purpose of this problem, we define empty string as valid palindrome.</p>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"A man, a plan, a canal: Panama\"\nOutput: true</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: \"race a car\"\nOutput: false</code></pre></div>\n<h3>Solution:</h3>\n<h4>ONE</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> clean <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^a-z0-9]*</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> clean<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> clean<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>TWO</h4>\n<p>Remove non-alphanumeric characters then compare.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> clean <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^a-zA-Z0-9]</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">=</span> clean<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> j<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>clean<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> clean<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>THREE</h4>\n<p>Compare the char codes.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} s\n * @return {boolean}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">isPalindrome</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> j<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> left <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> j <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">&lt;</span> <span class=\"token number\">48</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">></span> <span class=\"token number\">57</span> <span class=\"token operator\">&amp;&amp;</span> left <span class=\"token operator\">&lt;</span> <span class=\"token number\">65</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">></span> <span class=\"token number\">90</span> <span class=\"token operator\">&amp;&amp;</span> left <span class=\"token operator\">&lt;</span> <span class=\"token number\">97</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> left <span class=\"token operator\">></span> <span class=\"token number\">122</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            left <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token operator\">++</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">>=</span> j<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">>=</span> <span class=\"token number\">65</span> <span class=\"token operator\">&amp;&amp;</span> left <span class=\"token operator\">&lt;=</span> <span class=\"token number\">90</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            left <span class=\"token operator\">+=</span> <span class=\"token number\">32</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">let</span> right <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> j <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>right <span class=\"token operator\">&lt;</span> <span class=\"token number\">48</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>right <span class=\"token operator\">></span> <span class=\"token number\">57</span> <span class=\"token operator\">&amp;&amp;</span> right <span class=\"token operator\">&lt;</span> <span class=\"token number\">65</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>right <span class=\"token operator\">></span> <span class=\"token number\">90</span> <span class=\"token operator\">&amp;&amp;</span> right <span class=\"token operator\">&lt;</span> <span class=\"token number\">97</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> right <span class=\"token operator\">></span> <span class=\"token number\">122</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            right <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token operator\">--</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">>=</span> j<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>right <span class=\"token operator\">>=</span> <span class=\"token number\">65</span> <span class=\"token operator\">&amp;&amp;</span> right <span class=\"token operator\">&lt;=</span> <span class=\"token number\">90</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            right <span class=\"token operator\">+=</span> <span class=\"token number\">32</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">!==</span> right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Hard\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"String\": <a href=\"https://leetcode.com/tag/string\">https://leetcode.com/tag/string</a>\n\"Backtracking\": <a href=\"https://leetcode.com/tag/backtracking\">https://leetcode.com/tag/backtracking</a>\n\"Breadth-first Search\": <a href=\"https://leetcode.com/tag/breadth-first-search\">https://leetcode.com/tag/breadth-first-search</a>\nSimilar Questions:\n\"Word Ladder\": <a href=\"https://leetcode.com/problems/word-ladder\">https://leetcode.com/problems/word-ladder</a></p>\n<hr>\n<p><a href=\"#126-word-ladder-iihttpsleetcodecomproblemsword-ladder-iidescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/word-ladder-ii/description/\">126. Word Ladder II</a></h2>\n<h3>Problem:</h3>\n<p>Given two words (<em>beginWord</em> and <em>endWord</em>), and a dictionary's word list, find all shortest transformation sequence(s) from <em>beginWord</em> to <em>endWord</em>, such that:</p>\n<ol>\n<li>Only one letter can be changed at a time</li>\n<li>Each transformed word must exist in the word list. Note that <em>beginWord</em> is <em>not</em> a transformed word.</li>\n</ol>\n<p><strong>Note:</strong></p>\n<ul>\n<li>Return an empty list if there is no such transformation sequence.</li>\n<li>All words have the same length.</li>\n<li>All words contain only lowercase alphabetic characters.</li>\n<li>You may assume no duplicates in the word list.</li>\n<li>You may assume <em>beginWord</em> and <em>endWord</em> are non-empty and are not the same.</li>\n</ul>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nbeginWord = \"hit\",\nendWord = \"cog\",\nwordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\n\nOutput:\n[\n  [\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],\n  [\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]\n]</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nbeginWord = \"hit\"\nendWord = \"cog\"\nwordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\n\nOutput: []\n\nExplanation: The endWord \"cog\" is not in wordList, therefore no possible transformation.</code></pre></div>\n<h3>Solution:</h3>\n<p>This is just like <a href=\"./127.%20Word%20Ladder\">127. Word Ladder</a>.</p>\n<p>The constrain still works, but instead of deleting the words right away, collect them and delete them all when a level ends, so that we can reuse the words (matching different parents in the same level).</p>\n<p>The items in the queue are not just words now. Parent nodes are also kept so that we can backtrack the path from the end.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} beginWord\n * @param {string} endWord\n * @param {string[]} wordList\n * @return {string[][]}\n */</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">findLadders</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">beginWord<span class=\"token punctuation\">,</span> endWord<span class=\"token punctuation\">,</span> wordList</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    wordList <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>wordList<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>wordList<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>endWord<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> <span class=\"token constant\">ALPHABET</span> <span class=\"token operator\">=</span> <span class=\"token string\">'abcdefghijklmnopqrstuvwxyz'</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> isEndWordFound <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> levelWords <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span>beginWord<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>isEndWordFound<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            levelWords<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">word</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> wordList<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            levelWords<span class=\"token punctuation\">.</span><span class=\"token function\">clear</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> word <span class=\"token operator\">=</span> node<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> head <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> tail <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> c <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> c <span class=\"token operator\">&lt;</span> <span class=\"token number\">26</span><span class=\"token punctuation\">;</span> c<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">ALPHABET</span><span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> word<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">const</span> w <span class=\"token operator\">=</span> head <span class=\"token operator\">+</span> <span class=\"token constant\">ALPHABET</span><span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> tail<span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>w <span class=\"token operator\">===</span> endWord<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">const</span> path <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>endWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> n <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span> n <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span> n <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            path<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        isEndWordFound <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>wordList<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        levelWords<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>w<span class=\"token punctuation\">,</span> node<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Breadth-first Search\": <a href=\"https://leetcode.com/tag/breadth-first-search\">https://leetcode.com/tag/breadth-first-search</a>\nSimilar Questions:\n\"Word Ladder II\": <a href=\"https://leetcode.com/problems/word-ladder-ii\">https://leetcode.com/problems/word-ladder-ii</a>\n\"Minimum Genetic Mutation\": <a href=\"https://leetcode.com/problems/minimum-genetic-mutation\">https://leetcode.com/problems/minimum-genetic-mutation</a></p>\n<hr>\n<p><a href=\"#127-word-ladderhttpsleetcodecomproblemsword-ladderdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/word-ladder/description/\">127. Word Ladder</a></h2>\n<h3>Problem:</h3>\n<p>Given two words (<em>beginWord</em> and <em>endWord</em>), and a dictionary's word list, find the length of shortest transformation sequence from <em>beginWord</em> to <em>endWord</em>, such that:</p>\n<ol>\n<li>Only one letter can be changed at a time.</li>\n<li>Each transformed word must exist in the word list. Note that <em>beginWord</em> is <em>not</em> a transformed word.</li>\n</ol>\n<p><strong>Note:</strong></p>\n<ul>\n<li>Return 0 if there is no such transformation sequence.</li>\n<li>All words have the same length.</li>\n<li>All words contain only lowercase alphabetic characters.</li>\n<li>You may assume no duplicates in the word list.</li>\n<li>You may assume <em>beginWord</em> and <em>endWord</em> are non-empty and are not the same.</li>\n</ul>\n<p><strong>Example 1:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nbeginWord = \"hit\",\nendWord = \"cog\",\nwordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]\n\nOutput: 5\n\nExplanation: As one shortest transformation is \"hit\" -> \"hot\" -> \"dot\" -> \"dog\" -> \"cog\",\nreturn its length 5.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input:\nbeginWord = \"hit\"\nendWord = \"cog\"\nwordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\"]\n\nOutput: 0\n\nExplanation: The endWord \"cog\" is not in wordList, therefore no possible transformation.</code></pre></div>\n<h3>Solution:</h3>\n<p>Think of it as building a tree, with <code class=\"language-text\">begineWord</code> as root and <code class=\"language-text\">endWord</code> as leaves.</p>\n<p>The best way control the depth (length of the shortest transformations) while building the tree is level-order traversal (BFS).</p>\n<p>We do not actually build the tree because it is expensive (astronomical if the list is huge). In fact, we only need one shortest path. So just like Dijkstra's algorithm, we say that the first time (level <code class=\"language-text\">i</code>) we encounter a word that turns out to be in a shortest path, then level <code class=\"language-text\">i</code> is the lowest level this word could ever get. We can safely remove it from the <code class=\"language-text\">wordList</code>.</p>\n<p>To find all the next words, instead of filtering the <code class=\"language-text\">wordList</code>, enumerate all 25 possible words and check if in <code class=\"language-text\">wordList</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {string} beginWord\n * @param {string} endWord\n * @param {string[]} wordList\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">ladderLength</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">beginWord<span class=\"token punctuation\">,</span> endWord<span class=\"token punctuation\">,</span> wordList</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    wordList <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>wordList<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>wordList<span class=\"token punctuation\">.</span><span class=\"token function\">has</span><span class=\"token punctuation\">(</span>endWord<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> <span class=\"token constant\">ALPHABET</span> <span class=\"token operator\">=</span> <span class=\"token string\">'abcdefghijklmnopqrstuvwxyz'</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> level <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>beginWord<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> word <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>word <span class=\"token operator\">===</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            level<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> head <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> tail <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> c <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> c <span class=\"token operator\">&lt;</span> <span class=\"token number\">26</span><span class=\"token punctuation\">;</span> c<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">ALPHABET</span><span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span> <span class=\"token operator\">!==</span> word<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">const</span> word <span class=\"token operator\">=</span> head <span class=\"token operator\">+</span> <span class=\"token constant\">ALPHABET</span><span class=\"token punctuation\">[</span>c<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> tail<span class=\"token punctuation\">;</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>word <span class=\"token operator\">===</span> endWord<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> level <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>wordList<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Hard\nRelated Topics:\n\"Array\": <a href=\"https://leetcode.com/tag/array\">https://leetcode.com/tag/array</a>\n\"Union Find\": <a href=\"https://leetcode.com/tag/union-find\">https://leetcode.com/tag/union-find</a>\nSimilar Questions:\n\"Binary Tree Longest Consecutive Sequence\": <a href=\"https://leetcode.com/problems/binary-tree-longest-consecutive-sequence\">https://leetcode.com/problems/binary-tree-longest-consecutive-sequence</a></p>\n<hr>\n<p><a href=\"#128-longest-consecutive-sequencehttpsleetcodecomproblemslongest-consecutive-sequencedescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/longest-consecutive-sequence/description/\">128. Longest Consecutive Sequence</a></h2>\n<h3>Problem:</h3>\n<p>Given an unsorted array of integers, find the length of the longest consecutive elements sequence.</p>\n<p>Your algorithm should run in O(<em>n</em>) complexity.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [100, 4, 200, 1, 3, 2]\nOutput: 4\nExplanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.</code></pre></div>\n<h3>Solution:</h3>\n<p>Build a Set from the list. Pick a number, find all it's adjacent numbers that are also in the Set. Count them and remove them all from the Set. Repeat until the Set is empty. Time complexity O(n + n) = O(n).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} nums\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">longestConsecutive</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">nums</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> numSet <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span>nums<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> maxCount <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>numSet<span class=\"token punctuation\">.</span>size <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> num <span class=\"token operator\">=</span> numSet<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span>\n        numSet<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> n <span class=\"token operator\">=</span> num <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> numSet<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> n<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            count<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> n <span class=\"token operator\">=</span> num <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> numSet<span class=\"token punctuation\">.</span><span class=\"token function\">delete</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> n<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            count<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">></span> maxCount<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            maxCount <span class=\"token operator\">=</span> count<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> maxCount<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Tree\": <a href=\"https://leetcode.com/tag/tree\">https://leetcode.com/tag/tree</a>\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\nSimilar Questions:\n\"Path Sum\": <a href=\"https://leetcode.com/problems/path-sum\">https://leetcode.com/problems/path-sum</a>\n\"Binary Tree Maximum Path Sum\": <a href=\"https://leetcode.com/problems/binary-tree-maximum-path-sum\">https://leetcode.com/problems/binary-tree-maximum-path-sum</a></p>\n<hr>\n<p><a href=\"#129-sum-root-to-leaf-numbershttpsleetcodecomproblemssum-root-to-leaf-numbersdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/sum-root-to-leaf-numbers/description/\">129. Sum Root to Leaf Numbers</a></h2>\n<h3>Problem:</h3>\n<p>Given a binary tree containing digits from <code class=\"language-text\">0-9</code> only, each root-to-leaf path could represent a number.</p>\n<p>An example is the root-to-leaf path <code class=\"language-text\">1->2->3</code> which represents the number <code class=\"language-text\">123</code>.</p>\n<p>Find the total sum of all root-to-leaf numbers.</p>\n<p><strong>Note:</strong> A leaf is a node with no children.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [1,2,3]\n    1\n   / \\\n  2   3\nOutput: 25\nExplanation:\nThe root-to-leaf path 1->2 represents the number 12.\nThe root-to-leaf path 1->3 represents the number 13.\nTherefore, sum = 12 + 13 = 25.</code></pre></div>\n<p><strong>Example 2:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Input: [4,9,0,5,1]\n    4\n   / \\\n  9   0\n / \\\n5   1\nOutput: 1026\nExplanation:\nThe root-to-leaf path 4->9->5 represents the number 495.\nThe root-to-leaf path 4->9->1 represents the number 491.\nThe root-to-leaf path 4->0 represents the number 40.\nTherefore, sum = 495 + 491 + 40 = 1026.</code></pre></div>\n<h3>Solution:</h3>\n<p>To write a clean solution for this promblem, use <code class=\"language-text\">0</code> as indicator of leaf node. If all the children get <code class=\"language-text\">0</code>, it is a leaf node, return the sum of current level.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {number}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">sumNumbers</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root<span class=\"token punctuation\">,</span> sum <span class=\"token operator\">=</span> <span class=\"token number\">0</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    sum <span class=\"token operator\">=</span> sum <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">+</span> root<span class=\"token punctuation\">.</span>val<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">sumNumbers</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">,</span> sum<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">sumNumbers</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">,</span> sum<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> sum<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\n\"Breadth-first Search\": <a href=\"https://leetcode.com/tag/breadth-first-search\">https://leetcode.com/tag/breadth-first-search</a>\n\"Union Find\": <a href=\"https://leetcode.com/tag/union-find\">https://leetcode.com/tag/union-find</a>\nSimilar Questions:\n\"Number of Islands\": <a href=\"https://leetcode.com/problems/number-of-islands\">https://leetcode.com/problems/number-of-islands</a>\n\"Walls and Gates\": <a href=\"https://leetcode.com/problems/walls-and-gates\">https://leetcode.com/problems/walls-and-gates</a></p>\n<hr>\n<p><a href=\"#130-surrounded-regionshttpsleetcodecomproblemssurrounded-regionsdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/surrounded-regions/description/\">130. Surrounded Regions</a></h2>\n<h3>Problem:</h3>\n<p>Given a 2D board containing <code class=\"language-text\">'X'</code> and <code class=\"language-text\">'O'</code> (<strong>the letter O</strong>), capture all regions surrounded by <code class=\"language-text\">'X'</code>.</p>\n<p>A region is captured by flipping all <code class=\"language-text\">'O'</code>s into <code class=\"language-text\">'X'</code>s in that surrounded region.</p>\n<p><strong>Example:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">X X X X\nX O O X\nX X O X\nX O X X</code></pre></div>\n<p>After running your function, the board should be:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">X X X X\nX X X X\nX X X X\nX O X X</code></pre></div>\n<p><strong>Explanation:</strong></p>\n<p>Surrounded regions shouldn't be on the border, which means that any <code class=\"language-text\">'O'</code> on the border of the board are not flipped to <code class=\"language-text\">'X'</code>. Any <code class=\"language-text\">'O'</code> that is not on the border and it is not connected to an <code class=\"language-text\">'O'</code> on the border will be flipped to <code class=\"language-text\">'X'</code>. Two cells are connected if they are adjacent cells connected horizontally or vertically.</p>\n<h3>Solution:</h3>\n<p>Find all the <code class=\"language-text\">O</code>s that are connected to the <code class=\"language-text\">O</code>s on the border, change them to <code class=\"language-text\">#</code>. Then scan the board, change <code class=\"language-text\">O</code> to <code class=\"language-text\">X</code> and <code class=\"language-text\">#</code> back to <code class=\"language-text\">O</code>.</p>\n<p>The process of finding the connected <code class=\"language-text\">O</code>s is just like tree traversal. <code class=\"language-text\">O</code>s on the border are the same level. Their children are the second level. And so on.</p>\n<p>So both BFS and DFS are good. I prefer BFS when pruning is not needed in favor of its readability.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {character[][]} board\n * @return {void} Do not return anything, modify board in-place instead.\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">solve</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">board</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> height <span class=\"token operator\">=</span> board<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>height <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">const</span> width <span class=\"token operator\">=</span> board<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>width <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">const</span> rowend <span class=\"token operator\">=</span> height <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> colend <span class=\"token operator\">=</span> width <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> row <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> row <span class=\"token operator\">&lt;</span> height<span class=\"token punctuation\">;</span> row<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>colend<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>colend<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">,</span> colend<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> col <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> col <span class=\"token operator\">&lt;</span> width<span class=\"token punctuation\">;</span> col<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> col<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>rowend<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>rowend<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>rowend<span class=\"token punctuation\">,</span> col<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> row <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> col <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>row <span class=\"token operator\">&lt;</span> rowend <span class=\"token operator\">&amp;&amp;</span> board<span class=\"token punctuation\">[</span>row <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> col<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>row <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> board<span class=\"token punctuation\">[</span>row <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> col<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">,</span> col <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">;</span>\n            queue<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">,</span> col <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> row <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> row <span class=\"token operator\">&lt;</span> height<span class=\"token punctuation\">;</span> row<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> col <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> col <span class=\"token operator\">&lt;</span> width<span class=\"token punctuation\">;</span> col<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                board<span class=\"token punctuation\">[</span>row<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>col<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'X'</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<p>Difficulty: Medium\nRelated Topics:\n\"Depth-first Search\": <a href=\"https://leetcode.com/tag/depth-first-search\">https://leetcode.com/tag/depth-first-search</a>\n\"Breadth-first Search\": <a href=\"https://leetcode.com/tag/breadth-first-search\">https://leetcode.com/tag/breadth-first-search</a>\n\"Graph\": <a href=\"https://leetcode.com/tag/graph\">https://leetcode.com/tag/graph</a>\nSimilar Questions:\n\"Copy List with Random Pointer\": <a href=\"https://leetcode.com/problems/copy-list-with-random-pointer\">https://leetcode.com/problems/copy-list-with-random-pointer</a></p>\n<hr>\n<p><a href=\"#133-clone-graphhttpsleetcodecomproblemsclone-graphdescription\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h2>➤ <a href=\"https://leetcode.com/problems/clone-graph/description/\">133. Clone Graph</a></h2>\n<h3>Problem:</h3>\n<p>Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph contains a <code class=\"language-text\">label</code> (<code class=\"language-text\">int</code>) and a list (<code class=\"language-text\">List[UndirectedGraphNode]</code>) of its <code class=\"language-text\">neighbors</code>. There is an edge between the given node and each of the nodes in its neighbors.</p>\n<p>OJ's undirected graph serialization (so you can understand error output):</p>\n<p>Nodes are labeled uniquely.</p>\n<p>We use <code class=\"language-text\">#</code> as a separator for each node, and <code class=\"language-text\">,</code> as a separator for node label and each neighbor of the node.</p>\n<p>As an example, consider the serialized graph <code class=\"language-text\">{0,1,2#1,2#2,2}</code>.</p>\n<p>The graph has a total of three nodes, and therefore contains three parts as separated by <code class=\"language-text\">#</code>.</p>\n<ol>\n<li>First node is labeled as <code class=\"language-text\">0</code>. Connect node <code class=\"language-text\">0</code> to both nodes <code class=\"language-text\">1</code> and <code class=\"language-text\">2</code>.</li>\n<li>Second node is labeled as <code class=\"language-text\">1</code>. Connect node <code class=\"language-text\">1</code> to node <code class=\"language-text\">2</code>.</li>\n<li>Third node is labeled as <code class=\"language-text\">2</code>. Connect node <code class=\"language-text\">2</code> to node <code class=\"language-text\">2</code> (itself), thus forming a self-cycle.</li>\n</ol>\n<p>Visually, the graph looks like the following:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">       1\n      / \\\n     /   \\\n    0 --- 2\n         / \\\n         \\_/</code></pre></div>\n<p><strong>Note</strong>: The information about the tree serialization is only meant so that you can understand error output if you get a wrong answer. You don't need to understand the serialization to solve the problem.</p>\n<h3>Solution:</h3>\n<p>DFS. Cache the visited node before entering the next recursion.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for undirected graph.\n * function UndirectedGraphNode(label) {\n *     this.label = label;\n *     this.neighbors = [];   // Array of UndirectedGraphNode\n * }\n */</span>\n\n<span class=\"token comment\">/**\n * @param {UndirectedGraphNode} graph\n * @return {UndirectedGraphNode}\n */</span>\n<span class=\"token keyword\">let</span> <span class=\"token function-variable function\">cloneGraph</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">graph</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> cache <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">_clone</span><span class=\"token punctuation\">(</span>graph<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">_clone</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">graph</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>graph<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> graph<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">const</span> label <span class=\"token operator\">=</span> graph<span class=\"token punctuation\">.</span>label<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>cache<span class=\"token punctuation\">[</span>label<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            cache<span class=\"token punctuation\">[</span>label<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">UndirectedGraphNode</span><span class=\"token punctuation\">(</span>label<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            cache<span class=\"token punctuation\">[</span>label<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>neighbors <span class=\"token operator\">=</span> graph<span class=\"token punctuation\">.</span>neighbors<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_clone<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> cache<span class=\"token punctuation\">[</span>label<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><img src=\"https://github.com/everthis/leetcode-js/blob/master/images/binary-tree-upside-down.webp\" alt=\"alt text\" title=\"binary-tree-upside-down\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * Definition for a binary tree node.\n * function TreeNode(val) {\n *     this.val = val;\n *     this.left = this.right = null;\n * }\n */</span>\n<span class=\"token comment\">/**\n * @param {TreeNode} root\n * @return {TreeNode}\n */</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">upsideDownBinaryTree</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> curr <span class=\"token operator\">=</span> root<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> temp <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> prev <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>curr <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        next <span class=\"token operator\">=</span> curr<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n        curr<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> temp<span class=\"token punctuation\">;</span>\n        temp <span class=\"token operator\">=</span> curr<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n        curr<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> prev<span class=\"token punctuation\">;</span>\n        prev <span class=\"token operator\">=</span> curr<span class=\"token punctuation\">;</span>\n        curr <span class=\"token operator\">=</span> next<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> prev<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// another</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">upsideDownBinaryTree</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">root</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>root <span class=\"token operator\">==</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">||</span> root<span class=\"token punctuation\">.</span>left <span class=\"token operator\">==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> root<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">const</span> newRoot <span class=\"token operator\">=</span> <span class=\"token function\">upsideDownBinaryTree</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n    root<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> root<span class=\"token punctuation\">;</span>\n    root<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    root<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> newRoot<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><img src=\"https://github.com/everthis/leetcode-js/blob/master/images/maximum-sum-circular-subarray.png\" alt=\"alt text\" title=\"maximum-sum-circular-subarray\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[]} A\n * @return {number}\n */</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">maxSubarraySumCircular</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token constant\">A</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> minSum <span class=\"token operator\">=</span> <span class=\"token number\">Infinity</span><span class=\"token punctuation\">,</span>\n        sum <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n        maxSum <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">,</span>\n        curMax <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n        curMin <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> a <span class=\"token keyword\">of</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        sum <span class=\"token operator\">+=</span> a<span class=\"token punctuation\">;</span>\n        curMax <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>curMax <span class=\"token operator\">+</span> a<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        maxSum <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>maxSum<span class=\"token punctuation\">,</span> curMax<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        curMin <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>curMin <span class=\"token operator\">+</span> a<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        minSum <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>minSum<span class=\"token punctuation\">,</span> curMin<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> maxSum <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>maxSum<span class=\"token punctuation\">,</span> sum <span class=\"token operator\">-</span> minSum<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> maxSum<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><a href=\"#balanced-binary-tree---leetcode\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>\n<h1>➤ Balanced Binary Tree - LeetCode</h1>\n<blockquote>\n<p>Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.</p>\n</blockquote>\n<p>Given a binary tree, determine if it is height-balanced.</p>\n<p>For this problem, a height-balanced binary tree is defined as:</p>\n<blockquote>\n<p>a binary tree in which the left and right subtrees of <em>every</em> node differ in height by no more than 1.</p>\n</blockquote>\n<p><strong>Example 1:</strong></p>\n<p><img src=\"https://assets.leetcode.com/uploads/2020/10/06/balance_1.jpg\" alt=\"image\"></p>\n<p><strong>Input:</strong> root = [3,9,20,null,null,15,7]\n<strong>Output:</strong> true</p>\n<p><strong>Example 2:</strong></p>\n<p><img src=\"https://assets.leetcode.com/uploads/2020/10/06/balance_2.jpg\" alt=\"image\"></p>\n<p><strong>Input:</strong> root = [1,2,2,3,3,null,null,4,4]\n<strong>Output:</strong> false</p>\n<p><strong>Example 3:</strong></p>\n<p><strong>Input:</strong> root = []\n<strong>Output:</strong> true</p>\n<p><strong>Constraints:</strong></p>\n<ul>\n<li>The number of nodes in the tree is in the range <code class=\"language-text\">[0, 5000]</code>.</li>\n<li><code class=\"language-text\">-104 &lt;= Node.val &lt;= 104</code></li>\n</ul>\n<p><a href=\"https://leetcode.com/problems/balanced-binary-tree/\">Source</a># Convert Sorted Array to Binary Search Tree</p>\n<blockquote>\n<p>Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.</p>\n</blockquote>\n<p>Given an array where elements are sorted in ascending order, convert it to a height balanced BST.</p>\n<p>For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of <em>every</em> node never differ by more than 1.</p>\n<p><strong>Example:</strong></p>\n<p>Given the sorted array: [-10,-3,0,5,9],</p>\n<p>One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  0\n / \\\\</code></pre></div>\n<p>-3 9\n/ /\n-10 5</p>\n<p><a href=\"https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/\">Source</a># Delete Node in a BST</p>\n<blockquote>\n<p>Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.</p>\n</blockquote>\n<p>Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.</p>\n<p>Basically, the deletion can be divided into two stages:</p>\n<ol>\n<li>Search for a node to remove.</li>\n<li>If the node is found, delete the node.</li>\n</ol>\n<p><strong>Follow up:</strong> Can you solve it with time complexity <code class=\"language-text\">O(height of tree)</code>?</p>\n<p><strong>Example 1:</strong></p>\n<p><img src=\"https://assets.leetcode.com/uploads/2020/09/04/del_node_1.jpg\" alt=\"image\"></p>\n<p><strong>Input:</strong> root = [5,3,6,2,4,null,7], key = 3\n<strong>Output:</strong> [5,4,6,2,null,null,7]\n<strong>Explanation:</strong> Given key to delete is 3. So we find the node with value 3 and delete it.\nOne valid answer is [5,4,6,2,null,null,7], shown in the above BST.\nPlease notice that another valid answer is [5,2,6,null,4,null,7] and it's also accepted.</p>\n<p><img src=\"https://assets.leetcode.com/uploads/2020/09/04/del_node_supp.jpg\" alt=\"image\"></p>\n<p><strong>Example 2:</strong></p>\n<p><strong>Input:</strong> root = [5,3,6,2,4,null,7], key = 0\n<strong>Output:</strong> [5,3,6,2,4,null,7]\n<strong>Explanation:</strong> The tree does not contain a node with value = 0.</p>\n<p><strong>Example 3:</strong></p>\n<p><strong>Input:</strong> root = [], key = 0\n<strong>Output:</strong> []</p>\n<p><strong>Constraints:</strong></p>\n<ul>\n<li>The number of nodes in the tree is in the range <code class=\"language-text\">[0, 104]</code>.</li>\n<li><code class=\"language-text\">-105 &lt;= Node.val &lt;= 105</code></li>\n<li>Each node has a <strong>unique</strong> value.</li>\n<li><code class=\"language-text\">root</code> is a valid binary search tree.</li>\n<li><code class=\"language-text\">-105 &lt;= key &lt;= 105</code></li>\n</ul>\n<p><a href=\"https://leetcode.com/problems/delete-node-in-a-bst/\">Source</a><img src=\"https://github.com/everthis/leetcode-js/blob/master/images/meeting-room-ii-0.jpg\" alt=\"alt text\" title=\"meeting-room-ii\">\n<img src=\"https://github.com/everthis/leetcode-js/blob/master/images/meeting-room-ii-1.jpg\" alt=\"alt text\" title=\"meeting-room-ii\"></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n * @param {number[][]} intervals\n * @return {number}\n */</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">minMeetingRooms</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">intervals</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> len <span class=\"token operator\">=</span> intervals<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> starts <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span>len<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> ends <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span>len<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        starts<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> intervals<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        ends<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> intervals<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    starts<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    ends<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> rooms <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> endsIdx <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>starts<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> ends<span class=\"token punctuation\">[</span>endsIdx<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> rooms<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">else</span> endsIdx<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> rooms<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><a href=\"#-\"><img src=\"https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png\" alt=\"-----------------------------------------------------\"></a></p>"},{"url":"/docs/overflow/html-spec/","relativePath":"docs/overflow/html-spec.md","relativeDir":"docs/overflow","base":"html-spec.md","name":"html-spec","frontmatter":{"title":"HTML SPEC","weight":0,"excerpt":"HTML SPEC","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"docs"},"html":"<h2>HTML SPEC</h2>\n<p><a href=\"https://github.com/whatwg/html/issues/new\">File an issue about the selected text</a></p>\n<p><a href=\"https://whatwg.org/\"><img src=\"https://resources.whatwg.org/logo.svg\" alt=\"WHATWG\"></a></p>\n<h2>Living Standard — Last Updated 29 October 2021</h2>\n<hr>\n<h2>Table of contents</h2>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#toc-introduction\">1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-infrastructure\">2 Common infrastructure</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-dom\">3 Semantics, structure, and APIs of HTML documents</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-semantics\">4 The elements of HTML</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-microdata\">5 Microdata</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-editing\">6 User interaction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-browsers\">7 Loading web pages</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-webappapis\">8 Web application APIs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-comms\">9 Communication</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-workers\">10 Web workers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-worklets\">11 Worklets</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-webstorage\">12 Web storage</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-syntax\">13 The HTML syntax</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-the-xhtml-syntax\">14 The XML syntax</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-rendering\">15 Rendering</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-obsolete\">16 Obsolete features</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-iana\">17 IANA considerations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-index\">Index</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-references\">References</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-acknowledgments\">Acknowledgments</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#toc-ipr\">Intellectual property rights</a></li>\n</ol>\n<h2>Full table of contents</h2>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#introduction\">1 Introduction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#abstract\">1.1 Where does this specification fit?</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#is-this-html5?\">1.2 Is this HTML5?</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#background\">1.3 Background</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#audience\">1.4 Audience</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#scope\">1.5 Scope</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#history-2\">1.6 History</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#design-notes\">1.7 Design notes</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#serialisability-of-script-execution\">1.7.1 Serializability of script execution</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#compliance-with-other-specifications\">1.7.2 Compliance with other specifications</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#extensibility\">1.7.3 Extensibility</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#html-vs-xhtml\">1.8 HTML vs XML syntax</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#structure-of-this-specification\">1.9 Structure of this specification</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#how-to-read-this-specification\">1.9.1 How to read this specification</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#typographic-conventions\">1.9.2 Typographic conventions</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#a-quick-introduction-to-html\">1.10 A quick introduction to HTML</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#writing-secure-applications-with-html\">1.10.1 Writing secure applications with HTML</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#common-pitfalls-to-avoid-when-using-the-scripting-apis\">1.10.2 Common pitfalls to avoid when using the scripting APIs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#how-to-catch-mistakes-when-writing-html:-validators-and-conformance-checkers\">1.10.3 How to catch mistakes when writing HTML: validators and conformance checkers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#conformance-requirements-for-authors\">1.11 Conformance requirements for authors</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#presentational-markup\">1.11.1 Presentational markup</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#syntax-errors\">1.11.2 Syntax errors</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#restrictions-on-content-models-and-on-attribute-values\">1.11.3 Restrictions on content models and on attribute values</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#suggested-reading\">1.12 Suggested reading</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#infrastructure\">2 Common infrastructure</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#terminology\">2.1 Terminology</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#parallelism\">2.1.1 Parallelism</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#resources\">2.1.2 Resources</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#xml\">2.1.3 XML compatibility</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dom-trees\">2.1.4 DOM trees</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#scripting-2\">2.1.5 Scripting</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#plugins\">2.1.6 Plugins</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#encoding-terminology\">2.1.7 Character encodings</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#conformance-classes\">2.1.8 Conformance classes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dependencies\">2.1.9 Dependencies</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#extensibility-2\">2.1.10 Extensibility</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#interactions-with-xpath-and-xslt\">2.1.11 Interactions with XPath and XSLT</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#policy-controlled-features\">2.2 Policy-controlled features</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#common-microsyntaxes\">2.3 Common microsyntaxes</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#common-parser-idioms\">2.3.1 Common parser idioms</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#boolean-attributes\">2.3.2 Boolean attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#keywords-and-enumerated-attributes\">2.3.3 Keywords and enumerated attributes</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#numbers\">2.3.4 Numbers</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#signed-integers\">2.3.4.1 Signed integers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#non-negative-integers\">2.3.4.2 Non-negative integers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#floating-point-numbers\">2.3.4.3 Floating-point numbers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#percentages-and-dimensions\">2.3.4.4 Percentages and lengths</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#nonzero-percentages-and-lengths\">2.3.4.5 Nonzero percentages and lengths</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#lists-of-floating-point-numbers\">2.3.4.6 Lists of floating-point numbers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#lists-of-dimensions\">2.3.4.7 Lists of dimensions</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#dates-and-times\">2.3.5 Dates and times</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#months\">2.3.5.1 Months</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dates\">2.3.5.2 Dates</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#yearless-dates\">2.3.5.3 Yearless dates</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#times\">2.3.5.4 Times</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#local-dates-and-times\">2.3.5.5 Local dates and times</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#time-zones\">2.3.5.6 Time zones</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#global-dates-and-times\">2.3.5.7 Global dates and times</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#weeks\">2.3.5.8 Weeks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#durations\">2.3.5.9 Durations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#vaguer-moments-in-time\">2.3.5.10 Vaguer moments in time</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#colours\">2.3.6 Colors</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#space-separated-tokens\">2.3.7 Space-separated tokens</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comma-separated-tokens\">2.3.8 Comma-separated tokens</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#syntax-references\">2.3.9 References</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#mq\">2.3.10 Media queries</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#urls\">2.4 URLs</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#terminology-2\">2.4.1 Terminology</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#resolving-urls\">2.4.2 Parsing URLs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dynamic-changes-to-base-urls\">2.4.3 Dynamic changes to base URLs</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#fetching-resources\">2.5 Fetching resources</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#terminology-3\">2.5.1 Terminology</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#content-type-sniffing\">2.5.2 Determining the type of a resource</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#extracting-character-encodings-from-meta-elements\">2.5.3 Extracting character encodings from <code class=\"language-text\">meta</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cors-settings-attributes\">2.5.4 CORS settings attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#referrer-policy-attributes\">2.5.5 Referrer policy attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#nonce-attributes\">2.5.6 Nonce attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#lazy-loading-attributes\">2.5.7 Lazy loading attributes</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#common-dom-interfaces\">2.6 Common DOM interfaces</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#reflecting-content-attributes-in-idl-attributes\">2.6.1 Reflecting content attributes in IDL attributes</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#collections\">2.6.2 Collections</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-htmlallcollection-interface\">2.6.2.1 The <code class=\"language-text\">HTMLAllCollection</code> interface</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#HTMLAllCollection-call\">2.6.2.1.1 [[Call]] ( thisArgument, argumentsList )</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-htmlformcontrolscollection-interface\">2.6.2.2 The <code class=\"language-text\">HTMLFormControlsCollection</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-htmloptionscollection-interface\">2.6.2.3 The <code class=\"language-text\">HTMLOptionsCollection</code> interface</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-domstringlist-interface\">2.6.3 The <code class=\"language-text\">DOMStringList</code> interface</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#safe-passing-of-structured-data\">2.7 Safe passing of structured data</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#serializable-objects\">2.7.1 Serializable objects</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#transferable-objects\">2.7.2 Transferable objects</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#structuredserializeinternal\">2.7.3 StructuredSerializeInternal ( value, forStorage [ , memory ] )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#structuredserialize\">2.7.4 StructuredSerialize ( value )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#structuredserializeforstorage\">2.7.5 StructuredSerializeForStorage ( value )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#structureddeserialize\">2.7.6 StructuredDeserialize ( serialized, targetRealm [ , memory ] )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#structuredserializewithtransfer\">2.7.7 StructuredSerializeWithTransfer ( value, transferList )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#structureddeserializewithtransfer\">2.7.8 StructuredDeserializeWithTransfer ( serializeWithTransferResult, targetRealm )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#performing-structured-clones-from-other-specifications\">2.7.9 Performing serialization and transferring from other specifications</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#structured-cloning\">2.7.10 Structured cloning API</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#dom\">3 Semantics, structure, and APIs of HTML documents</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#documents\">3.1 Documents</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-document-object\">3.1.1 The <code class=\"language-text\">Document</code> object</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-documentorshadowroot-interface\">3.1.2 The <code class=\"language-text\">DocumentOrShadowRoot</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#resource-metadata-management\">3.1.3 Resource metadata management</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#reporting-document-loading-status\">3.1.4 Reporting document loading status</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dom-tree-accessors\">3.1.5 DOM tree accessors</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#elements\">3.2 Elements</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#semantics-2\">3.2.1 Semantics</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#elements-in-the-dom\">3.2.2 Elements in the DOM</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#html-element-constructors\">3.2.3 HTML element constructors</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#element-definitions\">3.2.4 Element definitions</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#attributes\">3.2.4.1 Attributes</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#content-models\">3.2.5 Content models</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-nothing-content-model\">3.2.5.1 The \"nothing\" content model</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#kinds-of-content\">3.2.5.2 Kinds of content</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#metadata-content\">3.2.5.2.1 Metadata content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#flow-content\">3.2.5.2.2 Flow content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sectioning-content\">3.2.5.2.3 Sectioning content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#heading-content\">3.2.5.2.4 Heading content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#phrasing-content\">3.2.5.2.5 Phrasing content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#embedded-content-2\">3.2.5.2.6 Embedded content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#interactive-content\">3.2.5.2.7 Interactive content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#palpable-content\">3.2.5.2.8 Palpable content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-supporting-elements\">3.2.5.2.9 Script-supporting elements</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#transparent-content-models\">3.2.5.3 Transparent content models</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#paragraphs\">3.2.5.4 Paragraphs</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#global-attributes\">3.2.6 Global attributes</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-title-attribute\">3.2.6.1 The <code class=\"language-text\">title</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-lang-and-xml:lang-attributes\">3.2.6.2 The <code class=\"language-text\">lang</code> and <code class=\"language-text\">xml:lang</code> attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-translate-attribute\">3.2.6.3 The <code class=\"language-text\">translate</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-dir-attribute\">3.2.6.4 The <code class=\"language-text\">dir</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-style-attribute\">3.2.6.5 The <code class=\"language-text\">style</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#embedding-custom-non-visible-data-with-the-data-*-attributes\">3.2.6.6 Embedding custom non-visible data with the <code class=\"language-text\">data-*</code> attributes</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-innertext-idl-attribute\">3.2.7 The <code class=\"language-text\">innerText</code> and <code class=\"language-text\">outerText</code> properties</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#requirements-relating-to-the-bidirectional-algorithm\">3.2.8 Requirements relating to the bidirectional algorithm</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#authoring-conformance-criteria-for-bidirectional-algorithm-formatting-characters\">3.2.8.1 Authoring conformance criteria for bidirectional-algorithm formatting characters</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#user-agent-conformance-criteria\">3.2.8.2 User agent conformance criteria</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#wai-aria\">3.2.9 Requirements related to ARIA and to platform accessibility APIs</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#semantics\">4 The elements of HTML</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-root-element\">4.1 The document element</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-html-element\">4.1.1 The <code class=\"language-text\">html</code> element</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#document-metadata\">4.2 Document metadata</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-head-element\">4.2.1 The <code class=\"language-text\">head</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-title-element\">4.2.2 The <code class=\"language-text\">title</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-base-element\">4.2.3 The <code class=\"language-text\">base</code> element</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-link-element\">4.2.4 The <code class=\"language-text\">link</code> element</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#processing-the-media-attribute\">4.2.4.1 Processing the <code class=\"language-text\">media</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#processing-the-type-attribute\">4.2.4.2 Processing the <code class=\"language-text\">type</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#fetching-and-processing-a-resource-from-a-link-element\">4.2.4.3 Fetching and processing a resource from a <code class=\"language-text\">link</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#processing-link-headers\">4.2.4.4 Processing `<code class=\"language-text\">Link</code>` headers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#providing-users-with-a-means-to-follow-hyperlinks-created-using-the-link-element\">4.2.4.5 Providing users with a means to follow hyperlinks created using the <code class=\"language-text\">link</code> element</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-meta-element\">4.2.5 The <code class=\"language-text\">meta</code> element</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#standard-metadata-names\">4.2.5.1 Standard metadata names</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#other-metadata-names\">4.2.5.2 Other metadata names</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#pragma-directives\">4.2.5.3 Pragma directives</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#charset\">4.2.5.4 Specifying the document's character encoding</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-style-element\">4.2.6 The <code class=\"language-text\">style</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#interactions-of-styling-and-scripting\">4.2.7 Interactions of styling and scripting</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#sections\">4.3 Sections</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-body-element\">4.3.1 The <code class=\"language-text\">body</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-article-element\">4.3.2 The <code class=\"language-text\">article</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-section-element\">4.3.3 The <code class=\"language-text\">section</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-nav-element\">4.3.4 The <code class=\"language-text\">nav</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-aside-element\">4.3.5 The <code class=\"language-text\">aside</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements\">4.3.6 The <code class=\"language-text\">h1</code>, <code class=\"language-text\">h2</code>, <code class=\"language-text\">h3</code>, <code class=\"language-text\">h4</code>, <code class=\"language-text\">h5</code>, and <code class=\"language-text\">h6</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-hgroup-element\">4.3.7 The <code class=\"language-text\">hgroup</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-header-element\">4.3.8 The <code class=\"language-text\">header</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-footer-element\">4.3.9 The <code class=\"language-text\">footer</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-address-element\">4.3.10 The <code class=\"language-text\">address</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#headings-and-sections\">4.3.11 Headings and sections</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#outlines\">4.3.11.1 Creating an outline</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sample-outlines\">4.3.11.2 Sample outlines</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#exposing-outlines-to-users\">4.3.11.3 Exposing outlines to users</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#usage-summary-2\">4.3.12 Usage summary</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#article-or-section\">4.3.12.1 Article or section?</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#grouping-content\">4.4 Grouping content</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-p-element\">4.4.1 The <code class=\"language-text\">p</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-hr-element\">4.4.2 The <code class=\"language-text\">hr</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-pre-element\">4.4.3 The <code class=\"language-text\">pre</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-blockquote-element\">4.4.4 The <code class=\"language-text\">blockquote</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-ol-element\">4.4.5 The <code class=\"language-text\">ol</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-ul-element\">4.4.6 The <code class=\"language-text\">ul</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-menu-element\">4.4.7 The <code class=\"language-text\">menu</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-li-element\">4.4.8 The <code class=\"language-text\">li</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-dl-element\">4.4.9 The <code class=\"language-text\">dl</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-dt-element\">4.4.10 The <code class=\"language-text\">dt</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-dd-element\">4.4.11 The <code class=\"language-text\">dd</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-figure-element\">4.4.12 The <code class=\"language-text\">figure</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-figcaption-element\">4.4.13 The <code class=\"language-text\">figcaption</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-main-element\">4.4.14 The <code class=\"language-text\">main</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-div-element\">4.4.15 The <code class=\"language-text\">div</code> element</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#text-level-semantics\">4.5 Text-level semantics</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-a-element\">4.5.1 The <code class=\"language-text\">a</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-em-element\">4.5.2 The <code class=\"language-text\">em</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-strong-element\">4.5.3 The <code class=\"language-text\">strong</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-small-element\">4.5.4 The <code class=\"language-text\">small</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-s-element\">4.5.5 The <code class=\"language-text\">s</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-cite-element\">4.5.6 The <code class=\"language-text\">cite</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-q-element\">4.5.7 The <code class=\"language-text\">q</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-dfn-element\">4.5.8 The <code class=\"language-text\">dfn</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-abbr-element\">4.5.9 The <code class=\"language-text\">abbr</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-ruby-element\">4.5.10 The <code class=\"language-text\">ruby</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-rt-element\">4.5.11 The <code class=\"language-text\">rt</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-rp-element\">4.5.12 The <code class=\"language-text\">rp</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-data-element\">4.5.13 The <code class=\"language-text\">data</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-time-element\">4.5.14 The <code class=\"language-text\">time</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-code-element\">4.5.15 The <code class=\"language-text\">code</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-var-element\">4.5.16 The <code class=\"language-text\">var</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-samp-element\">4.5.17 The <code class=\"language-text\">samp</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-kbd-element\">4.5.18 The <code class=\"language-text\">kbd</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-sub-and-sup-elements\">4.5.19 The <code class=\"language-text\">sub</code> and <code class=\"language-text\">sup</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-i-element\">4.5.20 The <code class=\"language-text\">i</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-b-element\">4.5.21 The <code class=\"language-text\">b</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-u-element\">4.5.22 The <code class=\"language-text\">u</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-mark-element\">4.5.23 The <code class=\"language-text\">mark</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-bdi-element\">4.5.24 The <code class=\"language-text\">bdi</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-bdo-element\">4.5.25 The <code class=\"language-text\">bdo</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-span-element\">4.5.26 The <code class=\"language-text\">span</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-br-element\">4.5.27 The <code class=\"language-text\">br</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-wbr-element\">4.5.28 The <code class=\"language-text\">wbr</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#usage-summary\">4.5.29 Usage summary</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#links\">4.6 Links</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-2\">4.6.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#links-created-by-a-and-area-elements\">4.6.2 Links created by <code class=\"language-text\">a</code> and <code class=\"language-text\">area</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#api-for-a-and-area-elements\">4.6.3 API for <code class=\"language-text\">a</code> and <code class=\"language-text\">area</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#following-hyperlinks\">4.6.4 Following hyperlinks</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#downloading-resources\">4.6.5 Downloading resources</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#hyperlink-auditing\">4.6.5.1 Hyperlink auditing</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#linkTypes\">4.6.6 Link types</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#rel-alternate\">4.6.6.1 Link type \"<code class=\"language-text\">alternate</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-author\">4.6.6.2 Link type \"<code class=\"language-text\">author</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-bookmark\">4.6.6.3 Link type \"<code class=\"language-text\">bookmark</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-canonical\">4.6.6.4 Link type \"<code class=\"language-text\">canonical</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-dns-prefetch\">4.6.6.5 Link type \"<code class=\"language-text\">dns-prefetch</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-external\">4.6.6.6 Link type \"<code class=\"language-text\">external</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-help\">4.6.6.7 Link type \"<code class=\"language-text\">help</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rel-icon\">4.6.6.8 Link type \"<code class=\"language-text\">icon</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-license\">4.6.6.9 Link type \"<code class=\"language-text\">license</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-manifest\">4.6.6.10 Link type \"<code class=\"language-text\">manifest</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-modulepreload\">4.6.6.11 Link type \"<code class=\"language-text\">modulepreload</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-nofollow\">4.6.6.12 Link type \"<code class=\"language-text\">nofollow</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-noopener\">4.6.6.13 Link type \"<code class=\"language-text\">noopener</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-noreferrer\">4.6.6.14 Link type \"<code class=\"language-text\">noreferrer</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-opener\">4.6.6.15 Link type \"<code class=\"language-text\">opener</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-pingback\">4.6.6.16 Link type \"<code class=\"language-text\">pingback</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-preconnect\">4.6.6.17 Link type \"<code class=\"language-text\">preconnect</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-prefetch\">4.6.6.18 Link type \"<code class=\"language-text\">prefetch</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-preload\">4.6.6.19 Link type \"<code class=\"language-text\">preload</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-prerender\">4.6.6.20 Link type \"<code class=\"language-text\">prerender</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-search\">4.6.6.21 Link type \"<code class=\"language-text\">search</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-stylesheet\">4.6.6.22 Link type \"<code class=\"language-text\">stylesheet</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-tag\">4.6.6.23 Link type \"<code class=\"language-text\">tag</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sequential-link-types\">4.6.6.24 Sequential link types</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-next\">4.6.6.24.1 Link type \"<code class=\"language-text\">next</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#link-type-prev\">4.6.6.24.2 Link type \"<code class=\"language-text\">prev</code>\"</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#other-link-types\">4.6.6.25 Other link types</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#edits\">4.7 Edits</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-ins-element\">4.7.1 The <code class=\"language-text\">ins</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-del-element\">4.7.2 The <code class=\"language-text\">del</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attributes-common-to-ins-and-del-elements\">4.7.3 Attributes common to <code class=\"language-text\">ins</code> and <code class=\"language-text\">del</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#edits-and-paragraphs\">4.7.4 Edits and paragraphs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#edits-and-lists\">4.7.5 Edits and lists</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#edits-and-tables\">4.7.6 Edits and tables</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#embedded-content\">4.8 Embedded content</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-picture-element\">4.8.1 The <code class=\"language-text\">picture</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-source-element\">4.8.2 The <code class=\"language-text\">source</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-img-element\">4.8.3 The <code class=\"language-text\">img</code> element</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#images\">4.8.4 Images</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#introduction-3\">4.8.4.1 Introduction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#adaptive-images\">4.8.4.1.1 Adaptive images</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#attributes-common-to-source-and-img-elements\">4.8.4.2 Attributes common to <code class=\"language-text\">source</code>, <code class=\"language-text\">img</code>, and <code class=\"language-text\">link</code> elements</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#srcset-attributes\">4.8.4.2.1 Srcset attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sizes-attributes\">4.8.4.2.2 Sizes attributes</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#images-processing-model\">4.8.4.3 Processing model</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#when-to-obtain-images\">4.8.4.3.1 When to obtain images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#reacting-to-dom-mutations\">4.8.4.3.2 Reacting to DOM mutations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-list-of-available-images\">4.8.4.3.3 The list of available images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#decoding-images\">4.8.4.3.4 Decoding images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#updating-the-image-data\">4.8.4.3.5 Updating the image data</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#preparing-an-image-for-presentation\">4.8.4.3.6 Preparing an image for presentation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#selecting-an-image-source\">4.8.4.3.7 Selecting an image source</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#updating-the-source-set\">4.8.4.3.8 Updating the source set</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-a-srcset-attribute\">4.8.4.3.9 Parsing a srcset attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-a-sizes-attribute\">4.8.4.3.10 Parsing a sizes attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#normalizing-the-source-densities\">4.8.4.3.11 Normalizing the source densities</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#reacting-to-environment-changes\">4.8.4.3.12 Reacting to environment changes</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#alt\">4.8.4.4 Requirements for providing text to act as an alternative for images</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#general-guidelines\">4.8.4.4.1 General guidelines</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-link-or-button-containing-nothing-but-the-image\">4.8.4.4.2 A link or button containing nothing but the image</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-phrase-or-paragraph-with-an-alternative-graphical-representation:-charts,-diagrams,-graphs,-maps,-illustrations\">4.8.4.4.3 A phrase or paragraph with an alternative graphical representation: charts, diagrams, graphs, maps, illustrations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-short-phrase-or-label-with-an-alternative-graphical-representation:-icons,-logos\">4.8.4.4.4 A short phrase or label with an alternative graphical representation: icons, logos</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text-that-has-been-rendered-to-a-graphic-for-typographical-effect\">4.8.4.4.5 Text that has been rendered to a graphic for typographical effect</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-graphical-representation-of-some-of-the-surrounding-text\">4.8.4.4.6 A graphical representation of some of the surrounding text</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ancillary-images\">4.8.4.4.7 Ancillary images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-purely-decorative-image-that-doesn&#x27;t-add-any-information\">4.8.4.4.8 A purely decorative image that doesn't add any information</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-group-of-images-that-form-a-single-larger-picture-with-no-links\">4.8.4.4.9 A group of images that form a single larger picture with no links</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-group-of-images-that-form-a-single-larger-picture-with-links\">4.8.4.4.10 A group of images that form a single larger picture with links</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-key-part-of-the-content\">4.8.4.4.11 A key part of the content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#an-image-not-intended-for-the-user\">4.8.4.4.12 An image not intended for the user</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#an-image-in-an-e-mail-or-private-document-intended-for-a-specific-person-who-is-known-to-be-able-to-view-images\">4.8.4.4.13 An image in an email or private document intended for a specific person who is known to be able to view images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#guidance-for-markup-generators\">4.8.4.4.14 Guidance for markup generators</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#guidance-for-conformance-checkers\">4.8.4.4.15 Guidance for conformance checkers</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-iframe-element\">4.8.5 The <code class=\"language-text\">iframe</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-embed-element\">4.8.6 The <code class=\"language-text\">embed</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-object-element\">4.8.7 The <code class=\"language-text\">object</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-param-element\">4.8.8 The <code class=\"language-text\">param</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-video-element\">4.8.9 The <code class=\"language-text\">video</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-audio-element\">4.8.10 The <code class=\"language-text\">audio</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-track-element\">4.8.11 The <code class=\"language-text\">track</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#media-elements\">4.8.12 Media elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#error-codes\">4.8.12.1 Error codes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-of-the-media-resource\">4.8.12.2 Location of the media resource</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#mime-types\">4.8.12.3 MIME types</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#network-states\">4.8.12.4 Network states</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#loading-the-media-resource\">4.8.12.5 Loading the media resource</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#offsets-into-the-media-resource\">4.8.12.6 Offsets into the media resource</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ready-states\">4.8.12.7 Ready states</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#playing-the-media-resource\">4.8.12.8 Playing the media resource</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#seeking\">4.8.12.9 Seeking</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#media-resources-with-multiple-media-tracks\">4.8.12.10 Media resources with multiple media tracks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#audiotracklist-and-videotracklist-objects\">4.8.12.10.1 <code class=\"language-text\">AudioTrackList</code> and <code class=\"language-text\">VideoTrackList</code> objects</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#selecting-specific-audio-and-video-tracks-declaratively\">4.8.12.10.2 Selecting specific audio and video tracks declaratively</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#timed-text-tracks\">4.8.12.11 Timed text tracks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text-track-model\">4.8.12.11.1 Text track model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sourcing-in-band-text-tracks\">4.8.12.11.2 Sourcing in-band text tracks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sourcing-out-of-band-text-tracks\">4.8.12.11.3 Sourcing out-of-band text tracks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#guidelines-for-exposing-cues-in-various-formats-as-text-track-cues\">4.8.12.11.4 Guidelines for exposing cues in various formats as text track cues</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text-track-api\">4.8.12.11.5 Text track API</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cue-events\">4.8.12.11.6 Event handlers for objects of the text track APIs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#best-practices-for-metadata-text-tracks\">4.8.12.11.7 Best practices for metadata text tracks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#identifying-a-track-kind-through-a-url\">4.8.12.12 Identifying a track kind through a URL</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#user-interface\">4.8.12.13 User interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#time-ranges\">4.8.12.14 Time ranges</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-trackevent-interface\">4.8.12.15 The <code class=\"language-text\">TrackEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#mediaevents\">4.8.12.16 Events summary</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#security-and-privacy-considerations\">4.8.12.17 Security and privacy considerations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#best-practices-for-authors-using-media-elements\">4.8.12.18 Best practices for authors using media elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#best-practices-for-implementers-of-media-elements\">4.8.12.19 Best practices for implementers of media elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-map-element\">4.8.13 The <code class=\"language-text\">map</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-area-element\">4.8.14 The <code class=\"language-text\">area</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#image-maps\">4.8.15 Image maps</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#authoring\">4.8.15.1 Authoring</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#image-map-processing-model\">4.8.15.2 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#mathml\">4.8.16 MathML</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#svg-0\">4.8.17 SVG</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dimension-attributes\">4.8.18 Dimension attributes</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#tables\">4.9 Tabular data</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-table-element\">4.9.1 The <code class=\"language-text\">table</code> element</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#table-descriptions-techniques\">4.9.1.1 Techniques for describing tables</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#table-layout-techniques\">4.9.1.2 Techniques for table design</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-caption-element\">4.9.2 The <code class=\"language-text\">caption</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-colgroup-element\">4.9.3 The <code class=\"language-text\">colgroup</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-col-element\">4.9.4 The <code class=\"language-text\">col</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-tbody-element\">4.9.5 The <code class=\"language-text\">tbody</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-thead-element\">4.9.6 The <code class=\"language-text\">thead</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-tfoot-element\">4.9.7 The <code class=\"language-text\">tfoot</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-tr-element\">4.9.8 The <code class=\"language-text\">tr</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-td-element\">4.9.9 The <code class=\"language-text\">td</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-th-element\">4.9.10 The <code class=\"language-text\">th</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attributes-common-to-td-and-th-elements\">4.9.11 Attributes common to <code class=\"language-text\">td</code> and <code class=\"language-text\">th</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#table-processing-model\">4.9.12 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#forming-a-table\">4.9.12.1 Forming a table</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#header-and-data-cell-semantics\">4.9.12.2 Forming relationships between data cells and header cells</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#table-examples\">4.9.13 Examples</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#forms\">4.10 Forms</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#introduction-4\">4.10.1 Introduction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#writing-a-form&#x27;s-user-interface\">4.10.1.1 Writing a form's user interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#implementing-the-server-side-processing-for-a-form\">4.10.1.2 Implementing the server-side processing for a form</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#configuring-a-form-to-communicate-with-a-server\">4.10.1.3 Configuring a form to communicate with a server</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#client-side-form-validation\">4.10.1.4 Client-side form validation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#enabling-client-side-automatic-filling-of-form-controls\">4.10.1.5 Enabling client-side automatic filling of form controls</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#improving-the-user-experience-on-mobile-devices\">4.10.1.6 Improving the user experience on mobile devices</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-difference-between-the-field-type,-the-autofill-field-name,-and-the-input-modality\">4.10.1.7 The difference between the field type, the autofill field name, and the input modality</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#input-author-notes\">4.10.1.8 Date, time, and number formats</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#categories\">4.10.2 Categories</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-form-element\">4.10.3 The <code class=\"language-text\">form</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-label-element\">4.10.4 The <code class=\"language-text\">label</code> element</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-input-element\">4.10.5 The <code class=\"language-text\">input</code> element</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#states-of-the-type-attribute\">4.10.5.1 States of the <code class=\"language-text\">type</code> attribute</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#hidden-state-(type=hidden)\">4.10.5.1.1 Hidden state (<code class=\"language-text\">type=hidden</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text-(type=text)-state-and-search-state-(type=search)\">4.10.5.1.2 Text (<code class=\"language-text\">type=text</code>) state and Search state (<code class=\"language-text\">type=search</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#telephone-state-(type=tel)\">4.10.5.1.3 Telephone state (<code class=\"language-text\">type=tel</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#url-state-(type=url)\">4.10.5.1.4 URL state (<code class=\"language-text\">type=url</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#email-state-(type=email)\">4.10.5.1.5 Email state (<code class=\"language-text\">type=email</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#password-state-(type=password)\">4.10.5.1.6 Password state (<code class=\"language-text\">type=password</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#date-state-(type=date)\">4.10.5.1.7 Date state (<code class=\"language-text\">type=date</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#month-state-(type=month)\">4.10.5.1.8 Month state (<code class=\"language-text\">type=month</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#week-state-(type=week)\">4.10.5.1.9 Week state (<code class=\"language-text\">type=week</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#time-state-(type=time)\">4.10.5.1.10 Time state (<code class=\"language-text\">type=time</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#local-date-and-time-state-(type=datetime-local)\">4.10.5.1.11 Local Date and Time state (<code class=\"language-text\">type=datetime-local</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#number-state-(type=number)\">4.10.5.1.12 Number state (<code class=\"language-text\">type=number</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#range-state-(type=range)\">4.10.5.1.13 Range state (<code class=\"language-text\">type=range</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#color-state-(type=color)\">4.10.5.1.14 Color state (<code class=\"language-text\">type=color</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#checkbox-state-(type=checkbox)\">4.10.5.1.15 Checkbox state (<code class=\"language-text\">type=checkbox</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#radio-button-state-(type=radio)\">4.10.5.1.16 Radio Button state (<code class=\"language-text\">type=radio</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#file-upload-state-(type=file)\">4.10.5.1.17 File Upload state (<code class=\"language-text\">type=file</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#submit-button-state-(type=submit)\">4.10.5.1.18 Submit Button state (<code class=\"language-text\">type=submit</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#image-button-state-(type=image)\">4.10.5.1.19 Image Button state (<code class=\"language-text\">type=image</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#reset-button-state-(type=reset)\">4.10.5.1.20 Reset Button state (<code class=\"language-text\">type=reset</code>)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#button-state-(type=button)\">4.10.5.1.21 Button state (<code class=\"language-text\">type=button</code>)</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#input-impl-notes\">4.10.5.2 Implementation notes regarding localization of form controls</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#common-input-element-attributes\">4.10.5.3 Common <code class=\"language-text\">input</code> element attributes</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-maxlength-and-minlength-attributes\">4.10.5.3.1 The <code class=\"language-text\">maxlength</code> and <code class=\"language-text\">minlength</code> attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-size-attribute\">4.10.5.3.2 The <code class=\"language-text\">size</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-readonly-attribute\">4.10.5.3.3 The <code class=\"language-text\">readonly</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-required-attribute\">4.10.5.3.4 The <code class=\"language-text\">required</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-multiple-attribute\">4.10.5.3.5 The <code class=\"language-text\">multiple</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-pattern-attribute\">4.10.5.3.6 The <code class=\"language-text\">pattern</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-min-and-max-attributes\">4.10.5.3.7 The <code class=\"language-text\">min</code> and <code class=\"language-text\">max</code> attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-step-attribute\">4.10.5.3.8 The <code class=\"language-text\">step</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-list-attribute\">4.10.5.3.9 The <code class=\"language-text\">list</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-placeholder-attribute\">4.10.5.3.10 The <code class=\"language-text\">placeholder</code> attribute</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#common-input-element-apis\">4.10.5.4 Common <code class=\"language-text\">input</code> element APIs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#common-input-element-events\">4.10.5.5 Common event behaviors</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-button-element\">4.10.6 The <code class=\"language-text\">button</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-select-element\">4.10.7 The <code class=\"language-text\">select</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-datalist-element\">4.10.8 The <code class=\"language-text\">datalist</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-optgroup-element\">4.10.9 The <code class=\"language-text\">optgroup</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-option-element\">4.10.10 The <code class=\"language-text\">option</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-textarea-element\">4.10.11 The <code class=\"language-text\">textarea</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-output-element\">4.10.12 The <code class=\"language-text\">output</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-progress-element\">4.10.13 The <code class=\"language-text\">progress</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-meter-element\">4.10.14 The <code class=\"language-text\">meter</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-fieldset-element\">4.10.15 The <code class=\"language-text\">fieldset</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-legend-element\">4.10.16 The <code class=\"language-text\">legend</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#form-control-infrastructure\">4.10.17 Form control infrastructure</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#a-form-control&#x27;s-value\">4.10.17.1 A form control's value</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#mutability\">4.10.17.2 Mutability</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#association-of-controls-and-forms\">4.10.17.3 Association of controls and forms</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attributes-common-to-form-controls\">4.10.18 Attributes common to form controls</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#naming-form-controls:-the-name-attribute\">4.10.18.1 Naming form controls: the <code class=\"language-text\">name</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#submitting-element-directionality:-the-dirname-attribute\">4.10.18.2 Submitting element directionality: the <code class=\"language-text\">dirname</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#limiting-user-input-length:-the-maxlength-attribute\">4.10.18.3 Limiting user input length: the <code class=\"language-text\">maxlength</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#setting-minimum-input-length-requirements:-the-minlength-attribute\">4.10.18.4 Setting minimum input length requirements: the <code class=\"language-text\">minlength</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#enabling-and-disabling-form-controls:-the-disabled-attribute\">4.10.18.5 Enabling and disabling form controls: the <code class=\"language-text\">disabled</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#form-submission-attributes\">4.10.18.6 Form submission attributes</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#autofill\">4.10.18.7 Autofill</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#autofilling-form-controls:-the-autocomplete-attribute\">4.10.18.7.1 Autofilling form controls: the <code class=\"language-text\">autocomplete</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#autofill-processing-model\">4.10.18.7.2 Processing model</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#textFieldSelection\">4.10.19 APIs for the text control selections</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#constraints\">4.10.20 Constraints</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#definitions\">4.10.20.1 Definitions</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#constraint-validation\">4.10.20.2 Constraint validation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-constraint-validation-api\">4.10.20.3 The constraint validation API</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#security-forms\">4.10.20.4 Security</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#form-submission-2\">4.10.21 Form submission</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-5\">4.10.21.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#implicit-submission\">4.10.21.2 Implicit submission</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#form-submission-algorithm\">4.10.21.3 Form submission algorithm</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#constructing-form-data-set\">4.10.21.4 Constructing the entry list</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#selecting-a-form-submission-encoding\">4.10.21.5 Selecting a form submission encoding</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#converting-an-entry-list-to-a-list-of-name-value-pairs\">4.10.21.6 Converting an entry list to a list of name-value pairs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#url-encoded-form-data\">4.10.21.7 URL-encoded form data</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#multipart-form-data\">4.10.21.8 Multipart form data</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#plain-text-form-data\">4.10.21.9 Plain text form data</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-submitevent-interface\">4.10.21.10 The <code class=\"language-text\">SubmitEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-formdataevent-interface\">4.10.21.11 The <code class=\"language-text\">FormDataEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#resetting-a-form\">4.10.22 Resetting a form</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#interactive-elements\">4.11 Interactive elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-details-element\">4.11.1 The <code class=\"language-text\">details</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-summary-element\">4.11.2 The <code class=\"language-text\">summary</code> element</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#commands\">4.11.3 Commands</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#facets-2\">4.11.3.1 Facets</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#using-the-a-element-to-define-a-command\">4.11.3.2 Using the <code class=\"language-text\">a</code> element to define a command</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#using-the-button-element-to-define-a-command\">4.11.3.3 Using the <code class=\"language-text\">button</code> element to define a command</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#using-the-input-element-to-define-a-command\">4.11.3.4 Using the <code class=\"language-text\">input</code> element to define a command</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#using-the-option-element-to-define-a-command\">4.11.3.5 Using the <code class=\"language-text\">option</code> element to define a command</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#using-the-accesskey-attribute-on-a-legend-element-to-define-a-command\">4.11.3.6 Using the <code class=\"language-text\">accesskey</code> attribute on a <code class=\"language-text\">legend</code> element to define a command</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#using-the-accesskey-attribute-to-define-a-command-on-other-elements\">4.11.3.7 Using the <code class=\"language-text\">accesskey</code> attribute to define a command on other elements</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-dialog-element\">4.11.4 The <code class=\"language-text\">dialog</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#scripting-3\">4.12 Scripting</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-script-element\">4.12.1 The <code class=\"language-text\">script</code> element</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#script-processing-model\">4.12.1.1 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#scriptingLanguages\">4.12.1.2 Scripting languages</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#restrictions-for-contents-of-script-elements\">4.12.1.3 Restrictions for contents of <code class=\"language-text\">script</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#inline-documentation-for-external-scripts\">4.12.1.4 Inline documentation for external scripts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#scriptTagXSLT\">4.12.1.5 Interaction of <code class=\"language-text\">script</code> elements and XSLT</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-noscript-element\">4.12.2 The <code class=\"language-text\">noscript</code> element</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-template-element\">4.12.3 The <code class=\"language-text\">template</code> element</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#template-XSLT-XPath\">4.12.3.1 Interaction of <code class=\"language-text\">template</code> elements with XSLT and XPath</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-slot-element\">4.12.4 The <code class=\"language-text\">slot</code> element</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-canvas-element\">4.12.5 The <code class=\"language-text\">canvas</code> element</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#2dcontext\">4.12.5.1 The 2D rendering context</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#implementation-notes\">4.12.5.1.1 Implementation notes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-canvas-state\">4.12.5.1.2 The canvas state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#line-styles\">4.12.5.1.3 Line styles</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text-styles\">4.12.5.1.4 Text styles</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#building-paths\">4.12.5.1.5 Building paths</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#path2d-objects\">4.12.5.1.6 <code class=\"language-text\">Path2D</code> objects</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#transformations\">4.12.5.1.7 Transformations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#image-sources-for-2d-rendering-contexts\">4.12.5.1.8 Image sources for 2D rendering contexts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#fill-and-stroke-styles\">4.12.5.1.9 Fill and stroke styles</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#drawing-rectangles-to-the-bitmap\">4.12.5.1.10 Drawing rectangles to the bitmap</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#drawing-text-to-the-bitmap\">4.12.5.1.11 Drawing text to the bitmap</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#drawing-paths-to-the-canvas\">4.12.5.1.12 Drawing paths to the canvas</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#drawing-focus-rings-and-scrolling-paths-into-view\">4.12.5.1.13 Drawing focus rings and scrolling paths into view</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#drawing-images\">4.12.5.1.14 Drawing images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#pixel-manipulation\">4.12.5.1.15 Pixel manipulation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#compositing\">4.12.5.1.16 Compositing</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#image-smoothing\">4.12.5.1.17 Image smoothing</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#shadows\">4.12.5.1.18 Shadows</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#filters\">4.12.5.1.19 Filters</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#working-with-externally-defined-svg-filters\">4.12.5.1.20 Working with externally-defined SVG filters</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#drawing-model\">4.12.5.1.21 Drawing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#best-practices\">4.12.5.1.22 Best practices</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#examples\">4.12.5.1.23 Examples</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-imagebitmap-rendering-context\">4.12.5.2 The <code class=\"language-text\">ImageBitmap</code> rendering context</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-6\">4.12.5.2.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-imagebitmaprenderingcontext-interface\">4.12.5.2.2 The <code class=\"language-text\">ImageBitmapRenderingContext</code> interface</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-offscreencanvas-interface\">4.12.5.3 The <code class=\"language-text\">OffscreenCanvas</code> interface</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-offscreen-2d-rendering-context\">4.12.5.3.1 The offscreen 2D rendering context</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#colour-spaces-and-colour-correction\">4.12.5.4 Color spaces and color space conversion</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#serialising-bitmaps-to-a-file\">4.12.5.5 Serializing bitmaps to a file</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#security-with-canvas-elements\">4.12.5.6 Security with <code class=\"language-text\">canvas</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#premultiplied-alpha-and-the-2d-rendering-context\">4.12.5.7 Premultiplied alpha and the 2D rendering context</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements\">4.13 Custom elements</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#custom-elements-intro\">4.13.1 Introduction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements-autonomous-example\">4.13.1.1 Creating an autonomous custom element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements-face-example\">4.13.1.2 Creating a form-associated custom element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements-accessibility-example\">4.13.1.3 Creating a custom element with default accessible roles, states, and properties</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements-customized-builtin-example\">4.13.1.4 Creating a customized built-in element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements-autonomous-drawbacks\">4.13.1.5 Drawbacks of autonomous custom elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements-upgrades-examples\">4.13.1.6 Upgrading elements after their creation</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-element-conformance\">4.13.2 Requirements for custom element constructors and reactions</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements-core-concepts\">4.13.3 Core concepts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-elements-api\">4.13.4 The <code class=\"language-text\">CustomElementRegistry</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#upgrades\">4.13.5 Upgrades</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#custom-element-reactions\">4.13.6 Custom element reactions</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#element-internals\">4.13.7 Element internals</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-elementinternals-interface\">4.13.7.1 The <code class=\"language-text\">ElementInternals</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#shadow-root-access\">4.13.7.2 Shadow root access</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#form-associated-custom-elements\">4.13.7.3 Form-associated custom elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#accessibility-semantics\">4.13.7.4 Accessibility semantics</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#common-idioms\">4.14 Common idioms without dedicated elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rel-up\">4.14.1 Breadcrumb navigation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#tag-clouds\">4.14.2 Tag clouds</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#conversations\">4.14.3 Conversations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#footnotes\">4.14.4 Footnotes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#disabled-elements\">4.15 Disabled elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#selectors\">4.16 Matching HTML elements using selectors and CSS</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#case-sensitivity-of-the-css-&#x27;attr()&#x27;-function\">4.16.1 Case-sensitivity of the CSS 'attr()' function</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#case-sensitivity-of-selectors\">4.16.2 Case-sensitivity of selectors</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#pseudo-classes\">4.16.3 Pseudo-classes</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#microdata\">5 Microdata</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#introduction-7\">5.1 Introduction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#overview\">5.1.1 Overview</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-basic-syntax\">5.1.2 The basic syntax</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#typed-items\">5.1.3 Typed items</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#global-identifiers-for-items\">5.1.4 Global identifiers for items</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#selecting-names-when-defining-vocabularies\">5.1.5 Selecting names when defining vocabularies</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#encoding-microdata\">5.2 Encoding microdata</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-microdata-model\">5.2.1 The microdata model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#items\">5.2.2 Items</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#names:-the-itemprop-attribute\">5.2.3 Names: the <code class=\"language-text\">itemprop</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#values\">5.2.4 Values</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#associating-names-with-items\">5.2.5 Associating names with items</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#microdata-and-other-namespaces\">5.2.6 Microdata and other namespaces</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#mdvocabs\">5.3 Sample microdata vocabularies</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#vcard\">5.3.1 vCard</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#conversion-to-vcard\">5.3.1.1 Conversion to vCard</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#examples-2\">5.3.1.2 Examples</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#vevent\">5.3.2 vEvent</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#conversion-to-icalendar\">5.3.2.1 Conversion to iCalendar</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#examples-3\">5.3.2.2 Examples</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#licensing-works\">5.3.3 Licensing works</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#examples-4\">5.3.3.1 Examples</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#converting-html-to-other-formats\">5.4 Converting HTML to other formats</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#json\">5.4.1 JSON</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#editing\">6 User interaction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-hidden-attribute\">6.1 The <code class=\"language-text\">hidden</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#inert-subtrees\">6.2 Inert subtrees</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#tracking-user-activation\">6.3 Tracking user activation</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#user-activation-data-model\">6.3.1 Data model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#user-activation-processing-model\">6.3.2 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#user-activation-gated-apis\">6.3.3 APIs gated by user activation</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#activation\">6.4 Activation behavior of elements</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#focus\">6.5 Focus</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-8\">6.5.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#data-model\">6.5.2 Data model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-tabindex-attribute\">6.5.3 The <code class=\"language-text\">tabindex</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#focus-processing-model\">6.5.4 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sequential-focus-navigation\">6.5.5 Sequential focus navigation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#focus-management-apis\">6.5.6 Focus management APIs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-autofocus-attribute\">6.5.7 The <code class=\"language-text\">autofocus</code> attribute</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#assigning-keyboard-shortcuts\">6.6 Assigning keyboard shortcuts</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-9\">6.6.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-accesskey-attribute\">6.6.2 The <code class=\"language-text\">accesskey</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#keyboard-shortcuts-processing-model\">6.6.3 Processing model</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#editing-2\">6.7 Editing</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#contenteditable\">6.7.1 Making document regions editable: The <code class=\"language-text\">contenteditable</code> content attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#making-entire-documents-editable:-the-designmode-idl-attribute\">6.7.2 Making entire documents editable: the <code class=\"language-text\">designMode</code> getter and setter</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#best-practices-for-in-page-editors\">6.7.3 Best practices for in-page editors</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#editing-apis\">6.7.4 Editing APIs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#spelling-and-grammar-checking\">6.7.5 Spelling and grammar checking</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#autocapitalization\">6.7.6 Autocapitalization</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#input-modalities:-the-inputmode-attribute\">6.7.7 Input modalities: the <code class=\"language-text\">inputmode</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#input-modalities:-the-enterkeyhint-attribute\">6.7.8 Input modalities: the <code class=\"language-text\">enterkeyhint</code> attribute</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#find-in-page\">6.8 Find-in-page</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-10\">6.8.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#interaction-with-details\">6.8.2 Interaction with <code class=\"language-text\">details</code></a></li>\n<li><a href=\"https://html.spec.whatwg.org/#interaction-with-selection\">6.8.3 Interaction with selection</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#dnd\">6.9 Drag and drop</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#event-drag\">6.9.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-drag-data-store\">6.9.2 The drag data store</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-datatransfer-interface\">6.9.3 The <code class=\"language-text\">DataTransfer</code> interface</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-datatransferitemlist-interface\">6.9.3.1 The <code class=\"language-text\">DataTransferItemList</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-datatransferitem-interface\">6.9.3.2 The <code class=\"language-text\">DataTransferItem</code> interface</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-dragevent-interface\">6.9.4 The <code class=\"language-text\">DragEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#drag-and-drop-processing-model\">6.9.5 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dndevents\">6.9.6 Events summary</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-draggable-attribute\">6.9.7 The <code class=\"language-text\">draggable</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#security-risks-in-the-drag-and-drop-model\">6.9.8 Security risks in the drag-and-drop model</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#browsers\">7 Loading web pages</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#windows\">7.1 Browsing contexts</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#creating-browsing-contexts\">7.1.1 Creating browsing contexts</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#nested-browsing-contexts\">7.1.2 Related browsing contexts</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#navigating-nested-browsing-contexts-in-the-dom\">7.1.2.1 Navigating related browsing contexts in the DOM</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#security-nav\">7.1.3 Security</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#groupings-of-browsing-contexts\">7.1.4 Groupings of browsing contexts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#browsing-context-names\">7.1.5 Browsing context names</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#cross-origin-objects\">7.2 Security infrastructure for <code class=\"language-text\">Window</code>, <code class=\"language-text\">WindowProxy</code>, and <code class=\"language-text\">Location</code> objects</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#integration-with-idl\">7.2.1 Integration with IDL</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#shared-internal-slot:-crossoriginpropertydescriptormap\">7.2.2 Shared internal slot: [[CrossOriginPropertyDescriptorMap]]</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#shared-abstract-operations\">7.2.3 Shared abstract operations</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#crossoriginproperties-(-o-)\">7.2.3.1 CrossOriginProperties ( O )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#crossoriginpropertyfallback-(-p-)\">7.2.3.2 CrossOriginPropertyFallback ( P )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#isplatformobjectsameorigin-(-o-)\">7.2.3.3 IsPlatformObjectSameOrigin ( O )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#crossorigingetownpropertyhelper-(-o,-p-)\">7.2.3.4 CrossOriginGetOwnPropertyHelper ( O, P )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#crossoriginget-(-o,-p,-receiver-)\">7.2.3.5 CrossOriginGet ( O, P, Receiver )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#crossoriginset-(-o,-p,-v,-receiver-)\">7.2.3.6 CrossOriginSet ( O, P, V, Receiver )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#crossoriginownpropertykeys-(-o-)\">7.2.3.7 CrossOriginOwnPropertyKeys ( O )</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-window-object\">7.3 The <code class=\"language-text\">Window</code> object</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#apis-for-creating-and-navigating-browsing-contexts-by-name\">7.3.1 APIs for creating and navigating browsing contexts by name</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#accessing-other-browsing-contexts\">7.3.2 Accessing other browsing contexts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#named-access-on-the-window-object\">7.3.3 Named access on the <code class=\"language-text\">Window</code> object</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#garbage-collection-and-browsing-contexts\">7.3.4 Discarding browsing contexts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#closing-browsing-contexts\">7.3.5 Closing browsing contexts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#browser-interface-elements\">7.3.6 Browser interface elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-settings-for-window-objects\">7.3.7 Script settings for <code class=\"language-text\">Window</code> objects</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-windowproxy-exotic-object\">7.4 The <code class=\"language-text\">WindowProxy</code> exotic object</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-getprototypeof\">7.4.1 [[GetPrototypeOf]] ( )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-setprototypeof\">7.4.2 [[SetPrototypeOf]] ( V )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-isextensible\">7.4.3 [[IsExtensible]] ( )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-preventextensions\">7.4.4 [[PreventExtensions]] ( )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-getownproperty\">7.4.5 [[GetOwnProperty]] ( P )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-defineownproperty\">7.4.6 [[DefineOwnProperty]] ( P, Desc )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-get\">7.4.7 [[Get]] ( P, Receiver )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-set\">7.4.8 [[Set]] ( P, V, Receiver )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-delete\">7.4.9 [[Delete]] ( P )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#windowproxy-ownpropertykeys\">7.4.10 [[OwnPropertyKeys]] ( )</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#origin\">7.5 Origin</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#sites\">7.5.1 Sites</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#relaxing-the-same-origin-restriction\">7.5.2 Relaxing the same-origin restriction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#origin-keyed-agent-clusters\">7.5.3 Origin-keyed agent clusters</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#sandboxing\">7.6 Sandboxing</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#cross-origin-opener-policies\">7.7 Cross-origin opener policies</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-headers\">7.7.1 The headers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#browsing-context-group-switches-due-to-cross-origin-opener-policy\">7.7.2 Browsing context group switches due to cross-origin opener policy</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#reporting\">7.7.3 Reporting</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#coep\">7.8 Cross-origin embedder policies</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-headers-2\">7.8.1 The headers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#embedder-policy-checks\">7.8.2 Embedder policy checks</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#policy-containers\">7.9 Policy containers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#history\">7.10 Session history and navigation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#browsing-sessions\">7.10.1 Browsing sessions</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-session-history-of-browsing-contexts\">7.10.2 The session history of browsing contexts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-history-interface\">7.10.3 The <code class=\"language-text\">History</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#history-notes\">7.10.4 Implementation notes for session history</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-location-interface\">7.10.5 The <code class=\"language-text\">Location</code> interface</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#location-getprototypeof\">7.10.5.1 [[GetPrototypeOf]] ( )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-setprototypeof\">7.10.5.2 [[SetPrototypeOf]] ( V )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-isextensible\">7.10.5.3 [[IsExtensible]] ( )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-preventextensions\">7.10.5.4 [[PreventExtensions]] ( )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-getownproperty\">7.10.5.5 [[GetOwnProperty]] ( P )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-defineownproperty\">7.10.5.6 [[DefineOwnProperty]] ( P, Desc )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-get\">7.10.5.7 [[Get]] ( P, Receiver )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-set\">7.10.5.8 [[Set]] ( P, V, Receiver )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-delete\">7.10.5.9 [[Delete]] ( P )</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#location-ownpropertykeys\">7.10.5.10 [[OwnPropertyKeys]] ( )</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#browsing-the-web\">7.11 Browsing the web</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#navigating-across-documents\">7.11.1 Navigating across documents</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#read-html\">7.11.2 Page load processing model for HTML files</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#read-xml\">7.11.3 Page load processing model for XML files</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#read-text\">7.11.4 Page load processing model for text files</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#read-multipart-x-mixed-replace\">7.11.5 Page load processing model for <code class=\"language-text\">multipart/x-mixed-replace</code> resources</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#read-media\">7.11.6 Page load processing model for media</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#read-plugin\">7.11.7 Page load processing model for content that uses plugins</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#read-ua-inline\">7.11.8 Page load processing model for inline content that doesn't have a DOM</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#scroll-to-fragid\">7.11.9 Navigating to a fragment</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#history-traversal\">7.11.10 History traversal</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#persisted-user-state-restoration\">7.11.10.1 Persisted history entry state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-popstateevent-interface\">7.11.10.2 The <code class=\"language-text\">PopStateEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-hashchangeevent-interface\">7.11.10.3 The <code class=\"language-text\">HashChangeEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-pagetransitionevent-interface\">7.11.10.4 The <code class=\"language-text\">PageTransitionEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#loading-documents\">7.11.11 Loading documents</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#unloading-documents\">7.11.12 Unloading documents</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-beforeunloadevent-interface\">7.11.12.1 The <code class=\"language-text\">BeforeUnloadEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#aborting-a-document-load\">7.11.13 Aborting a document load</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-x-frame-options-header\">7.11.14 The `<code class=\"language-text\">X-Frame-Options</code>` header</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#webappapis\">8 Web application APIs</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#scripting\">8.1 Scripting</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-11\">8.1.1 Introduction</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#agents-and-agent-clusters\">8.1.2 Agents and agent clusters</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#integration-with-the-javascript-agent-formalism\">8.1.2.1 Integration with the JavaScript agent formalism</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#integration-with-the-javascript-agent-cluster-formalism\">8.1.2.2 Integration with the JavaScript agent cluster formalism</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#realms-and-their-counterparts\">8.1.3 Realms and their counterparts</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#environments\">8.1.3.1 Environments</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#environment-settings-objects\">8.1.3.2 Environment settings objects</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#realms-settings-objects-global-objects\">8.1.3.3 Realms, settings objects, and global objects</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#entry\">8.1.3.3.1 Entry</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#incumbent\">8.1.3.3.2 Incumbent</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#current\">8.1.3.3.3 Current</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#relevant\">8.1.3.3.4 Relevant</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#enabling-and-disabling-scripting\">8.1.3.4 Enabling and disabling scripting</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#secure-contexts\">8.1.3.5 Secure contexts</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#scripting-processing-model\">8.1.4 Script processing model</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#script-structs\">8.1.4.1 Scripts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#fetching-scripts\">8.1.4.2 Fetching scripts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#creating-scripts\">8.1.4.3 Creating scripts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#calling-scripts\">8.1.4.4 Calling scripts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#killing-scripts\">8.1.4.5 Killing scripts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#runtime-script-errors\">8.1.4.6 Runtime script errors</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#unhandled-promise-rejections\">8.1.4.7 Unhandled promise rejections</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#javascript-specification-host-hooks\">8.1.5 JavaScript specification host hooks</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#hostensurecancompilestrings(callerrealm,-calleerealm)\">8.1.5.1 HostEnsureCanCompileStrings(callerRealm, calleeRealm)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-hostpromiserejectiontracker-implementation\">8.1.5.2 HostPromiseRejectionTracker(promise, operation)</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#integration-with-javascript-jobs\">8.1.5.3 Job-related host hooks</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#hostcalljobcallback\">8.1.5.3.1 HostCallJobCallback(callback, V, argumentsList)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#hostenqueuefinalizationregistrycleanupjob\">8.1.5.3.2 HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#hostenqueuepromisejob\">8.1.5.3.3 HostEnqueuePromiseJob(job, realm)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#hostmakejobcallback\">8.1.5.3.4 HostMakeJobCallback(callable)</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#integration-with-the-javascript-module-system\">8.1.5.4 Module-related host hooks</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#hostgetimportmetaproperties\">8.1.5.4.1 HostGetImportMetaProperties(moduleRecord)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#hostimportmoduledynamically(referencingscriptormodule,-modulerequest,-promisecapability)\">8.1.5.4.2 HostImportModuleDynamically(referencingScriptOrModule, moduleRequest, promiseCapability)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#hostresolveimportedmodule(referencingscriptormodule,-modulerequest)\">8.1.5.4.3 HostResolveImportedModule(referencingScriptOrModule, moduleRequest)</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#hostgetsupportedimportassertions\">8.1.5.4.4 HostGetSupportedImportAssertions()</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#event-loops\">8.1.6 Event loops</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#definitions-3\">8.1.6.1 Definitions</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#queuing-tasks\">8.1.6.2 Queuing tasks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#event-loop-processing-model\">8.1.6.3 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#generic-task-sources\">8.1.6.4 Generic task sources</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#event-loop-for-spec-authors\">8.1.6.5 Dealing with the event loop from other specifications</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#events\">8.1.7 Events</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#event-handler-attributes\">8.1.7.1 Event handlers</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#event-handlers-on-elements,-document-objects,-and-window-objects\">8.1.7.2 Event handlers on elements, <code class=\"language-text\">Document</code> objects, and <code class=\"language-text\">Window</code> objects</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#idl-definitions\">8.1.7.2.1 IDL definitions</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#event-firing\">8.1.7.3 Event firing</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#windoworworkerglobalscope-mixin\">8.2 The <code class=\"language-text\">WindowOrWorkerGlobalScope</code> mixin</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#atob\">8.3 Base64 utility methods</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#dynamic-markup-insertion\">8.4 Dynamic markup insertion</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#opening-the-input-stream\">8.4.1 Opening the input stream</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#closing-the-input-stream\">8.4.2 Closing the input stream</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#document.write()\">8.4.3 <code class=\"language-text\">document.write()</code></a></li>\n<li><a href=\"https://html.spec.whatwg.org/#document.writeln()\">8.4.4 <code class=\"language-text\">document.writeln()</code></a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#dom-parsing-and-serialization\">8.5 DOM parsing</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#timers\">8.6 Timers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#microtask-queuing\">8.7 Microtask queuing</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#user-prompts\">8.8 User prompts</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#simple-dialogs\">8.8.1 Simple dialogs</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#printing\">8.8.2 Printing</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#system-state-and-capabilities\">8.9 System state and capabilities</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-navigator-object\">8.9.1 The <code class=\"language-text\">Navigator</code> object</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#client-identification\">8.9.1.1 Client identification</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#language-preferences\">8.9.1.2 Language preferences</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#navigator.online\">8.9.1.3 Browser state</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#custom-handlers\">8.9.1.4 Custom scheme handlers: the <code class=\"language-text\">registerProtocolHandler()</code> method</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#security-and-privacy\">8.9.1.4.1 Security and privacy</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#cookies\">8.9.1.5 Cookies</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#pdf-viewing-support\">8.9.1.6 PDF viewing support</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#images-2\">8.10 Images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#animation-frames\">8.11 Animation frames</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#comms\">9 Communication</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-messageevent-interface\">9.1 The <code class=\"language-text\">MessageEvent</code> interface</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#server-sent-events\">9.2 Server-sent events</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#server-sent-events-intro\">9.2.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-eventsource-interface\">9.2.2 The <code class=\"language-text\">EventSource</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sse-processing-model\">9.2.3 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-an-event-stream\">9.2.4 Parsing an event stream</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#event-stream-interpretation\">9.2.5 Interpreting an event stream</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#authoring-notes\">9.2.6 Authoring notes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#eventsource-push\">9.2.7 Connectionless push and other features</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#garbage-collection\">9.2.8 Garbage collection</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#implementation-advice\">9.2.9 Implementation advice</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#network\">9.3 Web sockets</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#network-intro\">9.3.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-websocket-interface\">9.3.2 The <code class=\"language-text\">WebSocket</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#feedback-from-the-protocol\">9.3.3 Feedback from the protocol</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ping-and-pong-frames\">9.3.4 Ping and Pong frames</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-closeevent-interface\">9.3.5 The <code class=\"language-text\">CloseEvent</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#garbage-collection-2\">9.3.6 Garbage collection</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#web-messaging\">9.4 Cross-document messaging</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-12\">9.4.1 Introduction</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#security-postmsg\">9.4.2 Security</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#authors\">9.4.2.1 Authors</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#user-agents\">9.4.2.2 User agents</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#posting-messages\">9.4.3 Posting messages</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#channel-messaging\">9.5 Channel messaging</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#introduction-13\">9.5.1 Introduction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#examples-5\">9.5.1.1 Examples</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ports-as-the-basis-of-an-object-capability-model-on-the-web\">9.5.1.2 Ports as the basis of an object-capability model on the web</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ports-as-the-basis-of-abstracting-out-service-implementations\">9.5.1.3 Ports as the basis of abstracting out service implementations</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#message-channels\">9.5.2 Message channels</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#message-ports\">9.5.3 Message ports</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#broadcasting-to-many-ports\">9.5.4 Broadcasting to many ports</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ports-and-garbage-collection\">9.5.5 Ports and garbage collection</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#broadcasting-to-other-browsing-contexts\">9.6 Broadcasting to other browsing contexts</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#workers\">10 Web workers</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#introduction-14\">10.1 Introduction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#scope-2\">10.1.1 Scope</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#examples-6\">10.1.2 Examples</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#a-background-number-crunching-worker\">10.1.2.1 A background number-crunching worker</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#module-worker-example\">10.1.2.2 Using a JavaScript module as a worker</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#shared-workers-introduction\">10.1.2.3 Shared workers introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#shared-state-using-a-shared-worker\">10.1.2.4 Shared state using a shared worker</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#delegation\">10.1.2.5 Delegation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#providing-libraries\">10.1.2.6 Providing libraries</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#tutorials\">10.1.3 Tutorials</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#creating-a-dedicated-worker\">10.1.3.1 Creating a dedicated worker</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#communicating-with-a-dedicated-worker\">10.1.3.2 Communicating with a dedicated worker</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#shared-workers\">10.1.3.3 Shared workers</a></li>\n</ol>\n</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#infrastructure-2\">10.2 Infrastructure</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-global-scope\">10.2.1 The global scope</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-workerglobalscope-common-interface\">10.2.1.1 The <code class=\"language-text\">WorkerGlobalScope</code> common interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dedicated-workers-and-the-dedicatedworkerglobalscope-interface\">10.2.1.2 Dedicated workers and the <code class=\"language-text\">DedicatedWorkerGlobalScope</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#shared-workers-and-the-sharedworkerglobalscope-interface\">10.2.1.3 Shared workers and the <code class=\"language-text\">SharedWorkerGlobalScope</code> interface</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#worker-event-loop\">10.2.2 The event loop</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-worker&#x27;s-lifetime\">10.2.3 The worker's lifetime</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#worker-processing-model\">10.2.4 Processing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#runtime-script-errors-2\">10.2.5 Runtime script errors</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#creating-workers\">10.2.6 Creating workers</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-abstractworker-mixin\">10.2.6.1 The <code class=\"language-text\">AbstractWorker</code> mixin</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-settings-for-workers\">10.2.6.2 Script settings for workers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#dedicated-workers-and-the-worker-interface\">10.2.6.3 Dedicated workers and the <code class=\"language-text\">Worker</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#shared-workers-and-the-sharedworker-interface\">10.2.6.4 Shared workers and the <code class=\"language-text\">SharedWorker</code> interface</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#navigator.hardwareconcurrency\">10.2.7 Concurrent hardware capabilities</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#apis-available-to-workers\">10.3 APIs available to workers</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#importing-scripts-and-libraries\">10.3.1 Importing scripts and libraries</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-workernavigator-object\">10.3.2 The <code class=\"language-text\">WorkerNavigator</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#worker-locations\">10.3.3 The <code class=\"language-text\">WorkerLocation</code> interface</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#worklets\">11 Worklets</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#worklets-intro\">11.1 Introduction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#worklets-motivations\">11.1.1 Motivations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#worklets-idempotent\">11.1.2 Code idempotence</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#worklets-speculative\">11.1.3 Speculative evaluation</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#worklets-examples\">11.2 Examples</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#worklets-examples-loading\">11.2.1 Loading scripts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#worklets-example-registering\">11.2.2 Registering a class and invoking its methods</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#worklets-infrastructure\">11.3 Infrastructure</a></p>\n<ol>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#worklets-global\">11.3.1 The global scope</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#worklet-agents-and-event-loops\">11.3.1.1 Agents and event loops</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#worklets-creation-termination\">11.3.1.2 Creation and termination</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-settings-for-worklets\">11.3.1.3 Script settings for worklets</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#worklets-worklet\">11.3.2 The <code class=\"language-text\">Worklet</code> class</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#worklets-lifetime\">11.3.3 The worklet's lifetime</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#webstorage\">12 Web storage</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-15\">12.1 Introduction</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#storage\">12.2 The API</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-storage-interface\">12.2.1 The <code class=\"language-text\">Storage</code> interface</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-sessionstorage-attribute\">12.2.2 The <code class=\"language-text\">sessionStorage</code> getter</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-localstorage-attribute\">12.2.3 The <code class=\"language-text\">localStorage</code> getter</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-storageevent-interface\">12.2.4 The <code class=\"language-text\">StorageEvent</code> interface</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#privacy\">12.3 Privacy</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#user-tracking\">12.3.1 User tracking</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sensitivity-of-data\">12.3.2 Sensitivity of data</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#security-storage\">12.4 Security</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#dns-spoofing-attacks\">12.4.1 DNS spoofing attacks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cross-directory-attacks\">12.4.2 Cross-directory attacks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#implementation-risks\">12.4.3 Implementation risks</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#syntax\">13 The HTML syntax</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#writing\">13.1 Writing HTML documents</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-doctype\">13.1.1 The DOCTYPE</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#elements-2\">13.1.2 Elements</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#start-tags\">13.1.2.1 Start tags</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#end-tags\">13.1.2.2 End tags</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attributes-2\">13.1.2.3 Attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#optional-tags\">13.1.2.4 Optional tags</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#element-restrictions\">13.1.2.5 Restrictions on content models</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cdata-rcdata-restrictions\">13.1.2.6 Restrictions on the contents of raw text and escapable raw text elements</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#text-2\">13.1.3 Text</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#newlines\">13.1.3.1 Newlines</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#character-references\">13.1.4 Character references</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cdata-sections\">13.1.5 CDATA sections</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comments\">13.1.6 Comments</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#parsing\">13.2 Parsing HTML documents</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#overview-of-the-parsing-model\">13.2.1 Overview of the parsing model</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parse-errors\">13.2.2 Parse errors</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#the-input-byte-stream\">13.2.3 The input byte stream</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-with-a-known-character-encoding\">13.2.3.1 Parsing with a known character encoding</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#determining-the-character-encoding\">13.2.3.2 Determining the character encoding</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#character-encodings\">13.2.3.3 Character encodings</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#changing-the-encoding-while-parsing\">13.2.3.4 Changing the encoding while parsing</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#preprocessing-the-input-stream\">13.2.3.5 Preprocessing the input stream</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#parse-state\">13.2.4 Parse state</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-insertion-mode\">13.2.4.1 The insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-stack-of-open-elements\">13.2.4.2 The stack of open elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-list-of-active-formatting-elements\">13.2.4.3 The list of active formatting elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-element-pointers\">13.2.4.4 The element pointers</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#other-parsing-state-flags\">13.2.4.5 Other parsing state flags</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#tokenization\">13.2.5 Tokenization</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#data-state\">13.2.5.1 Data state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rcdata-state\">13.2.5.2 RCDATA state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rawtext-state\">13.2.5.3 RAWTEXT state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-state\">13.2.5.4 Script data state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#plaintext-state\">13.2.5.5 PLAINTEXT state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#tag-open-state\">13.2.5.6 Tag open state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#end-tag-open-state\">13.2.5.7 End tag open state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#tag-name-state\">13.2.5.8 Tag name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rcdata-less-than-sign-state\">13.2.5.9 RCDATA less-than sign state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rcdata-end-tag-open-state\">13.2.5.10 RCDATA end tag open state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rcdata-end-tag-name-state\">13.2.5.11 RCDATA end tag name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rawtext-less-than-sign-state\">13.2.5.12 RAWTEXT less-than sign state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rawtext-end-tag-open-state\">13.2.5.13 RAWTEXT end tag open state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rawtext-end-tag-name-state\">13.2.5.14 RAWTEXT end tag name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-less-than-sign-state\">13.2.5.15 Script data less-than sign state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-end-tag-open-state\">13.2.5.16 Script data end tag open state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-end-tag-name-state\">13.2.5.17 Script data end tag name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-escape-start-state\">13.2.5.18 Script data escape start state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-escape-start-dash-state\">13.2.5.19 Script data escape start dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-escaped-state\">13.2.5.20 Script data escaped state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-escaped-dash-state\">13.2.5.21 Script data escaped dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-escaped-dash-dash-state\">13.2.5.22 Script data escaped dash dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-escaped-less-than-sign-state\">13.2.5.23 Script data escaped less-than sign state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-escaped-end-tag-open-state\">13.2.5.24 Script data escaped end tag open state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-escaped-end-tag-name-state\">13.2.5.25 Script data escaped end tag name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-double-escape-start-state\">13.2.5.26 Script data double escape start state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-double-escaped-state\">13.2.5.27 Script data double escaped state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-double-escaped-dash-state\">13.2.5.28 Script data double escaped dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-double-escaped-dash-dash-state\">13.2.5.29 Script data double escaped dash dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-double-escaped-less-than-sign-state\">13.2.5.30 Script data double escaped less-than sign state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#script-data-double-escape-end-state\">13.2.5.31 Script data double escape end state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#before-attribute-name-state\">13.2.5.32 Before attribute name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attribute-name-state\">13.2.5.33 Attribute name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#after-attribute-name-state\">13.2.5.34 After attribute name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#before-attribute-value-state\">13.2.5.35 Before attribute value state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state\">13.2.5.36 Attribute value (double-quoted) state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state\">13.2.5.37 Attribute value (single-quoted) state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attribute-value-(unquoted)-state\">13.2.5.38 Attribute value (unquoted) state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#after-attribute-value-(quoted)-state\">13.2.5.39 After attribute value (quoted) state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#self-closing-start-tag-state\">13.2.5.40 Self-closing start tag state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#bogus-comment-state\">13.2.5.41 Bogus comment state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#markup-declaration-open-state\">13.2.5.42 Markup declaration open state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-start-state\">13.2.5.43 Comment start state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-start-dash-state\">13.2.5.44 Comment start dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-state\">13.2.5.45 Comment state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-less-than-sign-state\">13.2.5.46 Comment less-than sign state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-less-than-sign-bang-state\">13.2.5.47 Comment less-than sign bang state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-less-than-sign-bang-dash-state\">13.2.5.48 Comment less-than sign bang dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-less-than-sign-bang-dash-dash-state\">13.2.5.49 Comment less-than sign bang dash dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-end-dash-state\">13.2.5.50 Comment end dash state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-end-state\">13.2.5.51 Comment end state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#comment-end-bang-state\">13.2.5.52 Comment end bang state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#doctype-state\">13.2.5.53 DOCTYPE state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#before-doctype-name-state\">13.2.5.54 Before DOCTYPE name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#doctype-name-state\">13.2.5.55 DOCTYPE name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#after-doctype-name-state\">13.2.5.56 After DOCTYPE name state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#after-doctype-public-keyword-state\">13.2.5.57 After DOCTYPE public keyword state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#before-doctype-public-identifier-state\">13.2.5.58 Before DOCTYPE public identifier state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#doctype-public-identifier-(double-quoted)-state\">13.2.5.59 DOCTYPE public identifier (double-quoted) state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#doctype-public-identifier-(single-quoted)-state\">13.2.5.60 DOCTYPE public identifier (single-quoted) state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#after-doctype-public-identifier-state\">13.2.5.61 After DOCTYPE public identifier state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#between-doctype-public-and-system-identifiers-state\">13.2.5.62 Between DOCTYPE public and system identifiers state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#after-doctype-system-keyword-state\">13.2.5.63 After DOCTYPE system keyword state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#before-doctype-system-identifier-state\">13.2.5.64 Before DOCTYPE system identifier state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#doctype-system-identifier-(double-quoted)-state\">13.2.5.65 DOCTYPE system identifier (double-quoted) state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#doctype-system-identifier-(single-quoted)-state\">13.2.5.66 DOCTYPE system identifier (single-quoted) state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#after-doctype-system-identifier-state\">13.2.5.67 After DOCTYPE system identifier state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#bogus-doctype-state\">13.2.5.68 Bogus DOCTYPE state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cdata-section-state\">13.2.5.69 CDATA section state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cdata-section-bracket-state\">13.2.5.70 CDATA section bracket state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cdata-section-end-state\">13.2.5.71 CDATA section end state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#character-reference-state\">13.2.5.72 Character reference state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#named-character-reference-state\">13.2.5.73 Named character reference state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ambiguous-ampersand-state\">13.2.5.74 Ambiguous ampersand state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#numeric-character-reference-state\">13.2.5.75 Numeric character reference state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#hexadecimal-character-reference-start-state\">13.2.5.76 Hexadecimal character reference start state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#decimal-character-reference-start-state\">13.2.5.77 Decimal character reference start state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#hexadecimal-character-reference-state\">13.2.5.78 Hexadecimal character reference state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#decimal-character-reference-state\">13.2.5.79 Decimal character reference state</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#numeric-character-reference-end-state\">13.2.5.80 Numeric character reference end state</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#tree-construction\">13.2.6 Tree construction</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#creating-and-inserting-nodes\">13.2.6.1 Creating and inserting nodes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-elements-that-contain-only-text\">13.2.6.2 Parsing elements that contain only text</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#closing-elements-that-have-implied-end-tags\">13.2.6.3 Closing elements that have implied end tags</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#parsing-main-inhtml\">13.2.6.4 The rules for parsing tokens in HTML content</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-initial-insertion-mode\">13.2.6.4.1 The \"initial\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-before-html-insertion-mode\">13.2.6.4.2 The \"before html\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-before-head-insertion-mode\">13.2.6.4.3 The \"before head\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-inhead\">13.2.6.4.4 The \"in head\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-inheadnoscript\">13.2.6.4.5 The \"in head noscript\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-after-head-insertion-mode\">13.2.6.4.6 The \"after head\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-inbody\">13.2.6.4.7 The \"in body\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-incdata\">13.2.6.4.8 The \"text\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-intable\">13.2.6.4.9 The \"in table\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-intabletext\">13.2.6.4.10 The \"in table text\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-incaption\">13.2.6.4.11 The \"in caption\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-incolgroup\">13.2.6.4.12 The \"in column group\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-intbody\">13.2.6.4.13 The \"in table body\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-intr\">13.2.6.4.14 The \"in row\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-intd\">13.2.6.4.15 The \"in cell\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-inselect\">13.2.6.4.16 The \"in select\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-inselectintable\">13.2.6.4.17 The \"in select in table\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-intemplate\">13.2.6.4.18 The \"in template\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-afterbody\">13.2.6.4.19 The \"after body\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-inframeset\">13.2.6.4.20 The \"in frameset\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-afterframeset\">13.2.6.4.21 The \"after frameset\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-after-after-body-insertion-mode\">13.2.6.4.22 The \"after after body\" insertion mode</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-after-after-frameset-insertion-mode\">13.2.6.4.23 The \"after after frameset\" insertion mode</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-main-inforeign\">13.2.6.5 The rules for parsing tokens in foreign content</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#the-end\">13.2.7 The end</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#speculative-html-parsing\">13.2.8 Speculative HTML parsing</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#coercing-an-html-dom-into-an-infoset\">13.2.9 Coercing an HTML DOM into an infoset</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#an-introduction-to-error-handling-and-strange-cases-in-the-parser\">13.2.10 An introduction to error handling and strange cases in the parser</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#misnested-tags:-b-i-/b-/i\">13.2.10.1 Misnested tags: <b>\n<i>\n</b>\n</i></a></li>\n<li>\n<p>[13.2.10.2 Misnested tags: <b></p>\n<p>\n</b>\n</p>](https://html.spec.whatwg.org/#misnested-tags:-b-p-/b-/p)\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#unexpected-markup-in-tables\">13.2.10.3 Unexpected markup in tables</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#scripts-that-modify-the-page-as-it-is-being-parsed\">13.2.10.4 Scripts that modify the page as it is being parsed</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-execution-of-scripts-that-are-moving-across-multiple-documents\">13.2.10.5 The execution of scripts that are moving across multiple documents</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#unclosed-formatting-elements\">13.2.10.6 Unclosed formatting elements</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#serialising-html-fragments\">13.3 Serializing HTML fragments</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-html-fragments\">13.4 Parsing HTML fragments</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#named-character-references\">13.5 Named character references</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-xhtml-syntax\">14 The XML syntax</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#writing-xhtml-documents\">14.1 Writing documents in the XML syntax</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-xhtml-documents\">14.2 Parsing XML documents</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#serialising-xhtml-fragments\">14.3 Serializing XML fragments</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#parsing-xhtml-fragments\">14.4 Parsing XML fragments</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#rendering\">15 Rendering</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-16\">15.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-css-user-agent-style-sheet-and-presentational-hints\">15.2 The CSS user agent style sheet and presentational hints</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#non-replaced-elements\">15.3 Non-replaced elements</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#hidden-elements\">15.3.1 Hidden elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-page\">15.3.2 The page</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#flow-content-3\">15.3.3 Flow content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#phrasing-content-3\">15.3.4 Phrasing content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#bidi-rendering\">15.3.5 Bidirectional text</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#sections-and-headings\">15.3.6 Sections and headings</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#lists\">15.3.7 Lists</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#tables-2\">15.3.8 Tables</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#margin-collapsing-quirks\">15.3.9 Margin collapsing quirks</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#form-controls\">15.3.10 Form controls</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-hr-element-2\">15.3.11 The <code class=\"language-text\">hr</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-fieldset-and-legend-elements\">15.3.12 The <code class=\"language-text\">fieldset</code> and <code class=\"language-text\">legend</code> elements</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#replaced-elements\">15.4 Replaced elements</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#embedded-content-rendering-rules\">15.4.1 Embedded content</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#images-3\">15.4.2 Images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attributes-for-embedded-content-and-images\">15.4.3 Attributes for embedded content and images</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#image-maps-2\">15.4.4 Image maps</a></li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#widgets\">15.5 Widgets</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#introduction-17\">15.5.1 Introduction</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#button-layout\">15.5.2 Button layout</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-button-element-2\">15.5.3 The <code class=\"language-text\">button</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-details-and-summary-elements\">15.5.4 The <code class=\"language-text\">details</code> and <code class=\"language-text\">summary</code> elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-input-element-as-a-text-entry-widget\">15.5.5 The <code class=\"language-text\">input</code> element as a text entry widget</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-input-element-as-domain-specific-widgets\">15.5.6 The <code class=\"language-text\">input</code> element as domain-specific widgets</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-input-element-as-a-range-control\">15.5.7 The <code class=\"language-text\">input</code> element as a range control</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-input-element-as-a-colour-well\">15.5.8 The <code class=\"language-text\">input</code> element as a color well</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-input-element-as-a-checkbox-and-radio-button-widgets\">15.5.9 The <code class=\"language-text\">input</code> element as a checkbox and radio button widgets</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-input-element-as-a-file-upload-control\">15.5.10 The <code class=\"language-text\">input</code> element as a file upload control</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-input-element-as-a-button\">15.5.11 The <code class=\"language-text\">input</code> element as a button</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-marquee-element-2\">15.5.12 The <code class=\"language-text\">marquee</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-meter-element-2\">15.5.13 The <code class=\"language-text\">meter</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-progress-element-2\">15.5.14 The <code class=\"language-text\">progress</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-select-element-2\">15.5.15 The <code class=\"language-text\">select</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-textarea-element-2\">15.5.16 The <code class=\"language-text\">textarea</code> element</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#frames-and-framesets\">15.6 Frames and framesets</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#interactive-media\">15.7 Interactive media</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#links,-forms,-and-navigation\">15.7.1 Links, forms, and navigation</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#the-title-attribute-2\">15.7.2 The <code class=\"language-text\">title</code> attribute</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#editing-hosts\">15.7.3 Editing hosts</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text-rendered-in-native-user-interfaces\">15.7.4 Text rendered in native user interfaces</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#print-media\">15.8 Print media</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#unstyled-xml-documents\">15.9 Unstyled XML documents</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#obsolete\">16 Obsolete features</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#obsolete-but-conforming-features\">16.1 Obsolete but conforming features</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#warnings-for-obsolete-but-conforming-features\">16.1.1 Warnings for obsolete but conforming features</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#non-conforming-features\">16.2 Non-conforming features</a></li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/#requirements-for-implementations\">16.3 Requirements for implementations</a></p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/#the-marquee-element\">16.3.1 The <code class=\"language-text\">marquee</code> element</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#frames\">16.3.2 Frames</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#other-elements,-attributes-and-apis\">16.3.3 Other elements, attributes and APIs</a></li>\n</ol>\n</li>\n<li><a href=\"https://html.spec.whatwg.org/#iana\">17 IANA considerations</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text/html\">17.1 <code class=\"language-text\">text/html</code></a></li>\n<li><a href=\"https://html.spec.whatwg.org/#multipart/x-mixed-replace\">17.2 <code class=\"language-text\">multipart/x-mixed-replace</code></a></li>\n<li><a href=\"https://html.spec.whatwg.org/#application/xhtml+xml\">17.3 <code class=\"language-text\">application/xhtml+xml</code></a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text/ping\">17.4 <code class=\"language-text\">text/ping</code></a></li>\n<li><a href=\"https://html.spec.whatwg.org/#application/microdata+json\">17.5 <code class=\"language-text\">application/microdata+json</code></a></li>\n<li><a href=\"https://html.spec.whatwg.org/#text/event-stream\">17.6 <code class=\"language-text\">text/event-stream</code></a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cross-origin-embedder-policy\">17.7 `<code class=\"language-text\">Cross-Origin-Embedder-Policy</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cross-origin-embedder-policy-report-only\">17.8 `<code class=\"language-text\">Cross-Origin-Embedder-Policy-Report-Only</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cross-origin-opener-policy-2\">17.9 `<code class=\"language-text\">Cross-Origin-Opener-Policy</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#cross-origin-opener-policy-report-only\">17.10 `<code class=\"language-text\">Cross-Origin-Opener-Policy-Report-Only</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#origin-agent-cluster\">17.11 `<code class=\"language-text\">Origin-Agent-Cluster</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ping-from\">17.12 `<code class=\"language-text\">Ping-From</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ping-to\">17.13 `<code class=\"language-text\">Ping-To</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#refresh\">17.14 `<code class=\"language-text\">Refresh</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#last-event-id\">17.15 `<code class=\"language-text\">Last-Event-ID</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#x-frame-options\">17.16 `<code class=\"language-text\">X-Frame-Options</code>`</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#web+-scheme-prefix\">17.17 <code class=\"language-text\">web+</code> scheme prefix</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#index\">Index</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#elements-3\">Elements</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#element-content-categories\">Element content categories</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#attributes-3\">Attributes</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#element-interfaces\">Element Interfaces</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#all-interfaces\">All Interfaces</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#events-2\">Events</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#mime-types-2\">MIME Types</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#references\">References</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#acknowledgments\">Acknowledgments</a></li>\n<li><a href=\"https://html.spec.whatwg.org/#ipr\">Intellectual property rights</a></li>\n</ol>"},{"url":"/docs/projects/links/","relativePath":"docs/projects/links.md","relativeDir":"docs/projects","base":"links.md","name":"links","frontmatter":{"title":"Links","template":"docs","excerpt":"Links to my websites"},"html":"<table>\n<thead>\n<tr>\n<th><a href=\"https://bgoonz-blog-2-0.pages.dev/blog/platform-docs\">https://bgoonz-blog-2-0.pages.dev/blog/platform-docs</a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs\">https://bgoonz-blog-2-0.pages.dev/docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/about\">https://bgoonz-blog-2-0.pages.dev/docs/about</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/about/job-search\">https://bgoonz-blog-2-0.pages.dev/docs/about/job-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/articles\">https://bgoonz-blog-2-0.pages.dev/docs/articles</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/articles/nodejs\">https://bgoonz-blog-2-0.pages.dev/docs/articles/nodejs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/career\">https://bgoonz-blog-2-0.pages.dev/docs/career</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/career/dev-interview\">https://bgoonz-blog-2-0.pages.dev/docs/career/dev-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/career/job-boards\">https://bgoonz-blog-2-0.pages.dev/docs/career/job-boards</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/community\">https://bgoonz-blog-2-0.pages.dev/docs/community</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/community/bookmarks\">https://bgoonz-blog-2-0.pages.dev/docs/community/bookmarks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/content\">https://bgoonz-blog-2-0.pages.dev/docs/content</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/css\">https://bgoonz-blog-2-0.pages.dev/docs/css</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/data-structures\">https://bgoonz-blog-2-0.pages.dev/docs/data-structures</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/docs\">https://bgoonz-blog-2-0.pages.dev/docs/docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/docs/no-whiteboarding\">https://bgoonz-blog-2-0.pages.dev/docs/docs/no-whiteboarding</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/faq\">https://bgoonz-blog-2-0.pages.dev/docs/faq</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/faq/contact\">https://bgoonz-blog-2-0.pages.dev/docs/faq/contact</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/interact\">https://bgoonz-blog-2-0.pages.dev/docs/interact</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/interview\">https://bgoonz-blog-2-0.pages.dev/docs/interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/interview/job-search-nav\">https://bgoonz-blog-2-0.pages.dev/docs/interview/job-search-nav</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/javascript\">https://bgoonz-blog-2-0.pages.dev/docs/javascript</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/leetcode\">https://bgoonz-blog-2-0.pages.dev/docs/leetcode</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/projects\">https://bgoonz-blog-2-0.pages.dev/docs/projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/python/python-ds\">https://bgoonz-blog-2-0.pages.dev/docs/python/python-ds</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/quick-reference\">https://bgoonz-blog-2-0.pages.dev/docs/quick-reference</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/react\">https://bgoonz-blog-2-0.pages.dev/docs/react</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/reference\">https://bgoonz-blog-2-0.pages.dev/docs/reference</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/sitemap/link\">https://bgoonz-blog-2-0.pages.dev/docs/sitemap/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/tips\">https://bgoonz-blog-2-0.pages.dev/docs/tips</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/tools/archive\">https://bgoonz-blog-2-0.pages.dev/docs/tools/archive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/tools/link\">https://bgoonz-blog-2-0.pages.dev/docs/tools/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog-2-0.pages.dev/docs/tutorials\">https://bgoonz-blog-2-0.pages.dev/docs/tutorials</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify\">https://bgoonz-blog.netlify</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app\">https://bgoonz-blog.netlify.app</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/\">https://bgoonz-blog.netlify.app/</a>\"<a href=\"https://bgoonz-blog.netlify\">https://bgoonz-blog.netlify</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog\">https://bgoonz-blog.netlify.app/blog</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/300-react-questions\">https://bgoonz-blog.netlify.app/blog/300-react-questions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/adding-css-to-your-html\">https://bgoonz-blog.netlify.app/blog/adding-css-to-your-html</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/awesome-graphql\">https://bgoonz-blog.netlify.app/blog/awesome-graphql</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/big-o-complexity\">https://bgoonz-blog.netlify.app/blog/big-o-complexity</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/blog-archive\">https://bgoonz-blog.netlify.app/blog/blog-archive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/blogwcomments\">https://bgoonz-blog.netlify.app/blog/blogwcomments</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures\">https://bgoonz-blog.netlify.app/blog/data-structures</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures-algorithms-resources\">https://bgoonz-blog.netlify.app/blog/data-structures-algorithms-resources</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/date-component\">https://bgoonz-blog.netlify.app/blog/date-component</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/embedding-media-in-html\">https://bgoonz-blog.netlify.app/blog/embedding-media-in-html</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/event-handeling\">https://bgoonz-blog.netlify.app/blog/event-handeling</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/expressjs-apis\">https://bgoonz-blog.netlify.app/blog/expressjs-apis</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/flow-control-in-python\">https://bgoonz-blog.netlify.app/blog/flow-control-in-python</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/functions-in-python\">https://bgoonz-blog.netlify.app/blog/functions-in-python</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/git-gateway\">https://bgoonz-blog.netlify.app/blog/git-gateway</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/grep-in-linuz\">https://bgoonz-blog.netlify.app/blog/grep-in-linuz</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/hoisting\">https://bgoonz-blog.netlify.app/blog/hoisting</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/htt-requests\">https://bgoonz-blog.netlify.app/blog/htt-requests</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js\">https://bgoonz-blog.netlify.app/blog/interview-questions-js</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js-p2\">https://bgoonz-blog.netlify.app/blog/interview-questions-js-p2</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/interview-questions-js-p3\">https://bgoonz-blog.netlify.app/blog/interview-questions-js-p3</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/intro-01-data-structures\">https://bgoonz-blog.netlify.app/blog/intro-01-data-structures</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/js-closure\">https://bgoonz-blog.netlify.app/blog/js-closure</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/netlify-cms\">https://bgoonz-blog.netlify.app/blog/netlify-cms</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/passing-arguments-to-a-callback-in-js\">https://bgoonz-blog.netlify.app/blog/passing-arguments-to-a-callback-in-js</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/platform-docs\">https://bgoonz-blog.netlify.app/blog/platform-docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/psql-cheat-sheet\">https://bgoonz-blog.netlify.app/blog/psql-cheat-sheet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/python-for-js-dev\">https://bgoonz-blog.netlify.app/blog/python-for-js-dev</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/python-resources\">https://bgoonz-blog.netlify.app/blog/python-resources</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/react-semantics\">https://bgoonz-blog.netlify.app/blog/react-semantics</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/react-state\">https://bgoonz-blog.netlify.app/blog/react-state</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/using-the-dom\">https://bgoonz-blog.netlify.app/blog/using-the-dom</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/vs-code-extensions\">https://bgoonz-blog.netlify.app/blog/vs-code-extensions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/vscode-extensions\">https://bgoonz-blog.netlify.app/blog/vscode-extensions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/web-dev-trends\">https://bgoonz-blog.netlify.app/blog/web-dev-trends</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/blog/web-scraping\">https://bgoonz-blog.netlify.app/blog/web-scraping</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs\">https://bgoonz-blog.netlify.app/docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/about\">https://bgoonz-blog.netlify.app/docs/about</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/about/eng-portfolio\">https://bgoonz-blog.netlify.app/docs/about/eng-portfolio</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/about/intrests\">https://bgoonz-blog.netlify.app/docs/about/intrests</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/about/job-search\">https://bgoonz-blog.netlify.app/docs/about/job-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/about/readme\">https://bgoonz-blog.netlify.app/docs/about/readme</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/about/resume\">https://bgoonz-blog.netlify.app/docs/about/resume</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/about/youtube\">https://bgoonz-blog.netlify.app/docs/about/youtube</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/archive/embeded-websites\">https://bgoonz-blog.netlify.app/docs/archive/embeded-websites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/archive/link\">https://bgoonz-blog.netlify.app/docs/archive/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles\">https://bgoonz-blog.netlify.app/docs/articles</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev\">https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/buffers\">https://bgoonz-blog.netlify.app/docs/articles/buffers</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/common-modules\">https://bgoonz-blog.netlify.app/docs/articles/common-modules</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/dev-dep\">https://bgoonz-blog.netlify.app/docs/articles/dev-dep</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/event-loop\">https://bgoonz-blog.netlify.app/docs/articles/event-loop</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/fs-module\">https://bgoonz-blog.netlify.app/docs/articles/fs-module</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-search-engines-work\">https://bgoonz-blog.netlify.app/docs/articles/how-search-engines-work</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/how-the-web-works\">https://bgoonz-blog.netlify.app/docs/articles/how-the-web-works</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/http\">https://bgoonz-blog.netlify.app/docs/articles/http</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/install\">https://bgoonz-blog.netlify.app/docs/articles/install</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/intro\">https://bgoonz-blog.netlify.app/docs/articles/intro</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/jamstack\">https://bgoonz-blog.netlify.app/docs/articles/jamstack</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/modules\">https://bgoonz-blog.netlify.app/docs/articles/modules</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nextjs\">https://bgoonz-blog.netlify.app/docs/articles/nextjs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-api-express\">https://bgoonz-blog.netlify.app/docs/articles/node-api-express</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-cli-args\">https://bgoonz-blog.netlify.app/docs/articles/node-cli-args</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-common-modules\">https://bgoonz-blog.netlify.app/docs/articles/node-common-modules</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-env-variables\">https://bgoonz-blog.netlify.app/docs/articles/node-env-variables</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-js-language\">https://bgoonz-blog.netlify.app/docs/articles/node-js-language</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-package-manager\">https://bgoonz-blog.netlify.app/docs/articles/node-package-manager</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-repl\">https://bgoonz-blog.netlify.app/docs/articles/node-repl</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-run-cli\">https://bgoonz-blog.netlify.app/docs/articles/node-run-cli</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nodejs\">https://bgoonz-blog.netlify.app/docs/articles/nodejs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nodevsbrowser\">https://bgoonz-blog.netlify.app/docs/articles/nodevsbrowser</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/npm\">https://bgoonz-blog.netlify.app/docs/articles/npm</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/npx\">https://bgoonz-blog.netlify.app/docs/articles/npx</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/os-module\">https://bgoonz-blog.netlify.app/docs/articles/os-module</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/reading-files\">https://bgoonz-blog.netlify.app/docs/articles/reading-files</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic\">https://bgoonz-blog.netlify.app/docs/articles/semantic</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic-html\">https://bgoonz-blog.netlify.app/docs/articles/semantic-html</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/the-uniform-resource-locator-(url\">https://bgoonz-blog.netlify.app/docs/articles/the-uniform-resource-locator-(url</a>)</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/understanding-firebase\">https://bgoonz-blog.netlify.app/docs/articles/understanding-firebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/url\">https://bgoonz-blog.netlify.app/docs/articles/url</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/v8\">https://bgoonz-blog.netlify.app/docs/articles/v8</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/web-standards-checklist\">https://bgoonz-blog.netlify.app/docs/articles/web-standards-checklist</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/webdev-tools\">https://bgoonz-blog.netlify.app/docs/articles/webdev-tools</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/articles/writing-files\">https://bgoonz-blog.netlify.app/docs/articles/writing-files</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/audio\">https://bgoonz-blog.netlify.app/docs/audio</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/audio/audio\">https://bgoonz-blog.netlify.app/docs/audio/audio</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/audio/audio-feature-extraction\">https://bgoonz-blog.netlify.app/docs/audio/audio-feature-extraction</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dfft\">https://bgoonz-blog.netlify.app/docs/audio/dfft</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/audio/discrete-fft\">https://bgoonz-blog.netlify.app/docs/audio/discrete-fft</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dtw-python-explained\">https://bgoonz-blog.netlify.app/docs/audio/dtw-python-explained</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dynamic-time-warping\">https://bgoonz-blog.netlify.app/docs/audio/dynamic-time-warping</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/audio/web-audio-api\">https://bgoonz-blog.netlify.app/docs/audio/web-audio-api</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career\">https://bgoonz-blog.netlify.app/docs/career</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/dev-interview\">https://bgoonz-blog.netlify.app/docs/career/dev-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/dos-and-donts\">https://bgoonz-blog.netlify.app/docs/career/dos-and-donts</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/interview-dos-n-donts\">https://bgoonz-blog.netlify.app/docs/career/interview-dos-n-donts</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/job-boards\">https://bgoonz-blog.netlify.app/docs/career/job-boards</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/job-search\">https://bgoonz-blog.netlify.app/docs/career/job-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/js-interview\">https://bgoonz-blog.netlify.app/docs/career/js-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/list-of-projects\">https://bgoonz-blog.netlify.app/docs/career/list-of-projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/my-websites\">https://bgoonz-blog.netlify.app/docs/career/my-websites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/projects\">https://bgoonz-blog.netlify.app/docs/career/projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview\">https://bgoonz-blog.netlify.app/docs/career/web-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview2\">https://bgoonz-blog.netlify.app/docs/career/web-interview2</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview3\">https://bgoonz-blog.netlify.app/docs/career/web-interview3</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/web-interview4\">https://bgoonz-blog.netlify.app/docs/career/web-interview4</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/career/wed-dev-questions\">https://bgoonz-blog.netlify.app/docs/career/wed-dev-questions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/community\">https://bgoonz-blog.netlify.app/docs/community</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/community/an-open-letter-2-future-developers\">https://bgoonz-blog.netlify.app/docs/community/an-open-letter-2-future-developers</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/community/bookmarks\">https://bgoonz-blog.netlify.app/docs/community/bookmarks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/community/github-profiles\">https://bgoonz-blog.netlify.app/docs/community/github-profiles</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/community/video-chat\">https://bgoonz-blog.netlify.app/docs/community/video-chat</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content\">https://bgoonz-blog.netlify.app/docs/content</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/algo\">https://bgoonz-blog.netlify.app/docs/content/algo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/archive\">https://bgoonz-blog.netlify.app/docs/content/archive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/bash-intro\">https://bgoonz-blog.netlify.app/docs/content/bash-intro</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/data-structures-in-python\">https://bgoonz-blog.netlify.app/docs/content/data-structures-in-python</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/gatsby-queries-mutations\">https://bgoonz-blog.netlify.app/docs/content/gatsby-queries-mutations</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/gists\">https://bgoonz-blog.netlify.app/docs/content/gists</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/github-api\">https://bgoonz-blog.netlify.app/docs/content/github-api</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/history-api\">https://bgoonz-blog.netlify.app/docs/content/history-api</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/main-projects\">https://bgoonz-blog.netlify.app/docs/content/main-projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/native-data-structures-in-js\">https://bgoonz-blog.netlify.app/docs/content/native-data-structures-in-js</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/netlify\">https://bgoonz-blog.netlify.app/docs/content/netlify</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/content/trouble-shooting\">https://bgoonz-blog.netlify.app/docs/content/trouble-shooting</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/css\">https://bgoonz-blog.netlify.app/docs/css</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/css/css-positioning\">https://bgoonz-blog.netlify.app/docs/css/css-positioning</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/data-structures\">https://bgoonz-blog.netlify.app/docs/data-structures</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/data-structures/big-o\">https://bgoonz-blog.netlify.app/docs/data-structures/big-o</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/data-structures/data-structures-in-depth\">https://bgoonz-blog.netlify.app/docs/data-structures/data-structures-in-depth</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/data-structures/ds-algo-interview\">https://bgoonz-blog.netlify.app/docs/data-structures/ds-algo-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/data-structures/tree\">https://bgoonz-blog.netlify.app/docs/data-structures/tree</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs\">https://bgoonz-blog.netlify.app/docs/docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/appendix\">https://bgoonz-blog.netlify.app/docs/docs/appendix</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/art-of-command-line\">https://bgoonz-blog.netlify.app/docs/docs/art-of-command-line</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/bash\">https://bgoonz-blog.netlify.app/docs/docs/bash</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/css\">https://bgoonz-blog.netlify.app/docs/docs/css</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/data-structures-docs\">https://bgoonz-blog.netlify.app/docs/docs/data-structures-docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/es-6-features\">https://bgoonz-blog.netlify.app/docs/docs/es-6-features</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-reference\">https://bgoonz-blog.netlify.app/docs/docs/git-reference</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-repos\">https://bgoonz-blog.netlify.app/docs/docs/git-repos</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/glossary\">https://bgoonz-blog.netlify.app/docs/docs/glossary</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/html-spec\">https://bgoonz-blog.netlify.app/docs/docs/html-spec</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/html-tags\">https://bgoonz-blog.netlify.app/docs/docs/html-tags</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/jamstack\">https://bgoonz-blog.netlify.app/docs/docs/jamstack</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/markdown\">https://bgoonz-blog.netlify.app/docs/docs/markdown</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/no-whiteboarding\">https://bgoonz-blog.netlify.app/docs/docs/no-whiteboarding</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/node-docs-complete\">https://bgoonz-blog.netlify.app/docs/docs/node-docs-complete</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/node-docs-full\">https://bgoonz-blog.netlify.app/docs/docs/node-docs-full</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/regex-in-js\">https://bgoonz-blog.netlify.app/docs/docs/regex-in-js</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/sitemap\">https://bgoonz-blog.netlify.app/docs/docs/sitemap</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/docs/snippets\">https://bgoonz-blog.netlify.app/docs/docs/snippets</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo\">https://bgoonz-blog.netlify.app/docs/ds-algo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/big-o\">https://bgoonz-blog.netlify.app/docs/ds-algo/big-o</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-docs\">https://bgoonz-blog.netlify.app/docs/ds-algo/data-structures-docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-algo-interview\">https://bgoonz-blog.netlify.app/docs/ds-algo/ds-algo-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-by-example\">https://bgoonz-blog.netlify.app/docs/ds-algo/ds-by-example</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/ds-overview\">https://bgoonz-blog.netlify.app/docs/ds-algo/ds-overview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/free-code-camp\">https://bgoonz-blog.netlify.app/docs/ds-algo/free-code-camp</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/graph\">https://bgoonz-blog.netlify.app/docs/ds-algo/graph</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/heaps\">https://bgoonz-blog.netlify.app/docs/ds-algo/heaps</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/ds-algo/tree\">https://bgoonz-blog.netlify.app/docs/ds-algo/tree</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/faq\">https://bgoonz-blog.netlify.app/docs/faq</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/faq/contact\">https://bgoonz-blog.netlify.app/docs/faq/contact</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/faq/plug-ins\">https://bgoonz-blog.netlify.app/docs/faq/plug-ins</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/gists\">https://bgoonz-blog.netlify.app/docs/gists</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/git\">https://bgoonz-blog.netlify.app/docs/git</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/git/git-cheatsheet\">https://bgoonz-blog.netlify.app/docs/git/git-cheatsheet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/glossary\">https://bgoonz-blog.netlify.app/docs/glossary</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/glossary/folders-in-npm\">https://bgoonz-blog.netlify.app/docs/glossary/folders-in-npm</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/glossary/local-storage-vs-session-storage-vs-cookie\">https://bgoonz-blog.netlify.app/docs/glossary/local-storage-vs-session-storage-vs-cookie</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/glossary/mathfloor\">https://bgoonz-blog.netlify.app/docs/glossary/mathfloor</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/google-hosted-libraries\">https://bgoonz-blog.netlify.app/docs/google-hosted-libraries</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact\">https://bgoonz-blog.netlify.app/docs/interact</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/\">https://bgoonz-blog.netlify.app/docs/interact/</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/callstack-visual\">https://bgoonz-blog.netlify.app/docs/interact/callstack-visual</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/clock\">https://bgoonz-blog.netlify.app/docs/interact/clock</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/jupyter-notebooks\">https://bgoonz-blog.netlify.app/docs/interact/jupyter-notebooks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites\">https://bgoonz-blog.netlify.app/docs/interact/other-sites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites/\">https://bgoonz-blog.netlify.app/docs/interact/other-sites/</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/react-testing-library\">https://bgoonz-blog.netlify.app/docs/interact/react-testing-library</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/video-chat\">https://bgoonz-blog.netlify.app/docs/interact/video-chat</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interact/video-chat/\">https://bgoonz-blog.netlify.app/docs/interact/video-chat/</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview\">https://bgoonz-blog.netlify.app/docs/interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/dev-interview\">https://bgoonz-blog.netlify.app/docs/interview/dev-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/dos-and-donts\">https://bgoonz-blog.netlify.app/docs/interview/dos-and-donts</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/interview-questions\">https://bgoonz-blog.netlify.app/docs/interview/interview-questions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/job-search-nav\">https://bgoonz-blog.netlify.app/docs/interview/job-search-nav</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/previous-concepts\">https://bgoonz-blog.netlify.app/docs/interview/previous-concepts</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/review-concepts\">https://bgoonz-blog.netlify.app/docs/interview/review-concepts</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/web-interview\">https://bgoonz-blog.netlify.app/docs/interview/web-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/web-interview2\">https://bgoonz-blog.netlify.app/docs/interview/web-interview2</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/web-interview3\">https://bgoonz-blog.netlify.app/docs/interview/web-interview3</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/interview/web-interview4\">https://bgoonz-blog.netlify.app/docs/interview/web-interview4</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript\">https://bgoonz-blog.netlify.app/docs/javascript</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/arrow-functions\">https://bgoonz-blog.netlify.app/docs/javascript/arrow-functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/asyncjs\">https://bgoonz-blog.netlify.app/docs/javascript/asyncjs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/await-keyword\">https://bgoonz-blog.netlify.app/docs/javascript/await-keyword</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/bigo\">https://bgoonz-blog.netlify.app/docs/javascript/bigo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/clean-code\">https://bgoonz-blog.netlify.app/docs/javascript/clean-code</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/constructor-functions\">https://bgoonz-blog.netlify.app/docs/javascript/constructor-functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/cs-basics-in-js\">https://bgoonz-blog.netlify.app/docs/javascript/cs-basics-in-js</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/for-loops\">https://bgoonz-blog.netlify.app/docs/javascript/for-loops</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/js-expressions\">https://bgoonz-blog.netlify.app/docs/javascript/js-expressions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/js-objects\">https://bgoonz-blog.netlify.app/docs/javascript/js-objects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/part2-pojo\">https://bgoonz-blog.netlify.app/docs/javascript/part2-pojo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/promises\">https://bgoonz-blog.netlify.app/docs/javascript/promises</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/review\">https://bgoonz-blog.netlify.app/docs/javascript/review</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/snippets\">https://bgoonz-blog.netlify.app/docs/javascript/snippets</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/this-is-about-this\">https://bgoonz-blog.netlify.app/docs/javascript/this-is-about-this</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/variables\">https://bgoonz-blog.netlify.app/docs/javascript/variables</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips\">https://bgoonz-blog.netlify.app/docs/js-tips</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/abs\">https://bgoonz-blog.netlify.app/docs/js-tips/abs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acos\">https://bgoonz-blog.netlify.app/docs/js-tips/acos</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/acosh\">https://bgoonz-blog.netlify.app/docs/js-tips/acosh</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/addition\">https://bgoonz-blog.netlify.app/docs/js-tips/addition</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/all\">https://bgoonz-blog.netlify.app/docs/js-tips/all</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/allsettled\">https://bgoonz-blog.netlify.app/docs/js-tips/allsettled</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/any\">https://bgoonz-blog.netlify.app/docs/js-tips/any</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array\">https://bgoonz-blog.netlify.app/docs/js-tips/array</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/array-methods\">https://bgoonz-blog.netlify.app/docs/js-tips/array-methods</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/arrow_functions\">https://bgoonz-blog.netlify.app/docs/js-tips/arrow_functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/async_function\">https://bgoonz-blog.netlify.app/docs/js-tips/async_function</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bad_radix\">https://bgoonz-blog.netlify.app/docs/js-tips/bad_radix</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/bind\">https://bgoonz-blog.netlify.app/docs/js-tips/bind</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/classes\">https://bgoonz-blog.netlify.app/docs/js-tips/classes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/concat\">https://bgoonz-blog.netlify.app/docs/js-tips/concat</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/conditional_operator\">https://bgoonz-blog.netlify.app/docs/js-tips/conditional_operator</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/const\">https://bgoonz-blog.netlify.app/docs/js-tips/const</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/create\">https://bgoonz-blog.netlify.app/docs/js-tips/create</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/date\">https://bgoonz-blog.netlify.app/docs/js-tips/date</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/eval\">https://bgoonz-blog.netlify.app/docs/js-tips/eval</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/every\">https://bgoonz-blog.netlify.app/docs/js-tips/every</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/filter\">https://bgoonz-blog.netlify.app/docs/js-tips/filter</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/for...of\">https://bgoonz-blog.netlify.app/docs/js-tips/for...of</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/foreach\">https://bgoonz-blog.netlify.app/docs/js-tips/foreach</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/functions\">https://bgoonz-blog.netlify.app/docs/js-tips/functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/import\">https://bgoonz-blog.netlify.app/docs/js-tips/import</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/insert-into-array\">https://bgoonz-blog.netlify.app/docs/js-tips/insert-into-array</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/map\">https://bgoonz-blog.netlify.app/docs/js-tips/map</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/object\">https://bgoonz-blog.netlify.app/docs/js-tips/object</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/reduce\">https://bgoonz-blog.netlify.app/docs/js-tips/reduce</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/regexp\">https://bgoonz-blog.netlify.app/docs/js-tips/regexp</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sort\">https://bgoonz-blog.netlify.app/docs/js-tips/sort</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/sorting-strings\">https://bgoonz-blog.netlify.app/docs/js-tips/sorting-strings</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/string\">https://bgoonz-blog.netlify.app/docs/js-tips/string</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/this\">https://bgoonz-blog.netlify.app/docs/js-tips/this</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/js-tips/var\">https://bgoonz-blog.netlify.app/docs/js-tips/var</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode\">https://bgoonz-blog.netlify.app/docs/leetcode</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/004._median_of_two_sorted_arrays\">https://bgoonz-blog.netlify.app/docs/leetcode/004._median_of_two_sorted_arrays</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/006._zigzag_conversion\">https://bgoonz-blog.netlify.app/docs/leetcode/006._zigzag_conversion</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/008\">https://bgoonz-blog.netlify.app/docs/leetcode/008</a>.<em>string</em>to<em>integer</em></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/009._palindrome_number\">https://bgoonz-blog.netlify.app/docs/leetcode/009._palindrome_number</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/010._regular_expression_matching\">https://bgoonz-blog.netlify.app/docs/leetcode/010._regular_expression_matching</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/011._container_with_most_water\">https://bgoonz-blog.netlify.app/docs/leetcode/011._container_with_most_water</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/012._integer_to_roman\">https://bgoonz-blog.netlify.app/docs/leetcode/012._integer_to_roman</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/013._roman_to_integer\">https://bgoonz-blog.netlify.app/docs/leetcode/013._roman_to_integer</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/014._longest_common_prefix\">https://bgoonz-blog.netlify.app/docs/leetcode/014._longest_common_prefix</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/017._letter_combinations_of_a_phone_number\">https://bgoonz-blog.netlify.app/docs/leetcode/017._letter_combinations_of_a_phone_number</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/019._remove_nth_node_from_end_of_list\">https://bgoonz-blog.netlify.app/docs/leetcode/019._remove_nth_node_from_end_of_list</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/020._valid_parentheses\">https://bgoonz-blog.netlify.app/docs/leetcode/020._valid_parentheses</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/022._generate_parentheses\">https://bgoonz-blog.netlify.app/docs/leetcode/022._generate_parentheses</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/026._remove_duplicates_from_sorted_array\">https://bgoonz-blog.netlify.app/docs/leetcode/026._remove_duplicates_from_sorted_array</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/029._divide_two_integers\">https://bgoonz-blog.netlify.app/docs/leetcode/029._divide_two_integers</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/031._next_permutation\">https://bgoonz-blog.netlify.app/docs/leetcode/031._next_permutation</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/033._search_in_rotated_sorted_array\">https://bgoonz-blog.netlify.app/docs/leetcode/033._search_in_rotated_sorted_array</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/containewitmoswater\">https://bgoonz-blog.netlify.app/docs/leetcode/containewitmoswater</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/dividtwintegers\">https://bgoonz-blog.netlify.app/docs/leetcode/dividtwintegers</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/first-100\">https://bgoonz-blog.netlify.app/docs/leetcode/first-100</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/generatparentheses\">https://bgoonz-blog.netlify.app/docs/leetcode/generatparentheses</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/lettecombinationophonnumber\">https://bgoonz-blog.netlify.app/docs/leetcode/lettecombinationophonnumber</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/longescommoprefix\">https://bgoonz-blog.netlify.app/docs/leetcode/longescommoprefix</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/mediaotwsortearrays\">https://bgoonz-blog.netlify.app/docs/leetcode/mediaotwsortearrays</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/nexpermutation\">https://bgoonz-blog.netlify.app/docs/leetcode/nexpermutation</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/palindromnumber\">https://bgoonz-blog.netlify.app/docs/leetcode/palindromnumber</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/regulaexpressiomatching\">https://bgoonz-blog.netlify.app/docs/leetcode/regulaexpressiomatching</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/removduplicatefrosortearray\">https://bgoonz-blog.netlify.app/docs/leetcode/removduplicatefrosortearray</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/removntnodfroenolist\">https://bgoonz-blog.netlify.app/docs/leetcode/removntnodfroenolist</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/romatinteger\">https://bgoonz-blog.netlify.app/docs/leetcode/romatinteger</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/searcirotatesortearray\">https://bgoonz-blog.netlify.app/docs/leetcode/searcirotatesortearray</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/valiparentheses\">https://bgoonz-blog.netlify.app/docs/leetcode/valiparentheses</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/leetcode/zigzaconversion\">https://bgoonz-blog.netlify.app/docs/leetcode/zigzaconversion</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/netlify-cms\">https://bgoonz-blog.netlify.app/docs/netlify-cms</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/netlify-cms-jamstack\">https://bgoonz-blog.netlify.app/docs/netlify-cms-jamstack</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/netlify-cms-jamstack/get-started-with-gatsby\">https://bgoonz-blog.netlify.app/docs/netlify-cms-jamstack/get-started-with-gatsby</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/netlify-cms-jamstack/jamstack-templates\">https://bgoonz-blog.netlify.app/docs/netlify-cms-jamstack/jamstack-templates</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/netlify-cms-jamstack/serverlessjs\">https://bgoonz-blog.netlify.app/docs/netlify-cms-jamstack/serverlessjs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/netlify-cms/jamstack-templates\">https://bgoonz-blog.netlify.app/docs/netlify-cms/jamstack-templates</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow\">https://bgoonz-blog.netlify.app/docs/overflow</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/html-spec\">https://bgoonz-blog.netlify.app/docs/overflow/html-spec</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/http\">https://bgoonz-blog.netlify.app/docs/overflow/http</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/install\">https://bgoonz-blog.netlify.app/docs/overflow/install</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/modules\">https://bgoonz-blog.netlify.app/docs/overflow/modules</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-cli-args\">https://bgoonz-blog.netlify.app/docs/overflow/node-cli-args</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-js-language\">https://bgoonz-blog.netlify.app/docs/overflow/node-js-language</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-package-manager\">https://bgoonz-blog.netlify.app/docs/overflow/node-package-manager</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-repl\">https://bgoonz-blog.netlify.app/docs/overflow/node-repl</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/node-run-cli\">https://bgoonz-blog.netlify.app/docs/overflow/node-run-cli</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/nodejs\">https://bgoonz-blog.netlify.app/docs/overflow/nodejs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/nodevsbrowser\">https://bgoonz-blog.netlify.app/docs/overflow/nodevsbrowser</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/understanding-firebase\">https://bgoonz-blog.netlify.app/docs/overflow/understanding-firebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/overflow/v8\">https://bgoonz-blog.netlify.app/docs/overflow/v8</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/privacy-policy\">https://bgoonz-blog.netlify.app/docs/privacy-policy</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects\">https://bgoonz-blog.netlify.app/docs/projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/archive\">https://bgoonz-blog.netlify.app/docs/projects/archive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/archive/embeded-websites\">https://bgoonz-blog.netlify.app/docs/projects/archive/embeded-websites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/embeded-websites\">https://bgoonz-blog.netlify.app/docs/projects/embeded-websites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/list-of-projects\">https://bgoonz-blog.netlify.app/docs/projects/list-of-projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/main-projects\">https://bgoonz-blog.netlify.app/docs/projects/main-projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects\">https://bgoonz-blog.netlify.app/docs/projects/mini-projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/mini-projects2\">https://bgoonz-blog.netlify.app/docs/projects/mini-projects2</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/my-websites\">https://bgoonz-blog.netlify.app/docs/projects/my-websites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/projects/recent\">https://bgoonz-blog.netlify.app/docs/projects/recent</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python\">https://bgoonz-blog.netlify.app/docs/python</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/at-length\">https://bgoonz-blog.netlify.app/docs/python/at-length</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/cheat-sheet\">https://bgoonz-blog.netlify.app/docs/python/cheat-sheet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/comprehensive-guide\">https://bgoonz-blog.netlify.app/docs/python/comprehensive-guide</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/examples\">https://bgoonz-blog.netlify.app/docs/python/examples</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/flow-control\">https://bgoonz-blog.netlify.app/docs/python/flow-control</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/functions\">https://bgoonz-blog.netlify.app/docs/python/functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/google-sheets-api\">https://bgoonz-blog.netlify.app/docs/python/google-sheets-api</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/install-python-ubuntu\">https://bgoonz-blog.netlify.app/docs/python/install-python-ubuntu</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/intro-for-js-devs\">https://bgoonz-blog.netlify.app/docs/python/intro-for-js-devs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-ds\">https://bgoonz-blog.netlify.app/docs/python/python-ds</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/python-quiz\">https://bgoonz-blog.netlify.app/docs/python/python-quiz</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/python/snippets\">https://bgoonz-blog.netlify.app/docs/python/snippets</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref\">https://bgoonz-blog.netlify.app/docs/quick-ref</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/all-emojis\">https://bgoonz-blog.netlify.app/docs/quick-ref/all-emojis</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/create-react-app\">https://bgoonz-blog.netlify.app/docs/quick-ref/create-react-app</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/emmet\">https://bgoonz-blog.netlify.app/docs/quick-ref/emmet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/fetch\">https://bgoonz-blog.netlify.app/docs/quick-ref/fetch</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-bash\">https://bgoonz-blog.netlify.app/docs/quick-ref/git-bash</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/git-tricks\">https://bgoonz-blog.netlify.app/docs/quick-ref/git-tricks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/google-firebase\">https://bgoonz-blog.netlify.app/docs/quick-ref/google-firebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/heroku-error-codes\">https://bgoonz-blog.netlify.app/docs/quick-ref/heroku-error-codes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/installation\">https://bgoonz-blog.netlify.app/docs/quick-ref/installation</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/markdown-dropdowns\">https://bgoonz-blog.netlify.app/docs/quick-ref/markdown-dropdowns</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/minifiction\">https://bgoonz-blog.netlify.app/docs/quick-ref/minifiction</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/new-repo-instructions\">https://bgoonz-blog.netlify.app/docs/quick-ref/new-repo-instructions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/psql-setup\">https://bgoonz-blog.netlify.app/docs/quick-ref/psql-setup</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/pull-request-rubric\">https://bgoonz-blog.netlify.app/docs/quick-ref/pull-request-rubric</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/quick-links\">https://bgoonz-blog.netlify.app/docs/quick-ref/quick-links</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/toprepos\">https://bgoonz-blog.netlify.app/docs/quick-ref/toprepos</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/understanding-path\">https://bgoonz-blog.netlify.app/docs/quick-ref/understanding-path</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-ref/vscode-themes\">https://bgoonz-blog.netlify.app/docs/quick-ref/vscode-themes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference\">https://bgoonz-blog.netlify.app/docs/quick-reference</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/all-emojis\">https://bgoonz-blog.netlify.app/docs/quick-reference/all-emojis</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/create-react-app\">https://bgoonz-blog.netlify.app/docs/quick-reference/create-react-app</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/emmet\">https://bgoonz-blog.netlify.app/docs/quick-reference/emmet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/git-bash\">https://bgoonz-blog.netlify.app/docs/quick-reference/git-bash</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/git-tricks\">https://bgoonz-blog.netlify.app/docs/quick-reference/git-tricks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/google-firebase\">https://bgoonz-blog.netlify.app/docs/quick-reference/google-firebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/heroku-error-codes\">https://bgoonz-blog.netlify.app/docs/quick-reference/heroku-error-codes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/installation\">https://bgoonz-blog.netlify.app/docs/quick-reference/installation</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/markdown-dropdowns\">https://bgoonz-blog.netlify.app/docs/quick-reference/markdown-dropdowns</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/minifiction\">https://bgoonz-blog.netlify.app/docs/quick-reference/minifiction</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/new-repo-instructions\">https://bgoonz-blog.netlify.app/docs/quick-reference/new-repo-instructions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/psql-setup\">https://bgoonz-blog.netlify.app/docs/quick-reference/psql-setup</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/pull-request-rubric\">https://bgoonz-blog.netlify.app/docs/quick-reference/pull-request-rubric</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/quick-links\">https://bgoonz-blog.netlify.app/docs/quick-reference/quick-links</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/toprepos\">https://bgoonz-blog.netlify.app/docs/quick-reference/toprepos</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/understanding-path\">https://bgoonz-blog.netlify.app/docs/quick-reference/understanding-path</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/vscode-themes\">https://bgoonz-blog.netlify.app/docs/quick-reference/vscode-themes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react\">https://bgoonz-blog.netlify.app/docs/react</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/accessibility\">https://bgoonz-blog.netlify.app/docs/react/accessibility</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/ajax-n-apis\">https://bgoonz-blog.netlify.app/docs/react/ajax-n-apis</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/cheatsheet\">https://bgoonz-blog.netlify.app/docs/react/cheatsheet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/complete-react\">https://bgoonz-blog.netlify.app/docs/react/complete-react</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/createreactapp\">https://bgoonz-blog.netlify.app/docs/react/createreactapp</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/demo\">https://bgoonz-blog.netlify.app/docs/react/demo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/dont-use-index-as-keys\">https://bgoonz-blog.netlify.app/docs/react/dont-use-index-as-keys</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/jsx\">https://bgoonz-blog.netlify.app/docs/react/jsx</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/quiz\">https://bgoonz-blog.netlify.app/docs/react/quiz</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-docs\">https://bgoonz-blog.netlify.app/docs/react/react-docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-in-depth\">https://bgoonz-blog.netlify.app/docs/react/react-in-depth</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-patterns-by-usecase\">https://bgoonz-blog.netlify.app/docs/react/react-patterns-by-usecase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/react-w-api\">https://bgoonz-blog.netlify.app/docs/react/react-w-api</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2\">https://bgoonz-blog.netlify.app/docs/react/react2</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/react/render-elements\">https://bgoonz-blog.netlify.app/docs/react/render-elements</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference\">https://bgoonz-blog.netlify.app/docs/reference</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/art-of-command-line\">https://bgoonz-blog.netlify.app/docs/reference/art-of-command-line</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-lists\">https://bgoonz-blog.netlify.app/docs/reference/awesome-lists</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-nodejs\">https://bgoonz-blog.netlify.app/docs/reference/awesome-nodejs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/awesome-static\">https://bgoonz-blog.netlify.app/docs/reference/awesome-static</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bash-commands\">https://bgoonz-blog.netlify.app/docs/reference/bash-commands</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/bookmarks\">https://bgoonz-blog.netlify.app/docs/reference/bookmarks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/embed-the-web\">https://bgoonz-blog.netlify.app/docs/reference/embed-the-web</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-resources\">https://bgoonz-blog.netlify.app/docs/reference/github-resources</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/github-search\">https://bgoonz-blog.netlify.app/docs/reference/github-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/google-cloud\">https://bgoonz-blog.netlify.app/docs/reference/google-cloud</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-2-reinstall-npm\">https://bgoonz-blog.netlify.app/docs/reference/how-2-reinstall-npm</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/how-to-kill-a-process\">https://bgoonz-blog.netlify.app/docs/reference/how-to-kill-a-process</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/installing-node\">https://bgoonz-blog.netlify.app/docs/reference/installing-node</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/intro-to-nodejs\">https://bgoonz-blog.netlify.app/docs/reference/intro-to-nodejs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/markdown-styleguide\">https://bgoonz-blog.netlify.app/docs/reference/markdown-styleguide</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/notes-template\">https://bgoonz-blog.netlify.app/docs/reference/notes-template</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/psql\">https://bgoonz-blog.netlify.app/docs/reference/psql</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/resources\">https://bgoonz-blog.netlify.app/docs/reference/resources</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/vscode\">https://bgoonz-blog.netlify.app/docs/reference/vscode</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/web-api%27s\">https://bgoonz-blog.netlify.app/docs/reference/web-api%27s</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/reference/web-api\">https://bgoonz-blog.netlify.app/docs/reference/web-api</a>'s</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/search\">https://bgoonz-blog.netlify.app/docs/search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/sitemap\">https://bgoonz-blog.netlify.app/docs/sitemap</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/sitemap-april\">https://bgoonz-blog.netlify.app/docs/sitemap-april</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tips\">https://bgoonz-blog.netlify.app/docs/tips</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tips/7-tips-to-become-a-better-web-developer\">https://bgoonz-blog.netlify.app/docs/tips/7-tips-to-become-a-better-web-developer</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tips/array-methods\">https://bgoonz-blog.netlify.app/docs/tips/array-methods</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tips/insert-into-array\">https://bgoonz-blog.netlify.app/docs/tips/insert-into-array</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tips/regex-tips\">https://bgoonz-blog.netlify.app/docs/tips/regex-tips</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tips/sorting-strings\">https://bgoonz-blog.netlify.app/docs/tips/sorting-strings</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tips/storybook\">https://bgoonz-blog.netlify.app/docs/tips/storybook</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools\">https://bgoonz-blog.netlify.app/docs/tools</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools/\">https://bgoonz-blog.netlify.app/docs/tools/</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools/all\">https://bgoonz-blog.netlify.app/docs/tools/all</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools/all-stripped\">https://bgoonz-blog.netlify.app/docs/tools/all-stripped</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools/archive\">https://bgoonz-blog.netlify.app/docs/tools/archive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools/data-structures\">https://bgoonz-blog.netlify.app/docs/tools/data-structures</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools/dev-utilities\">https://bgoonz-blog.netlify.app/docs/tools/dev-utilities</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools/embeds-archive\">https://bgoonz-blog.netlify.app/docs/tools/embeds-archive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tools/markdown-html\">https://bgoonz-blog.netlify.app/docs/tools/markdown-html</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials\">https://bgoonz-blog.netlify.app/docs/tutorials</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/algolia-search\">https://bgoonz-blog.netlify.app/docs/tutorials/algolia-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/bash\">https://bgoonz-blog.netlify.app/docs/tutorials/bash</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/bash-commands-my\">https://bgoonz-blog.netlify.app/docs/tutorials/bash-commands-my</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/effect-hook\">https://bgoonz-blog.netlify.app/docs/tutorials/effect-hook</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/enviorment-setup\">https://bgoonz-blog.netlify.app/docs/tutorials/enviorment-setup</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/get-file-extension\">https://bgoonz-blog.netlify.app/docs/tutorials/get-file-extension</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/how-2-ubuntu\">https://bgoonz-blog.netlify.app/docs/tutorials/how-2-ubuntu</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/how-to-use-google-sheets-as-cms\">https://bgoonz-blog.netlify.app/docs/tutorials/how-to-use-google-sheets-as-cms</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/psql-setup\">https://bgoonz-blog.netlify.app/docs/tutorials/psql-setup</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/docs/tutorials/react-class-2-func\">https://bgoonz-blog.netlify.app/docs/tutorials/react-class-2-func</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/images/cool%20annimation.gif\">https://bgoonz-blog.netlify.app/images/cool%20annimation.gif</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/images/cool%20annimation.gif\">https://bgoonz-blog.netlify.app/images/cool%20annimation.gif</a>\"<a href=\"https://bgoonz-blog.netlify\">https://bgoonz-blog.netlify</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/interview-questions-js\">https://bgoonz-blog.netlify.app/interview-questions-js</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/privacy-policy\">https://bgoonz-blog.netlify.app/privacy-policy</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/readme\">https://bgoonz-blog.netlify.app/readme</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/readme/?!%5d%3e/link\">https://bgoonz-blog.netlify.app/readme/?!%5d%3e/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/readme/?:%5b%5cda-fa-f%5d(?:_%5b%5cda-fa-f%5d)/link\">https://bgoonz-blog.netlify.app/readme/?:%5b%5cda-fa-f%5d(?:_%5b%5cda-fa-f%5d)/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/readme/?:%5b%5e%7b%7d;%22%27%5d%7c%27%20+%20t.source%20+/link\">https://bgoonz-blog.netlify.app/readme/?:%5b%5e%7b%7d;%22%27%5d%7c%27%20+%20t.source%20+/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/readme/?:%5b0-7%5d(?:_%5b0-7%5d)/link\">https://bgoonz-blog.netlify.app/readme/?:%5b0-7%5d(?:_%5b0-7%5d)/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/readme/?:%5b01%5d(?:_%5b01%5d)/link\">https://bgoonz-blog.netlify.app/readme/?:%5b01%5d(?:_%5b01%5d)/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/readme/?:%5ba-z_%5d%7c%5cdx/link\">https://bgoonz-blog.netlify.app/readme/?:%5ba-z_%5d%7c%5cdx/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/readme/?:(?!%5cs)%5b$%5cw%5cxa0-%5cuffff%5d/link\">https://bgoonz-blog.netlify.app/readme/?:(?!%5cs)%5b$%5cw%5cxa0-%5cuffff%5d/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/_static/app-assets/lambda-demo1.gif\">https://bgoonz-blog.netlify.app/_static/app-assets/lambda-demo1.gif</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/_static/app-assets/lambda-demo1.gif\">https://bgoonz-blog.netlify.app/_static/app-assets/lambda-demo1.gif</a>\"<a href=\"https://bgoonz-blog.netlify\">https://bgoonz-blog.netlify</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/_static/app-assets/neural.png\">https://bgoonz-blog.netlify.app/_static/app-assets/neural.png</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz-blog.netlify.app/_static/app-assets/neural.png\">https://bgoonz-blog.netlify.app/_static/app-assets/neural.png</a>\"<a href=\"https://bgoonz-blog.netlify\">https://bgoonz-blog.netlify</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.blogspot.com/2021/01/easy-count-length-of-cycle-election.html/link\">https://bgoonz.blogspot.com/2021/01/easy-count-length-of-cycle-election.html/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.blogspot.com/2021/01/easy-count-length-of-cycle-election.html/title\">https://bgoonz.blogspot.com/2021/01/easy-count-length-of-cycle-election.html/title</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.blogspot.com/2021/07/data-persistence-sql-express.html/link\">https://bgoonz.blogspot.com/2021/07/data-persistence-sql-express.html/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.blogspot.com/2021/07/data-persistence-sql-express.html/title\">https://bgoonz.blogspot.com/2021/07/data-persistence-sql-express.html/title</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.blogspot.com/2021/07/fetch-json-data-in-react-app.html/link\">https://bgoonz.blogspot.com/2021/07/fetch-json-data-in-react-app.html/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.blogspot.com/2021/07/fetch-json-data-in-react-app.html/title\">https://bgoonz.blogspot.com/2021/07/fetch-json-data-in-react-app.html/title</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.blogspot.com/2021/07/react-tricks.html/link\">https://bgoonz.blogspot.com/2021/07/react-tricks.html/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.blogspot.com/2021/07/react-tricks.html/title\">https://bgoonz.blogspot.com/2021/07/react-tricks.html/title</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/bgoonz_blog_2.0/\">https://bgoonz.github.io/bgoonz_blog_2.0/</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/bgoonz_blog_2.0/\">https://bgoonz.github.io/bgoonz_blog_2.0/</a>\"github</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/projects/\">https://bgoonz.github.io/projects/</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/projects/\">https://bgoonz.github.io/projects/</a>\"<a href=\"https://bgoonz.github.io/pr\">https://bgoonz.github.io/pr</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/useful-snippets/\">https://bgoonz.github.io/useful-snippets/</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/useful-snippets/\">https://bgoonz.github.io/useful-snippets/</a>\"<a href=\"https://bgoonz.github.io/us\">https://bgoonz.github.io/us</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/useful-snippets/\">https://bgoonz.github.io/useful-snippets/</a>\"snippets</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/vanilla-mini-projects/\">https://bgoonz.github.io/vanilla-mini-projects/</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/vanilla-mini-projects/\">https://bgoonz.github.io/vanilla-mini-projects/</a>\"<a href=\"https://bgoonz.github.io/va\">https://bgoonz.github.io/va</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/vanilla-utils/\">https://bgoonz.github.io/vanilla-utils/</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.github.io/vanilla-utils/\">https://bgoonz.github.io/vanilla-utils/</a>\"<a href=\"https://bgoonz.github.io/va\">https://bgoonz.github.io/va</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.hashnode.dev/data-structures\">https://bgoonz.hashnode.dev/data-structures</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonz.hashnode.dev/data-structures\">https://bgoonz.hashnode.dev/data-structures</a>\"<a href=\"https://bgoonz.hashnode.dev\">https://bgoonz.hashnode.dev</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20-redo.netlify.app/\">https://bgoonzblog20-redo.netlify.app/</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20-redo.netlify.app/\">https://bgoonzblog20-redo.netlify.app/</a>\"<a href=\"https://bgoonzblog20-redo.n\">https://bgoonzblog20-redo.n</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gatsbyjs.io\">https://bgoonzblog20master.gatsbyjs.io</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/300-react-questions\">https://bgoonzblog20master.gtsb.io/blog/300-react-questions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/adding-css-to-your-html\">https://bgoonzblog20master.gtsb.io/blog/adding-css-to-your-html</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/awesome-graphql\">https://bgoonzblog20master.gtsb.io/blog/awesome-graphql</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/data-structures-algorithms-resources\">https://bgoonzblog20master.gtsb.io/blog/data-structures-algorithms-resources</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/flow-control-in-python\">https://bgoonzblog20master.gtsb.io/blog/flow-control-in-python</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/functions-in-python\">https://bgoonzblog20master.gtsb.io/blog/functions-in-python</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/platform-docs\">https://bgoonzblog20master.gtsb.io/blog/platform-docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/web-dev-trends\">https://bgoonzblog20master.gtsb.io/blog/web-dev-trends</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/blog/web-scraping\">https://bgoonzblog20master.gtsb.io/blog/web-scraping</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs\">https://bgoonzblog20master.gtsb.io/docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/about\">https://bgoonzblog20master.gtsb.io/docs/about</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/about/eng-portfolio\">https://bgoonzblog20master.gtsb.io/docs/about/eng-portfolio</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/about/job-search\">https://bgoonzblog20master.gtsb.io/docs/about/job-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/about/readme\">https://bgoonzblog20master.gtsb.io/docs/about/readme</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/about/resume\">https://bgoonzblog20master.gtsb.io/docs/about/resume</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/about/youtube\">https://bgoonzblog20master.gtsb.io/docs/about/youtube</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/archive/link\">https://bgoonzblog20master.gtsb.io/docs/archive/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles\">https://bgoonzblog20master.gtsb.io/docs/articles</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/basic-web-dev\">https://bgoonzblog20master.gtsb.io/docs/articles/basic-web-dev</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/buffers\">https://bgoonzblog20master.gtsb.io/docs/articles/buffers</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/common-modules\">https://bgoonzblog20master.gtsb.io/docs/articles/common-modules</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/dev-dep\">https://bgoonzblog20master.gtsb.io/docs/articles/dev-dep</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/event-loop\">https://bgoonzblog20master.gtsb.io/docs/articles/event-loop</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/how-search-engines-work\">https://bgoonzblog20master.gtsb.io/docs/articles/how-search-engines-work</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/how-the-web-works\">https://bgoonzblog20master.gtsb.io/docs/articles/how-the-web-works</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/http\">https://bgoonzblog20master.gtsb.io/docs/articles/http</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/install\">https://bgoonzblog20master.gtsb.io/docs/articles/install</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/intro\">https://bgoonzblog20master.gtsb.io/docs/articles/intro</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/jamstack\">https://bgoonzblog20master.gtsb.io/docs/articles/jamstack</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/nextjs\">https://bgoonzblog20master.gtsb.io/docs/articles/nextjs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/node-cli-args\">https://bgoonzblog20master.gtsb.io/docs/articles/node-cli-args</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/node-env-variables\">https://bgoonzblog20master.gtsb.io/docs/articles/node-env-variables</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/node-js-language\">https://bgoonzblog20master.gtsb.io/docs/articles/node-js-language</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/node-package-manager\">https://bgoonzblog20master.gtsb.io/docs/articles/node-package-manager</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/node-repl\">https://bgoonzblog20master.gtsb.io/docs/articles/node-repl</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/nodejs\">https://bgoonzblog20master.gtsb.io/docs/articles/nodejs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/npm\">https://bgoonzblog20master.gtsb.io/docs/articles/npm</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/os-module\">https://bgoonzblog20master.gtsb.io/docs/articles/os-module</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/reading-files\">https://bgoonzblog20master.gtsb.io/docs/articles/reading-files</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/semantic\">https://bgoonzblog20master.gtsb.io/docs/articles/semantic</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/semantic-html\">https://bgoonzblog20master.gtsb.io/docs/articles/semantic-html</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/the-uniform-resource-locator-(url\">https://bgoonzblog20master.gtsb.io/docs/articles/the-uniform-resource-locator-(url</a>)</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/understanding-firebase\">https://bgoonzblog20master.gtsb.io/docs/articles/understanding-firebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/url\">https://bgoonzblog20master.gtsb.io/docs/articles/url</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/v8\">https://bgoonzblog20master.gtsb.io/docs/articles/v8</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/web-standards-checklist\">https://bgoonzblog20master.gtsb.io/docs/articles/web-standards-checklist</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/webdev-tools\">https://bgoonzblog20master.gtsb.io/docs/articles/webdev-tools</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/articles/writing-files\">https://bgoonzblog20master.gtsb.io/docs/articles/writing-files</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/audio\">https://bgoonzblog20master.gtsb.io/docs/audio</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/audio/audio\">https://bgoonzblog20master.gtsb.io/docs/audio/audio</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/audio/audio-feature-extraction\">https://bgoonzblog20master.gtsb.io/docs/audio/audio-feature-extraction</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/audio/dfft\">https://bgoonzblog20master.gtsb.io/docs/audio/dfft</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/audio/discrete-fft\">https://bgoonzblog20master.gtsb.io/docs/audio/discrete-fft</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/audio/dtw-python-explained\">https://bgoonzblog20master.gtsb.io/docs/audio/dtw-python-explained</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/audio/dynamic-time-warping\">https://bgoonzblog20master.gtsb.io/docs/audio/dynamic-time-warping</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/audio/web-audio-api\">https://bgoonzblog20master.gtsb.io/docs/audio/web-audio-api</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career\">https://bgoonzblog20master.gtsb.io/docs/career</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career/dev-interview\">https://bgoonzblog20master.gtsb.io/docs/career/dev-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career/interview-dos-n-donts\">https://bgoonzblog20master.gtsb.io/docs/career/interview-dos-n-donts</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career/job-boards\">https://bgoonzblog20master.gtsb.io/docs/career/job-boards</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career/job-search\">https://bgoonzblog20master.gtsb.io/docs/career/job-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career/js-interview\">https://bgoonzblog20master.gtsb.io/docs/career/js-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career/list-of-projects\">https://bgoonzblog20master.gtsb.io/docs/career/list-of-projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career/my-websites\">https://bgoonzblog20master.gtsb.io/docs/career/my-websites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/career/web-interview\">https://bgoonzblog20master.gtsb.io/docs/career/web-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/community\">https://bgoonzblog20master.gtsb.io/docs/community</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/community/an-open-letter-2-future-developers\">https://bgoonzblog20master.gtsb.io/docs/community/an-open-letter-2-future-developers</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/community/bookmarks\">https://bgoonzblog20master.gtsb.io/docs/community/bookmarks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/community/video-chat\">https://bgoonzblog20master.gtsb.io/docs/community/video-chat</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content\">https://bgoonzblog20master.gtsb.io/docs/content</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content/algo\">https://bgoonzblog20master.gtsb.io/docs/content/algo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content/archive\">https://bgoonzblog20master.gtsb.io/docs/content/archive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content/data-structures-in-python\">https://bgoonzblog20master.gtsb.io/docs/content/data-structures-in-python</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content/gatsby-queries-mutations\">https://bgoonzblog20master.gtsb.io/docs/content/gatsby-queries-mutations</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content/gists\">https://bgoonzblog20master.gtsb.io/docs/content/gists</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content/history-api\">https://bgoonzblog20master.gtsb.io/docs/content/history-api</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content/main-projects\">https://bgoonzblog20master.gtsb.io/docs/content/main-projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/content/trouble-shooting\">https://bgoonzblog20master.gtsb.io/docs/content/trouble-shooting</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/css\">https://bgoonzblog20master.gtsb.io/docs/css</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/data-structures\">https://bgoonzblog20master.gtsb.io/docs/data-structures</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/data-structures/ds-algo-interview\">https://bgoonzblog20master.gtsb.io/docs/data-structures/ds-algo-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs\">https://bgoonzblog20master.gtsb.io/docs/docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/appendix\">https://bgoonzblog20master.gtsb.io/docs/docs/appendix</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/bash\">https://bgoonzblog20master.gtsb.io/docs/docs/bash</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/css\">https://bgoonzblog20master.gtsb.io/docs/docs/css</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/data-structures-docs\">https://bgoonzblog20master.gtsb.io/docs/docs/data-structures-docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/es-6-features\">https://bgoonzblog20master.gtsb.io/docs/docs/es-6-features</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/git-reference\">https://bgoonzblog20master.gtsb.io/docs/docs/git-reference</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/git-repos\">https://bgoonzblog20master.gtsb.io/docs/docs/git-repos</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/glossary\">https://bgoonzblog20master.gtsb.io/docs/docs/glossary</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/html-spec\">https://bgoonzblog20master.gtsb.io/docs/docs/html-spec</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/html-tags\">https://bgoonzblog20master.gtsb.io/docs/docs/html-tags</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/no-whiteboarding\">https://bgoonzblog20master.gtsb.io/docs/docs/no-whiteboarding</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/node-docs-complete\">https://bgoonzblog20master.gtsb.io/docs/docs/node-docs-complete</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/node-docs-full\">https://bgoonzblog20master.gtsb.io/docs/docs/node-docs-full</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/docs/sitemap\">https://bgoonzblog20master.gtsb.io/docs/docs/sitemap</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo\">https://bgoonzblog20master.gtsb.io/docs/ds-algo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/big-o\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/big-o</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/data-structures-docs\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/data-structures-docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/ds-algo-interview\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/ds-algo-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/ds-by-example\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/ds-by-example</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/ds-overview\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/ds-overview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/free-code-camp\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/free-code-camp</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/graph\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/graph</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/heaps\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/heaps</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/ds-algo/tree\">https://bgoonzblog20master.gtsb.io/docs/ds-algo/tree</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/faq\">https://bgoonzblog20master.gtsb.io/docs/faq</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/faq/contact\">https://bgoonzblog20master.gtsb.io/docs/faq/contact</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/faq/plug-ins\">https://bgoonzblog20master.gtsb.io/docs/faq/plug-ins</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/git/git-cheatsheet\">https://bgoonzblog20master.gtsb.io/docs/git/git-cheatsheet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/git/github-tutorial\">https://bgoonzblog20master.gtsb.io/docs/git/github-tutorial</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/glossary/mathfloor\">https://bgoonzblog20master.gtsb.io/docs/glossary/mathfloor</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interact\">https://bgoonzblog20master.gtsb.io/docs/interact</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interact/callstack-visual\">https://bgoonzblog20master.gtsb.io/docs/interact/callstack-visual</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interact/clock\">https://bgoonzblog20master.gtsb.io/docs/interact/clock</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interact/jupyter-notebooks\">https://bgoonzblog20master.gtsb.io/docs/interact/jupyter-notebooks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interact/other-sites\">https://bgoonzblog20master.gtsb.io/docs/interact/other-sites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interact/video-chat\">https://bgoonzblog20master.gtsb.io/docs/interact/video-chat</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interview\">https://bgoonzblog20master.gtsb.io/docs/interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interview/dos-and-donts\">https://bgoonzblog20master.gtsb.io/docs/interview/dos-and-donts</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interview/job-search-nav\">https://bgoonzblog20master.gtsb.io/docs/interview/job-search-nav</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interview/review-concepts\">https://bgoonzblog20master.gtsb.io/docs/interview/review-concepts</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/interview/web-interview\">https://bgoonzblog20master.gtsb.io/docs/interview/web-interview</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript\">https://bgoonzblog20master.gtsb.io/docs/javascript</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/arrow-functions\">https://bgoonzblog20master.gtsb.io/docs/javascript/arrow-functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/asyncjs\">https://bgoonzblog20master.gtsb.io/docs/javascript/asyncjs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/await-keyword\">https://bgoonzblog20master.gtsb.io/docs/javascript/await-keyword</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/bigo\">https://bgoonzblog20master.gtsb.io/docs/javascript/bigo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/clean-code\">https://bgoonzblog20master.gtsb.io/docs/javascript/clean-code</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/constructor-functions\">https://bgoonzblog20master.gtsb.io/docs/javascript/constructor-functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/cs-basics-in-js\">https://bgoonzblog20master.gtsb.io/docs/javascript/cs-basics-in-js</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/for-loops\">https://bgoonzblog20master.gtsb.io/docs/javascript/for-loops</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/js-objects\">https://bgoonzblog20master.gtsb.io/docs/javascript/js-objects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/javascript/review\">https://bgoonzblog20master.gtsb.io/docs/javascript/review</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips\">https://bgoonzblog20master.gtsb.io/docs/js-tips</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/abs\">https://bgoonzblog20master.gtsb.io/docs/js-tips/abs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/acos\">https://bgoonzblog20master.gtsb.io/docs/js-tips/acos</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/acosh\">https://bgoonzblog20master.gtsb.io/docs/js-tips/acosh</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/addition\">https://bgoonzblog20master.gtsb.io/docs/js-tips/addition</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/all\">https://bgoonzblog20master.gtsb.io/docs/js-tips/all</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/allsettled\">https://bgoonzblog20master.gtsb.io/docs/js-tips/allsettled</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/any\">https://bgoonzblog20master.gtsb.io/docs/js-tips/any</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/array-methods\">https://bgoonzblog20master.gtsb.io/docs/js-tips/array-methods</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/arrow_functions\">https://bgoonzblog20master.gtsb.io/docs/js-tips/arrow_functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/async_function\">https://bgoonzblog20master.gtsb.io/docs/js-tips/async_function</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/bad_radix\">https://bgoonzblog20master.gtsb.io/docs/js-tips/bad_radix</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/bind\">https://bgoonzblog20master.gtsb.io/docs/js-tips/bind</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/classes\">https://bgoonzblog20master.gtsb.io/docs/js-tips/classes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/concat\">https://bgoonzblog20master.gtsb.io/docs/js-tips/concat</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/conditional_operator\">https://bgoonzblog20master.gtsb.io/docs/js-tips/conditional_operator</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/const\">https://bgoonzblog20master.gtsb.io/docs/js-tips/const</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/create\">https://bgoonzblog20master.gtsb.io/docs/js-tips/create</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/date\">https://bgoonzblog20master.gtsb.io/docs/js-tips/date</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/filter\">https://bgoonzblog20master.gtsb.io/docs/js-tips/filter</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/import\">https://bgoonzblog20master.gtsb.io/docs/js-tips/import</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/insert-into-array\">https://bgoonzblog20master.gtsb.io/docs/js-tips/insert-into-array</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/map\">https://bgoonzblog20master.gtsb.io/docs/js-tips/map</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/object\">https://bgoonzblog20master.gtsb.io/docs/js-tips/object</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/reduce\">https://bgoonzblog20master.gtsb.io/docs/js-tips/reduce</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/regexp\">https://bgoonzblog20master.gtsb.io/docs/js-tips/regexp</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/sort\">https://bgoonzblog20master.gtsb.io/docs/js-tips/sort</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/sorting-strings\">https://bgoonzblog20master.gtsb.io/docs/js-tips/sorting-strings</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/string\">https://bgoonzblog20master.gtsb.io/docs/js-tips/string</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/js-tips/var\">https://bgoonzblog20master.gtsb.io/docs/js-tips/var</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode\">https://bgoonzblog20master.gtsb.io/docs/leetcode</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/004._median_of_two_sorted_arrays\">https://bgoonzblog20master.gtsb.io/docs/leetcode/004._median_of_two_sorted_arrays</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/009._palindrome_number\">https://bgoonzblog20master.gtsb.io/docs/leetcode/009._palindrome_number</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/010._regular_expression_matching\">https://bgoonzblog20master.gtsb.io/docs/leetcode/010._regular_expression_matching</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/013._roman_to_integer\">https://bgoonzblog20master.gtsb.io/docs/leetcode/013._roman_to_integer</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/019._remove_nth_node_from_end_of_list\">https://bgoonzblog20master.gtsb.io/docs/leetcode/019._remove_nth_node_from_end_of_list</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/029._divide_two_integers\">https://bgoonzblog20master.gtsb.io/docs/leetcode/029._divide_two_integers</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/lettecombinationophonnumber\">https://bgoonzblog20master.gtsb.io/docs/leetcode/lettecombinationophonnumber</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/nexpermutation\">https://bgoonzblog20master.gtsb.io/docs/leetcode/nexpermutation</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/palindromnumber\">https://bgoonzblog20master.gtsb.io/docs/leetcode/palindromnumber</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/removduplicatefrosortearray\">https://bgoonzblog20master.gtsb.io/docs/leetcode/removduplicatefrosortearray</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/romatinteger\">https://bgoonzblog20master.gtsb.io/docs/leetcode/romatinteger</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/valiparentheses\">https://bgoonzblog20master.gtsb.io/docs/leetcode/valiparentheses</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/leetcode/zigzaconversion\">https://bgoonzblog20master.gtsb.io/docs/leetcode/zigzaconversion</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/netlify-cms\">https://bgoonzblog20master.gtsb.io/docs/netlify-cms</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/netlify-cms-jamstack\">https://bgoonzblog20master.gtsb.io/docs/netlify-cms-jamstack</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/netlify-cms-jamstack/get-started-with-gatsby\">https://bgoonzblog20master.gtsb.io/docs/netlify-cms-jamstack/get-started-with-gatsby</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/netlify-cms-jamstack/jamstack-templates\">https://bgoonzblog20master.gtsb.io/docs/netlify-cms-jamstack/jamstack-templates</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/netlify-cms-jamstack/serverlessjs\">https://bgoonzblog20master.gtsb.io/docs/netlify-cms-jamstack/serverlessjs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/netlify-cms/jamstack-templates\">https://bgoonzblog20master.gtsb.io/docs/netlify-cms/jamstack-templates</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow\">https://bgoonzblog20master.gtsb.io/docs/overflow</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/html-spec\">https://bgoonzblog20master.gtsb.io/docs/overflow/html-spec</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/http\">https://bgoonzblog20master.gtsb.io/docs/overflow/http</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/install\">https://bgoonzblog20master.gtsb.io/docs/overflow/install</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/modules\">https://bgoonzblog20master.gtsb.io/docs/overflow/modules</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/node-cli-args\">https://bgoonzblog20master.gtsb.io/docs/overflow/node-cli-args</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/node-js-language\">https://bgoonzblog20master.gtsb.io/docs/overflow/node-js-language</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/node-package-manager\">https://bgoonzblog20master.gtsb.io/docs/overflow/node-package-manager</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/node-repl\">https://bgoonzblog20master.gtsb.io/docs/overflow/node-repl</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/node-run-cli\">https://bgoonzblog20master.gtsb.io/docs/overflow/node-run-cli</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/nodevsbrowser\">https://bgoonzblog20master.gtsb.io/docs/overflow/nodevsbrowser</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/understanding-firebase\">https://bgoonzblog20master.gtsb.io/docs/overflow/understanding-firebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/overflow/v8\">https://bgoonzblog20master.gtsb.io/docs/overflow/v8</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/projects/archive/embeded-websites\">https://bgoonzblog20master.gtsb.io/docs/projects/archive/embeded-websites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/projects/embeded-websites\">https://bgoonzblog20master.gtsb.io/docs/projects/embeded-websites</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/projects/link\">https://bgoonzblog20master.gtsb.io/docs/projects/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/projects/list-of-projects\">https://bgoonzblog20master.gtsb.io/docs/projects/list-of-projects</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/projects/mini-projects2\">https://bgoonzblog20master.gtsb.io/docs/projects/mini-projects2</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/projects/recent\">https://bgoonzblog20master.gtsb.io/docs/projects/recent</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python\">https://bgoonzblog20master.gtsb.io/docs/python</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/at-length\">https://bgoonzblog20master.gtsb.io/docs/python/at-length</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/cheat-sheet\">https://bgoonzblog20master.gtsb.io/docs/python/cheat-sheet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/comprehensive-guide\">https://bgoonzblog20master.gtsb.io/docs/python/comprehensive-guide</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/examples\">https://bgoonzblog20master.gtsb.io/docs/python/examples</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/flow-control\">https://bgoonzblog20master.gtsb.io/docs/python/flow-control</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/functions\">https://bgoonzblog20master.gtsb.io/docs/python/functions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/google-sheets-api\">https://bgoonzblog20master.gtsb.io/docs/python/google-sheets-api</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/intro-for-js-devs\">https://bgoonzblog20master.gtsb.io/docs/python/intro-for-js-devs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/python-ds\">https://bgoonzblog20master.gtsb.io/docs/python/python-ds</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/python-quiz\">https://bgoonzblog20master.gtsb.io/docs/python/python-quiz</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/python/snippets\">https://bgoonzblog20master.gtsb.io/docs/python/snippets</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref\">https://bgoonzblog20master.gtsb.io/docs/quick-ref</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/create-react-app\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/create-react-app</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/fetch\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/fetch</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/git-bash\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/git-bash</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/git-tricks\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/git-tricks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/google-firebase\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/google-firebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/installation\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/installation</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/markdown-dropdowns\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/markdown-dropdowns</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/psql-setup\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/psql-setup</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/toprepos\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/toprepos</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-ref/vscode-themes\">https://bgoonzblog20master.gtsb.io/docs/quick-ref/vscode-themes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference\">https://bgoonzblog20master.gtsb.io/docs/quick-reference</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/emmet\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/emmet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/git-bash\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/git-bash</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/git-tricks\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/git-tricks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/google-firebase\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/google-firebase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/heroku-error-codes\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/heroku-error-codes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/installation\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/installation</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/new-repo-instructions\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/new-repo-instructions</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/pull-request-rubric\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/pull-request-rubric</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/quick-links\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/quick-links</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/toprepos\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/toprepos</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/understanding-path\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/understanding-path</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/quick-reference/vscode-themes\">https://bgoonzblog20master.gtsb.io/docs/quick-reference/vscode-themes</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react\">https://bgoonzblog20master.gtsb.io/docs/react</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/accessibility\">https://bgoonzblog20master.gtsb.io/docs/react/accessibility</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/cheatsheet\">https://bgoonzblog20master.gtsb.io/docs/react/cheatsheet</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/complete-react\">https://bgoonzblog20master.gtsb.io/docs/react/complete-react</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/createreactapp\">https://bgoonzblog20master.gtsb.io/docs/react/createreactapp</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/demo\">https://bgoonzblog20master.gtsb.io/docs/react/demo</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/dont-use-index-as-keys\">https://bgoonzblog20master.gtsb.io/docs/react/dont-use-index-as-keys</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/jsx\">https://bgoonzblog20master.gtsb.io/docs/react/jsx</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/react-docs\">https://bgoonzblog20master.gtsb.io/docs/react/react-docs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/react-in-depth\">https://bgoonzblog20master.gtsb.io/docs/react/react-in-depth</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/react-patterns-by-usecase\">https://bgoonzblog20master.gtsb.io/docs/react/react-patterns-by-usecase</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/react2\">https://bgoonzblog20master.gtsb.io/docs/react/react2</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/react/render-elements\">https://bgoonzblog20master.gtsb.io/docs/react/render-elements</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference\">https://bgoonzblog20master.gtsb.io/docs/reference</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/awesome-lists\">https://bgoonzblog20master.gtsb.io/docs/reference/awesome-lists</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/awesome-nodejs\">https://bgoonzblog20master.gtsb.io/docs/reference/awesome-nodejs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/awesome-static\">https://bgoonzblog20master.gtsb.io/docs/reference/awesome-static</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/bash-commands\">https://bgoonzblog20master.gtsb.io/docs/reference/bash-commands</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/bookmarks\">https://bgoonzblog20master.gtsb.io/docs/reference/bookmarks</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/embed-the-web\">https://bgoonzblog20master.gtsb.io/docs/reference/embed-the-web</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/github-resources\">https://bgoonzblog20master.gtsb.io/docs/reference/github-resources</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/github-search\">https://bgoonzblog20master.gtsb.io/docs/reference/github-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/google-cloud\">https://bgoonzblog20master.gtsb.io/docs/reference/google-cloud</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/how-2-reinstall-npm\">https://bgoonzblog20master.gtsb.io/docs/reference/how-2-reinstall-npm</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/how-to-kill-a-process\">https://bgoonzblog20master.gtsb.io/docs/reference/how-to-kill-a-process</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/installing-node\">https://bgoonzblog20master.gtsb.io/docs/reference/installing-node</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/intro-to-nodejs\">https://bgoonzblog20master.gtsb.io/docs/reference/intro-to-nodejs</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/markdown-styleguide\">https://bgoonzblog20master.gtsb.io/docs/reference/markdown-styleguide</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/notes-template\">https://bgoonzblog20master.gtsb.io/docs/reference/notes-template</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/psql\">https://bgoonzblog20master.gtsb.io/docs/reference/psql</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/resources\">https://bgoonzblog20master.gtsb.io/docs/reference/resources</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/vscode\">https://bgoonzblog20master.gtsb.io/docs/reference/vscode</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/reference/web-api%27s\">https://bgoonzblog20master.gtsb.io/docs/reference/web-api%27s</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap/\">https://bgoonzblog20master.gtsb.io/docs/sitemap/</a>\"</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap/\">https://bgoonzblog20master.gtsb.io/docs/sitemap/</a>\"<a href=\"https://bgoonzblog20master\">https://bgoonzblog20master</a>.</td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/sitemap/link\">https://bgoonzblog20master.gtsb.io/docs/sitemap/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tips\">https://bgoonzblog20master.gtsb.io/docs/tips</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tips/7-tips-to-become-a-better-web-developer\">https://bgoonzblog20master.gtsb.io/docs/tips/7-tips-to-become-a-better-web-developer</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tips/array-methods\">https://bgoonzblog20master.gtsb.io/docs/tips/array-methods</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tips/insert-into-array\">https://bgoonzblog20master.gtsb.io/docs/tips/insert-into-array</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tips/regex-tips\">https://bgoonzblog20master.gtsb.io/docs/tips/regex-tips</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tips/sorting-strings\">https://bgoonzblog20master.gtsb.io/docs/tips/sorting-strings</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tips/storybook\">https://bgoonzblog20master.gtsb.io/docs/tips/storybook</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tips/web-accessibility\">https://bgoonzblog20master.gtsb.io/docs/tips/web-accessibility</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tools\">https://bgoonzblog20master.gtsb.io/docs/tools</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tools/all-stripped\">https://bgoonzblog20master.gtsb.io/docs/tools/all-stripped</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tools/archive/link\">https://bgoonzblog20master.gtsb.io/docs/tools/archive/link</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tools/dev-utilities\">https://bgoonzblog20master.gtsb.io/docs/tools/dev-utilities</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tools/embeds-archive\">https://bgoonzblog20master.gtsb.io/docs/tools/embeds-archive</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tools/markdown-html\">https://bgoonzblog20master.gtsb.io/docs/tools/markdown-html</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tutorials\">https://bgoonzblog20master.gtsb.io/docs/tutorials</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tutorials/algolia-search\">https://bgoonzblog20master.gtsb.io/docs/tutorials/algolia-search</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tutorials/bash\">https://bgoonzblog20master.gtsb.io/docs/tutorials/bash</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tutorials/bash-commands-my\">https://bgoonzblog20master.gtsb.io/docs/tutorials/bash-commands-my</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tutorials/enviorment-setup\">https://bgoonzblog20master.gtsb.io/docs/tutorials/enviorment-setup</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tutorials/get-file-extension\">https://bgoonzblog20master.gtsb.io/docs/tutorials/get-file-extension</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tutorials/how-to-use-google-sheets-as-cms\">https://bgoonzblog20master.gtsb.io/docs/tutorials/how-to-use-google-sheets-as-cms</a></td>\n</tr>\n<tr>\n<td><a href=\"https://bgoonzblog20master.gtsb.io/docs/tutorials/psql-setup\">https://bgoonzblog20master.gtsb.io/docs/tutorials/psql-setup</a></td>\n</tr>\n</tbody>\n</table>\n<hr>\n<p><a href=\"https://trusting-dijkstra-4d3b17.netlify.app/\">Data Structures Website</a></p>\n<ul>\n<li><a href=\"https://web-dev-interview-prep-quiz-website.netlify.app/intro-js2.html\">Web-Dev-Quizzes</a></li>\n<li><a href=\"https://zen-lamport-5aab2c.netlify.app/\">Recursion</a></li>\n<li><a href=\"https://csb-ov0d1-bgoonz.vercel.app/\">React Documentation Site</a></li>\n<li><a href=\"https://amazing-hodgkin-33aea6.netlify.app/\">Blogs-from-webdevhub</a></li>\n<li><a href=\"https://angry-fermat-dcf5dd.netlify.app/\">Realty Website Demo</a></li>\n<li><a href=\"https://boring-heisenberg-f425d8.netlify.app/\">Best-Prac &#x26; Tools</a></li>\n<li><a href=\"https://site-analysis.netlify.app/\">site-analysis</a></li>\n<li><a href=\"https://clever-bartik-b5ba19.netlify.app/\">a/AOpen Notes</a></li>\n<li><a href=\"https://code-playground.netlify.app/\">Iframe Embed Playground</a></li>\n<li><a href=\"https://condescending-lewin-c96727.netlify.app/\">Triggered Effects Guitar Platform</a></li>\n<li><a href=\"https://determined-dijkstra-666766.netlify.app/\">Live Form</a></li>\n<li><a href=\"https://determined-dijkstra-ee7390.netlify.app/\">Interview Questions</a></li>\n<li><a href=\"https://eager-northcutt-456076.netlify.app/\">Resources Compilation</a></li>\n<li><a href=\"https://ecstatic-jang-593fd1.netlify.app/\">React Blog Depreciated</a></li>\n<li><a href=\"https://eloquent-sammet-ba1810.netlify.app/\">MihirBeg.com</a></li>\n<li><a href=\"https://embedable-content.netlify.app/\">Embeded Html Projects</a></li>\n<li><a href=\"https://festive-borg-e4d856.netlify.app/\">Cheat Sheets</a></li>\n<li><a href=\"https://focused-pasteur-0faac8.netlify.app/\">Early Version Of WebDevHub</a></li>\n<li><a href=\"https://gists42.netlify.app/\">My Gists</a></li>\n<li><a href=\"https://gracious-raman-474030.netlify.app/\">DS-Algo-Links</a></li>\n<li><a href=\"https://happy-mestorf-0f8e75.netlify.app/\">Video Chat App</a></li>\n<li><a href=\"https://hungry-shaw-30d504.netlify.app/\">Ciriculumn</a></li>\n<li><a href=\"https://inspiring-jennings-d14689.netlify.app/\">Cheat Sheets</a></li>\n<li><a href=\"https://links4242.netlify.app/\">Links</a></li>\n<li><a href=\"https://modest-booth-4e17df.netlify.app/\">Medium Articles</a></li>\n<li><a href=\"https://modest-torvalds-34afbc.netlify.app/\">NextJS Blog Template</a></li>\n<li><a href=\"https://modest-varahamihira-772b59.netlify.app/\">React Demo</a></li>\n<li><a href=\"https://nervous-swartz-0ab2cc.netlify.app/\">Ecomerce Norwex V1</a></li>\n<li><a href=\"https://objective-borg-a327cd.netlify.app/\">Gifs</a></li>\n<li><a href=\"https://pedantic-wing-adbf82.netlify.app/\">Excel2HTML</a></li>\n<li><a href=\"https://pensive-meitner-1ea8c4.netlify.app/\">Data Structures Site</a></li>\n<li><a href=\"https://portfolio42.netlify.app/\">Portfolio</a></li>\n<li><a href=\"https://priceless-shaw-86ccb2.netlify.app/\">Page Templates</a></li>\n<li><a href=\"https://quizzical-mcnulty-fa09f2.netlify.app/\">Photo Gallary</a></li>\n<li><a href=\"https://relaxed-bhaskara-dc85ec.netlify.app/\">Coffee Website</a></li>\n<li><a href=\"https://romantic-hamilton-514b79.netlify.app/\">Awesome Resources</a></li>\n<li><a href=\"https://silly-lichterman-b22b5f.netlify.app/\">Cheat Sheets</a></li>\n<li><a href=\"https://silly-shirley-ec955e.netlify.app/\">Link City</a></li>\n<li><a href=\"https://stoic-mccarthy-2c335f.netlify.app/\">VSCODE Extensions</a></li>\n<li><a href=\"https://web-dev-resource-hub-manual-deploy.netlify.app/\">webdevhub manual attempt</a></li>\n<li><a href=\"https://wonderful-pasteur-392fbe.netlify.app/\">Norwex Resources</a></li>\n<li><a href=\"https://zen-bhabha-bd046f.netlify.app/\">idk</a></li>\n<li><a href=\"https://getting-started42.herokuapp.com/\">heroku bare bones template</a></li>\n<li><a href=\"https://bad-reads42.herokuapp.com/\">bad reads</a></li>\n<li><a href=\"https://documentation-site-react2.vercel.app/\">docusaurus</a></li>\n<li><a href=\"https://app.stackbit.com/studio/609b2d7c71a5dd0016f36326\">stackbit</a></li>\n<li><a href=\"https://best-celery-b2d7c.netlify.app/\">NEW BLOG</a></li>\n</ul>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/index.html\">index.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/Chessjs/index.html\">Chessjs/index.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/Javascript-Drum-Kit-master/index.html\">Javascript-Drum-Kit-master/index.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/explore-react-without-react-master/clock-demo.html\">explore-react-without-react-master/clock-demo.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/explore-react-without-react-master/index.html\">explore-react-without-react-master/index.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/explore-react-without-react-master/tick-demo.html\">explore-react-without-react-master/tick-demo.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/explore-react-without-react-master/comment-demo.html\">explore-react-without-react-master/comment-demo.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/explore-react-without-react-master/state-clock-demo.html\">explore-react-without-react-master/state-clock-demo.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/explore-react-without-react-master/welcome-demo.html\">explore-react-without-react-master/welcome-demo.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/guessing-game-project-master/guessing-game-project-master/README.html\">guessing-game-project-master/guessing-game-project-master/README.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/javascript-text-to-speech-master/index.html\">javascript-text-to-speech-master/index.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/jsanimate-master/jsanimate-master/index.html\">jsanimate-master/jsanimate-master/index.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/memorygame-master/index.html\">memorygame-master/index.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/memorygame-master/img/background.psd\">memorygame-master/img/background.psd</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/mini-projects/Calculator/calculator.html\">Calculator/calculator.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/mini-projects/Radar/radar.html\">Radar/radar.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/mini-projects/Tooltip/cssTooltip.html\">Tooltip/cssTooltip.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/mini-showcase/dist/index.html\">mini-showcase/dist/index.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/building-your-own-file-utilities-solution/short.txt\">project-archive/building-your-own-file-utilities-solution/short.txt</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/global-replace-project-bonus-solution/essay.txt\">project-archive/global-replace-project-bonus-solution/essay.txt</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/global-replace-project-core-solution/essay.txt\">project-archive/global-replace-project-core-solution/essay.txt</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/local-storage-project-solution/storage-project.html\">project-archive/local-storage-project-solution/storage-project.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/my-profile-solution/myProfile.html\">project-archive/my-profile-solution/myProfile.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/proj2_debugging-recursive-solutions/debugging-recursive-solutions.pdf\">project-archive/proj2_debugging-recursive-solutions/debugging-recursive-solutions.pdf</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/spud-face-project-solution/spud-face.html\">project-archive/spud-face-project-solution/spud-face.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/testing-an-existing-project-solution/category-list-screen.html\">project-archive/testing-an-existing-project-solution/category-list-screen.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/testing-an-existing-project-solution/search-items-screen.html\">project-archive/testing-an-existing-project-solution/search-items-screen.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/testing-an-existing-project-solution/list-of-items-screen.html\">project-archive/testing-an-existing-project-solution/list-of-items-screen.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/project-archive/testing-an-existing-project-solution/todo-form-screen.html\">project-archive/testing-an-existing-project-solution/todo-form-screen.html</a></li>\n<li><a href=\"https://bgoonz.github.io/Project-Showcase/yahtzze/index.html\">yahtzze/index.html</a></li>\n</ul>"},{"url":"/docs/python/snippets/","relativePath":"docs/python/snippets.md","relativeDir":"docs/python","base":"snippets.md","name":"snippets","frontmatter":{"title":"Python Snippets","weight":0,"excerpt":"Snippets","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>Python Snippets</h1>\n<hr>\n<hr>\n<h3>Calculates the date of <code class=\"language-text\">n</code> days from the given date</h3>\n<ul>\n<li>Use <code class=\"language-text\">datetime.timedelta</code> and the <code class=\"language-text\">+</code> operator to calculate the new <code class=\"language-text\">datetime.datetime</code> value after adding <code class=\"language-text\">n</code> days to <code class=\"language-text\">d</code>.</li>\n<li>Omit the second argument, <code class=\"language-text\">d</code>, to use a default value of <code class=\"language-text\">datetime.today()</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> datetime<span class=\"token punctuation\">,</span> timedelta\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">add_days</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> d <span class=\"token operator\">=</span> datetime<span class=\"token punctuation\">.</span>today<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> d <span class=\"token operator\">+</span> timedelta<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> date\n\nadd_days<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># date(2020, 10, 30)</span>\nadd_days<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># date(2020, 10, 20)</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if all elements in a list are equal</h3>\n<ul>\n<li>Use <code class=\"language-text\">set()</code> to eliminate duplicate elements and then use <code class=\"language-text\">len()</code> to check if length is <code class=\"language-text\">1</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">all_equal</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">all_equal<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span>\nall_equal<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if all the values in a list are unique</h3>\n<ul>\n<li>Use <code class=\"language-text\">set()</code> on the given list to keep only unique occurrences.</li>\n<li>Use <code class=\"language-text\">len()</code> to compare the length of the unique values to the original list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">all_unique</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">x <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span>\ny <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\nall_unique<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nall_unique<span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span></code></pre></div>\n<hr>\n<hr>\n<h3>Generates a list of numbers in the arithmetic progression starting with the given positive integer and up to the specified limit</h3>\n<ul>\n<li>Use <code class=\"language-text\">range()</code> and <code class=\"language-text\">list()</code> with the appropriate start, step and end values.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">arithmetic_progression</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> lim<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> lim <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">arithmetic_progression<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [5, 10, 15, 20, 25]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the average of two or more numbers</h3>\n<ul>\n<li>Use <code class=\"language-text\">sum()</code> to sum all of the <code class=\"language-text\">args</code> provided, divide by <code class=\"language-text\">len()</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">average</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">,</span> <span class=\"token number\">0.0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">average<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2.0</span>\naverage<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2.0</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the average of a list, after mapping each element to a value using the provided function</h3>\n<ul>\n<li>Use <code class=\"language-text\">map()</code> to map each element to the value returned by <code class=\"language-text\">fn</code>.</li>\n<li>Use <code class=\"language-text\">sum()</code> to sum all of the mapped values, divide by <code class=\"language-text\">len(lst)</code>.</li>\n<li>Omit the last argument, <code class=\"language-text\">fn</code>, to use the default identity function.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">average_by</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">average_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">8</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">6</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">[</span><span class=\"token string\">'n'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># 5.0</span></code></pre></div>\n<hr>\n<hr>\n<h3>Splits values into two groups, based on the result of the given <code class=\"language-text\">filter</code> list</h3>\n<ul>\n<li>Use a list comprehension and <code class=\"language-text\">zip()</code> to add elements to groups, based on <code class=\"language-text\">filter</code>.</li>\n<li>If <code class=\"language-text\">filter</code> has a truthy value for any element, add it to the first group, otherwise add it to the second group.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">bifurcate</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> <span class=\"token builtin\">filter</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">[</span>x <span class=\"token keyword\">for</span> x<span class=\"token punctuation\">,</span> flag <span class=\"token keyword\">in</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> <span class=\"token builtin\">filter</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> flag<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span>x <span class=\"token keyword\">for</span> x<span class=\"token punctuation\">,</span> flag <span class=\"token keyword\">in</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> <span class=\"token builtin\">filter</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> flag<span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">bifurcate<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'beep'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'boop'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'foo'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bar'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># [ ['beep', 'boop', 'bar'], ['foo'] ]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Splits values into two groups, based on the result of the given filtering function</h3>\n<ul>\n<li>Use a list comprehension to add elements to groups, based on the value returned by <code class=\"language-text\">fn</code> for each element.</li>\n<li>If <code class=\"language-text\">fn</code> returns a truthy value for any element, add it to the first group, otherwise add it to the second group.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">bifurcate_by</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">[</span>x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> lst <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span>x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> lst <span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> fn<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">bifurcate_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'beep'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'boop'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'foo'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bar'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># [ ['beep', 'boop', 'bar'], ['foo'] ]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the number of ways to choose <code class=\"language-text\">k</code> items from <code class=\"language-text\">n</code> items without repetition and without order</h3>\n<ul>\n<li>Use <code class=\"language-text\">math.comb()</code> to calculate the binomial coefficient.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> comb\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">binomial_coefficient</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> k<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> comb<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> k<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">binomial_coefficient<span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 28</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the length of a string in bytes</h3>\n<ul>\n<li>Use <code class=\"language-text\">str.encode('utf-8')</code> to encode the given string and return its length.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">byte_size</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>encode<span class=\"token punctuation\">(</span><span class=\"token string\">'utf-8'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">byte_size<span class=\"token punctuation\">(</span><span class=\"token string\">'😀'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 4</span>\nbyte_size<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 11</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a string to camelcase</h3>\n<ul>\n<li>Use <code class=\"language-text\">re.sub()</code> to replace any <code class=\"language-text\">-</code> or <code class=\"language-text\">_</code> with a space, using the regexp <code class=\"language-text\">r\"(_|-)+\"</code>.</li>\n<li>Use <code class=\"language-text\">str.title()</code> to capitalize the first letter of each word and convert the rest to lowercase.</li>\n<li>Finally, use <code class=\"language-text\">str.replace()</code> to remove spaces between words.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> re <span class=\"token keyword\">import</span> sub\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">camel</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  s <span class=\"token operator\">=</span> sub<span class=\"token punctuation\">(</span><span class=\"token string\">r\"(_|-)+\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\" \"</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>replace<span class=\"token punctuation\">(</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token string\">''</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">camel<span class=\"token punctuation\">(</span><span class=\"token string\">'some_database_field_name'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'someDatabaseFieldName'</span>\ncamel<span class=\"token punctuation\">(</span><span class=\"token string\">'Some label that needs to be camelized'</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># 'someLabelThatNeedsToBeCamelized'</span>\ncamel<span class=\"token punctuation\">(</span><span class=\"token string\">'some-javascript-property'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'someJavascriptProperty'</span>\ncamel<span class=\"token punctuation\">(</span><span class=\"token string\">'some-mixed_string with spaces_underscores-and-hyphens'</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># 'someMixedStringWithSpacesUnderscoresAndHyphens'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Capitalizes the first letter of a string</h3>\n<ul>\n<li>Use list slicing and <code class=\"language-text\">str.upper()</code> to capitalize the first letter of the string.</li>\n<li>Use <code class=\"language-text\">str.join()</code> to combine the capitalized first letter with the rest of the characters.</li>\n<li>Omit the <code class=\"language-text\">lower_rest</code> parameter to keep the rest of the string intact, or set it to <code class=\"language-text\">True</code> to convert to lowercase.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">capitalize</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> lower_rest <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token string\">''</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> lower_rest <span class=\"token keyword\">else</span> s<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">capitalize<span class=\"token punctuation\">(</span><span class=\"token string\">'fooBar'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'FooBar'</span>\ncapitalize<span class=\"token punctuation\">(</span><span class=\"token string\">'fooBar'</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'Foobar'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Capitalizes the first letter of every word in a string</h3>\n<ul>\n<li>Use <code class=\"language-text\">str.title()</code> to capitalize the first letter of every word in the string.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">capitalize_every_word</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> s<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">capitalize_every_word<span class=\"token punctuation\">(</span><span class=\"token string\">'hello world!'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'Hello World!'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Casts the provided value as a list if it's not one</h3>\n<ul>\n<li>Use <code class=\"language-text\">isinstance()</code> to check if the given value is enumerable.</li>\n<li>Return it by using <code class=\"language-text\">list()</code> or encapsulated in a list accordingly.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">cast_list</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> <span class=\"token builtin\">isinstance</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token builtin\">tuple</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">[</span>val<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">cast_list<span class=\"token punctuation\">(</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># ['foo']</span>\ncast_list<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1]</span>\ncast_list<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bar'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># ['foo', 'bar']</span></code></pre></div>\n<hr>\n<h2>unlisted: true</h2>\n<p>Converts Celsius to Fahrenheit.</p>\n<ul>\n<li>Follow the conversion formula <code class=\"language-text\">F = 1.8 * C + 32</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">celsius_to_fahrenheit</span><span class=\"token punctuation\">(</span>degrees<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>degrees <span class=\"token operator\">*</span> <span class=\"token number\">1.8</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">32</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">celsius_to_fahrenheit<span class=\"token punctuation\">(</span><span class=\"token number\">180</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 356.0</span></code></pre></div>\n<hr>\n<hr>\n<h3>Creates a function that will invoke a predicate function for the specified property on a given object</h3>\n<ul>\n<li>Return a <code class=\"language-text\">lambda</code> function that takes an object and applies the predicate function, <code class=\"language-text\">fn</code> to the specified property.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">check_prop</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> prop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">lambda</span> obj<span class=\"token punctuation\">:</span> fn<span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">[</span>prop<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">check_age <span class=\"token operator\">=</span> check_prop<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">>=</span> <span class=\"token number\">18</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">)</span>\nuser <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Mark'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">18</span><span class=\"token punctuation\">}</span>\ncheck_age<span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Chunks a list into smaller lists of a specified size</h3>\n<ul>\n<li>Use <code class=\"language-text\">list()</code> and <code class=\"language-text\">range()</code> to create a list of the desired <code class=\"language-text\">size</code>.</li>\n<li>Use <code class=\"language-text\">map()</code> on the list and fill it with splices of the given list.</li>\n<li>Finally, return the created list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> ceil\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">chunk</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>\n    <span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> lst<span class=\"token punctuation\">[</span>x <span class=\"token operator\">*</span> size<span class=\"token punctuation\">:</span>x <span class=\"token operator\">*</span> size <span class=\"token operator\">+</span> size<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n      <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>ceil<span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">chunk<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [[1, 2], [3, 4], [5]]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Chunks a list into <code class=\"language-text\">n</code> smaller lists</h3>\n<ul>\n<li>Use <code class=\"language-text\">math.ceil()</code> and <code class=\"language-text\">len()</code> to get the size of each chunk.</li>\n<li>Use <code class=\"language-text\">list()</code> and <code class=\"language-text\">range()</code> to create a new list of size <code class=\"language-text\">n</code>.</li>\n<li>Use <code class=\"language-text\">map()</code> to map each element of the new list to a chunk the length of <code class=\"language-text\">size</code>.</li>\n<li>If the original list can't be split evenly, the final chunk will contain the remaining elements.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> ceil\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">chunk_into_n</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  size <span class=\"token operator\">=</span> ceil<span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> n<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>\n    <span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> lst<span class=\"token punctuation\">[</span>x <span class=\"token operator\">*</span> size<span class=\"token punctuation\">:</span>x <span class=\"token operator\">*</span> size <span class=\"token operator\">+</span> size<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">chunk_into_n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [[1, 2], [3, 4], [5, 6], [7]]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Clamps <code class=\"language-text\">num</code> within the inclusive range specified by the boundary values</h3>\n<ul>\n<li>If <code class=\"language-text\">num</code> falls within the range (<code class=\"language-text\">a</code>, <code class=\"language-text\">b</code>), return <code class=\"language-text\">num</code>.</li>\n<li>Otherwise, return the nearest number in the range.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">clamp_number</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">,</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">clamp_number<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 3</span>\nclamp_number<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># -1</span></code></pre></div>\n<hr>\n<hr>\n<h3>Inverts a dictionary with non-unique hashable values</h3>\n<ul>\n<li>Create a <code class=\"language-text\">collections.defaultdict</code> with <code class=\"language-text\">list</code> as the default value for each key.</li>\n<li>Use <code class=\"language-text\">dictionary.items()</code> in combination with a loop to map the values of the dictionary to keys using <code class=\"language-text\">dict.append()</code>.</li>\n<li>Use <code class=\"language-text\">dict()</code> to convert the <code class=\"language-text\">collections.defaultdict</code> to a regular dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> defaultdict\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">collect_dictionary</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  inv_obj <span class=\"token operator\">=</span> defaultdict<span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    inv_obj<span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>inv_obj<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">ages <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'Peter'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Isabel'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Anna'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\ncollect_dictionary<span class=\"token punctuation\">(</span>ages<span class=\"token punctuation\">)</span> <span class=\"token comment\"># { 10: ['Peter', 'Isabel'], 9: ['Anna'] }</span></code></pre></div>\n<hr>\n<hr>\n<h3>Combines two or more dictionaries, creating a list of values for each key</h3>\n<ul>\n<li>Create a new <code class=\"language-text\">collections.defaultdict</code> with <code class=\"language-text\">list</code> as the default value for each key and loop over <code class=\"language-text\">dicts</code>.</li>\n<li>Use <code class=\"language-text\">dict.append()</code> to map the values of the dictionary to keys.</li>\n<li>Use <code class=\"language-text\">dict()</code> to convert the <code class=\"language-text\">collections.defaultdict</code> to a regular dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> defaultdict\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">combine_values</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>dicts<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  res <span class=\"token operator\">=</span> defaultdict<span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">for</span> d <span class=\"token keyword\">in</span> dicts<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> key <span class=\"token keyword\">in</span> d<span class=\"token punctuation\">:</span>\n      res<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>res<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">d1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'foo'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">400</span><span class=\"token punctuation\">}</span>\nd2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">200</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">400</span><span class=\"token punctuation\">}</span>\n\ncombine_values<span class=\"token punctuation\">(</span>d1<span class=\"token punctuation\">,</span> d2<span class=\"token punctuation\">)</span> <span class=\"token comment\"># {'a': [1, 3], 'b': ['foo', 200], 'c': [400], 'd': [400]}</span></code></pre></div>\n<hr>\n<hr>\n<h3>Removes falsy values from a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">filter()</code> to filter out falsy values (<code class=\"language-text\">False</code>, <code class=\"language-text\">None</code>, <code class=\"language-text\">0</code>, and <code class=\"language-text\">\"\"</code>).</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">compact</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">filter</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">compact<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'s'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">34</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [ 1, 2, 3, 'a', 's', 34 ]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Performs right-to-left function composition</h3>\n<ul>\n<li>Use <code class=\"language-text\">functools.reduce()</code> to perform right-to-left function composition.</li>\n<li>The last (rightmost) function can accept one or more arguments; the remaining functions must be unary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> functools <span class=\"token keyword\">import</span> <span class=\"token builtin\">reduce</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">compose</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>fns<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> f<span class=\"token punctuation\">,</span> g<span class=\"token punctuation\">:</span> <span class=\"token keyword\">lambda</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">:</span> f<span class=\"token punctuation\">(</span>g<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> fns<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">add5 <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> <span class=\"token number\">5</span>\nmultiply <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">:</span> x <span class=\"token operator\">*</span> y\nmultiply_and_add_5 <span class=\"token operator\">=</span> compose<span class=\"token punctuation\">(</span>add5<span class=\"token punctuation\">,</span> multiply<span class=\"token punctuation\">)</span>\nmultiply_and_add_5<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 15</span></code></pre></div>\n<hr>\n<hr>\n<h3>Performs left-to-right function composition</h3>\n<ul>\n<li>Use <code class=\"language-text\">functools.reduce()</code> to perform left-to-right function composition.</li>\n<li>The first (leftmost) function can accept one or more arguments; the remaining functions must be unary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> functools <span class=\"token keyword\">import</span> <span class=\"token builtin\">reduce</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">compose_right</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>fns<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> f<span class=\"token punctuation\">,</span> g<span class=\"token punctuation\">:</span> <span class=\"token keyword\">lambda</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">:</span> g<span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> fns<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">add <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> y\nsquare <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">*</span> x\nadd_and_square <span class=\"token operator\">=</span> compose_right<span class=\"token punctuation\">(</span>add<span class=\"token punctuation\">,</span> square<span class=\"token punctuation\">)</span>\nadd_and_square<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 9</span></code></pre></div>\n<hr>\n<hr>\n<h3>Groups the elements of a list based on the given function and returns the count of elements in each group</h3>\n<ul>\n<li>Use <code class=\"language-text\">collections.defaultdict</code> to initialize a dictionary.</li>\n<li>Use <code class=\"language-text\">map()</code> to map the values of the given list using the given function.</li>\n<li>Iterate over the map and increase the element count each time it occurs.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> defaultdict\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">count_by</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  count <span class=\"token operator\">=</span> defaultdict<span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">for</span> val <span class=\"token keyword\">in</span> <span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    count<span class=\"token punctuation\">[</span>val<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> floor\n\ncount_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">6.1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4.2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6.3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> floor<span class=\"token punctuation\">)</span> <span class=\"token comment\"># {6: 2, 4: 1}</span>\ncount_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># {3: 2, 5: 1}</span></code></pre></div>\n<hr>\n<hr>\n<h3>Counts the occurrences of a value in a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">list.count()</code> to count the number of occurrences of <code class=\"language-text\">val</code> in <code class=\"language-text\">lst</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">count_occurrences</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> lst<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">count_occurrences<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 3</span></code></pre></div>\n<hr>\n<hr>\n<h3>Creates a list of partial sums</h3>\n<ul>\n<li>Use <code class=\"language-text\">itertools.accumulate()</code> to create the accumulated sum for each element.</li>\n<li>Use <code class=\"language-text\">list()</code> to convert the result into a list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> itertools <span class=\"token keyword\">import</span> accumulate\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">cumsum</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>accumulate<span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">cumsum<span class=\"token punctuation\">(</span><span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">15</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [0, 3, 9, 18, 30]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Curries a function</h3>\n<ul>\n<li>Use <code class=\"language-text\">functools.partial()</code> to return a new partial object which behaves like <code class=\"language-text\">fn</code> with the given arguments, <code class=\"language-text\">args</code>, partially applied.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> functools <span class=\"token keyword\">import</span> partial\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">curry</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> partial<span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">add <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> y\nadd10 <span class=\"token operator\">=</span> curry<span class=\"token punctuation\">(</span>add<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\nadd10<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 30</span></code></pre></div>\n<hr>\n<hr>\n<h3>Creates a list of dates between <code class=\"language-text\">start</code> (inclusive) and <code class=\"language-text\">end</code> (not inclusive)</h3>\n<ul>\n<li>Use <code class=\"language-text\">datetime.timedelta.days</code> to get the days between <code class=\"language-text\">start</code> and <code class=\"language-text\">end</code>.</li>\n<li>Use <code class=\"language-text\">int()</code> to convert the result to an integer and <code class=\"language-text\">range()</code> to iterate over each day.</li>\n<li>Use a list comprehension and <code class=\"language-text\">datetime.timedelta()</code> to create a list of <code class=\"language-text\">datetime.date</code> objects.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> timedelta<span class=\"token punctuation\">,</span> date\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">daterange</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>start <span class=\"token operator\">+</span> timedelta<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> n <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>end <span class=\"token operator\">-</span> start<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>days<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> date\n\ndaterange<span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># [date(2020, 10, 1), date(2020, 10, 2), date(2020, 10, 3), date(2020, 10, 4)]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the date of <code class=\"language-text\">n</code> days ago from today</h3>\n<ul>\n<li>Use <code class=\"language-text\">datetime.date.today()</code> to get the current day.</li>\n<li>Use <code class=\"language-text\">datetime.timedelta</code> to subtract <code class=\"language-text\">n</code> days from today's date.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> timedelta<span class=\"token punctuation\">,</span> date\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">days_ago</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> date<span class=\"token punctuation\">.</span>today<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> timedelta<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">days_ago<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># date(2020, 10, 23)</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the day difference between two dates</h3>\n<ul>\n<li>Subtract <code class=\"language-text\">start</code> from <code class=\"language-text\">end</code> and use <code class=\"language-text\">datetime.timedelta.days</code> to get the day difference.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">days_diff</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>end <span class=\"token operator\">-</span> start<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>days</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> date\n\ndays_diff<span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 3</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the date of <code class=\"language-text\">n</code> days from today</h3>\n<ul>\n<li>Use <code class=\"language-text\">datetime.date.today()</code> to get the current day.</li>\n<li>Use <code class=\"language-text\">datetime.timedelta</code> to add <code class=\"language-text\">n</code> days from today's date.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> timedelta<span class=\"token punctuation\">,</span> date\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">days_from_now</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> date<span class=\"token punctuation\">.</span>today<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> timedelta<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">days_from_now<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># date(2020, 11, 02)</span></code></pre></div>\n<hr>\n<hr>\n<h3>Decapitalizes the first letter of a string</h3>\n<ul>\n<li>Use list slicing and <code class=\"language-text\">str.lower()</code> to decapitalize the first letter of the string.</li>\n<li>Use <code class=\"language-text\">str.join()</code> to combine the lowercase first letter with the rest of the characters.</li>\n<li>Omit the <code class=\"language-text\">upper_rest</code> parameter to keep the rest of the string intact, or set it to <code class=\"language-text\">True</code> to convert to uppercase.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">decapitalize</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> upper_rest <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token string\">''</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> upper_rest <span class=\"token keyword\">else</span> s<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">decapitalize<span class=\"token punctuation\">(</span><span class=\"token string\">'FooBar'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'fooBar'</span>\ndecapitalize<span class=\"token punctuation\">(</span><span class=\"token string\">'FooBar'</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'fOOBAR'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Deep flattens a list</h3>\n<ul>\n<li>Use recursion.</li>\n<li>Use <code class=\"language-text\">isinstance()</code> with <code class=\"language-text\">collections.abc.Iterable</code> to check if an element is iterable.</li>\n<li>If it is iterable, apply <code class=\"language-text\">deep_flatten()</code> recursively, otherwise return <code class=\"language-text\">[lst]</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections<span class=\"token punctuation\">.</span>abc <span class=\"token keyword\">import</span> Iterable\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">deep_flatten</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>a <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> lst <span class=\"token keyword\">for</span> a <span class=\"token keyword\">in</span>\n          deep_flatten<span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token keyword\">if</span> <span class=\"token builtin\">isinstance</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> Iterable<span class=\"token punctuation\">)</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">[</span>lst<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">deep_flatten<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3, 4, 5]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts an angle from degrees to radians</h3>\n<ul>\n<li>Use <code class=\"language-text\">math.pi</code> and the degrees to radians formula to convert the angle from degrees to radians.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> pi\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">degrees_to_rads</span><span class=\"token punctuation\">(</span>deg<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>deg <span class=\"token operator\">*</span> pi<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">180.0</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">degrees_to_rads<span class=\"token punctuation\">(</span><span class=\"token number\">180</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># ~3.1416</span></code></pre></div>\n<hr>\n<hr>\n<h3>Invokes the provided function after <code class=\"language-text\">ms</code> milliseconds</h3>\n<ul>\n<li>Use <code class=\"language-text\">time.sleep()</code> to delay the execution of <code class=\"language-text\">fn</code> by <code class=\"language-text\">ms / 1000</code> seconds.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> time <span class=\"token keyword\">import</span> sleep\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> ms<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  sleep<span class=\"token punctuation\">(</span>ms <span class=\"token operator\">/</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> fn<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">delay<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'later'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># prints 'later' after one second</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a dictionary to a list of tuples</h3>\n<ul>\n<li>Use <code class=\"language-text\">dict.items()</code> and <code class=\"language-text\">list()</code> to get a list of tuples from the given dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">dict_to_list</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">d <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'five'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'four'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\ndict_to_list<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># [('one', 1), ('three', 3), ('five', 5), ('two', 2), ('four', 4)]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the difference between two iterables, without filtering duplicate values</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code> from <code class=\"language-text\">b</code>.</li>\n<li>Use a list comprehension on <code class=\"language-text\">a</code> to only keep values not contained in the previously created set, <code class=\"language-text\">_b</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">difference</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  _b <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> a <span class=\"token keyword\">if</span> item <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> _b<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">difference<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the difference between two lists, after applying the provided function to each list element of both</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code>, using <code class=\"language-text\">map()</code> to apply <code class=\"language-text\">fn</code> to each element in <code class=\"language-text\">b</code>.</li>\n<li>Use a list comprehension in combination with <code class=\"language-text\">fn</code> on <code class=\"language-text\">a</code> to only keep values not contained in the previously created set, <code class=\"language-text\">_b</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">difference_by</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  _b <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> a <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> _b<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> floor\n\ndifference_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2.1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2.3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3.4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> floor<span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1.2]</span>\ndifference_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token string\">'x'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'x'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token string\">'x'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> v <span class=\"token punctuation\">:</span> v<span class=\"token punctuation\">[</span><span class=\"token string\">'x'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># [ { x: 2 } ]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a number to a list of digits</h3>\n<ul>\n<li>Use <code class=\"language-text\">map()</code> combined with <code class=\"language-text\">int</code> on the string representation of <code class=\"language-text\">n</code> and return a list from the result.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">digitize</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">digitize<span class=\"token punctuation\">(</span><span class=\"token number\">123</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a list with <code class=\"language-text\">n</code> elements removed from the left</h3>\n<ul>\n<li>Use slice notation to remove the specified number of elements from the left.</li>\n<li>Omit the last argument, <code class=\"language-text\">n</code>, to use a default value of <code class=\"language-text\">1</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">drop</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> a<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">drop<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2, 3]</span>\ndrop<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3]</span>\ndrop<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">42</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># []</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a list with <code class=\"language-text\">n</code> elements removed from the right</h3>\n<ul>\n<li>Use slice notation to remove the specified number of elements from the right.</li>\n<li>Omit the last argument, <code class=\"language-text\">n</code>, to use a default value of <code class=\"language-text\">1</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">drop_right</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> a<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span>n<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">drop_right<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2]</span>\ndrop_right<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1]</span>\ndrop_right<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">42</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># []</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the provided function returns <code class=\"language-text\">True</code> for every element in the list</h3>\n<ul>\n<li>Use <code class=\"language-text\">all()</code> in combination with <code class=\"language-text\">map()</code> and <code class=\"language-text\">fn</code> to check if <code class=\"language-text\">fn</code> returns <code class=\"language-text\">True</code> for all elements in the list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">every</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">every<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nevery<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns every <code class=\"language-text\">nth</code> element in a list</h3>\n<ul>\n<li>Use slice notation to create a new list that contains every <code class=\"language-text\">nth</code> element of the given list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">every_nth</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> nth<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> lst<span class=\"token punctuation\">[</span>nth <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span>nth<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">every_nth<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [ 2, 4, 6 ]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the factorial of a number</h3>\n<ul>\n<li>Use recursion.</li>\n<li>If <code class=\"language-text\">num</code> is less than or equal to <code class=\"language-text\">1</code>, return <code class=\"language-text\">1</code>.</li>\n<li>Otherwise, return the product of <code class=\"language-text\">num</code> and the factorial of <code class=\"language-text\">num - 1</code>.</li>\n<li>Throws an exception if <code class=\"language-text\">num</code> is a negative or a floating point number.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>num <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">%</span> <span class=\"token number\">1</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">\"Number can't be floating point or negative.\"</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token number\">1</span> <span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">0</span> <span class=\"token keyword\">else</span> num <span class=\"token operator\">*</span> factorial<span class=\"token punctuation\">(</span>num <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">factorial<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 720</span></code></pre></div>\n<hr>\n<h2>unlisted: true</h2>\n<p>Converts Fahrenheit to Celsius.</p>\n<ul>\n<li>Follow the conversion formula <code class=\"language-text\">C = (F - 32) * 5/9</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">fahrenheit_to_celsius</span><span class=\"token punctuation\">(</span>degrees<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>degrees <span class=\"token operator\">-</span> <span class=\"token number\">32</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span><span class=\"token operator\">/</span><span class=\"token number\">9</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">fahrenheit_to_celsius<span class=\"token punctuation\">(</span><span class=\"token number\">77</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 25.0</span></code></pre></div>\n<hr>\n<hr>\n<h3>Generates a list, containing the Fibonacci sequence, up until the nth term</h3>\n<ul>\n<li>Starting with <code class=\"language-text\">0</code> and <code class=\"language-text\">1</code>, use <code class=\"language-text\">list.append()</code> to add the sum of the last two numbers of the list to the end of the list, until the length of the list reaches <code class=\"language-text\">n</code>.</li>\n<li>If <code class=\"language-text\">n</code> is less or equal to <code class=\"language-text\">0</code>, return a list containing <code class=\"language-text\">0</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">fibonacci</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">if</span> n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n  sequence <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n  <span class=\"token keyword\">while</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>sequence<span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">:</span>\n    next_value <span class=\"token operator\">=</span> sequence<span class=\"token punctuation\">[</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>sequence<span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> sequence<span class=\"token punctuation\">[</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>sequence<span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\n    sequence<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>next_value<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> sequence</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">fibonacci<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [0, 1, 1, 2, 3, 5, 8, 13]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Creates a list with the non-unique values filtered out</h3>\n<ul>\n<li>Use <code class=\"language-text\">collections.Counter</code> to get the count of each value in the list.</li>\n<li>Use a list comprehension to create a list containing only the unique values.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> Counter\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">filter_non_unique</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item<span class=\"token punctuation\">,</span> count <span class=\"token keyword\">in</span> Counter<span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> count <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">filter_non_unique<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 3, 5]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Creates a list with the unique values filtered out</h3>\n<ul>\n<li>Use <code class=\"language-text\">collections.Counter</code> to get the count of each value in the list.</li>\n<li>Use a list comprehension to create a list containing only the non-unique values.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> Counter\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">filter_unique</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item<span class=\"token punctuation\">,</span> count <span class=\"token keyword\">in</span> Counter<span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> count <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">filter_unique<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2, 4]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the value of the first element in the given list that satisfies the provided testing function</h3>\n<ul>\n<li>Use a list comprehension and <code class=\"language-text\">next()</code> to return the first element in <code class=\"language-text\">lst</code> for which <code class=\"language-text\">fn</code> returns <code class=\"language-text\">True</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">find</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">next</span><span class=\"token punctuation\">(</span>x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> lst <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">find<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> n<span class=\"token punctuation\">:</span> n <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 1</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the index of the first element in the given list that satisfies the provided testing function</h3>\n<ul>\n<li>Use a list comprehension, <code class=\"language-text\">enumerate()</code> and <code class=\"language-text\">next()</code> to return the index of the first element in <code class=\"language-text\">lst</code> for which <code class=\"language-text\">fn</code> returns <code class=\"language-text\">True</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">find_index</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">next</span><span class=\"token punctuation\">(</span>i <span class=\"token keyword\">for</span> i<span class=\"token punctuation\">,</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">find_index<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> n<span class=\"token punctuation\">:</span> n <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 0</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the indexes of all elements in the given list that satisfy the provided testing function</h3>\n<ul>\n<li>Use <code class=\"language-text\">enumerate()</code> and a list comprehension to return the indexes of the all element in <code class=\"language-text\">lst</code> for which <code class=\"language-text\">fn</code> returns <code class=\"language-text\">True</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">find_index_of_all</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>i <span class=\"token keyword\">for</span> i<span class=\"token punctuation\">,</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">find_index_of_all<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> n<span class=\"token punctuation\">:</span> n <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [0, 2]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the first key in the provided dictionary that has the given value</h3>\n<ul>\n<li>Use <code class=\"language-text\">dictionary.items()</code> and <code class=\"language-text\">next()</code> to return the first key that has a value equal to <code class=\"language-text\">val</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">find_key</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">dict</span><span class=\"token punctuation\">,</span> val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">next</span><span class=\"token punctuation\">(</span>key <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> value <span class=\"token operator\">==</span> val<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">ages <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'Peter'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Isabel'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Anna'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\nfind_key<span class=\"token punctuation\">(</span>ages<span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'Isabel'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds all keys in the provided dictionary that have the given value</h3>\n<ul>\n<li>Use <code class=\"language-text\">dictionary.items()</code>, a generator and <code class=\"language-text\">list()</code> to return all keys that have a value equal to <code class=\"language-text\">val</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">find_keys</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">dict</span><span class=\"token punctuation\">,</span> val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>key <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> value <span class=\"token operator\">==</span> val<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">ages <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'Peter'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Isabel'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Anna'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\nfind_keys<span class=\"token punctuation\">(</span>ages<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [ 'Peter', 'Anna' ]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the value of the last element in the given list that satisfies the provided testing function</h3>\n<ul>\n<li>Use a list comprehension and <code class=\"language-text\">next()</code> to return the last element in <code class=\"language-text\">lst</code> for which <code class=\"language-text\">fn</code> returns <code class=\"language-text\">True</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">find_last</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">next</span><span class=\"token punctuation\">(</span>x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">find_last<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> n<span class=\"token punctuation\">:</span> n <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 3</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the index of the last element in the given list that satisfies the provided testing function</h3>\n<ul>\n<li>Use a list comprehension, <code class=\"language-text\">enumerate()</code> and <code class=\"language-text\">next()</code> to return the index of the last element in <code class=\"language-text\">lst</code> for which <code class=\"language-text\">fn</code> returns <code class=\"language-text\">True</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">find_last_index</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token operator\">-</span> <span class=\"token builtin\">next</span><span class=\"token punctuation\">(</span>i <span class=\"token keyword\">for</span> i<span class=\"token punctuation\">,</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">find_last_index<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> n<span class=\"token punctuation\">:</span> n <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the items that are parity outliers in a given list</h3>\n<ul>\n<li>Use <code class=\"language-text\">collections.Counter</code> with a list comprehension to count even and odd values in the list.</li>\n<li>Use <code class=\"language-text\">collections.Counter.most_common()</code> to get the most common parity.</li>\n<li>Use a list comprehension to find all elements that do not match the most common parity.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> Counter\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">find_parity_outliers</span><span class=\"token punctuation\">(</span>nums<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>\n    x <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> nums\n    <span class=\"token keyword\">if</span> x <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">!=</span> Counter<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>n <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token keyword\">for</span> n <span class=\"token keyword\">in</span> nums<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>most_common<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">find_parity_outliers<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 3]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Flattens a list of lists once</h3>\n<ul>\n<li>Use a list comprehension to extract each value from sub-lists in order.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">flatten</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>x <span class=\"token keyword\">for</span> y <span class=\"token keyword\">in</span> lst <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> y<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">flatten<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3, 4, 5, 6, 7, 8]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Executes the provided function once for each list element</h3>\n<ul>\n<li>Use a <code class=\"language-text\">for</code> loop to execute <code class=\"language-text\">fn</code> for each element in <code class=\"language-text\">itr</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">for_each</span><span class=\"token punctuation\">(</span>itr<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">for</span> el <span class=\"token keyword\">in</span> itr<span class=\"token punctuation\">:</span>\n    fn<span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">for_each<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 1 2 3</span></code></pre></div>\n<hr>\n<hr>\n<h3>Executes the provided function once for each list element, starting from the list's last element</h3>\n<ul>\n<li>Use a <code class=\"language-text\">for</code> loop in combination with slice notation to execute <code class=\"language-text\">fn</code> for each element in <code class=\"language-text\">itr</code>, starting from the last one.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">for_each_right</span><span class=\"token punctuation\">(</span>itr<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">for</span> el <span class=\"token keyword\">in</span> itr<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span>\n    fn<span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">for_each_right<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 3 2 1</span></code></pre></div>\n<hr>\n<hr>\n<h3>Creates a dictionary with the unique values of a list as keys and their frequencies as the values</h3>\n<ul>\n<li>Use <code class=\"language-text\">collections.defaultdict()</code> to store the frequencies of each unique element.</li>\n<li>Use <code class=\"language-text\">dict()</code> to return a dictionary with the unique elements of the list as keys and their frequencies as the values.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> defaultdict\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">frequencies</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  freq <span class=\"token operator\">=</span> defaultdict<span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">for</span> val <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">:</span>\n    freq<span class=\"token punctuation\">[</span>val<span class=\"token punctuation\">]</span> <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>freq<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">frequencies<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># { 'a': 4, 'b': 2, 'c': 1 }</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a date from its ISO-8601 representation</h3>\n<ul>\n<li>Use <code class=\"language-text\">datetime.datetime.fromisoformat()</code> to convert the given ISO-8601 date to a <code class=\"language-text\">datetime.datetime</code> object.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> datetime\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">from_iso_date</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> datetime<span class=\"token punctuation\">.</span>fromisoformat<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">from_iso_date<span class=\"token punctuation\">(</span><span class=\"token string\">'2020-10-28T12:30:59.000000'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2020-10-28 12:30:59</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the greatest common divisor of a list of numbers</h3>\n<ul>\n<li>Use <code class=\"language-text\">functools.reduce()</code> and <code class=\"language-text\">math.gcd()</code> over the given list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> functools <span class=\"token keyword\">import</span> <span class=\"token builtin\">reduce</span>\n<span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> gcd <span class=\"token keyword\">as</span> _gcd\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">gcd</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">reduce</span><span class=\"token punctuation\">(</span>_gcd<span class=\"token punctuation\">,</span> numbers<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">gcd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">36</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 4</span></code></pre></div>\n<hr>\n<hr>\n<h3>Initializes a list containing the numbers in the specified range where <code class=\"language-text\">start</code> and <code class=\"language-text\">end</code> are inclusive and the ratio between two terms is <code class=\"language-text\">step</code></h3>\n<p>Returns an error if <code class=\"language-text\">step</code> equals <code class=\"language-text\">1</code>.</p>\n<ul>\n<li>Use <code class=\"language-text\">range()</code>, <code class=\"language-text\">math.log()</code> and <code class=\"language-text\">math.floor()</code> and a list comprehension to create a list of the appropriate length, applying the step for each element.</li>\n<li>Omit the second argument, <code class=\"language-text\">start</code>, to use a default value of <code class=\"language-text\">1</code>.</li>\n<li>Omit the third argument, <code class=\"language-text\">step</code>, to use a default value of <code class=\"language-text\">2</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> floor<span class=\"token punctuation\">,</span> log\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">geometric_progression</span><span class=\"token punctuation\">(</span>end<span class=\"token punctuation\">,</span> start<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> step<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>start <span class=\"token operator\">*</span> step <span class=\"token operator\">**</span> i <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>floor<span class=\"token punctuation\">(</span>log<span class=\"token punctuation\">(</span>end <span class=\"token operator\">/</span> start<span class=\"token punctuation\">)</span>\n          <span class=\"token operator\">/</span> log<span class=\"token punctuation\">(</span>step<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">geometric_progression<span class=\"token punctuation\">(</span><span class=\"token number\">256</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 4, 8, 16, 32, 64, 128, 256]</span>\ngeometric_progression<span class=\"token punctuation\">(</span><span class=\"token number\">256</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3, 6, 12, 24, 48, 96, 192]</span>\ngeometric_progression<span class=\"token punctuation\">(</span><span class=\"token number\">256</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 4, 16, 64, 256]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Retrieves the value of the nested key indicated by the given selector list from a dictionary or list</h3>\n<ul>\n<li>Use <code class=\"language-text\">functools.reduce()</code> to iterate over the <code class=\"language-text\">selectors</code> list.</li>\n<li>Apply <code class=\"language-text\">operator.getitem()</code> for each key in <code class=\"language-text\">selectors</code>, retrieving the value to be used as the iteratee for the next iteration.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> functools <span class=\"token keyword\">import</span> <span class=\"token builtin\">reduce</span>\n<span class=\"token keyword\">from</span> operator <span class=\"token keyword\">import</span> getitem\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> selectors<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">reduce</span><span class=\"token punctuation\">(</span>getitem<span class=\"token punctuation\">,</span> selectors<span class=\"token punctuation\">,</span> d<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">users <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'freddy'</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token string\">'first'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'fred'</span><span class=\"token punctuation\">,</span>\n      <span class=\"token string\">'last'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'smith'</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'postIds'</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nget<span class=\"token punctuation\">(</span>users<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'freddy'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'last'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'smith'</span>\nget<span class=\"token punctuation\">(</span>users<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'freddy'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'postIds'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2</span></code></pre></div>\n<hr>\n<hr>\n<h3>Groups the elements of a list based on the given function</h3>\n<ul>\n<li>Use <code class=\"language-text\">collections.defaultdict</code> to initialize a dictionary.</li>\n<li>Use <code class=\"language-text\">fn</code> in combination with a <code class=\"language-text\">for</code> loop and <code class=\"language-text\">dict.append()</code> to populate the dictionary.</li>\n<li>Use <code class=\"language-text\">dict()</code> to convert it to a regular dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> defaultdict\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">group_by</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  d <span class=\"token operator\">=</span> defaultdict<span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">for</span> el <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">:</span>\n    d<span class=\"token punctuation\">[</span>fn<span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> floor\n\ngroup_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">6.1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4.2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6.3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> floor<span class=\"token punctuation\">)</span> <span class=\"token comment\"># {4: [4.2], 6: [6.1, 6.3]}</span>\ngroup_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># {3: ['one', 'two'], 5: ['three']}</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the Hamming distance between two values</h3>\n<ul>\n<li>Use the XOR operator (<code class=\"language-text\">^</code>) to find the bit difference between the two numbers.</li>\n<li>Use <code class=\"language-text\">bin()</code> to convert the result to a binary string.</li>\n<li>Convert the string to a list and use <code class=\"language-text\">count()</code> of <code class=\"language-text\">str</code> class to count and return the number of <code class=\"language-text\">1</code>s in it.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">hamming_distance</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">bin</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">^</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span><span class=\"token string\">'1'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">hamming_distance<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 1</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if there are duplicate values in a flat list</h3>\n<ul>\n<li>Use <code class=\"language-text\">set()</code> on the given list to remove duplicates, compare its length with the length of the list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">has_duplicates</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token operator\">!=</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">x <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\ny <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\nhas_duplicates<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nhas_duplicates<span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if two lists contain the same elements regardless of order</h3>\n<ul>\n<li>Use <code class=\"language-text\">set()</code> on the combination of both lists to find the unique values.</li>\n<li>Iterate over them with a <code class=\"language-text\">for</code> loop comparing the <code class=\"language-text\">count()</code> of each unique value in each list.</li>\n<li>Return <code class=\"language-text\">False</code> if the counts do not match for any element, <code class=\"language-text\">True</code> otherwise.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">have_same_contents</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">for</span> v <span class=\"token keyword\">in</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> a<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span> <span class=\"token operator\">!=</span> b<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>\n  <span class=\"token keyword\">return</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">have_same_contents<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the head of a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">lst[0]</code> to return the first element of the passed list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">head</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> lst<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">head<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 1</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components</h3>\n<ul>\n<li>Use a list comprehension in combination with <code class=\"language-text\">int()</code> and list slice notation to get the RGB components from the hexadecimal string.</li>\n<li>Use <code class=\"language-text\">tuple()</code> to convert the resulting list to a tuple.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">hex_to_rgb</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">hex</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">hex</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">:</span>i<span class=\"token operator\">+</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">16</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">hex_to_rgb<span class=\"token punctuation\">(</span><span class=\"token string\">'FFA501'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># (255, 165, 1)</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the given number falls within the given range</h3>\n<ul>\n<li>Use arithmetic comparison to check if the given number is in the specified range.</li>\n<li>If the second parameter, <code class=\"language-text\">end</code>, is not specified, the range is considered to be from <code class=\"language-text\">0</code> to <code class=\"language-text\">start</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">in_range</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> start <span class=\"token operator\">&lt;=</span> n <span class=\"token operator\">&lt;=</span> end <span class=\"token keyword\">if</span> end <span class=\"token operator\">>=</span> start <span class=\"token keyword\">else</span> end <span class=\"token operator\">&lt;=</span> n <span class=\"token operator\">&lt;=</span> start</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">in_range<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nin_range<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nin_range<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span>\nin_range<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if all the elements in <code class=\"language-text\">values</code> are included in <code class=\"language-text\">lst</code></h3>\n<ul>\n<li>Check if every value in <code class=\"language-text\">values</code> is contained in <code class=\"language-text\">lst</code> using a <code class=\"language-text\">for</code> loop.</li>\n<li>Return <code class=\"language-text\">False</code> if any one value is not found, <code class=\"language-text\">True</code> otherwise.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">includes_all</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> values<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">for</span> v <span class=\"token keyword\">in</span> values<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> v <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>\n  <span class=\"token keyword\">return</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">includes_all<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nincludes_all<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if any element in <code class=\"language-text\">values</code> is included in <code class=\"language-text\">lst</code></h3>\n<ul>\n<li>Check if any value in <code class=\"language-text\">values</code> is contained in <code class=\"language-text\">lst</code> using a <code class=\"language-text\">for</code> loop.</li>\n<li>Return <code class=\"language-text\">True</code> if any one value is found, <code class=\"language-text\">False</code> otherwise.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">includes_any</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> values<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">for</span> v <span class=\"token keyword\">in</span> values<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> v <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">return</span> <span class=\"token boolean\">True</span>\n  <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">includes_any<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nincludes_any<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a list of indexes of all the occurrences of an element in a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">enumerate()</code> and a list comprehension to check each element for equality with <code class=\"language-text\">value</code> and adding <code class=\"language-text\">i</code> to the result.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">index_of_all</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>i <span class=\"token keyword\">for</span> i<span class=\"token punctuation\">,</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> x <span class=\"token operator\">==</span> value<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">index_of_all<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [0, 2, 5]</span>\nindex_of_all<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># []</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns all the elements of a list except the last one</h3>\n<ul>\n<li>Use <code class=\"language-text\">lst[:-1]</code> to return all but the last element of the list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">initial</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> lst<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">initial<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Initializes a 2D list of given width and height and value</h3>\n<ul>\n<li>Use a list comprehension and <code class=\"language-text\">range()</code> to generate <code class=\"language-text\">h</code> rows where each is a list with length <code class=\"language-text\">h</code>, initialized with <code class=\"language-text\">val</code>.</li>\n<li>Omit the last argument, <code class=\"language-text\">val</code>, to set the default value to <code class=\"language-text\">None</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">initialize_2d_list</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">,</span> h<span class=\"token punctuation\">,</span> val <span class=\"token operator\">=</span> <span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span>val <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token keyword\">for</span> y <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>h<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">initialize_2d_list<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [[0, 0], [0, 0]]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Initializes a list containing the numbers in the specified range where <code class=\"language-text\">start</code> and <code class=\"language-text\">end</code> are inclusive with their common difference <code class=\"language-text\">step</code></h3>\n<ul>\n<li>Use <code class=\"language-text\">list()</code> and <code class=\"language-text\">range()</code> to generate a list of the appropriate length, filled with the desired values in the given range.</li>\n<li>Omit <code class=\"language-text\">start</code> to use the default value of <code class=\"language-text\">0</code>.</li>\n<li>Omit <code class=\"language-text\">step</code> to use the default value of <code class=\"language-text\">1</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">initialize_list_with_range</span><span class=\"token punctuation\">(</span>end<span class=\"token punctuation\">,</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> step <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> step<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">initialize_list_with_range<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [0, 1, 2, 3, 4, 5]</span>\ninitialize_list_with_range<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3, 4, 5, 6, 7]</span>\ninitialize_list_with_range<span class=\"token punctuation\">(</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [0, 2, 4, 6, 8]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Initializes and fills a list with the specified value</h3>\n<ul>\n<li>Use a list comprehension and <code class=\"language-text\">range()</code> to generate a list of length equal to <code class=\"language-text\">n</code>, filled with the desired values.</li>\n<li>Omit <code class=\"language-text\">val</code> to use the default value of <code class=\"language-text\">0</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">initialize_list_with_values</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> val <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>val <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">initialize_list_with_values<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2, 2, 2, 2, 2]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a list of elements that exist in both lists</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code> from <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code>.</li>\n<li>Use the built-in set operator <code class=\"language-text\">&amp;</code> to only keep values contained in both sets, then transform the <code class=\"language-text\">set</code> back into a <code class=\"language-text\">list</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">intersection</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  _a<span class=\"token punctuation\">,</span> _b <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>_a <span class=\"token operator\">&amp;</span> _b<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">intersection<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2, 3]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a list of elements that exist in both lists, after applying the provided function to each list element of both</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code>, using <code class=\"language-text\">map()</code> to apply <code class=\"language-text\">fn</code> to each element in <code class=\"language-text\">b</code>.</li>\n<li>Use a list comprehension in combination with <code class=\"language-text\">fn</code> on <code class=\"language-text\">a</code> to only keep values contained in both lists.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">intersection_by</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  _b <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> a <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> _b<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> floor\n\nintersection_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2.1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2.3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3.4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> floor<span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2.1]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Inverts a dictionary with unique hashable values</h3>\n<ul>\n<li>Use <code class=\"language-text\">dictionary.items()</code> in combination with a list comprehension to create a new dictionary with the values and keys inverted.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">invert_dictionary</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> value<span class=\"token punctuation\">:</span> key <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">ages <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'Peter'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Isabel'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Anna'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\ninvert_dictionary<span class=\"token punctuation\">(</span>ages<span class=\"token punctuation\">)</span> <span class=\"token comment\"># { 10: 'Peter', 11: 'Isabel', 9: 'Anna' }</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters)</h3>\n<ul>\n<li>Use <code class=\"language-text\">str.isalnum()</code> to filter out non-alphanumeric characters, <code class=\"language-text\">str.lower()</code> to transform each character to lowercase.</li>\n<li>Use <code class=\"language-text\">collections.Counter</code> to count the resulting characters for each string and compare the results.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> collections <span class=\"token keyword\">import</span> Counter\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">is_anagram</span><span class=\"token punctuation\">(</span>s1<span class=\"token punctuation\">,</span> s2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> Counter<span class=\"token punctuation\">(</span>\n    c<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> c <span class=\"token keyword\">in</span> s1 <span class=\"token keyword\">if</span> c<span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> Counter<span class=\"token punctuation\">(</span>\n    c<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> c <span class=\"token keyword\">in</span> s2 <span class=\"token keyword\">if</span> c<span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">is_anagram<span class=\"token punctuation\">(</span><span class=\"token string\">'#anagram'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Nag a ram!'</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the elements of the first list are contained in the second one regardless of order</h3>\n<ul>\n<li>Use <code class=\"language-text\">count()</code> to check if any value in <code class=\"language-text\">a</code> has more occurrences than it has in <code class=\"language-text\">b</code>.</li>\n<li>Return <code class=\"language-text\">False</code> if any such value is found, <code class=\"language-text\">True</code> otherwise.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">is_contained_in</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">for</span> v <span class=\"token keyword\">in</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> a<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> b<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>\n  <span class=\"token keyword\">return</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">is_contained_in<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<h2>unlisted: true</h2>\n<p>Checks if the first numeric argument is divisible by the second one.</p>\n<ul>\n<li>Use the modulo operator (<code class=\"language-text\">%</code>) to check if the remainder is equal to <code class=\"language-text\">0</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">is_divisible</span><span class=\"token punctuation\">(</span>dividend<span class=\"token punctuation\">,</span> divisor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> dividend <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">is_divisible<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<h2>unlisted: true</h2>\n<p>Checks if the given number is even.</p>\n<ul>\n<li>Check whether a number is odd or even using the modulo (<code class=\"language-text\">%</code>) operator.</li>\n<li>Return <code class=\"language-text\">True</code> if the number is even, <code class=\"language-text\">False</code> if the number is odd.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">is_even</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> num <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">is_even<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span></code></pre></div>\n<hr>\n<h2>unlisted: true</h2>\n<p>Checks if the given number is odd.</p>\n<ul>\n<li>Checks whether a number is even or odd using the modulo (<code class=\"language-text\">%</code>) operator.</li>\n<li>Returns <code class=\"language-text\">True</code> if the number is odd, <code class=\"language-text\">False</code> if the number is even.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">is_odd</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> num <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">!=</span> <span class=\"token number\">0</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">is_odd<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the provided integer is a prime number</h3>\n<ul>\n<li>Return <code class=\"language-text\">False</code> if the number is <code class=\"language-text\">0</code>, <code class=\"language-text\">1</code>, a negative number or a multiple of <code class=\"language-text\">2</code>.</li>\n<li>Use <code class=\"language-text\">all()</code> and <code class=\"language-text\">range()</code> to check numbers from <code class=\"language-text\">3</code> to the square root of the given number.</li>\n<li>Return <code class=\"language-text\">True</code> if none divides the given number, <code class=\"language-text\">False</code> otherwise.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> sqrt\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">is_prime</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">if</span> n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span> <span class=\"token keyword\">or</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span> <span class=\"token keyword\">and</span> n <span class=\"token operator\">></span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">%</span> i <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>sqrt<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">is_prime<span class=\"token punctuation\">(</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the given date is a weekday</h3>\n<ul>\n<li>Use <code class=\"language-text\">datetime.datetime.weekday()</code> to get the day of the week as an integer.</li>\n<li>Check if the day of the week is less than or equal to <code class=\"language-text\">4</code>.</li>\n<li>Omit the second argument, <code class=\"language-text\">d</code>, to use a default value of <code class=\"language-text\">datetime.today()</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> datetime\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">is_weekday</span><span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> datetime<span class=\"token punctuation\">.</span>today<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> d<span class=\"token punctuation\">.</span>weekday<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;=</span> <span class=\"token number\">4</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> date\n\nis_weekday<span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span>\nis_weekday<span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the given date is a weekend</h3>\n<ul>\n<li>Use <code class=\"language-text\">datetime.datetime.weekday()</code> to get the day of the week as an integer.</li>\n<li>Check if the day of the week is greater than <code class=\"language-text\">4</code>.</li>\n<li>Omit the second argument, <code class=\"language-text\">d</code>, to use a default value of <code class=\"language-text\">datetime.today()</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> datetime\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">is_weekend</span><span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> datetime<span class=\"token punctuation\">.</span>today<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> d<span class=\"token punctuation\">.</span>weekday<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> <span class=\"token number\">4</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> date\n\nis_weekend<span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nis_weekend<span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a string to kebab case</h3>\n<ul>\n<li>Use <code class=\"language-text\">re.sub()</code> to replace any <code class=\"language-text\">-</code> or <code class=\"language-text\">_</code> with a space, using the regexp <code class=\"language-text\">r\"(_|-)+\"</code>.</li>\n<li>Use <code class=\"language-text\">re.sub()</code> to match all words in the string, <code class=\"language-text\">str.lower()</code> to lowercase them.</li>\n<li>Finally, use <code class=\"language-text\">str.join()</code> to combine all word using <code class=\"language-text\">-</code> as the separator.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> re <span class=\"token keyword\">import</span> sub\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">kebab</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token string\">'-'</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span>\n    sub<span class=\"token punctuation\">(</span><span class=\"token string\">r\"(\\s|_|-)+\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">,</span>\n    sub<span class=\"token punctuation\">(</span><span class=\"token string\">r\"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token keyword\">lambda</span> mo<span class=\"token punctuation\">:</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">kebab<span class=\"token punctuation\">(</span><span class=\"token string\">'camelCase'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'camel-case'</span>\nkebab<span class=\"token punctuation\">(</span><span class=\"token string\">'some text'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'some-text'</span>\nkebab<span class=\"token punctuation\">(</span><span class=\"token string\">'some-mixed_string With spaces_underscores-and-hyphens'</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># 'some-mixed-string-with-spaces-underscores-and-hyphens'</span>\nkebab<span class=\"token punctuation\">(</span><span class=\"token string\">'AllThe-small Things'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'all-the-small-things'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the given key exists in a dictionary</h3>\n<ul>\n<li>Use the <code class=\"language-text\">in</code> operator to check if <code class=\"language-text\">d</code> contains <code class=\"language-text\">key</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">key_in_dict</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>key <span class=\"token keyword\">in</span> d<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">d <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'five'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'four'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\nkey_in_dict<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the key of the maximum value in a dictionary</h3>\n<ul>\n<li>Use <code class=\"language-text\">max()</code> with the <code class=\"language-text\">key</code> parameter set to <code class=\"language-text\">dict.get()</code> to find and return the key of the maximum value in the given dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">key_of_max</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> key <span class=\"token operator\">=</span> d<span class=\"token punctuation\">.</span>get<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">key_of_max<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span><span class=\"token number\">13</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># c</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the key of the minimum value in a dictionary</h3>\n<ul>\n<li>Use <code class=\"language-text\">min()</code> with the <code class=\"language-text\">key</code> parameter set to <code class=\"language-text\">dict.get()</code> to find and return the key of the minimum value in the given dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">key_of_min</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> key <span class=\"token operator\">=</span> d<span class=\"token punctuation\">.</span>get<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">key_of_min<span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span><span class=\"token number\">13</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># b</span></code></pre></div>\n<hr>\n<hr>\n<h3>Creates a flat list of all the keys in a flat dictionary</h3>\n<ul>\n<li>Use <code class=\"language-text\">dict.keys()</code> to return the keys in the given dictionary.</li>\n<li>Return a <code class=\"language-text\">list()</code> of the previous result.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">keys_only</span><span class=\"token punctuation\">(</span>flat_dict<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>flat_dict<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">ages <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'Peter'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Isabel'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Anna'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\nkeys_only<span class=\"token punctuation\">(</span>ages<span class=\"token punctuation\">)</span> <span class=\"token comment\"># ['Peter', 'Isabel', 'Anna']</span></code></pre></div>\n<hr>\n<h2>unlisted: true</h2>\n<p>Converts kilometers to miles.</p>\n<ul>\n<li>Follows the conversion formula <code class=\"language-text\">mi = km * 0.621371</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">km_to_miles</span><span class=\"token punctuation\">(</span>km<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> km <span class=\"token operator\">*</span> <span class=\"token number\">0.621371</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">km_to_miles<span class=\"token punctuation\">(</span><span class=\"token number\">8.1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 5.0331051</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the last element in a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">lst[-1]</code> to return the last element of the passed list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">last</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> lst<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">last<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 3</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the least common multiple of a list of numbers</h3>\n<ul>\n<li>Use <code class=\"language-text\">functools.reduce()</code>, <code class=\"language-text\">math.gcd()</code> and <code class=\"language-text\">lcm(x,y) = x * y / gcd(x,y)</code> over the given list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> functools <span class=\"token keyword\">import</span> <span class=\"token builtin\">reduce</span>\n<span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> gcd\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">lcm</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">:</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>x <span class=\"token operator\">*</span> y <span class=\"token operator\">/</span> gcd<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> numbers<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">lcm<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 84</span>\nlcm<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 60</span></code></pre></div>\n<hr>\n<hr>\n<h3>Takes any number of iterable objects or objects with a length property and returns the longest one</h3>\n<ul>\n<li>Use <code class=\"language-text\">max()</code> with <code class=\"language-text\">len()</code> as the <code class=\"language-text\">key</code> to return the item with the greatest length.</li>\n<li>If multiple objects have the same length, the first one will be returned.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">longest_item</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">,</span> key <span class=\"token operator\">=</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">longest_item<span class=\"token punctuation\">(</span><span class=\"token string\">'this'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'testcase'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'testcase'</span>\nlongest_item<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3, 4, 5]</span>\nlongest_item<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'foobar'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'foobar'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Maps the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value</h3>\n<ul>\n<li>Use <code class=\"language-text\">map()</code> to apply <code class=\"language-text\">fn</code> to each value of the list.</li>\n<li>Use <code class=\"language-text\">zip()</code> to pair original values to the values produced by <code class=\"language-text\">fn</code>.</li>\n<li>Use <code class=\"language-text\">dict()</code> to return an appropriate dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">map_dictionary</span><span class=\"token punctuation\">(</span>itr<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>itr<span class=\"token punctuation\">,</span> <span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> itr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">map_dictionary<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">*</span> x<span class=\"token punctuation\">)</span> <span class=\"token comment\"># { 1: 1, 2: 4, 3: 9 }</span></code></pre></div>\n<hr>\n<hr>\n<h3>Creates a dictionary with the same keys as the provided dictionary and values generated by running the provided function for each value</h3>\n<ul>\n<li>Use <code class=\"language-text\">dict.items()</code> to iterate over the dictionary, assigning the values produced by <code class=\"language-text\">fn</code> to each key of a new dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">map_values</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">users <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'fred'</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'user'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'fred'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">40</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'pebbles'</span><span class=\"token punctuation\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'user'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'pebbles'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nmap_values<span class=\"token punctuation\">(</span>users<span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> u <span class=\"token punctuation\">:</span> u<span class=\"token punctuation\">[</span><span class=\"token string\">'age'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># {'fred': 40, 'pebbles': 1}</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the maximum value of a list, after mapping each element to a value using the provided function</h3>\n<ul>\n<li>Use <code class=\"language-text\">map()</code> with <code class=\"language-text\">fn</code> to map each element to a value using the provided function.</li>\n<li>Use <code class=\"language-text\">max()</code> to return the maximum value.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">max_by</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">max_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">8</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">6</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> v <span class=\"token punctuation\">:</span> v<span class=\"token punctuation\">[</span><span class=\"token string\">'n'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 8</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the index of the element with the maximum value in a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">max()</code> and <code class=\"language-text\">list.index()</code> to get the maximum value in the list and return its index.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">max_element_index</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span><span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">max_element_index<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 4</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the <code class=\"language-text\">n</code> maximum elements from the provided list</h3>\n<ul>\n<li>Use <code class=\"language-text\">sorted()</code> to sort the list.</li>\n<li>Use slice notation to get the specified number of elements.</li>\n<li>Omit the second argument, <code class=\"language-text\">n</code>, to get a one-element list.</li>\n<li>If <code class=\"language-text\">n</code> is greater than or equal to the provided list's length, then return the original list (sorted in descending order).</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">max_n</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> reverse <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>n<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">max_n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3]</span>\nmax_n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3, 2]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Finds the median of a list of numbers</h3>\n<ul>\n<li>Sort the numbers of the list using <code class=\"language-text\">list.sort()</code>.</li>\n<li>Find the median, which is either the middle element of the list if the list length is odd or the average of the two middle elements if the list length is even.</li>\n<li><a href=\"https://docs.python.org/3/library/statistics.html#statistics.median\"><code class=\"language-text\">statistics.median()</code></a> provides similar functionality to this snippet.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">median</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token builtin\">list</span><span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  list_length <span class=\"token operator\">=</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">if</span> list_length <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">[</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>list_length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">[</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>list_length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">[</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>list_length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">median<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2.0</span>\nmedian<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2.5</span></code></pre></div>\n<hr>\n<hr>\n<h3>Merges two or more lists into a list of lists, combining elements from each of the input lists based on their positions</h3>\n<ul>\n<li>Use <code class=\"language-text\">max()</code> combined with a list comprehension to get the length of the longest list in the arguments.</li>\n<li>Use <code class=\"language-text\">range()</code> in combination with the <code class=\"language-text\">max_length</code> variable to loop as many times as there are elements in the longest list.</li>\n<li>If a list is shorter than <code class=\"language-text\">max_length</code>, use <code class=\"language-text\">fill_value</code> for the remaining items (defaults to <code class=\"language-text\">None</code>).</li>\n<li><a href=\"https://docs.python.org/3/library/functions.html#zip\"><code class=\"language-text\">zip()</code></a> and <a href=\"https://docs.python.org/3/library/itertools.html#itertools.zip_longest\"><code class=\"language-text\">itertools.zip_longest()</code></a> provide similar functionality to this snippet.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> fill_value <span class=\"token operator\">=</span> <span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  max_length <span class=\"token operator\">=</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> lst <span class=\"token keyword\">in</span> args<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n  result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n  <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>max_length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    result<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>\n      args<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token keyword\">if</span> i <span class=\"token operator\">&lt;</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">else</span> fill_value <span class=\"token keyword\">for</span> k <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> result</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">merge<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [['a', 1, True], ['b', 2, False]]</span>\nmerge<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [['a', 1, True], [None, 2, False]]</span>\nmerge<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> fill_value <span class=\"token operator\">=</span> <span class=\"token string\">'_'</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># [['a', 1, True], ['_', 2, False]]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Merges two or more dictionaries</h3>\n<ul>\n<li>Create a new <code class=\"language-text\">dict</code> and loop over <code class=\"language-text\">dicts</code>, using <code class=\"language-text\">dictionary.update()</code> to add the key-value pairs from each one to the result.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">merge_dictionaries</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>dicts<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  res <span class=\"token operator\">=</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">for</span> d <span class=\"token keyword\">in</span> dicts<span class=\"token punctuation\">:</span>\n    res<span class=\"token punctuation\">.</span>update<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> res</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">ages_one <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'Peter'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Isabel'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\nages_two <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'Anna'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span>\n<span class=\"token punctuation\">}</span>\nmerge_dictionaries<span class=\"token punctuation\">(</span>ages_one<span class=\"token punctuation\">,</span> ages_two<span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># { 'Peter': 10, 'Isabel': 11, 'Anna': 9 }</span></code></pre></div>\n<hr>\n<h2>unlisted: true</h2>\n<p>Converts miles to kilometers.</p>\n<ul>\n<li>Follows the conversion formula <code class=\"language-text\">km = mi * 1.609344</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">miles_to_km</span><span class=\"token punctuation\">(</span>miles<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> miles <span class=\"token operator\">*</span> <span class=\"token number\">1.609344</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">miles_to_km<span class=\"token punctuation\">(</span><span class=\"token number\">5.03</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 8.09500032</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the minimum value of a list, after mapping each element to a value using the provided function</h3>\n<ul>\n<li>Use <code class=\"language-text\">map()</code> with <code class=\"language-text\">fn</code> to map each element to a value using the provided function.</li>\n<li>Use <code class=\"language-text\">min()</code> to return the minimum value.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">min_by</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">min_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">8</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">6</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> v <span class=\"token punctuation\">:</span> v<span class=\"token punctuation\">[</span><span class=\"token string\">'n'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the index of the element with the minimum value in a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">min()</code> and <code class=\"language-text\">list.index()</code> to obtain the minimum value in the list and then return its index.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">min_element_index</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span><span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">min_element_index<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the <code class=\"language-text\">n</code> minimum elements from the provided list</h3>\n<ul>\n<li>Use <code class=\"language-text\">sorted()</code> to sort the list.</li>\n<li>Use slice notation to get the specified number of elements.</li>\n<li>Omit the second argument, <code class=\"language-text\">n</code>, to get a one-element list.</li>\n<li>If <code class=\"language-text\">n</code> is greater than or equal to the provided list's length, then return the original list (sorted in ascending order).</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">min_n</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> reverse <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>n<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">min_n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1]</span>\nmin_n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the month difference between two dates</h3>\n<ul>\n<li>Subtract <code class=\"language-text\">start</code> from <code class=\"language-text\">end</code> and use <code class=\"language-text\">datetime.timedelta.days</code> to get the day difference.</li>\n<li>Divide by <code class=\"language-text\">30</code> and use <code class=\"language-text\">math.ceil()</code> to get the difference in months (rounded up).</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> ceil\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">months_diff</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> ceil<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>end <span class=\"token operator\">-</span> start<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>days <span class=\"token operator\">/</span> <span class=\"token number\">30</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> date\n\nmonths_diff<span class=\"token punctuation\">(</span>date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">28</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> date<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 1</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the most frequent element in a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">set()</code> to get the unique values in <code class=\"language-text\">lst</code>.</li>\n<li>Use <code class=\"language-text\">max()</code> to find the element that has the most appearances.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">most_frequent</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> key <span class=\"token operator\">=</span> lst<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">most_frequent<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">#2</span></code></pre></div>\n<hr>\n<hr>\n<h3>Generates a string with the given string value repeated <code class=\"language-text\">n</code> number of times</h3>\n<ul>\n<li>Repeat the string <code class=\"language-text\">n</code> times, using the <code class=\"language-text\">*</code> operator.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">n_times_string</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>s <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">n_times_string<span class=\"token punctuation\">(</span><span class=\"token string\">'py'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">#'pypypypy'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the provided function returns <code class=\"language-text\">True</code> for at least one element in the list</h3>\n<ul>\n<li>Use <code class=\"language-text\">all()</code> and <code class=\"language-text\">fn</code> to check if <code class=\"language-text\">fn</code> returns <code class=\"language-text\">False</code> for all the elements in the list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">none</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">all</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">not</span> fn<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">none<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">>=</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">)</span> <span class=\"token comment\"># False</span>\nnone<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Maps a number from one range to another range</h3>\n<ul>\n<li>Return <code class=\"language-text\">num</code> mapped between <code class=\"language-text\">outMin</code>-<code class=\"language-text\">outMax</code> from <code class=\"language-text\">inMin</code>-<code class=\"language-text\">inMax</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">num_to_range</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">,</span> inMin<span class=\"token punctuation\">,</span> inMax<span class=\"token punctuation\">,</span> outMin<span class=\"token punctuation\">,</span> outMax<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> outMin <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span>num <span class=\"token operator\">-</span> inMin<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span>inMax <span class=\"token operator\">-</span> inMin<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>outMax\n                  <span class=\"token operator\">-</span> outMin<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">num_to_range<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 50.0</span></code></pre></div>\n<hr>\n<hr>\n<h3>Moves the specified amount of elements to the end of the list</h3>\n<ul>\n<li>Use slice notation to get the two slices of the list and combine them before returning.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">offset</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> offset<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> lst<span class=\"token punctuation\">[</span>offset<span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> lst<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>offset<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">offset<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3, 4, 5, 1, 2]</span>\noffset<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [4, 5, 1, 2, 3]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Pads a string on both sides with the specified character, if it's shorter than the specified length</h3>\n<ul>\n<li>Use <code class=\"language-text\">str.ljust()</code> and <code class=\"language-text\">str.rjust()</code> to pad both sides of the given string.</li>\n<li>Omit the third argument, <code class=\"language-text\">char</code>, to use the whitespace character as the default padding character.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> floor\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">pad</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> length<span class=\"token punctuation\">,</span> char <span class=\"token operator\">=</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> s<span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span>floor<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> length<span class=\"token punctuation\">)</span><span class=\"token operator\">/</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> char<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>ljust<span class=\"token punctuation\">(</span>length<span class=\"token punctuation\">,</span> char<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">pad<span class=\"token punctuation\">(</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># '  cat   '</span>\npad<span class=\"token punctuation\">(</span><span class=\"token string\">'42'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># '004200'</span>\npad<span class=\"token punctuation\">(</span><span class=\"token string\">'foobar'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'foobar'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Pads a given number to the specified length</h3>\n<ul>\n<li>Use <code class=\"language-text\">str.zfill()</code> to pad the number to the specified length, after converting it to a string.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">pad_number</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>zfill<span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">pad_number<span class=\"token punctuation\">(</span><span class=\"token number\">1234</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\"># '001234'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the given string is a palindrome</h3>\n<ul>\n<li>Use <code class=\"language-text\">str.lower()</code> and <code class=\"language-text\">re.sub()</code> to convert to lowercase and remove non-alphanumeric characters from the given string.</li>\n<li>Then, compare the new string with its reverse, using slice notation.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> re <span class=\"token keyword\">import</span> sub\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">palindrome</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  s <span class=\"token operator\">=</span> sub<span class=\"token punctuation\">(</span><span class=\"token string\">'[\\W_]'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> s <span class=\"token operator\">==</span> s<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">palindrome<span class=\"token punctuation\">(</span><span class=\"token string\">'taco cat'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a list of dictionaries into a list of values corresponding to the specified <code class=\"language-text\">key</code></h3>\n<ul>\n<li>Use a list comprehension and <code class=\"language-text\">dict.get()</code> to get the value of <code class=\"language-text\">key</code> for each dictionary in <code class=\"language-text\">lst</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">pluck</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">.</span>get<span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> lst<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">simpsons <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'lisa'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">8</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'homer'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">36</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'marge'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">34</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'bart'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span>\npluck<span class=\"token punctuation\">(</span>simpsons<span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [8, 36, 34, 10]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the powerset of a given iterable</h3>\n<ul>\n<li>Use <code class=\"language-text\">list()</code> to convert the given value to a list.</li>\n<li>Use <code class=\"language-text\">range()</code> and <code class=\"language-text\">itertools.combinations()</code> to create a generator that returns all subsets.</li>\n<li>Use <code class=\"language-text\">itertools.chain.from_iterable()</code> and <code class=\"language-text\">list()</code> to consume the generator and return a list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> itertools <span class=\"token keyword\">import</span> chain<span class=\"token punctuation\">,</span> combinations\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">powerset</span><span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  s <span class=\"token operator\">=</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>chain<span class=\"token punctuation\">.</span>from_iterable<span class=\"token punctuation\">(</span>combinations<span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> r <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">powerset<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [(), (1,), (2,), (1, 2)]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts an angle from radians to degrees</h3>\n<ul>\n<li>Use <code class=\"language-text\">math.pi</code> and the radian to degree formula to convert the angle from radians to degrees.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> pi\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">rads_to_degrees</span><span class=\"token punctuation\">(</span>rad<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>rad <span class=\"token operator\">*</span> <span class=\"token number\">180.0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> pi</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> pi\n\nrads_to_degrees<span class=\"token punctuation\">(</span>pi <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 90.0</span></code></pre></div>\n<hr>\n<hr>\n<h3>Reverses a list or a string</h3>\n<ul>\n<li>Use slice notation to reverse the list or string.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span>itr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> itr<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">reverse<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3, 2, 1]</span>\nreverse<span class=\"token punctuation\">(</span><span class=\"token string\">'snippet'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'teppins'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Reverses a number</h3>\n<ul>\n<li>Use <code class=\"language-text\">str()</code> to convert the number to a string, slice notation to reverse it and <code class=\"language-text\">str.replace()</code> to remove the sign.</li>\n<li>Use <code class=\"language-text\">float()</code> to convert the result to a number and <code class=\"language-text\">math.copysign()</code> to copy the original sign.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> copysign\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">reverse_number</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> copysign<span class=\"token punctuation\">(</span><span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>replace<span class=\"token punctuation\">(</span><span class=\"token string\">'-'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">reverse_number<span class=\"token punctuation\">(</span><span class=\"token number\">981</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 189</span>\nreverse_number<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">500</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># -5</span>\nreverse_number<span class=\"token punctuation\">(</span><span class=\"token number\">73.6</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 6.37</span>\nreverse_number<span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">5.23</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># -32.5</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts the values of RGB components to a hexadecimal color code</h3>\n<ul>\n<li>Create a placeholder for a zero-padded hexadecimal value using <code class=\"language-text\">'{:02X}'</code> and copy it three times.</li>\n<li>Use <code class=\"language-text\">str.format()</code> on the resulting string to replace the placeholders with the given values.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">rgb_to_hex</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">,</span> g<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'{:02X}'</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">,</span> g<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">rgb_to_hex<span class=\"token punctuation\">(</span><span class=\"token number\">255</span><span class=\"token punctuation\">,</span> <span class=\"token number\">165</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'FFA501'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Moves the specified amount of elements to the start of the list</h3>\n<ul>\n<li>Use slice notation to get the two slices of the list and combine them before returning.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">roll</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> offset<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> lst<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span>offset<span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> lst<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span>offset<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">roll<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [4, 5, 1, 2, 3]</span>\nroll<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3, 4, 5, 1, 2]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a random element from a list</h3>\n<ul>\n<li>Use <code class=\"language-text\">random.choice()</code> to get a random element from <code class=\"language-text\">lst</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> random <span class=\"token keyword\">import</span> choice\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">sample</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> choice<span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">sample<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 9</span></code></pre></div>\n<hr>\n<hr>\n<h3>Randomizes the order of the values of an list, returning a new list</h3>\n<ul>\n<li>Uses the <a href=\"https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\">Fisher-Yates algorithm</a> to reorder the elements of the list.</li>\n<li><a href=\"https://docs.python.org/3/library/random.html#random.shuffle\"><code class=\"language-text\">random.shuffle</code></a> provides similar functionality to this snippet.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> copy <span class=\"token keyword\">import</span> deepcopy\n<span class=\"token keyword\">from</span> random <span class=\"token keyword\">import</span> randint\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">shuffle</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  temp_lst <span class=\"token operator\">=</span> deepcopy<span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span>\n  m <span class=\"token operator\">=</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>temp_lst<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    m <span class=\"token operator\">-=</span> <span class=\"token number\">1</span>\n    i <span class=\"token operator\">=</span> randint<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span>\n    temp_lst<span class=\"token punctuation\">[</span>m<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> temp_lst<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> temp_lst<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> temp_lst<span class=\"token punctuation\">[</span>m<span class=\"token punctuation\">]</span>\n  <span class=\"token keyword\">return</span> temp_lst</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">foo <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\nshuffle<span class=\"token punctuation\">(</span>foo<span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2, 3, 1], foo = [1, 2, 3]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a list of elements that exist in both lists</h3>\n<ul>\n<li>Use a list comprehension on <code class=\"language-text\">a</code> to only keep values contained in both lists.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">similarity</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> a <span class=\"token keyword\">if</span> item <span class=\"token keyword\">in</span> b<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">similarity<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a string to a URL-friendly slug</h3>\n<ul>\n<li>Use <code class=\"language-text\">str.lower()</code> and <code class=\"language-text\">str.strip()</code> to normalize the input string.</li>\n<li>Use <code class=\"language-text\">re.sub()</code> to to replace spaces, dashes and underscores with <code class=\"language-text\">-</code> and remove special characters.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">import</span> re\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">slugify</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  s <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  s <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span>sub<span class=\"token punctuation\">(</span><span class=\"token string\">r'[^\\w\\s-]'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">)</span>\n  s <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span>sub<span class=\"token punctuation\">(</span><span class=\"token string\">r'[\\s_-]+'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'-'</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">)</span>\n  s <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span>sub<span class=\"token punctuation\">(</span><span class=\"token string\">r'^-+|-+$'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> s</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">slugify<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello World!'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'hello-world'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a string to snake case</h3>\n<ul>\n<li>Use <code class=\"language-text\">re.sub()</code> to match all words in the string, <code class=\"language-text\">str.lower()</code> to lowercase them.</li>\n<li>Use <code class=\"language-text\">re.sub()</code> to replace any <code class=\"language-text\">-</code> characters with spaces.</li>\n<li>Finally, use <code class=\"language-text\">str.join()</code> to combine all words using <code class=\"language-text\">-</code> as the separator.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> re <span class=\"token keyword\">import</span> sub\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">snake</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token string\">'_'</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span>\n    sub<span class=\"token punctuation\">(</span><span class=\"token string\">'([A-Z][a-z]+)'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">r' \\1'</span><span class=\"token punctuation\">,</span>\n    sub<span class=\"token punctuation\">(</span><span class=\"token string\">'([A-Z]+)'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">r' \\1'</span><span class=\"token punctuation\">,</span>\n    s<span class=\"token punctuation\">.</span>replace<span class=\"token punctuation\">(</span><span class=\"token string\">'-'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">snake<span class=\"token punctuation\">(</span><span class=\"token string\">'camelCase'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'camel_case'</span>\nsnake<span class=\"token punctuation\">(</span><span class=\"token string\">'some text'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'some_text'</span>\nsnake<span class=\"token punctuation\">(</span><span class=\"token string\">'some-mixed_string With spaces_underscores-and-hyphens'</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># 'some_mixed_string_with_spaces_underscores_and_hyphens'</span>\nsnake<span class=\"token punctuation\">(</span><span class=\"token string\">'AllThe-small Things'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'all_the_small_things'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Checks if the provided function returns <code class=\"language-text\">True</code> for at least one element in the list</h3>\n<ul>\n<li>Use <code class=\"language-text\">any()</code> in combination with <code class=\"language-text\">map()</code> to check if <code class=\"language-text\">fn</code> returns <code class=\"language-text\">True</code> for any element in the list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">some</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">any</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">some<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">>=</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span>\nsome<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># True</span></code></pre></div>\n<hr>\n<hr>\n<h3>Sorts one list based on another list containing the desired indexes</h3>\n<ul>\n<li>Use <code class=\"language-text\">zip()</code> and <code class=\"language-text\">sorted()</code> to combine and sort the two lists, based on the values of <code class=\"language-text\">indexes</code>.</li>\n<li>Use a list comprehension to get the first element of each pair from the result.</li>\n<li>Use the <code class=\"language-text\">reverse</code> parameter in <code class=\"language-text\">sorted()</code> to sort the dictionary in reverse order, based on the third argument.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">sort_by_indexes</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> indexes<span class=\"token punctuation\">,</span> reverse<span class=\"token operator\">=</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>val <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">,</span> val<span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>indexes<span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> key<span class=\"token operator\">=</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> \\\n          x<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> reverse<span class=\"token operator\">=</span>reverse<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'eggs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bread'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'oranges'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'jam'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'apples'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'milk'</span><span class=\"token punctuation\">]</span>\nb <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\nsort_by_indexes<span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span> <span class=\"token comment\"># ['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges']</span>\nsort_by_indexes<span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># ['oranges', 'milk', 'jam', 'eggs', 'bread', 'apples']</span></code></pre></div>\n<hr>\n<hr>\n<h3>Sorts the given dictionary by key</h3>\n<ul>\n<li>Use <code class=\"language-text\">dict.items()</code> to get a list of tuple pairs from <code class=\"language-text\">d</code> and sort it using <code class=\"language-text\">sorted()</code>.</li>\n<li>Use <code class=\"language-text\">dict()</code> to convert the sorted list back to a dictionary.</li>\n<li>Use the <code class=\"language-text\">reverse</code> parameter in <code class=\"language-text\">sorted()</code> to sort the dictionary in reverse order, based on the second argument.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">sort_dict_by_key</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> reverse <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> reverse <span class=\"token operator\">=</span> reverse<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">d <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'five'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'four'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\nsort_dict_by_key<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span> <span class=\"token comment\"># {'five': 5, 'four': 4, 'one': 1, 'three': 3, 'two': 2}</span>\nsort_dict_by_key<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># {'two': 2, 'three': 3, 'one': 1, 'four': 4, 'five': 5}</span></code></pre></div>\n<hr>\n<hr>\n<h3>Sorts the given dictionary by value</h3>\n<ul>\n<li>Use <code class=\"language-text\">dict.items()</code> to get a list of tuple pairs from <code class=\"language-text\">d</code> and sort it using a lambda function and <code class=\"language-text\">sorted()</code>.</li>\n<li>Use <code class=\"language-text\">dict()</code> to convert the sorted list back to a dictionary.</li>\n<li>Use the <code class=\"language-text\">reverse</code> parameter in <code class=\"language-text\">sorted()</code> to sort the dictionary in reverse order, based on the second argument.</li>\n<li><strong>⚠️ NOTICE:</strong> Dictionary values must be of the same type.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">sort_dict_by_value</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> reverse <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> key <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> reverse <span class=\"token operator\">=</span> reverse<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">d <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'three'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'five'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'four'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\nsort_dict_by_value<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span> <span class=\"token comment\"># {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}</span>\nsort_dict_by_value<span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># {'five': 5, 'four': 4, 'three': 3, 'two': 2, 'one': 1}</span></code></pre></div>\n<hr>\n<hr>\n<h3>Splits a multiline string into a list of lines</h3>\n<ul>\n<li>Use <code class=\"language-text\">str.split()</code> and <code class=\"language-text\">'\\n'</code> to match line breaks and create a list.</li>\n<li><a href=\"https://docs.python.org/3/library/stdtypes.html#str.splitlines\"><code class=\"language-text\">str.splitlines()</code></a> provides similar functionality to this snippet.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">split_lines</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> s<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token string\">'\\n'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">split_lines<span class=\"token punctuation\">(</span><span class=\"token string\">'This\\nis a\\nmultiline\\nstring.\\n'</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># ['This', 'is a', 'multiline', 'string.' , '']</span></code></pre></div>\n<hr>\n<hr>\n<h3>Flattens a list, by spreading its elements into a new list</h3>\n<ul>\n<li>Loop over elements, use <code class=\"language-text\">list.extend()</code> if the element is a list, <code class=\"language-text\">list.append()</code> otherwise.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">spread</span><span class=\"token punctuation\">(</span>arg<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  ret <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n  <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> arg<span class=\"token punctuation\">:</span>\n    ret<span class=\"token punctuation\">.</span>extend<span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> <span class=\"token builtin\">isinstance</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">else</span> ret<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> ret</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">spread<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">7</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3, 4, 5, 6, 7, 8, 9]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Calculates the sum of a list, after mapping each element to a value using the provided function</h3>\n<ul>\n<li>Use <code class=\"language-text\">map()</code> with <code class=\"language-text\">fn</code> to map each element to a value using the provided function.</li>\n<li>Use <code class=\"language-text\">sum()</code> to return the sum of the values.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum_by</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">sum_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">8</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">6</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> v <span class=\"token punctuation\">:</span> v<span class=\"token punctuation\">[</span><span class=\"token string\">'n'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 20</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the sum of the powers of all the numbers from <code class=\"language-text\">start</code> to <code class=\"language-text\">end</code> (both inclusive)</h3>\n<ul>\n<li>Use <code class=\"language-text\">range()</code> in combination with a list comprehension to create a list of elements in the desired range raised to the given <code class=\"language-text\">power</code>.</li>\n<li>Use <code class=\"language-text\">sum()</code> to add the values together.</li>\n<li>Omit the second argument, <code class=\"language-text\">power</code>, to use a default power of <code class=\"language-text\">2</code>.</li>\n<li>Omit the third argument, <code class=\"language-text\">start</code>, to use a default starting value of <code class=\"language-text\">1</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum_of_powers</span><span class=\"token punctuation\">(</span>end<span class=\"token punctuation\">,</span> power <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> start <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">**</span> power <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">sum_of_powers<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 385</span>\nsum_of_powers<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 3025</span>\nsum_of_powers<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2925</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the symmetric difference between two iterables, without filtering out duplicate values</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code> from each list.</li>\n<li>Use a list comprehension on each of them to only keep values not contained in the previously created set of the other.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">symmetric_difference</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token punctuation\">(</span>_a<span class=\"token punctuation\">,</span> _b<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> a <span class=\"token keyword\">if</span> item <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> _b<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> b\n          <span class=\"token keyword\">if</span> item <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> _a<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">symmetric_difference<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3, 4]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the symmetric difference between two lists, after applying the provided function to each list element of both</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code> by applying <code class=\"language-text\">fn</code> to each element in every list.</li>\n<li>Use a list comprehension in combination with <code class=\"language-text\">fn</code> on each of them to only keep values not contained in the previously created set of the other.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">symmetric_difference_by</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token punctuation\">(</span>_a<span class=\"token punctuation\">,</span> _b<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> a <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> _b<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span>item\n          <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> b <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> _a<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> floor\n\nsymmetric_difference_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2.1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1.2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2.3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3.4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> floor<span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1.2, 3.4]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns all elements in a list except for the first one</h3>\n<ul>\n<li>Use slice notation to return the last element if the list's length is more than <code class=\"language-text\">1</code>.</li>\n<li>Otherwise, return the whole list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">tail</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> lst<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span> <span class=\"token keyword\">if</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token keyword\">else</span> lst</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">tail<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2, 3]</span>\ntail<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a list with <code class=\"language-text\">n</code> elements removed from the beginning</h3>\n<ul>\n<li>Use slice notation to create a slice of the list with <code class=\"language-text\">n</code> elements taken from the beginning.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">take</span><span class=\"token punctuation\">(</span>itr<span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> itr<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span>n<span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">take<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3]</span>\ntake<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># []</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a list with <code class=\"language-text\">n</code> elements removed from the end</h3>\n<ul>\n<li>Use slice notation to create a slice of the list with <code class=\"language-text\">n</code> elements taken from the end.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">take_right</span><span class=\"token punctuation\">(</span>itr<span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> itr<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span>n<span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">take_right<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2, 3]</span>\ntake_right<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [3]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the binary representation of the given number</h3>\n<ul>\n<li>Use <code class=\"language-text\">bin()</code> to convert a given decimal number into its binary equivalent.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">to_binary</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">bin</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">to_binary<span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 0b1100100</span></code></pre></div>\n<hr>\n<hr>\n<h3>Combines two lists into a dictionary, where the elements of the first one serve as the keys and the elements of the second one serve as the values</h3>\n<p>The values of the first list need to be unique and hashable.</p>\n<ul>\n<li>Use <code class=\"language-text\">zip()</code> in combination with <code class=\"language-text\">dict()</code> to combine the values of the two lists into a dictionary.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">to_dictionary</span><span class=\"token punctuation\">(</span>keys<span class=\"token punctuation\">,</span> values<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>keys<span class=\"token punctuation\">,</span> values<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">to_dictionary<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># { a: 1, b: 2 }</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the hexadecimal representation of the given number</h3>\n<ul>\n<li>Use <code class=\"language-text\">hex()</code> to convert a given decimal number into its hexadecimal equivalent.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">to_hex</span><span class=\"token punctuation\">(</span>dec<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">hex</span><span class=\"token punctuation\">(</span>dec<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">to_hex<span class=\"token punctuation\">(</span><span class=\"token number\">41</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 0x29</span>\nto_hex<span class=\"token punctuation\">(</span><span class=\"token number\">332</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 0x14c</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a date to its ISO-8601 representation</h3>\n<ul>\n<li>Use <code class=\"language-text\">datetime.datetime.isoformat()</code> to convert the given <code class=\"language-text\">datetime.datetime</code> object to an ISO-8601 date.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> datetime\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">to_iso_date</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> d<span class=\"token punctuation\">.</span>isoformat<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> datetime <span class=\"token keyword\">import</span> datetime\n\nto_iso_date<span class=\"token punctuation\">(</span>datetime<span class=\"token punctuation\">(</span><span class=\"token number\">2020</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">25</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 2020-10-25T00:00:00</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts an integer to its roman numeral representation</h3>\n<p>Accepts value between <code class=\"language-text\">1</code> and <code class=\"language-text\">3999</code> (both inclusive).</p>\n<ul>\n<li>Create a lookup list containing tuples in the form of (roman value, integer).</li>\n<li>Use a <code class=\"language-text\">for</code> loop to iterate over the values in <code class=\"language-text\">lookup</code>.</li>\n<li>Use <code class=\"language-text\">divmod()</code> to update <code class=\"language-text\">num</code> with the remainder, adding the roman numeral representation to the result.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">to_roman_numeral</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  lookup <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">1000</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'M'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">900</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'CM'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">500</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'D'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">400</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'CD'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'XC'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">50</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'L'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">40</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'XL'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'X'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'IX'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'V'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'IV'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'I'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">]</span>\n  res <span class=\"token operator\">=</span> <span class=\"token string\">''</span>\n  <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> roman<span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> lookup<span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> num<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span> <span class=\"token builtin\">divmod</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span>\n    res <span class=\"token operator\">+=</span> roman <span class=\"token operator\">*</span> d\n  <span class=\"token keyword\">return</span> res</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">to_roman_numeral<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'III'</span>\nto_roman_numeral<span class=\"token punctuation\">(</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'XI'</span>\nto_roman_numeral<span class=\"token punctuation\">(</span><span class=\"token number\">1998</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 'MCMXCVIII'</span></code></pre></div>\n<hr>\n<hr>\n<h3>Transposes a two-dimensional list</h3>\n<ul>\n<li>Use <code class=\"language-text\">*lst</code> to get the provided list as tuples.</li>\n<li>Use <code class=\"language-text\">zip()</code> in combination with <code class=\"language-text\">list()</code> to create the transpose of the given two-dimensional list.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">transpose</span><span class=\"token punctuation\">(</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>lst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">transpose<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span> <span class=\"token number\">12</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># [(1, 4, 7, 10), (2, 5, 8, 11), (3, 6, 9, 12)]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Builds a list, using an iterator function and an initial seed value</h3>\n<ul>\n<li>The iterator function accepts one argument (<code class=\"language-text\">seed</code>) and must always return a list with two elements ([<code class=\"language-text\">value</code>, <code class=\"language-text\">nextSeed</code>]) or <code class=\"language-text\">False</code> to terminate.</li>\n<li>Use a generator function, <code class=\"language-text\">fn_generator</code>, that uses a <code class=\"language-text\">while</code> loop to call the iterator function and <code class=\"language-text\">yield</code> the <code class=\"language-text\">value</code> until it returns <code class=\"language-text\">False</code>.</li>\n<li>Use a list comprehension to return the list that is produced by the generator, using the iterator function.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">unfold</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> seed<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">def</span> <span class=\"token function\">fn_generator</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n      val <span class=\"token operator\">=</span> fn<span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n      <span class=\"token keyword\">if</span> val <span class=\"token operator\">==</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span> <span class=\"token keyword\">break</span>\n      <span class=\"token keyword\">yield</span> val<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>i <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> fn_generator<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> seed<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">f <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> n<span class=\"token punctuation\">:</span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">if</span> n <span class=\"token operator\">></span> <span class=\"token number\">50</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">-</span>n<span class=\"token punctuation\">,</span> n <span class=\"token operator\">+</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span>\nunfold<span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [-10, -20, -30, -40, -50]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns every element that exists in any of the two lists once</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code> with all values of <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> and convert to a <code class=\"language-text\">list</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">union</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">union<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3, 4]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns every element that exists in any of the two lists once, after applying the provided function to each element of both</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code> by applying <code class=\"language-text\">fn</code> to each element in <code class=\"language-text\">a</code>.</li>\n<li>Use a list comprehension in combination with <code class=\"language-text\">fn</code> on <code class=\"language-text\">b</code> to only keep values not contained in the previously created set, <code class=\"language-text\">_a</code>.</li>\n<li>Finally, create a <code class=\"language-text\">set</code> from the previous result and <code class=\"language-text\">a</code> and transform it into a <code class=\"language-text\">list</code></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">union_by</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  _a <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">map</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span>item <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> b <span class=\"token keyword\">if</span> fn<span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> _a<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> math <span class=\"token keyword\">import</span> floor\n\nunion_by<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2.1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1.2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2.3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> floor<span class=\"token punctuation\">)</span> <span class=\"token comment\"># [2.1, 1.2]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the unique elements in a given list</h3>\n<ul>\n<li>Create a <code class=\"language-text\">set</code> from the list to discard duplicated values, then return a <code class=\"language-text\">list</code> from it.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">unique_elements</span><span class=\"token punctuation\">(</span>li<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span>li<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">unique_elements<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># [1, 2, 3, 4]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns a flat list of all the values in a flat dictionary</h3>\n<ul>\n<li>Use <code class=\"language-text\">dict.values()</code> to return the values in the given dictionary.</li>\n<li>Return a <code class=\"language-text\">list()</code> of the previous result.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">values_only</span><span class=\"token punctuation\">(</span>flat_dict<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>flat_dict<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">ages <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token string\">'Peter'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Isabel'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">11</span><span class=\"token punctuation\">,</span>\n  <span class=\"token string\">'Anna'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span>\nvalues_only<span class=\"token punctuation\">(</span>ages<span class=\"token punctuation\">)</span> <span class=\"token comment\"># [10, 11, 9]</span></code></pre></div>\n<hr>\n<hr>\n<h3>Returns the weighted average of two or more numbers</h3>\n<ul>\n<li>Use <code class=\"language-text\">sum()</code> to sum the products of the numbers by their weight and to sum the weights.</li>\n<li>Use <code class=\"language-text\">zip()</code> and a list comprehension to iterate over the pairs of values and weights.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">weighted_average</span><span class=\"token punctuation\">(</span>nums<span class=\"token punctuation\">,</span> weights<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span>x <span class=\"token operator\">*</span> y <span class=\"token keyword\">for</span> x<span class=\"token punctuation\">,</span> y <span class=\"token keyword\">in</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>nums<span class=\"token punctuation\">,</span> weights<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token builtin\">sum</span><span class=\"token punctuation\">(</span>weights<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">weighted_average<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0.6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 1.72727</span></code></pre></div>\n<hr>\n<hr>\n<h3>Tests a value, <code class=\"language-text\">x</code>, against a testing function, conditionally applying a function</h3>\n<ul>\n<li>Check if the value of <code class=\"language-text\">predicate(x)</code> is <code class=\"language-text\">True</code> and if so return <code class=\"language-text\">when_true(x)</code>, otherwise return <code class=\"language-text\">x</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">def</span> <span class=\"token function\">when</span><span class=\"token punctuation\">(</span>predicate<span class=\"token punctuation\">,</span> when_true<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> when_true<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> predicate<span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token keyword\">else</span> x</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">double_even_numbers <span class=\"token operator\">=</span> when<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">lambda</span> x <span class=\"token punctuation\">:</span> x <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\ndouble_even_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 4</span>\ndouble_even_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># 1</span></code></pre></div>\n<hr>\n<hr>\n<h3>Converts a given string into a list of words</h3>\n<ul>\n<li>Use <code class=\"language-text\">re.findall()</code> with the supplied <code class=\"language-text\">pattern</code> to find all matching substrings.</li>\n<li>Omit the second argument to use the default regexp, which matches alphanumeric and hyphens.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">import</span> re\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">words</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> pattern <span class=\"token operator\">=</span> <span class=\"token string\">'[a-zA-Z-]+'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">return</span> re<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span>pattern<span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">words<span class=\"token punctuation\">(</span><span class=\"token string\">'I love Python!!'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># ['I', 'love', 'Python']</span>\nwords<span class=\"token punctuation\">(</span><span class=\"token string\">'python, javaScript &amp; coffee'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># ['python', 'javaScript', 'coffee']</span>\nwords<span class=\"token punctuation\">(</span><span class=\"token string\">'build -q --out one-item'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">r'\\b[a-zA-Z-]+\\b'</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># ['build', 'q', 'out', 'one-item']</span></code></pre></div>"},{"url":"/docs/python/cheat-sheet/","relativePath":"docs/python/cheat-sheet.md","relativeDir":"docs/python","base":"cheat-sheet.md","name":"cheat-sheet","frontmatter":{"title":"Python Cheat Sheet","weight":0,"excerpt":"lorem-ipsum","seo":{"title":"python cheat sheet","description":"cheat sheet for python developers","robots":[],"extra":[{"name":"og:image","value":"images/py-code.png","keyName":"property","relativeUrl":true},{"name":"twitter:title","value":"python cheat sheet","keyName":"name","relativeUrl":false}]},"template":"docs"},"html":"<h2>Lorem ipsum</h2>\n<h1>Python Cheat Sheet</h1>\n<h2>Python Basics</h2>\n<h3>Math Operators</h3>\n<p>From <strong>Highest</strong> to <strong>Lowest</strong> precedence:</p>\n<table>\n<thead>\n<tr>\n<th>Operators</th>\n<th>Operation</th>\n<th>Example</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>**</td>\n<td>Exponent</td>\n<td><code class=\"language-text\">2 ** 3 = 8</code></td>\n</tr>\n<tr>\n<td>%</td>\n<td>Modulus/Remaider</td>\n<td><code class=\"language-text\">22 % 8 = 6</code></td>\n</tr>\n<tr>\n<td>//</td>\n<td>Integer division</td>\n<td><code class=\"language-text\">22 // 8 = 2</code></td>\n</tr>\n<tr>\n<td>/</td>\n<td>Division</td>\n<td><code class=\"language-text\">22 / 8 = 2.75</code></td>\n</tr>\n<tr>\n<td>*</td>\n<td>Multiplication</td>\n<td><code class=\"language-text\">3 * 3 = 9</code></td>\n</tr>\n<tr>\n<td>-</td>\n<td>Subtraction</td>\n<td><code class=\"language-text\">5 - 2 = 3</code></td>\n</tr>\n<tr>\n<td>+</td>\n<td>Addition</td>\n<td><code class=\"language-text\">2 + 2 = 4</code></td>\n</tr>\n</tbody>\n</table>\n<p>Examples of expressions in the interactive shell:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">2</span> <span class=\"token operator\">**</span> <span class=\"token number\">8</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">23</span> <span class=\"token operator\">//</span> <span class=\"token number\">7</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">23</span> <span class=\"token operator\">%</span> <span class=\"token number\">7</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token punctuation\">(</span><span class=\"token number\">3</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Data Types</h3>\n<table>\n<thead>\n<tr>\n<th>Data Type</th>\n<th>Examples</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Integers</td>\n<td><code class=\"language-text\">-2, -1, 0, 1, 2, 3, 4, 5</code></td>\n</tr>\n<tr>\n<td>Floating-point numbers</td>\n<td><code class=\"language-text\">-1.25, -1.0, --0.5, 0.0, 0.5, 1.0, 1.25</code></td>\n</tr>\n<tr>\n<td>Strings</td>\n<td><code class=\"language-text\">'a', 'aa', 'aaa', 'Hello!', '11 cats'</code></td>\n</tr>\n</tbody>\n</table>\n<h3>String Concatenation and Replication</h3>\n<p>String concatenation:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Alice'</span> <span class=\"token string\">'Bob'</span></code></pre></div>\n<p>Note: Avoid <code class=\"language-text\">+</code> operator for string concatenation. Prefer string formatting.</p>\n<p>String Replication:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Alice'</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span></code></pre></div>\n<h3>Variables</h3>\n<p>You can name a variable anything as long as it obeys the following three rules:</p>\n<ol>\n<li>It can be only one word.</li>\n<li>It can use only letters, numbers, and the underscore (<code class=\"language-text\">_</code>) character.</li>\n<li>It can't begin with a number.</li>\n<li>Variable name starting with an underscore (<code class=\"language-text\">_</code>) are considered as \"unuseful`.</li>\n</ol>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">_spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span></code></pre></div>\n<p><code class=\"language-text\">_spam</code> should not be used again in the code.</p>\n<h3>Comments</h3>\n<p>Inline comment:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># This is a comment</span></code></pre></div>\n<p>Multiline comment:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># This is a</span>\n<span class=\"token comment\"># multiline comment</span></code></pre></div>\n<p>Code with a comment:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">=</span> <span class=\"token number\">1</span>  <span class=\"token comment\"># initialization</span></code></pre></div>\n<p>Please note the two spaces in front of the comment.</p>\n<p>Function docstring:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    This is a function docstring\n    You can also use:\n    ''' Function Docstring '''\n    \"\"\"</span></code></pre></div>\n<h3>The print Function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The input Function</h3>\n<p>Example Code:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'What is your name?'</span><span class=\"token punctuation\">)</span>   <span class=\"token comment\"># ask for their name</span>\nmyName <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is good to meet you, {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>myName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The len Function</h3>\n<p>Evaluates to the integer value of the number of characters in a string:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Note: test of emptiness of strings, lists, dictionary, etc, should <strong>not</strong> use len, but prefer direct\nboolean evaluation.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">if</span> a<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"the list is not empty!\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The str, int, and float Functions</h3>\n<p>Integer to String or Float:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">29</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I am {} years old.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">29</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">3.14</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Float to Integer:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token number\">7.7</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token number\">7.7</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<h2>Flow Control</h2>\n<h3>Comparison Operators</h3>\n<table>\n<thead>\n<tr>\n<th>Operator</th>\n<th>Meaning</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">==</code></td>\n<td>Equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">!=</code></td>\n<td>Not equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">&lt;</code></td>\n<td>Less than</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">></code></td>\n<td>Greater Than</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">&lt;=</code></td>\n<td>Less than or Equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">>=</code></td>\n<td>Greater than or Equal to</td>\n</tr>\n</tbody>\n</table>\n<p>These operators evaluate to True or False depending on the values you give them.</p>\n<p>Examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token number\">42</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">40</span> <span class=\"token operator\">==</span> <span class=\"token number\">42</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'hello'</span> <span class=\"token operator\">==</span> <span class=\"token string\">'hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'hello'</span> <span class=\"token operator\">==</span> <span class=\"token string\">'Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'dog'</span> <span class=\"token operator\">!=</span> <span class=\"token string\">'cat'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token number\">42.0</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token string\">'42'</span></code></pre></div>\n<h3>Boolean evaluation</h3>\n<p>Never use <code class=\"language-text\">==</code> or <code class=\"language-text\">!=</code> operator to evaluate boolean operation. Use the <code class=\"language-text\">is</code> or <code class=\"language-text\">is not</code> operators,\nor use implicit boolean evaluation.</p>\n<p>NO (even if they are valid Python):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token operator\">!=</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>YES (even if they are valid Python):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token boolean\">True</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>These statements are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span></code></pre></div>\n<p>And these as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span>\n<span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> a<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">pass</span></code></pre></div>\n<h3>Boolean Operators</h3>\n<p>There are three Boolean operators: and, or, and not.</p>\n<p>The <em>and</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>True and True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>True and False</td>\n<td>False</td>\n</tr>\n<tr>\n<td>False and True</td>\n<td>False</td>\n</tr>\n<tr>\n<td>False and False</td>\n<td>False</td>\n</tr>\n</tbody>\n</table>\n<p>The <em>or</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>True or True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>True or False</td>\n<td>True</td>\n</tr>\n<tr>\n<td>False or True</td>\n<td>True</td>\n</tr>\n<tr>\n<td>False or False</td>\n<td>False</td>\n</tr>\n</tbody>\n</table>\n<p>The <em>not</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>not True</td>\n<td>False</td>\n</tr>\n<tr>\n<td>not False</td>\n<td>True</td>\n</tr>\n</tbody>\n</table>\n<h3>Mixing Boolean and Comparison Operators</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token number\">9</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">or</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can also use multiple Boolean operators in an expression, along with the comparison operators:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">4</span> <span class=\"token keyword\">and</span> <span class=\"token keyword\">not</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">5</span> <span class=\"token keyword\">and</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span></code></pre></div>\n<h3>if Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>else Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, stranger.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>elif Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are not Alice, kiddo.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are not Alice, kiddo.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are neither Alice nor a little kid.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>while Loop Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n<span class=\"token keyword\">while</span> spam <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, world.'</span><span class=\"token punctuation\">)</span>\n    spam <span class=\"token operator\">=</span> spam <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<h3>break Statements</h3>\n<p>If the execution reaches a break statement, it immediately exits the while loop's clause:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Please type your name.'</span><span class=\"token punctuation\">)</span>\n    name <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'your name'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">break</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Thank you!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>continue Statements</h3>\n<p>When the program execution reaches a continue statement, the program execution immediately jumps back to the start of the loop.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Who are you?'</span><span class=\"token punctuation\">)</span>\n    name <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> name <span class=\"token operator\">!=</span> <span class=\"token string\">'Joe'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">continue</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, Joe. What is the password? (It is a fish.)'</span><span class=\"token punctuation\">)</span>\n    password <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> password <span class=\"token operator\">==</span> <span class=\"token string\">'swordfish'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">break</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Access granted.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>for Loops and the range() Function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'My name is'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Jimmy Five Times ({})'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <em>range()</em> function can also be called with three arguments. The first two arguments will be the start and stop values, and the third will be the step argument. The step is the amount that the variable is increased by after each iteration.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can even use a negative number for the step argument to make the for loop count down instead of up.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>For else statement</h3>\n<p>This allows to specify a statement to execute in case of the full loop has been executed. Only\nuseful when a <code class=\"language-text\">break</code> condition can occur in the loop:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">if</span> i <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n       <span class=\"token keyword\">break</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"only executed when no item of the list is equal to 3\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Importing Modules</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random<span class=\"token punctuation\">,</span> sys<span class=\"token punctuation\">,</span> os<span class=\"token punctuation\">,</span> math</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> random <span class=\"token keyword\">import</span> <span class=\"token operator\">*</span><span class=\"token punctuation\">.</span></code></pre></div>\n<h3>Ending a Program with sys.exit</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> sys\n\n<span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Type exit to exit.'</span><span class=\"token punctuation\">)</span>\n    response <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> response <span class=\"token operator\">==</span> <span class=\"token string\">'exit'</span><span class=\"token punctuation\">:</span>\n        sys<span class=\"token punctuation\">.</span>exit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You typed {}.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Functions</h2>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Return Values and return Statements</h3>\n<p>When creating a function using the def statement, you can specify what the return value should be with a return statement. A return statement consists of the following:</p>\n<ul>\n<li>The return keyword.</li>\n<li>-</li>\n<li>The value or expression that the function should return.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n<span class=\"token keyword\">def</span> <span class=\"token function\">getAnswer</span><span class=\"token punctuation\">(</span>answerNumber<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'It is certain'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'It is decidedly so'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Yes'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Reply hazy try again'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Ask again later'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Concentrate and ask again'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">7</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'My reply is no'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">8</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Outlook not so good'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">9</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Very doubtful'</span>\n\nr <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span>\nfortune <span class=\"token operator\">=</span> getAnswer<span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>fortune<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The None Value</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello!'</span><span class=\"token punctuation\">)</span>\nspam <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span></code></pre></div>\n<p>Note: never compare to <code class=\"language-text\">None</code> with the <code class=\"language-text\">==</code> operator. Always use <code class=\"language-text\">is</code>.</p>\n<h3>print Keyword Arguments</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'World'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mice'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mice'</span><span class=\"token punctuation\">,</span> sep<span class=\"token operator\">=</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Local and Global Scope</h3>\n<ul>\n<li>Code in the global scope cannot use any local variables.</li>\n<li>-</li>\n<li>However, a local scope can access global variables.</li>\n<li>-</li>\n<li>Code in a function's local scope cannot use variables in any other local scope.</li>\n<li>You can use the same name for different variables if they are in different scopes. That is, there can be a local variable named spam and a global variable also named spam.</li>\n</ul>\n<h3>The global Statement</h3>\n<p>If you need to modify a global variable from within a function, use the global statement:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">spam</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">global</span> eggs\n    eggs <span class=\"token operator\">=</span> <span class=\"token string\">'spam'</span>\n\neggs <span class=\"token operator\">=</span> <span class=\"token string\">'global'</span>\nspam<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>eggs<span class=\"token punctuation\">)</span></code></pre></div>\n<p>There are four rules to tell whether a variable is in a local scope or global scope:</p>\n<ol>\n<li>If a variable is being used in the global scope (that is, outside of all functions), then it is always a global variable.</li>\n<li>If there is a global statement for that variable in a function, it is a global variable.</li>\n<li>Otherwise, if the variable is used in an assignment statement in the function, it is a local variable.</li>\n<li>But if the variable is not used in an assignment statement, it is a global variable.</li>\n</ol>\n<h2>Exception Handling</h2>\n<h3>Basic exception handling</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">spam</span><span class=\"token punctuation\">(</span>divideBy<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">42</span> <span class=\"token operator\">/</span> divideBy\n    <span class=\"token keyword\">except</span> ZeroDivisionError <span class=\"token keyword\">as</span> e<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Error: Invalid argument: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">12</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Final code in exception handling</h3>\n<p>Code inside the <code class=\"language-text\">finally</code> section is always executed, no matter if an exception has been raised or\nnot, and even if an exception is not caught.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">spam</span><span class=\"token punctuation\">(</span>divideBy<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">42</span> <span class=\"token operator\">/</span> divideBy\n    <span class=\"token keyword\">except</span> ZeroDivisionError <span class=\"token keyword\">as</span> e<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Error: Invalid argument: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">finally</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"-- division finished --\"</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">12</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Lists</h2>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3>Getting Individual Values in a List with Indexes</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3>Negative Indexes</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'The {} is afraid of the {}.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Getting Sublists with Slices</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token number\">4</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3>Getting a list Length with len</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'moose'</span><span class=\"token punctuation\">]</span>\n<span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Changing Values in a List with Indexes</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'aardvark'</span>\nspam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nspam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">12345</span>\nspam</code></pre></div>\n<h3>List Concatenation and List Replication</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'B'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">[</span><span class=\"token string\">'X'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Y'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Z'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\nspam <span class=\"token operator\">=</span> spam <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'B'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C'</span><span class=\"token punctuation\">]</span>\nspam</code></pre></div>\n<h3>Removing Values from Lists with del Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">del</span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\nspam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">del</span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\nspam</code></pre></div>\n<h3>Using for Loops with Lists</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">supplies <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'pens'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'staplers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'flame-throwers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'binders'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token keyword\">for</span> i<span class=\"token punctuation\">,</span> supply <span class=\"token keyword\">in</span> <span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>supplies<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Index {} in supplies is: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> supply<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Looping Through Multiple Lists with zip</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Pete'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Elizabeth'</span><span class=\"token punctuation\">]</span>\nage <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23</span><span class=\"token punctuation\">,</span> <span class=\"token number\">44</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token keyword\">for</span> n<span class=\"token punctuation\">,</span> a <span class=\"token keyword\">in</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'{} is {} years old'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The in and not in Operators</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'howdy'</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hi'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'howdy'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'heyas'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hi'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'howdy'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'heyas'</span><span class=\"token punctuation\">]</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'howdy'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> spam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'cat'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> spam</code></pre></div>\n<h3>The Multiple Assignment Trick</h3>\n<p>The multiple assignment trick is a shortcut that lets you assign multiple variables with the values in a list in one line of code. So instead of doing this:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">cat <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'fat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'loud'</span><span class=\"token punctuation\">]</span>\nsize <span class=\"token operator\">=</span> cat<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\ncolor <span class=\"token operator\">=</span> cat<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\ndisposition <span class=\"token operator\">=</span> cat<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>You could type this line of code:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">cat <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'fat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'loud'</span><span class=\"token punctuation\">]</span>\nsize<span class=\"token punctuation\">,</span> color<span class=\"token punctuation\">,</span> disposition <span class=\"token operator\">=</span> cat</code></pre></div>\n<p>The multiple assignment trick can also be used to swap the values in two variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Bob'</span>\na<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> b<span class=\"token punctuation\">,</span> a\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Augmented Assignment Operators</h3>\n<table>\n<thead>\n<tr>\n<th>Operator</th>\n<th>Equivalent</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">spam += 1</code></td>\n<td><code class=\"language-text\">spam = spam + 1</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam -= 1</code></td>\n<td><code class=\"language-text\">spam = spam - 1</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam *= 1</code></td>\n<td><code class=\"language-text\">spam = spam * 1</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam /= 1</code></td>\n<td><code class=\"language-text\">spam = spam / 1</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam %= 1</code></td>\n<td><code class=\"language-text\">spam = spam % 1</code></td>\n</tr>\n</tbody>\n</table>\n<p>Examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span>\nspam <span class=\"token operator\">+=</span> <span class=\"token string\">' world!'</span>\nspam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">bacon <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">]</span>\nbacon <span class=\"token operator\">*=</span> <span class=\"token number\">3</span>\nbacon</code></pre></div>\n<h3>Finding a Value in a List with the index Method</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Fat-tail'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span><span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Adding Values to Lists with append and insert</h3>\n<p><strong>append()</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">'moose'</span><span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<p><strong>insert()</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">.</span>insert<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'chicken'</span><span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<h3>Removing Values from Lists with remove</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">.</span>remove<span class=\"token punctuation\">(</span><span class=\"token string\">'bat'</span><span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<p>If the value appears multiple times in the list, only the first instance of the value will be removed.</p>\n<h3>Sorting the Values in a List with sort</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">7</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'ants'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'badgers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephants'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<p>You can also pass True for the reverse keyword argument to have sort() sort the values in reverse order:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span>reverse<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<p>If you need to sort the values in regular alphabetical order, pass str. lower for the key keyword argument in the sort() method call:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'z'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Z'</span><span class=\"token punctuation\">]</span>\nspam<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span>key<span class=\"token operator\">=</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<p>You can use the built-in function <code class=\"language-text\">sorted</code> to return a new list:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'ants'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'badgers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephants'</span><span class=\"token punctuation\">]</span>\n<span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Tuple Data Type</h2>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">eggs <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.5</span><span class=\"token punctuation\">)</span>\neggs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">eggs<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>eggs<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The main way that tuples are different from lists is that tuples, like strings, are immutable.</p>\n<h2>Converting Types with the list and tuple Functions</h2>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Dictionaries and Structuring Data</h2>\n<p>Example Dictionary:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">myCat <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'size'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'fat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'gray'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'disposition'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'loud'</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3>The keys, values, and items Methods</h3>\n<p>values():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">for</span> v <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span></code></pre></div>\n<p>keys():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> k <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">)</span></code></pre></div>\n<p>items():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using the keys(), values(), and items() methods, a for loop can iterate over the keys, values, or key-value pairs in a dictionary, respectively.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Key: {} Value: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">,</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Checking if a Key or Value Exists in a Dictionary</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">7</span><span class=\"token punctuation\">}</span>\n<span class=\"token string\">'name'</span> <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Zophie'</span> <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># You can omit the call to keys() when checking for a key</span>\n<span class=\"token string\">'color'</span> <span class=\"token keyword\">in</span> spam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'color'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> spam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'color'</span> <span class=\"token keyword\">in</span> spam</code></pre></div>\n<h3>The get Method</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">picnic_items <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'apples'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cups'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n<span class=\"token string\">'I am bringing {} cups.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>picnic_items<span class=\"token punctuation\">.</span>get<span class=\"token punctuation\">(</span><span class=\"token string\">'cups'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'I am bringing {} eggs.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>picnic_items<span class=\"token punctuation\">.</span>get<span class=\"token punctuation\">(</span><span class=\"token string\">'eggs'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The setdefault Method</h3>\n<p>Let's consider this code:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">if</span> <span class=\"token string\">'color'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">:</span>\n    spam<span class=\"token punctuation\">[</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'black'</span></code></pre></div>\n<p>Using <code class=\"language-text\">setdefault</code> we could make the same code more shortly:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\nspam<span class=\"token punctuation\">.</span>setdefault<span class=\"token punctuation\">(</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'black'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">.</span>setdefault<span class=\"token punctuation\">(</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'white'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam</code></pre></div>\n<h3>Pretty Printing</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> pprint\n\nmessage <span class=\"token operator\">=</span> <span class=\"token string\">'It was a bright cold day in April, and the clocks were striking thirteen.'</span>\ncount <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">for</span> character <span class=\"token keyword\">in</span> message<span class=\"token punctuation\">:</span>\n    count<span class=\"token punctuation\">.</span>setdefault<span class=\"token punctuation\">(</span>character<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n    count<span class=\"token punctuation\">[</span>character<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> count<span class=\"token punctuation\">[</span>character<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n\npprint<span class=\"token punctuation\">.</span>pprint<span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Merge two dictionaries</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># in Python 3.5+:</span>\nx <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\ny <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\nz <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">**</span>x<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>y<span class=\"token punctuation\">}</span>\nz</code></pre></div>\n<h2>sets</h2>\n<p>From the Python 3 <a href=\"https://docs.python.org/3/tutorial/datastructures.html\">documentation</a></p>\n<blockquote>\n<p>A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.</p>\n</blockquote>\n<h3>Initializing a set</h3>\n<p>There are two ways to create sets: using curly braces <code class=\"language-text\">{}</code> and the bult-in function <code class=\"language-text\">set()</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>When creating an empty set, be sure to not use the curly braces <code class=\"language-text\">{}</code> or you will get an empty dictionary instead.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>sets: unordered collections of unique elements</h3>\n<p>A set automatically remove all the duplicate values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\ns</code></pre></div>\n<p>And as an unordered data type, they can't be indexed.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>set add and update</h3>\n<p>Using the <code class=\"language-text\">add()</code> method we can add a single element to the set.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns<span class=\"token punctuation\">.</span>add<span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\ns</code></pre></div>\n<p>And with <code class=\"language-text\">update()</code>, multiple ones .</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns<span class=\"token punctuation\">.</span>update<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\ns  <span class=\"token comment\"># remember, sets automatically remove duplicates</span></code></pre></div>\n<h3>set remove and discard</h3>\n<p>Both methods will remove an element from the set, but <code class=\"language-text\">remove()</code> will raise a <code class=\"language-text\">key error</code> if the value doesn't exist.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns<span class=\"token punctuation\">.</span>remove<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\ns</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s<span class=\"token punctuation\">.</span>remove<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">discard()</code> won't raise any errors.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns<span class=\"token punctuation\">.</span>discard<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\ns</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s<span class=\"token punctuation\">.</span>discard<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>set union</h3>\n<p><code class=\"language-text\">union()</code> or <code class=\"language-text\">|</code> will create a new set that contains all the elements from the sets provided.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\ns1<span class=\"token punctuation\">.</span>union<span class=\"token punctuation\">(</span>s2<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># or 's1 | s2'</span></code></pre></div>\n<h3>set intersection</h3>\n<p><code class=\"language-text\">intersection</code> or <code class=\"language-text\">&amp;</code> will return a set containing only the elements that are common to all of them.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\ns3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\ns1<span class=\"token punctuation\">.</span>intersection<span class=\"token punctuation\">(</span>s2<span class=\"token punctuation\">,</span> s3<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># or 's1 &amp; s2 &amp; s3'</span></code></pre></div>\n<h3>set difference</h3>\n<p><code class=\"language-text\">difference</code> or <code class=\"language-text\">-</code> will return only the elements that are in one of the sets.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\ns1<span class=\"token punctuation\">.</span>difference<span class=\"token punctuation\">(</span>s2<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># or 's1 - s2'</span></code></pre></div>\n<h3>set symetric_difference</h3>\n<p><code class=\"language-text\">symetric_difference</code> or <code class=\"language-text\">^</code> will return all the elements that are not common between them.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">s1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\ns2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\ns1<span class=\"token punctuation\">.</span>symmetric_difference<span class=\"token punctuation\">(</span>s2<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># or 's1 ^ s2'</span></code></pre></div>\n<h2>itertools Module</h2>\n<p>The <em>itertools</em> module is a collection of tools intented to be fast and use memory efficiently when handling iterators (like <a href=\"#lists\">lists</a> or <a href=\"#dictionaries-and-structuring-data\">dictionaries</a>).</p>\n<p>From the official <a href=\"https://docs.python.org/3/library/itertools.html\">Python 3.x documentation</a>:</p>\n<blockquote>\n<p>The module standardizes a core set of fast, memory efficient tools that are useful by themselves or in combination. Together, they form an \"iterator algebra\" making it possible to construct specialized tools succinctly and efficiently in pure Python.</p>\n</blockquote>\n<p>The <em>itertools</em> module comes in the standard library and must be imported.</p>\n<p>The <a href=\"https://docs.python.org/3/library/operator.html\">operator</a> module will also be used. This module is not necessary when using itertools, but needed for some of the examples below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> itertools\n<span class=\"token keyword\">import</span> operator</code></pre></div>\n<h3>accumulate</h3>\n<p>Makes an iterator that returns the results of a function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>accumulate<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> func<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>accumulate<span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">,</span> operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The operator.mul takes two numbers and multiplies them:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">(</span><span class=\"token number\">24</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Passing a function is optional:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>accumulate<span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<p>If no function is designated the items will be summed:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">5</span>\n<span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n<span class=\"token number\">7</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">13</span>\n<span class=\"token number\">13</span> <span class=\"token operator\">+</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">17</span>\n<span class=\"token number\">17</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">22</span>\n<span class=\"token number\">22</span> <span class=\"token operator\">+</span> <span class=\"token number\">9</span> <span class=\"token operator\">=</span> <span class=\"token number\">31</span>\n<span class=\"token number\">31</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">32</span></code></pre></div>\n<h3>combinations</h3>\n<p>Takes an iterable and a integer. This will create all the unique combination that have r members.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>combinations<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">shapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>combinations<span class=\"token punctuation\">(</span>shapes<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>combinations<em>with</em>replacement</h3>\n<p>Just like combinations(), but allows individual elements to be repeated more than once.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>combinations_with_replacement<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">shapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>combinations_with_replacement<span class=\"token punctuation\">(</span>shapes<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>count</h3>\n<p>Makes an iterator that returns evenly spaced values starting with number start.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>start<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> step<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n   <span class=\"token keyword\">if</span> i <span class=\"token operator\">></span> <span class=\"token number\">20</span><span class=\"token punctuation\">:</span>\n       <span class=\"token keyword\">break</span></code></pre></div>\n<h3>cycle</h3>\n<p>This function cycles through an iterator endlessly.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>cycle<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'violet'</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> color <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>cycle<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>color<span class=\"token punctuation\">)</span></code></pre></div>\n<p>When reached the end of the iterable it start over again from the beginning.</p>\n<h3>chain</h3>\n<p>Take a series of iterables and return them as one long iterable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>chain<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>iterables<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">]</span>\nshapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pentagon'</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>chain<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">,</span> shapes<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>compress</h3>\n<p>Filters one iterable with another.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>compress<span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">,</span> selectors<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">shapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pentagon'</span><span class=\"token punctuation\">]</span>\nselections <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>compress<span class=\"token punctuation\">(</span>shapes<span class=\"token punctuation\">,</span> selections<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>dropwhile</h3>\n<p>Make an iterator that drops elements from the iterable as long as the predicate is true; afterwards, returns every element.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>dropwhile<span class=\"token punctuation\">(</span>predicate<span class=\"token punctuation\">,</span> iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>dropwhile<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token operator\">&lt;</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>filterfalse</h3>\n<p>Makes an iterator that filters elements from iterable returning only those for which the predicate is False.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>filterfalse<span class=\"token punctuation\">(</span>predicate<span class=\"token punctuation\">,</span> iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>filterfalse<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token operator\">&lt;</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>groupby</h3>\n<p>Simply put, this function groups things together.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>groupby<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> key<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">robots <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'blaster'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'galvatron'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'jazz'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'metroplex'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'megatron'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'starcream'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> group <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>groupby<span class=\"token punctuation\">(</span>robots<span class=\"token punctuation\">,</span> key<span class=\"token operator\">=</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">[</span><span class=\"token string\">'faction'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>group<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>islice</h3>\n<p>This function is very much like slices. This allows you to cut out a piece of an iterable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>islice<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> stop<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> step<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span>\nfew_colors <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>islice<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> few_colors<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>permutations</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>permutations<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> r<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">alpha_data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>permutations<span class=\"token punctuation\">(</span>alpha_data<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>product</h3>\n<p>Creates the cartesian products from a series of iterables.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num_data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\nalpha_data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>product<span class=\"token punctuation\">(</span>num_data<span class=\"token punctuation\">,</span> alpha_data<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>repeat</h3>\n<p>This function will repeat an object over and over again. Unless, there is a times argument.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>repeat<span class=\"token punctuation\">(</span><span class=\"token builtin\">object</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> times<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>repeat<span class=\"token punctuation\">(</span><span class=\"token string\">\"spam\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>starmap</h3>\n<p>Makes an iterator that computes the function using arguments obtained from the iterable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>starmap<span class=\"token punctuation\">(</span>function<span class=\"token punctuation\">,</span> iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>starmap<span class=\"token punctuation\">(</span>operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>takewhile</h3>\n<p>The opposite of dropwhile(). Makes an iterator and returns elements from the iterable as long as the predicate is true.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>takewhile<span class=\"token punctuation\">(</span>predicate<span class=\"token punctuation\">,</span> iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\nresult <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>takewhile<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token operator\">&lt;</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>tee</h3>\n<p>Return n independent iterators from a single iterable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>tee<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> n<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">]</span>\nalpha_colors<span class=\"token punctuation\">,</span> beta_colors <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>tee<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> alpha_colors<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">]</span>\nalpha_colors<span class=\"token punctuation\">,</span> beta_colors <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>tee<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> beta_colors<span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>zip_longest</h3>\n<p>Makes an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled-in with fillvalue. Iteration continues until the longest iterable is exhausted.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>zip_longest<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>iterables<span class=\"token punctuation\">,</span> fillvalue<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span>\ndata <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>zip_longest<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">,</span> fillvalue<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Comprehensions</h2>\n<h3>List comprehension</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">]</span></code></pre></div>\n<h3>Set comprehension</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">b <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"def\"</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>s<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> s <span class=\"token keyword\">in</span> b<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Dict comprehension</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">c <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>v<span class=\"token punctuation\">,</span> k <span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> c<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>A List comprehension can be generated from a dictionary:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">c <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'first_name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Oooka'</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">\"{}:{}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> v<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> c<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h2>Manipulating Strings</h2>\n<h3>Escape Characters</h3>\n<table>\n<thead>\n<tr>\n<th>Escape character</th>\n<th>Prints as</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">\\'</code></td>\n<td>Single quote</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\\"</code></td>\n<td>Double quote</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\t</code></td>\n<td>Tab</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\n</code></td>\n<td>Newline (line break)</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\\\</code></td>\n<td>Backslash</td>\n</tr>\n</tbody>\n</table>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello there!\\nHow are you?\\nI\\'m doing fine.\"</span><span class=\"token punctuation\">)</span>\nHello there!\nHow are you?</code></pre></div>\n<h3>Raw Strings</h3>\n<p>A raw string completely ignores all escape characters and prints any backslash that appears in the string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'That is Carol\\'s cat.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Note: mostly used for regular expression definition (see <code class=\"language-text\">re</code> package)</p>\n<h3>Multiline Strings with Triple Quotes</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token triple-quoted-string string\">'''Dear Alice,\n\nEve's cat has been arrested for catnapping, cat burglary, and extortion.\n\nSincerely,\nBob'''</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>To keep a nicer flow in your code, you can use the <code class=\"language-text\">dedent</code> function from the <code class=\"language-text\">textwrap</code> standard package.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> textwrap <span class=\"token keyword\">import</span> dedent\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">my_function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token triple-quoted-string string\">'''\n        Dear Alice,\n\n        Eve's cat has been arrested for catnapping, cat burglary, and extortion.\n\n        Sincerely,\n        Bob\n        '''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This generates the same string than before.</p>\n<h3>Indexing and Slicing Strings</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">H   e   l   l   o       w   o   r   l   d    !\n0   1   2   3   4   5   6   7   8   9   10   11</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello world!'</span>\nspam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Slicing:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello world!'</span>\nfizz <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\nfizz</code></pre></div>\n<h3>The in and not in Operators with Strings</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'Hello World'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'HELLO'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'Hello World'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">''</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'spam'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'cats'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'cats and dogs'</span></code></pre></div>\n<h3>The in and not in Operators with list</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">5</span> <span class=\"token keyword\">in</span> a</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">2</span> <span class=\"token keyword\">in</span> a</code></pre></div>\n<h3>The upper, lower, isupper, and islower String Methods</h3>\n<p><code class=\"language-text\">upper()</code> and <code class=\"language-text\">lower()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello world!'</span>\nspam <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<p>isupper() and islower():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello world!'</span>\nspam<span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'HELLO'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'abc12345'</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'12345'</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'12345'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The isX String Methods</h3>\n<ul>\n<li><strong>isalpha()</strong> returns True if the string consists only of letters and is not blank.</li>\n<li><strong>isalnum()</strong> returns True if the string consists only of lettersand numbers and is not blank.</li>\n<li><strong>isdecimal()</strong> returns True if the string consists only ofnumeric characters and is not blank.</li>\n<li><strong>isspace()</strong> returns True if the string consists only of spaces,tabs, and new-lines and is not blank.</li>\n<li><strong>istitle()</strong> returns True if the string consists only of wordsthat begin with an uppercase letter followed by onlylowercase letters.</li>\n</ul>\n<h3>The startswith and endswith String Methods</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'world!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'abc123'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'abcdef'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'abc123'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'12'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The join and split String Methods</h3>\n<p>join():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">', '</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bats'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">' '</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'My'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'ABC'</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'My'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>split():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'My name is Simon'</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'MyABCnameABCisABCSimon'</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token string\">'ABC'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'My name is Simon'</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token string\">'m'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Justifying Text with rjust, ljust, and center</h3>\n<p>rjust() and ljust():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>ljust<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>An optional second argument to rjust() and ljust() will specify a fill character other than a space character. Enter the following into the interactive shell:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'*'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>ljust<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'-'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>center():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>center<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>center<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'='</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Removing Whitespace with strip, rstrip, and lstrip</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token string\">'    Hello World     '</span>\nspam<span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">.</span>lstrip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam<span class=\"token punctuation\">.</span>rstrip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token string\">'SpamSpamBaconSpamEggsSpamSpam'</span>\nspam<span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token string\">'ampS'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Copying and Pasting Strings with the pyperclip Module</h3>\n<p>First, install <code class=\"language-text\">pypeerclip</code> with pip:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">pip <span class=\"token function\">install</span> pyperclip</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> pyperclip\n\npyperclip<span class=\"token punctuation\">.</span>copy<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span>\npyperclip<span class=\"token punctuation\">.</span>paste<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2>String Formatting</h2>\n<h3>% operator</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Pete'</span>\n<span class=\"token string\">'Hello %s'</span> <span class=\"token operator\">%</span> name</code></pre></div>\n<p>We can use the <code class=\"language-text\">%x</code> format specifier to convert an int value to a string:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">num <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n<span class=\"token string\">'I have %x apples'</span> <span class=\"token operator\">%</span> num</code></pre></div>\n<p>Note: For new code, using str.format or f-strings is strongly recommended over the <code class=\"language-text\">%</code> operator.</p>\n<h3>str.format</h3>\n<p>Python 3 introduced a new way to do string formatting that was later back-ported to Python 2.7. This makes the syntax for string formatting more regular.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'John'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">20</span>'\n\n<span class=\"token string\">\"Hello I'm {}, my age is {}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token string\">\"Hello I'm {0}, my age is {1}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The official <a href=\"https://docs.python.org/3/library/stdtypes.html?highlight=sprintf#printf-style-string-formatting\">Python 3.x documentation</a> recommend <code class=\"language-text\">str.format</code> over the <code class=\"language-text\">%</code> operator:</p>\n<blockquote>\n<p>The formatting operations described here exhibit a variety of quirks that lead to a number of common errors (such as failing to display tuples and dictionaries correctly). Using the newer formatted string literals or the str.format() interface helps avoid these errors. These alternatives also provide more powerful, flexible and extensible approaches to formatting text.</p>\n</blockquote>\n<h3>Lazy string formatting</h3>\n<p>You would only use <code class=\"language-text\">%s</code> string formatting on functions that can do lazy parameters evaluation,\nthe most common being logging:</p>\n<p>Prefer:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">\"alice\"</span>\nlogging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">\"User name: %s\"</span><span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Over:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">\"User name: {}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Or:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">\"User name: \"</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Formatted String Literals or f-strings</h3>\n<p>Python 3.6+</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Elizabeth'</span>\n<span class=\"token string-interpolation\"><span class=\"token string\">f'Hello </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span></span><span class=\"token string\">!'</span></span></code></pre></div>\n<p>It is even possible to do inline arithmetic with it:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\nb <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n<span class=\"token string-interpolation\"><span class=\"token string\">f'Five plus ten is </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">}</span></span><span class=\"token string\"> and not </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span><span class=\"token string\">.'</span></span></code></pre></div>\n<h3>Template Strings</h3>\n<p>A simpler and less powerful mechanism, but it is recommended when handling format strings generated by users. Due to their reduced complexity template strings are a safer choice.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> string <span class=\"token keyword\">import</span> Template\n\nname <span class=\"token operator\">=</span> <span class=\"token string\">'Elizabeth'</span>\nt <span class=\"token operator\">=</span> Template<span class=\"token punctuation\">(</span><span class=\"token string\">'Hey $name!'</span><span class=\"token punctuation\">)</span>\nt<span class=\"token punctuation\">.</span>substitute<span class=\"token punctuation\">(</span>name<span class=\"token operator\">=</span>name<span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Regular Expressions</h2>\n<ol>\n<li>Import the regex module with <code class=\"language-text\">import re</code>.</li>\n<li>Create a Regex object with the <code class=\"language-text\">re.compile()</code> function. (Remember to use a raw string.)</li>\n<li>Pass the string you want to search into the Regex object's <code class=\"language-text\">search()</code> method. This returns a <code class=\"language-text\">Match</code> object.</li>\n<li>Call the Match object's <code class=\"language-text\">group()</code> method to return a string of the actual matched text.</li>\n</ol>\n<p>All the regex functions in Python are in the re module:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> re</code></pre></div>\n<h3>Matching Regex Objects</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">phone_num_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'\\d\\d\\d-\\d\\d\\d-\\d\\d\\d\\d'</span><span class=\"token punctuation\">)</span>\nmo <span class=\"token operator\">=</span> phone_num_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'My number is 415-555-4242.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Phone number found: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Grouping with Parentheses</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">phone_num_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'(\\d\\d\\d)-(\\d\\d\\d-\\d\\d\\d\\d)'</span><span class=\"token punctuation\">)</span>\nmo <span class=\"token operator\">=</span> phone_num_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'My number is 415-555-4242.'</span><span class=\"token punctuation\">)</span>\nmo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>To retrieve all the groups at once: use the groups() method—note the plural form for the name.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo<span class=\"token punctuation\">.</span>groups<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\narea_code<span class=\"token punctuation\">,</span> main_number <span class=\"token operator\">=</span> mo<span class=\"token punctuation\">.</span>groups<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>area_code<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>main_number<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Matching Multiple Groups with the Pipe</h3>\n<p>The | character is called a pipe. You can use it anywhere you want to match one of many expressions. For example, the regular expression r'Batman|Tina Fey' will match either 'Batman' or 'Tina Fey'.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">hero_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span> <span class=\"token punctuation\">(</span><span class=\"token string\">r'Batman|Tina Fey'</span><span class=\"token punctuation\">)</span>\nmo1 <span class=\"token operator\">=</span> hero_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Batman and Tina Fey.'</span><span class=\"token punctuation\">)</span>\nmo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo2 <span class=\"token operator\">=</span> hero_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Tina Fey and Batman.'</span><span class=\"token punctuation\">)</span>\nmo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can also use the pipe to match one of several patterns as part of your regex:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">bat_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Bat(man|mobile|copter|bat)'</span><span class=\"token punctuation\">)</span>\nmo <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Batmobile lost a wheel'</span><span class=\"token punctuation\">)</span>\nmo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Optional Matching with the Question Mark</h3>\n<p>The ? character flags the group that precedes it as an optional part of the pattern.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">bat_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Bat(wo)?man'</span><span class=\"token punctuation\">)</span>\nmo1 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batman'</span><span class=\"token punctuation\">)</span>\nmo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo2 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwoman'</span><span class=\"token punctuation\">)</span>\nmo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Matching Zero or More with the Star</h3>\n<p>The * (called the star or asterisk) means \"match zero or more\"—the group that precedes the star can occur any number of times in the text.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">bat_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Bat(wo)*man'</span><span class=\"token punctuation\">)</span>\nmo1 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batman'</span><span class=\"token punctuation\">)</span>\nmo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo2 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwoman'</span><span class=\"token punctuation\">)</span>\nmo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo3 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwowowowoman'</span><span class=\"token punctuation\">)</span>\nmo3<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Matching One or More with the Plus</h3>\n<p>While * means \"match zero or more,\" the + (or plus) means \"match one or more\". The group preceding a plus must appear at least once. It is not optional:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">bat_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Bat(wo)+man'</span><span class=\"token punctuation\">)</span>\nmo1 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwoman'</span><span class=\"token punctuation\">)</span>\nmo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo2 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwowowowoman'</span><span class=\"token punctuation\">)</span>\nmo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo3 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batman'</span><span class=\"token punctuation\">)</span>\nmo3 <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span></code></pre></div>\n<h3>Matching Specific Repetitions with Curly Brackets</h3>\n<p>If you have a group that you want to repeat a specific number of times, follow the group in your regex with a number in curly brackets. For example, the regex (Ha){3} will match the string 'HaHaHa', but it will not match 'HaHa', since the latter has only two repeats of the (Ha) group.</p>\n<p>Instead of one number, you can specify a range by writing a minimum, a comma, and a maximum in between the curly brackets. For example, the regex (Ha){3,5} will match 'HaHaHa', 'HaHaHaHa', and 'HaHaHaHaHa'.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">ha_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'(Ha){3}'</span><span class=\"token punctuation\">)</span>\nmo1 <span class=\"token operator\">=</span> ha_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'HaHaHa'</span><span class=\"token punctuation\">)</span>\nmo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo2 <span class=\"token operator\">=</span> ha_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Ha'</span><span class=\"token punctuation\">)</span>\nmo2 <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span></code></pre></div>\n<h3>Greedy and Nongreedy Matching</h3>\n<p>Python's regular expressions are greedy by default, which means that in ambiguous situations they will match the longest string possible. The non-greedy version of the curly brackets, which matches the shortest string possible, has the closing curly bracket followed by a question mark.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">greedy_ha_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'(Ha){3,5}'</span><span class=\"token punctuation\">)</span>\nmo1 <span class=\"token operator\">=</span> greedy_ha_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'HaHaHaHaHa'</span><span class=\"token punctuation\">)</span>\nmo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">nongreedy_ha_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'(Ha){3,5}?'</span><span class=\"token punctuation\">)</span>\nmo2 <span class=\"token operator\">=</span> nongreedy_ha_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'HaHaHaHaHa'</span><span class=\"token punctuation\">)</span>\nmo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The findall Method</h3>\n<p>In addition to the search() method, Regex objects also have a findall() method. While search() will return a Match object of the first matched text in the searched string, the findall() method will return the strings of every match in the searched string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">phone_num_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'\\d\\d\\d-\\d\\d\\d-\\d\\d\\d\\d'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># has no groups</span>\nphone_num_regex<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span><span class=\"token string\">'Cell: 415-555-9999 Work: 212-555-0000'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>To summarize what the findall() method returns, remember the following:</p>\n<ul>\n<li>When called on a regex with no groups, such as \\d-\\d\\d\\d-\\d\\d\\d\\d, the method findall() returns a list of ng matches, such as ['415-555-9999', '212-555-0000'].</li>\n<li>-</li>\n<li>When called on a regex that has groups, such as (\\d\\d\\d)-d\\d)-(\\d\\ d\\d\\d), the method findall() returns a list of es of strings (one string for each group), such as [('415', ', '9999'), ('212', '555', '0000')].</li>\n</ul>\n<h3>Making Your Own Character Classes</h3>\n<p>There are times when you want to match a set of characters but the shorthand character classes (\\d, \\w, \\s, and so on) are too broad. You can define your own character class using square brackets. For example, the character class [aeiouAEIOU] will match any vowel, both lowercase and uppercase.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">vowel_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'[aeiouAEIOU]'</span><span class=\"token punctuation\">)</span>\nvowel_regex<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span><span class=\"token string\">'Robocop eats baby food. BABY FOOD.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can also include ranges of letters or numbers by using a hyphen. For example, the character class [a-zA-Z0-9] will match all lowercase letters, uppercase letters, and numbers.</p>\n<p>By placing a caret character (^) just after the character class's opening bracket, you can make a negative character class. A negative character class will match all the characters that are not in the character class. For example, enter the following into the interactive shell:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">consonant_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'[^aeiouAEIOU]'</span><span class=\"token punctuation\">)</span>\nconsonant_regex<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span><span class=\"token string\">'Robocop eats baby food. BABY FOOD.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The Caret and Dollar Sign Characters</h3>\n<ul>\n<li>You can also use the caret symbol (^) at the start of a regex to indicate that a match must occur at the beginning of the searched text.</li>\n<li>-</li>\n<li>Likewise, you can put a dollar sign ($) at the end of the regex to indicate the string must end with this regex pattern.</li>\n<li>And you can use the ^ and $ together to indicate that the entire string must match the regex—that is, it's not enough for a match to be made on some subset of the string.</li>\n</ul>\n<p>The r'^Hello' regular expression string matches strings that begin with 'Hello':</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">begins_with_hello <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'^Hello'</span><span class=\"token punctuation\">)</span>\nbegins_with_hello<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">begins_with_hello<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'He said hello.'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span></code></pre></div>\n<p>The r'\\d$' regular expression string matches strings that end with a numeric character from 0 to 9:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">whole_string_is_num <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'^\\d+$'</span><span class=\"token punctuation\">)</span>\nwhole_string_is_num<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'1234567890'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">whole_string_is_num<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'12345xyz67890'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">whole_string_is_num<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'12 34567890'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span></code></pre></div>\n<h3>The Wildcard Character</h3>\n<p>The . (or dot) character in a regular expression is called a wildcard and will match any character except for a newline:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">at_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'.at'</span><span class=\"token punctuation\">)</span>\nat_regex<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span><span class=\"token string\">'The cat in the hat sat on the flat mat.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Matching Everything with Dot-Star</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'First Name: (.*) Last Name: (.*)'</span><span class=\"token punctuation\">)</span>\nmo <span class=\"token operator\">=</span> name_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'First Name: Some Last Name: One'</span><span class=\"token punctuation\">)</span>\nmo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The dot-star uses greedy mode: It will always try to match as much text as possible. To match any and all text in a nongreedy fashion, use the dot, star, and question mark (.*?). The question mark tells Python to match in a nongreedy way:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">nongreedy_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'&lt;.*?>'</span><span class=\"token punctuation\">)</span>\nmo <span class=\"token operator\">=</span> nongreedy_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'&lt;To serve man> for dinner.>'</span><span class=\"token punctuation\">)</span>\nmo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">greedy_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'&lt;.*>'</span><span class=\"token punctuation\">)</span>\nmo <span class=\"token operator\">=</span> greedy_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'&lt;To serve man> for dinner.>'</span><span class=\"token punctuation\">)</span>\nmo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Matching Newlines with the Dot Character</h3>\n<p>The dot-star will match everything except a newline. By passing re.DOTALL as the second argument to re.compile(), you can make the dot character match all characters, including the newline character:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">no_newline_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.*'</span><span class=\"token punctuation\">)</span>\nno_newline_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Serve the public trust.\\nProtect the innocent.\\nUphold the law.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">newline_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.*'</span><span class=\"token punctuation\">,</span> re<span class=\"token punctuation\">.</span>DOTALL<span class=\"token punctuation\">)</span>\nnewline_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Serve the public trust.\\nProtect the innocent.\\nUphold the law.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Review of Regex Symbols</h3>\n<table>\n<thead>\n<tr>\n<th>Symbol</th>\n<th>Matches</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">?</code></td>\n<td>zero or one of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">*</code></td>\n<td>zero or more of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">+</code></td>\n<td>one or more of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{n}</code></td>\n<td>exactly n of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{n,}</code></td>\n<td>n or more of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{,m}</code></td>\n<td>0 to m of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{n,m}</code></td>\n<td>at least n and at most m of the preceding p.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{n,m}?</code> or <code class=\"language-text\">*?</code> or <code class=\"language-text\">+?</code></td>\n<td>performs a nongreedy match of the preceding p.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">^spam</code></td>\n<td>means the string must begin with spam.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam$</code></td>\n<td>means the string must end with spam.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">.</code></td>\n<td>any character, except newline characters.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\d</code>, <code class=\"language-text\">\\w</code>, and <code class=\"language-text\">\\s</code></td>\n<td>a digit, word, or space character, resectively.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\D</code>, <code class=\"language-text\">\\W</code>, and <code class=\"language-text\">\\S</code></td>\n<td>anything except a digit, word, or space acter, respectively.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">[abc]</code></td>\n<td>any character between the brackets (such as a, b, ).</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">[^abc]</code></td>\n<td>any character that isn't between the brackets.</td>\n</tr>\n</tbody>\n</table>\n<h3>Case-Insensitive Matching</h3>\n<p>To make your regex case-insensitive, you can pass re.IGNORECASE or re.I as a second argument to re.compile():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">robocop <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'robocop'</span><span class=\"token punctuation\">,</span> re<span class=\"token punctuation\">.</span>I<span class=\"token punctuation\">)</span>\nrobocop<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Robocop is part man, part machine, all cop.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">robocop<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'ROBOCOP protects the innocent.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">robocop<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Al, why does your programming book talk about robocop so much?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Substituting Strings with the sub() Method</h3>\n<p>The sub() method for Regex objects is passed two arguments:</p>\n<ol>\n<li>The first argument is a string to replace any matches.</li>\n<li>The second is the string for the regular expression.</li>\n</ol>\n<p>The sub() method returns a string with the substitutions applied:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">names_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Agent \\w+'</span><span class=\"token punctuation\">)</span>\nnames_regex<span class=\"token punctuation\">.</span>sub<span class=\"token punctuation\">(</span><span class=\"token string\">'CENSORED'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Agent Alice gave the secret documents to Agent Bob.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Another example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">agent_names_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Agent (\\w)\\w*'</span><span class=\"token punctuation\">)</span>\nagent_names_regex<span class=\"token punctuation\">.</span>sub<span class=\"token punctuation\">(</span><span class=\"token string\">r'\\1****'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Agent Alice told Agent Carol that Agent Eve knew Agent Bob was a double agent.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Managing Complex Regexes</h3>\n<p>To tell the re.compile() function to ignore whitespace and comments inside the regular expression string, \"verbose mode\" can be enabled by passing the variable re.VERBOSE as the second argument to re.compile().</p>\n<p>Now instead of a hard-to-read regular expression like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">phone_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'((\\d{3}|\\(\\d{3}\\))?(\\s|-|\\.)?\\d{3}(\\s|-|\\.)\\d{4}(\\s*(ext|x|ext.)\\s*\\d{2,5})?)'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>you can spread the regular expression over multiple lines with comments like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">phone_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token triple-quoted-string string\">r'''(\n    (\\d{3}|\\(\\d{3}\\))?            # area code\n    (\\s|-|\\.)?                    # separator\n    \\d{3}                         # first 3 digits\n    (\\s|-|\\.)                     # separator\n    \\d{4}                         # last 4 digits\n    (\\s*(ext|x|ext.)\\s*\\d{2,5})?  # extension\n    )'''</span><span class=\"token punctuation\">,</span> re<span class=\"token punctuation\">.</span>VERBOSE<span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Handling File and Directory Paths</h2>\n<p>There are two main modules in Python that deals with path manipulation.\nOne is the <code class=\"language-text\">os.path</code> module and the other is the <code class=\"language-text\">pathlib</code> module.\nThe <code class=\"language-text\">pathlib</code> module was added in Python 3.4, offering an object-oriented way\nto handle file system paths.</p>\n<h3>Backslash on Windows and Forward Slash on OS X and Linux</h3>\n<p>On Windows, paths are written using backslashes () as the separator between\nfolder names. On Unix based operating system such as macOS, Linux, and BSDs,\nthe forward slash (/) is used as the path separator. Joining paths can be\na headache if your code needs to work on different platforms.</p>\n<p>Fortunately, Python provides easy ways to handle this. We will showcase\nhow to deal with this with both <code class=\"language-text\">os.path.join</code> and <code class=\"language-text\">pathlib.Path.joinpath</code></p>\n<p>Using <code class=\"language-text\">os.path.join</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n\nos<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token string\">'usr'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'spam'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>And using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">(</span><span class=\"token string\">'usr'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>joinpath<span class=\"token punctuation\">(</span><span class=\"token string\">'bin'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>joinpath<span class=\"token punctuation\">(</span><span class=\"token string\">'spam'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">pathlib</code> also provides a shortcut to joinpath using the <code class=\"language-text\">/</code> operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">(</span><span class=\"token string\">'usr'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token string\">'bin'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'spam'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Notice the path separator is different between Windows and Unix based operating\nsystem, that's why you want to use one of the above methods instead of\nadding strings together to join paths together.</p>\n<p>Joining paths is helpful if you need to create different file paths under\nthe same directory.</p>\n<p>Using <code class=\"language-text\">os.path.join</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">my_files <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'accounts.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'details.csv'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'invite.docx'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token keyword\">for</span> filename <span class=\"token keyword\">in</span> my_files<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Users\\\\asweigart'</span><span class=\"token punctuation\">,</span> filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">my_files <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'accounts.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'details.csv'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'invite.docx'</span><span class=\"token punctuation\">]</span>\nhome <span class=\"token operator\">=</span> Path<span class=\"token punctuation\">.</span>home<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> filename <span class=\"token keyword\">in</span> my_files<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>home <span class=\"token operator\">/</span> filename<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>The Current Working Directory</h3>\n<p>Using <code class=\"language-text\">os</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n\nos<span class=\"token punctuation\">.</span>getcwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32'</span><span class=\"token punctuation\">)</span>\nos<span class=\"token punctuation\">.</span>getcwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token keyword\">from</span> os <span class=\"token keyword\">import</span> chdir\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'/usr/lib/python3.6'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Creating New Folders</h3>\n<p>Using <code class=\"language-text\">os</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n\nos<span class=\"token punctuation\">.</span>makedirs<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\delicious\\\\walnut\\\\waffles'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\ncwd <span class=\"token operator\">=</span> Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span>cwd <span class=\"token operator\">/</span> <span class=\"token string\">'delicious'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'walnut'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'waffles'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>mkdir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Oh no, we got a nasty error! The reason is that the 'delicious' directory does\nnot exist, so we cannot make the 'walnut' and the 'waffles' directories under\nit. To fix this, do:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\ncwd <span class=\"token operator\">=</span> Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span>cwd <span class=\"token operator\">/</span> <span class=\"token string\">'delicious'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'walnut'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'waffles'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>mkdir<span class=\"token punctuation\">(</span>parents<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>And all is good :)</p>\n<h3>Absolute vs. Relative Paths</h3>\n<p>There are two ways to specify a file path.</p>\n<ul>\n<li>An absolute path, which always begins with the root folder</li>\n<li>A relative path, which is relative to the program's current working directory</li>\n</ul>\n<p>There are also the dot (.) and dot-dot (..) folders. These are not real folders but special names that can be used in a path. A single period (\"dot\") for a folder name is shorthand for \"this directory.\" Two periods (\"dot-dot\") means \"the parent folder.\"</p>\n<h3>Handling Absolute and Relative Paths</h3>\n<p>To see if a path is an absolute path:</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n\nos<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isabs<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isabs<span class=\"token punctuation\">(</span><span class=\"token string\">'..'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\nPath<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_absolute<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Path<span class=\"token punctuation\">(</span><span class=\"token string\">'..'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_absolute<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can extract an absolute path with both <code class=\"language-text\">os.path</code> and <code class=\"language-text\">pathlib</code></p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n\nos<span class=\"token punctuation\">.</span>getcwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>abspath<span class=\"token punctuation\">(</span><span class=\"token string\">'..'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">(</span><span class=\"token string\">'..'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>resolve<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can get a relative path from a starting path to another path.</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n\nos<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>relpath<span class=\"token punctuation\">(</span><span class=\"token string\">'/etc/passwd'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/etc/passwd'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>relative_to<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Checking Path Validity</h3>\n<p>Checking if a file/directory exists:</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\nos<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token string\">'/etc'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token string\">'nonexistentfile'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\nPath<span class=\"token punctuation\">(</span><span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Path<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/etc'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Path<span class=\"token punctuation\">(</span><span class=\"token string\">'nonexistentfile'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Checking if a path is a file:</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\nos<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isfile<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isfile<span class=\"token punctuation\">(</span><span class=\"token string\">'/home'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isfile<span class=\"token punctuation\">(</span><span class=\"token string\">'nonexistentfile'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\nPath<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_file<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/home'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_file<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Path<span class=\"token punctuation\">(</span><span class=\"token string\">'nonexistentfile'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_file<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Checking if a path is a directory:</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\nos<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isdir<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isdir<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isdir<span class=\"token punctuation\">(</span><span class=\"token string\">'/spam'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\nPath<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_dir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Path<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_dir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/spam'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_dir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Finding File Sizes and Folder Contents</h3>\n<p>Getting a file's size in bytes:</p>\n<p>Using <code class=\"language-text\">os.path</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\nos<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>getsize<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32\\\\calc.exe'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\nstat <span class=\"token operator\">=</span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/bin/python3.6'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>stat<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>stat<span class=\"token punctuation\">)</span> <span class=\"token comment\"># stat contains some other information about the file as well</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>stat<span class=\"token punctuation\">.</span>st_size<span class=\"token punctuation\">)</span> <span class=\"token comment\"># size in bytes</span></code></pre></div>\n<p>Listing directory contents using <code class=\"language-text\">os.listdir</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\nos<span class=\"token punctuation\">.</span>listdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Listing directory contents using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\n<span class=\"token keyword\">for</span> f <span class=\"token keyword\">in</span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/usr/bin'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>iterdir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">)</span></code></pre></div>\n<p>To find the total size of all the files in this directory:</p>\n<p><strong>WARNING</strong>: Directories themselves also have a size! So you might want to\ncheck for whether a path is a file or directory using the methods in the methods discussed in the above section!</p>\n<p>Using <code class=\"language-text\">os.path.getsize()</code> and <code class=\"language-text\">os.listdir()</code> together on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n\ntotal_size <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n<span class=\"token keyword\">for</span> filename <span class=\"token keyword\">in</span> os<span class=\"token punctuation\">.</span>listdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      total_size <span class=\"token operator\">=</span> total_size <span class=\"token operator\">+</span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>getsize<span class=\"token punctuation\">(</span>os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32'</span><span class=\"token punctuation\">,</span> filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>total_size<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\ntotal_size <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n<span class=\"token keyword\">for</span> sub_path <span class=\"token keyword\">in</span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/usr/bin'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>iterdir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    total_size <span class=\"token operator\">+=</span> sub_path<span class=\"token punctuation\">.</span>stat<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>st_size\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>total_size<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Copying Files and Folders</h3>\n<p>The shutil module provides functions for copying files, as well as entire folders.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> shutil<span class=\"token punctuation\">,</span> os\n\nos<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\'</span><span class=\"token punctuation\">)</span>\n\nshutil<span class=\"token punctuation\">.</span>copy<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\spam.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\delicious'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">shutil<span class=\"token punctuation\">.</span>copy<span class=\"token punctuation\">(</span><span class=\"token string\">'eggs.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\delicious\\\\eggs2.txt'</span><span class=\"token punctuation\">)</span>\n   <span class=\"token string\">'C:\\\\delicious\\\\eggs2.txt'</span></code></pre></div>\n<p>While shutil.copy() will copy a single file, shutil.copytree() will copy an entire folder and every folder and file contained in it:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> shutil<span class=\"token punctuation\">,</span> os\n\nos<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\'</span><span class=\"token punctuation\">)</span>\nshutil<span class=\"token punctuation\">.</span>copytree<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\bacon'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\bacon_backup'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Moving and Renaming Files and Folders</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> shutil\n\nshutil<span class=\"token punctuation\">.</span>move<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\eggs'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The destination path can also specify a filename. In the following example, the source file is moved and renamed:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">shutil<span class=\"token punctuation\">.</span>move<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\eggs\\\\new_bacon.txt'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>If there is no eggs folder, then move() will rename bacon.txt to a file named eggs.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">shutil<span class=\"token punctuation\">.</span>move<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\eggs'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Permanently Deleting Files and Folders</h3>\n<ul>\n<li>Calling os.unlink(path) or Path.unlink() will delete the file at path.</li>\n<li>-</li>\n<li>Calling os.rmdir(path) or Path.rmdir() will delete the folder at path. This folder must be empty of any files or folders.</li>\n<li>Calling shutil.rmtree(path) will remove the folder at path, and all files and folders it contains will also be deleted.</li>\n</ul>\n<h3>Safe Deletes with the send2trash Module</h3>\n<p>You can install this module by running pip install send2trash from a Terminal window.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> send2trash\n\n<span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> bacon_file<span class=\"token punctuation\">:</span> <span class=\"token comment\"># creates the file</span>\n    bacon_file<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'Bacon is not a vegetable.'</span><span class=\"token punctuation\">)</span>\n\nsend2trash<span class=\"token punctuation\">.</span>send2trash<span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Walking a Directory Tree</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n\n<span class=\"token keyword\">for</span> folder_name<span class=\"token punctuation\">,</span> subfolders<span class=\"token punctuation\">,</span> filenames <span class=\"token keyword\">in</span> os<span class=\"token punctuation\">.</span>walk<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\delicious'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The current folder is {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>folder_name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n    <span class=\"token keyword\">for</span> subfolder <span class=\"token keyword\">in</span> subfolders<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'SUBFOLDER OF {}: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>folder_name<span class=\"token punctuation\">,</span> subfolder<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">for</span> filename <span class=\"token keyword\">in</span> filenames<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'FILE INSIDE {}: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>folder_name<span class=\"token punctuation\">,</span> filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">pathlib</code> provides a lot more functionality than the ones listed above,\nlike getting file name, getting file extension, reading/writing a file without\nmanually opening it, etc. Check out the\n<a href=\"https://docs.python.org/3/library/pathlib.html\">official documentation</a>\nif you want to know more!</p>\n<h2>Reading and Writing Files</h2>\n<h3>The File Reading/Writing Process</h3>\n<p>To read/write to a file in Python, you will want to use the <code class=\"language-text\">with</code>\nstatement, which will close the file for you after you are done.</p>\n<h3>Opening and reading files with the open function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Users\\\\your_home_folder\\\\hello.txt'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> hello_file<span class=\"token punctuation\">:</span>\n    hello_content <span class=\"token operator\">=</span> hello_file<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\nhello_content</code></pre></div>\n<p>Alternatively, you can use the <em>readlines()</em> method to get a list of string values from the file, one string for each line of text:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'sonnet29.txt'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> sonnet_file<span class=\"token punctuation\">:</span>\n    sonnet_file<span class=\"token punctuation\">.</span>readlines<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can also iterate through the file line by line:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'sonnet29.txt'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> sonnet_file<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> line <span class=\"token keyword\">in</span> sonnet_file<span class=\"token punctuation\">:</span> <span class=\"token comment\"># note the new line character will be included in the line</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>line<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Writing to Files</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'w'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> bacon_file<span class=\"token punctuation\">:</span>\n    bacon_file<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!\\n'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> bacon_file<span class=\"token punctuation\">:</span>\n    bacon_file<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'Bacon is not a vegetable.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> bacon_file<span class=\"token punctuation\">:</span>\n    content <span class=\"token operator\">=</span> bacon_file<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>content<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Saving Variables with the shelve Module</h3>\n<p>To save variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> shelve\n\ncats <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">with</span> shelve<span class=\"token punctuation\">.</span><span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'mydata'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> shelf_file<span class=\"token punctuation\">:</span>\n    shelf_file<span class=\"token punctuation\">[</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> cats</code></pre></div>\n<p>To open and read variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> shelve<span class=\"token punctuation\">.</span><span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'mydata'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> shelf_file<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>shelf_file<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>shelf_file<span class=\"token punctuation\">[</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Just like dictionaries, shelf values have keys() and values() methods that will return list-like values of the keys and values in the shelf. Since these methods return list-like values instead of true lists, you should pass them to the list() function to get them in list form.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> shelve<span class=\"token punctuation\">.</span><span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'mydata'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> shelf_file<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>shelf_file<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>shelf_file<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Saving Variables with pprint.pformat</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> pprint\n\ncats <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'desc'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'chubby'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'desc'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'fluffy'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\npprint<span class=\"token punctuation\">.</span>pformat<span class=\"token punctuation\">(</span>cats<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'myCats.py'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'w'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> file_obj<span class=\"token punctuation\">:</span>\n    file_obj<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'cats = {}\\n'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>pprint<span class=\"token punctuation\">.</span>pformat<span class=\"token punctuation\">(</span>cats<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Reading ZIP Files</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> zipfile<span class=\"token punctuation\">,</span> os\n\nos<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\'</span><span class=\"token punctuation\">)</span>    <span class=\"token comment\"># move to the folder with example.zip</span>\n<span class=\"token keyword\">with</span> zipfile<span class=\"token punctuation\">.</span>ZipFile<span class=\"token punctuation\">(</span><span class=\"token string\">'example.zip'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> example_zip<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>example_zip<span class=\"token punctuation\">.</span>namelist<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    spam_info <span class=\"token operator\">=</span> example_zip<span class=\"token punctuation\">.</span>getinfo<span class=\"token punctuation\">(</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam_info<span class=\"token punctuation\">.</span>file_size<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam_info<span class=\"token punctuation\">.</span>compress_size<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Compressed file is %sx smaller!'</span> <span class=\"token operator\">%</span> <span class=\"token punctuation\">(</span><span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span>spam_info<span class=\"token punctuation\">.</span>file_size <span class=\"token operator\">/</span> spam_info<span class=\"token punctuation\">.</span>compress_size<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Extracting from ZIP Files</h3>\n<p>The extractall() method for ZipFile objects extracts all the files and folders from a ZIP file into the current working directory.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> zipfile<span class=\"token punctuation\">,</span> os\n\nos<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\'</span><span class=\"token punctuation\">)</span>    <span class=\"token comment\"># move to the folder with example.zip</span>\n\n<span class=\"token keyword\">with</span> zipfile<span class=\"token punctuation\">.</span>ZipFile<span class=\"token punctuation\">(</span><span class=\"token string\">'example.zip'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> example_zip<span class=\"token punctuation\">:</span>\n    example_zip<span class=\"token punctuation\">.</span>extractall<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The extract() method for ZipFile objects will extract a single file from the ZIP file. Continue the interactive shell example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> zipfile<span class=\"token punctuation\">.</span>ZipFile<span class=\"token punctuation\">(</span><span class=\"token string\">'example.zip'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> example_zip<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>example_zip<span class=\"token punctuation\">.</span>extract<span class=\"token punctuation\">(</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>example_zip<span class=\"token punctuation\">.</span>extract<span class=\"token punctuation\">(</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\some\\\\new\\\\folders'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Creating and Adding to ZIP Files</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> zipfile\n\n<span class=\"token keyword\">with</span> zipfile<span class=\"token punctuation\">.</span>ZipFile<span class=\"token punctuation\">(</span><span class=\"token string\">'new.zip'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'w'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> new_zip<span class=\"token punctuation\">:</span>\n    new_zip<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">,</span> compress_type<span class=\"token operator\">=</span>zipfile<span class=\"token punctuation\">.</span>ZIP_DEFLATED<span class=\"token punctuation\">)</span></code></pre></div>\n<p>This code will create a new ZIP file named new.zip that has the compressed contents of spam.txt.</p>\n<h2>JSON, YAML and configuration files</h2>\n<h3>JSON</h3>\n<p>Open a JSON file with:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> json\n<span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"filename.json\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"r\"</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> f<span class=\"token punctuation\">:</span>\n    content <span class=\"token operator\">=</span> json<span class=\"token punctuation\">.</span>loads<span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Write a JSON file with:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> json\n\ncontent <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Joe\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"age\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">20</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"filename.json\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"w\"</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> f<span class=\"token punctuation\">:</span>\n    f<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span>json<span class=\"token punctuation\">.</span>dumps<span class=\"token punctuation\">(</span>content<span class=\"token punctuation\">,</span> indent<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>YAML</h3>\n<p>Compared to JSON, YAML allows a much better humain maintainance and gives ability to add comments.\nIt is a convinient choice for configuration files where human will have to edit.</p>\n<p>There are two main librairies allowing to access to YAML files:</p>\n<ul>\n<li><a href=\"https://pypi.python.org/pypi/PyYAML\">PyYaml</a></li>\n<li><a href=\"https://pypi.python.org/pypi/ruamel.yaml\">Ruamel.yaml</a></li>\n</ul>\n<p>Install them using <code class=\"language-text\">pip install</code> in your virtual environment.</p>\n<p>The first one it easier to use but the second one, Ruamel, implements much better the YAML\nspecification, and allow for example to modify a YAML content without altering comments.</p>\n<p>Open a YAML file with:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> ruamel<span class=\"token punctuation\">.</span>yaml <span class=\"token keyword\">import</span> YAML\n\n<span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"filename.yaml\"</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> f<span class=\"token punctuation\">:</span>\n    yaml<span class=\"token operator\">=</span>YAML<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    yaml<span class=\"token punctuation\">.</span>load<span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Anyconfig</h3>\n<p><a href=\"https://pypi.python.org/pypi/anyconfig\">Anyconfig</a> is a very handy package allowing to abstract completly the underlying configuration file format. It allows to load a Python dictionary from JSON, YAML, TOML, and so on.</p>\n<p>Install it with:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">pip <span class=\"token function\">install</span> anyconfig</code></pre></div>\n<p>Usage:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> anyconfig\n\nconf1 <span class=\"token operator\">=</span> anyconfig<span class=\"token punctuation\">.</span>load<span class=\"token punctuation\">(</span><span class=\"token string\">\"/path/to/foo/conf.d/a.yml\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Debugging</h2>\n<h3>Raising Exceptions</h3>\n<p>Exceptions are raised with a raise statement. In code, a raise statement consists of the following:</p>\n<ul>\n<li>The raise keyword</li>\n<li>A call to the Exception() function</li>\n<li>A string with a helpful error message passed to the Exception() function</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'This is the error message.'</span><span class=\"token punctuation\">)</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;pyshell#191>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'This is the error message.'</span><span class=\"token punctuation\">)</span>\nException<span class=\"token punctuation\">:</span> This <span class=\"token keyword\">is</span> the error message<span class=\"token punctuation\">.</span></code></pre></div>\n<p>Often it's the code that calls the function, not the function itself, that knows how to handle an expection. So you will commonly see a raise statement inside a function and the try and except statements in the code calling the function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">box_print</span><span class=\"token punctuation\">(</span>symbol<span class=\"token punctuation\">,</span> width<span class=\"token punctuation\">,</span> height<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>symbol<span class=\"token punctuation\">)</span> <span class=\"token operator\">!=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'Symbol must be a single character string.'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> width <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'Width must be greater than 2.'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> height <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'Height must be greater than 2.'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>symbol <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>height <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>symbol <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token string\">' '</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>width <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> symbol<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>symbol <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> sym<span class=\"token punctuation\">,</span> w<span class=\"token punctuation\">,</span> h <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">'*'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'O'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'x'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'ZZ'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span>\n        box_print<span class=\"token punctuation\">(</span>sym<span class=\"token punctuation\">,</span> w<span class=\"token punctuation\">,</span> h<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">except</span> Exception <span class=\"token keyword\">as</span> err<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'An exception happened: '</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Getting the Traceback as a String</h3>\n<p>The traceback is displayed by Python whenever a raised exception goes unhandled. But can also obtain it as a string by calling traceback.format_exc(). This function is useful if you want the information from an exception's traceback but also want an except statement to gracefully handle the exception. You will need to import Python's traceback module before calling this function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> traceback\n\n<span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span>\n     <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'This is the error message.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">except</span><span class=\"token punctuation\">:</span>\n     <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'errorInfo.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'w'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> error_file<span class=\"token punctuation\">:</span>\n         error_file<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span>traceback<span class=\"token punctuation\">.</span>format_exc<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The traceback info was written to errorInfo.txt.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The 116 is the return value from the write() method, since 116 characters were written to the file. The traceback text was written to errorInfo.txt.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Traceback (most recent call last):\n  File \"&lt;pyshell#28>\", line 2, in &lt;module>\nException: This is the error message.</code></pre></div>\n<h3>Assertions</h3>\n<p>An assertion is a sanity check to make sure your code isn't doing something obviously wrong. These sanity checks are performed by assert statements. If the sanity check fails, then an AssertionError exception is raised. In code, an assert statement consists of the following:</p>\n<ul>\n<li>The assert keyword</li>\n<li>A condition (that is, an expression that evaluates to True or False)</li>\n<li>A comma</li>\n<li>A string to display when the condition is False</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">pod_bay_door_status <span class=\"token operator\">=</span> <span class=\"token string\">'open'</span>\n\n<span class=\"token keyword\">assert</span> pod_bay_door_status <span class=\"token operator\">==</span> <span class=\"token string\">'open'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The pod bay doors need to be \"open\".'</span>\n\npod_bay_door_status <span class=\"token operator\">=</span> <span class=\"token string\">'I\\'m sorry, Dave. I\\'m afraid I can\\'t do that.'</span>\n\n<span class=\"token keyword\">assert</span> pod_bay_door_status <span class=\"token operator\">==</span> <span class=\"token string\">'open'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The pod bay doors need to be \"open\".'</span></code></pre></div>\n<p>In plain English, an assert statement says, \"I assert that this condition holds true, and if not, there is a bug somewhere in the program.\" Unlike exceptions, your code should not handle assert statements with try and except; if an assert fails, your program should crash. By failing fast like this, you shorten the time between the original cause of the bug and when you first notice the bug. This will reduce the amount of code you will have to check before finding the code that's causing the bug.</p>\n<p>Disabling Assertions</p>\n<p>Assertions can be disabled by passing the -O option when running Python.</p>\n<h3>Logging</h3>\n<p>To enable the logging module to display log messages on your screen as your program runs, copy the following to the top of your program (but under the #! python shebang line):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> logging\n\nlogging<span class=\"token punctuation\">.</span>basicConfig<span class=\"token punctuation\">(</span>level<span class=\"token operator\">=</span>logging<span class=\"token punctuation\">.</span>DEBUG<span class=\"token punctuation\">,</span> <span class=\"token builtin\">format</span><span class=\"token operator\">=</span><span class=\"token string\">' %(asctime)s - %(levelname)s- %(message)s'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Say you wrote a function to calculate the factorial of a number. In mathematics, factorial 4 is 1 × 2 × 3 × 4, or 24. Factorial 7 is 1 × 2 × 3 × 4 × 5 × 6 × 7, or 5,040. Open a new file editor window and enter the following code. It has a bug in it, but you will also enter several log messages to help yourself figure out what is going wrong. Save the program as factorialLog.py.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> logging\n\nlogging<span class=\"token punctuation\">.</span>basicConfig<span class=\"token punctuation\">(</span>level<span class=\"token operator\">=</span>logging<span class=\"token punctuation\">.</span>DEBUG<span class=\"token punctuation\">,</span> <span class=\"token builtin\">format</span><span class=\"token operator\">=</span><span class=\"token string\">' %(asctime)s - %(levelname)s- %(message)s'</span><span class=\"token punctuation\">)</span>\n\nlogging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'Start of program'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n\n    logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'Start of factorial(%s)'</span> <span class=\"token operator\">%</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    total <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        total <span class=\"token operator\">*=</span> i\n        logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'i is '</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">', total is '</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>total<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n    logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'End of factorial(%s)'</span> <span class=\"token operator\">%</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n    <span class=\"token keyword\">return</span> total\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>factorial<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nlogging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'End of program'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Logging Levels</h3>\n<p>Logging levels provide a way to categorize your log messages by importance. There are five logging levels, described in Table 10-1 from least to most important. Messages can be logged at each level using a different logging function.</p>\n<table>\n<thead>\n<tr>\n<th>Level</th>\n<th>Logging Function</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">DEBUG</code></td>\n<td><code class=\"language-text\">logging.debug()</code></td>\n<td>The lowest level. Used for small details. Usually you care about these messages only when diagnosing problems.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">INFO</code></td>\n<td><code class=\"language-text\">logging.info()</code></td>\n<td>Used to record information on general events in your program or confirm that things are working at their point in the program.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">WARNING</code></td>\n<td><code class=\"language-text\">logging.warning()</code></td>\n<td>Used to indicate a potential problem that doesn't prevent the program from working but might do so in the future.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">ERROR</code></td>\n<td><code class=\"language-text\">logging.error()</code></td>\n<td>Used to record an error that caused the program to fail to do something.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">CRITICAL</code></td>\n<td><code class=\"language-text\">logging.critical()</code></td>\n<td>The highest level. Used to indicate a fatal error that has caused or is about to cause the program to stop running entirely.</td>\n</tr>\n</tbody>\n</table>\n<h3>Disabling Logging</h3>\n<p>After you've debugged your program, you probably don't want all these log messages cluttering the screen. The logging.disable() function disables these so that you don't have to go into your program and remove all the logging calls by hand.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> logging\n\nlogging<span class=\"token punctuation\">.</span>basicConfig<span class=\"token punctuation\">(</span>level<span class=\"token operator\">=</span>logging<span class=\"token punctuation\">.</span>INFO<span class=\"token punctuation\">,</span> <span class=\"token builtin\">format</span><span class=\"token operator\">=</span><span class=\"token string\">' %(asctime)s -%(levelname)s - %(message)s'</span><span class=\"token punctuation\">)</span>\nlogging<span class=\"token punctuation\">.</span>critical<span class=\"token punctuation\">(</span><span class=\"token string\">'Critical error! Critical error!'</span><span class=\"token punctuation\">)</span>\nlogging<span class=\"token punctuation\">.</span>disable<span class=\"token punctuation\">(</span>logging<span class=\"token punctuation\">.</span>CRITICAL<span class=\"token punctuation\">)</span>\nlogging<span class=\"token punctuation\">.</span>critical<span class=\"token punctuation\">(</span><span class=\"token string\">'Critical error! Critical error!'</span><span class=\"token punctuation\">)</span>\nlogging<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">(</span><span class=\"token string\">'Error! Error!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Logging to a File</h3>\n<p>Instead of displaying the log messages to the screen, you can write them to a text file. The logging.basicConfig() function takes a filename keyword argument, like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> logging\n\nlogging<span class=\"token punctuation\">.</span>basicConfig<span class=\"token punctuation\">(</span>filename<span class=\"token operator\">=</span><span class=\"token string\">'myProgramLog.txt'</span><span class=\"token punctuation\">,</span> level<span class=\"token operator\">=</span>logging<span class=\"token punctuation\">.</span>DEBUG<span class=\"token punctuation\">,</span> <span class=\"token builtin\">format</span><span class=\"token operator\">=</span><span class=\"token string\">'%(asctime)s - %(levelname)s - %(message)s'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2>Lambda Functions</h2>\n<p>This function:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> x <span class=\"token operator\">+</span> y\n\nadd<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Is equivalent to the <em>lambda</em> function:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">add <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> y\nadd<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>It's not even need to bind it to a name like add before:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Like regular nested functions, lambdas also work as lexical closures:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">make_adder</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> n\n\nplus_3 <span class=\"token operator\">=</span> make_adder<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\nplus_5<span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Note: lambda can only evaluate an expression, like a single line of code.</p>\n<h2>Ternary Conditional Operator</h2>\n<p>Many programming languages have a ternary operator, which define a conditional expression. The most common usage is to make a terse simple conditional assignment statement. In other words, it offers one-line code to evaluate the first expression if the condition is true, otherwise it evaluates the second expression.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;expression1> if &lt;condition> else &lt;expression2></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">age <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'kid'</span> <span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">18</span> <span class=\"token keyword\">else</span> <span class=\"token string\">'adult'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Ternary operators can be changed:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">age <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'kid'</span> <span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">13</span> <span class=\"token keyword\">else</span> <span class=\"token string\">'teenager'</span> <span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">18</span> <span class=\"token keyword\">else</span> <span class=\"token string\">'adult'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The code above is equivalent to:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">18</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'kid'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'teenager'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'adult'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2>args and kwargs</h2>\n<p>The names <code class=\"language-text\">args and kwargs</code> are arbitrary - the important thing are the <code class=\"language-text\">*</code> and <code class=\"language-text\">**</code> operators. They can mean:</p>\n<ol>\n<li>In a function declaration, <code class=\"language-text\">*</code> means \"pack all remaining positional arguments into a tuple named <code class=\"language-text\">&lt;name></code>\", while <code class=\"language-text\">**</code> is the same for keyword arguments (except it uses a dictionary, not a tuple).</li>\n<li>In a function call, <code class=\"language-text\">*</code> means \"unpack tuple or list named <code class=\"language-text\">&lt;name></code> to positional arguments at this position\", while <code class=\"language-text\">**</code> is the same for keyword arguments.</li>\n</ol>\n<p>For example you can make a function that you can use to call any other function, no matter what parameters it has:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">forward</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> f<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Inside forward, args is a tuple (of all positional arguments except the first one, because we specified it - the f), kwargs is a dict. Then we call f and unpack them so they become normal arguments to f.</p>\n<p>You use <code class=\"language-text\">*args</code> when you have an indefinite amount of positional arguments.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">fruits</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">for</span> fruit <span class=\"token keyword\">in</span> args<span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>fruit<span class=\"token punctuation\">)</span>\n\nfruits<span class=\"token punctuation\">(</span><span class=\"token string\">\"apples\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"bananas\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"grapes\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Similarly, you use <code class=\"language-text\">**kwargs</code> when you have an indefinite number of keyword arguments.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">fruit</span><span class=\"token punctuation\">(</span><span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n   <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> kwargs<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0}: {1}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\nfruit<span class=\"token punctuation\">(</span>name <span class=\"token operator\">=</span> <span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> color <span class=\"token operator\">=</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">show</span><span class=\"token punctuation\">(</span>arg1<span class=\"token punctuation\">,</span> arg2<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> kwarg1<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> kwarg2<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>arg1<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>arg2<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>kwarg1<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>kwarg2<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>kwargs<span class=\"token punctuation\">)</span>\n\ndata1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\ndata2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">]</span>\ndata3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span><span class=\"token number\">9</span><span class=\"token punctuation\">}</span>\n\nshow<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>data1<span class=\"token punctuation\">,</span><span class=\"token operator\">*</span>data2<span class=\"token punctuation\">,</span> kwarg1<span class=\"token operator\">=</span><span class=\"token string\">\"python\"</span><span class=\"token punctuation\">,</span>kwarg2<span class=\"token operator\">=</span><span class=\"token string\">\"cheatsheet\"</span><span class=\"token punctuation\">,</span><span class=\"token operator\">**</span>data3<span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">show<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>data1<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>data2<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>data3<span class=\"token punctuation\">)</span></code></pre></div>\n<p>If you do not specify ** for kwargs</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">show<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>data1<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>data2<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>data3<span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Thinks to Remember(args)</h3>\n<ol>\n<li>Functions can accept a variable number of positional arguments by using <code class=\"language-text\">*args</code> in the def statement.</li>\n<li>You can use the items from a sequence as the positional arguments for a function with the <code class=\"language-text\">*</code> operator.</li>\n<li>Using the <code class=\"language-text\">*</code> operator with a generator may cause your program to run out of memory and crash.</li>\n<li>Adding new positional parameters to functions that accept <code class=\"language-text\">*args</code> can introduce hard-to-find bugs.</li>\n</ol>\n<h3>Thinks to remember(kwargs)</h3>\n<ol>\n<li>Function arguments can be specified by position or by keyword.</li>\n<li>Keywords make it clear what the purpose of each argument is when it would be confusing with only positional arguments.</li>\n<li>Keyword arguments with default values make it easy to add new behaviors to a function, especially when the function has existing callers.</li>\n<li>Optional keyword arguments should always be passed by keyword instead of by position.</li>\n</ol>\n<h2>Context Manager</h2>\n<p>While Python's context managers are widely used, few understand the purpose behind their use. These statements, commonly used with reading and writing files, assist the application in conserving system memory and improve resource management by ensuring specific resources are only in use for certain processes.</p>\n<h3>with statement</h3>\n<p>A context manager is an object that is notified when a context (a block of code) starts and ends. You commonly use one with the with statement. It takes care of the notifying.</p>\n<p>For example, file objects are context managers. When a context ends, the file object is closed automatically:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> f<span class=\"token punctuation\">:</span>\n    file_contents <span class=\"token operator\">=</span> f<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># the open_file object has automatically been closed.</span></code></pre></div>\n<p>Anything that ends execution of the block causes the context manager's exit method to be called. This includes exceptions, and can be useful when an error causes you to prematurely exit from an open file or connection. Exiting a script without properly closing files/connections is a bad idea, that may cause data loss or other problems. By using a context manager you can ensure that precautions are always taken to prevent damage or loss in this way.</p>\n<h3>Writing your own contextmanager using generator syntax</h3>\n<p>It is also possible to write a context manager using generator syntax thanks to the <code class=\"language-text\">contextlib.contextmanager</code> decorator:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> contextlib\n\n<span class=\"token decorator annotation punctuation\">@contextlib<span class=\"token punctuation\">.</span>contextmanager</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">context_manager</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Enter'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">yield</span> num <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Exit'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">with</span> context_manager<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> cm<span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># the following instructions are run when the 'yield' point of the context</span>\n    <span class=\"token comment\"># manager is reached.</span>\n    <span class=\"token comment\"># 'cm' will have the value that was yielded</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Right in the middle with cm = {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>cm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h2><code class=\"language-text\">__main__</code> Top-level script environment</h2>\n<p><code class=\"language-text\">__main__</code> is the name of the scope in which top-level code executes.\nA module's <strong>name</strong> is set equal to <code class=\"language-text\">__main__</code> when read from standard input, a script, or from an interactive prompt.</p>\n<p>A module can discover whether or not it is running in the main scope by checking its own <code class=\"language-text\">__name__</code>, which allows a common idiom for conditionally executing code in a module when it is run as a script or with <code class=\"language-text\">python -m</code> but not when it is imported:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> __name__ <span class=\"token operator\">==</span> <span class=\"token string\">\"__main__\"</span><span class=\"token punctuation\">:</span>\n    <span class=\"token comment\"># execute only if run as a script</span>\n    main<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>For a package, the same effect can be achieved by including a <strong>main</strong>.py module, the contents of which will be executed when the module is run with -m.</p>\n<p>For example we are developing script which is designed to be used as module, we should do:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Python program to execute function directly</span>\n<span class=\"token keyword\">def</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> a<span class=\"token operator\">+</span>b\n\nadd<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># we can test it by calling the function save it as calculate.py</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Now if we want to use that module by importing we have to comment out our call,</span>\n<span class=\"token comment\"># Instead we can write like this in calculate.py</span>\n<span class=\"token keyword\">if</span> __name__ <span class=\"token operator\">==</span> <span class=\"token string\">\"__main__\"</span><span class=\"token punctuation\">:</span>\n    add<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> calculate\n\ncalculate<span class=\"token punctuation\">.</span>add<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Advantages</h3>\n<ol>\n<li>Every Python module has it's <code class=\"language-text\">__name__</code> defined and if this is <code class=\"language-text\">__main__</code>, it implies that the module is being run standalone by the user and we can do corresponding appropriate actions.</li>\n<li>If you import this script as a module in another script, the <strong>name</strong> is set to the name of the script/module.</li>\n<li>Python files can act as either reusable modules, or as standalone programs.</li>\n<li>if <code class=\"language-text\">__name__ == \"main\":</code> is used to execute some code only if the file was run directly, and not imported.</li>\n</ol>\n<h2>setup.py</h2>\n<p>The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the setup script is to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing.</p>\n<p>The <code class=\"language-text\">setup.py</code> file is at the heart of a Python project. It describes all of the metadata about your project. There a quite a few fields you can add to a project to give it a rich set of metadata describing the project. However, there are only three required fields: name, version, and packages. The name field must be unique if you wish to publish your package on the Python Package Index (PyPI). The version field keeps track of different releases of the project. The packages field describes where you've put the Python source code within your project.</p>\n<p>This allows you to easily install Python packages. Often it's enough to write:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">python setup.py <span class=\"token function\">install</span></code></pre></div>\n<p>and module will install itself.</p>\n<p>Our initial setup.py will also include information about the license and will re-use the README.txt file for the long_description field. This will look like:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> distutils<span class=\"token punctuation\">.</span>core <span class=\"token keyword\">import</span> setup\nsetup<span class=\"token punctuation\">(</span>\n   name<span class=\"token operator\">=</span><span class=\"token string\">'pythonCheatsheet'</span><span class=\"token punctuation\">,</span>\n   version<span class=\"token operator\">=</span><span class=\"token string\">'0.1'</span><span class=\"token punctuation\">,</span>\n   packages<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span><span class=\"token string\">'pipenv'</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n   license<span class=\"token operator\">=</span><span class=\"token string\">'MIT'</span><span class=\"token punctuation\">,</span>\n   long_description<span class=\"token operator\">=</span><span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'README.txt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Find more information visit <a href=\"http://docs.python.org/install/index.html\">http://docs.python.org/install/index.html</a>.</p>\n<h2>Dataclasses</h2>\n<p><code class=\"language-text\">Dataclasses</code> are python classes but are suited for storing data objects.\nThis module provides a decorator and functions for automatically adding generated special methods such as <code class=\"language-text\">__init__()</code> and <code class=\"language-text\">__repr__()</code> to user-defined classes.</p>\n<h3>Features</h3>\n<ol>\n<li>They store data and represent a certain data type. Ex: A number. For people familiar with ORMs, a model instance is a data object. It represents a specific kind of entity. It holds attributes that define or represent the entity.</li>\n<li>They can be compared to other objects of the same type. Ex: A number can be greater than, less than, or equal to another number.</li>\n</ol>\n<p>Python 3.7 provides a decorator dataclass that is used to convert a class into a dataclass.</p>\n<p>python 2.7</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        self<span class=\"token punctuation\">.</span>val <span class=\"token operator\">=</span> val\n\nobj <span class=\"token operator\">=</span> Number<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\nobj<span class=\"token punctuation\">.</span>val</code></pre></div>\n<p>with dataclass</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> dataclasses <span class=\"token keyword\">import</span> dataclass\n\n<span class=\"token decorator annotation punctuation\">@dataclass</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">:</span>\n    val<span class=\"token punctuation\">:</span> <span class=\"token builtin\">int</span>\n\nobj <span class=\"token operator\">=</span> Number<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\nobj<span class=\"token punctuation\">.</span>val</code></pre></div>\n<h3>Default values</h3>\n<p>It is easy to add default values to the fields of your data class.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> dataclasses <span class=\"token keyword\">import</span> dataclass\n\n<span class=\"token decorator annotation punctuation\">@dataclass</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Product</span><span class=\"token punctuation\">:</span>\n    name<span class=\"token punctuation\">:</span> <span class=\"token builtin\">str</span>\n    count<span class=\"token punctuation\">:</span> <span class=\"token builtin\">int</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n    price<span class=\"token punctuation\">:</span> <span class=\"token builtin\">float</span> <span class=\"token operator\">=</span> <span class=\"token number\">0.0</span>\n\nobj <span class=\"token operator\">=</span> Product<span class=\"token punctuation\">(</span><span class=\"token string\">\"Python\"</span><span class=\"token punctuation\">)</span>\nobj<span class=\"token punctuation\">.</span>name</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">obj<span class=\"token punctuation\">.</span>count</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">obj<span class=\"token punctuation\">.</span>price</code></pre></div>\n<h3>Type hints</h3>\n<p>It is mandatory to define the data type in dataclass. However, If you don't want specify the datatype then, use <code class=\"language-text\">typing.Any</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> dataclasses <span class=\"token keyword\">import</span> dataclass\n<span class=\"token keyword\">from</span> typing <span class=\"token keyword\">import</span> Any\n\n<span class=\"token decorator annotation punctuation\">@dataclass</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">WithoutExplicitTypes</span><span class=\"token punctuation\">:</span>\n   name<span class=\"token punctuation\">:</span> Any\n   value<span class=\"token punctuation\">:</span> Any <span class=\"token operator\">=</span> <span class=\"token number\">42</span></code></pre></div>\n<hr>\n<hr>\n<hr>\n<hr>\n<h1>PART 2:</h1>\n<h1>Single line comments start with a number symbol.</h1>\n<p>\"\"\" Multiline strings can be written\nusing three \"s, and are often used\nas documentation.\n\"\"\"</p>\n<p>####################################################</p>\n<h2>1. Primitive Datatypes and Operators</h2>\n<p>####################################################</p>\n<h1>You have numbers</h1>\n<p>3 # => 3</p>\n<h1>Math is what you would expect</h1>\n<p>1 + 1 # => 2\n8 - 1 # => 7\n10 * 2 # => 20\n35 / 5 # => 7.0</p>\n<h1>Integer division rounds down for both positive and negative numbers.</h1>\n<p>5 // 3 # => 1\n-5 // 3 # => -2\n5.0 // 3.0 # => 1.0 # works on floats too\n-5.0 // 3.0 # => -2.0</p>\n<h1>The result of division is always a float</h1>\n<p>10.0 / 3 # => 3.3333333333333335</p>\n<h1>Modulo operation</h1>\n<p>7 % 3 # => 1</p>\n<h1>Exponentiation (x**y, x to the yth power)</h1>\n<p>2**3 # => 8</p>\n<h1>Enforce precedence with parentheses</h1>\n<p>(1 + 3) * 2 # => 8</p>\n<h1>Boolean values are primitives (Note: the capitalization)</h1>\n<p>True\nFalse</p>\n<h1>negate with not</h1>\n<p>not True # => False\nnot False # => True</p>\n<h1>Boolean Operators</h1>\n<h1>Note \"and\" and \"or\" are case-sensitive</h1>\n<p>True and False # => False\nFalse or True # => True</p>\n<h1>True and False are actually 1 and 0 but with different keywords</h1>\n<p>True + True # => 2\nTrue * 8 # => 8\nFalse - 5 # => -5</p>\n<h1>Comparison operators look at the numerical value of True and False</h1>\n<p>0 == False # => True\n1 == True # => True\n2 == True # => False\n-5 != False # => True</p>\n<h1>Using boolean logical operators on ints casts them to booleans for evaluation, but their non-cast value is returned</h1>\n<h1>Don't mix up with bool(ints) and bitwise and/or (&#x26;,|)</h1>\n<p>bool(0) # => False\nbool(4) # => True\nbool(-6) # => True\n0 and 2 # => 0\n-5 or 0 # => -5</p>\n<h1>Equality is ==</h1>\n<p>1 == 1 # => True\n2 == 1 # => False</p>\n<h1>Inequality is !=</h1>\n<p>1 != 1 # => False\n2 != 1 # => True</p>\n<h1>More comparisons</h1>\n<p>1 &#x3C; 10 # => True\n1 > 10 # => False\n2 &#x3C;= 2 # => True\n2 >= 2 # => True</p>\n<h1>Seeing whether a value is in a range</h1>\n<p>1 &#x3C; 2 and 2 &#x3C; 3 # => True\n2 &#x3C; 3 and 3 &#x3C; 2 # => False</p>\n<h1>Chaining makes this look nicer</h1>\n<p>1 &#x3C; 2 &#x3C; 3 # => True\n2 &#x3C; 3 &#x3C; 2 # => False</p>\n<h1>(is vs. ==) is checks if two variables refer to the same object, but == checks</h1>\n<h1>if the objects pointed to have the same values.</h1>\n<p>a = [1, 2, 3, 4] # Point a at a new list, [1, 2, 3, 4]\nb = a # Point b at what a is pointing to\nb is a # => True, a and b refer to the same object\nb == a # => True, a's and b's objects are equal\nb = [1, 2, 3, 4] # Point b at a new list, [1, 2, 3, 4]\nb is a # => False, a and b do not refer to the same object\nb == a # => True, a's and b's objects are equal</p>\n<h1>Strings are created with \" or '</h1>\n<p>\"This is a string.\"\n'This is also a string.'</p>\n<h1>Strings can be added too! But try not to do this.</h1>\n<p>\"Hello \" + \"world!\" # => \"Hello world!\"</p>\n<h1>String literals (but not variables) can be concatenated without using '+'</h1>\n<p>\"Hello \" \"world!\" # => \"Hello world!\"</p>\n<h1>A string can be treated like a list of characters</h1>\n<p>\"This is a string\"[0] # => 'T'</p>\n<h1>You can find the length of a string</h1>\n<p>len(\"This is a string\") # => 16</p>\n<h1>.format can be used to format strings, like this:</h1>\n<p>\"{} can be {}\".format(\"Strings\", \"interpolated\") # => \"Strings can be interpolated\"</p>\n<h1>You can repeat the formatting arguments to save some typing.</h1>\n<p>\"{0} be nimble, {0} be quick, {0} jump over the {1}\".format(\"Jack\", \"candle stick\")</p>\n<h1>=> \"Jack be nimble, Jack be quick, Jack jump over the candle stick\"</h1>\n<h1>You can use keywords if you don't want to count.</h1>\n<p>\"{name} wants to eat {food}\".format(name=\"Bob\", food=\"lasagna\") # => \"Bob wants to eat lasagna\"</p>\n<h1>If your Python 3 code also needs to run on Python 2.5 and below, you can also</h1>\n<h1>still use the old style of formatting:</h1>\n<p>\"%s can be %s the %s way\" % (\"Strings\", \"interpolated\", \"old\") # => \"Strings can be interpolated the old way\"</p>\n<h1>You can also format using f-strings or formatted string literals (in Python 3.6+)</h1>\n<p>name = \"Reiko\"\nf\"She said her name is {name}.\" # => \"She said her name is Reiko\"</p>\n<h1>You can basically put any Python statement inside the braces and it will be output in the string.</h1>\n<p>f\"{name} is {len(name)} characters long.\" # => \"Reiko is 5 characters long.\"</p>\n<h1>None is an object</h1>\n<p>None # => None</p>\n<h1>Don't use the equality \"==\" symbol to compare objects to None</h1>\n<h1>Use \"is\" instead. This checks for equality of object identity.</h1>\n<p>\"etc\" is None # => False\nNone is None # => True</p>\n<h1>None, 0, and empty strings/lists/dicts/tuples all evaluate to False.</h1>\n<h1>All other values are True</h1>\n<p>bool(0) # => False\nbool(\"\") # => False\nbool([]) # => False\nbool({}) # => False\nbool(()) # => False</p>\n<p>####################################################</p>\n<h2>2. Variables and Collections</h2>\n<p>####################################################</p>\n<h1>Python has a print function</h1>\n<p>print(\"I'm Python. Nice to meet you!\") # => I'm Python. Nice to meet you!</p>\n<h1>By default the print function also prints out a newline at the end.</h1>\n<h1>Use the optional argument end to change the end string.</h1>\n<p>print(\"Hello, World\", end=\"!\") # => Hello, World!</p>\n<h1>Simple way to get input data from console</h1>\n<p>input<em>string</em>var = input(\"Enter some data: \") # Returns the data as a string</p>\n<h1>Note: In earlier versions of Python, input() method was named as raw_input()</h1>\n<h1>There are no declarations, only assignments.</h1>\n<h1>Convention is to use lower<em>case</em>with_underscores</h1>\n<p>some<em>var = 5\nsome</em>var # => 5</p>\n<h1>Accessing a previously unassigned variable is an exception.</h1>\n<h1>See Control Flow to learn more about exception handling.</h1>\n<p>some<em>unknown</em>var # Raises a NameError</p>\n<h1>if can be used as an expression</h1>\n<h1>Equivalent of C's '?:' ternary operator</h1>\n<p>\"yahoo!\" if 3 > 2 else 2 # => \"yahoo!\"</p>\n<h1>Lists store sequences</h1>\n<p>li = []</p>\n<h1>You can start with a prefilled list</h1>\n<p>other_li = [4, 5, 6]</p>\n<h1>Add stuff to the end of a list with append</h1>\n<p>li.append(1) # li is now [1]\nli.append(2) # li is now [1, 2]\nli.append(4) # li is now [1, 2, 4]\nli.append(3) # li is now [1, 2, 4, 3]</p>\n<h1>Remove from the end with pop</h1>\n<p>li.pop() # => 3 and li is now [1, 2, 4]</p>\n<h1>Let's put it back</h1>\n<p>li.append(3) # li is now [1, 2, 4, 3] again.</p>\n<h1>Access a list like you would any array</h1>\n<p>li[0] # => 1</p>\n<h1>Look at the last element</h1>\n<p>li[-1] # => 3</p>\n<h1>Looking out of bounds is an IndexError</h1>\n<p>li[4] # Raises an IndexError</p>\n<h1>You can look at ranges with slice syntax.</h1>\n<h1>The start index is included, the end index is not</h1>\n<h1>(It's a closed/open range for you mathy types.)</h1>\n<p>li[1:3] # Return list from index 1 to 3 => [2, 4]\nli[2:] # Return list starting from index 2 => [4, 3]\nli[:3] # Return list from beginning until index 3 => [1, 2, 4]\nli[::2] # Return list selecting every second entry => [1, 4]\nli[::-1] # Return list in reverse order => [3, 4, 2, 1]</p>\n<h1>Use any combination of these to make advanced slices</h1>\n<h1>li[start:end:step]</h1>\n<h1>Make a one layer deep copy using slices</h1>\n<p>li2 = li[:] # => li2 = [1, 2, 4, 3] but (li2 is li) will result in false.</p>\n<h1>Remove arbitrary elements from a list with \"del\"</h1>\n<p>del li[2] # li is now [1, 2, 3]</p>\n<h1>Remove first occurrence of a value</h1>\n<p>li.remove(2) # li is now [1, 3]\nli.remove(2) # Raises a ValueError as 2 is not in the list</p>\n<h1>Insert an element at a specific index</h1>\n<p>li.insert(1, 2) # li is now [1, 2, 3] again</p>\n<h1>Get the index of the first item found matching the argument</h1>\n<p>li.index(2) # => 1\nli.index(4) # Raises a ValueError as 4 is not in the list</p>\n<h1>You can add lists</h1>\n<h1>Note: values for li and for other_li are not modified.</h1>\n<p>li + other_li # => [1, 2, 3, 4, 5, 6]</p>\n<h1>Concatenate lists with \"extend()\"</h1>\n<p>li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]</p>\n<h1>Check for existence in a list with \"in\"</h1>\n<p>1 in li # => True</p>\n<h1>Examine the length with \"len()\"</h1>\n<p>len(li) # => 6</p>\n<h1>Tuples are like lists but are immutable.</h1>\n<p>tup = (1, 2, 3)\ntup[0] # => 1\ntup[0] = 3 # Raises a TypeError</p>\n<h1>Note that a tuple of length one has to have a comma after the last element but</h1>\n<h1>tuples of other lengths, even zero, do not.</h1>\n<p>type((1)) # => &#x3C;class 'int'>\ntype((1,)) # => &#x3C;class 'tuple'>\ntype(()) # => &#x3C;class 'tuple'></p>\n<h1>You can do most of the list operations on tuples too</h1>\n<p>len(tup) # => 3\ntup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6)\ntup[:2] # => (1, 2)\n2 in tup # => True</p>\n<h1>You can unpack tuples (or lists) into variables</h1>\n<p>a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3</p>\n<h1>You can also do extended unpacking</h1>\n<p>a, *b, c = (1, 2, 3, 4) # a is now 1, b is now [2, 3] and c is now 4</p>\n<h1>Tuples are created by default if you leave out the parentheses</h1>\n<p>d, e, f = 4, 5, 6 # tuple 4, 5, 6 is unpacked into variables d, e and f</p>\n<h1>respectively such that d = 4, e = 5 and f = 6</h1>\n<h1>Now look how easy it is to swap two values</h1>\n<p>e, d = d, e # d is now 5 and e is now 4</p>\n<h1>Dictionaries store mappings from keys to values</h1>\n<p>empty_dict = {}</p>\n<h1>Here is a prefilled dictionary</h1>\n<p>filled_dict = {\"one\": 1, \"two\": 2, \"three\": 3}</p>\n<h1>Note keys for dictionaries have to be immutable types. This is to ensure that</h1>\n<h1>the key can be converted to a constant hash value for quick look-ups.</h1>\n<h1>Immutable types include ints, floats, strings, tuples.</h1>\n<p>invalid<em>dict = {[1,2,3]: \"123\"} # => Raises a TypeError: unhashable type: 'list'\nvalid</em>dict = {(1,2,3):[1,2,3]} # Values can be of any type, however.</p>\n<h1>Look up values with []</h1>\n<p>filled_dict[\"one\"] # => 1</p>\n<h1>Get all keys as an iterable with \"keys()\". We need to wrap the call in list()</h1>\n<h1>to turn it into a list. We'll talk about those later. Note - for Python</h1>\n<h1>versions &#x3C;3.7, dictionary key ordering is not guaranteed. Your results might</h1>\n<h1>not match the example below exactly. However, as of Python 3.7, dictionary</h1>\n<h1>items maintain the order at which they are inserted into the dictionary.</h1>\n<p>list(filled<em>dict.keys()) # => [\"three\", \"two\", \"one\"] in Python &#x3C;3.7\nlist(filled</em>dict.keys()) # => [\"one\", \"two\", \"three\"] in Python 3.7+</p>\n<h1>Get all values as an iterable with \"values()\". Once again we need to wrap it</h1>\n<h1>in list() to get it out of the iterable. Note - Same as above regarding key</h1>\n<h1>ordering.</h1>\n<p>list(filled<em>dict.values()) # => [3, 2, 1] in Python &#x3C;3.7\nlist(filled</em>dict.values()) # => [1, 2, 3] in Python 3.7+</p>\n<h1>Check for existence of keys in a dictionary with \"in\"</h1>\n<p>\"one\" in filled<em>dict # => True\n1 in filled</em>dict # => False</p>\n<h1>Looking up a non-existing key is a KeyError</h1>\n<p>filled_dict[\"four\"] # KeyError</p>\n<h1>Use \"get()\" method to avoid the KeyError</h1>\n<p>filled<em>dict.get(\"one\") # => 1\nfilled</em>dict.get(\"four\") # => None</p>\n<h1>The get method supports a default argument when the value is missing</h1>\n<p>filled<em>dict.get(\"one\", 4) # => 1\nfilled</em>dict.get(\"four\", 4) # => 4</p>\n<h1>\"setdefault()\" inserts into a dictionary only if the given key isn't present</h1>\n<p>filled<em>dict.setdefault(\"five\", 5) # filled</em>dict[\"five\"] is set to 5\nfilled<em>dict.setdefault(\"five\", 6) # filled</em>dict[\"five\"] is still 5</p>\n<h1>Adding to a dictionary</h1>\n<p>filled<em>dict.update({\"four\":4}) # => {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4}\nfilled</em>dict[\"four\"] = 4 # another way to add to dict</p>\n<h1>Remove keys from a dictionary with del</h1>\n<p>del filled_dict[\"one\"] # Removes the key \"one\" from filled dict</p>\n<h1>From Python 3.5 you can also use the additional unpacking options</h1>\n<p>{'a': 1, **{'b': 2}} # => {'a': 1, 'b': 2}\n{'a': 1, **{'a': 2}} # => {'a': 2}</p>\n<h1>Sets store ... well sets</h1>\n<p>empty_set = set()</p>\n<h1>Initialize a set with a bunch of values. Yeah, it looks a bit like a dict. Sorry.</h1>\n<p>some<em>set = {1, 1, 2, 2, 3, 4} # some</em>set is now {1, 2, 3, 4}</p>\n<h1>Similar to keys of a dictionary, elements of a set have to be immutable.</h1>\n<p>invalid<em>set = {[1], 1} # => Raises a TypeError: unhashable type: 'list'\nvalid</em>set = {(1,), 1}</p>\n<h1>Add one more item to the set</h1>\n<p>filled<em>set = some</em>set\nfilled<em>set.add(5) # filled</em>set is now {1, 2, 3, 4, 5}</p>\n<h1>Sets do not have duplicate elements</h1>\n<p>filled_set.add(5) # it remains as before {1, 2, 3, 4, 5}</p>\n<h1>Do set intersection with &#x26;</h1>\n<p>other<em>set = {3, 4, 5, 6}\nfilled</em>set &#x26; other_set # => {3, 4, 5}</p>\n<h1>Do set union with |</h1>\n<p>filled<em>set | other</em>set # => {1, 2, 3, 4, 5, 6}</p>\n<h1>Do set difference with -</h1>\n<p>{1, 2, 3, 4} - {2, 3, 5} # => {1, 4}</p>\n<h1>Do set symmetric difference with ^</h1>\n<p>{1, 2, 3, 4} ^ {2, 3, 5} # => {1, 4, 5}</p>\n<h1>Check if set on the left is a superset of set on the right</h1>\n<p>{1, 2} >= {1, 2, 3} # => False</p>\n<h1>Check if set on the left is a subset of set on the right</h1>\n<p>{1, 2} &#x3C;= {1, 2, 3} # => True</p>\n<h1>Check for existence in a set with in</h1>\n<p>2 in filled<em>set # => True\n10 in filled</em>set # => False</p>\n<p>####################################################</p>\n<h2>3. Control Flow and Iterables</h2>\n<p>####################################################</p>\n<h1>Let's just make a variable</h1>\n<p>some_var = 5</p>\n<h1>Here is an if statement. Indentation is significant in Python!</h1>\n<h1>Convention is to use four spaces, not tabs.</h1>\n<h1>This prints \"some_var is smaller than 10\"</h1>\n<p>if some<em>var > 10:\nprint(\"some</em>var is totally bigger than 10.\")\nelif some<em>var &#x3C; 10: # This elif clause is optional.\nprint(\"some</em>var is smaller than 10.\")\nelse: # This is optional too.\nprint(\"some_var is indeed 10.\")</p>\n<p>\"\"\"\nFor loops iterate over lists\nprints:\ndog is a mammal\ncat is a mammal\nmouse is a mammal\n\"\"\"\nfor animal in [\"dog\", \"cat\", \"mouse\"]: # You can use format() to interpolate formatted strings\nprint(\"{} is a mammal\".format(animal))</p>\n<p>\"\"\"\n\"range(number)\" returns an iterable of numbers\nfrom zero to the given number\nprints:\n0\n1\n2\n3\n\"\"\"\nfor i in range(4):\nprint(i)</p>\n<p>\"\"\"\n\"range(lower, upper)\" returns an iterable of numbers\nfrom the lower number to the upper number\nprints:\n4\n5\n6\n7\n\"\"\"\nfor i in range(4, 8):\nprint(i)</p>\n<p>\"\"\"\n\"range(lower, upper, step)\" returns an iterable of numbers\nfrom the lower number to the upper number, while incrementing\nby step. If step is not indicated, the default value is 1.\nprints:\n4\n6\n\"\"\"\nfor i in range(4, 8, 2):\nprint(i)</p>\n<p>\"\"\"\nTo loop over a list, and retrieve both the index and the value of each item in the list\nprints:\n0 dog\n1 cat\n2 mouse\n\"\"\"\nlist = [\"dog\", \"cat\", \"mouse\"]\nfor i, value in enumerate(list):\nprint(i, value)</p>\n<p>\"\"\"\nWhile loops go until a condition is no longer met.\nprints:\n0\n1\n2\n3\n\"\"\"\nx = 0\nwhile x &#x3C; 4:\nprint(x)\nx += 1 # Shorthand for x = x + 1</p>\n<h1>Handle exceptions with a try/except block</h1>\n<p>try: # Use \"raise\" to raise an error\nraise IndexError(\"This is an index error\")\nexcept IndexError as e:\npass # Pass is just a no-op. Usually you would do recovery here.\nexcept (TypeError, NameError):\npass # Multiple exceptions can be handled together, if required.\nelse: # Optional clause to the try/except block. Must follow all except blocks\nprint(\"All good!\") # Runs only if the code in try raises no exceptions\nfinally: # Execute under all circumstances\nprint(\"We can clean up resources here\")</p>\n<h1>Instead of try/finally to cleanup resources you can use a with statement</h1>\n<p>with open(\"myfile.txt\") as f:\nfor line in f:\nprint(line)</p>\n<h1>Writing to a file</h1>\n<p>contents = {\"aa\": 12, \"bb\": 21}\nwith open(\"myfile1.txt\", \"w+\") as file:\nfile.write(str(contents)) # writes a string to a file</p>\n<p>with open(\"myfile2.txt\", \"w+\") as file:\nfile.write(json.dumps(contents)) # writes an object to a file</p>\n<h1>Reading from a file</h1>\n<p>with open('myfile1.txt', \"r+\") as file:\ncontents = file.read() # reads a string from a file\nprint(contents)</p>\n<h1>print: {\"aa\": 12, \"bb\": 21}</h1>\n<p>with open('myfile2.txt', \"r+\") as file:\ncontents = json.load(file) # reads a json object from a file\nprint(contents)</p>\n<h1>print: {\"aa\": 12, \"bb\": 21}</h1>\n<h1>Python offers a fundamental abstraction called the Iterable.</h1>\n<h1>An iterable is an object that can be treated as a sequence.</h1>\n<h1>The object returned by the range function, is an iterable.</h1>\n<p>filled<em>dict = {\"one\": 1, \"two\": 2, \"three\": 3}\nour</em>iterable = filled<em>dict.keys()\nprint(our</em>iterable) # => dict_keys(['one', 'two', 'three']). This is an object that implements our Iterable interface.</p>\n<h1>We can loop over it.</h1>\n<p>for i in our_iterable:\nprint(i) # Prints one, two, three</p>\n<h1>However we cannot address elements by index.</h1>\n<p>our_iterable[1] # Raises a TypeError</p>\n<h1>An iterable is an object that knows how to create an iterator.</h1>\n<p>our<em>iterator = iter(our</em>iterable)</p>\n<h1>Our iterator is an object that can remember the state as we traverse through it.</h1>\n<h1>We get the next object with \"next()\".</h1>\n<p>next(our_iterator) # => \"one\"</p>\n<h1>It maintains state as we iterate.</h1>\n<p>next(our<em>iterator) # => \"two\"\nnext(our</em>iterator) # => \"three\"</p>\n<h1>After the iterator has returned all of its data, it raises a StopIteration exception</h1>\n<p>next(our_iterator) # Raises StopIteration</p>\n<h1>We can also loop over it, in fact, \"for\" does this implicitly!</h1>\n<p>our<em>iterator = iter(our</em>iterable)\nfor i in our_iterator:\nprint(i) # Prints one, two, three</p>\n<h1>You can grab all the elements of an iterable or iterator by calling list() on it.</h1>\n<p>list(our<em>iterable) # => Returns [\"one\", \"two\", \"three\"]\nlist(our</em>iterator) # => Returns [] because state is saved</p>\n<p>####################################################</p>\n<h2>4. Functions</h2>\n<p>####################################################</p>\n<h1>Use \"def\" to create new functions</h1>\n<p>def add(x, y):\nprint(\"x is {} and y is {}\".format(x, y))\nreturn x + y # Return values with a return statement</p>\n<h1>Calling functions with parameters</h1>\n<p>add(5, 6) # => prints out \"x is 5 and y is 6\" and returns 11</p>\n<h1>Another way to call functions is with keyword arguments</h1>\n<p>add(y=6, x=5) # Keyword arguments can arrive in any order.</p>\n<h1>You can define functions that take a variable number of</h1>\n<h1>positional arguments</h1>\n<p>def varargs(*args):\nreturn args</p>\n<p>varargs(1, 2, 3) # => (1, 2, 3)</p>\n<h1>You can define functions that take a variable number of</h1>\n<h1>keyword arguments, as well</h1>\n<p>def keyword_args(**kwargs):\nreturn kwargs</p>\n<h1>Let's call it to see what happens</h1>\n<p>keyword_args(big=\"foot\", loch=\"ness\") # => {\"big\": \"foot\", \"loch\": \"ness\"}</p>\n<h1>You can do both at once, if you like</h1>\n<p>def all<em>the</em>args(*args, **kwargs):\nprint(args)\nprint(kwargs)\n\"\"\"\nall<em>the</em>args(1, 2, a=3, b=4) prints:\n(1, 2)\n{\"a\": 3, \"b\": 4}\n\"\"\"</p>\n<h1>When calling functions, you can do the opposite of args/kwargs!</h1>\n<h1>Use * to expand tuples and use ** to expand kwargs.</h1>\n<p>args = (1, 2, 3, 4)\nkwargs = {\"a\": 3, \"b\": 4}\nall<em>the</em>args(<em>args) # equivalent to all<em>the</em>args(1, 2, 3, 4)\nall<em>the</em>args(\\</em>*kwargs) # equivalent to all<em>the</em>args(a=3, b=4)\nall<em>the</em>args(<em>args, \\</em>*kwargs) # equivalent to all<em>the</em>args(1, 2, 3, 4, a=3, b=4)</p>\n<h1>Returning multiple values (with tuple assignments)</h1>\n<p>def swap(x, y):\nreturn y, x # Return multiple values as a tuple without the parenthesis. # (Note: parenthesis have been excluded but can be included)</p>\n<p>x = 1\ny = 2\nx, y = swap(x, y) # => x = 2, y = 1</p>\n<h1>(x, y) = swap(x,y) # Again parenthesis have been excluded but can be included.</h1>\n<h1>Function Scope</h1>\n<p>x = 5</p>\n<p>def set_x(num): # Local var x not the same as global variable x\nx = num # => 43\nprint(x) # => 43</p>\n<p>def set<em>global</em>x(num):\nglobal x\nprint(x) # => 5\nx = num # global var x is now set to 6\nprint(x) # => 6</p>\n<p>set<em>x(43)\nset</em>global_x(6)</p>\n<h1>Python has first class functions</h1>\n<p>def create_adder(x):\ndef adder(y):\nreturn x + y\nreturn adder</p>\n<p>add<em>10 = create</em>adder(10)\nadd_10(3) # => 13</p>\n<h1>There are also anonymous functions</h1>\n<p>(lambda x: x > 2)(3) # => True\n(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5</p>\n<h1>There are built-in higher order functions</h1>\n<p>list(map(add_10, [1, 2, 3])) # => [11, 12, 13]\nlist(map(max, [1, 2, 3], [4, 2, 1])) # => [4, 2, 3]</p>\n<p>list(filter(lambda x: x > 5, [3, 4, 5, 6, 7])) # => [6, 7]</p>\n<h1>We can use list comprehensions for nice maps and filters</h1>\n<h1>List comprehension stores the output as a list which can itself be a nested list</h1>\n<p>[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]\n[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]</p>\n<h1>You can construct set and dict comprehensions as well.</h1>\n<p>{x for x in 'abcddeef' if x not in 'abc'} # => {'d', 'e', 'f'}\n{x: x**2 for x in range(5)} # => {0: 0, 1: 1, 2: 4, 3: 9, 4: 16}</p>\n<p>####################################################</p>\n<h2>5. Modules</h2>\n<p>####################################################</p>\n<h1>You can import modules</h1>\n<p>import math\nprint(math.sqrt(16)) # => 4.0</p>\n<h1>You can get specific functions from a module</h1>\n<p>from math import ceil, floor\nprint(ceil(3.7)) # => 4.0\nprint(floor(3.7)) # => 3.0</p>\n<h1>You can import all functions from a module.</h1>\n<h1>Warning: this is not recommended</h1>\n<p>from math import *</p>\n<h1>You can shorten module names</h1>\n<p>import math as m\nmath.sqrt(16) == m.sqrt(16) # => True</p>\n<h1>Python modules are just ordinary Python files. You</h1>\n<h1>can write your own, and import them. The name of the</h1>\n<h1>module is the same as the name of the file.</h1>\n<h1>You can find out which functions and attributes</h1>\n<h1>are defined in a module.</h1>\n<p>import math\ndir(math)</p>\n<h1>If you have a Python script named math.py in the same</h1>\n<h1>folder as your current script, the file math.py will</h1>\n<h1>be loaded instead of the built-in Python module.</h1>\n<h1>This happens because the local folder has priority</h1>\n<h1>over Python's built-in libraries.</h1>\n<p>####################################################</p>\n<h2>6. Classes</h2>\n<p>####################################################</p>\n<h1>We use the \"class\" statement to create a class</h1>\n<p>class Human:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># A class attribute. It is shared by all instances of this class\nspecies = \"H. sapiens\"\n\n# Basic initializer, this is called when this class is instantiated.\n# Note that the double leading and trailing underscores denote objects\n# or attributes that are used by Python but that live in user-controlled\n# namespaces. Methods(or objects or attributes) like: __init__, __str__,\n# __repr__ etc. are called special methods (or sometimes called dunder methods)\n# You should not invent such names on your own.\ndef __init__(self, name):\n    # Assign the argument to the instance's name attribute\n    self.name = name\n\n    # Initialize property\n    self._age = 0\n\n# An instance method. All methods take \"self\" as the first argument\ndef say(self, msg):\n    print(\"{name}: {message}\".format(name=self.name, message=msg))\n\n# Another instance method\ndef sing(self):\n    return 'yo... yo... microphone check... one two... one two...'\n\n# A class method is shared among all instances\n# They are called with the calling class as the first argument\n@classmethod\ndef get_species(cls):\n    return cls.species\n\n# A static method is called without a class or instance reference\n@staticmethod\ndef grunt():\n    return \"*grunt*\"\n\n# A property is just like a getter.\n# It turns the method age() into an read-only attribute of the same name.\n# There's no need to write trivial getters and setters in Python, though.\n@property\ndef age(self):\n    return self._age\n\n# This allows the property to be set\n@age.setter\ndef age(self, age):\n    self._age = age\n\n# This allows the property to be deleted\n@age.deleter\ndef age(self):\n    del self._age</code></pre></div>\n<h1>When a Python interpreter reads a source file it executes all its code.</h1>\n<h1>This <strong>name</strong> check makes sure this code block is only executed when this</h1>\n<h1>module is the main program.</h1>\n<p>if <strong>name</strong> == '<strong>main</strong>': # Instantiate a class\ni = Human(name=\"Ian\")\ni.say(\"hi\") # \"Ian: hi\"\nj = Human(\"Joel\")\nj.say(\"hello\") # \"Joel: hello\" # i and j are instances of type Human, or in other words: they are Human objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Call our class method\ni.say(i.get_species())          # \"Ian: H. sapiens\"\n# Change the shared attribute\nHuman.species = \"H. neanderthalensis\"\ni.say(i.get_species())          # => \"Ian: H. neanderthalensis\"\nj.say(j.get_species())          # => \"Joel: H. neanderthalensis\"\n\n# Call the static method\nprint(Human.grunt())            # => \"*grunt*\"\n\n# Cannot call static method with instance of object\n# because i.grunt() will automatically put \"self\" (the object i) as an argument\nprint(i.grunt())                # => TypeError: grunt() takes 0 positional arguments but 1 was given\n\n# Update the property for this instance\ni.age = 42\n# Get the property\ni.say(i.age)                    # => \"Ian: 42\"\nj.say(j.age)                    # => \"Joel: 0\"\n# Delete the property\ndel i.age\n# i.age                         # => this would raise an AttributeError</code></pre></div>\n<p>####################################################</p>\n<h2>6.1 Inheritance</h2>\n<p>####################################################</p>\n<h1>Inheritance allows new child classes to be defined that inherit methods and</h1>\n<h1>variables from their parent class.</h1>\n<h1>Using the Human class defined above as the base or parent class, we can</h1>\n<h1>define a child class, Superhero, which inherits the class variables like</h1>\n<h1>\"species\", \"name\", and \"age\", as well as methods, like \"sing\" and \"grunt\"</h1>\n<h1>from the Human class, but can also have its own unique properties.</h1>\n<h1>To take advantage of modularization by file you could place the classes above in their own files,</h1>\n<h1>say, human.py</h1>\n<h1>To import functions from other files use the following format</h1>\n<h1>from \"filename-without-extension\" import \"function-or-class\"</h1>\n<p>from human import Human</p>\n<h1>Specify the parent class(es) as parameters to the class definition</h1>\n<p>class Superhero(Human):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># If the child class should inherit all of the parent's definitions without\n# any modifications, you can just use the \"pass\" keyword (and nothing else)\n# but in this case it is commented out to allow for a unique child class:\n# pass\n\n# Child classes can override their parents' attributes\nspecies = 'Superhuman'\n\n# Children automatically inherit their parent class's constructor including\n# its arguments, but can also define additional arguments or definitions\n# and override its methods such as the class constructor.\n# This constructor inherits the \"name\" argument from the \"Human\" class and\n# adds the \"superpower\" and \"movie\" arguments:\ndef __init__(self, name, movie=False,\n             superpowers=[\"super strength\", \"bulletproofing\"]):\n\n    # add additional class attributes:\n    self.fictional = True\n    self.movie = movie\n    # be aware of mutable default values, since defaults are shared\n    self.superpowers = superpowers\n\n    # The \"super\" function lets you access the parent class's methods\n    # that are overridden by the child, in this case, the __init__ method.\n    # This calls the parent class constructor:\n    super().__init__(name)\n\n# override the sing method\ndef sing(self):\n    return 'Dun, dun, DUN!'\n\n# add an additional instance method\ndef boast(self):\n    for power in self.superpowers:\n        print(\"I wield the power of {pow}!\".format(pow=power))</code></pre></div>\n<p>if <strong>name</strong> == '<strong>main</strong>':\nsup = Superhero(name=\"Tick\")</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Instance type checks\nif isinstance(sup, Human):\n    print('I am human')\nif type(sup) is Superhero:\n    print('I am a superhero')\n\n# Get the Method Resolution search Order used by both getattr() and super()\n# This attribute is dynamic and can be updated\nprint(Superhero.__mro__)    # => (&lt;class '__main__.Superhero'>,\n                            # => &lt;class 'human.Human'>, &lt;class 'object'>)\n\n# Calls parent method but uses its own class attribute\nprint(sup.get_species())    # => Superhuman\n\n# Calls overridden method\nprint(sup.sing())           # => Dun, dun, DUN!\n\n# Calls method from Human\nsup.say('Spoon')            # => Tick: Spoon\n\n# Call method that exists only in Superhero\nsup.boast()                 # => I wield the power of super strength!\n                            # => I wield the power of bulletproofing!\n\n# Inherited class attribute\nsup.age = 31\nprint(sup.age)              # => 31\n\n# Attribute that only exists within Superhero\nprint('Am I Oscar eligible? ' + str(sup.movie))</code></pre></div>\n<p>####################################################</p>\n<h2>6.2 Multiple Inheritance</h2>\n<p>####################################################</p>\n<h1>Another class definition</h1>\n<h1>bat.py</h1>\n<p>class Bat:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">species = 'Baty'\n\ndef __init__(self, can_fly=True):\n    self.fly = can_fly\n\n# This class also has a say method\ndef say(self, msg):\n    msg = '... ... ...'\n    return msg\n\n# And its own method as well\ndef sonar(self):\n    return '))) ... ((('</code></pre></div>\n<p>if <strong>name</strong> == '<strong>main</strong>':\nb = Bat()\nprint(b.say('hello'))\nprint(b.fly)</p>\n<h1>And yet another class definition that inherits from Superhero and Bat</h1>\n<h1>superhero.py</h1>\n<p>from superhero import Superhero\nfrom bat import Bat</p>\n<h1>Define Batman as a child that inherits from both Superhero and Bat</h1>\n<p>class Batman(Superhero, Bat):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">def __init__(self, *args, **kwargs):\n    # Typically to inherit attributes you have to call super:\n    # super(Batman, self).__init__(*args, **kwargs)\n    # However we are dealing with multiple inheritance here, and super()\n    # only works with the next base class in the MRO list.\n    # So instead we explicitly call __init__ for all ancestors.\n    # The use of *args and **kwargs allows for a clean way to pass arguments,\n    # with each parent \"peeling a layer of the onion\".\n    Superhero.__init__(self, 'anonymous', movie=True,\n                       superpowers=['Wealthy'], *args, **kwargs)\n    Bat.__init__(self, *args, can_fly=False, **kwargs)\n    # override the value for the name attribute\n    self.name = 'Sad Affleck'\n\ndef sing(self):\n    return 'nan nan nan nan nan batman!'</code></pre></div>\n<p>if <strong>name</strong> == '<strong>main</strong>':\nsup = Batman()</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Get the Method Resolution search Order used by both getattr() and super().\n# This attribute is dynamic and can be updated\nprint(Batman.__mro__)       # => (&lt;class '__main__.Batman'>,\n                            # => &lt;class 'superhero.Superhero'>,\n                            # => &lt;class 'human.Human'>,\n                            # => &lt;class 'bat.Bat'>, &lt;class 'object'>)\n\n# Calls parent method but uses its own class attribute\nprint(sup.get_species())    # => Superhuman\n\n# Calls overridden method\nprint(sup.sing())           # => nan nan nan nan nan batman!\n\n# Calls method from Human, because inheritance order matters\nsup.say('I agree')          # => Sad Affleck: I agree\n\n# Call method that exists only in 2nd ancestor\nprint(sup.sonar())          # => ))) ... (((\n\n# Inherited class attribute\nsup.age = 100\nprint(sup.age)              # => 100\n\n# Inherited attribute from 2nd ancestor whose default value was overridden.\nprint('Can I fly? ' + str(sup.fly)) # => Can I fly? False</code></pre></div>\n<p>####################################################</p>\n<h2>7. Advanced</h2>\n<p>####################################################</p>\n<h1>Generators help you make lazy code.</h1>\n<p>def double_numbers(iterable):\nfor i in iterable:\nyield i + i</p>\n<h1>Generators are memory-efficient because they only load the data needed to</h1>\n<h1>process the next value in the iterable. This allows them to perform</h1>\n<h1>operations on otherwise prohibitively large value ranges.</h1>\n<h1>NOTE: <code class=\"language-text\">range</code> replaces <code class=\"language-text\">xrange</code> in Python 3.</h1>\n<p>for i in double_numbers(range(1, 900000000)): # <code class=\"language-text\">range</code> is a generator.\nprint(i)\nif i >= 30:\nbreak</p>\n<h1>Just as you can create a list comprehension, you can create generator</h1>\n<h1>comprehensions as well.</h1>\n<p>values = (-x for x in [1,2,3,4,5])\nfor x in values:\nprint(x) # prints -1 -2 -3 -4 -5 to console/terminal</p>\n<h1>You can also cast a generator comprehension directly to a list.</h1>\n<p>values = (-x for x in [1,2,3,4,5])\ngen<em>to</em>list = list(values)\nprint(gen<em>to</em>list) # => [-1, -2, -3, -4, -5]</p>\n<h1>Decorators</h1>\n<h1>In this example <code class=\"language-text\">beg</code> wraps <code class=\"language-text\">say</code>. If say_please is True then it</h1>\n<h1>will change the returned message.</h1>\n<p>from functools import wraps</p>\n<p>def beg(target<em>function):\n@wraps(target</em>function)\ndef wrapper(<em>args, \\</em>*kwargs):\nmsg, say<em>please = target</em>function(<em>args, \\</em>*kwargs)\nif say_please:\nreturn \"{} {}\".format(msg, \"Please! I am poor :(\")\nreturn msg</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">return wrapper</code></pre></div>\n<p>@beg\ndef say(say<em>please=False):\nmsg = \"Can you buy me a beer?\"\nreturn msg, say</em>please</p>\n<p>print(say()) # Can you buy me a beer?\nprint(say(say_please=True)) # Can you buy me a beer? Please! I am poor :(</p>"},{"url":"/docs/react/react-docs/","relativePath":"docs/react/react-docs.md","relativeDir":"docs/react","base":"react-docs.md","name":"react-docs","frontmatter":{"title":"React Docs","weight":0,"excerpt":"In this guide, we will examine the building blocks of React apps: elements and components. Once you master them, you can create complex apps from small reusable pieces.","seo":{"title":"React","description":"We will examine the building blocks of React apps: elements and components. Once you master them, you can create complex apps from small reusable pieces.","robots":[],"extra":[{"name":"og:description","value":"We will examine the building blocks of React apps: elements and components. Once you master them, you can create complex apps from small reusable pieces.","keyName":"property","relativeUrl":false},{"name":"og:image","value":"images/react-banner.jpg","keyName":"property","relativeUrl":true},{"name":"og:type","value":"website","keyName":"property","relativeUrl":false},{"name":"twitter:title","value":"React Docs","keyName":"name","relativeUrl":false},{"name":"twitter:image","value":"images/react2-b4316710.jpg","keyName":"property","relativeUrl":true},{"name":"twitter:card","value":"summary_image","keyName":"name","relativeUrl":false}],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>React:</h1>\n<p><img src=\"https://i.imgur.com/3fhEosP.png\" alt=\"React Lifecycles\"></p>\n<h2><strong>Hello World</strong></h2>\n<h2>The smallest React example looks like this:</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>It displays a heading saying \"Hello, world!\" on the page.</p>\n<p><strong><a href=\"https://reactjs.org/redirect-to-codepen/hello-world\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/wveBJBM\"></a><a href=\"https://codepen.io/bgoonz/pen/wveBJBM\">https://codepen.io/bgoonz/pen/wveBJBM</a></p>\n<p>Click the link above to open an online editor. Feel free to make some changes, and see how they affect the output. Most pages in this guide will have editable examples like this one.</p>\n<hr>\n<h2>How to Read This Guide</h2>\n<p>In this guide, we will examine the building blocks of React apps: elements and components. Once you master them, you can create complex apps from small reusable pieces.</p>\n<blockquote>\n<p>TipThis guide is designed for people who prefer learning concepts step by step. If you prefer to learn by doing, check out our practical tutorial. You might find this guide and the tutorial complementary to each other.</p>\n</blockquote>\n<p>This is the first chapter in a step-by-step guide about main React concepts. You can find a list of all its chapters in the navigation sidebar. If you're reading this from a mobile device, you can access the navigation by pressing the button in the bottom right corner of your screen.</p>\n<p>Every chapter in this guide builds on the knowledge introduced in earlier chapters. <strong>You can learn most of React by reading the \"Main Concepts\" guide chapters in the order they appear in the sidebar.</strong> For example, <a href=\"https://reactjs.org/docs/introducing-jsx.html\">\"Introducing JSX\"</a> is the next chapter after this one.</p>\n<hr>\n<h2>Knowledge Level Assumptions</h2>\n<p>React is a JavaScript library, and so we'll assume you have a basic understanding of the JavaScript language. <strong>If you don't feel very confident, we recommend <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript\">going through a JavaScript tutorial</a> to check your knowledge level</strong> and enable you to follow along this guide without getting lost. It might take you between 30 minutes and an hour, but as a result you won't have to feel like you're learning both React and JavaScript at the same time.</p>\n<blockquote>\n<p>NoteThis guide occasionally uses some newer JavaScript syntax in the examples. If you haven't worked with JavaScript in the last few years, these three points should get you most of the way.</p>\n</blockquote>\n<hr>\n<h2><strong>Introducing JSX</strong></h2>\n<h2>Consider this variable declaration:</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This funny tag syntax is neither a string nor HTML.</p>\n<p>It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript.</p>\n<p>JSX produces React \"elements\". We will explore rendering them to the DOM in the <a href=\"https://reactjs.org/docs/rendering-elements.html\">next section</a>. Below, you can find the basics of JSX necessary to get you started.</p>\n<hr>\n<h2>Why JSX?</h2>\n<p>React embraces the fact that rendering logic is inherently coupled with other UI logic: how events are handled, how the state changes over time, and how the data is prepared for display.</p>\n<p>Instead of artificially separating <em>technologies</em> by putting markup and logic in separate files, React <a href=\"https://en.wikipedia.org/wiki/Separation_of_concerns\">separates <em>concerns</em></a> with loosely coupled units called \"components\" that contain both. We will come back to components in a <a href=\"https://reactjs.org/docs/components-and-props.html\">further section</a>, but if you're not yet comfortable putting markup in JS, <a href=\"https://www.youtube.com/watch?v=x7cQ3mrcKaY\">this talk</a> might convince you otherwise.</p>\n<p>React <a href=\"https://reactjs.org/docs/react-without-jsx.html\">doesn't require</a> using JSX, but most people find it helpful as a visual aid when working with UI inside the JavaScript code. It also allows React to show more useful error and warning messages.</p>\n<p>With that out of the way, let's get started!</p>\n<h2>Embedding Expressions in JSX</h2>\n<p>In the example below, we declare a variable called <code class=\"language-text\">name</code> and then use it inside JSX by wrapping it in curly braces:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> name <span class=\"token operator\">=</span> <span class=\"token string\">'Josh Perez'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You can put any valid <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Expressions\">JavaScript expression</a> inside the curly braces in JSX. For example, <code class=\"language-text\">2 + 2</code>, <code class=\"language-text\">user.firstName</code>, or <code class=\"language-text\">formatName(user)</code> are all valid JavaScript expressions.</p>\n<p>In the example below, we embed the result of calling a JavaScript function, <code class=\"language-text\">formatName(user)</code>, into an <code class=\"language-text\">&lt;h1></code> element.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">formatName</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">user</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> user<span class=\"token punctuation\">.</span>firstName <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> user<span class=\"token punctuation\">.</span>lastName<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> user <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Harper'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Perez'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span> Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token function\">formatName</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">!</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://reactjs.org/redirect-to-codepen/introducing-jsx\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/oNwgZgm\"></a><a href=\"https://codepen.io/bgoonz/pen/oNwgZgm\">https://codepen.io/bgoonz/pen/oNwgZgm</a></p>\n<p>We split JSX over multiple lines for readability. While it isn't required, when doing this, we also recommend wrapping it in parentheses to avoid the pitfalls of <a href=\"https://stackoverflow.com/q/2846283\">automatic semicolon insertion</a>.</p>\n<hr>\n<h2>JSX is an Expression Too</h2>\n<p>After compilation, JSX expressions become regular JavaScript function calls and evaluate to JavaScript objects.</p>\n<p>This means that you can use JSX inside of <code class=\"language-text\">if</code> statements and <code class=\"language-text\">for</code> loops, assign it to variables, accept it as arguments, and return it from functions:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">getGreeting</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">user</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token function\">formatName</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> Stranger<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Specifying Attributes with JSX</h2>\n<p>You may use quotes to specify string literals as attributes:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>div tabIndex<span class=\"token operator\">=</span><span class=\"token string\">\"0\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You may also use curly braces to embed a JavaScript expression in an attribute:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>img src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>user<span class=\"token punctuation\">.</span>avatarUrl<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>img<span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Don't put quotes around curly braces when embedding a JavaScript expression in an attribute. You should either use quotes (for string values) or curly braces (for expressions), but not both in the same attribute.</p>\n<blockquote>\n<p>Warning:Since JSX is closer to JavaScript than to HTML, React DOM uses camelCase property naming convention instead of HTML attribute names.For example, class becomes className in JSX, and tabindex becomes tabIndex.</p>\n</blockquote>\n<hr>\n<h2>Specifying Children with JSX</h2>\n<p>If a tag is empty, you may close it immediately with <code class=\"language-text\">/></code>, like XML:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>img src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>user<span class=\"token punctuation\">.</span>avatarUrl<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>JSX tags may contain children:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>Good to see you here<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>JSX Prevents Injection Attacks</h2>\n<p>It is safe to embed user input in JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> title <span class=\"token operator\">=</span> response<span class=\"token punctuation\">.</span>potentiallyMaliciousInput<span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// This is safe:</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>title<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>By default, React DOM <a href=\"https://stackoverflow.com/questions/7381974/which-characters-need-to-be-escaped-on-html\">escapes</a> any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that's not explicitly written in your application. Everything is converted to a string before being rendered. This helps prevent <a href=\"https://en.wikipedia.org/wiki/Cross-site_scripting\">XSS (cross-site-scripting)</a> attacks.</p>\n<hr>\n<h2>JSX Represents Objects</h2>\n<p>Babel compiles JSX down to <code class=\"language-text\">React.createElement()</code> calls.</p>\n<p>These two examples are identical:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>h1 className<span class=\"token operator\">=</span><span class=\"token string\">\"greeting\"</span><span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'h1'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">className</span><span class=\"token operator\">:</span> <span class=\"token string\">'greeting'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Hello, world!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"language-text\">React.createElement()</code> performs a few checks to help you write bug-free code but essentially it creates an object like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Note: this structure is simplified</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token string\">'h1'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">props</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">className</span><span class=\"token operator\">:</span> <span class=\"token string\">'greeting'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello, world!'</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>These objects are called \"React elements\". You can think of them as descriptions of what you want to see on the screen. React reads these objects and uses them to construct the DOM and keep it up to date.</p>\n<p>We will explore rendering React elements to the DOM in the <a href=\"https://reactjs.org/docs/rendering-elements.html\">next section</a>.</p>\n<blockquote>\n<p>Tip:We recommend using the \"Babel\" language definition for your editor of choice so that both ES6 and JSX code is properly highlighted.</p>\n</blockquote>\n<hr>\n<h2><strong>Rendering Elements</strong></h2>\n<h2>Elements are the smallest building blocks of React apps.</h2>\n<p>An element describes what you want to see on the screen:</p>\n<p><code class=\"language-text\">const element = &lt;h1>Hello, world&lt;/h1>;</code></p>\n<p>Unlike browser DOM elements, React elements are plain objects, and are cheap to create. React DOM takes care of updating the DOM to match the React elements.</p>\n<blockquote>\n<p>Note:One might confuse elements with a more widely known concept of \"components\". We will introduce components in the next section. Elements are what components are \"made of\", and we encourage you to read this section before jumping ahead.</p>\n</blockquote>\n<hr>\n<h2>Rendering an Element into the DOM</h2>\n<p>Let's say there is a <code class=\"language-text\">&lt;div></code> somewhere in your HTML file:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>div id<span class=\"token operator\">=</span><span class=\"token string\">\"root\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span></code></pre></div>\n<p>We call this a \"root\" DOM node because everything inside it will be managed by React DOM.</p>\n<p>Applications built with just React usually have a single root DOM node. If you are integrating React into an existing app, you may have as many isolated root DOM nodes as you like.</p>\n<p>To render a React element into a root DOM node, pass both to <code class=\"language-text\">[ReactDOM.render()](&lt;https://reactjs.org/docs/react-dom.html#render>)</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://reactjs.org/redirect-to-codepen/rendering-elements/render-an-element\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/mdwyWeb?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/mdwyWeb?editors=0010\">https://codepen.io/bgoonz/pen/mdwyWeb?editors=0010</a></p>\n<p>It displays \"Hello, world\" on the page.</p>\n<hr>\n<h2>Updating the Rendered Element</h2>\n<p>React elements are <a href=\"https://en.wikipedia.org/wiki/Immutable_object\">immutable</a>. Once you create an element, you can't change its children or attributes. An element is like a single frame in a movie: it represents the UI at a certain point in time.</p>\n<p>With our knowledge so far, the only way to update the UI is to create a new element, and pass it to <code class=\"language-text\">[ReactDOM.render()](&lt;https://reactjs.org/docs/react-dom.html#render>)</code>.</p>\n<p>Consider this ticking clock example:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span>tick<span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://reactjs.org/redirect-to-codepen/rendering-elements/update-rendered-element\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/eYRmvNy?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/eYRmvNy?editors=0010\">https://codepen.io/bgoonz/pen/eYRmvNy?editors=0010</a></p>\n<p>It calls <code class=\"language-text\">[ReactDOM.render()](&lt;https://reactjs.org/docs/react-dom.html#render>)</code> every second from a <code class=\"language-text\">[setInterval()](&lt;https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval>)</code> callback.</p>\n<blockquote>\n<p>Note:In practice, most React apps only call ReactDOM.render() once. In the next sections we will learn how such code gets encapsulated into stateful components.We recommend that you don't skip topics because they build on each other.</p>\n</blockquote>\n<hr>\n<h2>React Only Updates What's Necessary</h2>\n<p>React DOM compares the element and its children to the previous one, and only applies the DOM updates necessary to bring the DOM to the desired state.</p>\n<p>You can verify by inspecting the <a href=\"https://reactjs.org/redirect-to-codepen/rendering-elements/update-rendered-element\">last example</a> with the browser tools:</p>\n<p><img src=\"https://reactjs.org/c158617ed7cc0eac8f58330e49e48224/granular-dom-updates.gif\" alt=\"https://reactjs.org/c158617ed7cc0eac8f58330e49e48224/granular-dom-updates.gif\"></p>\n<p>Even though we create an element describing the whole UI tree on every tick, only the text node whose contents have changed gets updated by React DOM.</p>\n<p>In our experience, thinking about how the UI should look at any given moment, rather than how to change it over time, eliminates a whole class of bugs.</p>\n<hr>\n<h2><strong>Components and Props</strong></h2>\n<h2>Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to the idea of components. You can find a <a href=\"https://reactjs.org/docs/react-component.html\">detailed component API reference here</a>.</h2>\n<p>Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called \"props\") and return React elements describing what should appear on the screen.</p>\n<hr>\n<h2>Function and Class Components</h2>\n<p>The simplest way to define a component is to write a JavaScript function:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Welcome</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>This function is a valid React component because it accepts a single \"props\" (which stands for properties) object argument with data and returns a React element. We call such components \"function components\" because they are literally JavaScript functions.</p>\n<p>You can also use an <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes\">ES6 class</a> to define a component:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Welcome</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The above two components are equivalent from React's point of view.</p>\n<p>Function and Class components both have some additional features that we will discuss in the <a href=\"https://reactjs.org/docs/state-and-lifecycle.html\">next sections</a>.</p>\n<hr>\n<h2>Rendering a Component</h2>\n<p>Previously, we only encountered React elements that represent DOM tags:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>div <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>However, elements can also represent user-defined components:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>Welcome name<span class=\"token operator\">=</span><span class=\"token string\">\"Sara\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>When React sees an element representing a user-defined component, it passes JSX attributes and children to this component as a single object. We call this object \"props\".</p>\n<p>For example, this code renders \"Hello, Sara\" on the page:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Welcome</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>Welcome name<span class=\"token operator\">=</span><span class=\"token string\">\"Sara\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://reactjs.org/redirect-to-codepen/components-and-props/rendering-a-component\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/QWgwpjd?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/QWgwpjd?editors=0010\">https://codepen.io/bgoonz/pen/QWgwpjd?editors=0010</a></p>\n<p>Let's recap what happens in this example:</p>\n<ol>\n<li>We call <code class=\"language-text\">ReactDOM.render()</code> with the <code class=\"language-text\">&lt;Welcome name=\"Sara\" /></code> element.</li>\n<li>React calls the <code class=\"language-text\">Welcome</code> component with <code class=\"language-text\">{name: 'Sara'}</code> as the props.</li>\n<li>Our <code class=\"language-text\">Welcome</code> component returns a <code class=\"language-text\">&lt;h1>Hello, Sara&lt;/h1></code> element as the result.</li>\n<li>React DOM efficiently updates the DOM to match <code class=\"language-text\">&lt;h1>Hello, Sara&lt;/h1></code>.</li>\n</ol>\n<blockquote>\n<p>Note: Always start component names with a capital letter.React treats components starting with lowercase letters as DOM tags. For example, <div /> represents an HTML div tag, but <Welcome /> represents a component and requires Welcome to be in <a href=\"http://scope.To\">scope.To</a> learn more about the reasoning behind this convention, please read JSX In Depth.</p>\n</blockquote>\n<hr>\n<h2>Composing Components</h2>\n<p>Components can refer to other components in their output. This lets us use the same component abstraction for any level of detail. A button, a form, a dialog, a screen: in React apps, all those are commonly expressed as components.</p>\n<p>For example, we can create an <code class=\"language-text\">App</code> component that renders <code class=\"language-text\">Welcome</code> many times:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Welcome</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>Welcome name<span class=\"token operator\">=</span><span class=\"token string\">\"Sara\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>Welcome name<span class=\"token operator\">=</span><span class=\"token string\">\"Cahal\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>Welcome name<span class=\"token operator\">=</span><span class=\"token string\">\"Edite\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>App <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://reactjs.org/redirect-to-codepen/components-and-props/composing-components\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/LYLEWNq?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/LYLEWNq?editors=0010\">https://codepen.io/bgoonz/pen/LYLEWNq?editors=0010</a></p>\n<p>Typically, new React apps have a single <code class=\"language-text\">App</code> component at the very top. However, if you integrate React into an existing app, you might start bottom-up with a small component like <code class=\"language-text\">Button</code> and gradually work your way to the top of the view hierarchy.</p>\n<hr>\n<h2>Extracting Components</h2>\n<p>Don't be afraid to split components into smaller components.</p>\n<p>For example, consider this <code class=\"language-text\">Comment</code> component:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Comment</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment\"</span><span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"UserInfo\"</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>img className<span class=\"token operator\">=</span><span class=\"token string\">\"Avatar\"</span> src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>author<span class=\"token punctuation\">.</span>avatarUrl<span class=\"token punctuation\">}</span> alt<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>author<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"UserInfo-name\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>author<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment-text\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment-date\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">formatDate</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://reactjs.org/redirect-to-codepen/components-and-props/extracting-components\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/PojwpzP?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/PojwpzP?editors=0010\">https://codepen.io/bgoonz/pen/PojwpzP?editors=0010</a></p>\n<p>It accepts <code class=\"language-text\">author</code> (an object), <code class=\"language-text\">text</code> (a string), and <code class=\"language-text\">date</code> (a date) as props, and describes a comment on a social media website.</p>\n<p>This component can be tricky to change because of all the nesting, and it is also hard to reuse individual parts of it. Let's extract a few components from it.</p>\n<p>First, we will extract <code class=\"language-text\">Avatar</code>:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Avatar</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>img className<span class=\"token operator\">=</span><span class=\"token string\">\"Avatar\"</span> src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>user<span class=\"token punctuation\">.</span>avatarUrl<span class=\"token punctuation\">}</span> alt<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>user<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The <code class=\"language-text\">Avatar</code> doesn't need to know that it is being rendered inside a <code class=\"language-text\">Comment</code>. This is why we have given its prop a more generic name: <code class=\"language-text\">user</code> rather than <code class=\"language-text\">author</code>.</p>\n<p>We recommend naming props from the component's own point of view rather than the context in which it is being used.</p>\n<p>We can now simplify <code class=\"language-text\">Comment</code> a tiny bit:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Comment</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment\"</span><span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"UserInfo\"</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>Avatar user<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>author<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"UserInfo-name\"</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>author<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment-text\"</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment-date\"</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span><span class=\"token function\">formatDate</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Next, we will extract a <code class=\"language-text\">UserInfo</code> component that renders an <code class=\"language-text\">Avatar</code> next to the user's name:</p>\n<p><code class=\"language-text\">function UserInfo(props) { return ( &lt;div className=\"UserInfo\"> &lt;Avatar user={props.user} /> &lt;div className=\"UserInfo-name\"> {props.user.name} &lt;/div> &lt;/div> ); }</code></p>\n<p>This lets us simplify <code class=\"language-text\">Comment</code> even further:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Comment</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment\"</span><span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>UserInfo user<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>author<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment-text\"</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"Comment-date\"</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">{</span><span class=\"token function\">formatDate</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://reactjs.org/redirect-to-codepen/components-and-props/extracting-components-continued\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/eYRmvzV?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/eYRmvzV?editors=0010\">https://codepen.io/bgoonz/pen/eYRmvzV?editors=0010</a></p>\n<p>Extracting components might seem like grunt work at first, but having a palette of reusable components pays off in larger apps. A good rule of thumb is that if a part of your UI is used several times (<code class=\"language-text\">Button</code>, <code class=\"language-text\">Panel</code>, <code class=\"language-text\">Avatar</code>), or is complex enough on its own (<code class=\"language-text\">App</code>, <code class=\"language-text\">FeedStory</code>, <code class=\"language-text\">Comment</code>), it is a good candidate to be extracted to a separate component.</p>\n<hr>\n<h2>Props are Read-Only</h2>\n<p>Whether you declare a component <a href=\"https://reactjs.org/docs/components-and-props.html#function-and-class-components\">as a function or a class</a>, it must never modify its own props. Consider this <code class=\"language-text\">sum</code> function:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Such functions are called <a href=\"https://en.wikipedia.org/wiki/Pure_function\">\"pure\"</a> because they do not attempt to change their inputs, and always return the same result for the same inputs.</p>\n<p>In contrast, this function is impure because it changes its own input:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">withdraw</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">account<span class=\"token punctuation\">,</span> amount</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  account<span class=\"token punctuation\">.</span>total <span class=\"token operator\">-=</span> amount<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">js\n//\n\nReact is pretty flexible but it has a single strict rule:\n\n**All React components must act like pure functions with respect to their props.**\n\nOf course, application UIs are dynamic and change over time. In the [next section](https://reactjs.org/docs/state-and-lifecycle.html), we will introduce a new concept of \"state\". State allows React components to change their output over time in response to user actions, network responses, and anything else, without violating this rule.\n\n**State and Lifecycle**\n=======================\n\nThis page introduces the concept of state and lifecycle in a React component. You can find a [detailed component API reference here](https://reactjs.org/docs/react-component.html).\n====================================================================================================================================================================================\n\nConsider the ticking clock example from [one of the previous sections](https://reactjs.org/docs/rendering-elements.html#updating-the-rendered-element). In [Rendering Elements](https://reactjs.org/docs/rendering-elements.html#rendering-an-element-into-the-dom), we have only learned one way to update the UI. We call </span><span class=\"token template-punctuation string\">`</span></span>ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> to change the rendered output:\n\n---\n\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>js\n<span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>      <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>      <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>    element<span class=\"token punctuation\">,</span>    document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span>  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span>tick<span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/gwoJZk?editors=0010\">Try it on CodePen</a></strong></p>\n<p>In this section, we will learn how to make the <code class=\"language-text\">Clock</code> component truly reusable and encapsulated. It will set up its own timer and update itself every second.</p>\n<p>We can start by encapsulating how the clock looks:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Clock</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Clock date<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span>tick<span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/dpdoYR?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/powvegw?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/powvegw?editors=0010\">https://codepen.io/bgoonz/pen/powvegw?editors=0010</a></p>\n<p>However, it misses a crucial requirement: the fact that the <code class=\"language-text\">Clock</code> sets up a timer and updates the UI every second should be an implementation detail of the <code class=\"language-text\">Clock</code>.</p>\n<p>Ideally we want to write this once and have the <code class=\"language-text\">Clock</code> update itself:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Clock <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To implement this, we need to add \"state\" to the <code class=\"language-text\">Clock</code> component.</p>\n<p>State is similar to props, but it is private and fully controlled by the component.</p>\n<hr>\n<h2>Converting a Function to a Class</h2>\n<p>You can convert a function component like <code class=\"language-text\">Clock</code> to a class in five steps:</p>\n<ol>\n<li>Create an <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes\">ES6 class</a>, with the same name, that extends <code class=\"language-text\">React.Component</code>.</li>\n<li>Add a single empty method to it called <code class=\"language-text\">render()</code>.</li>\n<li>Move the body of the function into the <code class=\"language-text\">render()</code> method.</li>\n<li>Replace <code class=\"language-text\">props</code> with <code class=\"language-text\">this.props</code> in the <code class=\"language-text\">render()</code> body.</li>\n<li>Delete the remaining empty function declaration.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Clock</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/zKRGpo?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/eYRmvJV?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/eYRmvJV?editors=0010\">https://codepen.io/bgoonz/pen/eYRmvJV?editors=0010</a></p>\n<p><code class=\"language-text\">Clock</code> is now defined as a class rather than a function.</p>\n<p>The <code class=\"language-text\">render</code> method will be called each time an update happens, but as long as we render <code class=\"language-text\">&lt;Clock /></code> into the same DOM node, only a single instance of the <code class=\"language-text\">Clock</code> class will be used. This lets us use additional features such as local state and lifecycle methods.</p>\n<hr>\n<h2>Adding Local State to a Class</h2>\n<p>We will move the <code class=\"language-text\">date</code> from props to state in three steps:</p>\n<ol>\n<li>Replace <code class=\"language-text\">this.props.date</code> with <code class=\"language-text\">this.state.date</code> in the <code class=\"language-text\">render()</code> method:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Clock</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ol>\n<li>Add a <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes#Constructor\">class constructor</a> that assigns the initial <code class=\"language-text\">this.state</code>:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Clock</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Note how we pass <code class=\"language-text\">props</code> to the base constructor:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Class components should always call the base constructor with <code class=\"language-text\">props</code>.</p>\n<ol>\n<li>Remove the <code class=\"language-text\">date</code> prop from the <code class=\"language-text\">&lt;Clock /></code> element:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Clock <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We will later add the timer code back to the component itself.</p>\n<p>The result looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Clock</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Clock <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/KgQpJd?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/oNwgZbV?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/oNwgZbV?editors=0010\">https://codepen.io/bgoonz/pen/oNwgZbV?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/KgQpJd?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Next, we'll make the <code class=\"language-text\">Clock</code> set up its own timer and update itself every second.</p>\n<hr>\n<h2>Adding Lifecycle Methods to a Class</h2>\n<p>In applications with many components, it's very important to free up resources taken by the components when they are destroyed.</p>\n<p>We want to <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval\">set up a timer</a> whenever the <code class=\"language-text\">Clock</code> is rendered to the DOM for the first time. This is called \"mounting\" in React.</p>\n<p>We also want to <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/clearInterval\">clear that timer</a> whenever the DOM produced by the <code class=\"language-text\">Clock</code> is removed. This is called \"unmounting\" in React.</p>\n<p>We can declare special methods on the component class to run some code when a component mounts and unmounts:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Clock</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token function\">componentWillUnmount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>These methods are called \"lifecycle methods\".</p>\n<p>The <code class=\"language-text\">componentDidMount()</code> method runs after the component output has been rendered to the DOM. This is a good place to set up a timer:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>timerID <span class=\"token operator\">=</span> <span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span>      <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>      <span class=\"token number\">1000</span>    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Note how we save the timer ID right on <code class=\"language-text\">this</code> (<code class=\"language-text\">this.timerID</code>).</p>\n<p>While <code class=\"language-text\">this.props</code> is set up by React itself and <code class=\"language-text\">this.state</code> has a special meaning, you are free to add additional fields to the class manually if you need to store something that doesn't participate in the data flow (like a timer ID).</p>\n<p>We will tear down the timer in the <code class=\"language-text\">componentWillUnmount()</code> lifecycle method:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token function\">componentWillUnmount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">clearInterval</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>timerID<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Finally, we will implement a method called <code class=\"language-text\">tick()</code> that the <code class=\"language-text\">Clock</code> component will run every second.</p>\n<p>It will use <code class=\"language-text\">this.setState()</code> to schedule updates to the component local state:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Clock</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>timerID <span class=\"token operator\">=</span> <span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">componentWillUnmount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">clearInterval</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>timerID<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">date</span><span class=\"token operator\">:</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token punctuation\">,</span> world<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Clock <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/amqdNA?editors=0010\">Try it on CodePen</a></strong></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/amqdNA?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Now the clock ticks every second.</p>\n<p>Let's quickly recap what's going on and the order in which the methods are called:</p>\n<ol>\n<li>When <code class=\"language-text\">&lt;Clock /></code> is passed to <code class=\"language-text\">ReactDOM.render()</code>, React calls the constructor of the <code class=\"language-text\">Clock</code> component. Since <code class=\"language-text\">Clock</code> needs to display the current time, it initializes <code class=\"language-text\">this.state</code> with an object including the current time. We will later update this state.</li>\n<li>React then calls the <code class=\"language-text\">Clock</code> component's <code class=\"language-text\">render()</code> method. This is how React learns what should be displayed on the screen. React then updates the DOM to match the <code class=\"language-text\">Clock</code>'s render output.</li>\n<li>When the <code class=\"language-text\">Clock</code> output is inserted in the DOM, React calls the <code class=\"language-text\">componentDidMount()</code> lifecycle method. Inside it, the <code class=\"language-text\">Clock</code> component asks the browser to set up a timer to call the component's <code class=\"language-text\">tick()</code> method once a second.</li>\n<li>Every second the browser calls the <code class=\"language-text\">tick()</code> method. Inside it, the <code class=\"language-text\">Clock</code> component schedules a UI update by calling <code class=\"language-text\">setState()</code> with an object containing the current time. Thanks to the <code class=\"language-text\">setState()</code> call, React knows the state has changed, and calls the <code class=\"language-text\">render()</code> method again to learn what should be on the screen. This time, <code class=\"language-text\">this.state.date</code> in the <code class=\"language-text\">render()</code> method will be different, and so the render output will include the updated time. React updates the DOM accordingly.</li>\n<li>If the <code class=\"language-text\">Clock</code> component is ever removed from the DOM, React calls the <code class=\"language-text\">componentWillUnmount()</code> lifecycle method so the timer is stopped.</li>\n</ol>\n<hr>\n<h2>Using State Correctly</h2>\n<p>There are three things you should know about <code class=\"language-text\">setState()</code>.</p>\n<hr>\n<h2>Do Not Modify State Directly</h2>\n<p>For example, this will not re-render a component:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Wrong</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>comment <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Instead, use <code class=\"language-text\">setState()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Correct</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">comment</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The only place where you can assign <code class=\"language-text\">this.state</code> is the constructor.</p>\n<hr>\n<h2>State Updates May Be Asynchronous</h2>\n<p>React may batch multiple <code class=\"language-text\">setState()</code> calls into a single update for performance.</p>\n<p>Because <code class=\"language-text\">this.props</code> and <code class=\"language-text\">this.state</code> may be updated asynchronously, you should not rely on their values for calculating the next state.</p>\n<p>For example, this code may fail to update the counter:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Wrong</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">counter</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>counter <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>increment\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>To fix it, use a second form of <code class=\"language-text\">setState()</code> that accepts a function rather than an object. That function will receive the previous state as the first argument, and the props at the time the update is applied as the second argument:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Correct</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state<span class=\"token punctuation\">,</span> props</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">counter</span><span class=\"token operator\">:</span> state<span class=\"token punctuation\">.</span>counter <span class=\"token operator\">+</span> props<span class=\"token punctuation\">.</span>increment\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We used an <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions\">arrow function</a> above, but it also works with regular functions:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Correct</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">state<span class=\"token punctuation\">,</span> props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">counter</span><span class=\"token operator\">:</span> state<span class=\"token punctuation\">.</span>counter <span class=\"token operator\">+</span> props<span class=\"token punctuation\">.</span>increment\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>State Updates are Merged</h2>\n<p>When you call <code class=\"language-text\">setState()</code>, React merges the object you provide into the current state.</p>\n<p>For example, your state may contain several independent variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">posts</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>      <span class=\"token literal-property property\">comments</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<p>Then you can update them independently with separate <code class=\"language-text\">setState()</code> calls:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">fetchPosts</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">posts</span><span class=\"token operator\">:</span> response<span class=\"token punctuation\">.</span>posts      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">fetchComments</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">response</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">comments</span><span class=\"token operator\">:</span> response<span class=\"token punctuation\">.</span>comments      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span></code></pre></div>\n<p>The merging is shallow, so <code class=\"language-text\">this.setState({comments})</code> leaves <code class=\"language-text\">this.state.posts</code> intact, but completely replaces <code class=\"language-text\">this.state.comments</code>.</p>\n<hr>\n<h2>The Data Flows Down</h2>\n<p>Neither parent nor child components can know if a certain component is stateful or stateless, and they shouldn't care whether it is defined as a function or a class.</p>\n<p>This is why state is often called local or encapsulated. It is not accessible to any component other than the one that owns and sets it.</p>\n<p>A component may choose to pass its state down as props to its child components:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>FormattedDate date<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<p>The <code class=\"language-text\">FormattedDate</code> component would receive the <code class=\"language-text\">date</code> in its props and wouldn't know whether it came from the <code class=\"language-text\">Clock</code>'s state, from the <code class=\"language-text\">Clock</code>'s props, or was typed by hand:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">FormattedDate</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>It is <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>date<span class=\"token punctuation\">.</span><span class=\"token function\">toLocaleTimeString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/zKRqNB?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/GREgWEp?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/GREgWEp?editors=0010\">https://codepen.io/bgoonz/pen/GREgWEp?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/zKRqNB?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>This is commonly called a \"top-down\" or \"unidirectional\" data flow. Any state is always owned by some specific component, and any data or UI derived from that state can only affect components \"below\" them in the tree.</p>\n<p>If you imagine a component tree as a waterfall of props, each component's state is like an additional water source that joins it at an arbitrary point but also flows down.</p>\n<p>To show that all components are truly isolated, we can create an <code class=\"language-text\">App</code> component that renders three <code class=\"language-text\">&lt;Clock></code>s:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>Clock <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>Clock <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>Clock <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>App <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/vXdGmd?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/YzQPZQK?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/YzQPZQK?editors=0010\">https://codepen.io/bgoonz/pen/YzQPZQK?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/vXdGmd?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Each <code class=\"language-text\">Clock</code> sets up its own timer and updates independently.</p>\n<p>In React apps, whether a component is stateful or stateless is considered an implementation detail of the component that may change over time. You can use stateless components inside stateful components, and vice versa.</p>\n<hr>\n<h2><strong>Handling Events</strong></h2>\n<h2>Handling events with React elements is very similar to handling events on DOM elements. There are some syntax differences:</h2>\n<ul>\n<li>React events are named using camelCase, rather than lowercase.</li>\n<li>With JSX you pass a function as the event handler, rather than a string.</li>\n</ul>\n<p>For example, the HTML:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>button onclick<span class=\"token operator\">=</span><span class=\"token string\">\"activateLasers()\"</span><span class=\"token operator\">></span>Activate Lasers<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span></code></pre></div>\n<p>is slightly different in React:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>activateLasers<span class=\"token punctuation\">}</span><span class=\"token operator\">></span> Activate Lasers<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span></code></pre></div>\n<p>Another difference is that you cannot return <code class=\"language-text\">false</code> to prevent default behavior in React. You must call <code class=\"language-text\">preventDefault</code> explicitly. For example, with plain HTML, to prevent the default form behavior of submitting, you can write:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>form onsubmit<span class=\"token operator\">=</span><span class=\"token string\">\"console.log('You clicked submit.'); return false\"</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>button type<span class=\"token operator\">=</span><span class=\"token string\">\"submit\"</span><span class=\"token operator\">></span>Submit<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span></code></pre></div>\n<p>In React, this could instead be:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Form</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You clicked submit.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>form onSubmit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>handleSubmit<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>button type<span class=\"token operator\">=</span><span class=\"token string\">\"submit\"</span><span class=\"token operator\">></span>Submit<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Here, <code class=\"language-text\">e</code> is a synthetic event. React defines these synthetic events according to the <a href=\"https://www.w3.org/TR/DOM-Level-3-Events/\">W3C spec</a>, so you don't need to worry about cross-browser compatibility. React events do not work exactly the same as native events. See the <code class=\"language-text\">[SyntheticEvent](&lt;https://reactjs.org/docs/events.html>)</code> reference guide to learn more.</p>\n<p>When using React, you generally don't need to call <code class=\"language-text\">addEventListener</code> to add listeners to a DOM element after it is created. Instead, just provide a listener when the element is initially rendered.</p>\n<p>When you define a component using an <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes\">ES6 class</a>, a common pattern is for an event handler to be a method on the class. For example, this <code class=\"language-text\">Toggle</code> component renders a button that lets the user toggle between \"ON\" and \"OFF\" states:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Toggle</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">isToggleOn</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// This binding is necessary to make `this` work in the callback    this.handleClick = this.handleClick.bind(this);  }</span>\n\n  <span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">prevState</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>      <span class=\"token literal-property property\">isToggleOn</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span>prevState<span class=\"token punctuation\">.</span>isToggleOn    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token punctuation\">}</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>        <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>isToggleOn <span class=\"token operator\">?</span> <span class=\"token string\">'ON'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'OFF'</span><span class=\"token punctuation\">}</span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&lt;</span>Toggle <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/xEmzGg?editors=0010\">Try it on CodePen</a></strong></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/xEmzGg?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>You have to be careful about the meaning of <code class=\"language-text\">this</code> in JSX callbacks. In JavaScript, class methods are not <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind\">bound</a> by default. If you forget to bind <code class=\"language-text\">this.handleClick</code> and pass it to <code class=\"language-text\">onClick</code>, <code class=\"language-text\">this</code> will be <code class=\"language-text\">undefined</code> when the function is actually called.</p>\n<p>This is not React-specific behavior; it is a part of <a href=\"https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/\">how functions work in JavaScript</a>. Generally, if you refer to a method without <code class=\"language-text\">()</code> after it, such as <code class=\"language-text\">onClick={this.handleClick}</code>, you should bind that method.</p>\n<p>If calling <code class=\"language-text\">bind</code> annoys you, there are two ways you can get around this. If you are using the experimental <a href=\"https://babeljs.io/docs/plugins/transform-class-properties/\">public class fields syntax</a>, you can use class fields to correctly bind callbacks:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">LoggingButton</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// This syntax ensures `this` is bound within handleClick.  // Warning: this is *experimental* syntax.  handleClick = () => {    console.log('this is:', this);  }render() {</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>        Click me\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>This syntax is enabled by default in <a href=\"https://github.com/facebookincubator/create-react-app\">Create React App</a>.</p>\n<p>If you aren't using class fields syntax, you can use an <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions\">arrow function</a> in the callback:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">LoggingButton</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'this is:'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// This syntax ensures `this` is bound within handleClick    return (      &lt;button onClick={() => this.handleClick()}>        Click me</span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The problem with this syntax is that a different callback is created each time the <code class=\"language-text\">LoggingButton</code> renders. In most cases, this is fine. However, if this callback is passed as a prop to lower components, those components might do an extra re-rendering. We generally recommend binding in the constructor or using the class fields syntax, to avoid this sort of performance problem.</p>\n<hr>\n<h2>Passing Arguments to Event Handlers</h2>\n<p>Inside a loop, it is common to want to pass an extra parameter to an event handler. For example, if <code class=\"language-text\">id</code> is the row ID, either of the following would work:</p>\n<p><code class=\"language-text\">&lt;button onClick={(e) => this.deleteRow(id, e)}>Delete Row&lt;/button>\n&lt;button onClick={this.deleteRow.bind(this, id)}>Delete Row&lt;/button></code></p>\n<p>The above two lines are equivalent, and use <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions\">arrow functions</a> and <code class=\"language-text\">[Function.prototype.bind](&lt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind>)</code> respectively.</p>\n<p>In both cases, the <code class=\"language-text\">e</code> argument representing the React event will be passed as a second argument after the ID. With an arrow function, we have to pass it explicitly, but with <code class=\"language-text\">bind</code> any further arguments are automatically forwarded.</p>\n<hr>\n<h2><strong>Conditional Rendering</strong></h2>\n<h2>In React, you can create distinct components that encapsulate behavior you need. Then, you can render only some of them, depending on the state of your application.</h2>\n<p>Conditional rendering in React works the same way conditions work in JavaScript. Use JavaScript operators like <code class=\"language-text\">[if](&lt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else>)</code> or the <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator\">conditional operator</a> to create elements representing the current state, and let React update the UI to match them.</p>\n<p>Consider these two components:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">UserGreeting</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Welcome back<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">GuestGreeting</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Please sign up<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We'll create a <code class=\"language-text\">Greeting</code> component that displays either of these components depending on whether a user is logged in:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Greeting</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> isLoggedIn <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>isLoggedIn<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>isLoggedIn<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>UserGreeting <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>GuestGreeting <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n    <span class=\"token comment\">// Try changing to isLoggedIn={true}:</span>\n    <span class=\"token operator\">&lt;</span>Greeting isLoggedIn<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/ZpVxNq?editors=0011\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/mdwyWmJ?editors=0011\"></a><a href=\"https://codepen.io/bgoonz/pen/mdwyWmJ?editors=0011\">https://codepen.io/bgoonz/pen/mdwyWmJ?editors=0011</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/ZpVxNq?editors=0011\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>This example renders a different greeting depending on the value of <code class=\"language-text\">isLoggedIn</code> prop.</p>\n<hr>\n<h2>Element Variables</h2>\n<p>You can use variables to store elements. This can help you conditionally render a part of the component while the rest of the output doesn't change.</p>\n<p>Consider these two new components representing Logout and Login buttons:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">LoginButton</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>onClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Login<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">LogoutButton</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>onClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Logout<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>In the example below, we will create a <a href=\"https://reactjs.org/docs/state-and-lifecycle.html#adding-local-state-to-a-class\">stateful component</a> called <code class=\"language-text\">LoginControl</code>.</p>\n<p>It will render either <code class=\"language-text\">&lt;LoginButton /></code> or <code class=\"language-text\">&lt;LogoutButton /></code> depending on its current state. It will also render a <code class=\"language-text\">&lt;Greeting /></code> from the previous example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">LoginControl</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleLoginClick <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleLoginClick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleLogoutClick <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleLogoutClick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">isLoggedIn</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleLoginClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">isLoggedIn</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleLogoutClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">isLoggedIn</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> isLoggedIn <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>isLoggedIn<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> button<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>isLoggedIn<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            button <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>LogoutButton onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleLogoutClick<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            button <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>LoginButton onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleLoginClick<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>Greeting isLoggedIn<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isLoggedIn<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>button<span class=\"token punctuation\">}</span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>LoginControl <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/QKzAgB?editors=0010\">Try it on CodePen</a></strong></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/QKzAgB?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>While declaring a variable and using an <code class=\"language-text\">if</code> statement is a fine way to conditionally render a component, sometimes you might want to use a shorter syntax. There are a few ways to inline conditions in JSX, explained below.</p>\n<hr>\n<h2>Inline If with Logical &#x26;&#x26; Operator</h2>\n<p>You may <a href=\"https://reactjs.org/docs/introducing-jsx.html#embedding-expressions-in-jsx\">embed expressions in JSX</a> by wrapping them in curly braces. This includes the JavaScript logical <code class=\"language-text\">&amp;&amp;</code> operator. It can be handy for conditionally including an element:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Mailbox</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> unreadMessages <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>unreadMessages<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Hello<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>unreadMessages<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span> You have <span class=\"token punctuation\">{</span>unreadMessages<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">}</span> unread messages<span class=\"token punctuation\">.</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> messages <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'React'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Re: React'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Re:Re: React'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Mailbox unreadMessages<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>messages<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/ozJddz?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/VwWYppo?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/VwWYppo?editors=0010\">https://codepen.io/bgoonz/pen/VwWYppo?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/ozJddz?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>It works because in JavaScript, <code class=\"language-text\">true &amp;&amp; expression</code> always evaluates to <code class=\"language-text\">expression</code>, and <code class=\"language-text\">false &amp;&amp; expression</code> always evaluates to <code class=\"language-text\">false</code>.</p>\n<p>Therefore, if the condition is <code class=\"language-text\">true</code>, the element right after <code class=\"language-text\">&amp;&amp;</code> will appear in the output. If it is <code class=\"language-text\">false</code>, React will ignore and skip it.</p>\n<p>Note that returning a falsy expression will still cause the element after <code class=\"language-text\">&amp;&amp;</code> to be skipped but will return the falsy expression. In the example below, <code class=\"language-text\">&lt;div>0&lt;/div></code> will be returned by the render method.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> count <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>      <span class=\"token punctuation\">{</span> count <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Messages<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>count<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Inline If-Else with Conditional Operator</h2>\n<p>Another method for conditionally rendering elements inline is to use the JavaScript conditional operator <code class=\"language-text\">[condition ? true : false](&lt;https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator>)</code>.</p>\n<p>In the example below, we use it to conditionally render a small block of text.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> isLoggedIn <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>isLoggedIn<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>      The user is <span class=\"token operator\">&lt;</span>b<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>isLoggedIn <span class=\"token operator\">?</span> <span class=\"token string\">'currently'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'not'</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>b<span class=\"token operator\">></span> logged <span class=\"token keyword\">in</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>It can also be used for larger expressions although it is less obvious what's going on:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> isLoggedIn <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>isLoggedIn<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>      <span class=\"token punctuation\">{</span>isLoggedIn        <span class=\"token operator\">?</span> <span class=\"token operator\">&lt;</span>LogoutButton onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleLogoutClick<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>        <span class=\"token operator\">:</span> <span class=\"token operator\">&lt;</span>LoginButton onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleLoginClick<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>      <span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Just like in JavaScript, it is up to you to choose an appropriate style based on what you and your team consider more readable. Also remember that whenever conditions become too complex, it might be a good time to <a href=\"https://reactjs.org/docs/components-and-props.html#extracting-components\">extract a component</a>.</p>\n<hr>\n<h2>Preventing Component from Rendering</h2>\n<p>In rare cases you might want a component to hide itself even though it was rendered by another component. To do this return <code class=\"language-text\">null</code> instead of its render output.</p>\n<p>In the example below, the <code class=\"language-text\">&lt;WarningBanner /></code> is rendered depending on the value of the prop called <code class=\"language-text\">warn</code>. If the value of the prop is <code class=\"language-text\">false</code>, then the component does not render:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">WarningBanner</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>props<span class=\"token punctuation\">.</span>warn<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"warning\"</span><span class=\"token operator\">></span> Warning<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Page</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">showWarning</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleToggleClick <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleToggleClick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleToggleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">state</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">showWarning</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span>state<span class=\"token punctuation\">.</span>showWarning\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>WarningBanner warn<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>showWarning<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleToggleClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>showWarning <span class=\"token operator\">?</span> <span class=\"token string\">'Hide'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'Show'</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Page <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/Xjoqwm?editors=0010\">Try it on CodePen</a></strong></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/Xjoqwm?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Returning <code class=\"language-text\">null</code> from a component's <code class=\"language-text\">render</code> method does not affect the firing of the component's lifecycle methods. For instance <code class=\"language-text\">componentDidUpdate</code> will still be called.</p>\n<hr>\n<h2><strong>Lists and Keys</strong></h2>\n<h2>First, let's review how you transform lists in JavaScript.</h2>\n<p>Given the code below, we use the <code class=\"language-text\">[map()](&lt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map>)</code> function to take an array of <code class=\"language-text\">numbers</code> and double their values. We assign the new array returned by <code class=\"language-text\">map()</code> to the variable <code class=\"language-text\">doubled</code> and log it:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> doubled <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> number <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>doubled<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This code logs <code class=\"language-text\">[2, 4, 6, 8, 10]</code> to the console.</p>\n<p>In React, transforming arrays into lists of <a href=\"https://reactjs.org/docs/rendering-elements.html\">elements</a> is nearly identical.</p>\n<hr>\n<h2>Rendering Multiple Components</h2>\n<p>You can build collections of elements and <a href=\"https://reactjs.org/docs/introducing-jsx.html#embedding-expressions-in-jsx\">include them in JSX</a> using curly braces <code class=\"language-text\">{}</code>.</p>\n<p>Below, we loop through the <code class=\"language-text\">numbers</code> array using the JavaScript <code class=\"language-text\">[map()](&lt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map>)</code> function. We return a <code class=\"language-text\">&lt;li></code> element for each item. Finally, we assign the resulting array of elements to <code class=\"language-text\">listItems</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> listItems <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We include the entire <code class=\"language-text\">listItems</code> array inside a <code class=\"language-text\">&lt;ul></code> element, and <a href=\"https://reactjs.org/docs/rendering-elements.html#rendering-an-element-into-the-dom\">render it to the DOM</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>listItems<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/GjPyQr?editors=0011\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/eYRmvvr?editors=0011\"></a><a href=\"https://codepen.io/bgoonz/pen/eYRmvvr?editors=0011\">https://codepen.io/bgoonz/pen/eYRmvvr?editors=0011</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/GjPyQr?editors=0011\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>This code displays a bullet list of numbers between 1 and 5.</p>\n<hr>\n<h2>Basic List Component</h2>\n<p>Usually you would render lists inside a <a href=\"https://reactjs.org/docs/components-and-props.html\">component</a>.</p>\n<p>We can refactor the previous example into a component that accepts an array of <code class=\"language-text\">numbers</code> and outputs a list of elements.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">NumberList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>numbers<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> listItems <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>listItems<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>NumberList numbers<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>numbers<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>When you run this code, you'll be given a warning that a key should be provided for list items. A \"key\" is a special string attribute you need to include when creating lists of elements. We'll discuss why it's important in the next section.</p>\n<p>Let's assign a <code class=\"language-text\">key</code> to our list items inside <code class=\"language-text\">numbers.map()</code> and fix the missing key issue.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">NumberList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>numbers<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> listItems <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>listItems<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>NumberList numbers<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>numbers<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/jrXYRR?editors=0011\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/yLXyMMP?editors=0011\"></a><a href=\"https://codepen.io/bgoonz/pen/yLXyMMP?editors=0011\">https://codepen.io/bgoonz/pen/yLXyMMP?editors=0011</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/jrXYRR?editors=0011\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<h2>Keys</h2>\n<p>Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> listItems <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> todoItems <span class=\"token operator\">=</span> todos<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todo</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>todo<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>todo<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>When you don't have stable IDs for rendered items, you may use the item index as a key as a last resort:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> todoItems <span class=\"token operator\">=</span> todos<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todo<span class=\"token punctuation\">,</span> index</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n  <span class=\"token comment\">// Only do this if items have no stable IDs  &lt;li key={index}>    {todo.text}</span>\n  <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny's article for an <a href=\"https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318\">in-depth explanation on the negative impacts of using an index as a key</a>. If you choose not to assign an explicit key to list items then React will default to using indexes as keys.</p>\n<p>Here is an <a href=\"https://reactjs.org/docs/reconciliation.html#recursing-on-children\">in-depth explanation about why keys are necessary</a> if you're interested in learning more.</p>\n<hr>\n<h2>Extracting Components with Keys</h2>\n<p>Keys only make sense in the context of the surrounding array.</p>\n<p>For example, if you <a href=\"https://reactjs.org/docs/components-and-props.html#extracting-components\">extract</a> a <code class=\"language-text\">ListItem</code> component, you should keep the key on the <code class=\"language-text\">&lt;ListItem /></code> elements in the array rather than on the <code class=\"language-text\">&lt;li></code> element in the <code class=\"language-text\">ListItem</code> itself.</p>\n<p><strong>Example: Incorrect Key Usage</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">ListItem</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> value <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token comment\">// Wrong! There is no need to specify the key here:    &lt;li key={value.toString()}>      {value}</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">NumberList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>numbers<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> listItems <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n    <span class=\"token comment\">// Wrong! The key should have been specified here:    &lt;ListItem value={number} />  );</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>      <span class=\"token punctuation\">{</span>listItems<span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&lt;</span>NumberList numbers<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>numbers<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Example: Correct Key Usage</strong></p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">ListItem</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Correct! There is no need to specify the key here:  return &lt;li>{props.value}&lt;/li>;}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">NumberList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>numbers<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> listItems <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n    <span class=\"token comment\">// Correct! Key should be specified inside the array.    &lt;ListItem key={number.toString()} value={number} />  );</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>      <span class=\"token punctuation\">{</span>listItems<span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&lt;</span>NumberList numbers<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>numbers<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/ZXeOGM?editors=0010\">Try it on CodePen</a></strong></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/ZXeOGM?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>A good rule of thumb is that elements inside the <code class=\"language-text\">map()</code> call need keys.</p>\n<hr>\n<h2>Keys Must Only Be Unique Among Siblings</h2>\n<p>Keys used within arrays should be unique among their siblings. However, they don't need to be globally unique. We can use the same keys when we produce two different arrays:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Blog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> sidebar <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>posts<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">post</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>post<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>post<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> content <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>posts<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">post</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>post<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>h3<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>post<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h3<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>post<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">{</span>sidebar<span class=\"token punctuation\">}</span> <span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>content<span class=\"token punctuation\">}</span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> posts <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> <span class=\"token string\">'Welcome to learning React!'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> <span class=\"token string\">'Installation'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> <span class=\"token string\">'You can install React from npm.'</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>Blog posts<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>posts<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'root'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/NRZYGN?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/mdwyWWy?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/mdwyWWy?editors=0010\">https://codepen.io/bgoonz/pen/mdwyWWy?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/NRZYGN?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Keys serve as a hint to React but they don't get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> content <span class=\"token operator\">=</span> posts<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">post</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>Post key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>post<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span> id<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>post<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span> title<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>post<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>With the example above, the <code class=\"language-text\">Post</code> component can read <code class=\"language-text\">props.id</code>, but not <code class=\"language-text\">props.key</code>.</p>\n<hr>\n<h2>Embedding map() in JSX</h2>\n<p>In the examples above we declared a separate <code class=\"language-text\">listItems</code> variable and included it in JSX:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">NumberList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>numbers<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> listItems <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>ListItem key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>listItems<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>JSX allows <a href=\"https://reactjs.org/docs/introducing-jsx.html#embedding-expressions-in-jsx\">embedding any expression</a> in curly braces so we could inline the <code class=\"language-text\">map()</code> result:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">NumberList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> props<span class=\"token punctuation\">.</span>numbers<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">{</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                <span class=\"token operator\">&lt;</span>ListItem key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>number<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/BLvYrB?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/JjJoWEw?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/JjJoWEw?editors=0010\">https://codepen.io/bgoonz/pen/JjJoWEw?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/BLvYrB?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Sometimes this results in clearer code, but this style can also be abused. Like in JavaScript, it is up to you to decide whether it is worth extracting a variable for readability. Keep in mind that if the <code class=\"language-text\">map()</code> body is too nested, it might be a good time to <a href=\"https://reactjs.org/docs/components-and-props.html#extracting-components\">extract a component</a>.</p>\n<hr>\n<h2><strong>Forms</strong></h2>\n<h2>HTML form elements work a bit differently from other DOM elements in React, because form elements naturally keep some internal state. For example, this form in plain HTML accepts a single name:</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>form<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>\n        <span class=\"token literal-property property\">Name</span><span class=\"token operator\">:</span>\n        <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> name<span class=\"token operator\">=</span><span class=\"token string\">\"name\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"submit\"</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Submit\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span></code></pre></div>\n<p>This form has the default HTML form behavior of browsing to a new page when the user submits the form. If you want this behavior in React, it just works. But in most cases, it's convenient to have a JavaScript function that handles the submission of the form and has access to the data that the user entered into the form. The standard way to achieve this is with a technique called \"controlled components\".</p>\n<hr>\n<h2>Controlled Components</h2>\n<p>In HTML, form elements such as <code class=\"language-text\">&lt;input></code>, <code class=\"language-text\">&lt;textarea></code>, and <code class=\"language-text\">&lt;select></code> typically maintain their own state and update it based on user input. In React, mutable state is typically kept in the state property of components, and only updated with <code class=\"language-text\">[setState()](&lt;https://reactjs.org/docs/react-component.html#setstate>)</code>.</p>\n<p>We can combine the two by making the React state be the \"single source of truth\". Then the React component that renders a form also controls what happens in that form on subsequent user input. An input form element whose value is controlled by React in this way is called a \"controlled component\".</p>\n<p>For example, if we want to make the previous example log the name when it is submitted, we can write the form as a controlled component:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">NameForm</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSubmit <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'A name was submitted: '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        event<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>form onSubmit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSubmit<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token literal-property property\">Name</span><span class=\"token operator\">:</span>\n                    <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"submit\"</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Submit\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/VmmPgp?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/rNwayjv?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/rNwayjv?editors=0010\">https://codepen.io/bgoonz/pen/rNwayjv?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/VmmPgp?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Since the <code class=\"language-text\">value</code> attribute is set on our form element, the displayed value will always be <code class=\"language-text\">this.state.value</code>, making the React state the source of truth. Since <code class=\"language-text\">handleChange</code> runs on every keystroke to update the React state, the displayed value will update as the user types.</p>\n<p>With a controlled component, the input's value is always driven by the React state. While this means you have to type a bit more code, you can now pass the value to other UI elements too, or reset it from other event handlers.</p>\n<hr>\n<h2>The textarea Tag</h2>\n<p>In HTML, a <code class=\"language-text\">&lt;textarea></code> element defines its text by its children:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>textarea<span class=\"token operator\">></span>Hello there<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span> is some text <span class=\"token keyword\">in</span> a text area<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>textarea<span class=\"token operator\">></span></code></pre></div>\n<p>In React, a <code class=\"language-text\">&lt;textarea></code> uses a <code class=\"language-text\">value</code> attribute instead. This way, a form using a <code class=\"language-text\">&lt;textarea></code> can be written very similarly to a form that uses a single-line input:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">EssayForm</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">'Please write an essay about your favorite DOM element.'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSubmit <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'An essay was submitted: '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        event<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>form onSubmit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSubmit<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token literal-property property\">Essay</span><span class=\"token operator\">:</span>\n                    <span class=\"token operator\">&lt;</span>textarea value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"submit\"</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Submit\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Notice that <code class=\"language-text\">this.state.value</code> is initialized in the constructor, so that the text area starts off with some text in it.</p>\n<hr>\n<h2>The select Tag</h2>\n<p>In HTML, <code class=\"language-text\">&lt;select></code> creates a drop-down list. For example, this HTML creates a drop-down list of flavors:</p>\n<p>`<select></p>\n<option value=\"grapefruit\">Grapefruit</option>\n<option value=\"lime\">Lime</option>\n<option selected value=\"coconut\">Coconut</option>\n<option value=\"mango\">Mango</option>\n</select>`\n<p>Note that the Coconut option is initially selected, because of the <code class=\"language-text\">selected</code> attribute. React, instead of using this <code class=\"language-text\">selected</code> attribute, uses a <code class=\"language-text\">value</code> attribute on the root <code class=\"language-text\">select</code> tag. This is more convenient in a controlled component because you only need to update it in one place. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">FlavorForm</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">'coconut'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSubmit <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">handleSubmit</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Your favorite flavor is: '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        event<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>form onSubmit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSubmit<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                    Pick your favorite flavor<span class=\"token operator\">:</span>\n                    <span class=\"token operator\">&lt;</span>select value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span>option value<span class=\"token operator\">=</span><span class=\"token string\">\"grapefruit\"</span><span class=\"token operator\">></span>Grapefruit<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>option<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>option value<span class=\"token operator\">=</span><span class=\"token string\">\"lime\"</span><span class=\"token operator\">></span>Lime<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>option<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>option value<span class=\"token operator\">=</span><span class=\"token string\">\"coconut\"</span><span class=\"token operator\">></span>Coconut<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>option<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>option value<span class=\"token operator\">=</span><span class=\"token string\">\"mango\"</span><span class=\"token operator\">></span>\n                            Mango\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>option<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>select<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"submit\"</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Submit\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/JbbEzX?editors=0010\">Try it on CodePen</a></strong></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/JbbEzX?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Overall, this makes it so that <code class=\"language-text\">&lt;input type=\"text\"></code>, <code class=\"language-text\">&lt;textarea></code>, and <code class=\"language-text\">&lt;select></code> all work very similarly - they all accept a <code class=\"language-text\">value</code> attribute that you can use to implement a controlled component.</p>\n<blockquote>\n<p>NoteYou can pass an array into the value attribute, allowing you to select multiple options in a select tag:&#x3C;select multiple={true} value={['B', 'C']}></p>\n</blockquote>\n<h2>The file input Tag</h2>\n<p>In HTML, an <code class=\"language-text\">&lt;input type=\"file\"></code> lets the user choose one or more files from their device storage to be uploaded to a server or manipulated by JavaScript via the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications\">File API</a>.</p>\n<p><code class=\"language-text\">&lt;input type=\"file\" /></code></p>\n<p>Because its value is read-only, it is an <strong>uncontrolled</strong> component in React. It is discussed together with other uncontrolled components <a href=\"https://reactjs.org/docs/uncontrolled-components.html#the-file-input-tag\">later in the documentation</a>.</p>\n<hr>\n<h2>Handling Multiple Inputs</h2>\n<p>When you need to handle multiple controlled <code class=\"language-text\">input</code> elements, you can add a <code class=\"language-text\">name</code> attribute to each element and let the handler function choose what to do based on the value of <code class=\"language-text\">event.target.name</code>.</p>\n<p>For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Reservation</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">isGoing</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">numberOfGuests</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleInputChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleInputChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleInputChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> target <span class=\"token operator\">=</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> value <span class=\"token operator\">=</span> target<span class=\"token punctuation\">.</span>type <span class=\"token operator\">===</span> <span class=\"token string\">'checkbox'</span> <span class=\"token operator\">?</span> target<span class=\"token punctuation\">.</span>checked <span class=\"token operator\">:</span> target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> name <span class=\"token operator\">=</span> target<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">[</span>name<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> value\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>form<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                    Is going<span class=\"token operator\">:</span>\n                    <span class=\"token operator\">&lt;</span>input name<span class=\"token operator\">=</span><span class=\"token string\">\"isGoing\"</span> type<span class=\"token operator\">=</span><span class=\"token string\">\"checkbox\"</span> checked<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>isGoing<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleInputChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>br <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>label<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                    Number <span class=\"token keyword\">of</span> <span class=\"token literal-property property\">guests</span><span class=\"token operator\">:</span>\n                    <span class=\"token operator\">&lt;</span>input name<span class=\"token operator\">=</span><span class=\"token string\">\"numberOfGuests\"</span> type<span class=\"token operator\">=</span><span class=\"token string\">\"number\"</span> value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>numberOfGuests<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleInputChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>form<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/wgedvV?editors=0010\">Try it on CodePen</a></strong></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/wgedvV?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Note how we used the ES6 <a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names\">computed property name</a> syntax to update the state key corresponding to the given input name:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token punctuation\">[</span>name<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> value\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>It is equivalent to this ES5 code:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> partialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\npartialState<span class=\"token punctuation\">[</span>name<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span>partialState<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Also, since <code class=\"language-text\">setState()</code> automatically <a href=\"https://reactjs.org/docs/state-and-lifecycle.html#state-updates-are-merged\">merges a partial state into the current state</a>, we only needed to call it with the changed parts.</p>\n<hr>\n<h2>Controlled Input Null Value</h2>\n<p>Specifying the value prop on a <a href=\"https://reactjs.org/docs/forms.html#controlled-components\">controlled component</a> prevents the user from changing the input unless you desire so. If you've specified a <code class=\"language-text\">value</code> but the input is still editable, you may have accidentally set <code class=\"language-text\">value</code> to <code class=\"language-text\">undefined</code> or <code class=\"language-text\">null</code>.</p>\n<p>The following code demonstrates this. (The input is locked at first but becomes editable after a short delay.)</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>input value<span class=\"token operator\">=</span><span class=\"token string\">\"hi\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> mountNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    ReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>input value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> mountNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Alternatives to Controlled Components</h2>\n<p>It can sometimes be tedious to use controlled components, because you need to write an event handler for every way your data can change and pipe all of the input state through a React component. This can become particularly annoying when you are converting a preexisting codebase to React, or integrating a React application with a non-React library. In these situations, you might want to check out <a href=\"https://reactjs.org/docs/uncontrolled-components.html\">uncontrolled components</a>, an alternative technique for implementing input forms.</p>\n<hr>\n<h2>Fully-Fledged Solutions</h2>\n<p>If you're looking for a complete solution including validation, keeping track of the visited fields, and handling form submission, <a href=\"https://jaredpalmer.com/formik\">Formik</a> is one of the popular choices. However, it is built on the same principles of controlled components and managing state --- so don't neglect to learn them.</p>\n<hr>\n<h2><strong>Lifting State Up</strong></h2>\n<h2>Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor. Let's see how this works in action.</h2>\n<p>In this section, we will create a temperature calculator that calculates whether the water would boil at a given temperature.</p>\n<p>We will start with a component called <code class=\"language-text\">BoilingVerdict</code>. It accepts the <code class=\"language-text\">celsius</code> temperature as a prop, and prints whether it is enough to boil the water:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">BoilingVerdict</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">.</span>celsius <span class=\"token operator\">>=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>The water would boil<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>The water would not boil<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Next, we will create a component called <code class=\"language-text\">Calculator</code>. It renders an <code class=\"language-text\">&lt;input></code> that lets you enter the temperature, and keeps its value in <code class=\"language-text\">this.state.temperature</code>.</p>\n<p>Additionally, it renders the <code class=\"language-text\">BoilingVerdict</code> for the current input value.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Calculator</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> temperature <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>temperature<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>fieldset<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>legend<span class=\"token operator\">></span>Enter temperature <span class=\"token keyword\">in</span> <span class=\"token literal-property property\">Celsius</span><span class=\"token operator\">:</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>legend<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>input value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>temperature<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>BoilingVerdict\n                    celsius<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">parseFloat</span><span class=\"token punctuation\">(</span>temperature<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>fieldset<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/ZXeOBm?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/zYzxZoL?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/zYzxZoL?editors=0010\">https://codepen.io/bgoonz/pen/zYzxZoL?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/ZXeOBm?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<h2>Adding a Second Input</h2>\n<p>Our new requirement is that, in addition to a Celsius input, we provide a Fahrenheit input, and they are kept in sync.</p>\n<p>We can start by extracting a <code class=\"language-text\">TemperatureInput</code> component from <code class=\"language-text\">Calculator</code>. We will add a new <code class=\"language-text\">scale</code> prop to it that can either be <code class=\"language-text\">\"c\"</code> or <code class=\"language-text\">\"f\"</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> scaleNames <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">c</span><span class=\"token operator\">:</span> <span class=\"token string\">'Celsius'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">f</span><span class=\"token operator\">:</span> <span class=\"token string\">'Fahrenheit'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">TemperatureInput</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> temperature <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>temperature<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> scale <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>scale<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>fieldset<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>legend<span class=\"token operator\">></span>Enter temperature <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span>scaleNames<span class=\"token punctuation\">[</span>scale<span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span><span class=\"token operator\">:</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>legend<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>input value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>temperature<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>fieldset<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We can now change the <code class=\"language-text\">Calculator</code> to render two separate temperature inputs:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Calculator</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>TemperatureInput scale<span class=\"token operator\">=</span><span class=\"token string\">\"c\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>TemperatureInput scale<span class=\"token operator\">=</span><span class=\"token string\">\"f\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/jGBryx?editors=0010\">Try it on CodePen</a></strong></p>\n<p><a href=\"https://codepen.io/bgoonz/pen/QWgwpGv?editors=0010\"></a><a href=\"https://codepen.io/bgoonz/pen/QWgwpGv?editors=0010\">https://codepen.io/bgoonz/pen/QWgwpGv?editors=0010</a></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/jGBryx?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>We have two inputs now, but when you enter the temperature in one of them, the other doesn't update. This contradicts our requirement: we want to keep them in sync.</p>\n<p>We also can't display the <code class=\"language-text\">BoilingVerdict</code> from <code class=\"language-text\">Calculator</code>. The <code class=\"language-text\">Calculator</code> doesn't know the current temperature because it is hidden inside the <code class=\"language-text\">TemperatureInput</code>.</p>\n<hr>\n<h2>Writing Conversion Functions</h2>\n<p>First, we will write two functions to convert from Celsius to Fahrenheit and back:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">toCelsius</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">fahrenheit</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>fahrenheit <span class=\"token operator\">-</span> <span class=\"token number\">32</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">9</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">toFahrenheit</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">celsius</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>celsius <span class=\"token operator\">*</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">32</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>These two functions convert numbers. We will write another function that takes a string <code class=\"language-text\">temperature</code> and a converter function as arguments and returns a string. We will use it to calculate the value of one input based on the other input.</p>\n<p>It returns an empty string on an invalid <code class=\"language-text\">temperature</code>, and it keeps the output rounded to the third decimal place:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">tryConvert</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">temperature<span class=\"token punctuation\">,</span> convert</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> input <span class=\"token operator\">=</span> <span class=\"token function\">parseFloat</span><span class=\"token punctuation\">(</span>temperature<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>Number<span class=\"token punctuation\">.</span><span class=\"token function\">isNaN</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">const</span> output <span class=\"token operator\">=</span> <span class=\"token function\">convert</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> rounded <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">round</span><span class=\"token punctuation\">(</span>output <span class=\"token operator\">*</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> rounded<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>For example, <code class=\"language-text\">tryConvert('abc', toCelsius)</code> returns an empty string, and <code class=\"language-text\">tryConvert('10.22', toFahrenheit)</code> returns <code class=\"language-text\">'50.396'</code>.</p>\n<hr>\n<h2>Lifting State Up</h2>\n<p>Currently, both <code class=\"language-text\">TemperatureInput</code> components independently keep their values in the local state:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">TemperatureInput</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> temperature <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>temperature<span class=\"token punctuation\">;</span>    <span class=\"token comment\">// ...</span></code></pre></div>\n<p>However, we want these two inputs to be in sync with each other. When we update the Celsius input, the Fahrenheit input should reflect the converted temperature, and vice versa.</p>\n<p>In React, sharing state is accomplished by moving it up to the closest common ancestor of the components that need it. This is called \"lifting state up\". We will remove the local state from the <code class=\"language-text\">TemperatureInput</code> and move it into the <code class=\"language-text\">Calculator</code> instead.</p>\n<p>If the <code class=\"language-text\">Calculator</code> owns the shared state, it becomes the \"source of truth\" for the current temperature in both inputs. It can instruct them both to have values that are consistent with each other. Since the props of both <code class=\"language-text\">TemperatureInput</code> components are coming from the same parent <code class=\"language-text\">Calculator</code> component, the two inputs will always be in sync.</p>\n<p>Let's see how this works step by step.</p>\n<p>First, we will replace <code class=\"language-text\">this.state.temperature</code> with <code class=\"language-text\">this.props.temperature</code> in the <code class=\"language-text\">TemperatureInput</code> component. For now, let's pretend <code class=\"language-text\">this.props.temperature</code> already exists, although we will need to pass it from the <code class=\"language-text\">Calculator</code> in the future:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Before: const temperature = this.state.temperature;</span>\n    <span class=\"token keyword\">const</span> temperature <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>temperature<span class=\"token punctuation\">;</span>    <span class=\"token comment\">// ...</span></code></pre></div>\n<p>We know that <a href=\"https://reactjs.org/docs/components-and-props.html#props-are-read-only\">props are read-only</a>. When the <code class=\"language-text\">temperature</code> was in the local state, the <code class=\"language-text\">TemperatureInput</code> could just call <code class=\"language-text\">this.setState()</code> to change it. However, now that the <code class=\"language-text\">temperature</code> is coming from the parent as a prop, the <code class=\"language-text\">TemperatureInput</code> has no control over it.</p>\n<p>In React, this is usually solved by making a component \"controlled\". Just like the DOM <code class=\"language-text\">&lt;input></code> accepts both a <code class=\"language-text\">value</code> and an <code class=\"language-text\">onChange</code> prop, so can the custom <code class=\"language-text\">TemperatureInput</code> accept both <code class=\"language-text\">temperature</code> and <code class=\"language-text\">onTemperatureChange</code> props from its parent <code class=\"language-text\">Calculator</code>.</p>\n<p>Now, when the <code class=\"language-text\">TemperatureInput</code> wants to update its temperature, it calls <code class=\"language-text\">this.props.onTemperatureChange</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n  <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Before: this.setState({temperature: e.target.value});</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span><span class=\"token function\">onTemperatureChange</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token comment\">// ...</span></code></pre></div>\n<blockquote>\n<p>Note:There is no special meaning to either temperature or onTemperatureChange prop names in custom components. We could have called them anything else, like name them value and onChange which is a common convention.</p>\n</blockquote>\n<p>The <code class=\"language-text\">onTemperatureChange</code> prop will be provided together with the <code class=\"language-text\">temperature</code> prop by the parent <code class=\"language-text\">Calculator</code> component. It will handle the change by modifying its own local state, thus re-rendering both inputs with the new values. We will look at the new <code class=\"language-text\">Calculator</code> implementation very soon.</p>\n<p>Before diving into the changes in the <code class=\"language-text\">Calculator</code>, let's recap our changes to the <code class=\"language-text\">TemperatureInput</code> component. We have removed the local state from it, and instead of reading <code class=\"language-text\">this.state.temperature</code>, we now read <code class=\"language-text\">this.props.temperature</code>. Instead of calling <code class=\"language-text\">this.setState()</code> when we want to make a change, we now call <code class=\"language-text\">this.props.onTemperatureChange()</code>, which will be provided by the <code class=\"language-text\">Calculator</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">TemperatureInput</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span><span class=\"token function\">onTemperatureChange</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> temperature <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>temperature<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> scale <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>scale<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>fieldset<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>legend<span class=\"token operator\">></span>Enter temperature <span class=\"token keyword\">in</span> <span class=\"token punctuation\">{</span>scaleNames<span class=\"token punctuation\">[</span>scale<span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span><span class=\"token operator\">:</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>legend<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>input value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>temperature<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>fieldset<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now let's turn to the <code class=\"language-text\">Calculator</code> component.</p>\n<p>We will store the current input's <code class=\"language-text\">temperature</code> and <code class=\"language-text\">scale</code> in its local state. This is the state we \"lifted up\" from the inputs, and it will serve as the \"source of truth\" for both of them. It is the minimal representation of all the data we need to know in order to render both inputs.</p>\n<p>For example, if we enter 37 into the Celsius input, the state of the <code class=\"language-text\">Calculator</code> component will be:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> <span class=\"token string\">'37'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">scale</span><span class=\"token operator\">:</span> <span class=\"token string\">'c'</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>If we later edit the Fahrenheit field to be 212, the state of the <code class=\"language-text\">Calculator</code> will be:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> <span class=\"token string\">'212'</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">scale</span><span class=\"token operator\">:</span> <span class=\"token string\">'f'</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We could have stored the value of both inputs but it turns out to be unnecessary. It is enough to store the value of the most recently changed input, and the scale that it represents. We can then infer the value of the other input based on the current <code class=\"language-text\">temperature</code> and <code class=\"language-text\">scale</code> alone.</p>\n<p>The inputs stay in sync because their values are computed from the same state:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Calculator</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleCelsiusChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleCelsiusChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleFahrenheitChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleFahrenheitChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">temperature</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">scale</span><span class=\"token operator\">:</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">handleCelsiusChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">temperature</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token literal-property property\">scale</span><span class=\"token operator\">:</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> temperature<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">handleFahrenheitChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">temperature</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token literal-property property\">scale</span><span class=\"token operator\">:</span> <span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> temperature<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> scale <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>scale<span class=\"token punctuation\">;</span>    <span class=\"token keyword\">const</span> temperature <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>temperature<span class=\"token punctuation\">;</span>    <span class=\"token keyword\">const</span> celsius <span class=\"token operator\">=</span> scale <span class=\"token operator\">===</span> <span class=\"token string\">'f'</span> <span class=\"token operator\">?</span> <span class=\"token function\">tryConvert</span><span class=\"token punctuation\">(</span>temperature<span class=\"token punctuation\">,</span> toCelsius<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> temperature<span class=\"token punctuation\">;</span>    <span class=\"token keyword\">const</span> fahrenheit <span class=\"token operator\">=</span> scale <span class=\"token operator\">===</span> <span class=\"token string\">'c'</span> <span class=\"token operator\">?</span> <span class=\"token function\">tryConvert</span><span class=\"token punctuation\">(</span>temperature<span class=\"token punctuation\">,</span> toFahrenheit<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> temperature<span class=\"token punctuation\">;</span><span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>        <span class=\"token operator\">&lt;</span>TemperatureInputscale<span class=\"token operator\">=</span><span class=\"token string\">\"c\"</span>          temperature<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>celsius<span class=\"token punctuation\">}</span>          onTemperatureChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleCelsiusChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>        <span class=\"token operator\">&lt;</span>TemperatureInputscale<span class=\"token operator\">=</span><span class=\"token string\">\"f\"</span>          temperature<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>fahrenheit<span class=\"token punctuation\">}</span>          onTemperatureChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleFahrenheitChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>        <span class=\"token operator\">&lt;</span>BoilingVerdict          celsius<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">parseFloat</span><span class=\"token punctuation\">(</span>celsius<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/WZpxpz?editors=0010\">Try it on CodePen</a></strong></p>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codepen.io/gaearon/pen/WZpxpz?editors=0010\" height=\"900px\" width=\"100%\"> </iframe>\n<br>\n<p>Now, no matter which input you edit, <code class=\"language-text\">this.state.temperature</code> and <code class=\"language-text\">this.state.scale</code> in the <code class=\"language-text\">Calculator</code> get updated. One of the inputs gets the value as is, so any user input is preserved, and the other input value is always recalculated based on it.</p>\n<p>Let's recap what happens when you edit an input:</p>\n<ul>\n<li>React calls the function specified as <code class=\"language-text\">onChange</code> on the DOM <code class=\"language-text\">&lt;input></code>. In our case, this is the <code class=\"language-text\">handleChange</code> method in the <code class=\"language-text\">TemperatureInput</code> component.</li>\n<li>The <code class=\"language-text\">handleChange</code> method in the <code class=\"language-text\">TemperatureInput</code> component calls <code class=\"language-text\">this.props.onTemperatureChange()</code> with the new desired value. Its props, including <code class=\"language-text\">onTemperatureChange</code>, were provided by its parent component, the <code class=\"language-text\">Calculator</code>.</li>\n<li>When it previously rendered, the <code class=\"language-text\">Calculator</code> had specified that <code class=\"language-text\">onTemperatureChange</code> of the Celsius <code class=\"language-text\">TemperatureInput</code> is the <code class=\"language-text\">Calculator</code>'s <code class=\"language-text\">handleCelsiusChange</code> method, and <code class=\"language-text\">onTemperatureChange</code> of the Fahrenheit <code class=\"language-text\">TemperatureInput</code> is the <code class=\"language-text\">Calculator</code>'s <code class=\"language-text\">handleFahrenheitChange</code> method. So either of these two <code class=\"language-text\">Calculator</code> methods gets called depending on which input we edited.</li>\n<li>Inside these methods, the <code class=\"language-text\">Calculator</code> component asks React to re-render itself by calling <code class=\"language-text\">this.setState()</code> with the new input value and the current scale of the input we just edited.</li>\n<li>React calls the <code class=\"language-text\">Calculator</code> component's <code class=\"language-text\">render</code> method to learn what the UI should look like. The values of both inputs are recomputed based on the current temperature and the active scale. The temperature conversion is performed here.</li>\n<li>React calls the <code class=\"language-text\">render</code> methods of the individual <code class=\"language-text\">TemperatureInput</code> components with their new props specified by the <code class=\"language-text\">Calculator</code>. It learns what their UI should look like.</li>\n<li>React calls the <code class=\"language-text\">render</code> method of the <code class=\"language-text\">BoilingVerdict</code> component, passing the temperature in Celsius as its props.</li>\n<li>React DOM updates the DOM with the boiling verdict and to match the desired input values. The input we just edited receives its current value, and the other input is updated to the temperature after conversion.</li>\n</ul>\n<p>Every update goes through the same steps so the inputs stay in sync.</p>\n<hr>\n<h2>Lessons Learned</h2>\n<p>There should be a single \"source of truth\" for any data that changes in a React application. Usually, the state is first added to the component that needs it for rendering. Then, if other components also need it, you can lift it up to their closest common ancestor. Instead of trying to sync the state between different components, you should rely on the <a href=\"https://reactjs.org/docs/state-and-lifecycle.html#the-data-flows-down\">top-down data flow</a>.</p>\n<p>Lifting state involves writing more \"boilerplate\" code than two-way binding approaches, but as a benefit, it takes less work to find and isolate bugs. Since any state \"lives\" in some component and that component alone can change it, the surface area for bugs is greatly reduced. Additionally, you can implement any custom logic to reject or transform user input.</p>\n<p>If something can be derived from either props or state, it probably shouldn't be in the state. For example, instead of storing both <code class=\"language-text\">celsiusValue</code> and <code class=\"language-text\">fahrenheitValue</code>, we store just the last edited <code class=\"language-text\">temperature</code> and its <code class=\"language-text\">scale</code>. The value of the other input can always be calculated from them in the <code class=\"language-text\">render()</code> method. This lets us clear or apply rounding to the other field without losing any precision in the user input.</p>\n<p>When you see something wrong in the UI, you can use <a href=\"https://github.com/facebook/react/tree/main/packages/react-devtools\">React Developer Tools</a> to inspect the props and move up the tree until you find the component responsible for updating the state. This lets you trace the bugs to their source:</p>\n<p><img src=\"https://reactjs.org/ef94afc3447d75cdc245c77efb0d63be/react-devtools-state.gif\" alt=\"https://reactjs.org/ef94afc3447d75cdc245c77efb0d63be/react-devtools-state.gif\"></p>\n<h2><strong>Composition vs Inheritance</strong></h2>\n<h2>React has a powerful composition model, and we recommend using composition instead of inheritance to reuse code between components.</h2>\n<p>In this section, we will consider a few problems where developers new to React often reach for inheritance, and show how we can solve them with composition.</p>\n<hr>\n<h2>Containment</h2>\n<p>Some components don't know their children ahead of time. This is especially common for components like <code class=\"language-text\">Sidebar</code> or <code class=\"language-text\">Dialog</code> that represent generic \"boxes\".</p>\n<p>We recommend that such components use the special <code class=\"language-text\">children</code> prop to pass children elements directly into their output:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">FancyBorder</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token string\">'FancyBorder FancyBorder-'</span> <span class=\"token operator\">+</span> props<span class=\"token punctuation\">.</span>color<span class=\"token punctuation\">}</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>This lets other components pass arbitrary children to them by nesting the JSX:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">WelcomeDialog</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>FancyBorder color<span class=\"token operator\">=</span><span class=\"token string\">\"blue\"</span><span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>h1 className<span class=\"token operator\">=</span><span class=\"token string\">\"Dialog-title\"</span><span class=\"token operator\">></span> Welcome <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"Dialog-message\"</span><span class=\"token operator\">></span> Thank you <span class=\"token keyword\">for</span> visiting our spacecraft<span class=\"token operator\">!</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>FancyBorder<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/ozqNOV?editors=0010\">Try it on CodePen</a></strong></p>\n<p>Anything inside the <code class=\"language-text\">&lt;FancyBorder></code> JSX tag gets passed into the <code class=\"language-text\">FancyBorder</code> component as a <code class=\"language-text\">children</code> prop. Since <code class=\"language-text\">FancyBorder</code> renders <code class=\"language-text\">{props.children}</code> inside a <code class=\"language-text\">&lt;div></code>, the passed elements appear in the final output.</p>\n<p>While this is less common, sometimes you might need multiple \"holes\" in a component. In such cases you may come up with your own convention instead of using <code class=\"language-text\">children</code>:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">SplitPane</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"SplitPane\"</span><span class=\"token operator\">></span>      <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"SplitPane-left\"</span><span class=\"token operator\">></span>        <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">}</span>      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>      <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"SplitPane-right\"</span><span class=\"token operator\">></span>        <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">}</span>      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>SplitPaneleft<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>\n        <span class=\"token operator\">&lt;</span>Contacts <span class=\"token operator\">/</span><span class=\"token operator\">></span>      <span class=\"token punctuation\">}</span>right<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>\n        <span class=\"token operator\">&lt;</span>Chat <span class=\"token operator\">/</span><span class=\"token operator\">></span>      <span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/gwZOJp?editors=0010\">Try it on CodePen</a></strong></p>\n<p>React elements like <code class=\"language-text\">&lt;Contacts /></code> and <code class=\"language-text\">&lt;Chat /></code> are just objects, so you can pass them as props like any other data. This approach may remind you of \"slots\" in other libraries but there are no limitations on what you can pass as props in React.</p>\n<hr>\n<h2>Specialization</h2>\n<p>Sometimes we think about components as being \"special cases\" of other components. For example, we might say that a <code class=\"language-text\">WelcomeDialog</code> is a special case of <code class=\"language-text\">Dialog</code>.</p>\n<p>In React, this is also achieved by composition, where a more \"specific\" component renders a more \"generic\" one and configures it with props:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Dialog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>FancyBorder color<span class=\"token operator\">=</span><span class=\"token string\">\"blue\"</span><span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>h1 className<span class=\"token operator\">=</span><span class=\"token string\">\"Dialog-title\"</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">}</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"Dialog-message\"</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">}</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>FancyBorder<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">WelcomeDialog</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>Dialog title<span class=\"token operator\">=</span><span class=\"token string\">\"Welcome\"</span> message<span class=\"token operator\">=</span><span class=\"token string\">\"Thank you for visiting our spacecraft!\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/kkEaOZ?editors=0010\">Try it on CodePen</a></strong></p>\n<p>Composition works equally well for components defined as classes:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Dialog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>FancyBorder color<span class=\"token operator\">=</span><span class=\"token string\">\"blue\"</span><span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span>h1 className<span class=\"token operator\">=</span><span class=\"token string\">\"Dialog-title\"</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"Dialog-message\"</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>FancyBorder<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">SignUpDialog</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleChange</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSignUp <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleSignUp</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">login</span><span class=\"token operator\">:</span> <span class=\"token string\">''</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>Dialog title<span class=\"token operator\">=</span><span class=\"token string\">\"Mars Exploration Program\"</span> message<span class=\"token operator\">=</span><span class=\"token string\">\"How should we refer to you?\"</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span>input value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>login<span class=\"token punctuation\">}</span> onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleChange<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleSignUp<span class=\"token punctuation\">}</span><span class=\"token operator\">></span> Sign Me Up<span class=\"token operator\">!</span> <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Dialog<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleChange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">login</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">handleSignUp</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Welcome aboard, </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>login<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">!</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong><a href=\"https://codepen.io/gaearon/pen/gwZbYa?editors=0010\">Try it on CodePen</a></strong></p>\n<h2>So What About Inheritance?</h2>\n<p>At Facebook, we use React in thousands of components, and we haven't found any use cases where we would recommend creating component inheritance hierarchies.</p>\n<p>Props and composition give you all the flexibility you need to customize a component's look and behavior in an explicit and safe way. Remember that components may accept arbitrary props, including primitive values, React elements, or functions.</p>\n<p>If you want to reuse non-UI functionality between components, we suggest extracting it into a separate JavaScript module. The components may import it and use that function, object, or a class, without extending it.</p>\n<hr>\n<h2><strong>Thinking in React</strong></h2>\n<h2>React is, in our opinion, the premier way to build big, fast Web apps with JavaScript. It has scaled very well for us at Facebook and Instagram.</h2>\n<p>One of the many great parts of React is how it makes you think about apps as you build them. In this document, we'll walk you through the thought process of building a searchable product data table using React.</p>\n<hr>\n<h2>Start With A Mock</h2>\n<p>Imagine that we already have a JSON API and a mock from our designer. The mock looks like this:</p>\n<p><img src=\"https://reactjs.org/static/1071fbcc9eed01fddc115b41e193ec11/d4770/thinking-in-react-mock.png\" alt=\"https://reactjs.org/static/1071fbcc9eed01fddc115b41e193ec11/d4770/thinking-in-react-mock.png\"></p>\n<p>Our JSON API returns some data that looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">category</span><span class=\"token operator\">:</span> <span class=\"token string\">'Sporting Goods'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">price</span><span class=\"token operator\">:</span> <span class=\"token string\">'$49.99'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">stocked</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Football'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">category</span><span class=\"token operator\">:</span> <span class=\"token string\">'Sporting Goods'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">price</span><span class=\"token operator\">:</span> <span class=\"token string\">'$9.99'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">stocked</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baseball'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">category</span><span class=\"token operator\">:</span> <span class=\"token string\">'Sporting Goods'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">price</span><span class=\"token operator\">:</span> <span class=\"token string\">'$29.99'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">stocked</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Basketball'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">category</span><span class=\"token operator\">:</span> <span class=\"token string\">'Electronics'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">price</span><span class=\"token operator\">:</span> <span class=\"token string\">'$99.99'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">stocked</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'iPod Touch'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">category</span><span class=\"token operator\">:</span> <span class=\"token string\">'Electronics'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">price</span><span class=\"token operator\">:</span> <span class=\"token string\">'$399.99'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">stocked</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'iPhone 5'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">category</span><span class=\"token operator\">:</span> <span class=\"token string\">'Electronics'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">price</span><span class=\"token operator\">:</span> <span class=\"token string\">'$199.99'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">stocked</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Nexus 7'</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Step 1: Break The UI Into A Component Hierarchy</h2>\n<p>The first thing you'll want to do is to draw boxes around every component (and subcomponent) in the mock and give them all names. If you're working with a designer, they may have already done this, so go talk to them! Their Photoshop layer names may end up being the names of your React components!</p>\n<p>But how do you know what should be its own component? Use the same techniques for deciding if you should create a new function or object. One such technique is the <a href=\"https://en.wikipedia.org/wiki/Single_responsibility_principle\">single responsibility principle</a>, that is, a component should ideally only do one thing. If it ends up growing, it should be decomposed into smaller subcomponents.</p>\n<p>Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly, your UI (and therefore your component structure) will map nicely. That's because UI and data models tend to adhere to the same <em>information architecture</em>. Separate your UI into components, where each component matches one piece of your data model.</p>\n<p><img src=\"https://reactjs.org/static/eb8bda25806a89ebdc838813bdfa3601/6b2ea/thinking-in-react-components.png\" alt=\"https://reactjs.org/static/eb8bda25806a89ebdc838813bdfa3601/6b2ea/thinking-in-react-components.png\"></p>\n<p>You'll see here that we have five components in our app. We've italicized the data each component represents.</p>\n<ol>\n<li><strong><code class=\"language-text\">FilterableProductTable</code> (orange):</strong> contains the entirety of the example</li>\n<li><strong><code class=\"language-text\">SearchBar</code> (blue):</strong> receives all <em>user input</em></li>\n<li><strong><code class=\"language-text\">ProductTable</code> (green):</strong> displays and filters the <em>data collection</em> based on <em>user input</em></li>\n<li><strong><code class=\"language-text\">ProductCategoryRow</code> (turquoise):</strong> displays a heading for each <em>category</em></li>\n<li><strong><code class=\"language-text\">ProductRow</code> (red):</strong> displays a row for each <em>product</em></li>\n</ol>\n<p>If you look at <code class=\"language-text\">ProductTable</code>, you'll see that the table header (containing the \"Name\" and \"Price\" labels) isn't its own component. This is a matter of preference, and there's an argument to be made either way. For this example, we left it as part of <code class=\"language-text\">ProductTable</code> because it is part of rendering the <em>data collection</em> which is <code class=\"language-text\">ProductTable</code>'s responsibility. However, if this header grows to be complex (e.g., if we were to add affordances for sorting), it would certainly make sense to make this its own <code class=\"language-text\">ProductTableHeader</code> component.</p>\n<p>Now that we've identified the components in our mock, let's arrange them into a hierarchy. Components that appear within another component in the mock should appear as a child in the hierarchy:</p>\n<ul>\n<li>\n<p><code class=\"language-text\">FilterableProductTable</code></p>\n<ul>\n<li><code class=\"language-text\">SearchBar</code></li>\n<li>\n<p><code class=\"language-text\">ProductTable</code></p>\n<ul>\n<li><code class=\"language-text\">ProductCategoryRow</code></li>\n<li><code class=\"language-text\">ProductRow</code></li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<h2>Step 2: Build A Static Version in React</h2>\n<p>See the Pen <a href=\"https://codepen.io/gaearon/pen/BwWzwm\">Thinking In React: Step 2</a> on <a href=\"https://codepen.io/\">CodePen</a>.</p>\n<p>Now that you have your component hierarchy, it's time to implement your app. The easiest way is to build a version that takes your data model and renders the UI but has no interactivity. It's best to decouple these processes because building a static version requires a lot of typing and no thinking, and adding interactivity requires a lot of thinking and not a lot of typing. We'll see why.</p>\n<p>To build a static version of your app that renders your data model, you'll want to build components that reuse other components and pass data using <em>props</em>. <em>props</em> are a way of passing data from parent to child. If you're familiar with the concept of <em>state</em>, <strong>don't use state at all</strong> to build this static version. State is reserved only for interactivity, that is, data that changes over time. Since this is a static version of the app, you don't need it.</p>\n<p>You can build top-down or bottom-up. That is, you can either start with building the components higher up in the hierarchy (i.e. starting with <code class=\"language-text\">FilterableProductTable</code>) or with the ones lower in it (<code class=\"language-text\">ProductRow</code>). In simpler examples, it's usually easier to go top-down, and on larger projects, it's easier to go bottom-up and write tests as you build.</p>\n<p>At the end of this step, you'll have a library of reusable components that render your data model. The components will only have <code class=\"language-text\">render()</code> methods since this is a static version of your app. The component at the top of the hierarchy (<code class=\"language-text\">FilterableProductTable</code>) will take your data model as a prop. If you make a change to your underlying data model and call <code class=\"language-text\">ReactDOM.render()</code> again, the UI will be updated. You can see how your UI is updated and where to make changes. React's <strong>one-way data flow</strong> (also called <em>one-way binding</em>) keeps everything modular and fast.</p>\n<p>Refer to the <a href=\"https://reactjs.org/docs/\">React docs</a> if you need help executing this step.</p>\n<hr>\n<h2>A Brief Interlude: Props vs State</h2>\n<p>There are two types of \"model\" data in React: props and state. It's important to understand the distinction between the two; skim <a href=\"https://reactjs.org/docs/state-and-lifecycle.html\">the official React docs</a> if you aren't sure what the difference is. See also <a href=\"https://reactjs.org/docs/faq-state.html#what-is-the-difference-between-state-and-props\">FAQ: What is the difference between state and props?</a></p>\n<h2>Step 3: Identify The Minimal (but complete) Representation Of UI State</h2>\n<p>To make your UI interactive, you need to be able to trigger changes to your underlying data model. React achieves this with <strong>state</strong>.</p>\n<p>To build your app correctly, you first need to think of the minimal set of mutable state that your app needs. The key here is <a href=\"https://en.wikipedia.org/wiki/Don%27t_repeat_yourself\">DRY: <em>Don't Repeat Yourself</em></a>. Figure out the absolute minimal representation of the state your application needs and compute everything else you need on-demand. For example, if you're building a TODO list, keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count, take the length of the TODO items array.</p>\n<p>Think of all the pieces of data in our example application. We have:</p>\n<ul>\n<li>The original list of products</li>\n<li>The search text the user has entered</li>\n<li>The value of the checkbox</li>\n<li>The filtered list of products</li>\n</ul>\n<p>Let's go through each one and figure out which one is state. Ask three questions about each piece of data:</p>\n<ol>\n<li>Is it passed in from a parent via props? If so, it probably isn't state.</li>\n<li>Does it remain unchanged over time? If so, it probably isn't state.</li>\n<li>Can you compute it based on any other state or props in your component? If so, it isn't state.</li>\n</ol>\n<p>The original list of products is passed in as props, so that's not state. The search text and the checkbox seem to be state since they change over time and can't be computed from anything. And finally, the filtered list of products isn't state because it can be computed by combining the original list of products with the search text and value of the checkbox.</p>\n<p>So finally, our state is:</p>\n<ul>\n<li>The search text the user has entered</li>\n<li>The value of the checkbox</li>\n</ul>\n<h2>Step 4: Identify Where Your State Should Live</h2>\n<p>See the Pen <a href=\"https://codepen.io/gaearon/pen/qPrNQZ\">Thinking In React: Step 4</a> on <a href=\"https://codepen.io/\">CodePen</a>.</p>\n<p>OK, so we've identified what the minimal set of app state is. Next, we need to identify which component mutates, or <em>owns</em>, this state.</p>\n<p>Remember: React is all about one-way data flow down the component hierarchy. It may not be immediately clear which component should own what state. <strong>This is often the most challenging part for newcomers to understand,</strong> so follow these steps to figure it out:</p>\n<p>For each piece of state in your application:</p>\n<ul>\n<li>Identify every component that renders something based on that state.</li>\n<li>Find a common owner component (a single component above all the components that need the state in the hierarchy).</li>\n<li>Either the common owner or another component higher up in the hierarchy should own the state.</li>\n<li>If you can't find a component where it makes sense to own the state, create a new component solely for holding the state and add it somewhere in the hierarchy above the common owner component.</li>\n</ul>\n<p>Let's run through this strategy for our application:</p>\n<ul>\n<li><code class=\"language-text\">ProductTable</code> needs to filter the product list based on state and <code class=\"language-text\">SearchBar</code> needs to display the search text and checked state.</li>\n<li>The common owner component is <code class=\"language-text\">FilterableProductTable</code>.</li>\n<li>It conceptually makes sense for the filter text and checked value to live in <code class=\"language-text\">FilterableProductTable</code></li>\n</ul>\n<p>Cool, so we've decided that our state lives in <code class=\"language-text\">FilterableProductTable</code>. First, add an instance property <code class=\"language-text\">this.state = {filterText: '', inStockOnly: false}</code> to <code class=\"language-text\">FilterableProductTable</code>'s <code class=\"language-text\">constructor</code> to reflect the initial state of your application. Then, pass <code class=\"language-text\">filterText</code> and <code class=\"language-text\">inStockOnly</code> to <code class=\"language-text\">ProductTable</code> and <code class=\"language-text\">SearchBar</code> as a prop. Finally, use these props to filter the rows in <code class=\"language-text\">ProductTable</code> and set the values of the form fields in <code class=\"language-text\">SearchBar</code>.</p>\n<p>You can start seeing how your application will behave: set <code class=\"language-text\">filterText</code> to <code class=\"language-text\">\"ball\"</code> and refresh your app. You'll see that the data table is updated correctly.</p>\n<hr>\n<h2>Step 5: Add Inverse Data Flow</h2>\n<p>See the Pen <a href=\"https://codepen.io/gaearon/pen/LzWZvb\">Thinking In React: Step 5</a> on <a href=\"https://codepen.io/\">CodePen</a>.</p>\n<p>So far, we've built an app that renders correctly as a function of props and state flowing down the hierarchy. Now it's time to support data flowing the other way: the form components deep in the hierarchy need to update the state in <code class=\"language-text\">FilterableProductTable</code>.</p>\n<p>React makes this data flow explicit to help you understand how your program works, but it does require a little more typing than traditional two-way data binding.</p>\n<p>If you try to type or check the box in the current version of the example, you'll see that React ignores your input. This is intentional, as we've set the <code class=\"language-text\">value</code> prop of the <code class=\"language-text\">input</code> to always be equal to the <code class=\"language-text\">state</code> passed in from <code class=\"language-text\">FilterableProductTable</code>.</p>\n<p>Let's think about what we want to happen. We want to make sure that whenever the user changes the form, we update the state to reflect the user input. Since components should only update their own state, <code class=\"language-text\">FilterableProductTable</code> will pass callbacks to <code class=\"language-text\">SearchBar</code> that will fire whenever the state should be updated. We can use the <code class=\"language-text\">onChange</code> event on the inputs to be notified of it. The callbacks passed by <code class=\"language-text\">FilterableProductTable</code> will call <code class=\"language-text\">setState()</code>, and the app will be updated.</p>\n<hr>\n<h2>And That's It</h2>\n<p>Hopefully, this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you're used to, remember that code is read far more than it's written, and it's less difficult to read this modular, explicit code. As you start to build large libraries of components, you'll appreciate this explicitness and modularity, and with code reuse, your lines of code will start to shrink. :)</p>\n<p><a href=\"https://www.notion.so/Advanced-Content-fbe1ec3ca3544951b5763b051b843949\">Advanced Content</a></p>\n<p><a href=\"https://www.notion.so/React-Component-3dc17bc49a8e4d7e89efcc1281e747d9\">React Component</a></p>"},{"url":"/docs/reference/awesome-lists/","relativePath":"docs/reference/awesome-lists.md","relativeDir":"docs/reference","base":"awesome-lists.md","name":"awesome-lists","frontmatter":{"title":"Awesome Lists","weight":0,"excerpt":"this is an awesome list of awesome lists","seo":{"title":"Awesome Lists","description":"Search Awesome Lists","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Awesome Lists:</h2>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://search-awesome.vercel.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"   allowfullscreen>\n</iframe>\n<br>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/awesome-nodejs\"><strong>sindresorhus/awesome-nodejs</strong></a></li>\n<li><a href=\"https://github.com/bcoe/awesome-cross-platform-nodejs\"><strong>bcoe/awesome-cross-platform-nodejs</strong></a></li>\n<li><a href=\"https://github.com/dypsilon/frontend-dev-bookmarks\"><strong>dypsilon/frontend-dev-bookmarks</strong></a></li>\n<li><a href=\"https://github.com/vsouza/awesome-ios\"><strong>vsouza/awesome-ios</strong></a></li>\n<li><a href=\"https://github.com/JStumpp/awesome-android\"><strong>JStumpp/awesome-android</strong></a></li>\n<li><a href=\"https://github.com/weblancaster/awesome-IoT-hybrid\"><strong>weblancaster/awesome-IoT-hybrid</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-electron\"><strong>sindresorhus/awesome-electron</strong></a></li>\n<li><a href=\"https://github.com/busterc/awesome-cordova\"><strong>busterc/awesome-cordova</strong></a></li>\n<li><a href=\"https://github.com/jondot/awesome-react-native\"><strong>jondot/awesome-react-native</strong></a></li>\n<li><a href=\"https://github.com/XamSome/awesome-xamarin\"><strong>XamSome/awesome-xamarin</strong></a></li>\n<li><a href=\"https://github.com/inputsh/awesome-linux\"><strong>inputsh/awesome-linux</strong></a></li>\n<li><a href=\"https://github.com/Friz-zy/awesome-linux-containers\"><strong>Friz-zy/awesome-linux-containers</strong></a></li>\n<li><a href=\"https://github.com/zoidbergwill/awesome-ebpf\"><strong>zoidbergwill/awesome-ebpf</strong></a></li>\n<li><a href=\"https://github.com/PandaFoss/Awesome-Arch\"><strong>PandaFoss/Awesome-Arch</strong></a></li>\n<li><a href=\"https://github.com/iCHAIT/awesome-macOS\"><strong>iCHAIT/awesome-macOS</strong></a></li>\n<li><a href=\"https://github.com/herrbischoff/awesome-macos-command-line\"><strong>herrbischoff/awesome-macos-command-line</strong></a></li>\n<li><a href=\"https://github.com/agarrharr/awesome-macos-screensavers\"><strong>agarrharr/awesome-macos-screensavers</strong></a></li>\n<li><a href=\"https://github.com/jaywcjlove/awesome-mac\"><strong>jaywcjlove/awesome-mac</strong></a></li>\n<li><a href=\"https://github.com/serhii-londar/open-source-mac-os-apps\"><strong>serhii-londar/open-source-mac-os-apps</strong></a></li>\n<li><a href=\"https://github.com/yenchenlin/awesome-watchos\"><strong>yenchenlin/awesome-watchos</strong></a></li>\n<li><a href=\"https://github.com/deephacks/awesome-jvm\"><strong>deephacks/awesome-jvm</strong></a></li>\n<li><a href=\"https://github.com/mailtoharshit/awesome-salesforce\"><strong>mailtoharshit/awesome-salesforce</strong></a></li>\n<li><a href=\"https://github.com/donnemartin/awesome-aws\"><strong>donnemartin/awesome-aws</strong></a></li>\n<li><a href=\"https://github.com/Awesome-Windows/Awesome\"><strong>Awesome-Windows/Awesome</strong></a></li>\n<li><a href=\"https://github.com/ipfs/awesome-ipfs\"><strong>ipfs/awesome-ipfs</strong></a></li>\n<li><a href=\"https://github.com/fuse-compound/awesome-fuse\"><strong>fuse-compound/awesome-fuse</strong></a></li>\n<li><a href=\"https://github.com/ianstormtaylor/awesome-heroku\"><strong>ianstormtaylor/awesome-heroku</strong></a></li>\n<li><a href=\"https://github.com/thibmaek/awesome-raspberry-pi\"><strong>thibmaek/awesome-raspberry-pi</strong></a></li>\n<li><a href=\"https://github.com/JesseTG/awesome-qt\"><strong>JesseTG/awesome-qt</strong></a></li>\n<li><a href=\"https://github.com/fregante/Awesome-WebExtensions\"><strong>fregante/Awesome-WebExtensions</strong></a></li>\n<li><a href=\"https://github.com/motion-open-source/awesome-rubymotion\"><strong>motion-open-source/awesome-rubymotion</strong></a></li>\n<li><a href=\"https://github.com/vitalets/awesome-smart-tv\"><strong>vitalets/awesome-smart-tv</strong></a></li>\n<li><a href=\"https://github.com/Kazhnuz/awesome-gnome\"><strong>Kazhnuz/awesome-gnome</strong></a></li>\n<li><a href=\"https://github.com/francoism90/awesome-kde\"><strong>francoism90/awesome-kde</strong></a></li>\n<li><a href=\"https://github.com/quozd/awesome-dotnet\"><strong>quozd/awesome-dotnet</strong></a></li>\n<li><a href=\"https://github.com/thangchung/awesome-dotnet-core\"><strong>thangchung/awesome-dotnet-core</strong></a></li>\n<li><a href=\"https://github.com/ironcev/awesome-roslyn\"><strong>ironcev/awesome-roslyn</strong></a></li>\n<li><a href=\"https://github.com/miguelmota/awesome-amazon-alexa\"><strong>miguelmota/awesome-amazon-alexa</strong></a></li>\n<li><a href=\"https://github.com/jonleibowitz/awesome-digitalocean\"><strong>jonleibowitz/awesome-digitalocean</strong></a></li>\n<li><a href=\"https://github.com/Solido/awesome-flutter\"><strong>Solido/awesome-flutter</strong></a></li>\n<li><a href=\"https://github.com/frenck/awesome-home-assistant\"><strong>frenck/awesome-home-assistant</strong></a></li>\n<li><a href=\"https://github.com/victorshinya/awesome-ibmcloud\"><strong>victorshinya/awesome-ibmcloud</strong></a></li>\n<li><a href=\"https://github.com/jthegedus/awesome-firebase\"><strong>jthegedus/awesome-firebase</strong></a></li>\n<li><a href=\"https://github.com/fkromer/awesome-ros2\"><strong>fkromer/awesome-ros2</strong></a></li>\n<li><a href=\"https://github.com/adafruit/awesome-adafruitio\"><strong>adafruit/awesome-adafruitio</strong></a></li>\n<li><a href=\"https://github.com/irazasyed/awesome-cloudflare\"><strong>irazasyed/awesome-cloudflare</strong></a></li>\n<li><a href=\"https://github.com/ravirupareliya/awesome-actions-on-google\"><strong>ravirupareliya/awesome-actions-on-google</strong></a></li>\n<li><a href=\"https://github.com/agucova/awesome-esp\"><strong>agucova/awesome-esp</strong></a></li>\n<li><a href=\"https://github.com/denolib/awesome-deno\"><strong>denolib/awesome-deno</strong></a></li>\n<li><a href=\"https://github.com/balintkissdev/awesome-dos\"><strong>balintkissdev/awesome-dos</strong></a></li>\n<li><a href=\"https://github.com/nix-community/awesome-nix\"><strong>nix-community/awesome-nix</strong></a></li>\n<li><a href=\"https://github.com/sorrycc/awesome-javascript\"><strong>sorrycc/awesome-javascript</strong></a></li>\n<li><a href=\"https://github.com/wbinnssmith/awesome-promises\"><strong>wbinnssmith/awesome-promises</strong></a></li>\n<li><a href=\"https://github.com/standard/awesome-standard\"><strong>standard/awesome-standard</strong></a></li>\n<li><a href=\"https://github.com/bolshchikov/js-must-watch\"><strong>bolshchikov/js-must-watch</strong></a></li>\n<li><a href=\"https://github.com/loverajoel/jstips\"><strong>loverajoel/jstips</strong></a></li>\n<li><a href=\"https://github.com/Kikobeats/awesome-network-js\"><strong>Kikobeats/awesome-network-js</strong></a></li>\n<li><a href=\"https://github.com/parro-it/awesome-micro-npm-packages\"><strong>parro-it/awesome-micro-npm-packages</strong></a></li>\n<li><a href=\"https://github.com/feross/awesome-mad-science\"><strong>feross/awesome-mad-science</strong></a></li>\n<li><a href=\"https://github.com/maxogden/maintenance-modules\"><strong>maxogden/maintenance-modules</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-npm\"><strong>sindresorhus/awesome-npm</strong></a></li>\n<li><a href=\"https://github.com/avajs/awesome-ava\"><strong>avajs/awesome-ava</strong></a></li>\n<li><a href=\"https://github.com/dustinspecker/awesome-eslint\"><strong>dustinspecker/awesome-eslint</strong></a></li>\n<li><a href=\"https://github.com/stoeffel/awesome-fp-js\"><strong>stoeffel/awesome-fp-js</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-observables\"><strong>sindresorhus/awesome-observables</strong></a></li>\n<li><a href=\"https://github.com/RyanZim/awesome-npm-scripts\"><strong>RyanZim/awesome-npm-scripts</strong></a></li>\n<li><a href=\"https://github.com/30-seconds/30-seconds-of-code\"><strong>30-seconds/30-seconds-of-code</strong></a></li>\n<li><a href=\"https://github.com/Richienb/awesome-ponyfills\"><strong>Richienb/awesome-ponyfills</strong></a></li>\n<li><a href=\"https://github.com/matteocrippa/awesome-swift\"><strong>matteocrippa/awesome-swift</strong></a></li>\n<li><a href=\"https://github.com/hsavit1/Awesome-Swift-Education\"><strong>hsavit1/Awesome-Swift-Education</strong></a></li>\n<li><a href=\"https://github.com/uraimo/Awesome-Swift-Playgrounds\"><strong>uraimo/Awesome-Swift-Playgrounds</strong></a></li>\n<li><a href=\"https://github.com/vinta/awesome-python\"><strong>vinta/awesome-python</strong></a></li>\n<li><a href=\"https://github.com/timofurrer/awesome-asyncio\"><strong>timofurrer/awesome-asyncio</strong></a></li>\n<li><a href=\"https://github.com/faroit/awesome-python-scientific-audio\"><strong>faroit/awesome-python-scientific-audio</strong></a></li>\n<li><a href=\"https://github.com/adafruit/awesome-circuitpython\"><strong>adafruit/awesome-circuitpython</strong></a></li>\n<li><a href=\"https://github.com/krzjoa/awesome-python-data-science\"><strong>krzjoa/awesome-python-data-science</strong></a></li>\n<li><a href=\"https://github.com/typeddjango/awesome-python-typing\"><strong>typeddjango/awesome-python-typing</strong></a></li>\n<li><a href=\"https://github.com/mcauser/awesome-micropython\"><strong>mcauser/awesome-micropython</strong></a></li>\n<li><a href=\"https://github.com/rust-unofficial/awesome-rust\"><strong>rust-unofficial/awesome-rust</strong></a></li>\n<li><a href=\"https://github.com/krispo/awesome-haskell\"><strong>krispo/awesome-haskell</strong></a></li>\n<li><a href=\"https://github.com/passy/awesome-purescript\"><strong>passy/awesome-purescript</strong></a></li>\n<li><a href=\"https://github.com/avelino/awesome-go\"><strong>avelino/awesome-go</strong></a></li>\n<li><a href=\"https://github.com/lauris/awesome-scala\"><strong>lauris/awesome-scala</strong></a></li>\n<li><a href=\"https://github.com/tindzk/awesome-scala-native\"><strong>tindzk/awesome-scala-native</strong></a></li>\n<li><a href=\"https://github.com/markets/awesome-ruby\"><strong>markets/awesome-ruby</strong></a></li>\n<li><a href=\"https://github.com/razum2um/awesome-clojure\"><strong>razum2um/awesome-clojure</strong></a></li>\n<li><a href=\"https://github.com/hantuzun/awesome-clojurescript\"><strong>hantuzun/awesome-clojurescript</strong></a></li>\n<li><a href=\"https://github.com/h4cc/awesome-elixir\"><strong>h4cc/awesome-elixir</strong></a></li>\n<li><a href=\"https://github.com/sporto/awesome-elm\"><strong>sporto/awesome-elm</strong></a></li>\n<li><a href=\"https://github.com/drobakowski/awesome-erlang\"><strong>drobakowski/awesome-erlang</strong></a></li>\n<li><a href=\"https://github.com/svaksha/Julia.jl\"><strong>svaksha/Julia.jl</strong></a></li>\n<li><a href=\"https://github.com/LewisJEllis/awesome-lua\"><strong>LewisJEllis/awesome-lua</strong></a></li>\n<li><a href=\"https://github.com/inputsh/awesome-c\"><strong>inputsh/awesome-c</strong></a></li>\n<li><a href=\"https://github.com/fffaraz/awesome-cpp\"><strong>fffaraz/awesome-cpp</strong></a></li>\n<li><a href=\"https://github.com/qinwf/awesome-R\"><strong>qinwf/awesome-R</strong></a></li>\n<li><a href=\"https://github.com/iamericfletcher/awesome-r-learning-resources\"><strong>iamericfletcher/awesome-r-learning-resources</strong></a></li>\n<li><a href=\"https://github.com/dlang-community/awesome-d\"><strong>dlang-community/awesome-d</strong></a></li>\n<li><a href=\"https://github.com/CodyReichert/awesome-cl\"><strong>CodyReichert/awesome-cl</strong></a></li>\n<li><a href=\"https://github.com/GustavBertram/awesome-common-lisp-learning\"><strong>GustavBertram/awesome-common-lisp-learning</strong></a></li>\n<li><a href=\"https://github.com/hachiojipm/awesome-perl\"><strong>hachiojipm/awesome-perl</strong></a></li>\n<li><a href=\"https://github.com/kdabir/awesome-groovy\"><strong>kdabir/awesome-groovy</strong></a></li>\n<li><a href=\"https://github.com/yissachar/awesome-dart\"><strong>yissachar/awesome-dart</strong></a></li>\n<li><a href=\"https://github.com/akullpp/awesome-java\"><strong>akullpp/awesome-java</strong></a></li>\n<li><a href=\"https://github.com/eleventigers/awesome-rxjava\"><strong>eleventigers/awesome-rxjava</strong></a></li>\n<li><a href=\"https://github.com/KotlinBy/awesome-kotlin\"><strong>KotlinBy/awesome-kotlin</strong></a></li>\n<li><a href=\"https://github.com/ocaml-community/awesome-ocaml\"><strong>ocaml-community/awesome-ocaml</strong></a></li>\n<li><a href=\"https://github.com/seancoyne/awesome-coldfusion\"><strong>seancoyne/awesome-coldfusion</strong></a></li>\n<li><a href=\"https://github.com/rabbiabram/awesome-fortran\"><strong>rabbiabram/awesome-fortran</strong></a></li>\n<li><a href=\"https://github.com/ziadoz/awesome-php\"><strong>ziadoz/awesome-php</strong></a></li>\n<li><a href=\"https://github.com/jakoch/awesome-composer\"><strong>jakoch/awesome-composer</strong></a></li>\n<li><a href=\"https://github.com/Fr0sT-Brutal/awesome-pascal\"><strong>Fr0sT-Brutal/awesome-pascal</strong></a></li>\n<li><a href=\"https://github.com/ahkscript/awesome-AutoHotkey\"><strong>ahkscript/awesome-AutoHotkey</strong></a></li>\n<li><a href=\"https://github.com/J2TeaM/awesome-AutoIt\"><strong>J2TeaM/awesome-AutoIt</strong></a></li>\n<li><a href=\"https://github.com/veelenga/awesome-crystal\"><strong>veelenga/awesome-crystal</strong></a></li>\n<li><a href=\"https://github.com/sfischer13/awesome-frege\"><strong>sfischer13/awesome-frege</strong></a></li>\n<li><a href=\"https://github.com/onqtam/awesome-cmake\"><strong>onqtam/awesome-cmake</strong></a></li>\n<li><a href=\"https://github.com/robinrodricks/awesome-actionscript3\"><strong>robinrodricks/awesome-actionscript3</strong></a></li>\n<li><a href=\"https://github.com/sfischer13/awesome-eta\"><strong>sfischer13/awesome-eta</strong></a></li>\n<li><a href=\"https://github.com/joaomilho/awesome-idris\"><strong>joaomilho/awesome-idris</strong></a></li>\n<li><a href=\"https://github.com/ohenley/awesome-ada\"><strong>ohenley/awesome-ada</strong></a></li>\n<li><a href=\"https://github.com/ebraminio/awesome-qsharp\"><strong>ebraminio/awesome-qsharp</strong></a></li>\n<li><a href=\"https://github.com/koolamusic/awesome-imba\"><strong>koolamusic/awesome-imba</strong></a></li>\n<li><a href=\"https://github.com/desiderantes/awesome-vala\"><strong>desiderantes/awesome-vala</strong></a></li>\n<li><a href=\"https://github.com/coq-community/awesome-coq\"><strong>coq-community/awesome-coq</strong></a></li>\n<li><a href=\"https://github.com/vlang/awesome-v\"><strong>vlang/awesome-v</strong></a></li>\n<li><a href=\"https://github.com/addyosmani/es6-tools\"><strong>addyosmani/es6-tools</strong></a></li>\n<li><a href=\"https://github.com/davidsonfellipe/awesome-wpo\"><strong>davidsonfellipe/awesome-wpo</strong></a></li>\n<li><a href=\"https://github.com/lvwzhen/tools\"><strong>lvwzhen/tools</strong></a></li>\n<li><a href=\"https://github.com/awesome-css-group/awesome-css\"><strong>awesome-css-group/awesome-css</strong></a></li>\n<li><a href=\"https://github.com/addyosmani/critical-path-css-tools\"><strong>addyosmani/critical-path-css-tools</strong></a></li>\n<li><a href=\"https://github.com/davidtheclark/scalable-css-reading-list\"><strong>davidtheclark/scalable-css-reading-list</strong></a></li>\n<li><a href=\"https://github.com/AllThingsSmitty/must-watch-css\"><strong>AllThingsSmitty/must-watch-css</strong></a></li>\n<li><a href=\"https://github.com/AllThingsSmitty/css-protips\"><strong>AllThingsSmitty/css-protips</strong></a></li>\n<li><a href=\"https://github.com/troxler/awesome-css-frameworks\"><strong>troxler/awesome-css-frameworks</strong></a></li>\n<li><a href=\"https://github.com/enaqx/awesome-react\"><strong>enaqx/awesome-react</strong></a></li>\n<li><a href=\"https://github.com/expede/awesome-relay\"><strong>expede/awesome-relay</strong></a></li>\n<li><a href=\"https://github.com/glauberfc/awesome-react-hooks\"><strong>glauberfc/awesome-react-hooks</strong></a></li>\n<li><a href=\"https://github.com/mateusortiz/webcomponents-the-right-way\"><strong>mateusortiz/webcomponents-the-right-way</strong></a></li>\n<li><a href=\"https://github.com/Granze/awesome-polymer\"><strong>Granze/awesome-polymer</strong></a></li>\n<li><a href=\"https://github.com/PatrickJS/awesome-angular\"><strong>PatrickJS/awesome-angular</strong></a></li>\n<li><a href=\"https://github.com/sadcitizen/awesome-backbone\"><strong>sadcitizen/awesome-backbone</strong></a></li>\n<li><a href=\"https://github.com/diegocard/awesome-html5\"><strong>diegocard/awesome-html5</strong></a></li>\n<li><a href=\"https://github.com/willianjusten/awesome-svg\"><strong>willianjusten/awesome-svg</strong></a></li>\n<li><a href=\"https://github.com/raphamorim/awesome-canvas\"><strong>raphamorim/awesome-canvas</strong></a></li>\n<li><a href=\"https://github.com/dnbard/awesome-knockout\"><strong>dnbard/awesome-knockout</strong></a></li>\n<li><a href=\"https://github.com/petk/awesome-dojo\"><strong>petk/awesome-dojo</strong></a></li>\n<li><a href=\"https://github.com/NoahBuscher/Inspire\"><strong>NoahBuscher/Inspire</strong></a></li>\n<li><a href=\"https://github.com/ember-community-russia/awesome-ember\"><strong>ember-community-russia/awesome-ember</strong></a></li>\n<li><a href=\"https://github.com/wasabeef/awesome-android-ui\"><strong>wasabeef/awesome-android-ui</strong></a></li>\n<li><a href=\"https://github.com/cjwirth/awesome-ios-ui\"><strong>cjwirth/awesome-ios-ui</strong></a></li>\n<li><a href=\"https://github.com/Urigo/awesome-meteor\"><strong>Urigo/awesome-meteor</strong></a></li>\n<li><a href=\"https://github.com/sturobson/BEM-resources\"><strong>sturobson/BEM-resources</strong></a></li>\n<li><a href=\"https://github.com/afonsopacifer/awesome-flexbox\"><strong>afonsopacifer/awesome-flexbox</strong></a></li>\n<li><a href=\"https://github.com/deanhume/typography\"><strong>deanhume/typography</strong></a></li>\n<li><a href=\"https://github.com/brunopulis/awesome-a11y\"><strong>brunopulis/awesome-a11y</strong></a></li>\n<li><a href=\"https://github.com/sachin1092/awesome-material\"><strong>sachin1092/awesome-material</strong></a></li>\n<li><a href=\"https://github.com/wbkd/awesome-d3\"><strong>wbkd/awesome-d3</strong></a></li>\n<li><a href=\"https://github.com/jonathandion/awesome-emails\"><strong>jonathandion/awesome-emails</strong></a></li>\n<li><a href=\"https://github.com/petk/awesome-jquery\"><strong>petk/awesome-jquery</strong></a></li>\n<li><a href=\"https://github.com/AllThingsSmitty/jquery-tips-everyone-should-know\"><strong>AllThingsSmitty/jquery-tips-everyone-should-know</strong></a></li>\n<li><a href=\"https://github.com/notthetup/awesome-webaudio\"><strong>notthetup/awesome-webaudio</strong></a></li>\n<li><a href=\"https://github.com/pazguille/offline-first\"><strong>pazguille/offline-first</strong></a></li>\n<li><a href=\"https://github.com/agarrharr/awesome-static-website-services\"><strong>agarrharr/awesome-static-website-services</strong></a></li>\n<li><a href=\"https://github.com/cyclejs-community/awesome-cyclejs\"><strong>cyclejs-community/awesome-cyclejs</strong></a></li>\n<li><a href=\"https://github.com/dok/awesome-text-editing\"><strong>dok/awesome-text-editing</strong></a></li>\n<li><a href=\"https://github.com/fliptheweb/motion-ui-design\"><strong>fliptheweb/motion-ui-design</strong></a></li>\n<li><a href=\"https://github.com/vuejs/awesome-vue\"><strong>vuejs/awesome-vue</strong></a></li>\n<li><a href=\"https://github.com/sadcitizen/awesome-marionette\"><strong>sadcitizen/awesome-marionette</strong></a></li>\n<li><a href=\"https://github.com/aurelia-contrib/awesome-aurelia\"><strong>aurelia-contrib/awesome-aurelia</strong></a></li>\n<li><a href=\"https://github.com/zingchart/awesome-charting\"><strong>zingchart/awesome-charting</strong></a></li>\n<li><a href=\"https://github.com/candelibas/awesome-ionic\"><strong>candelibas/awesome-ionic</strong></a></li>\n<li><a href=\"https://github.com/ChromeDevTools/awesome-chrome-devtools\"><strong>ChromeDevTools/awesome-chrome-devtools</strong></a></li>\n<li><a href=\"https://github.com/jdrgomes/awesome-postcss\"><strong>jdrgomes/awesome-postcss</strong></a></li>\n<li><a href=\"https://github.com/nikgraf/awesome-draft-js\"><strong>nikgraf/awesome-draft-js</strong></a></li>\n<li><a href=\"https://github.com/TalAter/awesome-service-workers\"><strong>TalAter/awesome-service-workers</strong></a></li>\n<li><a href=\"https://github.com/TalAter/awesome-progressive-web-apps\"><strong>TalAter/awesome-progressive-web-apps</strong></a></li>\n<li><a href=\"https://github.com/choojs/awesome-choo\"><strong>choojs/awesome-choo</strong></a></li>\n<li><a href=\"https://github.com/brillout/awesome-redux\"><strong>brillout/awesome-redux</strong></a></li>\n<li><a href=\"https://github.com/webpack-contrib/awesome-webpack\"><strong>webpack-contrib/awesome-webpack</strong></a></li>\n<li><a href=\"https://github.com/browserify/awesome-browserify\"><strong>browserify/awesome-browserify</strong></a></li>\n<li><a href=\"https://github.com/Famolus/awesome-sass\"><strong>Famolus/awesome-sass</strong></a></li>\n<li><a href=\"https://github.com/websemantics/awesome-ant-design\"><strong>websemantics/awesome-ant-design</strong></a></li>\n<li><a href=\"https://github.com/LucasBassetti/awesome-less\"><strong>LucasBassetti/awesome-less</strong></a></li>\n<li><a href=\"https://github.com/sjfricke/awesome-webgl\"><strong>sjfricke/awesome-webgl</strong></a></li>\n<li><a href=\"https://github.com/preactjs/awesome-preact\"><strong>preactjs/awesome-preact</strong></a></li>\n<li><a href=\"https://github.com/jbmoelker/progressive-enhancement-resources\"><strong>jbmoelker/progressive-enhancement-resources</strong></a></li>\n<li><a href=\"https://github.com/unicodeveloper/awesome-nextjs\"><strong>unicodeveloper/awesome-nextjs</strong></a></li>\n<li><a href=\"https://github.com/web-padawan/awesome-lit-html\"><strong>web-padawan/awesome-lit-html</strong></a></li>\n<li><a href=\"https://github.com/automata/awesome-jamstack\"><strong>automata/awesome-jamstack</strong></a></li>\n<li><a href=\"https://github.com/henrikwirth/awesome-wordpress-gatsby\"><strong>henrikwirth/awesome-wordpress-gatsby</strong></a></li>\n<li><a href=\"https://github.com/myshov/awesome-mobile-web-development\"><strong>myshov/awesome-mobile-web-development</strong></a></li>\n<li><a href=\"https://github.com/lauthieb/awesome-storybook\"><strong>lauthieb/awesome-storybook</strong></a></li>\n<li><a href=\"https://github.com/AdrienTorris/awesome-blazor\"><strong>AdrienTorris/awesome-blazor</strong></a></li>\n<li><a href=\"https://github.com/csabapalfi/awesome-pagespeed-metrics\"><strong>csabapalfi/awesome-pagespeed-metrics</strong></a></li>\n<li><a href=\"https://github.com/aniftyco/awesome-tailwindcss\"><strong>aniftyco/awesome-tailwindcss</strong></a></li>\n<li><a href=\"https://github.com/seed-rs/awesome-seed-rs\"><strong>seed-rs/awesome-seed-rs</strong></a></li>\n<li><a href=\"https://github.com/pajaydev/awesome-web-performance-budget\"><strong>pajaydev/awesome-web-performance-budget</strong></a></li>\n<li><a href=\"https://github.com/sergey-pimenov/awesome-web-animation\"><strong>sergey-pimenov/awesome-web-animation</strong></a></li>\n<li><a href=\"https://github.com/jetli/awesome-yew\"><strong>jetli/awesome-yew</strong></a></li>\n<li><a href=\"https://github.com/nadunindunil/awesome-material-ui\"><strong>nadunindunil/awesome-material-ui</strong></a></li>\n<li><a href=\"https://github.com/componently-com/awesome-building-blocks-for-web-apps\"><strong>componently-com/awesome-building-blocks-for-web-apps</strong></a></li>\n<li><a href=\"https://github.com/TheComputerM/awesome-svelte\"><strong>TheComputerM/awesome-svelte</strong></a></li>\n<li><a href=\"https://github.com/klaufel/awesome-design-systems\"><strong>klaufel/awesome-design-systems</strong></a></li>\n<li><a href=\"https://github.com/innocenzi/awesome-inertiajs\"><strong>innocenzi/awesome-inertiajs</strong></a></li>\n<li><a href=\"https://github.com/mdbootstrap/awesome-mdbootstrap\"><strong>mdbootstrap/awesome-mdbootstrap</strong></a></li>\n<li><a href=\"https://github.com/mjhea0/awesome-flask\"><strong>mjhea0/awesome-flask</strong></a></li>\n<li><a href=\"https://github.com/veggiemonk/awesome-docker\"><strong>veggiemonk/awesome-docker</strong></a></li>\n<li><a href=\"https://github.com/iJackUA/awesome-vagrant\"><strong>iJackUA/awesome-vagrant</strong></a></li>\n<li><a href=\"https://github.com/uralbash/awesome-pyramid\"><strong>uralbash/awesome-pyramid</strong></a></li>\n<li><a href=\"https://github.com/PerfectCarl/awesome-play1\"><strong>PerfectCarl/awesome-play1</strong></a></li>\n<li><a href=\"https://github.com/friendsofcake/awesome-cakephp\"><strong>friendsofcake/awesome-cakephp</strong></a></li>\n<li><a href=\"https://github.com/sitepoint-editors/awesome-symfony\"><strong>sitepoint-editors/awesome-symfony</strong></a></li>\n<li><a href=\"https://github.com/pehapkari/awesome-symfony-education\"><strong>pehapkari/awesome-symfony-education</strong></a></li>\n<li><a href=\"https://github.com/chiraggude/awesome-laravel\"><strong>chiraggude/awesome-laravel</strong></a></li>\n<li><a href=\"https://github.com/fukuball/Awesome-Laravel-Education\"><strong>fukuball/Awesome-Laravel-Education</strong></a></li>\n<li><a href=\"https://github.com/blade-ui-kit/awesome-tall-stack\"><strong>blade-ui-kit/awesome-tall-stack</strong></a></li>\n<li><a href=\"https://github.com/gramantin/awesome-rails\"><strong>gramantin/awesome-rails</strong></a></li>\n<li><a href=\"https://github.com/hothero/awesome-rails-gem\"><strong>hothero/awesome-rails-gem</strong></a></li>\n<li><a href=\"https://github.com/phalcon/awesome-phalcon\"><strong>phalcon/awesome-phalcon</strong></a></li>\n<li><a href=\"https://github.com/phanan/htaccess\"><strong>phanan/htaccess</strong></a></li>\n<li><a href=\"https://github.com/fcambus/nginx-resources\"><strong>fcambus/nginx-resources</strong></a></li>\n<li><a href=\"https://github.com/stve/awesome-dropwizard\"><strong>stve/awesome-dropwizard</strong></a></li>\n<li><a href=\"https://github.com/ramitsurana/awesome-kubernetes\"><strong>ramitsurana/awesome-kubernetes</strong></a></li>\n<li><a href=\"https://github.com/unicodeveloper/awesome-lumen\"><strong>unicodeveloper/awesome-lumen</strong></a></li>\n<li><a href=\"https://github.com/pmuens/awesome-serverless\"><strong>pmuens/awesome-serverless</strong></a></li>\n<li><a href=\"https://github.com/PhantomYdn/awesome-wicket\"><strong>PhantomYdn/awesome-wicket</strong></a></li>\n<li><a href=\"https://github.com/vert-x3/vertx-awesome\"><strong>vert-x3/vertx-awesome</strong></a></li>\n<li><a href=\"https://github.com/shuaibiyy/awesome-terraform\"><strong>shuaibiyy/awesome-terraform</strong></a></li>\n<li><a href=\"https://github.com/Cellane/awesome-vapor\"><strong>Cellane/awesome-vapor</strong></a></li>\n<li><a href=\"https://github.com/ucg8j/awesome-dash\"><strong>ucg8j/awesome-dash</strong></a></li>\n<li><a href=\"https://github.com/mjhea0/awesome-fastapi\"><strong>mjhea0/awesome-fastapi</strong></a></li>\n<li><a href=\"https://github.com/kolomied/awesome-cdk\"><strong>kolomied/awesome-cdk</strong></a></li>\n<li><a href=\"https://github.com/kdeldycke/awesome-iam\"><strong>kdeldycke/awesome-iam</strong></a></li>\n<li><a href=\"https://github.com/prakhar1989/awesome-courses\"><strong>prakhar1989/awesome-courses</strong></a></li>\n<li><a href=\"https://github.com/academic/awesome-datascience\"><strong>academic/awesome-datascience</strong></a></li>\n<li><a href=\"https://github.com/siboehm/awesome-learn-datascience\"><strong>siboehm/awesome-learn-datascience</strong></a></li>\n<li><a href=\"https://github.com/josephmisiti/awesome-machine-learning\"><strong>josephmisiti/awesome-machine-learning</strong></a></li>\n<li><a href=\"https://github.com/ujjwalkarn/Machine-Learning-Tutorials\"><strong>ujjwalkarn/Machine-Learning-Tutorials</strong></a></li>\n<li><a href=\"https://github.com/arbox/machine-learning-with-ruby\"><strong>arbox/machine-learning-with-ruby</strong></a></li>\n<li><a href=\"https://github.com/likedan/Awesome-CoreML-Models\"><strong>likedan/Awesome-CoreML-Models</strong></a></li>\n<li><a href=\"https://github.com/h2oai/awesome-h2o\"><strong>h2oai/awesome-h2o</strong></a></li>\n<li><a href=\"https://github.com/SE-ML/awesome-seml\"><strong>SE-ML/awesome-seml</strong></a></li>\n<li><a href=\"https://github.com/georgezouq/awesome-ai-in-finance\"><strong>georgezouq/awesome-ai-in-finance</strong></a></li>\n<li><a href=\"https://github.com/n2cholas/awesome-jax\"><strong>n2cholas/awesome-jax</strong></a></li>\n<li><a href=\"https://github.com/altamiracorp/awesome-xai\"><strong>altamiracorp/awesome-xai</strong></a></li>\n<li><a href=\"https://github.com/edobashira/speech-language-processing\"><strong>edobashira/speech-language-processing</strong></a></li>\n<li><a href=\"https://github.com/dav009/awesome-spanish-nlp\"><strong>dav009/awesome-spanish-nlp</strong></a></li>\n<li><a href=\"https://github.com/arbox/nlp-with-ruby\"><strong>arbox/nlp-with-ruby</strong></a></li>\n<li><a href=\"https://github.com/seriousran/awesome-qa\"><strong>seriousran/awesome-qa</strong></a></li>\n<li><a href=\"https://github.com/tokenmill/awesome-nlg\"><strong>tokenmill/awesome-nlg</strong></a></li>\n<li><a href=\"https://github.com/theimpossibleastronaut/awesome-linguistics\"><strong>theimpossibleastronaut/awesome-linguistics</strong></a></li>\n<li><a href=\"https://github.com/sobolevn/awesome-cryptography\"><strong>sobolevn/awesome-cryptography</strong></a></li>\n<li><a href=\"https://github.com/pFarb/awesome-crypto-papers\"><strong>pFarb/awesome-crypto-papers</strong></a></li>\n<li><a href=\"https://github.com/jbhuang0604/awesome-computer-vision\"><strong>jbhuang0604/awesome-computer-vision</strong></a></li>\n<li><a href=\"https://github.com/ChristosChristofidis/awesome-deep-learning\"><strong>ChristosChristofidis/awesome-deep-learning</strong></a></li>\n<li><a href=\"https://github.com/jtoy/awesome-tensorflow\"><strong>jtoy/awesome-tensorflow</strong></a></li>\n<li><a href=\"https://github.com/aaronhma/awesome-tensorflow-js\"><strong>aaronhma/awesome-tensorflow-js</strong></a></li>\n<li><a href=\"https://github.com/margaretmz/awesome-tensorflow-lite\"><strong>margaretmz/awesome-tensorflow-lite</strong></a></li>\n<li><a href=\"https://github.com/terryum/awesome-deep-learning-papers\"><strong>terryum/awesome-deep-learning-papers</strong></a></li>\n<li><a href=\"https://github.com/guillaume-chevalier/awesome-deep-learning-resources\"><strong>guillaume-chevalier/awesome-deep-learning-resources</strong></a></li>\n<li><a href=\"https://github.com/kjw0612/awesome-deep-vision\"><strong>kjw0612/awesome-deep-vision</strong></a></li>\n<li><a href=\"https://github.com/ossu/computer-science\"><strong>ossu/computer-science</strong></a></li>\n<li><a href=\"https://github.com/lucasviola/awesome-functional-programming\"><strong>lucasviola/awesome-functional-programming</strong></a></li>\n<li><a href=\"https://github.com/dspinellis/awesome-msr\"><strong>dspinellis/awesome-msr</strong></a></li>\n<li><a href=\"https://github.com/analysis-tools-dev/static-analysis\"><strong>analysis-tools-dev/static-analysis</strong></a></li>\n<li><a href=\"https://github.com/harpribot/awesome-information-retrieval\"><strong>harpribot/awesome-information-retrieval</strong></a></li>\n<li><a href=\"https://github.com/desireevl/awesome-quantum-computing\"><strong>desireevl/awesome-quantum-computing</strong></a></li>\n<li><a href=\"https://github.com/mostafatouny/awesome-theoretical-computer-science\"><strong>mostafatouny/awesome-theoretical-computer-science</strong></a></li>\n<li><a href=\"https://github.com/onurakpolat/awesome-bigdata\"><strong>onurakpolat/awesome-bigdata</strong></a></li>\n<li><a href=\"https://github.com/awesomedata/awesome-public-datasets\"><strong>awesomedata/awesome-public-datasets</strong></a></li>\n<li><a href=\"https://github.com/youngwookim/awesome-hadoop\"><strong>youngwookim/awesome-hadoop</strong></a></li>\n<li><a href=\"https://github.com/igorbarinov/awesome-data-engineering\"><strong>igorbarinov/awesome-data-engineering</strong></a></li>\n<li><a href=\"https://github.com/manuzhang/awesome-streaming\"><strong>manuzhang/awesome-streaming</strong></a></li>\n<li><a href=\"https://github.com/awesome-spark/awesome-spark\"><strong>awesome-spark/awesome-spark</strong></a></li>\n<li><a href=\"https://github.com/ambster-public/awesome-qlik\"><strong>ambster-public/awesome-qlik</strong></a></li>\n<li><a href=\"https://github.com/sduff/awesome-splunk\"><strong>sduff/awesome-splunk</strong></a></li>\n<li><a href=\"https://github.com/papers-we-love/papers-we-love\"><strong>papers-we-love/papers-we-love</strong></a></li>\n<li><a href=\"https://github.com/JanVanRyswyck/awesome-talks\"><strong>JanVanRyswyck/awesome-talks</strong></a></li>\n<li><a href=\"https://github.com/tayllan/awesome-algorithms\"><strong>tayllan/awesome-algorithms</strong></a></li>\n<li><a href=\"https://github.com/gaerae/awesome-algorithms-education\"><strong>gaerae/awesome-algorithms-education</strong></a></li>\n<li><a href=\"https://github.com/enjalot/algovis\"><strong>enjalot/algovis</strong></a></li>\n<li><a href=\"https://github.com/owainlewis/awesome-artificial-intelligence\"><strong>owainlewis/awesome-artificial-intelligence</strong></a></li>\n<li><a href=\"https://github.com/marcobiedermann/search-engine-optimization\"><strong>marcobiedermann/search-engine-optimization</strong></a></li>\n<li><a href=\"https://github.com/lnishan/awesome-competitive-programming\"><strong>lnishan/awesome-competitive-programming</strong></a></li>\n<li><a href=\"https://github.com/rossant/awesome-math\"><strong>rossant/awesome-math</strong></a></li>\n<li><a href=\"https://github.com/passy/awesome-recursion-schemes\"><strong>passy/awesome-recursion-schemes</strong></a></li>\n<li><a href=\"https://github.com/EbookFoundation/free-programming-books\"><strong>EbookFoundation/free-programming-books</strong></a></li>\n<li><a href=\"https://github.com/dariubs/GoBooks\"><strong>dariubs/GoBooks</strong></a></li>\n<li><a href=\"https://github.com/RomanTsegelskyi/rbooks\"><strong>RomanTsegelskyi/rbooks</strong></a></li>\n<li><a href=\"https://github.com/hackerkid/Mind-Expanding-Books\"><strong>hackerkid/Mind-Expanding-Books</strong></a></li>\n<li><a href=\"https://github.com/TalAter/awesome-book-authoring\"><strong>TalAter/awesome-book-authoring</strong></a></li>\n<li><a href=\"https://github.com/sger/ElixirBooks\"><strong>sger/ElixirBooks</strong></a></li>\n<li><a href=\"https://github.com/dreikanter/sublime-bookmarks\"><strong>dreikanter/sublime-bookmarks</strong></a></li>\n<li><a href=\"https://github.com/mhinz/vim-galore\"><strong>mhinz/vim-galore</strong></a></li>\n<li><a href=\"https://github.com/emacs-tw/awesome-emacs\"><strong>emacs-tw/awesome-emacs</strong></a></li>\n<li><a href=\"https://github.com/mehcode/awesome-atom\"><strong>mehcode/awesome-atom</strong></a></li>\n<li><a href=\"https://github.com/viatsko/awesome-vscode\"><strong>viatsko/awesome-vscode</strong></a></li>\n<li><a href=\"https://github.com/ellisonleao/magictools\"><strong>ellisonleao/magictools</strong></a></li>\n<li><a href=\"https://github.com/hzoo/awesome-gametalks\"><strong>hzoo/awesome-gametalks</strong></a></li>\n<li><a href=\"https://github.com/godotengine/awesome-godot\"><strong>godotengine/awesome-godot</strong></a></li>\n<li><a href=\"https://github.com/leereilly/games\"><strong>leereilly/games</strong></a></li>\n<li><a href=\"https://github.com/RyanNielson/awesome-unity\"><strong>RyanNielson/awesome-unity</strong></a></li>\n<li><a href=\"https://github.com/hkirat/awesome-chess\"><strong>hkirat/awesome-chess</strong></a></li>\n<li><a href=\"https://github.com/love2d-community/awesome-love2d\"><strong>love2d-community/awesome-love2d</strong></a></li>\n<li><a href=\"https://github.com/pico-8/awesome-PICO-8\"><strong>pico-8/awesome-PICO-8</strong></a></li>\n<li><a href=\"https://github.com/gbdev/awesome-gbdev\"><strong>gbdev/awesome-gbdev</strong></a></li>\n<li><a href=\"https://github.com/WebCreationClub/awesome-construct\"><strong>WebCreationClub/awesome-construct</strong></a></li>\n<li><a href=\"https://github.com/stetso/awesome-gideros\"><strong>stetso/awesome-gideros</strong></a></li>\n<li><a href=\"https://github.com/bs-community/awesome-minecraft\"><strong>bs-community/awesome-minecraft</strong></a></li>\n<li><a href=\"https://github.com/leomaurodesenv/game-datasets\"><strong>leomaurodesenv/game-datasets</strong></a></li>\n<li><a href=\"https://github.com/Dvergar/awesome-haxe-gamedev\"><strong>Dvergar/awesome-haxe-gamedev</strong></a></li>\n<li><a href=\"https://github.com/rafaskb/awesome-libgdx\"><strong>rafaskb/awesome-libgdx</strong></a></li>\n<li><a href=\"https://github.com/playcanvas/awesome-playcanvas\"><strong>playcanvas/awesome-playcanvas</strong></a></li>\n<li><a href=\"https://github.com/radek-sprta/awesome-game-remakes\"><strong>radek-sprta/awesome-game-remakes</strong></a></li>\n<li><a href=\"https://github.com/flame-engine/awesome-flame\"><strong>flame-engine/awesome-flame</strong></a></li>\n<li><a href=\"https://github.com/mhxion/awesome-discord-communities\"><strong>mhxion/awesome-discord-communities</strong></a></li>\n<li><a href=\"https://github.com/tobiasvl/awesome-chip-8\"><strong>tobiasvl/awesome-chip-8</strong></a></li>\n<li><a href=\"https://github.com/michelpereira/awesome-games-of-coding\"><strong>michelpereira/awesome-games-of-coding</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/quick-look-plugins\"><strong>sindresorhus/quick-look-plugins</strong></a></li>\n<li><a href=\"https://github.com/jondot/awesome-devenv\"><strong>jondot/awesome-devenv</strong></a></li>\n<li><a href=\"https://github.com/webpro/awesome-dotfiles\"><strong>webpro/awesome-dotfiles</strong></a></li>\n<li><a href=\"https://github.com/alebcay/awesome-shell\"><strong>alebcay/awesome-shell</strong></a></li>\n<li><a href=\"https://github.com/jorgebucaran/awsm.fish\"><strong>jorgebucaran/awsm.fish</strong></a></li>\n<li><a href=\"https://github.com/agarrharr/awesome-cli-apps\"><strong>agarrharr/awesome-cli-apps</strong></a></li>\n<li><a href=\"https://github.com/unixorn/awesome-zsh-plugins\"><strong>unixorn/awesome-zsh-plugins</strong></a></li>\n<li><a href=\"https://github.com/phillipadsmith/awesome-github\"><strong>phillipadsmith/awesome-github</strong></a></li>\n<li><a href=\"https://github.com/stefanbuck/awesome-browser-extensions-for-github\"><strong>stefanbuck/awesome-browser-extensions-for-github</strong></a></li>\n<li><a href=\"https://github.com/tiimgreen/github-cheat-sheet\"><strong>tiimgreen/github-cheat-sheet</strong></a></li>\n<li><a href=\"https://github.com/matchai/awesome-pinned-gists\"><strong>matchai/awesome-pinned-gists</strong></a></li>\n<li><a href=\"https://github.com/arslanbilal/git-cheat-sheet\"><strong>arslanbilal/git-cheat-sheet</strong></a></li>\n<li><a href=\"https://github.com/git-tips/tips\"><strong>git-tips/tips</strong></a></li>\n<li><a href=\"https://github.com/stevemao/awesome-git-addons\"><strong>stevemao/awesome-git-addons</strong></a></li>\n<li><a href=\"https://github.com/compscilauren/awesome-git-hooks\"><strong>compscilauren/awesome-git-hooks</strong></a></li>\n<li><a href=\"https://github.com/moul/awesome-ssh\"><strong>moul/awesome-ssh</strong></a></li>\n<li><a href=\"https://github.com/tvvocold/FOSS-for-Dev\"><strong>tvvocold/FOSS-for-Dev</strong></a></li>\n<li><a href=\"https://github.com/bnb/awesome-hyper\"><strong>bnb/awesome-hyper</strong></a></li>\n<li><a href=\"https://github.com/janikvonrotz/awesome-powershell\"><strong>janikvonrotz/awesome-powershell</strong></a></li>\n<li><a href=\"https://github.com/alfred-workflows/awesome-alfred-workflows\"><strong>alfred-workflows/awesome-alfred-workflows</strong></a></li>\n<li><a href=\"https://github.com/k4m4/terminals-are-sexy\"><strong>k4m4/terminals-are-sexy</strong></a></li>\n<li><a href=\"https://github.com/sdras/awesome-actions\"><strong>sdras/awesome-actions</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-scifi\"><strong>sindresorhus/awesome-scifi</strong></a></li>\n<li><a href=\"https://github.com/RichardLitt/awesome-fantasy\"><strong>RichardLitt/awesome-fantasy</strong></a></li>\n<li><a href=\"https://github.com/ayr-ton/awesome-geek-podcasts\"><strong>ayr-ton/awesome-geek-podcasts</strong></a></li>\n<li><a href=\"https://github.com/zudochkin/awesome-newsletters\"><strong>zudochkin/awesome-newsletters</strong></a></li>\n<li><a href=\"https://github.com/victorlaerte/awesome-it-quotes\"><strong>victorlaerte/awesome-it-quotes</strong></a></li>\n<li><a href=\"https://github.com/numetriclabz/awesome-db\"><strong>numetriclabz/awesome-db</strong></a></li>\n<li><a href=\"https://github.com/shlomi-noach/awesome-mysql\"><strong>shlomi-noach/awesome-mysql</strong></a></li>\n<li><a href=\"https://github.com/dahlia/awesome-sqlalchemy\"><strong>dahlia/awesome-sqlalchemy</strong></a></li>\n<li><a href=\"https://github.com/mark-rushakoff/awesome-influxdb\"><strong>mark-rushakoff/awesome-influxdb</strong></a></li>\n<li><a href=\"https://github.com/neueda/awesome-neo4j\"><strong>neueda/awesome-neo4j</strong></a></li>\n<li><a href=\"https://github.com/ramnes/awesome-mongodb\"><strong>ramnes/awesome-mongodb</strong></a></li>\n<li><a href=\"https://github.com/d3viant0ne/awesome-rethinkdb\"><strong>d3viant0ne/awesome-rethinkdb</strong></a></li>\n<li><a href=\"https://github.com/mohataher/awesome-tinkerpop\"><strong>mohataher/awesome-tinkerpop</strong></a></li>\n<li><a href=\"https://github.com/dhamaniasad/awesome-postgres\"><strong>dhamaniasad/awesome-postgres</strong></a></li>\n<li><a href=\"https://github.com/quangv/awesome-couchdb\"><strong>quangv/awesome-couchdb</strong></a></li>\n<li><a href=\"https://github.com/rayokota/awesome-hbase\"><strong>rayokota/awesome-hbase</strong></a></li>\n<li><a href=\"https://github.com/erictleung/awesome-nosql-guides\"><strong>erictleung/awesome-nosql-guides</strong></a></li>\n<li><a href=\"https://github.com/chrislatorres/awesome-contexture\"><strong>chrislatorres/awesome-contexture</strong></a></li>\n<li><a href=\"https://github.com/mgramin/awesome-db-tools\"><strong>mgramin/awesome-db-tools</strong></a></li>\n<li><a href=\"https://github.com/vaticle/typedb-awesome\"><strong>vaticle/typedb-awesome</strong></a></li>\n<li><a href=\"https://github.com/Anant/awesome-cassandra\"><strong>Anant/awesome-cassandra</strong></a></li>\n<li><a href=\"https://github.com/shime/creative-commons-media\"><strong>shime/creative-commons-media</strong></a></li>\n<li><a href=\"https://github.com/brabadu/awesome-fonts\"><strong>brabadu/awesome-fonts</strong></a></li>\n<li><a href=\"https://github.com/chrissimpkins/codeface\"><strong>chrissimpkins/codeface</strong></a></li>\n<li><a href=\"https://github.com/neutraltone/awesome-stock-resources\"><strong>neutraltone/awesome-stock-resources</strong></a></li>\n<li><a href=\"https://github.com/davisonio/awesome-gif\"><strong>davisonio/awesome-gif</strong></a></li>\n<li><a href=\"https://github.com/ciconia/awesome-music\"><strong>ciconia/awesome-music</strong></a></li>\n<li><a href=\"https://github.com/44bits/awesome-opensource-documents\"><strong>44bits/awesome-opensource-documents</strong></a></li>\n<li><a href=\"https://github.com/willianjusten/awesome-audio-visualization\"><strong>willianjusten/awesome-audio-visualization</strong></a></li>\n<li><a href=\"https://github.com/ebu/awesome-broadcasting\"><strong>ebu/awesome-broadcasting</strong></a></li>\n<li><a href=\"https://github.com/Siilwyn/awesome-pixel-art\"><strong>Siilwyn/awesome-pixel-art</strong></a></li>\n<li><a href=\"https://github.com/transitive-bullshit/awesome-ffmpeg\"><strong>transitive-bullshit/awesome-ffmpeg</strong></a></li>\n<li><a href=\"https://github.com/notlmn/awesome-icons\"><strong>notlmn/awesome-icons</strong></a></li>\n<li><a href=\"https://github.com/stingalleman/awesome-audiovisual\"><strong>stingalleman/awesome-audiovisual</strong></a></li>\n<li><a href=\"https://github.com/mfkl/awesome-vlc\"><strong>mfkl/awesome-vlc</strong></a></li>\n<li><a href=\"https://github.com/therebelrobot/awesome-workshopper\"><strong>therebelrobot/awesome-workshopper</strong></a></li>\n<li><a href=\"https://github.com/karlhorky/learn-to-program\"><strong>karlhorky/learn-to-program</strong></a></li>\n<li><a href=\"https://github.com/matteofigus/awesome-speaking\"><strong>matteofigus/awesome-speaking</strong></a></li>\n<li><a href=\"https://github.com/lucasviola/awesome-tech-videos\"><strong>lucasviola/awesome-tech-videos</strong></a></li>\n<li><a href=\"https://github.com/hangtwenty/dive-into-machine-learning\"><strong>hangtwenty/dive-into-machine-learning</strong></a></li>\n<li><a href=\"https://github.com/watson/awesome-computer-history\"><strong>watson/awesome-computer-history</strong></a></li>\n<li><a href=\"https://github.com/HollyAdele/awesome-programming-for-kids\"><strong>HollyAdele/awesome-programming-for-kids</strong></a></li>\n<li><a href=\"https://github.com/yrgo/awesome-educational-games\"><strong>yrgo/awesome-educational-games</strong></a></li>\n<li><a href=\"https://github.com/micromata/awesome-javascript-learning\"><strong>micromata/awesome-javascript-learning</strong></a></li>\n<li><a href=\"https://github.com/micromata/awesome-css-learning\"><strong>micromata/awesome-css-learning</strong></a></li>\n<li><a href=\"https://github.com/dend/awesome-product-management\"><strong>dend/awesome-product-management</strong></a></li>\n<li><a href=\"https://github.com/liuchong/awesome-roadmaps\"><strong>liuchong/awesome-roadmaps</strong></a></li>\n<li><a href=\"https://github.com/JoseDeFreitas/awesome-youtubers\"><strong>JoseDeFreitas/awesome-youtubers</strong></a></li>\n<li><a href=\"https://github.com/paragonie/awesome-appsec\"><strong>paragonie/awesome-appsec</strong></a></li>\n<li><a href=\"https://github.com/sbilly/awesome-security\"><strong>sbilly/awesome-security</strong></a></li>\n<li><a href=\"https://github.com/apsdehal/awesome-ctf\"><strong>apsdehal/awesome-ctf</strong></a></li>\n<li><a href=\"https://github.com/rshipp/awesome-malware-analysis\"><strong>rshipp/awesome-malware-analysis</strong></a></li>\n<li><a href=\"https://github.com/ashishb/android-security-awesome\"><strong>ashishb/android-security-awesome</strong></a></li>\n<li><a href=\"https://github.com/carpedm20/awesome-hacking\"><strong>carpedm20/awesome-hacking</strong></a></li>\n<li><a href=\"https://github.com/paralax/awesome-honeypots\"><strong>paralax/awesome-honeypots</strong></a></li>\n<li><a href=\"https://github.com/meirwah/awesome-incident-response\"><strong>meirwah/awesome-incident-response</strong></a></li>\n<li><a href=\"https://github.com/jaredthecoder/awesome-vehicle-security\"><strong>jaredthecoder/awesome-vehicle-security</strong></a></li>\n<li><a href=\"https://github.com/qazbnm456/awesome-web-security\"><strong>qazbnm456/awesome-web-security</strong></a></li>\n<li><a href=\"https://github.com/fabacab/awesome-lockpicking\"><strong>fabacab/awesome-lockpicking</strong></a></li>\n<li><a href=\"https://github.com/fabacab/awesome-cybersecurity-blueteam\"><strong>fabacab/awesome-cybersecurity-blueteam</strong></a></li>\n<li><a href=\"https://github.com/cpuu/awesome-fuzzing\"><strong>cpuu/awesome-fuzzing</strong></a></li>\n<li><a href=\"https://github.com/fkie-cad/awesome-embedded-and-iot-security\"><strong>fkie-cad/awesome-embedded-and-iot-security</strong></a></li>\n<li><a href=\"https://github.com/bakke92/awesome-gdpr\"><strong>bakke92/awesome-gdpr</strong></a></li>\n<li><a href=\"https://github.com/TaptuIT/awesome-devsecops\"><strong>TaptuIT/awesome-devsecops</strong></a></li>\n<li><a href=\"https://github.com/umbraco-community/awesome-umbraco\"><strong>umbraco-community/awesome-umbraco</strong></a></li>\n<li><a href=\"https://github.com/refinerycms-contrib/awesome-refinerycms\"><strong>refinerycms-contrib/awesome-refinerycms</strong></a></li>\n<li><a href=\"https://github.com/springload/awesome-wagtail\"><strong>springload/awesome-wagtail</strong></a></li>\n<li><a href=\"https://github.com/drmonkeyninja/awesome-textpattern\"><strong>drmonkeyninja/awesome-textpattern</strong></a></li>\n<li><a href=\"https://github.com/nirgn975/awesome-drupal\"><strong>nirgn975/awesome-drupal</strong></a></li>\n<li><a href=\"https://github.com/craftcms/awesome\"><strong>craftcms/awesome</strong></a></li>\n<li><a href=\"https://github.com/MartinMiles/Awesome-Sitecore\"><strong>MartinMiles/Awesome-Sitecore</strong></a></li>\n<li><a href=\"https://github.com/wernerkrauss/awesome-silverstripe-cms\"><strong>wernerkrauss/awesome-silverstripe-cms</strong></a></li>\n<li><a href=\"https://github.com/Kiloreux/awesome-robotics\"><strong>Kiloreux/awesome-robotics</strong></a></li>\n<li><a href=\"https://github.com/HQarroum/awesome-iot\"><strong>HQarroum/awesome-iot</strong></a></li>\n<li><a href=\"https://github.com/kitspace/awesome-electronics\"><strong>kitspace/awesome-electronics</strong></a></li>\n<li><a href=\"https://github.com/rabschi/awesome-beacon\"><strong>rabschi/awesome-beacon</strong></a></li>\n<li><a href=\"https://github.com/gitfrage/guitarspecs\"><strong>gitfrage/guitarspecs</strong></a></li>\n<li><a href=\"https://github.com/beardicus/awesome-plotters\"><strong>beardicus/awesome-plotters</strong></a></li>\n<li><a href=\"https://github.com/protontypes/awesome-robotic-tooling\"><strong>protontypes/awesome-robotic-tooling</strong></a></li>\n<li><a href=\"https://github.com/szenergy/awesome-lidar\"><strong>szenergy/awesome-lidar</strong></a></li>\n<li><a href=\"https://github.com/opencompany/awesome-open-company\"><strong>opencompany/awesome-open-company</strong></a></li>\n<li><a href=\"https://github.com/mmccaff/PlacesToPostYourStartup\"><strong>mmccaff/PlacesToPostYourStartup</strong></a></li>\n<li><a href=\"https://github.com/domenicosolazzo/awesome-okr\"><strong>domenicosolazzo/awesome-okr</strong></a></li>\n<li><a href=\"https://github.com/LappleApple/awesome-leading-and-managing\"><strong>LappleApple/awesome-leading-and-managing</strong></a></li>\n<li><a href=\"https://github.com/mezod/awesome-indie\"><strong>mezod/awesome-indie</strong></a></li>\n<li><a href=\"https://github.com/cjbarber/ToolsOfTheTrade\"><strong>cjbarber/ToolsOfTheTrade</strong></a></li>\n<li><a href=\"https://github.com/nglgzz/awesome-clean-tech\"><strong>nglgzz/awesome-clean-tech</strong></a></li>\n<li><a href=\"https://github.com/wardley-maps-community/awesome-wardley-maps\"><strong>wardley-maps-community/awesome-wardley-maps</strong></a></li>\n<li><a href=\"https://github.com/RayBB/awesome-social-enterprise\"><strong>RayBB/awesome-social-enterprise</strong></a></li>\n<li><a href=\"https://github.com/kdeldycke/awesome-engineering-team-management\"><strong>kdeldycke/awesome-engineering-team-management</strong></a></li>\n<li><a href=\"https://github.com/agamm/awesome-developer-first\"><strong>agamm/awesome-developer-first</strong></a></li>\n<li><a href=\"https://github.com/kdeldycke/awesome-billing\"><strong>kdeldycke/awesome-billing</strong></a></li>\n<li><a href=\"https://github.com/matiassingers/awesome-slack\"><strong>matiassingers/awesome-slack</strong></a></li>\n<li><a href=\"https://github.com/filipelinhares/awesome-slack\"><strong>filipelinhares/awesome-slack</strong></a></li>\n<li><a href=\"https://github.com/lukasz-madon/awesome-remote-job\"><strong>lukasz-madon/awesome-remote-job</strong></a></li>\n<li><a href=\"https://github.com/jyguyomarch/awesome-productivity\"><strong>jyguyomarch/awesome-productivity</strong></a></li>\n<li><a href=\"https://github.com/tramcar/awesome-job-boards\"><strong>tramcar/awesome-job-boards</strong></a></li>\n<li><a href=\"https://github.com/DopplerHQ/awesome-interview-questions\"><strong>DopplerHQ/awesome-interview-questions</strong></a></li>\n<li><a href=\"https://github.com/joho/awesome-code-review\"><strong>joho/awesome-code-review</strong></a></li>\n<li><a href=\"https://github.com/j0hnm4r5/awesome-creative-technology\"><strong>j0hnm4r5/awesome-creative-technology</strong></a></li>\n<li><a href=\"https://github.com/lodthe/awesome-internships\"><strong>lodthe/awesome-internships</strong></a></li>\n<li><a href=\"https://github.com/sdnds-tw/awesome-sdn\"><strong>sdnds-tw/awesome-sdn</strong></a></li>\n<li><a href=\"https://github.com/briatte/awesome-network-analysis\"><strong>briatte/awesome-network-analysis</strong></a></li>\n<li><a href=\"https://github.com/caesar0301/awesome-pcaptools\"><strong>caesar0301/awesome-pcaptools</strong></a></li>\n<li><a href=\"https://github.com/rtckit/awesome-rtc\"><strong>rtckit/awesome-rtc</strong></a></li>\n<li><a href=\"https://github.com/igorbarinov/awesome-bitcoin\"><strong>igorbarinov/awesome-bitcoin</strong></a></li>\n<li><a href=\"https://github.com/vhpoet/awesome-ripple\"><strong>vhpoet/awesome-ripple</strong></a></li>\n<li><a href=\"https://github.com/machinomy/awesome-non-financial-blockchain\"><strong>machinomy/awesome-non-financial-blockchain</strong></a></li>\n<li><a href=\"https://github.com/tleb/awesome-mastodon\"><strong>tleb/awesome-mastodon</strong></a></li>\n<li><a href=\"https://github.com/ttumiel/Awesome-Ethereum\"><strong>ttumiel/Awesome-Ethereum</strong></a></li>\n<li><a href=\"https://github.com/steven2358/awesome-blockchain-ai\"><strong>steven2358/awesome-blockchain-ai</strong></a></li>\n<li><a href=\"https://github.com/DanailMinchev/awesome-eosio\"><strong>DanailMinchev/awesome-eosio</strong></a></li>\n<li><a href=\"https://github.com/chainstack/awesome-corda\"><strong>chainstack/awesome-corda</strong></a></li>\n<li><a href=\"https://github.com/msmolyakov/awesome-waves\"><strong>msmolyakov/awesome-waves</strong></a></li>\n<li><a href=\"https://github.com/substrate-developer-hub/awesome-substrate\"><strong>substrate-developer-hub/awesome-substrate</strong></a></li>\n<li><a href=\"https://github.com/golemfactory/awesome-golem\"><strong>golemfactory/awesome-golem</strong></a></li>\n<li><a href=\"https://github.com/friedger/awesome-stacks-chain\"><strong>friedger/awesome-stacks-chain</strong></a></li>\n<li><a href=\"https://github.com/eselkin/awesome-computational-neuroscience\"><strong>eselkin/awesome-computational-neuroscience</strong></a></li>\n<li><a href=\"https://github.com/maehr/awesome-digital-history\"><strong>maehr/awesome-digital-history</strong></a></li>\n<li><a href=\"https://github.com/writing-resources/awesome-scientific-writing\"><strong>writing-resources/awesome-scientific-writing</strong></a></li>\n<li><a href=\"https://github.com/danvoyce/awesome-creative-tech-events\"><strong>danvoyce/awesome-creative-tech-events</strong></a></li>\n<li><a href=\"https://github.com/ildoc/awesome-italy-events\"><strong>ildoc/awesome-italy-events</strong></a></li>\n<li><a href=\"https://github.com/awkward/awesome-netherlands-events\"><strong>awkward/awesome-netherlands-events</strong></a></li>\n<li><a href=\"https://github.com/TheJambo/awesome-testing\"><strong>TheJambo/awesome-testing</strong></a></li>\n<li><a href=\"https://github.com/mojoaxel/awesome-regression-testing\"><strong>mojoaxel/awesome-regression-testing</strong></a></li>\n<li><a href=\"https://github.com/christian-bromann/awesome-selenium\"><strong>christian-bromann/awesome-selenium</strong></a></li>\n<li><a href=\"https://github.com/SrinivasanTarget/awesome-appium\"><strong>SrinivasanTarget/awesome-appium</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-tap\"><strong>sindresorhus/awesome-tap</strong></a></li>\n<li><a href=\"https://github.com/aliesbelik/awesome-jmeter\"><strong>aliesbelik/awesome-jmeter</strong></a></li>\n<li><a href=\"https://github.com/k6io/awesome-k6\"><strong>k6io/awesome-k6</strong></a></li>\n<li><a href=\"https://github.com/mxschmitt/awesome-playwright\"><strong>mxschmitt/awesome-playwright</strong></a></li>\n<li><a href=\"https://github.com/fityanos/awesome-quality-assurance-roadmap\"><strong>fityanos/awesome-quality-assurance-roadmap</strong></a></li>\n<li><a href=\"https://github.com/burningtree/awesome-json\"><strong>burningtree/awesome-json</strong></a></li>\n<li><a href=\"https://github.com/tmcw/awesome-geojson\"><strong>tmcw/awesome-geojson</strong></a></li>\n<li><a href=\"https://github.com/jdorfman/awesome-json-datasets\"><strong>jdorfman/awesome-json-datasets</strong></a></li>\n<li><a href=\"https://github.com/secretGeek/awesomeCSV\"><strong>secretGeek/awesomeCSV</strong></a></li>\n<li><a href=\"https://github.com/AchoArnold/discount-for-student-dev\"><strong>AchoArnold/discount-for-student-dev</strong></a></li>\n<li><a href=\"https://github.com/kyleterry/awesome-radio\"><strong>kyleterry/awesome-radio</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome\"><strong>sindresorhus/awesome</strong></a></li>\n<li><a href=\"https://github.com/onurakpolat/awesome-analytics\"><strong>onurakpolat/awesome-analytics</strong></a></li>\n<li><a href=\"https://github.com/marmelab/awesome-rest\"><strong>marmelab/awesome-rest</strong></a></li>\n<li><a href=\"https://github.com/cicdops/awesome-ciandcd\"><strong>cicdops/awesome-ciandcd</strong></a></li>\n<li><a href=\"https://github.com/mmcgrana/services-engineering\"><strong>mmcgrana/services-engineering</strong></a></li>\n<li><a href=\"https://github.com/ripienaar/free-for-dev\"><strong>ripienaar/free-for-dev</strong></a></li>\n<li><a href=\"https://github.com/cyberglot/awesome-answers\"><strong>cyberglot/awesome-answers</strong></a></li>\n<li><a href=\"https://github.com/diessica/awesome-sketch\"><strong>diessica/awesome-sketch</strong></a></li>\n<li><a href=\"https://github.com/melvin0008/awesome-projects-boilerplates\"><strong>melvin0008/awesome-projects-boilerplates</strong></a></li>\n<li><a href=\"https://github.com/matiassingers/awesome-readme\"><strong>matiassingers/awesome-readme</strong></a></li>\n<li><a href=\"https://github.com/NARKOZ/guides\"><strong>NARKOZ/guides</strong></a></li>\n<li><a href=\"https://github.com/kilimchoi/engineering-blogs\"><strong>kilimchoi/engineering-blogs</strong></a></li>\n<li><a href=\"https://github.com/awesome-selfhosted/awesome-selfhosted\"><strong>awesome-selfhosted/awesome-selfhosted</strong></a></li>\n<li><a href=\"https://github.com/DataDaoDe/awesome-foss-apps\"><strong>DataDaoDe/awesome-foss-apps</strong></a></li>\n<li><a href=\"https://github.com/alferov/awesome-gulp\"><strong>alferov/awesome-gulp</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/amas\"><strong>sindresorhus/amas</strong></a></li>\n<li><a href=\"https://github.com/stoeffel/awesome-ama-answers\"><strong>stoeffel/awesome-ama-answers</strong></a></li>\n<li><a href=\"https://github.com/ibaaj/awesome-OpenSourcePhotography\"><strong>ibaaj/awesome-OpenSourcePhotography</strong></a></li>\n<li><a href=\"https://github.com/eug/awesome-opengl\"><strong>eug/awesome-opengl</strong></a></li>\n<li><a href=\"https://github.com/chentsulin/awesome-graphql\"><strong>chentsulin/awesome-graphql</strong></a></li>\n<li><a href=\"https://github.com/APA-Technology-Division/urban-and-regional-planning-resources\"><strong>APA-Technology-Division/urban-and-regional-planning-resources</strong></a></li>\n<li><a href=\"https://github.com/CUTR-at-USF/awesome-transit\"><strong>CUTR-at-USF/awesome-transit</strong></a></li>\n<li><a href=\"https://github.com/emptymalei/awesome-research\"><strong>emptymalei/awesome-research</strong></a></li>\n<li><a href=\"https://github.com/fasouto/awesome-dataviz\"><strong>fasouto/awesome-dataviz</strong></a></li>\n<li><a href=\"https://github.com/vinkla/shareable-links\"><strong>vinkla/shareable-links</strong></a></li>\n<li><a href=\"https://github.com/mfornos/awesome-microservices\"><strong>mfornos/awesome-microservices</strong></a></li>\n<li><a href=\"https://github.com/jagracey/Awesome-Unicode\"><strong>jagracey/Awesome-Unicode</strong></a></li>\n<li><a href=\"https://github.com/Codepoints/awesome-codepoints\"><strong>Codepoints/awesome-codepoints</strong></a></li>\n<li><a href=\"https://github.com/MunGell/awesome-for-beginners\"><strong>MunGell/awesome-for-beginners</strong></a></li>\n<li><a href=\"https://github.com/gamontal/awesome-katas\"><strong>gamontal/awesome-katas</strong></a></li>\n<li><a href=\"https://github.com/drewrwilson/toolsforactivism\"><strong>drewrwilson/toolsforactivism</strong></a></li>\n<li><a href=\"https://github.com/dylanrees/citizen-science\"><strong>dylanrees/citizen-science</strong></a></li>\n<li><a href=\"https://github.com/hobbyquaker/awesome-mqtt\"><strong>hobbyquaker/awesome-mqtt</strong></a></li>\n<li><a href=\"https://github.com/daviddias/awesome-hacking-locations\"><strong>daviddias/awesome-hacking-locations</strong></a></li>\n<li><a href=\"https://github.com/cristianoliveira/awesome4girls\"><strong>cristianoliveira/awesome4girls</strong></a></li>\n<li><a href=\"https://github.com/vorpaljs/awesome-vorpal\"><strong>vorpaljs/awesome-vorpal</strong></a></li>\n<li><a href=\"https://github.com/vinjn/awesome-vulkan\"><strong>vinjn/awesome-vulkan</strong></a></li>\n<li><a href=\"https://github.com/egeerardyn/awesome-LaTeX\"><strong>egeerardyn/awesome-LaTeX</strong></a></li>\n<li><a href=\"https://github.com/antontarasenko/awesome-economics\"><strong>antontarasenko/awesome-economics</strong></a></li>\n<li><a href=\"https://github.com/sublimino/awesome-funny-markov\"><strong>sublimino/awesome-funny-markov</strong></a></li>\n<li><a href=\"https://github.com/danielecook/Awesome-Bioinformatics\"><strong>danielecook/Awesome-Bioinformatics</strong></a></li>\n<li><a href=\"https://github.com/hsiaoyi0504/awesome-cheminformatics\"><strong>hsiaoyi0504/awesome-cheminformatics</strong></a></li>\n<li><a href=\"https://github.com/Siddharth11/Colorful\"><strong>Siddharth11/Colorful</strong></a></li>\n<li><a href=\"https://github.com/scholtzm/awesome-steam\"><strong>scholtzm/awesome-steam</strong></a></li>\n<li><a href=\"https://github.com/hackerkid/bots\"><strong>hackerkid/bots</strong></a></li>\n<li><a href=\"https://github.com/dastergon/awesome-sre\"><strong>dastergon/awesome-sre</strong></a></li>\n<li><a href=\"https://github.com/KimberlyMunoz/empathy-in-engineering\"><strong>KimberlyMunoz/empathy-in-engineering</strong></a></li>\n<li><a href=\"https://github.com/xen0l/awesome-dtrace\"><strong>xen0l/awesome-dtrace</strong></a></li>\n<li><a href=\"https://github.com/bvolpato/awesome-userscripts\"><strong>bvolpato/awesome-userscripts</strong></a></li>\n<li><a href=\"https://github.com/tobiasbueschel/awesome-pokemon\"><strong>tobiasbueschel/awesome-pokemon</strong></a></li>\n<li><a href=\"https://github.com/exAspArk/awesome-chatops\"><strong>exAspArk/awesome-chatops</strong></a></li>\n<li><a href=\"https://github.com/kdeldycke/awesome-falsehood\"><strong>kdeldycke/awesome-falsehood</strong></a></li>\n<li><a href=\"https://github.com/heynickc/awesome-ddd\"><strong>heynickc/awesome-ddd</strong></a></li>\n<li><a href=\"https://github.com/woop/awesome-quantified-self\"><strong>woop/awesome-quantified-self</strong></a></li>\n<li><a href=\"https://github.com/hbokh/awesome-saltstack\"><strong>hbokh/awesome-saltstack</strong></a></li>\n<li><a href=\"https://github.com/nicolesaidy/awesome-web-design\"><strong>nicolesaidy/awesome-web-design</strong></a></li>\n<li><a href=\"https://github.com/terkelg/awesome-creative-coding\"><strong>terkelg/awesome-creative-coding</strong></a></li>\n<li><a href=\"https://github.com/aviaryan/awesome-no-login-web-apps\"><strong>aviaryan/awesome-no-login-web-apps</strong></a></li>\n<li><a href=\"https://github.com/johnjago/awesome-free-software\"><strong>johnjago/awesome-free-software</strong></a></li>\n<li><a href=\"https://github.com/podo/awesome-framer\"><strong>podo/awesome-framer</strong></a></li>\n<li><a href=\"https://github.com/BubuAnabelas/awesome-markdown\"><strong>BubuAnabelas/awesome-markdown</strong></a></li>\n<li><a href=\"https://github.com/mislavcimpersak/awesome-dev-fun\"><strong>mislavcimpersak/awesome-dev-fun</strong></a></li>\n<li><a href=\"https://github.com/kakoni/awesome-healthcare\"><strong>kakoni/awesome-healthcare</strong></a></li>\n<li><a href=\"https://github.com/DavidLambauer/awesome-magento2\"><strong>DavidLambauer/awesome-magento2</strong></a></li>\n<li><a href=\"https://github.com/xiaohanyu/awesome-tikz\"><strong>xiaohanyu/awesome-tikz</strong></a></li>\n<li><a href=\"https://github.com/analyticalmonk/awesome-neuroscience\"><strong>analyticalmonk/awesome-neuroscience</strong></a></li>\n<li><a href=\"https://github.com/johnjago/awesome-ad-free\"><strong>johnjago/awesome-ad-free</strong></a></li>\n<li><a href=\"https://github.com/angrykoala/awesome-esolangs\"><strong>angrykoala/awesome-esolangs</strong></a></li>\n<li><a href=\"https://github.com/roaldnefs/awesome-prometheus\"><strong>roaldnefs/awesome-prometheus</strong></a></li>\n<li><a href=\"https://github.com/homematic-community/awesome-homematic\"><strong>homematic-community/awesome-homematic</strong></a></li>\n<li><a href=\"https://github.com/sfischer13/awesome-ledger\"><strong>sfischer13/awesome-ledger</strong></a></li>\n<li><a href=\"https://github.com/thomasbnt/awesome-web-monetization\"><strong>thomasbnt/awesome-web-monetization</strong></a></li>\n<li><a href=\"https://github.com/johnjago/awesome-uncopyright\"><strong>johnjago/awesome-uncopyright</strong></a></li>\n<li><a href=\"https://github.com/Zheaoli/awesome-coins\"><strong>Zheaoli/awesome-coins</strong></a></li>\n<li><a href=\"https://github.com/folkswhocode/awesome-diversity\"><strong>folkswhocode/awesome-diversity</strong></a></li>\n<li><a href=\"https://github.com/zachflower/awesome-open-source-supporters\"><strong>zachflower/awesome-open-source-supporters</strong></a></li>\n<li><a href=\"https://github.com/robinstickel/awesome-design-principles\"><strong>robinstickel/awesome-design-principles</strong></a></li>\n<li><a href=\"https://github.com/johnjago/awesome-theravada\"><strong>johnjago/awesome-theravada</strong></a></li>\n<li><a href=\"https://github.com/inspectit-labs/awesome-inspectit\"><strong>inspectit-labs/awesome-inspectit</strong></a></li>\n<li><a href=\"https://github.com/nayafia/awesome-maintainers\"><strong>nayafia/awesome-maintainers</strong></a></li>\n<li><a href=\"https://github.com/xxczaki/awesome-calculators\"><strong>xxczaki/awesome-calculators</strong></a></li>\n<li><a href=\"https://github.com/ZYSzys/awesome-captcha\"><strong>ZYSzys/awesome-captcha</strong></a></li>\n<li><a href=\"https://github.com/markusschanta/awesome-jupyter\"><strong>markusschanta/awesome-jupyter</strong></a></li>\n<li><a href=\"https://github.com/andrewda/awesome-frc\"><strong>andrewda/awesome-frc</strong></a></li>\n<li><a href=\"https://github.com/humanetech-community/awesome-humane-tech\"><strong>humanetech-community/awesome-humane-tech</strong></a></li>\n<li><a href=\"https://github.com/karlhorky/awesome-speakers\"><strong>karlhorky/awesome-speakers</strong></a></li>\n<li><a href=\"https://github.com/edm00se/awesome-board-games\"><strong>edm00se/awesome-board-games</strong></a></li>\n<li><a href=\"https://github.com/uraimo/awesome-software-patreons\"><strong>uraimo/awesome-software-patreons</strong></a></li>\n<li><a href=\"https://github.com/ecohealthalliance/awesome-parasite\"><strong>ecohealthalliance/awesome-parasite</strong></a></li>\n<li><a href=\"https://github.com/jzarca01/awesome-food\"><strong>jzarca01/awesome-food</strong></a></li>\n<li><a href=\"https://github.com/dreamingechoes/awesome-mental-health\"><strong>dreamingechoes/awesome-mental-health</strong></a></li>\n<li><a href=\"https://github.com/alexk111/awesome-bitcoin-payment-processors\"><strong>alexk111/awesome-bitcoin-payment-processors</strong></a></li>\n<li><a href=\"https://github.com/nschloe/awesome-scientific-computing\"><strong>nschloe/awesome-scientific-computing</strong></a></li>\n<li><a href=\"https://github.com/ScaleLeap/awesome-amazon-seller\"><strong>ScaleLeap/awesome-amazon-seller</strong></a></li>\n<li><a href=\"https://github.com/brycejohnston/awesome-agriculture\"><strong>brycejohnston/awesome-agriculture</strong></a></li>\n<li><a href=\"https://github.com/matttga/awesome-product-design\"><strong>matttga/awesome-product-design</strong></a></li>\n<li><a href=\"https://github.com/catalinmiron/awesome-prisma\"><strong>catalinmiron/awesome-prisma</strong></a></li>\n<li><a href=\"https://github.com/simskij/awesome-software-architecture\"><strong>simskij/awesome-software-architecture</strong></a></li>\n<li><a href=\"https://github.com/stevesong/awesome-connectivity-info\"><strong>stevesong/awesome-connectivity-info</strong></a></li>\n<li><a href=\"https://github.com/stackshareio/awesome-stacks\"><strong>stackshareio/awesome-stacks</strong></a></li>\n<li><a href=\"https://github.com/cytodata/awesome-cytodata\"><strong>cytodata/awesome-cytodata</strong></a></li>\n<li><a href=\"https://github.com/davisonio/awesome-irc\"><strong>davisonio/awesome-irc</strong></a></li>\n<li><a href=\"https://github.com/cenoura/awesome-ads\"><strong>cenoura/awesome-ads</strong></a></li>\n<li><a href=\"https://github.com/philsturgeon/awesome-earth\"><strong>philsturgeon/awesome-earth</strong></a></li>\n<li><a href=\"https://github.com/gruhn/awesome-naming\"><strong>gruhn/awesome-naming</strong></a></li>\n<li><a href=\"https://github.com/caufieldjh/awesome-bioie\"><strong>caufieldjh/awesome-bioie</strong></a></li>\n<li><a href=\"https://github.com/iipc/awesome-web-archiving\"><strong>iipc/awesome-web-archiving</strong></a></li>\n<li><a href=\"https://github.com/schlessera/awesome-wp-cli\"><strong>schlessera/awesome-wp-cli</strong></a></li>\n<li><a href=\"https://github.com/mourarthur/awesome-credit-modeling\"><strong>mourarthur/awesome-credit-modeling</strong></a></li>\n<li><a href=\"https://github.com/KeyboardInterrupt/awesome-ansible\"><strong>KeyboardInterrupt/awesome-ansible</strong></a></li>\n<li><a href=\"https://github.com/keller-mark/awesome-biological-visualizations\"><strong>keller-mark/awesome-biological-visualizations</strong></a></li>\n<li><a href=\"https://github.com/aureooms/awesome-qr-code\"><strong>aureooms/awesome-qr-code</strong></a></li>\n<li><a href=\"https://github.com/sdassow/awesome-veganism\"><strong>sdassow/awesome-veganism</strong></a></li>\n<li><a href=\"https://github.com/mbiesiad/awesome-translations\"><strong>mbiesiad/awesome-translations</strong></a></li>\n<li><a href=\"https://github.com/dersvenhesse/awesome-scriptable\"><strong>dersvenhesse/awesome-scriptable</strong></a></li>\n<li><a href=\"https://github.com/topics/awesome\"><strong>topics/awesome</strong></a></li>\n<li><a href=\"https://awesome-indexed.mathew-davies.co.uk\"><strong>https://awesome-indexed.mathew-davies.co.uk</strong></a></li>\n<li><a href=\"https://awesomelists.top\"><strong>https://awesomelists.top</strong></a></li>\n<li><a href=\"https://github.com/basharovV/StumbleUponAwesome\"><strong>basharovV/StumbleUponAwesome</strong></a></li>\n<li><a href=\"https://github.com/umutphp/awesome-cli\"><strong>umutphp/awesome-cli</strong></a></li>\n<li><a href=\"http://awesome.digitalbunker.dev\"><strong>http://awesome.digitalbunker.dev</strong></a></li>\n<li><a href=\"https://www.trackawesomelist.com\"><strong>https://www.trackawesomelist.com</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-nodejs\"><strong>sindresorhus/awesome-nodejs</strong></a></li>\n<li><a href=\"https://github.com/bcoe/awesome-cross-platform-nodejs\"><strong>bcoe/awesome-cross-platform-nodejs</strong></a></li>\n<li><a href=\"https://github.com/dypsilon/frontend-dev-bookmarks\"><strong>dypsilon/frontend-dev-bookmarks</strong></a></li>\n<li><a href=\"https://github.com/vsouza/awesome-ios\"><strong>vsouza/awesome-ios</strong></a></li>\n<li><a href=\"https://github.com/JStumpp/awesome-android\"><strong>JStumpp/awesome-android</strong></a></li>\n<li><a href=\"https://github.com/weblancaster/awesome-IoT-hybrid\"><strong>weblancaster/awesome-IoT-hybrid</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-electron\"><strong>sindresorhus/awesome-electron</strong></a></li>\n<li><a href=\"https://github.com/busterc/awesome-cordova\"><strong>busterc/awesome-cordova</strong></a></li>\n<li><a href=\"https://github.com/jondot/awesome-react-native\"><strong>jondot/awesome-react-native</strong></a></li>\n<li><a href=\"https://github.com/XamSome/awesome-xamarin\"><strong>XamSome/awesome-xamarin</strong></a></li>\n<li><a href=\"https://github.com/inputsh/awesome-linux\"><strong>inputsh/awesome-linux</strong></a></li>\n<li><a href=\"https://github.com/Friz-zy/awesome-linux-containers\"><strong>Friz-zy/awesome-linux-containers</strong></a></li>\n<li><a href=\"https://github.com/zoidbergwill/awesome-ebpf\"><strong>zoidbergwill/awesome-ebpf</strong></a></li>\n<li><a href=\"https://github.com/PandaFoss/Awesome-Arch\"><strong>PandaFoss/Awesome-Arch</strong></a></li>\n<li><a href=\"https://github.com/iCHAIT/awesome-macOS\"><strong>iCHAIT/awesome-macOS</strong></a></li>\n<li><a href=\"https://github.com/herrbischoff/awesome-macos-command-line\"><strong>herrbischoff/awesome-macos-command-line</strong></a></li>\n<li><a href=\"https://github.com/agarrharr/awesome-macos-screensavers\"><strong>agarrharr/awesome-macos-screensavers</strong></a></li>\n<li><a href=\"https://github.com/jaywcjlove/awesome-mac\"><strong>jaywcjlove/awesome-mac</strong></a></li>\n<li><a href=\"https://github.com/serhii-londar/open-source-mac-os-apps\"><strong>serhii-londar/open-source-mac-os-apps</strong></a></li>\n<li><a href=\"https://github.com/yenchenlin/awesome-watchos\"><strong>yenchenlin/awesome-watchos</strong></a></li>\n<li><a href=\"https://github.com/deephacks/awesome-jvm\"><strong>deephacks/awesome-jvm</strong></a></li>\n<li><a href=\"https://github.com/mailtoharshit/awesome-salesforce\"><strong>mailtoharshit/awesome-salesforce</strong></a></li>\n<li><a href=\"https://github.com/donnemartin/awesome-aws\"><strong>donnemartin/awesome-aws</strong></a></li>\n<li><a href=\"https://github.com/Awesome-Windows/Awesome\"><strong>Awesome-Windows/Awesome</strong></a></li>\n<li><a href=\"https://github.com/ipfs/awesome-ipfs\"><strong>ipfs/awesome-ipfs</strong></a></li>\n<li><a href=\"https://github.com/fuse-compound/awesome-fuse\"><strong>fuse-compound/awesome-fuse</strong></a></li>\n<li><a href=\"https://github.com/ianstormtaylor/awesome-heroku\"><strong>ianstormtaylor/awesome-heroku</strong></a></li>\n<li><a href=\"https://github.com/thibmaek/awesome-raspberry-pi\"><strong>thibmaek/awesome-raspberry-pi</strong></a></li>\n<li><a href=\"https://github.com/JesseTG/awesome-qt\"><strong>JesseTG/awesome-qt</strong></a></li>\n<li><a href=\"https://github.com/fregante/Awesome-WebExtensions\"><strong>fregante/Awesome-WebExtensions</strong></a></li>\n<li><a href=\"https://github.com/motion-open-source/awesome-rubymotion\"><strong>motion-open-source/awesome-rubymotion</strong></a></li>\n<li><a href=\"https://github.com/vitalets/awesome-smart-tv\"><strong>vitalets/awesome-smart-tv</strong></a></li>\n<li><a href=\"https://github.com/Kazhnuz/awesome-gnome\"><strong>Kazhnuz/awesome-gnome</strong></a></li>\n<li><a href=\"https://github.com/francoism90/awesome-kde\"><strong>francoism90/awesome-kde</strong></a></li>\n<li><a href=\"https://github.com/quozd/awesome-dotnet\"><strong>quozd/awesome-dotnet</strong></a></li>\n<li><a href=\"https://github.com/thangchung/awesome-dotnet-core\"><strong>thangchung/awesome-dotnet-core</strong></a></li>\n<li><a href=\"https://github.com/ironcev/awesome-roslyn\"><strong>ironcev/awesome-roslyn</strong></a></li>\n<li><a href=\"https://github.com/miguelmota/awesome-amazon-alexa\"><strong>miguelmota/awesome-amazon-alexa</strong></a></li>\n<li><a href=\"https://github.com/jonleibowitz/awesome-digitalocean\"><strong>jonleibowitz/awesome-digitalocean</strong></a></li>\n<li><a href=\"https://github.com/Solido/awesome-flutter\"><strong>Solido/awesome-flutter</strong></a></li>\n<li><a href=\"https://github.com/frenck/awesome-home-assistant\"><strong>frenck/awesome-home-assistant</strong></a></li>\n<li><a href=\"https://github.com/victorshinya/awesome-ibmcloud\"><strong>victorshinya/awesome-ibmcloud</strong></a></li>\n<li><a href=\"https://github.com/jthegedus/awesome-firebase\"><strong>jthegedus/awesome-firebase</strong></a></li>\n<li><a href=\"https://github.com/fkromer/awesome-ros2\"><strong>fkromer/awesome-ros2</strong></a></li>\n<li><a href=\"https://github.com/adafruit/awesome-adafruitio\"><strong>adafruit/awesome-adafruitio</strong></a></li>\n<li><a href=\"https://github.com/irazasyed/awesome-cloudflare\"><strong>irazasyed/awesome-cloudflare</strong></a></li>\n<li><a href=\"https://github.com/ravirupareliya/awesome-actions-on-google\"><strong>ravirupareliya/awesome-actions-on-google</strong></a></li>\n<li><a href=\"https://github.com/agucova/awesome-esp\"><strong>agucova/awesome-esp</strong></a></li>\n<li><a href=\"https://github.com/denolib/awesome-deno\"><strong>denolib/awesome-deno</strong></a></li>\n<li><a href=\"https://github.com/balintkissdev/awesome-dos\"><strong>balintkissdev/awesome-dos</strong></a></li>\n<li><a href=\"https://github.com/nix-community/awesome-nix\"><strong>nix-community/awesome-nix</strong></a></li>\n<li><a href=\"https://github.com/sorrycc/awesome-javascript\"><strong>sorrycc/awesome-javascript</strong></a></li>\n<li><a href=\"https://github.com/wbinnssmith/awesome-promises\"><strong>wbinnssmith/awesome-promises</strong></a></li>\n<li><a href=\"https://github.com/standard/awesome-standard\"><strong>standard/awesome-standard</strong></a></li>\n<li><a href=\"https://github.com/bolshchikov/js-must-watch\"><strong>bolshchikov/js-must-watch</strong></a></li>\n<li><a href=\"https://github.com/loverajoel/jstips\"><strong>loverajoel/jstips</strong></a></li>\n<li><a href=\"https://github.com/Kikobeats/awesome-network-js\"><strong>Kikobeats/awesome-network-js</strong></a></li>\n<li><a href=\"https://github.com/parro-it/awesome-micro-npm-packages\"><strong>parro-it/awesome-micro-npm-packages</strong></a></li>\n<li><a href=\"https://github.com/feross/awesome-mad-science\"><strong>feross/awesome-mad-science</strong></a></li>\n<li><a href=\"https://github.com/maxogden/maintenance-modules\"><strong>maxogden/maintenance-modules</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-npm\"><strong>sindresorhus/awesome-npm</strong></a></li>\n<li><a href=\"https://github.com/avajs/awesome-ava\"><strong>avajs/awesome-ava</strong></a></li>\n<li><a href=\"https://github.com/dustinspecker/awesome-eslint\"><strong>dustinspecker/awesome-eslint</strong></a></li>\n<li><a href=\"https://github.com/stoeffel/awesome-fp-js\"><strong>stoeffel/awesome-fp-js</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-observables\"><strong>sindresorhus/awesome-observables</strong></a></li>\n<li><a href=\"https://github.com/RyanZim/awesome-npm-scripts\"><strong>RyanZim/awesome-npm-scripts</strong></a></li>\n<li><a href=\"https://github.com/30-seconds/30-seconds-of-code\"><strong>30-seconds/30-seconds-of-code</strong></a></li>\n<li><a href=\"https://github.com/Richienb/awesome-ponyfills\"><strong>Richienb/awesome-ponyfills</strong></a></li>\n<li><a href=\"https://github.com/matteocrippa/awesome-swift\"><strong>matteocrippa/awesome-swift</strong></a></li>\n<li><a href=\"https://github.com/hsavit1/Awesome-Swift-Education\"><strong>hsavit1/Awesome-Swift-Education</strong></a></li>\n<li><a href=\"https://github.com/uraimo/Awesome-Swift-Playgrounds\"><strong>uraimo/Awesome-Swift-Playgrounds</strong></a></li>\n<li><a href=\"https://github.com/vinta/awesome-python\"><strong>vinta/awesome-python</strong></a></li>\n<li><a href=\"https://github.com/timofurrer/awesome-asyncio\"><strong>timofurrer/awesome-asyncio</strong></a></li>\n<li><a href=\"https://github.com/faroit/awesome-python-scientific-audio\"><strong>faroit/awesome-python-scientific-audio</strong></a></li>\n<li><a href=\"https://github.com/adafruit/awesome-circuitpython\"><strong>adafruit/awesome-circuitpython</strong></a></li>\n<li><a href=\"https://github.com/krzjoa/awesome-python-data-science\"><strong>krzjoa/awesome-python-data-science</strong></a></li>\n<li><a href=\"https://github.com/typeddjango/awesome-python-typing\"><strong>typeddjango/awesome-python-typing</strong></a></li>\n<li><a href=\"https://github.com/mcauser/awesome-micropython\"><strong>mcauser/awesome-micropython</strong></a></li>\n<li><a href=\"https://github.com/rust-unofficial/awesome-rust\"><strong>rust-unofficial/awesome-rust</strong></a></li>\n<li><a href=\"https://github.com/krispo/awesome-haskell\"><strong>krispo/awesome-haskell</strong></a></li>\n<li><a href=\"https://github.com/passy/awesome-purescript\"><strong>passy/awesome-purescript</strong></a></li>\n<li><a href=\"https://github.com/avelino/awesome-go\"><strong>avelino/awesome-go</strong></a></li>\n<li><a href=\"https://github.com/lauris/awesome-scala\"><strong>lauris/awesome-scala</strong></a></li>\n<li><a href=\"https://github.com/tindzk/awesome-scala-native\"><strong>tindzk/awesome-scala-native</strong></a></li>\n<li><a href=\"https://github.com/markets/awesome-ruby\"><strong>markets/awesome-ruby</strong></a></li>\n<li><a href=\"https://github.com/razum2um/awesome-clojure\"><strong>razum2um/awesome-clojure</strong></a></li>\n<li><a href=\"https://github.com/hantuzun/awesome-clojurescript\"><strong>hantuzun/awesome-clojurescript</strong></a></li>\n<li><a href=\"https://github.com/h4cc/awesome-elixir\"><strong>h4cc/awesome-elixir</strong></a></li>\n<li><a href=\"https://github.com/sporto/awesome-elm\"><strong>sporto/awesome-elm</strong></a></li>\n<li><a href=\"https://github.com/drobakowski/awesome-erlang\"><strong>drobakowski/awesome-erlang</strong></a></li>\n<li><a href=\"https://github.com/svaksha/Julia.jl\"><strong>svaksha/Julia.jl</strong></a></li>\n<li><a href=\"https://github.com/LewisJEllis/awesome-lua\"><strong>LewisJEllis/awesome-lua</strong></a></li>\n<li><a href=\"https://github.com/inputsh/awesome-c\"><strong>inputsh/awesome-c</strong></a></li>\n<li><a href=\"https://github.com/fffaraz/awesome-cpp\"><strong>fffaraz/awesome-cpp</strong></a></li>\n<li><a href=\"https://github.com/qinwf/awesome-R\"><strong>qinwf/awesome-R</strong></a></li>\n<li><a href=\"https://github.com/iamericfletcher/awesome-r-learning-resources\"><strong>iamericfletcher/awesome-r-learning-resources</strong></a></li>\n<li><a href=\"https://github.com/dlang-community/awesome-d\"><strong>dlang-community/awesome-d</strong></a></li>\n<li><a href=\"https://github.com/CodyReichert/awesome-cl\"><strong>CodyReichert/awesome-cl</strong></a></li>\n<li><a href=\"https://github.com/GustavBertram/awesome-common-lisp-learning\"><strong>GustavBertram/awesome-common-lisp-learning</strong></a></li>\n<li><a href=\"https://github.com/hachiojipm/awesome-perl\"><strong>hachiojipm/awesome-perl</strong></a></li>\n<li><a href=\"https://github.com/kdabir/awesome-groovy\"><strong>kdabir/awesome-groovy</strong></a></li>\n<li><a href=\"https://github.com/yissachar/awesome-dart\"><strong>yissachar/awesome-dart</strong></a></li>\n<li><a href=\"https://github.com/akullpp/awesome-java\"><strong>akullpp/awesome-java</strong></a></li>\n<li><a href=\"https://github.com/eleventigers/awesome-rxjava\"><strong>eleventigers/awesome-rxjava</strong></a></li>\n<li><a href=\"https://github.com/KotlinBy/awesome-kotlin\"><strong>KotlinBy/awesome-kotlin</strong></a></li>\n<li><a href=\"https://github.com/ocaml-community/awesome-ocaml\"><strong>ocaml-community/awesome-ocaml</strong></a></li>\n<li><a href=\"https://github.com/seancoyne/awesome-coldfusion\"><strong>seancoyne/awesome-coldfusion</strong></a></li>\n<li><a href=\"https://github.com/rabbiabram/awesome-fortran\"><strong>rabbiabram/awesome-fortran</strong></a></li>\n<li><a href=\"https://github.com/ziadoz/awesome-php\"><strong>ziadoz/awesome-php</strong></a></li>\n<li><a href=\"https://github.com/jakoch/awesome-composer\"><strong>jakoch/awesome-composer</strong></a></li>\n<li><a href=\"https://github.com/Fr0sT-Brutal/awesome-pascal\"><strong>Fr0sT-Brutal/awesome-pascal</strong></a></li>\n<li><a href=\"https://github.com/ahkscript/awesome-AutoHotkey\"><strong>ahkscript/awesome-AutoHotkey</strong></a></li>\n<li><a href=\"https://github.com/J2TeaM/awesome-AutoIt\"><strong>J2TeaM/awesome-AutoIt</strong></a></li>\n<li><a href=\"https://github.com/veelenga/awesome-crystal\"><strong>veelenga/awesome-crystal</strong></a></li>\n<li><a href=\"https://github.com/sfischer13/awesome-frege\"><strong>sfischer13/awesome-frege</strong></a></li>\n<li><a href=\"https://github.com/onqtam/awesome-cmake\"><strong>onqtam/awesome-cmake</strong></a></li>\n<li><a href=\"https://github.com/robinrodricks/awesome-actionscript3\"><strong>robinrodricks/awesome-actionscript3</strong></a></li>\n<li><a href=\"https://github.com/sfischer13/awesome-eta\"><strong>sfischer13/awesome-eta</strong></a></li>\n<li><a href=\"https://github.com/joaomilho/awesome-idris\"><strong>joaomilho/awesome-idris</strong></a></li>\n<li><a href=\"https://github.com/ohenley/awesome-ada\"><strong>ohenley/awesome-ada</strong></a></li>\n<li><a href=\"https://github.com/ebraminio/awesome-qsharp\"><strong>ebraminio/awesome-qsharp</strong></a></li>\n<li><a href=\"https://github.com/koolamusic/awesome-imba\"><strong>koolamusic/awesome-imba</strong></a></li>\n<li><a href=\"https://github.com/desiderantes/awesome-vala\"><strong>desiderantes/awesome-vala</strong></a></li>\n<li><a href=\"https://github.com/coq-community/awesome-coq\"><strong>coq-community/awesome-coq</strong></a></li>\n<li><a href=\"https://github.com/vlang/awesome-v\"><strong>vlang/awesome-v</strong></a></li>\n<li><a href=\"https://github.com/addyosmani/es6-tools\"><strong>addyosmani/es6-tools</strong></a></li>\n<li><a href=\"https://github.com/davidsonfellipe/awesome-wpo\"><strong>davidsonfellipe/awesome-wpo</strong></a></li>\n<li><a href=\"https://github.com/lvwzhen/tools\"><strong>lvwzhen/tools</strong></a></li>\n<li><a href=\"https://github.com/awesome-css-group/awesome-css\"><strong>awesome-css-group/awesome-css</strong></a></li>\n<li><a href=\"https://github.com/addyosmani/critical-path-css-tools\"><strong>addyosmani/critical-path-css-tools</strong></a></li>\n<li><a href=\"https://github.com/davidtheclark/scalable-css-reading-list\"><strong>davidtheclark/scalable-css-reading-list</strong></a></li>\n<li><a href=\"https://github.com/AllThingsSmitty/must-watch-css\"><strong>AllThingsSmitty/must-watch-css</strong></a></li>\n<li><a href=\"https://github.com/AllThingsSmitty/css-protips\"><strong>AllThingsSmitty/css-protips</strong></a></li>\n<li><a href=\"https://github.com/troxler/awesome-css-frameworks\"><strong>troxler/awesome-css-frameworks</strong></a></li>\n<li><a href=\"https://github.com/enaqx/awesome-react\"><strong>enaqx/awesome-react</strong></a></li>\n<li><a href=\"https://github.com/expede/awesome-relay\"><strong>expede/awesome-relay</strong></a></li>\n<li><a href=\"https://github.com/glauberfc/awesome-react-hooks\"><strong>glauberfc/awesome-react-hooks</strong></a></li>\n<li><a href=\"https://github.com/mateusortiz/webcomponents-the-right-way\"><strong>mateusortiz/webcomponents-the-right-way</strong></a></li>\n<li><a href=\"https://github.com/Granze/awesome-polymer\"><strong>Granze/awesome-polymer</strong></a></li>\n<li><a href=\"https://github.com/PatrickJS/awesome-angular\"><strong>PatrickJS/awesome-angular</strong></a></li>\n<li><a href=\"https://github.com/sadcitizen/awesome-backbone\"><strong>sadcitizen/awesome-backbone</strong></a></li>\n<li><a href=\"https://github.com/diegocard/awesome-html5\"><strong>diegocard/awesome-html5</strong></a></li>\n<li><a href=\"https://github.com/willianjusten/awesome-svg\"><strong>willianjusten/awesome-svg</strong></a></li>\n<li><a href=\"https://github.com/raphamorim/awesome-canvas\"><strong>raphamorim/awesome-canvas</strong></a></li>\n<li><a href=\"https://github.com/dnbard/awesome-knockout\"><strong>dnbard/awesome-knockout</strong></a></li>\n<li><a href=\"https://github.com/petk/awesome-dojo\"><strong>petk/awesome-dojo</strong></a></li>\n<li><a href=\"https://github.com/NoahBuscher/Inspire\"><strong>NoahBuscher/Inspire</strong></a></li>\n<li><a href=\"https://github.com/ember-community-russia/awesome-ember\"><strong>ember-community-russia/awesome-ember</strong></a></li>\n<li><a href=\"https://github.com/wasabeef/awesome-android-ui\"><strong>wasabeef/awesome-android-ui</strong></a></li>\n<li><a href=\"https://github.com/cjwirth/awesome-ios-ui\"><strong>cjwirth/awesome-ios-ui</strong></a></li>\n<li><a href=\"https://github.com/Urigo/awesome-meteor\"><strong>Urigo/awesome-meteor</strong></a></li>\n<li><a href=\"https://github.com/sturobson/BEM-resources\"><strong>sturobson/BEM-resources</strong></a></li>\n<li><a href=\"https://github.com/afonsopacifer/awesome-flexbox\"><strong>afonsopacifer/awesome-flexbox</strong></a></li>\n<li><a href=\"https://github.com/deanhume/typography\"><strong>deanhume/typography</strong></a></li>\n<li><a href=\"https://github.com/brunopulis/awesome-a11y\"><strong>brunopulis/awesome-a11y</strong></a></li>\n<li><a href=\"https://github.com/sachin1092/awesome-material\"><strong>sachin1092/awesome-material</strong></a></li>\n<li><a href=\"https://github.com/wbkd/awesome-d3\"><strong>wbkd/awesome-d3</strong></a></li>\n<li><a href=\"https://github.com/jonathandion/awesome-emails\"><strong>jonathandion/awesome-emails</strong></a></li>\n<li><a href=\"https://github.com/petk/awesome-jquery\"><strong>petk/awesome-jquery</strong></a></li>\n<li><a href=\"https://github.com/AllThingsSmitty/jquery-tips-everyone-should-know\"><strong>AllThingsSmitty/jquery-tips-everyone-should-know</strong></a></li>\n<li><a href=\"https://github.com/notthetup/awesome-webaudio\"><strong>notthetup/awesome-webaudio</strong></a></li>\n<li><a href=\"https://github.com/pazguille/offline-first\"><strong>pazguille/offline-first</strong></a></li>\n<li><a href=\"https://github.com/agarrharr/awesome-static-website-services\"><strong>agarrharr/awesome-static-website-services</strong></a></li>\n<li><a href=\"https://github.com/cyclejs-community/awesome-cyclejs\"><strong>cyclejs-community/awesome-cyclejs</strong></a></li>\n<li><a href=\"https://github.com/dok/awesome-text-editing\"><strong>dok/awesome-text-editing</strong></a></li>\n<li><a href=\"https://github.com/fliptheweb/motion-ui-design\"><strong>fliptheweb/motion-ui-design</strong></a></li>\n<li><a href=\"https://github.com/vuejs/awesome-vue\"><strong>vuejs/awesome-vue</strong></a></li>\n<li><a href=\"https://github.com/sadcitizen/awesome-marionette\"><strong>sadcitizen/awesome-marionette</strong></a></li>\n<li><a href=\"https://github.com/aurelia-contrib/awesome-aurelia\"><strong>aurelia-contrib/awesome-aurelia</strong></a></li>\n<li><a href=\"https://github.com/zingchart/awesome-charting\"><strong>zingchart/awesome-charting</strong></a></li>\n<li><a href=\"https://github.com/candelibas/awesome-ionic\"><strong>candelibas/awesome-ionic</strong></a></li>\n<li><a href=\"https://github.com/ChromeDevTools/awesome-chrome-devtools\"><strong>ChromeDevTools/awesome-chrome-devtools</strong></a></li>\n<li><a href=\"https://github.com/jdrgomes/awesome-postcss\"><strong>jdrgomes/awesome-postcss</strong></a></li>\n<li><a href=\"https://github.com/nikgraf/awesome-draft-js\"><strong>nikgraf/awesome-draft-js</strong></a></li>\n<li><a href=\"https://github.com/TalAter/awesome-service-workers\"><strong>TalAter/awesome-service-workers</strong></a></li>\n<li><a href=\"https://github.com/TalAter/awesome-progressive-web-apps\"><strong>TalAter/awesome-progressive-web-apps</strong></a></li>\n<li><a href=\"https://github.com/choojs/awesome-choo\"><strong>choojs/awesome-choo</strong></a></li>\n<li><a href=\"https://github.com/brillout/awesome-redux\"><strong>brillout/awesome-redux</strong></a></li>\n<li><a href=\"https://github.com/webpack-contrib/awesome-webpack\"><strong>webpack-contrib/awesome-webpack</strong></a></li>\n<li><a href=\"https://github.com/browserify/awesome-browserify\"><strong>browserify/awesome-browserify</strong></a></li>\n<li><a href=\"https://github.com/Famolus/awesome-sass\"><strong>Famolus/awesome-sass</strong></a></li>\n<li><a href=\"https://github.com/websemantics/awesome-ant-design\"><strong>websemantics/awesome-ant-design</strong></a></li>\n<li><a href=\"https://github.com/LucasBassetti/awesome-less\"><strong>LucasBassetti/awesome-less</strong></a></li>\n<li><a href=\"https://github.com/sjfricke/awesome-webgl\"><strong>sjfricke/awesome-webgl</strong></a></li>\n<li><a href=\"https://github.com/preactjs/awesome-preact\"><strong>preactjs/awesome-preact</strong></a></li>\n<li><a href=\"https://github.com/jbmoelker/progressive-enhancement-resources\"><strong>jbmoelker/progressive-enhancement-resources</strong></a></li>\n<li><a href=\"https://github.com/unicodeveloper/awesome-nextjs\"><strong>unicodeveloper/awesome-nextjs</strong></a></li>\n<li><a href=\"https://github.com/web-padawan/awesome-lit-html\"><strong>web-padawan/awesome-lit-html</strong></a></li>\n<li><a href=\"https://github.com/automata/awesome-jamstack\"><strong>automata/awesome-jamstack</strong></a></li>\n<li><a href=\"https://github.com/henrikwirth/awesome-wordpress-gatsby\"><strong>henrikwirth/awesome-wordpress-gatsby</strong></a></li>\n<li><a href=\"https://github.com/myshov/awesome-mobile-web-development\"><strong>myshov/awesome-mobile-web-development</strong></a></li>\n<li><a href=\"https://github.com/lauthieb/awesome-storybook\"><strong>lauthieb/awesome-storybook</strong></a></li>\n<li><a href=\"https://github.com/AdrienTorris/awesome-blazor\"><strong>AdrienTorris/awesome-blazor</strong></a></li>\n<li><a href=\"https://github.com/csabapalfi/awesome-pagespeed-metrics\"><strong>csabapalfi/awesome-pagespeed-metrics</strong></a></li>\n<li><a href=\"https://github.com/aniftyco/awesome-tailwindcss\"><strong>aniftyco/awesome-tailwindcss</strong></a></li>\n<li><a href=\"https://github.com/seed-rs/awesome-seed-rs\"><strong>seed-rs/awesome-seed-rs</strong></a></li>\n<li><a href=\"https://github.com/pajaydev/awesome-web-performance-budget\"><strong>pajaydev/awesome-web-performance-budget</strong></a></li>\n<li><a href=\"https://github.com/sergey-pimenov/awesome-web-animation\"><strong>sergey-pimenov/awesome-web-animation</strong></a></li>\n<li><a href=\"https://github.com/jetli/awesome-yew\"><strong>jetli/awesome-yew</strong></a></li>\n<li><a href=\"https://github.com/nadunindunil/awesome-material-ui\"><strong>nadunindunil/awesome-material-ui</strong></a></li>\n<li><a href=\"https://github.com/componently-com/awesome-building-blocks-for-web-apps\"><strong>componently-com/awesome-building-blocks-for-web-apps</strong></a></li>\n<li><a href=\"https://github.com/TheComputerM/awesome-svelte\"><strong>TheComputerM/awesome-svelte</strong></a></li>\n<li><a href=\"https://github.com/klaufel/awesome-design-systems\"><strong>klaufel/awesome-design-systems</strong></a></li>\n<li><a href=\"https://github.com/innocenzi/awesome-inertiajs\"><strong>innocenzi/awesome-inertiajs</strong></a></li>\n<li><a href=\"https://github.com/mdbootstrap/awesome-mdbootstrap\"><strong>mdbootstrap/awesome-mdbootstrap</strong></a></li>\n<li><a href=\"https://github.com/mjhea0/awesome-flask\"><strong>mjhea0/awesome-flask</strong></a></li>\n<li><a href=\"https://github.com/veggiemonk/awesome-docker\"><strong>veggiemonk/awesome-docker</strong></a></li>\n<li><a href=\"https://github.com/iJackUA/awesome-vagrant\"><strong>iJackUA/awesome-vagrant</strong></a></li>\n<li><a href=\"https://github.com/uralbash/awesome-pyramid\"><strong>uralbash/awesome-pyramid</strong></a></li>\n<li><a href=\"https://github.com/PerfectCarl/awesome-play1\"><strong>PerfectCarl/awesome-play1</strong></a></li>\n<li><a href=\"https://github.com/friendsofcake/awesome-cakephp\"><strong>friendsofcake/awesome-cakephp</strong></a></li>\n<li><a href=\"https://github.com/sitepoint-editors/awesome-symfony\"><strong>sitepoint-editors/awesome-symfony</strong></a></li>\n<li><a href=\"https://github.com/pehapkari/awesome-symfony-education\"><strong>pehapkari/awesome-symfony-education</strong></a></li>\n<li><a href=\"https://github.com/chiraggude/awesome-laravel\"><strong>chiraggude/awesome-laravel</strong></a></li>\n<li><a href=\"https://github.com/fukuball/Awesome-Laravel-Education\"><strong>fukuball/Awesome-Laravel-Education</strong></a></li>\n<li><a href=\"https://github.com/blade-ui-kit/awesome-tall-stack\"><strong>blade-ui-kit/awesome-tall-stack</strong></a></li>\n<li><a href=\"https://github.com/gramantin/awesome-rails\"><strong>gramantin/awesome-rails</strong></a></li>\n<li><a href=\"https://github.com/hothero/awesome-rails-gem\"><strong>hothero/awesome-rails-gem</strong></a></li>\n<li><a href=\"https://github.com/phalcon/awesome-phalcon\"><strong>phalcon/awesome-phalcon</strong></a></li>\n<li><a href=\"https://github.com/phanan/htaccess\"><strong>phanan/htaccess</strong></a></li>\n<li><a href=\"https://github.com/fcambus/nginx-resources\"><strong>fcambus/nginx-resources</strong></a></li>\n<li><a href=\"https://github.com/stve/awesome-dropwizard\"><strong>stve/awesome-dropwizard</strong></a></li>\n<li><a href=\"https://github.com/ramitsurana/awesome-kubernetes\"><strong>ramitsurana/awesome-kubernetes</strong></a></li>\n<li><a href=\"https://github.com/unicodeveloper/awesome-lumen\"><strong>unicodeveloper/awesome-lumen</strong></a></li>\n<li><a href=\"https://github.com/pmuens/awesome-serverless\"><strong>pmuens/awesome-serverless</strong></a></li>\n<li><a href=\"https://github.com/PhantomYdn/awesome-wicket\"><strong>PhantomYdn/awesome-wicket</strong></a></li>\n<li><a href=\"https://github.com/vert-x3/vertx-awesome\"><strong>vert-x3/vertx-awesome</strong></a></li>\n<li><a href=\"https://github.com/shuaibiyy/awesome-terraform\"><strong>shuaibiyy/awesome-terraform</strong></a></li>\n<li><a href=\"https://github.com/Cellane/awesome-vapor\"><strong>Cellane/awesome-vapor</strong></a></li>\n<li><a href=\"https://github.com/ucg8j/awesome-dash\"><strong>ucg8j/awesome-dash</strong></a></li>\n<li><a href=\"https://github.com/mjhea0/awesome-fastapi\"><strong>mjhea0/awesome-fastapi</strong></a></li>\n<li><a href=\"https://github.com/kolomied/awesome-cdk\"><strong>kolomied/awesome-cdk</strong></a></li>\n<li><a href=\"https://github.com/kdeldycke/awesome-iam\"><strong>kdeldycke/awesome-iam</strong></a></li>\n<li><a href=\"https://github.com/prakhar1989/awesome-courses\"><strong>prakhar1989/awesome-courses</strong></a></li>\n<li><a href=\"https://github.com/academic/awesome-datascience\"><strong>academic/awesome-datascience</strong></a></li>\n<li><a href=\"https://github.com/siboehm/awesome-learn-datascience\"><strong>siboehm/awesome-learn-datascience</strong></a></li>\n<li><a href=\"https://github.com/josephmisiti/awesome-machine-learning\"><strong>josephmisiti/awesome-machine-learning</strong></a></li>\n<li><a href=\"https://github.com/ujjwalkarn/Machine-Learning-Tutorials\"><strong>ujjwalkarn/Machine-Learning-Tutorials</strong></a></li>\n<li><a href=\"https://github.com/arbox/machine-learning-with-ruby\"><strong>arbox/machine-learning-with-ruby</strong></a></li>\n<li><a href=\"https://github.com/likedan/Awesome-CoreML-Models\"><strong>likedan/Awesome-CoreML-Models</strong></a></li>\n<li><a href=\"https://github.com/h2oai/awesome-h2o\"><strong>h2oai/awesome-h2o</strong></a></li>\n<li><a href=\"https://github.com/SE-ML/awesome-seml\"><strong>SE-ML/awesome-seml</strong></a></li>\n<li><a href=\"https://github.com/georgezouq/awesome-ai-in-finance\"><strong>georgezouq/awesome-ai-in-finance</strong></a></li>\n<li><a href=\"https://github.com/n2cholas/awesome-jax\"><strong>n2cholas/awesome-jax</strong></a></li>\n<li><a href=\"https://github.com/altamiracorp/awesome-xai\"><strong>altamiracorp/awesome-xai</strong></a></li>\n<li><a href=\"https://github.com/edobashira/speech-language-processing\"><strong>edobashira/speech-language-processing</strong></a></li>\n<li><a href=\"https://github.com/dav009/awesome-spanish-nlp\"><strong>dav009/awesome-spanish-nlp</strong></a></li>\n<li><a href=\"https://github.com/arbox/nlp-with-ruby\"><strong>arbox/nlp-with-ruby</strong></a></li>\n<li><a href=\"https://github.com/seriousran/awesome-qa\"><strong>seriousran/awesome-qa</strong></a></li>\n<li><a href=\"https://github.com/tokenmill/awesome-nlg\"><strong>tokenmill/awesome-nlg</strong></a></li>\n<li><a href=\"https://github.com/theimpossibleastronaut/awesome-linguistics\"><strong>theimpossibleastronaut/awesome-linguistics</strong></a></li>\n<li><a href=\"https://github.com/sobolevn/awesome-cryptography\"><strong>sobolevn/awesome-cryptography</strong></a></li>\n<li><a href=\"https://github.com/pFarb/awesome-crypto-papers\"><strong>pFarb/awesome-crypto-papers</strong></a></li>\n<li><a href=\"https://github.com/jbhuang0604/awesome-computer-vision\"><strong>jbhuang0604/awesome-computer-vision</strong></a></li>\n<li><a href=\"https://github.com/ChristosChristofidis/awesome-deep-learning\"><strong>ChristosChristofidis/awesome-deep-learning</strong></a></li>\n<li><a href=\"https://github.com/jtoy/awesome-tensorflow\"><strong>jtoy/awesome-tensorflow</strong></a></li>\n<li><a href=\"https://github.com/aaronhma/awesome-tensorflow-js\"><strong>aaronhma/awesome-tensorflow-js</strong></a></li>\n<li><a href=\"https://github.com/margaretmz/awesome-tensorflow-lite\"><strong>margaretmz/awesome-tensorflow-lite</strong></a></li>\n<li><a href=\"https://github.com/terryum/awesome-deep-learning-papers\"><strong>terryum/awesome-deep-learning-papers</strong></a></li>\n<li><a href=\"https://github.com/guillaume-chevalier/awesome-deep-learning-resources\"><strong>guillaume-chevalier/awesome-deep-learning-resources</strong></a></li>\n<li><a href=\"https://github.com/kjw0612/awesome-deep-vision\"><strong>kjw0612/awesome-deep-vision</strong></a></li>\n<li><a href=\"https://github.com/ossu/computer-science\"><strong>ossu/computer-science</strong></a></li>\n<li><a href=\"https://github.com/lucasviola/awesome-functional-programming\"><strong>lucasviola/awesome-functional-programming</strong></a></li>\n<li><a href=\"https://github.com/dspinellis/awesome-msr\"><strong>dspinellis/awesome-msr</strong></a></li>\n<li><a href=\"https://github.com/analysis-tools-dev/static-analysis\"><strong>analysis-tools-dev/static-analysis</strong></a></li>\n<li><a href=\"https://github.com/harpribot/awesome-information-retrieval\"><strong>harpribot/awesome-information-retrieval</strong></a></li>\n<li><a href=\"https://github.com/desireevl/awesome-quantum-computing\"><strong>desireevl/awesome-quantum-computing</strong></a></li>\n<li><a href=\"https://github.com/mostafatouny/awesome-theoretical-computer-science\"><strong>mostafatouny/awesome-theoretical-computer-science</strong></a></li>\n<li><a href=\"https://github.com/onurakpolat/awesome-bigdata\"><strong>onurakpolat/awesome-bigdata</strong></a></li>\n<li><a href=\"https://github.com/awesomedata/awesome-public-datasets\"><strong>awesomedata/awesome-public-datasets</strong></a></li>\n<li><a href=\"https://github.com/youngwookim/awesome-hadoop\"><strong>youngwookim/awesome-hadoop</strong></a></li>\n<li><a href=\"https://github.com/igorbarinov/awesome-data-engineering\"><strong>igorbarinov/awesome-data-engineering</strong></a></li>\n<li><a href=\"https://github.com/manuzhang/awesome-streaming\"><strong>manuzhang/awesome-streaming</strong></a></li>\n<li><a href=\"https://github.com/awesome-spark/awesome-spark\"><strong>awesome-spark/awesome-spark</strong></a></li>\n<li><a href=\"https://github.com/ambster-public/awesome-qlik\"><strong>ambster-public/awesome-qlik</strong></a></li>\n<li><a href=\"https://github.com/sduff/awesome-splunk\"><strong>sduff/awesome-splunk</strong></a></li>\n<li><a href=\"https://github.com/papers-we-love/papers-we-love\"><strong>papers-we-love/papers-we-love</strong></a></li>\n<li><a href=\"https://github.com/JanVanRyswyck/awesome-talks\"><strong>JanVanRyswyck/awesome-talks</strong></a></li>\n<li><a href=\"https://github.com/tayllan/awesome-algorithms\"><strong>tayllan/awesome-algorithms</strong></a></li>\n<li><a href=\"https://github.com/gaerae/awesome-algorithms-education\"><strong>gaerae/awesome-algorithms-education</strong></a></li>\n<li><a href=\"https://github.com/enjalot/algovis\"><strong>enjalot/algovis</strong></a></li>\n<li><a href=\"https://github.com/owainlewis/awesome-artificial-intelligence\"><strong>owainlewis/awesome-artificial-intelligence</strong></a></li>\n<li><a href=\"https://github.com/marcobiedermann/search-engine-optimization\"><strong>marcobiedermann/search-engine-optimization</strong></a></li>\n<li><a href=\"https://github.com/lnishan/awesome-competitive-programming\"><strong>lnishan/awesome-competitive-programming</strong></a></li>\n<li><a href=\"https://github.com/rossant/awesome-math\"><strong>rossant/awesome-math</strong></a></li>\n<li><a href=\"https://github.com/passy/awesome-recursion-schemes\"><strong>passy/awesome-recursion-schemes</strong></a></li>\n<li><a href=\"https://github.com/EbookFoundation/free-programming-books\"><strong>EbookFoundation/free-programming-books</strong></a></li>\n<li><a href=\"https://github.com/dariubs/GoBooks\"><strong>dariubs/GoBooks</strong></a></li>\n<li><a href=\"https://github.com/RomanTsegelskyi/rbooks\"><strong>RomanTsegelskyi/rbooks</strong></a></li>\n<li><a href=\"https://github.com/hackerkid/Mind-Expanding-Books\"><strong>hackerkid/Mind-Expanding-Books</strong></a></li>\n<li><a href=\"https://github.com/TalAter/awesome-book-authoring\"><strong>TalAter/awesome-book-authoring</strong></a></li>\n<li><a href=\"https://github.com/sger/ElixirBooks\"><strong>sger/ElixirBooks</strong></a></li>\n<li><a href=\"https://github.com/dreikanter/sublime-bookmarks\"><strong>dreikanter/sublime-bookmarks</strong></a></li>\n<li><a href=\"https://github.com/mhinz/vim-galore\"><strong>mhinz/vim-galore</strong></a></li>\n<li><a href=\"https://github.com/emacs-tw/awesome-emacs\"><strong>emacs-tw/awesome-emacs</strong></a></li>\n<li><a href=\"https://github.com/mehcode/awesome-atom\"><strong>mehcode/awesome-atom</strong></a></li>\n<li><a href=\"https://github.com/viatsko/awesome-vscode\"><strong>viatsko/awesome-vscode</strong></a></li>\n<li><a href=\"https://github.com/ellisonleao/magictools\"><strong>ellisonleao/magictools</strong></a></li>\n<li><a href=\"https://github.com/hzoo/awesome-gametalks\"><strong>hzoo/awesome-gametalks</strong></a></li>\n<li><a href=\"https://github.com/godotengine/awesome-godot\"><strong>godotengine/awesome-godot</strong></a></li>\n<li><a href=\"https://github.com/leereilly/games\"><strong>leereilly/games</strong></a></li>\n<li><a href=\"https://github.com/RyanNielson/awesome-unity\"><strong>RyanNielson/awesome-unity</strong></a></li>\n<li><a href=\"https://github.com/hkirat/awesome-chess\"><strong>hkirat/awesome-chess</strong></a></li>\n<li><a href=\"https://github.com/love2d-community/awesome-love2d\"><strong>love2d-community/awesome-love2d</strong></a></li>\n<li><a href=\"https://github.com/pico-8/awesome-PICO-8\"><strong>pico-8/awesome-PICO-8</strong></a></li>\n<li><a href=\"https://github.com/gbdev/awesome-gbdev\"><strong>gbdev/awesome-gbdev</strong></a></li>\n<li><a href=\"https://github.com/WebCreationClub/awesome-construct\"><strong>WebCreationClub/awesome-construct</strong></a></li>\n<li><a href=\"https://github.com/stetso/awesome-gideros\"><strong>stetso/awesome-gideros</strong></a></li>\n<li><a href=\"https://github.com/bs-community/awesome-minecraft\"><strong>bs-community/awesome-minecraft</strong></a></li>\n<li><a href=\"https://github.com/leomaurodesenv/game-datasets\"><strong>leomaurodesenv/game-datasets</strong></a></li>\n<li><a href=\"https://github.com/Dvergar/awesome-haxe-gamedev\"><strong>Dvergar/awesome-haxe-gamedev</strong></a></li>\n<li><a href=\"https://github.com/rafaskb/awesome-libgdx\"><strong>rafaskb/awesome-libgdx</strong></a></li>\n<li><a href=\"https://github.com/playcanvas/awesome-playcanvas\"><strong>playcanvas/awesome-playcanvas</strong></a></li>\n<li><a href=\"https://github.com/radek-sprta/awesome-game-remakes\"><strong>radek-sprta/awesome-game-remakes</strong></a></li>\n<li><a href=\"https://github.com/flame-engine/awesome-flame\"><strong>flame-engine/awesome-flame</strong></a></li>\n<li><a href=\"https://github.com/mhxion/awesome-discord-communities\"><strong>mhxion/awesome-discord-communities</strong></a></li>\n<li><a href=\"https://github.com/tobiasvl/awesome-chip-8\"><strong>tobiasvl/awesome-chip-8</strong></a></li>\n<li><a href=\"https://github.com/michelpereira/awesome-games-of-coding\"><strong>michelpereira/awesome-games-of-coding</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/quick-look-plugins\"><strong>sindresorhus/quick-look-plugins</strong></a></li>\n<li><a href=\"https://github.com/jondot/awesome-devenv\"><strong>jondot/awesome-devenv</strong></a></li>\n<li><a href=\"https://github.com/webpro/awesome-dotfiles\"><strong>webpro/awesome-dotfiles</strong></a></li>\n<li><a href=\"https://github.com/alebcay/awesome-shell\"><strong>alebcay/awesome-shell</strong></a></li>\n<li><a href=\"https://github.com/jorgebucaran/awsm.fish\"><strong>jorgebucaran/awsm.fish</strong></a></li>\n<li><a href=\"https://github.com/agarrharr/awesome-cli-apps\"><strong>agarrharr/awesome-cli-apps</strong></a></li>\n<li><a href=\"https://github.com/unixorn/awesome-zsh-plugins\"><strong>unixorn/awesome-zsh-plugins</strong></a></li>\n<li><a href=\"https://github.com/phillipadsmith/awesome-github\"><strong>phillipadsmith/awesome-github</strong></a></li>\n<li><a href=\"https://github.com/stefanbuck/awesome-browser-extensions-for-github\"><strong>stefanbuck/awesome-browser-extensions-for-github</strong></a></li>\n<li><a href=\"https://github.com/tiimgreen/github-cheat-sheet\"><strong>tiimgreen/github-cheat-sheet</strong></a></li>\n<li><a href=\"https://github.com/matchai/awesome-pinned-gists\"><strong>matchai/awesome-pinned-gists</strong></a></li>\n<li><a href=\"https://github.com/arslanbilal/git-cheat-sheet\"><strong>arslanbilal/git-cheat-sheet</strong></a></li>\n<li><a href=\"https://github.com/git-tips/tips\"><strong>git-tips/tips</strong></a></li>\n<li><a href=\"https://github.com/stevemao/awesome-git-addons\"><strong>stevemao/awesome-git-addons</strong></a></li>\n<li><a href=\"https://github.com/compscilauren/awesome-git-hooks\"><strong>compscilauren/awesome-git-hooks</strong></a></li>\n<li><a href=\"https://github.com/moul/awesome-ssh\"><strong>moul/awesome-ssh</strong></a></li>\n<li><a href=\"https://github.com/tvvocold/FOSS-for-Dev\"><strong>tvvocold/FOSS-for-Dev</strong></a></li>\n<li><a href=\"https://github.com/bnb/awesome-hyper\"><strong>bnb/awesome-hyper</strong></a></li>\n<li><a href=\"https://github.com/janikvonrotz/awesome-powershell\"><strong>janikvonrotz/awesome-powershell</strong></a></li>\n<li><a href=\"https://github.com/alfred-workflows/awesome-alfred-workflows\"><strong>alfred-workflows/awesome-alfred-workflows</strong></a></li>\n<li><a href=\"https://github.com/k4m4/terminals-are-sexy\"><strong>k4m4/terminals-are-sexy</strong></a></li>\n<li><a href=\"https://github.com/sdras/awesome-actions\"><strong>sdras/awesome-actions</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-scifi\"><strong>sindresorhus/awesome-scifi</strong></a></li>\n<li><a href=\"https://github.com/RichardLitt/awesome-fantasy\"><strong>RichardLitt/awesome-fantasy</strong></a></li>\n<li><a href=\"https://github.com/ayr-ton/awesome-geek-podcasts\"><strong>ayr-ton/awesome-geek-podcasts</strong></a></li>\n<li><a href=\"https://github.com/zudochkin/awesome-newsletters\"><strong>zudochkin/awesome-newsletters</strong></a></li>\n<li><a href=\"https://github.com/victorlaerte/awesome-it-quotes\"><strong>victorlaerte/awesome-it-quotes</strong></a></li>\n<li><a href=\"https://github.com/numetriclabz/awesome-db\"><strong>numetriclabz/awesome-db</strong></a></li>\n<li><a href=\"https://github.com/shlomi-noach/awesome-mysql\"><strong>shlomi-noach/awesome-mysql</strong></a></li>\n<li><a href=\"https://github.com/dahlia/awesome-sqlalchemy\"><strong>dahlia/awesome-sqlalchemy</strong></a></li>\n<li><a href=\"https://github.com/mark-rushakoff/awesome-influxdb\"><strong>mark-rushakoff/awesome-influxdb</strong></a></li>\n<li><a href=\"https://github.com/neueda/awesome-neo4j\"><strong>neueda/awesome-neo4j</strong></a></li>\n<li><a href=\"https://github.com/ramnes/awesome-mongodb\"><strong>ramnes/awesome-mongodb</strong></a></li>\n<li><a href=\"https://github.com/d3viant0ne/awesome-rethinkdb\"><strong>d3viant0ne/awesome-rethinkdb</strong></a></li>\n<li><a href=\"https://github.com/mohataher/awesome-tinkerpop\"><strong>mohataher/awesome-tinkerpop</strong></a></li>\n<li><a href=\"https://github.com/dhamaniasad/awesome-postgres\"><strong>dhamaniasad/awesome-postgres</strong></a></li>\n<li><a href=\"https://github.com/quangv/awesome-couchdb\"><strong>quangv/awesome-couchdb</strong></a></li>\n<li><a href=\"https://github.com/rayokota/awesome-hbase\"><strong>rayokota/awesome-hbase</strong></a></li>\n<li><a href=\"https://github.com/erictleung/awesome-nosql-guides\"><strong>erictleung/awesome-nosql-guides</strong></a></li>\n<li><a href=\"https://github.com/chrislatorres/awesome-contexture\"><strong>chrislatorres/awesome-contexture</strong></a></li>\n<li><a href=\"https://github.com/mgramin/awesome-db-tools\"><strong>mgramin/awesome-db-tools</strong></a></li>\n<li><a href=\"https://github.com/vaticle/typedb-awesome\"><strong>vaticle/typedb-awesome</strong></a></li>\n<li><a href=\"https://github.com/Anant/awesome-cassandra\"><strong>Anant/awesome-cassandra</strong></a></li>\n<li><a href=\"https://github.com/shime/creative-commons-media\"><strong>shime/creative-commons-media</strong></a></li>\n<li><a href=\"https://github.com/brabadu/awesome-fonts\"><strong>brabadu/awesome-fonts</strong></a></li>\n<li><a href=\"https://github.com/chrissimpkins/codeface\"><strong>chrissimpkins/codeface</strong></a></li>\n<li><a href=\"https://github.com/neutraltone/awesome-stock-resources\"><strong>neutraltone/awesome-stock-resources</strong></a></li>\n<li><a href=\"https://github.com/davisonio/awesome-gif\"><strong>davisonio/awesome-gif</strong></a></li>\n<li><a href=\"https://github.com/ciconia/awesome-music\"><strong>ciconia/awesome-music</strong></a></li>\n<li><a href=\"https://github.com/44bits/awesome-opensource-documents\"><strong>44bits/awesome-opensource-documents</strong></a></li>\n<li><a href=\"https://github.com/willianjusten/awesome-audio-visualization\"><strong>willianjusten/awesome-audio-visualization</strong></a></li>\n<li><a href=\"https://github.com/ebu/awesome-broadcasting\"><strong>ebu/awesome-broadcasting</strong></a></li>\n<li><a href=\"https://github.com/Siilwyn/awesome-pixel-art\"><strong>Siilwyn/awesome-pixel-art</strong></a></li>\n<li><a href=\"https://github.com/transitive-bullshit/awesome-ffmpeg\"><strong>transitive-bullshit/awesome-ffmpeg</strong></a></li>\n<li><a href=\"https://github.com/notlmn/awesome-icons\"><strong>notlmn/awesome-icons</strong></a></li>\n<li><a href=\"https://github.com/stingalleman/awesome-audiovisual\"><strong>stingalleman/awesome-audiovisual</strong></a></li>\n<li><a href=\"https://github.com/mfkl/awesome-vlc\"><strong>mfkl/awesome-vlc</strong></a></li>\n<li><a href=\"https://github.com/therebelrobot/awesome-workshopper\"><strong>therebelrobot/awesome-workshopper</strong></a></li>\n<li><a href=\"https://github.com/karlhorky/learn-to-program\"><strong>karlhorky/learn-to-program</strong></a></li>\n<li><a href=\"https://github.com/matteofigus/awesome-speaking\"><strong>matteofigus/awesome-speaking</strong></a></li>\n<li><a href=\"https://github.com/lucasviola/awesome-tech-videos\"><strong>lucasviola/awesome-tech-videos</strong></a></li>\n<li><a href=\"https://github.com/hangtwenty/dive-into-machine-learning\"><strong>hangtwenty/dive-into-machine-learning</strong></a></li>\n<li><a href=\"https://github.com/watson/awesome-computer-history\"><strong>watson/awesome-computer-history</strong></a></li>\n<li><a href=\"https://github.com/HollyAdele/awesome-programming-for-kids\"><strong>HollyAdele/awesome-programming-for-kids</strong></a></li>\n<li><a href=\"https://github.com/yrgo/awesome-educational-games\"><strong>yrgo/awesome-educational-games</strong></a></li>\n<li><a href=\"https://github.com/micromata/awesome-javascript-learning\"><strong>micromata/awesome-javascript-learning</strong></a></li>\n<li><a href=\"https://github.com/micromata/awesome-css-learning\"><strong>micromata/awesome-css-learning</strong></a></li>\n<li><a href=\"https://github.com/dend/awesome-product-management\"><strong>dend/awesome-product-management</strong></a></li>\n<li><a href=\"https://github.com/liuchong/awesome-roadmaps\"><strong>liuchong/awesome-roadmaps</strong></a></li>\n<li><a href=\"https://github.com/JoseDeFreitas/awesome-youtubers\"><strong>JoseDeFreitas/awesome-youtubers</strong></a></li>\n<li><a href=\"https://github.com/paragonie/awesome-appsec\"><strong>paragonie/awesome-appsec</strong></a></li>\n<li><a href=\"https://github.com/sbilly/awesome-security\"><strong>sbilly/awesome-security</strong></a></li>\n<li><a href=\"https://github.com/apsdehal/awesome-ctf\"><strong>apsdehal/awesome-ctf</strong></a></li>\n<li><a href=\"https://github.com/rshipp/awesome-malware-analysis\"><strong>rshipp/awesome-malware-analysis</strong></a></li>\n<li><a href=\"https://github.com/ashishb/android-security-awesome\"><strong>ashishb/android-security-awesome</strong></a></li>\n<li><a href=\"https://github.com/carpedm20/awesome-hacking\"><strong>carpedm20/awesome-hacking</strong></a></li>\n<li><a href=\"https://github.com/paralax/awesome-honeypots\"><strong>paralax/awesome-honeypots</strong></a></li>\n<li><a href=\"https://github.com/meirwah/awesome-incident-response\"><strong>meirwah/awesome-incident-response</strong></a></li>\n<li><a href=\"https://github.com/jaredthecoder/awesome-vehicle-security\"><strong>jaredthecoder/awesome-vehicle-security</strong></a></li>\n<li><a href=\"https://github.com/qazbnm456/awesome-web-security\"><strong>qazbnm456/awesome-web-security</strong></a></li>\n<li><a href=\"https://github.com/fabacab/awesome-lockpicking\"><strong>fabacab/awesome-lockpicking</strong></a></li>\n<li><a href=\"https://github.com/fabacab/awesome-cybersecurity-blueteam\"><strong>fabacab/awesome-cybersecurity-blueteam</strong></a></li>\n<li><a href=\"https://github.com/cpuu/awesome-fuzzing\"><strong>cpuu/awesome-fuzzing</strong></a></li>\n<li><a href=\"https://github.com/fkie-cad/awesome-embedded-and-iot-security\"><strong>fkie-cad/awesome-embedded-and-iot-security</strong></a></li>\n<li><a href=\"https://github.com/bakke92/awesome-gdpr\"><strong>bakke92/awesome-gdpr</strong></a></li>\n<li><a href=\"https://github.com/TaptuIT/awesome-devsecops\"><strong>TaptuIT/awesome-devsecops</strong></a></li>\n<li><a href=\"https://github.com/umbraco-community/awesome-umbraco\"><strong>umbraco-community/awesome-umbraco</strong></a></li>\n<li><a href=\"https://github.com/refinerycms-contrib/awesome-refinerycms\"><strong>refinerycms-contrib/awesome-refinerycms</strong></a></li>\n<li><a href=\"https://github.com/springload/awesome-wagtail\"><strong>springload/awesome-wagtail</strong></a></li>\n<li><a href=\"https://github.com/drmonkeyninja/awesome-textpattern\"><strong>drmonkeyninja/awesome-textpattern</strong></a></li>\n<li><a href=\"https://github.com/nirgn975/awesome-drupal\"><strong>nirgn975/awesome-drupal</strong></a></li>\n<li><a href=\"https://github.com/craftcms/awesome\"><strong>craftcms/awesome</strong></a></li>\n<li><a href=\"https://github.com/MartinMiles/Awesome-Sitecore\"><strong>MartinMiles/Awesome-Sitecore</strong></a></li>\n<li><a href=\"https://github.com/wernerkrauss/awesome-silverstripe-cms\"><strong>wernerkrauss/awesome-silverstripe-cms</strong></a></li>\n<li><a href=\"https://github.com/Kiloreux/awesome-robotics\"><strong>Kiloreux/awesome-robotics</strong></a></li>\n<li><a href=\"https://github.com/HQarroum/awesome-iot\"><strong>HQarroum/awesome-iot</strong></a></li>\n<li><a href=\"https://github.com/kitspace/awesome-electronics\"><strong>kitspace/awesome-electronics</strong></a></li>\n<li><a href=\"https://github.com/rabschi/awesome-beacon\"><strong>rabschi/awesome-beacon</strong></a></li>\n<li><a href=\"https://github.com/gitfrage/guitarspecs\"><strong>gitfrage/guitarspecs</strong></a></li>\n<li><a href=\"https://github.com/beardicus/awesome-plotters\"><strong>beardicus/awesome-plotters</strong></a></li>\n<li><a href=\"https://github.com/protontypes/awesome-robotic-tooling\"><strong>protontypes/awesome-robotic-tooling</strong></a></li>\n<li><a href=\"https://github.com/szenergy/awesome-lidar\"><strong>szenergy/awesome-lidar</strong></a></li>\n<li><a href=\"https://github.com/opencompany/awesome-open-company\"><strong>opencompany/awesome-open-company</strong></a></li>\n<li><a href=\"https://github.com/mmccaff/PlacesToPostYourStartup\"><strong>mmccaff/PlacesToPostYourStartup</strong></a></li>\n<li><a href=\"https://github.com/domenicosolazzo/awesome-okr\"><strong>domenicosolazzo/awesome-okr</strong></a></li>\n<li><a href=\"https://github.com/LappleApple/awesome-leading-and-managing\"><strong>LappleApple/awesome-leading-and-managing</strong></a></li>\n<li><a href=\"https://github.com/mezod/awesome-indie\"><strong>mezod/awesome-indie</strong></a></li>\n<li><a href=\"https://github.com/cjbarber/ToolsOfTheTrade\"><strong>cjbarber/ToolsOfTheTrade</strong></a></li>\n<li><a href=\"https://github.com/nglgzz/awesome-clean-tech\"><strong>nglgzz/awesome-clean-tech</strong></a></li>\n<li><a href=\"https://github.com/wardley-maps-community/awesome-wardley-maps\"><strong>wardley-maps-community/awesome-wardley-maps</strong></a></li>\n<li><a href=\"https://github.com/RayBB/awesome-social-enterprise\"><strong>RayBB/awesome-social-enterprise</strong></a></li>\n<li><a href=\"https://github.com/kdeldycke/awesome-engineering-team-management\"><strong>kdeldycke/awesome-engineering-team-management</strong></a></li>\n<li><a href=\"https://github.com/agamm/awesome-developer-first\"><strong>agamm/awesome-developer-first</strong></a></li>\n<li><a href=\"https://github.com/kdeldycke/awesome-billing\"><strong>kdeldycke/awesome-billing</strong></a></li>\n<li><a href=\"https://github.com/matiassingers/awesome-slack\"><strong>matiassingers/awesome-slack</strong></a></li>\n<li><a href=\"https://github.com/filipelinhares/awesome-slack\"><strong>filipelinhares/awesome-slack</strong></a></li>\n<li><a href=\"https://github.com/lukasz-madon/awesome-remote-job\"><strong>lukasz-madon/awesome-remote-job</strong></a></li>\n<li><a href=\"https://github.com/jyguyomarch/awesome-productivity\"><strong>jyguyomarch/awesome-productivity</strong></a></li>\n<li><a href=\"https://github.com/tramcar/awesome-job-boards\"><strong>tramcar/awesome-job-boards</strong></a></li>\n<li><a href=\"https://github.com/DopplerHQ/awesome-interview-questions\"><strong>DopplerHQ/awesome-interview-questions</strong></a></li>\n<li><a href=\"https://github.com/joho/awesome-code-review\"><strong>joho/awesome-code-review</strong></a></li>\n<li><a href=\"https://github.com/j0hnm4r5/awesome-creative-technology\"><strong>j0hnm4r5/awesome-creative-technology</strong></a></li>\n<li><a href=\"https://github.com/lodthe/awesome-internships\"><strong>lodthe/awesome-internships</strong></a></li>\n<li><a href=\"https://github.com/sdnds-tw/awesome-sdn\"><strong>sdnds-tw/awesome-sdn</strong></a></li>\n<li><a href=\"https://github.com/briatte/awesome-network-analysis\"><strong>briatte/awesome-network-analysis</strong></a></li>\n<li><a href=\"https://github.com/caesar0301/awesome-pcaptools\"><strong>caesar0301/awesome-pcaptools</strong></a></li>\n<li><a href=\"https://github.com/rtckit/awesome-rtc\"><strong>rtckit/awesome-rtc</strong></a></li>\n<li><a href=\"https://github.com/igorbarinov/awesome-bitcoin\"><strong>igorbarinov/awesome-bitcoin</strong></a></li>\n<li><a href=\"https://github.com/vhpoet/awesome-ripple\"><strong>vhpoet/awesome-ripple</strong></a></li>\n<li><a href=\"https://github.com/machinomy/awesome-non-financial-blockchain\"><strong>machinomy/awesome-non-financial-blockchain</strong></a></li>\n<li><a href=\"https://github.com/tleb/awesome-mastodon\"><strong>tleb/awesome-mastodon</strong></a></li>\n<li><a href=\"https://github.com/ttumiel/Awesome-Ethereum\"><strong>ttumiel/Awesome-Ethereum</strong></a></li>\n<li><a href=\"https://github.com/steven2358/awesome-blockchain-ai\"><strong>steven2358/awesome-blockchain-ai</strong></a></li>\n<li><a href=\"https://github.com/DanailMinchev/awesome-eosio\"><strong>DanailMinchev/awesome-eosio</strong></a></li>\n<li><a href=\"https://github.com/chainstack/awesome-corda\"><strong>chainstack/awesome-corda</strong></a></li>\n<li><a href=\"https://github.com/msmolyakov/awesome-waves\"><strong>msmolyakov/awesome-waves</strong></a></li>\n<li><a href=\"https://github.com/substrate-developer-hub/awesome-substrate\"><strong>substrate-developer-hub/awesome-substrate</strong></a></li>\n<li><a href=\"https://github.com/golemfactory/awesome-golem\"><strong>golemfactory/awesome-golem</strong></a></li>\n<li><a href=\"https://github.com/friedger/awesome-stacks-chain\"><strong>friedger/awesome-stacks-chain</strong></a></li>\n<li><a href=\"https://github.com/eselkin/awesome-computational-neuroscience\"><strong>eselkin/awesome-computational-neuroscience</strong></a></li>\n<li><a href=\"https://github.com/maehr/awesome-digital-history\"><strong>maehr/awesome-digital-history</strong></a></li>\n<li><a href=\"https://github.com/writing-resources/awesome-scientific-writing\"><strong>writing-resources/awesome-scientific-writing</strong></a></li>\n<li><a href=\"https://github.com/danvoyce/awesome-creative-tech-events\"><strong>danvoyce/awesome-creative-tech-events</strong></a></li>\n<li><a href=\"https://github.com/ildoc/awesome-italy-events\"><strong>ildoc/awesome-italy-events</strong></a></li>\n<li><a href=\"https://github.com/awkward/awesome-netherlands-events\"><strong>awkward/awesome-netherlands-events</strong></a></li>\n<li><a href=\"https://github.com/TheJambo/awesome-testing\"><strong>TheJambo/awesome-testing</strong></a></li>\n<li><a href=\"https://github.com/mojoaxel/awesome-regression-testing\"><strong>mojoaxel/awesome-regression-testing</strong></a></li>\n<li><a href=\"https://github.com/christian-bromann/awesome-selenium\"><strong>christian-bromann/awesome-selenium</strong></a></li>\n<li><a href=\"https://github.com/SrinivasanTarget/awesome-appium\"><strong>SrinivasanTarget/awesome-appium</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome-tap\"><strong>sindresorhus/awesome-tap</strong></a></li>\n<li><a href=\"https://github.com/aliesbelik/awesome-jmeter\"><strong>aliesbelik/awesome-jmeter</strong></a></li>\n<li><a href=\"https://github.com/k6io/awesome-k6\"><strong>k6io/awesome-k6</strong></a></li>\n<li><a href=\"https://github.com/mxschmitt/awesome-playwright\"><strong>mxschmitt/awesome-playwright</strong></a></li>\n<li><a href=\"https://github.com/fityanos/awesome-quality-assurance-roadmap\"><strong>fityanos/awesome-quality-assurance-roadmap</strong></a></li>\n<li><a href=\"https://github.com/burningtree/awesome-json\"><strong>burningtree/awesome-json</strong></a></li>\n<li><a href=\"https://github.com/tmcw/awesome-geojson\"><strong>tmcw/awesome-geojson</strong></a></li>\n<li><a href=\"https://github.com/jdorfman/awesome-json-datasets\"><strong>jdorfman/awesome-json-datasets</strong></a></li>\n<li><a href=\"https://github.com/secretGeek/awesomeCSV\"><strong>secretGeek/awesomeCSV</strong></a></li>\n<li><a href=\"https://github.com/AchoArnold/discount-for-student-dev\"><strong>AchoArnold/discount-for-student-dev</strong></a></li>\n<li><a href=\"https://github.com/kyleterry/awesome-radio\"><strong>kyleterry/awesome-radio</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome\"><strong>sindresorhus/awesome</strong></a></li>\n<li><a href=\"https://github.com/onurakpolat/awesome-analytics\"><strong>onurakpolat/awesome-analytics</strong></a></li>\n<li><a href=\"https://github.com/marmelab/awesome-rest\"><strong>marmelab/awesome-rest</strong></a></li>\n<li><a href=\"https://github.com/cicdops/awesome-ciandcd\"><strong>cicdops/awesome-ciandcd</strong></a></li>\n<li><a href=\"https://github.com/mmcgrana/services-engineering\"><strong>mmcgrana/services-engineering</strong></a></li>\n<li><a href=\"https://github.com/ripienaar/free-for-dev\"><strong>ripienaar/free-for-dev</strong></a></li>\n<li><a href=\"https://github.com/cyberglot/awesome-answers\"><strong>cyberglot/awesome-answers</strong></a></li>\n<li><a href=\"https://github.com/diessica/awesome-sketch\"><strong>diessica/awesome-sketch</strong></a></li>\n<li><a href=\"https://github.com/melvin0008/awesome-projects-boilerplates\"><strong>melvin0008/awesome-projects-boilerplates</strong></a></li>\n<li><a href=\"https://github.com/matiassingers/awesome-readme\"><strong>matiassingers/awesome-readme</strong></a></li>\n<li><a href=\"https://github.com/NARKOZ/guides\"><strong>NARKOZ/guides</strong></a></li>\n<li><a href=\"https://github.com/kilimchoi/engineering-blogs\"><strong>kilimchoi/engineering-blogs</strong></a></li>\n<li><a href=\"https://github.com/awesome-selfhosted/awesome-selfhosted\"><strong>awesome-selfhosted/awesome-selfhosted</strong></a></li>\n<li><a href=\"https://github.com/DataDaoDe/awesome-foss-apps\"><strong>DataDaoDe/awesome-foss-apps</strong></a></li>\n<li><a href=\"https://github.com/alferov/awesome-gulp\"><strong>alferov/awesome-gulp</strong></a></li>\n<li><a href=\"https://github.com/sindresorhus/amas\"><strong>sindresorhus/amas</strong></a></li>\n<li><a href=\"https://github.com/stoeffel/awesome-ama-answers\"><strong>stoeffel/awesome-ama-answers</strong></a></li>\n<li><a href=\"https://github.com/ibaaj/awesome-OpenSourcePhotography\"><strong>ibaaj/awesome-OpenSourcePhotography</strong></a></li>\n<li><a href=\"https://github.com/eug/awesome-opengl\"><strong>eug/awesome-opengl</strong></a></li>\n<li><a href=\"https://github.com/chentsulin/awesome-graphql\"><strong>chentsulin/awesome-graphql</strong></a></li>\n<li><a href=\"https://github.com/APA-Technology-Division/urban-and-regional-planning-resources\"><strong>APA-Technology-Division/urban-and-regional-planning-resources</strong></a></li>\n<li><a href=\"https://github.com/CUTR-at-USF/awesome-transit\"><strong>CUTR-at-USF/awesome-transit</strong></a></li>\n<li><a href=\"https://github.com/emptymalei/awesome-research\"><strong>emptymalei/awesome-research</strong></a></li>\n<li><a href=\"https://github.com/fasouto/awesome-dataviz\"><strong>fasouto/awesome-dataviz</strong></a></li>\n<li><a href=\"https://github.com/vinkla/shareable-links\"><strong>vinkla/shareable-links</strong></a></li>\n<li><a href=\"https://github.com/mfornos/awesome-microservices\"><strong>mfornos/awesome-microservices</strong></a></li>\n<li><a href=\"https://github.com/jagracey/Awesome-Unicode\"><strong>jagracey/Awesome-Unicode</strong></a></li>\n<li><a href=\"https://github.com/Codepoints/awesome-codepoints\"><strong>Codepoints/awesome-codepoints</strong></a></li>\n<li><a href=\"https://github.com/MunGell/awesome-for-beginners\"><strong>MunGell/awesome-for-beginners</strong></a></li>\n<li><a href=\"https://github.com/gamontal/awesome-katas\"><strong>gamontal/awesome-katas</strong></a></li>\n<li><a href=\"https://github.com/drewrwilson/toolsforactivism\"><strong>drewrwilson/toolsforactivism</strong></a></li>\n<li><a href=\"https://github.com/dylanrees/citizen-science\"><strong>dylanrees/citizen-science</strong></a></li>\n<li><a href=\"https://github.com/hobbyquaker/awesome-mqtt\"><strong>hobbyquaker/awesome-mqtt</strong></a></li>\n<li><a href=\"https://github.com/daviddias/awesome-hacking-locations\"><strong>daviddias/awesome-hacking-locations</strong></a></li>\n<li><a href=\"https://github.com/cristianoliveira/awesome4girls\"><strong>cristianoliveira/awesome4girls</strong></a></li>\n<li><a href=\"https://github.com/vorpaljs/awesome-vorpal\"><strong>vorpaljs/awesome-vorpal</strong></a></li>\n<li><a href=\"https://github.com/vinjn/awesome-vulkan\"><strong>vinjn/awesome-vulkan</strong></a></li>\n<li><a href=\"https://github.com/egeerardyn/awesome-LaTeX\"><strong>egeerardyn/awesome-LaTeX</strong></a></li>\n<li><a href=\"https://github.com/antontarasenko/awesome-economics\"><strong>antontarasenko/awesome-economics</strong></a></li>\n<li><a href=\"https://github.com/sublimino/awesome-funny-markov\"><strong>sublimino/awesome-funny-markov</strong></a></li>\n<li><a href=\"https://github.com/danielecook/Awesome-Bioinformatics\"><strong>danielecook/Awesome-Bioinformatics</strong></a></li>\n<li><a href=\"https://github.com/hsiaoyi0504/awesome-cheminformatics\"><strong>hsiaoyi0504/awesome-cheminformatics</strong></a></li>\n<li><a href=\"https://github.com/Siddharth11/Colorful\"><strong>Siddharth11/Colorful</strong></a></li>\n<li><a href=\"https://github.com/scholtzm/awesome-steam\"><strong>scholtzm/awesome-steam</strong></a></li>\n<li><a href=\"https://github.com/hackerkid/bots\"><strong>hackerkid/bots</strong></a></li>\n<li><a href=\"https://github.com/dastergon/awesome-sre\"><strong>dastergon/awesome-sre</strong></a></li>\n<li><a href=\"https://github.com/KimberlyMunoz/empathy-in-engineering\"><strong>KimberlyMunoz/empathy-in-engineering</strong></a></li>\n<li><a href=\"https://github.com/xen0l/awesome-dtrace\"><strong>xen0l/awesome-dtrace</strong></a></li>\n<li><a href=\"https://github.com/bvolpato/awesome-userscripts\"><strong>bvolpato/awesome-userscripts</strong></a></li>\n<li><a href=\"https://github.com/tobiasbueschel/awesome-pokemon\"><strong>tobiasbueschel/awesome-pokemon</strong></a></li>\n<li><a href=\"https://github.com/exAspArk/awesome-chatops\"><strong>exAspArk/awesome-chatops</strong></a></li>\n<li><a href=\"https://github.com/kdeldycke/awesome-falsehood\"><strong>kdeldycke/awesome-falsehood</strong></a></li>\n<li><a href=\"https://github.com/heynickc/awesome-ddd\"><strong>heynickc/awesome-ddd</strong></a></li>\n<li><a href=\"https://github.com/woop/awesome-quantified-self\"><strong>woop/awesome-quantified-self</strong></a></li>\n<li><a href=\"https://github.com/hbokh/awesome-saltstack\"><strong>hbokh/awesome-saltstack</strong></a></li>\n<li><a href=\"https://github.com/nicolesaidy/awesome-web-design\"><strong>nicolesaidy/awesome-web-design</strong></a></li>\n<li><a href=\"https://github.com/terkelg/awesome-creative-coding\"><strong>terkelg/awesome-creative-coding</strong></a></li>\n<li><a href=\"https://github.com/aviaryan/awesome-no-login-web-apps\"><strong>aviaryan/awesome-no-login-web-apps</strong></a></li>\n<li><a href=\"https://github.com/johnjago/awesome-free-software\"><strong>johnjago/awesome-free-software</strong></a></li>\n<li><a href=\"https://github.com/podo/awesome-framer\"><strong>podo/awesome-framer</strong></a></li>\n<li><a href=\"https://github.com/BubuAnabelas/awesome-markdown\"><strong>BubuAnabelas/awesome-markdown</strong></a></li>\n<li><a href=\"https://github.com/mislavcimpersak/awesome-dev-fun\"><strong>mislavcimpersak/awesome-dev-fun</strong></a></li>\n<li><a href=\"https://github.com/kakoni/awesome-healthcare\"><strong>kakoni/awesome-healthcare</strong></a></li>\n<li><a href=\"https://github.com/DavidLambauer/awesome-magento2\"><strong>DavidLambauer/awesome-magento2</strong></a></li>\n<li><a href=\"https://github.com/xiaohanyu/awesome-tikz\"><strong>xiaohanyu/awesome-tikz</strong></a></li>\n<li><a href=\"https://github.com/analyticalmonk/awesome-neuroscience\"><strong>analyticalmonk/awesome-neuroscience</strong></a></li>\n<li><a href=\"https://github.com/johnjago/awesome-ad-free\"><strong>johnjago/awesome-ad-free</strong></a></li>\n<li><a href=\"https://github.com/angrykoala/awesome-esolangs\"><strong>angrykoala/awesome-esolangs</strong></a></li>\n<li><a href=\"https://github.com/roaldnefs/awesome-prometheus\"><strong>roaldnefs/awesome-prometheus</strong></a></li>\n<li><a href=\"https://github.com/homematic-community/awesome-homematic\"><strong>homematic-community/awesome-homematic</strong></a></li>\n<li><a href=\"https://github.com/sfischer13/awesome-ledger\"><strong>sfischer13/awesome-ledger</strong></a></li>\n<li><a href=\"https://github.com/thomasbnt/awesome-web-monetization\"><strong>thomasbnt/awesome-web-monetization</strong></a></li>\n<li><a href=\"https://github.com/johnjago/awesome-uncopyright\"><strong>johnjago/awesome-uncopyright</strong></a></li>\n<li><a href=\"https://github.com/Zheaoli/awesome-coins\"><strong>Zheaoli/awesome-coins</strong></a></li>\n<li><a href=\"https://github.com/folkswhocode/awesome-diversity\"><strong>folkswhocode/awesome-diversity</strong></a></li>\n<li><a href=\"https://github.com/zachflower/awesome-open-source-supporters\"><strong>zachflower/awesome-open-source-supporters</strong></a></li>\n<li><a href=\"https://github.com/robinstickel/awesome-design-principles\"><strong>robinstickel/awesome-design-principles</strong></a></li>\n<li><a href=\"https://github.com/johnjago/awesome-theravada\"><strong>johnjago/awesome-theravada</strong></a></li>\n<li><a href=\"https://github.com/inspectit-labs/awesome-inspectit\"><strong>inspectit-labs/awesome-inspectit</strong></a></li>\n<li><a href=\"https://github.com/nayafia/awesome-maintainers\"><strong>nayafia/awesome-maintainers</strong></a></li>\n<li><a href=\"https://github.com/xxczaki/awesome-calculators\"><strong>xxczaki/awesome-calculators</strong></a></li>\n<li><a href=\"https://github.com/ZYSzys/awesome-captcha\"><strong>ZYSzys/awesome-captcha</strong></a></li>\n<li><a href=\"https://github.com/markusschanta/awesome-jupyter\"><strong>markusschanta/awesome-jupyter</strong></a></li>\n<li><a href=\"https://github.com/andrewda/awesome-frc\"><strong>andrewda/awesome-frc</strong></a></li>\n<li><a href=\"https://github.com/humanetech-community/awesome-humane-tech\"><strong>humanetech-community/awesome-humane-tech</strong></a></li>\n<li><a href=\"https://github.com/karlhorky/awesome-speakers\"><strong>karlhorky/awesome-speakers</strong></a></li>\n<li><a href=\"https://github.com/edm00se/awesome-board-games\"><strong>edm00se/awesome-board-games</strong></a></li>\n<li><a href=\"https://github.com/uraimo/awesome-software-patreons\"><strong>uraimo/awesome-software-patreons</strong></a></li>\n<li><a href=\"https://github.com/ecohealthalliance/awesome-parasite\"><strong>ecohealthalliance/awesome-parasite</strong></a></li>\n<li><a href=\"https://github.com/jzarca01/awesome-food\"><strong>jzarca01/awesome-food</strong></a></li>\n<li><a href=\"https://github.com/dreamingechoes/awesome-mental-health\"><strong>dreamingechoes/awesome-mental-health</strong></a></li>\n<li><a href=\"https://github.com/alexk111/awesome-bitcoin-payment-processors\"><strong>alexk111/awesome-bitcoin-payment-processors</strong></a></li>\n<li><a href=\"https://github.com/nschloe/awesome-scientific-computing\"><strong>nschloe/awesome-scientific-computing</strong></a></li>\n<li><a href=\"https://github.com/ScaleLeap/awesome-amazon-seller\"><strong>ScaleLeap/awesome-amazon-seller</strong></a></li>\n<li><a href=\"https://github.com/brycejohnston/awesome-agriculture\"><strong>brycejohnston/awesome-agriculture</strong></a></li>\n<li><a href=\"https://github.com/matttga/awesome-product-design\"><strong>matttga/awesome-product-design</strong></a></li>\n<li><a href=\"https://github.com/catalinmiron/awesome-prisma\"><strong>catalinmiron/awesome-prisma</strong></a></li>\n<li><a href=\"https://github.com/simskij/awesome-software-architecture\"><strong>simskij/awesome-software-architecture</strong></a></li>\n<li><a href=\"https://github.com/stevesong/awesome-connectivity-info\"><strong>stevesong/awesome-connectivity-info</strong></a></li>\n<li><a href=\"https://github.com/stackshareio/awesome-stacks\"><strong>stackshareio/awesome-stacks</strong></a></li>\n<li><a href=\"https://github.com/cytodata/awesome-cytodata\"><strong>cytodata/awesome-cytodata</strong></a></li>\n<li><a href=\"https://github.com/davisonio/awesome-irc\"><strong>davisonio/awesome-irc</strong></a></li>\n<li><a href=\"https://github.com/cenoura/awesome-ads\"><strong>cenoura/awesome-ads</strong></a></li>\n<li><a href=\"https://github.com/philsturgeon/awesome-earth\"><strong>philsturgeon/awesome-earth</strong></a></li>\n<li><a href=\"https://github.com/gruhn/awesome-naming\"><strong>gruhn/awesome-naming</strong></a></li>\n<li><a href=\"https://github.com/caufieldjh/awesome-bioie\"><strong>caufieldjh/awesome-bioie</strong></a></li>\n<li><a href=\"https://github.com/iipc/awesome-web-archiving\"><strong>iipc/awesome-web-archiving</strong></a></li>\n<li><a href=\"https://github.com/schlessera/awesome-wp-cli\"><strong>schlessera/awesome-wp-cli</strong></a></li>\n<li><a href=\"https://github.com/mourarthur/awesome-credit-modeling\"><strong>mourarthur/awesome-credit-modeling</strong></a></li>\n<li><a href=\"https://github.com/KeyboardInterrupt/awesome-ansible\"><strong>KeyboardInterrupt/awesome-ansible</strong></a></li>\n<li><a href=\"https://github.com/keller-mark/awesome-biological-visualizations\"><strong>keller-mark/awesome-biological-visualizations</strong></a></li>\n<li><a href=\"https://github.com/aureooms/awesome-qr-code\"><strong>aureooms/awesome-qr-code</strong></a></li>\n<li><a href=\"https://github.com/sdassow/awesome-veganism\"><strong>sdassow/awesome-veganism</strong></a></li>\n<li><a href=\"https://github.com/mbiesiad/awesome-translations\"><strong>mbiesiad/awesome-translations</strong></a></li>\n<li><a href=\"https://github.com/dersvenhesse/awesome-scriptable\"><strong>dersvenhesse/awesome-scriptable</strong></a></li>\n<li><a href=\"https://github.com/topics/awesome\"><strong>topics/awesome</strong></a></li>\n<li><a href=\"https://awesome-indexed.mathew-davies.co.uk\"><strong>https://awesome-indexed.mathew-davies.co.uk</strong></a></li>\n<li><a href=\"https://awesomelists.top\"><strong>https://awesomelists.top</strong></a></li>\n<li><a href=\"https://github.com/basharovV/StumbleUponAwesome\"><strong>basharovV/StumbleUponAwesome</strong></a></li>\n<li><a href=\"https://github.com/umutphp/awesome-cli\"><strong>umutphp/awesome-cli</strong></a></li>\n<li><a href=\"http://awesome.digitalbunker.dev\"><strong>http://awesome.digitalbunker.dev</strong></a></li>\n<li><a href=\"https://www.trackawesomelist.com\"><strong>https://www.trackawesomelist.com</strong></a></li>\n</ul>"},{"url":"/docs/python/comprehensive-guide/","relativePath":"docs/python/comprehensive-guide.md","relativeDir":"docs/python","base":"comprehensive-guide.md","name":"comprehensive-guide","frontmatter":{"title":"Comprehensive Python Guide","weight":0,"excerpt":"Pythons design into 20 aphorisms, only 19 of which have been written down.","seo":{"title":"Comprehensive Python Guide","description":"Pythons design into 20 aphorisms, only 19 of which have been written down.","robots":[],"extra":[]},"template":"docs"},"html":"<h2>Comprehensive Python Guide</h2>\n<ul>\n<li><a href=\"#comprehensive-python-guide\">Comprehensive Python Guide</a></li>\n<li><a href=\"#the-zen-of-python\">The Zen of Python</a></li>\n<li>\n<p><a href=\"#python-basics\">Python Basics</a></p>\n<ul>\n<li><a href=\"#math-operators\">Math Operators</a></li>\n<li><a href=\"#data-types\">Data Types</a></li>\n<li><a href=\"#string-concatenation-and-replication\">String Concatenation and Replication</a></li>\n<li><a href=\"#variables\">Variables</a></li>\n<li><a href=\"#comments\">Comments</a></li>\n<li><a href=\"#the-print-function\">The print() Function</a></li>\n<li><a href=\"#the-input-function\">The input() Function</a></li>\n<li><a href=\"#the-len-function\">The len() Function</a></li>\n<li><a href=\"#the-str-int-and-float-functions\">The str(), int(), and float() Functions</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#flow-control\">Flow Control</a></p>\n<ul>\n<li><a href=\"#comparison-operators\">Comparison Operators</a></li>\n<li><a href=\"#boolean-evaluation\">Boolean evaluation</a></li>\n<li><a href=\"#boolean-operators\">Boolean Operators</a></li>\n<li><a href=\"#mixing-boolean-and-comparison-operators\">Mixing Boolean and Comparison Operators</a></li>\n<li><a href=\"#if-statements\">if Statements</a></li>\n<li><a href=\"#else-statements\">else Statements</a></li>\n<li><a href=\"#elif-statements\">elif Statements</a></li>\n<li><a href=\"#while-loop-statements\">while Loop Statements</a></li>\n<li><a href=\"#break-statements\">break Statements</a></li>\n<li><a href=\"#continue-statements\">continue Statements</a></li>\n<li><a href=\"#for-loops-and-the-range-function\">for Loops and the range() Function</a></li>\n<li><a href=\"#for-else-statement\">For else statement</a></li>\n<li><a href=\"#importing-modules\">Importing Modules</a></li>\n<li><a href=\"#ending-a-program-early-with-sysexit\">Ending a Program Early with sys.exit()</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#functions\">Functions</a></p>\n<ul>\n<li><a href=\"#return-values-and-return-statements\">Return Values and return Statements</a></li>\n<li><a href=\"#the-none-value\">The None Value</a></li>\n<li><a href=\"#keyword-arguments-and-print\">Keyword Arguments and print()</a></li>\n<li><a href=\"#local-and-global-scope\">Local and Global Scope</a></li>\n<li><a href=\"#the-global-statement\">The global Statement</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#exception-handling\">Exception Handling</a></p>\n<ul>\n<li><a href=\"#basic-exception-handling\">Basic exception handling</a></li>\n<li><a href=\"#final-code-in-exception-handling\">Final code in exception handling</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#lists\">Lists</a></p>\n<ul>\n<li><a href=\"#getting-individual-values-in-a-list-with-indexes\">Getting Individual Values in a List with Indexes</a></li>\n<li><a href=\"#negative-indexes\">Negative Indexes</a></li>\n<li><a href=\"#getting-sublists-with-slices\">Getting Sublists with Slices</a></li>\n<li><a href=\"#getting-a-lists-length-with-len\">Getting a List's Length with len()</a></li>\n<li><a href=\"#changing-values-in-a-list-with-indexes\">Changing Values in a List with Indexes</a></li>\n<li><a href=\"#list-concatenation-and-list-replication\">List Concatenation and List Replication</a></li>\n<li><a href=\"#removing-values-from-lists-with-del-statements\">Removing Values from Lists with del Statements</a></li>\n<li><a href=\"#using-for-loops-with-lists\">Using for Loops with Lists</a></li>\n<li><a href=\"#looping-through-multiple-lists-with-zip\">Looping Through Multiple Lists with zip()</a></li>\n<li><a href=\"#the-in-and-not-in-operators\">The in and not in Operators</a></li>\n<li><a href=\"#the-multiple-assignment-trick\">The Multiple Assignment Trick</a></li>\n<li><a href=\"#augmented-assignment-operators\">Augmented Assignment Operators</a></li>\n<li><a href=\"#finding-a-value-in-a-list-with-the-index-method\">Finding a Value in a List with the index() Method</a></li>\n<li><a href=\"#adding-values-to-lists-with-the-append-and-insert-methods\">Adding Values to Lists with the append() and insert() Methods</a></li>\n<li><a href=\"#removing-values-from-lists-with-remove\">Removing Values from Lists with remove()</a></li>\n<li><a href=\"#removing-values-from-lists-with-pop\">Removing Values from Lists with pop()</a></li>\n<li><a href=\"#sorting-the-values-in-a-list-with-the-sort-method\">Sorting the Values in a List with the sort() Method</a></li>\n<li><a href=\"#tuple-data-type\">Tuple Data Type</a></li>\n<li><a href=\"#converting-types-with-the-list-and-tuple-functions\">Converting Types with the list() and tuple() Functions</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#dictionaries-and-structuring-data\">Dictionaries and Structuring Data</a></p>\n<ul>\n<li><a href=\"#the-keys-values-and-items-methods\">The keys(), values(), and items() Methods</a></li>\n<li><a href=\"#checking-whether-a-key-or-value-exists-in-a-dictionary\">Checking Whether a Key or Value Exists in a Dictionary</a></li>\n<li><a href=\"#the-get-method\">The get() Method</a></li>\n<li><a href=\"#the-setdefault-method\">The setdefault() Method</a></li>\n<li><a href=\"#pretty-printing\">Pretty Printing</a></li>\n<li><a href=\"#merge-two-dictionaries\">Merge two dictionaries</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#sets\">sets</a></p>\n<ul>\n<li><a href=\"#initializing-a-set\">Initializing a set</a></li>\n<li><a href=\"#sets-unordered-collections-of-unique-elements\">sets: unordered collections of unique elements</a></li>\n<li><a href=\"#set-add-and-update\">set add() and update()</a></li>\n<li><a href=\"#set-remove-and-discard\">set remove() and discard()</a></li>\n<li><a href=\"#set-union\">set union()</a></li>\n<li><a href=\"#set-intersection\">set intersection</a></li>\n<li><a href=\"#set-difference\">set difference</a></li>\n<li><a href=\"#set-symetric_difference\">set symetric_difference</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#itertools-module\">itertools Module</a></p>\n<ul>\n<li><a href=\"#accumulate\">accumulate()</a></li>\n<li><a href=\"#combinations\">combinations()</a></li>\n<li><a href=\"#combinations_with_replacement\">combinations<em>with</em>replacement()</a></li>\n<li><a href=\"#count\">count()</a></li>\n<li><a href=\"#cycle\">cycle()</a></li>\n<li><a href=\"#chain\">chain()</a></li>\n<li><a href=\"#compress\">compress()</a></li>\n<li><a href=\"#dropwhile\">dropwhile()</a></li>\n<li><a href=\"#filterfalse\">filterfalse()</a></li>\n<li><a href=\"#groupby\">groupby()</a></li>\n<li><a href=\"#islice\">islice()</a></li>\n<li><a href=\"#permutations\">permutations()</a></li>\n<li><a href=\"#product\">product()</a></li>\n<li><a href=\"#repeat\">repeat()</a></li>\n<li><a href=\"#starmap\">starmap()</a></li>\n<li><a href=\"#takewhile\">takewhile()</a></li>\n<li><a href=\"#tee\">tee()</a></li>\n<li><a href=\"#zip_longest\">zip_longest()</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#comprehensions\">Comprehensions</a></p>\n<ul>\n<li><a href=\"#list-comprehension\">List comprehension</a></li>\n<li><a href=\"#set-comprehension\">Set comprehension</a></li>\n<li><a href=\"#dict-comprehension\">Dict comprehension</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#manipulating-strings\">Manipulating Strings</a></p>\n<ul>\n<li><a href=\"#escape-characters\">Escape Characters</a></li>\n<li><a href=\"#raw-strings\">Raw Strings</a></li>\n<li><a href=\"#multiline-strings-with-triple-quotes\">Multiline Strings with Triple Quotes</a></li>\n<li><a href=\"#indexing-and-slicing-strings\">Indexing and Slicing Strings</a></li>\n<li><a href=\"#the-in-and-not-in-operators-with-strings\">The in and not in Operators with Strings</a></li>\n<li><a href=\"#the-in-and-not-in-operators-with-list\">The in and not in Operators with list</a></li>\n<li><a href=\"#the-upper-lower-isupper-and-islower-string-methods\">The upper(), lower(), isupper(), and islower() String Methods</a></li>\n<li><a href=\"#the-isx-string-methods\">The isX String Methods</a></li>\n<li><a href=\"#the-startswith-and-endswith-string-methods\">The startswith() and endswith() String Methods</a></li>\n<li><a href=\"#the-join-and-split-string-methods\">The join() and split() String Methods</a></li>\n<li><a href=\"#justifying-text-with-rjust-ljust-and-center\">Justifying Text with rjust(), ljust(), and center()</a></li>\n<li><a href=\"#removing-whitespace-with-strip-rstrip-and-lstrip\">Removing Whitespace with strip(), rstrip(), and lstrip()</a></li>\n<li><a href=\"#copying-and-pasting-strings-with-the-pyperclip-module-need-pip-install\">Copying and Pasting Strings with the pyperclip Module (need pip install)</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#string-formatting\">String Formatting</a></p>\n<ul>\n<li><a href=\"#-operator\">% operator</a></li>\n<li><a href=\"#string-formatting-strformat\">String Formatting (str.format)</a></li>\n<li><a href=\"#lazy-string-formatting\">Lazy string formatting</a></li>\n<li><a href=\"#formatted-string-literals-or-f-strings-python-36\">Formatted String Literals or f-strings (Python 3.6+)</a></li>\n<li><a href=\"#template-strings\">Template Strings</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#regular-expressions\">Regular Expressions</a></p>\n<ul>\n<li><a href=\"#matching-regex-objects\">Matching Regex Objects</a></li>\n<li><a href=\"#grouping-with-parentheses\">Grouping with Parentheses</a></li>\n<li><a href=\"#matching-multiple-groups-with-the-pipe\">Matching Multiple Groups with the Pipe</a></li>\n<li><a href=\"#optional-matching-with-the-question-mark\">Optional Matching with the Question Mark</a></li>\n<li><a href=\"#matching-zero-or-more-with-the-star\">Matching Zero or More with the Star</a></li>\n<li><a href=\"#matching-one-or-more-with-the-plus\">Matching One or More with the Plus</a></li>\n<li><a href=\"#matching-specific-repetitions-with-curly-brackets\">Matching Specific Repetitions with Curly Brackets</a></li>\n<li><a href=\"#greedy-and-nongreedy-matching\">Greedy and Nongreedy Matching</a></li>\n<li><a href=\"#the-findall-method\">The findall() Method</a></li>\n<li><a href=\"#making-your-own-character-classes\">Making Your Own Character Classes</a></li>\n<li><a href=\"#the-caret-and-dollar-sign-characters\">The Caret and Dollar Sign Characters</a></li>\n<li><a href=\"#the-wildcard-character\">The Wildcard Character</a></li>\n<li><a href=\"#matching-everything-with-dot-star\">Matching Everything with Dot-Star</a></li>\n<li><a href=\"#matching-newlines-with-the-dot-character\">Matching Newlines with the Dot Character</a></li>\n<li><a href=\"#review-of-regex-symbols\">Review of Regex Symbols</a></li>\n<li><a href=\"#case-insensitive-matching\">Case-Insensitive Matching</a></li>\n<li><a href=\"#substituting-strings-with-the-sub-method\">Substituting Strings with the sub() Method</a></li>\n<li><a href=\"#managing-complex-regexes\">Managing Complex Regexes</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#handling-file-and-directory-paths\">Handling File and Directory Paths</a></p>\n<ul>\n<li><a href=\"#backslash-on-windows-and-forward-slash-on-os-x-and-linux\">Backslash on Windows and Forward Slash on OS X and Linux</a></li>\n<li><a href=\"#the-current-working-directory\">The Current Working Directory</a></li>\n<li><a href=\"#creating-new-folders\">Creating New Folders</a></li>\n<li><a href=\"#absolute-vs-relative-paths\">Absolute vs. Relative Paths</a></li>\n<li><a href=\"#handling-absolute-and-relative-paths\">Handling Absolute and Relative Paths</a></li>\n<li><a href=\"#checking-path-validity\">Checking Path Validity</a></li>\n<li><a href=\"#finding-file-sizes-and-folder-contents\">Finding File Sizes and Folder Contents</a></li>\n<li><a href=\"#copying-files-and-folders\">Copying Files and Folders</a></li>\n<li><a href=\"#moving-and-renaming-files-and-folders\">Moving and Renaming Files and Folders</a></li>\n<li><a href=\"#permanently-deleting-files-and-folders\">Permanently Deleting Files and Folders</a></li>\n<li><a href=\"#safe-deletes-with-the-send2trash-module\">Safe Deletes with the send2trash Module</a></li>\n<li><a href=\"#walking-a-directory-tree\">Walking a Directory Tree</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#reading-and-writing-files\">Reading and Writing Files</a></p>\n<ul>\n<li><a href=\"#the-file-readingwriting-process\">The File Reading/Writing Process</a></li>\n<li><a href=\"#opening-and-reading-files-with-the-open-function\">Opening and reading files with the open() function</a></li>\n<li><a href=\"#writing-to-files\">Writing to Files</a></li>\n<li><a href=\"#saving-variables-with-the-shelve-module\">Saving Variables with the shelve Module</a></li>\n<li><a href=\"#saving-variables-with-the-pprintpformat-function\">Saving Variables with the pprint.pformat() Function</a></li>\n<li><a href=\"#reading-zip-files\">Reading ZIP Files</a></li>\n<li><a href=\"#extracting-from-zip-files\">Extracting from ZIP Files</a></li>\n<li><a href=\"#creating-and-adding-to-zip-files\">Creating and Adding to ZIP Files</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#json-yaml-and-configuration-files\">JSON, YAML and configuration files</a></p>\n<ul>\n<li><a href=\"#json\">JSON</a></li>\n<li><a href=\"#yaml\">YAML</a></li>\n<li><a href=\"#anyconfig\">Anyconfig</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#debugging\">Debugging</a></p>\n<ul>\n<li><a href=\"#raising-exceptions\">Raising Exceptions</a></li>\n<li><a href=\"#getting-the-traceback-as-a-string\">Getting the Traceback as a String</a></li>\n<li><a href=\"#assertions\">Assertions</a></li>\n<li><a href=\"#logging\">Logging</a></li>\n<li><a href=\"#logging-levels\">Logging Levels</a></li>\n<li><a href=\"#disabling-logging\">Disabling Logging</a></li>\n<li><a href=\"#logging-to-a-file\">Logging to a File</a></li>\n</ul>\n</li>\n<li><a href=\"#lambda-functions\">Lambda Functions</a></li>\n<li><a href=\"#ternary-conditional-operator\">Ternary Conditional Operator</a></li>\n<li>\n<p><a href=\"#args-and-kwargs\">args and kwargs</a></p>\n<ul>\n<li><a href=\"#things-to-rememberargs\">Things to Remember(args)</a></li>\n<li><a href=\"#things-to-rememberkwargs\">Things to Remember(kwargs)</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#context-manager\">Context Manager</a></p>\n<ul>\n<li><a href=\"#with-statement\">with statement</a></li>\n<li><a href=\"#writing-your-own-contextmanager-using-generator-syntax\">Writing your own contextmanager using generator syntax</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#__main__-top-level-script-environment\"><code class=\"language-text\">__main__</code> Top-level script environment</a></p>\n<ul>\n<li><a href=\"#advantages\">Advantages</a></li>\n</ul>\n</li>\n<li><a href=\"#setuppy\">setup.py</a></li>\n<li>\n<p><a href=\"#dataclasses\">Dataclasses</a></p>\n<ul>\n<li><a href=\"#features\">Features</a></li>\n<li><a href=\"#default-values\">Default values</a></li>\n<li><a href=\"#type-hints\">Type hints</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#virtual-environment\">Virtual Environment</a></p>\n<ul>\n<li><a href=\"#virtualenv\">virtualenv</a></li>\n<li><a href=\"#poetry\">poetry</a></li>\n<li><a href=\"#pipenv\">pipenv</a></li>\n<li><a href=\"#anaconda\">anaconda</a></li>\n</ul>\n</li>\n</ul>\n<h2>The Zen of Python</h2>\n<p>From the <a href=\"https://www.python.org/dev/peps/pep-0020/\">PEP 20 -- The Zen of Python</a>:</p>\n<blockquote>\n<p>Long time Pythoneer Tim Peters succinctly channels the BDFL's guiding principles for Pythons design into 20 aphorisms, only 19 of which have been written down.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> this\nThe Zen of Python<span class=\"token punctuation\">,</span> by Tim Peters\n\nBeautiful <span class=\"token keyword\">is</span> better than ugly<span class=\"token punctuation\">.</span>\nExplicit <span class=\"token keyword\">is</span> better than implicit<span class=\"token punctuation\">.</span>\nSimple <span class=\"token keyword\">is</span> better than <span class=\"token builtin\">complex</span><span class=\"token punctuation\">.</span>\nComplex <span class=\"token keyword\">is</span> better than complicated<span class=\"token punctuation\">.</span>\nFlat <span class=\"token keyword\">is</span> better than nested<span class=\"token punctuation\">.</span>\nSparse <span class=\"token keyword\">is</span> better than dense<span class=\"token punctuation\">.</span>\nReadability counts<span class=\"token punctuation\">.</span>\nSpecial cases aren't special enough to <span class=\"token keyword\">break</span> the rules<span class=\"token punctuation\">.</span>\nAlthough practicality beats purity<span class=\"token punctuation\">.</span>\nErrors should never <span class=\"token keyword\">pass</span> silently<span class=\"token punctuation\">.</span>\nUnless explicitly silenced<span class=\"token punctuation\">.</span>\nIn the face of ambiguity<span class=\"token punctuation\">,</span> refuse the temptation to guess<span class=\"token punctuation\">.</span>\nThere should be one<span class=\"token operator\">-</span><span class=\"token operator\">-</span> <span class=\"token keyword\">and</span> preferably only one <span class=\"token operator\">-</span><span class=\"token operator\">-</span>obvious way to do it<span class=\"token punctuation\">.</span>\nAlthough that way may <span class=\"token keyword\">not</span> be obvious at first unless you're Dutch<span class=\"token punctuation\">.</span>\nNow <span class=\"token keyword\">is</span> better than never<span class=\"token punctuation\">.</span>\nAlthough never <span class=\"token keyword\">is</span> often better than <span class=\"token operator\">*</span>right<span class=\"token operator\">*</span> now<span class=\"token punctuation\">.</span>\nIf the implementation <span class=\"token keyword\">is</span> hard to explain<span class=\"token punctuation\">,</span> it's a bad idea<span class=\"token punctuation\">.</span>\nIf the implementation <span class=\"token keyword\">is</span> easy to explain<span class=\"token punctuation\">,</span> it may be a good idea<span class=\"token punctuation\">.</span>\nNamespaces are one honking great idea <span class=\"token operator\">-</span><span class=\"token operator\">-</span> let's do more of those!</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Python Basics</h2>\n<h3>Math Operators</h3>\n<p>From <strong>Highest</strong> to <strong>Lowest</strong> precedence:</p>\n<table>\n<thead>\n<tr>\n<th>Operators</th>\n<th>Operation</th>\n<th>Example</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>**</td>\n<td>Exponent</td>\n<td><code class=\"language-text\">2 ** 3 = 8</code></td>\n</tr>\n<tr>\n<td>%</td>\n<td>Modulus/Remainder</td>\n<td><code class=\"language-text\">22 % 8 = 6</code></td>\n</tr>\n<tr>\n<td>//</td>\n<td>Integer division</td>\n<td><code class=\"language-text\">22 // 8 = 2</code></td>\n</tr>\n<tr>\n<td>/</td>\n<td>Division</td>\n<td><code class=\"language-text\">22 / 8 = 2.75</code></td>\n</tr>\n<tr>\n<td>*</td>\n<td>Multiplication</td>\n<td><code class=\"language-text\">3 * 3 = 9</code></td>\n</tr>\n<tr>\n<td>-</td>\n<td>Subtraction</td>\n<td><code class=\"language-text\">5 - 2 = 3</code></td>\n</tr>\n<tr>\n<td>+</td>\n<td>Addition</td>\n<td><code class=\"language-text\">2 + 2 = 4</code></td>\n</tr>\n</tbody>\n</table>\n<p>Examples of expressions in the interactive shell:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span>\n<span class=\"token number\">20</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span>\n<span class=\"token number\">30</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token operator\">**</span> <span class=\"token number\">8</span>\n<span class=\"token number\">256</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">23</span> <span class=\"token operator\">//</span> <span class=\"token number\">7</span>\n<span class=\"token number\">3</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">23</span> <span class=\"token operator\">%</span> <span class=\"token number\">7</span>\n<span class=\"token number\">2</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token punctuation\">(</span><span class=\"token number\">3</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">16.0</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Data Types</h3>\n<table>\n<thead>\n<tr>\n<th>Data Type</th>\n<th>Examples</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Integers</td>\n<td><code class=\"language-text\">-2, -1, 0, 1, 2, 3, 4, 5</code></td>\n</tr>\n<tr>\n<td>Floating-point numbers</td>\n<td><code class=\"language-text\">-1.25, -1.0, --0.5, 0.0, 0.5, 1.0, 1.25</code></td>\n</tr>\n<tr>\n<td>Strings</td>\n<td><code class=\"language-text\">'a', 'aa', 'aaa', 'Hello!', '11 cats'</code></td>\n</tr>\n</tbody>\n</table>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>String Concatenation and Replication</h3>\n<p>String concatenation:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Alice'</span> <span class=\"token string\">'Bob'</span>\n<span class=\"token string\">'AliceBob'</span></code></pre></div>\n<p>Note: Avoid <code class=\"language-text\">+</code> operator for string concatenation. Prefer string formatting.</p>\n<p>String Replication:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Alice'</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span>\n<span class=\"token string\">'AliceAliceAliceAliceAlice'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Variables</h3>\n<p>You can name a variable anything as long as it obeys the following rules:</p>\n<ol>\n<li>It can be only one word.</li>\n<li>It can use only letters, numbers, and the underscore (<code class=\"language-text\">_</code>) character.</li>\n<li>It can't begin with a number.</li>\n<li>Variable name starting with an underscore (<code class=\"language-text\">_</code>) are considered as \"unuseful`.</li>\n</ol>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token string\">'Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> _spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span></code></pre></div>\n<p><code class=\"language-text\">_spam</code> should not be used again in the code.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Comments</h3>\n<p>Inline comment:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># This is a comment</span></code></pre></div>\n<p>Multiline comment:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># This is a</span>\n<span class=\"token comment\"># multiline comment</span></code></pre></div>\n<p>Code with a comment:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">=</span> <span class=\"token number\">1</span>  <span class=\"token comment\"># initialization</span></code></pre></div>\n<p>Please note the two spaces in front of the comment.</p>\n<p>Function docstring:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token triple-quoted-string string\">\"\"\"\n    This is a function docstring\n    You can also use:\n    ''' Function Docstring '''\n    \"\"\"</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The print() Function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span>\nHello world!</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span>\nHello world! <span class=\"token number\">1</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The input() Function</h3>\n<p>Example Code:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'What is your name?'</span><span class=\"token punctuation\">)</span>   <span class=\"token comment\"># ask for their name</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> myName <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is good to meet you, {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>myName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nWhat <span class=\"token keyword\">is</span> your name?\nAl\nIt <span class=\"token keyword\">is</span> good to meet you<span class=\"token punctuation\">,</span> Al</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The len() Function</h3>\n<p>Evaluates to the integer value of the number of characters in a string:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">5</span></code></pre></div>\n<p>Note: test of emptiness of strings, lists, dictionary, etc, should <strong>not</strong> use len, but prefer direct\nboolean evaluation.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"the list is not empty!\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The str(), int(), and float() Functions</h3>\n<p>Integer to String or Float:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">29</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'29'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I am {} years old.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">29</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nI am <span class=\"token number\">29</span> years old<span class=\"token punctuation\">.</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">3.14</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'-3.14'</span></code></pre></div>\n<p>Float to Integer:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token number\">7.7</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">7</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token number\">7.7</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n<span class=\"token number\">8</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Flow Control</h2>\n<h3>Comparison Operators</h3>\n<table>\n<thead>\n<tr>\n<th>Operator</th>\n<th>Meaning</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">==</code></td>\n<td>Equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">!=</code></td>\n<td>Not equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">&lt;</code></td>\n<td>Less than</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">></code></td>\n<td>Greater Than</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">&lt;=</code></td>\n<td>Less than or Equal to</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">>=</code></td>\n<td>Greater than or Equal to</td>\n</tr>\n</tbody>\n</table>\n<p>These operators evaluate to True or False depending on the values you give them.</p>\n<p>Examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token number\">42</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">40</span> <span class=\"token operator\">==</span> <span class=\"token number\">42</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span> <span class=\"token operator\">==</span> <span class=\"token string\">'hello'</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span> <span class=\"token operator\">==</span> <span class=\"token string\">'Hello'</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'dog'</span> <span class=\"token operator\">!=</span> <span class=\"token string\">'cat'</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token number\">42.0</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">42</span> <span class=\"token operator\">==</span> <span class=\"token string\">'42'</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<h3>Boolean evaluation</h3>\n<p>Never use <code class=\"language-text\">==</code> or <code class=\"language-text\">!=</code> operator to evaluate boolean operation. Use the <code class=\"language-text\">is</code> or <code class=\"language-text\">is not</code> operators,\nor use implicit boolean evaluation.</p>\n<p>NO (even if they are valid Python):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">True</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token operator\">!=</span> <span class=\"token boolean\">False</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p>YES (even if they are valid Python):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p>These statements are equivalent:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">pass</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">pass</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">pass</span></code></pre></div>\n<p>And these as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">pass</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">pass</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> a<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">pass</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Boolean Operators</h3>\n<p>There are three Boolean operators: and, or, and not.</p>\n<p>The <em>and</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">True and True</code></td>\n<td><code class=\"language-text\">True</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">True and False</code></td>\n<td><code class=\"language-text\">False</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">False and True</code></td>\n<td><code class=\"language-text\">False</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">False and False</code></td>\n<td><code class=\"language-text\">False</code></td>\n</tr>\n</tbody>\n</table>\n<p>The <em>or</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">True or True</code></td>\n<td><code class=\"language-text\">True</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">True or False</code></td>\n<td><code class=\"language-text\">True</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">False or True</code></td>\n<td><code class=\"language-text\">True</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">False or False</code></td>\n<td><code class=\"language-text\">False</code></td>\n</tr>\n</tbody>\n</table>\n<p>The <em>not</em> Operator's <em>Truth</em> Table:</p>\n<table>\n<thead>\n<tr>\n<th>Expression</th>\n<th>Evaluates to</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">not True</code></td>\n<td><code class=\"language-text\">False</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">not False</code></td>\n<td><code class=\"language-text\">True</code></td>\n</tr>\n</tbody>\n</table>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Mixing Boolean and Comparison Operators</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> <span class=\"token punctuation\">(</span><span class=\"token number\">9</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">or</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p>You can also use multiple Boolean operators in an expression, along with the comparison operators:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">4</span> <span class=\"token keyword\">and</span> <span class=\"token keyword\">not</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">5</span> <span class=\"token keyword\">and</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>if Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>else Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, stranger.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>elif Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are not Alice, kiddo.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">'Bob'</span>\nage <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n<span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi, Alice.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are not Alice, kiddo.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You are neither Alice nor a little kid.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>while Loop Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n<span class=\"token keyword\">while</span> spam <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, world.'</span><span class=\"token punctuation\">)</span>\n    spam <span class=\"token operator\">=</span> spam <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>break Statements</h3>\n<p>If the execution reaches a break statement, it immediately exits the while loop's clause:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Please type your name.'</span><span class=\"token punctuation\">)</span>\n    name <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> name <span class=\"token operator\">==</span> <span class=\"token string\">'your name'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">break</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Thank you!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>continue Statements</h3>\n<p>When the program execution reaches a continue statement, the program execution immediately jumps back to the start of the loop.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Who are you?'</span><span class=\"token punctuation\">)</span>\n    name <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> name <span class=\"token operator\">!=</span> <span class=\"token string\">'Joe'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">continue</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, Joe. What is the password? (It is a fish.)'</span><span class=\"token punctuation\">)</span>\n    password <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> password <span class=\"token operator\">==</span> <span class=\"token string\">'swordfish'</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">break</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Access granted.'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>for Loops and the range() Function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'My name is'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Jimmy Five Times ({})'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nMy name <span class=\"token keyword\">is</span>\nJimmy Five Times <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\nJimmy Five Times <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\nJimmy Five Times <span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\nJimmy Five Times <span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\nJimmy Five Times <span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <em>range()</em> function can also be called with three arguments. The first two arguments will be the start and stop values, and the third will be the step argument. The step is the amount that the variable is increased by after each iteration.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token number\">0</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">4</span>\n<span class=\"token number\">6</span>\n<span class=\"token number\">8</span></code></pre></div>\n<p>You can even use a negative number for the step argument to make the for loop count down instead of up.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token number\">5</span>\n<span class=\"token number\">4</span>\n<span class=\"token number\">3</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">0</span></code></pre></div>\n<h3>For else statement</h3>\n<p>This allows to specify a statement to execute in case of the full loop has been executed. Only\nuseful when a <code class=\"language-text\">break</code> condition can occur in the loop:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">if</span> i <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>        <span class=\"token keyword\">break</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"only executed when no item of the list is equal to 3\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Importing Modules</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random<span class=\"token punctuation\">,</span> sys<span class=\"token punctuation\">,</span> os<span class=\"token punctuation\">,</span> math</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> random <span class=\"token keyword\">import</span> <span class=\"token operator\">*</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Ending a Program Early with sys.exit()</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> sys\n\n<span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Type exit to exit.'</span><span class=\"token punctuation\">)</span>\n    response <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> response <span class=\"token operator\">==</span> <span class=\"token string\">'exit'</span><span class=\"token punctuation\">:</span>\n        sys<span class=\"token punctuation\">.</span>exit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'You typed {}.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Functions</h2>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">hello</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> hello<span class=\"token punctuation\">(</span><span class=\"token string\">'Alice'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> hello<span class=\"token punctuation\">(</span><span class=\"token string\">'Bob'</span><span class=\"token punctuation\">)</span>\nHello Alice\nHello Bob</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Return Values and return Statements</h3>\n<p>When creating a function using the def statement, you can specify what the return value should be with a return statement. A return statement consists of the following:</p>\n<ul>\n<li>The return keyword.</li>\n<li>-</li>\n<li>The value or expression that the function should return.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n<span class=\"token keyword\">def</span> <span class=\"token function\">getAnswer</span><span class=\"token punctuation\">(</span>answerNumber<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'It is certain'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'It is decidedly so'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Yes'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Reply hazy try again'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Ask again later'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Concentrate and ask again'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">7</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'My reply is no'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">8</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Outlook not so good'</span>\n    <span class=\"token keyword\">elif</span> answerNumber <span class=\"token operator\">==</span> <span class=\"token number\">9</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Very doubtful'</span>\n\nr <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span>\nfortune <span class=\"token operator\">=</span> getAnswer<span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>fortune<span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The None Value</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello!'</span><span class=\"token punctuation\">)</span>\nHello!</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p>Note: never compare to <code class=\"language-text\">None</code> with the <code class=\"language-text\">==</code> operator. Always use <code class=\"language-text\">is</code>.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Keyword Arguments and print()</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'World'</span><span class=\"token punctuation\">)</span>\nHelloWorld</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mice'</span><span class=\"token punctuation\">)</span>\ncats dogs mice</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mice'</span><span class=\"token punctuation\">,</span> sep<span class=\"token operator\">=</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span>\ncats<span class=\"token punctuation\">,</span>dogs<span class=\"token punctuation\">,</span>mice</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Local and Global Scope</h3>\n<ul>\n<li>Code in the global scope cannot use any local variables.</li>\n<li>-</li>\n<li>However, a local scope can access global variables.</li>\n<li>-</li>\n<li>Code in a function's local scope cannot use variables in any other local scope.</li>\n<li>You can use the same name for different variables if they are in different scopes. That is, there can be a local variable named spam and a global variable also named spam.</li>\n</ul>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The global Statement</h3>\n<p>If you need to modify a global variable from within a function, use the global statement:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">spam</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">global</span> eggs\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     eggs <span class=\"token operator\">=</span> <span class=\"token string\">'spam'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> eggs <span class=\"token operator\">=</span> <span class=\"token string\">'global'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>eggs<span class=\"token punctuation\">)</span>\nspam</code></pre></div>\n<p>There are four rules to tell whether a variable is in a local scope or global scope:</p>\n<ol>\n<li>If a variable is being used in the global scope (that is, outside of all functions), then it is always a global variable.</li>\n<li>If there is a global statement for that variable in a function, it is a global variable.</li>\n<li>Otherwise, if the variable is used in an assignment statement in the function, it is a local variable.</li>\n<li>But if the variable is not used in an assignment statement, it is a global variable.</li>\n</ol>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Exception Handling</h2>\n<h3>Basic exception handling</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">spam</span><span class=\"token punctuation\">(</span>divideBy<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         <span class=\"token keyword\">return</span> <span class=\"token number\">42</span> <span class=\"token operator\">/</span> divideBy\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">except</span> ZeroDivisionError <span class=\"token keyword\">as</span> e<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Error: Invalid argument: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">12</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">21.0</span>\n<span class=\"token number\">3.5</span>\nError<span class=\"token punctuation\">:</span> Invalid argument<span class=\"token punctuation\">:</span> division by zero\n<span class=\"token boolean\">None</span>\n<span class=\"token number\">42.0</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Final code in exception handling</h3>\n<p>Code inside the <code class=\"language-text\">finally</code> section is always executed, no matter if an exception has been raised or\nnot, and even if an exception is not caught.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">spam</span><span class=\"token punctuation\">(</span>divideBy<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         <span class=\"token keyword\">return</span> <span class=\"token number\">42</span> <span class=\"token operator\">/</span> divideBy\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">except</span> ZeroDivisionError <span class=\"token keyword\">as</span> e<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Error: Invalid argument: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">finally</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"-- division finished --\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">-</span><span class=\"token operator\">-</span> division finished <span class=\"token operator\">-</span><span class=\"token operator\">-</span>\n<span class=\"token number\">21.0</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">12</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">-</span><span class=\"token operator\">-</span> division finished <span class=\"token operator\">-</span><span class=\"token operator\">-</span>\n<span class=\"token number\">3.5</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nError<span class=\"token punctuation\">:</span> Invalid Argument division by zero\n<span class=\"token operator\">-</span><span class=\"token operator\">-</span> division finished <span class=\"token operator\">-</span><span class=\"token operator\">-</span>\n<span class=\"token boolean\">None</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">-</span><span class=\"token operator\">-</span> division finished <span class=\"token operator\">-</span><span class=\"token operator\">-</span>\n<span class=\"token number\">42.0</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Lists</h2>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Getting Individual Values in a List with Indexes</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'cat'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'bat'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'rat'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'elephant'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Negative Indexes</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'elephant'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'bat'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'The {} is afraid of the {}.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'The elephant is afraid of the bat.'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Getting Sublists with Slices</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Slicing the complete list will perform a copy:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam2 <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">'dog'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam2\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Getting a List's Length with len()</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'moose'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">)</span>\n<span class=\"token number\">3</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Changing Values in a List with Indexes</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'aardvark'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'aardvark'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'aardvark'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'aardvark'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">12345</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'aardvark'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'aardvark'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">12345</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>List Concatenation and List Replication</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'B'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C'</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'B'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span><span class=\"token string\">'X'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Y'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Z'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'X'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Y'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Z'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'X'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Y'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Z'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'X'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Y'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Z'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> spam <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'B'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'B'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Removing Values from Lists with del Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">del</span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">del</span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Using for Loops with Lists</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> supplies <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'pens'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'staplers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'flame-throwers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'binders'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i<span class=\"token punctuation\">,</span> supply <span class=\"token keyword\">in</span> <span class=\"token builtin\">enumerate</span><span class=\"token punctuation\">(</span>supplies<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Index {} in supplies is: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> supply<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nIndex <span class=\"token number\">0</span> <span class=\"token keyword\">in</span> supplies <span class=\"token keyword\">is</span><span class=\"token punctuation\">:</span> pens\nIndex <span class=\"token number\">1</span> <span class=\"token keyword\">in</span> supplies <span class=\"token keyword\">is</span><span class=\"token punctuation\">:</span> staplers\nIndex <span class=\"token number\">2</span> <span class=\"token keyword\">in</span> supplies <span class=\"token keyword\">is</span><span class=\"token punctuation\">:</span> flame<span class=\"token operator\">-</span>throwers\nIndex <span class=\"token number\">3</span> <span class=\"token keyword\">in</span> supplies <span class=\"token keyword\">is</span><span class=\"token punctuation\">:</span> binders</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Looping Through Multiple Lists with zip()</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> name <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Pete'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Elizabeth'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> age <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">23</span><span class=\"token punctuation\">,</span> <span class=\"token number\">44</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> n<span class=\"token punctuation\">,</span> a <span class=\"token keyword\">in</span> <span class=\"token builtin\">zip</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'{} is {} years old'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nPete <span class=\"token keyword\">is</span> <span class=\"token number\">6</span> years old\nJohn <span class=\"token keyword\">is</span> <span class=\"token number\">23</span> years old\nElizabeth <span class=\"token keyword\">is</span> <span class=\"token number\">44</span> years old</code></pre></div>\n<h3>The in and not in Operators</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'howdy'</span> <span class=\"token keyword\">in</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hi'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'howdy'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'heyas'</span><span class=\"token punctuation\">]</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hi'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'howdy'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'heyas'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'cat'</span> <span class=\"token keyword\">in</span> spam\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'howdy'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> spam\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'cat'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> spam\n<span class=\"token boolean\">True</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The Multiple Assignment Trick</h3>\n<p>The multiple assignment trick is a shortcut that lets you assign multiple variables with the values in a list in one line of code. So instead of doing this:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> cat <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'fat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'loud'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> size <span class=\"token operator\">=</span> cat<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> color <span class=\"token operator\">=</span> cat<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> disposition <span class=\"token operator\">=</span> cat<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>You could type this line of code:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> cat <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'fat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'loud'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> size<span class=\"token punctuation\">,</span> color<span class=\"token punctuation\">,</span> disposition <span class=\"token operator\">=</span> cat</code></pre></div>\n<p>The multiple assignment trick can also be used to swap the values in two variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> <span class=\"token string\">'Alice'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Bob'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> a<span class=\"token punctuation\">,</span> b <span class=\"token operator\">=</span> b<span class=\"token punctuation\">,</span> a\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Bob'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Alice'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Augmented Assignment Operators</h3>\n<table>\n<thead>\n<tr>\n<th>Operator</th>\n<th>Equivalent</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">spam += 1</code></td>\n<td><code class=\"language-text\">spam = spam + 1</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam -= 1</code></td>\n<td><code class=\"language-text\">spam = spam - 1</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam *= 1</code></td>\n<td><code class=\"language-text\">spam = spam * 1</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam /= 1</code></td>\n<td><code class=\"language-text\">spam = spam / 1</code></td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam %= 1</code></td>\n<td><code class=\"language-text\">spam = spam % 1</code></td>\n</tr>\n</tbody>\n</table>\n<p>Examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">+=</span> <span class=\"token string\">' world!'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token string\">'Hello world!'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> bacon <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> bacon <span class=\"token operator\">*=</span> <span class=\"token number\">3</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> bacon\n<span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Finding a Value in a List with the index() Method</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Fat-tail'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span><span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">1</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Adding Values to Lists with the append() and insert() Methods</h3>\n<p><strong>append()</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">'moose'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'moose'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><strong>insert()</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>insert<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'chicken'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'chicken'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Removing Values from Lists with remove()</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>remove<span class=\"token punctuation\">(</span><span class=\"token string\">'bat'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>If the value appears multiple times in the list, only the first instance of the value will be removed.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Removing Values from Lists with pop()</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephant'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>pop<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'elephant'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>pop<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'cat'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'bat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Sorting the Values in a List with the sort() Method</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">7</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'ants'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'badgers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephants'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'ants'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'badgers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephants'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>You can also pass True for the reverse keyword argument to have sort() sort the values in reverse order:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span>reverse<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'elephants'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'badgers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'ants'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>If you need to sort the values in regular alphabetical order, pass str. lower for the key keyword argument in the sort() method call:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'z'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Z'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span>key<span class=\"token operator\">=</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'z'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Z'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>You can use the built-in function <code class=\"language-text\">sorted</code> to return a new list:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'ants'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'badgers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephants'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sorted</span><span class=\"token punctuation\">(</span>spam<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'ants'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'badgers'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dogs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'elephants'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Tuple Data Type</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> eggs <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.5</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> eggs<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> eggs<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">42</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.5</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>eggs<span class=\"token punctuation\">)</span>\n<span class=\"token number\">3</span></code></pre></div>\n<p>The main way that tuples are different from lists is that tuples, like strings, are immutable.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Converting Types with the list() and tuple() Functions</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">tuple</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'dog'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'h'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'e'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'l'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'l'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'o'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Dictionaries and Structuring Data</h2>\n<p>Example Dictionary:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">myCat <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'size'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'fat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'gray'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'disposition'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'loud'</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The keys(), values(), and items() Methods</h3>\n<p>values():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> v <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span>\nred\n<span class=\"token number\">42</span></code></pre></div>\n<p>keys():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> k <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">)</span>\ncolor\nage</code></pre></div>\n<p>items():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'age'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">42</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using the keys(), values(), and items() methods, a for loop can iterate over the keys, values, or key-value pairs in a dictionary, respectively.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">42</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Key: {} Value: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">,</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nKey<span class=\"token punctuation\">:</span> age Value<span class=\"token punctuation\">:</span> <span class=\"token number\">42</span>\nKey<span class=\"token punctuation\">:</span> color Value<span class=\"token punctuation\">:</span> red</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Checking Whether a Key or Value Exists in a Dictionary</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">7</span><span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'name'</span> <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Zophie'</span> <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token comment\"># You can omit the call to keys() when checking for a key</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'color'</span> <span class=\"token keyword\">in</span> spam\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'color'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> spam\n<span class=\"token boolean\">True</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The get() Method</h3>\n<p>Get has two parameters: key and default value if the key did not exist</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> picnic_items <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'apples'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cups'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'I am bringing {} cups.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>picnic_items<span class=\"token punctuation\">.</span>get<span class=\"token punctuation\">(</span><span class=\"token string\">'cups'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'I am bringing 2 cups.'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'I am bringing {} eggs.'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>picnic_items<span class=\"token punctuation\">.</span>get<span class=\"token punctuation\">(</span><span class=\"token string\">'eggs'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'I am bringing 0 eggs.'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The setdefault() Method</h3>\n<p>Let's consider this code:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token string\">'color'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> spam<span class=\"token punctuation\">:</span>\n    spam<span class=\"token punctuation\">[</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'black'</span></code></pre></div>\n<p>Using <code class=\"language-text\">setdefault</code> we could write the same code more succinctly:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>setdefault<span class=\"token punctuation\">(</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'black'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'black'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">{</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'black'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">}</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>setdefault<span class=\"token punctuation\">(</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'white'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'black'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token punctuation\">{</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'black'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Pretty Printing</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> pprint\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> 'It was a bright cold day <span class=\"token keyword\">in</span> April<span class=\"token punctuation\">,</span> <span class=\"token keyword\">and</span> the clocks were striking\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> thirteen<span class=\"token punctuation\">.</span>'\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> count <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> character <span class=\"token keyword\">in</span> message<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     count<span class=\"token punctuation\">.</span>setdefault<span class=\"token punctuation\">(</span>character<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     count<span class=\"token punctuation\">[</span>character<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> count<span class=\"token punctuation\">[</span>character<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> pprint<span class=\"token punctuation\">.</span>pprint<span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">:</span> <span class=\"token number\">13</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">','</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'.'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'A'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'I'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'d'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'e'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'g'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'h'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'i'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'k'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'l'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'n'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'o'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'p'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'r'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'s'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'t'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'w'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span>\n <span class=\"token string\">'y'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Merge two dictionaries</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># in Python 3.5+:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> x <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> y <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> z <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">**</span>x<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>y<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> z\n<span class=\"token punctuation\">{</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\"># in Python 2.7</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> z <span class=\"token operator\">=</span> <span class=\"token builtin\">dict</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>y<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> z\n<span class=\"token punctuation\">{</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h2>sets</h2>\n<p>From the Python 3 <a href=\"https://docs.python.org/3/tutorial/datastructures.html\">documentation</a></p>\n<blockquote>\n<p>A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.</p>\n</blockquote>\n<h3>Initializing a set</h3>\n<p>There are two ways to create sets: using curly braces <code class=\"language-text\">{}</code> and the built-in function <code class=\"language-text\">set()</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token builtin\">set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>When creating an empty set, be sure to not use the curly braces <code class=\"language-text\">{}</code> or you will get an empty dictionary instead.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'dict'</span><span class=\"token operator\">></span></code></pre></div>\n<h3>sets: unordered collections of unique elements</h3>\n<p>A set automatically remove all the duplicate values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s\n<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>And as an unordered data type, they can't be indexed.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nTypeError<span class=\"token punctuation\">:</span> <span class=\"token string\">'set'</span> <span class=\"token builtin\">object</span> does <span class=\"token keyword\">not</span> support indexing\n<span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<h3>set add() and update()</h3>\n<p>Using the <code class=\"language-text\">add()</code> method we can add a single element to the set.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s<span class=\"token punctuation\">.</span>add<span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s\n<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>And with <code class=\"language-text\">update()</code>, multiple ones .</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s<span class=\"token punctuation\">.</span>update<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s\n<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">}</span>  <span class=\"token comment\"># remember, sets automatically remove duplicates</span></code></pre></div>\n<h3>set remove() and discard()</h3>\n<p>Both methods will remove an element from the set, but <code class=\"language-text\">remove()</code> will raise a <code class=\"language-text\">key error</code> if the value doesn't exist.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s<span class=\"token punctuation\">.</span>remove<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s\n<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s<span class=\"token punctuation\">.</span>remove<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\nKeyError<span class=\"token punctuation\">:</span> <span class=\"token number\">3</span></code></pre></div>\n<p><code class=\"language-text\">discard()</code> won't raise any errors.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s<span class=\"token punctuation\">.</span>discard<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s\n<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s<span class=\"token punctuation\">.</span>discard<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<h3>set union()</h3>\n<p><code class=\"language-text\">union()</code> or <code class=\"language-text\">|</code> will create a new set that contains all the elements from the sets provided.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s1<span class=\"token punctuation\">.</span>union<span class=\"token punctuation\">(</span>s2<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># or 's1 | s2'</span>\n<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3>set intersection</h3>\n<p><code class=\"language-text\">intersection</code> or <code class=\"language-text\">&amp;</code> will return a set containing only the elements that are common to all of them.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s1<span class=\"token punctuation\">.</span>intersection<span class=\"token punctuation\">(</span>s2<span class=\"token punctuation\">,</span> s3<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># or 's1 &amp; s2 &amp; s3'</span>\n<span class=\"token punctuation\">{</span><span class=\"token number\">3</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3>set difference</h3>\n<p><code class=\"language-text\">difference</code> or <code class=\"language-text\">-</code> will return only the elements that are unique to the first set (invoked set).</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s1<span class=\"token punctuation\">.</span>difference<span class=\"token punctuation\">(</span>s2<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># or 's1 - s2'</span>\n<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s2<span class=\"token punctuation\">.</span>difference<span class=\"token punctuation\">(</span>s1<span class=\"token punctuation\">)</span> <span class=\"token comment\"># or 's2 - s1'</span>\n<span class=\"token punctuation\">{</span><span class=\"token number\">4</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3>set symetric_difference</h3>\n<p><code class=\"language-text\">symetric_difference</code> or <code class=\"language-text\">^</code> will return all the elements that are not common between them.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> s1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> s1<span class=\"token punctuation\">.</span>symmetric_difference<span class=\"token punctuation\">(</span>s2<span class=\"token punctuation\">)</span>  <span class=\"token comment\"># or 's1 ^ s2'</span>\n<span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>itertools Module</h2>\n<p>The <em>itertools</em> module is a collection of tools intended to be fast and use memory efficiently when handling iterators (like <a href=\"#lists\">lists</a> or <a href=\"#dictionaries-and-structuring-data\">dictionaries</a>).</p>\n<p>From the official <a href=\"https://docs.python.org/3/library/itertools.html\">Python 3.x documentation</a>:</p>\n<blockquote>\n<p>The module standardizes a core set of fast, memory efficient tools that are useful by themselves or in combination. Together, they form an \"iterator algebra\" making it possible to construct specialized tools succinctly and efficiently in pure Python.</p>\n</blockquote>\n<p>The <em>itertools</em> module comes in the standard library and must be imported.</p>\n<p>The <a href=\"https://docs.python.org/3/library/operator.html\">operator</a> module will also be used. This module is not necessary when using itertools, but needed for some of the examples below.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>accumulate()</h3>\n<p>Makes an iterator that returns the results of a function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>accumulate<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> func<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>accumulate<span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">,</span> operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">6</span>\n<span class=\"token number\">24</span>\n<span class=\"token number\">120</span></code></pre></div>\n<p>The operator.mul takes two numbers and multiplies them:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">2</span>\noperator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">6</span>\noperator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">24</span>\noperator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">(</span><span class=\"token number\">24</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">120</span></code></pre></div>\n<p>Passing a function is optional:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>accumulate<span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token number\">5</span>\n<span class=\"token number\">7</span>\n<span class=\"token number\">13</span>\n<span class=\"token number\">17</span>\n<span class=\"token number\">22</span>\n<span class=\"token number\">31</span>\n<span class=\"token number\">32</span></code></pre></div>\n<p>If no function is designated the items will be summed:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">5</span>\n<span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n<span class=\"token number\">7</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">13</span>\n<span class=\"token number\">13</span> <span class=\"token operator\">+</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">17</span>\n<span class=\"token number\">17</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">22</span>\n<span class=\"token number\">22</span> <span class=\"token operator\">+</span> <span class=\"token number\">9</span> <span class=\"token operator\">=</span> <span class=\"token number\">31</span>\n<span class=\"token number\">31</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">32</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>combinations()</h3>\n<p>Takes an iterable and a integer. This will create all the unique combination that have r members.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>combinations<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> shapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>combinations<span class=\"token punctuation\">(</span>shapes<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>combinations<em>with</em>replacement()</h3>\n<p>Just like combinations(), but allows individual elements to be repeated more than once.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>combinations_with_replacement<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> shapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>combinations_with_replacement<span class=\"token punctuation\">(</span>shapes<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'circle'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'square'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>count()</h3>\n<p>Makes an iterator that returns evenly spaced values starting with number start.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>start<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> step<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">if</span> i <span class=\"token operator\">></span> <span class=\"token number\">20</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>        <span class=\"token keyword\">break</span>\n<span class=\"token number\">10</span>\n<span class=\"token number\">13</span>\n<span class=\"token number\">16</span>\n<span class=\"token number\">19</span>\n<span class=\"token number\">22</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>cycle()</h3>\n<p>This function cycles through an iterator endlessly.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>cycle<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'violet'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> color <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>cycle<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>color<span class=\"token punctuation\">)</span>\nred\norange\nyellow\ngreen\nblue\nviolet\nred\norange</code></pre></div>\n<p>When reached the end of the iterable it start over again from the beginning.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>chain()</h3>\n<p>Take a series of iterables and return them as one long iterable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>chain<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>iterables<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> shapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pentagon'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>chain<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">,</span> shapes<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\nred\norange\nyellow\ngreen\nblue\ncircle\ntriangle\nsquare\npentagon</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>compress()</h3>\n<p>Filters one iterable with another.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>compress<span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">,</span> selectors<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> shapes <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'circle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'triangle'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'square'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'pentagon'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> selections <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>compress<span class=\"token punctuation\">(</span>shapes<span class=\"token punctuation\">,</span> selections<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\ncircle\nsquare</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>dropwhile()</h3>\n<p>Make an iterator that drops elements from the iterable as long as the predicate is true; afterwards, returns every element.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>dropwhile<span class=\"token punctuation\">(</span>predicate<span class=\"token punctuation\">,</span> iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>dropwhile<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token operator\">&lt;</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token number\">5</span>\n<span class=\"token number\">6</span>\n<span class=\"token number\">7</span>\n<span class=\"token number\">8</span>\n<span class=\"token number\">9</span>\n<span class=\"token number\">10</span>\n<span class=\"token number\">1</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>filterfalse()</h3>\n<p>Makes an iterator that filters elements from iterable returning only those for which the predicate is False.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>filterfalse<span class=\"token punctuation\">(</span>predicate<span class=\"token punctuation\">,</span> iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>filterfalse<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token operator\">&lt;</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token number\">5</span>\n<span class=\"token number\">6</span>\n<span class=\"token number\">7</span>\n<span class=\"token number\">8</span>\n<span class=\"token number\">9</span>\n<span class=\"token number\">10</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>groupby()</h3>\n<p>Simply put, this function groups things together.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>groupby<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> key<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> robots <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'blaster'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'galvatron'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'jazz'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'metroplex'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'megatron'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'starcream'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> group <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>groupby<span class=\"token punctuation\">(</span>robots<span class=\"token punctuation\">,</span> key<span class=\"token operator\">=</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token punctuation\">[</span><span class=\"token string\">'faction'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>group<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nautobot\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'blaster'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\ndecepticon\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'galvatron'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\nautobot\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'jazz'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'metroplex'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'autobot'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\ndecepticon\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'megatron'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'starcream'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'faction'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'decepticon'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>islice()</h3>\n<p>This function is very much like slices. This allows you to cut out a piece of an iterable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>islice<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> stop<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> step<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> few_colors <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>islice<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> few_colors<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\nred\norange</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>permutations()</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>permutations<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> r<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> alpha_data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>permutations<span class=\"token punctuation\">(</span>alpha_data<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>product()</h3>\n<p>Creates the cartesian products from a series of iterables.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> num_data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> alpha_data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>product<span class=\"token punctuation\">(</span>num_data<span class=\"token punctuation\">,</span> alpha_data<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>repeat()</h3>\n<p>This function will repeat an object over and over again. Unless, there is a times argument.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>repeat<span class=\"token punctuation\">(</span><span class=\"token builtin\">object</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> times<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>repeat<span class=\"token punctuation\">(</span><span class=\"token string\">\"spam\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\nspam\nspam\nspam</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>starmap()</h3>\n<p>Makes an iterator that computes the function using arguments obtained from the iterable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>starmap<span class=\"token punctuation\">(</span>function<span class=\"token punctuation\">,</span> iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>starmap<span class=\"token punctuation\">(</span>operator<span class=\"token punctuation\">.</span>mul<span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token number\">12</span>\n<span class=\"token number\">32</span>\n<span class=\"token number\">21</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>takewhile()</h3>\n<p>The opposite of dropwhile(). Makes an iterator and returns elements from the iterable as long as the predicate is true.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>takewhile<span class=\"token punctuation\">(</span>predicate<span class=\"token punctuation\">,</span> iterable<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> result <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>takewhile<span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x<span class=\"token operator\">&lt;</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> result<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token number\">3</span>\n<span class=\"token number\">4</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>tee()</h3>\n<p>Return n independent iterators from a single iterable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>tee<span class=\"token punctuation\">(</span>iterable<span class=\"token punctuation\">,</span> n<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> alpha_colors<span class=\"token punctuation\">,</span> beta_colors <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>tee<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> alpha_colors<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\nred\norange\nyellow\ngreen\nblue</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> alpha_colors<span class=\"token punctuation\">,</span> beta_colors <span class=\"token operator\">=</span> itertools<span class=\"token punctuation\">.</span>tee<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> beta_colors<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\nred\norange\nyellow\ngreen\nblue</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>zip_longest()</h3>\n<p>Makes an iterator that aggregates elements from each of the iterables. If the iterables are of uneven length, missing values are filled-in with fillvalue. Iteration continues until the longest iterable is exhausted.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">itertools<span class=\"token punctuation\">.</span>zip_longest<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>iterables<span class=\"token punctuation\">,</span> fillvalue<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> colors <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'blue'</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> each <span class=\"token keyword\">in</span> itertools<span class=\"token punctuation\">.</span>zip_longest<span class=\"token punctuation\">(</span>colors<span class=\"token punctuation\">,</span> data<span class=\"token punctuation\">,</span> fillvalue<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>each<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'orange'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'yellow'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'green'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'blue'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Comprehensions</h2>\n<h3>List comprehension</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h3>Set comprehension</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"def\"</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>s<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> s <span class=\"token keyword\">in</span> b<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span><span class=\"token string\">\"ABC\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"DEF\"</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Dict comprehension</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>v<span class=\"token punctuation\">:</span> k <span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> c<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span><span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'age'</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>A List comprehension can be generated from a dictionary:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'first_name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Oooka'</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"{}:{}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> v<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> k<span class=\"token punctuation\">,</span> v <span class=\"token keyword\">in</span> c<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'NAME:POOKA'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'FIRST_NAME:OOOKA'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<h2>Manipulating Strings</h2>\n<h3>Escape Characters</h3>\n<table>\n<thead>\n<tr>\n<th>Escape character</th>\n<th>Prints as</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">\\'</code></td>\n<td>Single quote</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\\"</code></td>\n<td>Double quote</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\t</code></td>\n<td>Tab</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\n</code></td>\n<td>Newline (line break)</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\\\</code></td>\n<td>Backslash</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\b</code></td>\n<td>Backspace</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\ooo</code></td>\n<td>Octal value</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\r</code></td>\n<td>Carriage Return</td>\n</tr>\n</tbody>\n</table>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello there!\\nHow are you?\\nI\\'m doing fine.\"</span><span class=\"token punctuation\">)</span>\nHello there!\nHow are you?\nI'm doing fine<span class=\"token punctuation\">.</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Raw Strings</h3>\n<p>A raw string completely ignores all escape characters and prints any backslash that appears in the string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'That is Carol\\'s cat.'</span><span class=\"token punctuation\">)</span>\nThat <span class=\"token keyword\">is</span> Carol\\'s cat<span class=\"token punctuation\">.</span></code></pre></div>\n<p>Note: mostly used for regular expression definition (see <code class=\"language-text\">re</code> package)</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Multiline Strings with Triple Quotes</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token triple-quoted-string string\">'''Dear Alice,\n>>>\n>>> Eve's cat has been arrested for catnapping, cat burglary, and extortion.\n>>>\n>>> Sincerely,\n>>> Bob'''</span><span class=\"token punctuation\">)</span>\nDear Alice<span class=\"token punctuation\">,</span>\n\nEve's cat has been arrested <span class=\"token keyword\">for</span> catnapping<span class=\"token punctuation\">,</span> cat burglary<span class=\"token punctuation\">,</span> <span class=\"token keyword\">and</span> extortion<span class=\"token punctuation\">.</span>\n\nSincerely<span class=\"token punctuation\">,</span>\nBob</code></pre></div>\n<p>To keep a nicer flow in your code, you can use the <code class=\"language-text\">dedent</code> function from the <code class=\"language-text\">textwrap</code> standard package.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> textwrap <span class=\"token keyword\">import</span> dedent\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">my_function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token triple-quoted-string string\">'''\n>>>         Dear Alice,\n>>>\n>>>         Eve's cat has been arrested for catnapping, cat burglary, and extortion.\n>>>\n>>>         Sincerely,\n>>>         Bob\n>>>         '''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This generates the same string than before.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Indexing and Slicing Strings</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">H   e   l   l   o       w   o   r   l   d    !\n0   1   2   3   4   5   6   7   8   9   10   11</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello world!'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'H'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'o'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'!'</span></code></pre></div>\n<p>Slicing:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'world!'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'world'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'Hello world'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n<span class=\"token string\">'!dlrow olleH'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello world!'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> fizz <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> fizz\n<span class=\"token string\">'Hello'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The in and not in Operators with Strings</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'Hello World'</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'Hello'</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'HELLO'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'Hello World'</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">''</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'spam'</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'cats'</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'cats and dogs'</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<h3>The in and not in Operators with list</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token keyword\">in</span> a\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token keyword\">in</span> a\n<span class=\"token boolean\">True</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The upper(), lower(), isupper(), and islower() String Methods</h3>\n<p><code class=\"language-text\">upper()</code> and <code class=\"language-text\">lower()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello world!'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token string\">'HELLO WORLD!'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> spam<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam\n<span class=\"token string\">'hello world!'</span></code></pre></div>\n<p>isupper() and islower():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token string\">'Hello world!'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'HELLO'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'abc12345'</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'12345'</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'12345'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The isX String Methods</h3>\n<ul>\n<li><strong>isalpha()</strong> returns True if the string consists only of letters and is not blank.</li>\n<li><strong>isalnum()</strong> returns True if the string consists only of letters and numbers and is not blank.</li>\n<li><strong>isdecimal()</strong> returns True if the string consists only of numeric characters and is not blank.</li>\n<li><strong>isspace()</strong> returns True if the string consists only of spaces,tabs, and new-lines and is not blank.</li>\n<li><strong>istitle()</strong> returns True if the string consists only of words that begin with an uppercase letter followed by only lowercase letters.</li>\n</ul>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The startswith() and endswith() String Methods</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'world!'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'abc123'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'abcdef'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'abc123'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'12'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The join() and split() String Methods</h3>\n<p>join():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">', '</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bats'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'cats, rats, bats'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">' '</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'My'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'My name is Simon'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ABC'</span><span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'My'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'MyABCnameABCisABCSimon'</span></code></pre></div>\n<p>split():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'My name is Simon'</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'My'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'MyABCnameABCisABCSimon'</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token string\">'ABC'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'My'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'My name is Simon'</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token string\">'m'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'My na'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'e is Si'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'on'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Justifying Text with rjust(), ljust(), and center()</h3>\n<p>rjust() and ljust():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'     Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'               Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'         Hello World'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>ljust<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Hello     '</span></code></pre></div>\n<p>An optional second argument to rjust() and ljust() will specify a fill character other than a space character. Enter the following into the interactive shell:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'*'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'***************Hello'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>ljust<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'-'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Hello---------------'</span></code></pre></div>\n<p>center():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>center<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'       Hello       '</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>center<span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'='</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'=======Hello========'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Removing Whitespace with strip(), rstrip(), and lstrip()</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token string\">'    Hello World     '</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Hello World'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>lstrip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Hello World '</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>rstrip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'    Hello World'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> spam <span class=\"token operator\">=</span> <span class=\"token string\">'SpamSpamBaconSpamEggsSpamSpam'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> spam<span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token string\">'ampS'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'BaconSpamEggs'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Copying and Pasting Strings with the pyperclip Module (need pip install)</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> pyperclip\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> pyperclip<span class=\"token punctuation\">.</span>copy<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> pyperclip<span class=\"token punctuation\">.</span>paste<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Hello world!'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>String Formatting</h2>\n<h3>% operator</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> name <span class=\"token operator\">=</span> <span class=\"token string\">'Pete'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello %s'</span> <span class=\"token operator\">%</span> name\n<span class=\"token string\">\"Hello Pete\"</span></code></pre></div>\n<p>We can use the <code class=\"language-text\">%x</code> format specifier to convert an int value to a string:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> num <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'I have %x apples'</span> <span class=\"token operator\">%</span> num\n<span class=\"token string\">\"I have 5 apples\"</span></code></pre></div>\n<p>Note: For new code, using <a href=\"#string-formatting-strformat\">str.format</a> or <a href=\"#formatted-string-literals-or-f-strings-python-36\">f-strings</a> (Python 3.6+) is strongly recommended over the <code class=\"language-text\">%</code> operator.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>String Formatting (str.format)</h3>\n<p>Python 3 introduced a new way to do string formatting that was later back-ported to Python 2.7. This makes the syntax for string formatting more regular.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> name <span class=\"token operator\">=</span> <span class=\"token string\">'John'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> age <span class=\"token operator\">=</span> <span class=\"token number\">20</span>'\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"Hello I'm {}, my age is {}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">)</span>\n<span class=\"token string\">\"Hello I'm John, my age is 20\"</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"Hello I'm {0}, my age is {1}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">)</span>\n<span class=\"token string\">\"Hello I'm John, my age is 20\"</span></code></pre></div>\n<p>The official <a href=\"https://docs.python.org/3/library/stdtypes.html?highlight=sprintf#printf-style-string-formatting\">Python 3.x documentation</a> recommend <code class=\"language-text\">str.format</code> over the <code class=\"language-text\">%</code> operator:</p>\n<blockquote>\n<p>The formatting operations described here exhibit a variety of quirks that lead to a number of common errors (such as failing to display tuples and dictionaries correctly). Using the newer formatted string literals or the str.format() interface helps avoid these errors. These alternatives also provide more powerful, flexible and extensible approaches to formatting text.</p>\n</blockquote>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Lazy string formatting</h3>\n<p>You would only use <code class=\"language-text\">%s</code> string formatting on functions that can do lazy parameters evaluation,\nthe most common being logging:</p>\n<p>Prefer:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> name <span class=\"token operator\">=</span> <span class=\"token string\">\"alice\"</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">\"User name: %s\"</span><span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Over:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">\"User name: {}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Or:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">\"User name: \"</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Formatted String Literals or f-strings (Python 3.6+)</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> name <span class=\"token operator\">=</span> <span class=\"token string\">'Elizabeth'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string-interpolation\"><span class=\"token string\">f'Hello </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span></span><span class=\"token string\">!'</span></span>\n'Hello Elizabeth!</code></pre></div>\n<p>It is even possible to do inline arithmetic with it:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string-interpolation\"><span class=\"token string\">f'Five plus ten is </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">}</span></span><span class=\"token string\"> and not </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span></span><span class=\"token string\">.'</span></span>\n<span class=\"token string\">'Five plus ten is 15 and not 30.'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Template Strings</h3>\n<p>A simpler and less powerful mechanism, but it is recommended when handling format strings generated by users. Due to their reduced complexity template strings are a safer choice.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> string <span class=\"token keyword\">import</span> Template\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> name <span class=\"token operator\">=</span> <span class=\"token string\">'Elizabeth'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> t <span class=\"token operator\">=</span> Template<span class=\"token punctuation\">(</span><span class=\"token string\">'Hey $name!'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> t<span class=\"token punctuation\">.</span>substitute<span class=\"token punctuation\">(</span>name<span class=\"token operator\">=</span>name<span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Hey Elizabeth!'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Regular Expressions</h2>\n<ol>\n<li>Import the regex module with <code class=\"language-text\">import re</code>.</li>\n<li>Create a Regex object with the <code class=\"language-text\">re.compile()</code> function. (Remember to use a raw string.)</li>\n<li>Pass the string you want to search into the Regex object's <code class=\"language-text\">search()</code> method. This returns a <code class=\"language-text\">Match</code> object.</li>\n<li>Call the Match object's <code class=\"language-text\">group()</code> method to return a string of the actual matched text.</li>\n</ol>\n<p>All the regex functions in Python are in the re module:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> re</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Matching Regex Objects</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> phone_num_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'\\d\\d\\d-\\d\\d\\d-\\d\\d\\d\\d'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo <span class=\"token operator\">=</span> phone_num_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'My number is 415-555-4242.'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Phone number found: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nPhone number found<span class=\"token punctuation\">:</span> <span class=\"token number\">415</span><span class=\"token operator\">-</span><span class=\"token number\">555</span><span class=\"token operator\">-</span><span class=\"token number\">4242</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Grouping with Parentheses</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> phone_num_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'(\\d\\d\\d)-(\\d\\d\\d-\\d\\d\\d\\d)'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo <span class=\"token operator\">=</span> phone_num_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'My number is 415-555-4242.'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'415'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'555-4242'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'415-555-4242'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'415-555-4242'</span></code></pre></div>\n<p>To retrieve all the groups at once: use the groups() method—note the plural form for the name.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>groups<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">(</span><span class=\"token string\">'415'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'555-4242'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> area_code<span class=\"token punctuation\">,</span> main_number <span class=\"token operator\">=</span> mo<span class=\"token punctuation\">.</span>groups<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>area_code<span class=\"token punctuation\">)</span>\n<span class=\"token number\">415</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>main_number<span class=\"token punctuation\">)</span>\n<span class=\"token number\">555</span><span class=\"token operator\">-</span><span class=\"token number\">4242</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Matching Multiple Groups with the Pipe</h3>\n<p>The | character is called a pipe. You can use it anywhere you want to match one of many expressions. For example, the regular expression r'Batman|Tina Fey' will match either 'Batman' or 'Tina Fey'.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> hero_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span> <span class=\"token punctuation\">(</span><span class=\"token string\">r'Batman|Tina Fey'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1 <span class=\"token operator\">=</span> hero_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Batman and Tina Fey.'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batman'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2 <span class=\"token operator\">=</span> hero_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Tina Fey and Batman.'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Tina Fey'</span></code></pre></div>\n<p>You can also use the pipe to match one of several patterns as part of your regex:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> bat_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Bat(man|mobile|copter|bat)'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Batmobile lost a wheel'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batmobile'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'mobile'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Optional Matching with the Question Mark</h3>\n<p>The ? character flags the group that precedes it as an optional part of the pattern.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> bat_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Bat(wo)?man'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batman'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batman'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwoman'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batwoman'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Matching Zero or More with the Star</h3>\n<p>The * (called the star or asterisk) means \"match zero or more\"—the group that precedes the star can occur any number of times in the text.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> bat_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Bat(wo)*man'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batman'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batman'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwoman'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batwoman'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo3 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwowowowoman'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo3<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batwowowowoman'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Matching One or More with the Plus</h3>\n<p>While * means \"match zero or more,\" the + (or plus) means \"match one or more\". The group preceding a plus must appear at least once. It is not optional:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> bat_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Bat(wo)+man'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwoman'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batwoman'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batwowowowoman'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Batwowowowoman'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> mo3 <span class=\"token operator\">=</span> bat_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'The Adventures of Batman'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo3 <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Matching Specific Repetitions with Curly Brackets</h3>\n<p>If you have a group that you want to repeat a specific number of times, follow the group in your regex with a number in curly brackets. For example, the regex (Ha){3} will match the string 'HaHaHa', but it will not match 'HaHa', since the latter has only two repeats of the (Ha) group.</p>\n<p>Instead of one number, you can specify a range by writing a minimum, a comma, and a maximum in between the curly brackets. For example, the regex (Ha){3,5} will match 'HaHaHa', 'HaHaHaHa', and 'HaHaHaHaHa'.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> ha_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'(Ha){3}'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1 <span class=\"token operator\">=</span> ha_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'HaHaHa'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'HaHaHa'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2 <span class=\"token operator\">=</span> ha_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Ha'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2 <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Greedy and Nongreedy Matching</h3>\n<p>Python's regular expressions are greedy by default, which means that in ambiguous situations they will match the longest string possible. The non-greedy version of the curly brackets, which matches the shortest string possible, has the closing curly bracket followed by a question mark.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> greedy_ha_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'(Ha){3,5}'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1 <span class=\"token operator\">=</span> greedy_ha_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'HaHaHaHaHa'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo1<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'HaHaHaHaHa'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> nongreedy_ha_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'(Ha){3,5}?'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2 <span class=\"token operator\">=</span> nongreedy_ha_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'HaHaHaHaHa'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo2<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'HaHaHa'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The findall() Method</h3>\n<p>In addition to the search() method, Regex objects also have a findall() method. While search() will return a Match object of the first matched text in the searched string, the findall() method will return the strings of every match in the searched string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> phone_num_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'\\d\\d\\d-\\d\\d\\d-\\d\\d\\d\\d'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># has no groups</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> phone_num_regex<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span><span class=\"token string\">'Cell: 415-555-9999 Work: 212-555-0000'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'415-555-9999'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'212-555-0000'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>To summarize what the findall() method returns, remember the following:</p>\n<ul>\n<li>When called on a regex with no groups, such as \\d-\\d\\d\\d-\\d\\d\\d\\d, the method findall() returns a list of ng matches, such as ['415-555-9999', '212-555-0000'].</li>\n<li>-</li>\n<li>When called on a regex that has groups, such as (\\d\\d\\d)-(d\\d)-(\\d\\d\\d\\d), the method findall() returns a list of es of strings (one string for each group), such as [('415', '555', '9999'), ('212', '555', '0000')].</li>\n</ul>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Making Your Own Character Classes</h3>\n<p>There are times when you want to match a set of characters but the shorthand character classes (\\d, \\w, \\s, and so on) are too broad. You can define your own character class using square brackets. For example, the character class [aeiouAEIOU] will match any vowel, both lowercase and uppercase.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> vowel_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'[aeiouAEIOU]'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> vowel_regex<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span><span class=\"token string\">'Robocop eats baby food. BABY FOOD.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'o'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'o'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'o'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'e'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'o'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'o'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'O'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>You can also include ranges of letters or numbers by using a hyphen. For example, the character class [a-zA-Z0-9] will match all lowercase letters, uppercase letters, and numbers.</p>\n<p>By placing a caret character (^) just after the character class's opening bracket, you can make a negative character class. A negative character class will match all the characters that are not in the character class. For example, enter the following into the interactive shell:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> consonant_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'[^aeiouAEIOU]'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> consonant_regex<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span><span class=\"token string\">'Robocop eats baby food. BABY FOOD.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'R'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'p'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'t'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'s'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'y'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'.'</span><span class=\"token punctuation\">,</span> '\n<span class=\"token string\">', '</span><span class=\"token string\">B', '</span><span class=\"token string\">B', '</span>Y<span class=\"token string\">', '</span> <span class=\"token string\">', '</span><span class=\"token string-interpolation\"><span class=\"token string\">F', '</span></span>D<span class=\"token string\">', '</span><span class=\"token punctuation\">.</span>'<span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The Caret and Dollar Sign Characters</h3>\n<ul>\n<li>You can also use the caret symbol (^) at the start of a regex to indicate that a match must occur at the beginning of the searched text.</li>\n<li>-</li>\n<li>Likewise, you can put a dollar sign ($) at the end of the regex to indicate the string must end with this regex pattern.</li>\n<li>And you can use the ^ and $ together to indicate that the entire string must match the regex—that is, it's not enough for a match to be made on some subset of the string.</li>\n</ul>\n<p>The r'^Hello' regular expression string matches strings that begin with 'Hello':</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> begins_with_hello <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'^Hello'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> begins_with_hello<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">&lt;</span>_sre<span class=\"token punctuation\">.</span>SRE_Match <span class=\"token builtin\">object</span><span class=\"token punctuation\">;</span> span<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">match</span><span class=\"token operator\">=</span><span class=\"token string\">'Hello'</span><span class=\"token operator\">></span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> begins_with_hello<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'He said hello.'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p>The r'\\d$' regular expression string matches strings that end with a numeric character from 0 to 9:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> whole_string_is_num <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'^\\d+$'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> whole_string_is_num<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'1234567890'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">&lt;</span>_sre<span class=\"token punctuation\">.</span>SRE_Match <span class=\"token builtin\">object</span><span class=\"token punctuation\">;</span> span<span class=\"token operator\">=</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">match</span><span class=\"token operator\">=</span><span class=\"token string\">'1234567890'</span><span class=\"token operator\">></span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> whole_string_is_num<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'12345xyz67890'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span>\n<span class=\"token boolean\">True</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> whole_string_is_num<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'12 34567890'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">is</span> <span class=\"token boolean\">None</span>\n<span class=\"token boolean\">True</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The Wildcard Character</h3>\n<p>The . (or dot) character in a regular expression is called a wildcard and will match any character except for a newline:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> at_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'.at'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> at_regex<span class=\"token punctuation\">.</span>findall<span class=\"token punctuation\">(</span><span class=\"token string\">'The cat in the hat sat on the flat mat.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'sat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'lat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'mat'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Matching Everything with Dot-Star</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> name_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'First Name: (.*) Last Name: (.*)'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo <span class=\"token operator\">=</span> name_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'First Name: Al Last Name: Sweigart'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Al'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Sweigart'</span></code></pre></div>\n<p>The dot-star uses greedy mode: It will always try to match as much text as possible. To match any and all text in a nongreedy fashion, use the dot, star, and question mark (.*?). The question mark tells Python to match in a nongreedy way:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> nongreedy_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'&lt;.*?>'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo <span class=\"token operator\">=</span> nongreedy_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'&lt;To serve man> for dinner.>'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'&lt;To serve man>'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> greedy_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'&lt;.*>'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo <span class=\"token operator\">=</span> greedy_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'&lt;To serve man> for dinner.>'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> mo<span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'&lt;To serve man> for dinner.>'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Matching Newlines with the Dot Character</h3>\n<p>The dot-star will match everything except a newline. By passing re.DOTALL as the second argument to re.compile(), you can make the dot character match all characters, including the newline character:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> no_newline_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.*'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> no_newline_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Serve the public trust.\\nProtect the innocent.\\nUphold the law.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Serve the public trust.'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> newline_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.*'</span><span class=\"token punctuation\">,</span> re<span class=\"token punctuation\">.</span>DOTALL<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> newline_regex<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Serve the public trust.\\nProtect the innocent.\\nUphold the law.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Serve the public trust.\\nProtect the innocent.\\nUphold the law.'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Review of Regex Symbols</h3>\n<table>\n<thead>\n<tr>\n<th>Symbol</th>\n<th>Matches</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">?</code></td>\n<td>zero or one of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">*</code></td>\n<td>zero or more of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">+</code></td>\n<td>one or more of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{n}</code></td>\n<td>exactly n of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{n,}</code></td>\n<td>n or more of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{,m}</code></td>\n<td>0 to m of the preceding group.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{n,m}</code></td>\n<td>at least n and at most m of the preceding p.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">{n,m}?</code> or <code class=\"language-text\">*?</code> or <code class=\"language-text\">+?</code></td>\n<td>performs a nongreedy match of the preceding p.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">^spam</code></td>\n<td>means the string must begin with spam.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">spam$</code></td>\n<td>means the string must end with spam.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">.</code></td>\n<td>any character, except newline characters.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\d</code>, <code class=\"language-text\">\\w</code>, and <code class=\"language-text\">\\s</code></td>\n<td>a digit, word, or space character, respectively.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">\\D</code>, <code class=\"language-text\">\\W</code>, and <code class=\"language-text\">\\S</code></td>\n<td>anything except a digit, word, or space, respectively.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">[abc]</code></td>\n<td>any character between the brackets (such as a, b, ).</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">[^abc]</code></td>\n<td>any character that isn't between the brackets.</td>\n</tr>\n</tbody>\n</table>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Case-Insensitive Matching</h3>\n<p>To make your regex case-insensitive, you can pass re.IGNORECASE or re.I as a second argument to re.compile():</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> robocop <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'robocop'</span><span class=\"token punctuation\">,</span> re<span class=\"token punctuation\">.</span>I<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> robocop<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Robocop is part man, part machine, all cop.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'Robocop'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> robocop<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'ROBOCOP protects the innocent.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'ROBOCOP'</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> robocop<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">(</span><span class=\"token string\">'Al, why does your programming book talk about robocop so much?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>group<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'robocop'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Substituting Strings with the sub() Method</h3>\n<p>The sub() method for Regex objects is passed two arguments:</p>\n<ol>\n<li>The first argument is a string to replace any matches.</li>\n<li>The second is the string for the regular expression.</li>\n</ol>\n<p>The sub() method returns a string with the substitutions applied:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> names_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Agent \\w+'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> names_regex<span class=\"token punctuation\">.</span>sub<span class=\"token punctuation\">(</span><span class=\"token string\">'CENSORED'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Agent Alice gave the secret documents to Agent Bob.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'CENSORED gave the secret documents to CENSORED.'</span></code></pre></div>\n<p>Another example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> agent_names_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'Agent (\\w)\\w*'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> agent_names_regex<span class=\"token punctuation\">.</span>sub<span class=\"token punctuation\">(</span><span class=\"token string\">r'\\1****'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Agent Alice told Agent Carol that Agent Eve knew Agent Bob was a double agent.'</span><span class=\"token punctuation\">)</span>\nA<span class=\"token operator\">**</span><span class=\"token operator\">**</span> told C<span class=\"token operator\">**</span><span class=\"token operator\">**</span> that E<span class=\"token operator\">**</span><span class=\"token operator\">**</span> knew B<span class=\"token operator\">**</span><span class=\"token operator\">**</span> was a double agent<span class=\"token punctuation\">.</span>'</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Managing Complex Regexes</h3>\n<p>To tell the re.compile() function to ignore whitespace and comments inside the regular expression string, \"verbose mode\" can be enabled by passing the variable re.VERBOSE as the second argument to re.compile().</p>\n<p>Now instead of a hard-to-read regular expression like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">phone_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token string\">r'((\\d{3}|\\(\\d{3}\\))?(\\s|-|\\.)?\\d{3}(\\s|-|\\.)\\d{4}(\\s*(ext|x|ext.)\\s*\\d{2,5})?)'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>you can spread the regular expression over multiple lines with comments like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">phone_regex <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token builtin\">compile</span><span class=\"token punctuation\">(</span><span class=\"token triple-quoted-string string\">r'''(\n    (\\d{3}|\\(\\d{3}\\))?            # area code\n    (\\s|-|\\.)?                    # separator\n    \\d{3}                         # first 3 digits\n    (\\s|-|\\.)                     # separator\n    \\d{4}                         # last 4 digits\n    (\\s*(ext|x|ext.)\\s*\\d{2,5})?  # extension\n    )'''</span><span class=\"token punctuation\">,</span> re<span class=\"token punctuation\">.</span>VERBOSE<span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Handling File and Directory Paths</h2>\n<p>There are two main modules in Python that deals with path manipulation.\nOne is the <code class=\"language-text\">os.path</code> module and the other is the <code class=\"language-text\">pathlib</code> module.\nThe <code class=\"language-text\">pathlib</code> module was added in Python 3.4, offering an object-oriented way\nto handle file system paths.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Backslash on Windows and Forward Slash on OS X and Linux</h3>\n<p>On Windows, paths are written using backslashes (<code class=\"language-text\">\\</code>) as the separator between\nfolder names. On Unix based operating system such as macOS, Linux, and BSDs,\nthe forward slash (<code class=\"language-text\">/</code>) is used as the path separator. Joining paths can be\na headache if your code needs to work on different platforms.</p>\n<p>Fortunately, Python provides easy ways to handle this. We will showcase\nhow to deal with this with both <code class=\"language-text\">os.path.join</code> and <code class=\"language-text\">pathlib.Path.joinpath</code></p>\n<p>Using <code class=\"language-text\">os.path.join</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token string\">'usr'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bin'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'spam'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'usr\\\\bin\\\\spam'</span></code></pre></div>\n<p>And using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">(</span><span class=\"token string\">'usr'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>joinpath<span class=\"token punctuation\">(</span><span class=\"token string\">'bin'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>joinpath<span class=\"token punctuation\">(</span><span class=\"token string\">'spam'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nusr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>spam</code></pre></div>\n<p><code class=\"language-text\">pathlib</code> also provides a shortcut to joinpath using the <code class=\"language-text\">/</code> operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">(</span><span class=\"token string\">'usr'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token string\">'bin'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'spam'</span><span class=\"token punctuation\">)</span>\nusr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>spam</code></pre></div>\n<p>Notice the path separator is different between Windows and Unix based operating\nsystem, that's why you want to use one of the above methods instead of\nadding strings together to join paths together.</p>\n<p>Joining paths is helpful if you need to create different file paths under\nthe same directory.</p>\n<p>Using <code class=\"language-text\">os.path.join</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> my_files <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'accounts.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'details.csv'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'invite.docx'</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> filename <span class=\"token keyword\">in</span> my_files<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Users\\\\asweigart'</span><span class=\"token punctuation\">,</span> filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nC<span class=\"token punctuation\">:</span>\\Users\\asweigart\\accounts<span class=\"token punctuation\">.</span>txt\nC<span class=\"token punctuation\">:</span>\\Users\\asweigart\\details<span class=\"token punctuation\">.</span>csv\nC<span class=\"token punctuation\">:</span>\\Users\\asweigart\\invite<span class=\"token punctuation\">.</span>docx</code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> my_files <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'accounts.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'details.csv'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'invite.docx'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> home <span class=\"token operator\">=</span> Path<span class=\"token punctuation\">.</span>home<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> filename <span class=\"token keyword\">in</span> my_files<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>home <span class=\"token operator\">/</span> filename<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">/</span>home<span class=\"token operator\">/</span>asweigart<span class=\"token operator\">/</span>accounts<span class=\"token punctuation\">.</span>txt\n<span class=\"token operator\">/</span>home<span class=\"token operator\">/</span>asweigart<span class=\"token operator\">/</span>details<span class=\"token punctuation\">.</span>csv\n<span class=\"token operator\">/</span>home<span class=\"token operator\">/</span>asweigart<span class=\"token operator\">/</span>invite<span class=\"token punctuation\">.</span>docx</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>The Current Working Directory</h3>\n<p>Using <code class=\"language-text\">os</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>getcwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'C:\\\\Python34'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>getcwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'C:\\\\Windows\\\\System32'</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> os <span class=\"token keyword\">import</span> chdir\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">/</span>home<span class=\"token operator\">/</span>asweigart\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'/usr/lib/python3.6'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span>lib<span class=\"token operator\">/</span>python3<span class=\"token punctuation\">.</span><span class=\"token number\">6</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Creating New Folders</h3>\n<p>Using <code class=\"language-text\">os</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>makedirs<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\delicious\\\\walnut\\\\waffles'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> cwd <span class=\"token operator\">=</span> Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span>cwd <span class=\"token operator\">/</span> <span class=\"token string\">'delicious'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'walnut'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'waffles'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>mkdir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n  File <span class=\"token string\">\"/usr/lib/python3.6/pathlib.py\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1226</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> mkdir\n    self<span class=\"token punctuation\">.</span>_accessor<span class=\"token punctuation\">.</span>mkdir<span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> mode<span class=\"token punctuation\">)</span>\n  File <span class=\"token string\">\"/usr/lib/python3.6/pathlib.py\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">387</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> wrapped\n    <span class=\"token keyword\">return</span> strfunc<span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>pathobj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span>\nFileNotFoundError<span class=\"token punctuation\">:</span> <span class=\"token punctuation\">[</span>Errno <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> No such <span class=\"token builtin\">file</span> <span class=\"token keyword\">or</span> directory<span class=\"token punctuation\">:</span> <span class=\"token string\">'/home/asweigart/delicious/walnut/waffles'</span></code></pre></div>\n<p>Oh no, we got a nasty error! The reason is that the 'delicious' directory does\nnot exist, so we cannot make the 'walnut' and the 'waffles' directories under\nit. To fix this, do:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> cwd <span class=\"token operator\">=</span> Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span>cwd <span class=\"token operator\">/</span> <span class=\"token string\">'delicious'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'walnut'</span> <span class=\"token operator\">/</span> <span class=\"token string\">'waffles'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>mkdir<span class=\"token punctuation\">(</span>parents<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>And all is good :)</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Absolute vs. Relative Paths</h3>\n<p>There are two ways to specify a file path.</p>\n<ul>\n<li>An absolute path, which always begins with the root folder</li>\n<li>A relative path, which is relative to the program's current working directory</li>\n</ul>\n<p>There are also the dot (.) and dot-dot (..) folders. These are not real folders but special names that can be used in a path. A single period (\"dot\") for a folder name is shorthand for \"this directory.\" Two periods (\"dot-dot\") means \"the parent folder.\"</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Handling Absolute and Relative Paths</h3>\n<p>To see if a path is an absolute path:</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isabs<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isabs<span class=\"token punctuation\">(</span><span class=\"token string\">'..'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_absolute<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'..'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_absolute<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p>You can extract an absolute path with both <code class=\"language-text\">os.path</code> and <code class=\"language-text\">pathlib</code></p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>getcwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'/home/asweigart'</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>abspath<span class=\"token punctuation\">(</span><span class=\"token string\">'..'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'/home'</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">.</span>cwd<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">/</span>home<span class=\"token operator\">/</span>asweigart\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">(</span><span class=\"token string\">'..'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>resolve<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">/</span>home</code></pre></div>\n<p>You can get a relative path from a starting path to another path.</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>relpath<span class=\"token punctuation\">(</span><span class=\"token string\">'/etc/passwd'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'etc/passwd'</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/etc/passwd'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>relative_to<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\netc<span class=\"token operator\">/</span>passwd</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Checking Path Validity</h3>\n<p>Checking if a file/directory exists:</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token string\">'/etc'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token string\">'nonexistentfile'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/etc'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'nonexistentfile'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>exists<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p>Checking if a path is a file:</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isfile<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isfile<span class=\"token punctuation\">(</span><span class=\"token string\">'/home'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isfile<span class=\"token punctuation\">(</span><span class=\"token string\">'nonexistentfile'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_file<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/home'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_file<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'nonexistentfile'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_file<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p>Checking if a path is a directory:</p>\n<p>Using <code class=\"language-text\">os.path</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isdir<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isdir<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>isdir<span class=\"token punctuation\">(</span><span class=\"token string\">'/spam'</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_dir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">True</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'setup.py'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_dir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/spam'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>is_dir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">False</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Finding File Sizes and Folder Contents</h3>\n<p>Getting a file's size in bytes:</p>\n<p>Using <code class=\"language-text\">os.path</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>getsize<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32\\\\calc.exe'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">776192</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> stat <span class=\"token operator\">=</span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/bin/python3.6'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>stat<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>stat<span class=\"token punctuation\">)</span> <span class=\"token comment\"># stat contains some other information about the file as well</span>\nos<span class=\"token punctuation\">.</span>stat_result<span class=\"token punctuation\">(</span>st_mode<span class=\"token operator\">=</span><span class=\"token number\">33261</span><span class=\"token punctuation\">,</span> st_ino<span class=\"token operator\">=</span><span class=\"token number\">141087</span><span class=\"token punctuation\">,</span> st_dev<span class=\"token operator\">=</span><span class=\"token number\">2051</span><span class=\"token punctuation\">,</span> st_nlink<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> st_uid<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n<span class=\"token operator\">-</span><span class=\"token operator\">-</span>snip<span class=\"token operator\">-</span><span class=\"token operator\">-</span>\nst_gid<span class=\"token operator\">=</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> st_size<span class=\"token operator\">=</span><span class=\"token number\">10024</span><span class=\"token punctuation\">,</span> st_atime<span class=\"token operator\">=</span><span class=\"token number\">1517725562</span><span class=\"token punctuation\">,</span> st_mtime<span class=\"token operator\">=</span><span class=\"token number\">1515119809</span><span class=\"token punctuation\">,</span> st_ctime<span class=\"token operator\">=</span><span class=\"token number\">1517261276</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>stat<span class=\"token punctuation\">.</span>st_size<span class=\"token punctuation\">)</span> <span class=\"token comment\"># size in bytes</span>\n<span class=\"token number\">10024</span></code></pre></div>\n<p>Listing directory contents using <code class=\"language-text\">os.listdir</code> on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>listdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'0409'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'12520437.cpx'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'12520850.cpx'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'5U877.ax'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'aaclient.dll'</span><span class=\"token punctuation\">,</span>\n<span class=\"token operator\">-</span><span class=\"token operator\">-</span>snip<span class=\"token operator\">-</span><span class=\"token operator\">-</span>\n<span class=\"token string\">'xwtpdui.dll'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'xwtpw32.dll'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'zh-CN'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'zh-HK'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'zh-TW'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'zipfldr.dll'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Listing directory contents using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> f <span class=\"token keyword\">in</span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/usr/bin'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>iterdir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>tiff2rgba\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>iconv\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>ldd\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>cache_restore\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>udiskie\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>unix2dos\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>t1reencode\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>epstopdf\n<span class=\"token operator\">/</span>usr<span class=\"token operator\">/</span><span class=\"token builtin\">bin</span><span class=\"token operator\">/</span>idle3\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>To find the total size of all the files in this directory:</p>\n<p><strong>WARNING</strong>: Directories themselves also have a size! So you might want to\ncheck for whether a path is a file or directory using the methods in the methods discussed in the above section!</p>\n<p>Using <code class=\"language-text\">os.path.getsize()</code> and <code class=\"language-text\">os.listdir()</code> together on Windows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> total_size <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> filename <span class=\"token keyword\">in</span> os<span class=\"token punctuation\">.</span>listdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      total_size <span class=\"token operator\">=</span> total_size <span class=\"token operator\">+</span> os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>getsize<span class=\"token punctuation\">(</span>os<span class=\"token punctuation\">.</span>path<span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Windows\\\\System32'</span><span class=\"token punctuation\">,</span> filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>total_size<span class=\"token punctuation\">)</span>\n<span class=\"token number\">1117846456</span></code></pre></div>\n<p>Using <code class=\"language-text\">pathlib</code> on *nix:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> pathlib <span class=\"token keyword\">import</span> Path\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> total_size <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> sub_path <span class=\"token keyword\">in</span> Path<span class=\"token punctuation\">(</span><span class=\"token string\">'/usr/bin'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>iterdir<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     total_size <span class=\"token operator\">+=</span> sub_path<span class=\"token punctuation\">.</span>stat<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>st_size\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>total_size<span class=\"token punctuation\">)</span>\n<span class=\"token number\">1903178911</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Copying Files and Folders</h3>\n<p>The shutil module provides functions for copying files, as well as entire folders.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> shutil<span class=\"token punctuation\">,</span> os\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> shutil<span class=\"token punctuation\">.</span>copy<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\spam.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\delicious'</span><span class=\"token punctuation\">)</span>\n   <span class=\"token string\">'C:\\\\delicious\\\\spam.txt'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> shutil<span class=\"token punctuation\">.</span>copy<span class=\"token punctuation\">(</span><span class=\"token string\">'eggs.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\delicious\\\\eggs2.txt'</span><span class=\"token punctuation\">)</span>\n   <span class=\"token string\">'C:\\\\delicious\\\\eggs2.txt'</span></code></pre></div>\n<p>While shutil.copy() will copy a single file, shutil.copytree() will copy an entire folder and every folder and file contained in it:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> shutil<span class=\"token punctuation\">,</span> os\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> shutil<span class=\"token punctuation\">.</span>copytree<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\bacon'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\bacon_backup'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'C:\\\\bacon_backup'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Moving and Renaming Files and Folders</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> shutil\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> shutil<span class=\"token punctuation\">.</span>move<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\eggs'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'C:\\\\eggs\\\\bacon.txt'</span></code></pre></div>\n<p>The destination path can also specify a filename. In the following example, the source file is moved and renamed:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> shutil<span class=\"token punctuation\">.</span>move<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\eggs\\\\new_bacon.txt'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'C:\\\\eggs\\\\new_bacon.txt'</span></code></pre></div>\n<p>If there is no eggs folder, then move() will rename bacon.txt to a file named eggs.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> shutil<span class=\"token punctuation\">.</span>move<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\eggs'</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'C:\\\\eggs'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Permanently Deleting Files and Folders</h3>\n<ul>\n<li>Calling os.unlink(path) or Path.unlink() will delete the file at path.</li>\n<li>-</li>\n<li>Calling os.rmdir(path) or Path.rmdir() will delete the folder at path. This folder must be empty of any files or folders.</li>\n<li>Calling shutil.rmtree(path) will remove the folder at path, and all files and folders it contains will also be deleted.</li>\n</ul>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Safe Deletes with the send2trash Module</h3>\n<p>You can install this module by running pip install send2trash from a Terminal window.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> send2trash\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> bacon_file<span class=\"token punctuation\">:</span> <span class=\"token comment\"># creates the file</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     bacon_file<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'Bacon is not a vegetable.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">25</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> send2trash<span class=\"token punctuation\">.</span>send2trash<span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Walking a Directory Tree</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> os\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> folder_name<span class=\"token punctuation\">,</span> subfolders<span class=\"token punctuation\">,</span> filenames <span class=\"token keyword\">in</span> os<span class=\"token punctuation\">.</span>walk<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\delicious'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The current folder is {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>folder_name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">for</span> subfolder <span class=\"token keyword\">in</span> subfolders<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'SUBFOLDER OF {}: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>folder_name<span class=\"token punctuation\">,</span> subfolder<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">for</span> filename <span class=\"token keyword\">in</span> filenames<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'FILE INSIDE {}: {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>folder_name<span class=\"token punctuation\">,</span> filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\nThe current folder <span class=\"token keyword\">is</span> C<span class=\"token punctuation\">:</span>\\delicious\nSUBFOLDER OF C<span class=\"token punctuation\">:</span>\\delicious<span class=\"token punctuation\">:</span> cats\nSUBFOLDER OF C<span class=\"token punctuation\">:</span>\\delicious<span class=\"token punctuation\">:</span> walnut\nFILE INSIDE C<span class=\"token punctuation\">:</span>\\delicious<span class=\"token punctuation\">:</span> spam<span class=\"token punctuation\">.</span>txt\n\nThe current folder <span class=\"token keyword\">is</span> C<span class=\"token punctuation\">:</span>\\delicious\\cats\nFILE INSIDE C<span class=\"token punctuation\">:</span>\\delicious\\cats<span class=\"token punctuation\">:</span> catnames<span class=\"token punctuation\">.</span>txt\nFILE INSIDE C<span class=\"token punctuation\">:</span>\\delicious\\cats<span class=\"token punctuation\">:</span> zophie<span class=\"token punctuation\">.</span>jpg\n\nThe current folder <span class=\"token keyword\">is</span> C<span class=\"token punctuation\">:</span>\\delicious\\walnut\nSUBFOLDER OF C<span class=\"token punctuation\">:</span>\\delicious\\walnut<span class=\"token punctuation\">:</span> waffles\n\nThe current folder <span class=\"token keyword\">is</span> C<span class=\"token punctuation\">:</span>\\delicious\\walnut\\waffles\nFILE INSIDE C<span class=\"token punctuation\">:</span>\\delicious\\walnut\\waffles<span class=\"token punctuation\">:</span> butter<span class=\"token punctuation\">.</span>txt</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<p><code class=\"language-text\">pathlib</code> provides a lot more functionality than the ones listed above,\nlike getting file name, getting file extension, reading/writing a file without\nmanually opening it, etc. Check out the\n<a href=\"https://docs.python.org/3/library/pathlib.html\">official documentation</a>\nif you want to know more!</p>\n<h2>Reading and Writing Files</h2>\n<h3>The File Reading/Writing Process</h3>\n<p>To read/write to a file in Python, you will want to use the <code class=\"language-text\">with</code>\nstatement, which will close the file for you after you are done.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Opening and reading files with the open() function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\Users\\\\your_home_folder\\\\hello.txt'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> hello_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     hello_content <span class=\"token operator\">=</span> hello_file<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> hello_content\n<span class=\"token string\">'Hello World!'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token comment\"># Alternatively, you can use the *readlines()* method to get a list of string values from the file, one string for each line of text:</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'sonnet29.txt'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> sonnet_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     sonnet_file<span class=\"token punctuation\">.</span>readlines<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span>When<span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> disgrace <span class=\"token keyword\">with</span> fortune <span class=\"token keyword\">and</span> men<span class=\"token string\">'s eyes,\\n'</span><span class=\"token punctuation\">,</span> ' I <span class=\"token builtin\">all</span> alone beweep my\noutcast state<span class=\"token punctuation\">,</span>\\n<span class=\"token string\">', And trouble deaf heaven with my bootless cries,\\n'</span><span class=\"token punctuation\">,</span> And\nlook upon myself <span class=\"token keyword\">and</span> curse my fate<span class=\"token punctuation\">,</span>'<span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token comment\"># You can also iterate through the file line by line:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'sonnet29.txt'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> sonnet_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> line <span class=\"token keyword\">in</span> sonnet_file<span class=\"token punctuation\">:</span> <span class=\"token comment\"># note the new line character will be included in the line</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>         <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>line<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n\nWhen<span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> disgrace <span class=\"token keyword\">with</span> fortune <span class=\"token keyword\">and</span> men's eyes<span class=\"token punctuation\">,</span>\nI <span class=\"token builtin\">all</span> alone beweep my outcast state<span class=\"token punctuation\">,</span>\nAnd trouble deaf heaven <span class=\"token keyword\">with</span> my bootless cries<span class=\"token punctuation\">,</span>\nAnd look upon myself <span class=\"token keyword\">and</span> curse my fate<span class=\"token punctuation\">,</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Writing to Files</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'w'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> bacon_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     bacon_file<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!\\n'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">13</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> bacon_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     bacon_file<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'Bacon is not a vegetable.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">25</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'bacon.txt'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> bacon_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     content <span class=\"token operator\">=</span> bacon_file<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>content<span class=\"token punctuation\">)</span>\nHello world!\nBacon <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> a vegetable<span class=\"token punctuation\">.</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Saving Variables with the shelve Module</h3>\n<p>To save variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> shelve\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> cats <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> shelve<span class=\"token punctuation\">.</span><span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'mydata'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> shelf_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     shelf_file<span class=\"token punctuation\">[</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> cats</code></pre></div>\n<p>To open and read variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> shelve<span class=\"token punctuation\">.</span><span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'mydata'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> shelf_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>shelf_file<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>shelf_file<span class=\"token punctuation\">[</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'shelve.DbfilenameShelf'</span><span class=\"token operator\">></span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Just like dictionaries, shelf values have keys() and values() methods that will return list-like values of the keys and values in the shelf. Since these methods return list-like values instead of true lists, you should pass them to the list() function to get them in list form.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> shelve<span class=\"token punctuation\">.</span><span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'mydata'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> shelf_file<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>shelf_file<span class=\"token punctuation\">.</span>keys<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">list</span><span class=\"token punctuation\">(</span>shelf_file<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span><span class=\"token string\">'cats'</span><span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Simon'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Saving Variables with the pprint.pformat() Function</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> pprint\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> cats <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Zophie'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'desc'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'chubby'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'Pooka'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'desc'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'fluffy'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> pprint<span class=\"token punctuation\">.</span>pformat<span class=\"token punctuation\">(</span>cats<span class=\"token punctuation\">)</span>\n<span class=\"token string\">\"[{'desc': 'chubby', 'name': 'Zophie'}, {'desc': 'fluffy', 'name': 'Pooka'}]\"</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'myCats.py'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'w'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> file_obj<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     file_obj<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'cats = {}\\n'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>pprint<span class=\"token punctuation\">.</span>pformat<span class=\"token punctuation\">(</span>cats<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">83</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Reading ZIP Files</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> zipfile<span class=\"token punctuation\">,</span> os\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\'</span><span class=\"token punctuation\">)</span>    <span class=\"token comment\"># move to the folder with example.zip</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> zipfile<span class=\"token punctuation\">.</span>ZipFile<span class=\"token punctuation\">(</span><span class=\"token string\">'example.zip'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> example_zip<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>example_zip<span class=\"token punctuation\">.</span>namelist<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     spam_info <span class=\"token operator\">=</span> example_zip<span class=\"token punctuation\">.</span>getinfo<span class=\"token punctuation\">(</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam_info<span class=\"token punctuation\">.</span>file_size<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>spam_info<span class=\"token punctuation\">.</span>compress_size<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Compressed file is %sx smaller!'</span> <span class=\"token operator\">%</span> <span class=\"token punctuation\">(</span><span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span>spam_info<span class=\"token punctuation\">.</span>file_size <span class=\"token operator\">/</span> spam_info<span class=\"token punctuation\">.</span>compress_size<span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">[</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats/'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats/catnames.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cats/zophie.jpg'</span><span class=\"token punctuation\">]</span>\n<span class=\"token number\">13908</span>\n<span class=\"token number\">3828</span>\n<span class=\"token string\">'Compressed file is 3.63x smaller!'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Extracting from ZIP Files</h3>\n<p>The extractall() method for ZipFile objects extracts all the files and folders from a ZIP file into the current working directory.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> zipfile<span class=\"token punctuation\">,</span> os\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> os<span class=\"token punctuation\">.</span>chdir<span class=\"token punctuation\">(</span><span class=\"token string\">'C:\\\\'</span><span class=\"token punctuation\">)</span>    <span class=\"token comment\"># move to the folder with example.zip</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> zipfile<span class=\"token punctuation\">.</span>ZipFile<span class=\"token punctuation\">(</span><span class=\"token string\">'example.zip'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> example_zip<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     example_zip<span class=\"token punctuation\">.</span>extractall<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The extract() method for ZipFile objects will extract a single file from the ZIP file. Continue the interactive shell example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> zipfile<span class=\"token punctuation\">.</span>ZipFile<span class=\"token punctuation\">(</span><span class=\"token string\">'example.zip'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> example_zip<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>example_zip<span class=\"token punctuation\">.</span>extract<span class=\"token punctuation\">(</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>example_zip<span class=\"token punctuation\">.</span>extract<span class=\"token punctuation\">(</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C:\\\\some\\\\new\\\\folders'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token string\">'C:\\\\spam.txt'</span>\n<span class=\"token string\">'C:\\\\some\\\\new\\\\folders\\\\spam.txt'</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Creating and Adding to ZIP Files</h3>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> zipfile\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> zipfile<span class=\"token punctuation\">.</span>ZipFile<span class=\"token punctuation\">(</span><span class=\"token string\">'new.zip'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'w'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> new_zip<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     new_zip<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span><span class=\"token string\">'spam.txt'</span><span class=\"token punctuation\">,</span> compress_type<span class=\"token operator\">=</span>zipfile<span class=\"token punctuation\">.</span>ZIP_DEFLATED<span class=\"token punctuation\">)</span></code></pre></div>\n<p>This code will create a new ZIP file named new.zip that has the compressed contents of spam.txt.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>JSON, YAML and configuration files</h2>\n<h3>JSON</h3>\n<p>Open a JSON file with:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> json\n<span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"filename.json\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"r\"</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> f<span class=\"token punctuation\">:</span>\n    content <span class=\"token operator\">=</span> json<span class=\"token punctuation\">.</span>loads<span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Write a JSON file with:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> json\n\ncontent <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">\"name\"</span><span class=\"token punctuation\">:</span> <span class=\"token string\">\"Joe\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"age\"</span><span class=\"token punctuation\">:</span> <span class=\"token number\">20</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"filename.json\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"w\"</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> f<span class=\"token punctuation\">:</span>\n    f<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span>json<span class=\"token punctuation\">.</span>dumps<span class=\"token punctuation\">(</span>content<span class=\"token punctuation\">,</span> indent<span class=\"token operator\">=</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>YAML</h3>\n<p>Compared to JSON, YAML allows for much better human maintainability and gives you the option to add comments.\nIt is a convenient choice for configuration files where humans will have to edit it.</p>\n<p>There are two main libraries allowing to access to YAML files:</p>\n<ul>\n<li><a href=\"https://pypi.python.org/pypi/PyYAML\">PyYaml</a></li>\n<li><a href=\"https://pypi.python.org/pypi/ruamel.yaml\">Ruamel.yaml</a></li>\n</ul>\n<p>Install them using <code class=\"language-text\">pip install</code> in your virtual environment.</p>\n<p>The first one it easier to use but the second one, Ruamel, implements much better the YAML\nspecification, and allow for example to modify a YAML content without altering comments.</p>\n<p>Open a YAML file with:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> ruamel<span class=\"token punctuation\">.</span>yaml <span class=\"token keyword\">import</span> YAML\n\n<span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"filename.yaml\"</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> f<span class=\"token punctuation\">:</span>\n    yaml<span class=\"token operator\">=</span>YAML<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    yaml<span class=\"token punctuation\">.</span>load<span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Anyconfig</h3>\n<p><a href=\"https://pypi.python.org/pypi/anyconfig\">Anyconfig</a> is a very handy package allowing to abstract completely the underlying configuration file format. It allows to load a Python dictionary from JSON, YAML, TOML, and so on.</p>\n<p>Install it with:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">pip <span class=\"token function\">install</span> anyconfig</code></pre></div>\n<p>Usage:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> anyconfig\n\nconf1 <span class=\"token operator\">=</span> anyconfig<span class=\"token punctuation\">.</span>load<span class=\"token punctuation\">(</span><span class=\"token string\">\"/path/to/foo/conf.d/a.yml\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Debugging</h2>\n<h3>Raising Exceptions</h3>\n<p>Exceptions are raised with a raise statement. In code, a raise statement consists of the following:</p>\n<ul>\n<li>The raise keyword</li>\n<li>A call to the Exception() function</li>\n<li>A string with a helpful error message passed to the Exception() function</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'This is the error message.'</span><span class=\"token punctuation\">)</span>\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;pyshell#191>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'This is the error message.'</span><span class=\"token punctuation\">)</span>\nException<span class=\"token punctuation\">:</span> This <span class=\"token keyword\">is</span> the error message<span class=\"token punctuation\">.</span></code></pre></div>\n<p>Often it's the code that calls the function, not the function itself, that knows how to handle an exception. So you will commonly see a raise statement inside a function and the try and except statements in the code calling the function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">box_print</span><span class=\"token punctuation\">(</span>symbol<span class=\"token punctuation\">,</span> width<span class=\"token punctuation\">,</span> height<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> <span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>symbol<span class=\"token punctuation\">)</span> <span class=\"token operator\">!=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'Symbol must be a single character string.'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> width <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'Width must be greater than 2.'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> height <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n      <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'Height must be greater than 2.'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>symbol <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>height <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>symbol <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token string\">' '</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>width <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> symbol<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>symbol <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> sym<span class=\"token punctuation\">,</span> w<span class=\"token punctuation\">,</span> h <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">'*'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'O'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'x'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'ZZ'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span>\n        box_print<span class=\"token punctuation\">(</span>sym<span class=\"token punctuation\">,</span> w<span class=\"token punctuation\">,</span> h<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">except</span> Exception <span class=\"token keyword\">as</span> err<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'An exception happened: '</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Getting the Traceback as a String</h3>\n<p>The traceback is displayed by Python whenever a raised exception goes unhandled. But can also obtain it as a string by calling traceback.format_exc(). This function is useful if you want the information from an exception's traceback but also want an except statement to gracefully handle the exception. You will need to import Python's traceback module before calling this function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> traceback\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>      <span class=\"token keyword\">raise</span> Exception<span class=\"token punctuation\">(</span><span class=\"token string\">'This is the error message.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">except</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>      <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'errorInfo.txt'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'w'</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> error_file<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>          error_file<span class=\"token punctuation\">.</span>write<span class=\"token punctuation\">(</span>traceback<span class=\"token punctuation\">.</span>format_exc<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>      <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The traceback info was written to errorInfo.txt.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">116</span>\nThe traceback info was written to errorInfo<span class=\"token punctuation\">.</span>txt<span class=\"token punctuation\">.</span></code></pre></div>\n<p>The 116 is the return value from the write() method, since 116 characters were written to the file. The traceback text was written to errorInfo.txt.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Traceback (most recent call last):\n  File \"&lt;pyshell#28>\", line 2, in &lt;module>\nException: This is the error message.</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Assertions</h3>\n<p>An assertion is a sanity check to make sure your code isn't doing something obviously wrong. These sanity checks are performed by assert statements. If the sanity check fails, then an AssertionError exception is raised. In code, an assert statement consists of the following:</p>\n<ul>\n<li>The assert keyword</li>\n<li>A condition (that is, an expression that evaluates to True or False)</li>\n<li>A comma</li>\n<li>A string to display when the condition is False</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> pod_bay_door_status <span class=\"token operator\">=</span> <span class=\"token string\">'open'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">assert</span> pod_bay_door_status <span class=\"token operator\">==</span> <span class=\"token string\">'open'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The pod bay doors need to be \"open\".'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> pod_bay_door_status <span class=\"token operator\">=</span> <span class=\"token string\">'I\\'m sorry, Dave. I\\'m afraid I can\\'t do that.'</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">assert</span> pod_bay_door_status <span class=\"token operator\">==</span> <span class=\"token string\">'open'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The pod bay doors need to be \"open\".'</span>\n\nTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  File <span class=\"token string\">\"&lt;pyshell#10>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    <span class=\"token keyword\">assert</span> pod_bay_door_status <span class=\"token operator\">==</span> <span class=\"token string\">'open'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'The pod bay doors need to be \"open\".'</span>\nAssertionError<span class=\"token punctuation\">:</span> The pod bay doors need to be <span class=\"token string\">\"open\"</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>In plain English, an assert statement says, \"I assert that this condition holds true, and if not, there is a bug somewhere in the program.\" Unlike exceptions, your code should not handle assert statements with try and except; if an assert fails, your program should crash. By failing fast like this, you shorten the time between the original cause of the bug and when you first notice the bug. This will reduce the amount of code you will have to check before finding the code that's causing the bug.</p>\n<p>Disabling Assertions</p>\n<p>Assertions can be disabled by passing the -O option when running Python.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Logging</h3>\n<p>To enable the logging module to display log messages on your screen as your program runs, copy the following to the top of your program (but under the #! python shebang line):</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> logging\n\nlogging<span class=\"token punctuation\">.</span>basicConfig<span class=\"token punctuation\">(</span>level<span class=\"token operator\">=</span>logging<span class=\"token punctuation\">.</span>DEBUG<span class=\"token punctuation\">,</span> <span class=\"token builtin\">format</span><span class=\"token operator\">=</span><span class=\"token string\">' %(asctime)s - %(levelname)s- %(message)s'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Say you wrote a function to calculate the factorial of a number. In mathematics, factorial 4 is 1 × 2 × 3 × 4, or 24. Factorial 7 is 1 × 2 × 3 × 4 × 5 × 6 × 7, or 5,040. Open a new file editor window and enter the following code. It has a bug in it, but you will also enter several log messages to help yourself figure out what is going wrong. Save the program as factorialLog.py.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> logging\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>basicConfig<span class=\"token punctuation\">(</span>level<span class=\"token operator\">=</span>logging<span class=\"token punctuation\">.</span>DEBUG<span class=\"token punctuation\">,</span> <span class=\"token builtin\">format</span><span class=\"token operator\">=</span><span class=\"token string\">' %(asctime)s - %(levelname)s- %(message)s'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'Start of program'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'Start of factorial(%s)'</span> <span class=\"token operator\">%</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     total <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         total <span class=\"token operator\">*=</span> i\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>         logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'i is '</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">', total is '</span> <span class=\"token operator\">+</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>total<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'End of factorial(%s)'</span> <span class=\"token operator\">%</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     <span class=\"token keyword\">return</span> total\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>factorial<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>debug<span class=\"token punctuation\">(</span><span class=\"token string\">'End of program'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">664</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> Start of program\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">664</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> Start of factorial<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">665</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> i <span class=\"token keyword\">is</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> total <span class=\"token keyword\">is</span> <span class=\"token number\">0</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">668</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> i <span class=\"token keyword\">is</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> total <span class=\"token keyword\">is</span> <span class=\"token number\">0</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">670</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> i <span class=\"token keyword\">is</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> total <span class=\"token keyword\">is</span> <span class=\"token number\">0</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">673</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> i <span class=\"token keyword\">is</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> total <span class=\"token keyword\">is</span> <span class=\"token number\">0</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">675</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> i <span class=\"token keyword\">is</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> total <span class=\"token keyword\">is</span> <span class=\"token number\">0</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">678</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> i <span class=\"token keyword\">is</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> total <span class=\"token keyword\">is</span> <span class=\"token number\">0</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">680</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> End of factorial<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">0</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">23</span> <span class=\"token number\">16</span><span class=\"token punctuation\">:</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span><span class=\"token number\">12</span><span class=\"token punctuation\">,</span><span class=\"token number\">684</span> <span class=\"token operator\">-</span> DEBUG <span class=\"token operator\">-</span> End of program</code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Logging Levels</h3>\n<p>Logging levels provide a way to categorize your log messages by importance. There are five logging levels, described in Table 10-1 from least to most important. Messages can be logged at each level using a different logging function.</p>\n<table>\n<thead>\n<tr>\n<th>Level</th>\n<th>Logging Function</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">DEBUG</code></td>\n<td><code class=\"language-text\">logging.debug()</code></td>\n<td>The lowest level. Used for small details. Usually you care about these messages only when diagnosing problems.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">INFO</code></td>\n<td><code class=\"language-text\">logging.info()</code></td>\n<td>Used to record information on general events in your program or confirm that things are working at their point in the program.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">WARNING</code></td>\n<td><code class=\"language-text\">logging.warning()</code></td>\n<td>Used to indicate a potential problem that doesn't prevent the program from working but might do so in the future.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">ERROR</code></td>\n<td><code class=\"language-text\">logging.error()</code></td>\n<td>Used to record an error that caused the program to fail to do something.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">CRITICAL</code></td>\n<td><code class=\"language-text\">logging.critical()</code></td>\n<td>The highest level. Used to indicate a fatal error that has caused or is about to cause the program to stop running entirely.</td>\n</tr>\n</tbody>\n</table>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Disabling Logging</h3>\n<p>After you've debugged your program, you probably don't want all these log messages cluttering the screen. The logging.disable() function disables these so that you don't have to go into your program and remove all the logging calls by hand.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> logging\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>basicConfig<span class=\"token punctuation\">(</span>level<span class=\"token operator\">=</span>logging<span class=\"token punctuation\">.</span>INFO<span class=\"token punctuation\">,</span> <span class=\"token builtin\">format</span><span class=\"token operator\">=</span><span class=\"token string\">' %(asctime)s -%(levelname)s - %(message)s'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>critical<span class=\"token punctuation\">(</span><span class=\"token string\">'Critical error! Critical error!'</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">2015</span><span class=\"token operator\">-</span><span class=\"token number\">05</span><span class=\"token operator\">-</span><span class=\"token number\">22</span> <span class=\"token number\">11</span><span class=\"token punctuation\">:</span><span class=\"token number\">10</span><span class=\"token punctuation\">:</span><span class=\"token number\">48</span><span class=\"token punctuation\">,</span><span class=\"token number\">054</span> <span class=\"token operator\">-</span> CRITICAL <span class=\"token operator\">-</span> Critical error! Critical error!\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>disable<span class=\"token punctuation\">(</span>logging<span class=\"token punctuation\">.</span>CRITICAL<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>critical<span class=\"token punctuation\">(</span><span class=\"token string\">'Critical error! Critical error!'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> logging<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">(</span><span class=\"token string\">'Error! Error!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Logging to a File</h3>\n<p>Instead of displaying the log messages to the screen, you can write them to a text file. The logging.basicConfig() function takes a filename keyword argument, like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> logging\n\nlogging<span class=\"token punctuation\">.</span>basicConfig<span class=\"token punctuation\">(</span>filename<span class=\"token operator\">=</span><span class=\"token string\">'myProgramLog.txt'</span><span class=\"token punctuation\">,</span> level<span class=\"token operator\">=</span>logging<span class=\"token punctuation\">.</span>DEBUG<span class=\"token punctuation\">,</span> <span class=\"token builtin\">format</span><span class=\"token operator\">=</span><span class=\"token string\">'%(asctime)s - %(levelname)s - %(message)s'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Lambda Functions</h2>\n<p>This function:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> x <span class=\"token operator\">+</span> y\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> add<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">8</span></code></pre></div>\n<p>Is equivalent to the <em>lambda</em> function:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> add <span class=\"token operator\">=</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> y\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> add<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">8</span></code></pre></div>\n<p>It's not even need to bind it to a name like add before:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">8</span></code></pre></div>\n<p>Like regular nested functions, lambdas also work as lexical closures:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">make_adder</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">lambda</span> x<span class=\"token punctuation\">:</span> x <span class=\"token operator\">+</span> n\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> plus_3 <span class=\"token operator\">=</span> make_adder<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> plus_5 <span class=\"token operator\">=</span> make_adder<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> plus_3<span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">7</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> plus_5<span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">9</span></code></pre></div>\n<p>Note: lambda can only evaluate an expression, like a single line of code.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Ternary Conditional Operator</h2>\n<p>Many programming languages have a ternary operator, which define a conditional expression. The most common usage is to make a terse simple conditional assignment statement. In other words, it offers one-line code to evaluate the first expression if the condition is true, otherwise it evaluates the second expression.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;expression1> if &lt;condition> else &lt;expression2></code></pre></div>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> age <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'kid'</span> <span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">18</span> <span class=\"token keyword\">else</span> <span class=\"token string\">'adult'</span><span class=\"token punctuation\">)</span>\nkid</code></pre></div>\n<p>Ternary operators can be chained:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> age <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'kid'</span> <span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">13</span> <span class=\"token keyword\">else</span> <span class=\"token string\">'teenager'</span> <span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">18</span> <span class=\"token keyword\">else</span> <span class=\"token string\">'adult'</span><span class=\"token punctuation\">)</span>\nteenager</code></pre></div>\n<p>The code above is equivalent to:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">18</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> age <span class=\"token operator\">&lt;</span> <span class=\"token number\">13</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'kid'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'teenager'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'adult'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>args and kwargs</h2>\n<p>The names <code class=\"language-text\">args and kwargs</code> are arbitrary - the important thing are the <code class=\"language-text\">*</code> and <code class=\"language-text\">**</code> operators. They can mean:</p>\n<ol>\n<li>In a function declaration, <code class=\"language-text\">*</code> means \"pack all remaining positional arguments into a tuple named <code class=\"language-text\">&lt;name></code>\", while <code class=\"language-text\">**</code> is the same for keyword arguments (except it uses a dictionary, not a tuple).</li>\n<li>In a function call, <code class=\"language-text\">*</code> means \"unpack tuple or list named <code class=\"language-text\">&lt;name></code> to positional arguments at this position\", while <code class=\"language-text\">**</code> is the same for keyword arguments.</li>\n</ol>\n<p>For example you can make a function that you can use to call any other function, no matter what parameters it has:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">forward</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> f<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Inside forward, args is a tuple (of all positional arguments except the first one, because we specified it - the f), kwargs is a dict. Then we call f and unpack them so they become normal arguments to f.</p>\n<p>You use <code class=\"language-text\">*args</code> when you have an indefinite amount of positional arguments.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">fruits</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">for</span> fruit <span class=\"token keyword\">in</span> args<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>fruit<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> fruits<span class=\"token punctuation\">(</span><span class=\"token string\">\"apples\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"bananas\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"grapes\"</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token string\">\"apples\"</span>\n<span class=\"token string\">\"bananas\"</span>\n<span class=\"token string\">\"grapes\"</span></code></pre></div>\n<p>Similarly, you use <code class=\"language-text\">**kwargs</code> when you have an indefinite number of keyword arguments.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">fruit</span><span class=\"token punctuation\">(</span><span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>    <span class=\"token keyword\">for</span> key<span class=\"token punctuation\">,</span> value <span class=\"token keyword\">in</span> kwargs<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0}: {1}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> fruit<span class=\"token punctuation\">(</span>name <span class=\"token operator\">=</span> <span class=\"token string\">\"apple\"</span><span class=\"token punctuation\">,</span> color <span class=\"token operator\">=</span> <span class=\"token string\">\"red\"</span><span class=\"token punctuation\">)</span>\n\nname<span class=\"token punctuation\">:</span> apple\ncolor<span class=\"token punctuation\">:</span> red</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">show</span><span class=\"token punctuation\">(</span>arg1<span class=\"token punctuation\">,</span> arg2<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>args<span class=\"token punctuation\">,</span> kwarg1<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> kwarg2<span class=\"token operator\">=</span><span class=\"token boolean\">None</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>kwargs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>arg1<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>arg2<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>kwarg1<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>kwarg2<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>kwargs<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> data1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> data2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">4</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">]</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> data3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span><span class=\"token number\">9</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> show<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>data1<span class=\"token punctuation\">,</span><span class=\"token operator\">*</span>data2<span class=\"token punctuation\">,</span> kwarg1<span class=\"token operator\">=</span><span class=\"token string\">\"python\"</span><span class=\"token punctuation\">,</span>kwarg2<span class=\"token operator\">=</span><span class=\"token string\">\"cheatsheet\"</span><span class=\"token punctuation\">,</span><span class=\"token operator\">**</span>data3<span class=\"token punctuation\">)</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\npython\ncheatsheet\n<span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> show<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>data1<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>data2<span class=\"token punctuation\">,</span> <span class=\"token operator\">**</span>data3<span class=\"token punctuation\">)</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">None</span>\n<span class=\"token boolean\">None</span>\n<span class=\"token punctuation\">{</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\"># If you do not specify ** for kwargs</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> show<span class=\"token punctuation\">(</span><span class=\"token operator\">*</span>data1<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>data2<span class=\"token punctuation\">,</span> <span class=\"token operator\">*</span>data3<span class=\"token punctuation\">)</span>\n<span class=\"token number\">1</span>\n<span class=\"token number\">2</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"a\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"b\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"c\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">None</span>\n<span class=\"token boolean\">None</span>\n<span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></code></pre></div>\n<h3>Things to Remember(args)</h3>\n<ol>\n<li>Functions can accept a variable number of positional arguments by using <code class=\"language-text\">*args</code> in the def statement.</li>\n<li>You can use the items from a sequence as the positional arguments for a function with the <code class=\"language-text\">*</code> operator.</li>\n<li>Using the <code class=\"language-text\">*</code> operator with a generator may cause your program to run out of memory and crash.</li>\n<li>Adding new positional parameters to functions that accept <code class=\"language-text\">*args</code> can introduce hard-to-find bugs.</li>\n</ol>\n<h3>Things to Remember(kwargs)</h3>\n<ol>\n<li>Function arguments can be specified by position or by keyword.</li>\n<li>Keywords make it clear what the purpose of each argument is when it would be confusing with only positional arguments.</li>\n<li>Keyword arguments with default values make it easy to add new behaviors to a function, especially when the function has existing callers.</li>\n<li>Optional keyword arguments should always be passed by keyword instead of by position.</li>\n</ol>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Context Manager</h2>\n<p>While Python's context managers are widely used, few understand the purpose behind their use. These statements, commonly used with reading and writing files, assist the application in conserving system memory and improve resource management by ensuring specific resources are only in use for certain processes.</p>\n<h3>with statement</h3>\n<p>A context manager is an object that is notified when a context (a block of code) starts and ends. You commonly use one with the with statement. It takes care of the notifying.</p>\n<p>For example, file objects are context managers. When a context ends, the file object is closed automatically:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> <span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span>filename<span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> f<span class=\"token punctuation\">:</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span>     file_contents <span class=\"token operator\">=</span> f<span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># the open_file object has automatically been closed.</span></code></pre></div>\n<p>Anything that ends execution of the block causes the context manager's exit method to be called. This includes exceptions, and can be useful when an error causes you to prematurely exit from an open file or connection. Exiting a script without properly closing files/connections is a bad idea, that may cause data loss or other problems. By using a context manager you can ensure that precautions are always taken to prevent damage or loss in this way.</p>\n<h3>Writing your own contextmanager using generator syntax</h3>\n<p>It is also possible to write a context manager using generator syntax thanks to the <code class=\"language-text\">contextlib.contextmanager</code> decorator:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> contextlib\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> @contextlib<span class=\"token punctuation\">.</span>contextmanager\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">def</span> <span class=\"token function\">context_manager</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Enter'</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">yield</span> num <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Exit'</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">with</span> context_manager<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">as</span> cm<span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token comment\"># the following instructions are run when the 'yield' point of the context</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token comment\"># manager is reached.</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token comment\"># 'cm' will have the value that was yielded</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Right in the middle with cm = {}'</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>cm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nEnter\nRight <span class=\"token keyword\">in</span> the middle <span class=\"token keyword\">with</span> cm <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\nExit\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2><code class=\"language-text\">__main__</code> Top-level script environment</h2>\n<p><code class=\"language-text\">__main__</code> is the name of the scope in which top-level code executes.\nA module's <strong>name</strong> is set equal to <code class=\"language-text\">__main__</code> when read from standard input, a script, or from an interactive prompt.</p>\n<p>A module can discover whether or not it is running in the main scope by checking its own <code class=\"language-text\">__name__</code>, which allows a common idiom for conditionally executing code in a module when it is run as a script or with <code class=\"language-text\">python -m</code> but not when it is imported:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> __name__ <span class=\"token operator\">==</span> <span class=\"token string\">\"__main__\"</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token comment\"># execute only if run as a script</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     main<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>For a package, the same effect can be achieved by including a <strong>main</strong>.py module, the contents of which will be executed when the module is run with -m</p>\n<p>For example we are developing script which is designed to be used as module, we should do:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token comment\"># Python program to execute function directly</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">return</span> a<span class=\"token operator\">+</span>b\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> add<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># we can test it by calling the function save it as calculate.py</span>\n<span class=\"token number\">30</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token comment\"># Now if we want to use that module by importing we have to comment out our call,</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token comment\"># Instead we can write like this in calculate.py</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> __name__ <span class=\"token operator\">==</span> <span class=\"token string\">\"__main__\"</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     add<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> calculate\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> calculate<span class=\"token punctuation\">.</span>add<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n<span class=\"token number\">8</span></code></pre></div>\n<h3>Advantages</h3>\n<ol>\n<li>Every Python module has it's <code class=\"language-text\">__name__</code> defined and if this is <code class=\"language-text\">__main__</code>, it implies that the module is being run standalone by the user and we can do corresponding appropriate actions.</li>\n<li>If you import this script as a module in another script, the <strong>name</strong> is set to the name of the script/module.</li>\n<li>Python files can act as either reusable modules, or as standalone programs.</li>\n<li>if <code class=\"language-text\">__name__ == \"main\":</code> is used to execute some code only if the file was run directly, and not imported.</li>\n</ol>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>setup.py</h2>\n<p>The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the setup script is to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing.</p>\n<p>The <code class=\"language-text\">setup.py</code> file is at the heart of a Python project. It describes all of the metadata about your project. There a quite a few fields you can add to a project to give it a rich set of metadata describing the project. However, there are only three required fields: name, version, and packages. The name field must be unique if you wish to publish your package on the Python Package Index (PyPI). The version field keeps track of different releases of the project. The packages field describes where you've put the Python source code within your project.</p>\n<p>This allows you to easily install Python packages. Often it's enough to write:</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">python setup.py <span class=\"token function\">install</span></code></pre></div>\n<p>and module will install itself.</p>\n<p>Our initial setup.py will also include information about the license and will re-use the README.txt file for the long_description field. This will look like:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> distutils<span class=\"token punctuation\">.</span>core <span class=\"token keyword\">import</span> setup\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> setup<span class=\"token punctuation\">(</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    name<span class=\"token operator\">=</span><span class=\"token string\">'pythonCheatsheet'</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    version<span class=\"token operator\">=</span><span class=\"token string\">'0.1'</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    packages<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span><span class=\"token string\">'pipenv'</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    license<span class=\"token operator\">=</span><span class=\"token string\">'MIT'</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    long_description<span class=\"token operator\">=</span><span class=\"token builtin\">open</span><span class=\"token punctuation\">(</span><span class=\"token string\">'README.txt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>read<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token punctuation\">)</span></code></pre></div>\n<p>Find more information visit <a href=\"http://docs.python.org/install/index.html\">http://docs.python.org/install/index.html</a>.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Dataclasses</h2>\n<p><code class=\"language-text\">Dataclasses</code> are python classes but are suited for storing data objects.\nThis module provides a decorator and functions for automatically adding generated special methods such as <code class=\"language-text\">__init__()</code> and <code class=\"language-text\">__repr__()</code> to user-defined classes.</p>\n<h3>Features</h3>\n<ol>\n<li>They store data and represent a certain data type. Ex: A number. For people familiar with ORMs, a model instance is a data object. It represents a specific kind of entity. It holds attributes that define or represent the entity.</li>\n<li>They can be compared to other objects of the same type. Ex: A number can be greater than, less than, or equal to another number.</li>\n</ol>\n<p>Python 3.7 provides a decorator dataclass that is used to convert a class into a dataclass.</p>\n<p>python 2.7</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>         self<span class=\"token punctuation\">.</span>val <span class=\"token operator\">=</span> val\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> obj <span class=\"token operator\">=</span> Number<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> obj<span class=\"token punctuation\">.</span>val\n<span class=\"token number\">2</span></code></pre></div>\n<p>with dataclass</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> @dataclass\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     val<span class=\"token punctuation\">:</span> <span class=\"token builtin\">int</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> obj <span class=\"token operator\">=</span> Number<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> obj<span class=\"token punctuation\">.</span>val\n<span class=\"token number\">2</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>Default values</h3>\n<p>It is easy to add default values to the fields of your data class.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> @dataclass\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Product</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     name<span class=\"token punctuation\">:</span> <span class=\"token builtin\">str</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     count<span class=\"token punctuation\">:</span> <span class=\"token builtin\">int</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     price<span class=\"token punctuation\">:</span> <span class=\"token builtin\">float</span> <span class=\"token operator\">=</span> <span class=\"token number\">0.0</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> obj <span class=\"token operator\">=</span> Product<span class=\"token punctuation\">(</span><span class=\"token string\">\"Python\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> obj<span class=\"token punctuation\">.</span>name\nPython\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> obj<span class=\"token punctuation\">.</span>count\n<span class=\"token number\">0</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> obj<span class=\"token punctuation\">.</span>price\n<span class=\"token number\">0.0</span></code></pre></div>\n<h3>Type hints</h3>\n<p>It is mandatory to define the data type in dataclass. However, If you don't want specify the datatype then, use <code class=\"language-text\">typing.Any</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> dataclasses <span class=\"token keyword\">import</span> dataclass\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">from</span> typing <span class=\"token keyword\">import</span> Any\n\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> @dataclass\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">WithoutExplicitTypes</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    name<span class=\"token punctuation\">:</span> Any\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    value<span class=\"token punctuation\">:</span> Any <span class=\"token operator\">=</span> <span class=\"token number\">42</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h2>Virtual Environment</h2>\n<p>The use of a Virtual Environment is to test python code in encapsulated environments and to also avoid filling the base Python installation with libraries we might use for only one project.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>virtualenv</h3>\n<ol>\n<li>\n<p>Install virtualenv</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pip install virtualenv</code></pre></div>\n</li>\n<li>\n<p>Install virtualenvwrapper-win (Windows)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pip install virtualenvwrapper-win</code></pre></div>\n</li>\n</ol>\n<p>Usage:</p>\n<ol>\n<li>\n<p>Make a Virtual Environment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">mkvirtualenv HelloWold</code></pre></div>\n<p>Anything we install now will be specific to this project. And available to the projects we connect to this environment.</p>\n</li>\n<li>\n<p>Set Project Directory</p>\n<p>To bind our virtualenv with our current working directory we simply enter:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">setprojectdir .</code></pre></div>\n</li>\n<li>\n<p>Deactivate</p>\n<p>To move onto something else in the command line type 'deactivate' to deactivate your environment.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">deactivate</code></pre></div>\n<p>Notice how the parenthesis disappear.</p>\n</li>\n<li>\n<p>Workon</p>\n<p>Open up the command prompt and type 'workon HelloWold' to activate the environment and move into your root project folder</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">workon HelloWold</code></pre></div>\n</li>\n</ol>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>poetry</h3>\n<blockquote>\n<p><a href=\"https://poetry.eustace.io/\">Poetry</a> is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.</p>\n</blockquote>\n<ol>\n<li>\n<p>Install Poetry</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pip install --user poetry</code></pre></div>\n</li>\n<li>\n<p>Create a new project</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">poetry new my-project</code></pre></div>\n<p>This will create a my-project directory:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">my-project\n├── pyproject.toml\n├── README.rst\n├── poetry_demo\n│   └── __init__.py\n└── tests\n    ├── __init__.py\n    └── test_poetry_demo.py</code></pre></div>\n<p>The pyproject.toml file will orchestrate your project and its dependencies:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[tool.poetry]\nname = \"my-project\"\nversion = \"0.1.0\"\ndescription = \"\"\nauthors = [\"your name &lt;your@mail.com>\"]\n\n[tool.poetry.dependencies]\npython = \"*\"\n\n[tool.poetry.dev-dependencies]\npytest = \"^3.4\"</code></pre></div>\n</li>\n<li>\n<p>Packages</p>\n<p>To add dependencies to your project, you can specify them in the tool.poetry.dependencies section:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[tool.poetry.dependencies]\npendulum = \"^1.4\"</code></pre></div>\n<p>Also, instead of modifying the pyproject.toml file by hand, you can use the add command and it will automatically find a suitable version constraint.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">$ poetry add pendulum</code></pre></div>\n<p>To install the dependencies listed in the pyproject.toml:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">poetry install</code></pre></div>\n<p>To remove dependencies:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">poetry remove pendulum</code></pre></div>\n</li>\n</ol>\n<p>For more information, check the <a href=\"https://poetry.eustace.io/docs/\">documentation</a>.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>pipenv</h3>\n<blockquote>\n<p><a href=\"https://pipenv.readthedocs.io/en/latest/\">Pipenv</a> is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. Windows is a first-class citizen, in our world.</p>\n</blockquote>\n<ol>\n<li>\n<p>Install pipenv</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pip install pipenv</code></pre></div>\n</li>\n<li>\n<p>Enter your Project directory and install the Packages for your project</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cd my_project\npipenv install &lt;package></code></pre></div>\n<p>Pipenv will install your package and create a Pipfile for you in your project's directory. The Pipfile is used to track which dependencies your project needs in case you need to re-install them.</p>\n</li>\n<li>\n<p>Uninstall Packages</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pipenv uninstall &lt;package></code></pre></div>\n</li>\n<li>\n<p>Activate the Virtual Environment associated with your Python project</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">pipenv shell</code></pre></div>\n</li>\n<li>\n<p>Exit the Virtual Environment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">exit</code></pre></div>\n</li>\n</ol>\n<p>Find more information and a video in <a href=\"https://docs.pipenv.org/\">docs.pipenv.org</a>.</p>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>\n<h3>anaconda</h3>\n<p><a href=\"https://anaconda.org/\">Anaconda</a> is another popular tool to manage python packages.</p>\n<blockquote>\n<p>Where packages, notebooks, projects and environments are shared.\nYour place for free public conda package hosting.</p>\n</blockquote>\n<p>Usage:</p>\n<ol>\n<li>\n<p>Make a Virtual Environment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">conda create -n HelloWorld</code></pre></div>\n</li>\n<li>\n<p>To use the Virtual Environment, activate it by:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">conda activate HelloWorld</code></pre></div>\n<p>Anything installed now will be specific to the project HelloWorld</p>\n</li>\n<li>\n<p>Exit the Virtual Environment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">conda deactivate</code></pre></div>\n</li>\n</ol>\n<p><a href=\"#python-cheatsheet\"><em>Return to the Top</em></a></p>"},{"url":"/docs/reference/awesome-nodejs/","relativePath":"docs/reference/awesome-nodejs.md","relativeDir":"docs/reference","base":"awesome-nodejs.md","name":"awesome-nodejs","frontmatter":{"title":"Awesome NodeJS","weight":0,"excerpt":"this is an awesome list of awesome NodeJS","seo":{"title":"","description":"","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h2>Official</h2>\n<ul>\n<li><a href=\"https://nodejs.org\">Website</a></li>\n<li><a href=\"https://nodejs.org/dist/latest/docs/api/\">Documentation</a></li>\n<li><a href=\"https://github.com/nodejs/node\">Repository</a></li>\n</ul>\n<h2>Packages</h2>\n<h3>Mad science</h3>\n<ul>\n<li><a href=\"https://github.com/feross/webtorrent\">webtorrent</a> - Streaming torrent client for Node.js and the browser.</li>\n<li><a href=\"https://github.com/mafintosh/peerflix\">peerflix</a> - Streaming torrent client.</li>\n<li><a href=\"https://github.com/datproject/dat-node\">dat</a> - Real-time replication and versioning for data sets.</li>\n<li><a href=\"https://github.com/ipfs/js-ipfs\">ipfs</a> - Distributed file system that seeks to connect all computing devices with the same system of files.</li>\n<li><a href=\"https://github.com/stackgl\">stackgl</a> - Open software ecosystem for WebGL, built on top of browserify and npm.</li>\n<li><a href=\"https://github.com/mafintosh/peerwiki\">peerwiki</a> - All of Wikipedia on BitTorrent.</li>\n<li><a href=\"https://github.com/mafintosh/peercast\">peercast</a> - Stream a torrent video to Chromecast.</li>\n<li><a href=\"https://github.com/bitcoinjs/bitcoinjs-lib\">BitcoinJS</a> - Clean, readable, proven Bitcoin library.</li>\n<li><a href=\"https://github.com/bitpay/bitcore\">Bitcore</a> - Pure and powerful Bitcoin library.</li>\n<li><a href=\"https://github.com/devongovett/pdfkit\">PDFKit</a> - PDF generation library.</li>\n<li><a href=\"https://github.com/Turfjs/turf\">turf</a> - Modular geospatial processing and analysis engine.</li>\n<li><a href=\"https://github.com/mafintosh/webcat\">webcat</a> - p2p pipe across the web using WebRTC that uses your GitHub private/public key for authentication.</li>\n<li><a href=\"https://github.com/NodeOS/NodeOS\">NodeOS</a> - The first operating system powered by npm.</li>\n<li><a href=\"https://github.com/yodaos-project/yodaos\">YodaOS</a> - AI operating system.</li>\n<li><a href=\"https://github.com/BrainJS/brain.js\">Brain.js</a> - Machine-learning framework.</li>\n<li><a href=\"https://github.com/alibaba/pipcook\">Pipcook</a> - Front-end algorithm framework to create a machine learning pipeline.</li>\n<li><a href=\"https://github.com/cytoscape/cytoscape.js\">Cytoscape.js</a> - Graph theory (a.k.a. network) modeling and analysis.</li>\n<li><a href=\"https://gitlab.com/deadcanaries/kadence\">Kadence</a> - Kademlia distributed hash table.</li>\n<li><a href=\"https://github.com/twobucks/seedshot\">seedshot</a> - Temporary P2P screenshot sharing from your browser.</li>\n<li><a href=\"https://github.com/creationix/js-git\">js-git</a> - JavaScript implementation of Git.</li>\n<li><a href=\"https://github.com/skale-me/skale-engine\">skale</a> - High performance distributed data processing engine.</li>\n<li><a href=\"https://github.com/sheetjs/js-xlsx\">xlsx</a> - Pure JS Excel spreadsheet reader and writer.</li>\n<li><a href=\"https://github.com/isomorphic-git/isomorphic-git\">isomorphic-git</a> - Pure JavaScript implementation of Git.</li>\n</ul>\n<h3>Command-line apps</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/np\">np</a> - Better <code class=\"language-text\">npm publish</code>.</li>\n<li><a href=\"https://github.com/sindresorhus/npm-name\">npm-name</a> - Check a package name's availability on npm.</li>\n<li><a href=\"https://github.com/sindresorhus/gh-home\">gh-home</a> - Open the GitHub page of the repo in the current directory.</li>\n<li><a href=\"https://github.com/sindresorhus/npm-home\">npm-home</a> - Open the npm page of a package.</li>\n<li><a href=\"https://github.com/sindresorhus/trash\">trash</a> - Safer alternative to <code class=\"language-text\">rm</code>.</li>\n<li><a href=\"https://github.com/sindresorhus/speed-test\">speed-test</a> - Test your internet connection speed and ping.</li>\n<li><a href=\"https://github.com/sindresorhus/emoj\">emoj</a> - Find relevant emoji from text on the command-line.</li>\n<li><a href=\"https://github.com/sindresorhus/pageres\">pageres</a> - Capture website screenshots.</li>\n<li><a href=\"https://github.com/sindresorhus/cpy\">cpy</a> - Copy files.</li>\n<li><a href=\"https://github.com/MrRio/vtop\">vtop</a> - More better top, with nice charts.</li>\n<li><a href=\"https://github.com/sindresorhus/empty-trash\">empty-trash</a> - Empty the trash.</li>\n<li><a href=\"https://github.com/sindresorhus/is-up\">is-up</a> - Check whether a website is up or down.</li>\n<li><a href=\"https://github.com/sindresorhus/is-online\">is-online</a> - Check if the internet connection is up.</li>\n<li><a href=\"https://github.com/sindresorhus/public-ip\">public-ip</a> - Get your public IP address.</li>\n<li><a href=\"https://github.com/sindresorhus/clipboard-cli\">clipboard-cli</a> - Copy &#x26; paste on the terminal.</li>\n<li><a href=\"https://github.com/xojs/xo\">XO</a> - Enforce strict code style using the JavaScript happiness style.</li>\n<li><a href=\"https://github.com/feross/standard\">Standard</a> - JavaScript Standard Style — One style to rule them all.</li>\n<li><a href=\"https://github.com/eslint/eslint\">ESLint</a> - The pluggable linting utility for JavaScript.</li>\n<li><a href=\"https://github.com/samverschueren/dev-time-cli\">dev-time</a> - Get the current local time of a GitHub user.</li>\n<li><a href=\"https://github.com/alanshaw/david\">David</a> - Tells you when your package npm dependencies are out of date.</li>\n<li><a href=\"https://github.com/indexzero/http-server\">http-server</a> - Simple, zero-config command-line HTTP server.</li>\n<li><a href=\"https://github.com/tapio/live-server\">Live Server</a> - Development HTTP-server with livereload capability.</li>\n<li><a href=\"https://github.com/kessler/node-bcat\">bcat</a> - Pipe command output to web browsers.</li>\n<li><a href=\"https://github.com/pawurb/normit\">normit</a> - Google Translate with speech synthesis in your terminal.</li>\n<li><a href=\"https://github.com/sindresorhus/fkill-cli\">fkill</a> - Fabulously kill processes. Cross-platform.</li>\n<li><a href=\"https://github.com/danielstjules/pjs\">pjs</a> - Pipeable JavaScript. Quickly filter, map, and reduce from the terminal.</li>\n<li><a href=\"https://github.com/davglass/license-checker\">license-checker</a> - Check licenses of your app's dependencies.</li>\n<li><a href=\"https://github.com/juliangruber/browser-run\">browser-run</a> - Easily run code in a browser environment.</li>\n<li><a href=\"https://github.com/sindresorhus/tmpin\">tmpin</a> - Adds stdin support to any CLI app that accepts file input.</li>\n<li><a href=\"https://github.com/kevva/wifi-password-cli\">wifi-password</a> - Get the current wifi password.</li>\n<li><a href=\"https://github.com/sindresorhus/wallpaper\">wallpaper</a> - Change the desktop wallpaper.</li>\n<li><a href=\"https://github.com/kevva/brightness-cli\">brightness</a> - Change the screen brightness.</li>\n<li><a href=\"https://github.com/maxogden/torrent\">torrent</a> - Download torrents.</li>\n<li><a href=\"https://github.com/sindresorhus/kill-tabs\">kill-tabs</a> - Kill all Chrome tabs to improve performance, decrease battery usage, and save memory.</li>\n<li><a href=\"https://github.com/wooorm/alex\">alex</a> - Catch insensitive, inconsiderate writing.</li>\n<li><a href=\"https://github.com/noraesae/pen\">pen</a> - Live Markdown preview in the browser from your favorite editor.</li>\n<li><a href=\"https://github.com/beatfreaker/subdownloader\">subdownloader</a> - Subtitle downloader for movies and TV series.</li>\n<li><a href=\"https://github.com/sindresorhus/dark-mode\">dark-mode</a> - Toggle the macOS Dark Mode.</li>\n<li><a href=\"https://github.com/nogizhopaboroda/iponmap\">iponmap</a> - IP location finder.</li>\n<li><a href=\"https://github.com/Javascipt/Jsome\">Jsome</a> - Pretty prints JSON with configurable colors and indentation.</li>\n<li><a href=\"https://github.com/mischah/itunes-remote\">itunes-remote</a> - Interactively control iTunes.</li>\n<li><a href=\"https://github.com/samverschueren/mobicon-cli\">mobicon</a> - Mobile app icon generator.</li>\n<li><a href=\"https://github.com/samverschueren/mobisplash-cli\">mobisplash</a> - Mobile app splash screen generator.</li>\n<li><a href=\"https://github.com/rtfpessoa/diff2html-cli\">diff2html-cli</a> - Pretty git diff to HTML generator.</li>\n<li><a href=\"https://github.com/dthree/cash\">Cash</a> - Cross-platform Unix shell commands in pure JavaScript.</li>\n<li><a href=\"https://github.com/VictorBjelkholm/trymodule\">trymodule</a> - Try out npm packages in the terminal.</li>\n<li><a href=\"https://github.com/kucherenko/jscpd\">jscpd</a> - Copy/paste detector for source code.</li>\n<li><a href=\"https://github.com/Raathigesh/Atmo\">atmo</a> - Server-side API mocking.</li>\n<li><a href=\"https://github.com/siddharthkp/auto-install\">auto-install</a> - Auto installs dependencies as you code.</li>\n<li><a href=\"https://github.com/linuxenko/lessmd\">lessmd</a> - Markdown in the terminal.</li>\n<li><a href=\"https://github.com/siddharthkp/cost-of-modules\">cost-of-modules</a> - Find out which dependencies are slowing you down.</li>\n<li><a href=\"https://github.com/localtunnel/localtunnel\">localtunnel</a> - Expose your localhost to the world.</li>\n<li><a href=\"https://github.com/marionebl/svg-term-cli\">svg-term-cli</a> - Share terminal sessions via SVG.</li>\n<li><a href=\"https://github.com/aksakalli/gtop\">gtop</a> - System monitoring dashboard for the terminal.</li>\n<li><a href=\"https://github.com/mjswensen/themer\">themer</a> - Generate themes for your editor, terminal, wallpaper, Slack, and more.</li>\n<li><a href=\"https://github.com/mixn/carbon-now-cli\">carbon-now-cli</a> - Beautiful images of your code — from right inside your terminal.</li>\n<li><a href=\"https://github.com/xxczaki/cash-cli\">cash-cli</a> - Convert between 170 currencies.</li>\n<li><a href=\"https://github.com/klauscfhq/taskbook\">taskbook</a> - Tasks, boards &#x26; notes for the command-line habitat.</li>\n<li><a href=\"https://github.com/brandonweiss/discharge\">discharge</a> - Easily deploy static websites to Amazon S3.</li>\n<li><a href=\"https://github.com/voidcosmos/npkill\">npkill</a> - Easily find and remove old and heavy node_modules folders.</li>\n</ul>\n<h3>Functional programming</h3>\n<ul>\n<li><a href=\"https://github.com/lodash/lodash\">lodash</a> - Utility library delivering consistency, customization, performance, &#x26; extras. A better and faster Underscore.js.</li>\n<li><a href=\"https://github.com/facebook/immutable-js\">immutable</a> - Immutable data collections.</li>\n<li><a href=\"https://github.com/ramda/ramda\">Ramda</a> - Utility library with a focus on flexible functional composition enabled by automatic currying and reversed argument order. Avoids mutating data.</li>\n<li><a href=\"https://github.com/origamitower/folktale\">Folktale</a> - Suite of libraries for generic functional programming in JavaScript that allows you to write elegant, modular applications with fewer bugs, and more reuse.</li>\n<li><a href=\"https://github.com/mout/mout\">Mout</a> - Utility library with the biggest difference between other existing solutions is that you can choose to load only the modules/functions that you need, no extra overhead.</li>\n<li><a href=\"https://github.com/baconjs/bacon.js\">Bacon.js</a> - Functional reactive programming.</li>\n<li><a href=\"https://github.com/reactivex/rxjs\">RxJS</a> - Functional reactive library for transforming, composing, and querying various kinds of data.</li>\n<li><a href=\"https://github.com/dtao/lazy.js\">Lazy.js</a> - Utility library similar to lodash/Underscore but with lazy evaluation, which can translate to superior performance in many cases.</li>\n<li><a href=\"https://github.com/kefirjs/kefir\">Kefir.js</a> - Reactive library with focus on high performance and low memory usage.</li>\n</ul>\n<h3>HTTP</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/got\">got</a> - Nicer interface to the built-in <code class=\"language-text\">http</code> module.</li>\n<li><a href=\"https://github.com/sindresorhus/gh-got\">gh-got</a> - Convenience wrapper for <code class=\"language-text\">got</code> to interact with the GitHub API.</li>\n<li><a href=\"https://github.com/mzabriskie/axios\">axios</a> - Promise based HTTP client (works in the browser too).</li>\n<li><a href=\"https://github.com/hapijs/wreck\">wreck</a> - HTTP Client Utilities.</li>\n<li><a href=\"https://github.com/kevva/download\">download</a> - Download and extract files effortlessly.</li>\n<li><a href=\"https://github.com/nodejitsu/node-http-proxy\">http-proxy</a> - HTTP proxy.</li>\n<li><a href=\"https://github.com/visionmedia/superagent\">superagent</a> - HTTP request library.</li>\n<li><a href=\"https://github.com/bitinn/node-fetch\">node-fetch</a> - <code class=\"language-text\">window.fetch</code> for Node.js.</li>\n<li><a href=\"https://github.com/bbc/flashheart\">flashheart</a> - REST client.</li>\n<li><a href=\"https://github.com/micromata/http-fake-backend\">http-fake-backend</a> - Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.</li>\n<li><a href=\"https://github.com/lukechilds/cacheable-request\">cacheable-request</a> - Wrap native HTTP requests with RFC compliant cache support.</li>\n<li><a href=\"https://github.com/khaosdoctor/gotql\">gotql</a> - GraphQL request library built on <a href=\"https://github.com/sindresorhus/got\">got</a>.</li>\n<li><a href=\"https://github.com/gajus/global-agent\">global-agent</a> - Global HTTP/HTTPS proxy agent that is configurable using environment variables.</li>\n<li><a href=\"https://github.com/sinedied/smoke\">smoke</a> - File-based HTTP mock server with recording abilities.</li>\n<li><a href=\"https://github.com/nodejs/undici\">undici</a> - High performance HTTP client written from scratch with zero dependencies.</li>\n</ul>\n<h3>Debugging / Profiling</h3>\n<ul>\n<li><a href=\"https://github.com/GoogleChromeLabs/ndb\">ndb</a> - Improved debugging experience, enabled by Chrome DevTools.</li>\n<li><a href=\"https://github.com/s-a/iron-node\">ironNode</a> - Node.js debugger supporting ES2015 out of the box.</li>\n<li><a href=\"https://github.com/node-inspector/node-inspector\">node-inspector</a> - Debugger based on Blink Developer Tools.</li>\n<li><a href=\"https://github.com/visionmedia/debug\">debug</a> - Tiny debugging utility.</li>\n<li><a href=\"https://github.com/mafintosh/why-is-node-running\">why-is-node-running</a> - Node.js is running but you don't know why?</li>\n<li><a href=\"https://github.com/valyouw/njstrace\">njsTrace</a> - Instrument and trace your code, see all function calls, arguments, return values, as well as the time spent in each function.</li>\n<li><a href=\"https://github.com/joyent/node-vstream\">vstream</a> - Instrumentable streams mix-ins to inspect a pipeline of streams.</li>\n<li><a href=\"https://github.com/watson/stackman\">stackman</a> - Enhance an error stacktrace with code excerpts and other goodies.</li>\n<li><a href=\"https://github.com/alidavut/locus\">locus</a> - Starts a REPL at runtime that has access to all variables.</li>\n<li><a href=\"https://github.com/davidmarkclements/0x\">0x</a> - Flamegraph profiling.</li>\n<li><a href=\"https://github.com/automation-stack/ctrace\">ctrace</a> - Well-formatted and improved trace system calls and signals.</li>\n<li><a href=\"https://github.com/andywer/leakage\">leakage</a> - Write memory leak tests.</li>\n<li><a href=\"https://github.com/nodejs/llnode\">llnode</a> - Post-mortem analysis tool which allows you to inspect objects and get insights from a crashed Node.js process.</li>\n<li><a href=\"https://github.com/sfninja/thetool\">thetool</a> - Capture different CPU, memory, and other profiles for your app in Chrome DevTools friendly format.</li>\n<li><a href=\"https://github.com/slanatech/swagger-stats\">swagger-stats</a> - Trace API calls and monitor API performance, health, and usage metrics.</li>\n<li><a href=\"https://github.com/june07/nim\">NiM</a> - Manages DevTools debugging workflow.</li>\n</ul>\n<h3>Logging</h3>\n<ul>\n<li><a href=\"https://github.com/pinojs/pino\">pino</a> - Extremely fast logger inspired by Bunyan.</li>\n<li><a href=\"https://github.com/winstonjs/winston\">winston</a> - Multi-transport async logging library.</li>\n<li><a href=\"https://github.com/watson/console-log-level\">console-log-level</a> - The most simple logger imaginable with support for log levels and custom prefixes.</li>\n<li><a href=\"https://github.com/guigrpa/storyboard\">storyboard</a> - End-to-end, hierarchical, real-time, colorful logs and stories.</li>\n<li><a href=\"https://github.com/klauscfhq/signale\">signale</a> - Console logger.</li>\n<li><a href=\"https://github.com/nuxt/consola\">consola</a> - Console logger.</li>\n</ul>\n<h3>Command-line utilities</h3>\n<ul>\n<li><a href=\"https://github.com/chalk/chalk\">chalk</a> - Terminal string styling done right.</li>\n<li><a href=\"https://github.com/sindresorhus/meow\">meow</a> - CLI app helper.</li>\n<li><a href=\"https://github.com/yargs/yargs\">yargs</a> - Command-line parser that automatically generates an elegant user-interface.</li>\n<li><a href=\"https://github.com/sindresorhus/ora\">ora</a> - Elegant terminal spinner.</li>\n<li><a href=\"https://github.com/sindresorhus/get-stdin\">get-stdin</a> - Easier stdin.</li>\n<li><a href=\"https://github.com/sindresorhus/log-update\">log-update</a> - Log by overwriting the previous output in the terminal. Useful for rendering progress bars, animations, etc.</li>\n<li><a href=\"https://github.com/vadimdemedes/ink\">Ink</a> - React for interactive command-line apps.</li>\n<li><a href=\"https://github.com/samverschueren/listr\">listr</a> - Terminal task list.</li>\n<li><a href=\"https://github.com/sindresorhus/conf\">conf</a> - Simple config handling for your app or module.</li>\n<li><a href=\"https://github.com/sindresorhus/ansi-escapes\">ansi-escapes</a> - ANSI escape codes for manipulating the terminal.</li>\n<li><a href=\"https://github.com/sindresorhus/log-symbols\">log-symbols</a> - Colored symbols for various log levels.</li>\n<li><a href=\"https://github.com/sindresorhus/figures\">figures</a> - Unicode symbols with Windows CMD fallbacks.</li>\n<li><a href=\"https://github.com/sindresorhus/boxen\">boxen</a> - Create boxes in the terminal.</li>\n<li><a href=\"https://github.com/sindresorhus/terminal-link\">terminal-link</a> - Create clickable links in the terminal.</li>\n<li><a href=\"https://github.com/sindresorhus/terminal-image\">terminal-image</a> - Display images in the terminal.</li>\n<li><a href=\"https://github.com/sindresorhus/string-width\">string-width</a> - Get the visual width of a string - the number of columns required to display it.</li>\n<li><a href=\"https://github.com/sindresorhus/cli-truncate\">cli-truncate</a> - Truncate a string to a specific width in the terminal.</li>\n<li><a href=\"https://github.com/sindresorhus/first-run\">first-run</a> - Check if it's the first time the process is run.</li>\n<li><a href=\"https://github.com/chjj/blessed\">blessed</a> - Curses-like library.</li>\n<li><a href=\"https://github.com/SBoudrias/Inquirer.js\">Inquirer.js</a> - Interactive command-line prompt.</li>\n<li><a href=\"https://github.com/sindresorhus/yn\">yn</a> - Parse yes/no like values.</li>\n<li><a href=\"https://github.com/cli-table/cli-table3\">cli-table3</a> - Pretty unicode tables.</li>\n<li><a href=\"https://github.com/madbence/node-drawille\">drawille</a> - Draw on the terminal with unicode braille characters.</li>\n<li><a href=\"https://github.com/yeoman/update-notifier\">update-notifier</a> - Update notifications for your CLI app.</li>\n<li><a href=\"https://github.com/jstrace/chart\">ascii-charts</a> - ASCII bar chart in the terminal.</li>\n<li><a href=\"https://github.com/tj/node-progress\">progress</a> - Flexible ascii progress bar.</li>\n<li><a href=\"https://github.com/yeoman/insight\">insight</a> - Helps you understand how your tool is being used by anonymously reporting usage metrics to Google Analytics.</li>\n<li><a href=\"https://github.com/sindresorhus/cli-cursor\">cli-cursor</a> - Toggle the CLI cursor.</li>\n<li><a href=\"https://github.com/timoxley/columnify\">columnify</a> - Create text-based columns suitable for console output. Supports cell wrapping.</li>\n<li><a href=\"https://github.com/shannonmoeller/cli-columns\">cli-columns</a> - Columnated unicode and ansi-safe text lists.</li>\n<li><a href=\"https://github.com/dominikwilkowski/cfonts\">cfonts</a> - Sexy ASCII fonts for the console.</li>\n<li><a href=\"https://github.com/codekirei/node-multispinner\">multispinner</a> - Multiple, simultaneous, individually controllable CLI spinners.</li>\n<li><a href=\"https://github.com/f/omelette\">omelette</a> - Shell autocompletion helper.</li>\n<li><a href=\"https://github.com/kentcdodds/cross-env\">cross-env</a> - Set environment variables cross-platform.</li>\n<li><a href=\"https://github.com/shelljs/shelljs\">shelljs</a> - Portable Unix shell commands.</li>\n<li><a href=\"https://github.com/sindresorhus/sudo-block\">sudo-block</a> - Block users from running your app with root permissions.</li>\n<li><a href=\"https://github.com/sindresorhus/loud-rejection\">loud-rejection</a> - Make unhandled promise rejections fail loudly instead of the default silent fail.</li>\n<li><a href=\"https://github.com/sindresorhus/sparkly\">sparkly</a> - Generate sparklines <code class=\"language-text\">▁▂▃▅▂▇</code>.</li>\n<li><a href=\"https://github.com/teambit/bit\">Bit</a> - Create, maintain, find and use small modules and components across repositories.</li>\n<li><a href=\"https://github.com/bokub/gradient-string\">gradient-string</a> - Beautiful color gradients in terminal output.</li>\n<li><a href=\"https://github.com/oclif/oclif\">oclif</a> - CLI framework complete with parser, automatic documentation, testing, and plugins.</li>\n<li><a href=\"https://github.com/sindresorhus/term-size\">term-size</a> - Reliably get the terminal window size.</li>\n<li><a href=\"https://github.com/drew-y/cliffy\">Cliffy</a> - Framework for interactive CLIs.</li>\n</ul>\n<h3>Build tools</h3>\n<ul>\n<li><a href=\"https://github.com/parcel-bundler/parcel\">parcel</a> - Blazing fast, zero config web app bundler.</li>\n<li><a href=\"https://github.com/webpack/webpack\">webpack</a> - Packs modules and assets for the browser.</li>\n<li><a href=\"https://github.com/rollup/rollup\">rollup</a> - Next-generation ES2015 module bundler.</li>\n<li><a href=\"https://github.com/gulpjs/gulp\">gulp</a> - Streaming and fast build system that favors code over config.</li>\n<li><a href=\"https://github.com/broccolijs/broccoli\">Broccoli</a> - Fast, reliable asset pipeline, supporting constant-time rebuilds and compact build definitions.</li>\n<li><a href=\"https://github.com/brunch/brunch\">Brunch</a> - Front-end web app build tool with simple declarative config, fast incremental compilation, and an opinionated workflow.</li>\n<li><a href=\"https://github.com/deepsweet/start\">Start</a> - Functional task runner with shareable presets.</li>\n<li><a href=\"https://github.com/shannonmoeller/ygor\">ygor</a> - Promising task runner for when <code class=\"language-text\">npm run</code> isn't enough and everything else is too much.</li>\n<li><a href=\"https://github.com/fuse-box/fuse-box\">FuseBox</a> - Fast build system that combines the power of webpack, JSPM and SystemJS, with first-class TypeScript support.</li>\n<li><a href=\"https://github.com/zeit/pkg\">pkg</a> - Package your Node.js project into an executable.</li>\n</ul>\n<h3>Hardware</h3>\n<ul>\n<li><a href=\"https://github.com/rwaldron/johnny-five\">johnny-five</a> - Firmata based Arduino Framework.</li>\n<li><a href=\"https://github.com/voodootikigod/node-serialport\">serialport</a> - Access serial ports for reading and writing.</li>\n<li><a href=\"https://github.com/nonolith/node-usb\">usb</a> - USB library.</li>\n<li><a href=\"https://github.com/fivdi/i2c-bus\">i2c-bus</a> - I2C serial bus access.</li>\n<li><a href=\"https://github.com/fivdi/onoff\">onoff</a> - GPIO access and interrupt detection.</li>\n<li><a href=\"https://github.com/fivdi/spi-device\">spi-device</a> - SPI serial bus access.</li>\n<li><a href=\"https://github.com/fivdi/pigpio\">pigpio</a> - Fast GPIO, PWM, servo control, state change notification, and interrupt handling on the Raspberry Pi.</li>\n<li><a href=\"https://github.com/infusion/GPS.js\">gps</a> - NMEA parser for handling GPS receivers.</li>\n</ul>\n<h3>Templating</h3>\n<ul>\n<li><a href=\"https://github.com/marko-js/marko\">marko</a> - HTML-based templating engine that compiles templates to CommonJS modules and supports streaming, async rendering and custom tags.</li>\n<li><a href=\"https://github.com/mozilla/nunjucks\">nunjucks</a> - Templating engine with inheritance, asynchronous control, and more (jinja2 inspired).</li>\n<li><a href=\"https://github.com/wycats/handlebars.js\">handlebars.js</a> - Superset of Mustache templates which adds powerful features like helpers and more advanced blocks.</li>\n<li><a href=\"https://github.com/mde/ejs\">EJS</a> - Simple unopinionated templating language.</li>\n<li><a href=\"https://github.com/pugjs/pug\">Pug</a> - High-performance template engine heavily influenced by Haml.</li>\n</ul>\n<h3>Web frameworks</h3>\n<ul>\n<li><a href=\"https://github.com/hapijs/hapi\">Hapi</a> - Framework for building applications and services.</li>\n<li><a href=\"https://github.com/koajs/koa\">Koa</a> - Framework designed by the team behind Express, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs.</li>\n<li><a href=\"https://github.com/expressjs/express\">Express</a> - Web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications.</li>\n<li><a href=\"https://github.com/feathersjs/feathers\">Feathers</a> - Microservice framework built in the spirit of Express.</li>\n<li><a href=\"https://github.com/strongloop/loopback-next\">LoopBack</a> - Powerful framework for creating REST APIs and easily connecting to backend data sources.</li>\n<li><a href=\"https://github.com/meteor/meteor\">Meteor</a> - An ultra-simple, database-everywhere, data-on-the-wire, pure-Javascript web framework. <em>(You might like <a href=\"https://github.com/Urigo/awesome-meteor\">awesome-meteor</a>)</em></li>\n<li><a href=\"https://github.com/restify/node-restify\">Restify</a> - Enables you to build correct REST web services.</li>\n<li><a href=\"https://github.com/thinkjs/thinkjs\">ThinkJS</a> - Framework with ES2015+ support, WebSockets, REST API.</li>\n<li><a href=\"https://github.com/actionhero/actionhero\">ActionHero</a> - Framework for making reusable &#x26; scalable APIs for TCP sockets, WebSockets, and HTTP clients.</li>\n<li><a href=\"https://github.com/zeit/next.js\">Next.js</a> - Minimalistic framework for server-rendered universal JavaScript web apps.</li>\n<li><a href=\"https://github.com/nuxt/nuxt.js\">Nuxt.js</a> - Minimalistic framework for server-rendered Vue.js apps.</li>\n<li><a href=\"https://github.com/senecajs/seneca\">seneca</a> - Toolkit for writing microservices.</li>\n<li><a href=\"http://adonisjs.com\">AdonisJs</a> - A true MVC framework for Node.js built on solid foundations of Dependency Injection and IoC container.</li>\n<li><a href=\"https://github.com/hemerajs/hemera\">Hemera</a> - Write reliable and fault-tolerant microservices with <a href=\"https://nats.io\">NATS</a>.</li>\n<li><a href=\"https://github.com/zeit/micro\">Micro</a> - Minimalistic microservice framework with an async approach.</li>\n<li><a href=\"https://moleculer.services\">Moleculer</a> - Fast &#x26; powerful microservices framework.</li>\n<li><a href=\"https://github.com/fastify/fastify\">Fastify</a> - Fast and low overhead web framework.</li>\n<li><a href=\"https://github.com/nestjs/nest\">Nest</a> - Angular-inspired framework for building efficient and scalable server-side apps.</li>\n<li><a href=\"https://github.com/19majkel94/type-graphql\">TypeGraphQL</a> - Modern framework for creating GraphQL APIs with TypeScript, using classes and decorators.</li>\n<li><a href=\"https://github.com/talentlessguy/tinyhttp\">Tinyhttp</a> - Modern and fast Express-like web framework.</li>\n<li><a href=\"https://github.com/marblejs/marble\">Marble.js</a> - Functional reactive framework for building server-side apps, based on TypeScript and RxJS.</li>\n<li><a href=\"https://github.com/ladjs/lad\">Lad</a> - Framework made by a former Express TC and Koa member that bundles web, API, job, and proxy servers.</li>\n</ul>\n<h3>Documentation</h3>\n<ul>\n<li><a href=\"https://github.com/documentationjs/documentation\">documentation.js</a> - API documentation generator with support for ES2015+ and flow annotation.</li>\n<li><a href=\"https://github.com/esdoc/esdoc\">ESDoc</a> - Documentation generator targeting ES2015, attaching test code and measuring documentation coverage.</li>\n<li><a href=\"https://github.com/jashkenas/docco\">Docco</a> - Documentation generator which produces an HTML document that displays your comments intermingled with your code.</li>\n<li><a href=\"https://github.com/jsdoc3/jsdoc\">JSDoc</a> - API documentation generator similar to JavaDoc or PHPDoc.</li>\n<li><a href=\"https://github.com/facebook/docusaurus\">Docusaurus</a> - Documentation website generator that leverages React and Markdown, and comes with translation and versioning features.</li>\n</ul>\n<h3>Filesystem</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/del\">del</a> - Delete files/folders using globs.</li>\n<li><a href=\"https://github.com/sindresorhus/globby\">globby</a> - Glob files with support for multiple patterns.</li>\n<li><a href=\"https://github.com/sindresorhus/cpy\">cpy</a> - Copy files.</li>\n<li><a href=\"https://github.com/isaacs/rimraf\">rimraf</a> - Recursively delete files like <code class=\"language-text\">rm -rf</code>.</li>\n<li><a href=\"https://github.com/sindresorhus/make-dir\">make-dir</a> - Recursively create directories like <code class=\"language-text\">mkdir -p</code>.</li>\n<li><a href=\"https://github.com/isaacs/node-graceful-fs\">graceful-fs</a> - Drop-in replacement for the <code class=\"language-text\">fs</code> module with various improvements.</li>\n<li><a href=\"https://github.com/paulmillr/chokidar\">chokidar</a> - Filesystem watcher which stabilizes events from <code class=\"language-text\">fs.watch</code> and <code class=\"language-text\">fs.watchFile</code> as well as using native <code class=\"language-text\">fsevents</code> on macOS.</li>\n<li><a href=\"https://github.com/sindresorhus/find-up\">find-up</a> - Find a file by walking up parent directories.</li>\n<li><a href=\"https://github.com/IndigoUnited/node-proper-lockfile\">proper-lockfile</a> - Inter-process and inter-machine lockfile utility.</li>\n<li><a href=\"https://github.com/sindresorhus/load-json-file\">load-json-file</a> - Read and parse a JSON file.</li>\n<li><a href=\"https://github.com/sindresorhus/write-json-file\">write-json-file</a> - Stringify and write JSON to a file atomically.</li>\n<li><a href=\"https://github.com/npm/fs-write-stream-atomic\">fs-write-stream-atomic</a> - Like <code class=\"language-text\">fs.createWriteStream()</code>, but atomic.</li>\n<li><a href=\"https://github.com/sindresorhus/filenamify\">filenamify</a> - Convert a string to a valid filename.</li>\n<li><a href=\"https://github.com/kevva/lnfs\">lnfs</a> - Force create symlinks like <code class=\"language-text\">ln -fs</code>.</li>\n<li><a href=\"https://github.com/bevry/istextorbinary\">istextorbinary</a> - Check if a file is text or binary.</li>\n<li><a href=\"https://github.com/szwacz/fs-jetpack\">fs-jetpack</a> - Completely redesigned file system API for convenience in everyday use.</li>\n<li><a href=\"https://github.com/jprichardson/node-fs-extra\">fs-extra</a> - Extra methods for the <code class=\"language-text\">fs</code> module.</li>\n<li><a href=\"https://github.com/sindresorhus/pkg-dir\">pkg-dir</a> - Find the root directory of an npm package.</li>\n<li><a href=\"https://github.com/nspragg/filehound\">filehound</a> - Flexible and fluent interface for searching the file system.</li>\n<li><a href=\"https://github.com/sindresorhus/move-file\">move-file</a> - Move a file, even works across devices.</li>\n<li><a href=\"https://github.com/sindresorhus/tempy\">tempy</a> - Get a random temporary file or directory path.</li>\n</ul>\n<h3>Control flow</h3>\n<ul>\n<li>\n<p>Promises</p>\n<ul>\n<li><a href=\"https://github.com/petkaantonov/bluebird\">Bluebird</a> - Promise library with focus on innovative features and performance.</li>\n<li><a href=\"https://github.com/sindresorhus/pify\">pify</a> - Promisify a callback-style function.</li>\n<li><a href=\"https://github.com/sindresorhus/delay\">delay</a> - Delay a promise a specified amount of time.</li>\n<li><a href=\"https://github.com/nodeca/promise-memoize\">promise-memoize</a> - Memoize promise-returning functions, with expire and prefetch.</li>\n<li><a href=\"https://github.com/lpinca/valvelet\">valvelet</a> - Limit the execution rate of a promise-returning function.</li>\n<li><a href=\"https://github.com/sindresorhus/p-map\">p-map</a> - Map over promises concurrently.</li>\n<li><a href=\"https://github.com/sindresorhus/promise-fun\">More…</a></li>\n</ul>\n</li>\n<li>\n<p>Observables</p>\n<ul>\n<li><a href=\"https://github.com/zenparsing/zen-observable\">zen-observable</a> - Implementation of Observables.</li>\n<li><a href=\"https://github.com/ReactiveX/RxJS\">RxJS</a> - Reactive programming.</li>\n<li><a href=\"https://github.com/sindresorhus/awesome-observables\">observable-to-promise</a> - Convert an Observable to a Promise.</li>\n<li><a href=\"https://github.com/sindresorhus/awesome-observables\">More…</a></li>\n</ul>\n</li>\n<li>Streams</li>\n<li>\n<ul>\n<li><a href=\"https://github.com/caolan/highland\">Highland.js</a> - Manages synchronous and asynchronous code easily, using nothing more than standard JavaScript and Node-like Streams.</li>\n</ul>\n</li>\n<li>\n<p>Callbacks</p>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/each-async\">each-async</a> - Async concurrent iterator like forEach.</li>\n<li><a href=\"https://github.com/caolan/async\">async</a> - Provides straight-forward, powerful functions for working with asynchronicity.</li>\n</ul>\n</li>\n<li>\n<p>Channels</p>\n<ul>\n<li><a href=\"https://github.com/ubolonton/js-csp\">js-csp</a> - Communicating sequential processes for JavaScript (like Clojurescript core.async, or Go).</li>\n</ul>\n</li>\n</ul>\n<h3>Streams</h3>\n<ul>\n<li><a href=\"https://github.com/rvagg/through2\">through2</a> - Tiny wrapper around streams2 Transform to avoid explicit subclassing noise.</li>\n<li><a href=\"https://github.com/hughsk/from2\">from2</a> - Convenience wrapper for ReadableStream, inspired by <code class=\"language-text\">through2</code>.</li>\n<li><a href=\"https://github.com/sindresorhus/get-stream\">get-stream</a> - Get a stream as a string or buffer.</li>\n<li><a href=\"https://github.com/sindresorhus/into-stream\">into-stream</a> - Convert a buffer/string/array/object into a stream.</li>\n<li><a href=\"https://github.com/mafintosh/duplexify\">duplexify</a> - Turn a writeable and readable stream into a single streams2 duplex stream.</li>\n<li><a href=\"https://github.com/mafintosh/pumpify\">pumpify</a> - Combine an array of streams into a single duplex stream.</li>\n<li><a href=\"https://github.com/mafintosh/peek-stream\">peek-stream</a> - Transform stream that lets you peek the first line before deciding how to parse it.</li>\n<li><a href=\"https://github.com/maxogden/binary-split\">binary-split</a> - Newline (or any delimiter) splitter stream.</li>\n<li><a href=\"https://github.com/jahewson/node-byline\">byline</a> - Super-simple line-by-line Stream reader.</li>\n<li><a href=\"https://github.com/sindresorhus/first-chunk-stream\">first-chunk-stream</a> - Transform the first chunk in a stream.</li>\n<li><a href=\"https://github.com/sindresorhus/pad-stream\">pad-stream</a> - Pad each line in a stream.</li>\n<li><a href=\"https://github.com/feross/multistream\">multistream</a> - Combine multiple streams into a single stream.</li>\n<li><a href=\"https://github.com/substack/stream-combiner2\">stream-combiner2</a> - Turn a pipeline into a single stream.</li>\n<li><a href=\"https://github.com/nodejs/readable-stream\">readable-stream</a> - Mirror of Streams2 and Streams3 implementations in core.</li>\n<li><a href=\"https://github.com/almost/through2-concurrent\">through2-concurrent</a> - Transform object streams concurrently.</li>\n</ul>\n<h3>Real-time</h3>\n<ul>\n<li><a href=\"https://github.com/uWebSockets/uWebSockets\">µWebSockets</a> - Highly scalable WebSocket server &#x26; client library.</li>\n<li><a href=\"https://github.com/socketio/socket.io\">Socket.io</a> - Enables real-time bidirectional event-based communication.</li>\n<li><a href=\"https://github.com/faye/faye\">Faye</a> - Real-time client-server message bus, based on Bayeux protocol.</li>\n<li><a href=\"https://github.com/SocketCluster/socketcluster\">SocketCluster</a> - Scalable HTTP + WebSocket engine which can run on multiple CPU cores.</li>\n<li><a href=\"https://github.com/primus/primus\">Primus</a> - An abstraction layer for real-time frameworks to prevent module lock-in.</li>\n<li><a href=\"https://github.com/deepstreamIO/deepstream.io-client-js\">deepstream.io</a> - Scalable real-time microservice framework.</li>\n<li><a href=\"https://github.com/kalm/kalm.js\">Kalm</a> - Low-level socket router and middleware framework.</li>\n<li><a href=\"https://github.com/mqttjs/MQTT.js\">MQTT.js</a> - Client for MQTT - Pub-sub based messaging protocol for use on top of TCP/IP.</li>\n<li><a href=\"https://github.com/elpheria/rpc-websockets\">rpc-websockets</a> - JSON-RPC 2.0 implementation over WebSockets.</li>\n<li><a href=\"https://github.com/mcollina/aedes\">Aedes</a> - Barebone MQTT server that can run on any stream server.</li>\n</ul>\n<h3>Image</h3>\n<ul>\n<li><a href=\"https://github.com/lovell/sharp\">sharp</a> - The fastest module for resizing JPEG, PNG, WebP and TIFF images.</li>\n<li><a href=\"https://github.com/sindresorhus/image-type\">image-type</a> - Detect the image type of a Buffer/Uint8Array.</li>\n<li><a href=\"https://github.com/aheckmann/gm\">gm</a> - GraphicsMagick and ImageMagick wrapper.</li>\n<li><a href=\"https://github.com/EyalAr/lwip\">lwip</a> - Lightweight image processor which does not require ImageMagick.</li>\n<li><a href=\"https://github.com/nodeca/pica\">pica</a> - High quality &#x26; fast resize (lanczos3) in pure JS. Alternative to canvas drawImage(), when no pixelation allowed.</li>\n<li><a href=\"https://github.com/oliver-moran/jimp\">jimp</a> - Image processing in pure JavaScript.</li>\n<li><a href=\"https://github.com/nodeca/probe-image-size\">probe-image-size</a> - Get the size of most image formats without a full download.</li>\n<li><a href=\"https://github.com/soldair/node-qrcode\">qrcode</a> - QR code and bar code generator.</li>\n<li><a href=\"https://github.com/matmen/ImageScript\">ImageScript</a> - Image processing in JavaScript, utilizing WebAssembly for performance.</li>\n</ul>\n<h3>Text</h3>\n<ul>\n<li><a href=\"https://github.com/ashtuchkin/iconv-lite\">iconv-lite</a> - Convert character encodings.</li>\n<li><a href=\"https://github.com/sindresorhus/string-length\">string-length</a> - Get the real length of a string - by correctly counting astral symbols and ignoring ansi escape codes.</li>\n<li><a href=\"https://github.com/sindresorhus/camelcase\">camelcase</a> - Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar.</li>\n<li><a href=\"https://github.com/sindresorhus/escape-string-regexp\">escape-string-regexp</a> - Escape RegExp special characters.</li>\n<li><a href=\"https://github.com/sindresorhus/execall\">execall</a> - Find multiple RegExp matches in a string.</li>\n<li><a href=\"https://github.com/sindresorhus/splice-string\">splice-string</a> - Remove or replace part of a string like <code class=\"language-text\">Array#splice</code>.</li>\n<li><a href=\"https://github.com/sindresorhus/indent-string\">indent-string</a> - Indent each line in a string.</li>\n<li><a href=\"https://github.com/sindresorhus/strip-indent\">strip-indent</a> - Strip leading whitespace from every line in a string.</li>\n<li><a href=\"https://github.com/sindresorhus/detect-indent\">detect-indent</a> - Detect the indentation of code.</li>\n<li><a href=\"https://github.com/mathiasbynens/he\">he</a> - HTML entity encoder/decoder.</li>\n<li><a href=\"https://github.com/mashpie/i18n-node\">i18n-node</a> - Simple translation module with dynamic JSON storage.</li>\n<li><a href=\"https://github.com/nodeca/babelfish\">babelfish</a> - i18n with very easy syntax for plurals.</li>\n<li><a href=\"https://github.com/sindresorhus/matcher\">matcher</a> - Simple wildcard matching.</li>\n<li><a href=\"https://github.com/nodeca/unhomoglyph\">unhomoglyph</a> - Normalize visually similar unicode characters.</li>\n<li><a href=\"https://github.com/i18next/i18next\">i18next</a> - Internationalization framework.</li>\n<li><a href=\"https://github.com/ai/nanoid\">nanoid</a> - Tiny, secure, URL-friendly, unique string ID generator.</li>\n<li><a href=\"https://github.com/kurolabs/stegcloak\">StegCloak</a> - Conceal secrets within strings, in plain sight.</li>\n</ul>\n<h3>Number</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/random-int\">random-int</a> - Generate a random integer.</li>\n<li><a href=\"https://github.com/sindresorhus/random-float\">random-float</a> - Generate a random float.</li>\n<li><a href=\"https://github.com/sindresorhus/unique-random\">unique-random</a> - Generate random numbers that are consecutively unique.</li>\n<li><a href=\"https://github.com/sindresorhus/round-to\">round-to</a> - Round a number to a specific number of decimal places: <code class=\"language-text\">1.234</code> → <code class=\"language-text\">1.2</code>.</li>\n</ul>\n<h3>Math</h3>\n<ul>\n<li><a href=\"https://github.com/scijs/ndarray\">ndarray</a> - Multidimensional arrays.</li>\n<li><a href=\"https://github.com/josdejong/mathjs\">mathjs</a> - An extensive math library.</li>\n<li><a href=\"https://github.com/sindresorhus/math-clamp\">math-clamp</a> - Clamp a number.</li>\n<li><a href=\"https://github.com/fibo/algebra\">algebra</a> - Algebraic structures.</li>\n<li><a href=\"https://github.com/nodeca/multimath\">multimath</a> - Core to create fast image math in WebAssembly and JS.</li>\n</ul>\n<h3>Date</h3>\n<ul>\n<li><a href=\"https://github.com/moment/luxon\">Luxon</a> - Library for working with dates and times.</li>\n<li><a href=\"https://github.com/date-fns/date-fns\">date-fns</a> - Modern date utility.</li>\n<li><a href=\"http://momentjs.com\">Moment.js</a> - Parse, validate, manipulate, and display dates.</li>\n<li><a href=\"https://github.com/iamkun/dayjs\">Day.js</a> - Immutable date library alternative to Moment.js.</li>\n<li><a href=\"https://github.com/felixge/node-dateformat\">dateformat</a> - Date formatting.</li>\n<li><a href=\"https://github.com/samverschueren/tz-format\">tz-format</a> - Format a date with timezone: <code class=\"language-text\">2015-11-30T10:40:35+01:00</code>.</li>\n<li><a href=\"https://github.com/floatdrop/node-cctz\">cctz</a> - Fast parsing, formatting, and timezone conversation for dates.</li>\n</ul>\n<h3>URL</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/normalize-url\">normalize-url</a> - Normalize a URL.</li>\n<li><a href=\"https://github.com/sindresorhus/humanize-url\">humanize-url</a> - Humanize a URL: <a href=\"http://sindresorhus.com\">http://sindresorhus.com</a> → sindresorhus.com.</li>\n<li><a href=\"https://github.com/nodeca/url-unshort\">url-unshort</a> - Expand shortened URLs.</li>\n<li><a href=\"https://github.com/pid/speakingurl\">speakingurl</a> - Generate a slug from a string with transliteration.</li>\n<li><a href=\"https://github.com/markdown-it/linkify-it\">linkify-it</a> - Link patterns detector with full unicode support.</li>\n<li><a href=\"https://github.com/snd/url-pattern\">url-pattern</a> - Easier than regex string matching patterns for URLs and other strings.</li>\n<li><a href=\"https://github.com/nodeca/embedza\">embedza</a> - Create HTML snippets/embeds from URLs using info from oEmbed, Open Graph, meta tags.</li>\n</ul>\n<h3>Data validation</h3>\n<ul>\n<li><a href=\"https://github.com/hapijs/joi\">joi</a> - Object schema description language and validator for JavaScript objects.</li>\n<li><a href=\"https://github.com/mafintosh/is-my-json-valid\">is-my-json-valid</a> - JSON Schema validator that uses code generation to be extremely fast.</li>\n<li><a href=\"https://github.com/nettofarah/property-validator\">property-validator</a> - Easy property validation for Express.</li>\n<li><a href=\"https://github.com/Atinux/schema-inspector\">schema-inspector</a> - JSON API sanitization and validation.</li>\n<li><a href=\"https://github.com/epoberezkin/ajv\">ajv</a> - The fastest JSON Schema validator. Supports v5, v6 and v7 proposals.</li>\n<li><a href=\"https://github.com/ianstormtaylor/superstruct\">Superstruct</a> - Simple and composable way to validate data in JavaScript (and TypeScript).</li>\n</ul>\n<h3>Parsing</h3>\n<ul>\n<li><a href=\"https://github.com/wooorm/remark\">remark</a> - Markdown processor powered by plugins.</li>\n<li><a href=\"https://github.com/markdown-it/markdown-it\">markdown-it</a> - Markdown parser with 100% CommonMark support, extensions and syntax plugins.</li>\n<li><a href=\"https://github.com/inikulin/parse5\">parse5</a> - Fast full-featured spec compliant HTML parser.</li>\n<li><a href=\"https://github.com/sindresorhus/strip-json-comments\">strip-json-comments</a> - Strip comments from JSON.</li>\n<li><a href=\"https://github.com/sindresorhus/strip-css-comments\">strip-css-comments</a> - Strip comments from CSS.</li>\n<li><a href=\"https://github.com/sindresorhus/parse-json\">parse-json</a> - Parse JSON with more helpful errors.</li>\n<li><a href=\"https://github.com/medialize/URI.js\">URI.js</a> - URL mutation.</li>\n<li><a href=\"https://github.com/postcss/postcss\">PostCSS</a> - CSS parser / stringifier.</li>\n<li><a href=\"https://github.com/dominictarr/JSONStream\">JSONStream</a> - Streaming JSON.parse and stringify.</li>\n<li><a href=\"https://github.com/sindresorhus/neat-csv\">neat-csv</a> - Fast CSV parser. Callback interface for the above.</li>\n<li><a href=\"https://github.com/mafintosh/csv-parser\">csv-parser</a> - Streaming CSV parser that aims to be faster than everyone else.</li>\n<li><a href=\"https://github.com/pegjs/pegjs\">PEG.js</a> - Simple parser generator that produces fast parsers with excellent error reporting.</li>\n<li><a href=\"https://github.com/lapwinglabs/x-ray\">x-ray</a> - Web scraping utility.</li>\n<li><a href=\"https://github.com/Hardmath123/nearley\">nearley</a> - Simple, fast, powerful parsing for JavaScript.</li>\n<li><a href=\"https://github.com/juliangruber/binary-extract\">binary-extract</a> - Extract a value from a buffer of JSON without parsing the whole thing.</li>\n<li><a href=\"https://github.com/stylecow/stylecow\">Stylecow</a> - Parse, manipulate and convert modern CSS to make it compatible with all browsers. Extensible with plugins.</li>\n<li><a href=\"https://github.com/nodeca/js-yaml\">js-yaml</a> - Very fast YAML parser.</li>\n<li><a href=\"https://github.com/Leonidas-from-XIV/node-xml2js\">xml2js</a> - XML to JavaScript object converter.</li>\n<li><a href=\"https://github.com/zaach/jison\">Jison</a> - Friendly JavaScript parser generator. It shares genes with Bison, Yacc and family.</li>\n<li><a href=\"https://github.com/seegno/google-libphonenumber\">google-libphonenumber</a> - Parse, format, store and validate phone numbers.</li>\n<li><a href=\"https://github.com/TooTallNate/ref\">ref</a> - Read/write structured binary data in Buffers.</li>\n<li><a href=\"https://github.com/dtjohnson/xlsx-populate\">xlsx-populate</a> - Read/write Excel XLSX.</li>\n<li><a href=\"https://github.com/Chevrotain/chevrotain\">Chevrotain</a> - Very fast and feature rich parser building toolkit for JavaScript.</li>\n<li><a href=\"https://github.com/NaturalIntelligence/fast-xml-parser\">fast-xml-parser</a> - Validate and parse XML.</li>\n</ul>\n<h3>Humanize</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/pretty-bytes\">pretty-bytes</a> - Convert bytes to a human readable string: <code class=\"language-text\">1337</code> → <code class=\"language-text\">1.34 kB</code>.</li>\n<li><a href=\"https://github.com/sindresorhus/pretty-ms\">pretty-ms</a> - Convert milliseconds to a human readable string: <code class=\"language-text\">1337000000</code> → <code class=\"language-text\">15d 11h 23m 20s</code>.</li>\n<li><a href=\"https://github.com/rauchg/ms.js\">ms</a> - Tiny millisecond conversion utility.</li>\n<li><a href=\"https://github.com/AriaMinaei/pretty-error\">pretty-error</a> - Errors with less clutter.</li>\n<li><a href=\"https://github.com/Tjatse/node-readability\">read-art</a> - Extract readable content from any page.</li>\n</ul>\n<h3>Compression</h3>\n<ul>\n<li><a href=\"https://github.com/thejoshwolfe/yazl\">yazl</a> - Zip.</li>\n<li><a href=\"https://github.com/thejoshwolfe/yauzl\">yauzl</a> - Unzip.</li>\n<li><a href=\"https://github.com/archiverjs/node-archiver\">Archiver</a> - Streaming interface for archive generation, supporting ZIP and TAR.</li>\n<li><a href=\"https://github.com/nodeca/pako\">pako</a> - High speed zlib port to pure js (deflate, inflate, gzip).</li>\n<li><a href=\"https://github.com/mafintosh/tar-stream\">tar-stream</a> - Streaming tar parser and generator. Also see <a href=\"https://github.com/mafintosh/tar-fs\">tar-fs</a>.</li>\n<li><a href=\"https://github.com/kevva/decompress\">decompress</a> - Decompression module with support for <code class=\"language-text\">tar</code>, <code class=\"language-text\">tar.gz</code> and <code class=\"language-text\">zip</code> files out of the box.</li>\n</ul>\n<h3>Network</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/get-port\">get-port</a> - Get an available port.</li>\n<li><a href=\"https://github.com/sindresorhus/ipify\">ipify</a> - Get your public IP address.</li>\n<li><a href=\"https://github.com/bevry/getmac\">getmac</a> - Get the computer MAC address.</li>\n<li><a href=\"https://github.com/infusion/node-dhcp\">DHCP</a> - DHCP client and server.</li>\n<li><a href=\"https://github.com/roccomuso/netcat\">netcat</a> - Netcat port in pure JS.</li>\n</ul>\n<h3>Database</h3>\n<ul>\n<li>\n<p>Drivers</p>\n<ul>\n<li><a href=\"https://github.com/brianc/node-postgres\">PostgreSQL</a> - PostgreSQL client. Pure JavaScript and native libpq bindings.</li>\n<li><a href=\"https://github.com/luin/ioredis\">Redis</a> - Redis client.</li>\n<li><a href=\"https://github.com/Level/levelup\">LevelUP</a> - LevelDB.</li>\n<li><a href=\"https://github.com/mysqljs/mysql\">MySQL</a> - MySQL client.</li>\n<li><a href=\"https://github.com/apache/couchdb-nano\">couchdb-nano</a> - CouchDB client.</li>\n<li><a href=\"https://github.com/aerospike/aerospike-client-nodejs\">Aerospike</a> - Aerospike client.</li>\n<li><a href=\"https://github.com/couchbase/couchnode\">Couchbase</a> - Couchbase client.</li>\n<li><a href=\"https://github.com/mongodb/node-mongodb-native\">MongoDB</a> - MongoDB driver.</li>\n</ul>\n</li>\n<li>\n<p>ODM / ORM</p>\n<ul>\n<li><a href=\"https://github.com/sequelize/sequelize\">Sequelize</a> - Multi-dialect ORM. Supports PostgreSQL, SQLite, MySQL, and more.</li>\n<li><a href=\"https://github.com/bookshelf/bookshelf\">Bookshelf</a> - ORM for PostgreSQL, MySQL and SQLite3 in the style of Backbone.js.</li>\n<li><a href=\"https://github.com/robconery/massive-js\">Massive</a> - PostgreSQL data access tool.</li>\n<li><a href=\"https://github.com/Automattic/mongoose\">Mongoose</a> - Elegant MongoDB object modeling.</li>\n<li><a href=\"https://github.com/balderdashy/waterline\">Waterline</a> - Datastore-agnostic tool that dramatically simplifies interaction with one or more databases.</li>\n<li><a href=\"https://github.com/PhilWaldmann/openrecord\">OpenRecord</a> - ORM for PostgreSQL, MySQL, SQLite3 and RESTful datastores. Similar to ActiveRecord.</li>\n<li><a href=\"https://github.com/vitaly-t/pg-promise\">pg-promise</a> - PostgreSQL framework for native SQL using promises.</li>\n<li><a href=\"https://github.com/gajus/slonik\">slonik</a> - PostgreSQL client with strict types, detailed logging and assertions.</li>\n<li><a href=\"https://github.com/Vincit/objection.js\">Objection.js</a> - Lightweight ORM built on the SQL query builder Knex.</li>\n<li><a href=\"https://github.com/typeorm/typeorm\">TypeORM</a> - ORM for PostgreSQL, MariaDB, MySQL, SQLite, and more.</li>\n<li><a href=\"https://github.com/mikro-orm/mikro-orm\">MikroORM</a> - TypeScript ORM based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, PostgreSQL, MySQL and SQLite.</li>\n<li><a href=\"https://github.com/prisma/prisma\">Prisma</a> - Modern database access (ORM alternative). Auto-generated and type-safe query builder in TypeScript. Supports PostgreSQL, MySQL &#x26; SQLite.</li>\n</ul>\n</li>\n<li>Query builder</li>\n<li>\n<ul>\n<li><a href=\"https://github.com/tgriesser/knex\">Knex</a> - Query builder for PostgreSQL, MySQL and SQLite3, designed to be flexible, portable, and fun to use.</li>\n</ul>\n</li>\n<li>\n<p>Other</p>\n<ul>\n<li><a href=\"https://github.com/louischatriot/nedb\">NeDB</a> - Embedded persistent database written in JavaScript.</li>\n<li><a href=\"https://github.com/typicode/lowdb\">Lowdb</a> - Small JavaScript database powered by Lodash.</li>\n<li><a href=\"https://github.com/lukechilds/keyv\">Keyv</a> - Simple key-value storage with support for multiple backends.</li>\n<li><a href=\"https://github.com/tommybananas/finale\">Finale</a> - RESTful endpoint generator for your Sequelize models.</li>\n<li><a href=\"https://github.com/mlaanderson/database-js\">database-js</a> - Wrapper for multiple databases with a JDBC-like connection.</li>\n<li><a href=\"https://github.com/pkosiec/mongo-seeding\">Mongo Seeding</a> - Populate MongoDB databases with JavaScript and JSON files.</li>\n<li><a href=\"https://github.com/ForbesLindesay/atdatabases\">@databases</a> - Query PostgreSQL, MySQL and SQLite3 with plain SQL without risking SQL injection.</li>\n<li><a href=\"https://github.com/oguimbal/pg-mem\">pg-mem</a> - In-memory PostgreSQL instance for your tests.</li>\n</ul>\n</li>\n</ul>\n<h3>Testing</h3>\n<ul>\n<li><a href=\"https://github.com/avajs/ava\">AVA</a> - Futuristic test runner.</li>\n<li><a href=\"https://github.com/mochajs/mocha\">Mocha</a> - Feature-rich test framework making asynchronous testing simple and fun.</li>\n<li><a href=\"https://github.com/bcoe/nyc\">nyc</a> - Code coverage tool built on istanbul that works with subprocesses.</li>\n<li><a href=\"https://github.com/isaacs/node-tap\">tap</a> - TAP test framework.</li>\n<li><a href=\"https://github.com/substack/tape\">tape</a> - TAP-producing test harness.</li>\n<li><a href=\"https://github.com/power-assert-js/power-assert\">power-assert</a> - Provides descriptive assertion messages through the standard assert interface.</li>\n<li><a href=\"https://github.com/mantoni/mochify.js\">Mochify</a> - TDD with Browserify, Mocha, PhantomJS and WebDriver.</li>\n<li><a href=\"https://github.com/vdemedes/trevor\">trevor</a> - Run tests against multiple versions of Node.js without switching versions manually or pushing to Travis CI.</li>\n<li><a href=\"https://github.com/alexfernandez/loadtest\">loadtest</a> - Run load tests for your web application, with an API for automation.</li>\n<li><a href=\"https://github.com/sinonjs/sinon\">Sinon.JS</a> - Test spies, stubs and mocks.</li>\n<li><a href=\"https://github.com/nodeca/navit\">navit</a> - PhantomJS / SlimerJS wrapper to simplify browser test scripting.</li>\n<li><a href=\"https://github.com/pgte/nock\">Nock</a> - HTTP mocking and expectations.</li>\n<li><a href=\"https://github.com/theintern/intern\">intern</a> - Code testing stack.</li>\n<li><a href=\"https://github.com/h2non/toxy\">toxy</a> - Hackable HTTP proxy to simulate failure scenarios and network conditions.</li>\n<li><a href=\"https://github.com/sindresorhus/hook-std\">hook-std</a> - Hook and modify stdout/stderr.</li>\n<li><a href=\"https://github.com/egoist/testen\">testen</a> - Run tests for multiple versions of Node.js locally with NVM.</li>\n<li><a href=\"https://github.com/nightwatchjs/nightwatch\">Nightwatch</a> - Automated UI testing framework based on Selenium WebDriver.</li>\n<li><a href=\"https://github.com/webdriverio/webdriverio\">WebdriverIO</a> - Automated testing based on the WebDriver protocol.</li>\n<li><a href=\"https://github.com/facebook/jest\">Jest</a> - Painless JavaScript testing.</li>\n<li><a href=\"https://github.com/DevExpress/testcafe\">TestCafe</a> - Automated browser testing.</li>\n<li><a href=\"https://github.com/bleenco/abstruse\">abstruse</a> - Continuous Integration server.</li>\n<li><a href=\"https://github.com/Codeception/CodeceptJS\">CodeceptJS</a> - End-to-end testing.</li>\n<li><a href=\"https://github.com/GoogleChrome/puppeteer\">Puppeteer</a> - Headless Chrome.</li>\n<li><a href=\"https://github.com/microsoft/playwright\">Playwright</a> - Headless Chromium, WebKit, and Firefox with a single API.</li>\n<li><a href=\"https://github.com/ehmicky/nve\">nve</a> - Run any command on multiple versions of Node.js locally.</li>\n<li><a href=\"https://github.com/dequelabs/axe-core\">axe-core</a> - Accessibility engine for automated Web UI testing.</li>\n<li><a href=\"https://github.com/testcontainers/testcontainers-node\">testcontainers-node</a> - Provides lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.</li>\n</ul>\n<h3>Security</h3>\n<ul>\n<li><a href=\"https://github.com/simonepri/upash\">upash</a> - Unified API for all password hashing algorithms.</li>\n<li><a href=\"https://github.com/cossacklabs/themis\">themis</a> - Multilanguage framework for making typical encryption schemes easy to use: data at rest, authenticated data exchange, transport protection, authentication, and so on.</li>\n<li><a href=\"https://github.com/apps/guardrails\">GuardRails</a> - GitHub app that provides security feedback in pull requests.</li>\n<li><a href=\"https://github.com/animir/node-rate-limiter-flexible\">rate-limiter-flexible</a> - Brute-force and DDoS attack protection.</li>\n<li><a href=\"https://github.com/sindresorhus/crypto-hash\">crypto-hash</a> - Async non-blocking hashing.</li>\n<li><a href=\"https://github.com/davesag/jose-simple\">jose-simple</a> - Encryption and decryption of data using the JOSE (JSON Object Signing and Encryption) standard.</li>\n</ul>\n<h3>Benchmarking</h3>\n<ul>\n<li><a href=\"https://github.com/bestiejs/benchmark.js\">Benchmark.js</a> - Benchmarking library that supports high-resolution timers and returns statistically significant results.</li>\n<li><a href=\"https://github.com/logicalparadox/matcha\">matcha</a> - Simplistic approach to benchmarking.</li>\n</ul>\n<h3>Minifiers</h3>\n<ul>\n<li><a href=\"https://github.com/babel/babili\">babili</a> - ES2015+ aware minifier based on the Babel toolchain.</li>\n<li><a href=\"https://github.com/mishoo/UglifyJS2\">UglifyJS2</a> - JavaScript minifier.</li>\n<li><a href=\"https://github.com/jakubpawlowicz/clean-css\">clean-css</a> - CSS minifier.</li>\n<li><a href=\"https://github.com/Swaagie/minimize\">minimize</a> - HTML minifier.</li>\n<li><a href=\"https://github.com/imagemin/imagemin\">imagemin</a> - Image minifier.</li>\n</ul>\n<h3>Authentication</h3>\n<ul>\n<li><a href=\"https://github.com/jaredhanson/passport\">Passport</a> - Simple, unobtrusive authentication.</li>\n<li><a href=\"https://github.com/simov/grant\">Grant</a> - OAuth providers for Express, Koa, Hapi, Fastify, AWS Lambda, Azure, Google Cloud, Vercel, and many more.</li>\n</ul>\n<h3>Authorization</h3>\n<ul>\n<li><a href=\"https://github.com/stalniy/casl\">CASL</a> - Isomorphic authorization for UI and API.</li>\n<li><a href=\"https://github.com/casbin/node-casbin\">node-casbin</a> - Authorization library that supports access control models like ACL, RBAC and ABAC.</li>\n</ul>\n<h3>Email</h3>\n<ul>\n<li><a href=\"https://github.com/andris9/Nodemailer\">Nodemailer</a> - The fastest way to handle email.</li>\n<li><a href=\"https://github.com/eleith/emailjs\">emailjs</a> - Send text/HTML emails with attachments to any SMTP server.</li>\n<li><a href=\"https://github.com/niftylettuce/email-templates\">email-templates</a> - Create, preview, and send custom email templates.</li>\n<li><a href=\"https://github.com/mjmlio/mjml\">MJML</a> - Markup language designed to reduce the pain of creating responsive emails.</li>\n</ul>\n<h3>Job queues</h3>\n<ul>\n<li><a href=\"https://github.com/OptimalBits/bull\">bull</a> - Persistent job and message queue.</li>\n<li><a href=\"https://github.com/rschmukler/agenda\">agenda</a> - MongoDB-backed job scheduling.</li>\n<li><a href=\"https://github.com/nodeca/idoit\">idoit</a> - Redis-backed job queue engine with advanced job control.</li>\n<li><a href=\"https://github.com/taskrabbit/node-resque\">node-resque</a> - Redis-backed job queue.</li>\n<li><a href=\"https://github.com/smrchy/rsmq\">rsmq</a> - Redis-backed message queue.</li>\n<li><a href=\"https://github.com/bee-queue/bee-queue\">bee-queue</a> - High-performance Redis-backed job queue.</li>\n<li><a href=\"https://github.com/weyoss/redis-smq\">RedisSMQ</a> - Simple high-performance Redis message queue with real-time monitoring.</li>\n<li><a href=\"https://github.com/bbc/sqs-consumer\">sqs-consumer</a> - Build Amazon Simple Queue Service (SQS) based apps without the boilerplate.</li>\n<li><a href=\"https://github.com/diamondio/better-queue\">better-queue</a> - Simple and efficient job queue when you cannot use Redis.</li>\n</ul>\n<h3>Node.js management</h3>\n<ul>\n<li><a href=\"https://github.com/tj/n\">n</a> - Node.js version management.</li>\n<li><a href=\"https://github.com/isaacs/nave\">nave</a> - Virtual Environments for Node.js.</li>\n<li><a href=\"https://github.com/ekalinin/nodeenv\">nodeenv</a> - Node.js virtual environment compatible to Python's virtualenv.</li>\n<li><a href=\"https://github.com/coreybutler/nvm-windows\">nvm for Windows</a> - Version management for Windows.</li>\n<li><a href=\"https://github.com/nodenv/nodenv\">nodenv</a> - Version manager that is similar to Ruby's rbenv. It supports auto version switching.</li>\n<li><a href=\"https://github.com/Schniz/fnm\">fnm</a> - Cross-platform Node.js version manager built in Rust.</li>\n</ul>\n<h3>Natural language processing</h3>\n<ul>\n<li><a href=\"https://github.com/wooorm/retext\">retext</a> - An extensible natural language system.</li>\n<li><a href=\"https://github.com/wooorm/franc\">franc</a> - Detect the language of text.</li>\n<li><a href=\"https://github.com/sindresorhus/leven\">leven</a> - Measure the difference between two strings using the Levenshtein distance algorithm.</li>\n<li><a href=\"https://github.com/NaturalNode/natural\">natural</a> - Natural language facility.</li>\n<li><a href=\"https://github.com/axa-group/nlp.js\">nlp.js</a> - Building bots, with entity extraction, sentiment analysis, automatic language identify, and more.</li>\n</ul>\n<h3>Process management</h3>\n<ul>\n<li><a href=\"https://github.com/Unitech/pm2\">PM2</a> - Advanced Process Manager.</li>\n<li><a href=\"https://github.com/remy/nodemon\">nodemon</a> - Monitor for changes in your app and automatically restart the server.</li>\n<li><a href=\"https://github.com/coreybutler/node-mac\">node-mac</a> - Run scripts as a native Mac daemon and log to the console app.</li>\n<li><a href=\"https://github.com/coreybutler/node-linux\">node-linux</a> - Run scripts as native system service and log to syslog.</li>\n<li><a href=\"https://github.com/coreybutler/node-windows\">node-windows</a> - Run scripts as a native Windows service and log to the Event viewer.</li>\n<li><a href=\"https://github.com/petruisfan/node-supervisor\">supervisor</a> - Restart scripts when they crash or restart when a <code class=\"language-text\">*.js</code> file changes.</li>\n<li><a href=\"https://github.com/phusion/passenger\">Phusion Passenger</a> - Friendly process manager that integrates directly into Nginx.</li>\n</ul>\n<h3>Automation</h3>\n<ul>\n<li><a href=\"https://github.com/octalmage/robotjs\">robotjs</a> - Desktop Automation: control the mouse, keyboard and read the screen.</li>\n<li><a href=\"https://github.com/nut-tree/nut.js\">nut.js</a> - Cross-platform native GUI automation / testing framework with image matching capabilities which integrates with Jest.</li>\n</ul>\n<h3>AST</h3>\n<ul>\n<li><a href=\"https://github.com/ternjs/acorn\">Acorn</a> - Tiny, fast JavaScript parser.</li>\n<li><a href=\"https://github.com/babel/babel/tree/master/packages/babel-parser\">babel-parser</a> - JavaScript parser used in Babel.</li>\n<li><a href=\"https://github.com/cherow/cherow\">cherow</a> - JavaScript parser with focus on performance and stability.</li>\n</ul>\n<h3>Static site generators</h3>\n<ul>\n<li><a href=\"https://github.com/jnordberg/wintersmith\">Wintersmith</a> - Flexible, minimalistic, multi-platform static site generator.</li>\n<li><a href=\"https://github.com/assemble/assemble/\">Assemble</a> - Static site generator for Node.js, Grunt.js, and Yeoman.</li>\n<li><a href=\"https://github.com/docpad/docpad\">DocPad</a> - Static site generator with dynamic abilities and huge plugin ecosystem.</li>\n<li><a href=\"https://github.com/phenomic/phenomic\">Phenomic</a> - Modern static website generator based on the React and Webpack ecosystem.</li>\n<li><a href=\"https://github.com/QingWei-Li/docsify\">docsify</a> - Markdown documentation site generator with no statically built HTML files.</li>\n<li><a href=\"https://github.com/brandonweiss/charge\">Charge</a> - Opinionated, zero-config static site generator using JSX and MDX.</li>\n</ul>\n<h3>Content management systems</h3>\n<ul>\n<li><a href=\"https://github.com/keystonejs/keystone\">KeystoneJS</a> - CMS and web application platform built on Express and MongoDB.</li>\n<li><a href=\"https://github.com/apostrophecms/apostrophe\">ApostropheCMS</a> - Content management system with an emphasis on intuitive front end content editing and administration built on Express and MongoDB.</li>\n<li><a href=\"https://github.com/strapi/strapi\">Strapi</a> - Content Management Framework (headless-CMS) to build powerful APIs.</li>\n<li><a href=\"https://github.com/tipeio/tipe\">Tipe</a> - Developer-first content management system with GraphQL and REST API from a schema file.</li>\n<li><a href=\"https://github.com/fiction-com/factor\">Factor</a> - Vue.js dashboard framework and headless CMS.</li>\n<li><a href=\"https://github.com/SoftwareBrothers/admin-bro\">AdminBro</a> - Auto-generated admin panel with CRUD for all your resources.</li>\n</ul>\n<h3>Forum</h3>\n<ul>\n<li><a href=\"https://github.com/NodeBB/NodeBB\">nodeBB</a> - Forum platform for the modern web.</li>\n</ul>\n<h3>Blogging</h3>\n<ul>\n<li><a href=\"https://github.com/TryGhost/Ghost\">Ghost</a> - Simple, powerful publishing platform.</li>\n<li><a href=\"https://github.com/hexojs/hexo\">Hexo</a> - Fast, simple and powerful blogging framework.</li>\n</ul>\n<h3>Weird</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/cows\">cows</a> - ASCII cows.</li>\n<li><a href=\"https://github.com/sindresorhus/superb\">superb</a> - Get superb like words.</li>\n<li><a href=\"https://github.com/sindresorhus/cat-names\">cat-names</a> - Get popular cat names.</li>\n<li><a href=\"https://github.com/sindresorhus/dog-names\">dog-names</a> - Get popular dog names.</li>\n<li><a href=\"https://github.com/sindresorhus/superheroes\">superheroes</a> - Get superhero names.</li>\n<li><a href=\"https://github.com/sindresorhus/supervillains\">supervillains</a> - Get supervillain names.</li>\n<li><a href=\"https://github.com/maxogden/cool-ascii-faces\">cool-ascii-faces</a> - Get some cool ascii faces.</li>\n<li><a href=\"https://github.com/melaniecebula/cat-ascii-faces\">cat-ascii-faces</a> - <code class=\"language-text\">₍˄·͈༝·͈˄₎◞ ̑̑ෆ⃛ (=ↀωↀ=)✧ (^･o･^)ﾉ\"</code>.</li>\n<li><a href=\"https://github.com/SkyHacks/nerds\">nerds</a> - Get data from nerdy topics like Harry Potter, Star Wars, and Pokémon.</li>\n</ul>\n<h3>Serialization</h3>\n<ul>\n<li><a href=\"https://github.com/kesla/node-snappy\">snappy</a> - Native bindings for Google's Snappy compression library.</li>\n<li><a href=\"https://github.com/dcodeIO/protobuf.js\">protobuf</a> - Implementation of Protocol Buffers.</li>\n<li><a href=\"https://github.com/compactr/compactr.js\">compactr</a> - Implementation of the Compactr protocol.</li>\n</ul>\n<h3>Miscellaneous</h3>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/execa\">execa</a> - Better <code class=\"language-text\">child_process</code>.</li>\n<li><a href=\"https://github.com/cheeriojs/cheerio\">cheerio</a> - Fast, flexible, and lean implementation of core jQuery designed specifically for the server.</li>\n<li><a href=\"https://github.com/atom/electron\">Electron</a> - Build cross platform desktop apps with web technologies. <em>(You might like <a href=\"https://github.com/sindresorhus/awesome-electron\">awesome-electron</a>)</em></li>\n<li><a href=\"https://github.com/sindresorhus/open\">open</a> - Opens stuff like websites, files, executables.</li>\n<li><a href=\"https://github.com/sindresorhus/hasha\">hasha</a> - Hashing made simple. Get the hash of a buffer/string/stream/file.</li>\n<li><a href=\"https://github.com/sindresorhus/dot-prop\">dot-prop</a> - Get a property from a nested object using a dot path.</li>\n<li><a href=\"https://github.com/sindresorhus/onetime\">onetime</a> - Only run a function once.</li>\n<li><a href=\"https://github.com/sindresorhus/mem\">mem</a> - Memoize functions - an optimization technique used to speed up consecutive function calls by caching the result of calls with identical input.</li>\n<li><a href=\"https://github.com/sindresorhus/import-fresh\">import-fresh</a> - Import a module while bypassing the cache.</li>\n<li><a href=\"https://github.com/sindresorhus/strip-bom\">strip-bom</a> - Strip UTF-8 byte order mark (BOM) from a string/buffer/stream.</li>\n<li><a href=\"https://github.com/sindresorhus/os-locale\">os-locale</a> - Get the system locale.</li>\n<li><a href=\"https://github.com/mscdex/ssh2\">ssh2</a> - SSH2 client and server module.</li>\n<li><a href=\"https://github.com/markelog/adit\">adit</a> - SSH tunneling made simple.</li>\n<li><a href=\"https://github.com/sindresorhus/import-lazy\">import-lazy</a> - Import a module lazily.</li>\n<li><a href=\"https://github.com/sindresorhus/file-type\">file-type</a> - Detect the file type of a Buffer.</li>\n<li><a href=\"https://github.com/SGrondin/bottleneck\">Bottleneck</a> - Rate limiter that makes throttling easy.</li>\n<li><a href=\"https://github.com/sindresorhus/ow\">ow</a> - Function argument validation for humans.</li>\n<li><a href=\"https://github.com/audreyt/node-webworker-threads\">webworker-threads</a> - Lightweight Web Worker API implementation with native threads.</li>\n<li><a href=\"https://github.com/sindresorhus/clipboardy\">clipboardy</a> - Access the system clipboard (copy/paste).</li>\n<li><a href=\"https://github.com/mapbox/node-pre-gyp\">node-pre-gyp</a> - Makes it easy to publish and install Node.js C++ addons from binaries.</li>\n<li><a href=\"https://github.com/peterbraden/node-opencv\">opencv</a> - Bindings for OpenCV. The defacto computer vision library.</li>\n<li><a href=\"https://github.com/motdotla/dotenv\">dotenv</a> - Load environment variables from .env file.</li>\n<li><a href=\"https://github.com/sindresorhus/remote-git-tags\">remote-git-tags</a> - Get tags from a remote git repo.</li>\n<li><a href=\"https://github.com/npm/node-semver\">semver</a> - Semantic version parser.</li>\n<li><a href=\"https://github.com/Marak/Faker.js\">Faker.js</a> - Generate massive amounts of fake data.</li>\n<li><a href=\"https://github.com/nodegit/nodegit\">nodegit</a> - Native bindings to Git.</li>\n<li><a href=\"https://github.com/pigulla/json-strictify\">json-strictify</a> - Safely serialize a value to JSON without data loss or going into an infinite loop.</li>\n<li><a href=\"https://github.com/sindresorhus/resolve-from\">resolve-from</a> - Resolve the path of a module like <code class=\"language-text\">require.resolve()</code> but from a given path.</li>\n<li><a href=\"https://github.com/cgiffard/node-simplecrawler\">simplecrawler</a> - Event driven web crawler.</li>\n<li><a href=\"https://github.com/tmpvar/jsdom\">jsdom</a> - JavaScript implementation of HTML and the DOM.</li>\n<li><a href=\"https://github.com/airbnb/hypernova\">hypernova</a> - Server-side rendering your JavaScript views.</li>\n<li><a href=\"https://github.com/sindresorhus/is\">@sindresorhus/is</a> - Type check values.</li>\n<li><a href=\"https://github.com/simonepri/env-dot-prop\">env-dot-prop</a> - Get, set, or delete nested properties of process.env using a dot path.</li>\n<li><a href=\"https://github.com/sindresorhus/emittery\">emittery</a> - Simple and modern async event emitter.</li>\n<li><a href=\"https://github.com/gkozlenko/node-video-lib\">node-video-lib</a> - Pure JavaScript library for working with MP4 and FLV video files and creating MPEG-TS chunks for HLS streaming.</li>\n<li><a href=\"https://github.com/patrickjuchli/basic-ftp\">basic-ftp</a> - FTP/FTPS client.</li>\n<li><a href=\"https://github.com/xxczaki/cashify\">cashify</a> - Currency conversion.</li>\n<li><a href=\"https://github.com/Geode-solutions/genepi\">genepi</a> - Automatically generate a native Node.js addon from C++ code.</li>\n<li><a href=\"https://github.com/typicode/husky\">husky</a> - Create Git hook scripts.</li>\n<li><a href=\"https://github.com/ds300/patch-package\">patch-package</a> - Make and preserve fixes to npm dependencies.</li>\n<li><a href=\"https://github.com/mifi/editly\">editly</a> - Declarative video editing API.</li>\n</ul>\n<h2>Resources</h2>\n<h3>Tutorials</h3>\n<ul>\n<li><a href=\"https://github.com/i0natan/nodebestpractices\">Node.js Best Practices</a> - Summary and curation of the top-ranked content on Node.js best practices, available in multiple languages.</li>\n<li><a href=\"https://github.com/nodeschool\">Nodeschool</a> - Learn Node.js with interactive lessons.</li>\n<li><a href=\"https://github.com/maxogden/art-of-node/#the-art-of-node\">The Art of Node</a> - An introduction to Node.js.</li>\n<li><a href=\"https://github.com/substack/stream-handbook\">stream-handbook</a> - How to write Node.js programs with streams.</li>\n<li><a href=\"https://github.com/mattdesl/module-best-practices\">module-best-practices</a> - Some good practices when writing new npm modules.</li>\n<li><a href=\"http://thenodeway.io\">The Node Way</a> - An entire philosophy of Node.js best practices and guiding principles exists for writing maintainable modules, scalable applications, and code that is actually pleasant to read.</li>\n<li><a href=\"https://github.com/azat-co/you-dont-know-node\">You Don't Know Node.js</a> - Introduction to Node.js core features and asynchronous JavaScript.</li>\n<li><a href=\"https://github.com/ehmicky/portable-node-guide\">Portable Node.js guide</a> - Practical guide on how to write portable/cross-platform Node.js code.</li>\n<li><a href=\"https://frameworkless.js.org/course\">Build a real web app with no frameworks</a> - A set of video tutorials/livestreams to help you build and deploy a real, live web app using a handful of simple libraries and the core Node.js modules.</li>\n</ul>\n<h3>Discovery</h3>\n<ul>\n<li><a href=\"https://npms.io\">npms</a> - Superb package search with deep analysis of package quality using a <a href=\"https://npms.io/about\">myriad of metrics</a>.</li>\n<li><a href=\"https://npmaddict.com\">npm addict</a> - Your daily injection of npm packages.</li>\n<li><a href=\"https://npmcompare.com\">npmcompare.com</a> - Compare and discover npm packages.</li>\n</ul>\n<h3>Articles</h3>\n<ul>\n<li><a href=\"https://www.joyent.com/node-js/production/design/errors\">Error Handling in Node.js</a></li>\n<li><a href=\"https://ponyfoo.com/articles/teach-yourself-nodejs-in-10-steps\">Teach Yourself Node.js in 10 Steps</a></li>\n<li><a href=\"https://medium.com/@yoshuawuyts/mastering-the-filesystem-in-node-js-4706b7cb0801\">Mastering the filesystem in Node.js</a></li>\n<li><a href=\"https://nodesource.com/blog/semver-a-primer/\">Semver: A Primer</a></li>\n<li><a href=\"https://nodesource.com/blog/semver-tilde-and-caret/\">Semver: Tilde and Caret</a></li>\n<li><a href=\"https://nodesource.com/blog/why-asynchronous/\">Why Asynchronous?</a></li>\n<li><a href=\"https://nodesource.com/blog/understanding-the-nodejs-event-loop/\">Understanding the Node.js Event Loop</a></li>\n<li><a href=\"https://nodesource.com/blog/understanding-object-streams/\">Understanding Object Streams</a></li>\n<li><a href=\"https://github.com/noffle/art-of-readme\">Art of README</a> - Learn the art of writing quality READMEs.</li>\n<li><a href=\"https://snipcart.com/blog/graphql-nodejs-express-tutorial\">Using Express to Quickly Build a GraphQL Server</a></li>\n</ul>\n<h3>Newsletters</h3>\n<ul>\n<li><a href=\"http://nodeweekly.com\">Node Weekly</a> - Weekly e-mail round-up of Node.js news and articles.</li>\n<li><a href=\"https://nmotw.in\">Node Module Of The Week!</a> - Weekly dose of hand picked node modules.</li>\n</ul>\n<h3>Videos</h3>\n<ul>\n<li><a href=\"https://www.youtube.com/watch?v=jo_B4LTHi3I\">Introduction to Node.js with Ryan Dahl</a></li>\n<li><a href=\"https://learn.bevry.me/hands-on-with-node.js/preface\">Hands on with Node.js</a></li>\n<li><a href=\"http://nodetuts.com\">Nodetuts</a> - Series of talks, including TCP &#x26; HTTP API servers, async programming, and more.</li>\n<li><a href=\"https://v8.dev/blog/trash-talk\">V8 Garbage Collector</a> - Trash talk about the V8 garbage collector.</li>\n<li><a href=\"https://www.youtube.com/watch?v=M3BM9TB-8yA\">10 Things I Regret About Node.js by Ryan Dahl</a> - Insightful talk by the creator of Node.js about some of its limitions.</li>\n<li><a href=\"https://www.manning.com/livevideo/mastering-rest-apis-in-nodejs\">Mastering REST APIs in Node.js: Zero-To-Hero</a> - Video course on how to make REST APIs using Node.js.</li>\n<li><a href=\"https://www.youtube.com/watch?v=_1xa8Bsho6A\">Make a vanilla Node.js REST API</a> - Building a REST API without using a framework like Express.</li>\n<li><a href=\"https://www.youtube.com/watch?v=FrufJFBSoQY\">Google I/O 2009 - V8: High Performance JavaScript Engine</a> - The basics of V8 architecture and how it optimizes JavaScript execution.</li>\n<li><a href=\"https://www.youtube.com/watch?v=UJPdhx5zTaw\">Google I/O 2012 - Breaking the JavaScript Speed Limit with V8</a> - How V8 optimizes JavaScript execution.</li>\n<li><a href=\"https://www.youtube.com/watch?v=VhpdsjBUS3g\">Google I/O 2013 - Accelerating Oz with V8: Follow the Yellow Brick Road to JavaScript Performance</a> - How to detect app bottlenecks and optimize performance with V8 knowledge.</li>\n<li><a href=\"https://www.youtube.com/watch?v=OCjvhCFFPTw\">Node.js Internal Architecture | Ignition, Turbofan, Libuv</a> - How Node.js works internally, with a focus on V8 and libuv.</li>\n<li><a href=\"https://www.youtube.com/watch?v=_c51fcXRLGw\">Introduction to libuv: What's a Unicorn Velociraptor?</a> - <code class=\"language-text\">libuv</code> architecture, thread pool, and event loop, with its source code.</li>\n<li><a href=\"https://www.youtube.com/watch?v=kCJ3PFU8Ke8\">libuv Cross platform asynchronous i/o</a> - <code class=\"language-text\">libuv</code> architecture in detail, such as where it's actually using threads.</li>\n<li><a href=\"https://www.youtube.com/watch?v=oPo4EQmkjvY\">You Don't Know Node - ForwardJS San Francisco</a> - Explaining Node.js internals with quizzes about V8, libuv, event loop, module, stream, and cluster.</li>\n</ul>\n<h3>Books</h3>\n<ul>\n<li><a href=\"https://www.manning.com/books/node-js-in-action-second-edition\">Node.js in Action</a></li>\n<li><a href=\"http://www.amazon.com/Node-js-Practice-Alex-R-Young/dp/1617290939\">Node.js in Practice</a></li>\n<li><a href=\"http://visionmedia.github.io/masteringnode/\">Mastering Node</a></li>\n<li><a href=\"https://pragprog.com/book/jwnode2/node-js-8-the-right-way\">Node.js 8 the Right Way</a></li>\n<li><a href=\"http://www.amazon.com/Professional-Node-js-Building-Javascript-Scalable-ebook/dp/B009L7QETY/\">Professional Node.js: Building JavaScript Based Scalable Software</a></li>\n<li><a href=\"http://practicalnodebook.com\">Practical Node.js: Building Real-World Scalable Web Apps</a></li>\n<li><a href=\"http://book.mixu.net/node/\">Mixu's Node book</a></li>\n<li><a href=\"http://proexpressjs.com\">Pro Express.js</a></li>\n<li><a href=\"http://www.amazon.com/Secure-Your-Node-js-Web-Application/dp/1680500856\">Secure Your Node.js Web Application</a></li>\n<li><a href=\"https://www.manning.com/books/express-in-action\">Express in Action</a></li>\n<li><a href=\"https://www.amazon.com/Practical-Modern-JavaScript-Dive-Future/dp/149194353X\">Practical Modern JavaScript</a></li>\n<li><a href=\"https://www.amazon.com/Mastering-Modular-JavaScript-Nicolas-Bevacqua/dp/1491955686/\">Mastering Modular JavaScript</a></li>\n<li><a href=\"https://www.manning.com/books/get-programming-with-node-js\">Get Programming with Node.js</a></li>\n<li><a href=\"https://www.amazon.com/dp/1838558756\">Node.js Cookbook</a></li>\n<li><a href=\"https://www.nodejsdesignpatterns.com\">Node.js Design Patterns</a></li>\n</ul>\n<h3>Blogs</h3>\n<ul>\n<li><a href=\"https://nodejs.org/en/blog/\">Node.js blog</a></li>\n<li><a href=\"http://webapplog.com/tag/node-js/\">webapplog.com</a> - Blog posts on Node.js and JavaScript from the author of Practical Node.js and Pro Express.js Azat Mardan.</li>\n</ul>\n<h3>Courses</h3>\n<ul>\n<li><a href=\"https://learnnode.com/friend/AWESOME\">Learn to build apps and APIs with Node.js</a> - Video course by Wes Bos.</li>\n<li><a href=\"https://www.codeschool.com/courses/real-time-web-with-node-js\">Real Time Web with Node.js</a></li>\n<li><a href=\"https://www.udemy.com/understand-nodejs\">Learn and Understand Node.js</a></li>\n</ul>\n<h3>Cheatsheets</h3>\n<ul>\n<li><a href=\"https://github.com/azat-co/cheatsheets/blob/master/express4\">Express.js</a></li>\n<li><a href=\"https://github.com/stephenplusplus/stream-faqs\">Stream FAQs</a> - Answering common questions about streams, covering pagination, events, and more.</li>\n<li><a href=\"https://github.com/jesusprubio/strong-node\">Strong Node.js</a> - Checklist for source code security analysis of a Node.js web service.</li>\n</ul>\n<h3>Tools</h3>\n<ul>\n<li><a href=\"https://chrome.google.com/webstore/detail/octolinker/jlmafbaeoofdegohdhinkhilhclaklkp\">OctoLinker</a> - Chrome extension that linkifies dependencies in package.json, .js, .jsx, .coffee and .md files on GitHub.</li>\n<li><a href=\"https://chrome.google.com/webstore/detail/npm-hub/kbbbjimdjbjclaebffknlabpogocablj\">npm-hub</a> - Chrome extension to display npm dependencies at the bottom of a repo's readme.</li>\n<li><a href=\"http://blog.tonicdev.com/2015/09/30/embedded-tonic.html\">RunKit</a> - Embed a Node.js environment on any website.</li>\n<li><a href=\"https://chrome.google.com/webstore/detail/github-npm-stats/oomfflokggoffaiagenekchfnpighcef\">github-npm-stats</a> - Chrome extension that displays npm download stats on GitHub.</li>\n<li><a href=\"https://semver.npmjs.com\">npm semver calculator</a> - Visually explore what versions of a package a semver range matches.</li>\n<li><a href=\"https://codesandbox.io/s/node-http-server-node\">CodeSandbox</a> - Online IDE and prototyping.</li>\n</ul>\n<h3>Community</h3>\n<ul>\n<li><a href=\"https://gitter.im/nodejs/node\">Gitter</a></li>\n<li><a href=\"http://webchat.freenode.net/?channels=node.js\"><code class=\"language-text\">#node.js</code> on Freenode</a></li>\n<li><a href=\"http://stackoverflow.com/questions/tagged/node.js\">Stack Overflow</a></li>\n<li><a href=\"https://www.reddit.com/r/node\">Reddit</a></li>\n<li><a href=\"https://twitter.com/nodejs\">Twitter</a></li>\n<li><a href=\"https://hashnode.com/n/nodejs\">Hashnode</a></li>\n<li><a href=\"https://discordapp.com/invite/96WGtJt\">Discord</a></li>\n</ul>\n<h3>Miscellaneous</h3>\n<ul>\n<li><a href=\"http://nodebots.io\">nodebots</a> - Robots powered by JavaScript.</li>\n<li><a href=\"https://github.com/sindresorhus/node-module-boilerplate\">node-module-boilerplate</a> - Boilerplate to kickstart creating a node module.</li>\n<li><a href=\"https://github.com/sheerun/modern-node\">modern-node</a> - Toolkit for creating node modules with Jest, Prettier, ESLint, and Standard.</li>\n<li><a href=\"https://github.com/sindresorhus/generator-nm\">generator-nm</a> - Scaffold out a node module.</li>\n<li><a href=\"https://github.com/Microsoft/nodejs-guidelines\">Microsoft Node.js Guidelines</a> - Tips, tricks, and resources for working with Node.js on Microsoft platforms.</li>\n<li><a href=\"https://github.com/sindresorhus/module-requests\">Module Requests &#x26; Ideas</a> - Request a JavaScript module you wish existed or get ideas for modules.</li>\n<li><a href=\"https://github.com/thlorenz/v8-perf\">v8-perf</a> - Notes and resources related to V8 and thus Node.js performance.</li>\n</ul>\n<h2>Related lists</h2>\n<ul>\n<li><a href=\"https://github.com/sindresorhus/awesome-npm\">awesome-npm</a> - Resources and tips for using npm.</li>\n<li><a href=\"https://github.com/bcoe/awesome-cross-platform-nodejs\">awesome-cross-platform-nodejs</a> - Resources for writing and testing cross-platform code.</li>\n</ul>"},{"url":"/docs/reference/github-search/","relativePath":"docs/reference/github-search.md","relativeDir":"docs/reference","base":"github-search.md","name":"github-search","frontmatter":{"title":"Github Search","weight":0,"excerpt":"The Search API helps you search for the specific item you want to find. For example, you can find a user or a specific file in a repository. Think of it the way you think of performing a search on Google. Its designed to help you find the one result youre looking for (or maybe the few results youre looking for). Just like searching on Google, you sometimes want to see a few pages of search results so that you can find the item that best meets your needs. To satisfy that need, the GitHub Search API provides **up to 1,000 results for each search**.","seo":{"title":"The Search API helps you search for the specific item you want to find. For example, you can find a user or a specific file in a repository. Think of it the way you think of performing a search on Google. It's designed to help you find the one result you're looking for (or maybe the few results you're looking for). Just like searching on Google, you sometimes want to see a few pages of search results so that you can find the item that best meets your needs. To satisfy that need, the GitHub Search API provides **up to 1,000 results for each search**.:","description":"The Search API helps you search for the specific item you want to find. For example, you can find a user or a specific file in a repository. Think of it the way you think of performing a search on Google. It's designed to help you find the one result you're looking for (or maybe the few results you're looking for). Just like searching on Google, you sometimes want to see a few pages of search results so that you can find the item that best meets your needs. To satisfy that need, the GitHub Search API provides **up to 1,000 results for each search**.:","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Search</h1>\n<blockquote>\n<p>The GitHub Search API lets you to search for the specific item efficiently.</p>\n</blockquote>\n<p>The GitHub Search API lets you to search for the specific item efficiently.</p>\n<p>The Search API helps you search for the specific item you want to find. For example, you can find a user or a specific file in a repository. Think of it the way you think of performing a search on Google. It's designed to help you find the one result you're looking for (or maybe the few results you're looking for). Just like searching on Google, you sometimes want to see a few pages of search results so that you can find the item that best meets your needs. To satisfy that need, the GitHub Search API provides <strong>up to 1,000 results for each search</strong>.</p>\n<p>You can narrow your search using queries. To learn more about the search query syntax, see \"<a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/rest/reference/search#constructing-a-search-query\">Constructing a search query</a>.\"</p>\n<h3><a href=\"#ranking-search-results\">Ranking search results</a></h3>\n<p>Unless another sort option is provided as a query parameter, results are sorted by best match in descending order. Multiple factors are combined to boost the most relevant item to the top of the result list.</p>\n<h3><a href=\"#rate-limit\">Rate limit</a></h3>\n<p>The Search API has a custom rate limit. For requests using <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/rest#authentication\">Basic Authentication</a>, <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/rest#authentication\">OAuth</a>, or <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/rest#increasing-the-unauthenticated-rate-limit-for-oauth-applications\">client ID and secret</a>, you can make up to 30 requests per minute. For unauthenticated requests, the rate limit allows you to make up to 10 requests per minute.</p>\n<p>See the <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/rest/reference/rate-limit\">rate limit documentation</a> for details on determining your current rate limit status.</p>\n<h3><a href=\"#constructing-a-search-query\">Constructing a search query</a></h3>\n<p>Each endpoint in the Search API uses <a href=\"https://en.wikipedia.org/wiki/Query_string\">query parameters</a> to perform searches on GitHub. See the individual endpoint in the Search API for an example that includes the endpoint and query parameters.</p>\n<p>A query can contain any combination of search qualifiers supported on GitHub. The format of the search query is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">SEARCH_KEYWORD_1 SEARCH_KEYWORD_N QUALIFIER_1 QUALIFIER_N</code></pre></div>\n<p>For example, if you wanted to search for all <em>repositories</em> owned by <code class=\"language-text\">defunkt</code> that contained the word <code class=\"language-text\">GitHub</code> and <code class=\"language-text\">Octocat</code> in the README file, you would use the following query with the <em>search repositories</em> endpoint:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">GitHub Octocat in:readme user:defunkt</code></pre></div>\n<p><strong>Note:</strong> Be sure to use your language's preferred HTML-encoder to construct your query strings. For example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const queryString = 'q=' + encodeURIComponent('GitHub Octocat in:readme user:defunkt');</code></pre></div>\n<p>See \"<a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/articles/searching-on-github\">Searching on GitHub</a>\" for a complete list of available qualifiers, their format, and an example of how to use them. For information about how to use operators to match specific quantities, dates, or to exclude results, see \"<a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/articles/understanding-the-search-syntax\">Understanding the search syntax</a>.\"</p>\n<h3><a href=\"#limitations-on-query-length\">Limitations on query length</a></h3>\n<p>The Search API does not support queries that:</p>\n<ul>\n<li>are longer than 256 characters (not including operators or qualifiers).</li>\n<li>have more than five <code class=\"language-text\">AND</code>, <code class=\"language-text\">OR</code>, or <code class=\"language-text\">NOT</code> operators.</li>\n</ul>\n<p>These search queries will return a \"Validation failed\" error message.</p>\n<h3><a href=\"#timeouts-and-incomplete-results\">Timeouts and incomplete results</a></h3>\n<p>To keep the Search API fast for everyone, we limit how long any individual query can run. For queries that <a href=\"https://developer.github.com/changes/2014-04-07-understanding-search-results-and-potential-timeouts/\">exceed the time limit</a>, the API returns the matches that were already found prior to the timeout, and the response has the <code class=\"language-text\">incomplete_results</code> property set to <code class=\"language-text\">true</code>.</p>\n<p>Reaching a timeout does not necessarily mean that search results are incomplete. More results might have been found, but also might not.</p>\n<h3><a href=\"#access-errors-or-missing-search-results\">Access errors or missing search results</a></h3>\n<p>You need to successfully authenticate and have access to the repositories in your search queries, otherwise, you'll see a <code class=\"language-text\">422 Unprocessible Entry</code> error with a \"Validation Failed\" message. For example, your search will fail if your query includes <code class=\"language-text\">repo:</code>, <code class=\"language-text\">user:</code>, or <code class=\"language-text\">org:</code> qualifiers that request resources that you don't have access to when you sign in on GitHub.</p>\n<p>When your search query requests multiple resources, the response will only contain the resources that you have access to and will <strong>not</strong> provide an error message listing the resources that were not returned.</p>\n<p>For example, if your search query searches for the <code class=\"language-text\">octocat/test</code> and <code class=\"language-text\">codertocat/test</code> repositories, but you only have access to <code class=\"language-text\">octocat/test</code>, your response will show search results for <code class=\"language-text\">octocat/test</code> and nothing for <code class=\"language-text\">codertocat/test</code>. This behavior mimics how search works on GitHub.</p>\n<h3><a href=\"#search-code\">Search code</a></h3>\n<p>Searches for query terms inside of a file. This method returns up to 100 results <a href=\"https://docs.github.com/rest/overview/resources-in-the-rest-api#pagination\">per page</a>.</p>\n<p>When searching for code, you can get text match metadata for the file <strong>content</strong> and file <strong>path</strong> fields when you pass the <code class=\"language-text\">text-match</code> media type. For more details about how to receive highlighted search results, see <a href=\"https://docs.github.com/rest/reference/search#text-match-metadata\">Text match metadata</a>.</p>\n<p>For example, if you want to find the definition of the <code class=\"language-text\">addClass</code> function inside <a href=\"https://github.com/jquery/jquery\">jQuery</a> repository, your query would look something like this:</p>\n<p><code class=\"language-text\">q=addClass+in:file+language:js+repo:jquery/jquery</code></p>\n<p>This query searches for the keyword <code class=\"language-text\">addClass</code> within a file's contents. The query limits the search to files where the language is JavaScript in the <code class=\"language-text\">jquery/jquery</code> repository.</p>\n<h4><a href=\"#considerations-for-code-search\">Considerations for code search</a></h4>\n<p>Due to the complexity of searching code, there are a few restrictions on how searches are performed:</p>\n<ul>\n<li>Only the <em>default branch</em> is considered. In most cases, this will be the <code class=\"language-text\">master</code> branch.</li>\n<li>Only files smaller than 384 KB are searchable.</li>\n<li>\n<p>You must always include at least one search term when searching source code. For example, searching for <a href=\"https://github.com/search?utf8=%E2%9C%93&#x26;q=language%3Ago&#x26;type=Code\"><code class=\"language-text\">language:go</code></a> is not valid, while <a href=\"https://github.com/search?utf8=%E2%9C%93&#x26;q=amazing+language%3Ago&#x26;type=Code\"><code class=\"language-text\">amazing language:go</code></a> is.</p>\n<p>get /search/code</p>\n</li>\n</ul>\n<h4><a href=\"#search-code--parameters\">Parameters</a></h4>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Type</th>\n<th>In</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">accept</code></td>\n<td>string</td>\n<td>header</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>Setting to <code class=\"language-text\">application/vnd.github.v3+json</code> is recommended.</p>\n<p>|\n| <code class=\"language-text\">q</code> | string | query |</p>\n<p>The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see <a href=\"https://docs.github.com/rest/reference/search#constructing-a-search-query\">Constructing a search query</a>. See \"<a href=\"https://help.github.com/articles/searching-code/\">Searching code</a>\" for a detailed list of qualifiers.</p>\n<p>|\n| <code class=\"language-text\">sort</code> | string | query |</p>\n<p>Sorts the results of your query. Can only be <code class=\"language-text\">indexed</code>, which indicates how recently a file has been indexed by the GitHub search infrastructure. Default: <a href=\"https://docs.github.com/rest/reference/search#ranking-search-results\">best match</a></p>\n<p>|\n| <code class=\"language-text\">order</code> | string | query |</p>\n<p>Determines whether the first search result returned is the highest number of matches (<code class=\"language-text\">desc</code>) or lowest number of matches (<code class=\"language-text\">asc</code>). This parameter is ignored unless you provide <code class=\"language-text\">sort</code>.</p>\n<p>Default: <code class=\"language-text\">desc</code> |\n| <code class=\"language-text\">per_page</code> | integer | query |</p>\n<p>Results per page (max 100)</p>\n<p>Default: <code class=\"language-text\">30</code> |\n| <code class=\"language-text\">page</code> | integer | query |</p>\n<p>Page number of the results to fetch.</p>\n<p>Default: <code class=\"language-text\">1</code> |</p>\n<h4><a href=\"#search-code--code-samples\">Code samples</a></h4>\n<h5>Shell</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl \\\n  -H \"Accept: application/vnd.github.v3+json\" \\\n  https://api.github.com/search/code</code></pre></div>\n<h5>JavaScript (<a href=\"https://github.com/octokit/core.js#readme\">@octokit/core.js</a>)</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">await octokit.request('GET /search/code', {\n  q: 'q'\n})</code></pre></div>\n<h4>Response</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 200 OK\n\n{\n  \"total_count\": 7,\n  \"incomplete_results\": false,\n  \"items\": [\n    {\n      \"name\": \"classes.js\",\n      \"path\": \"src/attributes/classes.js\",\n      \"sha\": \"d7212f9dee2dcc18f084d7df8f417b80846ded5a\",\n      \"url\": \"https://api.github.com/repositories/167174/contents/src/attributes/classes.js?ref=825ac3773694e0cd23ee74895fd5aeb535b27da4\",\n      \"git_url\": \"https://api.github.com/repositories/167174/git/blobs/d7212f9dee2dcc18f084d7df8f417b80846ded5a\",\n      \"html_url\": \"https://github.com/jquery/jquery/blob/825ac3773694e0cd23ee74895fd5aeb535b27da4/src/attributes/classes.js\",\n      \"repository\": {\n        \"id\": 167174,\n        \"node_id\": \"MDEwOlJlcG9zaXRvcnkxNjcxNzQ=\",\n        \"name\": \"jquery\",\n        \"full_name\": \"jquery/jquery\",\n        \"owner\": {\n          \"login\": \"jquery\",\n          \"id\": 70142,\n          \"node_id\": \"MDQ6VXNlcjcwMTQy\",\n          \"avatar_url\": \"https://0.gravatar.com/avatar/6906f317a4733f4379b06c32229ef02f?d=https%3A%2F%2Fidenticons.github.com%2Ff426f04f2f9813718fb806b30e0093de.png\",\n          \"gravatar_id\": \"\",\n          \"url\": \"https://api.github.com/users/jquery\",\n          \"html_url\": \"https://github.com/jquery\",\n          \"followers_url\": \"https://api.github.com/users/jquery/followers\",\n          \"following_url\": \"https://api.github.com/users/jquery/following{/other_user}\",\n          \"gists_url\": \"https://api.github.com/users/jquery/gists{/gist_id}\",\n          \"starred_url\": \"https://api.github.com/users/jquery/starred{/owner}{/repo}\",\n          \"subscriptions_url\": \"https://api.github.com/users/jquery/subscriptions\",\n          \"organizations_url\": \"https://api.github.com/users/jquery/orgs\",\n          \"repos_url\": \"https://api.github.com/users/jquery/repos\",\n          \"events_url\": \"https://api.github.com/users/jquery/events{/privacy}\",\n          \"received_events_url\": \"https://api.github.com/users/jquery/received_events\",\n          \"type\": \"Organization\",\n          \"site_admin\": false\n        },\n        \"private\": false,\n        \"html_url\": \"https://github.com/jquery/jquery\",\n        \"description\": \"jQuery JavaScript Library\",\n        \"fork\": false,\n        \"url\": \"https://api.github.com/repos/jquery/jquery\",\n        \"forks_url\": \"https://api.github.com/repos/jquery/jquery/forks\",\n        \"keys_url\": \"https://api.github.com/repos/jquery/jquery/keys{/key_id}\",\n        \"collaborators_url\": \"https://api.github.com/repos/jquery/jquery/collaborators{/collaborator}\",\n        \"teams_url\": \"https://api.github.com/repos/jquery/jquery/teams\",\n        \"hooks_url\": \"https://api.github.com/repos/jquery/jquery/hooks\",\n        \"issue_events_url\": \"https://api.github.com/repos/jquery/jquery/issues/events{/number}\",\n        \"events_url\": \"https://api.github.com/repos/jquery/jquery/events\",\n        \"assignees_url\": \"https://api.github.com/repos/jquery/jquery/assignees{/user}\",\n        \"branches_url\": \"https://api.github.com/repos/jquery/jquery/branches{/branch}\",\n        \"tags_url\": \"https://api.github.com/repos/jquery/jquery/tags\",\n        \"blobs_url\": \"https://api.github.com/repos/jquery/jquery/git/blobs{/sha}\",\n        \"git_tags_url\": \"https://api.github.com/repos/jquery/jquery/git/tags{/sha}\",\n        \"git_refs_url\": \"https://api.github.com/repos/jquery/jquery/git/refs{/sha}\",\n        \"trees_url\": \"https://api.github.com/repos/jquery/jquery/git/trees{/sha}\",\n        \"statuses_url\": \"https://api.github.com/repos/jquery/jquery/statuses/{sha}\",\n        \"languages_url\": \"https://api.github.com/repos/jquery/jquery/languages\",\n        \"stargazers_url\": \"https://api.github.com/repos/jquery/jquery/stargazers\",\n        \"contributors_url\": \"https://api.github.com/repos/jquery/jquery/contributors\",\n        \"subscribers_url\": \"https://api.github.com/repos/jquery/jquery/subscribers\",\n        \"subscription_url\": \"https://api.github.com/repos/jquery/jquery/subscription\",\n        \"commits_url\": \"https://api.github.com/repos/jquery/jquery/commits{/sha}\",\n        \"git_commits_url\": \"https://api.github.com/repos/jquery/jquery/git/commits{/sha}\",\n        \"comments_url\": \"https://api.github.com/repos/jquery/jquery/comments{/number}\",\n        \"issue_comment_url\": \"https://api.github.com/repos/jquery/jquery/issues/comments/{number}\",\n        \"contents_url\": \"https://api.github.com/repos/jquery/jquery/contents/{+path}\",\n        \"compare_url\": \"https://api.github.com/repos/jquery/jquery/compare/{base}...{head}\",\n        \"merges_url\": \"https://api.github.com/repos/jquery/jquery/merges\",\n        \"archive_url\": \"https://api.github.com/repos/jquery/jquery/{archive_format}{/ref}\",\n        \"downloads_url\": \"https://api.github.com/repos/jquery/jquery/downloads\",\n        \"issues_url\": \"https://api.github.com/repos/jquery/jquery/issues{/number}\",\n        \"pulls_url\": \"https://api.github.com/repos/jquery/jquery/pulls{/number}\",\n        \"milestones_url\": \"https://api.github.com/repos/jquery/jquery/milestones{/number}\",\n        \"notifications_url\": \"https://api.github.com/repos/jquery/jquery/notifications{?since,all,participating}\",\n        \"labels_url\": \"https://api.github.com/repos/jquery/jquery/labels{/name}\",\n        \"deployments_url\": \"http://api.github.com/repos/octocat/Hello-World/deployments\",\n        \"releases_url\": \"http://api.github.com/repos/octocat/Hello-World/releases{/id}\"\n      },\n      \"score\": 1\n    }\n  ]\n}</code></pre></div>\n<h4>Not modified</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 304 Not Modified</code></pre></div>\n<h4>Forbidden</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 403 Forbidden</code></pre></div>\n<h4>Validation failed</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 422 Unprocessable Entity</code></pre></div>\n<h4>Service unavailable</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 503 Service Unavailable</code></pre></div>\n<h4>Notes</h4>\n<ul>\n<li><a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/developers/apps\">Works with GitHub Apps</a></li>\n</ul>\n<hr>\n<h3><a href=\"#search-commits\">Search commits</a></h3>\n<p>Find commits via various criteria on the default branch (usually <code class=\"language-text\">master</code>). This method returns up to 100 results <a href=\"https://docs.github.com/rest/overview/resources-in-the-rest-api#pagination\">per page</a>.</p>\n<p>When searching for commits, you can get text match metadata for the <strong>message</strong> field when you provide the <code class=\"language-text\">text-match</code> media type. For more details about how to receive highlighted search results, see <a href=\"https://docs.github.com/rest/reference/search#text-match-metadata\">Text match metadata</a>.</p>\n<p>For example, if you want to find commits related to CSS in the <a href=\"https://github.com/octocat/Spoon-Knife\">octocat/Spoon-Knife</a> repository. Your query would look something like this:</p>\n<p><code class=\"language-text\">q=repo:octocat/Spoon-Knife+css</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">get /search/commits</code></pre></div>\n<h4><a href=\"#search-commits--parameters\">Parameters</a></h4>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Type</th>\n<th>In</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">accept</code></td>\n<td>string</td>\n<td>header</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>This API is under preview and subject to change.<a href=\"#search-commits-preview-notices\">See preview notice</a></p>\n<p>|\n| <code class=\"language-text\">q</code> | string | query |</p>\n<p>The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see <a href=\"https://docs.github.com/rest/reference/search#constructing-a-search-query\">Constructing a search query</a>. See \"<a href=\"https://help.github.com/articles/searching-commits/\">Searching commits</a>\" for a detailed list of qualifiers.</p>\n<p>|\n| <code class=\"language-text\">sort</code> | string | query |</p>\n<p>Sorts the results of your query by <code class=\"language-text\">author-date</code> or <code class=\"language-text\">committer-date</code>. Default: <a href=\"https://docs.github.com/rest/reference/search#ranking-search-results\">best match</a></p>\n<p>|\n| <code class=\"language-text\">order</code> | string | query |</p>\n<p>Determines whether the first search result returned is the highest number of matches (<code class=\"language-text\">desc</code>) or lowest number of matches (<code class=\"language-text\">asc</code>). This parameter is ignored unless you provide <code class=\"language-text\">sort</code>.</p>\n<p>Default: <code class=\"language-text\">desc</code> |\n| <code class=\"language-text\">per_page</code> | integer | query |</p>\n<p>Results per page (max 100)</p>\n<p>Default: <code class=\"language-text\">30</code> |\n| <code class=\"language-text\">page</code> | integer | query |</p>\n<p>Page number of the results to fetch.</p>\n<p>Default: <code class=\"language-text\">1</code> |</p>\n<h4><a href=\"#search-commits--code-samples\">Code samples</a></h4>\n<h5>Shell</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl \\\n  -H \"Accept: application/vnd.github.cloak-preview+json\" \\\n  https://api.github.com/search/commits</code></pre></div>\n<h5>JavaScript (<a href=\"https://github.com/octokit/core.js#readme\">@octokit/core.js</a>)</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">await octokit.request('GET /search/commits', {\n  q: 'q',\n  mediaType: {\n    previews: [\n      'cloak'\n    ]\n  }\n})</code></pre></div>\n<h4>Response</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 200 OK\n\n{\n  \"total_count\": 1,\n  \"incomplete_results\": false,\n  \"items\": [\n    {\n      \"url\": \"https://api.github.com/repos/octocat/Spoon-Knife/commits/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f\",\n      \"sha\": \"bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f\",\n      \"html_url\": \"https://github.com/octocat/Spoon-Knife/commit/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f\",\n      \"comments_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/commits/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f/comments\",\n      \"commit\": {\n        \"url\": \"https://api.github.com/repos/octocat/Spoon-Knife/git/commits/bb4cc8d3b2e14b3af5df699876dd4ff3acd00b7f\",\n        \"author\": {\n          \"date\": \"2014-02-04T14:38:36-08:00\",\n          \"name\": \"The Octocat\",\n          \"email\": \"octocat@nowhere.com\"\n        },\n        \"committer\": {\n          \"date\": \"2014-02-12T15:18:55-08:00\",\n          \"name\": \"The Octocat\",\n          \"email\": \"octocat@nowhere.com\"\n        },\n        \"message\": \"Create styles.css and updated README\",\n        \"tree\": {\n          \"url\": \"https://api.github.com/repos/octocat/Spoon-Knife/git/trees/a639e96f9038797fba6e0469f94a4b0cc459fa68\",\n          \"sha\": \"a639e96f9038797fba6e0469f94a4b0cc459fa68\"\n        },\n        \"comment_count\": 8\n      },\n      \"author\": {\n        \"login\": \"octocat\",\n        \"id\": 583231,\n        \"node_id\": \"MDQ6VXNlcjU4MzIzMQ==\",\n        \"avatar_url\": \"https://avatars.githubusercontent.com/u/583231?v=3\",\n        \"gravatar_id\": \"\",\n        \"url\": \"https://api.github.com/users/octocat\",\n        \"html_url\": \"https://github.com/octocat\",\n        \"followers_url\": \"https://api.github.com/users/octocat/followers\",\n        \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n        \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n        \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n        \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n        \"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n        \"repos_url\": \"https://api.github.com/users/octocat/repos\",\n        \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n        \"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n        \"type\": \"User\",\n        \"site_admin\": false\n      },\n      \"committer\": {},\n      \"parents\": [\n        {\n          \"url\": \"https://api.github.com/repos/octocat/Spoon-Knife/commits/a30c19e3f13765a3b48829788bc1cb8b4e95cee4\",\n          \"html_url\": \"https://github.com/octocat/Spoon-Knife/commit/a30c19e3f13765a3b48829788bc1cb8b4e95cee4\",\n          \"sha\": \"a30c19e3f13765a3b48829788bc1cb8b4e95cee4\"\n        }\n      ],\n      \"repository\": {\n        \"id\": 1300192,\n        \"node_id\": \"MDEwOlJlcG9zaXRvcnkxMzAwMTky\",\n        \"name\": \"Spoon-Knife\",\n        \"full_name\": \"octocat/Spoon-Knife\",\n        \"owner\": {\n          \"login\": \"octocat\",\n          \"id\": 583231,\n          \"node_id\": \"MDQ6VXNlcjU4MzIzMQ==\",\n          \"avatar_url\": \"https://avatars.githubusercontent.com/u/583231?v=3\",\n          \"gravatar_id\": \"\",\n          \"url\": \"https://api.github.com/users/octocat\",\n          \"html_url\": \"https://github.com/octocat\",\n          \"followers_url\": \"https://api.github.com/users/octocat/followers\",\n          \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n          \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n          \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n          \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n          \"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n          \"repos_url\": \"https://api.github.com/users/octocat/repos\",\n          \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n          \"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n          \"type\": \"User\",\n          \"site_admin\": false\n        },\n        \"private\": false,\n        \"html_url\": \"https://github.com/octocat/Spoon-Knife\",\n        \"description\": \"This repo is for demonstration purposes only.\",\n        \"fork\": false,\n        \"url\": \"https://api.github.com/repos/octocat/Spoon-Knife\",\n        \"forks_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/forks\",\n        \"keys_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/keys{/key_id}\",\n        \"collaborators_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/collaborators{/collaborator}\",\n        \"teams_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/teams\",\n        \"hooks_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/hooks\",\n        \"issue_events_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/issues/events{/number}\",\n        \"events_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/events\",\n        \"assignees_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/assignees{/user}\",\n        \"branches_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/branches{/branch}\",\n        \"tags_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/tags\",\n        \"blobs_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/git/blobs{/sha}\",\n        \"git_tags_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/git/tags{/sha}\",\n        \"git_refs_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/git/refs{/sha}\",\n        \"trees_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/git/trees{/sha}\",\n        \"statuses_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/statuses/{sha}\",\n        \"languages_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/languages\",\n        \"stargazers_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/stargazers\",\n        \"contributors_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/contributors\",\n        \"subscribers_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/subscribers\",\n        \"subscription_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/subscription\",\n        \"commits_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/commits{/sha}\",\n        \"git_commits_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/git/commits{/sha}\",\n        \"comments_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/comments{/number}\",\n        \"issue_comment_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/issues/comments{/number}\",\n        \"contents_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/contents/{+path}\",\n        \"compare_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/compare/{base}...{head}\",\n        \"merges_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/merges\",\n        \"archive_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/{archive_format}{/ref}\",\n        \"downloads_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/downloads\",\n        \"issues_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/issues{/number}\",\n        \"pulls_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/pulls{/number}\",\n        \"milestones_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/milestones{/number}\",\n        \"notifications_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/notifications{?since,all,participating}\",\n        \"labels_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/labels{/name}\",\n        \"releases_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/releases{/id}\",\n        \"deployments_url\": \"https://api.github.com/repos/octocat/Spoon-Knife/deployments\"\n      },\n      \"score\": 1,\n      \"node_id\": \"MDQ6VXNlcjU4MzIzMQ==\"\n    }\n  ]\n}</code></pre></div>\n<h4>Not modified</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 304 Not Modified</code></pre></div>\n<h4>Preview header missing</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 415 Unsupported Media Type</code></pre></div>\n<h4>Notes</h4>\n<ul>\n<li><a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/developers/apps\">Works with GitHub Apps</a></li>\n</ul>\n<h4>Preview notice</h4>\n<p>The Commit Search API is currently available for developers to preview. During the preview period, the APIs may change without advance notice. Please see the <a href=\"https://developer.github.com/changes/2017-01-05-commit-search-api/\">blog post</a> for full details.</p>\n<p>To access the API you must provide a custom <a href=\"https://docs.github.com/rest/overview/media-types\">media type</a> in the <code class=\"language-text\">Accept</code> header:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">application/vnd.github.cloak-preview</code></pre></div>\n<p>☝️This header is <strong>required</strong>.</p>\n<hr>\n<h3><a href=\"#search-issues-and-pull-requests\">Search issues and pull requests</a></h3>\n<p>Find issues by state and keyword. This method returns up to 100 results <a href=\"https://docs.github.com/rest/overview/resources-in-the-rest-api#pagination\">per page</a>.</p>\n<p>When searching for issues, you can get text match metadata for the issue <strong>title</strong>, issue <strong>body</strong>, and issue <strong>comment body</strong> fields when you pass the <code class=\"language-text\">text-match</code> media type. For more details about how to receive highlighted search results, see <a href=\"https://docs.github.com/rest/reference/search#text-match-metadata\">Text match metadata</a>.</p>\n<p>For example, if you want to find the oldest unresolved Python bugs on Windows. Your query might look something like this.</p>\n<p><code class=\"language-text\">q=windows+label:bug+language:python+state:open&amp;sort=created&amp;order=asc</code></p>\n<p>This query searches for the keyword <code class=\"language-text\">windows</code>, within any open issue that is labeled as <code class=\"language-text\">bug</code>. The search runs across repositories whose primary language is Python. The results are sorted by creation date in ascending order, which means the oldest issues appear first in the search results.</p>\n<p><strong>Note:</strong> For <a href=\"https://docs.github.com/developers/apps/identifying-and-authorizing-users-for-github-apps#user-to-server-requests\">user-to-server</a> GitHub App requests, you can't retrieve a combination of issues and pull requests in a single query. Requests that don't include the <code class=\"language-text\">is:issue</code> or <code class=\"language-text\">is:pull-request</code> qualifier will receive an HTTP <code class=\"language-text\">422 Unprocessable Entity</code> response. To get results for both issues and pull requests, you must send separate queries for issues and pull requests. For more information about the <code class=\"language-text\">is</code> qualifier, see \"<a href=\"https://docs.github.com/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-only-issues-or-pull-requests\">Searching only issues or pull requests</a>.\"</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">get /search/issues</code></pre></div>\n<h4><a href=\"#search-issues-and-pull-requests--parameters\">Parameters</a></h4>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Type</th>\n<th>In</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">accept</code></td>\n<td>string</td>\n<td>header</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>Setting to <code class=\"language-text\">application/vnd.github.v3+json</code> is recommended.</p>\n<p>|\n| <code class=\"language-text\">q</code> | string | query |</p>\n<p>The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see <a href=\"https://docs.github.com/rest/reference/search#constructing-a-search-query\">Constructing a search query</a>. See \"<a href=\"https://help.github.com/articles/searching-issues-and-pull-requests/\">Searching issues and pull requests</a>\" for a detailed list of qualifiers.</p>\n<p>|\n| <code class=\"language-text\">sort</code> | string | query |</p>\n<p>Sorts the results of your query by the number of <code class=\"language-text\">comments</code>, <code class=\"language-text\">reactions</code>, <code class=\"language-text\">reactions-+1</code>, <code class=\"language-text\">reactions--1</code>, <code class=\"language-text\">reactions-smile</code>, <code class=\"language-text\">reactions-thinking_face</code>, <code class=\"language-text\">reactions-heart</code>, <code class=\"language-text\">reactions-tada</code>, or <code class=\"language-text\">interactions</code>. You can also sort results by how recently the items were <code class=\"language-text\">created</code> or <code class=\"language-text\">updated</code>, Default: <a href=\"https://docs.github.com/rest/reference/search#ranking-search-results\">best match</a></p>\n<p>|\n| <code class=\"language-text\">order</code> | string | query |</p>\n<p>Determines whether the first search result returned is the highest number of matches (<code class=\"language-text\">desc</code>) or lowest number of matches (<code class=\"language-text\">asc</code>). This parameter is ignored unless you provide <code class=\"language-text\">sort</code>.</p>\n<p>Default: <code class=\"language-text\">desc</code> |\n| <code class=\"language-text\">per_page</code> | integer | query |</p>\n<p>Results per page (max 100)</p>\n<p>Default: <code class=\"language-text\">30</code> |\n| <code class=\"language-text\">page</code> | integer | query |</p>\n<p>Page number of the results to fetch.</p>\n<p>Default: <code class=\"language-text\">1</code> |</p>\n<h4><a href=\"#search-issues-and-pull-requests--code-samples\">Code samples</a></h4>\n<h5>Shell</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl \\\n  -H \"Accept: application/vnd.github.v3+json\" \\\n  https://api.github.com/search/issues</code></pre></div>\n<h5>JavaScript (<a href=\"https://github.com/octokit/core.js#readme\">@octokit/core.js</a>)</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">await octokit.request('GET /search/issues', {\n  q: 'q'\n})</code></pre></div>\n<h4>Response</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 200 OK\n\n{\n  \"total_count\": 280,\n  \"incomplete_results\": false,\n  \"items\": [\n    {\n      \"url\": \"https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132\",\n      \"repository_url\": \"https://api.github.com/repos/batterseapower/pinyin-toolkit\",\n      \"labels_url\": \"https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/labels{/name}\",\n      \"comments_url\": \"https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/comments\",\n      \"events_url\": \"https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/events\",\n      \"html_url\": \"https://github.com/batterseapower/pinyin-toolkit/issues/132\",\n      \"id\": 35802,\n      \"node_id\": \"MDU6SXNzdWUzNTgwMg==\",\n      \"number\": 132,\n      \"title\": \"Line Number Indexes Beyond 20 Not Displayed\",\n      \"user\": {\n        \"login\": \"Nick3C\",\n        \"id\": 90254,\n        \"node_id\": \"MDQ6VXNlcjkwMjU0\",\n        \"avatar_url\": \"https://secure.gravatar.com/avatar/934442aadfe3b2f4630510de416c5718?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png\",\n        \"gravatar_id\": \"\",\n        \"url\": \"https://api.github.com/users/Nick3C\",\n        \"html_url\": \"https://github.com/Nick3C\",\n        \"followers_url\": \"https://api.github.com/users/Nick3C/followers\",\n        \"following_url\": \"https://api.github.com/users/Nick3C/following{/other_user}\",\n        \"gists_url\": \"https://api.github.com/users/Nick3C/gists{/gist_id}\",\n        \"starred_url\": \"https://api.github.com/users/Nick3C/starred{/owner}{/repo}\",\n        \"subscriptions_url\": \"https://api.github.com/users/Nick3C/subscriptions\",\n        \"organizations_url\": \"https://api.github.com/users/Nick3C/orgs\",\n        \"repos_url\": \"https://api.github.com/users/Nick3C/repos\",\n        \"events_url\": \"https://api.github.com/users/Nick3C/events{/privacy}\",\n        \"received_events_url\": \"https://api.github.com/users/Nick3C/received_events\",\n        \"type\": \"User\",\n        \"site_admin\": true\n      },\n      \"labels\": [\n        {\n          \"id\": 4,\n          \"node_id\": \"MDU6TGFiZWw0\",\n          \"url\": \"https://api.github.com/repos/batterseapower/pinyin-toolkit/labels/bug\",\n          \"name\": \"bug\",\n          \"color\": \"ff0000\"\n        }\n      ],\n      \"state\": \"open\",\n      \"assignee\": null,\n      \"milestone\": {\n        \"url\": \"https://api.github.com/repos/octocat/Hello-World/milestones/1\",\n        \"html_url\": \"https://github.com/octocat/Hello-World/milestones/v1.0\",\n        \"labels_url\": \"https://api.github.com/repos/octocat/Hello-World/milestones/1/labels\",\n        \"id\": 1002604,\n        \"node_id\": \"MDk6TWlsZXN0b25lMTAwMjYwNA==\",\n        \"number\": 1,\n        \"state\": \"open\",\n        \"title\": \"v1.0\",\n        \"description\": \"Tracking milestone for version 1.0\",\n        \"creator\": {\n          \"login\": \"octocat\",\n          \"id\": 1,\n          \"node_id\": \"MDQ6VXNlcjE=\",\n          \"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n          \"gravatar_id\": \"\",\n          \"url\": \"https://api.github.com/users/octocat\",\n          \"html_url\": \"https://github.com/octocat\",\n          \"followers_url\": \"https://api.github.com/users/octocat/followers\",\n          \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n          \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n          \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n          \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n          \"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n          \"repos_url\": \"https://api.github.com/users/octocat/repos\",\n          \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n          \"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n          \"type\": \"User\",\n          \"site_admin\": false\n        },\n        \"open_issues\": 4,\n        \"closed_issues\": 8,\n        \"created_at\": \"2011-04-10T20:09:31Z\",\n        \"updated_at\": \"2014-03-03T18:58:10Z\",\n        \"closed_at\": \"2013-02-12T13:22:01Z\",\n        \"due_on\": \"2012-10-09T23:39:01Z\"\n      },\n      \"comments\": 15,\n      \"created_at\": \"2009-07-12T20:10:41Z\",\n      \"updated_at\": \"2009-07-19T09:23:43Z\",\n      \"closed_at\": null,\n      \"pull_request\": {\n        \"url\": \"https://api/github.com/repos/octocat/Hello-World/pull/1347\",\n        \"html_url\": \"https://github.com/octocat/Hello-World/pull/1347\",\n        \"diff_url\": \"https://github.com/octocat/Hello-World/pull/1347.diff\",\n        \"patch_url\": \"https://api.github.com/repos/octocat/Hello-World/pulls/1347\"\n      },\n      \"body\": \"...\",\n      \"score\": 1,\n      \"locked\": true,\n      \"author_association\": \"COLLABORATOR\"\n    }\n  ]\n}</code></pre></div>\n<h4>Not modified</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 304 Not Modified</code></pre></div>\n<h4>Forbidden</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 403 Forbidden</code></pre></div>\n<h4>Validation failed</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 422 Unprocessable Entity</code></pre></div>\n<h4>Service unavailable</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 503 Service Unavailable</code></pre></div>\n<h4>Notes</h4>\n<ul>\n<li><a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/developers/apps\">Works with GitHub Apps</a></li>\n</ul>\n<hr>\n<h3><a href=\"#search-labels\">Search labels</a></h3>\n<p>Find labels in a repository with names or descriptions that match search keywords. Returns up to 100 results <a href=\"https://docs.github.com/rest/overview/resources-in-the-rest-api#pagination\">per page</a>.</p>\n<p>When searching for labels, you can get text match metadata for the label <strong>name</strong> and <strong>description</strong> fields when you pass the <code class=\"language-text\">text-match</code> media type. For more details about how to receive highlighted search results, see <a href=\"https://docs.github.com/rest/reference/search#text-match-metadata\">Text match metadata</a>.</p>\n<p>For example, if you want to find labels in the <code class=\"language-text\">linguist</code> repository that match <code class=\"language-text\">bug</code>, <code class=\"language-text\">defect</code>, or <code class=\"language-text\">enhancement</code>. Your query might look like this:</p>\n<p><code class=\"language-text\">q=bug+defect+enhancement&amp;repository_id=64778136</code></p>\n<p>The labels that best match the query appear first in the search results.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">get /search/labels</code></pre></div>\n<h4><a href=\"#search-labels--parameters\">Parameters</a></h4>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Type</th>\n<th>In</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">accept</code></td>\n<td>string</td>\n<td>header</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>Setting to <code class=\"language-text\">application/vnd.github.v3+json</code> is recommended.</p>\n<p>|\n| <code class=\"language-text\">repository_id</code> | integer | query |</p>\n<p>The id of the repository.</p>\n<p>|\n| <code class=\"language-text\">q</code> | string | query |</p>\n<p>The search keywords. This endpoint does not accept qualifiers in the query. To learn more about the format of the query, see <a href=\"https://docs.github.com/rest/reference/search#constructing-a-search-query\">Constructing a search query</a>.</p>\n<p>|\n| <code class=\"language-text\">sort</code> | string | query |</p>\n<p>Sorts the results of your query by when the label was <code class=\"language-text\">created</code> or <code class=\"language-text\">updated</code>. Default: <a href=\"https://docs.github.com/rest/reference/search#ranking-search-results\">best match</a></p>\n<p>|\n| <code class=\"language-text\">order</code> | string | query |</p>\n<p>Determines whether the first search result returned is the highest number of matches (<code class=\"language-text\">desc</code>) or lowest number of matches (<code class=\"language-text\">asc</code>). This parameter is ignored unless you provide <code class=\"language-text\">sort</code>.</p>\n<p>Default: <code class=\"language-text\">desc</code> |\n| <code class=\"language-text\">per_page</code> | integer | query |</p>\n<p>Results per page (max 100)</p>\n<p>Default: <code class=\"language-text\">30</code> |\n| <code class=\"language-text\">page</code> | integer | query |</p>\n<p>Page number of the results to fetch.</p>\n<p>Default: <code class=\"language-text\">1</code> |</p>\n<h4><a href=\"#search-labels--code-samples\">Code samples</a></h4>\n<h5>Shell</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl \\\n  -H \"Accept: application/vnd.github.v3+json\" \\\n  https://api.github.com/search/labels</code></pre></div>\n<h5>JavaScript (<a href=\"https://github.com/octokit/core.js#readme\">@octokit/core.js</a>)</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">await octokit.request('GET /search/labels', {\n  repository_id: 42,\n  q: 'q'\n})</code></pre></div>\n<h4>Response</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 200 OK\n\n{\n  \"total_count\": 2,\n  \"incomplete_results\": false,\n  \"items\": [\n    {\n      \"id\": 418327088,\n      \"node_id\": \"MDU6TGFiZWw0MTgzMjcwODg=\",\n      \"url\": \"https://api.github.com/repos/octocat/linguist/labels/enhancement\",\n      \"name\": \"enhancement\",\n      \"color\": \"84b6eb\",\n      \"default\": true,\n      \"description\": \"New feature or request.\",\n      \"score\": 1\n    },\n    {\n      \"id\": 418327086,\n      \"node_id\": \"MDU6TGFiZWw0MTgzMjcwODY=\",\n      \"url\": \"https://api.github.com/repos/octocat/linguist/labels/bug\",\n      \"name\": \"bug\",\n      \"color\": \"ee0701\",\n      \"default\": true,\n      \"description\": \"Something isn't working.\",\n      \"score\": 1\n    }\n  ]\n}</code></pre></div>\n<h4>Not modified</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 304 Not Modified</code></pre></div>\n<h4>Forbidden</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 403 Forbidden</code></pre></div>\n<h4>Resource not found</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 404 Not Found</code></pre></div>\n<h4>Validation failed</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 422 Unprocessable Entity</code></pre></div>\n<h4>Notes</h4>\n<ul>\n<li><a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/developers/apps\">Works with GitHub Apps</a></li>\n</ul>\n<hr>\n<h3><a href=\"#search-repositories\">Search repositories</a></h3>\n<p>Find repositories via various criteria. This method returns up to 100 results <a href=\"https://docs.github.com/rest/overview/resources-in-the-rest-api#pagination\">per page</a>.</p>\n<p>When searching for repositories, you can get text match metadata for the <strong>name</strong> and <strong>description</strong> fields when you pass the <code class=\"language-text\">text-match</code> media type. For more details about how to receive highlighted search results, see <a href=\"https://docs.github.com/rest/reference/search#text-match-metadata\">Text match metadata</a>.</p>\n<p>For example, if you want to search for popular Tetris repositories written in assembly code, your query might look like this:</p>\n<p><code class=\"language-text\">q=tetris+language:assembly&amp;sort=stars&amp;order=desc</code></p>\n<p>This query searches for repositories with the word <code class=\"language-text\">tetris</code> in the name, the description, or the README. The results are limited to repositories where the primary language is assembly. The results are sorted by stars in descending order, so that the most popular repositories appear first in the search results.</p>\n<p>When you include the <code class=\"language-text\">mercy</code> preview header, you can also search for multiple topics by adding more <code class=\"language-text\">topic:</code> instances. For example, your query might look like this:</p>\n<p><code class=\"language-text\">q=topic:ruby+topic:rails</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">get /search/repositories</code></pre></div>\n<h4><a href=\"#search-repositories--parameters\">Parameters</a></h4>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Type</th>\n<th>In</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">accept</code></td>\n<td>string</td>\n<td>header</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>Setting to <code class=\"language-text\">application/vnd.github.v3+json</code> is recommended.<a href=\"#search-repositories-preview-notices\">See preview notice</a></p>\n<p>|\n| <code class=\"language-text\">q</code> | string | query |</p>\n<p>The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see <a href=\"https://docs.github.com/rest/reference/search#constructing-a-search-query\">Constructing a search query</a>. See \"<a href=\"https://help.github.com/articles/searching-for-repositories/\">Searching for repositories</a>\" for a detailed list of qualifiers.</p>\n<p>|\n| <code class=\"language-text\">sort</code> | string | query |</p>\n<p>Sorts the results of your query by number of <code class=\"language-text\">stars</code>, <code class=\"language-text\">forks</code>, or <code class=\"language-text\">help-wanted-issues</code> or how recently the items were <code class=\"language-text\">updated</code>. Default: <a href=\"https://docs.github.com/rest/reference/search#ranking-search-results\">best match</a></p>\n<p>|\n| <code class=\"language-text\">order</code> | string | query |</p>\n<p>Determines whether the first search result returned is the highest number of matches (<code class=\"language-text\">desc</code>) or lowest number of matches (<code class=\"language-text\">asc</code>). This parameter is ignored unless you provide <code class=\"language-text\">sort</code>.</p>\n<p>Default: <code class=\"language-text\">desc</code> |\n| <code class=\"language-text\">per_page</code> | integer | query |</p>\n<p>Results per page (max 100)</p>\n<p>Default: <code class=\"language-text\">30</code> |\n| <code class=\"language-text\">page</code> | integer | query |</p>\n<p>Page number of the results to fetch.</p>\n<p>Default: <code class=\"language-text\">1</code> |</p>\n<h4><a href=\"#search-repositories--code-samples\">Code samples</a></h4>\n<h5>Shell</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl \\\n  -H \"Accept: application/vnd.github.v3+json\" \\\n  https://api.github.com/search/repositories</code></pre></div>\n<h5>JavaScript (<a href=\"https://github.com/octokit/core.js#readme\">@octokit/core.js</a>)</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">await octokit.request('GET /search/repositories', {\n  q: 'q'\n})</code></pre></div>\n<h4>Response</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 200 OK\n\n{\n  \"total_count\": 40,\n  \"incomplete_results\": false,\n  \"items\": [\n    {\n      \"id\": 3081286,\n      \"node_id\": \"MDEwOlJlcG9zaXRvcnkzMDgxMjg2\",\n      \"name\": \"Tetris\",\n      \"full_name\": \"dtrupenn/Tetris\",\n      \"owner\": {\n        \"login\": \"dtrupenn\",\n        \"id\": 872147,\n        \"node_id\": \"MDQ6VXNlcjg3MjE0Nw==\",\n        \"avatar_url\": \"https://secure.gravatar.com/avatar/e7956084e75f239de85d3a31bc172ace?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png\",\n        \"gravatar_id\": \"\",\n        \"url\": \"https://api.github.com/users/dtrupenn\",\n        \"received_events_url\": \"https://api.github.com/users/dtrupenn/received_events\",\n        \"type\": \"User\",\n        \"html_url\": \"https://github.com/octocat\",\n        \"followers_url\": \"https://api.github.com/users/octocat/followers\",\n        \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n        \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n        \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n        \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n        \"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n        \"repos_url\": \"https://api.github.com/users/octocat/repos\",\n        \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n        \"site_admin\": true\n      },\n      \"private\": false,\n      \"html_url\": \"https://github.com/dtrupenn/Tetris\",\n      \"description\": \"A C implementation of Tetris using Pennsim through LC4\",\n      \"fork\": false,\n      \"url\": \"https://api.github.com/repos/dtrupenn/Tetris\",\n      \"created_at\": \"2012-01-01T00:31:50Z\",\n      \"updated_at\": \"2013-01-05T17:58:47Z\",\n      \"pushed_at\": \"2012-01-01T00:37:02Z\",\n      \"homepage\": \"https://github.com\",\n      \"size\": 524,\n      \"stargazers_count\": 1,\n      \"watchers_count\": 1,\n      \"language\": \"Assembly\",\n      \"forks_count\": 0,\n      \"open_issues_count\": 0,\n      \"master_branch\": \"master\",\n      \"default_branch\": \"master\",\n      \"score\": 1,\n      \"archive_url\": \"https://api.github.com/repos/dtrupenn/Tetris/{archive_format}{/ref}\",\n      \"assignees_url\": \"https://api.github.com/repos/dtrupenn/Tetris/assignees{/user}\",\n      \"blobs_url\": \"https://api.github.com/repos/dtrupenn/Tetris/git/blobs{/sha}\",\n      \"branches_url\": \"https://api.github.com/repos/dtrupenn/Tetris/branches{/branch}\",\n      \"collaborators_url\": \"https://api.github.com/repos/dtrupenn/Tetris/collaborators{/collaborator}\",\n      \"comments_url\": \"https://api.github.com/repos/dtrupenn/Tetris/comments{/number}\",\n      \"commits_url\": \"https://api.github.com/repos/dtrupenn/Tetris/commits{/sha}\",\n      \"compare_url\": \"https://api.github.com/repos/dtrupenn/Tetris/compare/{base}...{head}\",\n      \"contents_url\": \"https://api.github.com/repos/dtrupenn/Tetris/contents/{+path}\",\n      \"contributors_url\": \"https://api.github.com/repos/dtrupenn/Tetris/contributors\",\n      \"deployments_url\": \"https://api.github.com/repos/dtrupenn/Tetris/deployments\",\n      \"downloads_url\": \"https://api.github.com/repos/dtrupenn/Tetris/downloads\",\n      \"events_url\": \"https://api.github.com/repos/dtrupenn/Tetris/events\",\n      \"forks_url\": \"https://api.github.com/repos/dtrupenn/Tetris/forks\",\n      \"git_commits_url\": \"https://api.github.com/repos/dtrupenn/Tetris/git/commits{/sha}\",\n      \"git_refs_url\": \"https://api.github.com/repos/dtrupenn/Tetris/git/refs{/sha}\",\n      \"git_tags_url\": \"https://api.github.com/repos/dtrupenn/Tetris/git/tags{/sha}\",\n      \"git_url\": \"git:github.com/dtrupenn/Tetris.git\",\n      \"issue_comment_url\": \"https://api.github.com/repos/dtrupenn/Tetris/issues/comments{/number}\",\n      \"issue_events_url\": \"https://api.github.com/repos/dtrupenn/Tetris/issues/events{/number}\",\n      \"issues_url\": \"https://api.github.com/repos/dtrupenn/Tetris/issues{/number}\",\n      \"keys_url\": \"https://api.github.com/repos/dtrupenn/Tetris/keys{/key_id}\",\n      \"labels_url\": \"https://api.github.com/repos/dtrupenn/Tetris/labels{/name}\",\n      \"languages_url\": \"https://api.github.com/repos/dtrupenn/Tetris/languages\",\n      \"merges_url\": \"https://api.github.com/repos/dtrupenn/Tetris/merges\",\n      \"milestones_url\": \"https://api.github.com/repos/dtrupenn/Tetris/milestones{/number}\",\n      \"notifications_url\": \"https://api.github.com/repos/dtrupenn/Tetris/notifications{?since,all,participating}\",\n      \"pulls_url\": \"https://api.github.com/repos/dtrupenn/Tetris/pulls{/number}\",\n      \"releases_url\": \"https://api.github.com/repos/dtrupenn/Tetris/releases{/id}\",\n      \"ssh_url\": \"git@github.com:dtrupenn/Tetris.git\",\n      \"stargazers_url\": \"https://api.github.com/repos/dtrupenn/Tetris/stargazers\",\n      \"statuses_url\": \"https://api.github.com/repos/dtrupenn/Tetris/statuses/{sha}\",\n      \"subscribers_url\": \"https://api.github.com/repos/dtrupenn/Tetris/subscribers\",\n      \"subscription_url\": \"https://api.github.com/repos/dtrupenn/Tetris/subscription\",\n      \"tags_url\": \"https://api.github.com/repos/dtrupenn/Tetris/tags\",\n      \"teams_url\": \"https://api.github.com/repos/dtrupenn/Tetris/teams\",\n      \"trees_url\": \"https://api.github.com/repos/dtrupenn/Tetris/git/trees{/sha}\",\n      \"clone_url\": \"https://github.com/dtrupenn/Tetris.git\",\n      \"mirror_url\": \"git:git.example.com/dtrupenn/Tetris\",\n      \"hooks_url\": \"https://api.github.com/repos/dtrupenn/Tetris/hooks\",\n      \"svn_url\": \"https://svn.github.com/dtrupenn/Tetris\",\n      \"forks\": 1,\n      \"open_issues\": 1,\n      \"watchers\": 1,\n      \"has_issues\": true,\n      \"has_projects\": true,\n      \"has_pages\": true,\n      \"has_wiki\": true,\n      \"has_downloads\": true,\n      \"archived\": true,\n      \"disabled\": true,\n      \"license\": {\n        \"key\": \"mit\",\n        \"name\": \"MIT License\",\n        \"url\": \"https://api.github.com/licenses/mit\",\n        \"spdx_id\": \"MIT\",\n        \"node_id\": \"MDc6TGljZW5zZW1pdA==\",\n        \"html_url\": \"https://api.github.com/licenses/mit\"\n      }\n    }\n  ]\n}</code></pre></div>\n<h4>Not modified</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 304 Not Modified</code></pre></div>\n<h4>Validation failed</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 422 Unprocessable Entity</code></pre></div>\n<h4>Service unavailable</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 503 Service Unavailable</code></pre></div>\n<h4>Notes</h4>\n<ul>\n<li><a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/developers/apps\">Works with GitHub Apps</a></li>\n</ul>\n<h4>Preview notice</h4>\n<p>The <code class=\"language-text\">topics</code> property for repositories on GitHub is currently available for developers to preview. To view the <code class=\"language-text\">topics</code> property in calls that return repository results, you must provide a custom <a href=\"https://docs.github.com/rest/overview/media-types\">media type</a> in the <code class=\"language-text\">Accept</code> header:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">application/vnd.github.mercy-preview+json</code></pre></div>\n<hr>\n<h3><a href=\"#search-topics\">Search topics</a></h3>\n<p>Find topics via various criteria. Results are sorted by best match. This method returns up to 100 results <a href=\"https://docs.github.com/rest/overview/resources-in-the-rest-api#pagination\">per page</a>. See \"<a href=\"https://help.github.com/articles/searching-topics/\">Searching topics</a>\" for a detailed list of qualifiers.</p>\n<p>When searching for topics, you can get text match metadata for the topic's <strong>short_description</strong>, <strong>description</strong>, <strong>name</strong>, or <strong>display_name</strong> field when you pass the <code class=\"language-text\">text-match</code> media type. For more details about how to receive highlighted search results, see <a href=\"https://docs.github.com/rest/reference/search#text-match-metadata\">Text match metadata</a>.</p>\n<p>For example, if you want to search for topics related to Ruby that are featured on <a href=\"https://github.com/topics\">https://github.com/topics</a>. Your query might look like this:</p>\n<p><code class=\"language-text\">q=ruby+is:featured</code></p>\n<p>This query searches for topics with the keyword <code class=\"language-text\">ruby</code> and limits the results to find only topics that are featured. The topics that are the best match for the query appear first in the search results.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">get /search/topics</code></pre></div>\n<h4><a href=\"#search-topics--parameters\">Parameters</a></h4>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Type</th>\n<th>In</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">accept</code></td>\n<td>string</td>\n<td>header</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>This API is under preview and subject to change.<a href=\"#search-topics-preview-notices\">See preview notice</a></p>\n<p>|\n| <code class=\"language-text\">q</code> | string | query |</p>\n<p>The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see <a href=\"https://docs.github.com/rest/reference/search#constructing-a-search-query\">Constructing a search query</a>.</p>\n<p>|\n| <code class=\"language-text\">per_page</code> | integer | query |</p>\n<p>Results per page (max 100)</p>\n<p>Default: <code class=\"language-text\">30</code> |\n| <code class=\"language-text\">page</code> | integer | query |</p>\n<p>Page number of the results to fetch.</p>\n<p>Default: <code class=\"language-text\">1</code> |</p>\n<h4><a href=\"#search-topics--code-samples\">Code samples</a></h4>\n<h5>Shell</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl \\\n  -H \"Accept: application/vnd.github.mercy-preview+json\" \\\n  https://api.github.com/search/topics</code></pre></div>\n<h5>JavaScript (<a href=\"https://github.com/octokit/core.js#readme\">@octokit/core.js</a>)</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">await octokit.request('GET /search/topics', {\n  q: 'q',\n  mediaType: {\n    previews: [\n      'mercy'\n    ]\n  }\n})</code></pre></div>\n<h4>Response</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 200 OK\n\n{\n  \"total_count\": 6,\n  \"incomplete_results\": false,\n  \"items\": [\n    {\n      \"name\": \"ruby\",\n      \"display_name\": \"Ruby\",\n      \"short_description\": \"Ruby is a scripting language designed for simplified object-oriented programming.\",\n      \"description\": \"Ruby was developed by Yukihiro \\\"Matz\\\" Matsumoto in 1995 with the intent of having an easily readable programming language. It is integrated with the Rails framework to create dynamic web-applications. Ruby's syntax is similar to that of Perl and Python.\",\n      \"created_by\": \"Yukihiro Matsumoto\",\n      \"released\": \"December 21, 1995\",\n      \"created_at\": \"2016-11-28T22:03:59Z\",\n      \"updated_at\": \"2017-10-30T18:16:32Z\",\n      \"featured\": true,\n      \"curated\": true,\n      \"score\": 1\n    },\n    {\n      \"name\": \"rails\",\n      \"display_name\": \"Rails\",\n      \"short_description\": \"Ruby on Rails (Rails) is a web application framework written in Ruby.\",\n      \"description\": \"Ruby on Rails (Rails) is a web application framework written in Ruby. It is meant to help simplify the building of complex websites.\",\n      \"created_by\": \"David Heinemeier Hansson\",\n      \"released\": \"December 13 2005\",\n      \"created_at\": \"2016-12-09T17:03:50Z\",\n      \"updated_at\": \"2017-10-30T16:20:19Z\",\n      \"featured\": true,\n      \"curated\": true,\n      \"score\": 1\n    },\n    {\n      \"name\": \"python\",\n      \"display_name\": \"Python\",\n      \"short_description\": \"Python is a dynamically typed programming language.\",\n      \"description\": \"Python is a dynamically typed programming language designed by Guido Van Rossum. Much like the programming language Ruby, Python was designed to be easily read by programmers. Because of its large following and many libraries, Python can be implemented and used to do anything from webpages to scientific research.\",\n      \"created_by\": \"Guido van Rossum\",\n      \"released\": \"February 20, 1991\",\n      \"created_at\": \"2016-12-07T00:07:02Z\",\n      \"updated_at\": \"2017-10-27T22:45:43Z\",\n      \"featured\": true,\n      \"curated\": true,\n      \"score\": 1\n    },\n    {\n      \"name\": \"jekyll\",\n      \"display_name\": \"Jekyll\",\n      \"short_description\": \"Jekyll is a simple, blog-aware static site generator.\",\n      \"description\": \"Jekyll is a blog-aware, site generator written in Ruby. It takes raw text files, runs it through a renderer and produces a publishable static website.\",\n      \"created_by\": \"Tom Preston-Werner\",\n      \"released\": \"2008\",\n      \"created_at\": \"2016-12-16T21:53:08Z\",\n      \"updated_at\": \"2017-10-27T19:00:24Z\",\n      \"featured\": true,\n      \"curated\": true,\n      \"score\": 1\n    },\n    {\n      \"name\": \"sass\",\n      \"display_name\": \"Sass\",\n      \"short_description\": \"Sass is a stable extension to classic CSS.\",\n      \"description\": \"Sass is a stylesheet language with a main implementation in Ruby. It is an extension of CSS that makes improvements to the old stylesheet format, such as being able to declare variables and using a cleaner nesting syntax.\",\n      \"created_by\": \"Hampton Catlin, Natalie Weizenbaum, Chris Eppstein\",\n      \"released\": \"November 28, 2006\",\n      \"created_at\": \"2016-12-16T21:53:45Z\",\n      \"updated_at\": \"2018-01-16T16:30:40Z\",\n      \"featured\": true,\n      \"curated\": true,\n      \"score\": 1\n    },\n    {\n      \"name\": \"homebrew\",\n      \"display_name\": \"Homebrew\",\n      \"short_description\": \"Homebrew is a package manager for macOS.\",\n      \"description\": \"Homebrew is a package manager for Apple's macOS operating system. It simplifies the installation of software and is popular in the Ruby on Rails community.\",\n      \"created_by\": \"Max Howell\",\n      \"released\": \"2009\",\n      \"created_at\": \"2016-12-17T20:30:44Z\",\n      \"updated_at\": \"2018-02-06T16:14:56Z\",\n      \"featured\": true,\n      \"curated\": true,\n      \"score\": 1\n    }\n  ]\n}</code></pre></div>\n<h4>Not modified</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 304 Not Modified</code></pre></div>\n<h4>Preview header missing</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 415 Unsupported Media Type</code></pre></div>\n<h4>Notes</h4>\n<ul>\n<li><a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/developers/apps\">Works with GitHub Apps</a></li>\n</ul>\n<h4>Preview notice</h4>\n<p>The <code class=\"language-text\">topics</code> property for repositories on GitHub is currently available for developers to preview. To view the <code class=\"language-text\">topics</code> property in calls that return repository results, you must provide a custom <a href=\"https://docs.github.com/rest/overview/media-types\">media type</a> in the <code class=\"language-text\">Accept</code> header:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">application/vnd.github.mercy-preview+json</code></pre></div>\n<p>☝️This header is <strong>required</strong>.</p>\n<hr>\n<h3><a href=\"#search-users\">Search users</a></h3>\n<p>Find users via various criteria. This method returns up to 100 results <a href=\"https://docs.github.com/rest/overview/resources-in-the-rest-api#pagination\">per page</a>.</p>\n<p>When searching for users, you can get text match metadata for the issue <strong>login</strong>, <strong>email</strong>, and <strong>name</strong> fields when you pass the <code class=\"language-text\">text-match</code> media type. For more details about highlighting search results, see <a href=\"https://docs.github.com/rest/reference/search#text-match-metadata\">Text match metadata</a>. For more details about how to receive highlighted search results, see <a href=\"https://docs.github.com/rest/reference/search#text-match-metadata\">Text match metadata</a>.</p>\n<p>For example, if you're looking for a list of popular users, you might try this query:</p>\n<p><code class=\"language-text\">q=tom+repos:%3E42+followers:%3E1000</code></p>\n<p>This query searches for users with the name <code class=\"language-text\">tom</code>. The results are restricted to users with more than 42 repositories and over 1,000 followers.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">get /search/users</code></pre></div>\n<h4><a href=\"#search-users--parameters\">Parameters</a></h4>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Type</th>\n<th>In</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">accept</code></td>\n<td>string</td>\n<td>header</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p>Setting to <code class=\"language-text\">application/vnd.github.v3+json</code> is recommended.</p>\n<p>|\n| <code class=\"language-text\">q</code> | string | query |</p>\n<p>The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see <a href=\"https://docs.github.com/rest/reference/search#constructing-a-search-query\">Constructing a search query</a>. See \"<a href=\"https://help.github.com/articles/searching-users/\">Searching users</a>\" for a detailed list of qualifiers.</p>\n<p>|\n| <code class=\"language-text\">sort</code> | string | query |</p>\n<p>Sorts the results of your query by number of <code class=\"language-text\">followers</code> or <code class=\"language-text\">repositories</code>, or when the person <code class=\"language-text\">joined</code> GitHub. Default: <a href=\"https://docs.github.com/rest/reference/search#ranking-search-results\">best match</a></p>\n<p>|\n| <code class=\"language-text\">order</code> | string | query |</p>\n<p>Determines whether the first search result returned is the highest number of matches (<code class=\"language-text\">desc</code>) or lowest number of matches (<code class=\"language-text\">asc</code>). This parameter is ignored unless you provide <code class=\"language-text\">sort</code>.</p>\n<p>Default: <code class=\"language-text\">desc</code> |\n| <code class=\"language-text\">per_page</code> | integer | query |</p>\n<p>Results per page (max 100)</p>\n<p>Default: <code class=\"language-text\">30</code> |\n| <code class=\"language-text\">page</code> | integer | query |</p>\n<p>Page number of the results to fetch.</p>\n<p>Default: <code class=\"language-text\">1</code> |</p>\n<h4><a href=\"#search-users--code-samples\">Code samples</a></h4>\n<h5>Shell</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl \\\n  -H \"Accept: application/vnd.github.v3+json\" \\\n  https://api.github.com/search/users</code></pre></div>\n<h5>JavaScript (<a href=\"https://github.com/octokit/core.js#readme\">@octokit/core.js</a>)</h5>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">await octokit.request('GET /search/users', {\n  q: 'q'\n})</code></pre></div>\n<h4>Response</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 200 OK\n\n{\n  \"total_count\": 12,\n  \"incomplete_results\": false,\n  \"items\": [\n    {\n      \"login\": \"mojombo\",\n      \"id\": 1,\n      \"node_id\": \"MDQ6VXNlcjE=\",\n      \"avatar_url\": \"https://secure.gravatar.com/avatar/25c7c18223fb42a4c6ae1c8db6f50f9b?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png\",\n      \"gravatar_id\": \"\",\n      \"url\": \"https://api.github.com/users/mojombo\",\n      \"html_url\": \"https://github.com/mojombo\",\n      \"followers_url\": \"https://api.github.com/users/mojombo/followers\",\n      \"subscriptions_url\": \"https://api.github.com/users/mojombo/subscriptions\",\n      \"organizations_url\": \"https://api.github.com/users/mojombo/orgs\",\n      \"repos_url\": \"https://api.github.com/users/mojombo/repos\",\n      \"received_events_url\": \"https://api.github.com/users/mojombo/received_events\",\n      \"type\": \"User\",\n      \"score\": 1,\n      \"following_url\": \"https://api.github.com/users/mojombo/following{/other_user}\",\n      \"gists_url\": \"https://api.github.com/users/mojombo/gists{/gist_id}\",\n      \"starred_url\": \"https://api.github.com/users/mojombo/starred{/owner}{/repo}\",\n      \"events_url\": \"https://api.github.com/users/mojombo/events{/privacy}\",\n      \"site_admin\": true\n    }\n  ]\n}</code></pre></div>\n<h4>Not modified</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 304 Not Modified</code></pre></div>\n<h4>Validation failed</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 422 Unprocessable Entity</code></pre></div>\n<h4>Service unavailable</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Status: 503 Service Unavailable</code></pre></div>\n<h4>Notes</h4>\n<ul>\n<li><a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en/developers/apps\">Works with GitHub Apps</a></li>\n</ul>\n<hr>\n<h3><a href=\"#text-match-metadata\">Text match metadata</a></h3>\n<p>On GitHub, you can use the context provided by code snippets and highlights in search results. The Search API offers additional metadata that allows you to highlight the matching search terms when displaying search results.</p>\n<p><img src=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/assets/images/text-match-search-api.png\" alt=\"code-snippet-highlighting\"></p>\n<p>Requests can opt to receive those text fragments in the response, and every fragment is accompanied by numeric offsets identifying the exact location of each matching search term.</p>\n<p>To get this metadata in your search results, specify the <code class=\"language-text\">text-match</code> media type in your <code class=\"language-text\">Accept</code> header.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">application/vnd.github.v3.text-match+json</code></pre></div>\n<p>When you provide the <code class=\"language-text\">text-match</code> media type, you will receive an extra key in the JSON payload called <code class=\"language-text\">text_matches</code> that provides information about the position of your search terms within the text and the <code class=\"language-text\">property</code> that includes the search term. Inside the <code class=\"language-text\">text_matches</code> array, each object includes the following attributes:</p>\n<table>\n<thead>\n<tr>\n<th>Name</th>\n<th>Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code class=\"language-text\">object_url</code></td>\n<td>The URL for the resource that contains a string property matching one of the search terms.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">object_type</code></td>\n<td>The name for the type of resource that exists at the given <code class=\"language-text\">object_url</code>.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">property</code></td>\n<td>The name of a property of the resource that exists at <code class=\"language-text\">object_url</code>. That property is a string that matches one of the search terms. (In the JSON returned from <code class=\"language-text\">object_url</code>, the full content for the <code class=\"language-text\">fragment</code> will be found in the property with this name.)</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">fragment</code></td>\n<td>A subset of the value of <code class=\"language-text\">property</code>. This is the text fragment that matches one or more of the search terms.</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">matches</code></td>\n<td>An array of one or more search terms that are present in <code class=\"language-text\">fragment</code>. The indices (i.e., \"offsets\") are relative to the fragment. (They are not relative to the <em>full</em> content of <code class=\"language-text\">property</code>.)</td>\n</tr>\n</tbody>\n</table>\n<h4><a href=\"#example\">Example</a></h4>\n<p>Using cURL, and the <a href=\"#search-issues-and-pull-requests\">example issue search</a> above, our API request would look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">curl -H 'Accept: application/vnd.github.v3.text-match+json' \\\n'https://api.github.com/search/issues?q=windows+label:bug+language:python+state:open&amp;sort=created&amp;order=asc'</code></pre></div>\n<p>The response will include a <code class=\"language-text\">text_matches</code> array for each search result. In the JSON below, we have two objects in the <code class=\"language-text\">text_matches</code> array.</p>\n<p>The first text match occurred in the <code class=\"language-text\">body</code> property of the issue. We see a fragment of text from the issue body. The search term (<code class=\"language-text\">windows</code>) appears twice within that fragment, and we have the indices for each occurrence.</p>\n<p>The second text match occurred in the <code class=\"language-text\">body</code> property of one of the issue's comments. We have the URL for the issue comment. And of course, we see a fragment of text from the comment body. The search term (<code class=\"language-text\">windows</code>) appears once within that fragment.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"text_matches\": [\n    {\n      \"object_url\": \"https://api.github.com/repositories/215335/issues/132\",\n      \"object_type\": \"Issue\",\n      \"property\": \"body\",\n      \"fragment\": \"comprehensive windows font I know of).\\n\\nIf we can find a commonly distributed windows font that supports them then no problem (we can use html font tags) but otherwise the '(21)' style is probably better.\\n\",\n      \"matches\": [\n        {\n          \"text\": \"windows\",\n          \"indices\": [\n            14,\n            21\n          ]\n        },\n        {\n          \"text\": \"windows\",\n          \"indices\": [\n            78,\n            85\n          ]\n        }\n      ]\n    },\n    {\n      \"object_url\": \"https://api.github.com/repositories/215335/issues/comments/25688\",\n      \"object_type\": \"IssueComment\",\n      \"property\": \"body\",\n      \"fragment\": \" right after that are a bit broken IMHO :). I suppose we could have some hack that maxes out at whatever the font does...\\n\\nI'll check what the state of play is on Windows.\\n\",\n      \"matches\": [\n        {\n          \"text\": \"Windows\",\n          \"indices\": [\n            163,\n            170\n          ]\n        }\n      ]\n    }\n  ]\n}</code></pre></div>"},{"url":"/docs/reference/web-api's/","relativePath":"docs/reference/web-api's.md","relativeDir":"docs/reference","base":"web-api's.md","name":"web-api's","frontmatter":{"title":"Web Apis","weight":0,"excerpt":"When writing code for the Web, there are a large number of Web APIs available. Below is a list of all the APIs and interfaces (object types) that you may be able to use while developing your Web app or site","seo":{"title":"Web Apis","description":"When writing code for the Web, there are a large number of Web APIs available. Below is a list of all the APIs and interfaces (object types) that you may be able to use while developing your Web app or site","robots":[],"extra":[]},"template":"docs"},"html":"<h2># Web APIs</h2>\n<p>When writing code for the Web, there are a large number of Web APIs available. Below is a list of all the APIs and interfaces (object types) that you may be able to use while developing your Web app or site.</p>\n<p>Web APIs are typically used with JavaScript, although this doesn't always have to be the case.</p>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API#specifications\" title=\"Permalink to Specifications\">Specifications</a></h2>\n<p>This is a list of all the APIs that are available.</p>\n<p>B</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Background_Fetch_API\">Background Fetch API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Background_Tasks_API\">Background Tasks</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Barcode_Detection_API\">Barcode Detection API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Battery_Status_API\">Battery API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API\">Beacon</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API\">Bluetooth API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API\">Broadcast Channel API</a></li>\n</ul>\n<p>C</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSS_Counter_Styles\">CSS Counter Styles</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSS_Font_Loading_API\">CSS Font Loading API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSS_Painting_API\">CSS Painting API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSS_Typed_OM_API\">CSS Typed Object Model API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model\">CSSOM</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API\">Canvas API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API\">Channel Messaging API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API\">Clipboard API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Console_API\">Console API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Contact_Picker_API\">Contact Picker API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Content_Index_API\">Content Index API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Credential_Management_API\">Credential Management API</a></li>\n</ul>\n<p>D</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model\">DOM</a></li>\n</ul>\n<p>E</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API\">Encoding API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Encrypted_Media_Extensions_API\">Encrypted Media Extensions</a></li>\n</ul>\n<p>F</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\">Fetch API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/File_System_Access_API\">File System Access API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/File_and_Directory_Entries_API\">File and Directory Entries API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API\">Fullscreen API</a></li>\n</ul>\n<p>G</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API\">Gamepad API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API\">Geolocation API</a></li>\n</ul>\n<p>H</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API\">HTML Drag and Drop API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTML_Sanitizer_API\">HTML Sanitizer API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Performance_API\">High Resolution Time</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History_API\">History API</a></li>\n</ul>\n<p>I</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Image_Capture_API\">Image Capture API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API\">IndexedDB</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API\">Intersection Observer API</a></li>\n</ul>\n<p>L</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Layout_Instability_API\">Layout Instability API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Long_Tasks_API\">Long Tasks API</a></li>\n</ul>\n<p>M</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Media_Capabilities_API\">Media Capabilities API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Media_Streams_API\">Media Capture and Streams</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Media_Session_API\">Media Session API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Media_Source_Extensions_API\">Media Source Extensions</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API\">MediaStream Recording</a></li>\n</ul>\n<p>N</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Navigation_timing_API\">Navigation Timing</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API\">Network Information API</a></li>\n</ul>\n<p>P</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API\">Page Visibility API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Payment_Request_API\">Payment Request API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Performance_API\">Performance API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Performance_Timeline\">Performance Timeline API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Periodic_Background_Synchronization_API\">Periodic Background Sync</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API\">Permissions API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API\">Picture-in-Picture API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events\">Pointer Events</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API\">Pointer Lock API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Presentation_API\">Presentation API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Proximity_Events\">Proximity Events</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Push_API\">Push API</a></li>\n</ul>\n<p>R</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API\">Resize Observer API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Resource_Timing_API\">Resource Timing API</a></li>\n</ul>\n<p>S</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Screen_Capture_API\">Screen Capture API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Screen_Orientation_API\">Screen Orientation API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API\">Screen Wake Lock API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Sensor_APIs\">Sensor API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events\">Server Sent Events</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API\">Service Workers API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Storage_API\">Storage</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Storage_Access_API\">Storage Access API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Streams_API\">Streams</a></li>\n</ul>\n<p>T</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Touch_events\">Touch Events</a></li>\n</ul>\n<p>U</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/URL_API\">URL API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API\">URL Pattern API</a></li>\n</ul>\n<p>V</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API\">Vibration API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Visual_Viewport_API\">Visual Viewport</a></li>\n</ul>\n<p>W</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API\">Web Animations</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API\">Web Audio API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API\">Web Authentication API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API\">Web Crypto API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API\">Web MIDI API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API\">Web Notifications</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API\">Web Share API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API\">Web Speech API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API\">Web Storage API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API\">Web Workers API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API\">WebCodecs API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API\">WebGL</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API\">WebHID API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API\">WebRTC</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebVR_API\">WebVR API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API\">WebVTT</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API\">WebXR Device API</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API\">Websockets API</a></li>\n</ul>\n<p>X</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\">XMLHttpRequest</a></li>\n</ul>\n<h2><a href=\"https://developer.mozilla.org/en-US/docs/Web/API#interfaces\" title=\"Permalink to Interfaces\">Interfaces</a></h2>\n<p>This is a list of all the interfaces (that is, types of objects) that are available.</p>\n<p>A</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AbortController\"><code class=\"language-text\">AbortController</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\"><code class=\"language-text\">AbortSignal</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AbsoluteOrientationSensor\"><code class=\"language-text\">AbsoluteOrientationSensor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AbstractRange\"><code class=\"language-text\">AbstractRange</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Accelerometer\"><code class=\"language-text\">Accelerometer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AddressErrors\"><code class=\"language-text\">AddressErrors</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AesCbcParams\"><code class=\"language-text\">AesCbcParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AesCtrParams\"><code class=\"language-text\">AesCtrParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AesGcmParams\"><code class=\"language-text\">AesGcmParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AesKeyGenParams\"><code class=\"language-text\">AesKeyGenParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AmbientLightSensor\"><code class=\"language-text\">AmbientLightSensor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode\"><code class=\"language-text\">AnalyserNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ANGLE_instanced_arrays\"><code class=\"language-text\">ANGLE_instanced_arrays</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Animation\"><code class=\"language-text\">Animation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect\"><code class=\"language-text\">AnimationEffect</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent\"><code class=\"language-text\">AnimationEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AnimationPlaybackEvent\"><code class=\"language-text\">AnimationPlaybackEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AnimationTimeline\"><code class=\"language-text\">AnimationTimeline</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView\"><code class=\"language-text\">ArrayBufferView</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/atob\"><code class=\"language-text\">atob()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Attr\"><code class=\"language-text\">Attr</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer\"><code class=\"language-text\">AudioBuffer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode\"><code class=\"language-text\">AudioBufferSourceNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioConfiguration\"><code class=\"language-text\">AudioConfiguration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioContext\"><code class=\"language-text\">AudioContext</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioData\"><code class=\"language-text\">AudioData</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioDecoder\"><code class=\"language-text\">AudioDecoder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioDestinationNode\"><code class=\"language-text\">AudioDestinationNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioEncoder\"><code class=\"language-text\">AudioEncoder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioListener\"><code class=\"language-text\">AudioListener</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioNode\"><code class=\"language-text\">AudioNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioParam\"><code class=\"language-text\">AudioParam</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioParamDescriptor\"><code class=\"language-text\">AudioParamDescriptor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioParamMap\"><code class=\"language-text\">AudioParamMap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioProcessingEvent\"><code class=\"language-text\">AudioProcessingEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioScheduledSourceNode\"><code class=\"language-text\">AudioScheduledSourceNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioTrack\"><code class=\"language-text\">AudioTrack</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioTrackList\"><code class=\"language-text\">AudioTrackList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet\"><code class=\"language-text\">AudioWorklet</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletGlobalScope\"><code class=\"language-text\">AudioWorkletGlobalScope</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletNode\"><code class=\"language-text\">AudioWorkletNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor\"><code class=\"language-text\">AudioWorkletProcessor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorAssertionResponse\"><code class=\"language-text\">AuthenticatorAssertionResponse</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorAttestationResponse\"><code class=\"language-text\">AuthenticatorAttestationResponse</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorResponse\"><code class=\"language-text\">AuthenticatorResponse</code></a></li>\n</ul>\n<p>B</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BackgroundFetchEvent\"><code class=\"language-text\">BackgroundFetchEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BackgroundFetchManager\"><code class=\"language-text\">BackgroundFetchManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BackgroundFetchRecord\"><code class=\"language-text\">BackgroundFetchRecord</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BackgroundFetchRegistration\"><code class=\"language-text\">BackgroundFetchRegistration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BackgroundFetchUpdateUIEvent\"><code class=\"language-text\">BackgroundFetchUpdateUIEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BarcodeDetector\"><code class=\"language-text\">BarcodeDetector</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BarProp\"><code class=\"language-text\">BarProp</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BaseAudioContext\"><code class=\"language-text\">BaseAudioContext</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager\"><code class=\"language-text\">BatteryManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent\"><code class=\"language-text\">BeforeInstallPromptEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BeforeUnloadEvent\"><code class=\"language-text\">BeforeUnloadEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode\"><code class=\"language-text\">BiquadFilterNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Blob\"><code class=\"language-text\">Blob</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BlobBuilder\"><code class=\"language-text\">BlobBuilder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BlobEvent\"><code class=\"language-text\">BlobEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Bluetooth\"><code class=\"language-text\">Bluetooth</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BluetoothCharacteristicProperties\"><code class=\"language-text\">BluetoothCharacteristicProperties</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BluetoothDevice\"><code class=\"language-text\">BluetoothDevice</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic\"><code class=\"language-text\">BluetoothRemoteGATTCharacteristic</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTDescriptor\"><code class=\"language-text\">BluetoothRemoteGATTDescriptor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTServer\"><code class=\"language-text\">BluetoothRemoteGATTServer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTService\"><code class=\"language-text\">BluetoothRemoteGATTService</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BluetoothUUID\"><code class=\"language-text\">BluetoothUUID</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel\"><code class=\"language-text\">BroadcastChannel</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/btoa\"><code class=\"language-text\">btoa()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/BufferSource\"><code class=\"language-text\">BufferSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ByteLengthQueuingStrategy\"><code class=\"language-text\">ByteLengthQueuingStrategy</code></a></li>\n</ul>\n<p>C</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Cache\"><code class=\"language-text\">Cache</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/caches\"><code class=\"language-text\">caches</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage\"><code class=\"language-text\">CacheStorage</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CanvasCaptureMediaStreamTrack\"><code class=\"language-text\">CanvasCaptureMediaStreamTrack</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CanvasGradient\"><code class=\"language-text\">CanvasGradient</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CanvasImageSource\"><code class=\"language-text\">CanvasImageSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern\"><code class=\"language-text\">CanvasPattern</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D\"><code class=\"language-text\">CanvasRenderingContext2D</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CaretPosition\"><code class=\"language-text\">CaretPosition</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CDATASection\"><code class=\"language-text\">CDATASection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ChannelMergerNode\"><code class=\"language-text\">ChannelMergerNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ChannelSplitterNode\"><code class=\"language-text\">ChannelSplitterNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CharacterData\"><code class=\"language-text\">CharacterData</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/clearInterval\"><code class=\"language-text\">clearInterval()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout\"><code class=\"language-text\">clearTimeout()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Client\"><code class=\"language-text\">Client</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Clients\"><code class=\"language-text\">Clients</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Clipboard\"><code class=\"language-text\">Clipboard</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent\"><code class=\"language-text\">ClipboardEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem\"><code class=\"language-text\">ClipboardItem</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent\"><code class=\"language-text\">CloseEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Comment\"><code class=\"language-text\">Comment</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent\"><code class=\"language-text\">CompositionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream\"><code class=\"language-text\">CompressionStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/console\"><code class=\"language-text\">console</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ConstantSourceNode\"><code class=\"language-text\">ConstantSourceNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ContactsManager\"><code class=\"language-text\">ContactsManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ContentIndex\"><code class=\"language-text\">ContentIndex</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ContentIndexEvent\"><code class=\"language-text\">ContentIndexEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ConvolverNode\"><code class=\"language-text\">ConvolverNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CookieChangeEvent\"><code class=\"language-text\">CookieChangeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CookieStore\"><code class=\"language-text\">CookieStore</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CookieStoreManager\"><code class=\"language-text\">CookieStoreManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CountQueuingStrategy\"><code class=\"language-text\">CountQueuingStrategy</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CrashReportBody\"><code class=\"language-text\">CrashReportBody</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/createImageBitmap\"><code class=\"language-text\">createImageBitmap()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Credential\"><code class=\"language-text\">Credential</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer\"><code class=\"language-text\">CredentialsContainer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated\"><code class=\"language-text\">crossOriginIsolated</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Crypto\"><code class=\"language-text\">Crypto</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey\"><code class=\"language-text\">CryptoKey</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CryptoKeyPair\"><code class=\"language-text\">CryptoKeyPair</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSS\"><code class=\"language-text\">CSS</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSAnimation\"><code class=\"language-text\">CSSAnimation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSConditionRule\"><code class=\"language-text\">CSSConditionRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSCounterStyleRule\"><code class=\"language-text\">CSSCounterStyleRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSFontFaceRule\"><code class=\"language-text\">CSSFontFaceRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSGroupingRule\"><code class=\"language-text\">CSSGroupingRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSImageValue\"><code class=\"language-text\">CSSImageValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSImportRule\"><code class=\"language-text\">CSSImportRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSKeyframeRule\"><code class=\"language-text\">CSSKeyframeRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSKeyframesRule\"><code class=\"language-text\">CSSKeyframesRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSKeywordValue\"><code class=\"language-text\">CSSKeywordValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMathInvert\"><code class=\"language-text\">CSSMathInvert</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMathMax\"><code class=\"language-text\">CSSMathMax</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMathMin\"><code class=\"language-text\">CSSMathMin</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMathNegate\"><code class=\"language-text\">CSSMathNegate</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMathProduct\"><code class=\"language-text\">CSSMathProduct</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMathSum\"><code class=\"language-text\">CSSMathSum</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMathValue\"><code class=\"language-text\">CSSMathValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMatrixComponent\"><code class=\"language-text\">CSSMatrixComponent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSMediaRule\"><code class=\"language-text\">CSSMediaRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSNamespaceRule\"><code class=\"language-text\">CSSNamespaceRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericArray\"><code class=\"language-text\">CSSNumericArray</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue\"><code class=\"language-text\">CSSNumericValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSOMString\"><code class=\"language-text\">CSSOMString</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSPageRule\"><code class=\"language-text\">CSSPageRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSPerspective\"><code class=\"language-text\">CSSPerspective</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSPositionValue\"><code class=\"language-text\">CSSPositionValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSPrimitiveValue\"><code class=\"language-text\">CSSPrimitiveValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSPropertyRule\"><code class=\"language-text\">CSSPropertyRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSPseudoElement\"><code class=\"language-text\">CSSPseudoElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSRotate\"><code class=\"language-text\">CSSRotate</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSRule\"><code class=\"language-text\">CSSRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSRuleList\"><code class=\"language-text\">CSSRuleList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSScale\"><code class=\"language-text\">CSSScale</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSSkew\"><code class=\"language-text\">CSSSkew</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSSkewX\"><code class=\"language-text\">CSSSkewX</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSSkewY\"><code class=\"language-text\">CSSSkewY</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration\"><code class=\"language-text\">CSSStyleDeclaration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleRule\"><code class=\"language-text\">CSSStyleRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet\"><code class=\"language-text\">CSSStyleSheet</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleValue\"><code class=\"language-text\">CSSStyleValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSSupportsRule\"><code class=\"language-text\">CSSSupportsRule</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSTransformComponent\"><code class=\"language-text\">CSSTransformComponent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSTransformValue\"><code class=\"language-text\">CSSTransformValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSTransition\"><code class=\"language-text\">CSSTransition</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSTranslate\"><code class=\"language-text\">CSSTranslate</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSUnitValue\"><code class=\"language-text\">CSSUnitValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSUnparsedValue\"><code class=\"language-text\">CSSUnparsedValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSValue\"><code class=\"language-text\">CSSValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSValueList\"><code class=\"language-text\">CSSValueList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CSSVariableReferenceValue\"><code class=\"language-text\">CSSVariableReferenceValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry\"><code class=\"language-text\">CustomElementRegistry</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent\"><code class=\"language-text\">CustomEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet\"><code class=\"language-text\">CustomStateSet</code></a></li>\n</ul>\n<p>D</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer\"><code class=\"language-text\">DataTransfer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem\"><code class=\"language-text\">DataTransferItem</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItemList\"><code class=\"language-text\">DataTransferItemList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream\"><code class=\"language-text\">DecompressionStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope\"><code class=\"language-text\">DedicatedWorkerGlobalScope</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DelayNode\"><code class=\"language-text\">DelayNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DeprecationReportBody\"><code class=\"language-text\">DeprecationReportBody</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent\"><code class=\"language-text\">DeviceMotionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEventAcceleration\"><code class=\"language-text\">DeviceMotionEventAcceleration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEventRotationRate\"><code class=\"language-text\">DeviceMotionEventRotationRate</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent\"><code class=\"language-text\">DeviceOrientationEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DeviceProximityEvent\"><code class=\"language-text\">DeviceProximityEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DirectoryEntrySync\"><code class=\"language-text\">DirectoryEntrySync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReaderSync\"><code class=\"language-text\">DirectoryReaderSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DisplayMediaStreamConstraints\"><code class=\"language-text\">DisplayMediaStreamConstraints</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document\"><code class=\"language-text\">Document</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment\"><code class=\"language-text\">DocumentFragment</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DocumentTimeline\"><code class=\"language-text\">DocumentTimeline</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DocumentType\"><code class=\"language-text\">DocumentType</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMError\"><code class=\"language-text\">DOMError</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMException\"><code class=\"language-text\">DOMException</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp\"><code class=\"language-text\">DOMHighResTimeStamp</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation\"><code class=\"language-text\">DOMImplementation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrix\"><code class=\"language-text\">DOMMatrix</code> (WebKitCSSMatrix)</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMMatrixReadOnly\"><code class=\"language-text\">DOMMatrixReadOnly</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMParser\"><code class=\"language-text\">DOMParser</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMPoint\"><code class=\"language-text\">DOMPoint</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMPointReadOnly\"><code class=\"language-text\">DOMPointReadOnly</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMQuad\"><code class=\"language-text\">DOMQuad</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMRect\"><code class=\"language-text\">DOMRect</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMRectReadOnly\"><code class=\"language-text\">DOMRectReadOnly</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMString\"><code class=\"language-text\">DOMString</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMStringList\"><code class=\"language-text\">DOMStringList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMStringMap\"><code class=\"language-text\">DOMStringMap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMTimeStamp\"><code class=\"language-text\">DOMTimeStamp</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList\"><code class=\"language-text\">DOMTokenList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DragEvent\"><code class=\"language-text\">DragEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/DynamicsCompressorNode\"><code class=\"language-text\">DynamicsCompressorNode</code></a></li>\n</ul>\n<p>E</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EcdhKeyDeriveParams\"><code class=\"language-text\">EcdhKeyDeriveParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EcdsaParams\"><code class=\"language-text\">EcdsaParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EcKeyGenParams\"><code class=\"language-text\">EcKeyGenParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EcKeyImportParams\"><code class=\"language-text\">EcKeyImportParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Element\"><code class=\"language-text\">Element</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals\"><code class=\"language-text\">ElementInternals</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EncodedAudioChunk\"><code class=\"language-text\">EncodedAudioChunk</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EncodedVideoChunk\"><code class=\"language-text\">EncodedVideoChunk</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent\"><code class=\"language-text\">ErrorEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Event\"><code class=\"language-text\">Event</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EventListener\"><code class=\"language-text\">EventListener</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EventSource\"><code class=\"language-text\">EventSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EventTarget\"><code class=\"language-text\">EventTarget</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_blend_minmax\"><code class=\"language-text\">EXT_blend_minmax</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_color_buffer_float\"><code class=\"language-text\">EXT_color_buffer_float</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_color_buffer_half_float\"><code class=\"language-text\">EXT_color_buffer_half_float</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_disjoint_timer_query\"><code class=\"language-text\">EXT_disjoint_timer_query</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_float_blend\"><code class=\"language-text\">EXT_float_blend</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_frag_depth\"><code class=\"language-text\">EXT_frag_depth</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_shader_texture_lod\"><code class=\"language-text\">EXT_shader_texture_lod</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_sRGB\"><code class=\"language-text\">EXT_sRGB</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_compression_bptc\"><code class=\"language-text\">EXT_texture_compression_bptc</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_compression_rgtc\"><code class=\"language-text\">EXT_texture_compression_rgtc</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_filter_anisotropic\"><code class=\"language-text\">EXT_texture_filter_anisotropic</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/EXT_texture_norm16\"><code class=\"language-text\">EXT_texture_norm16</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ExtendableCookieChangeEvent\"><code class=\"language-text\">ExtendableCookieChangeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent\"><code class=\"language-text\">ExtendableEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ExtendableMessageEvent\"><code class=\"language-text\">ExtendableMessageEvent</code></a></li>\n</ul>\n<p>F</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FeaturePolicy\"><code class=\"language-text\">FeaturePolicy</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FederatedCredential\"><code class=\"language-text\">FederatedCredential</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/fetch\"><code class=\"language-text\">fetch()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent\"><code class=\"language-text\">FetchEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/File\"><code class=\"language-text\">File</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileEntrySync\"><code class=\"language-text\">FileEntrySync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileException\"><code class=\"language-text\">FileException</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileList\"><code class=\"language-text\">FileList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileReader\"><code class=\"language-text\">FileReader</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileReaderSync\"><code class=\"language-text\">FileReaderSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileRequest\"><code class=\"language-text\">FileRequest</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystem\"><code class=\"language-text\">FileSystem</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry\"><code class=\"language-text\">FileSystemDirectoryEntry</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle\"><code class=\"language-text\">FileSystemDirectoryHandle</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader\"><code class=\"language-text\">FileSystemDirectoryReader</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry\"><code class=\"language-text\">FileSystemEntry</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntrySync\"><code class=\"language-text\">FileSystemEntrySync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry\"><code class=\"language-text\">FileSystemFileEntry</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle\"><code class=\"language-text\">FileSystemFileHandle</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFlags\"><code class=\"language-text\">FileSystemFlags</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle\"><code class=\"language-text\">FileSystemHandle</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemSync\"><code class=\"language-text\">FileSystemSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream\"><code class=\"language-text\">FileSystemWritableFileStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent\"><code class=\"language-text\">FocusEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FontFace\"><code class=\"language-text\">FontFace</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet\"><code class=\"language-text\">FontFaceSet</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSetLoadEvent\"><code class=\"language-text\">FontFaceSetLoadEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FormData\"><code class=\"language-text\">FormData</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue\"><code class=\"language-text\">FormDataEntryValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/FormDataEvent\"><code class=\"language-text\">FormDataEvent</code></a></li>\n</ul>\n<p>G</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GainNode\"><code class=\"language-text\">GainNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Gamepad\"><code class=\"language-text\">Gamepad</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GamepadButton\"><code class=\"language-text\">GamepadButton</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GamepadEvent\"><code class=\"language-text\">GamepadEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GamepadHapticActuator\"><code class=\"language-text\">GamepadHapticActuator</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GamepadPose\"><code class=\"language-text\">GamepadPose</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Geolocation\"><code class=\"language-text\">Geolocation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates\"><code class=\"language-text\">GeolocationCoordinates</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPosition\"><code class=\"language-text\">GeolocationPosition</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError\"><code class=\"language-text\">GeolocationPositionError</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GestureEvent\"><code class=\"language-text\">GestureEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/getCandidateWindowClientRect\"><code class=\"language-text\">getCandidateWindowClientRect</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers\"><code class=\"language-text\">GlobalEventHandlers</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/GravitySensor\"><code class=\"language-text\">GravitySensor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Gyroscope\"><code class=\"language-text\">Gyroscope</code></a></li>\n</ul>\n<p>H</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HashChangeEvent\"><code class=\"language-text\">HashChangeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Headers\"><code class=\"language-text\">Headers</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HID\"><code class=\"language-text\">HID</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HIDConnectionEvent\"><code class=\"language-text\">HIDConnectionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HIDDevice\"><code class=\"language-text\">HIDDevice</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HIDInputReportEvent\"><code class=\"language-text\">HIDInputReportEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/History\"><code class=\"language-text\">History</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HkdfParams\"><code class=\"language-text\">HkdfParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HmacImportParams\"><code class=\"language-text\">HmacImportParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HmacKeyGenParams\"><code class=\"language-text\">HmacKeyGenParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HMDVRDevice\"><code class=\"language-text\">HMDVRDevice</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement\"><code class=\"language-text\">HTMLAnchorElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLAreaElement\"><code class=\"language-text\">HTMLAreaElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLAudioElement\"><code class=\"language-text\">HTMLAudioElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLBaseElement\"><code class=\"language-text\">HTMLBaseElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLBaseFontElement\"><code class=\"language-text\">HTMLBaseFontElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLBodyElement\"><code class=\"language-text\">HTMLBodyElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLBRElement\"><code class=\"language-text\">HTMLBRElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement\"><code class=\"language-text\">HTMLButtonElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement\"><code class=\"language-text\">HTMLCanvasElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection\"><code class=\"language-text\">HTMLCollection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLContentElement\"><code class=\"language-text\">HTMLContentElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLDataElement\"><code class=\"language-text\">HTMLDataElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLDataListElement\"><code class=\"language-text\">HTMLDataListElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLDetailsElement\"><code class=\"language-text\">HTMLDetailsElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement\"><code class=\"language-text\">HTMLDialogElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLDivElement\"><code class=\"language-text\">HTMLDivElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLDListElement\"><code class=\"language-text\">HTMLDListElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLDocument\"><code class=\"language-text\">HTMLDocument</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement\"><code class=\"language-text\">HTMLElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLEmbedElement\"><code class=\"language-text\">HTMLEmbedElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLFieldSetElement\"><code class=\"language-text\">HTMLFieldSetElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLFontElement\"><code class=\"language-text\">HTMLFontElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormControlsCollection\"><code class=\"language-text\">HTMLFormControlsCollection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement\"><code class=\"language-text\">HTMLFormElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLFrameSetElement\"><code class=\"language-text\">HTMLFrameSetElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLHeadElement\"><code class=\"language-text\">HTMLHeadElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLHeadingElement\"><code class=\"language-text\">HTMLHeadingElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLHRElement\"><code class=\"language-text\">HTMLHRElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLHtmlElement\"><code class=\"language-text\">HTMLHtmlElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement\"><code class=\"language-text\">HTMLIFrameElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement\"><code class=\"language-text\">HTMLImageElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement\"><code class=\"language-text\">HTMLInputElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLKeygenElement\"><code class=\"language-text\">HTMLKeygenElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement\"><code class=\"language-text\">HTMLLabelElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLLegendElement\"><code class=\"language-text\">HTMLLegendElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLLIElement\"><code class=\"language-text\">HTMLLIElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLLinkElement\"><code class=\"language-text\">HTMLLinkElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLMapElement\"><code class=\"language-text\">HTMLMapElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLMarqueeElement\"><code class=\"language-text\">HTMLMarqueeElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement\"><code class=\"language-text\">HTMLMediaElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLMenuElement\"><code class=\"language-text\">HTMLMenuElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLMenuItemElement\"><code class=\"language-text\">HTMLMenuItemElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLMetaElement\"><code class=\"language-text\">HTMLMetaElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLMeterElement\"><code class=\"language-text\">HTMLMeterElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLModElement\"><code class=\"language-text\">HTMLModElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement\"><code class=\"language-text\">HTMLObjectElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLOListElement\"><code class=\"language-text\">HTMLOListElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptGroupElement\"><code class=\"language-text\">HTMLOptGroupElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement\"><code class=\"language-text\">HTMLOptionElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection\"><code class=\"language-text\">HTMLOptionsCollection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement\"><code class=\"language-text\">HTMLOutputElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLParagraphElement\"><code class=\"language-text\">HTMLParagraphElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLParamElement\"><code class=\"language-text\">HTMLParamElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLPictureElement\"><code class=\"language-text\">HTMLPictureElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLPreElement\"><code class=\"language-text\">HTMLPreElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLProgressElement\"><code class=\"language-text\">HTMLProgressElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLQuoteElement\"><code class=\"language-text\">HTMLQuoteElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement\"><code class=\"language-text\">HTMLScriptElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement\"><code class=\"language-text\">HTMLSelectElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLShadowElement\"><code class=\"language-text\">HTMLShadowElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement\"><code class=\"language-text\">HTMLSlotElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLSourceElement\"><code class=\"language-text\">HTMLSourceElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLSpanElement\"><code class=\"language-text\">HTMLSpanElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement\"><code class=\"language-text\">HTMLStyleElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCaptionElement\"><code class=\"language-text\">HTMLTableCaptionElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableCellElement\"><code class=\"language-text\">HTMLTableCellElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableColElement\"><code class=\"language-text\">HTMLTableColElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement\"><code class=\"language-text\">HTMLTableElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableRowElement\"><code class=\"language-text\">HTMLTableRowElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableSectionElement\"><code class=\"language-text\">HTMLTableSectionElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement\"><code class=\"language-text\">HTMLTemplateElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement\"><code class=\"language-text\">HTMLTextAreaElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTimeElement\"><code class=\"language-text\">HTMLTimeElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTitleElement\"><code class=\"language-text\">HTMLTitleElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLTrackElement\"><code class=\"language-text\">HTMLTrackElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLUListElement\"><code class=\"language-text\">HTMLUListElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLUnknownElement\"><code class=\"language-text\">HTMLUnknownElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement\"><code class=\"language-text\">HTMLVideoElement</code></a></li>\n</ul>\n<p>I</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor\"><code class=\"language-text\">IDBCursor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBCursorSync\"><code class=\"language-text\">IDBCursorSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBCursorWithValue\"><code class=\"language-text\">IDBCursorWithValue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase\"><code class=\"language-text\">IDBDatabase</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabaseException\"><code class=\"language-text\">IDBDatabaseException</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabaseSync\"><code class=\"language-text\">IDBDatabaseSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBEnvironmentSync\"><code class=\"language-text\">IDBEnvironmentSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory\"><code class=\"language-text\">IDBFactory</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBFactorySync\"><code class=\"language-text\">IDBFactorySync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBIndex\"><code class=\"language-text\">IDBIndex</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBIndexSync\"><code class=\"language-text\">IDBIndexSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBKeyRange\"><code class=\"language-text\">IDBKeyRange</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBLocaleAwareKeyRange\"><code class=\"language-text\">IDBLocaleAwareKeyRange</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBMutableFile\"><code class=\"language-text\">IDBMutableFile</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore\"><code class=\"language-text\">IDBObjectStore</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStoreSync\"><code class=\"language-text\">IDBObjectStoreSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBOpenDBRequest\"><code class=\"language-text\">IDBOpenDBRequest</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBRequest\"><code class=\"language-text\">IDBRequest</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction\"><code class=\"language-text\">IDBTransaction</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBTransactionSync\"><code class=\"language-text\">IDBTransactionSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IDBVersionChangeEvent\"><code class=\"language-text\">IDBVersionChangeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IdleDeadline\"><code class=\"language-text\">IdleDeadline</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IIRFilterNode\"><code class=\"language-text\">IIRFilterNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap\"><code class=\"language-text\">ImageBitmap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmapRenderingContext\"><code class=\"language-text\">ImageBitmapRenderingContext</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ImageCapture\"><code class=\"language-text\">ImageCapture</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ImageData\"><code class=\"language-text\">ImageData</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ImageDecoder\"><code class=\"language-text\">ImageDecoder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ImageTrack\"><code class=\"language-text\">ImageTrack</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ImageTrackList\"><code class=\"language-text\">ImageTrackList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/indexedDB\"><code class=\"language-text\">indexedDB</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/InputDeviceCapabilities\"><code class=\"language-text\">InputDeviceCapabilities</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/InputDeviceInfo\"><code class=\"language-text\">InputDeviceInfo</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/InputEvent\"><code class=\"language-text\">InputEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/InstallEvent\"><code class=\"language-text\">InstallEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\"><code class=\"language-text\">IntersectionObserver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry\"><code class=\"language-text\">IntersectionObserverEntry</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/InterventionReportBody\"><code class=\"language-text\">InterventionReportBody</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/isSecureContext\"><code class=\"language-text\">isSecureContext</code></a></li>\n</ul>\n<p>K</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Keyboard\"><code class=\"language-text\">Keyboard</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent\"><code class=\"language-text\">KeyboardEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/KeyboardLayoutMap\"><code class=\"language-text\">KeyboardLayoutMap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect\"><code class=\"language-text\">KeyframeEffect</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/KHR_parallel_shader_compile\"><code class=\"language-text\">KHR_parallel_shader_compile</code></a></li>\n</ul>\n<p>L</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/LargestContentfulPaint\"><code class=\"language-text\">LargestContentfulPaint</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift\"><code class=\"language-text\">LayoutShift</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/LayoutShiftAttribution\"><code class=\"language-text\">LayoutShiftAttribution</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/LinearAccelerationSensor\"><code class=\"language-text\">LinearAccelerationSensor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/LocalFileSystem\"><code class=\"language-text\">LocalFileSystem</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/LocalFileSystemSync\"><code class=\"language-text\">LocalFileSystemSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Location\"><code class=\"language-text\">Location</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Lock\"><code class=\"language-text\">Lock</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/LockedFile\"><code class=\"language-text\">LockedFile</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/LockManager\"><code class=\"language-text\">LockManager</code></a></li>\n</ul>\n<p>M</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Magnetometer\"><code class=\"language-text\">Magnetometer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MathMLElement\"><code class=\"language-text\">MathMLElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaCapabilities\"><code class=\"language-text\">MediaCapabilities</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaConfiguration\"><code class=\"language-text\">MediaConfiguration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaDecodingConfiguration\"><code class=\"language-text\">MediaDecodingConfiguration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo\"><code class=\"language-text\">MediaDeviceInfo</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices\"><code class=\"language-text\">MediaDevices</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaElementAudioSourceNode\"><code class=\"language-text\">MediaElementAudioSourceNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaEncodingConfiguration\"><code class=\"language-text\">MediaEncodingConfiguration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaError\"><code class=\"language-text\">MediaError</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaImage\"><code class=\"language-text\">MediaImage</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaKeyMessageEvent\"><code class=\"language-text\">MediaKeyMessageEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaKeys\"><code class=\"language-text\">MediaKeys</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaKeySession\"><code class=\"language-text\">MediaKeySession</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaKeyStatusMap\"><code class=\"language-text\">MediaKeyStatusMap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaKeySystemAccess\"><code class=\"language-text\">MediaKeySystemAccess</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaList\"><code class=\"language-text\">MediaList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata\"><code class=\"language-text\">MediaMetadata</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList\"><code class=\"language-text\">MediaQueryList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryListEvent\"><code class=\"language-text\">MediaQueryListEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder\"><code class=\"language-text\">MediaRecorder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorderErrorEvent\"><code class=\"language-text\">MediaRecorderErrorEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaSession\"><code class=\"language-text\">MediaSession</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaSessionActionDetails\"><code class=\"language-text\">MediaSessionActionDetails</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaSettingsRange\"><code class=\"language-text\">MediaSettingsRange</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaSource\"><code class=\"language-text\">MediaSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStream\"><code class=\"language-text\">MediaStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioDestinationNode\"><code class=\"language-text\">MediaStreamAudioDestinationNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioSourceNode\"><code class=\"language-text\">MediaStreamAudioSourceNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioSourceOptions\"><code class=\"language-text\">MediaStreamAudioSourceOptions</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints\"><code class=\"language-text\">MediaStreamConstraints</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamEvent\"><code class=\"language-text\">MediaStreamEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack\"><code class=\"language-text\">MediaStreamTrack</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackAudioSourceNode\"><code class=\"language-text\">MediaStreamTrackAudioSourceNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackAudioSourceOptions\"><code class=\"language-text\">MediaStreamTrackAudioSourceOptions</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackEvent\"><code class=\"language-text\">MediaStreamTrackEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackGenerator\"><code class=\"language-text\">MediaStreamTrackGenerator</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrackProcessor\"><code class=\"language-text\">MediaStreamTrackProcessor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints\"><code class=\"language-text\">MediaTrackConstraints</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings\"><code class=\"language-text\">MediaTrackSettings</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSupportedConstraints\"><code class=\"language-text\">MediaTrackSupportedConstraints</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MerchantValidationEvent\"><code class=\"language-text\">MerchantValidationEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel\"><code class=\"language-text\">MessageChannel</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent\"><code class=\"language-text\">MessageEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MessagePort\"><code class=\"language-text\">MessagePort</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Metadata\"><code class=\"language-text\">Metadata</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MIDIAccess\"><code class=\"language-text\">MIDIAccess</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MIDIConnectionEvent\"><code class=\"language-text\">MIDIConnectionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MIDIInput\"><code class=\"language-text\">MIDIInput</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MIDIInputMap\"><code class=\"language-text\">MIDIInputMap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MIDIMessageEvent\"><code class=\"language-text\">MIDIMessageEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MIDIOutput\"><code class=\"language-text\">MIDIOutput</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MIDIOutputMap\"><code class=\"language-text\">MIDIOutputMap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MIDIPort\"><code class=\"language-text\">MIDIPort</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MimeType\"><code class=\"language-text\">MimeType</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MimeTypeArray\"><code class=\"language-text\">MimeTypeArray</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent\"><code class=\"language-text\">MouseEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MouseScrollEvent\"><code class=\"language-text\">MouseScrollEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/msCaching\"><code class=\"language-text\">msCaching</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/msCachingEnabled\"><code class=\"language-text\">msCachingEnabled</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MSCandidateWindowHide\"><code class=\"language-text\">MSCandidateWindowHide</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MSCandidateWindowShow\"><code class=\"language-text\">MSCandidateWindowShow</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MSCandidateWindowUpdate\"><code class=\"language-text\">MSCandidateWindowUpdate</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/msCapsLockWarningOff\"><code class=\"language-text\">msCapsLockWarningOff</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsFirstPaint\"><code class=\"language-text\">msFirstPaint</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MSGestureEvent\"><code class=\"language-text\">MSGestureEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/msGetPropertyEnabled\"><code class=\"language-text\">msGetPropertyEnabled</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/msGetRegionContent\"><code class=\"language-text\">msGetRegionContent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MSGraphicsTrust\"><code class=\"language-text\">MSGraphicsTrust</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsGraphicsTrustStatus\"><code class=\"language-text\">msGraphicsTrustStatus</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsIsBoxed\"><code class=\"language-text\">msIsBoxed</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MSManipulationEvent\"><code class=\"language-text\">MSManipulationEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsPlayToDisabled\"><code class=\"language-text\">msPlayToDisabled</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsPlayToPreferredSourceUri\"><code class=\"language-text\">msPlayToPreferredSourceUri</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsPlayToPrimary\"><code class=\"language-text\">msPlayToPrimary</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsPlayToSource\"><code class=\"language-text\">msPlayToSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/msPutPropertyEnabled\"><code class=\"language-text\">msPutPropertyEnabled</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MSRangeCollection\"><code class=\"language-text\">MSRangeCollection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsRealTime\"><code class=\"language-text\">msRealTime</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/msRegionOverflow\"><code class=\"language-text\">msRegionOverflow</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MsSetMediaProtectionManager\"><code class=\"language-text\">msSetMediaProtectionManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MSSiteModeEvent\"><code class=\"language-text\">MSSiteModeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/msWriteProfilerMark\"><code class=\"language-text\">msWriteProfilerMark</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MutationEvent\"><code class=\"language-text\">MutationEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver\"><code class=\"language-text\">MutationObserver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/MutationRecord\"><code class=\"language-text\">MutationRecord</code></a></li>\n</ul>\n<p>N</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NamedNodeMap\"><code class=\"language-text\">NamedNodeMap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NavigationPreloadManager\"><code class=\"language-text\">NavigationPreloadManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Navigator\"><code class=\"language-text\">Navigator</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData\"><code class=\"language-text\">NavigatorUAData</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NDEFMessage\"><code class=\"language-text\">NDEFMessage</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NDEFReader\"><code class=\"language-text\">NDEFReader</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NDEFReadingEvent\"><code class=\"language-text\">NDEFReadingEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NDEFRecord\"><code class=\"language-text\">NDEFRecord</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation\"><code class=\"language-text\">NetworkInformation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Node\"><code class=\"language-text\">Node</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter\"><code class=\"language-text\">NodeFilter</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeIterator\"><code class=\"language-text\">NodeIterator</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeList\"><code class=\"language-text\">NodeList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Notification\"><code class=\"language-text\">Notification</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NotificationAction\"><code class=\"language-text\">NotificationAction</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NotificationEvent\"><code class=\"language-text\">NotificationEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NotifyAudioAvailableEvent\"><code class=\"language-text\">NotifyAudioAvailableEvent</code></a></li>\n</ul>\n<p>O</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OES_element_index_uint\"><code class=\"language-text\">OES_element_index_uint</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OES_fbo_render_mipmap\"><code class=\"language-text\">OES_fbo_render_mipmap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OES_standard_derivatives\"><code class=\"language-text\">OES_standard_derivatives</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OES_texture_float\"><code class=\"language-text\">OES_texture_float</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OES_texture_float_linear\"><code class=\"language-text\">OES_texture_float_linear</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OES_texture_half_float\"><code class=\"language-text\">OES_texture_half_float</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OES_texture_half_float_linear\"><code class=\"language-text\">OES_texture_half_float_linear</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OES_vertex_array_object\"><code class=\"language-text\">OES_vertex_array_object</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioCompletionEvent\"><code class=\"language-text\">OfflineAudioCompletionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OfflineAudioContext\"><code class=\"language-text\">OfflineAudioContext</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas\"><code class=\"language-text\">OffscreenCanvas</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OrientationSensor\"><code class=\"language-text\">OrientationSensor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/origin\"><code class=\"language-text\">origin</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OscillatorNode\"><code class=\"language-text\">OscillatorNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OTPCredential\"><code class=\"language-text\">OTPCredential</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OverconstrainedError\"><code class=\"language-text\">OverconstrainedError</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/OVR_multiview2\"><code class=\"language-text\">OVR_multiview2</code></a></li>\n</ul>\n<p>P</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PageTransitionEvent\"><code class=\"language-text\">PageTransitionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaintWorklet\"><code class=\"language-text\">PaintWorklet</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PannerNode\"><code class=\"language-text\">PannerNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PasswordCredential\"><code class=\"language-text\">PasswordCredential</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Path2D\"><code class=\"language-text\">Path2D</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaymentAddress\"><code class=\"language-text\">PaymentAddress</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaymentItem\"><code class=\"language-text\">PaymentItem</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaymentMethodChangeEvent\"><code class=\"language-text\">PaymentMethodChangeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaymentRequest\"><code class=\"language-text\">PaymentRequest</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaymentRequestEvent\"><code class=\"language-text\">PaymentRequestEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaymentRequestUpdateEvent\"><code class=\"language-text\">PaymentRequestUpdateEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaymentResponse\"><code class=\"language-text\">PaymentResponse</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PaymentValidationErrors\"><code class=\"language-text\">PaymentValidationErrors</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Pbkdf2Params\"><code class=\"language-text\">Pbkdf2Params</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Performance\"><code class=\"language-text\">Performance</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceElementTiming\"><code class=\"language-text\">PerformanceElementTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry\"><code class=\"language-text\">PerformanceEntry</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEventTiming\"><code class=\"language-text\">PerformanceEventTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceLongTaskTiming\"><code class=\"language-text\">PerformanceLongTaskTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMark\"><code class=\"language-text\">PerformanceMark</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceMeasure\"><code class=\"language-text\">PerformanceMeasure</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigation\"><code class=\"language-text\">PerformanceNavigation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming\"><code class=\"language-text\">PerformanceNavigationTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver\"><code class=\"language-text\">PerformanceObserver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserverEntryList\"><code class=\"language-text\">PerformanceObserverEntryList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformancePaintTiming\"><code class=\"language-text\">PerformancePaintTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming\"><code class=\"language-text\">PerformanceResourceTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceServerTiming\"><code class=\"language-text\">PerformanceServerTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming\"><code class=\"language-text\">PerformanceTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PeriodicSyncEvent\"><code class=\"language-text\">PeriodicSyncEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PeriodicSyncManager\"><code class=\"language-text\">PeriodicSyncManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PeriodicWave\"><code class=\"language-text\">PeriodicWave</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Permissions\"><code class=\"language-text\">Permissions</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PermissionStatus\"><code class=\"language-text\">PermissionStatus</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PhotoCapabilities\"><code class=\"language-text\">PhotoCapabilities</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PictureInPictureEvent\"><code class=\"language-text\">PictureInPictureEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PictureInPictureWindow\"><code class=\"language-text\">PictureInPictureWindow</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Plugin\"><code class=\"language-text\">Plugin</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PluginArray\"><code class=\"language-text\">PluginArray</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebKitPoint\"><code class=\"language-text\">Point</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent\"><code class=\"language-text\">PointerEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PopStateEvent\"><code class=\"language-text\">PopStateEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PositionSensorVRDevice\"><code class=\"language-text\">PositionSensorVRDevice</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Presentation\"><code class=\"language-text\">Presentation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PresentationAvailability\"><code class=\"language-text\">PresentationAvailability</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PresentationConnection\"><code class=\"language-text\">PresentationConnection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PresentationConnectionAvailableEvent\"><code class=\"language-text\">PresentationConnectionAvailableEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PresentationConnectionCloseEvent\"><code class=\"language-text\">PresentationConnectionCloseEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PresentationConnectionList\"><code class=\"language-text\">PresentationConnectionList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PresentationReceiver\"><code class=\"language-text\">PresentationReceiver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PresentationRequest\"><code class=\"language-text\">PresentationRequest</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ProcessingInstruction\"><code class=\"language-text\">ProcessingInstruction</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent\"><code class=\"language-text\">ProgressEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent\"><code class=\"language-text\">PromiseRejectionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredential\"><code class=\"language-text\">PublicKeyCredential</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialRequestOptions\"><code class=\"language-text\">PublicKeyCredentialRequestOptions</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PushEvent\"><code class=\"language-text\">PushEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PushManager\"><code class=\"language-text\">PushManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PushMessageData\"><code class=\"language-text\">PushMessageData</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PushSubscription\"><code class=\"language-text\">PushSubscription</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/PushSubscriptionOptions\"><code class=\"language-text\">PushSubscriptionOptions</code></a></li>\n</ul>\n<p>Q</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask\"><code class=\"language-text\">queueMicrotask()</code></a></li>\n</ul>\n<p>R</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RadioNodeList\"><code class=\"language-text\">RadioNodeList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Range\"><code class=\"language-text\">Range</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReadableByteStreamController\"><code class=\"language-text\">ReadableByteStreamController</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\"><code class=\"language-text\">ReadableStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader\"><code class=\"language-text\">ReadableStreamBYOBReader</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBRequest\"><code class=\"language-text\">ReadableStreamBYOBRequest</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultController\"><code class=\"language-text\">ReadableStreamDefaultController</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\"><code class=\"language-text\">ReadableStreamDefaultReader</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RelativeOrientationSensor\"><code class=\"language-text\">RelativeOrientationSensor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RemotePlayback\"><code class=\"language-text\">RemotePlayback</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Report\"><code class=\"language-text\">Report</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReportBody\"><code class=\"language-text\">ReportBody</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/reportError\"><code class=\"language-text\">reportError()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReportingObserver\"><code class=\"language-text\">ReportingObserver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReportingObserverOptions\"><code class=\"language-text\">ReportingObserverOptions</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Request\"><code class=\"language-text\">Request</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver\"><code class=\"language-text\">ResizeObserver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry\"><code class=\"language-text\">ResizeObserverEntry</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverSize\"><code class=\"language-text\">ResizeObserverSize</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Response\"><code class=\"language-text\">Response</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedImportParams\"><code class=\"language-text\">RsaHashedImportParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RsaHashedKeyGenParams\"><code class=\"language-text\">RsaHashedKeyGenParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RsaOaepParams\"><code class=\"language-text\">RsaOaepParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RsaPssParams\"><code class=\"language-text\">RsaPssParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCAnswerOptions\"><code class=\"language-text\">RTCAnswerOptions</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCCertificate\"><code class=\"language-text\">RTCCertificate</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel\"><code class=\"language-text\">RTCDataChannel</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannelEvent\"><code class=\"language-text\">RTCDataChannelEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCDtlsTransport\"><code class=\"language-text\">RTCDtlsTransport</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCDTMFSender\"><code class=\"language-text\">RTCDTMFSender</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCDTMFToneChangeEvent\"><code class=\"language-text\">RTCDTMFToneChangeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCError\"><code class=\"language-text\">RTCError</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCErrorEvent\"><code class=\"language-text\">RTCErrorEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate\"><code class=\"language-text\">RTCIceCandidate</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidatePair\"><code class=\"language-text\">RTCIceCandidatePair</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidatePairStats\"><code class=\"language-text\">RTCIceCandidatePairStats</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidateStats\"><code class=\"language-text\">RTCIceCandidateStats</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCredentialType\"><code class=\"language-text\">RTCIceCredentialType</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceParameters\"><code class=\"language-text\">RTCIceParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceRole\"><code class=\"language-text\">RTCIceRole</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer\"><code class=\"language-text\">RTCIceServer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransport\"><code class=\"language-text\">RTCIceTransport</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIceTransportState\"><code class=\"language-text\">RTCIceTransportState</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCIdentityAssertion\"><code class=\"language-text\">RTCIdentityAssertion</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCInboundRtpStreamStats\"><code class=\"language-text\">RTCInboundRtpStreamStats</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCNetworkType\"><code class=\"language-text\">RTCNetworkType</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCOfferAnswerOptions\"><code class=\"language-text\">RTCOfferAnswerOptions</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCOfferOptions\"><code class=\"language-text\">RTCOfferOptions</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCOutboundRtpStreamStats\"><code class=\"language-text\">RTCOutboundRtpStreamStats</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection\"><code class=\"language-text\">RTCPeerConnection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnectionIceErrorEvent\"><code class=\"language-text\">RTCPeerConnectionIceErrorEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnectionIceEvent\"><code class=\"language-text\">RTCPeerConnectionIceEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRemoteOutboundRtpStreamStats\"><code class=\"language-text\">RTCRemoteOutboundRtpStreamStats</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtcpParameters\"><code class=\"language-text\">RTCRtcpParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpCapabilities\"><code class=\"language-text\">RTCRtpCapabilities</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpCodecCapability\"><code class=\"language-text\">RTCRtpCodecCapability</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpCodecParameters\"><code class=\"language-text\">RTCRtpCodecParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpContributingSource\"><code class=\"language-text\">RTCRtpContributingSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpEncodingParameters\"><code class=\"language-text\">RTCRtpEncodingParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpParameters\"><code class=\"language-text\">RTCRtpParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpReceiveParameters\"><code class=\"language-text\">RTCRtpReceiveParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpReceiver\"><code class=\"language-text\">RTCRtpReceiver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender\"><code class=\"language-text\">RTCRtpSender</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSendParameters\"><code class=\"language-text\">RTCRtpSendParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpStreamStats\"><code class=\"language-text\">RTCRtpStreamStats</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSynchronizationSource\"><code class=\"language-text\">RTCRtpSynchronizationSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpTransceiver\"><code class=\"language-text\">RTCRtpTransceiver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpTransceiverDirection\"><code class=\"language-text\">RTCRtpTransceiverDirection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCSctpTransport\"><code class=\"language-text\">RTCSctpTransport</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCSessionDescription\"><code class=\"language-text\">RTCSessionDescription</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCStats\"><code class=\"language-text\">RTCStats</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsIceCandidatePairState\"><code class=\"language-text\">RTCStatsIceCandidatePairState</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsReport\"><code class=\"language-text\">RTCStatsReport</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCStatsType\"><code class=\"language-text\">RTCStatsType</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCTrackEvent\"><code class=\"language-text\">RTCTrackEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/RTCTrackEventInit\"><code class=\"language-text\">RTCTrackEventInit</code></a></li>\n</ul>\n<p>S</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Sanitizer\"><code class=\"language-text\">Sanitizer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Screen\"><code class=\"language-text\">Screen</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation\"><code class=\"language-text\">ScreenOrientation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode\"><code class=\"language-text\">ScriptProcessorNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SecurityPolicyViolationEvent\"><code class=\"language-text\">SecurityPolicyViolationEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Selection\"><code class=\"language-text\">Selection</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/crypto_property\"><code class=\"language-text\">self.crypto</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/performance_property\"><code class=\"language-text\">self.performance</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Sensor\"><code class=\"language-text\">Sensor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SensorErrorEvent\"><code class=\"language-text\">SensorErrorEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Serial\"><code class=\"language-text\">Serial</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SerialPort\"><code class=\"language-text\">SerialPort</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker\"><code class=\"language-text\">ServiceWorker</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer\"><code class=\"language-text\">ServiceWorkerContainer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope\"><code class=\"language-text\">ServiceWorkerGlobalScope</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerMessageEvent\"><code class=\"language-text\">ServiceWorkerMessageEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration\"><code class=\"language-text\">ServiceWorkerRegistration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/setInterval\"><code class=\"language-text\">setInterval()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/setTimeout\"><code class=\"language-text\">setTimeout()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ShadowRoot\"><code class=\"language-text\">ShadowRoot</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker\"><code class=\"language-text\">SharedWorker</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SharedWorkerGlobalScope\"><code class=\"language-text\">SharedWorkerGlobalScope</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SourceBuffer\"><code class=\"language-text\">SourceBuffer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SourceBufferList\"><code class=\"language-text\">SourceBufferList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechGrammar\"><code class=\"language-text\">SpeechGrammar</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechGrammarList\"><code class=\"language-text\">SpeechGrammarList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition\"><code class=\"language-text\">SpeechRecognition</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionAlternative\"><code class=\"language-text\">SpeechRecognitionAlternative</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionError\"><code class=\"language-text\">SpeechRecognitionError</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionErrorEvent\"><code class=\"language-text\">SpeechRecognitionErrorEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionEvent\"><code class=\"language-text\">SpeechRecognitionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionResult\"><code class=\"language-text\">SpeechRecognitionResult</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognitionResultList\"><code class=\"language-text\">SpeechRecognitionResultList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis\"><code class=\"language-text\">SpeechSynthesis</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisErrorEvent\"><code class=\"language-text\">SpeechSynthesisErrorEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisEvent\"><code class=\"language-text\">SpeechSynthesisEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance\"><code class=\"language-text\">SpeechSynthesisUtterance</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisVoice\"><code class=\"language-text\">SpeechSynthesisVoice</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StaticRange\"><code class=\"language-text\">StaticRange</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StereoPannerNode\"><code class=\"language-text\">StereoPannerNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Storage\"><code class=\"language-text\">Storage</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent\"><code class=\"language-text\">StorageEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StorageManager\"><code class=\"language-text\">StorageManager</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/structuredClone\"><code class=\"language-text\">structuredClone()</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StylePropertyMap\"><code class=\"language-text\">StylePropertyMap</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StylePropertyMapReadOnly\"><code class=\"language-text\">StylePropertyMapReadOnly</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StyleSheet\"><code class=\"language-text\">StyleSheet</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/StyleSheetList\"><code class=\"language-text\">StyleSheetList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SubmitEvent\"><code class=\"language-text\">SubmitEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto\"><code class=\"language-text\">SubtleCrypto</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAElement\"><code class=\"language-text\">SVGAElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAltGlyphDefElement\"><code class=\"language-text\">SVGAltGlyphDefElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAltGlyphElement\"><code class=\"language-text\">SVGAltGlyphElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAltGlyphItemElement\"><code class=\"language-text\">SVGAltGlyphItemElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAngle\"><code class=\"language-text\">SVGAngle</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimateColorElement\"><code class=\"language-text\">SVGAnimateColorElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedAngle\"><code class=\"language-text\">SVGAnimatedAngle</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedBoolean\"><code class=\"language-text\">SVGAnimatedBoolean</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedEnumeration\"><code class=\"language-text\">SVGAnimatedEnumeration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedInteger\"><code class=\"language-text\">SVGAnimatedInteger</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedLength\"><code class=\"language-text\">SVGAnimatedLength</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedLengthList\"><code class=\"language-text\">SVGAnimatedLengthList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedNumber\"><code class=\"language-text\">SVGAnimatedNumber</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedNumberList\"><code class=\"language-text\">SVGAnimatedNumberList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedPreserveAspectRatio\"><code class=\"language-text\">SVGAnimatedPreserveAspectRatio</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedRect\"><code class=\"language-text\">SVGAnimatedRect</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedString\"><code class=\"language-text\">SVGAnimatedString</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimatedTransformList\"><code class=\"language-text\">SVGAnimatedTransformList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimateElement\"><code class=\"language-text\">SVGAnimateElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimateMotionElement\"><code class=\"language-text\">SVGAnimateMotionElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimateTransformElement\"><code class=\"language-text\">SVGAnimateTransformElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimationElement\"><code class=\"language-text\">SVGAnimationElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGCircleElement\"><code class=\"language-text\">SVGCircleElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGClipPathElement\"><code class=\"language-text\">SVGClipPathElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGComponentTransferFunctionElement\"><code class=\"language-text\">SVGComponentTransferFunctionElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGCursorElement\"><code class=\"language-text\">SVGCursorElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGDefsElement\"><code class=\"language-text\">SVGDefsElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGDescElement\"><code class=\"language-text\">SVGDescElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGElement\"><code class=\"language-text\">SVGElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGEllipseElement\"><code class=\"language-text\">SVGEllipseElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGEvent\"><code class=\"language-text\">SVGEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEBlendElement\"><code class=\"language-text\">SVGFEBlendElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEColorMatrixElement\"><code class=\"language-text\">SVGFEColorMatrixElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEComponentTransferElement\"><code class=\"language-text\">SVGFEComponentTransferElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFECompositeElement\"><code class=\"language-text\">SVGFECompositeElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEConvolveMatrixElement\"><code class=\"language-text\">SVGFEConvolveMatrixElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEDiffuseLightingElement\"><code class=\"language-text\">SVGFEDiffuseLightingElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEDisplacementMapElement\"><code class=\"language-text\">SVGFEDisplacementMapElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEDistantLightElement\"><code class=\"language-text\">SVGFEDistantLightElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEDropShadowElement\"><code class=\"language-text\">SVGFEDropShadowElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEFloodElement\"><code class=\"language-text\">SVGFEFloodElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEFuncAElement\"><code class=\"language-text\">SVGFEFuncAElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEFuncBElement\"><code class=\"language-text\">SVGFEFuncBElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEFuncGElement\"><code class=\"language-text\">SVGFEFuncGElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEFuncRElement\"><code class=\"language-text\">SVGFEFuncRElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEGaussianBlurElement\"><code class=\"language-text\">SVGFEGaussianBlurElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEImageElement\"><code class=\"language-text\">SVGFEImageElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEMergeElement\"><code class=\"language-text\">SVGFEMergeElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEMergeNodeElement\"><code class=\"language-text\">SVGFEMergeNodeElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEMorphologyElement\"><code class=\"language-text\">SVGFEMorphologyElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEOffsetElement\"><code class=\"language-text\">SVGFEOffsetElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFEPointLightElement\"><code class=\"language-text\">SVGFEPointLightElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFESpecularLightingElement\"><code class=\"language-text\">SVGFESpecularLightingElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFESpotLightElement\"><code class=\"language-text\">SVGFESpotLightElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFETileElement\"><code class=\"language-text\">SVGFETileElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFETurbulenceElement\"><code class=\"language-text\">SVGFETurbulenceElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFilterElement\"><code class=\"language-text\">SVGFilterElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFontElement\"><code class=\"language-text\">SVGFontElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFontFaceElement\"><code class=\"language-text\">SVGFontFaceElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFontFaceFormatElement\"><code class=\"language-text\">SVGFontFaceFormatElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFontFaceNameElement\"><code class=\"language-text\">SVGFontFaceNameElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFontFaceSrcElement\"><code class=\"language-text\">SVGFontFaceSrcElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGFontFaceUriElement\"><code class=\"language-text\">SVGFontFaceUriElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGForeignObjectElement\"><code class=\"language-text\">SVGForeignObjectElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGGElement\"><code class=\"language-text\">SVGGElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement\"><code class=\"language-text\">SVGGeometryElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGGlyphElement\"><code class=\"language-text\">SVGGlyphElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGGlyphRefElement\"><code class=\"language-text\">SVGGlyphRefElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGGradientElement\"><code class=\"language-text\">SVGGradientElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGGraphicsElement\"><code class=\"language-text\">SVGGraphicsElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGHKernElement\"><code class=\"language-text\">SVGHKernElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGImageElement\"><code class=\"language-text\">SVGImageElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGLength\"><code class=\"language-text\">SVGLength</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGLengthList\"><code class=\"language-text\">SVGLengthList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGLinearGradientElement\"><code class=\"language-text\">SVGLinearGradientElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGLineElement\"><code class=\"language-text\">SVGLineElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGMarkerElement\"><code class=\"language-text\">SVGMarkerElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGMaskElement\"><code class=\"language-text\">SVGMaskElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGMatrix\"><code class=\"language-text\">SVGMatrix</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGMetadataElement\"><code class=\"language-text\">SVGMetadataElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGMissingGlyphElement\"><code class=\"language-text\">SVGMissingGlyphElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGMPathElement\"><code class=\"language-text\">SVGMPathElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGNumber\"><code class=\"language-text\">SVGNumber</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGNumberList\"><code class=\"language-text\">SVGNumberList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGPathElement\"><code class=\"language-text\">SVGPathElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGPatternElement\"><code class=\"language-text\">SVGPatternElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGPoint\"><code class=\"language-text\">SVGPoint</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGPointList\"><code class=\"language-text\">SVGPointList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGPolygonElement\"><code class=\"language-text\">SVGPolygonElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGPolylineElement\"><code class=\"language-text\">SVGPolylineElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGPreserveAspectRatio\"><code class=\"language-text\">SVGPreserveAspectRatio</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGRadialGradientElement\"><code class=\"language-text\">SVGRadialGradientElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGRect\"><code class=\"language-text\">SVGRect</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGRectElement\"><code class=\"language-text\">SVGRectElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGRenderingIntent\"><code class=\"language-text\">SVGRenderingIntent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGScriptElement\"><code class=\"language-text\">SVGScriptElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGSetElement\"><code class=\"language-text\">SVGSetElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGStopElement\"><code class=\"language-text\">SVGStopElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGStringList\"><code class=\"language-text\">SVGStringList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGStyleElement\"><code class=\"language-text\">SVGStyleElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGSVGElement\"><code class=\"language-text\">SVGSVGElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGSwitchElement\"><code class=\"language-text\">SVGSwitchElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGSymbolElement\"><code class=\"language-text\">SVGSymbolElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTextContentElement\"><code class=\"language-text\">SVGTextContentElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTextElement\"><code class=\"language-text\">SVGTextElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTextPathElement\"><code class=\"language-text\">SVGTextPathElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTextPositioningElement\"><code class=\"language-text\">SVGTextPositioningElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTitleElement\"><code class=\"language-text\">SVGTitleElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTransform\"><code class=\"language-text\">SVGTransform</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTransformList\"><code class=\"language-text\">SVGTransformList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTRefElement\"><code class=\"language-text\">SVGTRefElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGTSpanElement\"><code class=\"language-text\">SVGTSpanElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGUnitTypes\"><code class=\"language-text\">SVGUnitTypes</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGUseElement\"><code class=\"language-text\">SVGUseElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGViewElement\"><code class=\"language-text\">SVGViewElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SVGVKernElement\"><code class=\"language-text\">SVGVKernElement</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SyncEvent\"><code class=\"language-text\">SyncEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/SyncManager\"><code class=\"language-text\">SyncManager</code></a></li>\n</ul>\n<p>T</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TaskAttributionTiming\"><code class=\"language-text\">TaskAttributionTiming</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Text\"><code class=\"language-text\">Text</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder\"><code class=\"language-text\">TextDecoder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextDecoderStream\"><code class=\"language-text\">TextDecoderStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder\"><code class=\"language-text\">TextEncoder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextEncoderStream\"><code class=\"language-text\">TextEncoderStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics\"><code class=\"language-text\">TextMetrics</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextTrack\"><code class=\"language-text\">TextTrack</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextTrackCue\"><code class=\"language-text\">TextTrackCue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextTrackCueList\"><code class=\"language-text\">TextTrackCueList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TextTrackList\"><code class=\"language-text\">TextTrackList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TimeEvent\"><code class=\"language-text\">TimeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TimeRanges\"><code class=\"language-text\">TimeRanges</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Touch\"><code class=\"language-text\">Touch</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent\"><code class=\"language-text\">TouchEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TouchList\"><code class=\"language-text\">TouchList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TrackEvent\"><code class=\"language-text\">TrackEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\"><code class=\"language-text\">TransformStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TransformStreamDefaultController\"><code class=\"language-text\">TransformStreamDefaultController</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent\"><code class=\"language-text\">TransitionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker\"><code class=\"language-text\">TreeWalker</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TrustedHTML\"><code class=\"language-text\">TrustedHTML</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TrustedScript\"><code class=\"language-text\">TrustedScript</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TrustedScriptURL\"><code class=\"language-text\">TrustedScriptURL</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy\"><code class=\"language-text\">TrustedTypePolicy</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicyFactory\"><code class=\"language-text\">TrustedTypePolicyFactory</code></a></li>\n</ul>\n<p>U</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/UIEvent\"><code class=\"language-text\">UIEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/URL\"><code class=\"language-text\">URL</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/URLPattern\"><code class=\"language-text\">URLPattern</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\"><code class=\"language-text\">URLSearchParams</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USB\"><code class=\"language-text\">USB</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBAlternateInterface\"><code class=\"language-text\">USBAlternateInterface</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBConfiguration\"><code class=\"language-text\">USBConfiguration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBConnectionEvent\"><code class=\"language-text\">USBConnectionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBDevice\"><code class=\"language-text\">USBDevice</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBEndpoint\"><code class=\"language-text\">USBEndpoint</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBInterface\"><code class=\"language-text\">USBInterface</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBInTransferResult\"><code class=\"language-text\">USBInTransferResult</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBIsochronousInTransferPacket\"><code class=\"language-text\">USBIsochronousInTransferPacket</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBIsochronousInTransferResult\"><code class=\"language-text\">USBIsochronousInTransferResult</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBIsochronousOutTransferPacket\"><code class=\"language-text\">USBIsochronousOutTransferPacket</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBIsochronousOutTransferResult\"><code class=\"language-text\">USBIsochronousOutTransferResult</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USBOutTransferResult\"><code class=\"language-text\">USBOutTransferResult</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/UserProximityEvent\"><code class=\"language-text\">UserProximityEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/USVString\"><code class=\"language-text\">USVString</code></a></li>\n</ul>\n<p>V</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ValidityState\"><code class=\"language-text\">ValidityState</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VideoColorSpace\"><code class=\"language-text\">VideoColorSpace</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VideoConfiguration\"><code class=\"language-text\">VideoConfiguration</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VideoDecoder\"><code class=\"language-text\">VideoDecoder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VideoEncoder\"><code class=\"language-text\">VideoEncoder</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame\"><code class=\"language-text\">VideoFrame</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VideoPlaybackQuality\"><code class=\"language-text\">VideoPlaybackQuality</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VideoTrack\"><code class=\"language-text\">VideoTrack</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VideoTrackList\"><code class=\"language-text\">VideoTrackList</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport\"><code class=\"language-text\">VisualViewport</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay\"><code class=\"language-text\">VRDisplay</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VRDisplayCapabilities\"><code class=\"language-text\">VRDisplayCapabilities</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VRDisplayEvent\"><code class=\"language-text\">VRDisplayEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VREyeParameters\"><code class=\"language-text\">VREyeParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VRFieldOfView\"><code class=\"language-text\">VRFieldOfView</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VRFrameData\"><code class=\"language-text\">VRFrameData</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VRLayerInit\"><code class=\"language-text\">VRLayerInit</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VRPose\"><code class=\"language-text\">VRPose</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VRStageParameters\"><code class=\"language-text\">VRStageParameters</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VTTCue\"><code class=\"language-text\">VTTCue</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/VTTRegion\"><code class=\"language-text\">VTTRegion</code></a></li>\n</ul>\n<p>W</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WakeLock\"><code class=\"language-text\">WakeLock</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WakeLockSentinel\"><code class=\"language-text\">WakeLockSentinel</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WaveShaperNode\"><code class=\"language-text\">WaveShaperNode</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_color_buffer_float\"><code class=\"language-text\">WEBGL_color_buffer_float</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_compressed_texture_astc\"><code class=\"language-text\">WEBGL_compressed_texture_astc</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_compressed_texture_etc\"><code class=\"language-text\">WEBGL_compressed_texture_etc</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_compressed_texture_etc1\"><code class=\"language-text\">WEBGL_compressed_texture_etc1</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_compressed_texture_pvrtc\"><code class=\"language-text\">WEBGL_compressed_texture_pvrtc</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_compressed_texture_s3tc\"><code class=\"language-text\">WEBGL_compressed_texture_s3tc</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_compressed_texture_s3tc_srgb\"><code class=\"language-text\">WEBGL_compressed_texture_s3tc_srgb</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_debug_renderer_info\"><code class=\"language-text\">WEBGL_debug_renderer_info</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_debug_shaders\"><code class=\"language-text\">WEBGL_debug_shaders</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_depth_texture\"><code class=\"language-text\">WEBGL_depth_texture</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_draw_buffers\"><code class=\"language-text\">WEBGL_draw_buffers</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context\"><code class=\"language-text\">WEBGL_lose_context</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_multi_draw\"><code class=\"language-text\">WEBGL_multi_draw</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext\"><code class=\"language-text\">WebGL2RenderingContext</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLActiveInfo\"><code class=\"language-text\">WebGLActiveInfo</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLBuffer\"><code class=\"language-text\">WebGLBuffer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLContextEvent\"><code class=\"language-text\">WebGLContextEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLFramebuffer\"><code class=\"language-text\">WebGLFramebuffer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLProgram\"><code class=\"language-text\">WebGLProgram</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLQuery\"><code class=\"language-text\">WebGLQuery</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderbuffer\"><code class=\"language-text\">WebGLRenderbuffer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext\"><code class=\"language-text\">WebGLRenderingContext</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLSampler\"><code class=\"language-text\">WebGLSampler</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLShader\"><code class=\"language-text\">WebGLShader</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLShaderPrecisionFormat\"><code class=\"language-text\">WebGLShaderPrecisionFormat</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLSync\"><code class=\"language-text\">WebGLSync</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLTexture\"><code class=\"language-text\">WebGLTexture</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLTransformFeedback\"><code class=\"language-text\">WebGLTransformFeedback</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLUniformLocation\"><code class=\"language-text\">WebGLUniformLocation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebGLVertexArrayObject\"><code class=\"language-text\">WebGLVertexArrayObject</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebSocket\"><code class=\"language-text\">WebSocket</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent\"><code class=\"language-text\">WheelEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window\"><code class=\"language-text\">Window</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowClient\"><code class=\"language-text\">WindowClient</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers\"><code class=\"language-text\">WindowEventHandlers</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Worker\"><code class=\"language-text\">Worker</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope\"><code class=\"language-text\">WorkerGlobalScope</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WorkerLocation\"><code class=\"language-text\">WorkerLocation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WorkerNavigator\"><code class=\"language-text\">WorkerNavigator</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Worklet\"><code class=\"language-text\">Worklet</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\"><code class=\"language-text\">WritableStream</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultController\"><code class=\"language-text\">WritableStreamDefaultController</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\"><code class=\"language-text\">WritableStreamDefaultWriter</code></a></li>\n</ul>\n<p>X</p>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLDocument\"><code class=\"language-text\">XMLDocument</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest\"><code class=\"language-text\">XMLHttpRequest</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget\"><code class=\"language-text\">XMLHttpRequestEventTarget</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLSerializer\"><code class=\"language-text\">XMLSerializer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XPathEvaluator\"><code class=\"language-text\">XPathEvaluator</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XPathException\"><code class=\"language-text\">XPathException</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XPathExpression\"><code class=\"language-text\">XPathExpression</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XPathNSResolver\"><code class=\"language-text\">XPathNSResolver</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XPathResult\"><code class=\"language-text\">XPathResult</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRAnchor\"><code class=\"language-text\">XRAnchor</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRAnchorSet\"><code class=\"language-text\">XRAnchorSet</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRBoundedReferenceSpace\"><code class=\"language-text\">XRBoundedReferenceSpace</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRCompositionLayer\"><code class=\"language-text\">XRCompositionLayer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRCPUDepthInformation\"><code class=\"language-text\">XRCPUDepthInformation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRCubeLayer\"><code class=\"language-text\">XRCubeLayer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRCylinderLayer\"><code class=\"language-text\">XRCylinderLayer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRDepthInformation\"><code class=\"language-text\">XRDepthInformation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XREquirectLayer\"><code class=\"language-text\">XREquirectLayer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRFrame\"><code class=\"language-text\">XRFrame</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRHand\"><code class=\"language-text\">XRHand</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRHitTestResult\"><code class=\"language-text\">XRHitTestResult</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRHitTestSource\"><code class=\"language-text\">XRHitTestSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRInputSource\"><code class=\"language-text\">XRInputSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourceArray\"><code class=\"language-text\">XRInputSourceArray</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourceEvent\"><code class=\"language-text\">XRInputSourceEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRInputSourcesChangeEvent\"><code class=\"language-text\">XRInputSourcesChangeEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRJointPose\"><code class=\"language-text\">XRJointPose</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRJointSpace\"><code class=\"language-text\">XRJointSpace</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRLayer\"><code class=\"language-text\">XRLayer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRLayerEvent\"><code class=\"language-text\">XRLayerEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRLightEstimate\"><code class=\"language-text\">XRLightEstimate</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRLightProbe\"><code class=\"language-text\">XRLightProbe</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRMediaBinding\"><code class=\"language-text\">XRMediaBinding</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRPermissionStatus\"><code class=\"language-text\">XRPermissionStatus</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRPose\"><code class=\"language-text\">XRPose</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRProjectionLayer\"><code class=\"language-text\">XRProjectionLayer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRQuadLayer\"><code class=\"language-text\">XRQuadLayer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRRay\"><code class=\"language-text\">XRRay</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRReferenceSpace\"><code class=\"language-text\">XRReferenceSpace</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRReferenceSpaceEvent\"><code class=\"language-text\">XRReferenceSpaceEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRRenderState\"><code class=\"language-text\">XRRenderState</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRRigidTransform\"><code class=\"language-text\">XRRigidTransform</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRSession\"><code class=\"language-text\">XRSession</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRSessionEvent\"><code class=\"language-text\">XRSessionEvent</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRSpace\"><code class=\"language-text\">XRSpace</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRSubImage\"><code class=\"language-text\">XRSubImage</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRSystem\"><code class=\"language-text\">XRSystem</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRTransientInputHitTestResult\"><code class=\"language-text\">XRTransientInputHitTestResult</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRTransientInputHitTestSource\"><code class=\"language-text\">XRTransientInputHitTestSource</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRView\"><code class=\"language-text\">XRView</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRViewerPose\"><code class=\"language-text\">XRViewerPose</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRViewport\"><code class=\"language-text\">XRViewport</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRWebGLBinding\"><code class=\"language-text\">XRWebGLBinding</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRWebGLDepthInformation\"><code class=\"language-text\">XRWebGLDepthInformation</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRWebGLLayer\"><code class=\"language-text\">XRWebGLLayer</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XRWebGLSubImage\"><code class=\"language-text\">XRWebGLSubImage</code></a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XSLTProcessor\"><code class=\"language-text\">XSLTProcessor</code></a></li>\n</ul>"},{"url":"/docs/ds-algo/data-structures-cheat-sheet/","relativePath":"docs/ds-algo/data-structures-cheat-sheet/index.md","relativeDir":"docs/ds-algo/data-structures-cheat-sheet","base":"index.md","name":"index","frontmatter":{"title":"Data Structures Cheat Sheet","template":"docs","excerpt":"Its always good to have a look at worst-case time complexities of common data structure operations frequently."},"html":"<h1></h1>\n<p><img src=\"ds-cheat-sheet-operations.png\" alt=\"image\"></p>\n<blockquote>\n<p>Its always good to have a look at worst-case time complexities of common data structure operations frequently.</p>\n</blockquote>\n<p>Its always good to have a look at worst-case time complexities of common data structure operations frequently.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*6NpRbTpekXG_1l5hh1XeIQ.png?q=20\" alt=\"Image for post\"></p>\n<p><img src=\"https://miro.medium.com/max/3572/1*6NpRbTpekXG_1l5hh1XeIQ.png\" alt=\"Image for post\"></p>\n<p>Arrays are one of the basic and important data structures to learn, They take constant time to read and Insert elements at the end and takes a linear time for the remaining.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*vFbcvaNX-aWr5-wERwKFIA.png?q=20\" alt=\"Image for post\"></p>\n<p><img src=\"https://miro.medium.com/max/3746/1*vFbcvaNX-aWr5-wERwKFIA.png\" alt=\"Image for post\"></p>\n<p>Stack takes constant time for Push, Pop &#x26; Peek operations.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*HgkpbE06UCWm2G3U54J8ew.png?q=20\" alt=\"Image for post\"></p>\n<p><img src=\"https://miro.medium.com/max/2512/1*HgkpbE06UCWm2G3U54J8ew.png\" alt=\"Image for post\"></p>\n<p>In Queue for Enqueue, Dequeue &#x26; Peek operations it takes only Constant time.</p>\n<p><img src=\"https://miro.medium.com/max/60/1*amq4OYYapQjaN2QXIG5eUw.png?q=20\" alt=\"Image for post\"></p>\n<p><img src=\"https://miro.medium.com/max/3942/1*amq4OYYapQjaN2QXIG5eUw.png\" alt=\"Image for post\"></p>\n<p>Here we are considering we are using tails for all single linked lists (Some implementations might not have it).\nLinked List is the data structure that comes with a lot of different operational scenarios, we have to think about head &#x26; tail usage in every operation we are doing. And operation logic and complexity changes at the head, tail, and middle. Typically insertion at head &#x26; tail takes constant time and insertion in middle takes linear time. Search can take linear time. Deletion at the head takes constant time and it can take linear time in remaining scenarios.</p>\n<hr>\n<h2><a href=\"#Trees-basic-concepts\" title=\"Trees: basic concepts\"></a>Trees: basic concepts</h2>\n<p>A tree is a data structure where a node can have zero or more children. Each node contains a <strong>value</strong>. Like graphs, the connection between nodes is called <strong>edges</strong>. A tree is a type of graph, but not all of them are trees (more on that later).</p>\n<p>These data structures are called \"trees\" because the data structure resembles a tree 🌳. It starts with a <strong>root</strong> node and <strong>branch</strong> off with its descendants, and finally, there are <strong>leaves</strong>.</p>\n<p><img src=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/images/tree-parts.jpg\" alt=\"image\"></p>\n<p>Here are some properties of trees:</p>\n<ul>\n<li>The top-most node is called <strong>root</strong>.</li>\n<li>A node without children is called <strong>leaf</strong> node or <strong>terminal</strong> node.</li>\n<li>\n<p><strong>Height</strong> (<em>h</em>) of the tree is the distance (edge count) between the farthest leaf to the root.</p>\n<ul>\n<li><code class=\"language-text\">A</code> has a height of 3</li>\n<li><code class=\"language-text\">I</code> has a height of 0</li>\n</ul>\n</li>\n<li>\n<p><strong>Depth</strong> or <strong>level</strong> of a node is the distance between the root and the node in question.</p>\n<ul>\n<li><code class=\"language-text\">H</code> has a depth of 2</li>\n<li><code class=\"language-text\">B</code> has a depth of 1</li>\n</ul>\n</li>\n</ul>\n<h3><a href=\"#Implementing-a-simple-tree-data-structure\" title=\"Implementing a simple tree data structure\"></a>Implementing a simple tree data structure</h3>\n<p>As we saw earlier, a tree node is just a data structure that has a value and has links to their descendants.</p>\n<p>Here's an example of a tree node:</p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br></pre></td><td><pre><span><span><span>class</span> <span>TreeNode</span> </span>{</span><br><span>  <span>constructor</span>(value) {</span><br><span>    <span>this</span>.value = value;</span><br><span>    <span>this</span>.descendents = [];</span><br><span>  }</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>We can create a tree with 3 descendents as follows:</p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br><span>9</span><br><span>10</span><br></pre></td><td><pre><span></span><br><span><span>const</span> abe = <span>new</span> TreeNode(<span>'Abe'</span>);</span><br><span><span>const</span> homer = <span>new</span> TreeNode(<span>'Homer'</span>);</span><br><span><span>const</span> bart = <span>new</span> TreeNode(<span>'Bart'</span>);</span><br><span><span>const</span> lisa = <span>new</span> TreeNode(<span>'Lisa'</span>);</span><br><span><span>const</span> maggie = <span>new</span> TreeNode(<span>'Maggie'</span>);</span><br><span></span><br><span></span><br><span>abe.descendents.push(homer);</span><br><span>homer.descendents.push(bart, lisa, maggie);</span><br></pre></td></tr></tbody></table>\n<p>That's all; we have a tree data structure!</p>\n<p><img src=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/images/simpson2-tree.jpg\" alt=\"image\" title=\"Simpson tree data structure\"></p>\n<p>The node <code class=\"language-text\">abe</code> is the <strong>root</strong> and <code class=\"language-text\">bart</code>, <code class=\"language-text\">lisa</code> and <code class=\"language-text\">maggie</code> are the <strong>leaf</strong> nodes of the tree. Notice that the tree's node can have a different number of descendants: 0, 1, 3, or any other value.</p>\n<p>Tree data structures have many applications such as:</p>\n<ul>\n<li><a href=\"https://adrianmejia.com/blog/2018/04/28/data-structures-time-complexity-for-beginners-arrays-hashmaps-linked-lists-stacks-queues-tutorial/#HashMaps\">Maps</a></li>\n<li><a href=\"https://adrianmejia.com/blog/2018/04/28/data-structures-time-complexity-for-beginners-arrays-hashmaps-linked-lists-stacks-queues-tutorial/#Sets\">Sets</a></li>\n<li>Databases</li>\n<li>Priority Queues</li>\n<li>Querying an LDAP (Lightweight Directory Access Protocol)</li>\n<li>Representing the Document Object Model (DOM) for HTML on Websites.</li>\n</ul>\n<h2><a href=\"#Binary-Trees\" title=\"Binary Trees\"></a>Binary Trees</h2>\n<p>Trees nodes can have zero or more children. However, when a tree has at the most two children, then it's called <strong>binary tree</strong>.</p>\n<h3><a href=\"#Full-Complete-and-Perfect-binary-trees\" title=\"Full, Complete and Perfect binary trees\"></a>Full, Complete and Perfect binary trees</h3>\n<p>Depending on how nodes are arranged in a binary tree, it can be <strong>full</strong>, <strong>complete</strong> and <strong>perfect</strong>:</p>\n<ul>\n<li><strong>Full binary tree</strong>: each node has exactly 0 or 2 children (but never 1).</li>\n<li><strong>Complete binary tree</strong>: when all levels except the last one are <strong>full</strong> with nodes.</li>\n<li><strong>Perfect binary tree</strong>: when all the levels (including the last one) are full of nodes.</li>\n</ul>\n<p>Look at these examples:</p>\n<p><img src=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/images/full-complete-perfect-binary-tree.jpg\" alt=\"image\" title=\"Full vs. Complete vs. Perfect Binary Tree\"></p>\n<p>These properties are not always mutually exclusive. You can have more than one:</p>\n<ul>\n<li>\n<p>A perfect tree is <strong>always</strong> complete and full.</p>\n<ul>\n<li>Perfect binary trees have precisely 2k-1 nodes, where <em><code class=\"language-text\">k</code></em> is the last level of the tree (starting with 1).</li>\n</ul>\n</li>\n<li>\n<p>A complete tree is <strong>not</strong> always <code class=\"language-text\">full</code>.</p>\n<ul>\n<li>Like in our \"complete\" example, since it has a parent with only one child. If we remove the rightmost gray node, then we would have a <strong>complete</strong> and <strong>full</strong> tree but not perfect.</li>\n</ul>\n</li>\n<li>A full tree is not always complete and perfect.</li>\n</ul>\n<h2><a href=\"#Binary-Search-Tree-BST\" title=\"Binary Search Tree (BST)\"></a>Binary Search Tree (BST)</h2>\n<p>Binary Search Trees or BST for short are a particular application of binary trees. BST has at most two nodes (like all binary trees). However, the values are in such a way that the left children value must be less than the parent, and the right children is must be higher.</p>\n<p><strong>Duplicates:</strong> Some BST doesn't allow duplicates while others add the same values as a right child. Other implementations might keep a count on a case of the duplicity (we are going to do this one later).</p>\n<p>Let's implement a Binary Search Tree!</p>\n<h3><a href=\"#BST-Implementation\" title=\"BST Implementation\"></a>BST Implementation</h3>\n<p>BST are very similar to our previous <a href=\"#Implementing-a-simple-tree-data-structure\">implementation of a tree</a>. However, there are some differences:</p>\n<ul>\n<li>Nodes can have at most, only two children: left and right.</li>\n<li>Nodes values has to be ordered as <code class=\"language-text\">left &lt; parent &lt; right</code>.</li>\n</ul>\n<p>Here's the tree node. Very similar to what we did before, but we added some handy getters and setters for left and right children. Notice that is also keeping a reference to the parent and we update it every time add children.</p>\n<p>TreeNode.js<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/tree-node.js\">Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br><span>9</span><br><span>10</span><br><span>11</span><br><span>12</span><br><span>13</span><br><span>14</span><br><span>15</span><br><span>16</span><br><span>17</span><br><span>18</span><br><span>19</span><br><span>20</span><br><span>21</span><br><span>22</span><br><span>23</span><br><span>24</span><br><span>25</span><br><span>26</span><br><span>27</span><br><span>28</span><br><span>29</span><br><span>30</span><br><span>31</span><br><span>32</span><br></pre></td><td><pre><span><span>const</span> LEFT = <span>0</span>;</span><br><span><span>const</span> RIGHT = <span>1</span>;</span><br><span></span><br><span><span><span>class</span> <span>TreeNode</span> </span>{</span><br><span>  <span>constructor</span>(value) {</span><br><span>    <span>this</span>.value = value;</span><br><span>    <span>this</span>.descendents = [];</span><br><span>    <span>this</span>.parent = <span>null</span>;</span><br><span>  }</span><br><span></span><br><span>  <span>get</span> <span>left</span>() {</span><br><span>    <span>return</span> <span>this</span>.descendents[LEFT];</span><br><span>  }</span><br><span></span><br><span>  <span>set</span> <span>left</span>(<span>node</span>) {</span><br><span>    <span>this</span>.descendents[LEFT] = node;</span><br><span>    <span>if</span> (node) {</span><br><span>      node.parent = <span>this</span>;</span><br><span>    }</span><br><span>  }</span><br><span></span><br><span>  <span>get</span> <span>right</span>() {</span><br><span>    <span>return</span> <span>this</span>.descendents[RIGHT];</span><br><span>  }</span><br><span></span><br><span>  <span>set</span> <span>right</span>(<span>node</span>) {</span><br><span>    <span>this</span>.descendents[RIGHT] = node;</span><br><span>    <span>if</span> (node) {</span><br><span>      node.parent = <span>this</span>;</span><br><span>    }</span><br><span>  }</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>Ok, so far we can add a left and right child. Now, let's do the BST class that enforces the <code class=\"language-text\">left &lt; parent &lt; right</code> rule.</p>\n<p>BinarySearchTree.js linkUrl linkText</p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br><span>9</span><br><span>10</span><br><span>11</span><br><span>12</span><br><span>13</span><br></pre></td><td><pre><span></span><br><span><span><span>class</span> <span>BinarySearchTree</span> </span>{</span><br><span>  <span>constructor</span>() {</span><br><span>    <span>this</span>.root = <span>null</span>;</span><br><span>    <span>this</span>.size = <span>0</span>;</span><br><span>  }</span><br><span></span><br><span>  add(value) {  }</span><br><span>  find(value) {  }</span><br><span>  remove(value) {  }</span><br><span>  getMax() {  }</span><br><span>  getMin() {  }</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>Let's implementing insertion.</p>\n<h3><a href=\"#BST-Node-Insertion\" title=\"BST Node Insertion\"></a>BST Node Insertion</h3>\n<p>To insert a node in a binary tree, we do the following:</p>\n<ol>\n<li>If a tree is empty, the first node becomes the <strong>root</strong> and you are done.</li>\n<li>Compare root/parent's value if it's <em>higher</em> go <strong>right</strong>, if it's <em>lower</em> go <strong>left</strong>. If it's the same, then the value already exists so you can increase the duplicate count (multiplicity).</li>\n<li>Repeat #2 until we found an empty slot to insert the new node.</li>\n</ol>\n<p>Let's do an illustration how to insert 30, 40, 10, 15, 12, 50:</p>\n<p><img src=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/images/bst2.gif\" alt=\"image\" title=\"Inserting nodes on a Binary Search Tree (BST)\"></p>\n<p>We can implement insert as follows:</p>\n<p>BinarySearchTree.prototype.add<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js#L11\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br><span>9</span><br><span>10</span><br><span>11</span><br><span>12</span><br><span>13</span><br><span>14</span><br><span>15</span><br><span>16</span><br><span>17</span><br><span>18</span><br><span>19</span><br></pre></td><td><pre><span>add(value) {</span><br><span>  <span>const</span> newNode = <span>new</span> TreeNode(value);</span><br><span></span><br><span>  <span>if</span> (<span>this</span>.root) {</span><br><span>    <span>const</span> { found, parent } = <span>this</span>.findNodeAndParent(value);</span><br><span>    <span>if</span> (found) { </span><br><span>      found.meta.multiplicity = (found.meta.multiplicity || <span>1</span>) + <span>1</span>;</span><br><span>    } <span>else</span> <span>if</span> (value &lt; parent.value) {</span><br><span>      parent.left = newNode;</span><br><span>    } <span>else</span> {</span><br><span>      parent.right = newNode;</span><br><span>    }</span><br><span>  } <span>else</span> {</span><br><span>    <span>this</span>.root = newNode;</span><br><span>  }</span><br><span></span><br><span>  <span>this</span>.size += <span>1</span>;</span><br><span>  <span>return</span> newNode;</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>We are using a helper function called <code class=\"language-text\">findNodeAndParent</code>. If we found that the node already exists in the tree, then we increase the <code class=\"language-text\">multiplicity</code> counter. Let's see how this function is implemented:</p>\n<p>BinarySearchTree.prototype.findNodeAndParent<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js#L44\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br><span>9</span><br><span>10</span><br><span>11</span><br><span>12</span><br><span>13</span><br><span>14</span><br></pre></td><td><pre><span>findNodeAndParent(value) {</span><br><span>  <span>let</span> node = <span>this</span>.root;</span><br><span>  <span>let</span> parent;</span><br><span></span><br><span>  <span>while</span> (node) {</span><br><span>    <span>if</span> (node.value === value) {</span><br><span>      <span>break</span>;</span><br><span>    }</span><br><span>    parent = node;</span><br><span>    node = ( value &gt;= node.value) ? node.right : node.left;</span><br><span>  }</span><br><span></span><br><span>  <span>return</span> { <span>found</span>: node, parent };</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p><code class=\"language-text\">findNodeAndParent</code> goes through the tree searching for the value. It starts at the root (line 2) and then goes left or right based on the value (line 10). If the value already exists, it will return the node <code class=\"language-text\">found</code> and also the parent. In case that the node doesn't exist, we still return the <code class=\"language-text\">parent</code>.</p>\n<h3><a href=\"#BST-Node-Deletion\" title=\"BST Node Deletion\"></a>BST Node Deletion</h3>\n<p>We know how to insert and search for value. Now, we are going to implement the delete operation. It's a little trickier than adding, so let's explain it with the following cases:</p>\n<p><strong>Deleting a leaf node (0 children)</strong></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br></pre></td><td><pre><span>    30                             30</span><br><span> /     \\         remove(12)     /     \\</span><br><span>10      40       ---------&gt;    10      40</span><br><span>  \\    /  \\                      \\    /  \\</span><br><span>  15  35   50                    15  35   50</span><br><span>  /</span><br><span>12*</span><br></pre></td></tr></tbody></table>\n<p>We just remove the reference from node's parent (15) to be null.</p>\n<p><strong>Deleting a node with one child.</strong></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br></pre></td><td><pre><span>    30                              30</span><br><span> /     \\         remove(10)      /     \\</span><br><span>10*     40       ---------&gt;     15      40</span><br><span>  \\    /  \\                            /  \\</span><br><span>  15  35   50                         35   50</span><br></pre></td></tr></tbody></table>\n<p>In this case, we go to the parent (30) and replace the child (10), with a child's child (15).</p>\n<p><strong>Deleting a node with two children</strong></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br></pre></td><td><pre><span>    30                              30</span><br><span> /     \\         remove(40)      /     \\</span><br><span>15      40*      ---------&gt;     15      50</span><br><span>       /  \\                            /</span><br><span>      35   50                         35</span><br></pre></td></tr></tbody></table>\n<p>We are removing node 40, that has two children (35 and 50). We replace the parent's (30) child (40) with the child's right child (50). Then we keep the left child (35) in the same place it was before, so we have to make it the left child of 50.</p>\n<p>Another way to do it to remove node 40, is to move the left child (35) up and then keep the right child (50) where it was.</p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br></pre></td><td><pre><span>    30</span><br><span> /     \\</span><br><span>15      35</span><br><span>          \\</span><br><span>           50</span><br></pre></td></tr></tbody></table>\n<p>Either way is ok as long as you keep the binary search tree property: <code class=\"language-text\">left &lt; parent &lt; right</code>.</p>\n<p><strong>Deleting the root.</strong></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br></pre></td><td><pre><span>   30*                            50</span><br><span> /     \\       remove(30)      /     \\</span><br><span>15      50     ---------&gt;     15      35</span><br><span>       /</span><br><span>      35</span><br></pre></td></tr></tbody></table>\n<p>Deleting the root is very similar to removing nodes with 0, 1, or 2 children that we discussed earlier. The only difference is that afterward, we need to update the reference of the root of the tree.</p>\n<p>Here's an animation of what we discussed.</p>\n<p><img src=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/images/bst-remove.gif\" alt=\"image\" title=\"Removing a node with 0, 1, 2 children from a binary search tree\"></p>\n<p>In the animation, it moves up the left child/subtree and keeps the right child/subtree in place.</p>\n<p>Now that we have a good idea how it should work, let's implement it:</p>\n<p>BinarySearchTree.prototype.remove<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js#L89\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br><span>9</span><br><span>10</span><br><span>11</span><br><span>12</span><br><span>13</span><br><span>14</span><br><span>15</span><br><span>16</span><br><span>17</span><br><span>18</span><br><span>19</span><br><span>20</span><br><span>21</span><br><span>22</span><br><span>23</span><br></pre></td><td><pre><span>remove(value) {</span><br><span>  <span>const</span> nodeToRemove = <span>this</span>.find(value);</span><br><span>  <span>if</span> (!nodeToRemove) <span>return</span> <span>false</span>;</span><br><span></span><br><span>  </span><br><span>  <span>const</span> nodeToRemoveChildren = <span>this</span>.combineLeftIntoRightSubtree(nodeToRemove);</span><br><span></span><br><span>  <span>if</span> (nodeToRemove.meta.multiplicity &amp;&amp; nodeToRemove.meta.multiplicity &gt; <span>1</span>) {</span><br><span>    nodeToRemove.meta.multiplicity -= <span>1</span>; </span><br><span>  } <span>else</span> <span>if</span> (nodeToRemove === <span>this</span>.root) {</span><br><span>    </span><br><span>    <span>this</span>.root = nodeToRemoveChildren;</span><br><span>    <span>this</span>.root.parent = <span>null</span>; </span><br><span>  } <span>else</span> {</span><br><span>    <span>const</span> side = nodeToRemove.isParentLeftChild ? <span>'left'</span> : <span>'right'</span>;</span><br><span>    <span>const</span> { parent } = nodeToRemove; </span><br><span>    </span><br><span>    parent[side] = nodeToRemoveChildren;</span><br><span>  }</span><br><span></span><br><span>  <span>this</span>.size -= <span>1</span>;</span><br><span>  <span>return</span> <span>true</span>;</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>Here are some highlights of the implementation:</p>\n<ul>\n<li>First, we search if the node exists. If it doesn't, we return false and we are done!</li>\n<li>If the node to remove exists, then combine left and right children into one subtree.</li>\n<li>Replace node to delete with the combined subtree.</li>\n</ul>\n<p>The function that combines left into right subtree is the following:</p>\n<p>BinarySearchTree.prototype.combineLeftIntoRightSubtree<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js#L89\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br></pre></td><td><pre><span>combineLeftIntoRightSubtree(node) {</span><br><span>  <span>if</span> (node.right) {</span><br><span>    <span>const</span> leftmost = <span>this</span>.getLeftmost(node.right);</span><br><span>    leftmost.left = node.left;</span><br><span>    <span>return</span> node.right;</span><br><span>  }</span><br><span>  <span>return</span> node.left;</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>For instance, let's say that we want to combine the following tree and we are about to delete node <code class=\"language-text\">30</code>. We want to mix 30's left subtree into the right one. The result is this:</p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br></pre></td><td><pre><span>   30*                             40</span><br><span> /     \\                          /  \\</span><br><span>10      40    combine(30)       35   50</span><br><span>  \\    /  \\   -----------&gt;      /</span><br><span>  15  35   50                  10</span><br><span>                                \\</span><br><span>                                 15</span><br></pre></td></tr></tbody></table>\n<p>Now, and if we make the new subtree the root, then node <code class=\"language-text\">30</code> is no more!</p>\n<h2><a href=\"#Binary-Tree-Transversal\" title=\"Binary Tree Transversal\"></a>Binary Tree Transversal</h2>\n<p>There are different ways of traversing a Binary Tree, depending on the order that the nodes are visited: in-order, pre-order, and post-order. Also, we can use them <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/blog/2018/05/14/Data-Structures-for-Beginners-Graphs-Time-Complexity-tutorial/#Depth-first-search-DFS-Graph-search\">DFS</a> and <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/blog/2018/05/14/Data-Structures-for-Beginners-Graphs-Time-Complexity-tutorial/#Breadth-frirst-search-BFS-Graph-search\">BFS</a> that we learned from the <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/blog/2018/05/14/Data-Structures-for-Beginners-Graphs-Time-Complexity-tutorial/\">graph post.</a> Let's go through each one.</p>\n<p><strong>In-Order Traversal</strong></p>\n<p>In-order traversal visit nodes on this order: left, parent, right.</p>\n<p>BinarySearchTree.prototype.inOrderTraversal<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br></pre></td><td><pre><span>*inOrderTraversal(node = <span>this</span>.root) {</span><br><span>  <span>if</span> (node.left) { <span>yield</span>* <span>this</span>.inOrderTraversal(node.left); }</span><br><span>  <span>yield</span> node;</span><br><span>  <span>if</span> (node.right) { <span>yield</span>* <span>this</span>.inOrderTraversal(node.right); }</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>Let's use this tree to make the example:</p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br></pre></td><td><pre><span>         10</span><br><span>       /    \\</span><br><span>      5      30</span><br><span>    /       /  \\</span><br><span>   4       15   40</span><br><span> /</span><br><span>3</span><br></pre></td></tr></tbody></table>\n<p>In-order traversal would print out the following values: <code class=\"language-text\">3, 4, 5, 10, 15, 30, 40</code>. If the tree is a BST, then the nodes will be sorted in ascendent order as in our example.</p>\n<p><strong>Post-Order Traversal</strong></p>\n<p>Post-order traversal visit nodes on this order: left, right, parent.</p>\n<p>BinarySearchTree.prototype.postOrderTraversal<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br></pre></td><td><pre><span>*postOrderTraversal(node = <span>this</span>.root) {</span><br><span>  <span>if</span> (node.left) { <span>yield</span>* <span>this</span>.postOrderTraversal(node.left); }</span><br><span>  <span>if</span> (node.right) { <span>yield</span>* <span>this</span>.postOrderTraversal(node.right); }</span><br><span>  <span>yield</span> node;</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>Post-order traversal would print out the following values: <code class=\"language-text\">3, 4, 5, 15, 40, 30, 10</code>.</p>\n<p><strong>Pre-Order Traversal and DFS</strong></p>\n<p>In-order traversal visit nodes on this order: parent, left, right.</p>\n<p>BinarySearchTree.prototype.preOrderTraversal<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br></pre></td><td><pre><span>*preOrderTraversal(node = <span>this</span>.root) {</span><br><span>  <span>yield</span> node;</span><br><span>  <span>if</span> (node.left) { <span>yield</span>* <span>this</span>.preOrderTraversal(node.left); }</span><br><span>  <span>if</span> (node.right) { <span>yield</span>* <span>this</span>.preOrderTraversal(node.right); }</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>Pre-order traversal would print out the following values: <code class=\"language-text\">10, 5, 4, 3, 30, 15, 40</code>. This order of numbers is the same result that we would get if we run the Depth-First Search (DFS).</p>\n<p>BinarySearchTree.prototype.dfs<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br><span>9</span><br><span>10</span><br><span>11</span><br><span>12</span><br></pre></td><td><pre><span>* dfs() {</span><br><span>  <span>const</span> stack = <span>new</span> Stack();</span><br><span></span><br><span>  stack.add(<span>this</span>.root);</span><br><span></span><br><span>  <span>while</span> (!stack.isEmpty()) {</span><br><span>    <span>const</span> node = stack.remove();</span><br><span>    <span>yield</span> node;</span><br><span>    </span><br><span>    node.descendents.reverse().forEach(<span><span>child</span> =&gt;</span> stack.add(child));</span><br><span>  }</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>If you need a refresher on DFS, we covered in details on <a href=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/blog/2018/05/14/Data-Structures-for-Beginners-Graphs-Time-Complexity-tutorial/#Depth-first-search-DFS-Graph-search\">Graph post</a>.</p>\n<p><strong>Breadth-First Search (BFS)</strong></p>\n<p>Similar to DFS, we can implement a BFS by switching the <code class=\"language-text\">Stack</code> by a <code class=\"language-text\">Queue</code>:</p>\n<p>BinarySearchTree.prototype.bfs<a href=\"https://github.com/amejiarosario/dsa.js/blob/master/src/data-structures/trees/binary-search-tree.js\">Full Code</a></p>\n<table><tbody><tr><td><pre><span>1</span><br><span>2</span><br><span>3</span><br><span>4</span><br><span>5</span><br><span>6</span><br><span>7</span><br><span>8</span><br><span>9</span><br><span>10</span><br><span>11</span><br></pre></td><td><pre><span>* bfs() {</span><br><span>  <span>const</span> queue = <span>new</span> Queue();</span><br><span></span><br><span>  queue.add(<span>this</span>.root);</span><br><span></span><br><span>  <span>while</span> (!queue.isEmpty()) {</span><br><span>    <span>const</span> node = queue.remove();</span><br><span>    <span>yield</span> node;</span><br><span>    node.descendents.forEach(<span><span>child</span> =&gt;</span> queue.add(child));</span><br><span>  }</span><br><span>}</span><br></pre></td></tr></tbody></table>\n<p>The BFS order is: <code class=\"language-text\">10, 5, 30, 4, 15, 40, 3</code></p>\n<h2><a href=\"#Balanced-vs-Non-balanced-Trees\" title=\"Balanced vs. Non-balanced Trees\"></a>Balanced vs. Non-balanced Trees</h2>\n<p>So far, we have discussed how to <code class=\"language-text\">add</code>, <code class=\"language-text\">remove</code> and <code class=\"language-text\">find</code> elements. However, we haven't talked about runtimes. Let's think about the worst-case scenarios.</p>\n<p>Let's say that we want to add numbers in ascending order.</p>\n<p><img src=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/images/bst-asc.gif\" alt=\"image\" title=\"Inserting values in ascending order in a Binary Search Tree\"></p>\n<p>We will end up with all the nodes on the left side! This unbalanced tree is no better than a LinkedList, so finding an element would take <em>O(n)</em>. 😱</p>\n<p>Looking for something in an unbalanced tree is like looking for a word in the dictionary page by page. When the tree is balanced, you can open the dictionary in the middle and from there you know if you have to go left or right depending on the alphabet and the word you are looking for.</p>\n<p>We need to find a way to balance the tree!</p>\n<p>If the tree was <strong>balanced</strong>, then we could find elements in <em>O(log n)</em> instead of going through each node. Let's talk about what balanced tree means.</p>\n<p><img src=\"chrome-extension://cjedbglnccaioiolemnfhjncicchinao/images/balanced-vs-non-balanced-tree.jpg\" alt=\"image\" title=\"Balanced vs unbalanced Tree\"></p>\n<p>If we are searching for <code class=\"language-text\">7</code> in the non-balanced tree, we have to go from 1 to 7. However, in the balanced tree, we visit: <code class=\"language-text\">4</code>, <code class=\"language-text\">6</code>, and <code class=\"language-text\">7</code>. It gets even worse with larger trees. If you have one million nodes, searching for a non-existing element might require to visit all million while on a balanced tree it just requires 20 visits! That's a huge difference!</p>\n<p>We are going to solve this issue in the next post using self-balanced trees (AVL trees).</p>\n<h2>Big O Notation</h2>\n<h3>time complexity</h3>\n<p>it allow us to talk formally about how the runtime of an algorithm grows as the input grows.</p>\n<p>n = number of operation the computer has to do can be:\nf(n) = n\nf(n) = n^2\nf(n) = 1</p>\n<p>f(n) = could be something entirely different !</p>\n<p>O(n):</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">addUpToSimple</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> total <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        total <span class=\"token operator\">+=</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> total<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>O(1):</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">addUpComplex</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>O(n): maybe thinking O(2n) but we see big picture! BigONotation doesn't care about precision only about general trends <em>linear? quadric? constant?</em></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">printUpAndDown</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Going up'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Going down'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>O(n^2)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">printAllPairs</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>O(n) : cuz as soon as n grows complexity grows too</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">logAtLeastFive</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>O(1)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">logAtMostFive</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>space complexity</h3>\n<p>Rules of Thumb</p>\n<ul>\n<li>&#x3C;==(<em><strong>most primitive booleans numbers undefined null are constant space</strong></em>)==>.</li>\n<li>&#x3C;==(<em>**strings and reference types like objects an arrays require O(n) space \\</em>n is string length or number of keys<em>**\\</em>)==></li>\n</ul>\n<p>O(1)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> total <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        total <span class=\"token operator\">+=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>O(n)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">double</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> newArr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        array<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> newArr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>quick note around object, array through BigO lens</h3>\n<ul>\n<li>object:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">22</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">hobbies</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'reading'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'sleeping'</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>person<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [\"name\", \"age\", \"hobbies\"] --->              O(n)</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span>person<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [\"John\", 22, Array(2)]--->                 O(n)</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span>person<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [Array(2), Array(2), Array(2)]--->        O(n)</span>\nperson<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true --->                          O(1)</span></code></pre></div>\n<ul>\n<li>array:\n<strong><em>push() and pop()</em> are always faster than <em>unshift() and shift()</em> because inserting or removing element from beginning of an array requires reIndexing all elements</strong></li>\n</ul>\n<h2>Common Patterns</h2>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">sortedArr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> min <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> max <span class=\"token operator\">=</span> sortedArr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>min <span class=\"token operator\">&lt;=</span> max<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> middle <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>min <span class=\"token operator\">+</span> max<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>sortedArr<span class=\"token punctuation\">[</span>middle<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            min <span class=\"token operator\">=</span> middle <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>sortedArr<span class=\"token punctuation\">[</span>middle<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            max <span class=\"token operator\">=</span> middle <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> middle<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Recursion</h2>\n<p>a process that calls itself</p>\n<p>quick note around callStack</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">wakeUp</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// callStack [wakeUp]</span>\n    <span class=\"token function\">takeShower</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">eatBreakfast</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Ready to go ... '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token comment\">// callStack []</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">takeShower</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// callStack [takeShower, wakeUp]</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'taking shower'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token comment\">// callStack[wakeUp]</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">eatBreakfast</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// callStack [eatBreakfast, wakeUp]</span>\n    <span class=\"token keyword\">const</span> meal <span class=\"token operator\">=</span> <span class=\"token function\">cookBreakFast</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">eating </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>meal<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token comment\">// callStack [wakeUp]</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">cookBreakFast</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// callStack [cookBreakFast, eatBreakfast, wakeUp]</span>\n    <span class=\"token keyword\">const</span> meals <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Cheese'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Protein Shake'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Coffee'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> meals<span class=\"token punctuation\">[</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">random</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> meals<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// callStack [eatBreakFast, wakeUp]</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">wakeUp</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>two essential part of recursive functions</p>\n<ul>\n<li><strong>base case : end of the line</strong></li>\n<li><strong>different input : recursive should call by different piece of data</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">sumRange</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">num</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> num <span class=\"token operator\">+</span> <span class=\"token function\">sumRange</span><span class=\"token punctuation\">(</span>num <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">num</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">===</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> num <span class=\"token operator\">*</span> <span class=\"token function\">factorial</span><span class=\"token punctuation\">(</span>num <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>helper method recursion vs pure recursion</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// helper method recursion approach</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">collectOdd</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">helper</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">helperArr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>helperArr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>helperArr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">!==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>helperArr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token function\">helper</span><span class=\"token punctuation\">(</span>helperArr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">helper</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// pure recursion approach</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">collectOdd</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">%</span> <span class=\"token number\">2</span> <span class=\"token operator\">!==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    result <span class=\"token operator\">=</span> <span class=\"token function\">collectOdd</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Searching Algorithms</h2>\n<h3>linear search</h3>\n<p><em>indexOf() includes() find() findIndex()</em> all this methods doing linear search behind the scene</p>\n<p>O(n)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">linearSearch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> i<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>binary search</h3>\n<p>O(Log n)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">binarySearch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">sortedArr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> left <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> right <span class=\"token operator\">=</span> sortedArr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">&lt;=</span> right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> middle <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">round</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>right <span class=\"token operator\">+</span> left<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>sortedArr<span class=\"token punctuation\">[</span>middle<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            right <span class=\"token operator\">=</span> middle <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>sortedArr<span class=\"token punctuation\">[</span>middle<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            left <span class=\"token operator\">=</span> middle <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> middle<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Sorting Algorithms</h2>\n<h3>array.sort()</h3>\n<p>array.sort(cb) will turn all values to <em>string</em> then sort it based on it's <em>unicode</em></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// (5) [\"a\", \"b\", \"c\", \"d\", \"f\"]</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//(7) [1, 10, 2, 3, 5, 6, 8]</span>\n\n<span class=\"token comment\">/* \nalso receive callback function by two arguments:\n    a: previous number \n    b: next number \n\n*/</span>\n<span class=\"token comment\">// if callback return NEGATIVE number a will placed before b</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// (7) [1, 2, 3, 5, 6, 8, 10]</span>\n\n<span class=\"token comment\">// if callback return POSITIVE number a will placed after b</span>\n<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> b <span class=\"token operator\">-</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// (7) [10, 8, 6, 5, 3, 2, 1]</span>\n\n<span class=\"token comment\">// if callback return ZERO a and b will placed at the same position</span></code></pre></div>\n<h2>Quadric</h2>\n<h3>bubble sort</h3>\n<p>general: O(n^2)\nnearlySortedData: O(n)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">bubbleSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> noSwap <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> i<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                noSwap <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>noSwap<span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// or</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">bubbleSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> noSwap <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                noSwap <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>noSwap<span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>selection sort</h3>\n<p>O(n^2)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">selectionSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> min <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">[</span>min<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                min <span class=\"token operator\">=</span> j<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>min <span class=\"token operator\">!==</span> i<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>min<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>min<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>insertion sort</h3>\n<p>general: O(n^2)\nnearlySortedData: O(n)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">insertionSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> currentVal<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        currentVal <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> j <span class=\"token operator\">=</span> i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">>=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span> <span class=\"token operator\">></span> currentVal<span class=\"token punctuation\">;</span> j<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        arr<span class=\"token punctuation\">[</span>j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> currentVal<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>quadric sorting algorithms comparison</h3>\n<table>\n<thead>\n<tr>\n<th align=\"center\">Algorithm</th>\n<th align=\"center\">Time Complexity (Best)</th>\n<th align=\"center\">Time Complexity (Average)</th>\n<th align=\"center\">Time Complexity (worst)</th>\n<th align=\"center\">Space Complexity</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\">bubble sort</td>\n<td align=\"center\">O(n)</td>\n<td align=\"center\">O(n^2)</td>\n<td align=\"center\">O(n^2)</td>\n<td align=\"center\">O(1)</td>\n</tr>\n<tr>\n<td align=\"center\">insertion sort</td>\n<td align=\"center\">O(n)</td>\n<td align=\"center\">O(n^2)</td>\n<td align=\"center\">O(n^2)</td>\n<td align=\"center\">O(1)</td>\n</tr>\n<tr>\n<td align=\"center\">selection sort</td>\n<td align=\"center\">O(n^2)</td>\n<td align=\"center\">O(n^2)</td>\n<td align=\"center\">O(n^2)</td>\n<td align=\"center\">O(1)</td>\n</tr>\n</tbody>\n</table>\n<h2>Fancy</h2>\n<h3>merge sort</h3>\n<p>O(n Log n)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// merge two sorted array</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr1</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">arr2</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> arr1<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> j <span class=\"token operator\">&lt;</span> arr2<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr1<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> arr2<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr1<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr2<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            j<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">&lt;</span> arr1<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr1<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        i<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>j <span class=\"token operator\">&lt;</span> arr2<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr2<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        j<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> middle <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> left <span class=\"token operator\">=</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> middle<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> right <span class=\"token operator\">=</span> <span class=\"token function\">mergeSort</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>middle<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token function\">merge</span><span class=\"token punctuation\">(</span>left<span class=\"token punctuation\">,</span> right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>quick sort</h3>\n<p><img src=\"./assets/Quicksort.gif\" alt=\"quick sort\"></p>\n<p>in following implementation we always assume <em>first item</em> as pivot</p>\n<p>general: O(n Log n)\nsorted: O(n^2)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// place pivot in the right index and return pivot index</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">pivot</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> pivot <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> pivotIndex <span class=\"token operator\">=</span> start<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> start <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> end<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;</span> pivot<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            pivotIndex<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>pivotIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>pivotIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>pivotIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span>pivotIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span>start<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> start <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>left <span class=\"token operator\">&lt;</span> right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> pivot <span class=\"token operator\">=</span> <span class=\"token function\">pivot</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token comment\">// left</span>\n        <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> pivotIndex <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// right</span>\n        <span class=\"token function\">quickSort</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> pivotIndex <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>radix sort</h3>\n<p>O(nk)\nn: the number of items we sorting\nk: average length of those numbers</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// get the actual number at the given index</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">getDigit</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">num</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">i</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">%</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// get number length</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">digitCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">num</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>num <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">log10</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// return number by most length</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">mostDigits</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> maxDigits <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        maxDigits <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>maxDigits<span class=\"token punctuation\">,</span> <span class=\"token function\">digitCount</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> maxDigits<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">radixSort</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> maxDigitCount <span class=\"token operator\">=</span> <span class=\"token function\">mostDigits</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> k <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> k <span class=\"token operator\">&lt;</span> maxDigitCount<span class=\"token punctuation\">;</span> k<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> digitBuckets <span class=\"token operator\">=</span> Array<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">length</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            digitBuckets<span class=\"token punctuation\">[</span><span class=\"token function\">getDigit</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> k<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>j<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>digitBuckets<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>fancy sorting algorithms comparison</h3>\n<table>\n<thead>\n<tr>\n<th align=\"center\">Algorithm</th>\n<th align=\"center\">Time Complexity (Best)</th>\n<th align=\"center\">Time Complexity (Average)</th>\n<th align=\"center\">Time Complexity (worst)</th>\n<th align=\"center\">Space Complexity</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\">merge sort</td>\n<td align=\"center\">O(n Log n)</td>\n<td align=\"center\">O(n Log n)</td>\n<td align=\"center\">O(n Log n)</td>\n<td align=\"center\">O(n)</td>\n</tr>\n<tr>\n<td align=\"center\">quick sort</td>\n<td align=\"center\">O(n Log n)</td>\n<td align=\"center\">O(n Log n)</td>\n<td align=\"center\">O(n^2)</td>\n<td align=\"center\">O(Log n)</td>\n</tr>\n<tr>\n<td align=\"center\">radix sort</td>\n<td align=\"center\">O(nk)</td>\n<td align=\"center\">O(nk)</td>\n<td align=\"center\">O(nk)</td>\n<td align=\"center\">O(n + k)</td>\n</tr>\n</tbody>\n</table>\n<h2>Data Structure</h2>\n<h3>complexity comparison</h3>\n<table>\n<thead>\n<tr>\n<th align=\"center\">DataStructure</th>\n<th align=\"center\">Insertion</th>\n<th align=\"center\">Removal</th>\n<th align=\"center\">Searching</th>\n<th align=\"center\">Access</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\">Singly Linked List</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">bestCase(very beginning): O(1) worstCase(very end): O(n)</td>\n<td align=\"center\">O(n)</td>\n<td align=\"center\">O(n)</td>\n</tr>\n<tr>\n<td align=\"center\">Doubly Linked List</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">O(n) it is faster than Singly Linked List</td>\n<td align=\"center\">O(n)</td>\n</tr>\n<tr>\n<td align=\"center\">Stack</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">O(n)</td>\n<td align=\"center\">O(n)</td>\n</tr>\n<tr>\n<td align=\"center\">Queue</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">O(n)</td>\n<td align=\"center\">O(n)</td>\n</tr>\n<tr>\n<td align=\"center\">Binary Search Tree</td>\n<td align=\"center\">O( Log n)</td>\n<td align=\"center\">-</td>\n<td align=\"center\">O(Log n)</td>\n<td align=\"center\">-</td>\n</tr>\n<tr>\n<td align=\"center\">Binary Heap</td>\n<td align=\"center\">O( Log n)</td>\n<td align=\"center\">O( Log n)</td>\n<td align=\"center\">O( n )</td>\n<td align=\"center\">-</td>\n</tr>\n<tr>\n<td align=\"center\">Hash Tables</td>\n<td align=\"center\">O( 1 )</td>\n<td align=\"center\">O( 1 )</td>\n<td align=\"center\">-</td>\n<td align=\"center\">O( 1 )</td>\n</tr>\n</tbody>\n</table>\n<h2>Singly Linked list</h2>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">_Node</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">public</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">SinglyLinkedList</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">_length</span><span class=\"token operator\">:</span> number <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">head</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">tail</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">|</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            arr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> SinglyLinkedList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> currentNode<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">&amp;&amp;</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> currentNode<span class=\"token punctuation\">.</span>next <span class=\"token keyword\">as</span> _Node<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">unShift</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> SinglyLinkedList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> currentHead <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentHead<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> currentHead<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> currentHead <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> currentHead<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentHead <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">)</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> currentHead<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> index <span class=\"token operator\">>=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> index<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode <span class=\"token operator\">&amp;&amp;</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> currentNode<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">set</span><span class=\"token punctuation\">(</span>index<span class=\"token operator\">:</span> number<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            node<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> node<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">insert</span><span class=\"token punctuation\">(</span>index<span class=\"token operator\">:</span> number<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> SinglyLinkedList <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> index <span class=\"token operator\">>=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">unShift</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> prevNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>prevNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">const</span> newNode <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                newNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> prevNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n                prevNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> newNode<span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">return</span> prevNode<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span>index<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> prevNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>prevNode <span class=\"token operator\">&amp;&amp;</span> currentNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                prevNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">return</span> currentNode<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> SinglyLinkedList <span class=\"token operator\">|</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> <span class=\"token literal-property property\">prev</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n                node<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> prev<span class=\"token punctuation\">;</span>\n                prev <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n                node <span class=\"token operator\">=</span> next<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Doubly Linked List</h2>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">_Node</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">prev</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">public</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">DoublyLinkedList</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">head</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">tail</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">private</span> _length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">|</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">let</span> currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            arr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> DoublyLinkedList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n            node<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> currentTail <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentTail<span class=\"token punctuation\">.</span>prev<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> currentTail<span class=\"token punctuation\">.</span>prev<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            currentTail<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> currentTail<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">|</span> _Node <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> currentHead <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentHead<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> currentHead<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            currentHead<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> currentHead<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> DoublyLinkedList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> currentHead <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> currentHead<span class=\"token punctuation\">;</span>\n        currentHead<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">|</span> _Node <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> index <span class=\"token operator\">>=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> <span class=\"token literal-property property\">currentNode</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">&lt;</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// iterate from head to tail</span>\n\n            currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> index<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode <span class=\"token operator\">&amp;&amp;</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// iterate from tail to head</span>\n\n            currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">></span> index<span class=\"token punctuation\">;</span> i<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode <span class=\"token operator\">&amp;&amp;</span> currentNode<span class=\"token punctuation\">.</span>prev<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>prev<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n                <span class=\"token keyword\">return</span> currentNode<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> currentNode<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">set</span><span class=\"token punctuation\">(</span>index<span class=\"token operator\">:</span> number<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            node<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> node<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">insert</span><span class=\"token punctuation\">(</span>index<span class=\"token operator\">:</span> number<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> DoublyLinkedList <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> index <span class=\"token operator\">></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> prevNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> nextNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>prevNode <span class=\"token operator\">&amp;&amp;</span> nextNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">const</span> newNode <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                prevNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> newNode<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">(</span>newNode<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> prevNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>newNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> nextNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                nextNode<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> newNode<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">remove</span><span class=\"token punctuation\">(</span>index<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> DoublyLinkedList <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">||</span> index <span class=\"token operator\">></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>index <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node <span class=\"token operator\">&amp;&amp;</span> node<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">&amp;&amp;</span> node<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>prev<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> node<span class=\"token punctuation\">.</span>prev<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Stacks</h2>\n<p>LIFO\nlast in first out</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// implement stack using array</span>\n<span class=\"token keyword\">const</span> stack <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nstack<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [1,2,3,4]</span>\nstack<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [1,2,3]</span>\n<span class=\"token comment\">// stacks just have push and pop</span>\nstack<span class=\"token punctuation\">.</span><span class=\"token function\">unshift</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [0,1,2,3]</span>\nstack<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [1,2,3]</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// implementing stack using singly linked list</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">_Node</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">public</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Stack</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">first</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">last</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">private</span> _length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">get</span> <span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> Stack <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> currentFirst <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first<span class=\"token punctuation\">;</span>\n\n        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first <span class=\"token operator\">=</span> node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> currentFirst<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>currentFirst<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> currentFirst <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentFirst<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last<span class=\"token punctuation\">)</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last <span class=\"token operator\">=</span> currentFirst<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first <span class=\"token operator\">=</span> currentFirst<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> currentFirst<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Queue</h2>\n<p>FIFO\nfirst in first out</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// implementing queue using array</span>\n<span class=\"token keyword\">const</span> q <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nq<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nq<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nq<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// out first items first</span>\n<span class=\"token comment\">// or</span>\nq<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nq<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nq<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// out first items first</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// implementing queue using singly linked list</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">_Node</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">public</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Queue</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">first</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">last</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">private</span> _length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">get</span> <span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> Queue <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first <span class=\"token operator\">=</span> node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last <span class=\"token operator\">=</span> node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">+=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">dequeue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> currentFirst <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentFirst<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last<span class=\"token punctuation\">)</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>last <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>first <span class=\"token operator\">=</span> currentFirst<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_length <span class=\"token operator\">-=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> currentFirst<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Tree</h2>\n<h3>terminology</h3>\n<ul>\n<li>root : top node of tree</li>\n<li>child : a node directly connected to another node when moving away from root</li>\n<li>parent : the converse notion of a child</li>\n<li>sibling : a group of nodes with the same parent</li>\n<li>leaf : a child with no children</li>\n<li>edge : connection from two node</li>\n</ul>\n<h3>binary search tree</h3>\n<ul>\n<li>every parent node has at most <strong>two</strong> children</li>\n<li>every node to the <strong>left</strong> of parent node is always <strong>less</strong> than the <strong>parent</strong></li>\n<li>every node to the <strong>right</strong> of parent node is always <strong>greater</strong> than the <strong>parent</strong></li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">_Node</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">public</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">left</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">right</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">BinarySearchTree</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">root</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">insert</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> BinarySearchTree <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> <span class=\"token literal-property property\">currentNode</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">do</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">===</span> currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">&lt;</span> currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                        currentNode<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                        currentNode<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">have</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">===</span> currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">&lt;</span> currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>tree traversal</h3>\n<p>there is two main strategies to traversal a tree : <strong>Breadth-first-search</strong> and <strong>Depth-first-search</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">_Node</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">public</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">left</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">right</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">BinarySearchTree</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">root</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">insert</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> BinarySearchTree <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> <span class=\"token literal-property property\">currentNode</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">do</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">===</span> currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">&lt;</span> currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                        currentNode<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                        currentNode<span class=\"token punctuation\">.</span>right <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">have</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> currentNode <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">===</span> currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">&lt;</span> currentNode<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentNode<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        currentNode <span class=\"token operator\">=</span> currentNode<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">;</span>\n                        <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">/*\n    breadth first search (bfs) : traverse tree horizontally\n*/</span>\n    <span class=\"token keyword\">public</span> <span class=\"token function\">bfs</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">visited</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">q</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                visited<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> visited<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">/*\n    depth first search (dfs) : traverse tree vertically\n    following contains three dfs searching methods:\n    1. preOrder : add node => going to left and add left => going to right and add right\n    2. postOrder : going to left and add left => going to right and add right => going to node and add node\n    3. inOrder : going to the left and add left => add node => going to the right and add right\n     */</span>\n    <span class=\"token keyword\">public</span> <span class=\"token function\">dfsPreOrder</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">visited</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">node</span><span class=\"token operator\">:</span> _Node</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token punctuation\">{</span>\n                visited<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> visited<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">dfsPostOrder</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">visited</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">node</span><span class=\"token operator\">:</span> _Node</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                visited<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> visited<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">dfsInOrder</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">visited</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">node</span><span class=\"token operator\">:</span> _Node</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                visited<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                f<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>right<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>root<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> visited<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>traversal comparison</h3>\n<p><strong>depth-first</strong> <em>vs</em> <strong>breadth-first</strong> : they both <strong>timeComplexity is same</strong> but <strong>spaceComplexity is different</strong> if we got <strong>a wide tree</strong> like this:</p>\n<p><img src=\"./assets/Z20M5iE.png\" alt=\"image\"></p>\n<p><strong>breadth-first take up more space.</strong> cuz we adding more element to queue.</p>\n<p>if we got <strong>a depth long tree</strong> like this:</p>\n<p><strong>depth-first take up more space.</strong></p>\n<hr/>\n<p><strong>potentially use cases for dfs variants (<em>preOder postOrder inOrder</em>)</strong>\npreOrder is useful when we want a clone of tree.\ninOrder is useful when we want data in order that it's stored in tree.</p>\n<h2>Binary heaps</h2>\n<h3>terminology</h3>\n<ul>\n<li>a binary heap is as compact as possible (all the children of each node are as full as they can be and left children and filled out first)</li>\n<li>each parent has at most two children</li>\n</ul>\n<p><strong>Max Binary Heap</strong>:</p>\n<ul>\n<li><strong>parent</strong> nodes are always greater than <strong>child</strong> nodes but there is no guarantees between sibling</li>\n</ul>\n<p><strong>Min Binary Heap</strong>:</p>\n<ul>\n<li><strong>child</strong> nodes are always greater than <strong>parent</strong> nodes but there is no guarantees between sibling</li>\n</ul>\n<h3>binary heap parent and child relations</h3>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">MaxBinaryHeap</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">_values</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">get</span> <span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">private</span> <span class=\"token function\">sinkingUp</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> valueIndex <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>valueIndex <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> parentIndex <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>valueIndex <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> parent <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>parentIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">&lt;=</span> parent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>parentIndex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>valueIndex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> parent<span class=\"token punctuation\">;</span>\n\n            valueIndex <span class=\"token operator\">=</span> parentIndex<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">private</span> <span class=\"token function\">sinkingDown</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> targetIndex <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> leftChildIndex <span class=\"token operator\">=</span> targetIndex <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n                rightChildIndex <span class=\"token operator\">=</span> targetIndex <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">let</span> target <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                leftChild <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                rightChild <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>target <span class=\"token operator\">&lt;</span> leftChild <span class=\"token operator\">&amp;&amp;</span> target <span class=\"token operator\">&lt;</span> rightChild<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rightChild <span class=\"token operator\">></span> leftChild<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token punctuation\">[</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                    targetIndex <span class=\"token operator\">=</span> rightChildIndex<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token punctuation\">[</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                    targetIndex <span class=\"token operator\">=</span> leftChildIndex<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rightChild <span class=\"token operator\">>=</span> target<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span>\n                <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                targetIndex <span class=\"token operator\">=</span> leftChildIndex<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>leftChild <span class=\"token operator\">>=</span> target<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span>\n                <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                targetIndex <span class=\"token operator\">=</span> leftChildIndex<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">insert</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">sinkingUp</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">extractMax</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">const</span> root <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">sinkingDown</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> root<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Priority Queue</h2>\n<p>A data structure which every element has a priority.\nElements with higher priorities are served before elements with lower priorities.</p>\n<p><strong>In the following example, we implemented a priority queue using minBinaryHeap but you should know binaryHeaps and priority queue is two different concepts and we just use an abstract of it</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">INode</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">;</span>\n    <span class=\"token literal-property property\">priority</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">_Node</span> <span class=\"token keyword\">implements</span> <span class=\"token class-name\">INode</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token keyword\">public</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">,</span> <span class=\"token keyword\">public</span> <span class=\"token literal-property property\">priority</span><span class=\"token operator\">:</span> number <span class=\"token operator\">=</span> <span class=\"token number\">0</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">PriorityQueue</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">_values</span><span class=\"token operator\">:</span> INode<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">get</span> <span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> INode<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">private</span> <span class=\"token function\">sinkingUp</span><span class=\"token punctuation\">(</span>node<span class=\"token operator\">:</span> INode<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> valueIndex <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>valueIndex <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> parentIndex <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>valueIndex <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> parent <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>parentIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">.</span>priority <span class=\"token operator\">>=</span> parent<span class=\"token punctuation\">.</span>priority<span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>parentIndex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> node<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>valueIndex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> parent<span class=\"token punctuation\">;</span>\n\n            valueIndex <span class=\"token operator\">=</span> parentIndex<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">private</span> <span class=\"token function\">sinkingDown</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> targetIndex <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> leftChildIndex <span class=\"token operator\">=</span> targetIndex <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n                rightChildIndex <span class=\"token operator\">=</span> targetIndex <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">let</span> target <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                leftChild <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                rightChild <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n                leftChild <span class=\"token operator\">&amp;&amp;</span>\n                rightChild <span class=\"token operator\">&amp;&amp;</span>\n                target<span class=\"token punctuation\">.</span>priority <span class=\"token operator\">></span> leftChild<span class=\"token punctuation\">.</span>priority <span class=\"token operator\">&amp;&amp;</span>\n                target<span class=\"token punctuation\">.</span>priority <span class=\"token operator\">></span> rightChild<span class=\"token punctuation\">.</span>priority\n            <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rightChild<span class=\"token punctuation\">.</span>priority <span class=\"token operator\">&lt;</span> leftChild<span class=\"token punctuation\">.</span>priority<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token punctuation\">[</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                    targetIndex <span class=\"token operator\">=</span> rightChildIndex<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token punctuation\">[</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                    targetIndex <span class=\"token operator\">=</span> leftChildIndex<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>rightChild <span class=\"token operator\">&amp;&amp;</span> rightChild<span class=\"token punctuation\">.</span>priority <span class=\"token operator\">&lt;=</span> target<span class=\"token punctuation\">.</span>priority<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>rightChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span>\n                <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                targetIndex <span class=\"token operator\">=</span> leftChildIndex<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>leftChild <span class=\"token operator\">&amp;&amp;</span> leftChild<span class=\"token punctuation\">.</span>priority <span class=\"token operator\">&lt;=</span> target<span class=\"token punctuation\">.</span>priority<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>leftChildIndex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span>targetIndex<span class=\"token punctuation\">]</span>\n                <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                targetIndex <span class=\"token operator\">=</span> leftChildIndex<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> value<span class=\"token punctuation\">,</span> priority <span class=\"token punctuation\">}</span><span class=\"token operator\">:</span> INode<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">_Node</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> priority<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">sinkingUp</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">dequeue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> _Node <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">const</span> root <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">[</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">sinkingDown</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> root<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Hash Tables</h2>\n<p>Hash tables are collection of key-value pairs</p>\n<h3>collisions</h3>\n<p>There is possibility for handle collisions is hash tables :</p>\n<ul>\n<li>Separate chaining ( e.g. using nested arrays of key values <em>implemented in following hash tables</em> )</li>\n<li>linear probing ( if index filled place {key, value} in next position )</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">type El <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>string<span class=\"token punctuation\">,</span> any<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">HashTable</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">keyMap</span><span class=\"token operator\">:</span> El<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">size</span><span class=\"token operator\">:</span> number <span class=\"token operator\">=</span> <span class=\"token number\">53</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span>size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> total <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> <span class=\"token constant\">WEIRD_PRIME</span> <span class=\"token operator\">=</span> <span class=\"token number\">31</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> key<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> characterCode <span class=\"token operator\">=</span> key<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> <span class=\"token number\">96</span><span class=\"token punctuation\">;</span>\n            total <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>total <span class=\"token operator\">+</span> characterCode <span class=\"token operator\">*</span> <span class=\"token constant\">WEIRD_PRIME</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">%</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> total<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">set</span><span class=\"token punctuation\">(</span>key<span class=\"token operator\">:</span> string<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> El<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">get</span><span class=\"token punctuation\">(</span>key<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> El <span class=\"token operator\">|</span> <span class=\"token keyword\">undefined</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> index <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">_hash</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> elements <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>elements<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> value <span class=\"token keyword\">of</span> elements<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> key<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> value<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">keys</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">keys</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> value <span class=\"token keyword\">of</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> _value <span class=\"token keyword\">of</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    keys<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>_value<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> keys<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> values <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token operator\">&lt;</span>any<span class=\"token operator\">></span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> value <span class=\"token keyword\">of</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>keyMap<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> _value <span class=\"token keyword\">of</span> value<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    values<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>values<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Graphs</h2>\n<p>A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for directed graph.</p>\n<h3>terminology</h3>\n<ul>\n<li>vertex :node</li>\n<li>edge : connection between nodes</li>\n<li>directed/ undirected graph:\nin directed graph there is a direction assigned to vertices an in undirected no direction assigned.</li>\n<li>weighted/ unweighted graph:\nin weighted graph there is a weight associated by edges but in unweighted graph no weight assigned to edges</li>\n</ul>\n<p><img src=\"./assets/3.-Weithened-Graph.png\" alt=\"image\"></p>\n<h3>adjacency matrix</h3>\n<p><img src=\"./assets/GahiR.jpg\" alt=\"image\"></p>\n<h2>adjacency list</h2>\n<p><img src=\"./assets/268857bd-bb32-4fa5-88c9-66d7787952e9.png\" alt=\"image\"></p>\n<h2>adjacency list vs adjacency matrix</h2>\n<table>\n<thead>\n<tr>\n<th align=\"center\">Operation</th>\n<th align=\"center\">Adjacency List</th>\n<th align=\"center\">Adjacency Matrix</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\">Add vertex</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">O(V^2)</td>\n</tr>\n<tr>\n<td align=\"center\">Add Edge</td>\n<td align=\"center\">O(1)</td>\n<td align=\"center\">O(1)</td>\n</tr>\n<tr>\n<td align=\"center\">Remove vertex</td>\n<td align=\"center\">O(V+E)</td>\n<td align=\"center\">O(V^2)</td>\n</tr>\n<tr>\n<td align=\"center\">Remove Edge</td>\n<td align=\"center\">O(E)</td>\n<td align=\"center\">O(1)</td>\n</tr>\n<tr>\n<td align=\"center\">Query</td>\n<td align=\"center\">O(V+E)</td>\n<td align=\"center\">O(1)</td>\n</tr>\n<tr>\n<td align=\"center\">Storage</td>\n<td align=\"center\">O(V+E)</td>\n<td align=\"center\">O(V^2)</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>|V| : number of Vertices</li>\n<li>|E| : number of Edges</li>\n</ul>\n<hr/>\n<ul>\n<li><strong>Adjacency List</strong> take <strong>less space</strong> in sparse graph( when we have a few edges ).</li>\n<li><strong>Adjacency List</strong> are <strong>faster to iterate</strong> over edges.</li>\n<li><strong>Adjacency Matrix</strong> are <strong>faster to</strong> finding a specific edge.</li>\n</ul>\n<h3>graph(adjacency list)</h3>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">AdjacencyList</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token punctuation\">[</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Graph</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">_adjacencyList</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">get</span> <span class=\"token function\">adjacencyList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">set</span> <span class=\"token function\">adjacencyList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> AdjacencyList</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token operator\">:</span> string<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">vertex2</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token operator\">:</span> string<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">vertex2</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span>\n                <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> string</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> value <span class=\"token operator\">!==</span> vertex2\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>\n                    vertex2\n                <span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> string</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> value <span class=\"token operator\">!==</span> vertex1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">removeVertex</span><span class=\"token punctuation\">(</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> string <span class=\"token operator\">|</span> <span class=\"token keyword\">undefined</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> key <span class=\"token keyword\">in</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> vertex<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Graph Traversal</h2>\n<h3>depth first traversal and breadth first traversal in graph</h3>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">AdjacencyList</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token punctuation\">[</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Graph</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">_adjacencyList</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">get</span> <span class=\"token function\">adjacencyList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">set</span> <span class=\"token function\">adjacencyList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> AdjacencyList</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token operator\">:</span> string<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">vertex2</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token operator\">:</span> string<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">vertex2</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span>\n                <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> string</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> value <span class=\"token operator\">!==</span> vertex2\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>\n                    vertex2\n                <span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> string</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> value <span class=\"token operator\">!==</span> vertex1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">removeVertex</span><span class=\"token punctuation\">(</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> string <span class=\"token operator\">|</span> <span class=\"token keyword\">undefined</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> key <span class=\"token keyword\">in</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeEdge</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> vertex<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">dfcRecursive</span><span class=\"token punctuation\">(</span>startingVertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">results</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> adjacencyList <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> currentVertex <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>startingVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentVertex<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">visitedVertex</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">vertex</span><span class=\"token operator\">:</span> string <span class=\"token operator\">|</span> <span class=\"token keyword\">undefined</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>vertex<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>visitedVertex<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    visitedVertex<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n                    results<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>vertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> neighbor <span class=\"token keyword\">of</span> currentVertex<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>visitedVertex<span class=\"token punctuation\">[</span>neighbor<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            currentVertex <span class=\"token operator\">=</span> adjacencyList<span class=\"token punctuation\">[</span>neighbor<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token function\">traverse</span><span class=\"token punctuation\">(</span>neighbor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>startingVertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> results<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">// or</span>\n    <span class=\"token keyword\">public</span> <span class=\"token function\">dfsIterative</span><span class=\"token punctuation\">(</span>startingVertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">results</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>startingVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> <span class=\"token literal-property property\">stack</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>startingVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">visitedVertex</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>stack<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">debugger</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">const</span> currentVertex <span class=\"token operator\">=</span> stack<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentVertex <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>visitedVertex<span class=\"token punctuation\">[</span>currentVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    visitedVertex<span class=\"token punctuation\">[</span>currentVertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n                    results<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>currentVertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    stack <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>stack<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>currentVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> results<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">breadthFirstSearch</span><span class=\"token punctuation\">(</span>startingVertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">results</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>startingVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>startingVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">visitedVertex</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>queue<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">const</span> currentVertex <span class=\"token operator\">=</span> queue<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>currentVertex <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>visitedVertex<span class=\"token punctuation\">[</span>currentVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    visitedVertex<span class=\"token punctuation\">[</span>currentVertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n                    results<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>currentVertex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    queue <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>queue<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>currentVertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> results<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Dijkstra's Shortest path firt Algorithms</h2>\n<p>Finding shortest path between two vertices in a <strong>weighted graph</strong>.</p>\n<p><img src=\"./assets/Dijkstra_Animation.gif\" alt=\"image\"></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">Value</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> any<span class=\"token punctuation\">;</span>\n    <span class=\"token literal-property property\">priority</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">interface</span> <span class=\"token class-name\">Neighbor</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">vertex</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">;</span>\n    <span class=\"token literal-property property\">weight</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">interface</span> <span class=\"token class-name\">AdjacencyList</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token punctuation\">[</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> Neighbor<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// naive priority queue</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">PriorityQueue</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">_values</span><span class=\"token operator\">:</span> Value<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">get</span> <span class=\"token function\">values</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> Value<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span>value<span class=\"token operator\">:</span> any<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">priority</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> Value<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> value<span class=\"token punctuation\">,</span> priority <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">dequeue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> Value <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> value <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> value <span class=\"token keyword\">as</span> Value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">private</span> <span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_values<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> Value<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> Value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a<span class=\"token punctuation\">.</span>priority <span class=\"token operator\">-</span> b<span class=\"token punctuation\">.</span>priority<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">WeightedGraph</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">private</span> <span class=\"token literal-property property\">_adjacencyList</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">get</span> <span class=\"token function\">adjacencyList</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">set</span> <span class=\"token function\">adjacencyList</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> AdjacencyList</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">addVertex</span><span class=\"token punctuation\">(</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> AdjacencyList <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">public</span> <span class=\"token function\">addEdge</span><span class=\"token punctuation\">(</span>vertex1<span class=\"token operator\">:</span> string<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">vertex2</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">weight</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> boolean <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex1<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">vertex</span><span class=\"token operator\">:</span> vertex2<span class=\"token punctuation\">,</span> weight <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">vertex</span><span class=\"token operator\">:</span> vertex1<span class=\"token punctuation\">,</span> weight <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">/*\n    dijkstra shortest path first\n    */</span>\n\n    <span class=\"token function\">dijkstraSPF</span><span class=\"token punctuation\">(</span>startingVertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">targetVertex</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> string<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>startingVertex<span class=\"token punctuation\">]</span> <span class=\"token operator\">&amp;&amp;</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>targetVertex<span class=\"token punctuation\">]</span>\n        <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> pq <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">PriorityQueue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">previousVertex</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> string <span class=\"token operator\">|</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">distances</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>vertex<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token comment\">// build initial states</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> key <span class=\"token keyword\">in</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>key <span class=\"token operator\">===</span> startingVertex<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token punctuation\">(</span>distances<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> pq<span class=\"token punctuation\">.</span><span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    distances<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">Infinity</span><span class=\"token punctuation\">;</span>\n                    pq<span class=\"token punctuation\">.</span><span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> <span class=\"token number\">Infinity</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n                previousVertex<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>pq<span class=\"token punctuation\">.</span>values<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">let</span> smallest <span class=\"token operator\">=</span> pq<span class=\"token punctuation\">.</span><span class=\"token function\">dequeue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>smallest<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>smallest <span class=\"token operator\">===</span> targetVertex<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token comment\">// done build path</span>\n                        <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>\n                            previousVertex<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span>\n                            smallest <span class=\"token operator\">===</span> startingVertex\n                        <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            path<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>smallest<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            smallest <span class=\"token operator\">=</span> previousVertex<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> neighbor <span class=\"token keyword\">of</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">const</span> candidate <span class=\"token operator\">=</span> distances<span class=\"token punctuation\">[</span>smallest<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> neighbor<span class=\"token punctuation\">.</span>weight<span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">let</span> nextNeighbor <span class=\"token operator\">=</span> neighbor<span class=\"token punctuation\">.</span>vertex<span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>candidate <span class=\"token operator\">&lt;</span> distances<span class=\"token punctuation\">[</span>nextNeighbor<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            distances<span class=\"token punctuation\">[</span>nextNeighbor<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> candidate<span class=\"token punctuation\">;</span>\n\n                            previousVertex<span class=\"token punctuation\">[</span>nextNeighbor<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> smallest<span class=\"token punctuation\">;</span>\n\n                            pq<span class=\"token punctuation\">.</span><span class=\"token function\">enqueue</span><span class=\"token punctuation\">(</span>nextNeighbor<span class=\"token punctuation\">,</span> candidate<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Dynamic Programming (light introduction)</h2>\n<p>It's a method for solving a complex problems by breaking it down into a collection of simpler problems, solving their subProblems <strong>once</strong> and <strong>storing</strong> their solutions.\n<em>technically it using knowledge of last problems to solve next by memorization</em></p>\n<h3>example Fibonacci sequence</h3>\n<p>Let's implement it without dynamic programming:without dynamic programming:</p>\n<p><strong><em>in fibonacci sequence fib(n) = fib(n-2) + fib(n-1) &#x26;&#x26; fin(1) = 1 &#x26;&#x26; fib(2) = 1</em></strong></p>\n<p><strong>O(2^n)</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><img src=\"./assets/2-Figure3.1-1.png\" alt=\"image\"></p>\n<p>As you see we calculate f(5) two times with current implementation.</p>\n<h3>memorization</h3>\n<p>Storing the results of expensive function class and returning the cached result when the same inputs occur again.</p>\n<p>O(n)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">memo</span><span class=\"token operator\">:</span> number<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> res <span class=\"token operator\">=</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> memo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    memo<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> res<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> res<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">fib</span><span class=\"token punctuation\">(</span><span class=\"token number\">10000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Maximum callStack exceeded</span></code></pre></div>\n<h3>tabulation</h3>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">fib</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">n</span><span class=\"token operator\">:</span> number</span><span class=\"token punctuation\">)</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> fibNumbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> index <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span> index <span class=\"token operator\">&lt;=</span> n<span class=\"token punctuation\">;</span> index<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        fibNumbers<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> fibNumbers<span class=\"token punctuation\">[</span>index <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> fibNumbers<span class=\"token punctuation\">[</span>index <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>fibNumbers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> fibNumbers<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">fib</span><span class=\"token punctuation\">(</span><span class=\"token number\">10000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Infinity</span></code></pre></div>\n<h2>Interesting Stuff</h2>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// turn it to boolean</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n\n<span class=\"token comment\">// group operation</span>\n<span class=\"token punctuation\">(</span>newNode<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> prevNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>newNode<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> nextNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>String</h2>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> str <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span><span class=\"token punctuation\">;</span>\nstr<span class=\"token punctuation\">.</span><span class=\"token function\">search</span><span class=\"token punctuation\">(</span><span class=\"token string\">'lo'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span><span class=\"token string\">'lo'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// 3</span>\nstr<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span><span class=\"token string\">'lo'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// true</span></code></pre></div>\n<h3>string pattern matching</h3>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// regex.test(str: number) Returns a Boolean value that indicates whether or not a pattern exists in a searched string.</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">charCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">str</span><span class=\"token operator\">:</span> string</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">result</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>key<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> char <span class=\"token keyword\">of</span> str<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        char <span class=\"token operator\">=</span> char<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[a-z0-9]</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            result<span class=\"token punctuation\">[</span>char<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token operator\">++</span>result<span class=\"token punctuation\">[</span>char<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// *** string.chatCodeAt(i: number) Returns the unicode of value on specified location</span>\n\n<span class=\"token comment\">/* \nnumeric (0-9) code > 47 &amp;&amp; code &lt; 58;\nupper alpha (A-Z) code > 64 &amp;&amp; code &lt; 91;\nlower alpha (a-z) code > 96 &amp;&amp; code &lt;123;\n*/</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">charCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">str</span><span class=\"token operator\">:</span> string</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token literal-property property\">result</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>key<span class=\"token operator\">:</span> string<span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> number <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> char <span class=\"token keyword\">of</span> str<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            char <span class=\"token operator\">=</span> char<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            result<span class=\"token punctuation\">[</span>char<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token operator\">++</span>result<span class=\"token punctuation\">[</span>char<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">isAlphaNumeric</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token literal-property property\">char</span><span class=\"token operator\">:</span> string</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> code <span class=\"token operator\">=</span> char<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>code <span class=\"token operator\">></span> <span class=\"token number\">47</span> <span class=\"token operator\">&amp;&amp;</span> code <span class=\"token operator\">&lt;</span> <span class=\"token number\">58</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>code <span class=\"token operator\">></span> <span class=\"token number\">64</span> <span class=\"token operator\">&amp;&amp;</span> code <span class=\"token operator\">&lt;</span> <span class=\"token number\">91</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>code <span class=\"token operator\">></span> <span class=\"token number\">96</span> <span class=\"token operator\">&amp;&amp;</span> code <span class=\"token operator\">&lt;</span> <span class=\"token number\">123</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2>Array</h2>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> array <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'world'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">find</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">el</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> el <span class=\"token operator\">===</span> <span class=\"token string\">'world'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// world</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">findIndex</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">el</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> el <span class=\"token operator\">===</span> <span class=\"token string\">'world'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1</span>\n\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\n\nArray<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">length</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">[</span><span class=\"token string\">'lol'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [[\"lol\"], [\"lol\"]]</span>\n\n<span class=\"token keyword\">const</span> stack <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'B'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'D'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'E'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'C'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'F'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> s <span class=\"token operator\">=</span> stack<span class=\"token punctuation\">.</span><span class=\"token function\">shift</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> p <span class=\"token operator\">=</span> stack<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"A\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"F\"</span>\n\n<span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">reverse</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ['b', 'a']</span></code></pre></div>\n<h3>Object</h3>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">[</span>vertex<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// delete key and value from object</span>\n<span class=\"token keyword\">delete</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_adjacencyList<span class=\"token punctuation\">.</span>vertex<span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Map</h3>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> map <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// store any type of **unique key** of use duplicate key it will override last value</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token number\">1</span><span class=\"token operator\">:</span> <span class=\"token string\">'Object'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Object'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token string\">'arr'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'arr'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'number'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'boolean'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmap<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>map<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/* \n0: {Object => \"Object\"}\n1: {Array(1) => \"arr\"}\n2: {1 => \"number\"}\n3: {false => \"boolean\"}\n4: {function () { return console.log(\"Function\"); } => \"Function\"}\n*/</span>\n\n<span class=\"token comment\">// iterable by **for (let [key, value] of map)**</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">]</span> <span class=\"token keyword\">of</span> map<span class=\"token punctuation\">)</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// map to arr</span>\n<span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>map<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// :[ [key, value] ]</span>\n<span class=\"token comment\">/* \n0: (2) [{…}, \"Object\"]\n1: (2) [Array(1), \"arr\"]\n2: (2) [1, \"number\"]\n3: (2) [false, \"boolean\"]\n4: (2) [ƒ, \"Function\"]\n*/</span></code></pre></div>\n<h2>Math</h2>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">Math<span class=\"token punctuation\">.</span><span class=\"token function\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 4</span>\nMath<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 5</span>\nMath<span class=\"token punctuation\">.</span><span class=\"token function\">log10</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 10</span>\nMath<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 3</span>\nMath<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1</span></code></pre></div>"},{"url":"/docs/tips/httrack/","relativePath":"docs/tips/httrack/index.md","relativeDir":"docs/tips/httrack","base":"index.md","name":"index","frontmatter":{"title":"HTTRACK","template":"docs","excerpt":"Httrack is a program that gets information from the Internet"},"html":"<h2>Basics</h2>\n<p>Httrack is a program that gets information from the Internet, looks for pointers to other information, gets that information, and so forth. If you ask it to, and have enough disk space, it will try to make a copy of the whole Internet on your computer. While this may be the answer to Dilbert's boss when he asks to get a printout of the Internet for some legal document, for most of us, we want to get copies of just the right part of the Internet, and have them nicely organized for our use. This is where httrack does a great job. Here's a simple example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">httrack \"http://www.all.net/\" -O \"/tmp/www.all.net\" \"+*.all.net/*\" -v</code></pre></div>\n<p>In this example, we ask httrack to start the Universal Resource Locator (URL) <a href=\"http://www.all.net/\">http://www.all.net/</a> and store the results under the directory /tmp/www.all.net (the -O stands for \"output to\") while not going beyond the bounds of all the files in the www.all.net domain and printing out any error messages along the way (-v means verbose). This is the most common way that I use httrack. Please note that this particular command might take you a while - and run you out of disk space.</p>\n<p>This sort of a mirror image is not an identical copy of the original web site - in some ways it's better such as for local use - while in other ways it may be problematic - such as for legal use. This default mirroring method changes the URLs within the web site so that the references are made relative to the location the copy is stored in. This makes it very useful for navigating through the web site on your local machine with a web browser since most things will work as you would expect them to work. In this example, URLs that point outside of the www.all.net domain space will still point there, and if you encounter one, the web browser will try to get the data from that location.</p>\n<p>For each of the issues discussed here - and many more - httrack has options to allow you to make different choices and get different results. This is one of the great things about httrack - and one of the the real major problems with using it without the knowledge of all that it can do. If you want to know all the things httrack can do, you might try typing:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">httrack --help</code></pre></div>\n<p>Unfortunately, while this outputs a though list of options, it is somewhat less helpful it might be for those who don't know what the options all mean and haven't used them before. On the other hand, this is most useful for those who already know how to use the program but don't remember some obscure option that they haven't used for some time.</p>\n<p>The rest of this manual is dedicated to detailing what you find in the help message and providing examples - lots and lots of examples... Here is what you get (page by page - use to move to the next page in the real program) if you type 'httrack --help':</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">>httrack --help\n HTTrack version 3.03BETAo4 (compiled Jul  1 2001)\nusage: ./httrack ] [-]\nwith options listed below: (* is the default value)\n\nGeneral options:\n  O  path for mirror/logfiles+cache (-O path_mirror[,path_cache_and_logfiles]) (--path )\n %O  top path if no path defined (-O path_mirror[,path_cache_and_logfiles])\n\nAction options:\n  w *mirror web sites (--mirror)\n  W  mirror web sites, semi-automatic (asks questions) (--mirror-wizard)\n  g  just get files (saved in the current directory) (--get-files)\n  i  continue an interrupted mirror using the cache\n  Y   mirror ALL links located in the first level pages (mirror links) (--mirrorlinks)\n\nProxy options:\n  P  proxy use (-P proxy:port or -P user:pass@proxy:port) (--proxy )\n %f *use proxy for ftp (f0 don't use) (--httpproxy-ftp[=N])\n\nLimits options:\n  rN set the mirror depth to N (* r9999) (--depth[=N])\n %eN set the external links depth to N (* %e0) (--ext-depth[=N])\n  mN maximum file length for a non-html file (--max-files[=N])\n  mN,N'                  for non html (N) and html (N')\n  MN maximum overall size that can be uploaded/scanned (--max-size[=N])\n  EN maximum mirror time in seconds (60=1 minute, 3600=1 hour) (--max-time[=N])\n  AN maximum transfer rate in bytes/seconds (1000=1kb/s max) (--max-rate[=N])\n %cN maximum number of connections/seconds (*%c10)\n  GN pause transfer if N bytes reached, and wait until lock file is deleted (--max-pause[=N])\n\nFlow control:\n  cN number of multiple connections (*c8) (--sockets[=N])\n  TN timeout, number of seconds after a non-responding link is shutdown (--timeout)\n  RN number of retries, in case of timeout or non-fatal errors (*R1) (--retries[=N])\n  JN traffic jam control, minimum transfert rate (bytes/seconds) tolerated for a link (--min-rate[=N])\n  HN host is abandonned if: 0=never, 1=timeout, 2=slow, 3=timeout or slow (--host-control[=N])\n\nLinks options:\n %P *extended parsing, attempt to parse all links, even in unknown tags or Javascript (%P0 don't use) (--extended-parsing[=N])\n  n  get non-html files 'near' an html file (ex: an image located outside) (--near)\n  t  test all URLs (even forbidden ones) (--test)\n %L )\n\nBuild options:\n  NN structure type (0 *original structure, 1+: see below) (--structure[=N])\n     or user defined structure (-N \"%h%p/%n%q.%t\")\n  LN long names (L1 *long names / L0 8-3 conversion) (--long-names[=N])\n  KN keep original links (e.g. http://www.adr/link) (K0 *relative link, K absolute links, K3 absolute URI links) (--keep-links[=N])\n  x  replace external html links by error pages (--replace-external)\n %x  do not include any password for external password protected websites (%x0 include) (--no-passwords)\n %q *include query string for local files (useless, for information purpose only) (%q0 don't include) (--include-query-string)\n  o *generate output html file in case of error (404..) (o0 don't generate) (--generate-errors)\n  X *purge old files after update (X0 keep delete) (--purge-old[=N])\n\nSpider options:\n  bN accept cookies in cookies.txt (0=do not accept,* 1=accept) (--cookies[=N])\n  u  check document type if unknown (cgi,asp..) (u0 don't check, * u1 check but /, u2 check always) (--check-type[=N])\n  j *parse Java Classes (j0 don't parse) (--parse-java[=N])\n  sN follow robots.txt and meta robots tags (0=never,1=sometimes,* 2=always) (--robots[=N])\n %h  force HTTP/1.0 requests (reduce update features, only for old servers or proxies) (--http-10)\n %B  tolerant requests (accept bogus responses on some servers, but not standard!) (--tolerant)\n %s  update hacks: various hacks to limit re-transfers when updating (identical size, bogus response..) (--updatehack)\n %A  assume that a type (cgi,asp..) is always linked with a mime type (-%A php3=text/html) (--assume )\n\nBrowser ID:\n  F  user-agent field (-F \"user-agent name\") (--user-agent )\n %F  footer string in Html code (-%F \"Mirrored [from host %s [file %s [at %s]]]\" (--footer )\n %l  preffered language (-%l \"fr, en, jp, *\" (--language )\n\nLog, index, cache\n  C  create/use a cache for updates and retries (C0 no cache,C1 cache is prioritary,* C2 test update before) (--cache[=N])\n  k  store all files in cache (not useful if files on disk) (--store-all-in-cache)\n %n  do not re-download locally erased files (--do-not-recatch)\n %v  display on screen filenames downloaded (in realtime) (--display)\n  Q  no log - quiet mode (--do-not-log)\n  q  no questions - quiet mode (--quiet)\n  z  log - extra infos (--extra-log)\n  Z  log - debug (--debug-log)\n  v  log on screen (--verbose)\n  f *log in files (--file-log)\n  f2 one single log file (--single-log)\n  I *make an index (I0 don't make) (--index)\n %I  make an searchable index for this mirror (* %I0 don't make) (--search-index)\n\nExpert options:\n  pN priority mode: (* p3) (--priority[=N])\n      0 just scan, don't save anything (for checking links)\n      1 save only html files\n      2 save only non html files\n     *3 save all files\n      7 get html files before, then treat other files\n  S  stay on the same directory\n  D *can only go down into subdirs\n  U  can only go to upper directories\n  B  can both go up&amp;down into the directory structure\n  a *stay on the same address\n  d  stay on the same principal domain\n  l  stay on the same TLD (eg: .com)\n  e  go everywhere on the web\n %H  debug HTTP headers in logfile (--debug-headers)\n\nGuru options: (do NOT use)\n #0  Filter test (-#0 '*.gif' 'www.bar.com/foo.gif')\n #f  Always flush log files\n #FN Maximum number of filters\n #h  Version info\n #K  Scan stdin (debug)\n #L  Maximum number of links (-#L1000000)\n #p  Display ugly progress information\n #P  Catch URL\n #R  Old FTP routines (debug)\n #T  Generate transfer ops. log every minutes\n #u  Wait time\n #Z  Generate transfer rate statictics every minutes\n #!  Execute a shell command (-#! \"echo hello\")\n\nCommand-line specific options:\n  V execute system command after each files ($0 is the filename: -V \"rm \\$0\") (--userdef-cmd )\n %U run the engine with another id when called as root (-%U smith) (--user )\n\nDetails: Option N\n  N0 Site-structure (default)\n  N1 HTML in web/, images/other files in web/images/\n  N2 HTML in web/HTML, images/other in web/images\n  N3 HTML in web/,  images/other in web/\n  N4 HTML in web/, images/other in web/xxx, where xxx is the file extension(all gif will be placed onto web/gif, for example)\n  N5 Images/other in web/xxx and HTML in web/HTML\n  N99 All files in web/, with random names (gadget !)\n  N100 Site-structure, without www.domain.xxx/\n  N101 Identical to N1 exept that \"web\" is replaced by the site's name\n  N102 Identical to N2 exept that \"web\" is replaced by the site's name\n  N103 Identical to N3 exept that \"web\" is replaced by the site's name\n  N104 Identical to N4 exept that \"web\" is replaced by the site's name\n  N105 Identical to N5 exept that \"web\" is replaced by the site's name\n  N199 Identical to N99 exept that \"web\" is replaced by the site's name\n  N1001 Identical to N1 exept that there is no \"web\" directory\n  N1002 Identical to N2 exept that there is no \"web\" directory\n  N1003 Identical to N3 exept that there is no \"web\" directory (option set for g option)\n  N1004 Identical to N4 exept that there is no \"web\" directory\n  N1005 Identical to N5 exept that there is no \"web\" directory\n  N1099 Identical to N99 exept that there is no \"web\" directory\nDetails: User-defined option N\n  %n Name of file without file type (ex: image) (--do-not-recatch)\n  %N Name of file, including file type (ex: image.gif)\n  %t File type (ex: gif)\n  %p Path [without ending /] (ex: /someimages)\n  %h Host name (ex: www.someweb.com) (--http-10)\n  %M URL MD5 (128 bits, 32 ascii bytes)\n  %Q query string MD5 (128 bits, 32 ascii bytes)\n  %q small query string MD5 (16 bits, 4 ascii bytes) (--include-query-string)\n     %s? Short name version (ex: %sN)\n  %[param] param variable in query string\n\nShortcuts:\n--mirror      \n\n For many of you, the manual is now complete, but for\nthe rest of us, I will now go through this listing one item at a time\nwith examples... I will be here a while...\n\n\n Syntax \n\nhttrack  [-option] [+] [-] \n\n The syntax of httrack is quite simple.  You specify\nthe URLs you wish to start the process from (), any options you\nmight want to add ([-option], any filters specifying places you should\n([+]) and should not ([-]) go, and end the command\nline by pressing .  Httrack then goes off and does your bidding.\nFor example:\n\n\nhttrack www.all.net/bob/\n\n\n This will use the 'defaults' (those selections from\nthe help page marked with '*' in the listing above) to image the web\nsite. Specifically, the defauls are:\n\n  w *mirror web sites\n %f *use proxy for ftp (f0 don't use)\n  cN number of multiple connections (*c8)\n  RN number of retries, in case of timeout or non-fatal errors (*R1)\n %P *extended parsing, attempt to parse all links, even in unknown tags or Javascript (%P0 don't use)\n  NN  name conversion type (0 *original structure, 1+: see below)\n  LN  long names (L1 *long names / L0 8-3 conversion)\n  K   keep original links (e.g. http://www.adr/link) (K0 *relative link)\n  o *generate output html file in case of error (404..) (o0 don't generate)\n  X *purge old files after update (X0 keep delete)\n  bN  accept cookies in cookies.txt (0=do not accept,* 1=accept)\n  u check document type if unknown (cgi,asp..) (u0 don't check, * u1 check but /, u2 check always)\n  j *parse Java Classes (j0 don't parse)\n  sN  follow robots.txt and meta robots tags (0=never,1=sometimes,* 2=always)\n  C  create/use a cache for updates and retries (C0 no cache,C1 cache is prioritary,* C2 test update before)\n  f *log file mode\n  I *make an index (I0 don't make)\n  pN priority mode: (* p3)  *3 save all files\n  D  *can only go down into subdirs\n  a  *stay on the same address\n  --mirror       *make a mirror of site(s) (default)\n\n\n Here's what all of that means:\n\n\n  w *mirror web sites \n\n Automatically go though each URL you download and look\nfor links to other URLs inside it, dowloading them as well. \n\n %f *use proxy for ftp (f0 don't use) \n\n If there are and links to ftp URLs (URLs using the\nfile transfer protocol (FTP) rather than the hypertext transfer protocol\nHTTP), go through an ftp proxy server to get them.\n\n  cN number of multiple connections (*c8) \n\n Use up to 8 simultaneous downloads so that at any\ngioven time, up to 8 URLs may be underway. \n\n  RN number of retries, in case of timeout or non-fatal errors (*R1) \n\n Retry once if anything goes wrong with a download. \n\n %P *extended parsing, attempt to parse all links, even in unknown tags or Javascript (%P0 don't use) \n\n Try to parse all URLs - even if they are in\nJavascript, Java, tags of unknown types, or anywhere else the program\ncan find things. \n\n  NN  name conversion type (0 *original structure, 1+: see below) \n\n Use the original directory and file structure of the\nweb site in your mirror image of the site.\n\n  LN  long names (L1 *long names / L0 8-3 conversion) \n\n If filenames do not follow the old DOS conventions,\nstore them with the same names used on the web site.\n\n  K   keep original links (e.g. http://www.adr/link) (K0 *relative link) \n\n Use relative rather than the original links so that\nURLs within this web site are adjusted to point to the files in the\nmirror.\n\n  o *generate output html file in case of error (404..) (o0 don't generate) \n\n IF there are errors in downloading, create a file that\nindicates that the URL was not found.  This makes browsing go a lot\nsmoother.\n\n  X *purge old files after update (X0 keep delete) \n\n Files not found on the web site that were previously\nthere get deleted so that you have an accurate snapshot of the site as\nit is today - losing historical data. \n\n  bN  accept cookies in cookies.txt (0=do not accept,* 1=accept) \n\n Accept all cokkies sent to you and return them if\nrequested.  This is required for many sites to function.  These cookies\nare only kept relative to the specific site, so you don't have to worry\nabout your browser retaining them.\n\n  u check document type if unknown (cgi,asp..) (u0 don't check, * u1 check but /, u2 check always) \n\n This causes different document types to be analyzed\ndifferently.\n\n  j *parse Java Classes (j0 don't parse) \n\n This causes Java class files to be parsed looking for\nURLs.\n\n  sN  follow robots.txt and meta robots tags (0=never,1=sometimes,* 2=always) \n\n This tells the program to follow the wishes of the\nsite owner with respect to limiting where robots like this one search. \n\n  C  create/use a cache for updates and retries (C0 no cache,C1 cache is prioritary,* C2 test update before) \n\n If you are downloading a site you have a previous copy\nof, supplemental parameters are transmitted to the server, for example\nthe 'If-Modified-Since:' field will be used to see if files are newer\nthan the last copy you have.  If they are newer, they will be\ndownloaded, otherwise, they will not. \n\n  f *log file mode \n\n This retains a detailed log of any important events\nthat took place. \n\n  I *make an index (I0 don't make) \n\n This makes a top-level index.html file so that if you\nimage a set of sites, you can have one place to start reviewing the set\nof sites. \n\n  pN priority mode: (* p3)  *3 save all files \n\n This will cause all downloaded files to be saved. \n\n  D  *can only go down into subdirs \n\n This prevents the program from going to higher level\ndirectories than the initial subdirectory, but allows lower-level\nsubdirectories of the starting directory to be investigated. \n\n  a  *stay on the same address \n\n This indicates that only the web site(s) where the\nsearch started are to be collected.  Other sites they point to are not\nto be imaged. \n\n  --mirror       *make a mirror of site(s) (default) \n\n This indicates that the program should try to make a\ncopy of the site as well as it can. \n\n\n\n Now that's a lot of options for the default - but of\ncourse there are a lot more options to go.  For the most part, the rest\nof the options represent variations on these themes.  For example,\ninstead of saving all files, we might only want to save html files, or\ninstead of 8 simultaneous sessions, we might want only 4.\n\n If we wanted to make one of these changes, we would\nspecify the option on the command line. For example:\n\n\nhttrack www.all.net/bob/ -c4 -B\n\n\n This would restrict httrack to only use 4\nsiumultaneous sessions but allow it to go up the directory structure\n(for example to www.all.net/joe/) as well as down it (for example to\nwww.all.net/bob/deeper/).\n\n You can add a lot of options to a command line!\n\n\n\n A Thorough Going Over \n\n Now that you have an introduction, it's time for a\nmore though coverage.  This is where I go through each of the options\nand describe it in detail with examples...  Actually, I won't quite do\nthat.  But I will get close.\n\n Options tend to come in groups.  Each group tends to\nbe interrelated, so it's easier and more useful to go through them a\ngroup at a time with some baseline project in mind.  In my case, the\nproject is to collect all of the information on the Internet about some\ngiven subject.  We will assume that, through a previous process, I have\ngotten a list of URLs of interest to me.  Typically there will be\nhundreds of these URLs, and they will be a mixed bag of sites that are\nfull of desired information, pages with lists of pointers to other\nsites, URLs of portions of a web site that are of interest (like Bob's\nhome pages and subdirectories), and so forth.  Let us say that for today\nwe are looking for the definitive colleciton of Internet information on\nshoe sizes from around the world. \n\n\nGeneral Options\n\n\nGeneral options:\n  O  path for mirror/logfiles+cache (-O path_mirror[,path_cache_and_logfiles])\n\n\n For this project, I will want to keep all of the\ninformation I gather in one place, so I will specify that output area of\nthe project as /tmp/shoesizes by adding '-O\n/tmp/shoesizes' to every command line I use.. for example:\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes\n\n\n The action options tell httrack how to operate at the\nlarger level.\n\n\nAction Options\n\n\nAction options:\n  w *mirror web sites\n  W  mirror web sites, semi-automatic (asks questions)\n  g  just get files (saved in the current directory)\n  i  continue an interrupted mirror using the cache\n  Y   mirror ALL links located in the first level pages (mirror links)\n\n\n If I want httrack to ask me questions - such as what\noptions to use, what sites to mirror, etc.  I can tell it to ask these\nquestions as follows:\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -W\n\n I can also do:\n\nhttrack\nOR\nhttrack -W\nOR\nhttrack -w\n\n The '-W' options asks whether the or not a site has to\nbe mirrored, while the '-w' option does not ask this question but asks\nthe remainder of the questions required to mirror the site.\n\n The -g option allows you to get the files exactly as\nthey are and store them in the current directory.  This is handy for a\nrelatively small collection of information where organization isn't\nimportant.  With this option, the html files will not even be parsed to\nlook for other URLs.  This option is useful for getting isolated files\n(e.g., httrack -g www.mydrivers.com/drivers/windrv32.exe). \n\n\n If I start a collection process and it fails for ome\nreason or another - such as me interrupting it because I am running out\nof disk space - or a network outage - then I can restart the process by\nusing the -i option:\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -i \n\n Finally, I can mirror all links in the first level\npages of the URLs I specify.  A good example of where to use whis would\nbe in a case where I have a page that points to a lot of other sites and\nI want to get the initial information on those sites before mirroring\nthem:\n\nhttrack http://www.shoesizes.com/othersites.html -O /tmp/shoesizes -Y \n\n\nProxy Options\n\n Many users use a proxy for many of their functions. \nThis is a key component in many firewalls, but it is also commonly used\nfor anonymizing access and for exploiting higher speed communications at\na remote server.\n\nProxy options:\n  P  proxy use (-P proxy:port or -P user:pass@proxy:port)\n %f *use proxy for ftp (f0 don't use)\n\n\n If you are using a standard proxy that doesn't require\na user ID and password, you would do something like this:\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -P proxy.www.all.net:8080 \n\n In this case, we have asusmed that proxy.www.all.net is\nthe host that does the proxy service and that it uses port 8080 for this\nservice.  In some cases you will have to ask your network or firewall\nadministrator for these details, however, in most cases they should be\nthe same as the options used in your web browser.\n\n In some cases, a user ID and password are required for\nthe proxy server.  This is common in corporate environments where only\nauthorized users may access the Internet.\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -P fc:password@proxy.www.all.net:8080 \n\n In this case, the user ID 'fc' and the password\n'password' are used on proxy.www.all.net port 8080.  Again, your network or\nfirewall administrator can be most helpful in addressing the specifics\nfor your environment. \n\n FTP normally operates through a proxy server, but for systems\nthat have direct connections to the Internet, the following option should help:\n\nhttrack ftp://ftp.shoesizes.com -O /tmp/shoesizes -%f0 \n\n\nLimits Options\n\n\nLimits options:\n  rN set the mirror depth to N\n  mN maximum file length for a non-html file\n  mN,N'                  for non html (N) and html (N')\n  MN maximum overall size that can be uploaded/scanned\n  EN maximum mirror time in seconds (60=1 minute, 3600=1 hour)\n  AN maximum transfer rate in bytes/seconds (1000=1kb/s max)\n  GN pause transfer if N bytes reached, and wait until lock file is deleted\n  %eN set the external links depth to N (* %e0) (--ext-depth[=N])\n  %cN maximum number of connections/seconds (*%c10)\n\n\n Setting limits provides the means by which you can\navoid running out of disk space, CPU time, and so forth.  This may be\nparticularly helpful for those who accidentally try to image the whole\nInternet. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -r50\n\n\n In this example, we limit the directlry depth to 50\nlevels deep.  As a general rule, web sites don't go much deeper than 20\nlevels or so, and if you think about it, if there are only 2\nsubdirectories per directory level, a directory structure 50 deep would\nhave about 10 trillion directories.  Of course many sites have a small\nnumber of files many levels deep in a directory structure for various\nreasons.  In some cases, a symbolic link will cause an infinite\nrecursion of directory levels as well, so placing a limit may be\nadvisable.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -m50000000\n\n\n This example sets the maximum file length for non-HTML\nfiles to 50 megabytes.  This is not an unusual length for things like\ntar files, and in some cases - for example when there are images of\nCD-ROMs to fetch from sites, you might want a limit more like 750\nmegabytes.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -m50000000,100000\n\n\n In this example, we have set a limit for html files\nas well - at 100,000 bytes.  HTML files are rarely larger than this,\nhowever, in some cases larger sizes may be needed. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -M1000000000\n\n\n This option sets the maximum total size - in bytes -\nthat can be uploaded from a site - in this case to 1 gigabyte. \nDepending on how much disk space you have, such an option may be\nworthwhile.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -E3600\n\n\n This sets the maximum runtime for the download\nprocess.  Of course depending on the speed of your connection it may\ntake longer or shorter runtimes to get the same job done, and network\ntraffic is also a factor.  3600 seconds corresponds to one hour. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes A100000000\n\n\n This option specifies the largest number of bytes per\nsecond that should be used for transfers.  For example, you might want\nto go slow for some servers that are heavily loaded in the middle of the\nday, or to download slowly so that the servers at the other end are less\nlikely to identify you as mirroring their site.  The setting above\nlimits my bandwidth to 100 million bytes per second - slow I know, but I\nwouldn't want to stress the rest of the Internet.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -G100000000\n\n\n In this case, the G option is used to 'pause' a\ndownload after the first gigabyte is downloaded pending manual removal\nof the lockfile.  This is handy of you want to download some portion of\nthe data, move it to secondary storage, and then continue - or if you\nwant to only download overnight and want to stop before daylight and\ncontinue the next evening.  You could even combine this option with a\ncron job to remove the lock file so that the job automatically restarts\nat 7PM every night and gets another gigabyte.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes %e5\n\n\n In this case, httrack will only go to depth 5 for external links,\nthus not imaging the entire web, but only yhose links within 5 links of these web pages.\n\n Also note that the interaction of these options may\ncause unintended consequences.  For example, limiting bandwidth and\ndownload time conspire to limit the total amount of data that can\nbe downloaded.\n\n\nFlow Control Options\n\n\nFlow control:\n  cN number of multiple connections (*c8)\n  %cN maximum number of connections/seconds (*%c10)\n  TN timeout, number of seconds after a non-responding link is shutdown\n  RN number of retries, in case of timeout or non-fatal errors (*R1)\n  JN traffic jam control, minimum transfert rate (bytes/seconds) tolerated for a link\n  HN host is abandonned if: 0=never, 1=timeout, 2=slow, 3=timeout or slow\n\n\n This example allows up to 128 simultaneous downloads. \nNote that this is likely to crash remote web servers - or at least fail\nto download many of the files - because of limits on the number of\nsimultaneous sessions at many sites.  At busy times of day, you might\nwant to lower this to 1 or 2, especially at sites that limit the number\nof simultaneous users. Otherwise you will not get all of the downloads.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -c128\n\n\n Many operating systems have a limit of 64 file\nhandles, including internet connections and all other files that can be\nopened.  Therefore, in many cases, more that 48 connections might cause\na \"socket error\" because the OS can not handle that many sockets.  This\nis also true for many servers.  As an example, a test with 48 sockets on\na cgi-based web server (Pentium 166,80Meg RAM) overloaded the machine\nand stopped other services from running correctly.  Some servers will\nban users that try to brutally download the website.  8 sockets is\ngenerally good, but when I'm getting large files (e.g., from a a site\nwith large graphical images) 1 or 2 sockets is a better selection.  Here\nare some other figures from one sample set of runs:\n\nTests: on a 10/100Mbps network, 30MB website, 99 files (70 images (some are\nlittle, other are big (few MB)), 23 HTML)\nWith 8 sockets: 1,24MB/s\nWith 48 sockets: 1,30MB/s\nWith 128 sockets: 0,93MB/s\n\n\n The timeout option causes downloads to time out after\na non-response from a download attempt.  30 seconds is pretty reasonable\nfor many sites.  You might want to increase the number of retries as\nwell so that you try again and again after such timeouts. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -%c20\n\n\n This limits the number of connections per second.  It\nis similar to the above option but allows the pace to be controlled\nrather than the simultanaety.  It is particulsrly useful for long-term\npulls at low rates that allow little impact on remote infrastructure.\nThe default is 10 connections per second.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -T30\n\n\n This example increases the number of retries to 5. \nThis means that if a download fails 5 times, httrack will give up on it. \nFor relatively unreliable sites - or for busy times of day, this number\nshould be higher.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -R5\n\n\n This is an interesting option.  It says that in a\ntraffic jam - where downloads are excessively slow - we might decide to\nback off the download.  In this case, we have limited downloads to stop\nbothering once we reach 10 bytes per second.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -J10\n\n\n These three options will cause the download from a\nhost to be abandoned if (respectively) (0) never, (1) a timeout is\nreached, (2) slow traffic is detected, (or) (3) a timeout is reached OR\nslow traffic is detected. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -H0\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -H1\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -H2\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -H3\n\n\n Of course these options can be combined to provide a\npowerful set of criteria for when to continue a download and when to\ngive it up, how hard to push other sites.  and how much to stress\ninfrastructures. \n\n\nLink Following Options\n\n\nLinks options:\n %P *extended parsing, attempt to parse all links, even in unknown tags or Javascript (%P0 don't use)\n  n   get non-html files 'near' an html file (ex: an image located outside)\n  t   test all URLs (even forbidden ones)\n %L  add all URL located in this text file (one URL per line)\n\n\n The links options allow you to control what links are\nfollowed and what links are not as well as to provide long lists of\nlinks to investigate.  Any setting other than the default for this\noption forces the engine to use less reliable and more complex parsing. \n'Dirty' parsing means that links like 'xsgfd syaze=\"foo.gif\"' will cause\nHTTrack to download foo.gif, even if HTTrack don't know what the \"xsgfd\nsyaze=\" tag actually means! This option is powerful because some links\nmight otherwise be missed, but it can cause errors in HTML or javascript.\n\n This will direct the program to NOT search Javascript\nfor unknown tag fields (e.g., it will find things like\nfoo.location=\"bar.html\"; but will not find things like bar=\"foo.gif\";). \nWhile I have never had a reason to use this, some users may decide that\nthey want to be more conservative in their searches.  As a note,\njavascript imported files (.js) are not currently searched for URLs.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes '%P0'\n\n\n Now here is a classic bit of cleaverness that 'does\nthe right thing' for some cases.  In this instance, we are asking\nhttrack to get images - like gif and jpeg files that are used by a web\npage in its display, even though we would not normally get them.  For\nexample, if we were only getting a portion of a web site (e.g.,\neverything under the 'bob directory') we might want to get graphics from\nthe rest of the web sote - or the rest of the web - that are used in\nthose pages as well so that our mirror will look right.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -n\n\n\n Here, we limit the collection to bob's area of the\nserver - except that we get images and other such things that are used\nby bob in his area of the server.\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -n\n\n\n This option 'tests' all links - even those forbidden\n(by the robot exclusion protocol) - by using the 'HEAD' protocol to test\nfor the presence of a file. \n\n\nhttrack http://www.shoesizes.com/ -O /tmp/shoesizes -t\n\n\n In this case, we use a file to list the URLs we wish\nto mirror.  This is particularly useful when we have a lot to do and\ndon't want to tirelessly type in URLs on command line after command line. \nIt's also useful - for example - if you update a set of mirrored sites\nevey evening.  You can set up a command like this to run automatically\nfrom your cron file.\n\n\nhttrack -%L linkfile -O /tmp/shoesizes\n\n\n This will update the mirror of your list of sites\nwhenever it is run. \n\n\nhttrack -%L linkfile -O /tmp/shoesizes -B --update\n\n\n The link file is also useful for things like this\nexample where, after a binary image of a hard disk was analyzed (image)\nURLs found on that disk were collected by httrack:\n\n\nstrings image | grep \"http://\" > list;\nhttrack -%L list -O /tmp/shoesizes\n\n\n\n\nMirror Build Options\n\n\nBuild options:\n  NN  name conversion type (0 *original structure, 1+: see below)\n  N   user defined structure (-N \"%h%p/%n%q.%t\")\n  LN  long names (L1 *long names / L0 8-3 conversion)\n  K   keep original links (e.g. http://www.adr/link) (K0 *relative link)\n  x   replace external html links by error pages\n  o *generate output html file in case of error (404..) (o0 don't generate)\n  X *purge old files after update (X0 keep delete)\n  %x  do not include any password for external password protected websites (%x0 include) (--no-passwords)\n  %q *include query string for local files (information only) (%q0 don't include) (--include-query-string)\n\n\n The user can define naming conventions for building\nthe mirror of a site by using these options.  For example, to retain the\noriginal structure, the default is used.  This only modifies the\nstructure to the extent that select characters (e.g., ~, :, &lt;, >, \\, and\n@) are replaced by _ in all pathnames. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -N0\n\n OR\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes\n\n\n In either case, the mirror will build with the same\ndirectory hierarchy and name structure as the original site.  For cases\nwhen you want to define your own structure, you use a string like this:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -N \"%h%p/%n.%t\"\n\n\n In this case, %h, %p, $n, and %t stand for the href\nelement (e.g., http://www.shoesizes.com or ftp://ftp.shoesizes.com), %p\nstands for the pathname (e.g., /bob/), %n stands for the name of the\nfile, and %t stands for type (file extension).  The full list of these\noptions follows:\n\n%n      Name of file without file type (ex: image)\n%N      Name of file, including file type (ex: image.gif)\n%t      File type (ex: gif)\n%p      Path [without ending /] (ex: /someimages)\n%h      Host name (ex: www.all.net)\n%M      URL MD5 (128 bits, 32 ascii bytes)\n%Q      query string MD5 (128 bits, 32 ascii bytes)\n%q      small query string MD5 (16 bits, 4 ascii bytes)\n%s?     Short name version (ex: %sN)\n\n\n Other 'N' options include:\n\n\n\nDetails: Option N\n  N0 Site-structure (default)\n  N1 HTML in web/, images/other files in web/images/\n  N2 HTML in web/HTML, images/other in web/images\n  N3 HTML in web/,  images/other in web/\n  N4 HTML in web/, images/other in web/xxx, where xxx is the file extension(all gif will be placed onto web/gif, for example)\n  N5 Images/other in web/xxx and HTML in web/HTML\n  N99 All files in web/, with random names (gadget !)\n  N100 Site-structure, without www.domain.xxx/\n  N101 Identical to N1 exept that \"web\" is replaced by the site's name\n  N102 Identical to N2 exept that \"web\" is replaced by the site's name\n  N103 Identical to N3 exept that \"web\" is replaced by the site's name\n  N104 Identical to N4 exept that \"web\" is replaced by the site's name\n  N105 Identical to N5 exept that \"web\" is replaced by the site's name\n  N199 Identical to N99 exept that \"web\" is replaced by the site's name\n  N1001 Identical to N1 exept that there is no \"web\" directory\n  N1002 Identical to N2 exept that there is no \"web\" directory\n  N1003 Identical to N3 exept that there is no \"web\" directory (option set for g option)\n  N1004 Identical to N4 exept that there is no \"web\" directory\n  N1005 Identical to N5 exept that there is no \"web\" directory\n  N1099 Identical to N99 exept that there is no \"web\" directory\n\n\n\n Long names are normally used (the -L0\noption) but if you are imaging to a DOS file system or want\naccessibility from older versions of DOS and Windows, you can use the\n-L1 option to generate these filename sizes. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -L1\n\n\n With the 'K' option, you can keep the original links\nin files.  While this is less useful in being able to view a web site\nfroim the mirrored copy, it is vitally important if you want an accurate\ncopy of exactly what was on the web site in the first place.  In a\nforensic image, for example, you might want to use this option to\nprevent the program from modifying the data as it is collected. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -K\n\n\n In this case, instead of leaving external links (URLs\nthat point to sites not being mirrored) in the pages, these links are\nreplaced by pages that leave messages indicating that they could not be\nfound.  This is useful for local mirrors not on the Internet or mirrors\nthat are on the Internet but that are not supposed to lead users to\nexternal sites.  A really good use for this is that 'bugging' devices\nplaced in web pages to track who is using them and from where will be\ndeactivated byt his process. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -x\n\n\n This option prevents the generation of '404' error\nfiles to replace files that were not found even though there were URLs\npointing to them.  It is useful for saving space as well as eliminating\nunnecessary files in operations where a working web site is not the\ndesired result. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -o0\n\n\n This option prevents the authoatic purging of files\nfrom the mirror site that were not found in the original web site after\nan 'update' is done.  If you want to retain old data and old names for\nfiles that were renamed, this option should be used.  If you want an\nup-to-date reflection of the current web site, you should not use this option.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -X0\n\n\n These options can be combined as desired to produce a\nwide range of different arrangements, from collections of only graphical\nfiles stored in a graphics area, to files identified by their MD5\nchecksums only, all stored in the same directory.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes %x0 include\n\n\n This will not include passwords for web sites.  If you\nmirror http://smith_john:foobar@www.privatefoo.com/smith/, and exclude\nusing filters some links, these links will be by default rewritten with\npassword data.  For example, \"bar.html\" will be renamed into\nhttp://smith_john:foobar@www.privatefoo.com/smith/bar.html This can be a\nproblem if you don't want to disclose the username/password! The %x\noption tell the engine not to include username/password data in\nrewritten URLs.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes %q\n\n\n This option is not very useful, because parameters are\nuseless, as pages are not dynamic anymore when mirrored.  But some\njavascript code may use the query string, and it can give useful\ninformation.  For example: catalog4FB8.html?page=computer-science is\nclearer than catalog4FB8.html Therefore, this option is activated by\ndefault.\n\n\nSpider Options\n\n These options provide for automation with regard to\nthe remote server.  For example, some sites require that cookies be\naccepted and sent back in order to allow access.\n\n\nSpider options:\n bN  accept cookies in cookies.txt (0=do not accept,* 1=accept)\n u   check document type if unknown (cgi,asp..) (u0 don't check, * u1 check but /, u2 check always)\n j   *parse Java Classes (j0 don't parse)\n sN  follow robots.txt and meta robots tags (0=never,1=sometimes,* 2=always)\n %h  force HTTP/1.0 requests (reduce update features, only for old servers or proxies)\n %B  tolerant requests (accept bogus responses on some servers, but not standard!)\n %s  update hacks: various hacks to limit re-transfers when updating\n %A  assume that a type (cgi,asp..) is always linked with a mime type (-%A php3=text/html) (--assume )\n\n\n By default, cookies are universally accepted and\nreturned.  This makes for more effective collection of data, but allows\nthe site to be identified with its collection of data more easily. To\ndisable cookies, use this option:\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -b0\n\n\n Some documents have known extension types (e.g.,\nhtml), while others have unknown types (e.g., iuh87Zs) and others may\nhave misleading types (e.g., an html file with a 'gif' file extension. \nThese options provide for (0) not checking file types, (1) checking all\nfile types except directories, and (2) checking all file types including\ndirectories. Choose from these options:\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -u0\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -u1\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -u2\n\n\n Meta tags or 'robots.txt' files on a web site are used\nto indicate what files should and should not be visited by automatic\nprograms when collectiong data.  The polite and prudent move for normal\ndata collection (and the default) is to follow this indication:\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -s2\n\n\n This follows the robots protocol and meta-tags EXCEPT\nin cases where the filters disagree with the robots protocols or\nmeta-tags. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -s1\n\n\n In this next case, we ignore meta-tags and robots.txt\nfiles completely and just take whatever we can get from the site.  The\ndanger of this includes the fact that automated programs - like games or\nsearch engines may generate an unlimited number of nearly identical or\nidentical outputs that will put us in an infinite loop collecting\nuseless data under different names.  The benefit is that we will get all\nthe data there is to get. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -s0\n\n\n This next option uses strict HTTP/1.0 protocol.  This\nmeans the program will use HTTP/1.0 headers (as in RFC1945.TXT) and NOT\nextended 1.1 features described in RFC2616.TXT.  For example, reget\n(complete a partially downloaded file) is a HTTP/1.1 feature.  The Etag\nfeature is also a HTTP/1.1 feature (Etag is a special identifier that\nallow to easily detect file changes).\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -%h\n\n\n Some servers give responses not strictly within the\nrequirements of the official http protocol.  These 'Bogus' responses can\nbe accepted by using this option.  For example, when requesting foo.gif\n(5132 bytes), the server can, optionally, add:\nContent-length: 5132\n\n\n This helps the client by allowing it to reserve a\nblock of memory, instead of collecting each byte and re-reserving memory\neach time data is being received.  But some servers are bogus, and send\na wrong filesize.  When HTtrack detects the end of file (connection\nbroken), there are three cases:\n\n\n\n 1- The connection has been closed by the server, and we\nhave received all data (we have received the number of bytes incicated\nby the server).  This is fine because we have successfully received the\nfile. \n\n 2- The connection has been closed by the server, BUT\nthe filesize received is different from the server's headers: the\nconnection has been suddenly closed, due to network problems, so we\nreget the file\n\n 3- The connetion has been closed by the server, the\nfilesize received is different from the server's headers, BUT the file\nis complete, because the server gave us a WRONG information!  In this\ncase, we use the bogus server option:\n\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -%B\n\n\n These options can be combined for the particular needs\nof the situaiton and are often adapted as a result of site-specific\nexperiences.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -%s\n\n\n This is a collection of \"tricks\" which are not really\n\"RFC compliant\" but which can save bandwidth by trying not to retransfer\ndata in several cases.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -%A asp=text/html\n\n\n The most important new feature for some people, maybe. \nThis option tells the engine that if a link is en countered, with a\nspecific type (.cgi, .asp, or .php3 for example), it MUST assume that\nthis link has always the same MIME type, for example the \"text/html\"\nMIME type.  This is VERY important to speed up many mirrors. \n\n We have done tests on big HTML files (approx.  150 MB,\n150,000,000 bytes!) with 100,000 links inside.  Such files are being\nparsed in approx.  20 seconds on my own PC by the latest optimized\nreleases of HTTra ck.  But these tests have been done with links of\nknown types, that is, html, gif, and so on..  If you have, say, 10,000\nlinks of unknown type, such as \".asp\", this will cause the engine to\ntest ALL t hese files, and this will SLOOOOW down the parser.  In this\nexample, the parser will take hours, instead of 20 seconds! In this\ncase, it would be great to tell HTTrack: \".asp pages are in fact HTML\npages\" This is possible, using: -%A asp=text/html\n\n The -%A option can be replaced by the alias --assume\nasp=text/html which is MUCH more clear.  You can use multiple\ndefinitions, separed by \",\", or use multiple options.  Therefore, these\ntwo lines are identical:\n\n--assume asp=text/html --assume php3=text/html --assume cgi=image/gif\n--assume asp=text/html,php3=text/html,cgi=image/gif\n\n\n The MIME type is the standard well known \"MIME\" type. \nHere are the most important ones:\ntext/html       Html files, parsed by HTTrack\nimage/gif       GIF files\nimage/jpeg      Jpeg files\nimage/png       PNG files\n\n\n There is also a collection of \"non standard\" MIME types. Example:\n\napplication/x-foo       Files with \"foo\" type\n\n\n Therefore, you can give to all files terminated by\n\".mp3\" the MIME type: application/x-mp3\n\n This allow you to rename files on a mirror.  If you\nKNOW that all \"dat\" files are in fact \"zip\" files ren amed into \"dat\",\nyou can tell httrack:\n\n--assume dat=application/x-zip\n\n\n You can also \"name\" a file type, with its original\nMIME type, if this type is not known by HTTrack.  This will avoid a test\nwhen the link will be reached:\n\n--assume foo=application/foobar\n\n\n In this case, HTTrack won't check the type, because it\nhas learned that \"foo\" is a known type, or MIME type\n\"application/foobar\".  Therefore, it will let untouched the \"foo\" type. \n\n A last remark, you can use complex definitions like:\n\n--assume asp=text/html,php3=text/html,cgi=image/gif,dat=application/x-zip,mpg=application/x-mp3,application/foobar\n\n\n ..and save it on your .httrackrc file:\n\nset assume asp=text/html,php3=text/html,cgi=image/gif,dat=application/x-zip,mpg=application/x-mp3,application/foobar\n\n\n\nBrowser Options\n\n Browsers commonly leave footprints in web servers - as\nweb servers leave footprints in the browser.\n\n\nBrowser ID:\n  F  user-agent field (-F \"user-agent name\")\n %F  footer string in Html code (-%F \"Mirrored [from host %s [file %s [at %s]]]\"\n %l  preffered language (-%l \"fr, en, jp, *\" (--language )\n\n\n The user-agent field is used by browsers to determine\nwhat kind of browser you are using as well as other information - such\nas your system type and operating system version.  The 'User Agent'\nfield can be set to indicate whatever is desired to the server.  In this\ncase, we are claiming to be a netscape browser (version 1.0) running a\nnon-exitent Solaris operating system version on a Sun Sparcstation.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -F \"Mozilla 1.0, Sparc, Solaris 23.54.34\"\n\n\n On the other side, we may wish to mark each page\ncollected with footer information so that we can see from the page where\nit was collected from, when, and under what name it was stored. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -%F \"Mirrored [from host %s [file %s [at %s]]]\"\n\n\n This makes a modified copy of the file that may be\nuseful in future identification.  While it is not 'pure' in some senses,\nit may (or may not) be considered siilar to a camera that adds time and\ndate stamps from a legal perspective. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -%l \"fr, en, jp, *\"\n\n\n \"I prefer to have pages with french language, then\nenglish, then japanese, then any other language\"\n\n\nLog, Cache, and Index Options\n\n A lot of options are available for log files, indexing\nof sites, and cached results:\n\n\nLog, index, cache\n  C  create/use a cache for updates and retries (C0 no cache,C1 cache is prioritary,* C2 test update before)\n  k  store all files in cache (not useful if files on disk)\n %n  do not re-download locally erased files\n  Q  log quiet mode (no log)\n  q  quiet mode (no questions)\n  z  extra infos log\n  Z  debug log\n  v  verbose screen mode\n  %v display on screen filenames downloaded (in realtime) (--display)\n  f  log file mode\n  f2 one single log file (--single-log)\n  I  *make an index (I0 don't make)\n  %I make an searchable index for this mirror (* %I0 don't make) (--search-index)\n\n\n\n A cache memory area is used for updates and retries to\nmake the process far more efficient than it would otherwise be.  You can\nchoose to (0) go without a cache, (1) do not check remotly if the file\nhas been updated or not, just load the cache content, or (2) see what\nworks best and use it (the default).  Here is the no cache example. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -C0\n\n\n The cache can be used to store all files - if desired\n- but if files are being stored on disk anyway (the normal process for a\nmirroring operation), this is not helpful.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -k\n\n\n In some cases, a file from a mirror site is erased\nlocally.  For example, if a file contains inappropriate content, it may\nbe erased from the mirror site but remain on the remote site.  This\noption allows you to leave deleted files permanently deleted when you\ndo a site update.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -update '%n'\n\n\n If no log is desired, the following option should be\nadded. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -Q\n\n\n If no questions should be asked of the user (in a mode\nthat would otherwise ask questions), the following option should be\nadded. \n\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -q\n\n By adding these options, you get (-z) extra log\ninformation or (-Z) debugging information, and (-v) verbose screen\noutput.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -z -Z -v\n\n\n Multiple log files can be created, but by default,\nthis option is used to put all logs into a single log file. \n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -f2\n\n\n Finally, an index is normally made of the sites\nmirrored (a pointer to the first page found from each specified URL) in\nan index.html file in the project directory.  This can be prevented\nthrough the use of this option:\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -I0\n\n\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes %v\n\n\n Animated information when using consol-based version,\nexample:\n17/95: localhost/manual/handler.html (6387 bytes) - OK\n\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes f2\n\n\n Do not split error and information log (hts-log.txt\nand hts-err.txt) - use only one file (hts-log.txt)\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -%I linux.localdomain\n\n\n Still in testing, this option asks the engine to\ngenerate an index.txt, useable by third-party programs or scripts, to\nindex all words contained in html files. The above example will produce\nindex.txt:\n\n..\nabridged\n        1 linux/manual/misc/API.html\n        =1\n        (0)\nabsence\n        3 linux/manual/mod/core.html\n        2 linux/manual/mod/mod_imap.html\n        1 linux/manual/misc/nopgp.html\n        1 linux/manual/mod/mod_proxy.html\n        1 linux/manual/new_features_1_3.html\n        =8\n        (0)\nabsolute\n        3 linux/manual/mod/mod_auth_digest.html\n        1 linux/manual/mod/mod_so.html\n        =4\n        (0)\n..\n\n\n\nExpert User Options\n\n For expert users, the following options provide further\noptions.\n\n\nExpert options:\n  pN priority mode: (* p3)\n      0 just scan, don't save anything (for checking links)\n      1 save only html files\n      2 save only non html files\n     *3 save all files\n      7 get html files before, then treat other files\n  S   stay on the same directory\n  D  *can only go down into subdirs\n  U   can only go to upper directories\n  B   can both go up&amp;down into the directory structure\n  a  *stay on the same address\n  d   stay on the same principal domain\n  l   stay on the same location (.com, etc.)\n  e   go everywhere on the web\n %H  debug HTTP headers in logfile\n\n\n One interesting application allows the mirror utility\nto check for valid and invalid links on a site.  This is commonly used\nin site tests to look for missing pages or other html errors.  I often\nrun such programs against my web sites to verify that nothing is missing.\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -p0\n\n\n To check for valid links outside of a site, the '-t'\noption can be used:\n\n\nhttrack http://www.shoesizes.com -O /tmp/shoesizes -t\n\n\n These options can be combined, for example, to provide\na service that checks sites for validity of links and reports back a\nlist of missing files and statistics.\n\n Other options allow the retention of select files -\nfor example - (1) only html files, (2) only non-html files, (3) all\nfiles, and (7) get all html files first, then get other files.  This\nlast option provides a fast way to get the web pointers so that, for\nexample, a time limited collection process will tend to get the most\nimportant content first. \n\n In many cases, we only want the files froma given\ndirectory.  In this case, we specify this option:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -S\n\n\n This option allows the mirror to go only into\nsubdirectories of the initial directory on the remote host.  You might\nwant to combine it with the  -n  option to get all\nnon-html files linked from the pages you find. \n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -D -n\n\n\n If you only want to work your way up the directory\nstructure from the specified URL (don't ask me why you might want to do\nthis), the following command line is for you:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -U\n\n\n If you want to go both up and down the directory\nstructure (i.e., anywhere on on this site that the requested page leads\nyou to), this option will be best:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -B\n\n\n The default is to remain on the same IP address - or\nhost name.  This option specifes this explicitly:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -a\n\n\n If you want to restrict yourself only to the same\nprincipal domain (e.g., include sites liks ftp.shoesizes.com), you would\nuse this option. \n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -d\n\n\n To restrict yourself to the same major portion of the\nInternet (e.g., .com, .net, .edu, etc.) try this option:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -l\n\n\n Finally, if you want to mirror the whole Internet - at\nleast every place on the internet that is ever led to - either directly\nor indirectly - from the starting point, use this one...  Please note\nthat this will almost always run you out of resources unless you use\nother options - like limiting the depth of search.\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -e\n\n\n Last but not least, you can include debugging\ninformaiton on all headers from a collection process by using this\noption:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -'%H'\n\n\n The options S, D, U, B, a, d, l, and e can be replaces\nwith filter options approximately as follows:\n\n\nS     -www.foo.com/* +www.foo.com/bar/*[file]\nD     (default)\nU     +www.foo.com/bar/* -www.foo.com/*[name]/*\nB     +www.foo.com/bar/*\na     (default)\nd     +*[name].foo.com/*\nl     +*[name].com/*\ne     +* (this is crazy unless a depth limit is used!)\n\n\n\nGuru Options - DO NOT USE!!!\n\n This is a new section, for all \"not very well\ndocumented options\".  You can use them, in fact, do not believe what is\nwritten above!\n\n #0  Filter test (-#0 '*.gif' 'www.bar.com/foo.gif')\n\n\n  To test the filter system. Example:\n\n$ httrack -#0 'www.*.com/*foo*bar.gif' 'www.mysite.com/test/foo4bar.gif'\nwww.mysite.com/test/foo4bar.gif does match www.*.com/*foo*bar.gif\n\n\n #f  Always flush log files\n\n\n Useful if you want the hts-log.txt file to be flushed\nregularly (not buffered)\n\n #FN Maximum number of filters\n\n\n Use if if you want to use more than the maximum\ndefault number of filters, that is, 500 filters: -#F2000 for 2,000 filters\n\n #h  Version info\n\n\n Informations on the version number\n\n #K  Scan stdin (debug)\n\n\n Not useful (debug only)\n\n #L  Maximum number of links (-#L1000000)\n\n\n Use if if you want to use more than the maximum\ndefault number of links, that is, 100,000 links: -#L2000000 for 2,000,000 links\n\n #p  Display ugly progress information\n\n\n  Self-explanatory :) I will have to improve this one\n\n #P  Catch URL\n\n\n \"Catch URL\" feature, allows to setup a temporary proxy\nto capture complex URLs, often linked with POST action (when using form\nbased authentication)\n\n #R  Old FTP routines (debug)\n\n\n Debug..\n\n #T  Generate transfer ops. log every minutes\n\n\n Generate a log file with transfer statistics\n\n #u  Wait time\n\n\n \"On hold\" option, in seconds\n\n #Z  Generate transfer rate statictics every minutes\n\n\n Generate a log file with transfer statistics\n\n #!  Execute a shell command (-#! \"echo hello\")\n\n\n Debug..\n\n\nCommand-line Specific Options\n\n\nCommand-line specific options:\n  V execute system command after each files ($0 is the filename: -V \"rm \\$0\") (--userdef-cmd )\n\n\n This option is very nice for a wide array of actions\nthat might be based on file details.  For example, a simple log of all\nfiles collected could be generated by using:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes -V \"/bin/echo \\$0\"\n\n\n %U run the engine with another id when called as root (-%U smith) (--user )\n\n\n Change the UID of the owner when running as r00t\n\n  Details: User-defined option N\n    %[param] param variable in query string\n\n\n\nThis new option is important: you can include query-string content when forming the destination filename!\n\nExample: you are mirroring a huge website, with many pages named as:\nwww.foo.com/catalog.php3?page=engineering\nwww.foo.com/catalog.php3?page=biology\nwww.foo.com/catalog.php3?page=computing\n..\n\n\n Then you can use the -N option:\n\nhttrack www.foo.com -N \"%h%p/%n%[page].%t\"\n\n\n If found, the \"page\" parameter will be included after\nthe filename, and the URLs above will be saved as:\n\n/home/mywebsites/foo/www.foo.com/catalogengineering.php3\n/home/mywebsites/foo/www.foo.com/catalogbiology.php3\n/home/mywebsites/foo/www.foo.com/catalogcomputing.php3\n...\n\n\n\nShortcuts\n\n These options provide shortcust to combinations\nof other options that are commonly used.\n\n\nShortcuts:\n--mirror       *make a mirror of site(s) (default)\n--get           get the files indicated, do not seek other URLs (-qg)\n--list     add all URL located in this text file (-%L)\n--mirrorlinks   mirror all links in 1st level pages (-Y)\n--testlinks     test links in pages (-r1p0C0I0t)\n--spider        spider site(s), to test links: reports Errors &amp; Warnings (-p0C0I0t)\n--testsite      identical to --spider\n--skeleton      make a mirror, but gets only html files (-p1)\n--update              update a mirror, without confirmation (-iC2)\n--continue            continue a mirror, without confirmation (-iC1)\n--catchurl            create a temporary proxy to capture an URL or a form post URL\n--clean               erase cache &amp; log files\n--http10              force http/1.0 requests (-%h)\n\n\n Mirror is the default behavior.  It is detailed\nearlier.\n\n get simply gets the files specified on the command\nline.\n\n The list option is useful for including a list of\nsites to collect data from.\n\n The mirrorlinks option is ideal for using the result\nof a previous search (like a list of pages found in a web search or\nsomebody's URL collection) to guide the collection of data.  With\nadditional options (such as depth 1) it can be used to collect all of\nthe pages linked to a given page without going further.  Here is an example:\n\n\nhttrack http://www.shoesizes.com/bob/ -O /tmp/shoesizes --mirrorlinks -e -r1\n\n\n Testing links in pages is useful for automating the\nverification that a link from a file is not pointing to a non-existent\npage.\n\n The spider option does a site test automatically and\nreturns errors for broken links. \n\n The skeleton option makes a mirror of html files only.\n\n The update option updates a site to match a remote\nmirror. \n\n The continue option continues a previously terminated\nmirroring activity. This is useful for all sorts of mirror failures.\n\n The catchurl option is a small application designed to\ncatch difficult pages, like sites protected via formulas.  You can see\nat http://httrack.free.fr/HelpHtml/addurl.html a Windows description of\nthis application.  The purpose is to create a temporary proxy, that will\ncatch the user request to a page, and then store this request to\ncontinue the mirror. For example,\n\n1. browse www.foo.com/bar/ until you have a page with a form\n2. fill this form to enter the site BUT do not click \"submit\"\n3. start the --catchurl application\n4. change your browser proxy settings according to the --catchurl application\n5. click on \"submit\" on your browser\n6. HTTrack has now captured this click and has stored it\n7. restore your proxy settings\n8. (click back in your browser)\n\n\n The clean option erases cache and log files.\n\n The http10 option forces http/1.0 requests (the same\nas -%h). \n\n\n\n Filters \n\n Filters are normally placed at the end of the command\nline, but can be intermixed with other command line options if desired,\nexcept that if they are placed between (for example) the '-O' and the\npathname, your results may be different than you might otherwise\npredict.  There are two sorts of filters, filters that indicate what to\ninclude (+) and filters that indicate what to exclude (-). \n\n Starting with the initially specified URLs, the\ndefault operation mode is to mirror starting from these URLs downward\ninto the directory structure of the host (i.e.  if one of your starting\npagees was www.all.net/test/a.html, all links starting with www.all.net/test/\nwill be collected but links in www.all.net/anything-else will not be\ncollected, because they are in a higher directory strcuture level.  This\nprevents HTTrack from mirroring the whole site.  If you may want to\ndownload files are in other parts of the site or pf particular types -\nor to not download files in a particular part of the site or of a\nparticular type, you can use filters to specify more precisely what to\ncollect and what not to collect. \n\n The syntax for filters is similar to Unix regular\nexpressions.  A simple filter can be made by using characters from the\nURL with '*' as a wildcard for 0 or more characters - with the last\nfilter rule having the highest precendence.  An initial '+' indicates\nURLs to include and an initial '-' indicated URLs to not include.  For\nexample:\n\n\n'-*' '+*jpg'\n\n\n would only get files ending in the 'jpg' extension,\nwhile:\n\n\n'-*jpg'\n\n\n would not get any files ending in the jpg extension. \nYou can add more filter lines to restrict or expand the scope as\ndesired.  The last rule is checked first, and so on - so that the rules\nare in reverse priority order.  Here's an example:\n\n    \n    \n    +*.gif -image*.gif\n    \n    Will accept all gif files BUT image1.gif,imageblue.gif,imagery.gif and so on\n    \n    \n    -image*.gif +*.gif\n    \n    Will accept all gif files, because the second pattern is prioritary (because it is defined AFTER the first one)\n    \n    \n\n The full syntax for filters follows:\n\n    \n      \n        *\n        any characters (the most commonly used)\n      \n      \n        *[file] or *[name]\n        any filename or name, e.g. not /,? and ; characters\n      \n      \n        *[path]\n        any path (and filename), e.g. not ? and ; characters\n      \n      \n        *[a,z,e,r,t,y]\n        any letters among a,z,e,r,t,y\n      \n      \n        *[a-z]\n        any letters\n      \n      \n        *[0-9,a,z,e,r,t,y]\n        any characters among 0..9 and a,z,e,r,t,y\n      \n      \n        *[]\n        no characters must be present after\n      \n\n  *[&lt; NN]\n size less than NN Kbytes\n\n\n  *[> PP]\n size more than PP Kbytes\n\n\n  *[&lt; NN > PP]\n size less than NN Kbytes and more than PP Kbytes\n\n    \n\n\n Here are some examples of filters: (that can be\ngenerated automatically using the interface)\n\n    \n      \n        -www.all.net* \n        This will refuse/accept this web site (all links located in it will be rejected)\n      \n      \n        +*.com/*\n        This will accept all links that contains .com in them\n      \n      \n        -*cgi-bin* \n        This will refuse all links that contains cgi-bin in them\n      \n      \n        +*.com/*[path].zip \n        This will accept all zip files in .com addresses\n      \n      \n        -*someweb*/*.tar*\n        This will refuse all tar (or tar.gz etc.) files in hosts containing someweb\n      \n      \n        +*/*somepage*\n        This will accept all links containing somepage (but not in the address)\n      \n      \n        -*.html\n        This will refuse all html files from anywhere in the world. \n      \n      \n        +*.html*[]\n        Accept *.html, but the link must not have any supplemental characters\n        at the end(e.g., links with parameters, like www.all.net/index.html?page=10\nwill not match this filter)\n      \n\n  -*.gif*[> 5] -*.zip +*.zip*[&lt; 10]\n refuse all gif files smaller than 5KB, exlude all zip files, EXCEPT zip files smaller than 10KB \n\n    \n\n\n\n User Authentication Protocols \n\n Smoe servers require user ID and password information\nin order to gain access.  In this example, the user ID smith with\npassword foobar is accessing www.all.net/private/index.html\n\n\nhttrack smith:foobar@www.all.net/private/index.html\n\n\n For more advanced forms of authentication, such as\nthose involving forms and cookies of various sorts, an emerging\ncapability is being provided through th URL capture features\n(--catchurl).  This feature don't work all of the time.\n\n\n\n .httrackrc \n\n A file called '.httrackrc' can be placed in the\ncurrent directory, or if not found there, in the home directory, to\ninclude command line options.  These options are included whenever\nhttrack is run. A sample .httrack follows:\n\n\n set sockets 8\n set retries 4\n index on\n set useragent \"Mozilla [en] (foo)\"\n set proxy proxy:8080\n\n\n But the syntax is not strict, you can use any of\nthese:\n\n\n set sockets 8\n set sockets=8\n sockets=8\n sockets 8\n\n\n\n .httrackrc is sought in the following sequence with\nthe first occurence used:\n\n\n in the dirctory indicated by -O option (.httrackrc)\n in the current directory (.httrackrc)\n in the user's home directory (.httrackrc)\n in /etc/httrack.conf (named httrack.conf to be \"standard\")\n\n\n An example .httrackrc looks like:\n\n\nset sockets=8\nset index on\nretries=2\nallow *.gif\ndeny ad.doubleclick.net/*\n\n\n Each line is composed of an option name and a\nparameter.  The \"set\" token can be used, but is not mandatory (it is\nignored, in fact).  The \"=\" is also optionnal, and is replaced by a\nspace internally.  The \"on\" and \"off\" are the same as \"1\" and \"0\"\nrespectively.  Therefore, the example .httrackrc above is equivalent to:\n\n\nsockets=8\nindex=1\nretries=2\nallow=*.gif\ndeny=ad.doubleclick.net/*\n\n\n Because the \"=\" seems to (wrongly) imply a variable\nassignment (the option can be defined more than once to define more than\none filter) the following .httrackrc:\n\n\nallow *.gif\nallow *.jpg\n\n\n looks better for a human than:\n\n\nallow=*.gif\nallow=*.jpg\n\n\n Here's a example run with the example .httrackrc file:\n\n\n$ httrack ghost\n$ cat hts-cache/doit.log\n-c8 -C1 -R2 +*.gif -ad.doubleclick.net/* ghost\n\n\n The \"-c8 -C1 -R2 +*.gif -ad.doubleclick.net/*\" was\nadded by the .httrackrc\n\n\n\n Release Notes \n\n Some things change between releases.  Here are some\nrecent changes in httrack that may affect some of these options:\n\n Options S,D,U,B, and a,d,l,e are default behaviours of\nHTTrack.  they were the only options in old versions (1.0).  With the\nintroduction of filters, their roles are now limited, because filters\ncan override them.\n\n Note for the -N option: \"%h%p/%n%q.%t\" will be now be\nused if possible.  In normal cases, when a file does not have any\nparameters (www.foo.com/bar.gif) the %q option does not add anything, so\nthere are no differences in file names.  But when parameters are present\n(for example, www.foo.com/bar.cgi?FileCollection=133.gif), the\nadditionnal query string (in this case, FileCollection=133.gif) will be\n\"hashed\" and added to the filename.  For example:\n\n'www.all.net/bar.cgi?FileCollection=133.gif'\n will be named\n'/tmp/mysite/bar4F2E.gif'\n\n The additionnal 4 letters/digits are VERY useful in\ncases where there are a substantial number of identical files:\n\n\nwww.all.net/bar.cgi?FileCollection=133.gif\nwww.all.net/bar.cgi?FileCollection=rose.gif\nwww.all.net/bar.cgi?FileCollection=plant4.gif\nwww.all.net/bar.cgi?FileCollection=silver.gif\nand so on...\n\n\n In these cases, there is a small probability of a hash\ncollision forlarge numbers of files.\n\n\n\n Some More Examples \n\n Here are some examples of special purpose httrack\ncommand lines that might be useful for your situation.\n\n This is a 'forensic' dump of a web site - intended to\ncollect all URLs reachable from the initial point and at that particular\nsite.  It is intended to make no changes whatsoever to the image.  It\nalso prints out an MD5 checksum of each file imaged so that the image\ncan be verified later to detect and changes after imaging.  It uses 5\nretries to be more certain than normal of getting the files, never\nabandons its efforts, keeps original links, does not generate error\nfiles, ignores site restrictions for robots, logs as much as it can,\nstays in the principal domain, places debugging headers in the log file,\n\n\nhttrack \"www.website.com/\" -O \"/tmp/www.website.com\" -R5H0Ko0s0zZd %H -V \"md5 \\$0\" \"+*.website.com/*\" \n\n\n Here's an example of a site where I pulled a set of\ndata related to some subject.  In this case, I only wanted the\nrelevant subdirectory, all external links were to remain the same, a\nverbose listing of URLs was to be printed, and I wanted files near (n)\nand below (D) the original directory.  Five retries just makes sure I\ndon't miss anything.\n\n\nhttrack \"http://www.somesite.com/~library/thing/thingmain.htm\" -O /tmp/thing -R5s0zZvDn\n\n\n This listing is, of course, rather verbose.  To reduce the noise,\nyou might want to do something more like this:\n\n\nhttrack \"http://www.somesite.com/~library/thing/thingmain.htm\" -O /tmp/thing -R5s0zvDn\n\n\n A still quieter version - without any debugging\ninformation but with a list of files loaded looks like this:\n\n\nhttrack \"http://www.somesite.com/~library/thing/thingmain.htm\" -O /tmp/thing -R5s0vDn\n\n\n For the strong silent type, this might be still better:\n\n\nhttrack \"http://www.somesite.com/~library/thing/thingmain.htm\" -O /tmp/thing -R5s0qDn\n\n\n\n\nGeneral questions:\n\nQ:  The install is not working on NT without administrator rights! \n\n A: That's right.  You can, however, install WinHTTrack\non your own machine, and then copy your WinHTTrack folder from\nyour Program Files folder to another machine, in a temporary\ndirectory (e.g.  C:\\temp\\)\n\nQ:  Where can I find French/other languages documentation? \n\n A: Windows interface is available on several\nlanguages, but not yet the documentation!\n\nQ:  Is HTTrack working on NT/2000? \n\n A: Yes, it should\n\nQ:  What's the difference between HTTrack and WinHTTrack? \n\n A: WinHTTrack is the Windows release of HTTrack (with\na graphic shell)\n\nQ: Is HTTrack Mac compatible? \n\n A: No, because of a lack of time.  But sources are\navailable\n\nQ:  Can HTTrack be compiled on all Un*x? \n\n A: It should.  The Makefile may be modified in\nsome cases, however\n\nQ: I use HTTrack for professional purpose.  What\nabout restrictions/license fee? \n\n A: There is no restrictions using HTTrack for\nprofessional purpose, except if you want to sell a product including\nHTTrack components (parts of the source, or any other component).  See\nthe license.txt file for more informations\n\nQ: Is a DLL/library version available? \n\n A: Not yet.  But, again, sources are available (see\nlicense.txt for distribution infos)\n\nQ: Is there a X11/KDE shell available for Linux and\nUn*x? \n\n A: No.  Unfortunately, we do not have enough time for\nthat - if you want to help us, please write one!\n\n Troubleshooting:\n\nQ: Only the first page is caught.  What's wrong?\n A: First, check the hts-err.txt error log file - this can\ngive you precious informations. \n\n The problem can be a website that redirects you to\nanother site (for example, www.all.net to public.www.all.net) : in\nthis case, use filters to accept this site\n\n This can be, also, a problem in the HTTrack options\n(link depth too low, for example)\n\nQ: With WinHTTrack, sometimes the minimize in system\ntray causes a crash! \n\n A: This bug sometimes appears in the shell on some\nsystems.  If you encounter this problem, avoid minimizing the window!\n\nQ: Files are created with strange names, like\n'-1.html'!\n\n A: Check the build options (you may have selected\nuser-defined structure with wrong parameters!)\n\nQ: When capturing real audio links (.ra), I only get\na shortcut!\n\n A: Yes.  The audio/video realtime streaming capture is\nnot yet supported\n\nQ:  Using user:password@address is not working!\n\n A: Again, first check the hts-err.txt error log\nfile - this can give you precious informations\n\n The site may have a different authentication scheme\n(form based authentication, for example)\n\nQ: When I use HTTrack, nothing is mirrored (no\nfiles) What's happening? \n\n A: First, be sure that the URL typed is correct. \nThen, check if you need to use a proxy server (see proxy options in\nWinHTTrack or the -P proxy:port option in the command line\nprogram).  The site you want to mirror may only accept certain browsers. \nYou can change your \"browser identity\" with the Browser ID\noption in the OPTION box.  Finally, you can have a look at the\nhts-err.txt (and hts-log.txt) file to see what happened. \n\nQ: There are missing files! What's happening? \n\n A: You may want to capture files that are in a\ndifferent folder, or in another web site.  In this case, HTTrack does not\ncapture them automatically, you have to ask it to do.  For that, use the\nfilters. \n\n Example: You are downloading\nhttp://www.all.net/foo/ and can not get .jpg images located in\nhttp://www.all.net/bar/ (for example, http://www.all.net/bar/blue.jpg)\n\n Then, add the filter rule +www.all.net/bar/*.jpg to\naccept all .jpg files from this location\n\n You can, also, accept all files from the /bar folder\nwith +www.all.net/bar/*, or only html files with\n+www.all.net/bar/*.html and so on.. \n \nQ: I'm downloading too many files! What can I do?\n\n\n A: This is often the case when you use too large\nfilters, for example +*.html, which asks the engine to catch all\n.html pages (even ones on other sites!).  In this case, try to use more\nspecific filters, like +www.all.net/specificfolder/*.html\n\n If you still have too many files, use filters to avoid\nsomes files.  For example, if you have too many files from www.all.net/big/,\nuse -www.all.net/big/* to avoid all files from this folder. \n \nQ: File types are sometimes changed! Why? \n\n A: By default, HTTrack tries to know the type of\nremote files.  This is useful when links like\nhttp://www.all.net/foo.cgi?id=1 can be either HTML pages, images or\nanything else.  Locally, foo.cgi will not be recognized as an html page,\nor as an image, by your browser.  HTTrack has to rename the file as\nfoo.html or foo.gif so that it can be viewed. \n\n Sometimes, however, some data files are seen by the\nremote server as html files, or images : in this case HTTrack is being\nfooled..  and rename the file.  You can avoid this by disabling the type\nchecking in the option panel. \n\nQ: I can not access to several pages (access\nforbidden, or redirect to another location), but I can with my browser,\nwhat's going on?\n\n A: You may need cookies! Cookies are specific datas\n(for example, your username or password) that are sent to your browser\nonce you have logged in certain sites so that you only have to log-in\nonce.  For example, after having entered your username in a website, you\ncan view pages and articles, and the next time you will go to this site,\nyou will not have to re-enter your username/password. \n\n To \"merge\" your personnal cookies to an HTTrack\nproject, just copy the cookies.txt file from your Netscape folder (or\nthe cookies located into the Temporary Internet Files folder for IE)\ninto your project folder (or even the HTTrack folder)\n\nQ: Some pages can't be seen, or are displayed\nwith errors! \n\n A: Some pages may include javascript or java files\nthat are not recognized.  For example, generated filenames.  There may\nbe transfer problems, too (broken pipe, etc.).  But most mirrors do\nwork.  We still are working to improve the mirror quality of HTTrack. \n\nQ: Some Java applets do not work properly! \n\n A: Java applets may not work in some cases, for\nexample if HTTrack failed to detect all included classes or files called\nwithin the class file.  Sometimes, Java applets need to be online,\nbecause remote files are directly caught.  Finally, the site structure\ncan be incompatible with the class (always try to keep the original site\nstructure when you want to get Java classes)\n\n If there is no way to make some classes work properly,\nyou can exclude them with the filters.  They will be available, but only\nonline. \n \nQ: HTTrack is being idle for a long time without\ntransfering.  What's happening? \n\n A: Maybe you try to reach some very slow sites.  Try a\nlower TimeOut value (see options, or -Txx option in the command\nline program).  Note that you will abandon the entire site (except if\nthe option is unchecked) if a timeout happen You can, with the Shell\nversion, skip some slow files, too. \n\nQ: I want to update a site, but it's taking too much\ntime! What's happening?\n\n A: First, HTTrack always tries to minimize the\ndownload flow by interrogating the server about the file changes.  But,\nbecause HTTrack has to rescan all files from the begining to rebuild the\nlocal site structure, it can takes some time.  Besides, some servers are\nnot very smart and always consider that they get newer files, forcing\nHTTrack to reload them, even if no changes have been made!\n\nQ: I am behind a firewall.  What can I do? \n\n A: You need to use a proxy, too.  Ask your\nadministrator to know the proxy server's name/port.  Then, use the proxy\nfield in HTTrack or use the -P proxy:port option in the command\nline program. \n\nQ: HTTrack has crashed during a mirror, what's\nhappening? \n\n A: We are trying to avoid bugs and problems so that\nthe program can be as reliable as possible.  But we can not be\ninfallible.  If you occurs a bug, please check if you have the latest\nrelease of HTTrack, and send us an email with a detailed description of\nyour problem (OS type, addresses concerned, crash description, and\neverything you deem to be necessary).  This may help the other users\ntoo. \n\nQ: I want to update a mirrored project, but HTTrack\nis retransfering all pages.  What's going on? \n\n A: First, HTTrack always rescan all local pages to\nreconstitute the website structure, and it can take some time.  Then, it\nasks the server if the files that are stored locally are up-to-date.  On\nmost sites, pages are not updated frequently, and the update process is\nfast.  But some sites have dynamically-generated pages that are\nconsidered as \"newer\" than the local ones..  even if there are\nidentical! Unfortunately, there is no possibility to avoid this problem,\nwhich is strongly linked with the server abilities. \n\n  Questions concerning a mirror: \n\n Q: I want to mirror a Web site,\nbut there are some files outside the domain, too.  How to retrieve them?\n\n\n A: If you just want to retrieve files that can be\nreached through links, just activate the 'get file near links' option. \nBut if you want to retrieve html pages too, you can both use wildcards\nor explicit addresses ; e.g.  add www.all.net/* to accept all\nfiles and pages from www.all.net. \n\nQ: I have forgotten some URLs of files during a long\nmirror..  Should I redo all? \n\n A: No, if you have kept the 'cache' files (in\nhts-cache), cached files will not be retransfered. \n\nQ: I just want to retrieve all ZIP files or other\nfiles in a web site/in a page.  How do I do it? \n\n A: You can use different methods.  You can use the\n'get files near a link' option if files are in a foreign domain.  You\ncan use, too, a filter adress: adding +*.zip in the URL list (or\nin the filter list) will accept all ZIP files, even if these files are\noutside the address. \n\n Example : httrack www.all.net/someaddress.html\n+*.zip will allow you to retrieve all zip files that are linked on\nthe site. \n\nQ: There are ZIP files in a page, but I don't want\nto transfer them.  How do I do it? \n\n A: Just filter them: add -*.zip in the filter\nlist. \n\nQ: I don't want to load gif files..  but what may\nhappen if I watch the page? \n\n A: If you have filtered gif files (-*.gif),\nlinks to gif files will be rebuild so that your browser can find them on\nthe server. \n\nQ: I get all types of files on a web site, but I\ndidn't select them on filters! \n\n A: By default, HTTrack retrieves all types of files on\nauthorized links.  To avoid that, define filters like\n\n-* +&lt;website>/*.html +&lt;website>/*.htm\n+&lt;website>/ +*.&lt;type wanted>\n\n Example: httrack www.all.net/index.html -*\n+www.all.net/*.htm* +www.all.net/*.gif +www.all.net/*.jpg\n\nQ: When I use filters, I get too many files! \n\n A: You are using too large a filter, for example\n*.html will get ALL html files identified.  If you want to get\nall files on an address, use www.&lt;address>/*.html.  There\nare lots of possibilities using filters. \n\n Example:httrack www.all.net +*.www.all.net/*.htm*\n\nQ: When I use filters, I can't access another\ndomain, but I have filtered it! \n\n A: You may have done a mistake declaring filters, for\nexample +www.all.net/* -*all*  will not work, because\n-*all* has an upper priority (because it has been declared after\n+www.all.net)\n\nQ: Must I add a  '+' or '-' in the filter list\nwhen I want to use filters? \n\n A: YES.  '+' is for accepting links and '-' to avoid\nthem.  If you forget it, HTTrack will consider that you want to accept a\nfilter if there is a wild card in the syntax - e.g.  +&lt;filter> if\nidentical to &lt;filter> if &lt;filter> contains a wild card (*)\n(else it will be considered as a normal link to mirror)\n\nQ: I want to find file(s) in a web-site.  How do I do it?\n\n\n A: You can use the filters: forbid all files (add a\n-* in the filter list) and accept only html files and the file(s)\nyou want to retrieve (BUT do not forget to add\n+&lt;website>*.html in the filter list, or pages will not be\nscanned! Add the name of files you want with a */ before ; i.e. \nif you want to retrieve file.zip, add */file.zip)\n\n Example:httrack www.all.net +www.all.net/*.htm*\n+thefileiwant.zip\n\nQ: I want to download ftp files/ftp site.  How to\ndo? \n\n A: First, HTTrack is not the best tool to download\nmany ftp files.  Its ftp engine is basic (even if reget are possible)\nand if your purpose is to download a complete site, use a specific\nclient. \n\n You can download ftp files just by typing the URL,\nsuch as ftp://ftp.www.all.net/pub/files/file010.zip and list ftp\ndirectories like ftp://ftp.www.all.net/pub/files/ . \n\n Note: For the filters, use something like\n+ftp://ftp.www.all.net/*\n\nQ: How can I retrieve .asp or .cgi sources instead\nof .html result? \n\n A: You can't! For security reasons, web servers do not\nallow that. \n\nQ: How can I remove these annoying &lt;!--\nMirrored from...  --> from html files? \n\n A: Use the footer option (-&amp;F, or see the WinHTTrack\noptions)\n\nQ: Do I have to select between ascii/binary transfer\nmode? \n\n A: No, http files are always transfered as binary\nfiles.  Ftp files, too (even if ascii mode could be selected)\n\nQ: Can HTTrack perform form-based authentication?\n\n\n A: Yes.  See the URL capture abilities (--catchurl for\ncommand-line release, or in the WinHTTrack interface)\n\nQ: Can I redirect downloads to tar/zip archive? \n\n A: Yes.  See the shell system command option (-V\noption for command-line release)\n\nQ: Can I use username/password authentication on a\nsite? \n\n A: Yes.  Use user:password@your_url (example:\nhttp://foo:bar@www.all.net/private/mybox.html)\n\nQ: Can I use username/password authentication for a\nproxy? \n\n A: Yes.  Use user:password@your_proxy_name as your\nproxy name (example: smith:foo@proxy.mycorp.com)\n\nQ: Can HTTrack generates HP-UX or ISO9660 compatible\nfiles? \n\n A: Yes.  See the build options (-N, or see the\nWinHTTrack options)\n\nQ: If there any SOCKS support? \n\n A: Not yet!\n\nQ: What's this hts-cache directory? Can I remove it?\n\n\n A: NO if you want to update the site, because this\ndirectory is used by HTTrack for this purpose.  If you remove it,\noptions and URLs will not be available for updating the site\n\nQ: Can I start a mirror from my bookmarks? \n\n A: Yes.  Drag&amp;Drop your bookmark.html file to the\nWinHTTrack window (or use file://filename for command-line release) and\nselect bookmark mirroring (mirror all links in pages, -Y) or bookmark\ntesting (--testlinks)\n\nQ: I am getting a \"pipe broken\" error and the mirror\nstops, what should I do? \n\n A: Chances are this is a result of downloading too\nmany pages at a time.  Remote servers may not allow or be able to handle\ntoo many sessions, or your system may be unable to provide the necessary\nresources.  Try redusing this number - for example using the -c2 options\nfor only 2 simultaneous sesions.</code></pre></div>"},{"url":"/blog/origin-policy/","relativePath":"blog/origin-policy.md","relativeDir":"blog","base":"origin-policy.md","name":"origin-policy","frontmatter":{"title":"Origin Policy","template":"post","subtitle":"Origins are the fundamental currency of the webs security model","excerpt":"Two actors in the web platform that share an origin are assumed to trust each other and to have the same authority.","date":"2022-08-27T06:19:28.467Z","image":"https://miro.medium.com/max/925/1*wnTTrWj5tn6VCQJHk9PHKQ.png","thumb_image":"https://miro.medium.com/max/925/1*wnTTrWj5tn6VCQJHk9PHKQ.png","image_position":"right","author":"src/data/authors/bgoonz.yaml","categories":["src/data/categories/content-management.yaml"],"tags":["src/data/tags/cms.yaml"],"show_author_bio":true,"related_posts":["src/pages/blog/embedding-media-in-html.md"],"cmseditable":true},"html":"<!--StartFragment-->\n<h3>7.5 Origin<a href=\"https://html.spec.whatwg.org/multipage/origin.html#origin\"></a></h3>\n<p>Origins are the fundamental currency of the web's security model. Two actors in the web platform that share an origin are assumed to trust each other and to have the same authority. Actors with differing origins are considered potentially hostile versus each other, and are isolated from each other to varying degrees.</p>\n<p>For example, if Example Bank's web site, hosted at <code class=\"language-text\">bank.example.com</code>, tries to examine the DOM of Example Charity's web site, hosted at <code class=\"language-text\">charity.example.org</code>, a <a href=\"https://webidl.spec.whatwg.org/#securityerror\">\"<code class=\"language-text\">SecurityError</code>\"</a> <code class=\"language-text\">DOMException</code> will be raised.</p>\n<hr>\n<p>An origin is one of the following:</p>\n<ul>\n<li>\n<p>An opaque origin</p>\n<p>An internal value, with no serialization it can be recreated from (it is serialized as \"<code class=\"language-text\">null</code>\" per <a href=\"https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin\">serialization of an origin</a>), for which the only meaningful operation is testing for equality.</p>\n</li>\n<li>\n<p>A tuple origin</p>\n<p>A <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-tuple\">tuple</a> consists of:</p>\n<ul>\n<li>A scheme (an <a href=\"https://infra.spec.whatwg.org/#ascii-string\">ASCII string</a>).</li>\n<li>A host (a <a href=\"https://url.spec.whatwg.org/#concept-host\">host</a>).</li>\n<li>A port (null or a 16-bit unsigned integer).</li>\n<li>A domain (null or a <a href=\"https://url.spec.whatwg.org/#concept-domain\">domain</a>). Null unless stated otherwise.</li>\n</ul>\n</li>\n</ul>\n<p><a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">Origins</a> can be shared, e.g., among multiple <code class=\"language-text\">Document</code> objects. Furthermore, <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> are generally immutable. Only the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domain</a> of a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-tuple\">tuple origin</a> can be changed, and only through the <code class=\"language-text\">document.domain</code> API.</p>\n<p>The effective domain of an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a> <code class=\"language-text\">origin</code> is computed as follows:</p>\n<ol>\n<li>If <code class=\"language-text\">origin</code> is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, then return null.</li>\n<li>If <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domain</a> is non-null, then return <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domain</a>.</li>\n<li>Return <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-host\">host</a>.</li>\n</ol>\n<p>The serialization of an origin is the string obtained by applying the following algorithm to the given <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a> <code class=\"language-text\">origin</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">origin</code> is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, then return \"<code class=\"language-text\">null</code>\".</li>\n<li>Otherwise, let <code class=\"language-text\">result</code> be <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-scheme\">scheme</a>.</li>\n<li>Append \"<code class=\"language-text\">://</code>\" to <code class=\"language-text\">result</code>.</li>\n<li>Append <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-host\">host</a>, <a href=\"https://url.spec.whatwg.org/#concept-host-serializer\">serialized</a>, to <code class=\"language-text\">result</code>.</li>\n<li>If <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-port\">port</a> is non-null, append a U+003A COLON character (:), and <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-port\">port</a>, <a href=\"https://url.spec.whatwg.org/#serialize-an-integer\">serialized</a>, to <code class=\"language-text\">result</code>.</li>\n<li>Return <code class=\"language-text\">result</code>.</li>\n</ol>\n<p>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin\">serialization</a> of (\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">xn--maraa-rta.example</code>\", null, null) is \"<code class=\"language-text\">https://xn--maraa-rta.example</code>\".</p>\n<p>There used to also be a <em>Unicode serialization of an origin</em>. However, it was never widely adopted.</p>\n<hr>\n<p>Two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a>, <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code>, are said to be same origin if the following algorithm returns true:</p>\n<ol>\n<li>If <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code> are the same <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, then return true.</li>\n<li>If <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code> are both <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-tuple\">tuple origins</a> and their <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-scheme\">schemes</a>, <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-host\">hosts</a>, and <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-port\">port</a> are identical, then return true.</li>\n<li>Return false.</li>\n</ol>\n<p>Two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a>, <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code>, are said to be same origin-domain if the following algorithm returns true:</p>\n<ol>\n<li>If <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code> are the same <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, then return true.</li>\n<li>\n<p>If <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code> are both <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-tuple\">tuple origins</a>, run these substeps:</p>\n<ol>\n<li>If <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-scheme\">schemes</a> are identical, and their <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domains</a> are identical and non-null, then return true.</li>\n<li>Otherwise, if <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> and their <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domains</a> are identical and null, then return true.</li>\n</ol>\n</li>\n<li>Return false.</li>\n</ol>\n<table>\n<thead>\n<tr>\n<th><code class=\"language-text\">A</code></th>\n<th><code class=\"language-text\">B</code></th>\n<th><a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a></th>\n<th><a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin-domain\">same origin-domain</a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", null, null)</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", null, null)</td>\n<td>✅</td>\n<td>✅</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", 314, null)</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", 420, null)</td>\n<td>❌</td>\n<td>❌</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", 314, \"<code class=\"language-text\">example.org</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", 420, \"<code class=\"language-text\">example.org</code>\")</td>\n<td>❌</td>\n<td>✅</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", null, null)</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", null, \"<code class=\"language-text\">example.org</code>\")</td>\n<td>✅</td>\n<td>❌</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.org</code>\", null, \"<code class=\"language-text\">example.org</code>\")</td>\n<td>(\"<code class=\"language-text\">http</code>\", \"<code class=\"language-text\">example.org</code>\", null, \"<code class=\"language-text\">example.org</code>\")</td>\n<td>❌</td>\n<td>❌</td>\n</tr>\n</tbody>\n</table>\n<h4>7.5.1 Sites<a href=\"https://html.spec.whatwg.org/multipage/origin.html#sites\"></a></h4>\n<p>A scheme-and-host is a <a href=\"https://infra.spec.whatwg.org/#tuple\">tuple</a> of a scheme (an <a href=\"https://infra.spec.whatwg.org/#ascii-string\">ASCII string</a>) and a host (a <a href=\"https://url.spec.whatwg.org/#concept-host\">host</a>).</p>\n<p>A site is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a> or a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#scheme-and-host\">scheme-and-host</a>.</p>\n<p>To obtain a site, given an origin <code class=\"language-text\">origin</code>, run these steps:</p>\n<ol>\n<li>If <code class=\"language-text\">origin</code> is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, then return <code class=\"language-text\">origin</code>.</li>\n<li>If <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-host\">host</a>'s <a href=\"https://url.spec.whatwg.org/#host-registrable-domain\">registrable domain</a> is null, then return (<code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-scheme\">scheme</a>, <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-host\">host</a>).</li>\n<li>Return (<code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-scheme\">scheme</a>, <code class=\"language-text\">origin</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-host\">host</a>'s <a href=\"https://url.spec.whatwg.org/#host-registrable-domain\">registrable domain</a>).</li>\n</ol>\n<p>Two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#site\">sites</a>, <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code>, are said to be same site if the following algorithm returns true:</p>\n<ol>\n<li>If <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code> are the same <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, the return true.</li>\n<li>If <code class=\"language-text\">A</code> or <code class=\"language-text\">B</code> is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, then return false.</li>\n<li>If <code class=\"language-text\">A</code>'s and <code class=\"language-text\">B</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-scheme-and-host-scheme\">scheme</a> values are different, then return false.</li>\n<li>If <code class=\"language-text\">A</code>'s and <code class=\"language-text\">B</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-scheme-and-host-host\">host</a> values are not <a href=\"https://url.spec.whatwg.org/#concept-host-equals\">equal</a>, then return false.</li>\n<li>Return true.</li>\n</ol>\n<p>The serialization of a site is the string obtained by applying the following algorithm to the given <a href=\"https://html.spec.whatwg.org/multipage/origin.html#site\">site</a> <code class=\"language-text\">site</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">site</code> is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, then return \"<code class=\"language-text\">null</code>\".</li>\n<li>Let <code class=\"language-text\">result</code> be <code class=\"language-text\">site</code>[0].</li>\n<li>Append \"<code class=\"language-text\">://</code>\" to <code class=\"language-text\">result</code>.</li>\n<li>Append <code class=\"language-text\">site</code>[1], <a href=\"https://url.spec.whatwg.org/#concept-host-serializer\">serialized</a>, to <code class=\"language-text\">result</code>.</li>\n<li>Return <code class=\"language-text\">result</code>.</li>\n</ol>\n<p>It needs to be clear from context that the serialized value is a site, not an origin, as there is not necessarily a syntactic difference between the two. For example, the origin (\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">shop.example</code>\", null, null) and the site (\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">shop.example</code>\") have the same serialization: \"<code class=\"language-text\">https://shop.example</code>\".</p>\n<p>Two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a>, <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code>, are said to be schemelessly same site if the following algorithm returns true:</p>\n<ol>\n<li>If <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code> are the same <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a>, then return true.</li>\n<li>\n<p>If <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code> are both <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-tuple\">tuple origins</a>, then:</p>\n<ol>\n<li>Let <code class=\"language-text\">hostA</code> be <code class=\"language-text\">A</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-host\">host</a>, and let <code class=\"language-text\">hostB</code> be <code class=\"language-text\">B</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-host\">host</a>.</li>\n<li>If <code class=\"language-text\">hostA</code> <a href=\"https://url.spec.whatwg.org/#concept-host-equals\">equals</a> <code class=\"language-text\">hostB</code> and <code class=\"language-text\">hostA</code>'s <a href=\"https://url.spec.whatwg.org/#host-registrable-domain\">registrable domain</a> is null, then return true.</li>\n<li>If <code class=\"language-text\">hostA</code>'s <a href=\"https://url.spec.whatwg.org/#host-registrable-domain\">registrable domain</a> <a href=\"https://url.spec.whatwg.org/#concept-host-equals\">equals</a> <code class=\"language-text\">hostB</code>'s <a href=\"https://url.spec.whatwg.org/#host-registrable-domain\">registrable domain</a> and is non-null, then return true.</li>\n</ol>\n</li>\n<li>Return false.</li>\n</ol>\n<p>Two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a>, <code class=\"language-text\">A</code> and <code class=\"language-text\">B</code>, are said to be same site if the following algorithm returns true:</p>\n<ol>\n<li>Let <code class=\"language-text\">siteA</code> be the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#obtain-a-site\">obtaining a site</a> given <code class=\"language-text\">A</code>.</li>\n<li>Let <code class=\"language-text\">siteB</code> be the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#obtain-a-site\">obtaining a site</a> given <code class=\"language-text\">B</code>.</li>\n<li>If <code class=\"language-text\">siteA</code> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-site-same-site\">same site</a> with <code class=\"language-text\">siteB</code>, then return true.</li>\n<li>Return false.</li>\n</ol>\n<p>Unlike the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> and <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin-domain\">same origin-domain</a> concepts, for <a href=\"https://html.spec.whatwg.org/multipage/origin.html#schemelessly-same-site\">schemelessly same site</a> and <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-site\">same site</a>, the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-port\">port</a> and <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domain</a> components are ignored.</p>\n<p>For the reasons <a href=\"https://url.spec.whatwg.org/#warning-avoid-psl\">explained in URL</a>, the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-site\">same site</a> and <a href=\"https://html.spec.whatwg.org/multipage/origin.html#schemelessly-same-site\">schemelessly same site</a> concepts should be avoided when possible, in favor of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> checks.</p>\n<p>Given that <code class=\"language-text\">wildlife.museum</code>, <code class=\"language-text\">museum</code>, and <code class=\"language-text\">com</code> are <a href=\"https://url.spec.whatwg.org/#host-public-suffix\">public suffixes</a> and that <code class=\"language-text\">example.com</code> is not:</p>\n<table>\n<thead>\n<tr>\n<th><code class=\"language-text\">A</code></th>\n<th><code class=\"language-text\">B</code></th>\n<th><a href=\"https://html.spec.whatwg.org/multipage/origin.html#schemelessly-same-site\">schemelessly same site</a></th>\n<th><a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-site\">same site</a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.com</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">sub.example.com</code>\")</td>\n<td>✅</td>\n<td>✅</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.com</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">sub.other.example.com</code>\")</td>\n<td>✅</td>\n<td>✅</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.com</code>\")</td>\n<td>(\"<code class=\"language-text\">http</code>\", \"<code class=\"language-text\">non-secure.example.com</code>\")</td>\n<td>✅</td>\n<td>❌</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">r.wildlife.museum</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">sub.r.wildlife.museum</code>\")</td>\n<td>✅</td>\n<td>✅</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">r.wildlife.museum</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">sub.other.r.wildlife.museum</code>\")</td>\n<td>✅</td>\n<td>✅</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">r.wildlife.museum</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">other.wildlife.museum</code>\")</td>\n<td>❌</td>\n<td>❌</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">r.wildlife.museum</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">wildlife.museum</code>\")</td>\n<td>❌</td>\n<td>❌</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">wildlife.museum</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">wildlife.museum</code>\")</td>\n<td>✅</td>\n<td>✅</td>\n</tr>\n<tr>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.com</code>\")</td>\n<td>(\"<code class=\"language-text\">https</code>\", \"<code class=\"language-text\">example.com.</code>\")</td>\n<td>❌</td>\n<td>❌</td>\n</tr>\n</tbody>\n</table>\n<p>(Here we have omitted the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-port\">port</a> and <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domain</a> components since they are not considered.)</p>\n<h4>7.5.2 Relaxing the same-origin restriction<a href=\"https://html.spec.whatwg.org/multipage/origin.html#relaxing-the-same-origin-restriction\"></a></h4>\n<ul>\n<li>\n<p><code class=\"language-text\">document.domain [ = domain ]</code></p>\n<p>Returns the current domain used for security checks.</p>\n<p>Can be set to a value that removes subdomains, to change the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domain</a> to allow pages on other subdomains of the same domain (if they do the same thing) to access each other. This enables pages on different hosts of a domain to synchronously access each other's DOMs.</p>\n<p>In sandboxed <code class=\"language-text\">iframe</code>s, <code class=\"language-text\">Document</code>s with <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origins</a>, <code class=\"language-text\">Document</code>s without a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#concept-document-bc\">browsing context</a>, and when the \"<code class=\"language-text\">document-domain</code>\" feature is disabled, the setter will throw a <a href=\"https://webidl.spec.whatwg.org/#securityerror\">\"<code class=\"language-text\">SecurityError</code>\"</a> exception. In cases where <code class=\"language-text\">crossOriginIsolated</code> or <code class=\"language-text\">originAgentCluster</code> return true, the setter will do nothing.</p>\n</li>\n</ul>\n<p>Avoid using the <code class=\"language-text\">document.domain</code> setter. It undermines the security protections provided by the same-origin policy. This is especially acute when using shared hosting; for example, if an untrusted third party is able to host an HTTP server at the same IP address but on a different port, then the same-origin protection that normally protects two different sites on the same host will fail, as the ports are ignored when comparing origins after the <code class=\"language-text\">document.domain</code> setter has been used.</p>\n<p>Because of these security pitfalls, this feature is in the process of being removed from the web platform. (This is a long process that takes many years.)</p>\n<p>Instead, use <code class=\"language-text\">postMessage()</code> or <code class=\"language-text\">MessageChannel</code> objects to communicate across origins in a safe manner.</p>\n<p>The <code class=\"language-text\">domain</code> getter steps are:</p>\n<ol>\n<li>Let <code class=\"language-text\">effectiveDomain</code> be <a href=\"https://webidl.spec.whatwg.org/#this\">this</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-effective-domain\">effective domain</a>.</li>\n<li>If <code class=\"language-text\">effectiveDomain</code> is null, then return the empty string.</li>\n<li>Return <code class=\"language-text\">effectiveDomain</code>, <a href=\"https://url.spec.whatwg.org/#concept-host-serializer\">serialized</a>.</li>\n</ol>\n<p>The <code class=\"language-text\">domain</code> setter steps are:</p>\n<ol>\n<li>If <a href=\"https://webidl.spec.whatwg.org/#this\">this</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#concept-document-bc\">browsing context</a> is null, then throw a <a href=\"https://webidl.spec.whatwg.org/#securityerror\">\"<code class=\"language-text\">SecurityError</code>\"</a> <code class=\"language-text\">DOMException</code>.</li>\n<li>If <a href=\"https://webidl.spec.whatwg.org/#this\">this</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set\">active sandboxing flag set</a> has its <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-document.domain-browsing-context-flag\">sandboxed <code class=\"language-text\">document.domain</code> browsing context flag</a> set, then throw a <a href=\"https://webidl.spec.whatwg.org/#securityerror\">\"<code class=\"language-text\">SecurityError</code>\"</a> <code class=\"language-text\">DOMException</code>.</li>\n<li>If <a href=\"https://webidl.spec.whatwg.org/#this\">this</a> is not <a href=\"https://html.spec.whatwg.org/multipage/iframe-embed-object.html#allowed-to-use\">allowed to use</a> the \"<code class=\"language-text\">document-domain</code>\" feature, then throw a <a href=\"https://webidl.spec.whatwg.org/#securityerror\">\"<code class=\"language-text\">SecurityError</code>\"</a> <code class=\"language-text\">DOMException</code>.</li>\n<li>Let <code class=\"language-text\">effectiveDomain</code> be <a href=\"https://webidl.spec.whatwg.org/#this\">this</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-effective-domain\">effective domain</a>.</li>\n<li>If <code class=\"language-text\">effectiveDomain</code> is null, then throw a <a href=\"https://webidl.spec.whatwg.org/#securityerror\">\"<code class=\"language-text\">SecurityError</code>\"</a> <code class=\"language-text\">DOMException</code>.</li>\n<li>If the given value <a href=\"https://html.spec.whatwg.org/multipage/origin.html#is-a-registrable-domain-suffix-of-or-is-equal-to\">is not a registrable domain suffix of and is not equal to</a> <code class=\"language-text\">effectiveDomain</code>, then throw a <a href=\"https://webidl.spec.whatwg.org/#securityerror\">\"<code class=\"language-text\">SecurityError</code>\"</a> <code class=\"language-text\">DOMException</code>.</li>\n<li>If the <a href=\"https://tc39.es/ecma262/#surrounding-agent\">surrounding agent</a>'s <a href=\"https://tc39.es/ecma262/#sec-agent-clusters\">agent cluster</a>'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#is-origin-keyed\">is origin-keyed</a> is true, then return.</li>\n<li>Set <code class=\"language-text\">this</code>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-domain\">domain</a> to the result of <a href=\"https://url.spec.whatwg.org/#concept-host-parser\">parsing</a> the given value.</li>\n</ol>\n<p>To determine if a string <code class=\"language-text\">hostSuffixString</code> is a registrable domain suffix of or is equal to a <a href=\"https://url.spec.whatwg.org/#concept-host\">host</a> <code class=\"language-text\">originalHost</code>, run these steps:</p>\n<ol>\n<li>If <code class=\"language-text\">hostSuffixString</code> is the empty string, then return false.</li>\n<li>Let <code class=\"language-text\">hostSuffix</code> be the result of <a href=\"https://url.spec.whatwg.org/#concept-host-parser\">parsing</a> <code class=\"language-text\">hostSuffixString</code>.</li>\n<li>If <code class=\"language-text\">hostSuffix</code> is failure, then return false.</li>\n<li>\n<p>If <code class=\"language-text\">hostSuffix</code> does not <a href=\"https://url.spec.whatwg.org/#concept-host-equals\">equal</a> <code class=\"language-text\">originalHost</code>, then:</p>\n<ol>\n<li>If <code class=\"language-text\">hostSuffix</code> or <code class=\"language-text\">originalHost</code> is not a <a href=\"https://url.spec.whatwg.org/#concept-domain\">domain</a>, then return false.</li>\n</ol>\n<p>  This excludes <a href=\"https://url.spec.whatwg.org/#concept-host\">hosts</a> that are <a href=\"https://url.spec.whatwg.org/#ip-address\">IP addresses</a>.</p>\n<ol start=\"2\">\n<li>If <code class=\"language-text\">hostSuffix</code>, prefixed by U+002E (.), does not match the end of <code class=\"language-text\">originalHost</code>, then return false.</li>\n<li>If one of the following is true</li>\n<li><code class=\"language-text\">hostSuffix</code> <a href=\"https://url.spec.whatwg.org/#concept-host-equals\">equals</a> <code class=\"language-text\">hostSuffix</code>'s <a href=\"https://url.spec.whatwg.org/#host-public-suffix\">public suffix</a></li>\n<li><code class=\"language-text\">hostSuffix</code>, prefixed by U+002E (.), matches the end <code class=\"language-text\">originalHost</code>'s <a href=\"https://url.spec.whatwg.org/#host-public-suffix\">public suffix</a></li>\n</ol>\n<p>  then return false. [[URL]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsURL\">https://html.spec.whatwg.org/multipage/references.html#refsURL</a>)</p>\n<ol start=\"4\">\n<li>Assert: <code class=\"language-text\">originalHost</code>'s <a href=\"https://url.spec.whatwg.org/#host-public-suffix\">public suffix</a>, prefixed by U+002E (.), matches the end of <code class=\"language-text\">hostSuffix</code>.</li>\n</ol>\n</li>\n<li>Return true.</li>\n</ol>\n<table>\n<thead>\n<tr>\n<th><code class=\"language-text\">hostSuffixString</code></th>\n<th><code class=\"language-text\">originalHost</code></th>\n<th>Outcome of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#is-a-registrable-domain-suffix-of-or-is-equal-to\">is a registrable domain suffix of or is equal to</a></th>\n<th>Notes</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>\"<code class=\"language-text\">0.0.0.0</code>\"</td>\n<td><code class=\"language-text\">0.0.0.0</code></td>\n<td>✅</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">0x10203</code>\"</td>\n<td><code class=\"language-text\">0.1.2.3</code></td>\n<td>✅</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">[0::1]</code>\"</td>\n<td><code class=\"language-text\">::1</code></td>\n<td>✅</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">example.com</code>\"</td>\n<td><code class=\"language-text\">example.com</code></td>\n<td>✅</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">example.com</code>\"</td>\n<td><code class=\"language-text\">example.com.</code></td>\n<td>❌</td>\n<td>Trailing dot is significant.</td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">example.com.</code>\"</td>\n<td><code class=\"language-text\">example.com</code></td>\n<td>❌</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">example.com</code>\"</td>\n<td><code class=\"language-text\">www.example.com</code></td>\n<td>✅</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">com</code>\"</td>\n<td><code class=\"language-text\">example.com</code></td>\n<td>❌</td>\n<td>At the time of writing, <code class=\"language-text\">com</code> is a public suffix.</td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">example</code>\"</td>\n<td><code class=\"language-text\">example</code></td>\n<td>✅</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">compute.amazonaws.com</code>\"</td>\n<td><code class=\"language-text\">example.compute.amazonaws.com</code></td>\n<td>❌</td>\n<td>At the time of writing, <code class=\"language-text\">*.compute.amazonaws.com</code> is a public suffix.</td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">example.compute.amazonaws.com</code>\"</td>\n<td><code class=\"language-text\">www.example.compute.amazonaws.com</code></td>\n<td>❌</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">amazonaws.com</code>\"</td>\n<td><code class=\"language-text\">www.example.compute.amazonaws.com</code></td>\n<td>❌</td>\n<td></td>\n</tr>\n<tr>\n<td>\"<code class=\"language-text\">amazonaws.com</code>\"</td>\n<td><code class=\"language-text\">test.amazonaws.com</code></td>\n<td>✅</td>\n<td>At the time of writing, <code class=\"language-text\">amazonaws.com</code> is a registrable domain.</td>\n</tr>\n</tbody>\n</table>\n<h4>7.5.3 Origin-keyed agent clusters<a href=\"https://html.spec.whatwg.org/multipage/origin.html#origin-keyed-agent-clusters\"></a></h4>\n<ul>\n<li>\n<p><code class=\"language-text\">window.originAgentCluster</code></p>\n<p>Returns true if this <code class=\"language-text\">Window</code> belongs to an <a href=\"https://tc39.es/ecma262/#sec-agent-clusters\">agent cluster</a> which is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a>-<a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#agent-cluster-key\">keyed</a>, in the manner described in this section.</p>\n</li>\n</ul>\n<p>A <code class=\"language-text\">Document</code> delivered over a <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#secure-context\">secure context</a> can request that it be placed in an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a>-<a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#agent-cluster-key\">keyed</a> <a href=\"https://tc39.es/ecma262/#sec-agent-clusters\">agent cluster</a>, by using the <code class=\"language-text\">Origin-Agent-Cluster</code> HTTP response header. This header is a <a href=\"https://httpwg.org/specs/rfc8941.html\">structured header</a> whose value must be a <a href=\"https://httpwg.org/specs/rfc8941.html#boolean\">boolean</a>. [[STRUCTURED-FIELDS]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsSTRUCTURED-FIELDS\">https://html.spec.whatwg.org/multipage/references.html#refsSTRUCTURED-FIELDS</a>)</p>\n<p>Per the processing model in the <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#initialise-the-document-object\">create and initialize a new <code class=\"language-text\">Document</code> object</a>, values that are not the <a href=\"https://httpwg.org/specs/rfc8941.html#boolean\">structured header boolean</a> true value (i.e., <code class=\"language-text\">?1</code>) will be ignored.</p>\n<p>The consequences of using this header are that the resulting <code class=\"language-text\">Document</code>'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#agent-cluster-key\">agent cluster key</a> is its <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a>, instead of the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#obtain-a-site\">corresponding site</a>. In terms of observable effects, this means that attempting to <a href=\"https://html.spec.whatwg.org/multipage/origin.html#relaxing-the-same-origin-restriction\">relax the same-origin restriction</a> using <code class=\"language-text\">document.domain</code> will instead do nothing, and it will not be possible to send <code class=\"language-text\">WebAssembly.Module</code> objects to cross-origin <code class=\"language-text\">Document</code>s (even if they are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-site\">same site</a>). Behind the scenes, this isolation can allow user agents to allocate implementation-specific resources corresponding to <a href=\"https://tc39.es/ecma262/#sec-agent-clusters\">agent clusters</a>, such as processes or threads, more efficiently.</p>\n<p>Note that within a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group\">browsing context group</a>, the <code class=\"language-text\">Origin-Agent-Cluster</code> header can never cause same-origin <code class=\"language-text\">Document</code> objects to end up in different <a href=\"https://tc39.es/ecma262/#sec-agent-clusters\">agent clusters</a>, even if one sends the header and the other doesn't. This is prevented by means of the <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#historical-agent-cluster-key-map\">historical agent cluster key map</a>.</p>\n<p>This means that the <code class=\"language-text\">originAgentCluster</code> getter can return false, even if the header is set, if the header was omitted on a previously-loaded same-origin page in the same <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group\">browsing context group</a>. Similarly, it can return true even when the header is not set.</p>\n<p>The <code class=\"language-text\">originAgentCluster</code> getter steps are to return the <a href=\"https://tc39.es/ecma262/#surrounding-agent\">surrounding agent</a>'s <a href=\"https://tc39.es/ecma262/#sec-agent-clusters\">agent cluster</a>'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#is-origin-keyed\">is origin-keyed</a>.</p>\n<p><code class=\"language-text\">Document</code>s with an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque\">opaque origin</a> can be considered unconditionally origin-keyed; for them the header has no effect, and the <code class=\"language-text\">originAgentCluster</code> getter will always return true.</p>\n<p>Similarly, <code class=\"language-text\">Document</code>s whose <a href=\"https://tc39.es/ecma262/#sec-agent-clusters\">agent cluster</a>'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#agent-cluster-cross-origin-isolation\">cross-origin isolation mode</a> is not \"<code class=\"language-text\">none</code>\" are automatically origin-keyed. The <code class=\"language-text\">Origin-Agent-Cluster`\\` header might be useful as an additional hint to implementations about resource allocation, since the \\</code>Cross-Origin-Opener-Policy<code class=\"language-text\">\\</code> and ``Cross-Origin-Embedder-Policy headers used to achieve cross-origin isolation are more about ensuring that everything in the same address space opts in to being there. But adding it would have no additional observable effects on author code.</p>\n<h3>7.6 Sandboxing<a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxing\"></a></h3>\n<p>A sandboxing flag set is a set of zero or more of the following flags, which are used to restrict the abilities that potentially untrusted resources have:</p>\n<ul>\n<li>\n<p>The sandboxed navigation browsing context flag</p>\n<p>This flag <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#sandboxLinks\">prevents content from navigating browsing contexts other than the sandboxed browsing context itself</a> (or browsing contexts further nested inside it), <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#auxiliary-browsing-context\">auxiliary browsing contexts</a> (which are protected by the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-auxiliary-navigation-browsing-context-flag\">sandboxed auxiliary navigation browsing context flag</a> defined next), and the <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a> (which is protected by the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-top-level-navigation-without-user-activation-browsing-context-flag\">sandboxed top-level navigation without user activation browsing context flag</a> and <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-top-level-navigation-with-user-activation-browsing-context-flag\">sandboxed top-level navigation with user activation browsing context flag</a> defined below).</p>\n<p>If the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-auxiliary-navigation-browsing-context-flag\">sandboxed auxiliary navigation browsing context flag</a> is not set, then in certain cases the restrictions nonetheless allow popups (new <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing contexts</a>) to be opened. These <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing contexts</a> always have one permitted sandboxed navigator, set when the browsing context is created, which allows the <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a> that created them to actually navigate them. (Otherwise, the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-navigation-browsing-context-flag\">sandboxed navigation browsing context flag</a> would prevent them from being navigated even if they were opened.)</p>\n</li>\n<li>\n<p>The sandboxed auxiliary navigation browsing context flag</p>\n<p>This flag <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#sandboxWindowOpen\">prevents content from creating new auxiliary browsing contexts</a>, e.g. using the <code class=\"language-text\">target</code> attribute or the <code class=\"language-text\">window.open()</code> method.</p>\n</li>\n<li>\n<p>The sandboxed top-level navigation without user activation browsing context flag</p>\n<p>This flag <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#sandboxLinks\">prevents content from navigating their top-level browsing context</a> and <a href=\"https://html.spec.whatwg.org/multipage/window-object.html#sandboxClose\">prevents content from closing their top-level browsing context</a>. It is consulted only when the sandboxed browsing context's <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-window\">active window</a> does not have <a href=\"https://html.spec.whatwg.org/multipage/interaction.html#transient-activation\">transient activation</a>.</p>\n<p>When the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-top-level-navigation-without-user-activation-browsing-context-flag\">sandboxed top-level navigation without user activation browsing context flag</a> is <em>not</em> set, content can navigate its <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>, but other <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing contexts</a> are still protected by the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-navigation-browsing-context-flag\">sandboxed navigation browsing context flag</a> and possibly the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-auxiliary-navigation-browsing-context-flag\">sandboxed auxiliary navigation browsing context flag</a>.</p>\n</li>\n<li>\n<p>The sandboxed top-level navigation with user activation browsing context flag</p>\n<p>This flag <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#sandboxLinks\">prevents content from navigating their top-level browsing context</a> and <a href=\"https://html.spec.whatwg.org/multipage/window-object.html#sandboxClose\">prevents content from closing their top-level browsing context</a>. It is consulted only when the sandboxed browsing context's <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-window\">active window</a> has <a href=\"https://html.spec.whatwg.org/multipage/interaction.html#transient-activation\">transient activation</a>.</p>\n<p>As with the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-top-level-navigation-without-user-activation-browsing-context-flag\">sandboxed top-level navigation without user activation browsing context flag</a>, this flag only affects the <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>; if it is not set, other <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing contexts</a> might still be protected by other flags.</p>\n</li>\n<li>\n<p>The sandboxed plugins browsing context flag</p>\n<p>This flag prevents content from instantiating <a href=\"https://html.spec.whatwg.org/multipage/infrastructure.html#plugin\">plugins</a>, whether using <a href=\"https://html.spec.whatwg.org/multipage/iframe-embed-object.html#sandboxPluginEmbed\">the <code class=\"language-text\">embed</code> element</a>, <a href=\"https://html.spec.whatwg.org/multipage/iframe-embed-object.html#sandboxPluginObject\">the <code class=\"language-text\">object</code> element</a>, or through <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#sandboxPluginNavigate\">navigation</a> of their <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#nested-browsing-context\">nested browsing context</a>.</p>\n</li>\n<li>\n<p>The sandboxed origin browsing context flag</p>\n<p>This flag <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#sandboxOrigin\">forces content into a unique origin</a>, thus preventing it from accessing other content from the same <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a>.</p>\n<p>This flag also <a href=\"https://html.spec.whatwg.org/multipage/dom.html#sandboxCookies\">prevents script from reading from or writing to the <code class=\"language-text\">document.cookie</code> IDL attribute</a>, and blocks access to <code class=\"language-text\">localStorage</code>.</p>\n</li>\n<li>\n<p>The sandboxed forms browsing context flag</p>\n<p>This flag <a href=\"https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#sandboxSubmitBlocked\">blocks form submission</a>.</p>\n</li>\n<li>\n<p>The sandboxed pointer lock browsing context flag</p>\n<p>This flag disables the Pointer Lock API. [[POINTERLOCK]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsPOINTERLOCK\">https://html.spec.whatwg.org/multipage/references.html#refsPOINTERLOCK</a>)</p>\n</li>\n<li>\n<p>The sandboxed scripts browsing context flag</p>\n<p>This flag <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#sandboxScriptBlocked\">blocks script execution</a>.</p>\n</li>\n<li>\n<p>The sandboxed automatic features browsing context flag</p>\n<p>This flag blocks features that trigger automatically, such as <a href=\"https://html.spec.whatwg.org/multipage/media.html#attr-media-autoplay\">automatically playing a video</a> or <a href=\"https://html.spec.whatwg.org/multipage/interaction.html#attr-fe-autofocus\">automatically focusing a form control</a>.</p>\n</li>\n<li>\n<p>The sandboxed <code class=\"language-text\">document.domain</code> browsing context flag</p>\n<p>This flag prevents content from using the <code class=\"language-text\">document.domain</code> setter.</p>\n</li>\n<li>\n<p>The sandbox propagates to auxiliary browsing contexts flag</p>\n<p>This flag prevents content from escaping the sandbox by ensuring that any <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#auxiliary-browsing-context\">auxiliary browsing context</a> it creates inherits the content's <a href=\"https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set\">active sandboxing flag set</a>.</p>\n</li>\n<li>\n<p>The sandboxed modals flag</p>\n<p>This flag prevents content from using any of the following features to produce modal dialogs:</p>\n<ul>\n<li><code class=\"language-text\">window.alert()</code></li>\n<li><code class=\"language-text\">window.confirm()</code></li>\n<li><code class=\"language-text\">window.print()</code></li>\n<li><code class=\"language-text\">window.prompt()</code></li>\n<li>the <code class=\"language-text\">beforeunload</code> event</li>\n</ul>\n</li>\n<li>\n<p>The sandboxed orientation lock browsing context flag</p>\n<p>This flag disables the ability to lock the screen orientation. [[SCREENORIENTATION]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsSCREENORIENTATION\">https://html.spec.whatwg.org/multipage/references.html#refsSCREENORIENTATION</a>)</p>\n</li>\n<li>\n<p>The sandboxed presentation browsing context flag</p>\n<p>This flag disables the Presentation API. [[PRESENTATION]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsPRESENTATION\">https://html.spec.whatwg.org/multipage/references.html#refsPRESENTATION</a>)</p>\n</li>\n<li>\n<p>The sandboxed downloads browsing context flag</p>\n<p>This flag prevents content from initiating or instantiating downloads, whether through <a href=\"https://html.spec.whatwg.org/multipage/links.html#downloading-hyperlinks\">downloading hyperlinks</a> or through <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#process-a-navigate-response\">navigation</a> that gets handled <a href=\"https://html.spec.whatwg.org/multipage/links.html#as-a-download\">as a download</a>.</p>\n</li>\n<li>\n<p>The sandboxed custom protocols navigation browsing context flag</p>\n<p>This flag prevents navigations toward non <a href=\"https://fetch.spec.whatwg.org/#fetch-scheme\">fetch schemes</a> from being <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#hand-off-to-external-software\">handed off to external software</a>.</p>\n</li>\n</ul>\n<p>When the user agent is to parse a sandboxing directive, given a string <code class=\"language-text\">input</code>, a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxing-flag-set\">sandboxing flag set</a> <code class=\"language-text\">output</code>, it must run the following steps:</p>\n<ol>\n<li><a href=\"https://infra.spec.whatwg.org/#split-on-ascii-whitespace\">Split <code class=\"language-text\">input</code> on ASCII whitespace</a>, to obtain <code class=\"language-text\">tokens</code>.</li>\n<li>Let <code class=\"language-text\">output</code> be empty.</li>\n<li>\n<p>Add the following flags to <code class=\"language-text\">output</code>:</p>\n<ul>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-navigation-browsing-context-flag\">sandboxed navigation browsing context flag</a>.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-auxiliary-navigation-browsing-context-flag\">sandboxed auxiliary navigation browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-popups</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-top-level-navigation-without-user-activation-browsing-context-flag\">sandboxed top-level navigation without user activation browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-top-navigation</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-top-level-navigation-with-user-activation-browsing-context-flag\">sandboxed top-level navigation with user activation browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains either the <code class=\"language-text\">allow-top-navigation-by-user-activation</code> keyword or the <code class=\"language-text\">allow-top-navigation</code> keyword.</li>\n</ul>\n<p> This means that if the <code class=\"language-text\">allow-top-navigation</code> is present, the <code class=\"language-text\">allow-top-navigation-by-user-activation</code> keyword will have no effect. For this reason, specifying both is a document conformance error.</p>\n<ul>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-plugins-browsing-context-flag\">sandboxed plugins browsing context flag</a>.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-origin-browsing-context-flag\">sandboxed origin browsing context flag</a>, unless the <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-same-origin</code> keyword.</li>\n</ul>\n<p> The <code class=\"language-text\">allow-same-origin</code> keyword is intended for two cases.</p>\n<p> First, it can be used to allow content from the same site to be sandboxed to disable scripting, while still allowing access to the DOM of the sandboxed content.</p>\n<p> Second, it can be used to embed content from a third-party site, sandboxed to prevent that site from opening popups, etc, without preventing the embedded page from communicating back to its originating site, using the database APIs to store data, etc.</p>\n<ul>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-forms-browsing-context-flag\">sandboxed forms browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-forms</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-pointer-lock-browsing-context-flag\">sandboxed pointer lock browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-pointer-lock</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-scripts-browsing-context-flag\">sandboxed scripts browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-scripts</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-automatic-features-browsing-context-flag\">sandboxed automatic features browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-scripts</code> keyword (defined above).</li>\n</ul>\n<p> This flag is relaxed by the same keyword as scripts, because when scripts are enabled these features are trivially possible anyway, and it would be unfortunate to force authors to use script to do them when sandboxed rather than allowing them to use the declarative features.</p>\n<ul>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-document.domain-browsing-context-flag\">sandboxed <code class=\"language-text\">document.domain</code> browsing context flag</a>.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandbox-propagates-to-auxiliary-browsing-contexts-flag\">sandbox propagates to auxiliary browsing contexts flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-popups-to-escape-sandbox</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-modals-flag\">sandboxed modals flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-modals</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-orientation-lock-browsing-context-flag\">sandboxed orientation lock browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-orientation-lock</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-presentation-browsing-context-flag\">sandboxed presentation browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-presentation</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-downloads-browsing-context-flag\">sandboxed downloads browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains the <code class=\"language-text\">allow-downloads</code> keyword.</li>\n<li>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxed-custom-protocols-navigation-browsing-context-flag\">sandboxed custom protocols navigation browsing context flag</a>, unless <code class=\"language-text\">tokens</code> contains either the <code class=\"language-text\">allow-top-navigation-to-custom-protocols</code> keyword, the <code class=\"language-text\">allow-popups</code> keyword, or the <code class=\"language-text\">allow-top-navigation</code> keyword.</li>\n</ul>\n</li>\n</ol>\n<hr>\n<p>Every <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a> has a popup sandboxing flag set, which is a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxing-flag-set\">sandboxing flag set</a>. When a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a> is created, its <a href=\"https://html.spec.whatwg.org/multipage/origin.html#popup-sandboxing-flag-set\">popup sandboxing flag set</a> must be empty. It is populated by <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name\">the rules for choosing a browsing context</a> and the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#obtain-browsing-context-navigation\">obtain a browsing context to use for a navigation response</a> algorithm.</p>\n<p>Every <code class=\"language-text\">iframe</code> element has an <code class=\"language-text\">iframe</code> sandboxing flag set, which is a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxing-flag-set\">sandboxing flag set</a>. Which flags in an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#iframe-sandboxing-flag-set\"><code class=\"language-text\">iframe</code> sandboxing flag set</a> are set at any particular time is determined by the <code class=\"language-text\">iframe</code> element's <code class=\"language-text\">sandbox</code> attribute.</p>\n<p>Every <code class=\"language-text\">Document</code> has an active sandboxing flag set, which is a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxing-flag-set\">sandboxing flag set</a>. When the <code class=\"language-text\">Document</code> is created, its <a href=\"https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set\">active sandboxing flag set</a> must be empty. It is populated by the <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate\">navigation algorithm</a>.</p>\n<p>Every resource that is obtained by the <a href=\"https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate\">navigation algorithm</a> has a forced sandboxing flag set, which is a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxing-flag-set\">sandboxing flag set</a>. A resource by default has no flags set in its <a href=\"https://html.spec.whatwg.org/multipage/origin.html#forced-sandboxing-flag-set\">forced sandboxing flag set</a>, but other specifications can define that certain flags are set.</p>\n<p>In particular, the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#forced-sandboxing-flag-set\">forced sandboxing flag set</a> is used by Content Security Policy. [[CSP]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsCSP\">https://html.spec.whatwg.org/multipage/references.html#refsCSP</a>)</p>\n<hr>\n<p>To determine the creation sandboxing flags for a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#concept-document-bc\">browsing context</a> <code class=\"language-text\">browsing context</code>, given null or an element <code class=\"language-text\">embedder</code>, return the <a href=\"https://infra.spec.whatwg.org/#set-union\">union</a> of the flags that are present in the following <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxing-flag-set\">sandboxing flag sets</a>:</p>\n<ul>\n<li>If <code class=\"language-text\">embedder</code> is null, then: the flags set on <code class=\"language-text\">browsing context</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#popup-sandboxing-flag-set\">popup sandboxing flag set</a>.</li>\n<li>If <code class=\"language-text\">embedder</code> is an element, then: the flags set on <code class=\"language-text\">embedder</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#iframe-sandboxing-flag-set\"><code class=\"language-text\">iframe</code> sandboxing flag set</a>.</li>\n<li>If <code class=\"language-text\">embedder</code> is an element, then: the flags set on <code class=\"language-text\">embedder</code>'s <a href=\"https://dom.spec.whatwg.org/#concept-node-document\">node document</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#active-sandboxing-flag-set\">active sandboxing flag set</a>.</li>\n</ul>\n<p>After creation, the sandboxing flags for a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#concept-document-bc\">browsing context</a> <code class=\"language-text\">browsing context</code> are the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#determining-the-creation-sandboxing-flags\">determining the creation sandboxing flags</a> given <code class=\"language-text\">browsing context</code> and <code class=\"language-text\">browsing context</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#bc-container\">container</a>.</p>\n<h3>7.7 Cross-origin opener policies<a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policies\"></a></h3>\n<p>A cross-origin opener policy value allows a document which is navigated to in a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a> to force the creation of a new <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>, and a corresponding <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group\">group</a>. The possible values are:</p>\n<ul>\n<li>\n<p>\"<code class=\"language-text\">unsafe-none</code>\"</p>\n<p>This is the (current) default and means that the document will occupy the same <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a> as its predecessor, unless that document specified a different <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a>.</p>\n</li>\n<li>\n<p>\"<code class=\"language-text\">same-origin-allow-popups</code>\"</p>\n<p>This forces the creation of a new <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a> for the document, unless its predecessor specified the same <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> and they are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>.</p>\n</li>\n<li>\n<p>\"<code class=\"language-text\">same-origin</code>\"</p>\n<p>This behaves the same as \"<code class=\"language-text\">same-origin-allow-popups</code>\", with the addition that any <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#auxiliary-browsing-context\">auxiliary browsing context</a> created needs to contain <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> documents that also have the same <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> or it will appear closed to the opener.</p>\n</li>\n<li>\n<p>\"<code class=\"language-text\">same-origin-plus-COEP</code>\"</p>\n<p>This behaves the same as \"<code class=\"language-text\">same-origin</code>\", with the addition that it sets the (new) <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group\">group</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#bcg-cross-origin-isolation\">cross-origin isolation mode</a> to one of \"<code class=\"language-text\">logical</code>\" or \"<code class=\"language-text\">concrete</code>\".</p>\n<p>\"<code class=\"language-text\">same-origin-plus-COEP</code>\" cannot be directly set via the <code class=\"language-text\">Cross-Origin-Opener-Policy`\\` header, but results from a combination of setting both \\</code>Cross-Origin-Opener-Policy: same-origin<code class=\"language-text\">\\</code> and a ``Cross-Origin-Embedder-Policy header whose value is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a> together.</p>\n</li>\n</ul>\n<p>A cross-origin opener policy consists of:</p>\n<ul>\n<li>A value, which is a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy-value\">cross-origin opener policy value</a>, initially \"<code class=\"language-text\">unsafe-none</code>\".</li>\n<li>A reporting endpoint, which is string or null, initially null.</li>\n<li>A report-only value, which is a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy-value\">cross-origin opener policy value</a>, initially \"<code class=\"language-text\">unsafe-none</code>\".</li>\n<li>A report-only reporting endpoint, which is a string or null, initially null.</li>\n</ul>\n<p>To match cross-origin opener policy values, given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy-value\">cross-origin opener policy value</a> <code class=\"language-text\">A</code>, an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a> <code class=\"language-text\">originA</code>, a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy-value\">cross-origin opener policy value</a> <code class=\"language-text\">B</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a> <code class=\"language-text\">originB</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">A</code> is \"<code class=\"language-text\">unsafe-none</code>\" and <code class=\"language-text\">B</code> is \"<code class=\"language-text\">unsafe-none</code>\", then return true.</li>\n<li>If <code class=\"language-text\">A</code> is \"<code class=\"language-text\">unsafe-none</code>\" or <code class=\"language-text\">B</code> is \"<code class=\"language-text\">unsafe-none</code>\", then return false.</li>\n<li>If <code class=\"language-text\">A</code> is <code class=\"language-text\">B</code> and <code class=\"language-text\">originA</code> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> with <code class=\"language-text\">originB</code>, then return true.</li>\n<li>Return false.</li>\n</ol>\n<h4>7.7.1 The headers<a href=\"https://html.spec.whatwg.org/multipage/origin.html#the-coop-headers\"></a></h4>\n<p><strong>✔</strong>MDN</p>\n<p>A <code class=\"language-text\">Document</code>'s <a href=\"https://html.spec.whatwg.org/multipage/dom.html#concept-document-coop\">cross-origin opener policy</a> is derived from the <code class=\"language-text\">Cross-Origin-Opener-Policy`\\` and \\</code>Cross-Origin-Opener-Policy-Report-Only HTTP response headers. These headers are <a href=\"https://httpwg.org/specs/rfc8941.html\">structured headers</a> whose value must be a <a href=\"https://httpwg.org/specs/rfc8941.html#token\">token</a>. [[STRUCTURED-FIELDS]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsSTRUCTURED-FIELDS\">https://html.spec.whatwg.org/multipage/references.html#refsSTRUCTURED-FIELDS</a>)</p>\n<p>The valid <a href=\"https://httpwg.org/specs/rfc8941.html#token\">token</a> values are the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy-value\">opener policy values</a>. The token may also have attached <a href=\"https://httpwg.org/specs/rfc8941.html#param\">parameters</a>; of these, the \"<code class=\"language-text\">report-to</code>\" parameter can have a <a href=\"https://url.spec.whatwg.org/#valid-url-string\">valid URL string</a> identifying an appropriate reporting endpoint. [[REPORTING]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsREPORTING\">https://html.spec.whatwg.org/multipage/references.html#refsREPORTING</a>)</p>\n<p>Per the processing model described below, user agents will ignore this header if it contains an invalid value. Likewise, user agents will ignore this header if the value cannot be parsed as a <a href=\"https://httpwg.org/specs/rfc8941.html#token\">token</a>.</p>\n<hr>\n<p>To obtain a cross-origin opener policy given a <a href=\"https://fetch.spec.whatwg.org/#concept-response\">response</a> <code class=\"language-text\">response</code> and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment\">environment</a> <code class=\"language-text\">reservedEnvironment</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">policy</code> be a new <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a>.</li>\n<li>If <code class=\"language-text\">reservedEnvironment</code> is a <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#non-secure-context\">non-secure context</a>, then return <code class=\"language-text\">policy</code>.</li>\n<li>Let <code class=\"language-text\">value</code> be the result of <a href=\"https://fetch.spec.whatwg.org/#concept-header-list-get-structured-header\">getting a structured field value</a> given <code class=\"language-text\">Cross-Origin-Opener-Policy</code> and \"<code class=\"language-text\">item</code>\" from <code class=\"language-text\">response</code>'s <a href=\"https://fetch.spec.whatwg.org/#concept-response-header-list\">header list</a>.</li>\n<li>\n<p>If <code class=\"language-text\">parsedItem</code> is not null, then:</p>\n<ol>\n<li>If <code class=\"language-text\">parsedItem</code>[0] is \"<code class=\"language-text\">same-origin</code>\", then:</li>\n<li>Let <code class=\"language-text\">coep</code> be the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#obtain-an-embedder-policy\">obtaining a cross-origin embedder policy</a> from <code class=\"language-text\">response</code> and <code class=\"language-text\">reservedEnvironment</code>.</li>\n<li>If <code class=\"language-text\">coep</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a>, then set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a> to \"<code class=\"language-text\">same-origin-plus-COEP</code>\".</li>\n<li>Otherwise, set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a> to \"<code class=\"language-text\">same-origin</code>\".</li>\n<li>If <code class=\"language-text\">parsedItem</code>[0] is \"<code class=\"language-text\">same-origin-allow-popups</code>\", then set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a> to \"<code class=\"language-text\">same-origin-allow-popups</code>\".</li>\n<li>If <code class=\"language-text\">parsedItem</code>[1][\"<code class=\"language-text\">report-to</code>\"] <a href=\"https://infra.spec.whatwg.org/#map-exists\">exists</a> and it is a string, then set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> to <code class=\"language-text\">parsedItem</code>[1][\"<code class=\"language-text\">report-to</code>\"].</li>\n</ol>\n</li>\n<li>Set <code class=\"language-text\">parsedItem</code> to the result of <a href=\"https://fetch.spec.whatwg.org/#concept-header-list-get-structured-header\">getting a structured field value</a> given <code class=\"language-text\">Cross-Origin-Opener-Policy-Report-Only</code> and \"<code class=\"language-text\">item</code>\" from <code class=\"language-text\">response</code>'s <a href=\"https://fetch.spec.whatwg.org/#concept-response-header-list\">header list</a>.</li>\n<li>\n<p>If <code class=\"language-text\">parsedItem</code> is not null, then:</p>\n<ol>\n<li>If <code class=\"language-text\">parsedItem</code>[0] is \"<code class=\"language-text\">same-origin</code>\", then:</li>\n<li>Let <code class=\"language-text\">coep</code> be the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#obtain-an-embedder-policy\">obtaining a cross-origin embedder policy</a> from <code class=\"language-text\">response</code> and <code class=\"language-text\">reservedEnvironment</code>.</li>\n<li>\n<p>If <code class=\"language-text\">coep</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a> or <code class=\"language-text\">coep</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-report-only-value\">report-only value</a> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a>, then set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a> to \"<code class=\"language-text\">same-origin-plus-COEP</code>\".</p>\n<p> Report only COOP also considers report-only COEP to assign the special \"<code class=\"language-text\">same-origin-plus-COEP</code>\" value. This allows developers more freedom in the order of deployment of COOP and COEP.</p>\n</li>\n<li>Otherwise, set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a> to \"<code class=\"language-text\">same-origin</code>\".</li>\n<li>If <code class=\"language-text\">parsedItem</code>[0] is \"<code class=\"language-text\">same-origin-allow-popups</code>\", then set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a> to \"<code class=\"language-text\">same-origin-allow-popups</code>\".</li>\n<li>If <code class=\"language-text\">parsedItem</code>[1][\"<code class=\"language-text\">report-to</code>\"] <a href=\"https://infra.spec.whatwg.org/#map-exists\">exists</a> and it is a string, then set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-endpoint\">report-only reporting endpoint</a> to <code class=\"language-text\">parsedItem</code>[1][\"<code class=\"language-text\">report-to</code>\"].</li>\n</ol>\n</li>\n<li>Return <code class=\"language-text\">policy</code>.</li>\n</ol>\n<h4>7.7.2 Browsing context group switches due to cross-origin opener policy<a href=\"https://html.spec.whatwg.org/multipage/origin.html#browsing-context-group-switches-due-to-cross-origin-opener-policy\"></a></h4>\n<p>To check if COOP values require a browsing context group switch, given a boolean <code class=\"language-text\">isInitialAboutBlank</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">responseOrigin</code> and <code class=\"language-text\">activeDocumentNavigationOrigin</code>, and two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">cross-origin opener policy values</a> <code class=\"language-text\">responseCOOPValue</code> and <code class=\"language-text\">activeDocumentCOOPValue</code>:</p>\n<ol>\n<li>If the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#matching-coop\">matching</a> <code class=\"language-text\">activeDocumentCOOPValue</code>, <code class=\"language-text\">activeDocumentNavigationOrigin</code>, <code class=\"language-text\">responseCOOPValue</code>, and <code class=\"language-text\">responseOrigin</code> is true, return false.</li>\n<li>\n<p>If all of the following are true:</p>\n<ul>\n<li><code class=\"language-text\">isInitialAboutBlank</code>,</li>\n<li><code class=\"language-text\">activeDocumentCOOPValue</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a> is \"<code class=\"language-text\">same-origin-allow-popups</code>\".</li>\n<li><code class=\"language-text\">responseCOOPValue</code> is \"<code class=\"language-text\">unsafe-none</code>\",</li>\n</ul>\n<p>then return false.</p>\n</li>\n<li>Return true.</li>\n</ol>\n<p>To check if enforcing report-only COOP would require a browsing context group switch, given a boolean <code class=\"language-text\">isInitialAboutBlank</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">responseOrigin</code>, <code class=\"language-text\">activeDocumentNavigationOrigin</code>, and two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policies</a> <code class=\"language-text\">responseCOOP</code> and <code class=\"language-text\">activeDocumentCOOP</code>:</p>\n<ol>\n<li>\n<p>If the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#check-browsing-context-group-switch-coop-value\">checking if COOP values require a browsing context group switch</a> given <code class=\"language-text\">isInitialAboutBlank</code>, <code class=\"language-text\">responseOrigin</code>, <code class=\"language-text\">activeDocumentNavigationOrigin</code>, <code class=\"language-text\">responseCOOP</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a> and <code class=\"language-text\">activeDocumentCOOPReportOnly</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a> is false, then return false.</p>\n<p>Matching report-only policies allows a website to specify the same report-only cross-origin opener policy on all its pages and not receive violation reports for navigations between these pages.</p>\n</li>\n<li>If the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#check-browsing-context-group-switch-coop-value\">checking if COOP values require a browsing context group switch</a> given <code class=\"language-text\">isInitialAboutBlank</code>, <code class=\"language-text\">responseOrigin</code>, <code class=\"language-text\">activeDocumentNavigationOrigin</code>, <code class=\"language-text\">responseCOOP</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a> and <code class=\"language-text\">activeDocumentCOOPReportOnly</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a> is true, then return true.</li>\n<li>If the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#check-browsing-context-group-switch-coop-value\">checking if COOP values require a browsing context group switch</a> given <code class=\"language-text\">isInitialAboutBlank</code>, <code class=\"language-text\">responseOrigin</code>, <code class=\"language-text\">activeDocumentNavigationOrigin</code>, <code class=\"language-text\">responseCOOP</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a> and <code class=\"language-text\">activeDocumentCOOPReportOnly</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a> is true, then return true.</li>\n<li>Return false.</li>\n</ol>\n<p>A cross-origin opener policy enforcement result is a <a href=\"https://infra.spec.whatwg.org/#struct\">struct</a> with the following <a href=\"https://infra.spec.whatwg.org/#struct-item\">items</a>:</p>\n<ul>\n<li>A boolean needs a browsing context group switch, initially false.</li>\n<li>A boolean would need a browsing context group switch due to report-only, initially false.</li>\n<li>A <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> url.</li>\n<li>An <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a> origin.</li>\n<li>A <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> cross-origin opener policy.</li>\n<li>A boolean current context is navigation source.</li>\n</ul>\n<p>To enforce a response's cross-origin opener policy, given a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a> <code class=\"language-text\">browsingContext</code>, a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> <code class=\"language-text\">responseURL</code>, an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origin</a> <code class=\"language-text\">responseOrigin</code>, a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">responseCOOP</code>, a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-result\">cross-origin opener policy enforcement result</a> <code class=\"language-text\">currentCOOPEnforcementResult</code>, and a <a href=\"https://fetch.spec.whatwg.org/#concept-request-referrer\">referrer</a> <code class=\"language-text\">referrer</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">newCOOPEnforcementResult</code> be a new <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-result\">cross-origin opener policy enforcement result</a> whose <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-bcg-switch\">needs a browsing context group switch</a> is <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-bcg-switch\">needs a browsing context group switch</a>, <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-bcg-switch-report-only\">would need a browsing context group switch due to report-only</a> is <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-bcg-switch-report-only\">would need a browsing context group switch due to report-only</a>, <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-url\">url</a> is <code class=\"language-text\">responseURL</code>, <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-origin\">origin</a> is <code class=\"language-text\">responseOrigin</code>, <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-coop\">coop</a> is <code class=\"language-text\">responseCOOP</code>, and <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-source\">current context is navigation source</a> is true.</li>\n<li>Let <code class=\"language-text\">isInitialAboutBlank</code> be true if <code class=\"language-text\">browsingContext</code> is <a href=\"https://html.spec.whatwg.org/multipage/dom.html#still-on-its-initial-about:blank-document\">still on its initial <code class=\"language-text\">about:blank</code> <code class=\"language-text\">Document</code></a>; otherwise, false.</li>\n<li>If <code class=\"language-text\">isInitialAboutBlank</code> is true and <code class=\"language-text\">browsingContext</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-initial-url\">initial URL</a> is null, set <code class=\"language-text\">browsingContext</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-initial-url\">initial URL</a> to <code class=\"language-text\">responseURL</code>.</li>\n<li>\n<p>If the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#check-browsing-context-group-switch-coop-value\">checking if COOP values require a browsing context group switch</a> given <code class=\"language-text\">isInitialAboutBlank</code>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-coop\">cross-origin opener policy</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-origin\">origin</a>, <code class=\"language-text\">responseCOOP</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a>, and <code class=\"language-text\">responseOrigin</code> is true, then:</p>\n<ol>\n<li>Set <code class=\"language-text\">newCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-bcg-switch\">needs a browsing context group switch</a> to true.</li>\n<li>If <code class=\"language-text\">browsingContext</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group\">group</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-set\">browsing context set</a>'s <a href=\"https://infra.spec.whatwg.org/#list-size\">size</a> is greater than 1, then:</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-navigation-to\">Queue a violation report for browsing context group switch when navigating to a COOP response</a> with <code class=\"language-text\">responseCOOP</code>, \"<code class=\"language-text\">enforce</code>\", <code class=\"language-text\">responseURL</code>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-url\">url</a>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-origin\">origin</a>, <code class=\"language-text\">responseOrigin</code>, and <code class=\"language-text\">referrer</code>.</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-navigation-from\">Queue a violation report for browsing context group switch when navigating away from a COOP response</a> with <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-coop\">cross-origin opener policy</a>, \"<code class=\"language-text\">enforce</code>\", <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-url\">url</a>, <code class=\"language-text\">responseURL</code>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-origin\">origin</a>, <code class=\"language-text\">responseOrigin</code>, and <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-source\">current context is navigation source</a>.</li>\n</ol>\n</li>\n<li>\n<p>If the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#check-bcg-switch-navigation-report-only\">checking if enforcing report-only COOP would require a browsing context group switch</a> given <code class=\"language-text\">isInitialAboutBlank</code>, <code class=\"language-text\">responseOrigin</code>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-origin\">origin</a>, <code class=\"language-text\">responseCOOP</code>, and <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-coop\">cross-origin opener policy</a>, is true, then:</p>\n<ol>\n<li>Set <code class=\"language-text\">result</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-bcg-switch-report-only\">would need a browsing context group switch due to report-only</a> to true.</li>\n<li>If <code class=\"language-text\">browsingContext</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group\">group</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-set\">browsing context set</a>'s <a href=\"https://infra.spec.whatwg.org/#list-size\">size</a> is greater than 1, then:</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-navigation-to\">Queue a violation report for browsing context group switch when navigating to a COOP response</a> with <code class=\"language-text\">responseCOOP</code>, \"<code class=\"language-text\">reporting</code>\", <code class=\"language-text\">responseURL</code>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-url\">url</a>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-origin\">origin</a>, <code class=\"language-text\">responseOrigin</code>, and <code class=\"language-text\">referrer</code>.</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-navigation-from\">Queue a violation report for browsing context group switch when navigating away from a COOP response</a> with <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-coop\">cross-origin opener policy</a>, \"<code class=\"language-text\">reporting</code>\", <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-url\">url</a>, <code class=\"language-text\">responseURL</code>, <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-origin\">origin</a>, <code class=\"language-text\">responseOrigin</code>, and <code class=\"language-text\">currentCOOPEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-source\">current context is navigation source</a>.</li>\n</ol>\n</li>\n<li>Return <code class=\"language-text\">newCOOPEnforcementResult</code>.</li>\n</ol>\n<p>To obtain a browsing context to use for a navigation response, given a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a> <code class=\"language-text\">browsingContext</code>, a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sandboxing-flag-set\">sandboxing flag set</a> <code class=\"language-text\">sandboxFlags</code>, a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">navigationCOOP</code>, and a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-result\">cross-origin opener policy enforcement result</a> <code class=\"language-text\">coopEnforcementResult</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">browsingContext</code> is not a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>, return <code class=\"language-text\">browsingContext</code>.</li>\n<li>\n<p>If <code class=\"language-text\">coopEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-bcg-switch\">needs a browsing context group switch</a> is false, then:</p>\n<ol>\n<li>If <code class=\"language-text\">coopEnforcementResult</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-enforcement-bcg-switch-report-only\">would need a browsing context group switch due to report-only</a> is true, set <code class=\"language-text\">browsing context</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#virtual-browsing-context-group-id\">virtual browsing context group ID</a> to a new unique identifier.</li>\n<li>Return <code class=\"language-text\">browsingContext</code>.</li>\n</ol>\n</li>\n<li>Let <code class=\"language-text\">newBrowsingContext</code> be the result of <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#creating-a-new-top-level-browsing-context\">creating a new top-level browsing context</a>.</li>\n<li>\n<p>If <code class=\"language-text\">navigationCOOP</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a> is \"<code class=\"language-text\">same-origin-plus-COEP</code>\", then set <code class=\"language-text\">newBrowsingContext</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group\">group</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#bcg-cross-origin-isolation\">cross-origin isolation mode</a> to either \"<code class=\"language-text\">logical</code>\" or \"<code class=\"language-text\">concrete</code>\". The choice of which is <a href=\"https://infra.spec.whatwg.org/#implementation-defined\">implementation-defined</a>.</p>\n<p>It is difficult on some platforms to provide the security properties required by the <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-cross-origin-isolated-capability\">cross-origin isolated capability</a>. \"<code class=\"language-text\">concrete</code>\" grants access to it and \"<code class=\"language-text\">logical</code>\" does not.</p>\n</li>\n<li>\n<p>If <code class=\"language-text\">sandboxFlags</code> is not empty, then:</p>\n<ol>\n<li>Assert <code class=\"language-text\">navigationCOOP</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a> is \"<code class=\"language-text\">unsafe-none</code>\".</li>\n<li>Assert: <code class=\"language-text\">newBrowsingContext</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#popup-sandboxing-flag-set\">popup sandboxing flag set</a> <a href=\"https://infra.spec.whatwg.org/#list-is-empty\">is empty</a>.</li>\n<li>Set <code class=\"language-text\">newBrowsingContext</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#popup-sandboxing-flag-set\">popup sandboxing flag set</a> to a <a href=\"https://infra.spec.whatwg.org/#list-clone\">clone</a> of <code class=\"language-text\">sandboxFlags</code>.</li>\n</ol>\n</li>\n<li>\n<p><a href=\"https://html.spec.whatwg.org/multipage/window-object.html#a-browsing-context-is-discarded\">Discard</a> <code class=\"language-text\">browsingContext</code>.</p>\n<p>This has no effect on <code class=\"language-text\">browsingContext</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#tlbc-group\">group</a>, unless <code class=\"language-text\">browsingContext</code> was its sole <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>. In that case, the user agent might delete the <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group\">browsing context group</a> which no longer contains any <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing contexts</a>.</p>\n</li>\n<li>Return <code class=\"language-text\">newBrowsingContext</code>.</li>\n</ol>\n<p>The impact of swapping browsing context groups following a navigation is not fully defined. It is currently under discussion in <a href=\"https://github.com/whatwg/html/issues/5350\">issue #5350</a>.</p>\n<h4>7.7.3 Reporting<a href=\"https://html.spec.whatwg.org/multipage/origin.html#reporting\"></a></h4>\n<p>An accessor-accessed relationship is an enum that describes the relationship between two <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing contexts</a> between which an access happened. It can take the following values:</p>\n<ul>\n<li>\n<p>accessor is opener</p>\n<p>The accessor <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a> or one of its <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#ancestor-browsing-context\">ancestors</a> is the <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#opener-browsing-context\">opener browsing context</a> of the accessed <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>.</p>\n</li>\n<li>\n<p>accessor is openee</p>\n<p>The accessed <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a> or one of its <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#ancestor-browsing-context\">ancestors</a> is the <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#opener-browsing-context\">opener browsing context</a> of the accessor <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>.</p>\n</li>\n<li>\n<p>none</p>\n<p>There is no opener relationship between the accessor <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a>, the accessor <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a>, or any of their <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#ancestor-browsing-context\">ancestors</a>.</p>\n</li>\n</ul>\n<p>To check if an access between two browsing contexts should be reported, given two <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing contexts</a> <code class=\"language-text\">accessor</code> and <code class=\"language-text\">accessed</code>, a JavaScript property name <code class=\"language-text\">P</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\">environment settings object</a> <code class=\"language-text\">environment</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">P</code> is not a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#cross-origin-accessible-window-property-name\">cross-origin accessible window property name</a>, then return.</li>\n<li>\n<p>If <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a> or any of its <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#ancestor-browsing-context\">ancestors</a>' <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origins</a> are not <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> with <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a>, or if <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a> or any of its <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#ancestor-browsing-context\">ancestors</a>' <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origins</a> are not <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> with <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a>, then return.</p>\n<p>This avoids leaking information about cross-origin iframes to a top level frame with cross-origin opener policy reporting.</p>\n</li>\n<li>If <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#virtual-browsing-context-group-id\">virtual browsing context group ID</a> is <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#virtual-browsing-context-group-id\">virtual browsing context group ID</a>, then return.</li>\n<li>Let <code class=\"language-text\">accessorAccessedRelationship</code> be a new <a href=\"https://html.spec.whatwg.org/multipage/origin.html#accessor-accessed-relationship\">accessor-accessed relationship</a> with value <a href=\"https://html.spec.whatwg.org/multipage/origin.html#accessor-accessed-none\">none</a>.</li>\n<li>If <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#opener-browsing-context\">opener browsing context</a> is <code class=\"language-text\">accessor</code> or an <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#ancestor-browsing-context\">ancestor</a> of <code class=\"language-text\">accessor</code>, then set <code class=\"language-text\">accessorAccessedRelationship</code> to <a href=\"https://html.spec.whatwg.org/multipage/origin.html#accessor-accessed-opener\">accessor is opener</a>.</li>\n<li>If <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#opener-browsing-context\">opener browsing context</a> is <code class=\"language-text\">accessed</code> or an <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#ancestor-browsing-context\">ancestor</a> of <code class=\"language-text\">accessed</code>, then set <code class=\"language-text\">accessorAccessedRelationship</code> to <a href=\"https://html.spec.whatwg.org/multipage/origin.html#accessor-accessed-openee\">accessor is openee</a>.</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-access\">Queue violation reports for accesses</a>, given <code class=\"language-text\">accessorAccessedRelationship</code>, <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://html.spec.whatwg.org/multipage/dom.html#concept-document-coop\">cross-origin opener policy</a>, <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://html.spec.whatwg.org/multipage/dom.html#concept-document-coop\">cross-origin opener policy</a>, <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-url\">URL</a>, <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-url\">URL</a>, <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-initial-url\">initial URL</a>, <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-initial-url\">initial URL</a>, <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a>, <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://dom.spec.whatwg.org/#concept-document-origin\">origin</a>, <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#opener-origin-at-creation\">opener origin at creation</a>, <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#opener-origin-at-creation\">opener origin at creation</a>, <code class=\"language-text\">accessor</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://html.spec.whatwg.org/multipage/dom.html#dom-document-referrer\">referrer</a>, <code class=\"language-text\">accessed</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#top-level-browsing-context\">top-level browsing context</a>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#active-document\">active document</a>'s <a href=\"https://html.spec.whatwg.org/multipage/dom.html#dom-document-referrer\">referrer</a>, <code class=\"language-text\">P</code>, and <code class=\"language-text\">environment</code>.</li>\n</ol>\n<p>To sanitize a URL to send in a report given a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> <code class=\"language-text\">url</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">sanitizedURL</code> be a copy of <code class=\"language-text\">url</code>.</li>\n<li><a href=\"https://url.spec.whatwg.org/#set-the-username\">Set the username</a> given <code class=\"language-text\">sanitizedURL</code> and the empty string.</li>\n<li><a href=\"https://url.spec.whatwg.org/#set-the-password\">Set the password</a> given <code class=\"language-text\">sanitizedURL</code> and the empty string.</li>\n<li>Return the <a href=\"https://url.spec.whatwg.org/#concept-url-serializer\">serialization</a> of <code class=\"language-text\">sanitizedURL</code> with <em><a href=\"https://url.spec.whatwg.org/#url-serializer-exclude-fragment\">exclude fragment</a></em> set to true.</li>\n</ol>\n<p>To queue a violation report for browsing context group switch when navigating to a COOP response given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">coop</code>, a string <code class=\"language-text\">disposition</code>, a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> <code class=\"language-text\">coopURL</code>, a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> <code class=\"language-text\">previousResponseURL</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">previousResponseOrigin</code>, and a <a href=\"https://fetch.spec.whatwg.org/#concept-request-referrer\">referrer</a> <code class=\"language-text\">referrer</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> is null, return.</li>\n<li>Let <code class=\"language-text\">coopValue</code> be <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a>.</li>\n<li>If <code class=\"language-text\">disposition</code> is \"<code class=\"language-text\">reporting</code>\", then set <code class=\"language-text\">coopValue</code> to <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a>.</li>\n<li>Let <code class=\"language-text\">serializedReferrer</code> be an empty string.</li>\n<li>If <code class=\"language-text\">referrer</code> is a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a>, set <code class=\"language-text\">serializedReferrer</code> to the <a href=\"https://url.spec.whatwg.org/#concept-url-serializer\">serialization</a> of <code class=\"language-text\">referrer</code>.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>disposition</td>\n<td><code class=\"language-text\">disposition</code></td>\n</tr>\n<tr>\n<td>effectivePolicy</td>\n<td><code class=\"language-text\">coopValue</code></td>\n</tr>\n<tr>\n<td>previousResponseURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">previousResponseOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">previousResponseURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>referrer</td>\n<td><code class=\"language-text\">serializedReferrer</code></td>\n</tr>\n<tr>\n<td>type</td>\n<td>\"<code class=\"language-text\">navigation-to-response</code>\"</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as \"<code class=\"language-text\">coop</code>\" for <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> with <code class=\"language-text\">coopURL</code>.</li>\n</ol>\n<p>To queue a violation report for browsing context group switch when navigating away from a COOP response given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">coop</code>, a string <code class=\"language-text\">disposition</code>, a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> <code class=\"language-text\">coopURL</code>, a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> <code class=\"language-text\">nextResponseURL</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">nextResponseOrigin</code>, and a boolean <code class=\"language-text\">isCOOPResponseNavigationSource</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> is null, return.</li>\n<li>Let <code class=\"language-text\">coopValue</code> be <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a>.</li>\n<li>If <code class=\"language-text\">disposition</code> is \"<code class=\"language-text\">reporting</code>\", then set <code class=\"language-text\">coopValue</code> to <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a>.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>disposition</td>\n<td><code class=\"language-text\">disposition</code></td>\n</tr>\n<tr>\n<td>effectivePolicy</td>\n<td><code class=\"language-text\">coopValue</code></td>\n</tr>\n<tr>\n<td>nextResponseURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">nextResponseOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a> or <code class=\"language-text\">isCOOPResponseNavigationSource</code> is true, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">previousResponseURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>type</td>\n<td>\"<code class=\"language-text\">navigation-from-response</code>\"</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as \"<code class=\"language-text\">coop</code>\" for <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> with <code class=\"language-text\">coopURL</code>.</li>\n</ol>\n<p>To queue violation reports for accesses, given an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#accessor-accessed-relationship\">accessor-accessed relationship</a> <code class=\"language-text\">accessorAccessedRelationship</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policies</a> <code class=\"language-text\">accessorCOOP</code> and <code class=\"language-text\">accessedCOOP</code>, four <a href=\"https://url.spec.whatwg.org/#concept-url\">URLs</a> <code class=\"language-text\">accessorURL</code>, <code class=\"language-text\">accessedURL</code>, <code class=\"language-text\">accessorInitialURL</code>, <code class=\"language-text\">accessedInitialURL</code>, four <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">accessorOrigin</code>, <code class=\"language-text\">accessedOrigin</code>, <code class=\"language-text\">accessorCreatorOrigin</code> and <code class=\"language-text\">accessedCreatorOrigin</code>, two <a href=\"https://html.spec.whatwg.org/multipage/dom.html#dom-document-referrer\">referrers</a> <code class=\"language-text\">accessorReferrer</code> and <code class=\"language-text\">accessedReferrer</code>, a string <code class=\"language-text\">propertyName</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\">environment settings object</a> <code class=\"language-text\">environment</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> is null, return.</li>\n<li>Let <code class=\"language-text\">coopValue</code> be <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-value\">value</a>.</li>\n<li>If <code class=\"language-text\">disposition</code> is \"<code class=\"language-text\">reporting</code>\", then set <code class=\"language-text\">coopValue</code> to <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a>.</li>\n<li>\n<p>If <code class=\"language-text\">accessorAccessedRelationship</code> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#accessor-accessed-opener\">accessor is opener</a>:</p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-access-to-opened\">Queue a violation report for access to an opened window</a>, given <code class=\"language-text\">accessorCOOP</code>, <code class=\"language-text\">accessorURL</code>, <code class=\"language-text\">accessedURL</code>, <code class=\"language-text\">accessedInitialURL</code>, <code class=\"language-text\">accessorOrigin</code>, <code class=\"language-text\">accessedOrigin</code>, <code class=\"language-text\">accessedCreatorOrigin</code>, <code class=\"language-text\">propertyName</code>, and <code class=\"language-text\">environment</code>.</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-access-from-opener\">Queue a violation report for access from the opener</a>, given <code class=\"language-text\">accessedCOOP</code>, <code class=\"language-text\">accessedURL</code>, <code class=\"language-text\">accessorURL</code>, <code class=\"language-text\">accessedOrigin</code>, <code class=\"language-text\">accessorOrigin</code>, <code class=\"language-text\">propertyName</code>, and <code class=\"language-text\">accessedReferrer</code>.</li>\n</ol>\n</li>\n<li>\n<p>Otherwise, if <code class=\"language-text\">accessorAccessedRelationship</code> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#accessor-accessed-openee\">accessor is openee</a>:</p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-access-to-opener\">Queue a violation report for access to the opener</a>, given <code class=\"language-text\">accessorCOOP</code>, <code class=\"language-text\">accessorURL</code>, <code class=\"language-text\">accessedURL</code>, <code class=\"language-text\">accessorOrigin</code>, <code class=\"language-text\">accessedOrigin</code>, <code class=\"language-text\">propertyName</code>, <code class=\"language-text\">accessorReferrer</code>, and <code class=\"language-text\">environment</code>.</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-access-from-opened\">Queue a violation report for access from an opened window</a>, given <code class=\"language-text\">accessedCOOP</code>, <code class=\"language-text\">accessedURL</code>, <code class=\"language-text\">accessorURL</code>, <code class=\"language-text\">accessorInitialURL</code>, <code class=\"language-text\">accessedOrigin</code>, <code class=\"language-text\">accessorOrigin</code>, <code class=\"language-text\">accessorCreatorOrigin</code>, and <code class=\"language-text\">propertyName</code>.</li>\n</ol>\n</li>\n<li>\n<p>Otherwise:</p>\n<ol>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-access-to-opened\">Queue a violation report for access to another window</a>, given <code class=\"language-text\">accessorCOOP</code>, <code class=\"language-text\">accessorURL</code>, <code class=\"language-text\">accessedURL</code>, <code class=\"language-text\">accessorOrigin</code>, <code class=\"language-text\">accessedOrigin</code>, <code class=\"language-text\">propertyName</code>, and <code class=\"language-text\">environment</code></li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-violation-access-from-other\">Queue a violation report for access from another window</a>, given <code class=\"language-text\">accessedCOOP</code>, <code class=\"language-text\">accessedURL</code>, <code class=\"language-text\">accessorURL</code>, <code class=\"language-text\">accessedOrigin</code>, <code class=\"language-text\">accessorOrigin</code>, and <code class=\"language-text\">propertyName</code>.</li>\n</ol>\n</li>\n</ol>\n<p>To queue a violation report for access to the opener, given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">coop</code>, two <a href=\"https://url.spec.whatwg.org/#concept-url\">URLs</a> <code class=\"language-text\">coopURL</code> and <code class=\"language-text\">openerURL</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">openerOrigin</code>, a string <code class=\"language-text\">propertyName</code>, a <a href=\"https://fetch.spec.whatwg.org/#concept-request-referrer\">referrer</a> <code class=\"language-text\">referrer</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\">environment settings object</a> <code class=\"language-text\">environment</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">sourceFile</code>, <code class=\"language-text\">lineNumber</code> and <code class=\"language-text\">columnNumber</code> be the relevant script URL and problematic position which triggered this report.</li>\n<li>Let <code class=\"language-text\">serializedReferrer</code> be an empty string.</li>\n<li>If <code class=\"language-text\">referrer</code> is a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a>, set <code class=\"language-text\">serializedReferrer</code> to the <a href=\"https://url.spec.whatwg.org/#concept-url-serializer\">serialization</a> of <code class=\"language-text\">referrer</code>.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>disposition</td>\n<td>\"<code class=\"language-text\">reporting</code>\"</td>\n</tr>\n<tr>\n<td>effectivePolicy</td>\n<td><code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a></td>\n</tr>\n<tr>\n<td>property</td>\n<td><code class=\"language-text\">propertyName</code></td>\n</tr>\n<tr>\n<td>openerURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">openerOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">openerURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>referrer</td>\n<td><code class=\"language-text\">serializedReferrer</code></td>\n</tr>\n<tr>\n<td>sourceFile</td>\n<td><code class=\"language-text\">sourceFile</code></td>\n</tr>\n<tr>\n<td>lineNumber</td>\n<td><code class=\"language-text\">lineNumber</code></td>\n</tr>\n<tr>\n<td>columnNumber</td>\n<td><code class=\"language-text\">columnNumber</code></td>\n</tr>\n<tr>\n<td>type</td>\n<td>\"<code class=\"language-text\">access-to-opener</code>\"</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as \"<code class=\"language-text\">coop</code>\" for <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> with <code class=\"language-text\">coopURL</code> and <code class=\"language-text\">environment</code>.</li>\n</ol>\n<p>To queue a violation report for access to an opened window, given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">coop</code>, three <a href=\"https://url.spec.whatwg.org/#concept-url\">URLs</a> <code class=\"language-text\">coopURL</code>, <code class=\"language-text\">openedWindowURL</code> and <code class=\"language-text\">initialWindowURL</code>, three <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">coopOrigin</code>, <code class=\"language-text\">openedWindowOrigin</code>, and <code class=\"language-text\">openerInitialOrigin</code>, a string <code class=\"language-text\">propertyName</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\">environment settings object</a> <code class=\"language-text\">environment</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">sourceFile</code>, <code class=\"language-text\">lineNumber</code> and <code class=\"language-text\">columnNumber</code> be the relevant script URL and problematic position which triggered this report.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>disposition</td>\n<td>\"<code class=\"language-text\">reporting</code>\"</td>\n</tr>\n<tr>\n<td>effectivePolicy</td>\n<td><code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a></td>\n</tr>\n<tr>\n<td>property</td>\n<td><code class=\"language-text\">propertyName</code></td>\n</tr>\n<tr>\n<td>openedWindowURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">openedWindowOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">openedWindowURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>openedWindowInitialURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">openerInitialOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">initialWindowURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>sourceFile</td>\n<td><code class=\"language-text\">sourceFile</code></td>\n</tr>\n<tr>\n<td>lineNumber</td>\n<td><code class=\"language-text\">lineNumber</code></td>\n</tr>\n<tr>\n<td>columnNumber</td>\n<td><code class=\"language-text\">columnNumber</code></td>\n</tr>\n<tr>\n<td>type</td>\n<td>\"<code class=\"language-text\">access-to-opener</code>\"</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as \"<code class=\"language-text\">coop</code>\" for <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> with <code class=\"language-text\">coopURL</code> and <code class=\"language-text\">environment</code>.</li>\n</ol>\n<p>To queue a violation report for access to another window, given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">coop</code>, two <a href=\"https://url.spec.whatwg.org/#concept-url\">URLs</a> <code class=\"language-text\">coopURL</code> and <code class=\"language-text\">otherURL</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">otherOrigin</code>, a string <code class=\"language-text\">propertyName</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\">environment settings object</a> <code class=\"language-text\">environment</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">sourceFile</code>, <code class=\"language-text\">lineNumber</code> and <code class=\"language-text\">columnNumber</code> be the relevant script URL and problematic position which triggered this report.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>disposition</td>\n<td>\"<code class=\"language-text\">reporting</code>\"</td>\n</tr>\n<tr>\n<td>effectivePolicy</td>\n<td><code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a></td>\n</tr>\n<tr>\n<td>property</td>\n<td><code class=\"language-text\">propertyName</code></td>\n</tr>\n<tr>\n<td>otherURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">otherOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">otherURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>sourceFile</td>\n<td><code class=\"language-text\">sourceFile</code></td>\n</tr>\n<tr>\n<td>lineNumber</td>\n<td><code class=\"language-text\">lineNumber</code></td>\n</tr>\n<tr>\n<td>columnNumber</td>\n<td><code class=\"language-text\">columnNumber</code></td>\n</tr>\n<tr>\n<td>type</td>\n<td>\"<code class=\"language-text\">access-to-opener</code>\"</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as \"<code class=\"language-text\">coop</code>\" for <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> with <code class=\"language-text\">coopURL</code> and <code class=\"language-text\">environment</code>.</li>\n</ol>\n<p>To queue a violation report for access from the opener, given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">coop</code>, two <a href=\"https://url.spec.whatwg.org/#concept-url\">URLs</a> <code class=\"language-text\">coopURL</code> and <code class=\"language-text\">openerURL</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">openerOrigin</code>, a string <code class=\"language-text\">propertyName</code>, and a <a href=\"https://fetch.spec.whatwg.org/#concept-request-referrer\">referrer</a> <code class=\"language-text\">referrer</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> is null, return.</li>\n<li>Let <code class=\"language-text\">serializedReferrer</code> be an empty string.</li>\n<li>If <code class=\"language-text\">referrer</code> is a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a>, set <code class=\"language-text\">serializedReferrer</code> to the <a href=\"https://url.spec.whatwg.org/#concept-url-serializer\">serialization</a> of <code class=\"language-text\">referrer</code>.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>disposition</td>\n<td>\"<code class=\"language-text\">reporting</code>\"</td>\n</tr>\n<tr>\n<td>effectivePolicy</td>\n<td><code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a></td>\n</tr>\n<tr>\n<td>property</td>\n<td><code class=\"language-text\">propertyName</code></td>\n</tr>\n<tr>\n<td>openerURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">openerOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">openerURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>referrer</td>\n<td><code class=\"language-text\">serializedReferrer</code></td>\n</tr>\n<tr>\n<td>type</td>\n<td>\"<code class=\"language-text\">access-to-opener</code>\"</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as \"<code class=\"language-text\">coop</code>\" for <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> with <code class=\"language-text\">coopURL</code>.</li>\n</ol>\n<p>To queue a violation report for access from an opened window, given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">coop</code>, three <a href=\"https://url.spec.whatwg.org/#concept-url\">URLs</a> <code class=\"language-text\">coopURL</code>, <code class=\"language-text\">openedWindowURL</code> and <code class=\"language-text\">initialWindowURL</code>, three <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">coopOrigin</code>, <code class=\"language-text\">openedWindowOrigin</code>, and <code class=\"language-text\">openerInitialOrigin</code>, and a string <code class=\"language-text\">propertyName</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> is null, return.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>disposition</td>\n<td>\"<code class=\"language-text\">reporting</code>\"</td>\n</tr>\n<tr>\n<td>effectivePolicy</td>\n<td><code class=\"language-text\">coopValue</code></td>\n</tr>\n<tr>\n<td>property</td>\n<td><code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a></td>\n</tr>\n<tr>\n<td>openedWindowURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">openedWindowOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">openedWindowURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>openedWindowInitialURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">openerInitialOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">initialWindowURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>type</td>\n<td>\"<code class=\"language-text\">access-to-opener</code>\"</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as \"<code class=\"language-text\">coop</code>\" for <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> with <code class=\"language-text\">coopURL</code>.</li>\n</ol>\n<p>To queue a violation report for access from another window, given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#cross-origin-opener-policy\">cross-origin opener policy</a> <code class=\"language-text\">coop</code>, two <a href=\"https://url.spec.whatwg.org/#concept-url\">URLs</a> <code class=\"language-text\">coopURL</code> and <code class=\"language-text\">otherURL</code>, two <a href=\"https://html.spec.whatwg.org/multipage/origin.html#concept-origin\">origins</a> <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">otherOrigin</code>, and a string <code class=\"language-text\">propertyName</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> is null, return.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>disposition</td>\n<td>\"<code class=\"language-text\">reporting</code>\"</td>\n</tr>\n<tr>\n<td>effectivePolicy</td>\n<td><code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-only-value\">report-only value</a></td>\n</tr>\n<tr>\n<td>property</td>\n<td><code class=\"language-text\">propertyName</code></td>\n</tr>\n<tr>\n<td>otherURL</td>\n<td>If <code class=\"language-text\">coopOrigin</code> and <code class=\"language-text\">otherOrigin</code> are <a href=\"https://html.spec.whatwg.org/multipage/origin.html#same-origin\">same origin</a>, this is the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#sanitize-url-report\">sanitization</a> of <code class=\"language-text\">otherURL</code>, null otherwise.</td>\n</tr>\n<tr>\n<td>type</td>\n<td><code class=\"language-text\">access-to-opener</code></td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as \"<code class=\"language-text\">coop</code>\" for <code class=\"language-text\">coop</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coop-struct-report-endpoint\">reporting endpoint</a> with <code class=\"language-text\">coopURL</code>.</li>\n</ol>\n<h3>7.8 Cross-origin embedder policies<a href=\"https://html.spec.whatwg.org/multipage/origin.html#coep\"></a></h3>\n<p><strong>✔</strong>MDN</p>\n<p>An embedder policy value is one of three strings that controls the fetching of cross-origin resources without explicit permission from resource owners.</p>\n<ul>\n<li>\n<p>\"<code class=\"language-text\">unsafe-none</code>\"</p>\n<p>This is the default value. When this value is used, cross-origin resources can be fetched without giving explicit permission through the <a href=\"https://fetch.spec.whatwg.org/#http-cors-protocol\">CORS protocol</a> or the <code class=\"language-text\">Cross-Origin-Resource-Policy</code> header.</p>\n</li>\n<li>\n<p>\"<code class=\"language-text\">require-corp</code>\"</p>\n<p>When this value is used, fetching cross-origin resources requires the server's explicit permission through the <a href=\"https://fetch.spec.whatwg.org/#http-cors-protocol\">CORS protocol</a> or the <code class=\"language-text\">Cross-Origin-Resource-Policy</code> header.</p>\n</li>\n<li>\n<p>\"<code class=\"language-text\">credentialless</code>\"</p>\n<p>When this value is used, fetching cross-origin no-CORS resources omits credentials. In exchange, an explicit <code class=\"language-text\">Cross-Origin-Resource-Policy</code> header is not required. Other requests sent with credentials require the server's explicit permission through the <a href=\"https://fetch.spec.whatwg.org/#http-cors-protocol\">CORS protocol</a> or the <code class=\"language-text\">Cross-Origin-Resource-Policy</code> header.</p>\n</li>\n</ul>\n<p>Before supporting \"<code class=\"language-text\">credentialless</code>\", implementers are strongly encouraged to support both:</p>\n<ul>\n<li><a href=\"https://wicg.github.io/private-network-access/\">Private Network Access</a></li>\n<li><a href=\"https://github.com/annevk/orb\">Opaque Response Blocking</a></li>\n</ul>\n<p>Otherwise, it would allow attackers to leverage the client's network position to read non public resources, using the <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-cross-origin-isolated-capability\">cross-origin isolated capability</a>.</p>\n<p>An <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value\">embedder policy value</a> is compatible with cross-origin isolation if it is \"<code class=\"language-text\">credentialless</code>\" or \"<code class=\"language-text\">require-corp</code>\".</p>\n<p>An embedder policy consists of:</p>\n<ul>\n<li>A value, which is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value\">embedder policy value</a>, initially \"<code class=\"language-text\">unsafe-none</code>\".</li>\n<li>A reporting endpoint string, initially the empty string.</li>\n<li>A report only value, which is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value\">embedder policy value</a>, initially \"<code class=\"language-text\">unsafe-none</code>\".</li>\n<li>A report only reporting endpoint string, initially the empty string.</li>\n</ul>\n<p>The \"<code class=\"language-text\">coep</code>\" report type is a <a href=\"https://w3c.github.io/reporting/#report-type\">report type</a> whose value is \"<code class=\"language-text\">coep</code>\". It is <a href=\"https://w3c.github.io/reporting/#visible-to-reportingobservers\">visible to <code class=\"language-text\">ReportingObserver</code>s</a>.</p>\n<h4>7.8.1 The headers<a href=\"https://html.spec.whatwg.org/multipage/origin.html#the-coep-headers\"></a></h4>\n<p>The <code class=\"language-text\">Cross-Origin-Embedder-Policy`\\` and \\</code>Cross-Origin-Embedder-Policy-Report-Only HTTP response headers allow a server to declare an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy\">embedder policy</a> for an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\">environment settings object</a>. These headers are <a href=\"https://httpwg.org/specs/rfc8941.html\">structured headers</a> whose values must be <a href=\"https://httpwg.org/specs/rfc8941.html#token\">token</a>. [[STRUCTURED-FIELDS]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsSTRUCTURED-FIELDS\">https://html.spec.whatwg.org/multipage/references.html#refsSTRUCTURED-FIELDS</a>)</p>\n<p>The valid <a href=\"https://httpwg.org/specs/rfc8941.html#token\">token</a> values are the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value\">embedder policy values</a>. The token may also have attached <a href=\"https://httpwg.org/specs/rfc8941.html#param\">parameters</a>; of these, the \"<code class=\"language-text\">report-to</code>\" parameter can have a <a href=\"https://url.spec.whatwg.org/#valid-url-string\">valid URL string</a> identifying an appropriate reporting endpoint. [[REPORTING]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsREPORTING\">https://html.spec.whatwg.org/multipage/references.html#refsREPORTING</a>)</p>\n<p>The <a href=\"https://html.spec.whatwg.org/multipage/origin.html#obtain-an-embedder-policy\">processing model</a> fails open (by defaulting to \"<code class=\"language-text\">unsafe-none</code>\") in the presence of a header that cannot be parsed as a token. This includes inadvertent lists created by combining multiple instances of the <code class=\"language-text\">Cross-Origin-Embedder-Policy</code> header present in a given response:</p>\n<table>\n<thead>\n<tr>\n<th><code class=\"language-text\">Cross-Origin-Embedder-Policy</code></th>\n<th>Final <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value\">embedder policy value</a></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><em>No header delivered</em></td>\n<td>\"<code class=\"language-text\">unsafe-none</code>\"</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">require-corp</code></td>\n<td>\"<code class=\"language-text\">require-corp</code>\"</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">unknown-value</code></td>\n<td>\"<code class=\"language-text\">unsafe-none</code>\"</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">require-corp, unknown-value</code></td>\n<td>\"<code class=\"language-text\">unsafe-none</code>\"</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">unknown-value, unknown-value</code></td>\n<td>\"<code class=\"language-text\">unsafe-none</code>\"</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">unknown-value, require-corp</code></td>\n<td>\"<code class=\"language-text\">unsafe-none</code>\"</td>\n</tr>\n<tr>\n<td><code class=\"language-text\">require-corp, require-corp</code></td>\n<td>\"<code class=\"language-text\">unsafe-none</code>\"</td>\n</tr>\n</tbody>\n</table>\n<p>(The same applies to <code class=\"language-text\">Cross-Origin-Embedder-Policy-Report-Only</code>.)</p>\n<hr>\n<p>To obtain an embedder policy from a <a href=\"https://fetch.spec.whatwg.org/#concept-response\">response</a> <code class=\"language-text\">response</code> and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment\">environment</a> <code class=\"language-text\">environment</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">policy</code> be a new <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy\">embedder policy</a>.</li>\n<li>If <code class=\"language-text\">environment</code> is a <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#non-secure-context\">non-secure context</a>, then return <code class=\"language-text\">policy</code>.</li>\n<li>Let <code class=\"language-text\">parsedItem</code> be the result of <a href=\"https://fetch.spec.whatwg.org/#concept-header-list-get-structured-header\">getting a structured field value</a> with <code class=\"language-text\">Cross-Origin-Embedder-Policy</code> and \"<code class=\"language-text\">item</code>\" from <code class=\"language-text\">response</code>'s <a href=\"https://fetch.spec.whatwg.org/#concept-response-header-list\">header list</a>.</li>\n<li>\n<p>If <code class=\"language-text\">parsedItem</code> is non-null and <code class=\"language-text\">parsedItem</code>[0] is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a>:</p>\n<ol>\n<li>Set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> to <code class=\"language-text\">parsedItem</code>[0].</li>\n<li>If <code class=\"language-text\">parsedItem</code>[1][\"<code class=\"language-text\">report-to</code>\"] <a href=\"https://infra.spec.whatwg.org/#map-exists\">exists</a>, then set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-reporting-endpoint\">endpoint</a> to <code class=\"language-text\">parsedItem</code>[1][\"<code class=\"language-text\">report-to</code>\"].</li>\n</ol>\n</li>\n<li>Set <code class=\"language-text\">parsedItem</code> to the result of <a href=\"https://fetch.spec.whatwg.org/#concept-header-list-get-structured-header\">getting a structured field value</a> with <code class=\"language-text\">Cross-Origin-Embedder-Policy-Report-Only</code> and \"<code class=\"language-text\">item</code>\" from <code class=\"language-text\">response</code>'s <a href=\"https://fetch.spec.whatwg.org/#concept-response-header-list\">header list</a>.</li>\n<li>\n<p>If <code class=\"language-text\">parsedItem</code> is non-null and <code class=\"language-text\">parsedItem</code>[0] is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a>:</p>\n<ol>\n<li>Set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-report-only-value\">value</a> to <code class=\"language-text\">parsedItem</code>[0].</li>\n<li>If <code class=\"language-text\">parsedItem</code>[1][\"<code class=\"language-text\">report-to</code>\"] <a href=\"https://infra.spec.whatwg.org/#map-exists\">exists</a>, then set <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-report-only-reporting-endpoint\">endpoint</a> to <code class=\"language-text\">parsedItem</code>[1][\"<code class=\"language-text\">report-to</code>\"].</li>\n</ol>\n</li>\n<li>Return <code class=\"language-text\">policy</code>.</li>\n</ol>\n<h4>7.8.2 Embedder policy checks<a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-checks\"></a></h4>\n<p>To check a navigation response's adherence to its embedder policy given a <a href=\"https://fetch.spec.whatwg.org/#concept-response\">response</a> <code class=\"language-text\">response</code>, a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#browsing-context\">browsing context</a> <code class=\"language-text\">target</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy\">embedder policy</a> <code class=\"language-text\">responsePolicy</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">target</code> is not a <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#child-browsing-context\">child browsing context</a>, then return true.</li>\n<li>Let <code class=\"language-text\">parentPolicy</code> be <code class=\"language-text\">target</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#bc-container-document\">container document</a>'s <a href=\"https://html.spec.whatwg.org/multipage/dom.html#concept-document-policy-container\">policy container</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-embedder-policy\">embedder policy</a>.</li>\n<li>If <code class=\"language-text\">parentPolicy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-report-only-value\">report-only value</a> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a> and <code class=\"language-text\">responsePolicy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> is not, then <a href=\"https://html.spec.whatwg.org/multipage/origin.html#queue-a-cross-origin-embedder-policy-inheritance-violation\">queue a cross-origin embedder policy inheritance violation</a> with <code class=\"language-text\">response</code>, \"<code class=\"language-text\">navigation</code>\", <code class=\"language-text\">parentPolicy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-report-only-reporting-endpoint\">report only reporting endpoint</a>, \"<code class=\"language-text\">reporting</code>\", and <code class=\"language-text\">target</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#bc-container-document\">container document</a>'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#relevant-settings-object\">relevant settings object</a>.</li>\n<li>If <code class=\"language-text\">parentPolicy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> is not <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a> or <code class=\"language-text\">responsePolicy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a>, then return true.</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#queue-a-cross-origin-embedder-policy-inheritance-violation\">Queue a cross-origin embedder policy inheritance violation</a> with <code class=\"language-text\">response</code>, \"<code class=\"language-text\">navigation</code>\", <code class=\"language-text\">parentPolicy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-reporting-endpoint\">reporting endpoint</a>, \"<code class=\"language-text\">enforce</code>\", and <code class=\"language-text\">target</code>'s <a href=\"https://html.spec.whatwg.org/multipage/browsers.html#bc-container-document\">container document</a>'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#relevant-settings-object\">relevant settings object</a>.</li>\n<li>Return false.</li>\n</ol>\n<p>To check a global object's embedder policy given a <code class=\"language-text\">WorkerGlobalScope</code> <code class=\"language-text\">workerGlobalScope</code>, an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\">environment settings object</a> <code class=\"language-text\">owner</code>, and a <a href=\"https://fetch.spec.whatwg.org/#concept-response\">response</a> <code class=\"language-text\">response</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">workerGlobalScope</code> is not a <code class=\"language-text\">DedicatedWorkerGlobalScope</code> object, then return true.</li>\n<li>Let <code class=\"language-text\">policy</code> be <code class=\"language-text\">workerGlobalScope</code>'s <a href=\"https://html.spec.whatwg.org/multipage/workers.html#concept-workerglobalscope-embedder-policy\">embedder policy</a>.</li>\n<li>Let <code class=\"language-text\">ownerPolicy</code> be <code class=\"language-text\">owner</code>'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-policy-container\">policy container</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-embedder-policy\">embedder policy</a>.</li>\n<li>If <code class=\"language-text\">ownerPolicy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-report-only-value\">report-only value</a> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a> and <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> is not, then <a href=\"https://html.spec.whatwg.org/multipage/origin.html#queue-a-cross-origin-embedder-policy-inheritance-violation\">queue a cross-origin embedder policy inheritance violation</a> with <code class=\"language-text\">response</code>, \"<code class=\"language-text\">worker initialization</code>\", <code class=\"language-text\">owner's policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-report-only-reporting-endpoint\">report only reporting endpoint</a>, \"<code class=\"language-text\">reporting</code>\", and <code class=\"language-text\">owner</code>.</li>\n<li>If <code class=\"language-text\">ownerPolicy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> is not <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a> or <code class=\"language-text\">policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-value-2\">value</a> is <a href=\"https://html.spec.whatwg.org/multipage/origin.html#compatible-with-cross-origin-isolation\">compatible with cross-origin isolation</a>, then return true.</li>\n<li><a href=\"https://html.spec.whatwg.org/multipage/origin.html#queue-a-cross-origin-embedder-policy-inheritance-violation\">Queue a cross-origin embedder policy inheritance violation</a> with <code class=\"language-text\">response</code>, \"<code class=\"language-text\">worker initialization</code>\", <code class=\"language-text\">owner's policy</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy-reporting-endpoint\">reporting endpoint</a>, \"<code class=\"language-text\">enforce</code>\", and <code class=\"language-text\">owner</code>.</li>\n<li>Return false.</li>\n</ol>\n<p>To queue a cross-origin embedder policy inheritance violation given a <a href=\"https://fetch.spec.whatwg.org/#concept-response\">response</a> <code class=\"language-text\">response</code>, a string <code class=\"language-text\">type</code>, a string <code class=\"language-text\">endpoint</code>, a string <code class=\"language-text\">disposition</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object\">environment settings object</a> <code class=\"language-text\">settings</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">serialized</code> be the result of <a href=\"https://fetch.spec.whatwg.org/#serialize-a-response-url-for-reporting\">serializing a response URL for reporting</a> with <code class=\"language-text\">response</code>.</li>\n<li>\n<p>Let <code class=\"language-text\">body</code> be a new object containing the following properties:</p>\n<table>\n<thead>\n<tr>\n<th>key</th>\n<th>value</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>type</td>\n<td><code class=\"language-text\">type</code></td>\n</tr>\n<tr>\n<td>blockedURL</td>\n<td><code class=\"language-text\">serialized</code></td>\n</tr>\n<tr>\n<td>disposition</td>\n<td><code class=\"language-text\">disposition</code></td>\n</tr>\n</tbody>\n</table>\n</li>\n<li><a href=\"https://w3c.github.io/reporting/#queue-report\">Queue</a> <code class=\"language-text\">body</code> as the <a href=\"https://html.spec.whatwg.org/multipage/origin.html#coep-report-type\">\"<code class=\"language-text\">coep</code>\" report type</a> for <code class=\"language-text\">endpoint</code> on <code class=\"language-text\">settings</code>.</li>\n</ol>\n<h3>7.9 Policy containers<a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-containers\"></a></h3>\n<p>A policy container is a <a href=\"https://infra.spec.whatwg.org/#struct\">struct</a> containing policies that apply to a <code class=\"language-text\">Document</code>, a <code class=\"language-text\">WorkerGlobalScope</code>, or a <code class=\"language-text\">WorkletGlobalScope</code>. It has the following <a href=\"https://infra.spec.whatwg.org/#struct-item\">items</a>:</p>\n<ul>\n<li>A CSP list, which is a <a href=\"https://w3c.github.io/webappsec-csp/#csp-list\">CSP list</a>. It is initially empty.</li>\n<li>An embedder policy, which is an <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy\">embedder policy</a>. It is initially a new <a href=\"https://html.spec.whatwg.org/multipage/origin.html#embedder-policy\">embedder policy</a>.</li>\n<li>A referrer policy, which is a <a href=\"https://w3c.github.io/webappsec-referrer-policy/#referrer-policy\">referrer policy</a>. It is initially the <a href=\"https://w3c.github.io/webappsec-referrer-policy/#default-referrer-policy\">default referrer policy</a>.</li>\n</ul>\n<p>Move other policies into the policy container.</p>\n<p>To clone a policy container given a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container\">policy container</a> <code class=\"language-text\">policyContainer</code>:</p>\n<ol>\n<li>Let <code class=\"language-text\">clone</code> be a new <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container\">policy container</a>.</li>\n<li><a href=\"https://infra.spec.whatwg.org/#list-iterate\">For each</a> <code class=\"language-text\">policy</code> in <code class=\"language-text\">policyContainer</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-csp-list\">CSP list</a>, <a href=\"https://infra.spec.whatwg.org/#list-append\">append</a> a copy of <code class=\"language-text\">policy</code> into <code class=\"language-text\">clone</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-csp-list\">CSP list</a>.</li>\n<li>Set <code class=\"language-text\">clone</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-embedder-policy\">embedder policy</a> to a copy of <code class=\"language-text\">policyContainer</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-embedder-policy\">embedder policy</a>.</li>\n<li>Set <code class=\"language-text\">clone</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-referrer-policy\">referrer policy</a> to <code class=\"language-text\">policyContainer</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-referrer-policy\">referrer policy</a>.</li>\n<li>Return <code class=\"language-text\">clone</code>.</li>\n</ol>\n<p>To determine whether a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> <code class=\"language-text\">url</code> requires storing the policy container in history:</p>\n<ol>\n<li>If <code class=\"language-text\">url</code>'s <a href=\"https://url.spec.whatwg.org/#concept-url-scheme\">scheme</a> is \"<code class=\"language-text\">blob</code>\", then return false.</li>\n<li>If <code class=\"language-text\">url</code> <a href=\"https://fetch.spec.whatwg.org/#is-local\">is local</a>, then return true.</li>\n<li>Return false.</li>\n</ol>\n<p>To create a policy container from a fetch response given a <a href=\"https://fetch.spec.whatwg.org/#concept-response\">response</a> <code class=\"language-text\">response</code> and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment\">environment</a>-or-null <code class=\"language-text\">environment</code>:</p>\n<ol>\n<li>If <code class=\"language-text\">response</code>'s <a href=\"https://fetch.spec.whatwg.org/#concept-response-url\">URL</a>'s <a href=\"https://url.spec.whatwg.org/#concept-url-scheme\">scheme</a> is \"<code class=\"language-text\">blob</code>\", then return a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#clone-a-policy-container\">clone</a> of <code class=\"language-text\">response</code>'s <a href=\"https://fetch.spec.whatwg.org/#concept-response-url\">URL</a>'s <a href=\"https://url.spec.whatwg.org/#concept-url-blob-entry\">blob URL entry</a>'s <a href=\"https://w3c.github.io/FileAPI/#blob-url-entry-environment\">environment</a>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container\">policy container</a>.</li>\n<li>Let <code class=\"language-text\">result</code> be a new <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container\">policy container</a>.</li>\n<li>Set <code class=\"language-text\">result</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-csp-list\">CSP list</a> to the result of <a href=\"https://w3c.github.io/webappsec-csp/#parse-response-csp\">parsing a response's Content Security Policies</a> given <code class=\"language-text\">response</code>.</li>\n<li>If <code class=\"language-text\">environment</code> is non-null, then set <code class=\"language-text\">result</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-embedder-policy\">embedder policy</a> to the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#obtain-an-embedder-policy\">obtaining an embedder policy</a> given <code class=\"language-text\">response</code> and <code class=\"language-text\">environment</code>. Otherwise, set it to \"<code class=\"language-text\">unsafe-none</code>\".</li>\n<li>Set <code class=\"language-text\">result</code>'s <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container-referrer-policy\">referrer policy</a> to the result of <a href=\"https://w3c.github.io/webappsec-referrer-policy/#parse-referrer-policy-from-header\">parsing the <code class=\"language-text\">Referrer-Policy</code> header</a> given <code class=\"language-text\">response</code>. [[REFERRERPOLICY]](<a href=\"https://html.spec.whatwg.org/multipage/references.html#refsREFERRERPOLICY\">https://html.spec.whatwg.org/multipage/references.html#refsREFERRERPOLICY</a>)</li>\n<li>Return <code class=\"language-text\">result</code>.</li>\n</ol>\n<p>To determine navigation params policy container given a <a href=\"https://url.spec.whatwg.org/#concept-url\">URL</a> <code class=\"language-text\">responseURL</code> and four <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container\">policy container</a>-or-nulls <code class=\"language-text\">historyPolicyContainer</code>, <code class=\"language-text\">initiatorPolicyContainer</code>, <code class=\"language-text\">parentPolicyContainer</code>, and <code class=\"language-text\">responsePolicyContainer</code>:</p>\n<ol>\n<li>\n<p>If <code class=\"language-text\">historyPolicyContainer</code> is not null, then:</p>\n<ol>\n<li>Assert: <code class=\"language-text\">responseURL</code> <a href=\"https://html.spec.whatwg.org/multipage/origin.html#requires-storing-the-policy-container-in-history\">requires storing the policy container in history</a>.</li>\n<li>Return a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#clone-a-policy-container\">clone</a> of <code class=\"language-text\">historyPolicyContainer</code>.</li>\n</ol>\n</li>\n<li>\n<p>If <code class=\"language-text\">responseURL</code> is <code class=\"language-text\">about:srcdoc</code>, then:</p>\n<ol>\n<li>Assert: <code class=\"language-text\">parentPolicyContainer</code> is not null.</li>\n<li>Return a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#clone-a-policy-container\">clone</a> of <code class=\"language-text\">parentPolicyContainer</code>.</li>\n</ol>\n</li>\n<li>If <code class=\"language-text\">responseURL</code> <a href=\"https://fetch.spec.whatwg.org/#is-local\">is local</a> and <code class=\"language-text\">initiatorPolicyContainer</code> is not null, then return a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#clone-a-policy-container\">clone</a> of <code class=\"language-text\">initiatorPolicyContainer</code>.</li>\n<li>If <code class=\"language-text\">responsePolicyContainer</code> is not null, then return <code class=\"language-text\">responsePolicyContainer</code>.</li>\n<li>Return a new <a href=\"https://html.spec.whatwg.org/multipage/origin.html#policy-container\">policy container</a>.</li>\n</ol>\n<p>To initialize a worker global scope's policy container given a <code class=\"language-text\">WorkerGlobalScope</code> <code class=\"language-text\">workerGlobalScope</code>, a <a href=\"https://fetch.spec.whatwg.org/#concept-response\">response</a> <code class=\"language-text\">response</code>, and an <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#environment\">environment</a> <code class=\"language-text\">environment</code>:</p>\n<ol>\n<li>\n<p>If <code class=\"language-text\">workerGlobalScope</code>'s <a href=\"https://html.spec.whatwg.org/multipage/workers.html#concept-workerglobalscope-url\">url</a> <a href=\"https://fetch.spec.whatwg.org/#is-local\">is local</a> but its <a href=\"https://url.spec.whatwg.org/#concept-url-scheme\">scheme</a> is not \"<code class=\"language-text\">blob</code>\":</p>\n<ol>\n<li>Assert: <code class=\"language-text\">workerGlobalScope</code>'s <a href=\"https://html.spec.whatwg.org/multipage/workers.html#concept-WorkerGlobalScope-owner-set\">owner set</a>'s <a href=\"https://infra.spec.whatwg.org/#list-size\">size</a> is 1.</li>\n<li>Set <code class=\"language-text\">workerGlobalScope</code>'s <a href=\"https://html.spec.whatwg.org/multipage/workers.html#concept-workerglobalscope-policy-container\">policy container</a> to a <a href=\"https://html.spec.whatwg.org/multipage/origin.html#clone-a-policy-container\">clone</a> of <code class=\"language-text\">workerGlobalScope</code>'s <a href=\"https://html.spec.whatwg.org/multipage/workers.html#concept-WorkerGlobalScope-owner-set\">owner set</a>[0]'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#relevant-settings-object\">relevant settings object</a>'s <a href=\"https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-policy-container\">policy container</a>.</li>\n</ol>\n</li>\n<li>Otherwise, set <code class=\"language-text\">workerGlobalScope</code>'s <a href=\"https://html.spec.whatwg.org/multipage/workers.html#concept-workerglobalscope-policy-container\">policy container</a> to the result of <a href=\"https://html.spec.whatwg.org/multipage/origin.html#creating-a-policy-container-from-a-fetch-response\">creating a policy container from a fetch response</a> given <code class=\"language-text\">response</code> and <code class=\"language-text\">environment</code>.</li>\n</ol>\n<!--EndFragment-->"},{"url":"/docs/reference/resources/","relativePath":"docs/reference/resources.md","relativeDir":"docs/reference","base":"resources.md","name":"resources","frontmatter":{"title":"Developer Resources","weight":0,"excerpt":"Developer Resources","seo":{"title":"Developer Resources","description":"Developer Resources","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h3>Web Dev Resources</h3>\n<details>\n  \n  <summary>\n    JS RESOURCES\n    \n  </summary>\n  \n  \n- [Worth Reading](#worth-reading)\n- [Other Awesome Lists](#other-awesome-lists)\n    - [JavaScript](#javascript)\n    - [GIT](#git)\n    - [Express](#express)\n    - [Node.js](#nodejs)\n    - [Study Guides](#study-guides)\n    - [React](#react)\n    - [Redux](#redux)\n    - [Redux Middleware](#redux-middleware)\n    - [Command Line](#command-line)\n    - [Atom](#atom)\n    - [VS Code](#vs-code)\n    - [Sublime](#sublime)\n    - [Whiteboard Interviews](#whiteboard-interviews)\n  - [MOAR!](#moar)\n    - [Ansible](#ansible)\n    - [Awesome Lists](#awesome-lists)\n    - [Epic Github Repos](#epic-github-repos)\n    - [Authentication](#authentication)\n    - [Data Science](#data-science)\n    - [Grafana](#grafana)\n    - [Docker](#docker)\n      - [Deploy Stacks to your Swarm: 🐳 ❤️](#deploy-stacks-to-your-swarm--️)\n      - [Awesome Docker Repos](#awesome-docker-repos)\n      - [RaspberryPi ARM Images:](#raspberrypi-arm-images)\n      - [Docker Image Repositories](#docker-image-repositories)\n      - [Docker-Awesome-Lists](#docker-awesome-lists)\n      - [Docker Blogs:](#docker-blogs)\n      - [Docker Storage](#docker-storage)\n      - [OpenFaas:](#openfaas)\n      - [Prometheus / Grafana on Swarm:](#prometheus--grafana-on-swarm)\n    - [Logging / Kibana / Beats](#logging--kibana--beats)\n    - [Libraries](#libraries)\n    - [Frameworks](#frameworks-2)\n    - [Continious Integration:](#continious-integration)\n      - [Circle-CI](#circle-ci)\n      - [Concourse](#concourse)\n      - [Jenkins](#jenkins)\n      - [SwarmCi](#swarmci)\n      - [Travis-CI](#travis-ci)\n      - [LambCI](#lambci)\n    - [DynamoDB](#dynamodb)\n      - [DynamoDB Docs](#dynamodb-docs)\n      - [DynamoDB Best Practices](#dynamodb-best-practices)\n      - [DynamoDB General Info](#dynamodb-general-info)\n    - [Elasticsearch](#elasticsearch)\n      - [Elasticsearch Documentation](#elasticsearch-documentation)\n      - [Elasticsearch Cheetsheets:](#elasticsearch-cheetsheets)\n      - [Elasticsearch Blogs](#elasticsearch-blogs)\n      - [Elasticsearch Tools](#elasticsearch-tools)\n    - [Environment Setups:](#environment-setups)\n    - [Knowledge Base](#knowledge-base)\n    - [KB HTTPS](#kb-https)\n    - [Kubernetes](#kubernetes)\n    - [Kubernetes Storage](#kubernetes-storage)\n    - [Golang](#golang)\n    - [Great Blogs](#great-blogs)\n    - [Linuxkit:](#linuxkit)\n    - [Logging Stacks](#logging-stacks)\n    - [Machine Learning:](#machine-learning-1)\n    - [Metrics:](#metrics)\n    - [MongoDB:](#mongodb)\n    - [Monitoring](#monitoring)\n    - [Monitoring and Alerting](#monitoring-and-alerting)\n    - [Monitoring as Statuspages](#monitoring-as-statuspages)\n    - [Programming](#programming)\n      - [Golang:](#golang-1)\n      - [Java:](#java)\n      - [Python](#python)\n      - [Ruby:](#ruby)\n      - [Ruby on Rails:](#ruby-on-rails)\n    - [Queues](#queues)\n    - [Sysadmin References:](#sysadmin-references)\n    - [Self Hosting](#self-hosting)\n      - [Email Server Setups](#email-server-setups)\n      - [Mailscanner Server Setups](#mailscanner-server-setups)\n      - [Financial](#financial)\n      - [Self Hosting Frameworks:](#self-hosting-frameworks)\n    - [Serverless](#serverless)\n    - [VPN:](#vpn)\n      - [VPN-Howto:](#vpn-howto)\n    - [Website Templates](#website-templates)\n      - [Resume Templates](#resume-templates)\n    - [Web Frameworks](#web-frameworks)\n      - [Python Flask:](#python-flask)\n    - [If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content:](#if-you-found-this-guide-helpful-feel-free-to-checkout-my-githubgists-where-i-host-similar-content)\n    - [Ada](#ada)\n    - [Android](#android)\n    - [Bash](#bash)\n    - [C](#c)\n    - [C Sharp](#c-sharp)\n    - [Clojure](#clojure)\n    - [Cloud Computing](#cloud-computing)\n    - [CoffeeScript](#coffeescript)\n    - [Dart](#dart)\n    - [Erlang](#erlang)\n    - [Git](#git-1)\n    - [GLSL](#glsl)\n    - [Go](#go)\n    - [Haskell](#haskell)\n    - [HTML / CSS](#html--css)\n      - [Bootstrap](#bootstrap)\n    - [Java](#java-1)\n    - [JavaScript](#javascript-1)\n      - [Angular.js](#angularjs)\n      - [jQuery](#jquery)\n      - [React](#react-1)\n    - [Kotlin](#kotlin)\n    - [Language Agnostic](#language-agnostic)\n      - [Operating systems](#operating-systems)\n    - [LaTeX](#latex)\n    - [Lisp](#lisp)\n    - [MATLAB](#matlab)\n    - [Node](#node)\n    - [NoSQL](#nosql)\n    - [Objective-C](#objective-c)\n    - [Ocaml](#ocaml)\n    - [PHP](#php)\n    - [PostgreSQL](#postgresql)\n    - [Python](#python-1)\n    - [Ruby](#ruby-1)\n    - [Rust](#rust)\n    - [Scala](#scala)\n    - [Selenium](#selenium)\n    - [SQL](#sql)\n    - [Vim](#vim)\n<hr>\n<h2>Package Managers</h2>\n<p><em>Host the JavaScript libraries and provide tools for fetching and packaging them.</em></p>\n<ul>\n<li><a href=\"https://www.npmjs.com/\">npm</a> - npm is the package manager for JavaScript.</li>\n<li><a href=\"https://github.com/bower/bower\">Bower</a> - A package manager for the web.</li>\n<li><a href=\"https://github.com/componentjs/component\">component</a> - Client package management for building better web applications.</li>\n<li><a href=\"https://github.com/spmjs/spm\">spm</a> - Brand new static package manager.</li>\n<li><a href=\"https://github.com/caolan/jam\">jam</a> - A package manager using a browser-focused and RequireJS compatible repository.</li>\n<li><a href=\"https://github.com/jspm/jspm-cli\">jspm</a> - Frictionless browser package management.</li>\n<li><a href=\"https://github.com/ender-js/Ender\">Ender</a> - The no-library library.</li>\n<li><a href=\"https://github.com/volojs/volo\">volo</a> - Create front end projects from templates, add dependencies, and automate the resulting projects.</li>\n<li><a href=\"https://github.com/duojs/duo\">Duo</a> - Next-generation package manager that blends the best ideas from Component, Browserify and Go to make organizing and writing front-end code quick and painless.</li>\n<li><a href=\"https://yarnpkg.com/\">yarn</a> - Fast, reliable, and secure dependency management.</li>\n</ul>\n<h2>Loaders</h2>\n<p><em>Module or loading system for JavaScript.</em></p>\n<ul>\n<li><a href=\"https://github.com/requirejs/requirejs\">RequireJS</a> - A file and module loader for JavaScript.</li>\n<li><a href=\"https://github.com/substack/node-browserify\">browserify</a> - Browser-side require() the node.js way.</li>\n<li><a href=\"https://github.com/seajs/seajs\">SeaJS</a> - A Module Loader for the Web.</li>\n<li><a href=\"https://github.com/headjs/headjs\">HeadJS</a> - The only script in your HEAD.</li>\n<li><a href=\"https://github.com/cujojs/curl\">curl</a> - A small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.</li>\n<li><a href=\"https://github.com/rgrove/lazyload/\">lazyload</a> - Tiny, dependency-free async JavaScript and CSS loader.</li>\n<li><a href=\"https://github.com/ded/script.js\">script.js</a> - Asynchronous JavaScript loader and dependency manager.</li>\n<li><a href=\"https://github.com/systemjs/systemjs\">systemjs</a> - AMD, CJS &#x26; ES6 spec-compliant module loader.</li>\n<li><a href=\"https://github.com/yanhaijing/lodjs\">LodJS</a> - Module loader based on AMD.</li>\n<li><a href=\"https://github.com/ecomfe/esl\">ESL</a> - Module loader browser first, support lazy define and AMD.</li>\n<li><a href=\"https://github.com/lrsjng/modulejs\">modulejs</a> - Lightweight JavaScript module system.</li>\n</ul>\n<h2>Bundlers</h2>\n<ul>\n<li><a href=\"https://github.com/substack/node-browserify\">browserify</a> - Browserify lets you require('modules') in the browser by bundling up all of your dependencies.</li>\n<li><a href=\"https://github.com/webpack/webpack\">webpack</a> - Packs CommonJs/AMD modules for the browser.</li>\n<li><a href=\"https://github.com/rollup/rollup\">Rollup</a> - Next-generation ES6 module bundler.</li>\n<li><a href=\"https://github.com/brunch/brunch\">Brunch</a> - Fast front-end web app build tool with simple declarative config.</li>\n<li><a href=\"https://github.com/parcel-bundler/parcel\">Parcel</a> - Blazing fast, zero configuration web application bundler.</li>\n</ul>\n<h2>Testing Frameworks</h2>\n<h3>Frameworks</h3>\n<ul>\n<li><a href=\"https://github.com/mochajs/mocha\">mocha</a> - Simple, flexible, fun JavaScript test framework for node.js &#x26; the browser.</li>\n<li><a href=\"https://github.com/jasmine/jasmine\">jasmine</a> - DOM-less simple JavaScript testing framework.</li>\n<li><a href=\"https://github.com/jquery/qunit\">qunit</a> - An easy-to-use JavaScript Unit Testing framework.</li>\n<li><a href=\"https://github.com/facebook/jest\">jest</a> - Painless JavaScript Unit Testing.</li>\n<li><a href=\"https://github.com/azer/prova\">prova</a> - Node &#x26; Browser test runner based on Tape and Browserify</li>\n<li><a href=\"https://github.com/dalekjs/dalek\">DalekJS</a> - Automated cross browser functional testing with JavaScript</li>\n<li><a href=\"https://github.com/angular/protractor\">Protractor</a> - Protractor is an end-to-end test framework for AngularJS applications.</li>\n<li><a href=\"https://github.com/substack/tape\">tape</a> - Tap-producing test harness for node and browsers.</li>\n<li><a href=\"https://github.com/DevExpress/testcafe\">TestCafe</a> - Automated browser testing for the modern web development stack.</li>\n<li><a href=\"https://github.com/avajs/ava\">ava</a> - 🚀 Futuristic JavaScript test runner</li>\n<li><a href=\"https://www.cypress.io/\">Cypress</a> - Complete end-to-end testing framework for anything that runs in a browser and beyond.</li>\n</ul>\n<h3>Assertion</h3>\n<ul>\n<li><a href=\"https://github.com/chaijs/chai\">chai</a> - BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.</li>\n<li><a href=\"http://airbnb.io/enzyme/index.html\">Enzyme</a> - Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components' output.</li>\n<li><a href=\"https://github.com/kentcdodds/react-testing-library\">react testing library</a> - Simple and complete React DOM testing utilities that encourage good testing practices.</li>\n<li><a href=\"https://github.com/sinonjs/sinon\">Sinon.JS</a> - Test spies, stubs, and mocks for JavaScript.</li>\n<li><a href=\"https://github.com/Automattic/expect.js\">expect.js</a> - Minimalistic BDD-style assertions for Node.JS and the browser.</li>\n<li><a href=\"https://github.com/thlorenz/proxyquire\">proxyquire</a> - Stub nodejs's require.</li>\n</ul>\n<h3>Coverage</h3>\n<ul>\n<li><a href=\"https://github.com/gotwarlost/istanbul\">istanbul</a> - Yet another JS code coverage tool.</li>\n<li><a href=\"https://github.com/alex-seville/blanket\">blanket</a> - A simple code coverage library for JavaScript. Designed to be easy to install and use, for both browser and nodejs.</li>\n<li><a href=\"https://github.com/tntim96/JSCover\">JSCover</a> - JSCover is a tool that measures code coverage for JavaScript programs.</li>\n</ul>\n<h3>Runner</h3>\n<ul>\n<li><a href=\"https://github.com/ariya/phantomjs\">phantomjs</a> - Scriptable Headless WebKit.</li>\n<li><a href=\"https://github.com/laurentj/slimerjs\">slimerjs</a> - A PhantomJS-like tool running Gecko.</li>\n<li><a href=\"https://github.com/casperjs/casperjs\">casperjs</a> - Navigation scripting &#x26; testing utility for PhantomJS and SlimerJS.</li>\n<li><a href=\"https://github.com/assaf/zombie\">zombie</a> - Insanely fast, full-stack, headless browser testing using node.js.</li>\n<li><a href=\"https://github.com/totorojs/totoro\">totoro</a> - A simple and stable cross-browser testing tool.</li>\n<li><a href=\"https://github.com/karma-runner/karma\">karma</a> - Spectacular Test Runner for JavaScript.</li>\n<li><a href=\"https://github.com/nightwatchjs/nightwatch\">nightwatch</a> - UI automated testing framework based on node.js and selenium webdriver.</li>\n<li><a href=\"https://github.com/theintern/intern\">intern</a> - A next-generation code testing stack for JavaScript.</li>\n<li><a href=\"http://www.yolpo.com\">yolpo</a> - A statement-by-statement JavaScript interpreter in the browser.</li>\n<li><a href=\"https://github.com/GoogleChrome/puppeteer\">puppeteer</a> - Headless Chrome Node.js API by official Google Chrome team.</li>\n<li><a href=\"https://github.com/webdriverio/webdriverio\">webdriverio</a> - Next-gen WebDriver test automation framework for Node.js.</li>\n</ul>\n<h2>QA Tools</h2>\n<ul>\n<li><a href=\"https://github.com/prettier/prettier\">prettier</a> - Prettier is an opinionated code formatter.</li>\n<li><a href=\"https://github.com/jshint/jshint/\">JSHint</a> - JSHint is a tool that helps to detect errors and potential problems in your JavaScript code.</li>\n<li><a href=\"https://github.com/jscs-dev/node-jscs\">jscs</a> - JavaScript Code Style checker.</li>\n<li><a href=\"https://github.com/rdio/jsfmt\">jsfmt</a> - For formatting, searching, and rewriting JavaScript.</li>\n<li><a href=\"https://github.com/danielstjules/jsinspect\">jsinspect</a> - Detect copy-pasted and structurally similar code.</li>\n<li><a href=\"https://github.com/danielstjules/buddy.js\">buddy.js</a> - Magic number detection for JavaScript.</li>\n<li><a href=\"https://github.com/eslint/eslint\">ESLint</a> - A fully pluggable tool for identifying and reporting on patterns in JavaScript.</li>\n<li><a href=\"https://github.com/douglascrockford/JSLint\">JSLint</a> - High-standards, strict &#x26; opinionated code quality tool, aiming to keep only good parts of the language.</li>\n<li><a href=\"https://github.com/feross/standard\">JavaScript Standard Style</a> - Opinionated, no-configuration style guide, style checker, and formatter</li>\n<li><a href=\"https://github.com/kentcdodds/preval.macro\">Pre-evaluate code at buildtime</a> - Pre-evaluate your front end javascript code at build-time</li>\n</ul>\n<h2>MVC Frameworks and Libraries</h2>\n<ul>\n<li><a href=\"https://github.com/angular/angular.js\">angular.js</a> - HTML enhanced for web apps.</li>\n<li><a href=\"http://aurelia.io\">aurelia</a> - A JavaScript client framework for mobile, desktop and web.</li>\n<li><a href=\"https://github.com/jashkenas/backbone\">backbone</a> - Give your JS App some Backbone with Models, Views, Collections, and Events.</li>\n<li><a href=\"https://github.com/emberjs/ember.js\">ember.js</a> - A JavaScript framework for creating ambitious web applications.</li>\n<li><a href=\"https://github.com/meteor/meteor\">meteor</a> - An ultra-simple, database-everywhere, data-on-the-wire, pure-javascript web framework.</li>\n<li><a href=\"https://github.com/ractivejs/ractive\">ractive</a> - Next-generation DOM manipulation.</li>\n<li><a href=\"https://github.com/vuejs/vue\">vue</a> - Intuitive, fast &#x26; composable MVVM for building interactive interfaces.</li>\n<li><a href=\"https://github.com/sveltejs/svelte\">svelte</a> - Svelte is a new way to build web applications. It's a compiler that takes your declarative components and converts them into efficient JavaScript that surgically updates the DOM.</li>\n<li><a href=\"https://github.com/knockout/knockout\">knockout</a> - Knockout makes it easier to create rich, responsive UIs with JavaScript.</li>\n<li><a href=\"https://github.com/spine/spine\">spine</a> - Lightweight MVC library for building JavaScript applications.</li>\n<li><a href=\"https://github.com/techlayer/espresso.js\">espresso.js</a> - A minimal JavaScript library for crafting user interfaces.</li>\n<li><a href=\"https://github.com/canjs/canjs\">canjs</a> - Can do JS, better, faster, easier.</li>\n<li><a href=\"https://facebook.github.io/react/\">react</a> - A library for building user interfaces. It's declarative, efficient, and extremely flexible. Works with a Virtual DOM.</li>\n<li><a href=\"https://github.com/hyperapp/hyperapp\">hyperapp</a> - 1kb JavaScript library for building frontend applications.</li>\n<li><a href=\"https://github.com/developit/preact\">preact</a> - Fast 3kb React alternative with the same ES6 API. Components &#x26; Virtual DOM.</li>\n<li><a href=\"https://github.com/NativeScript/NativeScript\">nativescript</a> - Build truly native cross-platform iOS and Android apps with JavaScript.</li>\n<li><a href=\"https://github.com/facebook/react-native\">react-native</a> - A framework for building native apps with React.</li>\n<li><a href=\"https://github.com/riot/riot\">riot</a> - React-like library, but with very small size.</li>\n<li><a href=\"https://github.com/walmartlabs/thorax\">thorax</a> - Strengthening your Backbone.</li>\n<li><a href=\"https://github.com/chaplinjs/chaplin\">chaplin</a> - An architecture for JavaScript applications using the Backbone.js library.</li>\n<li><a href=\"https://github.com/marionettejs/backbone.marionette\">marionette</a> - A composite application library for Backbone.js that aims to simplify the construction of large scale JavaScript applications.</li>\n<li><a href=\"https://github.com/ripplejs/ripple\">ripple</a> - A tiny foundation for building reactive views.</li>\n<li><a href=\"https://github.com/mikeric/rivets\">rivets</a> - Lightweight and powerful data binding + templating solution.</li>\n<li>\n<p><a href=\"https://github.com/derbyjs/derby\">derby</a> - MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers.</p>\n<ul>\n<li><a href=\"https://github.com/russll/awesome-derby\">derby-awesome</a> - A collection of awesome derby components</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/gwendall/way.js\">way.js</a> - Simple, lightweight, persistent two-way databinding.</li>\n<li><a href=\"https://github.com/lhorie/mithril.js\">mithril.js</a> - Mithril is a client-side MVC framework (Light-weight, Robust, Fast).</li>\n<li><a href=\"https://github.com/astoilkov/jsblocks\">jsblocks</a> - jsblocks is better MV-ish framework.</li>\n<li><a href=\"http://www.lava-framework.com/\">LiquidLava</a> - Transparent MVC framework for building user interfaces.</li>\n<li><a href=\"https://github.com/feathersjs/feathers\">feathers</a> - A minimalist real-time JavaScript framework for tomorrow's apps.</li>\n<li><a href=\"https://github.com/Wildhoney/Keo\">Keo</a> - Functional stateless React components with Shadow DOM support.</li>\n<li><a href=\"https://github.com/emadalam/atvjs\">atvjs</a> - Blazing fast Apple TV application development using pure JavaScript.</li>\n</ul>\n<h2>Node-Powered CMS Frameworks</h2>\n<ul>\n<li><a href=\"https://github.com/keystonejs/keystone\">KeystoneJS</a> - powerful CMS and web app framework.</li>\n<li><a href=\"https://github.com/reactioncommerce/reaction\">Reaction Commerce</a> - reactive CMS, real-time architecture and design.</li>\n<li><a href=\"https://github.com/tryghost/Ghost\">Ghost</a> - simple, powerful publishing platform.</li>\n<li><a href=\"https://github.com/punkave/apostrophe\">Apostrophe</a> - CMS with content editing and essential services.</li>\n<li><a href=\"https://github.com/wejs/we/\">We.js</a> - framework for real time apps, sites or blogs.</li>\n<li><a href=\"https://github.com/inventures/hatchjs\">Hatch.js</a> - CMS platform with social features.</li>\n<li><a href=\"https://github.com/xtremespb/taracotjs-generator/\">TaracotJS</a> - fast and minimalist CMS based on Node.js.</li>\n<li><a href=\"https://github.com/nodize/nodizecms\">Nodizecms</a> - CMS for CoffeeScript lovers.</li>\n<li><a href=\"https://github.com/jcoppieters/cody\">Cody</a> - CMS with WSYWYG editor.</li>\n<li><a href=\"https://github.com/pencilblue/pencilblue/\">PencilBlue</a> - CMS and blogging platform.</li>\n<li><a href=\"https://github.com/strapi/strapi\">Strapi</a> - Open source Node.js Headless CMS to easily build customisable APIs.</li>\n<li><a href=\"https://github.com/fiction-com/factor\">Factor</a> - The Javascript CMS</li>\n</ul>\n<h2>Templating Engines</h2>\n<p><em>Templating engines allow you to perform string interpolation.</em></p>\n<ul>\n<li><a href=\"https://github.com/janl/mustache.js\">mustache.js</a> - Minimal templating with {{mustaches}} in JavaScript.</li>\n<li><a href=\"https://github.com/wycats/handlebars.js/\">handlebars.js</a> - An extension to the Mustache templating language.</li>\n<li><a href=\"https://mozilla.github.io/nunjucks/\">nunjucks</a> - A rich and powerful templating language for JavaScript from Mozilla.</li>\n<li><a href=\"https://github.com/twitter/hogan.js\">hogan.js</a> - A compiler for the Mustache templating language.</li>\n<li><a href=\"https://github.com/olado/doT\">doT</a> - The fastest + concise JavaScript template engine for nodejs and browsers.</li>\n<li><a href=\"https://github.com/linkedin/dustjs/\">dustjs</a> - Asynchronous templates for the browser and node.js.</li>\n<li><a href=\"https://github.com/sstephenson/eco/\">eco</a> - Embedded CoffeeScript templates.</li>\n<li><a href=\"https://github.com/blueimp/JavaScript-Templates\">JavaScript-Templates</a> - &#x3C; 1KB lightweight, fast &#x26; powerful JavaScript templating engine with zero dependencies.</li>\n<li><a href=\"https://github.com/jasonmoo/t.js\">t.js</a> - A tiny JavaScript templating framework in ~400 bytes gzipped.</li>\n<li><a href=\"https://github.com/pugjs/pug\">Pug</a> - Robust, elegant, feature rich template engine for nodejs. (formerly known as Jade)</li>\n<li><a href=\"https://github.com/mde/ejs\">EJS</a> - Effective JavaScript templating.</li>\n<li><a href=\"https://github.com/xtemplate/xtemplate\">xtemplate</a> - eXtensible Template Engine lib for node and the browser</li>\n<li><a href=\"https://github.com/marko-js/marko\">marko</a> - A fast, lightweight, HTML-based templating engine for Node.js and the browser with async, streaming, custom tags and CommonJS modules as compiled output.</li>\n<li><a href=\"http://paularmstrong.github.io/swig/\">swig</a> - A simple, powerful, and extendable Node.js and browser-based JavaScript template engine.</li>\n</ul>\n<h2>Articles and Posts</h2>\n<ul>\n<li><a href=\"https://medium.com/@pedropolisenso/o-javasscript-que-voc%C3%AA-deveria-conhecer-b70e94d1d706\">The JavaScript that you should know</a> - Article about concepts of JavaScript Functional.</li>\n<li><a href=\"https://blog.sessionstack.com/tagged/tutorial\">How JavaScript works</a> - A series of articles about the building blocks of JavaScript.</li>\n</ul>\n<h2>Data Visualization</h2>\n<p><em>Data visualization tools for the web.</em></p>\n<ul>\n<li>\n<p><a href=\"https://github.com/d3/d3\">d3</a> - A JavaScript visualization library for HTML and SVG.</p>\n<ul>\n<li><a href=\"https://github.com/mozilla/metrics-graphics\">metrics-graphics</a> - A library optimized for concise, principled data graphics and layouts.</li>\n</ul>\n</li>\n<li><a href=\"https://github.com/mrdoob/three.js\">three.js</a> - JavaScript 3D library.</li>\n<li><a href=\"https://github.com/chartjs/Chart.js\">Chart.js</a> - Simple HTML5 Charts using the &#x3C;canvas> tag.</li>\n<li><a href=\"https://github.com/paperjs/paper.js\">paper.js</a> - The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas.</li>\n<li><a href=\"https://github.com/kangax/fabric.js\">fabric.js</a> - JavaScript Canvas Library, SVG-to-Canvas (&#x26; canvas-to-SVG) Parser.</li>\n<li><a href=\"https://github.com/benpickles/peity\">peity</a> - Progressive <svg> bar, line and pie charts.</li>\n<li><a href=\"https://github.com/DmitryBaranovskiy/raphael\">raphael</a> - JavaScript Vector Library.</li>\n<li><a href=\"https://github.com/ecomfe/echarts\">echarts</a> - Enterprise Charts.</li>\n<li><a href=\"https://github.com/almende/vis\">vis</a> - Dynamic, browser-based visualization library.</li>\n<li><a href=\"https://github.com/jonobr1/two.js\">two.js</a> - A renderer agnostic two-dimensional drawing api for the web.</li>\n<li><a href=\"https://github.com/DmitryBaranovskiy/g.raphael\">g.raphael</a> - Charts for Raphaël.</li>\n<li><a href=\"https://github.com/jacomyal/sigma.js\">sigma.js</a> - A JavaScript library dedicated to graph drawing.</li>\n<li><a href=\"https://github.com/samizdatco/arbor\">arbor</a> - A graph visualization library using web workers and jQuery.</li>\n<li><a href=\"https://github.com/square/cubism\">cubism</a> - A D3 plugin for visualizing time series.</li>\n<li><a href=\"https://github.com/dc-js/dc.js\">dc.js</a> - Multi-Dimensional charting built to work natively with crossfilter rendered with d3.js</li>\n<li><a href=\"https://github.com/trifacta/vega\">vega</a> - A visualization grammar.</li>\n<li><a href=\"http://processingjs.org/\">processing.js</a> - Processing.js makes your data visualizations work using web standards and without any plug-ins.</li>\n<li><a href=\"https://github.com/HumbleSoftware/envisionjs\">envisionjs</a> - Dynamic HTML5 visualization.</li>\n<li><a href=\"https://github.com/shutterstock/rickshaw\">rickshaw</a> - JavaScript toolkit for creating interactive real-time graphs.</li>\n<li><a href=\"https://github.com/flot/flot\">flot</a> - Attractive JavaScript charts for jQuery.</li>\n<li><a href=\"https://github.com/morrisjs/morris.js\">morris.js</a> - Pretty time-series line graphs.</li>\n<li><a href=\"https://github.com/novus/nvd3\">nvd3</a> - Build re-usable charts and chart components for d3.js.</li>\n<li><a href=\"https://github.com/wout/svg.js\">svg.js</a> - A lightweight library for manipulating and animating SVG.</li>\n<li><a href=\"https://github.com/pa7/heatmap.js\">heatmap.js</a> - JavaScript Library for HTML5 canvas based heatmaps.</li>\n<li><a href=\"https://github.com/gwatts/jquery.sparkline\">jquery.sparkline</a> - A plugin for the jQuery JavaScript library to generate small sparkline charts directly in the browser.</li>\n<li><a href=\"https://github.com/qrohlf/trianglify\">trianglify</a> - Low poly style background generator with d3.js.</li>\n<li><a href=\"https://github.com/jasondavies/d3-cloud\">d3-cloud</a> - Create word clouds in JavaScript.</li>\n<li><a href=\"https://github.com/heavysixer/d4\">d4</a> - A friendly reusable charts DSL for D3.</li>\n<li><a href=\"http://dimplejs.org\">dimple.js</a> - Easy charts for business analytics powered by d3.</li>\n<li><a href=\"https://github.com/gionkunz/chartist-js\">chartist-js</a> - Simple responsive charts.</li>\n<li><a href=\"https://github.com/epochjs/epoch\">epoch</a> - A general purpose real-time charting library.</li>\n<li><a href=\"https://github.com/c3js/c3\">c3</a> - D3-based reusable chart library.</li>\n<li><a href=\"https://github.com/BabylonJS/Babylon.js\">BabylonJS</a> - A framework for building 3D games with HTML 5 and WebGL.</li>\n<li><a href=\"https://github.com/recharts/recharts\">recharts</a> - Redefined chart library built with React and D3.</li>\n<li><a href=\"https://www.graphicsjs.org\">GraphicsJS</a> - A lightweight JavaScript graphics library with the intuitive API, based on SVG/VML technology.</li>\n<li><a href=\"https://github.com/jgraph/mxgraph\">mxGraph</a> - Diagramming library that enables interactive graph and charting applications to be quickly created that run natively in any major browser that is supported by its vendor.</li>\n</ul>\n<p>There're also some great commercial libraries, like <a href=\"https://www.amcharts.com/\">amchart</a>, <a href=\"http://www.anychart.com\">anychart</a>, <a href=\"https://plot.ly/\">plotly</a>, and <a href=\"http://www.highcharts.com/\">highchart</a>.</p>\n<h2>Timeline</h2>\n<ul>\n<li><a href=\"https://github.com/NUKnightLab/TimelineJS3\">TimelineJS v3</a> - A Storytelling Timeline built in JavaScript.</li>\n<li><a href=\"https://github.com/sbstjn/timesheet.js\">timesheet.js</a> - JavaScript library for simple HTML5 &#x26; CSS3 time sheets.</li>\n</ul>\n<h2>Spreadsheet</h2>\n<ul>\n<li><a href=\"https://github.com/handsontable/handsontable\">HANDSONTABLE</a> - Handsontable is a JavaScript/HTML5 Spreadsheet Library for Developers</li>\n</ul>\n<h2>Editors</h2>\n<ul>\n<li><a href=\"https://github.com/ajaxorg/ace\">ace</a> - Ace (Ajax.org Cloud9 Editor).</li>\n<li><a href=\"https://github.com/codemirror/CodeMirror\">CodeMirror</a> - In-browser code editor.</li>\n<li><a href=\"https://github.com/ariya/esprima\">esprima</a> - ECMAScript parsing infrastructure for multipurpose analysis.</li>\n<li><a href=\"https://github.com/quilljs/quill\">quill</a> - A cross browser rich text editor with an API.</li>\n<li><a href=\"https://github.com/yabwe/medium-editor\">medium-editor</a> - Medium.com WYSIWYG editor clone.</li>\n<li><a href=\"https://github.com/sofish/pen\">pen</a> - enjoy live editing (+markdown).</li>\n<li><a href=\"https://github.com/raphaelcruzeiro/jquery-notebook\">jquery-notebook</a> - A simple, clean and elegant text editor. Inspired by the awesomeness of Medium.</li>\n<li><a href=\"https://github.com/mindmup/bootstrap-wysiwyg\">bootstrap-wysiwyg</a> - Tiny bootstrap-compatible WYSIWYG rich text editor.</li>\n<li><a href=\"https://github.com/ckeditor/ckeditor-releases\">ckeditor-releases</a> - The best web text editor for everyone.</li>\n<li><a href=\"https://github.com/lepture/editor\">editor</a> - A markdown editor. still on development.</li>\n<li><a href=\"https://github.com/OscarGodson/EpicEditor\">EpicEditor</a> - An embeddable JavaScript Markdown editor with split fullscreen editing, live previewing, automatic draft saving, offline support, and more.</li>\n<li><a href=\"https://github.com/josdejong/jsoneditor\">jsoneditor</a> - A web-based tool to view, edit and format JSON.</li>\n<li><a href=\"https://github.com/coolwanglu/vim.js\">vim.js</a> - JavaScript port of Vim with a persistent <code class=\"language-text\">~/.vimrc</code>.</li>\n<li><a href=\"https://github.com/neilj/Squire\">Squire</a> - HTML5 rich text editor.</li>\n<li><a href=\"https://github.com/tinymce/tinymce\">TinyMCE</a> - The JavaScript Rich Text editor.</li>\n<li><a href=\"https://github.com/basecamp/trix\">trix</a> - A rich text editor for everyday writing. By Basecamp.</li>\n<li><a href=\"https://github.com/Alex-D/Trumbowyg\">Trumbowyg</a> - A lightweight and amazing WYSIWYG JavaScript editor.</li>\n<li><a href=\"https://github.com/facebook/draft-js\">Draft.js</a> - A React framework for building text editors.</li>\n<li><a href=\"https://github.com/jhollingworth/bootstrap-wysihtml5\">bootstrap-wysihtml5</a> - Simple, beautiful wysiwyg editor</li>\n<li><a href=\"https://github.com/xing/wysihtml5\">wysihtml5</a> - Open source rich text editor based on HTML5 and the progressive-enhancement approach. Uses a sophisticated security concept and aims to generate fully valid HTML5 markup by preventing unmaintainable tag soups and inline styles.</li>\n<li><a href=\"https://github.com/PANmedia/raptor-editor\">raptor-editor</a> - Raptor, an HTML5 WYSIWYG content editor!</li>\n<li><a href=\"https://github.com/kenshin54/popline\">popline</a> - Popline is an HTML5 Rich-Text-Editor Toolbar.</li>\n<li><a href=\"https://github.com/summernote/summernote\">Summernote</a> - Super simple WYSIWYG editor.</li>\n</ul>\n<h2>Documentation</h2>\n<ul>\n<li><a href=\"http://devdocs.io/\">DevDocs</a> is an all-in-one API documentation reader with a fast, organized, and consistent interface.</li>\n<li><a href=\"http://www.dexy.it/\">dexy</a> is a free-form literate documentation tool for writing any kind of technical document incorporating code.</li>\n<li><a href=\"http://jashkenas.github.io/docco/\">docco</a> is a quick-and-dirty, hundred-line-long, literate-programming-style documentation generator.</li>\n<li><a href=\"http://jacobrask.github.io/styledocco/\">styledocco</a> generates documentation and style guide documents from your stylesheets.</li>\n<li><a href=\"https://github.com/rtomayko/ronn\">Ronn</a> builds manuals. It converts simple, human readable textfiles to roff for terminal display, and also to HTML for the web.</li>\n<li><a href=\"https://github.com/tj/dox\">dox</a> is a JavaScript documentation generator written with node. Dox no longer generates an opinionated structure or style for your docs, it simply gives you a JSON representation, allowing you to use markdown and JSDoc-style tags.</li>\n<li><a href=\"https://github.com/sutoiku/jsdox\">jsdox</a> is a JSDoc3 to Markdown documentation generator.</li>\n<li><a href=\"https://github.com/esdoc/esdoc\">ESDoc</a> is a good documentation generator for JavaScript.</li>\n<li><a href=\"http://yui.github.io/yuidoc/\">YUIDoc</a> is a Node.js application that generates API documentation from comments in source, using a syntax similar to tools like Javadoc and Doxygen.</li>\n<li><a href=\"http://doug-martin.github.io/coddoc/\">coddoc</a> is a jsdoc parsing library. Coddoc is different in that it is easily extensible by allowing users to add tag and code parsers through the use of coddoc.addTagHandler and coddoc.addCodeHandler. coddoc also parses source code to be used in APIs.</li>\n<li><a href=\"http://www.sphinx-doc.org/\">sphinx</a> a tool that makes it easy to create intelligent and beautiful documentation</li>\n<li><a href=\"http://usejsdoc.org/\">Using JSDoc</a></li>\n<li><a href=\"http://beautifuldocs.com/\">Beautiful docs</a> is a documentation viewer based on markdown files.</li>\n<li><a href=\"http://documentation.js.org\">documentation.js</a> - API documentation generator with support for ES2015+ and flow annotation.</li>\n<li><a href=\"https://github.com/senchalabs/jsduck\">jsduck</a> - API documentation generator made for Sencha JavaScript frameworks, but can be used for other frameworks too.</li>\n<li><a href=\"https://github.com/Bogdan-Lyashenko/codecrumbs\">codecrumbs</a> is a visual tool for learning and documenting a codebase by putting breadcrumbs in source code.</li>\n</ul>\n<h2>Files</h2>\n<p><em>Libraries for working with files.</em></p>\n<ul>\n<li><a href=\"https://github.com/mholt/PapaParse\">Papa Parse</a> - A powerful CSV library that supports parsing CSV files/strings and also exporting to CSV.</li>\n<li><a href=\"https://github.com/jDataView/jBinary\">jBinary</a> - High-level I/O (loading, parsing, manipulating, serializing, saving) for binary files with declarative syntax for describing file types and data structures.</li>\n<li><a href=\"https://github.com/rtfpessoa/diff2html\">diff2html</a> - Git diff output parser and pretty HTML generator.</li>\n<li><a href=\"https://github.com/MrRio/jsPDF\">jsPDF</a> - JavaScript PDF generation.</li>\n<li><a href=\"https://github.com/mozilla/pdf.js\">PDF.js</a> - PDF Reader in JavaScript.</li>\n</ul>\n<h2>Functional Programming</h2>\n<p><em>Functional programming libraries to extend JavaScript's capabilities.</em></p>\n<ul>\n<li><a href=\"https://github.com/jashkenas/underscore\">underscore</a> - JavaScript's utility _ belt.</li>\n<li><a href=\"https://github.com/lodash/lodash\">lodash</a> - A utility library delivering consistency, customization, performance, &#x26; extras.</li>\n<li><a href=\"https://github.com/andrewplummer/Sugar\">Sugar</a> - A JavaScript library for working with native objects.</li>\n<li><a href=\"https://github.com/dtao/lazy.js\">lazy.js</a> - Like Underscore, but lazier.</li>\n<li><a href=\"https://github.com/CrossEye/ramda\">ramda</a> - A practical functional library for JavaScript programmers.</li>\n<li><a href=\"https://github.com/mout/mout\">mout</a> - Modular JavaScript Utilities.</li>\n<li><a href=\"https://github.com/crcn/mesh.js\">mesh</a> - Streamable data synchronization utility.</li>\n<li><a href=\"https://github.com/alanrsoares/prelude-js\">preludejs</a> - Hardcore Functional Programming for JavaScript.</li>\n</ul>\n<h2>Reactive Programming</h2>\n<p><em>Reactive programming libraries to extend JavaScript’s capabilities.</em></p>\n<ul>\n<li><a href=\"https://github.com/ReactiveX/rxjs\">RxJS</a> - A reactive programming library for JavaScript.</li>\n<li><a href=\"https://github.com/baconjs/bacon.js\">Bacon</a> - FRP (functional reactive programming) library for JavaScript.</li>\n<li><a href=\"https://github.com/pozadi/kefir\">Kefir</a> - FRP library for JavaScript inspired by Bacon.js and RxJS with focus on high performance and low memory consumption.</li>\n<li><a href=\"http://highlandjs.org/\">Highland</a> - Re-thinking the JavaScript utility belt, Highland manages synchronous and asynchronous code easily, using nothing more than standard JavaScript and Node-like Streams.</li>\n<li><a href=\"https://github.com/cujojs/most\">Most.js</a> - high performance FRP library.</li>\n<li><a href=\"https://github.com/mobxjs/mobx\">MobX</a> - TFRP library for simple, scalable state management.</li>\n<li><a href=\"https://cycle.js.org\">Cycle.js</a> - A functional and reactive JavaScript library for cleaner code.</li>\n</ul>\n<h2>Data Structure</h2>\n<p><em>Data structure libraries to build a more sophisticated application.</em></p>\n<ul>\n<li><a href=\"https://github.com/facebook/immutable-js\">immutable-js</a> - Immutable Data Collections including Sequence, Range, Repeat, Map, OrderedMap, Set and a sparse Vector.</li>\n<li><a href=\"https://github.com/swannodette/mori\">mori</a> - A library for using ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript.</li>\n<li><a href=\"https://github.com/mauriciosantos/Buckets-JS\">buckets</a> - A complete, fully tested and documented data structure library written in JavaScript.</li>\n<li><a href=\"https://github.com/flesler/hashmap\">hashmap</a> - Simple hashmap implementation that supports any kind of keys.</li>\n</ul>\n<h2>Date</h2>\n<p><em>Date Libraries.</em></p>\n<ul>\n<li><a href=\"https://github.com/moment/moment\">moment</a> - Parse, validate, manipulate, and display dates in JavaScript.</li>\n<li><a href=\"https://github.com/moment/moment-timezone\">moment-timezone</a> - Timezone support for moment.js.</li>\n<li><a href=\"https://github.com/rmm5t/jquery-timeago\">jquery-timeago</a> - A jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. \"4 minutes ago\").</li>\n<li><a href=\"https://github.com/mde/timezone-js\">timezone-js</a> - Timezone-enabled JavaScript Date object. Uses Olson zoneinfo files for timezone data.</li>\n<li><a href=\"https://github.com/MatthewMueller/date\">date</a> - Date() for humans.</li>\n<li><a href=\"https://github.com/rauchg/ms.js\">ms.js</a> - Tiny millisecond conversion utility.</li>\n<li><a href=\"https://github.com/gumroad/countdown.js\">countdown.js</a> - Super simple countdowns.</li>\n<li><a href=\"https://github.com/hustcc/timeago.js\">timeago.js</a> - Simple library (less then 2kb) used to format date with <code class=\"language-text\">*** time ago</code> statement.</li>\n<li><a href=\"https://github.com/taylorhakes/fecha\">fecha</a> - Lightweight date formatting and parsing (~2KB). Meant to replace parsing and formatting functionality of moment.js.</li>\n<li><a href=\"https://github.com/date-fns/date-fns\">date-fns</a> - Modern JavaScript date utility library.</li>\n<li><a href=\"https://github.com/dawidjaniga/map-countdown\">map-countdown</a> - A browser countdown built on top of the Google Maps.</li>\n<li><a href=\"https://github.com/iamkun/dayjs\">dayjs</a> - Day.js 2KB immutable date library alternative to Moment.js with the same modern API.</li>\n</ul>\n<h2>String</h2>\n<p><em>String Libraries.</em></p>\n<ul>\n<li><a href=\"https://github.com/panzerdp/voca\">voca</a> - The ultimate JavaScript string library</li>\n<li><a href=\"https://github.com/EvandroLG/selecting\">selecting</a> - A library that allows you to access the text selected by the user.</li>\n<li><a href=\"https://github.com/epeli/underscore.string\">underscore.string</a> - String manipulation extensions for Underscore.js JavaScript library.</li>\n<li><a href=\"https://github.com/jprichardson/string.js\">string.js</a> - Extra JavaScript string methods.</li>\n<li><a href=\"https://github.com/mathiasbynens/he\">he</a> - A robust HTML entity encoder/decoder written in JavaScript.</li>\n<li><a href=\"https://github.com/sindresorhus/multiline\">multiline</a> - Multiline strings in JavaScript.</li>\n<li><a href=\"https://github.com/sindresorhus/query-string\">query-string</a> - Parse and stringify URL query strings.</li>\n<li><a href=\"https://github.com/medialize/URI.js/\">URI.js</a> - JavaScript URL mutation library.</li>\n<li><a href=\"https://github.com/Mikhus/domurl\">jsurl</a> - Lightweight URL manipulation with JavaScript.</li>\n<li><a href=\"https://github.com/alexei/sprintf.js\">sprintf.js</a> - A sprintf implementation.</li>\n<li><a href=\"https://github.com/snd/url-pattern\">url-pattern</a> - Easier than regex string matching patterns for urls and other strings. Turn strings into data or data into strings.</li>\n<li><a href=\"https://github.com/plexis-js/plexis\">plexis</a> - Lo-fi, powerful, community-driven string manipulation library.</li>\n</ul>\n<h2>Number</h2>\n<ul>\n<li><a href=\"https://github.com/adamwdraper/Numeral-js\">Numeral-js</a> - A JavaScript library for formatting and manipulating numbers.</li>\n<li><a href=\"https://github.com/chancejs/chancejs\">chance.js</a> - Random generator helper in JavaScript. Can generate numbers, strings etc.</li>\n<li><a href=\"https://github.com/HubSpot/odometer\">odometer</a> - Smoothly transitions numbers with ease.</li>\n<li><a href=\"https://github.com/josscrowcroft/accounting.js\">accounting.js</a> - A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.</li>\n<li><a href=\"https://github.com/josscrowcroft/money.js\">money.js</a> - A tiny (1kb) JavaScript currency conversion library, for web &#x26; nodeJS.</li>\n<li><a href=\"https://github.com/infusion/Fraction.js\">Fraction.js</a> - A rational number library for JavaScript.</li>\n<li><a href=\"https://github.com/infusion/Complex.js\">Complex.js</a> - A complex number library for JavaScript.</li>\n<li><a href=\"https://github.com/infusion/Polynomial.js\">Polynomial.js</a> - A polynomials library for JavaScript.</li>\n</ul>\n<h2>Storage</h2>\n<ul>\n<li><a href=\"https://github.com/marcuswestin/store.js\">store.js</a> - LocalStorage wrapper for all browsers without using cookies or flash. Uses localStorage, globalStorage, and userData behavior under the hood.</li>\n<li><a href=\"https://github.com/mozilla/localForage\">localForage</a> - Offline storage, improved. Wraps IndexedDB, WebSQL, or localStorage using a simple but powerful API.</li>\n<li><a href=\"https://github.com/andris9/jStorage\">jStorage</a> - jStorage is a simple key/value database to store data on browser side.</li>\n<li><a href=\"https://github.com/zendesk/cross-storage\">cross-storage</a> - Cross domain local storage, with permissions.</li>\n<li><a href=\"https://github.com/addyosmani/basket.js\">basket.js</a> - A script and resource loader for caching &#x26; loading scripts with localStorage.</li>\n<li><a href=\"https://github.com/nodeca/bag.js\">bag.js</a> - A caching script and resource loader, similar to basket.js, but with additional k/v interface and localStorage / websql / indexedDB support.</li>\n<li><a href=\"https://github.com/Wisembly/basil.js\">basil.js</a> - The missing JavaScript smart persistent layer.</li>\n<li><a href=\"https://github.com/carhartl/jquery-cookie\">jquery-cookie</a> - A simple, lightweight jQuery plugin for reading, writing and deleting cookies.</li>\n<li><a href=\"https://github.com/js-cookie/js-cookie\">js-cookie</a> - A simple, lightweight JavaScript API for handling browser cookies.</li>\n<li><a href=\"https://github.com/ScottHamper/Cookies\">Cookies</a> - JavaScript Client-Side Cookie Manipulation Library.</li>\n<li><a href=\"https://github.com/aaronpowell/db.js/\">DB.js</a> - Promise based IndexDB Wrapper library.</li>\n<li><a href=\"https://github.com/brianleroux/lawnchair/\">lawnchair.js</a> - Simple client-side JSON storage.</li>\n<li><a href=\"https://github.com/kripken/sql.js\">sql.js</a> - SQLite compiled to JavaScript through Emscripten.</li>\n<li><a href=\"https://github.com/nirtz89/crumbsjs\">crumbsjs</a> - A lightweight vanilla ES6 cookies and local storage JavaScript library.</li>\n</ul>\n<h2>Color</h2>\n<ul>\n<li><a href=\"https://github.com/davidmerfield/randomColor\">randomColor</a> - A color generator for JavaScript.</li>\n<li><a href=\"https://github.com/gka/chroma.js\">chroma.js</a> - JavaScript library for all kinds of color manipulations.</li>\n<li><a href=\"https://github.com/Qix-/color\">color</a> - JavaScript color conversion and manipulation library.</li>\n<li><a href=\"https://github.com/mrmrs/colors\">colors</a> - Smarter defaults for colors on the web.</li>\n<li><a href=\"https://github.com/Fooidge/PleaseJS\">PleaseJS</a> - JavaScript Library for creating random pleasing colors and color schemes.</li>\n<li><a href=\"https://github.com/bgrins/TinyColor\">TinyColor</a> - Fast, small color manipulation and conversion for JavaScript.</li>\n<li><a href=\"https://github.com/jariz/vibrant.js/\">Vibrant.js</a> - Extract prominent colors from an image.</li>\n</ul>\n<h2>I18n And L10n</h2>\n<p><em>Localization (l10n) and internationalization (i18n) JavaScript libraries.</em></p>\n<ul>\n<li><a href=\"https://github.com/i18next/i18next\">i18next</a> - internationalisation (i18n) with JavaScript the easy way.</li>\n<li><a href=\"https://github.com/airbnb/polyglot.js\">polyglot</a> - tiny i18n helper library.</li>\n<li><a href=\"https://github.com/nodeca/babelfish/\">babelfish</a> - i18n with human friendly API and built in plurals support.</li>\n<li><a href=\"https://github.com/ttag-org/ttag\">ttag</a> - Modern javascript i18n localization library based on ES6 tagged templates and the good old GNU gettext.</li>\n</ul>\n<h2>Control Flow</h2>\n<ul>\n<li><a href=\"https://github.com/caolan/async\">async</a> - Async utilities for node and the browser.</li>\n<li><a href=\"https://github.com/kriskowal/q\">q</a> - A tool for making and composing asynchronous promises in JavaScript.</li>\n<li><a href=\"https://github.com/creationix/step/\">step</a> - An async control-flow library that makes stepping through logic easy.</li>\n<li><a href=\"https://github.com/bevacqua/contra/\">contra</a> - Asynchronous flow control with a functional taste to it.</li>\n<li><a href=\"https://github.com/petkaantonov/bluebird/\">Bluebird</a> - fully featured promise library with focus on innovative features and performance.</li>\n<li><a href=\"https://github.com/cujojs/when\">when</a> - A solid, fast Promises/A+ and when() implementation, plus other async goodies.</li>\n<li><a href=\"https://github.com/gartz/ObjectEventTarget\">ObjectEventTarget</a> - Provide a prototype that add support to event listeners (with same behavior of EventTarget from DOMElements available on browsers).</li>\n<li><a href=\"https://github.com/marcoonroad/sporadic\">sporadic</a> - Composable concurrency abstractions (such as streams, coroutines and Go-like channels) on top of promises, for Node and browser engines.</li>\n</ul>\n<h2>Routing</h2>\n<ul>\n<li><a href=\"https://github.com/flatiron/director\">director</a> - A tiny and isomorphic URL router for JavaScript.</li>\n<li><a href=\"https://github.com/visionmedia/page.js\">page.js</a> - Micro client-side router inspired by the Express router (~1200 bytes).</li>\n<li><a href=\"https://github.com/mtrpcic/pathjs\">pathjs</a> - Simple, lightweight routing for web browsers.</li>\n<li><a href=\"https://github.com/millermedeiros/crossroads.js\">crossroads</a> - JavaScript Routes.</li>\n<li><a href=\"https://github.com/olivernn/davis.js\">davis.js</a> - RESTful degradable JavaScript routing using pushState.</li>\n<li><a href=\"https://github.com/lukeed/navaid\">navaid</a> - A navigation aid (aka, router) for the browser in 850 bytes~!</li>\n</ul>\n<h2>Security</h2>\n<ul>\n<li><a href=\"https://github.com/cure53/DOMPurify\">DOMPurify</a> - A DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG.</li>\n<li><a href=\"https://github.com/leizongmin/js-xss\">js-xss</a> - Sanitize untrusted HTML (to prevent XSS) with a configuration specified by a Whitelist.</li>\n<li><a href=\"https://github.com/yahoo/xss-filters\">xss-filters</a> - Secure XSS Filters by Yahoo.</li>\n</ul>\n<h2>Log</h2>\n<ul>\n<li><a href=\"https://github.com/adamschwartz/log\">log</a> - Console.log with style.</li>\n<li><a href=\"https://github.com/Oaxoa/Conzole\">Conzole</a> - A debug panel built in JavaScript that wraps JavaScript native console object methods and functionality in a panel displayed inside the page.</li>\n<li><a href=\"https://github.com/patik/console.log-wrapper\">console.log-wrapper</a> - Log to the console in any browser with clarity.</li>\n<li><a href=\"https://github.com/pimterry/loglevel\">loglevel</a> - Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods.</li>\n<li><a href=\"http://mixu.net/minilog/\">minilog</a> – Lightweight client &#x26; server-side logging with Stream-API backends.</li>\n<li><a href=\"http://guigrpa.github.io/storyboard/\">storyboard</a> - Universal logging library + Chrome extension; it lets you see all client and server tasks triggered by a user action in a single place.</li>\n</ul>\n<h2>RegExp</h2>\n<ul>\n<li><a href=\"https://regex101.com/#javascript\">RegEx101</a> - Online regex tester and debugger for JavaScript. Also supports Python, PHP and PCRE.</li>\n<li><a href=\"http://regexr.com\">RegExr</a> - HTML/JS based tool for creating, testing, and learning about Regular Expressions.</li>\n<li><a href=\"https://github.com/thebinarysearchtree/regexpbuilderjs\">RegExpBuilder</a> - Create regular expressions using chained methods.</li>\n</ul>\n<h2>Voice Command</h2>\n<ul>\n<li><a href=\"https://github.com/TalAter/annyang\">annyang</a> - A JavaScript library for adding voice commands to your site, using speech recognition.</li>\n<li><a href=\"https://github.com/pazguille/voix\">voix.js</a> - A JavaScript library to add voice commands to your sites, apps or games.</li>\n</ul>\n<h2>API</h2>\n<ul>\n<li><a href=\"https://github.com/axios/axios\">axios</a> - Promise based HTTP client for the browser and node.js.</li>\n<li><a href=\"https://github.com/SGrondin/bottleneck\">bottleneck</a> - A powerful rate limiter that makes throttling easy.</li>\n<li><a href=\"https://github.com/bettiolo/oauth-signature-js\">oauth-signature-js</a> - JavaScript OAuth 1.0a signature generator for node and the browser.</li>\n<li><a href=\"https://github.com/lincolnloop/amygdala\">amygdala</a> - RESTful HTTP client for JavaScript powered web applications.</li>\n<li><a href=\"https://github.com/jpillora/jquery.rest\">jquery.rest</a> - A jQuery plugin for easy consumption of RESTful APIs.</li>\n<li><a href=\"https://github.com/victor-am/rails-ranger\">Rails Ranger</a> - An opinionated REST client for Ruby on Rails APIs.</li>\n<li><a href=\"https://github.com/elbywan/wretch\">wretch</a> - A tiny wrapper built around fetch with an intuitive syntax.</li>\n<li><a href=\"https://github.com/Bearer/bearer-js\">Bearer.sh</a> - Universal API client that supports OAuth / API Key / Basic / etc.</li>\n</ul>\n<h2>Streaming</h2>\n<ul>\n<li><a href=\"https://github.com/zalando/tailor\">Tailor</a> - Streaming layout service for front-end microservices, inspired by Facebook's BigPipe.</li>\n</ul>\n<h2>Vision Detection</h2>\n<ul>\n<li><a href=\"https://github.com/eduardolundgren/tracking.js\">tracking.js</a> - A modern approach for Computer Vision on the web.</li>\n<li><a href=\"https://github.com/antimatter15/ocrad.js\">ocrad.js</a> - OCR in JavaScript via Emscripten.</li>\n</ul>\n<h2>Machine Learning</h2>\n<ul>\n<li><a href=\"https://github.com/karpathy/convnetjs\">ConvNetJS</a> - Deep Learning in JavaScript. Train Convolutional Neural Networks (or ordinary ones) in your browser.</li>\n<li><a href=\"https://github.com/dn2a/dn2a-javascript\">DN2A</a> - Digital Neural Networks Architecture.</li>\n<li><a href=\"https://github.com/harthur/brain\">Brain.js</a> - Neural networks in JavaScript.</li>\n<li><a href=\"https://github.com/stevenmiller888/mind\">Mind.js</a> - A flexible neural network library.</li>\n<li><a href=\"https://github.com/cazala/synaptic\">Synaptic.js</a> - Architecture-free neural network library for node.js and the browser.</li>\n<li><a href=\"https://js.tensorflow.org\">TensorFlow.js</a> - A JavaScript library for training and deploying ML models in the browser and on Node.js.</li>\n<li><a href=\"https://ml5js.org\">ml5.js</a> - Friendly Machine Learning for the Web.</li>\n<li><a href=\"https://github.com/mrdimosthenis/Synapses\">Synapses</a> - Lightweight cross-platform Neural Network library.</li>\n</ul>\n<h2>Browser Detection</h2>\n<ul>\n<li><a href=\"https://github.com/ded/bowser\">bowser</a> - a browser detector.</li>\n</ul>\n<h2>Benchmark</h2>\n<ul>\n<li><a href=\"https://github.com/bestiejs/benchmark.js\">benchmark.js</a> - A benchmarking library. As used on jsPerf.com.</li>\n<li><a href=\"https://github.com/logicalparadox/matcha\">matcha</a> - A caffeine driven, simplistic approach to benchmarking.</li>\n</ul>\n<h2>Code highlighting</h2>\n<ul>\n<li><a href=\"https://github.com/isagalaev/highlight.js\">Highlight.js</a> - JavaScript syntax highlighter.</li>\n<li><a href=\"https://github.com/PrismJS/prism\">PrismJS</a> - Lightweight, robust, elegant syntax highlighting.</li>\n</ul>\n<h2>Loading Status</h2>\n<p><em>Libraries for indicate load status.</em></p>\n<ul>\n<li><a href=\"https://github.com/lightningtgc/MProgress.js\">Mprogress.js</a> - Create Google Material Design progress linear bars.</li>\n<li><a href=\"http://ricostacruz.com/nprogress/\">NProgress</a> - Slim progress bars for Ajax'y applications.</li>\n<li><a href=\"https://github.com/fgnass/spin.js\">Spin.js</a> - A spinning activity indicator.</li>\n<li><a href=\"https://github.com/usablica/progress.js\">progress.js</a> - Create and manage progress bar for every objects on the page.</li>\n<li><a href=\"https://github.com/kimmobrunfeldt/progressbar.js\">progressbar.js</a> - Beautiful and responsive progress bars with animated SVG paths.</li>\n<li><a href=\"https://github.com/HubSpot/pace\">pace</a> - Automatically add a progress bar to your site.</li>\n<li><a href=\"https://github.com/buunguyen/topbar\">topbar</a> - Tiny &#x26; beautiful site-wide progress indicator.</li>\n<li><a href=\"https://github.com/jacoborus/nanobar\">nanobar</a> - Very lightweight progress bars. No jQuery.</li>\n<li><a href=\"https://github.com/codrops/PageLoadingEffects\">PageLoadingEffects</a> - Modern ways of revealing new content using SVG animations.</li>\n<li><a href=\"https://github.com/tobiasahlin/SpinKit\">SpinKit</a> - A collection of loading indicators animated with CSS.</li>\n<li><a href=\"https://github.com/hakimel/Ladda\">Ladda</a> - Buttons with built-in loading indicators.</li>\n<li><a href=\"https://github.com/lukehaas/css-loaders\">css-loaders</a> - A collection of loading spinners animated with CSS</li>\n</ul>\n<p>Besides libraries, there're <a href=\"http://codepen.io/collection/HtAne/\">Collection on Codepen</a>, and generators like <a href=\"http://www.ajaxload.info/\">Ajaxload</a>, <a href=\"http://preloaders.net/\">Preloaders</a> and <a href=\"http://cssload.net/\">CSSLoad</a>.</p>\n<h2>Validation</h2>\n<ul>\n<li><a href=\"https://github.com/guillaumepotier/Parsley.js\">Parsley.js</a> - Validate your forms, frontend, without writing a single line of JavaScript.</li>\n<li><a href=\"https://github.com/jzaefferer/jquery-validation\">jquery-validation</a> - jQuery Validation Plugin.</li>\n<li><a href=\"https://github.com/chriso/validator.js\">validator.js</a> - String validation and sanitization.</li>\n<li><a href=\"https://github.com/rickharrison/validate.js\">validate.js</a> - Lightweight JavaScript form validation library inspired by CodeIgniter.</li>\n<li><a href=\"https://github.com/jaymorrow/validatr/\">validatr</a> - Cross Browser HTML5 Form Validation.</li>\n<li><a href=\"http://formvalidation.io/\">FormValidation</a> - The best jQuery plugin to validate form fields. Formerly BootstrapValidator.</li>\n<li><a href=\"https://github.com/arasatasaygin/is.js\">is.js</a> - Check types, regexps, presence, time and more.</li>\n<li><a href=\"https://github.com/FieldVal/fieldval-js\">FieldVal</a> - multipurpose validation library. Supports both sync and async validation.</li>\n</ul>\n<h2>Keyboard Wrappers</h2>\n<ul>\n<li><a href=\"https://github.com/ccampbell/mousetrap\">mousetrap</a> - Simple library for handling keyboard shortcuts in JavaScript.</li>\n<li><a href=\"https://github.com/madrobby/keymaster\">keymaster</a> - A simple micro-library for defining and dispatching keyboard shortcuts.</li>\n<li><a href=\"https://github.com/dmauro/Keypress\">Keypress</a> - A keyboard input capturing utility in which any key can be a modifier key.</li>\n<li><a href=\"https://github.com/RobertWHurst/KeyboardJS\">KeyboardJS</a> - A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.</li>\n<li><a href=\"https://github.com/jeresig/jquery.hotkeys\">jquery.hotkeys</a> - jQuery Hotkeys lets you watch for keyboard events anywhere in your code supporting almost any key combination.</li>\n<li><a href=\"https://github.com/keithamus/jwerty\">jwerty</a> - Awesome handling of keyboard events.</li>\n</ul>\n<h2>Tours And Guides</h2>\n<ul>\n<li><a href=\"https://github.com/usablica/intro.js\">intro.js</a> - A better way for new feature introduction and step-by-step users guide for your website and project.</li>\n<li><a href=\"https://github.com/HubSpot/shepherd\">shepherd</a> - Guide your users through a tour of your app.</li>\n<li><a href=\"https://github.com/sorich87/bootstrap-tour\">bootstrap-tour</a> - Quick and easy product tours with Twitter Bootstrap Popovers.</li>\n<li><a href=\"https://github.com/easelinc/tourist\">tourist</a> - Simple, flexible tours for your app.</li>\n<li><a href=\"https://github.com/heelhook/chardin.js\">chardin.js</a> - Simple overlay instructions for your apps.</li>\n<li><a href=\"https://github.com/tracelytics/pageguide\">pageguide</a> - An interactive guide for web page elements using jQuery and CSS3.</li>\n<li><a href=\"https://github.com/linkedin/hopscotch\">hopscotch</a> - A framework to make it easy for developers to add product tours to their pages.</li>\n<li><a href=\"https://github.com/zurb/joyride\">joyride</a> - jQuery feature tour plugin.</li>\n<li><a href=\"https://github.com/zzarcon/focusable\">focusable</a> - Set a spotlight focus on DOM element adding a overlay layer to the rest of the page.</li>\n<li><a href=\"https://github.com/kamranahmedse/driver.js\">driver.js</a> - Powerful yet light-weight, vanilla JavaScript engine to drive the user's focus across the page</li>\n</ul>\n<h2>Notifications</h2>\n<ul>\n<li><a href=\"https://github.com/dolce/iziToast\">iziToast</a> - Elegant, responsive, flexible and lightweight notification plugin with no dependencies.</li>\n<li><a href=\"https://github.com/HubSpot/messenger\">messenger</a> - Growl-style alerts and messages for your app.</li>\n<li><a href=\"https://github.com/needim/noty\">noty</a> - jQuery notification plugin.</li>\n<li><a href=\"https://github.com/sciactive/pnotify\">pnotify</a> - JavaScript notifications for Bootstrap, jQuery UI, and the Web Notifications Draft.</li>\n<li><a href=\"https://github.com/CodeSeven/toastr\">toastr</a> - Simple JavaScript toast notifications.</li>\n<li><a href=\"https://github.com/wavded/humane-js\">humane-js</a> - A simple, modern, browser notification system.</li>\n<li><a href=\"https://github.com/hxgf/smoke.js\">smoke.js</a> - Framework-agnostic styled alert system for JavaScript.</li>\n<li><a href=\"https://github.com/jaredreich/notie\">notie</a> - Simple notifications and inputs with no dependencies.</li>\n</ul>\n<h2>Sliders</h2>\n<ul>\n<li><a href=\"https://github.com/nolimits4web/Swiper\">Swiper</a> - Mobile touch slider and framework with hardware accelerated transitions.</li>\n<li><a href=\"https://github.com/kenwheeler/slick\">slick</a> - The last carousel you'll ever need.</li>\n<li><a href=\"http://www.slidesjs.com\">slidesJs</a> - Is a responsive slideshow plug-in for JQuery(1.7.1+) with features like touch and CSS3 transitions</li>\n<li><a href=\"https://github.com/woothemes/FlexSlider\">FlexSlider</a> - An awesome, fully responsive jQuery slider plugin.</li>\n<li><a href=\"https://github.com/idiot/unslider\">unslider</a> - The simplest jQuery slider there is.</li>\n<li><a href=\"https://github.com/darsain/sly\">sly</a> - JavaScript library for one-directional scrolling with item based navigation support.</li>\n<li><a href=\"https://github.com/jaysalvat/vegas\">vegas</a> - A jQuery plugin to add beautiful fullscreen backgrounds to your webpages. It even allows Slideshows.</li>\n<li><a href=\"https://github.com/IanLunn/Sequence\">Sequence</a> - CSS animation framework for creating responsive sliders, presentations, banners, and other step-based applications.</li>\n<li><a href=\"https://github.com/hakimel/reveal.js\">reveal.js</a> - A framework for easily creating beautiful presentations using HTML.</li>\n<li><a href=\"https://github.com/impress/impress.js\">impress.js</a> - It's a presentation framework based on the power of CSS3 transforms and transitions in modern browsers and inspired by the idea behind prezi.com.</li>\n<li><a href=\"https://github.com/bespokejs/bespoke\">bespoke.js</a> - DIY Presentation Micro-Framework</li>\n<li><a href=\"https://github.com/tantaman/Strut\">Strut</a> - Strut - An Impress.js and Bespoke.js Presentation Editor</li>\n<li><a href=\"https://github.com/dimsemenov/PhotoSwipe\">PhotoSwipe</a> - JavaScript image gallery for mobile and desktop, modular, framework independent.</li>\n<li><a href=\"https://github.com/JoanClaret/jcSlider\">jcSlider</a> - A responsive slider jQuery plugin with CSS animations.</li>\n<li><a href=\"https://github.com/jcobb/basic-jquery-slider\">basic-jquery-slider</a> - Simple to use, simple to theme, simple to customise.</li>\n<li><a href=\"https://github.com/creative-punch/jQuery.adaptive-slider/\">jQuery.adaptive-slider</a> - A jQuery plugin for a slider with adaptive colored figcaption and navigation.</li>\n<li><a href=\"https://github.com/bchanx/slidr\">slidr</a> - add some slide effects.</li>\n<li><a href=\"https://github.com/metafizzy/flickity\">Flickity</a> - Touch, responsive, flickable galleries.</li>\n<li><a href=\"https://github.com/jedrzejchalubek/glidejs\">Glide.js</a> - Responsive and touch-friendly jQuery slider. It's simple, lightweight and fast.</li>\n<li><a href=\"https://github.com/creative-punch/jQuery.adaptive-slider/\">jQuery.adaptive-slider</a> - A jQuery plugin for a slider with adaptive colored figcaption and navigation.</li>\n<li><a href=\"https://github.com/davidcetinkaya/embla-carousel\">Embla Carousel</a> - An extensible low level carousel for the web, written in TypeScript.</li>\n</ul>\n<h2>Range Sliders</h2>\n<ul>\n<li><a href=\"https://github.com/IonDen/ion.rangeSlider\">Ion.RangeSlider</a> - Powerful and easily customizable range slider with many options and skin support.</li>\n<li><a href=\"https://github.com/ghusse/jQRangeSlider\">jQRangeSlider</a> - A JavaScript slider selector that supports dates.</li>\n<li><a href=\"https://github.com/leongersen/noUiSlider\">noUiSlider</a> - A lightweight, highly customizable range slider without bloat.</li>\n<li><a href=\"https://github.com/andreruffert/rangeslider.js\">rangeslider.js</a> - HTML5 input range slider element polyfill.</li>\n</ul>\n<h2>Form Widgets</h2>\n<h3>Input</h3>\n<ul>\n<li><a href=\"https://github.com/twitter/typeahead.js\">typeahead.js</a> - A fast and fully-featured autocomplete library.</li>\n<li><a href=\"https://github.com/aehlke/tag-it\">tag-it</a> - A jQuery UI plugin to handle multi-tag fields as well as tag suggestions/autocomplete.</li>\n<li><a href=\"https://github.com/ichord/At.js\">At.js</a> - Add GitHub like mentions autocomplete to your application.</li>\n<li><a href=\"https://github.com/jamesallardice/Placeholders.js\">Placeholders.js</a> - A JavaScript polyfill for the HTML5 placeholder attribute.</li>\n<li><a href=\"https://github.com/yairEO/fancyInput\">fancyInput</a> - Makes typing in input fields fun with CSS3 effects.</li>\n<li><a href=\"https://github.com/xoxco/jQuery-Tags-Input\">jQuery-Tags-Input</a> - Magically convert a simple text input into a cool tag list with this jQuery plugin.</li>\n<li><a href=\"https://github.com/BankFacil/vanilla-masker\">vanilla-masker</a> - A pure JavaScript mask input.</li>\n<li><a href=\"https://github.com/IonDen/ion.checkRadio\">Ion.CheckRadio</a> - jQuery plugin for styling checkboxes and radio-buttons. With skin support.</li>\n<li><a href=\"https://github.com/LeaVerou/awesomplete\">awesomplete</a> - Ultra lightweight, usable, beautiful autocomplete with zero dependencies. - <a href=\"http://leaverou.github.io/awesomplete\">http://leaverou.github.io/awesomplete</a></li>\n</ul>\n<h3>Calendar</h3>\n<ul>\n<li><a href=\"https://github.com/amsul/pickadate.js\">pickadate.js</a> - The mobile-friendly, responsive, and lightweight jQuery date &#x26; time input picker.</li>\n<li><a href=\"https://github.com/eternicode/bootstrap-datepicker\">bootstrap-datepicker</a> - A datepicker for @twitter bootstrap forked from Stefan Petre's (of eyecon.ro), improvements by @eternicode.</li>\n<li><a href=\"https://github.com/dbushell/Pikaday\">Pikaday</a> - A refreshing JavaScript Datepicker — lightweight, no dependencies, modular CSS.</li>\n<li><a href=\"https://github.com/fullcalendar/fullcalendar\">fullcalendar</a> - Full-sized drag &#x26; drop event calendar (jQuery plugin).</li>\n<li><a href=\"https://github.com/bevacqua/rome\">rome</a> - A customizable date (and time) picker. Dependency free, opt-in UI.</li>\n<li><a href=\"https://github.com/felicegattuso/datedropper\">datedropper</a> - datedropper is a jQuery plugin that provides a quick and easy way to manage dates for input fields.</li>\n</ul>\n<h3>Select</h3>\n<ul>\n<li><a href=\"https://github.com/brianreavis/selectize.js\">selectize.js</a> - Selectize is the hybrid of a textbox and select box. It's jQuery based and it has autocomplete and native-feeling keyboard navigation; useful for tagging, contact lists, etc.</li>\n<li><a href=\"https://github.com/select2/select2\">select2</a> - a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.</li>\n<li><a href=\"https://github.com/harvesthq/chosen\">chosen</a> - A library for making long, unwieldy select boxes more friendly.</li>\n</ul>\n<h3>File Uploader</h3>\n<ul>\n<li><a href=\"https://github.com/blueimp/jQuery-File-Upload\">jQuery-File-Upload</a> - File Upload widget with multiple file selection, drag&#x26;drop support, progress bar, validation and preview images, audio and video for jQuery.</li>\n<li><a href=\"https://github.com/enyo/dropzone\">dropzone</a> - Dropzone is an easy to use drag'n'drop library. It supports image previews and shows nice progress bars.</li>\n<li><a href=\"https://github.com/flowjs/flow.js\">flow.js</a> - A JavaScript library providing multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API.</li>\n<li><a href=\"https://github.com/FineUploader/fine-uploader\">fine-uploader</a> - Multiple file upload plugin with progress-bar, drag-and-drop, direct-to-S3 uploading.</li>\n<li><a href=\"https://github.com/mailru/FileAPI\">FileAPI</a> - A set of JavaScript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF.</li>\n<li><a href=\"https://github.com/moxiecode/plupload\">plupload</a> - A JavaScript API for dealing with file uploads it supports features like multiple file selection, file type filtering, request chunking, client side image scaling and it uses different runtimes to achieve this such as HTML 5, Silverlight and Flash.</li>\n</ul>\n<h3>Other</h3>\n<ul>\n<li><a href=\"https://github.com/malsup/form\">form</a> - jQuery Form Plugin.</li>\n<li><a href=\"https://github.com/guillaumepotier/Garlic.js\">Garlic.js</a> - Automatically persist your forms' text and select field values locally, until the form is submitted.</li>\n<li><a href=\"https://github.com/RadLikeWhoa/Countable\">Countable</a> - A JavaScript function to add live paragraph-, word- and character-counting to an HTML element.</li>\n<li><a href=\"https://github.com/jessepollak/card\">card</a> - Make your credit card form better in one line of code.</li>\n<li><a href=\"https://github.com/LeaVerou/stretchy\">stretchy</a> - Form element autosizing, the way it should be.</li>\n<li><a href=\"https://github.com/davidwells/analytics\">analytics</a> - A lightweight, extendable analytics library designed to work with any third-party analytics provider to track page views, custom events, &#x26; identify users.</li>\n</ul>\n<h2>Tips</h2>\n<ul>\n<li><a href=\"https://github.com/jaz303/tipsy\">tipsy</a> - Facebook-style tooltips plugin for jQuery.</li>\n<li><a href=\"https://github.com/enyo/opentip\">opentip</a> - An open source JavaScript tooltip based on the prototype framework.</li>\n<li><a href=\"https://github.com/qTip2/qTip2\">qTip2</a> - Pretty powerful tooltips.</li>\n<li><a href=\"https://github.com/iamceege/tooltipster\">tooltipster</a> - A jQuery tooltip plugin.</li>\n<li><a href=\"https://github.com/arashmanteghi/simptip\">simptip</a> - A simple CSS tooltip made with Sass.</li>\n<li><a href=\"https://github.com/vast-engineering/jquery-popup-overlay\">jquery-popup-overlay</a> - jQuery plugin for responsive and accessible modal windows and tooltips.</li>\n<li><a href=\"https://github.com/paulkinzett/toolbar\">toolbar</a> - A tooltip style toolbar jQuery plugin</li>\n<li><a href=\"https://github.com/chinchang/hint.css\">hint.css</a> - A tooltip library in CSS for your lovely websites.</li>\n</ul>\n<h2>Modals and Popups</h2>\n<ul>\n<li><a href=\"https://github.com/dimsemenov/Magnific-Popup\">Magnific-Popup</a> - Light and responsive lightbox script with focus on performance.</li>\n<li><a href=\"https://github.com/gristmill/jquery-popbox\">jquery-popbox</a> - jQuery PopBox UI Element.</li>\n<li><a href=\"https://github.com/voronianski/jquery.avgrund.js\">jquery.avgrund.js</a> - A jQuery plugin with new modal concept for popups.</li>\n<li><a href=\"https://github.com/HubSpot/vex\">vex</a> - A modern dialog library which is highly configurable and easy to style.</li>\n<li><a href=\"https://github.com/jschr/bootstrap-modal\">bootstrap-modal</a> - Extends the default Bootstrap Modal class. Responsive, stackable, ajax and more.</li>\n<li><a href=\"https://github.com/drublic/css-modal\">css-modal</a> - A modal built out of pure CSS.</li>\n<li><a href=\"https://github.com/vast-engineering/jquery-popup-overlay\">jquery-popup-overlay</a> - jQuery plugin for responsive and accessible modal windows and tooltips.</li>\n<li><a href=\"https://github.com/t4t5/sweetalert\">SweetAlert</a> - An awesome replacement for JavaScript's alert.</li>\n<li><a href=\"https://github.com/feimosi/baguetteBox.js\">baguetteBox.js</a> - Simple and easy to use lightbox script written in pure JavaScript.</li>\n<li><a href=\"https://github.com/jackmoore/colorbox\">colorbox</a> - A light-weight, customizable lightbox plugin for jQuery.</li>\n<li><a href=\"https://github.com/fancyapps/fancyBox\">fancyBox</a> - A tool that offers a nice and elegant way to add zooming functionality for images, html content and multi-media on your webpages.</li>\n<li><a href=\"https://github.com/brutaldesign/swipebox\">swipebox</a> - A touchable jQuery lightbox</li>\n<li><a href=\"https://github.com/StephanWagner/jBox\">jBox</a> - jBox is a powerful and flexible jQuery plugin, taking care of all your popup windows, tooltips, notices and more.</li>\n</ul>\n<h2>Scroll</h2>\n<ul>\n<li><a href=\"https://github.com/stutrek/scrollMonitor\">scrollMonitor</a> - A simple and fast API to monitor elements as you scroll.</li>\n<li><a href=\"https://github.com/WickyNilliams/headroom.js\">headroom</a> - Give your pages some headroom. Hide your header until you need it.</li>\n<li><a href=\"https://github.com/peachananr/onepage-scroll\">onepage-scroll</a> - Create an Apple-like one page scroller website (iPhone 5S website) with One Page Scroll plugin.</li>\n<li><a href=\"https://github.com/cubiq/iscroll\">iscroll</a> - iScroll is a high performance, small footprint, dependency free, multi-platform JavaScript scroller.</li>\n<li><a href=\"https://github.com/Prinzhorn/skrollr\">skrollr</a> - Stand-alone parallax scrolling library for mobile (Android + iOS) and desktop. No jQuery.</li>\n<li><a href=\"https://github.com/wagerfield/parallax\">parallax</a> - Parallax Engine that reacts to the orientation of a smart device.</li>\n<li><a href=\"https://github.com/markdalgleish/stellar.js\">stellar.js</a> - Parallax scrolling made easy.</li>\n<li><a href=\"https://github.com/cameronmcefee/plax\">plax</a> - jQuery powered parallaxing.</li>\n<li><a href=\"https://github.com/stephband/jparallax\">jparallax</a> - jQuery plugin for creating interactive parallax effect.</li>\n<li><a href=\"https://github.com/alvarotrigo/fullPage.js\">fullPage</a> - A simple and easy to use plugin to create fullscreen scrolling websites (also known as single page websites).</li>\n<li><a href=\"https://github.com/s-yadav/ScrollMenu\">ScrollMenu</a> - A new interface to replace old boring scrollbar.</li>\n<li><a href=\"https://github.com/NeXTs/Clusterize.js\">Clusterize.js</a> - Tiny vanilla JS plugin to display large data sets easily.</li>\n<li><a href=\"https://github.com/geosigno/simpleParallax\">simpleParallax</a> - Simple and tiny JavaScript library to add parallax animations on any images</li>\n</ul>\n<h2>Menu</h2>\n<ul>\n<li><a href=\"https://github.com/kamens/jQuery-menu-aim\">jQuery-menu-aim</a> - jQuery plugin to fire events when user's cursor aims at particular dropdown menu items. For making responsive mega dropdowns like Amazon's.</li>\n<li><a href=\"https://github.com/swisnl/jQuery-contextMenu\">jQuery contextMenu</a> - contextMenu manager.</li>\n<li><a href=\"https://github.com/mango/slideout\">Slideout</a> - A responsive touch slideout navigation menu for mobile web apps.</li>\n<li><a href=\"https://github.com/JoanClaret/slide-and-swipe-menu\">Slide and swipe</a> - A sliding swipe menu that works with touchSwipe library.</li>\n</ul>\n<h2>Table/Grid</h2>\n<ul>\n<li><a href=\"https://github.com/hikalkan/jtable\">jTable</a> - A jQuery plugin to create AJAX based CRUD tables.</li>\n<li><a href=\"https://www.datatables.net/\">DataTables</a> - (jQuery plug-in) It is a highly flexible tool, based upon the foundations of progressive enhancement, and will add advanced interaction controls to any HTML table.</li>\n<li><a href=\"http://olifolkerd.github.io/tabulator/\">Tabulator</a> - (jQuery plug-in) An extremely flexible library that create tables with a range of interactive features from any JSON data source or existing HTML table.</li>\n<li><a href=\"http://bootstrap-table.wenzhixin.net.cn/\">Bootstrap Table</a> - An Extension to the popular Bootstrap framework for creating tables that fit the style of your site with no need for additional markup.</li>\n<li><a href=\"https://github.com/mkoryak/floatThead\">floatThead</a> - (jQuery plug-in) lock any table's header while scrolling within the body. Works on any table and requires no custom html or css.</li>\n<li><a href=\"http://masonry.desandro.com/\">Masonry</a> - A cascading grid layout library.</li>\n<li><a href=\"http://packery.metafizzy.co/\">Packery</a> - A grid layout library that uses a bin-packing algorithm. Useable for draggable layouts.</li>\n<li><a href=\"http://isotope.metafizzy.co/\">Isotope</a> - A filterable, sortable, grid layout library. Can implement Masonry, Packery, and other layouts.</li>\n<li><a href=\"https://github.com/kristoferjoseph/flexboxgrid/\">flexboxgrid</a> - Grid based on CSS3 flexbox.</li>\n</ul>\n<h2>Frameworks</h2>\n<ul>\n<li><a href=\"http://semantic-ui.com/\">Semantic UI</a> - UI Kit with lots of themes and elements.</li>\n<li><a href=\"http://w2ui.com/\">w2ui</a> - A set of jQuery plugins for front-end development of data-driven web applications.</li>\n<li><a href=\"https://github.com/mrmrs/fluidity\">fluidity</a> - The worlds smallest fully-responsive css framework.</li>\n<li><a href=\"https://github.com/sapo/Ink\">Ink</a> - An HTML5/CSS3 framework used at SAPO for fast and efficient website design and prototyping.</li>\n</ul>\n<h2>Boilerplates</h2>\n<ul>\n<li><a href=\"https://github.com/h5bp/html5-boilerplate\">html5-boilerplate</a> - A professional front-end template for building fast, robust, and adaptable web apps or sites.</li>\n<li><a href=\"https://github.com/h5bp/mobile-boilerplate\">mobile-boilerplate</a> - A front-end template that helps you build fast, modern mobile web apps.</li>\n<li><a href=\"https://github.com/chrishumboldt/webplate\">webplate</a> - An awesome front-end framework that lets you stay focused on building your site or app while remaining really easy to use.</li>\n<li><a href=\"https://github.com/TedGoas/Cerberus\">Cerberus</a> - A few simple, but solid patterns for responsive HTML emails. Even in Outlook.</li>\n<li><a href=\"https://github.com/CodyHouse/full-page-intro-and-navigation\">full-page-intro-and-navigation</a> - An intro page with a full width background image, a bold animated menu and an iOS-like blurred effect behind the navigation.</li>\n<li><a href=\"https://github.com/crozynski/Fluid-Squares\">Fluid-Squares</a> - A fluid grid of square units.</li>\n<li><a href=\"https://github.com/bradfrost/Mobile-First-RWD\">Mobile-First-RWD</a> - An example of a mobile-first responsive web design.</li>\n<li><a href=\"https://github.com/bradfrost/this-is-responsive\">this-is-responsive</a> - This Is Responsive.</li>\n<li><a href=\"https://gist.github.com/addyosmani/9f10c555e32a8d06ddb0\">npm run-scripts</a> Task automation with NPM run-scripts.</li>\n</ul>\n<h2>Gesture</h2>\n<ul>\n<li><a href=\"https://github.com/hammerjs/hammer.js\">hammer.js</a> - A JavaScript library for multi-touch gestures.</li>\n<li><a href=\"https://github.com/hammerjs/touchemulator\">touchemulator</a> - Emulate touch input on your desktop.</li>\n<li><a href=\"https://github.com/bevacqua/dragula/\">Dragula</a> - Drag and drop so simple it hurts.</li>\n</ul>\n<h2>Maps</h2>\n<ul>\n<li><a href=\"https://github.com/Leaflet/Leaflet\">Leaflet</a> - JavaScript library for mobile-friendly interactive maps.</li>\n<li><a href=\"https://github.com/AnalyticalGraphicsInc/cesium\">Cesium</a> - Open Source WebGL virtual globe and map engine.</li>\n<li><a href=\"https://github.com/HPNeo/gmaps\">gmaps</a> - The easiest way to use Google Maps.</li>\n<li><a href=\"https://github.com/simplegeo/polymaps\">polymaps</a> - A free JavaScript library for making dynamic, interactive maps in modern web browsers.</li>\n<li><a href=\"https://github.com/kartograph/kartograph.js\">kartograph.js</a> - Open source JavaScript renderer for Kartograph SVG maps.</li>\n<li><a href=\"https://github.com/mapbox/mapbox.js\">mapbox.js</a> - Mapbox JavaScript API, a Leaflet Plugin.</li>\n<li><a href=\"https://github.com/manifestinteractive/jqvmap\">jqvmap</a> - jQuery Vector Map Library.</li>\n<li><a href=\"http://openlayers.org/\">OpenLayers3</a> - A high-performance, feature-packed library for all your mapping needs.</li>\n</ul>\n<h2>Video/Audio</h2>\n<ul>\n<li><a href=\"https://github.com/mike-zarandona/prettyembed.js\">prettyembed.js</a> - Prettier embeds for your YouTubes - with nice options like high-res preview images, advanced customization of embed options, and optional FitVids support.</li>\n<li><a href=\"https://github.com/etianen/html5media\">html5media</a> - Enables <video> and <audio> tags in all major browsers. <a href=\"https://html5media.info/\">https://html5media.info/</a></li>\n<li><a href=\"https://github.com/adrienjoly/playemjs\">Play-em JS</a> - Play'em is a JavaScript component that manages a music/video track queue and plays a sequence of songs by embedding several players in a HTML DIV including Youtube, Soundcloud and Vimeo.</li>\n<li><a href=\"https://github.com/Acconut/polyplayer\">polyplayer</a> - Rule YouTube, Soundcloud and Vimeo player with one API.</li>\n<li><a href=\"https://github.com/flowplayer/flowplayer\">flowplayer</a> - The HTML5 video player for the web\n<a href=\"https://flowplayer.org/\">https://flowplayer.org/</a></li>\n<li><a href=\"https://github.com/johndyer/mediaelement\">mediaelement</a> - HTML5 <audio> or <video> player with Flash and Silverlight shims that mimics the HTML5 MediaElement API, enabling a consistent UI in all browsers. <a href=\"http://mediaelementjs.com/\">http://mediaelementjs.com/</a></li>\n<li><a href=\"https://github.com/CreateJS/SoundJS\">SoundJS</a> - A library to make working with audio on the web easier. It provides a consistent API for playing audio in different browsers.</li>\n<li><a href=\"https://github.com/videojs/video.js\">video.js</a> - Video.js - open source HTML5 &#x26; Flash video player.</li>\n<li><a href=\"https://github.com/davatron5000/FitVids.js\">FitVids.js</a> - A lightweight, easy-to-use jQuery plugin for fluid width video embeds.</li>\n<li><a href=\"https://github.com/IonDen/ion.sound\">Ion.Sound</a> - Simple sounds on any web page.</li>\n<li><a href=\"https://github.com/WolframHempel/photobooth-js\">photobooth-js</a> - A widget that allows users to take their avatar pictures on your site.</li>\n<li><a href=\"https://github.com/clappr/clappr\">clappr</a> - An extensible media player for the web <a href=\"http://clappr.io\">http://clappr.io</a></li>\n</ul>\n<h2>Typography</h2>\n<ul>\n<li><a href=\"https://github.com/simplefocus/FlowType.JS\">FlowType.JS</a> - Web typography at its finest: font-size and line-height based on element width.</li>\n<li><a href=\"https://github.com/zachleat/BigText\">BigText</a> - jQuery plugin, calculates the font-size and word-spacing needed to match a line of text to a specific width.</li>\n<li><a href=\"https://github.com/peterhry/circletype\">circletype</a> - A jQuery plugin that lets you curve type on the web.</li>\n<li><a href=\"https://github.com/freqDec/slabText/\">slabText</a> - A jQuery plugin for producing big, bold &#x26; responsive headlines.</li>\n<li><a href=\"https://github.com/peachananr/simple-text-rotator\">simple-text-rotator</a> - Add a super simple rotating text to your website with little to no markup.</li>\n<li><a href=\"https://github.com/chuckyglitch/novacancy.js\">novacancy.js</a> - Text Neon Golden effect jQuery plug-in.</li>\n<li><a href=\"https://github.com/ghepting/jquery-responsive-text\">jquery-responsive-text</a> - Make your text sizing responsive!</li>\n<li><a href=\"https://github.com/davatron5000/FitText.js\">FitText.js</a> - A jQuery plugin for inflating web type.</li>\n<li><a href=\"https://github.com/davatron5000/Lettering.js\">Lettering.js</a> - A lightweight, easy to use JavaScript <code class=\"language-text\">&lt;span></code> injector for radical Web Typography.</li>\n</ul>\n<h2>Animations</h2>\n<ul>\n<li><a href=\"https://github.com/julianshapiro/velocity\">velocity</a> - Accelerated JavaScript animation.</li>\n<li><a href=\"https://github.com/rstacruz/jquery.transit\">jquery.transit</a> - Super-smooth CSS3 transformations and transitions for jQuery.</li>\n<li><a href=\"https://github.com/impress/impress.js\">impress.js</a> - Make Prezi-like presentations with CSS3 transformations/transitions in an HTML document.</li>\n<li><a href=\"https://github.com/tictail/bounce.js\">bounce.js</a> - Create tasty CSS3 powered animations in no time.</li>\n<li><a href=\"https://github.com/greensock/GreenSock-JS\">GreenSock-JS</a> - High-performance HTML5 animations that work in all major browsers.</li>\n<li><a href=\"https://github.com/EvandroLG/transitionEnd\">TransitionEnd</a> - TransitionEnd is an agnostic and cross-browser library to work with transitioned event.</li>\n<li><a href=\"https://github.com/michaelvillar/dynamics.js\">Dynamic.js</a> - JavaScript library to create physics-based CSS animations.</li>\n<li><a href=\"https://github.com/pstadler/the-cube\">the-cube</a> - The Cube is an experiment with CSS3 transitions.</li>\n<li><a href=\"https://github.com/h5bp/Effeckt.css\">Effeckt.css</a> - A Performant Transitions and Animations Library</li>\n<li><a href=\"https://github.com/daneden/animate.css\">animate.css</a> - A cross-browser library of CSS animations. As easy to use as an easy thing.</li>\n<li><a href=\"https://github.com/jschr/textillate\">textillate</a> - A simple plugin for CSS3 text animations.</li>\n<li><a href=\"https://github.com/visionmedia/move.js\">move.js</a> - CSS3 backed JavaScript animation framework.</li>\n<li><a href=\"https://github.com/LeaVerou/animatable\">animatable</a> - One property, two values, endless possibilities.</li>\n<li><a href=\"https://github.com/peachananr/shuffle-images\">shuffle-images</a> - The Simplest Way to shuffle through images in a Creative Way <a href=\"http://www.thepetedesign.com/demos/shuffle-images_demo.html\">http://www.thepetedesign.com/demos/shuffle-images_demo.html</a></li>\n<li><a href=\"https://github.com/miguel-perez/smoothState.js\">smoothState.js</a> - Unobtrusive page transitions with jQuery. <a href=\"http://smoothstate.com/\">http://smoothstate.com/</a></li>\n<li><a href=\"http://animejs.com\">Anime.js</a> - A JavaScript animation engine <a href=\"http://animejs.com\">http://animejs.com</a>.</li>\n<li><a href=\"http://mojs.io\">Mo.js</a> - Motion graphics toolbelt for the web <a href=\"http://mojs.io\">http://mojs.io</a>.</li>\n<li><a href=\"https://github.com/VincentGarreau/particles.js\">particles.js</a> - A lightweight JavaScript library for creating particles.</li>\n</ul>\n<h2>Image Processing</h2>\n<ul>\n<li><a href=\"https://github.com/davidsonfellipe/lena.js\">lena.js</a> - A Library for image processing with filters and util functions.</li>\n<li><a href=\"https://github.com/nodeca/pica\">pica</a> - High quality image resize (with fast Lanczos filter, implemented in pure JS).</li>\n<li><a href=\"https://github.com/fengyuanchen/cropper\">cropper</a> - A simple jQuery image cropping plugin.</li>\n</ul>\n<h2>ES6</h2>\n<ul>\n<li><a href=\"https://github.com/lukehoban/es6features\">es6features</a> - Overview of ECMAScript 6 features.</li>\n<li><a href=\"https://github.com/rse/es6-features\">es6-features</a> - ECMAScript 6: Feature Overview &#x26; Comparison.</li>\n<li><a href=\"https://github.com/DrkSephy/es6-cheatsheet\">es6-cheatsheet</a> - ES2015 [ES6] cheatsheet containing tips, tricks, best practices and code snippets.</li>\n<li><a href=\"http://kangax.github.io/compat-table/es6/\">ECMAScript 6 compatibility table</a> - Compatibility tables for all ECMAScript 6 features on a variety of environments.</li>\n<li><a href=\"https://github.com/babel/babel\">Babel (Formerly 6to5)</a> - Turn ES6+ code into vanilla ES5 with no runtime.</li>\n<li><a href=\"https://github.com/google/traceur-compiler\">Traceur compiler</a> - ES6 features > ES5. Includes classes, generators, promises, destructuring patterns, default parameters &#x26; more.</li>\n</ul>\n<h2>Generators</h2>\n<ul>\n<li><a href=\"https://github.com/gatsbyjs/gatsby\">Gatsby.js</a> - React-based static site generator.</li>\n<li><a href=\"https://github.com/gridsome/gridsome\">Gridsome</a> - Vue-powered static site generator.</li>\n</ul>\n<h2>SDK</h2>\n<ul>\n<li><a href=\"https://github.com/huei90/javascript-sdk-design\">javascript-sdk-design</a> - JavaScript SDK design guide extracted from work and personal experience</li>\n<li><a href=\"https://github.com/loverajoel/spotify-sdk\">Spotify SDK</a> - Entity oriented SDK to work with the Spotify Web API.</li>\n<li><a href=\"https://github.com/square/connect-nodejs-sdk/\">Square Node.js SDK</a> - JavaScript client library for payments and other Square APIs.</li>\n</ul>\n<h2>Misc</h2>\n<ul>\n<li><a href=\"https://github.com/toddmotto/echo\">echo</a> - Lazy-loading images with data-* attributes.</li>\n<li><a href=\"https://github.com/scottjehl/picturefill\">picturefill</a> - A responsive image polyfill for &#x3C;picture>, srcset, sizes.</li>\n<li><a href=\"https://github.com/bestiejs/platform.js\">platform.js</a> - A platform detection library that works on nearly all JavaScript platforms.</li>\n<li><a href=\"https://github.com/bestiejs/json3\">json3</a> - A modern JSON implementation compatible with nearly all JavaScript platforms.</li>\n<li><a href=\"http://gabinaureche.com/logicalornot/\">Logical Or Not</a> - A game about JavaScript specificities.</li>\n<li><a href=\"https://github.com/infusion/BitSet.js\">BitSet.js</a> - A JavaScript Bit-Vector implementation</li>\n<li><a href=\"https://github.com/joshbuddy/spoiler-alert\">spoiler-alert</a> - SPOILER ALERT! A happy little jquery plugin to hide spoilers on your site.</li>\n<li><a href=\"https://github.com/illyism/jquery.vibrate.js\">jquery.vibrate.js</a> - Vibration API Wrappers</li>\n<li><a href=\"https://github.com/javve/list.js\">list.js</a> - Adds search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML.\n<a href=\"http://www.listjs.com\">http://www.listjs.com</a></li>\n<li><a href=\"https://github.com/patrickkunka/mixitup\">mixitup</a> - MixItUp - A Filter &#x26; Sort Plugin.</li>\n<li><a href=\"https://github.com/hootsuite/grid\">grid</a> - Drag and drop library for two-dimensional, resizable and responsive lists.</li>\n<li><a href=\"https://github.com/liabru/jquery-match-height\">jquery-match-height</a> - a responsive equal heights plugin for jQuery.</li>\n<li><a href=\"https://github.com/surveyjs/surveyjs\">survey.js</a> - JavaScript Survey Engine. It uses JSON for survey metadata and results. <a href=\"http://surveyjs.org/\">http://surveyjs.org/</a></li>\n<li><a href=\"https://github.com/sdras/array-explorer\">Array Explorer</a> and <a href=\"https://sdras.github.io/object-explorer/\">Object Explorer</a> - Resources to help figure out what native JavaScript method would be best to use at any given time</li>\n<li><a href=\"https://clipboardjs.com/\">Clipboard.js</a> - \"Copy to clipboard\" without Flash or use of Frameworks.</li>\n<li><a href=\"https://github.com/sindresorhus/ky\">ky</a> - Tiny and elegant HTTP client based on the browser Fetch API.</li>\n<li><a href=\"https://github.com/5anthosh/fcal\">Fcal</a> -  Math expression evaluator</li>\n</ul>\n<h2>Podcasts</h2>\n<ul>\n<li><a href=\"https://javascriptair.com/\">JavaScript Air</a> - The live video broadcast podcast all about JavaScript and the Web platform.</li>\n<li><a href=\"http://www.weboftomorrowpodcast.com/\">Web of Tomorrow</a> - Podcast about JavaScript for beginners.</li>\n<li><a href=\"https://devchat.tv/js-jabber\">JavaScript Jabber</a> - A weekly podcast about JavaScript, including Node.js, Front-End Technologies, Careers, Teams and more.</li>\n</ul>\n<h1>Worth Reading</h1>\n<ul>\n<li><a href=\"https://github.com/getify/You-Dont-Know-JS\">You Don't Know JS</a> - Possibly the best book written on modern JavaScript, completely readable online for free, or can be bought to support the author.</li>\n<li><a href=\"https://github.com/braziljs/js-the-right-way/\">braziljs/js-the-right-way</a> - An easy-to-read, quick reference for JS best practices, accepted coding standards, and links around the Web.</li>\n<li><a href=\"https://github.com/revolunet/JSbooks\">JSbooks</a> - Directory of free JavaScript ebooks.</li>\n<li><a href=\"http://superherojs.com\">Superhero.js</a> - A collection of resources about creating, testing and maintaining a large JavaScript code base.</li>\n<li><a href=\"https://github.com/HugoGiraudel/SJSJ\">SJSJ</a> - Simplified JavaScript Jargon is a community-driven attempt at explaining the loads of buzzwords making the current JavaScript ecosystem in a few simple words.</li>\n<li><a href=\"https://github.com/sarbbottam/write-an-open-source-js-lib\">How to Write an Open Source JavaScript Library</a> - A comprehensive guide through a set of steps to publish a JavaScript open source library.</li>\n<li><a href=\"https://hackr.io/tutorials/learn-javascript\">JavaScript Tutorials</a> - Learn Javascript online from a diverse range of user ranked online tutorials.</li>\n<li><a href=\"https://github.com/getify/Functional-Light-JS\">Functional-Light JavaScript</a> - Pragmatic, balanced FP in JavaScript.</li>\n<li><a href=\"https://github.com/ryanmcdermott/clean-code-javascript\">Clean Code JavaScript</a> - Clean Code concepts adapted for JavaScript.</li>\n</ul>\n<h1>Other Awesome Lists</h1>\n<ul>\n<li><a href=\"https://github.com/sotayamashita/awesome-css\">sotayamashita/awesome-css</a></li>\n<li><a href=\"https://github.com/emijrp/awesome-awesome\">emijrp/awesome-awesome</a></li>\n<li><a href=\"https://github.com/bayandin/awesome-awesomeness\">bayandin/awesome-awesomeness</a></li>\n<li><a href=\"https://github.com/sindresorhus/awesome\">sindresorhus/awesome</a></li>\n<li><a href=\"https://github.com/jnv/lists\">jnv/list</a></li>\n<li><a href=\"https://github.com/gianarb/awesome-angularjs\">gianarb/angularjs</a></li>\n<li><a href=\"https://github.com/peterkokot/awesome-dojo\">peterkokot/awesome-dojo</a></li>\n<li><a href=\"https://github.com/addyosmani/es6-tools\">addyosmani/es6-tools</a></li>\n<li><a href=\"https://github.com/ericdouglas/ES6-Learning\">ericdouglas/ES6-Learning</a></li>\n<li><a href=\"https://github.com/obetomuniz/awesome-webcomponents\">obetomuniz/awesome-webcomponents</a></li>\n<li><a href=\"https://github.com/willianjusten/awesome-svg\">willianjusten/awesome-svg</a></li>\n<li><a href=\"https://github.com/davidsonfellipe/awesome-wpo\">davidsonfellipe/awesome-wpo</a></li>\n<li><a href=\"https://github.com/sadcitizen/awesome-backbone\">instanceofpro/awesome-backbone</a></li>\n<li><a href=\"https://github.com/enaqx/awesome-react\">enaqx/awesome-react</a></li>\n<li><a href=\"https://github.com/bolshchikov/js-must-watch\">bolshchikov/js-must-watch</a></li>\n<li><a href=\"https://github.com/peterkokot/awesome-jquery\">peterkokot/awesome-jquery</a></li>\n<li><a href=\"https://github.com/davidyezsetz/you-might-not-need-jquery-plugins\">davidyezsetz/you-might-not-need-jquery-plugins</a></li>\n<li>\n<p><a href=\"https://github.com/MaximAbramchuck/awesome-interview-questions\">MaximAbramchuck/awesome-interviews</a></p>\n</details\n</li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*S5zCjm6p0WSZJQfT\" alt=\"Photo by Roman Synkevych on Unsplash\" class=\"graf-image\" />\n<figcaption>Photo by <a href=\"https://unsplash.com/@synkevych?utm_source=medium&amp;utm_medium=referral\" class=\"markup--anchor markup--figure-anchor\">Roman Synkevych</a> on <a href=\"https://unsplash.com?utm_source=medium&amp;utm_medium=referral\" class=\"markup--anchor markup--figure-anchor\">Unsplash</a>\n</figcaption>\n</figure>### Web Development\n<ul>\n<li>\n<span id=\"7f87\">\n<a href=\"https://caniuse.com/#home\" class=\"markup--anchor markup--li-anchor\">Check cross-browser compatibility for CSS, JavaScript and HTML</a>\n</span>\n</li>\n<li>\n<span id=\"6491\">\n<a href=\"https://medium.freecodecamp.org/modern-frontend-hacking-cheatsheets-df9c2566c72a\" class=\"markup--anchor markup--li-anchor\">Modern front-end Cheatsheets</a>\n</span>\n</li>\n<li>\n<span id=\"1272\">\n<a href=\"https://stackshare.io/\" class=\"markup--anchor markup--li-anchor\">Check out what your favorite company's stack is</a>\n</span>\n</li>\n<li>\n<span id=\"d228\">\n<a href=\"https://medium.com/coderbyte/a-guide-to-becoming-a-full-stack-developer-in-2017-5c3c08a1600c\" class=\"markup--anchor markup--li-anchor\">A Guide to Becoming a Full-Stack Developer in 2017</a>\n</span>\n</li>\n<li>\n<span id=\"0b32\">\n<a href=\"http://edusagar.com/articles/view/70/What-happens-when-you-type-a-URL-in-browser\" class=\"markup--anchor markup--li-anchor\">What happens when you type a URL into a web browser</a>\n</span>\n</li>\n</ul>\n<h3>JavaScript</h3>\n<ul>\n<li>\n<span id=\"cb55\">\n<a href=\"https://github.com/airbnb/javascript\" class=\"markup--anchor markup--li-anchor\">Airbnb JavaScript Style Guide</a>\n</span>\n</li>\n<li>\n<span id=\"5f22\">\n<a href=\"https://medium.freecodecamp.org/regular-expressions-demystified-regex-isnt-as-hard-as-it-looks-617b55cf787\" class=\"markup--anchor markup--li-anchor\">Regular Expressions Demystified</a>\n</span>\n</li>\n<li>\n<span id=\"1f9e\">\n<a href=\"https://kangax.github.io/compat-table/es6/\" class=\"markup--anchor markup--li-anchor\">ECMAScript compatibility table</a>\n</span>\n</li>\n</ul>\n<h3>GIT</h3>\n<ul>\n<li>\n<span id=\"c612\">\n<a href=\"http://product.hubspot.com/blog/git-and-github-tutorial-for-beginners\" class=\"markup--anchor markup--li-anchor\">HubSpot's Intro to Git/GitHub including Pull Requests &amp; Merging</a>\n</span>\n</li>\n</ul>\n<h3>Express</h3>\n<ul>\n<li>\n<span id=\"f5e1\">\n<a href=\"https://github.com/tanukid/express-starter\" class=\"markup--anchor markup--li-anchor\">Express Starter</a>\n</span>\n</li>\n</ul>\n<h3>Node.js</h3>\n<ul>\n<li>\n<span id=\"3f91\">\n<a href=\"https://medium.com/@thejasonfile/fetch-vs-axios-js-for-making-http-requests-2b261cdd3af5\" class=\"markup--anchor markup--li-anchor\">Fetch vs. Axios.js for making http requests</a> \\#\\# Sequelize</span>\n</li>\n<li>\n<span id=\"b94a\">\n<a href=\"https://www.youtube.com/watch?v=6NKNfXtKk0c\" class=\"markup--anchor markup--li-anchor\">Sequelize: Getting Started</a>\n</span>\n</li>\n<li><span id=\"fe38\">[Sequelize reference by @tmkelly28](<a href=\"https://github.com/tmkelly28/sequelize-reference\">https://github.com/tmkelly28/sequelize-reference</a>)</span></li>\n<li>\n<span id=\"63a1\">\n<a href=\"https://blog.cloudboost.io/docs-for-the-sequelize-docs-querying-edition-aed4bd1273f0\" class=\"markup--anchor markup--li-anchor\">Short but useful Sequelize querying cheatsheet</a>\n</span>\n</li>\n</ul>\n<h3>Study Guides</h3>\n<ul>\n<li>\n<span id=\"06de\">\n<a href=\"https://github.com/ohagert1/Express-Sequelize-Boilerplate-Study-Guide\" class=\"markup--anchor markup--li-anchor\">Express &amp; Sequelize Boilerplate/Study Guide</a>\n</span>\n</li>\n</ul>\n<h3>React</h3>\n<ul>\n<li>\n<span id=\"524d\">\n<a href=\"https://www.youtube.com/channel/UCZkjWyyLvzWeoVWEpRemrDQ\" class=\"markup--anchor markup--li-anchor\">React Casts — Series of React tutorials by Cassio</a>\n</span>\n</li>\n<li>\n<span id=\"4e2f\">\n<a href=\"https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en\" class=\"markup--anchor markup--li-anchor\">React Dev Tool Google Chrome Extension</a>\n</span>\n</li>\n<li>\n<span id=\"f6ec\">\n<a href=\"https://github.com/facebookincubator/create-react-app\" class=\"markup--anchor markup--li-anchor\">create-react-app: Create React apps with no build configuration.</a>\n</span>\n</li>\n<li>\n<span id=\"e294\">\n<a href=\"https://www.javascriptstuff.com/react-starter-projects/\" class=\"markup--anchor markup--li-anchor\">Find the perfect React starter template</a>\n</span>\n</li>\n<li>\n<span id=\"df74\">\n<a href=\"https://github.com/jaredpalmer/formik\" class=\"markup--anchor markup--li-anchor\">Formik — Build forms in React, without the tears 😭</a>\n</span>\n</li>\n</ul>\n<h3>Redux</h3>\n<ul>\n<li>\n<span id=\"3ec4\">\n<a href=\"https://egghead.io/courses/getting-started-with-redux\" class=\"markup--anchor markup--li-anchor\">Getting Started with Redux (free course by Dan Abramov)</a>\n</span>\n</li>\n<li>\n<span id=\"ccfe\">\n<a href=\"https://egghead.io/courses/building-react-applications-with-idiomatic-redux\" class=\"markup--anchor markup--li-anchor\">Building React Applications with Idiomatic Redux (free course by Dan Abramov)</a>\n</span>\n</li>\n<li>\n<span id=\"5cd7\">\n<a href=\"https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en\" class=\"markup--anchor markup--li-anchor\">Redux Dev Tool Chrome Extension</a>\n</span>\n</li>\n</ul>\n<h3>Redux Middleware</h3>\n<ul>\n<li>\n<span id=\"281b\">\n<a href=\"https://github.com/buunguyen/redux-freeze\" class=\"markup--anchor markup--li-anchor\">redux-freeze: avoid accidental in-place mutations of state</a>\n</span>\n</li>\n<li>\n<span id=\"34e9\">\n<a href=\"https://github.com/redux-saga/redux-saga\" class=\"markup--anchor markup--li-anchor\">redux-saga: manage redux side-effects with es6 generators</a>\n</span>\n</li>\n<li>\n<span id=\"7dd0\">\n<a href=\"https://github.com/pburtchaell/redux-promise-middleware\" class=\"markup--anchor markup--li-anchor\">redux-promise-middleware: A thunk alternative with more bells and whistles</a> \\#\\# CSS</span>\n</li>\n<li>\n<span id=\"883f\">\n<a href=\"https://specificity.keegan.st/\" class=\"markup--anchor markup--li-anchor\">Specificity Calculator</a>\n</span>\n</li>\n<li>\n<span id=\"4a83\">\n<a href=\"http://bennettfeely.com/clippy/\" class=\"markup--anchor markup--li-anchor\">Tool for making clip-paths quickly with CSS</a>\n</span>\n</li>\n</ul>\n<h3>Command Line</h3>\n<ul>\n<li>\n<span id=\"ed0b\">\n<a href=\"https://lifehacker.com/5743814/become-a-command-line-ninja-with-these-time-saving-shortcuts\" class=\"markup--anchor markup--li-anchor\">Useful commands</a>\n</span>\n</li>\n<li><span id=\"bf51\">Get your IP address in Mac OSX/Unix: <code class=\"language-text\">ifconfig | grep 'inet '</code></span></li>\n</ul>\n<h3>Atom</h3>\n<ul>\n<li>\n<span id=\"118a\">\n<a href=\"https://gist.github.com/chrissimpkins/5bf5686bae86b8129bee\" class=\"markup--anchor markup--li-anchor\">Atom command cheat sheet</a>\n</span>\n</li>\n</ul>\n<h3>VS Code</h3>\n<ul>\n<li>\n<span id=\"e3ec\">\n<a href=\"https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf\" class=\"markup--anchor markup--li-anchor\">Keystroke cheat sheet</a>\n</span>\n</li>\n<li>\n<span id=\"7f06\">\n<a href=\"https://gist.github.com/tanukid/4ba5d7021a2027362592cbac0a356f58\" class=\"markup--anchor markup--li-anchor\">Daniel's Config</a>\n</span>\n</li>\n</ul>\n<h3>Sublime</h3>\n<ul>\n<li>\n<span id=\"e63f\">\n<a href=\"http://sweetme.at/2013/08/08/sublime-text-keyboard-shortcuts/\" class=\"markup--anchor markup--li-anchor\">Keystroke cheat sheet</a>\n</span>\n</li>\n<li>\n<span id=\"02d2\">\n<a href=\"https://medium.com/beyond-the-manifesto/configuring-sublime-text-3-for-modern-es6-js-projects-6f3fd69e95de\" class=\"markup--anchor markup--li-anchor\">Configuring Sublime Text 3 for Modern ES6 JS Projects</a>\n</span>\n</li>\n</ul>\n<h3>Whiteboard Interviews</h3>\n<ul>\n<li>\n<span id=\"555f\">\n<a href=\"https://www.algoexpert.io/product\" class=\"markup--anchor markup--li-anchor\">algoexpert.io (Made by FSA alumni)</a>\n</span>\n</li>\n<li>\n<span id=\"cb9b\">\n<a href=\"https://github.com/mgechev/javascript-algorithms\" class=\"markup--anchor markup--li-anchor\">JavaScript implementation of popular algorithms and data structures</a>\n</span>\n</li>\n<li>\n<span id=\"ed3d\">\n<a href=\"www.codewars.com\" class=\"markup--anchor markup--li-anchor\">Code Wars</a>\n</span>\n</li>\n<li>\n<span id=\"d0e8\">\n<a href=\"http://www.geeksforgeeks.org/\" class=\"markup--anchor markup--li-anchor\">Geeks for Geeks</a>\n</span>\n</li>\n<li>\n<span id=\"adce\">\n<a href=\"https://www.interviewcake.com/\" class=\"markup--anchor markup--li-anchor\">Interview Cake</a>\n</span>\n</li>\n<li>\n<span id=\"9e2d\">\n<a href=\"https://leetcode.com/\" class=\"markup--anchor markup--li-anchor\">Leet Code</a>\n</span>\n</li>\n<li>\n<span id=\"3b9d\">\n<a href=\"https://coderbyte.com/\" class=\"markup--anchor markup--li-anchor\">Coder Byte</a>\n</span>\n</li>\n<li>\n<span id=\"b6d5\">\n<a href=\"https://www.hackerrank.com/\" class=\"markup--anchor markup--li-anchor\">Hacker Rank</a>\n</span>\n</li>\n<li>\n<span id=\"6a45\">\n<a href=\"https://www.amazon.com/Cracking-Coding-Interview-Programming-Questions/dp/0984782850/ref=pd_lpo_sbs_14_t_0?_encoding=UTF8&amp;psc=1&amp;refRID=8BB0KRJ073A8CZXTW5PP&amp;dpID=41XgSiYW7dL&amp;preST=_SY291_BO1,204,203,200_QL40_&amp;dpSrc=detail\" class=\"markup--anchor markup--li-anchor\">Cracking the Coding Interview</a>\n</span>\n</li>\n</ul>\n<p>Here's a repo where I hoard resource lists!</p>\n<a href=\"https://github.com/bgoonz/Cumulative-Resource-List.git\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz/Cumulative-Resource-List.git\">\n<strong>bgoonz/Cumulative-Resource-List</strong>\n<br />\n<em>Inspired by Awesome Lists. Contribute to bgoonz/Cumulative-Resource-List development by creating an account on GitHub.</em>github.com</a>\n<a href=\"https://github.com/bgoonz/Cumulative-Resource-List.git\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h2>MOAR!</h2>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*eEDATI6RAaEQw71I.jpg\" class=\"graf-image\" />\n</figure>- <span id=\"84dc\">\n<a href=\"https://bgoonz.github.io/about.html#ansible\" class=\"markup--anchor markup--li-anchor\">Ansible</a>\n</span>\n- <span id=\"1d08\">\n<a href=\"https://bgoonz.github.io/about.html#awesome-lists\" class=\"markup--anchor markup--li-anchor\">Awesome Lists</a>\n</span>\n- <span id=\"958d\">\n<a href=\"https://bgoonz.github.io/about.html#continious-integration\" class=\"markup--anchor markup--li-anchor\">CI/CD</a>\n</span>\n- <span id=\"eee2\">\n<a href=\"https://bgoonz.github.io/about.html#data-science\" class=\"markup--anchor markup--li-anchor\">Data Science</a>\n</span>\n- <span id=\"efef\">\n<a href=\"https://bgoonz.github.io/about.html#docker\" class=\"markup--anchor markup--li-anchor\">Docker</a>\n</span>\n- <span id=\"069b\">\n<a href=\"https://bgoonz.github.io/about.html#dynamodb\" class=\"markup--anchor markup--li-anchor\">DynamoDB</a>\n</span>\n- <span id=\"49cc\">\n<a href=\"https://bgoonz.github.io/about.html#elasticsearch\" class=\"markup--anchor markup--li-anchor\">Elasticsearch</a>\n</span>\n- <span id=\"a53b\">\n<a href=\"https://bgoonz.github.io/about.html#environment-setups\" class=\"markup--anchor markup--li-anchor\">Environment Setups</a>\n</span>\n- <span id=\"e5a2\">\n<a href=\"https://bgoonz.github.io/about.html#epic-github-repos\" class=\"markup--anchor markup--li-anchor\">Epic Github Repos</a>\n</span>\n- <span id=\"3439\">\n<a href=\"https://bgoonz.github.io/about.html#golang\" class=\"markup--anchor markup--li-anchor\">Golang</a>\n</span>\n- <span id=\"4a3d\">\n<a href=\"https://bgoonz.github.io/about.html#grafana\" class=\"markup--anchor markup--li-anchor\">Grafana</a>\n</span>\n- <span id=\"7b62\">\n<a href=\"https://bgoonz.github.io/about.html#great-blogs\" class=\"markup--anchor markup--li-anchor\">Great Blogs</a>\n</span>\n- <span id=\"ad80\">\n<a href=\"https://bgoonz.github.io/about.html#knowledge-base\" class=\"markup--anchor markup--li-anchor\">Knowledge Base</a>\n</span>\n- <span id=\"227d\">\n<a href=\"https://bgoonz.github.io/about.html#kubernetes\" class=\"markup--anchor markup--li-anchor\">Kubernetes</a>\n</span>\n- <span id=\"6ceb\">\n<a href=\"https://bgoonz.github.io/about.html#kubernetes-storage\" class=\"markup--anchor markup--li-anchor\">Kubernetes Storage</a>\n</span>\n- <span id=\"97b6\">\n<a href=\"https://bgoonz.github.io/about.html#machine-learning\" class=\"markup--anchor markup--li-anchor\">Machine Learning</a>\n</span>\n- <span id=\"5b37\">\n<a href=\"https://bgoonz.github.io/about.html#monitoring\" class=\"markup--anchor markup--li-anchor\">Monitoring</a>\n</span>\n- <span id=\"c262\">\n<a href=\"https://bgoonz.github.io/about.html#mongodb\" class=\"markup--anchor markup--li-anchor\">MongoDB</a>\n</span>\n- <span id=\"5857\">\n<a href=\"https://bgoonz.github.io/about.html#programming\" class=\"markup--anchor markup--li-anchor\">Programming</a>\n</span>\n- <span id=\"60a1\">\n<a href=\"https://bgoonz.github.io/about.html#queues\" class=\"markup--anchor markup--li-anchor\">Queues</a>\n</span>\n- <span id=\"2694\">\n<a href=\"https://bgoonz.github.io/about.html#self-hosting\" class=\"markup--anchor markup--li-anchor\">Self Hosting</a>\n</span>\n- <span id=\"d4a4\">\n<a href=\"https://bgoonz.github.io/about.html#email-server-setups\" class=\"markup--anchor markup--li-anchor\">Email Server Setups</a>\n</span>\n- <span id=\"6309\">\n<a href=\"https://bgoonz.github.io/about.html#mailscanner-server-setups\" class=\"markup--anchor markup--li-anchor\">Mailscanner Server Setups</a>\n</span>\n- <span id=\"1c97\">\n<a href=\"https://bgoonz.github.io/about.html#serverless\" class=\"markup--anchor markup--li-anchor\">Serverless</a>\n</span>\n- <span id=\"bafa\">\n<a href=\"https://bgoonz.github.io/about.html#sysadmin-references\" class=\"markup--anchor markup--li-anchor\">Sysadmin References</a>\n</span>\n- <span id=\"5fc4\">\n<a href=\"https://bgoonz.github.io/about.html#vpn\" class=\"markup--anchor markup--li-anchor\">VPN</a>\n</span>\n- <span id=\"81ef\">\n<a href=\"https://bgoonz.github.io/about.html#web-frameworks\" class=\"markup--anchor markup--li-anchor\">Web Frameworks</a>\n</span>\n<h3>Ansible</h3>\n<ul>\n<li>\n<span id=\"abab\">\n<a href=\"https://github.com/zimmertr/Bootstrap-Kubernetes-with-LXC\" class=\"markup--anchor markup--li-anchor\">Kubernetes on LXC with Ansible</a>\n</span>\n</li>\n</ul>\n<h3>Awesome Lists</h3>\n<ul>\n<li>\n<span id=\"4570\">\n<a href=\"https://github.com/exAspArk/awesome-chatops\" class=\"markup--anchor markup--li-anchor\">Awesome ChatOps</a>\n</span>\n</li>\n<li>\n<span id=\"e8b4\">\n<a href=\"https://github.com/binhnguyennus/awesome-scalability\" class=\"markup--anchor markup--li-anchor\">Awesome Scalability</a>\n</span>\n</li>\n<li>\n<span id=\"9050\">\n<a href=\"https://github.com/drone/awesome-drone\" class=\"markup--anchor markup--li-anchor\">Awesome Drone</a>\n</span>\n</li>\n</ul>\n<h3>Epic Github Repos</h3>\n<ul>\n<li>\n<span id=\"1cb2\">\n<a href=\"https://github.com/mlabouardy?tab=repositories\" class=\"markup--anchor markup--li-anchor\">mlabouardy</a>\n</span>\n</li>\n</ul>\n<h3>Authentication</h3>\n<ul>\n<li>\n<span id=\"19fa\">\n<a href=\"https://mapr.com/blog/how-secure-elasticsearch-and-kibana/\" class=\"markup--anchor markup--li-anchor\">Nginx ES and Kibana Proxy with LDAP</a>\n</span>\n</li>\n</ul>\n<h3>Data Science</h3>\n<ul>\n<li>\n<span id=\"cf4c\">\n<a href=\"https://github.com/bulutyazilim/awesome-datascience\" class=\"markup--anchor markup--li-anchor\">bulutyazilim — datascience awesome list</a>\n</span>\n</li>\n</ul>\n<h3>Grafana</h3>\n<ul>\n<li>\n<span id=\"db81\">\n<a href=\"https://github.com/mlabouardy/grafana-dashboards\" class=\"markup--anchor markup--li-anchor\">Grafana Dashboards @mlabouardy</a>\n</span>\n</li>\n</ul>\n<h3>Docker</h3>\n<h4>Deploy Stacks to your Swarm: 🐳 ❤️</h4>\n<p>Logging:</p>\n<ul>\n<li>\n<span id=\"b7ff\">\n<a href=\"https://github.com/shazChaudhry/docker-elastic\" class=\"markup--anchor markup--li-anchor\">shazChaudhry Swarm GELF Stack</a>\n</span>\n</li>\n</ul>\n<p>Metrics:</p>\n<ul>\n<li>\n<span id=\"52cc\">\n<a href=\"https://github.com/stefanprodan/swarmprom\" class=\"markup--anchor markup--li-anchor\">StefanProdan — Prometheus, Grafana, cAdvisor, Node Exporter and Alert Manager</a>\n</span>\n</li>\n<li>\n<span id=\"d0e5\">\n<a href=\"https://github.com/mlabouardy/swarm-tick\" class=\"markup--anchor markup--li-anchor\">Mlabouardy — Telegraf, InfluxDB, Chronograf, Kapacitor &amp; Slack</a>\n</span>\n</li>\n</ul>\n<h4>Awesome Docker Repos</h4>\n<ul>\n<li>\n<span id=\"8b0f\">\n<a href=\"https://github.com/jessfraz/dockerfiles\" class=\"markup--anchor markup--li-anchor\">Jess's Dockerfiles</a>\n</span>\n</li>\n<li>\n<span id=\"46e9\">\n<a href=\"https://github.com/firecat53/dockerfiles\" class=\"markup--anchor markup--li-anchor\">Firecat53's Dockerfiles</a>\n</span>\n</li>\n</ul>\n<h4>RaspberryPi ARM Images:</h4>\n<ul>\n<li>\n<span id=\"1cd6\">\n<a href=\"https://hub.docker.com/r/arm32v6/alpine/\" class=\"markup--anchor markup--li-anchor\">arm32v6/alpine:edge</a>\n</span>\n</li>\n<li>\n<span id=\"c5c2\">\n<a href=\"https://hub.docker.com/r/arm32v6/golang/\" class=\"markup--anchor markup--li-anchor\">arm32v6/golang:alpine</a>\n</span>\n</li>\n<li>\n<span id=\"1b14\">\n<a href=\"https://hub.docker.com/r/arm32v6/haproxy/\" class=\"markup--anchor markup--li-anchor\">arm32v6/haproxy:alpine</a>\n</span>\n</li>\n<li>\n<span id=\"a39c\">\n<a href=\"https://hub.docker.com/r/arm32v6/node/\" class=\"markup--anchor markup--li-anchor\">arm32v6/node:alpine</a>\n</span>\n</li>\n<li>\n<span id=\"80fb\">\n<a href=\"https://hub.docker.com/r/arm32v6/openjdk/\" class=\"markup--anchor markup--li-anchor\">arm32v6/openjdk:alpine</a>\n</span>\n</li>\n<li>\n<span id=\"13b3\">\n<a href=\"https://hub.docker.com/r/arm32v6/postgres/\" class=\"markup--anchor markup--li-anchor\">arm32v6/postgres:alpine</a>\n</span>\n</li>\n<li>\n<span id=\"8a43\">\n<a href=\"https://hub.docker.com/r/arm32v6/python/\" class=\"markup--anchor markup--li-anchor\">arm32v6/python:2.7-alpine3.6</a>\n</span>\n</li>\n<li>\n<span id=\"ef75\">\n<a href=\"https://hub.docker.com/r/arm32v6/python/\" class=\"markup--anchor markup--li-anchor\">arm32v6/python:3.6-alpine3.6</a>\n</span>\n</li>\n<li>\n<span id=\"846e\">\n<a href=\"https://hub.docker.com/r/arm32v6/rabbitmq/\" class=\"markup--anchor markup--li-anchor\">arm32v6/rabbitmq:alpine</a>\n</span>\n</li>\n<li>\n<span id=\"bfdc\">\n<a href=\"https://hub.docker.com/r/arm32v6/redis/\" class=\"markup--anchor markup--li-anchor\">arm32v6/redis:alpine</a>\n</span>\n</li>\n<li>\n<span id=\"b879\">\n<a href=\"https://hub.docker.com/r/arm32v6/ruby/\" class=\"markup--anchor markup--li-anchor\">arm32v6/ruby:alpine3.6</a>\n</span>\n</li>\n<li>\n<span id=\"3cbe\">\n<a href=\"https://hub.docker.com/r/arm32v6/tomcat/\" class=\"markup--anchor markup--li-anchor\">arm32v6/tomcat:alpine</a>\n</span>\n</li>\n<li>\n<span id=\"18e7\">\n<a href=\"https://hub.docker.com/r/arm32v6/traefik/\" class=\"markup--anchor markup--li-anchor\">arm32v6/traefik:latest</a>\n</span>\n</li>\n<li>\n<span id=\"502c\">\n<a href=\"https://hub.docker.com/r/arm32v7/debian/\" class=\"markup--anchor markup--li-anchor\">arm32v7/debian:lates</a>\n</span>\n</li>\n<li>\n<span id=\"c976\">\n<a href=\"https://hub.docker.com/r/hypriot/rpi-redis/\" class=\"markup--anchor markup--li-anchor\">hypriot/rpi-redis</a>\n</span>\n</li>\n<li>\n<span id=\"5c87\">\n<a href=\"https://github.com/jixer/rpi-mongo\" class=\"markup--anchor markup--li-anchor\">jixer/rpi-mongo</a>\n</span>\n</li>\n<li>\n<span id=\"15e1\">\n<a href=\"https://github.com/alexellis/docker-arm/tree/master/images/armhf\" class=\"markup--anchor markup--li-anchor\">alexellis/armhf</a>\n</span>\n</li>\n<li>\n<span id=\"578c\">\n<a href=\"https://github.com/zeiot\" class=\"markup--anchor markup--li-anchor\">zeiot: rpi-prometheus stack</a>\n</span>\n</li>\n<li>\n<span id=\"0ce9\">\n<a href=\"https://hub.docker.com/u/larmog/\" class=\"markup--anchor markup--li-anchor\">larmog</a>\n</span>\n</li>\n<li>\n<span id=\"3662\">\n<a href=\"https://github.com/andresvidal/rpi3-mongodb3\" class=\"markup--anchor markup--li-anchor\">Rpi MongoDB</a>\n</span>\n</li>\n<li>\n<span id=\"2ea6\">\n<a href=\"https://github.com/armswarm\" class=\"markup--anchor markup--li-anchor\">ARM Swarm</a>\n</span>\n</li>\n</ul>\n<h4>Docker Image Repositories</h4>\n<ul>\n<li>\n<span id=\"202f\">\n<a href=\"https://hub.docker.com/u/arm32v6/\" class=\"markup--anchor markup--li-anchor\">Docker Hub: arm32v6</a>\n</span>\n</li>\n<li>\n<span id=\"67a9\">\n<a href=\"https://hub.docker.com/u/armv7/\" class=\"markup--anchor markup--li-anchor\">Docker Hub: armv7</a>\n</span>\n</li>\n<li>\n<span id=\"5e86\">\n<a href=\"https://github.com/luvres/armhf\" class=\"markup--anchor markup--li-anchor\">Github: Luvres Armhf</a>\n</span>\n</li>\n<li>\n<span id=\"3f80\">\n<a href=\"https://github.com/ulsmith/alpine-apache-php7\" class=\"markup--anchor markup--li-anchor\">Apache/PHP7 on Alpine</a>\n</span>\n</li>\n<li>\n<span id=\"6cff\">\n<a href=\"https://github.com/docker-library/tomcat/blob/master/8.0/jre8-alpine/Dockerfile\" class=\"markup--anchor markup--li-anchor\">Tomcat on Alpine</a>\n</span>\n</li>\n<li>\n<span id=\"57cd\">\n<a href=\"https://github.com/jwilder/nginx-proxy\" class=\"markup--anchor markup--li-anchor\">Nginx (jwilder)</a>\n</span>\n</li>\n<li>\n<span id=\"7aa0\">\n<a href=\"https://github.com/smebberson/docker-alpine\" class=\"markup--anchor markup--li-anchor\">Alpine Images (smebberson)</a>\n</span>\n</li>\n<li>\n<span id=\"6e95\">\n<a href=\"https://hub.docker.com/u/sameersbn/\" class=\"markup--anchor markup--li-anchor\">SameerSbn</a>\n</span>\n</li>\n<li>\n<span id=\"d74c\">\n<a href=\"https://hub.docker.com/u/linuxserver/\" class=\"markup--anchor markup--li-anchor\">Linuxserver.io</a>\n</span>\n</li>\n<li>\n<span id=\"54e0\">\n<a href=\"https://hub.docker.com/r/nimmis/alpine-apache-php5/\" class=\"markup--anchor markup--li-anchor\">Apache-PHP5</a>\n</span>\n</li>\n<li>\n<span id=\"ea4c\">\n<a href=\"https://github.com/harobed/docker-php-ssmtp\" class=\"markup--anchor markup--li-anchor\">Apache-PHP-Email</a>\n</span>\n</li>\n</ul>\n<h4>Docker-Awesome-Lists</h4>\n<ul>\n<li>\n<span id=\"b67a\">\n<a href=\"https://github.com/AdamBien/docklands\" class=\"markup--anchor markup--li-anchor\">Java Docker Services</a>\n</span>\n</li>\n<li>\n<span id=\"158f\">\n<a href=\"https://gist.github.com/shouse/a14c44e97a2cd2a1f030\" class=\"markup--anchor markup--li-anchor\">shouse Docker Awesome List</a>\n</span>\n</li>\n</ul>\n<h4>Docker Blogs:</h4>\n<ul>\n<li>\n<span id=\"5e06\">\n<a href=\"https://hub.docker.com/r/emilevauge/whoami/\" class=\"markup--anchor markup--li-anchor\">Whoami used in Traefik Docs</a>\n</span>\n</li>\n<li>\n<span id=\"3fd6\">\n<a href=\"https://github.com/spartakode/my-docker-repos/blob/master/sqlite3/Dockerfile\" class=\"markup--anchor markup--li-anchor\">Sqlite with Docker</a>\n</span>\n</li>\n<li>\n<span id=\"433f\">\n<a href=\"https://github.com/mookjp/rails-docker-example\" class=\"markup--anchor markup--li-anchor\">Rails with Postgres and Redis</a>\n</span>\n</li>\n<li>\n<span id=\"ff65\">\n<a href=\"https://testdriven.io/asynchronous-tasks-with-flask-and-redis-queue\" class=\"markup--anchor markup--li-anchor\">Async Tasks with Flask and Redis</a>\n</span>\n</li>\n<li>\n<span id=\"e4f4\">\n<a href=\"https://github.com/davidmukiibi/docker-flask\" class=\"markup--anchor markup--li-anchor\">Flask and Postgres</a>\n</span>\n</li>\n<li>\n<span id=\"2935\">\n<a href=\"http://ict.renevdmark.nl/2016/07/05/elastic-beats-on-raspberry-pi/\" class=\"markup--anchor markup--li-anchor\">Elastic Beats on RaspberryPi</a>\n</span>\n</li>\n</ul>\n<h4>Docker Storage</h4>\n<ul>\n<li>\n<span id=\"a2ce\">\n<a href=\"https://github.com/rancher/convoy\" class=\"markup--anchor markup--li-anchor\">Rancher Convoy</a>\n</span>\n</li>\n<li>\n<span id=\"118f\">\n<a href=\"https://flocker.readthedocs.io/en/latest/flocker-features/storage-backends.html#supported-backends\" class=\"markup--anchor markup--li-anchor\">Flocker</a>\n</span>\n</li>\n<li>\n<span id=\"2312\">\n<a href=\"http://node.mu/2017/06/30/scaleio-on-ubuntu-xenial/\" class=\"markup--anchor markup--li-anchor\">EMC ScaleIO</a>\n</span>\n</li>\n<li>\n<span id=\"0ab0\">\n<a href=\"https://github.com/lucj/swarm-rexray-ceph\" class=\"markup--anchor markup--li-anchor\">RexRay Ceph with Ansible</a>\n</span>\n</li>\n<li>\n<span id=\"f428\">\n<a href=\"http://containx.io/\" class=\"markup--anchor markup--li-anchor\">ContainX</a>\n</span>\n</li>\n</ul>\n<h4>OpenFaas:</h4>\n<ul>\n<li>\n<span id=\"da90\">\n<a href=\"https://github.com/openfaas/faas/releases\" class=\"markup--anchor markup--li-anchor\">FaaS Releases</a>\n</span>\n</li>\n<li>\n<span id=\"3af4\">\n<a href=\"https://github.com/openfaas/workshop\" class=\"markup--anchor markup--li-anchor\">FaaS Workshop</a>\n</span>\n</li>\n</ul>\n<h4>Prometheus / Grafana on Swarm:</h4>\n<ul>\n<li>\n<span id=\"f482\">\n<a href=\"https://github.com/stefanprodan/swarmprom\" class=\"markup--anchor markup--li-anchor\">StefanProdan — SwarmProm</a>\n</span>\n</li>\n<li>\n<span id=\"6ded\">\n<a href=\"https://medium.com/@soumyadipde/monitoring-in-docker-stacks-its-that-easy-with-prometheus-5d71c1042443\" class=\"markup--anchor markup--li-anchor\">Monitoring with Prometheus</a>\n</span>\n</li>\n<li>\n<span id=\"2631\">\n<a href=\"https://github.com/uschtwill/docker_monitoring_logging_alerting\" class=\"markup--anchor markup--li-anchor\">UschtWill — Prometheus Grafana Elastalert</a>\n</span>\n</li>\n<li>\n<span id=\"2849\">\n<a href=\"https://github.com/chmod666org/docker-swarm-prometheus\" class=\"markup--anchor markup--li-anchor\">Chmod-Org Promethus with Blackbox</a>\n</span>\n</li>\n<li>\n<span id=\"3995\">\n<a href=\"https://finestructure.co/blog/2016/5/16/monitoring-with-prometheus-grafana-docker-part-1\" class=\"markup--anchor markup--li-anchor\">Finestructure: Prometheus Tutorial</a>\n</span>\n</li>\n</ul>\n<h3>Logging / Kibana / Beats</h3>\n<h3>Libraries</h3>\n<ul>\n<li>\n<span id=\"b055\">\n<a href=\"https://github.com/Delgan/loguru\" class=\"markup--anchor markup--li-anchor\">Loguru</a> | <a href=\"https://gist.github.com/M0r13n/0b8c62c603fdbc98361062bd9ebe8153\" class=\"markup--anchor markup--li-anchor\">Flask Example with Loguru</a>\n</span>\n</li>\n</ul>\n<h3>Frameworks</h3>\n<ul>\n<li>\n<span id=\"8e4c\">\n<a href=\"https://github.com/shazChaudhry/docker-elastic\" class=\"markup--anchor markup--li-anchor\">shazChaudhry Swarm GELF Stack</a>\n</span>\n</li>\n</ul>\n<h3>Continious Integration:</h3>\n<h4>Circle-CI</h4>\n<ul>\n<li>\n<span id=\"0eac\">\n<a href=\"https://circleci.com/docs/1.0/language-php/\" class=\"markup--anchor markup--li-anchor\">PHP with Circle-CI</a>\n</span>\n</li>\n</ul>\n<h4>Concourse</h4>\n<ul>\n<li>\n<span id=\"3f92\">\n<a href=\"https://concourse.ci/docker-repository.html\" class=\"markup--anchor markup--li-anchor\">Setup Concourse Environment with Docker</a>\n</span>\n</li>\n<li>\n<span id=\"4284\">\n<a href=\"https://blog.anynines.com/getting-started-with-concourse-ci-and-docker/\" class=\"markup--anchor markup--li-anchor\">Getting Started with Concourse and Docker</a>\n</span>\n</li>\n<li>\n<span id=\"7536\">\n<a href=\"https://github.com/pivotalservices/concourse-pipeline-samples/tree/master/concourse-pipeline-patterns/gated-pipelines\" class=\"markup--anchor markup--li-anchor\">Concourse Gated Pipelines</a>\n</span>\n</li>\n<li>\n<span id=\"1a92\">\n<a href=\"https://github.com/EugenMayer/concourseci-server-boilerplate\" class=\"markup--anchor markup--li-anchor\">Concourse Boilerplate</a>\n</span>\n</li>\n</ul>\n<h4>Jenkins</h4>\n<ul>\n<li>\n<span id=\"e55e\">\n<a href=\"https://modess.io/jenkins-php/\" class=\"markup--anchor markup--li-anchor\">Modess — PHP with Jenkins</a>\n</span>\n</li>\n<li>\n<span id=\"e077\">\n<a href=\"https://code.tutsplus.com/tutorials/setting-up-continuous-integration-continuous-deployment-with-jenkins--cms-21511\" class=\"markup--anchor markup--li-anchor\">CI/CD Nodejs Tutorial with Jenkins</a>\n</span>\n</li>\n<li>\n<span id=\"8663\">\n<a href=\"https://medium.com/@mosheezderman/how-to-set-up-ci-cd-pipeline-for-a-node-js-app-with-jenkins-c51581cc783c\" class=\"markup--anchor markup--li-anchor\">CI/CD Nodejs Tutorial with Jenkins @medium</a>\n</span>\n</li>\n<li>\n<span id=\"c17d\">\n<a href=\"https://github.com/shazChaudhry/docker-swarm-mode\" class=\"markup--anchor markup--li-anchor\">Epic CICD workflow with Jenkins, Gitlab, Sonar, Nexus</a>\n</span>\n</li>\n</ul>\n<h4>SwarmCi</h4>\n<ul>\n<li>\n<span id=\"ca48\">\n<a href=\"https://github.com/ghostsquad/swarmci\" class=\"markup--anchor markup--li-anchor\">SwarmCI</a>\n</span>\n</li>\n</ul>\n<h4>Travis-CI</h4>\n<ul>\n<li>\n<span id=\"5050\">\n<a href=\"https://docs.travis-ci.com/user/getting-started/\" class=\"markup--anchor markup--li-anchor\">Getting Started with Travis-CI (Original Docs)</a>\n</span>\n</li>\n<li>\n<span id=\"1f71\">\n<a href=\"https://github.com/dwyl/learn-travis\" class=\"markup--anchor markup--li-anchor\">Getting Started with Travis-CI (dwyl — nodejs)</a>\n</span>\n</li>\n<li>\n<span id=\"12a1\">\n<a href=\"https://matthewmoisen.com/blog/how-to-set-up-travis-ci-with-github-for-a-python-project/\" class=\"markup--anchor markup--li-anchor\">Blog Site with Travis-CI (Python)</a>\n</span>\n</li>\n<li>\n<span id=\"74dd\">\n<a href=\"https://github.com/softwaresaved/build_and_test_examples/blob/master/travis/HelloWorld.md\" class=\"markup--anchor markup--li-anchor\">Build Tests with Python on Travis-CI</a>\n</span>\n</li>\n<li>\n<span id=\"0c8a\">\n<a href=\"https://www.raywenderlich.com/109418/travis-ci-tutorial\" class=\"markup--anchor markup--li-anchor\">Moving app with Travis-CI</a>\n</span>\n</li>\n</ul>\n<h4>LambCI</h4>\n<ul>\n<li>\n<span id=\"5a62\">\n<a href=\"https://github.com/lambci/lambci\" class=\"markup--anchor markup--li-anchor\">LambCI</a>\n</span>\n</li>\n</ul>\n<h3>DynamoDB</h3>\n<h4>DynamoDB Docs</h4>\n<ul>\n<li>\n<span id=\"f776\">\n<a href=\"https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SQLtoNoSQL.ReadData.Query.html\" class=\"markup--anchor markup--li-anchor\">AWS DynamoDB: SQL to NoSQL</a>\n</span>\n</li>\n</ul>\n<h4>DynamoDB Best Practices</h4>\n<ul>\n<li>\n<span id=\"db69\">\n<a href=\"https://aws.amazon.com/blogs/database/choosing-the-right-dynamodb-partition-key/\" class=\"markup--anchor markup--li-anchor\">Choosing the Right Partition Key</a>\n</span>\n</li>\n<li>\n<span id=\"6d4c\">\n<a href=\"https://cloudacademy.com/blog/amazon-dynamodb-ten-things/\" class=\"markup--anchor markup--li-anchor\">10 Things you should know</a>\n</span>\n</li>\n</ul>\n<h4>DynamoDB General Info</h4>\n<ul>\n<li>\n<span id=\"1006\">\n<a href=\"https://medium.com/@yaofei/understand-dynamodb-b278f718ddb8\" class=\"markup--anchor markup--li-anchor\">Understanding DynamoDB</a>\n</span>\n</li>\n</ul>\n<h3>Elasticsearch</h3>\n<h4>Elasticsearch Documentation</h4>\n<ul>\n<li>\n<span id=\"4493\">\n<a href=\"https://www.elastic.co/guide/en/elasticsearch/reference/current/general-recommendations.html\" class=\"markup--anchor markup--li-anchor\">General Recommendation</a>\n</span>\n</li>\n<li>\n<span id=\"8921\">\n<a href=\"https://www.elastic.co/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster\" class=\"markup--anchor markup--li-anchor\">How Many Shards in my Cluster</a>\n</span>\n</li>\n<li>\n<span id=\"8e3f\">\n<a href=\"https://www.elastic.co/blog/managing-time-based-indices-efficiently\" class=\"markup--anchor markup--li-anchor\">Managing Time-Based Indices Efficiently</a>\n</span>\n</li>\n<li>\n<span id=\"bdc6\">\n<a href=\"https://bonsai.io/2016/01/11/ideal-elasticsearch-cluster\" class=\"markup--anchor markup--li-anchor\">Elasticsearch Best Practices (Bonsai.io)</a>\n</span>\n</li>\n<li>\n<span id=\"300c\">\n<a href=\"https://aws.amazon.com/premiumsupport/knowledge-center/elasticsearch-scale-up/\" class=\"markup--anchor markup--li-anchor\">AWS ES — Scaling up my Domain</a>\n</span>\n</li>\n</ul>\n<h4>Elasticsearch Cheetsheets:</h4>\n<ul>\n<li>\n<span id=\"1637\">\n<a href=\"https://gist.github.com/ruanbekker/e8a09604b14f37e8d2f743a87b930f93\" class=\"markup--anchor markup--li-anchor\">My ES Cheatsheet</a>\n</span>\n</li>\n</ul>\n<h4>Elasticsearch Blogs</h4>\n<ul>\n<li>\n<span id=\"0f1a\">\n<a href=\"https://qbox.io/blog/maximize-guide-elasticsearch-indexing-performance-part-1\" class=\"markup--anchor markup--li-anchor\">Maximize Elasticsearch Indexing Performance</a>\n</span>\n</li>\n<li>\n<span id=\"b16a\">\n<a href=\"https://qbox.io/blog/authoritative-guide-elasticsearch-performance-tuning-part-1\" class=\"markup--anchor markup--li-anchor\">Autoritative Guide to ES Performance Tuning</a>\n</span>\n</li>\n<li>\n<span id=\"a39b\">\n<a href=\"https://opendistro.github.io/for-elasticsearch-docs/docs/elasticsearch/full-text/\" class=\"markup--anchor markup--li-anchor\">Full text Search Queries</a>\n</span>\n</li>\n<li>\n<span id=\"e4d6\">\n<a href=\"https://okfnlabs.org/blog/2013/07/01/elasticsearch-query-tutorial.html\" class=\"markup--anchor markup--li-anchor\">Query Elasticsearch</a>\n</span>\n</li>\n</ul>\n<h4>Elasticsearch Tools</h4>\n<ul>\n<li>\n<span id=\"daeb\">\n<a href=\"https://github.com/mallocator/Elasticsearch-Exporter\" class=\"markup--anchor markup--li-anchor\">Export Data from ES to ES</a>\n</span>\n</li>\n</ul>\n<h3>Environment Setups:</h3>\n<ul>\n<li>\n<span id=\"efec\">\n<a href=\"https://medium.com/aishik/install-golang-the-right-way-4743fee9255f\" class=\"markup--anchor markup--li-anchor\">Golang</a>\n</span>\n</li>\n</ul>\n<h3>Knowledge Base</h3>\n<h3>KB HTTPS</h3>\n<ul>\n<li>\n<span id=\"b222\">\n<a href=\"https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https\" class=\"markup--anchor markup--li-anchor\">How does HTTPS work (Miguel Grinberg)</a>\n</span>\n</li>\n</ul>\n<h3>Kubernetes</h3>\n<ul>\n<li>\n<span id=\"aafa\">\n<a href=\"https://github.com/ramitsurana/awesome-kubernetes/blob/master/README.md\" class=\"markup--anchor markup--li-anchor\">Awesome Kubernetes</a>\n</span>\n</li>\n<li>\n<span id=\"6faa\">\n<a href=\"https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4\" class=\"markup--anchor markup--li-anchor\">Kubernetes Cheatsheet</a>\n</span>\n</li>\n<li>\n<span id=\"7b5a\">\n<a href=\"https://kubernetes.io/blog/2019/07/23/get-started-with-kubernetes-using-python/\" class=\"markup--anchor markup--li-anchor\">Getting Started: Python application on Kubernetes</a>\n</span>\n</li>\n<li>\n<span id=\"8945\">\n<a href=\"https://semaphoreci.com/blog/kubernetes-deployment\" class=\"markup--anchor markup--li-anchor\">Kubernetes Deployments: The Ultimate Guide</a>\n</span>\n</li>\n<li>\n<span id=\"b6dc\">\n<a href=\"https://www.digitalocean.com/community/tutorials/how-to-set-up-a-prometheus-grafana-and-alertmanager-monitoring-stack-on-digitalocean-kubernetes\" class=\"markup--anchor markup--li-anchor\">Prometheus Monitoring Stack with Kubernetes on DO</a>\n</span>\n</li>\n<li>\n<span id=\"7d6a\">\n<a href=\"https://tech.evaneos.com/traefik-as-an-ingress-controller-on-minikube-with-kustomize-helm-a3b2f44a5c2a\" class=\"markup--anchor markup--li-anchor\">Traefik as an Ingress Controller on Minikube</a>\n</span>\n</li>\n<li>\n<span id=\"1a6e\">\n<a href=\"https://itnext.io/traefik-cluster-as-ingress-controller-for-kubernetes-99fa6c34402\" class=\"markup--anchor markup--li-anchor\">Traefik Ingress with Kubernetes</a>\n</span>\n</li>\n<li>\n<span id=\"7ac9\">\n<a href=\"https://medium.com/faun/manually-connect-to-your-kubernetes-cluster-from-the-outside-d852346a7f0a\" class=\"markup--anchor markup--li-anchor\">Manual Connect your Kubernetes from Outside</a>\n</span>\n</li>\n<li>\n<span id=\"8967\">\n<a href=\"https://pascalw.me/blog/2019/07/02/k3s-https-letsencrypt.html\" class=\"markup--anchor markup--li-anchor\">HTTPS Letsencrypt on k3s</a>\n</span>\n</li>\n<li>\n<span id=\"4e91\">\n<a href=\"https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0\" class=\"markup--anchor markup--li-anchor\">Kubernetes: Nodeport vs Loadbalancer</a>\n</span>\n</li>\n<li>\n<span id=\"0df0\">\n<a href=\"https://medium.com/kubernetes-tutorials/simple-management-of-prometheus-monitoring-pipeline-with-the-prometheus-operator-b445da0e0d1a\" class=\"markup--anchor markup--li-anchor\">Prometheus Monitoring Pipeline on Kubernetes</a>\n</span>\n</li>\n<li>\n<span id=\"8eef\">\n<a href=\"https://rancher.com/blog/2018/2018-08-07-cicd-pipeline-k8s-autodevops-rancher-and-gitlab/\" class=\"markup--anchor markup--li-anchor\">Building a Kubernetes CI/CD Pipeline with Rancher</a>\n</span>\n</li>\n<li>\n<span id=\"57cf\">\n<a href=\"https://medium.com/swlh/universal-cicd-pipeline-on-aws-and-k8s-7b4129fac5d4\" class=\"markup--anchor markup--li-anchor\">Building a Kubernetes CI/CD Pipeline with AWS</a>\n</span>\n</li>\n<li>\n<span id=\"d761\">\n<a href=\"https://itnext.io/explore-gitea-drone-ci-cd-on-k3s-4a9e99f8b938\" class=\"markup--anchor markup--li-anchor\">Gitea and Drone CI/CD on k3s</a>\n</span>\n</li>\n<li>\n<span id=\"bde3\">\n<a href=\"https://github.com/openfaas-incubator/openfaas-linkerd2/blob/master/README.md\" class=\"markup--anchor markup--li-anchor\">Serverless with Kubernetes using OpenFaaS and Linkerd2</a>\n</span>\n</li>\n<li>\n<span id=\"236a\">\n<a href=\"https://rancher.com/blog/2019/how-to-manage-kubernetes-with-kubectl/\" class=\"markup--anchor markup--li-anchor\">Managing Kubernetes with kubectl</a>\n</span>\n</li>\n<li>\n<span id=\"b0af\">\n<a href=\"https://gist.github.com/alexellis/a6ee5f094f86987a0dc508442220c52a\" class=\"markup--anchor markup--li-anchor\">OpenFaas Workshop on k3s</a>\n</span>\n</li>\n<li>\n<span id=\"b217\">\n<a href=\"http://collabnix.com/kubernetes-hands-on-lab-4-deploy-application-stack-using-helm-on-play-with-kubernetes-platform/\" class=\"markup--anchor markup--li-anchor\">Kubernetes Hands-On Lab with collabnix</a>\n</span>\n</li>\n<li>\n<span id=\"e717\">\n<a href=\"https://medium.com/asl19-developers/create-readwritemany-persistentvolumeclaims-on-your-kubernetes-cluster-3a8db51f98e3\" class=\"markup--anchor markup--li-anchor\">Create ReadWrite Persistent Volumes on Kubernetes</a>\n</span>\n</li>\n<li>\n<span id=\"fca8\">\n<a href=\"https://medium.com/@mattiaperi/kubernetes-cluster-with-k3s-and-multipass-7532361affa3\" class=\"markup--anchor markup--li-anchor\">Kubernetes Clusters with k3s and multipass</a>\n</span>\n</li>\n</ul>\n<h3>Kubernetes Storage</h3>\n<ul>\n<li>\n<span id=\"4413\">\n<a href=\"https://kadalu.io/docs/quick-start\" class=\"markup--anchor markup--li-anchor\">Kadalu</a>\n</span>\n</li>\n<li>\n<span id=\"eb56\">\n<a href=\"https://rancher.com/docs/k3s/latest/en/storage/\" class=\"markup--anchor markup--li-anchor\">Rancher: Longhorn Storage</a>\n</span>\n</li>\n</ul>\n<h3>Golang</h3>\n<ul>\n<li>\n<span id=\"fc71\">\n<a href=\"https://github.com/brianvoe/gofakeit\" class=\"markup--anchor markup--li-anchor\">Generate Fake Random Data with Golang</a>\n</span>\n</li>\n<li>\n<span id=\"ad3a\">\n<a href=\"https://github.com/hoanhan101/ultimate-go\" class=\"markup--anchor markup--li-anchor\">Ultimate Golang Study Guide</a>\n</span>\n</li>\n</ul>\n<h3>Great Blogs</h3>\n<ul>\n<li>\n<span id=\"6f90\">\n<a href=\"https://www.exratione.com/blog/\" class=\"markup--anchor markup--li-anchor\">Exratione.com</a>\n</span>\n</li>\n<li>\n<span id=\"e5f2\">\n<a href=\"http://joelabrahamsson.com/elasticsearch-101/\" class=\"markup--anchor markup--li-anchor\">Joelabrahamsson.com</a>\n</span>\n</li>\n<li>\n<span id=\"38cc\">\n<a href=\"http://bencane.com/\" class=\"markup--anchor markup--li-anchor\">Benjamin Cane</a>\n</span>\n</li>\n<li>\n<span id=\"2583\">\n<a href=\"http://mherman.org/\" class=\"markup--anchor markup--li-anchor\">Michael Herman</a>\n</span>\n</li>\n<li>\n<span id=\"3e8c\">\n<a href=\"http://charlesleifer.com/\" class=\"markup--anchor markup--li-anchor\">Charles Leifer</a>\n</span>\n</li>\n<li>\n<span id=\"3b5d\">\n<a href=\"https://www.blog.labouardy.com/\" class=\"markup--anchor markup--li-anchor\">Labouardy</a>\n</span>\n</li>\n<li>\n<span id=\"2759\">\n<a href=\"https://tech.marksblogg.com/\" class=\"markup--anchor markup--li-anchor\">Mark's Tech Blog</a>\n</span>\n</li>\n</ul>\n<h3>Linuxkit:</h3>\n<ul>\n<li>\n<span id=\"22a7\">\n<a href=\"https://medium.com/aishik/getting-started-with-linuxkit-and-moby-project-ff7121c4e321\" class=\"markup--anchor markup--li-anchor\">Getting Started with Linuxkit</a>\n</span>\n</li>\n</ul>\n<h3>Logging Stacks</h3>\n<ul>\n<li>\n<span id=\"bc7b\">\n<a href=\"https://github.com/shazChaudhry/docker-elastic\" class=\"markup--anchor markup--li-anchor\">shazChaudhry Swarm GELF Stack</a>\n</span>\n</li>\n</ul>\n<h3>Machine Learning:</h3>\n<ul>\n<li>\n<span id=\"7892\">\n<a href=\"https://github.com/GokuMohandas/practicalAI/blob/master/README.md\" class=\"markup--anchor markup--li-anchor\">PracticalAI</a>\n</span>\n</li>\n</ul>\n<h3>Metrics:</h3>\n<ul>\n<li>\n<span id=\"02a4\">\n<a href=\"https://github.com/avalente/appmetrics\" class=\"markup--anchor markup--li-anchor\">AppMetrics with Flask</a>\n</span>\n</li>\n<li>\n<span id=\"f097\">\n<a href=\"https://github.com/Cue/scales\" class=\"markup--anchor markup--li-anchor\">Scales: Metrics for Python</a>\n</span>\n</li>\n<li>\n<span id=\"1e03\">\n<a href=\"https://pypi.org/project/graphite-pymetrics/\" class=\"markup--anchor markup--li-anchor\">Graphite: Python Flask Metrics</a>\n</span>\n</li>\n</ul>\n<h3>MongoDB:</h3>\n<ul>\n<li>\n<span id=\"a9f4\">\n<a href=\"https://linode.com/docs/databases/mongodb/build-database-clusters-with-mongodb/\" class=\"markup--anchor markup--li-anchor\">Setup MongoDB Cluster</a>\n</span>\n</li>\n<li>\n<span id=\"8450\">\n<a href=\"https://github.com/AD7six/mongo-scripts\" class=\"markup--anchor markup--li-anchor\">MongoDB Scripts</a>\n</span>\n</li>\n<li>\n<span id=\"31a1\">\n<a href=\"https://docs.mongodb.com/v2.4/administration/monitoring/#self-hosted-monitoring-tools\" class=\"markup--anchor markup--li-anchor\">MongoDB Monitoring Tools</a>\n</span>\n</li>\n<li>\n<span id=\"6864\">\n<a href=\"https://studio3t.com/knowledge-base/articles/mongodb-users-roles-explained-part-1/\" class=\"markup--anchor markup--li-anchor\">Roles with MongoDB</a>\n</span>\n</li>\n<li>\n<span id=\"b14c\">\n<a href=\"https://www.guru99.com/mongodb-tutorials.html\" class=\"markup--anchor markup--li-anchor\">Queries: Guru99</a>\n</span>\n</li>\n<li>\n<span id=\"5531\">\n<a href=\"https://blog.exploratory.io/an-introduction-to-mongodb-query-for-beginners-bd463319aa4c\" class=\"markup--anchor markup--li-anchor\">Queries: Exploratory</a>\n</span>\n</li>\n<li>\n<span id=\"ea6e\">\n<a href=\"https://www.tutorialspoint.com/mongodb/mongodb_create_database.htm\" class=\"markup--anchor markup--li-anchor\">Queries: Tutorialspoint</a>\n</span>\n</li>\n<li>\n<span id=\"3fb5\">\n<a href=\"https://gist.github.com/rbekker87/5b4cd9ef36b6ae092a6260ab9e621a43\" class=\"markup--anchor markup--li-anchor\">Queries: MongoDB Cheatsheet</a>\n</span>\n</li>\n</ul>\n<h3>Monitoring</h3>\n<ul>\n<li>\n<span id=\"49fb\">\n<a href=\"https://hackernoon.com/monitor-swarm-cluster-with-tick-stack-slack-3aaa6483d44a\" class=\"markup--anchor markup--li-anchor\">Docker Swarm Monitoring Stack: Telegraf, InfluxDB, Chronograf, Kapacitor</a> <a href=\"https://github.com/mlabouardy/swarm-tick\" class=\"markup--anchor markup--li-anchor\">github source</a>\n</span>\n</li>\n<li>\n<span id=\"7f00\">\n<a href=\"https://stefanprodan.com/2017/docker-swarm-instrumentation-with-prometheus/\" class=\"markup--anchor markup--li-anchor\">Docker Swarm Monitoring Stack: Prometheus, Grafana, cAdvisor, Node Exporter</a> <a href=\"https://github.com/stefanprodan/swarmprom\" class=\"markup--anchor markup--li-anchor\">github source</a>\n</span>\n</li>\n<li>\n<span id=\"be31\">\n<a href=\"https://finestructure.co/blog/2016/5/16/monitoring-with-prometheus-grafana-docker-part-1\" class=\"markup--anchor markup--li-anchor\">Prometheus Grafana Docker</a>\n</span>\n</li>\n<li>\n<span id=\"dc44\">\n<a href=\"https://pierrevincent.github.io/2017/12/prometheus-blog-series-part-1-metrics-and-labels/\" class=\"markup--anchor markup--li-anchor\">Prometheus Blog Seros</a>\n</span>\n</li>\n<li>\n<span id=\"eb7c\">\n<a href=\"https://blog.serverdensity.com/monitor-memcached/\" class=\"markup--anchor markup--li-anchor\">Memcached Monitoring</a>\n</span>\n</li>\n<li>\n<span id=\"eb53\">\n<a href=\"https://raymii.org/s/tutorials/Nagios_Core_4_Installation_on_Ubuntu_12.04.html\" class=\"markup--anchor markup--li-anchor\">Nagios with Nagios Graph</a>\n</span>\n</li>\n<li>\n<span id=\"aaa6\">\n<a href=\"https://medium.com/quiq-blog/better-slack-alerts-from-prometheus-49125c8c672b\" class=\"markup--anchor markup--li-anchor\">Slack Alerts with Prometheus</a>\n</span>\n</li>\n<li>\n<span id=\"6035\">\n<a href=\"https://github.com/deanwilson/docker-compose-prometheus\" class=\"markup--anchor markup--li-anchor\">Local Prometheus Stack</a>\n</span>\n</li>\n<li>\n<span id=\"9144\">\n<a href=\"https://github.com/chmod666org/docker-swarm-prometheus\" class=\"markup--anchor markup--li-anchor\">Docker Swarm Promethus Setup #1</a>\n</span>\n</li>\n<li>\n<span id=\"58e5\">\n<a href=\"https://chmod666.org/2017/08/monitoring-a-docker-swarm-cluster-with-prometheus\" class=\"markup--anchor markup--li-anchor\">Docker Swarm Prometheus Setup #1: Blog</a>\n</span>\n</li>\n<li>\n<span id=\"dfae\">\n<a href=\"https://homelab.business/docker-swarm-monitoring-part-01/\" class=\"markup--anchor markup--li-anchor\">Docker Swarm Promethus Setup #2</a>\n</span>\n</li>\n<li>\n<span id=\"3810\">\n<a href=\"https://medium.com/the-telegraph-engineering/how-prometheus-and-the-blackbox-exporter-makes-monitoring-microservice-endpoints-easy-and-free-of-a986078912ee\" class=\"markup--anchor markup--li-anchor\">Docker Swarm Promethus Setup #3 (Blackbox)</a>\n</span>\n</li>\n<li>\n<span id=\"945a\">\n<a href=\"https://github.com/fzaninotto/uptime\" class=\"markup--anchor markup--li-anchor\">Uptime (fzaninotto)</a>\n</span>\n</li>\n</ul>\n<h3>Monitoring and Alerting</h3>\n<ul>\n<li>\n<span id=\"dccc\">\n<a href=\"https://github.com/arachnys/cabot\" class=\"markup--anchor markup--li-anchor\">Cabot (Lightweight Pagerduty)</a>\n</span>\n</li>\n<li>\n<span id=\"4e80\">\n<a href=\"https://www.nagios.org/\" class=\"markup--anchor markup--li-anchor\">Nagios</a>\n</span>\n</li>\n</ul>\n<h3>Monitoring as Statuspages</h3>\n<ul>\n<li>\n<span id=\"d496\">\n<a href=\"https://github.com/darkpixel/statuspage\" class=\"markup--anchor markup--li-anchor\">Statuspage (darkpixel</a>\n</span>\n</li>\n<li>\n<span id=\"7997\">\n<a href=\"https://github.com/cachethq/Cachet\" class=\"markup--anchor markup--li-anchor\">Cachet</a>\n</span>\n</li>\n</ul>\n<h3>Programming</h3>\n<h4>Golang:</h4>\n<ul>\n<li>\n<span id=\"f63d\">\n<a href=\"http://golangtutorials.blogspot.co.za/2011/05/table-of-contents.html\" class=\"markup--anchor markup--li-anchor\">Golang Tutorials</a>\n</span>\n</li>\n<li>\n<span id=\"a233\">\n<a href=\"https://github.com/golang/go/wiki\" class=\"markup--anchor markup--li-anchor\">Golang Wiki</a>\n</span>\n</li>\n</ul>\n<h4>Java:</h4>\n<ul>\n<li>\n<span id=\"aba9\">\n<a href=\"https://wiki.ruanbekker.com/index.php/Java_Spring_Boot_App_Examples\" class=\"markup--anchor markup--li-anchor\">Java Spring Boot Examples</a>\n</span>\n</li>\n</ul>\n<h4>Python</h4>\n<h4>Ruby:</h4>\n<ul>\n<li>\n<span id=\"935a\">\n<a href=\"https://learnrubythehardway.org/book\" class=\"markup--anchor markup--li-anchor\">Learn Ruby: Learn Ruby the Hard Way</a>\n</span>\n</li>\n<li>\n<span id=\"d022\">\n<a href=\"http://ruby-for-beginners.rubymonstas.org/index.html\" class=\"markup--anchor markup--li-anchor\">Learn Ruby: Ruby for Beginners</a>\n</span>\n</li>\n<li>\n<span id=\"9ff8\">\n<a href=\"https://launchschool.com/books/ruby/read/loops_iterators#forloops\" class=\"markup--anchor markup--li-anchor\">Learn Ruby: Launch School</a>\n</span>\n</li>\n<li>\n<span id=\"bda7\">\n<a href=\"https://gistpages.com/posts/ruby_arrays_insert_append_length_index_remove\" class=\"markup--anchor markup--li-anchor\">Learn Ruby: Arrays</a>\n</span>\n</li>\n<li>\n<span id=\"bb79\">\n<a href=\"https://gorails.com/setup/osx/10.12-sierra\" class=\"markup--anchor markup--li-anchor\">Install Ruby Environment on Mac</a>\n</span>\n</li>\n</ul>\n<h4>Ruby on Rails:</h4>\n<ul>\n<li>\n<span id=\"473f\">\n<a href=\"https://www.railstutorial.org/book/beginning\" class=\"markup--anchor markup--li-anchor\">Tutorial: Ruby On Rails</a>\n</span>\n</li>\n<li>\n<span id=\"2639\">\n<a href=\"http://codingnudge.com/2017/03/17/tutorial-how-to-run-ruby-on-rails-on-docker-part-1/\" class=\"markup--anchor markup--li-anchor\">Tutorial: ROR on Docker</a>\n</span>\n</li>\n</ul>\n<h3>Queues</h3>\n<ul>\n<li>\n<span id=\"2d48\">\n<a href=\"https://github.com/roribio/alpine-sqs\" class=\"markup--anchor markup--li-anchor\">Alpine SQS</a>\n</span>\n</li>\n<li>\n<span id=\"30f2\">\n<a href=\"https://github.com/celery/kombu\" class=\"markup--anchor markup--li-anchor\">Kombu: Messaging library for Python</a>\n</span>\n</li>\n<li>\n<span id=\"da56\">\n<a href=\"https://python-rq.org/\" class=\"markup--anchor markup--li-anchor\">Python Job Queues with Redis</a>\n</span>\n</li>\n</ul>\n<h3>Sysadmin References:</h3>\n<ul>\n<li>\n<span id=\"2ead\">\n<a href=\"https://gist.github.com/ruanbekker/3118ed23c25451132becacd3b974db08\" class=\"markup--anchor markup--li-anchor\">Sysadmin Command References</a>\n</span>\n</li>\n<li>\n<span id=\"69c9\">\n<a href=\"https://medium.com/@chrishantha/linux-performance-observability-tools-19ae2328f87f\" class=\"markup--anchor markup--li-anchor\">Linux Performance Observability Tools</a>\n</span>\n</li>\n<li>\n<span id=\"0009\">\n<a href=\"http://bencane.com/2012/08/06/troubleshooting-high-io-wait-in-linux/\" class=\"markup--anchor markup--li-anchor\">Troubleshooting High IO Wait</a>\n</span>\n</li>\n<li>\n<span id=\"aef7\">\n<a href=\"https://blog.pythian.com/basic-io-monitoring-on-linux/\" class=\"markup--anchor markup--li-anchor\">IO Monitoring in Linux</a>\n</span>\n</li>\n<li>\n<span id=\"5716\">\n<a href=\"http://xiayubin.com/blog/2014/01/29/how-i-use-iostat-and-vmstat-for-performance-analysis/\" class=\"markup--anchor markup--li-anchor\">IOStat and VMStat for Performance Monitoring</a>\n</span>\n</li>\n<li>\n<span id=\"e5bf\">\n<a href=\"https://www.tummy.com/articles/isolating-heavy-load/\" class=\"markup--anchor markup--li-anchor\">Debugging Heavy Load</a>\n</span>\n</li>\n</ul>\n<h3>Self Hosting</h3>\n<h4>Email Server Setups</h4>\n<ul>\n<li>\n<span id=\"8cd4\">\n<a href=\"https://www.exratione.com/2016/05/a-mailserver-on-ubuntu-16-04-postfix-dovecot-mysql/\" class=\"markup--anchor markup--li-anchor\">Extratione: Postfix Dovecot MySQL Virtual Users Postfixadmin</a>\n</span>\n</li>\n<li>\n<span id=\"4409\">\n<a href=\"https://www.exratione.com/2019/02/a-mailserver-on-ubuntu-18-04-postfix-dovecot-mysql/\" class=\"markup--anchor markup--li-anchor\">Extratione: Postfix Dovecot MySQL Virtual Users Postfixadmin (Ubuntu 18)</a>\n</span>\n</li>\n<li>\n<span id=\"bd51\">\n<a href=\"https://linuxize.com/post/set-up-an-email-server-with-postfixadmin/\" class=\"markup--anchor markup--li-anchor\">Linuxsize: Postfix Dovecot MySQL Virtual Users Postfixadmin</a>\n</span>\n</li>\n<li>\n<span id=\"aa71\">\n<a href=\"https://www.howtoforge.com/postfix_mysql_dovecot_dspam_clamav_postgrey_rbl_debian_etch\" class=\"markup--anchor markup--li-anchor\">Howtoforge: Postfix, MySQL, Dovecto, Dspam</a>\n</span>\n</li>\n<li>\n<span id=\"35d1\">\n<a href=\"https://linuxize.com/post/set-up-an-email-server-with-postfixadmin/\" class=\"markup--anchor markup--li-anchor\">Linuxsize: VirtualUsers, MySQL, Postfix, Dovecot</a>\n</span>\n</li>\n</ul>\n<h4>Mailscanner Server Setups</h4>\n<ul>\n<li>\n<span id=\"8498\">\n<a href=\"https://syslint.com/blog/tutorial/how-to-install-and-configure-spamassassin-with-postfix-in-debian-8/\" class=\"markup--anchor markup--li-anchor\">Spamassassin with Debian 8</a>\n</span>\n</li>\n</ul>\n<h4>Financial</h4>\n<ul>\n<li>\n<span id=\"0ba4\">\n<a href=\"https://github.com/firefly-iii/firefly-iii\" class=\"markup--anchor markup--li-anchor\">SelfHosted Firefly</a>\n</span>\n</li>\n</ul>\n<h4>Self Hosting Frameworks:</h4>\n<ul>\n<li>\n<span id=\"0c97\">\n<a href=\"https://sandstorm.io/\" class=\"markup--anchor markup--li-anchor\">Sandstorm</a>\n</span>\n</li>\n</ul>\n<h3>Serverless</h3>\n<ul>\n<li>\n<span id=\"0baf\">\n<a href=\"https://github.com/Miserlou/Zappa\" class=\"markup--anchor markup--li-anchor\">Serverless Zappa</a>\n</span>\n</li>\n<li>\n<span id=\"eb32\">\n<a href=\"https://github.com/faizanbashir/python-ses-dynamodb-contactform\" class=\"markup--anchor markup--li-anchor\">Serverless Contact Form</a>\n</span>\n</li>\n<li>\n<span id=\"67dc\">\n<a href=\"https://github.com/danilop/LambdAuth\" class=\"markup--anchor markup--li-anchor\">Serverless Authentication on AWS (danilop)</a>\n</span>\n</li>\n</ul>\n<h3>VPN:</h3>\n<h4>VPN-Howto:</h4>\n<ul>\n<li>\n<span id=\"d7dc\">\n<a href=\"https://www.cyberciti.biz/faq/howto-setup-openvpn-server-on-ubuntu-linux-14-04-or-16-04-lts/\" class=\"markup--anchor markup--li-anchor\">Ubuntu OpenVPN Script</a>\n</span>\n</li>\n<li>\n<span id=\"2198\">\n<a href=\"https://github.com/hwdsl2/setup-ipsec-vpn\" class=\"markup--anchor markup--li-anchor\">Ubuntu IPSec Script</a>\n</span>\n</li>\n<li>\n<span id=\"7fec\">\n<a href=\"https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-16-04\" class=\"markup--anchor markup--li-anchor\">DO — Setup OpenVPN on Ubuntu</a>\n</span>\n</li>\n<li>\n<span id=\"bbff\">\n<a href=\"https://www.elastichosts.com/blog/linux-l2tpipsec-vpn-client/\" class=\"markup--anchor markup--li-anchor\">Elasticshosts — IPSec VPN</a>\n</span>\n</li>\n<li>\n<span id=\"43f7\">\n<a href=\"https://github.com/bedefaced/vpn-install\" class=\"markup--anchor markup--li-anchor\">PPTP/IPSec/OpenVPN Auto Install</a>\n</span>\n</li>\n</ul>\n<h3>Website Templates</h3>\n<h4>Resume Templates</h4>\n<ul>\n<li>\n<span id=\"7f29\">\n<a href=\"https://github.com/johnmarcampbell/resume-site\" class=\"markup--anchor markup--li-anchor\">johnmarcampbell resume-site</a>\n</span>\n</li>\n</ul>\n<h3>Web Frameworks</h3>\n<h4>Python Flask:</h4>\n<ul>\n<li>\n<span id=\"a98a\">\n<a href=\"https://gist.github.com/dAnjou/2874714\" class=\"markup--anchor markup--li-anchor\">Python Flask Upload Example</a>\n</span>\n</li>\n<li>\n<span id=\"2c23\">\n<a href=\"https://github.com/humiaozuzu/awesome-flask#awesome-flask\" class=\"markup--anchor markup--li-anchor\">Awesome Flask — humiaozuzu</a>\n</span>\n</li>\n<li>\n<span id=\"b710\">\n<a href=\"https://github.com/greyli?tab=repositories\" class=\"markup--anchor markup--li-anchor\">Awesome Flask Apps — Greyli</a>\n</span>\n</li>\n<li>\n<span id=\"f396\">\n<a href=\"https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https\" class=\"markup--anchor markup--li-anchor\">Flask over HTTPS (MG)</a>\n</span>\n</li>\n<li>\n<span id=\"9d33\">\n<a href=\"https://speakerdeck.com/mitsuhiko/advanced-flask-patterns-1\" class=\"markup--anchor markup--li-anchor\">Flask Advanced Patterns</a>\n</span>\n</li>\n<li>\n<span id=\"adf1\">\n<a href=\"https://github.com/tojrobinson/flask-mvc\" class=\"markup--anchor markup--li-anchor\">Flask MVC Boilerplate</a>\n</span>\n</li>\n</ul>\n<h3>If you found this guide helpful feel free to checkout my GitHub/gists where I host similar content:</h3>\n<a href=\"https://gist.github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://gist.github.com/bgoonz\">\n<strong>bgoonz's gists</strong>\n<br />\n<em>Instantly share code, notes, and snippets. Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python |…</em>gist.github.com</a>\n<a href=\"https://gist.github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n<strong>bgoonz — Overview</strong>\n<br />\n<em>Web Developer, Electrical Engineer JavaScript | CSS | Bootstrap | Python | React | Node.js | Express | Sequelize…</em>github.com</a>\n<a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n</a>\n<h3>Ada</h3>\n<ul>\n<li><a href=\"https://learn.adacore.com/courses/intro-to-ada/index.html\">Introduction to Ada</a></li>\n</ul>\n<h3>Android</h3>\n<ul>\n<li><a href=\"https://www.tutlane.com/tutorial/android\">Android Tutorial</a> - tutlane</li>\n<li><a href=\"https://www.javatpoint.com/android-tutorial\">Javatpoint Android Tutorial</a></li>\n</ul>\n<h3>Bash</h3>\n<ul>\n<li><a href=\"https://explainshell.com\">Help messages will explain everything</a></li>\n<li><a href=\"http://www.learnshell.org\">Learn Shell Programming</a></li>\n</ul>\n<h3>C</h3>\n<ul>\n<li><a href=\"http://www.learn-c.org\">Learn C</a></li>\n</ul>\n<h3>C Sharp</h3>\n<ul>\n<li><a href=\"https://www.tutlane.com/tutorial/csharp\">C# Tutorial</a> - tutlane</li>\n<li><a href=\"https://www.w3schools.com/cs\">C# Tutorial</a> - W3Schools</li>\n<li><a href=\"https://codeasy.net/course/csharp_elementary\">Codeasy</a></li>\n<li><a href=\"http://www.learncs.org\">Learn C#</a></li>\n<li><a href=\"https://www.codecademy.com/learn/learn-c-sharp\">Learn C#</a> - Codecademy</li>\n</ul>\n<h3 id=\"cpp\">C++</h3>\n<ul>\n<li><a href=\"https://www.w3schools.com/cpp\">C++ Tutorial</a> - W3Schools</li>\n<li><a href=\"https://github.com/torbjoernk/CppKoans\">CppKoans</a></li>\n</ul>\n<h3>Clojure</h3>\n<ul>\n<li><a href=\"http://www.4clojure.com\">4Clojure - Koans</a></li>\n<li><a href=\"http://clojurekoans.com\">Clojure Koans</a></li>\n<li><a href=\"http://clojurescriptkoans.com\">ClojureScript Koans</a></li>\n<li><a href=\"http://www.tryclj.com\">Try Clojure</a></li>\n</ul>\n<h3>Cloud Computing</h3>\n<ul>\n<li><a href=\"https://run.qwiklabs.com/focuses/269?catalog_rank=%7B%22rank%22%3A3%2C%22num_filters%22%3A1%2C%22has_search%22%3Atrue%7D&#x26;parent=catalog&#x26;search_id=3605949\">AWS API Gateway</a> - <em>registration required</em></li>\n<li><a href=\"https://run.qwiklabs.com/focuses/7782?catalog_rank=%7B%22rank%22%3A6%2C%22num_filters%22%3A1%2C%22has_search%22%3Atrue%7D&#x26;parent=catalog&#x26;search_id=3605942\">AWS Identity and Access Management (IAM)</a> - <em>registration required</em></li>\n<li><a href=\"https://run.qwiklabs.com/focuses/6431?catalog_rank=%7B%22rank%22%3A2%2C%22num_filters%22%3A1%2C%22has_search%22%3Atrue%7D&#x26;parent=catalog&#x26;search_id=3605949\">AWS Lambda</a> - <em>registration required</em></li>\n<li><a href=\"https://run.qwiklabs.com/focuses/7860?catalog_rank=%7B%22rank%22%3A3%2C%22num_filters%22%3A0%2C%22has_search%22%3Atrue%7D&#x26;parent=catalog&#x26;search_id=3597563\">AWS Simple Storage Service (S3)</a> - <em>registration required</em></li>\n<li><a href=\"https://cloud.google.com/training/free-labs/\">Google Cloud Platform</a></li>\n</ul>\n<h3>CoffeeScript</h3>\n<ul>\n<li><a href=\"https://github.com/polarmobile/coffeescript-style-guide/blob/master/README.md\">Coffeescript Style Guide</a></li>\n<li><a href=\"http://autotelicum.github.io/Smooth-CoffeeScript/interactive/interactive-coffeescript.html\">Smooth CoffeeScript, Interactive Edition</a></li>\n</ul>\n<h3>Dart</h3>\n<ul>\n<li><a href=\"https://dart.dev/codelabs\">Dart Official Codelabs</a></li>\n</ul>\n<h3>Erlang</h3>\n<ul>\n<li><a href=\"http://www.tryerlang.org\">Try Erlang</a></li>\n</ul>\n<h3>Git</h3>\n<ul>\n<li><a href=\"https://github.com/git-game/git-game\">git-game</a></li>\n<li><a href=\"https://github.com/git-game/git-game-v2\">git-game-v2</a></li>\n<li><a href=\"https://github.com/Gazler/githug\">Githug</a> (Tutorial in shell)</li>\n<li><a href=\"https://learngitbranching.js.org\">Learn Git Branching</a></li>\n<li><a href=\"https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud\">Learn Git with Bitbucket Cloud</a></li>\n<li><a href=\"http://try.github.io\">Try Git</a></li>\n</ul>\n<h3>GLSL</h3>\n<ul>\n<li><a href=\"https://thebookofshaders.com\">The Book of Shaders</a></li>\n</ul>\n<h3>Go</h3>\n<ul>\n<li><a href=\"https://github.com/cdarwin/go-koans\">Go Koans</a></li>\n<li><a href=\"https://docs.microsoft.com/learn/paths/go-first-steps/\">Start using Go</a> - Microsoft</li>\n<li><a href=\"http://tour.golang.org\">The Go Tutorial</a></li>\n</ul>\n<h3>Haskell</h3>\n<ul>\n<li><a href=\"http://tryhaskell.org\">Try Haskell!</a></li>\n</ul>\n<h3>HTML / CSS</h3>\n<ul>\n<li><a href=\"http://flukeout.github.io\">CSS Diner</a></li>\n<li><a href=\"https://www.w3schools.com/css/\">CSS Tutorial</a> - W3Schools</li>\n<li><a href=\"https://codingfantasy.com/games/flexboxadventure\">Flex Box Adventure</a> - Nick Bull</li>\n<li><a href=\"http://flexboxdefense.com\">Flexbox Defense</a></li>\n<li><a href=\"http://flexboxfroggy.com\">Flexbox Froggy</a></li>\n<li><a href=\"https://www.freecodecamp.org/learn/responsive-web-design/basic-html-and-html5/\">FreeCodeCamp: Responsive Web Design Course</a></li>\n<li><a href=\"https://codingfantasy.com/games/css-grid-attack\">Grid Attack</a> - Nick Bull</li>\n<li><a href=\"https://cssgridgarden.com\">Grid Garden</a></li>\n<li><a href=\"https://www.w3schools.com/html/\">HTML Tutorial</a> - W3Schools</li>\n<li><a href=\"https://knightsoftheflexboxtable.com\">Knights of the Flexbox Table</a></li>\n<li><a href=\"https://dash.generalassemb.ly\">Learn by doing beginner projects</a></li>\n<li><a href=\"https://www.codecademy.com/learn/web\">Learn HTML &#x26; CSS interactively</a></li>\n<li><a href=\"https://www.codecademy.com/learn/make-a-website\">Prototyping a professional website</a></li>\n</ul>\n<h4>Bootstrap</h4>\n<ul>\n<li><a href=\"https://www.tutlane.com/tutorial/bootstrap\">Bootstrap Tutorial</a> - tutlane</li>\n<li><a href=\"https://www.freecodecamp.org/learn/front-end-libraries/bootstrap\">Front End Libraries: Bootstrap</a></li>\n</ul>\n<h3>Java</h3>\n<ul>\n<li><a href=\"http://codingbat.com/java\">CodingBat code practice</a></li>\n<li><a href=\"https://www.codecademy.com/courses/learn-java\">Java at Codecademy</a></li>\n<li><a href=\"https://www.w3schools.com/java\">Java Tutorial</a> - W3Schools</li>\n<li><a href=\"http://www.learnjavaonline.org\">Learn Java</a></li>\n<li><a href=\"https://www.learneroo.com/modules/11\">Learneroo Java tutorial</a></li>\n</ul>\n<h3>JavaScript</h3>\n<ul>\n<li><a href=\"http://www.openjs.com/tutorials/basic_tutorial/\">ABC of JavaScript : An Interactive JavaScript Tutorial</a></li>\n<li><a href=\"https://www.codecademy.com/learn/jquery\">Codecademy jquery track</a></li>\n<li><a href=\"http://stack.formidable.com/es6-interactive-guide/#/\">ES6 Interactive Guide</a></li>\n<li><a href=\"https://github.com/ReactiveX/learnrx\">Functional Programming in Javascript</a></li>\n<li><a href=\"https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript\">JavaScript Algorithms and Data Structures Certification</a></li>\n<li><a href=\"https://www.codecademy.com/learn/javascript\">Javascript interactive tutorial on CodeCademy</a></li>\n<li><a href=\"http://www.codermania.com/javascript/lesson/1a/hello-world\">JavaScript interactive tutorial on CoderMania</a></li>\n<li><a href=\"https://www.w3schools.com/js\">JavaScript Tutorial</a> - W3Schools</li>\n<li><a href=\"https://github.com/sethvincent/javascripting\">Javascripting</a></li>\n<li><a href=\"http://www.learn-js.org\">Learn JavaScript</a></li>\n<li><a href=\"http://learn.knockoutjs.com\">Learn knockout.js</a></li>\n<li><a href=\"https://grasshopper.app\">Learn to Code for Free - Grasshopper</a></li>\n<li><a href=\"http://ejohn.org/apps/learn/\">Learning Advanced JavaScript</a></li>\n<li><a href=\"http://try.jquery.com\">Try jQuery</a></li>\n</ul>\n<h4>Angular.js</h4>\n<ul>\n<li><a href=\"http://www.angularjsbook.com\">Angular Basics</a></li>\n<li><a href=\"https://www.w3schools.com/angular/\">Angular Tutorial</a> - W3Schools</li>\n<li><a href=\"http://nicholasjohnson.com/angular-book/\">AngularJS - Step by Logical Step</a></li>\n<li><a href=\"https://www.tutlane.com/tutorial/angularjs\">AngularJS Tutorial</a> - tutlane</li>\n<li><a href=\"https://egghead.io\">egghead.io: Learn AngularJS with Tutorial Videos &#x26; Training</a></li>\n<li><a href=\"http://www.learn-angular.org\">Learn AngularJS with free interactive lessons</a></li>\n</ul>\n<h4>jQuery</h4>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/learn/front-end-libraries/jquery\">Front End Libraries: jQuery</a></li>\n</ul>\n<h4>React</h4>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/learn/front-end-libraries/react\">Front End Libraries: React</a></li>\n<li><a href=\"https://react-tutorial.app\">React Tutorial</a></li>\n</ul>\n<h3>Kotlin</h3>\n<ul>\n<li><a href=\"https://kotlinlang.org/docs/tutorials/\">Kotlin tutorial</a></li>\n</ul>\n<h3>Language Agnostic</h3>\n<ul>\n<li><a href=\"http://codecombat.com\">CodeCombat</a> - Python, JavaScript, CoffeeScript, Clojure, Lua, Io</li>\n<li><a href=\"https://codility.com/programmers/\">Codility</a></li>\n<li><a href=\"https://www.freecodecamp.org/learn/coding-interview-prep/algorithms\">Introduction to the Coding Interview Prep Algorithms</a> (freeCodeCamp)</li>\n<li><a href=\"http://pythontutor.com\">Python Tutor</a> - Python, Java, JavaScript, TypeScript, Ruby, C, C++</li>\n<li><a href=\"https://www.howtographql.com\">The Fullstack Tutorial for GraphQL</a></li>\n</ul>\n<h4>Operating systems</h4>\n<ul>\n<li><a href=\"https://github.com/s-matyukevich/raspberry-pi-os\">Learning operating system development using Linux kernel and Raspberry Pi</a> - Sergey Matyukevich (:construction: <em>in process</em>)</li>\n</ul>\n<h3>LaTeX</h3>\n<ul>\n<li><a href=\"https://www.overleaf.com/learn/latex/Learn_LaTeX_in_30_minutes\">Learn LaTeX in 30 minutes</a></li>\n</ul>\n<h3>Lisp</h3>\n<ul>\n<li><a href=\"https://github.com/google/lisp-koans\">Lisp Koans</a></li>\n</ul>\n<h3>MATLAB</h3>\n<ul>\n<li><a href=\"http://www.mathworks.com/tutorials\">Interactive Tutorials for MATLAB, Simulink, Signal Processing, Controls, and Computational Mathematics</a></li>\n</ul>\n<h3>Node</h3>\n<ul>\n<li><a href=\"http://nodeschool.io\">Node School</a></li>\n<li><a href=\"https://www.tutlane.com/tutorial/nodejs\">Node.js Tutorial</a> - tutlane</li>\n<li><a href=\"https://www.w3schools.com/nodejs\">Node.js Tutorial</a> - W3Schools</li>\n</ul>\n<h3>NoSQL</h3>\n<ul>\n<li><a href=\"https://github.com/chicagoruby/MongoDB_Koans\">MongoDB Koans</a></li>\n<li><a href=\"http://try.redis.io\">Try Redis</a></li>\n</ul>\n<h3>Objective-C</h3>\n<ul>\n<li><a href=\"http://tryobjectivec.codeschool.com\">Try Objective-C</a></li>\n</ul>\n<h3>Ocaml</h3>\n<ul>\n<li><a href=\"http://try.ocamlpro.com\">Try Ocaml</a></li>\n</ul>\n<h3>PHP</h3>\n<ul>\n<li><a href=\"https://www.codecademy.com/learn/php\">CodeCademy PHP</a></li>\n<li><a href=\"http://www.learn-php.org\">Learn PHP</a></li>\n<li><a href=\"https://www.w3schools.com/php\">PHP tutorial</a> - W3Schools</li>\n</ul>\n<h3>PostgreSQL</h3>\n<ul>\n<li><a href=\"https://www.postgresqltutorial.com\">PostgreSQL Tutorial</a></li>\n</ul>\n<h3>Python</h3>\n<ul>\n<li><a href=\"https://www.codecademy.com/learn/python\">Codecademy Python course</a></li>\n<li><a href=\"http://interactivepython.org/courselib/static/thinkcspy/index.html\">How to Think Like a Computer Scientist: Learning with Python, Interactive Edition</a></li>\n<li><a href=\"http://www.learnpython.org\">Learn Python</a></li>\n<li><a href=\"http://www.techbeamers.com/python-tutorial-step-by-step\">Learn Python Step by Step</a></li>\n<li><a href=\"https://runestone.academy/runestone/books/published/py4e-int/index.html\">Python for Everybody - Interactive</a> - Barbara Ericson</li>\n<li><a href=\"https://github.com/gregmalcolm/python_koans\">Python Koans</a></li>\n<li><a href=\"https://www.learndatasci.com/tutorials/python-pandas-tutorial-complete-introduction-for-beginners/\">Python Pandas Tutorial: A Complete Introduction for Beginners</a> - George McIntire, Brendan Martin, Lauren Washington</li>\n<li><a href=\"https://www.geeksforgeeks.org/python-programming-language/\">Python Programming Language</a> - GeeksforGeeks</li>\n<li><a href=\"https://www.tutlane.com/tutorial/python\">Python Tutorial</a> - tutlane</li>\n<li><a href=\"https://www.w3schools.com/python\">Python Tutorial</a> - W3Schools</li>\n</ul>\n<h3>Ruby</h3>\n<ul>\n<li><a href=\"https://www.codecademy.com/learn/ruby\">CodeCademy Ruby</a></li>\n<li><a href=\"http://www.rubykoans.com\">Ruby Koans</a></li>\n<li><a href=\"http://www.theodinproject.com\">The Odin Project</a></li>\n<li><a href=\"http://tryruby.org\">Try Ruby</a></li>\n</ul>\n<h3>Rust</h3>\n<ul>\n<li><a href=\"https://github.com/rust-lang/rustlings\">Rustlings</a></li>\n</ul>\n<h3>Scala</h3>\n<ul>\n<li><a href=\"https://scalatutorials.com/tour/\">A Tour of Scala - an interactive scala tutorial</a></li>\n<li><a href=\"https://www.scala-exercises.org\">Scala Exercises</a></li>\n</ul>\n<h3>Selenium</h3>\n<ul>\n<li><a href=\"http://www.techbeamers.com/selenium-webdriver-tutorial\">Selenium Tutorial - Web Automation</a></li>\n</ul>\n<h3>SQL</h3>\n<ul>\n<li><a href=\"https://www.khanacademy.org/computing/computer-programming/sql\">Intro to SQL: Querying and managing data</a> - Khan Academy</li>\n<li><a href=\"https://www.codecademy.com/courses/learn-sql\">SQL at Codecademy</a></li>\n<li><a href=\"https://www.tutlane.com/tutorial/sql-server\">SQL Server Tutorial</a> - tutlane</li>\n<li><a href=\"https://www.w3schools.com/sql\">SQL Tutorial</a> - W3Schools</li>\n<li><a href=\"http://sqlbolt.com\">SQLBolt</a></li>\n</ul>\n<h3>Vim</h3>\n<ul>\n<li><a href=\"http://www.openvim.com/tutorial.html\">Interactive Vim Tutorial</a></li>\n</ul>"},{"url":"/docs/react/complete-react/","relativePath":"docs/react/complete-react.md","relativeDir":"docs/react","base":"complete-react.md","name":"complete-react","frontmatter":{"title":"Complete React","weight":0,"excerpt":"React is a JavaScript library that aims to simplify development of visual interfaces.","seo":{"title":"Comprehensive Guide To ReactJS","description":"Its primary goal is to make it easy to reason about an interface and its state at any point in time, by dividing the UI into a collection of components.","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Comprehensive Guide To ReactJS</h1>\n<h4>Table of Contents</h4>\n<p><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#an-introduction-to-the-react-view-library\">An introduction to React</a><br>\n<a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#how-to-use-create-react-app\">How to use create-react-app</a></p>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#variables\">Variables</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#arrow-functions\">Arrow functions</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#rest-and-spread\">Rest and spread</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#object-and-array-destructuring\">Object and array destructuring</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#template-literals\">Template literals</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#classes\">Classes</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#callbacks\">Callbacks</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#promises\">Promises</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#async-await\">Async/Await</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#es-modules\">ES Modules</a></li>\n</ul>\n<p>*<strong>*SECTION 2**</strong>: REACT CONCEPTS</p>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#single-page-applications\">Single Page Applications</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#declarative\">Declarative</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#immutability\">Immutability</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#purity\">Purity</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#composition\">Composition</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#the-virtual-dom\">The Virtual DOM</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#unidirectional-data-flow\">Unidirectional Data Flow</a></li>\n</ul>\n<p>*<strong>*SECTION 3**</strong>: IN-DEPTH REACT</p>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#jsx\">JSX</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#components\">Components</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#state\">State</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#props\">Props</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#presentational-vs-container-components\">Presentational vs container components</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#state-vs-props\">State vs props</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#proptypes\">PropTypes</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#react-fragment\">React Fragment</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#events\">Events</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#lifecycle-events\">Lifecycle Events</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#forms-in-react\">Forms in React</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#reference-a-dom-element\">Reference a DOM element</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#server-side-rendering\">Server side rendering</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#the-context-api\">The Context API</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#higher-order-components\">Higher order components</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#render-props\">Render Props</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#hooks\">Hooks</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#code-splitting\">Code splitting</a></li>\n</ul>\n<p>*<strong>*SECTION 4**</strong>: PRACTICAL EXAMPLES</p>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#build-a-simple-counter\">Build a simple counter</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#fetch-and-display-github-users-information-via-api\">Fetch and display GitHub users information via API</a></li>\n</ul>\n<p>*<strong>*SECTION 5**</strong>: STYLING</p>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#css-in-react\">CSS in React</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#sass-in-react\">SASS in React</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#styled-components\">Styled Components</a></li>\n</ul>\n<p>*<strong>*SECTION 6**</strong>: TOOLING</p>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#babel\">Babel</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#webpack\">Webpack</a></li>\n</ul>\n<p>*<strong>*SECTION 7**</strong>: TESTING</p>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#jest\">Jest</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#testing-react-components\">Testing React components</a></li>\n</ul>\n<p>*<strong>*SECTION 8**</strong>: THE REACT ECOSYSTEM</p>\n<ul>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#react-router\">React Router</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#redux\">Redux</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#next-js\">Next.js</a></li>\n<li><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#gatsby\">Gatsby</a></li>\n</ul>\n<p><a href=\"https://www.freecodecamp.org/news/the-react-handbook-b71c27b0a795/#wrapping-up\">Wrapping up</a></p>\n<h3>An introduction to the React view library</h3>\n<h4>What is React?</h4>\n<p>React is a JavaScript library that aims to simplify development of visual interfaces.</p>\n<p>Developed at Facebook and released to the world in 2013, it drives some of the most widely used apps, powering Facebook and Instagram among countless other applications.</p>\n<p>Its primary goal is to make it easy to reason about an interface and its state at any point in time, by dividing the UI into a collection of components.</p>\n<h4>Why is React so popular?</h4>\n<p>React has taken the frontend web development world by storm. Why?</p>\n<h4>Less complex than the other alternatives</h4>\n<p>At the time when React was announced, Ember.js and Angular 1.x were the predominant choices as a framework. Both these imposed so many conventions on the code that porting an existing app was not convenient at all.</p>\n<p>React made a choice to be very easy to integrate into an existing project, because that's how they had to do it at Facebook in order to introduce it to the existing codebase. Also, those 2 frameworks brought too much to the table, while React only chose to implement the View layer instead of the full MVC stack.</p>\n<h4>Perfect timing</h4>\n<p>At the time, Angular 2.x was announced by Google, along with the backwards incompatibility and major changes it was going to bring. Moving from Angular 1 to 2 was like moving to a different framework, so this, along with execution speed improvements that React promised, made it something developers were eager to try.</p>\n<h4>Backed by Facebook</h4>\n<p>Being backed by Facebook is, of course, going to benefit a project if it turns out to be successful.</p>\n<p>Facebook currently has a strong interest in React, sees the value of it being Open Source, and this is a huge plus for all the developers using it in their own projects.</p>\n<h4>Is React simple to learn?</h4>\n<p>Even though I said that React is simpler than alternative frameworks, diving into React is still complicated, but mostly because of the corollary technologies that can be integrated with React, like Redux and GraphQL.</p>\n<p>React in itself has a very small API, and you basically need to understand 4 concepts to get started:</p>\n<ul>\n<li>Components</li>\n<li>JSX</li>\n<li>State</li>\n<li>Props</li>\n</ul>\n<p>All these (and more) are explained in this handbook.</p>\n<h4>How to install React on your development computer</h4>\n<p>How do you install React?</p>\n<p>React is a library, so saying <em>install</em> might sound a bit weird. Maybe <em>setup</em> is a better word, but you get the concept.</p>\n<p>There are various ways to setup React so that it can be used on your app or site.</p>\n<h4>Load React directly in the web page</h4>\n<p>The simplest one is to add the React JavaScript file into the page directly. This is best when your React app will interact with the elements present on a single page, and not actually controls the whole navigation aspect.</p>\n<p>In this case, you add 2 script tags to the end of the <code class=\"language-text\">body</code> tag:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;html>\n  ...\n  &lt;body>\n    ...\n    &lt;script\n      src=\"https://cdnjs.cloudflare.com/ajax/libs/react/16.8.3/umd/react.development.js\"\n      crossorigin\n    >\n&lt;/script>\n    &lt;script\n      src=\"https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.3/umd/react-dom.production.min.js\"\n      crossorigin\n    >\n&lt;/script>\n  &lt;/body>\n&lt;/html></code></pre></div>\n<blockquote>\n<p><em>Please change the version number to the latest version of React available.</em></p>\n</blockquote>\n<p>Here we loaded both React and React DOM. Why 2 libraries? Because React is 100% independent from the browser and can be used outside it (for example on Mobile devices with React Native). Hence the need for React DOM, to add the wrappers for the browser.</p>\n<p>After those tags you can load your JavaScript files that use React, or even inline JavaScript in a <code class=\"language-text\">script</code> tag:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script src=\"app.js\">\n&lt;/script>\n\n&lt;!-- or -->\n\n&lt;script>\n  //my app\n&lt;/script></code></pre></div>\n<p>To use JSX you need an extra step: load Babel</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script src=\"https://unpkg.com/babel-standalone@6/babel.min.js\">\n&lt;/script></code></pre></div>\n<p>and load your scripts with the special <code class=\"language-text\">text/babel</code> MIME type:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script src=\"app.js\" type=\"text/babel\">\n&lt;;/script></code></pre></div>\n<p>Now you can add JSX in your app.js file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = () => {\n  return &lt;button>Click me!&lt;/button>\n}\n\nReactDOM.render(&lt;Button />, document.getElementById('root'))</code></pre></div>\n<p>Check out this simple Glitch example: <a href=\"https://glitch.com/edit/#!/react-example-inline-jsx?path=script.js\">https://glitch.com/edit/#!/react-example-inline-jsx?path=script.js</a></p>\n<p>Starting in this way with script tags is good for building prototypes and enables a quick start without having to set up a complex workflow.</p>\n<h3>How to use create-react-app</h3>\n<p><code class=\"language-text\">create-react-app</code> is a project aimed at getting you up to speed with React in no time, and any React app that needs to outgrow a single page will find that <code class=\"language-text\">create-react-app</code> meets that need.</p>\n<p>You start by using <code class=\"language-text\">[npx](https://flaviocopes.com/npx/)</code>, which is an easy way to download and execute Node.js commands without installing them. <code class=\"language-text\">npx</code> comes with <code class=\"language-text\">npm</code> (since version 5.2) and if you don't have npm installed already, do it now from <a href=\"https://nodejs.org/\">https://nodejs.org</a> (npm is installed with Node).</p>\n<p>If you are unsure which version of npm you have, run <code class=\"language-text\">npm -v</code> to check if you need to update.</p>\n<blockquote>\n<p><em>Tip: check out my <a href=\"https://flaviocopes.com/macos-terminal/\">OSX terminal tutorial</a> if you're unfamiliar with using the terminal, applies to Linux as well — I'm sorry but I don't have a tutorial for Windows at the moment, but Google is your friend.</em></p>\n</blockquote>\n<p>When you run <code class=\"language-text\">npx create-react-app &lt;app-name></code>, <code class=\"language-text\">npx</code> is going to <em>download</em> the most recent <code class=\"language-text\">create-react-app</code> release, run it, and then remove it from your system. This is great because you will never have an outdated version on your system, and every time you run it, you're getting the latest and greatest code available.</p>\n<p>Let's start then:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npx create-react-app todolist</code></pre></div>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/bZgizsJA2eDZwRUPT9KmAuqaWq2z-i5JYO49\" alt=\"bZgizsJA2eDZwRUPT9KmAuqaWq2z-i5JYO49\"></p>\n<p>This is when it finished running:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/yJPelCCT4muE3FcEci5CIDm4GEyy5rvdh6R5\" alt=\"yJPelCCT4muE3FcEci5CIDm4GEyy5rvdh6R5\"></p>\n<p><code class=\"language-text\">create-react-app</code> created a files structure in the folder you told (<code class=\"language-text\">todolist</code> in this case), and initialized a <a href=\"https://flaviocopes.com/git/\">Git</a> repository.</p>\n<p>It also added a few commands in the <code class=\"language-text\">package.json</code> file, so you can immediately start the app by going into the folder and run <code class=\"language-text\">npm start</code>.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/bIcUqq3FBoasmTjSSeYJ1LA4yMndxfNF12nu\" alt=\"bIcUqq3FBoasmTjSSeYJ1LA4yMndxfNF12nu\"></p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/bD33lX4Yp0WYlgDNGCwr3Otftsstxvx1HvTQ\" alt=\"bD33lX4Yp0WYlgDNGCwr3Otftsstxvx1HvTQ\"></p>\n<p>In addition to <code class=\"language-text\">npm start</code>, <code class=\"language-text\">create-react-app</code> added a few other commands:</p>\n<ul>\n<li><code class=\"language-text\">npm run build</code>: to build the React application files in the <code class=\"language-text\">build</code> folder, ready to be deployed to a server</li>\n<li><code class=\"language-text\">npm test</code>: to run the testing suite using <a href=\"https://flaviocopes.com/jest/\">Jest</a></li>\n<li><code class=\"language-text\">npm eject</code>: to eject from <code class=\"language-text\">create-react-app</code></li>\n</ul>\n<p>Ejecting is the act of deciding that <code class=\"language-text\">create-react-app</code> has done enough for you, but you want to do more than what it allows.</p>\n<p>Since <code class=\"language-text\">create-react-app</code> is a set of common denominator conventions and a limited amount of options, it's probable that at some point your needs will demand something unique that outgrows the capabilities of <code class=\"language-text\">create-react-app</code>.</p>\n<p>When you eject, you lose the ability of automatic updates but you gain more flexibility in the <a href=\"https://flaviocopes.com/babel/\">Babel</a> and <a href=\"https://flaviocopes.com/webpack/\">Webpack</a> configuration.</p>\n<p>When you eject the action is irreversible. You will get 2 new folders in your application directory, <code class=\"language-text\">config</code> and <code class=\"language-text\">scripts</code>. Those contain the configurations - and now you can start editing them.</p>\n<blockquote>\n<p><em>If you already have a React app installed using an older version of React, first check the version by adding <code class=\"language-text\">console.log(React.version)</code> in your app, then you can update by running <code class=\"language-text\">yarn add react@16.7</code>, and yarn will prompt you to update (choose the latest version available). Repeat for <code class=\"language-text\">yarn add react-dom@16.7</code> (change \"16.7\" with whatever is the newest version of React at the moment)</em></p>\n</blockquote>\n<h4>CodeSandbox</h4>\n<p>An easy way to have the <code class=\"language-text\">create-react-app</code> structure, without installing it, is to go to <a href=\"https://codesandbox.io/s\">https://codesandbox.io/s</a> and choose \"React\".</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/DQRfUlIow3Z-icJy6XcMwTWh7gd8ZCwac02l\" alt=\"DQRfUlIow3Z-icJy6XcMwTWh7gd8ZCwac02l\"></p>\n<p>CodeSandbox is a great way to start a React project without having to install it locally.</p>\n<h4>Codepen</h4>\n<p>Another great solution is <a href=\"https://codepen.io/\">Codepen</a>.</p>\n<p>You can use this Codepen starter project which already comes pre-configured with React, with support for Hooks: <a href=\"https://codepen.io/flaviocopes/pen/VqeaxB\">https://codepen.io/flaviocopes/pen/VqeaxB</a></p>\n<p>Codepen \"pens\" are great for quick projects with one JavaScript file, while \"projects\" are great for projects with multiple files, like the ones we'll use the most when building React apps.</p>\n<p>One thing to note is that in Codepen, due to how it works internally, you don't use the regular ES Modules <code class=\"language-text\">import</code> syntax, but rather to import for example <code class=\"language-text\">useState</code>, you use</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const { useState } = React</code></pre></div>\n<p>and not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { useState } from 'react'</code></pre></div>\n<h3>SECTION 1: MODERN JAVASCRIPT CORE CONCEPTS YOU NEED TO KNOW TO USE REACT</h3>\n<h4>Find out if you have to learn something before diving into learning React</h4>\n<p>If you are willing to learn React, you first need to have a few things under your belt. There are some prerequisite technologies you have to be familiar with, in particular related to some of the more recent JavaScript features you'll use over and over in React.</p>\n<p>Sometimes people think one particular feature is provided by React, but instead it's just modern JavaScript syntax.</p>\n<p>There is no point in being an expert in those topics right away, but the more you dive into React, the more you'll need to master those.</p>\n<p>I will mention a list of things to get you up to speed quickly.</p>\n<h3>Variables</h3>\n<p>A variable is a literal assigned to an identifier, so you can reference and use it later in the program.</p>\n<p>Variables in JavaScript do not have any type attached. Once you assign a specific literal type to a variable, you can later reassign the variable to host any other type, without type errors or any issue.</p>\n<p>This is why JavaScript is sometimes referred to as \"untyped\".</p>\n<p>A variable must be declared before you can use it. There are 3 ways to do this, using <code class=\"language-text\">var</code>, <code class=\"language-text\">let</code> or <code class=\"language-text\">const</code>, and those 3 ways differ in how you can interact with the variable later on.</p>\n<h4>Using <code class=\"language-text\">var</code></h4>\n<p>Until ES2015, <code class=\"language-text\">var</code> was the only construct available for defining variables.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var a = 0</code></pre></div>\n<p>If you forget to add <code class=\"language-text\">var</code> you will be assigning a value to an undeclared variable, and the results might vary.</p>\n<p>In modern environments, with strict mode enabled, you will get an error. In older environments (or with strict mode disabled) this will simply initialize the variable and assign it to the global object.</p>\n<p>If you don't initialize the variable when you declare it, it will have the <code class=\"language-text\">undefined</code> value until you assign a value to it.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var a //typeof a === 'undefined'</code></pre></div>\n<p>You can redeclare the variable many times, overriding it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var a = 1\nvar a = 2</code></pre></div>\n<p>You can also declare multiple variables at once in the same statement:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var a = 1, b = 2jsx</code></pre></div>\n<p>The <strong>scope</strong> is the portion of code where the variable is visible.</p>\n<p>A variable initialized with <code class=\"language-text\">var</code> outside of any function is assigned to the global object, has a global scope and is visible everywhere. A variable initialized with <code class=\"language-text\">var</code> inside a function is assigned to that function, it's local and is visible only inside it, just like a function parameter.</p>\n<p>Any variable defined in a function with the same name as a global variable takes precedence over the global variable, shadowing it.</p>\n<p>It's important to understand that a block (identified by a pair of curly braces) does not define a new scope. A new scope is only created when a function is created, because <code class=\"language-text\">var</code> does not have block scope, but function scope.</p>\n<p>Inside a function, any variable defined in it is visible throughout all the function code, even if the variable is declared at the end of the function it can still be referenced in the beginning, because JavaScript before executing the code actually <em>moves all variables on top</em> (something that is called <strong>hoisting</strong>). To avoid confusion, always declare variables at the beginning of a function.</p>\n<h4>Using <code class=\"language-text\">let</code></h4>\n<p><code class=\"language-text\">let</code> is a new feature introduced in ES2015 and it's essentially a block scoped version of <code class=\"language-text\">var</code>. Its scope is limited to the block, statement or expression where it's defined, and all the contained inner blocks.</p>\n<p>Modern JavaScript developers might choose to only use <code class=\"language-text\">let</code> and completely discard the use of <code class=\"language-text\">var</code>.</p>\n<blockquote>\n<p><em>If <code class=\"language-text\">let</code> seems an obscure term, just read <code class=\"language-text\">let color = 'red'</code> as</em> let the color be red <em>and it all makes much more sense</em></p>\n</blockquote>\n<p>Defining <code class=\"language-text\">let</code> outside of any function - contrary to <code class=\"language-text\">var</code> - does not create a global variable.</p>\n<h4>Using <code class=\"language-text\">const</code></h4>\n<p>Variables declared with <code class=\"language-text\">var</code> or <code class=\"language-text\">let</code> can be changed later on in the program, and reassigned. Once a <code class=\"language-text\">const</code> is initialized, its value can never be changed again, and it can't be reassigned to a different value.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const a = 'test'</code></pre></div>\n<p>We can't assign a different literal to the <code class=\"language-text\">a</code> const. We can however mutate <code class=\"language-text\">a</code> if it's an object that provides methods that mutate its contents.</p>\n<p><code class=\"language-text\">const</code> does not provide immutability, just makes sure that the reference can't be changed.</p>\n<p><code class=\"language-text\">const</code> has block scope, same as <code class=\"language-text\">let</code>.</p>\n<p>Modern JavaScript developers might choose to always use <code class=\"language-text\">const</code> for variables that don't need to be reassigned later in the program.</p>\n<p>Why? Because we should always use the simplest construct available to avoid making errors down the road.</p>\n<h3>Arrow functions</h3>\n<p>Arrow functions were introduced in ES6 / ECMAScript 2015, and since their introduction they changed forever how JavaScript code looks (and works).</p>\n<p>In my opinion this change was so welcoming that you now rarely see the usage of the <code class=\"language-text\">function</code> keyword in modern codebases.</p>\n<p>Visually, it's a simple and welcome change, which allows you to write functions with a shorter syntax, from:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myFunction = function() {\n  //...\n}</code></pre></div>\n<p>to</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myFunction = () => {\n  //...\n}</code></pre></div>\n<p>If the function body contains just a single statement, you can omit the brackets and write all on a single line:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myFunction = () => doSomething()</code></pre></div>\n<p>Parameters are passed in the parentheses:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myFunction = (param1, param2) => doSomething(param1, param2)</code></pre></div>\n<p>If you have one (and just one) parameter, you could omit the parentheses completely:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myFunction = param => doSomething(param)</code></pre></div>\n<p>Thanks to this short syntax, arrow functions <strong>encourage the use of small functions</strong>.</p>\n<h3>Implicit return</h3>\n<p>Arrow functions allow you to have an implicit return: values are returned without having to use the <code class=\"language-text\">return</code> keyword.</p>\n<p>It works when there is a one-line statement in the function body:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myFunction = () => 'test'\n\nmyFunction() //'test'</code></pre></div>\n<p>Another example, when returning an object, remember to wrap the curly brackets in parentheses to avoid it being considered the wrapping function body brackets:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myFunction = () => ({ value: 'test' })\n\nmyFunction() //{value: 'test'}</code></pre></div>\n<h3>How this works in arrow functions</h3>\n<p><code class=\"language-text\">this</code> is a concept that can be complicated to grasp, as it varies a lot depending on the context and also varies depending on the mode of JavaScript (<em>strict mode</em> or not).</p>\n<p>It's important to clarify this concept because arrow functions behave very differently compared to regular functions.</p>\n<p>When defined as a method of an object, in a regular function <code class=\"language-text\">this</code> refers to the object, so you can do:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const car = {\n  model: 'Fiesta',\n  manufacturer: 'Ford',\n  fullName: function() {\n    return `${this.manufacturer} ${this.model}`\n  }\n}</code></pre></div>\n<p>calling <code class=\"language-text\">car.fullName()</code> will return <code class=\"language-text\">\"Ford Fiesta\"</code>.</p>\n<p>The <code class=\"language-text\">this</code> scope with arrow functions is <strong>inherited</strong> from the execution context. An arrow function does not bind <code class=\"language-text\">this</code> at all, so its value will be looked up in the call stack, so in this code <code class=\"language-text\">car.fullName()</code> will not work, and will return the string <code class=\"language-text\">\"undefined undefined\"</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const car = {\n  model: 'Fiesta',\n  manufacturer: 'Ford',\n  fullName: () => {\n    return `${this.manufacturer} ${this.model}`\n  }\n}</code></pre></div>\n<p>Due to this, arrow functions are not suited as object methods.</p>\n<p>Arrow functions cannot be used as constructors either, when instantiating an object will raise a <code class=\"language-text\">TypeError</code>.</p>\n<p>This is where regular functions should be used instead, <strong>when dynamic context is not needed</strong>.</p>\n<p>This is also a problem when handling events. DOM Event listeners set <code class=\"language-text\">this</code> to be the target element, and if you rely on <code class=\"language-text\">this</code> in an event handler, a regular function is necessary:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const link = document.querySelector('#link')\nlink.addEventListener('click', () => {\n  // this === window\n})\n\nconst link = document.querySelector('#link')\nlink.addEventListener('click', function() {\n  // this === link\n})</code></pre></div>\n<h3>Rest and spread</h3>\n<p>You can expand an array, an object or a string using the spread operator <code class=\"language-text\">...</code>.</p>\n<p>Let's start with an array example. Given</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const a = [1, 2, 3]</code></pre></div>\n<p>you can create a new array using</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const b = [...a, 4, 5, 6]</code></pre></div>\n<p>You can also create a copy of an array using</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const c = [...a]</code></pre></div>\n<p>This works for objects as well. Clone an object with:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const newObj = { ...oldObj }</code></pre></div>\n<p>Using strings, the spread operator creates an array with each char in the string:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const hey = 'hey'\nconst arrayized = [...hey] // ['h', 'e', 'y']</code></pre></div>\n<p>This operator has some pretty useful applications. The most important one is the ability to use an array as function argument in a very simple way:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const f = (foo, bar) => {}\nconst a = [1, 2]\nf(...a)</code></pre></div>\n<p>(in the past you could do this using <code class=\"language-text\">f.apply(null, a)</code> but that's not as nice and readable)</p>\n<p>The <strong>rest element</strong> is useful when working with <strong>array destructuring</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const numbers = [1, 2, 3, 4, 5]\n[first, second, ...others] = numbers</code></pre></div>\n<p>and <strong>spread elements</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const numbers = [1, 2, 3, 4, 5]\nconst sum = (a, b, c, d, e) => a + b + c + d + e\nconst sumOfNumbers = sum(...numbers)</code></pre></div>\n<p>ES2018 introduces rest properties, which are the same but for objects.</p>\n<p><strong>Rest properties</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const { first, second, ...others } = {\n  first: 1,\n  second: 2,\n  third: 3,\n  fourth: 4,\n  fifth: 5\n}\n\nfirst // 1\nsecond // 2\nothers // { third: 3, fourth: 4, fifth: 5 }</code></pre></div>\n<p><strong>Spread properties</strong> allow to create a new object by combining the properties of the object passed after the spread operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const items = { first, second, ...others }\nitems //{ first: 1, second: 2, third: 3, fourth: 4, fifth: 5 }</code></pre></div>\n<h3>Object and array destructuring</h3>\n<p>Given an object, using the destructuring syntax you can extract just some values and put them into named variables:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const person = {\n  firstName: 'Tom',\n  lastName: 'Cruise',\n  actor: true,\n  age: 54 //made up\n}\n\nconst { firstName: name, age } = person //name: Tom, age: 54</code></pre></div>\n<p><code class=\"language-text\">name</code> and <code class=\"language-text\">age</code> contain the desired values.</p>\n<p>The syntax also works on arrays:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const a = [1, 2, 3, 4, 5]\nconst [first, second] = a</code></pre></div>\n<p>This statement creates 3 new variables by getting the items with index 0, 1, 4 from the array <code class=\"language-text\">a</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const [first, second, , , fifth] = a</code></pre></div>\n<h3>Template literals</h3>\n<p>Template Literals are a new ES2015 / ES6 feature that allows you to work with strings in a novel way compared to ES5 and below.</p>\n<p>The syntax at a first glance is very simple, just use backticks instead of single or double quotes:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const a_string = `something`</code></pre></div>\n<p>They are unique because they provide a lot of features that normal strings built with quotes do not, in particular:</p>\n<ul>\n<li>they offer a great syntax to define multiline strings</li>\n<li>they provide an easy way to interpolate variables and expressions in strings</li>\n<li>they allow you to create DSLs with template tags (DSL means domain specific language, and it's for example used in React by Styled Components, to define CSS for a component)</li>\n</ul>\n<p>Let's dive into each of these in detail.</p>\n<h4>Multiline strings</h4>\n<p>Pre-ES6, to create a string spanning over two lines you had to use the <code class=\"language-text\">\\</code> character at the end of a line:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const string =\n  'first part \\\nsecond part'</code></pre></div>\n<p>This allows to create a string on 2 lines, but it's rendered on just one line:</p>\n<p><code class=\"language-text\">first part second part</code></p>\n<p>To render the string on multiple lines as well, you explicitly need to add <code class=\"language-text\">\\n</code> at the end of each line, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const string =\n  'first line\\n \\\nsecond line'</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const string = 'first line\\n' + 'second line'</code></pre></div>\n<p>Template literals make multiline strings much simpler.</p>\n<p>Once a template literal is opened with the backtick, you just press enter to create a new line, with no special characters, and it's rendered as-is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const string = `Hey\nthis\nstring\nis awesome!`</code></pre></div>\n<p>Keep in mind that space is meaningful, so doing this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const string = `First\n                Second`</code></pre></div>\n<p>is going to create a string like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">First\n                Second</code></pre></div>\n<p>an easy way to fix this problem is by having an empty first line, and appending the trim() method right after the closing backtick, which will eliminate any space before the first character:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const string = `\nFirst\nSecond`.trim()</code></pre></div>\n<h4>Interpolation</h4>\n<p>Template literals provide an easy way to interpolate variables and expressions into strings.</p>\n<p>You do so by using the <code class=\"language-text\">${...}</code> syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myVariable = 'test'\nconst string = `something ${myVariable}` //something test</code></pre></div>\n<p>inside the <code class=\"language-text\">${}</code> you can add anything, even expressions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const string = `something ${1 + 2 + 3}`\nconst string2 = `something ${foo() ? 'x' : 'y'}`</code></pre></div>\n<h3>Classes</h3>\n<p>In 2015 the ECMAScript 6 (ES6) standard introduced classes.</p>\n<p>JavaScript has a quite uncommon way to implement inheritance: prototypical inheritance. <a href=\"https://flaviocopes.com/javascript-prototypal-inheritance/\">Prototypal inheritance</a>, while in my opinion great, is unlike most other popular programming language's implementation of inheritance, which is class-based.</p>\n<p>People coming from Java or Python or other languages had a hard time understanding the intricacies of prototypal inheritance, so the ECMAScript committee decided to sprinkle syntactic sugar on top of prototypical inheritance so that it resembles how class-based inheritance works in other popular implementations.</p>\n<p>This is important: JavaScript under the hood is still the same, and you can access an object prototype in the usual way.</p>\n<h4>A class definition</h4>\n<p>This is how a class looks.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Person {\n  constructor(name) {\n    this.name = name\n  }\n  \n  hello() {\n    return 'Hello, I am ' + this.name + '.'\n  }\n}</code></pre></div>\n<p>A class has an identifier, which we can use to create new objects using <code class=\"language-text\">new ClassIdentifier()</code>.</p>\n<p>When the object is initialized, the <code class=\"language-text\">constructor</code> method is called, with any parameters passed.</p>\n<p>A class also has as many methods as it needs. In this case <code class=\"language-text\">hello</code> is a method and can be called on all objects derived from this class:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const flavio = new Person('Flavio')\nflavio.hello()</code></pre></div>\n<h4>Class inheritance</h4>\n<p>A class can extend another class, and objects initialized using that class inherit all the methods of both classes.</p>\n<p>If the inherited class has a method with the same name as one of the classes higher in the hierarchy, the closest method takes precedence:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Programmer extends Person {\n  hello() {\n    return super.hello() + ' I am a programmer.'\n  }\n}\n\nconst flavio = new Programmer('Flavio')\nflavio.hello()</code></pre></div>\n<p>(the above program prints \"<em>Hello, I am Flavio. I am a programmer.</em>\")</p>\n<p>Classes do not have explicit class variable declarations, but you must initialize any variable in the constructor.</p>\n<p>Inside a class, you can reference the parent class calling <code class=\"language-text\">super()</code>.</p>\n<h4>Static methods</h4>\n<p>Normally methods are defined on the instance, not on the class.</p>\n<p>Static methods are executed on the class instead:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Person {\n  static genericHello() {\n    return 'Hello'\n  }\n}\n\nPerson.genericHello() //Hello</code></pre></div>\n<h4>Private methods</h4>\n<p>JavaScript does not have a built-in way to define private or protected methods.</p>\n<p>There are workarounds, but I won't describe them here.</p>\n<h4>Getters and setters</h4>\n<p>You can add methods prefixed with <code class=\"language-text\">get</code> or <code class=\"language-text\">set</code> to create a getter and setter, which are two different pieces of code that are executed based on what you are doing: accessing the variable, or modifying its value.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Person {\n  constructor(name) {\n    this.name = name\n  }\n  \n  set name(value) {\n    this.name = value\n  }\n  \n  get name() {\n    return this.name\n  }\n}</code></pre></div>\n<p>If you only have a getter, the property cannot be set, and any attempt at doing so will be ignored:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Person {\n  constructor(name) {\n    this.name = name\n  }\n  \n  get name() {\n    return this.name\n  }\n}</code></pre></div>\n<p>If you only have a setter, you can change the value but not access it from the outside:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Person {\n  constructor(name) {\n    this.name = name\n  }\n  \n  set name(value) {\n    this.name = value\n  }\n}</code></pre></div>\n<h3>Callbacks</h3>\n<p>Computers are asynchronous by design.</p>\n<p>Asynchronous means that things can happen independently of the main program flow.</p>\n<p>In the current consumer computers, every program runs for a specific time slot, and then it stops its execution to let another program continue its execution. This thing runs in a cycle so fast that's impossible to notice, and we think our computers run many programs simultaneously, but this is an illusion (except on multiprocessor machines).</p>\n<p>Programs internally use <em>interrupts</em>, a signal that's emitted to the processor to gain the attention of the system.</p>\n<p>I won't go into the internals of this, but just keep in mind that it's normal for programs to be asynchronous, and halt their execution until they need attention, and the computer can execute other things in the meantime. When a program is waiting for a response from the network, it cannot halt the processor until the request finishes.</p>\n<p>Normally, programming languages are synchronous, and some provide a way to manage asynchronicity, in the language or through libraries. C, Java, C#, PHP, Go, Ruby, Swift, Python, they are all synchronous by default. Some of them handle async by using threads, spawning a new process.</p>\n<p>JavaScript is <strong>synchronous</strong> by default and is single threaded. This means that code cannot create new threads and run in parallel.</p>\n<p>Lines of code are executed in series, one after another, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const a = 1\nconst b = 2\nconst c = a * b\nconsole.log(c)\ndoSomething()</code></pre></div>\n<p>But JavaScript was born inside the browser, its main job, in the beginning, was to respond to user actions, like <code class=\"language-text\">onClick</code>, <code class=\"language-text\">onMouseOver</code>, <code class=\"language-text\">onChange</code>, <code class=\"language-text\">onSubmit</code> and so on. How could it do this with a synchronous programming model?</p>\n<p>The answer was in its environment. The <strong>browser</strong> provides a way to do it by providing a set of APIs that can handle this kind of functionality.</p>\n<p>More recently, Node.js introduced a non-blocking I/O environment to extend this concept to file access, network calls and so on.</p>\n<p>You can't know when a user is going to click a button, so what you do is, you <strong>define an event handler for the click event</strong>. This event handler accepts a function, which will be called when the event is triggered:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">document.getElementById('button').addEventListener('click', () => {\n  //item clicked\n})</code></pre></div>\n<p>This is the so-called <strong>callback</strong>.</p>\n<p>A callback is a simple function that's passed as a value to another function, and will only be executed when the event happens. We can do this because JavaScript has first-class functions, which can be assigned to variables and passed around to other functions (called <strong>higher-order functions</strong>)</p>\n<p>It's common to wrap all your client code in a <code class=\"language-text\">load</code> event listener on the <code class=\"language-text\">window</code>object, which runs the callback function only when the page is ready:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">window.addEventListener('load', () => {\n  //window loaded\n  //do what you want\n})</code></pre></div>\n<p>Callbacks are used everywhere, not just in DOM events.</p>\n<p>One common example is by using timers:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">setTimeout(() => {\n  // runs after 2 seconds\n}, 2000)</code></pre></div>\n<p>XHR requests also accept a callback, in this example by assigning a function to a property that will be called when a particular event occurs (in this case, the state of the request changes):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const xhr = new XMLHttpRequest()\nxhr.onreadystatechange = () => {\n  if (xhr.readyState === 4) {\n    xhr.status === 200 ? console.log(xhr.responseText) : console.error('error')\n  }\n}\nxhr.open('GET', 'https://yoursite.com')\nxhr.send()</code></pre></div>\n<h4>Handling errors in callbacks</h4>\n<p>How do you handle errors with callbacks? One very common strategy is to use what Node.js adopted: the first parameter in any callback function is the error object: <strong>error-first callbacks</strong></p>\n<p>If there is no error, the object is <code class=\"language-text\">null</code>. If there is an error, it contains some description of the error and other information.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fs.readFile('/file.json', (err, data) => {\n  if (err !== null) {\n    //handle error\n    console.log(err)\n    return\n  }\n  \n  //no errors, process data\n  console.log(data)\n})</code></pre></div>\n<h4>The problem with callbacks</h4>\n<p>Callbacks are great for simple cases!</p>\n<p>However every callback adds a level of nesting, and when you have lots of callbacks, the code starts to be complicated very quickly:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">window.addEventListener('load', () => {\n  document.getElementById('button').addEventListener('click', () => {\n    setTimeout(() => {\n      items.forEach(item => {\n        //your code here\n      })\n    }, 2000)\n  })\n})</code></pre></div>\n<p>This is just a simple 4-levels code, but I've seen much more levels of nesting and it's not fun.</p>\n<p>How do we solve this?</p>\n<h3>ALTERNATIVES TO CALLBACKS</h3>\n<p>Starting with ES6, JavaScript introduced several features that help us with asynchronous code that do not involve using callbacks:</p>\n<ul>\n<li>Promises (ES6)</li>\n<li>Async/Await (ES8)</li>\n</ul>\n<h3>Promises</h3>\n<p>Promises are one way to deal with asynchronous code, without writing too many callbacks in your code.</p>\n<p>Although they've been around for years, they were standardized and introduced in ES2015, and now they have been superseded in ES2017 by async functions.</p>\n<p><strong>Async functions</strong> use the promises API as their building block, so understanding them is fundamental even if in newer code you'll likely use async functions instead of promises.</p>\n<h4>How promises work, in brief</h4>\n<p>Once a promise has been called, it will start in <strong>pending state</strong>. This means that the caller function continues the execution, while it waits for the promise to do its own processing, and give the caller function some feedback.</p>\n<p>At this point, the caller function waits for it to either return the promise in a <strong>resolved state</strong>, or in a <strong>rejected state</strong>, but as you know JavaScript is asynchronous, so <em>the function continues its execution while the promise does it work</em>.</p>\n<h4>Which JS API use promises?</h4>\n<p>In addition to your own code and library code, promises are used by standard modern Web APIs like <a href=\"https://flaviocopes.com/fetch-api/\">Fetch</a> or <a href=\"https://flaviocopes.com/service-workers/\">Service Workers</a>.</p>\n<p>It's unlikely that in modern JavaScript you'll find yourself <em>not</em> using promises, so let's start diving right into them.</p>\n<h4>Creating a promise</h4>\n<p>The Promise API exposes a Promise constructor, which you initialize using <code class=\"language-text\">new Promise()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let done = true\n\nconst isItDoneYet = new Promise((resolve, reject) => {\n  if (done) {\n    const workDone = 'Here is the thing I built'\n    resolve(workDone)\n  } else {\n    const why = 'Still working on something else'\n    reject(why)\n  }\n})</code></pre></div>\n<p>As you can see the promise checks the <code class=\"language-text\">done</code> global constant, and if that's true, we return a resolved promise, otherwise a rejected promise.</p>\n<p>Using <code class=\"language-text\">resolve</code> and <code class=\"language-text\">reject</code> we can communicate back a value, in the above case we just return a string, but it could be an object as well.</p>\n<h4>Consuming a promise</h4>\n<p>In the last section, we introduced how a promise is created.</p>\n<p>Now let's see how the promise can be <em>consumed</em> or used.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const isItDoneYet = new Promise()\n//...\n\nconst checkIfItsDone = () => {\n  isItDoneYet\n    .then(ok => {\n      console.log(ok)\n    })\n    .catch(err => {\n      console.error(err)\n    })\n}</code></pre></div>\n<p>Running <code class=\"language-text\">checkIfItsDone()</code> will execute the <code class=\"language-text\">isItDoneYet()</code> promise and will wait for it to resolve, using the <code class=\"language-text\">then</code> callback, and if there is an error, it will handle it in the <code class=\"language-text\">catch</code> callback.</p>\n<h4>Chaining promises</h4>\n<p>A promise can be returned to another promise, creating a chain of promises.</p>\n<p>A great example of chaining promises is given by the <a href=\"https://flaviocopes.com/fetch-api/\">Fetch API</a>, a layer on top of the XMLHttpRequest API, which we can use to get a resource and queue a chain of promises to execute when the resource is fetched.</p>\n<p>The Fetch API is a promise-based mechanism, and calling <code class=\"language-text\">fetch()</code> is equivalent to defining our own promise using <code class=\"language-text\">new Promise()</code>.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const status = response => {\n  if (response.status >= 200 &amp;&amp; response.status &lt; 300) {\n    return Promise.resolve(response)\n  }\n  return Promise.reject(new Error(response.statusText))\n}\n\nconst json = response => response.json()\n\nfetch('/todos.json')\n  .then(status)\n  .then(json)\n  .then(data => {\n    console.log('Request succeeded with JSON response', data)\n  })\n  .catch(error => {\n    console.log('Request failed', error)\n  })</code></pre></div>\n<p>In this example, we call <code class=\"language-text\">fetch()</code> to get a list of TODO items from the <code class=\"language-text\">todos.json</code> file found in the domain root, and we create a chain of promises.</p>\n<p>Running <code class=\"language-text\">fetch()</code> returns a <a href=\"https://fetch.spec.whatwg.org/#concept-response\">response</a>, which has many properties, and within those we reference:</p>\n<ul>\n<li><code class=\"language-text\">status</code>, a numeric value representing the HTTP status code</li>\n<li><code class=\"language-text\">statusText</code>, a status message, which is <code class=\"language-text\">OK</code> if the request succeeded</li>\n</ul>\n<p><code class=\"language-text\">response</code> also has a <code class=\"language-text\">json()</code> method, which returns a promise that will resolve with the content of the body processed and transformed into JSON.</p>\n<p>So given those premises, this is what happens: the first promise in the chain is a function that we defined, called <code class=\"language-text\">status()</code>, that checks the response status and if it's not a success response (between 200 and 299), it rejects the promise.</p>\n<p>This operation will cause the promise chain to skip all the chained promises listed and will skip directly to the <code class=\"language-text\">catch()</code> statement at the bottom, logging the <code class=\"language-text\">Request failed</code> text along with the error message.</p>\n<p>If that succeeds instead, it calls the json() function we defined. Since the previous promise, when successful, returned the <code class=\"language-text\">response</code> object, we get it as an input to the second promise.</p>\n<p>In this case, we return the data JSON processed, so the third promise receives the JSON directly:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.then((data) => {\n  console.log('Request succeeded with JSON response', data)\n})</code></pre></div>\n<p>and we simply log it to the console.</p>\n<h4>Handling errors</h4>\n<p>In the above example, in the previous section, we had a <code class=\"language-text\">catch</code> that was appended to the chain of promises.</p>\n<p>When anything in the chain of promises fails and raises an error or rejects the promise, the control goes to the nearest <code class=\"language-text\">catch()</code> statement down the chain.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">new Promise((resolve, reject) => {\n  throw new Error('Error')\n}).catch(err => {\n  console.error(err)\n})\n\n// or\n\nnew Promise((resolve, reject) => {\n  reject('Error')\n}).catch(err => {\n  console.error(err)\n})</code></pre></div>\n<h4>Cascading errors</h4>\n<p>If inside the <code class=\"language-text\">catch()</code> you raise an error, you can append a second <code class=\"language-text\">catch()</code> to handle it, and so on.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">new Promise((resolve, reject) => {\n  throw new Error('Error')\n})\n  .catch(err => {\n    throw new Error('Error')\n  })\n  .catch(err => {\n    console.error(err)\n  })</code></pre></div>\n<h4>Orchestrating promises with <code class=\"language-text\">Promise.all()</code></h4>\n<p>If you need to synchronize different promises, <code class=\"language-text\">Promise.all()</code> helps you define a list of promises, and execute something when they are all resolved.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const f1 = fetch('/something.json')\nconst f2 = fetch('/something2.json')\n\nPromise.all([f1, f2])\n  .then(res => {\n    console.log('Array of results', res)\n  })\n  .catch(err => {\n    console.error(err)\n  })</code></pre></div>\n<p>The ES2015 destructuring assignment syntax allows you to also do</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.all([f1, f2]).then(([res1, res2]) => {\n  console.log('Results', res1, res2)\n})</code></pre></div>\n<p>You are not limited to using <code class=\"language-text\">fetch</code> of course, <strong>any promise is good to go</strong>.</p>\n<h4>Orchestrating promises with <code class=\"language-text\">Promise.race()</code></h4>\n<p><code class=\"language-text\">Promise.race()</code> runs as soon as one of the promises you pass to it resolves, and it runs the attached callback just once with the result of the first promise resolved.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const promiseOne = new Promise((resolve, reject) => {\n  setTimeout(resolve, 500, 'one')\n})\nconst promiseTwo = new Promise((resolve, reject) => {\n  setTimeout(resolve, 100, 'two')\n})\n\nPromise.race([promiseOne, promiseTwo]).then(result => {\n  console.log(result) // 'two'\n})</code></pre></div>\n<h3>Async/Await</h3>\n<p>JavaScript evolved in a very short time from callbacks to promises (ES2015), and since ES2017 asynchronous JavaScript is even simpler with the async/await syntax.</p>\n<p>Async functions are a combination of promises and generators, and basically, they are a higher level abstraction over promises. Let me repeat: <strong>async/await is built on promises</strong>.</p>\n<h4>Why were async/await introduced?</h4>\n<p>They reduce the boilerplate around promises, and the \"don't break the chain\" limitation of chaining promises.</p>\n<p>When Promises were introduced in ES2015, they were meant to solve a problem with asynchronous code, and they did, but over the 2 years that separated ES2015 and ES2017, it was clear that <em>promises could not be the final solution</em>.</p>\n<p>Promises were introduced to solve the famous <em>callback hell</em> problem, but they introduced complexity on their own, and syntax complexity.</p>\n<p>They were good primitives around which a better syntax could be exposed to developers, so when the time was right we got <strong>async functions</strong>.</p>\n<p>They make the code look like it's synchronous, but it's asynchronous and non-blocking behind the scenes.</p>\n<h4>How it works</h4>\n<p>An async function returns a promise, like in this example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const doSomethingAsync = () => {\n  return new Promise(resolve => {\n    setTimeout(() => resolve('I did something'), 3000)\n  })\n}</code></pre></div>\n<p>When you want to <strong>call</strong> this function you prepend <code class=\"language-text\">await</code>, and <strong>the calling code will stop until the promise is resolved or rejected</strong>. One caveat: the client function must be defined as <code class=\"language-text\">async</code>. Here's an example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const doSomething = async () => {\n  console.log(await doSomethingAsync())\n}</code></pre></div>\n<h4>A quick example</h4>\n<p>This is a simple example of async/await used to run a function asynchronously:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const doSomethingAsync = () => {\n  return new Promise(resolve => {\n    setTimeout(() => resolve('I did something'), 3000)\n  })\n}\n\nconst doSomething = async () => {\n  console.log(await doSomethingAsync())\n}\n\nconsole.log('Before')\ndoSomething()\nconsole.log('After')</code></pre></div>\n<p>The above code will print the following to the browser console:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Before\nAfter\nI did something //after 3s</code></pre></div>\n<h4>Promise all the things</h4>\n<p>Prepending the <code class=\"language-text\">async</code> keyword to any function means that the function will return a promise.</p>\n<p>Even if it's not doing so explicitly, it will internally make it return a promise.</p>\n<p>This is why this code is valid:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const aFunction = async () => {\n  return 'test'\n}\n\naFunction().then(alert) // This will alert 'test'</code></pre></div>\n<p>and it's the same as:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const aFunction = async () => {\n  return Promise.resolve('test')\n}\n\naFunction().then(alert) // This will alert 'test'</code></pre></div>\n<h4>The code is much simpler to read</h4>\n<p>As you can see in the example above, our code looks very simple. Compare it to code using plain promises, with chaining and callback functions.</p>\n<p>And this is a very simple example, the major benefits will arise when the code is much more complex.</p>\n<p>For example here's how you would get a JSON resource, and parse it, using promises:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const getFirstUserData = () => {\n  return fetch('/users.json') // get users list\n    .then(response => response.json()) // parse JSON\n    .then(users => users[0]) // pick first user\n    .then(user => fetch(`/users/${user.name}`)) // get user data\n    .then(userResponse => userResponse.json()) // parse JSON\n}\n\ngetFirstUserData()</code></pre></div>\n<p>And here is the same functionality provided using await/async:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const getFirstUserData = async () => {\n  const response = await fetch('/users.json') // get users list\n  const users = await response.json() // parse JSON\n  const user = users[0] // pick first user\n  const userResponse = await fetch(`/users/${user.name}`) // get user data\n  const userData = await userResponse.json() // parse JSON\n  return userData\n}\n\ngetFirstUserData()</code></pre></div>\n<h4>Multiple async functions in series</h4>\n<p>Async functions can be chained very easily, and the syntax is much more readable than with plain promises:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const promiseToDoSomething = () => {\n  return new Promise(resolve => {\n    setTimeout(() => resolve('I did something'), 10000)\n  })\n}\n\nconst watchOverSomeoneDoingSomething = async () => {\n  const something = await promiseToDoSomething()\n  return something + ' and I watched'\n}\n\nconst watchOverSomeoneWatchingSomeoneDoingSomething = async () => {\n  const something = await watchOverSomeoneDoingSomething()\n  return something + ' and I watched as well'\n}\n\nwatchOverSomeoneWatchingSomeoneDoingSomething().then(res => {\n  console.log(res)\n})</code></pre></div>\n<p>Will print:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">I did something and I watched and I watched as well</code></pre></div>\n<h4>Easier debugging</h4>\n<p>Debugging promises is hard because the debugger will not step over asynchronous code.</p>\n<p>Async/await makes this very easy because to the compiler it's just like synchronous code.</p>\n<h3>ES Modules</h3>\n<p>ES Modules is the ECMAScript standard for working with modules.</p>\n<p>While Node.js has been using the CommonJS standard for years, the browser never had a module system, as every major decision such as a module system must be first standardized by ECMAScript and then implemented by the browser.</p>\n<p>This standardization process completed with ES6 and browsers started implementing this standard trying to keep everything well aligned, working all in the same way, and now ES Modules are supported in Chrome, Safari, Edge and Firefox (since version 60).</p>\n<p>Modules are very cool, because they let you encapsulate all sorts of functionality, and expose this functionality to other JavaScript files, as libraries.</p>\n<h4>The ES Modules Syntax</h4>\n<p>The syntax to import a module is:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import package from 'module-name'</code></pre></div>\n<p>while CommonJS uses</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const package = require('module-name')</code></pre></div>\n<p>A module is a JavaScript file that <strong>exports</strong> one or more values (objects, functions or variables), using the <code class=\"language-text\">export</code> keyword. For example, this module exports a function that returns a string uppercase:</p>\n<blockquote>\n<p><em>uppercase.js</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export default str => str.toUpperCase()</code></pre></div>\n<p>In this example, the module defines a single, <strong>default export</strong>, so it can be an anonymous function. Otherwise it would need a name to distinguish it from other exports.</p>\n<p>Now, <strong>any other JavaScript module</strong> can import the functionality offered by uppercase.js by importing it.</p>\n<p>An HTML page can add a module by using a <code class=\"language-text\">&lt;scri</code>pt> tag with the sp<code class=\"language-text\">ecial type=\"m</code>odule\" attribute:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script type=\"module\" src=\"index.js\">\n&lt;;/script></code></pre></div>\n<blockquote>\n<p><em>Note: this module import behaves like a <code class=\"language-text\">defer</code> script load. See <a href=\"https://flaviocopes.com/javascript-async-defer/\">efficiently load JavaScript with defer and async</a></em></p>\n</blockquote>\n<p>It's important to note that any script loaded with <code class=\"language-text\">type=\"module\"</code> is loaded in <a href=\"https://flaviocopes.com/javascript-strict-mode/\">strict mode</a>.</p>\n<p>In this example, the <code class=\"language-text\">uppercase.js</code> module defines a <strong>default export</strong>, so when we import it, we can assign it a name we prefer:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import toUpperCase from './uppercase.js'</code></pre></div>\n<p>and we can use it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">toUpperCase('test') //'TEST'</code></pre></div>\n<p>You can also use an absolute path for the module import, to reference modules defined on another domain:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import toUpperCase from 'https://flavio-es-modules-example.glitch.me/uppercase.js'</code></pre></div>\n<p>This is also valid import syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { foo } from '/uppercase.js'import { foo } from '../uppercase.js'</code></pre></div>\n<p>This is not:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { foo } from 'uppercase.js'\nimport { foo } from 'utils/uppercase.js'</code></pre></div>\n<p>It's either absolute, or has a <code class=\"language-text\">./</code> or <code class=\"language-text\">/</code> before the name.</p>\n<h3>Other import/export options</h3>\n<p>We saw this example above:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export default str => str.toUpperCase()</code></pre></div>\n<p>This creates one default export. In a file however you can export more than one thing, by using this syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const a = 1\nconst b = 2\nconst c = 3\n\nexport { a, b, c }</code></pre></div>\n<p>Another module can import all those exports using</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import * from 'module'</code></pre></div>\n<p>You can import just a few of those exports, using the destructuring assignment:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { a } from 'module'\nimport { a, b } from 'module'</code></pre></div>\n<p>You can rename any import, for convenience, using <code class=\"language-text\">as</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { a, b as two } from 'module'</code></pre></div>\n<p>You can import the default export, and any non-default export by name, like in this common React import:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { Component } from 'react'</code></pre></div>\n<p>You can see an ES Modules example here: <a href=\"https://glitch.com/edit/#!/flavio-es-modules-example?path=index.html\">https://glitch.com/edit/#!/flavio-es-modules-example?path=index.html</a></p>\n<h4>CORS</h4>\n<p>Modules are fetched using <a href=\"https://flaviocopes.com/cors/\">CORS</a>. This means that if you reference scripts from other domains, they must have a valid CORS header that allows cross-site loading (like <code class=\"language-text\">Access-Control-Allow-Origin: *</code>)</p>\n<h4>What about browsers that do not support modules?</h4>\n<p>Use a combination of <code class=\"language-text\">type=\"module\"</code> and <code class=\"language-text\">nomodule</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script type=\"module\" src=\"module.js\">\n&lt;/script>\n&lt;script nomodule src=\"fallback.js\">\n&lt;/script></code></pre></div>\n<p>ES Modules are one of the biggest features introduced in modern browsers. They are part of ES6 but the road to implement them has been long.</p>\n<p>We can now use them! But we must also remember that having more than a few modules is going to have a performance hit on our pages, as it's one more step that the browser must perform at runtime.</p>\n<p>Webpack is probably going to still be a huge player even if ES Modules land in the browser, but having such a feature directly built in the language is huge for a unification of how modules work client-side and on Node.js as well.</p>\n<h3>SECTION 2: REACT CONCEPTS</h3>\n<h3>Single Page Applications</h3>\n<p>React Applications are also called Single Page Applications. What does this mean?</p>\n<p>In the past, when browsers were much less capable than today, and JavaScript performance was poor, every page was coming from a server. Every time you clicked something, a new request was made to the server and the browser subsequently loaded the new page.</p>\n<p>Only very innovative products worked differently, and experimented with new approaches.</p>\n<p>Today, popularized by modern frontend JavaScript frameworks like React, an app is usually built as a single page application: you only load the application code (HTML, <a href=\"https://flaviocopes.com/css/\">CSS</a>, <a href=\"https://flaviocopes.com/javascript/\">JavaScript</a>) once, and when you interact with the application, what generally happens is that JavaScript intercepts the browser events and instead of making a new request to the server that then returns a new document, the client requests some JSON or performs an action on the server but the page that the user sees is never completely wiped away, and behaves more like a desktop application.</p>\n<p>Single page applications are built in JavaScript (or at least compiled to JavaScript) and work in the browser.</p>\n<p>The technology is always the same, but the philosophy and some key components of how the application works are different.</p>\n<h4>Examples of Single Page Applications</h4>\n<p>Some notable examples:</p>\n<ul>\n<li>Gmail</li>\n<li>Google Maps</li>\n<li>Facebook</li>\n<li>Twitter</li>\n<li>Google Drive</li>\n</ul>\n<h4>Pros and cons of SPAs</h4>\n<p>An SPA feels much faster to the user, because instead of waiting for the client-server communication to happen, and wait for the browser to re-render the page, you can now have instant feedback. This is the responsibility of the application maker, but you can have transitions and spinners and any kind of UX improvement that is certainly better than the traditional workflow.</p>\n<p>In addition to making the experience faster to the user, the server will consume less resources because you can focus on providing an efficient API instead of building the layouts server-side.</p>\n<p>This makes it ideal if you also build a mobile app on top of the API, as you can completely reuse your existing server-side code.</p>\n<p>Single Page Applications are easy to transform into Progressive Web Apps, which in turn enables you to provide local caching and to support offline experiences for your services (or simply a better error message if your users need to be online).</p>\n<p>SPAs are best used when there is no need for SEO (search engine optimization). For example for apps that work behind a login.</p>\n<p>Search engines, while improving every day, still have trouble indexing sites built with an SPA approach rather than the traditional server-rendered pages. This is the case for blogs. If you are going to rely on search engines, don't even bother with creating a single page application without having a server rendered part as well.</p>\n<p>When coding an SPA, you are going to write a great deal of JavaScript. Since the app can be long-running, you are going to need to pay a lot more attention to possible memory leaks — if in the past your page had a lifespan that was counted in minutes, now an SPA might stay open for hours at a time and if there is any memory issue that's going to increase the browser memory usage by a lot more and it's going to cause an unpleasantly slow experience if you don't take care of it.</p>\n<p>SPAs are great when working in teams. Backend developers can just focus on the API, and frontend developers can focus on creating the best user experience, making use of the API built in the backend.</p>\n<p>As a con, Single Page Apps rely heavily on JavaScript. This might make using an application running on low power devices a poor experience in terms of speed. Also, some of your visitors might just have JavaScript disabled, and you also need to consider accessibility for anything you build.</p>\n<h4>Overriding the navigation</h4>\n<p>Since you get rid of the default browser navigation, URLs must be managed manually.</p>\n<p>This part of an application is called the router. Some frameworks already take care of them for you (like Ember), others require libraries that will do this job (like <a href=\"https://flaviocopes.com/react-router/\">React Router</a>).</p>\n<p>What's the problem? In the beginning, this was an afterthought for developers building Single Page Applications. This caused the common \"broken back button\" issue: when navigating inside the application the URL didn't change (since the browser default navigation was hijacked) and hitting the back button, a common operation that users do to go to the previous screen, might move to a website you visited a long time ago.</p>\n<p>This problem can now be solved using the <a href=\"https://flaviocopes.com/history-api/\">History API</a> offered by browsers, but most of the time you'll use a library that internally uses that API, like <strong>React Router</strong>.</p>\n<h3>Declarative</h3>\n<p>What does it mean when you read that React is declarative? You'll run across articles describing React as a <strong>declarative approach to building UIs</strong>.</p>\n<p>React made its \"declarative approach\" quite popular and upfront so it permeated the frontend world along with React.</p>\n<p>It's really not a new concept, but React took building UIs a lot more declaratively than with HTML templates:</p>\n<ul>\n<li>you can build Web interfaces without even touching the DOM directly</li>\n<li>you can have an event system without having to interact with the actual DOM Events.</li>\n</ul>\n<p>The opposite of declarative is <strong>imperative</strong>. A common example of an imperative approach is looking up elements in the DOM using jQuery or DOM events. You tell the browser exactly what to do, instead of telling it what you need.</p>\n<p>The React declarative approach abstracts that for us. We just tell React we want a component to be rendered in a specific way, and we never have to interact with the DOM to reference it later.</p>\n<h3>Immutability</h3>\n<p>One concept you will likely meet when programming in React is immutability (and its opposite, mutability).</p>\n<p>It's a controversial topic, but whatever you might think about the concept of immutability, React and most of its ecosystem kind of forces this, so you need to at least have a grasp of why it's so important and the implications of it.</p>\n<p>In programming, a variable is immutable when its value cannot change after it's created.</p>\n<p>You are already using immutable variables without knowing it when you manipulate a string. Strings are immutable by default, when you change them in reality you create a new string and assign it to the same variable name.</p>\n<p>An immutable variable can never be changed. To update its value, you create a new variable.</p>\n<p>The same applies to objects and arrays.</p>\n<p>Instead of changing an array, to add a new item you create a new array by concatenating the old array, plus the new item.</p>\n<p>An object is never updated, but copied before changing it.</p>\n<p>This applies to React in many places.</p>\n<p>For example, you should never mutate the <code class=\"language-text\">state</code> property of a component directly, but only through the <code class=\"language-text\">setState()</code> method.</p>\n<p>In Redux, you never mutate the state directly, but only through reducers, which are functions.</p>\n<p>The question is, why?</p>\n<p>There are various reasons, the most important of which are:</p>\n<ul>\n<li>Mutations can be centralized, like in the case of Redux, which improves your debugging capabilities and reduces sources of errors.</li>\n<li>Code looks cleaner and simpler to understand. You never expect a function to change some value without you knowing, which gives you <strong>predictability</strong>. When a function does not mutate objects but just returns a new object, it's called a pure function.</li>\n<li>The library can optimize the code because for example JavaScript is faster when swapping an old object reference for an entirely new object, rather than mutating an existing object. This gives you <strong>performance</strong>.</li>\n</ul>\n<h3>Purity</h3>\n<p>In JavaScript, when a function does not mutate objects but just returns a new object, it's called a pure function.</p>\n<p>A function, or a method, in order to be called <em>pure</em> should not cause side effects and should return the same output when called multiple times with the same input.</p>\n<p>A pure function takes an input and returns an output without changing the input nor anything else.</p>\n<p>Its output is only determined by the arguments. You could call this function 1M times, and given the same set of arguments, the output will always be the same.</p>\n<p>React applies this concept to components. A React component is a pure component when its output is only dependant on its props.</p>\n<p>All functional components are pure components:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = props => {\n  return &lt;button>{props.message}&lt;/button>\n}</code></pre></div>\n<p>Class components can be pure if their output only depends on the props:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Button extends React.Component {\n  render() {\n    return &lt;button>{this.props.message}&lt;/button>\n  }\n}</code></pre></div>\n<h3>Composition</h3>\n<p>In programming, composition allows you to build more complex functionality by combining small and focused functions.</p>\n<p>For example, think about using <code class=\"language-text\">map()</code> to create a new array from an initial set, and then filtering the result using <code class=\"language-text\">filter()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const list = ['Apple', 'Orange', 'Egg']\nlist.map(item => item[0]).filter(item => item === 'A') //'A'</code></pre></div>\n<p>In React, composition allows you to have some pretty cool advantages.</p>\n<p>You create small and lean components and use them to <em>compose</em> more functionality on top of them. How?</p>\n<h4>Create specialized version of a component</h4>\n<p>Use an outer component to expand and specialize a more generic component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = props => {\n  return &lt;button>{props.text}&lt;/button>\n}\n\nconst SubmitButton = () => {\n  return &lt;Button text=\"Submit\" />\n}\n\nconst LoginButton = () => {\n  return &lt;Button text=\"Login\" />\n}</code></pre></div>\n<h4>Pass methods as props</h4>\n<p>A component can focus on tracking a click event, for example, and what actually happens when the click event happens is up to the container component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = props => {\n  return &lt;button onClick={props.onClickHandler}>{props.text}&lt;/button>\n}\n\nconst LoginButton = props => {\n  return &lt;Button text=\"Login\" onClickHandler={props.onClickHandler} />\n}\n\nconst Container = () => {\n  const onClickHandler = () => {\n    alert('clicked')\n  }\n  \n  return &lt;LoginButton onClickHandler={onClickHandler} />\n}</code></pre></div>\n<h4>Using children</h4>\n<p>The <code class=\"language-text\">props.children</code> property allows you to inject components inside other components.</p>\n<p>The component needs to output <code class=\"language-text\">props.children</code> in its JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Sidebar = props => {\n  return &lt;aside>{props.children}&lt;/aside>\n}</code></pre></div>\n<p>and you embed more components into it in a transparent way:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Sidebar>\n  &lt;Link title=\"First link\" />\n  &lt;Link title=\"Second link\" />\n&lt;/Sidebar></code></pre></div>\n<h4>Higher order components</h4>\n<p>When a component receives a component as a prop and returns a component, it's called higher order component.</p>\n<p>We'll see them in a little while.</p>\n<h3>The Virtual DOM</h3>\n<p>Many existing frameworks, before React came on the scene, were directly manipulating the DOM on every change.</p>\n<p>First, what is the DOM?</p>\n<p>The DOM (<em>Document Object Model</em>) is a Tree representation of the page, starting from the <code class=\"language-text\">&lt;ht</code>ml> tag, going down into every child, which are called nodes.</p>\n<p>It's kept in the browser memory, and directly linked to what you see in a page. The DOM has an API that you can use to traverse it, access every single node, filter them, modify them.</p>\n<p>The API is the familiar syntax you have likely seen many times, if you were not using the abstract API provided by jQuery and friends:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">document.getElementById(id)\ndocument.getElementsByTagName(name)\ndocument.createElement(name)\nparentNode.appendChild(node)\nelement.innerHTML\nelement.style.left\nelement.setAttribute()\nelement.getAttribute()\nelement.addEventListener()\nwindow.content\nwindow.onload\nwindow.dump()\nwindow.scrollTo()</code></pre></div>\n<p>React keeps a copy of the DOM representation, for what concerns the React rendering: the Virtual DOM</p>\n<h4>The Virtual DOM Explained</h4>\n<p>Every time the DOM changes, the browser has to do two intensive operations: repaint (visual or content changes to an element that do not affect the layout and positioning relative to other elements) and reflow (recalculate the layout of a portion of the page — or the whole page layout).</p>\n<p>React uses a Virtual DOM to help the browser use less resources when changes need to be done on a page.</p>\n<p>When you call <code class=\"language-text\">setState()</code> on a Component, specifying a state different than the previous one, React marks that Component as <strong>dirty</strong>. This is key: React only updates when a Component changes the state explicitly.</p>\n<p>What happens next is:</p>\n<ul>\n<li>React updates the Virtual DOM relative to the components marked as dirty (with some additional checks, like triggering <code class=\"language-text\">shouldComponentUpdate()</code>)</li>\n<li>Runs the diffing algorithm to reconcile the changes</li>\n<li>Updates the real DOM</li>\n</ul>\n<h4>Why is the Virtual DOM helpful: batching</h4>\n<p>The key thing is that React batches much of the changes and performs a unique update to the real DOM, by changing all the elements that need to be changed at the same time, so the repaint and reflow the browser must perform to render the changes are executed just once.</p>\n<h3>Unidirectional Data Flow</h3>\n<p>Working with React you might encounter the term Unidirectional Data Flow. What does it mean? Unidirectional Data Flow is not a concept unique to React, but as a JavaScript developer this might be the first time you hear it.</p>\n<p>In general this concept means that data has one, and only one, way to be transferred to other parts of the application.</p>\n<p>In React this means that:</p>\n<ul>\n<li>state is passed to the view and to child components</li>\n<li>actions are triggered by the view</li>\n<li>actions can update the state</li>\n<li>the state change is passed to the view and to child components</li>\n</ul>\n<p>The view is a result of the application state. State can only change when actions happen. When actions happen, the state is updated.</p>\n<p>Thanks to one-way bindings, data cannot flow in the opposite way (as would happen with two-way bindings, for example), and this has some key advantages:</p>\n<ul>\n<li>it's less error prone, as you have more control over your data</li>\n<li>it's easier to debug, as you know <em>what</em> is coming from <em>where</em></li>\n<li>it's more efficient, as the library already knows what the boundaries are of each part of the system</li>\n</ul>\n<p>A state is always owned by one Component. Any data that's affected by this state can only affect Components below it: its children.</p>\n<p>Changing state on a Component will never affect its parent, or its siblings, or any other Component in the application: just its children.</p>\n<p>This is the reason that the state is often moved up in the Component tree, so that it can be shared between components that need to access it.</p>\n<h3>SECTION 3: IN-DEPTH REACT</h3>\n<h3>JSX</h3>\n<p>JSX is a technology that was introduced by React.</p>\n<p>Although React can work completely fine without using JSX, it's an ideal technology to work with components, so React benefits a lot from JSX.</p>\n<p>At first, you might think that using JSX is like mixing HTML and <a href=\"https://flaviocopes.com/javascript/\">JavaScript</a> (and as you'll see CSS).</p>\n<p>But this is not true, because what you are really doing when using JSX syntax is writing a declarative syntax of what a component UI should be.</p>\n<p>And you're describing that UI not using strings, but instead using JavaScript, which allows you to do many nice things.</p>\n<h4>A JSX primer</h4>\n<p>Here is how you define a h1 tag containing a string:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const element = &lt;h1>Hello, world!&lt;/h1></code></pre></div>\n<p>It looks like a strange mix of JavaScript and HTML, but in reality it's all JavaScript.</p>\n<p>What looks like HTML, is actually syntactic sugar for defining components and their positioning inside the markup.</p>\n<p>Inside a JSX expression, attributes can be inserted very easily:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const myId = 'test'\nconst element = &lt;h1 id={myId}>Hello, world!&lt;/h1></code></pre></div>\n<p>You just need to pay attention when an attribute has a dash (<code class=\"language-text\">-</code>) which is converted to camelCase syntax instead, and these 2 special cases:</p>\n<ul>\n<li><code class=\"language-text\">class</code> becomes <code class=\"language-text\">className</code></li>\n<li><code class=\"language-text\">for</code> becomes <code class=\"language-text\">htmlFor</code></li>\n</ul>\n<p>because they are reserved words in JavaScript.</p>\n<p>Here's a JSX snippet that wraps two components into a <code class=\"language-text\">div</code> tag:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  &lt;BlogPostsList />\n  &lt;Sidebar />\n&lt;/div></code></pre></div>\n<p>A tag always needs to be closed, because this is more XML than HTML (if you remember the XHTML days, this will be familiar, but since then the HTML5 loose syntax won). In this case a self-closing tag is used.</p>\n<p>Notice how I wrapped the 2 components into a <code class=\"language-text\">div</code>. Why? Because <strong>the render() function can only return a single node</strong>, so in case you want to return 2 siblings, just add a parent. It can be any tag, not just <code class=\"language-text\">div</code>.</p>\n<h4>Transpiling JSX</h4>\n<p>A browser cannot execute JavaScript files containing JSX code. They must be first transformed to regular JS.</p>\n<p>How? By doing a process called <strong>transpiling</strong>.</p>\n<p>We already said that JSX is optional, because to every JSX line, a corresponding plain JavaScript alternative is available, and that's what JSX is transpiled to.</p>\n<p>For example the following two constructs are equivalent:</p>\n<blockquote>\n<p><em>Plain JS</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(\n  React.DOM.div(\n    { id: 'test' },\n    React.DOM.h1(null, 'A title'),\n    React.DOM.p(null, 'A paragraph')\n  ),\n  document.getElementById('myapp')\n)</code></pre></div>\n<blockquote>\n<p><em>JSX</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(\n  &lt;div id=\"test\">\n    &lt;h1>A title&lt;/h1>\n    &lt;p>A paragraph&lt;/p>\n  &lt;/div>,\n  document.getElementById('myapp')\n)</code></pre></div>\n<p>This very basic example is just the starting point, but you can already see how more complicated the plain JS syntax is compared to using JSX.</p>\n<p>At the time of writing the most popular way to perform the <strong>transpilation</strong> is to use <strong>Babel</strong>, which is the default option when running <code class=\"language-text\">create-react-app</code>, so if you use it you don't have to worry, everything happens under the hood for you.</p>\n<p>If you don't use <code class=\"language-text\">create-react-app</code> you need to setup Babel yourself.</p>\n<h4>JS in JSX</h4>\n<p>JSX accepts any kind of JavaScript mixed into it.</p>\n<p>Whenever you need to add some JS, just put it inside curly braces <code class=\"language-text\">{}</code>. For example here's how to use a constant value defined elsewhere:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const paragraph = 'A paragraph'\nReactDOM.render(\n  &lt;div id=\"test\">\n    &lt;h1>A title&lt;/h1>\n    &lt;p>{paragraph}&lt;/p>\n  &lt;/div>,\n  document.getElementById('myapp')\n)</code></pre></div>\n<p>This is a basic example. Curly braces accept <em>any</em> JS code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const paragraph = 'A paragraph'\nReactDOM.render(\n  &lt;table>\n    {rows.map((row, i) => {\n      return &lt;tr>{row.text}&lt;/tr>\n    })}\n  &lt;/table>,\n  document.getElementById('myapp')\n)</code></pre></div>\n<p>As you can see <em>we nested JavaScript inside JSX defined inside JavaScript nested in JSX</em>. You can go as deep as you need.</p>\n<h4>HTML in JSX</h4>\n<p>JSX resembles HTML a lot, but it's actually XML syntax.</p>\n<p>In the end you render HTML, so you need to know a few differences between how you would define some things in HTML, and how you define them in JSX.</p>\n<h4>You need to close all tags</h4>\n<p>Just like in XHTML, if you have ever used it, you need to close all tags: no more <code class=\"language-text\">&lt;br></code> but instead use the self-closing tag: <code class=\"language-text\">&lt;br /></code> (the same goes for other tags)</p>\n<h4>camelCase is the new standard</h4>\n<p>In HTML you'll find attributes without any case (e.g. <code class=\"language-text\">onchange</code>). In JSX, they are renamed to their camelCase equivalent:</p>\n<ul>\n<li><code class=\"language-text\">onchange</code> => <code class=\"language-text\">onChange</code></li>\n<li><code class=\"language-text\">onclick</code> => <code class=\"language-text\">onClick</code></li>\n<li><code class=\"language-text\">onsubmit</code> => <code class=\"language-text\">onSubmit</code></li>\n</ul>\n<h4><code class=\"language-text\">class</code> becomes <code class=\"language-text\">className</code></h4>\n<p>Due to the fact that JSX is JavaScript, and <code class=\"language-text\">class</code> is a reserved word, you can't write</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p class=\"description\"></code></pre></div>\n<p>but you need to use</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p className=\"description\"></code></pre></div>\n<p><strong>The same applies to <code class=\"language-text\">for</code></strong> which is translated to <code class=\"language-text\">htmlFor</code>.</p>\n<h4>CSS in React</h4>\n<p>JSX provides a cool way to define CSS.</p>\n<p>If you have a little experience with HTML inline styles, at first glance you'll find yourself pushed back 10 or 15 years, to a world where inline CSS was completely normal (nowadays it's demonized and usually just a \"quick fix\" go-to solution).</p>\n<p>JSX style is not the same thing: first of all, instead of accepting a string containing CSS properties, the JSX <code class=\"language-text\">style</code> attribute only accepts an object. This means you define properties in an object:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var divStyle = {\n  color: 'white'\n}\n\nReactDOM.render(&lt;div style={divStyle}>Hello World!&lt;/div>, mountNode)</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(&lt;div style={{ color: 'white' }}>Hello World!&lt;/div>, mountNode)</code></pre></div>\n<p>The CSS values you write in JSX are slightly different from plain CSS:</p>\n<ul>\n<li>the keys property names are camelCased</li>\n<li>values are just strings</li>\n<li>you separate each tuple with a comma</li>\n</ul>\n<h4>Why is this preferred over plain CSS / SASS / LESS?</h4>\n<p>CSS is an <strong>unsolved problem</strong>. Since its inception, dozens of tools around it rose and then fell. The main problem with JS is that there is no scoping and it's easy to write CSS that is not enforced in any way, thus a \"quick fix\" can impact elements that should not be touched.</p>\n<p>JSX allows components (defined in React for example) to completely encapsulate their style.</p>\n<h4>Is this the go-to solution?</h4>\n<p>Inline styles in JSX are good until you need to</p>\n<ol>\n<li>write media queries</li>\n<li>style animations</li>\n<li>reference pseudo classes (e.g. <code class=\"language-text\">:hover</code>)</li>\n<li>reference pseudo elements (e.g. <code class=\"language-text\">::first-letter</code>)</li>\n</ol>\n<p>In short, they cover the basics, but it's not the final solution.</p>\n<h4>Forms in JSX</h4>\n<p>JSX adds some changes to how HTML forms work, with the goal of making things easier for the developer.</p>\n<h4><code class=\"language-text\">value</code> and <code class=\"language-text\">defaultValue</code></h4>\n<p>The <code class=\"language-text\">value</code> attribute always holds the current value of the field.</p>\n<p>The <code class=\"language-text\">defaultValue</code> attribute holds the default value that was set when the field was created.</p>\n<p><em>This helps solve some weird behavior of regular <a href=\"https://flaviocopes.com/dom/\">DOM</a> interaction when inspecting <code class=\"language-text\">input.value</code> and <code class=\"language-text\">input.getAttribute('value')</code> returning one the current value and one the original default value.</em></p>\n<p>This also applies to the <code class=\"language-text\">textarea</code> field, e.g.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;textarea>Some text&lt;/textarea></code></pre></div>\n<p>but instead</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;textarea defaultValue={'Some text'} /></code></pre></div>\n<p>For <code class=\"language-text\">select</code> fields, instead of using</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;select>\n  &lt;option value=\"x\" selected>\n    ...\n  &lt;/option>\n&lt;/select></code></pre></div>\n<p>use</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;select defaultValue=\"x\">\n  &lt;option value=\"x\">...&lt;/option>\n&lt;/select></code></pre></div>\n<h4>A more consistent onChange</h4>\n<p>Passing a function to the <code class=\"language-text\">onChange</code> attribute you can subscribe to events on form fields.</p>\n<p>It works consistently across fields, even <code class=\"language-text\">radio</code>, <code class=\"language-text\">select</code> and <code class=\"language-text\">checkbox</code> input fields fire a <code class=\"language-text\">onChange</code> event.</p>\n<p><code class=\"language-text\">onChange</code> also fires when typing a character into an <code class=\"language-text\">input</code> or <code class=\"language-text\">textarea</code> field.</p>\n<h4>JSX auto escapes</h4>\n<p>To mitigate the ever present risk of XSS exploits, JSX forces automatic escaping in expressions.</p>\n<p>This means that you might run into issues when using an HTML entity in a string expression.</p>\n<p>You expect the following to print <code class=\"language-text\">© 2017</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>{'© 2017'}&lt;/p></code></pre></div>\n<p>But it's not, it's printing <code class=\"language-text\">© 2017</code> because the string is escaped.</p>\n<p>To fix this you can either move the entities outside the expression:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>© 2017&lt;/p></code></pre></div>\n<p>or by using a constant that prints the Unicode representation corresponding to the HTML entity you need to print:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>{'\\u00A9 2017'}&lt;/p></code></pre></div>\n<h4>White space in JSX</h4>\n<p>To add white space in JSX there are 2 rules:</p>\n<p><strong>Rule 1: Horizontal white space is trimmed to 1</strong></p>\n<p>If you have white space between elements in the same line, it's all trimmed to 1 white space.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>Something       becomes               this&lt;/p></code></pre></div>\n<p>becomes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>Something becomes this&lt;/p></code></pre></div>\n<p><strong>Rule 2: Vertical white space is eliminated</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>\n  Something\n  becomes\n  this\n&lt;/p></code></pre></div>\n<p>becomes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>Somethingbecomesthis&lt;/p></code></pre></div>\n<p>To fix this problem you need to explicitly add white space, by adding a space expression like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>\n  Something\n  {' '}becomes\n  {' '}this\n&lt;/p></code></pre></div>\n<p>or by embedding the string in a space expression:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>\n  Something\n  {' becomes '}\n  this\n&lt;/p></code></pre></div>\n<p>You can add comments to JSX by using the normal JavaScript comments inside an expression:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p>\n  {/* a comment */}\n  {\n    //another comment\n  }\n&lt;/p></code></pre></div>\n<h4>Spread attributes</h4>\n<p>In JSX a common operation is assigning values to attributes.</p>\n<p>Instead of doing it manually, e.g.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  &lt;BlogPost title={data.title} date={data.date} />\n&lt;/div></code></pre></div>\n<p>you can pass</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  &lt;BlogPost {...data} />\n&lt;/div></code></pre></div>\n<p>and the properties of the <code class=\"language-text\">data</code> object will be used as attributes automatically, thanks to the <em>ES6 spread operator</em>.</p>\n<h4>How to loop in JSX</h4>\n<p>If you have a set of elements you need to loop upon to generate a JSX partial, you can create a loop, and then add JSX to an array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const elements = [] //..some array\n\nconst items = []\n\nfor (const [index, value] of elements.entries()) {\n  items.push(&lt;Element key={index} />)\n}</code></pre></div>\n<p>Now when rendering the JSX you can embed the <code class=\"language-text\">items</code> array simply by wrapping it in curly braces:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const elements = ['one', 'two', 'three'];\n\nconst items = []\n\nfor (const [index, value] of elements.entries()) {\n  items.push(&lt;li key={index}>{value}&lt;/li>)\n}\n\nreturn (\n  &lt;div>\n    {items}\n  &lt;/div>\n)</code></pre></div>\n<p>You can do the same directly in the JSX, using <code class=\"language-text\">map</code> instead of a for-of loop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const elements = ['one', 'two', 'three'];\nreturn (\n  &lt;ul>\n    {elements.map((value, index) => {\n      return &lt;li key={index}>{value}&lt;/li>\n    })}\n  &lt;/ul>\n)</code></pre></div>\n<h3>Components</h3>\n<p>A component is one isolated piece of interface. For example in a typical blog homepage you might find the Sidebar component, and the Blog Posts List component. They are in turn composed of components themselves, so you could have a list of Blog post components, each for every blog post, and each with its own peculiar properties.</p>\n<p>React makes it very simple: everything is a component.</p>\n<p>Even plain HTML tags are component on their own, and they are added by default.</p>\n<p>The next 2 lines are equivalent, they do the same thing. One with *<strong>*JSX**</strong>, one without, by injecting <code class=\"language-text\">&lt;h1>Hello World!&lt;/h1></code> into an element with id <code class=\"language-text\">app</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\nimport ReactDOM from 'react-dom'\n\nReactDOM.render(&lt;h1>Hello World!&lt;/h1>, document.getElementById('app'))\n\nReactDOM.render(\n  React.DOM.h1(null, 'Hello World!'),\n  document.getElementById('app')\n)</code></pre></div>\n<p>See, <code class=\"language-text\">React.DOM</code> exposed us an <code class=\"language-text\">h1</code> component. Which other HTML tags are available? All of them! You can inspect what <code class=\"language-text\">React.DOM</code> offers by typing it in the Browser Console:</p>\n<p>(the list is longer)</p>\n<p>The built-in components are nice, but you'll quickly outgrow them. What React excels in is letting us compose a UI by composing custom components.</p>\n<h4>Custom components</h4>\n<p>There are 2 ways to define a component in React.</p>\n<p>A function component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const BlogPostExcerpt = () => {\n  return (\n    &lt;div>\n      &lt;h1>Title&lt;/h1>\n      &lt;p>Description&lt;/p>\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>A class component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { Component } from 'react'\n\nclass BlogPostExcerpt extends Component {\n  render() {\n    return (\n      &lt;div>\n        &lt;h1>Title&lt;/h1>\n        &lt;p>Description&lt;/p>\n      &lt;/div>\n    )\n  }\n}</code></pre></div>\n<p>Up until recently, class components were the only way to define a component that had its own state, and could access the lifecycle methods so you could do things when the component was first rendered, updated or removed.</p>\n<p>React Hooks changed this, so our function components are now much more powerful than ever and I believe we'll see fewer and fewer class components in the future, although it will still be perfectly valid way to create components.</p>\n<p>There is also a third syntax which uses the <code class=\"language-text\">ES5</code> syntax, without the classes:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\n\nReact.createClass({\n  render() {\n    return (\n      &lt;div>\n        &lt;h1>Title&lt;/h1>\n        &lt;p>Description&lt;/p>\n      &lt;/div>\n    )\n  }\n})</code></pre></div>\n<p>You'll rarely see this in modern, <code class=\"language-text\">> ES6</code> codebases.</p>\n<h3>State</h3>\n<h4>Setting the default state of a component</h4>\n<p>In the Component constructor, initialize <code class=\"language-text\">this.state</code>. For example the BlogPostExcerpt component might have a <code class=\"language-text\">clicked</code> state:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class BlogPostExcerpt extends Component {\n  constructor(props) {\n    super(props)\n    this.state = { clicked: false }\n  }\n  \n  render() {\n    return (\n      &lt;div>\n        &lt;h1>Title&lt;/h1>\n        &lt;p>Description&lt;/p>\n      &lt;/div>\n    )\n  }\n}</code></pre></div>\n<h4>Accessing the state</h4>\n<p>The <em>clicked</em> state can be accessed by referencing <code class=\"language-text\">this.state.clicked</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class BlogPostExcerpt extends Component {\n  constructor(props) {\n    super(props)\n    this.state = { clicked: false }\n  }\n  \n  render() {\n    return (\n      &lt;div>\n        &lt;h1>Title&lt;/h1>\n        &lt;p>Description&lt;/p>\n        &lt;p>Clicked: {this.state.clicked}&lt;/p>\n      &lt;/div>\n    )\n  }\n}</code></pre></div>\n<h4>Mutating the state</h4>\n<p>A state should never be mutated by using</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.state.clicked = true</code></pre></div>\n<p>Instead, you should always use <code class=\"language-text\">setState()</code> instead, passing it an object:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">this.setState({ clicked: true })</code></pre></div>\n<p>The object can contain a subset, or a superset, of the state. Only the properties you pass will be mutated, the ones omitted will be left in their current state.</p>\n<h4>Why you should always use <code class=\"language-text\">setState()</code></h4>\n<p>The reason is that using this method, React knows that the state has changed. It will then start the series of events that will lead to the Component being re-rendered, along with any <a href=\"https://flaviocopes.com/dom/\">DOM</a> update.</p>\n<h4>Unidirectional Data Flow</h4>\n<p>A state is always owned by one Component. Any data that's affected by this state can only affect Components below it: its children.</p>\n<p>Changing the state on a Component will never affect its parent, or its siblings, or any other Component in the application: just its children.</p>\n<p>This is the reason the state is often moved up in the Component tree.</p>\n<h4>Moving the State Up in the Tree</h4>\n<p>Because of the Unidirectional Data Flow rule, if two components need to share state, the state needs to be moved up to a common ancestor.</p>\n<p>Many times the closest ancestor is the best place to manage the state, but it's not a mandatory rule.</p>\n<p>The state is passed down to the components that need that value via props:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Converter extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = { currency: '€' }\n  }\n  \n  render() {\n    return (\n      &lt;div>\n        &lt;Display currency={this.state.currency} />\n        &lt;CurrencySwitcher currency={this.state.currency} />\n      &lt;/div>\n    )\n  }\n}</code></pre></div>\n<p>The state can be mutated by a child component by passing a mutating function down as a prop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Converter extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = { currency: '€' }\n  }\n  \n  handleChangeCurrency = event => {\n    this.setState({ currency: this.state.currency === '€' ? '$' : '€' })\n  }\n  \n  render() {\n    return (\n      &lt;div>\n        &lt;Display currency={this.state.currency} />\n        &lt;CurrencySwitcher\n          currency={this.state.currency}\n          handleChangeCurrency={this.handleChangeCurrency}\n        />\n      &lt;/div>\n    )\n  }\n}\n\nconst CurrencySwitcher = props => {\n  return (\n    &lt;button onClick={props.handleChangeCurrency}>\n      Current currency is {props.currency}. Change it!\n    &lt;/button>\n  )\n}\n\nconst Display = props => {\n  return &lt;p>Current currency is {props.currency}.&lt;/p>\n}</code></pre></div>\n<h3>Props</h3>\n<p>Props is how Components get their properties. Starting from the top component, every child component gets its props from the parent. In a function component, props is all it gets passed, and they are available by adding <code class=\"language-text\">props</code> as the function argument:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const BlogPostExcerpt = props => {\n  return (\n    &lt;div>\n      &lt;h1>{props.title}&lt;/h1>\n      &lt;p>{props.description}&lt;/p>\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>In a class component, props are passed by default. There is no need to add anything special, and they are accessible as <code class=\"language-text\">this.props</code> in a Component instance.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { Component } from 'react'\n\nclass BlogPostExcerpt extends Component {\n  render() {\n    return (\n      &lt;div>\n        &lt;h1>{this.props.title}&lt;/h1>\n        &lt;p>{this.props.description}&lt;/p>\n      &lt;/div>\n    )\n  }\n}</code></pre></div>\n<p>Passing props down to child components is a great way to pass values around in your application. A component either holds data (has state) or receives data through its props.</p>\n<p>It gets complicated when:</p>\n<ul>\n<li>you need to access the state of a component from a child that's several levels down (all the previous children need to act as a pass-through, even if they do not need to know the state, complicating things)</li>\n<li>you need to access the state of a component from a completely unrelated component.</li>\n</ul>\n<h4>Default values for props</h4>\n<p>If any value is not required we need to specify a default value for it if it's missing when the Component is initialized.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">BlogPostExcerpt.propTypes = {\n  title: PropTypes.string,\n  description: PropTypes.string\n}\n\nBlogPostExcerpt.defaultProps = {\n  title: '',\n  description: ''\n}</code></pre></div>\n<p>Some tooling like <a href=\"https://flaviocopes.com/eslint/\">ESLint</a> have the ability to enforce defining the defaultProps for a Component with some propTypes not explicitly required.</p>\n<h4>How props are passed</h4>\n<p>When initializing a component, pass the props in a way similar to HTML attributes:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const desc = 'A description'\n//...\n&lt;BlogPostExcerpt title=\"A blog post\" description={desc} /></code></pre></div>\n<p>We passed the title as a plain string (something we can <em>only</em> do with strings!), and description as a variable.</p>\n<h4>Children</h4>\n<p>A special prop is <code class=\"language-text\">children</code>. That contains the value of anything that is passed in the <code class=\"language-text\">body</code> of the component, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;BlogPostExcerpt title=\"A blog post\" description=\"{desc}\">\n  Something\n&lt;/BlogPostExcerpt></code></pre></div>\n<p>In this case, inside <code class=\"language-text\">BlogPostExcerpt</code> we could access \"Something\" by looking up <code class=\"language-text\">this.props.children</code>.</p>\n<p>While Props allow a Component to receive properties from its parent, to be \"instructed\" to print some data for example, state allows a component to take on life itself, and be independent of the surrounding environment.</p>\n<h3>Presentational vs container components</h3>\n<p>In React, components are often divided into 2 big buckets: <strong>presentational components</strong> and <strong>container components</strong>.</p>\n<p>Each of those have their unique characteristics.</p>\n<p>Presentational components are mostly concerned with generating some markup to be outputted.</p>\n<p>They don't manage any kind of state, except for state related the the presentation</p>\n<p>Container components are mostly concerned with the \"backend\" operations.</p>\n<p>They might handle the state of various sub-components. They might wrap several presentational components. They might interface with Redux.</p>\n<p>As a way to simplify the distinction, we can say <strong>presentational components are concerned with the look</strong>, <strong>container components are concerned with making things work</strong>.</p>\n<p>For example, this is a presentational component. It gets data from its props, and just focuses on showing an element:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Users = props => (\n  &lt;ul>\n    {props.users.map(user => (\n      &lt;li>{user}&lt;/li>\n    ))}\n  &lt;/ul>\n)</code></pre></div>\n<p>On the other hand this is a container component. It manages and stores its own data, and uses the presentational component to display it.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class UsersContainer extends React.Component {\n  constructor() {\n    this.state = {\n      users: []\n    }\n  }\n  \n  componentDidMount() {\n    axios.get('/users').then(users =>\n      this.setState({ users: users }))\n    )\n  }\n  \n  render() {\n    return &lt;Users users={this.state.users} />\n  }\n}</code></pre></div>\n<h3>State vs props</h3>\n<p>In a React component, <strong>props</strong> are variables passed to it by its parent component. <strong>State</strong> on the other hand is still variables, but directly initialized and managed by the component.</p>\n<p>The state can be initialized by props.</p>\n<p>For example, a parent component might include a child component by calling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;ChildComponent /></code></pre></div>\n<p>The parent can pass a prop by using this syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;ChildComponent color=green /></code></pre></div>\n<p>Inside the ChildComponent constructor we could access the prop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class ChildComponent extends React.Component {\n  constructor(props) {\n    super(props)\n    console.log(props.color)\n  }\n}</code></pre></div>\n<p>and any other method in this class can reference the props using <code class=\"language-text\">this.props</code>.</p>\n<p>Props can be used to set the internal state based on a prop value in the constructor, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class ChildComponent extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state.colorName = props.color\n  }\n}</code></pre></div>\n<p>Of course a component can also initialize the state without looking at props.</p>\n<p>In this case there's nothing useful going on, but imagine doing something different based on the prop value, probably setting a state value is best.</p>\n<p>Props should never be changed in a child component, so if there's something going on that alters some variable, that variable should belong to the component state.</p>\n<p>Props are also used to allow child components to access methods defined in the parent component. This is a good way to centralize managing the state in the parent component, and avoid children having the need to have their own state.</p>\n<p>Most of your components will just display some kind of information based on the props they received, and stay <strong>stateless</strong>.</p>\n<h3>PropTypes</h3>\n<p>Since JavaScript is a dynamically typed language, we don't really have a way to enforce the type of a variable at compile time, and if we pass invalid types, they will fail at runtime or give weird results if the types are compatible but not what we expect.</p>\n<p>Flow and TypeScript help a lot, but React has a way to directly help with props types, and even before running the code, our tools (editors, linters) can detect when we are passing the wrong values:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import PropTypes from 'prop-types'\nimport React from 'react'\n\nclass BlogPostExcerpt extends Component {\n  render() {\n    return (\n      &lt;div>\n        &lt;h1>{this.props.title}&lt;/h1>\n        &lt;p>{this.props.description}&lt;/p>\n      &lt;/div>\n    )\n  }\n}\n\nBlogPostExcerpt.propTypes = {\n  title: PropTypes.string,\n  description: PropTypes.string\n}\n\nexport default BlogPostExcerpt</code></pre></div>\n<h4>Which types can we use</h4>\n<p>These are the fundamental types we can accept:</p>\n<ul>\n<li>PropTypes.array</li>\n<li>PropTypes.bool</li>\n<li>PropTypes.func</li>\n<li>PropTypes.number</li>\n<li>PropTypes.object</li>\n<li>PropTypes.string</li>\n<li>PropTypes.symbol</li>\n</ul>\n<p>We can accept one of two types:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PropTypes.oneOfType([\n  PropTypes.string,\n  PropTypes.number\n]),</code></pre></div>\n<p>We can accept one of many values:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PropTypes.oneOf(['Test1', 'Test2']),</code></pre></div>\n<p>We can accept an instance of a class:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PropTypes.instanceOf(Something)</code></pre></div>\n<p>We can accept any React node:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PropTypes.node</code></pre></div>\n<p>or even any type at all:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PropTypes.any</code></pre></div>\n<p>Arrays have a special syntax that we can use to accept an array of a particular type:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PropTypes.arrayOf(PropTypes.string)</code></pre></div>\n<p>We can compose object properties by using</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PropTypes.shape({\n  color: PropTypes.string,\n  fontSize: PropTypes.number\n})</code></pre></div>\n<h4>Requiring properties</h4>\n<p>Appending <code class=\"language-text\">isRequired</code> to any PropTypes option will cause React to return an error if that property is missing:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">PropTypes.arrayOf(PropTypes.string).isRequired,\nPropTypes.string.isRequired,</code></pre></div>\n<h3>React Fragment</h3>\n<p>Notice how I wrap return values in a <code class=\"language-text\">div</code>. This is because a component can only return one single element, and if you want more than one, you need to wrap it with another container tag.</p>\n<p>This, however, causes an unnecessary <code class=\"language-text\">div</code> in the output. You can avoid this by using <code class=\"language-text\">React.Fragment</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { Component } from 'react'\n\nclass BlogPostExcerpt extends Component {\n  render() {\n    return (\n      &lt;React.Fragment>\n        &lt;h1>{this.props.title}&lt;/h1>\n        &lt;p>{this.props.description}&lt;/p>\n      &lt;/React.Fragment>\n    )\n  }\n}</code></pre></div>\n<p>which also has a very nice shorthand syntax <code class=\"language-text\">&lt;>\n&lt;/></code> that is supported only in recent releases (and Babel 7+):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { Component } from 'react'\n\nclass BlogPostExcerpt extends Component {\n  render() {\n    return (\n      &lt;>\n        &lt;h1>{this.props.title}&lt;/h1>\n        &lt;p>{this.props.description}&lt;/p>\n      &lt;/>\n    )\n  }\n}</code></pre></div>\n<h3>Events</h3>\n<p>React provides an easy way to manage events. Prepare to say goodbye to <code class=\"language-text\">addEventListener</code>.</p>\n<p>In the previous article about the State you saw this example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const CurrencySwitcher = props => {\n  return (\n    &lt;button onClick={props.handleChangeCurrency}>\n      Current currency is {props.currency}. Change it!\n    &lt;/button>\n  )\n}</code></pre></div>\n<p>If you've been using JavaScript for a while, this is just like plain old <a href=\"https://flaviocopes.com/javascript-events/\">JavaScript event handlers</a>, except that this time you're defining everything in JavaScript, not in your HTML, and you're passing a function, not a string.</p>\n<p>The actual event names are a little bit different because in React you use camelCase for everything, so <code class=\"language-text\">onclick</code> becomes <code class=\"language-text\">onClick</code>, <code class=\"language-text\">onsubmit</code> becomes <code class=\"language-text\">onSubmit</code>.</p>\n<p>For reference, this is old school HTML with JavaScript events mixed in:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;button onclick=\"handleChangeCurrency()\">...&lt;;/button></code></pre></div>\n<h4>Event handlers</h4>\n<p>It's a convention to have event handlers defined as methods on the Component class:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Converter extends React.Component {\n  handleChangeCurrency = event => {\n    this.setState({ currency: this.state.currency === '€' ? '$' : '€' })\n  }\n}</code></pre></div>\n<p>All handlers receive an event object that adheres, cross-browser, to the <a href=\"https://www.w3.org/TR/DOM-Level-3-Events/\">W3C UI Events spec</a>.</p>\n<h4>Bind <code class=\"language-text\">this</code> in methods</h4>\n<p>If you use class components, don't forget to bind methods. The methods of ES6 classes by default are not bound. What this means is that <code class=\"language-text\">this</code> is not defined unless you define methods as arrow functions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Converter extends React.Component {\n  handleClick = e => {\n    /* ... */\n  }\n  //...\n}</code></pre></div>\n<p>when using the the property initializer syntax with Babel (enabled by default in <code class=\"language-text\">create-react-app</code>), otherwise you need to bind it manually in the constructor:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Converter extends React.Component {\n  constructor(props) {\n    super(props)\n    this.handleClick = this.handleClick.bind(this)\n  }\n  handleClick(e) {}\n}</code></pre></div>\n<h3>The events reference</h3>\n<p>There are lots of events supported, here's a summary list.</p>\n<h4>Clipboard</h4>\n<ul>\n<li>onCopy</li>\n<li>onCut</li>\n<li>onPaste</li>\n</ul>\n<h4>Composition</h4>\n<ul>\n<li>onCompositionEnd</li>\n<li>onCompositionStart</li>\n<li>onCompositionUpdate</li>\n</ul>\n<h4>Keyboard</h4>\n<ul>\n<li>onKeyDown</li>\n<li>onKeyPress</li>\n<li>onKeyUp</li>\n</ul>\n<h4>Focus</h4>\n<ul>\n<li>onFocus</li>\n<li>onBlur</li>\n</ul>\n<h4>Form</h4>\n<ul>\n<li>onChange</li>\n<li>onInput</li>\n<li>onSubmit</li>\n</ul>\n<h4>Mouse</h4>\n<ul>\n<li>onClick</li>\n<li>onContextMenu</li>\n<li>onDoubleClick</li>\n<li>onDrag</li>\n<li>onDragEnd</li>\n<li>onDragEnter</li>\n<li>onDragExit</li>\n<li>onDragLeave</li>\n<li>onDragOver</li>\n<li>onDragStart</li>\n<li>onDrop</li>\n<li>onMouseDown</li>\n<li>onMouseEnter</li>\n<li>onMouseLeave</li>\n<li>onMouseMove</li>\n<li>onMouseOut</li>\n<li>onMouseOver</li>\n<li>onMouseUp</li>\n</ul>\n<h4>Selection</h4>\n<ul>\n<li>onSelect</li>\n</ul>\n<h4>Touch</h4>\n<ul>\n<li>onTouchCancel</li>\n<li>onTouchEnd</li>\n<li>onTouchMove</li>\n<li>onTouchStart</li>\n</ul>\n<h4>UI</h4>\n<ul>\n<li>onScroll</li>\n</ul>\n<h4>Mouse Wheel</h4>\n<ul>\n<li>onWheel</li>\n</ul>\n<h4>Media</h4>\n<ul>\n<li>onAbort</li>\n<li>onCanPlay</li>\n<li>onCanPlayThrough</li>\n<li>onDurationChange</li>\n<li>onEmptied</li>\n<li>onEncrypted</li>\n<li>onEnded</li>\n<li>onError</li>\n<li>onLoadedData</li>\n<li>onLoadedMetadata</li>\n<li>onLoadStart</li>\n<li>onPause</li>\n<li>onPlay</li>\n<li>onPlaying</li>\n<li>onProgress</li>\n<li>onRateChange</li>\n<li>onSeeked</li>\n<li>onSeeking</li>\n<li>onStalled</li>\n<li>onSuspend</li>\n<li>onTimeUpdate</li>\n<li>onVolumeChange</li>\n<li>onWaiting</li>\n</ul>\n<h4>Image</h4>\n<ul>\n<li>onLoad</li>\n<li>onError</li>\n</ul>\n<h4>Animation</h4>\n<ul>\n<li>onAnimationStart</li>\n<li>onAnimationEnd</li>\n<li>onAnimationIteration</li>\n</ul>\n<h4>Transition</h4>\n<ul>\n<li>onTransitionEnd</li>\n</ul>\n<h3>Lifecycle Events</h3>\n<p>React class components can have hooks for several lifecycle events.</p>\n<blockquote>\n<p><em>Hooks allow function components to access them too, in a different way.</em></p>\n</blockquote>\n<p>During the lifetime of a component, there's a series of events that gets called, and to each event you can hook and provide custom functionality.</p>\n<p>What hook is best for what functionality is something we're going to see here.</p>\n<p>First, there are 3 phases in a React component lifecycle:</p>\n<ul>\n<li>Mounting</li>\n<li>Updating</li>\n<li>Unmounting</li>\n</ul>\n<p>Let's see those 3 phases in detail and the methods that get called for each.</p>\n<h4>Mounting</h4>\n<p>When mounting you have 4 lifecycle methods before the component is mounted in the DOM: the <code class=\"language-text\">constructor</code>, <code class=\"language-text\">getDerivedStateFromProps</code>, <code class=\"language-text\">render</code> and <code class=\"language-text\">componentDidMount</code>.</p>\n<h4>Constructor</h4>\n<p>The constructor is the first method that is called when mounting a component.</p>\n<p>You usually use the constructor to set up the initial state using <code class=\"language-text\">this.state = ...</code>.</p>\n<h4>getDerivedStateFromProps()</h4>\n<p>When the state depends on props, <code class=\"language-text\">getDerivedStateFromProps</code> can be used to update the state based on the props value.</p>\n<p>It was added in React 16.3, aiming to replace the <code class=\"language-text\">componentWillReceiveProps</code> deprecated method.</p>\n<p>In this method you haven't access to <code class=\"language-text\">this</code> as it's a static method.</p>\n<p>It's a pure method, so it should not cause side effects and should return the same output when called multiple times with the same input.</p>\n<p>Returns an object with the updated elements of the state (or null if the state does not change)</p>\n<h4>render()</h4>\n<p>From the render() method you return the JSX that builds the component interface.</p>\n<p>It's a pure method, so it should not cause side effects and should return the same output when called multiple times with the same input.</p>\n<h4>componentDidMount()</h4>\n<p>This method is the one that you will use to perform API calls, or process operations on the DOM.</p>\n<h4>Updating</h4>\n<p>When updating you have 5 lifecycle methods before the component is mounted in the DOM: the <code class=\"language-text\">getDerivedStateFromProps</code>, <code class=\"language-text\">shouldComponentUpdate</code>, <code class=\"language-text\">render</code>, <code class=\"language-text\">getSnapshotBeforeUpdate</code> and <code class=\"language-text\">componentDidUpdate</code>.</p>\n<h4>getDerivedStateFromProps()</h4>\n<p>See the above description for this method.</p>\n<h4>shouldComponentUpdate()</h4>\n<p>This method returns a boolean, <code class=\"language-text\">true</code> or <code class=\"language-text\">false</code>. You use this method to tell React if it should go on with the rerendering, and defaults to <code class=\"language-text\">true</code>. You will return <code class=\"language-text\">false</code> when rerendering is expensive and you want to have more control on when this happens.</p>\n<h4>render()</h4>\n<p>See the above description for this method.</p>\n<h4>getSnapshotBeforeUpdate()</h4>\n<p>In this method you have access to the props and state of the previous render, and of the current render.</p>\n<p>Its use cases are very niche, and it's probably the one that you will use less.</p>\n<h4>componentDidUpdate()</h4>\n<p>This method is called when the component has been updated in the DOM. Use this to run any 3rd party DOM API or call APIs that must be updated when the DOM changes.</p>\n<p>It corresponds to the <code class=\"language-text\">componentDidMount()</code> method from the mounting phase.</p>\n<h4>Unmounting</h4>\n<p>In this phase we only have one method, <code class=\"language-text\">componentWillUnmount</code>.</p>\n<h4>componentWillUnmount()</h4>\n<p>The method is called when the component is removed from the DOM. Use this to do any sort of cleanup you need to perform.</p>\n<h4>Legacy</h4>\n<p>If you are working on an app that uses <code class=\"language-text\">componentWillMount</code>, <code class=\"language-text\">componentWillReceiveProps</code> or <code class=\"language-text\">componentWillUpdate</code>, those were deprecated in React 16.3 and you should migrate to other lifecycle methods.</p>\n<h3>Forms in React</h3>\n<p>Forms are one of the few HTML elements that are interactive by default.</p>\n<p>They were designed to allow the user to interact with a page.</p>\n<p>Common uses of forms?</p>\n<ul>\n<li>Search</li>\n<li>Contact forms</li>\n<li>Shopping carts checkout</li>\n<li>Login and registration</li>\n<li>and more!</li>\n</ul>\n<p>Using React we can make our forms much more interactive and less static.</p>\n<p>There are two main ways of handling forms in React, which differ on a fundamental level: how data is managed.</p>\n<ul>\n<li>if the data is handled by the DOM, we call them <strong>uncontrolled components</strong></li>\n<li>if the data is handled by the components we call them <strong>controlled components</strong></li>\n</ul>\n<p>As you can imagine, controlled components is what you will use most of the time. The component state is the single source of truth, rather than the DOM. Some form fields are inherently uncontrolled because of their behavior, like the <code class=\"language-text\">&lt;input type=\"file\"></code> field.</p>\n<p>When an element state changes in a form field managed by a component, we track it using the <code class=\"language-text\">onChange</code> attribute.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Form extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = { username: '' }\n  }\n  \n  handleChange(event) {}\n  \n  render() {\n    return (\n      &lt;form>\n        Username:\n        &lt;input\n          type=\"text\"\n          value={this.state.username}\n          onChange={this.handleChange}\n        />\n      &lt;/form>\n    )\n  }\n}</code></pre></div>\n<p>In order to set the new state, we must bind <code class=\"language-text\">this</code> to the <code class=\"language-text\">handleChange</code> method, otherwise <code class=\"language-text\">this</code> is not accessible from within that method:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Form extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = { username: '' }\n    this.handleChange = this.handleChange.bind(this)\n  }\n  \n  handleChange(event) {\n    this.setState({ value: event.target.value })\n  }\n  \n  render() {\n    return (\n      &lt;form>\n        &lt;input\n          type=\"text\"\n          value={this.state.username}\n          onChange={this.handleChange}\n        />\n      &lt;/form>\n    )\n  }\n}</code></pre></div>\n<p>Similarly, we use the <code class=\"language-text\">onSubmit</code> attribute on the form to call the <code class=\"language-text\">handleSubmit</code> method when the form is submitted:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Form extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = { username: '' }\n    this.handleChange = this.handleChange.bind(this)\n    this.handleSubmit = this.handleSubmit.bind(this)\n  }\n  \n  handleChange(event) {\n    this.setState({ value: event.target.value })\n  }\n  \n  handleSubmit(event) {\n    alert(this.state.username)\n    event.preventDefault()\n  }\n  \n  render() {\n    return (\n      &lt;form onSubmit={this.handleSubmit}>\n        &lt;input\n          type=\"text\"\n          value={this.state.username}\n          onChange={this.handleChange}\n        />\n        &lt;input type=\"submit\" value=\"Submit\" />\n      &lt;/form>\n    )\n  }\n}</code></pre></div>\n<p>Validation in a form can be handled in the <code class=\"language-text\">handleChange</code> method: you have access to the old value of the state, and the new one. You can check the new value and if not valid reject the updated value (and communicate it in some way to the user).</p>\n<p>HTML Forms are inconsistent. They have a long history, and it shows. React however makes things more consistent for us, and you can get (and update) fields using its <code class=\"language-text\">value</code> attribute.</p>\n<p>Here's a <code class=\"language-text\">textarea</code>, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;textarea value={this.state.address} onChange={this.handleChange} /></code></pre></div>\n<p>The same goes for the <code class=\"language-text\">select</code> tag:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;select value=\"{this.state.age}\" onChange=\"{this.handleChange}\">\n  &lt;option value=\"teen\">Less than 18&lt;/option>\n  &lt;option value=\"adult\">18+&lt;/option>\n&lt;/select></code></pre></div>\n<p>Previously we mentioned the <code class=\"language-text\">&lt;input type=\"file\"></code> field. That works a bit differently.</p>\n<p>In this case you need to get a reference to the field by assigning the <code class=\"language-text\">ref</code> attribute to a property defined in the constructor with <code class=\"language-text\">React.createRef()</code>, and use that to get the value of it in the submit handler:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class FileInput extends React.Component {\n  constructor(props) {\n    super(props)\n    this.curriculum = React.createRef()\n    this.handleSubmit = this.handleSubmit.bind(this)\n  }\n  \n  handleSubmit(event) {\n    alert(this.curriculum.current.files[0].name)\n    event.preventDefault()\n  }\n  \n  render() {\n    return (\n      &lt;form onSubmit={this.handleSubmit}>\n        &lt;input type=\"file\" ref={this.curriculum} />\n        &lt;input type=\"submit\" value=\"Submit\" />\n      &lt;/form>\n    )\n  }\n}</code></pre></div>\n<p>This is the <strong>uncontrolled components</strong> way. The state is stored in the DOM rather than in the component state (notice we used <code class=\"language-text\">this.curriculum</code> to access the uploaded file, and have not touched the <code class=\"language-text\">state</code>.</p>\n<p>I know what you're thinking — beyond those basics, there must be a library that simplifies all this form handling stuff and automates validation, error handling and more, right? There is a great one, <a href=\"https://github.com/jaredpalmer/formik\">Formik</a>.</p>\n<h3>Reference a DOM element</h3>\n<p>React is great at abstracting away the DOM from you when building apps.</p>\n<p>But what if you want to access the DOM element that a React component represents?</p>\n<p>Maybe you have to add a library that interacts directly with the DOM like a chart library, maybe you need to call some DOM API, or add focus on an element.</p>\n<blockquote>\n<p><em>Whatever the reason is, a good practice is making sure there's no other way of doing so without accessing the DOM directly.</em></p>\n</blockquote>\n<p>In the JSX of your component, you can assign the reference of the DOM element to a component property using this attribute:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ref={el => this.someProperty = el}</code></pre></div>\n<p>Put this into context, for example with a <code class=\"language-text\">button</code> element:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;button ref={el => (this.button = el)} /></code></pre></div>\n<p><code class=\"language-text\">button</code> refers to a property of the component, which can then be used by the component's lifecycle methods (or other methods) to interact with the DOM:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class SomeComponent extends Component {\n  render() {\n    return &lt;button ref={el => (this.button = el)} />\n  }\n}</code></pre></div>\n<p>In a function component the mechanism is the same, you just avoid using <code class=\"language-text\">this</code> (since it does not point to the component instance) and use a property instead:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function SomeComponent() {\n  let button\n  return &lt;button ref={el => (button = el)} />\n}</code></pre></div>\n<h3>Server side rendering</h3>\n<p><strong>Server Side Rendering</strong>, also called <strong>SSR</strong>, is the ability of a JavaScript application to render on the server rather than in the browser.</p>\n<p>Why would we ever want to do so?</p>\n<ul>\n<li>it allows your site to have a faster first page load time, which is the key to a good user experience</li>\n<li>it is essential for SEO: search engines cannot (yet?) efficiently and correctly index applications that exclusively render client-side. Despite the latest improvements to indexing in Google, there are other search engines too, and Google is not perfect at it in any case. Also, Google favors sites with fast load times, and having to load client-side is not good for speed</li>\n<li>it's great when people share a page of your site on social media, as they can easily gather the metadata needed to nicely share the link (images, title, description..)</li>\n</ul>\n<p>Without Server Side Rendering, all your server ships is an HTML page with no body, just some script tags that are then used by the browser to render the application.</p>\n<p>Client-rendered apps are great at any subsequent user interaction after the first page load. Server Side Rendering allows us to get the sweet spot in the middle of client-rendered apps and backend-rendered apps: the page is generated server-side, but all interactions with the page once it's been loaded are handled client-side.</p>\n<p>However Server Side Rendering has its drawback too:</p>\n<ul>\n<li>it's fair to say that a simple SSR proof of concept is simple, but the complexity of SSR can grow with the complexity of your application</li>\n<li>rendering a big application server-side can be quite resource-intensive, and under heavy load it could even provide a slower experience than client-side rendering, since you have a single bottleneck</li>\n</ul>\n<h3>A very simplistic example of what it takes to Server-Side render a React app</h3>\n<p>SSR setups can grow very, very complex and most tutorials will bake in Redux, React Router and many other concepts from the start.</p>\n<p>To understand how SSR works, let's start from the basics to implement a proof of concept.</p>\n<blockquote>\n<p><em>Feel free to skip this paragraph if you just want to look into the libraries that provide SSR and not bother with the ground work</em></p>\n</blockquote>\n<p>To implement basic SSR we're going to use Express.</p>\n<blockquote>\n<p><em>If you are new to Express, or need some catch-up, check out my free Express Handbook here: <a href=\"https://flaviocopes.com/page/ebooks/\">https://flaviocopes.com/page/ebooks/</a>.</em></p>\n</blockquote>\n<p>Warning: the complexity of SSR can grow with the complexity of your application. This is the bare minimum setup to render a basic React app. For more complex needs you might need to do a bit more work or also check out SSR libraries for React.</p>\n<p>I assume you started a React app with <code class=\"language-text\">create-react-app</code>. If you are just trying, install one now using <code class=\"language-text\">npx create-react-app ssr</code>.</p>\n<p>Go to the main app folder with the terminal, then run:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install express</code></pre></div>\n<p>You have a set of folders in your app directory. Create a new folder called <code class=\"language-text\">server</code>, then go into it and create a file named <code class=\"language-text\">server.js</code>.</p>\n<p>Following the <code class=\"language-text\">create-react-app</code> conventions, the app lives in the <code class=\"language-text\">src/App.js</code> file. We're going to load that component, and render it to a string using <a href=\"https://reactjs.org/docs/react-dom-server.html\">ReactDOMServer.renderToString()</a>, which is provided by <code class=\"language-text\">react-dom</code>.</p>\n<p>You get the contents of the <code class=\"language-text\">./build/index.html</code> file, and replace the `<div id=\"root\"></p>\n</div>`placeholder, which is the tag where the application hooks by default, with `` `<div id=\"root\">\\${ReactDOMServer.renderToString(<App />)}</div> ``.\n<p>All the content inside the <code class=\"language-text\">build</code> folder is going to be served as-is, statically by Express.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import path from 'path'\nimport fs from 'fs'\n\nimport express from 'express'\nimport React from 'react'\nimport ReactDOMServer from 'react-dom/server'\n\nimport App from '../src/App'\n\nconst PORT = 8080\nconst app = express()\n\nconst router = express.Router()\n\nconst serverRenderer = (req, res, next) => {\n  fs.readFile(path.resolve('./build/index.html'), 'utf8', (err, data) => {\n    if (err) {\n      console.error(err)\n      return res.status(500).send('An error occurred')\n    }\n    return res.send(\n      data.replace(\n        '&lt;div id=\"root\">\n&lt;/div>',\n        `&lt;div id=\"root\">${ReactDOMServer.renderToString(&lt;App />)}&lt;/div>`\n      )\n    )\n  })\n}\nrouter.use('^/$', serverRenderer)\n\nrouter.use(\n  express.static(path.resolve(__dirname, '..', 'build'), { maxAge: '30d' })\n)\n\n// tell the app to use the above rules\napp.use(router)\n\n// app.use(express.static('./build'))\napp.listen(PORT, () => {\n  console.log(`SSR running on port ${PORT}`)\n})</code></pre></div>\n<p>Now, in the client application, in your <code class=\"language-text\">src/index.js</code>, instead of calling <code class=\"language-text\">ReactDOM.render()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(&lt;App />, document.getElementById('root'))</code></pre></div>\n<p>call <code class=\"language-text\">[ReactDOM.hydrate()](https://reactjs.org/docs/react-dom.html#hydrate)</code>, which is the same but has the additional ability to attach event listeners to existing markup once React loads:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.hydrate(&lt;App />, document.getElementById('root'))</code></pre></div>\n<p>All the Node.js code needs to be transpiled by Babel, as server-side Node.js code does not know anything about JSX, nor ES Modules (which we use for the <code class=\"language-text\">include</code> statements).</p>\n<p>Install these 3 packages:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install @babel/register @babel/preset-env @babel/preset-react ignore-styles express</code></pre></div>\n<p><code class=\"language-text\">[ignore-styles](https://www.npmjs.com/package/ignore-styles)</code> is a Babel utility that will tell it to ignore CSS files imported using the <code class=\"language-text\">import</code> syntax.</p>\n<p>Let's create an entry point in <code class=\"language-text\">server/index.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">require('ignore-styles')\n\nrequire('@babel/register')({\n  ignore: [/(node_modules)/],\n  presets: ['@babel/preset-env', '@babel/preset-react']\n})\n\nrequire('./server')</code></pre></div>\n<p>Build the React application, so that the build/ folder is populated:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm run build</code></pre></div>\n<p>and let's run this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">node server/index.js</code></pre></div>\n<p>I said this is a simplistic approach, and it is:</p>\n<ul>\n<li>it does not handle rendering images correctly when using imports, which need Webpack in order to work (and which complicates the process a lot)</li>\n<li>it does not handle page header metadata, which is essential for SEO and social sharing purposes (among other things)</li>\n</ul>\n<p>So while this is a good example of using <code class=\"language-text\">ReactDOMServer.renderToString()</code> and <code class=\"language-text\">ReactDOM.hydrate</code> to get this basic server-side rendering, it's not enough for real world usage.</p>\n<h4>Server Side Rendering using libraries</h4>\n<p>SSR is hard to do right, and React has no de-facto way to implement it.</p>\n<p>It's still very much debatable if it's worth the trouble, complication and overhead to get the benefits, rather than using a different technology to serve those pages. <a href=\"https://www.reddit.com/r/reactjs/comments/7o6oj6/serverside_rendering_not_worth_it/\">This discussion on Reddit</a> has lots of opinions in that regard.</p>\n<p>When Server Side Rendering is an important matter, my suggestion is to rely on pre-made libraries and tools that have had this goal in mind since the beginning.</p>\n<p>In particular, I suggest <strong>Next.js</strong> and <strong>Gatsby</strong>, two projects we'll see later on.</p>\n<h3>The Context API</h3>\n<p>The Context API is a neat way to pass state across the app without having to use props. It was introduced to allow you to pass state (and enable the state to update) across the app, without having to use props for it.</p>\n<p>The React team suggests to stick to props if you have just a few levels of children to pass, because it's still a much less complicated API than the Context API.</p>\n<p>In many cases, it enables us to avoid using Redux, simplifying our apps a lot, and also learning how to use React.</p>\n<p>How does it work?</p>\n<p>You create a context using <code class=\"language-text\">React.createContext()</code>, which returns a Context object:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const { Provider, Consumer } = React.createContext()</code></pre></div>\n<p>Then you create a wrapper component that returns a <strong>Provider</strong> component, and you add as children all the components from which you want to access the context:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Container extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = {\n      something: 'hey'\n    }\n  }\n  \n  render() {\n    return (\n      &lt;Provider value={{ state: this.state }}>{this.props.children}&lt;/Provider>\n    )\n  }\n}\n\nclass HelloWorld extends React.Component {\n  render() {\n    return (\n      &lt;Container>\n        &lt;Button />\n      &lt;/Container>\n    )\n  }\n}</code></pre></div>\n<p>I used Container as the name of this component because this will be a global provider. You can also create smaller contexts.</p>\n<p>Inside a component that's wrapped in a Provider, you use a <strong>Consumer</strong> component to make use of the context:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Button extends React.Component {\n  render() {\n    return (\n      &lt;Consumer>\n        {context => &lt;button>{context.state.something}&lt;/button>}\n      &lt;/Consumer>\n    )\n  }\n}</code></pre></div>\n<p>You can also pass functions into a Provider value, and those functions will be used by the Consumer to update the context state:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Provider value={{\n  state: this.state,\n  updateSomething: () => this.setState({something: 'ho!'})\n  {this.props.children}\n&lt;/Provider>\n\n/* ... */\n&lt;Consumer>\n  {(context) => (\n    &lt;button onClick={context.updateSomething}>{context.state.something}&lt;/button>\n  )}\n&lt;/Consumer></code></pre></div>\n<p>You can see this in action <a href=\"https://glitch.com/edit/#!/flavio-react-context-api-example?path=app/components/HelloWorld.jsx\">in this Glitch</a>.</p>\n<p>You can create multiple contexts, to make your state distributed across components, yet expose it and make it reachable by any component you want.</p>\n<p>When using multiple files, you create the content in one file, and import it in all the places you use it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//context.js\nimport React from 'react'\nexport default React.createContext()\n\n//component1.js\nimport Context from './context'\n//... use Context.Provider\n\n//component2.js\nimport Context from './context'\n//... use Context.Consumer</code></pre></div>\n<h3>Higher order components</h3>\n<p>You might be familiar with Higher Order Functions in JavaScript. Those are functions that accept functions as arguments, and/or return functions.</p>\n<p>Two examples of those functions are <code class=\"language-text\">Array.map()</code> or <code class=\"language-text\">Array.filter()</code>.</p>\n<p>In React, we extend this concept to components, and so we have a <strong>Higher Order Component (HOC)</strong>when the component accepts a component as input and returns a component as its output.</p>\n<p>In general, higher order components allow you to create code that's composable and reusable, and also more encapsulated.</p>\n<p>We can use a HOC to add methods or properties to the state of a component, or a Redux store for example.</p>\n<p>You might want to use Higher Order Components when you want to enhance an existing component, operate on the state or props, or its rendered markup.</p>\n<p>There is a convention of prepending a Higher Order Component with the <code class=\"language-text\">with</code> string (it's a convention, so it's not mandatory), so if you have a <code class=\"language-text\">Button</code> component, its HOC counterpart should be called <code class=\"language-text\">withButton</code>.</p>\n<p>Let's create one.</p>\n<p>The simplest example ever of a HOC is one that simply returns the component unaltered:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const withElement = Element => () => &amp;lt;Element /></code></pre></div>\n<p>Let's make this a little bit more useful and add a property to that button, in addition to all the props it already came with, the color:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const withColor = Element => props => &lt;Element {...props} color=\"red\" /></code></pre></div>\n<p>We use this HOC in a component JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = () => {\n  return &lt;button>test&lt;/button>\n}\n\nconst ColoredButton = withColor(Button)</code></pre></div>\n<p>and we can finally render the ColoredButton component in our app JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function App() {\n  return (\n    &lt;div className=\"App\">\n      &lt;h1>Hello&lt;/h1>\n      &lt;ColoredButton />\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>This is a very simple example but hopefully you can get the gist of HOCs before applying those concepts to more complex scenarios.</p>\n<h3>Render Props</h3>\n<p>A common pattern used to share state between components is to use the <code class=\"language-text\">children</code> prop.</p>\n<p>Inside a component JSX you can render <code class=\"language-text\">{this.props.children}</code> which automatically injects any JSX passed in the parent component as a children:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Parent extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = {\n      /*...*/\n    }\n  }\n  \n  render() {\n    return &lt;div>{this.props.children}&lt;/div>\n  }\n}\n\nconst Children1 = () => {}\n\nconst Children2 = () => {}\n\nconst App = () => (\n  &lt;Parent>\n    &lt;Children1 />\n    &lt;Children2 />\n  &lt;/Parent>\n)</code></pre></div>\n<p>However, there is a problem here: the state of the parent component cannot be accessed from the children.</p>\n<p>To be able to share the state, you need to use a render prop component, and instead of passing components as children of the parent component, you pass a function which you then execute in <code class=\"language-text\">{this.props.children()}</code>. The function can accept arguments:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Parent extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = { name: 'Flavio' }\n  }\n  \n  render() {\n    return &lt;div>{this.props.children(this.state.name)}&lt;/div>\n  }\n}\n\nconst Children1 = props => {\n  return &lt;p>{props.name}&lt;/p>\n}\n\nconst App = () => &lt;Parent>{name => &lt;Children1 name={name} />}&lt;/Parent></code></pre></div>\n<p>Instead of using the <code class=\"language-text\">children</code> prop, which has a very specific meaning, you can use any prop, and so you can use this pattern multiple times on the same component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Parent extends React.Component {\n  constructor(props) {\n    super(props)\n    this.state = { name: 'Flavio', age: 35 }\n  }\n  \n  render() {\n    return (\n      &lt;div>\n        &lt;p>Test&lt;/p>\n        {this.props.someprop1(this.state.name)}\n        {this.props.someprop2(this.state.age)}\n      &lt;/div>\n    )\n  }\n}\n\nconst Children1 = props => {\n  return &lt;p>{props.name}&lt;/p>\n}\n\nconst Children2 = props => {\n  return &lt;p>{props.age}&lt;/p>\n}\n\nconst App = () => (\n  &lt;Parent\n    someprop1={name => &lt;Children1 name={name} />}\n    someprop2={age => &lt;Children2 age={age} />}\n  />\n)\n\nReactDOM.render(&lt;App />, document.getElementById('app'))</code></pre></div>\n<h3>Hooks</h3>\n<p>Hooks is a feature that will be introduced in React 16.7, and is going to change how we write React apps in the future.</p>\n<p>Before Hooks appeared, some key things in components were only possible using class components: having their own state, and using lifecycle events. Function components, lighter and more flexible, were limited in functionality.</p>\n<p><strong>Hooks allow function components to have state and to respond to lifecycle events</strong> too, and kind of make class components obsolete. They also allow function components to have a good way to handle events.</p>\n<h4>Access state</h4>\n<p>Using the <code class=\"language-text\">useState()</code> API, you can create a new state variable, and have a way to alter it. <code class=\"language-text\">useState()</code> accepts the initial value of the state item and returns an array containing the state variable, and the function you call to alter the state. Since it returns an array we use <a href=\"https://flaviocopes.com/es6/#destructuring-assignments\">array destructuring</a> to access each individual item, like this: <code class=\"language-text\">const [count, setCount] = useState(0)</code></p>\n<p>Here's a practical example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { useState } from 'react'\n\nconst Counter = () => {\n  const [count, setCount] = useState(0)\n  \n  return (\n    &lt;div>\n      &lt;p>You clicked {count} times&lt;/p>\n      &lt;button onClick={() => setCount(count + 1)}>Click me&lt;/button>\n    &lt;/div>\n  )\n}\n\nReactDOM.render(&lt;Counter />, document.getElementById('app'))</code></pre></div>\n<p>You can add as many <code class=\"language-text\">useState()</code> calls you want, to create as many state variables as you want. Just make sure you call it in the top level of a component (not in an <code class=\"language-text\">if</code> or in any other block).</p>\n<p><a href=\"https://codepen.io/flaviocopes/pen/maVPKa\">Example on Codepen</a></p>\n<h4>Access lifecycle hooks</h4>\n<p>Another very important feature of Hooks is allowing function components to have access to the lifecycle hooks.</p>\n<p>Using class components you can register a function on the <code class=\"language-text\">componentDidMount</code>, <code class=\"language-text\">componentWillUnmount</code> and <code class=\"language-text\">componentDidUpdate</code> events, and those will serve many use cases, from variables initialization to API calls to cleanup.</p>\n<p>Hooks provide the <code class=\"language-text\">useEffect()</code> API. The call accepts a function as argument.</p>\n<p>The function runs when the component is first rendered, and on every subsequent re-render/update. React first updates the DOM, then calls any function passed to <code class=\"language-text\">useEffect()</code>. All without blocking the UI rendering even on blocking code, unlike the old <code class=\"language-text\">componentDidMount</code> and <code class=\"language-text\">componentDidUpdate</code>, which makes our apps feel faster.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const { useEffect, useState } = React\n\nconst CounterWithNameAndSideEffect = () => {\n  const [count, setCount] = useState(0)\n  const [name, setName] = useState('Flavio')\n  \n  useEffect(() => {\n    console.log(`Hi ${name} you clicked ${count} times`)\n  })\n  \n  return (\n    &lt;div>\n      &lt;p>\n        Hi {name} you clicked {count} times\n      &lt;/p>\n      &lt;button onClick={() => setCount(count + 1)}>Click me&lt;/button>\n      &lt;button onClick={() => setName(name === 'Flavio' ? 'Roger' : 'Flavio')}>\n        Change name\n      &lt;/button>\n    &lt;/div>\n  )\n}\n\nReactDOM.render(\n  &lt;CounterWithNameAndSideEffect />,\n  document.getElementById('app')\n)</code></pre></div>\n<p>The same <code class=\"language-text\">componentWillUnmount</code> job can be achieved by optionally <strong>returning</strong> a function from our <code class=\"language-text\">useEffect()</code> parameter:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">useEffect(() => {\n  console.log(`Hi ${name} you clicked ${count} times`)\n  return () => {\n    console.log(`Unmounted`)\n  }\n})</code></pre></div>\n<p><code class=\"language-text\">useEffect()</code> can be called multiple times, which is nice to separate unrelated logic (something that plagues the class component lifecycle events).</p>\n<p>Since the <code class=\"language-text\">useEffect()</code> functions are run on every subsequent re-render/update, we can tell React to skip a run, for performance purposes, by adding a second parameter which is an array that contains a list of state variables to watch for. React will only re-run the side effect if one of the items in this array changes.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">useEffect(\n  () => {\n    console.log(`Hi ${name} you clicked ${count} times`)\n  },\n  [name, count]\n)</code></pre></div>\n<p>Similarly you can tell React to only execute the side effect once (at mount time), by passing an empty array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">useEffect(() => {\n  console.log(`Component mounted`)\n}, [])</code></pre></div>\n<p><code class=\"language-text\">useEffect()</code> is great for adding logs, accessing 3rd party APIs and much more.</p>\n<p><a href=\"https://codepen.io/flaviocopes/pen/WLrxXp\">Example on Codepen</a></p>\n<h4>Handle events in function components</h4>\n<p>Before hooks, you either used class components, or you passed an event handler using props.</p>\n<p>Now we can use the <code class=\"language-text\">useCallback()</code> built-in API:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = () => {\n  const handleClick = useCallback(() => {\n    //...do something\n  })\n  return &lt;button onClick={handleClick} />\n}</code></pre></div>\n<p>Any parameter used inside the function must be passed through a second parameter to <code class=\"language-text\">useCallback()</code>, in an array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = () => {\n  let name = '' //... add logic\n  const handleClick = useCallback(\n    () => {\n      //...do something\n    },\n    [name]\n  )\n  return &lt;button onClick={handleClick} />\n}</code></pre></div>\n<h4>Enable cross-component communication using custom hooks</h4>\n<p>The ability to write your own hooks is the feature that is going to significantly alter how you write React apps in the future.</p>\n<p>Using custom hooks you have one more way to share state and logic between components, adding a significant improvement to the patterns of render props and higher order components. Which are still great, but now with custom hooks have less relevance in many use cases.</p>\n<p>How do you create a custom hook?</p>\n<p>A hook is just a function that conventionally starts with <code class=\"language-text\">use</code>. It can accept an arbitrary number of arguments, and return anything it wants.</p>\n<p>Examples:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const useGetData() {\n  //...\n  return data\n}</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const useGetUser(username) {\n  //...const user = fetch(...)\n  //...const userData = ...\n  return [user, userData]\n}</code></pre></div>\n<p>In your own components, you can use the hook like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const MyComponent = () => {\n  const data = useGetData()\n  const [user, userData] = useGetUser('flavio')\n  //...\n}</code></pre></div>\n<p>When exactly to add hooks instead of regular functions should be determined on a use case basis, and only experience will tell.</p>\n<h3>Code splitting</h3>\n<p>Modern JavaScript applications can be quite huge in terms of bundle size. You don't want your users to have to download a 1MB package of JavaScript (your code and the libraries you use) just to load the first page, right? But this is what happens by default when you ship a modern Web App built with Webpack bundling.</p>\n<p>That bundle will contain code that might never run because the user only stops on the login page and never sees the rest of your app.</p>\n<p>Code splitting is the practice of only loading the JavaScript you need the moment when you need it.</p>\n<p>This improves:</p>\n<ul>\n<li>the performance of your app</li>\n<li>the impact on memory, and so battery usage on mobile devices</li>\n<li>the downloaded KiloBytes (or MegaBytes) size</li>\n</ul>\n<p>React 16.6.0, released in October 2018, introduced a way of performing code splitting that should take the place of every previously used tool or library: <strong>React.lazy</strong> and <strong>Suspense</strong>.</p>\n<p><code class=\"language-text\">React.lazy</code> and <code class=\"language-text\">Suspense</code> form the perfect way to lazily load a dependency and only load it when needed.</p>\n<p>Let's start with <code class=\"language-text\">React.lazy</code>. You use it to import any component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\n\nconst TodoList = React.lazy(() => import('./TodoList'))\n\nexport default () => {\n  return (\n    &lt;div>\n      &lt;TodoList />\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>the TodoList component will be dynamically added to the output as soon as it's available. Webpack will create a separate bundle for it, and will take care of loading it when necessary.</p>\n<p><code class=\"language-text\">Suspense</code> is a component that you can use to wrap any lazily loaded component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\n\nconst TodoList = React.lazy(() => import('./TodoList'))\n\nexport default () => {\n  return (\n    &lt;div>\n      &lt;React.Suspense>\n        &lt;TodoList />\n      &lt;/React.Suspense>\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>It takes care of handling the output while the lazy loaded component is fetched and rendered.</p>\n<p>Use its <code class=\"language-text\">fallback</code> prop to output some JSX or a component output:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">...\n      &lt;React.Suspense fallback={&lt;p>Please wait&lt;/p>}>\n        &lt;TodoList />\n      &lt;/React.Suspense>\n...</code></pre></div>\n<p>All this plays well with React Router:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\nimport { BrowserRouter as Router, Route, Switch } from 'react-router-dom'\n\nconst TodoList = React.lazy(() => import('./routes/TodoList'))\nconst NewTodo = React.lazy(() => import('./routes/NewTodo'))\n\nconst App = () => (\n  &lt;Router>\n    &lt;React.Suspense fallback={&lt;p>Please wait&lt;/p>}>\n      &lt;Switch>\n        &lt;Route exact path=\"/\" component={TodoList} />\n        &lt;Route path=\"/new\" component={NewTodo} />\n      &lt;/Switch>\n    &lt;/React.Suspense>\n  &lt;/Router>\n)</code></pre></div>\n<h3>SECTION 4: PRACTICAL EXAMPLES</h3>\n<p>2 very simple applications to explain some of the concepts introduced so far.</p>\n<h3>A very simple example of building a counter in React</h3>\n<p>In this short example we'll build a very simple example of a counter in React, applying many of the concepts and theory outlined before.</p>\n<p>Let's use Codepen for this. We start by forking the <a href=\"https://codepen.io/flaviocopes/pen/VqeaxB\">React template pen</a>.</p>\n<blockquote>\n<p><em>In Codepen we don't need to import React and ReactDOM as they are already added in the scope.</em></p>\n</blockquote>\n<p>We show the count in a div, and we add a few buttons to increment this count:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = ({ increment }) => {\n  return &lt;button>+{increment}&lt;/button>\n}\n\nconst App = () => {\n  let count = 0\n  \n  return (\n    &lt;div>\n      &lt;Button increment={1} />\n      &lt;Button increment={10} />\n      &lt;Button increment={100} />\n      &lt;Button increment={1000} />\n      &lt;span>{count}&lt;/span>\n    &lt;/div>\n  )\n}\n\nReactDOM.render(&lt;App />, document.getElementById('app'))</code></pre></div>\n<p>Let's add the functionality that lets us change the count by clicking the buttons, by adding a <code class=\"language-text\">onClickFunction</code> prop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = ({ increment, onClickFunction }) => {\n  const handleClick = () => {\n    onClickFunction(increment)\n  }\n  return &lt;button onClick={handleClick}>+{increment}&lt;/button>\n}\n\nconst App = () => {\n  let count = 0\n  \n  const incrementCount = increment => {\n    //TODO\n  }\n  \n  return (\n    &lt;div>\n      &lt;Button increment={1} onClickFunction={incrementCount} />\n      &lt;Button increment={10} onClickFunction={incrementCount} />\n      &lt;Button increment={100} onClickFunction={incrementCount} />\n      &lt;Button increment={1000} onClickFunction={incrementCount} />\n      &lt;span>{count}&lt;/span>\n    &lt;/div>\n  )\n}\n\nReactDOM.render(&lt;App />, document.getElementById('app'))</code></pre></div>\n<p>Here, every Button element has 2 props: <code class=\"language-text\">increment</code> and <code class=\"language-text\">onClickFunction</code>. We create 4 different buttons, with 4 increment values: 1, 10, 100, 1000.</p>\n<p>When the button in the Button component is clicked, the <code class=\"language-text\">incrementCount</code> function is called.</p>\n<p>This function must increment the local count. How can we do so? We can use hooks:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const { useState } = React\n\nconst Button = ({ increment, onClickFunction }) => {\n  const handleClick = () => {\n    onClickFunction(increment)\n  }\n  return &lt;button onClick={handleClick}>+{increment}&lt;/button>\n}\n\nconst App = () => {\n  const [count, setCount] = useState(0)\n  \n  const incrementCount = increment => {\n    setCount(count + increment)\n  }\n  \n  return (\n    &lt;div>\n      &lt;Button increment={1} onClickFunction={incrementCount} />\n      &lt;Button increment={10} onClickFunction={incrementCount} />\n      &lt;Button increment={100} onClickFunction={incrementCount} />\n      &lt;Button increment={1000} onClickFunction={incrementCount} />\n      &lt;span>{count}&lt;/span>\n    &lt;/div>\n  )\n}\n\nReactDOM.render(&lt;App />, document.getElementById('app'))</code></pre></div>\n<p><code class=\"language-text\">useState()</code> initializes the count variable at 0 and provides us the <code class=\"language-text\">setCount()</code> method to update its value.</p>\n<p>We use both in the <code class=\"language-text\">incrementCount()</code> method implementation, which calls <code class=\"language-text\">setCount()</code> updating the value to the existing value of <code class=\"language-text\">count</code>, plus the increment passed by each Button component.</p>\n<p>The complete example code can be seen at <a href=\"https://codepen.io/flaviocopes/pen/QzEQPR\">https://codepen.io/flaviocopes/pen/QzEQPR</a></p>\n<h3>Fetch and display GitHub users information via API</h3>\n<p>Very simple example of a form that accepts a GitHub username and once it receives a <code class=\"language-text\">submit</code> event, it asks the GitHub API for the user information, and prints them.</p>\n<p>This code creates a reusable <strong>Card</strong> component. When you enter a name in the <code class=\"language-text\">input</code> field managed by the <strong>Form</strong> component, this name is <em>bound to its state</em>.</p>\n<p>When <em>Add card</em> is pressed, the input form is cleared by clearing the <code class=\"language-text\">userName</code> state of the <strong>Form</strong> component.</p>\n<p>The example uses, in addition to React, the <a href=\"https://flaviocopes.com/axios/\">Axios</a> library. It's a nice useful and lightweight library to handle network requests. Add it to the Pen settings in Codepen, or install it locally using <code class=\"language-text\">npm install axios</code>.</p>\n<p>We start by creating the <code class=\"language-text\">Card</code> component, the one that will display our image and details as gathered from GitHub. It gets its data via props, using</p>\n<ul>\n<li><code class=\"language-text\">props.avatar_url</code> the user avatar</li>\n<li><code class=\"language-text\">props.name</code> the user name</li>\n<li><code class=\"language-text\">props.blog</code> the user website URL</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Card = props => {\n  return (\n    &lt;div style={{ margin: '1em' }}>\n      &lt;img alt=\"avatar\" style={{ width: '70px' }} src={props.avatar_url} />\n      &lt;div>\n        &lt;div style={{ fontWeight: 'bold' }}>{props.name}&lt;/div>\n        &lt;div>{props.blog}&lt;/div>\n      &lt;/div>\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>We create a list of those components, which will be passed by a parent component in the <code class=\"language-text\">cards</code> prop to <code class=\"language-text\">CardList</code>, which simply iterates on it using <code class=\"language-text\">map()</code> and outputs a list of cards:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const CardList = props => (\n  &lt;div>\n    {props.cards.map(card => (\n      &lt;Card {...card} />\n    ))}\n  &lt;/div>\n)</code></pre></div>\n<p>The parent component is App, which stores the <code class=\"language-text\">cards</code> array in its own state, managed using the <code class=\"language-text\">useState()</code> Hook:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const App = () => {\n  const [cards, setCards] = useState([])\n  \n  return (\n    &lt;div>\n      &lt;CardList cards={cards} />\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>Cool! We must have a way now to ask GitHub for the details of a single username. We'll do so using a <code class=\"language-text\">Form</code> component, where we manage our own state (<code class=\"language-text\">username</code>), and we ask GitHub for information about a user using their public APIs, via Axios:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Form = props => {\n  const [username, setUsername] = useState('')\n  \n  handleSubmit = event => {\n    event.preventDefault()\n    \n    axios.get(`https://api.github.com/users/${username}`).then(resp => {\n      props.onSubmit(resp.data)\n      setUsername('')\n    })\n  }\n  \n  return (\n    &lt;form onSubmit={handleSubmit}>\n      &lt;input\n        type=\"text\"\n        value={username}\n        onChange={event => setUsername(event.target.value)}\n        placeholder=\"GitHub username\"\n        required\n      />\n      &lt;button type=\"submit\">Add card&lt;/button>\n    &lt;/form>\n  )\n}</code></pre></div>\n<p>When the form is submitted we call the <code class=\"language-text\">handleSubmit</code> event, and after the network call we call <code class=\"language-text\">props.onSubmit</code> passing the parent (<code class=\"language-text\">App</code>) the data we got from GitHub.</p>\n<p>We add it to <code class=\"language-text\">App</code>, passing a method to add a new card to the list of cards, <code class=\"language-text\">addNewCard</code>, as its <code class=\"language-text\">onSubmit</code> prop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const App = () => {\n  const [cards, setCards] = useState([])\n  \n  addNewCard = cardInfo => {\n    setCards(cards.concat(cardInfo))\n  }\n  \n  return (\n    &lt;div>\n      &lt;Form onSubmit={addNewCard} />\n      &lt;CardList cards={cards} />\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>Finally we render the app:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ReactDOM.render(&lt;App />, document.getElementById('app'))</code></pre></div>\n<p>Here is the full source code of our little React app:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const { useState } = React\n\nconst Card = props => {\n  return (\n    &lt;div style={{ margin: '1em' }}>\n      &lt;img alt=\"avatar\" style={{ width: '70px' }} src={props.avatar_url} />\n      &lt;div>\n        &lt;div style={{ fontWeight: 'bold' }}>{props.name}&lt;/div>\n        &lt;div>{props.blog}&lt;/div>\n      &lt;/div>\n    &lt;/div>\n  )\n}\n\nconst CardList = props => &lt;div>{props.cards.map(card => &lt;Card {...card} />)}&lt;/div>\n\nconst Form = props => {\n  const [username, setUsername] = useState('')\n  \n  handleSubmit = event => {\n    event.preventDefault()\n    \n    axios\n      .get(`https://api.github.com/users/${username}`)\n      .then(resp => {\n        props.onSubmit(resp.data)\n        setUsername('')\n      })\n  }\n  \n  return (\n    &lt;form onSubmit={handleSubmit}>\n      &lt;input\n        type=\"text\"\n        value={username}\n        onChange={event => setUsername(event.target.value)}\n        placeholder=\"GitHub username\"\n        required\n      />\n      &lt;button type=\"submit\">Add card&lt;/button>\n    &lt;/form>\n  )\n}\n\nconst App = () => {\n  const [cards, setCards] = useState([])\n  \n  addNewCard = cardInfo => {\n    setCards(cards.concat(cardInfo))\n  }\n  \n  return (\n    &lt;div>\n      &lt;Form onSubmit={addNewCard} />\n      &lt;CardList cards={cards} />\n    &lt;/div>\n  )\n}\n\nReactDOM.render(&lt;App />, document.getElementById('app'))</code></pre></div>\n<p>This is the final result:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/cZoqPqmbwvuUaIiWJ16fTj6VOhTIquXDECnP\" alt=\"cZoqPqmbwvuUaIiWJ16fTj6VOhTIquXDECnP\"></p>\n<p>Check it out on Codepen at <a href=\"https://codepen.io/flaviocopes/pen/oJLyeY\">https://codepen.io/flaviocopes/pen/oJLyeY</a></p>\n<h3>SECTION 5: STYLING</h3>\n<h3>CSS in React</h3>\n<p>Using React you have various ways to add styling to your components.</p>\n<h4>Using classes and CSS</h4>\n<p>The first and most simple is to use classes, and use a normal CSS file to target those classes:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = () => {\n  return &lt;button className=\"button\">A button&lt;/button>\n}\n\n.button {\n  background-color: yellow;\n}</code></pre></div>\n<p>You can import the stylesheet using an import statement, like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import './style.css'</code></pre></div>\n<p>and <a href=\"https://flaviocopes.com/webpack/\">Webpack</a> will take care of adding the CSS property to the bundle.</p>\n<h4>Using the style attribute</h4>\n<p>A second method is to use the <code class=\"language-text\">style</code> attribute attached to a JSX element. Using this approach you don't need a separate CSS file.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = () => {\n  return &lt;button style={{ backgroundColor: 'yellow' }}>A button&lt;/button>\n}</code></pre></div>\n<p>CSS is defined in a slightly different way now. First, notice the double curly brackets: it's because <code class=\"language-text\">style</code> accepts an object. We pass in a JavaScript object, which is defined in curly braces. We could also do this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const buttonStyle = { backgroundColor: 'yellow' }\nconst Button = () => {\n  return &lt;button style={buttonStyle}>A button&lt;/button>\n}</code></pre></div>\n<p>When using <code class=\"language-text\">create-react-app</code>, those styles are autoprefixed by default thanks to its use of <a href=\"https://github.com/postcss/autoprefixer\">Autoprefixer</a>.</p>\n<p>Also, the style now is camelCased instead of using dashes. Every time a CSS property has a dash, remove it and start the next word capitalized.</p>\n<p>Styles have the benefit of being local to the component, and they cannot leak to other components in other parts of the app, something that using classes and an external CSS file can't provide.</p>\n<h4>Using CSS Modules</h4>\n<p><strong>CSS Modules</strong> seem to be a perfect spot in the middle: you use classes, but CSS is scoped to the component, which means that any styling you add cannot be applied to other components without your permission. And yet your styles are defined in a separate CSS file, which is easier to maintain than CSS in JavaScript (and you can use your good old CSS property names).</p>\n<p>Start by creating a CSS file that ends with <code class=\"language-text\">.module.css</code>, for example <code class=\"language-text\">Button.module.css</code>. A great choice is to give it the same name as the component you are going to style</p>\n<p>Add your CSS here, then import it inside the component file you want to style:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import style from './Button.module.css'</code></pre></div>\n<p>now you can use it in your JSX:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = () => {\n  return &lt;button className={style.content}>A button&lt;/button>\n}</code></pre></div>\n<p>That's it! In the resulting markup, React will generate a specific, unique class for each rendered component, and assign the CSS to that class, so that the CSS is not affecting other markup.</p>\n<h3>SASS in React</h3>\n<p>When you build a React application using <code class=\"language-text\">[create-react-app](https://flaviocopes.com/react-create-react-app/)</code>, you have many options at your disposal when it comes to styling.</p>\n<blockquote>\n<p><em>Of course, if not using <code class=\"language-text\">create-react-app</code>, you have all the choices in the world, but we limit the discussion to the <code class=\"language-text\">create-react-app</code>-provided options.</em></p>\n</blockquote>\n<p>You can style using plain classes and CSS files, using the style attribute or CSS Modules, to start with.</p>\n<p>SASS/SCSS is a very popular option, a much loved one by many developers.</p>\n<p>You can use it without any configuration at all, starting with <code class=\"language-text\">create-react-app</code> 2.</p>\n<p>All you need is a <code class=\"language-text\">.sass</code> or <code class=\"language-text\">.scss</code> file, and you just import it in a component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import './styles.scss'</code></pre></div>\n<p>You can see an example of it working at <a href=\"https://codesandbox.io/s/18qq31rp3\">https://codesandbox.io/s/18qq31rp3</a>.</p>\n<h3>Styled Components</h3>\n<p>Styled Components are one of the new ways to use CSS in modern JavaScript. It is the meant to be a successor of CSS Modules, a way to write CSS that's scoped to a single component, and not leak to any other element in the page</p>\n<h4>A brief history</h4>\n<p>Once upon a time, the Web was really simple and CSS didn't even exist. We laid out pages using <strong>tables</strong> and frames. Good times.</p>\n<p>Then <strong>CSS</strong> came to life, and after some time it became clear that frameworks could greatly help especially in building grids and layouts, Bootstrap and Foundation playing a big part in this.</p>\n<p>Preprocessors like <strong>SASS</strong> and others helped a lot to slow down the adoption of frameworks, and to better organize the code, conventions like <strong>BEM</strong> and <strong>SMACSS</strong> grew in use, especially within teams.</p>\n<p>Conventions are not a solution to everything, and they are complex to remember, so in the last few years with the increasing adoption of <a href=\"https://flaviocopes.com/javascript/\">JavaScript</a> and build processes in every frontend project, CSS found its way into JavaScript (<strong>CSS-in-JS</strong>).</p>\n<p>New tools explored new ways of doing CSS-in-JS and a few succeeded with increasing popularity:</p>\n<ul>\n<li>React Style</li>\n<li>jsxstyle</li>\n<li>Radium</li>\n</ul>\n<p>and more.</p>\n<h4>Introducing Styled Components</h4>\n<p>One of the most popular of these tools is <strong>Styled Components</strong>.</p>\n<p>It is the meant to be a successor to <strong>CSS Modules</strong>, a way to write CSS that's scoped to a single component, and not leak to any other element in the page.</p>\n<p>(more on CSS modules <a href=\"https://css-tricks.com/css-modules-part-1-need/\">here</a> and <a href=\"https://glenmaddern.com/articles/css-modules\">here</a>)</p>\n<p>Styled Components allow you to write plain CSS in your components without worrying about class name collisions.</p>\n<h4>Installation</h4>\n<p>Simply install styled-components using <a href=\"https://flaviocopes.com/npm/\">npm</a> or <a href=\"https://flaviocopes.com/yarn/\">yarn</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install styled-components\nyarn add styled-components</code></pre></div>\n<p>That's it! Now all you have to do is to add this import:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import styled from 'styled-components'</code></pre></div>\n<h4>Your first styled component</h4>\n<p>With the <code class=\"language-text\">styled</code> object imported, you can now start creating Styled Components. Here's the first one:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = styled.button`\n  font-size: 1.5em;\n  background-color: black;\n  color: white;\n`</code></pre></div>\n<p><code class=\"language-text\">Button</code> is now a React Component in all its greatness.</p>\n<p>We created it using a function of the styled object, called <code class=\"language-text\">button</code> in this case, and passing some CSS properties in a <a href=\"https://flaviocopes.com/ecmascript/#template-literals\">template literal</a>.</p>\n<p>Now this component can be rendered in our container using the normal React syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">render(&lt;Button />)</code></pre></div>\n<p>Styled Components offer other functions you can use to create other components, not just <code class=\"language-text\">button</code>, like <code class=\"language-text\">section</code>, <code class=\"language-text\">h1</code>, <code class=\"language-text\">input</code> and many others.</p>\n<p>The syntax used, with the backtick, might be weird at first, but it's called <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals\">Tagged Templates</a>, it's plain JavaScript and it's a way to pass an argument to the function.</p>\n<h4>Using props to customize components</h4>\n<p>When you pass some props to a Styled Component, it will pass them down to the <a href=\"https://flaviocopes.com/dom/\">DOM</a> node mounted.</p>\n<p>For example here's how we pass the <code class=\"language-text\">placeholder</code> and <code class=\"language-text\">type</code> props to an <code class=\"language-text\">input</code> component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Input = styled.input`\n  //...\n`\n\nrender(\n  &lt;div>\n    &lt;Input placeholder=\"...\" type=\"text\" />\n  &lt;/div>\n)</code></pre></div>\n<p>This will do just what you think, inserting those props as HTML attributes.</p>\n<p>Props instead of just being blindly passed down to the <a href=\"https://flaviocopes.com/dom/\">DOM</a> can also be used to customize a component based on the prop value. Here's an example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = styled.button`\n  background: ${props => (props.primary ? 'black' : 'white')};\n  color: ${props => (props.primary ? 'white' : 'black')};\n`\n\nrender(\n  &lt;div>\n    &lt;Button>A normal button&lt;/Button>\n    &lt;Button>A normal button&lt;/Button>\n    &lt;Button primary>The primary button&lt;/Button>\n  &lt;/div>\n)</code></pre></div>\n<p>Setting the <code class=\"language-text\">primary</code> prop changes the color of the button.</p>\n<h4>Extending an existing Styled Component</h4>\n<p>If you have one component and you want to create a similar one, just styled slightly differently, you can use <code class=\"language-text\">extend</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Button = styled.button`\n  color: black;\n  //...\n`\n\nconst WhiteButton = Button.extend`\n  color: white;\n`\n\nrender(\n  &lt;div>\n    &lt;Button>A black button, like all buttons&lt;/Button>\n    &lt;WhiteButton>A white button&lt;/WhiteButton>\n  &lt;/div>\n)</code></pre></div>\n<h4>It's Regular CSS</h4>\n<p>In Styled Components, you can use the CSS you already know and love. It's just plain CSS. It is not pseudo CSS nor inline CSS with its limitations.</p>\n<p>You can use media queries, <a href=\"https://tabatkins.github.io/specs/css-nesting/\">nesting</a> and anything else you might need.</p>\n<h4>Using Vendor Prefixes</h4>\n<p>Styled Components automatically add all the vendor prefixes needed, so you don't need to worry about this problem.</p>\n<h3>SECTION 6: TOOLING</h3>\n<h3>Babel</h3>\n<p>Babel is an awesome tool, and it's been around for quite some time, but nowadays almost every JavaScript developer relies on it. This will continue, because Babel is now indispensable and has solved a big problem for everyone.</p>\n<p>Which problem?</p>\n<p>The problem that every Web Developer has surely had: a feature of JavaScript is available in the latest release of a browser, but not in the older versions. Or maybe Chrome or Firefox implement it, but Safari iOS and Edge do not.</p>\n<p>For example, ES6 introduced the <strong>arrow function</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[1, 2, 3].map((n) => n + 1)</code></pre></div>\n<p>Which is now supported by all modern browsers. IE11 does not support it, nor Opera Mini (How do I know? By checking the <a href=\"http://kangax.github.io/compat-table/es6/#test-arrow_functions\">ES6 Compatibility Table</a>).</p>\n<p>So how should you deal with this problem? Should you move on and leave those customers with older/incompatible browsers behind, or should you write older JavaScript code to make all your users happy?</p>\n<p>Enter Babel. Babel is a <strong>compiler</strong>: it takes code written in one standard, and it transpiles it to code written into another standard.</p>\n<p>You can configure Babel to transpile modern ES2017 JavaScript into JavaScript ES5 syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">[1, 2, 3].map(function(n) {\n  return n + 1\n})</code></pre></div>\n<p>This must happen at build time, so you must setup a workflow that handles this for you. <a href=\"https://flaviocopes.com/webpack/\">Webpack</a> is a common solution.</p>\n<p>(P.S. if all this <em>ES</em> thing sounds confusing to you, see more about ES versions <a href=\"https://flaviocopes.com/ecmascript/\">in the ECMAScript guide</a>)</p>\n<h4>Installing Babel</h4>\n<p>Babel is easily installed using <a href=\"https://flaviocopes.com/npm/\">npm</a>, locally in a project:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install --save-dev @babel/core @babel/cli</code></pre></div>\n<p>Since npm now comes with <code class=\"language-text\">[npx](https://flaviocopes.com/node/npx/)</code>, locally installed CLI packages can run by typing the command in the project folder:</p>\n<p>So we can run Babel by just running</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npx babel script.js</code></pre></div>\n<h4>An example Babel configuration</h4>\n<p>Babel out of the box does not do anything useful, you need to configure it and add plugins.</p>\n<blockquote>\n<p><a href=\"https://babeljs.io/docs/en/plugins\"><em>Here is a list of Babel plugins</em></a></p>\n</blockquote>\n<p>To solve the problem we talked about in the introduction (using arrow functions in every browser), we can run</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install --save-dev \\\n    @babel/plugin-transform-es2015-arrow-functions</code></pre></div>\n<p>to download the package in the <code class=\"language-text\">node_modules</code> folder of our app, then we need to add</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"plugins\": [\"transform-es2015-arrow-functions\"]\n}</code></pre></div>\n<p>to the <code class=\"language-text\">.babelrc</code> file present in the application root folder. If you don't have that file already, you just create a blank file, and put that content into it.</p>\n<blockquote>\n<p><em>TIP: If you have never seen a dot file (a file starting with a dot) it might be odd at first because that file might not appear in your file manager, as it's a hidden file.</em></p>\n</blockquote>\n<p>Now if we have a <code class=\"language-text\">script.js</code> file with this content:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var a = () => {};\nvar a = (b) => b;\n\nconst double = [1,2,3].map((num) => num * 2);\nconsole.log(double); // [2,4,6]\n\nvar bob = {\n  _name: \"Bob\",\n  _friends: [\"Sally\", \"Tom\"],\n  printFriends() {\n    this._friends.forEach(f =>\n      console.log(this._name + \" knows \" + f));\n  }\n};\nconsole.log(bob.printFriends());</code></pre></div>\n<p>running <code class=\"language-text\">babel script.js</code> will output the following code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var a = function () {};var a = function (b) {\n  return b;\n};\n\nconst double = [1, 2, 3].map(function (num) {\n  return num * 2;\n});\nconsole.log(double); // [2,4,6]\n\nvar bob = {\n  _name: \"Bob\",\n  _friends: [\"Sally\", \"Tom\"],\n  printFriends() {\n    var _this = this;\n    \n    this._friends.forEach(function (f) {\n      return console.log(_this._name + \" knows \" + f);\n    });\n  }\n};\nconsole.log(bob.printFriends());</code></pre></div>\n<p>As you can see arrow functions have all been converted to JavaScript ES5 functions.</p>\n<h4>Babel presets</h4>\n<p>We just saw in the previous article how Babel can be configured to transpile specific JavaScript features.</p>\n<p>You can add much more plugins, but you can't add to the configuration features one by one, it's not practical.</p>\n<p>This is why Babel offers <strong>presets</strong>.</p>\n<p>The most popular presets are <code class=\"language-text\">env</code> and <code class=\"language-text\">react</code>.</p>\n<blockquote>\n<p><em>Tip: Babel 7 deprecated (and removed) yearly presets like <code class=\"language-text\">preset-es2017</code>, and stage presets. Use <code class=\"language-text\">@babel/preset-env</code> instead.</em></p>\n</blockquote>\n<h4><code class=\"language-text\">env</code> preset</h4>\n<p>The <code class=\"language-text\">env</code> preset is very nice: you tell it which environments you want to support, and it does everything for you, <strong>supporting all modern JavaScript features</strong>.</p>\n<p>E.g. \"support the last 2 versions of every browser, but for Safari let's support all versions since Safari 7\"</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"presets\": [\n    [\"env\", {\n      \"targets\": {\n        \"browsers\": [\"last 2 versions\", \"safari >= 7\"]\n      }\n    }]\n  ]\n}</code></pre></div>\n<p>or \"I don't need browser support, just let me work with <a href=\"https://flaviocopes.com/node/\">Node.js</a> 6.10\"</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"presets\": [\n    [\"env\", {\n      \"targets\": {\n        \"node\": \"6.10\"\n      }\n    }]\n  ]\n}</code></pre></div>\n<h4><code class=\"language-text\">react</code> preset</h4>\n<p>The <code class=\"language-text\">react</code> preset is very convenient when writing React apps: adding <code class=\"language-text\">preset-flow</code>, <code class=\"language-text\">syntax-jsx</code>, <code class=\"language-text\">transform-react-jsx</code>, <code class=\"language-text\">transform-react-display-name</code>.</p>\n<p>By including it, you are all ready to go developing React apps, with JSX transforms and Flow support.</p>\n<h4>More info on presets</h4>\n<p><a href=\"https://babeljs.io/docs/plugins/\">https://babeljs.io/docs/plugins/</a></p>\n<h4>Using Babel with webpack</h4>\n<p>If you want to run modern JavaScript in the browser, Babel on its own is not enough, you also need to bundle the code. Webpack is the perfect tool for this.</p>\n<p>Modern JS needs two different stages: a compile stage, and a runtime stage. This is because some ES6+ features need a polyfill or a runtime helper.</p>\n<p>To install the Babel polyfill runtime functionality, run</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install @babel/polyfill \\\n            @babel/runtime \\\n            @babel/plugin-transform-runtime</code></pre></div>\n<p>Now in your <code class=\"language-text\">webpack.config.js</code> file add:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">entry: [\n  'babel-polyfill',\n  // your app scripts should be here\n],\n\nmodule: {\n  loaders: [\n    // Babel loader compiles ES2015 into ES5 for\n    // complete cross-browser support\n    {\n      loader: 'babel-loader',\n      test: /\\.js$/,\n      // only include files present in the `src` subdirectory\n      include: [path.resolve(__dirname, \"src\")],\n      // exclude node_modules, equivalent to the above line\n      exclude: /node_modules/,\n      query: {\n        // Use the default ES2015 preset\n        // to include all ES2015 features\n        presets: ['es2015'],\n        plugins: ['transform-runtime']\n      }\n    }\n  ]\n}</code></pre></div>\n<p>By keeping the presets and plugins information inside the <code class=\"language-text\">webpack.config.js</code> file, we can avoid having a <code class=\"language-text\">.babelrc</code> file.</p>\n<h3>Webpack</h3>\n<p>Webpack is a tool that lets you compile JavaScript modules, also known as <strong>module bundler</strong>. Given a large number of files, it generates a single file (or a few files) that run your app.</p>\n<p>It can perform many operations:</p>\n<ul>\n<li>helps you bundle your resources.</li>\n<li>watches for changes and re-runs the tasks.</li>\n<li>can run Babel transpilation to ES5, allowing you to use the latest JavaScript features without worrying about browser support.</li>\n<li>can transpile CoffeeScript to JavaScript</li>\n<li>can convert inline images to data URIs.</li>\n<li>allows you to use require() for CSS files.</li>\n<li>can run a development webserver.</li>\n<li>can handle hot module replacement.</li>\n<li>can split the output files into multiple files, to avoid having a huge js file to load in the first page hit.</li>\n<li>can perform <a href=\"https://flaviocopes.com/javascript-glossary/#tree-shaking\">tree shaking</a>.</li>\n</ul>\n<p>Webpack is not limited to be use on the frontend, it's also useful in backend Node.js development as well.</p>\n<p>Predecessors of webpack, and still widely used tools, include:</p>\n<ul>\n<li>Grunt</li>\n<li>Broccoli</li>\n<li>Gulp</li>\n</ul>\n<p>There are lots of similarities in what those and Webpack can do, but the main difference is that those are known as <strong>task runners</strong>, while webpack was born as a module bundler.</p>\n<p>It's a more focused tool: you specify an entry point to your app (it could even be an HTML file with script tags) and webpack analyzes the files and bundles all you need to run the app in a single JavaScript output file (or in more files if you use code splitting).</p>\n<h4>Installing webpack</h4>\n<p>Webpack can be installed globally or locally for each project.</p>\n<h4>Global install</h4>\n<p>Here's how to install it globally with <a href=\"https://flaviocopes.com/yarn/\">Yarn</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn global add webpack webpack-cli</code></pre></div>\n<p>with <a href=\"https://flaviocopes.com/npm/\">npm</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm i -g webpack webpack-cli</code></pre></div>\n<p>once this is done, you should be able to run</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">webpack-cli</code></pre></div>\n<h4>Local install</h4>\n<p>Webpack can be installed locally as well. It's the recommended setup, because webpack can be updated per-project, and you have less resistance to using the latest features just for a small project rather than updating all the projects you have that use webpack.</p>\n<p>With <a href=\"https://flaviocopes.com/yarn/\">Yarn</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add webpack webpack-cli -D</code></pre></div>\n<p>with <a href=\"https://flaviocopes.com/npm/\">npm</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm i webpack webpack-cli --save-dev</code></pre></div>\n<p>Once this is done, add this to your <code class=\"language-text\">package.json</code> file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  //...\n  \"scripts\": {\n    \"build\": \"webpack\"\n  }\n}</code></pre></div>\n<p>once this is done, you can run webpack by typing</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn build</code></pre></div>\n<p>in the project root.</p>\n<h4>Webpack configuration</h4>\n<p>By default, webpack (starting from version 4) does not require any config if you respect these conventions:</p>\n<ul>\n<li>the <strong>entry point</strong> of your app is <code class=\"language-text\">./src/index.js</code></li>\n<li>the output is put in <code class=\"language-text\">./dist/main.js</code>.</li>\n<li>Webpack works in production mode</li>\n</ul>\n<p>You can customize every little bit of webpack of course, when you need. The webpack configuration is stored in the <code class=\"language-text\">webpack.config.js</code> file, in the project root folder.</p>\n<h4>The entry point</h4>\n<p>By default the entry point is <code class=\"language-text\">./src/index.js</code> This simple example uses the <code class=\"language-text\">./index.js</code> file as a starting point:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  entry: './index.js'\n  /*...*/\n}</code></pre></div>\n<h4>The output</h4>\n<p>By default the output is generated in <code class=\"language-text\">./dist/main.js</code>. This example puts the output bundle into <code class=\"language-text\">app.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'app.js'\n  }\n  /*...*/\n}</code></pre></div>\n<h4>Loaders</h4>\n<p>Using webpack allows you to use <code class=\"language-text\">import</code> or <code class=\"language-text\">require</code> statements in your JavaScript code to not just include other JavaScript, but any kind of file, for example CSS.</p>\n<p>Webpack aims to handle all our dependencies, not just JavaScript, and loaders are one way to do that.</p>\n<p>For example, in your code you can use:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import 'style.css'</code></pre></div>\n<p>by using this loader configuration:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  module: {\n    rules: [\n      { test: /\\.css$/, use: 'css-loader' },\n    }]\n  }\n  /*...*/\n}</code></pre></div>\n<p>The <a href=\"https://flaviocopes.com/javascript-regular-expressions/\">regular expression</a> targets any CSS file.</p>\n<p>A loader can have options:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  module: {\n    rules: [\n      {\n        test: /\\.css$/,\n        use: [\n          {\n            loader: 'css-loader',\n            options: {\n              modules: true\n            }\n          }\n        ]\n      }\n    ]\n  }\n  /*...*/\n}</code></pre></div>\n<p>You can require multiple loaders for each rule:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  module: {\n    rules: [\n      {\n        test: /\\.css$/,\n        use:\n          [\n            'style-loader',\n            'css-loader',\n          ]\n      }\n    ]\n  }\n  /*...*/\n}</code></pre></div>\n<p>In this example, <code class=\"language-text\">css-loader</code> interprets the <code class=\"language-text\">import 'style.css'</code> directive in the CSS. <code class=\"language-text\">style-loader</code> is then responsible for injecting that CSS in the DOM, using a <code class=\"language-text\">&lt;style></code> tag.</p>\n<p>The order matters, and it's reversed (the last is executed first).</p>\n<p>What kind of loaders are there? Many! <a href=\"https://webpack.js.org/loaders/\">You can find the full list here</a>.</p>\n<p>A commonly used loader is Babel, which is used to transpile modern JavaScript to ES5 code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  module: {\n    rules: [\n      {\n        test: /\\.js$/,\n        exclude: /(node_modules|bower_components)/,\n        use: {\n          loader: 'babel-loader',\n          options: {\n            presets: ['@babel/preset-env']\n          }\n        }\n      }\n    ]\n  }\n  /*...*/\n}</code></pre></div>\n<p>This example makes Babel preprocess all our React/JSX files:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  module: {\n    rules: [\n      {\n        test: /\\.(js|jsx)$/,\n        exclude: /node_modules/,\n        use: 'babel-loader'\n      }\n    ]\n  },\n  resolve: {\n    extensions: [\n      '.js',\n      '.jsx'\n    ]\n  }\n  /*...*/\n}</code></pre></div>\n<p><a href=\"https://webpack.js.org/loaders/babel-loader/\">See the <code class=\"language-text\">babel-loader</code> options here</a>.</p>\n<h4>Plugins</h4>\n<p>Plugins are like loaders, but on steroids. They can do things that loaders can't do, and they are the main building block of webpack.</p>\n<p>Take this example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  plugins: [\n    new HTMLWebpackPlugin()\n  ]\n  /*...*/\n}</code></pre></div>\n<p>The <code class=\"language-text\">HTMLWebpackPlugin</code> plugin has the job of automatically creating an HTML file, adding the output JS bundle path, so the JavaScript is ready to be served.</p>\n<p>There are <a href=\"https://webpack.js.org/plugins/\">lots of plugins available</a>.</p>\n<p>One useful plugin, <code class=\"language-text\">CleanWebpackPlugin</code>, can be used to clear the <code class=\"language-text\">dist/</code> folder before creating any output, so you don't leave files around when you change the name of the output file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  plugins: [\n    new CleanWebpackPlugin(['dist']),\n  ]\n  /*...*/\n}</code></pre></div>\n<h4>The webpack mode</h4>\n<p>This mode (introduced in webpack 4) sets the environment on which webpack works. It can be set to <code class=\"language-text\">development</code> or <code class=\"language-text\">production</code> (defaults to production, so you only set it when moving to development)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  entry: './index.js',\n  mode: 'development',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'app.js'\n  }\n}</code></pre></div>\n<p>Development mode:</p>\n<ul>\n<li>builds very fast</li>\n<li>is less optimized than production</li>\n<li>does not remove comments</li>\n<li>provides more detailed error messages and suggestions</li>\n<li>provides a better debugging experience</li>\n</ul>\n<p>Production mode is slower to build, since it needs to generate a more optimized bundle. The resulting JavaScript file is smaller in size, as it removes many things that are not needed in production.</p>\n<p>I made a sample app that just prints a <code class=\"language-text\">console.log</code> statement.</p>\n<p>Here's the production bundle:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/kbXOiSFaO06VSDxcLC29Nh4a8ycSoaL9LDup\" alt=\"kbXOiSFaO06VSDxcLC29Nh4a8ycSoaL9LDup\"></p>\n<p>Here's the development bundle:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/W-1sAge4rvYL0aH00e7FuyJ5NLv7PJYpves0\" alt=\"W-1sAge4rvYL0aH00e7FuyJ5NLv7PJYpves0\"></p>\n<h4>Running webpack</h4>\n<p>Webpack can be run from the command line manually if installed globally, but generally you write a script inside the <code class=\"language-text\">package.json</code> file, which is then run using <code class=\"language-text\">npm</code> or <code class=\"language-text\">yarn</code>.</p>\n<p>For example this <code class=\"language-text\">package.json</code> scripts definition we used before:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">\"scripts\": {\n  \"build\": \"webpack\"\n}</code></pre></div>\n<p>allows us to run <code class=\"language-text\">webpack</code> by running</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm run build</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn run build</code></pre></div>\n<p>or simply</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn build</code></pre></div>\n<h4>Watching changes</h4>\n<p>Webpack can automatically rebuild the bundle when a change in your app happens, and keep listening for the next change.</p>\n<p>Just add this script:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">\"scripts\": {\n  \"watch\": \"webpack --watch\"\n}</code></pre></div>\n<p>and run</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm run watch</code></pre></div>\n<p>or</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn run watch</code></pre></div>\n<p>or simply</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn watch</code></pre></div>\n<p>One nice feature of the watch mode is that the bundle is only changed if the build has no errors. If there are errors, <code class=\"language-text\">watch</code> will keep listening for changes, and try to rebuild the bundle, but the current, working bundle is not affected by those problematic builds.</p>\n<h4>Handling images</h4>\n<p>Webpack allows us to use images in a very convenient way, using the <code class=\"language-text\">[file-loader](https://webpack.js.org/loaders/file-loader/)</code> loader.</p>\n<p>This simple configuration:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  module: {\n    rules: [\n      {\n        test: /\\.(png|svg|jpg|gif)$/,\n        use: [\n          'file-loader'\n        ]\n      }\n    ]\n  }\n  /*...*/\n}</code></pre></div>\n<p>Allows you to import images in your JavaScript:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import Icon from './icon.png'\n\nconst img = new Image()\nimg.src = Icon\nelement.appendChild(img)</code></pre></div>\n<p>(<code class=\"language-text\">img</code> is an HTMLImageElement. Check the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image\">Image docs</a>)</p>\n<p><code class=\"language-text\">file-loader</code> can handle other asset types as well, like fonts, CSV files, xml, and more.</p>\n<p>Another nice tool to work with images is the <code class=\"language-text\">url-loader</code> loader.</p>\n<p>This example loads any PNG file smaller than 8KB as a <a href=\"https://flaviocopes.com/data-urls/\">data URL</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  module: {\n    rules: [\n      {\n        test: /\\.png$/,\n        use: [\n          {\n            loader: 'url-loader',\n            options: {\n              limit: 8192\n            }\n          }\n        ]\n      }\n    ]\n  }\n  /*...*/\n}</code></pre></div>\n<h4>Process your SASS code and transform it to CSS</h4>\n<p>Using <code class=\"language-text\">sass-loader</code>, <code class=\"language-text\">css-loader</code> and <code class=\"language-text\">style-loader</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  module: {\n    rules: [\n      {\n        test: /\\.scss$/,\n        use: [\n          'style-loader',\n          'css-loader',\n          'sass-loader'\n        ]\n      }\n    ]\n  }\n  /*...*/\n}</code></pre></div>\n<h4>Generate Source Maps</h4>\n<p>Since webpack bundles the code, Source Maps are mandatory to get a reference to the original file that raised an error, for example.</p>\n<p>You tell webpack to generate source maps using the <code class=\"language-text\">devtool</code> property of the configuration:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  /*...*/\n  devtool: 'inline-source-map',\n  /*...*/\n}</code></pre></div>\n<p><code class=\"language-text\">devtool</code> has <a href=\"https://webpack.js.org/configuration/devtool/\">many possible values</a>, the most used probably are:</p>\n<ul>\n<li><code class=\"language-text\">none</code>: adds no source maps</li>\n<li><code class=\"language-text\">source-map</code>: ideal for production, provides a separate source map that can be minimized, and adds a reference into the bundle, so development tools know that the source map is available. Of course you should configure the server to avoid shipping this, and just use it for debugging purposes</li>\n<li><code class=\"language-text\">inline-source-map</code>: ideal for development, inlines the source map as a Data URL</li>\n</ul>\n<h3>SECTION 7: TESTING</h3>\n<h3>Jest</h3>\n<p>Jest is a library for testing JavaScript code.</p>\n<p>It's an open source project maintained by Facebook, and it's especially well suited for React code testing, although not limited to that: it can test any JavaScript code. Its strengths are:</p>\n<ul>\n<li>it's fast</li>\n<li>it can perform <strong>snapshot testing</strong></li>\n<li>it's opinionated, and provides everything out of the box without requiring you to make choices</li>\n</ul>\n<p>Jest is a tool very similar to Mocha, although they have differences:</p>\n<ul>\n<li>Mocha is less opinionated, while Jest has a certain set of conventions</li>\n<li>Mocha requires more configuration, while Jest works usually out of the box, thanks to being opinionated</li>\n<li>Mocha is older and more established, with more tooling integrations</li>\n</ul>\n<p>In my opinion the biggest feature of Jest is it's an out of the box solution that works without having to interact with other testing libraries to perform its job.</p>\n<h4>Installation</h4>\n<p>Jest is automatically installed in <code class=\"language-text\">create-react-app</code>, so if you use that, you don't need to install Jest.</p>\n<p>Jest can be installed in any other project using <a href=\"https://flaviocopes.com/yarn/\">Yarn</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add --dev jest</code></pre></div>\n<p>or <a href=\"https://flaviocopes.com/npm/\">npm</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install --save-dev jest</code></pre></div>\n<p>notice how we instruct both to put Jest in the <code class=\"language-text\">devDependencies</code> part of the <code class=\"language-text\">package.json</code> file, so that it will only be installed in the development environment and not in production.</p>\n<p>Add this line to the scripts part of your <code class=\"language-text\">package.json</code> file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"scripts\": {\n    \"test\": \"jest\"\n  }\n}</code></pre></div>\n<p>so that tests can be run using <code class=\"language-text\">yarn test</code> or <code class=\"language-text\">npm run test</code>.</p>\n<p>Alternatively, you can install Jest globally:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn global add jest</code></pre></div>\n<p>and run all your tests using the <code class=\"language-text\">jest</code> command line tool.</p>\n<h4>Create the first Jest test</h4>\n<p>Projects created with <code class=\"language-text\">create-react-app</code> have Jest installed and preconfigured out of the box, but adding Jest to any project is as easy as typing</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add --dev jest</code></pre></div>\n<p>Add to your <code class=\"language-text\">package.json</code> this line:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"scripts\": {\n    \"test\": \"jest\"\n  }\n}</code></pre></div>\n<p>and run your tests by executing <code class=\"language-text\">yarn test</code> in your shell.</p>\n<p>Now, you don't have any tests here, so nothing is going to be executed:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/QJ4lMCN6PhDyBBZ8mPyLmLciew9p9cUE9ug0\" alt=\"QJ4lMCN6PhDyBBZ8mPyLmLciew9p9cUE9ug0\"></p>\n<p>Let's create the first test. Open a <code class=\"language-text\">math.js</code> file and type a couple functions that we'll later test:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const sum = (a, b) => a + b\nconst mul = (a, b) => a * b\nconst sub = (a, b) => a - b\nconst div = (a, b) => a / b\n\nexport default { sum, mul, sub, div }</code></pre></div>\n<p>Now create a <code class=\"language-text\">math.test.js</code> file, in the same folder, and there we'll use Jest to test the functions defined in <code class=\"language-text\">math.js</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const { sum, mul, sub, div } = require('./math')\n\ntest('Adding 1 + 1 equals 2', () => {\n  expect(sum(1, 1)).toBe(2)\n})\ntest('Multiplying 1 * 1 equals 1', () => {\n  expect(mul(1, 1)).toBe(1)\n})\ntest('Subtracting 1 - 1 equals 0', () => {\n  expect(sub(1, 1)).toBe(0)\n})\ntest('Dividing 1 / 1 equals 1', () => {\n  expect(div(1, 1)).toBe(1)\n})</code></pre></div>\n<p>Running <code class=\"language-text\">yarn test</code> results in Jest being run on all the test files it finds, and returning us the end result:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/vGSvRogM-QF8N3EP5j9vUYYrkWvRc89OhE98\" alt=\"vGSvRogM-QF8N3EP5j9vUYYrkWvRc89OhE98\"></p>\n<h4>Run Jest with VS Code</h4>\n<p>Visual Studio Code is a great editor for JavaScript development. The <a href=\"https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest\">Jest extension</a> offers a top notch integration for our tests.</p>\n<p>Once you install it, it will automatically detect if you have installed Jest in your devDependencies and run the tests. You can also invoke the tests manually by selecting the <strong>Jest: Start Runner</strong> command. It will run the tests and stay in watch mode to re-run them whenever you change one of the files that have a test (or a test file):</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/WYyCsxacP34Fss8u9jT5lT0u3O--1Uwz9cKW\" alt=\"WYyCsxacP34Fss8u9jT5lT0u3O--1Uwz9cKW\"></p>\n<h4>Matchers</h4>\n<p>In the previous article I used <code class=\"language-text\">toBe()</code> as the only <strong>matcher</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">test('Adding 1 + 1 equals 2', () => {\n  expect(sum(1, 1)).toBe(2)\n})</code></pre></div>\n<p>A matcher is a method that lets you test values.</p>\n<p>Most commonly used matchers, comparing the value of the result of <code class=\"language-text\">expect()</code> with the value passed in as argument, are:</p>\n<ul>\n<li><code class=\"language-text\">toBe</code> compares strict equality, using <code class=\"language-text\">===</code></li>\n<li><code class=\"language-text\">toEqual</code> compares the values of two variables. If it's an object or array, it checks the equality of all the properties or elements</li>\n<li><code class=\"language-text\">toBeNull</code> is true when passing a null value</li>\n<li><code class=\"language-text\">toBeDefined</code> is true when passing a defined value (opposite to the above)</li>\n<li><code class=\"language-text\">toBeUndefined</code> is true when passing an undefined value</li>\n<li><code class=\"language-text\">toBeCloseTo</code> is used to compare floating values, avoiding rounding errors</li>\n<li><code class=\"language-text\">toBeTruthy</code> true if the value is considered true (like an <code class=\"language-text\">if</code> does)</li>\n<li><code class=\"language-text\">toBeFalsy</code> true if the value is considered false (like an <code class=\"language-text\">if</code> does)</li>\n<li><code class=\"language-text\">toBeGreaterThan</code> true if the result of expect() is higher than the argument</li>\n<li><code class=\"language-text\">toBeGreaterThanOrEqual</code> true if the result of expect() is equal to the argument, or higher than the argument</li>\n<li><code class=\"language-text\">toBeLessThan</code> true if the result of expect() is lower than the argument</li>\n<li><code class=\"language-text\">toBeLessThanOrEqual</code> true if the result of expect() is equal to the argument, or lower than the argument</li>\n<li><code class=\"language-text\">toMatch</code> is used to compare strings with <a href=\"https://flaviocopes.com/javascript-regular-expressions/\">regular expression</a> pattern matching</li>\n<li><code class=\"language-text\">toContain</code> is used in arrays, true if the expected array contains the argument in its elements set</li>\n<li><code class=\"language-text\">toHaveLength(number)</code>: checks the length of an array</li>\n<li><code class=\"language-text\">toHaveProperty(key, value)</code>: checks if an object has a property, and optionally checks its value</li>\n<li><code class=\"language-text\">toThrow</code> checks if a function you pass throws an exception (in general) or a specific exception</li>\n<li><code class=\"language-text\">toBeInstanceOf()</code>: checks if an object is an instance of a class</li>\n</ul>\n<p>All those matchers can be negated using <code class=\"language-text\">.not.</code> inside the statement, for example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">test('Adding 1 + 1 does not equal 3', () => {\n  expect(sum(1, 1)).not.toBe(3)\n})</code></pre></div>\n<p>For use with promises, you can use <code class=\"language-text\">.resolves</code> and <code class=\"language-text\">.rejects</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">expect(Promise.resolve('lemon')).resolves.toBe('lemon')\n\nexpect(Promise.reject(new Error('octopus'))).rejects.toThrow('octopus')</code></pre></div>\n<h4>Setup</h4>\n<p>Before running your tests you will want to perform some initialization.</p>\n<p>To do something once before all the tests run, use the <code class=\"language-text\">beforeAll()</code> function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">beforeAll(() => {\n  //do something\n})</code></pre></div>\n<p>To perform something before each test runs, use <code class=\"language-text\">beforeEach()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">beforeEach(() => {\n  //do something\n})</code></pre></div>\n<h4>Teardown</h4>\n<p>Just as you can do with setup, you can also perform something after each test runs:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">afterEach(() => {\n  //do something\n})</code></pre></div>\n<p>and after all tests end:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">afterAll(() => {\n  //do something\n})</code></pre></div>\n<h4>Group tests using describe()</h4>\n<p>You can create groups of tests, in a single file, that isolate the setup and teardown functions:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">describe('first set', () => {\n  beforeEach(() => {\n    //do something\n  })\n  afterAll(() => {\n    //do something\n  })\n  test(/*...*/)\n  test(/*...*/)\n})\n\ndescribe('second set', () => {\n  beforeEach(() => {\n    //do something\n  })\n  beforeAll(() => {\n    //do something\n  })\n  test(/*...*/)\n  test(/*...*/)\n}) </code></pre></div>\n<h4>Testing asynchronous code</h4>\n<p>Asynchronous code in modern JavaScript can have basically 2 forms: callbacks and promises. On top of promises we can use async/await.</p>\n<h4>Callbacks</h4>\n<p>You can't have a test in a callback, because Jest won't execute it — the execution of the test file ends before the callback is called. To fix this, pass a parameter to the test function, which you can conveniently call <code class=\"language-text\">done</code>. Jest will wait until you call <code class=\"language-text\">done()</code> before ending that test:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//uppercase.js\nfunction uppercase(str, callback) {\n  callback(str.toUpperCase())\n}\nmodule.exports = uppercase\n\n//uppercase.test.js\nconst uppercase = require('./src/uppercase')\n\ntest(`uppercase 'test' to equal 'TEST'`, (done) => {\n  uppercase('test', (str) => {\n    expect(str).toBe('TEST')\n    done()\n  }\n})</code></pre></div>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/wsyP30ZeaXYM6LTu4UOiTIg4cFjUOo4GtutV\" alt=\"wsyP30ZeaXYM6LTu4UOiTIg4cFjUOo4GtutV\"></p>\n<h4>Promises</h4>\n<p>With functions that return promises, we simply <strong>return a promise</strong> from the test:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//uppercase.js\nconst uppercase = str => {\n  return new Promise((resolve, reject) => {\n    if (!str) {\n      reject('Empty string')\n      return\n    }\n    resolve(str.toUpperCase())\n  })\n}\nmodule.exports = uppercase\n\n//uppercase.test.js\nconst uppercase = require('./uppercase')\ntest(`uppercase 'test' to equal 'TEST'`, () => {\n  return uppercase('test').then(str => {\n    expect(str).toBe('TEST')\n  })\n})</code></pre></div>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/8j7LKC8uKE5Tw0X4WN4Gm0rD3NziyPxNwyCn\" alt=\"8j7LKC8uKE5Tw0X4WN4Gm0rD3NziyPxNwyCn\"></p>\n<p>Promises that are rejected can be tested using <code class=\"language-text\">.catch()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//uppercase.js\nconst uppercase = str => {\n  return new Promise((resolve, reject) => {\n    if (!str) {\n      reject('Empty string')\n      return\n    }\n    resolve(str.toUpperCase())\n  })\n}\n\nmodule.exports = uppercase\n\n//uppercase.test.js\nconst uppercase = require('./uppercase')\n\ntest(`uppercase 'test' to equal 'TEST'`, () => {\n  return uppercase('').catch(e => {\n    expect(e).toMatch('Empty string')\n  })\n})</code></pre></div>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/F9HWCuZKWwG1RMZdNkDAaGMRsC0zaIsMokia\" alt=\"F9HWCuZKWwG1RMZdNkDAaGMRsC0zaIsMokia\"></p>\n<h4>Async/await</h4>\n<p>To test functions that return promises we can also use async/await, which makes the syntax very straightforward and simple:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//uppercase.test.js\nconst uppercase = require('./uppercase')\ntest(`uppercase 'test' to equal 'TEST'`, async () => {\n  const str = await uppercase('test')\n  expect(str).toBe('TEST')\n})</code></pre></div>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/7xWQMgM0PC9AGUBewAzcCgNWvHIjjxerfRxR\" alt=\"7xWQMgM0PC9AGUBewAzcCgNWvHIjjxerfRxR\"></p>\n<h4>Mocking</h4>\n<p>In testing, <strong>mocking</strong> allows you to test functionality that depends on:</p>\n<ul>\n<li><strong>Database</strong></li>\n<li><strong>Network</strong> requests</li>\n<li>access to <strong>Files</strong></li>\n<li>any <strong>External</strong> system</li>\n</ul>\n<p>so that:</p>\n<ol>\n<li>your tests run <strong>faster</strong>, giving a quick turnaround time during development</li>\n<li>your tests are <strong>independent</strong> of network conditions, or the state of the database</li>\n<li>your tests do not <strong>pollute</strong> any data storage because they do not touch the database</li>\n<li>any change done in a test does not change the state for subsequent tests, and re-running the test suite should start from a known and reproducible starting point</li>\n<li>you don't have to worry about rate limiting on API calls and network requests</li>\n</ol>\n<p>Mocking is useful when you want to avoid side effects (e.g. writing to a database) or you want to skip slow portions of code (like network access), and also avoids implications with running your tests multiple times (e.g. imagine a function that sends an email or calls a rate-limited API).</p>\n<p>Even more important, if you are writing a <strong>Unit Test</strong>, you should test the functionality of a function in isolation, not with all its baggage of things it touches.</p>\n<p>Using mocks, you can inspect if a module function has been called and which parameters were used, with:</p>\n<ul>\n<li><code class=\"language-text\">expect().toHaveBeenCalled()</code>: check if a spied function has been called</li>\n<li><code class=\"language-text\">expect().toHaveBeenCalledTimes()</code>: count how many times a spied function has been called</li>\n<li><code class=\"language-text\">expect().toHaveBeenCalledWith()</code>: check if the function has been called with a specific set of parameters</li>\n<li><code class=\"language-text\">expect().toHaveBeenLastCalledWith()</code>: check the parameters of the last time the function has been invoked</li>\n</ul>\n<h4>Spy packages without affecting the functions code</h4>\n<p>When you import a package, you can tell Jest to \"spy\" on the execution of a particular function, using <code class=\"language-text\">spyOn()</code>, without affecting how that method works.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const mathjs = require('mathjs')\n\ntest(`The mathjs log function`, () => {\n  const spy = jest.spyOn(mathjs, 'log')\n  const result = mathjs.log(10000, 10)\n  \n  expect(mathjs.log).toHaveBeenCalled()\n  expect(mathjs.log).toHaveBeenCalledWith(10000, 10)\n})</code></pre></div>\n<h4>Mock an entire package</h4>\n<p>Jest provides a convenient way to mock an entire package. Create a <code class=\"language-text\">__mocks__</code>folder in the project root, and in this folder create one JavaScript file for each of your packages.</p>\n<p>Say you import <code class=\"language-text\">mathjs</code>. Create a <code class=\"language-text\">__mocks__/mathjs.js</code> file in your project root, and add this content:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  log: jest.fn(() => 'test')\n}</code></pre></div>\n<p>This will mock the log() function of the package. Add as many functions as you want to mock:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const mathjs = require('mathjs')\n\ntest(`The mathjs log function`, () => {\n  const result = mathjs.log(10000, 10)\n  expect(result).toBe('test')\n  expect(mathjs.log).toHaveBeenCalled()\n  expect(mathjs.log).toHaveBeenCalledWith(10000, 10)\n})</code></pre></div>\n<h4>Mock a single function</h4>\n<p>More simply, you can mock a single function using <code class=\"language-text\">jest.fn()</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const mathjs = require('mathjs')\n\nmathjs.log = jest.fn(() => 'test')\ntest(`The mathjs log function`, () => {\n  const result = mathjs.log(10000, 10)\n  expect(result).toBe('test')\n  expect(mathjs.log).toHaveBeenCalled()\n  expect(mathjs.log).toHaveBeenCalledWith(10000, 10)\n})</code></pre></div>\n<p>You can also use <code class=\"language-text\">jest.fn().mockReturnValue('test')</code> to create a simple mock that does nothing except returning a value.</p>\n<h4>Pre-built mocks</h4>\n<p>You can find pre-made mocks for popular libraries. For example this package <a href=\"https://github.com/jefflau/jest-fetch-mock\">https://github.com/jefflau/jest-fetch-mock</a> allows you to mock <code class=\"language-text\">fetch()</code> calls, and provide sample return values without interacting with the actual server in your tests.</p>\n<h4>Snapshot testing</h4>\n<p>Snapshot testing is a pretty cool feature offered by Jest. It can memorize how your UI components are rendered, and compare it to the current test, raising an error if there's a mismatch.</p>\n<p>This is a simple test on the App component of a simple <code class=\"language-text\">create-react-app</code> application (make sure you install <code class=\"language-text\">react-test-renderer</code>):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\nimport App from './App'\nimport renderer from 'react-test-renderer'\n\nit('renders correctly', () => {\n  const tree = renderer.create(&lt;App />).toJSON()\n  expect(tree).toMatchSnapshot()\n})</code></pre></div>\n<p>the first time you run this test, Jest saves the snapshot to the <code class=\"language-text\">__snapshots__</code>folder. Here's what App.test.js.snap contains:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Jest Snapshot v1, https://goo.gl/fbAQLP\n\nexports[`renders correctly 1`] = `\n&lt;div\n  className=\"App\"\n>\n  &lt;header\n    className=\"App-header\"\n  >\n    &lt;img\n      alt=\"logo\"\n      className=\"App-logo\"\n      src=\"logo.svg\"\n    />\n    &lt;h1\n      className=\"App-title\"\n    >\n      Welcome to React\n    &lt;/h1>\n  &lt;/header>\n  &lt;p\n    className=\"App-intro\"\n  >\n    To get started, edit\n    &lt;code>\n      src/App.js\n    &lt;/code>\n     and save to reload.\n  &lt;/p>\n&lt;/div>\n`</code></pre></div>\n<p>As you see it's the code that the App component renders, nothing more.</p>\n<p>The next time the test compares the output of <code class=\"language-text\">&lt;App</code> /> to this. If App changes, you get an error:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/imS-QSkC1rmVVRYLkLYSJrGk5b3DOjodEJkx\" alt=\"imS-QSkC1rmVVRYLkLYSJrGk5b3DOjodEJkx\"></p>\n<p>When using <code class=\"language-text\">yarn test</code> in <code class=\"language-text\">create-react-app</code> you are in <strong>watch mode</strong>, and from there you can press <code class=\"language-text\">w</code> and show more options:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Watch Usage\n › Press u to update failing snapshots.\n › Press p to filter by a filename regex pattern.\n › Press t to filter by a test name regex pattern.\n › Press q to quit watch mode.\n › Press Enter to trigger a test run.</code></pre></div>\n<p>If your change is intended, pressing <code class=\"language-text\">u</code> will update the failing snapshots, and make the test pass.</p>\n<p>You can also update the snapshot by running <code class=\"language-text\">jest -u</code> (or <code class=\"language-text\">jest --updateSnapshot</code>) outside of watch mode.</p>\n<h3>Testing React components</h3>\n<p>The easiest way to start with testing React components is doing snapshot testing, a testing technique that lets you test components in isolation.</p>\n<p>If you are familiar with testing software, it's just like unit testing you do for classes: you test each component functionality.</p>\n<p>I assume you created a React app with <code class=\"language-text\">create-react-app</code>, which already comes with <strong>Jest</strong> installed, the testing package we'll need.</p>\n<p>Let's start with a simple test. CodeSandbox is a great environment to try this out. Start with a React sandbox, and create an <code class=\"language-text\">App.js</code> component in a <code class=\"language-text\">components</code> folder, and add an <code class=\"language-text\">App.test.js</code> file.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\n\nexport default function App() {\n  return (\n    &lt;div className=\"App\">\n      &lt;h1>Hello CodeSandbox&lt;/h1>\n      &lt;h2>Start editing to see some magic happen!&lt;/h2>\n    &lt;/div>\n  )\n}</code></pre></div>\n<p>Our first test is dumb:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">test('First test', () => {\n  expect(true).toBeTruthy()\n})</code></pre></div>\n<p>When CodeSandbox detects test files, it automatically runs them for you, and you can click the Tests button in the bottom of the view to show your test results:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/DKFPyZSWF0O2ldKLAMyz7i0Di9NLqMs-ChQ4\" alt=\"DKFPyZSWF0O2ldKLAMyz7i0Di9NLqMs-ChQ4\"></p>\n<p>A test file can contain multiple tests:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/iWZgjKzyxhyAtvjpsyTTEpzs4pKot938aVjk\" alt=\"iWZgjKzyxhyAtvjpsyTTEpzs4pKot938aVjk\"></p>\n<p>Let's do something a bit more useful now, to actually test a React component. We only have App now, which is not doing anything really useful, so let's first set up the environment with a little application with more functionality: the counter app we built previously. If you skipped it, you can go back and read how we built it, but for easier reference I add it here again.</p>\n<p>It's just 2 components: App and Button. Create the <code class=\"language-text\">App.js</code> file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React, { useState } from 'react'\nimport Button from './Button'\n\nconst App = () => {\n  const [count, setCount] = useState(0)\n  \n  const incrementCount = increment => {\n    setCount(count + increment)\n  }\n  \n  return (\n    &lt;div>\n      &lt;Button increment={1} onClickFunction={incrementCount} />\n      &lt;Button increment={10} onClickFunction={incrementCount} />\n      &lt;Button increment={100} onClickFunction={incrementCount} />\n      &lt;Button increment={1000} onClickFunction={incrementCount} />\n      &lt;span>{count}&lt;/span>\n    &lt;/div>\n  )\n}\n\nexport default App</code></pre></div>\n<p>and the <code class=\"language-text\">Button.js</code> file:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\n\nconst Button = ({ increment, onClickFunction }) => {\n  const handleClick = () => {\n    onClickFunction(increment)\n  }\n  return &lt;button onClick={handleClick}>+{increment}&lt;/button>\n}\n\nexport default Button</code></pre></div>\n<p>We are going to use the <code class=\"language-text\">react-testing-library</code>, which is a great help as it allows us to inspect the output of every component and to apply events on them. You can read more about it on <a href=\"https://github.com/kentcdodds/react-testing-library\">https://github.com/kentcdodds/react-testing-library</a> or watch <a href=\"https://www.youtube.com/watch?v=JKOwJUM4_RM\">this video</a>.</p>\n<p>Let's test the Button component first.</p>\n<p>We start by importing <code class=\"language-text\">render</code> and <code class=\"language-text\">fireEvent</code> from <code class=\"language-text\">react-testing-library</code>, two helpers. The first lets us render JSX. The second lets us emit events on a component.</p>\n<p>Create a <code class=\"language-text\">Button.test.js</code> and put it in the same folder as <code class=\"language-text\">Button.js</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\nimport { render, fireEvent } from 'react-testing-library'\nimport Button from './Button'</code></pre></div>\n<p>Buttons are used in the app to accept a click event and then they call a function passed to the <code class=\"language-text\">onClickFunction</code> prop. We add a <code class=\"language-text\">count</code> variable and we create a function that increments it:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let count\n\nconst incrementCount = increment => {\n  count += increment\n}</code></pre></div>\n<p>Now off to the actual tests. We first initialize count to 0, and we render a <code class=\"language-text\">+1</code> <code class=\"language-text\">Button</code> component passing a <code class=\"language-text\">1</code> to <code class=\"language-text\">increment</code> and our <code class=\"language-text\">incrementCount</code> function to <code class=\"language-text\">onClickFunction</code>.</p>\n<p>Then we get the content of the first child of the component, and we check it outputs <code class=\"language-text\">+1</code>.</p>\n<p>We then proceed to clicking the button, and we check that the count got from 0 to 1:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">test('+1 Button works', () => {\n  count = 0\n  const { container } = render(\n    &lt;Button increment={1} onClickFunction={incrementCount} />\n  )\n  const button = container.firstChild\n  expect(button.textContent).toBe('+1')\n  expect(count).toBe(0)\n  fireEvent.click(button)\n  expect(count).toBe(1)\n})</code></pre></div>\n<p>Similarly we test a +100 button, this time checking the output is <code class=\"language-text\">+100</code> and the button click increments the count of 100.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">test('+100 Button works', () => {\n  count = 0\n  const { container } = render(\n    &lt;Button increment={100} onClickFunction={incrementCount} />\n  )\n  const button = container.firstChild\n  expect(button.textContent).toBe('+100')\n  expect(count).toBe(0)\n  fireEvent.click(button)\n  expect(count).toBe(100)\n})</code></pre></div>\n<p>Let's test the App component now. It shows 4 buttons and the result in the page. We can inspect each button and see if the result increases when we click them, clicking multiple times as well:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\nimport { render, fireEvent } from 'react-testing-library'\nimport App from './App'\n\ntest('App works', () => {\n  const { container } = render(&lt;App />)\n  console.log(container)\n  const buttons = container.querySelectorAll('button')\n  \n  expect(buttons[0].textContent).toBe('+1')\n  expect(buttons[1].textContent).toBe('+10')\n  expect(buttons[2].textContent).toBe('+100')\n  expect(buttons[3].textContent).toBe('+1000')\n  \n  const result = container.querySelector('span')\n  expect(result.textContent).toBe('0')\n  fireEvent.click(buttons[0])\n  expect(result.textContent).toBe('1')\n  fireEvent.click(buttons[1])\n  expect(result.textContent).toBe('11')\n  fireEvent.click(buttons[2])\n  expect(result.textContent).toBe('111')\n  fireEvent.click(buttons[3])\n  expect(result.textContent).toBe('1111')\n  fireEvent.click(buttons[2])\n  expect(result.textContent).toBe('1211')\n  fireEvent.click(buttons[1])\n  expect(result.textContent).toBe('1221')\n  fireEvent.click(buttons[0])\n  expect(result.textContent).toBe('1222')\n})</code></pre></div>\n<p>Check the code working on this CodeSandbox: <a href=\"https://codesandbox.io/s/pprl4y0wq\">https://codesandbox.io/s/pprl4y0wq</a></p>\n<h3>SECTION 8: THE REACT ECOSYSTEM</h3>\n<p>The ecosystem around React is huge. Here I introduce you to 4 of the most popular projects based upon React: React Router, Redux, Next.js, Gatsby.</p>\n<h3>React Router</h3>\n<p>React Router is the de-facto React routing library, and it's one of the most popular projects built on top of React.</p>\n<p>React at its core is a very simple library, and it does not dictate anything about routing.</p>\n<p>Routing in a Single Page Application is the way to introduce some features to navigating the app through links, which are <strong>expected</strong> in normal web applications:</p>\n<ol>\n<li>The browser should <strong>change the URL</strong> when you navigate to a different screen</li>\n<li><strong>Deep linking</strong> should work: if you point the browser to a URL, the application should reconstruct the same view that was presented when the URL was generated.</li>\n<li>The <strong>browser back (and forward) button</strong> should work like expected.</li>\n</ol>\n<p><strong>Routing links together your application navigation with the navigation features offered by the browser</strong>: the <strong>address bar</strong> and the <strong>navigation buttons</strong>.</p>\n<p>React Router offers a way to write your code so that <strong>it will show certain components of your app only if the route matches what you define</strong>.</p>\n<h3>Installation</h3>\n<p>With <a href=\"https://flaviocopes.com/npm/\">npm</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install react-router-dom</code></pre></div>\n<p>With <a href=\"https://flaviocopes.com/yarn/\">Yarn</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add react-router-dom</code></pre></div>\n<h3>Types of routes</h3>\n<p>React Router provides two different kind of routes:</p>\n<ul>\n<li><code class=\"language-text\">BrowserRouter</code></li>\n<li><code class=\"language-text\">HashRouter</code></li>\n</ul>\n<p>One builds classic URLs, the other builds URLs with the hash:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">https://application.com/dashboard   /* BrowserRouter */\nhttps://application.com/#/dashboard /* HashRouter    */</code></pre></div>\n<p>Which one to use is mainly dictated by the browsers you need to support. <code class=\"language-text\">BrowserRouter</code> uses the <a href=\"https://flaviocopes.com/history-api/\">History API</a>, which is relatively recent, and not supported in IE9 and below. If you don't have to worry about older browsers, it's the recommended choice.</p>\n<h3>Components</h3>\n<p>The 3 components you will interact the most when working with React Router are:</p>\n<ul>\n<li><code class=\"language-text\">BrowserRouter</code>, usually aliased as <code class=\"language-text\">Router</code></li>\n<li><code class=\"language-text\">Link</code></li>\n<li><code class=\"language-text\">Route</code></li>\n</ul>\n<p><code class=\"language-text\">BrowserRouter</code> wraps all your Route components.</p>\n<p><code class=\"language-text\">Link</code> components are - as you can imagine - used to generate links to your routes</p>\n<p><code class=\"language-text\">Route</code> components are responsible for showing - or hiding - the components they contain.</p>\n<h3>BrowserRouter</h3>\n<p>Here's a simple example of the BrowserRouter component. You import it from react-router-dom, and you use it to wrap all your app:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\nimport ReactDOM from 'react-dom'\nimport { BrowserRouter as Router } from 'react-router-dom'\n\nReactDOM.render(\n  &lt;Router>\n      &lt;div>\n        &lt;!-- -->\n      &lt;/div>\n  &lt;/Router>,\n  document.getElementById('app')\n)</code></pre></div>\n<p>A BrowserRouter component can only have one child element, so we wrap all we're going to add in a <code class=\"language-text\">div</code> element.</p>\n<h3>Link</h3>\n<p>The Link component is used to trigger new routes. You import it from <code class=\"language-text\">react-router-dom</code>, and you can add the Link components to point at different routes, with the <code class=\"language-text\">to</code> attribute:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\nimport ReactDOM from 'react-dom'\nimport { BrowserRouter as Router, Link } from 'react-router-dom'\n\nReactDOM.render(\n  &lt;Router>\n      &lt;div>\n        &lt;aside>\n          &lt;Link to={`/dashboard`}>Dashboard&lt;/Link>\n          &lt;Link to={`/about`}>About&lt;/Link>\n        &lt;/aside>\n        &lt;!-- -->\n      &lt;/div>\n  &lt;/Router>,\n  document.getElementById('app')\n)</code></pre></div>\n<h3>Route</h3>\n<p>Now let's add the Route component in the above snippet to make things actually work as we want:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\nimport ReactDOM from 'react-dom'\nimport { BrowserRouter as Router, Link, Route } from 'react-router-dom'\n\nconst Dashboard = () => (\n  &lt;div>\n    &lt;h2>Dashboard&lt;/h2>\n    ...\n  &lt;/div>\n)\n\nconst About = () => (\n  &lt;div>\n    &lt;h2>About&lt;/h2>\n    ...\n  &lt;/div>\n)\n\nReactDOM.render(\n  &lt;Router>\n    &lt;div>\n      &lt;aside>\n        &lt;Link to={`/`}>Dashboard&lt;/Link>\n        &lt;Link to={`/about`}>About&lt;/Link>\n      &lt;/aside>\n      \n      &lt;main>\n        &lt;Route exact path=\"/\" component={Dashboard} />\n        &lt;Route path=\"/about\" component={About} />\n      &lt;/main>\n    &lt;/div>\n  &lt;/Router>,\n  document.getElementById('app')\n)</code></pre></div>\n<p>Check this example on Glitch: <a href=\"https://flaviocopes-react-router-v4.glitch.me/\">https://flaviocopes-react-router-v4.glitch.me/</a></p>\n<p>When the route matches <code class=\"language-text\">/</code>, the application shows the <strong>Dashboard</strong> component.</p>\n<p>When the route is changed by clicking the \"About\" link to <code class=\"language-text\">/about</code>, the Dashboard component is removed and the <strong>About</strong> component is inserted in the DOM.</p>\n<p>Notice the <code class=\"language-text\">exact</code> attribute. Without this, <code class=\"language-text\">path=\"/\"</code> would also match <code class=\"language-text\">/about</code>, since <code class=\"language-text\">/</code> is contained in the route.</p>\n<h3>Match multiple paths</h3>\n<p>You can have a route respond to multiple paths simply using a regex, because <code class=\"language-text\">path</code> can be a regular expressions string:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Route path=\"/(about|who)/\" component={Dashboard} /></code></pre></div>\n<h3>Inline rendering</h3>\n<p>Instead of specifying a <code class=\"language-text\">component</code> property on <code class=\"language-text\">Route</code>, you can set a <code class=\"language-text\">render</code> prop:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Route\n  path=\"/(about|who)/\"\n  render={() => (\n    &lt;div>\n      &lt;h2>About&lt;/h2>\n      ...\n    &lt;/div>\n  )}\n/></code></pre></div>\n<h3>Match dynamic route parameter</h3>\n<p>You already saw how to use static routes like</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Posts = () => (\n  &lt;div>\n    &lt;h2>Posts&lt;/h2>\n    ...\n  &lt;/div>\n)\n\n//...\n\n&lt;Route exact path=\"/posts\" component={Posts} /></code></pre></div>\n<p>Here's how to handle dynamic routes:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Post = ({match}) => (\n  &lt;div>\n    &lt;h2>Post #{match.params.id}&lt;/h2>\n    ...\n  &lt;/div>\n)\n\n//...\n\n&lt;Route exact path=\"/post/:id\" component={Post} /></code></pre></div>\n<p>In your Route component you can lookup the dynamic parameters in <code class=\"language-text\">match.params</code>.</p>\n<p><code class=\"language-text\">match</code> is also available in inline rendered routes, and this is especially useful in this case, because we can use the <code class=\"language-text\">id</code> parameter to lookup the post data in our data source before rendering Post:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const posts = [\n  { id: 1, title: 'First', content: 'Hello world!' },\n  { id: 2, title: 'Second', content: 'Hello again!' }\n]\n\nconst Post = ({post}) => (\n  &lt;div>\n    &lt;h2>{post.title}&lt;/h2>\n    {post.content}\n  &lt;/div>\n)\n\n//...\n\n&lt;Route exact path=\"/post/:id\" render={({match}) => (\n  &lt;Post post={posts.find(p => p.id === match.params.id)} />\n)} /></code></pre></div>\n<h3>Redux</h3>\n<p>Redux is a state manager that's usually used along with React, but it's not tied to that library — it can be used with other technologies as well, but we'll stick to React for the sake of the explanation..</p>\n<p>Redux is a way to manage an application state, and move it to an <strong>external global store</strong>.</p>\n<p>There are a few concepts to grasp, but once you do, Redux is a very simple approach to the problem.</p>\n<p>Redux is very popular with React applications, but it's in no way unique to React: there are bindings for nearly any popular framework. That said, I'll make some examples using React as it is its primary use case.</p>\n<h4>When should you use Redux?</h4>\n<p>Redux is ideal for medium to big apps, and you should only use it when you have trouble managing the state with the default state management of React, or the other library you use.</p>\n<p>Simple apps should not need it at all (and there's nothing wrong with simple apps).</p>\n<h4>Immutable State Tree</h4>\n<p>In Redux, the whole state of the application is represented by <strong>one</strong> <a href=\"https://flaviocopes.com/javascript/\">JavaScript</a> object, called <strong>State</strong> or <strong>State Tree</strong>.</p>\n<p>We call it <strong>Immutable State Tree</strong> because it is read only: it can't be changed directly.</p>\n<p>It can only be changed by dispatching an <strong>Action</strong>.</p>\n<h4>Actions</h4>\n<p>An <strong>Action</strong> is <strong>a JavaScript object that describes a change in a minimal way</strong> (with just the information needed):</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  type: 'CLICKED_SIDEBAR'\n}\n\n// e.g. with more data\n{\n  type: 'SELECTED_USER',\n  userId: 232\n}</code></pre></div>\n<p>The only requirement of an action object is having a <code class=\"language-text\">type</code> property, whose value is usually a string.</p>\n<h4>Actions types should be constants</h4>\n<p>In a simple app an action type can be defined as a string, as I did in the example in the previous lesson.</p>\n<p>When the app grows is best to use constants:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const ADD_ITEM = 'ADD_ITEM'\nconst action = { type: ADD_ITEM, title: 'Third item' }</code></pre></div>\n<p>and to separate actions in their own files, and import them</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { ADD_ITEM, REMOVE_ITEM } from './actions'</code></pre></div>\n<h4>Action creators</h4>\n<p><strong>Actions Creators</strong> are functions that create actions.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function addItem(t) {\n  return {\n    type: ADD_ITEM,\n    title: t\n  }\n}</code></pre></div>\n<p>You usually run action creators in combination with triggering the dispatcher:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">dispatch(addItem('Milk'))</code></pre></div>\n<p>or by defining an action dispatcher function:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const dispatchAddItem = i => dispatch(addItem(i))\ndispatchAddItem('Milk')</code></pre></div>\n<h4>Reducers</h4>\n<p>When an action is fired, something must happen, the state of the application must change.</p>\n<p>This is the job of <strong>reducers</strong>.</p>\n<p>A <strong>reducer</strong> is a <strong>pure function</strong> that calculates the next State Tree based on the previous State Tree, and the action dispatched.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">;(currentState, action) => newState</code></pre></div>\n<p>A pure function takes an input and returns an output without changing the input or anything else. Thus, a reducer returns a completely new state tree object that substitutes the previous one.</p>\n<h4>What a reducer should not do</h4>\n<p>A reducer should be a pure function, so it should:</p>\n<ul>\n<li>never mutate its arguments</li>\n<li>never mutate the state, but instead create a new one with <code class=\"language-text\">Object.assign({}, ...)</code></li>\n<li>never generate side-effects (no API calls changing anything)</li>\n<li>never call non-pure functions, functions that change their output based on factors other than their input (e.g. <code class=\"language-text\">Date.now()</code> or <code class=\"language-text\">Math.random()</code>)</li>\n</ul>\n<p>There is no reinforcement, but you should stick to the rules.</p>\n<h4>Multiple reducers</h4>\n<p>Since the state of a complex app could be really wide, there is not a single reducer, but many reducers for any kind of action.</p>\n<h4>A simulation of a reducer</h4>\n<p>At its core, Redux can be simplified with this simple model:</p>\n<h4>The state</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  list: [\n    { title: \"First item\" },\n    { title: \"Second item\" },\n  ],\n  title: 'Groceries list'\n}</code></pre></div>\n<h4>A list of actions</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{ type: 'ADD_ITEM', title: 'Third item' }\n{ type: 'REMOVE_ITEM', index: 1 }\n{ type: 'CHANGE_LIST_TITLE', title: 'Road trip list' }</code></pre></div>\n<h4>A reducer for every part of the state</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const title = (state = '', action) => {\n    if (action.type === 'CHANGE_LIST_TITLE') {\n      return action.title\n    } else {\n      return state\n    }\n}\n\nconst list = (state = [], action) => {\n  switch (action.type) {\n    case 'ADD_ITEM':\n      return state.concat([{ title: action.title }])\n    case 'REMOVE_ITEM':\n      return state.map((item, index) =>\n        action.index === index\n          ? { title: item.title }\n          : item\n    default:\n      return state\n  }\n}</code></pre></div>\n<h4>A reducer for the whole state</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const listManager = (state = {}, action) => {\n  return {\n    title: title(state.title, action),\n    list: list(state.list, action)\n  }\n}</code></pre></div>\n<h4>The Store</h4>\n<p>The <strong>Store</strong> is an object that:</p>\n<ul>\n<li><strong>holds the state</strong> of the app</li>\n<li><strong>exposes the state</strong> via <code class=\"language-text\">getState()</code></li>\n<li>allows us to <strong>update the state</strong> via <code class=\"language-text\">dispatch()</code></li>\n<li>allows us to (un)register a <strong>state change listener</strong> using <code class=\"language-text\">subscribe()</code></li>\n</ul>\n<p>A store is <strong>unique</strong> in the app.</p>\n<p>Here is how a store for the listManager app is created:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { createStore } from 'redux'\nimport listManager from './reducers'\nlet store = createStore(listManager)</code></pre></div>\n<h4>Can I initialize the store with server-side data?</h4>\n<p>Sure, <strong>just pass a starting state</strong>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let store = createStore(listManager, preexistingState)</code></pre></div>\n<h4>Getting the state</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">store.getState()</code></pre></div>\n<h4>Update the state</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">store.dispatch(addItem('Something'))</code></pre></div>\n<h4>Listen to state changes</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const unsubscribe = store.subscribe(() =>\n  const newState = store.getState()\n)\n\nunsubscribe()</code></pre></div>\n<h4>Data Flow</h4>\n<p>Data flow in Redux is always <strong>unidirectional</strong>.</p>\n<p>You call <code class=\"language-text\">dispatch()</code> on the Store, passing an Action.</p>\n<p>The Store takes care of passing the Action to the Reducer, generating the next State.</p>\n<p>The Store updates the State and alerts all the Listeners.</p>\n<h3>Next.js</h3>\n<p>Working on a modern <a href=\"https://flaviocopes.com/javascript/\">JavaScript</a> application powered by <a href=\"https://flaviocopes.com/react/\">React</a> is awesome until you realize that there are a couple problems related to rendering all the content on the client-side.</p>\n<p>First, the page takes longer to the become visible to the user, because before the content loads, all the JavaScript must load, and your application needs to run to determine what to show on the page.</p>\n<p>Second, if you are building a publicly available website, you have a content SEO issue. Search engines are getting better at running and indexing JavaScript apps, but it's much better if we can send them content instead of letting them figure it out.</p>\n<p>The solution to both of those problems is <strong>server rendering</strong>, also called <strong>static pre-rendering</strong>.</p>\n<p>Next.js is one React framework to do all of this in a very simple way, but it's not limited to this. It's advertised by its creators as a <strong>zero-configuration, single-command toolchain for React apps</strong>.</p>\n<p>It provides a common structure that allows you to easily build a frontend React application, and transparently handle server-side rendering for you.</p>\n<p>Here is a non-exhaustive list of the main Next.js features:</p>\n<ul>\n<li><strong>Hot Code Reloading</strong>: Next.js reloads the page when it detects any change saved to disk.</li>\n<li><strong>Automatic Routing</strong>: any URL is mapped to the filesystem, to files put in the <code class=\"language-text\">pages</code> folder, and you don't need any configuration (you have customization options of course).</li>\n<li><strong>Single File Components</strong>: using <a href=\"https://github.com/zeit/styled-jsx\">styled-jsx</a>, completely integrated as built by the same team, it's trivial to add styles scoped to the component.</li>\n<li><strong>Server Rendering</strong>: you can (optionally) render React components on the server side, before sending the HTML to the client.</li>\n<li><strong>Ecosystem Compatibility</strong>: Next.js plays well with the rest of the JavaScript, Node and React ecosystem.</li>\n<li><strong>Automatic Code Splitting</strong>: pages are rendered with just the libraries and JavaScript that they need, no more.</li>\n<li><strong>Prefetching</strong>: the <code class=\"language-text\">Link</code> component, used to link together different pages, supports a <code class=\"language-text\">prefetch</code> prop which automatically prefetches page resources (including code missing due to code splitting) in the background.</li>\n<li><strong>Dynamic Components</strong>: you can import JavaScript modules and React Components dynamically (<a href=\"https://github.com/zeit/next.js#dynamic-import\">https://github.com/zeit/next.js#dynamic-import</a>).</li>\n<li><strong>Static Exports</strong>: using the <code class=\"language-text\">next export</code> command, Next.js allows you to export a fully static site from your app.</li>\n</ul>\n<h4>Installation</h4>\n<p>Next.js supports all the major platforms: Linux, macOS, Windows.</p>\n<p>A Next.js project is started easily with npm:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install next react react-dom</code></pre></div>\n<p>or with <a href=\"https://flaviocopes.com/yarn/\">Yarn</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">yarn add next react react-dom</code></pre></div>\n<h4>Getting started</h4>\n<p>Create a <code class=\"language-text\">package.json</code> file with this content:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"scripts\": {\n    \"dev\": \"next\"\n  }\n}</code></pre></div>\n<p>If you run this command now:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm run dev</code></pre></div>\n<p>the script will raise an error complaining about not finding the <code class=\"language-text\">pages</code> folder. This is the only thing that Next.js requires to run.</p>\n<p>Create an empty <code class=\"language-text\">pages</code> folder, and run the command again, and Next.js will start up a server on <code class=\"language-text\">localhost:3000</code>.</p>\n<p>If you go to that URL now, you'll be greeted by a friendly 404 page, with a nice clean design.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/wBBqzsveZC9evvtqiPb6yrFav9V5UjExd0HE\" alt=\"wBBqzsveZC9evvtqiPb6yrFav9V5UjExd0HE\"></p>\n<p>Next.js handles other error types as well, like 500 errors for example.</p>\n<h4>Create a page</h4>\n<p>In the <code class=\"language-text\">pages</code> folder create an <code class=\"language-text\">index.js</code> file with a simple React functional component:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export default () => (\n  &lt;div>\n    &lt;p>Hello World!&lt;/p>\n  &lt;/div>\n)</code></pre></div>\n<p>If you visit <code class=\"language-text\">localhost:3000</code>, this component will automatically be rendered.</p>\n<p>Why is this so simple?</p>\n<p>Next.js uses a declarative pages structure, which is based on the filesystem structure.</p>\n<p>Simply put, pages are inside a <code class=\"language-text\">pages</code> folder, and the page URL is determined by the page file name. The filesystem is the pages API.</p>\n<h4>Server-side rendering</h4>\n<p>Open the page source, <code class=\"language-text\">View -> Developer -> View</code> Source with Chrome.</p>\n<p>As you can see, the HTML generated by the component is sent directly in the page source. It's not rendered client-side, but instead it's rendered on the server.</p>\n<p>The Next.js team wanted to create a developer experience for server rendered pages similar to the one you get when creating a basic PHP project, where you simply drop PHP files and you call them, and they show up as pages. Internally of course it's all very different, but the apparent ease of use is clear.</p>\n<h4>Add a second page</h4>\n<p>Let's create another page, in <code class=\"language-text\">pages/contact.js</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export default () => (\n  &lt;div>\n    &lt;p>\n      &lt;a href=\"mailto:my@email.com\">Contact us!&lt;/a>\n    &lt;/p>\n  &lt;/div>\n)</code></pre></div>\n<p>If you point your browser to <code class=\"language-text\">localhost:3000/contact</code> this page will be rendered. As you can see, also this page is server rendered.</p>\n<h4>Hot reloading</h4>\n<p>Note how you did not have to restart the <code class=\"language-text\">npm</code> process to load the second page. Next.js does this for you under the hood.</p>\n<h4>Client rendering</h4>\n<p>Server rendering is very convenient in your first page load, for all the reasons we saw above, but when it comes to navigating inside the website, client-side rendering is key to speeding up the page load and improving the user experience.</p>\n<p>Next.js provides a <code class=\"language-text\">Link</code> component you can use to build links. Try linking the two pages above.</p>\n<p>Change <code class=\"language-text\">index.js</code> to this code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import Link from 'next/link'\n\nexport default () => (\n  &lt;div>\n    &lt;p>Hello World!&lt;/p>\n    &lt;Link href=\"/contact\">\n      &lt;a>Contact me!&lt;/a>\n    &lt;/Link>\n  &lt;/div>\n)</code></pre></div>\n<p>Now go back to the browser and try this link. As you can see, the Contact page loads immediately, without a page refresh.</p>\n<p>This is client-side navigation working correctly, with complete support for the <a href=\"https://flaviocopes.com/history-api/\"><strong>History API</strong></a>, which means your users back button won't break.</p>\n<p>If you now <code class=\"language-text\">cmd-click</code> the link, the same Contact page will open in a new tab, now server rendered.</p>\n<h4>Dynamic pages</h4>\n<p>A good use case for Next.js is a blog, as it's something that all developers know how it works, and it's a good fit for a simple example of how to handle dynamic pages.</p>\n<p>A dynamic page is a page that has no fixed content, but instead display some data based on some parameters.</p>\n<p>Change <code class=\"language-text\">index.js</code> to</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import Link from 'next/link'\n\nconst Post = props => (\n  &lt;li>\n    &lt;Link href={`/post?title=${props.title}`}>\n      &lt;a>{props.title}&lt;/a>\n    &lt;/Link>\n  &lt;/li>\n)\n\nexport default () => (\n  &lt;div>\n    &lt;h2>My blog&lt;/h2>\n    &lt;ul>\n      &lt;li>\n        &lt;Post title=\"Yet another post\" />\n        &lt;Post title=\"Second post\" />\n        &lt;Post title=\"Hello, world!\" />\n      &lt;/li>\n    &lt;/ul>\n  &lt;/div>\n)</code></pre></div>\n<p>This will create a series of posts and will fill the title query parameter with the post title:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/nEBXVSebNz6KzUWgNg62w-clo2vL7tnLIYpl\" alt=\"nEBXVSebNz6KzUWgNg62w-clo2vL7tnLIYpl\"></p>\n<p>Now create a <code class=\"language-text\">post.js</code> file in the <code class=\"language-text\">pages</code> folder, and add:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export default props => &lt;h1>{props.url.query.title}&lt;/h1></code></pre></div>\n<p>Now clicking a single post will render the post title in a <code class=\"language-text\">h1</code> tag:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/urgIpOydqbjE4i9nyELblMonOjrK0Plrn3OJ\" alt=\"urgIpOydqbjE4i9nyELblMonOjrK0Plrn3OJ\"></p>\n<p>You can use clean URLs without query parameters. The Next.js Link component helps us by accepting an <code class=\"language-text\">as</code> attribute, which you can use to pass a slug:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import Link from 'next/link'\n\nconst Post = props => (\n  &lt;li>\n    &lt;Link as={`/${props.slug}`} href={`/post?title=${props.title}`}>\n      &lt;a>{props.title}&lt;/a>\n    &lt;/Link>\n  &lt;/li>\n)\n\nexport default () => (\n  &lt;div>\n    &lt;h2>My blog&lt;/h2>\n    &lt;ul>\n      &lt;li>\n        &lt;Post slug=\"yet-another-post\" title=\"Yet another post\" />\n        &lt;Post slug=\"second-post\" title=\"Second post\" />\n        &lt;Post slug=\"hello-world\" title=\"Hello, world!\" />\n      &lt;/li>\n    &lt;/ul>\n  &lt;/div>\n)</code></pre></div>\n<h4>CSS-in-JS</h4>\n<p>Next.js by default provides support for <a href=\"https://github.com/zeit/styled-jsx\">styled-jsx</a>, which is a CSS-in-JS solution provided by the same development team, but you can use whatever library you prefer, like Styled Components.</p>\n<p>Example:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export default () => (\n  &lt;div>\n    &lt;p>\n      &lt;a href=\"mailto:my@email.com\">Contact us!&lt;/a>\n    &lt;/p>\n    &lt;style jsx>{`\n      p {\n        font-family: 'Courier New';\n      }\n      a {\n        text-decoration: none;\n        color: black;\n      }\n      a:hover {\n        opacity: 0.8;\n      }\n    `}&lt;/style>\n  &lt;/div>\n)</code></pre></div>\n<p>Styles are scoped to the component, but you can also edit global styles adding <code class=\"language-text\">global</code> to the <code class=\"language-text\">style</code> element:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export default () => (\n  &lt;div>\n    &lt;p>\n      &lt;a href=\"mailto:my@email.com\">Contact us!&lt;/a>\n    &lt;/p>\n    &lt;style jsx global>{`\n      body {\n        font-family: 'Benton Sans', 'Helvetica Neue';\n        margin: 2em;\n      }\n      h2 {\n        font-style: italic;\n        color: #373fff;\n      }\n    `}&lt;/style>\n  &lt;/div>\n)</code></pre></div>\n<h4>Exporting a static site</h4>\n<p>A Next.js application can be easily exported as a static site, which can be deployed on one of the super fast static site hosts, like <a href=\"https://flaviocopes.com/netlify/\">Netlify</a> or <a href=\"https://flaviocopes.com/firebase-hosting/\">Firebase Hosting</a>, without the need to set up a Node environment.</p>\n<p>The process requires you to declare the URLs that compose the site, but it's <a href=\"https://github.com/zeit/next.js/#static-html-export\">a straightforward process</a>.</p>\n<h4>Deploying</h4>\n<p>Creating a production-ready copy of the application, without source maps or other development tooling that aren't needed in the final build, is easy.</p>\n<p>At the beginning of this tutorial you created a <code class=\"language-text\">package.json</code> file with this content:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"scripts\": {\n    \"dev\": \"next\"\n  }\n}</code></pre></div>\n<p>which was the way to start up a development server using <code class=\"language-text\">npm run dev</code>.</p>\n<p>Now just add the following content to <code class=\"language-text\">package.json</code> instead:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{\n  \"scripts\": {\n    \"dev\": \"next\",\n    \"build\": \"next build\",\n    \"start\": \"next start\"\n  }\n}</code></pre></div>\n<p>and prepare your app by running <code class=\"language-text\">npm run build</code> and <code class=\"language-text\">npm run start</code>.</p>\n<h4>Now</h4>\n<p>The company behind Next.js provides an awesome hosting service for Node.js applications, called <a href=\"https://zeit.co/now\"><strong>Now</strong></a>.</p>\n<p>Of course they integrate both their products so you can deploy Next.js apps seamlessly, <a href=\"https://zeit.co/download\">once you have Now installed</a>, by running the <code class=\"language-text\">now</code> command in the application folder.</p>\n<p>Behind the scenes Now sets up a server for you, and you don't need to worry about anything, just wait for your application URL to be ready.</p>\n<h4>Zones</h4>\n<p>You can set up multiple Next.js instances to listen to different URLs, yet the application to an outside user will simply look like it's being powered by a single server: <a href=\"https://github.com/zeit/next.js/#multi-zones\">https://github.com/zeit/next.js/#multi-zones</a></p>\n<h4>Plugins</h4>\n<p>Next.js has a list of plugins at <a href=\"https://github.com/zeit/next-plugins\">https://github.com/zeit/next-plugins</a></p>\n<h4>Starter kit on Glitch</h4>\n<p>If you're looking to experiment, I recommend Glitch. Check out my <a href=\"https://glitch.com/edit/#!/flavio-starter-nextjs\">Next.js Glitch Starter Kit</a>.</p>\n<h3>Gatsby</h3>\n<p>Gatsby is a platform for building apps and websites using React.</p>\n<p>It is one of the tools that allow you to build on a set of technologies and practices collectively known as <a href=\"https://flaviocopes.com/jamstack/\">JAMstack</a>.</p>\n<p>Gatsby is one of the cool kids in the Frontend Development space right now. Why? I think the reasons are:</p>\n<ul>\n<li>the explosion of the JAMstack approach to building Web Apps and Web Sites</li>\n<li>the rapid adoption of the <a href=\"https://flaviocopes.com/progressive-web-apps/\">Progressive Web Apps</a> technology in the industry, which is one of the key features of Gatsby</li>\n<li>it's built in React and <a href=\"https://flaviocopes.com/graphql/\">GraphQL</a>, which are two very popular and rising technologies</li>\n<li>it's really powerful</li>\n<li>it's fast</li>\n<li>the documentation is great</li>\n<li>the network effect (people use it, create sites, make tutorials, people know more about it, creating a cycle)</li>\n<li>everything is JavaScript (no need to learn a new templating language)</li>\n<li>it hides the complexity, in the beginning, but allows us access into every step to customize</li>\n</ul>\n<p>All those are great points, and Gatsby is definitely worth a look.</p>\n<h4>How does it work?</h4>\n<p>With Gatsby, your applications are built using React components.</p>\n<p>The content you'll render in a site is generally written using Markdown, but you can use any kind of data source, like a headless CMS or a web service like Contentful.</p>\n<p>Gatsby builds the site, and it's compiled to static HTML which can be deployed on any Web Server you want, like Netlify, AWS S3, GitHub Pages, regular hosting providers, PAAS and more. All you need is a place that serves plain HTTP pages and your assets to the client.</p>\n<p>I mentioned Progressive Web Apps in the list. Gatsby automatically generates your site as a PWA, with a service worker that speeds up page loading and resource caching.</p>\n<p>You can enhance the functionality of Gatsby via plugins.</p>\n<h4>Installation</h4>\n<p>You can install Gatsby by simply running this in your terminal:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install -g gatsby-cli</code></pre></div>\n<p>This installs the <code class=\"language-text\">gatsby</code> CLI utility.</p>\n<p>(when a new version is out, update it by calling this command again)</p>\n<p>You create a new \"Hello World\" site by running</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">gatsby new mysite https://github.com/gatsbyjs/gatsby-starter-hello-world</code></pre></div>\n<p>This command creates a brand new Gatsby site in the <code class=\"language-text\">mysite</code> folder, using the <em>starter</em> available at <a href=\"https://github.com/gatsbyjs/gatsby-starter-hello-world\">https://github.com/gatsbyjs/gatsby-starter-hello-world</a>.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/rNWB5DuHCS526rLjNuhwMdYAErq4TTAJFqg5\" alt=\"rNWB5DuHCS526rLjNuhwMdYAErq4TTAJFqg5\"></p>\n<p>A <em>starter</em> is a sample site that you can build upon. Another common starter is <code class=\"language-text\">default</code>, available at <a href=\"https://github.com/gatsbyjs/gatsby-starter-default\">https://github.com/gatsbyjs/gatsby-starter-default</a>.</p>\n<blockquote>\n<p><a href=\"https://www.gatsbyjs.org/docs/gatsby-starters/\"><em>Here you can find a list of all the starters you can use</em></a><em>.</em></p>\n</blockquote>\n<h4>Running the Gatsby site</h4>\n<p>After the terminal has finished installing the starter, you can run the website by calling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">cd mysite\ngatsby develop</code></pre></div>\n<p>which will start up a new Web Server and serve the site on port 8000 on localhost.</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/tThFtYg35ax6YBnuLS9z4y92JYUhdxJZaBaj\" alt=\"tThFtYg35ax6YBnuLS9z4y92JYUhdxJZaBaj\"></p>\n<p>And here is our Hello World starter in action:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/i-aQLpALPcniL3pkUylOWeoqYCKvnzDHX8Sx\" alt=\"i-aQLpALPcniL3pkUylOWeoqYCKvnzDHX8Sx\"></p>\n<h3>Inspecting the site</h3>\n<p>If you open the site you created with your favorite code editor (I use <a href=\"https://flaviocopes.com/vscode/\">VS Code</a>), you'll find there are 3 folders:</p>\n<ul>\n<li><code class=\"language-text\">.cache</code>, a hidden folder that contains the Gatsby internals, nothing you should change right now</li>\n<li><code class=\"language-text\">public</code>, which contains the resulting website once you build it</li>\n<li><code class=\"language-text\">src</code> contains the React components, in this case just the <code class=\"language-text\">index</code> component</li>\n<li><code class=\"language-text\">static</code> which will contain the static resources like CSS and images</li>\n</ul>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/x5XH1s5uMEQdUfnZB6BM2-T9HXkDwv1xLhPd\" alt=\"x5XH1s5uMEQdUfnZB6BM2-T9HXkDwv1xLhPd\"></p>\n<p>Now, making a simple change to the default page is easy, just open <code class=\"language-text\">src/pages/index.js</code> and change \"Hello world!\" to something else, and save. The browser should instantly <strong>hot reload</strong> the component (which means the page does not actually refresh, but the content changes - a trick made possible by the underlying technology).</p>\n<p>To add a second page, just create another .js file in this folder, with the same content of <code class=\"language-text\">index.js</code> (tweak the content) and save it.</p>\n<p>For example I created a <code class=\"language-text\">second.js</code> file with this content:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import React from 'react'\n\nexport default () => &lt;div>Second page!&lt;/div></code></pre></div>\n<p>and I opened the browser to <a href=\"http://localhost:8000/second\">http://localhost:8000/second</a>:</p>\n<p><img src=\"https://cdn-media-1.freecodecamp.org/images/g4uWZNxitB4AAVbqOFmCKKPugS7yrxKYH-ld\" alt=\"g4uWZNxitB4AAVbqOFmCKKPugS7yrxKYH-ld\"></p>\n<h4>Linking pages</h4>\n<p>You can link those pages by importing a Gatsby-provided React component called <code class=\"language-text\">Link</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { Link } from \"gatsby\"</code></pre></div>\n<p>and using it in your component <a href=\"https://flaviocopes.com/jsx/\">JSX</a>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Link to=\"/second/\">Second&amp;lt;/Link></code></pre></div>\n<h4>Adding CSS</h4>\n<p>You can import any CSS file using a JavaScript import:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import './index.css'</code></pre></div>\n<p>You can use React styling:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;p style={{\n    margin: '0 auto',\n    padding: '20px'\n  }}>Hello world&lt;/p></code></pre></div>\n<h4>Using plugins</h4>\n<p>Gatsby provides lots of things out of the box, but many other functionalities are provided by <a href=\"https://www.gatsbyjs.org/plugins/\">plugins</a>.</p>\n<p>There are 3 kind of plugins:</p>\n<ul>\n<li><strong>source plugins</strong> fetch data from a source. Create nodes that can be then filtered by transformer plugins</li>\n<li><strong>transformer plugins</strong> transform the data provided by source plugins into something Gatsby can use</li>\n<li><strong>functional plugins</strong> implement some kind of functionality, like adding sitemap support or more</li>\n</ul>\n<p>Some commonly used plugins are:</p>\n<ul>\n<li><a href=\"https://www.gatsbyjs.org/packages/gatsby-plugin-react-helmet/\">gatsby-plugin-react-helmet</a> which allows to edit the <code class=\"language-text\">head</code> tag content</li>\n<li><a href=\"https://www.gatsbyjs.org/packages/gatsby-plugin-catch-links/\">gatsby-plugin-catch-links</a> which uses the <a href=\"https://flaviocopes.com/history-api/\">History API</a> to prevent the browser reloading the page when a link is clicked, loading the new content using AJAX instead</li>\n</ul>\n<p>A Gatsby plugin is installed in 2 steps. First you install it using <code class=\"language-text\">npm</code>, then you add it to the Gatsby configuration in <code class=\"language-text\">gatsby-config.js</code>.</p>\n<p>For example you can install the Catch Links plugin:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install gatsby-plugin-catch-links</code></pre></div>\n<p>In <code class=\"language-text\">gatsby-config.js</code> (create it if you don't have it, in the website root folder), add the plugin to the <code class=\"language-text\">plugins</code> exported array:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">module.exports = {\n  plugins: ['gatsby-plugin-catch-links']\n}</code></pre></div>\n<p>That's it, the plugin will now do its job.</p>\n<h4>Building the static website</h4>\n<p>Once you are done tweaking the site and you want to generate the production static site, you will call</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">gatsby build</code></pre></div>\n<p>At this point you can check that it all works as you expect by starting a local Web Server using</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">gatsby serve</code></pre></div>\n<p>which will render the site as close as possible to how you will see it in production.</p>\n<h4>Deployment</h4>\n<p>Once you build the site using <code class=\"language-text\">gatsby build</code>, all you need to do is to deploy the result contained in the <code class=\"language-text\">public</code> folder.</p>\n<p>Depending on the solution you choose, you'll need different steps here, but generally you'll push to a Git repository and let the Git post-commit hooks do the job of deploying. <a href=\"https://www.gatsbyjs.org/docs/deploying-and-hosting/\">Here are some great guides for some popular hosting platforms</a> where you can deploy Gatsby.</p>"},{"url":"/docs/ds-algo/ds-algo-interview/","relativePath":"docs/ds-algo/ds-algo-interview.md","relativeDir":"docs/ds-algo","base":"ds-algo-interview.md","name":"ds-algo-interview","frontmatter":{"title":"Data Structures Interview","weight":0,"excerpt":"Asymptotic Notation is the hardware independent notation used to tell the time and space complexity of an algorithm. Meaning it's a standardized way of measuring how much memory an algorithm uses or how long it runs for given an input.","seo":{"title":"Data Structures Interview","description":"In Javascript","robots":[],"extra":[]},"template":"docs"},"html":"<h1><a id=\"asymptotic-notation\"></h1>\n<p></a>Asymptotic Notation</p>\n<h3><span style=\"color:red;\"> Definition:</h3>\n<p>Asymptotic Notation is the hardware independent notation used to tell the time and space complexity of an algorithm. Meaning it's a standardized way of measuring how much memory an algorithm uses or how long it runs for given an input.</p>\n<h3><span style=\"color:red;\"> Complexities</h3>\n<p>The following are the Asymptotic rates of growth from best to worst:</p>\n<ul>\n<li>constant growth - <code class=\"language-text\">O(1)</code> Runtime is constant and does not grow with <code class=\"language-text\">n</code></li>\n<li>logarithmic growth - <code class=\"language-text\">O(log n)</code> Runtime grows logarithmically in proportion to <code class=\"language-text\">n</code></li>\n<li>linear growth - <code class=\"language-text\">O(n)</code> Runtime grows directly in proportion to <code class=\"language-text\">n</code></li>\n<li>superlinear growth - <code class=\"language-text\">O(n log n)</code> Runtime grows in proportion <em>and</em> logarithmically to <code class=\"language-text\">n</code></li>\n<li>polynomial growth - <code class=\"language-text\">O(n^c)</code> Runtime grows quicker than previous all based on <code class=\"language-text\">n</code></li>\n<li>exponential growth - <code class=\"language-text\">O(c^n)</code> Runtime grows even faster than polynomial growth based on <code class=\"language-text\">n</code></li>\n<li>factorial growth - <code class=\"language-text\">O(n!)</code> Runtime grows the fastest and becomes quickly unusable for even\nsmall values of <code class=\"language-text\">n</code>\n<a href=\"https://www.geeksforgeeks.org/analysis-algorithms-big-o-analysis/\">(source: Soumyadeep Debnath, <em>Analysis of Algorithms | Big-O analysis</em>)</a>\nVisualized below; the x-axis representing input size and the y-axis representing complexity:\n<img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/7/7e/Comparison_computational_complexity.svg/400px-Comparison_computational_complexity.svg.png\" alt=\"#\">\n<a href=\"https://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations\">(source: Wikipedia, <em>Computational Complexity of Mathematical Operations</em>)</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Big-O notation</h3>\n<p>Big-O refers to the upper bound of time or space complexity of an algorithm, meaning it worst case runtime scenario. An easy way to think of it is that runtime could be better than Big-O but it will never be worse.</p>\n<h3><span style=\"color:red;\"> Big-Ω (Big-Omega) notation</h3>\n<p>Big-Omega refers to the lower bound of time or space complexity of an algorithm, meaning it is the best runtime scenario. Or runtime could worse than Big-Omega, but it will never be better.</p>\n<h3><span style=\"color:red;\"> Big-θ (Big-Theta) notation</h3>\n<p>Big-Theta refers to the tight bound of time or space complexity of an algorithm. Another way to think of it is the intersection of Big-O and Big-Omega, or more simply runtime is guaranteed to be a given complexity, such as <code class=\"language-text\">n log n</code>.</p>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Big-O and Big-Theta are the most common and helpful notations</li>\n<li>Big-O does <em>not</em> mean Worst Case Scenario, Big-Theta does <em>not</em> mean average case, and Big-Omega does <em>not</em> mean Best Case Scenario. They only connote the algorithm's performance for a particular scenario, and all three can be used for any scenario.</li>\n<li>Worst Case means given an unideal input, Average Case means given a typical input, Best case means a ideal input. Ex. Worst case means given an input the algorithm performs particularly bad, or best case an already sorted array for a sorting algorithm.</li>\n<li>Best Case and Big Omega are generally not helpful since Best Cases are rare in the real world and lower bound might be very different than an upper bound.</li>\n<li>Big-O isn't everything. On paper merge sort is faster than quick sort, but in practice quick sort is superior.</li>\n</ul>\n<h1><a id=\"data-structures\"></h1>\n<p></a>Data Structures</p>\n<h3><span style=\"color:red;\"> <a id=\"array\"></h3>\n<p></a> Array</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>Stores data elements based on an sequential, most commonly 0 based, index.</li>\n<li>Based on <a href=\"http://en.wikipedia.org/wiki/Tuple\">tuples</a> from set theory.</li>\n<li>They are one of the oldest, most commonly used data structures.</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Optimal for indexing; bad at searching, inserting, and deleting (except at the end).</li>\n<li><strong>Linear arrays</strong>, or one dimensional arrays, are the most basic.</li>\n<li>\n<ul>\n<li>Are static in size, meaning that they are declared with a fixed size.</li>\n</ul>\n</li>\n<li>\n<p><strong>Dynamic arrays</strong> are like one dimensional arrays, but have reserved space for additional elements.</p>\n<ul>\n<li>If a dynamic array is full, it copies its contents to a larger array.</li>\n</ul>\n</li>\n<li><strong>Multi dimensional arrays</strong> nested arrays that allow for multiple dimensions such as an array of arrays providing a 2 dimensional spacial representation via x, y coordinates.</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Indexing: Linear array: <code class=\"language-text\">O(1)</code>, Dynamic array: <code class=\"language-text\">O(1)</code></li>\n<li>Search: Linear array: <code class=\"language-text\">O(n)</code>, Dynamic array: <code class=\"language-text\">O(n)</code></li>\n<li>Optimized Search: Linear array: <code class=\"language-text\">O(log n)</code>, Dynamic array: <code class=\"language-text\">O(log n)</code></li>\n<li>Insertion: Linear array: n/a, Dynamic array: <code class=\"language-text\">O(n)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> <a id=\"linked-list\"></h3>\n<p></a> Linked List</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>Stores data with <strong>nodes</strong> that point to other nodes.</p>\n<ul>\n<li>Nodes, at its most basic it has one datum and one reference (another node).</li>\n<li>A linked list <em>chains</em> nodes together by pointing one node's reference towards another node.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Designed to optimize insertion and deletion, slow at indexing and searching.</li>\n<li><strong>Doubly linked list</strong> has nodes that also reference the previous node.</li>\n<li><strong>Circularly linked list</strong> is simple linked list whose <strong>tail</strong>, the last node, references the <strong>head</strong>, the first node.</li>\n<li>\n<p><strong>Stack</strong>, commonly implemented with linked lists but can be made from arrays too.</p>\n<ul>\n<li>Stacks are <strong>last in, first out</strong> (LIFO) data structures.</li>\n<li>Made with a linked list by having the head be the only place for insertion and removal.</li>\n</ul>\n</li>\n<li>\n<p><strong>Queues</strong>, too can be implemented with a linked list or an array.</p>\n<ul>\n<li>Queues are a <strong>first in, first out</strong> (FIFO) data structure.</li>\n<li>Made with a doubly linked list that only removes from head and adds to tail.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Indexing: Linked Lists: <code class=\"language-text\">O(n)</code></li>\n<li>Search: Linked Lists: <code class=\"language-text\">O(n)</code></li>\n<li>Optimized Search: Linked Lists: <code class=\"language-text\">O(n)</code></li>\n<li>Append: Linked Lists: <code class=\"language-text\">O(1)</code></li>\n<li>Prepend: Linked Lists: <code class=\"language-text\">O(1)</code></li>\n<li>Insertion: Linked Lists: <code class=\"language-text\">O(n)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> <a id=\"hash\"></h3>\n<p></a> Hash Table or Hash Map</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>Stores data with key value pairs.</li>\n<li>\n<p><strong>Hash functions</strong> accept a key and return an output unique only to that specific key.</p>\n<ul>\n<li>This is known as <strong>hashing</strong>, which is the concept that an input and an output have a one-to-one correspondence to map information.</li>\n<li>Hash functions return a unique address in memory for that data.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Designed to optimize searching, insertion, and deletion.</li>\n<li>\n<p><strong>Hash collisions</strong> are when a hash function returns the same output for two distinct inputs.</p>\n<ul>\n<li>All hash functions have this problem.</li>\n<li>This is often accommodated for by having the hash tables be very large.</li>\n</ul>\n</li>\n<li>Hashes are important for associative arrays and database indexing.</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Indexing: Hash Tables: <code class=\"language-text\">O(1)</code></li>\n<li>Search: Hash Tables: <code class=\"language-text\">O(1)</code></li>\n<li>Insertion: Hash Tables: <code class=\"language-text\">O(1)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> <a id=\"binary-tree\"></h3>\n<p></a> Binary Tree</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>Is a tree like data structure where every node has at most two children.</p>\n<ul>\n<li>There is one left and right child node.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Designed to optimize searching and sorting.</li>\n<li>A <strong>degenerate tree</strong> is an unbalanced tree, which if entirely one-sided, is essentially a linked list.</li>\n<li>They are comparably simple to implement than other data structures.</li>\n<li>\n<p>Used to make <strong>binary search trees</strong>.</p>\n<ul>\n<li>A binary tree that uses comparable keys to assign which direction a child is.</li>\n<li>Left child has a key smaller than its parent node.</li>\n<li>Right child has a key greater than its parent node.</li>\n<li>There can be no duplicate node.</li>\n<li>Because of the above it is more likely to be used as a data structure than a binary tree.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Indexing: Binary Search Tree: <code class=\"language-text\">O(log n)</code></li>\n<li>Search: Binary Search Tree: <code class=\"language-text\">O(log n)</code></li>\n<li>Insertion: Binary Search Tree: <code class=\"language-text\">O(log n)</code></li>\n</ul>\n<h1><a id=\"algorithms\"></h1>\n<p></a> Algorithms</p>\n<h2><a id=\"algorithm-basics\"></h2>\n<p></a> Algorithm Basics</p>\n<h3><span style=\"color:red;\"> Recursive Algorithms</h3>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>An algorithm that calls itself in its definition.</p>\n<ul>\n<li><strong>Recursive case</strong> a conditional statement that is used to trigger the recursion.</li>\n<li><strong>Base case</strong> a conditional statement that is used to break the recursion.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>\n<p><strong>Stack level too deep</strong> and <strong>stack overflow</strong>.</p>\n<ul>\n<li>If you've seen either of these from a recursive algorithm, you messed up.</li>\n<li>It means that your base case was never triggered because it was faulty or the problem was so massive you ran out of alloted memory.</li>\n<li>Knowing whether or not you will reach a base case is integral to correctly using recursion.</li>\n<li>Often used in Depth First Search</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> Iterative Algorithms</h3>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>An algorithm that is called repeatedly but for a finite number of times, each time being a single iteration.</p>\n<ul>\n<li>Often used to move incrementally through a data set.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Generally you will see iteration as loops, for, while, and until statements.</li>\n<li>Think of iteration as moving one at a time through a set.</li>\n<li>Often used to move through an array.</li>\n</ul>\n<h3><span style=\"color:red;\"> Recursion Vs. Iteration</h3>\n<ul>\n<li>\n<p>The differences between recursion and iteration can be confusing to distinguish since both can be used to implement the other. But know that,</p>\n<ul>\n<li>Recursion is, usually, more expressive and easier to implement.</li>\n<li>Iteration uses less memory.</li>\n</ul>\n</li>\n<li><strong>Functional languages</strong> tend to use recursion. (i.e. Haskell)</li>\n<li><strong>Imperative languages</strong> tend to use iteration. (i.e. Ruby)</li>\n<li>Check out this <a href=\"http://stackoverflow.com/questions/19794739/what-is-the-difference-between-iteration-and-recursion\">Stack Overflow post</a> for more info.</li>\n</ul>\n<h3><span style=\"color:red;\"> Pseudo Code of Moving Through an Array</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">| Recursion                    | Iteration                     |\n| ---------------------------- | ----------------------------- |\n| recursive method (array, n)  | iterative method (array)      |\n| if array[n] is not nil       | for n from 0 to size of array |\n| print array[n]               | print(array[n])               |\n| recursive method(array, n+1) |\n| else                         |\n| exit loop                    |</code></pre></div>\n<h3><span style=\"color:red;\"> Greedy Algorithms</h3>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>An algorithm that, while executing, selects only the information that meets a certain criteria.</li>\n<li>\n<p>The general five components, taken from <a href=\"http://en.wikipedia.org/wiki/Greedy_algorithm#Specifics\">Wikipedia</a>:</p>\n<ul>\n<li>A candidate set, from which a solution is created.</li>\n<li>A selection function, which chooses the best candidate to be added to the solution.</li>\n<li>A feasibility function, that is used to determine if a candidate can be used to contribute to a solution.</li>\n<li>An objective function, which assigns a value to a solution, or a partial solution.</li>\n<li>A solution function, which will indicate when we have discovered a complete solution.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Used to find the expedient, though non-optimal, solution for a given problem.</li>\n<li>Generally used on sets of data where only a small proportion of the information evaluated meets the desired result.</li>\n<li>Often a greedy algorithm can help reduce the Big O of an algorithm.</li>\n</ul>\n<h3><span style=\"color:red;\"> Pseudo Code of a Greedy Algorithm to Find Largest Difference of any Two Numbers in an Array.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">greedy algorithm (array)\n  let largest difference = 0\n  let new difference = find next difference (array[n], array[n+1])\n  largest difference = new difference if new difference is > largest difference\n  repeat above two steps until all differences have been found\n  return largest difference</code></pre></div>\n<p>This algorithm never needed to compare all the differences to one another, saving it an entire iteration.</p>\n<h2><a id=\"search-algorithms\"></h2>\n<p></a>Search Algorithms</p>\n<h3><span style=\"color:red;\"> <a id=\"breadth-first-search\"></h3>\n<p></a>Breadth First Search</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>An algorithm that searches a tree (or graph) by searching levels of the tree first, starting at the root.</p>\n<ul>\n<li>It finds every node on the same level, most often moving left to right.</li>\n<li>While doing this it tracks the children nodes of the nodes on the current level.</li>\n<li>When finished examining a level it moves to the left most node on the next level.</li>\n<li>The bottom-right most node is evaluated last (the node that is deepest and is farthest right of it's level).</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Optimal for searching a tree that is wider than it is deep.</li>\n<li>\n<p>Uses a queue to store information about the tree while it traverses a tree.</p>\n<ul>\n<li>Because it uses a queue it is more memory intensive than <strong>depth first search</strong>.</li>\n<li>The queue uses more memory because it needs to stores pointers</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Search: Breadth First Search: O(V + E)</li>\n<li>E is number of edges</li>\n<li>V is number of vertices</li>\n</ul>\n<h3><span style=\"color:red;\"> <a id=\"depth-first-search\"></h3>\n<p></a>Depth First Search</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>An algorithm that searches a tree (or graph) by searching depth of the tree first, starting at the root.</p>\n<ul>\n<li>It traverses left down a tree until it cannot go further.</li>\n<li>Once it reaches the end of a branch it traverses back up trying the right child of nodes on that branch, and if possible left from the right children.</li>\n<li>When finished examining a branch it moves to the node right of the root then tries to go left on all it's children until it reaches the bottom.</li>\n<li>The right most node is evaluated last (the node that is right of all it's ancestors).</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Optimal for searching a tree that is deeper than it is wide.</li>\n<li>\n<p>Uses a stack to push nodes onto.</p>\n<ul>\n<li>Because a stack is LIFO it does not need to keep track of the nodes pointers and is therefore less memory intensive than breadth first search.</li>\n<li>Once it cannot go further left it begins evaluating the stack.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Search: Depth First Search: O(|E| + |V|)</li>\n<li>E is number of edges</li>\n<li>V is number of vertices</li>\n</ul>\n<h3><span style=\"color:red;\"> Breadth First Search Vs. Depth First Search</h3>\n<ul>\n<li>\n<p>The simple answer to this question is that it depends on the size and shape of the tree.</p>\n<ul>\n<li>For wide, shallow trees use Breadth First Search</li>\n<li>For deep, narrow trees use Depth First Search</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> Nuances</h3>\n<ul>\n<li>Because BFS uses queues to store information about the nodes and its children, it could use more memory than is available on your computer. (But you probably won't have to worry about this.)</li>\n<li>If using a DFS on a tree that is very deep you might go unnecessarily deep in the search. See <a href=\"http://xkcd.com/761/\">xkcd</a> for more information.</li>\n<li>Breadth First Search tends to be a looping algorithm.</li>\n<li>Depth First Search tends to be a recursive algorithm.</li>\n</ul>\n<h2><a id=\"sorting-algorithms\"></h2>\n<p></a>Sorting Algorithms</p>\n<h3><span style=\"color:red;\"> <a id=\"selection-sort\"></h3>\n<p></a>Selection Sort</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>A comparison based sorting algorithm.</p>\n<ul>\n<li>Starts with the cursor on the left, iterating left to right</li>\n<li>\n<p>Compares the left side to the right, looking for the smallest known item</p>\n<ul>\n<li>If the left is smaller than the item to the right it continues iterating</li>\n<li>If the left is bigger than the item to the right, the item on the right becomes the known smallest number</li>\n<li>Once it has checked all items, it moves the known smallest to the cursor and advances the cursor to the right and starts over</li>\n</ul>\n</li>\n<li>As the algorithm processes the data set, it builds a fully sorted left side of the data until the entire data set is sorted</li>\n</ul>\n</li>\n<li>Changes the array in place.</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Inefficient for large data sets.</li>\n<li>Very simple to implement.</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Best Case Sort: Merge Sort: <code class=\"language-text\">O(n^2)</code></li>\n<li>Average Case Sort: Merge Sort: <code class=\"language-text\">O(n^2)</code></li>\n<li>Worst Case Sort: Merge Sort: <code class=\"language-text\">O(n^2)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Space Complexity</h3>\n<ul>\n<li>Worst Case: <code class=\"language-text\">O(1)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Visualization</h3>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/9/94/Selection-Sort-Animation.gif\" alt=\"#\">\n<a href=\"https://en.wikipedia.org/wiki/Selection_sort\">(source: Wikipedia, <em>Insertion Sort</em>)</a></p>\n<h3><span style=\"color:red;\"> <a id=\"insertion-sort\"></h3>\n<p></a>Insertion Sort</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>A comparison based sorting algorithm.</p>\n<ul>\n<li>Iterates left to right comparing the current cursor to the previous item.</li>\n<li>If the cursor is smaller than the item on the left it swaps positions and the cursor compares itself again to the left hand side until it is put in its sorted position.</li>\n<li>As the algorithm processes the data set, the left side becomes increasingly sorted until it is fully sorted.</li>\n</ul>\n</li>\n<li>Changes the array in place.</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>Inefficient for large data sets, but can be faster for than other algorithms for small ones.</li>\n<li>Although it has an <code class=\"language-text\">O(n^2)</code>, in practice it slightly less since its comparison scheme only requires checking place if its smaller than its neighbor.</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Best Case: <code class=\"language-text\">O(n)</code></li>\n<li>Average Case: <code class=\"language-text\">O(n^2)</code></li>\n<li>Worst Case: <code class=\"language-text\">O(n^2)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Space Complexity</h3>\n<ul>\n<li>Worst Case: <code class=\"language-text\">O(n)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Visualization</h3>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif\" alt=\"#\">\n<a href=\"https://en.wikipedia.org/wiki/Insertion_sort\">(source: Wikipedia, <em>Insertion Sort</em>)</a></p>\n<h3><span style=\"color:red;\"> <a id=\"merge-sort\"></h3>\n<p></a>Merge Sort</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>A divide and conquer algorithm.</p>\n<ul>\n<li>Recursively divides entire array by half into subsets until the subset is one, the base case.</li>\n<li>Once the base case is reached results are returned and sorted ascending left to right.</li>\n<li>Recursive calls are returned and the sorts double in size until the entire array is sorted.</li>\n</ul>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>This is one of the fundamental sorting algorithms.</li>\n<li>Know that it divides all the data into as small possible sets then compares them.</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Worst Case: <code class=\"language-text\">O(n log n)</code></li>\n<li>Average Case: <code class=\"language-text\">O(n log n)</code></li>\n<li>Best Case: <code class=\"language-text\">O(n)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Space Complexity</h3>\n<ul>\n<li>Worst Case: <code class=\"language-text\">O(1)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Visualization</h3>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e6/Merge_sort_algorithm_diagram.svg/400px-Merge_sort_algorithm_diagram.svg.png\" alt=\"#\">\n<a href=\"https://en.wikipedia.org/wiki/Merge_sort\">(source: Wikipedia, <em>Merge Sort</em>)</a></p>\n<h3><span style=\"color:red;\"> <a id=\"quick-sort\"></h3>\n<p></a>Quicksort</p>\n<h3><span style=\"color:red;\"> Definition</h3>\n<ul>\n<li>\n<p>A divide and conquer algorithm</p>\n<ul>\n<li>Partitions entire data set in half by selecting a random pivot element and putting all smaller elements to the left of the element and larger ones to the right.</li>\n<li>It repeats this process on the left side until it is comparing only two elements at which point the left side is sorted.</li>\n<li>When the left side is finished sorting it performs the same operation on the right side.</li>\n</ul>\n</li>\n<li>Computer architecture favors the quicksort process.</li>\n<li>Changes the array in place.</li>\n</ul>\n<h3><span style=\"color:red;\"> What you need to know</h3>\n<ul>\n<li>While it has the same Big O as (or worse in some cases) many other sorting algorithms it is often faster in practice than many other sorting algorithms, such as merge sort.</li>\n</ul>\n<h3><span style=\"color:red;\"> Time Complexity</h3>\n<ul>\n<li>Worst Case: <code class=\"language-text\">O(n^2)</code></li>\n<li>Average Case: <code class=\"language-text\">O(n log n)</code></li>\n<li>Best Case: <code class=\"language-text\">O(n log n)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Space Complexity</h3>\n<ul>\n<li>Worst Case: <code class=\"language-text\">O(log n)</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Visualization</h3>\n<p><img src=\"https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif\" alt=\"#\">\n<a href=\"https://en.wikipedia.org/wiki/Quicksort\">(source: Wikipedia, <em>Quicksort</em>)</a></p>\n<h3><span style=\"color:red;\"> Merge Sort Vs. Quicksort</h3>\n<ul>\n<li>Quicksort is likely faster in practice, but merge sort is faster on paper.</li>\n<li>Merge Sort divides the set into the smallest possible groups immediately then reconstructs the incrementally as it sorts the groupings.</li>\n<li>Quicksort continually partitions the data set by a pivot, until the set is recursively sorted.</li>\n</ul>\n<h2><a id=\"additional-resources\"></h2>\n<p></a>Additional Resources</p>\n<p><a href=\"https://www.khanacademy.org/computing/computer-science/algorithms\">Khan Academy's Algorithm Course</a></p>\n<h3><span style=\"color:red;\"> What is ARIA and when should you use it?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>ARIA stands for \"Accessible Rich Internet Applications\", and is a technical specification created by the World Wide Web Consortium (W3C). Better known as WAI-ARIA, it provides additional HTML attributes in the development of web applications to offer people who use assistive technologies (AT) a more robust and interoperable experience with dynamic components. By providing the component's role, name, and state, AT users can better understand how to interact with the component. WAI-ARIA should only be used when an HTML element equivalent is not available or lacks full browser or AT support. WAI-ARIA's semantic markup coupled with JavaScript works to provide an understandable and interactive experience for people who use AT.\nAn example using ARIA:</p>\n<div\n      role=\"combobox\"\n      aria-expanded=\"false\"\n      aria-owns=\"ex1-grid\"\n      aria-haspopup=\"grid\"\n      id=\"ex1-combobox\">\n...\n</div>\nCredit: W3C's [ARIA 1.1 Combobox with Grid Popup Example](https://w3c.github.io/aria-practices/examples/combobox/aria1.1pattern/grid-combo.html)\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Accessible Rich Internet Applications</li>\n<li>Benefits people who use assistive technologies (AT)</li>\n<li>Provides role, name, and state</li>\n<li>Semantic HTML coupled with JavaScript</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.w3.org/WAI/standards-guidelines/aria/\">WAI-ARIA Overview</a></li>\n<li><a href=\"https://www.w3.org/TR/wai-aria/\">WAI-ARIA Spec</a></li>\n<li><a href=\"https://youtu.be/4bH57rWPnYo\">ARIA Serious? Eric Eggert presentation</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the minimum recommended ratio of contrast between foreground text and background to comply with WCAG? Why does this matter?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>4.5:1 is the calculated contrast ratio between foreground text and background that is recommended by the Web Content Accessibiity Guidelines (WCAG) success criteria (SC) 1.4.3: Contrast (Minimum). This SC was written by the World Wide Web Consortium (W3C) to ensure that people with low vision or color deficiencies are able to read (perceive) important content on a web page. It goes beyond color choices to ensure text stands out on the background it's placed on.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>At least 4.5:1 contrast ratio between foreground text and background</li>\n<li>Benefits people with low vision or color deficiencies</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.alaskawebdev.com/contact\">Understanding SC 1.4.3</a></li>\n<li><a href=\"https://webaim.org/resources/contrastchecker/\">WebAIM Contrast Checker</a></li>\n<li><a href=\"https://contrast-ratio.com/#\">Contrast Ratio checker</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are some of the tools available to test the accessibility of a website or web application?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>There are multiple tools that can help you to find for accessibility issues in your website or application.\nCheck for issues in your website:</p>\n<ul>\n<li>Lighthouse from Google, it provides an option for accessibility testing, it will check for the compliance of different accessibility standards and give you an score with details on the different issues</li>\n<li>Axe Coconut from DequeLabs, it is a Chrome extension that adds a tab in the Developer tools, it will check for accessibility issues and it will classify them by severity and suggest possible solutions\nCheck for issues in your code: * Jest Axe, you can add unit tests for accessibility * React Axe, test your React application with the axe-core accessibility testing library. Results will show in the Chrome DevTools console. * eslint-plugin-jsx-a11y, pairing this plugin with an editor lint plugin, you can bake accessibility standards into your application in real-time.\nCheck for individual issues: * Color Contrast checkers * Use a screen reader * Use only keyboard to navigate your site</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>None of the tools will replace manual testing</li>\n<li>Mention of different ways to test accessibility</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://github.com/nickcolley/jest-axe\">Jest Axe</a></li>\n<li><a href=\"https://www.w3.org/TR/wai-aria/\">eslint-plugin-jsx-a11y</a></li>\n<li><a href=\"https://github.com/dequelabs/react-axe\">React axe</a></li>\n<li><a href=\"http://romeo.elsevier.com/accessibility_checklist/\">Accessibility Checklist</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the Accessibility Tree?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The Accessibility Tree is a structure produced by the browser's Accessibility APIs which provides accessibility information to assistive technologies such as screen readers. It runs parallel to the DOM and is similar to the DOM API, but with much fewer nodes, because a lot of that information is only useful for visual presentation. By writing semantic HTML we can take advantage of this process in creating an accessible experience for our users.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Tree structure exposing information to assistive technologies</li>\n<li>Runs parallel to the DOM</li>\n<li>Semantic HTML is essential in creating accessible experiences</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.smashingmagazine.com/2015/03/web-accessibility-with-accessibility-api/\">Accessibility APIs</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the purpose of the <code class=\"language-text\">alt</code> attribute on images?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The <code class=\"language-text\">alt</code> attribute provides alternative information for an image if a user cannot view it. The <code class=\"language-text\">alt</code> attribute should be used to describe any images except those which only serve a decorative purpose, in which case it should be left empty.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Decorative images should have an empty <code class=\"language-text\">alt</code> attribute.</li>\n<li>Web crawlers use <code class=\"language-text\">alt</code> tags to understand image content, so they are considered important for Search Engine Optimization (SEO).</li>\n<li>Put the <code class=\"language-text\">.</code> at the end of <code class=\"language-text\">alt</code> tag to improve accessibility.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Learn/Accessibility/HTML\">A good basis for accessibility</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are <code class=\"language-text\">defer</code> and <code class=\"language-text\">async</code> attributes on a <code class=\"language-text\">&lt;script></code> tag?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>If neither attribute is present, the script is downloaded and executed synchronously, and will halt parsing of the document until it has finished executing (default behavior). Scripts are downloaded and executed in the order they are encountered.\nThe <code class=\"language-text\">defer</code> attribute downloads the script while the document is still parsing but waits until the document has finished parsing before executing it, equivalent to executing inside a <code class=\"language-text\">DOMContentLoaded</code> event listener. <code class=\"language-text\">defer</code> scripts will execute in order.\nThe <code class=\"language-text\">async</code> attribute downloads the script during parsing the document but will pause the parser to execute the script before it has fully finished parsing. <code class=\"language-text\">async</code> scripts will not necessarily execute in order.\nNote: both attributes must only be used if the script has a <code class=\"language-text\">src</code> attribute (i.e. not an inline script).</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script src=\"myscript.js\">\n&lt;/script>\n&lt;script src=\"myscript.js\" defer>\n&lt;/script>\n&lt;script src=\"myscript.js\" async>\n&lt;/script></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Placing a <code class=\"language-text\">defer</code> script in the <code class=\"language-text\">&lt;head></code> allows the browser to download the script while the page is still parsing, and is therefore a better option than placing the script before the end of the body.</li>\n<li>If the scripts rely on each other, use <code class=\"language-text\">defer</code>.</li>\n<li>If the script is independent, use <code class=\"language-text\">async</code>.</li>\n<li>Use <code class=\"language-text\">defer</code> if the DOM must be ready and the contents are not placed within a <code class=\"language-text\">DOMContentLoaded</code> listener.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html\">async vs defer attributes</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is an <code class=\"language-text\">async</code> function?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token operator\">...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>An <code class=\"language-text\">async</code> function is a function that allows you to pause the function's execution while it waits for (<code class=\"language-text\">await</code>s) a promise to resolve. It's an abstraction on top of the Promise API that makes asynchronous operations <em>look</em> like they're synchronous.\n<code class=\"language-text\">async</code> functions automatically return a Promise object. Whatever you <code class=\"language-text\">return</code> from the <code class=\"language-text\">async</code> function will be the promise's <em>resolution</em>. If instead you <code class=\"language-text\">throw</code> from the body of an <code class=\"language-text\">async</code> function, that will be how your async function <em>rejects</em> the promise it returns.\nMost importantly, <code class=\"language-text\">async</code> functions are able to use the <code class=\"language-text\">await</code> keyword in their function body, which <strong>pauses the function</strong> until the operation after the <code class=\"language-text\">await</code> completes, and allows it to return that operation's result to a variable synchronously.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Normal promises in regular function:</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">promiseCall</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// do something with the result</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// async functions</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">promiseCall</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// do something with the result</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li><code class=\"language-text\">async</code> functions are just syntactic sugar on top of Promises.</li>\n<li>They make asynchronous operations look like synchronous operations in your function.</li>\n<li>They implicitly return a promise which resolves to whatever your <code class=\"language-text\">async</code> function returns, and reject to whatever your <code class=\"language-text\">async</code> function <code class=\"language-text\">throw</code>s.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function\">MDN Docs - async function</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await\">MDN Docs - await</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Create a function <code class=\"language-text\">batches</code> that returns the maximum number of whole batches that can be cooked from a recipe.</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\nIt accepts two objects as arguments: the first object is the recipe\nfor the food, while the second object is the available ingredients.\nEach ingredient's value is a number representing how many units there are.\n`batches(recipe, available)`\n*/</span>\n<span class=\"token comment\">// 0 batches can be made</span>\n<span class=\"token function\">batches</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">flour</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">132</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">48</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">flour</span><span class=\"token operator\">:</span> <span class=\"token number\">51</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">batches</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">flour</span><span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">sugar</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">1288</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">flour</span><span class=\"token operator\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">sugar</span><span class=\"token operator\">:</span> <span class=\"token number\">95</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 1 batch can be made</span>\n<span class=\"token function\">batches</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cheese</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">198</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">52</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cheese</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// 2 batches can be made</span>\n<span class=\"token function\">batches</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">sugar</span><span class=\"token operator\">:</span> <span class=\"token number\">40</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">sugar</span><span class=\"token operator\">:</span> <span class=\"token number\">120</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">500</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>We must have all ingredients of the recipe available, and in quantities that are more than or equal to the number of units required. If just one of the ingredients is not available or lower than needed, we cannot make a single batch.\nUse <code class=\"language-text\">Object.keys()</code> to return the ingredients of the recipe as an array, then use <code class=\"language-text\">Array.prototype.map()</code> to map each ingredient to the ratio of available units to the amount required by the recipe. If one of the ingredients required by the recipe is not available at all, the ratio will evaluate to <code class=\"language-text\">NaN</code>, so the logical OR operator can be used to fallback to <code class=\"language-text\">0</code> in this case.\nUse the spread <code class=\"language-text\">...</code> operator to feed the array of all the ingredient ratios into <code class=\"language-text\">Math.min()</code> to determine the lowest ratio. Passing this entire result into <code class=\"language-text\">Math.floor()</code> rounds down to return the maximum number of whole batches.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">batches</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">recipe<span class=\"token punctuation\">,</span> available</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>recipe<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">k</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> available<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span> <span class=\"token operator\">/</span> recipe<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> What is CSS BEM?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The BEM methodology is a naming convention for CSS classes in order to keep CSS more maintainable by defining namespaces to solve scoping issues. BEM stands for Block Element Modifier which is an explanation for its structure. A Block is a standalone component that is reusable across projects and acts as a \"namespace\" for sub components (Elements). Modifiers are used as flags when a Block or Element is in a certain state or is different in structure or style.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">/* block component */\n.block {\n}\n/* element */\n.block__element {\n}\n/* modifier */\n.block__element--modifier {\n}</code></pre></div>\n<p>Here is an example with the class names on markup:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;nav class=\"navbar\">\n  &lt;a href=\"/\" class=\"navbar__link navbar__link--active\">\n&lt;/a>\n  &lt;a href=\"/\" class=\"navbar__link\">\n&lt;/a>\n  &lt;a href=\"/\" class=\"navbar__link\">\n&lt;/a>\n&lt;/nav></code></pre></div>\n<p>In this case, <code class=\"language-text\">navbar</code> is the Block, <code class=\"language-text\">navbar__link</code> is an Element that makes no sense outside of the <code class=\"language-text\">navbar</code> component, and <code class=\"language-text\">navbar__link--active</code> is a Modifier that indicates a different state for the <code class=\"language-text\">navbar__link</code> Element.\nSince Modifiers are verbose, many opt to use <code class=\"language-text\">is-*</code> flags instead as modifiers.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;a href=\"/\" class=\"navbar__link is-active\">\n&lt;/a></code></pre></div>\n<p>These must be chained to the Element and never alone however, or there will be scope issues.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.navbar__link.is-active {\n}</code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Alternative solutions to scope issues like CSS-in-JS</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://hackernoon.com/writing-clean-and-maintainable-css-using-bem-methodology-1dcbf810a664\">Writing clean and maintainable CSS</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is Big O Notation?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Big O notation is used in Computer Science to describe the time complexity of an algorithm. The best algorithms will execute the fastest and have the simplest complexity.\nAlgorithms don't always perform the same and may vary based on the data they are supplied. While in some cases they will execute quickly, in other cases they will execute slowly, even with the same number of elements to deal with.\nIn these examples, the base time is 1 element = <code class=\"language-text\">1ms</code>.</p>\n<h3><span style=\"color:red;\"> O(1)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\narr<span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1000 elements = <code class=\"language-text\">1ms</code>\nConstant time complexity. No matter how many elements the array has, it will theoretically take (excluding real-world variation) the same amount of time to execute.</li>\n</ul>\n<h3><span style=\"color:red;\"> O(N)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1000 elements = <code class=\"language-text\">1000ms</code>\nLinear time complexity. The execution time will increase linearly with the number of elements the array has. If the array has 1000 elements and the function takes 1ms to execute, 7000 elements will take 7ms to execute. This is because the function must iterate through all elements of the array before returning a result.</li>\n</ul>\n<h3><span style=\"color:red;\"> O([1, N])</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">some</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1000 elements = <code class=\"language-text\">1ms &lt;= x &lt;= 1000ms</code>\nThe execution time varies depending on the data supplied to the function, it may return very early or very late. The best case here is O(1) and the worst case is O(N).</li>\n</ul>\n<h3><span style=\"color:red;\"> O(NlogN)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1000 elements ~= <code class=\"language-text\">10000ms</code>\nBrowsers usually implement the quicksort algorithm for the <code class=\"language-text\">sort()</code> method and the average time complexity of quicksort is O(NlgN). This is very efficient for large collections.</li>\n</ul>\n<h3><span style=\"color:red;\"> O(N^2)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>1000 elements = <code class=\"language-text\">1000000ms</code>\nThe execution time rises quadratically with the number of elements. Usually the result of nesting loops.</li>\n</ul>\n<h3><span style=\"color:red;\"> O(N!)</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">permutations</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">2</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> arr<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">acc<span class=\"token punctuation\">,</span> item<span class=\"token punctuation\">,</span> i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> acc<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token function\">permutations</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">val</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">[</span>item<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>val<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1000 elements = <code class=\"language-text\">Infinity</code> (practically) ms\nThe execution time rises extremely fast with even just 1 addition to the array.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Be wary of nesting loops as execution time increases exponentially.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://medium.com/cesars-tech-insights/big-o-notation-javascript-25c79f50b19b\">Big O Notation in JavaScript</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Create a standalone function <code class=\"language-text\">bind</code> that is functionally equivalent to the method <code class=\"language-text\">Function.prototype.bind</code>.</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">example</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> boundExample <span class=\"token operator\">=</span> <span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>example<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">boundExample</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// logs { a: true }</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Return a function that accepts an arbitrary number of arguments by gathering them with the rest <code class=\"language-text\">...</code> operator. From that function, return the result of calling the <code class=\"language-text\">fn</code> with <code class=\"language-text\">Function.prototype.apply</code> to apply the context and the array of arguments to the function.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">bind</span> <span class=\"token operator\">=</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">fn<span class=\"token punctuation\">,</span> context</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>args</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n        <span class=\"token function\">fn</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>context<span class=\"token punctuation\">,</span> args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> What is the purpose of cache busting and how can you achieve it?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Browsers have a cache to temporarily store files on websites so they don't need to be re-downloaded again when switching between pages or reloading the same page. The server is set up to send headers that tell the browser to store the file for a given amount of time. This greatly increases website speed and preserves bandwidth.\nHowever, it can cause problems when the website has been changed by developers because the user's cache still references old files. This can either leave them with old functionality or break a website if the cached CSS and JavaScript files are referencing elements that no longer exist, have moved or have been renamed.\nCache busting is the process of forcing the browser to download the new files. This is done by naming the file something different to the old file.\nA common technique to force the browser to re-download the file is to append a query string to the end of the file.</p>\n<ul>\n<li><code class=\"language-text\">src=\"js/script.js\"</code> => <code class=\"language-text\">src=\"js/script.js?v=2\"</code>\nThe browser considers it a different file but prevents the need to change the file name.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://css-tricks.com/strategies-for-cache-busting-css/\">Strategies for cache-busting CSS</a></li>\n</ul>\n<h3><span style=\"color:red;\"> How can you avoid callback hells?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">getData</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">d</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token comment\">// ...</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Refactoring the functions to return promises and using <code class=\"language-text\">async/await</code> is usually the best option. Instead of supplying the functions with callbacks that cause deep nesting, they return a promise that can be <code class=\"language-text\">await</code>ed and will be resolved once the data has arrived, allowing the next line of code to be evaluated in a sync-like fashion.\nThe above code can be restructured like so:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">asyncAwaitVersion</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> a <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> b <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> c <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> d <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> e <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>There are lots of ways to solve the issue of callback hells:</p>\n<ul>\n<li>Modularization: break callbacks into independent functions</li>\n<li>Use a control flow library, like async</li>\n<li>Use generators with Promises</li>\n<li>Use async/await (from v7 on)</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>As an efficient JavaScript developer, you have to avoid the constantly growing indentation level, produce clean and readable code and be able to handle complex flows.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"http://stackabuse.com/avoiding-callback-hell-in-node-js/\">Avoiding Callback Hell in Node.js</a></li>\n<li><a href=\"https://blog.hellojs.org/asynchronous-javascript-from-callback-hell-to-async-and-await-9b9ceb63c8e8\">Asynchronous JavaScript: From Callback Hell to Async and Await</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the purpose of callback function as an argument of <code class=\"language-text\">setState</code>?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The callback function is invoked when <code class=\"language-text\">setState</code> has finished and the component gets rendered. Since <code class=\"language-text\">setState</code> is asynchronous, the callback function is used for any post action.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'sudheer'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The name has updated and component re-rendered'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>The callback function is invoked after <code class=\"language-text\">setState</code> finishes and is used for any post action.</li>\n<li>It is recommended to use lifecycle method rather this callback function.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/react-component.html#setstate\">React docs on <code class=\"language-text\">setState</code></a></li>\n</ul>\n<h3><span style=\"color:red;\"> Which is the preferred option between callback refs and findDOMNode()?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Callback refs are preferred over the <code class=\"language-text\">findDOMNode()</code> API, due to the fact that <code class=\"language-text\">findDOMNode()</code> prevents certain improvements in React in the future.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Legacy approach using findDOMNode()</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MyComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">findDOMNode</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">scrollIntoView</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// Recommended approach using callback refs</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MyComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span><span class=\"token function\">scrollIntoView</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div ref<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">node</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>node <span class=\"token operator\">=</span> node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Callback refs are preferred over <code class=\"language-text\">findDOMNode()</code>.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/refs-and-the-dom.html#exposing-dom-refs-to-parent-components\">React docs on Refs and the DOM</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a callback? Can you show an example using one?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Callbacks are functions passed as an argument to another function to be executed once an event has occurred or a certain task is complete, often used in asynchronous code. Callback functions are invoked later by a piece of code but can be declared on initialization without being invoked.\nAs an example, event listeners are asynchronous callbacks that are only executed when a specific event occurs.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">onClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The user clicked on the page.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> onClick<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>However, callbacks can also be synchronous. The following <code class=\"language-text\">map</code> function takes a callback function that is invoked synchronously for each iteration of the loop (array element).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">map</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// [2, 4, 6, 8, 10]</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Functions are first-class objects in JavaScript</li>\n<li>Callbacks vs Promises</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Callback_function\">MDN docs for callbacks</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the <code class=\"language-text\">children</code> prop?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p><code class=\"language-text\">children</code> is part of the props object passed to components that allows components to be passed as data to other components, providing the ability to compose components cleanly. There are a number of methods available in the React API to work with this prop, such as <code class=\"language-text\">React.Children.map</code>, <code class=\"language-text\">React.Children.forEach</code>, <code class=\"language-text\">React.Children.count</code>, <code class=\"language-text\">React.Children.only</code> and <code class=\"language-text\">React.Children.toArray</code>. A simple usage example of the children prop is as follows:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">GenericBox</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> children <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"container\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>GenericBox<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>span<span class=\"token operator\">></span>Hello<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>span<span class=\"token operator\">></span>World<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>GenericBox<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Children is a prop that allows components to be passed as data to other components.</li>\n<li>The React API provides methods to work with this prop.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/jsx-in-depth.html#children-in-jsx\">React docs on Children</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Why does React use <code class=\"language-text\">className</code> instead of <code class=\"language-text\">class</code> like in HTML?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>React's philosophy in the beginning was to align with the browser DOM API rather than HTML, since that more closely represents how elements are created. Setting a <code class=\"language-text\">class</code> on an element meant using the <code class=\"language-text\">className</code> API:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nelement<span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Additionally, before ES5, reserved words could not be used in objects:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">attributes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">class</span><span class=\"token operator\">:</span> <span class=\"token string\">'hello'</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In IE8, this will throw an error.\nIn modern environments, destructuring will throw an error if trying to assign to a variable:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">class</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props <span class=\"token comment\">// Error</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> className <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props <span class=\"token comment\">// All good</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">class</span><span class=\"token operator\">:</span> className <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props <span class=\"token comment\">// All good, but</span>\n        cumbersome<span class=\"token operator\">!</span></code></pre></div>\n<p>However, <code class=\"language-text\">class</code> <em>can</em> be used as a prop without problems, as seen in other libraries like Preact. React currently allows you to use <code class=\"language-text\">class</code>, but will throw a warning and convert it to <code class=\"language-text\">className</code> under the hood. There is currently an open thread (as of January 2019) discussing changing <code class=\"language-text\">className</code> to <code class=\"language-text\">class</code> to reduce confusion.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> How do you clone an object in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Using the object spread operator <code class=\"language-text\">...</code>, the object's own enumerable properties can be copied into the new object. This creates a shallow clone of the object.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> shallowClone <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>obj <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>With this technique, prototypes are ignored. In addition, nested objects are not cloned, but rather their references get copied, so nested objects still refer to the same objects as the original. Deep-cloning is much more complex in order to effectively clone any type of object (Date, RegExp, Function, Set, etc) that may be nested within the object.\nOther alternatives include:</p>\n<ul>\n<li><code class=\"language-text\">JSON.parse(JSON.stringify(obj))</code> can be used to deep-clone a simple object, but it is CPU-intensive and only accepts valid JSON (therefore it strips functions and does not allow circular references).</li>\n<li><code class=\"language-text\">Object.assign({}, obj)</code> is another alternative.</li>\n<li><code class=\"language-text\">Object.keys(obj).reduce((acc, key) => (acc[key] = obj[key], acc), {})</code> is another more verbose alternative that shows the concept in greater depth.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>JavaScript passes objects by reference, meaning that nested objects get their references copied, instead of their values.</li>\n<li>The same method can be used to merge two objects.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign\">MDN docs for Object.assign()</a></li>\n<li><a href=\"http://voidcanvas.com/clone-an-object-in-vanilla-js-in-depth/\">Clone an object in vanilla JS</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a closure? Can you give a useful example of one?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>A closure is a function defined inside another function and has access to its lexical scope even when it is executing outside its lexical scope. The closure has access to variables in three scopes:</p>\n<ul>\n<li>Variables declared in its own scope</li>\n<li>Variables declared in the scope of the parent function</li>\n<li>Variables declared in the global scope\nIn JavaScript, all functions are closures because they have access to the outer scope, but most functions don't utilise the usefulness of closures: the persistence of state. Closures are also sometimes called stateful functions because of this.\nIn addition, closures are the only way to store private data that can't be accessed from the outside in JavaScript. They are the key to the UMD (Universal Module Definition) pattern, which is frequently used in libraries that only expose a public API but keep the implementation details private, preventing name collisions with other libraries or the user's own code.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Closures are useful because they let you associate data with a function that operates on that data.</li>\n<li>A closure can substitute an object with only a single method.</li>\n<li>Closures can be used to emulate private properties and methods.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures\">MDN docs for closures</a></li>\n<li><a href=\"https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-closure-b2f0d2152b36\">What is a closure</a></li>\n<li><a href=\"https://medium.com/dailyjs/i-never-understood-javascript-closures-9663703368e8\">I never understood JavaScript closures</a></li>\n</ul>\n<h3><span style=\"color:red;\"> How do you compare two objects in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Even though two different objects can have the same properties with equal values, they are not considered equal when compared using <code class=\"language-text\">==</code> or <code class=\"language-text\">===</code>. This is because they are being compared by their reference (location in memory), unlike primitive values which are compared by value.\nIn order to test if two objects are equal in structure, a helper function is required. It will iterate through the own properties of each object to test if they have the same values, including nested objects. Optionally, the prototypes of the objects may also be tested for equivalence by passing <code class=\"language-text\">true</code> as the 3rd argument.\nNote: this technique does not attempt to test equivalence of data structures other than plain objects, arrays, functions, dates and primitive values.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">isDeepEqual</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">obj1<span class=\"token punctuation\">,</span> obj2<span class=\"token punctuation\">,</span> testPrototypes <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>obj1 <span class=\"token operator\">===</span> obj2<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> obj1 <span class=\"token operator\">===</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> obj2 <span class=\"token operator\">===</span> <span class=\"token string\">'function'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> obj1<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> obj2<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>obj1 <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Date</span> <span class=\"token operator\">&amp;&amp;</span> obj2 <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> obj1<span class=\"token punctuation\">.</span><span class=\"token function\">getTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> obj2<span class=\"token punctuation\">.</span><span class=\"token function\">getTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>obj1<span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token keyword\">typeof</span> obj1 <span class=\"token operator\">!==</span> <span class=\"token string\">'object'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">const</span> prototypesAreEqual <span class=\"token operator\">=</span> testPrototypes <span class=\"token operator\">?</span> <span class=\"token function\">isDeepEqual</span><span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">getPrototypeOf</span><span class=\"token punctuation\">(</span>obj1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">getPrototypeOf</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> obj1Props <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertyNames</span><span class=\"token punctuation\">(</span>obj1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> obj2Props <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertyNames</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> obj1Props<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> obj2Props<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> prototypesAreEqual <span class=\"token operator\">&amp;&amp;</span> obj1Props<span class=\"token punctuation\">.</span><span class=\"token function\">every</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">prop</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">isDeepEqual</span><span class=\"token punctuation\">(</span>obj1<span class=\"token punctuation\">[</span>prop<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> obj2<span class=\"token punctuation\">[</span>prop<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Primitives like strings and numbers are compared by their value</li>\n<li>Objects on the other hand are compared by their reference (location in memory)</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"http://adripofjavascript.com/blog/drips/object-equality-in-javascript.html\">Object Equality in JavaScript</a></li>\n<li><a href=\"https://30secondsofcode.org/object#equals\">Deep comparison between two values</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is context?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Context provides a way to pass data through the component tree without having to pass props down manually at every level. For example, authenticated user, locale preference, UI theme need to be accessed in the application by many components.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> Provider<span class=\"token punctuation\">,</span> Consumer <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createContext</span><span class=\"token punctuation\">(</span>defaultValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Context provides a way to pass data through a tree of React components, without having to manually pass props.</li>\n<li>Context is designed to share data that is considered <em>global</em> for a tree of React components.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/context.html\">React docs on Context</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is CORS?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Cross-Origin Resource Sharing or CORS is a mechanism that uses additional HTTP headers to grant a browser permission to access resources from a server at an origin different from the website origin.\nAn example of a cross-origin request is a web application served from <code class=\"language-text\">http://mydomain.com</code> that uses AJAX to make a request for <code class=\"language-text\">http://yourdomain.com</code>.\nFor security reasons, browsers restrict cross-origin HTTP requests initiated by JavaScript. <code class=\"language-text\">XMLHttpRequest</code> and <code class=\"language-text\">fetch</code> follow the same-origin policy, meaning a web application using those APIs can only request HTTP resources from the same origin the application was accessed, unless the response from the other origin includes the correct CORS headers.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>CORS behavior is not an error,  it's a security mechanism to protect users.</li>\n<li>CORS is designed to prevent a malicious website that a user may unintentionally visit from making a request to a legitimate website to read their personal data or perform actions against their will.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS\">MDN docs for CORS</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Describe the layout of the CSS Box Model and briefly describe each component.</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p><code class=\"language-text\">Content</code>: The inner-most part of the box filled with content, such as text, an image, or video player. It has the dimensions <code class=\"language-text\">content-box width</code> and <code class=\"language-text\">content-box height</code>.\n<code class=\"language-text\">Padding</code>: The transparent area surrounding the content. It has dimensions <code class=\"language-text\">padding-box width</code> and <code class=\"language-text\">padding-box height</code>.\n<code class=\"language-text\">Border</code>: The area surrounding the padding (if any) and content. It has dimensions <code class=\"language-text\">border-box width</code> and <code class=\"language-text\">border-box height</code>.\n<em>Margin</em>: The transparent outer-most layer that surrounds the border. It separates the element from other elements in the DOM. It has dimensions <code class=\"language-text\">margin-box width</code> and <code class=\"language-text\">margin-box height</code>.\n<img src=\"https://www.washington.edu/accesscomputing/webd2/student/unit3/images/boxmodel.gif\" alt=\"alt text\">\nalt text</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>This is a very common question asked during front-end interviews and while it may seem easy, it is critical you know it well!</li>\n<li>Shows a solid understanding of spacing and the DOM</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.w3schools.com/Css/css_boxmodel.asp\">W3School's CSS Box Model Page</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model\">Mozilla's Intro to the CSS Box Model</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are the advantages of using CSS preprocessors?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>CSS preprocessors add useful functionality that native CSS does not have, and generally make CSS neater and more maintainable by enabling DRY (Don't Repeat Yourself) principles. Their terse syntax for nested selectors cuts down on repeated code. They provide variables for consistent theming (however, CSS variables have largely replaced this functionality) and additional tools like color functions (<code class=\"language-text\">lighten</code>, <code class=\"language-text\">darken</code>, <code class=\"language-text\">transparentize</code>, etc), mixins, and loops that make CSS more like a real programming language and gives the developer more power to generate complex CSS.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>They allow us to write more maintainable and scalable CSS</li>\n<li>Some disadvantages of using CSS preprocessors (setup, re-compilation time can be slow etc.)</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://medium.com/@garyfagan/css-preprocessors-6f226fa16f27\">CSS Preprocessors</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between '+' and '~' sibling selectors?.</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The General Sibling Selector <code class=\"language-text\">~</code> selects all elements that are siblings of a specified element.\nThe following example selects all <code class=\"language-text\">&lt;p></code> elements that are siblings of <code class=\"language-text\">&lt;div></code> elements:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">div ~ p {\n  background-color: blue;\n}</code></pre></div>\n<p>The Adjacent Sibling Selector <code class=\"language-text\">+</code> selects all elements that are the adjacent siblings of a specified element.\nThe following example will select all <code class=\"language-text\">&lt;p></code> elements that are placed immediately after <code class=\"language-text\">&lt;div></code> elements:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">div + p {\n  background-color: red;\n}</code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.w3schools.com/css/css_combinators.asp\">W3School's CSS Combinators Page</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Combinators_and_multiple_selectors\">Mozilla's Combinators and groups of selectors page</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Can you describe how CSS specificity works?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Assuming the browser has already determined the set of rules for an element, each rule is assigned a matrix of values, which correspond to the following from highest to lowest specificity:</p>\n<ul>\n<li>Inline rules (binary - 1 or 0)</li>\n<li>Number of id selectors</li>\n<li>Number of class, pseudo-class and attribute selectors</li>\n<li>Number of tags and pseudo-element selectors\nWhen two selectors are compared, the comparison is made on a per-column basis (e.g. an id selector will always be higher than any amount of class selectors, as ids have higher specificity than classes). In cases of equal specificity between multiple rules, the rules that comes last in the page's style sheet is deemed more specific and therefore applied to the element.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Specificity matrix: [inline, id, class/pseudo-class/attribute, tag/pseudo-element]</li>\n<li>In cases of equal specificity, last rule is applied</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.smashingmagazine.com/2007/07/css-specificity-things-you-should-know/\">CSS Specificity</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is debouncing?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Debouncing is a process to add some delay before executing a function. It is commonly used with DOM event listeners to improve the performance of page. It is a technique which allow us to \"group\" multiple sequential calls in a single one. A raw DOM event listeners can easily trigger 20+ events per second. A debounced function will only be called once the delay has passed.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">debounce</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">func<span class=\"token punctuation\">,</span> delay</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> debounceTimer<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> context <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> args <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">;</span>\n        <span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>debounceTimer<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        debounceTimer <span class=\"token operator\">=</span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">func</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>context<span class=\"token punctuation\">,</span> args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListere</span><span class=\"token punctuation\">(</span>\n    <span class=\"token string\">'scroll'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">debounce</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Do stuff, this function will be called after a delay of 1 second</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Common use case is to make API call only when user is finished typing while searching.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://css-tricks.com/debouncing-throttling-explained-examples/\">Debouncing explained</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the DOM?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The DOM (Document Object Model) is a cross-platform API that treats HTML and XML documents as a tree structure consisting of nodes. These nodes (such as elements and text nodes) are objects that can be programmatically manipulated and any visible changes made to them are reflected live in the document. In a browser, this API is available to JavaScript where DOM nodes can be manipulated to change their styles, contents, placement in the document, or interacted with through event listeners.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>The DOM was designed to be independent of any particular programming language, making the structural representation of the document available from a single, consistent API.</li>\n<li>The DOM is constructed progressively in the browser as a page loads, which is why scripts are often placed at the bottom of a page, in the <code class=\"language-text\">&lt;head></code> with a <code class=\"language-text\">defer</code> attribute, or inside a <code class=\"language-text\">DOMContentLoaded</code> event listener. Scripts that manipulate DOM nodes should be run after the DOM has been constructed to avoid errors.</li>\n<li><code class=\"language-text\">document.getElementById()</code> and <code class=\"language-text\">document.querySelector()</code> are common functions for selecting DOM nodes.</li>\n<li>Setting the <code class=\"language-text\">innerHTML</code> property to a new value runs the string through the HTML parser, offering an easy way to append dynamic HTML content to a node.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/DOM\">MDN docs for DOM</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between the equality operators <code class=\"language-text\">==</code> and <code class=\"language-text\">===</code>?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Triple equals (<code class=\"language-text\">===</code>) checks for strict equality, which means both the type and value must be the same. Double equals (<code class=\"language-text\">==</code>) on the other hand first performs type coercion so that both operands are of the same type and then applies strict comparison.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Whenever possible, use triple equals to test equality because loose equality <code class=\"language-text\">==</code> can have unintuitive results.</li>\n<li>Type coercion means the values are converted into the same type.</li>\n<li>Mention of falsy values and their comparison.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators\">MDN docs for comparison operators</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between an element and a component in React?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>An element is a plain JavaScript object that represents a DOM node or component. Elements are pure and never mutated, and are cheap to create.\nA component is a function or class. Components can have state and take props as input and return an element tree as output (although they can represent generic containers or wrappers and don't necessarily have to emit DOM). Components can initiate side effects in lifecycle methods (e.g. AJAX requests, DOM mutations, interfacing with 3rd party libraries) and may be expensive to create.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Component</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> componentElement <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>Component <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> domNodeElement <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>div <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Elements are immutable, plain objects that describe the DOM nodes or components you want to render.</li>\n<li>Components can be either classes or functions, that take props as an input and return an element tree as the output.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/rendering-elements.html\">React docs on Rendering Elements</a></li>\n<li><a href=\"https://reactjs.org/docs/components-and-props.html\">React docs on Components and Props</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between <code class=\"language-text\">em</code> and <code class=\"language-text\">rem</code> units?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Both <code class=\"language-text\">em</code> and <code class=\"language-text\">rem</code> units are based on the <code class=\"language-text\">font-size</code> CSS property. The only difference is where they inherit their values from.</p>\n<ul>\n<li><code class=\"language-text\">em</code> units inherit their value from the <code class=\"language-text\">font-size</code> of the parent element</li>\n<li><code class=\"language-text\">rem</code> units inherit their value from the <code class=\"language-text\">font-size</code> of the root element (<code class=\"language-text\">html</code>)\nIn most browsers, the <code class=\"language-text\">font-size</code> of the root element is set to <code class=\"language-text\">16px</code> by default.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Benefits of using <code class=\"language-text\">em</code> and <code class=\"language-text\">rem</code> units</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://medium.com/code-better/css-units-for-font-size-px-em-rem-79f7e592bb97\">CSS units for font-size: px | em | rem</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are error boundaries in React?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed.\nClass components become error boundaries if they define either (or both) of the lifecycle methods <code class=\"language-text\">static getDerivedStateFromError()</code> or <code class=\"language-text\">componentDidCatch().</code></p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ErrorBoundary</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">hasError</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">// Use componentDidCatch to log the error</span>\n    <span class=\"token function\">componentDidCatch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error<span class=\"token punctuation\">,</span> info</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// You can also log the error to an error reporting service</span>\n        <span class=\"token function\">logErrorToMyService</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">,</span> info<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">// use getDerivedStateFromError to update state</span>\n    <span class=\"token keyword\">static</span> <span class=\"token function\">getDerivedStateFromError</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Display fallback UI</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">hasError</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>hasError<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// You can render any custom fallback UI</span>\n            <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Something went wrong<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Error boundaries only catch errors in the components below them in the tree. An error boundary can't catch an error within itself.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<p><a href=\"https://reactjs.org/docs/error-boundaries.html\">https://reactjs.org/docs/error-boundaries.html</a></p>\n<h3><span style=\"color:red;\"> What is event delegation and why is it useful? Can you show an example of how to use it?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Event delegation is a technique of delegating events to a single common ancestor. Due to event bubbling, events \"bubble\" up the DOM tree by executing any handlers progressively on each ancestor element up to the root that may be listening to it.\nDOM events provide useful information about the element that initiated the event via <code class=\"language-text\">Event.target</code>. This allows the parent element to handle behavior as though the target element was listening to the event, rather than all children of the parent or the parent itself.\nThis provides two main benefits:</p>\n<ul>\n<li>It increases performance and reduces memory consumption by only needing to register a single event listener to handle potentially thousands of elements.</li>\n<li>If elements are dynamically added to the parent, there is no need to register new event listeners for them.\nInstead of:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">button</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    button<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> handleButtonClick<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Event delegation involves using a condition to ensure the child target matches our desired element:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">handleButtonClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>The difference between event bubbling and capturing</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://davidwalsh.name/event-delegate\">Event Delegation</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is event-driven programming?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Event-driven programming is a paradigm that involves building applications that send and receive events. When the program emits events, the program responds by running any callback functions that are registered to that event and context, passing in associated data to the function. With this pattern, events can be emitted into the wild without throwing errors even if no functions are subscribed to it.\nA common example of this is the pattern of elements listening to DOM events such as <code class=\"language-text\">click</code> and <code class=\"language-text\">mouseenter</code>, where a callback function is run when the event occurs.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// This callback function is run when the user</span>\n    <span class=\"token comment\">// clicks on the document.</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Without the context of the DOM, the pattern may look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> hub <span class=\"token operator\">=</span> <span class=\"token function\">createEventHub</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhub<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'message'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>data<span class=\"token punctuation\">.</span>username<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> said </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>data<span class=\"token punctuation\">.</span>text<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhub<span class=\"token punctuation\">.</span><span class=\"token function\">emit</span><span class=\"token punctuation\">(</span><span class=\"token string\">'message'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">username</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello?'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>With this implementation, <code class=\"language-text\">on</code> is the way to <em>subscribe</em> to an event, while <code class=\"language-text\">emit</code> is the way to <em>publish</em> the event.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Follows a publish-subscribe pattern.</li>\n<li>Responds to events that occur by running any callback functions subscribed to the event.</li>\n<li>Show how to create a simple pub-sub implementation with JavaScript.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Overview_of_Events_and_Handlers\">MDN docs on Events and Handlers</a></li>\n<li><a href=\"https://medium.freecodecamp.org/understanding-node-js-event-driven-architecture-223292fcbc2d\">Understanding Node.js event-driven architecture</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between an expression and a statement in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>There are two main syntactic categories in JavaScript: expressions and statements. A third one is both together, referred to as an expression statement. They are roughly summarized as:</p>\n<ul>\n<li><strong>Expression</strong>: produces a value</li>\n<li><strong>Statement</strong>: performs an action</li>\n<li>\n<p><strong>Expression statement</strong>: produces a value and performs an action\nA general rule of thumb:</p>\n<blockquote>\n<p>If you can print it or assign it to a variable, it's an expression. If you can't, it's a statement.</p>\n</blockquote>\n</li>\n</ul>\n<h3><span style=\"color:red;\"> Statements</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> x <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">declaration</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Statements appear as instructions that do something but don't produce values.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Assign `x` to the absolute value of `y`.</span>\n<span class=\"token keyword\">var</span> x<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    x <span class=\"token operator\">=</span> y<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    x <span class=\"token operator\">=</span> <span class=\"token operator\">-</span>y<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The only expression in the above code is <code class=\"language-text\">y >= 0</code> which produces a value, either <code class=\"language-text\">true</code> or <code class=\"language-text\">false</code>. A value is not produced by other parts of the code.</p>\n<h3><span style=\"color:red;\"> Expressions</h3>\n<p>Expressions produce a value. They can be passed around to functions because the interpreter replaces them with the value they resolve to.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => 10</span>\n<span class=\"token function\">lastCharacter</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => \"t\"</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">===</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// => true</span></code></pre></div>\n<h3><span style=\"color:red;\"> Expression statements</h3>\n<p>There is an equivalent version of the set of statements used before as an expression using the conditional operator:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Assign `x` as the absolute value of `y`.</span>\n<span class=\"token keyword\">var</span> x <span class=\"token operator\">=</span> y <span class=\"token operator\">>=</span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> y <span class=\"token operator\">:</span> <span class=\"token operator\">-</span>y<span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is both an expression and a statement, because we are declaring a variable <code class=\"language-text\">x</code> (statement) as an evaluation (expression).</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Function declarations vs function expressions</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://stackoverflow.com/questions/12703214/javascript-difference-between-a-statement-and-an-expression\">What is the difference between a statement and an expression?</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are truthy and falsy values in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>A value is either truthy or falsy depending on how it is evaluated in a Boolean context. Falsy means false-like and truthy means true-like. Essentially, they are values that are coerced to <code class=\"language-text\">true</code> or <code class=\"language-text\">false</code> when performing certain operations.\nThere are 6 falsy values in JavaScript. They are:</p>\n<ul>\n<li><code class=\"language-text\">false</code></li>\n<li><code class=\"language-text\">undefined</code></li>\n<li><code class=\"language-text\">null</code></li>\n<li><code class=\"language-text\">\"\"</code> (empty string)</li>\n<li><code class=\"language-text\">NaN</code></li>\n<li><code class=\"language-text\">0</code> (both <code class=\"language-text\">+0</code> and <code class=\"language-text\">-0</code>)\nEvery other value is considered truthy.\nA value's truthiness can be examined by passing it into the <code class=\"language-text\">Boolean</code> function.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">Boolean</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">Boolean</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n<p>There is a shortcut for this using the logical NOT <code class=\"language-text\">!</code> operator. Using <code class=\"language-text\">!</code> once will convert a value to its inverse boolean equivalent (i.e. not false is true), and <code class=\"language-text\">!</code> once more will convert back, thus effectively converting the value to a boolean.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">!</span><span class=\"token string\">''</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">!</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en/docs/Glossary/Truthy\">Truthy on MDN</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Falsy\">Falsy on MDN</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Generate an array, containing the Fibonacci sequence, up until the nth term.</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Initialize an empty array of length <code class=\"language-text\">n</code>. Use <code class=\"language-text\">Array.prototype.reduce()</code> to add values into the array, using the sum of the last two values, except for the first two.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">fibonacci</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token function\">Array</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">acc<span class=\"token punctuation\">,</span> val<span class=\"token punctuation\">,</span> i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> acc<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">?</span> acc<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> acc<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://github.com/Chalarangelo/30-seconds-of-code/blob/master/snippets_archive/fibonacciUntilNum.md\">Similar problem</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Given an array of words, write a method to output matching sets of anagrams.</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> words <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'rates'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'stare'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'taser'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tears'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'art'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tabs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tar'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'state'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> words <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'rates'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'stare'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'taser'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tears'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'art'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tabs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tar'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'state'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">anagramGroups</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">wordAry</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> groupedWords <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// iterate over each word in the array</span>\n    wordAry<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">word</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// alphabetize the word and a separate variable</span>\n        alphaWord <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// if the alphabetize word is already a key, push the actual word value (this is an anagram)</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>groupedWords<span class=\"token punctuation\">[</span>alphaWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> groupedWords<span class=\"token punctuation\">[</span>alphaWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token comment\">// otherwise add the alphabetize word key and actual word value (may not turn out to be an anagram)</span>\n        groupedWords<span class=\"token punctuation\">[</span>alphaWord<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>word<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> groupedWords<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// call the function and store results in a variable called collectedAnagrams</span>\n<span class=\"token keyword\">const</span> collectedAnagrams <span class=\"token operator\">=</span> <span class=\"token function\">anagramGroups</span><span class=\"token punctuation\">(</span>words<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// iterate over groupedAnagrams, printing out group of values</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> sortedWord <span class=\"token keyword\">in</span> collectedAnagrams<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>collectedAnagrams<span class=\"token punctuation\">[</span>sortedWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>collectedAnagrams<span class=\"token punctuation\">[</span>sortedWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Iterate the array</li>\n<li>Alphabetize each word</li>\n<li>Store alphabetize word as the key value in a groupedWords object with the original word as the value</li>\n<li>Compare alphabetize words to object keys and add additional original words when matches are found</li>\n<li>Iterate over the return object and output the values, when there is more then one. (single values mean no anagram )</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://gist.github.com/tinabme/fe6878f5cff42f60a537262503f9b765\">Find The Anagrams Gist</a></li>\n<li><a href=\"https://www.30secondsofcode.org/snippet/isAnagram\">isAnagram function implementation</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Using flexbox, create a 3-column layout where each column takes up a <code class=\"language-text\">col-{n} / 12</code> ratio of the container.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"row\">\n  &lt;div class=\"col-2\">\n&lt;/div>\n  &lt;div class=\"col-7\">\n&lt;/div>\n  &lt;div class=\"col-3\">\n&lt;/div>\n&lt;/div></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Set the <code class=\"language-text\">.row</code> parent to <code class=\"language-text\">display: flex;</code> and use the <code class=\"language-text\">flex</code> shorthand property to give the column classes a <code class=\"language-text\">flex-grow</code> value that corresponds to its ratio value.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.row {\n  display: flex;\n}\n.col-2 {\n  flex: 2;\n}\n.col-7 {\n  flex: 7;\n}\n.col-3 {\n  flex: 3;\n}</code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox\">MDN docs for basic concepts of flexbox</a></li>\n<li><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox/\">A complete guide to Flexbox</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What does <code class=\"language-text\">0.1 + 0.2 === 0.3</code> evaluate to?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>It evaluates to <code class=\"language-text\">false</code> because JavaScript uses the IEEE 754 standard for Math and it makes use of 64-bit floating numbers. This causes precision errors when doing decimal calculations, in short, due to computers working in Base 2 while decimal is Base 10.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 0.30000000000000004</span></code></pre></div>\n<p>A solution to this problem would be to use a function that determines if two numbers are approximately equal by defining an error margin (epsilon) value that the difference between two values should be less than.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">approxEqual</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n1<span class=\"token punctuation\">,</span> n2<span class=\"token punctuation\">,</span> epsilon <span class=\"token operator\">=</span> <span class=\"token number\">0.0001</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span>n1 <span class=\"token operator\">-</span> n2<span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;</span> epsilon<span class=\"token punctuation\">;</span>\n<span class=\"token function\">approxEqual</span><span class=\"token punctuation\">(</span><span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>A simple solution to this problem</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://github.com/Chalarangelo/30-seconds-of-code#approximatelyequal\">A simple helper function to check equality</a></li>\n<li><a href=\"http://blog.blakesimpson.co.uk/read/61-fix-0-1-0-2-0-300000004-in-javascript\">Fix \"0.1 + 0.2 = 0.300000004\" in JavaScript</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a focus ring? What is the correct solution to handle them?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>A focus ring is a visible outline given to focusable elements such as buttons and anchor tags. It varies depending on the vendor, but generally it appears as a blue outline around the element to indicate it is currently focused.\nIn the past, many people specified <code class=\"language-text\">outline: 0;</code> on the element to remove the focus ring. However, this causes accessibility issues for keyboard users because the focus state may not be clear. When not specified though, it causes an unappealing blue ring to appear around an element.\nIn recent times, frameworks like Bootstrap have opted to use a more appealing <code class=\"language-text\">box-shadow</code> outline to replace the default focus ring. However, this is still not ideal for mouse users.\nThe best solution is an upcoming pseudo-selector <code class=\"language-text\">:focus-visible</code> which can be polyfilled today with JavaScript. It will only show a focus ring if the user is using a keyboard and leave it hidden for mouse users. This keeps both aesthetics for mouse use and accessibility for keyboard use.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://css-tricks.com/focus-visible-and-backwards-compatibility/\">:focus-visible</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between the array methods <code class=\"language-text\">map()</code> and <code class=\"language-text\">forEach()</code>?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Both methods iterate through the elements of an array. <code class=\"language-text\">map()</code> maps each element to a new element by invoking the callback function on each element and returning a new array. On the other hand, <code class=\"language-text\">forEach()</code> invokes the callback function for each element but does not return a new array. <code class=\"language-text\">forEach()</code> is generally used when causing a side effect on each iteration, whereas <code class=\"language-text\">map()</code> is a common functional programming technique.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Use <code class=\"language-text\">forEach()</code> if you need to iterate over an array and cause mutations to the elements without needing to return values to generate a new array.</li>\n<li><code class=\"language-text\">map()</code> is the right choice to keep data immutable where each value of the original array is mapped to a new array.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach\">MDN docs for forEach</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map\">MDN docs for map</a></li>\n<li><a href=\"https://codeburst.io/javascript-map-vs-foreach-f38111822c0f\">JavaScript — Map vs. ForEach</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are fragments?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Fragments allow a React component to return multiple elements without a wrapper, by grouping the children without adding extra elements to the DOM. Fragments offer better performance, lower memory usage, a cleaner DOM and can help in dealing with certain CSS mechanisms (e.g. tables, Flexbox and Grid).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildA <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildB <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildC <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// Short syntax supported by Babel 7</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildA <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildB <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildC <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span><span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Fragments group multiple elements returned from a component, without adding a DOM element around them.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/fragments.html\">React docs on Fragments</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is functional programming?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Functional programming is a paradigm in which programs are built in a declarative manner using pure functions that avoid shared state and mutable data. Functions that always return the same value for the same input and don't produce side effects are the pillar of functional programming. Many programmers consider this to be the best approach to software development as it reduces bugs and cognitive load.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Cleaner, more concise development experience</li>\n<li>Simple function composition</li>\n<li>Features of JavaScript that enable functional programming (<code class=\"language-text\">.map</code>, <code class=\"language-text\">.reduce</code> etc.)</li>\n<li>JavaScript is multi-paradigm programming language (Object-Oriented Programming and Functional Programming live in harmony)</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://hackernoon.com/javascript-and-functional-programming-an-introduction-286aa625e26d\">Javascript and Functional Programming: An Introduction</a></li>\n<li><a href=\"https://medium.com/javascript-scene/master-the-javascript-interview-what-is-functional-programming-7f218c68b3a0\">Master the JavaScript Interview: What is Functional Programming?</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Describe your thoughts on how a single page web app should handle focus when changing routes</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Single page applications make use of client-side rendering. This means that 'examplesite.com' and 'examplesite.com/page2' are actually the same HTML web page, but the client app decides what content to drop into that single page at runtime. Your user never actually \"leaves\" the page, and this causes some accessibility issues in terms of focus.\nUnless focus is explicitly managed in the app, a scenario like this may happen:</p>\n<ol>\n<li>User visits 'examplesite.com'</li>\n<li>User clicks a link to go to another route: 'examplesite.com/product1'</li>\n<li>Client app changes the visible content to show the details for this new route (e.g. some info about Product 1)</li>\n<li>Focus is still on the link that was clicked in step 2</li>\n<li>If a user uses the keyboard or screen reader to now try and read the content, the focused starting point is in the middle of the page on an element no longer visible\nMany strategies have been proposed in handling this situation, all involving explicitly managing the focus when the new page content is rendered. <a href=\"https://www.gatsbyjs.org/blog/2019-07-11-user-testing-accessible-client-routing/\">Recent research by GatsbyJS</a> suggests the best approach is:</li>\n<li>User visits 'examplesite.com'</li>\n<li>User clicks a link to go to another route: 'examplesite.com/product1'</li>\n<li>Client app changes the visible content to show the details for this new route (e.g. some info about Product 1)</li>\n<li>Client app manually places focus on the main header at the top of the page (almost always this will be the H1 element)\nBy doing so, focus is reset to the top of the page, ready for the user to begin exploring the new content. This solution requires inserting the main heading into the start of tabbing order with <code class=\"language-text\">tabindex=\"-1\"</code>.</li>\n</ol>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Focus issues caused by client-side rendering, instead of server-side</li>\n<li>Focus should not be left on elements no longer visible on the page</li>\n<li>Challenges faced by screen reader users and users utilising keyboard navigation</li>\n<li>Careful manual focus management required</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.upyoura11y.com/handling-focus/\">Handling Focus on Route Change: Up Your A11y</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are higher-order components?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>A higher-order component (HOC) is a function that takes a component as an argument and returns a new component. It is a pattern that is derived from React's compositional nature. Higher-order components are like <strong>pure components</strong> because they accept any dynamically provided child component, but they won't modify or copy any behavior from their input components.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> EnhancedComponent <span class=\"token operator\">=</span> <span class=\"token function\">higherOrderComponent</span><span class=\"token punctuation\">(</span>WrappedComponent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>They can be used for state abstraction and manipulation, props manipulation, render high jacking, etc.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> What will the console log in this example?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> foo <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">foobar</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>foo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">var</span> foo <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">foobar</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Due to hoisting, the local variable <code class=\"language-text\">foo</code> is declared before the <code class=\"language-text\">console.log</code> method is called. This means the local variable <code class=\"language-text\">foo</code> is passed as an argument to <code class=\"language-text\">console.log()</code> instead of the global one declared outside of the function. However, since the value is not hoisted with the variable declaration, the output will be <code class=\"language-text\">undefined</code>, not <code class=\"language-text\">2</code>.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Hoisting is JavaScript's default behavior of moving declarations to the top</li>\n<li>Mention of <code class=\"language-text\">strict</code> mode</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Hoisting\">MDN docs for hoisting</a></li>\n</ul>\n<h3><span style=\"color:red;\"> How does hoisting work in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Hoisting is a JavaScript mechanism where variable and function declarations are put into memory during the compile phase. This means that no matter where functions and variables are declared, they are moved to the top of their scope regardless of whether their scope is global or local.\nHowever, the value is not hoisted with the declaration.\nThe following snippet:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>hoist<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> hoist <span class=\"token operator\">=</span> <span class=\"token string\">'value'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>is equivalent to:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> hoist<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>hoist<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nhoist <span class=\"token operator\">=</span> <span class=\"token string\">'value'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Therefore logging <code class=\"language-text\">hoist</code> outputs <code class=\"language-text\">undefined</code> to the console, not <code class=\"language-text\">\"value\"</code>.\nHoisting also allows you to invoke a function declaration before it appears to be declared in a program.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// No error; logs \"hello\"</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>But be wary of function expressions that are assigned to a variable:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Error: `myFunction` is not a function</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">myFunction</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Hoisting is JavaScript's default behavior of moving declarations to the top</li>\n<li>Functions declarations are hoisted before variable declarations</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Hoisting\">MDN docs for hoisting</a></li>\n<li><a href=\"https://scotch.io/tutorials/understanding-hoisting-in-javascript\">Understanding Hoisting in JavaScript</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Can a web page contain multiple <code class=\"language-text\">&lt;header></code> elements? What about <code class=\"language-text\">&lt;footer></code> elements?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Yes to both. The W3 documents state that the tags represent the header(<code class=\"language-text\">&lt;header></code>) and footer(<code class=\"language-text\">&lt;footer></code>) areas of their nearest ancestor \"section\". So not only can the page <code class=\"language-text\">&lt;body></code> contain a header and a footer, but so can every <code class=\"language-text\">&lt;article></code> and <code class=\"language-text\">&lt;section></code> element.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>W3 recommends having as many as you want, but only 1 of each for each \"section\" of your page, i.e. body, section etc.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://stackoverflow.com/questions/4837269/html5-using-header-or-footer-tag-twice?utm_medium=organic&#x26;utm_source=google_rich_qa&#x26;utm_campaign=google_rich_qa\">StackOverflow - Using header or footer tag twice</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Discuss the differences between an HTML specification and a browser's implementation thereof.</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>HTML specifications such as <code class=\"language-text\">HTML5</code> define a set of rules that a document must adhere to in order to be \"valid\" according to that specification. In addition, a specification provides instructions on how a browser must interpret and render such a document.\nA browser is said to \"support\" a specification if it handles valid documents according to the rules of the specification. As of yet, no browser supports all aspects of the <code class=\"language-text\">HTML5</code> specification (although all of the major browser support most of it), and as a result, it is necessary for the developer to confirm whether the aspect they are making use of will be supported by all of the browsers on which they hope to display their content. This is why cross-browser support continues to be a headache for developers, despite the improved specificiations.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li><code class=\"language-text\">HTML5</code> defines some rules to follow for an invalid <code class=\"language-text\">HTML5</code> document (i.e., one that contains syntactical errors)</li>\n<li>However, invalid documents may contain anything, so it's impossible for the specification to handle all possibilities comprehensively.</li>\n<li>Thus, many decisions about how to handle malformed documents are left up to the browser.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.w3.org/TR/html52/\">HTML 5.2 WWW Specifications</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between HTML and React event handling?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>In HTML, the attribute name is in all lowercase and is given a string invoking a function defined somewhere:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;button onclick=\"handleClick()\">\n&lt;/button></code></pre></div>\n<p>In React, the attribute name is camelCase and are passed the function reference inside curly braces:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>handleClick<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<p>In HTML, <code class=\"language-text\">false</code> can be returned to prevent default behavior, whereas in React <code class=\"language-text\">preventDefault</code> has to be called explicitly.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;a href=\"#\" onclick=\"console.log('The link was clicked.'); return false\" /></code></pre></div>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The link was clicked.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>HTML uses lowercase, React uses camelCase.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/handling-events.html\">React docs on Handling Events</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are some differences that XHTML has compared to HTML?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Some of the key differences are:</p>\n<ul>\n<li>An XHTML element must have an XHTML <code class=\"language-text\">&lt;DOCTYPE></code></li>\n<li>Attributes values must be enclosed in quotes</li>\n<li>Attribute minimization is forbidden (e.g. one has to use <code class=\"language-text\">checked=\"checked\"</code> instead of <code class=\"language-text\">checked</code>)</li>\n<li>Elements must always be properly nested</li>\n<li>Elements must always be closed</li>\n<li>Special characters must be escaped</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Any element can be self-closed</li>\n<li>Tags ands attributes are case-sensitive, usually lowercase</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.w3schools.com/html/html_xhtml.asp\">W3Schools docs for HTML and XHTML</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Briefly describe the correct usage of the following HTML5 semantic elements: <code class=\"language-text\">&lt;header></code>, <code class=\"language-text\">&lt;article></code>,<code class=\"language-text\">&lt;section></code>, <code class=\"language-text\">&lt;footer></code></h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<ul>\n<li><code class=\"language-text\">&lt;header></code> is used to contain introductory and navigational information about a section of the page. This can include the section heading, the author's name, time and date of publication, table of contents, or other navigational information.</li>\n<li><code class=\"language-text\">&lt;article></code> is meant to house a self-contained composition that can logically be independently recreated outside of the page without losing its meaning. Individual blog posts or news stories are good examples.</li>\n<li><code class=\"language-text\">&lt;section></code> is a flexible container for holding content that shares a common informational theme or purpose.</li>\n<li><code class=\"language-text\">&lt;footer></code> is used to hold information that should appear at the end of a section of content and contain additional information about the section. Author's name, copyright information, and related links are typical examples of such content.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Other semantic elements are <code class=\"language-text\">&lt;form></code> and <code class=\"language-text\">&lt;table></code></li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.w3schools.com/html/html5_semantic_elements.asp\">HTML 5 Semantic Elements</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is HTML5 Web Storage? Explain <code class=\"language-text\">localStorage</code> and <code class=\"language-text\">sessionStorage</code>.</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>With HTML5, web pages can store data locally within the user's browser. The data is stored in name/value pairs, and a web page can only access data stored by itself.\n<strong>Differences between <code class=\"language-text\">localStorage</code> and <code class=\"language-text\">sessionStorage</code> regarding lifetime:</strong></p>\n<ul>\n<li>Data stored through <code class=\"language-text\">localStorage</code> is permanent: it does not expire and remains stored on the user's computer until a web app deletes it or the user asks the browser to delete it.</li>\n<li><code class=\"language-text\">sessionStorage</code> has the same lifetime as the top-level window or browser tab in which the data got stored. When the tab is permanently closed, any data stored through <code class=\"language-text\">sessionStorage</code> is deleted.</li>\n<li><strong>Differences between <code class=\"language-text\">localStorage</code> and <code class=\"language-text\">sessionStorage</code> regarding storage scope:</strong> Both forms of storage are scoped to the document origin so</li>\n<li><code class=\"language-text\">sessionStorage</code> is also scoped on a per-window basis. Two browser tabs with documents from the same origin have separate <code class=\"language-text\">sessionStorage</code> data.</li>\n<li>Unlike in <code class=\"language-text\">localStorage</code>, the same scripts from the same origin can't access each other's <code class=\"language-text\">sessionStorage</code> when opened in different tabs.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Earlier, this was done with cookies.</li>\n<li>The storage limit is far larger (at least 5MB) than with cookies and its faster.</li>\n<li>The data is never transferred to the server and can only be used if the client specifically asks for it.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.w3schools.com/html/html5_webstorage.asp\">W3Schools - HTML5 Webstorage</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the reason for wrapping the entire contents of a JavaScript source file in a function that is immediately invoked?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>This technique is very common in JavaScript libraries. It creates a closure around the entire contents of the file which creates a private namespace and thereby helps avoid potential name clashes between different JavaScript modules and libraries. The function is immediately invoked so that the namespace (library name) is assigned the return value of the function.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> myLibrary <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> privateVariable <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function-variable function\">publicMethod</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> privateVariable\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nprivateVariable<span class=\"token punctuation\">;</span> <span class=\"token comment\">// ReferenceError</span>\nmyLibrary<span class=\"token punctuation\">.</span><span class=\"token function\">publicMethod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 2</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Used among many popular JavaScript libraries</li>\n<li>Creates a private namespace</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures\">MDN docs for closures</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Explain the differences between imperative and declarative programming.</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>These two types of programming can roughly be summarized as:</p>\n<ul>\n<li>Imperative: <strong>how</strong> to achieve something</li>\n<li>Declarative: <strong>what</strong> should be achieved\nA common example of declarative programming is CSS. The developer specifies CSS properties that describe what something should look like rather than how to achieve it. The \"how\" is abstracted away by the browser.\nOn the other hand, imperative programming involves the steps required to achieve something. In JavaScript, the differences can be contrasted like so:</li>\n</ul>\n<h3><span style=\"color:red;\"> Imperative</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> numbersDoubled <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> numbers<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    numbersDoubled<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We manually loop over the numbers of the array and assign the new index as the number doubled.</p>\n<h3><span style=\"color:red;\"> Declarative</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> numbersDoubled <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We declare that the new array is mapped to a new one where each value is doubled.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Declarative programming often works with functions and expressions. Imperative programming frequently uses statements and relies on low-level features that cause mutations, while declarative programming has a strong focus on abstraction and purity.</li>\n<li>Declarative programming is more terse and easier to process at a glance.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://codeburst.io/declarative-vs-imperative-programming-a8a7c93d9ad2\">Declarative vs Imperative Programming</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are inline conditional expressions?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Since a JSX element tree is one large expression, you cannot embed statements inside. Conditional expressions act as a replacement for statements to use inside the tree.\nFor example, this won't work:</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> messages<span class=\"token punctuation\">,</span> isVisible <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>messages<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>You have <span class=\"token punctuation\">{</span>messages<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">}</span> unread messages<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>You have no unread messages<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>isVisible<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span><span class=\"token constant\">I</span> am visible<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Logical AND <code class=\"language-text\">&amp;&amp;</code> and the ternary <code class=\"language-text\">? :</code> operator replace the <code class=\"language-text\">if</code>/<code class=\"language-text\">else</code> statements.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> messages<span class=\"token punctuation\">,</span> isVisible <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token punctuation\">{</span>messages<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>You have <span class=\"token punctuation\">{</span>messages<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">}</span> unread messages<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span> <span class=\"token operator\">:</span> <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>You have no unread messages<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">{</span>isVisible <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span><span class=\"token constant\">I</span> am visible<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/conditional-rendering.html\">React docs on Conditional Rendering</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a key? What are the benefits of using it in lists?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Keys are a special string attribute that helps React identify which items have been changed, added or removed. They are used when rendering array elements to give them a stable identity. Each element's key must be unique (e.g. IDs from the data or indexes as a last resort).</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> todoItems <span class=\"token operator\">=</span> todos<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todo</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>todo<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>todo<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Using indexes as keys is not recommended if the order of items may change, as it might negatively impact performance and may cause issues with component state.</li>\n<li>If you extract list items as a separate component then apply keys on the list component instead of the <code class=\"language-text\">&lt;li></code> tag.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Keys give elements in a collection a stable identity and help React identify changes.</li>\n<li>You should avoid using indexes as keys if the order of items may change.</li>\n<li>You should lift the key up to the component, instead of the <code class=\"language-text\">&lt;li></code> element, if you extract list items as components.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/lists-and-keys.html\">React docs on Lists and Keys</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are landmark roles and how can they be useful?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Landmark roles is a way to identify different sections of a page like the main content or a navigation region. The Landmarks helps assistive technology users to navigate a page, allowing them skip over areas of it.\nFor example,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div id=\"header\" role=\"banner\">Header of the Page&lt;/div>\n&lt;div id=\"content\" role=\"main\">Main Content Goes Here&lt;/div></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Identify sections of a page</li>\n<li>Assist users in navigating a page</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.washington.edu/accessibility/web/landmarks/\">ARIA Landmark Roles</a></li>\n<li><a href=\"https://www.w3.org/WAI/GL/wiki/Using_ARIA_landmarks_to_identify_regions_of_a_page\">Using ARIA landmarks to identify regions of a page</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between lexical scoping and dynamic scoping?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Lexical scoping refers to when the location of a function's definition determines which variables you have access to. On the other hand, dynamic scoping uses the location of the function's invocation to determine which variables are available.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Lexical scoping is also known as static scoping.</li>\n<li>Lexical scoping in JavaScript allows for the concept of closures.</li>\n<li>Most languages use lexical scoping because it tends to promote source code that is more easily understood.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures\">Mozilla Docs - Closures &#x26; Lexical Scoping</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are the lifecycle methods in React?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p><code class=\"language-text\">getDerivedStateFromProps</code>: Executed before rendering on the initial mount and all component updates. Used to update the state based on changes in props over time. Has rare use cases, like tracking component animations during the lifecycle. There are only few cases where this makes sense to use over other lifecycle methods. It expects to return an object that will be the the new state, or null to update nothing. This method does not have access to the component instance either.\n<code class=\"language-text\">componentDidMount</code>: Executed after first rendering and here all AJAX requests, DOM or state updates, and set up eventListeners should occur.\n<code class=\"language-text\">shouldComponentUpdate</code>: Determines if the component will be updated or not. By default, it returns true. If you are sure that the component doesn't need to render after state or props are updated, you can return a false value. It is a great place to improve performance as it allows you to prevent a rerender if component receives new prop.\n<code class=\"language-text\">getSnapshotBeforeUpdate</code>: Invoked right after a component render happens because of an update, before <code class=\"language-text\">componentDidUpdate</code>. Any value returned from this method will be passed to <code class=\"language-text\">componentDidUpdate</code>.\n<code class=\"language-text\">componentDidUpdate</code>: Mostly it is used to update the DOM in response to prop or state changes.\n<code class=\"language-text\">componentWillUnmount</code>: It will be used to cancel any outgoing network requests, or remove all event listeners associated with the component.\n<code class=\"language-text\">componentDidCatch</code>: Used in error boundaries, which are components that implement this method. It allows the component to catch JavaScript errors anywhere in the <em>child</em> component tree (below this component), log errors, and display a UI with error information.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> What are the different phases of the component lifecycle in React?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>There are four different phases of component's lifecycle:\n<strong>Initialization</strong>: In this phase, the component prepares setting up the initial state and default props.\n<strong>Mounting</strong>: The react component is ready to mount to the DOM. This phase covers the <code class=\"language-text\">getDerivedStateFromProps</code> and <code class=\"language-text\">componentDidMount</code> lifecycle methods.\n<strong>Updating</strong>: In this phase, the component gets updated in two ways, sending the new props and updating the state. This phase covers the <code class=\"language-text\">getDerivedStateFromProps</code>, <code class=\"language-text\">shouldComponentUpdate</code>, <code class=\"language-text\">getSnapshotBeforeUpdate</code> and <code class=\"language-text\">componentDidUpdate</code> lifecycle methods.\n<strong>Unmounting</strong>: In this last phase, the component is not needed and gets unmounted from the browser DOM. This phase includes the <code class=\"language-text\">componentWillUnmount</code> lifecycle method.\n<strong>Error Handling</strong>: In this phase, the component is called whenever there's an error during rendering, in a lifecycle method, or in the constructor for any child component. This phase includes the <code class=\"language-text\">componentDidCatch</code> lifecycle method.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> What does lifting state up in React mean?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>When several components need to share the same data, then it is recommended to lift the shared state up to their closest common ancestor. For example, if two child components share the same data, it is recommended to move the shared state to parent instead of maintaining the local state in both child components.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> Create a function that masks a string of characters with <code class=\"language-text\">#</code> except for the last four (4) characters.</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">mask</span><span class=\"token punctuation\">(</span><span class=\"token string\">'123456789'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"#####6789\"</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<blockquote>\n<p>There are many ways to solve this problem, this is just one one of them.\nUsing <code class=\"language-text\">String.prototype.slice()</code> we can grab the last 4 characters of the string by passing <code class=\"language-text\">-4</code> as an argument. Then, using <code class=\"language-text\">String.prototype.padStart()</code>, we can pad the string to the original length with the repeated mask character.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> mask <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">,</span> maskChar <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> str<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">padStart</span><span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> maskChar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Short, one-line functional solutions to problems should be preferred provided they are efficient</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> Can you name the four types of <code class=\"language-text\">@media</code> properties?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<ul>\n<li><code class=\"language-text\">all</code>, which applies to all media type devices</li>\n<li><code class=\"language-text\">print</code>, which only applies to printers</li>\n<li><code class=\"language-text\">screen</code>, which only applies to screens (desktops, tablets, mobile etc.)</li>\n<li><code class=\"language-text\">speech</code>, which only applies to screenreaders</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/@media\">MDN docs for <code class=\"language-text\">@media</code> rule</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries\">MDN docs for using media queries</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is memoization?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Memoization is the process of caching the output of function calls so that subsequent calls are faster. Calling the function again with the same input will return the cached output without needing to do the calculation again.\nA basic implementation in JavaScript looks like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">memoize</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">fn</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> cache <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> cachedResult <span class=\"token operator\">=</span> cache<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>cachedResult <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> cachedResult<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        cache<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>The above technique returns a unary function even if the function can take multiple arguments.</li>\n<li>The first function call will be slower than usual because of the overhead created by checking if a cached result exists and setting a result before returning the value.</li>\n<li>Memoization increases performance on subsequent function calls but still needs to do work on the first call.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.sitepoint.com/implementing-memoization-in-javascript/\">Implementing memoization in JavaScript</a></li>\n</ul>\n<h3><span style=\"color:red;\"> How do you ensure methods have the correct <code class=\"language-text\">this</code> context in React component classes?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>In JavaScript classes, the methods are not bound by default. This means that their <code class=\"language-text\">this</code> context can be changed (in the case of an event handler, to the element that is listening to the event) and will not refer to the component instance. To solve this, <code class=\"language-text\">Function.prototype.bind()</code> can be used to enforce the <code class=\"language-text\">this</code> context as the component instance.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Perform some logic</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>The <code class=\"language-text\">bind</code> approach can be verbose and requires defining a <code class=\"language-text\">constructor</code>, so the new public class fields syntax is generally preferred:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token function-variable function\">handleClick</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'this is:'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n      Click me\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>You can also use an inline arrow function, because lexical <code class=\"language-text\">this</code> (referring to the component instance) is preserved:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Click me<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span></code></pre></div>\n<p>Note that extra re-rendering can occur using this technique because a new function reference is created on render, which gets passed down to child components and breaks <code class=\"language-text\">shouldComponentUpdate</code> / <code class=\"language-text\">PureComponent</code> shallow equality checks to prevent unnecessary re-renders. In cases where performance is important, it is preferred to go with <code class=\"language-text\">bind</code> in the constructor, or the public class fields syntax approach, because the function reference remains constant.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>You can either bind methods to the component instance context in the constructor, use public class fields syntax, or use inline arrow functions.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/handling-events.html\">React docs on Handling Events</a></li>\n<li><a href=\"https://reactjs.org/docs/faq-functions.html#how-do-i-bind-a-function-to-a-component-instance\">React docs on Passing Functions to Components</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a MIME type and what is it used for?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p><code class=\"language-text\">MIME</code> is an acronym for <code class=\"language-text\">Multi-purpose Internet Mail Extensions</code>. It is used as a standard way of classifying file types over the Internet.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>A <code class=\"language-text\">MIME type</code> actually has two parts: a type and a subtype that are separated by a slash (/). For example, the <code class=\"language-text\">MIME type</code> for Microsoft Word files is <code class=\"language-text\">application/msword</code> (i.e., type is application and the subtype is msword).</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types\">MIME Type - MDN</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Contrast mutable and immutable values, and mutating vs non-mutating methods.</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The two terms can be contrasted as:</p>\n<ul>\n<li>Mutable: subject to change</li>\n<li>Immutable: cannot change\nIn JavaScript, objects are mutable while primitive values are immutable. This means operations performed on objects can change the original reference in some way, while operations performed on a primitive value cannot change the original value.\nAll <code class=\"language-text\">String.prototype</code> methods do not have an effect on the original string and return a new string. On the other hand, while some methods of <code class=\"language-text\">Array.prototype</code> do not mutate the original array reference and produce a fresh array, some cause mutations.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> myString <span class=\"token operator\">=</span> <span class=\"token string\">'hello!'</span><span class=\"token punctuation\">;</span>\nmyString<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token string\">'!'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a new string, cannot mutate the original value</span>\n<span class=\"token keyword\">const</span> originalArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\noriginalArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// mutates originalArray, now [1, 2, 3, 4]</span>\noriginalArray<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a new array, does not mutate the original</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>List of mutating and non-mutating array methods</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://lorenstewart.me/2017/01/22/javascript-array-methods-mutating-vs-non-mutating/\">Mutating vs non-mutating array methods</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the only value not equal to itself in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p><code class=\"language-text\">NaN</code> (Not-a-Number) is the only value not equal to itself when comparing with any of the comparison operators. <code class=\"language-text\">NaN</code> is often the result of meaningless math computations, so two <code class=\"language-text\">NaN</code> values make no sense to be considered equal.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>The difference between <code class=\"language-text\">isNaN()</code> and <code class=\"language-text\">Number.isNaN()</code></li>\n<li><code class=\"language-text\">const isNaN = x => x !== x</code></li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN\">MDN docs for <code class=\"language-text\">NaN</code></a></li>\n</ul>\n<h3><span style=\"color:red;\"> NodeJS often uses a callback pattern where if an error is encountered during execution, this error is passed as the first argument to the callback. What are the advantages of this pattern?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readFile</span><span class=\"token punctuation\">(</span>filePath<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">err<span class=\"token punctuation\">,</span> data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// handle the error, the return is important here</span>\n        <span class=\"token comment\">// so execution stops here</span>\n        <span class=\"token keyword\">return</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token comment\">// use the data object</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Advantages include:</p>\n<ul>\n<li>Not needing to process data if there is no need to even reference it</li>\n<li>Having a consistent API leads to more adoption</li>\n<li>Ability to easily adapt a callback pattern that will lead to more maintainable code\nAs you can see from below example, the callback is called with null as its first argument if there is no error. However, if there is an error, you create an Error object, which then becomes the callback's only parameter. The callback function allows a user to easily know whether or not an error occurred.\nThis practice is also called the <em>Node.js error convention</em>, and this kind of callback implementations are called <em>error-first callbacks</em>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">isTrue</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">===</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Value was true.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Value is not true!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">callback</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">error<span class=\"token punctuation\">,</span> retval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>retval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">isTrue</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">isTrue</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/*\n  { stack: [Getter/Setter],\n    arguments: undefined,\n    type: undefined,\n    message: 'Value is not true!' }\n  Value was true.\n*/</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>This is just a convention. However, you should stick to it.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"http://fredkschott.com/post/2014/03/understanding-error-first-callbacks-in-node-js/\">The Node.js Way - Understanding Error-First Callbacks</a></li>\n<li><a href=\"https://docs.nodejitsu.com/articles/errors/what-are-the-error-conventions\">What are the error conventions?</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the event loop in Node.js?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The event loop handles all async callbacks. Callbacks are queued in a loop, while other code runs, and will run one by one when the response for each one has been received.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>The event loop allows Node.js to perform non-blocking I/O operations, despite the fact that JavaScript is single-threaded</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/\">Node.js docs on event loop, timers and process.nextTick()</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between <code class=\"language-text\">null</code> and <code class=\"language-text\">undefined</code>?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>In JavaScript, two values discretely represent nothing - <code class=\"language-text\">undefined</code> and <code class=\"language-text\">null</code>. The concrete difference between them is that <code class=\"language-text\">null</code> is explicit, while <code class=\"language-text\">undefined</code> is implicit. When a property does not exist or a variable has not been given a value, the value is <code class=\"language-text\">undefined</code>. <code class=\"language-text\">null</code> is set as the value to explicitly indicate \"no value\". In essence, <code class=\"language-text\">undefined</code> is used when the nothing is not known, and <code class=\"language-text\">null</code> is used when the nothing is known.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li><code class=\"language-text\">typeof undefined</code> evaluates to <code class=\"language-text\">\"undefined\"</code>.</li>\n<li><code class=\"language-text\">typeof null</code> evaluates <code class=\"language-text\">\"object\"</code>. However, it is still a primitive value and this is considered an implementation bug in JavaScript.</li>\n<li><code class=\"language-text\">undefined == null</code> evaluates to <code class=\"language-text\">true</code>.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null\">MDN docs for null</a></li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined\">MDN docs for undefined</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Describe the different ways to create an object. When should certain ways be preferred over others?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<h3><span style=\"color:red;\"> Object literal</h3>\n<p>Often used to store one occurrence of data.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nperson<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// person.age === 51</span></code></pre></div>\n<h3><span style=\"color:red;\"> Constructor</h3>\n<p>Often used when you need to create multiple instances of an object, each with their own data that other instances of the class cannot affect. The <code class=\"language-text\">new</code> operator must be used before invoking the constructor or the global object will be mutated.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name<span class=\"token punctuation\">,</span> age</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> age<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">birthday</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> person1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> person2 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Sally'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nperson1<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// person1.age === 51</span>\nperson2<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// person2.age === 21</span></code></pre></div>\n<h3><span style=\"color:red;\"> Factory function</h3>\n<p>Creates a new object similar to a constructor, but can store private data using a closure. There is also no need to use <code class=\"language-text\">new</code> before invoking the function or the <code class=\"language-text\">this</code> keyword. Factory functions usually discard the idea of prototypes and keep all properties and methods as own properties of the object.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">createPerson</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">name<span class=\"token punctuation\">,</span> age</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">birthday</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> person<span class=\"token punctuation\">.</span>age<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> name<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">,</span> birthday <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> person<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token function\">createPerson</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">50</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nperson<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// person.age === 51</span></code></pre></div>\n<h3><span style=\"color:red;\"> <code class=\"language-text\">Object.create()</code></h3>\n<p>Sets the prototype of the newly created object.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> personProto <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>personProto<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nperson<span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">50</span><span class=\"token punctuation\">;</span>\nperson<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// person.age === 51</span></code></pre></div>\n<p>A second argument can also be supplied to <code class=\"language-text\">Object.create()</code> which acts as a descriptor for the new properties to be defined.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>personProto<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">writable</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">enumerable</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Prototypes are objects that other objects inherit properties and methods from.</li>\n<li>Factory functions offer private properties and methods through a closure but increase memory usage as a tradeoff, while classes do not have private properties or methods but reduce memory impact by reusing a single prototype object.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> What is the difference between a parameter and an argument?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Parameters are the variable names of the function definition, while arguments are the values given to a function when it is invoked.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">parameter1<span class=\"token punctuation\">,</span> parameter2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"argument1\"</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token string\">'argument1'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'argument2'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li><code class=\"language-text\">arguments</code> is an array-like object containing information about the arguments supplied to an invoked function.</li>\n<li><code class=\"language-text\">myFunction.length</code> describes the arity of a function (how many parameters it has, regardless of how many arguments it is supplied).</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> Does JavaScript pass by value or by reference?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>JavaScript always passes by value. However, with objects, the value is a reference to the object.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Difference between pass-by-value and pass-by-reference</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://medium.com/dailyjs/back-to-roots-javascript-value-vs-reference-8fb69d587a18\">JavaScript Value vs Reference</a></li>\n</ul>\n<h3><span style=\"color:red;\"> How do you pass an argument to an event handler or callback?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>You can use an arrow function to wrap around an event handler and pass arguments, which is equivalent to calling <code class=\"language-text\">bind</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/handling-events.html\">React docs on Handling Events</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Create a function <code class=\"language-text\">pipe</code> that performs left-to-right function composition by returning a function that accepts one argument.</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">square</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">v</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">*</span> v<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">double</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">v</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">addOne</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">v</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> res <span class=\"token operator\">=</span> <span class=\"token function\">pipe</span><span class=\"token punctuation\">(</span>square<span class=\"token punctuation\">,</span> double<span class=\"token punctuation\">,</span> addOne<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">res</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 19; addOne(double(square(3)))</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Gather all supplied arguments using the rest operator <code class=\"language-text\">...</code> and return a unary function that uses <code class=\"language-text\">Array.prototype.reduce()</code> to run the value through the series of functions before returning the final value.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">pipe</span> <span class=\"token operator\">=</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>fns</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">x</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n        fns<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">v<span class=\"token punctuation\">,</span> fn</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Function composition is the process of combining two or more functions to produce a new function.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://medium.com/javascript-scene/master-the-javascript-interview-what-is-function-composition-20dfb109a1a0\">What is function composition?</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are portals in React?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Portal are the recommended way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">createPortal</span><span class=\"token punctuation\">(</span>child<span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The first argument (<code class=\"language-text\">child</code>) is any renderable React child, such as an element, string, or fragment. The second argument (<code class=\"language-text\">container</code>) is a DOM element.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/portals.html\">React docs on Portals</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between the postfix <code class=\"language-text\">i++</code> and prefix <code class=\"language-text\">++i</code> increment operators?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Both increment the variable value by 1. The difference is what they evaluate to.\nThe postfix increment operator evaluates to the value <em>before</em> it was incremented.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\ni<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// i === 1</span></code></pre></div>\n<p>The prefix increment operator evaluates to the value <em>after</em> it was incremented.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token operator\">++</span>i<span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// i === 1</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> In which states can a Promise be?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>A <code class=\"language-text\">Promise</code> is in one of these states:</p>\n<ul>\n<li>pending: initial state, neither fulfilled nor rejected.</li>\n<li>fulfilled: meaning that the operation completed successfully.</li>\n<li>rejected: meaning that the operation failed.\nA pending promise can either be fulfilled with a value, or rejected with a reason (error). When either of these options happens, the associated handlers queued up by a promise's then method are called.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\">Official Web Docs - Promise</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are Promises?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The <code class=\"language-text\">Promise</code> object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value. An example can be the following snippet, which after 100ms prints out the result string to the standard output. Also, note the catch, which can be used for error handling. <code class=\"language-text\">Promise</code>s are chainable.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">'result'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span>console<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Take a look into the other questions regarding <code class=\"language-text\">Promise</code>s!</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-promise-27fc71e772618\">Master the JavaScript Interview: What is a Promise?</a></li>\n</ul>\n<h3><span style=\"color:red;\"> How to apply prop validation in React?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>When the application is running in development mode, React will automatically check for all props that we set on components to make sure they are the correct data type. For incorrect data types, it will generate warning messages in the console for development mode. They are stripped in production mode due to their performance impact. Required props are defined with <code class=\"language-text\">isRequired</code>.\nFor example, we define <code class=\"language-text\">propTypes</code> for component as below:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> PropTypes <span class=\"token keyword\">from</span> <span class=\"token string\">\"prop-types\"</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">User</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">static</span> propTypes <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>string<span class=\"token punctuation\">.</span>isRequired<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>number<span class=\"token punctuation\">.</span>isRequired\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Welcome<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>Age<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>We can define custom <code class=\"language-text\">propTypes</code></li>\n<li>Using <code class=\"language-text\">propTypes</code> is not mandatory. However, it is a good practice and can reduce bugs.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> How does prototypal inheritance differ from classical inheritance?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>In the classical inheritance paradigm, object instances inherit their properties and functions from a class, which acts as a blueprint for the object. Object instances are typically created using a constructor and the <code class=\"language-text\">new</code> keyword.\nIn the prototypal inheritance paradigm, object instances inherit directly from other objects and are typically created using factory functions or <code class=\"language-text\">Object.create()</code>.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain\">MDN docs for inheritance and the prototype chain</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a pure function?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>A pure function is a function that satisfies these two conditions:</p>\n<ul>\n<li>Given the same input, the function returns the same output.</li>\n<li>The function doesn't cause side effects outside of the function's scope (i.e. mutate data outside the function or data supplied to the function).\nPure functions can mutate local data within the function as long as it satisfies the two conditions above.</li>\n</ul>\n<h3><span style=\"color:red;\"> Pure</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">a</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> x <span class=\"token operator\">+</span> y<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">b</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">c</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>arr<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Impure</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">a</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> x <span class=\"token operator\">+</span> y <span class=\"token operator\">+</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">random</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">b</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">c</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Pure functions are easier to reason about due to their reliability.</li>\n<li>All functions should be pure unless explicitly causing a side effect (i.e. <code class=\"language-text\">setInnerHTML</code>).</li>\n<li>If a function does not return a value, it is an indication that it is causing side effects.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"http://www.nicoespeon.com/en/2015/01/pure-functions-javascript/\">Pure functions in JavaScript</a></li>\n</ul>\n<h3><span style=\"color:red;\"> How do you write comments inside a JSX tree in React?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Comments must be wrapped inside curly braces <code class=\"language-text\">{}</code> and use the <code class=\"language-text\">/* */</code> syntax.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n\n\n<span class=\"token keyword\">const</span> tree <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">{</span><span class=\"token comment\">/* Comment */</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Text<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> What is recursion and when is it useful?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Recursion is the repeated application of a process. In JavaScript, recursion involves functions that call themselves repeatedly until they reach a base condition. The base condition breaks out of the recursion loop because otherwise the function would call itself indefinitely. Recursion is very useful when working with data structures that contain nesting where the number of levels deep is unknown.\nFor example, you may have a thread of comments returned from a database that exist in a flat array but need to be nested for display in the UI. Each comment is either a top-level comment (no parent) or is a reply to a parent comment. Comments can be a reply of a reply of a reply… we have no knowledge beforehand the number of levels deep a comment may be. This is where recursion can help.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> nest <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>items<span class=\"token punctuation\">,</span> id <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> link <span class=\"token operator\">=</span> <span class=\"token string\">'parent_id'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> items<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> item<span class=\"token punctuation\">[</span>link<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>item<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token function\">nest</span><span class=\"token punctuation\">(</span>items<span class=\"token punctuation\">,</span> item<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> comments <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'First reply to post.'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'First reply to comment #1.'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Second reply to comment #1.'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'First reply to comment #3.'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'First reply to comment #4.'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">'Second reply to post.'</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">nest</span><span class=\"token punctuation\">(</span>comments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">/*\n[\n  { id: 1, parent_id: null, text: \"First reply to post.\", children: [...] },\n  { id: 6, parent_id: null, text: \"Second reply to post.\", children: [] }\n]\n*/</span></code></pre></div>\n<p>In the above example, the base condition is met if <code class=\"language-text\">filter()</code> returns an empty array. The chained <code class=\"language-text\">map()</code> won't invoke the callback function which contains the recursive call, thereby breaking the loop.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Recursion is useful when working with data structures containing an unknown number of nested structures.</li>\n<li>Recursion must have a base condition to be met that breaks out of the loop or it will call itself indefinitely.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://softwareengineering.stackexchange.com/questions/25052/in-plain-english-what-is-recursion\">In plain English, what is recursion?</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the output of the following code?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> b <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> c <span class=\"token operator\">=</span> <span class=\"token string\">'1,2,3'</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">==</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">==</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The first <code class=\"language-text\">console.log</code> outputs <code class=\"language-text\">true</code> because JavaScript's compiler performs type conversion and therefore it compares to strings by their value. On the other hand, the second <code class=\"language-text\">console.log</code> outputs <code class=\"language-text\">false</code> because Arrays are Objects and Objects are compared by reference.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>JavaScript performs automatic type conversion</li>\n<li>Objects are compared by reference</li>\n<li>Primitives are compared by value</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://medium.com/dailyjs/back-to-roots-javascript-value-vs-reference-8fb69d587a18\">JavaScript Value vs Reference</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are refs in React? When should they be used?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Refs provide a way to access DOM nodes or React elements created in the render method. Refs should be used sparringly, but there are some good use cases for refs, such as:</p>\n<ul>\n<li>Managing focus, text selection, or media playback.</li>\n<li>Triggering imperative animations.</li>\n<li>Integrating with third-party DOM libraries.\nRefs are created using <code class=\"language-text\">React.createRef()</code> method and attached to React elements via the <code class=\"language-text\">ref</code> attribute. In order to use refs throughout the component, assign the <code class=\"language-text\">ref</code> to the instance property within the constructor:</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MyComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myRef <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createRef</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div ref<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myRef<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Refs can also be used in functional components with the help of closures.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Refs are used to return a reference to an element.</li>\n<li>Refs shouldn't be overused.</li>\n<li>You can create a ref using <code class=\"language-text\">React.createRef()</code> and attach to elements via the <code class=\"language-text\">ref</code> attribute.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/refs-and-the-dom.html\">React docs on Refs and the DOM</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Where and why is the <code class=\"language-text\">rel=\"noopener\"</code> attribute used?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The <code class=\"language-text\">rel=\"noopener\"</code> is an attribute used in <code class=\"language-text\">&lt;a></code> elements (hyperlinks). It prevents pages from having a <code class=\"language-text\">window.opener</code> property, which would otherwise point to the page from where the link was opened and would allow the page opened from the hyperlink to manipulate the page where the hyperlink is.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li><code class=\"language-text\">rel=\"noopener\"</code> is applied to hyperlinks.</li>\n<li><code class=\"language-text\">rel=\"noopener\"</code> prevents opened links from manipulating the source page.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developers.google.com/web/tools/lighthouse/audits/noopener\">Open external anchors using rel=\"noopener\"</a></li>\n<li><a href=\"https://mathiasbynens.github.io/rel-noopener/\">About rel=\"noopener\"</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is REST?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>REST (REpresentational State Transfer) is a software design pattern for network architecture. A RESTful web application exposes data in the form of information about its resources.\nGenerally, this concept is used in web applications to manage state. With most applications, there is a common theme of reading, creating, updating, and destroying data. Data is modularized into separate tables like <code class=\"language-text\">posts</code>, <code class=\"language-text\">users</code>, <code class=\"language-text\">comments</code>, and a RESTful API exposes access to this data with:</p>\n<ul>\n<li>An identifier for the resource. This is known as the endpoint or URL for the resource.</li>\n<li>The operation the server should perform on that resource in the form of an HTTP method or verb. The common HTTP methods are GET, POST, PUT, and DELETE.</li>\n<li>Here is an example of the</li>\n<li>Reading: <code class=\"language-text\">/posts/</code> => GET</li>\n<li>Creating: <code class=\"language-text\">/posts/new</code> => POS</li>\n<li>Updating: <code class=\"language-text\">/posts/:id</code> => PUT</li>\n<li>Destroying: <code class=\"language-text\">/posts/:id</code> => DELETE</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Alternatives to this pattern like GraphQL</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://medium.com/extend/what-is-rest-a-simple-explanation-for-beginners-part-1-introduction-b4a072f8740f\">What is REST — A Simple Explanation for Beginners, Part 1: Introduction</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What does the following function return?</h3>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Because of JavaScript's automatic semicolon insertion (ASI), the compiler places a semicolon after <code class=\"language-text\">return</code> keyword and therefore it returns <code class=\"language-text\">undefined</code> without an error being thrown.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Automatic semicolon placement can lead to time-consuming bugs</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"http://2ality.com/2011/05/semicolon-insertion.html\">Automatic semicolon insertion in JavaScript</a>\n<strong>Folders</strong>\n<a href=\"../right.html\">&#x3C;parent></a>\n| <strong>File</strong> | <strong>File</strong> | <strong>File</strong> | <strong>File</strong> | <strong>File</strong> | <strong>File</strong> |\n| :--------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------- | :----------------------------------------------------------------- | :--------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------- |\n| <a href=\"accessibility-aria.html\">accessibility-aria.html</a> | <a href=\"fibonacci.html\">fibonacci.html</a> | <a href=\"object-creation.html\">object-creation.html</a> | <a href=\"accessibility-contrast.md\">accessibility-contrast.md</a> | <a href=\"fibonacci.md\">fibonacci.md</a> | <a href=\"null-vs-undefined.md\">null-vs-undefined.md</a> |\n| <a href=\"accessibility-contrast.html\">accessibility-contrast.html</a> | <a href=\"find-the-anagrams.html\">find-the-anagrams.html</a> | <a href=\"parameter-vs-argument.html\">parameter-vs-argument.html</a> | <a href=\"accessibility-testing.md\">accessibility-testing.md</a> | <a href=\"find-the-anagrams.md\">find-the-anagrams.md</a> | <a href=\"object-creation.md\">object-creation.md</a> |\n| <a href=\"accessibility-testing.html\">accessibility-testing.html</a> | <a href=\"flex-layout.html\">flex-layout.html</a> | <a href=\"pass-by-value-reference.html\">pass-by-value-reference.html</a> | <a href=\"accessibility-tree.md\">accessibility-tree.md</a> | <a href=\"flex-layout.md\">flex-layout.md</a> | <a href=\"parameter-vs-argument.md\">parameter-vs-argument.md</a> |\n| <a href=\"accessibility-tree.html\">accessibility-tree.html</a> | <a href=\"floating-point.html\">floating-point.html</a> | <a href=\"passing-arguments-to-event-handlers.html\">passing-arguments-to-event-handlers.html</a> | <a href=\"alt-attribute.md\">alt-attribute.md</a> | <a href=\"floating-point.md\">floating-point.md</a> | <a href=\"pass-by-value-reference.md\">pass-by-value-reference.md</a> |\n| <a href=\"alt-attribute.html\">alt-attribute.html</a> | <a href=\"focus-ring.html\">focus-ring.html</a> | <a href=\"pipe.html\">pipe.html</a> | <a href=\"async-defer-attributes.md\">async-defer-attributes.md</a> | <a href=\"focus-ring.md\">focus-ring.md</a> | <a href=\"passing-arguments-to-event-handlers.md\">passing-arguments-to-event-handlers.md</a> |\n| <a href=\"async-defer-attributes.html\">async-defer-attributes.html</a> | <a href=\"for-each-map.html\">for-each-map.html</a> | <a href=\"portals.html\">portals.html</a> | <a href=\"async-functions.md\">async-functions.md</a> | <a href=\"for-each-map.md\">for-each-map.md</a> | <a href=\"pipe.md\">pipe.md</a> |\n| <a href=\"async-functions.html\">async-functions.html</a> | <a href=\"fragments.html\">fragments.html</a> | <a href=\"postfix-vs-prefix-increment.html\">postfix-vs-prefix-increment.html</a> | <a href=\"batches.md\">batches.md</a> | <a href=\"fragments.md\">fragments.md</a> | <a href=\"portals.md\">portals.md</a> |\n| <a href=\"batches.html\">batches.html</a> | <a href=\"functional-programming.html\">functional-programming.html</a> | <a href=\"promise-states.html\">promise-states.html</a> | <a href=\"bem.md\">bem.md</a> | <a href=\"functional-programming.md\">functional-programming.md</a> | <a href=\"postfix-vs-prefix-increment.md\">postfix-vs-prefix-increment.md</a> |\n| <a href=\"bem.html\">bem.html</a> | <a href=\"handling-route-changes-in-single-page-apps.html\">handling-route-changes-in-single-page-apps.html</a> | <a href=\"promises.html\">promises.html</a> | <a href=\"big-o-notation.md\">big-o-notation.md</a> | <a href=\"handling-route-changes-in-single-page-apps.md\">handling-route-changes-in-single-page-apps.md</a> | <a href=\"promise-states.md\">promise-states.md</a> |\n| <a href=\"big-o-notation.html\">big-o-notation.html</a> | <a href=\"hoc-component.html\">hoc-component.html</a> | <a href=\"prop-validation.html\">prop-validation.html</a> | <a href=\"bind-function.md\">bind-function.md</a> | <a href=\"hoc-component.md\">hoc-component.md</a> | <a href=\"promises.md\">promises.md</a> |\n| <a href=\"bind-function.html\">bind-function.html</a> | <a href=\"hoisting-example.html\">hoisting-example.html</a> | <a href=\"prototypal-inheritance.html\">prototypal-inheritance.html</a> | <a href=\"cache-busting.md\">cache-busting.md</a> | <a href=\"hoisting-example.md\">hoisting-example.md</a> | <a href=\"prop-validation.md\">prop-validation.md</a> |\n| <a href=\"cache-busting.html\">cache-busting.html</a> | <a href=\"hoisting.html\">hoisting.html</a> | <a href=\"pure-functions.html\">pure-functions.html</a> | <a href=\"callback-hell.md\">callback-hell.md</a> | <a href=\"hoisting.md\">hoisting.md</a> | <a href=\"prototypal-inheritance.md\">prototypal-inheritance.md</a> |\n| <a href=\"callback-hell.html\">callback-hell.html</a> | <a href=\"html-multiple-header-footers.html\">html-multiple-header-footers.html</a> | <a href=\"react-comments.html\">react-comments.html</a> | <a href=\"callback-in-setState.md\">callback-in-setState.md</a> | <a href=\"html-multiple-header-footers.md\">html-multiple-header-footers.md</a> | <a href=\"pure-functions.md\">pure-functions.md</a> |\n| <a href=\"callback-in-setState.html\">callback-in-setState.html</a> | <a href=\"html-specification-implementation.html\">html-specification-implementation.html</a> | <a href=\"recursion.html\">recursion.html</a> | <a href=\"callback-refs-vs-finddomnode.md\">callback-refs-vs-finddomnode.md</a> | <a href=\"html-specification-implementation.md\">html-specification-implementation.md</a> | <a href=\"react-comments.md\">react-comments.md</a> |\n| <a href=\"callback-refs-vs-finddomnode.html\">callback-refs-vs-finddomnode.html</a> | <a href=\"html-vs-react-event-handling.html\">html-vs-react-event-handling.html</a> | <a href=\"reference-example.html\">reference-example.html</a> | <a href=\"callbacks.md\">callbacks.md</a> | <a href=\"html-vs-react-event-handling.md\">html-vs-react-event-handling.md</a> | <a href=\"recursion.md\">recursion.md</a> |\n| <a href=\"callbacks.html\">callbacks.html</a> | <a href=\"html-vs-xhtml.html\">html-vs-xhtml.html</a> | <a href=\"refs.html\">refs.html</a> | <a href=\"children-prop.md\">children-prop.md</a> | <a href=\"html-vs-xhtml.md\">html-vs-xhtml.md</a> | <a href=\"reference-example.md\">reference-example.md</a> |\n| <a href=\"children-prop.html\">children-prop.html</a> | <a href=\"html5-semantic-elements-usage.html\">html5-semantic-elements-usage.html</a> | <a href=\"rel-noopener.html\">rel-noopener.html</a> | <a href=\"class-name.md\">class-name.md</a> | <a href=\"html5-semantic-elements-usage.md\">html5-semantic-elements-usage.md</a> | <a href=\"refs.md\">refs.md</a> |\n| <a href=\"class-name.html\">class-name.html</a> | <a href=\"html5-web-storage.html\">html5-web-storage.html</a> | <a href=\"rest.html\">rest.html</a> | <a href=\"clone-object.md\">clone-object.md</a> | <a href=\"html5-web-storage.md\">html5-web-storage.md</a> | <a href=\"rel-noopener.md\">rel-noopener.md</a> |\n| <a href=\"clone-object.html\">clone-object.html</a> | <a href=\"iife.html\">iife.html</a> | <a href=\"return-semicolon.html\">return-semicolon.html</a> | <a href=\"closures.md\">closures.md</a> | <a href=\"iife.md\">iife.md</a> | <a href=\"rest.md\">rest.md</a> |\n| <a href=\"closures.html\">closures.html</a> | <a href=\"imperative-vs-declarative.html\">imperative-vs-declarative.html</a> | <a href=\"right.html\">right.html</a> | <a href=\"comparing-objects.md\">comparing-objects.md</a> | <a href=\"imperative-vs-declarative.md\">imperative-vs-declarative.md</a> | <a href=\"return-semicolon.md\">return-semicolon.md</a> |\n| <a href=\"comparing-objects.html\">comparing-objects.html</a> | <a href=\"inline-conditional-expressions.html\">inline-conditional-expressions.html</a> | <a href=\"semicolons.html\">semicolons.html</a> | <a href=\"context.md\">context.md</a> | <a href=\"inline-conditional-expressions.md\">inline-conditional-expressions.md</a> | <a href=\"semicolons.md\">semicolons.md</a> |\n| <a href=\"context.html\">context.html</a> | <a href=\"keys.html\">keys.html</a> | <a href=\"short-circuit-evaluation.html\">short-circuit-evaluation.html</a> | <a href=\"cors.md\">cors.md</a> | <a href=\"keys.md\">keys.md</a> | <a href=\"short-circuit-evaluation.md\">short-circuit-evaluation.md</a> |\n| <a href=\"cors.html\">cors.html</a> | <a href=\"landmark-roles.html\">landmark-roles.html</a> | <a href=\"sprites.html\">sprites.html</a> | <a href=\"css-box-model.md\">css-box-model.md</a> | <a href=\"landmark-roles.md\">landmark-roles.md</a> | <a href=\"sprites.md\">sprites.md</a> |\n| <a href=\"css-box-model.html\">css-box-model.html</a> | <a href=\"lexical-vs-dynamic-scoping.html\">lexical-vs-dynamic-scoping.html</a> | <a href=\"stateful-components.html\">stateful-components.html</a> | <a href=\"css-preprocessors.md\">css-preprocessors.md</a> | <a href=\"lexical-vs-dynamic-scoping.md\">lexical-vs-dynamic-scoping.md</a> | <a href=\"stateful-components.md\">stateful-components.md</a> |\n| <a href=\"css-preprocessors.html\">css-preprocessors.html</a> | <a href=\"lifecycle-methods.html\">lifecycle-methods.html</a> | <a href=\"stateless-components.html\">stateless-components.html</a> | <a href=\"css-sibling-selectors.md\">css-sibling-selectors.md</a> | <a href=\"lifecycle-methods.md\">lifecycle-methods.md</a> | <a href=\"stateless-components.md\">stateless-components.md</a> |\n| <a href=\"css-sibling-selectors.html\">css-sibling-selectors.html</a> | <a href=\"lifecycle.html\">lifecycle.html</a> | <a href=\"static-vs-instance-method.html\">static-vs-instance-method.html</a> | <a href=\"css-specificity.md\">css-specificity.md</a> | <a href=\"lifecycle.md\">lifecycle.md</a> | <a href=\"static-vs-instance-method.md\">static-vs-instance-method.md</a> |\n| <a href=\"css-specificity.html\">css-specificity.html</a> | <a href=\"lift-state.html\">lift-state.html</a> | <a href=\"sync-vs-async.html\">sync-vs-async.html</a> | <a href=\"debouncing.md\">debouncing.md</a> | <a href=\"lift-state.md\">lift-state.md</a> | <a href=\"sync-vs-async.md\">sync-vs-async.md</a> |\n| <a href=\"debouncing.html\">debouncing.html</a> | <a href=\"mask.html\">mask.html</a> | <a href=\"this.html\">this.html</a> | <a href=\"dom.md\">dom.md</a> | <a href=\"mask.md\">mask.md</a> | <a href=\"this.md\">this.md</a> |\n| <a href=\"dom.html\">dom.html</a> | <a href=\"media-properties.html\">media-properties.html</a> | <a href=\"typeof-typeof.html\">typeof-typeof.html</a> | <a href=\"double-vs-triple-equals.md\">double-vs-triple-equals.md</a> | <a href=\"media-properties.md\">media-properties.md</a> | <a href=\"typeof-typeof.md\">typeof-typeof.md</a> |\n| <a href=\"double-vs-triple-equals.html\">double-vs-triple-equals.html</a> | <a href=\"memoize.html\">memoize.html</a> | <a href=\"types.html\">types.html</a> | <a href=\"element-vs-component.md\">element-vs-component.md</a> | <a href=\"memoize.md\">memoize.md</a> | <a href=\"types.md\">types.md</a> |\n| <a href=\"element-vs-component.html\">element-vs-component.html</a> | <a href=\"methods-context-react-classes.html\">methods-context-react-classes.html</a> | <a href=\"ui-library-framework-purpose.html\">ui-library-framework-purpose.html</a> | <a href=\"em-rem-difference.md\">em-rem-difference.md</a> | <a href=\"methods-context-react-classes.md\">methods-context-react-classes.md</a> | <a href=\"ui-library-framework-purpose.md\">ui-library-framework-purpose.md</a> |\n| <a href=\"em-rem-difference.html\">em-rem-difference.html</a> | <a href=\"mime.html\">mime.html</a> | <a href=\"use-strict.html\">use-strict.html</a> | <a href=\"error-boundaries.md\">error-boundaries.md</a> | <a href=\"mime.md\">mime.md</a> | <a href=\"use-strict.md\">use-strict.md</a> |\n| <a href=\"error-boundaries.html\">error-boundaries.html</a> | <a href=\"mutable-vs-immutable.html\">mutable-vs-immutable.html</a> | <a href=\"var-let-const.html\">var-let-const.html</a> | <a href=\"event-delegation.md\">event-delegation.md</a> | <a href=\"mutable-vs-immutable.md\">mutable-vs-immutable.md</a> | <a href=\"var-let-const.md\">var-let-const.md</a> |\n| <a href=\"event-delegation.html\">event-delegation.html</a> | <a href=\"nan.html\">nan.html</a> | <a href=\"virtual-dom.html\">virtual-dom.html</a> | <a href=\"event-driven-programming.md\">event-driven-programming.md</a> | <a href=\"nan.md\">nan.md</a> | <a href=\"virtual-dom.md\">virtual-dom.md</a> |\n| <a href=\"event-driven-programming.html\">event-driven-programming.html</a> | <a href=\"node-error-first-callback.html\">node-error-first-callback.html</a> | <a href=\"wcag.html\">wcag.html</a> | <a href=\"expression-vs-statement.md\">expression-vs-statement.md</a> | <a href=\"node-error-first-callback.md\">node-error-first-callback.md</a> | <a href=\"wcag.md\">wcag.md</a> |\n| <a href=\"expression-vs-statement.html\">expression-vs-statement.html</a> | <a href=\"node-event-loop.html\">node-event-loop.html</a> | <a href=\"xss.html\">xss.html</a> | <a href=\"falsy-truthy.md\">falsy-truthy.md</a> | <a href=\"node-event-loop.md\">node-event-loop.md</a> | <a href=\"xss.md\">xss.md</a> |\n| <a href=\"falsy-truthy.html\">falsy-truthy.html</a> | <a href=\"null-vs-undefined.html\">null-vs-undefined.html</a> | <a href=\"accessibility-aria.md\">accessibility-aria.md</a> | | | |\nFolders: 1\nFiles: 219\nSize of all files: 461594 K</li>\n</ul>\n<h3><span style=\"color:red;\"> Are semicolons required in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Sometimes. Due to JavaScript's automatic semicolon insertion, the interpreter places semicolons after most statements. This means semicolons can be omitted in most cases.\nHowever, there are some cases where they are required. They are not required at the beginning of a block, but are if they follow a line and:</p>\n<ol>\n<li>The line starts with <code class=\"language-text\">[</code></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> previousLine <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> previousLine<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li>The line starts with <code class=\"language-text\">(</code></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> previousLine <span class=\"token operator\">=</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In the above cases, the interpreter does not insert a semicolon after <code class=\"language-text\">3</code>, and therefore it will see the <code class=\"language-text\">3</code> as attempting object property access or being invoked as a function, which will throw errors.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Semicolons are usually optional in JavaScript but have edge cases where they are required.</li>\n<li>If you don't use semicolons, tools like Prettier will insert semicolons for you in the places where they are required on save in a text editor to prevent errors.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> What is short-circuit evaluation in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Short-circuit evaluation involves logical operations evaluating from left-to-right and stopping early.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In the above sample using logical OR, JavaScript won't look at the second operand <code class=\"language-text\">false</code>, because the expression evaluates to <code class=\"language-text\">true</code> regardless. This is known as short-circuit evaluation.\nThis also works for logical AND.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token boolean\">false</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This means you can have an expression that throws an error if evaluated, and it won't cause issues.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> <span class=\"token function\">nonexistentFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token boolean\">false</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">nonexistentFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This remains true for multiple operations because of left-to-right evaluation.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> <span class=\"token function\">nonexistentFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> window<span class=\"token punctuation\">.</span>nothing<span class=\"token punctuation\">.</span>wouldThrowError<span class=\"token punctuation\">;</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> window<span class=\"token punctuation\">.</span>nothing<span class=\"token punctuation\">.</span>wouldThrowError<span class=\"token punctuation\">;</span>\n<span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>A common use case for this behavior is setting default values. If the first operand is falsy the second operand will be evaluated.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> options <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> setting <span class=\"token operator\">=</span> options<span class=\"token punctuation\">.</span>setting <span class=\"token operator\">||</span> <span class=\"token string\">'default'</span><span class=\"token punctuation\">;</span>\nsetting<span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"default\"</span></code></pre></div>\n<p>Another common use case is only evaluating an expression if the first operand is truthy.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Instead of:</span>\n<span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">handleButtonClick</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// You can take advantage of short-circuit evaluation:</span>\n<span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">handleButtonClick</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In the above case, if <code class=\"language-text\">e.target</code> is not or does not contain an element matching the <code class=\"language-text\">\"button\"</code> selector, the function will not be called. This is because the first operand will be falsy, causing the second operand to not be evaluated.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Logical operations do not produce a boolean unless the operand(s) evaluate to a boolean.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://codeburst.io/javascript-what-is-short-circuit-evaluation-ff22b2f5608c\">JavaScript: What is short-circuit evaluation?</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are the advantages of using CSS sprites and how are they utilized?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>CSS sprites combine multiple images into one image, limiting the number of HTTP requests a browser has to make, thus improving load times. Even under the new HTTP/2 protocol, this remains true.\nUnder HTTP/1.1, at most one request is allowed per TCP connection. With HTTP/1.1, modern browsers open multiple parallel connections (between 2 to 8) but it is limited. With HTTP/2, all requests between the browser and the server are multiplexed on a single TCP connection. This means the cost of opening and closing multiple connections is mitigated, resulting in a better usage of the TCP connection and limits the impact of latency between the client and server. It could then become possible to load tens of images in parallel on the same TCP connection.\nHowever, according to <a href=\"https://blog.octo.com/en/http2-arrives-but-sprite-sets-aint-no-dead/\">benchmark results</a>, although HTTP/2 offers 50% improvement over HTTP/1.1, in most cases the sprite set is still faster to load than individual images.\nTo utilize a spritesheet in CSS, one would use certain properties, such as <code class=\"language-text\">background-image</code>, <code class=\"language-text\">background-position</code> and <code class=\"language-text\">background-size</code> to ultimately alter the <code class=\"language-text\">background</code> of an element.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li><code class=\"language-text\">background-image</code>, <code class=\"language-text\">background-position</code> and <code class=\"language-text\">background-size</code> can be used to utilize a spritesheet.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://css-tricks.com/css-sprites/\">CSS Sprites explained by CSS Tricks</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a stateful component in React?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>A stateful component is a component whose behavior depends on its state. This means that two separate instances of the component if given the same props will not necessarily render the same output, unlike pure function components.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Stateful class component</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// Stateful function component</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>count<span class=\"token punctuation\">,</span> setCount<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Stateful components have internal state that they depend on.</li>\n<li>Stateful components are class components or function components that use stateful Hooks.</li>\n<li>Stateful components have their state initialized in the constructor or with <code class=\"language-text\">useState()</code>.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/state-and-lifecycle.html\">React docs on State and Lifecycle</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a stateless component?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>A stateless component is a component whose behavior does not depend on its state. Stateless components can be either functional or class components. Stateless functional components are easier to maintain and test since they are guaranteed to produce the same output given the same props. Stateless functional components should be preferred when lifecycle hooks don't need to be used.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Stateless components are independent of their state.</li>\n<li>Stateless components can be either class or functional components.</li>\n<li>Stateless functional components avoid the <code class=\"language-text\">this</code> keyword altogether.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://reactjs.org/docs/state-and-lifecycle.html\">React docs on State and Lifecycle</a></li>\n</ul>\n<h3><span style=\"color:red;\"> Explain the difference between a static method and an instance method.</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Static methods belong to a class and don't act on instances, while instance methods belong to the class prototype which is inherited by all instances of the class and acts on them.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nArray<span class=\"token punctuation\">.</span>isArray<span class=\"token punctuation\">;</span> <span class=\"token comment\">// static method of Array</span>\n<span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>push<span class=\"token punctuation\">;</span> <span class=\"token comment\">// instance method of Array</span></code></pre></div>\n<p>In this case, the <code class=\"language-text\">Array.isArray</code> method does not make sense as an instance method of arrays because we already know the value is an array when working with it.\nInstance methods could technically work as static methods, but provide terser syntax:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>How to create static and instance methods with ES2015 class syntax</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\">Classes on MDN</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the difference between synchronous and asynchronous code in JavaScript?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Synchronous means each operation must wait for the previous one to complete.\nAsynchronous means an operation can occur while another operation is still being processed.\nIn JavaScript, all code is synchronous due to the single-threaded nature of it. However, asynchronous operations not part of the program (such as <code class=\"language-text\">XMLHttpRequest</code> or <code class=\"language-text\">setTimeout</code>) are processed outside of the main thread because they are controlled by native code (browser APIs), but callbacks part of the program will still be executed synchronously.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>JavaScript has a concurrency model based on an \"event loop\".</li>\n<li>Functions like <code class=\"language-text\">alert</code> block the main thread so that no user input is registered until the user closes it.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<h3><span style=\"color:red;\"> What is the <code class=\"language-text\">this</code> keyword and how does it work?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The <code class=\"language-text\">this</code> keyword is an object that represents the context of an executing function. Regular functions can have their <code class=\"language-text\">this</code> value changed with the methods <code class=\"language-text\">call()</code>, <code class=\"language-text\">apply()</code> and <code class=\"language-text\">bind()</code>. Arrow functions implicitly bind <code class=\"language-text\">this</code> so that it refers to the context of its lexical environment, regardless of whether or not its context is set explicitly with <code class=\"language-text\">call()</code>.\nHere are some common examples of how <code class=\"language-text\">this</code> works:</p>\n<h3><span style=\"color:red;\"> Object literals</h3>\n<p><code class=\"language-text\">this</code> refers to the object itself inside regular functions if the object precedes the invocation of the function.\nProperties set as <code class=\"language-text\">this</code> do not refer to the object.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> myObject <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">property</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">regularFunction</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">arrowFunction</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">iife</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nmyObject<span class=\"token punctuation\">.</span><span class=\"token function\">regularFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// myObject</span>\nmyObject<span class=\"token punctuation\">[</span><span class=\"token string\">'regularFunction'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// my Object</span>\nmyObject<span class=\"token punctuation\">.</span>property<span class=\"token punctuation\">;</span> <span class=\"token comment\">// NOT myObject; lexical `this`</span>\nmyObject<span class=\"token punctuation\">.</span><span class=\"token function\">arrowFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// NOT myObject; lexical `this`</span>\nmyObject<span class=\"token punctuation\">.</span>iife<span class=\"token punctuation\">;</span> <span class=\"token comment\">// NOT myObject; lexical `this`</span>\n<span class=\"token keyword\">const</span> regularFunction <span class=\"token operator\">=</span> myObject<span class=\"token punctuation\">.</span>regularFunction<span class=\"token punctuation\">;</span>\n<span class=\"token function\">regularFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// NOT myObject; lexical `this`</span></code></pre></div>\n<h3><span style=\"color:red;\"> Event listeners</h3>\n<p><code class=\"language-text\">this</code> refers to the element listening to the event.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\ndocument<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// document.body</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Constructors</h3>\n<p><code class=\"language-text\">this</code> refers to the newly created object.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Example</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// myExample</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> myExample <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Example</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Manual</h3>\n<p>With <code class=\"language-text\">call()</code> and <code class=\"language-text\">apply()</code>, <code class=\"language-text\">this</code> refers to the object passed as the first argument.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">myFunction</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">customThis</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// { customThis: true }</span></code></pre></div>\n<h3><span style=\"color:red;\"> Unwanted <code class=\"language-text\">this</code></h3>\n<p>Because <code class=\"language-text\">this</code> can change depending on the scope, it can have unexpected values when using regular functions.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">doubleArr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token comment\">// this is now this.arr</span>\n            <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">double</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">double</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> value <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nobj<span class=\"token punctuation\">.</span><span class=\"token function\">doubleArr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Uncaught TypeError: this.double is not a function</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>In non-strict mode, global <code class=\"language-text\">this</code> is the global object (<code class=\"language-text\">window</code> in browsers), while in strict mode global <code class=\"language-text\">this</code> is <code class=\"language-text\">undefined</code>.</li>\n<li><code class=\"language-text\">Function.prototype.call</code> and <code class=\"language-text\">Function.prototype.apply</code> set the <code class=\"language-text\">this</code> context of an executing function as the first argument, with <code class=\"language-text\">call</code> accepting a variadic number of arguments thereafter, and <code class=\"language-text\">apply</code> accepting an array as the second argument which are fed to the function in a variadic manner.</li>\n<li><code class=\"language-text\">Function.prototype.bind</code> returns a new function that enforces the <code class=\"language-text\">this</code> context as the first argument which cannot be changed by other functions.</li>\n<li>If a function requires its <code class=\"language-text\">this</code> context to be changed based on how it is called, you must use the <code class=\"language-text\">function</code> keyword. Use arrow functions when you want <code class=\"language-text\">this</code> to be the surrounding (lexical) context.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this\"><code class=\"language-text\">this</code> on MDN</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What does the following code evaluate to?</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>It evaluates to <code class=\"language-text\">\"string\"</code>.\n<code class=\"language-text\">typeof 0</code> evaluates to the string <code class=\"language-text\">\"number\"</code> and therefore <code class=\"language-text\">typeof \"number\"</code> evaluates to <code class=\"language-text\">\"string\"</code>.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof\">MDN docs for typeof</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are JavaScript data types?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The latest ECMAScript standard defines seven data types, six of them being primitive: <code class=\"language-text\">Boolean</code>, <code class=\"language-text\">Null</code>, <code class=\"language-text\">Undefined</code>, <code class=\"language-text\">Number</code>, <code class=\"language-text\">String</code>, <code class=\"language-text\">Symbol</code> and one non-primitive data type: <code class=\"language-text\">Object</code>.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Mention of newly added <code class=\"language-text\">Symbol</code> data type</li>\n<li><code class=\"language-text\">Array</code>, <code class=\"language-text\">Date</code> and <code class=\"language-text\">function</code> are all of type <code class=\"language-text\">object</code></li>\n<li>Functions in JavaScript are objects with the capability of being callable</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures\">MDN docs for data types and data structures</a></li>\n<li><a href=\"https://www.digitalocean.com/community/tutorials/understanding-data-types-in-javascript\">Understanding Data Types in JavaScript</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is the purpose of JavaScript UI libraries/frameworks like React, Vue, Angular, Hyperapp, etc?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The main purpose is to avoid manipulating the DOM directly and keep the state of an application in sync with the UI easily. Additionally, they provide the ability to create components that can be reused when they have similar functionality with minor differences, avoiding duplication which would require multiple changes whenever the structure of a component which is reused in multiple places needs to be updated.\nWhen working with DOM manipulation libraries like jQuery, the data of an application is generally kept in the DOM itself, often as class names or <code class=\"language-text\">data</code> attributes. Manipulating the DOM to update the UI involves many extra steps and can introduce subtle bugs over time. Keeping the state separate and letting a framework handle the UI updates when the state changes reduces cognitive load. Saying you want the UI to look a certain way when the state is a certain value is the declarative way of creating an application, instead of the imperative way of manually updating the UI to reflect the new state.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>The virtual DOM is a representation of the real DOM tree in the form of plain objects, which allows a library to write code as if the entire document is thrown away and rebuilt on each change, while the real DOM only updates what needs to be changed. Comparing the new virtual DOM against the previous one leads to high efficiency as changing real DOM nodes is costly compared to recalculating the virtual DOM.</li>\n<li>JSX is an extension to JavaScript that provides XML-like syntax to create virtual DOM objects which is transformed to function calls by a transpiler. It simplifies control flow (if statements/ternary expressions) compared to tagged template literals.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://github.com/hyperapp/hyperapp#view\">Virtual DOM in Hyperapp</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What does <code class=\"language-text\">'use strict'</code> do and what are some of the key benefits to using it?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>Including <code class=\"language-text\">'use strict'</code> at the beginning of your JavaScript source file enables strict mode, which enforces more strict parsing and error handling of JavaScript code. It is considered a good practice and offers a lot of benefits, such as:</p>\n<ul>\n<li>Easier debugging due to eliminating silent errors.</li>\n<li>Disallows variable redefinition.</li>\n<li>Prevents accidental global variables.</li>\n<li>Oftentimes provides increased performance over identical code that is not running in strict mode.</li>\n<li>Simplifies <code class=\"language-text\">eval()</code> and <code class=\"language-text\">arguments</code>.</li>\n<li>Helps make JavaScript more secure.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Eliminates <code class=\"language-text\">this</code> coercion, throwing an error when <code class=\"language-text\">this</code> references a value of <code class=\"language-text\">null</code> or <code class=\"language-text\">undefined</code>.</li>\n<li>Throws an error on invalid usage of <code class=\"language-text\">delete</code>.</li>\n<li>Prohibits some syntax likely to be defined in future versions of ECMAScript</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode\">MDN docs for strict mode</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What are the differences between <code class=\"language-text\">var</code>, <code class=\"language-text\">let</code>, <code class=\"language-text\">const</code> and no keyword statements?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<h3><span style=\"color:red;\"> No keyword</h3>\n<p>When no keyword exists before a variable assignment, it is either assigning a global variable if one does not exist, or reassigns an already declared variable. In non-strict mode, if the variable has not yet been declared, it will assign the variable as a property of the global object (<code class=\"language-text\">window</code> in browsers). In strict mode, it will throw an error to prevent unwanted global variables from being created.</p>\n<h3><span style=\"color:red;\"> var</h3>\n<p><code class=\"language-text\">var</code> was the default statement to declare a variable until ES2015. It creates a function-scoped variable that can be reassigned and redeclared. However, due to its lack of block scoping, it can cause issues if the variable is being reused in a loop that contains an asynchronous callback because the variable will continue to exist outside of the block scope.\nBelow, by the time the the <code class=\"language-text\">setTimeout</code> callback executes, the loop has already finished and the <code class=\"language-text\">i</code> variable is <code class=\"language-text\">10</code>, so all ten callbacks reference the same variable available in the function scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// logs `10` ten times</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">/* Solutions with `var` */</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Passed as an argument will use the value as-is in</span>\n    <span class=\"token comment\">// that point in time</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Create a new function scope that will use the value</span>\n    <span class=\"token comment\">// as-is in that point in time</span>\n    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> let</h3>\n<p><code class=\"language-text\">let</code> was introduced in ES2015 and is the new preferred way to declare variables that will be reassigned later. Trying to redeclare a variable again will throw an error. It is block-scoped so that using it in a loop will keep it scoped to the iteration.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// logs 0, 1, 2, 3, ...</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3><span style=\"color:red;\"> const</h3>\n<p><code class=\"language-text\">const</code> was introduced in ES2015 and is the new preferred default way to declare all variables if they won't be reassigned later, even for objects that will be mutated (as long as the reference to the object does not change). It is block-scoped and cannot be reassigned.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> myObject <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nmyObject<span class=\"token punctuation\">.</span>prop <span class=\"token operator\">=</span> <span class=\"token string\">'hello!'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// No error</span>\nmyObject <span class=\"token operator\">=</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Error</span></code></pre></div>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>All declarations are hoisted to the top of their scope.</li>\n<li>However, with <code class=\"language-text\">let</code> and <code class=\"language-text\">const</code> there is a concept called the temporal dead zone (TDZ). While the declarations are still hoisted, there is a period between entering scope and being declared where they cannot be accessed.</li>\n<li>Show a common issue with using <code class=\"language-text\">var</code> and how <code class=\"language-text\">let</code> can solve it, as well as a solution that keeps <code class=\"language-text\">var</code>.</li>\n<li><code class=\"language-text\">var</code> should be avoided whenever possible and prefer <code class=\"language-text\">const</code> as the default declaration statement for all variables unless they will be reassigned later, then use <code class=\"language-text\">let</code> if so.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://wesbos.com/let-vs-const/\"><code class=\"language-text\">let</code> vs <code class=\"language-text\">const</code></a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a virtual DOM and why is it used in libraries/frameworks?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>The virtual DOM (VDOM) is a representation of the real DOM in the form of plain JavaScript objects. These objects have properties to describe the real DOM nodes they represent: the node name, its attributes, and child nodes.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div class=\"counter\">\n  &lt;h1>0&lt;/h1>\n  &lt;button>-&lt;/button>\n  &lt;button>+&lt;/button>\n&lt;/div></code></pre></div>\n<p>The above markup's virtual DOM representation might look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">nodeName</span><span class=\"token operator\">:</span> <span class=\"token string\">\"div\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">attributes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">class</span><span class=\"token operator\">:</span> <span class=\"token string\">\"counter\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">nodeName</span><span class=\"token operator\">:</span> <span class=\"token string\">\"h1\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">attributes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">nodeName</span><span class=\"token operator\">:</span> <span class=\"token string\">\"button\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">attributes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"-\"</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">nodeName</span><span class=\"token operator\">:</span> <span class=\"token string\">\"button\"</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">attributes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"+\"</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The library/framework uses the virtual DOM as a means to improve performance. When the state of an application changes, the real DOM needs to be updated to reflect it. However, changing real DOM nodes is costly compared to recalculating the virtual DOM. The previous virtual DOM can be compared to the new virtual DOM very quickly in comparison.\nOnce the changes between the old VDOM and new VDOM have been calculated by the diffing engine of the framework, the real DOM can be patched efficiently in the least time possible to match the new state of the application.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>Why accessing the DOM can be so costly.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"http://reactkungfu.com/2015/10/the-difference-between-virtual-dom-and-dom/\">The difference between Virtual DOM and DOM</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is WCAG? What are the differences between A, AA, and AAA compliance?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>WCAG stands for \"Web Content Accessibility Guidelines\". It is a standard describing how to make web content more accessible to people with disabilities They have 12-13 guidelines and for each one, there are testable success criteria, which are at three levels: A, AA, and AAA. The higher the level, the higher the impact on the design of the web content. The higher the level, the web content is essentially more accessible by more users. Depending on where you live/work, there may be regulations requiring websites to meet certain levels of compliance. For instance, in Ontario, Canada, beginning January 1, 2021 all public websites and web content posted after January 1, 2012 must meet AA compliance.</p>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>A guideline for making web content more accessible</li>\n<li>3 different levels (A, AA, and AAA) of compliance for each guideline</li>\n<li>Governments are starting to require web content to meet a certain level of compliance by law</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.w3.org/WAI/standards-guidelines/wcag/\">Web Content Accessibility Guidelines (WCAG) Overview</a></li>\n<li><a href=\"https://www.w3.org/WAI/WCAG21/quickref/\">How to Meet WCAG</a></li>\n</ul>\n<h3><span style=\"color:red;\"> What is a cross-site scripting attack (XSS) and how do you prevent it?</h3>\n<h3><span style=\"color:red;\"> Answer</h3>\n<p>XSS refers to client-side code injection where the attacker injects malicious scripts into a legitimate website or web application. This is often achieved when the application does not validate user input and freely injects dynamic HTML content.\nFor example, a comment system will be at risk if it does not validate or escape user input. If the comment contains unescaped HTML, the comment can inject a <code class=\"language-text\">&lt;script></code> tag into the website that other users will execute against their knowledge.</p>\n<ul>\n<li>The malicious script has access to cookies which are often used to store session tokens. If an attacker can obtain a user's session cookie, they can impersonate the user.</li>\n<li>The script can arbitrarily manipulate the DOM of the page the script is executing in, allowing the attacker to insert pieces of content that appear to be a real part of the website.</li>\n<li>The script can use AJAX to send HTTP requests with arbitrary content to arbitrary destinations.</li>\n</ul>\n<h3><span style=\"color:red;\"> Don't forget:</h3>\n<ul>\n<li>On the client, using <code class=\"language-text\">textContent</code> instead of <code class=\"language-text\">innerHTML</code> prevents the browser from running the string through the HTML parser which would execute scripts in it.</li>\n<li>On the server, escaping HTML tags will prevent the browser from parsing the user input as actual HTML and therefore won't execute the script.</li>\n</ul>\n<h3><span style=\"color:red;\"> Additional links</h3>\n<ul>\n<li><a href=\"https://www.acunetix.com/websitesecurity/cross-site-scripting/\">Cross-Site Scripting Attack (XSS)</a></li>\n</ul>\n<hr>\n<h1>ALL Prior Code:</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">// Normal promises in regular function:</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">promiseCall</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// do something with the result</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// async functions</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">promiseCall</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token comment\">// do something with the result</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">/**\nIt accepts two objects as arguments: the first object is the recipe\nfor the food, while the second object is the available ingredients.\nEach ingredient's value is a number representing how many units there are.\n`batches(recipe, available)`\n*/</span>\n<span class=\"token comment\">// 0 batches can be made</span>\n<span class=\"token function\">batches</span><span class=\"token punctuation\">(</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">flour</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">132</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">48</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">flour</span><span class=\"token operator\">:</span> <span class=\"token number\">51</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token function\">batches</span><span class=\"token punctuation\">(</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">flour</span><span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">sugar</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">1288</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">flour</span><span class=\"token operator\">:</span> <span class=\"token number\">9</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">sugar</span><span class=\"token operator\">:</span> <span class=\"token number\">95</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\">// 1 batch can be made</span>\n<span class=\"token function\">batches</span><span class=\"token punctuation\">(</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cheese</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">198</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">52</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cheese</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\">// 2 batches can be made</span>\n<span class=\"token function\">batches</span><span class=\"token punctuation\">(</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">sugar</span><span class=\"token operator\">:</span> <span class=\"token number\">40</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">milk</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">sugar</span><span class=\"token operator\">:</span> <span class=\"token number\">120</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">butter</span><span class=\"token operator\">:</span> <span class=\"token number\">500</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">batches</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">recipe<span class=\"token punctuation\">,</span> available</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n  Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>\n    Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span><span class=\"token operator\">...</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>recipe<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">k</span> <span class=\"token operator\">=></span> available<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span> <span class=\"token operator\">/</span> recipe<span class=\"token punctuation\">[</span>k<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">)</span>\narr<span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">some</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> j <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> j <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> j<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">permutations</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">arr</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&lt;=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">2</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>arr<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> arr\n  <span class=\"token keyword\">return</span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">acc<span class=\"token punctuation\">,</span> item<span class=\"token punctuation\">,</span> i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n      acc<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>\n        <span class=\"token function\">permutations</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">val</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">[</span>\n          item<span class=\"token punctuation\">,</span>\n          <span class=\"token operator\">...</span>val\n        <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">example</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> boundExample <span class=\"token operator\">=</span> <span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>example<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token function\">boundExample</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// logs { a: true }</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">bind</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">fn<span class=\"token punctuation\">,</span> context</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>args</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">fn</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>context<span class=\"token punctuation\">,</span> args<span class=\"token punctuation\">)</span>\n<span class=\"token function\">getData</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">b</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">d</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token comment\">// ...</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">asyncAwaitVersion</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> a <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">const</span> b <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">const</span> c <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">const</span> d <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">const</span> e <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">getMoreData</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span>\n  <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"sudheer\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"The name has updated and component re-rendered\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\">// Legacy approach using findDOMNode()</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MyComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">findDOMNode</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">scrollIntoView</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// Recommended approach using callback refs</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MyComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">componentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span><span class=\"token function\">scrollIntoView</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div ref<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token parameter\">node</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>node <span class=\"token operator\">=</span> node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">onClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"The user clicked on the page.\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span>\n    onClick<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">map</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n  <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> arr<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    result<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> result\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token parameter\">n</span> <span class=\"token operator\">=></span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// [2, 4, 6, 8, 10]</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">GenericBox</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> children <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"container\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>GenericBox<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>span<span class=\"token operator\">></span>Hello<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>span<span class=\"token operator\">></span>World<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>GenericBox<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"div\"</span><span class=\"token punctuation\">)</span>\nelement<span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span>\n<span class=\"token keyword\">const</span> element <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">attributes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">class</span><span class=\"token operator\">:</span> <span class=\"token string\">\"hello\"</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">class</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props <span class=\"token comment\">// Error</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> className <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props <span class=\"token comment\">// All good</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">class</span><span class=\"token operator\">:</span> className <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props <span class=\"token comment\">// All good, but</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> shallowClone <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>obj <span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">isDeepEqual</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">obj1<span class=\"token punctuation\">,</span> obj2<span class=\"token punctuation\">,</span> testPrototypes <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>obj1 <span class=\"token operator\">===</span> obj2<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">true</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> obj1 <span class=\"token operator\">===</span> <span class=\"token string\">\"function\"</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> obj2 <span class=\"token operator\">===</span> <span class=\"token string\">\"function\"</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> obj1<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> obj2<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>obj1 <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Date</span> <span class=\"token operator\">&amp;&amp;</span> obj2 <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> obj1<span class=\"token punctuation\">.</span><span class=\"token function\">getTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> obj2<span class=\"token punctuation\">.</span><span class=\"token function\">getTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>obj1<span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span>\n      <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span>\n    <span class=\"token keyword\">typeof</span> obj1 <span class=\"token operator\">!==</span> <span class=\"token string\">\"object\"</span>\n  <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">const</span> prototypesAreEqual <span class=\"token operator\">=</span> testPrototypes\n    <span class=\"token operator\">?</span> <span class=\"token function\">isDeepEqual</span><span class=\"token punctuation\">(</span>\n        Object<span class=\"token punctuation\">.</span><span class=\"token function\">getPrototypeOf</span><span class=\"token punctuation\">(</span>obj1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        Object<span class=\"token punctuation\">.</span><span class=\"token function\">getPrototypeOf</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        <span class=\"token boolean\">true</span>\n      <span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n  <span class=\"token keyword\">const</span> obj1Props <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertyNames</span><span class=\"token punctuation\">(</span>obj1<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">const</span> obj2Props <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">getOwnPropertyNames</span><span class=\"token punctuation\">(</span>obj2<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    obj1Props<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> obj2Props<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span>\n    prototypesAreEqual <span class=\"token operator\">&amp;&amp;</span>\n    obj1Props<span class=\"token punctuation\">.</span><span class=\"token function\">every</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">prop</span> <span class=\"token operator\">=></span> <span class=\"token function\">isDeepEqual</span><span class=\"token punctuation\">(</span>obj1<span class=\"token punctuation\">[</span>prop<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> obj2<span class=\"token punctuation\">[</span>prop<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> Provider<span class=\"token punctuation\">,</span> Consumer <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createContext</span><span class=\"token punctuation\">(</span>defaultValue<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">debounce</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">func<span class=\"token punctuation\">,</span> delay</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> debounceTimer<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> context <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> args <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">;</span>\n      <span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>debounceTimer<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        debounceTimer <span class=\"token operator\">=</span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">func</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>context<span class=\"token punctuation\">,</span> args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListere</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scroll'</span><span class=\"token punctuation\">,</span> <span class=\"token function\">debounce</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Do stuff, this function will be called after a delay of 1 second</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Component</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token string\">\"Hello\"</span>\n<span class=\"token keyword\">const</span> componentElement <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>Component <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token keyword\">const</span> domNodeElement <span class=\"token operator\">=</span> <span class=\"token operator\">&lt;</span>div <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ErrorBoundary</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">hasError</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token comment\">// Use componentDidCatch to log the error</span>\n  <span class=\"token function\">componentDidCatch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error<span class=\"token punctuation\">,</span> info</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// You can also log the error to an error reporting service</span>\n    <span class=\"token function\">logErrorToMyService</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">,</span> info<span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token comment\">// use getDerivedStateFromError to update state</span>\n  <span class=\"token keyword\">static</span> <span class=\"token function\">getDerivedStateFromError</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Display fallback UI</span>\n     <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">hasError</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>hasError<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// You can render any custom fallback UI</span>\n      <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Something went wrong<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>children\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"button\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">button</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  button<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span> handleButtonClick<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span> <span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"button\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">handleButtonClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// This callback function is run when the user</span>\n  <span class=\"token comment\">// clicks on the document.</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> hub <span class=\"token operator\">=</span> <span class=\"token function\">createEventHub</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nhub<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"message\"</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>data<span class=\"token punctuation\">.</span>username<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> said </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>data<span class=\"token punctuation\">.</span>text<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\nhub<span class=\"token punctuation\">.</span><span class=\"token function\">emit</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"message\"</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">username</span><span class=\"token operator\">:</span> <span class=\"token string\">\"John\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Hello?\"</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">let</span> x <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">declaration</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// Assign `x` to the absolute value of `y`.</span>\n<span class=\"token keyword\">var</span> x\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  x <span class=\"token operator\">=</span> y\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n  x <span class=\"token operator\">=</span> <span class=\"token operator\">-</span>y\n<span class=\"token punctuation\">}</span>\n<span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token comment\">// => 10</span>\n<span class=\"token function\">lastCharacter</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"input\"</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// => \"t\"</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">===</span> <span class=\"token boolean\">true</span> <span class=\"token comment\">// => true</span>\n<span class=\"token comment\">// Assign `x` as the absolute value of `y`.</span>\n<span class=\"token keyword\">var</span> x <span class=\"token operator\">=</span> y <span class=\"token operator\">>=</span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> y <span class=\"token operator\">:</span> <span class=\"token operator\">-</span>y\n<span class=\"token function\">Boolean</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">Boolean</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// true</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">!</span><span class=\"token string\">\"\"</span> <span class=\"token comment\">// false</span>\n<span class=\"token operator\">!</span><span class=\"token operator\">!</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">// true</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">fibonacci</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">n</span> <span class=\"token operator\">=></span>\n  <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span><span class=\"token function\">Array</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">acc<span class=\"token punctuation\">,</span> val<span class=\"token punctuation\">,</span> i</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> acc<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">?</span> acc<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> acc<span class=\"token punctuation\">[</span>i <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> words <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'rates'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'stare'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'taser'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tears'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'art'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tabs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tar'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'state'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> words <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'rates'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'rat'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'stare'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'taser'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tears'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'art'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tabs'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'tar'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'bats'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'state'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">anagramGroups</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">wordAry</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> groupedWords <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token comment\">// iterate over each word in the array</span>\n    wordAry<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">word</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// alphabetize the word and a separate variable</span>\n      alphaWord <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token comment\">// if the alphabetize word is already a key, push the actual word value (this is an anagram)</span>\n      <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>groupedWords<span class=\"token punctuation\">[</span>alphaWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> groupedWords<span class=\"token punctuation\">[</span>alphaWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n      <span class=\"token comment\">// otherwise add the alphabetize word key and actual word value (may not turn out to be an anagram)</span>\n      groupedWords<span class=\"token punctuation\">[</span>alphaWord<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>word<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span> groupedWords<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// call the function and store results in a variable called collectedAnagrams</span>\n<span class=\"token keyword\">const</span> collectedAnagrams <span class=\"token operator\">=</span> <span class=\"token function\">anagramGroups</span><span class=\"token punctuation\">(</span>words<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// iterate over groupedAnagrams, printing out group of values</span>\n<span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> sortedWord <span class=\"token keyword\">in</span> collectedAnagrams<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>collectedAnagrams<span class=\"token punctuation\">[</span>sortedWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>collectedAnagrams<span class=\"token punctuation\">[</span>sortedWord<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span> <span class=\"token comment\">// 0.30000000000000004</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">approxEqual</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n1<span class=\"token punctuation\">,</span> n2<span class=\"token punctuation\">,</span> epsilon <span class=\"token operator\">=</span> <span class=\"token number\">0.0001</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span>n1 <span class=\"token operator\">-</span> n2<span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;</span> epsilon\n<span class=\"token function\">approxEqual</span><span class=\"token punctuation\">(</span><span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0.3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// true</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildA <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildB <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildC <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Short syntax supported by Babel 7</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildA <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildB <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span>ChildC <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span><span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> EnhancedComponent <span class=\"token operator\">=</span> <span class=\"token function\">higherOrderComponent</span><span class=\"token punctuation\">(</span>WrappedComponent<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">var</span> foo <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">foobar</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>foo<span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">var</span> foo <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">foobar</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>hoist<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">var</span> hoist <span class=\"token operator\">=</span> <span class=\"token string\">\"value\"</span>\n<span class=\"token keyword\">var</span> hoist\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>hoist<span class=\"token punctuation\">)</span>\nhoist <span class=\"token operator\">=</span> <span class=\"token string\">\"value\"</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// No error; logs \"hello\"</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hello\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// Error: `myFunction` is not a function</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">myFunction</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hello\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> myLibrary <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">var</span> privateVariable <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">publicMethod</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> privateVariable\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nprivateVariable <span class=\"token comment\">// ReferenceError</span>\nmyLibrary<span class=\"token punctuation\">.</span><span class=\"token function\">publicMethod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// 2</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">const</span> numbersDoubled <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> numbers<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  numbersDoubled<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">const</span> numbersDoubled <span class=\"token operator\">=</span> numbers<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span> <span class=\"token operator\">=></span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> messages<span class=\"token punctuation\">,</span> isVisible <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>messages<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>You have <span class=\"token punctuation\">{</span>messages<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">}</span> unread messages<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n      <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>You have no unread messages<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n      <span class=\"token punctuation\">}</span>\n      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>isVisible<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span><span class=\"token constant\">I</span> am visible<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> messages<span class=\"token punctuation\">,</span> isVisible <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n      <span class=\"token punctuation\">{</span>messages<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>You have <span class=\"token punctuation\">{</span>messages<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">}</span> unread messages<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n      <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>You have no unread messages<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">{</span>isVisible <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span><span class=\"token constant\">I</span> am visible<span class=\"token punctuation\">.</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> todoItems <span class=\"token operator\">=</span> todos<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">todo</span> <span class=\"token operator\">=></span> <span class=\"token operator\">&lt;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>todo<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>todo<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> mask <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">,</span> maskChar <span class=\"token operator\">=</span> <span class=\"token string\">\"#\"</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n  str<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">padStart</span><span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> maskChar<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">memoize</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">fn</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> cache <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token parameter\">value</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> cachedResult <span class=\"token operator\">=</span> cache<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>cachedResult <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> cachedResult\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span>\n    cache<span class=\"token punctuation\">.</span><span class=\"token function\">set</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> result<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span> result\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Perform some logic</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function-variable function\">handleClick</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'this is:'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>handleClick<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n      Click me\n    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Click me<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n<span class=\"token keyword\">const</span> myString <span class=\"token operator\">=</span> <span class=\"token string\">\"hello!\"</span>\nmyString<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"!\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// returns a new string, cannot mutate the original value</span>\n<span class=\"token keyword\">const</span> originalArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\noriginalArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// mutates originalArray, now [1, 2, 3, 4]</span>\noriginalArray<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// returns a new array, does not mutate the original</span>\nfs<span class=\"token punctuation\">.</span><span class=\"token function\">readFile</span><span class=\"token punctuation\">(</span>filePath<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">err<span class=\"token punctuation\">,</span> data</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// handle the error, the return is important here</span>\n    <span class=\"token comment\">// so execution stops here</span>\n    <span class=\"token keyword\">return</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token comment\">// use the data object</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">isTrue</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value<span class=\"token punctuation\">,</span> callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token operator\">===</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Value was true.\"</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Value is not true!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">callback</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error<span class=\"token punctuation\">,</span> retval</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span>\n  <span class=\"token punctuation\">}</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>retval<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">isTrue</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span>\n<span class=\"token function\">isTrue</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span>\n<span class=\"token comment\">/*\n  { stack: [Getter/Setter],\n    arguments: undefined,\n    type: undefined,\n    message: 'Value is not true!' }\n  Value was true.\n*/</span>\n<span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"John\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age<span class=\"token operator\">++</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nperson<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// person.age === 51</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name<span class=\"token punctuation\">,</span> age</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> age\n<span class=\"token punctuation\">}</span>\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">birthday</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age<span class=\"token operator\">++</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> person1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"John\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">50</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> person2 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Sally\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span>\nperson1<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// person1.age === 51</span>\nperson2<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// person2.age === 21</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">createPerson</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">name<span class=\"token punctuation\">,</span> age</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token function-variable function\">birthday</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> person<span class=\"token punctuation\">.</span>age<span class=\"token operator\">++</span>\n  <span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> name<span class=\"token punctuation\">,</span> age<span class=\"token punctuation\">,</span> birthday <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> person\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> <span class=\"token function\">createPerson</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"John\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">50</span><span class=\"token punctuation\">)</span>\nperson<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// person.age === 51</span>\n<span class=\"token keyword\">const</span> personProto <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age<span class=\"token operator\">++</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> person <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>personProto<span class=\"token punctuation\">)</span>\nperson<span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">50</span>\nperson<span class=\"token punctuation\">.</span><span class=\"token function\">birthday</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// person.age === 51</span>\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>personProto<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token number\">50</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">writable</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">enumerable</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">parameter1<span class=\"token punctuation\">,</span> parameter2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// \"argument1\"</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"argument1\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"argument2\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleClick</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">square</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">v</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">*</span> v\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">double</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">v</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">*</span> <span class=\"token number\">2</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">addOne</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">v</span> <span class=\"token operator\">=></span> v <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n<span class=\"token keyword\">const</span> res <span class=\"token operator\">=</span> <span class=\"token function\">pipe</span><span class=\"token punctuation\">(</span>square<span class=\"token punctuation\">,</span> double<span class=\"token punctuation\">,</span> addOne<span class=\"token punctuation\">)</span>\n<span class=\"token function\">res</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// 19; addOne(double(square(3)))</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">pipe</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>fns</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token parameter\">x</span> <span class=\"token operator\">=></span> fns<span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">v<span class=\"token punctuation\">,</span> fn</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">)</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">createPortal</span><span class=\"token punctuation\">(</span>child<span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\ni<span class=\"token operator\">++</span> <span class=\"token comment\">// 0</span>\n<span class=\"token comment\">// i === 1</span>\n<span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n<span class=\"token operator\">++</span>i <span class=\"token comment\">// 1</span>\n<span class=\"token comment\">// i === 1</span>\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"result\"</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span>console<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">import</span> PropTypes <span class=\"token keyword\">from</span> <span class=\"token string\">\"prop-types\"</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">User</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">static</span> propTypes <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>string<span class=\"token punctuation\">.</span>isRequired<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> PropTypes<span class=\"token punctuation\">.</span>number<span class=\"token punctuation\">.</span>isRequired\n  <span class=\"token punctuation\">}</span>\n<span class=\"token comment\">//</span>\n<span class=\"token comment\">//   render() {</span>\n<span class=\"token comment\">//     return (</span>\n<span class=\"token comment\">//       &lt;h1>Welcome, {this.props.name}&lt;/h1></span>\n<span class=\"token comment\">//       &lt;h2>Age, {this.props.age}</span>\n<span class=\"token comment\">//     )</span>\n<span class=\"token comment\">//   }</span>\n<span class=\"token comment\">// }</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">a</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> x <span class=\"token operator\">+</span> y\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">b</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">c</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">arr</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>arr<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">a</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> x <span class=\"token operator\">+</span> y <span class=\"token operator\">+</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">random</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">b</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">arr<span class=\"token punctuation\">,</span> value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> arr<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">c</span> <span class=\"token operator\">=</span> <span class=\"token parameter\">arr</span> <span class=\"token operator\">=></span> arr<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">-</span> b<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> nest <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>items<span class=\"token punctuation\">,</span> id <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> link <span class=\"token operator\">=</span> <span class=\"token string\">\"parent_id\"</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span>\n  items\n    <span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span> <span class=\"token operator\">=></span> item<span class=\"token punctuation\">[</span>link<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> id<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>item<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token function\">nest</span><span class=\"token punctuation\">(</span>items<span class=\"token punctuation\">,</span> item<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> comments <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">\"First reply to post.\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">\"First reply to comment #1.\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Second reply to comment #1.\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">\"First reply to comment #3.\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">\"First reply to comment #4.\"</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">parent_id</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Second reply to post.\"</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span>\n<span class=\"token function\">nest</span><span class=\"token punctuation\">(</span>comments<span class=\"token punctuation\">)</span>\n<span class=\"token comment\">/*\n[\n  { id: 1, parent_id: null, text: \"First reply to post.\", children: [...] },\n  { id: 6, parent_id: null, text: \"Second reply to post.\", children: [] }\n]\n*/</span>\n<span class=\"token keyword\">const</span> a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">const</span> b <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">const</span> c <span class=\"token operator\">=</span> <span class=\"token string\">\"1,2,3\"</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">==</span> c<span class=\"token punctuation\">)</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">==</span> b<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">MyComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myRef <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createRef</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div ref<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>myRef<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">>>></span><span class=\"token operator\">></span><span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span>\n  <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">\"hello\"</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> previousLine <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n<span class=\"token punctuation\">;</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> previousLine<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span> <span class=\"token operator\">=></span> n <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">const</span> previousLine <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n<span class=\"token punctuation\">;</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> <span class=\"token boolean\">false</span>\n<span class=\"token boolean\">false</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token boolean\">true</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> <span class=\"token function\">nonexistentFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">false</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">nonexistentFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> <span class=\"token function\">nonexistentFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> window<span class=\"token punctuation\">.</span>nothing<span class=\"token punctuation\">.</span>wouldThrowError\n<span class=\"token boolean\">true</span> <span class=\"token operator\">||</span> window<span class=\"token punctuation\">.</span>nothing<span class=\"token punctuation\">.</span>wouldThrowError\n<span class=\"token boolean\">true</span>\n<span class=\"token keyword\">const</span> options <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> setting <span class=\"token operator\">=</span> options<span class=\"token punctuation\">.</span>setting <span class=\"token operator\">||</span> <span class=\"token string\">\"default\"</span>\nsetting <span class=\"token comment\">// \"default\"</span>\n<span class=\"token comment\">// Instead of:</span>\n<span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span> <span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"button\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">handleButtonClick</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\">// You can take advantage of short-circuit evaluation:</span>\n<span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>\n  <span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span>\n  <span class=\"token parameter\">e</span> <span class=\"token operator\">=></span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"button\"</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">handleButtonClick</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token comment\">// Stateful class component</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">App</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Component</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">props</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">count</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// ...</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">// Stateful function component</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>count<span class=\"token punctuation\">,</span> setCount<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">return</span> <span class=\"token comment\">// ...</span>\n<span class=\"token punctuation\">}</span>\nArray<span class=\"token punctuation\">.</span>isArray <span class=\"token comment\">// static method of Array</span>\n<span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>push <span class=\"token comment\">// instance method of Array</span>\n<span class=\"token keyword\">const</span> arr <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\narr<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\nArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>arr<span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">var</span> myObject <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">property</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function-variable function\">regularFunction</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function-variable function\">arrowFunction</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token literal-property property\">iife</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\nmyObject<span class=\"token punctuation\">.</span><span class=\"token function\">regularFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// myObject</span>\nmyObject<span class=\"token punctuation\">[</span><span class=\"token string\">\"regularFunction\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// my Object</span>\nmyObject<span class=\"token punctuation\">.</span>property <span class=\"token comment\">// NOT myObject; lexical `this`</span>\nmyObject<span class=\"token punctuation\">.</span><span class=\"token function\">arrowFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// NOT myObject; lexical `this`</span>\nmyObject<span class=\"token punctuation\">.</span>iife <span class=\"token comment\">// NOT myObject; lexical `this`</span>\n<span class=\"token keyword\">const</span> regularFunction <span class=\"token operator\">=</span> myObject<span class=\"token punctuation\">.</span>regularFunction\n<span class=\"token function\">regularFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// NOT myObject; lexical `this`</span>\ndocument<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"click\"</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// document.body</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Example</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// myExample</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> myExample <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Example</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">var</span> <span class=\"token function-variable function\">myFunction</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">customThis</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// { customThis: true }</span>\n<span class=\"token keyword\">var</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">arr</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function\">doubleArr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>arr<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// this is now this.arr</span>\n      <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">double</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function\">double</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> value <span class=\"token operator\">*</span> <span class=\"token number\">2</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nobj<span class=\"token punctuation\">.</span><span class=\"token function\">doubleArr</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">// Uncaught TypeError: this.double is not a function</span>\n<span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token number\">0</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// logs `10` ten times</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token comment\">/* Solutions with `var` */</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Passed as an argument will use the value as-is in</span>\n  <span class=\"token comment\">// that point in time</span>\n  <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token comment\">// Create a new function scope that will use the value</span>\n  <span class=\"token comment\">// as-is in that point in time</span>\n  <span class=\"token punctuation\">;</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">i</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n      console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// logs 0, 1, 2, 3, ...</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">const</span> myObject <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\nmyObject<span class=\"token punctuation\">.</span>prop <span class=\"token operator\">=</span> <span class=\"token string\">\"hello!\"</span> <span class=\"token comment\">// No error</span>\nmyObject <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span> <span class=\"token comment\">// Error</span></code></pre></div>"},{"url":"/docs/react/react2/","relativePath":"docs/react/react2.md","relativeDir":"docs/react","base":"react2.md","name":"react2","frontmatter":{"title":"Intro To React","weight":0,"excerpt":"All of the code examples below will be included a second time at the bottom of this article as an embedded gist.","seo":{"title":"React Intro","description":"Introduction to React for Complete Beginners All of the code examples below will be included a second time at the bottom of this article as an embedded gist, so that it is properly syntax highlighted. React uses a syntax extension of JavaScript called JSX that allows you to write HTML directly within JavaScript.","robots":[],"extra":[],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h3>Introduction to React for Complete Beginners</h3>\n<p>All of the code examples below will be included a second time at the bottom of this article as an embedded gist, so that it is properly syntax highlighted.</p>\n<p>React uses a syntax extension of JavaScript called JSX that allows you to write HTML directly within JavaScript.</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/1200/0*Olfj44MF6WSzvlSM.png\" class=\"graf-image\" />\n</figure>\n<h3>React</h3>\n<blockquote>\n<p><em>React uses a syntax extension of JavaScript called JSX that allows you to write HTML directly within JavaScript</em></p>\n</blockquote>\n<blockquote>\n<p><em>because JSX is a syntactic extension of JavaScript, you can actually write JavaScript directly within JSX</em></p>\n</blockquote>\n<blockquote>\n<p><em>include the code you want to be treated as JavaScript within curly braces: { 'this is treated as JavaScript code' }</em></p>\n</blockquote>\n<blockquote>\n<p><em>JSX code must be compiled into JavaScript</em></p>\n</blockquote>\n<blockquote>\n<p><em>under the hood the challenges are calling ReactDOM.render (JSX, document.getElementById('root'))</em></p>\n</blockquote>\n<blockquote>\n<p><em>One important thing to know about nested JSX is that it must return a single element.</em></p>\n</blockquote>\n<blockquote>\n<p><em>For instance, several JSX elements written as siblings with no parent wrapper element will not transpile.</em></p>\n</blockquote>\n<hr>\n<h3>From the React Docs:</h3>\n<h3>What is React?</h3>\n<p>React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It lets you compose complex UIs from small and isolated pieces of code called \"components\".</p>\n<p>React has a few different kinds of components, but we'll start with <code class=\"language-text\">React.Component</code> subclasses:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class ShoppingList extends React.Component {\n  render() {\n    return (\n      &lt;div className=\"shopping-list\">\n        &lt;h1>Shopping List for {this.props.name}&lt;/h1>\n        &lt;ul>\n          &lt;li>Instagram&lt;/li>\n          &lt;li>WhatsApp&lt;/li>\n          &lt;li>Oculus&lt;/li>\n        &lt;/ul>\n      &lt;/div>\n    );\n  }\n}\n\n// Example usage: &lt;ShoppingList name=\"Mark\" /></code></pre></div>\n<details>\n<summary> More About React </summary>\n<p>React.js is a JavaScript library that can be used to build user interfaces. With React, users can create reusable components, and these components display data as it changes over time. React Native also exists to help you create native mobile apps using React (the more common approach for users). In other words, React is a JavaScript tool that makes it easy to reason about, construct, and maintain stateless and stateful user interfaces. It provides the means to declaratively define and divide a UI into UI components (a.k.a., React components) using HTML-like nodes called React nodes. React nodes eventually get transformed into a format for UI rendering (e.g., HTML/DOM, canvas, svg, etc.).</p>\n<p>I could ramble on trying to express in words what React is, but I think it best to just show you. What follows is a whirlwind tour of React and React components from thirty thousand feet. Don't try and figure out all the details yet as I describe React in this section. The entire book is meant to unwrap the details showcased in the following overview. Still asking, <a href=\"https://www.reactenlightenment.com/what-is-react.html\">what is react?</a> Just follow along grabbing a hold of the big concepts for now.</p>\n<h2>Using React to create UI components similar to a <code class=\"language-text\">&lt;select></code></h2>\n<p>Below is an HTML <code class=\"language-text\">&lt;select></code> element that encapsulates child HTML <code class=\"language-text\">&lt;option></code> elements. Hopefully the creation and functionality of an HTML <code class=\"language-text\">&lt;select></code> is already familiar.</p>\n<p>When a browser parses the above tree of elements it will produce a UI containing a textual list of items that can be selected. Click on the \"Result\" tab in the above JSFiddle, to see what the browser produces.</p>\n<p>The browser, <a href=\"http://domenlightenment.com/\">the DOM</a>, and the <a href=\"https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM\">shadow DOM</a> are working together behind the scenes to turn the <code class=\"language-text\">&lt;select></code> HTML into a UI component. Note that the <code class=\"language-text\">&lt;select></code> component allows the user to make a selection thus storing the state of that selection (i.e., click on \"Volvo\", and you have selected it instead of \"Mercedes\").</p>\n<p>Using React you can create a custom <code class=\"language-text\">&lt;select></code> by using React nodes to make a React component that eventually will result in HTML elements in an HTML DOM.</p>\n<p>Let's create our own <code class=\"language-text\">&lt;select></code>-like UI component using React.</p>\n<h2>Defining a React component</h2>\n<p>Below I am creating a React component by invoking the <code class=\"language-text\">React.createClass</code> function in order to create a <code class=\"language-text\">MySelect</code> React component.</p>\n<p>As you can see, the <code class=\"language-text\">MySelect</code> component is made up of some styles and an empty React <code class=\"language-text\">&lt;div></code> node element.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> MySelect <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token comment\">//define MySelect component</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> mySelectStyle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token string\">'1px solid #999'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token string\">'inline-block'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">padding</span><span class=\"token operator\">:</span> <span class=\"token string\">'5px'</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token comment\">// using {} to reference a JS variable inside of JSX</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>mySelectStyle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//react div element, via JSX</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>That <code class=\"language-text\">&lt;div></code> is an HTML-like tag, yes in JavaScript, called <a href=\"https://facebook.github.io/jsx/\">JSX</a>. JSX is an optional custom JavaScript syntax used by React to express React nodes that can map to real HTML elements, custom elements, and text nodes. React nodes, defined using JSX should not be considered a one to one match to HTML elements. There are <a href=\"https://facebook.github.io/react/docs/dom-differences.html\">differences</a> and some <a href=\"https://facebook.github.io/react/docs/jsx-gotchas.html\">gotchas</a>.</p>\n<p>JSX syntax must be transformed from JSX to real JavaScript in order to be parsed by ES5 JS engines. The above code, if not transformed would of course cause a JavaScript error.</p>\n<p>The official tool used to transform JSX to actual JavaScript code is called <a href=\"http://babeljs.io/\">Babel</a>.</p>\n<p>After Babel (or something similar) transforms the JSX <code class=\"language-text\">&lt;div></code> in the above code into real JavaScript, it will look like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">return React.createElement('div', { style: mySelectStyle });</code></pre></div>\n<p>instead of this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">return &lt;div style={mySelectStyle}>\n&lt;/div>;</code></pre></div>\n<p>For now, just keep in mind that when you write HTML-like tags in React code, eventually it must be transformed into real JavaScript, along with any ES6 syntax.</p>\n<p>The <code class=\"language-text\">&lt;MySelect></code> component at this point consist of an empty React <code class=\"language-text\">&lt;div></code> node element. That's a rather trivial component, so let's change it.</p>\n<p>I'm going to define another component called <code class=\"language-text\">&lt;MyOption></code> and then use the <code class=\"language-text\">&lt;MyOption></code> component within the <code class=\"language-text\">&lt;MySelect></code> component (a.k.a., composition).</p>\n<p>Examine the updated JavaScript code below which defines both the <code class=\"language-text\">&lt;MySelect></code> and <code class=\"language-text\">&lt;MyOption></code> React components.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> MySelect <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> mySelectStyle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token string\">'1px solid #999'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token string\">'inline-block'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">padding</span><span class=\"token operator\">:</span> <span class=\"token string\">'5px'</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span> <span class=\"token comment\">//react div element, via JSX, containing &lt;MyOption> component</span>\n            <span class=\"token operator\">&lt;</span>div style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>mySelectStyle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Volvo\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Saab\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Mercedes\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Audi\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> MyOption <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>  <span class=\"token comment\">//define MyOption component</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//react div element, via JSX</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>You should note how the <code class=\"language-text\">&lt;MyOption></code> component is used inside of the <code class=\"language-text\">&lt;MySelect></code> component and that both are created using JSX.</p>\n<h2>Passing Component Options Using React attributes/props</h2>\n<p>Notice that the <code class=\"language-text\">&lt;MyOption></code> component is made up of one <code class=\"language-text\">&lt;div></code> containing the expression <code class=\"language-text\">{this.props.value}</code>. The <code class=\"language-text\">{}</code> brackets indicate to JSX that a JavaScript expression is being used. In other words, inside of <code class=\"language-text\">{}</code> you can write JavaScript.</p>\n<p>The <code class=\"language-text\">{}</code> brackets are used to gain access (i.e., <code class=\"language-text\">this.props.value</code>) to the properties or attributes passed by the <code class=\"language-text\">&lt;MyOption></code> component. In other words, when the <code class=\"language-text\">&lt;MyOption></code> component is rendered the <code class=\"language-text\">value</code> option, passed using an HTML-like attribute (i.e., <code class=\"language-text\">value=\"Volvo\"</code>), will be placed into the <code class=\"language-text\">&lt;div></code>. These HTML looking attributes are considered React attributes/<a href=\"https://facebook.github.io/react-native/docs/props.html\">props</a>. React uses them to pass stateless/immutable options into components. In this case we are simply passing the <code class=\"language-text\">value</code> prop to the <code class=\"language-text\">&lt;MyOption></code> component. Not unlike how an argument is passed to a JavaScript function. And in fact that is exactly what is going on behind the JSX.</p>\n<h2>Rendering a component to the Virtual DOM, then HTML DOM</h2>\n<p>At this point our JavaScript only defines two React Components. We have yet to actually render these components to the Virtual DOM and thus to the HTML DOM.</p>\n<p>Before we do that I'd like to mention that up to this point all we have done is define two React components using JavaScript. In theory, the JavaScript we have so far is just the definition of a UI component. It doesn't strictly have to go into a DOM, or even a Virtual DOM. This same definition, in theory, could also be used to render this component to a <a href=\"https://github.com/facebook/react-native\">native mobile platform</a> or an <a href=\"https://github.com/Flipboard/react-canvas\">HTML canvas</a>. But we're not going to do that, even though we could. Just be aware that React is a pattern for organizing a UI that can transcend the DOM, front-end applications, and <a href=\"https://facebook.github.io/react/docs/top-level-api.html#reactdomserver\">even the web platform</a>.</p>\n<p>Let's now render the <code class=\"language-text\">&lt;MySelect></code> component to the virtual DOM which in turn will render it to the actual DOM inside of an HTML page.</p>\n<p>In the JavaScript below notice I added a call to the <code class=\"language-text\">ReactDOM.render()</code> function on the last line. Here I am passing the <code class=\"language-text\">ReactDOM.render()</code> function the component we want to render (i.e., <code class=\"language-text\">&lt;MySelect></code>) and a reference to the HTML element already in the HTML DOM (i.e., `<div id=\"app\"></p>\n</div>`) where I want to render my React `<MySelect>` component.\n<p>Click on the \"Result\" tab and you will see our custom React <code class=\"language-text\">&lt;MySelect></code> component rendered to the HTML DOM.</p>\n<p>Note that all I did was tell React where to start rendering components and which component to start with. React will then render any children components (i.e., <code class=\"language-text\">&lt;MyOption></code>) contained within the starting component (i.e., <code class=\"language-text\">&lt;MySelect></code>).</p>\n<p>Hold up, you might be thinking. We haven't actually created a <code class=\"language-text\">&lt;select></code> at all. All we have done is create a static/stateless list of text strings. We'll fix that next.</p>\n<p>Before I move on I want to point out that no implicit DOM interactions were written to get the <code class=\"language-text\">&lt;MySelect></code> component into the real DOM. In other words, no jQuery code was invoked during the creation of this component. The dealings with the actual DOM have all been abstracted by the React virtual DOM. In fact, when using React what you are doing is describing a virtual DOM that React takes and uses to create a real DOM for you.</p>\n<h2>Using React state</h2>\n<p>In order for our <code class=\"language-text\">&lt;MySelect></code> component to mimic a native <code class=\"language-text\">&lt;select></code> element we are going to have to add state. After all what good is a custom <code class=\"language-text\">&lt;select></code> element if it can't keep the state of the selection.</p>\n<p>State typically gets involved when a component contains snapshots of information. In regards to our custom <code class=\"language-text\">&lt;MyOption></code> component, its state is the currently selected text or the fact that no text is selected at all. Note that state will typically involve user events (i.e., mouse, keyboard, clipboard, etc.) or network events (i.e., AJAX) and its value is used to determine when the UI needs to be re-rendered (i.e., when value changes re-render).</p>\n<p>State is typically found on the top most component which makes up a UI component. Using the React <code class=\"language-text\">getInitialState()</code> function we can set the default state of our component to <code class=\"language-text\">false</code> (i.e., nothing selected) by returning a state object when <code class=\"language-text\">getInitialState</code> is invoked (i.e., <code class=\"language-text\">return {selected: false};</code>). The <code class=\"language-text\">getInitialState</code> <a href=\"https://facebook.github.io/react/docs/react-component.html#the-component-lifecycle\">lifecycle method</a> gets invoked once before the component is mounted. The return value will be used as the initial value of <code class=\"language-text\">this.state</code>.</p>\n<p>I've updated the code below accordingly to add state to the component. As I am making updates to the code, make sure you read the JavaScript comments which call attention to the changes in the code.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> MySelect <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">getInitialState</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span> <span class=\"token comment\">//add selected, default state</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//this.state.selected = false;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> mySelectStyle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token string\">'1px solid #999'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token string\">'inline-block'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">padding</span><span class=\"token operator\">:</span> <span class=\"token string\">'5px'</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>mySelectStyle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Volvo\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Saab\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Mercedes\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Audi\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> MyOption <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>MySelect <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>With the default state set, next we'll add a callback function called <code class=\"language-text\">select</code> that gets called when a user clicks on an option. Inside of this function we get the text of the option that was selected (via the <code class=\"language-text\">event</code> parameter) and use that to determine how to <code class=\"language-text\">setState</code> on the current component. Notice that I am using <code class=\"language-text\">event</code> details passed to the <code class=\"language-text\">select</code> callback. This pattern should look familiar if you've had any experience with jQuery.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> MySelect <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">getInitialState</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">select</span><span class=\"token operator\">:</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span><span class=\"token comment\">// added select function</span>\n        <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>selected<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span><span class=\"token comment\">//remove selection</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//update state</span>\n        <span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">{</span><span class=\"token comment\">//add selection</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>textContent<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//update state</span>\n        <span class=\"token punctuation\">}</span>   \n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> mySelectStyle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token string\">'1px solid #999'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token string\">'inline-block'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">padding</span><span class=\"token operator\">:</span> <span class=\"token string\">'5px'</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>div style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>mySelectStyle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Volvo\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Saab\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Mercedes\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption value<span class=\"token operator\">=</span><span class=\"token string\">\"Audi\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> MyOption <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>MySelect <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In order for our <code class=\"language-text\">&lt;MyOption></code> components to gain access to the <code class=\"language-text\">select</code> function we'll have to pass a reference to it, via props, from the <code class=\"language-text\">&lt;MySelect></code> component to the <code class=\"language-text\">&lt;MyOption></code> component. To do this we add <code class=\"language-text\">select={this.select}</code> to the <code class=\"language-text\">&lt;MyOption></code> components.</p>\n<p>With that in place we can add <code class=\"language-text\">onClick={this.props.select}</code> to the <code class=\"language-text\">&lt;MyOption></code> components. Hopefully it's obvious that all we have done is wired up a <code class=\"language-text\">click</code> event that will call the <code class=\"language-text\">select</code> function. React takes care of wiring up the real click handler in the real DOM for you.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> MySelect <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">getInitialState</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span><span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">select</span><span class=\"token operator\">:</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>selected<span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>textContent<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>   \n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> mySelectStyle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token string\">'1px solid #999'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token string\">'inline-block'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">padding</span><span class=\"token operator\">:</span> <span class=\"token string\">'5px'</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token comment\">//pass reference, using props, to select callback to &lt;MyOption></span>\n            <span class=\"token operator\">&lt;</span>div style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>mySelectStyle<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption select<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Volvo\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption select<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Saab\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption select<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Mercedes\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>MyOption select<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Audi\"</span><span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>MyOption<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> MyOption <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span><span class=\"token comment\">//add event handler that will invoke select callback</span>\n        <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>div onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&lt;</span>MySelect <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>By doing all this we can now set the state by clicking on one of the options. In other words, when you click on an option the <code class=\"language-text\">select</code> function will now run and set the state of the <code class=\"language-text\">MySelect</code> component. However, the user of the component has no idea this is being done because all we have done is update our code so that state is managed by the component. At this point we have no feedback visually that anything is selected. Let's fix that.</p>\n<p>The next thing we will need to do is pass the current state down to the <code class=\"language-text\">&lt;MyOption></code> component so that it can respond visually to the state of the component.</p>\n<p>Using props, again, we will pass the <code class=\"language-text\">selected</code> state from the <code class=\"language-text\">&lt;MySelect></code> component down to the <code class=\"language-text\">&lt;MyOption></code> component by placing the property <code class=\"language-text\">state={this.state.selected}</code> on all of the <code class=\"language-text\">&lt;MyOption></code> components. Now that we know the state (i.e., <code class=\"language-text\">this.props.state</code>) and the current value (i.e., <code class=\"language-text\">this.props.value</code>) of the option we can verify if the state matches the value in a given <code class=\"language-text\">&lt;MyOption></code> component . If it does, we then know that this option should be selected. We do this by writing a simple <code class=\"language-text\">if</code> statement which adds a styled selected state (i.e., <code class=\"language-text\">selectedStyle</code>) to the JSX <code class=\"language-text\">&lt;div></code> if the state matches the value of the current option. Otherwise, we return a React element with <code class=\"language-text\">unSelectedStyle</code> styles.</p>\n<p>Make sure you click on the \"Result\" tab above and use the custom React select component to verify the new functioning.</p>\n<p>While our React UI select component is not as pretty or feature complete as you might hope, I think you can see still where all this is going. React is a tool that can help you reason about, construct, and maintain stateless and stateful UI components, in a structure tree (i.e., a tree of components).</p>\n<p>Before moving on to the role of the virtual DOM I do want to stress that you don't have to use JSX and Babel. You can always bypass these tools and just write straight JavaScript. Below, I'm showing the final state of the code after the JSX has been transformed by Babel. If you choose not to use JSX, then you'll have to write the following code yourself instead of the code I've written throughout this section.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> MySelect <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">displayName</span><span class=\"token operator\">:</span> <span class=\"token string\">'MySelect'</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token function-variable function\">getInitialState</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">getInitialState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function-variable function\">select</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">select</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>selected<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">setState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">selected</span><span class=\"token operator\">:</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>textContent <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> mySelectStyle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token string\">'1px solid #999'</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token string\">'inline-block'</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">padding</span><span class=\"token operator\">:</span> <span class=\"token string\">'5px'</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n      <span class=\"token string\">'div'</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">style</span><span class=\"token operator\">:</span> mySelectStyle <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n      React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>MyOption<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">state</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>selected<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">select</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">'Volvo'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n      React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>MyOption<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">state</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>selected<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">select</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">'Saab'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n      React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>MyOption<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">state</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>selected<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">select</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">'Mercedes'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n      React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>MyOption<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">state</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>selected<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">select</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>select<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">'Audi'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> MyOption <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createClass</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">displayName</span><span class=\"token operator\">:</span> <span class=\"token string\">'MyOption'</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token function-variable function\">render</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> selectedStyle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">backgroundColor</span><span class=\"token operator\">:</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'#fff'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cursor</span><span class=\"token operator\">:</span> <span class=\"token string\">'pointer'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> unSelectedStyle <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">cursor</span><span class=\"token operator\">:</span> <span class=\"token string\">'pointer'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>value <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n        <span class=\"token string\">'div'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">style</span><span class=\"token operator\">:</span> selectedStyle<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">onClick</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>select <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>value\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n        <span class=\"token string\">'div'</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">style</span><span class=\"token operator\">:</span> unSelectedStyle<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">onClick</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>select <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>value\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>React<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>MySelect<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2>Understanding the role of the Virtual DOM</h2>\n<p>I'm going to end this whirlwind tour where most people typically start talking about React. I'll finish off this React overview by talking about the merits of the React virtual DOM.</p>\n<p>Hopefully you notice the only interaction with the real DOM we had during the creation of our custom select UI is when we told the <code class=\"language-text\">ReactDOM.render()</code> function where to render our UI component in the HTML page (i.e., render it to `<div id=\"app\"></p>\n</div>`). This might just be the only interaction you ever have with the real DOM when building out a React application from a tree of React components. And herein lies much of the value of React. By using React, you really don't ever have to think about the DOM like you once did when you were writing jQuery code. React replaces jQuery, as a complete DOM abstraction, by removing most, if not all, implicit DOM interactions from your code. Of course, that's not the only benefit, or even the best benefit.\n<p>Because the DOM has been completely abstracted by the Virtual DOM this allows for a heavy handed performance pattern of updating the real DOM when state is changed. The Virtual DOM keeps track of UI changes based on state and props. It then compares that to the real DOM, and then makes only the minimal changes required to update the UI. In other words, the real DOM is only ever patched with the minimal changes needed when state or props change.</p>\n<ul>\n<li>Seeing these performant updates in real time will often clarify any confusion about the performant DOM diffing. Look at the animated image below showcasing the usage (i.e., changing state) of the UI component we created in this chapter.</li>\n<li>Notice that as the UI component changes state only the minimally needed changes to the real DOM are occurring. We know that React is doing it's job because the only parts of the real DOM that are actually being updated are the parts with a green outline/background. The entire UI component is not being updated on each state change, only the parts that require a change.</li>\n</ul>\n<blockquote>\n<p>Let me be clear, this isn't a revolutionary concept. You could accomplish the same thing with some carefully crafted and performant minded jQuery code. However, by using React you'll rarely, if ever, have to think about it. The Virtual DOM is doing all the performance work for you. In a sense, this is the best type of jQuery/DOM abstraction possible. One where you don't even have to worry about, or code for, the DOM. It all just happens behinds the scene without you ever implicitly having to interact with the DOM itself.</p>\n</blockquote>\n<p>Now, it might be tempting to leave this overview thinking the value of React is contained in the fact that it almost eliminates the need for something like jQuery. And while the Virtual DOM is certainly a relief when compared to implicit jQuery code, the value of React does not rest alone on the Virtual DOM. The Virtual DOM is just the icing on the cake. Simply stated, the value of React rests upon the fact it provides a simple and maintainable pattern for creating a tree of UI components. Imagine how simple programming a UI could be by defining the entire interface of your application using reusable React components alone.</p>\n</details>\n<p>We'll get to the funny XML-like tags soon. We use components to tell React what we want to see on the screen. When our data changes, React will efficiently update and re-render our components.</p>\n<p>Here, ShoppingList is a <strong>React component class</strong>, or <strong>React component type</strong>. A component takes in parameters, called <code class=\"language-text\">props</code> (short for \"properties\"), and returns a hierarchy of views to display via the <code class=\"language-text\">render</code> method.</p>\n<p>The <code class=\"language-text\">render</code> method returns a <em>description</em> of what you want to see on the screen. React takes the description and displays the result. In particular, <code class=\"language-text\">render</code> returns a <strong>React element</strong>, which is a lightweight description of what to render. Most React developers use a special syntax called \"JSX\" which makes these structures easier to write. The <code class=\"language-text\">&lt;div /></code> syntax is transformed at build time to <code class=\"language-text\">React.createElement('div')</code>. The example above is equivalent to:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">return React.createElement('div', {className: 'shopping-list'},\n  React.createElement('h1', /* ... h1 children ... */),\n  React.createElement('ul', /* ... ul children ... */)\n);</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">---\n\n### Valid JSX:\n\n    &lt;div>\n      &lt;p>Paragraph One&lt;/p>\n      &lt;p>Paragraph Two&lt;/p>\n      &lt;p>Paragraph Three&lt;/p>\n    &lt;/div>\n\n---\n\n### Invalid JSX:\n\n    &lt;p>Paragraph One&lt;/p>\n    &lt;p>Paragraph Two&lt;/p>\n    &lt;p>Paragraph Three&lt;/p>\n\n#### To put comments inside JSX, you use the syntax {/\\* \\*/} to wrap around the comment text.\n\nTo put comments inside JSX, you use the syntax {/\\* \\*/} to wrap around the comment text.\n\nThe code editor has a JSX element similar to what you created in the last challenge. Add a comment somewhere within the provided div element, without modifying the existing h1 or p elements.\n\n\n```js\n//\n\n    const JSX = (\n      &lt;div>\n      {/* This is a comment */}\n        &lt;h1>This is a block of JSX&lt;/h1>\n        &lt;p>Here's a subtitle&lt;/p>\n      &lt;/div>\n    );</code></pre></div>\n<hr>\n<blockquote>\n<p><em>With React, we can render this JSX directly to the HTML DOM using React's rendering API known as ReactDOM.</em></p>\n</blockquote>\n<blockquote>\n<p><em>ReactDOM offers a simple method to render React elements to the DOM which looks like this:</em></p>\n</blockquote>\n<p><code class=\"language-text\">ReactDOM.render(componentToRender, targetNode)</code></p>\n<ul>\n<li><span id=\"f724\">the first argument is the React element or component that you want to render,</span></li>\n<li><span id=\"7093\">and the second argument is the DOM node that you want to render the component to.</span></li>\n</ul>\n<blockquote>\n<p><em>ReactDOM.render() must be called after the JSX element declarations, just like how you must declare variables before using them.</em></p>\n</blockquote>\n<blockquote>\n<p><em>key difference in JSX is that you can no longer use the word class to define HTML classes.</em></p>\n</blockquote>\n<ul>\n<li><span id=\"aafc\">— -> This is because class is a reserved word in JavaScript. Instead, JSX uses className</span></li>\n</ul>\n<blockquote>\n<p><em>the naming convention for all HTML attributes and event references in JSX become camelCase</em></p>\n</blockquote>\n<blockquote>\n<p><em>a click event in JSX is onClick, instead of onclick. Likewise, onchange becomes onChange. While this is a subtle difference, it is an important one to keep in mind moving forward.</em></p>\n</blockquote>\n<h3>Apply a class of myDiv to the div provided in the JSX code.</h3>\n<ul>\n<li><span id=\"9500\">The constant JSX should return a div element.</span></li>\n<li><span id=\"8d42\">The div should have a class of myDiv.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const JSX = (\n  &lt;div>\n    &lt;h1>Add a class to this div&lt;/h1>\n  &lt;/div>\n);</code></pre></div>\n<h3>Ans:</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n <span class=\"token keyword\">const</span> <span class=\"token constant\">JSX</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"myDiv\"</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Add a <span class=\"token keyword\">class</span> <span class=\"token class-name\">to</span> <span class=\"token keyword\">this</span> div<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n### React<span class=\"token operator\">:</span> Learn About Self<span class=\"token operator\">-</span>Closing <span class=\"token constant\">JSX</span> Tags\n\n<span class=\"token operator\">-</span>Another important way <span class=\"token keyword\">in</span> which <span class=\"token constant\">JSX</span> differs <span class=\"token keyword\">from</span> <span class=\"token constant\">HTML</span> is <span class=\"token keyword\">in</span> the idea <span class=\"token keyword\">of</span> the self<span class=\"token operator\">-</span>closing tag<span class=\"token punctuation\">.</span>\n\n<span class=\"token operator\">></span> _In <span class=\"token constant\">HTML</span><span class=\"token punctuation\">,</span> almost all tags have both an opening and closing tag<span class=\"token operator\">:</span>_ <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;div>\n&lt;/div>;</span><span class=\"token template-punctuation string\">`</span></span> _the closing tag always has a forward slash before the tag name that you are closing<span class=\"token punctuation\">.</span>_\n\n<span class=\"token operator\">></span> _there are special instances <span class=\"token keyword\">in</span> <span class=\"token constant\">HTML</span> called <span class=\"token string\">\"self-closing tags\"</span><span class=\"token punctuation\">,</span> or tags that don't require both an opening and closing tag before another tag can start<span class=\"token punctuation\">.</span>_\n\n<span class=\"token operator\">></span> _For example the line<span class=\"token operator\">-</span><span class=\"token keyword\">break</span> tag can be written as_ <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;br></span><span class=\"token template-punctuation string\">`</span></span> _or as_ <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;br />,</span><span class=\"token template-punctuation string\">`</span></span> _but should never be written as_ <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;br>\n&lt;/br></span><span class=\"token template-punctuation string\">`</span></span>_<span class=\"token punctuation\">,</span> since it doesn't contain any content<span class=\"token punctuation\">.</span>_\n\n<span class=\"token operator\">></span> _In <span class=\"token constant\">JSX</span><span class=\"token punctuation\">,</span> the rules are a little different<span class=\"token punctuation\">.</span> Any <span class=\"token constant\">JSX</span> element can be written <span class=\"token keyword\">with</span> a self<span class=\"token operator\">-</span>closing tag<span class=\"token punctuation\">,</span> and every element must be closed<span class=\"token punctuation\">.</span>  \n<span class=\"token operator\">></span> The line<span class=\"token operator\">-</span><span class=\"token keyword\">break</span> tag<span class=\"token punctuation\">,</span> <span class=\"token keyword\">for</span> example<span class=\"token punctuation\">,</span> must always be written as_ <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;br /></span><span class=\"token template-punctuation string\">`</span></span> _in order to be valid <span class=\"token constant\">JSX</span> that can be transpiled<span class=\"token punctuation\">.</span>  \n<span class=\"token operator\">></span> <span class=\"token constant\">A_</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;div></span><span class=\"token template-punctuation string\">`</span></span>_<span class=\"token punctuation\">,</span> on the other hand<span class=\"token punctuation\">,</span> can be written as_ <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;div /></span><span class=\"token template-punctuation string\">`</span></span>_or_<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;div>\n&lt;/div></span><span class=\"token template-punctuation string\">`</span></span>_<span class=\"token punctuation\">.</span>  \n<span class=\"token operator\">></span> The difference is that <span class=\"token keyword\">in</span> the first syntax version there is no way to include anything <span class=\"token keyword\">in</span> the_ <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">&lt;div /></span><span class=\"token template-punctuation string\">`</span></span>_<span class=\"token punctuation\">.</span>_\n\n### Fix the errors <span class=\"token keyword\">in</span> the code editor so that it is valid <span class=\"token constant\">JSX</span> and successfully transpiles<span class=\"token punctuation\">.</span> Make sure you don't change any <span class=\"token keyword\">of</span> the content — you only need to close tags where they are needed<span class=\"token punctuation\">.</span>\n\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">js\n//\n\n    const JSX = (\n      &lt;div>\n        &lt;h2>Welcome to React!&lt;/h2> &lt;br >\n        &lt;p>Be sure to close all tags!&lt;/p>\n        &lt;hr >\n      &lt;/div>\n    );\n\n### Ans:\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>js\n<span class=\"token comment\">//</span>\n\n <span class=\"token keyword\">const</span> <span class=\"token constant\">JSX</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>\n      <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>h2<span class=\"token operator\">></span>Welcome to React<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>br <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Be sure to close all tags<span class=\"token operator\">!</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n      <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3>React: Create a Stateless Functional Component</h3>\n<blockquote>\n<p><em>There are two ways to create a React component. The first way is to use a JavaScript function.</em></p>\n</blockquote>\n<blockquote>\n<p><em>Defining a component in this way creates a stateless functional component.</em></p>\n</blockquote>\n<blockquote>\n<p><em>think of a stateless component as one that can receive data and render it, but does not manage or track changes to that data.</em></p>\n</blockquote>\n<h4>To create a component with a function, you simply write a JavaScript function that returns either JSX or null</h4>\n<ul>\n<li><span id=\"b514\">React requires your function name to begin with a capital letter.</span></li>\n</ul>\n<blockquote>\n<p><em>Here's an example of a stateless functional component that assigns an HTML class in JSX:</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// After being transpiled, the &lt;div> will have a CSS class of 'customClass'\nconst DemoComponent = function() {\n  return (\n    &lt;div className='customClass' />\n  );\n};</code></pre></div>\n<blockquote>\n<p><em>Because a JSX component represents HTML, you could put several components together to create a more complex HTML page.</em></p>\n</blockquote>\n<h3>The code editor has a function called MyComponent. Complete this function so it returns a single div element which contains some string of text.</h3>\n<p>Note: The text is considered a child of the div element, so you will not be able to use a self-closing tag.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const MyComponent = function() {\n  // Change code below this line\n\n  // Change code above this line\n}</code></pre></div>\n<h3>ANS:</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const MyComponent = function() {\n  // Change code below this line\n\nreturn (\n   &lt;div> Some Text &lt;/div >\n  );\n\n  // Change code above this line\n};</code></pre></div>\n<hr>\n<h3>React: Create a React Component</h3>\n<blockquote>\n<p><em>The other way to define a React component is with the ES6 class syntax. In the following example, Kitten extends React.Component:</em></p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Kitten extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n\n  render() {\n    return (\n      &lt;h1>Hi&lt;/h1>\n    );\n  }\n}</code></pre></div>\n<blockquote>\n<p><em>This creates an ES6 class Kitten which extends the React.Component class.</em></p>\n</blockquote>\n<blockquote>\n<p><em>So the Kitten class now has access to many useful React features, such as local state and lifecycle hooks.</em></p>\n</blockquote>\n<blockquote>\n<p><em>Also notice the Kitten class has a constructor defined within it that calls super()</em></p>\n</blockquote>\n<blockquote>\n<p><em>It uses super() to call the constructor of the parent class, in this case React.Component</em></p>\n</blockquote>\n<blockquote>\n<p><em>The constructor is a special method used during the initialization of objects that are created with the class keyword. It is best practice to call a component's constructor with super, and pass props to both.</em></p>\n</blockquote>\n<blockquote>\n<p><em>This makes sure the component is initialized properly. For now, know that it is standard for this code to be included.</em></p>\n</blockquote>\n<h3>MyComponent is defined in the code editor using class syntax. Finish writing the render method so it returns a div element that contains an h1 with the text Hello React!.</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class MyComponent extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n  render() {\n    // Change code below this line\n\n    // Change code above this line\n  }\n};</code></pre></div>\n<h3>ANS:</h3>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class MyComponent extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n  render() {\n    // Change code below this line\n return (\n   &lt;div>\n      &lt;h1>Hello React!&lt;/h1>\n      &lt;/div>\n    );\n\n    // Change code above this line\n  }\n};</code></pre></div>\n<hr>\n<details>\n<summary>  See More </summary>   \n<h3>React: Create a Component with Composition</h3>\n<blockquote>\n<p><em>Imagine you are building an App and have created three components, a Navbar, Dashboard, and Footer.</em></p>\n</blockquote>\n<blockquote>\n<p><em>To compose these components together, you could create an App parent component which renders each of these three components as children. To render a component as a child in a React component, you include the component name written as a custom HTML tag in the JSX.</em></p>\n</blockquote>\n<ul>\n<li><span id=\"000b\">For example, in the render method you could write:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">return (\n &lt;App>\n  &lt;Navbar />\n  &lt;Dashboard />\n  &lt;Footer />\n &lt;/App>\n)</code></pre></div>\n<blockquote>\n<p><em>When React encounters a custom HTML tag that references another component (a component name wrapped in &#x3C; /> like in this example), it renders the markup for that component in the location of the tag. This should illustrate the parent/child relationship between the App component and the Navbar, Dashboard, and Footer.</em></p>\n</blockquote>\n<h3>Challenge:</h3>\n<blockquote>\n<p><em>In the code editor, there is a simple functional component called ChildComponent and a class component called ParentComponent. Compose the two together by rendering the ChildComponent within the ParentComponent. Make sure to close the ChildComponent tag with a forward slash.</em></p>\n</blockquote>\n<ul>\n<li><span id=\"2ed5\">Note:<strong>ChildComponent is defined with an ES6 arrow function because this is a very common practice when using React</strong>.</span></li>\n<li><span id=\"fddd\">However, know that this is just a function.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const ChildComponent = () => {\n  return (\n    &lt;div>\n      &lt;p>I am the child&lt;/p>\n    &lt;/div>\n  );\n};\n\nclass ParentComponent extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n  render() {\n    return (\n      &lt;div>\n        &lt;h1>I am the parent&lt;/h1>\n        { /* Change code below this line */ }\n\n        { /* Change code above this line */ }\n      &lt;/div>\n    );\n  }\n};</code></pre></div>\n<p>⌛The React component should return a single div element.<br>\n⌛The component should return two nested elements.<br>\n⌛The component should return the ChildComponent as its second child.</p>\n<h3>Ans:</h3>\n<details>\n<summary>  Answers </summary>   \n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const ChildComponent = () => {\n  return (\n    &lt;div>\n      &lt;p>I am the child&lt;/p>\n    &lt;/div>\n  );\n};\n\nclass ParentComponent extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n  render() {\n    return (\n      &lt;div>\n        &lt;h1>I am the parent&lt;/h1>\n        { /* Change code below this line */ }\n\n        { /* Change code above this line */ }\n      &lt;/div>\n    );\n  }\n};</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    \n &lt;/details>   \n    \n\n### More Examples:\n\n\n\n&lt;a href=\"https://github.com/bgoonz\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://github.com/bgoonz\">\n&lt;strong>bgoonz - Overview&lt;/strong>\n&lt;br />\n&lt;em>Web Developer, Electrical Engineer https://bryanguner.medium.com/ https://portfolio42.netlify.app/…&lt;/em>github.com&lt;/a>\n&lt;a href=\"https://github.com/bgoonz\" class=\"js-mixtapeImage mixtapeImage u-ignoreBlock\">\n&lt;/a>\n\n_More content at_ &lt;a href=\"http://plainenglish.io/\" class=\"markup--anchor markup--p-anchor\">\n&lt;em>plainenglish.io&lt;/em>\n&lt;/a>\n\nBy &lt;a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner&lt;/a> on [May 19, 2021](https://medium.com/p/8021738aa1ad).\n\n&lt;a href=\"https://medium.com/@bryanguner/introduction-to-react-for-complete-beginners-8021738aa1ad\" class=\"p-canonical\">Canonical link&lt;/a>\n\n May 23, 2021.\n\n# Snippets:\n\n&lt;p>Renders an accordion menu with multiple collapsible content elements.&lt;/p>\n&lt;ul>\n&lt;li>Define an &lt;code>AccordionItem&lt;/code> component, that renders a &lt;code>&amp;lt;button&amp;gt;&lt;/code> which is used to update the component and notify its parent via the &lt;code>handleClick&lt;/code> callback.&lt;/li>\n&lt;li>Use the &lt;code>isCollapsed&lt;/code> prop in &lt;code>AccordionItem&lt;/code> to determine its appearance and set an appropriate &lt;code>className&lt;/code>.&lt;/li>\n&lt;li>Define an &lt;code>Accordion&lt;/code> component that uses the &lt;code>useState()&lt;/code> hook to initialize the value of the &lt;code>bindIndex&lt;/code> state variable to &lt;code>defaultIndex&lt;/code>.&lt;/li>\n&lt;li>Filter &lt;code>children&lt;/code> to remove unnecessary nodes except for &lt;code>AccordionItem&lt;/code> by identifying the function's name.&lt;/li>\n&lt;li>Use &lt;code>Array.prototype.map()&lt;/code> on the collected nodes to render the individual collapsible elements.&lt;/li>\n&lt;li>Define &lt;code>changeItem&lt;/code>, which will be executed when clicking an &lt;code>AccordionItem&lt;/code>'s &lt;code>&amp;lt;button&amp;gt;&lt;/code>.&lt;/li>\n&lt;li>\n&lt;code>changeItem&lt;/code> executes the passed callback, &lt;code>onItemClick&lt;/code>, and updates &lt;code>bindIndex&lt;/code> based on the clicked element.&lt;/li>\n&lt;/ul>\n&lt;div class=\"sourceCode\" id=\"cb1\">\n&lt;pre class=\"sourceCode css\">\n&lt;code class=\"sourceCode css\">\n&lt;a class=\"sourceLine\" id=\"cb1-1\" title=\"1\">\n&lt;span class=\"fu\">.accordion-item.collapsed&lt;/span> {&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-2\" title=\"2\">  &lt;span class=\"kw\">display&lt;/span>: &lt;span class=\"dv\">none&lt;/span>\n&lt;span class=\"op\">;&lt;/span>\n&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-3\" title=\"3\">}&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-4\" title=\"4\">\n&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-5\" title=\"5\">\n&lt;span class=\"fu\">.accordion-item.expanded&lt;/span> {&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-6\" title=\"6\">  &lt;span class=\"kw\">display&lt;/span>: &lt;span class=\"dv\">block&lt;/span>\n&lt;span class=\"op\">;&lt;/span>\n&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-7\" title=\"7\">}&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-8\" title=\"8\">\n&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-9\" title=\"9\">\n&lt;span class=\"fu\">.accordion-button&lt;/span> {&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-10\" title=\"10\">  &lt;span class=\"kw\">display&lt;/span>: &lt;span class=\"dv\">block&lt;/span>\n&lt;span class=\"op\">;&lt;/span>\n&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-11\" title=\"11\">  &lt;span class=\"kw\">width&lt;/span>: &lt;span class=\"dv\">100&lt;/span>\n&lt;span class=\"dt\">%&lt;/span>\n&lt;span class=\"op\">;&lt;/span>\n&lt;/a>\n&lt;a class=\"sourceLine\" id=\"cb1-12\" title=\"12\">}&lt;/a>\n\n&lt;/div>\n\n```js\n//\n\nconst AccordionItem = ({ label, isCollapsed, handleClick, children }) =&amp;gt; {\n  return (\n    &amp;lt;&amp;gt;\n      &amp;lt;button className=&amp;quot;accordion-button&amp;quot; onClick={handleClick}&amp;gt;\n        {label}\n      &amp;lt;/button&amp;gt;\n      &amp;lt;div\n        className={`accordion-item ${isCollapsed ? &amp;quot;collapsed&amp;quot; : &amp;quot;expanded&amp;quot;}`}\n        aria-expanded={isCollapsed}\n      &amp;gt;\n        {children}\n      &amp;lt;/div&amp;gt;\n    &amp;lt;/&amp;gt;\n  );\n};\n\nconst Accordion = ({ defaultIndex, onItemClick, children }) =&amp;gt; {\nconst [bindIndex, setBindIndex] = React.useState(defaultIndex);\n\nconst changeItem = (itemIndex) =&amp;gt; {\nif (typeof onItemClick === &amp;quot;function&amp;quot;) onItemClick(itemIndex);\nif (itemIndex !== bindIndex) setBindIndex(itemIndex);\n};\nconst items = children.filter((item) =&amp;gt; item.type.name === &amp;quot;AccordionItem&amp;quot;);\n\nreturn (\n&amp;lt;&amp;gt;\n{items.map(({ props }) =&amp;gt; (\n&amp;lt;AccordionItem\nisCollapsed={bindIndex !== props.index}\nlabel={props.label}\nhandleClick={() =&amp;gt; changeItem(props.index)}\nchildren={props.children}\n/&amp;gt;\n))}\n&amp;lt;/&amp;gt;\n);\n};\n\n&lt;hr />\n\n```js\n//\n\nReactDOM.render(\n  &amp;lt;Accordion defaultIndex=&amp;quot;1&amp;quot; onItemClick={console.log}&amp;gt;\n    &amp;lt;AccordionItem label=&amp;quot;A&amp;quot; index=&amp;quot;1&amp;quot;&amp;gt;\n      Lorem ipsum\n    &amp;lt;/AccordionItem&amp;gt;\n    &amp;lt;AccordionItem label=&amp;quot;B&amp;quot; index=&amp;quot;2&amp;quot;&amp;gt;\n      Dolor sit amet\n    &amp;lt;/AccordionItem&amp;gt;\n  &amp;lt;/Accordion&amp;gt;,\n  document.getElementById(&amp;quot;root&amp;quot;)\n);</code></pre></div>\n<hr />\n<p>Renders an alert component with <code>type</code> prop.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>isShown</code> and <code>isLeaving</code> state variables and set both to <code>false</code> initially.</li>\n<li>Define <code>timeoutId</code> to keep the timer instance for clearing on component unmount.</li>\n<li>Use the <code>useEffect()</code> hook to update the value of <code>isShown</code> to <code>true</code> and clear the interval by using <code>timeoutId</code> when the component is unmounted.</li>\n<li>Define a <code>closeAlert</code> function to set the component as removed from the DOM by displaying a fading out animation and set <code>isShown</code> to <code>false</code> via <code>setTimeout()</code>.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb4\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb4-1\" title=\"1\">\n<span class=\"im\">@keyframes</span> leave {</a>\n<a class=\"sourceLine\" id=\"cb4-2\" title=\"2\">  <span class=\"dv\">0%</span> {</a>\n<a class=\"sourceLine\" id=\"cb4-3\" title=\"3\">    <span class=\"kw\">opacity</span>: <span class=\"dv\">1</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-4\" title=\"4\">  }</a>\n<a class=\"sourceLine\" id=\"cb4-5\" title=\"5\">  <span class=\"dv\">100%</span> {</a>\n<a class=\"sourceLine\" id=\"cb4-6\" title=\"6\">    <span class=\"kw\">opacity</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-7\" title=\"7\">  }</a>\n<a class=\"sourceLine\" id=\"cb4-8\" title=\"8\">}</a>\n<a class=\"sourceLine\" id=\"cb4-9\" title=\"9\">\n</a>\n<a class=\"sourceLine\" id=\"cb4-10\" title=\"10\">\n<span class=\"fu\">.alert</span> {</a>\n<a class=\"sourceLine\" id=\"cb4-11\" title=\"11\">  <span class=\"kw\">padding</span>: <span class=\"dv\">0.75</span>\n<span class=\"dt\">rem</span> <span class=\"dv\">0.5</span>\n<span class=\"dt\">rem</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-12\" title=\"12\">  <span class=\"kw\">margin-bottom</span>: <span class=\"dv\">0.5</span>\n<span class=\"dt\">rem</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-13\" title=\"13\">  <span class=\"kw\">text-align</span>: <span class=\"dv\">left</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-14\" title=\"14\">  <span class=\"kw\">padding-right</span>: <span class=\"dv\">40</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-15\" title=\"15\">  <span class=\"kw\">border-radius</span>: <span class=\"dv\">4</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-16\" title=\"16\">  <span class=\"kw\">font-size</span>: <span class=\"dv\">16</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-17\" title=\"17\">  <span class=\"kw\">position</span>: <span class=\"dv\">relative</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-18\" title=\"18\">}</a>\n<a class=\"sourceLine\" id=\"cb4-19\" title=\"19\">\n</a>\n<a class=\"sourceLine\" id=\"cb4-20\" title=\"20\">\n<span class=\"fu\">.alert.warning</span> {</a>\n<a class=\"sourceLine\" id=\"cb4-21\" title=\"21\">  <span class=\"kw\">color</span>: <span class=\"cn\">#856404</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-22\" title=\"22\">  <span class=\"kw\">background-color</span>: <span class=\"cn\">#fff3cd</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-23\" title=\"23\">  <span class=\"kw\">border-color</span>: <span class=\"cn\">#ffeeba</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-24\" title=\"24\">}</a>\n<a class=\"sourceLine\" id=\"cb4-25\" title=\"25\">\n</a>\n<a class=\"sourceLine\" id=\"cb4-26\" title=\"26\">\n<span class=\"fu\">.alert.error</span> {</a>\n<a class=\"sourceLine\" id=\"cb4-27\" title=\"27\">  <span class=\"kw\">color</span>: <span class=\"cn\">#721c24</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-28\" title=\"28\">  <span class=\"kw\">background-color</span>: <span class=\"cn\">#f8d7da</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-29\" title=\"29\">  <span class=\"kw\">border-color</span>: <span class=\"cn\">#f5c6cb</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-30\" title=\"30\">}</a>\n<a class=\"sourceLine\" id=\"cb4-31\" title=\"31\">\n</a>\n<a class=\"sourceLine\" id=\"cb4-32\" title=\"32\">\n<span class=\"fu\">.alert.leaving</span> {</a>\n<a class=\"sourceLine\" id=\"cb4-33\" title=\"33\">  <span class=\"kw\">animation</span>: leave <span class=\"dv\">0.5</span>\n<span class=\"dt\">s</span> <span class=\"dv\">forwards</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-34\" title=\"34\">}</a>\n<a class=\"sourceLine\" id=\"cb4-35\" title=\"35\">\n</a>\n<a class=\"sourceLine\" id=\"cb4-36\" title=\"36\">\n<span class=\"fu\">.alert</span> <span class=\"fu\">.close</span> {</a>\n<a class=\"sourceLine\" id=\"cb4-37\" title=\"37\">  <span class=\"kw\">position</span>: <span class=\"dv\">absolute</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-38\" title=\"38\">  <span class=\"kw\">top</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-39\" title=\"39\">  <span class=\"kw\">right</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-40\" title=\"40\">  <span class=\"kw\">padding</span>: <span class=\"dv\">0</span> <span class=\"dv\">0.75</span>\n<span class=\"dt\">rem</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-41\" title=\"41\">  <span class=\"kw\">color</span>: <span class=\"cn\">#333</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-42\" title=\"42\">  <span class=\"kw\">border</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-43\" title=\"43\">  <span class=\"kw\">height</span>: <span class=\"dv\">100</span>\n<span class=\"dt\">%</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-44\" title=\"44\">  <span class=\"kw\">cursor</span>: <span class=\"dv\">pointer</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-45\" title=\"45\">  <span class=\"kw\">background</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-46\" title=\"46\">  <span class=\"kw\">font-weight</span>: <span class=\"dv\">600</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-47\" title=\"47\">  <span class=\"kw\">font-size</span>: <span class=\"dv\">16</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-48\" title=\"48\">}</a>\n<a class=\"sourceLine\" id=\"cb4-49\" title=\"49\">\n</a>\n<a class=\"sourceLine\" id=\"cb4-50\" title=\"50\">\n<span class=\"fu\">.alert</span> <span class=\"fu\">.close</span>\n<span class=\"in\">:after</span> {</a>\n<a class=\"sourceLine\" id=\"cb4-51\" title=\"51\">  <span class=\"kw\">content</span>: <span class=\"st\">&quot;x&quot;</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb4-52\" title=\"52\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Alert <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> isDefaultShown <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> timeout <span class=\"token operator\">=</span> <span class=\"token number\">250</span><span class=\"token punctuation\">,</span> type<span class=\"token punctuation\">,</span> message <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>isShown<span class=\"token punctuation\">,</span> setIsShown<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>isDefaultShown<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>isLeaving<span class=\"token punctuation\">,</span> setIsLeaving<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> timeoutId <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setIsShown</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>timeoutId<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>isDefaultShown<span class=\"token punctuation\">,</span> timeout<span class=\"token punctuation\">,</span> timeoutId<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> closeAlert <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setIsLeaving</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ntimeoutId <span class=\"token operator\">=</span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setIsLeaving</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setIsShown</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> timeout<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\nisShown <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">alert </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>type<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>isLeaving <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>leaving<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\nrole<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>alert<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>close<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>closeAlert<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>message<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Alert type<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>info<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> message<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>This is info<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a string as plaintext, with URLs converted to appropriate link elements.</p>\n<ul>\n<li>Use <code>String.prototype.split()</code> and <code>String.prototype.match()</code> with a regular expression to find URLs in a string.</li>\n<li>Return matched URLs rendered as <code>&lt;a&gt;</code> elements, dealing with missing protocol prefixes if necessary.</li>\n<li>Render the rest of the string as plaintext.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> AutoLink <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> text <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> delimiter <span class=\"token operator\">=</span>\n    <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:https?:\\/\\/)?(?:(?:[a-z0-9]?(?:[a-z0-9\\-]{1,61}[a-z0-9])?\\.[^\\.|\\s])+[a-z\\.]*[a-z]+|(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})(?::\\d{1,5})*[a-z0-9.,_\\/~#&amp;amp;=;%+?\\-\\\\(\\\\)]*)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">gi</span></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>text<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span>delimiter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> match <span class=\"token operator\">=</span> word<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span>delimiter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>match<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> url <span class=\"token operator\">=</span> match<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>a href<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>url<span class=\"token punctuation\">.</span><span class=\"token function\">startsWith</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>http<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> url <span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">http://</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>url<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>url<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">return</span> word<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>AutoLink text<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>foo bar baz http<span class=\"token operator\">:</span><span class=\"token operator\">/</span><span class=\"token operator\">/</span>example<span class=\"token punctuation\">.</span>org bar<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a link formatted to call a phone number (<code>tel:</code> link).</p>\n<ul>\n<li>Use <code>phone</code> to create a <code>&lt;a&gt;</code> element with an appropriate <code>href</code> attribute.</li>\n<li>Render the link with <code>children</code> as its content.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Callto <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> phone<span class=\"token punctuation\">,</span> children <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>a href<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">tel:</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>phone<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Callto phone<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">+</span><span class=\"token number\">302101234567</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Call me<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>Callto<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a carousel component.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>active</code> state variable and give it a value of <code>0</code> (index of the first item).</li>\n<li>Use the <code>useEffect()</code> hook to update the value of <code>active</code> to the index of the next item, using <code>setTimeout</code>.</li>\n<li>Compute the <code>className</code> for each carousel item while mapping over them and applying it accordingly.</li>\n<li>Render the carousel items using <code>React.cloneElement()</code> and pass down <code>...rest</code> along with the computed <code>className</code>.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb11\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb11-1\" title=\"1\">\n<span class=\"fu\">.carousel</span> {</a>\n<a class=\"sourceLine\" id=\"cb11-2\" title=\"2\">  <span class=\"kw\">position</span>: <span class=\"dv\">relative</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb11-3\" title=\"3\">}</a>\n<a class=\"sourceLine\" id=\"cb11-4\" title=\"4\">\n</a>\n<a class=\"sourceLine\" id=\"cb11-5\" title=\"5\">\n<span class=\"fu\">.carousel-item</span> {</a>\n<a class=\"sourceLine\" id=\"cb11-6\" title=\"6\">  <span class=\"kw\">position</span>: <span class=\"dv\">absolute</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb11-7\" title=\"7\">  <span class=\"kw\">visibility</span>: <span class=\"dv\">hidden</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb11-8\" title=\"8\">}</a>\n<a class=\"sourceLine\" id=\"cb11-9\" title=\"9\">\n</a>\n<a class=\"sourceLine\" id=\"cb11-10\" title=\"10\">\n<span class=\"fu\">.carousel-item.visible</span> {</a>\n<a class=\"sourceLine\" id=\"cb11-11\" title=\"11\">  <span class=\"kw\">visibility</span>: <span class=\"dv\">visible</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb11-12\" title=\"12\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Carousel <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> carouselItems<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>active<span class=\"token punctuation\">,</span> setActive<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> scrollInterval <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\nscrollInterval <span class=\"token operator\">=</span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setActive</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>active <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">%</span> carouselItems<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>scrollInterval<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>carousel<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>carouselItems<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> index<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> activeClass <span class=\"token operator\">=</span> active <span class=\"token operator\">===</span> index <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> visible<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">cloneElement</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n<span class=\"token operator\">...</span>rest<span class=\"token punctuation\">,</span>\n<span class=\"token literal-property property\">className</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">carousel-item</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>activeClass<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Carousel\n    carouselItems<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">[</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>carousel item <span class=\"token number\">1</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>carousel item <span class=\"token number\">2</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>carousel item <span class=\"token number\">3</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span>\n  <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a component with collapsible content.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>isCollapsed</code> state variable with an initial value of <code>collapsed</code>.</li>\n<li>Use the <code>&lt;button&gt;</code> to change the component's <code>isCollapsed</code> state and the content of the component, passed down via <code>children</code>.</li>\n<li>Determine the appearance of the content, based on <code>isCollapsed</code> and apply the appropriate <code>className</code>.</li>\n<li>Update the value of the <code>aria-expanded</code> attribute based on <code>isCollapsed</code> to make the component accessible.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb14\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb14-1\" title=\"1\">\n<span class=\"fu\">.collapse-button</span> {</a>\n<a class=\"sourceLine\" id=\"cb14-2\" title=\"2\">  <span class=\"kw\">display</span>: <span class=\"dv\">block</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb14-3\" title=\"3\">  <span class=\"kw\">width</span>: <span class=\"dv\">100</span>\n<span class=\"dt\">%</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb14-4\" title=\"4\">}</a>\n<a class=\"sourceLine\" id=\"cb14-5\" title=\"5\">\n</a>\n<a class=\"sourceLine\" id=\"cb14-6\" title=\"6\">\n<span class=\"fu\">.collapse-content.collapsed</span> {</a>\n<a class=\"sourceLine\" id=\"cb14-7\" title=\"7\">  <span class=\"kw\">display</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb14-8\" title=\"8\">}</a>\n<a class=\"sourceLine\" id=\"cb14-9\" title=\"9\">\n</a>\n<a class=\"sourceLine\" id=\"cb14-10\" title=\"10\">\n<span class=\"fu\">.collapsed-content.expanded</span> {</a>\n<a class=\"sourceLine\" id=\"cb14-11\" title=\"11\">  <span class=\"kw\">display</span>: <span class=\"dv\">block</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb14-12\" title=\"12\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Collapse <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> collapsed<span class=\"token punctuation\">,</span> children <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>isCollapsed<span class=\"token punctuation\">,</span> setIsCollapsed<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>collapsed<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button\nclassName<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>collapse<span class=\"token operator\">-</span>button<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\nonClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setIsCollapsed</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>isCollapsed<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>isCollapsed <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Show<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Hide<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span> content\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">collapse-content </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>isCollapsed <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>collapsed<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>expanded<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\naria<span class=\"token operator\">-</span>expanded<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isCollapsed<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Collapse<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>h1<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>This is a collapse<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Hello world<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>Collapse<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a controlled <code>&lt;input&gt;</code> element that uses a callback function to inform its parent about value updates.</p>\n<ul>\n<li>Use the <code>value</code> passed down from the parent as the controlled input field's value.</li>\n<li>Use the <code>onChange</code> event to fire the <code>onValueChange</code> callback and send the new value to the parent.</li>\n<li>The parent must update the input field's <code>value</code> prop in order for its value to change on user input.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> ControlledInput <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> value<span class=\"token punctuation\">,</span> onValueChange<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input\n      value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>value<span class=\"token punctuation\">}</span>\n      onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> value <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">onValueChange</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Form <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> setValue<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>ControlledInput\ntype<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>text<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\nplaceholder<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Insert some text here<span class=\"token operator\">...</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\nvalue<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>value<span class=\"token punctuation\">}</span>\nonValueChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>setValue<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Form <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a countdown timer that prints a message when it reaches zero.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create a state variable to hold the time value, initialize it from the props and destructure it into its components.</li>\n<li>Use the <code>useState()</code> hook to create the <code>paused</code> and <code>over</code> state variables, used to prevent the timer from ticking if it's paused or the time has run out.</li>\n<li>Create a method <code>tick</code>, that updates the time values based on the current value (i.e. decreasing the time by one second).</li>\n<li>Create a method <code>reset</code>, that resets all state variables to their initial states.</li>\n<li>Use the the <code>useEffect()</code> hook to call the <code>tick</code> method every second via the use of <code>setInterval()</code> and use <code>clearInterval()</code> to clean up when the component is unmounted.</li>\n<li>Use <code>String.prototype.padStart()</code> to pad each part of the time array to two characters to create the visual representation of the timer.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> CountDown <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> hours <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> minutes <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> seconds <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>paused<span class=\"token punctuation\">,</span> setPaused<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>over<span class=\"token punctuation\">,</span> setOver<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span>h<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> setTime<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>hours<span class=\"token punctuation\">,</span> minutes<span class=\"token punctuation\">,</span> seconds<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> tick <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>paused <span class=\"token operator\">||</span> over<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>h <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> m <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> s <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token function\">setOver</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>m <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> s <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>h <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">59</span><span class=\"token punctuation\">,</span> <span class=\"token number\">59</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>s <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>h<span class=\"token punctuation\">,</span> m <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">59</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>h<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">,</span> s <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> reset <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>hours<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>minutes<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>seconds<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setPaused</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setOver</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> timerID <span class=\"token operator\">=</span> <span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">clearInterval</span><span class=\"token punctuation\">(</span>timerID<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>h<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">padStart</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">0</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">:</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>m<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">padStart</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">0</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">:</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>s <span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">.</span><span class=\"token function\">padStart</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">0</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>over <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Time<span class=\"token operator\">&amp;</span>#<span class=\"token number\">39</span><span class=\"token punctuation\">;</span>s up<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setPaused</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>paused<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>paused <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Resume<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Pause<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">reset</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Restart<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>CountDown hours<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">1</span><span class=\"token punctuation\">}</span> minutes<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">45</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a list of elements from an array of primitives.</p>\n<ul>\n<li>Use the value of the <code>isOrdered</code> prop to conditionally render an <code>&lt;ol&gt;</code> or a <code>&lt;ul&gt;</code> list.</li>\n<li>Use <code>Array.prototype.map()</code> to render every item in <code>data</code> as a <code>&lt;li&gt;</code> element with an appropriate <code>key</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> DataList <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> isOrdered <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> data <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> list <span class=\"token operator\">=</span> data<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">_</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>val<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>val<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> isOrdered <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>ol<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>list<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>ol<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>ul<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>list<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> names <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>John<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Paul<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Mary<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>DataList data<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>names<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>DataList data<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>names<span class=\"token punctuation\">}</span> isOrdered <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a table with rows dynamically created from an array of primitives.</p>\n<ul>\n<li>Render a <code>&lt;table&gt;</code> element with two columns (<code>ID</code> and <code>Value</code>).</li>\n<li>Use <code>Array.prototype.map()</code> to render every item in <code>data</code> as a <code>&lt;tr&gt;</code> element with an appropriate <code>key</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> DataTable <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> data <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>table<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>thead<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>tr<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n          <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>th<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token constant\">ID</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>th<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n          <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>th<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Value<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>th<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>tr<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>thead<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>tbody<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">{</span>data<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n          <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>tr key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">_</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>val<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n            <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>td<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>td<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n            <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>td<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>val<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>td<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n          <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>tr<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>tbody<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>table<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> people <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>John<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Jesse<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>DataTable data<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>people<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a file drag and drop component for a single file.</p>\n<ul>\n<li>Create a ref, called <code>dropRef</code> and bind it to the component's wrapper.</li>\n<li>Use the <code>useState()</code> hook to create the <code>drag</code> and <code>filename</code> variables, initialized to <code>false</code> and <code>''</code> respectively.</li>\n<li>The variables <code>dragCounter</code> and <code>drag</code> are used to determine if a file is being dragged, while <code>filename</code> is used to store the dropped file's name.</li>\n<li>Create the <code>handleDrag</code>, <code>handleDragIn</code>, <code>handleDragOut</code> and <code>handleDrop</code> methods to handle drag and drop functionality.</li>\n<li>\n<code>handleDrag</code> prevents the browser from opening the dragged file, <code>handleDragIn</code> and <code>handleDragOut</code> handle the dragged file entering and exiting the component, while <code>handleDrop</code> handles the file being dropped and passes it to <code>onDrop</code>.</li>\n<li>Use the <code>useEffect()</code> hook to handle each of the drag and drop events using the previously created methods.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb25\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb25-1\" title=\"1\">\n<span class=\"fu\">.filedrop</span> {</a>\n<a class=\"sourceLine\" id=\"cb25-2\" title=\"2\">  <span class=\"kw\">min-height</span>: <span class=\"dv\">120</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb25-3\" title=\"3\">  <span class=\"kw\">border</span>: <span class=\"dv\">3</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">#d3d3d3</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb25-4\" title=\"4\">  <span class=\"kw\">text-align</span>: <span class=\"dv\">center</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb25-5\" title=\"5\">  <span class=\"kw\">font-size</span>: <span class=\"dv\">24</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb25-6\" title=\"6\">  <span class=\"kw\">padding</span>: <span class=\"dv\">32</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb25-7\" title=\"7\">  <span class=\"kw\">border-radius</span>: <span class=\"dv\">4</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb25-8\" title=\"8\">}</a>\n<a class=\"sourceLine\" id=\"cb25-9\" title=\"9\">\n</a>\n<a class=\"sourceLine\" id=\"cb25-10\" title=\"10\">\n<span class=\"fu\">.filedrop.drag</span> {</a>\n<a class=\"sourceLine\" id=\"cb25-11\" title=\"11\">  <span class=\"kw\">border</span>: <span class=\"dv\">3</span>\n<span class=\"dt\">px</span> <span class=\"dv\">dashed</span> <span class=\"cn\">#1e90ff</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb25-12\" title=\"12\">}</a>\n<a class=\"sourceLine\" id=\"cb25-13\" title=\"13\">\n</a>\n<a class=\"sourceLine\" id=\"cb25-14\" title=\"14\">\n<span class=\"fu\">.filedrop.ready</span> {</a>\n<a class=\"sourceLine\" id=\"cb25-15\" title=\"15\">  <span class=\"kw\">border</span>: <span class=\"dv\">3</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">#32cd32</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb25-16\" title=\"16\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> FileDrop <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> onDrop <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>drag<span class=\"token punctuation\">,</span> setDrag<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>filename<span class=\"token punctuation\">,</span> setFilename<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> dropRef <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">createRef</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> dragCounter <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> handleDrag <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\ne<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ne<span class=\"token punctuation\">.</span><span class=\"token function\">stopPropagation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> handleDragIn <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\ne<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ne<span class=\"token punctuation\">.</span><span class=\"token function\">stopPropagation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndragCounter<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>dataTransfer<span class=\"token punctuation\">.</span>items <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> e<span class=\"token punctuation\">.</span>dataTransfer<span class=\"token punctuation\">.</span>items<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token function\">setDrag</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> handleDragOut <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\ne<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ne<span class=\"token punctuation\">.</span><span class=\"token function\">stopPropagation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndragCounter<span class=\"token operator\">--</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>dragCounter <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token function\">setDrag</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> handleDrop <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\ne<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ne<span class=\"token punctuation\">.</span><span class=\"token function\">stopPropagation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setDrag</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>dataTransfer<span class=\"token punctuation\">.</span>files <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> e<span class=\"token punctuation\">.</span>dataTransfer<span class=\"token punctuation\">.</span>files<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">onDrop</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>dataTransfer<span class=\"token punctuation\">.</span>files<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setFilename</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>dataTransfer<span class=\"token punctuation\">.</span>files<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ne<span class=\"token punctuation\">.</span>dataTransfer<span class=\"token punctuation\">.</span><span class=\"token function\">clearData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndragCounter <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> div <span class=\"token operator\">=</span> dropRef<span class=\"token punctuation\">.</span>current<span class=\"token punctuation\">;</span>\ndiv<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>dragenter<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleDragIn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndiv<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>dragleave<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleDragOut<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndiv<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>dragover<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleDrag<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndiv<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>drop<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleDrop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\ndiv<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>dragenter<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleDragIn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndiv<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>dragleave<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleDragOut<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndiv<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>dragover<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleDrag<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndiv<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>drop<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleDrop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\nref<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>dropRef<span class=\"token punctuation\">}</span>\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>\ndrag <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>filedrop drag<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> filename <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>filedrop ready<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>filedrop<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>filename <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">!</span>drag <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>filename<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Drop a file here<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>FileDrop onDrop<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a textarea component with a character limit.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>content</code> state variable and set its value to that of <code>value</code> prop, trimmed down to <code>limit</code> characters.</li>\n<li>Create a method <code>setFormattedContent</code>, which trims the content down to <code>limit</code> characters and memoize it, using the <code>useCallback()</code> hook.</li>\n<li>Bind the <code>onChange</code> event of the <code>&lt;textarea&gt;</code> to call <code>setFormattedContent</code> with the value of the fired event.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> LimitedTextarea <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> rows<span class=\"token punctuation\">,</span> cols<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">,</span> limit <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>content<span class=\"token punctuation\">,</span> setContent<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> limit<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> setFormattedContent <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useCallback</span><span class=\"token punctuation\">(</span>\n<span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setContent</span><span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> limit<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">[</span>limit<span class=\"token punctuation\">,</span> setContent<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>textarea\nrows<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>rows<span class=\"token punctuation\">}</span>\ncols<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>cols<span class=\"token punctuation\">}</span>\nonChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setFormattedContent</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\nvalue<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>content<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>content<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">}</span><span class=\"token operator\">/</span><span class=\"token punctuation\">{</span>limit<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>LimitedTextarea limit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">32</span><span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Hello<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a textarea component with a word limit.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create a state variable, containing <code>content</code> and <code>wordCount</code>, using the <code>value</code> prop and <code>0</code> as the initial values respectively.</li>\n<li>Use the <code>useCallback()</code> hooks to create a memoized function, <code>setFormattedContent</code>, that uses <code>String.prototype.split()</code> to turn the input into an array of words.</li>\n<li>Check if the result of applying <code>Array.prototype.filter()</code> combined with <code>Boolean</code> has a <code>length</code> longer than <code>limit</code> and, if so, trim the input, otherwise return the raw input, updating state accordingly in both cases.</li>\n<li>Use the <code>useEffect()</code> hook to call the <code>setFormattedContent</code> method on the value of the <code>content</code> state variable during the initial render.</li>\n<li>Bind the <code>onChange</code> event of the <code>&lt;textarea&gt;</code> to call <code>setFormattedContent</code> with the value of <code>event.target.value</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> LimitedWordTextarea <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> rows<span class=\"token punctuation\">,</span> cols<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">,</span> limit <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> content<span class=\"token punctuation\">,</span> wordCount <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> setContent<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> value<span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">wordCount</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> setFormattedContent <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useCallback</span><span class=\"token punctuation\">(</span>\n<span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> words <span class=\"token operator\">=</span> text<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span>Boolean<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>words<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> limit<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setContent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n<span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> words<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> limit<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token literal-property property\">wordCount</span><span class=\"token operator\">:</span> limit<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setContent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> text<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">wordCount</span><span class=\"token operator\">:</span> words<span class=\"token punctuation\">.</span>length <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">[</span>limit<span class=\"token punctuation\">,</span> setContent<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setFormattedContent</span><span class=\"token punctuation\">(</span>content<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>textarea\nrows<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>rows<span class=\"token punctuation\">}</span>\ncols<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>cols<span class=\"token punctuation\">}</span>\nonChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setFormattedContent</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\nvalue<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>content<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>wordCount<span class=\"token punctuation\">}</span><span class=\"token operator\">/</span><span class=\"token punctuation\">{</span>limit<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>LimitedWordTextarea limit<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">5</span><span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Hello there<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a spinning loader component.</p>\n<ul>\n<li>Render an SVG, whose <code>height</code> and <code>width</code> are determined by the <code>size</code> prop.</li>\n<li>Use CSS to animate the SVG, creating a spinning animation.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb32\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb32-1\" title=\"1\">\n<span class=\"fu\">.loader</span> {</a>\n<a class=\"sourceLine\" id=\"cb32-2\" title=\"2\">  <span class=\"kw\">animation</span>: rotate <span class=\"dv\">2</span>\n<span class=\"dt\">s</span> <span class=\"dv\">linear</span> <span class=\"dv\">infinite</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-3\" title=\"3\">}</a>\n<a class=\"sourceLine\" id=\"cb32-4\" title=\"4\">\n</a>\n<a class=\"sourceLine\" id=\"cb32-5\" title=\"5\">\n<span class=\"im\">@keyframes</span> rotate {</a>\n<a class=\"sourceLine\" id=\"cb32-6\" title=\"6\">  <span class=\"dv\">100%</span> {</a>\n<a class=\"sourceLine\" id=\"cb32-7\" title=\"7\">    <span class=\"kw\">transform</span>: <span class=\"fu\">rotate(</span>\n<span class=\"dv\">360</span>\n<span class=\"dt\">deg</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-8\" title=\"8\">  }</a>\n<a class=\"sourceLine\" id=\"cb32-9\" title=\"9\">}</a>\n<a class=\"sourceLine\" id=\"cb32-10\" title=\"10\">\n</a>\n<a class=\"sourceLine\" id=\"cb32-11\" title=\"11\">\n<span class=\"fu\">.loader</span> circle {</a>\n<a class=\"sourceLine\" id=\"cb32-12\" title=\"12\">  <span class=\"kw\">animation</span>: dash <span class=\"dv\">1.5</span>\n<span class=\"dt\">s</span> <span class=\"dv\">ease-in-out</span> <span class=\"dv\">infinite</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-13\" title=\"13\">}</a>\n<a class=\"sourceLine\" id=\"cb32-14\" title=\"14\">\n</a>\n<a class=\"sourceLine\" id=\"cb32-15\" title=\"15\">\n<span class=\"im\">@keyframes</span> dash {</a>\n<a class=\"sourceLine\" id=\"cb32-16\" title=\"16\">  <span class=\"dv\">0%</span> {</a>\n<a class=\"sourceLine\" id=\"cb32-17\" title=\"17\">    stroke-dasharray: <span class=\"dv\">1</span>\n<span class=\"op\">,</span> <span class=\"dv\">150</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-18\" title=\"18\">    stroke-dashoffset: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-19\" title=\"19\">  }</a>\n<a class=\"sourceLine\" id=\"cb32-20\" title=\"20\">  <span class=\"dv\">50%</span> {</a>\n<a class=\"sourceLine\" id=\"cb32-21\" title=\"21\">    stroke-dasharray: <span class=\"dv\">90</span>\n<span class=\"op\">,</span> <span class=\"dv\">150</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-22\" title=\"22\">    stroke-dashoffset: <span class=\"dv\">-35</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-23\" title=\"23\">  }</a>\n<a class=\"sourceLine\" id=\"cb32-24\" title=\"24\">  <span class=\"dv\">100%</span> {</a>\n<a class=\"sourceLine\" id=\"cb32-25\" title=\"25\">    stroke-dasharray: <span class=\"dv\">90</span>\n<span class=\"op\">,</span> <span class=\"dv\">150</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-26\" title=\"26\">    stroke-dashoffset: <span class=\"dv\">-124</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb32-27\" title=\"27\">  }</a>\n<a class=\"sourceLine\" id=\"cb32-28\" title=\"28\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Loader <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> size <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>svg\n      className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>loader<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      xmlns<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>http<span class=\"token operator\">:</span><span class=\"token operator\">/</span><span class=\"token operator\">/</span>www<span class=\"token punctuation\">.</span>w3<span class=\"token punctuation\">.</span>org<span class=\"token operator\">/</span><span class=\"token number\">2000</span><span class=\"token operator\">/</span>svg<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      width<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>size<span class=\"token punctuation\">}</span>\n      height<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>size<span class=\"token punctuation\">}</span>\n      viewBox<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">0</span> <span class=\"token number\">0</span> <span class=\"token number\">24</span> <span class=\"token number\">24</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      fill<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>none<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      stroke<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>currentColor<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      strokeWidth<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">2</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      strokeLinecap<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>round<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      strokeLinejoin<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>round<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>circle cx<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">12</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> cy<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">12</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> r<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">10</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>svg<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Loader size<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">24</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a link formatted to send an email (<code>mailto:</code> link).</p>\n<ul>\n<li>Use the <code>email</code>, <code>subject</code> and <code>body</code> props to create a <code>&lt;a&gt;</code> element with an appropriate <code>href</code> attribute.</li>\n<li>Use <code>encodeURIcomponent</code> to safely encode the <code>subject</code> and <code>body</code> into the link URL.</li>\n<li>Render the link with <code>children</code> as its content.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Mailto <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> email<span class=\"token punctuation\">,</span> subject <span class=\"token operator\">=</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> body <span class=\"token operator\">=</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> children <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> params <span class=\"token operator\">=</span> subject <span class=\"token operator\">||</span> body <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">?</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>subject<span class=\"token punctuation\">)</span> params <span class=\"token operator\">+=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">subject=</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token function\">encodeURIComponent</span><span class=\"token punctuation\">(</span>subject<span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>body<span class=\"token punctuation\">)</span> params <span class=\"token operator\">+=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>subject <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">body=</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token function\">encodeURIComponent</span><span class=\"token punctuation\">(</span>body<span class=\"token punctuation\">)</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>a href<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">mailto:</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>email<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>params<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Mailto email<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>foo@bar<span class=\"token punctuation\">.</span>baz<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> subject<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Hello <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> Welcome<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> body<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Hello world<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    Mail me<span class=\"token operator\">!</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>Mailto<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a table with rows dynamically created from an array of objects and a list of property names.</p>\n<ul>\n<li>Use <code>Object.keys()</code>, <code>Array.prototype.filter()</code>, <code>Array.prototype.includes()</code> and <code>Array.prototype.reduce()</code> to produce a <code>filteredData</code> array, containing all objects with the keys specified in <code>propertyNames</code>.</li>\n<li>Render a <code>&lt;table&gt;</code> element with a set of columns equal to the amount of values in <code>propertyNames</code>.</li>\n<li>Use <code>Array.prototype.map()</code> to render each value in the <code>propertyNames</code> array as a <code>&lt;th&gt;</code> element.</li>\n<li>Use <code>Array.prototype.map()</code> to render each object in the <code>filteredData</code> array as a <code>&lt;tr&gt;</code> element, containing a <code>&lt;td&gt;</code> for each key in the object.</li>\n</ul>\n<p>\n<em>This component does not work with nested objects and will break if there are nested objects inside any of the properties specified in <code>propertyNames</code>\n</em>\n</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> MappedTable <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> data<span class=\"token punctuation\">,</span> propertyNames <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> filteredData <span class=\"token operator\">=</span> data<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">)</span>\n      <span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> propertyNames<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n      <span class=\"token punctuation\">.</span><span class=\"token function\">reduce</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>acc<span class=\"token punctuation\">,</span> key<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>acc<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> v<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> acc<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>table<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>thead<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>tr<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">{</span>propertyNames<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>th key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">h_</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>val<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>val<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>th<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>tr<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>thead<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>tbody<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">{</span>filteredData<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n          <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>tr key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">i_</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">{</span>propertyNames<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>p<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n              <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>td key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">i_</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">_</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>p<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>val<span class=\"token punctuation\">[</span>p<span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>td<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n          <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>tr<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>tbody<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>table<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> people <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>John<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">surname</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Smith<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">42</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Adam<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">surname</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Smith<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">gender</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>male<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> propertyNames <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>name<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>surname<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>age<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>MappedTable data<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>people<span class=\"token punctuation\">}</span> propertyNames<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>propertyNames<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a Modal component, controllable through events.</p>\n<ul>\n<li>Define <code>keydownHandler</code>, a method which handles all keyboard events and is used to call <code>onClose</code> when the <code>Esc</code> key is pressed.</li>\n<li>Use the <code>useEffect()</code> hook to add or remove the <code>keydown</code> event listener to the <code>document</code>, calling <code>keydownHandler</code> for every event.</li>\n<li>Add a styled <code>&lt;span&gt;</code> element that acts as a close button, calling <code>onClose</code> when clicked.</li>\n<li>Use the <code>isVisible</code> prop passed down from the parent to determine if the modal should be displayed or not.</li>\n<li>To use the component, import <code>Modal</code> only once and then display it by passing a boolean value to the <code>isVisible</code> attribute.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb39\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb39-1\" title=\"1\">\n<span class=\"fu\">.modal</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-2\" title=\"2\">  <span class=\"kw\">position</span>: <span class=\"dv\">fixed</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-3\" title=\"3\">  <span class=\"kw\">top</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-4\" title=\"4\">  <span class=\"kw\">bottom</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-5\" title=\"5\">  <span class=\"kw\">left</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-6\" title=\"6\">  <span class=\"kw\">right</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-7\" title=\"7\">  <span class=\"kw\">width</span>: <span class=\"dv\">100</span>\n<span class=\"dt\">%</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-8\" title=\"8\">  <span class=\"kw\">z-index</span>: <span class=\"dv\">9999</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-9\" title=\"9\">  <span class=\"kw\">display</span>: flex<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-10\" title=\"10\">  <span class=\"kw\">align-items</span>: <span class=\"dv\">center</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-11\" title=\"11\">  <span class=\"kw\">justify-content</span>: <span class=\"dv\">center</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-12\" title=\"12\">  <span class=\"kw\">background-color</span>: <span class=\"fu\">rgba(</span>\n<span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0.25</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-13\" title=\"13\">  <span class=\"kw\">animation-name</span>: appear<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-14\" title=\"14\">  <span class=\"kw\">animation-duration</span>: <span class=\"dv\">300</span>\n<span class=\"dt\">ms</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-15\" title=\"15\">}</a>\n<a class=\"sourceLine\" id=\"cb39-16\" title=\"16\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-17\" title=\"17\">\n<span class=\"fu\">.modal-dialog</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-18\" title=\"18\">  <span class=\"kw\">width</span>: <span class=\"dv\">100</span>\n<span class=\"dt\">%</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-19\" title=\"19\">  <span class=\"kw\">max-width</span>: <span class=\"dv\">550</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-20\" title=\"20\">  <span class=\"kw\">background</span>: <span class=\"cn\">white</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-21\" title=\"21\">  <span class=\"kw\">position</span>: <span class=\"dv\">relative</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-22\" title=\"22\">  <span class=\"kw\">margin</span>: <span class=\"dv\">0</span> <span class=\"dv\">20</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-23\" title=\"23\">  <span class=\"kw\">max-height</span>: <span class=\"fu\">calc(</span>\n<span class=\"dv\">100</span>\n<span class=\"dt\">vh</span> <span class=\"op\">-</span> <span class=\"dv\">40</span>\n<span class=\"dt\">px</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-24\" title=\"24\">  <span class=\"kw\">text-align</span>: <span class=\"dv\">left</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-25\" title=\"25\">  <span class=\"kw\">display</span>: flex<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-26\" title=\"26\">  <span class=\"kw\">flex-direction</span>: column<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-27\" title=\"27\">  <span class=\"kw\">overflow</span>: <span class=\"dv\">hidden</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-28\" title=\"28\">  <span class=\"kw\">box-shadow</span>: <span class=\"dv\">0</span> <span class=\"dv\">4</span>\n<span class=\"dt\">px</span> <span class=\"dv\">8</span>\n<span class=\"dt\">px</span> <span class=\"dv\">0</span> <span class=\"fu\">rgba(</span>\n<span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0.2</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span> <span class=\"dv\">6</span>\n<span class=\"dt\">px</span> <span class=\"dv\">20</span>\n<span class=\"dt\">px</span> <span class=\"dv\">0</span> <span class=\"fu\">rgba(</span>\n<span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0.19</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-29\" title=\"29\">  <span class=\"kw\">-webkit-animation-name</span>: animatetop<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-30\" title=\"30\">  <span class=\"kw\">-webkit-animation-duration</span>: <span class=\"dv\">0.4</span>\n<span class=\"dt\">s</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-31\" title=\"31\">  <span class=\"kw\">animation-name</span>: slide-in<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-32\" title=\"32\">  <span class=\"kw\">animation-duration</span>: <span class=\"dv\">0.5</span>\n<span class=\"dt\">s</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-33\" title=\"33\">}</a>\n<a class=\"sourceLine\" id=\"cb39-34\" title=\"34\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-35\" title=\"35\">\n<span class=\"fu\">.modal-header</span>\n<span class=\"op\">,</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-36\" title=\"36\">\n<span class=\"fu\">.modal-footer</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-37\" title=\"37\">  <span class=\"kw\">display</span>: flex<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-38\" title=\"38\">  <span class=\"kw\">align-items</span>: <span class=\"dv\">center</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-39\" title=\"39\">  <span class=\"kw\">padding</span>: <span class=\"dv\">1</span>\n<span class=\"dt\">rem</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-40\" title=\"40\">}</a>\n<a class=\"sourceLine\" id=\"cb39-41\" title=\"41\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-42\" title=\"42\">\n<span class=\"fu\">.modal-header</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-43\" title=\"43\">  <span class=\"kw\">border-bottom</span>: <span class=\"dv\">1</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">#dbdbdb</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-44\" title=\"44\">  <span class=\"kw\">justify-content</span>: space-between<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-45\" title=\"45\">}</a>\n<a class=\"sourceLine\" id=\"cb39-46\" title=\"46\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-47\" title=\"47\">\n<span class=\"fu\">.modal-footer</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-48\" title=\"48\">  <span class=\"kw\">border-top</span>: <span class=\"dv\">1</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">#dbdbdb</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-49\" title=\"49\">  <span class=\"kw\">justify-content</span>: flex-end<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-50\" title=\"50\">}</a>\n<a class=\"sourceLine\" id=\"cb39-51\" title=\"51\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-52\" title=\"52\">\n<span class=\"fu\">.modal-close</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-53\" title=\"53\">  <span class=\"kw\">cursor</span>: <span class=\"dv\">pointer</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-54\" title=\"54\">  <span class=\"kw\">padding</span>: <span class=\"dv\">1</span>\n<span class=\"dt\">rem</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-55\" title=\"55\">  <span class=\"kw\">margin</span>: <span class=\"dv\">-1</span>\n<span class=\"dt\">rem</span> <span class=\"dv\">-1</span>\n<span class=\"dt\">rem</span> <span class=\"dv\">-1</span>\n<span class=\"dt\">rem</span> <span class=\"bu\">auto</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-56\" title=\"56\">}</a>\n<a class=\"sourceLine\" id=\"cb39-57\" title=\"57\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-58\" title=\"58\">\n<span class=\"fu\">.modal-body</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-59\" title=\"59\">  <span class=\"kw\">overflow</span>: <span class=\"bu\">auto</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-60\" title=\"60\">}</a>\n<a class=\"sourceLine\" id=\"cb39-61\" title=\"61\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-62\" title=\"62\">\n<span class=\"fu\">.modal-content</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-63\" title=\"63\">  <span class=\"kw\">padding</span>: <span class=\"dv\">1</span>\n<span class=\"dt\">rem</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-64\" title=\"64\">}</a>\n<a class=\"sourceLine\" id=\"cb39-65\" title=\"65\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-66\" title=\"66\">\n<span class=\"im\">@keyframes</span> appear {</a>\n<a class=\"sourceLine\" id=\"cb39-67\" title=\"67\">  <span class=\"dv\">from</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-68\" title=\"68\">    <span class=\"kw\">opacity</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-69\" title=\"69\">  }</a>\n<a class=\"sourceLine\" id=\"cb39-70\" title=\"70\">  <span class=\"dv\">to</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-71\" title=\"71\">    <span class=\"kw\">opacity</span>: <span class=\"dv\">1</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-72\" title=\"72\">  }</a>\n<a class=\"sourceLine\" id=\"cb39-73\" title=\"73\">}</a>\n<a class=\"sourceLine\" id=\"cb39-74\" title=\"74\">\n</a>\n<a class=\"sourceLine\" id=\"cb39-75\" title=\"75\">\n<span class=\"im\">@keyframes</span> slide-in {</a>\n<a class=\"sourceLine\" id=\"cb39-76\" title=\"76\">  <span class=\"dv\">from</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-77\" title=\"77\">    <span class=\"kw\">transform</span>: translateY(<span class=\"dv\">-150</span>\n<span class=\"dt\">px</span>)<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-78\" title=\"78\">  }</a>\n<a class=\"sourceLine\" id=\"cb39-79\" title=\"79\">  <span class=\"dv\">to</span> {</a>\n<a class=\"sourceLine\" id=\"cb39-80\" title=\"80\">    <span class=\"kw\">transform</span>: translateY(<span class=\"dv\">0</span>)<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb39-81\" title=\"81\">  }</a>\n<a class=\"sourceLine\" id=\"cb39-82\" title=\"82\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Modal <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> isVisible <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> title<span class=\"token punctuation\">,</span> content<span class=\"token punctuation\">,</span> footer<span class=\"token punctuation\">,</span> onClose <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> keydownHandler <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> key <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">case</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Escape<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">:</span>\n        <span class=\"token function\">onClose</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>keydown<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> keydownHandler<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>keydown<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> keydownHandler<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">!</span>isVisible <span class=\"token operator\">?</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>modal<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>onClose<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>modal<span class=\"token operator\">-</span>dialog<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">stopPropagation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>modal<span class=\"token operator\">-</span>header<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>h3 className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>modal<span class=\"token operator\">-</span>title<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>title<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>h3<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>modal<span class=\"token operator\">-</span>close<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>onClose<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span>times<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>modal<span class=\"token operator\">-</span>body<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>modal<span class=\"token operator\">-</span>content<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>content<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>footer <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>modal<span class=\"token operator\">-</span>footer<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>footer<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> App <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>isModal<span class=\"token punctuation\">,</span> setModal<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setModal</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Click Here<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Modal\n        isVisible<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isModal<span class=\"token punctuation\">}</span>\n        title<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Modal Title<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n        content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Add your content here<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n        footer<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Cancel<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n        onClose<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setModal</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>App <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a checkbox list that uses a callback function to pass its selected value/values to the parent component.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>data</code> state variable and use the <code>options</code> prop to initialize its value.</li>\n<li>Create a <code>toggle</code> function that uses the spread operator (<code>...</code>) and <code>Array.prototype.splice()</code> to update the <code>data</code> state variable and call the <code>onChange</code> callback with any <code>checked</code> options.</li>\n<li>Use <code>Array.prototype.map()</code> to map the <code>data</code> state variable to individual <code>&lt;input type=\"checkbox\"&gt;</code> elements, each one wrapped in a <code>&lt;label&gt;</code>, binding the <code>onClick</code> handler to the <code>toggle</code> function.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> MultiselectCheckbox <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> options<span class=\"token punctuation\">,</span> onChange <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>data<span class=\"token punctuation\">,</span> setData<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>options<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> toggle <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> newData <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>data<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nnewData<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n<span class=\"token literal-property property\">label</span><span class=\"token operator\">:</span> data<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>label<span class=\"token punctuation\">,</span>\n<span class=\"token literal-property property\">checked</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span>data<span class=\"token punctuation\">[</span>index<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>checked<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setData</span><span class=\"token punctuation\">(</span>newData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">onChange</span><span class=\"token punctuation\">(</span>newData<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> x<span class=\"token punctuation\">.</span>checked<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>data<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> index<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>label key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>label<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input\nreadOnly\ntype<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>checkbox<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\nchecked<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>checked <span class=\"token operator\">||</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">}</span>\nonClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">toggle</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>item<span class=\"token punctuation\">.</span>label<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> options <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">label</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Item One<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">label</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Item Two<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>MultiselectCheckbox\noptions<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>options<span class=\"token punctuation\">}</span>\nonChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a password input field with a reveal button.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>shown</code> state variable and set its value to <code>false</code>.</li>\n<li>When the <code>&lt;button&gt;</code> is clicked, execute <code>setShown</code>, toggling the <code>type</code> of the <code>&lt;input&gt;</code> between <code>\"text\"</code> and <code>\"password\"</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> PasswordRevealer <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>shown<span class=\"token punctuation\">,</span> setShown<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input type<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>shown <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>text<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>password<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>value<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setShown</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>shown<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Show<span class=\"token operator\">/</span>Hide<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>PasswordRevealer <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a button that animates a ripple effect when clicked.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>coords</code> and <code>isRippling</code> state variables for the pointer's coordinates and the animation state of the button respectively.</li>\n<li>Use a <code>useEffect()</code> hook to change the value of <code>isRippling</code> every time the <code>coords</code> state variable changes, starting the animation.</li>\n<li>Use <code>setTimeout()</code> in the previous hook to clear the animation after it's done playing.</li>\n<li>Use a <code>useEffect()</code> hook to reset <code>coords</code> whenever the <code>isRippling</code> state variable is <code>false.</code>\n</li>\n<li>Handle the <code>onClick</code> event by updating the <code>coords</code> state variable and calling the passed callback.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb46\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb46-1\" title=\"1\">\n<span class=\"fu\">.ripple-button</span> {</a>\n<a class=\"sourceLine\" id=\"cb46-2\" title=\"2\">  <span class=\"kw\">border-radius</span>: <span class=\"dv\">4</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-3\" title=\"3\">  <span class=\"kw\">border</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-4\" title=\"4\">  <span class=\"kw\">margin</span>: <span class=\"dv\">8</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-5\" title=\"5\">  <span class=\"kw\">padding</span>: <span class=\"dv\">14</span>\n<span class=\"dt\">px</span> <span class=\"dv\">24</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-6\" title=\"6\">  <span class=\"kw\">background</span>: <span class=\"cn\">#1976d2</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-7\" title=\"7\">  <span class=\"kw\">color</span>: <span class=\"cn\">#fff</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-8\" title=\"8\">  <span class=\"kw\">overflow</span>: <span class=\"dv\">hidden</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-9\" title=\"9\">  <span class=\"kw\">position</span>: <span class=\"dv\">relative</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-10\" title=\"10\">  <span class=\"kw\">cursor</span>: <span class=\"dv\">pointer</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-11\" title=\"11\">}</a>\n<a class=\"sourceLine\" id=\"cb46-12\" title=\"12\">\n</a>\n<a class=\"sourceLine\" id=\"cb46-13\" title=\"13\">\n<span class=\"fu\">.ripple-button</span> <span class=\"op\">&gt;</span> <span class=\"fu\">.ripple</span> {</a>\n<a class=\"sourceLine\" id=\"cb46-14\" title=\"14\">  <span class=\"kw\">width</span>: <span class=\"dv\">20</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-15\" title=\"15\">  <span class=\"kw\">height</span>: <span class=\"dv\">20</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-16\" title=\"16\">  <span class=\"kw\">position</span>: <span class=\"dv\">absolute</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-17\" title=\"17\">  <span class=\"kw\">background</span>: <span class=\"cn\">#63a4ff</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-18\" title=\"18\">  <span class=\"kw\">display</span>: <span class=\"dv\">block</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-19\" title=\"19\">  <span class=\"kw\">content</span>: <span class=\"st\">&quot;&quot;</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-20\" title=\"20\">  <span class=\"kw\">border-radius</span>: <span class=\"dv\">9999</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-21\" title=\"21\">  <span class=\"kw\">opacity</span>: <span class=\"dv\">1</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-22\" title=\"22\">  <span class=\"kw\">animation</span>: <span class=\"dv\">0.9</span>\n<span class=\"dt\">s</span> <span class=\"dv\">ease</span> <span class=\"dv\">1</span> <span class=\"dv\">forwards</span> ripple-effect<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-23\" title=\"23\">}</a>\n<a class=\"sourceLine\" id=\"cb46-24\" title=\"24\">\n</a>\n<a class=\"sourceLine\" id=\"cb46-25\" title=\"25\">\n<span class=\"im\">@keyframes</span> ripple-effect {</a>\n<a class=\"sourceLine\" id=\"cb46-26\" title=\"26\">  <span class=\"dv\">0%</span> {</a>\n<a class=\"sourceLine\" id=\"cb46-27\" title=\"27\">    <span class=\"kw\">transform</span>: <span class=\"fu\">scale(</span>\n<span class=\"dv\">1</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-28\" title=\"28\">    <span class=\"kw\">opacity</span>: <span class=\"dv\">1</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-29\" title=\"29\">  }</a>\n<a class=\"sourceLine\" id=\"cb46-30\" title=\"30\">  <span class=\"dv\">50%</span> {</a>\n<a class=\"sourceLine\" id=\"cb46-31\" title=\"31\">    <span class=\"kw\">transform</span>: <span class=\"fu\">scale(</span>\n<span class=\"dv\">10</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-32\" title=\"32\">    <span class=\"kw\">opacity</span>: <span class=\"dv\">0.375</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-33\" title=\"33\">  }</a>\n<a class=\"sourceLine\" id=\"cb46-34\" title=\"34\">  <span class=\"dv\">100%</span> {</a>\n<a class=\"sourceLine\" id=\"cb46-35\" title=\"35\">    <span class=\"kw\">transform</span>: <span class=\"fu\">scale(</span>\n<span class=\"dv\">35</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-36\" title=\"36\">    <span class=\"kw\">opacity</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-37\" title=\"37\">  }</a>\n<a class=\"sourceLine\" id=\"cb46-38\" title=\"38\">}</a>\n<a class=\"sourceLine\" id=\"cb46-39\" title=\"39\">\n</a>\n<a class=\"sourceLine\" id=\"cb46-40\" title=\"40\">\n<span class=\"fu\">.ripple-button</span> <span class=\"op\">&gt;</span> <span class=\"fu\">.content</span> {</a>\n<a class=\"sourceLine\" id=\"cb46-41\" title=\"41\">  <span class=\"kw\">position</span>: <span class=\"dv\">relative</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-42\" title=\"42\">  <span class=\"kw\">z-index</span>: <span class=\"dv\">2</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb46-43\" title=\"43\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> RippleButton <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> children<span class=\"token punctuation\">,</span> onClick <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>coords<span class=\"token punctuation\">,</span> setCoords<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">x</span><span class=\"token operator\">:</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">y</span><span class=\"token operator\">:</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>isRippling<span class=\"token punctuation\">,</span> setIsRippling<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>coords<span class=\"token punctuation\">.</span>x <span class=\"token operator\">!==</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> coords<span class=\"token punctuation\">.</span>y <span class=\"token operator\">!==</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setIsRippling</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setIsRippling</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">300</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token function\">setIsRippling</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>coords<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>isRippling<span class=\"token punctuation\">)</span> <span class=\"token function\">setCoords</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">x</span><span class=\"token operator\">:</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">y</span><span class=\"token operator\">:</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>isRippling<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button\nclassName<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>ripple<span class=\"token operator\">-</span>button<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\nonClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> rect <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">getBoundingClientRect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setCoords</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">x</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>clientX <span class=\"token operator\">-</span> rect<span class=\"token punctuation\">.</span>left<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">y</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>clientY <span class=\"token operator\">-</span> rect<span class=\"token punctuation\">.</span>top <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nonClick <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token function\">onClick</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>isRippling <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span\nclassName<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>ripple<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\nstyle<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">left</span><span class=\"token operator\">:</span> coords<span class=\"token punctuation\">.</span>x<span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">top</span><span class=\"token operator\">:</span> coords<span class=\"token punctuation\">.</span>y<span class=\"token punctuation\">,</span>\n          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>content<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>RippleButton onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Click me<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>RippleButton<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders an uncontrolled <code>&lt;select&gt;</code> element that uses a callback function to pass its value to the parent component.</p>\n<ul>\n<li>Use the the <code>selectedValue</code> prop as the <code>defaultValue</code> of the <code>&lt;select&gt;</code> element to set its initial value..</li>\n<li>Use the <code>onChange</code> event to fire the <code>onValueChange</code> callback and send the new value to the parent.</li>\n<li>Use <code>Array.prototype.map()</code> on the <code>values</code> array to create an <code>&lt;option&gt;</code> element for each passed value.</li>\n<li>Each item in <code>values</code> must be a 2-element array, where the first element is the <code>value</code> of the item and the second one is the displayed text for it.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Select <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> values<span class=\"token punctuation\">,</span> onValueChange<span class=\"token punctuation\">,</span> selectedValue<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>select\n      defaultValue<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>selectedValue<span class=\"token punctuation\">}</span>\n      onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> value <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">onValueChange</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">{</span>values<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> text<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>option key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>value<span class=\"token punctuation\">}</span> value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>value<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">{</span>text<span class=\"token punctuation\">}</span>\n        <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>option<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>select<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> choices <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n  <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>grapefruit<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Grapefruit<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>lime<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Lime<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>coconut<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Coconut<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>mango<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Mango<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Select\n    values<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>choices<span class=\"token punctuation\">}</span>\n    selectedValue<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>lime<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n    onValueChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n  <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders an uncontrolled range input element that uses a callback function to pass its value to the parent component.</p>\n<ul>\n<li>Set the <code>type</code> of the <code>&lt;input&gt;</code> element to <code>\"range\"</code> to create a slider.</li>\n<li>Use the <code>defaultValue</code> passed down from the parent as the uncontrolled input field's initial value.</li>\n<li>Use the <code>onChange</code> event to fire the <code>onValueChange</code> callback and send the new value to the parent.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Slider <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n  min <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n  max <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span>\n  defaultValue<span class=\"token punctuation\">,</span>\n  onValueChange<span class=\"token punctuation\">,</span>\n  <span class=\"token operator\">...</span>rest\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input\n      type<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>range<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      min<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>min<span class=\"token punctuation\">}</span>\n      max<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>max<span class=\"token punctuation\">}</span>\n      defaultValue<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>defaultValue<span class=\"token punctuation\">}</span>\n      onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> value <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">onValueChange</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Slider onValueChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a star rating component.</p>\n<ul>\n<li>Define a component, called <code>Star</code> that will render each individual star with the appropriate appearance, based on the parent component's state.</li>\n<li>In the <code>StarRating</code> component, use the <code>useState()</code> hook to define the <code>rating</code> and <code>selection</code> state variables with the appropriate initial values.</li>\n<li>Create a method, <code>hoverOver</code>, that updates <code>selected</code> according to the provided <code>event</code>, using the .<code>data-star-id</code> attribute of the event's target or resets it to <code>0</code> if called with a <code>null</code> argument.</li>\n<li>Use <code>Array.from()</code> to create an array of <code>5</code> elements and <code>Array.prototype.map()</code> to create individual <code>&lt;Star&gt;</code> components.</li>\n<li>Handle the <code>onMouseOver</code> and <code>onMouseLeave</code> events of the wrapping element using <code>hoverOver</code> and the <code>onClick</code> event using <code>setRating</code>.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb53\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb53-1\" title=\"1\">\n<span class=\"fu\">.star</span> {</a>\n<a class=\"sourceLine\" id=\"cb53-2\" title=\"2\">  <span class=\"kw\">color</span>: <span class=\"cn\">#ff9933</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb53-3\" title=\"3\">  <span class=\"kw\">cursor</span>: <span class=\"dv\">pointer</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb53-4\" title=\"4\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Star <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> marked<span class=\"token punctuation\">,</span> starId <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span data<span class=\"token operator\">-</span>star<span class=\"token operator\">-</span>id<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>starId<span class=\"token punctuation\">}</span> className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>star<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> role<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>button<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">{</span>marked <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\\u2605<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\\u2606<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> StarRating <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>rating<span class=\"token punctuation\">,</span> setRating<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>selection<span class=\"token punctuation\">,</span> setSelection<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> hoverOver <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> val <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>event <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> event<span class=\"token punctuation\">.</span>target <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>data<span class=\"token operator\">-</span>star<span class=\"token operator\">-</span>id<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nval <span class=\"token operator\">=</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>data<span class=\"token operator\">-</span>star<span class=\"token operator\">-</span>id<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setSelection</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\nonMouseOut<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">hoverOver</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\nonClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token function\">setRating</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>data<span class=\"token operator\">-</span>star<span class=\"token operator\">-</span>id<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> rating<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">}</span>\nonMouseOver<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>hoverOver<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">from</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">length</span><span class=\"token operator\">:</span> <span class=\"token number\">5</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Star\nstarId<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">}</span>\nkey<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">star_</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\nmarked<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>selection <span class=\"token operator\">?</span> selection <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span> <span class=\"token operator\">:</span> rating <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>StarRating value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">2</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a tabbed menu and view component.</p>\n<ul>\n<li>Define a <code>Tabs</code> component that uses the <code>useState()</code> hook to initialize the value of the <code>bindIndex</code> state variable to <code>defaultIndex</code>.</li>\n<li>Define a <code>TabItem</code> component and filter <code>children</code> passed to the <code>Tabs</code> component to remove unnecessary nodes except for <code>TabItem</code> by identifying the function's name.</li>\n<li>Define <code>changeTab</code>, which will be executed when clicking a <code>&lt;button&gt;</code> from the menu.</li>\n<li>\n<code>changeTab</code> executes the passed callback, <code>onTabClick</code>, and updates <code>bindIndex</code> based on the clicked element.</li>\n<li>Use <code>Array.prototype.map()</code> on the collected nodes to render the menu and view of the tabs, using the value of <code>binIndex</code> to determine the active tab and apply the correct <code>className</code>.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb56\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb56-1\" title=\"1\">\n<span class=\"fu\">.tab-menu</span> <span class=\"op\">&gt;</span> button {</a>\n<a class=\"sourceLine\" id=\"cb56-2\" title=\"2\">  <span class=\"kw\">cursor</span>: <span class=\"dv\">pointer</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-3\" title=\"3\">  <span class=\"kw\">padding</span>: <span class=\"dv\">8</span>\n<span class=\"dt\">px</span> <span class=\"dv\">16</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-4\" title=\"4\">  <span class=\"kw\">border</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-5\" title=\"5\">  <span class=\"kw\">border-bottom</span>: <span class=\"dv\">2</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"dv\">transparent</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-6\" title=\"6\">  <span class=\"kw\">background</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-7\" title=\"7\">}</a>\n<a class=\"sourceLine\" id=\"cb56-8\" title=\"8\">\n</a>\n<a class=\"sourceLine\" id=\"cb56-9\" title=\"9\">\n<span class=\"fu\">.tab-menu</span> <span class=\"op\">&gt;</span> button<span class=\"fu\">.focus</span> {</a>\n<a class=\"sourceLine\" id=\"cb56-10\" title=\"10\">  <span class=\"kw\">border-bottom</span>: <span class=\"dv\">2</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">#007bef</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-11\" title=\"11\">}</a>\n<a class=\"sourceLine\" id=\"cb56-12\" title=\"12\">\n</a>\n<a class=\"sourceLine\" id=\"cb56-13\" title=\"13\">\n<span class=\"fu\">.tab-menu</span> <span class=\"op\">&gt;</span> button<span class=\"in\">:hover</span> {</a>\n<a class=\"sourceLine\" id=\"cb56-14\" title=\"14\">  <span class=\"kw\">border-bottom</span>: <span class=\"dv\">2</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">#007bef</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-15\" title=\"15\">}</a>\n<a class=\"sourceLine\" id=\"cb56-16\" title=\"16\">\n</a>\n<a class=\"sourceLine\" id=\"cb56-17\" title=\"17\">\n<span class=\"fu\">.tab-content</span> {</a>\n<a class=\"sourceLine\" id=\"cb56-18\" title=\"18\">  <span class=\"kw\">display</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-19\" title=\"19\">}</a>\n<a class=\"sourceLine\" id=\"cb56-20\" title=\"20\">\n</a>\n<a class=\"sourceLine\" id=\"cb56-21\" title=\"21\">\n<span class=\"fu\">.tab-content.selected</span> {</a>\n<a class=\"sourceLine\" id=\"cb56-22\" title=\"22\">  <span class=\"kw\">display</span>: <span class=\"dv\">block</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb56-23\" title=\"23\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> TabItem <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> Tabs <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> defaultIndex <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> onTabClick<span class=\"token punctuation\">,</span> children <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>bindIndex<span class=\"token punctuation\">,</span> setBindIndex<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>defaultIndex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> changeTab <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>newIndex<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> onItemClick <span class=\"token operator\">===</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token keyword\">function</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span> <span class=\"token function\">onItemClick</span><span class=\"token punctuation\">(</span>itemIndex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setBindIndex</span><span class=\"token punctuation\">(</span>newIndex<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> items <span class=\"token operator\">=</span> children<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> item<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>TabItem<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>wrapper<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tab<span class=\"token operator\">-</span>menu<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">props</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> index<span class=\"token punctuation\">,</span> label <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button\nkey<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">tab-btn-</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>index<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\nonClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">changeTab</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>bindIndex <span class=\"token operator\">===</span> index <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>focus<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>label<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tab<span class=\"token operator\">-</span>view<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>items<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> props <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\n<span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>props<span class=\"token punctuation\">}</span>\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">tab-content </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span> bindIndex <span class=\"token operator\">===</span> props<span class=\"token punctuation\">.</span>index <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>selected<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\nkey<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">tab-content-</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>props<span class=\"token punctuation\">.</span>index<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Tabs defaultIndex<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">1</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> onTabClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>TabItem label<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token constant\">A</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> index<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">1</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      Lorem ipsum\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>TabItem<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>TabItem label<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token constant\">B</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> index<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token number\">2</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      Dolor sit amet\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>TabItem<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>Tabs<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a tag input field.</p>\n<ul>\n<li>Define a <code>TagInput</code> component and use the <code>useState()</code> hook to initialize an array from <code>tags</code>.</li>\n<li>Use <code>Array.prototype.map()</code> on the collected nodes to render the list of tags.</li>\n<li>Define the <code>addTagData</code> method, which will be executed when pressing the <code>Enter</code> key.</li>\n<li>The <code>addTagData</code> method calls <code>setTagData</code> to add the new tag using the spread (<code>...</code>) operator to prepend the existing tags and add the new tag at the end of the <code>tagData</code> array.</li>\n<li>Define the <code>removeTagData</code> method, which will be executed on clicking the delete icon in the tag.</li>\n<li>Use <code>Array.prototype.filter()</code> in the <code>removeTagData</code> method to remove the tag using its <code>index</code> to filter it out from the <code>tagData</code> array.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb59\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb59-1\" title=\"1\">\n<span class=\"fu\">.tag-input</span> {</a>\n<a class=\"sourceLine\" id=\"cb59-2\" title=\"2\">  <span class=\"kw\">display</span>: flex<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-3\" title=\"3\">  <span class=\"kw\">flex-wrap</span>: wrap<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-4\" title=\"4\">  <span class=\"kw\">min-height</span>: <span class=\"dv\">48</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-5\" title=\"5\">  <span class=\"kw\">padding</span>: <span class=\"dv\">0</span> <span class=\"dv\">8</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-6\" title=\"6\">  <span class=\"kw\">border</span>: <span class=\"dv\">1</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">#d6d8da</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-7\" title=\"7\">  <span class=\"kw\">border-radius</span>: <span class=\"dv\">6</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-8\" title=\"8\">}</a>\n<a class=\"sourceLine\" id=\"cb59-9\" title=\"9\">\n</a>\n<a class=\"sourceLine\" id=\"cb59-10\" title=\"10\">\n<span class=\"fu\">.tag-input</span> input {</a>\n<a class=\"sourceLine\" id=\"cb59-11\" title=\"11\">  <span class=\"kw\">flex</span>: <span class=\"dv\">1</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-12\" title=\"12\">  <span class=\"kw\">border</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-13\" title=\"13\">  <span class=\"kw\">height</span>: <span class=\"dv\">46</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-14\" title=\"14\">  <span class=\"kw\">font-size</span>: <span class=\"dv\">14</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-15\" title=\"15\">  <span class=\"kw\">padding</span>: <span class=\"dv\">4</span>\n<span class=\"dt\">px</span> <span class=\"dv\">0</span> <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-16\" title=\"16\">}</a>\n<a class=\"sourceLine\" id=\"cb59-17\" title=\"17\">\n</a>\n<a class=\"sourceLine\" id=\"cb59-18\" title=\"18\">\n<span class=\"fu\">.tag-input</span> input<span class=\"in\">:focus</span> {</a>\n<a class=\"sourceLine\" id=\"cb59-19\" title=\"19\">  <span class=\"kw\">outline</span>: <span class=\"dv\">transparent</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-20\" title=\"20\">}</a>\n<a class=\"sourceLine\" id=\"cb59-21\" title=\"21\">\n</a>\n<a class=\"sourceLine\" id=\"cb59-22\" title=\"22\">\n<span class=\"fu\">.tags</span> {</a>\n<a class=\"sourceLine\" id=\"cb59-23\" title=\"23\">  <span class=\"kw\">display</span>: flex<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-24\" title=\"24\">  <span class=\"kw\">flex-wrap</span>: wrap<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-25\" title=\"25\">  <span class=\"kw\">padding</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-26\" title=\"26\">  <span class=\"kw\">margin</span>: <span class=\"dv\">8</span>\n<span class=\"dt\">px</span> <span class=\"dv\">0</span> <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-27\" title=\"27\">}</a>\n<a class=\"sourceLine\" id=\"cb59-28\" title=\"28\">\n</a>\n<a class=\"sourceLine\" id=\"cb59-29\" title=\"29\">\n<span class=\"fu\">.tag</span> {</a>\n<a class=\"sourceLine\" id=\"cb59-30\" title=\"30\">  <span class=\"kw\">width</span>: <span class=\"bu\">auto</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-31\" title=\"31\">  <span class=\"kw\">height</span>: <span class=\"dv\">32</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-32\" title=\"32\">  <span class=\"kw\">display</span>: flex<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-33\" title=\"33\">  <span class=\"kw\">align-items</span>: <span class=\"dv\">center</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-34\" title=\"34\">  <span class=\"kw\">justify-content</span>: <span class=\"dv\">center</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-35\" title=\"35\">  <span class=\"kw\">color</span>: <span class=\"cn\">#fff</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-36\" title=\"36\">  <span class=\"kw\">padding</span>: <span class=\"dv\">0</span> <span class=\"dv\">8</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-37\" title=\"37\">  <span class=\"kw\">font-size</span>: <span class=\"dv\">14</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-38\" title=\"38\">  <span class=\"kw\">list-style</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-39\" title=\"39\">  <span class=\"kw\">border-radius</span>: <span class=\"dv\">6</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-40\" title=\"40\">  <span class=\"kw\">margin</span>: <span class=\"dv\">0</span> <span class=\"dv\">8</span>\n<span class=\"dt\">px</span> <span class=\"dv\">8</span>\n<span class=\"dt\">px</span> <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-41\" title=\"41\">  <span class=\"kw\">background</span>: <span class=\"cn\">#0052cc</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-42\" title=\"42\">}</a>\n<a class=\"sourceLine\" id=\"cb59-43\" title=\"43\">\n</a>\n<a class=\"sourceLine\" id=\"cb59-44\" title=\"44\">\n<span class=\"fu\">.tag-title</span> {</a>\n<a class=\"sourceLine\" id=\"cb59-45\" title=\"45\">  <span class=\"kw\">margin-top</span>: <span class=\"dv\">3</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-46\" title=\"46\">}</a>\n<a class=\"sourceLine\" id=\"cb59-47\" title=\"47\">\n</a>\n<a class=\"sourceLine\" id=\"cb59-48\" title=\"48\">\n<span class=\"fu\">.tag-close-icon</span> {</a>\n<a class=\"sourceLine\" id=\"cb59-49\" title=\"49\">  <span class=\"kw\">display</span>: <span class=\"dv\">block</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-50\" title=\"50\">  <span class=\"kw\">width</span>: <span class=\"dv\">16</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-51\" title=\"51\">  <span class=\"kw\">height</span>: <span class=\"dv\">16</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-52\" title=\"52\">  <span class=\"kw\">line-height</span>: <span class=\"dv\">16</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-53\" title=\"53\">  <span class=\"kw\">text-align</span>: <span class=\"dv\">center</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-54\" title=\"54\">  <span class=\"kw\">font-size</span>: <span class=\"dv\">14</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-55\" title=\"55\">  <span class=\"kw\">margin-left</span>: <span class=\"dv\">8</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-56\" title=\"56\">  <span class=\"kw\">color</span>: <span class=\"cn\">#0052cc</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-57\" title=\"57\">  <span class=\"kw\">border-radius</span>: <span class=\"dv\">50</span>\n<span class=\"dt\">%</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-58\" title=\"58\">  <span class=\"kw\">background</span>: <span class=\"cn\">#fff</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-59\" title=\"59\">  <span class=\"kw\">cursor</span>: <span class=\"dv\">pointer</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb59-60\" title=\"60\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> TagInput <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> tags <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>tagData<span class=\"token punctuation\">,</span> setTagData<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>tags<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> removeTagData <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>indexToRemove<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTagData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>tagData<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">,</span> index<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> index <span class=\"token operator\">!==</span> indexToRemove<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> addTagData <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token operator\">!==</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">setTagData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>tagData<span class=\"token punctuation\">,</span> event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tag<span class=\"token operator\">-</span>input<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>ul className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tags<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">{</span>tagData<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>tag<span class=\"token punctuation\">,</span> index<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n          <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>li key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>index<span class=\"token punctuation\">}</span> className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tag<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n            <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tag<span class=\"token operator\">-</span>title<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>tag<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n            <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span\n              className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tag<span class=\"token operator\">-</span>close<span class=\"token operator\">-</span>icon<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n              onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">removeTagData</span><span class=\"token punctuation\">(</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n              x\n            <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n          <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input\n        type<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>text<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n        onKeyUp<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>key <span class=\"token operator\">===</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Enter<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">?</span> <span class=\"token function\">addTagData</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n        placeholder<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Press enter to add a tag<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>TagInput tags<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Nodejs<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>MongoDB<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders an uncontrolled <code>&lt;textarea&gt;</code> element that uses a callback function to pass its value to the parent component.</p>\n<ul>\n<li>Use the <code>defaultValue</code> passed down from the parent as the uncontrolled input field's initial value.</li>\n<li>Use the <code>onChange</code> event to fire the <code>onValueChange</code> callback and send the new value to the parent.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> TextArea <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n  cols <span class=\"token operator\">=</span> <span class=\"token number\">20</span><span class=\"token punctuation\">,</span>\n  rows <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span>\n  defaultValue<span class=\"token punctuation\">,</span>\n  onValueChange<span class=\"token punctuation\">,</span>\n  <span class=\"token operator\">...</span>rest\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>textarea\n      cols<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>cols<span class=\"token punctuation\">}</span>\n      rows<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>rows<span class=\"token punctuation\">}</span>\n      defaultValue<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>defaultValue<span class=\"token punctuation\">}</span>\n      onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> value <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">onValueChange</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>TextArea\n    placeholder<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Insert some text here<span class=\"token operator\">...</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n    onValueChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>val<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n  <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a toggle component.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to initialize the <code>isToggleOn</code> state variable to <code>defaultToggled</code>.</li>\n<li>Render an <code>&lt;input&gt;</code> and bind its <code>onClick</code> event to update the <code>isToggledOn</code> state variable, applying the appropriate <code>className</code> to the wrapping <code>&lt;label&gt;</code>.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb64\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb64-1\" title=\"1\">\n<span class=\"fu\">.toggle</span> input<span class=\"ex\">[type</span>\n<span class=\"op\">=</span>\n<span class=\"st\">&quot;checkbox&quot;</span>\n<span class=\"ex\">]</span> {</a>\n<a class=\"sourceLine\" id=\"cb64-2\" title=\"2\">  <span class=\"kw\">display</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb64-3\" title=\"3\">}</a>\n<a class=\"sourceLine\" id=\"cb64-4\" title=\"4\">\n</a>\n<a class=\"sourceLine\" id=\"cb64-5\" title=\"5\">\n<span class=\"fu\">.toggle.on</span> {</a>\n<a class=\"sourceLine\" id=\"cb64-6\" title=\"6\">  <span class=\"kw\">background-color</span>: <span class=\"cn\">green</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb64-7\" title=\"7\">}</a>\n<a class=\"sourceLine\" id=\"cb64-8\" title=\"8\">\n</a>\n<a class=\"sourceLine\" id=\"cb64-9\" title=\"9\">\n<span class=\"fu\">.toggle.off</span> {</a>\n<a class=\"sourceLine\" id=\"cb64-10\" title=\"10\">  <span class=\"kw\">background-color</span>: <span class=\"cn\">red</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb64-11\" title=\"11\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Toggle <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> defaultToggled <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>isToggleOn<span class=\"token punctuation\">,</span> setIsToggleOn<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>defaultToggled<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>label className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isToggleOn <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>toggle on<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>toggle off<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input\ntype<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>checkbox<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\nchecked<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isToggleOn<span class=\"token punctuation\">}</span>\nonChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setIsToggleOn</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>isToggleOn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>isToggleOn <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token constant\">ON</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token constant\">OFF</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>label<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Toggle <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a tooltip component.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>show</code> variable and initialize it to <code>false</code>.</li>\n<li>Render a container element that contains the tooltip element and the <code>children</code> passed to the component.</li>\n<li>Handle the <code>onMouseEnter</code> and <code>onMouseLeave</code> methods, by altering the value of the <code>show</code> variable, toggling the <code>className</code> of the tooltip.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb67\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb67-1\" title=\"1\">\n<span class=\"fu\">.tooltip-container</span> {</a>\n<a class=\"sourceLine\" id=\"cb67-2\" title=\"2\">  <span class=\"kw\">position</span>: <span class=\"dv\">relative</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-3\" title=\"3\">}</a>\n<a class=\"sourceLine\" id=\"cb67-4\" title=\"4\">\n</a>\n<a class=\"sourceLine\" id=\"cb67-5\" title=\"5\">\n<span class=\"fu\">.tooltip-box</span> {</a>\n<a class=\"sourceLine\" id=\"cb67-6\" title=\"6\">  <span class=\"kw\">position</span>: <span class=\"dv\">absolute</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-7\" title=\"7\">  <span class=\"kw\">background</span>: <span class=\"fu\">rgba(</span>\n<span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0.7</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-8\" title=\"8\">  <span class=\"kw\">color</span>: <span class=\"cn\">#fff</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-9\" title=\"9\">  <span class=\"kw\">padding</span>: <span class=\"dv\">5</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-10\" title=\"10\">  <span class=\"kw\">border-radius</span>: <span class=\"dv\">5</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-11\" title=\"11\">  <span class=\"kw\">top</span>: <span class=\"fu\">calc(</span>\n<span class=\"dv\">100</span>\n<span class=\"dt\">%</span> <span class=\"op\">+</span> <span class=\"dv\">5</span>\n<span class=\"dt\">px</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-12\" title=\"12\">  <span class=\"kw\">display</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-13\" title=\"13\">}</a>\n<a class=\"sourceLine\" id=\"cb67-14\" title=\"14\">\n</a>\n<a class=\"sourceLine\" id=\"cb67-15\" title=\"15\">\n<span class=\"fu\">.tooltip-box.visible</span> {</a>\n<a class=\"sourceLine\" id=\"cb67-16\" title=\"16\">  <span class=\"kw\">display</span>: <span class=\"dv\">block</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-17\" title=\"17\">}</a>\n<a class=\"sourceLine\" id=\"cb67-18\" title=\"18\">\n</a>\n<a class=\"sourceLine\" id=\"cb67-19\" title=\"19\">\n<span class=\"fu\">.tooltip-arrow</span> {</a>\n<a class=\"sourceLine\" id=\"cb67-20\" title=\"20\">  <span class=\"kw\">position</span>: <span class=\"dv\">absolute</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-21\" title=\"21\">  <span class=\"kw\">top</span>: <span class=\"dv\">-10</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-22\" title=\"22\">  <span class=\"kw\">left</span>: <span class=\"dv\">50</span>\n<span class=\"dt\">%</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-23\" title=\"23\">  <span class=\"kw\">border-width</span>: <span class=\"dv\">5</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-24\" title=\"24\">  <span class=\"kw\">border-style</span>: <span class=\"dv\">solid</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-25\" title=\"25\">  <span class=\"kw\">border-color</span>: <span class=\"dv\">transparent</span> <span class=\"dv\">transparent</span> <span class=\"fu\">rgba(</span>\n<span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0</span>\n<span class=\"op\">,</span> <span class=\"dv\">0.7</span>\n<span class=\"fu\">)</span> <span class=\"dv\">transparent</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb67-26\" title=\"26\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Tooltip <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> children<span class=\"token punctuation\">,</span> text<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>show<span class=\"token punctuation\">,</span> setShow<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tooltip<span class=\"token operator\">-</span>container<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>show <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tooltip<span class=\"token operator\">-</span>box visible<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tooltip<span class=\"token operator\">-</span>box<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>text<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tooltip<span class=\"token operator\">-</span>arrow<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\nonMouseEnter<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setShow</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\nonMouseLeave<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setShow</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>children<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Tooltip text<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Simple tooltip<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Hover me<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>Tooltip<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders a tree view of a JSON object or array with collapsible content.</p>\n<ul>\n<li>Use the value of the <code>toggled</code> prop to determine the initial state of the content (collapsed/expanded).</li>\n<li>Use the <code>useState()</code> hook to create the <code>isToggled</code> state variable and give it the value of the <code>toggled</code> prop initially.</li>\n<li>Render a <code>&lt;span&gt;</code> element and bind its <code>onClick</code> event to alter the component's <code>isToggled</code> state.</li>\n<li>Determine the appearance of the component, based on <code>isParentToggled</code>, <code>isToggled</code>, <code>name</code> and checking for <code>Array.isArray()</code> on <code>data</code>.</li>\n<li>For each child in <code>data</code>, determine if it is an object or array and recursively render a sub-tree or a text element with the appropriate style.</li>\n</ul>\n<div class=\"sourceCode\" id=\"cb70\">\n<pre class=\"sourceCode css\">\n<code class=\"sourceCode css\">\n<a class=\"sourceLine\" id=\"cb70-1\" title=\"1\">\n<span class=\"fu\">.tree-element</span> {</a>\n<a class=\"sourceLine\" id=\"cb70-2\" title=\"2\">  <span class=\"kw\">margin</span>: <span class=\"dv\">0</span> <span class=\"dv\">0</span> <span class=\"dv\">0</span> <span class=\"dv\">4</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-3\" title=\"3\">  <span class=\"kw\">position</span>: <span class=\"dv\">relative</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-4\" title=\"4\">}</a>\n<a class=\"sourceLine\" id=\"cb70-5\" title=\"5\">\n</a>\n<a class=\"sourceLine\" id=\"cb70-6\" title=\"6\">\n<span class=\"fu\">.tree-element.is-child</span> {</a>\n<a class=\"sourceLine\" id=\"cb70-7\" title=\"7\">  <span class=\"kw\">margin-left</span>: <span class=\"dv\">16</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-8\" title=\"8\">}</a>\n<a class=\"sourceLine\" id=\"cb70-9\" title=\"9\">\n</a>\n<a class=\"sourceLine\" id=\"cb70-10\" title=\"10\">div<span class=\"fu\">.tree-element</span>\n<span class=\"in\">:before</span> {</a>\n<a class=\"sourceLine\" id=\"cb70-11\" title=\"11\">  <span class=\"kw\">content</span>: <span class=\"st\">&quot;&quot;</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-12\" title=\"12\">  <span class=\"kw\">position</span>: <span class=\"dv\">absolute</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-13\" title=\"13\">  <span class=\"kw\">top</span>: <span class=\"dv\">24</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-14\" title=\"14\">  <span class=\"kw\">left</span>: <span class=\"dv\">1</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-15\" title=\"15\">  <span class=\"kw\">height</span>: <span class=\"fu\">calc(</span>\n<span class=\"dv\">100</span>\n<span class=\"dt\">%</span> <span class=\"op\">-</span> <span class=\"dv\">48</span>\n<span class=\"dt\">px</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-16\" title=\"16\">  <span class=\"kw\">border-left</span>: <span class=\"dv\">1</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">gray</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-17\" title=\"17\">}</a>\n<a class=\"sourceLine\" id=\"cb70-18\" title=\"18\">\n</a>\n<a class=\"sourceLine\" id=\"cb70-19\" title=\"19\">p<span class=\"fu\">.tree-element</span> {</a>\n<a class=\"sourceLine\" id=\"cb70-20\" title=\"20\">  <span class=\"kw\">margin-left</span>: <span class=\"dv\">16</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-21\" title=\"21\">}</a>\n<a class=\"sourceLine\" id=\"cb70-22\" title=\"22\">\n</a>\n<a class=\"sourceLine\" id=\"cb70-23\" title=\"23\">\n<span class=\"fu\">.toggler</span> {</a>\n<a class=\"sourceLine\" id=\"cb70-24\" title=\"24\">  <span class=\"kw\">position</span>: <span class=\"dv\">absolute</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-25\" title=\"25\">  <span class=\"kw\">top</span>: <span class=\"dv\">10</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-26\" title=\"26\">  <span class=\"kw\">left</span>: <span class=\"dv\">0</span>\n<span class=\"dt\">px</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-27\" title=\"27\">  <span class=\"kw\">width</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-28\" title=\"28\">  <span class=\"kw\">height</span>: <span class=\"dv\">0</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-29\" title=\"29\">  <span class=\"kw\">border-top</span>: <span class=\"dv\">4</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"dv\">transparent</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-30\" title=\"30\">  <span class=\"kw\">border-bottom</span>: <span class=\"dv\">4</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"dv\">transparent</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-31\" title=\"31\">  <span class=\"kw\">border-left</span>: <span class=\"dv\">5</span>\n<span class=\"dt\">px</span> <span class=\"dv\">solid</span> <span class=\"cn\">gray</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-32\" title=\"32\">  <span class=\"kw\">cursor</span>: <span class=\"dv\">pointer</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-33\" title=\"33\">}</a>\n<a class=\"sourceLine\" id=\"cb70-34\" title=\"34\">\n</a>\n<a class=\"sourceLine\" id=\"cb70-35\" title=\"35\">\n<span class=\"fu\">.toggler.closed</span> {</a>\n<a class=\"sourceLine\" id=\"cb70-36\" title=\"36\">  <span class=\"kw\">transform</span>: <span class=\"fu\">rotate(</span>\n<span class=\"dv\">90</span>\n<span class=\"dt\">deg</span>\n<span class=\"fu\">)</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-37\" title=\"37\">}</a>\n<a class=\"sourceLine\" id=\"cb70-38\" title=\"38\">\n</a>\n<a class=\"sourceLine\" id=\"cb70-39\" title=\"39\">\n<span class=\"fu\">.collapsed</span> {</a>\n<a class=\"sourceLine\" id=\"cb70-40\" title=\"40\">  <span class=\"kw\">display</span>: <span class=\"dv\">none</span>\n<span class=\"op\">;</span>\n</a>\n<a class=\"sourceLine\" id=\"cb70-41\" title=\"41\">}</a>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> TreeView <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n  data<span class=\"token punctuation\">,</span>\n  toggled <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n  name <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n  isLast <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n  isChildElement <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span>\n  isParentToggled <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>isToggled<span class=\"token punctuation\">,</span> setIsToggled<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>toggled<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> isDataArray <span class=\"token operator\">=</span> Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">tree-element </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>isParentToggled <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>collapsed<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span> isChildElement <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>is<span class=\"token operator\">-</span>child<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isToggled <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>toggler<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>toggler closed<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\nonClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setIsToggled</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>isToggled<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>name <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>strong<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span>nbsp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span>nbsp<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>strong<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span>nbsp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span>nbsp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>isDataArray <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span><span class=\"token operator\">!</span>isToggled <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">...</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">typeof</span> data<span class=\"token punctuation\">[</span>v<span class=\"token punctuation\">]</span> <span class=\"token operator\">===</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>object<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>TreeView\nkey<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">-</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>v<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">-</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\ndata<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>data<span class=\"token punctuation\">[</span>v<span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span>\nisLast<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>i <span class=\"token operator\">===</span> a<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">}</span>\nname<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isDataArray <span class=\"token operator\">?</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">:</span> v<span class=\"token punctuation\">}</span>\nisChildElement\nisParentToggled<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isParentToggled <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> isToggled<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p\nkey<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">-</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>v<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">-</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>i<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">}</span>\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>isToggled <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tree<span class=\"token operator\">-</span>element<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tree<span class=\"token operator\">-</span>element collapsed<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>isDataArray <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>strong<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>v<span class=\"token punctuation\">}</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>strong<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>data<span class=\"token punctuation\">[</span>v<span class=\"token punctuation\">]</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>i <span class=\"token operator\">===</span> a<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span> <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>isDataArray <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span><span class=\"token operator\">!</span>isLast <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">&lt;</span>hr <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>`js\n<span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> data <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token literal-property property\">lorem</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">ipsum</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>dolor sit<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">amet</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">consectetur</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>adipiscing<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">elit</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>duis<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>vitae<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">{</span>\n          <span class=\"token literal-property property\">semper</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>orci<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">{</span>\n          <span class=\"token literal-property property\">est</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>sed ornare<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>etiam<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>laoreet<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>tincidunt<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token punctuation\">[</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>vestibulum<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>ante<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">ipsum</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>primis<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>TreeView data<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>data<span class=\"token punctuation\">}</span> name<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>data<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Renders an uncontrolled <code>&lt;input&gt;</code> element that uses a callback function to inform its parent about value updates.</p>\n<ul>\n<li>Use the <code>defaultValue</code> passed down from the parent as the uncontrolled input field's initial value.</li>\n<li>Use the <code>onChange</code> event to fire the <code>onValueChange</code> callback and send the new value to the parent.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> UncontrolledInput <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> defaultValue<span class=\"token punctuation\">,</span> onValueChange<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>rest <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input\n      defaultValue<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>defaultValue<span class=\"token punctuation\">}</span>\n      onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> value <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">onValueChange</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span>rest<span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n  <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>UncontrolledInput\n    type<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>text<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n    placeholder<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Insert some text here<span class=\"token operator\">...</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n    onValueChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>console<span class=\"token punctuation\">.</span>log<span class=\"token punctuation\">}</span>\n  <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n  document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Handles asynchronous calls.</p>\n<ul>\n<li>Create a custom hook that takes a handler function, <code>fn</code>.</li>\n<li>Define a reducer function and an initial state for the custom hook's state.</li>\n<li>Use the <code>useReducer()</code> hook to initialize the <code>state</code> variable and the <code>dispatch</code> function.</li>\n<li>Define an asynchronous <code>run</code> function that will run the provided callback, <code>fn</code>, while using <code>dispatch</code> to update <code>state</code> as necessary.</li>\n<li>Return an object containing the properties of <code>state</code> (<code>value</code>, <code>error</code> and <code>loading</code>) and the <code>run</code> function.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useAsync <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> initialState <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">loading</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">error</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> stateReducer <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">,</span> action<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">case</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>start<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">loading</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">error</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">case</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>finish<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">loading</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">error</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> action<span class=\"token punctuation\">.</span>value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n      <span class=\"token keyword\">case</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>error<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">loading</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">error</span><span class=\"token operator\">:</span> action<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>state<span class=\"token punctuation\">,</span> dispatch<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useReducer</span><span class=\"token punctuation\">(</span>stateReducer<span class=\"token punctuation\">,</span> initialState<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> run <span class=\"token operator\">=</span> <span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span>args <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>start<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> value <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>finish<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> value <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">dispatch</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>error<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> error <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> <span class=\"token operator\">...</span>state<span class=\"token punctuation\">,</span> run <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> RandomImage <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> imgFetch <span class=\"token operator\">=</span> <span class=\"token function\">useAsync</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>response<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> response<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button\nonClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> imgFetch<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>https<span class=\"token operator\">:</span><span class=\"token operator\">/</span><span class=\"token operator\">/</span>dog<span class=\"token punctuation\">.</span>ceo<span class=\"token operator\">/</span>api<span class=\"token operator\">/</span>breeds<span class=\"token operator\">/</span>image<span class=\"token operator\">/</span>random<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\ndisabled<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>imgFetch<span class=\"token punctuation\">.</span>isLoading<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\nLoad image\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>br <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">{</span>imgFetch<span class=\"token punctuation\">.</span>loading <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Loading<span class=\"token operator\">...</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>imgFetch<span class=\"token punctuation\">.</span>error <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Error <span class=\"token punctuation\">{</span>imgFetch<span class=\"token punctuation\">.</span>error<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">{</span>imgFetch<span class=\"token punctuation\">.</span>value <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>img\nsrc<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>imgFetch<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">}</span>\nalt<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>avatar<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\nwidth<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">400</span><span class=\"token punctuation\">}</span>\nheight<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>auto<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>RandomImage <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Handles the event of clicking inside the wrapped component.</p>\n<ul>\n<li>Create a custom hook that takes a <code>ref</code> and a <code>callback</code> to handle the <code>'click'</code> event.</li>\n<li>Use the <code>useEffect()</code> hook to append and clean up the <code>click</code> event.</li>\n<li>Use the <code>useRef()</code> hook to create a <code>ref</code> for your click component and pass it to the <code>useClickInside</code> hook.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useClickInside <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>ref<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> handleClick <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>ref<span class=\"token punctuation\">.</span>current <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> ref<span class=\"token punctuation\">.</span>current<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  React<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>click<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleClick<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n      document<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>click<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleClick<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> ClickBox <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> onClickInside <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> clickRef <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useRef</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">useClickInside</span><span class=\"token punctuation\">(</span>clickRef<span class=\"token punctuation\">,</span> onClickInside<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\n      className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>click<span class=\"token operator\">-</span>box<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      ref<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>clickRef<span class=\"token punctuation\">}</span>\n      style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>2px dashed orangered<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">height</span><span class=\"token operator\">:</span> <span class=\"token number\">200</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">width</span><span class=\"token operator\">:</span> <span class=\"token number\">400</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>flex<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">justifyContent</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>center<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">alignItems</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>center<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Click inside <span class=\"token keyword\">this</span> element<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>ClickBox onClickInside<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>click inside<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Handles the event of clicking outside of the wrapped component.</p>\n<ul>\n<li>Create a custom hook that takes a <code>ref</code> and a <code>callback</code> to handle the <code>click</code> event.</li>\n<li>Use the <code>useEffect()</code> hook to append and clean up the <code>click</code> event.</li>\n<li>Use the <code>useRef()</code> hook to create a <code>ref</code> for your click component and pass it to the <code>useClickOutside</code> hook.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useClickOutside <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>ref<span class=\"token punctuation\">,</span> callback<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> handleClick <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>ref<span class=\"token punctuation\">.</span>current <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">!</span>ref<span class=\"token punctuation\">.</span>current<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  React<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>click<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleClick<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n      document<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>click<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> handleClick<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> ClickBox <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> onClickOutside <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> clickRef <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useRef</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">useClickOutside</span><span class=\"token punctuation\">(</span>clickRef<span class=\"token punctuation\">,</span> onClickOutside<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div\n      className<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>click<span class=\"token operator\">-</span>box<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n      ref<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>clickRef<span class=\"token punctuation\">}</span>\n      style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>2px dashed orangered<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">height</span><span class=\"token operator\">:</span> <span class=\"token number\">200</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">width</span><span class=\"token operator\">:</span> <span class=\"token number\">400</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">display</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>flex<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">justifyContent</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>center<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">alignItems</span><span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>center<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Click out <span class=\"token keyword\">of</span> <span class=\"token keyword\">this</span> element<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>ClickBox onClickOutside<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>click outside<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Executes a callback immediately after a component is mounted.</p>\n<ul>\n<li>Use <code>useEffect()</code> with an empty array as the second argument to execute the provided callback only once when the component is mounted.</li>\n<li>Behaves like the <code>componentDidMount()</code> lifecycle method of class components.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useComponentDidMount <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>onMountHandler<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  React<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">onMountHandler</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Mounter <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">useComponentDidMount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Component did mount<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Check the console<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Mounter <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Executes a callback immediately before a component is unmounted and destroyed.</p>\n<ul>\n<li>Use <code>useEffect()</code> with an empty array as the second argument and return the provided callback to be executed only once before cleanup.</li>\n<li>Behaves like the <code>componentWillUnmount()</code> lifecycle method of class components.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useComponentWillUnmount <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>onUnmountHandler<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  React<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">onUnmountHandler</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Unmounter <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">useComponentWillUnmount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Component will unmount<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Check the console<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Unmounter <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Copies the given text to the clipboard.</p>\n<ul>\n<li>Use the <a href=\"/js/s/copy-to-clipboard/\">copyToClipboard</a> snippet to copy the text to clipboard.</li>\n<li>Use the <code>useState()</code> hook to initialize the <code>copied</code> variable.</li>\n<li>Use the <code>useCallback()</code> hook to create a callback for the <code>copyToClipboard</code> method.</li>\n<li>Use the <code>useEffect()</code> hook to reset the <code>copied</code> state variable if the <code>text</code> changes.</li>\n<li>Return the <code>copied</code> state variable and the <code>copy</code> callback.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useCopyToClipboard <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> copyToClipboard <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>str<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> el <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>textarea<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    el<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> str<span class=\"token punctuation\">;</span>\n    el<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>readonly<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    el<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>position <span class=\"token operator\">=</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>absolute<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n    el<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token operator\">-</span>9999px<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> selected <span class=\"token operator\">=</span>\n      document<span class=\"token punctuation\">.</span><span class=\"token function\">getSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>rangeCount <span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token number\">0</span>\n        <span class=\"token operator\">?</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">getRangeAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n    el<span class=\"token punctuation\">.</span><span class=\"token function\">select</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> success <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">execCommand</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>copy<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>selected<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      document<span class=\"token punctuation\">.</span><span class=\"token function\">getSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeAllRanges</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      document<span class=\"token punctuation\">.</span><span class=\"token function\">getSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addRange</span><span class=\"token punctuation\">(</span>selected<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> success<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>copied<span class=\"token punctuation\">,</span> setCopied<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> copy <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useCallback</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>copied<span class=\"token punctuation\">)</span> <span class=\"token function\">setCopied</span><span class=\"token punctuation\">(</span><span class=\"token function\">copyToClipboard</span><span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>text<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setCopied</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>text<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>copied<span class=\"token punctuation\">,</span> copy<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> TextCopy <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>copied<span class=\"token punctuation\">,</span> copy<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useCopyToClipboard</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Lorem ipsum<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>copy<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Click to copy<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>copied <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Copied<span class=\"token operator\">!</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>TextCopy <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Debounces the given value.</p>\n<ul>\n<li>Create a custom hook that takes a <code>value</code> and a <code>delay</code>.</li>\n<li>Use the <code>useState()</code> hook to store the debounced value.</li>\n<li>Use the <code>useEffect()</code> hook to update the debounced value every time <code>value</code> is updated.</li>\n<li>Use <code>setTimeout()</code> to create a timeout that delays invoking the setter of the previous state variable by <code>delay</code> ms.</li>\n<li>Use <code>clearTimeout()</code> to clean up when dismounting the component.</li>\n<li>This is particularly useful when dealing with user input.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useDebounce <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>debouncedValue<span class=\"token punctuation\">,</span> setDebouncedValue<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> handler <span class=\"token operator\">=</span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setDebouncedValue</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>handler<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> debouncedValue<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Counter <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> setValue<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> lastValue <span class=\"token operator\">=</span> <span class=\"token function\">useDebounce</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">,</span> <span class=\"token number\">500</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token literal-property property\">Current</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>value<span class=\"token punctuation\">}</span> <span class=\"token operator\">-</span> Debounced<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>lastValue<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setValue</span><span class=\"token punctuation\">(</span>value <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Increment<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Counter <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Implements <code>fetch</code> in a declarative manner.</p>\n<ul>\n<li>Create a custom hook that takes a <code>url</code> and <code>options</code>.</li>\n<li>Use the <code>useState()</code> hook to initialize the <code>response</code> and <code>error</code> state variables.</li>\n<li>Use the <code>useEffect()</code> hook to asynchronously call <code>fetch()</code> and update the state variables accordingly.</li>\n<li>Return an object containing the <code>response</code> and <code>error</code> state variables.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useFetch <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>response<span class=\"token punctuation\">,</span> setResponse<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>error<span class=\"token punctuation\">,</span> setError<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> fetchData <span class=\"token operator\">=</span> <span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> res <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetch</span><span class=\"token punctuation\">(</span>url<span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> json <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> res<span class=\"token punctuation\">.</span><span class=\"token function\">json</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">setResponse</span><span class=\"token punctuation\">(</span>json<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setError</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">fetchData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span> response<span class=\"token punctuation\">,</span> error <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> ImageFetch <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> res <span class=\"token operator\">=</span> <span class=\"token function\">useFetch</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>https<span class=\"token operator\">:</span><span class=\"token operator\">/</span><span class=\"token operator\">/</span>dog<span class=\"token punctuation\">.</span>ceo<span class=\"token operator\">/</span>api<span class=\"token operator\">/</span>breeds<span class=\"token operator\">/</span>image<span class=\"token operator\">/</span>random<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>res<span class=\"token punctuation\">.</span>response<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Loading<span class=\"token operator\">...</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">const</span> imageUrl <span class=\"token operator\">=</span> res<span class=\"token punctuation\">.</span>response<span class=\"token punctuation\">.</span>message<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n      <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>img src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>imageUrl<span class=\"token punctuation\">}</span> alt<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>avatar<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> width<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">400</span><span class=\"token punctuation\">}</span> height<span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>auto<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>ImageFetch <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Implements <code>setInterval</code> in a declarative manner.</p>\n<ul>\n<li>Create a custom hook that takes a <code>callback</code> and a <code>delay</code>.</li>\n<li>Use the <code>useRef()</code> hook to create a <code>ref</code> for the callback function.</li>\n<li>Use a <code>useEffect()</code> hook to remember the latest <code>callback</code> whenever it changes.</li>\n<li>Use a <code>useEffect()</code> hook dependent on <code>delay</code> to set up the interval and clean up.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useInterval <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> savedCallback <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useRef</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\nsavedCallback<span class=\"token punctuation\">.</span>current <span class=\"token operator\">=</span> callback<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\nsavedCallback<span class=\"token punctuation\">.</span><span class=\"token function\">current</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>delay <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> id <span class=\"token operator\">=</span> <span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span>tick<span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">clearInterval</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>delay<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Timer <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>seconds<span class=\"token punctuation\">,</span> setSeconds<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">useInterval</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setSeconds</span><span class=\"token punctuation\">(</span>seconds <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>seconds<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Timer <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Checks if the current environment matches a given media query and returns the appropriate value.</p>\n<ul>\n<li>Check if <code>window</code> and <code>window.matchMedia</code> exist, return <code>whenFalse</code> if not (e.g. SSR environment or unsupported browser).</li>\n<li>Use <code>window.matchMedia()</code> to match the given <code>query</code>, cast its <code>matches</code> property to a boolean and store in a state variable, <code>match</code>, using the <code>useState()</code> hook.</li>\n<li>Use the <code>useEffect()</code> hook to add a listener for changes and to clean up the listeners after the hook is destroyed.</li>\n<li>Return either <code>whenTrue</code> or <code>whenFalse</code> based on the value of <code>match</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useMediaQuery <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>query<span class=\"token punctuation\">,</span> whenTrue<span class=\"token punctuation\">,</span> whenFalse<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> window <span class=\"token operator\">===</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token keyword\">undefined</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">||</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>matchMedia <span class=\"token operator\">===</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token keyword\">undefined</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span> whenFalse<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> mediaQuery <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">matchMedia</span><span class=\"token punctuation\">(</span>query<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>match<span class=\"token punctuation\">,</span> setMatch<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token operator\">!</span>mediaQuery<span class=\"token punctuation\">.</span>matches<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> handler <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setMatch</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token operator\">!</span>mediaQuery<span class=\"token punctuation\">.</span>matches<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmediaQuery<span class=\"token punctuation\">.</span><span class=\"token function\">addListener</span><span class=\"token punctuation\">(</span>handler<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> mediaQuery<span class=\"token punctuation\">.</span><span class=\"token function\">removeListener</span><span class=\"token punctuation\">(</span>handler<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> match <span class=\"token operator\">?</span> whenTrue <span class=\"token operator\">:</span> whenFalse<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> ResponsiveText <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> text <span class=\"token operator\">=</span> <span class=\"token function\">useMediaQuery</span><span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">(</span>max<span class=\"token operator\">-</span>width<span class=\"token operator\">:</span> 400px<span class=\"token punctuation\">)</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n    <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Less than 400px wide<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n    <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>More than 400px wide<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>text<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>ResponsiveText <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Checks if the client is online or offline.</p>\n<ul>\n<li>Create a function, <code>getOnLineStatus</code>, that uses the <code>NavigatorOnLine</code> web API to get the online status of the client.</li>\n<li>Use the <code>useState()</code> hook to create an appropriate state variable, <code>status</code>, and setter.</li>\n<li>Use the <code>useEffect()</code> hook to add listeners for appropriate events, updating state, and cleanup those listeners when unmounting.</li>\n<li>Finally return the <code>status</code> state variable.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> getOnLineStatus <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">typeof</span> navigator <span class=\"token operator\">!==</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token keyword\">undefined</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token keyword\">typeof</span> navigator<span class=\"token punctuation\">.</span>onLine <span class=\"token operator\">===</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>boolean<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>\n    <span class=\"token operator\">?</span> navigator<span class=\"token punctuation\">.</span>onLine\n    <span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> useNavigatorOnLine <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>status<span class=\"token punctuation\">,</span> setStatus<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token function\">getOnLineStatus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> setOnline <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setStatus</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> setOffline <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setStatus</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>online<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> setOnline<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>offline<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> setOffline<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n      window<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>online<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> setOnline<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      window<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>offline<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> setOffline<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> status<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> StatusIndicator <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> isOnline <span class=\"token operator\">=</span> <span class=\"token function\">useNavigatorOnLine</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>You are <span class=\"token punctuation\">{</span>isOnline <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>online<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>offline<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>StatusIndicator <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Returns a stateful value, persisted in <code>localStorage</code>, and a function to update it.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to initialize the <code>value</code> to <code>defaultValue</code>.</li>\n<li>Use the <code>useRef()</code> hook to create a ref that will hold the <code>name</code> of the value in <code>localStorage</code>.</li>\n<li>Use 3 instances of the <code>useEffect()</code> hook for initialization, <code>value</code> change and <code>name</code> change respectively.</li>\n<li>When the component is first mounted, use <code>Storage.getItem()</code> to update <code>value</code> if there's a stored value or <code>Storage.setItem()</code> to persist the current value.</li>\n<li>When <code>value</code> is updated, use <code>Storage.setItem()</code> to store the new value.</li>\n<li>When <code>name</code> is updated, use <code>Storage.setItem()</code> to create the new key, update the <code>nameRef</code> and use <code>Storage.removeItem()</code> to remove the previous key from <code>localStorage</code>.</li>\n<li>\n<strong>NOTE:</strong> The hook is meant for use with primitive values (i.e. not objects) and doesn't account for changes to <code>localStorage</code> due to other code. Both of these issues can be easily handled (e.g. JSON serialization and handling the <code>'storage'</code> event).</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> usePersistedState <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> defaultValue<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> setValue<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>defaultValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> nameRef <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useRef</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> storedValue <span class=\"token operator\">=</span> localStorage<span class=\"token punctuation\">.</span><span class=\"token function\">getItem</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>storedValue <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token function\">setValue</span><span class=\"token punctuation\">(</span>storedValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">else</span> localStorage<span class=\"token punctuation\">.</span><span class=\"token function\">setItem</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> defaultValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setValue</span><span class=\"token punctuation\">(</span>defaultValue<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\nlocalStorage<span class=\"token punctuation\">.</span><span class=\"token function\">setItem</span><span class=\"token punctuation\">(</span>nameRef<span class=\"token punctuation\">.</span>current<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> lastName <span class=\"token operator\">=</span> nameRef<span class=\"token punctuation\">.</span>current<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>name <span class=\"token operator\">!==</span> lastName<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\nlocalStorage<span class=\"token punctuation\">.</span><span class=\"token function\">setItem</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nnameRef<span class=\"token punctuation\">.</span>current <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\nlocalStorage<span class=\"token punctuation\">.</span><span class=\"token function\">removeItem</span><span class=\"token punctuation\">(</span>lastName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>name<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> setValue<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> MyComponent <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> name <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>val<span class=\"token punctuation\">,</span> setVal<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">usePersistedState</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n    <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input\n      value<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>val<span class=\"token punctuation\">}</span>\n      onChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">setVal</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n    <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> MyApp <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>name<span class=\"token punctuation\">,</span> setName<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>my<span class=\"token operator\">-</span>value<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>MyComponent name<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>input\nvalue<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>name<span class=\"token punctuation\">}</span>\nonChange<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setName</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n<span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>MyApp <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Stores the previous state or props.</p>\n<ul>\n<li>Create a custom hook that takes a <code>value</code>.</li>\n<li>Use the <code>useRef()</code> hook to create a <code>ref</code> for the <code>value</code>.</li>\n<li>Use the <code>useEffect()</code> hook to remember the latest <code>value</code>.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> usePrevious <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> ref <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useRef</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  React<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    ref<span class=\"token punctuation\">.</span>current <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> ref<span class=\"token punctuation\">.</span>current<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Counter <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> setValue<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">const</span> lastValue <span class=\"token operator\">=</span> <span class=\"token function\">usePrevious</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token literal-property property\">Current</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>value<span class=\"token punctuation\">}</span> <span class=\"token operator\">-</span> Previous<span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>lastValue<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setValue</span><span class=\"token punctuation\">(</span>value <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Increment<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Counter <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Checks if the code is running on the browser or the server.</p>\n<ul>\n<li>Create a custom hook that returns an appropriate object.</li>\n<li>Use <code>typeof window</code>, <code>window.document</code> and <code>Document.createElement()</code> to check if the code is running on the browser.</li>\n<li>Use the <code>useState()</code> hook to define the <code>inBrowser</code> state variable.</li>\n<li>Use the <code>useEffect()</code> hook to update the <code>inBrowser</code> state variable and clean up at the end.</li>\n<li>Use the <code>useMemo()</code> hook to memoize the return values of the custom hook.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> isDOMavailable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>\n  <span class=\"token keyword\">typeof</span> window <span class=\"token operator\">!==</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token keyword\">undefined</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span>\n  window<span class=\"token punctuation\">.</span>document <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span>\n  window<span class=\"token punctuation\">.</span>document<span class=\"token punctuation\">.</span>createElement\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> useSSR <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>inBrowser<span class=\"token punctuation\">,</span> setInBrowser<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>isDOMavailable<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setInBrowser</span><span class=\"token punctuation\">(</span>isDOMavailable<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token function\">setInBrowser</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> useSSRObject <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useMemo</span><span class=\"token punctuation\">(</span>\n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n<span class=\"token literal-property property\">isBrowser</span><span class=\"token operator\">:</span> inBrowser<span class=\"token punctuation\">,</span>\n<span class=\"token literal-property property\">isServer</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span>inBrowser<span class=\"token punctuation\">,</span>\n<span class=\"token literal-property property\">canUseWorkers</span><span class=\"token operator\">:</span> <span class=\"token keyword\">typeof</span> Worker <span class=\"token operator\">!==</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token keyword\">undefined</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span>\n<span class=\"token literal-property property\">canUseEventListeners</span><span class=\"token operator\">:</span> inBrowser <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>window<span class=\"token punctuation\">.</span>addEventListener<span class=\"token punctuation\">,</span>\n<span class=\"token literal-property property\">canUseViewport</span><span class=\"token operator\">:</span> inBrowser <span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span><span class=\"token operator\">&amp;</span>amp<span class=\"token punctuation\">;</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>window<span class=\"token punctuation\">.</span>screen<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">[</span>inBrowser<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useMemo</span><span class=\"token punctuation\">(</span>\n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">assign</span><span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span><span class=\"token function\">values</span><span class=\"token punctuation\">(</span>useSSRObject<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> useSSRObject<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">[</span>inBrowser<span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> SSRChecker <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> <span class=\"token punctuation\">{</span> isBrowser<span class=\"token punctuation\">,</span> isServer <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token function\">useSSR</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>isBrowser <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Running on browser<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Running on server<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>SSRChecker <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Implements <code>setTimeout</code> in a declarative manner.</p>\n<ul>\n<li>Create a custom hook that takes a <code>callback</code> and a <code>delay</code>.</li>\n<li>Use the <code>useRef()</code> hook to create a <code>ref</code> for the callback function.</li>\n<li>Use the <code>useEffect()</code> hook to remember the latest callback.</li>\n<li>Use the <code>useEffect()</code> hook to set up the timeout and clean up.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useTimeout <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>callback<span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> savedCallback <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useRef</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\nsavedCallback<span class=\"token punctuation\">.</span>current <span class=\"token operator\">=</span> callback<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>callback<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">tick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\nsavedCallback<span class=\"token punctuation\">.</span><span class=\"token function\">current</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>delay <span class=\"token operator\">!==</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">let</span> id <span class=\"token operator\">=</span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>tick<span class=\"token punctuation\">,</span> delay<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>delay<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> OneSecondTimer <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>props<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>seconds<span class=\"token punctuation\">,</span> setSeconds<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">useTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setSeconds</span><span class=\"token punctuation\">(</span>seconds <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>seconds<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>OneSecondTimer <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Provides a boolean state variable that can be toggled between its two states.</p>\n<ul>\n<li>Use the <code>useState()</code> hook to create the <code>value</code> state variable and its setter.</li>\n<li>Create a function that toggles the value of the <code>value</code> state variable and memoize it, using the <code>useCallback()</code> hook.</li>\n<li>Return the <code>value</code> state variable and the memoized toggler function.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useToggler <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>initialState<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> setValue<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useState</span><span class=\"token punctuation\">(</span>initialState<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> toggleValue <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useCallback</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token function\">setValue</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>prev<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token operator\">!</span>prev<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">,</span> toggleValue<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> Switch <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>val<span class=\"token punctuation\">,</span> toggleVal<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">useToggler</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>button onClick<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>toggleVal<span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">{</span>val <span class=\"token operator\">?</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token constant\">ON</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span> <span class=\"token operator\">:</span> <span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token constant\">OFF</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>Switch <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<p>Handles the <code>beforeunload</code> window event.</p>\n<ul>\n<li>Use the <code>useRef()</code> hook to create a ref for the callback function, <code>fn</code>.</li>\n<li>Use the <code>useEffect()</code> hook and <code>EventTarget.addEventListener()</code> to handle the <code>'beforeunload'</code> (when the user is about to close the window).</li>\n<li>Use <code>EventTarget.removeEventListener()</code> to perform cleanup after the component is unmounted.</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> useUnload <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> cb <span class=\"token operator\">=</span> React<span class=\"token punctuation\">.</span><span class=\"token function\">useRef</span><span class=\"token punctuation\">(</span>fn<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nReact<span class=\"token punctuation\">.</span><span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n<span class=\"token keyword\">const</span> onUnload <span class=\"token operator\">=</span> cb<span class=\"token punctuation\">.</span>current<span class=\"token punctuation\">;</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>beforeunload<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> onUnload<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>beforeunload<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> onUnload<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>cb<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">const</span> App <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">useUnload</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">=</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">{</span>\n    e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">const</span> exit <span class=\"token operator\">=</span> <span class=\"token function\">confirm</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>Are you sure you want to leave<span class=\"token operator\">?</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>exit<span class=\"token punctuation\">)</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">close</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span>Try closing the window<span class=\"token punctuation\">.</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nReactDOM<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>lt<span class=\"token punctuation\">;</span>App <span class=\"token operator\">/</span><span class=\"token operator\">&amp;</span>gt<span class=\"token punctuation\">;</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span>root<span class=\"token operator\">&amp;</span>quot<span class=\"token punctuation\">;</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr />\n</details>"},{"url":"/interview-questions-js/","relativePath":"interview-questions-js.md","relativeDir":"","base":"interview-questions-js.md","name":"interview-questions-js","frontmatter":{"title":"JS-Intervew-2","subtitle":"Object Oriented JavaScript","date":"2021-09-11","thumb_image_alt":"big o","excerpt":"What are the possible ways to create objects in JavaScript","seo":{"title":"Javascript Interview Questions Part 2","description":"What are the possible ways to create objects in JavaScript","robots":[],"extra":[{"name":"og:image","value":"images/js-code-spiral-num.png","keyName":"property","relativeUrl":true},{"name":"twitter:title","value":"JS-Interview","keyName":"name","relativeUrl":false},{"name":"twitter:description","value":"What are the possible ways to create objects in JavaScript","keyName":"name","relativeUrl":false}]},"template":"post","thumb_image":"images/bigo.jpg","image":"images/green-spruce-4e3a1745.png"},"html":"<h2>Javascript Interview Questions</h2>\n<ol>\n<li>\n<p>What are the possible ways to create objects in JavaScript</p>\n<p>There are many ways to create objects in javascript as below</p>\n<ol>\n<li>\n<p><strong>Object constructor:</strong></p>\n<p>The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Object's create method:</strong></p>\n<p>The create method of Object creates a new object by passing the prototype object as a parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Object literal syntax:</strong></p>\n<p>The object literal syntax is equivalent to create method when it passes null as parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Function constructor:</strong></p>\n<p>Create any function and apply the new operator to create object instances,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">21</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Sudheer'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Function constructor with prototype:</strong></p>\n<p>This is similar to function constructor but it uses prototype for their properties and methods,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Sudheer'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is equivalent to an instance created with an object create method with a function prototype and then call that function with an instance and parameters as arguments.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> func <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">func</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> z<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>(OR)</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// Create a new instance using function prototype.</span>\n<span class=\"token keyword\">var</span> newInstance <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>func<span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Call the function</span>\n<span class=\"token keyword\">var</span> result <span class=\"token operator\">=</span> <span class=\"token function\">func</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>newInstance<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> z<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token comment\">// If the result is a non-null object then use it otherwise just use the new instance.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> result <span class=\"token operator\">===</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">?</span> result <span class=\"token operator\">:</span> newInstance<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>ES6 Class syntax:</strong></p>\n<p>ES6 introduces class feature to create the objects</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Person</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Sudheer'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Singleton pattern:</strong></p>\n<p>A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance and this way one can ensure that they don't accidentally create multiple instances.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Sudheer'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n</ol>\n</li>\n<li>\n<p>What is a prototype chain</p>\n<p><strong>Prototype chaining</strong> is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language.</p>\n<p>The prototype on object instance is available through <strong>Object.getPrototypeOf(object)</strong> or *<strong>*proto**</strong> property whereas prototype on constructors function is available through <strong>Object.prototype</strong>.</p>\n<p><img src=\"images/prototype_chain.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>What is the difference between Call, Apply and Bind</p>\n<p>The difference between Call, Apply and Bind can be explained with below examples,</p>\n<p><strong>Call:</strong> The call() method invokes a function with a given <code class=\"language-text\">this</code> value and arguments provided one by one</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> employee1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Rodson'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> employee2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jimmy'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baily'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">greeting1<span class=\"token punctuation\">,</span> greeting2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>greeting1 <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>firstName <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>lastName <span class=\"token operator\">+</span> <span class=\"token string\">', '</span> <span class=\"token operator\">+</span> greeting2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>employee1<span class=\"token punctuation\">,</span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello John Rodson, How are you?</span>\n<span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>employee2<span class=\"token punctuation\">,</span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello Jimmy Baily, How are you?</span></code></pre></div>\n<p><strong>Apply:</strong> Invokes the function with a given <code class=\"language-text\">this</code> value and allows you to pass in arguments as an array</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> employee1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Rodson'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> employee2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jimmy'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baily'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">greeting1<span class=\"token punctuation\">,</span> greeting2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>greeting1 <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>firstName <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>lastName <span class=\"token operator\">+</span> <span class=\"token string\">', '</span> <span class=\"token operator\">+</span> greeting2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>employee1<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello John Rodson, How are you?</span>\n<span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>employee2<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello Jimmy Baily, How are you?</span></code></pre></div>\n<p><strong>bind:</strong> returns a new function, allowing you to pass any number of arguments</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> employee1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Rodson'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> employee2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jimmy'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baily'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">greeting1<span class=\"token punctuation\">,</span> greeting2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>greeting1 <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>firstName <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>lastName <span class=\"token operator\">+</span> <span class=\"token string\">', '</span> <span class=\"token operator\">+</span> greeting2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> inviteEmployee1 <span class=\"token operator\">=</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>employee1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> inviteEmployee2 <span class=\"token operator\">=</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>employee2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">inviteEmployee1</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello John Rodson, How are you?</span>\n<span class=\"token function\">inviteEmployee2</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello Jimmy Baily, How are you?</span></code></pre></div>\n<p>Call and apply are pretty interchangeable. Both execute the current function immediately. You need to decide whether it's easier to send in an array or a comma separated list of arguments. You can remember by treating Call is for <strong>comma</strong> (separated list) and Apply is for <strong>Array</strong>.</p>\n<p>Whereas Bind creates a new function that will have <code class=\"language-text\">this</code> set to the first parameter passed to bind().</p>\n</li>\n<li>\n<p>What is JSON and its common operations</p>\n<p><strong>JSON</strong> is a text-based data format following JavaScript object syntax, which was popularized by <code class=\"language-text\">Douglas Crockford</code>. It is useful when you want to transmit data across a network and it is basically just a text file with an extension of .json, and a MIME type of application/json</p>\n<p><strong>Parsing:</strong> Converting a string to a native object</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Stringification:</strong> converting a native object to a string so it can be transmitted across the network</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the array slice method</p>\n<p>The <strong>slice()</strong> method returns the selected elements in an array as a new array object. It selects the elements starting at the given start argument, and ends at the given optional end argument without including the last element. If you omit the second argument then it selects till the end.</p>\n<p>Some of the examples of this method are,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> arrayIntegers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> arrayIntegers1 <span class=\"token operator\">=</span> arrayIntegers<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [1,2]</span>\n<span class=\"token keyword\">let</span> arrayIntegers2 <span class=\"token operator\">=</span> arrayIntegers<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [3]</span>\n<span class=\"token keyword\">let</span> arrayIntegers3 <span class=\"token operator\">=</span> arrayIntegers<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//returns [5]</span></code></pre></div>\n<p><strong>Note:</strong> Slice method won't mutate the original array but it returns the subset as a new array.</p>\n</li>\n<li>\n<p>What is the purpose of the array splice method</p>\n<p>The <strong>splice()</strong> method is used either adds/removes items to/from an array, and then returns the removed item. The first argument specifies the array position for insertion or deletion whereas the optional second argument indicates the number of elements to be deleted. Each additional argument is added to the array.</p>\n<p>Some of the examples of this method are,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> arrayIntegersOriginal1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> arrayIntegersOriginal2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> arrayIntegersOriginal3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> arrayIntegers1 <span class=\"token operator\">=</span> arrayIntegersOriginal1<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [1, 2]; original array: [3, 4, 5]</span>\n<span class=\"token keyword\">let</span> arrayIntegers2 <span class=\"token operator\">=</span> arrayIntegersOriginal2<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [4, 5]; original array: [1, 2, 3]</span>\n<span class=\"token keyword\">let</span> arrayIntegers3 <span class=\"token operator\">=</span> arrayIntegersOriginal3<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//returns [4]; original array: [1, 2, 3, \"a\", \"b\", \"c\", 5]</span></code></pre></div>\n<p><strong>Note:</strong> Splice method modifies the original array and returns the deleted array.</p>\n</li>\n<li>\n<p>What is the difference between slice and splice</p>\n<p>Some of the major difference in a tabular form</p>\n<table>\n<thead>\n<tr>\n<th>Slice</th>\n<th>Splice</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Doesn't modify the original array(immutable)</td>\n<td>Modifies the original array(mutable)</td>\n</tr>\n<tr>\n<td>Returns the subset of original array</td>\n<td>Returns the deleted elements as array</td>\n</tr>\n<tr>\n<td>Used to pick the elements from array</td>\n<td>Used to insert or delete elements to/from array</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>How do you compare Object and Map</p>\n<p><strong>Objects</strong> are similar to <strong>Maps</strong> in that both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. Due to this reason, Objects have been used as Maps historically. But there are important differences that make using a Map preferable in certain cases.</p>\n<ol>\n<li>The keys of an Object are Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive.</li>\n<li>The keys in Map are ordered while keys added to Object are not. Thus, when iterating over it, a Map object returns keys in order of insertion.</li>\n<li>You can get the size of a Map easily with the size property, while the number of properties in an Object must be determined manually.</li>\n<li>A Map is an iterable and can thus be directly iterated, whereas iterating over an Object requires obtaining its keys in some fashion and iterating over them.</li>\n<li>An Object has a prototype, so there are default keys in the map that could collide with your keys if you're not careful. As of ES5 this can be bypassed by using map = Object.create(null), but this is seldom done.</li>\n<li>A Map may perform better in scenarios involving frequent addition and removal of key pairs.</li>\n</ol>\n</li>\n<li>\n<p>What is the difference between == and === operators</p>\n<p>JavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison. The strict operators take type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables. The strict operators follow the below conditions for different types,</p>\n<ol>\n<li>Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.</li>\n<li>\n<p>Two numbers are strictly equal when they are numerically equal. i.e, Having the same number value.\nThere are two special cases in this,</p>\n<ol>\n<li>NaN is not equal to anything, including NaN.</li>\n<li>Positive and negative zeros are equal to one another.</li>\n</ol>\n</li>\n<li>Two Boolean operands are strictly equal if both are true or both are false.</li>\n<li>Two objects are strictly equal if they refer to the same Object.</li>\n<li>Null and Undefined types are not equal with ===, but equal with ==. i.e,\nnull===undefined --> false but null==undefined --> true</li>\n</ol>\n<p>Some of the example which covers the above cases,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token number\">0</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span>   <span class=\"token comment\">// true</span>\n<span class=\"token number\">0</span> <span class=\"token operator\">===</span> <span class=\"token boolean\">false</span>  <span class=\"token comment\">// false</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">==</span> <span class=\"token string\">\"1\"</span>     <span class=\"token comment\">// true</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">===</span> <span class=\"token string\">\"1\"</span>    <span class=\"token comment\">// false</span>\n<span class=\"token keyword\">null</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">undefined</span> <span class=\"token comment\">// true</span>\n<span class=\"token keyword\">null</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span> <span class=\"token comment\">// false</span>\n<span class=\"token string\">'0'</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span> <span class=\"token comment\">// true</span>\n<span class=\"token string\">'0'</span> <span class=\"token operator\">===</span> <span class=\"token boolean\">false</span> <span class=\"token comment\">// false</span>\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token operator\">==</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> or <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token operator\">===</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">//false, refer different objects in memory</span>\n<span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">==</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> or <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">===</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token comment\">//false, refer different objects in memory</span></code></pre></div>\n</li>\n<li>\n<p>What are lambda or arrow functions</p>\n<p>An arrow function is a shorter syntax for a function expression and does not have its own <strong>this, arguments, super, or new.target</strong>. These functions are best suited for non-method functions, and they cannot be used as constructors.</p>\n</li>\n<li>\n<p>What is a first class function</p>\n<p>In Javascript, functions are first class objects. First-class functions means when functions in that language are treated like any other variable.</p>\n<p>For example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable. For example, in the below example, handler functions assigned to a listener</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">handler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'This is a click handler function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> handler<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a first order function</p>\n<p>First-order function is a function that doesn't accept another function as an argument and doesn't return a function as its return value.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">firstOrder</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I am a first order function!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a higher order function</p>\n<p>Higher-order function is a function that accepts another function as an argument or returns a function as a return value or both.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">firstOrderFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, I am a First order function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">higherOrder</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">ReturnFirstOrderFunc</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">ReturnFirstOrderFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">higherOrder</span><span class=\"token punctuation\">(</span>firstOrderFunc<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a unary function</p>\n<p>Unary function (i.e. monadic) is a function that accepts exactly one argument. It stands for a single argument accepted by a function.</p>\n<p>Let us take an example of unary function,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">unaryFunction</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">+</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Add 10 to the given argument and display the value</span></code></pre></div>\n</li>\n<li>\n<p>What is the currying function</p>\n<p>Currying is the process of taking a function with multiple arguments and turning it into a sequence of functions each with only a single argument. Currying is named after a mathematician <strong>Haskell Curry</strong>. By applying currying, a n-ary function turns it into a unary function.</p>\n<p>Let's take an example of n-ary function and how it turns into a currying function,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">multiArgFunction</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">multiArgFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 6</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">curryUnaryFunction</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c<span class=\"token punctuation\">;</span>\n<span class=\"token function\">curryUnaryFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a function: b => c =>  1 + b + c</span>\n<span class=\"token function\">curryUnaryFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a function: c => 3 + c</span>\n<span class=\"token function\">curryUnaryFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns the number 6</span></code></pre></div>\n<p>Curried functions are great to improve <strong>code reusability</strong> and <strong>functional composition</strong>.</p>\n</li>\n<li>\n<p>What is a pure function</p>\n<p>A <strong>Pure function</strong> is a function where the return value is only determined by its arguments without any side effects. i.e, If you call a function with the same arguments 'n' number of times and 'n' number of places in the application then it will always return the same value.</p>\n<p>Let's take an example to see the difference between pure and impure functions,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//Impure</span>\n<span class=\"token keyword\">let</span> numberArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">impureAddNumber</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> numberArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//Pure</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">pureAddNumber</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">argNumberArray</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> argNumberArray<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>number<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//Display the results</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">impureAddNumber</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns 1</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numberArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [6]</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">pureAddNumber</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>numberArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [6, 7]</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numberArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [6]</span></code></pre></div>\n<p>As per above code snippets, <strong>Push</strong> function is impure itself by altering the array and returning an push number index which is independent of parameter value. Whereas <strong>Concat</strong> on the other hand takes the array and concatenates it with the other array producing a whole new array without side effects. Also, the return value is a concatenation of the previous array.</p>\n<p>Remember that Pure functions are important as they simplify unit testing without any side effects and no need for dependency injection. They also avoid tight coupling and make it harder to break your application by not having any side effects. These principles are coming together with <strong>Immutability</strong> concept of ES6 by giving preference to <strong>const</strong> over <strong>let</strong> usage.</p>\n</li>\n<li>\n<p>What is the purpose of the let keyword</p>\n<p>The <code class=\"language-text\">let</code> statement declares a <strong>block scope local variable</strong>. Hence the variables defined with let keyword are limited in scope to the block, statement, or expression on which it is used. Whereas variables declared with the <code class=\"language-text\">var</code> keyword used to define a variable globally, or locally to an entire function regardless of block scope.</p>\n<p>Let's take an example to demonstrate the usage,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token number\">30</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>counter <span class=\"token operator\">===</span> <span class=\"token number\">30</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token number\">31</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>counter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 31</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>counter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 30 (because the variable in if block won't exist here)</span></code></pre></div>\n</li>\n<li>\n<p>What is the difference between let and var</p>\n<p>You can list out the differences in a tabular format</p>\n<table>\n<thead>\n<tr>\n<th>var</th>\n<th>let</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is been available from the beginning of JavaScript</td>\n<td>Introduced as part of ES6</td>\n</tr>\n<tr>\n<td>It has function scope</td>\n<td>It has block scope</td>\n</tr>\n<tr>\n<td>Variables will be hoisted</td>\n<td>Hoisted but not initialized</td>\n</tr>\n</tbody>\n</table>\n<p>Let's take an example to see the difference,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">userDetails</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">username</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>username<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>salary<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// undefined due to hoisting</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ReferenceError: Cannot access 'age' before initialization</span>\n        <span class=\"token keyword\">let</span> age <span class=\"token operator\">=</span> <span class=\"token number\">30</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">var</span> salary <span class=\"token operator\">=</span> <span class=\"token number\">10000</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>salary<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//10000 (accessible to due function scope)</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//error: age is not defined(due to block scope)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">userDetails</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the reason to choose the name let as a keyword</p>\n<p><code class=\"language-text\">let</code> is a mathematical statement that was adopted by early programming languages like <strong>Scheme</strong> and <strong>Basic</strong>. It has been borrowed from dozens of other languages that use <code class=\"language-text\">let</code> already as a traditional keyword as close to <code class=\"language-text\">var</code> as possible.</p>\n</li>\n<li>\n<p>How do you redeclare variables in switch block without an error</p>\n<p>If you try to redeclare variables in a <code class=\"language-text\">switch block</code> then it will cause errors because there is only one block. For example, the below code block throws a syntax error as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">0</span><span class=\"token operator\">:</span>\n        <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">case</span> <span class=\"token number\">1</span><span class=\"token operator\">:</span>\n        <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span> <span class=\"token comment\">// SyntaxError for redeclaration.</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To avoid this error, you can create a nested block inside a case clause and create a new block scoped lexical environment.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">0</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">1</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span> <span class=\"token comment\">// No SyntaxError for redeclaration.</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What is the Temporal Dead Zone</p>\n<p>The Temporal Dead Zone is a behavior in JavaScript that occurs when declaring a variable with the let and const keywords, but not with var. In ECMAScript 6, accessing a <code class=\"language-text\">let</code> or <code class=\"language-text\">const</code> variable before its declaration (within its scope) causes a ReferenceError. The time span when that happens, between the creation of a variable's binding and its declaration, is called the temporal dead zone.</p>\n<p>Let's see this behavior with an example,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">somemethod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>counter1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// undefined</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>counter2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ReferenceError</span>\n    <span class=\"token keyword\">var</span> counter1 <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> counter2 <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What is IIFE(Immediately Invoked Function Expression)</p>\n<p>IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. The signature of it would be as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// logic here</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The primary reason to use an IIFE is to obtain data privacy because any variables declared within the IIFE cannot be accessed by the outside world. i.e, If you try to access variables with IIFE then it throws an error as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> message <span class=\"token operator\">=</span> <span class=\"token string\">'IIFE'</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//Error: message is not defined</span></code></pre></div>\n</li>\n<li>\n<p>What is the benefit of using modules</p>\n<p>There are a lot of benefits to using modules in favour of a sprawling. Some of the benefits are,</p>\n<ol>\n<li>Maintainability</li>\n<li>Reusability</li>\n<li>Namespacing</li>\n</ol>\n</li>\n<li>\n<p>What is memoization</p>\n<p>Memoization is a programming technique which attempts to increase a function's performance by caching its previously computed results. Each time a memoized function is called, its parameters are used to index the cache. If the data is present, then it can be returned, without executing the entire function. Otherwise the function is executed and then the result is added to the cache.\nLet's take an example of adding function with memoization,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">memoizAddition</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> cache <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token keyword\">in</span> cache<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Fetching from cache'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> cache<span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Here, cache.value cannot be used as property name starts with the number which is not a valid JavaScript  identifier. Hence, can only be accessed using the square bracket notation.</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Calculating result'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> value <span class=\"token operator\">+</span> <span class=\"token number\">20</span><span class=\"token punctuation\">;</span>\n            cache<span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> result<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// returned function from memoizAddition</span>\n<span class=\"token keyword\">const</span> addition <span class=\"token operator\">=</span> <span class=\"token function\">memoizAddition</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">addition</span><span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//output: 40 calculated</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">addition</span><span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//output: 40 cached</span></code></pre></div>\n</li>\n<li>\n<p>What is Hoisting</p>\n<p>Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialisation.\nLet's take a simple example of variable hoisting,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//output : undefined</span>\n<span class=\"token keyword\">var</span> message <span class=\"token operator\">=</span> <span class=\"token string\">'The variable Has been hoisted'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The above code looks like as below to the interpreter,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> message<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmessage <span class=\"token operator\">=</span> <span class=\"token string\">'The variable Has been hoisted'</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What are classes in ES6</p>\n<p>In ES6, Javascript classes are primarily syntactic sugar over JavaScript's existing prototype-based inheritance.\nFor example, the prototype based inheritance written in function expression as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Bike</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">model<span class=\"token punctuation\">,</span> color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Bike</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getDetails</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">+</span> <span class=\"token string\">' bike has'</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">+</span> <span class=\"token string\">' color'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Whereas ES6 classes can be defined as an alternative</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Bike</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">color<span class=\"token punctuation\">,</span> model</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getDetails</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">+</span> <span class=\"token string\">' bike has'</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">+</span> <span class=\"token string\">' color'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What are closures</p>\n<p>A closure is the combination of a function and the lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function's variables. The closure has three scope chains</p>\n<ol>\n<li>Own scope where variables defined between its curly brackets</li>\n<li>Outer function's variables</li>\n<li>Global variables</li>\n</ol>\n<p>Let's take an example of closure concept,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Welcome</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">greetingInfo</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">message</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> greetingInfo<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> myFunction <span class=\"token operator\">=</span> <span class=\"token function\">Welcome</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Welcome '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//Output: Welcome John</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello Mr.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//output: Hello Mr.John</span></code></pre></div>\n<p>As per the above code, the inner function(i.e, greetingInfo) has access to the variables in the outer function scope(i.e, Welcome) even after the outer function has returned.</p>\n</li>\n<li>\n<p>What are modules</p>\n<p>Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. Most of the JavaScript modules export an object literal, a function, or a constructor</p>\n</li>\n<li>\n<p>Why do you need modules</p>\n<p>Below are the list of benefits using modules in javascript ecosystem</p>\n<ol>\n<li>Maintainability</li>\n<li>Reusability</li>\n<li>Namespacing</li>\n</ol>\n</li>\n<li>\n<p>What is scope in javascript</p>\n<p>Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime. In other words, scope determines the visibility of variables and other resources in areas of your code.</p>\n</li>\n<li>\n<p>What is a service worker</p>\n<p>A Service worker is basically a script (JavaScript file) that runs in the background, separate from a web page and provides features that don't need a web page or user interaction. Some of the major features of service workers are Rich offline experiences(offline first web application development), periodic background syncs, push notifications, intercept and handle network requests and programmatically managing a cache of responses.</p>\n</li>\n<li>\n<p>How do you manipulate DOM using a service worker</p>\n<p>Service worker can't access the DOM directly. But it can communicate with the pages it controls by responding to messages sent via the <code class=\"language-text\">postMessage</code> interface, and those pages can manipulate the DOM.</p>\n</li>\n<li>\n<p>How do you reuse information across service worker restarts</p>\n<p>The problem with service worker is that it gets terminated when not in use, and restarted when it's next needed, so you cannot rely on global state within a service worker's <code class=\"language-text\">onfetch</code> and <code class=\"language-text\">onmessage</code> handlers. In this case, service workers will have access to IndexedDB API in order to persist and reuse across restarts.</p>\n</li>\n<li>\n<p>What is IndexedDB</p>\n<p>IndexedDB is a low-level API for client-side storage of larger amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data.</p>\n</li>\n<li>\n<p>What is web storage</p>\n<p>Web storage is an API that provides a mechanism by which browsers can store key/value pairs locally within the user's browser, in a much more intuitive fashion than using cookies. The web storage provides two mechanisms for storing data on the client.</p>\n<ol>\n<li><strong>Local storage:</strong> It stores data for current origin with no expiration date.</li>\n<li><strong>Session storage:</strong> It stores data for one session and the data is lost when the browser tab is closed.</li>\n</ol>\n</li>\n<li>\n<p>What is a post message</p>\n<p>Post message is a method that enables cross-origin communication between Window objects.(i.e, between a page and a pop-up that it spawned, or between a page and an iframe embedded within it). Generally, scripts on different pages are allowed to access each other if and only if the pages follow same-origin policy(i.e, pages share the same protocol, port number, and host).</p>\n</li>\n<li>\n<p>What is a Cookie</p>\n<p>A cookie is a piece of data that is stored on your computer to be accessed by your browser. Cookies are saved as key/value pairs.\nFor example, you can create a cookie named username as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> <span class=\"token string\">'username=John'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><img src=\"images/cookie.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>Why do you need a Cookie</p>\n<p>Cookies are used to remember information about the user profile(such as username). It basically involves two steps,</p>\n<ol>\n<li>When a user visits a web page, the user profile can be stored in a cookie.</li>\n<li>Next time the user visits the page, the cookie remembers the user profile.</li>\n</ol>\n</li>\n<li>\n<p>What are the options in a cookie</p>\n<p>There are few below options available for a cookie,</p>\n<ol>\n<li>By default, the cookie is deleted when the browser is closed but you can change this behavior by setting expiry date (in UTC time).</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> <span class=\"token string\">'username=John; expires=Sat, 8 Jun 2019 12:00:00 UTC'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li>By default, the cookie belongs to a current page. But you can tell the browser what path the cookie belongs to using a path parameter.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> <span class=\"token string\">'username=John; path=/services'</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>How do you delete a cookie</p>\n<p>You can delete a cookie by setting the expiry date as a passed date. You don't need to specify a cookie value in this case.\nFor example, you can delete a username cookie in the current page as below.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> <span class=\"token string\">'username=; expires=Fri, 07 Jun 2019 00:00:00 UTC; path=/;'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Note:</strong> You should define the cookie path option to ensure that you delete the right cookie. Some browsers doesn't allow to delete a cookie unless you specify a path parameter.</p>\n</li>\n<li>\n<p>What are the differences between cookie, local storage and session storage</p>\n<p>Below are some of the differences between cookie, local storage and session storage,</p>\n<table>\n<thead>\n<tr>\n<th>Feature</th>\n<th>Cookie</th>\n<th>Local storage</th>\n<th>Session storage</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Accessed on client or server side</td>\n<td>Both server-side &#x26; client-side</td>\n<td>client-side only</td>\n<td>client-side only</td>\n</tr>\n<tr>\n<td>Lifetime</td>\n<td>As configured using Expires option</td>\n<td>until deleted</td>\n<td>until tab is closed</td>\n</tr>\n<tr>\n<td>SSL support</td>\n<td>Supported</td>\n<td>Not supported</td>\n<td>Not supported</td>\n</tr>\n<tr>\n<td>Maximum data size</td>\n<td>4KB</td>\n<td>5 MB</td>\n<td>5MB</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What is the main difference between localStorage and sessionStorage</p>\n<p>LocalStorage is the same as SessionStorage but it persists the data even when the browser is closed and reopened(i.e it has no expiration time) whereas in sessionStorage data gets cleared when the page session ends.</p>\n</li>\n<li>\n<p>How do you access web storage</p>\n<p>The Window object implements the <code class=\"language-text\">WindowLocalStorage</code> and <code class=\"language-text\">WindowSessionStorage</code> objects which has <code class=\"language-text\">localStorage</code>(window.localStorage) and <code class=\"language-text\">sessionStorage</code>(window.sessionStorage) properties respectively. These properties create an instance of the Storage object, through which data items can be set, retrieved and removed for a specific domain and storage type (session or local).\nFor example, you can read and write on local storage objects as below</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">localStorage<span class=\"token punctuation\">.</span><span class=\"token function\">setItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'logo'</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'logo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nlocalStorage<span class=\"token punctuation\">.</span><span class=\"token function\">getItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'logo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What are the methods available on session storage</p>\n<p>The session storage provided methods for reading, writing and clearing the session data</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// Save data to sessionStorage</span>\nsessionStorage<span class=\"token punctuation\">.</span><span class=\"token function\">setItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'key'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Get saved data from sessionStorage</span>\n<span class=\"token keyword\">let</span> data <span class=\"token operator\">=</span> sessionStorage<span class=\"token punctuation\">.</span><span class=\"token function\">getItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'key'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Remove saved data from sessionStorage</span>\nsessionStorage<span class=\"token punctuation\">.</span><span class=\"token function\">removeItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'key'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Remove all saved data from sessionStorage</span>\nsessionStorage<span class=\"token punctuation\">.</span><span class=\"token function\">clear</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a storage event and its event handler</p>\n<p>The StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events.\nThe syntax would be as below</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">window<span class=\"token punctuation\">.</span>onstorage <span class=\"token operator\">=</span> functionRef<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Let's take the example usage of onstorage event handler which logs the storage key and it's values</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onstorage</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The '</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>key <span class=\"token operator\">+</span> <span class=\"token string\">' key has been changed from '</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>oldValue <span class=\"token operator\">+</span> <span class=\"token string\">' to '</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>newValue <span class=\"token operator\">+</span> <span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>Why do you need web storage</p>\n<p>Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Also, the information is never transferred to the server. Hence this is a more recommended approach than Cookies.</p>\n</li>\n<li>\n<p>How do you check web storage browser support</p>\n<p>You need to check browser support for localStorage and sessionStorage before using web storage,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> Storage <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Code for localStorage/sessionStorage.</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Sorry! No Web Storage support..</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>How do you check web workers browser support</p>\n<p>You need to check browser support for web workers before using it</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> Worker <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// code for Web worker support.</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Sorry! No Web Worker support..</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>Give an example of a web worker</p>\n<p>You need to follow below steps to start using web workers for counting example</p>\n<ol>\n<li>Create a Web Worker File: You need to write a script to increment the count value. Let's name it as counter.js</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">timedCount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">postMessage</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token string\">'timedCount()'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">500</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">timedCount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here postMessage() method is used to post a message back to the HTML page</p>\n<ol>\n<li>Create a Web Worker Object: You can create a web worker object by checking for browser support. Let's name this file as web<em>worker</em>example.js</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> w <span class=\"token operator\">==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    w <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Worker</span><span class=\"token punctuation\">(</span><span class=\"token string\">'counter.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>and we can receive messages from web worker</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">w<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onmessage</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'message'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> event<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li>Terminate a Web Worker:\nWeb workers will continue to listen for messages (even after the external script is finished) until it is terminated. You can use the terminate() method to terminate listening to the messages.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">w<span class=\"token punctuation\">.</span><span class=\"token function\">terminate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li>Reuse the Web Worker: If you set the worker variable to undefined you can reuse the code</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">w <span class=\"token operator\">=</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What are the restrictions of web workers on DOM</p>\n<p>WebWorkers don't have access to below javascript objects since they are defined in an external files</p>\n<ol>\n<li>Window object</li>\n<li>Document object</li>\n<li>Parent object</li>\n</ol>\n</li>\n<li>\n<p>What is a promise</p>\n<p>A promise is an object that may produce a single value some time in the future with either a resolved value or a reason that it's not resolved(for example, network error). It will be in one of the 3 possible states: fulfilled, rejected, or pending.</p>\n<p>The syntax of Promise creation looks like below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// promise description</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The usage of a promise would be as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm a Promise!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\npromise<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The action flow of a promise will be as below,</p>\n<p><img src=\"images/promises.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>Why do you need a promise</p>\n<p>Promises are used to handle asynchronous operations. They provide an alternative approach for callbacks by reducing the callback hell and writing the cleaner code.</p>\n</li>\n<li>\n<p>What are the three states of promise</p>\n<p>Promises have three states:</p>\n<ol>\n<li><strong>Pending:</strong> This is an initial state of the Promise before an operation begins</li>\n<li><strong>Fulfilled:</strong> This state indicates that the specified operation was completed.</li>\n<li><strong>Rejected:</strong> This state indicates that the operation did not complete. In this case an error value will be thrown.</li>\n</ol>\n</li>\n<li>\n<p>What is a callback function</p>\n<p>A callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action.\nLet's take a simple example of how to use callback function</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">callbackFunction</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello '</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">outerFunction</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> name <span class=\"token operator\">=</span> <span class=\"token function\">prompt</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Please enter your name.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">outerFunction</span><span class=\"token punctuation\">(</span>callbackFunction<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>Why do we need callbacks</p>\n<p>The callbacks are needed because javascript is an event driven language. That means instead of waiting for a response javascript will keep executing while listening for other events.\nLet's take an example with the first function invoking an API call(simulated by setTimeout) and the next function which logs the message.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">firstFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Simulate a code delay</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'First function called'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">secondFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Second function called'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">firstFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">secondFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nOutput<span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Second function called</span>\n<span class=\"token comment\">// First function called</span></code></pre></div>\n<p>As observed from the output, javascript didn't wait for the response of the first function and the remaining code block got executed. So callbacks are used in a way to make sure that certain code doesn't execute until the other code finishes execution.</p>\n</li>\n<li>\n<p>What is a callback hell</p>\n<p>Callback Hell is an anti-pattern with multiple nested callbacks which makes code hard to read and debug when dealing with asynchronous logic. The callback hell looks like below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">async1</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function\">async2</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token function\">async3</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n            <span class=\"token function\">async4</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n                <span class=\"token operator\">...</span><span class=\"token punctuation\">.</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What are server-sent events</p>\n<p>Server-sent events (SSE) is a server push technology enabling a browser to receive automatic updates from a server via HTTP connection without resorting to polling. These are a one way communications channel - events flow from server to client only. This has been used in Facebook/Twitter updates, stock price updates, news feeds etc.</p>\n</li>\n<li>\n<p>How do you receive server-sent event notifications</p>\n<p>The EventSource object is used to receive server-sent event notifications. For example, you can receive messages from server as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> EventSource <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> source <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">EventSource</span><span class=\"token punctuation\">(</span><span class=\"token string\">'sse_generator.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    source<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onmessage</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'output'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">+=</span> event<span class=\"token punctuation\">.</span>data <span class=\"token operator\">+</span> <span class=\"token string\">'&lt;br>'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>How do you check browser support for server-sent events</p>\n<p>You can perform browser support for server-sent events before using it as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> EventSource <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Server-sent events supported. Let's have some code here!</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// No server-sent events supported</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What are the events available for server sent events</p>\n<p>Below are the list of events available for server sent events\n| Event | Description |\n|---- | ---------\n| onopen | It is used when a connection to the server is opened |\n| onmessage | This event is used when a message is received |\n| onerror | It happens when an error occurs|</p>\n</li>\n<li>\n<p>What are the main rules of promise</p>\n<p>A promise must follow a specific set of rules,</p>\n<ol>\n<li>A promise is an object that supplies a standard-compliant <code class=\"language-text\">.then()</code> method</li>\n<li>A pending promise may transition into either fulfilled or rejected state</li>\n<li>A fulfilled or rejected promise is settled and it must not transition into any other state.</li>\n<li>Once a promise is settled, the value must not change.</li>\n</ol>\n</li>\n<li>\n<p>What is callback in callback</p>\n<p>You can nest one callback inside in another callback to execute the actions sequentially one by one. This is known as callbacks in callbacks.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">loadScript</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/script1.js'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">script</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'first script is loaded'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">loadScript</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/script2.js'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">script</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'second script is loaded'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token function\">loadScript</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/script3.js'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">script</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'third script is loaded'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token comment\">// after all scripts are loaded</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is promise chaining</p>\n<p>The process of executing a sequence of asynchronous tasks one after another using promises is known as Promise chaining. Let's take an example of promise chaining for calculating the final result,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1</span>\n        <span class=\"token keyword\">return</span> result <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 2</span>\n        <span class=\"token keyword\">return</span> result <span class=\"token operator\">*</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 6</span>\n        <span class=\"token keyword\">return</span> result <span class=\"token operator\">*</span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In the above handlers, the result is passed to the chain of .then() handlers with the below work flow,</p>\n<ol>\n<li>The initial promise resolves in 1 second,</li>\n<li>After that <code class=\"language-text\">.then</code> handler is called by logging the result(1) and then return a promise with the value of result * 2.</li>\n<li>After that the value passed to the next <code class=\"language-text\">.then</code> handler by logging the result(2) and return a promise with result * 3.</li>\n<li>Finally the value passed to the last <code class=\"language-text\">.then</code> handler by logging the result(6) and return a promise with result * 4.</li>\n</ol>\n</li>\n<li>\n<p>What is promise.all</p>\n<p>Promise.all is a promise that takes an array of promises as an input (an iterable), and it gets resolved when all the promises get resolved or any one of them gets rejected. For example, the syntax of promise.all method is below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">Promise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>Promise1<span class=\"token punctuation\">,</span> Promise2<span class=\"token punctuation\">,</span> Promise3<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>   console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Error in promises </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>error<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Note:</strong> Remember that the order of the promises(output the result) is maintained as per input order.</p>\n</li>\n<li>\n<p>What is the purpose of the race method in promise</p>\n<p>Promise.race() method will return the promise instance which is firstly resolved or rejected. Let's take an example of race() method where promise2 is resolved first</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> promise1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">500</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> promise2 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nPromise<span class=\"token punctuation\">.</span><span class=\"token function\">race</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>promise1<span class=\"token punctuation\">,</span> promise2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"two\" // Both promises will resolve, but promise2 is faster</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a strict mode in javascript</p>\n<p>Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a \"strict\" operating context. This way it prevents certain actions from being taken and throws more exceptions. The literal expression <code class=\"language-text\">\"use strict\";</code> instructs the browser to use the javascript code in the Strict mode.</p>\n</li>\n<li>\n<p>Why do you need strict mode</p>\n<p>Strict mode is useful to write \"secure\" JavaScript by notifying \"bad syntax\" into real errors. For example, it eliminates accidentally creating a global variable by throwing an error and also throws an error for assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object.</p>\n</li>\n<li>\n<p>How do you declare strict mode</p>\n<p>The strict mode is declared by adding \"use strict\"; to the beginning of a script or a function.\nIf declared at the beginning of a script, it has global scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\nx <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// This will cause an error because x is not declared</span></code></pre></div>\n<p>and if you declare inside a function, it has local scope</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">x <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// This will not cause an error.</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n    y <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// This will cause an error</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of double exclamation</p>\n<p>The double exclamation or negation(!!) ensures the resulting type is a boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.\nFor example, you can test IE version using this expression as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> isIE8 <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\nisIE8 <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>navigator<span class=\"token punctuation\">.</span>userAgent<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">MSIE 8.0</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>isIE8<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns true or false</span></code></pre></div>\n<p>If you don't use this expression then it returns the original value.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>navigator<span class=\"token punctuation\">.</span>userAgent<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">MSIE 8.0</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns either an Array or null</span></code></pre></div>\n<p><strong>Note:</strong> The expression !! is not an operator, but it is just twice of ! operator.</p>\n</li>\n<li>\n<p>What is the purpose of the delete operator</p>\n<p>The delete keyword is used to delete the property as well as its value.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> user <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">delete</span> user<span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {name: \"John\"}</span></code></pre></div>\n</li>\n<li>\n<p>What is the typeof operator</p>\n<p>You can use the JavaScript typeof operator to find the type of a JavaScript variable. It returns the type of a variable or an expression.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">typeof</span> <span class=\"token string\">'John Abraham'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Returns \"string\"</span>\n<span class=\"token keyword\">typeof</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Returns \"number\"</span></code></pre></div>\n</li>\n<li>\n<p>What is undefined property</p>\n<p>The undefined property indicates that a variable has not been assigned a value, or not declared at all. The type of undefined value is undefined too.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> user<span class=\"token punctuation\">;</span> <span class=\"token comment\">// Value is undefined, type is undefined</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//undefined</span></code></pre></div>\n<p>Any variable can be emptied by setting the value to undefined.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">user <span class=\"token operator\">=</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is null value</p>\n<p>The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values. The type of null value is object.\nYou can empty the variable by setting the value to null.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//object</span></code></pre></div>\n</li>\n<li>\n<p>What is the difference between null and undefined</p>\n<p>Below are the main differences between null and undefined,</p>\n<table>\n<thead>\n<tr>\n<th>Null</th>\n<th>Undefined</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is an assignment value which indicates that variable points to no object.</td>\n<td>It is not an assignment value where a variable has been declared but has not yet been assigned a value.</td>\n</tr>\n<tr>\n<td>Type of null is object</td>\n<td>Type of undefined is undefined</td>\n</tr>\n<tr>\n<td>The null value is a primitive value that represents the null, empty, or non-existent reference.</td>\n<td>The undefined value is a primitive value used when a variable has not been assigned a value.</td>\n</tr>\n<tr>\n<td>Indicates the absence of a value for a variable</td>\n<td>Indicates absence of variable itself</td>\n</tr>\n<tr>\n<td>Converted to zero (0) while performing primitive operations</td>\n<td>Converted to NaN while performing primitive operations</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What is eval</p>\n<p>The eval() function evaluates JavaScript code represented as a string. The string can be a JavaScript expression, variable, statement, or sequence of statements.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">eval</span><span class=\"token punctuation\">(</span><span class=\"token string\">'1 + 2'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//  3</span></code></pre></div>\n</li>\n<li>\n<p>What is the difference between window and document</p>\n<p>Below are the main differences between window and document,</p>\n<table>\n<thead>\n<tr>\n<th>Window</th>\n<th>Document</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is the root level element in any web page</td>\n<td>It is the direct child of the window object. This is also known as Document Object Model(DOM)</td>\n</tr>\n<tr>\n<td>By default window object is available implicitly in the page</td>\n<td>You can access it via window.document or document.</td>\n</tr>\n<tr>\n<td>It has methods like alert(), confirm() and properties like document, location</td>\n<td>It provides methods like getElementById, getElementsByTagName, createElement etc</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>How do you access history in javascript</p>\n<p>The window.history object contains the browser's history. You can load previous and next URLs in the history using back() and next() methods.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">goBack</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span>history<span class=\"token punctuation\">.</span><span class=\"token function\">back</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">goForward</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span>history<span class=\"token punctuation\">.</span><span class=\"token function\">forward</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Note:</strong> You can also access history without window prefix.</p>\n</li>\n<li>\n<p>How do you detect caps lock key turned on or not</p>\n<p>The <code class=\"language-text\">mouseEvent getModifierState()</code> is used to return a boolean value that indicates whether the specified modifier key is activated or not. The modifiers such as CapsLock, ScrollLock and NumLock are activated when they are clicked, and deactivated when they are clicked again.</p>\n<p>Let's take an input element to detect the CapsLock on/off behavior with an example,</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>input</span> <span class=\"token attr-name\">type</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>password<span class=\"token punctuation\">\"</span></span> <span class=\"token special-attr\"><span class=\"token attr-name\">onmousedown</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span><span class=\"token value javascript language-javascript\"><span class=\"token function\">enterInput</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">)</span></span><span class=\"token punctuation\">\"</span></span></span> <span class=\"token punctuation\">/></span></span>\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>p</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>feedback<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>p</span><span class=\"token punctuation\">></span></span>\n\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>script</span><span class=\"token punctuation\">></span></span><span class=\"token script\"><span class=\"token language-javascript\">\n    <span class=\"token keyword\">function</span> <span class=\"token function\">enterInput</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> flag <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getModifierState</span><span class=\"token punctuation\">(</span><span class=\"token string\">'CapsLock'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>flag<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'feedback'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> <span class=\"token string\">'CapsLock activated'</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'feedback'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> <span class=\"token string\">'CapsLock not activated'</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n</span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>script</span><span class=\"token punctuation\">></span></span></code></pre></div>\n</li>\n<li>\n<p>What is isNaN</p>\n<p>The isNaN() function is used to determine whether a value is an illegal number (Not-a-Number) or not. i.e, This function returns true if the value equates to NaN. Otherwise it returns false.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">isNaN</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//true</span>\n<span class=\"token function\">isNaN</span><span class=\"token punctuation\">(</span><span class=\"token string\">'100'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//false</span></code></pre></div>\n</li>\n<li>\n<p>What are the differences between undeclared and undefined variables</p>\n<p>Below are the major differences between undeclared and undefined variables,</p>\n<table>\n<thead>\n<tr>\n<th>undeclared</th>\n<th>undefined</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>These variables do not exist in a program and are not declared</td>\n<td>These variables declared in the program but have not assigned any value</td>\n</tr>\n<tr>\n<td>If you try to read the value of an undeclared variable, then a runtime error is encountered</td>\n<td>If you try to read the value of an undefined variable, an undefined value is returned.</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What are global variables</p>\n<p>Global variables are those that are available throughout the length of the code without any scope. The var keyword is used to declare a local variable but if you omit it then it will become global variable</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">msg <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// var is missing, it becomes global variable</span></code></pre></div>\n</li>\n<li>\n<p>What are the problems with global variables</p>\n<p>The problem with global variables is the conflict of variable names of local and global scope. It is also difficult to debug and test the code that relies on global variables.</p>\n</li>\n<li>\n<p>What is NaN property</p>\n<p>The NaN property is a global property that represents \"Not-a-Number\" value. i.e, It indicates that a value is not a legal number. It is very rare to use NaN in a program but it can be used as return value for few cases</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">Math<span class=\"token punctuation\">.</span><span class=\"token function\">sqrt</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of isFinite function</p>\n<p>The isFinite() function is used to determine whether a number is a finite, legal number. It returns false if the value is +infinity, -infinity, or NaN (Not-a-Number), otherwise it returns true.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">isFinite</span><span class=\"token punctuation\">(</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">isFinite</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">isFinite</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n\n<span class=\"token function\">isFinite</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n</li>\n<li>\n<p>What is an event flow</p>\n<p>Event flow is the order in which event is received on the web page. When you click an element that is nested in various other elements, before your click actually reaches its destination, or target element, it must trigger the click event for each of its parent elements first, starting at the top with the global window object.\nThere are two ways of event flow</p>\n<ol>\n<li>Top to Bottom(Event Capturing)</li>\n<li>Bottom to Top (Event Bubbling)</li>\n</ol>\n</li>\n<li>\n<p>What is event bubbling</p>\n<p>Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors (parents) of the target element in the same nesting hierarchy till it reaches the outermost DOM element.</p>\n</li>\n<li>\n<p>What is event capturing</p>\n<p>Event capturing is a type of event propagation where the event is first captured by the outermost element, and then successively triggers on the descendants (children) of the target element in the same nesting hierarchy till it reaches the innermost DOM element.</p>\n</li>\n<li>\n<p>How do you submit a form using JavaScript</p>\n<p>You can submit a form using <code class=\"language-text\">document.forms[0].submit()</code>. All the form input's information is submitted using onsubmit event handler</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">submit</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    document<span class=\"token punctuation\">.</span>forms<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">submit</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>How do you find operating system details</p>\n<p>The window.navigator object contains information about the visitor's browser OS details. Some of the OS properties are available under platform property,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>navigator<span class=\"token punctuation\">.</span>platform<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the difference between document load and DOMContentLoaded events</p>\n<p>The <code class=\"language-text\">DOMContentLoaded</code> event is fired when the initial HTML document has been completely loaded and parsed, without waiting for assets(stylesheets, images, and subframes) to finish loading. Whereas The load event is fired when the whole page has loaded, including all dependent resources(stylesheets, images).</p>\n</li>\n<li>\n<p>What is the difference between native, host and user objects</p>\n<p><code class=\"language-text\">Native objects</code> are objects that are part of the JavaScript language defined by the ECMAScript specification. For example, String, Math, RegExp, Object, Function etc core objects defined in the ECMAScript spec.\n<code class=\"language-text\">Host objects</code> are objects provided by the browser or runtime environment (Node). For example, window, XmlHttpRequest, DOM nodes etc are considered as host objects.\n<code class=\"language-text\">User objects</code> are objects defined in the javascript code. For example, User objects created for profile information.</p>\n</li>\n<li>\n<p>What are the tools or techniques used for debugging JavaScript code</p>\n<p>You can use below tools or techniques for debugging javascript</p>\n<ol>\n<li>Chrome Devtools</li>\n<li>debugger statement</li>\n<li>Good old console.log statement</li>\n</ol>\n</li>\n<li>\n<p>What are the pros and cons of promises over callbacks</p>\n<p>Below are the list of pros and cons of promises over callbacks,</p>\n<p><strong>Pros:</strong></p>\n<ol>\n<li>It avoids callback hell which is unreadable</li>\n<li>Easy to write sequential asynchronous code with .then()</li>\n<li>Easy to write parallel asynchronous code with Promise.all()</li>\n<li>Solves some of the common problems of callbacks(call the callback too late, too early, many times and swallow errors/exceptions)</li>\n</ol>\n<p><strong>Cons:</strong></p>\n<ol>\n<li>It makes little complex code</li>\n<li>You need to load a polyfill if ES6 is not supported</li>\n</ol>\n</li>\n<li>\n<p>What is the difference between an attribute and a property</p>\n<p>Attributes are defined on the HTML markup whereas properties are defined on the DOM. For example, the below HTML element has 2 attributes type and value,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Name:\"</span><span class=\"token operator\">></span></code></pre></div>\n<p>You can retrieve the attribute value as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> input <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'value'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Good morning</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Good morning</span></code></pre></div>\n<p>And after you change the value of the text field to \"Good evening\", it becomes like</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'value'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Good morning</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Good evening</span></code></pre></div>\n</li>\n<li>\n<p>What is same-origin policy</p>\n<p>The same-origin policy is a policy that prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of URI scheme, hostname, and port number. If you enable this policy then it prevents a malicious script on one page from obtaining access to sensitive data on another web page using Document Object Model(DOM).</p>\n</li>\n<li>\n<p>What is the purpose of void 0</p>\n<p>Void(0) is used to prevent the page from refreshing. This will be helpful to eliminate the unwanted side-effect, because it will return the undefined primitive value. It is commonly used for HTML documents that use href=\"JavaScript:Void(0);\" within an <code class=\"language-text\">&lt;a></code> element. i.e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression.\nFor example, the below link notify the message without reloading the page</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>a href<span class=\"token operator\">=</span><span class=\"token string\">\"JavaScript:void(0);\"</span> onclick<span class=\"token operator\">=</span><span class=\"token string\">\"alert('Well done!')\"</span><span class=\"token operator\">></span>\n    Click Me<span class=\"token operator\">!</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span></code></pre></div>\n</li>\n<li>\n<p>Is JavaScript a compiled or interpreted language</p>\n<p>JavaScript is an interpreted language, not a compiled language. An interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. Nowadays modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.</p>\n</li>\n<li>\n<p>Is JavaScript a case-sensitive language</p>\n<p>Yes, JavaScript is a case sensitive language. The language keywords, variables, function &#x26; object names, and any other identifiers must always be typed with a consistent capitalization of letters.</p>\n</li>\n<li>\n<p>Is there any relation between Java and JavaScript</p>\n<p>No, they are entirely two different programming languages and have nothing to do with each other. But both of them are Object Oriented Programming languages and like many other languages, they follow similar syntax for basic features(if, else, for, switch, break, continue etc).</p>\n</li>\n<li>\n<p>What are events</p>\n<p> Events are \"things\" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can <code class=\"language-text\">react</code> on these events. Some of the examples of HTML events are,</p>\n<ol>\n<li>Web page has finished loading</li>\n<li>Input field was changed</li>\n<li>Button was clicked</li>\n</ol>\n<p> Let's describe the behavior of click event for button element,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span><span class=\"token operator\">!</span>doctype html<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>html<span class=\"token operator\">></span>\n <span class=\"token operator\">&lt;</span>head<span class=\"token operator\">></span>\n   <span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>\n     <span class=\"token keyword\">function</span> <span class=\"token function\">greeting</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n       <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello! Good morning'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n     <span class=\"token punctuation\">}</span>\n   <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span>\n <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>head<span class=\"token operator\">></span>\n <span class=\"token operator\">&lt;</span>body<span class=\"token operator\">></span>\n   <span class=\"token operator\">&lt;</span>button type<span class=\"token operator\">=</span><span class=\"token string\">\"button\"</span> onclick<span class=\"token operator\">=</span><span class=\"token string\">\"greeting()\"</span><span class=\"token operator\">></span>Click me<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>body<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>html<span class=\"token operator\">></span></code></pre></div>\n</li>\n<li>\n<p>Who created javascript</p>\n<p> JavaScript was created by Brendan Eich in 1995 during his time at Netscape Communications. Initially it was developed under the name <code class=\"language-text\">Mocha</code>, but later the language was officially called <code class=\"language-text\">LiveScript</code> when it first shipped in beta releases of Netscape.</p>\n</li>\n<li>\n<p>What is the use of preventDefault method</p>\n<p> The preventDefault() method cancels the event if it is cancelable, meaning that the default action or behaviour that belongs to the event will not occur. For example, prevent form submission when clicking on submit button and prevent opening the page URL when clicking on hyperlink are some common use cases.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'link'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    event<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p> <strong>Note:</strong> Remember that not all events are cancelable.</p>\n</li>\n<li>\n<p>What is the use of stopPropagation method</p>\n<p> The stopPropagation method is used to stop the event from bubbling up the event chain. For example, the below nested divs with stopPropagation method prevents default event propagation when clicking on nested div(Div1)</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span>Click <span class=\"token constant\">DIV1</span> Element<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span>div onclick<span class=\"token operator\">=</span><span class=\"token string\">\"secondFunc()\"</span><span class=\"token operator\">></span><span class=\"token constant\">DIV</span> <span class=\"token number\">2</span>\n  <span class=\"token operator\">&lt;</span>div onclick<span class=\"token operator\">=</span><span class=\"token string\">\"firstFunc(event)\"</span><span class=\"token operator\">></span><span class=\"token constant\">DIV</span> <span class=\"token number\">1</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n\n<span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">firstFunc</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"DIV 1\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  event<span class=\"token punctuation\">.</span><span class=\"token function\">stopPropagation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">secondFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"DIV 2\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span></code></pre></div>\n</li>\n<li>\n<p>What are the steps involved in return false usage</p>\n<p> The return false statement in event handlers performs the below steps,</p>\n<ol>\n<li>First it stops the browser's default action or behaviour.</li>\n<li>It prevents the event from propagating the DOM</li>\n<li>Stops callback execution and returns immediately when called.</li>\n</ol>\n</li>\n<li>\n<p>What is BOM</p>\n<p> The Browser Object Model (BOM) allows JavaScript to \"talk to\" the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers.</p>\n<p> <img src=\"images/bom.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>What is the use of setTimeout</p>\n<p> The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Good morning'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the use of setInterval</p>\n<p> The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Good morning'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>Why is JavaScript treated as Single threaded</p>\n<p> JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs.</p>\n</li>\n<li>\n<p>What is an event delegation</p>\n<p> Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it.</p>\n<p> For example, if you wanted to detect field changes in inside a specific form, you can use event delegation technique,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> form <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'#registration-form'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Listen for changes to fields inside the form</span>\nform<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>\n    <span class=\"token string\">'input'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Log the field that was changed</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>event<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token boolean\">false</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is ECMAScript</p>\n<p> ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. The first edition of ECMAScript was released in 1997.</p>\n</li>\n<li>\n<p>What is JSON</p>\n<p> JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language in the way objects are built in JavaScript.</p>\n</li>\n<li>\n<p>What are the syntax rules of JSON</p>\n<p> Below are the list of syntax rules of JSON</p>\n<ol>\n<li>The data is in name/value pairs</li>\n<li>The data is separated by commas</li>\n<li>Curly braces hold objects</li>\n<li>Square brackets hold arrays</li>\n</ol>\n</li>\n<li>\n<p>What is the purpose JSON stringify</p>\n<p> When sending data to a web server, the data has to be in a string format. You can achieve this by converting JSON object into a string using stringify() method.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> userJSON <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">31</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> userString <span class=\"token operator\">=</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>userString<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//\"{\"name\":\"John\",\"age\":31}\"</span></code></pre></div>\n</li>\n<li>\n<p>How do you parse JSON string</p>\n<p> When receiving the data from a web server, the data is always in a string format. But you can convert this string value to a javascript object using parse() method.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> userString <span class=\"token operator\">=</span> <span class=\"token string\">'{\"name\":\"John\",\"age\":31}'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> userJSON <span class=\"token operator\">=</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>userString<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>userJSON<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {name: \"John\", age: 31}</span></code></pre></div>\n</li>\n<li>\n<p>Why do you need JSON</p>\n<p> When exchanging data between a browser and a server, the data can only be text. Since JSON is text only, it can easily be sent to and from a server, and used as a data format by any programming language.</p>\n</li>\n<li>\n<p>What are PWAs</p>\n<p> Progressive web applications (PWAs) are a type of mobile app delivered through the web, built using common web technologies including HTML, CSS and JavaScript. These PWAs are deployed to servers, accessible through URLs, and indexed by search engines.</p>\n</li>\n<li>\n<p>What is the purpose of clearTimeout method</p>\n<p> The clearTimeout() function is used in javascript to clear the timeout which has been set by setTimeout()function before that. i.e, The return value of setTimeout() function is stored in a variable and it's passed into the clearTimeout() function to clear the timer.</p>\n<p> For example, the below setTimeout method is used to display the message after 3 seconds. This timeout can be cleared by the clearTimeout() method.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>\n<span class=\"token keyword\">var</span> msg<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">greeting</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Good morning'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  msg <span class=\"token operator\">=</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> <span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">stop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>msg<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of clearInterval method</p>\n<p> The clearInterval() function is used in javascript to clear the interval which has been set by setInterval() function. i.e, The return value returned by setInterval() function is stored in a variable and it's passed into the clearInterval() function to clear the interval.</p>\n<p> For example, the below setInterval method is used to display the message for every 3 seconds. This interval can be cleared by the clearInterval() method.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>script<span class=\"token operator\">></span>\n<span class=\"token keyword\">var</span> msg<span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">greeting</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   <span class=\"token function\">alert</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Good morning'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  msg <span class=\"token operator\">=</span> <span class=\"token function\">setInterval</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> <span class=\"token number\">3000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">stop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">clearInterval</span><span class=\"token punctuation\">(</span>msg<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>script<span class=\"token operator\">></span></code></pre></div>\n</li>\n<li>\n<p>How do you redirect new page in javascript</p>\n<p> In vanilla javascript, you can redirect to a new page using the <code class=\"language-text\">location</code> property of window object. The syntax would be as follows,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">redirect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>href <span class=\"token operator\">=</span> <span class=\"token string\">'newPage.html'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>How do you check whether a string contains a substring</p>\n<p> There are 3 possible ways to check whether a string contains a substring or not,</p>\n<ol>\n<li><strong>Using includes:</strong> ES6 provided <code class=\"language-text\">String.prototype.includes</code> method to test a string contains a substring</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> mainString <span class=\"token operator\">=</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span>\n    subString <span class=\"token operator\">=</span> <span class=\"token string\">'hell'</span><span class=\"token punctuation\">;</span>\nmainString<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span>subString<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li><strong>Using indexOf:</strong> In an ES5 or older environment, you can use <code class=\"language-text\">String.prototype.indexOf</code> which returns the index of a substring. If the index value is not equal to -1 then it means the substring exists in the main string.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> mainString <span class=\"token operator\">=</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span>\n    subString <span class=\"token operator\">=</span> <span class=\"token string\">'hell'</span><span class=\"token punctuation\">;</span>\nmainString<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>subString<span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li><strong>Using RegEx:</strong> The advanced solution is using Regular expression's test method(<code class=\"language-text\">RegExp.test</code>), which allows for testing for against regular expressions</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> mainString <span class=\"token operator\">=</span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">,</span>\n    regex <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">hell</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">;</span>\nregex<span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>mainString<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>How do you validate an email in javascript</p>\n<p> You can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead of the client side. Because the javascript can be disabled on the client side.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">validateEmail</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">email</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> re <span class=\"token operator\">=</span>\n        <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^(([^&lt;>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^&lt;>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> re<span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span><span class=\"token function\">String</span><span class=\"token punctuation\">(</span>email<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p> The above regular expression accepts unicode characters.</p>\n</li>\n<li>\n<p>How do you get the current url with javascript</p>\n<p> You can use <code class=\"language-text\">window.location.href</code> expression to get the current url path and you can use the same expression for updating the URL too. You can also use <code class=\"language-text\">document.URL</code> for read-only purposes but this solution has issues in FF.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'location.href'</span><span class=\"token punctuation\">,</span> window<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>href<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Returns full URL</span></code></pre></div>\n</li>\n<li>\n<p>What are the various url properties of location object</p>\n<p> The below <code class=\"language-text\">Location</code> object properties can be used to access URL components of the page,</p>\n<ol>\n<li>href - The entire URL</li>\n<li>protocol - The protocol of the URL</li>\n<li>host - The hostname and port of the URL</li>\n<li>hostname - The hostname of the URL</li>\n<li>port - The port number in the URL</li>\n<li>pathname - The path name of the URL</li>\n<li>search - The query portion of the URL</li>\n<li>hash - The anchor portion of the URL</li>\n</ol>\n</li>\n<li>\n<p>How do get query string values in javascript</p>\n<p> You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> urlParams <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">URLSearchParams</span><span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>search<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> clientCode <span class=\"token operator\">=</span> urlParams<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'clientCode'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>How do you check if a key exists in an object</p>\n<p> You can check whether a key exists in an object or not using three approaches,</p>\n<ol>\n<li><strong>Using in operator:</strong> You can use the in operator whether a key exists in an object or not</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token string\">'key'</span> <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">;</span></code></pre></div>\n<p> and If you want to check if a key doesn't exist, remember to use parenthesis,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token string\">'key'</span> <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li><strong>Using hasOwnProperty method:</strong> You can use <code class=\"language-text\">hasOwnProperty</code> to particularly test for properties of the object instance (and not inherited properties)</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">obj<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span><span class=\"token string\">'key'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n<ol>\n<li><strong>Using undefined comparison:</strong> If you access a non-existing property from an object, the result is undefined. Let's compare the properties against undefined to determine the existence of the property.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> user <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">.</span>name <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">.</span>nickName <span class=\"token operator\">!==</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span></code></pre></div>\n</li>\n<li>\n<p>How do you loop through or enumerate javascript object</p>\n<p> You can use the <code class=\"language-text\">for-in</code> loop to loop through javascript object. You can also make sure that the key you get is an actual property of an object, and doesn't come from the prototype using <code class=\"language-text\">hasOwnProperty</code> method.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">k1</span><span class=\"token operator\">:</span> <span class=\"token string\">'value1'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">k2</span><span class=\"token operator\">:</span> <span class=\"token string\">'value2'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">k3</span><span class=\"token operator\">:</span> <span class=\"token string\">'value3'</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> key <span class=\"token keyword\">in</span> object<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>key<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>key <span class=\"token operator\">+</span> <span class=\"token string\">' -> '</span> <span class=\"token operator\">+</span> object<span class=\"token punctuation\">[</span>key<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// k1 -> value1 ...</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>How do you test for an empty object</p>\n<p> There are different solutions based on ECMAScript versions</p>\n<ol>\n<li><strong>Using Object entries(ECMA 7+):</strong> You can use object entries length along with constructor type.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">Object<span class=\"token punctuation\">.</span><span class=\"token function\">entries</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> obj<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">===</span> Object<span class=\"token punctuation\">;</span> <span class=\"token comment\">// Since date object length is 0, you need to check constructor check as well</span></code></pre></div>\n<ol>\n<li><strong>Using Object keys(ECMA 5+):</strong> You can use object keys length along with constructor type.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> obj<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">===</span> Object<span class=\"token punctuation\">;</span> <span class=\"token comment\">// Since date object length is 0, you need to check constructor check as well</span></code></pre></div>\n<ol>\n<li><strong>Using for-in with hasOwnProperty(Pre-ECMA 5):</strong> You can use a for-in loop along with hasOwnProperty.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">isEmpty</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">obj</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> prop <span class=\"token keyword\">in</span> obj<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>prop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What is an arguments object</p>\n<p> The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> total <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> len <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> len<span class=\"token punctuation\">;</span> <span class=\"token operator\">++</span>i<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        total <span class=\"token operator\">+=</span> arguments<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">return</span> total<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">sum</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns 6</span></code></pre></div>\n<p> <strong>Note:</strong> You can't apply array methods on arguments object. But you can convert into a regular array as below.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> argsArray <span class=\"token operator\">=</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>How do you make first letter of the string in an uppercase</p>\n<p> You can create a function which uses a chain of string methods such as charAt, toUpperCase and slice methods to generate a string with the first letter in uppercase.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">capitalizeFirstLetter</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">string</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> string<span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> string<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What are the pros and cons of for loop</p>\n<p> The for-loop is a commonly used iteration syntax in javascript. It has both pros and cons</p>\n</li>\n</ol>\n<p>Pros</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> 1. Works on every environment\n 2. You can use break and continue flow control statements</code></pre></div>\n<p>Cons</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> 1. Too verbose\n 2. Imperative\n 3. You might face one-by-off errors</code></pre></div>\n<ol start=\"131\">\n<li>\n<p>How do you display the current date in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `new Date()` to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy\n\n```javascript\nvar today = new Date();\nvar dd = String(today.getDate()).padStart(2, '0');\nvar mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!\nvar yyyy = today.getFullYear();\n\ntoday = mm + '/' + dd + '/' + yyyy;\ndocument.write(today);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you compare two date objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to use date.getTime() method to compare date values instead of comparison operators (==, !=, ===, and !== operators)\n\n```javascript\nvar d1 = new Date();\nvar d2 = new Date(d1);\nconsole.log(d1.getTime() === d2.getTime()); //True\nconsole.log(d1 === d2); // False\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check if a string starts with another string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use ECMAScript 6's `String.prototype.startsWith()` method to check if a string starts with another string or not. But it is not yet supported in all browsers. Let's see an example to see this usage,\n\n```javascript\n'Good morning'.startsWith('Good'); // true\n'Good morning'.startsWith('morning'); // false\n```</code></pre></div>\n</li>\n<li>\n<p>How do you trim a string in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript provided a trim method on string types to trim any whitespaces present at the beginning or ending of the string.\n\n```javascript\n'  Hello World   '.trim(); //Hello World\n```\n\nIf your browser(&lt;IE9) doesn't support this method then you can use below polyfill.\n\n```javascript\nif (!String.prototype.trim) {\n    (function () {\n        // Make sure we trim BOM and NBSP\n        var rtrim = /^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g;\n        String.prototype.trim = function () {\n            return this.replace(rtrim, '');\n        };\n    })();\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you add a key value pair in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are two possible solutions to add new properties to an object. Let's take a simple object to explain these solutions.\n\n```javascript\nvar object = {\n    key1: value1,\n    key2: value2\n};\n```\n\n1. **Using dot notation:** This solution is useful when you know the name of the property\n\n```javascript\nobject.key3 = 'value3';\n```\n\n1. **Using square bracket notation:** This solution is useful when the name of the property is dynamically determined.\n\n```javascript\nobj['key3'] = 'value3';\n```</code></pre></div>\n</li>\n<li>\n<p>Is the !-- notation represents a special operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No,that's not a special operator. But it is a combination of 2 standard operators one after the other,\n\n1. A logical not (!)\n2. A prefix decrement (--)\n\nAt first, the value decremented by one and then tested to see if it is equal to zero or not for determining the truthy/falsy value.</code></pre></div>\n</li>\n<li>\n<p>How do you assign default values to variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the logical or operator `||` in an assignment expression to provide a default value. The syntax looks like as below,\n\n```javascript\nvar a = b || c;\n```\n\nAs per the above expression, variable 'a 'will get the value of 'c' only if 'b' is falsy (if is null, false, undefined, 0, empty string, or NaN), otherwise 'a' will get the value of 'b'.</code></pre></div>\n</li>\n<li>\n<p>How do you define multiline strings</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can define multiline string literals using the '\\\\' character followed by line terminator.\n\n```javascript\nvar str =\n    'This is a \\\nvery lengthy \\\nsentence!';\n```\n\nBut if you have a space after the '\\\\' character, the code will look exactly the same, but it will raise a SyntaxError.</code></pre></div>\n</li>\n<li>\n<p>What is an app shell model</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An application shell (or app shell) architecture is one way to build a Progressive Web App that reliably and instantly loads on your users' screens, similar to what you see in native applications. It is useful for getting some initial HTML to the screen fast without a network.</code></pre></div>\n</li>\n<li>\n<p>Can we define properties for functions</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, We can define properties for functions because functions are also objects.\n\n```javascript\nfn = function (x) {\n    //Function code goes here\n};\n\nfn.name = 'John';\n\nfn.profile = function (y) {\n    //Profile code goes here\n};\n```</code></pre></div>\n</li>\n<li>\n<p>What is the way to find the number of parameters expected by a function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `function.length` syntax to find the number of parameters expected by a function. Let's take an example of `sum` function to calculate the sum of numbers,\n\n```javascript\nfunction sum(num1, num2, num3, num4) {\n    return num1 + num2 + num3 + num4;\n}\nsum.length; // 4 is the number of parameters expected.\n```</code></pre></div>\n</li>\n<li>\n<p>What is a polyfill</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A polyfill is a piece of JS code used to provide modern functionality on older browsers that do not natively support it. For example, Silverlight plugin polyfill can be used to mimic the functionality of an HTML Canvas element on Microsoft Internet Explorer 7.</code></pre></div>\n</li>\n<li>\n<p>What are break and continue statements</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The break statement is used to \"jump out\" of a loop. i.e, It breaks the loop and continues executing the code after the loop.\n\n```javascript\nfor (i = 0; i &lt; 10; i++) {\n    if (i === 5) {\n        break;\n    }\n    text += 'Number: ' + i + '&lt;br>';\n}\n```\n\nThe continue statement is used to \"jump over\" one iteration in the loop. i.e, It breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.\n\n```javascript\nfor (i = 0; i &lt; 10; i++) {\n    if (i === 5) {\n        continue;\n    }\n    text += 'Number: ' + i + '&lt;br>';\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are js labels</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The label statement allows us to name loops and blocks in JavaScript. We can then use these labels to refer back to the code later. For example, the below code with labels avoids printing the numbers when they are same,\n\n```javascript\nvar i, j;\n\nloop1: for (i = 0; i &lt; 3; i++) {\n    loop2: for (j = 0; j &lt; 3; j++) {\n        if (i === j) {\n            continue loop1;\n        }\n        console.log('i = ' + i + ', j = ' + j);\n    }\n}\n\n// Output is:\n//   \"i = 1, j = 0\"\n//   \"i = 2, j = 0\"\n//   \"i = 2, j = 1\"\n```</code></pre></div>\n</li>\n<li>\n<p>What are the benefits of keeping declarations at the top</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to keep all declarations at the top of each script or function. The benefits of doing this are,\n\n1. Gives cleaner code\n2. It provides a single place to look for local variables\n3. Easy to avoid unwanted global variables\n4. It reduces the possibility of unwanted re-declarations</code></pre></div>\n</li>\n<li>\n<p>What are the benefits of initializing variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to initialize variables because of the below benefits,\n\n1. It gives cleaner code\n2. It provides a single place to initialize variables\n3. Avoid undefined values in the code</code></pre></div>\n</li>\n<li>\n<p>What are the recommendations to create new object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to avoid creating new objects using `new Object()`. Instead you can initialize values based on it's type to create the objects.\n\n1. Assign {} instead of new Object()\n2. Assign \"\" instead of new String()\n3. Assign 0 instead of new Number()\n4. Assign false instead of new Boolean()\n5. Assign [] instead of new Array()\n6. Assign /()/ instead of new RegExp()\n7. Assign function (){} instead of new Function()\n\nYou can define them as an example,\n\n```javascript\nvar v1 = {};\nvar v2 = '';\nvar v3 = 0;\nvar v4 = false;\nvar v5 = [];\nvar v6 = /()/;\nvar v7 = function () {};\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define JSON arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JSON arrays are written inside square brackets and arrays contain javascript objects. For example, the JSON array of users would be as below,\n\n```javascript\n\"users\":[\n  {\"firstName\":\"John\", \"lastName\":\"Abrahm\"},\n  {\"firstName\":\"Anna\", \"lastName\":\"Smith\"},\n  {\"firstName\":\"Shane\", \"lastName\":\"Warn\"}\n]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you generate random integers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use Math.random() with Math.floor() to return random integers. For example, if you want generate random integers between 1 to 10, the multiplication factor should be 10,\n\n```javascript\nMath.floor(Math.random() * 10) + 1; // returns a random integer from 1 to 10\nMath.floor(Math.random() * 100) + 1; // returns a random integer from 1 to 100\n```\n\n**Note:** Math.random() returns a random number between 0 (inclusive), and 1 (exclusive)</code></pre></div>\n</li>\n<li>\n<p>Can you write a random integers function to print integers with in a range</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, you can create a proper random function to return a random number between min and max (both included)\n\n```javascript\nfunction randomInteger(min, max) {\n    return Math.floor(Math.random() * (max - min + 1)) + min;\n}\nrandomInteger(1, 100); // returns a random integer from 1 to 100\nrandomInteger(1, 1000); // returns a random integer from 1 to 1000\n```</code></pre></div>\n</li>\n<li>\n<p>What is tree shaking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tree shaking is a form of dead code elimination. It means that unused modules will not be included in the bundle during the build process and for that it relies on the static structure of ES2015 module syntax,( i.e. import and export). Initially this has been popularized by the ES2015 module bundler `rollup`.</code></pre></div>\n</li>\n<li>\n<p>What is the need of tree shaking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tree Shaking can significantly reduce the code size in any application. i.e, The less code we send over the wire the more performant the application will be. For example, if we just want to create a \"Hello World\" Application using SPA frameworks then it will take around a few MBs, but by tree shaking it can bring down the size to just a few hundred KBs. Tree shaking is implemented in Rollup and Webpack bundlers.</code></pre></div>\n</li>\n<li>\n<p>Is it recommended to use eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, it allows arbitrary code to be run which causes a security problem. As we know that the eval() function is used to run text as code. In most of the cases, it should not be necessary to use it.</code></pre></div>\n</li>\n<li>\n<p>What is a Regular Expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A regular expression is a sequence of characters that forms a search pattern. You can use this search pattern for searching data in a text. These can be used to perform all types of text search and text replace operations. Let's see the syntax format now,\n\n```javascript\n/pattern/modifiers;\n```\n\nFor example, the regular expression or search pattern with case-insensitive username would be,\n\n```javascript\n/John/i;\n```</code></pre></div>\n</li>\n<li>\n<p>What are the string methods available in Regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Regular Expressions has two string methods: search() and replace().\nThe search() method uses an expression to search for a match, and returns the position of the match.\n\n```javascript\nvar msg = 'Hello John';\nvar n = msg.search(/John/i); // 6\n```\n\nThe replace() method is used to return a modified string where the pattern is replaced.\n\n```javascript\nvar msg = 'Hello John';\nvar n = msg.replace(/John/i, 'Buttler'); // Hello Buttler\n```</code></pre></div>\n</li>\n<li>\n<p>What are modifiers in regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Modifiers can be used to perform case-insensitive and global searches. Let's list down some of the modifiers,\n\n| Modifier | Description                                             |\n| -------- | ------------------------------------------------------- |\n| i        | Perform case-insensitive matching                       |\n| g        | Perform a global match rather than stops at first match |\n| m        | Perform multiline matching                              |\n\nLet's take an example of global modifier,\n\n```javascript\nvar text = 'Learn JS one by one';\nvar pattern = /one/g;\nvar result = text.match(pattern); // one,one\n```</code></pre></div>\n</li>\n<li>\n<p>What are regular expression patterns</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Regular Expressions provide a group of patterns in order to match characters. Basically they are categorized into 3 types,\n\n1. **Brackets:** These are used to find a range of characters.\n   For example, below are some use cases,\n    1. [abc]: Used to find any of the characters between the brackets(a,b,c)\n    2. [0-9]: Used to find any of the digits between the brackets\n    3. (a|b): Used to find any of the alternatives separated with |\n2. **Metacharacters:** These are characters with a special meaning\n   For example, below are some use cases,\n    1. \\\\d: Used to find a digit\n    2. \\\\s: Used to find a whitespace character\n    3. \\\\b: Used to find a match at the beginning or ending of a word\n3. **Quantifiers:** These are useful to define quantities\n   For example, below are some use cases,\n    1. n+: Used to find matches for any string that contains at least one n\n    2. n\\*: Used to find matches for any string that contains zero or more occurrences of n\n    3. n?: Used to find matches for any string that contains zero or one occurrences of n</code></pre></div>\n</li>\n<li>\n<p>What is a RegExp object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">RegExp object is a regular expression object with predefined properties and methods. Let's see the simple usage of RegExp object,\n\n```javascript\nvar regexp = new RegExp('\\\\w+');\nconsole.log(regexp);\n// expected output: /\\w+/\n```</code></pre></div>\n</li>\n<li>\n<p>How do you search a string for a pattern</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the test() method of regular expression in order to search a string for a pattern, and return true or false depending on the result.\n\n```javascript\nvar pattern = /you/;\nconsole.log(pattern.test('How are you?')); //true\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of exec method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The purpose of exec method is similar to test method but it executes a search for a match in a specified string and returns a result array, or null instead of returning true/false.\n\n```javascript\nvar pattern = /you/;\nconsole.log(pattern.exec('How are you?')); //[\"you\", index: 8, input: \"How are you?\", groups: undefined]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you change the style of a HTML element</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can change inline style or classname of a HTML element using javascript\n\n1. **Using style property:** You can modify inline style using style property\n\n```javascript\ndocument.getElementById('title').style.fontSize = '30px';\n```\n\n1. **Using ClassName property:** It is easy to modify element class using className property\n\n```javascript\ndocument.getElementById('title').className = 'custom-title';\n```</code></pre></div>\n</li>\n<li>\n<p>What would be the result of 1+2+'3'</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`.</code></pre></div>\n</li>\n<li>\n<p>What is a debugger statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.\nFor example, in the below function a debugger statement has been inserted. So\nexecution is paused at the debugger statement just like a breakpoint in the script source.\n\n```javascript\nfunction getProfile() {\n    // code goes here\n    debugger;\n    // code goes here\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of breakpoints in debugging</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can set breakpoints in the javascript code once the debugger statement is executed and the debugger window pops up. At each breakpoint, javascript will stop executing, and let you examine the JavaScript values. After examining values, you can resume the execution of code using the play button.</code></pre></div>\n</li>\n<li>\n<p>Can I use reserved words as identifiers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, you cannot use the reserved words as variables, labels, object or function names. Let's see one simple example,\n\n```javascript\nvar else = \"hello\"; // Uncaught SyntaxError: Unexpected token else\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect a mobile browser</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use regex which returns a true or false value depending on whether or not the user is browsing with a mobile.\n\n```javascript\nwindow.mobilecheck = function () {\n    var mobileCheck = false;\n    (function (a) {\n        if (\n            /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(\n                a\n            ) ||\n            /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i.test(\n                a.substr(0, 4)\n            )\n        )\n            mobileCheck = true;\n    })(navigator.userAgent || navigator.vendor || window.opera);\n    return mobileCheck;\n};\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect a mobile browser without regexp</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can detect mobile browsers by simply running through a list of devices and checking if the useragent matches anything. This is an alternative solution for RegExp usage,\n\n```javascript\nfunction detectmob() {\n    if (\n        navigator.userAgent.match(/Android/i) ||\n        navigator.userAgent.match(/webOS/i) ||\n        navigator.userAgent.match(/iPhone/i) ||\n        navigator.userAgent.match(/iPad/i) ||\n        navigator.userAgent.match(/iPod/i) ||\n        navigator.userAgent.match(/BlackBerry/i) ||\n        navigator.userAgent.match(/Windows Phone/i)\n    ) {\n        return true;\n    } else {\n        return false;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get the image width and height using JS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can programmatically get the image and check the dimensions(width and height) using Javascript.\n\n```javascript\nvar img = new Image();\nimg.onload = function () {\n    console.log(this.width + 'x' + this.height);\n};\nimg.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make synchronous HTTP request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Browsers provide an XMLHttpRequest object which can be used to make synchronous HTTP requests from JavaScript\n\n```javascript\nfunction httpGet(theUrl) {\n    var xmlHttpReq = new XMLHttpRequest();\n    xmlHttpReq.open('GET', theUrl, false); // false for synchronous request\n    xmlHttpReq.send(null);\n    return xmlHttpReq.responseText;\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make asynchronous HTTP request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Browsers provide an XMLHttpRequest object which can be used to make asynchronous HTTP requests from JavaScript by passing the 3rd parameter as true.\n\n```javascript\nfunction httpGetAsync(theUrl, callback) {\n    var xmlHttpReq = new XMLHttpRequest();\n    xmlHttpReq.onreadystatechange = function () {\n        if (xmlHttpReq.readyState == 4 &amp;&amp; xmlHttpReq.status == 200) callback(xmlHttpReq.responseText);\n    };\n    xmlHttp.open('GET', theUrl, true); // true for asynchronous\n    xmlHttp.send(null);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you convert date to another timezone in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the toLocaleString() method to convert dates in one timezone to another. For example, let's convert current date to British English timezone as below,\n\n```javascript\nconsole.log(event.toLocaleString('en-GB', { timeZone: 'UTC' })); //29/06/2019, 09:56:00\n```</code></pre></div>\n</li>\n<li>\n<p>What are the properties used to get size of window</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use them combination of these properties to calculate the size of a window or document,\n\n```javascript\nvar width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;\n\nvar height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;\n```</code></pre></div>\n</li>\n<li>\n<p>What is a conditional operator in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for if statements.\n\n```javascript\nvar isAuthenticated = false;\nconsole.log(isAuthenticated ? 'Hello, welcome' : 'Sorry, you are not authenticated'); //Sorry, you are not authenticated\n```</code></pre></div>\n</li>\n<li>\n<p>Can you apply chaining on conditional operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, you can apply chaining on conditional operators similar to if … else if … else if … else chain. The syntax is going to be as below,\n\n```javascript\nfunction traceValue(someParam) {\n    return condition1 ? value1 : condition2 ? value2 : condition3 ? value3 : value4;\n}\n\n// The above conditional operator is equivalent to:\n\nfunction traceValue(someParam) {\n    if (condition1) {\n        return value1;\n    } else if (condition2) {\n        return value2;\n    } else if (condition3) {\n        return value3;\n    } else {\n        return value4;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the ways to execute javascript after page load</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can execute javascript after page load in many different ways,\n\n1. **window.onload:**\n\n```javascript\nwindow.onload = function ...\n```\n\n1. **document.onload:**\n\n```javascript\ndocument.onload = function ...\n```\n\n1. **body onload:**\n\n```javascript\n&lt;body onload=\"script();\">\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between proto and prototype</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `__proto__` object is the actual object that is used in the lookup chain to resolve methods, etc. Whereas `prototype` is the object that is used to build `__proto__` when you create an object with new\n\n```javascript\nnew Employee().__proto__ === Employee.prototype;\nnew Employee().prototype === undefined;\n```</code></pre></div>\n</li>\n<li>\n<p>Give an example where do you really need semicolon</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to use semicolons after every statement in JavaScript. For example, in the below case it throws an error \".. is not a function\" at runtime due to missing semicolon.\n\n```javascript\n// define a function\nvar fn = (function () {\n    //...\n})(\n    // semicolon missing at this line\n\n    // then execute some code inside a closure\n    function () {\n        //...\n    }\n)();\n```\n\nand it will be interpreted as\n\n```javascript\nvar fn = (function () {\n    //...\n})(function () {\n    //...\n})();\n```\n\nIn this case, we are passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. Hence, the second function will fail with a \"... is not a function\" error at runtime.</code></pre></div>\n</li>\n<li>\n<p>What is a freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The **freeze()** method is used to freeze an object. Freezing an object does not allow adding new properties to an object,prevents from removing and prevents changing the enumerability, configurability, or writability of existing properties. i.e, It returns the passed object and does not create a frozen copy.\n\n```javascript\nconst obj = {\n    prop: 100\n};\n\nObject.freeze(obj);\nobj.prop = 200; // Throws an error in strict mode\n\nconsole.log(obj.prop); //100\n```\n\n**Note:** It causes a TypeError if the argument passed is not an object.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main benefits of using freeze method,\n\n1. It is used for freezing objects and arrays.\n2. It is used to make an object immutable.</code></pre></div>\n</li>\n<li>\n<p>Why do I need to use freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In the Object-oriented paradigm, an existing API contains certain elements that are not intended to be extended, modified, or re-used outside of their current context. Hence it works as the `final` keyword which is used in various languages.</code></pre></div>\n</li>\n<li>\n<p>How do you detect a browser language preference</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use navigator object to detect a browser language preference as below,\n\n```javascript\nvar language =\n    (navigator.languages &amp;&amp; navigator.languages[0]) || // Chrome / Firefox\n    navigator.language || // All browsers\n    navigator.userLanguage; // IE &lt;= 10\n\nconsole.log(language);\n```</code></pre></div>\n</li>\n<li>\n<p>How to convert string to title case with javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function,\n\n```javascript\nfunction toTitleCase(str) {\n    return str.replace(/\\w\\S*/g, function (txt) {\n        return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();\n    });\n}\ntoTitleCase('good morning john'); // Good Morning John\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect javascript disabled in the page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `&lt;noscript>` tag to detect javascript disabled or not. The code block inside `&lt;noscript>` gets executed when JavaScript is disabled, and is typically used to display alternative content when the page generated in JavaScript.\n\n```javascript\n&lt;script type=\"javascript\">\n    // JS related code goes here\n&lt;/script>\n&lt;noscript>\n    &lt;a href=\"next_page.html?noJS=true\">JavaScript is disabled in the page. Please click Next Page&lt;/a>\n&lt;/noscript>\n```</code></pre></div>\n</li>\n<li>\n<p>What are various operators supported by javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An operator is capable of manipulating(mathematical and logical computations) a certain value or operand. There are various operators supported by JavaScript as below,\n\n1. **Arithmetic Operators:** Includes + (Addition),- (Subtraction), \\* (Multiplication), / (Division), % (Modulus), + + (Increment) and - - (Decrement)\n2. **Comparison Operators:** Includes = =(Equal),!= (Not Equal), ===(Equal with type), > (Greater than),> = (Greater than or Equal to),&lt; (Less than),&lt;= (Less than or Equal to)\n3. **Logical Operators:** Includes &amp;&amp;(Logical AND),||(Logical OR),!(Logical NOT)\n4. **Assignment Operators:** Includes = (Assignment Operator), += (Add and Assignment Operator), - = (Subtract and Assignment Operator), \\*= (Multiply and Assignment), /= (Divide and Assignment), %= (Modules and Assignment)\n5. **Ternary Operators:** It includes conditional(: ?) Operator\n6. **typeof Operator:** It uses to find type of variable. The syntax looks like `typeof variable`</code></pre></div>\n</li>\n<li>\n<p>What is a rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Rest parameter is an improved way to handle function parameters which allows us to represent an indefinite number of arguments as an array. The syntax would be as below,\n\n```javascript\nfunction f(a, b, ...theArgs) {\n    // ...\n}\n```\n\nFor example, let's take a sum example to calculate on dynamic number of parameters,\n\n```javascript\nfunction total(…args){\nlet sum = 0;\nfor(let i of args){\nsum+=i;\n}\nreturn sum;\n}\nconsole.log(fun(1,2)); //3\nconsole.log(fun(1,2,3)); //6\nconsole.log(fun(1,2,3,4)); //13\nconsole.log(fun(1,2,3,4,5)); //15\n```\n\n**Note:** Rest parameter is added in ES2015 or ES6</code></pre></div>\n</li>\n<li>\n<p>What happens if you do not use rest parameter as a last argument</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The rest parameter should be the last argument, as its job is to collect all the remaining arguments into an array. For example, if you define a function like below it doesn't make any sense and will throw an error.\n\n```javascript\nfunction someFunc(a,…b,c){\n//You code goes here\nreturn;\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the bitwise operators available in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of bitwise logical operators used in JavaScript\n\n1. Bitwise AND ( &amp; )\n2. Bitwise OR ( | )\n3. Bitwise XOR ( ^ )\n4. Bitwise NOT ( ~ )\n5. Left Shift ( &lt;&lt; )\n6. Sign Propagating Right Shift ( >> )\n7. Zero fill Right Shift ( >>> )</code></pre></div>\n</li>\n<li>\n<p>What is a spread operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. Let's take an example to see this behavior,\n\n```javascript\nfunction calculateSum(x, y, z) {\n    return x + y + z;\n}\n\nconst numbers = [1, 2, 3];\n\nconsole.log(calculateSum(...numbers)); // 6\n```</code></pre></div>\n</li>\n<li>\n<p>How do you determine whether object is frozen or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object.isFrozen() method is used to determine if an object is frozen or not.An object is frozen if all of the below conditions hold true,\n\n1. If it is not extensible.\n2. If all of its properties are non-configurable.\n3. If all its data properties are non-writable.\n   The usage is going to be as follows,\n\n```javascript\nconst object = {\n    property: 'Welcome JS world'\n};\nObject.freeze(object);\nconsole.log(Object.isFrozen(object));\n```</code></pre></div>\n</li>\n<li>\n<p>How do you determine two values same or not using object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.is() method determines whether two values are the same value. For example, the usage with different types of values would be,\n\n```javascript\nObject.is('hello', 'hello'); // true\nObject.is(window, window); // true\nObject.is([], []); // false\n```\n\nTwo values are the same if one of the following holds:\n\n1. both undefined\n2. both null\n3. both true or both false\n4. both strings of the same length with the same characters in the same order\n5. both the same object (means both object have same reference)\n6. both numbers and\n   both +0\n   both -0\n   both NaN\n   both non-zero and both not NaN and both have the same value.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of using object is method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the applications of Object's `is` method are follows,\n\n1. It is used for comparison of two strings.\n2. It is used for comparison of two numbers.\n3. It is used for comparing the polarity of two numbers.\n4. It is used for comparison of two objects.</code></pre></div>\n</li>\n<li>\n<p>How do you copy properties from one object to other</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the Object.assign() method which is used to copy the values and properties from one or more source objects to a target object. It returns the target object which has properties and values copied from the target object. The syntax would be as below,\n\n```javascript\nObject.assign(target, ...sources);\n```\n\nLet's take example with one source and one target object,\n\n```javascript\nconst target = { a: 1, b: 2 };\nconst source = { b: 3, c: 4 };\n\nconst returnedTarget = Object.assign(target, source);\n\nconsole.log(target); // { a: 1, b: 3, c: 4 }\n\nconsole.log(returnedTarget); // { a: 1, b: 3, c: 4 }\n```\n\nAs observed in the above code, there is a common property(`b`) from source to target so it's value has been overwritten.</code></pre></div>\n</li>\n<li>\n<p>What are the applications of assign method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the some of main applications of Object.assign() method,\n\n1. It is used for cloning an object.\n2. It is used to merge objects with the same properties.</code></pre></div>\n</li>\n<li>\n<p>What is a proxy object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Proxy object is used to define custom behavior for fundamental operations such as property lookup, assignment, enumeration, function invocation, etc. The syntax would be as follows,\n\n```javascript\nvar p = new Proxy(target, handler);\n```\n\nLet's take an example of proxy object,\n\n```javascript\nvar handler = {\n    get: function (obj, prop) {\n        return prop in obj ? obj[prop] : 100;\n    }\n};\n\nvar p = new Proxy({}, handler);\np.a = 10;\np.b = null;\n\nconsole.log(p.a, p.b); // 10, null\nconsole.log('c' in p, p.c); // false, 100\n```\n\nIn the above code, it uses `get` handler which define the behavior of the proxy when an operation is performed on it</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of seal method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The **Object.seal()** method is used to seal an object, by preventing new properties from being added to it and marking all existing properties as non-configurable. But values of present properties can still be changed as long as they are writable. Let's see the below example to understand more about seal() method\n\n```javascript\nconst object = {\n    property: 'Welcome JS world'\n};\nObject.seal(object);\nobject.property = 'Welcome to object world';\nconsole.log(Object.isSealed(object)); // true\ndelete object.property; // You cannot delete when sealed\nconsole.log(object.property); //Welcome to object world\n```</code></pre></div>\n</li>\n<li>\n<p>What are the applications of seal method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main applications of Object.seal() method,\n\n1. It is used for sealing objects and arrays.\n2. It is used to make an object immutable.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between freeze and seal methods</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If an object is frozen using the Object.freeze() method then its properties become immutable and no changes can be made in them whereas if an object is sealed using the Object.seal() method then the changes can be made in the existing properties of the object.</code></pre></div>\n</li>\n<li>\n<p>How do you determine if an object is sealed or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.isSealed() method is used to determine if an object is sealed or not. An object is sealed if all of the below conditions hold true\n\n1. If it is not extensible.\n2. If all of its properties are non-configurable.\n3. If it is not removable (but not necessarily non-writable).\n   Let's see it in the action\n\n```javascript\nconst object = {\n    property: 'Hello, Good morning'\n};\n\nObject.seal(object); // Using seal() method to seal the object\n\nconsole.log(Object.isSealed(object)); // checking whether the object is sealed or not\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get enumerable key and value pairs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.entries() method is used to return an array of a given object's own enumerable string-keyed property [key, value] pairs, in the same order as that provided by a for...in loop. Let's see the functionality of object.entries() method in an example,\n\n```javascript\nconst object = {\n    a: 'Good morning',\n    b: 100\n};\n\nfor (let [key, value] of Object.entries(object)) {\n    console.log(`${key}: ${value}`); // a: 'Good morning'\n    // b: 100\n}\n```\n\n**Note:** The order is not guaranteed as object defined.</code></pre></div>\n</li>\n<li>\n<p>What is the main difference between Object.values and Object.entries method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.values() method's behavior is similar to Object.entries() method but it returns an array of values instead [key,value] pairs.\n\n```javascript\nconst object = {\n    a: 'Good morning',\n    b: 100\n};\n\nfor (let value of Object.values(object)) {\n    console.log(`${value}`); // 'Good morning'\n    100;\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How can you get the list of keys of any object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.keys()` method which is used to return an array of a given object's own property names, in the same order as we get with a normal loop. For example, you can get the keys of a user object,\n\n```javascript\nconst user = {\n    name: 'John',\n    gender: 'male',\n    age: 40\n};\n\nconsole.log(Object.keys(user)); //['name', 'gender', 'age']\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create an object with prototype</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.create() method is used to create a new object with the specified prototype object and properties. i.e, It uses an existing object as the prototype of the newly created object. It returns a new object with the specified prototype object and properties.\n\n```javascript\nconst user = {\n    name: 'John',\n    printInfo: function () {\n        console.log(`My name is ${this.name}.`);\n    }\n};\n\nconst admin = Object.create(user);\n\nadmin.name = 'Nick'; // Remember that \"name\" is a property set on \"admin\" but not on \"user\" object\n\nadmin.printInfo(); // My name is Nick\n```</code></pre></div>\n</li>\n<li>\n<p>What is a WeakSet</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">WeakSet is used to store a collection of weakly(weak references) held objects. The syntax would be as follows,\n\n```javascript\nnew WeakSet([iterable]);\n```\n\nLet's see the below example to explain it's behavior,\n\n```javascript\nvar ws = new WeakSet();\nvar user = {};\nws.add(user);\nws.has(user); // true\nws.delete(user); // removes user from the set\nws.has(user); // false, user has been removed\n```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between WeakSet and Set</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference is that references to objects in Set are strong while references to objects in WeakSet are weak. i.e, An object in WeakSet can be garbage collected if there is no other reference to it.\nOther differences are,\n\n1. Sets can store any value Whereas WeakSets can store only collections of objects\n2. WeakSet does not have size property unlike Set\n3. WeakSet does not have methods such as clear, keys, values, entries, forEach.\n4. WeakSet is not iterable.</code></pre></div>\n</li>\n<li>\n<p>List down the collection of methods available on WeakSet</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of methods available on WeakSet,\n\n1. add(value): A new object is appended with the given value to the weakset\n2. delete(value): Deletes the value from the WeakSet collection.\n3. has(value): It returns true if the value is present in the WeakSet Collection, otherwise it returns false.\n\nLet's see the functionality of all the above methods in an example,\n\n```javascript\nvar weakSetObject = new WeakSet();\nvar firstObject = {};\nvar secondObject = {};\n// add(value)\nweakSetObject.add(firstObject);\nweakSetObject.add(secondObject);\nconsole.log(weakSetObject.has(firstObject)); //true\nweakSetObject.delete(secondObject);\n```</code></pre></div>\n</li>\n<li>\n<p>What is a WeakMap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced. In this case, keys must be objects and the values can be arbitrary values. The syntax is looking like as below,\n\n```javascript\nnew WeakMap([iterable]);\n```\n\nLet's see the below example to explain it's behavior,\n\n```javascript\nvar ws = new WeakMap();\nvar user = {};\nws.set(user);\nws.has(user); // true\nws.delete(user); // removes user from the map\nws.has(user); // false, user has been removed\n```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between WeakMap and Map</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference is that references to key objects in Map are strong while references to key objects in WeakMap are weak. i.e, A key object in WeakMap can be garbage collected if there is no other reference to it.\nOther differences are,\n\n1. Maps can store any key type Whereas WeakMaps can store only collections of key objects\n2. WeakMap does not have size property unlike Map\n3. WeakMap does not have methods such as clear, keys, values, entries, forEach.\n4. WeakMap is not iterable.</code></pre></div>\n</li>\n<li>\n<p>List down the collection of methods available on WeakMap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of methods available on WeakMap,\n\n1. set(key, value): Sets the value for the key in the WeakMap object. Returns the WeakMap object.\n2. delete(key): Removes any value associated to the key.\n3. has(key): Returns a Boolean asserting whether a value has been associated to the key in the WeakMap object or not.\n4. get(key): Returns the value associated to the key, or undefined if there is none.\n   Let's see the functionality of all the above methods in an example,\n\n```javascript\nvar weakMapObject = new WeakMap();\nvar firstObject = {};\nvar secondObject = {};\n// set(key, value)\nweakMapObject.set(firstObject, 'John');\nweakMapObject.set(secondObject, 100);\nconsole.log(weakMapObject.has(firstObject)); //true\nconsole.log(weakMapObject.get(firstObject)); // John\nweakMapObject.delete(secondObject);\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of uneval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The uneval() is an inbuilt function which is used to create a string representation of the source code of an Object. It is a top-level function and is not associated with any object. Let's see the below example to know more about it's functionality,\n\n```javascript\nvar a = 1;\nuneval(a); // returns a String containing 1\nuneval(function user() {}); // returns \"(function user(){})\"\n```</code></pre></div>\n</li>\n<li>\n<p>How do you encode an URL</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The encodeURI() function is used to encode complete URI which has special characters except (, / ? : @ &amp; = + $ #) characters.\n\n```javascript\nvar uri = 'https://mozilla.org/?x=шеллы';\nvar encoded = encodeURI(uri);\nconsole.log(encoded); // https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B\n```</code></pre></div>\n</li>\n<li>\n<p>How do you decode an URL</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The decodeURI() function is used to decode a Uniform Resource Identifier (URI) previously created by encodeURI().\n\n```javascript\nvar uri = 'https://mozilla.org/?x=шеллы';\nvar encoded = encodeURI(uri);\nconsole.log(encoded); // https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B\ntry {\n    console.log(decodeURI(encoded)); // \"https://mozilla.org/?x=шеллы\"\n} catch (e) {\n    // catches a malformed URI\n    console.error(e);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you print the contents of web page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The window object provided a print() method which is used to print the contents of the current window. It opens a Print dialog box which lets you choose between various printing options. Let's see the usage of print method in an example,\n\n```html\n&lt;input type=\"button\" value=\"Print\" onclick=\"window.print()\" />\n```\n\n**Note:** In most browsers, it will block while the print dialog is open.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between uneval and eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `uneval` function returns the source of a given object; whereas the `eval` function does the opposite, by evaluating that source code in a different memory area. Let's see an example to clarify the difference,\n\n```javascript\nvar msg = uneval(function greeting() {\n    return 'Hello, Good morning';\n});\nvar greeting = eval(msg);\ngreeting(); // returns \"Hello, Good morning\"\n```</code></pre></div>\n</li>\n<li>\n<p>What is an anonymous function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An anonymous function is a function without a name! Anonymous functions are commonly assigned to a variable name or used as a callback function. The syntax would be as below,\n\n```javascript\nfunction (optionalParameters) {\n  //do something\n}\n\nconst myFunction = function(){ //Anonymous function assigned to a variable\n  //do something\n};\n\n[1, 2, 3].map(function(element){ //Anonymous function used as a callback function\n  //do something\n});\n```\n\nLet's see the above anonymous function in an example,\n\n```javascript\nvar x = function (a, b) {\n    return a * b;\n};\nvar z = x(5, 10);\nconsole.log(z); // 50\n```</code></pre></div>\n</li>\n<li>\n<p>What is the precedence order between local and global variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A local variable takes precedence over a global variable with the same name. Let's see this behavior in an example.\n\n```javascript\nvar msg = 'Good morning';\nfunction greeting() {\n    msg = 'Good Evening';\n    console.log(msg);\n}\ngreeting();\n```</code></pre></div>\n</li>\n<li>\n<p>What are javascript accessors</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ECMAScript 5 introduced javascript object accessors or computed properties through getters and setters. Getters uses the `get` keyword whereas Setters uses the `set` keyword.\n\n```javascript\nvar user = {\n  firstName: \"John\",\n  lastName : \"Abraham\",\n  language : \"en\",\n  get lang() {\n    return this.language;\n  }\n  set lang(lang) {\n  this.language = lang;\n  }\n};\nconsole.log(user.lang); // getter access lang as en\nuser.lang = 'fr';\nconsole.log(user.lang); // setter used to set lang as fr\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define property on Object constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.defineProperty() static method is used to define a new property directly on an object, or modify an existing property on an object, and returns the object. Let's see an example to know how to define property,\n\n```javascript\nconst newObject = {};\n\nObject.defineProperty(newObject, 'newProperty', {\n    value: 100,\n    writable: false\n});\n\nconsole.log(newObject.newProperty); // 100\n\nnewObject.newProperty = 200; // It throws an error in strict mode due to writable setting\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between get and defineProperty</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both have similar results until unless you use classes. If you use `get` the property will be defined on the prototype of the object whereas using `Object.defineProperty()` the property will be defined on the instance it is applied to.</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of Getters and Setters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of benefits of Getters and Setters,\n\n1. They provide simpler syntax\n2. They are used for defining computed properties, or accessors in JS.\n3. Useful to provide equivalence relation between properties and methods\n4. They can provide better data quality\n5. Useful for doing things behind the scenes with the encapsulated logic.</code></pre></div>\n</li>\n<li>\n<p>Can I add getters and setters using defineProperty method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, You can use the `Object.defineProperty()` method to add Getters and Setters. For example, the below counter object uses increment, decrement, add and subtract properties,\n\n```javascript\nvar obj = { counter: 0 };\n\n// Define getters\nObject.defineProperty(obj, 'increment', {\n    get: function () {\n        this.counter++;\n    }\n});\nObject.defineProperty(obj, 'decrement', {\n    get: function () {\n        this.counter--;\n    }\n});\n\n// Define setters\nObject.defineProperty(obj, 'add', {\n    set: function (value) {\n        this.counter += value;\n    }\n});\nObject.defineProperty(obj, 'subtract', {\n    set: function (value) {\n        this.counter -= value;\n    }\n});\n\nobj.add = 10;\nobj.subtract = 5;\nconsole.log(obj.increment); //6\nconsole.log(obj.decrement); //5\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of switch-case</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The switch case statement in JavaScript is used for decision making purposes. In a few cases, using the switch case statement is going to be more convenient than if-else statements. The syntax would be as below,\n\n```javascript\nswitch (expression)\n{\n    case value1:\n        statement1;\n        break;\n    case value2:\n        statement2;\n        break;\n    .\n    .\n    case valueN:\n        statementN;\n        break;\n    default:\n        statementDefault;\n}\n```\n\nThe above multi-way branch statement provides an easy way to dispatch execution to different parts of code based on the value of the expression.</code></pre></div>\n</li>\n<li>\n<p>What are the conventions to be followed for the usage of switch case</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of conventions should be taken care,\n\n1. The expression can be of type either number or string.\n2. Duplicate values are not allowed for the expression.\n3. The default statement is optional. If the expression passed to switch does not match with any case value then the statement within default case will be executed.\n4. The break statement is used inside the switch to terminate a statement sequence.\n5. The break statement is optional. But if it is omitted, the execution will continue on into the next case.</code></pre></div>\n</li>\n<li>\n<p>What are primitive data types</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A primitive data type is data that has a primitive value (which has no properties or methods). There are 7 types of primitive data types.\n\n1. string\n2. number\n3. boolean\n4. null\n5. undefined\n6. bigint\n7. symbol</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to access object properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are 3 possible ways for accessing the property of an object.\n\n1. **Dot notation:** It uses dot for accessing the properties\n\n```javascript\nobjectName.property;\n```\n\n1. **Square brackets notation:** It uses square brackets for property access\n\n```javascript\nobjectName['property'];\n```\n\n1. **Expression notation:** It uses expression in the square brackets\n\n```javascript\nobjectName[expression];\n```</code></pre></div>\n</li>\n<li>\n<p>What are the function parameter rules</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript functions follow below rules for parameters,\n\n1. The function definitions do not specify data types for parameters.\n2. Do not perform type checking on the passed arguments.\n3. Do not check the number of arguments received.\n   i.e, The below function follows the above rules,\n\n```javascript\nfunction functionName(parameter1, parameter2, parameter3) {\n    console.log(parameter1); // 1\n}\nfunctionName(1);\n```</code></pre></div>\n</li>\n<li>\n<p>What is an error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An error object is a built in error object that provides error information when an error occurs. It has two properties: name and message. For example, the below function logs error details,\n\n```javascript\ntry {\n    greeting('Welcome');\n} catch (err) {\n    console.log(err.name + '&lt;br>' + err.message);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>When you get a syntax error</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A SyntaxError is thrown if you try to evaluate code with a syntax error. For example, the below missing quote for the function parameter throws a syntax error\n\n```javascript\ntry {\n    eval(\"greeting('welcome)\"); // Missing ' will produce an error\n} catch (err) {\n    console.log(err.name);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different error names from error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are 6 different types of error names returned from error object,\n| Error Name | Description |\n|---- | ---------\n| EvalError | An error has occurred in the eval() function |\n| RangeError | An error has occurred with a number \"out of range\" |\n| ReferenceError | An error due to an illegal reference|\n| SyntaxError | An error due to a syntax error|\n| TypeError | An error due to a type error |\n| URIError | An error due to encodeURI() |</code></pre></div>\n</li>\n<li>\n<p>What are the various statements in error handling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of statements used in an error handling,\n\n1. **try:** This statement is used to test a block of code for errors\n2. **catch:** This statement is used to handle the error\n3. **throw:** This statement is used to create custom errors.\n4. **finally:** This statement is used to execute code after try and catch regardless of the result.</code></pre></div>\n</li>\n<li>\n<p>What are the two types of loops in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. **Entry Controlled loops:** In this kind of loop type, the test condition is tested before entering the loop body. For example, For Loop and While Loop comes under this category.\n2. **Exit Controlled Loops:** In this kind of loop type, the test condition is tested or evaluated at the end of the loop body. i.e, the loop body will execute at least once irrespective of test condition true or false. For example, do-while loop comes under this category.</code></pre></div>\n</li>\n<li>\n<p>What is nodejs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Node.js is a server-side platform built on Chrome's JavaScript runtime for easily building fast and scalable network applications. It is an event-based, non-blocking, asynchronous I/O runtime that uses Google's V8 JavaScript engine and libuv library.</code></pre></div>\n</li>\n<li>\n<p>What is an Intl object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. It provides access to several constructors and language sensitive functions.</code></pre></div>\n</li>\n<li>\n<p>How do you perform language specific date and time formatting</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Intl.DateTimeFormat` object which is a constructor for objects that enable language-sensitive date and time formatting. Let's see this behavior with an example,\n\n```javascript\nvar date = new Date(Date.UTC(2019, 07, 07, 3, 0, 0));\nconsole.log(new Intl.DateTimeFormat('en-GB').format(date)); // 07/08/2019\nconsole.log(new Intl.DateTimeFormat('en-AU').format(date)); // 07/08/2019\n```</code></pre></div>\n</li>\n<li>\n<p>What is an Iterator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An iterator is an object which defines a sequence and a return value upon its termination. It implements the Iterator protocol with a `next()` method which returns an object with two properties: `value` (the next value in the sequence) and `done` (which is true if the last value in the sequence has been consumed).</code></pre></div>\n</li>\n<li>\n<p>How does synchronous iteration works</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Synchronous iteration was introduced in ES6 and it works with below set of components,\n\n**Iterable:** It is an object which can be iterated over via a method whose key is Symbol.iterator.\n**Iterator:** It is an object returned by invoking `[Symbol.iterator]()` on an iterable. This iterator object wraps each iterated element in an object and returns it via `next()` method one by one.\n**IteratorResult:** It is an object returned by `next()` method. The object contains two properties; the `value` property contains an iterated element and the `done` property determines whether the element is the last element or not.\n\nLet's demonstrate synchronous iteration with an array as below,\n\n```javascript\nconst iterable = ['one', 'two', 'three'];\nconst iterator = iterable[Symbol.iterator]();\nconsole.log(iterator.next()); // { value: 'one', done: false }\nconsole.log(iterator.next()); // { value: 'two', done: false }\nconsole.log(iterator.next()); // { value: 'three', done: false }\nconsole.log(iterator.next()); // { value: 'undefined, done: true }\n```</code></pre></div>\n</li>\n<li>\n<p>What is an event loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Event Loop is a queue of callback functions. When an async function executes, the callback function is pushed into the queue. The JavaScript engine doesn't start processing the event loop until the async function has finished executing the code.\n**Note:** It allows Node.js to perform non-blocking I/O operations even though JavaScript is single-threaded.</code></pre></div>\n</li>\n<li>\n<p>What is call stack</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Call Stack is a data structure for javascript interpreters to keep track of function calls in the program. It has two major actions,\n\n1. Whenever you call a function for its execution, you are pushing it to the stack.\n2. Whenever the execution is completed, the function is popped out of the stack.\n\nLet's take an example and it's state representation in a diagram format\n\n```javascript\nfunction hungry() {\n    eatFruits();\n}\nfunction eatFruits() {\n    return \"I'm eating fruits\";\n}\n\n// Invoke the `hungry` function\nhungry();\n```\n\nThe above code processed in a call stack as below,\n\n1. Add the `hungry()` function to the call stack list and execute the code.\n2. Add the `eatFruits()` function to the call stack list and execute the code.\n3. Delete the `eatFruits()` function from our call stack list.\n4. Delete the `hungry()` function from the call stack list since there are no items anymore.\n\n![Screenshot](images/call-stack.png)</code></pre></div>\n</li>\n<li>What is an event queue</li>\n<li>\n<p>What is a decorator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A decorator is an expression that evaluates to a function and that takes the target, name, and decorator descriptor as arguments. Also, it optionally returns a decorator descriptor to install on the target object. Let's define admin decorator for user class at design time,\n\n```javascript\nfunction admin(isAdmin) {\n   return function(target) {\n       target.isAdmin = isAdmin;\n   }\n}\n\n@admin(true)\nclass User() {\n}\nconsole.log(User.isAdmin); //true\n\n @admin(false)\n class User() {\n }\n console.log(User.isAdmin); //false\n```</code></pre></div>\n</li>\n<li>\n<p>What are the properties of Intl object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of properties available on Intl object,\n\n1. **Collator:** These are the objects that enable language-sensitive string comparison.\n2. **DateTimeFormat:** These are the objects that enable language-sensitive date and time formatting.\n3. **ListFormat:** These are the objects that enable language-sensitive list formatting.\n4. **NumberFormat:** Objects that enable language-sensitive number formatting.\n5. **PluralRules:** Objects that enable plural-sensitive formatting and language-specific rules for plurals.\n6. **RelativeTimeFormat:** Objects that enable language-sensitive relative time formatting.</code></pre></div>\n</li>\n<li>\n<p>What is an Unary operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The unary(+) operator is used to convert a variable to a number.If the variable cannot be converted, it will still become a number but with the value NaN. Let's see this behavior in an action.\n\n```javascript\nvar x = '100';\nvar y = +x;\nconsole.log(typeof x, typeof y); // string, number\n\nvar a = 'Hello';\nvar b = +a;\nconsole.log(typeof a, typeof b, b); // string, number, NaN\n```</code></pre></div>\n</li>\n<li>\n<p>How do you sort elements in an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The sort() method is used to sort the elements of an array in place and returns the sorted array. The example usage would be as below,\n\n```javascript\nvar months = ['Aug', 'Sep', 'Jan', 'June'];\nmonths.sort();\nconsole.log(months); //  [\"Aug\", \"Jan\", \"June\", \"Sep\"]\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of compareFunction while sorting arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The compareFunction is used to define the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value. Let's take an example to see the usage of compareFunction,\n\n```javascript\nlet numbers = [1, 2, 5, 3, 4];\nnumbers.sort((a, b) => b - a);\nconsole.log(numbers); // [5, 4, 3, 2, 1]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you reversing an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the reverse() method to reverse the elements in an array. This method is useful to sort an array in descending order. Let's see the usage of reverse() method in an example,\n\n```javascript\nlet numbers = [1, 2, 5, 3, 4];\nnumbers.sort((a, b) => b - a);\nnumbers.reverse();\nconsole.log(numbers); // [1, 2, 3, 4 ,5]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you find min and max value in an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `Math.min` and `Math.max` methods on array variables to find the minimum and maximum elements within an array. Let's create two functions to find the min and max value with in an array,\n\n```javascript\nvar marks = [50, 20, 70, 60, 45, 30];\nfunction findMin(arr) {\n    return Math.min.apply(null, arr);\n}\nfunction findMax(arr) {\n    return Math.max.apply(null, arr);\n}\n\nconsole.log(findMin(marks));\nconsole.log(findMax(marks));\n```</code></pre></div>\n</li>\n<li>\n<p>How do you find min and max values without Math functions</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can write functions which loop through an array comparing each value with the lowest value or highest value to find the min and max values. Let's create those functions to find min and max values,\n\n```javascript\nvar marks = [50, 20, 70, 60, 45, 30];\nfunction findMin(arr) {\n    var length = arr.length;\n    var min = Infinity;\n    while (length--) {\n        if (arr[length] &lt; min) {\n            min = arr[len];\n        }\n    }\n    return min;\n}\n\nfunction findMax(arr) {\n    var length = arr.length;\n    var max = -Infinity;\n    while (len--) {\n        if (arr[length] > max) {\n            max = arr[length];\n        }\n    }\n    return max;\n}\n\nconsole.log(findMin(marks));\nconsole.log(findMax(marks));\n```</code></pre></div>\n</li>\n<li>\n<p>What is an empty statement and purpose of it</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The empty statement is a semicolon (;) indicating that no statement will be executed, even if JavaScript syntax requires one. Since there is no action with an empty statement you might think that it's usage is quite less, but the empty statement is occasionally useful when you want to create a loop that has an empty body. For example, you can initialize an array with zero values as below,\n\n```javascript\n// Initialize an array a\nfor(int i=0; i &lt; a.length; a[i++] = 0) ;\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get metadata of a module</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `import.meta` object which is a meta-property exposing context-specific meta data to a JavaScript module. It contains information about the current module, such as the module's URL. In browsers, you might get different meta data than NodeJS.\n\n```javascript\n&lt;script type=\"module\" src=\"welcome-module.js\">&lt;/script>;\nconsole.log(import.meta); // { url: \"file:///home/user/welcome-module.js\" }\n```</code></pre></div>\n</li>\n<li>\n<p>What is a comma operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The comma operator is used to evaluate each of its operands from left to right and returns the value of the last operand. This is totally different from comma usage within arrays, objects, and function arguments and parameters. For example, the usage for numeric expressions would be as below,\n\n```javascript\nvar x = 1;\nx = (x++, x);\n\nconsole.log(x); // 2\n```</code></pre></div>\n</li>\n<li>\n<p>What is the advantage of a comma operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is normally used to include multiple expressions in a location that requires a single expression. One of the common usages of this comma operator is to supply multiple parameters in a `for` loop. For example, the below for loop uses multiple expressions in a single location using comma operator,\n\n```javascript\nfor (var a = 0, b =10; a &lt;= 10; a++, b--)\n```\n\nYou can also use the comma operator in a return statement where it processes before returning.\n\n```javascript\nfunction myFunction() {\n    var a = 1;\n    return (a += 10), a; // 11\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is typescript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">TypeScript is a typed superset of JavaScript created by Microsoft that adds optional types, classes, async/await, and many other features, and compiles to plain JavaScript. Angular built entirely in TypeScript and used as a primary language. You can install it globally as\n\n```shell\nnpm install -g typescript\n```\n\nLet's see a simple example of TypeScript usage,\n\n```typescript\nfunction greeting(name: string): string {\n    return 'Hello, ' + name;\n}\n\nlet user = 'Sudheer';\n\nconsole.log(greeting(user));\n```\n\nThe greeting method allows only string type as argument.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between javascript and typescript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of differences between javascript and typescript,\n\n| feature             | typescript                            | javascript                                      |\n| ------------------- | ------------------------------------- | ----------------------------------------------- |\n| Language paradigm   | Object oriented programming language  | Scripting language                              |\n| Typing support      | Supports static typing                | It has dynamic typing                           |\n| Modules             | Supported                             | Not supported                                   |\n| Interface           | It has interfaces concept             | Doesn't support interfaces                      |\n| Optional parameters | Functions support optional parameters | No support of optional parameters for functions |</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of typescript over javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are some of the advantages of typescript over javascript,\n\n1. TypeScript is able to find compile time errors at the development time only and it makes sures less runtime errors. Whereas javascript is an interpreted language.\n2. TypeScript is strongly-typed or supports static typing which allows for checking type correctness at compile time. This is not available in javascript.\n3. TypeScript compiler can compile the .ts files into ES3,ES4 and ES5 unlike ES6 features of javascript which may not be supported in some browsers.</code></pre></div>\n</li>\n<li>\n<p>What is an object initializer</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An object initializer is an expression that describes the initialization of an Object. The syntax for this expression is represented as a comma-delimited list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}). This is also known as literal notation. It is one of the ways to create an object.\n\n```javascript\nvar initObject = { a: 'John', b: 50, c: {} };\n\nconsole.log(initObject.a); // John\n```</code></pre></div>\n</li>\n<li>\n<p>What is a constructor method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The constructor method is a special method for creating and initializing an object created within a class. If you do not specify a constructor method, a default constructor is used. The example usage of constructor would be as below,\n\n```javascript\nclass Employee {\n    constructor() {\n        this.name = 'John';\n    }\n}\n\nvar employeeObject = new Employee();\n\nconsole.log(employeeObject.name); // John\n```</code></pre></div>\n</li>\n<li>\n<p>What happens if you write constructor more than once in a class</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The \"constructor\" in a class is a special method and it should be defined only once in a class. i.e, If you write a constructor method more than once in a class it will throw a `SyntaxError` error.\n\n```javascript\n class Employee {\n   constructor() {\n     this.name = \"John\";\n   }\n   constructor() {   //  Uncaught SyntaxError: A class may only have one constructor\n     this.age = 30;\n   }\n }\n\n var employeeObject = new Employee();\n\n console.log(employeeObject.name);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you call the constructor of a parent class</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `super` keyword to call the constructor of a parent class. Remember that `super()` must be called before using 'this' reference. Otherwise it will cause a reference error. Let's the usage of it,\n\n```javascript\nclass Square extends Rectangle {\n    constructor(length) {\n        super(length, length);\n        this.name = 'Square';\n    }\n\n    get area() {\n        return this.width * this.height;\n    }\n\n    set area(value) {\n        this.area = value;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get the prototype of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.getPrototypeOf(obj)` method to return the prototype of the specified object. i.e. The value of the internal `prototype` property. If there are no inherited properties then `null` value is returned.\n\n```javascript\nconst newPrototype = {};\nconst newObject = Object.create(newPrototype);\n\nconsole.log(Object.getPrototypeOf(newObject) === newPrototype); // true\n```</code></pre></div>\n</li>\n<li>\n<p>What happens If I pass string type for getPrototype method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In ES5, it will throw a TypeError exception if the obj parameter isn't an object. Whereas in ES2015, the parameter will be coerced to an `Object`.\n\n```javascript\n// ES5\nObject.getPrototypeOf('James'); // TypeError: \"James\" is not an object\n// ES2015\nObject.getPrototypeOf('James'); // String.prototype\n```</code></pre></div>\n</li>\n<li>\n<p>How do you set prototype of one object to another</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.setPrototypeOf()` method that sets the prototype (i.e., the internal `Prototype` property) of a specified object to another object or null. For example, if you want to set prototype of a square object to rectangle object would be as follows,\n\n```javascript\nObject.setPrototypeOf(Square.prototype, Rectangle.prototype);\nObject.setPrototypeOf({}, null);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether an object can be extendable or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `Object.isExtensible()` method is used to determine if an object is extendable or not. i.e, Whether it can have new properties added to it or not.\n\n```javascript\nconst newObject = {};\nconsole.log(Object.isExtensible(newObject)); //true\n```\n\n**Note:** By default, all the objects are extendable. i.e, The new properties can be added or modified.</code></pre></div>\n</li>\n<li>\n<p>How do you prevent an object to extend</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `Object.preventExtensions()` method is used to prevent new properties from ever being added to an object. In other words, it prevents future extensions to the object. Let's see the usage of this property,\n\n```javascript\nconst newObject = {};\nObject.preventExtensions(newObject); // NOT extendable\n\ntry {\n    Object.defineProperty(newObject, 'newProperty', {\n        // Adding new property\n        value: 100\n    });\n} catch (e) {\n    console.log(e); // TypeError: Cannot define property newProperty, object is not extensible\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to make an object non-extensible</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can mark an object non-extensible in 3 ways,\n\n1. Object.preventExtensions\n2. Object.seal\n3. Object.freeze\n\n```javascript\nvar newObject = {};\n\nObject.preventExtensions(newObject); // Prevent objects are non-extensible\nObject.isExtensible(newObject); // false\n\nvar sealedObject = Object.seal({}); // Sealed objects are non-extensible\nObject.isExtensible(sealedObject); // false\n\nvar frozenObject = Object.freeze({}); // Frozen objects are non-extensible\nObject.isExtensible(frozenObject); // false\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define multiple properties on an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `Object.defineProperties()` method is used to define new or modify existing properties directly on an object and returning the object. Let's define multiple properties on an empty object,\n\n```javascript\nconst newObject = {};\n\nObject.defineProperties(newObject, {\n    newProperty1: {\n        value: 'John',\n        writable: true\n    },\n    newProperty2: {}\n});\n```</code></pre></div>\n</li>\n<li>\n<p>What is MEAN in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The MEAN (MongoDB, Express, AngularJS, and Node.js) stack is the most popular open-source JavaScript software tech stack available for building dynamic web apps where you can write both the server-side and client-side halves of the web project entirely in JavaScript.</code></pre></div>\n</li>\n<li>\n<p>What Is Obfuscation in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Obfuscation is the deliberate act of creating obfuscated javascript code(i.e, source or machine code) that is difficult for humans to understand. It is something similar to encryption, but a machine can understand the code and execute it.\nLet's see the below function before Obfuscation,\n\n```javascript\nfunction greeting() {\n    console.log('Hello, welcome to JS world');\n}\n```\n\nAnd after the code Obfuscation, it would be appeared as below,\n\n```javascript\neval(\n    (function (p, a, c, k, e, d) {\n        e = function (c) {\n            return c;\n        };\n        if (!''.replace(/^/, String)) {\n            while (c--) {\n                d[c] = k[c] || c;\n            }\n            k = [\n                function (e) {\n                    return d[e];\n                }\n            ];\n            e = function () {\n                return '\\\\w+';\n            };\n            c = 1;\n        }\n        while (c--) {\n            if (k[c]) {\n                p = p.replace(new RegExp('\\\\b' + e(c) + '\\\\b', 'g'), k[c]);\n            }\n        }\n        return p;\n    })(\"2 1(){0.3('4, 7 6 5 8')}\", 9, 9, 'console|greeting|function|log|Hello|JS|to|welcome|world'.split('|'), 0, {})\n);\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need Obfuscation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the few reasons for Obfuscation,\n\n1. The Code size will be reduced. So data transfers between server and client will be fast.\n2. It hides the business logic from outside world and protects the code from others\n3. Reverse engineering is highly difficult\n4. The download time will be reduced</code></pre></div>\n</li>\n<li>\n<p>What is Minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Minification is the process of removing all unnecessary characters(empty spaces are removed) and variables will be renamed without changing it's functionality. It is also a type of obfuscation .</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Normally it is recommended to use minification for heavy traffic and intensive requirements of resources. It reduces file sizes with below benefits,\n\n1. Decreases loading times of a web page\n2. Saves bandwidth usages</code></pre></div>\n</li>\n<li>\n<p>What are the differences between Obfuscation and Encryption</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main differences between Obfuscation and Encryption,\n\n| Feature            | Obfuscation                                     | Encryption                                                              |\n| ------------------ | ----------------------------------------------- | ----------------------------------------------------------------------- |\n| Definition         | Changing the form of any data in any other form | Changing the form of information to an unreadable format by using a key |\n| A key to decode    | It can be decoded without any key               | It is required                                                          |\n| Target data format | It will be converted to a complex form          | Converted into an unreadable format                                     |</code></pre></div>\n</li>\n<li>\n<p>What are the common tools used for minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are many online/offline tools to minify the javascript files,\n\n1. Google's Closure Compiler\n2. UglifyJS2\n3. jsmin\n4. javascript-minifier.com/\n5. prettydiff.com</code></pre></div>\n</li>\n<li>\n<p>How do you perform form validation using javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript can be used to perform HTML form validation. For example, if the form field is empty, the function needs to notify, and return false, to prevent the form being submitted.\nLets' perform user login in an html form,\n\n```html\n&lt;form name=\"myForm\" onsubmit=\"return validateForm()\" method=\"post\">\n    User name: &lt;input type=\"text\" name=\"uname\" />\n    &lt;input type=\"submit\" value=\"Submit\" />\n&lt;/form>\n```\n\nAnd the validation on user login is below,\n\n```javascript\nfunction validateForm() {\n    var x = document.forms['myForm']['uname'].value;\n    if (x == '') {\n        alert(\"The username shouldn't be empty\");\n        return false;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you perform form validation without javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can perform HTML form validation automatically without using javascript. The validation enabled by applying the `required` attribute to prevent form submission when the input is empty.\n\n```html\n&lt;form method=\"post\">\n    &lt;input type=\"text\" name=\"uname\" required />\n    &lt;input type=\"submit\" value=\"Submit\" />\n&lt;/form>\n```\n\n**Note:** Automatic form validation does not work in Internet Explorer 9 or earlier.</code></pre></div>\n</li>\n<li>\n<p>What are the DOM methods available for constraint validation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The below DOM methods are available for constraint validation on an invalid input,\n\n1. checkValidity(): It returns true if an input element contains valid data.\n2. setCustomValidity(): It is used to set the validationMessage property of an input element.\n   Let's take an user login form with DOM validations\n\n```javascript\nfunction myFunction() {\n    var userName = document.getElementById('uname');\n    if (!userName.checkValidity()) {\n        document.getElementById('message').innerHTML = userName.validationMessage;\n    } else {\n        document.getElementById('message').innerHTML = 'Entered a valid username';\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the available constraint validation DOM properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of some of the constraint validation DOM properties available,\n\n1. validity: It provides a list of boolean properties related to the validity of an input element.\n2. validationMessage: It displays the message when the validity is false.\n3. willValidate: It indicates if an input element will be validated or not.</code></pre></div>\n</li>\n<li>\n<p>What are the list of validity properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The validity property of an input element provides a set of properties related to the validity of data.\n\n1. customError: It returns true, if a custom validity message is set.\n2. patternMismatch: It returns true, if an element's value does not match its pattern attribute.\n3. rangeOverflow: It returns true, if an element's value is greater than its max attribute.\n4. rangeUnderflow: It returns true, if an element's value is less than its min attribute.\n5. stepMismatch: It returns true, if an element's value is invalid according to step attribute.\n6. tooLong: It returns true, if an element's value exceeds its maxLength attribute.\n7. typeMismatch: It returns true, if an element's value is invalid according to type attribute.\n8. valueMissing: It returns true, if an element with a required attribute has no value.\n9. valid: It returns true, if an element's value is valid.</code></pre></div>\n</li>\n<li>\n<p>Give an example usage of rangeOverflow property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If an element's value is greater than its max attribute then rangeOverflow property returns true. For example, the below form submission throws an error if the value is more than 100,\n\n```html\n&lt;input id=\"age\" type=\"number\" max=\"100\" /> &lt;button onclick=\"myOverflowFunction()\">OK&lt;/button>\n```\n\n```javascript\nfunction myOverflowFunction() {\n    if (document.getElementById('age').validity.rangeOverflow) {\n        alert('The mentioned age is not allowed');\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>Is enums feature available in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, javascript does not natively support enums. But there are different kinds of solutions to simulate them even though they may not provide exact equivalents. For example, you can use freeze or seal on object,\n\n```javascript\nvar DaysEnum = Object.freeze({\"monday\":1, \"tuesday\":2, \"wednesday\":3, ...})\n```</code></pre></div>\n</li>\n<li>\n<p>What is an enum</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An enum is a type restricting variables to one value from a predefined set of constants. JavaScript has no enums but typescript provides built-in enum support.\n\n```javascript\nenum Color {\n RED, GREEN, BLUE\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you list all properties of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.getOwnPropertyNames()` method which returns an array of all properties found directly in a given object. Let's the usage of it in an example,\n\n```javascript\nconst newObject = {\n    a: 1,\n    b: 2,\n    c: 3\n};\n\nconsole.log(Object.getOwnPropertyNames(newObject));\n['a', 'b', 'c'];\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get property descriptors of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.getOwnPropertyDescriptors()` method which returns all own property descriptors of a given object. The example usage of this method is below,\n\n```javascript\nconst newObject = {\n    a: 1,\n    b: 2,\n    c: 3\n};\nconst descriptorsObject = Object.getOwnPropertyDescriptors(newObject);\nconsole.log(descriptorsObject.a.writable); //true\nconsole.log(descriptorsObject.a.configurable); //true\nconsole.log(descriptorsObject.a.enumerable); //true\nconsole.log(descriptorsObject.a.value); // 1\n```</code></pre></div>\n</li>\n<li>\n<p>What are the attributes provided by a property descriptor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A property descriptor is a record which has the following attributes\n\n1. value: The value associated with the property\n2. writable: Determines whether the value associated with the property can be changed or not\n3. configurable: Returns true if the type of this property descriptor can be changed and if the property can be deleted from the corresponding object.\n4. enumerable: Determines whether the property appears during enumeration of the properties on the corresponding object or not.\n5. set: A function which serves as a setter for the property\n6. get: A function which serves as a getter for the property</code></pre></div>\n</li>\n<li>\n<p>How do you extend classes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `extends` keyword is used in class declarations/expressions to create a class which is a child of another class. It can be used to subclass custom classes as well as built-in objects. The syntax would be as below,\n\n```javascript\nclass ChildClass extends ParentClass { ... }\n```\n\nLet's take an example of Square subclass from Polygon parent class,\n\n```javascript\nclass Square extends Rectangle {\n    constructor(length) {\n        super(length, length);\n        this.name = 'Square';\n    }\n\n    get area() {\n        return this.width * this.height;\n    }\n\n    set area(value) {\n        this.area = value;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do I modify the url without reloading the page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `window.location.url` property will be helpful to modify the url but it reloads the page. HTML5 introduced the `history.pushState()` and `history.replaceState()` methods, which allow you to add and modify history entries, respectively. For example, you can use pushState as below,\n\n```javascript\nwindow.history.pushState('page2', 'Title', '/page2.html');\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether an array includes a particular value or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `Array#includes()` method is used to determine whether an array includes a particular value among its entries by returning either true or false. Let's see an example to find an element(numeric and string) within an array.\n\n```javascript\nvar numericArray = [1, 2, 3, 4];\nconsole.log(numericArray.includes(3)); // true\n\nvar stringArray = ['green', 'yellow', 'blue'];\nconsole.log(stringArray.includes('blue')); //true\n```</code></pre></div>\n</li>\n<li>\n<p>How do you compare scalar arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use length and every method of arrays to compare two scalar(compared directly using ===) arrays. The combination of these expressions can give the expected result,\n\n```javascript\nconst arrayFirst = [1, 2, 3, 4, 5];\nconst arraySecond = [1, 2, 3, 4, 5];\nconsole.log(arrayFirst.length === arraySecond.length &amp;&amp; arrayFirst.every((value, index) => value === arraySecond[index])); // true\n```\n\nIf you would like to compare arrays irrespective of order then you should sort them before,\n\n```javascript\nconst arrayFirst = [2, 3, 1, 4, 5];\nconst arraySecond = [1, 2, 3, 4, 5];\nconsole.log(arrayFirst.length === arraySecond.length &amp;&amp; arrayFirst.sort().every((value, index) => value === arraySecond[index])); //true\n```</code></pre></div>\n</li>\n<li>\n<p>How to get the value from get parameters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `new URL()` object accepts the url string and `searchParams` property of this object can be used to access the get parameters. Remember that you may need to use polyfill or `window.location` to access the URL in older browsers(including IE).\n\n```javascript\nlet urlString = 'http://www.some-domain.com/about.html?x=1&amp;y=2&amp;z=3'; //window.location.href\nlet url = new URL(urlString);\nlet parameterZ = url.searchParams.get('z');\nconsole.log(parameterZ); // 3\n```</code></pre></div>\n</li>\n<li>\n<p>How do you print numbers with commas as thousand separators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Number.prototype.toLocaleString()` method which returns a string with a language-sensitive representation such as thousand separator,currency etc of this number.\n\n```javascript\nfunction convertToThousandFormat(x) {\n    return x.toLocaleString(); // 12,345.679\n}\n\nconsole.log(convertToThousandFormat(12345.6789));\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between java and javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both are totally unrelated programming languages and no relation between them. Java is statically typed, compiled, runs on its own VM. Whereas Javascript is dynamically typed, interpreted, and runs in a browser and nodejs environments. Let's see the major differences in a tabular format,\n| Feature | Java | JavaScript |\n|---- | ---- | -----\n| Typed | It's a strongly typed language | It's a dynamic typed language |\n| Paradigm | Object oriented programming | Prototype based programming |\n| Scoping | Block scoped | Function-scoped |\n| Concurrency | Thread based | event based |\n| Memory | Uses more memory | Uses less memory. Hence it will be used for web pages |</code></pre></div>\n</li>\n<li>\n<p>Does JavaScript supports namespace</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript doesn't support namespace by default. So if you create any element(function, method, object, variable) then it becomes global and pollutes the global namespace. Let's take an example of defining two functions without any namespace,\n\n```javascript\nfunction func1() {\n    console.log('This is a first definition');\n}\nfunction func1() {\n    console.log('This is a second definition');\n}\nfunc1(); // This is a second definition\n```\n\nIt always calls the second function definition. In this case, namespace will solve the name collision problem.</code></pre></div>\n</li>\n<li>\n<p>How do you declare namespace</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Even though JavaScript lacks namespaces, we can use Objects , IIFE to create namespaces.\n\n1. **Using Object Literal Notation:** Let's wrap variables and functions inside an Object literal which acts as a namespace. After that you can access them using object notation\n\n```javascript\nvar namespaceOne = {\n   function func1() {\n       console.log(\"This is a first definition\");\n   }\n}\nvar namespaceTwo = {\n     function func1() {\n         console.log(\"This is a second definition\");\n     }\n }\nnamespaceOne.func1(); // This is a first definition\nnamespaceTwo.func1(); // This is a second definition\n```\n\n1. **Using IIFE (Immediately invoked function expression):** The outer pair of parentheses of IIFE creates a local scope for all the code inside of it and makes the anonymous function a function expression. Due to that, you can create the same function in two different function expressions to act as a namespace.\n\n```javascript\n(function () {\n    function fun1() {\n        console.log('This is a first definition');\n    }\n    fun1();\n})();\n\n(function () {\n    function fun1() {\n        console.log('This is a second definition');\n    }\n    fun1();\n})();\n```\n\n1. **Using a block and a let/const declaration:** In ECMAScript 6, you can simply use a block and a let declaration to restrict the scope of a variable to a block.\n\n```javascript\n{\n    let myFunction = function fun1() {\n        console.log('This is a first definition');\n    };\n    myFunction();\n}\n//myFunction(): ReferenceError: myFunction is not defined.\n\n{\n    let myFunction = function fun1() {\n        console.log('This is a second definition');\n    };\n    myFunction();\n}\n//myFunction(): ReferenceError: myFunction is not defined.\n```</code></pre></div>\n</li>\n<li>\n<p>How do you invoke javascript code in an iframe from parent page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Initially iFrame needs to be accessed using either `document.getElementBy` or `window.frames`. After that `contentWindow` property of iFrame gives the access for targetFunction\n\n```javascript\ndocument.getElementById('targetFrame').contentWindow.targetFunction();\nwindow.frames[0].frameElement.contentWindow.targetFunction(); // Accessing iframe this way may not work in latest versions chrome and firefox\n```</code></pre></div>\n</li>\n<li>\n<p>How do get the timezone offset from date</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `getTimezoneOffset` method of the date object. This method returns the time zone difference, in minutes, from current locale (host system settings) to UTC\n\n```javascript\nvar offset = new Date().getTimezoneOffset();\nconsole.log(offset); // -480\n```</code></pre></div>\n</li>\n<li>\n<p>How do you load CSS and JS files dynamically</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can create both link and script elements in the DOM and append them as child to head tag. Let's create a function to add script and style resources as below,\n\n```javascript\nfunction loadAssets(filename, filetype) {\n    if (filetype == 'css') {\n        // External CSS file\n        var fileReference = document.createElement('link');\n        fileReference.setAttribute('rel', 'stylesheet');\n        fileReference.setAttribute('type', 'text/css');\n        fileReference.setAttribute('href', filename);\n    } else if (filetype == 'js') {\n        // External JavaScript file\n        var fileReference = document.createElement('script');\n        fileReference.setAttribute('type', 'text/javascript');\n        fileReference.setAttribute('src', filename);\n    }\n    if (typeof fileReference != 'undefined') document.getElementsByTagName('head')[0].appendChild(fileReference);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different methods to find HTML elements in DOM</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you want to access any element in an HTML page, you need to start with accessing the document object. Later you can use any of the below methods to find the HTML element,\n\n1. document.getElementById(id): It finds an element by Id\n2. document.getElementsByTagName(name): It finds an element by tag name\n3. document.getElementsByClassName(name): It finds an element by class name</code></pre></div>\n</li>\n<li>\n<p>What is jQuery</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">jQuery is a popular cross-browser JavaScript library that provides Document Object Model (DOM) traversal, event handling, animations and AJAX interactions by minimizing the discrepancies across browsers. It is widely famous with its philosophy of \"Write less, do more\". For example, you can display welcome message on the page load using jQuery as below,\n\n```javascript\n$(document).ready(function () {\n    // It selects the document and apply the function on page load\n    alert('Welcome to jQuery world');\n});\n```\n\n**Note:** You can download it from jquery's official site or install it from CDNs, like google.</code></pre></div>\n</li>\n<li>\n<p>What is V8 JavaScript engine</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">V8 is an open source high-performance JavaScript engine used by the Google Chrome browser, written in C++. It is also being used in the node.js project. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors.\n**Note:** It can run standalone, or can be embedded into any C++ application.</code></pre></div>\n</li>\n<li>\n<p>Why do we call javascript as dynamic language</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a loosely typed or a dynamic language because variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned/reassigned with values of all types.\n\n```javascript\nlet age = 50; // age is a number now\nage = 'old'; // age is a string now\nage = true; // age is a boolean\n```</code></pre></div>\n</li>\n<li>\n<p>What is a void operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `void` operator evaluates the given expression and then returns undefined(i.e, without returning value). The syntax would be as below,\n\n```javascript\nvoid expression;\nvoid expression;\n```\n\nLet's display a message without any redirection or reload\n\n```javascript\n&lt;a href=\"javascript:void(alert('Welcome to JS world'))\">Click here to see a message&lt;/a>\n```\n\n**Note:** This operator is often used to obtain the undefined primitive value, using \"void(0)\".</code></pre></div>\n</li>\n<li>\n<p>How to set the cursor to wait</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The cursor can be set to wait in JavaScript by using the property \"cursor\". Let's perform this behavior on page load using the below function.\n\n```javascript\nfunction myFunction() {\n    window.document.body.style.cursor = 'wait';\n}\n```\n\nand this function invoked on page load\n\n```html\n&lt;body onload=\"myFunction()\">&lt;/body>\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create an infinite loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can create infinite loops using for and while loops without using any expressions. The for loop construct or syntax is better approach in terms of ESLint and code optimizer tools,\n\n```javascript\nfor (;;) {}\nwhile (true) {}\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need to avoid with statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript's with statement was intended to provide a shorthand for writing recurring accesses to objects. So it can help reduce file size by reducing the need to repeat a lengthy object reference without performance penalty. Let's take an example where it is used to avoid redundancy when accessing an object several times.\n\n```javascript\na.b.c.greeting = 'welcome';\na.b.c.age = 32;\n```\n\nUsing `with` it turns this into:\n\n```javascript\nwith (a.b.c) {\n    greeting = 'welcome';\n    age = 32;\n}\n```\n\nBut this `with` statement creates performance problems since one cannot predict whether an argument will refer to a real variable or to a property inside the with argument.</code></pre></div>\n</li>\n<li>\n<p>What is the output of below for loops</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">```javascript\nfor (var i = 0; i &lt; 4; i++) {\n    // global scope\n    setTimeout(() => console.log(i));\n}\n\nfor (let i = 0; i &lt; 4; i++) {\n    // block scope\n    setTimeout(() => console.log(i));\n}\n```\n\nThe output of the above for loops is 4 4 4 4 and 0 1 2 3\n\n**Explanation:** Due to the event queue/loop of javascript, the `setTimeout` callback function is called after the loop has been executed. Since the variable i is declared with the `var` keyword it became a global variable and the value was equal to 4 using iteration when the time `setTimeout` function is invoked. Hence, the output of the first loop is `4 4 4 4`.\n\nWhereas in the second loop, the variable i is declared as the `let` keyword it becomes a block scoped variable and it holds a new value(0, 1 ,2 3) for each iteration. Hence, the output of the first loop is `0 1 2 3`.</code></pre></div>\n</li>\n<li>\n<p>List down some of the features of ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of some new features of ES6,\n\n1. Support for constants or immutable variables\n2. Block-scope support for variables, constants and functions\n3. Arrow functions\n4. Default parameters\n5. Rest and Spread Parameters\n6. Template Literals\n7. Multi-line Strings\n8. Destructuring Assignment\n9. Enhanced Object Literals\n10. Promises\n11. Classes\n12. Modules</code></pre></div>\n</li>\n<li>\n<p>What is ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ES6 is the sixth edition of the javascript language and it was released in June 2015. It was initially known as ECMAScript 6 (ES6) and later renamed to ECMAScript 2015. Almost all the modern browsers support ES6 but for the old browsers there are many transpilers, like Babel.js etc.</code></pre></div>\n</li>\n<li>\n<p>Can I redeclare let and const variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, you cannot redeclare let and const variables. If you do, it throws below error\n\n```shell\nUncaught SyntaxError: Identifier 'someVariable' has already been declared\n```\n\n**Explanation:** The variable declaration with `var` keyword refers to a function scope and the variable is treated as if it were declared at the top of the enclosing scope due to hoisting feature. So all the multiple declarations contributing to the same hoisted variable without any error. Let's take an example of re-declaring variables in the same scope for both var and let/const variables.\n\n```javascript\nvar name = 'John';\nfunction myFunc() {\n    var name = 'Nick';\n    var name = 'Abraham'; // Re-assigned in the same function block\n    alert(name); // Abraham\n}\nmyFunc();\nalert(name); // John\n```\n\nThe block-scoped multi-declaration throws syntax error,\n\n```javascript\nlet name = 'John';\nfunction myFunc() {\n    let name = 'Nick';\n    let name = 'Abraham'; // Uncaught SyntaxError: Identifier 'name' has already been declared\n    alert(name);\n}\n\nmyFunc();\nalert(name);\n```</code></pre></div>\n</li>\n<li>\n<p>Is const variable makes the value immutable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, the const variable doesn't make the value immutable. But it disallows subsequent assignments(i.e, You can declare with assignment but can't assign another value later)\n\n```javascript\nconst userList = [];\nuserList.push('John'); // Can mutate even though it can't re-assign\nconsole.log(userList); // ['John']\n```</code></pre></div>\n</li>\n<li>\n<p>What are default parameters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In E5, we need to depend on logical OR operators to handle default values of function parameters. Whereas in ES6, Default function parameters feature allows parameters to be initialized with default values if no value or undefined is passed. Let's compare the behavior with an examples,\n\n```javascript\n//ES5\nvar calculateArea = function (height, width) {\n    height = height || 50;\n    width = width || 60;\n\n    return width * height;\n};\nconsole.log(calculateArea()); //300\n```\n\nThe default parameters makes the initialization more simpler,\n\n```javascript\n//ES6\nvar calculateArea = function (height = 50, width = 60) {\n    return width * height;\n};\n\nconsole.log(calculateArea()); //300\n```</code></pre></div>\n</li>\n<li>\n<p>What are template literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Template literals or template strings are string literals allowing embedded expressions. These are enclosed by the back-tick (`) character instead of double or single quotes.\nIn E6, this feature enables using dynamic expressions as below,\n\n```javascript\nvar greeting = `Welcome to JS World, Mr. ${firstName} ${lastName}.`;\n```\n\nIn ES5, you need break string like below,\n\n```javascript\nvar greeting = 'Welcome to JS World, Mr. ' + firstName + ' ' + lastName.`\n```\n\n**Note:** You can use multi-line strings and string interpolation features with template literals.</code></pre></div>\n</li>\n<li>\n<p>How do you write multi-line strings in template literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In ES5, you would have to use newline escape characters('\\\\n') and concatenation symbols(+) in order to get multi-line strings.\n\n```javascript\nconsole.log('This is string sentence 1\\n' + 'This is string sentence 2');\n```\n\nWhereas in ES6, You don't need to mention any newline sequence character,\n\n```javascript\nconsole.log(`This is string sentence\n'This is string sentence 2`);\n```</code></pre></div>\n</li>\n<li>\n<p>What are nesting templates</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The nesting template is a feature supported within template literals syntax to allow inner backticks inside a placeholder ${ } within the template. For example, the below nesting template is used to display the icons based on user permissions whereas outer template checks for platform type,\n\n```javascript\nconst iconStyles = `icon ${isMobilePlatform() ? '' : `icon-${user.isAuthorized ? 'submit' : 'disabled'}`}`;\n```\n\nYou can write the above use case without nesting template features as well. However, the nesting template feature is more compact and readable.\n\n```javascript\n//Without nesting templates\n const iconStyles = `icon ${ isMobilePlatform() ? '' :\n  (user.isAuthorized ? 'icon-submit' : 'icon-disabled'}`;\n```</code></pre></div>\n</li>\n<li>\n<p>What are tagged templates</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tagged templates are the advanced form of templates in which tags allow you to parse template literals with a function. The tag function accepts the first parameter as an array of strings and remaining parameters as expressions. This function can also return manipulated strings based on parameters. Let's see the usage of this tagged template behavior of an IT professional skill set in an organization,\n\n```javascript\nvar user1 = 'John';\nvar skill1 = 'JavaScript';\nvar experience1 = 15;\n\nvar user2 = 'Kane';\nvar skill2 = 'JavaScript';\nvar experience2 = 5;\n\nfunction myInfoTag(strings, userExp, experienceExp, skillExp) {\n  var str0 = strings[0]; // \"Mr/Ms. \"\n  var str1 = strings[1]; // \" is a/an \"\n  var str2 = strings[2]; // \"in\"\n\n  var expertiseStr;\n  if (experienceExp > 10){\n    expertiseStr = 'expert developer';\n  } else if(skillExp > 5 &amp;&amp; skillExp &lt;= 10) {\n    expertiseStr = 'senior developer';\n  } else {\n    expertiseStr = 'junior developer';\n  }\n\n  return ${str0}${userExp}${str1}${expertiseStr}${str2}${skillExp};\n}\n\nvar output1 = myInfoTag`Mr/Ms. ${ user1 } is a/an ${ experience1 } in ${skill1}`;\nvar output2 = myInfoTag`Mr/Ms. ${ user2 } is a/an ${ experience2 } in ${skill2}`;\n\nconsole.log(output1);// Mr/Ms. John is a/an expert developer in JavaScript\nconsole.log(output2);// Mr/Ms. Kane is a/an junior developer in JavaScript\n```</code></pre></div>\n</li>\n<li>\n<p>What are raw strings</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ES6 provides a raw strings feature using the `String.raw()` method which is used to get the raw string form of template strings. This feature allows you to access the raw strings as they were entered, without processing escape sequences. For example, the usage would be as below,\n\n```javascript\nvar calculationString = String.raw`The sum of numbers is \\n${1 + 2 + 3 + 4}!`;\nconsole.log(calculationString); // The sum of numbers is 10\n```\n\nIf you don't use raw strings, the newline character sequence will be processed by displaying the output in multiple lines\n\n```javascript\nvar calculationString = `The sum of numbers is \\n${1 + 2 + 3 + 4}!`;\nconsole.log(calculationString);\n// The sum of numbers is\n// 10\n```\n\nAlso, the raw property is available on the first argument to the tag function\n\n```javascript\nfunction tag(strings) {\n    console.log(strings.raw[0]);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The destructuring assignment is a JavaScript expression that makes it possible to unpack values from arrays or properties from objects into distinct variables.\nLet's get the month values from an array using destructuring assignment\n\n```javascript\nvar [one, two, three] = ['JAN', 'FEB', 'MARCH'];\n\nconsole.log(one); // \"JAN\"\nconsole.log(two); // \"FEB\"\nconsole.log(three); // \"MARCH\"\n```\n\nand you can get user properties of an object using destructuring assignment,\n\n```javascript\nvar { name, age } = { name: 'John', age: 32 };\n\nconsole.log(name); // John\nconsole.log(age); // 32\n```</code></pre></div>\n</li>\n<li>\n<p>What are default values in destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A variable can be assigned a default value when the value unpacked from the array or object is undefined during destructuring assignment. It helps to avoid setting default values separately for each assignment. Let's take an example for both arrays and object use cases,\n\n**Arrays destructuring:**\n\n```javascript\nvar x, y, z;\n\n[x = 2, y = 4, z = 6] = [10];\nconsole.log(x); // 10\nconsole.log(y); // 4\nconsole.log(z); // 6\n```\n\n**Objects destructuring:**\n\n```javascript\nvar { x = 2, y = 4, z = 6 } = { x: 10 };\n\nconsole.log(x); // 10\nconsole.log(y); // 4\nconsole.log(z); // 6\n```</code></pre></div>\n</li>\n<li>\n<p>How do you swap variables in destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you don't use destructuring assignment, swapping two values requires a temporary variable. Whereas using a destructuring feature, two variable values can be swapped in one destructuring expression. Let's swap two number variables in array destructuring assignment,\n\n```javascript\nvar x = 10,\n    y = 20;\n\n[x, y] = [y, x];\nconsole.log(x); // 20\nconsole.log(y); // 10\n```</code></pre></div>\n</li>\n<li>\n<p>What are enhanced object literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object literals make it easy to quickly create objects with properties inside the curly braces. For example, it provides shorter syntax for common object property definition as below.\n\n```javascript\n//ES6\nvar x = 10,\n    y = 20;\nobj = { x, y };\nconsole.log(obj); // {x: 10, y:20}\n//ES5\nvar x = 10,\n    y = 20;\nobj = { x: x, y: y };\nconsole.log(obj); // {x: 10, y:20}\n```</code></pre></div>\n</li>\n<li>\n<p>What are dynamic imports</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The dynamic imports using `import()` function syntax allows us to load modules on demand by using promises or the async/await syntax. Currently this feature is in [stage4 proposal](https://github.com/tc39/proposal-dynamic-import). The main advantage of dynamic imports is reduction of our bundle's sizes, the size/payload response of our requests and overall improvements in the user experience.\nThe syntax of dynamic imports would be as below,\n\n```javascript\nimport('./Module').then((Module) => Module.method());\n```</code></pre></div>\n</li>\n<li>\n<p>What are the use cases for dynamic imports</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are some of the use cases of using dynamic imports over static imports,\n\n1. Import a module on-demand or conditionally. For example, if you want to load a polyfill on legacy browser\n\n```javascript\nif (isLegacyBrowser()) {\n    import(···)\n    .then(···);\n}\n```\n\n1. Compute the module specifier at runtime. For example, you can use it for internationalization.\n\n```javascript\nimport(`messages_${getLocale()}.js`).then(···);\n```\n\n1. Import a module from within a regular script instead a module.</code></pre></div>\n</li>\n<li>\n<p>What are typed arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Typed arrays are array-like objects from ECMAScript 6 API for handling binary data. JavaScript provides 8 Typed array types,\n\n1. Int8Array: An array of 8-bit signed integers\n2. Int16Array: An array of 16-bit signed integers\n3. Int32Array: An array of 32-bit signed integers\n4. Uint8Array: An array of 8-bit unsigned integers\n5. Uint16Array: An array of 16-bit unsigned integers\n6. Uint32Array: An array of 32-bit unsigned integers\n7. Float32Array: An array of 32-bit floating point numbers\n8. Float64Array: An array of 64-bit floating point numbers\n\nFor example, you can create an array of 8-bit signed integers as below\n\n```javascript\nconst a = new Int8Array();\n// You can pre-allocate n bytes\nconst bytes = 1024;\nconst a = new Int8Array(bytes);\n```</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of module loaders</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The module loaders provides the below features,\n\n1. Dynamic loading\n2. State isolation\n3. Global namespace isolation\n4. Compilation hooks\n5. Nested virtualization</code></pre></div>\n</li>\n<li>\n<p>What is collation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Collation is used for sorting a set of strings and searching within a set of strings. It is parameterized by locale and aware of Unicode. Let's take comparison and sorting features,\n\n1. **Comparison:**\n\n```javascript\nvar list = ['ä', 'a', 'z']; // In German,  \"ä\" sorts with \"a\" Whereas in Swedish, \"ä\" sorts after \"z\"\nvar l10nDE = new Intl.Collator('de');\nvar l10nSV = new Intl.Collator('sv');\nconsole.log(l10nDE.compare('ä', 'z') === -1); // true\nconsole.log(l10nSV.compare('ä', 'z') === +1); // true\n```\n\n1. **Sorting:**\n\n```javascript\nvar list = ['ä', 'a', 'z']; // In German,  \"ä\" sorts with \"a\" Whereas in Swedish, \"ä\" sorts after \"z\"\nvar l10nDE = new Intl.Collator('de');\nvar l10nSV = new Intl.Collator('sv');\nconsole.log(list.sort(l10nDE.compare)); // [ \"a\", \"ä\", \"z\" ]\nconsole.log(list.sort(l10nSV.compare)); // [ \"a\", \"z\", \"ä\" ]\n```</code></pre></div>\n</li>\n<li>\n<p>What is for...of statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The for...of statement creates a loop iterating over iterable objects or elements such as built-in String, Array, Array-like objects (like arguments or NodeList), TypedArray, Map, Set, and user-defined iterables. The basic usage of for...of statement on arrays would be as below,\n\n```javascript\nlet arrayIterable = [10, 20, 30, 40, 50];\n\nfor (let value of arrayIterable) {\n    value++;\n    console.log(value); // 11 21 31 41 51\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below spread operator array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">```javascript\n[...'John Resig'];\n```\n\nThe output of the array is ['J', 'o', 'h', 'n', '', 'R', 'e', 's', 'i', 'g']\n**Explanation:** The string is an iterable type and the spread operator within an array maps every character of an iterable to one element. Hence, each character of a string becomes an element within an Array.</code></pre></div>\n</li>\n<li>\n<p>Is PostMessage secure</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, postMessages can be considered very secure as long as the programmer/developer is careful about checking the origin and source of an arriving message. But if you try to send/receive a message without verifying its source will create cross-site scripting attacks.</code></pre></div>\n</li>\n<li>\n<p>What are the problems with postmessage target origin as wildcard</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The second argument of postMessage method specifies which origin is allowed to receive the message. If you use the wildcard \"\\*\" as an argument then any origin is allowed to receive the message. In this case, there is no way for the sender window to know if the target window is at the target origin when sending the message. If the target window has been navigated to another origin, the other origin would receive the data. Hence, this may lead to XSS vulnerabilities.\n\n```javascript\ntargetWindow.postMessage(message, '*');\n```</code></pre></div>\n</li>\n<li>\n<p>How do you avoid receiving postMessages from attackers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Since the listener listens for any message, an attacker can trick the application by sending a message from the attacker's origin, which gives an impression that the receiver received the message from the actual sender's window. You can avoid this issue by validating the origin of the message on the receiver's end using the \"message.origin\" attribute. For examples, let's check the sender's origin [http://www.some-sender.com](https://www.some-sender.com) on receiver side [www.some-receiver.com](www.some-receiver.com),\n\n```javascript\n//Listener on http://www.some-receiver.com/\nwindow.addEventListener(\"message\", function(message){\n    if(/^http://www\\.some-sender\\.com$/.test(message.origin)){\n         console.log('You received the data from valid sender', message.data);\n   }\n});\n```</code></pre></div>\n</li>\n<li>\n<p>Can I avoid using postMessages completely</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You cannot avoid using postMessages completely(or 100%). Even though your application doesn't use postMessage considering the risks, a lot of third party scripts use postMessage to communicate with the third party service. So your application might be using postMessage without your knowledge.</code></pre></div>\n</li>\n<li>\n<p>Is postMessages synchronous</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The postMessages are synchronous in IE8 browser but they are asynchronous in IE9 and all other modern browsers (i.e, IE9+, Firefox, Chrome, Safari).Due to this asynchronous behaviour, we use a callback mechanism when the postMessage is returned.</code></pre></div>\n</li>\n<li>\n<p>What paradigm is Javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a multi-paradigm language, supporting imperative/procedural programming, Object-Oriented Programming and functional programming. JavaScript supports Object-Oriented Programming with prototypical inheritance.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between internal and external javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**Internal JavaScript:** It is the source code within the script tag.\n**External JavaScript:** The source code is stored in an external file(stored with .js extension) and referred with in the tag.</code></pre></div>\n</li>\n<li>\n<p>Is JavaScript faster than server side script</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, JavaScript is faster than server side script. Because JavaScript is a client-side script it does not require any web server's help for its computation or calculation. So JavaScript is always faster than any server-side script like ASP, PHP, etc.</code></pre></div>\n</li>\n<li>\n<p>How do you get the status of a checkbox</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can apply the `checked` property on the selected checkbox in the DOM. If the value is `True` means the checkbox is checked otherwise it is unchecked. For example, the below HTML checkbox element can be access using javascript as below,\n\n```html\n&lt;input type=\"checkbox\" name=\"checkboxname\" value=\"Agree\" /> Agree the conditions&lt;br />\n```\n\n```javascript\nconsole.log(document.getElementById('checkboxname').checked); // true or false\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of double tilde operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The double tilde operator(~~) is known as double NOT bitwise operator. This operator is going to be a quicker substitute for Math.floor().</code></pre></div>\n</li>\n<li>\n<p>How do you convert character to ASCII code</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `String.prototype.charCodeAt()` method to convert string characters to ASCII numbers. For example, let's find ASCII code for the first letter of 'ABC' string,\n\n```javascript\n'ABC'.charCodeAt(0); // returns 65\n```\n\nWhereas `String.fromCharCode()` method converts numbers to equal ASCII characters.\n\n```javascript\nString.fromCharCode(65, 66, 67); // returns 'ABC'\n```</code></pre></div>\n</li>\n<li>\n<p>What is ArrayBuffer</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You can create it as below,\n\n```javascript\nlet buffer = new ArrayBuffer(16); // create a buffer of length 16\nalert(buffer.byteLength); // 16\n```\n\nTo manipulate an ArrayBuffer, we need to use a \"view\" object.\n\n```javascript\n//Create a DataView referring to the buffer\nlet view = new DataView(buffer);\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below string expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">```javascript\nconsole.log('Welcome to JS world'[0]);\n```\n\nThe output of the above expression is \"W\".\n**Explanation:** The bracket notation with specific index on a string returns the character at a specific location. Hence, it returns the character \"W\" of the string. Since this is not supported in IE7 and below versions, you may need to use the .charAt() method to get the desired result.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of Error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Error constructor creates an error object and the instances of error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. The syntax of error object would be as below,\n\n```javascript\nnew Error([message[, fileName[, lineNumber]]])\n```\n\nYou can throw user defined exceptions or errors using Error object in try...catch block as below,\n\n```javascript\ntry {\n    if (withdraw > balance) throw new Error(\"Oops! You don't have enough balance\");\n} catch (e) {\n    console.log(e.name + ': ' + e.message);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of EvalError object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The EvalError object indicates an error regarding the global `eval()` function. Even though this exception is not thrown by JavaScript anymore, the EvalError object remains for compatibility. The syntax of this expression would be as below,\n\n```javascript\nnew EvalError([message[, fileName[, lineNumber]]])\n```\n\nYou can throw EvalError with in try...catch block as below,\n\n```javascript\ntry {\n  throw new EvalError('Eval function error', 'someFile.js', 100);\n} catch (e) {\n  console.log(e.message, e.name, e.fileName);              // \"Eval function error\", \"EvalError\", \"someFile.js\"\n```</code></pre></div>\n</li>\n<li>\n<p>What are the list of cases error thrown from non-strict mode to strict mode</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">When you apply 'use strict'; syntax, some of the below cases will throw a SyntaxError before executing the script\n\n1. When you use Octal syntax\n\n```javascript\nvar n = 022;\n```\n\n1. Using `with` statement\n2. When you use delete operator on a variable name\n3. Using eval or arguments as variable or function argument name\n4. When you use newly reserved keywords\n5. When you declare a function in a block\n\n```javascript\nif (someCondition) {\n    function f() {}\n}\n```\n\nHence, the errors from above cases are helpful to avoid errors in development/production environments.</code></pre></div>\n</li>\n<li>\n<p>Do all objects have prototypes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No. All objects have prototypes except for the base object which is created by the user, or an object that is created using the new keyword.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between a parameter and an argument</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Parameter is the variable name of a function definition whereas an argument represents the value given to a function when it is invoked. Let's explain this with a simple function\n\n```javascript\nfunction myFunction(parameter1, parameter2, parameter3) {\n    console.log(arguments[0]); // \"argument1\"\n    console.log(arguments[1]); // \"argument2\"\n    console.log(arguments[2]); // \"argument3\"\n}\nmyFunction('argument1', 'argument2', 'argument3');\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of some method in arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The some() method is used to test whether at least one element in the array passes the test implemented by the provided function. The method returns a boolean value. Let's take an example to test for any odd elements,\n\n```javascript\nvar array = [1, 2, 3, 4, 5, 6 ,7, 8, 9, 10];\n\nvar odd = element ==> element % 2 !== 0;\n\nconsole.log(array.some(odd)); // true (the odd element exists)\n```</code></pre></div>\n</li>\n<li>\n<p>How do you combine two or more arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The concat() method is used to join two or more arrays by returning a new array containing all the elements. The syntax would be as below,\n\n```javascript\narray1.concat(array2, array3, ..., arrayX)\n```\n\nLet's take an example of array's concatenation with veggies and fruits arrays,\n\n```javascript\nvar veggies = ['Tomato', 'Carrot', 'Cabbage'];\nvar fruits = ['Apple', 'Orange', 'Pears'];\nvar veggiesAndFruits = veggies.concat(fruits);\nconsole.log(veggiesAndFruits); // Tomato, Carrot, Cabbage, Apple, Orange, Pears\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between Shallow and Deep copy</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are two ways to copy an object,\n\n**Shallow Copy:**\nShallow copy is a bitwise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied.\n\n**Example**\n\n```javascript\nvar empDetails = {\n    name: 'John',\n    age: 25,\n    expertise: 'Software Developer'\n};\n```\n\nto create a duplicate\n\n```javascript\nvar empDetailsShallowCopy = empDetails; //Shallow copying!\n```\n\nif we change some property value in the duplicate one like this:\n\n```javascript\nempDetailsShallowCopy.name = 'Johnson';\n```\n\nThe above statement will also change the name of `empDetails`, since we have a shallow copy. That means we're losing the original data as well.\n\n**Deep copy:**\nA deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.\n\n**Example**\n\n```javascript\nvar empDetails = {\n    name: 'John',\n    age: 25,\n    expertise: 'Software Developer'\n};\n```\n\nCreate a deep copy by using the properties from the original object into new variable\n\n```javascript\nvar empDetailsDeepCopy = {\n    name: empDetails.name,\n    age: empDetails.age,\n    expertise: empDetails.expertise\n};\n```\n\nNow if you change `empDetailsDeepCopy.name`, it will only affect `empDetailsDeepCopy` &amp; not `empDetails`</code></pre></div>\n</li>\n<li>\n<p>How do you create specific number of copies of a string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `repeat()` method is used to construct and return a new string which contains the specified number of copies of the string on which it was called, concatenated together. Remember that this method has been added to the ECMAScript 2015 specification.\nLet's take an example of Hello string to repeat it 4 times,\n\n```javascript\n'Hello'.repeat(4); // 'HelloHelloHelloHello'\n```</code></pre></div>\n</li>\n<li>\n<p>How do you return all matching strings against a regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `matchAll()` method can be used to return an iterator of all results matching a string against a regular expression. For example, the below example returns an array of matching string results against a regular expression,\n\n```javascript\nlet regexp = /Hello(\\d?))/g;\nlet greeting = 'Hello1Hello2Hello3';\n\nlet greetingList = [...greeting.matchAll(regexp)];\n\nconsole.log(greetingList[0]); //Hello1\nconsole.log(greetingList[1]); //Hello2\nconsole.log(greetingList[2]); //Hello3\n```</code></pre></div>\n</li>\n<li>\n<p>How do you trim a string at the beginning or ending</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `trim` method of string prototype is used to trim on both sides of a string. But if you want to trim especially at the beginning or ending of the string then you can use `trimStart/trimLeft` and `trimEnd/trimRight` methods. Let's see an example of these methods on a greeting message,\n\n```javascript\nvar greeting = '   Hello, Goodmorning!   ';\n\nconsole.log(greeting); // \"   Hello, Goodmorning!   \"\nconsole.log(greeting.trimStart()); // \"Hello, Goodmorning!   \"\nconsole.log(greeting.trimLeft()); // \"Hello, Goodmorning!   \"\n\nconsole.log(greeting.trimEnd()); // \"   Hello, Goodmorning!\"\nconsole.log(greeting.trimRight()); // \"   Hello, Goodmorning!\"\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below console statement with unary operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Let's take console statement with unary operator as given below,\n\n```javascript\nconsole.log(+'Hello');\n```\n\nThe output of the above console log statement returns NaN. Because the element is prefixed by the unary operator and the JavaScript interpreter will try to convert that element into a number type. Since the conversion fails, the value of the statement results in NaN value.</code></pre></div>\n</li>\n<li>Does javascript uses mixins</li>\n<li>\n<p>What is a thunk function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A thunk is just a function which delays the evaluation of the value. It doesn't take any arguments but gives the value whenever you invoke the thunk. i.e, It is used not to execute now but it will be sometime in the future. Let's take a synchronous example,\n\n```javascript\nconst add = (x, y) => x + y;\n\nconst thunk = () => add(2, 3);\n\nthunk(); // 5\n```</code></pre></div>\n</li>\n<li>\n<p>What are asynchronous thunks</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The asynchronous thunks are useful to make network requests. Let's see an example of network requests,\n\n```javascript\nfunction fetchData(fn) {\n    fetch('https://jsonplaceholder.typicode.com/todos/1')\n        .then((response) => response.json())\n        .then((json) => fn(json));\n}\n\nconst asyncThunk = function () {\n    return fetchData(function getData(data) {\n        console.log(data);\n    });\n};\n\nasyncThunk();\n```\n\nThe `getData` function won't be called immediately but it will be invoked only when the data is available from API endpoint. The setTimeout function is also used to make our code asynchronous. The best real time example is redux state management library which uses the asynchronous thunks to delay the actions to dispatch.</code></pre></div>\n</li>\n<li>\n<p>What is the output of below function calls</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**Code snippet:**\n\n```javascript\nconst circle = {\n    radius: 20,\n    diameter() {\n        return this.radius * 2;\n    },\n    perimeter: () => 2 * Math.PI * this.radius\n};\n```\n\nconsole.log(circle.diameter());\nconsole.log(circle.perimeter());\n\n**Output:**\n\nThe output is 40 and NaN. Remember that diameter is a regular function, whereas the value of perimeter is an arrow function. The `this` keyword of a regular function(i.e, diameter) refers to the surrounding scope which is a class(i.e, Shape object). Whereas this keyword of perimeter function refers to the surrounding scope which is a window object. Since there is no radius property on window objects it returns an undefined value and the multiple of number value returns NaN value.</code></pre></div>\n</li>\n<li>\n<p>How to remove all line breaks from a string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The easiest approach is using regular expressions to detect and replace newlines in the string. In this case, we use replace function along with string to replace with, which in our case is an empty string.\n\n```javascript\nfunction remove_linebreaks( var message ) {\n    return message.replace( /[\\r\\n]+/gm, \"\" );\n}\n```\n\nIn the above expression, g and m are for global and multiline flags.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between reflow and repaint</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A _repaint_ occurs when changes are made which affect the visibility of an element, but not its layout. Examples of this include outline, visibility, or background color. A _reflow_ involves changes that affect the layout of a portion of the page (or the whole page). Resizing the browser window, changing the font, content changing (such as user typing text), using JavaScript methods involving computed styles, adding or removing elements from the DOM, and changing an element's classes are a few of the things that can trigger reflow. Reflow of an element causes the subsequent reflow of all child and ancestor elements as well as any elements following it in the DOM.</code></pre></div>\n</li>\n<li>\n<p>What happens with negating an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Negating an array with `!` character will coerce the array into a boolean. Since Arrays are considered to be truthy So negating it will return `false`.\n\n```javascript\nconsole.log(![]); // false\n```</code></pre></div>\n</li>\n<li>\n<p>What happens if we add two arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you add two arrays together, it will convert them both to strings and concatenate them. For example, the result of adding arrays would be as below,\n\n```javascript\nconsole.log(['a'] + ['b']); // \"ab\"\nconsole.log([] + []); // \"\"\nconsole.log(![] + []); // \"false\", because ![] returns false.\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of prepend additive operator on falsy values</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you prepend the additive(+) operator on falsy values(null, undefined, NaN, false, \"\"), the falsy value converts to a number value zero. Let's display them on browser console as below,\n\n```javascript\nconsole.log(+null); // 0\nconsole.log(+undefined); // NaN\nconsole.log(+false); // 0\nconsole.log(+NaN); // NaN\nconsole.log(+''); // 0\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create self string using special characters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The self string can be formed with the combination of `[]()!+` characters. You need to remember the below conventions to achieve this pattern.\n\n1. Since Arrays are truthful values, negating the arrays will produce false: ![] === false\n2. As per JavaScript coercion rules, the addition of arrays together will toString them: [] + [] === \"\"\n3. Prepend an array with + operator will convert an array to false, the negation will make it true and finally converting the result will produce value '1': +(!(+[])) === 1\n\nBy applying the above rules, we can derive below conditions\n\n```javascript\n(![] + [] === 'false' + !+[]) === 1;\n```\n\nNow the character pattern would be created as below,\n\n```javascript\n      s               e               l               f\n ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^\n\n (![] + [])[3] + (![] + [])[4] + (![] + [])[2] + (![] + [])[0]\n ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^\n(![] + [])[+!+[]+!+[]+!+[]] +\n(![] + [])[+!+[]+!+[]+!+[]+!+[]] +\n(![] + [])[+!+[]+!+[]] +\n(![] + [])[+[]]\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n(![]+[])[+!+[]+!+[]+!+[]]+(![]+[])[+!+[]+!+[]+!+[]+!+[]]+(![]+[])[+!+[]+!+[]]+(![]+[])[+[]]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you remove falsy values from an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can apply the filter method on the array by passing Boolean as a parameter. This way it removes all falsy values(0, undefined, null, false and \"\") from the array.\n\n```javascript\nconst myArray = [false, null, 1, 5, undefined];\nmyArray.filter(Boolean); // [1, 5] // is same as myArray.filter(x => x);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get unique values of an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can get unique values of an array with the combination of `Set` and rest expression/spread(...) syntax.\n\n```javascript\nconsole.log([...new Set([1, 2, 4, 4, 3])]); // [1, 2, 4, 3]\n```</code></pre></div>\n</li>\n<li>\n<p>What is destructuring aliases</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Sometimes you would like to have a destructured variable with a different name than the property name. In that case, you'll use a `: newName` to specify a name for the variable. This process is called destructuring aliases.\n\n```javascript\nconst obj = { x: 1 };\n// Grabs obj.x as as { otherName }\nconst { x: otherName } = obj;\n```</code></pre></div>\n</li>\n<li>\n<p>How do you map the array values without using map method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can map the array values without using the `map` method by just using the `from` method of Array. Let's map city names from Countries array,\n\n```javascript\nconst countries = [\n    { name: 'India', capital: 'Delhi' },\n    { name: 'US', capital: 'Washington' },\n    { name: 'Russia', capital: 'Moscow' },\n    { name: 'Singapore', capital: 'Singapore' },\n    { name: 'China', capital: 'Beijing' },\n    { name: 'France', capital: 'Paris' }\n];\n\nconst cityNames = Array.from(countries, ({ capital }) => capital);\nconsole.log(cityNames); // ['Delhi, 'Washington', 'Moscow', 'Singapore', 'Beijing', 'Paris']\n```</code></pre></div>\n</li>\n<li>\n<p>How do you empty an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can empty an array quickly by setting the array length to zero.\n\n```javascript\nlet cities = ['Singapore', 'Delhi', 'London'];\ncities.length = 0; // cities becomes []\n```</code></pre></div>\n</li>\n<li>\n<p>How do you rounding numbers to certain decimals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can round numbers to a certain number of decimals using `toFixed` method from native javascript.\n\n```javascript\nlet pie = 3.141592653;\npie = pie.toFixed(3); // 3.142\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to convert an array to an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can convert an array to an object with the same data using spread(...) operator.\n\n```javascript\nvar fruits = ['banana', 'apple', 'orange', 'watermelon'];\nvar fruitsObject = { ...fruits };\nconsole.log(fruitsObject); // {0: \"banana\", 1: \"apple\", 2: \"orange\", 3: \"watermelon\"}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create an array with some data</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can create an array with some data or an array with the same values using `fill` method.\n\n```javascript\nvar newArray = new Array(5).fill('0');\nconsole.log(newArray); // [\"0\", \"0\", \"0\", \"0\", \"0\"]\n```</code></pre></div>\n</li>\n<li>\n<p>What are the placeholders from console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of placeholders available from console object,\n\n1. %o — It takes an object,\n2. %s — It takes a string,\n3. %d — It is used for a decimal or integer\n   These placeholders can be represented in the console.log as below\n\n```javascript\nconst user = { name: 'John', id: 1, city: 'Delhi' };\nconsole.log('Hello %s, your details %o are available in the object form', 'John', user); // Hello John, your details {name: \"John\", id: 1, city: \"Delhi\"} are available in object\n```</code></pre></div>\n</li>\n<li>\n<p>Is it possible to add CSS to console messages</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, you can apply CSS styles to console messages similar to html text on the web page.\n\n```javascript\nconsole.log('%c The text has blue color, with large font and red background', 'color: blue; font-size: x-large; background: red');\n```\n\nThe text will be displayed as below,\n![Screenshot](images/console-css.png)\n\n**Note:** All CSS styles can be applied to console messages.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of dir method of console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `console.dir()` is used to display an interactive list of the properties of the specified JavaScript object as JSON.\n\n```javascript\nconst user = { name: 'John', id: 1, city: 'Delhi' };\nconsole.dir(user);\n```\n\nThe user object displayed in JSON representation\n![Screenshot](images/console-dir.png)</code></pre></div>\n</li>\n<li>\n<p>Is it possible to debug HTML elements in console</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, it is possible to get and debug HTML elements in the console just like inspecting elements.\n\n```javascript\nconst element = document.getElementsByTagName('body')[0];\nconsole.log(element);\n```\n\nIt prints the HTML element in the console,\n\n![Screenshot](images/console-html.png)</code></pre></div>\n</li>\n<li>\n<p>How do you display data in a tabular format using console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `console.table()` is used to display data in the console in a tabular format to visualize complex arrays or objects.\n\n     ```js\n\n//\nconst users = [\n{ name: 'John', id: 1, city: 'Delhi' },\n{ name: 'Max', id: 2, city: 'London' },\n{ name: 'Rod', id: 3, city: 'Paris' }\n];\nconsole.table(users);\n\n```\n\n     The data visualized in a table format,\n\n     ![Screenshot](images/console-table.png)\n     **Not:** Remember that `console.table()` is not supported in IE.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you verify that an argument is a Number or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The combination of IsNaN and isFinite methods are used to confirm whether an argument is a number or not.\n\n```javascript\nfunction isNumber(n) {\n    return !isNaN(parseFloat(n)) &amp;&amp; isFinite(n);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create copy to clipboard button</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to select the content(using .select() method) of the input element and execute the copy command with execCommand (i.e, execCommand('copy')). You can also execute other system commands like cut and paste.\n\n```javascript\ndocument.querySelector('#copy-button').onclick = function () {\n    // Select the content\n    document.querySelector('#copy-input').select();\n    // Copy to the clipboard\n    document.execCommand('copy');\n};\n```</code></pre></div>\n</li>\n<li>\n<p>What is the shortcut to get timestamp</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `new Date().getTime()` to get the current timestamp. There is an alternative shortcut to get the value.\n\n```javascript\nconsole.log(+new Date());\nconsole.log(Date.now());\n```</code></pre></div>\n</li>\n<li>\n<p>How do you flattening multi dimensional arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Flattening bi-dimensional arrays is trivial with Spread operator.\n\n```javascript\nconst biDimensionalArr = [11, [22, 33], [44, 55], [66, 77], 88, 99];\nconst flattenArr = [].concat(...biDimensionalArr); // [11, 22, 33, 44, 55, 66, 77, 88, 99]\n```\n\nBut you can make it work with multi-dimensional arrays by recursive calls,\n\n```javascript\nfunction flattenMultiArray(arr) {\n    const flattened = [].concat(...arr);\n    return flattened.some((item) => Array.isArray(item)) ? flattenMultiArray(flattened) : flattened;\n}\nconst multiDimensionalArr = [11, [22, 33], [44, [55, 66, [77, [88]], 99]]];\nconst flatArr = flattenMultiArray(multiDimensionalArr); // [11, 22, 33, 44, 55, 66, 77, 88, 99]\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest multi condition checking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `indexOf` to compare input with multiple values instead of checking each value as one condition.\n\n```javascript\n// Verbose approach\nif (input === 'first' || input === 1 || input === 'second' || input === 2) {\n    someFunction();\n}\n// Shortcut\nif (['first', 1, 'second', 2].indexOf(input) !== -1) {\n    someFunction();\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you capture browser back button</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `window.onbeforeunload` method is used to capture browser back button events. This is helpful to warn users about losing the current data.\n\n```javascript\nwindow.onbeforeunload = function () {\n    alert('You work will be lost');\n};\n```</code></pre></div>\n</li>\n<li>\n<p>How do you disable right click in the web page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The right click on the page can be disabled by returning false from the `oncontextmenu` attribute on the body element.\n\n```html\n&lt;body oncontextmenu=\"return false;\">&lt;/body>\n```</code></pre></div>\n</li>\n<li>\n<p>What are wrapper objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Primitive Values like string,number and boolean don't have properties and methods but they are temporarily converted or coerced to an object(Wrapper object) when you try to perform actions on them. For example, if you apply toUpperCase() method on a primitive string value, it does not throw an error but returns uppercase of the string.\n\n```javascript\nlet name = 'john';\n\nconsole.log(name.toUpperCase()); // Behind the scenes treated as console.log(new String(name).toUpperCase());\n```\n\ni.e, Every primitive except null and undefined have Wrapper Objects and the list of wrapper objects are String,Number,Boolean,Symbol and BigInt.</code></pre></div>\n</li>\n<li>\n<p>What is AJAX</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">AJAX stands for Asynchronous JavaScript and XML and it is a group of related technologies(HTML, CSS, JavaScript, XMLHttpRequest API etc) used to display data asynchronously. i.e. We can send data to the server and get data from the server without reloading the web page.</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to deal with Asynchronous Code</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of different ways to deal with Asynchronous code.\n\n1. Callbacks\n2. Promises\n3. Async/await\n4. Third-party libraries such as async.js,bluebird etc</code></pre></div>\n</li>\n<li>\n<p>How to cancel a fetch request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Until a few days back, One shortcoming of native promises is no direct way to cancel a fetch request. But the new `AbortController` from js specification allows you to use a signal to abort one or multiple fetch calls.\nThe basic flow of cancelling a fetch request would be as below,\n\n1. Create an `AbortController` instance\n2. Get the signal property of an instance and pass the signal as a fetch option for signal\n3. Call the AbortController's abort property to cancel all fetches that use that signal\n   For example, let's pass the same signal to multiple fetch calls will cancel all requests with that signal,\n\n```javascript\nconst controller = new AbortController();\nconst { signal } = controller;\n\nfetch('http://localhost:8000', { signal })\n    .then((response) => {\n        console.log(`Request 1 is complete!`);\n    })\n    .catch((e) => {\n        if (e.name === 'AbortError') {\n            // We know it's been canceled!\n        }\n    });\n\nfetch('http://localhost:8000', { signal })\n    .then((response) => {\n        console.log(`Request 2 is complete!`);\n    })\n    .catch((e) => {\n        if (e.name === 'AbortError') {\n            // We know it's been canceled!\n        }\n    });\n\n// Wait 2 seconds to abort both requests\nsetTimeout(() => controller.abort(), 2000);\n```</code></pre></div>\n</li>\n<li>\n<p>What is web speech API</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Web speech API is used to enable modern browsers recognize and synthesize speech(i.e, voice data into web apps). This API has been introduced by W3C Community in the year 2012. It has two main parts,\n\n1. **SpeechRecognition (Asynchronous Speech Recognition or Speech-to-Text):** It provides the ability to recognize voice context from an audio input and respond accordingly. This is accessed by the `SpeechRecognition` interface.\n   The below example shows on how to use this API to get text from speech,\n\n```javascript\nwindow.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition; // webkitSpeechRecognition for Chrome and SpeechRecognition for FF\nconst recognition = new window.SpeechRecognition();\nrecognition.onresult = (event) => {\n    // SpeechRecognitionEvent type\n    const speechToText = event.results[0][0].transcript;\n    console.log(speechToText);\n};\nrecognition.start();\n```\n\nIn this API, browser is going to ask you for permission to use your microphone\n\n1. **SpeechSynthesis (Text-to-Speech):** It provides the ability to recognize voice context from an audio input and respond. This is accessed by the `SpeechSynthesis` interface.\n   For example, the below code is used to get voice/speech from text,\n\n```javascript\nif ('speechSynthesis' in window) {\n    var speech = new SpeechSynthesisUtterance('Hello World!');\n    speech.lang = 'en-US';\n    window.speechSynthesis.speak(speech);\n}\n```\n\nThe above examples can be tested on chrome(33+) browser's developer console.\n**Note:** This API is still a working draft and only available in Chrome and Firefox browsers(ofcourse Chrome only implemented the specification)</code></pre></div>\n</li>\n<li>\n<p>What is minimum timeout throttling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both browser and NodeJS javascript environments throttles with a minimum delay that is greater than 0ms. That means even though setting a delay of 0ms will not happen instantaneously.\n**Browsers:** They have a minimum delay of 4ms. This throttle occurs when successive calls are triggered due to callback nesting(certain depth) or after a certain number of successive intervals.\nNote: The older browsers have a minimum delay of 10ms.\n**Nodejs:** They have a minimum delay of 1ms. This throttle happens when the delay is larger than 2147483647 or less than 1.\nThe best example to explain this timeout throttling behavior is the order of below code snippet.\n\n```javascript\nfunction runMeFirst() {\n    console.log('My script is initialized');\n}\nsetTimeout(runMeFirst, 0);\nconsole.log('Script loaded');\n```\n\nand the output would be in\n\n```shell\nScript loaded\nMy script is initialized\n```\n\nIf you don't use `setTimeout`, the order of logs will be sequential.\n\n```javascript\nfunction runMeFirst() {\n    console.log('My script is initialized');\n}\nrunMeFirst();\nconsole.log('Script loaded');\n```\n\nand the output is,\n\n```shell\nMy script is initialized\nScript loaded\n```</code></pre></div>\n</li>\n<li>\n<p>How do you implement zero timeout in modern browsers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can't use setTimeout(fn, 0) to execute the code immediately due to minimum delay of greater than 0ms. But you can use window.postMessage() to achieve this behavior.</code></pre></div>\n</li>\n<li>\n<p>What are tasks in event loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A task is any javascript code/program which is scheduled to be run by the standard mechanisms such as initially starting to run a program, run an event callback, or an interval or timeout being fired. All these tasks are scheduled on a task queue.\nBelow are the list of use cases to add tasks to the task queue,\n\n1. When a new javascript program is executed directly from console or running by the `&lt;script>` element, the task will be added to the task queue.\n2. When an event fires, the event callback added to task queue\n3. When a setTimeout or setInterval is reached, the corresponding callback added to task queue</code></pre></div>\n</li>\n<li>\n<p>What is microtask</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Microtask is the javascript code which needs to be executed immediately after the currently executing task/microtask is completed. They are kind of blocking in nature. i.e, The main thread will be blocked until the microtask queue is empty.\nThe main sources of microtasks are Promise.resolve, Promise.reject, MutationObservers, IntersectionObservers etc\n\n**Note:** All of these microtasks are processed in the same turn of the event loop.</code></pre></div>\n</li>\n<li>What are different event loops</li>\n<li>What is the purpose of queueMicrotask</li>\n<li>\n<p>How do you use javascript libraries in typescript file</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is known that not all JavaScript libraries or frameworks have TypeScript declaration files. But if you still want to use libraries or frameworks in our TypeScript files without getting compilation errors, the only solution is `declare` keyword along with a variable declaration. For example, let's imagine you have a library called `customLibrary` that doesn't have a TypeScript declaration and have a namespace called `customLibrary` in the global namespace. You can use this library in typescript code as below,\n\n```javascript\ndeclare var customLibrary;\n```\n\nIn the runtime, typescript will provide the type to the `customLibrary` variable as `any` type. The another alternative without using declare keyword is below\n\n```javascript\nvar customLibrary: any;\n```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between promises and observables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the major difference in a tabular form\n\n| Promises                                                           | Observables                                                                              |\n| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |\n| Emits only a single value at a time                                | Emits multiple values over a period of time(stream of values ranging from 0 to multiple) |\n| Eager in nature; they are going to be called immediately           | Lazy in nature; they require subscription to be invoked                                  |\n| Promise is always asynchronous even though it resolved immediately | Observable can be either synchronous or asynchronous                                     |\n| Doesn't provide any operators                                      | Provides operators such as map, forEach, filter, reduce, retry, and retryWhen etc        |\n| Cannot be canceled                                                 | Canceled by using unsubscribe() method                                                   |</code></pre></div>\n</li>\n<li>\n<p>What is heap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Heap(Or memory heap) is the memory location where objects are stored when we define variables. i.e, This is the place where all the memory allocations and de-allocation take place. Both heap and call-stack are two containers of JS runtime.\nWhenever runtime comes across variables and function declarations in the code it stores them in the Heap.\n\n![Screenshot](images/heap.png)</code></pre></div>\n</li>\n<li>\n<p>What is an event table</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Event Table is a data structure that stores and keeps track of all the events which will be executed asynchronously like after some time interval or after the resolution of some API requests. i.e Whenever you call a setTimeout function or invoke async operation, it is added to the Event Table.\nIt doesn't not execute functions on it's own. The main purpose of the event table is to keep track of events and send them to the Event Queue as shown in the below diagram.\n\n![Screenshot](images/event-table.png)</code></pre></div>\n</li>\n<li>\n<p>What is a microTask queue</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Microtask Queue is the new queue where all the tasks initiated by promise objects get processed before the callback queue.\nThe microtasks queue are processed before the next rendering and painting jobs. But if these microtasks are running for a long time then it leads to visual degradation.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between shim and polyfill</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A shim is a library that brings a new API to an older environment, using only the means of that environment. It isn't necessarily restricted to a web application. For example, es5-shim.js is used to emulate ES5 features on older browsers (mainly pre IE9).\nWhereas polyfill is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively.\nIn a simple sentence, A polyfill is a shim for a browser API.</code></pre></div>\n</li>\n<li>\n<p>How do you detect primitive or non primitive value type</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In JavaScript, primitive types include boolean, string, number, BigInt, null, Symbol and undefined. Whereas non-primitive types include the Objects. But you can easily identify them with the below function,\n\n```javascript\nvar myPrimitive = 30;\nvar myNonPrimitive = {};\nfunction isPrimitive(val) {\n    return Object(val) !== val;\n}\n\nisPrimitive(myPrimitive);\nisPrimitive(myNonPrimitive);\n```\n\nIf the value is a primitive data type, the Object constructor creates a new wrapper object for the value. But If the value is a non-primitive data type (an object), the Object constructor will give the same object.</code></pre></div>\n</li>\n<li>\n<p>What is babel</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Babel is a JavaScript transpiler to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments. Some of the main features are listed below,\n\n1. Transform syntax\n2. Polyfill features that are missing in your target environment (using @babel/polyfill)\n3. Source code transformations (or codemods)</code></pre></div>\n</li>\n<li>\n<p>Is Node.js completely single threaded</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Node is a single thread, but some of the functions included in the Node.js standard library(e.g, fs module functions) are not single threaded. i.e, Their logic runs outside of the Node.js single thread to improve the speed and performance of a program.</code></pre></div>\n</li>\n<li>\n<p>What are the common use cases of observables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the most common use cases of observables are web sockets with push notifications, user input changes, repeating intervals, etc</code></pre></div>\n</li>\n<li>\n<p>What is RxJS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">RxJS (Reactive Extensions for JavaScript) is a library for implementing reactive programming using observables that makes it easier to compose asynchronous or callback-based code. It also provides utility functions for creating and working with observables.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between Function constructor and function declaration</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The functions which are created with `Function constructor` do not create closures to their creation contexts but they are always created in the global scope. i.e, the function can access its own local variables and global scope variables only. Whereas function declarations can access outer function variables(closures) too.\n\nLet's see this difference with an example,\n\n**Function Constructor:**\n\n```javascript\nvar a = 100;\nfunction createFunction() {\n    var a = 200;\n    return new Function('return a;');\n}\nconsole.log(createFunction()()); // 100\n```\n\n**Function declaration:**\n\n```javascript\nvar a = 100;\nfunction createFunction() {\n    var a = 200;\n    return function func() {\n        return a;\n    };\n}\nconsole.log(createFunction()()); // 200\n```</code></pre></div>\n</li>\n<li>\n<p>What is a Short circuit condition</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Short circuit conditions are meant for condensed way of writing simple if statements. Let's demonstrate the scenario using an example. If you would like to login to a portal with an authentication condition, the expression would be as below,\n\n```javascript\nif (authenticate) {\n    loginToPorta();\n}\n```\n\nSince the javascript logical operators evaluated from left to right, the above expression can be simplified using &amp;&amp; logical operator\n\n```javascript\nauthenticate &amp;&amp; loginToPorta();\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to resize an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The length property of an array is useful to resize or empty an array quickly. Let's apply length property on number array to resize the number of elements from 5 to 2,\n\n```javascript\nvar array = [1, 2, 3, 4, 5];\nconsole.log(array.length); // 5\n\narray.length = 2;\nconsole.log(array.length); // 2\nconsole.log(array); // [1,2]\n```\n\nand the array can be emptied too\n\n```javascript\nvar array = [1, 2, 3, 4, 5];\narray.length = 0;\nconsole.log(array.length); // 0\nconsole.log(array); // []\n```</code></pre></div>\n</li>\n<li>\n<p>What is an observable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An Observable is basically a function that can return a stream of values either synchronously or asynchronously to an observer over time. The consumer can get the value by calling `subscribe()` method.\nLet's look at a simple example of an Observable\n\n```javascript\nimport { Observable } from 'rxjs';\n\nconst observable = new Observable((observer) => {\n    setTimeout(() => {\n        observer.next('Message from a Observable!');\n    }, 3000);\n});\n\nobservable.subscribe((value) => console.log(value));\n```\n\n![Screenshot](images/observables.png)\n\n**Note:** Observables are not part of the JavaScript language yet but they are being proposed to be added to the language</code></pre></div>\n</li>\n<li>\n<p>What is the difference between function and class declarations</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference between function declarations and class declarations is `hoisting`. The function declarations are hoisted but not class declarations.\n\n**Classes:**\n\n```javascript\nconst user = new User(); // ReferenceError\n\nclass User {}\n```\n\n**Constructor Function:**\n\n```javascript\nconst user = new User(); // No error\n\nfunction User() {}\n```</code></pre></div>\n</li>\n<li>\n<p>What is an async function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An async function is a function declared with the `async` keyword which enables asynchronous, promise-based behavior to be written in a cleaner style by avoiding promise chains. These functions can contain zero or more `await` expressions.\n\nLet's take a below async function example,\n\n```javascript\nasync function logger() {\n    let data = await fetch('http://someapi.com/users'); // pause until fetch returns\n    console.log(data);\n}\nlogger();\n```\n\nIt is basically syntax sugar over ES2015 promises and generators.</code></pre></div>\n</li>\n<li>\n<p>How do you prevent promises swallowing errors</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">While using asynchronous code, JavaScript's ES6 promises can make your life a lot easier without having callback pyramids and error handling on every second line. But Promises have some pitfalls and the biggest one is swallowing errors by default.\n\nLet's say you expect to print an error to the console for all the below cases,\n\n```javascript\nPromise.resolve('promised value').then(function () {\n    throw new Error('error');\n});\n\nPromise.reject('error value').catch(function () {\n    throw new Error('error');\n});\n\nnew Promise(function (resolve, reject) {\n    throw new Error('error');\n});\n```\n\nBut there are many modern JavaScript environments that won't print any errors. You can fix this problem in different ways,\n\n1. **Add catch block at the end of each chain:** You can add catch block to the end of each of your promise chains\n\n    ```javascript\n    Promise.resolve('promised value')\n        .then(function () {\n            throw new Error('error');\n        })\n        .catch(function (error) {\n            console.error(error.stack);\n        });\n    ```\n\n    But it is quite difficult to type for each promise chain and verbose too.\n\n2. **Add done method:** You can replace first solution's then and catch blocks with done method\n\n    ```javascript\n    Promise.resolve('promised value').done(function () {\n        throw new Error('error');\n    });\n    ```\n\n    Let's say you want to fetch data using HTTP and later perform processing on the resulting data asynchronously. You can write `done` block as below,\n\n    ```javascript\n    getDataFromHttp()\n        .then(function (result) {\n            return processDataAsync(result);\n        })\n        .done(function (processed) {\n            displayData(processed);\n        });\n    ```\n\n    In future, if the processing library API changed to synchronous then you can remove `done` block as below,\n\n    ```javascript\n    getDataFromHttp().then(function (result) {\n        return displayData(processDataAsync(result));\n    });\n    ```\n\n    and then you forgot to add `done` block to `then` block leads to silent errors.\n\n3. **Extend ES6 Promises by Bluebird:**\n   Bluebird extends the ES6 Promises API to avoid the issue in the second solution. This library has a \"default\" onRejection handler which will print all errors from rejected Promises to stderr. After installation, you can process unhandled rejections\n\n    ```javascript\n    Promise.onPossiblyUnhandledRejection(function (error) {\n        throw error;\n    });\n    ```\n\n    and discard a rejection, just handle it with an empty catch\n\n    ```javascript\n    Promise.reject('error value').catch(function () {});\n    ```</code></pre></div>\n</li>\n<li>\n<p>What is deno</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 JavaScript engine and the Rust programming language.</code></pre></div>\n</li>\n<li>\n<p>How do you make an object iterable in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">By default, plain objects are not iterable. But you can make the object iterable by defining a `Symbol.iterator` property on it.\n\nLet's demonstrate this with an example,\n\n```javascript\nconst collection = {\n    one: 1,\n    two: 2,\n    three: 3,\n    [Symbol.iterator]() {\n        const values = Object.keys(this);\n        let i = 0;\n        return {\n            next: () => {\n                return {\n                    value: this[values[i++]],\n                    done: i > values.length\n                };\n            }\n        };\n    }\n};\n\nconst iterator = collection[Symbol.iterator]();\n\nconsole.log(iterator.next()); // → {value: 1, done: false}\nconsole.log(iterator.next()); // → {value: 2, done: false}\nconsole.log(iterator.next()); // → {value: 3, done: false}\nconsole.log(iterator.next()); // → {value: undefined, done: true}\n```\n\nThe above process can be simplified using a generator function,\n\n```javascript\nconst collection = {\n    one: 1,\n    two: 2,\n    three: 3,\n    [Symbol.iterator]: function* () {\n        for (let key in this) {\n            yield this[key];\n        }\n    }\n};\nconst iterator = collection[Symbol.iterator]();\nconsole.log(iterator.next()); // {value: 1, done: false}\nconsole.log(iterator.next()); // {value: 2, done: false}\nconsole.log(iterator.next()); // {value: 3, done: false}\nconsole.log(iterator.next()); // {value: undefined, done: true}\n```</code></pre></div>\n</li>\n<li>\n<p>What is a Proper Tail Call</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">First, we should know about tail call before talking about \"Proper Tail Call\". A tail call is a subroutine or function call performed as the final action of a calling function. Whereas **Proper tail call(PTC)** is a technique where the program or code will not create additional stack frames for a recursion when the function call is a tail call.\n\nFor example, the below classic or head recursion of factorial function relies on stack for each step. Each step need to be processed upto `n * factorial(n - 1)`\n\n```javascript\nfunction factorial(n) {\n    if (n === 0) {\n        return 1;\n    }\n    return n * factorial(n - 1);\n}\nconsole.log(factorial(5)); //120\n```\n\nBut if you use Tail recursion functions, they keep passing all the necessary data it needs down the recursion without relying on the stack.\n\n```javascript\nfunction factorial(n, acc = 1) {\n    if (n === 0) {\n        return acc;\n    }\n    return factorial(n - 1, n * acc);\n}\nconsole.log(factorial(5)); //120\n```\n\nThe above pattern returns the same output as the first one. But the accumulator keeps track of total as an argument without using stack memory on recursive calls.</code></pre></div>\n</li>\n<li>\n<p>How do you check an object is a promise or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you don't know if a value is a promise or not, wrapping the value as `Promise.resolve(value)` which returns a promise\n\n```javascript\nfunction isPromise(object) {\n    if (Promise &amp;&amp; Promise.resolve) {\n        return Promise.resolve(object) == object;\n    } else {\n        throw 'Promise not supported in your environment';\n    }\n}\n\nvar i = 1;\nvar promise = new Promise(function (resolve, reject) {\n    resolve();\n});\n\nconsole.log(isPromise(i)); // false\nconsole.log(isPromise(p)); // true\n```\n\nAnother way is to check for `.then()` handler type\n\n```javascript\nfunction isPromise(value) {\n    return Boolean(value &amp;&amp; typeof value.then === 'function');\n}\nvar i = 1;\nvar promise = new Promise(function (resolve, reject) {\n    resolve();\n});\n\nconsole.log(isPromise(i)); // false\nconsole.log(isPromise(promise)); // true\n```</code></pre></div>\n</li>\n<li>\n<p>How to detect if a function is called as constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `new.target` pseudo-property to detect whether a function was called as a constructor(using the new operator) or as a regular function call.\n\n1. If a constructor or function invoked using the new operator, new.target returns a reference to the constructor or function.\n2. For function calls, new.target is undefined.\n\n```javascript\nfunction Myfunc() {\n   if (new.target) {\n      console.log('called with new');\n   } else {\n      console.log('not called with new');\n   }\n}\n\nnew Myfunc(); // called with new\nMyfunc(); // not called with new\nMyfunc.call({}); not called with new\n```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between arguments object and rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are three main differences between arguments object and rest parameters\n\n1. The arguments object is an array-like but not an array. Whereas the rest parameters are array instances.\n2. The arguments object does not support methods such as sort, map, forEach, or pop. Whereas these methods can be used in rest parameters.\n3. The rest parameters are only the ones that haven't been given a separate name, while the arguments object contains all arguments passed to the function</code></pre></div>\n</li>\n<li>\n<p>What are the differences between spread operator and rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Rest parameter collects all remaining elements into an array. Whereas Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. i.e, Rest parameter is opposite to the spread operator.</code></pre></div>\n</li>\n<li>\n<p>What are the different kinds of generators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are five kinds of generators,\n\n1. **Generator function declaration:**\n\n    ```javascript\n    function* myGenFunc() {\n        yield 1;\n        yield 2;\n        yield 3;\n    }\n    const genObj = myGenFunc();\n    ```\n\n2. **Generator function expressions:**\n\n    ```javascript\n    const myGenFunc = function* () {\n        yield 1;\n        yield 2;\n        yield 3;\n    };\n    const genObj = myGenFunc();\n    ```\n\n3. **Generator method definitions in object literals:**\n\n    ```javascript\n    const myObj = {\n        *myGeneratorMethod() {\n            yield 1;\n            yield 2;\n            yield 3;\n        }\n    };\n    const genObj = myObj.myGeneratorMethod();\n    ```\n\n4. **Generator method definitions in class:**\n\n    ```javascript\n    class MyClass {\n        *myGeneratorMethod() {\n            yield 1;\n            yield 2;\n            yield 3;\n        }\n    }\n    const myObject = new MyClass();\n    const genObj = myObject.myGeneratorMethod();\n    ```\n\n5. **Generator as a computed property:**\n\n    ```javascript\n    const SomeObj = {\n        *[Symbol.iterator]() {\n            yield 1;\n            yield 2;\n            yield 3;\n        }\n    };\n\n    console.log(Array.from(SomeObj)); // [ 1, 2, 3 ]\n    ```</code></pre></div>\n</li>\n<li>\n<p>What are the built-in iterables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of built-in iterables in javascript,\n\n1. Arrays and TypedArrays\n2. Strings: Iterate over each character or Unicode code-points\n3. Maps: iterate over its key-value pairs\n4. Sets: iterates over their elements\n5. arguments: An array-like special variable in functions\n6. DOM collection such as NodeList</code></pre></div>\n</li>\n<li>\n<p>What are the differences between for...of and for...in statements</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both for...in and for...of statements iterate over js data structures. The only difference is over what they iterate:\n\n1. for..in iterates over all enumerable property keys of an object\n2. for..of iterates over the values of an iterable object.\n\nLet's explain this difference with an example,\n\n```javascript\nlet arr = ['a', 'b', 'c'];\n\narr.newProp = 'newVlue';\n\n// key are the property keys\nfor (let key in arr) {\n    console.log(key);\n}\n\n// value are the property values\nfor (let value of arr) {\n    console.log(value);\n}\n```\n\nSince for..in loop iterates over the keys of the object, the first loop logs 0, 1, 2 and newProp while iterating over the array object. The for..of loop iterates over the values of a arr data structure and logs a, b, c in the console.</code></pre></div>\n</li>\n<li>\n<p>How do you define instance and non-instance properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Instance properties must be defined inside of class methods. For example, name and age properties defined insider constructor as below,\n\n```javascript\nclass Person {\n    constructor(name, age) {\n        this.name = name;\n        this.age = age;\n    }\n}\n```\n\nBut Static(class) and prototype data properties must be defined outside of the ClassBody declaration. Let's assign the age value for Person class as below,\n\n```javascript\nPerson.staticAge = 30;\nPerson.prototype.prototypeAge = 40;\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between isNaN and Number.isNaN?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. **isNaN**: The global function `isNaN` converts the argument to a Number and returns true if the resulting value is NaN.\n2. **Number.isNaN**: This method does not convert the argument. But it returns true when the type is a Number and value is NaN.\n\nLet's see the difference with an example,\n\n```javascript\nisNaN('hello'); // true\nNumber.isNaN('hello'); // false\n```</code></pre></div>\n</li>\n<li>\n<p>How to invoke an IIFE without any extra brackets?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Immediately Invoked Function Expressions(IIFE) requires a pair of parenthesis to wrap the function which contains set of statements.\n\n     ```js\n\n//\n(function (dt) {\nconsole.log(dt.toLocaleTimeString());\n})(new Date());\n\n````\n\n     Since both IIFE and void operator discard the result of an expression, you can avoid the extra brackets using `void operator` for IIFE as below,\n\n     ```js\n\n//\nvoid (function (dt) {\nconsole.log(dt.toLocaleTimeString());\n})(new Date());\n````</code></pre></div>\n</li>\n<li>\n<p>Is that possible to use expressions in switch cases?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You might have seen expressions used in switch condition but it is also possible to use for switch cases by assigning true value for the switch condition. Let's see the weather condition based on temparature as an example,\n\n     ```js\n\n//\nconst weather = (function getWeather(temp) {\nswitch (true) {\ncase temp &lt; 0:\nreturn 'freezing';\ncase temp &lt; 10:\nreturn 'cold';\ncase temp &lt; 24:\nreturn 'cool';\ndefault:\nreturn 'unknown';\n}\n\n     })(10);\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to ignore promise errors?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The easiest and safest way to ignore promise errors is void that error. This approach is ESLint friendly too.\n\n     ```js\n\n//\nawait promise.catch((e) => void e);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do style the console output using CSS?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can add CSS styling to the console output using the CSS format content specifier %c. The console string message can be appended after the specifier and CSS style in another argument. Let's print the red the color text using console.log and CSS specifier as below,\n\n     ```js\n\n//\nconsole.log('%cThis is a red text', 'color:red');\n\n````\n\n     It is also possible to add more styles for the content. For example, the font-size can be modified for the above text\n\n     ```js\n\n//\nconsole.log('%cThis is a red text with bigger font', 'color:red; font-size:20px');\n````</code></pre></div>\n</li>\n<li>\n<p>What is nullish coalescing operator (??)?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. This can be contrasted with the logical OR (||) operator, which returns the right-hand side operand if the left operand is any falsy value, not only null or undefined.\n\n     ```js\n\n//\nconsole.log(null ?? true); // true\nconsole.log(false ?? true); // false\nconsole.log(undefined ?? true); // true\n\n```\n\n```</code></pre></div>\n</li>\n</ol>\n<h3>Coding Exercise</h3>\n<h4>1. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Vehicle</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Honda'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'white'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'2010'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'UK'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Vehicle</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">model<span class=\"token punctuation\">,</span> color<span class=\"token punctuation\">,</span> year<span class=\"token punctuation\">,</span> country</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>year <span class=\"token operator\">=</span> year<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>country <span class=\"token operator\">=</span> country<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  Undefined\n- 2: ReferenceError\n- 3: null\n- 4: {model: \"Honda\", color: \"white\", year: \"2010\", country: \"UK\"}\n\n&lt;details>&lt;summary>&lt;b>Answer&lt;/b>&lt;/summary>\n&lt;p>\n\n##### Answer: 4\n\nThe function declarations are hoisted similar to any variables. So the placement for </span><span class=\"token template-punctuation string\">`</span></span>Vehicle<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> function declaration doesn't make any difference.\n\n&lt;/p>\n&lt;/details>\n\n---\n\n#### 2. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> x <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    x<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    y<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> x<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> x<span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, undefined and undefined</li>\n<li>2: ReferenceError: X is not defined</li>\n<li>3: 1, undefined and number</li>\n<li>4: 1, number and number</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Of course the return value of <code class=\"language-text\">foo()</code> is 1 due to the increment operator. But the statement <code class=\"language-text\">let x = y = 0</code> declares a local variable x. Whereas y declared as a global variable accidentally. This statement is equivalent to,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> x<span class=\"token punctuation\">;</span>\nwindow<span class=\"token punctuation\">.</span>y <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\nx <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span>y<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Since the block scoped variable x is undefined outside of the function, the type will be undefined too. Whereas the global variable <code class=\"language-text\">y</code> is available outside the function, the value is 0 and type is number.</p>\n</p>\n</details>\n<hr>\n<h4>3. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">main</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'B'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'C'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">m</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>A, B and C</li>\n<li>2: B, A and C</li>\n<li>3: A and C</li>\n<li>4: A, C and B</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The statements order is based on the event loop mechanism. The order of statements follows the below order,</p>\n<ol>\n<li>At first, the main function is pushed to the stack.</li>\n<li>Then the browser pushes the fist statement of the main function( i.e, A's console.log) to the stack, executing and popping out immediately.</li>\n<li>But <code class=\"language-text\">setTimeout</code> statement moved to Browser API to apply the delay for callback.</li>\n<li>In the meantime, C's console.log added to stack, executed and popped out.</li>\n<li>The callback of <code class=\"language-text\">setTimeout</code> moved from Browser API to message queue.</li>\n<li>The <code class=\"language-text\">main</code> function popped out from stack because there are no statements to execute</li>\n<li>The callback moved from message queue to the stack since the stack is empty.</li>\n<li>The console.log for B is added to the stack and display on the console.</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>4. What is the output of below equality check</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span> <span class=\"token operator\">===</span> <span class=\"token number\">0.3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>This is due to the float point math problem. Since the floating point numbers are encoded in binary format, the addition operations on them lead to rounding errors. Hence, the comparison of floating points doesn't give expected results.\nYou can find more details about the explanation here <a href=\"https://0.30000000000000004.com/\">0.30000000000000004.com/</a></p>\n</p>\n</details>\n<hr>\n<h4>5. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    y <span class=\"token operator\">+=</span> <span class=\"token keyword\">typeof</span> f<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1function</li>\n<li>2: 1object</li>\n<li>3: ReferenceError</li>\n<li>4: 1undefined</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The main points in the above code snippets are,</p>\n<ol>\n<li>You can see function expression instead function declaration inside if statement. So it always returns true.</li>\n<li>Since it is not declared(or assigned) anywhere, f is undefined and typeof f is undefined too.</li>\n</ol>\n<p>In other words, it is same as</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    y <span class=\"token operator\">+=</span> <span class=\"token keyword\">typeof</span> f<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Note:</strong> It returns 1object for MS Edge browser</p>\n</p>\n</details>\n<hr>\n<h4>6. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Hello World</li>\n<li>2: Object {message: \"Hello World\"}</li>\n<li>3: Undefined</li>\n<li>4: SyntaxError</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>This is a semicolon issue. Normally semicolons are optional in JavaScript. So if there are any statements(in this case, return) missing semicolon, it is automatically inserted immediately. Hence, the function returned as undefined.</p>\n<p>Whereas if the opening curly brace is along with the return keyword then the function is going to be returned as expected.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {message: \"Hello World\"}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>7. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> myChars <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">delete</span> myChars<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[empty, 'b', 'c', 'd'], empty, 3</li>\n<li>2: [null, 'b', 'c', 'd'], empty, 3</li>\n<li>3: [empty, 'b', 'c', 'd'], undefined, 4</li>\n<li>4: [null, 'b', 'c', 'd'], undefined, 4</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The <code class=\"language-text\">delete</code> operator will delete the object property but it will not reindex the array or change its length. So the number or elements or length of the array won't be changed.\nIf you try to print myChars then you can observe that it doesn't set an undefined value, rather the property is removed from the array. The newer versions of Chrome use <code class=\"language-text\">empty</code> instead of <code class=\"language-text\">undefined</code> to make the difference a bit clearer.</p>\n</p>\n</details>\n<hr>\n<h4>8. What is the output of below code in latest Chrome</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> array1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> array2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\narray2<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> array3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[undefined × 3], [undefined × 2, 100], [undefined × 3]</li>\n<li>2: [empty × 3], [empty × 2, 100], [empty × 3]</li>\n<li>3: [null × 3], [null × 2, 100], [null × 3]</li>\n<li>4: [], [100], []</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The latest chrome versions display <code class=\"language-text\">sparse array</code>(they are filled with holes) using this empty x n notation. Whereas the older versions have undefined x n notation.\n<strong>Note:</strong> The latest version of FF displays <code class=\"language-text\">n empty slots</code> notation.</p>\n</p>\n</details>\n<hr>\n<h4>9. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">prop1</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">prop2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'prop'</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop3</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>0, 1, 2</li>\n<li>2: 0, { return 1 }, 2</li>\n<li>3: 0, { return 1 }, { return 2 }</li>\n<li>4: 0, 1, undefined</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>ES6 provides method definitions and property shorthands for objects. So both prop2 and prop3 are treated as regular function values.</p>\n</p>\n</details>\n<hr>\n<h4>10. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">2</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span> <span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>true, true</li>\n<li>2: true, false</li>\n<li>3: SyntaxError, SyntaxError,</li>\n<li>4: false, false</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The important point is that if the statement contains the same operators(e.g, &#x3C; or >) then it can be evaluated from left to right.\nThe first statement follows the below order,</p>\n<ol>\n<li>console.log(1 &#x3C; 2 &#x3C; 3);</li>\n<li>console.log(true &#x3C; 3);</li>\n<li>console.log(1 &#x3C; 3); // True converted as <code class=\"language-text\">1</code> during comparison</li>\n<li>True</li>\n</ol>\n<p>Whereas the second statement follows the below order,</p>\n<ol>\n<li>console.log(3 > 2 > 1);</li>\n<li>console.log(true > 1);</li>\n<li>console.log(1 > 1); // False converted as <code class=\"language-text\">0</code> during comparison</li>\n<li>False</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>11. What is the output of below code in non-strict mode</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">printNumbers</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\np <span class=\"token function\">tNumbers</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, 2, 3</li>\n<li>2: 3, 2, 3</li>\n<li>3: SyntaxError: Duplicate parameter name not allowed in this context</li>\n<li>4: 1, 2, 1</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>In non-strict mode, the regular JavaScript functions allow duplicate named parameters. The above code snippet has duplicate parameters on 1st and 3rd parameters.\nThe value of the first parameter is mapped to the third argument which is passed to the function. Hence, the 3rd argument overrides the first parameter.</p>\n<p><strong>Note:</strong> In strict mode, duplicate parameters will throw a Syntax Error.</p>\n</p>\n</details>\n<hr>\n<h4>12. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">printNumbersArrow</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\np <span class=\"token function\">tNumbersArrow</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, 2, 3</li>\n<li>2: 3, 2, 3</li>\n<li>3: SyntaxError: Duplicate parameter name not allowed in this context</li>\n<li>4: 1, 2, 1</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Unlike regular functions, the arrow functions doesn't not allow duplicate parameters in either strict or non-strict mode. So you can see <code class=\"language-text\">SyntaxError</code> in the console.</p>\n</p>\n</details>\n<hr>\n<h4>13. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">arrowFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">arrowFunc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>ReferenceError: arguments is not defined</li>\n<li>2: 3</li>\n<li>3: undefined</li>\n<li>4: null</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Arrow functions do not have an <code class=\"language-text\">arguments, super, this, or new.target</code> bindings. So any reference to <code class=\"language-text\">arguments</code> variable tries to resolve to a binding in a lexically enclosing environment. In this case, the arguments variable is not defined outside of the arrow function. Hence, you will receive a reference error.</p>\n<p>Where as the normal function provides the number of arguments passed to the function</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">func</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>But If you still want to use an arrow function then rest operator on arguments provides the expected arguments</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">arrowFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>args</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> args<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">arrowFunc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>14. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>trimLeft<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'trimLeft'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>trimLeft<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'trimStart'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: True, False</li>\n<li>2: False, True</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>In order to be consistent with functions like <code class=\"language-text\">String.prototype.padStart</code>, the standard method name for trimming the whitespaces is considered as <code class=\"language-text\">trimStart</code>. Due to web web compatibility reasons, the old method name 'trimLeft' still acts as an alias for 'trimStart'. Hence, the prototype for 'trimLeft' is always 'trimStart'</p>\n</p>\n</details>\n<hr>\n<h4>15. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined</li>\n<li>2: Infinity</li>\n<li>3: 0</li>\n<li>4: -Infinity</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>-Infinity is the initial comparant because almost every other value is bigger. So when no arguments are provided, -Infinity is going to be returned.\n<strong>Note:</strong> Zero number of arguments is a valid case.</p>\n</p>\n</details>\n<hr>\n<h4>16. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">==</span> <span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">==</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>True, True</li>\n<li>2: True, False</li>\n<li>3: False, False</li>\n<li>4: False, True</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>As per the comparison algorithm in the ECMAScript specification(ECMA-262), the above expression converted into JS as below</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token number\">10</span> <span class=\"token operator\">===</span> <span class=\"token function\">Number</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">valueOf</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 10</span></code></pre></div>\n<p>So it doesn't matter about number brackets([]) around the number, it is always converted to a number in the expression.</p>\n</p>\n</details>\n<hr>\n<h4>17. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">+</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">-</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>20, 0</li>\n<li>2: 1010, 0</li>\n<li>3: 1010, 10-10</li>\n<li>4: NaN, NaN</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The concatenation operator(+) is applicable for both number and string types. So if any operand is string type then both operands concatenated as strings. Whereas subtract(-) operator tries to convert the operands as number type.</p>\n</p>\n</details>\n<hr>\n<h4>18. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm True\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm False\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  True, I'm True\n- 2: True, I'm False\n- 3: False, I'm True\n- 4: False, I'm False\n\n&lt;details>&lt;summary>&lt;b>Answer&lt;/b>&lt;/summary>\n&lt;p>\n\n##### Answer: 1\n\nIn comparison operators, the expression </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> converted to Number([0].valueOf().toString()) which is resolved to false. Whereas </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> just becomes a truthy value without any conversion because there is no comparison operator.\n\n&lt;/p>\n&lt;/details>\n\n#### 19. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[1,2,3,4]</li>\n<li>2: [1,2][3,4]</li>\n<li>3: SyntaxError</li>\n<li>4: 1,23,4</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The + operator is not meant or defined for arrays. So it converts arrays into strings and concatenates them.</p>\n</p>\n</details>\n<hr>\n<h4>20. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> browser <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Firefox'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>browser<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}</li>\n<li>2: {1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"}</li>\n<li>3: [1, 2, 3, 4], [\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"]</li>\n<li>4: {1, 1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Since <code class=\"language-text\">Set</code> object is a collection of unique values, it won't allow duplicate values in the collection. At the same time, it is case sensitive data structure.</p>\n</p>\n</details>\n<hr>\n<h4>21. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span> <span class=\"token operator\">===</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: True</li>\n<li>2: False</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>JavaScript follows IEEE 754 spec standards. As per this spec, NaNs are never equal for floating-point numbers.</p>\n</p>\n</details>\n<hr>\n<h4>22. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>4</li>\n<li>2: NaN</li>\n<li>3: SyntaxError</li>\n<li>4: -1</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The <code class=\"language-text\">indexOf</code> uses strict equality operator(===) internally and <code class=\"language-text\">NaN === NaN</code> evaluates to false. Since indexOf won't be able to find NaN inside an array, it returns -1 always.\nBut you can use <code class=\"language-text\">Array.prototype.findIndex</code> method to find out the index of NaN in an array or You can use <code class=\"language-text\">Array.prototype.includes</code> to check if NaN is present in an array or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">findIndex</span><span class=\"token punctuation\">(</span>Number<span class=\"token punctuation\">.</span>isNaN<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 4</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>23. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, [2, 3, 4, 5]</li>\n<li>2: 1, {2, 3, 4, 5}</li>\n<li>3: SyntaxError</li>\n<li>4: 1, [2, 3, 4]</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>When using rest parameters, trailing commas are not allowed and will throw a SyntaxError.\nIf you remove the trailing comma then it displays 1st answer</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1, [2, 3, 4, 5]</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>25. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Promise {&#x3C;fulfilled>: 10}</li>\n<li>2: 10</li>\n<li>3: SyntaxError</li>\n<li>4: Promise {&#x3C;rejected>: 10}</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Async functions always return a promise. But even if the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise. The above async function is equivalent to below expression,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>26. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Promise {&#x3C;fulfilled>: 10}</li>\n<li>2: 10</li>\n<li>3: SyntaxError</li>\n<li>4: Promise {&#x3C;resolved>: undefined}</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The await expression returns value 10 with promise resolution and the code after each await expression can be treated as existing in a <code class=\"language-text\">.then</code> callback. In this case, there is no return expression at the end of the function. Hence, the default return value of <code class=\"language-text\">undefined</code> is returned as the resolution of the promise. The above async function is equivalent to below expression,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>27. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">processArray</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\np <span class=\"token function\">essArray</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: 1, 2, 3, 4</li>\n<li>3: 4, 4, 4, 4</li>\n<li>4: 4, 3, 2, 1</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Even though \"processArray\" is an async function, the anonymous function that we use for <code class=\"language-text\">forEach</code> is synchronous. If you use await inside a synchronous function then it throws a syntax error.</p>\n</p>\n</details>\n<hr>\n<h4>28. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">process</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Process completed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\np <span class=\"token function\">ess</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1 2 3 5 and Process completed!</li>\n<li>2: 5 5 5 5 and Process completed!</li>\n<li>3: Process completed! and 5 5 5 5</li>\n<li>4: Process completed! and 1 2 3 5</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The forEach method will not wait until all items are finished but it just runs the tasks and goes next. Hence, the last statement is displayed first followed by a sequence of promise resolutions.</p>\n<p>But you control the array sequence using for..of loop,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">processArray</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> item <span class=\"token keyword\">of</span> array<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Process completed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>29. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> set <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'+0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>set<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Set(4) {\"+0\", \"-0\", NaN, undefined}</li>\n<li>2: Set(3) {\"+0\", NaN, undefined}</li>\n<li>3: Set(5) {\"+0\", \"-0\", NaN, undefined, NaN}</li>\n<li>4: Set(4) {\"+0\", NaN, undefined, NaN}</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Set has few exceptions from equality check,</p>\n<ol>\n<li>All NaN values are equal</li>\n<li>Both +0 and -0 considered as different values</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>30. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> sym1 <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> sym2 <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> sym3 <span class=\"token operator\">=</span> Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> sym4 <span class=\"token operator\">=</span> Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nc oe<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sym1 <span class=\"token operator\">===</span> sym2<span class=\"token punctuation\">,</span> sym3 <span class=\"token operator\">===</span> sym4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>true, true</li>\n<li>2: true, false</li>\n<li>3: false, true</li>\n<li>4: false, false</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Symbol follows below conventions,</p>\n<ol>\n<li>Every symbol value returned from Symbol() is unique irrespective of the optional string.</li>\n<li><code class=\"language-text\">Symbol.for()</code> function creates a symbol in a global symbol registry list. But it doesn't necessarily create a new symbol on every call, it checks first if a symbol with the given key is already present in the registry and returns the symbol if it is found. Otherwise a new symbol created in the registry.</li>\n</ol>\n<p><strong>Note:</strong> The symbol description is just useful for debugging purposes.</p>\n</p>\n</details>\n<hr>\n<h4>31. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> sym1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sym1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: one</li>\n<li>3: Symbol('one')</li>\n<li>4: Symbol</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p><code class=\"language-text\">Symbol</code> is a just a standard function and not an object constructor(unlike other primitives new Boolean, new String and new Number). So if you try to call it with the new operator will result in a TypeError</p>\n</p>\n</details>\n<hr>\n<h4>32. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> myNumber <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> myString <span class=\"token operator\">=</span> <span class=\"token string\">'100'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myNumber <span class=\"token operator\">===</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is not a string!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is a string!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myString <span class=\"token operator\">===</span> <span class=\"token string\">'number'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is not a number!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is a number!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  SyntaxError\n- 2: It is not a string!, It is not a number!\n- 3: It is not a string!, It is a number!\n- 4: It is a string!, It is a number!\n\n&lt;details>&lt;summary>&lt;b>Answer&lt;/b>&lt;/summary>\n&lt;p>\n\n##### Answer: 4\n\nThe return value of </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token keyword\">typeof</span> <span class=\"token function\">myNumber</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">OR</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">typeof</span> myString<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> is always the truthy value (either \"number\" or \"string\"). Since ! operator converts the value to a boolean value, the value of both </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myNumber or <span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myString<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> is always false. Hence the if condition fails and control goes to else block.\n\n&lt;/p>\n\n&lt;/details>\n\n---\n\n#### 33. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">myArray</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token string\">'one'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{\"myArray\":['one', undefined, {}, Symbol]}, {}</li>\n<li>2: {\"myArray\":['one', null,null,null]}, {}</li>\n<li>3: {\"myArray\":['one', null,null,null]}, \"{ [Symbol.for('one')]: 'one' }, [Symbol.for('one')]\"</li>\n<li>4: {\"myArray\":['one', undefined, function(){}, Symbol('')]}, {}</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The symbols has below constraints,</p>\n<ol>\n<li>The undefined, Functions, and Symbols are not valid JSON values. So those values are either omitted (in an object) or changed to null (in an array). Hence, it returns null values for the value array.</li>\n<li>All Symbol-keyed properties will be completely ignored. Hence it returns an empty object({}).</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>34. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">A</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span><span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">B</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">A</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">A</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nn <span class=\"token constant\">B</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: A, A</li>\n<li>2: A, B</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Using constructors, <code class=\"language-text\">new.target</code> refers to the constructor (points to the class definition of class which is initialized) that was directly invoked by new. This also applies to the case if the constructor is in a parent class and was delegated from a child constructor.</p>\n</p>\n</details>\n<hr>\n<h4>35. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>y<span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, [2, 3, 4]</li>\n<li>2: 1, [2, 3]</li>\n<li>3: 1, [2]</li>\n<li>4: SyntaxError</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It throws a syntax error because the rest element should not have a trailing comma. You should always consider using a rest operator as the last element.</p>\n</p>\n</details>\n<hr>\n<h4>36. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> x <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> y <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30, 20</li>\n<li>2: 10, 20</li>\n<li>3: 10, undefined</li>\n<li>4: 30, undefined</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The object property follows below rules,</p>\n<ol>\n<li>The object properties can be retrieved and assigned to a variable with a different name</li>\n<li>The property assigned a default value when the retrieved value is <code class=\"language-text\">undefined</code></li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>37. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">a</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>200</li>\n<li>2: Error</li>\n<li>3: undefined</li>\n<li>4: 0</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>If you leave out the right-hand side assignment for the destructuring object, the function will look for at least one argument to be supplied when invoked. Otherwise you will receive an error <code class=\"language-text\">Error: Cannot read property 'length' of undefined</code> as mentioned above.</p>\n<p>You can avoid the error with either of the below changes,</p>\n<ol>\n<li><strong>Pass at least an empty object:</strong></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol start=\"2\">\n<li><strong>Assign default empty object:</strong></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>38. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> props <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jack'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Tom'</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> name <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Tom</li>\n<li>2: Error</li>\n<li>3: undefined</li>\n<li>4: John</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>It is possible to combine Array and Object destructuring. In this case, the third element in the array props accessed first followed by name property in the object.</p>\n</p>\n</details>\n<hr>\n<h4>39. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">num <span class=\"token operator\">=</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc <span class=\"token function\">kType</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>number, undefined, string, object</li>\n<li>2: undefined, undefined, string, object</li>\n<li>3: number, number, string, object</li>\n<li>4: number, number, number, number</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>If the function argument is set implicitly(not passing argument) or explicitly to undefined, the value of the argument is the default parameter. Whereas for other falsy values('' or null), the value of the argument is passed as a parameter.</p>\n<p>Hence, the result of function calls categorized as below,</p>\n<ol>\n<li>The first two function calls logs number type since the type of default value is number</li>\n<li>The type of '' and null values are string and object type respectively.</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>40. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item<span class=\"token punctuation\">,</span> items <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    items<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> items<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Orange'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Apple'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: ['Orange'], ['Orange', 'Apple']</li>\n<li>2: ['Orange'], ['Apple']</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Since the default argument is evaluated at call time, a new object is created each time the function is called. So in this case, the new array is created and an element pushed to the default empty array.</p>\n</p>\n</details>\n<hr>\n<h4>41. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">,</span> message <span class=\"token operator\">=</span> greeting <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>greeting<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">,</span> message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ng <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Good morning!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: ['Hello', 'John', 'Hello John'], ['Hello', 'John', 'Good morning!']</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Since parameters defined earlier are available to later default parameters, this code snippet doesn't throw any error.</p>\n</p>\n</details>\n<hr>\n<h4>42. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">outer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f <span class=\"token operator\">=</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Inner'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\no <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: ReferenceError</li>\n<li>2: Inner</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The functions and variables declared in the function body cannot be referred from default value parameter initializers. If you still try to access, it throws a run-time ReferenceError(i.e, <code class=\"language-text\">inner</code> is not defined).</p>\n</p>\n</details>\n<hr>\n<h4>43. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">myFun</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>manyMoreArgs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>manyMoreArgs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">myFun</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nm <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[3, 4, 5], undefined</li>\n<li>2: SyntaxError</li>\n<li>3: [3, 4, 5], []</li>\n<li>4: [3, 4, 5], [undefined]</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The rest parameter is used to hold the remaining parameters of a function and it becomes an empty array if the argument is not provided.</p>\n</p>\n</details>\n<hr>\n<h4>44. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'value'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> array <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>obj<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>['key', 'value']</li>\n<li>2: TypeError</li>\n<li>3: []</li>\n<li>4: ['key']</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Spread syntax can be applied only to iterable objects. By default, Objects are not iterable, but they become iterable when used in an Array, or with iterating functions such as <code class=\"language-text\">map(), reduce(), and assign()</code>. If you still try to do it, it still throws <code class=\"language-text\">TypeError: obj is not iterable</code>.</p>\n</p>\n</details>\n<hr>\n<h4>45. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1</li>\n<li>2: undefined</li>\n<li>3: SyntaxError</li>\n<li>4: TypeError</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>Generators are not constructible type. But if you still proceed to do, there will be an error saying \"TypeError: myGenFunc is not a constructor\"</p>\n</p>\n</details>\n<hr>\n<h4>46. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{ value: 1, done: false }, { value: 2, done: true }, { value: undefined, done: true }</li>\n<li>2: { value: 1, done: false }, { value: 2, done: false }, { value: undefined, done: true }</li>\n<li>3: { value: 1, done: false }, { value: 2, done: true }, { value: 3, done: true }</li>\n<li>4: { value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>A return statement in a generator function will make the generator finish. If a value is returned, it will be set as the value property of the object and done property to true. When a generator is finished, subsequent next() calls return an object of this form: <code class=\"language-text\">{value: undefined, done: true}</code>.</p>\n</p>\n</details>\n<hr>\n<h4>47. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> myGenerator <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  1,2,3 and 1,2,3\n- 2: 1,2,3 and 4,5,6\n- 3: 1 and 1\n- 4: 1\n\n&lt;details>&lt;summary>&lt;b>Answer&lt;/b>&lt;/summary>\n&lt;p>\n\n##### Answer: 4\n\nThe generator should not be re-used once the iterator is closed. i.e, Upon exiting a loop(on completion or using break &amp; return), the generator is closed and trying to iterate over it again does not yield any more results. Hence, the second loop doesn't print any value.\n\n&lt;/p>\n\n&lt;/details>\n\n---\n\n#### 48. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\n<span class=\"token keyword\">const</span> num <span class=\"token operator\">=</span> 0o38<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: 38</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>If you use an invalid number(outside of 0-7 range) in the octal literal, JavaScript will throw a SyntaxError. In ES5, it treats the octal literal as a decimal number.</p>\n</p>\n</details>\n<hr>\n<h4>49. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> squareObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Square</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>squareObj<span class=\"token punctuation\">.</span>area<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Square</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">length</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">set</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>area <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n- 1: 100\n- 2: ReferenceError\n\n&lt;details>&lt;summary>&lt;b>Answer&lt;/b>&lt;/summary>\n&lt;p>\n\n##### Answer: 2\n\nUnlike function declarations, class declarations are not hoisted. i.e, First You need to declare your class and then access it, otherwise it will throw a ReferenceError \"Uncaught ReferenceError: Square is not defined\".\n\n**Note:** Class expressions also applies to the same hoisting restrictions of class declarations.\n\n&lt;/p>\n\n&lt;/details>\n\n---\n\n#### 50. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\n<span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">walk</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nPerson<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">run</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> walk <span class=\"token operator\">=</span> user<span class=\"token punctuation\">.</span>walk<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> run <span class=\"token operator\">=</span> Person<span class=\"token punctuation\">.</span>run<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined, undefined</li>\n<li>2: Person, Person</li>\n<li>3: SyntaxError</li>\n<li>4: Window, Window</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>When a regular or prototype method is called without a value for <strong>this</strong>, the methods return an initial this value if the value is not undefined. Otherwise global window object will be returned. In our case, the initial <code class=\"language-text\">this</code> value is undefined so both methods return window objects.</p>\n</p>\n</details>\n<hr>\n<h4>51. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> vehicle started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Car</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> car started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'BMW'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: BMW vehicle started, BMW car started</li>\n<li>3: BMW car started, BMW vehicle started</li>\n<li>4: BMW car started, BMW car started</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The super keyword is used to call methods of a superclass. Unlike other languages the super invocation doesn't need to be a first statement. i.e, The statements will be executed in the same order of code.</p>\n</p>\n</details>\n<hr>\n<h4>52. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token constant\">USER</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">25</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30</li>\n<li>2: 25</li>\n<li>3: Uncaught TypeError</li>\n<li>4: SyntaxError</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Even though we used constant variables, the content of it is an object and the object's contents (e.g properties) can be altered. Hence, the change is going to be valid in this case.</p>\n</p>\n</details>\n<hr>\n<h4>53. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🙂'</span> <span class=\"token operator\">===</span> <span class=\"token string\">'🙂'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Emojis are unicodes and the unicode for smile symbol is \"U+1F642\". The unicode comparision of same emojies is equivalent to string comparison. Hence, the output is always true.</p>\n</p>\n</details>\n<hr>\n<h4>54. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>string</li>\n<li>2: boolean</li>\n<li>3: NaN</li>\n<li>4: number</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The typeof operator on any primitive returns a string value. So even if you apply the chain of typeof operators on the return value, it is always string.</p>\n</p>\n</details>\n<hr>\n<h4>55. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> zero <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>zero<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'If'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Else'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  If\n- 2: Else\n- 3: NaN\n- 4: SyntaxError\n\n&lt;details>&lt;summary>&lt;b>Answer&lt;/b>&lt;/summary>\n&lt;p>\n\n##### Answer: 1\n\n1. The type of operator on new Number always returns object. i.e, typeof new Number(0) --> object.\n2. Objects are always truthy in if block\n\nHence the above code block always goes to if section.\n\n&lt;/p>\n\n&lt;/details>\n\n---\n\n#### 55. What is the output of below code in non strict mode?\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\n<span class=\"token keyword\">let</span> msg <span class=\"token operator\">=</span> <span class=\"token string\">'Good morning!!'</span><span class=\"token punctuation\">;</span>\n\nmsg<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">;</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>msg<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>\"\"</li>\n<li>2: Error</li>\n<li>3: John</li>\n<li>4: Undefined</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It returns undefined for non-strict mode and returns Error for strict mode. In non-strict mode, the wrapper object is going to be created and get the mentioned property. But the object get disappeared after accessing the property in next line.</p>\n</p>\n</details>\n<hr>\n<h4>56. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">innerFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">===</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">11</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>11, 10</li>\n<li>2: 11, 11</li>\n<li>3: 10, 11</li>\n<li>4: 10, 10</li>\n</ul>\n<details><summary><b>Answer</b></summary>\n<p>\n<h5>Answer: 1</h5>\n<p>11 and 10 is logged to the console.</p>\n<p>The innerFunc is a closure which captures the count variable from the outerscope. i.e, 10. But the conditional has another local variable <code class=\"language-text\">count</code> which overwrites the ourter <code class=\"language-text\">count</code> variable. So the first console.log displays value 11.\nWhereas the second console.log logs 10 by capturing the count variable from outerscope.</p>\n</p>\n</details>\n<hr>\n<hr>"},{"url":"/blog/interview-questions-js-p2/","relativePath":"blog/interview-questions-js-p2.md","relativeDir":"blog","base":"interview-questions-js-p2.md","name":"interview-questions-js-p2","frontmatter":{"title":"JS-Questions P2","subtitle":"Javascript Interview Questions P2","date":"2021-09-11","thumb_image_alt":"big o","excerpt":"What are the possible ways to create objects in JavaScript","seo":{"title":"Javascript Interview","description":"What are the possible ways to create objects in JavaScript","robots":[],"extra":[{"name":"og:image","value":"images/js-code-spiral-num.png","keyName":"property","relativeUrl":true},{"name":"twitter:title","value":"JS-Interview","keyName":"name","relativeUrl":false},{"name":"twitter:description","value":"What are the possible ways to create objects in JavaScript","keyName":"name","relativeUrl":false}]},"template":"post","thumb_image":"images/bigo.jpg","image":"images/js-questions-n-answers.png"},"html":"<h2>Javascript Interview Questions</h2>\n<ol>\n<li>\n<p>What are the possible ways to create objects in JavaScript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are many ways to create objects in javascript as below\n\n1. **Object constructor:**\n\n    The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended.\n\n    ```js</code></pre></div>\n<p>//\nvar object = new Object();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    2. **Object's create method:**\n\n        The create method of Object creates a new object by passing the prototype object as a parameter\n\n        ```js\n\n//\nvar object = Object.create(null);</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">3. **Object literal syntax:**\n\n    The object literal syntax is equivalent to create method when it passes null as parameter\n\n    ```js</code></pre></div>\n<p>//\nvar object = {};</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    4. **Function constructor:**\n\n        Create any function and apply the new operator to create object instances,\n\n        ```js\n\n//\nfunction Person(name) {\nthis.name = name;\nthis.age = 21;\n}\nvar object = new Person('Sudheer');</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">5. **Function constructor with prototype:**\n\n    This is similar to function constructor but it uses prototype for their properties and methods,\n\n    ```js</code></pre></div>\n<p>//\nfunction Person() {}\nPerson.prototype.name = 'Sudheer';\nvar object = new Person();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        This is equivalent to an instance created with an object create method with a function prototype and then call that function with an instance and parameters as arguments.\n\n        ```js\n\n//\nfunction func {};\n\n        new func(x, y, z);\n        ```\n\n        **(OR)**\n\n        ```js\n\n//\n// Create a new instance using function prototype.\nvar newInstance = Object.create(func.prototype)\n\n        // Call the function\n        var result = func.call(newInstance, x, y, z),\n\n        // If the result is a non-null object then use it otherwise just use the new instance.\n        console.log(result &amp;&amp; typeof result === 'object' ? result : newInstance);\n        ```\n\n    6. **ES6 Class syntax:**\n\n        ES6 introduces class feature to create the objects\n\n        ```js\n\n//\nclass Person {\nconstructor(name) {\nthis.name = name;\n}\n}\n\n        var object = new Person('Sudheer');\n        ```\n\n    7. **Singleton pattern:**\n\n        A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance and this way one can ensure that they don't accidentally create multiple instances.\n\n        ```js\n\n//\nvar object = new (function () {\nthis.name = 'Sudheer';\n})();</code></pre></div>\n</li>\n<li>\n<p>What is a prototype chain</p>\n<p><strong>Prototype chaining</strong> is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language.</p>\n<p>The prototype on object instance is available through <strong>Object.getPrototypeOf(object)</strong> or *<strong>*proto**</strong> property whereas prototype on constructors function is available through <strong>Object.prototype</strong>.</p>\n<p><img src=\"images/prototype_chain.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>What is the difference between Call, Apply and Bind</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The difference between Call, Apply and Bind can be explained with below examples,\n\n**Call:** The call() method invokes a function with a given `this` value and arguments provided one by one\n\n```js</code></pre></div>\n<p>//\nvar employee1 = { firstName: 'John', lastName: 'Rodson' };\nvar employee2 = { firstName: 'Jimmy', lastName: 'Baily' };</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName + ', ' + greeting2);\n}\n\ninvite.call(employee1, 'Hello', 'How are you?'); // Hello John Rodson, How are you?\ninvite.call(employee2, 'Hello', 'How are you?'); // Hello Jimmy Baily, How are you?\n```\n\n**Apply:** Invokes the function with a given `this` value and allows you to pass in arguments as an array\n\n```js</code></pre></div>\n<p>//\nvar employee1 = { firstName: 'John', lastName: 'Rodson' };\nvar employee2 = { firstName: 'Jimmy', lastName: 'Baily' };</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName + ', ' + greeting2);\n}\n\ninvite.apply(employee1, ['Hello', 'How are you?']); // Hello John Rodson, How are you?\ninvite.apply(employee2, ['Hello', 'How are you?']); // Hello Jimmy Baily, How are you?\n```\n\n**bind:** returns a new function, allowing you to pass any number of arguments\n\n```js</code></pre></div>\n<p>//\nvar employee1 = { firstName: 'John', lastName: 'Rodson' };\nvar employee2 = { firstName: 'Jimmy', lastName: 'Baily' };</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName + ', ' + greeting2);\n}\n\nvar inviteEmployee1 = invite.bind(employee1);\nvar inviteEmployee2 = invite.bind(employee2);\ninviteEmployee1('Hello', 'How are you?'); // Hello John Rodson, How are you?\ninviteEmployee2('Hello', 'How are you?'); // Hello Jimmy Baily, How are you?\n```\n\nCall and apply are pretty interchangeable. Both execute the current function immediately. You need to decide whether it's easier to send in an array or a comma separated list of arguments. You can remember by treating Call is for **comma** (separated list) and Apply is for **Array**.\n\nWhereas Bind creates a new function that will have `this` set to the first parameter passed to bind().</code></pre></div>\n</li>\n<li>\n<p>What is JSON and its common operations</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**JSON** is a text-based data format following JavaScript object syntax, which was popularized by `Douglas Crockford`. It is useful when you want to transmit data across a network and it is basically just a text file with an extension of .json, and a MIME type of application/json\n\n**Parsing:** Converting a string to a native object\n\n```js</code></pre></div>\n<p>//\nJSON.parse(text);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Stringification:** converting a native object to a string so it can be transmitted across the network\n\n    ```js\n\n//\nJSON.stringify(object);</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the array slice method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The **slice()** method returns the selected elements in an array as a new array object. It selects the elements starting at the given start argument, and ends at the given optional end argument without including the last element. If you omit the second argument then it selects till the end.\n\nSome of the examples of this method are,\n\n```js</code></pre></div>\n<p>//\nlet arrayIntegers = [1, 2, 3, 4, 5];\nlet arrayIntegers1 = arrayIntegers.slice(0, 2); // returns [1,2]\nlet arrayIntegers2 = arrayIntegers.slice(2, 3); // returns [3]\nlet arrayIntegers3 = arrayIntegers.slice(4); //returns [5]</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Note:** Slice method won't mutate the original array but it returns the subset as a new array.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the array splice method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The **splice()** method is used either adds/removes items to/from an array, and then returns the removed item. The first argument specifies the array position for insertion or deletion whereas the optional second argument indicates the number of elements to be deleted. Each additional argument is added to the array.\n\nSome of the examples of this method are,\n\n```js</code></pre></div>\n<p>//\nlet arrayIntegersOriginal1 = [1, 2, 3, 4, 5];\nlet arrayIntegersOriginal2 = [1, 2, 3, 4, 5];\nlet arrayIntegersOriginal3 = [1, 2, 3, 4, 5];</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let arrayIntegers1 = arrayIntegersOriginal1.splice(0, 2); // returns [1, 2]; original array: [3, 4, 5]\nlet arrayIntegers2 = arrayIntegersOriginal2.splice(3); // returns [4, 5]; original array: [1, 2, 3]\nlet arrayIntegers3 = arrayIntegersOriginal3.splice(3, 1, 'a', 'b', 'c'); //returns [4]; original array: [1, 2, 3, \"a\", \"b\", \"c\", 5]\n```\n\n**Note:** Splice method modifies the original array and returns the deleted array.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between slice and splice</p>\n<p>Some of the major difference in a tabular form</p>\n<table>\n<thead>\n<tr>\n<th>Slice</th>\n<th>Splice</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Doesn't modify the original array(immutable)</td>\n<td>Modifies the original array(mutable)</td>\n</tr>\n<tr>\n<td>Returns the subset of original array</td>\n<td>Returns the deleted elements as array</td>\n</tr>\n<tr>\n<td>Used to pick the elements from array</td>\n<td>Used to insert or delete elements to/from array</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>How do you compare Object and Map</p>\n<p><strong>Objects</strong> are similar to <strong>Maps</strong> in that both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. Due to this reason, Objects have been used as Maps historically. But there are important differences that make using a Map preferable in certain cases.</p>\n<ol>\n<li>The keys of an Object are Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive.</li>\n<li>The keys in Map are ordered while keys added to Object are not. Thus, when iterating over it, a Map object returns keys in order of insertion.</li>\n<li>You can get the size of a Map easily with the size property, while the number of properties in an Object must be determined manually.</li>\n<li>A Map is an iterable and can thus be directly iterated, whereas iterating over an Object requires obtaining its keys in some fashion and iterating over them.</li>\n<li>An Object has a prototype, so there are default keys in the map that could collide with your keys if you're not careful. As of ES5 this can be bypassed by using map = Object.create(null), but this is seldom done.</li>\n<li>A Map may perform better in scenarios involving frequent addition and removal of key pairs.</li>\n</ol>\n</li>\n<li>\n<p>What is the difference between == and === operators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison. The strict operators take type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables. The strict operators follow the below conditions for different types,\n\n1. Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.\n2. Two numbers are strictly equal when they are numerically equal. i.e, Having the same number value.\n   There are two special cases in this,\n    1. NaN is not equal to anything, including NaN.\n    2. Positive and negative zeros are equal to one another.\n3. Two Boolean operands are strictly equal if both are true or both are false.\n4. Two objects are strictly equal if they refer to the same Object.\n5. Null and Undefined types are not equal with ===, but equal with ==. i.e,\n   null===undefined --> false but null==undefined --> true\n\nSome of the example which covers the above cases,\n\n```js</code></pre></div>\n<p>//\n0 == false // true\n0 === false // false\n1 == \"1\" // true\n1 === \"1\" // false\nnull == undefined // true\nnull === undefined // false\n'0' == false // true\n'0' === false // false\n[]==[] or []===[] //false, refer different objects in memory\n{}=={} or {}==={} //false, refer different objects in memory</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are lambda or arrow functions</p>\n<p>An arrow function is a shorter syntax for a function expression and does not have its own <strong>this, arguments, super, or new.target</strong>. These functions are best suited for non-method functions, and they cannot be used as constructors.</p>\n</li>\n<li>\n<p>What is a first class function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In Javascript, functions are first class objects. First-class functions means when functions in that language are treated like any other variable.\n\nFor example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable. For example, in the below example, handler functions assigned to a listener\n\n```js</code></pre></div>\n<p>//\nconst handler = () => console.log('This is a click handler function');\ndocument.addEventListener('click', handler);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is a first order function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">First-order function is a function that doesn't accept another function as an argument and doesn't return a function as its return value.\n\n```js</code></pre></div>\n<p>//\nconst firstOrder = () => console.log('I am a first order function!');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is a higher order function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Higher-order function is a function that accepts another function as an argument or returns a function as a return value or both.\n\n```js</code></pre></div>\n<p>//\nconst firstOrderFunc = () => console.log('Hello, I am a First order function');\nconst higherOrder = (ReturnFirstOrderFunc) => ReturnFirstOrderFunc();\nhigherOrder(firstOrderFunc);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is a unary function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Unary function (i.e. monadic) is a function that accepts exactly one argument. It stands for a single argument accepted by a function.\n\nLet us take an example of unary function,\n\n```js</code></pre></div>\n<p>//\nconst unaryFunction = (a) => console.log(a + 10); // Add 10 to the given argument and display the value</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the currying function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Currying is the process of taking a function with multiple arguments and turning it into a sequence of functions each with only a single argument. Currying is named after a mathematician **Haskell Curry**. By applying currying, a n-ary function turns it into a unary function.\n\nLet's take an example of n-ary function and how it turns into a currying function,\n\n```js</code></pre></div>\n<p>//\nconst multiArgFunction = (a, b, c) => a + b + c;\nconsole.log(multiArgFunction(1, 2, 3)); // 6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const curryUnaryFunction = (a) => (b) => (c) => a + b + c;\ncurryUnaryFunction(1); // returns a function: b => c =>  1 + b + c\ncurryUnaryFunction(1)(2); // returns a function: c => 3 + c\ncurryUnaryFunction(1)(2)(3); // returns the number 6\n```\n\nCurried functions are great to improve **code reusability** and **functional composition**.</code></pre></div>\n</li>\n<li>\n<p>What is a pure function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A **Pure function** is a function where the return value is only determined by its arguments without any side effects. i.e, If you call a function with the same arguments 'n' number of times and 'n' number of places in the application then it will always return the same value.\n\nLet's take an example to see the difference between pure and impure functions,\n\n```js</code></pre></div>\n<p>//\n//Impure\nlet numberArray = [];\nconst impureAddNumber = (number) => numberArray.push(number);\n//Pure\nconst pureAddNumber = (number) => (argNumberArray) => argNumberArray.concat([number]);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Display the results\nconsole.log(impureAddNumber(6)); // returns 1\nconsole.log(numberArray); // returns [6]\nconsole.log(pureAddNumber(7)(numberArray)); // returns [6, 7]\nconsole.log(numberArray); // returns [6]\n```\n\nAs per above code snippets, **Push** function is impure itself by altering the array and returning an push number index which is independent of parameter value. Whereas **Concat** on the other hand takes the array and concatenates it with the other array producing a whole new array without side effects. Also, the return value is a concatenation of the previous array.\n\nRemember that Pure functions are important as they simplify unit testing without any side effects and no need for dependency injection. They also avoid tight coupling and make it harder to break your application by not having any side effects. These principles are coming together with **Immutability** concept of ES6 by giving preference to **const** over **let** usage.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the let keyword</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `let` statement declares a **block scope local variable**. Hence the variables defined with let keyword are limited in scope to the block, statement, or expression on which it is used. Whereas variables declared with the `var` keyword used to define a variable globally, or locally to an entire function regardless of block scope.\n\nLet's take an example to demonstrate the usage,\n\n```js</code></pre></div>\n<p>//\nlet counter = 30;\nif (counter === 30) {\nlet counter = 31;\nconsole.log(counter); // 31\n}\nconsole.log(counter); // 30 (because the variable in if block won't exist here)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the difference between let and var</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can list out the differences in a tabular format\n\n| var                                                   | let                         |\n|-------------------------------------------------------|-----------------------------|\n| It is been available from the beginning of JavaScript | Introduced as part of ES6   |\n| It has function scope                                 | It has block scope          |\n| Variables will be hoisted                             | Hoisted but not initialized |\n\nLet's take an example to see the difference,\n\n```js</code></pre></div>\n<p>//\nfunction userDetails(username) {\nif (username) {\nconsole.log(salary); // undefined due to hoisting\nconsole.log(age); // ReferenceError: Cannot access 'age' before initialization\nlet age = 30;\nvar salary = 10000;\n}\nconsole.log(salary); //10000 (accessible to due function scope)\nconsole.log(age); //error: age is not defined(due to block scope)\n}\nuserDetails('John');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the reason to choose the name let as a keyword</p>\n<p><code class=\"language-text\">let</code> is a mathematical statement that was adopted by early programming languages like <strong>Scheme</strong> and <strong>Basic</strong>. It has been borrowed from dozens of other languages that use <code class=\"language-text\">let</code> already as a traditional keyword as close to <code class=\"language-text\">var</code> as possible.</p>\n</li>\n<li>\n<p>How do you redeclare variables in switch block without an error</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you try to redeclare variables in a `switch block` then it will cause errors because there is only one block. For example, the below code block throws a syntax error as below,\n\n```js</code></pre></div>\n<p>//\nlet counter = 1;\nswitch (x) {\ncase 0:\nlet name;\nbreak;</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    case 1:\n        let name; // SyntaxError for redeclaration.\n        break;\n}\n```\n\nTo avoid this error, you can create a nested block inside a case clause and create a new block scoped lexical environment.\n\n```js</code></pre></div>\n<p>//\nlet counter = 1;\nswitch (x) {\ncase 0: {\nlet name;\nbreak;\n}\ncase 1: {\nlet name; // No SyntaxError for redeclaration.\nbreak;\n}\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the Temporal Dead Zone</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Temporal Dead Zone is a behavior in JavaScript that occurs when declaring a variable with the let and const keywords, but not with var. In ECMAScript 6, accessing a `let` or `const` variable before its declaration (within its scope) causes a ReferenceError. The time span when that happens, between the creation of a variable's binding and its declaration, is called the temporal dead zone.\n\nLet's see this behavior with an example,\n\n```js</code></pre></div>\n<p>//\nfunction somemethod() {\nconsole.log(counter1); // undefined\nconsole.log(counter2); // ReferenceError\nvar counter1 = 1;\nlet counter2 = 2;\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is IIFE(Immediately Invoked Function Expression)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. The signature of it would be as below,\n\n```js</code></pre></div>\n<p>//\n(function () {\n// logic here\n})();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    The primary reason to use an IIFE is to obtain data privacy because any variables declared within the IIFE cannot be accessed by the outside world. i.e, If you try to access variables with IIFE then it throws an error as below,\n\n    ```js\n\n//\n(function () {\nvar message = 'IIFE';\nconsole.log(message);\n})();\nconsole.log(message); //Error: message is not defined</code></pre></div>\n</li>\n<li>\n<p>What is the benefit of using modules</p>\n<p>There are a lot of benefits to using modules in favour of a sprawling. Some of the benefits are,</p>\n<ol>\n<li>Maintainability</li>\n<li>Reusability</li>\n<li>Namespacing</li>\n</ol>\n</li>\n<li>\n<p>What is memoization</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Memoization is a programming technique which attempts to increase a function's performance by caching its previously computed results. Each time a memoized function is called, its parameters are used to index the cache. If the data is present, then it can be returned, without executing the entire function. Otherwise the function is executed and then the result is added to the cache.\nLet's take an example of adding function with memoization,\n\n```js</code></pre></div>\n<p>//\nconst memoizAddition = () => {\nlet cache = {};\nreturn (value) => {\nif (value in cache) {\nconsole.log('Fetching from cache');\nreturn cache[value]; // Here, cache.value cannot be used as property name starts with the number which is not a valid JavaScript identifier. Hence, can only be accessed using the square bracket notation.\n} else {\nconsole.log('Calculating result');\nlet result = value + 20;\ncache[value] = result;\nreturn result;\n}\n};\n};\n// returned function from memoizAddition\nconst addition = memoizAddition();\nconsole.log(addition(20)); //output: 40 calculated\nconsole.log(addition(20)); //output: 40 cached</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is Hoisting</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialisation.\nLet's take a simple example of variable hoisting,\n\n```js</code></pre></div>\n<p>//\nconsole.log(message); //output : undefined\nvar message = 'The variable Has been hoisted';</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    The above code looks like as below to the interpreter,\n\n    ```js\n\n//\nvar message;\nconsole.log(message);\nmessage = 'The variable Has been hoisted';</code></pre></div>\n</li>\n<li>\n<p>What are classes in ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In ES6, Javascript classes are primarily syntactic sugar over JavaScript's existing prototype-based inheritance.\nFor example, the prototype based inheritance written in function expression as below,\n\n```js</code></pre></div>\n<p>//\nfunction Bike(model, color) {\nthis.model = model;\nthis.color = color;\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Bike.prototype.getDetails = function () {\n    return this.model + ' bike has' + this.color + ' color';\n};\n```\n\nWhereas ES6 classes can be defined as an alternative\n\n```js</code></pre></div>\n<p>//\nclass Bike {\nconstructor(color, model) {\nthis.color = color;\nthis.model = model;\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    getDetails() {\n        return this.model + ' bike has' + this.color + ' color';\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are closures</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A closure is the combination of a function and the lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function's variables. The closure has three scope chains\n\n1. Own scope where variables defined between its curly brackets\n2. Outer function's variables\n3. Global variables\n\nLet's take an example of closure concept,\n\n```js</code></pre></div>\n<p>//\nfunction Welcome(name) {\nvar greetingInfo = function (message) {\nconsole.log(message + ' ' + name);\n};\nreturn greetingInfo;\n}\nvar myFunction = Welcome('John');\nmyFunction('Welcome '); //Output: Welcome John\nmyFunction('Hello Mr.'); //output: Hello Mr.John</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    As per the above code, the inner function(i.e, greetingInfo) has access to the variables in the outer function scope(i.e, Welcome) even after the outer function has returned.</code></pre></div>\n</li>\n<li>\n<p>What are modules</p>\n<p>Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. Most of the JavaScript modules export an object literal, a function, or a constructor</p>\n</li>\n<li>\n<p>Why do you need modules</p>\n<p>Below are the list of benefits using modules in javascript ecosystem</p>\n<ol>\n<li>Maintainability</li>\n<li>Reusability</li>\n<li>Namespacing</li>\n</ol>\n</li>\n<li>\n<p>What is scope in javascript</p>\n<p>Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime. In other words, scope determines the visibility of variables and other resources in areas of your code.</p>\n</li>\n<li>\n<p>What is a service worker</p>\n<p>A Service worker is basically a script (JavaScript file) that runs in the background, separate from a web page and provides features that don't need a web page or user interaction. Some of the major features of service workers are Rich offline experiences(offline first web application development), periodic background syncs, push notifications, intercept and handle network requests and programmatically managing a cache of responses.</p>\n</li>\n<li>\n<p>How do you manipulate DOM using a service worker</p>\n<p>Service worker can't access the DOM directly. But it can communicate with the pages it controls by responding to messages sent via the <code class=\"language-text\">postMessage</code> interface, and those pages can manipulate the DOM.</p>\n</li>\n<li>\n<p>How do you reuse information across service worker restarts</p>\n<p>The problem with service worker is that it gets terminated when not in use, and restarted when it's next needed, so you cannot rely on global state within a service worker's <code class=\"language-text\">onfetch</code> and <code class=\"language-text\">onmessage</code> handlers. In this case, service workers will have access to IndexedDB API in order to persist and reuse across restarts.</p>\n</li>\n<li>\n<p>What is IndexedDB</p>\n<p>IndexedDB is a low-level API for client-side storage of larger amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data.</p>\n</li>\n<li>\n<p>What is web storage</p>\n<p>Web storage is an API that provides a mechanism by which browsers can store key/value pairs locally within the user's browser, in a much more intuitive fashion than using cookies. The web storage provides two mechanisms for storing data on the client.</p>\n<ol>\n<li><strong>Local storage:</strong> It stores data for current origin with no expiration date.</li>\n<li><strong>Session storage:</strong> It stores data for one session and the data is lost when the browser tab is closed.</li>\n</ol>\n</li>\n<li>\n<p>What is a post message</p>\n<p>Post message is a method that enables cross-origin communication between Window objects.(i.e, between a page and a pop-up that it spawned, or between a page and an iframe embedded within it). Generally, scripts on different pages are allowed to access each other if and only if the pages follow same-origin policy(i.e, pages share the same protocol, port number, and host).</p>\n</li>\n<li>\n<p>What is a Cookie</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A cookie is a piece of data that is stored on your computer to be accessed by your browser. Cookies are saved as key/value pairs.\nFor example, you can create a cookie named username as below,\n\n```js</code></pre></div>\n<p>//\ndocument.cookie = 'username=John';</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    ![Screenshot](images/cookie.png)</code></pre></div>\n</li>\n<li>\n<p>Why do you need a Cookie</p>\n<p>Cookies are used to remember information about the user profile(such as username). It basically involves two steps,</p>\n<ol>\n<li>When a user visits a web page, the user profile can be stored in a cookie.</li>\n<li>Next time the user visits the page, the cookie remembers the user profile.</li>\n</ol>\n</li>\n<li>\n<p>What are the options in a cookie</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are few below options available for a cookie,\n\n1. By default, the cookie is deleted when the browser is closed but you can change this behavior by setting expiry date (in UTC time).\n\n```js</code></pre></div>\n<p>//\ndocument.cookie = 'username=John; expires=Sat, 8 Jun 2019 12:00:00 UTC';</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    1. By default, the cookie belongs to a current page. But you can tell the browser what path the cookie belongs to using a path parameter.\n\n    ```js\n\n//\ndocument.cookie = 'username=John; path=/services';</code></pre></div>\n</li>\n<li>\n<p>How do you delete a cookie</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can delete a cookie by setting the expiry date as a passed date. You don't need to specify a cookie value in this case.\nFor example, you can delete a username cookie in the current page as below.\n\n```js</code></pre></div>\n<p>//\ndocument.cookie = 'username=; expires=Fri, 07 Jun 2019 00:00:00 UTC; path=/;';</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Note:** You should define the cookie path option to ensure that you delete the right cookie. Some browsers doesn't allow to delete a cookie unless you specify a path parameter.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between cookie, local storage and session storage</p>\n<p>Below are some of the differences between cookie, local storage and session storage,</p>\n<table>\n<thead>\n<tr>\n<th>Feature</th>\n<th>Cookie</th>\n<th>Local storage</th>\n<th>Session storage</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Accessed on client or server side</td>\n<td>Both server-side &#x26; client-side</td>\n<td>client-side only</td>\n<td>client-side only</td>\n</tr>\n<tr>\n<td>Lifetime</td>\n<td>As configured using Expires option</td>\n<td>until deleted</td>\n<td>until tab is closed</td>\n</tr>\n<tr>\n<td>SSL support</td>\n<td>Supported</td>\n<td>Not supported</td>\n<td>Not supported</td>\n</tr>\n<tr>\n<td>Maximum data size</td>\n<td>4KB</td>\n<td>5 MB</td>\n<td>5MB</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What is the main difference between localStorage and sessionStorage</p>\n<p>LocalStorage is the same as SessionStorage but it persists the data even when the browser is closed and reopened(i.e it has no expiration time) whereas in sessionStorage data gets cleared when the page session ends.</p>\n</li>\n<li>\n<p>How do you access web storage</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Window object implements the `WindowLocalStorage` and `WindowSessionStorage` objects which has `localStorage`(window.localStorage) and `sessionStorage`(window.sessionStorage) properties respectively. These properties create an instance of the Storage object, through which data items can be set, retrieved and removed for a specific domain and storage type (session or local).\nFor example, you can read and write on local storage objects as below\n\n```js</code></pre></div>\n<p>//\nlocalStorage.setItem('logo', document.getElementById('logo').value);\nlocalStorage.getItem('logo');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are the methods available on session storage</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The session storage provided methods for reading, writing and clearing the session data\n\n```js</code></pre></div>\n<p>//\n// Save data to sessionStorage\nsessionStorage.setItem('key', 'value');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Get saved data from sessionStorage\nlet data = sessionStorage.getItem('key');\n\n// Remove saved data from sessionStorage\nsessionStorage.removeItem('key');\n\n// Remove all saved data from sessionStorage\nsessionStorage.clear();\n```</code></pre></div>\n</li>\n<li>\n<p>What is a storage event and its event handler</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events.\nThe syntax would be as below\n\n```js</code></pre></div>\n<p>//\nwindow.onstorage = functionRef;</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    Let's take the example usage of onstorage event handler which logs the storage key and it's values\n\n    ```js\n\n//\nwindow.onstorage = function (e) {\nconsole.log('The ' + e.key + ' key has been changed from ' + e.oldValue + ' to ' + e.newValue + '.');\n};</code></pre></div>\n</li>\n<li>\n<p>Why do you need web storage</p>\n<p>Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Also, the information is never transferred to the server. Hence this is a more recommended approach than Cookies.</p>\n</li>\n<li>\n<p>How do you check web storage browser support</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to check browser support for localStorage and sessionStorage before using web storage,\n\n```js</code></pre></div>\n<p>//\nif (typeof Storage !== 'undefined') {\n// Code for localStorage/sessionStorage.\n} else {\n// Sorry! No Web Storage support..\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>How do you check web workers browser support</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to check browser support for web workers before using it\n\n```js</code></pre></div>\n<p>//\nif (typeof Worker !== 'undefined') {\n// code for Web worker support.\n} else {\n// Sorry! No Web Worker support..\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>Give an example of a web worker</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to follow below steps to start using web workers for counting example\n\n1. Create a Web Worker File: You need to write a script to increment the count value. Let's name it as counter.js\n\n```js</code></pre></div>\n<p>//\nlet i = 0;</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function timedCount() {\n    i = i + 1;\n    postMessage(i);\n    setTimeout('timedCount()', 500);\n}\n\ntimedCount();\n```\n\nHere postMessage() method is used to post a message back to the HTML page\n\n1. Create a Web Worker Object: You can create a web worker object by checking for browser support. Let's name this file as web_worker_example.js\n\n```js</code></pre></div>\n<p>//\nif (typeof w == 'undefined') {\nw = new Worker('counter.js');\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    and we can receive messages from web worker\n\n    ```js\n\n//\nw.onmessage = function (event) {\ndocument.getElementById('message').innerHTML = event.data;\n};</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. Terminate a Web Worker:\n   Web workers will continue to listen for messages (even after the external script is finished) until it is terminated. You can use the terminate() method to terminate listening to the messages.\n\n```js</code></pre></div>\n<p>//\nw.terminate();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    1. Reuse the Web Worker: If you set the worker variable to undefined you can reuse the code\n\n    ```js\n\n//\nw = undefined;</code></pre></div>\n</li>\n<li>\n<p>What are the restrictions of web workers on DOM</p>\n<p>WebWorkers don't have access to below javascript objects since they are defined in an external files</p>\n<ol>\n<li>Window object</li>\n<li>Document object</li>\n<li>Parent object</li>\n</ol>\n</li>\n<li>\n<p>What is a promise</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A promise is an object that may produce a single value some time in the future with either a resolved value or a reason that it's not resolved(for example, network error). It will be in one of the 3 possible states: fulfilled, rejected, or pending.\n\nThe syntax of Promise creation looks like below,\n\n```js</code></pre></div>\n<p>//\nconst promise = new Promise(function (resolve, reject) {\n// promise description\n});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    The usage of a promise would be as below,\n\n    ```js\n\n//\nconst promise = new Promise(\n(resolve) => {\nsetTimeout(() => {\nresolve(\"I'm a Promise!\");\n}, 5000);\n},\n(reject) => {}\n);\n\n    promise.then((value) => console.log(value));\n    ```\n\n    The action flow of a promise will be as below,\n\n    ![Screenshot](images/promises.png)</code></pre></div>\n</li>\n<li>\n<p>Why do you need a promise</p>\n<p>Promises are used to handle asynchronous operations. They provide an alternative approach for callbacks by reducing the callback hell and writing the cleaner code.</p>\n</li>\n<li>\n<p>What are the three states of promise</p>\n<p>Promises have three states:</p>\n<ol>\n<li><strong>Pending:</strong> This is an initial state of the Promise before an operation begins</li>\n<li><strong>Fulfilled:</strong> This state indicates that the specified operation was completed.</li>\n<li><strong>Rejected:</strong> This state indicates that the operation did not complete. In this case an error value will be thrown.</li>\n</ol>\n</li>\n<li>\n<p>What is a callback function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action.\nLet's take a simple example of how to use callback function\n\n```js</code></pre></div>\n<p>//\nfunction callbackFunction(name) {\nconsole.log('Hello ' + name);\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function outerFunction(callback) {\n    let name = prompt('Please enter your name.');\n    callback(name);\n}\n\nouterFunction(callbackFunction);\n```</code></pre></div>\n</li>\n<li>\n<p>Why do we need callbacks</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The callbacks are needed because javascript is an event driven language. That means instead of waiting for a response javascript will keep executing while listening for other events.\nLet's take an example with the first function invoking an API call(simulated by setTimeout) and the next function which logs the message.\n\n```js</code></pre></div>\n<p>//\nfunction firstFunction() {\n// Simulate a code delay\nsetTimeout(function () {\nconsole.log('First function called');\n}, 1000);\n}\nfunction secondFunction() {\nconsole.log('Second function called');\n}\nfirstFunction();\nsecondFunction();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Output;\n// Second function called\n// First function called\n```\n\nAs observed from the output, javascript didn't wait for the response of the first function and the remaining code block got executed. So callbacks are used in a way to make sure that certain code doesn't execute until the other code finishes execution.</code></pre></div>\n</li>\n<li>\n<p>What is a callback hell</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Callback Hell is an anti-pattern with multiple nested callbacks which makes code hard to read and debug when dealing with asynchronous logic. The callback hell looks like below,\n\n```js</code></pre></div>\n<p>//\nasync1(function(){\nasync2(function(){\nasync3(function(){\nasync4(function(){\n....\n});\n});\n});\n});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are server-sent events</p>\n<p>Server-sent events (SSE) is a server push technology enabling a browser to receive automatic updates from a server via HTTP connection without resorting to polling. These are a one way communications channel - events flow from server to client only. This has been used in Facebook/Twitter updates, stock price updates, news feeds etc.</p>\n</li>\n<li>\n<p>How do you receive server-sent event notifications</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The EventSource object is used to receive server-sent event notifications. For example, you can receive messages from server as below,\n\n```js</code></pre></div>\n<p>//\nif (typeof EventSource !== 'undefined') {\nvar source = new EventSource('sse_generator.js');\nsource.onmessage = function (event) {\ndocument.getElementById('output').innerHTML += event.data + '<br>';\n};\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>How do you check browser support for server-sent events</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can perform browser support for server-sent events before using it as below,\n\n```js</code></pre></div>\n<p>//\nif (typeof EventSource !== 'undefined') {\n// Server-sent events supported. Let's have some code here!\n} else {\n// No server-sent events supported\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are the events available for server sent events</p>\n<p>Below are the list of events available for server sent events\n| Event | Description |\n|---- | ---------\n| onopen | It is used when a connection to the server is opened |\n| onmessage | This event is used when a message is received |\n| onerror | It happens when an error occurs|</p>\n</li>\n<li>\n<p>What are the main rules of promise</p>\n<p>A promise must follow a specific set of rules,</p>\n<ol>\n<li>A promise is an object that supplies a standard-compliant <code class=\"language-text\">.then()</code> method</li>\n<li>A pending promise may transition into either fulfilled or rejected state</li>\n<li>A fulfilled or rejected promise is settled and it must not transition into any other state.</li>\n<li>Once a promise is settled, the value must not change.</li>\n</ol>\n</li>\n<li>\n<p>What is callback in callback</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can nest one callback inside in another callback to execute the actions sequentially one by one. This is known as callbacks in callbacks.\n\n```js</code></pre></div>\n<p>//\nloadScript('/script1.js', function (script) {\nconsole.log('first script is loaded');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    loadScript('/script2.js', function (script) {\n        console.log('second script is loaded');\n\n        loadScript('/script3.js', function (script) {\n            console.log('third script is loaded');\n            // after all scripts are loaded\n        });\n    });\n});\n```</code></pre></div>\n</li>\n<li>\n<p>What is promise chaining</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The process of executing a sequence of asynchronous tasks one after another using promises is known as Promise chaining. Let's take an example of promise chaining for calculating the final result,\n\n```js</code></pre></div>\n<p>//\nnew Promise(function (resolve, reject) {\nsetTimeout(() => resolve(1), 1000);\n})\n.then(function (result) {\nconsole.log(result); // 1\nreturn result _ 2;\n})\n.then(function (result) {\nconsole.log(result); // 2\nreturn result _ 3;\n})\n.then(function (result) {\nconsole.log(result); // 6\nreturn result * 4;\n});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    In the above handlers, the result is passed to the chain of .then() handlers with the below work flow,\n\n    1. The initial promise resolves in 1 second,\n    2. After that `.then` handler is called by logging the result(1) and then return a promise with the value of result \\* 2.\n    3. After that the value passed to the next `.then` handler by logging the result(2) and return a promise with result \\* 3.\n    4. Finally the value passed to the last `.then` handler by logging the result(6) and return a promise with result \\* 4.</code></pre></div>\n</li>\n<li>\n<p>What is promise.all</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.all is a promise that takes an array of promises as an input (an iterable), and it gets resolved when all the promises get resolved or any one of them gets rejected. For example, the syntax of promise.all method is below,\n\n```js</code></pre></div>\n<p>//\nPromise.all([Promise1, Promise2, Promise3]) .then(result) => { console.log(result) }) .catch(error => console.log(<code class=\"language-text\">Error in promises ${error}</code>))</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Note:** Remember that the order of the promises(output the result) is maintained as per input order.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the race method in promise</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.race() method will return the promise instance which is firstly resolved or rejected. Let's take an example of race() method where promise2 is resolved first\n\n```js</code></pre></div>\n<p>//\nvar promise1 = new Promise(function (resolve, reject) {\nsetTimeout(resolve, 500, 'one');\n});\nvar promise2 = new Promise(function (resolve, reject) {\nsetTimeout(resolve, 100, 'two');\n});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.race([promise1, promise2]).then(function (value) {\n    console.log(value); // \"two\" // Both promises will resolve, but promise2 is faster\n});\n```</code></pre></div>\n</li>\n<li>\n<p>What is a strict mode in javascript</p>\n<p>Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a \"strict\" operating context. This way it prevents certain actions from being taken and throws more exceptions. The literal expression <code class=\"language-text\">\"use strict\";</code> instructs the browser to use the javascript code in the Strict mode.</p>\n</li>\n<li>\n<p>Why do you need strict mode</p>\n<p>Strict mode is useful to write \"secure\" JavaScript by notifying \"bad syntax\" into real errors. For example, it eliminates accidentally creating a global variable by throwing an error and also throws an error for assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object.</p>\n</li>\n<li>\n<p>How do you declare strict mode</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The strict mode is declared by adding \"use strict\"; to the beginning of a script or a function.\nIf declared at the beginning of a script, it has global scope.\n\n```js</code></pre></div>\n<p>//\n'use strict';\nx = 3.14; // This will cause an error because x is not declared</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    and if you declare inside a function, it has local scope\n\n    ```js\n\n//\nx = 3.14; // This will not cause an error.\nmyFunction();\n\n    function myFunction() {\n        'use strict';\n        y = 3.14; // This will cause an error\n    }\n    ```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of double exclamation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The double exclamation or negation(!!) ensures the resulting type is a boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.\nFor example, you can test IE version using this expression as below,\n\n```js</code></pre></div>\n<p>//\nlet isIE8 = false;\nisIE8 = !!navigator.userAgent.match(/MSIE 8.0/);\nconsole.log(isIE8); // returns true or false</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    If you don't use this expression then it returns the original value.\n\n    ```js\n\n//\nconsole.log(navigator.userAgent.match(/MSIE 8.0/)); // returns either an Array or null</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**Note:** The expression !! is not an operator, but it is just twice of ! operator.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the delete operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The delete keyword is used to delete the property as well as its value.\n\n```js</code></pre></div>\n<p>//\nvar user = { name: 'John', age: 20 };\ndelete user.age;</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(user); // {name: \"John\"}\n```</code></pre></div>\n</li>\n<li>\n<p>What is the typeof operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the JavaScript typeof operator to find the type of a JavaScript variable. It returns the type of a variable or an expression.\n\n```js</code></pre></div>\n<p>//\ntypeof 'John Abraham'; // Returns \"string\"\ntypeof (1 + 2); // Returns \"number\"</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is undefined property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The undefined property indicates that a variable has not been assigned a value, or not declared at all. The type of undefined value is undefined too.\n\n```js</code></pre></div>\n<p>//\nvar user; // Value is undefined, type is undefined\nconsole.log(typeof user); //undefined</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    Any variable can be emptied by setting the value to undefined.\n\n    ```js\n\n//\nuser = undefined;</code></pre></div>\n</li>\n<li>\n<p>What is null value</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values. The type of null value is object.\nYou can empty the variable by setting the value to null.\n\n```js</code></pre></div>\n<p>//\nvar user = null;\nconsole.log(typeof user); //object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the difference between null and undefined</p>\n<p>Below are the main differences between null and undefined,</p>\n<table>\n<thead>\n<tr>\n<th>Null</th>\n<th>Undefined</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is an assignment value which indicates that variable points to no object.</td>\n<td>It is not an assignment value where a variable has been declared but has not yet been assigned a value.</td>\n</tr>\n<tr>\n<td>Type of null is object</td>\n<td>Type of undefined is undefined</td>\n</tr>\n<tr>\n<td>The null value is a primitive value that represents the null, empty, or non-existent reference.</td>\n<td>The undefined value is a primitive value used when a variable has not been assigned a value.</td>\n</tr>\n<tr>\n<td>Indicates the absence of a value for a variable</td>\n<td>Indicates absence of variable itself</td>\n</tr>\n<tr>\n<td>Converted to zero (0) while performing primitive operations</td>\n<td>Converted to NaN while performing primitive operations</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What is eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The eval() function evaluates JavaScript code represented as a string. The string can be a JavaScript expression, variable, statement, or sequence of statements.\n\n```js</code></pre></div>\n<p>//\nconsole.log(eval('1 + 2')); // 3</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the difference between window and document</p>\n<p>Below are the main differences between window and document,</p>\n<table>\n<thead>\n<tr>\n<th>Window</th>\n<th>Document</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is the root level element in any web page</td>\n<td>It is the direct child of the window object. This is also known as Document Object Model(DOM)</td>\n</tr>\n<tr>\n<td>By default window object is available implicitly in the page</td>\n<td>You can access it via window.document or document.</td>\n</tr>\n<tr>\n<td>It has methods like alert(), confirm() and properties like document, location</td>\n<td>It provides methods like getElementById, getElementsByTagName, createElement etc</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>How do you access history in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The window.history object contains the browser's history. You can load previous and next URLs in the history using back() and next() methods.\n\n```js</code></pre></div>\n<p>//\nfunction goBack() {\nwindow.history.back();\n}\nfunction goForward() {\nwindow.history.forward();\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Note:** You can also access history without window prefix.</code></pre></div>\n</li>\n<li>\n<p>How do you detect caps lock key turned on or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `mouseEvent getModifierState()` is used to return a boolean value that indicates whether the specified modifier key is activated or not. The modifiers such as CapsLock, ScrollLock and NumLock are activated when they are clicked, and deactivated when they are clicked again.\n\nLet's take an input element to detect the CapsLock on/off behavior with an example,\n\n```html\n&lt;input type=\"password\" onmousedown=\"enterInput(event)\" />\n\n&lt;p id=\"feedback\"></code></pre></div>\n</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script>\n    function enterInput(e) {\n        var flag = e.getModifierState('CapsLock');\n        if (flag) {\n            document.getElementById('feedback').innerHTML = 'CapsLock activated';\n        } else {\n            document.getElementById('feedback').innerHTML = 'CapsLock not activated';\n        }\n    }\n&lt;/script>\n```</code></pre></div>\n</li>\n<li>\n<p>What is isNaN</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The isNaN() function is used to determine whether a value is an illegal number (Not-a-Number) or not. i.e, This function returns true if the value equates to NaN. Otherwise it returns false.\n\n```js</code></pre></div>\n<p>//\nisNaN('Hello'); //true\nisNaN('100'); //false</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are the differences between undeclared and undefined variables</p>\n<p>Below are the major differences between undeclared and undefined variables,</p>\n<table>\n<thead>\n<tr>\n<th>undeclared</th>\n<th>undefined</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>These variables do not exist in a program and are not declared</td>\n<td>These variables declared in the program but have not assigned any value</td>\n</tr>\n<tr>\n<td>If you try to read the value of an undeclared variable, then a runtime error is encountered</td>\n<td>If you try to read the value of an undefined variable, an undefined value is returned.</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What are global variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Global variables are those that are available throughout the length of the code without any scope. The var keyword is used to declare a local variable but if you omit it then it will become global variable\n\n```js</code></pre></div>\n<p>//\nmsg = 'Hello'; // var is missing, it becomes global variable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are the problems with global variables</p>\n<p>The problem with global variables is the conflict of variable names of local and global scope. It is also difficult to debug and test the code that relies on global variables.</p>\n</li>\n<li>\n<p>What is NaN property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The NaN property is a global property that represents \"Not-a-Number\" value. i.e, It indicates that a value is not a legal number. It is very rare to use NaN in a program but it can be used as return value for few cases\n\n```js</code></pre></div>\n<p>//\nMath.sqrt(-1);\nparseInt('Hello');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of isFinite function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The isFinite() function is used to determine whether a number is a finite, legal number. It returns false if the value is +infinity, -infinity, or NaN (Not-a-Number), otherwise it returns true.\n\n```js</code></pre></div>\n<p>//\nisFinite(Infinity); // false\nisFinite(NaN); // false\nisFinite(-Infinity); // false</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">isFinite(100); // true\n```</code></pre></div>\n</li>\n<li>\n<p>What is an event flow</p>\n<p>Event flow is the order in which event is received on the web page. When you click an element that is nested in various other elements, before your click actually reaches its destination, or target element, it must trigger the click event for each of its parent elements first, starting at the top with the global window object.\nThere are two ways of event flow</p>\n<ol>\n<li>Top to Bottom(Event Capturing)</li>\n<li>Bottom to Top (Event Bubbling)</li>\n</ol>\n</li>\n<li>\n<p>What is event bubbling</p>\n<p>Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors (parents) of the target element in the same nesting hierarchy till it reaches the outermost DOM element.</p>\n</li>\n<li>\n<p>What is event capturing</p>\n<p>Event capturing is a type of event propagation where the event is first captured by the outermost element, and then successively triggers on the descendants (children) of the target element in the same nesting hierarchy till it reaches the innermost DOM element.</p>\n</li>\n<li>\n<p>How do you submit a form using JavaScript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can submit a form using `document.forms[0].submit()`. All the form input's information is submitted using onsubmit event handler\n\n```js</code></pre></div>\n<p>//\nfunction submit() {\ndocument.forms[0].submit();\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>How do you find operating system details</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The window.navigator object contains information about the visitor's browser OS details. Some of the OS properties are available under platform property,\n\n```js</code></pre></div>\n<p>//\nconsole.log(navigator.platform);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the difference between document load and DOMContentLoaded events</p>\n<p>The <code class=\"language-text\">DOMContentLoaded</code> event is fired when the initial HTML document has been completely loaded and parsed, without waiting for assets(stylesheets, images, and subframes) to finish loading. Whereas The load event is fired when the whole page has loaded, including all dependent resources(stylesheets, images).</p>\n</li>\n<li>\n<p>What is the difference between native, host and user objects</p>\n<p><code class=\"language-text\">Native objects</code> are objects that are part of the JavaScript language defined by the ECMAScript specification. For example, String, Math, RegExp, Object, Function etc core objects defined in the ECMAScript spec.\n<code class=\"language-text\">Host objects</code> are objects provided by the browser or runtime environment (Node). For example, window, XmlHttpRequest, DOM nodes etc are considered as host objects.\n<code class=\"language-text\">User objects</code> are objects defined in the javascript code. For example, User objects created for profile information.</p>\n</li>\n<li>\n<p>What are the tools or techniques used for debugging JavaScript code</p>\n<p>You can use below tools or techniques for debugging javascript</p>\n<ol>\n<li>Chrome Devtools</li>\n<li>debugger statement</li>\n<li>Good old console.log statement</li>\n</ol>\n</li>\n<li>\n<p>What are the pros and cons of promises over callbacks</p>\n<p>Below are the list of pros and cons of promises over callbacks,</p>\n<p><strong>Pros:</strong></p>\n<ol>\n<li>It avoids callback hell which is unreadable</li>\n<li>Easy to write sequential asynchronous code with .then()</li>\n<li>Easy to write parallel asynchronous code with Promise.all()</li>\n<li>Solves some of the common problems of callbacks(call the callback too late, too early, many times and swallow errors/exceptions)</li>\n</ol>\n<p><strong>Cons:</strong></p>\n<ol>\n<li>It makes little complex code</li>\n<li>You need to load a polyfill if ES6 is not supported</li>\n</ol>\n</li>\n<li>\n<p>What is the difference between an attribute and a property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Attributes are defined on the HTML markup whereas properties are defined on the DOM. For example, the below HTML element has 2 attributes type and value,\n\n```js</code></pre></div>\n<p>//\n<input type=\"text\" value=\"Name:\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    You can retrieve the attribute value as below,\n\n    ```js\n\n//\nconst input = document.querySelector('input');\nconsole.log(input.getAttribute('value')); // Good morning\nconsole.log(input.value); // Good morning</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">And after you change the value of the text field to \"Good evening\", it becomes like\n\n```js</code></pre></div>\n<p>//\nconsole.log(input.getAttribute('value')); // Good morning\nconsole.log(input.value); // Good evening</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is same-origin policy</p>\n<p>The same-origin policy is a policy that prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of URI scheme, hostname, and port number. If you enable this policy then it prevents a malicious script on one page from obtaining access to sensitive data on another web page using Document Object Model(DOM).</p>\n</li>\n<li>\n<p>What is the purpose of void 0</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Void(0) is used to prevent the page from refreshing. This will be helpful to eliminate the unwanted side-effect, because it will return the undefined primitive value. It is commonly used for HTML documents that use href=\"JavaScript:Void(0);\" within an `&lt;a>` element. i.e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression.\nFor example, the below link notify the message without reloading the page\n\n```js</code></pre></div>\n<p>//\n<a href=\"JavaScript:void(0);\" onclick=\"alert('Well done!')\">\nClick Me!\n</a></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>Is JavaScript a compiled or interpreted language</p>\n<p>JavaScript is an interpreted language, not a compiled language. An interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. Nowadays modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.</p>\n</li>\n<li>\n<p>Is JavaScript a case-sensitive language</p>\n<p>Yes, JavaScript is a case sensitive language. The language keywords, variables, function &#x26; object names, and any other identifiers must always be typed with a consistent capitalization of letters.</p>\n</li>\n<li>\n<p>Is there any relation between Java and JavaScript</p>\n<p>No, they are entirely two different programming languages and have nothing to do with each other. But both of them are Object Oriented Programming languages and like many other languages, they follow similar syntax for basic features(if, else, for, switch, break, continue etc).</p>\n</li>\n<li>\n<p>What are events</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Events are \"things\" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can `react` on these events. Some of the examples of HTML events are,\n\n     1. Web page has finished loading\n     2. Input field was changed\n     3. Button was clicked\n\n     Let's describe the behavior of click event for button element,\n\n     ```js\n\n//\n&lt;!doctype html>\n&lt;html>\n&lt;head>\n&lt;script>\nfunction greeting() {\nalert('Hello! Good morning');\n}\n&lt;/script>\n&lt;/head>\n&lt;body>\n&lt;button type=\"button\" onclick=\"greeting()\">Click me&lt;/button>\n&lt;/body>\n&lt;/html>\n```</code></pre></div>\n</li>\n<li>\n<p>Who created javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript was created by Brendan Eich in 1995 during his time at Netscape Communications. Initially it was developed under the name `Mocha`, but later the language was officially called `LiveScript` when it first shipped in beta releases of Netscape.</code></pre></div>\n</li>\n<li>\n<p>What is the use of preventDefault method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The preventDefault() method cancels the event if it is cancelable, meaning that the default action or behaviour that belongs to the event will not occur. For example, prevent form submission when clicking on submit button and prevent opening the page URL when clicking on hyperlink are some common use cases.\n\n     ```js\n\n//\ndocument.getElementById('link').addEventListener('click', function (event) {\nevent.preventDefault();\n});\n\n```\n\n     **Note:** Remember that not all events are cancelable.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the use of stopPropagation method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The stopPropagation method is used to stop the event from bubbling up the event chain. For example, the below nested divs with stopPropagation method prevents default event propagation when clicking on nested div(Div1)\n\n     ```js\n\n//\n&lt;p>Click DIV1 Element&lt;/p>\n&lt;div onclick=\"secondFunc()\">DIV 2\n&lt;div onclick=\"firstFunc(event)\">DIV 1&lt;/div>\n&lt;/div>\n\n     &lt;script>\n     function firstFunc(event) {\n       alert(\"DIV 1\");\n       event.stopPropagation();\n     }\n\n     function secondFunc() {\n       alert(\"DIV 2\");\n     }\n     &lt;/script>\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the steps involved in return false usage</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The return false statement in event handlers performs the below steps,\n\n1. First it stops the browser's default action or behaviour.\n2. It prevents the event from propagating the DOM\n3. Stops callback execution and returns immediately when called.</code></pre></div>\n</li>\n<li>\n<p>What is BOM</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Browser Object Model (BOM) allows JavaScript to \"talk to\" the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers.\n\n![Screenshot](images/bom.png)</code></pre></div>\n</li>\n<li>\n<p>What is the use of setTimeout</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,\n\n     ```js\n\n//\nsetTimeout(function () {\nconsole.log('Good morning');\n}, 2000);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the use of setInterval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,\n\n     ```js\n\n//\nsetInterval(function () {\nconsole.log('Good morning');\n}, 2000);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Why is JavaScript treated as Single threaded</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs.</code></pre></div>\n</li>\n<li>\n<p>What is an event delegation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it.\n\n     For example, if you wanted to detect field changes in inside a specific form, you can use event delegation technique,\n\n     ```js\n\n//\nvar form = document.querySelector('#registration-form');\n\n     // Listen for changes to fields inside the form\n     form.addEventListener(\n         'input',\n         function (event) {\n             // Log the field that was changed\n             console.log(event.target);\n         },\n         false\n     );\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is ECMAScript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. The first edition of ECMAScript was released in 1997.</code></pre></div>\n</li>\n<li>\n<p>What is JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language in the way objects are built in JavaScript.</code></pre></div>\n</li>\n<li>\n<p>What are the syntax rules of JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of syntax rules of JSON\n\n1. The data is in name/value pairs\n2. The data is separated by commas\n3. Curly braces hold objects\n4. Square brackets hold arrays</code></pre></div>\n</li>\n<li>\n<p>What is the purpose JSON stringify</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     When sending data to a web server, the data has to be in a string format. You can achieve this by converting JSON object into a string using stringify() method.\n\n     ```js\n\n//\nvar userJSON = { name: 'John', age: 31 };\nvar userString = JSON.stringify(user);\nconsole.log(userString); //\"{\"name\":\"John\",\"age\":31}\"\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you parse JSON string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     When receiving the data from a web server, the data is always in a string format. But you can convert this string value to a javascript object using parse() method.\n\n     ```js\n\n//\nvar userString = '{\"name\":\"John\",\"age\":31}';\nvar userJSON = JSON.parse(userString);\nconsole.log(userJSON); // {name: \"John\", age: 31}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">When exchanging data between a browser and a server, the data can only be text. Since JSON is text only, it can easily be sent to and from a server, and used as a data format by any programming language.</code></pre></div>\n</li>\n<li>\n<p>What are PWAs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Progressive web applications (PWAs) are a type of mobile app delivered through the web, built using common web technologies including HTML, CSS and JavaScript. These PWAs are deployed to servers, accessible through URLs, and indexed by search engines.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of clearTimeout method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The clearTimeout() function is used in javascript to clear the timeout which has been set by setTimeout()function before that. i.e, The return value of setTimeout() function is stored in a variable and it's passed into the clearTimeout() function to clear the timer.\n\n     For example, the below setTimeout method is used to display the message after 3 seconds. This timeout can be cleared by the clearTimeout() method.\n\n     ```js\n\n//\n&lt;script>\nvar msg;\nfunction greeting() {\nalert('Good morning');\n}\nfunction start() {\nmsg =setTimeout(greeting, 3000);\n\n     }\n\n     function stop() {\n         clearTimeout(msg);\n     }\n     &lt;/script>\n\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of clearInterval method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The clearInterval() function is used in javascript to clear the interval which has been set by setInterval() function. i.e, The return value returned by setInterval() function is stored in a variable and it's passed into the clearInterval() function to clear the interval.\n\n     For example, the below setInterval method is used to display the message for every 3 seconds. This interval can be cleared by the clearInterval() method.\n\n     ```js\n\n//\n&lt;script>\nvar msg;\nfunction greeting() {\nalert('Good morning');\n}\nfunction start() {\nmsg = setInterval(greeting, 3000);\n\n     }\n\n     function stop() {\n         clearInterval(msg);\n     }\n     &lt;/script>\n\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you redirect new page in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In vanilla javascript, you can redirect to a new page using the `location` property of window object. The syntax would be as follows,\n\n     ```js\n\n//\nfunction redirect() {\nwindow.location.href = 'newPage.html';\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether a string contains a substring</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are 3 possible ways to check whether a string contains a substring or not,\n\n     1. **Using includes:** ES6 provided `String.prototype.includes` method to test a string contains a substring\n\n     ```js\n\n//\nvar mainString = 'hello',\nsubString = 'hell';\nmainString.includes(subString);\n\n````\n\n     1. **Using indexOf:** In an ES5 or older environment, you can use `String.prototype.indexOf` which returns the index of a substring. If the index value is not equal to -1 then it means the substring exists in the main string.\n\n     ```js\n\n//\nvar mainString = 'hello',\nsubString = 'hell';\nmainString.indexOf(subString) !== -1;\n````\n\n     1. **Using RegEx:** The advanced solution is using Regular expression's test method(`RegExp.test`), which allows for testing for against regular expressions\n\n     ```js\n\n//\nvar mainString = 'hello',\nregex = /hell/;\nregex.test(mainString);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you validate an email in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead of the client side. Because the javascript can be disabled on the client side.\n\n     ```js\n\n//\nfunction validateEmail(email) {\nvar re =\n/^(([^&lt;>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^&lt;>()\\[\\]\\\\.,;:\\s@\"]+)\\*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\nreturn re.test(String(email).toLowerCase());\n}\n\n```\n\n     The above regular expression accepts unicode characters.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get the current url with javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `window.location.href` expression to get the current url path and you can use the same expression for updating the URL too. You can also use `document.URL` for read-only purposes but this solution has issues in FF.\n\n     ```js\n\n//\nconsole.log('location.href', window.location.href); // Returns full URL\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the various url properties of location object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The below `Location` object properties can be used to access URL components of the page,\n\n1. href - The entire URL\n2. protocol - The protocol of the URL\n3. host - The hostname and port of the URL\n4. hostname - The hostname of the URL\n5. port - The port number in the URL\n6. pathname - The path name of the URL\n7. search - The query portion of the URL\n8. hash - The anchor portion of the URL</code></pre></div>\n</li>\n<li>\n<p>How do get query string values in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string,\n\n     ```js\n\n//\nconst urlParams = new URLSearchParams(window.location.search);\nconst clientCode = urlParams.get('clientCode');\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check if a key exists in an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can check whether a key exists in an object or not using three approaches,\n\n     1. **Using in operator:** You can use the in operator whether a key exists in an object or not\n\n     ```js\n\n//\n'key' in obj;\n\n````\n\n     and If you want to check if a key doesn't exist, remember to use parenthesis,\n\n     ```js\n\n//\n!('key' in obj);\n````\n\n     1. **Using hasOwnProperty method:** You can use `hasOwnProperty` to particularly test for properties of the object instance (and not inherited properties)\n\n     ```js\n\n//\nobj.hasOwnProperty('key'); // true\n\n````\n\n     1. **Using undefined comparison:** If you access a non-existing property from an object, the result is undefined. Let's compare the properties against undefined to determine the existence of the property.\n\n     ```js\n\n//\nconst user = {\nname: 'John'\n};\n\n     console.log(user.name !== undefined); // true\n     console.log(user.nickName !== undefined); // false\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do you loop through or enumerate javascript object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `for-in` loop to loop through javascript object. You can also make sure that the key you get is an actual property of an object, and doesn't come from the prototype using `hasOwnProperty` method.\n\n     ```js\n\n//\nvar object = {\nk1: 'value1',\nk2: 'value2',\nk3: 'value3'\n};\n\n     for (var key in object) {\n         if (object.hasOwnProperty(key)) {\n             console.log(key + ' -> ' + object[key]); // k1 -> value1 ...\n         }\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you test for an empty object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are different solutions based on ECMAScript versions\n\n     1. **Using Object entries(ECMA 7+):** You can use object entries length along with constructor type.\n\n     ```js\n\n//\nObject.entries(obj).length === 0 &amp;&amp; obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well\n\n````\n\n     1. **Using Object keys(ECMA 5+):** You can use object keys length along with constructor type.\n\n     ```js\n\n//\nObject.keys(obj).length === 0 &amp;&amp; obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well\n````\n\n     1. **Using for-in with hasOwnProperty(Pre-ECMA 5):** You can use a for-in loop along with hasOwnProperty.\n\n     ```js\n\n//\nfunction isEmpty(obj) {\nfor (var prop in obj) {\nif (obj.hasOwnProperty(prop)) {\nreturn false;\n}\n}\n\n         return JSON.stringify(obj) === JSON.stringify({});\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is an arguments object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,\n\n     ```js\n\n//\nfunction sum() {\nvar total = 0;\nfor (var i = 0, len = arguments.length; i &lt; len; ++i) {\ntotal += arguments[i];\n}\nreturn total;\n}\n\n     sum(1, 2, 3); // returns 6\n     ```\n\n     **Note:** You can't apply array methods on arguments object. But you can convert into a regular array as below.\n\n     ```js\n\n//\nvar argsArray = Array.prototype.slice.call(arguments);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make first letter of the string in an uppercase</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can create a function which uses a chain of string methods such as charAt, toUpperCase and slice methods to generate a string with the first letter in uppercase.\n\n     ```js\n\n//\nfunction capitalizeFirstLetter(string) {\nreturn string.charAt(0).toUpperCase() + string.slice(1);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the pros and cons of for loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The for-loop is a commonly used iteration syntax in javascript. It has both pros and cons</code></pre></div>\n</li>\n</ol>\n<p>Pros</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> 1. Works on every environment\n 2. You can use break and continue flow control statements</code></pre></div>\n<p>Cons</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> 1. Too verbose\n 2. Imperative\n 3. You might face one-by-off errors</code></pre></div>\n<ol start=\"131\">\n<li>\n<p>How do you display the current date in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `new Date()` to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy\n\n     ```js\n\n//\nvar today = new Date();\nvar dd = String(today.getDate()).padStart(2, '0');\nvar mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!\nvar yyyy = today.getFullYear();\n\n     today = mm + '/' + dd + '/' + yyyy;\n     document.write(today);\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you compare two date objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You need to use date.getTime() method to compare date values instead of comparison operators (==, !=, ===, and !== operators)\n\n     ```js\n\n//\nvar d1 = new Date();\nvar d2 = new Date(d1);\nconsole.log(d1.getTime() === d2.getTime()); //True\nconsole.log(d1 === d2); // False\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check if a string starts with another string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use ECMAScript 6's `String.prototype.startsWith()` method to check if a string starts with another string or not. But it is not yet supported in all browsers. Let's see an example to see this usage,\n\n     ```js\n\n//\n'Good morning'.startsWith('Good'); // true\n'Good morning'.startsWith('morning'); // false\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you trim a string in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript provided a trim method on string types to trim any whitespaces present at the beginning or ending of the string.\n\n     ```js\n\n//\n' Hello World '.trim(); //Hello World\n\n````\n\n     If your browser(&lt;IE9) doesn't support this method then you can use below polyfill.\n\n     ```js\n\n//\nif (!String.prototype.trim) {\n(function () {\n// Make sure we trim BOM and NBSP\nvar rtrim = /^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g;\nString.prototype.trim = function () {\nreturn this.replace(rtrim, '');\n};\n})();\n}\n````</code></pre></div>\n</li>\n<li>\n<p>How do you add a key value pair in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are two possible solutions to add new properties to an object. Let's take a simple object to explain these solutions.\n\n     ```js\n\n//\nvar object = {\nkey1: value1,\nkey2: value2\n};\n\n````\n\n     1. **Using dot notation:** This solution is useful when you know the name of the property\n\n     ```js\n\n//\nobject.key3 = 'value3';\n````\n\n     1. **Using square bracket notation:** This solution is useful when the name of the property is dynamically determined.\n\n     ```js\n\n//\nobj['key3'] = 'value3';\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is the !-- notation represents a special operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No,that's not a special operator. But it is a combination of 2 standard operators one after the other,\n\n1. A logical not (!)\n2. A prefix decrement (--)\n\nAt first, the value decremented by one and then tested to see if it is equal to zero or not for determining the truthy/falsy value.</code></pre></div>\n</li>\n<li>\n<p>How do you assign default values to variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the logical or operator `||` in an assignment expression to provide a default value. The syntax looks like as below,\n\n     ```js\n\n//\nvar a = b || c;\n\n```\n\n     As per the above expression, variable 'a 'will get the value of 'c' only if 'b' is falsy (if is null, false, undefined, 0, empty string, or NaN), otherwise 'a' will get the value of 'b'.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define multiline strings</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can define multiline string literals using the '\\\\' character followed by line terminator.\n\n     ```js\n\n//\nvar str =\n'This is a \\\n very lengthy \\\n sentence!';\n\n```\n\n     But if you have a space after the '\\\\' character, the code will look exactly the same, but it will raise a SyntaxError.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an app shell model</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An application shell (or app shell) architecture is one way to build a Progressive Web App that reliably and instantly loads on your users' screens, similar to what you see in native applications. It is useful for getting some initial HTML to the screen fast without a network.</code></pre></div>\n</li>\n<li>\n<p>Can we define properties for functions</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, We can define properties for functions because functions are also objects.\n\n     ```js\n\n//\nfn = function (x) {\n//Function code goes here\n};\n\n     fn.name = 'John';\n\n     fn.profile = function (y) {\n         //Profile code goes here\n     };\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the way to find the number of parameters expected by a function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `function.length` syntax to find the number of parameters expected by a function. Let's take an example of `sum` function to calculate the sum of numbers,\n\n     ```js\n\n//\nfunction sum(num1, num2, num3, num4) {\nreturn num1 + num2 + num3 + num4;\n}\nsum.length; // 4 is the number of parameters expected.\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a polyfill</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A polyfill is a piece of JS code used to provide modern functionality on older browsers that do not natively support it. For example, Silverlight plugin polyfill can be used to mimic the functionality of an HTML Canvas element on Microsoft Internet Explorer 7.</code></pre></div>\n</li>\n<li>\n<p>What are break and continue statements</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The break statement is used to \"jump out\" of a loop. i.e, It breaks the loop and continues executing the code after the loop.\n\n     ```js\n\n//\nfor (i = 0; i &lt; 10; i++) {\nif (i === 5) {\nbreak;\n}\ntext += 'Number: ' + i + '&lt;br>';\n}\n\n````\n\n     The continue statement is used to \"jump over\" one iteration in the loop. i.e, It breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.\n\n     ```js\n\n//\nfor (i = 0; i &lt; 10; i++) {\nif (i === 5) {\ncontinue;\n}\ntext += 'Number: ' + i + '&lt;br>';\n}\n````</code></pre></div>\n</li>\n<li>\n<p>What are js labels</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The label statement allows us to name loops and blocks in JavaScript. We can then use these labels to refer back to the code later. For example, the below code with labels avoids printing the numbers when they are same,\n\n     ```js\n\n//\nvar i, j;\n\n     loop1: for (i = 0; i &lt; 3; i++) {\n         loop2: for (j = 0; j &lt; 3; j++) {\n             if (i === j) {\n                 continue loop1;\n             }\n             console.log('i = ' + i + ', j = ' + j);\n         }\n     }\n\n     // Output is:\n     //   \"i = 1, j = 0\"\n     //   \"i = 2, j = 0\"\n     //   \"i = 2, j = 1\"\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the benefits of keeping declarations at the top</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to keep all declarations at the top of each script or function. The benefits of doing this are,\n\n1. Gives cleaner code\n2. It provides a single place to look for local variables\n3. Easy to avoid unwanted global variables\n4. It reduces the possibility of unwanted re-declarations</code></pre></div>\n</li>\n<li>\n<p>What are the benefits of initializing variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to initialize variables because of the below benefits,\n\n1. It gives cleaner code\n2. It provides a single place to initialize variables\n3. Avoid undefined values in the code</code></pre></div>\n</li>\n<li>\n<p>What are the recommendations to create new object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is recommended to avoid creating new objects using `new Object()`. Instead you can initialize values based on it's type to create the objects.\n\n     1. Assign {} instead of new Object()\n     2. Assign \"\" instead of new String()\n     3. Assign 0 instead of new Number()\n     4. Assign false instead of new Boolean()\n     5. Assign [] instead of new Array()\n     6. Assign /()/ instead of new RegExp()\n     7. Assign function (){} instead of new Function()\n\n     You can define them as an example,\n\n     ```js\n\n//\nvar v1 = {};\nvar v2 = '';\nvar v3 = 0;\nvar v4 = false;\nvar v5 = [];\nvar v6 = /()/;\nvar v7 = function () {};\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define JSON arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JSON arrays are written inside square brackets and arrays contain javascript objects. For example, the JSON array of users would be as below,\n\n     ```js\n\n//\n\"users\":[\n{\"firstName\":\"John\", \"lastName\":\"Abrahm\"},\n{\"firstName\":\"Anna\", \"lastName\":\"Smith\"},\n{\"firstName\":\"Shane\", \"lastName\":\"Warn\"}\n]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you generate random integers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use Math.random() with Math.floor() to return random integers. For example, if you want generate random integers between 1 to 10, the multiplication factor should be 10,\n\n     ```js\n\n//\nMath.floor(Math.random() _ 10) + 1; // returns a random integer from 1 to 10\nMath.floor(Math.random() _ 100) + 1; // returns a random integer from 1 to 100\n\n```\n\n     **Note:** Math.random() returns a random number between 0 (inclusive), and 1 (exclusive)\n\n```</code></pre></div>\n</li>\n<li>\n<p>Can you write a random integers function to print integers with in a range</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, you can create a proper random function to return a random number between min and max (both included)\n\n     ```js\n\n//\nfunction randomInteger(min, max) {\nreturn Math.floor(Math.random() \\* (max - min + 1)) + min;\n}\nrandomInteger(1, 100); // returns a random integer from 1 to 100\nrandomInteger(1, 1000); // returns a random integer from 1 to 1000\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is tree shaking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tree shaking is a form of dead code elimination. It means that unused modules will not be included in the bundle during the build process and for that it relies on the static structure of ES2015 module syntax,( i.e. import and export). Initially this has been popularized by the ES2015 module bundler `rollup`.</code></pre></div>\n</li>\n<li>\n<p>What is the need of tree shaking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tree Shaking can significantly reduce the code size in any application. i.e, The less code we send over the wire the more performant the application will be. For example, if we just want to create a \"Hello World\" Application using SPA frameworks then it will take around a few MBs, but by tree shaking it can bring down the size to just a few hundred KBs. Tree shaking is implemented in Rollup and Webpack bundlers.</code></pre></div>\n</li>\n<li>\n<p>Is it recommended to use eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, it allows arbitrary code to be run which causes a security problem. As we know that the eval() function is used to run text as code. In most of the cases, it should not be necessary to use it.</code></pre></div>\n</li>\n<li>\n<p>What is a Regular Expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A regular expression is a sequence of characters that forms a search pattern. You can use this search pattern for searching data in a text. These can be used to perform all types of text search and text replace operations. Let's see the syntax format now,\n\n     ```js\n\n//\n/pattern/modifiers;\n\n````\n\n     For example, the regular expression or search pattern with case-insensitive username would be,\n\n     ```js\n\n//\n/John/i;\n````</code></pre></div>\n</li>\n<li>\n<p>What are the string methods available in Regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Regular Expressions has two string methods: search() and replace().\n     The search() method uses an expression to search for a match, and returns the position of the match.\n\n     ```js\n\n//\nvar msg = 'Hello John';\nvar n = msg.search(/John/i); // 6\n\n````\n\n     The replace() method is used to return a modified string where the pattern is replaced.\n\n     ```js\n\n//\nvar msg = 'Hello John';\nvar n = msg.replace(/John/i, 'Buttler'); // Hello Buttler\n````</code></pre></div>\n</li>\n<li>\n<p>What are modifiers in regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Modifiers can be used to perform case-insensitive and global searches. Let's list down some of the modifiers,\n\n     | Modifier | Description                                             |\n     |----------|---------------------------------------------------------|\n     | i        | Perform case-insensitive matching                       |\n     | g        | Perform a global match rather than stops at first match |\n     | m        | Perform multiline matching                              |\n\n     Let's take an example of global modifier,\n\n     ```js\n\n//\nvar text = 'Learn JS one by one';\nvar pattern = /one/g;\nvar result = text.match(pattern); // one,one\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are regular expression patterns</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Regular Expressions provide a group of patterns in order to match characters. Basically they are categorized into 3 types,\n\n1. **Brackets:** These are used to find a range of characters.\n   For example, below are some use cases,\n    1. [abc]: Used to find any of the characters between the brackets(a,b,c)\n    2. [0-9]: Used to find any of the digits between the brackets\n    3. (a|b): Used to find any of the alternatives separated with |\n2. **Metacharacters:** These are characters with a special meaning\n   For example, below are some use cases,\n    1. \\\\d: Used to find a digit\n    2. \\\\s: Used to find a whitespace character\n    3. \\\\b: Used to find a match at the beginning or ending of a word\n3. **Quantifiers:** These are useful to define quantities\n   For example, below are some use cases,\n    1. n+: Used to find matches for any string that contains at least one n\n    2. n\\*: Used to find matches for any string that contains zero or more occurrences of n\n    3. n?: Used to find matches for any string that contains zero or one occurrences of n</code></pre></div>\n</li>\n<li>\n<p>What is a RegExp object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     RegExp object is a regular expression object with predefined properties and methods. Let's see the simple usage of RegExp object,\n\n     ```js\n\n//\nvar regexp = new RegExp('\\\\w+');\nconsole.log(regexp);\n// expected output: /\\w+/\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you search a string for a pattern</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the test() method of regular expression in order to search a string for a pattern, and return true or false depending on the result.\n\n     ```js\n\n//\nvar pattern = /you/;\nconsole.log(pattern.test('How are you?')); //true\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of exec method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The purpose of exec method is similar to test method but it executes a search for a match in a specified string and returns a result array, or null instead of returning true/false.\n\n     ```js\n\n//\nvar pattern = /you/;\nconsole.log(pattern.exec('How are you?')); //[\"you\", index: 8, input: \"How are you?\", groups: undefined]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you change the style of a HTML element</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can change inline style or classname of a HTML element using javascript\n\n     1. **Using style property:** You can modify inline style using style property\n\n     ```js\n\n//\ndocument.getElementById('title').style.fontSize = '30px';\n\n````\n\n     1. **Using ClassName property:** It is easy to modify element class using className property\n\n     ```js\n\n//\ndocument.getElementById('title').className = 'custom-title';\n````</code></pre></div>\n</li>\n<li>\n<p>What would be the result of 1+2+'3'</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`.</code></pre></div>\n</li>\n<li>\n<p>What is a debugger statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.\n     For example, in the below function a debugger statement has been inserted. So\n     execution is paused at the debugger statement just like a breakpoint in the script source.\n\n     ```js\n\n//\nfunction getProfile() {\n// code goes here\ndebugger;\n// code goes here\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of breakpoints in debugging</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can set breakpoints in the javascript code once the debugger statement is executed and the debugger window pops up. At each breakpoint, javascript will stop executing, and let you examine the JavaScript values. After examining values, you can resume the execution of code using the play button.</code></pre></div>\n</li>\n<li>\n<p>Can I use reserved words as identifiers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     No, you cannot use the reserved words as variables, labels, object or function names. Let's see one simple example,\n\n     ```js\n\n//\nvar else = \"hello\"; // Uncaught SyntaxError: Unexpected token else\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect a mobile browser</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use regex which returns a true or false value depending on whether or not the user is browsing with a mobile.\n\n     ```js\n\n//\nwindow.mobilecheck = function () {\nvar mobileCheck = false;\n(function (a) {\nif (\n/(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(\na\n) ||\n/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i.test(\na.substr(0, 4)\n)\n)\nmobileCheck = true;\n})(navigator.userAgent || navigator.vendor || window.opera);\nreturn mobileCheck;\n};\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect a mobile browser without regexp</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can detect mobile browsers by simply running through a list of devices and checking if the useragent matches anything. This is an alternative solution for RegExp usage,\n\n     ```js\n\n//\nfunction detectmob() {\nif (\nnavigator.userAgent.match(/Android/i) ||\nnavigator.userAgent.match(/webOS/i) ||\nnavigator.userAgent.match(/iPhone/i) ||\nnavigator.userAgent.match(/iPad/i) ||\nnavigator.userAgent.match(/iPod/i) ||\nnavigator.userAgent.match(/BlackBerry/i) ||\nnavigator.userAgent.match(/Windows Phone/i)\n) {\nreturn true;\n} else {\nreturn false;\n}\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get the image width and height using JS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can programmatically get the image and check the dimensions(width and height) using Javascript.\n\n     ```js\n\n//\nvar img = new Image();\nimg.onload = function () {\nconsole.log(this.width + 'x' + this.height);\n};\nimg.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make synchronous HTTP request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Browsers provide an XMLHttpRequest object which can be used to make synchronous HTTP requests from JavaScript\n\n     ```js\n\n//\nfunction httpGet(theUrl) {\nvar xmlHttpReq = new XMLHttpRequest();\nxmlHttpReq.open('GET', theUrl, false); // false for synchronous request\nxmlHttpReq.send(null);\nreturn xmlHttpReq.responseText;\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make asynchronous HTTP request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Browsers provide an XMLHttpRequest object which can be used to make asynchronous HTTP requests from JavaScript by passing the 3rd parameter as true.\n\n     ```js\n\n//\nfunction httpGetAsync(theUrl, callback) {\nvar xmlHttpReq = new XMLHttpRequest();\nxmlHttpReq.onreadystatechange = function () {\nif (xmlHttpReq.readyState == 4 &amp;&amp; xmlHttpReq.status == 200) callback(xmlHttpReq.responseText);\n};\nxmlHttp.open('GET', theUrl, true); // true for asynchronous\nxmlHttp.send(null);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you convert date to another timezone in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the toLocaleString() method to convert dates in one timezone to another. For example, let's convert current date to British English timezone as below,\n\n     ```js\n\n//\nconsole.log(event.toLocaleString('en-GB', { timeZone: 'UTC' })); //29/06/2019, 09:56:00\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the properties used to get size of window</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use them combination of these properties to calculate the size of a window or document,\n\n     ```js\n\n//\nvar width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;\n\n     var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is a conditional operator in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for if statements.\n\n     ```js\n\n//\nvar isAuthenticated = false;\nconsole.log(isAuthenticated ? 'Hello, welcome' : 'Sorry, you are not authenticated'); //Sorry, you are not authenticated\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Can you apply chaining on conditional operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, you can apply chaining on conditional operators similar to if … else if … else if … else chain. The syntax is going to be as below,\n\n     ```js\n\n//\nfunction traceValue(someParam) {\nreturn condition1 ? value1 : condition2 ? value2 : condition3 ? value3 : value4;\n}\n\n     // The above conditional operator is equivalent to:\n\n     function traceValue(someParam) {\n         if (condition1) {\n             return value1;\n         } else if (condition2) {\n             return value2;\n         } else if (condition3) {\n             return value3;\n         } else {\n             return value4;\n         }\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the ways to execute javascript after page load</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can execute javascript after page load in many different ways,\n\n     1. **window.onload:**\n\n     ```js\n\n//\nwindow.onload = function ...\n\n````\n\n     1. **document.onload:**\n\n     ```js\n\n//\ndocument.onload = function ...\n````\n\n     1. **body onload:**\n\n     ```js\n\n//\n&lt;body onload=\"script();\">\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between proto and prototype</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `__proto__` object is the actual object that is used in the lookup chain to resolve methods, etc. Whereas `prototype` is the object that is used to build `__proto__` when you create an object with new\n\n     ```js\n\n//\nnew Employee().**proto** === Employee.prototype;\nnew Employee().prototype === undefined;\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Give an example where do you really need semicolon</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is recommended to use semicolons after every statement in JavaScript. For example, in the below case it throws an error \".. is not a function\" at runtime due to missing semicolon.\n\n     ```js\n\n//\n// define a function\nvar fn = (function () {\n//...\n})(\n// semicolon missing at this line\n\n         // then execute some code inside a closure\n         function () {\n             //...\n         }\n     )();\n     ```\n\n     and it will be interpreted as\n\n     ```js\n\n//\nvar fn = (function () {\n//...\n})(function () {\n//...\n})();\n\n```\n\n     In this case, we are passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. Hence, the second function will fail with a \"... is not a function\" error at runtime.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The **freeze()** method is used to freeze an object. Freezing an object does not allow adding new properties to an object,prevents from removing and prevents changing the enumerability, configurability, or writability of existing properties. i.e, It returns the passed object and does not create a frozen copy.\n\n     ```js\n\n//\nconst obj = {\nprop: 100\n};\n\n     Object.freeze(obj);\n     obj.prop = 200; // Throws an error in strict mode\n\n     console.log(obj.prop); //100\n     ```\n\n     **Note:** It causes a TypeError if the argument passed is not an object.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main benefits of using freeze method,\n\n1. It is used for freezing objects and arrays.\n2. It is used to make an object immutable.</code></pre></div>\n</li>\n<li>\n<p>Why do I need to use freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In the Object-oriented paradigm, an existing API contains certain elements that are not intended to be extended, modified, or re-used outside of their current context. Hence it works as the `final` keyword which is used in various languages.</code></pre></div>\n</li>\n<li>\n<p>How do you detect a browser language preference</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use navigator object to detect a browser language preference as below,\n\n     ```js\n\n//\nvar language =\n(navigator.languages &amp;&amp; navigator.languages[0]) || // Chrome / Firefox\nnavigator.language || // All browsers\nnavigator.userLanguage; // IE &lt;= 10\n\n     console.log(language);\n     ```</code></pre></div>\n</li>\n<li>\n<p>How to convert string to title case with javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function,\n\n     ```js\n\n//\nfunction toTitleCase(str) {\nreturn str.replace(/\\w\\S\\*/g, function (txt) {\nreturn txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();\n});\n}\ntoTitleCase('good morning john'); // Good Morning John\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect javascript disabled in the page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `&lt;noscript>` tag to detect javascript disabled or not. The code block inside `&lt;noscript>` gets executed when JavaScript is disabled, and is typically used to display alternative content when the page generated in JavaScript.\n\n     ```js\n\n//\n&lt;script type=\"javascript\">\n// JS related code goes here\n&lt;/script>\n&lt;noscript>\n&lt;a href=\"next_page.html?noJS=true\">JavaScript is disabled in the page. Please click Next Page&lt;/a>\n&lt;/noscript>\n```</code></pre></div>\n</li>\n<li>\n<p>What are various operators supported by javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An operator is capable of manipulating(mathematical and logical computations) a certain value or operand. There are various operators supported by JavaScript as below,\n\n1. **Arithmetic Operators:** Includes + (Addition),- (Subtraction), \\* (Multiplication), / (Division), % (Modulus), + + (Increment) and - - (Decrement)\n2. **Comparison Operators:** Includes = =(Equal),!= (Not Equal), ===(Equal with type), > (Greater than),> = (Greater than or Equal to),&lt; (Less than),&lt;= (Less than or Equal to)\n3. **Logical Operators:** Includes &amp;&amp;(Logical AND),||(Logical OR),!(Logical NOT)\n4. **Assignment Operators:** Includes = (Assignment Operator), += (Add and Assignment Operator), - = (Subtract and Assignment Operator), \\*= (Multiply and Assignment), /= (Divide and Assignment), %= (Modules and Assignment)\n5. **Ternary Operators:** It includes conditional(: ?) Operator\n6. **typeof Operator:** It uses to find type of variable. The syntax looks like `typeof variable`</code></pre></div>\n</li>\n<li>\n<p>What is a rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Rest parameter is an improved way to handle function parameters which allows us to represent an indefinite number of arguments as an array. The syntax would be as below,\n\n     ```js\n\n//\nfunction f(a, b, ...theArgs) {\n// ...\n}\n\n````\n\n     For example, let's take a sum example to calculate on dynamic number of parameters,\n\n     ```js\n\n//\nfunction total(…args){\nlet sum = 0;\nfor(let i of args){\nsum+=i;\n}\nreturn sum;\n}\nconsole.log(fun(1,2)); //3\nconsole.log(fun(1,2,3)); //6\nconsole.log(fun(1,2,3,4)); //13\nconsole.log(fun(1,2,3,4,5)); //15\n````\n\n     **Note:** Rest parameter is added in ES2015 or ES6</code></pre></div>\n</li>\n<li>\n<p>What happens if you do not use rest parameter as a last argument</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The rest parameter should be the last argument, as its job is to collect all the remaining arguments into an array. For example, if you define a function like below it doesn't make any sense and will throw an error.\n\n     ```js\n\n//\nfunction someFunc(a,…b,c){\n//You code goes here\nreturn;\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the bitwise operators available in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of bitwise logical operators used in JavaScript\n\n1. Bitwise AND ( &amp; )\n2. Bitwise OR ( | )\n3. Bitwise XOR ( ^ )\n4. Bitwise NOT ( ~ )\n5. Left Shift ( &lt;&lt; )\n6. Sign Propagating Right Shift ( >> )\n7. Zero fill Right Shift ( >>> )</code></pre></div>\n</li>\n<li>\n<p>What is a spread operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. Let's take an example to see this behavior,\n\n     ```js\n\n//\nfunction calculateSum(x, y, z) {\nreturn x + y + z;\n}\n\n     const numbers = [1, 2, 3];\n\n     console.log(calculateSum(...numbers)); // 6\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you determine whether object is frozen or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Object.isFrozen() method is used to determine if an object is frozen or not.An object is frozen if all of the below conditions hold true,\n\n     1. If it is not extensible.\n     2. If all of its properties are non-configurable.\n     3. If all its data properties are non-writable.\n        The usage is going to be as follows,\n\n     ```js\n\n//\nconst object = {\nproperty: 'Welcome JS world'\n};\nObject.freeze(object);\nconsole.log(Object.isFrozen(object));\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you determine two values same or not using object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.is() method determines whether two values are the same value. For example, the usage with different types of values would be,\n\n     ```js\n\n//\nObject.is('hello', 'hello'); // true\nObject.is(window, window); // true\nObject.is([], []); // false\n\n```\n\n     Two values are the same if one of the following holds:\n\n     1. both undefined\n     2. both null\n     3. both true or both false\n     4. both strings of the same length with the same characters in the same order\n     5. both the same object (means both object have same reference)\n     6. both numbers and\n        both +0\n        both -0\n        both NaN\n        both non-zero and both not NaN and both have the same value.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of using object is method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the applications of Object's `is` method are follows,\n\n1. It is used for comparison of two strings.\n2. It is used for comparison of two numbers.\n3. It is used for comparing the polarity of two numbers.\n4. It is used for comparison of two objects.</code></pre></div>\n</li>\n<li>\n<p>How do you copy properties from one object to other</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the Object.assign() method which is used to copy the values and properties from one or more source objects to a target object. It returns the target object which has properties and values copied from the target object. The syntax would be as below,\n\n     ```js\n\n//\nObject.assign(target, ...sources);\n\n````\n\n     Let's take example with one source and one target object,\n\n     ```js\n\n//\nconst target = { a: 1, b: 2 };\nconst source = { b: 3, c: 4 };\n\n     const returnedTarget = Object.assign(target, source);\n\n     console.log(target); // { a: 1, b: 3, c: 4 }\n\n     console.log(returnedTarget); // { a: 1, b: 3, c: 4 }\n     ```\n\n     As observed in the above code, there is a common property(`b`) from source to target so it's value has been overwritten.\n\n````</code></pre></div>\n</li>\n<li>\n<p>What are the applications of assign method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the some of main applications of Object.assign() method,\n\n1. It is used for cloning an object.\n2. It is used to merge objects with the same properties.</code></pre></div>\n</li>\n<li>\n<p>What is a proxy object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Proxy object is used to define custom behavior for fundamental operations such as property lookup, assignment, enumeration, function invocation, etc. The syntax would be as follows,\n\n     ```js\n\n//\nvar p = new Proxy(target, handler);\n\n````\n\n     Let's take an example of proxy object,\n\n     ```js\n\n//\nvar handler = {\nget: function (obj, prop) {\nreturn prop in obj ? obj[prop] : 100;\n}\n};\n\n     var p = new Proxy({}, handler);\n     p.a = 10;\n     p.b = null;\n\n     console.log(p.a, p.b); // 10, null\n     console.log('c' in p, p.c); // false, 100\n     ```\n\n     In the above code, it uses `get` handler which define the behavior of the proxy when an operation is performed on it\n\n````</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of seal method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The **Object.seal()** method is used to seal an object, by preventing new properties from being added to it and marking all existing properties as non-configurable. But values of present properties can still be changed as long as they are writable. Let's see the below example to understand more about seal() method\n\n     ```js\n\n//\nconst object = {\nproperty: 'Welcome JS world'\n};\nObject.seal(object);\nobject.property = 'Welcome to object world';\nconsole.log(Object.isSealed(object)); // true\ndelete object.property; // You cannot delete when sealed\nconsole.log(object.property); //Welcome to object world\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the applications of seal method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main applications of Object.seal() method,\n\n1. It is used for sealing objects and arrays.\n2. It is used to make an object immutable.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between freeze and seal methods</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If an object is frozen using the Object.freeze() method then its properties become immutable and no changes can be made in them whereas if an object is sealed using the Object.seal() method then the changes can be made in the existing properties of the object.</code></pre></div>\n</li>\n<li>\n<p>How do you determine if an object is sealed or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.isSealed() method is used to determine if an object is sealed or not. An object is sealed if all of the below conditions hold true\n\n     1. If it is not extensible.\n     2. If all of its properties are non-configurable.\n     3. If it is not removable (but not necessarily non-writable).\n        Let's see it in the action\n\n     ```js\n\n//\nconst object = {\nproperty: 'Hello, Good morning'\n};\n\n     Object.seal(object); // Using seal() method to seal the object\n\n     console.log(Object.isSealed(object)); // checking whether the object is sealed or not\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you get enumerable key and value pairs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.entries() method is used to return an array of a given object's own enumerable string-keyed property [key, value] pairs, in the same order as that provided by a for...in loop. Let's see the functionality of object.entries() method in an example,\n\n     ```js\n\n//\nconst object = {\na: 'Good morning',\nb: 100\n};\n\n     for (let [key, value] of Object.entries(object)) {\n         console.log(`${key}: ${value}`); // a: 'Good morning'\n         // b: 100\n     }\n     ```\n\n     **Note:** The order is not guaranteed as object defined.</code></pre></div>\n</li>\n<li>\n<p>What is the main difference between Object.values and Object.entries method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.values() method's behavior is similar to Object.entries() method but it returns an array of values instead [key,value] pairs.\n\n     ```js\n\n//\nconst object = {\na: 'Good morning',\nb: 100\n};\n\n     for (let value of Object.values(object)) {\n         console.log(`${value}`); // 'Good morning'\n         100;\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>How can you get the list of keys of any object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.keys()` method which is used to return an array of a given object's own property names, in the same order as we get with a normal loop. For example, you can get the keys of a user object,\n\n     ```js\n\n//\nconst user = {\nname: 'John',\ngender: 'male',\nage: 40\n};\n\n     console.log(Object.keys(user)); //['name', 'gender', 'age']\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you create an object with prototype</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.create() method is used to create a new object with the specified prototype object and properties. i.e, It uses an existing object as the prototype of the newly created object. It returns a new object with the specified prototype object and properties.\n\n     ```js\n\n//\nconst user = {\nname: 'John',\nprintInfo: function () {\nconsole.log(`My name is ${this.name}.`);\n}\n};\n\n     const admin = Object.create(user);\n\n     admin.name = 'Nick'; // Remember that \"name\" is a property set on \"admin\" but not on \"user\" object\n\n     admin.printInfo(); // My name is Nick\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is a WeakSet</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     WeakSet is used to store a collection of weakly(weak references) held objects. The syntax would be as follows,\n\n     ```js\n\n//\nnew WeakSet([iterable]);\n\n````\n\n     Let's see the below example to explain it's behavior,\n\n     ```js\n\n//\nvar ws = new WeakSet();\nvar user = {};\nws.add(user);\nws.has(user); // true\nws.delete(user); // removes user from the set\nws.has(user); // false, user has been removed\n````</code></pre></div>\n</li>\n<li>\n<p>What are the differences between WeakSet and Set</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference is that references to objects in Set are strong while references to objects in WeakSet are weak. i.e, An object in WeakSet can be garbage collected if there is no other reference to it.\nOther differences are,\n\n1. Sets can store any value Whereas WeakSets can store only collections of objects\n2. WeakSet does not have size property unlike Set\n3. WeakSet does not have methods such as clear, keys, values, entries, forEach.\n4. WeakSet is not iterable.</code></pre></div>\n</li>\n<li>\n<p>List down the collection of methods available on WeakSet</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Below are the list of methods available on WeakSet,\n\n     1. add(value): A new object is appended with the given value to the weakset\n     2. delete(value): Deletes the value from the WeakSet collection.\n     3. has(value): It returns true if the value is present in the WeakSet Collection, otherwise it returns false.\n\n     Let's see the functionality of all the above methods in an example,\n\n     ```js\n\n//\nvar weakSetObject = new WeakSet();\nvar firstObject = {};\nvar secondObject = {};\n// add(value)\nweakSetObject.add(firstObject);\nweakSetObject.add(secondObject);\nconsole.log(weakSetObject.has(firstObject)); //true\nweakSetObject.delete(secondObject);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a WeakMap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced. In this case, keys must be objects and the values can be arbitrary values. The syntax is looking like as below,\n\n     ```js\n\n//\nnew WeakMap([iterable]);\n\n````\n\n     Let's see the below example to explain it's behavior,\n\n     ```js\n\n//\nvar ws = new WeakMap();\nvar user = {};\nws.set(user);\nws.has(user); // true\nws.delete(user); // removes user from the map\nws.has(user); // false, user has been removed\n````</code></pre></div>\n</li>\n<li>\n<p>What are the differences between WeakMap and Map</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference is that references to key objects in Map are strong while references to key objects in WeakMap are weak. i.e, A key object in WeakMap can be garbage collected if there is no other reference to it.\nOther differences are,\n\n1. Maps can store any key type Whereas WeakMaps can store only collections of key objects\n2. WeakMap does not have size property unlike Map\n3. WeakMap does not have methods such as clear, keys, values, entries, forEach.\n4. WeakMap is not iterable.</code></pre></div>\n</li>\n<li>\n<p>List down the collection of methods available on WeakMap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Below are the list of methods available on WeakMap,\n\n     1. set(key, value): Sets the value for the key in the WeakMap object. Returns the WeakMap object.\n     2. delete(key): Removes any value associated to the key.\n     3. has(key): Returns a Boolean asserting whether a value has been associated to the key in the WeakMap object or not.\n     4. get(key): Returns the value associated to the key, or undefined if there is none.\n        Let's see the functionality of all the above methods in an example,\n\n     ```js\n\n//\nvar weakMapObject = new WeakMap();\nvar firstObject = {};\nvar secondObject = {};\n// set(key, value)\nweakMapObject.set(firstObject, 'John');\nweakMapObject.set(secondObject, 100);\nconsole.log(weakMapObject.has(firstObject)); //true\nconsole.log(weakMapObject.get(firstObject)); // John\nweakMapObject.delete(secondObject);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of uneval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The uneval() is an inbuilt function which is used to create a string representation of the source code of an Object. It is a top-level function and is not associated with any object. Let's see the below example to know more about it's functionality,\n\n     ```js\n\n//\nvar a = 1;\nuneval(a); // returns a String containing 1\nuneval(function user() {}); // returns \"(function user(){})\"\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you encode an URL</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The encodeURI() function is used to encode complete URI which has special characters except (, / ? : @ &amp; = + $ #) characters.\n\n     ```js\n\n//\nvar uri = 'https://mozilla.org/?x=шеллы';\nvar encoded = encodeURI(uri);\nconsole.log(encoded); // https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you decode an URL</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The decodeURI() function is used to decode a Uniform Resource Identifier (URI) previously created by encodeURI().\n\n     ```js\n\n//\nvar uri = 'https://mozilla.org/?x=шеллы';\nvar encoded = encodeURI(uri);\nconsole.log(encoded); // https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B\ntry {\nconsole.log(decodeURI(encoded)); // \"https://mozilla.org/?x=шеллы\"\n} catch (e) {\n// catches a malformed URI\nconsole.error(e);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you print the contents of web page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The window object provided a print() method which is used to print the contents of the current window. It opens a Print dialog box which lets you choose between various printing options. Let's see the usage of print method in an example,\n\n```html\n&lt;input type=\"button\" value=\"Print\" onclick=\"window.print()\" />\n```\n\n**Note:** In most browsers, it will block while the print dialog is open.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between uneval and eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `uneval` function returns the source of a given object; whereas the `eval` function does the opposite, by evaluating that source code in a different memory area. Let's see an example to clarify the difference,\n\n     ```js\n\n//\nvar msg = uneval(function greeting() {\nreturn 'Hello, Good morning';\n});\nvar greeting = eval(msg);\ngreeting(); // returns \"Hello, Good morning\"\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an anonymous function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An anonymous function is a function without a name! Anonymous functions are commonly assigned to a variable name or used as a callback function. The syntax would be as below,\n\n     ```js\n\n//\nfunction (optionalParameters) {\n//do something\n}\n\n     const myFunction = function(){ //Anonymous function assigned to a variable\n       //do something\n     };\n\n     [1, 2, 3].map(function(element){ //Anonymous function used as a callback function\n       //do something\n     });\n     ```\n\n     Let's see the above anonymous function in an example,\n\n     ```js\n\n//\nvar x = function (a, b) {\nreturn a \\* b;\n};\nvar z = x(5, 10);\nconsole.log(z); // 50\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the precedence order between local and global variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A local variable takes precedence over a global variable with the same name. Let's see this behavior in an example.\n\n     ```js\n\n//\nvar msg = 'Good morning';\nfunction greeting() {\nmsg = 'Good Evening';\nconsole.log(msg);\n}\ngreeting();\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are javascript accessors</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ECMAScript 5 introduced javascript object accessors or computed properties through getters and setters. Getters uses the `get` keyword whereas Setters uses the `set` keyword.\n\n     ```js\n\n//\nvar user = {\nfirstName: \"John\",\nlastName : \"Abraham\",\nlanguage : \"en\",\nget lang() {\nreturn this.language;\n}\nset lang(lang) {\nthis.language = lang;\n}\n};\nconsole.log(user.lang); // getter access lang as en\nuser.lang = 'fr';\nconsole.log(user.lang); // setter used to set lang as fr\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define property on Object constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.defineProperty() static method is used to define a new property directly on an object, or modify an existing property on an object, and returns the object. Let's see an example to know how to define property,\n\n     ```js\n\n//\nconst newObject = {};\n\n     Object.defineProperty(newObject, 'newProperty', {\n         value: 100,\n         writable: false\n     });\n\n     console.log(newObject.newProperty); // 100\n\n     newObject.newProperty = 200; // It throws an error in strict mode due to writable setting\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between get and defineProperty</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both have similar results until unless you use classes. If you use `get` the property will be defined on the prototype of the object whereas using `Object.defineProperty()` the property will be defined on the instance it is applied to.</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of Getters and Setters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of benefits of Getters and Setters,\n\n1. They provide simpler syntax\n2. They are used for defining computed properties, or accessors in JS.\n3. Useful to provide equivalence relation between properties and methods\n4. They can provide better data quality\n5. Useful for doing things behind the scenes with the encapsulated logic.</code></pre></div>\n</li>\n<li>\n<p>Can I add getters and setters using defineProperty method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, You can use the `Object.defineProperty()` method to add Getters and Setters. For example, the below counter object uses increment, decrement, add and subtract properties,\n\n     ```js\n\n//\nvar obj = { counter: 0 };\n\n     // Define getters\n     Object.defineProperty(obj, 'increment', {\n         get: function () {\n             this.counter++;\n         }\n     });\n     Object.defineProperty(obj, 'decrement', {\n         get: function () {\n             this.counter--;\n         }\n     });\n\n     // Define setters\n     Object.defineProperty(obj, 'add', {\n         set: function (value) {\n             this.counter += value;\n         }\n     });\n     Object.defineProperty(obj, 'subtract', {\n         set: function (value) {\n             this.counter -= value;\n         }\n     });\n\n     obj.add = 10;\n     obj.subtract = 5;\n     console.log(obj.increment); //6\n     console.log(obj.decrement); //5\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of switch-case</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The switch case statement in JavaScript is used for decision making purposes. In a few cases, using the switch case statement is going to be more convenient than if-else statements. The syntax would be as below,\n\n     ```js\n\n//\nswitch (expression)\n{\ncase value1:\nstatement1;\nbreak;\ncase value2:\nstatement2;\nbreak;\n.\n.\ncase valueN:\nstatementN;\nbreak;\ndefault:\nstatementDefault;\n}\n\n```\n\n     The above multi-way branch statement provides an easy way to dispatch execution to different parts of code based on the value of the expression.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the conventions to be followed for the usage of switch case</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of conventions should be taken care,\n\n1. The expression can be of type either number or string.\n2. Duplicate values are not allowed for the expression.\n3. The default statement is optional. If the expression passed to switch does not match with any case value then the statement within default case will be executed.\n4. The break statement is used inside the switch to terminate a statement sequence.\n5. The break statement is optional. But if it is omitted, the execution will continue on into the next case.</code></pre></div>\n</li>\n<li>\n<p>What are primitive data types</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A primitive data type is data that has a primitive value (which has no properties or methods). There are 7 types of primitive data types.\n\n1. string\n2. number\n3. boolean\n4. null\n5. undefined\n6. bigint\n7. symbol</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to access object properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are 3 possible ways for accessing the property of an object.\n\n     1. **Dot notation:** It uses dot for accessing the properties\n\n     ```js\n\n//\nobjectName.property;\n\n````\n\n     1. **Square brackets notation:** It uses square brackets for property access\n\n     ```js\n\n//\nobjectName['property'];\n````\n\n     1. **Expression notation:** It uses expression in the square brackets\n\n     ```js\n\n//\nobjectName[expression];\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the function parameter rules</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript functions follow below rules for parameters,\n\n     1. The function definitions do not specify data types for parameters.\n     2. Do not perform type checking on the passed arguments.\n     3. Do not check the number of arguments received.\n        i.e, The below function follows the above rules,\n\n     ```js\n\n//\nfunction functionName(parameter1, parameter2, parameter3) {\nconsole.log(parameter1); // 1\n}\nfunctionName(1);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An error object is a built in error object that provides error information when an error occurs. It has two properties: name and message. For example, the below function logs error details,\n\n     ```js\n\n//\ntry {\ngreeting('Welcome');\n} catch (err) {\nconsole.log(err.name + '&lt;br>' + err.message);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>When you get a syntax error</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A SyntaxError is thrown if you try to evaluate code with a syntax error. For example, the below missing quote for the function parameter throws a syntax error\n\n     ```js\n\n//\ntry {\neval(\"greeting('welcome)\"); // Missing ' will produce an error\n} catch (err) {\nconsole.log(err.name);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different error names from error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are 6 different types of error names returned from error object,\n| Error Name | Description |\n|---- | ---------\n| EvalError | An error has occurred in the eval() function |\n| RangeError | An error has occurred with a number \"out of range\" |\n| ReferenceError | An error due to an illegal reference|\n| SyntaxError | An error due to a syntax error|\n| TypeError | An error due to a type error |\n| URIError | An error due to encodeURI() |</code></pre></div>\n</li>\n<li>\n<p>What are the various statements in error handling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of statements used in an error handling,\n\n1. **try:** This statement is used to test a block of code for errors\n2. **catch:** This statement is used to handle the error\n3. **throw:** This statement is used to create custom errors.\n4. **finally:** This statement is used to execute code after try and catch regardless of the result.</code></pre></div>\n</li>\n<li>\n<p>What are the two types of loops in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. **Entry Controlled loops:** In this kind of loop type, the test condition is tested before entering the loop body. For example, For Loop and While Loop comes under this category.\n2. **Exit Controlled Loops:** In this kind of loop type, the test condition is tested or evaluated at the end of the loop body. i.e, the loop body will execute at least once irrespective of test condition true or false. For example, do-while loop comes under this category.</code></pre></div>\n</li>\n<li>\n<p>What is nodejs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Node.js is a server-side platform built on Chrome's JavaScript runtime for easily building fast and scalable network applications. It is an event-based, non-blocking, asynchronous I/O runtime that uses Google's V8 JavaScript engine and libuv library.</code></pre></div>\n</li>\n<li>\n<p>What is an Intl object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. It provides access to several constructors and language sensitive functions.</code></pre></div>\n</li>\n<li>\n<p>How do you perform language specific date and time formatting</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Intl.DateTimeFormat` object which is a constructor for objects that enable language-sensitive date and time formatting. Let's see this behavior with an example,\n\n     ```js\n\n//\nvar date = new Date(Date.UTC(2019, 07, 07, 3, 0, 0));\nconsole.log(new Intl.DateTimeFormat('en-GB').format(date)); // 07/08/2019\nconsole.log(new Intl.DateTimeFormat('en-AU').format(date)); // 07/08/2019\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an Iterator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An iterator is an object which defines a sequence and a return value upon its termination. It implements the Iterator protocol with a `next()` method which returns an object with two properties: `value` (the next value in the sequence) and `done` (which is true if the last value in the sequence has been consumed).</code></pre></div>\n</li>\n<li>\n<p>How does synchronous iteration works</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Synchronous iteration was introduced in ES6 and it works with below set of components,\n\n     **Iterable:** It is an object which can be iterated over via a method whose key is Symbol.iterator.\n     **Iterator:** It is an object returned by invoking `[Symbol.iterator]()` on an iterable. This iterator object wraps each iterated element in an object and returns it via `next()` method one by one.\n     **IteratorResult:** It is an object returned by `next()` method. The object contains two properties; the `value` property contains an iterated element and the `done` property determines whether the element is the last element or not.\n\n     Let's demonstrate synchronous iteration with an array as below,\n\n     ```js\n\n//\nconst iterable = ['one', 'two', 'three'];\nconst iterator = iterable[Symbol.iterator]();\nconsole.log(iterator.next()); // { value: 'one', done: false }\nconsole.log(iterator.next()); // { value: 'two', done: false }\nconsole.log(iterator.next()); // { value: 'three', done: false }\nconsole.log(iterator.next()); // { value: 'undefined, done: true }\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an event loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Event Loop is a queue of callback functions. When an async function executes, the callback function is pushed into the queue. The JavaScript engine doesn't start processing the event loop until the async function has finished executing the code.\n**Note:** It allows Node.js to perform non-blocking I/O operations even though JavaScript is single-threaded.</code></pre></div>\n</li>\n<li>\n<p>What is call stack</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Call Stack is a data structure for javascript interpreters to keep track of function calls in the program. It has two major actions,\n\n     1. Whenever you call a function for its execution, you are pushing it to the stack.\n     2. Whenever the execution is completed, the function is popped out of the stack.\n\n     Let's take an example and it's state representation in a diagram format\n\n     ```js\n\n//\nfunction hungry() {\neatFruits();\n}\nfunction eatFruits() {\nreturn \"I'm eating fruits\";\n}\n\n     // Invoke the `hungry` function\n     hungry();\n     ```\n\n     The above code processed in a call stack as below,\n\n     1. Add the `hungry()` function to the call stack list and execute the code.\n     2. Add the `eatFruits()` function to the call stack list and execute the code.\n     3. Delete the `eatFruits()` function from our call stack list.\n     4. Delete the `hungry()` function from the call stack list since there are no items anymore.\n\n     ![Screenshot](images/call-stack.png)</code></pre></div>\n</li>\n<li>What is an event queue</li>\n<li>\n<p>What is a decorator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A decorator is an expression that evaluates to a function and that takes the target, name, and decorator descriptor as arguments. Also, it optionally returns a decorator descriptor to install on the target object. Let's define admin decorator for user class at design time,\n\n     ```js\n\n//\nfunction admin(isAdmin) {\nreturn function(target) {\ntarget.isAdmin = isAdmin;\n}\n}\n\n     @admin(true)\n     class User() {\n     }\n     console.log(User.isAdmin); //true\n\n      @admin(false)\n      class User() {\n      }\n      console.log(User.isAdmin); //false\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the properties of Intl object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of properties available on Intl object,\n\n1. **Collator:** These are the objects that enable language-sensitive string comparison.\n2. **DateTimeFormat:** These are the objects that enable language-sensitive date and time formatting.\n3. **ListFormat:** These are the objects that enable language-sensitive list formatting.\n4. **NumberFormat:** Objects that enable language-sensitive number formatting.\n5. **PluralRules:** Objects that enable plural-sensitive formatting and language-specific rules for plurals.\n6. **RelativeTimeFormat:** Objects that enable language-sensitive relative time formatting.</code></pre></div>\n</li>\n<li>\n<p>What is an Unary operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The unary(+) operator is used to convert a variable to a number.If the variable cannot be converted, it will still become a number but with the value NaN. Let's see this behavior in an action.\n\n     ```js\n\n//\nvar x = '100';\nvar y = +x;\nconsole.log(typeof x, typeof y); // string, number\n\n     var a = 'Hello';\n     var b = +a;\n     console.log(typeof a, typeof b, b); // string, number, NaN\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you sort elements in an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The sort() method is used to sort the elements of an array in place and returns the sorted array. The example usage would be as below,\n\n     ```js\n\n//\nvar months = ['Aug', 'Sep', 'Jan', 'June'];\nmonths.sort();\nconsole.log(months); // [\"Aug\", \"Jan\", \"June\", \"Sep\"]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of compareFunction while sorting arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The compareFunction is used to define the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value. Let's take an example to see the usage of compareFunction,\n\n     ```js\n\n//\nlet numbers = [1, 2, 5, 3, 4];\nnumbers.sort((a, b) => b - a);\nconsole.log(numbers); // [5, 4, 3, 2, 1]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you reversing an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the reverse() method to reverse the elements in an array. This method is useful to sort an array in descending order. Let's see the usage of reverse() method in an example,\n\n     ```js\n\n//\nlet numbers = [1, 2, 5, 3, 4];\nnumbers.sort((a, b) => b - a);\nnumbers.reverse();\nconsole.log(numbers); // [1, 2, 3, 4 ,5]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you find min and max value in an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `Math.min` and `Math.max` methods on array variables to find the minimum and maximum elements within an array. Let's create two functions to find the min and max value with in an array,\n\n     ```js\n\n//\nvar marks = [50, 20, 70, 60, 45, 30];\nfunction findMin(arr) {\nreturn Math.min.apply(null, arr);\n}\nfunction findMax(arr) {\nreturn Math.max.apply(null, arr);\n}\n\n     console.log(findMin(marks));\n     console.log(findMax(marks));\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you find min and max values without Math functions</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can write functions which loop through an array comparing each value with the lowest value or highest value to find the min and max values. Let's create those functions to find min and max values,\n\n     ```js\n\n//\nvar marks = [50, 20, 70, 60, 45, 30];\nfunction findMin(arr) {\nvar length = arr.length;\nvar min = Infinity;\nwhile (length--) {\nif (arr[length] &lt; min) {\nmin = arr[len];\n}\n}\nreturn min;\n}\n\n     function findMax(arr) {\n         var length = arr.length;\n         var max = -Infinity;\n         while (len--) {\n             if (arr[length] > max) {\n                 max = arr[length];\n             }\n         }\n         return max;\n     }\n\n     console.log(findMin(marks));\n     console.log(findMax(marks));\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is an empty statement and purpose of it</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The empty statement is a semicolon (;) indicating that no statement will be executed, even if JavaScript syntax requires one. Since there is no action with an empty statement you might think that it's usage is quite less, but the empty statement is occasionally useful when you want to create a loop that has an empty body. For example, you can initialize an array with zero values as below,\n\n     ```js\n\n//\n// Initialize an array a\nfor(int i=0; i &lt; a.length; a[i++] = 0) ;\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get metadata of a module</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `import.meta` object which is a meta-property exposing context-specific meta data to a JavaScript module. It contains information about the current module, such as the module's URL. In browsers, you might get different meta data than NodeJS.\n\n     ```js\n\n//\n&lt;script type=\"module\" src=\"welcome-module.js\">\n&lt;/script>;\n\nconsole.log(import.meta); // { url: \"file:///home/user/welcome-module.js\" }\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a comma operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The comma operator is used to evaluate each of its operands from left to right and returns the value of the last operand. This is totally different from comma usage within arrays, objects, and function arguments and parameters. For example, the usage for numeric expressions would be as below,\n\n     ```js\n\n//\nvar x = 1;\nx = (x++, x);\n\n     console.log(x); // 2\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the advantage of a comma operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is normally used to include multiple expressions in a location that requires a single expression. One of the common usages of this comma operator is to supply multiple parameters in a `for` loop. For example, the below for loop uses multiple expressions in a single location using comma operator,\n\n     ```js\n\n//\nfor (var a = 0, b =10; a &lt;= 10; a++, b--)\n\n````\n\n     You can also use the comma operator in a return statement where it processes before returning.\n\n     ```js\n\n//\nfunction myFunction() {\nvar a = 1;\nreturn (a += 10), a; // 11\n}\n````</code></pre></div>\n</li>\n<li>\n<p>What is typescript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">TypeScript is a typed superset of JavaScript created by Microsoft that adds optional types, classes, async/await, and many other features, and compiles to plain JavaScript. Angular built entirely in TypeScript and used as a primary language. You can install it globally as\n\n```shell\nnpm install -g typescript\n```\n\nLet's see a simple example of TypeScript usage,\n\n```typescript\nfunction greeting(name: string): string {\n    return 'Hello, ' + name;\n}\n\nlet user = 'Sudheer';\n\nconsole.log(greeting(user));\n```\n\nThe greeting method allows only string type as argument.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between javascript and typescript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of differences between javascript and typescript,\n\n| feature             | typescript                            | javascript                                      |\n| ------------------- | ------------------------------------- | ----------------------------------------------- |\n| Language paradigm   | Object oriented programming language  | Scripting language                              |\n| Typing support      | Supports static typing                | It has dynamic typing                           |\n| Modules             | Supported                             | Not supported                                   |\n| Interface           | It has interfaces concept             | Doesn't support interfaces                      |\n| Optional parameters | Functions support optional parameters | No support of optional parameters for functions |</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of typescript over javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are some of the advantages of typescript over javascript,\n\n1. TypeScript is able to find compile time errors at the development time only and it makes sures less runtime errors. Whereas javascript is an interpreted language.\n2. TypeScript is strongly-typed or supports static typing which allows for checking type correctness at compile time. This is not available in javascript.\n3. TypeScript compiler can compile the .ts files into ES3,ES4 and ES5 unlike ES6 features of javascript which may not be supported in some browsers.</code></pre></div>\n</li>\n<li>\n<p>What is an object initializer</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An object initializer is an expression that describes the initialization of an Object. The syntax for this expression is represented as a comma-delimited list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}). This is also known as literal notation. It is one of the ways to create an object.\n\n     ```js\n\n//\nvar initObject = { a: 'John', b: 50, c: {} };\n\n     console.log(initObject.a); // John\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is a constructor method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The constructor method is a special method for creating and initializing an object created within a class. If you do not specify a constructor method, a default constructor is used. The example usage of constructor would be as below,\n\n     ```js\n\n//\nclass Employee {\nconstructor() {\nthis.name = 'John';\n}\n}\n\n     var employeeObject = new Employee();\n\n     console.log(employeeObject.name); // John\n     ```</code></pre></div>\n</li>\n<li>\n<p>What happens if you write constructor more than once in a class</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The \"constructor\" in a class is a special method and it should be defined only once in a class. i.e, If you write a constructor method more than once in a class it will throw a `SyntaxError` error.\n\n     ```js\n\n//\nclass Employee {\nconstructor() {\nthis.name = \"John\";\n}\nconstructor() { // Uncaught SyntaxError: A class may only have one constructor\nthis.age = 30;\n}\n}\n\n      var employeeObject = new Employee();\n\n      console.log(employeeObject.name);\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you call the constructor of a parent class</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `super` keyword to call the constructor of a parent class. Remember that `super()` must be called before using 'this' reference. Otherwise it will cause a reference error. Let's the usage of it,\n\n     ```js\n\n//\nclass Square extends Rectangle {\nconstructor(length) {\nsuper(length, length);\nthis.name = 'Square';\n}\n\n         get area() {\n             return this.width * this.height;\n         }\n\n         set area(value) {\n             this.area = value;\n         }\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you get the prototype of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.getPrototypeOf(obj)` method to return the prototype of the specified object. i.e. The value of the internal `prototype` property. If there are no inherited properties then `null` value is returned.\n\n     ```js\n\n//\nconst newPrototype = {};\nconst newObject = Object.create(newPrototype);\n\n     console.log(Object.getPrototypeOf(newObject) === newPrototype); // true\n     ```</code></pre></div>\n</li>\n<li>\n<p>What happens If I pass string type for getPrototype method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In ES5, it will throw a TypeError exception if the obj parameter isn't an object. Whereas in ES2015, the parameter will be coerced to an `Object`.\n\n     ```js\n\n//\n// ES5\nObject.getPrototypeOf('James'); // TypeError: \"James\" is not an object\n// ES2015\nObject.getPrototypeOf('James'); // String.prototype\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you set prototype of one object to another</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.setPrototypeOf()` method that sets the prototype (i.e., the internal `Prototype` property) of a specified object to another object or null. For example, if you want to set prototype of a square object to rectangle object would be as follows,\n\n     ```js\n\n//\nObject.setPrototypeOf(Square.prototype, Rectangle.prototype);\nObject.setPrototypeOf({}, null);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether an object can be extendable or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `Object.isExtensible()` method is used to determine if an object is extendable or not. i.e, Whether it can have new properties added to it or not.\n\n     ```js\n\n//\nconst newObject = {};\nconsole.log(Object.isExtensible(newObject)); //true\n\n```\n\n     **Note:** By default, all the objects are extendable. i.e, The new properties can be added or modified.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you prevent an object to extend</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `Object.preventExtensions()` method is used to prevent new properties from ever being added to an object. In other words, it prevents future extensions to the object. Let's see the usage of this property,\n\n     ```js\n\n//\nconst newObject = {};\nObject.preventExtensions(newObject); // NOT extendable\n\n     try {\n         Object.defineProperty(newObject, 'newProperty', {\n             // Adding new property\n             value: 100\n         });\n     } catch (e) {\n         console.log(e); // TypeError: Cannot define property newProperty, object is not extensible\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to make an object non-extensible</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can mark an object non-extensible in 3 ways,\n\n     1. Object.preventExtensions\n     2. Object.seal\n     3. Object.freeze\n\n     ```js\n\n//\nvar newObject = {};\n\n     Object.preventExtensions(newObject); // Prevent objects are non-extensible\n     Object.isExtensible(newObject); // false\n\n     var sealedObject = Object.seal({}); // Sealed objects are non-extensible\n     Object.isExtensible(sealedObject); // false\n\n     var frozenObject = Object.freeze({}); // Frozen objects are non-extensible\n     Object.isExtensible(frozenObject); // false\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you define multiple properties on an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `Object.defineProperties()` method is used to define new or modify existing properties directly on an object and returning the object. Let's define multiple properties on an empty object,\n\n     ```js\n\n//\nconst newObject = {};\n\n     Object.defineProperties(newObject, {\n         newProperty1: {\n             value: 'John',\n             writable: true\n         },\n         newProperty2: {}\n     });\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is MEAN in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The MEAN (MongoDB, Express, AngularJS, and Node.js) stack is the most popular open-source JavaScript software tech stack available for building dynamic web apps where you can write both the server-side and client-side halves of the web project entirely in JavaScript.</code></pre></div>\n</li>\n<li>\n<p>What Is Obfuscation in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Obfuscation is the deliberate act of creating obfuscated javascript code(i.e, source or machine code) that is difficult for humans to understand. It is something similar to encryption, but a machine can understand the code and execute it.\n     Let's see the below function before Obfuscation,\n\n     ```js\n\n//\nfunction greeting() {\nconsole.log('Hello, welcome to JS world');\n}\n\n````\n\n     And after the code Obfuscation, it would be appeared as below,\n\n     ```js\n\n//\neval(\n(function (p, a, c, k, e, d) {\ne = function (c) {\nreturn c;\n};\nif (!''.replace(/^/, String)) {\nwhile (c--) {\nd[c] = k[c] || c;\n}\nk = [\nfunction (e) {\nreturn d[e];\n}\n];\ne = function () {\nreturn '\\\\w+';\n};\nc = 1;\n}\nwhile (c--) {\nif (k[c]) {\np = p.replace(new RegExp('\\\\b' + e(c) + '\\\\b', 'g'), k[c]);\n}\n}\nreturn p;\n})(\"2 1(){0.3('4, 7 6 5 8')}\", 9, 9, 'console|greeting|function|log|Hello|JS|to|welcome|world'.split('|'), 0, {})\n);\n````</code></pre></div>\n</li>\n<li>\n<p>Why do you need Obfuscation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the few reasons for Obfuscation,\n\n1. The Code size will be reduced. So data transfers between server and client will be fast.\n2. It hides the business logic from outside world and protects the code from others\n3. Reverse engineering is highly difficult\n4. The download time will be reduced</code></pre></div>\n</li>\n<li>\n<p>What is Minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Minification is the process of removing all unnecessary characters(empty spaces are removed) and variables will be renamed without changing it's functionality. It is also a type of obfuscation .</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Normally it is recommended to use minification for heavy traffic and intensive requirements of resources. It reduces file sizes with below benefits,\n\n1. Decreases loading times of a web page\n2. Saves bandwidth usages</code></pre></div>\n</li>\n<li>\n<p>What are the differences between Obfuscation and Encryption</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main differences between Obfuscation and Encryption,\n\n| Feature            | Obfuscation                                     | Encryption                                                              |\n| ------------------ | ----------------------------------------------- | ----------------------------------------------------------------------- |\n| Definition         | Changing the form of any data in any other form | Changing the form of information to an unreadable format by using a key |\n| A key to decode    | It can be decoded without any key               | It is required                                                          |\n| Target data format | It will be converted to a complex form          | Converted into an unreadable format                                     |</code></pre></div>\n</li>\n<li>\n<p>What are the common tools used for minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are many online/offline tools to minify the javascript files,\n\n1. Google's Closure Compiler\n2. UglifyJS2\n3. jsmin\n4. javascript-minifier.com/\n5. prettydiff.com</code></pre></div>\n</li>\n<li>\n<p>How do you perform form validation using javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript can be used to perform HTML form validation. For example, if the form field is empty, the function needs to notify, and return false, to prevent the form being submitted.\n     Lets' perform user login in an html form,\n\n     ```html\n     &lt;form name=\"myForm\" onsubmit=\"return validateForm()\" method=\"post\">\n         User name: &lt;input type=\"text\" name=\"uname\" />\n         &lt;input type=\"submit\" value=\"Submit\" />\n     &lt;/form>\n     ```\n\n     And the validation on user login is below,\n\n     ```js\n\n//\nfunction validateForm() {\nvar x = document.forms['myForm']['uname'].value;\nif (x == '') {\nalert(\"The username shouldn't be empty\");\nreturn false;\n}\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you perform form validation without javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can perform HTML form validation automatically without using javascript. The validation enabled by applying the `required` attribute to prevent form submission when the input is empty.\n\n```html\n&lt;form method=\"post\">\n    &lt;input type=\"text\" name=\"uname\" required />\n    &lt;input type=\"submit\" value=\"Submit\" />\n&lt;/form>\n```\n\n**Note:** Automatic form validation does not work in Internet Explorer 9 or earlier.</code></pre></div>\n</li>\n<li>\n<p>What are the DOM methods available for constraint validation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The below DOM methods are available for constraint validation on an invalid input,\n\n     1. checkValidity(): It returns true if an input element contains valid data.\n     2. setCustomValidity(): It is used to set the validationMessage property of an input element.\n        Let's take an user login form with DOM validations\n\n     ```js\n\n//\nfunction myFunction() {\nvar userName = document.getElementById('uname');\nif (!userName.checkValidity()) {\ndocument.getElementById('message').innerHTML = userName.validationMessage;\n} else {\ndocument.getElementById('message').innerHTML = 'Entered a valid username';\n}\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the available constraint validation DOM properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of some of the constraint validation DOM properties available,\n\n1. validity: It provides a list of boolean properties related to the validity of an input element.\n2. validationMessage: It displays the message when the validity is false.\n3. willValidate: It indicates if an input element will be validated or not.</code></pre></div>\n</li>\n<li>\n<p>What are the list of validity properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The validity property of an input element provides a set of properties related to the validity of data.\n\n1. customError: It returns true, if a custom validity message is set.\n2. patternMismatch: It returns true, if an element's value does not match its pattern attribute.\n3. rangeOverflow: It returns true, if an element's value is greater than its max attribute.\n4. rangeUnderflow: It returns true, if an element's value is less than its min attribute.\n5. stepMismatch: It returns true, if an element's value is invalid according to step attribute.\n6. tooLong: It returns true, if an element's value exceeds its maxLength attribute.\n7. typeMismatch: It returns true, if an element's value is invalid according to type attribute.\n8. valueMissing: It returns true, if an element with a required attribute has no value.\n9. valid: It returns true, if an element's value is valid.</code></pre></div>\n</li>\n<li>\n<p>Give an example usage of rangeOverflow property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If an element's value is greater than its max attribute then rangeOverflow property returns true. For example, the below form submission throws an error if the value is more than 100,\n\n     ```html\n     &lt;input id=\"age\" type=\"number\" max=\"100\" /> &lt;button onclick=\"myOverflowFunction()\">OK&lt;/button>\n     ```\n\n     ```js\n\n//\nfunction myOverflowFunction() {\nif (document.getElementById('age').validity.rangeOverflow) {\nalert('The mentioned age is not allowed');\n}\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is enums feature available in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     No, javascript does not natively support enums. But there are different kinds of solutions to simulate them even though they may not provide exact equivalents. For example, you can use freeze or seal on object,\n\n     ```js\n\n//\nvar DaysEnum = Object.freeze({\"monday\":1, \"tuesday\":2, \"wednesday\":3, ...})\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an enum</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An enum is a type restricting variables to one value from a predefined set of constants. JavaScript has no enums but typescript provides built-in enum support.\n\n     ```js\n\n//\nenum Color {\nRED, GREEN, BLUE\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you list all properties of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.getOwnPropertyNames()` method which returns an array of all properties found directly in a given object. Let's the usage of it in an example,\n\n     ```js\n\n//\nconst newObject = {\na: 1,\nb: 2,\nc: 3\n};\n\n     console.log(Object.getOwnPropertyNames(newObject));\n     ['a', 'b', 'c'];\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you get property descriptors of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.getOwnPropertyDescriptors()` method which returns all own property descriptors of a given object. The example usage of this method is below,\n\n     ```js\n\n//\nconst newObject = {\na: 1,\nb: 2,\nc: 3\n};\nconst descriptorsObject = Object.getOwnPropertyDescriptors(newObject);\nconsole.log(descriptorsObject.a.writable); //true\nconsole.log(descriptorsObject.a.configurable); //true\nconsole.log(descriptorsObject.a.enumerable); //true\nconsole.log(descriptorsObject.a.value); // 1\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the attributes provided by a property descriptor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A property descriptor is a record which has the following attributes\n\n1. value: The value associated with the property\n2. writable: Determines whether the value associated with the property can be changed or not\n3. configurable: Returns true if the type of this property descriptor can be changed and if the property can be deleted from the corresponding object.\n4. enumerable: Determines whether the property appears during enumeration of the properties on the corresponding object or not.\n5. set: A function which serves as a setter for the property\n6. get: A function which serves as a getter for the property</code></pre></div>\n</li>\n<li>\n<p>How do you extend classes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `extends` keyword is used in class declarations/expressions to create a class which is a child of another class. It can be used to subclass custom classes as well as built-in objects. The syntax would be as below,\n\n     ```js\n\n//\nclass ChildClass extends ParentClass { ... }\n\n````\n\n     Let's take an example of Square subclass from Polygon parent class,\n\n     ```js\n\n//\nclass Square extends Rectangle {\nconstructor(length) {\nsuper(length, length);\nthis.name = 'Square';\n}\n\n         get area() {\n             return this.width * this.height;\n         }\n\n         set area(value) {\n             this.area = value;\n         }\n     }\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do I modify the url without reloading the page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `window.location.url` property will be helpful to modify the url but it reloads the page. HTML5 introduced the `history.pushState()` and `history.replaceState()` methods, which allow you to add and modify history entries, respectively. For example, you can use pushState as below,\n\n     ```js\n\n//\nwindow.history.pushState('page2', 'Title', '/page2.html');\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether an array includes a particular value or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `Array#includes()` method is used to determine whether an array includes a particular value among its entries by returning either true or false. Let's see an example to find an element(numeric and string) within an array.\n\n     ```js\n\n//\nvar numericArray = [1, 2, 3, 4];\nconsole.log(numericArray.includes(3)); // true\n\n     var stringArray = ['green', 'yellow', 'blue'];\n     console.log(stringArray.includes('blue')); //true\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you compare scalar arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use length and every method of arrays to compare two scalar(compared directly using ===) arrays. The combination of these expressions can give the expected result,\n\n     ```js\n\n//\nconst arrayFirst = [1, 2, 3, 4, 5];\nconst arraySecond = [1, 2, 3, 4, 5];\nconsole.log(arrayFirst.length === arraySecond.length &amp;&amp; arrayFirst.every((value, index) => value === arraySecond[index])); // true\n\n````\n\n     If you would like to compare arrays irrespective of order then you should sort them before,\n\n     ```js\n\n//\nconst arrayFirst = [2, 3, 1, 4, 5];\nconst arraySecond = [1, 2, 3, 4, 5];\nconsole.log(arrayFirst.length === arraySecond.length &amp;&amp; arrayFirst.sort().every((value, index) => value === arraySecond[index])); //true\n````</code></pre></div>\n</li>\n<li>\n<p>How to get the value from get parameters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `new URL()` object accepts the url string and `searchParams` property of this object can be used to access the get parameters. Remember that you may need to use polyfill or `window.location` to access the URL in older browsers(including IE).\n\n     ```js\n\n//\nlet urlString = 'http://www.some-domain.com/about.html?x=1&amp;y=2&amp;z=3'; //window.location.href\nlet url = new URL(urlString);\nlet parameterZ = url.searchParams.get('z');\nconsole.log(parameterZ); // 3\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you print numbers with commas as thousand separators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Number.prototype.toLocaleString()` method which returns a string with a language-sensitive representation such as thousand separator,currency etc of this number.\n\n     ```js\n\n//\nfunction convertToThousandFormat(x) {\nreturn x.toLocaleString(); // 12,345.679\n}\n\n     console.log(convertToThousandFormat(12345.6789));\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between java and javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both are totally unrelated programming languages and no relation between them. Java is statically typed, compiled, runs on its own VM. Whereas Javascript is dynamically typed, interpreted, and runs in a browser and nodejs environments. Let's see the major differences in a tabular format,\n| Feature | Java | JavaScript |\n|---- | ---- | -----\n| Typed | It's a strongly typed language | It's a dynamic typed language |\n| Paradigm | Object oriented programming | Prototype based programming |\n| Scoping | Block scoped | Function-scoped |\n| Concurrency | Thread based | event based |\n| Memory | Uses more memory | Uses less memory. Hence it will be used for web pages |</code></pre></div>\n</li>\n<li>\n<p>Does JavaScript supports namespace</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript doesn't support namespace by default. So if you create any element(function, method, object, variable) then it becomes global and pollutes the global namespace. Let's take an example of defining two functions without any namespace,\n\n     ```js\n\n//\nfunction func1() {\nconsole.log('This is a first definition');\n}\nfunction func1() {\nconsole.log('This is a second definition');\n}\nfunc1(); // This is a second definition\n\n```\n\n     It always calls the second function definition. In this case, namespace will solve the name collision problem.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you declare namespace</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Even though JavaScript lacks namespaces, we can use Objects , IIFE to create namespaces.\n\n     1. **Using Object Literal Notation:** Let's wrap variables and functions inside an Object literal which acts as a namespace. After that you can access them using object notation\n\n     ```js\n\n//\nvar namespaceOne = {\nfunction func1() {\nconsole.log(\"This is a first definition\");\n}\n}\nvar namespaceTwo = {\nfunction func1() {\nconsole.log(\"This is a second definition\");\n}\n}\nnamespaceOne.func1(); // This is a first definition\nnamespaceTwo.func1(); // This is a second definition\n\n````\n\n     1. **Using IIFE (Immediately invoked function expression):** The outer pair of parentheses of IIFE creates a local scope for all the code inside of it and makes the anonymous function a function expression. Due to that, you can create the same function in two different function expressions to act as a namespace.\n\n     ```js\n\n//\n(function () {\nfunction fun1() {\nconsole.log('This is a first definition');\n}\nfun1();\n})();\n\n     (function () {\n         function fun1() {\n             console.log('This is a second definition');\n         }\n         fun1();\n     })();\n     ```\n\n     1. **Using a block and a let/const declaration:** In ECMAScript 6, you can simply use a block and a let declaration to restrict the scope of a variable to a block.\n\n     ```js\n\n//\n{\nlet myFunction = function fun1() {\nconsole.log('This is a first definition');\n};\nmyFunction();\n}\n//myFunction(): ReferenceError: myFunction is not defined.\n\n     {\n         let myFunction = function fun1() {\n             console.log('This is a second definition');\n         };\n         myFunction();\n     }\n     //myFunction(): ReferenceError: myFunction is not defined.\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do you invoke javascript code in an iframe from parent page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Initially iFrame needs to be accessed using either `document.getElementBy` or `window.frames`. After that `contentWindow` property of iFrame gives the access for targetFunction\n\n     ```js\n\n//\ndocument.getElementById('targetFrame').contentWindow.targetFunction();\nwindow.frames[0].frameElement.contentWindow.targetFunction(); // Accessing iframe this way may not work in latest versions chrome and firefox\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do get the timezone offset from date</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `getTimezoneOffset` method of the date object. This method returns the time zone difference, in minutes, from current locale (host system settings) to UTC\n\n     ```js\n\n//\nvar offset = new Date().getTimezoneOffset();\nconsole.log(offset); // -480\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you load CSS and JS files dynamically</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can create both link and script elements in the DOM and append them as child to head tag. Let's create a function to add script and style resources as below,\n\n     ```js\n\n//\nfunction loadAssets(filename, filetype) {\nif (filetype == 'css') {\n// External CSS file\nvar fileReference = document.createElement('link');\nfileReference.setAttribute('rel', 'stylesheet');\nfileReference.setAttribute('type', 'text/css');\nfileReference.setAttribute('href', filename);\n} else if (filetype == 'js') {\n// External JavaScript file\nvar fileReference = document.createElement('script');\nfileReference.setAttribute('type', 'text/javascript');\nfileReference.setAttribute('src', filename);\n}\nif (typeof fileReference != 'undefined') document.getElementsByTagName('head')[0].appendChild(fileReference);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different methods to find HTML elements in DOM</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you want to access any element in an HTML page, you need to start with accessing the document object. Later you can use any of the below methods to find the HTML element,\n\n1. document.getElementById(id): It finds an element by Id\n2. document.getElementsByTagName(name): It finds an element by tag name\n3. document.getElementsByClassName(name): It finds an element by class name</code></pre></div>\n</li>\n<li>\n<p>What is jQuery</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     jQuery is a popular cross-browser JavaScript library that provides Document Object Model (DOM) traversal, event handling, animations and AJAX interactions by minimizing the discrepancies across browsers. It is widely famous with its philosophy of \"Write less, do more\". For example, you can display welcome message on the page load using jQuery as below,\n\n     ```js\n\n//\n$(document).ready(function () {\n// It selects the document and apply the function on page load\nalert('Welcome to jQuery world');\n});\n\n```\n\n     **Note:** You can download it from jquery's official site or install it from CDNs, like google.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is V8 JavaScript engine</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">V8 is an open source high-performance JavaScript engine used by the Google Chrome browser, written in C++. It is also being used in the node.js project. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors.\n**Note:** It can run standalone, or can be embedded into any C++ application.</code></pre></div>\n</li>\n<li>\n<p>Why do we call javascript as dynamic language</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript is a loosely typed or a dynamic language because variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned/reassigned with values of all types.\n\n     ```js\n\n//\nlet age = 50; // age is a number now\nage = 'old'; // age is a string now\nage = true; // age is a boolean\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a void operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `void` operator evaluates the given expression and then returns undefined(i.e, without returning value). The syntax would be as below,\n\n     ```js\n\n//\nvoid expression;\nvoid expression;\n\n````\n\n     Let's display a message without any redirection or reload\n\n     ```js\n\n//\n&lt;a href=\"javascript:void(alert('Welcome to JS world'))\">Click here to see a message&lt;/a>\n````\n\n     **Note:** This operator is often used to obtain the undefined primitive value, using \"void(0)\".</code></pre></div>\n</li>\n<li>\n<p>How to set the cursor to wait</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The cursor can be set to wait in JavaScript by using the property \"cursor\". Let's perform this behavior on page load using the below function.\n\n     ```js\n\n//\nfunction myFunction() {\nwindow.document.body.style.cursor = 'wait';\n}\n\n````\n\n     and this function invoked on page load\n\n     ```html\n     &lt;body onload=\"myFunction()\">\n\n&lt;/body>\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do you create an infinite loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can create infinite loops using for and while loops without using any expressions. The for loop construct or syntax is better approach in terms of ESLint and code optimizer tools,\n\n     ```js\n\n//\nfor (;;) {}\nwhile (true) {}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need to avoid with statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript's with statement was intended to provide a shorthand for writing recurring accesses to objects. So it can help reduce file size by reducing the need to repeat a lengthy object reference without performance penalty. Let's take an example where it is used to avoid redundancy when accessing an object several times.\n\n     ```js\n\n//\na.b.c.greeting = 'welcome';\na.b.c.age = 32;\n\n````\n\n     Using `with` it turns this into:\n\n     ```js\n\n//\nwith (a.b.c) {\ngreeting = 'welcome';\nage = 32;\n}\n````\n\n     But this `with` statement creates performance problems since one cannot predict whether an argument will refer to a real variable or to a property inside the with argument.</code></pre></div>\n</li>\n<li>\n<p>What is the output of below for loops</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ```js\n\n//\nfor (var i = 0; i &lt; 4; i++) {\n// global scope\nsetTimeout(() => console.log(i));\n}\n\n     for (let i = 0; i &lt; 4; i++) {\n         // block scope\n         setTimeout(() => console.log(i));\n     }\n     ```\n\n     The output of the above for loops is 4 4 4 4 and 0 1 2 3\n\n     **Explanation:** Due to the event queue/loop of javascript, the `setTimeout` callback function is called after the loop has been executed. Since the variable i is declared with the `var` keyword it became a global variable and the value was equal to 4 using iteration when the time `setTimeout` function is invoked. Hence, the output of the first loop is `4 4 4 4`.\n\n     Whereas in the second loop, the variable i is declared as the `let` keyword it becomes a block scoped variable and it holds a new value(0, 1 ,2 3) for each iteration. Hence, the output of the first loop is `0 1 2 3`.</code></pre></div>\n</li>\n<li>\n<p>List down some of the features of ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of some new features of ES6,\n\n1. Support for constants or immutable variables\n2. Block-scope support for variables, constants and functions\n3. Arrow functions\n4. Default parameters\n5. Rest and Spread Parameters\n6. Template Literals\n7. Multi-line Strings\n8. Destructuring Assignment\n9. Enhanced Object Literals\n10. Promises\n11. Classes\n12. Modules</code></pre></div>\n</li>\n<li>\n<p>What is ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ES6 is the sixth edition of the javascript language and it was released in June 2015. It was initially known as ECMAScript 6 (ES6) and later renamed to ECMAScript 2015. Almost all the modern browsers support ES6 but for the old browsers there are many transpilers, like Babel.js etc.</code></pre></div>\n</li>\n<li>\n<p>Can I redeclare let and const variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     No, you cannot redeclare let and const variables. If you do, it throws below error\n\n     ```shell\n     Uncaught SyntaxError: Identifier 'someVariable' has already been declared\n     ```\n\n     **Explanation:** The variable declaration with `var` keyword refers to a function scope and the variable is treated as if it were declared at the top of the enclosing scope due to hoisting feature. So all the multiple declarations contributing to the same hoisted variable without any error. Let's take an example of re-declaring variables in the same scope for both var and let/const variables.\n\n     ```js\n\n//\nvar name = 'John';\nfunction myFunc() {\nvar name = 'Nick';\nvar name = 'Abraham'; // Re-assigned in the same function block\nalert(name); // Abraham\n}\nmyFunc();\nalert(name); // John\n\n````\n\n     The block-scoped multi-declaration throws syntax error,\n\n     ```js\n\n//\nlet name = 'John';\nfunction myFunc() {\nlet name = 'Nick';\nlet name = 'Abraham'; // Uncaught SyntaxError: Identifier 'name' has already been declared\nalert(name);\n}\n\n     myFunc();\n     alert(name);\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>Is const variable makes the value immutable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     No, the const variable doesn't make the value immutable. But it disallows subsequent assignments(i.e, You can declare with assignment but can't assign another value later)\n\n     ```js\n\n//\nconst userList = [];\nuserList.push('John'); // Can mutate even though it can't re-assign\nconsole.log(userList); // ['John']\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are default parameters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In E5, we need to depend on logical OR operators to handle default values of function parameters. Whereas in ES6, Default function parameters feature allows parameters to be initialized with default values if no value or undefined is passed. Let's compare the behavior with an examples,\n\n     ```js\n\n//\n//ES5\nvar calculateArea = function (height, width) {\nheight = height || 50;\nwidth = width || 60;\n\n         return width * height;\n     };\n     console.log(calculateArea()); //300\n     ```\n\n     The default parameters makes the initialization more simpler,\n\n     ```js\n\n//\n//ES6\nvar calculateArea = function (height = 50, width = 60) {\nreturn width \\* height;\n};\n\n     console.log(calculateArea()); //300\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are template literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Template literals or template strings are string literals allowing embedded expressions. These are enclosed by the back-tick (`) character instead of double or single quotes.\n     In E6, this feature enables using dynamic expressions as below,\n\n     ```js\n\n//\nvar greeting = `Welcome to JS World, Mr. ${firstName} ${lastName}.`;\n\n````\n\n     In ES5, you need break string like below,\n\n     ```js\n\n//\nvar greeting = 'Welcome to JS World, Mr. ' + firstName + ' ' + lastName.`\n````\n\n     **Note:** You can use multi-line strings and string interpolation features with template literals.</code></pre></div>\n</li>\n<li>\n<p>How do you write multi-line strings in template literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In ES5, you would have to use newline escape characters('\\\\n') and concatenation symbols(+) in order to get multi-line strings.\n\n     ```js\n\n//\nconsole.log('This is string sentence 1\\n' + 'This is string sentence 2');\n\n````\n\n     Whereas in ES6, You don't need to mention any newline sequence character,\n\n     ```js\n\n//\nconsole.log(`This is string sentence 'This is string sentence 2`);\n````</code></pre></div>\n</li>\n<li>\n<p>What are nesting templates</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The nesting template is a feature supported within template literals syntax to allow inner backticks inside a placeholder ${ } within the template. For example, the below nesting template is used to display the icons based on user permissions whereas outer template checks for platform type,\n\n     ```js\n\n//\nconst iconStyles = `icon ${isMobilePlatform() ? '' : `icon-${user.isAuthorized ? 'submit' : 'disabled'}`}`;\n\n````\n\n     You can write the above use case without nesting template features as well. However, the nesting template feature is more compact and readable.\n\n     ```js\n\n//\n//Without nesting templates\nconst iconStyles = `icon ${ isMobilePlatform() ? '' : (user.isAuthorized ? 'icon-submit' : 'icon-disabled'}`;\n````</code></pre></div>\n</li>\n<li>\n<p>What are tagged templates</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Tagged templates are the advanced form of templates in which tags allow you to parse template literals with a function. The tag function accepts the first parameter as an array of strings and remaining parameters as expressions. This function can also return manipulated strings based on parameters. Let's see the usage of this tagged template behavior of an IT professional skill set in an organization,\n\n     ```js\n\n//\nvar user1 = 'John';\nvar skill1 = 'JavaScript';\nvar experience1 = 15;\n\n     var user2 = 'Kane';\n     var skill2 = 'JavaScript';\n     var experience2 = 5;\n\n     function myInfoTag(strings, userExp, experienceExp, skillExp) {\n       var str0 = strings[0]; // \"Mr/Ms. \"\n       var str1 = strings[1]; // \" is a/an \"\n       var str2 = strings[2]; // \"in\"\n\n       var expertiseStr;\n       if (experienceExp > 10){\n         expertiseStr = 'expert developer';\n       } else if(skillExp > 5 &amp;&amp; skillExp &lt;= 10) {\n         expertiseStr = 'senior developer';\n       } else {\n         expertiseStr = 'junior developer';\n       }\n\n       return ${str0}${userExp}${str1}${expertiseStr}${str2}${skillExp};\n     }\n\n     var output1 = myInfoTag`Mr/Ms. ${ user1 } is a/an ${ experience1 } in ${skill1}`;\n     var output2 = myInfoTag`Mr/Ms. ${ user2 } is a/an ${ experience2 } in ${skill2}`;\n\n     console.log(output1);// Mr/Ms. John is a/an expert developer in JavaScript\n     console.log(output2);// Mr/Ms. Kane is a/an junior developer in JavaScript\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are raw strings</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ES6 provides a raw strings feature using the `String.raw()` method which is used to get the raw string form of template strings. This feature allows you to access the raw strings as they were entered, without processing escape sequences. For example, the usage would be as below,\n\n     ```js\n\n//\nvar calculationString = String.raw`The sum of numbers is \\n${1 + 2 + 3 + 4}!`;\nconsole.log(calculationString); // The sum of numbers is 10\n\n````\n\n     If you don't use raw strings, the newline character sequence will be processed by displaying the output in multiple lines\n\n     ```js\n\n//\nvar calculationString = `The sum of numbers is \\n${1 + 2 + 3 + 4}!`;\nconsole.log(calculationString);\n// The sum of numbers is\n// 10\n````\n\n     Also, the raw property is available on the first argument to the tag function\n\n     ```js\n\n//\nfunction tag(strings) {\nconsole.log(strings.raw[0]);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The destructuring assignment is a JavaScript expression that makes it possible to unpack values from arrays or properties from objects into distinct variables.\n     Let's get the month values from an array using destructuring assignment\n\n     ```js\n\n//\nvar [one, two, three] = ['JAN', 'FEB', 'MARCH'];\n\n     console.log(one); // \"JAN\"\n     console.log(two); // \"FEB\"\n     console.log(three); // \"MARCH\"\n     ```\n\n     and you can get user properties of an object using destructuring assignment,\n\n     ```js\n\n//\nvar { name, age } = { name: 'John', age: 32 };\n\n     console.log(name); // John\n     console.log(age); // 32\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are default values in destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A variable can be assigned a default value when the value unpacked from the array or object is undefined during destructuring assignment. It helps to avoid setting default values separately for each assignment. Let's take an example for both arrays and object use cases,\n\n     **Arrays destructuring:**\n\n     ```js\n\n//\nvar x, y, z;\n\n     [x = 2, y = 4, z = 6] = [10];\n     console.log(x); // 10\n     console.log(y); // 4\n     console.log(z); // 6\n     ```\n\n     **Objects destructuring:**\n\n     ```js\n\n//\nvar { x = 2, y = 4, z = 6 } = { x: 10 };\n\n     console.log(x); // 10\n     console.log(y); // 4\n     console.log(z); // 6\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you swap variables in destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If you don't use destructuring assignment, swapping two values requires a temporary variable. Whereas using a destructuring feature, two variable values can be swapped in one destructuring expression. Let's swap two number variables in array destructuring assignment,\n\n     ```js\n\n//\nvar x = 10,\ny = 20;\n\n     [x, y] = [y, x];\n     console.log(x); // 20\n     console.log(y); // 10\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are enhanced object literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Object literals make it easy to quickly create objects with properties inside the curly braces. For example, it provides shorter syntax for common object property definition as below.\n\n     ```js\n\n//\n//ES6\nvar x = 10,\ny = 20;\nobj = { x, y };\nconsole.log(obj); // {x: 10, y:20}\n//ES5\nvar x = 10,\ny = 20;\nobj = { x: x, y: y };\nconsole.log(obj); // {x: 10, y:20}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are dynamic imports</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The dynamic imports using `import()` function syntax allows us to load modules on demand by using promises or the async/await syntax. Currently this feature is in [stage4 proposal](https://github.com/tc39/proposal-dynamic-import). The main advantage of dynamic imports is reduction of our bundle's sizes, the size/payload response of our requests and overall improvements in the user experience.\n     The syntax of dynamic imports would be as below,\n\n     ```js\n\n//\nimport('./Module').then((Module) => Module.method());\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the use cases for dynamic imports</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Below are some of the use cases of using dynamic imports over static imports,\n\n     1. Import a module on-demand or conditionally. For example, if you want to load a polyfill on legacy browser\n\n     ```js\n\n//\nif (isLegacyBrowser()) {\nimport(···)\n.then(···);\n}\n\n````\n\n     1. Compute the module specifier at runtime. For example, you can use it for internationalization.\n\n     ```js\n\n//\nimport(`messages_${getLocale()}.js`).then(···);\n````\n\n     1. Import a module from within a regular script instead a module.</code></pre></div>\n</li>\n<li>\n<p>What are typed arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Typed arrays are array-like objects from ECMAScript 6 API for handling binary data. JavaScript provides 8 Typed array types,\n\n     1. Int8Array: An array of 8-bit signed integers\n     2. Int16Array: An array of 16-bit signed integers\n     3. Int32Array: An array of 32-bit signed integers\n     4. Uint8Array: An array of 8-bit unsigned integers\n     5. Uint16Array: An array of 16-bit unsigned integers\n     6. Uint32Array: An array of 32-bit unsigned integers\n     7. Float32Array: An array of 32-bit floating point numbers\n     8. Float64Array: An array of 64-bit floating point numbers\n\n     For example, you can create an array of 8-bit signed integers as below\n\n     ```js\n\n//\nconst a = new Int8Array();\n// You can pre-allocate n bytes\nconst bytes = 1024;\nconst a = new Int8Array(bytes);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of module loaders</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The module loaders provides the below features,\n\n1. Dynamic loading\n2. State isolation\n3. Global namespace isolation\n4. Compilation hooks\n5. Nested virtualization</code></pre></div>\n</li>\n<li>\n<p>What is collation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Collation is used for sorting a set of strings and searching within a set of strings. It is parameterized by locale and aware of Unicode. Let's take comparison and sorting features,\n\n     1. **Comparison:**\n\n     ```js\n\n//\nvar list = ['ä', 'a', 'z']; // In German, \"ä\" sorts with \"a\" Whereas in Swedish, \"ä\" sorts after \"z\"\nvar l10nDE = new Intl.Collator('de');\nvar l10nSV = new Intl.Collator('sv');\nconsole.log(l10nDE.compare('ä', 'z') === -1); // true\nconsole.log(l10nSV.compare('ä', 'z') === +1); // true\n\n````\n\n     1. **Sorting:**\n\n     ```js\n\n//\nvar list = ['ä', 'a', 'z']; // In German, \"ä\" sorts with \"a\" Whereas in Swedish, \"ä\" sorts after \"z\"\nvar l10nDE = new Intl.Collator('de');\nvar l10nSV = new Intl.Collator('sv');\nconsole.log(list.sort(l10nDE.compare)); // [ \"a\", \"ä\", \"z\" ]\nconsole.log(list.sort(l10nSV.compare)); // [ \"a\", \"z\", \"ä\" ]\n````</code></pre></div>\n</li>\n<li>\n<p>What is for...of statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The for...of statement creates a loop iterating over iterable objects or elements such as built-in String, Array, Array-like objects (like arguments or NodeList), TypedArray, Map, Set, and user-defined iterables. The basic usage of for...of statement on arrays would be as below,\n\n     ```js\n\n//\nlet arrayIterable = [10, 20, 30, 40, 50];\n\n     for (let value of arrayIterable) {\n         value++;\n         console.log(value); // 11 21 31 41 51\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below spread operator array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ```js\n\n//\n[...'John Resig'];\n\n```\n\n     The output of the array is ['J', 'o', 'h', 'n', '', 'R', 'e', 's', 'i', 'g']\n     **Explanation:** The string is an iterable type and the spread operator within an array maps every character of an iterable to one element. Hence, each character of a string becomes an element within an Array.\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is PostMessage secure</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, postMessages can be considered very secure as long as the programmer/developer is careful about checking the origin and source of an arriving message. But if you try to send/receive a message without verifying its source will create cross-site scripting attacks.</code></pre></div>\n</li>\n<li>\n<p>What are the problems with postmessage target origin as wildcard</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The second argument of postMessage method specifies which origin is allowed to receive the message. If you use the wildcard \"\\*\" as an argument then any origin is allowed to receive the message. In this case, there is no way for the sender window to know if the target window is at the target origin when sending the message. If the target window has been navigated to another origin, the other origin would receive the data. Hence, this may lead to XSS vulnerabilities.\n\n     ```js\n\n//\ntargetWindow.postMessage(message, '\\*');\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you avoid receiving postMessages from attackers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Since the listener listens for any message, an attacker can trick the application by sending a message from the attacker's origin, which gives an impression that the receiver received the message from the actual sender's window. You can avoid this issue by validating the origin of the message on the receiver's end using the \"message.origin\" attribute. For examples, let's check the sender's origin [http://www.some-sender.com](https://www.some-sender.com) on receiver side [www.some-receiver.com](www.some-receiver.com),\n\n     ```js\n\n//\n//Listener on http://www.some-receiver.com/\nwindow.addEventListener(\"message\", function(message){\nif(/^http://www\\.some-sender\\.com$/.test(message.origin)){\nconsole.log('You received the data from valid sender', message.data);\n}\n});\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Can I avoid using postMessages completely</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You cannot avoid using postMessages completely(or 100%). Even though your application doesn't use postMessage considering the risks, a lot of third party scripts use postMessage to communicate with the third party service. So your application might be using postMessage without your knowledge.</code></pre></div>\n</li>\n<li>\n<p>Is postMessages synchronous</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The postMessages are synchronous in IE8 browser but they are asynchronous in IE9 and all other modern browsers (i.e, IE9+, Firefox, Chrome, Safari).Due to this asynchronous behaviour, we use a callback mechanism when the postMessage is returned.</code></pre></div>\n</li>\n<li>\n<p>What paradigm is Javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a multi-paradigm language, supporting imperative/procedural programming, Object-Oriented Programming and functional programming. JavaScript supports Object-Oriented Programming with prototypical inheritance.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between internal and external javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**Internal JavaScript:** It is the source code within the script tag.\n**External JavaScript:** The source code is stored in an external file(stored with .js extension) and referred with in the tag.</code></pre></div>\n</li>\n<li>\n<p>Is JavaScript faster than server side script</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, JavaScript is faster than server side script. Because JavaScript is a client-side script it does not require any web server's help for its computation or calculation. So JavaScript is always faster than any server-side script like ASP, PHP, etc.</code></pre></div>\n</li>\n<li>\n<p>How do you get the status of a checkbox</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can apply the `checked` property on the selected checkbox in the DOM. If the value is `True` means the checkbox is checked otherwise it is unchecked. For example, the below HTML checkbox element can be access using javascript as below,\n\n     ```html\n     &lt;input type=\"checkbox\" name=\"checkboxname\" value=\"Agree\" /> Agree the conditions&lt;br />\n     ```\n\n     ```js\n\n//\nconsole.log(document.getElementById('checkboxname').checked); // true or false\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of double tilde operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The double tilde operator(~~) is known as double NOT bitwise operator. This operator is going to be a quicker substitute for Math.floor().</code></pre></div>\n</li>\n<li>\n<p>How do you convert character to ASCII code</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `String.prototype.charCodeAt()` method to convert string characters to ASCII numbers. For example, let's find ASCII code for the first letter of 'ABC' string,\n\n     ```js\n\n//\n'ABC'.charCodeAt(0); // returns 65\n\n````\n\n     Whereas `String.fromCharCode()` method converts numbers to equal ASCII characters.\n\n     ```js\n\n//\nString.fromCharCode(65, 66, 67); // returns 'ABC'\n````</code></pre></div>\n</li>\n<li>\n<p>What is ArrayBuffer</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You can create it as below,\n\n     ```js\n\n//\nlet buffer = new ArrayBuffer(16); // create a buffer of length 16\nalert(buffer.byteLength); // 16\n\n````\n\n     To manipulate an ArrayBuffer, we need to use a \"view\" object.\n\n     ```js\n\n//\n//Create a DataView referring to the buffer\nlet view = new DataView(buffer);\n````</code></pre></div>\n</li>\n<li>\n<p>What is the output of below string expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ```js\n\n//\nconsole.log('Welcome to JS world'[0]);\n\n```\n\n     The output of the above expression is \"W\".\n     **Explanation:** The bracket notation with specific index on a string returns the character at a specific location. Hence, it returns the character \"W\" of the string. Since this is not supported in IE7 and below versions, you may need to use the .charAt() method to get the desired result.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of Error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Error constructor creates an error object and the instances of error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. The syntax of error object would be as below,\n\n     ```js\n\n//\nnew Error([message[, fileName[, lineNumber]]])\n\n````\n\n     You can throw user defined exceptions or errors using Error object in try...catch block as below,\n\n     ```js\n\n//\ntry {\nif (withdraw > balance) throw new Error(\"Oops! You don't have enough balance\");\n} catch (e) {\nconsole.log(e.name + ': ' + e.message);\n}\n````</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of EvalError object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The EvalError object indicates an error regarding the global `eval()` function. Even though this exception is not thrown by JavaScript anymore, the EvalError object remains for compatibility. The syntax of this expression would be as below,\n\n     ```js\n\n//\nnew EvalError([message[, fileName[, lineNumber]]])\n\n````\n\n     You can throw EvalError with in try...catch block as below,\n\n     ```js\n\n//\ntry {\nthrow new EvalError('Eval function error', 'someFile.js', 100);\n} catch (e) {\nconsole.log(e.message, e.name, e.fileName); // \"Eval function error\", \"EvalError\", \"someFile.js\"\n````</code></pre></div>\n</li>\n<li>\n<p>What are the list of cases error thrown from non-strict mode to strict mode</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     When you apply 'use strict'; syntax, some of the below cases will throw a SyntaxError before executing the script\n\n     1. When you use Octal syntax\n\n     ```js\n\n//\nvar n = 022;\n\n````\n\n     1. Using `with` statement\n     2. When you use delete operator on a variable name\n     3. Using eval or arguments as variable or function argument name\n     4. When you use newly reserved keywords\n     5. When you declare a function in a block\n\n     ```js\n\n//\nif (someCondition) {\nfunction f() {}\n}\n````\n\n     Hence, the errors from above cases are helpful to avoid errors in development/production environments.</code></pre></div>\n</li>\n<li>\n<p>Do all objects have prototypes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No. All objects have prototypes except for the base object which is created by the user, or an object that is created using the new keyword.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between a parameter and an argument</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Parameter is the variable name of a function definition whereas an argument represents the value given to a function when it is invoked. Let's explain this with a simple function\n\n     ```js\n\n//\nfunction myFunction(parameter1, parameter2, parameter3) {\nconsole.log(arguments[0]); // \"argument1\"\nconsole.log(arguments[1]); // \"argument2\"\nconsole.log(arguments[2]); // \"argument3\"\n}\nmyFunction('argument1', 'argument2', 'argument3');\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of some method in arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The some() method is used to test whether at least one element in the array passes the test implemented by the provided function. The method returns a boolean value. Let's take an example to test for any odd elements,\n\n     ```js\n\n//\nvar array = [1, 2, 3, 4, 5, 6 ,7, 8, 9, 10];\n\n     var odd = element ==> element % 2 !== 0;\n\n     console.log(array.some(odd)); // true (the odd element exists)\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you combine two or more arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The concat() method is used to join two or more arrays by returning a new array containing all the elements. The syntax would be as below,\n\n     ```js\n\n//\narray1.concat(array2, array3, ..., arrayX)\n\n````\n\n     Let's take an example of array's concatenation with veggies and fruits arrays,\n\n     ```js\n\n//\nvar veggies = ['Tomato', 'Carrot', 'Cabbage'];\nvar fruits = ['Apple', 'Orange', 'Pears'];\nvar veggiesAndFruits = veggies.concat(fruits);\nconsole.log(veggiesAndFruits); // Tomato, Carrot, Cabbage, Apple, Orange, Pears\n````</code></pre></div>\n</li>\n<li>\n<p>What is the difference between Shallow and Deep copy</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are two ways to copy an object,\n\n     **Shallow Copy:**\n     Shallow copy is a bitwise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied.\n\n     **Example**\n\n     ```js\n\n//\nvar empDetails = {\nname: 'John',\nage: 25,\nexpertise: 'Software Developer'\n};\n\n````\n\n     to create a duplicate\n\n     ```js\n\n//\nvar empDetailsShallowCopy = empDetails; //Shallow copying!\n````\n\n     if we change some property value in the duplicate one like this:\n\n     ```js\n\n//\nempDetailsShallowCopy.name = 'Johnson';\n\n````\n\n     The above statement will also change the name of `empDetails`, since we have a shallow copy. That means we're losing the original data as well.\n\n     **Deep copy:**\n     A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.\n\n     **Example**\n\n     ```js\n\n//\nvar empDetails = {\nname: 'John',\nage: 25,\nexpertise: 'Software Developer'\n};\n````\n\n     Create a deep copy by using the properties from the original object into new variable\n\n     ```js\n\n//\nvar empDetailsDeepCopy = {\nname: empDetails.name,\nage: empDetails.age,\nexpertise: empDetails.expertise\n};\n\n```\n\n     Now if you change `empDetailsDeepCopy.name`, it will only affect `empDetailsDeepCopy` &amp; not `empDetails`\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create specific number of copies of a string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `repeat()` method is used to construct and return a new string which contains the specified number of copies of the string on which it was called, concatenated together. Remember that this method has been added to the ECMAScript 2015 specification.\n     Let's take an example of Hello string to repeat it 4 times,\n\n     ```js\n\n//\n'Hello'.repeat(4); // 'HelloHelloHelloHello'\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you return all matching strings against a regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `matchAll()` method can be used to return an iterator of all results matching a string against a regular expression. For example, the below example returns an array of matching string results against a regular expression,\n\n     ```js\n\n//\nlet regexp = /Hello(\\d?))/g;\nlet greeting = 'Hello1Hello2Hello3';\n\n     let greetingList = [...greeting.matchAll(regexp)];\n\n     console.log(greetingList[0]); //Hello1\n     console.log(greetingList[1]); //Hello2\n     console.log(greetingList[2]); //Hello3\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you trim a string at the beginning or ending</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `trim` method of string prototype is used to trim on both sides of a string. But if you want to trim especially at the beginning or ending of the string then you can use `trimStart/trimLeft` and `trimEnd/trimRight` methods. Let's see an example of these methods on a greeting message,\n\n     ```js\n\n//\nvar greeting = ' Hello, Goodmorning! ';\n\n     console.log(greeting); // \"   Hello, Goodmorning!   \"\n     console.log(greeting.trimStart()); // \"Hello, Goodmorning!   \"\n     console.log(greeting.trimLeft()); // \"Hello, Goodmorning!   \"\n\n     console.log(greeting.trimEnd()); // \"   Hello, Goodmorning!\"\n     console.log(greeting.trimRight()); // \"   Hello, Goodmorning!\"\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below console statement with unary operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Let's take console statement with unary operator as given below,\n\n     ```js\n\n//\nconsole.log(+'Hello');\n\n```\n\n     The output of the above console log statement returns NaN. Because the element is prefixed by the unary operator and the JavaScript interpreter will try to convert that element into a number type. Since the conversion fails, the value of the statement results in NaN value.\n\n```</code></pre></div>\n</li>\n<li>Does javascript uses mixins</li>\n<li>\n<p>What is a thunk function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A thunk is just a function which delays the evaluation of the value. It doesn't take any arguments but gives the value whenever you invoke the thunk. i.e, It is used not to execute now but it will be sometime in the future. Let's take a synchronous example,\n\n     ```js\n\n//\nconst add = (x, y) => x + y;\n\n     const thunk = () => add(2, 3);\n\n     thunk(); // 5\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are asynchronous thunks</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The asynchronous thunks are useful to make network requests. Let's see an example of network requests,\n\n     ```js\n\n//\nfunction fetchData(fn) {\nfetch('https://jsonplaceholder.typicode.com/todos/1')\n.then((response) => response.json())\n.then((json) => fn(json));\n}\n\n     const asyncThunk = function () {\n         return fetchData(function getData(data) {\n             console.log(data);\n         });\n     };\n\n     asyncThunk();\n     ```\n\n     The `getData` function won't be called immediately but it will be invoked only when the data is available from API endpoint. The setTimeout function is also used to make our code asynchronous. The best real time example is redux state management library which uses the asynchronous thunks to delay the actions to dispatch.</code></pre></div>\n</li>\n<li>\n<p>What is the output of below function calls</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     **Code snippet:**\n\n     ```js\n\n//\nconst circle = {\nradius: 20,\ndiameter() {\nreturn this.radius _ 2;\n},\nperimeter: () => 2 _ Math.PI \\* this.radius\n};\n\n```\n\n     console.log(circle.diameter());\n     console.log(circle.perimeter());\n\n     **Output:**\n\n     The output is 40 and NaN. Remember that diameter is a regular function, whereas the value of perimeter is an arrow function. The `this` keyword of a regular function(i.e, diameter) refers to the surrounding scope which is a class(i.e, Shape object). Whereas this keyword of perimeter function refers to the surrounding scope which is a window object. Since there is no radius property on window objects it returns an undefined value and the multiple of number value returns NaN value.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How to remove all line breaks from a string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The easiest approach is using regular expressions to detect and replace newlines in the string. In this case, we use replace function along with string to replace with, which in our case is an empty string.\n\n     ```js\n\n//\nfunction remove_linebreaks( var message ) {\nreturn message.replace( /[\\r\\n]+/gm, \"\" );\n}\n\n```\n\n     In the above expression, g and m are for global and multiline flags.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between reflow and repaint</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A _repaint_ occurs when changes are made which affect the visibility of an element, but not its layout. Examples of this include outline, visibility, or background color. A _reflow_ involves changes that affect the layout of a portion of the page (or the whole page). Resizing the browser window, changing the font, content changing (such as user typing text), using JavaScript methods involving computed styles, adding or removing elements from the DOM, and changing an element's classes are a few of the things that can trigger reflow. Reflow of an element causes the subsequent reflow of all child and ancestor elements as well as any elements following it in the DOM.</code></pre></div>\n</li>\n<li>\n<p>What happens with negating an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Negating an array with `!` character will coerce the array into a boolean. Since Arrays are considered to be truthy So negating it will return `false`.\n\n     ```js\n\n//\nconsole.log(![]); // false\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What happens if we add two arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If you add two arrays together, it will convert them both to strings and concatenate them. For example, the result of adding arrays would be as below,\n\n     ```js\n\n//\nconsole.log(['a'] + ['b']); // \"ab\"\nconsole.log([] + []); // \"\"\nconsole.log(![] + []); // \"false\", because ![] returns false.\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of prepend additive operator on falsy values</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If you prepend the additive(+) operator on falsy values(null, undefined, NaN, false, \"\"), the falsy value converts to a number value zero. Let's display them on browser console as below,\n\n     ```js\n\n//\nconsole.log(+null); // 0\nconsole.log(+undefined); // NaN\nconsole.log(+false); // 0\nconsole.log(+NaN); // NaN\nconsole.log(+''); // 0\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create self string using special characters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The self string can be formed with the combination of `[]()!+` characters. You need to remember the below conventions to achieve this pattern.\n\n     1. Since Arrays are truthful values, negating the arrays will produce false: ![] === false\n     2. As per JavaScript coercion rules, the addition of arrays together will toString them: [] + [] === \"\"\n     3. Prepend an array with + operator will convert an array to false, the negation will make it true and finally converting the result will produce value '1': +(!(+[])) === 1\n\n     By applying the above rules, we can derive below conditions\n\n     ```js\n\n//\n(![] + [] === 'false' + !+[]) === 1;\n\n````\n\n     Now the character pattern would be created as below,\n\n     ```js\n\n//\ns e l f\n^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^\n\n      (![] + [])[3] + (![] + [])[4] + (![] + [])[2] + (![] + [])[0]\n      ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^\n     (![] + [])[+!+[]+!+[]+!+[]] +\n     (![] + [])[+!+[]+!+[]+!+[]+!+[]] +\n     (![] + [])[+!+[]+!+[]] +\n     (![] + [])[+[]]\n     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n     (![]+[])[+!+[]+!+[]+!+[]]+(![]+[])[+!+[]+!+[]+!+[]+!+[]]+(![]+[])[+!+[]+!+[]]+(![]+[])[+[]]\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do you remove falsy values from an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can apply the filter method on the array by passing Boolean as a parameter. This way it removes all falsy values(0, undefined, null, false and \"\") from the array.\n\n     ```js\n\n//\nconst myArray = [false, null, 1, 5, undefined];\nmyArray.filter(Boolean); // [1, 5] // is same as myArray.filter(x => x);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get unique values of an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can get unique values of an array with the combination of `Set` and rest expression/spread(...) syntax.\n\n     ```js\n\n//\nconsole.log([...new Set([1, 2, 4, 4, 3])]); // [1, 2, 4, 3]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is destructuring aliases</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Sometimes you would like to have a destructured variable with a different name than the property name. In that case, you'll use a `: newName` to specify a name for the variable. This process is called destructuring aliases.\n\n     ```js\n\n//\nconst obj = { x: 1 };\n// Grabs obj.x as as { otherName }\nconst { x: otherName } = obj;\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you map the array values without using map method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can map the array values without using the `map` method by just using the `from` method of Array. Let's map city names from Countries array,\n\n     ```js\n\n//\nconst countries = [\n{ name: 'India', capital: 'Delhi' },\n{ name: 'US', capital: 'Washington' },\n{ name: 'Russia', capital: 'Moscow' },\n{ name: 'Singapore', capital: 'Singapore' },\n{ name: 'China', capital: 'Beijing' },\n{ name: 'France', capital: 'Paris' }\n];\n\n     const cityNames = Array.from(countries, ({ capital }) => capital);\n     console.log(cityNames); // ['Delhi, 'Washington', 'Moscow', 'Singapore', 'Beijing', 'Paris']\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you empty an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can empty an array quickly by setting the array length to zero.\n\n     ```js\n\n//\nlet cities = ['Singapore', 'Delhi', 'London'];\ncities.length = 0; // cities becomes []\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you rounding numbers to certain decimals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can round numbers to a certain number of decimals using `toFixed` method from native javascript.\n\n     ```js\n\n//\nlet pie = 3.141592653;\npie = pie.toFixed(3); // 3.142\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to convert an array to an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can convert an array to an object with the same data using spread(...) operator.\n\n     ```js\n\n//\nvar fruits = ['banana', 'apple', 'orange', 'watermelon'];\nvar fruitsObject = { ...fruits };\nconsole.log(fruitsObject); // {0: \"banana\", 1: \"apple\", 2: \"orange\", 3: \"watermelon\"}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create an array with some data</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can create an array with some data or an array with the same values using `fill` method.\n\n     ```js\n\n//\nvar newArray = new Array(5).fill('0');\nconsole.log(newArray); // [\"0\", \"0\", \"0\", \"0\", \"0\"]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the placeholders from console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Below are the list of placeholders available from console object,\n\n     1. %o — It takes an object,\n     2. %s — It takes a string,\n     3. %d — It is used for a decimal or integer\n        These placeholders can be represented in the console.log as below\n\n     ```js\n\n//\nconst user = { name: 'John', id: 1, city: 'Delhi' };\nconsole.log('Hello %s, your details %o are available in the object form', 'John', user); // Hello John, your details {name: \"John\", id: 1, city: \"Delhi\"} are available in object\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is it possible to add CSS to console messages</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, you can apply CSS styles to console messages similar to html text on the web page.\n\n     ```js\n\n//\nconsole.log('%c The text has blue color, with large font and red background', 'color: blue; font-size: x-large; background: red');\n\n```\n\n     The text will be displayed as below,\n     ![Screenshot](images/console-css.png)\n\n     **Note:** All CSS styles can be applied to console messages.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of dir method of console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `console.dir()` is used to display an interactive list of the properties of the specified JavaScript object as JSON.\n\n     ```js\n\n//\nconst user = { name: 'John', id: 1, city: 'Delhi' };\nconsole.dir(user);\n\n```\n\n     The user object displayed in JSON representation\n     ![Screenshot](images/console-dir.png)\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is it possible to debug HTML elements in console</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, it is possible to get and debug HTML elements in the console just like inspecting elements.\n\n     ```js\n\n//\nconst element = document.getElementsByTagName('body')[0];\nconsole.log(element);\n\n```\n\n     It prints the HTML element in the console,\n\n     ![Screenshot](images/console-html.png)\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you display data in a tabular format using console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `console.table()` is used to display data in the console in a tabular format to visualize complex arrays or objects.\n\n     ```js\n\n//\nconst users = [\n{ name: 'John', id: 1, city: 'Delhi' },\n{ name: 'Max', id: 2, city: 'London' },\n{ name: 'Rod', id: 3, city: 'Paris' }\n];\nconsole.table(users);\n\n```\n\n     The data visualized in a table format,\n\n     ![Screenshot](images/console-table.png)\n     **Not:** Remember that `console.table()` is not supported in IE.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you verify that an argument is a Number or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The combination of IsNaN and isFinite methods are used to confirm whether an argument is a number or not.\n\n     ```js\n\n//\nfunction isNumber(n) {\nreturn !isNaN(parseFloat(n)) &amp;&amp; isFinite(n);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create copy to clipboard button</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You need to select the content(using .select() method) of the input element and execute the copy command with execCommand (i.e, execCommand('copy')). You can also execute other system commands like cut and paste.\n\n     ```js\n\n//\ndocument.querySelector('#copy-button').onclick = function () {\n// Select the content\ndocument.querySelector('#copy-input').select();\n// Copy to the clipboard\ndocument.execCommand('copy');\n};\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the shortcut to get timestamp</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `new Date().getTime()` to get the current timestamp. There is an alternative shortcut to get the value.\n\n     ```js\n\n//\nconsole.log(+new Date());\nconsole.log(Date.now());\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you flattening multi dimensional arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Flattening bi-dimensional arrays is trivial with Spread operator.\n\n     ```js\n\n//\nconst biDimensionalArr = [11, [22, 33], [44, 55], [66, 77], 88, 99];\nconst flattenArr = [].concat(...biDimensionalArr); // [11, 22, 33, 44, 55, 66, 77, 88, 99]\n\n````\n\n     But you can make it work with multi-dimensional arrays by recursive calls,\n\n     ```js\n\n//\nfunction flattenMultiArray(arr) {\nconst flattened = [].concat(...arr);\nreturn flattened.some((item) => Array.isArray(item)) ? flattenMultiArray(flattened) : flattened;\n}\nconst multiDimensionalArr = [11, [22, 33], [44, [55, 66, [77, [88]], 99]]];\nconst flatArr = flattenMultiArray(multiDimensionalArr); // [11, 22, 33, 44, 55, 66, 77, 88, 99]\n````</code></pre></div>\n</li>\n<li>\n<p>What is the easiest multi condition checking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `indexOf` to compare input with multiple values instead of checking each value as one condition.\n\n     ```js\n\n//\n// Verbose approach\nif (input === 'first' || input === 1 || input === 'second' || input === 2) {\nsomeFunction();\n}\n// Shortcut\nif (['first', 1, 'second', 2].indexOf(input) !== -1) {\nsomeFunction();\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you capture browser back button</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `window.onbeforeunload` method is used to capture browser back button events. This is helpful to warn users about losing the current data.\n\n     ```js\n\n//\nwindow.onbeforeunload = function () {\nalert('You work will be lost');\n};\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you disable right click in the web page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The right click on the page can be disabled by returning false from the `oncontextmenu` attribute on the body element.\n\n     ```html\n     &lt;body oncontextmenu=\"return false;\">\n\n&lt;/body>\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are wrapper objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Primitive Values like string,number and boolean don't have properties and methods but they are temporarily converted or coerced to an object(Wrapper object) when you try to perform actions on them. For example, if you apply toUpperCase() method on a primitive string value, it does not throw an error but returns uppercase of the string.\n\n     ```js\n\n//\nlet name = 'john';\n\n     console.log(name.toUpperCase()); // Behind the scenes treated as console.log(new String(name).toUpperCase());\n     ```\n\n     i.e, Every primitive except null and undefined have Wrapper Objects and the list of wrapper objects are String,Number,Boolean,Symbol and BigInt.</code></pre></div>\n</li>\n<li>\n<p>What is AJAX</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">AJAX stands for Asynchronous JavaScript and XML and it is a group of related technologies(HTML, CSS, JavaScript, XMLHttpRequest API etc) used to display data asynchronously. i.e. We can send data to the server and get data from the server without reloading the web page.</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to deal with Asynchronous Code</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of different ways to deal with Asynchronous code.\n\n1. Callbacks\n2. Promises\n3. Async/await\n4. Third-party libraries such as async.js,bluebird etc</code></pre></div>\n</li>\n<li>\n<p>How to cancel a fetch request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Until a few days back, One shortcoming of native promises is no direct way to cancel a fetch request. But the new `AbortController` from js specification allows you to use a signal to abort one or multiple fetch calls.\n     The basic flow of cancelling a fetch request would be as below,\n\n     1. Create an `AbortController` instance\n     2. Get the signal property of an instance and pass the signal as a fetch option for signal\n     3. Call the AbortController's abort property to cancel all fetches that use that signal\n        For example, let's pass the same signal to multiple fetch calls will cancel all requests with that signal,\n\n     ```js\n\n//\nconst controller = new AbortController();\nconst { signal } = controller;\n\n     fetch('http://localhost:8000', { signal })\n         .then((response) => {\n             console.log(`Request 1 is complete!`);\n         })\n         .catch((e) => {\n             if (e.name === 'AbortError') {\n                 // We know it's been canceled!\n             }\n         });\n\n     fetch('http://localhost:8000', { signal })\n         .then((response) => {\n             console.log(`Request 2 is complete!`);\n         })\n         .catch((e) => {\n             if (e.name === 'AbortError') {\n                 // We know it's been canceled!\n             }\n         });\n\n     // Wait 2 seconds to abort both requests\n     setTimeout(() => controller.abort(), 2000);\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is web speech API</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Web speech API is used to enable modern browsers recognize and synthesize speech(i.e, voice data into web apps). This API has been introduced by W3C Community in the year 2012. It has two main parts,\n\n     1. **SpeechRecognition (Asynchronous Speech Recognition or Speech-to-Text):** It provides the ability to recognize voice context from an audio input and respond accordingly. This is accessed by the `SpeechRecognition` interface.\n        The below example shows on how to use this API to get text from speech,\n\n     ```js\n\n//\nwindow.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition; // webkitSpeechRecognition for Chrome and SpeechRecognition for FF\nconst recognition = new window.SpeechRecognition();\nrecognition.onresult = (event) => {\n// SpeechRecognitionEvent type\nconst speechToText = event.results[0][0].transcript;\nconsole.log(speechToText);\n};\nrecognition.start();\n\n````\n\n     In this API, browser is going to ask you for permission to use your microphone\n\n     1. **SpeechSynthesis (Text-to-Speech):** It provides the ability to recognize voice context from an audio input and respond. This is accessed by the `SpeechSynthesis` interface.\n        For example, the below code is used to get voice/speech from text,\n\n     ```js\n\n//\nif ('speechSynthesis' in window) {\nvar speech = new SpeechSynthesisUtterance('Hello World!');\nspeech.lang = 'en-US';\nwindow.speechSynthesis.speak(speech);\n}\n````\n\n     The above examples can be tested on chrome(33+) browser's developer console.\n     **Note:** This API is still a working draft and only available in Chrome and Firefox browsers(ofcourse Chrome only implemented the specification)</code></pre></div>\n</li>\n<li>\n<p>What is minimum timeout throttling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Both browser and NodeJS javascript environments throttles with a minimum delay that is greater than 0ms. That means even though setting a delay of 0ms will not happen instantaneously.\n     **Browsers:** They have a minimum delay of 4ms. This throttle occurs when successive calls are triggered due to callback nesting(certain depth) or after a certain number of successive intervals.\n     Note: The older browsers have a minimum delay of 10ms.\n     **Nodejs:** They have a minimum delay of 1ms. This throttle happens when the delay is larger than 2147483647 or less than 1.\n     The best example to explain this timeout throttling behavior is the order of below code snippet.\n\n     ```js\n\n//\nfunction runMeFirst() {\nconsole.log('My script is initialized');\n}\nsetTimeout(runMeFirst, 0);\nconsole.log('Script loaded');\n\n````\n\n     and the output would be in\n\n     ```shell\n     Script loaded\n     My script is initialized\n     ```\n\n     If you don't use `setTimeout`, the order of logs will be sequential.\n\n     ```js\n\n//\nfunction runMeFirst() {\nconsole.log('My script is initialized');\n}\nrunMeFirst();\nconsole.log('Script loaded');\n````\n\n     and the output is,\n\n     ```shell\n     My script is initialized\n     Script loaded\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you implement zero timeout in modern browsers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can't use setTimeout(fn, 0) to execute the code immediately due to minimum delay of greater than 0ms. But you can use window.postMessage() to achieve this behavior.</code></pre></div>\n</li>\n<li>\n<p>What are tasks in event loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A task is any javascript code/program which is scheduled to be run by the standard mechanisms such as initially starting to run a program, run an event callback, or an interval or timeout being fired. All these tasks are scheduled on a task queue.\nBelow are the list of use cases to add tasks to the task queue,\n\n1. When a new javascript program is executed directly from console or running by the `&lt;script>` element, the task will be added to the task queue.\n2. When an event fires, the event callback added to task queue\n3. When a setTimeout or setInterval is reached, the corresponding callback added to task queue</code></pre></div>\n</li>\n<li>\n<p>What is microtask</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Microtask is the javascript code which needs to be executed immediately after the currently executing task/microtask is completed. They are kind of blocking in nature. i.e, The main thread will be blocked until the microtask queue is empty.\nThe main sources of microtasks are Promise.resolve, Promise.reject, MutationObservers, IntersectionObservers etc\n\n**Note:** All of these microtasks are processed in the same turn of the event loop.</code></pre></div>\n</li>\n<li>What are different event loops</li>\n<li>What is the purpose of queueMicrotask</li>\n<li>\n<p>How do you use javascript libraries in typescript file</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is known that not all JavaScript libraries or frameworks have TypeScript declaration files. But if you still want to use libraries or frameworks in our TypeScript files without getting compilation errors, the only solution is `declare` keyword along with a variable declaration. For example, let's imagine you have a library called `customLibrary` that doesn't have a TypeScript declaration and have a namespace called `customLibrary` in the global namespace. You can use this library in typescript code as below,\n\n     ```js\n\n//\ndeclare var customLibrary;\n\n````\n\n     In the runtime, typescript will provide the type to the `customLibrary` variable as `any` type. The another alternative without using declare keyword is below\n\n     ```js\n\n//\nvar customLibrary: any;\n````</code></pre></div>\n</li>\n<li>\n<p>What are the differences between promises and observables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the major difference in a tabular form\n\n| Promises                                                           | Observables                                                                              |\n| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |\n| Emits only a single value at a time                                | Emits multiple values over a period of time(stream of values ranging from 0 to multiple) |\n| Eager in nature; they are going to be called immediately           | Lazy in nature; they require subscription to be invoked                                  |\n| Promise is always asynchronous even though it resolved immediately | Observable can be either synchronous or asynchronous                                     |\n| Doesn't provide any operators                                      | Provides operators such as map, forEach, filter, reduce, retry, and retryWhen etc        |\n| Cannot be canceled                                                 | Canceled by using unsubscribe() method                                                   |</code></pre></div>\n</li>\n<li>\n<p>What is heap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Heap(Or memory heap) is the memory location where objects are stored when we define variables. i.e, This is the place where all the memory allocations and de-allocation take place. Both heap and call-stack are two containers of JS runtime.\nWhenever runtime comes across variables and function declarations in the code it stores them in the Heap.\n\n![Screenshot](images/heap.png)</code></pre></div>\n</li>\n<li>\n<p>What is an event table</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Event Table is a data structure that stores and keeps track of all the events which will be executed asynchronously like after some time interval or after the resolution of some API requests. i.e Whenever you call a setTimeout function or invoke async operation, it is added to the Event Table.\nIt doesn't not execute functions on it's own. The main purpose of the event table is to keep track of events and send them to the Event Queue as shown in the below diagram.\n\n![Screenshot](images/event-table.png)</code></pre></div>\n</li>\n<li>\n<p>What is a microTask queue</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Microtask Queue is the new queue where all the tasks initiated by promise objects get processed before the callback queue.\nThe microtasks queue are processed before the next rendering and painting jobs. But if these microtasks are running for a long time then it leads to visual degradation.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between shim and polyfill</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A shim is a library that brings a new API to an older environment, using only the means of that environment. It isn't necessarily restricted to a web application. For example, es5-shim.js is used to emulate ES5 features on older browsers (mainly pre IE9).\nWhereas polyfill is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively.\nIn a simple sentence, A polyfill is a shim for a browser API.</code></pre></div>\n</li>\n<li>\n<p>How do you detect primitive or non primitive value type</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In JavaScript, primitive types include boolean, string, number, BigInt, null, Symbol and undefined. Whereas non-primitive types include the Objects. But you can easily identify them with the below function,\n\n     ```js\n\n//\nvar myPrimitive = 30;\nvar myNonPrimitive = {};\nfunction isPrimitive(val) {\nreturn Object(val) !== val;\n}\n\n     isPrimitive(myPrimitive);\n     isPrimitive(myNonPrimitive);\n     ```\n\n     If the value is a primitive data type, the Object constructor creates a new wrapper object for the value. But If the value is a non-primitive data type (an object), the Object constructor will give the same object.</code></pre></div>\n</li>\n<li>\n<p>What is babel</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Babel is a JavaScript transpiler to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments. Some of the main features are listed below,\n\n1. Transform syntax\n2. Polyfill features that are missing in your target environment (using @babel/polyfill)\n3. Source code transformations (or codemods)</code></pre></div>\n</li>\n<li>\n<p>Is Node.js completely single threaded</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Node is a single thread, but some of the functions included in the Node.js standard library(e.g, fs module functions) are not single threaded. i.e, Their logic runs outside of the Node.js single thread to improve the speed and performance of a program.</code></pre></div>\n</li>\n<li>\n<p>What are the common use cases of observables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the most common use cases of observables are web sockets with push notifications, user input changes, repeating intervals, etc</code></pre></div>\n</li>\n<li>\n<p>What is RxJS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">RxJS (Reactive Extensions for JavaScript) is a library for implementing reactive programming using observables that makes it easier to compose asynchronous or callback-based code. It also provides utility functions for creating and working with observables.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between Function constructor and function declaration</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The functions which are created with `Function constructor` do not create closures to their creation contexts but they are always created in the global scope. i.e, the function can access its own local variables and global scope variables only. Whereas function declarations can access outer function variables(closures) too.\n\n     Let's see this difference with an example,\n\n     **Function Constructor:**\n\n     ```js\n\n//\nvar a = 100;\nfunction createFunction() {\nvar a = 200;\nreturn new Function('return a;');\n}\nconsole.log(createFunction()()); // 100\n\n````\n\n     **Function declaration:**\n\n     ```js\n\n//\nvar a = 100;\nfunction createFunction() {\nvar a = 200;\nreturn function func() {\nreturn a;\n};\n}\nconsole.log(createFunction()()); // 200\n````</code></pre></div>\n</li>\n<li>\n<p>What is a Short circuit condition</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Short circuit conditions are meant for condensed way of writing simple if statements. Let's demonstrate the scenario using an example. If you would like to login to a portal with an authentication condition, the expression would be as below,\n\n     ```js\n\n//\nif (authenticate) {\nloginToPorta();\n}\n\n````\n\n     Since the javascript logical operators evaluated from left to right, the above expression can be simplified using &amp;&amp; logical operator\n\n     ```js\n\n//\nauthenticate &amp;&amp; loginToPorta();\n````</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to resize an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The length property of an array is useful to resize or empty an array quickly. Let's apply length property on number array to resize the number of elements from 5 to 2,\n\n     ```js\n\n//\nvar array = [1, 2, 3, 4, 5];\nconsole.log(array.length); // 5\n\n     array.length = 2;\n     console.log(array.length); // 2\n     console.log(array); // [1,2]\n     ```\n\n     and the array can be emptied too\n\n     ```js\n\n//\nvar array = [1, 2, 3, 4, 5];\narray.length = 0;\nconsole.log(array.length); // 0\nconsole.log(array); // []\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an observable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An Observable is basically a function that can return a stream of values either synchronously or asynchronously to an observer over time. The consumer can get the value by calling `subscribe()` method.\n     Let's look at a simple example of an Observable\n\n     ```js\n\n//\nimport { Observable } from 'rxjs';\n\n     const observable = new Observable((observer) => {\n         setTimeout(() => {\n             observer.next('Message from a Observable!');\n         }, 3000);\n     });\n\n     observable.subscribe((value) => console.log(value));\n     ```\n\n     ![Screenshot](images/observables.png)\n\n     **Note:** Observables are not part of the JavaScript language yet but they are being proposed to be added to the language</code></pre></div>\n</li>\n<li>\n<p>What is the difference between function and class declarations</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The main difference between function declarations and class declarations is `hoisting`. The function declarations are hoisted but not class declarations.\n\n     **Classes:**\n\n     ```js\n\n//\nconst user = new User(); // ReferenceError\n\n     class User {}\n     ```\n\n     **Constructor Function:**\n\n     ```js\n\n//\nconst user = new User(); // No error\n\n     function User() {}\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is an async function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An async function is a function declared with the `async` keyword which enables asynchronous, promise-based behavior to be written in a cleaner style by avoiding promise chains. These functions can contain zero or more `await` expressions.\n\n     Let's take a below async function example,\n\n     ```js\n\n//\nasync function logger() {\nlet data = await fetch('http://someapi.com/users'); // pause until fetch returns\nconsole.log(data);\n}\nlogger();\n\n```\n\n     It is basically syntax sugar over ES2015 promises and generators.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you prevent promises swallowing errors</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     While using asynchronous code, JavaScript's ES6 promises can make your life a lot easier without having callback pyramids and error handling on every second line. But Promises have some pitfalls and the biggest one is swallowing errors by default.\n\n     Let's say you expect to print an error to the console for all the below cases,\n\n     ```js\n\n//\nPromise.resolve('promised value').then(function () {\nthrow new Error('error');\n});\n\n     Promise.reject('error value').catch(function () {\n         throw new Error('error');\n     });\n\n     new Promise(function (resolve, reject) {\n         throw new Error('error');\n     });\n     ```\n\n     But there are many modern JavaScript environments that won't print any errors. You can fix this problem in different ways,\n\n     1. **Add catch block at the end of each chain:** You can add catch block to the end of each of your promise chains\n\n         ```js\n\n//\nPromise.resolve('promised value')\n.then(function () {\nthrow new Error('error');\n})\n.catch(function (error) {\nconsole.error(error.stack);\n});\n\n````\n\n         But it is quite difficult to type for each promise chain and verbose too.\n\n     2. **Add done method:** You can replace first solution's then and catch blocks with done method\n\n         ```js\n\n//\nPromise.resolve('promised value').done(function () {\nthrow new Error('error');\n});\n````\n\n         Let's say you want to fetch data using HTTP and later perform processing on the resulting data asynchronously. You can write `done` block as below,\n\n         ```js\n\n//\ngetDataFromHttp()\n.then(function (result) {\nreturn processDataAsync(result);\n})\n.done(function (processed) {\ndisplayData(processed);\n});\n\n````\n\n         In future, if the processing library API changed to synchronous then you can remove `done` block as below,\n\n         ```js\n\n//\ngetDataFromHttp().then(function (result) {\nreturn displayData(processDataAsync(result));\n});\n````\n\n         and then you forgot to add `done` block to `then` block leads to silent errors.\n\n     3. **Extend ES6 Promises by Bluebird:**\n        Bluebird extends the ES6 Promises API to avoid the issue in the second solution. This library has a \"default\" onRejection handler which will print all errors from rejected Promises to stderr. After installation, you can process unhandled rejections\n\n         ```js\n\n//\nPromise.onPossiblyUnhandledRejection(function (error) {\nthrow error;\n});\n\n````\n\n         and discard a rejection, just handle it with an empty catch\n\n         ```js\n\n//\nPromise.reject('error value').catch(function () {});\n````</code></pre></div>\n</li>\n<li>\n<p>What is deno</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 JavaScript engine and the Rust programming language.</code></pre></div>\n</li>\n<li>\n<p>How do you make an object iterable in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     By default, plain objects are not iterable. But you can make the object iterable by defining a `Symbol.iterator` property on it.\n\n     Let's demonstrate this with an example,\n\n     ```js\n\n//\nconst collection = {\none: 1,\ntwo: 2,\nthree: 3,\n[Symbol.iterator]() {\nconst values = Object.keys(this);\nlet i = 0;\nreturn {\nnext: () => {\nreturn {\nvalue: this[values[i++]],\ndone: i > values.length\n};\n}\n};\n}\n};\n\n     const iterator = collection[Symbol.iterator]();\n\n     console.log(iterator.next()); // → {value: 1, done: false}\n     console.log(iterator.next()); // → {value: 2, done: false}\n     console.log(iterator.next()); // → {value: 3, done: false}\n     console.log(iterator.next()); // → {value: undefined, done: true}\n     ```\n\n     The above process can be simplified using a generator function,\n\n     ```js\n\n//\nconst collection = {\none: 1,\ntwo: 2,\nthree: 3,\n[Symbol.iterator]: function\\* () {\nfor (let key in this) {\nyield this[key];\n}\n}\n};\nconst iterator = collection[Symbol.iterator]();\nconsole.log(iterator.next()); // {value: 1, done: false}\nconsole.log(iterator.next()); // {value: 2, done: false}\nconsole.log(iterator.next()); // {value: 3, done: false}\nconsole.log(iterator.next()); // {value: undefined, done: true}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a Proper Tail Call</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     First, we should know about tail call before talking about \"Proper Tail Call\". A tail call is a subroutine or function call performed as the final action of a calling function. Whereas **Proper tail call(PTC)** is a technique where the program or code will not create additional stack frames for a recursion when the function call is a tail call.\n\n     For example, the below classic or head recursion of factorial function relies on stack for each step. Each step need to be processed upto `n * factorial(n - 1)`\n\n     ```js\n\n//\nfunction factorial(n) {\nif (n === 0) {\nreturn 1;\n}\nreturn n \\* factorial(n - 1);\n}\nconsole.log(factorial(5)); //120\n\n````\n\n     But if you use Tail recursion functions, they keep passing all the necessary data it needs down the recursion without relying on the stack.\n\n     ```js\n\n//\nfunction factorial(n, acc = 1) {\nif (n === 0) {\nreturn acc;\n}\nreturn factorial(n - 1, n \\* acc);\n}\nconsole.log(factorial(5)); //120\n````\n\n     The above pattern returns the same output as the first one. But the accumulator keeps track of total as an argument without using stack memory on recursive calls.</code></pre></div>\n</li>\n<li>\n<p>How do you check an object is a promise or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If you don't know if a value is a promise or not, wrapping the value as `Promise.resolve(value)` which returns a promise\n\n     ```js\n\n//\nfunction isPromise(object) {\nif (Promise &amp;&amp; Promise.resolve) {\nreturn Promise.resolve(object) == object;\n} else {\nthrow 'Promise not supported in your environment';\n}\n}\n\n     var i = 1;\n     var promise = new Promise(function (resolve, reject) {\n         resolve();\n     });\n\n     console.log(isPromise(i)); // false\n     console.log(isPromise(p)); // true\n     ```\n\n     Another way is to check for `.then()` handler type\n\n     ```js\n\n//\nfunction isPromise(value) {\nreturn Boolean(value &amp;&amp; typeof value.then === 'function');\n}\nvar i = 1;\nvar promise = new Promise(function (resolve, reject) {\nresolve();\n});\n\n     console.log(isPromise(i)); // false\n     console.log(isPromise(promise)); // true\n     ```</code></pre></div>\n</li>\n<li>\n<p>How to detect if a function is called as constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `new.target` pseudo-property to detect whether a function was called as a constructor(using the new operator) or as a regular function call.\n\n     1. If a constructor or function invoked using the new operator, new.target returns a reference to the constructor or function.\n     2. For function calls, new.target is undefined.\n\n     ```js\n\n//\nfunction Myfunc() {\nif (new.target) {\nconsole.log('called with new');\n} else {\nconsole.log('not called with new');\n}\n}\n\n     new Myfunc(); // called with new\n     Myfunc(); // not called with new\n     Myfunc.call({}); not called with new\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between arguments object and rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are three main differences between arguments object and rest parameters\n\n1. The arguments object is an array-like but not an array. Whereas the rest parameters are array instances.\n2. The arguments object does not support methods such as sort, map, forEach, or pop. Whereas these methods can be used in rest parameters.\n3. The rest parameters are only the ones that haven't been given a separate name, while the arguments object contains all arguments passed to the function</code></pre></div>\n</li>\n<li>\n<p>What are the differences between spread operator and rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Rest parameter collects all remaining elements into an array. Whereas Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. i.e, Rest parameter is opposite to the spread operator.</code></pre></div>\n</li>\n<li>\n<p>What are the different kinds of generators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are five kinds of generators,\n\n     1. **Generator function declaration:**\n\n         ```js\n\n//\nfunction\\* myGenFunc() {\nyield 1;\nyield 2;\nyield 3;\n}\nconst genObj = myGenFunc();\n\n````\n\n     2. **Generator function expressions:**\n\n         ```js\n\n//\nconst myGenFunc = function\\* () {\nyield 1;\nyield 2;\nyield 3;\n};\nconst genObj = myGenFunc();\n````\n\n     3. **Generator method definitions in object literals:**\n\n         ```js\n\n//\nconst myObj = {\n\\*myGeneratorMethod() {\nyield 1;\nyield 2;\nyield 3;\n}\n};\nconst genObj = myObj.myGeneratorMethod();\n\n````\n\n     4. **Generator method definitions in class:**\n\n         ```js\n\n//\nclass MyClass {\n\\*myGeneratorMethod() {\nyield 1;\nyield 2;\nyield 3;\n}\n}\nconst myObject = new MyClass();\nconst genObj = myObject.myGeneratorMethod();\n````\n\n     5. **Generator as a computed property:**\n\n         ```js\n\n//\nconst SomeObj = { \\*[Symbol.iterator]() {\nyield 1;\nyield 2;\nyield 3;\n}\n};\n\n         console.log(Array.from(SomeObj)); // [ 1, 2, 3 ]\n         ```</code></pre></div>\n</li>\n<li>\n<p>What are the built-in iterables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of built-in iterables in javascript,\n\n1. Arrays and TypedArrays\n2. Strings: Iterate over each character or Unicode code-points\n3. Maps: iterate over its key-value pairs\n4. Sets: iterates over their elements\n5. arguments: An array-like special variable in functions\n6. DOM collection such as NodeList</code></pre></div>\n</li>\n<li>\n<p>What are the differences between for...of and for...in statements</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Both for...in and for...of statements iterate over js data structures. The only difference is over what they iterate:\n\n     1. for..in iterates over all enumerable property keys of an object\n     2. for..of iterates over the values of an iterable object.\n\n     Let's explain this difference with an example,\n\n     ```js\n\n//\nlet arr = ['a', 'b', 'c'];\n\n     arr.newProp = 'newVlue';\n\n     // key are the property keys\n     for (let key in arr) {\n         console.log(key);\n     }\n\n     // value are the property values\n     for (let value of arr) {\n         console.log(value);\n     }\n     ```\n\n     Since for..in loop iterates over the keys of the object, the first loop logs 0, 1, 2 and newProp while iterating over the array object. The for..of loop iterates over the values of a arr data structure and logs a, b, c in the console.</code></pre></div>\n</li>\n<li>\n<p>How do you define instance and non-instance properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Instance properties must be defined inside of class methods. For example, name and age properties defined insider constructor as below,\n\n     ```js\n\n//\nclass Person {\nconstructor(name, age) {\nthis.name = name;\nthis.age = age;\n}\n}\n\n````\n\n     But Static(class) and prototype data properties must be defined outside of the ClassBody declaration. Let's assign the age value for Person class as below,\n\n     ```js\n\n//\nPerson.staticAge = 30;\nPerson.prototype.prototypeAge = 40;\n````</code></pre></div>\n</li>\n<li>\n<p>What is the difference between isNaN and Number.isNaN?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1. **isNaN**: The global function `isNaN` converts the argument to a Number and returns true if the resulting value is NaN.\n     2. **Number.isNaN**: This method does not convert the argument. But it returns true when the type is a Number and value is NaN.\n\n     Let's see the difference with an example,\n\n     ```js\n\n//\nisNaN('hello'); // true\nNumber.isNaN('hello'); // false\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How to invoke an IIFE without any extra brackets?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Immediately Invoked Function Expressions(IIFE) requires a pair of parenthesis to wrap the function which contains set of statements.\n\n     ```js\n\n//\n(function (dt) {\nconsole.log(dt.toLocaleTimeString());\n})(new Date());\n\n````\n\n     Since both IIFE and void operator discard the result of an expression, you can avoid the extra brackets using `void operator` for IIFE as below,\n\n     ```js\n\n//\nvoid (function (dt) {\nconsole.log(dt.toLocaleTimeString());\n})(new Date());\n````</code></pre></div>\n</li>\n<li>\n<p>Is that possible to use expressions in switch cases?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You might have seen expressions used in switch condition but it is also possible to use for switch cases by assigning true value for the switch condition. Let's see the weather condition based on temparature as an example,\n\n     ```js\n\n//\nconst weather = (function getWeather(temp) {\nswitch (true) {\ncase temp &lt; 0:\nreturn 'freezing';\ncase temp &lt; 10:\nreturn 'cold';\ncase temp &lt; 24:\nreturn 'cool';\ndefault:\nreturn 'unknown';\n}\n})(10);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to ignore promise errors?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The easiest and safest way to ignore promise errors is void that error. This approach is ESLint friendly too.\n\n     ```js\n\n//\nawait promise.catch((e) => void e);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do style the console output using CSS?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can add CSS styling to the console output using the CSS format content specifier %c. The console string message can be appended after the specifier and CSS style in another argument. Let's print the red the color text using console.log and CSS specifier as below,\n\n     ```js\n\n//\nconsole.log('%cThis is a red text', 'color:red');\n\n````\n\n     It is also possible to add more styles for the content. For example, the font-size can be modified for the above text\n\n     ```js\n\n//\nconsole.log('%cThis is a red text with bigger font', 'color:red; font-size:20px');\n````</code></pre></div>\n</li>\n<li>\n<p>What is nullish coalescing operator (??)?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. This can be contrasted with the logical OR (||) operator, which returns the right-hand side operand if the left operand is any falsy value, not only null or undefined.\n\n     ```js\n\n//\nconsole.log(null ?? true); // true\nconsole.log(false ?? true); // false\nconsole.log(undefined ?? true); // true\n\n```\n\n```</code></pre></div>\n</li>\n</ol>\n<h3>Coding Exercise</h3>\n<h4>1. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Vehicle</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Honda'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'white'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'2010'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'UK'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Vehicle</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">model<span class=\"token punctuation\">,</span> color<span class=\"token punctuation\">,</span> year<span class=\"token punctuation\">,</span> country</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>year <span class=\"token operator\">=</span> year<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>country <span class=\"token operator\">=</span> country<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Undefined</li>\n<li>2: ReferenceError</li>\n<li>3: null</li>\n<li>4: {model: \"Honda\", color: \"white\", year: \"2010\", country: \"UK\"}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The function declarations are hoisted similar to any variables. So the placement for <code class=\"language-text\">Vehicle</code> function declaration doesn't make any difference.</p>\n</p>\n</details>\n<hr>\n<h4>2. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> x <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    x<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    y<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> x<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> x<span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, undefined and undefined</li>\n<li>2: ReferenceError: X is not defined</li>\n<li>3: 1, undefined and number</li>\n<li>4: 1, number and number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Of course the return value of <code class=\"language-text\">foo()</code> is 1 due to the increment operator. But the statement <code class=\"language-text\">let x = y = 0</code> declares a local variable x. Whereas y declared as a global variable accidentally. This statement is equivalent to,</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> x<span class=\"token punctuation\">;</span>\nwindow<span class=\"token punctuation\">.</span>y <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\nx <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span>y<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Since the block scoped variable x is undefined outside of the function, the type will be undefined too. Whereas the global variable <code class=\"language-text\">y</code> is available outside the function, the value is 0 and type is number.</p>\n</p>\n</details>\n<hr>\n<h4>3. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">main</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'B'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'C'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">m</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>A, B and C</li>\n<li>2: B, A and C</li>\n<li>3: A and C</li>\n<li>4: A, C and B</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The statements order is based on the event loop mechanism. The order of statements follows the below order,</p>\n<ol>\n<li>At first, the main function is pushed to the stack.</li>\n<li>Then the browser pushes the fist statement of the main function( i.e, A's console.log) to the stack, executing and popping out immediately.</li>\n<li>But <code class=\"language-text\">setTimeout</code> statement moved to Browser API to apply the delay for callback.</li>\n<li>In the meantime, C's console.log added to stack, executed and popped out.</li>\n<li>The callback of <code class=\"language-text\">setTimeout</code> moved from Browser API to message queue.</li>\n<li>The <code class=\"language-text\">main</code> function popped out from stack because there are no statements to execute</li>\n<li>The callback moved from message queue to the stack since the stack is empty.</li>\n<li>The console.log for B is added to the stack and display on the console.</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>4. What is the output of below equality check</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span> <span class=\"token operator\">===</span> <span class=\"token number\">0.3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>This is due to the float point math problem. Since the floating point numbers are encoded in binary format, the addition operations on them lead to rounding errors. Hence, the comparison of floating points doesn't give expected results.\nYou can find more details about the explanation here <a href=\"https://0.30000000000000004.com/\">0.30000000000000004.com/</a></p>\n</p>\n</details>\n<hr>\n<h4>5. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    y <span class=\"token operator\">+=</span> <span class=\"token keyword\">typeof</span> f<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1function</li>\n<li>2: 1object</li>\n<li>3: ReferenceError</li>\n<li>4: 1undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The main points in the above code snippets are,</p>\n<ol>\n<li>You can see function expression instead function declaration inside if statement. So it always returns true.</li>\n<li>Since it is not declared(or assigned) anywhere, f is undefined and typeof f is undefined too.</li>\n</ol>\n<p>In other words, it is same as</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    y <span class=\"token operator\">+=</span> <span class=\"token keyword\">typeof</span> f<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Note:</strong> It returns 1object for MS Edge browser</p>\n</p>\n</details>\n<hr>\n<h4>6. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Hello World</li>\n<li>2: Object {message: \"Hello World\"}</li>\n<li>3: Undefined</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>This is a semicolon issue. Normally semicolons are optional in JavaScript. So if there are any statements(in this case, return) missing semicolon, it is automatically inserted immediately. Hence, the function returned as undefined.</p>\n<p>Whereas if the opening curly brace is along with the return keyword then the function is going to be returned as expected.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {message: \"Hello World\"}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>7. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> myChars <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">delete</span> myChars<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[empty, 'b', 'c', 'd'], empty, 3</li>\n<li>2: [null, 'b', 'c', 'd'], empty, 3</li>\n<li>3: [empty, 'b', 'c', 'd'], undefined, 4</li>\n<li>4: [null, 'b', 'c', 'd'], undefined, 4</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The <code class=\"language-text\">delete</code> operator will delete the object property but it will not reindex the array or change its length. So the number or elements or length of the array won't be changed.\nIf you try to print myChars then you can observe that it doesn't set an undefined value, rather the property is removed from the array. The newer versions of Chrome use <code class=\"language-text\">empty</code> instead of <code class=\"language-text\">undefined</code> to make the difference a bit clearer.</p>\n</p>\n</details>\n<hr>\n<h4>8. What is the output of below code in latest Chrome</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> array1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> array2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\narray2<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> array3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[undefined × 3], [undefined × 2, 100], [undefined × 3]</li>\n<li>2: [empty × 3], [empty × 2, 100], [empty × 3]</li>\n<li>3: [null × 3], [null × 2, 100], [null × 3]</li>\n<li>4: [], [100], []</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The latest chrome versions display <code class=\"language-text\">sparse array</code>(they are filled with holes) using this empty x n notation. Whereas the older versions have undefined x n notation.\n<strong>Note:</strong> The latest version of FF displays <code class=\"language-text\">n empty slots</code> notation.</p>\n</p>\n</details>\n<hr>\n<h4>9. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">prop1</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">prop2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'prop'</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop3</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>0, 1, 2</li>\n<li>2: 0, { return 1 }, 2</li>\n<li>3: 0, { return 1 }, { return 2 }</li>\n<li>4: 0, 1, undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>ES6 provides method definitions and property shorthands for objects. So both prop2 and prop3 are treated as regular function values.</p>\n</p>\n</details>\n<hr>\n<h4>10. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">2</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span> <span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>true, true</li>\n<li>2: true, false</li>\n<li>3: SyntaxError, SyntaxError,</li>\n<li>4: false, false</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The important point is that if the statement contains the same operators(e.g, &#x3C; or >) then it can be evaluated from left to right.\nThe first statement follows the below order,</p>\n<ol>\n<li>console.log(1 &#x3C; 2 &#x3C; 3);</li>\n<li>console.log(true &#x3C; 3);</li>\n<li>console.log(1 &#x3C; 3); // True converted as <code class=\"language-text\">1</code> during comparison</li>\n<li>True</li>\n</ol>\n<p>Whereas the second statement follows the below order,</p>\n<ol>\n<li>console.log(3 > 2 > 1);</li>\n<li>console.log(true > 1);</li>\n<li>console.log(1 > 1); // False converted as <code class=\"language-text\">0</code> during comparison</li>\n<li>False</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>11. What is the output of below code in non-strict mode</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">printNumbers</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\np <span class=\"token function\">tNumbers</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, 2, 3</li>\n<li>2: 3, 2, 3</li>\n<li>3: SyntaxError: Duplicate parameter name not allowed in this context</li>\n<li>4: 1, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>In non-strict mode, the regular JavaScript functions allow duplicate named parameters. The above code snippet has duplicate parameters on 1st and 3rd parameters.\nThe value of the first parameter is mapped to the third argument which is passed to the function. Hence, the 3rd argument overrides the first parameter.</p>\n<p><strong>Note:</strong> In strict mode, duplicate parameters will throw a Syntax Error.</p>\n</p>\n</details>\n<hr>\n<h4>12. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">printNumbersArrow</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\np <span class=\"token function\">tNumbersArrow</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, 2, 3</li>\n<li>2: 3, 2, 3</li>\n<li>3: SyntaxError: Duplicate parameter name not allowed in this context</li>\n<li>4: 1, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Unlike regular functions, the arrow functions doesn't not allow duplicate parameters in either strict or non-strict mode. So you can see <code class=\"language-text\">SyntaxError</code> in the console.</p>\n</p>\n</details>\n<hr>\n<h4>13. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">arrowFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">arrowFunc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>ReferenceError: arguments is not defined</li>\n<li>2: 3</li>\n<li>3: undefined</li>\n<li>4: null</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Arrow functions do not have an <code class=\"language-text\">arguments, super, this, or new.target</code> bindings. So any reference to <code class=\"language-text\">arguments</code> variable tries to resolve to a binding in a lexically enclosing environment. In this case, the arguments variable is not defined outside of the arrow function. Hence, you will receive a reference error.</p>\n<p>Where as the normal function provides the number of arguments passed to the function</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">func</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>But If you still want to use an arrow function then rest operator on arguments provides the expected arguments</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">arrowFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>args</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> args<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">arrowFunc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>14. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>trimLeft<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'trimLeft'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>trimLeft<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'trimStart'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: True, False</li>\n<li>2: False, True</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>In order to be consistent with functions like <code class=\"language-text\">String.prototype.padStart</code>, the standard method name for trimming the whitespaces is considered as <code class=\"language-text\">trimStart</code>. Due to web web compatibility reasons, the old method name 'trimLeft' still acts as an alias for 'trimStart'. Hence, the prototype for 'trimLeft' is always 'trimStart'</p>\n</p>\n</details>\n<hr>\n<h4>15. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined</li>\n<li>2: Infinity</li>\n<li>3: 0</li>\n<li>4: -Infinity</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>-Infinity is the initial comparant because almost every other value is bigger. So when no arguments are provided, -Infinity is going to be returned.\n<strong>Note:</strong> Zero number of arguments is a valid case.</p>\n</p>\n</details>\n<hr>\n<h4>16. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">==</span> <span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">==</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>True, True</li>\n<li>2: True, False</li>\n<li>3: False, False</li>\n<li>4: False, True</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>As per the comparison algorithm in the ECMAScript specification(ECMA-262), the above expression converted into JS as below</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token number\">10</span> <span class=\"token operator\">===</span> <span class=\"token function\">Number</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">valueOf</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 10</span></code></pre></div>\n<p>So it doesn't matter about number brackets([]) around the number, it is always converted to a number in the expression.</p>\n</p>\n</details>\n<hr>\n<h4>17. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">+</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">-</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>20, 0</li>\n<li>2: 1010, 0</li>\n<li>3: 1010, 10-10</li>\n<li>4: NaN, NaN</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The concatenation operator(+) is applicable for both number and string types. So if any operand is string type then both operands concatenated as strings. Whereas subtract(-) operator tries to convert the operands as number type.</p>\n</p>\n</details>\n<hr>\n<h4>18. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm True\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm False\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>True, I'm True</li>\n<li>2: True, I'm False</li>\n<li>3: False, I'm True</li>\n<li>4: False, I'm False</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>In comparison operators, the expression <code class=\"language-text\">[0]</code> converted to Number([0].valueOf().toString()) which is resolved to false. Whereas <code class=\"language-text\">[0]</code> just becomes a truthy value without any conversion because there is no comparison operator.</p>\n</p>\n</details>\n<h4>19. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[1,2,3,4]</li>\n<li>2: [1,2][3,4]</li>\n<li>3: SyntaxError</li>\n<li>4: 1,23,4</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The + operator is not meant or defined for arrays. So it converts arrays into strings and concatenates them.</p>\n</p>\n</details>\n<hr>\n<h4>20. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> browser <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Firefox'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>browser<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}</li>\n<li>2: {1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"}</li>\n<li>3: [1, 2, 3, 4], [\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"]</li>\n<li>4: {1, 1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Since <code class=\"language-text\">Set</code> object is a collection of unique values, it won't allow duplicate values in the collection. At the same time, it is case sensitive data structure.</p>\n</p>\n</details>\n<hr>\n<h4>21. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span> <span class=\"token operator\">===</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: True</li>\n<li>2: False</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>JavaScript follows IEEE 754 spec standards. As per this spec, NaNs are never equal for floating-point numbers.</p>\n</p>\n</details>\n<hr>\n<h4>22. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>4</li>\n<li>2: NaN</li>\n<li>3: SyntaxError</li>\n<li>4: -1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The <code class=\"language-text\">indexOf</code> uses strict equality operator(===) internally and <code class=\"language-text\">NaN === NaN</code> evaluates to false. Since indexOf won't be able to find NaN inside an array, it returns -1 always.\nBut you can use <code class=\"language-text\">Array.prototype.findIndex</code> method to find out the index of NaN in an array or You can use <code class=\"language-text\">Array.prototype.includes</code> to check if NaN is present in an array or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">findIndex</span><span class=\"token punctuation\">(</span>Number<span class=\"token punctuation\">.</span>isNaN<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 4</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>23. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, [2, 3, 4, 5]</li>\n<li>2: 1, {2, 3, 4, 5}</li>\n<li>3: SyntaxError</li>\n<li>4: 1, [2, 3, 4]</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>When using rest parameters, trailing commas are not allowed and will throw a SyntaxError.\nIf you remove the trailing comma then it displays 1st answer</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1, [2, 3, 4, 5]</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>25. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Promise {&#x3C;fulfilled>: 10}</li>\n<li>2: 10</li>\n<li>3: SyntaxError</li>\n<li>4: Promise {&#x3C;rejected>: 10}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Async functions always return a promise. But even if the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise. The above async function is equivalent to below expression,</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>26. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Promise {&#x3C;fulfilled>: 10}</li>\n<li>2: 10</li>\n<li>3: SyntaxError</li>\n<li>4: Promise {&#x3C;resolved>: undefined}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The await expression returns value 10 with promise resolution and the code after each await expression can be treated as existing in a <code class=\"language-text\">.then</code> callback. In this case, there is no return expression at the end of the function. Hence, the default return value of <code class=\"language-text\">undefined</code> is returned as the resolution of the promise. The above async function is equivalent to below expression,</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>27. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">processArray</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\np <span class=\"token function\">essArray</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: 1, 2, 3, 4</li>\n<li>3: 4, 4, 4, 4</li>\n<li>4: 4, 3, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Even though \"processArray\" is an async function, the anonymous function that we use for <code class=\"language-text\">forEach</code> is synchronous. If you use await inside a synchronous function then it throws a syntax error.</p>\n</p>\n</details>\n<hr>\n<h4>28. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">process</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Process completed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\np <span class=\"token function\">ess</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1 2 3 5 and Process completed!</li>\n<li>2: 5 5 5 5 and Process completed!</li>\n<li>3: Process completed! and 5 5 5 5</li>\n<li>4: Process completed! and 1 2 3 5</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The forEach method will not wait until all items are finished but it just runs the tasks and goes next. Hence, the last statement is displayed first followed by a sequence of promise resolutions.</p>\n<p>But you control the array sequence using for..of loop,</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">processArray</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> item <span class=\"token keyword\">of</span> array<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Process completed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>29. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> set <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'+0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>set<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Set(4) {\"+0\", \"-0\", NaN, undefined}</li>\n<li>2: Set(3) {\"+0\", NaN, undefined}</li>\n<li>3: Set(5) {\"+0\", \"-0\", NaN, undefined, NaN}</li>\n<li>4: Set(4) {\"+0\", NaN, undefined, NaN}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Set has few exceptions from equality check,</p>\n<ol>\n<li>All NaN values are equal</li>\n<li>Both +0 and -0 considered as different values</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>30. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> sym1 <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> sym2 <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> sym3 <span class=\"token operator\">=</span> Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> sym4 <span class=\"token operator\">=</span> Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nc oe<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sym1 <span class=\"token operator\">===</span> sym2<span class=\"token punctuation\">,</span> sym3 <span class=\"token operator\">===</span> sym4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>true, true</li>\n<li>2: true, false</li>\n<li>3: false, true</li>\n<li>4: false, false</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Symbol follows below conventions,</p>\n<ol>\n<li>Every symbol value returned from Symbol() is unique irrespective of the optional string.</li>\n<li><code class=\"language-text\">Symbol.for()</code> function creates a symbol in a global symbol registry list. But it doesn't necessarily create a new symbol on every call, it checks first if a symbol with the given key is already present in the registry and returns the symbol if it is found. Otherwise a new symbol created in the registry.</li>\n</ol>\n<p><strong>Note:</strong> The symbol description is just useful for debugging purposes.</p>\n</p>\n</details>\n<hr>\n<h4>31. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> sym1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sym1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: one</li>\n<li>3: Symbol('one')</li>\n<li>4: Symbol</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p><code class=\"language-text\">Symbol</code> is a just a standard function and not an object constructor(unlike other primitives new Boolean, new String and new Number). So if you try to call it with the new operator will result in a TypeError</p>\n</p>\n</details>\n<hr>\n<h4>32. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> myNumber <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> myString <span class=\"token operator\">=</span> <span class=\"token string\">'100'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myNumber <span class=\"token operator\">===</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is not a string!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is a string!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myString <span class=\"token operator\">===</span> <span class=\"token string\">'number'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is not a number!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is a number!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: It is not a string!, It is not a number!</li>\n<li>3: It is not a string!, It is a number!</li>\n<li>4: It is a string!, It is a number!</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The return value of <code class=\"language-text\">typeof myNumber (OR) typeof myString</code> is always the truthy value (either \"number\" or \"string\"). Since ! operator converts the value to a boolean value, the value of both <code class=\"language-text\">!typeof myNumber or !typeof myString</code> is always false. Hence the if condition fails and control goes to else block.</p>\n</p>\n</details>\n<hr>\n<h4>33. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">myArray</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token string\">'one'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{\"myArray\":['one', undefined, {}, Symbol]}, {}</li>\n<li>2: {\"myArray\":['one', null,null,null]}, {}</li>\n<li>3: {\"myArray\":['one', null,null,null]}, \"{ [Symbol.for('one')]: 'one' }, [Symbol.for('one')]\"</li>\n<li>4: {\"myArray\":['one', undefined, function(){}, Symbol('')]}, {}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The symbols has below constraints,</p>\n<ol>\n<li>The undefined, Functions, and Symbols are not valid JSON values. So those values are either omitted (in an object) or changed to null (in an array). Hence, it returns null values for the value array.</li>\n<li>All Symbol-keyed properties will be completely ignored. Hence it returns an empty object({}).</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>34. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">A</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span><span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">B</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">A</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">A</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nn <span class=\"token constant\">B</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: A, A</li>\n<li>2: A, B</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Using constructors, <code class=\"language-text\">new.target</code> refers to the constructor (points to the class definition of class which is initialized) that was directly invoked by new. This also applies to the case if the constructor is in a parent class and was delegated from a child constructor.</p>\n</p>\n</details>\n<hr>\n<h4>35. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>y<span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, [2, 3, 4]</li>\n<li>2: 1, [2, 3]</li>\n<li>3: 1, [2]</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It throws a syntax error because the rest element should not have a trailing comma. You should always consider using a rest operator as the last element.</p>\n</p>\n</details>\n<hr>\n<h4>36. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> x <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> y <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30, 20</li>\n<li>2: 10, 20</li>\n<li>3: 10, undefined</li>\n<li>4: 30, undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The object property follows below rules,</p>\n<ol>\n<li>The object properties can be retrieved and assigned to a variable with a different name</li>\n<li>The property assigned a default value when the retrieved value is <code class=\"language-text\">undefined</code></li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>37. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">a</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>200</li>\n<li>2: Error</li>\n<li>3: undefined</li>\n<li>4: 0</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>If you leave out the right-hand side assignment for the destructuring object, the function will look for at least one argument to be supplied when invoked. Otherwise you will receive an error <code class=\"language-text\">Error: Cannot read property 'length' of undefined</code> as mentioned above.</p>\n<p>You can avoid the error with either of the below changes,</p>\n<ol>\n<li><strong>Pass at least an empty object:</strong></li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol start=\"2\">\n<li><strong>Assign default empty object:</strong></li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>38. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> props <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jack'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Tom'</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> name <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Tom</li>\n<li>2: Error</li>\n<li>3: undefined</li>\n<li>4: John</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>It is possible to combine Array and Object destructuring. In this case, the third element in the array props accessed first followed by name property in the object.</p>\n</p>\n</details>\n<hr>\n<h4>39. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">num <span class=\"token operator\">=</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc <span class=\"token function\">kType</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>number, undefined, string, object</li>\n<li>2: undefined, undefined, string, object</li>\n<li>3: number, number, string, object</li>\n<li>4: number, number, number, number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>If the function argument is set implicitly(not passing argument) or explicitly to undefined, the value of the argument is the default parameter. Whereas for other falsy values('' or null), the value of the argument is passed as a parameter.</p>\n<p>Hence, the result of function calls categorized as below,</p>\n<ol>\n<li>The first two function calls logs number type since the type of default value is number</li>\n<li>The type of '' and null values are string and object type respectively.</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>40. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item<span class=\"token punctuation\">,</span> items <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    items<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> items<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Orange'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Apple'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: ['Orange'], ['Orange', 'Apple']</li>\n<li>2: ['Orange'], ['Apple']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Since the default argument is evaluated at call time, a new object is created each time the function is called. So in this case, the new array is created and an element pushed to the default empty array.</p>\n</p>\n</details>\n<hr>\n<h4>41. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">,</span> message <span class=\"token operator\">=</span> greeting <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>greeting<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">,</span> message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ng <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Good morning!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: ['Hello', 'John', 'Hello John'], ['Hello', 'John', 'Good morning!']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Since parameters defined earlier are available to later default parameters, this code snippet doesn't throw any error.</p>\n</p>\n</details>\n<hr>\n<h4>42. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">outer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f <span class=\"token operator\">=</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Inner'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\no <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: ReferenceError</li>\n<li>2: Inner</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The functions and variables declared in the function body cannot be referred from default value parameter initializers. If you still try to access, it throws a run-time ReferenceError(i.e, <code class=\"language-text\">inner</code> is not defined).</p>\n</p>\n</details>\n<hr>\n<h4>43. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFun</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>manyMoreArgs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>manyMoreArgs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">myFun</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nm <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[3, 4, 5], undefined</li>\n<li>2: SyntaxError</li>\n<li>3: [3, 4, 5], []</li>\n<li>4: [3, 4, 5], [undefined]</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The rest parameter is used to hold the remaining parameters of a function and it becomes an empty array if the argument is not provided.</p>\n</p>\n</details>\n<hr>\n<h4>44. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'value'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> array <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>obj<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>['key', 'value']</li>\n<li>2: TypeError</li>\n<li>3: []</li>\n<li>4: ['key']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Spread syntax can be applied only to iterable objects. By default, Objects are not iterable, but they become iterable when used in an Array, or with iterating functions such as <code class=\"language-text\">map(), reduce(), and assign()</code>. If you still try to do it, it still throws <code class=\"language-text\">TypeError: obj is not iterable</code>.</p>\n</p>\n</details>\n<hr>\n<h4>45. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1</li>\n<li>2: undefined</li>\n<li>3: SyntaxError</li>\n<li>4: TypeError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>Generators are not constructible type. But if you still proceed to do, there will be an error saying \"TypeError: myGenFunc is not a constructor\"</p>\n</p>\n</details>\n<hr>\n<h4>46. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{ value: 1, done: false }, { value: 2, done: true }, { value: undefined, done: true }</li>\n<li>2: { value: 1, done: false }, { value: 2, done: false }, { value: undefined, done: true }</li>\n<li>3: { value: 1, done: false }, { value: 2, done: true }, { value: 3, done: true }</li>\n<li>4: { value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>A return statement in a generator function will make the generator finish. If a value is returned, it will be set as the value property of the object and done property to true. When a generator is finished, subsequent next() calls return an object of this form: <code class=\"language-text\">{value: undefined, done: true}</code>.</p>\n</p>\n</details>\n<hr>\n<h4>47. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> myGenerator <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>1,2,3 and 1,2,3</li>\n<li>2: 1,2,3 and 4,5,6</li>\n<li>3: 1 and 1</li>\n<li>4: 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The generator should not be re-used once the iterator is closed. i.e, Upon exiting a loop(on completion or using break &#x26; return), the generator is closed and trying to iterate over it again does not yield any more results. Hence, the second loop doesn't print any value.</p>\n</p>\n</details>\n<hr>\n<h4>48. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> num <span class=\"token operator\">=</span> 0o38<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: 38</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>If you use an invalid number(outside of 0-7 range) in the octal literal, JavaScript will throw a SyntaxError. In ES5, it treats the octal literal as a decimal number.</p>\n</p>\n</details>\n<hr>\n<h4>49. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> squareObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Square</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>squareObj<span class=\"token punctuation\">.</span>area<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Square</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">length</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">set</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>area <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>1: 100</li>\n<li>2: ReferenceError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Unlike function declarations, class declarations are not hoisted. i.e, First You need to declare your class and then access it, otherwise it will throw a ReferenceError \"Uncaught ReferenceError: Square is not defined\".</p>\n<p><strong>Note:</strong> Class expressions also applies to the same hoisting restrictions of class declarations.</p>\n</p>\n</details>\n<hr>\n<h4>50. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">walk</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nPerson<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">run</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> walk <span class=\"token operator\">=</span> user<span class=\"token punctuation\">.</span>walk<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> run <span class=\"token operator\">=</span> Person<span class=\"token punctuation\">.</span>run<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined, undefined</li>\n<li>2: Person, Person</li>\n<li>3: SyntaxError</li>\n<li>4: Window, Window</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>When a regular or prototype method is called without a value for <strong>this</strong>, the methods return an initial this value if the value is not undefined. Otherwise global window object will be returned. In our case, the initial <code class=\"language-text\">this</code> value is undefined so both methods return window objects.</p>\n</p>\n</details>\n<hr>\n<h4>51. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> vehicle started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Car</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> car started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'BMW'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: BMW vehicle started, BMW car started</li>\n<li>3: BMW car started, BMW vehicle started</li>\n<li>4: BMW car started, BMW car started</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The super keyword is used to call methods of a superclass. Unlike other languages the super invocation doesn't need to be a first statement. i.e, The statements will be executed in the same order of code.</p>\n</p>\n</details>\n<hr>\n<h4>52. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">USER</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">25</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30</li>\n<li>2: 25</li>\n<li>3: Uncaught TypeError</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Even though we used constant variables, the content of it is an object and the object's contents (e.g properties) can be altered. Hence, the change is going to be valid in this case.</p>\n</p>\n</details>\n<hr>\n<h4>53. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🙂'</span> <span class=\"token operator\">===</span> <span class=\"token string\">'🙂'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Emojis are unicodes and the unicode for smile symbol is \"U+1F642\". The unicode comparision of same emojies is equivalent to string comparison. Hence, the output is always true.</p>\n</p>\n</details>\n<hr>\n<h4>54. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>string</li>\n<li>2: boolean</li>\n<li>3: NaN</li>\n<li>4: number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The typeof operator on any primitive returns a string value. So even if you apply the chain of typeof operators on the return value, it is always string.</p>\n</p>\n</details>\n<hr>\n<h4>55. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> zero <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>zero<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'If'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Else'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>If</li>\n<li>2: Else</li>\n<li>3: NaN</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<ol>\n<li>The type of operator on new Number always returns object. i.e, typeof new Number(0) --> object.</li>\n<li>Objects are always truthy in if block</li>\n</ol>\n<p>Hence the above code block always goes to if section.</p>\n</p>\n</details>\n<hr>\n<h4>55. What is the output of below code in non strict mode?</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> msg <span class=\"token operator\">=</span> <span class=\"token string\">'Good morning!!'</span><span class=\"token punctuation\">;</span>\n\nmsg<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">;</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>msg<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>\"\"</li>\n<li>2: Error</li>\n<li>3: John</li>\n<li>4: Undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It returns undefined for non-strict mode and returns Error for strict mode. In non-strict mode, the wrapper object is going to be created and get the mentioned property. But the object get disappeared after accessing the property in next line.</p>\n</p>\n</details>\n<hr>\n<h4>56. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">innerFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">===</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">11</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>11, 10</li>\n<li>2: 11, 11</li>\n<li>3: 10, 11</li>\n<li>4: 10, 10</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>11 and 10 is logged to the console.</p>\n<p>The innerFunc is a closure which captures the count variable from the outerscope. i.e, 10. But the conditional has another local variable <code class=\"language-text\">count</code> which overwrites the ourter <code class=\"language-text\">count</code> variable. So the first console.log displays value 11.\nWhereas the second console.log logs 10 by capturing the count variable from outerscope.</p>\n</p>\n</details>\n<hr>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>"},{"url":"/blog/interview-questions-js/","relativePath":"blog/interview-questions-js.md","relativeDir":"blog","base":"interview-questions-js.md","name":"interview-questions-js","frontmatter":{"title":"JS-Intervew-2","subtitle":"Object Oriented JavaScript","date":"2021-09-11","thumb_image_alt":"big o","excerpt":"What are the possible ways to create objects in JavaScript","seo":{"title":"Javascript Interview Questions Part 2","description":"What are the possible ways to create objects in JavaScript","robots":[],"extra":[{"name":"og:image","value":"images/js-code-spiral-num.png","keyName":"property","relativeUrl":true},{"name":"twitter:title","value":"JS-Interview","keyName":"name","relativeUrl":false},{"name":"twitter:description","value":"What are the possible ways to create objects in JavaScript","keyName":"name","relativeUrl":false}]},"template":"post","thumb_image":"images/bigo.jpg","image":"images/green-spruce-4e3a1745.png"},"html":"<h2>Javascript Interview Questions</h2>\n<ol>\n<li>\n<p>What are the possible ways to create objects in JavaScript</p>\n<p>There are many ways to create objects in javascript as below</p>\n<ol>\n<li>\n<p><strong>Object constructor:</strong></p>\n<p>The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Object's create method:</strong></p>\n<p>The create method of Object creates a new object by passing the prototype object as a parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Object literal syntax:</strong></p>\n<p>The object literal syntax is equivalent to create method when it passes null as parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Function constructor:</strong></p>\n<p>Create any function and apply the new operator to create object instances,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">21</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Sudheer'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Function constructor with prototype:</strong></p>\n<p>This is similar to function constructor but it uses prototype for their properties and methods,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Sudheer'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is equivalent to an instance created with an object create method with a function prototype and then call that function with an instance and parameters as arguments.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> func <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">func</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> z<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>(OR)</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// Create a new instance using function prototype.</span>\n<span class=\"token keyword\">var</span> newInstance <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>func<span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\">// Call the function</span>\n<span class=\"token keyword\">var</span> result <span class=\"token operator\">=</span> <span class=\"token function\">func</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>newInstance<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> z<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token comment\">// If the result is a non-null object then use it otherwise just use the new instance.</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> result <span class=\"token operator\">===</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">?</span> result <span class=\"token operator\">:</span> newInstance<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>ES6 Class syntax:</strong></p>\n<p>ES6 introduces class feature to create the objects</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Person</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Sudheer'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p><strong>Singleton pattern:</strong></p>\n<p>A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance and this way one can ensure that they don't accidentally create multiple instances.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> object <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Sudheer'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n</ol>\n</li>\n<li>\n<p>What is a prototype chain</p>\n<p><strong>Prototype chaining</strong> is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language.</p>\n<p>The prototype on object instance is available through <strong>Object.getPrototypeOf(object)</strong> or *<strong>*proto**</strong> property whereas prototype on constructors function is available through <strong>Object.prototype</strong>.</p>\n<p><img src=\"images/prototype_chain.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>What is the difference between Call, Apply and Bind</p>\n<p>The difference between Call, Apply and Bind can be explained with below examples,</p>\n<p><strong>Call:</strong> The call() method invokes a function with a given <code class=\"language-text\">this</code> value and arguments provided one by one</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> employee1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Rodson'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> employee2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jimmy'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baily'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">greeting1<span class=\"token punctuation\">,</span> greeting2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>greeting1 <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>firstName <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>lastName <span class=\"token operator\">+</span> <span class=\"token string\">', '</span> <span class=\"token operator\">+</span> greeting2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>employee1<span class=\"token punctuation\">,</span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello John Rodson, How are you?</span>\n<span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>employee2<span class=\"token punctuation\">,</span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello Jimmy Baily, How are you?</span></code></pre></div>\n<p><strong>Apply:</strong> Invokes the function with a given <code class=\"language-text\">this</code> value and allows you to pass in arguments as an array</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> employee1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Rodson'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> employee2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jimmy'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baily'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">greeting1<span class=\"token punctuation\">,</span> greeting2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>greeting1 <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>firstName <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>lastName <span class=\"token operator\">+</span> <span class=\"token string\">', '</span> <span class=\"token operator\">+</span> greeting2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>employee1<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello John Rodson, How are you?</span>\n<span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>employee2<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello Jimmy Baily, How are you?</span></code></pre></div>\n<p><strong>bind:</strong> returns a new function, allowing you to pass any number of arguments</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> employee1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Rodson'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> employee2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">firstName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jimmy'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lastName</span><span class=\"token operator\">:</span> <span class=\"token string\">'Baily'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">greeting1<span class=\"token punctuation\">,</span> greeting2</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>greeting1 <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>firstName <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>lastName <span class=\"token operator\">+</span> <span class=\"token string\">', '</span> <span class=\"token operator\">+</span> greeting2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> inviteEmployee1 <span class=\"token operator\">=</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>employee1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> inviteEmployee2 <span class=\"token operator\">=</span> <span class=\"token function\">invite</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span>employee2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">inviteEmployee1</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello John Rodson, How are you?</span>\n<span class=\"token function\">inviteEmployee2</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'How are you?'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Hello Jimmy Baily, How are you?</span></code></pre></div>\n<p>Call and apply are pretty interchangeable. Both execute the current function immediately. You need to decide whether it's easier to send in an array or a comma separated list of arguments. You can remember by treating Call is for <strong>comma</strong> (separated list) and Apply is for <strong>Array</strong>.</p>\n<p>Whereas Bind creates a new function that will have <code class=\"language-text\">this</code> set to the first parameter passed to bind().</p>\n</li>\n<li>\n<p>What is JSON and its common operations</p>\n<p><strong>JSON</strong> is a text-based data format following JavaScript object syntax, which was popularized by <code class=\"language-text\">Douglas Crockford</code>. It is useful when you want to transmit data across a network and it is basically just a text file with an extension of .json, and a MIME type of application/json</p>\n<p><strong>Parsing:</strong> Converting a string to a native object</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Stringification:</strong> converting a native object to a string so it can be transmitted across the network</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>object<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the array slice method</p>\n<p>The <strong>slice()</strong> method returns the selected elements in an array as a new array object. It selects the elements starting at the given start argument, and ends at the given optional end argument without including the last element. If you omit the second argument then it selects till the end.</p>\n<p>Some of the examples of this method are,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> arrayIntegers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> arrayIntegers1 <span class=\"token operator\">=</span> arrayIntegers<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [1,2]</span>\n<span class=\"token keyword\">let</span> arrayIntegers2 <span class=\"token operator\">=</span> arrayIntegers<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [3]</span>\n<span class=\"token keyword\">let</span> arrayIntegers3 <span class=\"token operator\">=</span> arrayIntegers<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//returns [5]</span></code></pre></div>\n<p><strong>Note:</strong> Slice method won't mutate the original array but it returns the subset as a new array.</p>\n</li>\n<li>\n<p>What is the purpose of the array splice method</p>\n<p>The <strong>splice()</strong> method is used either adds/removes items to/from an array, and then returns the removed item. The first argument specifies the array position for insertion or deletion whereas the optional second argument indicates the number of elements to be deleted. Each additional argument is added to the array.</p>\n<p>Some of the examples of this method are,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> arrayIntegersOriginal1 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> arrayIntegersOriginal2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> arrayIntegersOriginal3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> arrayIntegers1 <span class=\"token operator\">=</span> arrayIntegersOriginal1<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [1, 2]; original array: [3, 4, 5]</span>\n<span class=\"token keyword\">let</span> arrayIntegers2 <span class=\"token operator\">=</span> arrayIntegersOriginal2<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [4, 5]; original array: [1, 2, 3]</span>\n<span class=\"token keyword\">let</span> arrayIntegers3 <span class=\"token operator\">=</span> arrayIntegersOriginal3<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//returns [4]; original array: [1, 2, 3, \"a\", \"b\", \"c\", 5]</span></code></pre></div>\n<p><strong>Note:</strong> Splice method modifies the original array and returns the deleted array.</p>\n</li>\n<li>\n<p>What is the difference between slice and splice</p>\n<p>Some of the major difference in a tabular form</p>\n<table>\n<thead>\n<tr>\n<th>Slice</th>\n<th>Splice</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Doesn't modify the original array(immutable)</td>\n<td>Modifies the original array(mutable)</td>\n</tr>\n<tr>\n<td>Returns the subset of original array</td>\n<td>Returns the deleted elements as array</td>\n</tr>\n<tr>\n<td>Used to pick the elements from array</td>\n<td>Used to insert or delete elements to/from array</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>How do you compare Object and Map</p>\n<p><strong>Objects</strong> are similar to <strong>Maps</strong> in that both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. Due to this reason, Objects have been used as Maps historically. But there are important differences that make using a Map preferable in certain cases.</p>\n<ol>\n<li>The keys of an Object are Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive.</li>\n<li>The keys in Map are ordered while keys added to Object are not. Thus, when iterating over it, a Map object returns keys in order of insertion.</li>\n<li>You can get the size of a Map easily with the size property, while the number of properties in an Object must be determined manually.</li>\n<li>A Map is an iterable and can thus be directly iterated, whereas iterating over an Object requires obtaining its keys in some fashion and iterating over them.</li>\n<li>An Object has a prototype, so there are default keys in the map that could collide with your keys if you're not careful. As of ES5 this can be bypassed by using map = Object.create(null), but this is seldom done.</li>\n<li>A Map may perform better in scenarios involving frequent addition and removal of key pairs.</li>\n</ol>\n</li>\n<li>\n<p>What is the difference between == and === operators</p>\n<p>JavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison. The strict operators take type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables. The strict operators follow the below conditions for different types,</p>\n<ol>\n<li>Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.</li>\n<li>\n<p>Two numbers are strictly equal when they are numerically equal. i.e, Having the same number value.\nThere are two special cases in this,</p>\n<ol>\n<li>NaN is not equal to anything, including NaN.</li>\n<li>Positive and negative zeros are equal to one another.</li>\n</ol>\n</li>\n<li>Two Boolean operands are strictly equal if both are true or both are false.</li>\n<li>Two objects are strictly equal if they refer to the same Object.</li>\n<li>Null and Undefined types are not equal with ===, but equal with ==. i.e,\nnull===undefined --> false but null==undefined --> true</li>\n</ol>\n<p>Some of the example which covers the above cases,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token number\">0</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span>   <span class=\"token comment\">// true</span>\n<span class=\"token number\">0</span> <span class=\"token operator\">===</span> <span class=\"token boolean\">false</span>  <span class=\"token comment\">// false</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">==</span> <span class=\"token string\">\"1\"</span>     <span class=\"token comment\">// true</span>\n<span class=\"token number\">1</span> <span class=\"token operator\">===</span> <span class=\"token string\">\"1\"</span>    <span class=\"token comment\">// false</span>\n<span class=\"token keyword\">null</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">undefined</span> <span class=\"token comment\">// true</span>\n<span class=\"token keyword\">null</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">undefined</span> <span class=\"token comment\">// false</span>\n<span class=\"token string\">'0'</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span> <span class=\"token comment\">// true</span>\n<span class=\"token string\">'0'</span> <span class=\"token operator\">===</span> <span class=\"token boolean\">false</span> <span class=\"token comment\">// false</span>\n<span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token operator\">==</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> or <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token operator\">===</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">//false, refer different objects in memory</span>\n<span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">==</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> or <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token operator\">===</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token comment\">//false, refer different objects in memory</span></code></pre></div>\n</li>\n<li>\n<p>What are lambda or arrow functions</p>\n<p>An arrow function is a shorter syntax for a function expression and does not have its own <strong>this, arguments, super, or new.target</strong>. These functions are best suited for non-method functions, and they cannot be used as constructors.</p>\n</li>\n<li>\n<p>What is a first class function</p>\n<p>In Javascript, functions are first class objects. First-class functions means when functions in that language are treated like any other variable.</p>\n<p>For example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable. For example, in the below example, handler functions assigned to a listener</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">handler</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'This is a click handler function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ndocument<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> handler<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a first order function</p>\n<p>First-order function is a function that doesn't accept another function as an argument and doesn't return a function as its return value.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">firstOrder</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'I am a first order function!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a higher order function</p>\n<p>Higher-order function is a function that accepts another function as an argument or returns a function as a return value or both.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">firstOrderFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello, I am a First order function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">higherOrder</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">ReturnFirstOrderFunc</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">ReturnFirstOrderFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">higherOrder</span><span class=\"token punctuation\">(</span>firstOrderFunc<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a unary function</p>\n<p>Unary function (i.e. monadic) is a function that accepts exactly one argument. It stands for a single argument accepted by a function.</p>\n<p>Let us take an example of unary function,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">unaryFunction</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">+</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Add 10 to the given argument and display the value</span></code></pre></div>\n</li>\n<li>\n<p>What is the currying function</p>\n<p>Currying is the process of taking a function with multiple arguments and turning it into a sequence of functions each with only a single argument. Currying is named after a mathematician <strong>Haskell Curry</strong>. By applying currying, a n-ary function turns it into a unary function.</p>\n<p>Let's take an example of n-ary function and how it turns into a currying function,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">multiArgFunction</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">multiArgFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 6</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">curryUnaryFunction</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">b</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c<span class=\"token punctuation\">;</span>\n<span class=\"token function\">curryUnaryFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a function: b => c =>  1 + b + c</span>\n<span class=\"token function\">curryUnaryFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns a function: c => 3 + c</span>\n<span class=\"token function\">curryUnaryFunction</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns the number 6</span></code></pre></div>\n<p>Curried functions are great to improve <strong>code reusability</strong> and <strong>functional composition</strong>.</p>\n</li>\n<li>\n<p>What is a pure function</p>\n<p>A <strong>Pure function</strong> is a function where the return value is only determined by its arguments without any side effects. i.e, If you call a function with the same arguments 'n' number of times and 'n' number of places in the application then it will always return the same value.</p>\n<p>Let's take an example to see the difference between pure and impure functions,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">//Impure</span>\n<span class=\"token keyword\">let</span> numberArray <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">impureAddNumber</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> numberArray<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">//Pure</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">pureAddNumber</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">number</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">argNumberArray</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> argNumberArray<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>number<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//Display the results</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">impureAddNumber</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns 1</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numberArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [6]</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">pureAddNumber</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>numberArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [6, 7]</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numberArray<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns [6]</span></code></pre></div>\n<p>As per above code snippets, <strong>Push</strong> function is impure itself by altering the array and returning an push number index which is independent of parameter value. Whereas <strong>Concat</strong> on the other hand takes the array and concatenates it with the other array producing a whole new array without side effects. Also, the return value is a concatenation of the previous array.</p>\n<p>Remember that Pure functions are important as they simplify unit testing without any side effects and no need for dependency injection. They also avoid tight coupling and make it harder to break your application by not having any side effects. These principles are coming together with <strong>Immutability</strong> concept of ES6 by giving preference to <strong>const</strong> over <strong>let</strong> usage.</p>\n</li>\n<li>\n<p>What is the purpose of the let keyword</p>\n<p>The <code class=\"language-text\">let</code> statement declares a <strong>block scope local variable</strong>. Hence the variables defined with let keyword are limited in scope to the block, statement, or expression on which it is used. Whereas variables declared with the <code class=\"language-text\">var</code> keyword used to define a variable globally, or locally to an entire function regardless of block scope.</p>\n<p>Let's take an example to demonstrate the usage,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token number\">30</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>counter <span class=\"token operator\">===</span> <span class=\"token number\">30</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token number\">31</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>counter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 31</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>counter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 30 (because the variable in if block won't exist here)</span></code></pre></div>\n</li>\n<li>\n<p>What is the difference between let and var</p>\n<p>You can list out the differences in a tabular format</p>\n<table>\n<thead>\n<tr>\n<th>var</th>\n<th>let</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is been available from the beginning of JavaScript</td>\n<td>Introduced as part of ES6</td>\n</tr>\n<tr>\n<td>It has function scope</td>\n<td>It has block scope</td>\n</tr>\n<tr>\n<td>Variables will be hoisted</td>\n<td>Hoisted but not initialized</td>\n</tr>\n</tbody>\n</table>\n<p>Let's take an example to see the difference,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">userDetails</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">username</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>username<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>salary<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// undefined due to hoisting</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ReferenceError: Cannot access 'age' before initialization</span>\n        <span class=\"token keyword\">let</span> age <span class=\"token operator\">=</span> <span class=\"token number\">30</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">var</span> salary <span class=\"token operator\">=</span> <span class=\"token number\">10000</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>salary<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//10000 (accessible to due function scope)</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//error: age is not defined(due to block scope)</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">userDetails</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the reason to choose the name let as a keyword</p>\n<p><code class=\"language-text\">let</code> is a mathematical statement that was adopted by early programming languages like <strong>Scheme</strong> and <strong>Basic</strong>. It has been borrowed from dozens of other languages that use <code class=\"language-text\">let</code> already as a traditional keyword as close to <code class=\"language-text\">var</code> as possible.</p>\n</li>\n<li>\n<p>How do you redeclare variables in switch block without an error</p>\n<p>If you try to redeclare variables in a <code class=\"language-text\">switch block</code> then it will cause errors because there is only one block. For example, the below code block throws a syntax error as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">0</span><span class=\"token operator\">:</span>\n        <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">case</span> <span class=\"token number\">1</span><span class=\"token operator\">:</span>\n        <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span> <span class=\"token comment\">// SyntaxError for redeclaration.</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>To avoid this error, you can create a nested block inside a case clause and create a new block scoped lexical environment.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> counter <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">0</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">case</span> <span class=\"token number\">1</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> name<span class=\"token punctuation\">;</span> <span class=\"token comment\">// No SyntaxError for redeclaration.</span>\n        <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What is the Temporal Dead Zone</p>\n<p>The Temporal Dead Zone is a behavior in JavaScript that occurs when declaring a variable with the let and const keywords, but not with var. In ECMAScript 6, accessing a <code class=\"language-text\">let</code> or <code class=\"language-text\">const</code> variable before its declaration (within its scope) causes a ReferenceError. The time span when that happens, between the creation of a variable's binding and its declaration, is called the temporal dead zone.</p>\n<p>Let's see this behavior with an example,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">somemethod</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>counter1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// undefined</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>counter2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// ReferenceError</span>\n    <span class=\"token keyword\">var</span> counter1 <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">let</span> counter2 <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What is IIFE(Immediately Invoked Function Expression)</p>\n<p>IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. The signature of it would be as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// logic here</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The primary reason to use an IIFE is to obtain data privacy because any variables declared within the IIFE cannot be accessed by the outside world. i.e, If you try to access variables with IIFE then it throws an error as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> message <span class=\"token operator\">=</span> <span class=\"token string\">'IIFE'</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//Error: message is not defined</span></code></pre></div>\n</li>\n<li>\n<p>What is the benefit of using modules</p>\n<p>There are a lot of benefits to using modules in favour of a sprawling. Some of the benefits are,</p>\n<ol>\n<li>Maintainability</li>\n<li>Reusability</li>\n<li>Namespacing</li>\n</ol>\n</li>\n<li>\n<p>What is memoization</p>\n<p>Memoization is a programming technique which attempts to increase a function's performance by caching its previously computed results. Each time a memoized function is called, its parameters are used to index the cache. If the data is present, then it can be returned, without executing the entire function. Otherwise the function is executed and then the result is added to the cache.\nLet's take an example of adding function with memoization,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">memoizAddition</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> cache <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>value <span class=\"token keyword\">in</span> cache<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Fetching from cache'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> cache<span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Here, cache.value cannot be used as property name starts with the number which is not a valid JavaScript  identifier. Hence, can only be accessed using the square bracket notation.</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Calculating result'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> value <span class=\"token operator\">+</span> <span class=\"token number\">20</span><span class=\"token punctuation\">;</span>\n            cache<span class=\"token punctuation\">[</span>value<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> result<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// returned function from memoizAddition</span>\n<span class=\"token keyword\">const</span> addition <span class=\"token operator\">=</span> <span class=\"token function\">memoizAddition</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">addition</span><span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//output: 40 calculated</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">addition</span><span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//output: 40 cached</span></code></pre></div>\n</li>\n<li>\n<p>What is Hoisting</p>\n<p>Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialisation.\nLet's take a simple example of variable hoisting,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//output : undefined</span>\n<span class=\"token keyword\">var</span> message <span class=\"token operator\">=</span> <span class=\"token string\">'The variable Has been hoisted'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The above code looks like as below to the interpreter,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> message<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmessage <span class=\"token operator\">=</span> <span class=\"token string\">'The variable Has been hoisted'</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What are classes in ES6</p>\n<p>In ES6, Javascript classes are primarily syntactic sugar over JavaScript's existing prototype-based inheritance.\nFor example, the prototype based inheritance written in function expression as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Bike</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">model<span class=\"token punctuation\">,</span> color</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Bike</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">getDetails</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">+</span> <span class=\"token string\">' bike has'</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">+</span> <span class=\"token string\">' color'</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Whereas ES6 classes can be defined as an alternative</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Bike</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">color<span class=\"token punctuation\">,</span> model</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">getDetails</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">+</span> <span class=\"token string\">' bike has'</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">+</span> <span class=\"token string\">' color'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What are closures</p>\n<p>A closure is the combination of a function and the lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function's variables. The closure has three scope chains</p>\n<ol>\n<li>Own scope where variables defined between its curly brackets</li>\n<li>Outer function's variables</li>\n<li>Global variables</li>\n</ol>\n<p>Let's take an example of closure concept,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">Welcome</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">greetingInfo</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">message</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>message <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> greetingInfo<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> myFunction <span class=\"token operator\">=</span> <span class=\"token function\">Welcome</span><span class=\"token punctuation\">(</span><span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Welcome '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//Output: Welcome John</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello Mr.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//output: Hello Mr.John</span></code></pre></div>\n<p>As per the above code, the inner function(i.e, greetingInfo) has access to the variables in the outer function scope(i.e, Welcome) even after the outer function has returned.</p>\n</li>\n<li>\n<p>What are modules</p>\n<p>Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. Most of the JavaScript modules export an object literal, a function, or a constructor</p>\n</li>\n<li>\n<p>Why do you need modules</p>\n<p>Below are the list of benefits using modules in javascript ecosystem</p>\n<ol>\n<li>Maintainability</li>\n<li>Reusability</li>\n<li>Namespacing</li>\n</ol>\n</li>\n<li>\n<p>What is scope in javascript</p>\n<p>Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime. In other words, scope determines the visibility of variables and other resources in areas of your code.</p>\n</li>\n<li>\n<p>What is a service worker</p>\n<p>A Service worker is basically a script (JavaScript file) that runs in the background, separate from a web page and provides features that don't need a web page or user interaction. Some of the major features of service workers are Rich offline experiences(offline first web application development), periodic background syncs, push notifications, intercept and handle network requests and programmatically managing a cache of responses.</p>\n</li>\n<li>\n<p>How do you manipulate DOM using a service worker</p>\n<p>Service worker can't access the DOM directly. But it can communicate with the pages it controls by responding to messages sent via the <code class=\"language-text\">postMessage</code> interface, and those pages can manipulate the DOM.</p>\n</li>\n<li>\n<p>How do you reuse information across service worker restarts</p>\n<p>The problem with service worker is that it gets terminated when not in use, and restarted when it's next needed, so you cannot rely on global state within a service worker's <code class=\"language-text\">onfetch</code> and <code class=\"language-text\">onmessage</code> handlers. In this case, service workers will have access to IndexedDB API in order to persist and reuse across restarts.</p>\n</li>\n<li>\n<p>What is IndexedDB</p>\n<p>IndexedDB is a low-level API for client-side storage of larger amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data.</p>\n</li>\n<li>\n<p>What is web storage</p>\n<p>Web storage is an API that provides a mechanism by which browsers can store key/value pairs locally within the user's browser, in a much more intuitive fashion than using cookies. The web storage provides two mechanisms for storing data on the client.</p>\n<ol>\n<li><strong>Local storage:</strong> It stores data for current origin with no expiration date.</li>\n<li><strong>Session storage:</strong> It stores data for one session and the data is lost when the browser tab is closed.</li>\n</ol>\n</li>\n<li>\n<p>What is a post message</p>\n<p>Post message is a method that enables cross-origin communication between Window objects.(i.e, between a page and a pop-up that it spawned, or between a page and an iframe embedded within it). Generally, scripts on different pages are allowed to access each other if and only if the pages follow same-origin policy(i.e, pages share the same protocol, port number, and host).</p>\n</li>\n<li>\n<p>What is a Cookie</p>\n<p>A cookie is a piece of data that is stored on your computer to be accessed by your browser. Cookies are saved as key/value pairs.\nFor example, you can create a cookie named username as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> <span class=\"token string\">'username=John'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><img src=\"images/cookie.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>Why do you need a Cookie</p>\n<p>Cookies are used to remember information about the user profile(such as username). It basically involves two steps,</p>\n<ol>\n<li>When a user visits a web page, the user profile can be stored in a cookie.</li>\n<li>Next time the user visits the page, the cookie remembers the user profile.</li>\n</ol>\n</li>\n<li>\n<p>What are the options in a cookie</p>\n<p>There are few below options available for a cookie,</p>\n<ol>\n<li>By default, the cookie is deleted when the browser is closed but you can change this behavior by setting expiry date (in UTC time).</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> <span class=\"token string\">'username=John; expires=Sat, 8 Jun 2019 12:00:00 UTC'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li>By default, the cookie belongs to a current page. But you can tell the browser what path the cookie belongs to using a path parameter.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> <span class=\"token string\">'username=John; path=/services'</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>How do you delete a cookie</p>\n<p>You can delete a cookie by setting the expiry date as a passed date. You don't need to specify a cookie value in this case.\nFor example, you can delete a username cookie in the current page as below.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> <span class=\"token string\">'username=; expires=Fri, 07 Jun 2019 00:00:00 UTC; path=/;'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Note:</strong> You should define the cookie path option to ensure that you delete the right cookie. Some browsers doesn't allow to delete a cookie unless you specify a path parameter.</p>\n</li>\n<li>\n<p>What are the differences between cookie, local storage and session storage</p>\n<p>Below are some of the differences between cookie, local storage and session storage,</p>\n<table>\n<thead>\n<tr>\n<th>Feature</th>\n<th>Cookie</th>\n<th>Local storage</th>\n<th>Session storage</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Accessed on client or server side</td>\n<td>Both server-side &#x26; client-side</td>\n<td>client-side only</td>\n<td>client-side only</td>\n</tr>\n<tr>\n<td>Lifetime</td>\n<td>As configured using Expires option</td>\n<td>until deleted</td>\n<td>until tab is closed</td>\n</tr>\n<tr>\n<td>SSL support</td>\n<td>Supported</td>\n<td>Not supported</td>\n<td>Not supported</td>\n</tr>\n<tr>\n<td>Maximum data size</td>\n<td>4KB</td>\n<td>5 MB</td>\n<td>5MB</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What is the main difference between localStorage and sessionStorage</p>\n<p>LocalStorage is the same as SessionStorage but it persists the data even when the browser is closed and reopened(i.e it has no expiration time) whereas in sessionStorage data gets cleared when the page session ends.</p>\n</li>\n<li>\n<p>How do you access web storage</p>\n<p>The Window object implements the <code class=\"language-text\">WindowLocalStorage</code> and <code class=\"language-text\">WindowSessionStorage</code> objects which has <code class=\"language-text\">localStorage</code>(window.localStorage) and <code class=\"language-text\">sessionStorage</code>(window.sessionStorage) properties respectively. These properties create an instance of the Storage object, through which data items can be set, retrieved and removed for a specific domain and storage type (session or local).\nFor example, you can read and write on local storage objects as below</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">localStorage<span class=\"token punctuation\">.</span><span class=\"token function\">setItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'logo'</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'logo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nlocalStorage<span class=\"token punctuation\">.</span><span class=\"token function\">getItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'logo'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What are the methods available on session storage</p>\n<p>The session storage provided methods for reading, writing and clearing the session data</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token comment\">// Save data to sessionStorage</span>\nsessionStorage<span class=\"token punctuation\">.</span><span class=\"token function\">setItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'key'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Get saved data from sessionStorage</span>\n<span class=\"token keyword\">let</span> data <span class=\"token operator\">=</span> sessionStorage<span class=\"token punctuation\">.</span><span class=\"token function\">getItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'key'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Remove saved data from sessionStorage</span>\nsessionStorage<span class=\"token punctuation\">.</span><span class=\"token function\">removeItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'key'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Remove all saved data from sessionStorage</span>\nsessionStorage<span class=\"token punctuation\">.</span><span class=\"token function\">clear</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a storage event and its event handler</p>\n<p>The StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events.\nThe syntax would be as below</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">window<span class=\"token punctuation\">.</span>onstorage <span class=\"token operator\">=</span> functionRef<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Let's take the example usage of onstorage event handler which logs the storage key and it's values</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onstorage</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'The '</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>key <span class=\"token operator\">+</span> <span class=\"token string\">' key has been changed from '</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>oldValue <span class=\"token operator\">+</span> <span class=\"token string\">' to '</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>newValue <span class=\"token operator\">+</span> <span class=\"token string\">'.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>Why do you need web storage</p>\n<p>Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Also, the information is never transferred to the server. Hence this is a more recommended approach than Cookies.</p>\n</li>\n<li>\n<p>How do you check web storage browser support</p>\n<p>You need to check browser support for localStorage and sessionStorage before using web storage,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> Storage <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Code for localStorage/sessionStorage.</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Sorry! No Web Storage support..</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>How do you check web workers browser support</p>\n<p>You need to check browser support for web workers before using it</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> Worker <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// code for Web worker support.</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Sorry! No Web Worker support..</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>Give an example of a web worker</p>\n<p>You need to follow below steps to start using web workers for counting example</p>\n<ol>\n<li>Create a Web Worker File: You need to write a script to increment the count value. Let's name it as counter.js</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">timedCount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">postMessage</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token string\">'timedCount()'</span><span class=\"token punctuation\">,</span> <span class=\"token number\">500</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">timedCount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Here postMessage() method is used to post a message back to the HTML page</p>\n<ol>\n<li>Create a Web Worker Object: You can create a web worker object by checking for browser support. Let's name this file as web<em>worker</em>example.js</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> w <span class=\"token operator\">==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    w <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Worker</span><span class=\"token punctuation\">(</span><span class=\"token string\">'counter.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>and we can receive messages from web worker</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">w<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onmessage</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'message'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> event<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li>Terminate a Web Worker:\nWeb workers will continue to listen for messages (even after the external script is finished) until it is terminated. You can use the terminate() method to terminate listening to the messages.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">w<span class=\"token punctuation\">.</span><span class=\"token function\">terminate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol>\n<li>Reuse the Web Worker: If you set the worker variable to undefined you can reuse the code</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">w <span class=\"token operator\">=</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What are the restrictions of web workers on DOM</p>\n<p>WebWorkers don't have access to below javascript objects since they are defined in an external files</p>\n<ol>\n<li>Window object</li>\n<li>Document object</li>\n<li>Parent object</li>\n</ol>\n</li>\n<li>\n<p>What is a promise</p>\n<p>A promise is an object that may produce a single value some time in the future with either a resolved value or a reason that it's not resolved(for example, network error). It will be in one of the 3 possible states: fulfilled, rejected, or pending.</p>\n<p>The syntax of Promise creation looks like below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// promise description</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The usage of a promise would be as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> promise <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm a Promise!\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token parameter\">reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\npromise<span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The action flow of a promise will be as below,</p>\n<p><img src=\"images/promises.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>Why do you need a promise</p>\n<p>Promises are used to handle asynchronous operations. They provide an alternative approach for callbacks by reducing the callback hell and writing the cleaner code.</p>\n</li>\n<li>\n<p>What are the three states of promise</p>\n<p>Promises have three states:</p>\n<ol>\n<li><strong>Pending:</strong> This is an initial state of the Promise before an operation begins</li>\n<li><strong>Fulfilled:</strong> This state indicates that the specified operation was completed.</li>\n<li><strong>Rejected:</strong> This state indicates that the operation did not complete. In this case an error value will be thrown.</li>\n</ol>\n</li>\n<li>\n<p>What is a callback function</p>\n<p>A callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action.\nLet's take a simple example of how to use callback function</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">callbackFunction</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello '</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">outerFunction</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">callback</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> name <span class=\"token operator\">=</span> <span class=\"token function\">prompt</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Please enter your name.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">callback</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">outerFunction</span><span class=\"token punctuation\">(</span>callbackFunction<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>Why do we need callbacks</p>\n<p>The callbacks are needed because javascript is an event driven language. That means instead of waiting for a response javascript will keep executing while listening for other events.\nLet's take an example with the first function invoking an API call(simulated by setTimeout) and the next function which logs the message.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">firstFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Simulate a code delay</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'First function called'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">secondFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Second function called'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">firstFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">secondFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nOutput<span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Second function called</span>\n<span class=\"token comment\">// First function called</span></code></pre></div>\n<p>As observed from the output, javascript didn't wait for the response of the first function and the remaining code block got executed. So callbacks are used in a way to make sure that certain code doesn't execute until the other code finishes execution.</p>\n</li>\n<li>\n<p>What is a callback hell</p>\n<p>Callback Hell is an anti-pattern with multiple nested callbacks which makes code hard to read and debug when dealing with asynchronous logic. The callback hell looks like below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">async1</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n    <span class=\"token function\">async2</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n        <span class=\"token function\">async3</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n            <span class=\"token function\">async4</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">{</span>\n                <span class=\"token operator\">...</span><span class=\"token punctuation\">.</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What are server-sent events</p>\n<p>Server-sent events (SSE) is a server push technology enabling a browser to receive automatic updates from a server via HTTP connection without resorting to polling. These are a one way communications channel - events flow from server to client only. This has been used in Facebook/Twitter updates, stock price updates, news feeds etc.</p>\n</li>\n<li>\n<p>How do you receive server-sent event notifications</p>\n<p>The EventSource object is used to receive server-sent event notifications. For example, you can receive messages from server as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> EventSource <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">var</span> source <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">EventSource</span><span class=\"token punctuation\">(</span><span class=\"token string\">'sse_generator.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    source<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onmessage</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">event</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'output'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">+=</span> event<span class=\"token punctuation\">.</span>data <span class=\"token operator\">+</span> <span class=\"token string\">'&lt;br>'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>How do you check browser support for server-sent events</p>\n<p>You can perform browser support for server-sent events before using it as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> EventSource <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Server-sent events supported. Let's have some code here!</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// No server-sent events supported</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What are the events available for server sent events</p>\n<p>Below are the list of events available for server sent events\n| Event | Description |\n|---- | ---------\n| onopen | It is used when a connection to the server is opened |\n| onmessage | This event is used when a message is received |\n| onerror | It happens when an error occurs|</p>\n</li>\n<li>\n<p>What are the main rules of promise</p>\n<p>A promise must follow a specific set of rules,</p>\n<ol>\n<li>A promise is an object that supplies a standard-compliant <code class=\"language-text\">.then()</code> method</li>\n<li>A pending promise may transition into either fulfilled or rejected state</li>\n<li>A fulfilled or rejected promise is settled and it must not transition into any other state.</li>\n<li>Once a promise is settled, the value must not change.</li>\n</ol>\n</li>\n<li>\n<p>What is callback in callback</p>\n<p>You can nest one callback inside in another callback to execute the actions sequentially one by one. This is known as callbacks in callbacks.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">loadScript</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/script1.js'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">script</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'first script is loaded'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">loadScript</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/script2.js'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">script</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'second script is loaded'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token function\">loadScript</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/script3.js'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">script</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'third script is loaded'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token comment\">// after all scripts are loaded</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is promise chaining</p>\n<p>The process of executing a sequence of asynchronous tasks one after another using promises is known as Promise chaining. Let's take an example of promise chaining for calculating the final result,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1</span>\n        <span class=\"token keyword\">return</span> result <span class=\"token operator\">*</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 2</span>\n        <span class=\"token keyword\">return</span> result <span class=\"token operator\">*</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 6</span>\n        <span class=\"token keyword\">return</span> result <span class=\"token operator\">*</span> <span class=\"token number\">4</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In the above handlers, the result is passed to the chain of .then() handlers with the below work flow,</p>\n<ol>\n<li>The initial promise resolves in 1 second,</li>\n<li>After that <code class=\"language-text\">.then</code> handler is called by logging the result(1) and then return a promise with the value of result * 2.</li>\n<li>After that the value passed to the next <code class=\"language-text\">.then</code> handler by logging the result(2) and return a promise with result * 3.</li>\n<li>Finally the value passed to the last <code class=\"language-text\">.then</code> handler by logging the result(6) and return a promise with result * 4.</li>\n</ol>\n</li>\n<li>\n<p>What is promise.all</p>\n<p>Promise.all is a promise that takes an array of promises as an input (an iterable), and it gets resolved when all the promises get resolved or any one of them gets rejected. For example, the syntax of promise.all method is below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">Promise<span class=\"token punctuation\">.</span><span class=\"token function\">all</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>Promise1<span class=\"token punctuation\">,</span> Promise2<span class=\"token punctuation\">,</span> Promise3<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>   console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">.</span><span class=\"token function\">catch</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span> <span class=\"token operator\">=></span> console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Error in promises </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>error<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Note:</strong> Remember that the order of the promises(output the result) is maintained as per input order.</p>\n</li>\n<li>\n<p>What is the purpose of the race method in promise</p>\n<p>Promise.race() method will return the promise instance which is firstly resolved or rejected. Let's take an example of race() method where promise2 is resolved first</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> promise1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">500</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">var</span> promise2 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nPromise<span class=\"token punctuation\">.</span><span class=\"token function\">race</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>promise1<span class=\"token punctuation\">,</span> promise2<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// \"two\" // Both promises will resolve, but promise2 is faster</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is a strict mode in javascript</p>\n<p>Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a \"strict\" operating context. This way it prevents certain actions from being taken and throws more exceptions. The literal expression <code class=\"language-text\">\"use strict\";</code> instructs the browser to use the javascript code in the Strict mode.</p>\n</li>\n<li>\n<p>Why do you need strict mode</p>\n<p>Strict mode is useful to write \"secure\" JavaScript by notifying \"bad syntax\" into real errors. For example, it eliminates accidentally creating a global variable by throwing an error and also throws an error for assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object.</p>\n</li>\n<li>\n<p>How do you declare strict mode</p>\n<p>The strict mode is declared by adding \"use strict\"; to the beginning of a script or a function.\nIf declared at the beginning of a script, it has global scope.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\nx <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// This will cause an error because x is not declared</span></code></pre></div>\n<p>and if you declare inside a function, it has local scope</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">x <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// This will not cause an error.</span>\n<span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFunction</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n    y <span class=\"token operator\">=</span> <span class=\"token number\">3.14</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// This will cause an error</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of double exclamation</p>\n<p>The double exclamation or negation(!!) ensures the resulting type is a boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.\nFor example, you can test IE version using this expression as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> isIE8 <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\nisIE8 <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>navigator<span class=\"token punctuation\">.</span>userAgent<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">MSIE 8.0</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>isIE8<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns true or false</span></code></pre></div>\n<p>If you don't use this expression then it returns the original value.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>navigator<span class=\"token punctuation\">.</span>userAgent<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">MSIE 8.0</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// returns either an Array or null</span></code></pre></div>\n<p><strong>Note:</strong> The expression !! is not an operator, but it is just twice of ! operator.</p>\n</li>\n<li>\n<p>What is the purpose of the delete operator</p>\n<p>The delete keyword is used to delete the property as well as its value.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> user <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">delete</span> user<span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {name: \"John\"}</span></code></pre></div>\n</li>\n<li>\n<p>What is the typeof operator</p>\n<p>You can use the JavaScript typeof operator to find the type of a JavaScript variable. It returns the type of a variable or an expression.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">typeof</span> <span class=\"token string\">'John Abraham'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Returns \"string\"</span>\n<span class=\"token keyword\">typeof</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Returns \"number\"</span></code></pre></div>\n</li>\n<li>\n<p>What is undefined property</p>\n<p>The undefined property indicates that a variable has not been assigned a value, or not declared at all. The type of undefined value is undefined too.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> user<span class=\"token punctuation\">;</span> <span class=\"token comment\">// Value is undefined, type is undefined</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//undefined</span></code></pre></div>\n<p>Any variable can be emptied by setting the value to undefined.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">user <span class=\"token operator\">=</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is null value</p>\n<p>The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values. The type of null value is object.\nYou can empty the variable by setting the value to null.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> user<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//object</span></code></pre></div>\n</li>\n<li>\n<p>What is the difference between null and undefined</p>\n<p>Below are the main differences between null and undefined,</p>\n<table>\n<thead>\n<tr>\n<th>Null</th>\n<th>Undefined</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is an assignment value which indicates that variable points to no object.</td>\n<td>It is not an assignment value where a variable has been declared but has not yet been assigned a value.</td>\n</tr>\n<tr>\n<td>Type of null is object</td>\n<td>Type of undefined is undefined</td>\n</tr>\n<tr>\n<td>The null value is a primitive value that represents the null, empty, or non-existent reference.</td>\n<td>The undefined value is a primitive value used when a variable has not been assigned a value.</td>\n</tr>\n<tr>\n<td>Indicates the absence of a value for a variable</td>\n<td>Indicates absence of variable itself</td>\n</tr>\n<tr>\n<td>Converted to zero (0) while performing primitive operations</td>\n<td>Converted to NaN while performing primitive operations</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What is eval</p>\n<p>The eval() function evaluates JavaScript code represented as a string. The string can be a JavaScript expression, variable, statement, or sequence of statements.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">eval</span><span class=\"token punctuation\">(</span><span class=\"token string\">'1 + 2'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//  3</span></code></pre></div>\n</li>\n<li>\n<p>What is the difference between window and document</p>\n<p>Below are the main differences between window and document,</p>\n<table>\n<thead>\n<tr>\n<th>Window</th>\n<th>Document</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is the root level element in any web page</td>\n<td>It is the direct child of the window object. This is also known as Document Object Model(DOM)</td>\n</tr>\n<tr>\n<td>By default window object is available implicitly in the page</td>\n<td>You can access it via window.document or document.</td>\n</tr>\n<tr>\n<td>It has methods like alert(), confirm() and properties like document, location</td>\n<td>It provides methods like getElementById, getElementsByTagName, createElement etc</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>How do you access history in javascript</p>\n<p>The window.history object contains the browser's history. You can load previous and next URLs in the history using back() and next() methods.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">goBack</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span>history<span class=\"token punctuation\">.</span><span class=\"token function\">back</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">goForward</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span>history<span class=\"token punctuation\">.</span><span class=\"token function\">forward</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p><strong>Note:</strong> You can also access history without window prefix.</p>\n</li>\n<li>\n<p>How do you detect caps lock key turned on or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `mouseEvent getModifierState()` is used to return a boolean value that indicates whether the specified modifier key is activated or not. The modifiers such as CapsLock, ScrollLock and NumLock are activated when they are clicked, and deactivated when they are clicked again.\n\nLet's take an input element to detect the CapsLock on/off behavior with an example,\n\n```html\n&lt;input type=\"password\" onmousedown=\"enterInput(event)\" />\n\n&lt;p id=\"feedback\"></code></pre></div>\n</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script>\n    function enterInput(e) {\n        var flag = e.getModifierState('CapsLock');\n        if (flag) {\n            document.getElementById('feedback').innerHTML = 'CapsLock activated';\n        } else {\n            document.getElementById('feedback').innerHTML = 'CapsLock not activated';\n        }\n    }\n&lt;/script>\n```</code></pre></div>\n</li>\n<li>\n<p>What is isNaN</p>\n<p>The isNaN() function is used to determine whether a value is an illegal number (Not-a-Number) or not. i.e, This function returns true if the value equates to NaN. Otherwise it returns false.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">isNaN</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//true</span>\n<span class=\"token function\">isNaN</span><span class=\"token punctuation\">(</span><span class=\"token string\">'100'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//false</span></code></pre></div>\n</li>\n<li>\n<p>What are the differences between undeclared and undefined variables</p>\n<p>Below are the major differences between undeclared and undefined variables,</p>\n<table>\n<thead>\n<tr>\n<th>undeclared</th>\n<th>undefined</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>These variables do not exist in a program and are not declared</td>\n<td>These variables declared in the program but have not assigned any value</td>\n</tr>\n<tr>\n<td>If you try to read the value of an undeclared variable, then a runtime error is encountered</td>\n<td>If you try to read the value of an undefined variable, an undefined value is returned.</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What are global variables</p>\n<p>Global variables are those that are available throughout the length of the code without any scope. The var keyword is used to declare a local variable but if you omit it then it will become global variable</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">msg <span class=\"token operator\">=</span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// var is missing, it becomes global variable</span></code></pre></div>\n</li>\n<li>\n<p>What are the problems with global variables</p>\n<p>The problem with global variables is the conflict of variable names of local and global scope. It is also difficult to debug and test the code that relies on global variables.</p>\n</li>\n<li>\n<p>What is NaN property</p>\n<p>The NaN property is a global property that represents \"Not-a-Number\" value. i.e, It indicates that a value is not a legal number. It is very rare to use NaN in a program but it can be used as return value for few cases</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">Math<span class=\"token punctuation\">.</span><span class=\"token function\">sqrt</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of isFinite function</p>\n<p>The isFinite() function is used to determine whether a number is a finite, legal number. It returns false if the value is +infinity, -infinity, or NaN (Not-a-Number), otherwise it returns true.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token function\">isFinite</span><span class=\"token punctuation\">(</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">isFinite</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n<span class=\"token function\">isFinite</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">Infinity</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// false</span>\n\n<span class=\"token function\">isFinite</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n</li>\n<li>\n<p>What is an event flow</p>\n<p>Event flow is the order in which event is received on the web page. When you click an element that is nested in various other elements, before your click actually reaches its destination, or target element, it must trigger the click event for each of its parent elements first, starting at the top with the global window object.\nThere are two ways of event flow</p>\n<ol>\n<li>Top to Bottom(Event Capturing)</li>\n<li>Bottom to Top (Event Bubbling)</li>\n</ol>\n</li>\n<li>\n<p>What is event bubbling</p>\n<p>Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors (parents) of the target element in the same nesting hierarchy till it reaches the outermost DOM element.</p>\n</li>\n<li>\n<p>What is event capturing</p>\n<p>Event capturing is a type of event propagation where the event is first captured by the outermost element, and then successively triggers on the descendants (children) of the target element in the same nesting hierarchy till it reaches the innermost DOM element.</p>\n</li>\n<li>\n<p>How do you submit a form using JavaScript</p>\n<p>You can submit a form using <code class=\"language-text\">document.forms[0].submit()</code>. All the form input's information is submitted using onsubmit event handler</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">submit</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    document<span class=\"token punctuation\">.</span>forms<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">submit</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</li>\n<li>\n<p>How do you find operating system details</p>\n<p>The window.navigator object contains information about the visitor's browser OS details. Some of the OS properties are available under platform property,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>navigator<span class=\"token punctuation\">.</span>platform<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</li>\n<li>\n<p>What is the difference between document load and DOMContentLoaded events</p>\n<p>The <code class=\"language-text\">DOMContentLoaded</code> event is fired when the initial HTML document has been completely loaded and parsed, without waiting for assets(stylesheets, images, and subframes) to finish loading. Whereas The load event is fired when the whole page has loaded, including all dependent resources(stylesheets, images).</p>\n</li>\n<li>\n<p>What is the difference between native, host and user objects</p>\n<p><code class=\"language-text\">Native objects</code> are objects that are part of the JavaScript language defined by the ECMAScript specification. For example, String, Math, RegExp, Object, Function etc core objects defined in the ECMAScript spec.\n<code class=\"language-text\">Host objects</code> are objects provided by the browser or runtime environment (Node). For example, window, XmlHttpRequest, DOM nodes etc are considered as host objects.\n<code class=\"language-text\">User objects</code> are objects defined in the javascript code. For example, User objects created for profile information.</p>\n</li>\n<li>\n<p>What are the tools or techniques used for debugging JavaScript code</p>\n<p>You can use below tools or techniques for debugging javascript</p>\n<ol>\n<li>Chrome Devtools</li>\n<li>debugger statement</li>\n<li>Good old console.log statement</li>\n</ol>\n</li>\n<li>\n<p>What are the pros and cons of promises over callbacks</p>\n<p>Below are the list of pros and cons of promises over callbacks,</p>\n<p><strong>Pros:</strong></p>\n<ol>\n<li>It avoids callback hell which is unreadable</li>\n<li>Easy to write sequential asynchronous code with .then()</li>\n<li>Easy to write parallel asynchronous code with Promise.all()</li>\n<li>Solves some of the common problems of callbacks(call the callback too late, too early, many times and swallow errors/exceptions)</li>\n</ol>\n<p><strong>Cons:</strong></p>\n<ol>\n<li>It makes little complex code</li>\n<li>You need to load a polyfill if ES6 is not supported</li>\n</ol>\n</li>\n<li>\n<p>What is the difference between an attribute and a property</p>\n<p>Attributes are defined on the HTML markup whereas properties are defined on the DOM. For example, the below HTML element has 2 attributes type and value,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>input type<span class=\"token operator\">=</span><span class=\"token string\">\"text\"</span> value<span class=\"token operator\">=</span><span class=\"token string\">\"Name:\"</span><span class=\"token operator\">></span></code></pre></div>\n<p>You can retrieve the attribute value as below,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> input <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'input'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'value'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Good morning</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Good morning</span></code></pre></div>\n<p>And after you change the value of the text field to \"Good evening\", it becomes like</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'value'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Good morning</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>input<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Good evening</span></code></pre></div>\n</li>\n<li>\n<p>What is same-origin policy</p>\n<p>The same-origin policy is a policy that prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of URI scheme, hostname, and port number. If you enable this policy then it prevents a malicious script on one page from obtaining access to sensitive data on another web page using Document Object Model(DOM).</p>\n</li>\n<li>\n<p>What is the purpose of void 0</p>\n<p>Void(0) is used to prevent the page from refreshing. This will be helpful to eliminate the unwanted side-effect, because it will return the undefined primitive value. It is commonly used for HTML documents that use href=\"JavaScript:Void(0);\" within an <code class=\"language-text\">&lt;a></code> element. i.e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression.\nFor example, the below link notify the message without reloading the page</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token operator\">&lt;</span>a href<span class=\"token operator\">=</span><span class=\"token string\">\"JavaScript:void(0);\"</span> onclick<span class=\"token operator\">=</span><span class=\"token string\">\"alert('Well done!')\"</span><span class=\"token operator\">></span>\n    Click Me<span class=\"token operator\">!</span>\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span></code></pre></div>\n</li>\n<li>\n<p>Is JavaScript a compiled or interpreted language</p>\n<p>JavaScript is an interpreted language, not a compiled language. An interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. Nowadays modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.</p>\n</li>\n<li>\n<p>Is JavaScript a case-sensitive language</p>\n<p>Yes, JavaScript is a case sensitive language. The language keywords, variables, function &#x26; object names, and any other identifiers must always be typed with a consistent capitalization of letters.</p>\n</li>\n<li>\n<p>Is there any relation between Java and JavaScript</p>\n<p>No, they are entirely two different programming languages and have nothing to do with each other. But both of them are Object Oriented Programming languages and like many other languages, they follow similar syntax for basic features(if, else, for, switch, break, continue etc).</p>\n</li>\n<li>\n<p>What are events</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Events are \"things\" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can `react` on these events. Some of the examples of HTML events are,\n\n1. Web page has finished loading\n2. Input field was changed\n3. Button was clicked\n\nLet's describe the behavior of click event for button element,\n\n```javascript\n&lt;!doctype html>\n&lt;html>\n &lt;head>\n   &lt;script>\n     function greeting() {\n       alert('Hello! Good morning');\n     }\n   &lt;/script>\n &lt;/head>\n &lt;body>\n   &lt;button type=\"button\" onclick=\"greeting()\">Click me&lt;/button>\n &lt;/body>\n&lt;/html>\n```</code></pre></div>\n</li>\n<li>\n<p>Who created javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript was created by Brendan Eich in 1995 during his time at Netscape Communications. Initially it was developed under the name `Mocha`, but later the language was officially called `LiveScript` when it first shipped in beta releases of Netscape.</code></pre></div>\n</li>\n<li>\n<p>What is the use of preventDefault method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The preventDefault() method cancels the event if it is cancelable, meaning that the default action or behaviour that belongs to the event will not occur. For example, prevent form submission when clicking on submit button and prevent opening the page URL when clicking on hyperlink are some common use cases.\n\n```javascript\ndocument.getElementById('link').addEventListener('click', function (event) {\n    event.preventDefault();\n});\n```\n\n**Note:** Remember that not all events are cancelable.</code></pre></div>\n</li>\n<li>\n<p>What is the use of stopPropagation method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The stopPropagation method is used to stop the event from bubbling up the event chain. For example, the below nested divs with stopPropagation method prevents default event propagation when clicking on nested div(Div1)\n\n```javascript\n&lt;p>Click DIV1 Element&lt;/p>\n&lt;div onclick=\"secondFunc()\">DIV 2\n  &lt;div onclick=\"firstFunc(event)\">DIV 1&lt;/div>\n&lt;/div>\n\n&lt;script>\nfunction firstFunc(event) {\n  alert(\"DIV 1\");\n  event.stopPropagation();\n}\n\nfunction secondFunc() {\n  alert(\"DIV 2\");\n}\n&lt;/script>\n```</code></pre></div>\n</li>\n<li>\n<p>What are the steps involved in return false usage</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The return false statement in event handlers performs the below steps,\n\n1. First it stops the browser's default action or behaviour.\n2. It prevents the event from propagating the DOM\n3. Stops callback execution and returns immediately when called.</code></pre></div>\n</li>\n<li>\n<p>What is BOM</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Browser Object Model (BOM) allows JavaScript to \"talk to\" the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers.\n\n![Screenshot](images/bom.png)</code></pre></div>\n</li>\n<li>\n<p>What is the use of setTimeout</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,\n\n```javascript\nsetTimeout(function () {\n    console.log('Good morning');\n}, 2000);\n```</code></pre></div>\n</li>\n<li>\n<p>What is the use of setInterval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,\n\n```javascript\nsetInterval(function () {\n    console.log('Good morning');\n}, 2000);\n```</code></pre></div>\n</li>\n<li>\n<p>Why is JavaScript treated as Single threaded</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs.</code></pre></div>\n</li>\n<li>\n<p>What is an event delegation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it.\n\nFor example, if you wanted to detect field changes in inside a specific form, you can use event delegation technique,\n\n```javascript\nvar form = document.querySelector('#registration-form');\n\n// Listen for changes to fields inside the form\nform.addEventListener(\n    'input',\n    function (event) {\n        // Log the field that was changed\n        console.log(event.target);\n    },\n    false\n);\n```</code></pre></div>\n</li>\n<li>\n<p>What is ECMAScript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. The first edition of ECMAScript was released in 1997.</code></pre></div>\n</li>\n<li>\n<p>What is JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language in the way objects are built in JavaScript.</code></pre></div>\n</li>\n<li>\n<p>What are the syntax rules of JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of syntax rules of JSON\n\n1. The data is in name/value pairs\n2. The data is separated by commas\n3. Curly braces hold objects\n4. Square brackets hold arrays</code></pre></div>\n</li>\n<li>\n<p>What is the purpose JSON stringify</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">When sending data to a web server, the data has to be in a string format. You can achieve this by converting JSON object into a string using stringify() method.\n\n```javascript\nvar userJSON = { name: 'John', age: 31 };\nvar userString = JSON.stringify(user);\nconsole.log(userString); //\"{\"name\":\"John\",\"age\":31}\"\n```</code></pre></div>\n</li>\n<li>\n<p>How do you parse JSON string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">When receiving the data from a web server, the data is always in a string format. But you can convert this string value to a javascript object using parse() method.\n\n```javascript\nvar userString = '{\"name\":\"John\",\"age\":31}';\nvar userJSON = JSON.parse(userString);\nconsole.log(userJSON); // {name: \"John\", age: 31}\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">When exchanging data between a browser and a server, the data can only be text. Since JSON is text only, it can easily be sent to and from a server, and used as a data format by any programming language.</code></pre></div>\n</li>\n<li>\n<p>What are PWAs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Progressive web applications (PWAs) are a type of mobile app delivered through the web, built using common web technologies including HTML, CSS and JavaScript. These PWAs are deployed to servers, accessible through URLs, and indexed by search engines.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of clearTimeout method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The clearTimeout() function is used in javascript to clear the timeout which has been set by setTimeout()function before that. i.e, The return value of setTimeout() function is stored in a variable and it's passed into the clearTimeout() function to clear the timer.\n\nFor example, the below setTimeout method is used to display the message after 3 seconds. This timeout can be cleared by the clearTimeout() method.\n\n```javascript\n&lt;script>\nvar msg;\nfunction greeting() {\n   alert('Good morning');\n}\nfunction start() {\n  msg =setTimeout(greeting, 3000);\n\n}\n\nfunction stop() {\n    clearTimeout(msg);\n}\n&lt;/script>\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of clearInterval method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The clearInterval() function is used in javascript to clear the interval which has been set by setInterval() function. i.e, The return value returned by setInterval() function is stored in a variable and it's passed into the clearInterval() function to clear the interval.\n\nFor example, the below setInterval method is used to display the message for every 3 seconds. This interval can be cleared by the clearInterval() method.\n\n```javascript\n&lt;script>\nvar msg;\nfunction greeting() {\n   alert('Good morning');\n}\nfunction start() {\n  msg = setInterval(greeting, 3000);\n\n}\n\nfunction stop() {\n    clearInterval(msg);\n}\n&lt;/script>\n```</code></pre></div>\n</li>\n<li>\n<p>How do you redirect new page in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In vanilla javascript, you can redirect to a new page using the `location` property of window object. The syntax would be as follows,\n\n```javascript\nfunction redirect() {\n    window.location.href = 'newPage.html';\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether a string contains a substring</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are 3 possible ways to check whether a string contains a substring or not,\n\n1. **Using includes:** ES6 provided `String.prototype.includes` method to test a string contains a substring\n\n```javascript\nvar mainString = 'hello',\n    subString = 'hell';\nmainString.includes(subString);\n```\n\n1. **Using indexOf:** In an ES5 or older environment, you can use `String.prototype.indexOf` which returns the index of a substring. If the index value is not equal to -1 then it means the substring exists in the main string.\n\n```javascript\nvar mainString = 'hello',\n    subString = 'hell';\nmainString.indexOf(subString) !== -1;\n```\n\n1. **Using RegEx:** The advanced solution is using Regular expression's test method(`RegExp.test`), which allows for testing for against regular expressions\n\n```javascript\nvar mainString = 'hello',\n    regex = /hell/;\nregex.test(mainString);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you validate an email in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead of the client side. Because the javascript can be disabled on the client side.\n\n```javascript\nfunction validateEmail(email) {\n    var re =\n        /^(([^&lt;>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^&lt;>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n    return re.test(String(email).toLowerCase());\n}\n```\n\nThe above regular expression accepts unicode characters.</code></pre></div>\n</li>\n<li>\n<p>How do you get the current url with javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `window.location.href` expression to get the current url path and you can use the same expression for updating the URL too. You can also use `document.URL` for read-only purposes but this solution has issues in FF.\n\n```javascript\nconsole.log('location.href', window.location.href); // Returns full URL\n```</code></pre></div>\n</li>\n<li>\n<p>What are the various url properties of location object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The below `Location` object properties can be used to access URL components of the page,\n\n1. href - The entire URL\n2. protocol - The protocol of the URL\n3. host - The hostname and port of the URL\n4. hostname - The hostname of the URL\n5. port - The port number in the URL\n6. pathname - The path name of the URL\n7. search - The query portion of the URL\n8. hash - The anchor portion of the URL</code></pre></div>\n</li>\n<li>\n<p>How do get query string values in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string,\n\n```javascript\nconst urlParams = new URLSearchParams(window.location.search);\nconst clientCode = urlParams.get('clientCode');\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check if a key exists in an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can check whether a key exists in an object or not using three approaches,\n\n1. **Using in operator:** You can use the in operator whether a key exists in an object or not\n\n```javascript\n'key' in obj;\n```\n\nand If you want to check if a key doesn't exist, remember to use parenthesis,\n\n```javascript\n!('key' in obj);\n```\n\n1. **Using hasOwnProperty method:** You can use `hasOwnProperty` to particularly test for properties of the object instance (and not inherited properties)\n\n```javascript\nobj.hasOwnProperty('key'); // true\n```\n\n1. **Using undefined comparison:** If you access a non-existing property from an object, the result is undefined. Let's compare the properties against undefined to determine the existence of the property.\n\n```javascript\nconst user = {\n    name: 'John'\n};\n\nconsole.log(user.name !== undefined); // true\nconsole.log(user.nickName !== undefined); // false\n```</code></pre></div>\n</li>\n<li>\n<p>How do you loop through or enumerate javascript object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `for-in` loop to loop through javascript object. You can also make sure that the key you get is an actual property of an object, and doesn't come from the prototype using `hasOwnProperty` method.\n\n```javascript\nvar object = {\n    k1: 'value1',\n    k2: 'value2',\n    k3: 'value3'\n};\n\nfor (var key in object) {\n    if (object.hasOwnProperty(key)) {\n        console.log(key + ' -> ' + object[key]); // k1 -> value1 ...\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you test for an empty object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are different solutions based on ECMAScript versions\n\n1. **Using Object entries(ECMA 7+):** You can use object entries length along with constructor type.\n\n```javascript\nObject.entries(obj).length === 0 &amp;&amp; obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well\n```\n\n1. **Using Object keys(ECMA 5+):** You can use object keys length along with constructor type.\n\n```javascript\nObject.keys(obj).length === 0 &amp;&amp; obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well\n```\n\n1. **Using for-in with hasOwnProperty(Pre-ECMA 5):** You can use a for-in loop along with hasOwnProperty.\n\n```javascript\nfunction isEmpty(obj) {\n    for (var prop in obj) {\n        if (obj.hasOwnProperty(prop)) {\n            return false;\n        }\n    }\n\n    return JSON.stringify(obj) === JSON.stringify({});\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is an arguments object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,\n\n```javascript\nfunction sum() {\n    var total = 0;\n    for (var i = 0, len = arguments.length; i &lt; len; ++i) {\n        total += arguments[i];\n    }\n    return total;\n}\n\nsum(1, 2, 3); // returns 6\n```\n\n**Note:** You can't apply array methods on arguments object. But you can convert into a regular array as below.\n\n```javascript\nvar argsArray = Array.prototype.slice.call(arguments);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make first letter of the string in an uppercase</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can create a function which uses a chain of string methods such as charAt, toUpperCase and slice methods to generate a string with the first letter in uppercase.\n\n```javascript\nfunction capitalizeFirstLetter(string) {\n    return string.charAt(0).toUpperCase() + string.slice(1);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the pros and cons of for loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The for-loop is a commonly used iteration syntax in javascript. It has both pros and cons</code></pre></div>\n</li>\n</ol>\n<p>Pros</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> 1. Works on every environment\n 2. You can use break and continue flow control statements</code></pre></div>\n<p>Cons</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> 1. Too verbose\n 2. Imperative\n 3. You might face one-by-off errors</code></pre></div>\n<ol start=\"131\">\n<li>\n<p>How do you display the current date in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `new Date()` to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy\n\n```javascript\nvar today = new Date();\nvar dd = String(today.getDate()).padStart(2, '0');\nvar mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!\nvar yyyy = today.getFullYear();\n\ntoday = mm + '/' + dd + '/' + yyyy;\ndocument.write(today);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you compare two date objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to use date.getTime() method to compare date values instead of comparison operators (==, !=, ===, and !== operators)\n\n```javascript\nvar d1 = new Date();\nvar d2 = new Date(d1);\nconsole.log(d1.getTime() === d2.getTime()); //True\nconsole.log(d1 === d2); // False\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check if a string starts with another string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use ECMAScript 6's `String.prototype.startsWith()` method to check if a string starts with another string or not. But it is not yet supported in all browsers. Let's see an example to see this usage,\n\n```javascript\n'Good morning'.startsWith('Good'); // true\n'Good morning'.startsWith('morning'); // false\n```</code></pre></div>\n</li>\n<li>\n<p>How do you trim a string in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript provided a trim method on string types to trim any whitespaces present at the beginning or ending of the string.\n\n```javascript\n'  Hello World   '.trim(); //Hello World\n```\n\nIf your browser(&lt;IE9) doesn't support this method then you can use below polyfill.\n\n```javascript\nif (!String.prototype.trim) {\n    (function () {\n        // Make sure we trim BOM and NBSP\n        var rtrim = /^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g;\n        String.prototype.trim = function () {\n            return this.replace(rtrim, '');\n        };\n    })();\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you add a key value pair in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are two possible solutions to add new properties to an object. Let's take a simple object to explain these solutions.\n\n```javascript\nvar object = {\n    key1: value1,\n    key2: value2\n};\n```\n\n1. **Using dot notation:** This solution is useful when you know the name of the property\n\n```javascript\nobject.key3 = 'value3';\n```\n\n1. **Using square bracket notation:** This solution is useful when the name of the property is dynamically determined.\n\n```javascript\nobj['key3'] = 'value3';\n```</code></pre></div>\n</li>\n<li>\n<p>Is the !-- notation represents a special operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No,that's not a special operator. But it is a combination of 2 standard operators one after the other,\n\n1. A logical not (!)\n2. A prefix decrement (--)\n\nAt first, the value decremented by one and then tested to see if it is equal to zero or not for determining the truthy/falsy value.</code></pre></div>\n</li>\n<li>\n<p>How do you assign default values to variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the logical or operator `||` in an assignment expression to provide a default value. The syntax looks like as below,\n\n```javascript\nvar a = b || c;\n```\n\nAs per the above expression, variable 'a 'will get the value of 'c' only if 'b' is falsy (if is null, false, undefined, 0, empty string, or NaN), otherwise 'a' will get the value of 'b'.</code></pre></div>\n</li>\n<li>\n<p>How do you define multiline strings</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can define multiline string literals using the '\\\\' character followed by line terminator.\n\n```javascript\nvar str =\n    'This is a \\\nvery lengthy \\\nsentence!';\n```\n\nBut if you have a space after the '\\\\' character, the code will look exactly the same, but it will raise a SyntaxError.</code></pre></div>\n</li>\n<li>\n<p>What is an app shell model</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An application shell (or app shell) architecture is one way to build a Progressive Web App that reliably and instantly loads on your users' screens, similar to what you see in native applications. It is useful for getting some initial HTML to the screen fast without a network.</code></pre></div>\n</li>\n<li>\n<p>Can we define properties for functions</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, We can define properties for functions because functions are also objects.\n\n```javascript\nfn = function (x) {\n    //Function code goes here\n};\n\nfn.name = 'John';\n\nfn.profile = function (y) {\n    //Profile code goes here\n};\n```</code></pre></div>\n</li>\n<li>\n<p>What is the way to find the number of parameters expected by a function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `function.length` syntax to find the number of parameters expected by a function. Let's take an example of `sum` function to calculate the sum of numbers,\n\n```javascript\nfunction sum(num1, num2, num3, num4) {\n    return num1 + num2 + num3 + num4;\n}\nsum.length; // 4 is the number of parameters expected.\n```</code></pre></div>\n</li>\n<li>\n<p>What is a polyfill</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A polyfill is a piece of JS code used to provide modern functionality on older browsers that do not natively support it. For example, Silverlight plugin polyfill can be used to mimic the functionality of an HTML Canvas element on Microsoft Internet Explorer 7.</code></pre></div>\n</li>\n<li>\n<p>What are break and continue statements</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The break statement is used to \"jump out\" of a loop. i.e, It breaks the loop and continues executing the code after the loop.\n\n```javascript\nfor (i = 0; i &lt; 10; i++) {\n    if (i === 5) {\n        break;\n    }\n    text += 'Number: ' + i + '&lt;br>';\n}\n```\n\nThe continue statement is used to \"jump over\" one iteration in the loop. i.e, It breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.\n\n```javascript\nfor (i = 0; i &lt; 10; i++) {\n    if (i === 5) {\n        continue;\n    }\n    text += 'Number: ' + i + '&lt;br>';\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are js labels</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The label statement allows us to name loops and blocks in JavaScript. We can then use these labels to refer back to the code later. For example, the below code with labels avoids printing the numbers when they are same,\n\n```javascript\nvar i, j;\n\nloop1: for (i = 0; i &lt; 3; i++) {\n    loop2: for (j = 0; j &lt; 3; j++) {\n        if (i === j) {\n            continue loop1;\n        }\n        console.log('i = ' + i + ', j = ' + j);\n    }\n}\n\n// Output is:\n//   \"i = 1, j = 0\"\n//   \"i = 2, j = 0\"\n//   \"i = 2, j = 1\"\n```</code></pre></div>\n</li>\n<li>\n<p>What are the benefits of keeping declarations at the top</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to keep all declarations at the top of each script or function. The benefits of doing this are,\n\n1. Gives cleaner code\n2. It provides a single place to look for local variables\n3. Easy to avoid unwanted global variables\n4. It reduces the possibility of unwanted re-declarations</code></pre></div>\n</li>\n<li>\n<p>What are the benefits of initializing variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to initialize variables because of the below benefits,\n\n1. It gives cleaner code\n2. It provides a single place to initialize variables\n3. Avoid undefined values in the code</code></pre></div>\n</li>\n<li>\n<p>What are the recommendations to create new object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to avoid creating new objects using `new Object()`. Instead you can initialize values based on it's type to create the objects.\n\n1. Assign {} instead of new Object()\n2. Assign \"\" instead of new String()\n3. Assign 0 instead of new Number()\n4. Assign false instead of new Boolean()\n5. Assign [] instead of new Array()\n6. Assign /()/ instead of new RegExp()\n7. Assign function (){} instead of new Function()\n\nYou can define them as an example,\n\n```javascript\nvar v1 = {};\nvar v2 = '';\nvar v3 = 0;\nvar v4 = false;\nvar v5 = [];\nvar v6 = /()/;\nvar v7 = function () {};\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define JSON arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JSON arrays are written inside square brackets and arrays contain javascript objects. For example, the JSON array of users would be as below,\n\n```javascript\n\"users\":[\n  {\"firstName\":\"John\", \"lastName\":\"Abrahm\"},\n  {\"firstName\":\"Anna\", \"lastName\":\"Smith\"},\n  {\"firstName\":\"Shane\", \"lastName\":\"Warn\"}\n]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you generate random integers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use Math.random() with Math.floor() to return random integers. For example, if you want generate random integers between 1 to 10, the multiplication factor should be 10,\n\n```javascript\nMath.floor(Math.random() * 10) + 1; // returns a random integer from 1 to 10\nMath.floor(Math.random() * 100) + 1; // returns a random integer from 1 to 100\n```\n\n**Note:** Math.random() returns a random number between 0 (inclusive), and 1 (exclusive)</code></pre></div>\n</li>\n<li>\n<p>Can you write a random integers function to print integers with in a range</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, you can create a proper random function to return a random number between min and max (both included)\n\n```javascript\nfunction randomInteger(min, max) {\n    return Math.floor(Math.random() * (max - min + 1)) + min;\n}\nrandomInteger(1, 100); // returns a random integer from 1 to 100\nrandomInteger(1, 1000); // returns a random integer from 1 to 1000\n```</code></pre></div>\n</li>\n<li>\n<p>What is tree shaking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tree shaking is a form of dead code elimination. It means that unused modules will not be included in the bundle during the build process and for that it relies on the static structure of ES2015 module syntax,( i.e. import and export). Initially this has been popularized by the ES2015 module bundler `rollup`.</code></pre></div>\n</li>\n<li>\n<p>What is the need of tree shaking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tree Shaking can significantly reduce the code size in any application. i.e, The less code we send over the wire the more performant the application will be. For example, if we just want to create a \"Hello World\" Application using SPA frameworks then it will take around a few MBs, but by tree shaking it can bring down the size to just a few hundred KBs. Tree shaking is implemented in Rollup and Webpack bundlers.</code></pre></div>\n</li>\n<li>\n<p>Is it recommended to use eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, it allows arbitrary code to be run which causes a security problem. As we know that the eval() function is used to run text as code. In most of the cases, it should not be necessary to use it.</code></pre></div>\n</li>\n<li>\n<p>What is a Regular Expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A regular expression is a sequence of characters that forms a search pattern. You can use this search pattern for searching data in a text. These can be used to perform all types of text search and text replace operations. Let's see the syntax format now,\n\n```javascript\n/pattern/modifiers;\n```\n\nFor example, the regular expression or search pattern with case-insensitive username would be,\n\n```javascript\n/John/i;\n```</code></pre></div>\n</li>\n<li>\n<p>What are the string methods available in Regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Regular Expressions has two string methods: search() and replace().\nThe search() method uses an expression to search for a match, and returns the position of the match.\n\n```javascript\nvar msg = 'Hello John';\nvar n = msg.search(/John/i); // 6\n```\n\nThe replace() method is used to return a modified string where the pattern is replaced.\n\n```javascript\nvar msg = 'Hello John';\nvar n = msg.replace(/John/i, 'Buttler'); // Hello Buttler\n```</code></pre></div>\n</li>\n<li>\n<p>What are modifiers in regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Modifiers can be used to perform case-insensitive and global searches. Let's list down some of the modifiers,\n\n| Modifier | Description                                             |\n| -------- | ------------------------------------------------------- |\n| i        | Perform case-insensitive matching                       |\n| g        | Perform a global match rather than stops at first match |\n| m        | Perform multiline matching                              |\n\nLet's take an example of global modifier,\n\n```javascript\nvar text = 'Learn JS one by one';\nvar pattern = /one/g;\nvar result = text.match(pattern); // one,one\n```</code></pre></div>\n</li>\n<li>\n<p>What are regular expression patterns</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Regular Expressions provide a group of patterns in order to match characters. Basically they are categorized into 3 types,\n\n1. **Brackets:** These are used to find a range of characters.\n   For example, below are some use cases,\n    1. [abc]: Used to find any of the characters between the brackets(a,b,c)\n    2. [0-9]: Used to find any of the digits between the brackets\n    3. (a|b): Used to find any of the alternatives separated with |\n2. **Metacharacters:** These are characters with a special meaning\n   For example, below are some use cases,\n    1. \\\\d: Used to find a digit\n    2. \\\\s: Used to find a whitespace character\n    3. \\\\b: Used to find a match at the beginning or ending of a word\n3. **Quantifiers:** These are useful to define quantities\n   For example, below are some use cases,\n    1. n+: Used to find matches for any string that contains at least one n\n    2. n\\*: Used to find matches for any string that contains zero or more occurrences of n\n    3. n?: Used to find matches for any string that contains zero or one occurrences of n</code></pre></div>\n</li>\n<li>\n<p>What is a RegExp object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">RegExp object is a regular expression object with predefined properties and methods. Let's see the simple usage of RegExp object,\n\n```javascript\nvar regexp = new RegExp('\\\\w+');\nconsole.log(regexp);\n// expected output: /\\w+/\n```</code></pre></div>\n</li>\n<li>\n<p>How do you search a string for a pattern</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the test() method of regular expression in order to search a string for a pattern, and return true or false depending on the result.\n\n```javascript\nvar pattern = /you/;\nconsole.log(pattern.test('How are you?')); //true\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of exec method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The purpose of exec method is similar to test method but it executes a search for a match in a specified string and returns a result array, or null instead of returning true/false.\n\n```javascript\nvar pattern = /you/;\nconsole.log(pattern.exec('How are you?')); //[\"you\", index: 8, input: \"How are you?\", groups: undefined]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you change the style of a HTML element</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can change inline style or classname of a HTML element using javascript\n\n1. **Using style property:** You can modify inline style using style property\n\n```javascript\ndocument.getElementById('title').style.fontSize = '30px';\n```\n\n1. **Using ClassName property:** It is easy to modify element class using className property\n\n```javascript\ndocument.getElementById('title').className = 'custom-title';\n```</code></pre></div>\n</li>\n<li>\n<p>What would be the result of 1+2+'3'</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`.</code></pre></div>\n</li>\n<li>\n<p>What is a debugger statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.\nFor example, in the below function a debugger statement has been inserted. So\nexecution is paused at the debugger statement just like a breakpoint in the script source.\n\n```javascript\nfunction getProfile() {\n    // code goes here\n    debugger;\n    // code goes here\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of breakpoints in debugging</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can set breakpoints in the javascript code once the debugger statement is executed and the debugger window pops up. At each breakpoint, javascript will stop executing, and let you examine the JavaScript values. After examining values, you can resume the execution of code using the play button.</code></pre></div>\n</li>\n<li>\n<p>Can I use reserved words as identifiers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, you cannot use the reserved words as variables, labels, object or function names. Let's see one simple example,\n\n```javascript\nvar else = \"hello\"; // Uncaught SyntaxError: Unexpected token else\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect a mobile browser</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use regex which returns a true or false value depending on whether or not the user is browsing with a mobile.\n\n```javascript\nwindow.mobilecheck = function () {\n    var mobileCheck = false;\n    (function (a) {\n        if (\n            /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(\n                a\n            ) ||\n            /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i.test(\n                a.substr(0, 4)\n            )\n        )\n            mobileCheck = true;\n    })(navigator.userAgent || navigator.vendor || window.opera);\n    return mobileCheck;\n};\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect a mobile browser without regexp</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can detect mobile browsers by simply running through a list of devices and checking if the useragent matches anything. This is an alternative solution for RegExp usage,\n\n```javascript\nfunction detectmob() {\n    if (\n        navigator.userAgent.match(/Android/i) ||\n        navigator.userAgent.match(/webOS/i) ||\n        navigator.userAgent.match(/iPhone/i) ||\n        navigator.userAgent.match(/iPad/i) ||\n        navigator.userAgent.match(/iPod/i) ||\n        navigator.userAgent.match(/BlackBerry/i) ||\n        navigator.userAgent.match(/Windows Phone/i)\n    ) {\n        return true;\n    } else {\n        return false;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get the image width and height using JS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can programmatically get the image and check the dimensions(width and height) using Javascript.\n\n```javascript\nvar img = new Image();\nimg.onload = function () {\n    console.log(this.width + 'x' + this.height);\n};\nimg.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make synchronous HTTP request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Browsers provide an XMLHttpRequest object which can be used to make synchronous HTTP requests from JavaScript\n\n```javascript\nfunction httpGet(theUrl) {\n    var xmlHttpReq = new XMLHttpRequest();\n    xmlHttpReq.open('GET', theUrl, false); // false for synchronous request\n    xmlHttpReq.send(null);\n    return xmlHttpReq.responseText;\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make asynchronous HTTP request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Browsers provide an XMLHttpRequest object which can be used to make asynchronous HTTP requests from JavaScript by passing the 3rd parameter as true.\n\n```javascript\nfunction httpGetAsync(theUrl, callback) {\n    var xmlHttpReq = new XMLHttpRequest();\n    xmlHttpReq.onreadystatechange = function () {\n        if (xmlHttpReq.readyState == 4 &amp;&amp; xmlHttpReq.status == 200) callback(xmlHttpReq.responseText);\n    };\n    xmlHttp.open('GET', theUrl, true); // true for asynchronous\n    xmlHttp.send(null);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you convert date to another timezone in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the toLocaleString() method to convert dates in one timezone to another. For example, let's convert current date to British English timezone as below,\n\n```javascript\nconsole.log(event.toLocaleString('en-GB', { timeZone: 'UTC' })); //29/06/2019, 09:56:00\n```</code></pre></div>\n</li>\n<li>\n<p>What are the properties used to get size of window</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use them combination of these properties to calculate the size of a window or document,\n\n```javascript\nvar width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;\n\nvar height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;\n```</code></pre></div>\n</li>\n<li>\n<p>What is a conditional operator in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for if statements.\n\n```javascript\nvar isAuthenticated = false;\nconsole.log(isAuthenticated ? 'Hello, welcome' : 'Sorry, you are not authenticated'); //Sorry, you are not authenticated\n```</code></pre></div>\n</li>\n<li>\n<p>Can you apply chaining on conditional operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, you can apply chaining on conditional operators similar to if … else if … else if … else chain. The syntax is going to be as below,\n\n```javascript\nfunction traceValue(someParam) {\n    return condition1 ? value1 : condition2 ? value2 : condition3 ? value3 : value4;\n}\n\n// The above conditional operator is equivalent to:\n\nfunction traceValue(someParam) {\n    if (condition1) {\n        return value1;\n    } else if (condition2) {\n        return value2;\n    } else if (condition3) {\n        return value3;\n    } else {\n        return value4;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the ways to execute javascript after page load</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can execute javascript after page load in many different ways,\n\n1. **window.onload:**\n\n```javascript\nwindow.onload = function ...\n```\n\n1. **document.onload:**\n\n```javascript\ndocument.onload = function ...\n```\n\n1. **body onload:**\n\n```javascript\n&lt;body onload=\"script();\">\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between proto and prototype</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `__proto__` object is the actual object that is used in the lookup chain to resolve methods, etc. Whereas `prototype` is the object that is used to build `__proto__` when you create an object with new\n\n```javascript\nnew Employee().__proto__ === Employee.prototype;\nnew Employee().prototype === undefined;\n```</code></pre></div>\n</li>\n<li>\n<p>Give an example where do you really need semicolon</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to use semicolons after every statement in JavaScript. For example, in the below case it throws an error \".. is not a function\" at runtime due to missing semicolon.\n\n```javascript\n// define a function\nvar fn = (function () {\n    //...\n})(\n    // semicolon missing at this line\n\n    // then execute some code inside a closure\n    function () {\n        //...\n    }\n)();\n```\n\nand it will be interpreted as\n\n```javascript\nvar fn = (function () {\n    //...\n})(function () {\n    //...\n})();\n```\n\nIn this case, we are passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. Hence, the second function will fail with a \"... is not a function\" error at runtime.</code></pre></div>\n</li>\n<li>\n<p>What is a freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The **freeze()** method is used to freeze an object. Freezing an object does not allow adding new properties to an object,prevents from removing and prevents changing the enumerability, configurability, or writability of existing properties. i.e, It returns the passed object and does not create a frozen copy.\n\n```javascript\nconst obj = {\n    prop: 100\n};\n\nObject.freeze(obj);\nobj.prop = 200; // Throws an error in strict mode\n\nconsole.log(obj.prop); //100\n```\n\n**Note:** It causes a TypeError if the argument passed is not an object.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main benefits of using freeze method,\n\n1. It is used for freezing objects and arrays.\n2. It is used to make an object immutable.</code></pre></div>\n</li>\n<li>\n<p>Why do I need to use freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In the Object-oriented paradigm, an existing API contains certain elements that are not intended to be extended, modified, or re-used outside of their current context. Hence it works as the `final` keyword which is used in various languages.</code></pre></div>\n</li>\n<li>\n<p>How do you detect a browser language preference</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use navigator object to detect a browser language preference as below,\n\n```javascript\nvar language =\n    (navigator.languages &amp;&amp; navigator.languages[0]) || // Chrome / Firefox\n    navigator.language || // All browsers\n    navigator.userLanguage; // IE &lt;= 10\n\nconsole.log(language);\n```</code></pre></div>\n</li>\n<li>\n<p>How to convert string to title case with javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function,\n\n```javascript\nfunction toTitleCase(str) {\n    return str.replace(/\\w\\S*/g, function (txt) {\n        return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();\n    });\n}\ntoTitleCase('good morning john'); // Good Morning John\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect javascript disabled in the page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `&lt;noscript>` tag to detect javascript disabled or not. The code block inside `&lt;noscript>` gets executed when JavaScript is disabled, and is typically used to display alternative content when the page generated in JavaScript.\n\n```javascript\n&lt;script type=\"javascript\">\n    // JS related code goes here\n&lt;/script>\n&lt;noscript>\n    &lt;a href=\"next_page.html?noJS=true\">JavaScript is disabled in the page. Please click Next Page&lt;/a>\n&lt;/noscript>\n```</code></pre></div>\n</li>\n<li>\n<p>What are various operators supported by javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An operator is capable of manipulating(mathematical and logical computations) a certain value or operand. There are various operators supported by JavaScript as below,\n\n1. **Arithmetic Operators:** Includes + (Addition),- (Subtraction), \\* (Multiplication), / (Division), % (Modulus), + + (Increment) and - - (Decrement)\n2. **Comparison Operators:** Includes = =(Equal),!= (Not Equal), ===(Equal with type), > (Greater than),> = (Greater than or Equal to),&lt; (Less than),&lt;= (Less than or Equal to)\n3. **Logical Operators:** Includes &amp;&amp;(Logical AND),||(Logical OR),!(Logical NOT)\n4. **Assignment Operators:** Includes = (Assignment Operator), += (Add and Assignment Operator), - = (Subtract and Assignment Operator), \\*= (Multiply and Assignment), /= (Divide and Assignment), %= (Modules and Assignment)\n5. **Ternary Operators:** It includes conditional(: ?) Operator\n6. **typeof Operator:** It uses to find type of variable. The syntax looks like `typeof variable`</code></pre></div>\n</li>\n<li>\n<p>What is a rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Rest parameter is an improved way to handle function parameters which allows us to represent an indefinite number of arguments as an array. The syntax would be as below,\n\n```javascript\nfunction f(a, b, ...theArgs) {\n    // ...\n}\n```\n\nFor example, let's take a sum example to calculate on dynamic number of parameters,\n\n```javascript\nfunction total(…args){\nlet sum = 0;\nfor(let i of args){\nsum+=i;\n}\nreturn sum;\n}\nconsole.log(fun(1,2)); //3\nconsole.log(fun(1,2,3)); //6\nconsole.log(fun(1,2,3,4)); //13\nconsole.log(fun(1,2,3,4,5)); //15\n```\n\n**Note:** Rest parameter is added in ES2015 or ES6</code></pre></div>\n</li>\n<li>\n<p>What happens if you do not use rest parameter as a last argument</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The rest parameter should be the last argument, as its job is to collect all the remaining arguments into an array. For example, if you define a function like below it doesn't make any sense and will throw an error.\n\n```javascript\nfunction someFunc(a,…b,c){\n//You code goes here\nreturn;\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the bitwise operators available in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of bitwise logical operators used in JavaScript\n\n1. Bitwise AND ( &amp; )\n2. Bitwise OR ( | )\n3. Bitwise XOR ( ^ )\n4. Bitwise NOT ( ~ )\n5. Left Shift ( &lt;&lt; )\n6. Sign Propagating Right Shift ( >> )\n7. Zero fill Right Shift ( >>> )</code></pre></div>\n</li>\n<li>\n<p>What is a spread operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. Let's take an example to see this behavior,\n\n```javascript\nfunction calculateSum(x, y, z) {\n    return x + y + z;\n}\n\nconst numbers = [1, 2, 3];\n\nconsole.log(calculateSum(...numbers)); // 6\n```</code></pre></div>\n</li>\n<li>\n<p>How do you determine whether object is frozen or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object.isFrozen() method is used to determine if an object is frozen or not.An object is frozen if all of the below conditions hold true,\n\n1. If it is not extensible.\n2. If all of its properties are non-configurable.\n3. If all its data properties are non-writable.\n   The usage is going to be as follows,\n\n```javascript\nconst object = {\n    property: 'Welcome JS world'\n};\nObject.freeze(object);\nconsole.log(Object.isFrozen(object));\n```</code></pre></div>\n</li>\n<li>\n<p>How do you determine two values same or not using object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.is() method determines whether two values are the same value. For example, the usage with different types of values would be,\n\n```javascript\nObject.is('hello', 'hello'); // true\nObject.is(window, window); // true\nObject.is([], []); // false\n```\n\nTwo values are the same if one of the following holds:\n\n1. both undefined\n2. both null\n3. both true or both false\n4. both strings of the same length with the same characters in the same order\n5. both the same object (means both object have same reference)\n6. both numbers and\n   both +0\n   both -0\n   both NaN\n   both non-zero and both not NaN and both have the same value.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of using object is method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the applications of Object's `is` method are follows,\n\n1. It is used for comparison of two strings.\n2. It is used for comparison of two numbers.\n3. It is used for comparing the polarity of two numbers.\n4. It is used for comparison of two objects.</code></pre></div>\n</li>\n<li>\n<p>How do you copy properties from one object to other</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the Object.assign() method which is used to copy the values and properties from one or more source objects to a target object. It returns the target object which has properties and values copied from the target object. The syntax would be as below,\n\n```javascript\nObject.assign(target, ...sources);\n```\n\nLet's take example with one source and one target object,\n\n```javascript\nconst target = { a: 1, b: 2 };\nconst source = { b: 3, c: 4 };\n\nconst returnedTarget = Object.assign(target, source);\n\nconsole.log(target); // { a: 1, b: 3, c: 4 }\n\nconsole.log(returnedTarget); // { a: 1, b: 3, c: 4 }\n```\n\nAs observed in the above code, there is a common property(`b`) from source to target so it's value has been overwritten.</code></pre></div>\n</li>\n<li>\n<p>What are the applications of assign method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the some of main applications of Object.assign() method,\n\n1. It is used for cloning an object.\n2. It is used to merge objects with the same properties.</code></pre></div>\n</li>\n<li>\n<p>What is a proxy object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Proxy object is used to define custom behavior for fundamental operations such as property lookup, assignment, enumeration, function invocation, etc. The syntax would be as follows,\n\n```javascript\nvar p = new Proxy(target, handler);\n```\n\nLet's take an example of proxy object,\n\n```javascript\nvar handler = {\n    get: function (obj, prop) {\n        return prop in obj ? obj[prop] : 100;\n    }\n};\n\nvar p = new Proxy({}, handler);\np.a = 10;\np.b = null;\n\nconsole.log(p.a, p.b); // 10, null\nconsole.log('c' in p, p.c); // false, 100\n```\n\nIn the above code, it uses `get` handler which define the behavior of the proxy when an operation is performed on it</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of seal method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The **Object.seal()** method is used to seal an object, by preventing new properties from being added to it and marking all existing properties as non-configurable. But values of present properties can still be changed as long as they are writable. Let's see the below example to understand more about seal() method\n\n```javascript\nconst object = {\n    property: 'Welcome JS world'\n};\nObject.seal(object);\nobject.property = 'Welcome to object world';\nconsole.log(Object.isSealed(object)); // true\ndelete object.property; // You cannot delete when sealed\nconsole.log(object.property); //Welcome to object world\n```</code></pre></div>\n</li>\n<li>\n<p>What are the applications of seal method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main applications of Object.seal() method,\n\n1. It is used for sealing objects and arrays.\n2. It is used to make an object immutable.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between freeze and seal methods</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If an object is frozen using the Object.freeze() method then its properties become immutable and no changes can be made in them whereas if an object is sealed using the Object.seal() method then the changes can be made in the existing properties of the object.</code></pre></div>\n</li>\n<li>\n<p>How do you determine if an object is sealed or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.isSealed() method is used to determine if an object is sealed or not. An object is sealed if all of the below conditions hold true\n\n1. If it is not extensible.\n2. If all of its properties are non-configurable.\n3. If it is not removable (but not necessarily non-writable).\n   Let's see it in the action\n\n```javascript\nconst object = {\n    property: 'Hello, Good morning'\n};\n\nObject.seal(object); // Using seal() method to seal the object\n\nconsole.log(Object.isSealed(object)); // checking whether the object is sealed or not\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get enumerable key and value pairs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.entries() method is used to return an array of a given object's own enumerable string-keyed property [key, value] pairs, in the same order as that provided by a for...in loop. Let's see the functionality of object.entries() method in an example,\n\n```javascript\nconst object = {\n    a: 'Good morning',\n    b: 100\n};\n\nfor (let [key, value] of Object.entries(object)) {\n    console.log(`${key}: ${value}`); // a: 'Good morning'\n    // b: 100\n}\n```\n\n**Note:** The order is not guaranteed as object defined.</code></pre></div>\n</li>\n<li>\n<p>What is the main difference between Object.values and Object.entries method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.values() method's behavior is similar to Object.entries() method but it returns an array of values instead [key,value] pairs.\n\n```javascript\nconst object = {\n    a: 'Good morning',\n    b: 100\n};\n\nfor (let value of Object.values(object)) {\n    console.log(`${value}`); // 'Good morning'\n    100;\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How can you get the list of keys of any object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.keys()` method which is used to return an array of a given object's own property names, in the same order as we get with a normal loop. For example, you can get the keys of a user object,\n\n```javascript\nconst user = {\n    name: 'John',\n    gender: 'male',\n    age: 40\n};\n\nconsole.log(Object.keys(user)); //['name', 'gender', 'age']\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create an object with prototype</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.create() method is used to create a new object with the specified prototype object and properties. i.e, It uses an existing object as the prototype of the newly created object. It returns a new object with the specified prototype object and properties.\n\n```javascript\nconst user = {\n    name: 'John',\n    printInfo: function () {\n        console.log(`My name is ${this.name}.`);\n    }\n};\n\nconst admin = Object.create(user);\n\nadmin.name = 'Nick'; // Remember that \"name\" is a property set on \"admin\" but not on \"user\" object\n\nadmin.printInfo(); // My name is Nick\n```</code></pre></div>\n</li>\n<li>\n<p>What is a WeakSet</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">WeakSet is used to store a collection of weakly(weak references) held objects. The syntax would be as follows,\n\n```javascript\nnew WeakSet([iterable]);\n```\n\nLet's see the below example to explain it's behavior,\n\n```javascript\nvar ws = new WeakSet();\nvar user = {};\nws.add(user);\nws.has(user); // true\nws.delete(user); // removes user from the set\nws.has(user); // false, user has been removed\n```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between WeakSet and Set</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference is that references to objects in Set are strong while references to objects in WeakSet are weak. i.e, An object in WeakSet can be garbage collected if there is no other reference to it.\nOther differences are,\n\n1. Sets can store any value Whereas WeakSets can store only collections of objects\n2. WeakSet does not have size property unlike Set\n3. WeakSet does not have methods such as clear, keys, values, entries, forEach.\n4. WeakSet is not iterable.</code></pre></div>\n</li>\n<li>\n<p>List down the collection of methods available on WeakSet</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of methods available on WeakSet,\n\n1. add(value): A new object is appended with the given value to the weakset\n2. delete(value): Deletes the value from the WeakSet collection.\n3. has(value): It returns true if the value is present in the WeakSet Collection, otherwise it returns false.\n\nLet's see the functionality of all the above methods in an example,\n\n```javascript\nvar weakSetObject = new WeakSet();\nvar firstObject = {};\nvar secondObject = {};\n// add(value)\nweakSetObject.add(firstObject);\nweakSetObject.add(secondObject);\nconsole.log(weakSetObject.has(firstObject)); //true\nweakSetObject.delete(secondObject);\n```</code></pre></div>\n</li>\n<li>\n<p>What is a WeakMap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced. In this case, keys must be objects and the values can be arbitrary values. The syntax is looking like as below,\n\n```javascript\nnew WeakMap([iterable]);\n```\n\nLet's see the below example to explain it's behavior,\n\n```javascript\nvar ws = new WeakMap();\nvar user = {};\nws.set(user);\nws.has(user); // true\nws.delete(user); // removes user from the map\nws.has(user); // false, user has been removed\n```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between WeakMap and Map</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference is that references to key objects in Map are strong while references to key objects in WeakMap are weak. i.e, A key object in WeakMap can be garbage collected if there is no other reference to it.\nOther differences are,\n\n1. Maps can store any key type Whereas WeakMaps can store only collections of key objects\n2. WeakMap does not have size property unlike Map\n3. WeakMap does not have methods such as clear, keys, values, entries, forEach.\n4. WeakMap is not iterable.</code></pre></div>\n</li>\n<li>\n<p>List down the collection of methods available on WeakMap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of methods available on WeakMap,\n\n1. set(key, value): Sets the value for the key in the WeakMap object. Returns the WeakMap object.\n2. delete(key): Removes any value associated to the key.\n3. has(key): Returns a Boolean asserting whether a value has been associated to the key in the WeakMap object or not.\n4. get(key): Returns the value associated to the key, or undefined if there is none.\n   Let's see the functionality of all the above methods in an example,\n\n```javascript\nvar weakMapObject = new WeakMap();\nvar firstObject = {};\nvar secondObject = {};\n// set(key, value)\nweakMapObject.set(firstObject, 'John');\nweakMapObject.set(secondObject, 100);\nconsole.log(weakMapObject.has(firstObject)); //true\nconsole.log(weakMapObject.get(firstObject)); // John\nweakMapObject.delete(secondObject);\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of uneval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The uneval() is an inbuilt function which is used to create a string representation of the source code of an Object. It is a top-level function and is not associated with any object. Let's see the below example to know more about it's functionality,\n\n```javascript\nvar a = 1;\nuneval(a); // returns a String containing 1\nuneval(function user() {}); // returns \"(function user(){})\"\n```</code></pre></div>\n</li>\n<li>\n<p>How do you encode an URL</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The encodeURI() function is used to encode complete URI which has special characters except (, / ? : @ &amp; = + $ #) characters.\n\n```javascript\nvar uri = 'https://mozilla.org/?x=шеллы';\nvar encoded = encodeURI(uri);\nconsole.log(encoded); // https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B\n```</code></pre></div>\n</li>\n<li>\n<p>How do you decode an URL</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The decodeURI() function is used to decode a Uniform Resource Identifier (URI) previously created by encodeURI().\n\n```javascript\nvar uri = 'https://mozilla.org/?x=шеллы';\nvar encoded = encodeURI(uri);\nconsole.log(encoded); // https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B\ntry {\n    console.log(decodeURI(encoded)); // \"https://mozilla.org/?x=шеллы\"\n} catch (e) {\n    // catches a malformed URI\n    console.error(e);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you print the contents of web page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The window object provided a print() method which is used to print the contents of the current window. It opens a Print dialog box which lets you choose between various printing options. Let's see the usage of print method in an example,\n\n```html\n&lt;input type=\"button\" value=\"Print\" onclick=\"window.print()\" />\n```\n\n**Note:** In most browsers, it will block while the print dialog is open.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between uneval and eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `uneval` function returns the source of a given object; whereas the `eval` function does the opposite, by evaluating that source code in a different memory area. Let's see an example to clarify the difference,\n\n```javascript\nvar msg = uneval(function greeting() {\n    return 'Hello, Good morning';\n});\nvar greeting = eval(msg);\ngreeting(); // returns \"Hello, Good morning\"\n```</code></pre></div>\n</li>\n<li>\n<p>What is an anonymous function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An anonymous function is a function without a name! Anonymous functions are commonly assigned to a variable name or used as a callback function. The syntax would be as below,\n\n```javascript\nfunction (optionalParameters) {\n  //do something\n}\n\nconst myFunction = function(){ //Anonymous function assigned to a variable\n  //do something\n};\n\n[1, 2, 3].map(function(element){ //Anonymous function used as a callback function\n  //do something\n});\n```\n\nLet's see the above anonymous function in an example,\n\n```javascript\nvar x = function (a, b) {\n    return a * b;\n};\nvar z = x(5, 10);\nconsole.log(z); // 50\n```</code></pre></div>\n</li>\n<li>\n<p>What is the precedence order between local and global variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A local variable takes precedence over a global variable with the same name. Let's see this behavior in an example.\n\n```javascript\nvar msg = 'Good morning';\nfunction greeting() {\n    msg = 'Good Evening';\n    console.log(msg);\n}\ngreeting();\n```</code></pre></div>\n</li>\n<li>\n<p>What are javascript accessors</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ECMAScript 5 introduced javascript object accessors or computed properties through getters and setters. Getters uses the `get` keyword whereas Setters uses the `set` keyword.\n\n```javascript\nvar user = {\n  firstName: \"John\",\n  lastName : \"Abraham\",\n  language : \"en\",\n  get lang() {\n    return this.language;\n  }\n  set lang(lang) {\n  this.language = lang;\n  }\n};\nconsole.log(user.lang); // getter access lang as en\nuser.lang = 'fr';\nconsole.log(user.lang); // setter used to set lang as fr\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define property on Object constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Object.defineProperty() static method is used to define a new property directly on an object, or modify an existing property on an object, and returns the object. Let's see an example to know how to define property,\n\n```javascript\nconst newObject = {};\n\nObject.defineProperty(newObject, 'newProperty', {\n    value: 100,\n    writable: false\n});\n\nconsole.log(newObject.newProperty); // 100\n\nnewObject.newProperty = 200; // It throws an error in strict mode due to writable setting\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between get and defineProperty</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both have similar results until unless you use classes. If you use `get` the property will be defined on the prototype of the object whereas using `Object.defineProperty()` the property will be defined on the instance it is applied to.</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of Getters and Setters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of benefits of Getters and Setters,\n\n1. They provide simpler syntax\n2. They are used for defining computed properties, or accessors in JS.\n3. Useful to provide equivalence relation between properties and methods\n4. They can provide better data quality\n5. Useful for doing things behind the scenes with the encapsulated logic.</code></pre></div>\n</li>\n<li>\n<p>Can I add getters and setters using defineProperty method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, You can use the `Object.defineProperty()` method to add Getters and Setters. For example, the below counter object uses increment, decrement, add and subtract properties,\n\n```javascript\nvar obj = { counter: 0 };\n\n// Define getters\nObject.defineProperty(obj, 'increment', {\n    get: function () {\n        this.counter++;\n    }\n});\nObject.defineProperty(obj, 'decrement', {\n    get: function () {\n        this.counter--;\n    }\n});\n\n// Define setters\nObject.defineProperty(obj, 'add', {\n    set: function (value) {\n        this.counter += value;\n    }\n});\nObject.defineProperty(obj, 'subtract', {\n    set: function (value) {\n        this.counter -= value;\n    }\n});\n\nobj.add = 10;\nobj.subtract = 5;\nconsole.log(obj.increment); //6\nconsole.log(obj.decrement); //5\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of switch-case</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The switch case statement in JavaScript is used for decision making purposes. In a few cases, using the switch case statement is going to be more convenient than if-else statements. The syntax would be as below,\n\n```javascript\nswitch (expression)\n{\n    case value1:\n        statement1;\n        break;\n    case value2:\n        statement2;\n        break;\n    .\n    .\n    case valueN:\n        statementN;\n        break;\n    default:\n        statementDefault;\n}\n```\n\nThe above multi-way branch statement provides an easy way to dispatch execution to different parts of code based on the value of the expression.</code></pre></div>\n</li>\n<li>\n<p>What are the conventions to be followed for the usage of switch case</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of conventions should be taken care,\n\n1. The expression can be of type either number or string.\n2. Duplicate values are not allowed for the expression.\n3. The default statement is optional. If the expression passed to switch does not match with any case value then the statement within default case will be executed.\n4. The break statement is used inside the switch to terminate a statement sequence.\n5. The break statement is optional. But if it is omitted, the execution will continue on into the next case.</code></pre></div>\n</li>\n<li>\n<p>What are primitive data types</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A primitive data type is data that has a primitive value (which has no properties or methods). There are 7 types of primitive data types.\n\n1. string\n2. number\n3. boolean\n4. null\n5. undefined\n6. bigint\n7. symbol</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to access object properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are 3 possible ways for accessing the property of an object.\n\n1. **Dot notation:** It uses dot for accessing the properties\n\n```javascript\nobjectName.property;\n```\n\n1. **Square brackets notation:** It uses square brackets for property access\n\n```javascript\nobjectName['property'];\n```\n\n1. **Expression notation:** It uses expression in the square brackets\n\n```javascript\nobjectName[expression];\n```</code></pre></div>\n</li>\n<li>\n<p>What are the function parameter rules</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript functions follow below rules for parameters,\n\n1. The function definitions do not specify data types for parameters.\n2. Do not perform type checking on the passed arguments.\n3. Do not check the number of arguments received.\n   i.e, The below function follows the above rules,\n\n```javascript\nfunction functionName(parameter1, parameter2, parameter3) {\n    console.log(parameter1); // 1\n}\nfunctionName(1);\n```</code></pre></div>\n</li>\n<li>\n<p>What is an error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An error object is a built in error object that provides error information when an error occurs. It has two properties: name and message. For example, the below function logs error details,\n\n```javascript\ntry {\n    greeting('Welcome');\n} catch (err) {\n    console.log(err.name + '&lt;br>' + err.message);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>When you get a syntax error</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A SyntaxError is thrown if you try to evaluate code with a syntax error. For example, the below missing quote for the function parameter throws a syntax error\n\n```javascript\ntry {\n    eval(\"greeting('welcome)\"); // Missing ' will produce an error\n} catch (err) {\n    console.log(err.name);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different error names from error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are 6 different types of error names returned from error object,\n| Error Name | Description |\n|---- | ---------\n| EvalError | An error has occurred in the eval() function |\n| RangeError | An error has occurred with a number \"out of range\" |\n| ReferenceError | An error due to an illegal reference|\n| SyntaxError | An error due to a syntax error|\n| TypeError | An error due to a type error |\n| URIError | An error due to encodeURI() |</code></pre></div>\n</li>\n<li>\n<p>What are the various statements in error handling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of statements used in an error handling,\n\n1. **try:** This statement is used to test a block of code for errors\n2. **catch:** This statement is used to handle the error\n3. **throw:** This statement is used to create custom errors.\n4. **finally:** This statement is used to execute code after try and catch regardless of the result.</code></pre></div>\n</li>\n<li>\n<p>What are the two types of loops in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. **Entry Controlled loops:** In this kind of loop type, the test condition is tested before entering the loop body. For example, For Loop and While Loop comes under this category.\n2. **Exit Controlled Loops:** In this kind of loop type, the test condition is tested or evaluated at the end of the loop body. i.e, the loop body will execute at least once irrespective of test condition true or false. For example, do-while loop comes under this category.</code></pre></div>\n</li>\n<li>\n<p>What is nodejs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Node.js is a server-side platform built on Chrome's JavaScript runtime for easily building fast and scalable network applications. It is an event-based, non-blocking, asynchronous I/O runtime that uses Google's V8 JavaScript engine and libuv library.</code></pre></div>\n</li>\n<li>\n<p>What is an Intl object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. It provides access to several constructors and language sensitive functions.</code></pre></div>\n</li>\n<li>\n<p>How do you perform language specific date and time formatting</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Intl.DateTimeFormat` object which is a constructor for objects that enable language-sensitive date and time formatting. Let's see this behavior with an example,\n\n```javascript\nvar date = new Date(Date.UTC(2019, 07, 07, 3, 0, 0));\nconsole.log(new Intl.DateTimeFormat('en-GB').format(date)); // 07/08/2019\nconsole.log(new Intl.DateTimeFormat('en-AU').format(date)); // 07/08/2019\n```</code></pre></div>\n</li>\n<li>\n<p>What is an Iterator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An iterator is an object which defines a sequence and a return value upon its termination. It implements the Iterator protocol with a `next()` method which returns an object with two properties: `value` (the next value in the sequence) and `done` (which is true if the last value in the sequence has been consumed).</code></pre></div>\n</li>\n<li>\n<p>How does synchronous iteration works</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Synchronous iteration was introduced in ES6 and it works with below set of components,\n\n**Iterable:** It is an object which can be iterated over via a method whose key is Symbol.iterator.\n**Iterator:** It is an object returned by invoking `[Symbol.iterator]()` on an iterable. This iterator object wraps each iterated element in an object and returns it via `next()` method one by one.\n**IteratorResult:** It is an object returned by `next()` method. The object contains two properties; the `value` property contains an iterated element and the `done` property determines whether the element is the last element or not.\n\nLet's demonstrate synchronous iteration with an array as below,\n\n```javascript\nconst iterable = ['one', 'two', 'three'];\nconst iterator = iterable[Symbol.iterator]();\nconsole.log(iterator.next()); // { value: 'one', done: false }\nconsole.log(iterator.next()); // { value: 'two', done: false }\nconsole.log(iterator.next()); // { value: 'three', done: false }\nconsole.log(iterator.next()); // { value: 'undefined, done: true }\n```</code></pre></div>\n</li>\n<li>\n<p>What is an event loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Event Loop is a queue of callback functions. When an async function executes, the callback function is pushed into the queue. The JavaScript engine doesn't start processing the event loop until the async function has finished executing the code.\n**Note:** It allows Node.js to perform non-blocking I/O operations even though JavaScript is single-threaded.</code></pre></div>\n</li>\n<li>\n<p>What is call stack</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Call Stack is a data structure for javascript interpreters to keep track of function calls in the program. It has two major actions,\n\n1. Whenever you call a function for its execution, you are pushing it to the stack.\n2. Whenever the execution is completed, the function is popped out of the stack.\n\nLet's take an example and it's state representation in a diagram format\n\n```javascript\nfunction hungry() {\n    eatFruits();\n}\nfunction eatFruits() {\n    return \"I'm eating fruits\";\n}\n\n// Invoke the `hungry` function\nhungry();\n```\n\nThe above code processed in a call stack as below,\n\n1. Add the `hungry()` function to the call stack list and execute the code.\n2. Add the `eatFruits()` function to the call stack list and execute the code.\n3. Delete the `eatFruits()` function from our call stack list.\n4. Delete the `hungry()` function from the call stack list since there are no items anymore.\n\n![Screenshot](images/call-stack.png)</code></pre></div>\n</li>\n<li>What is an event queue</li>\n<li>\n<p>What is a decorator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A decorator is an expression that evaluates to a function and that takes the target, name, and decorator descriptor as arguments. Also, it optionally returns a decorator descriptor to install on the target object. Let's define admin decorator for user class at design time,\n\n```javascript\nfunction admin(isAdmin) {\n   return function(target) {\n       target.isAdmin = isAdmin;\n   }\n}\n\n@admin(true)\nclass User() {\n}\nconsole.log(User.isAdmin); //true\n\n @admin(false)\n class User() {\n }\n console.log(User.isAdmin); //false\n```</code></pre></div>\n</li>\n<li>\n<p>What are the properties of Intl object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of properties available on Intl object,\n\n1. **Collator:** These are the objects that enable language-sensitive string comparison.\n2. **DateTimeFormat:** These are the objects that enable language-sensitive date and time formatting.\n3. **ListFormat:** These are the objects that enable language-sensitive list formatting.\n4. **NumberFormat:** Objects that enable language-sensitive number formatting.\n5. **PluralRules:** Objects that enable plural-sensitive formatting and language-specific rules for plurals.\n6. **RelativeTimeFormat:** Objects that enable language-sensitive relative time formatting.</code></pre></div>\n</li>\n<li>\n<p>What is an Unary operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The unary(+) operator is used to convert a variable to a number.If the variable cannot be converted, it will still become a number but with the value NaN. Let's see this behavior in an action.\n\n```javascript\nvar x = '100';\nvar y = +x;\nconsole.log(typeof x, typeof y); // string, number\n\nvar a = 'Hello';\nvar b = +a;\nconsole.log(typeof a, typeof b, b); // string, number, NaN\n```</code></pre></div>\n</li>\n<li>\n<p>How do you sort elements in an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The sort() method is used to sort the elements of an array in place and returns the sorted array. The example usage would be as below,\n\n```javascript\nvar months = ['Aug', 'Sep', 'Jan', 'June'];\nmonths.sort();\nconsole.log(months); //  [\"Aug\", \"Jan\", \"June\", \"Sep\"]\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of compareFunction while sorting arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The compareFunction is used to define the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value. Let's take an example to see the usage of compareFunction,\n\n```javascript\nlet numbers = [1, 2, 5, 3, 4];\nnumbers.sort((a, b) => b - a);\nconsole.log(numbers); // [5, 4, 3, 2, 1]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you reversing an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the reverse() method to reverse the elements in an array. This method is useful to sort an array in descending order. Let's see the usage of reverse() method in an example,\n\n```javascript\nlet numbers = [1, 2, 5, 3, 4];\nnumbers.sort((a, b) => b - a);\nnumbers.reverse();\nconsole.log(numbers); // [1, 2, 3, 4 ,5]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you find min and max value in an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `Math.min` and `Math.max` methods on array variables to find the minimum and maximum elements within an array. Let's create two functions to find the min and max value with in an array,\n\n```javascript\nvar marks = [50, 20, 70, 60, 45, 30];\nfunction findMin(arr) {\n    return Math.min.apply(null, arr);\n}\nfunction findMax(arr) {\n    return Math.max.apply(null, arr);\n}\n\nconsole.log(findMin(marks));\nconsole.log(findMax(marks));\n```</code></pre></div>\n</li>\n<li>\n<p>How do you find min and max values without Math functions</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can write functions which loop through an array comparing each value with the lowest value or highest value to find the min and max values. Let's create those functions to find min and max values,\n\n```javascript\nvar marks = [50, 20, 70, 60, 45, 30];\nfunction findMin(arr) {\n    var length = arr.length;\n    var min = Infinity;\n    while (length--) {\n        if (arr[length] &lt; min) {\n            min = arr[len];\n        }\n    }\n    return min;\n}\n\nfunction findMax(arr) {\n    var length = arr.length;\n    var max = -Infinity;\n    while (len--) {\n        if (arr[length] > max) {\n            max = arr[length];\n        }\n    }\n    return max;\n}\n\nconsole.log(findMin(marks));\nconsole.log(findMax(marks));\n```</code></pre></div>\n</li>\n<li>\n<p>What is an empty statement and purpose of it</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The empty statement is a semicolon (;) indicating that no statement will be executed, even if JavaScript syntax requires one. Since there is no action with an empty statement you might think that it's usage is quite less, but the empty statement is occasionally useful when you want to create a loop that has an empty body. For example, you can initialize an array with zero values as below,\n\n```javascript\n// Initialize an array a\nfor(int i=0; i &lt; a.length; a[i++] = 0) ;\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get metadata of a module</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `import.meta` object which is a meta-property exposing context-specific meta data to a JavaScript module. It contains information about the current module, such as the module's URL. In browsers, you might get different meta data than NodeJS.\n\n     ```javascript\n     &lt;script type=\"module\" src=\"welcome-module.js\">\n\n&lt;/script>;\nconsole.log(import.meta); // { url: \"file:///home/user/welcome-module.js\" }\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a comma operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The comma operator is used to evaluate each of its operands from left to right and returns the value of the last operand. This is totally different from comma usage within arrays, objects, and function arguments and parameters. For example, the usage for numeric expressions would be as below,\n\n```javascript\nvar x = 1;\nx = (x++, x);\n\nconsole.log(x); // 2\n```</code></pre></div>\n</li>\n<li>\n<p>What is the advantage of a comma operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is normally used to include multiple expressions in a location that requires a single expression. One of the common usages of this comma operator is to supply multiple parameters in a `for` loop. For example, the below for loop uses multiple expressions in a single location using comma operator,\n\n```javascript\nfor (var a = 0, b =10; a &lt;= 10; a++, b--)\n```\n\nYou can also use the comma operator in a return statement where it processes before returning.\n\n```javascript\nfunction myFunction() {\n    var a = 1;\n    return (a += 10), a; // 11\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is typescript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">TypeScript is a typed superset of JavaScript created by Microsoft that adds optional types, classes, async/await, and many other features, and compiles to plain JavaScript. Angular built entirely in TypeScript and used as a primary language. You can install it globally as\n\n```shell\nnpm install -g typescript\n```\n\nLet's see a simple example of TypeScript usage,\n\n```typescript\nfunction greeting(name: string): string {\n    return 'Hello, ' + name;\n}\n\nlet user = 'Sudheer';\n\nconsole.log(greeting(user));\n```\n\nThe greeting method allows only string type as argument.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between javascript and typescript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of differences between javascript and typescript,\n\n| feature             | typescript                            | javascript                                      |\n| ------------------- | ------------------------------------- | ----------------------------------------------- |\n| Language paradigm   | Object oriented programming language  | Scripting language                              |\n| Typing support      | Supports static typing                | It has dynamic typing                           |\n| Modules             | Supported                             | Not supported                                   |\n| Interface           | It has interfaces concept             | Doesn't support interfaces                      |\n| Optional parameters | Functions support optional parameters | No support of optional parameters for functions |</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of typescript over javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are some of the advantages of typescript over javascript,\n\n1. TypeScript is able to find compile time errors at the development time only and it makes sures less runtime errors. Whereas javascript is an interpreted language.\n2. TypeScript is strongly-typed or supports static typing which allows for checking type correctness at compile time. This is not available in javascript.\n3. TypeScript compiler can compile the .ts files into ES3,ES4 and ES5 unlike ES6 features of javascript which may not be supported in some browsers.</code></pre></div>\n</li>\n<li>\n<p>What is an object initializer</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An object initializer is an expression that describes the initialization of an Object. The syntax for this expression is represented as a comma-delimited list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}). This is also known as literal notation. It is one of the ways to create an object.\n\n```javascript\nvar initObject = { a: 'John', b: 50, c: {} };\n\nconsole.log(initObject.a); // John\n```</code></pre></div>\n</li>\n<li>\n<p>What is a constructor method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The constructor method is a special method for creating and initializing an object created within a class. If you do not specify a constructor method, a default constructor is used. The example usage of constructor would be as below,\n\n```javascript\nclass Employee {\n    constructor() {\n        this.name = 'John';\n    }\n}\n\nvar employeeObject = new Employee();\n\nconsole.log(employeeObject.name); // John\n```</code></pre></div>\n</li>\n<li>\n<p>What happens if you write constructor more than once in a class</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The \"constructor\" in a class is a special method and it should be defined only once in a class. i.e, If you write a constructor method more than once in a class it will throw a `SyntaxError` error.\n\n```javascript\n class Employee {\n   constructor() {\n     this.name = \"John\";\n   }\n   constructor() {   //  Uncaught SyntaxError: A class may only have one constructor\n     this.age = 30;\n   }\n }\n\n var employeeObject = new Employee();\n\n console.log(employeeObject.name);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you call the constructor of a parent class</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `super` keyword to call the constructor of a parent class. Remember that `super()` must be called before using 'this' reference. Otherwise it will cause a reference error. Let's the usage of it,\n\n```javascript\nclass Square extends Rectangle {\n    constructor(length) {\n        super(length, length);\n        this.name = 'Square';\n    }\n\n    get area() {\n        return this.width * this.height;\n    }\n\n    set area(value) {\n        this.area = value;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get the prototype of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.getPrototypeOf(obj)` method to return the prototype of the specified object. i.e. The value of the internal `prototype` property. If there are no inherited properties then `null` value is returned.\n\n```javascript\nconst newPrototype = {};\nconst newObject = Object.create(newPrototype);\n\nconsole.log(Object.getPrototypeOf(newObject) === newPrototype); // true\n```</code></pre></div>\n</li>\n<li>\n<p>What happens If I pass string type for getPrototype method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In ES5, it will throw a TypeError exception if the obj parameter isn't an object. Whereas in ES2015, the parameter will be coerced to an `Object`.\n\n```javascript\n// ES5\nObject.getPrototypeOf('James'); // TypeError: \"James\" is not an object\n// ES2015\nObject.getPrototypeOf('James'); // String.prototype\n```</code></pre></div>\n</li>\n<li>\n<p>How do you set prototype of one object to another</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.setPrototypeOf()` method that sets the prototype (i.e., the internal `Prototype` property) of a specified object to another object or null. For example, if you want to set prototype of a square object to rectangle object would be as follows,\n\n```javascript\nObject.setPrototypeOf(Square.prototype, Rectangle.prototype);\nObject.setPrototypeOf({}, null);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether an object can be extendable or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `Object.isExtensible()` method is used to determine if an object is extendable or not. i.e, Whether it can have new properties added to it or not.\n\n```javascript\nconst newObject = {};\nconsole.log(Object.isExtensible(newObject)); //true\n```\n\n**Note:** By default, all the objects are extendable. i.e, The new properties can be added or modified.</code></pre></div>\n</li>\n<li>\n<p>How do you prevent an object to extend</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `Object.preventExtensions()` method is used to prevent new properties from ever being added to an object. In other words, it prevents future extensions to the object. Let's see the usage of this property,\n\n```javascript\nconst newObject = {};\nObject.preventExtensions(newObject); // NOT extendable\n\ntry {\n    Object.defineProperty(newObject, 'newProperty', {\n        // Adding new property\n        value: 100\n    });\n} catch (e) {\n    console.log(e); // TypeError: Cannot define property newProperty, object is not extensible\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to make an object non-extensible</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can mark an object non-extensible in 3 ways,\n\n1. Object.preventExtensions\n2. Object.seal\n3. Object.freeze\n\n```javascript\nvar newObject = {};\n\nObject.preventExtensions(newObject); // Prevent objects are non-extensible\nObject.isExtensible(newObject); // false\n\nvar sealedObject = Object.seal({}); // Sealed objects are non-extensible\nObject.isExtensible(sealedObject); // false\n\nvar frozenObject = Object.freeze({}); // Frozen objects are non-extensible\nObject.isExtensible(frozenObject); // false\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define multiple properties on an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `Object.defineProperties()` method is used to define new or modify existing properties directly on an object and returning the object. Let's define multiple properties on an empty object,\n\n```javascript\nconst newObject = {};\n\nObject.defineProperties(newObject, {\n    newProperty1: {\n        value: 'John',\n        writable: true\n    },\n    newProperty2: {}\n});\n```</code></pre></div>\n</li>\n<li>\n<p>What is MEAN in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The MEAN (MongoDB, Express, AngularJS, and Node.js) stack is the most popular open-source JavaScript software tech stack available for building dynamic web apps where you can write both the server-side and client-side halves of the web project entirely in JavaScript.</code></pre></div>\n</li>\n<li>\n<p>What Is Obfuscation in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Obfuscation is the deliberate act of creating obfuscated javascript code(i.e, source or machine code) that is difficult for humans to understand. It is something similar to encryption, but a machine can understand the code and execute it.\nLet's see the below function before Obfuscation,\n\n```javascript\nfunction greeting() {\n    console.log('Hello, welcome to JS world');\n}\n```\n\nAnd after the code Obfuscation, it would be appeared as below,\n\n```javascript\neval(\n    (function (p, a, c, k, e, d) {\n        e = function (c) {\n            return c;\n        };\n        if (!''.replace(/^/, String)) {\n            while (c--) {\n                d[c] = k[c] || c;\n            }\n            k = [\n                function (e) {\n                    return d[e];\n                }\n            ];\n            e = function () {\n                return '\\\\w+';\n            };\n            c = 1;\n        }\n        while (c--) {\n            if (k[c]) {\n                p = p.replace(new RegExp('\\\\b' + e(c) + '\\\\b', 'g'), k[c]);\n            }\n        }\n        return p;\n    })(\"2 1(){0.3('4, 7 6 5 8')}\", 9, 9, 'console|greeting|function|log|Hello|JS|to|welcome|world'.split('|'), 0, {})\n);\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need Obfuscation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the few reasons for Obfuscation,\n\n1. The Code size will be reduced. So data transfers between server and client will be fast.\n2. It hides the business logic from outside world and protects the code from others\n3. Reverse engineering is highly difficult\n4. The download time will be reduced</code></pre></div>\n</li>\n<li>\n<p>What is Minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Minification is the process of removing all unnecessary characters(empty spaces are removed) and variables will be renamed without changing it's functionality. It is also a type of obfuscation .</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Normally it is recommended to use minification for heavy traffic and intensive requirements of resources. It reduces file sizes with below benefits,\n\n1. Decreases loading times of a web page\n2. Saves bandwidth usages</code></pre></div>\n</li>\n<li>\n<p>What are the differences between Obfuscation and Encryption</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main differences between Obfuscation and Encryption,\n\n| Feature            | Obfuscation                                     | Encryption                                                              |\n| ------------------ | ----------------------------------------------- | ----------------------------------------------------------------------- |\n| Definition         | Changing the form of any data in any other form | Changing the form of information to an unreadable format by using a key |\n| A key to decode    | It can be decoded without any key               | It is required                                                          |\n| Target data format | It will be converted to a complex form          | Converted into an unreadable format                                     |</code></pre></div>\n</li>\n<li>\n<p>What are the common tools used for minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are many online/offline tools to minify the javascript files,\n\n1. Google's Closure Compiler\n2. UglifyJS2\n3. jsmin\n4. javascript-minifier.com/\n5. prettydiff.com</code></pre></div>\n</li>\n<li>\n<p>How do you perform form validation using javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript can be used to perform HTML form validation. For example, if the form field is empty, the function needs to notify, and return false, to prevent the form being submitted.\nLets' perform user login in an html form,\n\n```html\n&lt;form name=\"myForm\" onsubmit=\"return validateForm()\" method=\"post\">\n    User name: &lt;input type=\"text\" name=\"uname\" />\n    &lt;input type=\"submit\" value=\"Submit\" />\n&lt;/form>\n```\n\nAnd the validation on user login is below,\n\n```javascript\nfunction validateForm() {\n    var x = document.forms['myForm']['uname'].value;\n    if (x == '') {\n        alert(\"The username shouldn't be empty\");\n        return false;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you perform form validation without javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can perform HTML form validation automatically without using javascript. The validation enabled by applying the `required` attribute to prevent form submission when the input is empty.\n\n```html\n&lt;form method=\"post\">\n    &lt;input type=\"text\" name=\"uname\" required />\n    &lt;input type=\"submit\" value=\"Submit\" />\n&lt;/form>\n```\n\n**Note:** Automatic form validation does not work in Internet Explorer 9 or earlier.</code></pre></div>\n</li>\n<li>\n<p>What are the DOM methods available for constraint validation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The below DOM methods are available for constraint validation on an invalid input,\n\n1. checkValidity(): It returns true if an input element contains valid data.\n2. setCustomValidity(): It is used to set the validationMessage property of an input element.\n   Let's take an user login form with DOM validations\n\n```javascript\nfunction myFunction() {\n    var userName = document.getElementById('uname');\n    if (!userName.checkValidity()) {\n        document.getElementById('message').innerHTML = userName.validationMessage;\n    } else {\n        document.getElementById('message').innerHTML = 'Entered a valid username';\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the available constraint validation DOM properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of some of the constraint validation DOM properties available,\n\n1. validity: It provides a list of boolean properties related to the validity of an input element.\n2. validationMessage: It displays the message when the validity is false.\n3. willValidate: It indicates if an input element will be validated or not.</code></pre></div>\n</li>\n<li>\n<p>What are the list of validity properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The validity property of an input element provides a set of properties related to the validity of data.\n\n1. customError: It returns true, if a custom validity message is set.\n2. patternMismatch: It returns true, if an element's value does not match its pattern attribute.\n3. rangeOverflow: It returns true, if an element's value is greater than its max attribute.\n4. rangeUnderflow: It returns true, if an element's value is less than its min attribute.\n5. stepMismatch: It returns true, if an element's value is invalid according to step attribute.\n6. tooLong: It returns true, if an element's value exceeds its maxLength attribute.\n7. typeMismatch: It returns true, if an element's value is invalid according to type attribute.\n8. valueMissing: It returns true, if an element with a required attribute has no value.\n9. valid: It returns true, if an element's value is valid.</code></pre></div>\n</li>\n<li>\n<p>Give an example usage of rangeOverflow property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If an element's value is greater than its max attribute then rangeOverflow property returns true. For example, the below form submission throws an error if the value is more than 100,\n\n```html\n&lt;input id=\"age\" type=\"number\" max=\"100\" /> &lt;button onclick=\"myOverflowFunction()\">OK&lt;/button>\n```\n\n```javascript\nfunction myOverflowFunction() {\n    if (document.getElementById('age').validity.rangeOverflow) {\n        alert('The mentioned age is not allowed');\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>Is enums feature available in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, javascript does not natively support enums. But there are different kinds of solutions to simulate them even though they may not provide exact equivalents. For example, you can use freeze or seal on object,\n\n```javascript\nvar DaysEnum = Object.freeze({\"monday\":1, \"tuesday\":2, \"wednesday\":3, ...})\n```</code></pre></div>\n</li>\n<li>\n<p>What is an enum</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An enum is a type restricting variables to one value from a predefined set of constants. JavaScript has no enums but typescript provides built-in enum support.\n\n```javascript\nenum Color {\n RED, GREEN, BLUE\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you list all properties of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.getOwnPropertyNames()` method which returns an array of all properties found directly in a given object. Let's the usage of it in an example,\n\n```javascript\nconst newObject = {\n    a: 1,\n    b: 2,\n    c: 3\n};\n\nconsole.log(Object.getOwnPropertyNames(newObject));\n['a', 'b', 'c'];\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get property descriptors of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Object.getOwnPropertyDescriptors()` method which returns all own property descriptors of a given object. The example usage of this method is below,\n\n```javascript\nconst newObject = {\n    a: 1,\n    b: 2,\n    c: 3\n};\nconst descriptorsObject = Object.getOwnPropertyDescriptors(newObject);\nconsole.log(descriptorsObject.a.writable); //true\nconsole.log(descriptorsObject.a.configurable); //true\nconsole.log(descriptorsObject.a.enumerable); //true\nconsole.log(descriptorsObject.a.value); // 1\n```</code></pre></div>\n</li>\n<li>\n<p>What are the attributes provided by a property descriptor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A property descriptor is a record which has the following attributes\n\n1. value: The value associated with the property\n2. writable: Determines whether the value associated with the property can be changed or not\n3. configurable: Returns true if the type of this property descriptor can be changed and if the property can be deleted from the corresponding object.\n4. enumerable: Determines whether the property appears during enumeration of the properties on the corresponding object or not.\n5. set: A function which serves as a setter for the property\n6. get: A function which serves as a getter for the property</code></pre></div>\n</li>\n<li>\n<p>How do you extend classes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `extends` keyword is used in class declarations/expressions to create a class which is a child of another class. It can be used to subclass custom classes as well as built-in objects. The syntax would be as below,\n\n```javascript\nclass ChildClass extends ParentClass { ... }\n```\n\nLet's take an example of Square subclass from Polygon parent class,\n\n```javascript\nclass Square extends Rectangle {\n    constructor(length) {\n        super(length, length);\n        this.name = 'Square';\n    }\n\n    get area() {\n        return this.width * this.height;\n    }\n\n    set area(value) {\n        this.area = value;\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do I modify the url without reloading the page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `window.location.url` property will be helpful to modify the url but it reloads the page. HTML5 introduced the `history.pushState()` and `history.replaceState()` methods, which allow you to add and modify history entries, respectively. For example, you can use pushState as below,\n\n```javascript\nwindow.history.pushState('page2', 'Title', '/page2.html');\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether an array includes a particular value or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `Array#includes()` method is used to determine whether an array includes a particular value among its entries by returning either true or false. Let's see an example to find an element(numeric and string) within an array.\n\n```javascript\nvar numericArray = [1, 2, 3, 4];\nconsole.log(numericArray.includes(3)); // true\n\nvar stringArray = ['green', 'yellow', 'blue'];\nconsole.log(stringArray.includes('blue')); //true\n```</code></pre></div>\n</li>\n<li>\n<p>How do you compare scalar arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use length and every method of arrays to compare two scalar(compared directly using ===) arrays. The combination of these expressions can give the expected result,\n\n```javascript\nconst arrayFirst = [1, 2, 3, 4, 5];\nconst arraySecond = [1, 2, 3, 4, 5];\nconsole.log(arrayFirst.length === arraySecond.length &amp;&amp; arrayFirst.every((value, index) => value === arraySecond[index])); // true\n```\n\nIf you would like to compare arrays irrespective of order then you should sort them before,\n\n```javascript\nconst arrayFirst = [2, 3, 1, 4, 5];\nconst arraySecond = [1, 2, 3, 4, 5];\nconsole.log(arrayFirst.length === arraySecond.length &amp;&amp; arrayFirst.sort().every((value, index) => value === arraySecond[index])); //true\n```</code></pre></div>\n</li>\n<li>\n<p>How to get the value from get parameters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `new URL()` object accepts the url string and `searchParams` property of this object can be used to access the get parameters. Remember that you may need to use polyfill or `window.location` to access the URL in older browsers(including IE).\n\n```javascript\nlet urlString = 'http://www.some-domain.com/about.html?x=1&amp;y=2&amp;z=3'; //window.location.href\nlet url = new URL(urlString);\nlet parameterZ = url.searchParams.get('z');\nconsole.log(parameterZ); // 3\n```</code></pre></div>\n</li>\n<li>\n<p>How do you print numbers with commas as thousand separators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `Number.prototype.toLocaleString()` method which returns a string with a language-sensitive representation such as thousand separator,currency etc of this number.\n\n```javascript\nfunction convertToThousandFormat(x) {\n    return x.toLocaleString(); // 12,345.679\n}\n\nconsole.log(convertToThousandFormat(12345.6789));\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between java and javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both are totally unrelated programming languages and no relation between them. Java is statically typed, compiled, runs on its own VM. Whereas Javascript is dynamically typed, interpreted, and runs in a browser and nodejs environments. Let's see the major differences in a tabular format,\n| Feature | Java | JavaScript |\n|---- | ---- | -----\n| Typed | It's a strongly typed language | It's a dynamic typed language |\n| Paradigm | Object oriented programming | Prototype based programming |\n| Scoping | Block scoped | Function-scoped |\n| Concurrency | Thread based | event based |\n| Memory | Uses more memory | Uses less memory. Hence it will be used for web pages |</code></pre></div>\n</li>\n<li>\n<p>Does JavaScript supports namespace</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript doesn't support namespace by default. So if you create any element(function, method, object, variable) then it becomes global and pollutes the global namespace. Let's take an example of defining two functions without any namespace,\n\n```javascript\nfunction func1() {\n    console.log('This is a first definition');\n}\nfunction func1() {\n    console.log('This is a second definition');\n}\nfunc1(); // This is a second definition\n```\n\nIt always calls the second function definition. In this case, namespace will solve the name collision problem.</code></pre></div>\n</li>\n<li>\n<p>How do you declare namespace</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Even though JavaScript lacks namespaces, we can use Objects , IIFE to create namespaces.\n\n1. **Using Object Literal Notation:** Let's wrap variables and functions inside an Object literal which acts as a namespace. After that you can access them using object notation\n\n```javascript\nvar namespaceOne = {\n   function func1() {\n       console.log(\"This is a first definition\");\n   }\n}\nvar namespaceTwo = {\n     function func1() {\n         console.log(\"This is a second definition\");\n     }\n }\nnamespaceOne.func1(); // This is a first definition\nnamespaceTwo.func1(); // This is a second definition\n```\n\n1. **Using IIFE (Immediately invoked function expression):** The outer pair of parentheses of IIFE creates a local scope for all the code inside of it and makes the anonymous function a function expression. Due to that, you can create the same function in two different function expressions to act as a namespace.\n\n```javascript\n(function () {\n    function fun1() {\n        console.log('This is a first definition');\n    }\n    fun1();\n})();\n\n(function () {\n    function fun1() {\n        console.log('This is a second definition');\n    }\n    fun1();\n})();\n```\n\n1. **Using a block and a let/const declaration:** In ECMAScript 6, you can simply use a block and a let declaration to restrict the scope of a variable to a block.\n\n```javascript\n{\n    let myFunction = function fun1() {\n        console.log('This is a first definition');\n    };\n    myFunction();\n}\n//myFunction(): ReferenceError: myFunction is not defined.\n\n{\n    let myFunction = function fun1() {\n        console.log('This is a second definition');\n    };\n    myFunction();\n}\n//myFunction(): ReferenceError: myFunction is not defined.\n```</code></pre></div>\n</li>\n<li>\n<p>How do you invoke javascript code in an iframe from parent page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Initially iFrame needs to be accessed using either `document.getElementBy` or `window.frames`. After that `contentWindow` property of iFrame gives the access for targetFunction\n\n```javascript\ndocument.getElementById('targetFrame').contentWindow.targetFunction();\nwindow.frames[0].frameElement.contentWindow.targetFunction(); // Accessing iframe this way may not work in latest versions chrome and firefox\n```</code></pre></div>\n</li>\n<li>\n<p>How do get the timezone offset from date</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `getTimezoneOffset` method of the date object. This method returns the time zone difference, in minutes, from current locale (host system settings) to UTC\n\n```javascript\nvar offset = new Date().getTimezoneOffset();\nconsole.log(offset); // -480\n```</code></pre></div>\n</li>\n<li>\n<p>How do you load CSS and JS files dynamically</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can create both link and script elements in the DOM and append them as child to head tag. Let's create a function to add script and style resources as below,\n\n```javascript\nfunction loadAssets(filename, filetype) {\n    if (filetype == 'css') {\n        // External CSS file\n        var fileReference = document.createElement('link');\n        fileReference.setAttribute('rel', 'stylesheet');\n        fileReference.setAttribute('type', 'text/css');\n        fileReference.setAttribute('href', filename);\n    } else if (filetype == 'js') {\n        // External JavaScript file\n        var fileReference = document.createElement('script');\n        fileReference.setAttribute('type', 'text/javascript');\n        fileReference.setAttribute('src', filename);\n    }\n    if (typeof fileReference != 'undefined') document.getElementsByTagName('head')[0].appendChild(fileReference);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different methods to find HTML elements in DOM</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you want to access any element in an HTML page, you need to start with accessing the document object. Later you can use any of the below methods to find the HTML element,\n\n1. document.getElementById(id): It finds an element by Id\n2. document.getElementsByTagName(name): It finds an element by tag name\n3. document.getElementsByClassName(name): It finds an element by class name</code></pre></div>\n</li>\n<li>\n<p>What is jQuery</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">jQuery is a popular cross-browser JavaScript library that provides Document Object Model (DOM) traversal, event handling, animations and AJAX interactions by minimizing the discrepancies across browsers. It is widely famous with its philosophy of \"Write less, do more\". For example, you can display welcome message on the page load using jQuery as below,\n\n```javascript\n$(document).ready(function () {\n    // It selects the document and apply the function on page load\n    alert('Welcome to jQuery world');\n});\n```\n\n**Note:** You can download it from jquery's official site or install it from CDNs, like google.</code></pre></div>\n</li>\n<li>\n<p>What is V8 JavaScript engine</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">V8 is an open source high-performance JavaScript engine used by the Google Chrome browser, written in C++. It is also being used in the node.js project. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors.\n**Note:** It can run standalone, or can be embedded into any C++ application.</code></pre></div>\n</li>\n<li>\n<p>Why do we call javascript as dynamic language</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a loosely typed or a dynamic language because variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned/reassigned with values of all types.\n\n```javascript\nlet age = 50; // age is a number now\nage = 'old'; // age is a string now\nage = true; // age is a boolean\n```</code></pre></div>\n</li>\n<li>\n<p>What is a void operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `void` operator evaluates the given expression and then returns undefined(i.e, without returning value). The syntax would be as below,\n\n```javascript\nvoid expression;\nvoid expression;\n```\n\nLet's display a message without any redirection or reload\n\n```javascript\n&lt;a href=\"javascript:void(alert('Welcome to JS world'))\">Click here to see a message&lt;/a>\n```\n\n**Note:** This operator is often used to obtain the undefined primitive value, using \"void(0)\".</code></pre></div>\n</li>\n<li>\n<p>How to set the cursor to wait</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The cursor can be set to wait in JavaScript by using the property \"cursor\". Let's perform this behavior on page load using the below function.\n\n     ```javascript\n     function myFunction() {\n         window.document.body.style.cursor = 'wait';\n     }\n     ```\n\n     and this function invoked on page load\n\n     ```html\n     &lt;body onload=\"myFunction()\">\n\n&lt;/body>\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you create an infinite loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can create infinite loops using for and while loops without using any expressions. The for loop construct or syntax is better approach in terms of ESLint and code optimizer tools,\n\n```javascript\nfor (;;) {}\nwhile (true) {}\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need to avoid with statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript's with statement was intended to provide a shorthand for writing recurring accesses to objects. So it can help reduce file size by reducing the need to repeat a lengthy object reference without performance penalty. Let's take an example where it is used to avoid redundancy when accessing an object several times.\n\n```javascript\na.b.c.greeting = 'welcome';\na.b.c.age = 32;\n```\n\nUsing `with` it turns this into:\n\n```javascript\nwith (a.b.c) {\n    greeting = 'welcome';\n    age = 32;\n}\n```\n\nBut this `with` statement creates performance problems since one cannot predict whether an argument will refer to a real variable or to a property inside the with argument.</code></pre></div>\n</li>\n<li>\n<p>What is the output of below for loops</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">```javascript\nfor (var i = 0; i &lt; 4; i++) {\n    // global scope\n    setTimeout(() => console.log(i));\n}\n\nfor (let i = 0; i &lt; 4; i++) {\n    // block scope\n    setTimeout(() => console.log(i));\n}\n```\n\nThe output of the above for loops is 4 4 4 4 and 0 1 2 3\n\n**Explanation:** Due to the event queue/loop of javascript, the `setTimeout` callback function is called after the loop has been executed. Since the variable i is declared with the `var` keyword it became a global variable and the value was equal to 4 using iteration when the time `setTimeout` function is invoked. Hence, the output of the first loop is `4 4 4 4`.\n\nWhereas in the second loop, the variable i is declared as the `let` keyword it becomes a block scoped variable and it holds a new value(0, 1 ,2 3) for each iteration. Hence, the output of the first loop is `0 1 2 3`.</code></pre></div>\n</li>\n<li>\n<p>List down some of the features of ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of some new features of ES6,\n\n1. Support for constants or immutable variables\n2. Block-scope support for variables, constants and functions\n3. Arrow functions\n4. Default parameters\n5. Rest and Spread Parameters\n6. Template Literals\n7. Multi-line Strings\n8. Destructuring Assignment\n9. Enhanced Object Literals\n10. Promises\n11. Classes\n12. Modules</code></pre></div>\n</li>\n<li>\n<p>What is ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ES6 is the sixth edition of the javascript language and it was released in June 2015. It was initially known as ECMAScript 6 (ES6) and later renamed to ECMAScript 2015. Almost all the modern browsers support ES6 but for the old browsers there are many transpilers, like Babel.js etc.</code></pre></div>\n</li>\n<li>\n<p>Can I redeclare let and const variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, you cannot redeclare let and const variables. If you do, it throws below error\n\n```shell\nUncaught SyntaxError: Identifier 'someVariable' has already been declared\n```\n\n**Explanation:** The variable declaration with `var` keyword refers to a function scope and the variable is treated as if it were declared at the top of the enclosing scope due to hoisting feature. So all the multiple declarations contributing to the same hoisted variable without any error. Let's take an example of re-declaring variables in the same scope for both var and let/const variables.\n\n```javascript\nvar name = 'John';\nfunction myFunc() {\n    var name = 'Nick';\n    var name = 'Abraham'; // Re-assigned in the same function block\n    alert(name); // Abraham\n}\nmyFunc();\nalert(name); // John\n```\n\nThe block-scoped multi-declaration throws syntax error,\n\n```javascript\nlet name = 'John';\nfunction myFunc() {\n    let name = 'Nick';\n    let name = 'Abraham'; // Uncaught SyntaxError: Identifier 'name' has already been declared\n    alert(name);\n}\n\nmyFunc();\nalert(name);\n```</code></pre></div>\n</li>\n<li>\n<p>Is const variable makes the value immutable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, the const variable doesn't make the value immutable. But it disallows subsequent assignments(i.e, You can declare with assignment but can't assign another value later)\n\n```javascript\nconst userList = [];\nuserList.push('John'); // Can mutate even though it can't re-assign\nconsole.log(userList); // ['John']\n```</code></pre></div>\n</li>\n<li>\n<p>What are default parameters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In E5, we need to depend on logical OR operators to handle default values of function parameters. Whereas in ES6, Default function parameters feature allows parameters to be initialized with default values if no value or undefined is passed. Let's compare the behavior with an examples,\n\n```javascript\n//ES5\nvar calculateArea = function (height, width) {\n    height = height || 50;\n    width = width || 60;\n\n    return width * height;\n};\nconsole.log(calculateArea()); //300\n```\n\nThe default parameters makes the initialization more simpler,\n\n```javascript\n//ES6\nvar calculateArea = function (height = 50, width = 60) {\n    return width * height;\n};\n\nconsole.log(calculateArea()); //300\n```</code></pre></div>\n</li>\n<li>\n<p>What are template literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Template literals or template strings are string literals allowing embedded expressions. These are enclosed by the back-tick (`) character instead of double or single quotes.\nIn E6, this feature enables using dynamic expressions as below,\n\n```javascript\nvar greeting = `Welcome to JS World, Mr. ${firstName} ${lastName}.`;\n```\n\nIn ES5, you need break string like below,\n\n```javascript\nvar greeting = 'Welcome to JS World, Mr. ' + firstName + ' ' + lastName.`\n```\n\n**Note:** You can use multi-line strings and string interpolation features with template literals.</code></pre></div>\n</li>\n<li>\n<p>How do you write multi-line strings in template literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In ES5, you would have to use newline escape characters('\\\\n') and concatenation symbols(+) in order to get multi-line strings.\n\n```javascript\nconsole.log('This is string sentence 1\\n' + 'This is string sentence 2');\n```\n\nWhereas in ES6, You don't need to mention any newline sequence character,\n\n```javascript\nconsole.log(`This is string sentence\n'This is string sentence 2`);\n```</code></pre></div>\n</li>\n<li>\n<p>What are nesting templates</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The nesting template is a feature supported within template literals syntax to allow inner backticks inside a placeholder ${ } within the template. For example, the below nesting template is used to display the icons based on user permissions whereas outer template checks for platform type,\n\n```javascript\nconst iconStyles = `icon ${isMobilePlatform() ? '' : `icon-${user.isAuthorized ? 'submit' : 'disabled'}`}`;\n```\n\nYou can write the above use case without nesting template features as well. However, the nesting template feature is more compact and readable.\n\n```javascript\n//Without nesting templates\n const iconStyles = `icon ${ isMobilePlatform() ? '' :\n  (user.isAuthorized ? 'icon-submit' : 'icon-disabled'}`;\n```</code></pre></div>\n</li>\n<li>\n<p>What are tagged templates</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tagged templates are the advanced form of templates in which tags allow you to parse template literals with a function. The tag function accepts the first parameter as an array of strings and remaining parameters as expressions. This function can also return manipulated strings based on parameters. Let's see the usage of this tagged template behavior of an IT professional skill set in an organization,\n\n```javascript\nvar user1 = 'John';\nvar skill1 = 'JavaScript';\nvar experience1 = 15;\n\nvar user2 = 'Kane';\nvar skill2 = 'JavaScript';\nvar experience2 = 5;\n\nfunction myInfoTag(strings, userExp, experienceExp, skillExp) {\n  var str0 = strings[0]; // \"Mr/Ms. \"\n  var str1 = strings[1]; // \" is a/an \"\n  var str2 = strings[2]; // \"in\"\n\n  var expertiseStr;\n  if (experienceExp > 10){\n    expertiseStr = 'expert developer';\n  } else if(skillExp > 5 &amp;&amp; skillExp &lt;= 10) {\n    expertiseStr = 'senior developer';\n  } else {\n    expertiseStr = 'junior developer';\n  }\n\n  return ${str0}${userExp}${str1}${expertiseStr}${str2}${skillExp};\n}\n\nvar output1 = myInfoTag`Mr/Ms. ${ user1 } is a/an ${ experience1 } in ${skill1}`;\nvar output2 = myInfoTag`Mr/Ms. ${ user2 } is a/an ${ experience2 } in ${skill2}`;\n\nconsole.log(output1);// Mr/Ms. John is a/an expert developer in JavaScript\nconsole.log(output2);// Mr/Ms. Kane is a/an junior developer in JavaScript\n```</code></pre></div>\n</li>\n<li>\n<p>What are raw strings</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ES6 provides a raw strings feature using the `String.raw()` method which is used to get the raw string form of template strings. This feature allows you to access the raw strings as they were entered, without processing escape sequences. For example, the usage would be as below,\n\n```javascript\nvar calculationString = String.raw`The sum of numbers is \\n${1 + 2 + 3 + 4}!`;\nconsole.log(calculationString); // The sum of numbers is 10\n```\n\nIf you don't use raw strings, the newline character sequence will be processed by displaying the output in multiple lines\n\n```javascript\nvar calculationString = `The sum of numbers is \\n${1 + 2 + 3 + 4}!`;\nconsole.log(calculationString);\n// The sum of numbers is\n// 10\n```\n\nAlso, the raw property is available on the first argument to the tag function\n\n```javascript\nfunction tag(strings) {\n    console.log(strings.raw[0]);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The destructuring assignment is a JavaScript expression that makes it possible to unpack values from arrays or properties from objects into distinct variables.\nLet's get the month values from an array using destructuring assignment\n\n```javascript\nvar [one, two, three] = ['JAN', 'FEB', 'MARCH'];\n\nconsole.log(one); // \"JAN\"\nconsole.log(two); // \"FEB\"\nconsole.log(three); // \"MARCH\"\n```\n\nand you can get user properties of an object using destructuring assignment,\n\n```javascript\nvar { name, age } = { name: 'John', age: 32 };\n\nconsole.log(name); // John\nconsole.log(age); // 32\n```</code></pre></div>\n</li>\n<li>\n<p>What are default values in destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A variable can be assigned a default value when the value unpacked from the array or object is undefined during destructuring assignment. It helps to avoid setting default values separately for each assignment. Let's take an example for both arrays and object use cases,\n\n**Arrays destructuring:**\n\n```javascript\nvar x, y, z;\n\n[x = 2, y = 4, z = 6] = [10];\nconsole.log(x); // 10\nconsole.log(y); // 4\nconsole.log(z); // 6\n```\n\n**Objects destructuring:**\n\n```javascript\nvar { x = 2, y = 4, z = 6 } = { x: 10 };\n\nconsole.log(x); // 10\nconsole.log(y); // 4\nconsole.log(z); // 6\n```</code></pre></div>\n</li>\n<li>\n<p>How do you swap variables in destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you don't use destructuring assignment, swapping two values requires a temporary variable. Whereas using a destructuring feature, two variable values can be swapped in one destructuring expression. Let's swap two number variables in array destructuring assignment,\n\n```javascript\nvar x = 10,\n    y = 20;\n\n[x, y] = [y, x];\nconsole.log(x); // 20\nconsole.log(y); // 10\n```</code></pre></div>\n</li>\n<li>\n<p>What are enhanced object literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Object literals make it easy to quickly create objects with properties inside the curly braces. For example, it provides shorter syntax for common object property definition as below.\n\n```javascript\n//ES6\nvar x = 10,\n    y = 20;\nobj = { x, y };\nconsole.log(obj); // {x: 10, y:20}\n//ES5\nvar x = 10,\n    y = 20;\nobj = { x: x, y: y };\nconsole.log(obj); // {x: 10, y:20}\n```</code></pre></div>\n</li>\n<li>\n<p>What are dynamic imports</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The dynamic imports using `import()` function syntax allows us to load modules on demand by using promises or the async/await syntax. Currently this feature is in [stage4 proposal](https://github.com/tc39/proposal-dynamic-import). The main advantage of dynamic imports is reduction of our bundle's sizes, the size/payload response of our requests and overall improvements in the user experience.\nThe syntax of dynamic imports would be as below,\n\n```javascript\nimport('./Module').then((Module) => Module.method());\n```</code></pre></div>\n</li>\n<li>\n<p>What are the use cases for dynamic imports</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are some of the use cases of using dynamic imports over static imports,\n\n1. Import a module on-demand or conditionally. For example, if you want to load a polyfill on legacy browser\n\n```javascript\nif (isLegacyBrowser()) {\n    import(···)\n    .then(···);\n}\n```\n\n1. Compute the module specifier at runtime. For example, you can use it for internationalization.\n\n```javascript\nimport(`messages_${getLocale()}.js`).then(···);\n```\n\n1. Import a module from within a regular script instead a module.</code></pre></div>\n</li>\n<li>\n<p>What are typed arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Typed arrays are array-like objects from ECMAScript 6 API for handling binary data. JavaScript provides 8 Typed array types,\n\n1. Int8Array: An array of 8-bit signed integers\n2. Int16Array: An array of 16-bit signed integers\n3. Int32Array: An array of 32-bit signed integers\n4. Uint8Array: An array of 8-bit unsigned integers\n5. Uint16Array: An array of 16-bit unsigned integers\n6. Uint32Array: An array of 32-bit unsigned integers\n7. Float32Array: An array of 32-bit floating point numbers\n8. Float64Array: An array of 64-bit floating point numbers\n\nFor example, you can create an array of 8-bit signed integers as below\n\n```javascript\nconst a = new Int8Array();\n// You can pre-allocate n bytes\nconst bytes = 1024;\nconst a = new Int8Array(bytes);\n```</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of module loaders</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The module loaders provides the below features,\n\n1. Dynamic loading\n2. State isolation\n3. Global namespace isolation\n4. Compilation hooks\n5. Nested virtualization</code></pre></div>\n</li>\n<li>\n<p>What is collation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Collation is used for sorting a set of strings and searching within a set of strings. It is parameterized by locale and aware of Unicode. Let's take comparison and sorting features,\n\n1. **Comparison:**\n\n```javascript\nvar list = ['ä', 'a', 'z']; // In German,  \"ä\" sorts with \"a\" Whereas in Swedish, \"ä\" sorts after \"z\"\nvar l10nDE = new Intl.Collator('de');\nvar l10nSV = new Intl.Collator('sv');\nconsole.log(l10nDE.compare('ä', 'z') === -1); // true\nconsole.log(l10nSV.compare('ä', 'z') === +1); // true\n```\n\n1. **Sorting:**\n\n```javascript\nvar list = ['ä', 'a', 'z']; // In German,  \"ä\" sorts with \"a\" Whereas in Swedish, \"ä\" sorts after \"z\"\nvar l10nDE = new Intl.Collator('de');\nvar l10nSV = new Intl.Collator('sv');\nconsole.log(list.sort(l10nDE.compare)); // [ \"a\", \"ä\", \"z\" ]\nconsole.log(list.sort(l10nSV.compare)); // [ \"a\", \"z\", \"ä\" ]\n```</code></pre></div>\n</li>\n<li>\n<p>What is for...of statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The for...of statement creates a loop iterating over iterable objects or elements such as built-in String, Array, Array-like objects (like arguments or NodeList), TypedArray, Map, Set, and user-defined iterables. The basic usage of for...of statement on arrays would be as below,\n\n```javascript\nlet arrayIterable = [10, 20, 30, 40, 50];\n\nfor (let value of arrayIterable) {\n    value++;\n    console.log(value); // 11 21 31 41 51\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below spread operator array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">```javascript\n[...'John Resig'];\n```\n\nThe output of the array is ['J', 'o', 'h', 'n', '', 'R', 'e', 's', 'i', 'g']\n**Explanation:** The string is an iterable type and the spread operator within an array maps every character of an iterable to one element. Hence, each character of a string becomes an element within an Array.</code></pre></div>\n</li>\n<li>\n<p>Is PostMessage secure</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, postMessages can be considered very secure as long as the programmer/developer is careful about checking the origin and source of an arriving message. But if you try to send/receive a message without verifying its source will create cross-site scripting attacks.</code></pre></div>\n</li>\n<li>\n<p>What are the problems with postmessage target origin as wildcard</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The second argument of postMessage method specifies which origin is allowed to receive the message. If you use the wildcard \"\\*\" as an argument then any origin is allowed to receive the message. In this case, there is no way for the sender window to know if the target window is at the target origin when sending the message. If the target window has been navigated to another origin, the other origin would receive the data. Hence, this may lead to XSS vulnerabilities.\n\n```javascript\ntargetWindow.postMessage(message, '*');\n```</code></pre></div>\n</li>\n<li>\n<p>How do you avoid receiving postMessages from attackers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Since the listener listens for any message, an attacker can trick the application by sending a message from the attacker's origin, which gives an impression that the receiver received the message from the actual sender's window. You can avoid this issue by validating the origin of the message on the receiver's end using the \"message.origin\" attribute. For examples, let's check the sender's origin [http://www.some-sender.com](https://www.some-sender.com) on receiver side [www.some-receiver.com](www.some-receiver.com),\n\n```javascript\n//Listener on http://www.some-receiver.com/\nwindow.addEventListener(\"message\", function(message){\n    if(/^http://www\\.some-sender\\.com$/.test(message.origin)){\n         console.log('You received the data from valid sender', message.data);\n   }\n});\n```</code></pre></div>\n</li>\n<li>\n<p>Can I avoid using postMessages completely</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You cannot avoid using postMessages completely(or 100%). Even though your application doesn't use postMessage considering the risks, a lot of third party scripts use postMessage to communicate with the third party service. So your application might be using postMessage without your knowledge.</code></pre></div>\n</li>\n<li>\n<p>Is postMessages synchronous</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The postMessages are synchronous in IE8 browser but they are asynchronous in IE9 and all other modern browsers (i.e, IE9+, Firefox, Chrome, Safari).Due to this asynchronous behaviour, we use a callback mechanism when the postMessage is returned.</code></pre></div>\n</li>\n<li>\n<p>What paradigm is Javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a multi-paradigm language, supporting imperative/procedural programming, Object-Oriented Programming and functional programming. JavaScript supports Object-Oriented Programming with prototypical inheritance.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between internal and external javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**Internal JavaScript:** It is the source code within the script tag.\n**External JavaScript:** The source code is stored in an external file(stored with .js extension) and referred with in the tag.</code></pre></div>\n</li>\n<li>\n<p>Is JavaScript faster than server side script</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, JavaScript is faster than server side script. Because JavaScript is a client-side script it does not require any web server's help for its computation or calculation. So JavaScript is always faster than any server-side script like ASP, PHP, etc.</code></pre></div>\n</li>\n<li>\n<p>How do you get the status of a checkbox</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can apply the `checked` property on the selected checkbox in the DOM. If the value is `True` means the checkbox is checked otherwise it is unchecked. For example, the below HTML checkbox element can be access using javascript as below,\n\n```html\n&lt;input type=\"checkbox\" name=\"checkboxname\" value=\"Agree\" /> Agree the conditions&lt;br />\n```\n\n```javascript\nconsole.log(document.getElementById('checkboxname').checked); // true or false\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of double tilde operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The double tilde operator(~~) is known as double NOT bitwise operator. This operator is going to be a quicker substitute for Math.floor().</code></pre></div>\n</li>\n<li>\n<p>How do you convert character to ASCII code</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the `String.prototype.charCodeAt()` method to convert string characters to ASCII numbers. For example, let's find ASCII code for the first letter of 'ABC' string,\n\n```javascript\n'ABC'.charCodeAt(0); // returns 65\n```\n\nWhereas `String.fromCharCode()` method converts numbers to equal ASCII characters.\n\n```javascript\nString.fromCharCode(65, 66, 67); // returns 'ABC'\n```</code></pre></div>\n</li>\n<li>\n<p>What is ArrayBuffer</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You can create it as below,\n\n```javascript\nlet buffer = new ArrayBuffer(16); // create a buffer of length 16\nalert(buffer.byteLength); // 16\n```\n\nTo manipulate an ArrayBuffer, we need to use a \"view\" object.\n\n```javascript\n//Create a DataView referring to the buffer\nlet view = new DataView(buffer);\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below string expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">```javascript\nconsole.log('Welcome to JS world'[0]);\n```\n\nThe output of the above expression is \"W\".\n**Explanation:** The bracket notation with specific index on a string returns the character at a specific location. Hence, it returns the character \"W\" of the string. Since this is not supported in IE7 and below versions, you may need to use the .charAt() method to get the desired result.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of Error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Error constructor creates an error object and the instances of error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. The syntax of error object would be as below,\n\n```javascript\nnew Error([message[, fileName[, lineNumber]]])\n```\n\nYou can throw user defined exceptions or errors using Error object in try...catch block as below,\n\n```javascript\ntry {\n    if (withdraw > balance) throw new Error(\"Oops! You don't have enough balance\");\n} catch (e) {\n    console.log(e.name + ': ' + e.message);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of EvalError object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The EvalError object indicates an error regarding the global `eval()` function. Even though this exception is not thrown by JavaScript anymore, the EvalError object remains for compatibility. The syntax of this expression would be as below,\n\n```javascript\nnew EvalError([message[, fileName[, lineNumber]]])\n```\n\nYou can throw EvalError with in try...catch block as below,\n\n```javascript\ntry {\n  throw new EvalError('Eval function error', 'someFile.js', 100);\n} catch (e) {\n  console.log(e.message, e.name, e.fileName);              // \"Eval function error\", \"EvalError\", \"someFile.js\"\n```</code></pre></div>\n</li>\n<li>\n<p>What are the list of cases error thrown from non-strict mode to strict mode</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">When you apply 'use strict'; syntax, some of the below cases will throw a SyntaxError before executing the script\n\n1. When you use Octal syntax\n\n```javascript\nvar n = 022;\n```\n\n1. Using `with` statement\n2. When you use delete operator on a variable name\n3. Using eval or arguments as variable or function argument name\n4. When you use newly reserved keywords\n5. When you declare a function in a block\n\n```javascript\nif (someCondition) {\n    function f() {}\n}\n```\n\nHence, the errors from above cases are helpful to avoid errors in development/production environments.</code></pre></div>\n</li>\n<li>\n<p>Do all objects have prototypes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No. All objects have prototypes except for the base object which is created by the user, or an object that is created using the new keyword.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between a parameter and an argument</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Parameter is the variable name of a function definition whereas an argument represents the value given to a function when it is invoked. Let's explain this with a simple function\n\n```javascript\nfunction myFunction(parameter1, parameter2, parameter3) {\n    console.log(arguments[0]); // \"argument1\"\n    console.log(arguments[1]); // \"argument2\"\n    console.log(arguments[2]); // \"argument3\"\n}\nmyFunction('argument1', 'argument2', 'argument3');\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of some method in arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The some() method is used to test whether at least one element in the array passes the test implemented by the provided function. The method returns a boolean value. Let's take an example to test for any odd elements,\n\n```javascript\nvar array = [1, 2, 3, 4, 5, 6 ,7, 8, 9, 10];\n\nvar odd = element ==> element % 2 !== 0;\n\nconsole.log(array.some(odd)); // true (the odd element exists)\n```</code></pre></div>\n</li>\n<li>\n<p>How do you combine two or more arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The concat() method is used to join two or more arrays by returning a new array containing all the elements. The syntax would be as below,\n\n```javascript\narray1.concat(array2, array3, ..., arrayX)\n```\n\nLet's take an example of array's concatenation with veggies and fruits arrays,\n\n```javascript\nvar veggies = ['Tomato', 'Carrot', 'Cabbage'];\nvar fruits = ['Apple', 'Orange', 'Pears'];\nvar veggiesAndFruits = veggies.concat(fruits);\nconsole.log(veggiesAndFruits); // Tomato, Carrot, Cabbage, Apple, Orange, Pears\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between Shallow and Deep copy</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are two ways to copy an object,\n\n**Shallow Copy:**\nShallow copy is a bitwise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied.\n\n**Example**\n\n```javascript\nvar empDetails = {\n    name: 'John',\n    age: 25,\n    expertise: 'Software Developer'\n};\n```\n\nto create a duplicate\n\n```javascript\nvar empDetailsShallowCopy = empDetails; //Shallow copying!\n```\n\nif we change some property value in the duplicate one like this:\n\n```javascript\nempDetailsShallowCopy.name = 'Johnson';\n```\n\nThe above statement will also change the name of `empDetails`, since we have a shallow copy. That means we're losing the original data as well.\n\n**Deep copy:**\nA deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.\n\n**Example**\n\n```javascript\nvar empDetails = {\n    name: 'John',\n    age: 25,\n    expertise: 'Software Developer'\n};\n```\n\nCreate a deep copy by using the properties from the original object into new variable\n\n```javascript\nvar empDetailsDeepCopy = {\n    name: empDetails.name,\n    age: empDetails.age,\n    expertise: empDetails.expertise\n};\n```\n\nNow if you change `empDetailsDeepCopy.name`, it will only affect `empDetailsDeepCopy` &amp; not `empDetails`</code></pre></div>\n</li>\n<li>\n<p>How do you create specific number of copies of a string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `repeat()` method is used to construct and return a new string which contains the specified number of copies of the string on which it was called, concatenated together. Remember that this method has been added to the ECMAScript 2015 specification.\nLet's take an example of Hello string to repeat it 4 times,\n\n```javascript\n'Hello'.repeat(4); // 'HelloHelloHelloHello'\n```</code></pre></div>\n</li>\n<li>\n<p>How do you return all matching strings against a regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `matchAll()` method can be used to return an iterator of all results matching a string against a regular expression. For example, the below example returns an array of matching string results against a regular expression,\n\n```javascript\nlet regexp = /Hello(\\d?))/g;\nlet greeting = 'Hello1Hello2Hello3';\n\nlet greetingList = [...greeting.matchAll(regexp)];\n\nconsole.log(greetingList[0]); //Hello1\nconsole.log(greetingList[1]); //Hello2\nconsole.log(greetingList[2]); //Hello3\n```</code></pre></div>\n</li>\n<li>\n<p>How do you trim a string at the beginning or ending</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `trim` method of string prototype is used to trim on both sides of a string. But if you want to trim especially at the beginning or ending of the string then you can use `trimStart/trimLeft` and `trimEnd/trimRight` methods. Let's see an example of these methods on a greeting message,\n\n```javascript\nvar greeting = '   Hello, Goodmorning!   ';\n\nconsole.log(greeting); // \"   Hello, Goodmorning!   \"\nconsole.log(greeting.trimStart()); // \"Hello, Goodmorning!   \"\nconsole.log(greeting.trimLeft()); // \"Hello, Goodmorning!   \"\n\nconsole.log(greeting.trimEnd()); // \"   Hello, Goodmorning!\"\nconsole.log(greeting.trimRight()); // \"   Hello, Goodmorning!\"\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below console statement with unary operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Let's take console statement with unary operator as given below,\n\n```javascript\nconsole.log(+'Hello');\n```\n\nThe output of the above console log statement returns NaN. Because the element is prefixed by the unary operator and the JavaScript interpreter will try to convert that element into a number type. Since the conversion fails, the value of the statement results in NaN value.</code></pre></div>\n</li>\n<li>Does javascript uses mixins</li>\n<li>\n<p>What is a thunk function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A thunk is just a function which delays the evaluation of the value. It doesn't take any arguments but gives the value whenever you invoke the thunk. i.e, It is used not to execute now but it will be sometime in the future. Let's take a synchronous example,\n\n```javascript\nconst add = (x, y) => x + y;\n\nconst thunk = () => add(2, 3);\n\nthunk(); // 5\n```</code></pre></div>\n</li>\n<li>\n<p>What are asynchronous thunks</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The asynchronous thunks are useful to make network requests. Let's see an example of network requests,\n\n```javascript\nfunction fetchData(fn) {\n    fetch('https://jsonplaceholder.typicode.com/todos/1')\n        .then((response) => response.json())\n        .then((json) => fn(json));\n}\n\nconst asyncThunk = function () {\n    return fetchData(function getData(data) {\n        console.log(data);\n    });\n};\n\nasyncThunk();\n```\n\nThe `getData` function won't be called immediately but it will be invoked only when the data is available from API endpoint. The setTimeout function is also used to make our code asynchronous. The best real time example is redux state management library which uses the asynchronous thunks to delay the actions to dispatch.</code></pre></div>\n</li>\n<li>\n<p>What is the output of below function calls</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**Code snippet:**\n\n```javascript\nconst circle = {\n    radius: 20,\n    diameter() {\n        return this.radius * 2;\n    },\n    perimeter: () => 2 * Math.PI * this.radius\n};\n```\n\nconsole.log(circle.diameter());\nconsole.log(circle.perimeter());\n\n**Output:**\n\nThe output is 40 and NaN. Remember that diameter is a regular function, whereas the value of perimeter is an arrow function. The `this` keyword of a regular function(i.e, diameter) refers to the surrounding scope which is a class(i.e, Shape object). Whereas this keyword of perimeter function refers to the surrounding scope which is a window object. Since there is no radius property on window objects it returns an undefined value and the multiple of number value returns NaN value.</code></pre></div>\n</li>\n<li>\n<p>How to remove all line breaks from a string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The easiest approach is using regular expressions to detect and replace newlines in the string. In this case, we use replace function along with string to replace with, which in our case is an empty string.\n\n```javascript\nfunction remove_linebreaks( var message ) {\n    return message.replace( /[\\r\\n]+/gm, \"\" );\n}\n```\n\nIn the above expression, g and m are for global and multiline flags.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between reflow and repaint</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A _repaint_ occurs when changes are made which affect the visibility of an element, but not its layout. Examples of this include outline, visibility, or background color. A _reflow_ involves changes that affect the layout of a portion of the page (or the whole page). Resizing the browser window, changing the font, content changing (such as user typing text), using JavaScript methods involving computed styles, adding or removing elements from the DOM, and changing an element's classes are a few of the things that can trigger reflow. Reflow of an element causes the subsequent reflow of all child and ancestor elements as well as any elements following it in the DOM.</code></pre></div>\n</li>\n<li>\n<p>What happens with negating an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Negating an array with `!` character will coerce the array into a boolean. Since Arrays are considered to be truthy So negating it will return `false`.\n\n```javascript\nconsole.log(![]); // false\n```</code></pre></div>\n</li>\n<li>\n<p>What happens if we add two arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you add two arrays together, it will convert them both to strings and concatenate them. For example, the result of adding arrays would be as below,\n\n```javascript\nconsole.log(['a'] + ['b']); // \"ab\"\nconsole.log([] + []); // \"\"\nconsole.log(![] + []); // \"false\", because ![] returns false.\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of prepend additive operator on falsy values</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you prepend the additive(+) operator on falsy values(null, undefined, NaN, false, \"\"), the falsy value converts to a number value zero. Let's display them on browser console as below,\n\n```javascript\nconsole.log(+null); // 0\nconsole.log(+undefined); // NaN\nconsole.log(+false); // 0\nconsole.log(+NaN); // NaN\nconsole.log(+''); // 0\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create self string using special characters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The self string can be formed with the combination of `[]()!+` characters. You need to remember the below conventions to achieve this pattern.\n\n1. Since Arrays are truthful values, negating the arrays will produce false: ![] === false\n2. As per JavaScript coercion rules, the addition of arrays together will toString them: [] + [] === \"\"\n3. Prepend an array with + operator will convert an array to false, the negation will make it true and finally converting the result will produce value '1': +(!(+[])) === 1\n\nBy applying the above rules, we can derive below conditions\n\n```javascript\n(![] + [] === 'false' + !+[]) === 1;\n```\n\nNow the character pattern would be created as below,\n\n```javascript\n      s               e               l               f\n ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^\n\n (![] + [])[3] + (![] + [])[4] + (![] + [])[2] + (![] + [])[0]\n ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^\n(![] + [])[+!+[]+!+[]+!+[]] +\n(![] + [])[+!+[]+!+[]+!+[]+!+[]] +\n(![] + [])[+!+[]+!+[]] +\n(![] + [])[+[]]\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n(![]+[])[+!+[]+!+[]+!+[]]+(![]+[])[+!+[]+!+[]+!+[]+!+[]]+(![]+[])[+!+[]+!+[]]+(![]+[])[+[]]\n```</code></pre></div>\n</li>\n<li>\n<p>How do you remove falsy values from an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can apply the filter method on the array by passing Boolean as a parameter. This way it removes all falsy values(0, undefined, null, false and \"\") from the array.\n\n```javascript\nconst myArray = [false, null, 1, 5, undefined];\nmyArray.filter(Boolean); // [1, 5] // is same as myArray.filter(x => x);\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get unique values of an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can get unique values of an array with the combination of `Set` and rest expression/spread(...) syntax.\n\n```javascript\nconsole.log([...new Set([1, 2, 4, 4, 3])]); // [1, 2, 4, 3]\n```</code></pre></div>\n</li>\n<li>\n<p>What is destructuring aliases</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Sometimes you would like to have a destructured variable with a different name than the property name. In that case, you'll use a `: newName` to specify a name for the variable. This process is called destructuring aliases.\n\n```javascript\nconst obj = { x: 1 };\n// Grabs obj.x as as { otherName }\nconst { x: otherName } = obj;\n```</code></pre></div>\n</li>\n<li>\n<p>How do you map the array values without using map method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can map the array values without using the `map` method by just using the `from` method of Array. Let's map city names from Countries array,\n\n```javascript\nconst countries = [\n    { name: 'India', capital: 'Delhi' },\n    { name: 'US', capital: 'Washington' },\n    { name: 'Russia', capital: 'Moscow' },\n    { name: 'Singapore', capital: 'Singapore' },\n    { name: 'China', capital: 'Beijing' },\n    { name: 'France', capital: 'Paris' }\n];\n\nconst cityNames = Array.from(countries, ({ capital }) => capital);\nconsole.log(cityNames); // ['Delhi, 'Washington', 'Moscow', 'Singapore', 'Beijing', 'Paris']\n```</code></pre></div>\n</li>\n<li>\n<p>How do you empty an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can empty an array quickly by setting the array length to zero.\n\n```javascript\nlet cities = ['Singapore', 'Delhi', 'London'];\ncities.length = 0; // cities becomes []\n```</code></pre></div>\n</li>\n<li>\n<p>How do you rounding numbers to certain decimals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can round numbers to a certain number of decimals using `toFixed` method from native javascript.\n\n```javascript\nlet pie = 3.141592653;\npie = pie.toFixed(3); // 3.142\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to convert an array to an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can convert an array to an object with the same data using spread(...) operator.\n\n```javascript\nvar fruits = ['banana', 'apple', 'orange', 'watermelon'];\nvar fruitsObject = { ...fruits };\nconsole.log(fruitsObject); // {0: \"banana\", 1: \"apple\", 2: \"orange\", 3: \"watermelon\"}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create an array with some data</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can create an array with some data or an array with the same values using `fill` method.\n\n```javascript\nvar newArray = new Array(5).fill('0');\nconsole.log(newArray); // [\"0\", \"0\", \"0\", \"0\", \"0\"]\n```</code></pre></div>\n</li>\n<li>\n<p>What are the placeholders from console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of placeholders available from console object,\n\n1. %o — It takes an object,\n2. %s — It takes a string,\n3. %d — It is used for a decimal or integer\n   These placeholders can be represented in the console.log as below\n\n```javascript\nconst user = { name: 'John', id: 1, city: 'Delhi' };\nconsole.log('Hello %s, your details %o are available in the object form', 'John', user); // Hello John, your details {name: \"John\", id: 1, city: \"Delhi\"} are available in object\n```</code></pre></div>\n</li>\n<li>\n<p>Is it possible to add CSS to console messages</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, you can apply CSS styles to console messages similar to html text on the web page.\n\n```javascript\nconsole.log('%c The text has blue color, with large font and red background', 'color: blue; font-size: x-large; background: red');\n```\n\nThe text will be displayed as below,\n![Screenshot](images/console-css.png)\n\n**Note:** All CSS styles can be applied to console messages.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of dir method of console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `console.dir()` is used to display an interactive list of the properties of the specified JavaScript object as JSON.\n\n```javascript\nconst user = { name: 'John', id: 1, city: 'Delhi' };\nconsole.dir(user);\n```\n\nThe user object displayed in JSON representation\n![Screenshot](images/console-dir.png)</code></pre></div>\n</li>\n<li>\n<p>Is it possible to debug HTML elements in console</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, it is possible to get and debug HTML elements in the console just like inspecting elements.\n\n```javascript\nconst element = document.getElementsByTagName('body')[0];\nconsole.log(element);\n```\n\nIt prints the HTML element in the console,\n\n![Screenshot](images/console-html.png)</code></pre></div>\n</li>\n<li>\n<p>How do you display data in a tabular format using console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `console.table()` is used to display data in the console in a tabular format to visualize complex arrays or objects.\n\n     ```js\n\n//\nconst users = [\n{ name: 'John', id: 1, city: 'Delhi' },\n{ name: 'Max', id: 2, city: 'London' },\n{ name: 'Rod', id: 3, city: 'Paris' }\n];\nconsole.table(users);\n\n```\n\n     The data visualized in a table format,\n\n     ![Screenshot](images/console-table.png)\n     **Not:** Remember that `console.table()` is not supported in IE.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you verify that an argument is a Number or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The combination of IsNaN and isFinite methods are used to confirm whether an argument is a number or not.\n\n```javascript\nfunction isNumber(n) {\n    return !isNaN(parseFloat(n)) &amp;&amp; isFinite(n);\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create copy to clipboard button</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to select the content(using .select() method) of the input element and execute the copy command with execCommand (i.e, execCommand('copy')). You can also execute other system commands like cut and paste.\n\n```javascript\ndocument.querySelector('#copy-button').onclick = function () {\n    // Select the content\n    document.querySelector('#copy-input').select();\n    // Copy to the clipboard\n    document.execCommand('copy');\n};\n```</code></pre></div>\n</li>\n<li>\n<p>What is the shortcut to get timestamp</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `new Date().getTime()` to get the current timestamp. There is an alternative shortcut to get the value.\n\n```javascript\nconsole.log(+new Date());\nconsole.log(Date.now());\n```</code></pre></div>\n</li>\n<li>\n<p>How do you flattening multi dimensional arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Flattening bi-dimensional arrays is trivial with Spread operator.\n\n```javascript\nconst biDimensionalArr = [11, [22, 33], [44, 55], [66, 77], 88, 99];\nconst flattenArr = [].concat(...biDimensionalArr); // [11, 22, 33, 44, 55, 66, 77, 88, 99]\n```\n\nBut you can make it work with multi-dimensional arrays by recursive calls,\n\n```javascript\nfunction flattenMultiArray(arr) {\n    const flattened = [].concat(...arr);\n    return flattened.some((item) => Array.isArray(item)) ? flattenMultiArray(flattened) : flattened;\n}\nconst multiDimensionalArr = [11, [22, 33], [44, [55, 66, [77, [88]], 99]]];\nconst flatArr = flattenMultiArray(multiDimensionalArr); // [11, 22, 33, 44, 55, 66, 77, 88, 99]\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest multi condition checking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `indexOf` to compare input with multiple values instead of checking each value as one condition.\n\n```javascript\n// Verbose approach\nif (input === 'first' || input === 1 || input === 'second' || input === 2) {\n    someFunction();\n}\n// Shortcut\nif (['first', 1, 'second', 2].indexOf(input) !== -1) {\n    someFunction();\n}\n```</code></pre></div>\n</li>\n<li>\n<p>How do you capture browser back button</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `window.onbeforeunload` method is used to capture browser back button events. This is helpful to warn users about losing the current data.\n\n```javascript\nwindow.onbeforeunload = function () {\n    alert('You work will be lost');\n};\n```</code></pre></div>\n</li>\n<li>\n<p>How do you disable right click in the web page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The right click on the page can be disabled by returning false from the `oncontextmenu` attribute on the body element.\n\n     ```html\n     &lt;body oncontextmenu=\"return false;\">\n\n&lt;/body>\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are wrapper objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Primitive Values like string,number and boolean don't have properties and methods but they are temporarily converted or coerced to an object(Wrapper object) when you try to perform actions on them. For example, if you apply toUpperCase() method on a primitive string value, it does not throw an error but returns uppercase of the string.\n\n```javascript\nlet name = 'john';\n\nconsole.log(name.toUpperCase()); // Behind the scenes treated as console.log(new String(name).toUpperCase());\n```\n\ni.e, Every primitive except null and undefined have Wrapper Objects and the list of wrapper objects are String,Number,Boolean,Symbol and BigInt.</code></pre></div>\n</li>\n<li>\n<p>What is AJAX</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">AJAX stands for Asynchronous JavaScript and XML and it is a group of related technologies(HTML, CSS, JavaScript, XMLHttpRequest API etc) used to display data asynchronously. i.e. We can send data to the server and get data from the server without reloading the web page.</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to deal with Asynchronous Code</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of different ways to deal with Asynchronous code.\n\n1. Callbacks\n2. Promises\n3. Async/await\n4. Third-party libraries such as async.js,bluebird etc</code></pre></div>\n</li>\n<li>\n<p>How to cancel a fetch request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Until a few days back, One shortcoming of native promises is no direct way to cancel a fetch request. But the new `AbortController` from js specification allows you to use a signal to abort one or multiple fetch calls.\nThe basic flow of cancelling a fetch request would be as below,\n\n1. Create an `AbortController` instance\n2. Get the signal property of an instance and pass the signal as a fetch option for signal\n3. Call the AbortController's abort property to cancel all fetches that use that signal\n   For example, let's pass the same signal to multiple fetch calls will cancel all requests with that signal,\n\n```javascript\nconst controller = new AbortController();\nconst { signal } = controller;\n\nfetch('http://localhost:8000', { signal })\n    .then((response) => {\n        console.log(`Request 1 is complete!`);\n    })\n    .catch((e) => {\n        if (e.name === 'AbortError') {\n            // We know it's been canceled!\n        }\n    });\n\nfetch('http://localhost:8000', { signal })\n    .then((response) => {\n        console.log(`Request 2 is complete!`);\n    })\n    .catch((e) => {\n        if (e.name === 'AbortError') {\n            // We know it's been canceled!\n        }\n    });\n\n// Wait 2 seconds to abort both requests\nsetTimeout(() => controller.abort(), 2000);\n```</code></pre></div>\n</li>\n<li>\n<p>What is web speech API</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Web speech API is used to enable modern browsers recognize and synthesize speech(i.e, voice data into web apps). This API has been introduced by W3C Community in the year 2012. It has two main parts,\n\n1. **SpeechRecognition (Asynchronous Speech Recognition or Speech-to-Text):** It provides the ability to recognize voice context from an audio input and respond accordingly. This is accessed by the `SpeechRecognition` interface.\n   The below example shows on how to use this API to get text from speech,\n\n```javascript\nwindow.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition; // webkitSpeechRecognition for Chrome and SpeechRecognition for FF\nconst recognition = new window.SpeechRecognition();\nrecognition.onresult = (event) => {\n    // SpeechRecognitionEvent type\n    const speechToText = event.results[0][0].transcript;\n    console.log(speechToText);\n};\nrecognition.start();\n```\n\nIn this API, browser is going to ask you for permission to use your microphone\n\n1. **SpeechSynthesis (Text-to-Speech):** It provides the ability to recognize voice context from an audio input and respond. This is accessed by the `SpeechSynthesis` interface.\n   For example, the below code is used to get voice/speech from text,\n\n```javascript\nif ('speechSynthesis' in window) {\n    var speech = new SpeechSynthesisUtterance('Hello World!');\n    speech.lang = 'en-US';\n    window.speechSynthesis.speak(speech);\n}\n```\n\nThe above examples can be tested on chrome(33+) browser's developer console.\n**Note:** This API is still a working draft and only available in Chrome and Firefox browsers(ofcourse Chrome only implemented the specification)</code></pre></div>\n</li>\n<li>\n<p>What is minimum timeout throttling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both browser and NodeJS javascript environments throttles with a minimum delay that is greater than 0ms. That means even though setting a delay of 0ms will not happen instantaneously.\n**Browsers:** They have a minimum delay of 4ms. This throttle occurs when successive calls are triggered due to callback nesting(certain depth) or after a certain number of successive intervals.\nNote: The older browsers have a minimum delay of 10ms.\n**Nodejs:** They have a minimum delay of 1ms. This throttle happens when the delay is larger than 2147483647 or less than 1.\nThe best example to explain this timeout throttling behavior is the order of below code snippet.\n\n```javascript\nfunction runMeFirst() {\n    console.log('My script is initialized');\n}\nsetTimeout(runMeFirst, 0);\nconsole.log('Script loaded');\n```\n\nand the output would be in\n\n```shell\nScript loaded\nMy script is initialized\n```\n\nIf you don't use `setTimeout`, the order of logs will be sequential.\n\n```javascript\nfunction runMeFirst() {\n    console.log('My script is initialized');\n}\nrunMeFirst();\nconsole.log('Script loaded');\n```\n\nand the output is,\n\n```shell\nMy script is initialized\nScript loaded\n```</code></pre></div>\n</li>\n<li>\n<p>How do you implement zero timeout in modern browsers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can't use setTimeout(fn, 0) to execute the code immediately due to minimum delay of greater than 0ms. But you can use window.postMessage() to achieve this behavior.</code></pre></div>\n</li>\n<li>\n<p>What are tasks in event loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A task is any javascript code/program which is scheduled to be run by the standard mechanisms such as initially starting to run a program, run an event callback, or an interval or timeout being fired. All these tasks are scheduled on a task queue.\nBelow are the list of use cases to add tasks to the task queue,\n\n1. When a new javascript program is executed directly from console or running by the `&lt;script>` element, the task will be added to the task queue.\n2. When an event fires, the event callback added to task queue\n3. When a setTimeout or setInterval is reached, the corresponding callback added to task queue</code></pre></div>\n</li>\n<li>\n<p>What is microtask</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Microtask is the javascript code which needs to be executed immediately after the currently executing task/microtask is completed. They are kind of blocking in nature. i.e, The main thread will be blocked until the microtask queue is empty.\nThe main sources of microtasks are Promise.resolve, Promise.reject, MutationObservers, IntersectionObservers etc\n\n**Note:** All of these microtasks are processed in the same turn of the event loop.</code></pre></div>\n</li>\n<li>What are different event loops</li>\n<li>What is the purpose of queueMicrotask</li>\n<li>\n<p>How do you use javascript libraries in typescript file</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is known that not all JavaScript libraries or frameworks have TypeScript declaration files. But if you still want to use libraries or frameworks in our TypeScript files without getting compilation errors, the only solution is `declare` keyword along with a variable declaration. For example, let's imagine you have a library called `customLibrary` that doesn't have a TypeScript declaration and have a namespace called `customLibrary` in the global namespace. You can use this library in typescript code as below,\n\n```javascript\ndeclare var customLibrary;\n```\n\nIn the runtime, typescript will provide the type to the `customLibrary` variable as `any` type. The another alternative without using declare keyword is below\n\n```javascript\nvar customLibrary: any;\n```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between promises and observables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the major difference in a tabular form\n\n| Promises                                                           | Observables                                                                              |\n| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |\n| Emits only a single value at a time                                | Emits multiple values over a period of time(stream of values ranging from 0 to multiple) |\n| Eager in nature; they are going to be called immediately           | Lazy in nature; they require subscription to be invoked                                  |\n| Promise is always asynchronous even though it resolved immediately | Observable can be either synchronous or asynchronous                                     |\n| Doesn't provide any operators                                      | Provides operators such as map, forEach, filter, reduce, retry, and retryWhen etc        |\n| Cannot be canceled                                                 | Canceled by using unsubscribe() method                                                   |</code></pre></div>\n</li>\n<li>\n<p>What is heap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Heap(Or memory heap) is the memory location where objects are stored when we define variables. i.e, This is the place where all the memory allocations and de-allocation take place. Both heap and call-stack are two containers of JS runtime.\nWhenever runtime comes across variables and function declarations in the code it stores them in the Heap.\n\n![Screenshot](images/heap.png)</code></pre></div>\n</li>\n<li>\n<p>What is an event table</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Event Table is a data structure that stores and keeps track of all the events which will be executed asynchronously like after some time interval or after the resolution of some API requests. i.e Whenever you call a setTimeout function or invoke async operation, it is added to the Event Table.\nIt doesn't not execute functions on it's own. The main purpose of the event table is to keep track of events and send them to the Event Queue as shown in the below diagram.\n\n![Screenshot](images/event-table.png)</code></pre></div>\n</li>\n<li>\n<p>What is a microTask queue</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Microtask Queue is the new queue where all the tasks initiated by promise objects get processed before the callback queue.\nThe microtasks queue are processed before the next rendering and painting jobs. But if these microtasks are running for a long time then it leads to visual degradation.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between shim and polyfill</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A shim is a library that brings a new API to an older environment, using only the means of that environment. It isn't necessarily restricted to a web application. For example, es5-shim.js is used to emulate ES5 features on older browsers (mainly pre IE9).\nWhereas polyfill is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively.\nIn a simple sentence, A polyfill is a shim for a browser API.</code></pre></div>\n</li>\n<li>\n<p>How do you detect primitive or non primitive value type</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In JavaScript, primitive types include boolean, string, number, BigInt, null, Symbol and undefined. Whereas non-primitive types include the Objects. But you can easily identify them with the below function,\n\n```javascript\nvar myPrimitive = 30;\nvar myNonPrimitive = {};\nfunction isPrimitive(val) {\n    return Object(val) !== val;\n}\n\nisPrimitive(myPrimitive);\nisPrimitive(myNonPrimitive);\n```\n\nIf the value is a primitive data type, the Object constructor creates a new wrapper object for the value. But If the value is a non-primitive data type (an object), the Object constructor will give the same object.</code></pre></div>\n</li>\n<li>\n<p>What is babel</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Babel is a JavaScript transpiler to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments. Some of the main features are listed below,\n\n1. Transform syntax\n2. Polyfill features that are missing in your target environment (using @babel/polyfill)\n3. Source code transformations (or codemods)</code></pre></div>\n</li>\n<li>\n<p>Is Node.js completely single threaded</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Node is a single thread, but some of the functions included in the Node.js standard library(e.g, fs module functions) are not single threaded. i.e, Their logic runs outside of the Node.js single thread to improve the speed and performance of a program.</code></pre></div>\n</li>\n<li>\n<p>What are the common use cases of observables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the most common use cases of observables are web sockets with push notifications, user input changes, repeating intervals, etc</code></pre></div>\n</li>\n<li>\n<p>What is RxJS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">RxJS (Reactive Extensions for JavaScript) is a library for implementing reactive programming using observables that makes it easier to compose asynchronous or callback-based code. It also provides utility functions for creating and working with observables.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between Function constructor and function declaration</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The functions which are created with `Function constructor` do not create closures to their creation contexts but they are always created in the global scope. i.e, the function can access its own local variables and global scope variables only. Whereas function declarations can access outer function variables(closures) too.\n\nLet's see this difference with an example,\n\n**Function Constructor:**\n\n```javascript\nvar a = 100;\nfunction createFunction() {\n    var a = 200;\n    return new Function('return a;');\n}\nconsole.log(createFunction()()); // 100\n```\n\n**Function declaration:**\n\n```javascript\nvar a = 100;\nfunction createFunction() {\n    var a = 200;\n    return function func() {\n        return a;\n    };\n}\nconsole.log(createFunction()()); // 200\n```</code></pre></div>\n</li>\n<li>\n<p>What is a Short circuit condition</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Short circuit conditions are meant for condensed way of writing simple if statements. Let's demonstrate the scenario using an example. If you would like to login to a portal with an authentication condition, the expression would be as below,\n\n```javascript\nif (authenticate) {\n    loginToPorta();\n}\n```\n\nSince the javascript logical operators evaluated from left to right, the above expression can be simplified using &amp;&amp; logical operator\n\n```javascript\nauthenticate &amp;&amp; loginToPorta();\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to resize an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The length property of an array is useful to resize or empty an array quickly. Let's apply length property on number array to resize the number of elements from 5 to 2,\n\n```javascript\nvar array = [1, 2, 3, 4, 5];\nconsole.log(array.length); // 5\n\narray.length = 2;\nconsole.log(array.length); // 2\nconsole.log(array); // [1,2]\n```\n\nand the array can be emptied too\n\n```javascript\nvar array = [1, 2, 3, 4, 5];\narray.length = 0;\nconsole.log(array.length); // 0\nconsole.log(array); // []\n```</code></pre></div>\n</li>\n<li>\n<p>What is an observable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An Observable is basically a function that can return a stream of values either synchronously or asynchronously to an observer over time. The consumer can get the value by calling `subscribe()` method.\nLet's look at a simple example of an Observable\n\n```javascript\nimport { Observable } from 'rxjs';\n\nconst observable = new Observable((observer) => {\n    setTimeout(() => {\n        observer.next('Message from a Observable!');\n    }, 3000);\n});\n\nobservable.subscribe((value) => console.log(value));\n```\n\n![Screenshot](images/observables.png)\n\n**Note:** Observables are not part of the JavaScript language yet but they are being proposed to be added to the language</code></pre></div>\n</li>\n<li>\n<p>What is the difference between function and class declarations</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference between function declarations and class declarations is `hoisting`. The function declarations are hoisted but not class declarations.\n\n**Classes:**\n\n```javascript\nconst user = new User(); // ReferenceError\n\nclass User {}\n```\n\n**Constructor Function:**\n\n```javascript\nconst user = new User(); // No error\n\nfunction User() {}\n```</code></pre></div>\n</li>\n<li>\n<p>What is an async function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An async function is a function declared with the `async` keyword which enables asynchronous, promise-based behavior to be written in a cleaner style by avoiding promise chains. These functions can contain zero or more `await` expressions.\n\nLet's take a below async function example,\n\n```javascript\nasync function logger() {\n    let data = await fetch('http://someapi.com/users'); // pause until fetch returns\n    console.log(data);\n}\nlogger();\n```\n\nIt is basically syntax sugar over ES2015 promises and generators.</code></pre></div>\n</li>\n<li>\n<p>How do you prevent promises swallowing errors</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">While using asynchronous code, JavaScript's ES6 promises can make your life a lot easier without having callback pyramids and error handling on every second line. But Promises have some pitfalls and the biggest one is swallowing errors by default.\n\nLet's say you expect to print an error to the console for all the below cases,\n\n```javascript\nPromise.resolve('promised value').then(function () {\n    throw new Error('error');\n});\n\nPromise.reject('error value').catch(function () {\n    throw new Error('error');\n});\n\nnew Promise(function (resolve, reject) {\n    throw new Error('error');\n});\n```\n\nBut there are many modern JavaScript environments that won't print any errors. You can fix this problem in different ways,\n\n1. **Add catch block at the end of each chain:** You can add catch block to the end of each of your promise chains\n\n    ```javascript\n    Promise.resolve('promised value')\n        .then(function () {\n            throw new Error('error');\n        })\n        .catch(function (error) {\n            console.error(error.stack);\n        });\n    ```\n\n    But it is quite difficult to type for each promise chain and verbose too.\n\n2. **Add done method:** You can replace first solution's then and catch blocks with done method\n\n    ```javascript\n    Promise.resolve('promised value').done(function () {\n        throw new Error('error');\n    });\n    ```\n\n    Let's say you want to fetch data using HTTP and later perform processing on the resulting data asynchronously. You can write `done` block as below,\n\n    ```javascript\n    getDataFromHttp()\n        .then(function (result) {\n            return processDataAsync(result);\n        })\n        .done(function (processed) {\n            displayData(processed);\n        });\n    ```\n\n    In future, if the processing library API changed to synchronous then you can remove `done` block as below,\n\n    ```javascript\n    getDataFromHttp().then(function (result) {\n        return displayData(processDataAsync(result));\n    });\n    ```\n\n    and then you forgot to add `done` block to `then` block leads to silent errors.\n\n3. **Extend ES6 Promises by Bluebird:**\n   Bluebird extends the ES6 Promises API to avoid the issue in the second solution. This library has a \"default\" onRejection handler which will print all errors from rejected Promises to stderr. After installation, you can process unhandled rejections\n\n    ```javascript\n    Promise.onPossiblyUnhandledRejection(function (error) {\n        throw error;\n    });\n    ```\n\n    and discard a rejection, just handle it with an empty catch\n\n    ```javascript\n    Promise.reject('error value').catch(function () {});\n    ```</code></pre></div>\n</li>\n<li>\n<p>What is deno</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 JavaScript engine and the Rust programming language.</code></pre></div>\n</li>\n<li>\n<p>How do you make an object iterable in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">By default, plain objects are not iterable. But you can make the object iterable by defining a `Symbol.iterator` property on it.\n\nLet's demonstrate this with an example,\n\n```javascript\nconst collection = {\n    one: 1,\n    two: 2,\n    three: 3,\n    [Symbol.iterator]() {\n        const values = Object.keys(this);\n        let i = 0;\n        return {\n            next: () => {\n                return {\n                    value: this[values[i++]],\n                    done: i > values.length\n                };\n            }\n        };\n    }\n};\n\nconst iterator = collection[Symbol.iterator]();\n\nconsole.log(iterator.next()); // → {value: 1, done: false}\nconsole.log(iterator.next()); // → {value: 2, done: false}\nconsole.log(iterator.next()); // → {value: 3, done: false}\nconsole.log(iterator.next()); // → {value: undefined, done: true}\n```\n\nThe above process can be simplified using a generator function,\n\n```javascript\nconst collection = {\n    one: 1,\n    two: 2,\n    three: 3,\n    [Symbol.iterator]: function* () {\n        for (let key in this) {\n            yield this[key];\n        }\n    }\n};\nconst iterator = collection[Symbol.iterator]();\nconsole.log(iterator.next()); // {value: 1, done: false}\nconsole.log(iterator.next()); // {value: 2, done: false}\nconsole.log(iterator.next()); // {value: 3, done: false}\nconsole.log(iterator.next()); // {value: undefined, done: true}\n```</code></pre></div>\n</li>\n<li>\n<p>What is a Proper Tail Call</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">First, we should know about tail call before talking about \"Proper Tail Call\". A tail call is a subroutine or function call performed as the final action of a calling function. Whereas **Proper tail call(PTC)** is a technique where the program or code will not create additional stack frames for a recursion when the function call is a tail call.\n\nFor example, the below classic or head recursion of factorial function relies on stack for each step. Each step need to be processed upto `n * factorial(n - 1)`\n\n```javascript\nfunction factorial(n) {\n    if (n === 0) {\n        return 1;\n    }\n    return n * factorial(n - 1);\n}\nconsole.log(factorial(5)); //120\n```\n\nBut if you use Tail recursion functions, they keep passing all the necessary data it needs down the recursion without relying on the stack.\n\n```javascript\nfunction factorial(n, acc = 1) {\n    if (n === 0) {\n        return acc;\n    }\n    return factorial(n - 1, n * acc);\n}\nconsole.log(factorial(5)); //120\n```\n\nThe above pattern returns the same output as the first one. But the accumulator keeps track of total as an argument without using stack memory on recursive calls.</code></pre></div>\n</li>\n<li>\n<p>How do you check an object is a promise or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you don't know if a value is a promise or not, wrapping the value as `Promise.resolve(value)` which returns a promise\n\n```javascript\nfunction isPromise(object) {\n    if (Promise &amp;&amp; Promise.resolve) {\n        return Promise.resolve(object) == object;\n    } else {\n        throw 'Promise not supported in your environment';\n    }\n}\n\nvar i = 1;\nvar promise = new Promise(function (resolve, reject) {\n    resolve();\n});\n\nconsole.log(isPromise(i)); // false\nconsole.log(isPromise(p)); // true\n```\n\nAnother way is to check for `.then()` handler type\n\n```javascript\nfunction isPromise(value) {\n    return Boolean(value &amp;&amp; typeof value.then === 'function');\n}\nvar i = 1;\nvar promise = new Promise(function (resolve, reject) {\n    resolve();\n});\n\nconsole.log(isPromise(i)); // false\nconsole.log(isPromise(promise)); // true\n```</code></pre></div>\n</li>\n<li>\n<p>How to detect if a function is called as constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use `new.target` pseudo-property to detect whether a function was called as a constructor(using the new operator) or as a regular function call.\n\n1. If a constructor or function invoked using the new operator, new.target returns a reference to the constructor or function.\n2. For function calls, new.target is undefined.\n\n```javascript\nfunction Myfunc() {\n   if (new.target) {\n      console.log('called with new');\n   } else {\n      console.log('not called with new');\n   }\n}\n\nnew Myfunc(); // called with new\nMyfunc(); // not called with new\nMyfunc.call({}); not called with new\n```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between arguments object and rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are three main differences between arguments object and rest parameters\n\n1. The arguments object is an array-like but not an array. Whereas the rest parameters are array instances.\n2. The arguments object does not support methods such as sort, map, forEach, or pop. Whereas these methods can be used in rest parameters.\n3. The rest parameters are only the ones that haven't been given a separate name, while the arguments object contains all arguments passed to the function</code></pre></div>\n</li>\n<li>\n<p>What are the differences between spread operator and rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Rest parameter collects all remaining elements into an array. Whereas Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. i.e, Rest parameter is opposite to the spread operator.</code></pre></div>\n</li>\n<li>\n<p>What are the different kinds of generators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are five kinds of generators,\n\n1. **Generator function declaration:**\n\n    ```javascript\n    function* myGenFunc() {\n        yield 1;\n        yield 2;\n        yield 3;\n    }\n    const genObj = myGenFunc();\n    ```\n\n2. **Generator function expressions:**\n\n    ```javascript\n    const myGenFunc = function* () {\n        yield 1;\n        yield 2;\n        yield 3;\n    };\n    const genObj = myGenFunc();\n    ```\n\n3. **Generator method definitions in object literals:**\n\n    ```javascript\n    const myObj = {\n        *myGeneratorMethod() {\n            yield 1;\n            yield 2;\n            yield 3;\n        }\n    };\n    const genObj = myObj.myGeneratorMethod();\n    ```\n\n4. **Generator method definitions in class:**\n\n    ```javascript\n    class MyClass {\n        *myGeneratorMethod() {\n            yield 1;\n            yield 2;\n            yield 3;\n        }\n    }\n    const myObject = new MyClass();\n    const genObj = myObject.myGeneratorMethod();\n    ```\n\n5. **Generator as a computed property:**\n\n    ```javascript\n    const SomeObj = {\n        *[Symbol.iterator]() {\n            yield 1;\n            yield 2;\n            yield 3;\n        }\n    };\n\n    console.log(Array.from(SomeObj)); // [ 1, 2, 3 ]\n    ```</code></pre></div>\n</li>\n<li>\n<p>What are the built-in iterables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of built-in iterables in javascript,\n\n1. Arrays and TypedArrays\n2. Strings: Iterate over each character or Unicode code-points\n3. Maps: iterate over its key-value pairs\n4. Sets: iterates over their elements\n5. arguments: An array-like special variable in functions\n6. DOM collection such as NodeList</code></pre></div>\n</li>\n<li>\n<p>What are the differences between for...of and for...in statements</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both for...in and for...of statements iterate over js data structures. The only difference is over what they iterate:\n\n1. for..in iterates over all enumerable property keys of an object\n2. for..of iterates over the values of an iterable object.\n\nLet's explain this difference with an example,\n\n```javascript\nlet arr = ['a', 'b', 'c'];\n\narr.newProp = 'newVlue';\n\n// key are the property keys\nfor (let key in arr) {\n    console.log(key);\n}\n\n// value are the property values\nfor (let value of arr) {\n    console.log(value);\n}\n```\n\nSince for..in loop iterates over the keys of the object, the first loop logs 0, 1, 2 and newProp while iterating over the array object. The for..of loop iterates over the values of a arr data structure and logs a, b, c in the console.</code></pre></div>\n</li>\n<li>\n<p>How do you define instance and non-instance properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Instance properties must be defined inside of class methods. For example, name and age properties defined insider constructor as below,\n\n```javascript\nclass Person {\n    constructor(name, age) {\n        this.name = name;\n        this.age = age;\n    }\n}\n```\n\nBut Static(class) and prototype data properties must be defined outside of the ClassBody declaration. Let's assign the age value for Person class as below,\n\n```javascript\nPerson.staticAge = 30;\nPerson.prototype.prototypeAge = 40;\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between isNaN and Number.isNaN?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. **isNaN**: The global function `isNaN` converts the argument to a Number and returns true if the resulting value is NaN.\n2. **Number.isNaN**: This method does not convert the argument. But it returns true when the type is a Number and value is NaN.\n\nLet's see the difference with an example,\n\n```javascript\nisNaN('hello'); // true\nNumber.isNaN('hello'); // false\n```</code></pre></div>\n</li>\n<li>\n<p>How to invoke an IIFE without any extra brackets?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Immediately Invoked Function Expressions(IIFE) requires a pair of parenthesis to wrap the function which contains set of statements.\n\n     ```js\n\n//\n(function (dt) {\nconsole.log(dt.toLocaleTimeString());\n})(new Date());\n\n````\n\n     Since both IIFE and void operator discard the result of an expression, you can avoid the extra brackets using `void operator` for IIFE as below,\n\n     ```js\n\n//\nvoid (function (dt) {\nconsole.log(dt.toLocaleTimeString());\n})(new Date());\n````</code></pre></div>\n</li>\n<li>\n<p>Is that possible to use expressions in switch cases?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You might have seen expressions used in switch condition but it is also possible to use for switch cases by assigning true value for the switch condition. Let's see the weather condition based on temparature as an example,\n\n     ```js\n\n//\nconst weather = (function getWeather(temp) {\nswitch (true) {\ncase temp &lt; 0:\nreturn 'freezing';\ncase temp &lt; 10:\nreturn 'cold';\ncase temp &lt; 24:\nreturn 'cool';\ndefault:\nreturn 'unknown';\n}\n\n     })(10);\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to ignore promise errors?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The easiest and safest way to ignore promise errors is void that error. This approach is ESLint friendly too.\n\n     ```js\n\n//\nawait promise.catch((e) => void e);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do style the console output using CSS?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can add CSS styling to the console output using the CSS format content specifier %c. The console string message can be appended after the specifier and CSS style in another argument. Let's print the red the color text using console.log and CSS specifier as below,\n\n     ```js\n\n//\nconsole.log('%cThis is a red text', 'color:red');\n\n````\n\n     It is also possible to add more styles for the content. For example, the font-size can be modified for the above text\n\n     ```js\n\n//\nconsole.log('%cThis is a red text with bigger font', 'color:red; font-size:20px');\n````</code></pre></div>\n</li>\n<li>\n<p>What is nullish coalescing operator (??)?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. This can be contrasted with the logical OR (||) operator, which returns the right-hand side operand if the left operand is any falsy value, not only null or undefined.\n\n     ```js\n\n//\nconsole.log(null ?? true); // true\nconsole.log(false ?? true); // false\nconsole.log(undefined ?? true); // true\n\n```\n\n```</code></pre></div>\n</li>\n</ol>\n<h3>Coding Exercise</h3>\n<h4>1. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Vehicle</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Honda'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'white'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'2010'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'UK'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Vehicle</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">model<span class=\"token punctuation\">,</span> color<span class=\"token punctuation\">,</span> year<span class=\"token punctuation\">,</span> country</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>year <span class=\"token operator\">=</span> year<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>country <span class=\"token operator\">=</span> country<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  Undefined\n- 2: ReferenceError\n- 3: null\n- 4: {model: \"Honda\", color: \"white\", year: \"2010\", country: \"UK\"}\n\n&lt;details>\n&lt;summary>\n&lt;b>Answer&lt;/b>\n&lt;/summary>\n&lt;p>\n\n##### Answer: 4\n\nThe function declarations are hoisted similar to any variables. So the placement for </span><span class=\"token template-punctuation string\">`</span></span>Vehicle<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> function declaration doesn't make any difference.\n\n&lt;/p>\n&lt;/details>\n\n---\n\n#### 2. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> x <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    x<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    y<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> x<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> x<span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, undefined and undefined</li>\n<li>2: ReferenceError: X is not defined</li>\n<li>3: 1, undefined and number</li>\n<li>4: 1, number and number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Of course the return value of <code class=\"language-text\">foo()</code> is 1 due to the increment operator. But the statement <code class=\"language-text\">let x = y = 0</code> declares a local variable x. Whereas y declared as a global variable accidentally. This statement is equivalent to,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> x<span class=\"token punctuation\">;</span>\nwindow<span class=\"token punctuation\">.</span>y <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\nx <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span>y<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Since the block scoped variable x is undefined outside of the function, the type will be undefined too. Whereas the global variable <code class=\"language-text\">y</code> is available outside the function, the value is 0 and type is number.</p>\n</p>\n</details>\n<hr>\n<h4>3. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">main</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'B'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'C'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">m</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>A, B and C</li>\n<li>2: B, A and C</li>\n<li>3: A and C</li>\n<li>4: A, C and B</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The statements order is based on the event loop mechanism. The order of statements follows the below order,</p>\n<ol>\n<li>At first, the main function is pushed to the stack.</li>\n<li>Then the browser pushes the fist statement of the main function( i.e, A's console.log) to the stack, executing and popping out immediately.</li>\n<li>But <code class=\"language-text\">setTimeout</code> statement moved to Browser API to apply the delay for callback.</li>\n<li>In the meantime, C's console.log added to stack, executed and popped out.</li>\n<li>The callback of <code class=\"language-text\">setTimeout</code> moved from Browser API to message queue.</li>\n<li>The <code class=\"language-text\">main</code> function popped out from stack because there are no statements to execute</li>\n<li>The callback moved from message queue to the stack since the stack is empty.</li>\n<li>The console.log for B is added to the stack and display on the console.</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>4. What is the output of below equality check</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span> <span class=\"token operator\">===</span> <span class=\"token number\">0.3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>This is due to the float point math problem. Since the floating point numbers are encoded in binary format, the addition operations on them lead to rounding errors. Hence, the comparison of floating points doesn't give expected results.\nYou can find more details about the explanation here <a href=\"https://0.30000000000000004.com/\">0.30000000000000004.com/</a></p>\n</p>\n</details>\n<hr>\n<h4>5. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    y <span class=\"token operator\">+=</span> <span class=\"token keyword\">typeof</span> f<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1function</li>\n<li>2: 1object</li>\n<li>3: ReferenceError</li>\n<li>4: 1undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The main points in the above code snippets are,</p>\n<ol>\n<li>You can see function expression instead function declaration inside if statement. So it always returns true.</li>\n<li>Since it is not declared(or assigned) anywhere, f is undefined and typeof f is undefined too.</li>\n</ol>\n<p>In other words, it is same as</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    y <span class=\"token operator\">+=</span> <span class=\"token keyword\">typeof</span> f<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Note:</strong> It returns 1object for MS Edge browser</p>\n</p>\n</details>\n<hr>\n<h4>6. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Hello World</li>\n<li>2: Object {message: \"Hello World\"}</li>\n<li>3: Undefined</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>This is a semicolon issue. Normally semicolons are optional in JavaScript. So if there are any statements(in this case, return) missing semicolon, it is automatically inserted immediately. Hence, the function returned as undefined.</p>\n<p>Whereas if the opening curly brace is along with the return keyword then the function is going to be returned as expected.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {message: \"Hello World\"}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>7. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> myChars <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">delete</span> myChars<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[empty, 'b', 'c', 'd'], empty, 3</li>\n<li>2: [null, 'b', 'c', 'd'], empty, 3</li>\n<li>3: [empty, 'b', 'c', 'd'], undefined, 4</li>\n<li>4: [null, 'b', 'c', 'd'], undefined, 4</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The <code class=\"language-text\">delete</code> operator will delete the object property but it will not reindex the array or change its length. So the number or elements or length of the array won't be changed.\nIf you try to print myChars then you can observe that it doesn't set an undefined value, rather the property is removed from the array. The newer versions of Chrome use <code class=\"language-text\">empty</code> instead of <code class=\"language-text\">undefined</code> to make the difference a bit clearer.</p>\n</p>\n</details>\n<hr>\n<h4>8. What is the output of below code in latest Chrome</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> array1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> array2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\narray2<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> array3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[undefined × 3], [undefined × 2, 100], [undefined × 3]</li>\n<li>2: [empty × 3], [empty × 2, 100], [empty × 3]</li>\n<li>3: [null × 3], [null × 2, 100], [null × 3]</li>\n<li>4: [], [100], []</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The latest chrome versions display <code class=\"language-text\">sparse array</code>(they are filled with holes) using this empty x n notation. Whereas the older versions have undefined x n notation.\n<strong>Note:</strong> The latest version of FF displays <code class=\"language-text\">n empty slots</code> notation.</p>\n</p>\n</details>\n<hr>\n<h4>9. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">prop1</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">prop2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'prop'</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop3</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>0, 1, 2</li>\n<li>2: 0, { return 1 }, 2</li>\n<li>3: 0, { return 1 }, { return 2 }</li>\n<li>4: 0, 1, undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>ES6 provides method definitions and property shorthands for objects. So both prop2 and prop3 are treated as regular function values.</p>\n</p>\n</details>\n<hr>\n<h4>10. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">2</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span> <span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>true, true</li>\n<li>2: true, false</li>\n<li>3: SyntaxError, SyntaxError,</li>\n<li>4: false, false</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The important point is that if the statement contains the same operators(e.g, &#x3C; or >) then it can be evaluated from left to right.\nThe first statement follows the below order,</p>\n<ol>\n<li>console.log(1 &#x3C; 2 &#x3C; 3);</li>\n<li>console.log(true &#x3C; 3);</li>\n<li>console.log(1 &#x3C; 3); // True converted as <code class=\"language-text\">1</code> during comparison</li>\n<li>True</li>\n</ol>\n<p>Whereas the second statement follows the below order,</p>\n<ol>\n<li>console.log(3 > 2 > 1);</li>\n<li>console.log(true > 1);</li>\n<li>console.log(1 > 1); // False converted as <code class=\"language-text\">0</code> during comparison</li>\n<li>False</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>11. What is the output of below code in non-strict mode</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">printNumbers</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\np <span class=\"token function\">tNumbers</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, 2, 3</li>\n<li>2: 3, 2, 3</li>\n<li>3: SyntaxError: Duplicate parameter name not allowed in this context</li>\n<li>4: 1, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>In non-strict mode, the regular JavaScript functions allow duplicate named parameters. The above code snippet has duplicate parameters on 1st and 3rd parameters.\nThe value of the first parameter is mapped to the third argument which is passed to the function. Hence, the 3rd argument overrides the first parameter.</p>\n<p><strong>Note:</strong> In strict mode, duplicate parameters will throw a Syntax Error.</p>\n</p>\n</details>\n<hr>\n<h4>12. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">printNumbersArrow</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\np <span class=\"token function\">tNumbersArrow</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, 2, 3</li>\n<li>2: 3, 2, 3</li>\n<li>3: SyntaxError: Duplicate parameter name not allowed in this context</li>\n<li>4: 1, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Unlike regular functions, the arrow functions doesn't not allow duplicate parameters in either strict or non-strict mode. So you can see <code class=\"language-text\">SyntaxError</code> in the console.</p>\n</p>\n</details>\n<hr>\n<h4>13. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">arrowFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">arrowFunc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>ReferenceError: arguments is not defined</li>\n<li>2: 3</li>\n<li>3: undefined</li>\n<li>4: null</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Arrow functions do not have an <code class=\"language-text\">arguments, super, this, or new.target</code> bindings. So any reference to <code class=\"language-text\">arguments</code> variable tries to resolve to a binding in a lexically enclosing environment. In this case, the arguments variable is not defined outside of the arrow function. Hence, you will receive a reference error.</p>\n<p>Where as the normal function provides the number of arguments passed to the function</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">func</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>But If you still want to use an arrow function then rest operator on arguments provides the expected arguments</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token function-variable function\">arrowFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>args</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> args<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">arrowFunc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>14. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>trimLeft<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'trimLeft'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>trimLeft<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'trimStart'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: True, False</li>\n<li>2: False, True</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>In order to be consistent with functions like <code class=\"language-text\">String.prototype.padStart</code>, the standard method name for trimming the whitespaces is considered as <code class=\"language-text\">trimStart</code>. Due to web web compatibility reasons, the old method name 'trimLeft' still acts as an alias for 'trimStart'. Hence, the prototype for 'trimLeft' is always 'trimStart'</p>\n</p>\n</details>\n<hr>\n<h4>15. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined</li>\n<li>2: Infinity</li>\n<li>3: 0</li>\n<li>4: -Infinity</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>-Infinity is the initial comparant because almost every other value is bigger. So when no arguments are provided, -Infinity is going to be returned.\n<strong>Note:</strong> Zero number of arguments is a valid case.</p>\n</p>\n</details>\n<hr>\n<h4>16. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">==</span> <span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">==</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>True, True</li>\n<li>2: True, False</li>\n<li>3: False, False</li>\n<li>4: False, True</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>As per the comparison algorithm in the ECMAScript specification(ECMA-262), the above expression converted into JS as below</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token number\">10</span> <span class=\"token operator\">===</span> <span class=\"token function\">Number</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">valueOf</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 10</span></code></pre></div>\n<p>So it doesn't matter about number brackets([]) around the number, it is always converted to a number in the expression.</p>\n</p>\n</details>\n<hr>\n<h4>17. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">+</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">-</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>20, 0</li>\n<li>2: 1010, 0</li>\n<li>3: 1010, 10-10</li>\n<li>4: NaN, NaN</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The concatenation operator(+) is applicable for both number and string types. So if any operand is string type then both operands concatenated as strings. Whereas subtract(-) operator tries to convert the operands as number type.</p>\n</p>\n</details>\n<hr>\n<h4>18. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm True\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm False\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  True, I'm True\n- 2: True, I'm False\n- 3: False, I'm True\n- 4: False, I'm False\n\n&lt;details>\n&lt;summary>\n&lt;b>Answer&lt;/b>\n&lt;/summary>\n&lt;p>\n\n##### Answer: 1\n\nIn comparison operators, the expression </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> converted to Number([0].valueOf().toString()) which is resolved to false. Whereas </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> just becomes a truthy value without any conversion because there is no comparison operator.\n\n&lt;/p>\n&lt;/details>\n\n#### 19. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[1,2,3,4]</li>\n<li>2: [1,2][3,4]</li>\n<li>3: SyntaxError</li>\n<li>4: 1,23,4</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The + operator is not meant or defined for arrays. So it converts arrays into strings and concatenates them.</p>\n</p>\n</details>\n<hr>\n<h4>20. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> browser <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Firefox'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>browser<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}</li>\n<li>2: {1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"}</li>\n<li>3: [1, 2, 3, 4], [\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"]</li>\n<li>4: {1, 1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Since <code class=\"language-text\">Set</code> object is a collection of unique values, it won't allow duplicate values in the collection. At the same time, it is case sensitive data structure.</p>\n</p>\n</details>\n<hr>\n<h4>21. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span> <span class=\"token operator\">===</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: True</li>\n<li>2: False</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>JavaScript follows IEEE 754 spec standards. As per this spec, NaNs are never equal for floating-point numbers.</p>\n</p>\n</details>\n<hr>\n<h4>22. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>4</li>\n<li>2: NaN</li>\n<li>3: SyntaxError</li>\n<li>4: -1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The <code class=\"language-text\">indexOf</code> uses strict equality operator(===) internally and <code class=\"language-text\">NaN === NaN</code> evaluates to false. Since indexOf won't be able to find NaN inside an array, it returns -1 always.\nBut you can use <code class=\"language-text\">Array.prototype.findIndex</code> method to find out the index of NaN in an array or You can use <code class=\"language-text\">Array.prototype.includes</code> to check if NaN is present in an array or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">findIndex</span><span class=\"token punctuation\">(</span>Number<span class=\"token punctuation\">.</span>isNaN<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 4</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>23. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, [2, 3, 4, 5]</li>\n<li>2: 1, {2, 3, 4, 5}</li>\n<li>3: SyntaxError</li>\n<li>4: 1, [2, 3, 4]</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>When using rest parameters, trailing commas are not allowed and will throw a SyntaxError.\nIf you remove the trailing comma then it displays 1st answer</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1, [2, 3, 4, 5]</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>25. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Promise {&#x3C;fulfilled>: 10}</li>\n<li>2: 10</li>\n<li>3: SyntaxError</li>\n<li>4: Promise {&#x3C;rejected>: 10}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Async functions always return a promise. But even if the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise. The above async function is equivalent to below expression,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>26. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Promise {&#x3C;fulfilled>: 10}</li>\n<li>2: 10</li>\n<li>3: SyntaxError</li>\n<li>4: Promise {&#x3C;resolved>: undefined}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The await expression returns value 10 with promise resolution and the code after each await expression can be treated as existing in a <code class=\"language-text\">.then</code> callback. In this case, there is no return expression at the end of the function. Hence, the default return value of <code class=\"language-text\">undefined</code> is returned as the resolution of the promise. The above async function is equivalent to below expression,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>27. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">processArray</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\np <span class=\"token function\">essArray</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: 1, 2, 3, 4</li>\n<li>3: 4, 4, 4, 4</li>\n<li>4: 4, 3, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Even though \"processArray\" is an async function, the anonymous function that we use for <code class=\"language-text\">forEach</code> is synchronous. If you use await inside a synchronous function then it throws a syntax error.</p>\n</p>\n</details>\n<hr>\n<h4>28. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">process</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Process completed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\np <span class=\"token function\">ess</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1 2 3 5 and Process completed!</li>\n<li>2: 5 5 5 5 and Process completed!</li>\n<li>3: Process completed! and 5 5 5 5</li>\n<li>4: Process completed! and 1 2 3 5</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The forEach method will not wait until all items are finished but it just runs the tasks and goes next. Hence, the last statement is displayed first followed by a sequence of promise resolutions.</p>\n<p>But you control the array sequence using for..of loop,</p>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">processArray</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> item <span class=\"token keyword\">of</span> array<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Process completed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>29. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">var</span> set <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'+0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>set<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Set(4) {\"+0\", \"-0\", NaN, undefined}</li>\n<li>2: Set(3) {\"+0\", NaN, undefined}</li>\n<li>3: Set(5) {\"+0\", \"-0\", NaN, undefined, NaN}</li>\n<li>4: Set(4) {\"+0\", NaN, undefined, NaN}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Set has few exceptions from equality check,</p>\n<ol>\n<li>All NaN values are equal</li>\n<li>Both +0 and -0 considered as different values</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>30. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> sym1 <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> sym2 <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> sym3 <span class=\"token operator\">=</span> Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> sym4 <span class=\"token operator\">=</span> Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nc oe<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sym1 <span class=\"token operator\">===</span> sym2<span class=\"token punctuation\">,</span> sym3 <span class=\"token operator\">===</span> sym4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>true, true</li>\n<li>2: true, false</li>\n<li>3: false, true</li>\n<li>4: false, false</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Symbol follows below conventions,</p>\n<ol>\n<li>Every symbol value returned from Symbol() is unique irrespective of the optional string.</li>\n<li><code class=\"language-text\">Symbol.for()</code> function creates a symbol in a global symbol registry list. But it doesn't necessarily create a new symbol on every call, it checks first if a symbol with the given key is already present in the registry and returns the symbol if it is found. Otherwise a new symbol created in the registry.</li>\n</ol>\n<p><strong>Note:</strong> The symbol description is just useful for debugging purposes.</p>\n</p>\n</details>\n<hr>\n<h4>31. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> sym1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sym1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: one</li>\n<li>3: Symbol('one')</li>\n<li>4: Symbol</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p><code class=\"language-text\">Symbol</code> is a just a standard function and not an object constructor(unlike other primitives new Boolean, new String and new Number). So if you try to call it with the new operator will result in a TypeError</p>\n</p>\n</details>\n<hr>\n<h4>32. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> myNumber <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> myString <span class=\"token operator\">=</span> <span class=\"token string\">'100'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myNumber <span class=\"token operator\">===</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is not a string!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is a string!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myString <span class=\"token operator\">===</span> <span class=\"token string\">'number'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is not a number!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is a number!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  SyntaxError\n- 2: It is not a string!, It is not a number!\n- 3: It is not a string!, It is a number!\n- 4: It is a string!, It is a number!\n\n&lt;details>\n&lt;summary>\n&lt;b>Answer&lt;/b>\n&lt;/summary>\n&lt;p>\n\n##### Answer: 4\n\nThe return value of </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token keyword\">typeof</span> <span class=\"token function\">myNumber</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">OR</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">typeof</span> myString<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> is always the truthy value (either \"number\" or \"string\"). Since ! operator converts the value to a boolean value, the value of both </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myNumber or <span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myString<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\"> is always false. Hence the if condition fails and control goes to else block.\n\n&lt;/p>\n\n&lt;/details>\n\n---\n\n#### 33. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">myArray</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token string\">'one'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{\"myArray\":['one', undefined, {}, Symbol]}, {}</li>\n<li>2: {\"myArray\":['one', null,null,null]}, {}</li>\n<li>3: {\"myArray\":['one', null,null,null]}, \"{ [Symbol.for('one')]: 'one' }, [Symbol.for('one')]\"</li>\n<li>4: {\"myArray\":['one', undefined, function(){}, Symbol('')]}, {}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The symbols has below constraints,</p>\n<ol>\n<li>The undefined, Functions, and Symbols are not valid JSON values. So those values are either omitted (in an object) or changed to null (in an array). Hence, it returns null values for the value array.</li>\n<li>All Symbol-keyed properties will be completely ignored. Hence it returns an empty object({}).</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>34. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">A</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span><span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">B</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">A</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">A</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nn <span class=\"token constant\">B</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: A, A</li>\n<li>2: A, B</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Using constructors, <code class=\"language-text\">new.target</code> refers to the constructor (points to the class definition of class which is initialized) that was directly invoked by new. This also applies to the case if the constructor is in a parent class and was delegated from a child constructor.</p>\n</p>\n</details>\n<hr>\n<h4>35. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>y<span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, [2, 3, 4]</li>\n<li>2: 1, [2, 3]</li>\n<li>3: 1, [2]</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It throws a syntax error because the rest element should not have a trailing comma. You should always consider using a rest operator as the last element.</p>\n</p>\n</details>\n<hr>\n<h4>36. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> x <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> y <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30, 20</li>\n<li>2: 10, 20</li>\n<li>3: 10, undefined</li>\n<li>4: 30, undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The object property follows below rules,</p>\n<ol>\n<li>The object properties can be retrieved and assigned to a variable with a different name</li>\n<li>The property assigned a default value when the retrieved value is <code class=\"language-text\">undefined</code></li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>37. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">a</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>200</li>\n<li>2: Error</li>\n<li>3: undefined</li>\n<li>4: 0</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>If you leave out the right-hand side assignment for the destructuring object, the function will look for at least one argument to be supplied when invoked. Otherwise you will receive an error <code class=\"language-text\">Error: Cannot read property 'length' of undefined</code> as mentioned above.</p>\n<p>You can avoid the error with either of the below changes,</p>\n<ol>\n<li><strong>Pass at least an empty object:</strong></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol start=\"2\">\n<li><strong>Assign default empty object:</strong></li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>38. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> props <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jack'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Tom'</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> name <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Tom</li>\n<li>2: Error</li>\n<li>3: undefined</li>\n<li>4: John</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>It is possible to combine Array and Object destructuring. In this case, the third element in the array props accessed first followed by name property in the object.</p>\n</p>\n</details>\n<hr>\n<h4>39. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">num <span class=\"token operator\">=</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc <span class=\"token function\">kType</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>number, undefined, string, object</li>\n<li>2: undefined, undefined, string, object</li>\n<li>3: number, number, string, object</li>\n<li>4: number, number, number, number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>If the function argument is set implicitly(not passing argument) or explicitly to undefined, the value of the argument is the default parameter. Whereas for other falsy values('' or null), the value of the argument is passed as a parameter.</p>\n<p>Hence, the result of function calls categorized as below,</p>\n<ol>\n<li>The first two function calls logs number type since the type of default value is number</li>\n<li>The type of '' and null values are string and object type respectively.</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>40. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item<span class=\"token punctuation\">,</span> items <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    items<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> items<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Orange'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Apple'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: ['Orange'], ['Orange', 'Apple']</li>\n<li>2: ['Orange'], ['Apple']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Since the default argument is evaluated at call time, a new object is created each time the function is called. So in this case, the new array is created and an element pushed to the default empty array.</p>\n</p>\n</details>\n<hr>\n<h4>41. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">,</span> message <span class=\"token operator\">=</span> greeting <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>greeting<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">,</span> message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ng <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Good morning!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: ['Hello', 'John', 'Hello John'], ['Hello', 'John', 'Good morning!']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Since parameters defined earlier are available to later default parameters, this code snippet doesn't throw any error.</p>\n</p>\n</details>\n<hr>\n<h4>42. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">outer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f <span class=\"token operator\">=</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Inner'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\no <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: ReferenceError</li>\n<li>2: Inner</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The functions and variables declared in the function body cannot be referred from default value parameter initializers. If you still try to access, it throws a run-time ReferenceError(i.e, <code class=\"language-text\">inner</code> is not defined).</p>\n</p>\n</details>\n<hr>\n<h4>43. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span> <span class=\"token function\">myFun</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>manyMoreArgs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>manyMoreArgs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">myFun</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nm <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[3, 4, 5], undefined</li>\n<li>2: SyntaxError</li>\n<li>3: [3, 4, 5], []</li>\n<li>4: [3, 4, 5], [undefined]</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The rest parameter is used to hold the remaining parameters of a function and it becomes an empty array if the argument is not provided.</p>\n</p>\n</details>\n<hr>\n<h4>44. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'value'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> array <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>obj<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>['key', 'value']</li>\n<li>2: TypeError</li>\n<li>3: []</li>\n<li>4: ['key']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Spread syntax can be applied only to iterable objects. By default, Objects are not iterable, but they become iterable when used in an Array, or with iterating functions such as <code class=\"language-text\">map(), reduce(), and assign()</code>. If you still try to do it, it still throws <code class=\"language-text\">TypeError: obj is not iterable</code>.</p>\n</p>\n</details>\n<hr>\n<h4>45. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1</li>\n<li>2: undefined</li>\n<li>3: SyntaxError</li>\n<li>4: TypeError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>Generators are not constructible type. But if you still proceed to do, there will be an error saying \"TypeError: myGenFunc is not a constructor\"</p>\n</p>\n</details>\n<hr>\n<h4>46. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{ value: 1, done: false }, { value: 2, done: true }, { value: undefined, done: true }</li>\n<li>2: { value: 1, done: false }, { value: 2, done: false }, { value: undefined, done: true }</li>\n<li>3: { value: 1, done: false }, { value: 2, done: true }, { value: 3, done: true }</li>\n<li>4: { value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>A return statement in a generator function will make the generator finish. If a value is returned, it will be set as the value property of the object and done property to true. When a generator is finished, subsequent next() calls return an object of this form: <code class=\"language-text\">{value: undefined, done: true}</code>.</p>\n</p>\n</details>\n<hr>\n<h4>47. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> myGenerator <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  1,2,3 and 1,2,3\n- 2: 1,2,3 and 4,5,6\n- 3: 1 and 1\n- 4: 1\n\n&lt;details>\n&lt;summary>\n&lt;b>Answer&lt;/b>\n&lt;/summary>\n&lt;p>\n\n##### Answer: 4\n\nThe generator should not be re-used once the iterator is closed. i.e, Upon exiting a loop(on completion or using break &amp; return), the generator is closed and trying to iterate over it again does not yield any more results. Hence, the second loop doesn't print any value.\n\n&lt;/p>\n\n&lt;/details>\n\n---\n\n#### 48. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\n<span class=\"token keyword\">const</span> num <span class=\"token operator\">=</span> 0o38<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: 38</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>If you use an invalid number(outside of 0-7 range) in the octal literal, JavaScript will throw a SyntaxError. In ES5, it treats the octal literal as a decimal number.</p>\n</p>\n</details>\n<hr>\n<h4>49. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> squareObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Square</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>squareObj<span class=\"token punctuation\">.</span>area<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Square</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">length</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">set</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>area <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n- 1: 100\n- 2: ReferenceError\n\n&lt;details>\n&lt;summary>\n&lt;b>Answer&lt;/b>\n&lt;/summary>\n&lt;p>\n\n##### Answer: 2\n\nUnlike function declarations, class declarations are not hoisted. i.e, First You need to declare your class and then access it, otherwise it will throw a ReferenceError \"Uncaught ReferenceError: Square is not defined\".\n\n**Note:** Class expressions also applies to the same hoisting restrictions of class declarations.\n\n&lt;/p>\n\n&lt;/details>\n\n---\n\n#### 50. What is the output of below code\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\n<span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">walk</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nPerson<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">run</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> walk <span class=\"token operator\">=</span> user<span class=\"token punctuation\">.</span>walk<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> run <span class=\"token operator\">=</span> Person<span class=\"token punctuation\">.</span>run<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined, undefined</li>\n<li>2: Person, Person</li>\n<li>3: SyntaxError</li>\n<li>4: Window, Window</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>When a regular or prototype method is called without a value for <strong>this</strong>, the methods return an initial this value if the value is not undefined. Otherwise global window object will be returned. In our case, the initial <code class=\"language-text\">this</code> value is undefined so both methods return window objects.</p>\n</p>\n</details>\n<hr>\n<h4>51. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> vehicle started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Car</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> car started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'BMW'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: BMW vehicle started, BMW car started</li>\n<li>3: BMW car started, BMW vehicle started</li>\n<li>4: BMW car started, BMW car started</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The super keyword is used to call methods of a superclass. Unlike other languages the super invocation doesn't need to be a first statement. i.e, The statements will be executed in the same order of code.</p>\n</p>\n</details>\n<hr>\n<h4>52. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">const</span> <span class=\"token constant\">USER</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">25</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30</li>\n<li>2: 25</li>\n<li>3: Uncaught TypeError</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Even though we used constant variables, the content of it is an object and the object's contents (e.g properties) can be altered. Hence, the change is going to be valid in this case.</p>\n</p>\n</details>\n<hr>\n<h4>53. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🙂'</span> <span class=\"token operator\">===</span> <span class=\"token string\">'🙂'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Emojis are unicodes and the unicode for smile symbol is \"U+1F642\". The unicode comparision of same emojies is equivalent to string comparison. Hence, the output is always true.</p>\n</p>\n</details>\n<hr>\n<h4>54. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\">c ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>string</li>\n<li>2: boolean</li>\n<li>3: NaN</li>\n<li>4: number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The typeof operator on any primitive returns a string value. So even if you apply the chain of typeof operators on the return value, it is always string.</p>\n</p>\n</details>\n<hr>\n<h4>55. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> zero <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>zero<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'If'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Else'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n-  If\n- 2: Else\n- 3: NaN\n- 4: SyntaxError\n\n&lt;details>\n&lt;summary>\n&lt;b>Answer&lt;/b>\n&lt;/summary>\n&lt;p>\n\n##### Answer: 1\n\n1. The type of operator on new Number always returns object. i.e, typeof new Number(0) --> object.\n2. Objects are always truthy in if block\n\nHence the above code block always goes to if section.\n\n&lt;/p>\n\n&lt;/details>\n\n---\n\n#### 55. What is the output of below code in non strict mode?\n\n</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token template-punctuation string\">`</span></span>javascript\n<span class=\"token keyword\">let</span> msg <span class=\"token operator\">=</span> <span class=\"token string\">'Good morning!!'</span><span class=\"token punctuation\">;</span>\n\nmsg<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">;</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>msg<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>\"\"</li>\n<li>2: Error</li>\n<li>3: John</li>\n<li>4: Undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It returns undefined for non-strict mode and returns Error for strict mode. In non-strict mode, the wrapper object is going to be created and get the mentioned property. But the object get disappeared after accessing the property in next line.</p>\n</p>\n</details>\n<hr>\n<h4>56. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"javascript\"><pre class=\"language-javascript\"><code class=\"language-javascript\"><span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">innerFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">===</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">11</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>11, 10</li>\n<li>2: 11, 11</li>\n<li>3: 10, 11</li>\n<li>4: 10, 10</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>11 and 10 is logged to the console.</p>\n<p>The innerFunc is a closure which captures the count variable from the outerscope. i.e, 10. But the conditional has another local variable <code class=\"language-text\">count</code> which overwrites the ourter <code class=\"language-text\">count</code> variable. So the first console.log displays value 11.\nWhereas the second console.log logs 10 by capturing the count variable from outerscope.</p>\n</p>\n</details>\n<hr>\n<hr>"},{"url":"/docs/career/interview/","relativePath":"docs/career/interview.md","relativeDir":"docs/career","base":"interview.md","name":"interview","frontmatter":{"title":"Interview","weight":0,"excerpt":"Reference materials and descriptions of fundamental concepts as well as visua","seo":{"title":"Interview","description":"Job search guidance for front end web developers.","robots":[],"extra":[{"name":"og:image","value":"images/og-image.png","keyName":"property","relativeUrl":true}]},"template":"docs"},"html":"<h1>Interview:</h1>\n<iframe src=\"https://web-dev-interview-prep-quiz-website.netlify.app/\" height=\"800px\" width=\"1000px\"></iframe>\n<details>\n<summary> See JS Interview Questions </summary>\n<h2>Javascript Interview Questions</h2>\n<ol>\n<li>\n<p>What are the possible ways to create objects in JavaScript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are many ways to create objects in javascript as below\n\n1. **Object constructor:**\n\n    The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended.\n\n    ```js</code></pre></div>\n<p>//\nvar object = new Object();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    2. **Object's create method:**\n\n        The create method of Object creates a new object by passing the prototype object as a parameter\n\n        ```js\n\n//\nvar object = Object.create(null);</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">3. **Object literal syntax:**\n\n    The object literal syntax is equivalent to create method when it passes null as parameter\n\n    ```js</code></pre></div>\n<p>//\nvar object = {};</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    4. **Function constructor:**\n\n        Create any function and apply the new operator to create object instances,\n\n        ```js\n\n//\nfunction Person(name) {\nthis.name = name;\nthis.age = 21;\n}\nvar object = new Person('Sudheer');</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">5. **Function constructor with prototype:**\n\n    This is similar to function constructor but it uses prototype for their properties and methods,\n\n    ```js</code></pre></div>\n<p>//\nfunction Person() {}\nPerson.prototype.name = 'Sudheer';\nvar object = new Person();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        This is equivalent to an instance created with an object create method with a function prototype and then call that function with an instance and parameters as arguments.\n\n        ```js\n\n//\nfunction func {};\n\n        new func(x, y, z);\n        ```\n\n        **(OR)**\n\n        ```js\n\n//\n// Create a new instance using function prototype.\nvar newInstance = Object.create(func.prototype)\n\n        // Call the function\n        var result = func.call(newInstance, x, y, z),\n\n        // If the result is a non-null object then use it otherwise just use the new instance.\n        console.log(result &amp;&amp; typeof result === 'object' ? result : newInstance);\n        ```\n\n    6. **ES6 Class syntax:**\n\n        ES6 introduces class feature to create the objects\n\n        ```js\n\n//\nclass Person {\nconstructor(name) {\nthis.name = name;\n}\n}\n\n        var object = new Person('Sudheer');\n        ```\n\n    7. **Singleton pattern:**\n\n        A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance and this way one can ensure that they don't accidentally create multiple instances.\n\n        ```js\n\n//\nvar object = new (function () {\nthis.name = 'Sudheer';\n})();</code></pre></div>\n</li>\n<li>\n<p>What is a prototype chain</p>\n<p><strong>Prototype chaining</strong> is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language.</p>\n<p>The prototype on object instance is available through <strong>Object.getPrototypeOf(object)</strong> or *<strong>*proto**</strong> property whereas prototype on constructors function is available through <strong>Object.prototype</strong>.</p>\n<p><img src=\"images/prototype_chain.png\" alt=\"Screenshot\"></p>\n</li>\n<li>\n<p>What is the difference between Call, Apply and Bind</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The difference between Call, Apply and Bind can be explained with below examples,\n\n**Call:** The call() method invokes a function with a given `this` value and arguments provided one by one\n\n```js</code></pre></div>\n<p>//\nvar employee1 = { firstName: 'John', lastName: 'Rodson' };\nvar employee2 = { firstName: 'Jimmy', lastName: 'Baily' };</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName + ', ' + greeting2);\n}\n\ninvite.call(employee1, 'Hello', 'How are you?'); // Hello John Rodson, How are you?\ninvite.call(employee2, 'Hello', 'How are you?'); // Hello Jimmy Baily, How are you?\n```\n\n**Apply:** Invokes the function with a given `this` value and allows you to pass in arguments as an array\n\n```js</code></pre></div>\n<p>//\nvar employee1 = { firstName: 'John', lastName: 'Rodson' };\nvar employee2 = { firstName: 'Jimmy', lastName: 'Baily' };</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName + ', ' + greeting2);\n}\n\ninvite.apply(employee1, ['Hello', 'How are you?']); // Hello John Rodson, How are you?\ninvite.apply(employee2, ['Hello', 'How are you?']); // Hello Jimmy Baily, How are you?\n```\n\n**bind:** returns a new function, allowing you to pass any number of arguments\n\n```js</code></pre></div>\n<p>//\nvar employee1 = { firstName: 'John', lastName: 'Rodson' };\nvar employee2 = { firstName: 'Jimmy', lastName: 'Baily' };</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName + ', ' + greeting2);\n}\n\nvar inviteEmployee1 = invite.bind(employee1);\nvar inviteEmployee2 = invite.bind(employee2);\ninviteEmployee1('Hello', 'How are you?'); // Hello John Rodson, How are you?\ninviteEmployee2('Hello', 'How are you?'); // Hello Jimmy Baily, How are you?\n```\n\nCall and apply are pretty interchangeable. Both execute the current function immediately. You need to decide whether it's easier to send in an array or a comma separated list of arguments. You can remember by treating Call is for **comma** (separated list) and Apply is for **Array**.\n\nWhereas Bind creates a new function that will have `this` set to the first parameter passed to bind().</code></pre></div>\n</li>\n<li>\n<p>What is JSON and its common operations</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**JSON** is a text-based data format following JavaScript object syntax, which was popularized by `Douglas Crockford`. It is useful when you want to transmit data across a network and it is basically just a text file with an extension of .json, and a MIME type of application/json\n\n**Parsing:** Converting a string to a native object\n\n```js</code></pre></div>\n<p>//\nJSON.parse(text);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Stringification:** converting a native object to a string so it can be transmitted across the network\n\n    ```js\n\n//\nJSON.stringify(object);</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the array slice method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The **slice()** method returns the selected elements in an array as a new array object. It selects the elements starting at the given start argument, and ends at the given optional end argument without including the last element. If you omit the second argument then it selects till the end.\n\nSome of the examples of this method are,\n\n```js</code></pre></div>\n<p>//\nlet arrayIntegers = [1, 2, 3, 4, 5];\nlet arrayIntegers1 = arrayIntegers.slice(0, 2); // returns [1,2]\nlet arrayIntegers2 = arrayIntegers.slice(2, 3); // returns [3]\nlet arrayIntegers3 = arrayIntegers.slice(4); //returns [5]</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Note:** Slice method won't mutate the original array but it returns the subset as a new array.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the array splice method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The **splice()** method is used either adds/removes items to/from an array, and then returns the removed item. The first argument specifies the array position for insertion or deletion whereas the optional second argument indicates the number of elements to be deleted. Each additional argument is added to the array.\n\nSome of the examples of this method are,\n\n```js</code></pre></div>\n<p>//\nlet arrayIntegersOriginal1 = [1, 2, 3, 4, 5];\nlet arrayIntegersOriginal2 = [1, 2, 3, 4, 5];\nlet arrayIntegersOriginal3 = [1, 2, 3, 4, 5];</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let arrayIntegers1 = arrayIntegersOriginal1.splice(0, 2); // returns [1, 2]; original array: [3, 4, 5]\nlet arrayIntegers2 = arrayIntegersOriginal2.splice(3); // returns [4, 5]; original array: [1, 2, 3]\nlet arrayIntegers3 = arrayIntegersOriginal3.splice(3, 1, 'a', 'b', 'c'); //returns [4]; original array: [1, 2, 3, \"a\", \"b\", \"c\", 5]\n```\n\n**Note:** Splice method modifies the original array and returns the deleted array.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between slice and splice</p>\n<p>Some of the major difference in a tabular form</p>\n<table>\n<thead>\n<tr>\n<th>Slice</th>\n<th>Splice</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Doesn't modify the original array(immutable)</td>\n<td>Modifies the original array(mutable)</td>\n</tr>\n<tr>\n<td>Returns the subset of original array</td>\n<td>Returns the deleted elements as array</td>\n</tr>\n<tr>\n<td>Used to pick the elements from array</td>\n<td>Used to insert or delete elements to/from array</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>How do you compare Object and Map</p>\n<p><strong>Objects</strong> are similar to <strong>Maps</strong> in that both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. Due to this reason, Objects have been used as Maps historically. But there are important differences that make using a Map preferable in certain cases.</p>\n<ol>\n<li>The keys of an Object are Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive.</li>\n<li>The keys in Map are ordered while keys added to Object are not. Thus, when iterating over it, a Map object returns keys in order of insertion.</li>\n<li>You can get the size of a Map easily with the size property, while the number of properties in an Object must be determined manually.</li>\n<li>A Map is an iterable and can thus be directly iterated, whereas iterating over an Object requires obtaining its keys in some fashion and iterating over them.</li>\n<li>An Object has a prototype, so there are default keys in the map that could collide with your keys if you're not careful. As of ES5 this can be bypassed by using map = Object.create(null), but this is seldom done.</li>\n<li>A Map may perform better in scenarios involving frequent addition and removal of key pairs.</li>\n</ol>\n</li>\n<li>\n<p>What is the difference between == and === operators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison. The strict operators take type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables. The strict operators follow the below conditions for different types,\n\n1. Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.\n2. Two numbers are strictly equal when they are numerically equal. i.e, Having the same number value.\n   There are two special cases in this,\n    1. NaN is not equal to anything, including NaN.\n    2. Positive and negative zeros are equal to one another.\n3. Two Boolean operands are strictly equal if both are true or both are false.\n4. Two objects are strictly equal if they refer to the same Object.\n5. Null and Undefined types are not equal with ===, but equal with ==. i.e,\n   null===undefined --> false but null==undefined --> true\n\nSome of the example which covers the above cases,\n\n```js</code></pre></div>\n<p>//\n0 == false // true\n0 === false // false\n1 == \"1\" // true\n1 === \"1\" // false\nnull == undefined // true\nnull === undefined // false\n'0' == false // true\n'0' === false // false\n[]==[] or []===[] //false, refer different objects in memory\n{}=={} or {}==={} //false, refer different objects in memory</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are lambda or arrow functions</p>\n<p>An arrow function is a shorter syntax for a function expression and does not have its own <strong>this, arguments, super, or new.target</strong>. These functions are best suited for non-method functions, and they cannot be used as constructors.</p>\n</li>\n<li>\n<p>What is a first class function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In Javascript, functions are first class objects. First-class functions means when functions in that language are treated like any other variable.\n\nFor example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable. For example, in the below example, handler functions assigned to a listener\n\n```js</code></pre></div>\n<p>//\nconst handler = () => console.log('This is a click handler function');\ndocument.addEventListener('click', handler);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is a first order function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">First-order function is a function that doesn't accept another function as an argument and doesn't return a function as its return value.\n\n```js</code></pre></div>\n<p>//\nconst firstOrder = () => console.log('I am a first order function!');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is a higher order function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Higher-order function is a function that accepts another function as an argument or returns a function as a return value or both.\n\n```js</code></pre></div>\n<p>//\nconst firstOrderFunc = () => console.log('Hello, I am a First order function');\nconst higherOrder = (ReturnFirstOrderFunc) => ReturnFirstOrderFunc();\nhigherOrder(firstOrderFunc);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is a unary function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Unary function (i.e. monadic) is a function that accepts exactly one argument. It stands for a single argument accepted by a function.\n\nLet us take an example of unary function,\n\n```js</code></pre></div>\n<p>//\nconst unaryFunction = (a) => console.log(a + 10); // Add 10 to the given argument and display the value</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the currying function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Currying is the process of taking a function with multiple arguments and turning it into a sequence of functions each with only a single argument. Currying is named after a mathematician **Haskell Curry**. By applying currying, a n-ary function turns it into a unary function.\n\nLet's take an example of n-ary function and how it turns into a currying function,\n\n```js</code></pre></div>\n<p>//\nconst multiArgFunction = (a, b, c) => a + b + c;\nconsole.log(multiArgFunction(1, 2, 3)); // 6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const curryUnaryFunction = (a) => (b) => (c) => a + b + c;\ncurryUnaryFunction(1); // returns a function: b => c =>  1 + b + c\ncurryUnaryFunction(1)(2); // returns a function: c => 3 + c\ncurryUnaryFunction(1)(2)(3); // returns the number 6\n```\n\nCurried functions are great to improve **code reusability** and **functional composition**.</code></pre></div>\n</li>\n<li>\n<p>What is a pure function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A **Pure function** is a function where the return value is only determined by its arguments without any side effects. i.e, If you call a function with the same arguments 'n' number of times and 'n' number of places in the application then it will always return the same value.\n\nLet's take an example to see the difference between pure and impure functions,\n\n```js</code></pre></div>\n<p>//\n//Impure\nlet numberArray = [];\nconst impureAddNumber = (number) => numberArray.push(number);\n//Pure\nconst pureAddNumber = (number) => (argNumberArray) => argNumberArray.concat([number]);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">//Display the results\nconsole.log(impureAddNumber(6)); // returns 1\nconsole.log(numberArray); // returns [6]\nconsole.log(pureAddNumber(7)(numberArray)); // returns [6, 7]\nconsole.log(numberArray); // returns [6]\n```\n\nAs per above code snippets, **Push** function is impure itself by altering the array and returning an push number index which is independent of parameter value. Whereas **Concat** on the other hand takes the array and concatenates it with the other array producing a whole new array without side effects. Also, the return value is a concatenation of the previous array.\n\nRemember that Pure functions are important as they simplify unit testing without any side effects and no need for dependency injection. They also avoid tight coupling and make it harder to break your application by not having any side effects. These principles are coming together with **Immutability** concept of ES6 by giving preference to **const** over **let** usage.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the let keyword</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `let` statement declares a **block scope local variable**. Hence the variables defined with let keyword are limited in scope to the block, statement, or expression on which it is used. Whereas variables declared with the `var` keyword used to define a variable globally, or locally to an entire function regardless of block scope.\n\nLet's take an example to demonstrate the usage,\n\n```js</code></pre></div>\n<p>//\nlet counter = 30;\nif (counter === 30) {\nlet counter = 31;\nconsole.log(counter); // 31\n}\nconsole.log(counter); // 30 (because the variable in if block won't exist here)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the difference between let and var</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can list out the differences in a tabular format\n\n| var                                                   | let                         |\n|-------------------------------------------------------|-----------------------------|\n| It is been available from the beginning of JavaScript | Introduced as part of ES6   |\n| It has function scope                                 | It has block scope          |\n| Variables will be hoisted                             | Hoisted but not initialized |\n\nLet's take an example to see the difference,\n\n```js</code></pre></div>\n<p>//\nfunction userDetails(username) {\nif (username) {\nconsole.log(salary); // undefined due to hoisting\nconsole.log(age); // ReferenceError: Cannot access 'age' before initialization\nlet age = 30;\nvar salary = 10000;\n}\nconsole.log(salary); //10000 (accessible to due function scope)\nconsole.log(age); //error: age is not defined(due to block scope)\n}\nuserDetails('John');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the reason to choose the name let as a keyword</p>\n<p><code class=\"language-text\">let</code> is a mathematical statement that was adopted by early programming languages like <strong>Scheme</strong> and <strong>Basic</strong>. It has been borrowed from dozens of other languages that use <code class=\"language-text\">let</code> already as a traditional keyword as close to <code class=\"language-text\">var</code> as possible.</p>\n</li>\n<li>\n<p>How do you redeclare variables in switch block without an error</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you try to redeclare variables in a `switch block` then it will cause errors because there is only one block. For example, the below code block throws a syntax error as below,\n\n```js</code></pre></div>\n<p>//\nlet counter = 1;\nswitch (x) {\ncase 0:\nlet name;\nbreak;</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    case 1:\n        let name; // SyntaxError for redeclaration.\n        break;\n}\n```\n\nTo avoid this error, you can create a nested block inside a case clause and create a new block scoped lexical environment.\n\n```js</code></pre></div>\n<p>//\nlet counter = 1;\nswitch (x) {\ncase 0: {\nlet name;\nbreak;\n}\ncase 1: {\nlet name; // No SyntaxError for redeclaration.\nbreak;\n}\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the Temporal Dead Zone</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Temporal Dead Zone is a behavior in JavaScript that occurs when declaring a variable with the let and const keywords, but not with var. In ECMAScript 6, accessing a `let` or `const` variable before its declaration (within its scope) causes a ReferenceError. The time span when that happens, between the creation of a variable's binding and its declaration, is called the temporal dead zone.\n\nLet's see this behavior with an example,\n\n```js</code></pre></div>\n<p>//\nfunction somemethod() {\nconsole.log(counter1); // undefined\nconsole.log(counter2); // ReferenceError\nvar counter1 = 1;\nlet counter2 = 2;\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is IIFE(Immediately Invoked Function Expression)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. The signature of it would be as below,\n\n```js</code></pre></div>\n<p>//\n(function () {\n// logic here\n})();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    The primary reason to use an IIFE is to obtain data privacy because any variables declared within the IIFE cannot be accessed by the outside world. i.e, If you try to access variables with IIFE then it throws an error as below,\n\n    ```js\n\n//\n(function () {\nvar message = 'IIFE';\nconsole.log(message);\n})();\nconsole.log(message); //Error: message is not defined</code></pre></div>\n</li>\n<li>\n<p>What is the benefit of using modules</p>\n<p>There are a lot of benefits to using modules in favour of a sprawling. Some of the benefits are,</p>\n<ol>\n<li>Maintainability</li>\n<li>Reusability</li>\n<li>Namespacing</li>\n</ol>\n</li>\n<li>\n<p>What is memoization</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Memoization is a programming technique which attempts to increase a function's performance by caching its previously computed results. Each time a memoized function is called, its parameters are used to index the cache. If the data is present, then it can be returned, without executing the entire function. Otherwise the function is executed and then the result is added to the cache.\nLet's take an example of adding function with memoization,\n\n```js</code></pre></div>\n<p>//\nconst memoizAddition = () => {\nlet cache = {};\nreturn (value) => {\nif (value in cache) {\nconsole.log('Fetching from cache');\nreturn cache[value]; // Here, cache.value cannot be used as property name starts with the number which is not a valid JavaScript identifier. Hence, can only be accessed using the square bracket notation.\n} else {\nconsole.log('Calculating result');\nlet result = value + 20;\ncache[value] = result;\nreturn result;\n}\n};\n};\n// returned function from memoizAddition\nconst addition = memoizAddition();\nconsole.log(addition(20)); //output: 40 calculated\nconsole.log(addition(20)); //output: 40 cached</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is Hoisting</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Remember that JavaScript only hoists declarations, not initialisation.\nLet's take a simple example of variable hoisting,\n\n```js</code></pre></div>\n<p>//\nconsole.log(message); //output : undefined\nvar message = 'The variable Has been hoisted';</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    The above code looks like as below to the interpreter,\n\n    ```js\n\n//\nvar message;\nconsole.log(message);\nmessage = 'The variable Has been hoisted';</code></pre></div>\n</li>\n<li>\n<p>What are classes in ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In ES6, Javascript classes are primarily syntactic sugar over JavaScript's existing prototype-based inheritance.\nFor example, the prototype based inheritance written in function expression as below,\n\n```js</code></pre></div>\n<p>//\nfunction Bike(model, color) {\nthis.model = model;\nthis.color = color;\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Bike.prototype.getDetails = function () {\n    return this.model + ' bike has' + this.color + ' color';\n};\n```\n\nWhereas ES6 classes can be defined as an alternative\n\n```js</code></pre></div>\n<p>//\nclass Bike {\nconstructor(color, model) {\nthis.color = color;\nthis.model = model;\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    getDetails() {\n        return this.model + ' bike has' + this.color + ' color';\n    }\n}\n```</code></pre></div>\n</li>\n<li>\n<p>What are closures</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A closure is the combination of a function and the lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function's variables. The closure has three scope chains\n\n1. Own scope where variables defined between its curly brackets\n2. Outer function's variables\n3. Global variables\n\nLet's take an example of closure concept,\n\n```js</code></pre></div>\n<p>//\nfunction Welcome(name) {\nvar greetingInfo = function (message) {\nconsole.log(message + ' ' + name);\n};\nreturn greetingInfo;\n}\nvar myFunction = Welcome('John');\nmyFunction('Welcome '); //Output: Welcome John\nmyFunction('Hello Mr.'); //output: Hello Mr.John</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    As per the above code, the inner function(i.e, greetingInfo) has access to the variables in the outer function scope(i.e, Welcome) even after the outer function has returned.</code></pre></div>\n</li>\n<li>\n<p>What are modules</p>\n<p>Modules refer to small units of independent, reusable code and also act as the foundation of many JavaScript design patterns. Most of the JavaScript modules export an object literal, a function, or a constructor</p>\n</li>\n<li>\n<p>Why do you need modules</p>\n<p>Below are the list of benefits using modules in javascript ecosystem</p>\n<ol>\n<li>Maintainability</li>\n<li>Reusability</li>\n<li>Namespacing</li>\n</ol>\n</li>\n<li>\n<p>What is scope in javascript</p>\n<p>Scope is the accessibility of variables, functions, and objects in some particular part of your code during runtime. In other words, scope determines the visibility of variables and other resources in areas of your code.</p>\n</li>\n<li>\n<p>What is a service worker</p>\n<p>A Service worker is basically a script (JavaScript file) that runs in the background, separate from a web page and provides features that don't need a web page or user interaction. Some of the major features of service workers are Rich offline experiences(offline first web application development), periodic background syncs, push notifications, intercept and handle network requests and programmatically managing a cache of responses.</p>\n</li>\n<li>\n<p>How do you manipulate DOM using a service worker</p>\n<p>Service worker can't access the DOM directly. But it can communicate with the pages it controls by responding to messages sent via the <code class=\"language-text\">postMessage</code> interface, and those pages can manipulate the DOM.</p>\n</li>\n<li>\n<p>How do you reuse information across service worker restarts</p>\n<p>The problem with service worker is that it gets terminated when not in use, and restarted when it's next needed, so you cannot rely on global state within a service worker's <code class=\"language-text\">onfetch</code> and <code class=\"language-text\">onmessage</code> handlers. In this case, service workers will have access to IndexedDB API in order to persist and reuse across restarts.</p>\n</li>\n<li>\n<p>What is IndexedDB</p>\n<p>IndexedDB is a low-level API for client-side storage of larger amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data.</p>\n</li>\n<li>\n<p>What is web storage</p>\n<p>Web storage is an API that provides a mechanism by which browsers can store key/value pairs locally within the user's browser, in a much more intuitive fashion than using cookies. The web storage provides two mechanisms for storing data on the client.</p>\n<ol>\n<li><strong>Local storage:</strong> It stores data for current origin with no expiration date.</li>\n<li><strong>Session storage:</strong> It stores data for one session and the data is lost when the browser tab is closed.</li>\n</ol>\n</li>\n<li>\n<p>What is a post message</p>\n<p>Post message is a method that enables cross-origin communication between Window objects.(i.e, between a page and a pop-up that it spawned, or between a page and an iframe embedded within it). Generally, scripts on different pages are allowed to access each other if and only if the pages follow same-origin policy(i.e, pages share the same protocol, port number, and host).</p>\n</li>\n<li>\n<p>What is a Cookie</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A cookie is a piece of data that is stored on your computer to be accessed by your browser. Cookies are saved as key/value pairs.\nFor example, you can create a cookie named username as below,\n\n```js</code></pre></div>\n<p>//\ndocument.cookie = 'username=John';</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    ![Screenshot](images/cookie.png)</code></pre></div>\n</li>\n<li>\n<p>Why do you need a Cookie</p>\n<p>Cookies are used to remember information about the user profile(such as username). It basically involves two steps,</p>\n<ol>\n<li>When a user visits a web page, the user profile can be stored in a cookie.</li>\n<li>Next time the user visits the page, the cookie remembers the user profile.</li>\n</ol>\n</li>\n<li>\n<p>What are the options in a cookie</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are few below options available for a cookie,\n\n1. By default, the cookie is deleted when the browser is closed but you can change this behavior by setting expiry date (in UTC time).\n\n```js</code></pre></div>\n<p>//\ndocument.cookie = 'username=John; expires=Sat, 8 Jun 2019 12:00:00 UTC';</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    1. By default, the cookie belongs to a current page. But you can tell the browser what path the cookie belongs to using a path parameter.\n\n    ```js\n\n//\ndocument.cookie = 'username=John; path=/services';</code></pre></div>\n</li>\n<li>\n<p>How do you delete a cookie</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can delete a cookie by setting the expiry date as a passed date. You don't need to specify a cookie value in this case.\nFor example, you can delete a username cookie in the current page as below.\n\n```js</code></pre></div>\n<p>//\ndocument.cookie = 'username=; expires=Fri, 07 Jun 2019 00:00:00 UTC; path=/;';</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Note:** You should define the cookie path option to ensure that you delete the right cookie. Some browsers doesn't allow to delete a cookie unless you specify a path parameter.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between cookie, local storage and session storage</p>\n<p>Below are some of the differences between cookie, local storage and session storage,</p>\n<table>\n<thead>\n<tr>\n<th>Feature</th>\n<th>Cookie</th>\n<th>Local storage</th>\n<th>Session storage</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Accessed on client or server side</td>\n<td>Both server-side &#x26; client-side</td>\n<td>client-side only</td>\n<td>client-side only</td>\n</tr>\n<tr>\n<td>Lifetime</td>\n<td>As configured using Expires option</td>\n<td>until deleted</td>\n<td>until tab is closed</td>\n</tr>\n<tr>\n<td>SSL support</td>\n<td>Supported</td>\n<td>Not supported</td>\n<td>Not supported</td>\n</tr>\n<tr>\n<td>Maximum data size</td>\n<td>4KB</td>\n<td>5 MB</td>\n<td>5MB</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What is the main difference between localStorage and sessionStorage</p>\n<p>LocalStorage is the same as SessionStorage but it persists the data even when the browser is closed and reopened(i.e it has no expiration time) whereas in sessionStorage data gets cleared when the page session ends.</p>\n</li>\n<li>\n<p>How do you access web storage</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Window object implements the `WindowLocalStorage` and `WindowSessionStorage` objects which has `localStorage`(window.localStorage) and `sessionStorage`(window.sessionStorage) properties respectively. These properties create an instance of the Storage object, through which data items can be set, retrieved and removed for a specific domain and storage type (session or local).\nFor example, you can read and write on local storage objects as below\n\n```js</code></pre></div>\n<p>//\nlocalStorage.setItem('logo', document.getElementById('logo').value);\nlocalStorage.getItem('logo');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are the methods available on session storage</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The session storage provided methods for reading, writing and clearing the session data\n\n```js</code></pre></div>\n<p>//\n// Save data to sessionStorage\nsessionStorage.setItem('key', 'value');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Get saved data from sessionStorage\nlet data = sessionStorage.getItem('key');\n\n// Remove saved data from sessionStorage\nsessionStorage.removeItem('key');\n\n// Remove all saved data from sessionStorage\nsessionStorage.clear();\n```</code></pre></div>\n</li>\n<li>\n<p>What is a storage event and its event handler</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events.\nThe syntax would be as below\n\n```js</code></pre></div>\n<p>//\nwindow.onstorage = functionRef;</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    Let's take the example usage of onstorage event handler which logs the storage key and it's values\n\n    ```js\n\n//\nwindow.onstorage = function (e) {\nconsole.log('The ' + e.key + ' key has been changed from ' + e.oldValue + ' to ' + e.newValue + '.');\n};</code></pre></div>\n</li>\n<li>\n<p>Why do you need web storage</p>\n<p>Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Also, the information is never transferred to the server. Hence this is a more recommended approach than Cookies.</p>\n</li>\n<li>\n<p>How do you check web storage browser support</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to check browser support for localStorage and sessionStorage before using web storage,\n\n```js</code></pre></div>\n<p>//\nif (typeof Storage !== 'undefined') {\n// Code for localStorage/sessionStorage.\n} else {\n// Sorry! No Web Storage support..\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>How do you check web workers browser support</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to check browser support for web workers before using it\n\n```js</code></pre></div>\n<p>//\nif (typeof Worker !== 'undefined') {\n// code for Web worker support.\n} else {\n// Sorry! No Web Worker support..\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>Give an example of a web worker</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You need to follow below steps to start using web workers for counting example\n\n1. Create a Web Worker File: You need to write a script to increment the count value. Let's name it as counter.js\n\n```js</code></pre></div>\n<p>//\nlet i = 0;</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function timedCount() {\n    i = i + 1;\n    postMessage(i);\n    setTimeout('timedCount()', 500);\n}\n\ntimedCount();\n```\n\nHere postMessage() method is used to post a message back to the HTML page\n\n1. Create a Web Worker Object: You can create a web worker object by checking for browser support. Let's name this file as web_worker_example.js\n\n```js</code></pre></div>\n<p>//\nif (typeof w == 'undefined') {\nw = new Worker('counter.js');\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    and we can receive messages from web worker\n\n    ```js\n\n//\nw.onmessage = function (event) {\ndocument.getElementById('message').innerHTML = event.data;\n};</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. Terminate a Web Worker:\n   Web workers will continue to listen for messages (even after the external script is finished) until it is terminated. You can use the terminate() method to terminate listening to the messages.\n\n```js</code></pre></div>\n<p>//\nw.terminate();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    1. Reuse the Web Worker: If you set the worker variable to undefined you can reuse the code\n\n    ```js\n\n//\nw = undefined;</code></pre></div>\n</li>\n<li>\n<p>What are the restrictions of web workers on DOM</p>\n<p>WebWorkers don't have access to below javascript objects since they are defined in an external files</p>\n<ol>\n<li>Window object</li>\n<li>Document object</li>\n<li>Parent object</li>\n</ol>\n</li>\n<li>\n<p>What is a promise</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A promise is an object that may produce a single value some time in the future with either a resolved value or a reason that it's not resolved(for example, network error). It will be in one of the 3 possible states: fulfilled, rejected, or pending.\n\nThe syntax of Promise creation looks like below,\n\n```js</code></pre></div>\n<p>//\nconst promise = new Promise(function (resolve, reject) {\n// promise description\n});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    The usage of a promise would be as below,\n\n    ```js\n\n//\nconst promise = new Promise(\n(resolve) => {\nsetTimeout(() => {\nresolve(\"I'm a Promise!\");\n}, 5000);\n},\n(reject) => {}\n);\n\n    promise.then((value) => console.log(value));\n    ```\n\n    The action flow of a promise will be as below,\n\n    ![Screenshot](images/promises.png)</code></pre></div>\n</li>\n<li>\n<p>Why do you need a promise</p>\n<p>Promises are used to handle asynchronous operations. They provide an alternative approach for callbacks by reducing the callback hell and writing the cleaner code.</p>\n</li>\n<li>\n<p>What are the three states of promise</p>\n<p>Promises have three states:</p>\n<ol>\n<li><strong>Pending:</strong> This is an initial state of the Promise before an operation begins</li>\n<li><strong>Fulfilled:</strong> This state indicates that the specified operation was completed.</li>\n<li><strong>Rejected:</strong> This state indicates that the operation did not complete. In this case an error value will be thrown.</li>\n</ol>\n</li>\n<li>\n<p>What is a callback function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action.\nLet's take a simple example of how to use callback function\n\n```js</code></pre></div>\n<p>//\nfunction callbackFunction(name) {\nconsole.log('Hello ' + name);\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function outerFunction(callback) {\n    let name = prompt('Please enter your name.');\n    callback(name);\n}\n\nouterFunction(callbackFunction);\n```</code></pre></div>\n</li>\n<li>\n<p>Why do we need callbacks</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The callbacks are needed because javascript is an event driven language. That means instead of waiting for a response javascript will keep executing while listening for other events.\nLet's take an example with the first function invoking an API call(simulated by setTimeout) and the next function which logs the message.\n\n```js</code></pre></div>\n<p>//\nfunction firstFunction() {\n// Simulate a code delay\nsetTimeout(function () {\nconsole.log('First function called');\n}, 1000);\n}\nfunction secondFunction() {\nconsole.log('Second function called');\n}\nfirstFunction();\nsecondFunction();</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Output;\n// Second function called\n// First function called\n```\n\nAs observed from the output, javascript didn't wait for the response of the first function and the remaining code block got executed. So callbacks are used in a way to make sure that certain code doesn't execute until the other code finishes execution.</code></pre></div>\n</li>\n<li>\n<p>What is a callback hell</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Callback Hell is an anti-pattern with multiple nested callbacks which makes code hard to read and debug when dealing with asynchronous logic. The callback hell looks like below,\n\n```js</code></pre></div>\n<p>//\nasync1(function(){\nasync2(function(){\nasync3(function(){\nasync4(function(){\n....\n});\n});\n});\n});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are server-sent events</p>\n<p>Server-sent events (SSE) is a server push technology enabling a browser to receive automatic updates from a server via HTTP connection without resorting to polling. These are a one way communications channel - events flow from server to client only. This has been used in Facebook/Twitter updates, stock price updates, news feeds etc.</p>\n</li>\n<li>\n<p>How do you receive server-sent event notifications</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The EventSource object is used to receive server-sent event notifications. For example, you can receive messages from server as below,\n\n```js</code></pre></div>\n<p>//\nif (typeof EventSource !== 'undefined') {\nvar source = new EventSource('sse_generator.js');\nsource.onmessage = function (event) {\ndocument.getElementById('output').innerHTML += event.data + '<br>';\n};\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>How do you check browser support for server-sent events</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can perform browser support for server-sent events before using it as below,\n\n```js</code></pre></div>\n<p>//\nif (typeof EventSource !== 'undefined') {\n// Server-sent events supported. Let's have some code here!\n} else {\n// No server-sent events supported\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are the events available for server sent events</p>\n<p>Below are the list of events available for server sent events\n| Event | Description |\n|---- | ---------\n| onopen | It is used when a connection to the server is opened |\n| onmessage | This event is used when a message is received |\n| onerror | It happens when an error occurs|</p>\n</li>\n<li>\n<p>What are the main rules of promise</p>\n<p>A promise must follow a specific set of rules,</p>\n<ol>\n<li>A promise is an object that supplies a standard-compliant <code class=\"language-text\">.then()</code> method</li>\n<li>A pending promise may transition into either fulfilled or rejected state</li>\n<li>A fulfilled or rejected promise is settled and it must not transition into any other state.</li>\n<li>Once a promise is settled, the value must not change.</li>\n</ol>\n</li>\n<li>\n<p>What is callback in callback</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can nest one callback inside in another callback to execute the actions sequentially one by one. This is known as callbacks in callbacks.\n\n```js</code></pre></div>\n<p>//\nloadScript('/script1.js', function (script) {\nconsole.log('first script is loaded');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    loadScript('/script2.js', function (script) {\n        console.log('second script is loaded');\n\n        loadScript('/script3.js', function (script) {\n            console.log('third script is loaded');\n            // after all scripts are loaded\n        });\n    });\n});\n```</code></pre></div>\n</li>\n<li>\n<p>What is promise chaining</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The process of executing a sequence of asynchronous tasks one after another using promises is known as Promise chaining. Let's take an example of promise chaining for calculating the final result,\n\n```js</code></pre></div>\n<p>//\nnew Promise(function (resolve, reject) {\nsetTimeout(() => resolve(1), 1000);\n})\n.then(function (result) {\nconsole.log(result); // 1\nreturn result _ 2;\n})\n.then(function (result) {\nconsole.log(result); // 2\nreturn result _ 3;\n})\n.then(function (result) {\nconsole.log(result); // 6\nreturn result * 4;\n});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    In the above handlers, the result is passed to the chain of .then() handlers with the below work flow,\n\n    1. The initial promise resolves in 1 second,\n    2. After that `.then` handler is called by logging the result(1) and then return a promise with the value of result \\* 2.\n    3. After that the value passed to the next `.then` handler by logging the result(2) and return a promise with result \\* 3.\n    4. Finally the value passed to the last `.then` handler by logging the result(6) and return a promise with result \\* 4.</code></pre></div>\n</li>\n<li>\n<p>What is promise.all</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.all is a promise that takes an array of promises as an input (an iterable), and it gets resolved when all the promises get resolved or any one of them gets rejected. For example, the syntax of promise.all method is below,\n\n```js</code></pre></div>\n<p>//\nPromise.all([Promise1, Promise2, Promise3]) .then(result) => { console.log(result) }) .catch(error => console.log(<code class=\"language-text\">Error in promises ${error}</code>))</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Note:** Remember that the order of the promises(output the result) is maintained as per input order.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the race method in promise</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.race() method will return the promise instance which is firstly resolved or rejected. Let's take an example of race() method where promise2 is resolved first\n\n```js</code></pre></div>\n<p>//\nvar promise1 = new Promise(function (resolve, reject) {\nsetTimeout(resolve, 500, 'one');\n});\nvar promise2 = new Promise(function (resolve, reject) {\nsetTimeout(resolve, 100, 'two');\n});</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Promise.race([promise1, promise2]).then(function (value) {\n    console.log(value); // \"two\" // Both promises will resolve, but promise2 is faster\n});\n```</code></pre></div>\n</li>\n<li>\n<p>What is a strict mode in javascript</p>\n<p>Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a \"strict\" operating context. This way it prevents certain actions from being taken and throws more exceptions. The literal expression <code class=\"language-text\">\"use strict\";</code> instructs the browser to use the javascript code in the Strict mode.</p>\n</li>\n<li>\n<p>Why do you need strict mode</p>\n<p>Strict mode is useful to write \"secure\" JavaScript by notifying \"bad syntax\" into real errors. For example, it eliminates accidentally creating a global variable by throwing an error and also throws an error for assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object.</p>\n</li>\n<li>\n<p>How do you declare strict mode</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The strict mode is declared by adding \"use strict\"; to the beginning of a script or a function.\nIf declared at the beginning of a script, it has global scope.\n\n```js</code></pre></div>\n<p>//\n'use strict';\nx = 3.14; // This will cause an error because x is not declared</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    and if you declare inside a function, it has local scope\n\n    ```js\n\n//\nx = 3.14; // This will not cause an error.\nmyFunction();\n\n    function myFunction() {\n        'use strict';\n        y = 3.14; // This will cause an error\n    }\n    ```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of double exclamation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The double exclamation or negation(!!) ensures the resulting type is a boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.\nFor example, you can test IE version using this expression as below,\n\n```js</code></pre></div>\n<p>//\nlet isIE8 = false;\nisIE8 = !!navigator.userAgent.match(/MSIE 8.0/);\nconsole.log(isIE8); // returns true or false</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    If you don't use this expression then it returns the original value.\n\n    ```js\n\n//\nconsole.log(navigator.userAgent.match(/MSIE 8.0/)); // returns either an Array or null</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**Note:** The expression !! is not an operator, but it is just twice of ! operator.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of the delete operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The delete keyword is used to delete the property as well as its value.\n\n```js</code></pre></div>\n<p>//\nvar user = { name: 'John', age: 20 };\ndelete user.age;</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(user); // {name: \"John\"}\n```</code></pre></div>\n</li>\n<li>\n<p>What is the typeof operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can use the JavaScript typeof operator to find the type of a JavaScript variable. It returns the type of a variable or an expression.\n\n```js</code></pre></div>\n<p>//\ntypeof 'John Abraham'; // Returns \"string\"\ntypeof (1 + 2); // Returns \"number\"</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is undefined property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The undefined property indicates that a variable has not been assigned a value, or not declared at all. The type of undefined value is undefined too.\n\n```js</code></pre></div>\n<p>//\nvar user; // Value is undefined, type is undefined\nconsole.log(typeof user); //undefined</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    Any variable can be emptied by setting the value to undefined.\n\n    ```js\n\n//\nuser = undefined;</code></pre></div>\n</li>\n<li>\n<p>What is null value</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values. The type of null value is object.\nYou can empty the variable by setting the value to null.\n\n```js</code></pre></div>\n<p>//\nvar user = null;\nconsole.log(typeof user); //object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the difference between null and undefined</p>\n<p>Below are the main differences between null and undefined,</p>\n<table>\n<thead>\n<tr>\n<th>Null</th>\n<th>Undefined</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is an assignment value which indicates that variable points to no object.</td>\n<td>It is not an assignment value where a variable has been declared but has not yet been assigned a value.</td>\n</tr>\n<tr>\n<td>Type of null is object</td>\n<td>Type of undefined is undefined</td>\n</tr>\n<tr>\n<td>The null value is a primitive value that represents the null, empty, or non-existent reference.</td>\n<td>The undefined value is a primitive value used when a variable has not been assigned a value.</td>\n</tr>\n<tr>\n<td>Indicates the absence of a value for a variable</td>\n<td>Indicates absence of variable itself</td>\n</tr>\n<tr>\n<td>Converted to zero (0) while performing primitive operations</td>\n<td>Converted to NaN while performing primitive operations</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What is eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The eval() function evaluates JavaScript code represented as a string. The string can be a JavaScript expression, variable, statement, or sequence of statements.\n\n```js</code></pre></div>\n<p>//\nconsole.log(eval('1 + 2')); // 3</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the difference between window and document</p>\n<p>Below are the main differences between window and document,</p>\n<table>\n<thead>\n<tr>\n<th>Window</th>\n<th>Document</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>It is the root level element in any web page</td>\n<td>It is the direct child of the window object. This is also known as Document Object Model(DOM)</td>\n</tr>\n<tr>\n<td>By default window object is available implicitly in the page</td>\n<td>You can access it via window.document or document.</td>\n</tr>\n<tr>\n<td>It has methods like alert(), confirm() and properties like document, location</td>\n<td>It provides methods like getElementById, getElementsByTagName, createElement etc</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>How do you access history in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The window.history object contains the browser's history. You can load previous and next URLs in the history using back() and next() methods.\n\n```js</code></pre></div>\n<p>//\nfunction goBack() {\nwindow.history.back();\n}\nfunction goForward() {\nwindow.history.forward();\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    **Note:** You can also access history without window prefix.</code></pre></div>\n</li>\n<li>\n<p>How do you detect caps lock key turned on or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The `mouseEvent getModifierState()` is used to return a boolean value that indicates whether the specified modifier key is activated or not. The modifiers such as CapsLock, ScrollLock and NumLock are activated when they are clicked, and deactivated when they are clicked again.\n\nLet's take an input element to detect the CapsLock on/off behavior with an example,\n\n```html\n&lt;input type=\"password\" onmousedown=\"enterInput(event)\" />\n\n&lt;p id=\"feedback\"></code></pre></div>\n</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;script>\n    function enterInput(e) {\n        var flag = e.getModifierState('CapsLock');\n        if (flag) {\n            document.getElementById('feedback').innerHTML = 'CapsLock activated';\n        } else {\n            document.getElementById('feedback').innerHTML = 'CapsLock not activated';\n        }\n    }\n&lt;/script>\n```</code></pre></div>\n</li>\n<li>\n<p>What is isNaN</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The isNaN() function is used to determine whether a value is an illegal number (Not-a-Number) or not. i.e, This function returns true if the value equates to NaN. Otherwise it returns false.\n\n```js</code></pre></div>\n<p>//\nisNaN('Hello'); //true\nisNaN('100'); //false</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are the differences between undeclared and undefined variables</p>\n<p>Below are the major differences between undeclared and undefined variables,</p>\n<table>\n<thead>\n<tr>\n<th>undeclared</th>\n<th>undefined</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>These variables do not exist in a program and are not declared</td>\n<td>These variables declared in the program but have not assigned any value</td>\n</tr>\n<tr>\n<td>If you try to read the value of an undeclared variable, then a runtime error is encountered</td>\n<td>If you try to read the value of an undefined variable, an undefined value is returned.</td>\n</tr>\n</tbody>\n</table>\n</li>\n<li>\n<p>What are global variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Global variables are those that are available throughout the length of the code without any scope. The var keyword is used to declare a local variable but if you omit it then it will become global variable\n\n```js</code></pre></div>\n<p>//\nmsg = 'Hello'; // var is missing, it becomes global variable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What are the problems with global variables</p>\n<p>The problem with global variables is the conflict of variable names of local and global scope. It is also difficult to debug and test the code that relies on global variables.</p>\n</li>\n<li>\n<p>What is NaN property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The NaN property is a global property that represents \"Not-a-Number\" value. i.e, It indicates that a value is not a legal number. It is very rare to use NaN in a program but it can be used as return value for few cases\n\n```js</code></pre></div>\n<p>//\nMath.sqrt(-1);\nparseInt('Hello');</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the purpose of isFinite function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The isFinite() function is used to determine whether a number is a finite, legal number. It returns false if the value is +infinity, -infinity, or NaN (Not-a-Number), otherwise it returns true.\n\n```js</code></pre></div>\n<p>//\nisFinite(Infinity); // false\nisFinite(NaN); // false\nisFinite(-Infinity); // false</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">isFinite(100); // true\n```</code></pre></div>\n</li>\n<li>\n<p>What is an event flow</p>\n<p>Event flow is the order in which event is received on the web page. When you click an element that is nested in various other elements, before your click actually reaches its destination, or target element, it must trigger the click event for each of its parent elements first, starting at the top with the global window object.\nThere are two ways of event flow</p>\n<ol>\n<li>Top to Bottom(Event Capturing)</li>\n<li>Bottom to Top (Event Bubbling)</li>\n</ol>\n</li>\n<li>\n<p>What is event bubbling</p>\n<p>Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors (parents) of the target element in the same nesting hierarchy till it reaches the outermost DOM element.</p>\n</li>\n<li>\n<p>What is event capturing</p>\n<p>Event capturing is a type of event propagation where the event is first captured by the outermost element, and then successively triggers on the descendants (children) of the target element in the same nesting hierarchy till it reaches the innermost DOM element.</p>\n</li>\n<li>\n<p>How do you submit a form using JavaScript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can submit a form using `document.forms[0].submit()`. All the form input's information is submitted using onsubmit event handler\n\n```js</code></pre></div>\n<p>//\nfunction submit() {\ndocument.forms[0].submit();\n}</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>How do you find operating system details</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The window.navigator object contains information about the visitor's browser OS details. Some of the OS properties are available under platform property,\n\n```js</code></pre></div>\n<p>//\nconsole.log(navigator.platform);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is the difference between document load and DOMContentLoaded events</p>\n<p>The <code class=\"language-text\">DOMContentLoaded</code> event is fired when the initial HTML document has been completely loaded and parsed, without waiting for assets(stylesheets, images, and subframes) to finish loading. Whereas The load event is fired when the whole page has loaded, including all dependent resources(stylesheets, images).</p>\n</li>\n<li>\n<p>What is the difference between native, host and user objects</p>\n<p><code class=\"language-text\">Native objects</code> are objects that are part of the JavaScript language defined by the ECMAScript specification. For example, String, Math, RegExp, Object, Function etc core objects defined in the ECMAScript spec.\n<code class=\"language-text\">Host objects</code> are objects provided by the browser or runtime environment (Node). For example, window, XmlHttpRequest, DOM nodes etc are considered as host objects.\n<code class=\"language-text\">User objects</code> are objects defined in the javascript code. For example, User objects created for profile information.</p>\n</li>\n<li>\n<p>What are the tools or techniques used for debugging JavaScript code</p>\n<p>You can use below tools or techniques for debugging javascript</p>\n<ol>\n<li>Chrome Devtools</li>\n<li>debugger statement</li>\n<li>Good old console.log statement</li>\n</ol>\n</li>\n<li>\n<p>What are the pros and cons of promises over callbacks</p>\n<p>Below are the list of pros and cons of promises over callbacks,</p>\n<p><strong>Pros:</strong></p>\n<ol>\n<li>It avoids callback hell which is unreadable</li>\n<li>Easy to write sequential asynchronous code with .then()</li>\n<li>Easy to write parallel asynchronous code with Promise.all()</li>\n<li>Solves some of the common problems of callbacks(call the callback too late, too early, many times and swallow errors/exceptions)</li>\n</ol>\n<p><strong>Cons:</strong></p>\n<ol>\n<li>It makes little complex code</li>\n<li>You need to load a polyfill if ES6 is not supported</li>\n</ol>\n</li>\n<li>\n<p>What is the difference between an attribute and a property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Attributes are defined on the HTML markup whereas properties are defined on the DOM. For example, the below HTML element has 2 attributes type and value,\n\n```js</code></pre></div>\n<p>//\n<input type=\"text\" value=\"Name:\"></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    You can retrieve the attribute value as below,\n\n    ```js\n\n//\nconst input = document.querySelector('input');\nconsole.log(input.getAttribute('value')); // Good morning\nconsole.log(input.value); // Good morning</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">And after you change the value of the text field to \"Good evening\", it becomes like\n\n```js</code></pre></div>\n<p>//\nconsole.log(input.getAttribute('value')); // Good morning\nconsole.log(input.value); // Good evening</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>What is same-origin policy</p>\n<p>The same-origin policy is a policy that prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of URI scheme, hostname, and port number. If you enable this policy then it prevents a malicious script on one page from obtaining access to sensitive data on another web page using Document Object Model(DOM).</p>\n</li>\n<li>\n<p>What is the purpose of void 0</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Void(0) is used to prevent the page from refreshing. This will be helpful to eliminate the unwanted side-effect, because it will return the undefined primitive value. It is commonly used for HTML documents that use href=\"JavaScript:Void(0);\" within an `&lt;a>` element. i.e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression.\nFor example, the below link notify the message without reloading the page\n\n```js</code></pre></div>\n<p>//\n<a href=\"JavaScript:void(0);\" onclick=\"alert('Well done!')\">\nClick Me!\n</a></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"></code></pre></div>\n</li>\n<li>\n<p>Is JavaScript a compiled or interpreted language</p>\n<p>JavaScript is an interpreted language, not a compiled language. An interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. Nowadays modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.</p>\n</li>\n<li>\n<p>Is JavaScript a case-sensitive language</p>\n<p>Yes, JavaScript is a case sensitive language. The language keywords, variables, function &#x26; object names, and any other identifiers must always be typed with a consistent capitalization of letters.</p>\n</li>\n<li>\n<p>Is there any relation between Java and JavaScript</p>\n<p>No, they are entirely two different programming languages and have nothing to do with each other. But both of them are Object Oriented Programming languages and like many other languages, they follow similar syntax for basic features(if, else, for, switch, break, continue etc).</p>\n</li>\n<li>\n<p>What are events</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Events are \"things\" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can `react` on these events. Some of the examples of HTML events are,\n\n     1. Web page has finished loading\n     2. Input field was changed\n     3. Button was clicked\n\n     Let's describe the behavior of click event for button element,\n\n     ```js\n\n//\n&lt;!doctype html>\n&lt;html>\n&lt;head>\n&lt;script>\nfunction greeting() {\nalert('Hello! Good morning');\n}\n&lt;/script>\n&lt;/head>\n&lt;body>\n&lt;button type=\"button\" onclick=\"greeting()\">Click me&lt;/button>\n&lt;/body>\n&lt;/html>\n```</code></pre></div>\n</li>\n<li>\n<p>Who created javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript was created by Brendan Eich in 1995 during his time at Netscape Communications. Initially it was developed under the name `Mocha`, but later the language was officially called `LiveScript` when it first shipped in beta releases of Netscape.</code></pre></div>\n</li>\n<li>\n<p>What is the use of preventDefault method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The preventDefault() method cancels the event if it is cancelable, meaning that the default action or behaviour that belongs to the event will not occur. For example, prevent form submission when clicking on submit button and prevent opening the page URL when clicking on hyperlink are some common use cases.\n\n     ```js\n\n//\ndocument.getElementById('link').addEventListener('click', function (event) {\nevent.preventDefault();\n});\n\n```\n\n     **Note:** Remember that not all events are cancelable.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the use of stopPropagation method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The stopPropagation method is used to stop the event from bubbling up the event chain. For example, the below nested divs with stopPropagation method prevents default event propagation when clicking on nested div(Div1)\n\n     ```js\n\n//\n&lt;p>Click DIV1 Element&lt;/p>\n&lt;div onclick=\"secondFunc()\">DIV 2\n&lt;div onclick=\"firstFunc(event)\">DIV 1&lt;/div>\n&lt;/div>\n\n     &lt;script>\n     function firstFunc(event) {\n       alert(\"DIV 1\");\n       event.stopPropagation();\n     }\n\n     function secondFunc() {\n       alert(\"DIV 2\");\n     }\n     &lt;/script>\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the steps involved in return false usage</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The return false statement in event handlers performs the below steps,\n\n1. First it stops the browser's default action or behaviour.\n2. It prevents the event from propagating the DOM\n3. Stops callback execution and returns immediately when called.</code></pre></div>\n</li>\n<li>\n<p>What is BOM</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Browser Object Model (BOM) allows JavaScript to \"talk to\" the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers.\n\n![Screenshot](images/bom.png)</code></pre></div>\n</li>\n<li>\n<p>What is the use of setTimeout</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,\n\n     ```js\n\n//\nsetTimeout(function () {\nconsole.log('Good morning');\n}, 2000);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the use of setInterval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,\n\n     ```js\n\n//\nsetInterval(function () {\nconsole.log('Good morning');\n}, 2000);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Why is JavaScript treated as Single threaded</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs.</code></pre></div>\n</li>\n<li>\n<p>What is an event delegation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it.\n\n     For example, if you wanted to detect field changes in inside a specific form, you can use event delegation technique,\n\n     ```js\n\n//\nvar form = document.querySelector('#registration-form');\n\n     // Listen for changes to fields inside the form\n     form.addEventListener(\n         'input',\n         function (event) {\n             // Log the field that was changed\n             console.log(event.target);\n         },\n         false\n     );\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is ECMAScript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. The first edition of ECMAScript was released in 1997.</code></pre></div>\n</li>\n<li>\n<p>What is JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language in the way objects are built in JavaScript.</code></pre></div>\n</li>\n<li>\n<p>What are the syntax rules of JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of syntax rules of JSON\n\n1. The data is in name/value pairs\n2. The data is separated by commas\n3. Curly braces hold objects\n4. Square brackets hold arrays</code></pre></div>\n</li>\n<li>\n<p>What is the purpose JSON stringify</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     When sending data to a web server, the data has to be in a string format. You can achieve this by converting JSON object into a string using stringify() method.\n\n     ```js\n\n//\nvar userJSON = { name: 'John', age: 31 };\nvar userString = JSON.stringify(user);\nconsole.log(userString); //\"{\"name\":\"John\",\"age\":31}\"\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you parse JSON string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     When receiving the data from a web server, the data is always in a string format. But you can convert this string value to a javascript object using parse() method.\n\n     ```js\n\n//\nvar userString = '{\"name\":\"John\",\"age\":31}';\nvar userJSON = JSON.parse(userString);\nconsole.log(userJSON); // {name: \"John\", age: 31}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need JSON</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">When exchanging data between a browser and a server, the data can only be text. Since JSON is text only, it can easily be sent to and from a server, and used as a data format by any programming language.</code></pre></div>\n</li>\n<li>\n<p>What are PWAs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Progressive web applications (PWAs) are a type of mobile app delivered through the web, built using common web technologies including HTML, CSS and JavaScript. These PWAs are deployed to servers, accessible through URLs, and indexed by search engines.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of clearTimeout method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The clearTimeout() function is used in javascript to clear the timeout which has been set by setTimeout()function before that. i.e, The return value of setTimeout() function is stored in a variable and it's passed into the clearTimeout() function to clear the timer.\n\n     For example, the below setTimeout method is used to display the message after 3 seconds. This timeout can be cleared by the clearTimeout() method.\n\n     ```js\n\n//\n&lt;script>\nvar msg;\nfunction greeting() {\nalert('Good morning');\n}\nfunction start() {\nmsg =setTimeout(greeting, 3000);\n\n     }\n\n     function stop() {\n         clearTimeout(msg);\n     }\n     &lt;/script>\n\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of clearInterval method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The clearInterval() function is used in javascript to clear the interval which has been set by setInterval() function. i.e, The return value returned by setInterval() function is stored in a variable and it's passed into the clearInterval() function to clear the interval.\n\n     For example, the below setInterval method is used to display the message for every 3 seconds. This interval can be cleared by the clearInterval() method.\n\n     ```js\n\n//\n&lt;script>\nvar msg;\nfunction greeting() {\nalert('Good morning');\n}\nfunction start() {\nmsg = setInterval(greeting, 3000);\n\n     }\n\n     function stop() {\n         clearInterval(msg);\n     }\n     &lt;/script>\n\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you redirect new page in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In vanilla javascript, you can redirect to a new page using the `location` property of window object. The syntax would be as follows,\n\n     ```js\n\n//\nfunction redirect() {\nwindow.location.href = 'newPage.html';\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether a string contains a substring</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are 3 possible ways to check whether a string contains a substring or not,\n\n     1. **Using includes:** ES6 provided `String.prototype.includes` method to test a string contains a substring\n\n     ```js\n\n//\nvar mainString = 'hello',\nsubString = 'hell';\nmainString.includes(subString);\n\n````\n\n     1. **Using indexOf:** In an ES5 or older environment, you can use `String.prototype.indexOf` which returns the index of a substring. If the index value is not equal to -1 then it means the substring exists in the main string.\n\n     ```js\n\n//\nvar mainString = 'hello',\nsubString = 'hell';\nmainString.indexOf(subString) !== -1;\n````\n\n     1. **Using RegEx:** The advanced solution is using Regular expression's test method(`RegExp.test`), which allows for testing for against regular expressions\n\n     ```js\n\n//\nvar mainString = 'hello',\nregex = /hell/;\nregex.test(mainString);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you validate an email in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead of the client side. Because the javascript can be disabled on the client side.\n\n     ```js\n\n//\nfunction validateEmail(email) {\nvar re =\n/^(([^&lt;>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^&lt;>()\\[\\]\\\\.,;:\\s@\"]+)\\*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\nreturn re.test(String(email).toLowerCase());\n}\n\n```\n\n     The above regular expression accepts unicode characters.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get the current url with javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `window.location.href` expression to get the current url path and you can use the same expression for updating the URL too. You can also use `document.URL` for read-only purposes but this solution has issues in FF.\n\n     ```js\n\n//\nconsole.log('location.href', window.location.href); // Returns full URL\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the various url properties of location object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The below `Location` object properties can be used to access URL components of the page,\n\n1. href - The entire URL\n2. protocol - The protocol of the URL\n3. host - The hostname and port of the URL\n4. hostname - The hostname of the URL\n5. port - The port number in the URL\n6. pathname - The path name of the URL\n7. search - The query portion of the URL\n8. hash - The anchor portion of the URL</code></pre></div>\n</li>\n<li>\n<p>How do get query string values in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string,\n\n     ```js\n\n//\nconst urlParams = new URLSearchParams(window.location.search);\nconst clientCode = urlParams.get('clientCode');\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check if a key exists in an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can check whether a key exists in an object or not using three approaches,\n\n     1. **Using in operator:** You can use the in operator whether a key exists in an object or not\n\n     ```js\n\n//\n'key' in obj;\n\n````\n\n     and If you want to check if a key doesn't exist, remember to use parenthesis,\n\n     ```js\n\n//\n!('key' in obj);\n````\n\n     1. **Using hasOwnProperty method:** You can use `hasOwnProperty` to particularly test for properties of the object instance (and not inherited properties)\n\n     ```js\n\n//\nobj.hasOwnProperty('key'); // true\n\n````\n\n     1. **Using undefined comparison:** If you access a non-existing property from an object, the result is undefined. Let's compare the properties against undefined to determine the existence of the property.\n\n     ```js\n\n//\nconst user = {\nname: 'John'\n};\n\n     console.log(user.name !== undefined); // true\n     console.log(user.nickName !== undefined); // false\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do you loop through or enumerate javascript object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `for-in` loop to loop through javascript object. You can also make sure that the key you get is an actual property of an object, and doesn't come from the prototype using `hasOwnProperty` method.\n\n     ```js\n\n//\nvar object = {\nk1: 'value1',\nk2: 'value2',\nk3: 'value3'\n};\n\n     for (var key in object) {\n         if (object.hasOwnProperty(key)) {\n             console.log(key + ' -> ' + object[key]); // k1 -> value1 ...\n         }\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you test for an empty object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are different solutions based on ECMAScript versions\n\n     1. **Using Object entries(ECMA 7+):** You can use object entries length along with constructor type.\n\n     ```js\n\n//\nObject.entries(obj).length === 0 &amp;&amp; obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well\n\n````\n\n     1. **Using Object keys(ECMA 5+):** You can use object keys length along with constructor type.\n\n     ```js\n\n//\nObject.keys(obj).length === 0 &amp;&amp; obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well\n````\n\n     1. **Using for-in with hasOwnProperty(Pre-ECMA 5):** You can use a for-in loop along with hasOwnProperty.\n\n     ```js\n\n//\nfunction isEmpty(obj) {\nfor (var prop in obj) {\nif (obj.hasOwnProperty(prop)) {\nreturn false;\n}\n}\n\n         return JSON.stringify(obj) === JSON.stringify({});\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is an arguments object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,\n\n     ```js\n\n//\nfunction sum() {\nvar total = 0;\nfor (var i = 0, len = arguments.length; i &lt; len; ++i) {\ntotal += arguments[i];\n}\nreturn total;\n}\n\n     sum(1, 2, 3); // returns 6\n     ```\n\n     **Note:** You can't apply array methods on arguments object. But you can convert into a regular array as below.\n\n     ```js\n\n//\nvar argsArray = Array.prototype.slice.call(arguments);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make first letter of the string in an uppercase</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can create a function which uses a chain of string methods such as charAt, toUpperCase and slice methods to generate a string with the first letter in uppercase.\n\n     ```js\n\n//\nfunction capitalizeFirstLetter(string) {\nreturn string.charAt(0).toUpperCase() + string.slice(1);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the pros and cons of for loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The for-loop is a commonly used iteration syntax in javascript. It has both pros and cons</code></pre></div>\n</li>\n</ol>\n<p>Pros</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> 1. Works on every environment\n 2. You can use break and continue flow control statements</code></pre></div>\n<p>Cons</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> 1. Too verbose\n 2. Imperative\n 3. You might face one-by-off errors</code></pre></div>\n<ol start=\"131\">\n<li>\n<p>How do you display the current date in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `new Date()` to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy\n\n     ```js\n\n//\nvar today = new Date();\nvar dd = String(today.getDate()).padStart(2, '0');\nvar mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!\nvar yyyy = today.getFullYear();\n\n     today = mm + '/' + dd + '/' + yyyy;\n     document.write(today);\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you compare two date objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You need to use date.getTime() method to compare date values instead of comparison operators (==, !=, ===, and !== operators)\n\n     ```js\n\n//\nvar d1 = new Date();\nvar d2 = new Date(d1);\nconsole.log(d1.getTime() === d2.getTime()); //True\nconsole.log(d1 === d2); // False\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check if a string starts with another string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use ECMAScript 6's `String.prototype.startsWith()` method to check if a string starts with another string or not. But it is not yet supported in all browsers. Let's see an example to see this usage,\n\n     ```js\n\n//\n'Good morning'.startsWith('Good'); // true\n'Good morning'.startsWith('morning'); // false\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you trim a string in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript provided a trim method on string types to trim any whitespaces present at the beginning or ending of the string.\n\n     ```js\n\n//\n' Hello World '.trim(); //Hello World\n\n````\n\n     If your browser(&lt;IE9) doesn't support this method then you can use below polyfill.\n\n     ```js\n\n//\nif (!String.prototype.trim) {\n(function () {\n// Make sure we trim BOM and NBSP\nvar rtrim = /^[\\s\\uFEFF\\xA0]+|[\\s\\uFEFF\\xA0]+$/g;\nString.prototype.trim = function () {\nreturn this.replace(rtrim, '');\n};\n})();\n}\n````</code></pre></div>\n</li>\n<li>\n<p>How do you add a key value pair in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are two possible solutions to add new properties to an object. Let's take a simple object to explain these solutions.\n\n     ```js\n\n//\nvar object = {\nkey1: value1,\nkey2: value2\n};\n\n````\n\n     1. **Using dot notation:** This solution is useful when you know the name of the property\n\n     ```js\n\n//\nobject.key3 = 'value3';\n````\n\n     1. **Using square bracket notation:** This solution is useful when the name of the property is dynamically determined.\n\n     ```js\n\n//\nobj['key3'] = 'value3';\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is the !-- notation represents a special operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No,that's not a special operator. But it is a combination of 2 standard operators one after the other,\n\n1. A logical not (!)\n2. A prefix decrement (--)\n\nAt first, the value decremented by one and then tested to see if it is equal to zero or not for determining the truthy/falsy value.</code></pre></div>\n</li>\n<li>\n<p>How do you assign default values to variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the logical or operator `||` in an assignment expression to provide a default value. The syntax looks like as below,\n\n     ```js\n\n//\nvar a = b || c;\n\n```\n\n     As per the above expression, variable 'a 'will get the value of 'c' only if 'b' is falsy (if is null, false, undefined, 0, empty string, or NaN), otherwise 'a' will get the value of 'b'.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define multiline strings</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can define multiline string literals using the '\\\\' character followed by line terminator.\n\n     ```js\n\n//\nvar str =\n'This is a \\\n very lengthy \\\n sentence!';\n\n```\n\n     But if you have a space after the '\\\\' character, the code will look exactly the same, but it will raise a SyntaxError.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an app shell model</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An application shell (or app shell) architecture is one way to build a Progressive Web App that reliably and instantly loads on your users' screens, similar to what you see in native applications. It is useful for getting some initial HTML to the screen fast without a network.</code></pre></div>\n</li>\n<li>\n<p>Can we define properties for functions</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, We can define properties for functions because functions are also objects.\n\n     ```js\n\n//\nfn = function (x) {\n//Function code goes here\n};\n\n     fn.name = 'John';\n\n     fn.profile = function (y) {\n         //Profile code goes here\n     };\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the way to find the number of parameters expected by a function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `function.length` syntax to find the number of parameters expected by a function. Let's take an example of `sum` function to calculate the sum of numbers,\n\n     ```js\n\n//\nfunction sum(num1, num2, num3, num4) {\nreturn num1 + num2 + num3 + num4;\n}\nsum.length; // 4 is the number of parameters expected.\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a polyfill</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A polyfill is a piece of JS code used to provide modern functionality on older browsers that do not natively support it. For example, Silverlight plugin polyfill can be used to mimic the functionality of an HTML Canvas element on Microsoft Internet Explorer 7.</code></pre></div>\n</li>\n<li>\n<p>What are break and continue statements</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The break statement is used to \"jump out\" of a loop. i.e, It breaks the loop and continues executing the code after the loop.\n\n     ```js\n\n//\nfor (i = 0; i &lt; 10; i++) {\nif (i === 5) {\nbreak;\n}\ntext += 'Number: ' + i + '&lt;br>';\n}\n\n````\n\n     The continue statement is used to \"jump over\" one iteration in the loop. i.e, It breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.\n\n     ```js\n\n//\nfor (i = 0; i &lt; 10; i++) {\nif (i === 5) {\ncontinue;\n}\ntext += 'Number: ' + i + '&lt;br>';\n}\n````</code></pre></div>\n</li>\n<li>\n<p>What are js labels</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The label statement allows us to name loops and blocks in JavaScript. We can then use these labels to refer back to the code later. For example, the below code with labels avoids printing the numbers when they are same,\n\n     ```js\n\n//\nvar i, j;\n\n     loop1: for (i = 0; i &lt; 3; i++) {\n         loop2: for (j = 0; j &lt; 3; j++) {\n             if (i === j) {\n                 continue loop1;\n             }\n             console.log('i = ' + i + ', j = ' + j);\n         }\n     }\n\n     // Output is:\n     //   \"i = 1, j = 0\"\n     //   \"i = 2, j = 0\"\n     //   \"i = 2, j = 1\"\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the benefits of keeping declarations at the top</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to keep all declarations at the top of each script or function. The benefits of doing this are,\n\n1. Gives cleaner code\n2. It provides a single place to look for local variables\n3. Easy to avoid unwanted global variables\n4. It reduces the possibility of unwanted re-declarations</code></pre></div>\n</li>\n<li>\n<p>What are the benefits of initializing variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">It is recommended to initialize variables because of the below benefits,\n\n1. It gives cleaner code\n2. It provides a single place to initialize variables\n3. Avoid undefined values in the code</code></pre></div>\n</li>\n<li>\n<p>What are the recommendations to create new object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is recommended to avoid creating new objects using `new Object()`. Instead you can initialize values based on it's type to create the objects.\n\n     1. Assign {} instead of new Object()\n     2. Assign \"\" instead of new String()\n     3. Assign 0 instead of new Number()\n     4. Assign false instead of new Boolean()\n     5. Assign [] instead of new Array()\n     6. Assign /()/ instead of new RegExp()\n     7. Assign function (){} instead of new Function()\n\n     You can define them as an example,\n\n     ```js\n\n//\nvar v1 = {};\nvar v2 = '';\nvar v3 = 0;\nvar v4 = false;\nvar v5 = [];\nvar v6 = /()/;\nvar v7 = function () {};\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define JSON arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JSON arrays are written inside square brackets and arrays contain javascript objects. For example, the JSON array of users would be as below,\n\n     ```js\n\n//\n\"users\":[\n{\"firstName\":\"John\", \"lastName\":\"Abrahm\"},\n{\"firstName\":\"Anna\", \"lastName\":\"Smith\"},\n{\"firstName\":\"Shane\", \"lastName\":\"Warn\"}\n]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you generate random integers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use Math.random() with Math.floor() to return random integers. For example, if you want generate random integers between 1 to 10, the multiplication factor should be 10,\n\n     ```js\n\n//\nMath.floor(Math.random() _ 10) + 1; // returns a random integer from 1 to 10\nMath.floor(Math.random() _ 100) + 1; // returns a random integer from 1 to 100\n\n```\n\n     **Note:** Math.random() returns a random number between 0 (inclusive), and 1 (exclusive)\n\n```</code></pre></div>\n</li>\n<li>\n<p>Can you write a random integers function to print integers with in a range</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, you can create a proper random function to return a random number between min and max (both included)\n\n     ```js\n\n//\nfunction randomInteger(min, max) {\nreturn Math.floor(Math.random() \\* (max - min + 1)) + min;\n}\nrandomInteger(1, 100); // returns a random integer from 1 to 100\nrandomInteger(1, 1000); // returns a random integer from 1 to 1000\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is tree shaking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tree shaking is a form of dead code elimination. It means that unused modules will not be included in the bundle during the build process and for that it relies on the static structure of ES2015 module syntax,( i.e. import and export). Initially this has been popularized by the ES2015 module bundler `rollup`.</code></pre></div>\n</li>\n<li>\n<p>What is the need of tree shaking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Tree Shaking can significantly reduce the code size in any application. i.e, The less code we send over the wire the more performant the application will be. For example, if we just want to create a \"Hello World\" Application using SPA frameworks then it will take around a few MBs, but by tree shaking it can bring down the size to just a few hundred KBs. Tree shaking is implemented in Rollup and Webpack bundlers.</code></pre></div>\n</li>\n<li>\n<p>Is it recommended to use eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No, it allows arbitrary code to be run which causes a security problem. As we know that the eval() function is used to run text as code. In most of the cases, it should not be necessary to use it.</code></pre></div>\n</li>\n<li>\n<p>What is a Regular Expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A regular expression is a sequence of characters that forms a search pattern. You can use this search pattern for searching data in a text. These can be used to perform all types of text search and text replace operations. Let's see the syntax format now,\n\n     ```js\n\n//\n/pattern/modifiers;\n\n````\n\n     For example, the regular expression or search pattern with case-insensitive username would be,\n\n     ```js\n\n//\n/John/i;\n````</code></pre></div>\n</li>\n<li>\n<p>What are the string methods available in Regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Regular Expressions has two string methods: search() and replace().\n     The search() method uses an expression to search for a match, and returns the position of the match.\n\n     ```js\n\n//\nvar msg = 'Hello John';\nvar n = msg.search(/John/i); // 6\n\n````\n\n     The replace() method is used to return a modified string where the pattern is replaced.\n\n     ```js\n\n//\nvar msg = 'Hello John';\nvar n = msg.replace(/John/i, 'Buttler'); // Hello Buttler\n````</code></pre></div>\n</li>\n<li>\n<p>What are modifiers in regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Modifiers can be used to perform case-insensitive and global searches. Let's list down some of the modifiers,\n\n     | Modifier | Description                                             |\n     |----------|---------------------------------------------------------|\n     | i        | Perform case-insensitive matching                       |\n     | g        | Perform a global match rather than stops at first match |\n     | m        | Perform multiline matching                              |\n\n     Let's take an example of global modifier,\n\n     ```js\n\n//\nvar text = 'Learn JS one by one';\nvar pattern = /one/g;\nvar result = text.match(pattern); // one,one\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are regular expression patterns</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Regular Expressions provide a group of patterns in order to match characters. Basically they are categorized into 3 types,\n\n1. **Brackets:** These are used to find a range of characters.\n   For example, below are some use cases,\n    1. [abc]: Used to find any of the characters between the brackets(a,b,c)\n    2. [0-9]: Used to find any of the digits between the brackets\n    3. (a|b): Used to find any of the alternatives separated with |\n2. **Metacharacters:** These are characters with a special meaning\n   For example, below are some use cases,\n    1. \\\\d: Used to find a digit\n    2. \\\\s: Used to find a whitespace character\n    3. \\\\b: Used to find a match at the beginning or ending of a word\n3. **Quantifiers:** These are useful to define quantities\n   For example, below are some use cases,\n    1. n+: Used to find matches for any string that contains at least one n\n    2. n\\*: Used to find matches for any string that contains zero or more occurrences of n\n    3. n?: Used to find matches for any string that contains zero or one occurrences of n</code></pre></div>\n</li>\n<li>\n<p>What is a RegExp object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     RegExp object is a regular expression object with predefined properties and methods. Let's see the simple usage of RegExp object,\n\n     ```js\n\n//\nvar regexp = new RegExp('\\\\w+');\nconsole.log(regexp);\n// expected output: /\\w+/\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you search a string for a pattern</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the test() method of regular expression in order to search a string for a pattern, and return true or false depending on the result.\n\n     ```js\n\n//\nvar pattern = /you/;\nconsole.log(pattern.test('How are you?')); //true\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of exec method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The purpose of exec method is similar to test method but it executes a search for a match in a specified string and returns a result array, or null instead of returning true/false.\n\n     ```js\n\n//\nvar pattern = /you/;\nconsole.log(pattern.exec('How are you?')); //[\"you\", index: 8, input: \"How are you?\", groups: undefined]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you change the style of a HTML element</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can change inline style or classname of a HTML element using javascript\n\n     1. **Using style property:** You can modify inline style using style property\n\n     ```js\n\n//\ndocument.getElementById('title').style.fontSize = '30px';\n\n````\n\n     1. **Using ClassName property:** It is easy to modify element class using className property\n\n     ```js\n\n//\ndocument.getElementById('title').className = 'custom-title';\n````</code></pre></div>\n</li>\n<li>\n<p>What would be the result of 1+2+'3'</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`.</code></pre></div>\n</li>\n<li>\n<p>What is a debugger statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.\n     For example, in the below function a debugger statement has been inserted. So\n     execution is paused at the debugger statement just like a breakpoint in the script source.\n\n     ```js\n\n//\nfunction getProfile() {\n// code goes here\ndebugger;\n// code goes here\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of breakpoints in debugging</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can set breakpoints in the javascript code once the debugger statement is executed and the debugger window pops up. At each breakpoint, javascript will stop executing, and let you examine the JavaScript values. After examining values, you can resume the execution of code using the play button.</code></pre></div>\n</li>\n<li>\n<p>Can I use reserved words as identifiers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     No, you cannot use the reserved words as variables, labels, object or function names. Let's see one simple example,\n\n     ```js\n\n//\nvar else = \"hello\"; // Uncaught SyntaxError: Unexpected token else\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect a mobile browser</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use regex which returns a true or false value depending on whether or not the user is browsing with a mobile.\n\n     ```js\n\n//\nwindow.mobilecheck = function () {\nvar mobileCheck = false;\n(function (a) {\nif (\n/(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(\na\n) ||\n/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i.test(\na.substr(0, 4)\n)\n)\nmobileCheck = true;\n})(navigator.userAgent || navigator.vendor || window.opera);\nreturn mobileCheck;\n};\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect a mobile browser without regexp</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can detect mobile browsers by simply running through a list of devices and checking if the useragent matches anything. This is an alternative solution for RegExp usage,\n\n     ```js\n\n//\nfunction detectmob() {\nif (\nnavigator.userAgent.match(/Android/i) ||\nnavigator.userAgent.match(/webOS/i) ||\nnavigator.userAgent.match(/iPhone/i) ||\nnavigator.userAgent.match(/iPad/i) ||\nnavigator.userAgent.match(/iPod/i) ||\nnavigator.userAgent.match(/BlackBerry/i) ||\nnavigator.userAgent.match(/Windows Phone/i)\n) {\nreturn true;\n} else {\nreturn false;\n}\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get the image width and height using JS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can programmatically get the image and check the dimensions(width and height) using Javascript.\n\n     ```js\n\n//\nvar img = new Image();\nimg.onload = function () {\nconsole.log(this.width + 'x' + this.height);\n};\nimg.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make synchronous HTTP request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Browsers provide an XMLHttpRequest object which can be used to make synchronous HTTP requests from JavaScript\n\n     ```js\n\n//\nfunction httpGet(theUrl) {\nvar xmlHttpReq = new XMLHttpRequest();\nxmlHttpReq.open('GET', theUrl, false); // false for synchronous request\nxmlHttpReq.send(null);\nreturn xmlHttpReq.responseText;\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you make asynchronous HTTP request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Browsers provide an XMLHttpRequest object which can be used to make asynchronous HTTP requests from JavaScript by passing the 3rd parameter as true.\n\n     ```js\n\n//\nfunction httpGetAsync(theUrl, callback) {\nvar xmlHttpReq = new XMLHttpRequest();\nxmlHttpReq.onreadystatechange = function () {\nif (xmlHttpReq.readyState == 4 &amp;&amp; xmlHttpReq.status == 200) callback(xmlHttpReq.responseText);\n};\nxmlHttp.open('GET', theUrl, true); // true for asynchronous\nxmlHttp.send(null);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you convert date to another timezone in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the toLocaleString() method to convert dates in one timezone to another. For example, let's convert current date to British English timezone as below,\n\n     ```js\n\n//\nconsole.log(event.toLocaleString('en-GB', { timeZone: 'UTC' })); //29/06/2019, 09:56:00\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the properties used to get size of window</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use them combination of these properties to calculate the size of a window or document,\n\n     ```js\n\n//\nvar width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;\n\n     var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is a conditional operator in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for if statements.\n\n     ```js\n\n//\nvar isAuthenticated = false;\nconsole.log(isAuthenticated ? 'Hello, welcome' : 'Sorry, you are not authenticated'); //Sorry, you are not authenticated\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Can you apply chaining on conditional operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, you can apply chaining on conditional operators similar to if … else if … else if … else chain. The syntax is going to be as below,\n\n     ```js\n\n//\nfunction traceValue(someParam) {\nreturn condition1 ? value1 : condition2 ? value2 : condition3 ? value3 : value4;\n}\n\n     // The above conditional operator is equivalent to:\n\n     function traceValue(someParam) {\n         if (condition1) {\n             return value1;\n         } else if (condition2) {\n             return value2;\n         } else if (condition3) {\n             return value3;\n         } else {\n             return value4;\n         }\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the ways to execute javascript after page load</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can execute javascript after page load in many different ways,\n\n     1. **window.onload:**\n\n     ```js\n\n//\nwindow.onload = function ...\n\n````\n\n     1. **document.onload:**\n\n     ```js\n\n//\ndocument.onload = function ...\n````\n\n     1. **body onload:**\n\n     ```js\n\n//\n&lt;body onload=\"script();\">\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between proto and prototype</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `__proto__` object is the actual object that is used in the lookup chain to resolve methods, etc. Whereas `prototype` is the object that is used to build `__proto__` when you create an object with new\n\n     ```js\n\n//\nnew Employee().**proto** === Employee.prototype;\nnew Employee().prototype === undefined;\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Give an example where do you really need semicolon</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is recommended to use semicolons after every statement in JavaScript. For example, in the below case it throws an error \".. is not a function\" at runtime due to missing semicolon.\n\n     ```js\n\n//\n// define a function\nvar fn = (function () {\n//...\n})(\n// semicolon missing at this line\n\n         // then execute some code inside a closure\n         function () {\n             //...\n         }\n     )();\n     ```\n\n     and it will be interpreted as\n\n     ```js\n\n//\nvar fn = (function () {\n//...\n})(function () {\n//...\n})();\n\n```\n\n     In this case, we are passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. Hence, the second function will fail with a \"... is not a function\" error at runtime.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The **freeze()** method is used to freeze an object. Freezing an object does not allow adding new properties to an object,prevents from removing and prevents changing the enumerability, configurability, or writability of existing properties. i.e, It returns the passed object and does not create a frozen copy.\n\n     ```js\n\n//\nconst obj = {\nprop: 100\n};\n\n     Object.freeze(obj);\n     obj.prop = 200; // Throws an error in strict mode\n\n     console.log(obj.prop); //100\n     ```\n\n     **Note:** It causes a TypeError if the argument passed is not an object.</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main benefits of using freeze method,\n\n1. It is used for freezing objects and arrays.\n2. It is used to make an object immutable.</code></pre></div>\n</li>\n<li>\n<p>Why do I need to use freeze method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">In the Object-oriented paradigm, an existing API contains certain elements that are not intended to be extended, modified, or re-used outside of their current context. Hence it works as the `final` keyword which is used in various languages.</code></pre></div>\n</li>\n<li>\n<p>How do you detect a browser language preference</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use navigator object to detect a browser language preference as below,\n\n     ```js\n\n//\nvar language =\n(navigator.languages &amp;&amp; navigator.languages[0]) || // Chrome / Firefox\nnavigator.language || // All browsers\nnavigator.userLanguage; // IE &lt;= 10\n\n     console.log(language);\n     ```</code></pre></div>\n</li>\n<li>\n<p>How to convert string to title case with javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function,\n\n     ```js\n\n//\nfunction toTitleCase(str) {\nreturn str.replace(/\\w\\S\\*/g, function (txt) {\nreturn txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();\n});\n}\ntoTitleCase('good morning john'); // Good Morning John\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you detect javascript disabled in the page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `&lt;noscript>` tag to detect javascript disabled or not. The code block inside `&lt;noscript>` gets executed when JavaScript is disabled, and is typically used to display alternative content when the page generated in JavaScript.\n\n     ```js\n\n//\n&lt;script type=\"javascript\">\n// JS related code goes here\n&lt;/script>\n&lt;noscript>\n&lt;a href=\"next_page.html?noJS=true\">JavaScript is disabled in the page. Please click Next Page&lt;/a>\n&lt;/noscript>\n```</code></pre></div>\n</li>\n<li>\n<p>What are various operators supported by javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An operator is capable of manipulating(mathematical and logical computations) a certain value or operand. There are various operators supported by JavaScript as below,\n\n1. **Arithmetic Operators:** Includes + (Addition),- (Subtraction), \\* (Multiplication), / (Division), % (Modulus), + + (Increment) and - - (Decrement)\n2. **Comparison Operators:** Includes = =(Equal),!= (Not Equal), ===(Equal with type), > (Greater than),> = (Greater than or Equal to),&lt; (Less than),&lt;= (Less than or Equal to)\n3. **Logical Operators:** Includes &amp;&amp;(Logical AND),||(Logical OR),!(Logical NOT)\n4. **Assignment Operators:** Includes = (Assignment Operator), += (Add and Assignment Operator), - = (Subtract and Assignment Operator), \\*= (Multiply and Assignment), /= (Divide and Assignment), %= (Modules and Assignment)\n5. **Ternary Operators:** It includes conditional(: ?) Operator\n6. **typeof Operator:** It uses to find type of variable. The syntax looks like `typeof variable`</code></pre></div>\n</li>\n<li>\n<p>What is a rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Rest parameter is an improved way to handle function parameters which allows us to represent an indefinite number of arguments as an array. The syntax would be as below,\n\n     ```js\n\n//\nfunction f(a, b, ...theArgs) {\n// ...\n}\n\n````\n\n     For example, let's take a sum example to calculate on dynamic number of parameters,\n\n     ```js\n\n//\nfunction total(…args){\nlet sum = 0;\nfor(let i of args){\nsum+=i;\n}\nreturn sum;\n}\nconsole.log(fun(1,2)); //3\nconsole.log(fun(1,2,3)); //6\nconsole.log(fun(1,2,3,4)); //13\nconsole.log(fun(1,2,3,4,5)); //15\n````\n\n     **Note:** Rest parameter is added in ES2015 or ES6</code></pre></div>\n</li>\n<li>\n<p>What happens if you do not use rest parameter as a last argument</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The rest parameter should be the last argument, as its job is to collect all the remaining arguments into an array. For example, if you define a function like below it doesn't make any sense and will throw an error.\n\n     ```js\n\n//\nfunction someFunc(a,…b,c){\n//You code goes here\nreturn;\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the bitwise operators available in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of bitwise logical operators used in JavaScript\n\n1. Bitwise AND ( &amp; )\n2. Bitwise OR ( | )\n3. Bitwise XOR ( ^ )\n4. Bitwise NOT ( ~ )\n5. Left Shift ( &lt;&lt; )\n6. Sign Propagating Right Shift ( >> )\n7. Zero fill Right Shift ( >>> )</code></pre></div>\n</li>\n<li>\n<p>What is a spread operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. Let's take an example to see this behavior,\n\n     ```js\n\n//\nfunction calculateSum(x, y, z) {\nreturn x + y + z;\n}\n\n     const numbers = [1, 2, 3];\n\n     console.log(calculateSum(...numbers)); // 6\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you determine whether object is frozen or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Object.isFrozen() method is used to determine if an object is frozen or not.An object is frozen if all of the below conditions hold true,\n\n     1. If it is not extensible.\n     2. If all of its properties are non-configurable.\n     3. If all its data properties are non-writable.\n        The usage is going to be as follows,\n\n     ```js\n\n//\nconst object = {\nproperty: 'Welcome JS world'\n};\nObject.freeze(object);\nconsole.log(Object.isFrozen(object));\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you determine two values same or not using object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.is() method determines whether two values are the same value. For example, the usage with different types of values would be,\n\n     ```js\n\n//\nObject.is('hello', 'hello'); // true\nObject.is(window, window); // true\nObject.is([], []); // false\n\n```\n\n     Two values are the same if one of the following holds:\n\n     1. both undefined\n     2. both null\n     3. both true or both false\n     4. both strings of the same length with the same characters in the same order\n     5. both the same object (means both object have same reference)\n     6. both numbers and\n        both +0\n        both -0\n        both NaN\n        both non-zero and both not NaN and both have the same value.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of using object is method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the applications of Object's `is` method are follows,\n\n1. It is used for comparison of two strings.\n2. It is used for comparison of two numbers.\n3. It is used for comparing the polarity of two numbers.\n4. It is used for comparison of two objects.</code></pre></div>\n</li>\n<li>\n<p>How do you copy properties from one object to other</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the Object.assign() method which is used to copy the values and properties from one or more source objects to a target object. It returns the target object which has properties and values copied from the target object. The syntax would be as below,\n\n     ```js\n\n//\nObject.assign(target, ...sources);\n\n````\n\n     Let's take example with one source and one target object,\n\n     ```js\n\n//\nconst target = { a: 1, b: 2 };\nconst source = { b: 3, c: 4 };\n\n     const returnedTarget = Object.assign(target, source);\n\n     console.log(target); // { a: 1, b: 3, c: 4 }\n\n     console.log(returnedTarget); // { a: 1, b: 3, c: 4 }\n     ```\n\n     As observed in the above code, there is a common property(`b`) from source to target so it's value has been overwritten.\n\n````</code></pre></div>\n</li>\n<li>\n<p>What are the applications of assign method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the some of main applications of Object.assign() method,\n\n1. It is used for cloning an object.\n2. It is used to merge objects with the same properties.</code></pre></div>\n</li>\n<li>\n<p>What is a proxy object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Proxy object is used to define custom behavior for fundamental operations such as property lookup, assignment, enumeration, function invocation, etc. The syntax would be as follows,\n\n     ```js\n\n//\nvar p = new Proxy(target, handler);\n\n````\n\n     Let's take an example of proxy object,\n\n     ```js\n\n//\nvar handler = {\nget: function (obj, prop) {\nreturn prop in obj ? obj[prop] : 100;\n}\n};\n\n     var p = new Proxy({}, handler);\n     p.a = 10;\n     p.b = null;\n\n     console.log(p.a, p.b); // 10, null\n     console.log('c' in p, p.c); // false, 100\n     ```\n\n     In the above code, it uses `get` handler which define the behavior of the proxy when an operation is performed on it\n\n````</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of seal method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The **Object.seal()** method is used to seal an object, by preventing new properties from being added to it and marking all existing properties as non-configurable. But values of present properties can still be changed as long as they are writable. Let's see the below example to understand more about seal() method\n\n     ```js\n\n//\nconst object = {\nproperty: 'Welcome JS world'\n};\nObject.seal(object);\nobject.property = 'Welcome to object world';\nconsole.log(Object.isSealed(object)); // true\ndelete object.property; // You cannot delete when sealed\nconsole.log(object.property); //Welcome to object world\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the applications of seal method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main applications of Object.seal() method,\n\n1. It is used for sealing objects and arrays.\n2. It is used to make an object immutable.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between freeze and seal methods</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If an object is frozen using the Object.freeze() method then its properties become immutable and no changes can be made in them whereas if an object is sealed using the Object.seal() method then the changes can be made in the existing properties of the object.</code></pre></div>\n</li>\n<li>\n<p>How do you determine if an object is sealed or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.isSealed() method is used to determine if an object is sealed or not. An object is sealed if all of the below conditions hold true\n\n     1. If it is not extensible.\n     2. If all of its properties are non-configurable.\n     3. If it is not removable (but not necessarily non-writable).\n        Let's see it in the action\n\n     ```js\n\n//\nconst object = {\nproperty: 'Hello, Good morning'\n};\n\n     Object.seal(object); // Using seal() method to seal the object\n\n     console.log(Object.isSealed(object)); // checking whether the object is sealed or not\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you get enumerable key and value pairs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.entries() method is used to return an array of a given object's own enumerable string-keyed property [key, value] pairs, in the same order as that provided by a for...in loop. Let's see the functionality of object.entries() method in an example,\n\n     ```js\n\n//\nconst object = {\na: 'Good morning',\nb: 100\n};\n\n     for (let [key, value] of Object.entries(object)) {\n         console.log(`${key}: ${value}`); // a: 'Good morning'\n         // b: 100\n     }\n     ```\n\n     **Note:** The order is not guaranteed as object defined.</code></pre></div>\n</li>\n<li>\n<p>What is the main difference between Object.values and Object.entries method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.values() method's behavior is similar to Object.entries() method but it returns an array of values instead [key,value] pairs.\n\n     ```js\n\n//\nconst object = {\na: 'Good morning',\nb: 100\n};\n\n     for (let value of Object.values(object)) {\n         console.log(`${value}`); // 'Good morning'\n         100;\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>How can you get the list of keys of any object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.keys()` method which is used to return an array of a given object's own property names, in the same order as we get with a normal loop. For example, you can get the keys of a user object,\n\n     ```js\n\n//\nconst user = {\nname: 'John',\ngender: 'male',\nage: 40\n};\n\n     console.log(Object.keys(user)); //['name', 'gender', 'age']\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you create an object with prototype</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.create() method is used to create a new object with the specified prototype object and properties. i.e, It uses an existing object as the prototype of the newly created object. It returns a new object with the specified prototype object and properties.\n\n     ```js\n\n//\nconst user = {\nname: 'John',\nprintInfo: function () {\nconsole.log(`My name is ${this.name}.`);\n}\n};\n\n     const admin = Object.create(user);\n\n     admin.name = 'Nick'; // Remember that \"name\" is a property set on \"admin\" but not on \"user\" object\n\n     admin.printInfo(); // My name is Nick\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is a WeakSet</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     WeakSet is used to store a collection of weakly(weak references) held objects. The syntax would be as follows,\n\n     ```js\n\n//\nnew WeakSet([iterable]);\n\n````\n\n     Let's see the below example to explain it's behavior,\n\n     ```js\n\n//\nvar ws = new WeakSet();\nvar user = {};\nws.add(user);\nws.has(user); // true\nws.delete(user); // removes user from the set\nws.has(user); // false, user has been removed\n````</code></pre></div>\n</li>\n<li>\n<p>What are the differences between WeakSet and Set</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference is that references to objects in Set are strong while references to objects in WeakSet are weak. i.e, An object in WeakSet can be garbage collected if there is no other reference to it.\nOther differences are,\n\n1. Sets can store any value Whereas WeakSets can store only collections of objects\n2. WeakSet does not have size property unlike Set\n3. WeakSet does not have methods such as clear, keys, values, entries, forEach.\n4. WeakSet is not iterable.</code></pre></div>\n</li>\n<li>\n<p>List down the collection of methods available on WeakSet</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Below are the list of methods available on WeakSet,\n\n     1. add(value): A new object is appended with the given value to the weakset\n     2. delete(value): Deletes the value from the WeakSet collection.\n     3. has(value): It returns true if the value is present in the WeakSet Collection, otherwise it returns false.\n\n     Let's see the functionality of all the above methods in an example,\n\n     ```js\n\n//\nvar weakSetObject = new WeakSet();\nvar firstObject = {};\nvar secondObject = {};\n// add(value)\nweakSetObject.add(firstObject);\nweakSetObject.add(secondObject);\nconsole.log(weakSetObject.has(firstObject)); //true\nweakSetObject.delete(secondObject);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a WeakMap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The WeakMap object is a collection of key/value pairs in which the keys are weakly referenced. In this case, keys must be objects and the values can be arbitrary values. The syntax is looking like as below,\n\n     ```js\n\n//\nnew WeakMap([iterable]);\n\n````\n\n     Let's see the below example to explain it's behavior,\n\n     ```js\n\n//\nvar ws = new WeakMap();\nvar user = {};\nws.set(user);\nws.has(user); // true\nws.delete(user); // removes user from the map\nws.has(user); // false, user has been removed\n````</code></pre></div>\n</li>\n<li>\n<p>What are the differences between WeakMap and Map</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The main difference is that references to key objects in Map are strong while references to key objects in WeakMap are weak. i.e, A key object in WeakMap can be garbage collected if there is no other reference to it.\nOther differences are,\n\n1. Maps can store any key type Whereas WeakMaps can store only collections of key objects\n2. WeakMap does not have size property unlike Map\n3. WeakMap does not have methods such as clear, keys, values, entries, forEach.\n4. WeakMap is not iterable.</code></pre></div>\n</li>\n<li>\n<p>List down the collection of methods available on WeakMap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Below are the list of methods available on WeakMap,\n\n     1. set(key, value): Sets the value for the key in the WeakMap object. Returns the WeakMap object.\n     2. delete(key): Removes any value associated to the key.\n     3. has(key): Returns a Boolean asserting whether a value has been associated to the key in the WeakMap object or not.\n     4. get(key): Returns the value associated to the key, or undefined if there is none.\n        Let's see the functionality of all the above methods in an example,\n\n     ```js\n\n//\nvar weakMapObject = new WeakMap();\nvar firstObject = {};\nvar secondObject = {};\n// set(key, value)\nweakMapObject.set(firstObject, 'John');\nweakMapObject.set(secondObject, 100);\nconsole.log(weakMapObject.has(firstObject)); //true\nconsole.log(weakMapObject.get(firstObject)); // John\nweakMapObject.delete(secondObject);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of uneval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The uneval() is an inbuilt function which is used to create a string representation of the source code of an Object. It is a top-level function and is not associated with any object. Let's see the below example to know more about it's functionality,\n\n     ```js\n\n//\nvar a = 1;\nuneval(a); // returns a String containing 1\nuneval(function user() {}); // returns \"(function user(){})\"\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you encode an URL</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The encodeURI() function is used to encode complete URI which has special characters except (, / ? : @ &amp; = + $ #) characters.\n\n     ```js\n\n//\nvar uri = 'https://mozilla.org/?x=шеллы';\nvar encoded = encodeURI(uri);\nconsole.log(encoded); // https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you decode an URL</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The decodeURI() function is used to decode a Uniform Resource Identifier (URI) previously created by encodeURI().\n\n     ```js\n\n//\nvar uri = 'https://mozilla.org/?x=шеллы';\nvar encoded = encodeURI(uri);\nconsole.log(encoded); // https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B\ntry {\nconsole.log(decodeURI(encoded)); // \"https://mozilla.org/?x=шеллы\"\n} catch (e) {\n// catches a malformed URI\nconsole.error(e);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you print the contents of web page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The window object provided a print() method which is used to print the contents of the current window. It opens a Print dialog box which lets you choose between various printing options. Let's see the usage of print method in an example,\n\n```html\n&lt;input type=\"button\" value=\"Print\" onclick=\"window.print()\" />\n```\n\n**Note:** In most browsers, it will block while the print dialog is open.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between uneval and eval</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `uneval` function returns the source of a given object; whereas the `eval` function does the opposite, by evaluating that source code in a different memory area. Let's see an example to clarify the difference,\n\n     ```js\n\n//\nvar msg = uneval(function greeting() {\nreturn 'Hello, Good morning';\n});\nvar greeting = eval(msg);\ngreeting(); // returns \"Hello, Good morning\"\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an anonymous function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An anonymous function is a function without a name! Anonymous functions are commonly assigned to a variable name or used as a callback function. The syntax would be as below,\n\n     ```js\n\n//\nfunction (optionalParameters) {\n//do something\n}\n\n     const myFunction = function(){ //Anonymous function assigned to a variable\n       //do something\n     };\n\n     [1, 2, 3].map(function(element){ //Anonymous function used as a callback function\n       //do something\n     });\n     ```\n\n     Let's see the above anonymous function in an example,\n\n     ```js\n\n//\nvar x = function (a, b) {\nreturn a \\* b;\n};\nvar z = x(5, 10);\nconsole.log(z); // 50\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the precedence order between local and global variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A local variable takes precedence over a global variable with the same name. Let's see this behavior in an example.\n\n     ```js\n\n//\nvar msg = 'Good morning';\nfunction greeting() {\nmsg = 'Good Evening';\nconsole.log(msg);\n}\ngreeting();\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are javascript accessors</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ECMAScript 5 introduced javascript object accessors or computed properties through getters and setters. Getters uses the `get` keyword whereas Setters uses the `set` keyword.\n\n     ```js\n\n//\nvar user = {\nfirstName: \"John\",\nlastName : \"Abraham\",\nlanguage : \"en\",\nget lang() {\nreturn this.language;\n}\nset lang(lang) {\nthis.language = lang;\n}\n};\nconsole.log(user.lang); // getter access lang as en\nuser.lang = 'fr';\nconsole.log(user.lang); // setter used to set lang as fr\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you define property on Object constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Object.defineProperty() static method is used to define a new property directly on an object, or modify an existing property on an object, and returns the object. Let's see an example to know how to define property,\n\n     ```js\n\n//\nconst newObject = {};\n\n     Object.defineProperty(newObject, 'newProperty', {\n         value: 100,\n         writable: false\n     });\n\n     console.log(newObject.newProperty); // 100\n\n     newObject.newProperty = 200; // It throws an error in strict mode due to writable setting\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between get and defineProperty</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both have similar results until unless you use classes. If you use `get` the property will be defined on the prototype of the object whereas using `Object.defineProperty()` the property will be defined on the instance it is applied to.</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of Getters and Setters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of benefits of Getters and Setters,\n\n1. They provide simpler syntax\n2. They are used for defining computed properties, or accessors in JS.\n3. Useful to provide equivalence relation between properties and methods\n4. They can provide better data quality\n5. Useful for doing things behind the scenes with the encapsulated logic.</code></pre></div>\n</li>\n<li>\n<p>Can I add getters and setters using defineProperty method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, You can use the `Object.defineProperty()` method to add Getters and Setters. For example, the below counter object uses increment, decrement, add and subtract properties,\n\n     ```js\n\n//\nvar obj = { counter: 0 };\n\n     // Define getters\n     Object.defineProperty(obj, 'increment', {\n         get: function () {\n             this.counter++;\n         }\n     });\n     Object.defineProperty(obj, 'decrement', {\n         get: function () {\n             this.counter--;\n         }\n     });\n\n     // Define setters\n     Object.defineProperty(obj, 'add', {\n         set: function (value) {\n             this.counter += value;\n         }\n     });\n     Object.defineProperty(obj, 'subtract', {\n         set: function (value) {\n             this.counter -= value;\n         }\n     });\n\n     obj.add = 10;\n     obj.subtract = 5;\n     console.log(obj.increment); //6\n     console.log(obj.decrement); //5\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of switch-case</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The switch case statement in JavaScript is used for decision making purposes. In a few cases, using the switch case statement is going to be more convenient than if-else statements. The syntax would be as below,\n\n     ```js\n\n//\nswitch (expression)\n{\ncase value1:\nstatement1;\nbreak;\ncase value2:\nstatement2;\nbreak;\n.\n.\ncase valueN:\nstatementN;\nbreak;\ndefault:\nstatementDefault;\n}\n\n```\n\n     The above multi-way branch statement provides an easy way to dispatch execution to different parts of code based on the value of the expression.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the conventions to be followed for the usage of switch case</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of conventions should be taken care,\n\n1. The expression can be of type either number or string.\n2. Duplicate values are not allowed for the expression.\n3. The default statement is optional. If the expression passed to switch does not match with any case value then the statement within default case will be executed.\n4. The break statement is used inside the switch to terminate a statement sequence.\n5. The break statement is optional. But if it is omitted, the execution will continue on into the next case.</code></pre></div>\n</li>\n<li>\n<p>What are primitive data types</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A primitive data type is data that has a primitive value (which has no properties or methods). There are 7 types of primitive data types.\n\n1. string\n2. number\n3. boolean\n4. null\n5. undefined\n6. bigint\n7. symbol</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to access object properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are 3 possible ways for accessing the property of an object.\n\n     1. **Dot notation:** It uses dot for accessing the properties\n\n     ```js\n\n//\nobjectName.property;\n\n````\n\n     1. **Square brackets notation:** It uses square brackets for property access\n\n     ```js\n\n//\nobjectName['property'];\n````\n\n     1. **Expression notation:** It uses expression in the square brackets\n\n     ```js\n\n//\nobjectName[expression];\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the function parameter rules</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript functions follow below rules for parameters,\n\n     1. The function definitions do not specify data types for parameters.\n     2. Do not perform type checking on the passed arguments.\n     3. Do not check the number of arguments received.\n        i.e, The below function follows the above rules,\n\n     ```js\n\n//\nfunction functionName(parameter1, parameter2, parameter3) {\nconsole.log(parameter1); // 1\n}\nfunctionName(1);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An error object is a built in error object that provides error information when an error occurs. It has two properties: name and message. For example, the below function logs error details,\n\n     ```js\n\n//\ntry {\ngreeting('Welcome');\n} catch (err) {\nconsole.log(err.name + '&lt;br>' + err.message);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>When you get a syntax error</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A SyntaxError is thrown if you try to evaluate code with a syntax error. For example, the below missing quote for the function parameter throws a syntax error\n\n     ```js\n\n//\ntry {\neval(\"greeting('welcome)\"); // Missing ' will produce an error\n} catch (err) {\nconsole.log(err.name);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different error names from error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are 6 different types of error names returned from error object,\n| Error Name | Description |\n|---- | ---------\n| EvalError | An error has occurred in the eval() function |\n| RangeError | An error has occurred with a number \"out of range\" |\n| ReferenceError | An error due to an illegal reference|\n| SyntaxError | An error due to a syntax error|\n| TypeError | An error due to a type error |\n| URIError | An error due to encodeURI() |</code></pre></div>\n</li>\n<li>\n<p>What are the various statements in error handling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of statements used in an error handling,\n\n1. **try:** This statement is used to test a block of code for errors\n2. **catch:** This statement is used to handle the error\n3. **throw:** This statement is used to create custom errors.\n4. **finally:** This statement is used to execute code after try and catch regardless of the result.</code></pre></div>\n</li>\n<li>\n<p>What are the two types of loops in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">1. **Entry Controlled loops:** In this kind of loop type, the test condition is tested before entering the loop body. For example, For Loop and While Loop comes under this category.\n2. **Exit Controlled Loops:** In this kind of loop type, the test condition is tested or evaluated at the end of the loop body. i.e, the loop body will execute at least once irrespective of test condition true or false. For example, do-while loop comes under this category.</code></pre></div>\n</li>\n<li>\n<p>What is nodejs</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Node.js is a server-side platform built on Chrome's JavaScript runtime for easily building fast and scalable network applications. It is an event-based, non-blocking, asynchronous I/O runtime that uses Google's V8 JavaScript engine and libuv library.</code></pre></div>\n</li>\n<li>\n<p>What is an Intl object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Intl object is the namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting. It provides access to several constructors and language sensitive functions.</code></pre></div>\n</li>\n<li>\n<p>How do you perform language specific date and time formatting</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Intl.DateTimeFormat` object which is a constructor for objects that enable language-sensitive date and time formatting. Let's see this behavior with an example,\n\n     ```js\n\n//\nvar date = new Date(Date.UTC(2019, 07, 07, 3, 0, 0));\nconsole.log(new Intl.DateTimeFormat('en-GB').format(date)); // 07/08/2019\nconsole.log(new Intl.DateTimeFormat('en-AU').format(date)); // 07/08/2019\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an Iterator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">An iterator is an object which defines a sequence and a return value upon its termination. It implements the Iterator protocol with a `next()` method which returns an object with two properties: `value` (the next value in the sequence) and `done` (which is true if the last value in the sequence has been consumed).</code></pre></div>\n</li>\n<li>\n<p>How does synchronous iteration works</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Synchronous iteration was introduced in ES6 and it works with below set of components,\n\n     **Iterable:** It is an object which can be iterated over via a method whose key is Symbol.iterator.\n     **Iterator:** It is an object returned by invoking `[Symbol.iterator]()` on an iterable. This iterator object wraps each iterated element in an object and returns it via `next()` method one by one.\n     **IteratorResult:** It is an object returned by `next()` method. The object contains two properties; the `value` property contains an iterated element and the `done` property determines whether the element is the last element or not.\n\n     Let's demonstrate synchronous iteration with an array as below,\n\n     ```js\n\n//\nconst iterable = ['one', 'two', 'three'];\nconst iterator = iterable[Symbol.iterator]();\nconsole.log(iterator.next()); // { value: 'one', done: false }\nconsole.log(iterator.next()); // { value: 'two', done: false }\nconsole.log(iterator.next()); // { value: 'three', done: false }\nconsole.log(iterator.next()); // { value: 'undefined, done: true }\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an event loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The Event Loop is a queue of callback functions. When an async function executes, the callback function is pushed into the queue. The JavaScript engine doesn't start processing the event loop until the async function has finished executing the code.\n**Note:** It allows Node.js to perform non-blocking I/O operations even though JavaScript is single-threaded.</code></pre></div>\n</li>\n<li>\n<p>What is call stack</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Call Stack is a data structure for javascript interpreters to keep track of function calls in the program. It has two major actions,\n\n     1. Whenever you call a function for its execution, you are pushing it to the stack.\n     2. Whenever the execution is completed, the function is popped out of the stack.\n\n     Let's take an example and it's state representation in a diagram format\n\n     ```js\n\n//\nfunction hungry() {\neatFruits();\n}\nfunction eatFruits() {\nreturn \"I'm eating fruits\";\n}\n\n     // Invoke the `hungry` function\n     hungry();\n     ```\n\n     The above code processed in a call stack as below,\n\n     1. Add the `hungry()` function to the call stack list and execute the code.\n     2. Add the `eatFruits()` function to the call stack list and execute the code.\n     3. Delete the `eatFruits()` function from our call stack list.\n     4. Delete the `hungry()` function from the call stack list since there are no items anymore.\n\n     ![Screenshot](images/call-stack.png)</code></pre></div>\n</li>\n<li>What is an event queue</li>\n<li>\n<p>What is a decorator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A decorator is an expression that evaluates to a function and that takes the target, name, and decorator descriptor as arguments. Also, it optionally returns a decorator descriptor to install on the target object. Let's define admin decorator for user class at design time,\n\n     ```js\n\n//\nfunction admin(isAdmin) {\nreturn function(target) {\ntarget.isAdmin = isAdmin;\n}\n}\n\n     @admin(true)\n     class User() {\n     }\n     console.log(User.isAdmin); //true\n\n      @admin(false)\n      class User() {\n      }\n      console.log(User.isAdmin); //false\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the properties of Intl object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of properties available on Intl object,\n\n1. **Collator:** These are the objects that enable language-sensitive string comparison.\n2. **DateTimeFormat:** These are the objects that enable language-sensitive date and time formatting.\n3. **ListFormat:** These are the objects that enable language-sensitive list formatting.\n4. **NumberFormat:** Objects that enable language-sensitive number formatting.\n5. **PluralRules:** Objects that enable plural-sensitive formatting and language-specific rules for plurals.\n6. **RelativeTimeFormat:** Objects that enable language-sensitive relative time formatting.</code></pre></div>\n</li>\n<li>\n<p>What is an Unary operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The unary(+) operator is used to convert a variable to a number.If the variable cannot be converted, it will still become a number but with the value NaN. Let's see this behavior in an action.\n\n     ```js\n\n//\nvar x = '100';\nvar y = +x;\nconsole.log(typeof x, typeof y); // string, number\n\n     var a = 'Hello';\n     var b = +a;\n     console.log(typeof a, typeof b, b); // string, number, NaN\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you sort elements in an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The sort() method is used to sort the elements of an array in place and returns the sorted array. The example usage would be as below,\n\n     ```js\n\n//\nvar months = ['Aug', 'Sep', 'Jan', 'June'];\nmonths.sort();\nconsole.log(months); // [\"Aug\", \"Jan\", \"June\", \"Sep\"]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of compareFunction while sorting arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The compareFunction is used to define the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value. Let's take an example to see the usage of compareFunction,\n\n     ```js\n\n//\nlet numbers = [1, 2, 5, 3, 4];\nnumbers.sort((a, b) => b - a);\nconsole.log(numbers); // [5, 4, 3, 2, 1]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you reversing an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the reverse() method to reverse the elements in an array. This method is useful to sort an array in descending order. Let's see the usage of reverse() method in an example,\n\n     ```js\n\n//\nlet numbers = [1, 2, 5, 3, 4];\nnumbers.sort((a, b) => b - a);\nnumbers.reverse();\nconsole.log(numbers); // [1, 2, 3, 4 ,5]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you find min and max value in an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `Math.min` and `Math.max` methods on array variables to find the minimum and maximum elements within an array. Let's create two functions to find the min and max value with in an array,\n\n     ```js\n\n//\nvar marks = [50, 20, 70, 60, 45, 30];\nfunction findMin(arr) {\nreturn Math.min.apply(null, arr);\n}\nfunction findMax(arr) {\nreturn Math.max.apply(null, arr);\n}\n\n     console.log(findMin(marks));\n     console.log(findMax(marks));\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you find min and max values without Math functions</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can write functions which loop through an array comparing each value with the lowest value or highest value to find the min and max values. Let's create those functions to find min and max values,\n\n     ```js\n\n//\nvar marks = [50, 20, 70, 60, 45, 30];\nfunction findMin(arr) {\nvar length = arr.length;\nvar min = Infinity;\nwhile (length--) {\nif (arr[length] &lt; min) {\nmin = arr[len];\n}\n}\nreturn min;\n}\n\n     function findMax(arr) {\n         var length = arr.length;\n         var max = -Infinity;\n         while (len--) {\n             if (arr[length] > max) {\n                 max = arr[length];\n             }\n         }\n         return max;\n     }\n\n     console.log(findMin(marks));\n     console.log(findMax(marks));\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is an empty statement and purpose of it</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The empty statement is a semicolon (;) indicating that no statement will be executed, even if JavaScript syntax requires one. Since there is no action with an empty statement you might think that it's usage is quite less, but the empty statement is occasionally useful when you want to create a loop that has an empty body. For example, you can initialize an array with zero values as below,\n\n     ```js\n\n//\n// Initialize an array a\nfor(int i=0; i &lt; a.length; a[i++] = 0) ;\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get metadata of a module</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `import.meta` object which is a meta-property exposing context-specific meta data to a JavaScript module. It contains information about the current module, such as the module's URL. In browsers, you might get different meta data than NodeJS.\n\n     ```js\n\n//\n&lt;script type=\"module\" src=\"welcome-module.js\">\n&lt;/script>;\n\nconsole.log(import.meta); // { url: \"file:///home/user/welcome-module.js\" }\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a comma operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The comma operator is used to evaluate each of its operands from left to right and returns the value of the last operand. This is totally different from comma usage within arrays, objects, and function arguments and parameters. For example, the usage for numeric expressions would be as below,\n\n     ```js\n\n//\nvar x = 1;\nx = (x++, x);\n\n     console.log(x); // 2\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the advantage of a comma operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is normally used to include multiple expressions in a location that requires a single expression. One of the common usages of this comma operator is to supply multiple parameters in a `for` loop. For example, the below for loop uses multiple expressions in a single location using comma operator,\n\n     ```js\n\n//\nfor (var a = 0, b =10; a &lt;= 10; a++, b--)\n\n````\n\n     You can also use the comma operator in a return statement where it processes before returning.\n\n     ```js\n\n//\nfunction myFunction() {\nvar a = 1;\nreturn (a += 10), a; // 11\n}\n````</code></pre></div>\n</li>\n<li>\n<p>What is typescript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">TypeScript is a typed superset of JavaScript created by Microsoft that adds optional types, classes, async/await, and many other features, and compiles to plain JavaScript. Angular built entirely in TypeScript and used as a primary language. You can install it globally as\n\n```shell\nnpm install -g typescript\n```\n\nLet's see a simple example of TypeScript usage,\n\n```typescript\nfunction greeting(name: string): string {\n    return 'Hello, ' + name;\n}\n\nlet user = 'Sudheer';\n\nconsole.log(greeting(user));\n```\n\nThe greeting method allows only string type as argument.</code></pre></div>\n</li>\n<li>\n<p>What are the differences between javascript and typescript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of differences between javascript and typescript,\n\n| feature             | typescript                            | javascript                                      |\n| ------------------- | ------------------------------------- | ----------------------------------------------- |\n| Language paradigm   | Object oriented programming language  | Scripting language                              |\n| Typing support      | Supports static typing                | It has dynamic typing                           |\n| Modules             | Supported                             | Not supported                                   |\n| Interface           | It has interfaces concept             | Doesn't support interfaces                      |\n| Optional parameters | Functions support optional parameters | No support of optional parameters for functions |</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of typescript over javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are some of the advantages of typescript over javascript,\n\n1. TypeScript is able to find compile time errors at the development time only and it makes sures less runtime errors. Whereas javascript is an interpreted language.\n2. TypeScript is strongly-typed or supports static typing which allows for checking type correctness at compile time. This is not available in javascript.\n3. TypeScript compiler can compile the .ts files into ES3,ES4 and ES5 unlike ES6 features of javascript which may not be supported in some browsers.</code></pre></div>\n</li>\n<li>\n<p>What is an object initializer</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An object initializer is an expression that describes the initialization of an Object. The syntax for this expression is represented as a comma-delimited list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}). This is also known as literal notation. It is one of the ways to create an object.\n\n     ```js\n\n//\nvar initObject = { a: 'John', b: 50, c: {} };\n\n     console.log(initObject.a); // John\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is a constructor method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The constructor method is a special method for creating and initializing an object created within a class. If you do not specify a constructor method, a default constructor is used. The example usage of constructor would be as below,\n\n     ```js\n\n//\nclass Employee {\nconstructor() {\nthis.name = 'John';\n}\n}\n\n     var employeeObject = new Employee();\n\n     console.log(employeeObject.name); // John\n     ```</code></pre></div>\n</li>\n<li>\n<p>What happens if you write constructor more than once in a class</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The \"constructor\" in a class is a special method and it should be defined only once in a class. i.e, If you write a constructor method more than once in a class it will throw a `SyntaxError` error.\n\n     ```js\n\n//\nclass Employee {\nconstructor() {\nthis.name = \"John\";\n}\nconstructor() { // Uncaught SyntaxError: A class may only have one constructor\nthis.age = 30;\n}\n}\n\n      var employeeObject = new Employee();\n\n      console.log(employeeObject.name);\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you call the constructor of a parent class</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `super` keyword to call the constructor of a parent class. Remember that `super()` must be called before using 'this' reference. Otherwise it will cause a reference error. Let's the usage of it,\n\n     ```js\n\n//\nclass Square extends Rectangle {\nconstructor(length) {\nsuper(length, length);\nthis.name = 'Square';\n}\n\n         get area() {\n             return this.width * this.height;\n         }\n\n         set area(value) {\n             this.area = value;\n         }\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you get the prototype of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.getPrototypeOf(obj)` method to return the prototype of the specified object. i.e. The value of the internal `prototype` property. If there are no inherited properties then `null` value is returned.\n\n     ```js\n\n//\nconst newPrototype = {};\nconst newObject = Object.create(newPrototype);\n\n     console.log(Object.getPrototypeOf(newObject) === newPrototype); // true\n     ```</code></pre></div>\n</li>\n<li>\n<p>What happens If I pass string type for getPrototype method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In ES5, it will throw a TypeError exception if the obj parameter isn't an object. Whereas in ES2015, the parameter will be coerced to an `Object`.\n\n     ```js\n\n//\n// ES5\nObject.getPrototypeOf('James'); // TypeError: \"James\" is not an object\n// ES2015\nObject.getPrototypeOf('James'); // String.prototype\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you set prototype of one object to another</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.setPrototypeOf()` method that sets the prototype (i.e., the internal `Prototype` property) of a specified object to another object or null. For example, if you want to set prototype of a square object to rectangle object would be as follows,\n\n     ```js\n\n//\nObject.setPrototypeOf(Square.prototype, Rectangle.prototype);\nObject.setPrototypeOf({}, null);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether an object can be extendable or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `Object.isExtensible()` method is used to determine if an object is extendable or not. i.e, Whether it can have new properties added to it or not.\n\n     ```js\n\n//\nconst newObject = {};\nconsole.log(Object.isExtensible(newObject)); //true\n\n```\n\n     **Note:** By default, all the objects are extendable. i.e, The new properties can be added or modified.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you prevent an object to extend</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `Object.preventExtensions()` method is used to prevent new properties from ever being added to an object. In other words, it prevents future extensions to the object. Let's see the usage of this property,\n\n     ```js\n\n//\nconst newObject = {};\nObject.preventExtensions(newObject); // NOT extendable\n\n     try {\n         Object.defineProperty(newObject, 'newProperty', {\n             // Adding new property\n             value: 100\n         });\n     } catch (e) {\n         console.log(e); // TypeError: Cannot define property newProperty, object is not extensible\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to make an object non-extensible</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can mark an object non-extensible in 3 ways,\n\n     1. Object.preventExtensions\n     2. Object.seal\n     3. Object.freeze\n\n     ```js\n\n//\nvar newObject = {};\n\n     Object.preventExtensions(newObject); // Prevent objects are non-extensible\n     Object.isExtensible(newObject); // false\n\n     var sealedObject = Object.seal({}); // Sealed objects are non-extensible\n     Object.isExtensible(sealedObject); // false\n\n     var frozenObject = Object.freeze({}); // Frozen objects are non-extensible\n     Object.isExtensible(frozenObject); // false\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you define multiple properties on an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `Object.defineProperties()` method is used to define new or modify existing properties directly on an object and returning the object. Let's define multiple properties on an empty object,\n\n     ```js\n\n//\nconst newObject = {};\n\n     Object.defineProperties(newObject, {\n         newProperty1: {\n             value: 'John',\n             writable: true\n         },\n         newProperty2: {}\n     });\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is MEAN in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The MEAN (MongoDB, Express, AngularJS, and Node.js) stack is the most popular open-source JavaScript software tech stack available for building dynamic web apps where you can write both the server-side and client-side halves of the web project entirely in JavaScript.</code></pre></div>\n</li>\n<li>\n<p>What Is Obfuscation in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Obfuscation is the deliberate act of creating obfuscated javascript code(i.e, source or machine code) that is difficult for humans to understand. It is something similar to encryption, but a machine can understand the code and execute it.\n     Let's see the below function before Obfuscation,\n\n     ```js\n\n//\nfunction greeting() {\nconsole.log('Hello, welcome to JS world');\n}\n\n````\n\n     And after the code Obfuscation, it would be appeared as below,\n\n     ```js\n\n//\neval(\n(function (p, a, c, k, e, d) {\ne = function (c) {\nreturn c;\n};\nif (!''.replace(/^/, String)) {\nwhile (c--) {\nd[c] = k[c] || c;\n}\nk = [\nfunction (e) {\nreturn d[e];\n}\n];\ne = function () {\nreturn '\\\\w+';\n};\nc = 1;\n}\nwhile (c--) {\nif (k[c]) {\np = p.replace(new RegExp('\\\\b' + e(c) + '\\\\b', 'g'), k[c]);\n}\n}\nreturn p;\n})(\"2 1(){0.3('4, 7 6 5 8')}\", 9, 9, 'console|greeting|function|log|Hello|JS|to|welcome|world'.split('|'), 0, {})\n);\n````</code></pre></div>\n</li>\n<li>\n<p>Why do you need Obfuscation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the few reasons for Obfuscation,\n\n1. The Code size will be reduced. So data transfers between server and client will be fast.\n2. It hides the business logic from outside world and protects the code from others\n3. Reverse engineering is highly difficult\n4. The download time will be reduced</code></pre></div>\n</li>\n<li>\n<p>What is Minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Minification is the process of removing all unnecessary characters(empty spaces are removed) and variables will be renamed without changing it's functionality. It is also a type of obfuscation .</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Normally it is recommended to use minification for heavy traffic and intensive requirements of resources. It reduces file sizes with below benefits,\n\n1. Decreases loading times of a web page\n2. Saves bandwidth usages</code></pre></div>\n</li>\n<li>\n<p>What are the differences between Obfuscation and Encryption</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the main differences between Obfuscation and Encryption,\n\n| Feature            | Obfuscation                                     | Encryption                                                              |\n| ------------------ | ----------------------------------------------- | ----------------------------------------------------------------------- |\n| Definition         | Changing the form of any data in any other form | Changing the form of information to an unreadable format by using a key |\n| A key to decode    | It can be decoded without any key               | It is required                                                          |\n| Target data format | It will be converted to a complex form          | Converted into an unreadable format                                     |</code></pre></div>\n</li>\n<li>\n<p>What are the common tools used for minification</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are many online/offline tools to minify the javascript files,\n\n1. Google's Closure Compiler\n2. UglifyJS2\n3. jsmin\n4. javascript-minifier.com/\n5. prettydiff.com</code></pre></div>\n</li>\n<li>\n<p>How do you perform form validation using javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript can be used to perform HTML form validation. For example, if the form field is empty, the function needs to notify, and return false, to prevent the form being submitted.\n     Lets' perform user login in an html form,\n\n     ```html\n     &lt;form name=\"myForm\" onsubmit=\"return validateForm()\" method=\"post\">\n         User name: &lt;input type=\"text\" name=\"uname\" />\n         &lt;input type=\"submit\" value=\"Submit\" />\n     &lt;/form>\n     ```\n\n     And the validation on user login is below,\n\n     ```js\n\n//\nfunction validateForm() {\nvar x = document.forms['myForm']['uname'].value;\nif (x == '') {\nalert(\"The username shouldn't be empty\");\nreturn false;\n}\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you perform form validation without javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can perform HTML form validation automatically without using javascript. The validation enabled by applying the `required` attribute to prevent form submission when the input is empty.\n\n```html\n&lt;form method=\"post\">\n    &lt;input type=\"text\" name=\"uname\" required />\n    &lt;input type=\"submit\" value=\"Submit\" />\n&lt;/form>\n```\n\n**Note:** Automatic form validation does not work in Internet Explorer 9 or earlier.</code></pre></div>\n</li>\n<li>\n<p>What are the DOM methods available for constraint validation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The below DOM methods are available for constraint validation on an invalid input,\n\n     1. checkValidity(): It returns true if an input element contains valid data.\n     2. setCustomValidity(): It is used to set the validationMessage property of an input element.\n        Let's take an user login form with DOM validations\n\n     ```js\n\n//\nfunction myFunction() {\nvar userName = document.getElementById('uname');\nif (!userName.checkValidity()) {\ndocument.getElementById('message').innerHTML = userName.validationMessage;\n} else {\ndocument.getElementById('message').innerHTML = 'Entered a valid username';\n}\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the available constraint validation DOM properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of some of the constraint validation DOM properties available,\n\n1. validity: It provides a list of boolean properties related to the validity of an input element.\n2. validationMessage: It displays the message when the validity is false.\n3. willValidate: It indicates if an input element will be validated or not.</code></pre></div>\n</li>\n<li>\n<p>What are the list of validity properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The validity property of an input element provides a set of properties related to the validity of data.\n\n1. customError: It returns true, if a custom validity message is set.\n2. patternMismatch: It returns true, if an element's value does not match its pattern attribute.\n3. rangeOverflow: It returns true, if an element's value is greater than its max attribute.\n4. rangeUnderflow: It returns true, if an element's value is less than its min attribute.\n5. stepMismatch: It returns true, if an element's value is invalid according to step attribute.\n6. tooLong: It returns true, if an element's value exceeds its maxLength attribute.\n7. typeMismatch: It returns true, if an element's value is invalid according to type attribute.\n8. valueMissing: It returns true, if an element with a required attribute has no value.\n9. valid: It returns true, if an element's value is valid.</code></pre></div>\n</li>\n<li>\n<p>Give an example usage of rangeOverflow property</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If an element's value is greater than its max attribute then rangeOverflow property returns true. For example, the below form submission throws an error if the value is more than 100,\n\n     ```html\n     &lt;input id=\"age\" type=\"number\" max=\"100\" /> &lt;button onclick=\"myOverflowFunction()\">OK&lt;/button>\n     ```\n\n     ```js\n\n//\nfunction myOverflowFunction() {\nif (document.getElementById('age').validity.rangeOverflow) {\nalert('The mentioned age is not allowed');\n}\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is enums feature available in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     No, javascript does not natively support enums. But there are different kinds of solutions to simulate them even though they may not provide exact equivalents. For example, you can use freeze or seal on object,\n\n     ```js\n\n//\nvar DaysEnum = Object.freeze({\"monday\":1, \"tuesday\":2, \"wednesday\":3, ...})\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an enum</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An enum is a type restricting variables to one value from a predefined set of constants. JavaScript has no enums but typescript provides built-in enum support.\n\n     ```js\n\n//\nenum Color {\nRED, GREEN, BLUE\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you list all properties of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.getOwnPropertyNames()` method which returns an array of all properties found directly in a given object. Let's the usage of it in an example,\n\n     ```js\n\n//\nconst newObject = {\na: 1,\nb: 2,\nc: 3\n};\n\n     console.log(Object.getOwnPropertyNames(newObject));\n     ['a', 'b', 'c'];\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you get property descriptors of an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Object.getOwnPropertyDescriptors()` method which returns all own property descriptors of a given object. The example usage of this method is below,\n\n     ```js\n\n//\nconst newObject = {\na: 1,\nb: 2,\nc: 3\n};\nconst descriptorsObject = Object.getOwnPropertyDescriptors(newObject);\nconsole.log(descriptorsObject.a.writable); //true\nconsole.log(descriptorsObject.a.configurable); //true\nconsole.log(descriptorsObject.a.enumerable); //true\nconsole.log(descriptorsObject.a.value); // 1\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the attributes provided by a property descriptor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A property descriptor is a record which has the following attributes\n\n1. value: The value associated with the property\n2. writable: Determines whether the value associated with the property can be changed or not\n3. configurable: Returns true if the type of this property descriptor can be changed and if the property can be deleted from the corresponding object.\n4. enumerable: Determines whether the property appears during enumeration of the properties on the corresponding object or not.\n5. set: A function which serves as a setter for the property\n6. get: A function which serves as a getter for the property</code></pre></div>\n</li>\n<li>\n<p>How do you extend classes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `extends` keyword is used in class declarations/expressions to create a class which is a child of another class. It can be used to subclass custom classes as well as built-in objects. The syntax would be as below,\n\n     ```js\n\n//\nclass ChildClass extends ParentClass { ... }\n\n````\n\n     Let's take an example of Square subclass from Polygon parent class,\n\n     ```js\n\n//\nclass Square extends Rectangle {\nconstructor(length) {\nsuper(length, length);\nthis.name = 'Square';\n}\n\n         get area() {\n             return this.width * this.height;\n         }\n\n         set area(value) {\n             this.area = value;\n         }\n     }\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do I modify the url without reloading the page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `window.location.url` property will be helpful to modify the url but it reloads the page. HTML5 introduced the `history.pushState()` and `history.replaceState()` methods, which allow you to add and modify history entries, respectively. For example, you can use pushState as below,\n\n     ```js\n\n//\nwindow.history.pushState('page2', 'Title', '/page2.html');\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you check whether an array includes a particular value or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `Array#includes()` method is used to determine whether an array includes a particular value among its entries by returning either true or false. Let's see an example to find an element(numeric and string) within an array.\n\n     ```js\n\n//\nvar numericArray = [1, 2, 3, 4];\nconsole.log(numericArray.includes(3)); // true\n\n     var stringArray = ['green', 'yellow', 'blue'];\n     console.log(stringArray.includes('blue')); //true\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you compare scalar arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use length and every method of arrays to compare two scalar(compared directly using ===) arrays. The combination of these expressions can give the expected result,\n\n     ```js\n\n//\nconst arrayFirst = [1, 2, 3, 4, 5];\nconst arraySecond = [1, 2, 3, 4, 5];\nconsole.log(arrayFirst.length === arraySecond.length &amp;&amp; arrayFirst.every((value, index) => value === arraySecond[index])); // true\n\n````\n\n     If you would like to compare arrays irrespective of order then you should sort them before,\n\n     ```js\n\n//\nconst arrayFirst = [2, 3, 1, 4, 5];\nconst arraySecond = [1, 2, 3, 4, 5];\nconsole.log(arrayFirst.length === arraySecond.length &amp;&amp; arrayFirst.sort().every((value, index) => value === arraySecond[index])); //true\n````</code></pre></div>\n</li>\n<li>\n<p>How to get the value from get parameters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `new URL()` object accepts the url string and `searchParams` property of this object can be used to access the get parameters. Remember that you may need to use polyfill or `window.location` to access the URL in older browsers(including IE).\n\n     ```js\n\n//\nlet urlString = 'http://www.some-domain.com/about.html?x=1&amp;y=2&amp;z=3'; //window.location.href\nlet url = new URL(urlString);\nlet parameterZ = url.searchParams.get('z');\nconsole.log(parameterZ); // 3\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you print numbers with commas as thousand separators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `Number.prototype.toLocaleString()` method which returns a string with a language-sensitive representation such as thousand separator,currency etc of this number.\n\n     ```js\n\n//\nfunction convertToThousandFormat(x) {\nreturn x.toLocaleString(); // 12,345.679\n}\n\n     console.log(convertToThousandFormat(12345.6789));\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between java and javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Both are totally unrelated programming languages and no relation between them. Java is statically typed, compiled, runs on its own VM. Whereas Javascript is dynamically typed, interpreted, and runs in a browser and nodejs environments. Let's see the major differences in a tabular format,\n| Feature | Java | JavaScript |\n|---- | ---- | -----\n| Typed | It's a strongly typed language | It's a dynamic typed language |\n| Paradigm | Object oriented programming | Prototype based programming |\n| Scoping | Block scoped | Function-scoped |\n| Concurrency | Thread based | event based |\n| Memory | Uses more memory | Uses less memory. Hence it will be used for web pages |</code></pre></div>\n</li>\n<li>\n<p>Does JavaScript supports namespace</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript doesn't support namespace by default. So if you create any element(function, method, object, variable) then it becomes global and pollutes the global namespace. Let's take an example of defining two functions without any namespace,\n\n     ```js\n\n//\nfunction func1() {\nconsole.log('This is a first definition');\n}\nfunction func1() {\nconsole.log('This is a second definition');\n}\nfunc1(); // This is a second definition\n\n```\n\n     It always calls the second function definition. In this case, namespace will solve the name collision problem.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you declare namespace</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Even though JavaScript lacks namespaces, we can use Objects , IIFE to create namespaces.\n\n     1. **Using Object Literal Notation:** Let's wrap variables and functions inside an Object literal which acts as a namespace. After that you can access them using object notation\n\n     ```js\n\n//\nvar namespaceOne = {\nfunction func1() {\nconsole.log(\"This is a first definition\");\n}\n}\nvar namespaceTwo = {\nfunction func1() {\nconsole.log(\"This is a second definition\");\n}\n}\nnamespaceOne.func1(); // This is a first definition\nnamespaceTwo.func1(); // This is a second definition\n\n````\n\n     1. **Using IIFE (Immediately invoked function expression):** The outer pair of parentheses of IIFE creates a local scope for all the code inside of it and makes the anonymous function a function expression. Due to that, you can create the same function in two different function expressions to act as a namespace.\n\n     ```js\n\n//\n(function () {\nfunction fun1() {\nconsole.log('This is a first definition');\n}\nfun1();\n})();\n\n     (function () {\n         function fun1() {\n             console.log('This is a second definition');\n         }\n         fun1();\n     })();\n     ```\n\n     1. **Using a block and a let/const declaration:** In ECMAScript 6, you can simply use a block and a let declaration to restrict the scope of a variable to a block.\n\n     ```js\n\n//\n{\nlet myFunction = function fun1() {\nconsole.log('This is a first definition');\n};\nmyFunction();\n}\n//myFunction(): ReferenceError: myFunction is not defined.\n\n     {\n         let myFunction = function fun1() {\n             console.log('This is a second definition');\n         };\n         myFunction();\n     }\n     //myFunction(): ReferenceError: myFunction is not defined.\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do you invoke javascript code in an iframe from parent page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Initially iFrame needs to be accessed using either `document.getElementBy` or `window.frames`. After that `contentWindow` property of iFrame gives the access for targetFunction\n\n     ```js\n\n//\ndocument.getElementById('targetFrame').contentWindow.targetFunction();\nwindow.frames[0].frameElement.contentWindow.targetFunction(); // Accessing iframe this way may not work in latest versions chrome and firefox\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do get the timezone offset from date</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `getTimezoneOffset` method of the date object. This method returns the time zone difference, in minutes, from current locale (host system settings) to UTC\n\n     ```js\n\n//\nvar offset = new Date().getTimezoneOffset();\nconsole.log(offset); // -480\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you load CSS and JS files dynamically</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can create both link and script elements in the DOM and append them as child to head tag. Let's create a function to add script and style resources as below,\n\n     ```js\n\n//\nfunction loadAssets(filename, filetype) {\nif (filetype == 'css') {\n// External CSS file\nvar fileReference = document.createElement('link');\nfileReference.setAttribute('rel', 'stylesheet');\nfileReference.setAttribute('type', 'text/css');\nfileReference.setAttribute('href', filename);\n} else if (filetype == 'js') {\n// External JavaScript file\nvar fileReference = document.createElement('script');\nfileReference.setAttribute('type', 'text/javascript');\nfileReference.setAttribute('src', filename);\n}\nif (typeof fileReference != 'undefined') document.getElementsByTagName('head')[0].appendChild(fileReference);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the different methods to find HTML elements in DOM</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">If you want to access any element in an HTML page, you need to start with accessing the document object. Later you can use any of the below methods to find the HTML element,\n\n1. document.getElementById(id): It finds an element by Id\n2. document.getElementsByTagName(name): It finds an element by tag name\n3. document.getElementsByClassName(name): It finds an element by class name</code></pre></div>\n</li>\n<li>\n<p>What is jQuery</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     jQuery is a popular cross-browser JavaScript library that provides Document Object Model (DOM) traversal, event handling, animations and AJAX interactions by minimizing the discrepancies across browsers. It is widely famous with its philosophy of \"Write less, do more\". For example, you can display welcome message on the page load using jQuery as below,\n\n     ```js\n\n//\n$(document).ready(function () {\n// It selects the document and apply the function on page load\nalert('Welcome to jQuery world');\n});\n\n```\n\n     **Note:** You can download it from jquery's official site or install it from CDNs, like google.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is V8 JavaScript engine</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">V8 is an open source high-performance JavaScript engine used by the Google Chrome browser, written in C++. It is also being used in the node.js project. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors.\n**Note:** It can run standalone, or can be embedded into any C++ application.</code></pre></div>\n</li>\n<li>\n<p>Why do we call javascript as dynamic language</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript is a loosely typed or a dynamic language because variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned/reassigned with values of all types.\n\n     ```js\n\n//\nlet age = 50; // age is a number now\nage = 'old'; // age is a string now\nage = true; // age is a boolean\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a void operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `void` operator evaluates the given expression and then returns undefined(i.e, without returning value). The syntax would be as below,\n\n     ```js\n\n//\nvoid expression;\nvoid expression;\n\n````\n\n     Let's display a message without any redirection or reload\n\n     ```js\n\n//\n&lt;a href=\"javascript:void(alert('Welcome to JS world'))\">Click here to see a message&lt;/a>\n````\n\n     **Note:** This operator is often used to obtain the undefined primitive value, using \"void(0)\".</code></pre></div>\n</li>\n<li>\n<p>How to set the cursor to wait</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The cursor can be set to wait in JavaScript by using the property \"cursor\". Let's perform this behavior on page load using the below function.\n\n     ```js\n\n//\nfunction myFunction() {\nwindow.document.body.style.cursor = 'wait';\n}\n\n````\n\n     and this function invoked on page load\n\n     ```html\n     &lt;body onload=\"myFunction()\">\n\n&lt;/body>\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do you create an infinite loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can create infinite loops using for and while loops without using any expressions. The for loop construct or syntax is better approach in terms of ESLint and code optimizer tools,\n\n     ```js\n\n//\nfor (;;) {}\nwhile (true) {}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Why do you need to avoid with statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     JavaScript's with statement was intended to provide a shorthand for writing recurring accesses to objects. So it can help reduce file size by reducing the need to repeat a lengthy object reference without performance penalty. Let's take an example where it is used to avoid redundancy when accessing an object several times.\n\n     ```js\n\n//\na.b.c.greeting = 'welcome';\na.b.c.age = 32;\n\n````\n\n     Using `with` it turns this into:\n\n     ```js\n\n//\nwith (a.b.c) {\ngreeting = 'welcome';\nage = 32;\n}\n````\n\n     But this `with` statement creates performance problems since one cannot predict whether an argument will refer to a real variable or to a property inside the with argument.</code></pre></div>\n</li>\n<li>\n<p>What is the output of below for loops</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ```js\n\n//\nfor (var i = 0; i &lt; 4; i++) {\n// global scope\nsetTimeout(() => console.log(i));\n}\n\n     for (let i = 0; i &lt; 4; i++) {\n         // block scope\n         setTimeout(() => console.log(i));\n     }\n     ```\n\n     The output of the above for loops is 4 4 4 4 and 0 1 2 3\n\n     **Explanation:** Due to the event queue/loop of javascript, the `setTimeout` callback function is called after the loop has been executed. Since the variable i is declared with the `var` keyword it became a global variable and the value was equal to 4 using iteration when the time `setTimeout` function is invoked. Hence, the output of the first loop is `4 4 4 4`.\n\n     Whereas in the second loop, the variable i is declared as the `let` keyword it becomes a block scoped variable and it holds a new value(0, 1 ,2 3) for each iteration. Hence, the output of the first loop is `0 1 2 3`.</code></pre></div>\n</li>\n<li>\n<p>List down some of the features of ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of some new features of ES6,\n\n1. Support for constants or immutable variables\n2. Block-scope support for variables, constants and functions\n3. Arrow functions\n4. Default parameters\n5. Rest and Spread Parameters\n6. Template Literals\n7. Multi-line Strings\n8. Destructuring Assignment\n9. Enhanced Object Literals\n10. Promises\n11. Classes\n12. Modules</code></pre></div>\n</li>\n<li>\n<p>What is ES6</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">ES6 is the sixth edition of the javascript language and it was released in June 2015. It was initially known as ECMAScript 6 (ES6) and later renamed to ECMAScript 2015. Almost all the modern browsers support ES6 but for the old browsers there are many transpilers, like Babel.js etc.</code></pre></div>\n</li>\n<li>\n<p>Can I redeclare let and const variables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     No, you cannot redeclare let and const variables. If you do, it throws below error\n\n     ```shell\n     Uncaught SyntaxError: Identifier 'someVariable' has already been declared\n     ```\n\n     **Explanation:** The variable declaration with `var` keyword refers to a function scope and the variable is treated as if it were declared at the top of the enclosing scope due to hoisting feature. So all the multiple declarations contributing to the same hoisted variable without any error. Let's take an example of re-declaring variables in the same scope for both var and let/const variables.\n\n     ```js\n\n//\nvar name = 'John';\nfunction myFunc() {\nvar name = 'Nick';\nvar name = 'Abraham'; // Re-assigned in the same function block\nalert(name); // Abraham\n}\nmyFunc();\nalert(name); // John\n\n````\n\n     The block-scoped multi-declaration throws syntax error,\n\n     ```js\n\n//\nlet name = 'John';\nfunction myFunc() {\nlet name = 'Nick';\nlet name = 'Abraham'; // Uncaught SyntaxError: Identifier 'name' has already been declared\nalert(name);\n}\n\n     myFunc();\n     alert(name);\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>Is const variable makes the value immutable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     No, the const variable doesn't make the value immutable. But it disallows subsequent assignments(i.e, You can declare with assignment but can't assign another value later)\n\n     ```js\n\n//\nconst userList = [];\nuserList.push('John'); // Can mutate even though it can't re-assign\nconsole.log(userList); // ['John']\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are default parameters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In E5, we need to depend on logical OR operators to handle default values of function parameters. Whereas in ES6, Default function parameters feature allows parameters to be initialized with default values if no value or undefined is passed. Let's compare the behavior with an examples,\n\n     ```js\n\n//\n//ES5\nvar calculateArea = function (height, width) {\nheight = height || 50;\nwidth = width || 60;\n\n         return width * height;\n     };\n     console.log(calculateArea()); //300\n     ```\n\n     The default parameters makes the initialization more simpler,\n\n     ```js\n\n//\n//ES6\nvar calculateArea = function (height = 50, width = 60) {\nreturn width \\* height;\n};\n\n     console.log(calculateArea()); //300\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are template literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Template literals or template strings are string literals allowing embedded expressions. These are enclosed by the back-tick (`) character instead of double or single quotes.\n     In E6, this feature enables using dynamic expressions as below,\n\n     ```js\n\n//\nvar greeting = `Welcome to JS World, Mr. ${firstName} ${lastName}.`;\n\n````\n\n     In ES5, you need break string like below,\n\n     ```js\n\n//\nvar greeting = 'Welcome to JS World, Mr. ' + firstName + ' ' + lastName.`\n````\n\n     **Note:** You can use multi-line strings and string interpolation features with template literals.</code></pre></div>\n</li>\n<li>\n<p>How do you write multi-line strings in template literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In ES5, you would have to use newline escape characters('\\\\n') and concatenation symbols(+) in order to get multi-line strings.\n\n     ```js\n\n//\nconsole.log('This is string sentence 1\\n' + 'This is string sentence 2');\n\n````\n\n     Whereas in ES6, You don't need to mention any newline sequence character,\n\n     ```js\n\n//\nconsole.log(`This is string sentence 'This is string sentence 2`);\n````</code></pre></div>\n</li>\n<li>\n<p>What are nesting templates</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The nesting template is a feature supported within template literals syntax to allow inner backticks inside a placeholder ${ } within the template. For example, the below nesting template is used to display the icons based on user permissions whereas outer template checks for platform type,\n\n     ```js\n\n//\nconst iconStyles = `icon ${isMobilePlatform() ? '' : `icon-${user.isAuthorized ? 'submit' : 'disabled'}`}`;\n\n````\n\n     You can write the above use case without nesting template features as well. However, the nesting template feature is more compact and readable.\n\n     ```js\n\n//\n//Without nesting templates\nconst iconStyles = `icon ${ isMobilePlatform() ? '' : (user.isAuthorized ? 'icon-submit' : 'icon-disabled'}`;\n````</code></pre></div>\n</li>\n<li>\n<p>What are tagged templates</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Tagged templates are the advanced form of templates in which tags allow you to parse template literals with a function. The tag function accepts the first parameter as an array of strings and remaining parameters as expressions. This function can also return manipulated strings based on parameters. Let's see the usage of this tagged template behavior of an IT professional skill set in an organization,\n\n     ```js\n\n//\nvar user1 = 'John';\nvar skill1 = 'JavaScript';\nvar experience1 = 15;\n\n     var user2 = 'Kane';\n     var skill2 = 'JavaScript';\n     var experience2 = 5;\n\n     function myInfoTag(strings, userExp, experienceExp, skillExp) {\n       var str0 = strings[0]; // \"Mr/Ms. \"\n       var str1 = strings[1]; // \" is a/an \"\n       var str2 = strings[2]; // \"in\"\n\n       var expertiseStr;\n       if (experienceExp > 10){\n         expertiseStr = 'expert developer';\n       } else if(skillExp > 5 &amp;&amp; skillExp &lt;= 10) {\n         expertiseStr = 'senior developer';\n       } else {\n         expertiseStr = 'junior developer';\n       }\n\n       return ${str0}${userExp}${str1}${expertiseStr}${str2}${skillExp};\n     }\n\n     var output1 = myInfoTag`Mr/Ms. ${ user1 } is a/an ${ experience1 } in ${skill1}`;\n     var output2 = myInfoTag`Mr/Ms. ${ user2 } is a/an ${ experience2 } in ${skill2}`;\n\n     console.log(output1);// Mr/Ms. John is a/an expert developer in JavaScript\n     console.log(output2);// Mr/Ms. Kane is a/an junior developer in JavaScript\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are raw strings</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ES6 provides a raw strings feature using the `String.raw()` method which is used to get the raw string form of template strings. This feature allows you to access the raw strings as they were entered, without processing escape sequences. For example, the usage would be as below,\n\n     ```js\n\n//\nvar calculationString = String.raw`The sum of numbers is \\n${1 + 2 + 3 + 4}!`;\nconsole.log(calculationString); // The sum of numbers is 10\n\n````\n\n     If you don't use raw strings, the newline character sequence will be processed by displaying the output in multiple lines\n\n     ```js\n\n//\nvar calculationString = `The sum of numbers is \\n${1 + 2 + 3 + 4}!`;\nconsole.log(calculationString);\n// The sum of numbers is\n// 10\n````\n\n     Also, the raw property is available on the first argument to the tag function\n\n     ```js\n\n//\nfunction tag(strings) {\nconsole.log(strings.raw[0]);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The destructuring assignment is a JavaScript expression that makes it possible to unpack values from arrays or properties from objects into distinct variables.\n     Let's get the month values from an array using destructuring assignment\n\n     ```js\n\n//\nvar [one, two, three] = ['JAN', 'FEB', 'MARCH'];\n\n     console.log(one); // \"JAN\"\n     console.log(two); // \"FEB\"\n     console.log(three); // \"MARCH\"\n     ```\n\n     and you can get user properties of an object using destructuring assignment,\n\n     ```js\n\n//\nvar { name, age } = { name: 'John', age: 32 };\n\n     console.log(name); // John\n     console.log(age); // 32\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are default values in destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A variable can be assigned a default value when the value unpacked from the array or object is undefined during destructuring assignment. It helps to avoid setting default values separately for each assignment. Let's take an example for both arrays and object use cases,\n\n     **Arrays destructuring:**\n\n     ```js\n\n//\nvar x, y, z;\n\n     [x = 2, y = 4, z = 6] = [10];\n     console.log(x); // 10\n     console.log(y); // 4\n     console.log(z); // 6\n     ```\n\n     **Objects destructuring:**\n\n     ```js\n\n//\nvar { x = 2, y = 4, z = 6 } = { x: 10 };\n\n     console.log(x); // 10\n     console.log(y); // 4\n     console.log(z); // 6\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you swap variables in destructuring assignment</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If you don't use destructuring assignment, swapping two values requires a temporary variable. Whereas using a destructuring feature, two variable values can be swapped in one destructuring expression. Let's swap two number variables in array destructuring assignment,\n\n     ```js\n\n//\nvar x = 10,\ny = 20;\n\n     [x, y] = [y, x];\n     console.log(x); // 20\n     console.log(y); // 10\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are enhanced object literals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Object literals make it easy to quickly create objects with properties inside the curly braces. For example, it provides shorter syntax for common object property definition as below.\n\n     ```js\n\n//\n//ES6\nvar x = 10,\ny = 20;\nobj = { x, y };\nconsole.log(obj); // {x: 10, y:20}\n//ES5\nvar x = 10,\ny = 20;\nobj = { x: x, y: y };\nconsole.log(obj); // {x: 10, y:20}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are dynamic imports</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The dynamic imports using `import()` function syntax allows us to load modules on demand by using promises or the async/await syntax. Currently this feature is in [stage4 proposal](https://github.com/tc39/proposal-dynamic-import). The main advantage of dynamic imports is reduction of our bundle's sizes, the size/payload response of our requests and overall improvements in the user experience.\n     The syntax of dynamic imports would be as below,\n\n     ```js\n\n//\nimport('./Module').then((Module) => Module.method());\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the use cases for dynamic imports</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Below are some of the use cases of using dynamic imports over static imports,\n\n     1. Import a module on-demand or conditionally. For example, if you want to load a polyfill on legacy browser\n\n     ```js\n\n//\nif (isLegacyBrowser()) {\nimport(···)\n.then(···);\n}\n\n````\n\n     1. Compute the module specifier at runtime. For example, you can use it for internationalization.\n\n     ```js\n\n//\nimport(`messages_${getLocale()}.js`).then(···);\n````\n\n     1. Import a module from within a regular script instead a module.</code></pre></div>\n</li>\n<li>\n<p>What are typed arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Typed arrays are array-like objects from ECMAScript 6 API for handling binary data. JavaScript provides 8 Typed array types,\n\n     1. Int8Array: An array of 8-bit signed integers\n     2. Int16Array: An array of 16-bit signed integers\n     3. Int32Array: An array of 32-bit signed integers\n     4. Uint8Array: An array of 8-bit unsigned integers\n     5. Uint16Array: An array of 16-bit unsigned integers\n     6. Uint32Array: An array of 32-bit unsigned integers\n     7. Float32Array: An array of 32-bit floating point numbers\n     8. Float64Array: An array of 64-bit floating point numbers\n\n     For example, you can create an array of 8-bit signed integers as below\n\n     ```js\n\n//\nconst a = new Int8Array();\n// You can pre-allocate n bytes\nconst bytes = 1024;\nconst a = new Int8Array(bytes);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the advantages of module loaders</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The module loaders provides the below features,\n\n1. Dynamic loading\n2. State isolation\n3. Global namespace isolation\n4. Compilation hooks\n5. Nested virtualization</code></pre></div>\n</li>\n<li>\n<p>What is collation</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Collation is used for sorting a set of strings and searching within a set of strings. It is parameterized by locale and aware of Unicode. Let's take comparison and sorting features,\n\n     1. **Comparison:**\n\n     ```js\n\n//\nvar list = ['ä', 'a', 'z']; // In German, \"ä\" sorts with \"a\" Whereas in Swedish, \"ä\" sorts after \"z\"\nvar l10nDE = new Intl.Collator('de');\nvar l10nSV = new Intl.Collator('sv');\nconsole.log(l10nDE.compare('ä', 'z') === -1); // true\nconsole.log(l10nSV.compare('ä', 'z') === +1); // true\n\n````\n\n     1. **Sorting:**\n\n     ```js\n\n//\nvar list = ['ä', 'a', 'z']; // In German, \"ä\" sorts with \"a\" Whereas in Swedish, \"ä\" sorts after \"z\"\nvar l10nDE = new Intl.Collator('de');\nvar l10nSV = new Intl.Collator('sv');\nconsole.log(list.sort(l10nDE.compare)); // [ \"a\", \"ä\", \"z\" ]\nconsole.log(list.sort(l10nSV.compare)); // [ \"a\", \"z\", \"ä\" ]\n````</code></pre></div>\n</li>\n<li>\n<p>What is for...of statement</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The for...of statement creates a loop iterating over iterable objects or elements such as built-in String, Array, Array-like objects (like arguments or NodeList), TypedArray, Map, Set, and user-defined iterables. The basic usage of for...of statement on arrays would be as below,\n\n     ```js\n\n//\nlet arrayIterable = [10, 20, 30, 40, 50];\n\n     for (let value of arrayIterable) {\n         value++;\n         console.log(value); // 11 21 31 41 51\n     }\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below spread operator array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ```js\n\n//\n[...'John Resig'];\n\n```\n\n     The output of the array is ['J', 'o', 'h', 'n', '', 'R', 'e', 's', 'i', 'g']\n     **Explanation:** The string is an iterable type and the spread operator within an array maps every character of an iterable to one element. Hence, each character of a string becomes an element within an Array.\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is PostMessage secure</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, postMessages can be considered very secure as long as the programmer/developer is careful about checking the origin and source of an arriving message. But if you try to send/receive a message without verifying its source will create cross-site scripting attacks.</code></pre></div>\n</li>\n<li>\n<p>What are the problems with postmessage target origin as wildcard</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The second argument of postMessage method specifies which origin is allowed to receive the message. If you use the wildcard \"\\*\" as an argument then any origin is allowed to receive the message. In this case, there is no way for the sender window to know if the target window is at the target origin when sending the message. If the target window has been navigated to another origin, the other origin would receive the data. Hence, this may lead to XSS vulnerabilities.\n\n     ```js\n\n//\ntargetWindow.postMessage(message, '\\*');\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you avoid receiving postMessages from attackers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Since the listener listens for any message, an attacker can trick the application by sending a message from the attacker's origin, which gives an impression that the receiver received the message from the actual sender's window. You can avoid this issue by validating the origin of the message on the receiver's end using the \"message.origin\" attribute. For examples, let's check the sender's origin [http://www.some-sender.com](http://www.some-sender.com) on receiver side [www.some-receiver.com](www.some-receiver.com),\n\n     ```js\n\n//\n//Listener on http://www.some-receiver.com/\nwindow.addEventListener(\"message\", function(message){\nif(/^http://www\\.some-sender\\.com$/.test(message.origin)){\nconsole.log('You received the data from valid sender', message.data);\n}\n});\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Can I avoid using postMessages completely</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You cannot avoid using postMessages completely(or 100%). Even though your application doesn't use postMessage considering the risks, a lot of third party scripts use postMessage to communicate with the third party service. So your application might be using postMessage without your knowledge.</code></pre></div>\n</li>\n<li>\n<p>Is postMessages synchronous</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The postMessages are synchronous in IE8 browser but they are asynchronous in IE9 and all other modern browsers (i.e, IE9+, Firefox, Chrome, Safari).Due to this asynchronous behaviour, we use a callback mechanism when the postMessage is returned.</code></pre></div>\n</li>\n<li>\n<p>What paradigm is Javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">JavaScript is a multi-paradigm language, supporting imperative/procedural programming, Object-Oriented Programming and functional programming. JavaScript supports Object-Oriented Programming with prototypical inheritance.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between internal and external javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">**Internal JavaScript:** It is the source code within the script tag.\n**External JavaScript:** The source code is stored in an external file(stored with .js extension) and referred with in the tag.</code></pre></div>\n</li>\n<li>\n<p>Is JavaScript faster than server side script</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Yes, JavaScript is faster than server side script. Because JavaScript is a client-side script it does not require any web server's help for its computation or calculation. So JavaScript is always faster than any server-side script like ASP, PHP, etc.</code></pre></div>\n</li>\n<li>\n<p>How do you get the status of a checkbox</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can apply the `checked` property on the selected checkbox in the DOM. If the value is `True` means the checkbox is checked otherwise it is unchecked. For example, the below HTML checkbox element can be access using javascript as below,\n\n     ```html\n     &lt;input type=\"checkbox\" name=\"checkboxname\" value=\"Agree\" /> Agree the conditions&lt;br />\n     ```\n\n     ```js\n\n//\nconsole.log(document.getElementById('checkboxname').checked); // true or false\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of double tilde operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">The double tilde operator(~~) is known as double NOT bitwise operator. This operator is going to be a quicker substitute for Math.floor().</code></pre></div>\n</li>\n<li>\n<p>How do you convert character to ASCII code</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use the `String.prototype.charCodeAt()` method to convert string characters to ASCII numbers. For example, let's find ASCII code for the first letter of 'ABC' string,\n\n     ```js\n\n//\n'ABC'.charCodeAt(0); // returns 65\n\n````\n\n     Whereas `String.fromCharCode()` method converts numbers to equal ASCII characters.\n\n     ```js\n\n//\nString.fromCharCode(65, 66, 67); // returns 'ABC'\n````</code></pre></div>\n</li>\n<li>\n<p>What is ArrayBuffer</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You can create it as below,\n\n     ```js\n\n//\nlet buffer = new ArrayBuffer(16); // create a buffer of length 16\nalert(buffer.byteLength); // 16\n\n````\n\n     To manipulate an ArrayBuffer, we need to use a \"view\" object.\n\n     ```js\n\n//\n//Create a DataView referring to the buffer\nlet view = new DataView(buffer);\n````</code></pre></div>\n</li>\n<li>\n<p>What is the output of below string expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     ```js\n\n//\nconsole.log('Welcome to JS world'[0]);\n\n```\n\n     The output of the above expression is \"W\".\n     **Explanation:** The bracket notation with specific index on a string returns the character at a specific location. Hence, it returns the character \"W\" of the string. Since this is not supported in IE7 and below versions, you may need to use the .charAt() method to get the desired result.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of Error object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Error constructor creates an error object and the instances of error objects are thrown when runtime errors occur. The Error object can also be used as a base object for user-defined exceptions. The syntax of error object would be as below,\n\n     ```js\n\n//\nnew Error([message[, fileName[, lineNumber]]])\n\n````\n\n     You can throw user defined exceptions or errors using Error object in try...catch block as below,\n\n     ```js\n\n//\ntry {\nif (withdraw > balance) throw new Error(\"Oops! You don't have enough balance\");\n} catch (e) {\nconsole.log(e.name + ': ' + e.message);\n}\n````</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of EvalError object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The EvalError object indicates an error regarding the global `eval()` function. Even though this exception is not thrown by JavaScript anymore, the EvalError object remains for compatibility. The syntax of this expression would be as below,\n\n     ```js\n\n//\nnew EvalError([message[, fileName[, lineNumber]]])\n\n````\n\n     You can throw EvalError with in try...catch block as below,\n\n     ```js\n\n//\ntry {\nthrow new EvalError('Eval function error', 'someFile.js', 100);\n} catch (e) {\nconsole.log(e.message, e.name, e.fileName); // \"Eval function error\", \"EvalError\", \"someFile.js\"\n````</code></pre></div>\n</li>\n<li>\n<p>What are the list of cases error thrown from non-strict mode to strict mode</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     When you apply 'use strict'; syntax, some of the below cases will throw a SyntaxError before executing the script\n\n     1. When you use Octal syntax\n\n     ```js\n\n//\nvar n = 022;\n\n````\n\n     1. Using `with` statement\n     2. When you use delete operator on a variable name\n     3. Using eval or arguments as variable or function argument name\n     4. When you use newly reserved keywords\n     5. When you declare a function in a block\n\n     ```js\n\n//\nif (someCondition) {\nfunction f() {}\n}\n````\n\n     Hence, the errors from above cases are helpful to avoid errors in development/production environments.</code></pre></div>\n</li>\n<li>\n<p>Do all objects have prototypes</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">No. All objects have prototypes except for the base object which is created by the user, or an object that is created using the new keyword.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between a parameter and an argument</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Parameter is the variable name of a function definition whereas an argument represents the value given to a function when it is invoked. Let's explain this with a simple function\n\n     ```js\n\n//\nfunction myFunction(parameter1, parameter2, parameter3) {\nconsole.log(arguments[0]); // \"argument1\"\nconsole.log(arguments[1]); // \"argument2\"\nconsole.log(arguments[2]); // \"argument3\"\n}\nmyFunction('argument1', 'argument2', 'argument3');\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of some method in arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The some() method is used to test whether at least one element in the array passes the test implemented by the provided function. The method returns a boolean value. Let's take an example to test for any odd elements,\n\n     ```js\n\n//\nvar array = [1, 2, 3, 4, 5, 6 ,7, 8, 9, 10];\n\n     var odd = element ==> element % 2 !== 0;\n\n     console.log(array.some(odd)); // true (the odd element exists)\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you combine two or more arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The concat() method is used to join two or more arrays by returning a new array containing all the elements. The syntax would be as below,\n\n     ```js\n\n//\narray1.concat(array2, array3, ..., arrayX)\n\n````\n\n     Let's take an example of array's concatenation with veggies and fruits arrays,\n\n     ```js\n\n//\nvar veggies = ['Tomato', 'Carrot', 'Cabbage'];\nvar fruits = ['Apple', 'Orange', 'Pears'];\nvar veggiesAndFruits = veggies.concat(fruits);\nconsole.log(veggiesAndFruits); // Tomato, Carrot, Cabbage, Apple, Orange, Pears\n````</code></pre></div>\n</li>\n<li>\n<p>What is the difference between Shallow and Deep copy</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are two ways to copy an object,\n\n     **Shallow Copy:**\n     Shallow copy is a bitwise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the reference addresses are copied i.e., only the memory address is copied.\n\n     **Example**\n\n     ```js\n\n//\nvar empDetails = {\nname: 'John',\nage: 25,\nexpertise: 'Software Developer'\n};\n\n````\n\n     to create a duplicate\n\n     ```js\n\n//\nvar empDetailsShallowCopy = empDetails; //Shallow copying!\n````\n\n     if we change some property value in the duplicate one like this:\n\n     ```js\n\n//\nempDetailsShallowCopy.name = 'Johnson';\n\n````\n\n     The above statement will also change the name of `empDetails`, since we have a shallow copy. That means we're losing the original data as well.\n\n     **Deep copy:**\n     A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. A deep copy occurs when an object is copied along with the objects to which it refers.\n\n     **Example**\n\n     ```js\n\n//\nvar empDetails = {\nname: 'John',\nage: 25,\nexpertise: 'Software Developer'\n};\n````\n\n     Create a deep copy by using the properties from the original object into new variable\n\n     ```js\n\n//\nvar empDetailsDeepCopy = {\nname: empDetails.name,\nage: empDetails.age,\nexpertise: empDetails.expertise\n};\n\n```\n\n     Now if you change `empDetailsDeepCopy.name`, it will only affect `empDetailsDeepCopy` &amp; not `empDetails`\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create specific number of copies of a string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `repeat()` method is used to construct and return a new string which contains the specified number of copies of the string on which it was called, concatenated together. Remember that this method has been added to the ECMAScript 2015 specification.\n     Let's take an example of Hello string to repeat it 4 times,\n\n     ```js\n\n//\n'Hello'.repeat(4); // 'HelloHelloHelloHello'\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you return all matching strings against a regular expression</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `matchAll()` method can be used to return an iterator of all results matching a string against a regular expression. For example, the below example returns an array of matching string results against a regular expression,\n\n     ```js\n\n//\nlet regexp = /Hello(\\d?))/g;\nlet greeting = 'Hello1Hello2Hello3';\n\n     let greetingList = [...greeting.matchAll(regexp)];\n\n     console.log(greetingList[0]); //Hello1\n     console.log(greetingList[1]); //Hello2\n     console.log(greetingList[2]); //Hello3\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you trim a string at the beginning or ending</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `trim` method of string prototype is used to trim on both sides of a string. But if you want to trim especially at the beginning or ending of the string then you can use `trimStart/trimLeft` and `trimEnd/trimRight` methods. Let's see an example of these methods on a greeting message,\n\n     ```js\n\n//\nvar greeting = ' Hello, Goodmorning! ';\n\n     console.log(greeting); // \"   Hello, Goodmorning!   \"\n     console.log(greeting.trimStart()); // \"Hello, Goodmorning!   \"\n     console.log(greeting.trimLeft()); // \"Hello, Goodmorning!   \"\n\n     console.log(greeting.trimEnd()); // \"   Hello, Goodmorning!\"\n     console.log(greeting.trimRight()); // \"   Hello, Goodmorning!\"\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is the output of below console statement with unary operator</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Let's take console statement with unary operator as given below,\n\n     ```js\n\n//\nconsole.log(+'Hello');\n\n```\n\n     The output of the above console log statement returns NaN. Because the element is prefixed by the unary operator and the JavaScript interpreter will try to convert that element into a number type. Since the conversion fails, the value of the statement results in NaN value.\n\n```</code></pre></div>\n</li>\n<li>Does javascript uses mixins</li>\n<li>\n<p>What is a thunk function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     A thunk is just a function which delays the evaluation of the value. It doesn't take any arguments but gives the value whenever you invoke the thunk. i.e, It is used not to execute now but it will be sometime in the future. Let's take a synchronous example,\n\n     ```js\n\n//\nconst add = (x, y) => x + y;\n\n     const thunk = () => add(2, 3);\n\n     thunk(); // 5\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are asynchronous thunks</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The asynchronous thunks are useful to make network requests. Let's see an example of network requests,\n\n     ```js\n\n//\nfunction fetchData(fn) {\nfetch('https://jsonplaceholder.typicode.com/todos/1')\n.then((response) => response.json())\n.then((json) => fn(json));\n}\n\n     const asyncThunk = function () {\n         return fetchData(function getData(data) {\n             console.log(data);\n         });\n     };\n\n     asyncThunk();\n     ```\n\n     The `getData` function won't be called immediately but it will be invoked only when the data is available from API endpoint. The setTimeout function is also used to make our code asynchronous. The best real time example is redux state management library which uses the asynchronous thunks to delay the actions to dispatch.</code></pre></div>\n</li>\n<li>\n<p>What is the output of below function calls</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     **Code snippet:**\n\n     ```js\n\n//\nconst circle = {\nradius: 20,\ndiameter() {\nreturn this.radius _ 2;\n},\nperimeter: () => 2 _ Math.PI \\* this.radius\n};\n\n```\n\n     console.log(circle.diameter());\n     console.log(circle.perimeter());\n\n     **Output:**\n\n     The output is 40 and NaN. Remember that diameter is a regular function, whereas the value of perimeter is an arrow function. The `this` keyword of a regular function(i.e, diameter) refers to the surrounding scope which is a class(i.e, Shape object). Whereas this keyword of perimeter function refers to the surrounding scope which is a window object. Since there is no radius property on window objects it returns an undefined value and the multiple of number value returns NaN value.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How to remove all line breaks from a string</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The easiest approach is using regular expressions to detect and replace newlines in the string. In this case, we use replace function along with string to replace with, which in our case is an empty string.\n\n     ```js\n\n//\nfunction remove_linebreaks( var message ) {\nreturn message.replace( /[\\r\\n]+/gm, \"\" );\n}\n\n```\n\n     In the above expression, g and m are for global and multiline flags.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the difference between reflow and repaint</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A _repaint_ occurs when changes are made which affect the visibility of an element, but not its layout. Examples of this include outline, visibility, or background color. A _reflow_ involves changes that affect the layout of a portion of the page (or the whole page). Resizing the browser window, changing the font, content changing (such as user typing text), using JavaScript methods involving computed styles, adding or removing elements from the DOM, and changing an element's classes are a few of the things that can trigger reflow. Reflow of an element causes the subsequent reflow of all child and ancestor elements as well as any elements following it in the DOM.</code></pre></div>\n</li>\n<li>\n<p>What happens with negating an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Negating an array with `!` character will coerce the array into a boolean. Since Arrays are considered to be truthy So negating it will return `false`.\n\n     ```js\n\n//\nconsole.log(![]); // false\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What happens if we add two arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If you add two arrays together, it will convert them both to strings and concatenate them. For example, the result of adding arrays would be as below,\n\n     ```js\n\n//\nconsole.log(['a'] + ['b']); // \"ab\"\nconsole.log([] + []); // \"\"\nconsole.log(![] + []); // \"false\", because ![] returns false.\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the output of prepend additive operator on falsy values</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If you prepend the additive(+) operator on falsy values(null, undefined, NaN, false, \"\"), the falsy value converts to a number value zero. Let's display them on browser console as below,\n\n     ```js\n\n//\nconsole.log(+null); // 0\nconsole.log(+undefined); // NaN\nconsole.log(+false); // 0\nconsole.log(+NaN); // NaN\nconsole.log(+''); // 0\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create self string using special characters</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The self string can be formed with the combination of `[]()!+` characters. You need to remember the below conventions to achieve this pattern.\n\n     1. Since Arrays are truthful values, negating the arrays will produce false: ![] === false\n     2. As per JavaScript coercion rules, the addition of arrays together will toString them: [] + [] === \"\"\n     3. Prepend an array with + operator will convert an array to false, the negation will make it true and finally converting the result will produce value '1': +(!(+[])) === 1\n\n     By applying the above rules, we can derive below conditions\n\n     ```js\n\n//\n(![] + [] === 'false' + !+[]) === 1;\n\n````\n\n     Now the character pattern would be created as below,\n\n     ```js\n\n//\ns e l f\n^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^^^^^^^^^^^\n\n      (![] + [])[3] + (![] + [])[4] + (![] + [])[2] + (![] + [])[0]\n      ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^   ^^^^^^^^^^^^^\n     (![] + [])[+!+[]+!+[]+!+[]] +\n     (![] + [])[+!+[]+!+[]+!+[]+!+[]] +\n     (![] + [])[+!+[]+!+[]] +\n     (![] + [])[+[]]\n     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n     (![]+[])[+!+[]+!+[]+!+[]]+(![]+[])[+!+[]+!+[]+!+[]+!+[]]+(![]+[])[+!+[]+!+[]]+(![]+[])[+[]]\n     ```\n\n````</code></pre></div>\n</li>\n<li>\n<p>How do you remove falsy values from an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can apply the filter method on the array by passing Boolean as a parameter. This way it removes all falsy values(0, undefined, null, false and \"\") from the array.\n\n     ```js\n\n//\nconst myArray = [false, null, 1, 5, undefined];\nmyArray.filter(Boolean); // [1, 5] // is same as myArray.filter(x => x);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you get unique values of an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can get unique values of an array with the combination of `Set` and rest expression/spread(...) syntax.\n\n     ```js\n\n//\nconsole.log([...new Set([1, 2, 4, 4, 3])]); // [1, 2, 4, 3]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is destructuring aliases</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Sometimes you would like to have a destructured variable with a different name than the property name. In that case, you'll use a `: newName` to specify a name for the variable. This process is called destructuring aliases.\n\n     ```js\n\n//\nconst obj = { x: 1 };\n// Grabs obj.x as as { otherName }\nconst { x: otherName } = obj;\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you map the array values without using map method</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can map the array values without using the `map` method by just using the `from` method of Array. Let's map city names from Countries array,\n\n     ```js\n\n//\nconst countries = [\n{ name: 'India', capital: 'Delhi' },\n{ name: 'US', capital: 'Washington' },\n{ name: 'Russia', capital: 'Moscow' },\n{ name: 'Singapore', capital: 'Singapore' },\n{ name: 'China', capital: 'Beijing' },\n{ name: 'France', capital: 'Paris' }\n];\n\n     const cityNames = Array.from(countries, ({ capital }) => capital);\n     console.log(cityNames); // ['Delhi, 'Washington', 'Moscow', 'Singapore', 'Beijing', 'Paris']\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you empty an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can empty an array quickly by setting the array length to zero.\n\n     ```js\n\n//\nlet cities = ['Singapore', 'Delhi', 'London'];\ncities.length = 0; // cities becomes []\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you rounding numbers to certain decimals</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can round numbers to a certain number of decimals using `toFixed` method from native javascript.\n\n     ```js\n\n//\nlet pie = 3.141592653;\npie = pie.toFixed(3); // 3.142\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to convert an array to an object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can convert an array to an object with the same data using spread(...) operator.\n\n     ```js\n\n//\nvar fruits = ['banana', 'apple', 'orange', 'watermelon'];\nvar fruitsObject = { ...fruits };\nconsole.log(fruitsObject); // {0: \"banana\", 1: \"apple\", 2: \"orange\", 3: \"watermelon\"}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create an array with some data</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can create an array with some data or an array with the same values using `fill` method.\n\n     ```js\n\n//\nvar newArray = new Array(5).fill('0');\nconsole.log(newArray); // [\"0\", \"0\", \"0\", \"0\", \"0\"]\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What are the placeholders from console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Below are the list of placeholders available from console object,\n\n     1. %o — It takes an object,\n     2. %s — It takes a string,\n     3. %d — It is used for a decimal or integer\n        These placeholders can be represented in the console.log as below\n\n     ```js\n\n//\nconst user = { name: 'John', id: 1, city: 'Delhi' };\nconsole.log('Hello %s, your details %o are available in the object form', 'John', user); // Hello John, your details {name: \"John\", id: 1, city: \"Delhi\"} are available in object\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is it possible to add CSS to console messages</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, you can apply CSS styles to console messages similar to html text on the web page.\n\n     ```js\n\n//\nconsole.log('%c The text has blue color, with large font and red background', 'color: blue; font-size: x-large; background: red');\n\n```\n\n     The text will be displayed as below,\n     ![Screenshot](images/console-css.png)\n\n     **Note:** All CSS styles can be applied to console messages.\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the purpose of dir method of console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `console.dir()` is used to display an interactive list of the properties of the specified JavaScript object as JSON.\n\n     ```js\n\n//\nconst user = { name: 'John', id: 1, city: 'Delhi' };\nconsole.dir(user);\n\n```\n\n     The user object displayed in JSON representation\n     ![Screenshot](images/console-dir.png)\n\n```</code></pre></div>\n</li>\n<li>\n<p>Is it possible to debug HTML elements in console</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Yes, it is possible to get and debug HTML elements in the console just like inspecting elements.\n\n     ```js\n\n//\nconst element = document.getElementsByTagName('body')[0];\nconsole.log(element);\n\n```\n\n     It prints the HTML element in the console,\n\n     ![Screenshot](images/console-html.png)\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you display data in a tabular format using console object</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `console.table()` is used to display data in the console in a tabular format to visualize complex arrays or objects.\n\n     ```js\n\n//\nconst users = [\n{ name: 'John', id: 1, city: 'Delhi' },\n{ name: 'Max', id: 2, city: 'London' },\n{ name: 'Rod', id: 3, city: 'Paris' }\n];\nconsole.table(users);\n\n```\n\n     The data visualized in a table format,\n\n     ![Screenshot](images/console-table.png)\n     **Not:** Remember that `console.table()` is not supported in IE.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you verify that an argument is a Number or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The combination of IsNaN and isFinite methods are used to confirm whether an argument is a number or not.\n\n     ```js\n\n//\nfunction isNumber(n) {\nreturn !isNaN(parseFloat(n)) &amp;&amp; isFinite(n);\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you create copy to clipboard button</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You need to select the content(using .select() method) of the input element and execute the copy command with execCommand (i.e, execCommand('copy')). You can also execute other system commands like cut and paste.\n\n     ```js\n\n//\ndocument.querySelector('#copy-button').onclick = function () {\n// Select the content\ndocument.querySelector('#copy-input').select();\n// Copy to the clipboard\ndocument.execCommand('copy');\n};\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the shortcut to get timestamp</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `new Date().getTime()` to get the current timestamp. There is an alternative shortcut to get the value.\n\n     ```js\n\n//\nconsole.log(+new Date());\nconsole.log(Date.now());\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you flattening multi dimensional arrays</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Flattening bi-dimensional arrays is trivial with Spread operator.\n\n     ```js\n\n//\nconst biDimensionalArr = [11, [22, 33], [44, 55], [66, 77], 88, 99];\nconst flattenArr = [].concat(...biDimensionalArr); // [11, 22, 33, 44, 55, 66, 77, 88, 99]\n\n````\n\n     But you can make it work with multi-dimensional arrays by recursive calls,\n\n     ```js\n\n//\nfunction flattenMultiArray(arr) {\nconst flattened = [].concat(...arr);\nreturn flattened.some((item) => Array.isArray(item)) ? flattenMultiArray(flattened) : flattened;\n}\nconst multiDimensionalArr = [11, [22, 33], [44, [55, 66, [77, [88]], 99]]];\nconst flatArr = flattenMultiArray(multiDimensionalArr); // [11, 22, 33, 44, 55, 66, 77, 88, 99]\n````</code></pre></div>\n</li>\n<li>\n<p>What is the easiest multi condition checking</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `indexOf` to compare input with multiple values instead of checking each value as one condition.\n\n     ```js\n\n//\n// Verbose approach\nif (input === 'first' || input === 1 || input === 'second' || input === 2) {\nsomeFunction();\n}\n// Shortcut\nif (['first', 1, 'second', 2].indexOf(input) !== -1) {\nsomeFunction();\n}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you capture browser back button</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The `window.onbeforeunload` method is used to capture browser back button events. This is helpful to warn users about losing the current data.\n\n     ```js\n\n//\nwindow.onbeforeunload = function () {\nalert('You work will be lost');\n};\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you disable right click in the web page</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The right click on the page can be disabled by returning false from the `oncontextmenu` attribute on the body element.\n\n     ```html\n     &lt;body oncontextmenu=\"return false;\">\n\n&lt;/body>\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are wrapper objects</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Primitive Values like string,number and boolean don't have properties and methods but they are temporarily converted or coerced to an object(Wrapper object) when you try to perform actions on them. For example, if you apply toUpperCase() method on a primitive string value, it does not throw an error but returns uppercase of the string.\n\n     ```js\n\n//\nlet name = 'john';\n\n     console.log(name.toUpperCase()); // Behind the scenes treated as console.log(new String(name).toUpperCase());\n     ```\n\n     i.e, Every primitive except null and undefined have Wrapper Objects and the list of wrapper objects are String,Number,Boolean,Symbol and BigInt.</code></pre></div>\n</li>\n<li>\n<p>What is AJAX</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">AJAX stands for Asynchronous JavaScript and XML and it is a group of related technologies(HTML, CSS, JavaScript, XMLHttpRequest API etc) used to display data asynchronously. i.e. We can send data to the server and get data from the server without reloading the web page.</code></pre></div>\n</li>\n<li>\n<p>What are the different ways to deal with Asynchronous Code</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of different ways to deal with Asynchronous code.\n\n1. Callbacks\n2. Promises\n3. Async/await\n4. Third-party libraries such as async.js,bluebird etc</code></pre></div>\n</li>\n<li>\n<p>How to cancel a fetch request</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Until a few days back, One shortcoming of native promises is no direct way to cancel a fetch request. But the new `AbortController` from js specification allows you to use a signal to abort one or multiple fetch calls.\n     The basic flow of cancelling a fetch request would be as below,\n\n     1. Create an `AbortController` instance\n     2. Get the signal property of an instance and pass the signal as a fetch option for signal\n     3. Call the AbortController's abort property to cancel all fetches that use that signal\n        For example, let's pass the same signal to multiple fetch calls will cancel all requests with that signal,\n\n     ```js\n\n//\nconst controller = new AbortController();\nconst { signal } = controller;\n\n     fetch('http://localhost:8000', { signal })\n         .then((response) => {\n             console.log(`Request 1 is complete!`);\n         })\n         .catch((e) => {\n             if (e.name === 'AbortError') {\n                 // We know it's been canceled!\n             }\n         });\n\n     fetch('http://localhost:8000', { signal })\n         .then((response) => {\n             console.log(`Request 2 is complete!`);\n         })\n         .catch((e) => {\n             if (e.name === 'AbortError') {\n                 // We know it's been canceled!\n             }\n         });\n\n     // Wait 2 seconds to abort both requests\n     setTimeout(() => controller.abort(), 2000);\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is web speech API</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Web speech API is used to enable modern browsers recognize and synthesize speech(i.e, voice data into web apps). This API has been introduced by W3C Community in the year 2012. It has two main parts,\n\n     1. **SpeechRecognition (Asynchronous Speech Recognition or Speech-to-Text):** It provides the ability to recognize voice context from an audio input and respond accordingly. This is accessed by the `SpeechRecognition` interface.\n        The below example shows on how to use this API to get text from speech,\n\n     ```js\n\n//\nwindow.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition; // webkitSpeechRecognition for Chrome and SpeechRecognition for FF\nconst recognition = new window.SpeechRecognition();\nrecognition.onresult = (event) => {\n// SpeechRecognitionEvent type\nconst speechToText = event.results[0][0].transcript;\nconsole.log(speechToText);\n};\nrecognition.start();\n\n````\n\n     In this API, browser is going to ask you for permission to use your microphone\n\n     1. **SpeechSynthesis (Text-to-Speech):** It provides the ability to recognize voice context from an audio input and respond. This is accessed by the `SpeechSynthesis` interface.\n        For example, the below code is used to get voice/speech from text,\n\n     ```js\n\n//\nif ('speechSynthesis' in window) {\nvar speech = new SpeechSynthesisUtterance('Hello World!');\nspeech.lang = 'en-US';\nwindow.speechSynthesis.speak(speech);\n}\n````\n\n     The above examples can be tested on chrome(33+) browser's developer console.\n     **Note:** This API is still a working draft and only available in Chrome and Firefox browsers(ofcourse Chrome only implemented the specification)</code></pre></div>\n</li>\n<li>\n<p>What is minimum timeout throttling</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Both browser and NodeJS javascript environments throttles with a minimum delay that is greater than 0ms. That means even though setting a delay of 0ms will not happen instantaneously.\n     **Browsers:** They have a minimum delay of 4ms. This throttle occurs when successive calls are triggered due to callback nesting(certain depth) or after a certain number of successive intervals.\n     Note: The older browsers have a minimum delay of 10ms.\n     **Nodejs:** They have a minimum delay of 1ms. This throttle happens when the delay is larger than 2147483647 or less than 1.\n     The best example to explain this timeout throttling behavior is the order of below code snippet.\n\n     ```js\n\n//\nfunction runMeFirst() {\nconsole.log('My script is initialized');\n}\nsetTimeout(runMeFirst, 0);\nconsole.log('Script loaded');\n\n````\n\n     and the output would be in\n\n     ```shell\n     Script loaded\n     My script is initialized\n     ```\n\n     If you don't use `setTimeout`, the order of logs will be sequential.\n\n     ```js\n\n//\nfunction runMeFirst() {\nconsole.log('My script is initialized');\n}\nrunMeFirst();\nconsole.log('Script loaded');\n````\n\n     and the output is,\n\n     ```shell\n     My script is initialized\n     Script loaded\n     ```</code></pre></div>\n</li>\n<li>\n<p>How do you implement zero timeout in modern browsers</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">You can't use setTimeout(fn, 0) to execute the code immediately due to minimum delay of greater than 0ms. But you can use window.postMessage() to achieve this behavior.</code></pre></div>\n</li>\n<li>\n<p>What are tasks in event loop</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A task is any javascript code/program which is scheduled to be run by the standard mechanisms such as initially starting to run a program, run an event callback, or an interval or timeout being fired. All these tasks are scheduled on a task queue.\nBelow are the list of use cases to add tasks to the task queue,\n\n1. When a new javascript program is executed directly from console or running by the `&lt;script>` element, the task will be added to the task queue.\n2. When an event fires, the event callback added to task queue\n3. When a setTimeout or setInterval is reached, the corresponding callback added to task queue</code></pre></div>\n</li>\n<li>\n<p>What is microtask</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Microtask is the javascript code which needs to be executed immediately after the currently executing task/microtask is completed. They are kind of blocking in nature. i.e, The main thread will be blocked until the microtask queue is empty.\nThe main sources of microtasks are Promise.resolve, Promise.reject, MutationObservers, IntersectionObservers etc\n\n**Note:** All of these microtasks are processed in the same turn of the event loop.</code></pre></div>\n</li>\n<li>What are different event loops</li>\n<li>What is the purpose of queueMicrotask</li>\n<li>\n<p>How do you use javascript libraries in typescript file</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is known that not all JavaScript libraries or frameworks have TypeScript declaration files. But if you still want to use libraries or frameworks in our TypeScript files without getting compilation errors, the only solution is `declare` keyword along with a variable declaration. For example, let's imagine you have a library called `customLibrary` that doesn't have a TypeScript declaration and have a namespace called `customLibrary` in the global namespace. You can use this library in typescript code as below,\n\n     ```js\n\n//\ndeclare var customLibrary;\n\n````\n\n     In the runtime, typescript will provide the type to the `customLibrary` variable as `any` type. The another alternative without using declare keyword is below\n\n     ```js\n\n//\nvar customLibrary: any;\n````</code></pre></div>\n</li>\n<li>\n<p>What are the differences between promises and observables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the major difference in a tabular form\n\n| Promises                                                           | Observables                                                                              |\n| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- |\n| Emits only a single value at a time                                | Emits multiple values over a period of time(stream of values ranging from 0 to multiple) |\n| Eager in nature; they are going to be called immediately           | Lazy in nature; they require subscription to be invoked                                  |\n| Promise is always asynchronous even though it resolved immediately | Observable can be either synchronous or asynchronous                                     |\n| Doesn't provide any operators                                      | Provides operators such as map, forEach, filter, reduce, retry, and retryWhen etc        |\n| Cannot be canceled                                                 | Canceled by using unsubscribe() method                                                   |</code></pre></div>\n</li>\n<li>\n<p>What is heap</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Heap(Or memory heap) is the memory location where objects are stored when we define variables. i.e, This is the place where all the memory allocations and de-allocation take place. Both heap and call-stack are two containers of JS runtime.\nWhenever runtime comes across variables and function declarations in the code it stores them in the Heap.\n\n![Screenshot](images/heap.png)</code></pre></div>\n</li>\n<li>\n<p>What is an event table</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Event Table is a data structure that stores and keeps track of all the events which will be executed asynchronously like after some time interval or after the resolution of some API requests. i.e Whenever you call a setTimeout function or invoke async operation, it is added to the Event Table.\nIt doesn't not execute functions on it's own. The main purpose of the event table is to keep track of events and send them to the Event Queue as shown in the below diagram.\n\n![Screenshot](images/event-table.png)</code></pre></div>\n</li>\n<li>\n<p>What is a microTask queue</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Microtask Queue is the new queue where all the tasks initiated by promise objects get processed before the callback queue.\nThe microtasks queue are processed before the next rendering and painting jobs. But if these microtasks are running for a long time then it leads to visual degradation.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between shim and polyfill</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">A shim is a library that brings a new API to an older environment, using only the means of that environment. It isn't necessarily restricted to a web application. For example, es5-shim.js is used to emulate ES5 features on older browsers (mainly pre IE9).\nWhereas polyfill is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively.\nIn a simple sentence, A polyfill is a shim for a browser API.</code></pre></div>\n</li>\n<li>\n<p>How do you detect primitive or non primitive value type</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     In JavaScript, primitive types include boolean, string, number, BigInt, null, Symbol and undefined. Whereas non-primitive types include the Objects. But you can easily identify them with the below function,\n\n     ```js\n\n//\nvar myPrimitive = 30;\nvar myNonPrimitive = {};\nfunction isPrimitive(val) {\nreturn Object(val) !== val;\n}\n\n     isPrimitive(myPrimitive);\n     isPrimitive(myNonPrimitive);\n     ```\n\n     If the value is a primitive data type, the Object constructor creates a new wrapper object for the value. But If the value is a non-primitive data type (an object), the Object constructor will give the same object.</code></pre></div>\n</li>\n<li>\n<p>What is babel</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Babel is a JavaScript transpiler to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments. Some of the main features are listed below,\n\n1. Transform syntax\n2. Polyfill features that are missing in your target environment (using @babel/polyfill)\n3. Source code transformations (or codemods)</code></pre></div>\n</li>\n<li>\n<p>Is Node.js completely single threaded</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Node is a single thread, but some of the functions included in the Node.js standard library(e.g, fs module functions) are not single threaded. i.e, Their logic runs outside of the Node.js single thread to improve the speed and performance of a program.</code></pre></div>\n</li>\n<li>\n<p>What are the common use cases of observables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Some of the most common use cases of observables are web sockets with push notifications, user input changes, repeating intervals, etc</code></pre></div>\n</li>\n<li>\n<p>What is RxJS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">RxJS (Reactive Extensions for JavaScript) is a library for implementing reactive programming using observables that makes it easier to compose asynchronous or callback-based code. It also provides utility functions for creating and working with observables.</code></pre></div>\n</li>\n<li>\n<p>What is the difference between Function constructor and function declaration</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The functions which are created with `Function constructor` do not create closures to their creation contexts but they are always created in the global scope. i.e, the function can access its own local variables and global scope variables only. Whereas function declarations can access outer function variables(closures) too.\n\n     Let's see this difference with an example,\n\n     **Function Constructor:**\n\n     ```js\n\n//\nvar a = 100;\nfunction createFunction() {\nvar a = 200;\nreturn new Function('return a;');\n}\nconsole.log(createFunction()()); // 100\n\n````\n\n     **Function declaration:**\n\n     ```js\n\n//\nvar a = 100;\nfunction createFunction() {\nvar a = 200;\nreturn function func() {\nreturn a;\n};\n}\nconsole.log(createFunction()()); // 200\n````</code></pre></div>\n</li>\n<li>\n<p>What is a Short circuit condition</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Short circuit conditions are meant for condensed way of writing simple if statements. Let's demonstrate the scenario using an example. If you would like to login to a portal with an authentication condition, the expression would be as below,\n\n     ```js\n\n//\nif (authenticate) {\nloginToPorta();\n}\n\n````\n\n     Since the javascript logical operators evaluated from left to right, the above expression can be simplified using &amp;&amp; logical operator\n\n     ```js\n\n//\nauthenticate &amp;&amp; loginToPorta();\n````</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to resize an array</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The length property of an array is useful to resize or empty an array quickly. Let's apply length property on number array to resize the number of elements from 5 to 2,\n\n     ```js\n\n//\nvar array = [1, 2, 3, 4, 5];\nconsole.log(array.length); // 5\n\n     array.length = 2;\n     console.log(array.length); // 2\n     console.log(array); // [1,2]\n     ```\n\n     and the array can be emptied too\n\n     ```js\n\n//\nvar array = [1, 2, 3, 4, 5];\narray.length = 0;\nconsole.log(array.length); // 0\nconsole.log(array); // []\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is an observable</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An Observable is basically a function that can return a stream of values either synchronously or asynchronously to an observer over time. The consumer can get the value by calling `subscribe()` method.\n     Let's look at a simple example of an Observable\n\n     ```js\n\n//\nimport { Observable } from 'rxjs';\n\n     const observable = new Observable((observer) => {\n         setTimeout(() => {\n             observer.next('Message from a Observable!');\n         }, 3000);\n     });\n\n     observable.subscribe((value) => console.log(value));\n     ```\n\n     ![Screenshot](images/observables.png)\n\n     **Note:** Observables are not part of the JavaScript language yet but they are being proposed to be added to the language</code></pre></div>\n</li>\n<li>\n<p>What is the difference between function and class declarations</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The main difference between function declarations and class declarations is `hoisting`. The function declarations are hoisted but not class declarations.\n\n     **Classes:**\n\n     ```js\n\n//\nconst user = new User(); // ReferenceError\n\n     class User {}\n     ```\n\n     **Constructor Function:**\n\n     ```js\n\n//\nconst user = new User(); // No error\n\n     function User() {}\n     ```</code></pre></div>\n</li>\n<li>\n<p>What is an async function</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     An async function is a function declared with the `async` keyword which enables asynchronous, promise-based behavior to be written in a cleaner style by avoiding promise chains. These functions can contain zero or more `await` expressions.\n\n     Let's take a below async function example,\n\n     ```js\n\n//\nasync function logger() {\nlet data = await fetch('http://someapi.com/users'); // pause until fetch returns\nconsole.log(data);\n}\nlogger();\n\n```\n\n     It is basically syntax sugar over ES2015 promises and generators.\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do you prevent promises swallowing errors</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     While using asynchronous code, JavaScript's ES6 promises can make your life a lot easier without having callback pyramids and error handling on every second line. But Promises have some pitfalls and the biggest one is swallowing errors by default.\n\n     Let's say you expect to print an error to the console for all the below cases,\n\n     ```js\n\n//\nPromise.resolve('promised value').then(function () {\nthrow new Error('error');\n});\n\n     Promise.reject('error value').catch(function () {\n         throw new Error('error');\n     });\n\n     new Promise(function (resolve, reject) {\n         throw new Error('error');\n     });\n     ```\n\n     But there are many modern JavaScript environments that won't print any errors. You can fix this problem in different ways,\n\n     1. **Add catch block at the end of each chain:** You can add catch block to the end of each of your promise chains\n\n         ```js\n\n//\nPromise.resolve('promised value')\n.then(function () {\nthrow new Error('error');\n})\n.catch(function (error) {\nconsole.error(error.stack);\n});\n\n````\n\n         But it is quite difficult to type for each promise chain and verbose too.\n\n     2. **Add done method:** You can replace first solution's then and catch blocks with done method\n\n         ```js\n\n//\nPromise.resolve('promised value').done(function () {\nthrow new Error('error');\n});\n````\n\n         Let's say you want to fetch data using HTTP and later perform processing on the resulting data asynchronously. You can write `done` block as below,\n\n         ```js\n\n//\ngetDataFromHttp()\n.then(function (result) {\nreturn processDataAsync(result);\n})\n.done(function (processed) {\ndisplayData(processed);\n});\n\n````\n\n         In future, if the processing library API changed to synchronous then you can remove `done` block as below,\n\n         ```js\n\n//\ngetDataFromHttp().then(function (result) {\nreturn displayData(processDataAsync(result));\n});\n````\n\n         and then you forgot to add `done` block to `then` block leads to silent errors.\n\n     3. **Extend ES6 Promises by Bluebird:**\n        Bluebird extends the ES6 Promises API to avoid the issue in the second solution. This library has a \"default\" onRejection handler which will print all errors from rejected Promises to stderr. After installation, you can process unhandled rejections\n\n         ```js\n\n//\nPromise.onPossiblyUnhandledRejection(function (error) {\nthrow error;\n});\n\n````\n\n         and discard a rejection, just handle it with an empty catch\n\n         ```js\n\n//\nPromise.reject('error value').catch(function () {});\n````</code></pre></div>\n</li>\n<li>\n<p>What is deno</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 JavaScript engine and the Rust programming language.</code></pre></div>\n</li>\n<li>\n<p>How do you make an object iterable in javascript</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     By default, plain objects are not iterable. But you can make the object iterable by defining a `Symbol.iterator` property on it.\n\n     Let's demonstrate this with an example,\n\n     ```js\n\n//\nconst collection = {\none: 1,\ntwo: 2,\nthree: 3,\n[Symbol.iterator]() {\nconst values = Object.keys(this);\nlet i = 0;\nreturn {\nnext: () => {\nreturn {\nvalue: this[values[i++]],\ndone: i > values.length\n};\n}\n};\n}\n};\n\n     const iterator = collection[Symbol.iterator]();\n\n     console.log(iterator.next()); // → {value: 1, done: false}\n     console.log(iterator.next()); // → {value: 2, done: false}\n     console.log(iterator.next()); // → {value: 3, done: false}\n     console.log(iterator.next()); // → {value: undefined, done: true}\n     ```\n\n     The above process can be simplified using a generator function,\n\n     ```js\n\n//\nconst collection = {\none: 1,\ntwo: 2,\nthree: 3,\n[Symbol.iterator]: function\\* () {\nfor (let key in this) {\nyield this[key];\n}\n}\n};\nconst iterator = collection[Symbol.iterator]();\nconsole.log(iterator.next()); // {value: 1, done: false}\nconsole.log(iterator.next()); // {value: 2, done: false}\nconsole.log(iterator.next()); // {value: 3, done: false}\nconsole.log(iterator.next()); // {value: undefined, done: true}\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is a Proper Tail Call</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     First, we should know about tail call before talking about \"Proper Tail Call\". A tail call is a subroutine or function call performed as the final action of a calling function. Whereas **Proper tail call(PTC)** is a technique where the program or code will not create additional stack frames for a recursion when the function call is a tail call.\n\n     For example, the below classic or head recursion of factorial function relies on stack for each step. Each step need to be processed upto `n * factorial(n - 1)`\n\n     ```js\n\n//\nfunction factorial(n) {\nif (n === 0) {\nreturn 1;\n}\nreturn n \\* factorial(n - 1);\n}\nconsole.log(factorial(5)); //120\n\n````\n\n     But if you use Tail recursion functions, they keep passing all the necessary data it needs down the recursion without relying on the stack.\n\n     ```js\n\n//\nfunction factorial(n, acc = 1) {\nif (n === 0) {\nreturn acc;\n}\nreturn factorial(n - 1, n \\* acc);\n}\nconsole.log(factorial(5)); //120\n````\n\n     The above pattern returns the same output as the first one. But the accumulator keeps track of total as an argument without using stack memory on recursive calls.</code></pre></div>\n</li>\n<li>\n<p>How do you check an object is a promise or not</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     If you don't know if a value is a promise or not, wrapping the value as `Promise.resolve(value)` which returns a promise\n\n     ```js\n\n//\nfunction isPromise(object) {\nif (Promise &amp;&amp; Promise.resolve) {\nreturn Promise.resolve(object) == object;\n} else {\nthrow 'Promise not supported in your environment';\n}\n}\n\n     var i = 1;\n     var promise = new Promise(function (resolve, reject) {\n         resolve();\n     });\n\n     console.log(isPromise(i)); // false\n     console.log(isPromise(p)); // true\n     ```\n\n     Another way is to check for `.then()` handler type\n\n     ```js\n\n//\nfunction isPromise(value) {\nreturn Boolean(value &amp;&amp; typeof value.then === 'function');\n}\nvar i = 1;\nvar promise = new Promise(function (resolve, reject) {\nresolve();\n});\n\n     console.log(isPromise(i)); // false\n     console.log(isPromise(promise)); // true\n     ```</code></pre></div>\n</li>\n<li>\n<p>How to detect if a function is called as constructor</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can use `new.target` pseudo-property to detect whether a function was called as a constructor(using the new operator) or as a regular function call.\n\n     1. If a constructor or function invoked using the new operator, new.target returns a reference to the constructor or function.\n     2. For function calls, new.target is undefined.\n\n     ```js\n\n//\nfunction Myfunc() {\nif (new.target) {\nconsole.log('called with new');\n} else {\nconsole.log('not called with new');\n}\n}\n\n     new Myfunc(); // called with new\n     Myfunc(); // not called with new\n     Myfunc.call({}); not called with new\n     ```</code></pre></div>\n</li>\n<li>\n<p>What are the differences between arguments object and rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">There are three main differences between arguments object and rest parameters\n\n1. The arguments object is an array-like but not an array. Whereas the rest parameters are array instances.\n2. The arguments object does not support methods such as sort, map, forEach, or pop. Whereas these methods can be used in rest parameters.\n3. The rest parameters are only the ones that haven't been given a separate name, while the arguments object contains all arguments passed to the function</code></pre></div>\n</li>\n<li>\n<p>What are the differences between spread operator and rest parameter</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Rest parameter collects all remaining elements into an array. Whereas Spread operator allows iterables( arrays / objects / strings ) to be expanded into single arguments/elements. i.e, Rest parameter is opposite to the spread operator.</code></pre></div>\n</li>\n<li>\n<p>What are the different kinds of generators</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     There are five kinds of generators,\n\n     1. **Generator function declaration:**\n\n         ```js\n\n//\nfunction\\* myGenFunc() {\nyield 1;\nyield 2;\nyield 3;\n}\nconst genObj = myGenFunc();\n\n````\n\n     2. **Generator function expressions:**\n\n         ```js\n\n//\nconst myGenFunc = function\\* () {\nyield 1;\nyield 2;\nyield 3;\n};\nconst genObj = myGenFunc();\n````\n\n     3. **Generator method definitions in object literals:**\n\n         ```js\n\n//\nconst myObj = {\n\\*myGeneratorMethod() {\nyield 1;\nyield 2;\nyield 3;\n}\n};\nconst genObj = myObj.myGeneratorMethod();\n\n````\n\n     4. **Generator method definitions in class:**\n\n         ```js\n\n//\nclass MyClass {\n\\*myGeneratorMethod() {\nyield 1;\nyield 2;\nyield 3;\n}\n}\nconst myObject = new MyClass();\nconst genObj = myObject.myGeneratorMethod();\n````\n\n     5. **Generator as a computed property:**\n\n         ```js\n\n//\nconst SomeObj = { \\*[Symbol.iterator]() {\nyield 1;\nyield 2;\nyield 3;\n}\n};\n\n         console.log(Array.from(SomeObj)); // [ 1, 2, 3 ]\n         ```</code></pre></div>\n</li>\n<li>\n<p>What are the built-in iterables</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">Below are the list of built-in iterables in javascript,\n\n1. Arrays and TypedArrays\n2. Strings: Iterate over each character or Unicode code-points\n3. Maps: iterate over its key-value pairs\n4. Sets: iterates over their elements\n5. arguments: An array-like special variable in functions\n6. DOM collection such as NodeList</code></pre></div>\n</li>\n<li>\n<p>What are the differences between for...of and for...in statements</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Both for...in and for...of statements iterate over js data structures. The only difference is over what they iterate:\n\n     1. for..in iterates over all enumerable property keys of an object\n     2. for..of iterates over the values of an iterable object.\n\n     Let's explain this difference with an example,\n\n     ```js\n\n//\nlet arr = ['a', 'b', 'c'];\n\n     arr.newProp = 'newVlue';\n\n     // key are the property keys\n     for (let key in arr) {\n         console.log(key);\n     }\n\n     // value are the property values\n     for (let value of arr) {\n         console.log(value);\n     }\n     ```\n\n     Since for..in loop iterates over the keys of the object, the first loop logs 0, 1, 2 and newProp while iterating over the array object. The for..of loop iterates over the values of a arr data structure and logs a, b, c in the console.</code></pre></div>\n</li>\n<li>\n<p>How do you define instance and non-instance properties</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The Instance properties must be defined inside of class methods. For example, name and age properties defined insider constructor as below,\n\n     ```js\n\n//\nclass Person {\nconstructor(name, age) {\nthis.name = name;\nthis.age = age;\n}\n}\n\n````\n\n     But Static(class) and prototype data properties must be defined outside of the ClassBody declaration. Let's assign the age value for Person class as below,\n\n     ```js\n\n//\nPerson.staticAge = 30;\nPerson.prototype.prototypeAge = 40;\n````</code></pre></div>\n</li>\n<li>\n<p>What is the difference between isNaN and Number.isNaN?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     1. **isNaN**: The global function `isNaN` converts the argument to a Number and returns true if the resulting value is NaN.\n     2. **Number.isNaN**: This method does not convert the argument. But it returns true when the type is a Number and value is NaN.\n\n     Let's see the difference with an example,\n\n     ```js\n\n//\nisNaN('hello'); // true\nNumber.isNaN('hello'); // false\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How to invoke an IIFE without any extra brackets?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     Immediately Invoked Function Expressions(IIFE) requires a pair of parenthesis to wrap the function which contains set of statements.\n\n     ```js\n\n//\n(function (dt) {\nconsole.log(dt.toLocaleTimeString());\n})(new Date());\n\n````\n\n     Since both IIFE and void operator discard the result of an expression, you can avoid the extra brackets using `void operator` for IIFE as below,\n\n     ```js\n\n//\nvoid (function (dt) {\nconsole.log(dt.toLocaleTimeString());\n})(new Date());\n````</code></pre></div>\n</li>\n<li>\n<p>Is that possible to use expressions in switch cases?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You might have seen expressions used in switch condition but it is also possible to use for switch cases by assigning true value for the switch condition. Let's see the weather condition based on temparature as an example,\n\n     ```js\n\n//\nconst weather = (function getWeather(temp) {\nswitch (true) {\ncase temp &lt; 0:\nreturn 'freezing';\ncase temp &lt; 10:\nreturn 'cold';\ncase temp &lt; 24:\nreturn 'cool';\ndefault:\nreturn 'unknown';\n}\n})(10);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>What is the easiest way to ignore promise errors?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     The easiest and safest way to ignore promise errors is void that error. This approach is ESLint friendly too.\n\n     ```js\n\n//\nawait promise.catch((e) => void e);\n\n```\n\n```</code></pre></div>\n</li>\n<li>\n<p>How do style the console output using CSS?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     You can add CSS styling to the console output using the CSS format content specifier %c. The console string message can be appended after the specifier and CSS style in another argument. Let's print the red the color text using console.log and CSS specifier as below,\n\n     ```js\n\n//\nconsole.log('%cThis is a red text', 'color:red');\n\n````\n\n     It is also possible to add more styles for the content. For example, the font-size can be modified for the above text\n\n     ```js\n\n//\nconsole.log('%cThis is a red text with bigger font', 'color:red; font-size:20px');\n````</code></pre></div>\n</li>\n<li>\n<p>What is nullish coalescing operator (??)?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">     It is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. This can be contrasted with the logical OR (||) operator, which returns the right-hand side operand if the left operand is any falsy value, not only null or undefined.\n\n     ```js\n\n//\nconsole.log(null ?? true); // true\nconsole.log(false ?? true); // false\nconsole.log(undefined ?? true); // true\n\n```\n\n```</code></pre></div>\n</li>\n</ol>\n<h3>Coding Exercise</h3>\n<h4>1. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Vehicle</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Honda'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'white'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'2010'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'UK'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Vehicle</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">model<span class=\"token punctuation\">,</span> color<span class=\"token punctuation\">,</span> year<span class=\"token punctuation\">,</span> country</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>model <span class=\"token operator\">=</span> model<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>color <span class=\"token operator\">=</span> color<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>year <span class=\"token operator\">=</span> year<span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>country <span class=\"token operator\">=</span> country<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>Undefined</li>\n<li>2: ReferenceError</li>\n<li>3: null</li>\n<li>4: {model: \"Honda\", color: \"white\", year: \"2010\", country: \"UK\"}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The function declarations are hoisted similar to any variables. So the placement for <code class=\"language-text\">Vehicle</code> function declaration doesn't make any difference.</p>\n</p>\n</details>\n<hr>\n<h4>2. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> x <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    x<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    y<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> x<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> x<span class=\"token punctuation\">,</span> <span class=\"token keyword\">typeof</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, undefined and undefined</li>\n<li>2: ReferenceError: X is not defined</li>\n<li>3: 1, undefined and number</li>\n<li>4: 1, number and number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Of course the return value of <code class=\"language-text\">foo()</code> is 1 due to the increment operator. But the statement <code class=\"language-text\">let x = y = 0</code> declares a local variable x. Whereas y declared as a global variable accidentally. This statement is equivalent to,</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> x<span class=\"token punctuation\">;</span>\nwindow<span class=\"token punctuation\">.</span>y <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\nx <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span>y<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Since the block scoped variable x is undefined outside of the function, the type will be undefined too. Whereas the global variable <code class=\"language-text\">y</code> is available outside the function, the value is 0 and type is number.</p>\n</p>\n</details>\n<hr>\n<h4>3. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">main</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'A'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'B'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'C'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token function\">m</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>A, B and C</li>\n<li>2: B, A and C</li>\n<li>3: A and C</li>\n<li>4: A, C and B</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The statements order is based on the event loop mechanism. The order of statements follows the below order,</p>\n<ol>\n<li>At first, the main function is pushed to the stack.</li>\n<li>Then the browser pushes the fist statement of the main function( i.e, A's console.log) to the stack, executing and popping out immediately.</li>\n<li>But <code class=\"language-text\">setTimeout</code> statement moved to Browser API to apply the delay for callback.</li>\n<li>In the meantime, C's console.log added to stack, executed and popped out.</li>\n<li>The callback of <code class=\"language-text\">setTimeout</code> moved from Browser API to message queue.</li>\n<li>The <code class=\"language-text\">main</code> function popped out from stack because there are no statements to execute</li>\n<li>The callback moved from message queue to the stack since the stack is empty.</li>\n<li>The console.log for B is added to the stack and display on the console.</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>4. What is the output of below equality check</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">0.1</span> <span class=\"token operator\">+</span> <span class=\"token number\">0.2</span> <span class=\"token operator\">===</span> <span class=\"token number\">0.3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>This is due to the float point math problem. Since the floating point numbers are encoded in binary format, the addition operations on them lead to rounding errors. Hence, the comparison of floating points doesn't give expected results.\nYou can find more details about the explanation here <a href=\"https://0.30000000000000004.com/\">0.30000000000000004.com/</a></p>\n</p>\n</details>\n<hr>\n<h4>5. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">f</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    y <span class=\"token operator\">+=</span> <span class=\"token keyword\">typeof</span> f<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1function</li>\n<li>2: 1object</li>\n<li>3: ReferenceError</li>\n<li>4: 1undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The main points in the above code snippets are,</p>\n<ol>\n<li>You can see function expression instead function declaration inside if statement. So it always returns true.</li>\n<li>Since it is not declared(or assigned) anywhere, f is undefined and typeof f is undefined too.</li>\n</ol>\n<p>In other words, it is same as</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    y <span class=\"token operator\">+=</span> <span class=\"token keyword\">typeof</span> f<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Note:</strong> It returns 1object for MS Edge browser</p>\n</p>\n</details>\n<hr>\n<h4>6. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Hello World</li>\n<li>2: Object {message: \"Hello World\"}</li>\n<li>3: Undefined</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>This is a semicolon issue. Normally semicolons are optional in JavaScript. So if there are any statements(in this case, return) missing semicolon, it is automatically inserted immediately. Hence, the function returned as undefined.</p>\n<p>Whereas if the opening curly brace is along with the return keyword then the function is going to be returned as expected.</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">message</span><span class=\"token operator\">:</span> <span class=\"token string\">'Hello World'</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">foo</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// {message: \"Hello World\"}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>7. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> myChars <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'d'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">delete</span> myChars<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myChars<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[empty, 'b', 'c', 'd'], empty, 3</li>\n<li>2: [null, 'b', 'c', 'd'], empty, 3</li>\n<li>3: [empty, 'b', 'c', 'd'], undefined, 4</li>\n<li>4: [null, 'b', 'c', 'd'], undefined, 4</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The <code class=\"language-text\">delete</code> operator will delete the object property but it will not reindex the array or change its length. So the number or elements or length of the array won't be changed.\nIf you try to print myChars then you can observe that it doesn't set an undefined value, rather the property is removed from the array. The newer versions of Chrome use <code class=\"language-text\">empty</code> instead of <code class=\"language-text\">undefined</code> to make the difference a bit clearer.</p>\n</p>\n</details>\n<hr>\n<h4>8. What is the output of below code in latest Chrome</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> array1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> array2 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\narray2<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array2<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> array3 <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[undefined × 3], [undefined × 2, 100], [undefined × 3]</li>\n<li>2: [empty × 3], [empty × 2, 100], [empty × 3]</li>\n<li>3: [null × 3], [null × 2, 100], [null × 3]</li>\n<li>4: [], [100], []</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The latest chrome versions display <code class=\"language-text\">sparse array</code>(they are filled with holes) using this empty x n notation. Whereas the older versions have undefined x n notation.\n<strong>Note:</strong> The latest version of FF displays <code class=\"language-text\">n empty slots</code> notation.</p>\n</p>\n</details>\n<hr>\n<h4>9. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function-variable function\">prop1</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">prop2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'prop'</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop1</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop2</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">.</span><span class=\"token function\">prop3</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>0, 1, 2</li>\n<li>2: 0, { return 1 }, 2</li>\n<li>3: 0, { return 1 }, { return 2 }</li>\n<li>4: 0, 1, undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>ES6 provides method definitions and property shorthands for objects. So both prop2 and prop3 are treated as regular function values.</p>\n</p>\n</details>\n<hr>\n<h4>10. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">2</span> <span class=\"token operator\">&lt;</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span> <span class=\"token operator\">></span> <span class=\"token number\">2</span> <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>true, true</li>\n<li>2: true, false</li>\n<li>3: SyntaxError, SyntaxError,</li>\n<li>4: false, false</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The important point is that if the statement contains the same operators(e.g, &#x3C; or >) then it can be evaluated from left to right.\nThe first statement follows the below order,</p>\n<ol>\n<li>console.log(1 &#x3C; 2 &#x3C; 3);</li>\n<li>console.log(true &#x3C; 3);</li>\n<li>console.log(1 &#x3C; 3); // True converted as <code class=\"language-text\">1</code> during comparison</li>\n<li>True</li>\n</ol>\n<p>Whereas the second statement follows the below order,</p>\n<ol>\n<li>console.log(3 > 2 > 1);</li>\n<li>console.log(true > 1);</li>\n<li>console.log(1 > 1); // False converted as <code class=\"language-text\">0</code> during comparison</li>\n<li>False</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>11. What is the output of below code in non-strict mode</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">printNumbers</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\np <span class=\"token function\">tNumbers</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, 2, 3</li>\n<li>2: 3, 2, 3</li>\n<li>3: SyntaxError: Duplicate parameter name not allowed in this context</li>\n<li>4: 1, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>In non-strict mode, the regular JavaScript functions allow duplicate named parameters. The above code snippet has duplicate parameters on 1st and 3rd parameters.\nThe value of the first parameter is mapped to the third argument which is passed to the function. Hence, the 3rd argument overrides the first parameter.</p>\n<p><strong>Note:</strong> In strict mode, duplicate parameters will throw a Syntax Error.</p>\n</p>\n</details>\n<hr>\n<h4>12. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">printNumbersArrow</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">,</span> first<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\np <span class=\"token function\">tNumbersArrow</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, 2, 3</li>\n<li>2: 3, 2, 3</li>\n<li>3: SyntaxError: Duplicate parameter name not allowed in this context</li>\n<li>4: 1, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Unlike regular functions, the arrow functions doesn't not allow duplicate parameters in either strict or non-strict mode. So you can see <code class=\"language-text\">SyntaxError</code> in the console.</p>\n</p>\n</details>\n<hr>\n<h4>13. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">arrowFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">arrowFunc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>ReferenceError: arguments is not defined</li>\n<li>2: 3</li>\n<li>3: undefined</li>\n<li>4: null</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Arrow functions do not have an <code class=\"language-text\">arguments, super, this, or new.target</code> bindings. So any reference to <code class=\"language-text\">arguments</code> variable tries to resolve to a binding in a lexically enclosing environment. In this case, the arguments variable is not defined outside of the arrow function. Hence, you will receive a reference error.</p>\n<p>Where as the normal function provides the number of arguments passed to the function</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">func</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>But If you still want to use an arrow function then rest operator on arguments provides the expected arguments</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">arrowFunc</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token operator\">...</span>args</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> args<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">arrowFunc</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>14. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>trimLeft<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'trimLeft'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">String</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>trimLeft<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token string\">'trimStart'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: True, False</li>\n<li>2: False, True</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>In order to be consistent with functions like <code class=\"language-text\">String.prototype.padStart</code>, the standard method name for trimming the whitespaces is considered as <code class=\"language-text\">trimStart</code>. Due to web web compatibility reasons, the old method name 'trimLeft' still acts as an alias for 'trimStart'. Hence, the prototype for 'trimLeft' is always 'trimStart'</p>\n</p>\n</details>\n<hr>\n<h4>15. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined</li>\n<li>2: Infinity</li>\n<li>3: 0</li>\n<li>4: -Infinity</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>-Infinity is the initial comparant because almost every other value is bigger. So when no arguments are provided, -Infinity is going to be returned.\n<strong>Note:</strong> Zero number of arguments is a valid case.</p>\n</p>\n</details>\n<hr>\n<h4>16. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">==</span> <span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">==</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>True, True</li>\n<li>2: True, False</li>\n<li>3: False, False</li>\n<li>4: False, True</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>As per the comparison algorithm in the ECMAScript specification(ECMA-262), the above expression converted into JS as below</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token number\">10</span> <span class=\"token operator\">===</span> <span class=\"token function\">Number</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">10</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">valueOf</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 10</span></code></pre></div>\n<p>So it doesn't matter about number brackets([]) around the number, it is always converted to a number in the expression.</p>\n</p>\n</details>\n<hr>\n<h4>17. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">+</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span> <span class=\"token operator\">-</span> <span class=\"token string\">'10'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>20, 0</li>\n<li>2: 1010, 0</li>\n<li>3: 1010, 10-10</li>\n<li>4: NaN, NaN</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The concatenation operator(+) is applicable for both number and string types. So if any operand is string type then both operands concatenated as strings. Whereas subtract(-) operator tries to convert the operands as number type.</p>\n</p>\n</details>\n<hr>\n<h4>18. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">==</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm True\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"I'm False\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>True, I'm True</li>\n<li>2: True, I'm False</li>\n<li>3: False, I'm True</li>\n<li>4: False, I'm False</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>In comparison operators, the expression <code class=\"language-text\">[0]</code> converted to Number([0].valueOf().toString()) which is resolved to false. Whereas <code class=\"language-text\">[0]</code> just becomes a truthy value without any conversion because there is no comparison operator.</p>\n</p>\n</details>\n<h4>19. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[1,2,3,4]</li>\n<li>2: [1,2][3,4]</li>\n<li>3: SyntaxError</li>\n<li>4: 1,23,4</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The + operator is not meant or defined for arrays. So it converts arrays into strings and concatenates them.</p>\n</p>\n</details>\n<hr>\n<h4>20. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> numbers <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> browser <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Firefox'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>browser<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}</li>\n<li>2: {1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"}</li>\n<li>3: [1, 2, 3, 4], [\"F\", \"i\", \"r\", \"e\", \"o\", \"x\"]</li>\n<li>4: {1, 1, 2, 3, 4}, {\"F\", \"i\", \"r\", \"e\", \"f\", \"o\", \"x\"}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Since <code class=\"language-text\">Set</code> object is a collection of unique values, it won't allow duplicate values in the collection. At the same time, it is case sensitive data structure.</p>\n</p>\n</details>\n<hr>\n<h4>21. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span> <span class=\"token operator\">===</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: True</li>\n<li>2: False</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>JavaScript follows IEEE 754 spec standards. As per this spec, NaNs are never equal for floating-point numbers.</p>\n</p>\n</details>\n<hr>\n<h4>22. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>4</li>\n<li>2: NaN</li>\n<li>3: SyntaxError</li>\n<li>4: -1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The <code class=\"language-text\">indexOf</code> uses strict equality operator(===) internally and <code class=\"language-text\">NaN === NaN</code> evaluates to false. Since indexOf won't be able to find NaN inside an array, it returns -1 always.\nBut you can use <code class=\"language-text\">Array.prototype.findIndex</code> method to find out the index of NaN in an array or You can use <code class=\"language-text\">Array.prototype.includes</code> to check if NaN is present in an array or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> numbers <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">NaN</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">findIndex</span><span class=\"token punctuation\">(</span>Number<span class=\"token punctuation\">.</span>isNaN<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 4</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>numbers<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// true</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>23. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, [2, 3, 4, 5]</li>\n<li>2: 1, {2, 3, 4, 5}</li>\n<li>3: SyntaxError</li>\n<li>4: 1, [2, 3, 4]</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>When using rest parameters, trailing commas are not allowed and will throw a SyntaxError.\nIf you remove the trailing comma then it displays 1st answer</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> <span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>b<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// 1, [2, 3, 4, 5]</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>25. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Promise {&#x3C;fulfilled>: 10}</li>\n<li>2: 10</li>\n<li>3: SyntaxError</li>\n<li>4: Promise {&#x3C;rejected>: 10}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Async functions always return a promise. But even if the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise. The above async function is equivalent to below expression,</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>26. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Promise {&#x3C;fulfilled>: 10}</li>\n<li>2: 10</li>\n<li>3: SyntaxError</li>\n<li>4: Promise {&#x3C;resolved>: undefined}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The await expression returns value 10 with promise resolution and the code after each await expression can be treated as existing in a <code class=\"language-text\">.then</code> callback. In this case, there is no return expression at the end of the function. Hence, the default return value of <code class=\"language-text\">undefined</code> is returned as the resolution of the promise. The above async function is equivalent to below expression,</p>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">func</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Promise<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>27. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">processArray</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\np <span class=\"token function\">essArray</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: 1, 2, 3, 4</li>\n<li>3: 4, 4, 4, 4</li>\n<li>4: 4, 3, 2, 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Even though \"processArray\" is an async function, the anonymous function that we use for <code class=\"language-text\">forEach</code> is synchronous. If you use await inside a synchronous function then it throws a syntax error.</p>\n</p>\n</details>\n<hr>\n<h4>28. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>resolve<span class=\"token punctuation\">,</span> <span class=\"token number\">2000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">await</span> <span class=\"token function\">delay</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">process</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    array<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">item</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Process completed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\np <span class=\"token function\">ess</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1 2 3 5 and Process completed!</li>\n<li>2: 5 5 5 5 and Process completed!</li>\n<li>3: Process completed! and 5 5 5 5</li>\n<li>4: Process completed! and 1 2 3 5</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The forEach method will not wait until all items are finished but it just runs the tasks and goes next. Hence, the last statement is displayed first followed by a sequence of promise resolutions.</p>\n<p>But you control the array sequence using for..of loop,</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">async</span> <span class=\"token keyword\">function</span> <span class=\"token function\">processArray</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">array</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> item <span class=\"token keyword\">of</span> array<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">await</span> <span class=\"token function\">delayedLog</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Process completed!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>29. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">var</span> set <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Set</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nset<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'+0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">NaN</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>set<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Set(4) {\"+0\", \"-0\", NaN, undefined}</li>\n<li>2: Set(3) {\"+0\", NaN, undefined}</li>\n<li>3: Set(5) {\"+0\", \"-0\", NaN, undefined, NaN}</li>\n<li>4: Set(4) {\"+0\", NaN, undefined, NaN}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>Set has few exceptions from equality check,</p>\n<ol>\n<li>All NaN values are equal</li>\n<li>Both +0 and -0 considered as different values</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>30. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> sym1 <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> sym2 <span class=\"token operator\">=</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> sym3 <span class=\"token operator\">=</span> Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> sym4 <span class=\"token operator\">=</span> Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'two'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nc oe<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sym1 <span class=\"token operator\">===</span> sym2<span class=\"token punctuation\">,</span> sym3 <span class=\"token operator\">===</span> sym4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>true, true</li>\n<li>2: true, false</li>\n<li>3: false, true</li>\n<li>4: false, false</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>Symbol follows below conventions,</p>\n<ol>\n<li>Every symbol value returned from Symbol() is unique irrespective of the optional string.</li>\n<li><code class=\"language-text\">Symbol.for()</code> function creates a symbol in a global symbol registry list. But it doesn't necessarily create a new symbol on every call, it checks first if a symbol with the given key is already present in the registry and returns the symbol if it is found. Otherwise a new symbol created in the registry.</li>\n</ol>\n<p><strong>Note:</strong> The symbol description is just useful for debugging purposes.</p>\n</p>\n</details>\n<hr>\n<h4>31. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> sym1 <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>sym1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: one</li>\n<li>3: Symbol('one')</li>\n<li>4: Symbol</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p><code class=\"language-text\">Symbol</code> is a just a standard function and not an object constructor(unlike other primitives new Boolean, new String and new Number). So if you try to call it with the new operator will result in a TypeError</p>\n</p>\n</details>\n<hr>\n<h4>32. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> myNumber <span class=\"token operator\">=</span> <span class=\"token number\">100</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> myString <span class=\"token operator\">=</span> <span class=\"token string\">'100'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myNumber <span class=\"token operator\">===</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is not a string!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is a string!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token keyword\">typeof</span> myString <span class=\"token operator\">===</span> <span class=\"token string\">'number'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is not a number!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'It is a number!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: It is not a string!, It is not a number!</li>\n<li>3: It is not a string!, It is a number!</li>\n<li>4: It is a string!, It is a number!</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The return value of <code class=\"language-text\">typeof myNumber (OR) typeof myString</code> is always the truthy value (either \"number\" or \"string\"). Since ! operator converts the value to a boolean value, the value of both <code class=\"language-text\">!typeof myNumber or !typeof myString</code> is always false. Hence the if condition fails and control goes to else block.</p>\n</p>\n</details>\n<hr>\n<h4>33. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">myArray</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">undefined</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token function\">Symbol</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token operator\">:</span> <span class=\"token string\">'one'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>Symbol<span class=\"token punctuation\">.</span><span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token string\">'one'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{\"myArray\":['one', undefined, {}, Symbol]}, {}</li>\n<li>2: {\"myArray\":['one', null,null,null]}, {}</li>\n<li>3: {\"myArray\":['one', null,null,null]}, \"{ [Symbol.for('one')]: 'one' }, [Symbol.for('one')]\"</li>\n<li>4: {\"myArray\":['one', undefined, function(){}, Symbol('')]}, {}</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>The symbols has below constraints,</p>\n<ol>\n<li>The undefined, Functions, and Symbols are not valid JSON values. So those values are either omitted (in an object) or changed to null (in an array). Hence, it returns null values for the value array.</li>\n<li>All Symbol-keyed properties will be completely ignored. Hence it returns an empty object({}).</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>34. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">A</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">new</span><span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">B</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">A</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">new</span> <span class=\"token class-name\">A</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nn <span class=\"token constant\">B</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: A, A</li>\n<li>2: A, B</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Using constructors, <code class=\"language-text\">new.target</code> refers to the constructor (points to the class definition of class which is initialized) that was directly invoked by new. This also applies to the case if the constructor is in a parent class and was delegated from a child constructor.</p>\n</p>\n</details>\n<hr>\n<h4>35. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span>x<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>y<span class=\"token punctuation\">,</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1, [2, 3, 4]</li>\n<li>2: 1, [2, 3]</li>\n<li>3: 1, [2]</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It throws a syntax error because the rest element should not have a trailing comma. You should always consider using a rest operator as the last element.</p>\n</p>\n</details>\n<hr>\n<h4>36. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> x <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">b</span><span class=\"token operator\">:</span> y <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">a</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30, 20</li>\n<li>2: 10, 20</li>\n<li>3: 10, undefined</li>\n<li>4: 30, undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The object property follows below rules,</p>\n<ol>\n<li>The object properties can be retrieved and assigned to a variable with a different name</li>\n<li>The property assigned a default value when the retrieved value is <code class=\"language-text\">undefined</code></li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>37. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">a</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>200</li>\n<li>2: Error</li>\n<li>3: undefined</li>\n<li>4: 0</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>If you leave out the right-hand side assignment for the destructuring object, the function will look for at least one argument to be supplied when invoked. Otherwise you will receive an error <code class=\"language-text\">Error: Cannot read property 'length' of undefined</code> as mentioned above.</p>\n<p>You can avoid the error with either of the below changes,</p>\n<ol>\n<li><strong>Pass at least an empty object:</strong></li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ol start=\"2\">\n<li><strong>Assign default empty object:</strong></li>\n</ol>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> length <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span> width <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>length <span class=\"token operator\">*</span> width<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n</p>\n</details>\n<hr>\n<h4>38. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> props <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'John'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Jack'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'Tom'</span> <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> name <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> props<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>Tom</li>\n<li>2: Error</li>\n<li>3: undefined</li>\n<li>4: John</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>It is possible to combine Array and Object destructuring. In this case, the third element in the array props accessed first followed by name property in the object.</p>\n</p>\n</details>\n<hr>\n<h4>39. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">num <span class=\"token operator\">=</span> <span class=\"token number\">1</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">undefined</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">checkType</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc <span class=\"token function\">kType</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>number, undefined, string, object</li>\n<li>2: undefined, undefined, string, object</li>\n<li>3: number, number, string, object</li>\n<li>4: number, number, number, number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>If the function argument is set implicitly(not passing argument) or explicitly to undefined, the value of the argument is the default parameter. Whereas for other falsy values('' or null), the value of the argument is passed as a parameter.</p>\n<p>Hence, the result of function calls categorized as below,</p>\n<ol>\n<li>The first two function calls logs number type since the type of default value is number</li>\n<li>The type of '' and null values are string and object type respectively.</li>\n</ol>\n</p>\n</details>\n<hr>\n<h4>40. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">item<span class=\"token punctuation\">,</span> items <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    items<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> items<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Orange'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Apple'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: ['Orange'], ['Orange', 'Apple']</li>\n<li>2: ['Orange'], ['Apple']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Since the default argument is evaluated at call time, a new object is created each time the function is called. So in this case, the new array is created and an element pushed to the default empty array.</p>\n</p>\n</details>\n<hr>\n<h4>41. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">greet</span><span class=\"token punctuation\">(</span>greeting<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">,</span> message <span class=\"token operator\">=</span> greeting <span class=\"token operator\">+</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> name<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>greeting<span class=\"token punctuation\">,</span> name<span class=\"token punctuation\">,</span> message<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">greet</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\ng <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Good morning!'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: ['Hello', 'John', 'Hello John'], ['Hello', 'John', 'Good morning!']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Since parameters defined earlier are available to later default parameters, this code snippet doesn't throw any error.</p>\n</p>\n</details>\n<hr>\n<h4>42. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">outer</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f <span class=\"token operator\">=</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">function</span> <span class=\"token function\">inner</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">'Inner'</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\no <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: ReferenceError</li>\n<li>2: Inner</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The functions and variables declared in the function body cannot be referred from default value parameter initializers. If you still try to access, it throws a run-time ReferenceError(i.e, <code class=\"language-text\">inner</code> is not defined).</p>\n</p>\n</details>\n<hr>\n<h4>43. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">myFun</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">x<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> <span class=\"token operator\">...</span>manyMoreArgs</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>manyMoreArgs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">myFun</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">4</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nm <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>[3, 4, 5], undefined</li>\n<li>2: SyntaxError</li>\n<li>3: [3, 4, 5], []</li>\n<li>4: [3, 4, 5], [undefined]</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The rest parameter is used to hold the remaining parameters of a function and it becomes an empty array if the argument is not provided.</p>\n</p>\n</details>\n<hr>\n<h4>44. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'value'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> array <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token operator\">...</span>obj<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>array<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>['key', 'value']</li>\n<li>2: TypeError</li>\n<li>3: []</li>\n<li>4: ['key']</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Spread syntax can be applied only to iterable objects. By default, Objects are not iterable, but they become iterable when used in an Array, or with iterating functions such as <code class=\"language-text\">map(), reduce(), and assign()</code>. If you still try to do it, it still throws <code class=\"language-text\">TypeError: obj is not iterable</code>.</p>\n</p>\n</details>\n<hr>\n<h4>45. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">myGenFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1</li>\n<li>2: undefined</li>\n<li>3: SyntaxError</li>\n<li>4: TypeError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>Generators are not constructible type. But if you still proceed to do, there will be an error saying \"TypeError: myGenFunc is not a constructor\"</p>\n</p>\n</details>\n<hr>\n<h4>46. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> myGenObj <span class=\"token operator\">=</span> <span class=\"token function\">yieldAndReturn</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>myGenObj<span class=\"token punctuation\">.</span><span class=\"token function\">next</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>{ value: 1, done: false }, { value: 2, done: true }, { value: undefined, done: true }</li>\n<li>2: { value: 1, done: false }, { value: 2, done: false }, { value: undefined, done: true }</li>\n<li>3: { value: 1, done: false }, { value: 2, done: true }, { value: 3, done: true }</li>\n<li>4: { value: 1, done: false }, { value: 2, done: false }, { value: 3, done: true }</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>A return statement in a generator function will make the generator finish. If a value is returned, it will be set as the value property of the object and done property to true. When a generator is finished, subsequent next() calls return an object of this form: <code class=\"language-text\">{value: undefined, done: true}</code>.</p>\n</p>\n</details>\n<hr>\n<h4>47. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> myGenerator <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span><span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">2</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">yield</span> <span class=\"token number\">3</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> value <span class=\"token keyword\">of</span> myGenerator<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>1,2,3 and 1,2,3</li>\n<li>2: 1,2,3 and 4,5,6</li>\n<li>3: 1 and 1</li>\n<li>4: 1</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>The generator should not be re-used once the iterator is closed. i.e, Upon exiting a loop(on completion or using break &#x26; return), the generator is closed and trying to iterate over it again does not yield any more results. Hence, the second loop doesn't print any value.</p>\n</p>\n</details>\n<hr>\n<h4>48. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> num <span class=\"token operator\">=</span> 0o38<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>num<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: SyntaxError</li>\n<li>2: 38</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>If you use an invalid number(outside of 0-7 range) in the octal literal, JavaScript will throw a SyntaxError. In ES5, it treats the octal literal as a decimal number.</p>\n</p>\n</details>\n<hr>\n<h4>49. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> squareObj <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Square</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>squareObj<span class=\"token punctuation\">.</span>area<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Square</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">length</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">get</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">*</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">set</span> <span class=\"token function\">area</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">value</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>area <span class=\"token operator\">=</span> value<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>1: 100</li>\n<li>2: ReferenceError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Unlike function declarations, class declarations are not hoisted. i.e, First You need to declare your class and then access it, otherwise it will throw a ReferenceError \"Uncaught ReferenceError: Square is not defined\".</p>\n<p><strong>Note:</strong> Class expressions also applies to the same hoisting restrictions of class declarations.</p>\n</p>\n</details>\n<hr>\n<h4>50. What is the output of below code</h4>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token class-name\">Person</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">walk</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nPerson<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">run</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> user <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Person</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> walk <span class=\"token operator\">=</span> user<span class=\"token punctuation\">.</span>walk<span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">walk</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">let</span> run <span class=\"token operator\">=</span> Person<span class=\"token punctuation\">.</span>run<span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>undefined, undefined</li>\n<li>2: Person, Person</li>\n<li>3: SyntaxError</li>\n<li>4: Window, Window</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>When a regular or prototype method is called without a value for <strong>this</strong>, the methods return an initial this value if the value is not undefined. Otherwise global window object will be returned. In our case, the initial <code class=\"language-text\">this</code> value is undefined so both methods return window objects.</p>\n</p>\n</details>\n<hr>\n<h4>51. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">constructor</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">name</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> name<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> vehicle started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">Car</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Vehicle</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>name<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\"> car started</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">super</span><span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> car <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Car</span><span class=\"token punctuation\">(</span><span class=\"token string\">'BMW'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>car<span class=\"token punctuation\">.</span><span class=\"token function\">start</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>SyntaxError</li>\n<li>2: BMW vehicle started, BMW car started</li>\n<li>3: BMW car started, BMW vehicle started</li>\n<li>4: BMW car started, BMW car started</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 3</h5>\n<p>The super keyword is used to call methods of a superclass. Unlike other languages the super invocation doesn't need to be a first statement. i.e, The statements will be executed in the same order of code.</p>\n</p>\n</details>\n<hr>\n<h4>52. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> <span class=\"token constant\">USER</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">age</span><span class=\"token operator\">:</span> <span class=\"token number\">30</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age <span class=\"token operator\">=</span> <span class=\"token number\">25</span><span class=\"token punctuation\">;</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token constant\">USER</span><span class=\"token punctuation\">.</span>age<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>30</li>\n<li>2: 25</li>\n<li>3: Uncaught TypeError</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Even though we used constant variables, the content of it is an object and the object's contents (e.g properties) can be altered. Hence, the change is going to be valid in this case.</p>\n</p>\n</details>\n<hr>\n<h4>53. What is the output of below code</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'🙂'</span> <span class=\"token operator\">===</span> <span class=\"token string\">'🙂'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>1: false</li>\n<li>2: true</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 2</h5>\n<p>Emojis are unicodes and the unicode for smile symbol is \"U+1F642\". The unicode comparision of same emojies is equivalent to string comparison. Hence, the output is always true.</p>\n</p>\n</details>\n<hr>\n<h4>54. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token keyword\">typeof</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>string</li>\n<li>2: boolean</li>\n<li>3: NaN</li>\n<li>4: number</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>The typeof operator on any primitive returns a string value. So even if you apply the chain of typeof operators on the return value, it is always string.</p>\n</p>\n</details>\n<hr>\n<h4>55. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> zero <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Number</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>zero<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'If'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Else'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<ul>\n<li>If</li>\n<li>2: Else</li>\n<li>3: NaN</li>\n<li>4: SyntaxError</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<ol>\n<li>The type of operator on new Number always returns object. i.e, typeof new Number(0) --> object.</li>\n<li>Objects are always truthy in if block</li>\n</ol>\n<p>Hence the above code block always goes to if section.</p>\n</p>\n</details>\n<hr>\n<h4>55. What is the output of below code in non strict mode?</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> msg <span class=\"token operator\">=</span> <span class=\"token string\">'Good morning!!'</span><span class=\"token punctuation\">;</span>\n\nmsg<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'John'</span><span class=\"token punctuation\">;</span>\n\nc ole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>msg<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>\"\"</li>\n<li>2: Error</li>\n<li>3: John</li>\n<li>4: Undefined</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 4</h5>\n<p>It returns undefined for non-strict mode and returns Error for strict mode. In non-strict mode, the wrapper object is going to be created and get the mentioned property. But the object get disappeared after accessing the property in next line.</p>\n</p>\n</details>\n<hr>\n<h4>56. What is the output of below code?</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">innerFunc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">===</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> count <span class=\"token operator\">=</span> <span class=\"token number\">11</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">;</span></code></pre></div>\n<ul>\n<li>11, 10</li>\n<li>2: 11, 11</li>\n<li>3: 10, 11</li>\n<li>4: 10, 10</li>\n</ul>\n<details>\n<summary>\n<b>Answer</b>\n</summary>\n<p>\n<h5>Answer: 1</h5>\n<p>11 and 10 is logged to the console.</p>\n<p>The innerFunc is a closure which captures the count variable from the outerscope. i.e, 10. But the conditional has another local variable <code class=\"language-text\">count</code> which overwrites the ourter <code class=\"language-text\">count</code> variable. So the first console.log displays value 11.\nWhereas the second console.log logs 10 by capturing the count variable from outerscope.</p>\n</p>\n</details>\n<hr>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;/details></code></pre></div>"},{"url":"/docs/reference/bookmarks/","relativePath":"docs/reference/bookmarks.md","relativeDir":"docs/reference","base":"bookmarks.md","name":"bookmarks","frontmatter":{"title":"Web Dev Bookmarks","weight":0,"excerpt":"Web Dev Bookmarks","seo":{"title":"Bookmarks","description":"Web Dev Bookmarks","robots":[],"extra":[]},"template":"docs"},"html":"<h1>Web Dev Bookmarks</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"   style=\"resize:both; overflow:scroll;\"  src=\"https://bgoonz-bookmarks.netlify.app/\" height=\"800px\" width=\"1000px\" scrolling=\"yes\"   frameborder=\"yes\" loading=\"lazy\"  allowfullscreen=\"true\"  frameborder=\"0\" >\n</iframe>\n<br>\n<h1>Frontend Development <a href=\"https://github.com/sindresorhus/awesome\"><img src=\"https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg\" alt=\"Awesome\"></a></h1>\n<hr>\n<h2>Appearance</h2>\n<p>The outward or visible aspect of a website.</p>\n<ul>\n<li>\n<p><strong>Animation</strong>: The process of creating motion and shape change.</p>\n<ul>\n<li><strong><a href=\"http://daneden.github.io/animate.css/\">Animate.css</a></strong>: Just-add-water CSS animations.</li>\n<li><strong><a href=\"https://github.com/machito/animate.less\">Animate.less</a></strong>: A bunch of cool, fun, and cross-browser animations converted into LESS for you to use in your Bootstrap projects.</li>\n<li><strong><a href=\"https://github.com/juliangarnier/anime\">Anime.js</a></strong>: Anime is a flexible yet lightweight JavaScript animation library. It works with CSS, Individual Transforms, SVG, DOM attributes and JS Objects.</li>\n<li><strong><a href=\"http://srobbin.com/jquery-plugins/approach/\">Approach</a></strong>: A jQuery plugin that allows you to animate CSS properties based on distance to an object.</li>\n<li><strong><a href=\"http://jsfiddle.net/simurai/CGmCe/light/\">CSS Spritesheet Animation Example</a></strong>: Sprite Sheet animation with CSS3 using the steps() feature.</li>\n<li><strong><a href=\"http://hyperandroid.github.io/CAAT/\">Caat</a></strong>: Scene graph director-based animation framework for javascript.</li>\n<li><strong><a href=\"http://www.arahaya.com/canvasscript3/\">CanvasScript3</a></strong>: CanvasScript3 is a Javascript library for the new HTML5 Canvas with an interface similar to ActionScript3. This library enables Sprite Groups, Layers, Mouse Events, Keyboard Events, Bitmap Effects, Tween Animations etc.</li>\n<li><strong><a href=\"http://jindo.dev.naver.com/collie/\">Collie</a></strong>: Collie is a Javascript library that helps to create highly optimized animations and games using HTML 5. Collie runs on both PC and mobile using HTML 5 canvas and DOM.</li>\n<li><strong><a href=\"https://github.com/madrobby/emile\">Emile.js</a></strong>: Emile.js is a no-frills stand-alone CSS animation JavaScript framework.</li>\n<li><strong><a href=\"http://extralogical.net/projects/firmin/\">Firmin</a></strong>: Firmin is a JavaScript animation library using CSS transforms and transitions.</li>\n<li>\n<p><strong><a href=\"http://www.greensock.com/get-started-js/\">GreenSock Animation Platform</a></strong>: GreenSock Animation Platform is a suite of tools for scripted animation.</p>\n<ul>\n<li><strong><a href=\"http://codepen.io/GreenSock/\">Codepen Repository</a></strong>: Codepen repository with examples of Greensock usage and code.</li>\n<li><strong><a href=\"http://ahrengot.com/tutorials/greensock-javascript-animation/\">Examples</a></strong>: Here are a couple of examples demonstrating the core features of the Greensock Animation Platform.</li>\n<li><strong><a href=\"http://www.greensock.com/learning/\">Learning Center</a></strong>: Tutorials and videos for GreenSock Animation Platform.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://ricostacruz.com/jquery.transit/\">JQuery Transit</a></strong>: Super-smooth CSS3 transformations and transitions for jQuery.</li>\n<li><strong><a href=\"https://github.com/MikeMcTiernan/Janis\">Janis</a></strong>: Janis is a lightweight Javascript framework that provides simple animations via CSS transitions for modern browsers on the web as well as mobile devices.</li>\n<li><strong><a href=\"https://github.com/wambotron/Keanu\">Keanu</a></strong>: Keanu is a micro-lib for animation on Canvas/JS.</li>\n<li><strong><a href=\"https://github.com/miniMAC/magic\">Magic</a></strong>: CSS3 Animations with special effects.</li>\n<li><strong><a href=\"http://visionmedia.github.com/move.js/\">Move.js</a></strong>: Move.js is a small JavaScript library making CSS3 backed animation extremely simple and elegant.</li>\n<li><strong><a href=\"http://www.rich-harris.co.uk/ramjet/\">Ramjet</a></strong>: Ramjet makes it looks as though one DOM element is capable of transforming into another, no matter where the two elements sit in the DOM tree.</li>\n<li><strong><a href=\"http://rekapi.com/\">Rekapi</a></strong>: A keyframe animation library for JavaScript.</li>\n<li><strong><a href=\"http://svgjs.com/\">SVG.js</a></strong>: A lightweight library for manipulating and animating SVG.</li>\n<li><strong><a href=\"http://scripty2.com/\">Scripty2</a></strong>: scripty2 is a powerful, flexible JavaScript framework to help you write your own delicious visual effects &#x26; user interfaces.</li>\n<li><strong><a href=\"http://jeremyckahn.github.com/shifty/\">Shifty</a></strong>: Shifty is a tweening engine built in JavaScript. It is designed to fit any number of tweening needs.</li>\n<li><strong><a href=\"http://snapsvg.io/\">Snap.svg</a></strong>: Snap.svg JavaScript library makes working with your SVG assets as easy as jQuery makes working with the DOM.</li>\n<li><strong><a href=\"http://jeremyckahn.github.io/stylie/\">Stylie</a></strong>: Stylie is a fun tool for easily creating complex CSS animations. Quickly design your animation graphically, grab the generated code and go!</li>\n<li><strong><a href=\"http://jschr.github.io/textillate/\">Textillate.js</a></strong>: Textillate.js combines some awesome libraries to provide a ease-to-use plugin for applying CSS3 animations to any text.</li>\n<li><strong><a href=\"https://github.com/sole/tween.js\">Tween.js</a></strong>: Super simple, fast and easy to use tweening engine which incorporates optimised Robert Penner's equations.</li>\n<li><strong><a href=\"https://cssanimation.rocks/twitter-fave/\">Twitter Fave Animation</a></strong>: Rather than rely on CSS transitions, the new animation makes use of a series of images. Here's how to recreate the animation using the CSS animation steps timing function.</li>\n<li><strong><a href=\"http://alistapart.com/article/web-animation-past-present-and-future\">Web Animation Past, Present, and Future (2016)</a></strong>: Rachel Nabors explores the world of web animation standards, platforms and tools in 2016: SVG, SMIL, GreenSock AP, Framer, Browser Tooling etc.</li>\n<li>\n<p><strong><a href=\"http://w3c.github.io/web-animations/\">Web Animations API</a></strong>: Web Animations is a new JavaScript API for driving animated content on the web. By unifying the animation features of SVG and CSS, Web Animations unlocks features previously only usable declaratively, and exposes powerful, high-performance animation capabilities to developers.</p>\n<ul>\n<li><strong><a href=\"https://birtles.github.io/areweanimatedyet/\">Are we animated yet?</a></strong>: This page tracks the progress of implementing the Web Animations API in Firefox.</li>\n<li><strong><a href=\"http://codepen.io/danwilson/pen/XmWraY\">WAAPI Browser Support Test (+ Polyfill)</a></strong>: This codepen tests whether and to which extend your browser supports Web Animations API. The test is run after including the Polyfill.</li>\n<li><strong><a href=\"https://github.com/web-animations/web-animations-js\">Web Animations Polyfill</a></strong>: JavaScript implementation of the Web Animations API.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Typography</strong>: The style, arrangement, or appearance of typeset matter.</p>\n<ul>\n<li><strong><a href=\"https://www.zachleat.com/web/comprehensive-webfonts/\">A Comprehensive Guide to Font Loading Strategies</a></strong>: Zach Leatherman describes different approaches to loading of web fonts.</li>\n<li><strong><a href=\"https://edgewebfonts.adobe.com/fonts\">Adobe Edge Web Fonts</a></strong>: Edge Web Fonts is a free service that provides access to a large library of fonts for your website. It's one of the Edge Tools &#x26; Services from Adobe. Use of the service is free and unlimited.</li>\n<li><strong><a href=\"https://github.com/daneden/Baseline.js\">Baseline.js</a></strong>: A simple jQuery plugin for restoring vertical baselines thrown off by odd image sizes.</li>\n<li><strong><a href=\"http://www.newnet-soft.com/blog/csstypography\">CSS Typography cheat sheet</a></strong>: Small roundup on CSS features that will enhance your web typography.</li>\n<li><strong><a href=\"http://stackoverflow.com/questions/2892691/font-face-fonts-only-work-on-their-own-domain\">Convincing a browser to load fonts from other domains</a></strong>: A StackOverflow question about loading fonts across domains.</li>\n<li><strong><a href=\"http://fittextjs.com/\">FitText</a></strong>: FitText makes font-sizes flexible. Use this plugin on your fluid or responsive layout to achieve scalable headlines that fill the width of a parent element.</li>\n<li><strong><a href=\"http://simplefocus.com/flowtype/\">FlowType.JS</a></strong>: Font-size and line-height based on element width.</li>\n<li><strong><a href=\"http://media.24ways.org/2007/17/fontmatrix.html\">Fontmatrix</a></strong>: Matrix of fonts bundled with Mac and Windows operating systems, Microsoft Office and Adobe Creative Suite.</li>\n<li><strong><a href=\"https://www.google.com/fonts/\">Google Fonts</a></strong>: Google Fonts makes it quick and easy for everyone to use web fonts. Our goal is to create a directory of web fonts for the world to use. Our API service makes it easy to add Google Fonts to a website in seconds.</li>\n<li><strong><a href=\"http://matejlatin.github.io/Gutenberg/\">Gutenberg</a></strong>: Gutenberg is a flexible and simple-to-use web typography starter kit for web designers and developers.</li>\n<li><strong><a href=\"http://letteringjs.com/\">Lettering.js</a></strong>: Web type is exploding all over the web but CSS currently doesn't offer complete down-to-the-letter control. So we created a jQuery plugin to give you that control.</li>\n<li><strong><a href=\"http://open-foundry.com/\">OpenFoundry</a></strong>: A platform for open-source fonts in a noise-free environment; to highlight their beauty and encourage further exploration.</li>\n<li><strong><a href=\"http://tilomitra.github.io/csstypography/\">Pure Typography</a></strong>: CSS Styles for nicer web type. Depends on Pure.</li>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/webfonts/quick/\">Quick guide to webfonts via @font-face</a></strong>: The @font-face feature from CSS3 allows us to use custom typefaces on the web in an accessible, manipulable, and scalable way.</li>\n<li><strong><a href=\"https://www.smashingmagazine.com/2016/05/fluid-typography/\">Truly Fluid Typography With vh And vw Units</a></strong>: This article describes viewport units and other technics to achieve typography which resizes smoothly with the screen.</li>\n<li><strong><a href=\"https://github.com/hudsonfoo/typebutter\">TypeButter</a></strong>: TypeButter allows you to set optical kerning for any font on your website. If you're longing for beautifully laid out text that today' browsers just don't provide, this is the plugin for you.</li>\n<li><strong><a href=\"https://github.com/joshuarudd/typeset.css\">Typeset.css</a></strong>: A no-nonsense CSS typography reset for styling user-generated content like blog posts, comments, and forum content.</li>\n<li><strong><a href=\"http://stormwarning.github.io/typeset.css/\">Typeset.css</a></strong>: A Sass library that provides some sensible default styles, optional classes to use &#x26; extend as needed, and some utility functions &#x26; mixins to make elevating your typography simpler.</li>\n<li><strong><a href=\"http://baconforme.com/\">bacon</a></strong>: Bacon is a jQuery plugin that allows you to wrap text around a bezier curve or a line.</li>\n<li><strong><a href=\"https://github.com/freqDec/slabText/\">slabText</a></strong>: A jQuery plugin for producing big, bold &#x26; responsive headlines.</li>\n<li><strong><a href=\"http://jrvis.com/trunk8/\">trunk8</a></strong>: trunk8 is an intelligent text truncation plugin to jQuery. When applied to a large block of text, trunk8 will cut off just enough text to prevent it from spilling over.</li>\n</ul>\n</li>\n<li>\n<p><strong>Visualization</strong>: Placing data in a visual context.</p>\n<ul>\n<li><strong><a href=\"http://bonsaijs.org/\">Bonsai.js</a></strong>: A lightweight graphics library with an intuitive graphics API and an SVG renderer.</li>\n<li><strong><a href=\"http://www.chartjs.org/\">Chart.js</a></strong>: Simple, clean and engaging charts for designers and developers.</li>\n<li><strong><a href=\"http://square.github.io/crossfilter/\">Crossfilter</a></strong>: Crossfilter is a JavaScript library for exploring large multivariate datasets in the browser.</li>\n<li><strong><a href=\"http://square.github.io/cube/\">Cube</a></strong>: Cube is a system for collecting timestamped events and deriving metrics. By collecting events rather than metrics, Cube lets you compute aggregate statistics post hoc.</li>\n<li><strong><a href=\"http://square.github.io/cubism/\">Cubism.js</a></strong>: Cubism.js is a D3 plugin for visualizing time series. Use Cubism to construct better realtime dashboards, pulling data from Graphite, Cube and other sources.</li>\n<li>\n<p><strong><a href=\"https://d3js.org/\">D3.js</a></strong>: D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS.</p>\n<ul>\n<li><strong><a href=\"http://datamaps.github.io/\">DataMaps</a></strong>: Customizable SVG (world) map visualizations for the web in a single Javascript file using D3.js.</li>\n<li><strong><a href=\"http://vadim.ogievetsky.com/IntroD3/\">Interactive Introduction to D3</a></strong>: D3 slides in D3 that I put together after becoming frustrated with explaining D3 using PowerPoint.</li>\n<li><strong><a href=\"http://nvd3.org/\">NVD3</a></strong>: This project is an attempt to build re-usable charts and chart components for d3.js without taking away the power that d3.js gives you.</li>\n<li><strong><a href=\"http://www.janwillemtulp.com/2011/03/20/tutorial-introduction-to-d3/\">Tutorial: Introduction to D3</a></strong>: Basically we just plot hidden circles randomly on the screen, and then transition them to a portion of the screen. Then we add some interaction to it so that the circles will move once you move your mouse over them.</li>\n<li><strong><a href=\"http://tenxer.github.io/xcharts/\">xCharts</a></strong>: xCharts is a JavaScript library for building beautiful and custom data-driven chart visualizations for the web using D3.js. Using HTML, CSS, and SVG, xCharts are designed to be dynamic, fluid, and open to integrations and customization.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://rendro.github.io/easy-pie-chart/\">Easy Pie Chart</a></strong>: Easy pie chart is a jQuery plugin that uses the canvas element to render simple pie charts for single values</li>\n<li><strong><a href=\"http://www.flotcharts.org/\">Flot</a></strong>: Flot is a pure JavaScript plotting library for jQuery, with a focus on simple usage, attractive looks and interactive features.</li>\n<li><strong><a href=\"https://developers.google.com/chart/\">Google Chart Tools</a></strong>: The Google Visualization API allows you to create charts and reporting applications over structured data and helps integrate these directly into your website.</li>\n<li><strong><a href=\"http://paperjs.org\">Paper.js</a></strong>: Paper.js offers a clean Scene Graph / Document Object Model and a lot of powerful functionality to create and work with vector graphics and bezier curves.</li>\n<li><strong><a href=\"http://photon.attasi.com/\">Photon</a></strong>: Photon is a JavaScript library that adds simple lighting effects to DOM elements in 3D space.</li>\n<li><strong><a href=\"http://lipka.github.io/piecon/\">Piecon</a></strong>: A tiny javascript library for dynamically generating progress pie charts in your favicons.</li>\n<li><strong><a href=\"http://berniesumption.com/software/animator/\">Processing.js</a></strong>: Processing.js is the sister project of the popular Processing visual programming language, designed for the web. Processing.js makes your data visualizations work using web standards.</li>\n<li><strong><a href=\"http://smoothiecharts.org/\">Smoothie Charts</a></strong>: A JavaScript Charting Library for Streaming Data.</li>\n<li><strong><a href=\"http://timeline.knightlab.com/\">TimelineJS</a></strong>: TimelineJS is an open-source tool that enables anyone to build visually rich, interactive timelines.</li>\n<li><strong><a href=\"http://sbstjn.github.io/timesheet.js/\">Timesheet.js</a></strong>: Visualize your data and events with sexy HTML5 and CSS3. Create simple time sheets with sneaky JavaScript. Style them with CSS and have mobile fun as well.</li>\n<li><strong><a href=\"https://github.com/jimblackler/treefun\">Treefun by Jim Blackler</a></strong>: This tool creates SVG (Standard Vector Graphics) files to illustrate information structured as a basic tree.</li>\n<li><strong><a href=\"http://taitems.github.io/jQuery.Gantt/\">jQuery.Gantt</a></strong>: Draw Gantt charts with the famous jQuery ease of development.</li>\n<li><strong><a href=\"http://jstat.github.io/\">jStat</a></strong>: jStat is a statistical library written in JavaScript that allows you to perform advanced statistical operations without the need of a dedicated statistical language (e.g. MATLAB or R).</li>\n<li><strong><a href=\"http://morrisjs.github.io/morris.js/\">morris.js</a></strong>: Morris.js is a very simple API for drawing line, bar, area and donut charts.</li>\n<li><strong><a href=\"http://jgraph.github.io/mxgraph/\">mxgraph</a></strong>: mxGraph is a JavaScript diagramming library that enables interactive graph and charting applications to be quickly created that run natively in any major browser, both HTML 5 capable and Internet Explorer v7+.</li>\n<li><strong><a href=\"http://threejs.org/\">three.js</a></strong>: Three.js is a library that makes WebGL - 3D in the browser - easy to use. While a simple cube in raw WebGL would turn out hundreds of lines of Javascript and shader code, a Three.js equivalent is only a fraction of that.</li>\n<li><strong><a href=\"http://visjs.org/\">vis.js</a></strong>: Vis.js is a dynamic, browser based visualization library. The library is designed to be easy to use, handle large amounts of dynamic data, and enable manipulation of the data.</li>\n</ul>\n</li>\n</ul>\n<h2>Architecture</h2>\n<p>High level structure of the frontend code and the discipline of creating such structures.</p>\n<ul>\n<li>\n<p><strong>Algorithms</strong>: A self-contained step-by-step set of operations to be performed. Algorithms perform calculation, data processing, and/or automated reasoning tasks.</p>\n<ul>\n<li><strong><a href=\"https://github.com/parkjs814/AlgorithmVisualizer\">Algorithm Visualizer</a></strong>: A collection of algorithms with code and visualizations for each one of them.</li>\n<li><strong><a href=\"https://www.toptal.com/developers/sorting-algorithms/\">Sorting Algorithms Animations</a></strong>: The following animations illustrate how effectively data sets from different starting points can be sorted using different algorithms.</li>\n</ul>\n</li>\n<li>\n<p><strong>Design Patterns</strong>: Best practices that the programmer can use to solve common problems when designing an application or system.</p>\n<ul>\n<li>\n<p><strong><a href=\"https://github.com/css-modules\">CSS Modules</a></strong>: A CSS Module is a CSS file in which all class names and animation names are scoped locally by default.</p>\n<ul>\n<li><strong><a href=\"https://github.com/css-modules/css-modules\">CSS Modules Documentation</a></strong>: General overview and some implementations.</li>\n<li><strong><a href=\"https://github.com/jacobp100/es-css-modules\">ES CSS Modules</a></strong>: PostCSS plugin that combines CSS Modules and ES Imports.</li>\n<li><strong><a href=\"https://medium.com/@jacobp/tree-shaking-bootstrap-95d6301f61a9\">Tree Shaking Bootstrap</a></strong>: Jacob Parker describes how to include only those parts of Bootstrap you are really using on your website by leveraging CSS modules and ES6 modules.</li>\n</ul>\n</li>\n<li>\n<p><strong>Components</strong>: Reusable and composable pieces of HTML, CSS and/or JavaScript code which are mostly used for GUI elements.</p>\n<ul>\n<li><strong><a href=\"https://github.com/Mercateo/component-check\">Component Check</a></strong>: In this project Donald Pipowitch compares the usage and development of components in several frameworks such as Angular, Ember, Cycle.js and React.</li>\n<li><strong><a href=\"https://medium.com/@learnreact/container-components-c0e67432e005\">Container Components</a></strong>: Container Components is a pattern which allows to separate data-fetching and rendering concerns and increase the reusability of the (child) components.</li>\n<li><strong><a href=\"http://livingstyleguide.devbridge.com/\">Devbridge Styleguide</a></strong>: Devbridge Styleguide helps you create, share, and automate a living visual style library of your brand.</li>\n<li><strong><a href=\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\">Presentational and Container Components</a></strong>: Dan Abramov creates a pattern for separating presentational and container components to increase reusability and clarity of the application code.</li>\n<li>\n<p><strong>Web Components</strong>: Web Components is a W3C standard for encapsulated, reusable and composable widgets for the web platform.</p>\n<ul>\n<li><strong><a href=\"http://jonrimmer.github.io/are-we-componentized-yet/\">Are We Componentized Yet?</a></strong>: Tracking the progress of Web Components through standardisation, polyfillification and implementation.</li>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/webcomponents/customelements/\">Custom Elements</a></strong>: Eric Bidelman describes how to create new HTML elements and manage their life cycle.</li>\n<li><strong><a href=\"http://w3c.github.io/webcomponents/spec/custom/\">Custom Elements W3C Editor's Draft</a></strong>: This specification describes the method for enabling the author to define and use new types of DOM elements in a document.</li>\n<li><strong><a href=\"http://w3c.github.io/webcomponents/spec/imports/\">HTML Imports W3C Editor's Draft</a></strong>: HTML Imports are a way to include and reuse HTML documents in other HTML documents.</li>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/webcomponents/imports/\">HTML Imports: #include for the web</a></strong>: Eric Bidelman describes how to use HTML imports and goes through several edge cases.</li>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/webcomponents/template/\">HTML's New Template Tag</a></strong>: The template element allows you to declare fragments of DOM which are parsed, inert at page load, and instantiated later at runtime.</li>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/\">Shadow DOM 101</a></strong>: Dominic Cooney shows you how to use Shadow DOM in this tutorial.</li>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/\">Shadow DOM 201</a></strong>: Eric Bidelman explains advanced topics related to styling of Shadow DOM elements.</li>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-301/\">Shadow DOM 301</a></strong>: Eric Bidelman talks about advanced Shadow DOM topics like multiple shadow roots, insertion points, event model and Shadow DOM Visualizer.</li>\n<li><strong><a href=\"http://w3c.github.io/webcomponents/spec/shadow/\">Shadow DOM W3C Editor's Draft</a></strong>: This specification describes a method of combining multiple DOM trees into one hierarchy and how these trees interact with each other within a document, thus enabling better composition of the DOM.</li>\n<li><strong><a href=\"http://html5-demos.appspot.com/static/shadowdom-visualizer/index.html\">ShadowDOM Visualizer</a></strong>: This tool allows you to visualize how Shadow DOM renders in the browser.</li>\n<li><strong><a href=\"https://blog.revillweb.com/why-web-components-are-so-important-66ad0bd4807a\">Why Web Components Are So Important</a></strong>: Leon Revill compares web components with concepts from different frameworks and explains why web components matter.</li>\n<li><strong><a href=\"https://blog.revillweb.com/write-web-components-with-es2015-es6-75585e1f2584\">Write Web Components with ES2015 (ES6)</a></strong>: This tutorial shows how to create a web component using ES2015 and how to make use of babel to transpile back to ES5.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>DOM Diffing &#x26; Patching</strong>: Diffing &#x26; Patching is a pattern which allows faster and simpler rendering and updating of DOM trees as manual manipulation à la jQuery.</p>\n<ul>\n<li><strong><a href=\"http://teropa.info/blog/2015/03/02/change-and-its-detection-in-javascript-frameworks.html\">Change And Its Detection In JavaScript Frameworks</a></strong>: This article explores several approaches to manage state: Ember's data binding, Angular's dirty checking, React's virtual DOM, and its relationship to immutable data structures.</li>\n<li><strong><a href=\"https://github.com/joelrich/citojs\">Cito.js</a></strong>: The core of cito.js consists of a virtual DOM library inspired by React/Mithril. On top of that, it will provide a component framework which will make it easy to build well-encapsulated components.</li>\n<li>\n<p><strong><a href=\"https://github.com/google/incremental-dom\">Incremental DOM</a></strong>: Incremental DOM is a library for building up DOM trees and updating them in-place when data changes. It differs from the established virtual DOM approach in that no intermediate tree is created (the existing tree is mutated in-place).</p>\n<ul>\n<li><strong><a href=\"https://medium.com/google-developers/introducing-incremental-dom-e98f79ce2c5f\">Introducing Incremental DOM</a></strong>: Incremental DOM is a library inspired by Virtual DOM developed at Google.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/patrick-steele-idem/morphdom\">Morphdom</a></strong>: Lightweight module for morphing an existing DOM node tree to match a target DOM node tree. It's fast and works with the real DOM—no virtual DOM here!</li>\n<li><strong><a href=\"http://blog.reverberate.org/2014/02/react-demystified.html\">React Demystified</a></strong>: This article is an attempt to explain the core ideas behind React.js and Virtual DOM.</li>\n<li><strong><a href=\"https://auth0.com/blog/2015/11/20/face-off-virtual-dom-vs-incremental-dom-vs-glimmer/\">React vs Incremental DOM vs Glimmer</a></strong>: In this post we will explore three technologies to build dynamic DOMs. We will also run benchmarks and find out which one is faster.</li>\n<li><strong><a href=\"https://medium.com/@yelouafi/react-less-virtual-dom-with-snabbdom-functions-everywhere-53b672cb2fe3\">React-less Virtual DOM with Snabbdom: functions everywhere!</a></strong>: Yassine Elouafi shows in this post how to write a virtual DOM based applications using a small and standalone library.</li>\n<li><strong><a href=\"https://github.com/paldepind/snabbdom\">Snabbdom</a></strong>: A virtual DOM library with focus on simplicity, modularity, powerful features and performance.</li>\n<li>\n<p><strong><a href=\"https://github.com/Matt-Esch/virtual-dom\">Virtual DOM</a></strong>: Virtual-dom is a collection of modules designed to provide a declarative way of representing the DOM for your app. So instead of updating the DOM, you simply create a virtual tree or VTree, which looks like the DOM state that you want.</p>\n<ul>\n<li><strong><a href=\"https://github.com/TimBeyer/html-to-vdom\">html-to-vdom</a></strong>: This is yet another library to convert HTML into a vtree. It's used in conjunction with virtual-dom to convert template based views into virtual-dom views.</li>\n<li><strong><a href=\"https://github.com/unframework/html2hyperscript\">html2hyperscript</a></strong>: Automatically translate old HTML markup into the new Hyperscript markup embeddable directly inside your component Javascript code.</li>\n<li><strong><a href=\"https://github.com/nthtran/vdom-to-html/\">vdom-to-html</a></strong>: Turn Virtual DOM nodes into HTML.</li>\n<li><strong><a href=\"https://github.com/marcelklehr/vdom-virtualize/\">vdom-virtualize</a></strong>: Turn a DOMNode into a virtual-dom node.</li>\n<li><strong><a href=\"https://github.com/yoshuawuyts/virtual-html\">virtual-html</a></strong>: Convert given HTML into Virtual DOM object.</li>\n<li><strong><a href=\"https://github.com/parshap/vtree-select\">vtree-select</a></strong>: Select vtree nodes (used by virtual-dom) using css selectors. Selector matching is done using cssauron. See the documentation for details on supported selectors.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Design Pattern Collections</strong>: Overview resources and collections of design patterns.</p>\n<ul>\n<li><strong><a href=\"http://nicolasgallagher.com/about-html-semantics-front-end-architecture/\">About HTML Semantics and Frontend Architecture</a></strong>: A collection of thoughts, experiences, ideas on HTML semantics, components and approaches to front-end architecture, class naming patterns, and HTTP compression.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=mKouqShWI4o\">Box Tech Talk: Scalable JavaScript Application Architecture</a></strong>: A video by Nicholas Zakas (2012) about JavaScript Architecture.</li>\n<li><strong><a href=\"https://addyosmani.com/resources/essentialjsdesignpatterns/book/\">Learning JavaScript Design Patterns</a></strong>: In this free book Addy Osmani explores applying both classical and modern design patterns to the JavaScript programming language.</li>\n<li><strong><a href=\"https://addyosmani.com/largescalejavascript/\">Patterns For Large-Scale JavaScript Application Architecture</a></strong>: An extensive overview by Addy Osmani of existing architectural solutions in the frontend development field.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=vXjVFPosQHw\">Scalable JavaScript Application Architecture</a></strong>: In this video (2011) Nicholas Zakas discusses frontend architecture for complex, modular web applications with significant JavaScript elements.</li>\n<li><strong><a href=\"http://singlepageappbook.com/\">Single Page Apps in Depth</a></strong>: This free book is what I wanted when I started working with single page apps. It's not an API reference on a particular framework, rather, the focus is on discussing patterns, implementation choices and decent practices.</li>\n</ul>\n</li>\n<li>\n<p><strong>JavaScript Modules</strong>: Modules divide programs into clusters of code that, by some criterion, belong together.</p>\n<ul>\n<li><strong><a href=\"http://eloquentjavascript.net/10_modules.html\">Chapter 10 of Eloquent JavaScript: Modules</a></strong>: This chapter explores some of the benefits that division of code provides and shows techniques for building modules in JavaScript.</li>\n<li><strong><a href=\"https://hacks.mozilla.org/2015/08/es6-in-depth-modules/\">ES6 In Depth: Modules</a></strong>: This article highlights export and import keywords from ES6.</li>\n<li><strong><a href=\"https://mariusgundersen.net/module-pusher/\">Efficient Module Loading Without Bundling</a></strong>: We can combine ES2015 modules, static analysis of those modules, HTTP/2, caching, Service Workers and a bloom-filter to create a server-client relationship where the client can efficiently load any module.</li>\n<li><strong><a href=\"https://medium.freecodecamp.com/javascript-modules-a-beginner-s-guide-783f7d7a5fcc#.i78m6tfs9\">JavaScript Modules: A Beginner's Guide</a></strong>: In this post, Preethi Kasireddy will unpack the buzzwords like module bundlers, AMD and CommonJS for you in plain English, including a few code samples.</li>\n<li><strong><a href=\"https://addyosmani.com/resources/essentialjsdesignpatterns/book/#modularjavascript\">Modern Modular JavaScript Design Patterns</a></strong>: A chapter from Essential JavaScript Design Patterns on Modules.</li>\n<li>\n<p><strong>Module Bundlers and Loaders</strong>: Libraries for bundling JavaScript Modules into one or several files.</p>\n<ul>\n<li>\n<p><strong><a href=\"http://browserify.org/\">Browserify</a></strong>: Browserify lets you require('modules') in the browser by bundling up all of your dependencies.</p>\n<ul>\n<li><strong><a href=\"https://github.com/mattdesl/budo\">Budo</a></strong>: A browserify development server, focused on incremental reloading, LiveReload integration (including CSS injection), and other high-level features.</li>\n<li><strong><a href=\"https://www.npmjs.org/package/watchify\">Watchify</a></strong>: Watch mode for browserify builds.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/gregersrygg/crapLoader\">CrapLoader</a></strong>: The goal of crapLoader is to load ads, widgets or any JavaScript code with document.write in it. This library hijacks document.write and delegates the content loaded from each script into the correct position.</li>\n<li><strong><a href=\"https://github.com/medikoo/modules-webmake\">Modules Webmake</a></strong>: A CommonJS module bundler similar to Browserify but much faster due to different requirements finder.</li>\n<li><strong><a href=\"http://requirejs.org/\">Require.js</a></strong>: RequireJS is a JavaScript file and AMD module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments.</li>\n<li><strong><a href=\"http://stuk.github.io/require1k/\">Require1k</a></strong>: CommonJS require for the browser in 1KB, with no build needed.</li>\n<li><strong><a href=\"http://rollupjs.org/\">Rollup.js</a></strong>: Rollup is a next-generation JavaScript module bundler. Author your app or library using ES2015 modules, then efficiently bundle them up into a single file for use in browsers and Node.js.</li>\n<li>\n<p><strong><a href=\"https://github.com/systemjs/systemjs\">SystemJS</a></strong>: Universal dynamic module loader - loads ES6 modules, AMD, CommonJS and global scripts in the browser and NodeJS. Works with both Traceur and Babel.</p>\n<ul>\n<li><strong><a href=\"http://www.sitepoint.com/modular-javascript-systemjs-jspm/\">Modular JavaScript: A Beginners Guide to SystemJS &#x26; JSPM</a></strong>: The combination of jspm and SystemJS provides a unified way of installing and loading dependencies.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/anodynos/urequire\">URequire</a></strong>: The Ultimate JavaScript Module Builder &#x26; Automagical Task Runner.</li>\n<li>\n<p><strong><a href=\"http://webpack.github.io/\">Webpack</a></strong>: Webpack is a module bundler. It takes modules with dependencies and generates static assets representing those modules.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b\">Block, Element, Modifying Your JavaScript Components</a></strong>: Mark Dalgleish is discussing how to organize React code with BEM and build everything with Webpack.</li>\n<li><strong><a href=\"http://dapperdeveloper.com/2016/05/18/developing-with-docker-and-webpack/\">Developing with Docker and Webpack</a></strong>: Chris Harrington explains how to create a development environment with Webpack and Docker to match the production as much as possible.</li>\n<li><strong><a href=\"http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html\">Full-Stack Redux Tutorial</a></strong>: We will go through all the steps of constructing a Node+Redux backend and a React+Redux frontend for a real-world application, using test-first development.</li>\n<li><strong><a href=\"http://www.davidmeents.com/how-to-set-up-webpack-image-loader/\">How to Set Up Webpack Image Loader</a></strong>: This brief tutorial will help you set up an image loader in Webpack.</li>\n<li><strong><a href=\"http://www.robinwieruch.de/the-soundcloud-client-in-react-redux/\">The SoundCloud Client in React + Redux</a></strong>: After finishing this step by step tutorial you will be able to author your own React + Redux project with Webpack and Babel.</li>\n<li><strong><a href=\"http://survivejs.com/webpack/\">Webpack from Apprentice to Master</a></strong>: The purpose of this guide is to help you get started with Webpack and then go beyond basics.</li>\n<li><strong><a href=\"http://www.webpackbin.com/\">WebpackBin</a></strong>: A webpack code sandbox.</li>\n<li><strong><a href=\"http://devlog.disco.zone/2016/06/01/webpack/\">Why I think Webpack is the Right Approach To Build Pipelines</a></strong>: Thomas Boyt compares how Grunt, Gulp, Broccoli and Webpack discover dependencies.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/umdjs/umd\">UMD (Universal Module Definition)</a></strong>: This repository formalizes the design and implementation of the Universal Module Definition (UMD) API for JavaScript modules. These are modules which are capable of working everywhere, be it in the client, on the server or elsewhere.</li>\n<li><strong><a href=\"https://addyosmani.com/writing-modular-js/\">Writing Modular JavaScript With AMD, CommonJS &#x26; ES Harmony</a></strong>: In this article Addy Osmani reviewes several of the options available for writing modular JavaScript using modern module formats AMD, CommonJS and ES6 Modules.</li>\n</ul>\n</li>\n<li>\n<p><strong>Observable</strong>: An Observable is an event stream which can emit zero or more events, and may or may not finish. If it finishes, then it does so by either emitting an error or a special \"complete\" event.</p>\n<ul>\n<li><strong><a href=\"https://github.com/zenparsing/es-observable\">ECMAScript Observable</a></strong>: This proposal introduces an Observable type to the ECMAScript standard library. The Observable type can be used to model push-based data sources such as DOM events, timer intervals, and sockets.</li>\n<li>\n<p><strong><a href=\"https://github.com/Reactive-Extensions/RxJS\">Reactive Extensions (RxJS)</a></strong>: RxJS is a set of libraries for composing asynchronous and event-based programs using observable sequences and fluent query operators.</p>\n<ul>\n<li><strong><a href=\"https://www.youtube.com/watch?v=XRYN2xt11Ek\">Async JavaScript with Reactive Extensions</a></strong>: Jafar Husain explains in this video how Netflix uses the Reactive Extensions (Rx) library to build responsive user experiences that strive to be event-driven, scalable and resilient.</li>\n<li><strong><a href=\"http://blog.thoughtram.io/rx/2016/08/01/exploring-rx-operators-flatmap.html\">Exploring Rx Operators: FlatMap</a></strong>: Christoph Burgdorf introduces the FlatMap operator and its usage for collections and observables.</li>\n<li><strong><a href=\"http://blog.thoughtram.io/angular/2016/05/16/exploring-rx-operators-map.html\">Exploring Rx Operators: Map</a></strong>: Christoph Burgdorf explains how to use the map operator in RxJS.</li>\n<li><strong><a href=\"http://www.mokacoding.com/blog/functional-core-reactive-shell/\">Functional Core Reactive Shell</a></strong>: Giovanni Lodi makes an overview of different architecture meta-patterns and describes his current findings about functional programming and observables as a way to control side effects.</li>\n<li><strong><a href=\"http://reactivex.io/learnrx/\">Learn RX</a></strong>: A series of interactive exercises for learning Microsoft's Reactive Extensions (Rx) Library for Javascript.</li>\n<li><strong><a href=\"http://www.learnrxjs.io/\">Learn RxJS</a></strong>: This site focuses on making RxJS concepts approachable, the examples clear and easy to explore, and features references throughout to the best RxJS related material on the web.</li>\n<li><strong><a href=\"https://medium.com/@sergimansilla/real-world-observables-1f65748c8f9\">Real World Observables</a></strong>: Sergi Mansilla writes an FTP client to use it as an example for a real world application based on RxJS.</li>\n<li><strong><a href=\"https://github.com/JulienMoumne/rx-training-games\">Rx Training Games</a></strong>: Rx Training Games is a coding playground that can be used to learn and practice Reactive Extensions coding grid-based games</li>\n<li><strong><a href=\"http://xgrommx.github.io/rx-book/index.html\">Rx-Book</a></strong>: A complete book about RxJS v.4.0.</li>\n<li><strong><a href=\"http://rxmarbles.com/\">RxMarbles</a></strong>: A webapp for experimenting with diagrams of Rx Observables, for learning purposes.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/rxstate\">RxState</a></strong>: Simple opinionated state management library based on RxJS and Immutable.js</li>\n<li><strong><a href=\"http://blog.thoughtram.io/angular/2016/01/06/taking-advantage-of-observables-in-angular2.html\">Taking Advantage of Observables in Angular 2</a></strong>: Christoph Burgdorf describes the advantages of Observables and how you can use them in Angular 2 context.</li>\n<li><strong><a href=\"https://xgrommx.github.io/rx-book/content/getting_started_with_rxjs/creating_and_querying_observable_sequences/transducers.html\">Transducers with Observable Sequences</a></strong>: A chapter from the RxJS Book describing Transducers.</li>\n<li><strong><a href=\"http://staltz.com/why-we-built-xstream.html\">Why We Built Xstream</a></strong>: The authors needed a stream library tailored for Cycle.js. It needs to be \"hot\" only, small in kB size and it should have only a few and intuitive operators.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Routing</strong>: A routing system parses a string input (usually a URL) and decides which action should be executed by matching the string against multiple patterns.</p>\n<ul>\n<li><strong><a href=\"http://joakim.beng.se/blog/posts/a-javascript-router-in-20-lines.html\">A JavaScript router in 20 lines</a></strong>: Joakim Carlstein shows how to write a simple router with data binding.</li>\n<li><strong><a href=\"http://millermedeiros.github.io/crossroads.js/\">Crossroads.js</a></strong>: Crossroads.js is a powerful and flexible routing system. If used properly it can reduce code complexity by decoupling objects and also by abstracting navigation paths and server requests.</li>\n<li><strong><a href=\"https://github.com/flatiron/director\">Director</a></strong>: A tiny and isomorphic URL router for JavaScript.</li>\n<li><strong><a href=\"https://www.polymer-project.org/1.0/blog/routing\">Encapsulated Routing with Elements</a></strong>: Peter Burns describes a routing approach based on Polymer elements, that allow to create chained and modular routes.</li>\n<li><strong><a href=\"https://github.com/javve/hash.js\">Hash.js</a></strong>: Hash.js is a 0.5 KB script that lets you manipulate everything behind # in urls.</li>\n<li><strong><a href=\"http://www.asual.com/jquery/address/\">JQuery Address</a></strong>: The jQuery Address plugin provides powerful deep linking capabilities and allows the creation of unique virtual addresses that can point to a website section or an application state.</li>\n<li><strong><a href=\"https://github.com/visionmedia/page.js\">Page.js</a></strong>: Micro client-side router inspired by the Express router.</li>\n<li><strong><a href=\"http://grobmeier.github.io/Roadcrew.js/\">Roadcrew.js</a></strong>: Roadcrew.js is a small JavaScript component which lets you switch pages of a single file website.</li>\n<li><strong><a href=\"https://github.com/tildeio/route-recognizer\">Route Recognizer</a></strong>: A lightweight JavaScript library that matches paths against registered routes. It includes support for dynamic and star segments and nested handlers.</li>\n<li><strong><a href=\"https://github.com/tildeio/router.js\">Router.js (Ember)</a></strong>: Router.js is the routing microlib used by Ember.js.</li>\n<li><strong><a href=\"https://github.com/router5/router5\">Router5</a></strong>: A simple, powerful, modular and extensible router, organising your named routes in a tree and handling route transitions. In its simplest form, Router5 processes routing instructions and outputs state updates.</li>\n</ul>\n</li>\n<li>\n<p><strong>UI Data Binding</strong>: Binding of UI elements to an application domain model. Most frameworks employ the Observer pattern as the underlying binding mechanism.</p>\n<ul>\n<li><strong><a href=\"https://guides.emberjs.com/v2.6.0/object-model/bindings/\">Bindings in Ember</a></strong>: Unlike most other frameworks that include some sort of binding implementation, bindings in Ember.js can be used with any object.</li>\n<li><strong><a href=\"http://teropa.info/blog/2015/03/02/change-and-its-detection-in-javascript-frameworks.html\">Change And Its Detection In JavaScript Frameworks</a></strong>: This article explores several approaches to manage state: Ember's data binding, Angular's dirty checking, React's virtual DOM, and its relationship to immutable data structures.</li>\n<li><strong><a href=\"http://www.lucaongaro.eu/blog/2012/12/02/easy-two-way-data-binding-in-javascript/\">Easy Two-Way Data Binding in JavaScript</a></strong>: Two-way data binding refers to the ability to bind changes to an object's properties to changes in the UI, and viceversa. This article describes how to implement data binding with vanilla JavaScript.</li>\n<li><strong><a href=\"https://github.com/kriskowal/frb\">Functional Reactive Bindings</a></strong>: A CommonJS package that includes functional and generic building blocks to help incrementally ensure consistent state.</li>\n<li><strong><a href=\"http://knockoutjs.com/\">Knockout.js</a></strong>: Knockout is a standalone JavaScript implementation of the Model-View-ViewModel pattern with templates.</li>\n<li><strong><a href=\"http://rivetsjs.com/\">Rivets.js</a></strong>: Lightweight and powerful data binding + templating solution for building modern web applications.</li>\n<li><strong><a href=\"https://github.com/bruth/synapse/\">Synapse</a></strong>: Hooks to support data binding between virtually any object.</li>\n</ul>\n</li>\n<li>\n<p><strong>Unidirectional Data Flow</strong>: An architecture design pattern which promotes a flow of data and events in a single direction, usually creating an interactive loop.</p>\n<ul>\n<li>\n<p><strong><a href=\"https://facebook.github.io/flux/\">Flux</a></strong>: Flux is the application architecture that Facebook uses for building client-side web applications. It complements React's composable view components by utilizing a unidirectional data flow. It's more of a pattern rather than a formal framework, and you can start using Flux immediately without a lot of new code.</p>\n<ul>\n<li><strong><a href=\"https://github.com/krasimir/fluxiny\">Fluxiny</a></strong>: ~1K implementation of flux architecture</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://vimeo.com/album/3953264/video/166790294\">Immutable User Interfaces</a></strong>: Lee Byron talks about unidirectional data flow architectures based on immutable data structures in contrast to traditional MVC based designs.</p>\n<ul>\n<li><strong><a href=\"https://github.com/facebook/immutable-js/\">Immutable.js</a></strong>: Immutable persistent data collections for Javascript which increase efficiency and simplicity.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/mobxjs/mobx\">MobX</a></strong>: MobX is a battle tested library that makes state management simple and scalable by transparently applying functional reactive programming.</li>\n<li>\n<p><strong>Model-View-Intent (MVI)</strong>: MVI is a unidirectional data flow architecture pattern consisting of three parts: Intent (to listen to the user), Model (to process information), and View (to output back to the user).</p>\n<ul>\n<li><strong><a href=\"http://cycle.js.org/model-view-intent.html\">MVI in Cycle.js Docs</a></strong>: André Staltz describes how to refactor an application into MVI pattern.</li>\n<li><strong><a href=\"https://satishchilukuri.com/blog/entry/model-view-intent-with-react-and-rxjs\">Model-View-Intent with React and RxJS</a></strong>: Satish Chilukuri shows an example implementation of MVI pattern with React.</li>\n<li><strong><a href=\"http://futurice.com/blog/reactive-mvc-and-the-virtual-dom\">Reactive MVC and the Virtual DOM</a></strong>: André Staltz describes the idea of Reactive Programming vs. Interactive Programming, proceeds with the MVI design pattern and compares it to React/Flux.</li>\n<li><strong><a href=\"http://thenewstack.io/developers-need-know-mvi-model-view-intent/\">What Developers Need to Know about MVI (Model-View-Intent)</a></strong>: The article explains the general MVI pattern and how it relates to React, Reactive Programming and Cycle.js</li>\n</ul>\n</li>\n<li><strong><a href=\"http://staltz.com/nothing-new-in-react-and-flux-except-one-thing.html\">Nothing New in React and Flux Except One Thing</a></strong>: Andre Staltz talks about aspects of React and Flux which make them innovative and compelling.</li>\n<li>\n<p><strong><a href=\"http://redux.js.org/\">Redux</a></strong>: Redux is a predictable state container for JavaScript apps. It attempts to make state mutations predictable by imposing certain restrictions on how and when updates can happen.</p>\n<ul>\n<li><strong><a href=\"http://blog.ng-book.com/introduction-to-redux-with-typescript-and-angular-2/\">Building Redux in TypeScript with Angular 2</a></strong>: In this post we're going to discuss the ideas behind Redux. How to build our own mini version of the Redux Store and hook it up to Angular 2.</li>\n<li><strong><a href=\"http://blog.krawaller.se/posts/exploring-redux-middleware/\">Exploring Redux Middleware</a></strong>: The author explains how to author your own middleware for Redux. He dives into the execution path of each middleware function in the chain and shows some examples.</li>\n<li><strong><a href=\"http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html\">Full-Stack Redux Tutorial</a></strong>: We will go through all the steps of constructing a Node+Redux backend and a React+Redux frontend for a real-world application, using test-first development.</li>\n<li><strong><a href=\"https://github.com/facebook/immutable-js/\">Immutable.js</a></strong>: Immutable persistent data collections for Javascript which increase efficiency and simplicity.</li>\n<li><strong><a href=\"https://youtu.be/hmwBow1PUuo\">Learn Redux</a></strong>: A video series by Wes Bos, teaching Redux. From setting up Webpack to using Dev Tools.</li>\n<li><strong><a href=\"https://github.com/paularmstrong/normalizr\">Normalizr</a></strong>: Normalizes deeply nested JSON API responses according to a schema for Flux and Redux apps.</li>\n<li><strong><a href=\"https://github.com/acdlite/redux-actions\">Redux Actions</a></strong>: Flux Standard Action utilities for Redux.</li>\n<li><strong><a href=\"https://github.com/erikras/redux-form\">Redux Form</a></strong>: A Higher Order Component using react-redux to keep form state in a Redux store.</li>\n<li><strong><a href=\"https://github.com/raisemarketplace/redux-loop\">Redux Loop</a></strong>: A port of elm-effects and the Elm Architecture to Redux that allows you to sequence your effects naturally and purely by returning them from your reducers.</li>\n<li><strong><a href=\"https://github.com/yelouafi/redux-saga\">Redux Saga</a></strong>: An alternative Side Effects middleware for Redux applications. Instead of dispatching Thunks which get handled by the redux-thunk middleware, you create Sagas to gather all your Side Effects logic in a central place.</li>\n<li><strong><a href=\"https://github.com/happypoulp/redux-tutorial\">Redux Tutorial</a></strong>: This repository contains a step by step tutorial to help grasp flux and more specifically Redux.</li>\n<li><strong><a href=\"http://survivejs.com/blog/redux-interview/\">Reinventing Flux - Interview with Dan Abramov</a></strong>: Dan talks about why he developed Redux.</li>\n<li><strong><a href=\"https://github.com/reactjs/reselect\">Reselect</a></strong>: Simple \"selector\" library for Redux inspired by getters in NuclearJS and subscriptions in re-frame.</li>\n<li><strong><a href=\"http://staltz.com/some-problems-with-react-redux.html\">Some Problems with React/Redux</a></strong>: André Staltz goes through the pros and cons of React + Redux.</li>\n<li><strong><a href=\"http://silvenon.com/testing-react-and-redux/\">Testing a React &#x26; Redux Codebase</a></strong>: This series aims to be a very comprehensive guide through testing a React and Redux codebase, where you can really cover a lot with just unit tests because the code is mostly universal.</li>\n<li><strong><a href=\"https://medium.com/@denisraslov/the-redux-ecosystem-539c630ec521\">The Redux Ecosystem</a></strong>: Let's take a look at most of the features that you'll have to deal with when the time comes, — and where React &#x26; Redux themselves can't help you.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=uvAXVMwHJXU\">The Redux Journey at react-europe 2016</a></strong>: In this talk, Dan Abramov reflects on the past, present, and future of Redux.</li>\n<li><strong><a href=\"http://www.robinwieruch.de/the-soundcloud-client-in-react-redux/\">The SoundCloud Client in React + Redux</a></strong>: After finishing this step by step tutorial you will be able to author your own React + Redux project with Webpack and Babel.</li>\n<li><strong><a href=\"http://ramonvictor.github.io/tic-tac-toe-js/\">Tic-Tac-Toe.js: Redux Pattern in Plain JavaScript</a></strong>: Ramon Victor describes how to use Redux with vanilla JavaScript. No React, no jQuery, no micro-library, it doesn't rely on anything else. It's just plain JS.</li>\n<li><strong><a href=\"https://medium.com/@meagle/understanding-87566abcfb7a\">Understanding Redux Middleware</a></strong>: The author describes the functional programming concepts involved in the creation and application of middleware functions.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://vimeo.com/168652278\">Unidirectional Data Flow Architectures (Talk)</a></strong>: Andre Staltz compares modern architecture patterns including Flux, Redux, Model-View-Intent, Elm Arch and BEST.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Designs</strong>: Ready to use and well documented structures and frameworks for frontend development.</p>\n<ul>\n<li>\n<p><strong><a href=\"http://atomicdesign.bradfrost.com/table-of-contents/\">Atomic Design</a></strong>: Atomic Design discusses the importance of crafting robust design systems, and introduces a methodology for which to create smart, deliberate interface systems.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/@AshConnolly/a-more-seamless-workflow-style-guides-for-better-design-and-development-639fc55be28c\">A More Seamless Workflow — Style Guides for Better Design and Development</a></strong>: Ash Connolly explains what styles guides are and which benefits they bring to designers and developers.</li>\n<li><strong><a href=\"http://atomicdocs.io/\">Atomic Docs</a></strong>: Atomic Docs is a styleguide generator and component manager. Atomic Docs is built in PHP. Inspired by Brad Frost's Atomic Design principles.</li>\n<li><strong><a href=\"http://steelydylan.github.io/atomic-lab/\">Atomic Lab</a></strong>: Template sharing and coding environment based on atomic design.</li>\n</ul>\n</li>\n<li>\n<p><strong>Authoring jQuery Plugins</strong>: jQuery is an utility library and a plugin framework. This section collects resources about creating such plugins.</p>\n<ul>\n<li><strong><a href=\"http://learn.jquery.com/plugins/advanced-plugin-concepts/\">Advanced Plugin Concepts</a></strong>: A collection of best practices for jQuery plugin authoring.</li>\n<li><strong><a href=\"http://learn.jquery.com/plugins/basic-plugin-creation/\">How to Create a Basic Plugin</a></strong>: The article describes basic plugin creation and provides a simple boilerplate.</li>\n<li><strong><a href=\"https://remysharp.com/2010/06/03/signs-of-a-poorly-written-jquery-plugin\">Signs of a poorly written jQuery plugin</a></strong>: Collection of jQuery plugin antipatterns.</li>\n<li><strong><a href=\"https://websanova.com/blog/jquery/the-ultimate-guide-to-writing-jquery-plugins\">The Ultimate Guide to Writing jQuery Plugins</a></strong>: A comprehensive guide on how to develop jQuery plugins including a simple boilerplate.</li>\n<li><strong><a href=\"http://learn.jquery.com/plugins/stateful-plugins-with-widget-factory/\">Writing Stateful Plugins with the jQuery UI Widget Factory</a></strong>: The article demonstrates the capabilities of the Widget Factory by building a simple progress bar plugin.</li>\n<li><strong><a href=\"https://github.com/jquery-boilerplate/jquery-boilerplate\">jQuery Boilerplate</a></strong>: This project won't seek to provide a perfect solution to every possible pattern, but will attempt to cover a simple template for beginners and above.</li>\n<li><strong><a href=\"https://github.com/jquery-boilerplate/jquery-patterns\">jQuery Plugin Patterns</a></strong>: This project won't seek to provide implementations for every possible pattern, but will attempt to cover popular patterns developers often use in the wild.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://en.bem.info/method/\">Block Element Modifier (BEM)</a></strong>: Methodology aimed at achieving fast to develop long-lived projects, team scalability, and code reuse.</p>\n<ul>\n<li><strong><a href=\"http://www.smashingmagazine.com/2012/04/a-new-front-end-methodology-bem/\">A New Front-End Methodology: BEM</a></strong>: An introduction by Varvara Stepanova at SmashingMagazine.</li>\n<li><strong><a href=\"http://webdesign.tutsplus.com/articles/an-introduction-to-the-bem-methodology--cms-19403\">An Introduction to the BEM Methodology</a></strong>: General introduction article on tutsplus.</li>\n<li><strong><a href=\"https://css-tricks.com/bem-101/\">BEM 101</a></strong>: A collaborative post by Joe Richardson, Robin Rendle, and CSS-Tricks staff giving an introduction to BEM with some good examples.</li>\n<li><strong><a href=\"https://m.alphasights.com/bem-i-finally-understand-b0c74815d5b0\">BEM I (finally) understand</a></strong>: In this article Andrei Popa will focus on the basics of BEM and how to approach simple to complex anatomies.</li>\n<li><strong><a href=\"https://www.smashingmagazine.com/2016/06/battling-bem-extended-edition-common-problems-and-how-to-avoid-them/\">Battling BEM (Extended Edition): 10 Common Problems And How To Avoid Them</a></strong>: This article aims to be useful for people who are already BEM enthusiasts and wish to use it more effectively or people who are curious to learn more about it.</li>\n<li><strong><a href=\"https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b\">Block, Element, Modifying Your JavaScript Components</a></strong>: Mark Dalgleish is discussing how to organize React code with BEM and build everything with Webpack.</li>\n<li><strong><a href=\"http://docs.emmet.io/filters/bem/\">Emmet filter for BEM</a></strong>: If you're writing your HTML and CSS code in OOCSS-style, Yandex's BEM style specifically, you will like this filter. It provides some aliases and automatic insertions of common block and element names in classes.</li>\n<li><strong><a href=\"http://blog.kaelig.fr/post/48196348743/fifty-shades-of-bem\">Fifty Shades of BEM</a></strong>: Article describes different flavors of BEM.</li>\n<li><strong><a href=\"https://m.alphasights.com/how-we-use-bem-to-modularise-our-css-82a0c39463b0\">How We Use BEM to Modularise Our CSS</a></strong>: Andrei Popa describes the challenges, AlphaSights team had, implementing BEM in their projects.</li>\n<li><strong><a href=\"https://www.toptal.com/css/introduction-to-bem-methodology\">Introduction To BEM Methodology (Toptal)</a></strong>: General introduction to BEM methodology and platform.</li>\n<li><strong><a href=\"http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/\">MindBEMding - getting your head 'round BEM syntax</a></strong>: Article on csswizardry explaining the BEM syntax for CSS classes.</li>\n<li><strong><a href=\"https://github.com/bem-contrib/pobem\">Pobem</a></strong>: PostCSS plugin for BEM syntax.</li>\n<li><strong><a href=\"http://mikefowler.me/2013/10/17/support-for-bem-modules-sass-3.3/\">Support for BEM modules in Sass 3.3</a></strong>: The next major release of Sass is poised for release and with it comes real support for BEM-style modules...</li>\n<li><strong><a href=\"http://www.didoo.net/to-bem-or-not-to-bem/\">To BEM or not to BEM</a></strong>: A series of interviews on BEM methodology.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://cycle.js.org/\">Cycle.js</a></strong>: A functional and reactive JavaScript framework that solves the cyclic dependency of Observables which emerge during dialogues (mutual observations) between the Human and the Computer.</p>\n<ul>\n<li><strong><a href=\"https://github.com/whitecolor/cycle-async-driver\">Async Driver</a></strong>: Higher order factory for creating cycle.js async request based drivers. Allows you almost completely eliminate boilerplate code for this kind of drivers.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=Rj8ZTRVka4E\">Cycle.js Was Built to Solve Problems</a></strong>: In this video André Staltz shows how Cycle.js has a practical purpose, meant to solve problems your customers/business may relate to.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=uNZnftSksYg\">Cycle.js and Functional Reactive User Interfaces</a></strong>: In this talk we will discover how Cycle.js is purely reactive and functional, and why it's an interesting alternative to React.</li>\n<li><strong><a href=\"https://glebbahmutov.com/draw-cycle/\">Draw Cycle</a></strong>: Simple Cycle.js program visualized</li>\n<li>\n<p><strong><a href=\"http://cycle.js.org/drivers.html\">Drivers</a></strong>: Drivers are functions that listen to Observable sinks (their input), perform imperative side effects, and may return Observable sources (their output).</p>\n<ul>\n<li><strong><a href=\"https://github.com/Widdershin/cycle-animation-driver\">Animation</a></strong>: A Cycle driver for requestAnimationFrame.</li>\n<li><strong><a href=\"https://github.com/benji6/cycle-audio-graph\">Audio Graph Driver</a></strong>: Audio graph driver for Cycle.js based on virtual-audio-graph.</li>\n<li><strong><a href=\"https://github.com/10clouds/cyclejs-cookie\">Cookie</a></strong>: Cycle.js Cookie Driver, based on cookie_js library.</li>\n<li><strong><a href=\"https://github.com/cyclejs/dom\">DOM</a></strong>: The standard DOM Driver for Cycle.js based on virtual-dom, and other helpers.</li>\n<li><strong><a href=\"https://github.com/secobarbital/cycle-fetch-driver\">Fetch</a></strong>: A Cycle.js Driver for making HTTP requests, using the Fetch API.</li>\n<li><strong><a href=\"https://github.com/r7kamura/cycle-fetcher-driver\">Fetcher</a></strong>: A Cycle.js Driver for making HTTP requests using stackable-fetcher.</li>\n<li><strong><a href=\"https://github.com/dralletje/cycle-firebase\">Firebase</a></strong>: Thin layer around the firebase javascript API that allows you to query and declaratively update your favorite real-time database.</li>\n<li><strong><a href=\"https://github.com/cyclejs/http\">HTTP</a></strong>: A Cycle.js Driver for making HTTP requests, based on superagent.</li>\n<li><strong><a href=\"https://github.com/CyclicMaterials/cycle-hammer-driver\">Hammer.js</a></strong>: The driver incorporates the Hammer.js gesture library.</li>\n<li><strong><a href=\"https://github.com/cyclejs/history\">History</a></strong>: Cycle.js URL Driver based on the rackt/history library.</li>\n<li><strong><a href=\"https://github.com/raquelxmoss/cycle-keys\">Keys</a></strong>: A Cycle.js driver for keyboard events.</li>\n<li><strong><a href=\"https://github.com/whitecolor/cycle-mongoose/\">Mongoose.js</a></strong>: A driver for using Mongoose with Cycle JS. Accepts both, write and read operations.</li>\n<li><strong><a href=\"https://github.com/cyclejs/cycle-notification-driver\">Notification</a></strong>: A Cycle.js Driver for showing and responding to HTML5 Notifications.</li>\n<li><strong><a href=\"https://github.com/TylorS/cycle-router\">Router</a></strong>: A router built from the ground up with Cycle.js in mind. Stands on the shoulders of battle-tested libraries switch-path for route matching and rackt/history for dealing with the History API.</li>\n<li><strong><a href=\"https://github.com/axefrog/cycle-router5\">Router5</a></strong>: A source/sink router driver for Cycle.js, based on router5.</li>\n<li><strong><a href=\"https://github.com/jessaustin/cycle-sse-driver\">Server-Sent Events</a></strong>: Cycle.js driver for Server-Sent Events (SSE), a browser feature also known as EventSource. Server-Sent Events allow the server to continuously update the page with new events, without resorting to hacks like long-polling.</li>\n<li><strong><a href=\"https://github.com/TylorS/cycle-snabbdom\">Snabbdom</a></strong>: Alternative DOM driver utilizing the snabbdom library.</li>\n<li><strong><a href=\"https://github.com/cgeorg/cycle-socket.io\">Socket.IO</a></strong>: A Cycle driver for applications using Socket.IO</li>\n<li><strong><a href=\"https://github.com/cyclejs/storage\">Storage</a></strong>: A Cycle.js Driver for using localStorage and sessionStorage in the browser.</li>\n</ul>\n</li>\n<li>\n<p><strong>Example Projects</strong>: Example applications built with Cycle.js</p>\n<ul>\n<li><strong><a href=\"https://github.com/cyclejs/examples\">Cycle.js Examples</a></strong>: Browse and learn from examples of small Cycle.js apps using Core, DOM Driver, HTML Driver, HTTP Driver, JSONP Driver, and others.</li>\n<li><strong><a href=\"https://github.com/staltz/rxmarbles\">RX Marbles</a></strong>: Interactive diagrams of Rx Observables.</li>\n<li><strong><a href=\"https://github.com/cgeorg/todomvp\">TODO: Minimum Viable Pizza</a></strong>: Minimum Viable Pizza implemented with Cycle.js</li>\n<li><strong><a href=\"https://github.com/Widdershin/tricycle\">Tricycle</a></strong>: A scratchpad for trying out Cycle.js.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=6_ETUyh0tns\">Intro to Functional Reactive Programming with Cycle.js</a></strong>: Nick Johnstone gives an introduction to developing with Cycle.js in this video presentation.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=31URmaeNHSs\">Learning How to Ride: an Introduction to Cycle.js</a></strong>: In this talk, Fernando Macias Pereznieto introduces us to the good, the bad, and the beautiful of using Cycle.js, whether you are a complete beginner or an experienced JS ninja.</li>\n<li>\n<p><strong><a href=\"https://github.com/motorcyclejs/core\">Motorcycle.js</a></strong>: This is a sister project that will continue to evolve and grow alongside Cycle.js for the foreseeable future. The primary focus of this project is to tune it for performance as much as possible.</p>\n<ul>\n<li><strong><a href=\"https://github.com/cujojs/most\">Most</a></strong>: Monadic reactive streams with high performance.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://medium.com/@fkrautwald/plug-and-play-all-your-observable-streams-with-cycle-js-e543fc287872\">Plug and Play All Your Observable Streams With Cycle.js</a></strong>: Frederik Krautwald explains the principles behind Cycle.js, it's inner workings and how to use it to create a simple program with drivers.</li>\n<li><strong><a href=\"https://github.com/Widdershin/tricycle\">Tricycle</a></strong>: A scratchpad for trying out Cycle.js.</li>\n<li><strong><a href=\"http://thenewstack.io/developers-need-know-mvi-model-view-intent/\">What Developers Need to Know about MVI (Model-View-Intent)</a></strong>: The article explains the general MVI pattern and how it relates to React, Reactive Programming and Cycle.js</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://www.polymer-project.org/1.0/docs/devguide/feature-overview.html\">Polymer Project</a></strong>: The Polymer library is designed to make it easier and faster for developers to create great, reusable components for the modern web.</p>\n<ul>\n<li><strong><a href=\"https://www.polymer-project.org/1.0/articles/es6.html\">Building web components using ES6 classes</a></strong>: Web components evolve markup into something that's meaningful, maintainable, and highly modular. Thanks to these new API primitives, not only do we have improved ergonomics when building apps, but we gain better overall structure, design, and reusability.</li>\n<li><strong><a href=\"https://technologyconversations.com/2015/08/09/developing-front-end-microservices-with-polymer-web-components-and-test-driven-development-part-15-the-first-component/\">Developing Front-End Microservices</a></strong>: In this article series we'll go through Web Components development in context of microservices.</li>\n<li><strong><a href=\"https://github.com/TimvdLippe/iron-lazy-pages\">Lazy Loading of Pages</a></strong>: iron-lazy-pages is a Polymer component which allows to load pages on demand.</li>\n<li><strong><a href=\"http://html5-demos.appspot.com/shadowdom-visualizer\">ShadowDOM Visualizer</a></strong>: This tools allows you to visualize how Shadow DOM renders in the browser.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=ZDjiUmx51y8\">Thinking in Polymer (The Polymer Summit 2015)</a></strong>: Kevin Schaaf explains how to employ data binding and composition to build complex application using only Polymer.</li>\n<li><strong><a href=\"https://medium.com/@richardanaya/unidirectional-data-architecture-with-polymer-rxjs-immutable-data-c689386ee998\">Unidirectional Dataflow Architecture with Polymer + RxJS + Immutable Data</a></strong>: Richard Anaya describes how to combine Polymer, RxJS and Freezer to implement a unidirectional data flow architecture.</li>\n<li><strong><a href=\"https://elements.polymer-project.org/guides/using-elements\">Using Elements</a></strong>: This guide describes how to install and use standalone Polymer components in an existing project.</li>\n<li><strong><a href=\"http://paulusschoutsen.nl/blog/2015/07/using-polymer-with-flux-and-a-global-app-state/\">Using Polymer with Flux and a Global App State</a></strong>: Paulus Schoutsen describes his experience integrating Polymer and NuclearJS.</li>\n<li><strong><a href=\"https://www.polymer-project.org/1.0/articles/shadydom.html\">What is shady DOM?</a></strong>: On browsers that support shadow DOM, it's possible to have an element that is rendered with complex DOM, but have that complexity hidden away as implementation detail.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://smacss.com/book/\">SMACSS</a></strong>: SMACSS (pronounced \"smacks\") is a way to examine your design process and as a way to fit those rigid frameworks into a flexible thought process. It is an attempt to document a consistent approach to site development when using CSS.</li>\n<li><strong><a href=\"http://t3js.org/\">T3</a></strong>: T3 is a minimalist JavaScript framework sponsored by Box Inc. that provides core structure to code.</li>\n<li><strong><a href=\"http://guide.elm-lang.org/architecture/index.html\">The Elm Architecture</a></strong>: The Elm Architecture is a simple pattern for infinitely nestable components. It is great for modularity, code reuse, and testing.</li>\n<li><strong><a href=\"http://todomvc.com/\">TodoMVC</a></strong>: A project which offers the same Todo application implemented using MV* concepts in most of the popular JavaScript MV* frameworks of today.</li>\n</ul>\n</li>\n<li>\n<p><strong>Event-Driven Programming</strong>: Event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions, sensor outputs, or messages from other programs/threads.</p>\n<ul>\n<li><strong><a href=\"https://github.com/millermedeiros/js-signals/wiki/Comparison-between-different-Observer-Pattern-implementations\">Comparison Between Different Observer Pattern Implementations</a></strong>: The comparison below is just about the basic features of subscribing to an event type, dispatching and removing an event listener.</li>\n<li><strong><a href=\"https://otaqui.com/blog/1374/event-emitter-pub-sub-or-deferred-promises-which-should-you-choose/\">Event Emitter, Pub Sub or Deferred Promises</a></strong>: In this post Pete Otaqui explores a little about how each pattern works with (very) basic implementations and looks at the reasons why you might choose one over another.</li>\n<li>\n<p><strong>Implementations</strong>: Libraries, frameworks and tools that use Event-Driven Programming paradigm.</p>\n<ul>\n<li><strong><a href=\"https://baconjs.github.io/\">Bacon.js</a></strong>: A small functional reactive programming lib for JavaScript. Turns your event spaghetti into clean and declarative feng shui bacon, by switching from imperative to functional.</li>\n<li><strong><a href=\"http://flightjs.github.io/\">Flight</a></strong>: An event-driven web framework, from Twitter.</li>\n<li><strong><a href=\"http://thejacklawson.com/Mediator.js/\">Mediator.js</a></strong>: Mediator is a simple class that allows you to register, unregister, and call subscriber methods to help event-based, asyncronous programming.</li>\n<li><strong><a href=\"https://github.com/postaljs/postal.js\">Postal.js</a></strong>: Postal.js takes the familiar \"eventing-style\" paradigm and extends it by providing \"broker\" and subscriber implementations</li>\n<li><strong><a href=\"http://radio.uxder.com/\">Radio.js</a></strong>: Radio.js is a small dependency-free publish/subscribe JavaScript library. Use it to implement the observer pattern in your code to help decouple your application architecture for greater maintainability.</li>\n<li><strong><a href=\"http://millermedeiros.github.io/js-signals/\">js-signals</a></strong>: Custom Event/Messaging system for JavaScript.</li>\n<li><strong><a href=\"https://github.com/federico-lox/pubsub.js\">pubsub.js</a></strong>: A tiny (~600 bytes when minified, ~300 bytes when gzip'd) and robust pubsub implementation.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Functional Programming</strong>: Functional programming is a programming paradigm, that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.</p>\n<ul>\n<li>\n<p><strong>A Gentle Introduction to Functional JavaScript</strong>: A 3 part series, by Derick Bailey featuring Chet Harrison, about functional programming with many examples in JavaScript.</p>\n<ul>\n<li><strong><a href=\"https://www.youtube.com/watch?v=ZQSU4geXAxM\">Monads, Monoids and Composition with Functional JavaScript</a></strong>: Chet Harrison explains monads using form validation as an example.</li>\n<li><strong><a href=\"https://github.com/ChetHarrison/A-Gentle-Introduction-to-Functional-JavaScript\">Notes and Code from the Crowdcast</a></strong>: Chet Harrison provides a broad overview of functional programming concepts and a step by step tutorial for building Monads.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=myISHtMMeyU\">The Basics of Functional Programming</a></strong>: In this first episode, you'll learn the basics of why functional programming, what it is, where it came from and what the core of it is. You'll see function composition, function purity, currying, higher order functions and first-class functions.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=JZSoPZUoR58\">A Million Ways to Fold in JS</a></strong>: Brian Lonsdorf provides many functional alternatives to loops in this video.</li>\n<li><strong><a href=\"https://vimeo.com/45140590\">Adventures in Functional Programming</a></strong>: A talk by Jim Weirich, demonstrating how to use functional programming and lambda calculus to derive Y combinator.</li>\n<li><strong><a href=\"http://allong.es/\">Allong.es</a></strong>: allong.es is a JavaScript library based on the function combinator and decorator recipes introduced in the book JavaScript Allongé.</li>\n<li><strong><a href=\"https://github.com/cullophid/barely-functional\">Barely Functional</a></strong>: Tiny (2.7kb) functional programming library using native es5/6 operations.</li>\n<li><strong><a href=\"http://blog.gypsydave5.com/2015/03/21/lazy-eval-and-memo/\">Basic Lazy Evaluation and Memoization in JavaScript</a></strong>: Memoization is a way of optimizing code so that it will return cached results for the same inputs.</li>\n<li><strong><a href=\"http://bilby.brianmckenna.org/\">Bilby.js</a></strong>: A functional library based on category theory with immutable multimethods, functional data structures, functional operator overloading, automated specification testing.</li>\n<li><strong><a href=\"https://medium.com/@homam/composability-from-callbacks-to-categories-in-es6-f3d91e62451e\">Composability: from Callbacks to Categories in ES6</a></strong>: The author borrows some ideas from functional languages to explore a different approach for addressing the callback hell.</li>\n<li><strong><a href=\"https://medium.com/javascript-scene/curry-or-partial-application-8150044c78b8\">Curry or Partial Application?</a></strong>: Eric Elliott describes the difference between partial application and curry.</li>\n<li><strong><a href=\"https://github.com/puffnfresh/daggy\">Daggy</a></strong>: Library for creating tagged constructors with catamorphism.</li>\n<li><strong><a href=\"https://github.com/cullophid/date-fp\">Date FP</a></strong>: Functional programming date manipulation library.</li>\n<li><strong><a href=\"https://medium.com/@drboolean/debugging-functional-7deb4688a08c\">Debugging Functional</a></strong>: This post will demonstrate a simple solution that can go a long way to enhance the debugging experience in functional JavaScript applications.</li>\n<li><strong><a href=\"https://deterministic.curated.co/\">Deterministic</a></strong>: A weekly digest of interesting news and articles covering functional programming for the web, especially on the front end.</li>\n<li>\n<p><strong>Example Projects</strong>: Open source projects which use functional programming, preferably point-free and side-effect-free.</p>\n<ul>\n<li><strong><a href=\"https://github.com/plaid/async-problem\">Async Problem</a></strong>: This project considers various approaches to the problem of concurrently reading files inside a directory and concatenating their contents.</li>\n<li><strong><a href=\"https://github.com/iamstarkov/es-deps-deep\">CommonJS module dependencies resolver</a></strong>: The module and all related modules are written using point-free style.</li>\n<li><strong><a href=\"https://github.com/Bradcomp/egghunt-server/tree/functional\">Egg Hunt Server</a></strong>: A restful API written in FP style.</li>\n<li><strong><a href=\"https://github.com/Avaq/Idealist\">Idealist</a></strong>: Functional HTTP micro-framework.</li>\n<li><strong><a href=\"https://github.com/sanctuary-js/sanctuary-site/blob/gh-pages/scripts/generate\">Sanctuary Build Script</a></strong>: A build script for generating the Sanctuary website.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/fp-dom/fp-dom\">FP DOM</a></strong>: A collection of functions to favor functional programming in a DOM context.</li>\n<li><strong><a href=\"https://github.com/fantasyland/fantasy-combinators\">Fantasy Combinators</a></strong>: Combinators which are used for fantasy-land projects.</li>\n<li>\n<p><strong><a href=\"https://github.com/fantasyland/fantasy-land\">Fantasy Land</a></strong>: Specification for interoperability of common algebraic structures in JavaScript.</p>\n<ul>\n<li><strong><a href=\"https://github.com/fantasyland/fantasy-land/blob/master/implementations.md\">Conformant Implementations</a></strong>: A list of libraries implementing the Fantasy Land specification.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/fantasyland/fantasy-lenses\">Fantasy Lenses</a></strong>: Composable, immutable getters and setters.</li>\n<li><strong><a href=\"https://blog.simpleblend.net/functional-javascript-concepts-currying/\">Functional Concepts For JavaScript Developers: Currying</a></strong>: Andrew Robbins talks about what currying is and why it's useful.</li>\n<li><strong><a href=\"http://www.mokacoding.com/blog/functional-core-reactive-shell/\">Functional Core Reactive Shell</a></strong>: Giovanni Lodi makes an overview of different architecture meta-patterns and describes his current findings about functional programming and observables as a way to control side effects.</li>\n<li><strong><a href=\"https://github.com/paldepind/functional-frontend-architecture\">Functional Frontend Architecture</a></strong>: This repository is meant to document and explore the implementation of what is known as \"the Elm architecture\". A simple functional architecture for building frontend applications.</li>\n<li><strong><a href=\"https://jcouyang.gitbooks.io/functional-javascript/content/en/index.html\">Functional JavaScript Mini Book</a></strong>: Jichao Ouyang gives and introduction to functional programming with JavaScript and describes some Typeclasses like Functor and Monad.</li>\n<li><strong><a href=\"https://github.com/timoxley/functional-javascript-workshop\">Functional Javascript Workshop</a></strong>: The goal of this workshop is to create realistic problems that can be solved using terse, vanilla, idiomatic JavaScript.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=1uRC3hmKQnM\">Functional Principles In React</a></strong>: Jessica Kerr talks about four functional principles: Composition, Declarative Style, Isolation and Flow Of Data, and their usage in React.</li>\n<li><strong><a href=\"https://github.com/hemanth/functional-programming-jargon\">Functional Programming Jargon</a></strong>: Jargon from the functional programming world in simple terms.</li>\n<li><strong><a href=\"https://medium.com/@chetcorcos/functional-programming-for-javascript-people-1915d8775504\">Functional Programming for JavaScript People</a></strong>: Chet Corcos explains different features of functional programming like composition, currying, lazy evaluation, referential transparency and compares Clojure with Haskell.</li>\n<li><strong><a href=\"http://victorsavkin.com/post/63551894251/functional-refactoring-in-javascript\">Functional Refactoring in JavaScript</a></strong>: In this article Victor Savkin shows how to apply functional thinking when refactoring JavaScript code. He does that by taking a simple function and transforming it into a more extendable one, which has no mutable state, and no if statements.</li>\n<li><strong><a href=\"http://functionaljs.com/\">Functional.js</a></strong>: Functional.js is a functional JavaScript library. It facilitates currying and point-free / tacit programming and this methodology has been adhered to from the ground up.</li>\n<li><strong><a href=\"https://github.com/paldepind/functionize\">Functionize</a></strong>: A collection of functions which aids in making non-functional libraries functional.</li>\n<li><strong><a href=\"https://medium.com/@yelouafi/futures-and-monoids-7e9f4574bd88\">Futures and Monoids</a></strong>: Yassine Elouafi explains the nature of Monoids using Futures, Numbers and Strings as examples.</li>\n<li><strong><a href=\"http://functionaltalks.org/2013/05/27/brian-lonsdorf-hey-underscore-youre-doing-it-wrong/\">Hey Underscore, You're Doing It Wrong!</a></strong>: In this talk Brian Lonsdorf gently takes a shot at underscore.js for not thinking about currying and partial function application in its library design.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=mS264h8KGwk\">Immutability, Interactivity &#x26; JavaScript</a></strong>: We'll dive in and see how trees of JavaScript arrays can permit building efficient immutable collections. Then we'll see how embracing immutable values dramatically simplifies some classic hard problems in client side programming including but not limited to undo, error playback, and online/offline synchronization.</li>\n<li><strong><a href=\"https://github.com/qiao/immutable-sequence.js\">Immutable Sequence.js</a></strong>: High performance implementation of Immutable Sequence in JavaScript, based on Finger Tree.</li>\n<li><strong><a href=\"https://github.com/facebook/immutable-js/\">Immutable.js</a></strong>: Immutable persistent data collections for Javascript which increase efficiency and simplicity.</li>\n<li><strong><a href=\"https://javascriptair.com/episodes/2015-12-30/\">JSAir - Functional and Immutable Design Patterns in JavaScript</a></strong>: An episode of JavaScript Air about \"the how and why of functional programming and immutable design patterns in JavaScript\" with Dab Abramov and Brian Lonsdorf as guests.</li>\n<li><strong><a href=\"https://medium.com/@yelouafi/javascript-and-type-thinking-735edddc388d\">JavaScript and Type Thinking</a></strong>: Yassine Elouafi introduces Algebraic Data Types with an example of a simple and a recursive type.</li>\n<li><strong><a href=\"https://vimeo.com/97408202\">Javascript Combinators by Reginald Braithwaite</a></strong>: In this talk, we'll explore functions that consume and return functions, and see how they can be used to build expressive programs that hew closely to JavaScript's natural style.</li>\n<li><strong><a href=\"https://github.com/loop-recur/lambdajs\">Lamda.js</a></strong>: This library takes all the methods on instances of strings, arrays, objects, numbers, and regexp's and turns them into functions that can be used in a pointfree way.</li>\n<li><strong><a href=\"https://vimeo.com/104807358\">Lenses Quick n' Dirty</a></strong>: A video by Brian Lonsdorf that introduces lenses.</li>\n<li><strong><a href=\"http://joneshf.github.io/programming/2015/12/19/Lenses-and-Virtual-DOM-Support-Open-Closed.html\">Lenses and Virtual DOM Support Open Closed</a></strong>: Hardy Jones explains how Lenses work using a simple example of working with Virtual DOM.</li>\n<li><strong><a href=\"https://github.com/DrBoolean/lenses\">Lenses.js</a></strong>: Composable kmett style lenses.</li>\n<li><strong><a href=\"https://github.com/lodash/lodash/wiki/FP-Guide\">Lodash/fp</a></strong>: The lodash/fp module is an instance of lodash with its methods wrapped to produce immutable auto-curried iteratee-first data-last methods.</li>\n<li><strong><a href=\"http://alistapart.com/article/making-your-javascript-pure\">Making your JavaScript Pure</a></strong>: Jack Franklin compares pure and impure functions and describes how to leverage functional programming principles in JavaScript.</li>\n<li>\n<p><strong>Monads</strong>: Composable computation descriptions. The essence of monad is thus separation of composition timeline from the composed computation's execution timeline, as well as the ability of computation to implicitly carry extra data.</p>\n<ul>\n<li>\n<p><strong>Collections of Monads</strong>: Libraries of monad implementations.</p>\n<ul>\n<li><strong><a href=\"http://akh-js.com/\">Akh</a></strong>: Akh includes a basic set of common monad transformers, along with monads derived from these transformers. Akh structures implement the Fantasy Land specification.</li>\n<li><strong><a href=\"http://folktale.origamitower.com\">Folktale</a></strong>: Folktale is a suite of libraries for generic functional programming in JavaScript that allows you to write elegant modular applications with fewer bugs, and more reuse.</li>\n<li><strong><a href=\"https://github.com/cwmyers/monet.js\">Monet.js</a></strong>: Monet is a tool bag that assists Functional Programming by providing a rich set of Monads and other useful functions.</li>\n</ul>\n</li>\n<li>\n<p><strong>Continuation Monad</strong>: Represents computations in continuation-passing style (CPS). In continuation-passing style function result is not returned, but instead is passed to another function, received as a parameter (continuation).</p>\n<ul>\n<li><strong><a href=\"http://blog.mattbierner.com/the-delimited-continuation-monad-in-javascript/\">The Delimited Continuation Monad in Javascript</a></strong>: This post overviews continuations in Atum and covers the implementation of the delimited continuation monad in JavaScript.</li>\n</ul>\n</li>\n<li>\n<p><strong>Either Monad</strong>: The Either type represents values with two possibilities: a value of type Either a b is either Left a or Right b. It is often used for error handling.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/lazy-either\">Lazy Either</a></strong>: The LazyEither type is used to represent a lazy Either value. It is similar to the Future and Promise types.</li>\n<li><strong><a href=\"https://tech.evojam.com/2016/03/21/practical-intro-to-monads-in-javascript-either/\">Practical Intro to Monads in JavaScript: Either</a></strong>: Jakub Strojewski describes the Either Monad, a tool for fast-failing, synchronous computation chains.</li>\n</ul>\n</li>\n<li>\n<p><strong>Free Monad</strong>: A free monad satisfies all the Monad laws, but does not do any computation. It just builds up a nested series of contexts. The user who creates such a free monadic value is responsible for doing something with those nested contexts.</p>\n<ul>\n<li><strong><a href=\"https://github.com/fantasyland/fantasy-frees\">Fantasy Frees</a></strong>: An implementation of Coyoneda, Yoneda, Trampoline, Free Monad and Free Applicative with usage examples.</li>\n<li><strong><a href=\"https://github.com/joneshf/abstractions/tree/master/src\">Free Monad Experiments by Hardy Jones</a></strong>: Coyoneda, Coproduct, Either, Free, State, AJAX and so on.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=WH5BrkzGgQY&#x26;list=PLK_hdtAJ4KqUWp5LJdLOgkD_8qKW0iAHi&#x26;index=1\">Free Monads Video Series</a></strong>: A video series on free monads by Brian Lonsdorf explaining Coyoneda, Free Monad and Interpretors.</li>\n<li><strong><a href=\"https://github.com/DrBoolean/freeky\">Freeky</a></strong>: Collection of free monads by Brian Lonsdorf.</li>\n</ul>\n</li>\n<li>\n<p><strong>Futures</strong>: Futures represent the value arising from the success or failure of an asynchronous operation (I/O).</p>\n<ul>\n<li><strong><a href=\"https://github.com/Avaq/Fluture\">Fluture</a></strong>: The debuggable Fantasy Land Future library.</li>\n<li><strong><a href=\"http://folktale.origamitower.com/api/v2.1.0/en/folktale.concurrency.task.html\">Folktale Task</a></strong>: A structure for time-dependent values, providing explicit effects for delayed computations, latency, etc.</li>\n<li><strong><a href=\"https://medium.com/@yelouafi/from-callback-to-future-functor-monad-6c86d9c16cb5\">From Callback to Future -> Functor -> Monad</a></strong>: Yassine Elouafi goes through a simple implementation of Futures and compares them to Promises.</li>\n<li><strong><a href=\"https://github.com/futurize/future-io\">Future IO</a></strong>: A fantasy-land compliant monadic IO library for Node.js.</li>\n<li><strong><a href=\"https://github.com/arcseldon/futurizer\">Futurizer</a></strong>: Turn callback-style functions or promises into futures!</li>\n</ul>\n</li>\n<li>\n<p><strong>Introduction</strong>: Introductory materials about monads.</p>\n<ul>\n<li><strong><a href=\"https://curiosity-driven.org/monads-in-javascript\">Monads in JavaScript</a></strong>: This article explains monads and their usage in JavaScript including Identity, Maybe, List, Continuation, Do notation and Chaining.</li>\n<li><strong><a href=\"https://tech.evojam.com/2016/02/22/practical-intro-to-monads-in-javascript/\">Practical Intro to Monads in JavaScript</a></strong>: A simple, practical tutorial for JavaScript developers showing how some monads can be used.</li>\n<li><strong><a href=\"http://igstan.ro/posts/2011-05-02-understanding-monads-with-javascript.html\">Understanding Monads With JavaScript</a></strong>: The author starts with a problem of dealing with explicit immutable state and solves it with JavaScript using monads.</li>\n</ul>\n</li>\n<li>\n<p><strong>Maybe Monad</strong>: Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error. It is a simple kind of error monad, where all errors are represented by Nothing. A richer error monad can be built using the Either type.</p>\n<ul>\n<li><strong><a href=\"http://sean.voisen.org/blog/2013/10/intro-monads-maybe/\">A Gentle Intro to Monads … Maybe?</a></strong>: A short introduction to Maybe and the world of monads.</li>\n<li><strong><a href=\"http://robotlolita.me/2013/12/08/a-monad-in-practicality-first-class-failures.html\">A Monad in Practicality: First-Class Failures</a></strong>: This article shows how the Maybe monad can be used for handling simple failure use cases. It then extrapolates into complex failure scenarios and shows how these cases can be modelled in terms of the Either monad.</li>\n<li><strong><a href=\"https://tech.evojam.com/2016/02/22/practical-intro-to-monads-in-javascript/\">Practical Intro to Monads in JavaScript</a></strong>: A simple, practical tutorial for JavaScript developers showing how some monads can be used.</li>\n</ul>\n</li>\n<li>\n<p><strong>Reader Monad</strong>: Represents a computation, which can read values from a shared environment, pass values from function to function, and execute sub-computations in a modified environment.</p>\n<ul>\n<li><strong><a href=\"https://passy.svbtle.com/dont-fear-the-reader\">Don't Fear the Reader</a></strong>: Pascal Hartig explains how to use the reader monad in JavaScript.</li>\n<li><strong><a href=\"https://github.com/fantasyland/fantasy-readers\">Fantasy Readers</a></strong>: Fantasy Land compatible implementation of the Reader Monad.</li>\n<li><strong><a href=\"https://www.livecoding.tv/evilsoft/videos/WojoB-functional-js-reader-monad\">LiveCoding Video of Reader Monad Implementation</a></strong>: In this video you will learn how to use and implement a Reader from scratch.</li>\n<li><strong><a href=\"https://vimeo.com/105300347\">Monad a Day: Reader</a></strong>: Short video by Brian Lonsdorf about the Reader Monad.</li>\n</ul>\n</li>\n<li>\n<p><strong>Transformers</strong>: Special types that allow us to roll two monads into a single one that shares the behavior of both.</p>\n<ul>\n<li><strong><a href=\"http://akh-js.com/\">Akh</a></strong>: Akh includes a basic set of common monad transformers, along with monads derived from these transformers. Akh structures implement the Fantasy Land specification.</li>\n<li><strong><a href=\"https://github.com/quarterto-archive/fantasy-arrayt\">Fantasy ArrayT</a></strong>: Monad transformer for JavaScript Arrays.</li>\n<li><strong><a href=\"https://github.com/boris-marinov/monad-transformers\">Monad Transformers</a></strong>: Monad transformers are tricky, they require an excessive amount of type juggling. One of the aims of this package is to reduce the amount of wrapping and unwrapping needed for making a new transformer and to provide an easy way to define and combine transformers.</li>\n<li><strong><a href=\"https://github.com/boris-marinov/monad-transformers\">Monad Transformers Library</a></strong>: Practical monad transformers for JS.</li>\n</ul>\n</li>\n<li>\n<p><strong>Validation Monad</strong>: A disjunction that is appropriate for validating inputs and aggregating failures.</p>\n<ul>\n<li><strong><a href=\"http://folktale.origamitower.com/api/v2.1.0/en/folktale.validation.html\">Folktale Validation</a></strong>: Validation Monad implementation of Folktale Library.</li>\n<li><strong><a href=\"https://tech.evojam.com/2016/04/26/practical-intro-to-monads-in-javascript-validation/\">Practical Intro to Monads in JavaScript: Validation</a></strong>: Jakub Strojewski shows how to accumulate errors in a simple Validation use case.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong><a href=\"http://swannodette.github.io/mori/\">Mori</a></strong>: A library for using ClojureScript's persistent data structures and supporting API from the comfort of vanilla JavaScript.</li>\n<li><strong><a href=\"https://drboolean.gitbooks.io/mostly-adequate-guide/content/\">Mostly Adequate Guide to Functional Programming</a></strong>: A book by Brian Lonsdorf that introduces algebraic functional programming in JavaScript.</li>\n<li><strong><a href=\"http://kovach.me/nanoscope/\">Nanoscope</a></strong>: Nanoscope is a javascript library designed to make complex transformations of data much easier. It is a built on the idea of a functional Lens - a construct that enables focusing on sub-parts of data structures to get and modify.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/pointfree-fantasy\">Pointfree Fantasy</a></strong>: Point-free wrappers for fantasy-land. Functions are curried using lodash's curry function, and receive their data last. Gives us aliases with our familar haskell names as well.</li>\n<li><strong><a href=\"http://lucasmreis.github.io/blog/pointfree-javascript/\">Pointfree Javascript</a></strong>: In this post Lucas Reis presents what is called pointfree style programming and goes through some common scenarios to demonstrate its benefits.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=XcS-LdEBUkE\">Practical Functional Programming: Pick Two</a></strong>: James Coglan tries to show in this video how to use functional concepts in daily JavaScript programming.</li>\n<li><strong><a href=\"https://medium.com/@yelouafi/promises-fp-beautiful-streams-6f0235c5b179\">Promises + FP = Beautiful Streams</a></strong>: Yassine Elouafi show how to use functional programming and algebraic data types to derive a pure functional definition of reactive programming like streams.</li>\n<li><strong><a href=\"https://vimeo.com/49384334\">Pure JavaScript</a></strong>: Christian Johansen shows you how you can up your game by leaving loops behind and embracing functions as the primary unit of abstraction.</li>\n<li><strong><a href=\"http://rauchg.com/2015/pure-ui/\">Pure UI</a></strong>: Guillermo Rauch discusses the definition of an application's UI as a pure function of application state.</li>\n<li><strong><a href=\"http://www.purescript.org/\">PureScript</a></strong>: PureScript is a strongly, statically typed language which compiles to JavaScript. It is written in and inspired by Haskell.</li>\n<li>\n<p><strong><a href=\"http://ramdajs.com/\">Ramda</a></strong>: A practical library designed specifically for a functional programming style, one that makes it easy to create functional pipelines, one that never mutates user data.</p>\n<ul>\n<li><strong>Practical Ramda - Functional Programming Examples</strong>: Tom MacWright gives some practical examples of Ramda usage.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/ramda/ramda-fantasy\">Ramda Fantasy</a></strong>: Fantasy Land compatible types for easy integration with Ramda. This is an experimental project and will probably merge with Sanctuary.</li>\n<li>\n<p><strong><a href=\"http://sanctuary.js.org/\">Sanctuary</a></strong>: Sanctuary is a functional programming library inspired by Haskell and PureScript. It depends on and works nicely with Ramda. Sanctuary makes it possible to write safe code without null checks.</p>\n<ul>\n<li><strong><a href=\"https://github.com/sanctuary-js/sanctuary-site/blob/gh-pages/scripts/generate\">Sanctuary Build Script</a></strong>: A build script for generating the Sanctuary website.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://jaysoo.ca/2016/01/13/functional-programming-little-ideas/\">The Little Idea of Functional Programming</a></strong>: Jack Hsu tries to take a look at a couple of simple concepts that make up the little idea behind functional programming and to tie the concepts back to code examples in JavaScript.</li>\n<li><strong><a href=\"http://guigrpa.github.io/timm/\">Timm</a></strong>: Immutability helpers with fast reads and acceptable writes.</li>\n<li>\n<p><strong><a href=\"http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming\">Transducers</a></strong>: Transducers are a powerful and composable way to build algorithmic transformations that you can reuse in many contexts.</p>\n<ul>\n<li><strong><a href=\"https://www.youtube.com/watch?v=6mTbuzafcII\">\"Transducers\" Presentation at Strange Loop</a></strong>: This talk will describe transducers, a new library feature for Clojure (but of interest to other languages) that emphasizes composable, context-free, intermediate-free notions like 'mapping' and 'filtering' and their concrete reuse across all of the contexts above.</li>\n<li><strong><a href=\"http://gfxmonk.net/2015/11/25/figuring-out-what-transducers-are-good-for.html\">Figuring out what transducers are good for</a></strong>: Tim Cuthbertson attempts some plausible but detailed examples with Transducers in JavaScript.</li>\n<li>\n<p><strong>Implementations</strong>: Libraries that implement Transducer protocoll and include ready to use transformers.</p>\n<ul>\n<li><strong><a href=\"https://github.com/transduce/transduce\">Transduce</a></strong>: Implementation by Kevin Beaty extracted from underarm.</li>\n<li><strong><a href=\"https://github.com/cognitect-labs/transducers-js\">Transducers-js by Cognitect Labs</a></strong>: A high performance Transducers implementation for JavaScript by Cognitect Labs.</li>\n<li>\n<p><strong><a href=\"https://github.com/jlongster/transducers.js\">Transducers.js Library by James Long</a></strong>: A small library for generalized transformation of data (inspired by Clojure's transducers)</p>\n<ul>\n<li><strong><a href=\"http://jlongster.com/Transducers.js-Round-2-with-Benchmarks\">Transducers.js Round 2 with Benchmarks</a></strong>: Refactored version of Transducers.js, some benchmarks, Laziness, the transformer protocoll.</li>\n<li><strong><a href=\"http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data\">Transducers.js: A JavaScript Library for Transformation of Data</a></strong>: A post announcing the transducers.js library with some explanation.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong><a href=\"http://simplectic.com/blog/2015/ramda-transducers-logs/\">Streaming Logs with Transducers and Ramda</a></strong>: In this article we will use Ramda to parse a log file without curly braces (and introduce transducers along the way).</li>\n<li><strong><a href=\"http://clojure.org/reference/transducers\">Transducers Documentation for Clojure</a></strong>: Transducers are composable algorithmic transformations. They are independent from the context of their input and output sources and specify only the essence of the transformation in terms of an individual element.</li>\n<li><strong><a href=\"http://simplectic.com/blog/2014/transducers-explained-1/\">Transducers Explained: Part 1</a></strong>: An introduction to transducers using JavaScript. We will work from reducing over arrays, to defining transformations as transformers, then incrementally introducing transducers and using them with transduce.</li>\n<li><strong><a href=\"http://simplectic.com/blog/2014/transducers-explained-pipelines/\">Transducers Explained: Pipelines</a></strong>: In this article, we will introduce four new transducers: filter, remove, drop and take. We will show how transducers can be composed into pipelines and talk about the order of transformation.</li>\n<li><strong><a href=\"http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming\">Transducers are Coming</a></strong>: The first announcement by Rich Hickey.</li>\n<li><strong><a href=\"https://xgrommx.github.io/rx-book/content/getting_started_with_rxjs/creating_and_querying_observable_sequences/transducers.html\">Transducers with Observable Sequences</a></strong>: A chapter from the RxJS Book describing Transducers.</li>\n<li><strong><a href=\"https://medium.com/@roman01la/understanding-transducers-in-javascript-3500d3bd9624#.3lbq6d4yq\">Understanding Transducers in JavaScript</a></strong>: Roman Liutikov translated code examples from similar Clojure article into JavaScript. So you can still read the article and check code examples here.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/paldepind/union-type\">Union Type</a></strong>: Union types are a way to group different values together. Union-type is a small JavaScript library for defining and using union types.</li>\n</ul>\n</li>\n<li>\n<p><strong>Functional Reactive Programming (FRP)</strong>: FRP is a programming paradigm for asynchronous dataflow programming using the building blocks of functional programming.</p>\n<ul>\n<li><strong><a href=\"https://github.com/kriskowal/gtor\">A General Theory of Reactivity</a></strong>: Kris Kowal describes popular primitives of Reactive Programming and some use cases.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=R9CGieinKVo\">A General Theory of Reactivity (Video)</a></strong>: Kris Kowal talks about reactive primitives and their traits.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=Agu6jipKfYw\">Controlling Time and Space</a></strong>: This talk will quickly cover the basics of FRP, and then go into a couple different formulations of FRP that people are beginning to use. We will explore how these formulations fit together historically and theoretically.</li>\n<li>\n<p><strong><a href=\"http://cycle.js.org/\">Cycle.js</a></strong>: A functional and reactive JavaScript framework that solves the cyclic dependency of Observables which emerge during dialogues (mutual observations) between the Human and the Computer.</p>\n<ul>\n<li><strong><a href=\"https://github.com/whitecolor/cycle-async-driver\">Async Driver</a></strong>: Higher order factory for creating cycle.js async request based drivers. Allows you almost completely eliminate boilerplate code for this kind of drivers.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=Rj8ZTRVka4E\">Cycle.js Was Built to Solve Problems</a></strong>: In this video André Staltz shows how Cycle.js has a practical purpose, meant to solve problems your customers/business may relate to.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=uNZnftSksYg\">Cycle.js and Functional Reactive User Interfaces</a></strong>: In this talk we will discover how Cycle.js is purely reactive and functional, and why it's an interesting alternative to React.</li>\n<li><strong><a href=\"https://glebbahmutov.com/draw-cycle/\">Draw Cycle</a></strong>: Simple Cycle.js program visualized</li>\n<li>\n<p><strong><a href=\"http://cycle.js.org/drivers.html\">Drivers</a></strong>: Drivers are functions that listen to Observable sinks (their input), perform imperative side effects, and may return Observable sources (their output).</p>\n<ul>\n<li><strong><a href=\"https://github.com/Widdershin/cycle-animation-driver\">Animation</a></strong>: A Cycle driver for requestAnimationFrame.</li>\n<li><strong><a href=\"https://github.com/benji6/cycle-audio-graph\">Audio Graph Driver</a></strong>: Audio graph driver for Cycle.js based on virtual-audio-graph.</li>\n<li><strong><a href=\"https://github.com/10clouds/cyclejs-cookie\">Cookie</a></strong>: Cycle.js Cookie Driver, based on cookie_js library.</li>\n<li><strong><a href=\"https://github.com/cyclejs/dom\">DOM</a></strong>: The standard DOM Driver for Cycle.js based on virtual-dom, and other helpers.</li>\n<li><strong><a href=\"https://github.com/secobarbital/cycle-fetch-driver\">Fetch</a></strong>: A Cycle.js Driver for making HTTP requests, using the Fetch API.</li>\n<li><strong><a href=\"https://github.com/r7kamura/cycle-fetcher-driver\">Fetcher</a></strong>: A Cycle.js Driver for making HTTP requests using stackable-fetcher.</li>\n<li><strong><a href=\"https://github.com/dralletje/cycle-firebase\">Firebase</a></strong>: Thin layer around the firebase javascript API that allows you to query and declaratively update your favorite real-time database.</li>\n<li><strong><a href=\"https://github.com/cyclejs/http\">HTTP</a></strong>: A Cycle.js Driver for making HTTP requests, based on superagent.</li>\n<li><strong><a href=\"https://github.com/CyclicMaterials/cycle-hammer-driver\">Hammer.js</a></strong>: The driver incorporates the Hammer.js gesture library.</li>\n<li><strong><a href=\"https://github.com/cyclejs/history\">History</a></strong>: Cycle.js URL Driver based on the rackt/history library.</li>\n<li><strong><a href=\"https://github.com/raquelxmoss/cycle-keys\">Keys</a></strong>: A Cycle.js driver for keyboard events.</li>\n<li><strong><a href=\"https://github.com/whitecolor/cycle-mongoose/\">Mongoose.js</a></strong>: A driver for using Mongoose with Cycle JS. Accepts both, write and read operations.</li>\n<li><strong><a href=\"https://github.com/cyclejs/cycle-notification-driver\">Notification</a></strong>: A Cycle.js Driver for showing and responding to HTML5 Notifications.</li>\n<li><strong><a href=\"https://github.com/TylorS/cycle-router\">Router</a></strong>: A router built from the ground up with Cycle.js in mind. Stands on the shoulders of battle-tested libraries switch-path for route matching and rackt/history for dealing with the History API.</li>\n<li><strong><a href=\"https://github.com/axefrog/cycle-router5\">Router5</a></strong>: A source/sink router driver for Cycle.js, based on router5.</li>\n<li><strong><a href=\"https://github.com/jessaustin/cycle-sse-driver\">Server-Sent Events</a></strong>: Cycle.js driver for Server-Sent Events (SSE), a browser feature also known as EventSource. Server-Sent Events allow the server to continuously update the page with new events, without resorting to hacks like long-polling.</li>\n<li><strong><a href=\"https://github.com/TylorS/cycle-snabbdom\">Snabbdom</a></strong>: Alternative DOM driver utilizing the snabbdom library.</li>\n<li><strong><a href=\"https://github.com/cgeorg/cycle-socket.io\">Socket.IO</a></strong>: A Cycle driver for applications using Socket.IO</li>\n<li><strong><a href=\"https://github.com/cyclejs/storage\">Storage</a></strong>: A Cycle.js Driver for using localStorage and sessionStorage in the browser.</li>\n</ul>\n</li>\n<li>\n<p><strong>Example Projects</strong>: Example applications built with Cycle.js</p>\n<ul>\n<li><strong><a href=\"https://github.com/cyclejs/examples\">Cycle.js Examples</a></strong>: Browse and learn from examples of small Cycle.js apps using Core, DOM Driver, HTML Driver, HTTP Driver, JSONP Driver, and others.</li>\n<li><strong><a href=\"https://github.com/staltz/rxmarbles\">RX Marbles</a></strong>: Interactive diagrams of Rx Observables.</li>\n<li><strong><a href=\"https://github.com/cgeorg/todomvp\">TODO: Minimum Viable Pizza</a></strong>: Minimum Viable Pizza implemented with Cycle.js</li>\n<li><strong><a href=\"https://github.com/Widdershin/tricycle\">Tricycle</a></strong>: A scratchpad for trying out Cycle.js.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=6_ETUyh0tns\">Intro to Functional Reactive Programming with Cycle.js</a></strong>: Nick Johnstone gives an introduction to developing with Cycle.js in this video presentation.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=31URmaeNHSs\">Learning How to Ride: an Introduction to Cycle.js</a></strong>: In this talk, Fernando Macias Pereznieto introduces us to the good, the bad, and the beautiful of using Cycle.js, whether you are a complete beginner or an experienced JS ninja.</li>\n<li>\n<p><strong><a href=\"https://github.com/motorcyclejs/core\">Motorcycle.js</a></strong>: This is a sister project that will continue to evolve and grow alongside Cycle.js for the foreseeable future. The primary focus of this project is to tune it for performance as much as possible.</p>\n<ul>\n<li><strong><a href=\"https://github.com/cujojs/most\">Most</a></strong>: Monadic reactive streams with high performance.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://medium.com/@fkrautwald/plug-and-play-all-your-observable-streams-with-cycle-js-e543fc287872\">Plug and Play All Your Observable Streams With Cycle.js</a></strong>: Frederik Krautwald explains the principles behind Cycle.js, it's inner workings and how to use it to create a simple program with drivers.</li>\n<li><strong><a href=\"https://github.com/Widdershin/tricycle\">Tricycle</a></strong>: A scratchpad for trying out Cycle.js.</li>\n<li><strong><a href=\"http://thenewstack.io/developers-need-know-mvi-model-view-intent/\">What Developers Need to Know about MVI (Model-View-Intent)</a></strong>: The article explains the general MVI pattern and how it relates to React, Reactive Programming and Cycle.js</li>\n</ul>\n</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=uNZnftSksYg\">Cycle.js and Functional Reactive User Interfaces</a></strong>: In this talk we will discover how Cycle.js is purely reactive and functional, and why it's an interesting alternative to React.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=v68ppDlvHqs\">Dynamics of Change: why Reactivity Matters</a></strong>: In this talk we will see when passive or reactive strategy is advantageous, and how the reactive strategy is a sensible default.</li>\n<li><strong><a href=\"https://vimeo.com/68987289\">Enemy of the State</a></strong>: An introduction to Functional Reactive Programming and Bacon.js by Philip Roberts.</li>\n<li><strong><a href=\"https://github.com/mobxjs/mobx\">MobX</a></strong>: MobX is a battle tested library that makes state management simple and scalable by transparently applying functional reactive programming.</li>\n<li><strong><a href=\"https://medium.com/@yelouafi/promises-fp-beautiful-streams-6f0235c5b179\">Promises + FP = Beautiful Streams</a></strong>: Yassine Elouafi show how to use functional programming and algebraic data types to derive a pure functional definition of reactive programming like streams.</li>\n<li>\n<p><strong>Stream Libraries</strong>: Libraries which help you compose asynchronous operations on streams of time-varying values and events.</p>\n<ul>\n<li><strong><a href=\"http://baconjs.github.io/\">Bacon.js</a></strong>: A small functional reactive programming lib for JavaScript. Turns your event spaghetti into clean and declarative feng shui bacon, by switching from imperative to functional.</li>\n<li><strong><a href=\"https://rpominov.github.io/kefir/\">Kefir.js</a></strong>: Kefir — is a Reactive Programming library for JavaScript inspired by Bacon.js and RxJS, with focus on high performance and low memory usage.</li>\n<li><strong><a href=\"https://github.com/cujojs/most\">Most</a></strong>: Monadic reactive streams with high performance.</li>\n<li>\n<p><strong><a href=\"https://github.com/Reactive-Extensions/RxJS\">Reactive Extensions (RxJS)</a></strong>: RxJS is a set of libraries for composing asynchronous and event-based programs using observable sequences and fluent query operators.</p>\n<ul>\n<li><strong><a href=\"https://www.youtube.com/watch?v=XRYN2xt11Ek\">Async JavaScript with Reactive Extensions</a></strong>: Jafar Husain explains in this video how Netflix uses the Reactive Extensions (Rx) library to build responsive user experiences that strive to be event-driven, scalable and resilient.</li>\n<li><strong><a href=\"http://blog.thoughtram.io/rx/2016/08/01/exploring-rx-operators-flatmap.html\">Exploring Rx Operators: FlatMap</a></strong>: Christoph Burgdorf introduces the FlatMap operator and its usage for collections and observables.</li>\n<li><strong><a href=\"http://blog.thoughtram.io/angular/2016/05/16/exploring-rx-operators-map.html\">Exploring Rx Operators: Map</a></strong>: Christoph Burgdorf explains how to use the map operator in RxJS.</li>\n<li><strong><a href=\"http://www.mokacoding.com/blog/functional-core-reactive-shell/\">Functional Core Reactive Shell</a></strong>: Giovanni Lodi makes an overview of different architecture meta-patterns and describes his current findings about functional programming and observables as a way to control side effects.</li>\n<li><strong><a href=\"http://reactivex.io/learnrx/\">Learn RX</a></strong>: A series of interactive exercises for learning Microsoft's Reactive Extensions (Rx) Library for Javascript.</li>\n<li><strong><a href=\"http://www.learnrxjs.io/\">Learn RxJS</a></strong>: This site focuses on making RxJS concepts approachable, the examples clear and easy to explore, and features references throughout to the best RxJS related material on the web.</li>\n<li><strong><a href=\"https://medium.com/@sergimansilla/real-world-observables-1f65748c8f9\">Real World Observables</a></strong>: Sergi Mansilla writes an FTP client to use it as an example for a real world application based on RxJS.</li>\n<li><strong><a href=\"https://github.com/JulienMoumne/rx-training-games\">Rx Training Games</a></strong>: Rx Training Games is a coding playground that can be used to learn and practice Reactive Extensions coding grid-based games</li>\n<li><strong><a href=\"http://xgrommx.github.io/rx-book/index.html\">Rx-Book</a></strong>: A complete book about RxJS v.4.0.</li>\n<li><strong><a href=\"http://rxmarbles.com/\">RxMarbles</a></strong>: A webapp for experimenting with diagrams of Rx Observables, for learning purposes.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/rxstate\">RxState</a></strong>: Simple opinionated state management library based on RxJS and Immutable.js</li>\n<li><strong><a href=\"http://blog.thoughtram.io/angular/2016/01/06/taking-advantage-of-observables-in-angular2.html\">Taking Advantage of Observables in Angular 2</a></strong>: Christoph Burgdorf describes the advantages of Observables and how you can use them in Angular 2 context.</li>\n<li><strong><a href=\"https://xgrommx.github.io/rx-book/content/getting_started_with_rxjs/creating_and_querying_observable_sequences/transducers.html\">Transducers with Observable Sequences</a></strong>: A chapter from the RxJS Book describing Transducers.</li>\n<li><strong><a href=\"http://staltz.com/why-we-built-xstream.html\">Why We Built Xstream</a></strong>: The authors needed a stream library tailored for Cycle.js. It needs to be \"hot\" only, small in kB size and it should have only a few and intuitive operators.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://github.com/staltz/xstream\">Xstream</a></strong>: An extremely intuitive, small, and fast functional reactive stream library for JavaScript.</p>\n<ul>\n<li><strong><a href=\"http://staltz.com/why-we-built-xstream.html\">Why We Built Xstream</a></strong>: The authors needed a stream library tailored for Cycle.js. It needs to be \"hot\" only, small in kB size and it should have only a few and intuitive operators.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong><a href=\"https://gist.github.com/staltz/868e7e9bc2a7b8c1f754\">The Introduction to Reactive Programming</a></strong>: André Staltz provides a complete introduction to the Reactive Programming and RxJS.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=1zj7M1LnJV4\">What if the User was a Function?</a></strong>: In this video André Staltz talks about the input/output cycle between humans and computers and how to take advantage of this model by using FRP and event streams.</li>\n</ul>\n</li>\n</ul>\n<h2>Compatibility</h2>\n<p>Ability of a product to work with different input/output devices and rendering software. Including printers, email, mobile devices and different browsers.</p>\n<ul>\n<li>\n<p><strong>Cross Browser</strong>: Cross-browser refers to the ability of a website, web application, HTML construct or client-side script to function in environments that provide its required features and to bow out or degrade gracefully when features are absent or lacking.</p>\n<ul>\n<li><strong><a href=\"http://caniuse.com/\">Can I use ... ?</a></strong>: \"Can I use\" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.</li>\n<li><strong><a href=\"https://developer.microsoft.com/en-us/microsoft-edge/tools/\">Dev Tools by Microsoft</a></strong>: These tools allow you to test your product on different version of Internet Explorer and Microsoft Edge.</li>\n<li><strong><a href=\"https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills\">HTML5 Cross Browser Polyfills</a></strong>: So here we're collecting all the shims, fallbacks, and polyfills in order to implant HTML5 functionality in browsers that don't natively support them.</li>\n<li><strong><a href=\"http://html5please.com/\">HTML5 Please</a></strong>: Look up HTML5, CSS3, etc features, know if they are ready for use, and if so find out how you should use them - with polyfills, fallbacks or as they are.</li>\n<li><strong><a href=\"https://modernizr.com/\">Modernizr</a></strong>: It's a collection of superfast tests - or \"detects\" as we like to call them - which run as your web page loads, then you can use the results to tailor the experience to the user.</li>\n<li><strong><a href=\"http://necolas.github.io/normalize.css/\">Normalize.css</a></strong>: A modern, HTML5-ready alternative to CSS resets.</li>\n<li><strong><a href=\"https://polyfill.io/\">Polyfill.io</a></strong>: Just the polyfills you need for your site, tailored to each browser.</li>\n</ul>\n</li>\n<li>\n<p><strong>E-Mail</strong>: Preparing HTML based electronic mail.</p>\n<ul>\n<li><strong><a href=\"https://buttons.cm/\">Bulletproof E-Mail Buttons</a></strong>: Design gorgeous buttons using progressively enhanced VML and CSS.</li>\n<li><strong><a href=\"https://github.com/sparkbox/email-lab\">Email Lab</a></strong>: This a project for developing and testing email templates. It uses Grunt to streamline and simplify the creation of email templates. Email template can be built with re-usable components.</li>\n<li><strong><a href=\"https://github.com/seanpowell/Email-Boilerplate\">Email-Boilerplate</a></strong>: Use these code examples as a guideline for formatting your HTML email to avoid some of the major styling pitfalls in HTML email design.</li>\n<li><strong><a href=\"http://foundation.zurb.com/emails.html\">Foundation for Emails 2</a></strong>: Frontend Framework for E-Mails including a grid, global styles, aligment classes, buttons, callout panels, thumbnail styles, typography, visibility classes.</li>\n<li><strong><a href=\"https://mjml.io/\">MJML</a></strong>: MJML is a markup language designed to reduce the pain of coding a responsive email. Its semantic syntax makes it easy and straightforward and its rich standard components library speeds up your development time and lightens your email codebase.</li>\n<li><strong><a href=\"https://github.com/mailchimp/Email-Blueprints\">MailChimp E-Mail Blueprints</a></strong>: Email Blueprints is a collection of HTML email templates that can serve as a solid foundation and starting point for the design of emails.</li>\n<li><strong><a href=\"https://www.sendwithus.com/resources/templates\">Open Source Email Templates</a></strong>: The sendwithus Open Source Template Project is a collection of free email templates created and managed by the sendwithus team and community.</li>\n<li><strong><a href=\"https://github.com/leemunroe/responsive-html-email-template\">Really Simple Responsive HTML Email Template</a></strong>: Sometimes all you want is a really simple HTML email template. Here it is.</li>\n<li><strong><a href=\"https://www.campaignmonitor.com/dev-resources/guides/mobile/\">Responsive Email Design</a></strong>: In this guide, the author will cover the fundamentals of designing and building a mobile-friendly email and back it all up with some neat tips and techniques.</li>\n<li><strong><a href=\"http://zurb.com/playground/responsive-email-templates\">Responsive Email Templates</a></strong>: Zurb Studios put together this set of super awesome email templates so that you can make your email campaigns responsive.</li>\n<li><strong><a href=\"https://www.campaignmonitor.com/css/\">The Ultimate Guide to CSS</a></strong>: A complete breakdown of the CSS support for the top 10 most popular mobile, web and desktop email clients on the planet.</li>\n</ul>\n</li>\n<li><strong>Keyboard</strong>: Working with keyboard input in a web browser.</li>\n<li>\n<ul>\n<li><strong><a href=\"https://developers.google.com/web/updates/2016/04/keyboardevent-keys-codes\">What's New with KeyboardEvents? Keys and Codes!</a></strong>: Jeff Posnick talks about the code and key event attributes and how to use them in practice.</li>\n</ul>\n</li>\n<li>\n<p><strong>Mobile</strong>: Development of websites optimized for viewing on smartphone and tablet devices.</p>\n<ul>\n<li>\n<p><strong>Emulation</strong>: Tools for emulating features of mobile devices on a desktop.</p>\n<ul>\n<li><strong><a href=\"http://www.responsinator.com/\">Responsinator</a></strong>: Quickly test any website in popular resolutions.</li>\n<li><strong><a href=\"https://developers.google.com/web/tools/chrome-devtools/iterate/device-mode/?hl=en\">Simulate Mobile Devices with Chrome Developer Tools</a></strong>: Use Chrome DevTools' Device Mode to build mobile-first, fully responsive web sites. Learn how to use it to simulate a wide range of devices and their capabilities.</li>\n<li><strong><a href=\"https://github.com/davidcalhoun/touche\">Touché</a></strong>: Touché: bringing touch events to non-touch browsers (how touching!). No dependencies. No code bloat.</li>\n<li><strong><a href=\"http://mwbrooks.github.io/thumbs.js/\">thumbs.js</a></strong>: Adds touch support to your browser.</li>\n</ul>\n</li>\n<li>\n<p><strong>Gestures</strong>: Resources for working with touch mechanics (what your fingers do on the screen) and touch activities (results of specific gestures).</p>\n<ul>\n<li><strong><a href=\"http://hammerjs.github.io/\">Hammer.js</a></strong>: Hammer helps you add support for touch gestures to your page, and remove the 300ms delay from clicks.</li>\n<li><strong><a href=\"https://www.google.com/design/spec/patterns/gestures.html\">Introduction to Gestures</a></strong>: Descriptions of different gestures an their meanings.</li>\n<li><strong><a href=\"https://github.com/jquery/PEP\">Pointer Events Polyfill</a></strong>: PEP polyfills pointer events in all browsers that haven't yet implemented them, providing a unified, responsive input model for all devices and input types.</li>\n<li><strong><a href=\"https://github.com/HotStudio/touchy\">Touchy</a></strong>: Touchy is a jQuery plugin for managing touch events on W3C-compliant browsers, such as Mobile Safari or Android Browser, or any browser that supports the ontouchstart, ontouchmove and ontouchend events.</li>\n<li><strong><a href=\"http://jgestures.codeplex.com/\">jGestures</a></strong>: A jQuery plugin that enables you to add gesture events just like native jQuery events. Includes event substitution for mouse events.</li>\n</ul>\n</li>\n<li>\n<p><strong>Layout</strong>: The way in which the parts of the website are arranged or laid out.</p>\n<ul>\n<li><strong><a href=\"https://github.com/jakiestfu/Snap.js\">Snap.js</a></strong>: A Library for creating beautiful mobile shelfs (side menus) in Javascript.</li>\n<li><strong><a href=\"https://github.com/thebird/swipe\">Swipe</a></strong>: Swipe is the most accurate touch slider.</li>\n<li><strong><a href=\"http://idangero.us/swiper/\">Swiper</a></strong>: Swiper is a free mobile touch slider with hardware accelerated transitions and native behavior. It is intended to be used in mobile websites, mobile web apps, and mobile native/hybrid apps.</li>\n<li><strong><a href=\"https://github.com/filamentgroup/jqm-pagination\">jqm-pagination</a></strong>: A jQuery Mobile plugin for sequential pagination between pages with support for touch, mouse, and keyboard.</li>\n<li><strong><a href=\"https://github.com/max-power/swipeslide\">swipeslide</a></strong>: A Zepto Plugin for iOS like swipe navigation.</li>\n</ul>\n</li>\n<li>\n<p><strong>Scrolling</strong>: Native scrolling of the browsers doesn't always fit for mobile websites. There are resources which solve this problem.</p>\n<ul>\n<li><strong><a href=\"https://github.com/azoff/overscroll\">Overscroll</a></strong>: Overscroll is a jQuery plug-in that mimics the iphone/ipad scrolling experience in a browser.</li>\n<li><strong><a href=\"https://www.filamentgroup.com/lab/overthrow.html\">Overthrow</a></strong>: A framework-independent, overflow: auto polyfill for use in responsive design.</li>\n<li><strong><a href=\"https://github.com/zynga/scroller\">Zynga Scroller</a></strong>: A pure logic component for scrolling/zooming. It is independent of any specific kind of rendering or event system.</li>\n<li><strong><a href=\"http://iscrolljs.com/\">iScroll</a></strong>: iScroll is a high performance, small footprint, dependency free, multi-platform javascript scroller.</li>\n<li><strong><a href=\"http://pep.briangonzalez.org/\">jQuery.pep.js</a></strong>: A lightweight plugin for kinetic-drag on mobile/desktop.</li>\n<li><strong><a href=\"http://jswipekinetic.codeplex.com/\">jSwipeKinetic</a></strong>: A jQuery plugin that enables you to add kinetic scrolling on your touch optimized projects. jSwipeKinetic is build on top of jGestures.</li>\n<li><strong><a href=\"https://github.com/visiongeist/pull-to-refresh-js\">pull-to-refresh.js</a></strong>: This plugin enables a pull-to-refresh functionality in mobile safari for scrollable block elements with native scrolling on iOS.</li>\n</ul>\n</li>\n<li>\n<p><strong>Tap Acceleration</strong>: Every touch-based mobile browser has an artificial ~300ms delay between you tapping a thing on the screen and the browser considering it a \"click\", but there are ways to work around this behavior.</p>\n<ul>\n<li><strong><a href=\"https://developers.google.com/web/updates/2013/12/300ms-tap-delay-gone-away\">300ms Tap Delay, Gone Away</a></strong>: An article by Google describing the 300ms delay and how Chrome 32+ on Anrdoid deals with it.</li>\n<li><strong><a href=\"http://hammerjs.github.io/\">Hammer.js</a></strong>: Hammer helps you add support for touch gestures to your page, and remove the 300ms delay from clicks.</li>\n<li><strong><a href=\"http://cheeaun.github.io/tappable/\">Tappable</a></strong>: Tappable is a simple, standalone library to invoke the tap event for touch-friendly web browsers.</li>\n<li><strong><a href=\"https://github.com/ftlabs/fastclick\">fastclick</a></strong>: FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile browsers.</li>\n</ul>\n</li>\n<li>\n<p><strong>Touch Keyboard</strong>: Almost all modern smartphones provide a touch based keyboard for text input. There are some tactics to influence them and work around their quirks.</p>\n<ul>\n<li><strong><a href=\"https://www.smashingmagazine.com/2013/08/guide-to-designing-touch-keyboards-with-cheat-sheet/\">A Guide To Designing Touch Keyboards</a></strong>: In this article, we will look a bit deeper into the usability issues surrounding touch keyboards, including five design guidelines that will alleviate some of these pains.</li>\n</ul>\n</li>\n<li>\n<p><strong>Working With Sensors</strong>: All mobile devices are equipped with sensors like gyroscope, accelerometers, photometers, magnetometers and so on. Some of them are accessible in a browser through JavaScript.</p>\n<ul>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/device/orientation/\">This End Up: Using Device Orientation</a></strong>: In this article, we'll take a look at device orientation and motion events, and use CSS to rotate an image based on the orientation of the device.</li>\n<li><strong><a href=\"http://lenticular.attasi.com/\">lenticular.js</a></strong>: Tilt-controlled images in the browser.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong>Printers</strong>: Manipulation of printer output through CSS.</li>\n<li>\n<ul>\n<li><strong><a href=\"http://coding.smashingmagazine.com/2013/03/08/tips-tricks-print-style-sheets/\">Tips And Tricks For Print Style Sheets</a></strong>: A comprehensive guide for print optimization including background images and colors, expanding external links, QR codes, CSS3 filters for print quality.</li>\n</ul>\n</li>\n<li>\n<p><strong>Responsive Web Design (RWD)</strong>: RWD responds to the needs of the users and the devices they're using. The layout changes based on the size and capabilities of the device.</p>\n<ul>\n<li>\n<p><strong>Data Tables</strong>: Tables filled with data don't behave well on small screens. Here are some resources to tame them.</p>\n<ul>\n<li><strong><a href=\"https://css-tricks.com/responsive-data-tables/\">Responsive Data Tables</a></strong>: Several ideas by Chris Coyier on how to deal with responsive tables.</li>\n<li><strong><a href=\"http://johnpolacek.github.com/stacktable.js/\">stacktable.js</a></strong>: jQuery plugin for stacking tables on small screens.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://futurefriendlyweb.com/thinking.html\">Future Friendly Thinking</a></strong>: We want to make things that are future friendly. The following ideas have been on our minds recently. Help us explore them further or suggest new ones.</li>\n<li><strong><a href=\"http://www.newnet-soft.com/blog/responsive-multi-column\">How to make a Responsive Newspaper-like layout</a></strong>: The article describes several approaches for creating multi column websites.</li>\n<li>\n<p><strong>Images</strong>: Images pose a set of problems on responsive websites: scaling, performance, retina screens and file size.</p>\n<ul>\n<li><strong><a href=\"http://adaptive-images.com/\">Adaptive Images</a></strong>: Adaptive Images detects your visitor's screen size and automatically creates, caches, and delivers device appropriate re-scaled versions of your web page's embeded HTML images.</li>\n<li><strong><a href=\"https://www.smashingmagazine.com/2013/07/choosing-a-responsive-image-solution/\">Choosing A Responsive Image Solution</a></strong>: This article leads you through the basics, and then arms you with the information you'll need to pick the best responsive image solution for your situation.</li>\n<li><strong><a href=\"https://github.com/estelle/clowncar\">Clown Car Technique</a></strong>: We can use media queries within SVG to serve up the right image. The beauty of the \"Clown Car\" technique is that all the logic remains in the SVG file.</li>\n<li><strong><a href=\"http://www.shutterstock.com/blog/2013/05/how-to-use-responsive-images-to-make-your-site-shine-on-any-platform/\">How to Use Responsive Images...</a></strong>: Engineers at Shutterstock describe different problems and solutions around responsive images.</li>\n<li><strong><a href=\"http://scottjehl.github.io/picturefill/\">Picturefill</a></strong>: A responsive image polyfill for <picture>, srcset, sizes, and more.</li>\n<li><strong><a href=\"https://github.com/tubalmartin/riloadr\">Riloadr</a></strong>: The goal of this library is to deliver optimized, contextual image sizes in responsive layouts that utilize dramatically different image sizes at different resolutions in order to improve page load time.</li>\n<li><strong><a href=\"https://timkadlec.com/2013/06/why-we-need-responsive-images/\">Why We Need Responsive Images</a></strong>: Tim Kadlec talks about page weight and responsive image solutions.</li>\n<li><strong><a href=\"https://github.com/karacas/imgLiquid\">imgLiquid</a></strong>: A jQuery Plugin to resize images to fit in a container.</li>\n<li><strong><a href=\"http://jquerypicture.com/\">jQuery Picture</a></strong>: jQuery Picture is a tiny (2kb) plugin to add support for responsive images to your layouts. It supports both figure elements with some custom data attributes and the new proposed picture format.</li>\n</ul>\n</li>\n<li>\n<p><strong>Monitoring Breakpoints</strong>: Triggering JavaScript events on different breakpoints.</p>\n<ul>\n<li><strong><a href=\"http://xoxco.com/projects/code/breakpoints/\">Breakpoints.js</a></strong>: Define breakpoints for your responsive design, and Breakpoints.js will fire custom events when the browser enters and/or exits that breakpoint.</li>\n<li><strong><a href=\"http://harvesthq.github.io/harvey/\">Harvey</a></strong>: Harvey helps you monitor and manage behavior changes by firing an event whenever your media query is activated.</li>\n<li><strong><a href=\"http://wicky.nillia.ms/enquire.js/\">enquire.js</a></strong>: enquire.js is a lightweight, pure javascript library (with no dependencies) for programmatically responding to media queries.</li>\n</ul>\n</li>\n<li>\n<p><strong>Navigation</strong>: Adapting the website navigation to different screen sizes.</p>\n<ul>\n<li><strong><a href=\"http://bradfrost.com/blog/web/complex-navigation-patterns-for-responsive-design/\">Complex Navigation Patterns</a></strong>: The article describes some emerging patterns for dealing with complex, lengthy and/or multi-level navigations.</li>\n<li><strong><a href=\"http://mobile.smashingmagazine.com/2013/09/11/responsive-navigation-on-complex-websites/\">Responsive Navigation On Complex Websites</a></strong>: To illustrate the techniques involved in implementing responsive navigation on a large website, author refers to two actual clients.</li>\n<li><strong><a href=\"http://bradfrost.com/blog/web/responsive-nav-patterns/\">Responsive Navigation Patterns</a></strong>: The article describes some of the more popular techniques for handling navigation in responsive designs.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://vimeo.com/45915667\">Responsive Design Workflow</a></strong>: In this video, Stephen Hay explores at a content-based approach to design workflow which is grounded in our multiplatform reality, not fixed-width Photoshop comps and overproduced wireframes.</li>\n<li><strong><a href=\"http://kumailht.com/responsive-elements/\">Responsive Elements</a></strong>: Responsive elements makes it possible for any element to adapt and respond to the area they occupy. It's a tiny JavaScript library that you can drop into your projects today.</li>\n<li><strong><a href=\"http://bradfrost.github.io/this-is-responsive/patterns.html\">Responsive Patterns</a></strong>: A collection of patterns and modules for responsive designs.</li>\n<li>\n<p><strong>Text</strong>: Working with text in a context of different viewport sizes.</p>\n<ul>\n<li><strong><a href=\"http://fittextjs.com/\">FitText</a></strong>: FitText makes font-sizes flexible. Use this plugin on your fluid or responsive layout to achieve scalable headlines that fill the width of a parent element.</li>\n<li><strong><a href=\"http://starburst1977.github.io/out-of-words/\">Out Of Words!</a></strong>: The responsive typography framework behind Words App.</li>\n<li><strong><a href=\"http://www.newnet-soft.com/blog/responsivefontsizing\">Responsive Font Sizing</a></strong>: Making your font size respond to your screen size, easy &#x26; maintainable.</li>\n<li><strong><a href=\"http://jbrewer.github.com/Responsive-Measure/\">Responsive Measure</a></strong>: A jQuery plugin for generating a responsive ideal measure.</li>\n<li><strong><a href=\"https://www.smashingmagazine.com/2016/05/fluid-typography/\">Truly Fluid Typography With vh And vw Units</a></strong>: This article describes viewport units and other technics to achieve typography which resizes smoothly with the screen.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/pazguille/viewport\">Viewport Component</a></strong>: Viewport is a component to ease viewport management. You can get the dimensions of the viewport and beyond, which can be quite helpful to perform some checks with JavaScript.</li>\n</ul>\n</li>\n<li>\n<p><strong>Web Accessibility</strong>: Web accessibility means that people with disabilities can perceive, understand, navigate, and interact with the Web, and that they can contribute to the Web.</p>\n<ul>\n<li><strong><a href=\"http://w3c.github.io/aria-in-html/\">Notes on Using ARIA in HTML</a></strong>: This document is a practical guide for developers on how to add accessibility information to HTML elements using the Accessible Rich Internet Applications specification.</li>\n<li><strong><a href=\"http://a11yproject.com/\">The A11Y Project</a></strong>: A community-driven effort to make web accessibility easier.</li>\n</ul>\n</li>\n</ul>\n<h2>Ecosystem</h2>\n<p>Important developers, companies, organizations and news sources.</p>\n<ul>\n<li>\n<p><strong>Communities Around Projects</strong>: Successful open source projects attract many developers who produce plugins, libraries, tutorials and other resources. This section collects such resources.</p>\n<ul>\n<li>\n<p><strong><a href=\"https://angularjs.org/\">Angular</a></strong>: AngularJS is a web application framework trying to address many of the challenges encountered in developing single-page applications.</p>\n<ul>\n<li><strong><a href=\"https://devchat.tv/adv-in-angular\">Adventures in Angular</a></strong>: Adventures in Angular is a weekly podcast dedicated to the Angular JavaScript framework and related technologies, tools, languages, and practices.</li>\n<li><strong><a href=\"https://github.com/blacksonic/angular2-esnext-starter\">Angular 2 ESNext Starter</a></strong>: This repo stands as a starting point for those who try Angular 2 in Javascript. It shows techniques how easy development can be also without Typescript.</li>\n<li><strong><a href=\"https://vsavkin.com/angular-2-template-syntax-5f2ee9f13c6a\">Angular 2 Template Syntax</a></strong>: Victor Savkin writes about Angular 2 Templates including bindings, interpolation, syntax sugar, web component support and much more.</li>\n<li><strong><a href=\"http://developer.telerik.com/featured/angular-2-upgrade-strategies-angular-1-x/\">Angular 2 Upgrade Strategies from Angular 1.x</a></strong>: Some thoughts on general upgrading to Angular 2 and what you/your team can do to prepare.</li>\n<li><strong><a href=\"http://blog.ng-book.com/introduction-to-redux-with-typescript-and-angular-2/\">Building Redux in TypeScript with Angular 2</a></strong>: In this post we're going to discuss the ideas behind Redux. How to build our own mini version of the Redux Store and hook it up to Angular 2.</li>\n<li><strong><a href=\"http://victorsavkin.com/post/110170125256/change-detection-in-angular-2\">Change Detection in Angular 2</a></strong>: In this article Victor Savkin talks in depth about the Angular 2 change detection system.</li>\n<li><strong><a href=\"https://scotch.io/tutorials/how-to-implement-conditional-validation-in-angular-2-model-driven-forms\">How to Implement Conditional Validation in Model-driven Forms</a></strong>: In this article, we will learn about how to handle conditional validation in our model-driven form using the latest forms module.</li>\n<li><strong><a href=\"http://blog.thoughtram.io/angular/2016/05/23/opaque-tokens-in-angular-2.html\">How to Prevent Name Collisions in Angular 2 Providers</a></strong>: Opaque tokens are distinguishable and prevent us from running into naming collisions. Whenever we create a token that is not a type, OpaqueToken should be used.</li>\n<li><strong><a href=\"http://www.ng-newsletter.com/\">Ng-Newsletter</a></strong>: The free, weekly newsletter of the best AngularJS content on the web.</li>\n<li><strong><a href=\"http://www.primefaces.org/primeng/\">PrimeNG</a></strong>: PrimeNG is a collection of rich UI components for AngularJS2. PrimeNG is a sibling of the popular JavaServer Faces Component Suite, PrimeFaces.</li>\n<li><strong><a href=\"https://medium.com/@jecelynyeen/simple-language-translation-in-angular-2-part-1-a14087f50431\">Simple Language Translation</a></strong>: Create a pipe that we can use to translate words in the HTML view and a service that we can use to translate our words in JS / Typescript.</li>\n<li><strong><a href=\"https://scotch.io/tutorials/using-angular-2s-model-driven-forms-with-formgroup-and-formcontrol\">Using Model-Driven Forms with FormGroup and FormControl</a></strong>: In this article, we will learn about building model-driven form with validation using the latest forms module, then we will talk about what are the advantages / disadvantages of using model driven form as compared to template-driven form.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://backbonejs.org/\">Backbone.js</a></strong>: Backbone supplies structure to JavaScript-heavy applications by providing models, collections, views with declarative event handling, and connects it all to your existing application over a RESTful JSON interface.</li>\n<li>\n<p><strong><a href=\"http://getbootstrap.com/\">Bootstrap</a></strong>: Bootstrap is a HTML, CSS, and JS framework for developing responsive, mobile first projects on the web.</p>\n<ul>\n<li><strong><a href=\"http://hackerthemes.com/bootstrap-cheatsheet/\">Bootstrap 4 Cheat Sheet</a></strong>: A quick reference for Bootstrap v4 by Alexander Rechsteiner.</li>\n<li><strong><a href=\"https://medium.com/@jacobp/tree-shaking-bootstrap-95d6301f61a9\">Tree Shaking Bootstrap</a></strong>: Jacob Parker describes how to include only those parts of Bootstrap you are really using on your website by leveraging CSS modules and ES6 modules.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://cycle.js.org/\">Cycle.js</a></strong>: A functional and reactive JavaScript framework that solves the cyclic dependency of Observables which emerge during dialogues (mutual observations) between the Human and the Computer.</p>\n<ul>\n<li><strong><a href=\"https://github.com/whitecolor/cycle-async-driver\">Async Driver</a></strong>: Higher order factory for creating cycle.js async request based drivers. Allows you almost completely eliminate boilerplate code for this kind of drivers.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=Rj8ZTRVka4E\">Cycle.js Was Built to Solve Problems</a></strong>: In this video André Staltz shows how Cycle.js has a practical purpose, meant to solve problems your customers/business may relate to.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=uNZnftSksYg\">Cycle.js and Functional Reactive User Interfaces</a></strong>: In this talk we will discover how Cycle.js is purely reactive and functional, and why it's an interesting alternative to React.</li>\n<li><strong><a href=\"https://glebbahmutov.com/draw-cycle/\">Draw Cycle</a></strong>: Simple Cycle.js program visualized</li>\n<li>\n<p><strong><a href=\"http://cycle.js.org/drivers.html\">Drivers</a></strong>: Drivers are functions that listen to Observable sinks (their input), perform imperative side effects, and may return Observable sources (their output).</p>\n<ul>\n<li><strong><a href=\"https://github.com/Widdershin/cycle-animation-driver\">Animation</a></strong>: A Cycle driver for requestAnimationFrame.</li>\n<li><strong><a href=\"https://github.com/benji6/cycle-audio-graph\">Audio Graph Driver</a></strong>: Audio graph driver for Cycle.js based on virtual-audio-graph.</li>\n<li><strong><a href=\"https://github.com/10clouds/cyclejs-cookie\">Cookie</a></strong>: Cycle.js Cookie Driver, based on cookie_js library.</li>\n<li><strong><a href=\"https://github.com/cyclejs/dom\">DOM</a></strong>: The standard DOM Driver for Cycle.js based on virtual-dom, and other helpers.</li>\n<li><strong><a href=\"https://github.com/secobarbital/cycle-fetch-driver\">Fetch</a></strong>: A Cycle.js Driver for making HTTP requests, using the Fetch API.</li>\n<li><strong><a href=\"https://github.com/r7kamura/cycle-fetcher-driver\">Fetcher</a></strong>: A Cycle.js Driver for making HTTP requests using stackable-fetcher.</li>\n<li><strong><a href=\"https://github.com/dralletje/cycle-firebase\">Firebase</a></strong>: Thin layer around the firebase javascript API that allows you to query and declaratively update your favorite real-time database.</li>\n<li><strong><a href=\"https://github.com/cyclejs/http\">HTTP</a></strong>: A Cycle.js Driver for making HTTP requests, based on superagent.</li>\n<li><strong><a href=\"https://github.com/CyclicMaterials/cycle-hammer-driver\">Hammer.js</a></strong>: The driver incorporates the Hammer.js gesture library.</li>\n<li><strong><a href=\"https://github.com/cyclejs/history\">History</a></strong>: Cycle.js URL Driver based on the rackt/history library.</li>\n<li><strong><a href=\"https://github.com/raquelxmoss/cycle-keys\">Keys</a></strong>: A Cycle.js driver for keyboard events.</li>\n<li><strong><a href=\"https://github.com/whitecolor/cycle-mongoose/\">Mongoose.js</a></strong>: A driver for using Mongoose with Cycle JS. Accepts both, write and read operations.</li>\n<li><strong><a href=\"https://github.com/cyclejs/cycle-notification-driver\">Notification</a></strong>: A Cycle.js Driver for showing and responding to HTML5 Notifications.</li>\n<li><strong><a href=\"https://github.com/TylorS/cycle-router\">Router</a></strong>: A router built from the ground up with Cycle.js in mind. Stands on the shoulders of battle-tested libraries switch-path for route matching and rackt/history for dealing with the History API.</li>\n<li><strong><a href=\"https://github.com/axefrog/cycle-router5\">Router5</a></strong>: A source/sink router driver for Cycle.js, based on router5.</li>\n<li><strong><a href=\"https://github.com/jessaustin/cycle-sse-driver\">Server-Sent Events</a></strong>: Cycle.js driver for Server-Sent Events (SSE), a browser feature also known as EventSource. Server-Sent Events allow the server to continuously update the page with new events, without resorting to hacks like long-polling.</li>\n<li><strong><a href=\"https://github.com/TylorS/cycle-snabbdom\">Snabbdom</a></strong>: Alternative DOM driver utilizing the snabbdom library.</li>\n<li><strong><a href=\"https://github.com/cgeorg/cycle-socket.io\">Socket.IO</a></strong>: A Cycle driver for applications using Socket.IO</li>\n<li><strong><a href=\"https://github.com/cyclejs/storage\">Storage</a></strong>: A Cycle.js Driver for using localStorage and sessionStorage in the browser.</li>\n</ul>\n</li>\n<li>\n<p><strong>Example Projects</strong>: Example applications built with Cycle.js</p>\n<ul>\n<li><strong><a href=\"https://github.com/cyclejs/examples\">Cycle.js Examples</a></strong>: Browse and learn from examples of small Cycle.js apps using Core, DOM Driver, HTML Driver, HTTP Driver, JSONP Driver, and others.</li>\n<li><strong><a href=\"https://github.com/staltz/rxmarbles\">RX Marbles</a></strong>: Interactive diagrams of Rx Observables.</li>\n<li><strong><a href=\"https://github.com/cgeorg/todomvp\">TODO: Minimum Viable Pizza</a></strong>: Minimum Viable Pizza implemented with Cycle.js</li>\n<li><strong><a href=\"https://github.com/Widdershin/tricycle\">Tricycle</a></strong>: A scratchpad for trying out Cycle.js.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=6_ETUyh0tns\">Intro to Functional Reactive Programming with Cycle.js</a></strong>: Nick Johnstone gives an introduction to developing with Cycle.js in this video presentation.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=31URmaeNHSs\">Learning How to Ride: an Introduction to Cycle.js</a></strong>: In this talk, Fernando Macias Pereznieto introduces us to the good, the bad, and the beautiful of using Cycle.js, whether you are a complete beginner or an experienced JS ninja.</li>\n<li>\n<p><strong><a href=\"https://github.com/motorcyclejs/core\">Motorcycle.js</a></strong>: This is a sister project that will continue to evolve and grow alongside Cycle.js for the foreseeable future. The primary focus of this project is to tune it for performance as much as possible.</p>\n<ul>\n<li><strong><a href=\"https://github.com/cujojs/most\">Most</a></strong>: Monadic reactive streams with high performance.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://medium.com/@fkrautwald/plug-and-play-all-your-observable-streams-with-cycle-js-e543fc287872\">Plug and Play All Your Observable Streams With Cycle.js</a></strong>: Frederik Krautwald explains the principles behind Cycle.js, it's inner workings and how to use it to create a simple program with drivers.</li>\n<li><strong><a href=\"https://github.com/Widdershin/tricycle\">Tricycle</a></strong>: A scratchpad for trying out Cycle.js.</li>\n<li><strong><a href=\"http://thenewstack.io/developers-need-know-mvi-model-view-intent/\">What Developers Need to Know about MVI (Model-View-Intent)</a></strong>: The article explains the general MVI pattern and how it relates to React, Reactive Programming and Cycle.js</li>\n</ul>\n</li>\n<li><strong><a href=\"http://dojotoolkit.org/\">Dojo Toolkit</a></strong>: A JavaScript toolkit that saves you time and scales with your development process. Provides everything you need to build a Web app. Language utilities, UI components, and more, all in one place, designed to work together perfectly.</li>\n<li>\n<p><strong><a href=\"http://emberjs.com/\">Ember</a></strong>: Ember.js is an open-source JavaScript web framework, based on the MVC pattern. It allows developers to create scalable single-page web applications.</p>\n<ul>\n<li><strong><a href=\"https://guides.emberjs.com/v2.6.0/object-model/bindings/\">Bindings in Ember</a></strong>: Unlike most other frameworks that include some sort of binding implementation, bindings in Ember.js can be used with any object.</li>\n<li><strong><a href=\"https://github.com/tildeio/router.js\">Router.js (Ember)</a></strong>: Router.js is the routing microlib used by Ember.js.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://foundation.zurb.com/\">Foundation</a></strong>: Foundation provides a responsive grid and HTML and CSS UI components, templates, and code snippets, including typography, forms, buttons, navigation and other interface components, as well as optional JavaScript extensions.</li>\n<li>\n<p><strong><a href=\"http://gulpjs.com/\">Gulp</a></strong>: Gulp is a toolkit that helps you automate painful or time-consuming tasks in your development workflow. It's very fast, platform-agnostic and simple.</p>\n<ul>\n<li>\n<p><strong>Articles &#x26; Tutorials</strong>: Publications about gulp or step by step guides for setting up and using gulp in a project.</p>\n<ul>\n<li>\n<p><strong>Building with Gulp 3 and 4 (Series)</strong>: Great series of articles about single components and gulp as a whole.</p>\n<ul>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/04/23/building-with-gulp-3-and-4-part-1-examples/\">Part 1: Examples</a></strong>: Introduction to gulp and gulpfile.js.</li>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/04/23/building-with-gulp-3-and-4-part-2-gulp-anatomy/\">Part 2: Gulp's anatomy</a></strong>: Orchestrator, Undertaker, Vinyl and Vinyl FS, Gulp Plugins.</li>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/04/28/building-with-gulp-3-and-4-part-3-writing-transformers/\">Part 3: Writing transformers</a></strong>: Using map-stream, though2 and event-stream.</li>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/05/01/building-with-gulp-4-part-4-incremental-builds/\">Part 4: Incremental builds</a></strong>: Building files which changed since last run and caching.</li>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/05/05/building-with-gulp-part-5-caveats/\">Part 5: Caveats</a></strong>: Error management in Gulp 3 and \"MANY:1 disguised as a 1:1\" problem.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://medium.com/@contrahacks/gulp-3828e8126466\">The vision, history, and future of the project (Apr. 2014)</a></strong>: The article talks about Streams, Vinyl, Vinyl Adapters, Orchestrator and Error Management in Gulp 4.</li>\n<li><strong><a href=\"http://scm.io/blog/hack/2014/07/why-gulp-might-not-be-the-answer/\">Why Gulp might not be the Answer</a></strong>: ... there is still a conceptual problem that Gulp has yet to address. Many build steps are not 1:1 (one file in, one file out) but rather n:1 or 1:n.</li>\n</ul>\n</li>\n<li>\n<p><strong>CSS</strong>: Gulp plugins for working with CSS files.</p>\n<ul>\n<li><strong><a href=\"https://github.com/scniro/gulp-clean-css\">gulp-clean-css</a></strong>: gulp plugin to minify CSS, using clean-css.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-cssnano\">gulp-cssnano</a></strong>: Minify CSS with cssnano.</li>\n</ul>\n</li>\n<li>\n<p><strong>Concatenation</strong>: Plugins for file concatenation. For example bundling CSS or JavaScript files.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-concat\">gulp-concat</a></strong>: This plugin will concat files by your operating systems newLine. It will take the base directory from the first file that passes through it.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-group-concat\">gulp-group-concat</a></strong>: Concats groups of files into a smaller number of files</li>\n</ul>\n</li>\n<li>\n<p><strong>Deployment</strong>: Plugins for pushing built files into production.</p>\n<ul>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-tar\">gulp-tar</a></strong>: Create tarball from files.</li>\n<li><strong><a href=\"https://github.com/morris/vinyl-ftp\">vinyl-ftp</a></strong>: Blazing fast vinyl adapter for FTP.</li>\n<li><strong><a href=\"https://github.com/izaakschroeder/vinyl-s3\">vinyl-s3</a></strong>: Use S3 as a source or destination of vinyl files.</li>\n</ul>\n</li>\n<li>\n<p><strong>Ecosystem</strong>: The network of developers and plugins around gulp.</p>\n<ul>\n<li><strong><a href=\"https://github.com/search?q=%40sindresorhus+gulp-\">@sindresorhus plugins</a></strong>: A collection of plugins by Sindre Sorhus.</li>\n<li><strong><a href=\"https://www.npmjs.com/browse/keyword/gulpfriendly\">Gulp Friendly NPM Packages</a></strong>: Normal node packages that work with gulp.</li>\n</ul>\n</li>\n<li>\n<p><strong>Filters</strong>: Plugins for filtering files in a vinyl stream.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-cache\">gulp-cache</a></strong>: A temp file based caching proxy task for gulp.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-cached\">gulp-cached</a></strong>: A simple in-memory file cache for gulp.</li>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-changed\">gulp-changed</a></strong>: Only pass through changed files.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-filter\">gulp-filter</a></strong>: Filter files in a vinyl stream.</li>\n<li><strong><a href=\"https://github.com/tschaub/gulp-newer\">gulp-newer</a></strong>: Pass through newer source files only.</li>\n<li><strong><a href=\"https://github.com/ahaurw01/gulp-remember\">gulp-remember</a></strong>: A plugin for gulp that remembers and recalls files passed through it.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-diff\">vinyl-diff</a></strong>: This library allows you to perform diffs between streams of vinyl.</li>\n</ul>\n</li>\n<li>\n<p><strong>Images</strong>: Plugins for working with images.</p>\n<ul>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-imagemin\">gulp-imagemin</a></strong>: Minify PNG, JPEG, GIF and SVG images.</li>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-webp\">gulp-webp</a></strong>: Convert PNG, JPEG, TIFF images to WebP.</li>\n</ul>\n</li>\n<li>\n<p><strong>JavaScript</strong>: Module loaders, minifiers and other tools for working with JavaScript files.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-pure-cjs\">gulp-pure-cjs</a></strong>: Gulp plugin for Pure CommonJS builder.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-uglify\">gulp-uglify</a></strong>: Minify files with UglifyJS.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/yoloader\">yoloader</a></strong>: A CommonJS module loader implementation. It provides tools to bundle a CommonJS based project and to load such bundles.</li>\n</ul>\n</li>\n<li>\n<p><strong>SourceMaps</strong>: A source map provides a way of mapping code within a compressed file back to it's original position in a source file.</p>\n<ul>\n<li><strong><a href=\"https://github.com/floridoo/gulp-sourcemaps/wiki/Plugins-with-gulp-sourcemaps-support\">Plugins with gulp sourcemaps support</a></strong>: A list of plugins which support gulp-sourcemaps.</li>\n<li><strong><a href=\"https://github.com/floridoo/gulp-sourcemaps\">gulp-sourcemaps</a></strong>: Source map support for Gulp.js</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-sourcemaps-apply\">vinyl-sourcemaps-apply</a></strong>: Apply a source map to a vinyl file, merging it with preexisting source maps.</li>\n</ul>\n</li>\n<li>\n<p><strong>Utility</strong>: Tools and parts for building gulp plugins.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-count\">gulp-count</a></strong>: Count files in a vinyl stream.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-debug\">gulp-debug</a></strong>: Debug vinyl file streams to see what files are run through your gulp pipeline.</li>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-size\">gulp-size</a></strong>: Logs out the total size of files in the stream and optionally the individual file-sizes.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/lazypipe\">lazypipe</a></strong>: Lazypipe allows you to create an immutable, lazily-initialized pipeline. It's designed to be used in an environment where you want to reuse partial pipelines, such as with gulp.</li>\n<li><strong><a href=\"https://github.com/dominictarr/map-stream\">map-stream</a></strong>: Create a through stream from an asyncronous function.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://github.com/gulpjs/vinyl\">Vinyl</a></strong>: Vinyl is a very simple metadata object that describes a file.</p>\n<ul>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-chmod\">gulp-chmod</a></strong>: Change permissions of Vinyl files.</li>\n<li><strong><a href=\"https://github.com/hparra/gulp-rename\">gulp-rename</a></strong>: A plugin to rename files easily.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/mem-fs\">mem-fs</a></strong>: Simple in-memory vinyl file store.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-ast\">vinyl-ast</a></strong>: Parse-once and generate-once AST tool bridge for Gulp plugins.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-buffer\">vinyl-buffer</a></strong>: Creates a transform stream that takes vinyl files as input, and outputs buffered (isStream() === false) vinyl files as output.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-file\">vinyl-file</a></strong>: Create a vinyl file from an actual file.</li>\n<li><strong><a href=\"https://github.com/wearefractal/vinyl-fs\">vinyl-fs</a></strong>: Vinyl adapter for the file system.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-fs-fake\">vinyl-fs-fake</a></strong>: A vinyl adapter that extends vinyl-fs to allow for easy debugging by passing in virtual files instead of globs, and calling a function instead of writing.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-git\">vinyl-git</a></strong>: Vinyl adapter for git.</li>\n<li><strong><a href=\"https://github.com/hughsk/vinyl-map\">vinyl-map</a></strong>: Map vinyl files' contents as strings, so you can easily use existing code without needing yet another gulp plugin!</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-paths\">vinyl-paths</a></strong>: Get the file paths in a vinyl stream.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-source-buffer\">vinyl-source-buffer</a></strong>: Convert a text stream into a vinyl pipeline whose content is a buffer.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-source-stream\">vinyl-source-stream</a></strong>: Use conventional text streams at the start of your gulp or vinyl pipelines, making for nicer interoperability with the existing npm stream.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-to-stream\">vinyl-to-stream</a></strong>: Convert a vinyl stream to a text stream.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-transform\">vinyl-transform</a></strong>: Wraps standard text transform streams so you can write fewer gulp plugins. Fulfills a similar use case to vinyl-map and vinyl-source-stream.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong><a href=\"https://www.meteor.com/\">Meteor</a></strong>: Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages.</li>\n<li>\n<p><strong><a href=\"http://facebook.github.io/react/\">React</a></strong>: React is a JavaScript library for creating user interfaces. Many people choose to think of React as the V in MVC. We built React to solve one problem: building large applications with data that changes over time.</p>\n<ul>\n<li><strong><a href=\"https://www.sitepoint.com/react-alternatives-preact-virtualdom-deku/\">3 Lightweight React Alternatives</a></strong>: Dan Prince explores Preact, VirtualDom &#x26; Deku.</li>\n<li><strong><a href=\"http://jamesknelson.com/state-react-1-stateless-react-app/\">A Stateless React App?</a></strong>: James K Nelson describes how to avoid state in React Components.</li>\n<li><strong><a href=\"https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b\">Block, Element, Modifying Your JavaScript Components</a></strong>: Mark Dalgleish is discussing how to organize React code with BEM and build everything with Webpack.</li>\n<li><strong><a href=\"https://medium.com/@kadmil/css-modules-to-the-rescue-jsx-ded2db874d34\">CSS Modules To The Rescue.jsx</a></strong>: If you use react-like templates/components, use webpack CSS loader to enable CSS Modules and forget about global CSS problems.</li>\n<li><strong><a href=\"http://andrewhfarmer.com/starter-project/\">Find Your Perfect React Starter Project</a></strong>: A simple search engine for React boilerplates with the ability to pick the ingredients.</li>\n<li><strong><a href=\"http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html\">Full-Stack Redux Tutorial</a></strong>: We will go through all the steps of constructing a Node+Redux backend and a React+Redux frontend for a real-world application, using test-first development.</li>\n<li><strong><a href=\"https://medium.com/@floydophone/functional-dom-programming-67d81637d43\">Functional DOM Programming</a></strong>: One of the earliest intros to React and its purpose by Pete Hunt.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=1uRC3hmKQnM\">Functional Principles In React</a></strong>: Jessica Kerr talks about four functional principles: Composition, Declarative Style, Isolation and Flow Of Data, and their usage in React.</li>\n<li><strong><a href=\"https://semaphoreci.com/community/tutorials/getting-started-with-tdd-in-react\">Getting Started with TDD in React</a></strong>: Learn how to test React components using a TDD approach with minimal setup, while learning exactly what to test and how to avoid common pitfalls.</li>\n<li><strong><a href=\"https://daveceddia.com/to-react-from-angular/\">Getting to Grips with React (as an Angular developer)</a></strong>: In a series of posts Dave Ceddia tries to help you apply your hard-won knowledge of \"Angularisms\" to React.</li>\n<li><strong><a href=\"https://medium.com/react-ecosystem/how-to-handle-state-in-react-6f2d3cd73a0c\">How to Handle State in React. The Missing FAQ</a></strong>: Osmel Mora challenges the common misconception that you always need a Flux-like architecture in your React apps.</li>\n<li><strong><a href=\"https://medium.com/@delveeng/how-we-use-the-flux-architecture-in-delve-effc551f8fbc\">How we use the Flux architecture in Delve</a></strong>: Øystein Hallaråker describes how Delve utilizes the Flux application architecture.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=I7IdS-PbEgI\">Immutable Data and React</a></strong>: Lee Byron talks about how persistent immutable data structures work, and techniques for using them in a React applications with Immutable.js.</li>\n<li><strong><a href=\"https://github.com/alexmingoia/jsx-transform\">JSX Transform</a></strong>: JSX transpiler. A standard and configurable implementation of JSX decoupled from React.</li>\n<li><strong><a href=\"https://github.com/facebook/jest\">Jest</a></strong>: A JavaScript unit testing framework, used by Facebook to test services and React applications.</li>\n<li><strong><a href=\"https://satishchilukuri.com/blog/entry/model-view-intent-with-react-and-rxjs\">Model-View-Intent with React and RxJS</a></strong>: Satish Chilukuri shows an example implementation of MVI pattern with React.</li>\n<li><strong><a href=\"https://github.com/team-gryff/react-monocle\">Monocle</a></strong>: A developer tool for generating visual representations of your React app's component hierarchy.</li>\n<li><strong><a href=\"http://staltz.com/nothing-new-in-react-and-flux-except-one-thing.html\">Nothing New in React and Flux Except One Thing</a></strong>: Andre Staltz talks about aspects of React and Flux which make them innovative and compelling.</li>\n<li><strong><a href=\"http://rauchg.com/2015/pure-ui/\">Pure UI</a></strong>: Guillermo Rauch discusses the definition of an application's UI as a pure function of application state.</li>\n<li><strong><a href=\"https://github.com/reactjs/react-basic\">React - Basic Theoretical Concepts</a></strong>: Sebastian Markbage attempts to formally explain his mental model of React. The intention is to describe this in terms of deductive reasoning that lead us to this design.</li>\n<li><strong><a href=\"https://github.com/kriasoft/react-app\">React App</a></strong>: React App is a small library powered by React, Universal Router and History that handles routing, navigation and rendering logic in isomorphic (universal) and single-page applications.</li>\n<li><strong><a href=\"https://medium.com/@dan_abramov/react-components-elements-and-instances-90800811f8ca#.9208ahtfb\">React Components, Elements, and Instances</a></strong>: Dan Abramov explains the Virtual DOM dictionary in React.</li>\n<li><strong><a href=\"http://blog.reverberate.org/2014/02/react-demystified.html\">React Demystified</a></strong>: This article is an attempt to explain the core ideas behind React.js and Virtual DOM.</li>\n<li><strong><a href=\"https://github.com/necolas/react-native-web\">React Native for Web</a></strong>: This project allows components built upon React Native to be run on the Web, and it manages all component styling out-of-the-box.</li>\n<li><strong><a href=\"https://www.reactstarterkit.com/\">React Starter Kit</a></strong>: Isomorphic web app boilerplate including Node.js, Express, GraphQL, React.js, Babel 6, PostCSS, Webpack, Browsersync.</li>\n<li><strong><a href=\"https://github.com/kadirahq/react-storybook\">React Storybook</a></strong>: Isolate your React UI Component development from the main app.</li>\n<li><strong><a href=\"https://github.com/jesstelford/react-workshop\">React Workshop</a></strong>: This is a self-directed workshop. Follow along to the steps at your own pace, and feel free to ask your instructors questions as you go.</li>\n<li><strong><a href=\"https://github.com/krasimir/react-in-patterns\">React in Patterns</a></strong>: List of design patterns/techniques used while developing with React.</li>\n<li><strong><a href=\"https://auth0.com/blog/2015/11/20/face-off-virtual-dom-vs-incremental-dom-vs-glimmer/\">React vs Incremental DOM vs Glimmer</a></strong>: In this post we will explore three technologies to build dynamic DOMs. We will also run benchmarks and find out which one is faster.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=x7cQ3mrcKaY\">React: Rethinking best practices (2013)</a></strong>: A video introduction to React by Pete Hunt.</li>\n<li><strong><a href=\"https://github.com/RamonGebben/react-perf-tool\">ReactPerfTool</a></strong>: ReactPerfTool tries to give you a more visual way of debugging performance of your React application. It does this by using the addons delivered by the React team and community to get measurements and visualize this using graphs.</li>\n<li><strong><a href=\"http://jlongster.com/Removing-User-Interface-Complexity,-or-Why-React-is-Awesome\">Removing User Interface Complexity, or Why React is Awesome</a></strong>: In this post James Long tries not to evangelize React specifically, but to explain why its technique is profound.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=x7cQ3mrcKaY\">Rethinking Best Practices</a></strong>: Pete Hunt talks about React's design decisions challenging established best practices.</li>\n<li><strong><a href=\"https://github.com/LiquidLabsGmbH/retractor\">Retractor</a></strong>: Retractor exposes the internals of a React application for end-to-end testing purposes. This allows you to select DOM nodes based on the name of the React Component that rendered the node as well as its state or properties.</li>\n<li><strong><a href=\"http://staltz.com/some-problems-with-react-redux.html\">Some Problems with React/Redux</a></strong>: André Staltz goes through the pros and cons of React + Redux.</li>\n<li><strong><a href=\"http://developer.telerik.com/featured/taming-react-setup/\">Taming the React Setup</a></strong>: Cody Lindley lays out seven React setups in this article and explains the relation of React to BYOA (Bring Your Own Architecture) approach.</li>\n<li><strong><a href=\"http://silvenon.com/testing-react-and-redux/\">Testing a React &#x26; Redux Codebase</a></strong>: This series aims to be a very comprehensive guide through testing a React and Redux codebase, where you can really cover a lot with just unit tests because the code is mostly universal.</li>\n<li><strong><a href=\"http://krasimirtsonev.com/blog/article/The-bare-minimum-to-work-with-React\">The Bare Minimum to Work with React</a></strong>: Krasimir Tsonev describes how to start working with React after installing only 7 dependencies and learning only three commands.</li>\n<li><strong><a href=\"https://medium.com/@denisraslov/the-redux-ecosystem-539c630ec521\">The Redux Ecosystem</a></strong>: Let's take a look at most of the features that you'll have to deal with when the time comes, — and where React &#x26; Redux themselves can't help you.</li>\n<li><strong><a href=\"http://www.robinwieruch.de/the-soundcloud-client-in-react-redux/\">The SoundCloud Client in React + Redux</a></strong>: After finishing this step by step tutorial you will be able to author your own React + Redux project with Webpack and Babel.</li>\n<li><strong><a href=\"https://www.fullstackreact.com/articles/react-tutorial-cloning-yelp/\">Tutorial: Cloning Yelp</a></strong>: This post will guide you through building a full React app, even with little to no experience in the framework. We are going to build a Yelp clone in React.</li>\n<li><strong><a href=\"https://medium.com/@firasd/interface-from-data-using-react-to-sync-updates-and-offline-activity-across-devices-f672b213701c\">Using React to Sync Updates and Offline Activity</a></strong>: Firas Durri describes how React based architectures make syncing state across devices much easier.</li>\n<li><strong><a href=\"http://thenewstack.io/developers-need-know-mvi-model-view-intent/\">What Developers Need to Know about MVI (Model-View-Intent)</a></strong>: The article explains the general MVI pattern and how it relates to React, Reactive Programming and Cycle.js</li>\n<li><strong><a href=\"https://github.com/garbles/why-did-you-update\">Why Did You Update?</a></strong>: A function that monkey patches React and notifies you in the console when potentially unnecessary re-renders occur.</li>\n<li><strong><a href=\"http://facebook.github.io/react/blog/2013/06/05/why-react.html\">Why did we build React?</a></strong>: Pete Hunt tries to explain why Facebook devs built React in the first place.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://yeoman.io/\">Yeoman</a></strong>: Yeoman helps you to kickstart new projects, prescribing best practices and tools to help you stay productive. It provides a generator ecosystem.</li>\n<li>\n<p><strong><a href=\"https://jquery.com/\">jQuery</a></strong>: jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler.</p>\n<ul>\n<li>\n<p><strong>Alternatives</strong>: Other libraries which intend to replace jQuery in one way or another.</p>\n<ul>\n<li><strong><a href=\"https://github.com/kenwheeler/cash\">Cash</a></strong>: Cash is a small library for modern browsers that provides jQuery style syntax for manipulating the DOM.</li>\n<li><strong><a href=\"https://github.com/kylebarrow/chibi\">Chibi</a></strong>: Chibi focuses on just the essentials, melted down and mixed with optimisation rainbows to create a really light micro-library that allows you to do awesome things.</li>\n<li><strong><a href=\"https://github.com/mattdesl/dom-css\">DOM CSS</a></strong>: Small module for fast and reliable DOM styling.</li>\n<li><strong><a href=\"http://minifiedjs.com/\">Minified.js</a></strong>: Minified.js is a client-side JavaScript library that's both powerful and small. It offers jQuery-like features and utility functions with a single, consistent API.</li>\n<li><strong><a href=\"https://plainjs.com/javascript/\">Plain.js</a></strong>: Vanilla JS utilities for writing powerful web applications without jQuery.</li>\n<li><strong><a href=\"http://zeptojs.com/\">Zepto.js</a></strong>: Zepto is a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API.</li>\n</ul>\n</li>\n<li>\n<p><strong>Authoring jQuery Plugins</strong>: jQuery is an utility library and a plugin framework. This section collects resources about creating such plugins.</p>\n<ul>\n<li><strong><a href=\"http://learn.jquery.com/plugins/advanced-plugin-concepts/\">Advanced Plugin Concepts</a></strong>: A collection of best practices for jQuery plugin authoring.</li>\n<li><strong><a href=\"http://learn.jquery.com/plugins/basic-plugin-creation/\">How to Create a Basic Plugin</a></strong>: The article describes basic plugin creation and provides a simple boilerplate.</li>\n<li><strong><a href=\"https://remysharp.com/2010/06/03/signs-of-a-poorly-written-jquery-plugin\">Signs of a poorly written jQuery plugin</a></strong>: Collection of jQuery plugin antipatterns.</li>\n<li><strong><a href=\"https://websanova.com/blog/jquery/the-ultimate-guide-to-writing-jquery-plugins\">The Ultimate Guide to Writing jQuery Plugins</a></strong>: A comprehensive guide on how to develop jQuery plugins including a simple boilerplate.</li>\n<li><strong><a href=\"http://learn.jquery.com/plugins/stateful-plugins-with-widget-factory/\">Writing Stateful Plugins with the jQuery UI Widget Factory</a></strong>: The article demonstrates the capabilities of the Widget Factory by building a simple progress bar plugin.</li>\n<li><strong><a href=\"https://github.com/jquery-boilerplate/jquery-boilerplate\">jQuery Boilerplate</a></strong>: This project won't seek to provide a perfect solution to every possible pattern, but will attempt to cover a simple template for beginners and above.</li>\n<li><strong><a href=\"https://github.com/jquery-boilerplate/jquery-patterns\">jQuery Plugin Patterns</a></strong>: This project won't seek to provide implementations for every possible pattern, but will attempt to cover popular patterns developers often use in the wild.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/yuanyan/pragmatic-jquery\">Pragmatic jQuery Style</a></strong>: Coding guidelines for working with jQuery.</li>\n<li><strong><a href=\"http://jqfundamentals.com/\">jQuery Fundamentals</a></strong>: A guide to the basics of jQuery including a built-in editor for examples.</li>\n<li>\n<p><strong><a href=\"http://jqueryui.com/\">jQuery UI</a></strong>: jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library.</p>\n<ul>\n<li><strong><a href=\"http://learn.jquery.com/jquery-ui/\">Learning jQuery UI</a></strong>: Series of articles about jQuery UI on learn.jquery.com.</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong>News</strong>: Websites &#x26; newsletters which provide daily and weekly news related to frontend web development. + <strong><a href=\"http://adripofjavascript.com/\">A Drip of JavaScript</a></strong>: One quick JavaScript tip, delivered to your inbox every other week. + <strong><a href=\"http://css-weekly.com/\">CSS Weekly</a></strong>: Weekly E-Mail roundup of CSS articles, tutorials, experiments and tools</li>\n<li>curated by Zoran Jambor. + <strong><a href=\"https://deterministic.curated.co/\">Deterministic</a></strong>: A weekly digest of interesting news and articles covering functional programming for the web, especially on the front end. + <strong><a href=\"http://frontenddevweekly.com/\">Frontend Dev Weekly</a></strong>: Front-end developer news, tools and inspiration hand-picked each week. + <strong><a href=\"http://html5bookmarks.com/\">HTML5 Bookmarks</a></strong>: Daily bookmarks of HTML5 related resources. + <strong><a href=\"http://html5weekly.com/\">HTML5 Weekly</a></strong>: A once-weekly HTML5 and Web Platform technology roundup. CSS 3, Canvas, WebSockets, WebGL, Native Client, and more. + <strong><a href=\"http://javascriptweekly.com/\">JavaScript Weekly</a></strong>: A free, once-weekly e-mail round-up of JavaScript news and articles. + <strong><a href=\"http://www.ng-newsletter.com/\">Ng-Newsletter</a></strong>: The free, weekly newsletter of the best AngularJS content on the web. + <strong><a href=\"http://responsivedesignweekly.com/\">Responsive Design Newsletter</a></strong>: A free, once-weekly round-up of responsive design articles, tools, tips, tutorials and inspirational links. + <strong><a href=\"https://wdrl.info/\">WDRL</a></strong>: A handcrafted, carefully selected list of web development related resources. Curated and published usually every week. + <strong><a href=\"https://web-design-weekly.com/\">Web Design Weekly</a></strong>: A once a week email with no spam, no rambling. Just pure awesome links to the best news and articles to hit the interweb during the week. + <strong><a href=\"http://webplatformdaily.org/\">Web Platform Daily</a></strong>: Daily digest of web development news. + <strong><a href=\"http://webtoolsweekly.com/\">Web Tools Weekly</a></strong>: Web Tools Weekly is a front-end development and web design newsletter with a focus on tools. + <strong><a href=\"http://www.echojs.com/\">echo.js</a></strong>: Echo JS is a community-driven news site entirely focused on JavaScript development, HTML5, and front-end news.</li>\n<li>\n<p><strong>Notable Community Members</strong>: Important engineers, evangelists, architects and other celebrities.</p>\n<ul>\n<li>\n<p><strong><a href=\"https://addyosmani.com/\">Addy Osmani</a></strong>: Engineer at Google working on open web tooling.</p>\n<ul>\n<li><strong><a href=\"https://addyosmani.com/resources/essentialjsdesignpatterns/book/\">Learning JavaScript Design Patterns</a></strong>: In this free book Addy Osmani explores applying both classical and modern design patterns to the JavaScript programming language.</li>\n<li><strong><a href=\"https://addyosmani.com/largescalejavascript/\">Patterns For Large-Scale JavaScript Application Architecture</a></strong>: An extensive overview by Addy Osmani of existing architectural solutions in the frontend development field.</li>\n<li><strong><a href=\"https://addyosmani.com/writing-modular-js/\">Writing Modular JavaScript With AMD, CommonJS &#x26; ES Harmony</a></strong>: In this article Addy Osmani reviewes several of the options available for writing modular JavaScript using modern module formats AMD, CommonJS and ES6 Modules.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://alexsexton.com/\">Alex Sexton</a></strong>: Alex Sexton is an engineer at Stripe. He is on the Modernizr core team, the jQuery Board of Directors, as well as the Dojo Foundation Board.</p>\n<ul>\n<li><strong><a href=\"https://modernizr.com/\">Modernizr</a></strong>: It's a collection of superfast tests - or \"detects\" as we like to call them - which run as your web page loads, then you can use the results to tailor the experience to the user.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://staltz.com/\">André Staltz</a></strong>: Founder of the cycle.js framework and important contributor to ReactiveX.</p>\n<ul>\n<li><strong><a href=\"https://www.youtube.com/watch?v=uNZnftSksYg\">Cycle.js and Functional Reactive User Interfaces</a></strong>: In this talk we will discover how Cycle.js is purely reactive and functional, and why it's an interesting alternative to React.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=v68ppDlvHqs\">Dynamics of Change: why Reactivity Matters</a></strong>: In this talk we will see when passive or reactive strategy is advantageous, and how the reactive strategy is a sensible default.</li>\n<li><strong><a href=\"http://cycle.js.org/model-view-intent.html\">MVI in Cycle.js Docs</a></strong>: André Staltz describes how to refactor an application into MVI pattern.</li>\n<li><strong><a href=\"http://staltz.com/nothing-new-in-react-and-flux-except-one-thing.html\">Nothing New in React and Flux Except One Thing</a></strong>: Andre Staltz talks about aspects of React and Flux which make them innovative and compelling.</li>\n<li><strong><a href=\"http://rxmarbles.com/\">RxMarbles</a></strong>: A webapp for experimenting with diagrams of Rx Observables, for learning purposes.</li>\n<li><strong><a href=\"http://staltz.com/some-problems-with-react-redux.html\">Some Problems with React/Redux</a></strong>: André Staltz goes through the pros and cons of React + Redux.</li>\n<li><strong><a href=\"https://gist.github.com/staltz/868e7e9bc2a7b8c1f754\">The Introduction to Reactive Programming</a></strong>: André Staltz provides a complete introduction to the Reactive Programming and RxJS.</li>\n<li><strong><a href=\"https://vimeo.com/168652278\">Unidirectional Data Flow Architectures (Talk)</a></strong>: Andre Staltz compares modern architecture patterns including Flux, Redux, Model-View-Intent, Elm Arch and BEST.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=1zj7M1LnJV4\">What if the User was a Function?</a></strong>: In this video André Staltz talks about the input/output cycle between humans and computers and how to take advantage of this model by using FRP and event streams.</li>\n<li><strong><a href=\"http://staltz.com/why-we-built-xstream.html\">Why We Built Xstream</a></strong>: The authors needed a stream library tailored for Cycle.js. It needs to be \"hot\" only, small in kB size and it should have only a few and intuitive operators.</li>\n<li>\n<p><strong><a href=\"https://github.com/staltz/xstream\">Xstream</a></strong>: An extremely intuitive, small, and fast functional reactive stream library for JavaScript.</p>\n<ul>\n<li><strong><a href=\"http://staltz.com/why-we-built-xstream.html\">Why We Built Xstream</a></strong>: The authors needed a stream library tailored for Cycle.js. It needs to be \"hot\" only, small in kB size and it should have only a few and intuitive operators.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://bradfrost.com/\">Brad Frost</a></strong>: Web designer, speaker, writer, consultant, musician, and artist in beautiful Pittsburgh.</p>\n<ul>\n<li>\n<p><strong><a href=\"http://atomicdesign.bradfrost.com/table-of-contents/\">Atomic Design</a></strong>: Atomic Design discusses the importance of crafting robust design systems, and introduces a methodology for which to create smart, deliberate interface systems.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/@AshConnolly/a-more-seamless-workflow-style-guides-for-better-design-and-development-639fc55be28c\">A More Seamless Workflow — Style Guides for Better Design and Development</a></strong>: Ash Connolly explains what styles guides are and which benefits they bring to designers and developers.</li>\n<li><strong><a href=\"http://atomicdocs.io/\">Atomic Docs</a></strong>: Atomic Docs is a styleguide generator and component manager. Atomic Docs is built in PHP. Inspired by Brad Frost's Atomic Design principles.</li>\n<li><strong><a href=\"http://steelydylan.github.io/atomic-lab/\">Atomic Lab</a></strong>: Template sharing and coding environment based on atomic design.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://bradfrost.com/blog/web/responsive-nav-patterns/\">Responsive Navigation Patterns</a></strong>: The article describes some of the more popular techniques for handling navigation in responsive designs.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://github.com/DrBoolean\">Brian Lonsdorf</a></strong>: Lead UXE Engineer at Salesforce, JavaScript developer and speaker known for his work in functional programming community.</p>\n<ul>\n<li><strong><a href=\"https://www.youtube.com/watch?v=JZSoPZUoR58\">A Million Ways to Fold in JS</a></strong>: Brian Lonsdorf provides many functional alternatives to loops in this video.</li>\n<li><strong><a href=\"https://medium.com/@drboolean/debugging-functional-7deb4688a08c\">Debugging Functional</a></strong>: This post will demonstrate a simple solution that can go a long way to enhance the debugging experience in functional JavaScript applications.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=WH5BrkzGgQY&#x26;list=PLK_hdtAJ4KqUWp5LJdLOgkD_8qKW0iAHi&#x26;index=1\">Free Monads Video Series</a></strong>: A video series on free monads by Brian Lonsdorf explaining Coyoneda, Free Monad and Interpretors.</li>\n<li><strong><a href=\"https://github.com/DrBoolean/freeky\">Freeky</a></strong>: Collection of free monads by Brian Lonsdorf.</li>\n<li><strong><a href=\"http://functionaltalks.org/2013/05/27/brian-lonsdorf-hey-underscore-youre-doing-it-wrong/\">Hey Underscore, You're Doing It Wrong!</a></strong>: In this talk Brian Lonsdorf gently takes a shot at underscore.js for not thinking about currying and partial function application in its library design.</li>\n<li><strong><a href=\"https://javascriptair.com/episodes/2015-12-30/\">JSAir - Functional and Immutable Design Patterns in JavaScript</a></strong>: An episode of JavaScript Air about \"the how and why of functional programming and immutable design patterns in JavaScript\" with Dab Abramov and Brian Lonsdorf as guests.</li>\n<li><strong><a href=\"https://vimeo.com/104807358\">Lenses Quick n' Dirty</a></strong>: A video by Brian Lonsdorf that introduces lenses.</li>\n<li><strong><a href=\"https://github.com/DrBoolean/lenses\">Lenses.js</a></strong>: Composable kmett style lenses.</li>\n<li><strong><a href=\"https://vimeo.com/105300347\">Monad a Day: Reader</a></strong>: Short video by Brian Lonsdorf about the Reader Monad.</li>\n<li><strong><a href=\"https://vimeo.com/105300347\">Monad a day 1: Reader</a></strong>: A video by Brian Lonsdorf explaining the Reader Monad.</li>\n<li><strong><a href=\"https://vimeo.com/106008027\">Monad a day 2: Future</a></strong>: Brian Lonsdorf explains the Future monad in this video.</li>\n<li><strong><a href=\"https://vimeo.com/109984691\">Monad a day 3: State</a></strong>: Brian Lonsdorf explains the State monad in this video.</li>\n<li><strong><a href=\"https://drboolean.gitbooks.io/mostly-adequate-guide/content/\">Mostly Adequate Guide to Functional Programming</a></strong>: A book by Brian Lonsdorf that introduces algebraic functional programming in JavaScript.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://twitter.com/cmaxw\">Charles Max Wood</a></strong>: Podcaster at Devchat.tv, organizer of remote confs such as Angular RC, React RC, Rails RC. Software consultant and developer.</p>\n<ul>\n<li><strong><a href=\"https://devchat.tv/adv-in-angular\">Adventures in Angular</a></strong>: Adventures in Angular is a weekly podcast dedicated to the Angular JavaScript framework and related technologies, tools, languages, and practices.</li>\n<li><strong><a href=\"https://devchat.tv/js-jabber/\">JavaScript Jabber</a></strong>: A weekly podcast about JavaScript, including Node.js, Front-End Technologies, Careers, Teams and more.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://chriscoyier.net/\">Chris Coyier</a></strong>: Designer at Codepen. Writer at CSS-Tricks. Podcaster at ShopTalk.</p>\n<ul>\n<li><strong><a href=\"https://css-tricks.com/responsive-data-tables/\">Responsive Data Tables</a></strong>: Several ideas by Chris Coyier on how to deal with responsive tables.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://www.crockford.com/\">Douglas Crockford</a></strong>: Computer programmer who is best known for his ongoing involvement in the development of the JavaScript language, for having popularized the data format JSON, and for developing JSLint and JSMin.</p>\n<ul>\n<li><strong><a href=\"https://www.youtube.com/watch?v=dkZFtimgAcM\">Monads and Gonads</a></strong>: In this video from YUIConf 2012, Douglas Crockford attempts to break the long-standing Monad tutorial curse by explaining the concept and applications of monads in a way that is actually understandable to the audience.</li>\n<li><strong><a href=\"http://javascript.crockford.com/prototypal.html\">Prototypal Inheritance in JavaScript</a></strong>: An article by Douglas Crockford introducing the Object.create() method and describing the rational behind it.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://jlongster.com/\">James Long</a></strong>: Works on Firefox Developer Tools at Mozilla.</p>\n<ul>\n<li><strong><a href=\"http://jlongster.com/A-Study-on-Solving-Callbacks-with-JavaScript-Generators\">A Study on Solving Callbacks with JavaScript Generators</a></strong>: This article describes how Generators help fight callback hell.</li>\n<li><strong><a href=\"http://jlongster.com/Removing-User-Interface-Complexity,-or-Why-React-is-Awesome\">Removing User Interface Complexity, or Why React is Awesome</a></strong>: In this post James Long tries not to evangelize React specifically, but to explain why its technique is profound.</li>\n<li>\n<p><strong><a href=\"https://github.com/jlongster/transducers.js\">Transducers.js Library by James Long</a></strong>: A small library for generalized transformation of data (inspired by Clojure's transducers)</p>\n<ul>\n<li><strong><a href=\"http://jlongster.com/Transducers.js-Round-2-with-Benchmarks\">Transducers.js Round 2 with Benchmarks</a></strong>: Refactored version of Transducers.js, some benchmarks, Laziness, the transformer protocoll.</li>\n<li><strong><a href=\"http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data\">Transducers.js: A JavaScript Library for Transformation of Data</a></strong>: A post announcing the transducers.js library with some explanation.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://jlongster.com/Transducers.js-Round-2-with-Benchmarks\">Transducers.js Round 2 with Benchmarks</a></strong>: Refactored version of Transducers.js, some benchmarks, Laziness, the transformer protocoll.</li>\n<li><strong><a href=\"http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data\">Transducers.js: A JavaScript Library for Transformation of Data</a></strong>: A post announcing the transducers.js library with some explanation.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://snook.ca/about/\">Jonathan Snook</a></strong>: A web designer and developer who is currently UX Architect at Xero. Former lead frontend developer at Shopify.</p>\n<ul>\n<li><strong><a href=\"https://smacss.com/book/\">SMACSS</a></strong>: SMACSS (pronounced \"smacks\") is a way to examine your design process and as a way to fit those rigid frameworks into a flexible thought process. It is an attempt to document a consistent approach to site development when using CSS.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://mixu.net/\">Mikito Takada (mixu)</a></strong>: Software engineer at Stripe.</p>\n<ul>\n<li><strong><a href=\"http://book.mixu.net/css/\">Learn CSS Layout the pedantic way</a></strong>: Walks you through every major concept in CSS layout, without trying to simplify away the underlying mechanisms described in the CSS 2.1 and flexbox specs.</li>\n<li><strong><a href=\"http://singlepageappbook.com/\">Single Page Apps in Depth</a></strong>: This free book is what I wanted when I started working with single page apps. It's not an API reference on a particular framework, rather, the focus is on discussing patterns, implementation choices and decent practices.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://www.nczonline.net/about/\">Nicholas C. Zakas</a></strong>: Former principal front-end engineer at Yahoo! and YUI developer. Leads a team of frontend engineers at Box now.</p>\n<ul>\n<li><strong><a href=\"https://www.youtube.com/watch?v=mKouqShWI4o\">Box Tech Talk: Scalable JavaScript Application Architecture</a></strong>: A video by Nicholas Zakas (2012) about JavaScript Architecture.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=vXjVFPosQHw\">Scalable JavaScript Application Architecture</a></strong>: In this video (2011) Nicholas Zakas discusses frontend architecture for complex, modular web applications with significant JavaScript elements.</li>\n<li><strong><a href=\"http://t3js.org/\">T3</a></strong>: T3 is a minimalist JavaScript framework sponsored by Box Inc. that provides core structure to code.</li>\n<li><strong><a href=\"https://leanpub.com/understandinges6/read\">Understanding ECMAScript 6</a></strong>: Free (as in pay what you want) E-Book by Nicholas C. Zakas describing the new features in EcmaScript 6.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://nicolasgallagher.com/\">Nicolas Gallagher</a></strong>: Frontend Engineer at Twitter.</p>\n<ul>\n<li><strong><a href=\"http://necolas.github.io/normalize.css/\">Normalize.css</a></strong>: A modern, HTML5-ready alternative to CSS resets.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://github.com/petehunt\">Pete Hunt</a></strong>: Co-founder &#x26; CEO @HelloSmyte. Ex-FB and Instagram. Worked on React.js.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/@floydophone/functional-dom-programming-67d81637d43\">Functional DOM Programming</a></strong>: One of the earliest intros to React and its purpose by Pete Hunt.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=x7cQ3mrcKaY\">React: Rethinking best practices (2013)</a></strong>: A video introduction to React by Pete Hunt.</li>\n<li><strong><a href=\"http://facebook.github.io/react/blog/2013/06/05/why-react.html\">Why did we build React?</a></strong>: Pete Hunt tries to explain why Facebook devs built React in the first place.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong>Organizations</strong>: Commercial companies and nonprofit organizations around web development. + <strong><a href=\"http://airbnb.io/projects/\">Airbnb</a></strong>: Airbnb is a website for people to list, find, and rent lodging. + <strong><a href=\"http://airbnb.io/projects/css/\">Airbnb CSS + Sass Style Guide</a></strong>: This style guide covers Terminology, Rule Declaration, Selectors, Properties, Formatting, Comments, OOCSS and BEM, ID Selectors, JavaScript hooks</li>\n<li>Sass, Syntax, Ordering, Mixins, Placeholders, Nested selectors. + <strong><a href=\"http://airbnb.io/projects/javascript/\">Airbnb JavaScript Style Guide</a></strong>: A style guide for writing JavaScript code at Airbnb. + <strong><a href=\"http://airbnb.io/projects/enzyme/\">Enzyme</a></strong>: Enzyme is a JavaScript Testing utility for React that makes it easier to assert, manipulate, and traverse your React Components' output. + <strong><a href=\"http://airbnb.io/polyglot.js/\">Polyglot</a></strong>: Polyglot.js is a I18n helper library written in JavaScript, made to work both in the browser and in CommonJS environments (Node). It provides a simple solution for interpolation and pluralization. + <strong><a href=\"https://medium.com/airbnb-engineering/turbocharged-javascript-refactoring-with-codemods-b0cae8b326b9\">Turbocharged JavaScript Refactoring with Codemods</a></strong>: Joe Lencioni describes how they used codemods to transform a large JavaScript code base at AirBnB + <strong><a href=\"http://opensource.box.com/\">Box Inc.</a></strong>: Box is an online file sharing and content management service for businesses based in Redwood City, California. + <strong><a href=\"https://github.com/box/leche\">Leche</a></strong>: A JavaScript testing utility designed to work with Mocha and Sinon. This is intended for use both by Node.js and in browsers, so any changes must work in both locations. + <strong><a href=\"https://www.nczonline.net/about/\">Nicholas C. Zakas</a></strong>: Former principal front-end engineer at Yahoo! and YUI developer. Leads a team of frontend engineers at Box now. + <strong><a href=\"https://www.youtube.com/watch?v=mKouqShWI4o\">Box Tech Talk: Scalable JavaScript Application Architecture</a></strong>: A video by Nicholas Zakas (2012) about JavaScript Architecture. + <strong><a href=\"https://www.youtube.com/watch?v=vXjVFPosQHw\">Scalable JavaScript Application Architecture</a></strong>: In this video (2011) Nicholas Zakas discusses frontend architecture for complex, modular web applications with significant JavaScript elements. + <strong><a href=\"http://t3js.org/\">T3</a></strong>: T3 is a minimalist JavaScript framework sponsored by Box Inc. that provides core structure to code. + <strong><a href=\"https://leanpub.com/understandinges6/read\">Understanding ECMAScript 6</a></strong>: Free (as in pay what you want) E-Book by Nicholas C. Zakas describing the new features in EcmaScript 6. + <strong><a href=\"https://github.com/box/shalam\">Shalam</a></strong>: A friendly tool for CSS spriting. Shalam allows you to add Retina-friendly, high-quality image sprites to your website without modifying any markup. + <strong><a href=\"http://t3js.org/\">T3</a></strong>: T3 is a minimalist JavaScript framework sponsored by Box Inc. that provides core structure to code. + <strong><a href=\"https://github.com/box/stalker\">stalker</a></strong>: A jQuery plugin allowing elements to follow the user as they scroll a page. + <strong><a href=\"https://code.facebook.com/projects/\">Facebook</a></strong>: Facebook is a corporation and online social networking service headquartered in Menlo Park, California, in the United States. + <strong><a href=\"https://github.com/facebook/immutable-js/\">Immutable.js</a></strong>: Immutable persistent data collections for Javascript which increase efficiency and simplicity. + <strong><a href=\"http://facebook.github.io/react/\">React</a></strong>: React is a JavaScript library for creating user interfaces. Many people choose to think of React as the V in MVC. We built React to solve one problem: building large applications with data that changes over time. + <strong><a href=\"https://www.sitepoint.com/react-alternatives-preact-virtualdom-deku/\">3 Lightweight React Alternatives</a></strong>: Dan Prince explores Preact, VirtualDom &#x26; Deku. + <strong><a href=\"http://jamesknelson.com/state-react-1-stateless-react-app/\">A Stateless React App?</a></strong>: James K Nelson describes how to avoid state in React Components. + <strong><a href=\"https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b\">Block, Element, Modifying Your JavaScript Components</a></strong>: Mark Dalgleish is discussing how to organize React code with BEM and build everything with Webpack. + <strong><a href=\"https://medium.com/@kadmil/css-modules-to-the-rescue-jsx-ded2db874d34\">CSS Modules To The Rescue.jsx</a></strong>: If you use react-like templates/components, use webpack CSS loader to enable CSS Modules and forget about global CSS problems. + <strong><a href=\"http://andrewhfarmer.com/starter-project/\">Find Your Perfect React Starter Project</a></strong>: A simple search engine for React boilerplates with the ability to pick the ingredients. + <strong><a href=\"http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html\">Full-Stack Redux Tutorial</a></strong>: We will go through all the steps of constructing a Node+Redux backend and a React+Redux frontend for a real-world application, using test-first development. + <strong><a href=\"https://medium.com/@floydophone/functional-dom-programming-67d81637d43\">Functional DOM Programming</a></strong>: One of the earliest intros to React and its purpose by Pete Hunt. + <strong><a href=\"https://www.youtube.com/watch?v=1uRC3hmKQnM\">Functional Principles In React</a></strong>: Jessica Kerr talks about four functional principles: Composition, Declarative Style, Isolation and Flow Of Data, and their usage in React. + <strong><a href=\"https://semaphoreci.com/community/tutorials/getting-started-with-tdd-in-react\">Getting Started with TDD in React</a></strong>: Learn how to test React components using a TDD approach with minimal setup, while learning exactly what to test and how to avoid common pitfalls. + <strong><a href=\"https://daveceddia.com/to-react-from-angular/\">Getting to Grips with React (as an Angular developer)</a></strong>: In a series of posts Dave Ceddia tries to help you apply your hard-won knowledge of \"Angularisms\" to React. + <strong><a href=\"https://medium.com/react-ecosystem/how-to-handle-state-in-react-6f2d3cd73a0c\">How to Handle State in React. The Missing FAQ</a></strong>: Osmel Mora challenges the common misconception that you always need a Flux-like architecture in your React apps. + <strong><a href=\"https://medium.com/@delveeng/how-we-use-the-flux-architecture-in-delve-effc551f8fbc\">How we use the Flux architecture in Delve</a></strong>: Øystein Hallaråker describes how Delve utilizes the Flux application architecture. + <strong><a href=\"https://www.youtube.com/watch?v=I7IdS-PbEgI\">Immutable Data and React</a></strong>: Lee Byron talks about how persistent immutable data structures work, and techniques for using them in a React applications with Immutable.js. + <strong><a href=\"https://github.com/alexmingoia/jsx-transform\">JSX Transform</a></strong>: JSX transpiler. A standard and configurable implementation of JSX decoupled from React. + <strong><a href=\"https://github.com/facebook/jest\">Jest</a></strong>: A JavaScript unit testing framework, used by Facebook to test services and React applications. + <strong><a href=\"https://satishchilukuri.com/blog/entry/model-view-intent-with-react-and-rxjs\">Model-View-Intent with React and RxJS</a></strong>: Satish Chilukuri shows an example implementation of MVI pattern with React. + <strong><a href=\"https://github.com/team-gryff/react-monocle\">Monocle</a></strong>: A developer tool for generating visual representations of your React app's component hierarchy. + <strong><a href=\"http://staltz.com/nothing-new-in-react-and-flux-except-one-thing.html\">Nothing New in React and Flux Except One Thing</a></strong>: Andre Staltz talks about aspects of React and Flux which make them innovative and compelling. + <strong><a href=\"http://rauchg.com/2015/pure-ui/\">Pure UI</a></strong>: Guillermo Rauch discusses the definition of an application's UI as a pure function of application state. + <strong><a href=\"https://github.com/reactjs/react-basic\">React - Basic Theoretical Concepts</a></strong>: Sebastian Markbage attempts to formally explain his mental model of React. The intention is to describe this in terms of deductive reasoning that lead us to this design. + <strong><a href=\"https://github.com/kriasoft/react-app\">React App</a></strong>: React App is a small library powered by React, Universal Router and History that handles routing, navigation and rendering logic in isomorphic (universal) and single-page applications. + <strong><a href=\"https://medium.com/@dan_abramov/react-components-elements-and-instances-90800811f8ca#.9208ahtfb\">React Components, Elements, and Instances</a></strong>: Dan Abramov explains the Virtual DOM dictionary in React. + <strong><a href=\"http://blog.reverberate.org/2014/02/react-demystified.html\">React Demystified</a></strong>: This article is an attempt to explain the core ideas behind React.js and Virtual DOM. + <strong><a href=\"https://github.com/necolas/react-native-web\">React Native for Web</a></strong>: This project allows components built upon React Native to be run on the Web, and it manages all component styling out-of-the-box. + <strong><a href=\"https://www.reactstarterkit.com/\">React Starter Kit</a></strong>: Isomorphic web app boilerplate including Node.js, Express, GraphQL, React.js, Babel 6, PostCSS, Webpack, Browsersync. + <strong><a href=\"https://github.com/kadirahq/react-storybook\">React Storybook</a></strong>: Isolate your React UI Component development from the main app. + <strong><a href=\"https://github.com/jesstelford/react-workshop\">React Workshop</a></strong>: This is a self-directed workshop. Follow along to the steps at your own pace, and feel free to ask your instructors questions as you go. + <strong><a href=\"https://github.com/krasimir/react-in-patterns\">React in Patterns</a></strong>: List of design patterns/techniques used while developing with React. + <strong><a href=\"https://auth0.com/blog/2015/11/20/face-off-virtual-dom-vs-incremental-dom-vs-glimmer/\">React vs Incremental DOM vs Glimmer</a></strong>: In this post we will explore three technologies to build dynamic DOMs. We will also run benchmarks and find out which one is faster. + <strong><a href=\"https://www.youtube.com/watch?v=x7cQ3mrcKaY\">React: Rethinking best practices (2013)</a></strong>: A video introduction to React by Pete Hunt. + <strong><a href=\"https://github.com/RamonGebben/react-perf-tool\">ReactPerfTool</a></strong>: ReactPerfTool tries to give you a more visual way of debugging performance of your React application. It does this by using the addons delivered by the React team and community to get measurements and visualize this using graphs. + <strong><a href=\"http://jlongster.com/Removing-User-Interface-Complexity,-or-Why-React-is-Awesome\">Removing User Interface Complexity, or Why React is Awesome</a></strong>: In this post James Long tries not to evangelize React specifically, but to explain why its technique is profound. + <strong><a href=\"https://www.youtube.com/watch?v=x7cQ3mrcKaY\">Rethinking Best Practices</a></strong>: Pete Hunt talks about React's design decisions challenging established best practices. + <strong><a href=\"https://github.com/LiquidLabsGmbH/retractor\">Retractor</a></strong>: Retractor exposes the internals of a React application for end-to-end testing purposes. This allows you to select DOM nodes based on the name of the React Component that rendered the node as well as its state or properties. + <strong><a href=\"http://staltz.com/some-problems-with-react-redux.html\">Some Problems with React/Redux</a></strong>: André Staltz goes through the pros and cons of React + Redux. + <strong><a href=\"http://developer.telerik.com/featured/taming-react-setup/\">Taming the React Setup</a></strong>: Cody Lindley lays out seven React setups in this article and explains the relation of React to BYOA (Bring Your Own Architecture) approach. + <strong><a href=\"http://silvenon.com/testing-react-and-redux/\">Testing a React &#x26; Redux Codebase</a></strong>: This series aims to be a very comprehensive guide through testing a React and Redux codebase, where you can really cover a lot with just unit tests because the code is mostly universal. + <strong><a href=\"http://krasimirtsonev.com/blog/article/The-bare-minimum-to-work-with-React\">The Bare Minimum to Work with React</a></strong>: Krasimir Tsonev describes how to start working with React after installing only 7 dependencies and learning only three commands. + <strong><a href=\"https://medium.com/@denisraslov/the-redux-ecosystem-539c630ec521\">The Redux Ecosystem</a></strong>: Let's take a look at most of the features that you'll have to deal with when the time comes, — and where React &#x26; Redux themselves can't help you. + <strong><a href=\"http://www.robinwieruch.de/the-soundcloud-client-in-react-redux/\">The SoundCloud Client in React + Redux</a></strong>: After finishing this step by step tutorial you will be able to author your own React + Redux project with Webpack and Babel. + <strong><a href=\"https://www.fullstackreact.com/articles/react-tutorial-cloning-yelp/\">Tutorial: Cloning Yelp</a></strong>: This post will guide you through building a full React app, even with little to no experience in the framework. We are going to build a Yelp clone in React. + <strong><a href=\"https://medium.com/@firasd/interface-from-data-using-react-to-sync-updates-and-offline-activity-across-devices-f672b213701c\">Using React to Sync Updates and Offline Activity</a></strong>: Firas Durri describes how React based architectures make syncing state across devices much easier. + <strong><a href=\"http://thenewstack.io/developers-need-know-mvi-model-view-intent/\">What Developers Need to Know about MVI (Model-View-Intent)</a></strong>: The article explains the general MVI pattern and how it relates to React, Reactive Programming and Cycle.js + <strong><a href=\"https://github.com/garbles/why-did-you-update\">Why Did You Update?</a></strong>: A function that monkey patches React and notifies you in the console when potentially unnecessary re-renders occur. + <strong><a href=\"http://facebook.github.io/react/blog/2013/06/05/why-react.html\">Why did we build React?</a></strong>: Pete Hunt tries to explain why Facebook devs built React in the first place. + <strong><a href=\"https://github.com/facebook/regenerator\">Regenerator</a></strong>: This package implements a source transformation that takes the proposed syntax for generators/yield from future versions of JS and spits out efficient JS-of-today (ES5) that behaves the same way. + <strong><a href=\"https://www.google.com/\">Google</a></strong>: Google's mission is to organize the world's information and make it universally accessible and useful. + <strong><a href=\"https://addyosmani.com/\">Addy Osmani</a></strong>: Engineer at Google working on open web tooling. + <strong><a href=\"https://addyosmani.com/resources/essentialjsdesignpatterns/book/\">Learning JavaScript Design Patterns</a></strong>: In this free book Addy Osmani explores applying both classical and modern design patterns to the JavaScript programming language. + <strong><a href=\"https://addyosmani.com/largescalejavascript/\">Patterns For Large-Scale JavaScript Application Architecture</a></strong>: An extensive overview by Addy Osmani of existing architectural solutions in the frontend development field. + <strong><a href=\"https://addyosmani.com/writing-modular-js/\">Writing Modular JavaScript With AMD, CommonJS &#x26; ES Harmony</a></strong>: In this article Addy Osmani reviewes several of the options available for writing modular JavaScript using modern module formats AMD, CommonJS and ES6 Modules. + <strong><a href=\"https://developers.google.com/closure/compiler/\">Closure Compiler</a></strong>: The Closure Compiler parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. + <strong><a href=\"https://medium.com/google-developers/introducing-incremental-dom-e98f79ce2c5f\">Introducing Incremental DOM</a></strong>: Incremental DOM is a library inspired by Virtual DOM developed at Google. + <strong><a href=\"http://www.microsoft.com/\">Microsoft</a></strong>: Microsoft Corporation is an American multinational technology company, that develops, manufactures, licenses, supports and sells computer software, consumer electronics and personal computers and services. + <strong><a href=\"https://developer.microsoft.com/en-us/microsoft-edge/tools/\">Dev Tools by Microsoft</a></strong>: These tools allow you to test your product on different version of Internet Explorer and Microsoft Edge. + <strong><a href=\"http://knockoutjs.com/\">Knockout.js</a></strong>: Knockout is a standalone JavaScript implementation of the Model-View-ViewModel pattern with templates. + <strong><a href=\"https://github.com/Reactive-Extensions/RxJS\">Reactive Extensions (RxJS)</a></strong>: RxJS is a set of libraries for composing asynchronous and event-based programs using observable sequences and fluent query operators. + <strong><a href=\"https://www.youtube.com/watch?v=XRYN2xt11Ek\">Async JavaScript with Reactive Extensions</a></strong>: Jafar Husain explains in this video how Netflix uses the Reactive Extensions (Rx) library to build responsive user experiences that strive to be event-driven, scalable and resilient. + <strong><a href=\"http://blog.thoughtram.io/rx/2016/08/01/exploring-rx-operators-flatmap.html\">Exploring Rx Operators: FlatMap</a></strong>: Christoph Burgdorf introduces the FlatMap operator and its usage for collections and observables. + <strong><a href=\"http://blog.thoughtram.io/angular/2016/05/16/exploring-rx-operators-map.html\">Exploring Rx Operators: Map</a></strong>: Christoph Burgdorf explains how to use the map operator in RxJS. + <strong><a href=\"http://www.mokacoding.com/blog/functional-core-reactive-shell/\">Functional Core Reactive Shell</a></strong>: Giovanni Lodi makes an overview of different architecture meta-patterns and describes his current findings about functional programming and observables as a way to control side effects. + <strong><a href=\"http://reactivex.io/learnrx/\">Learn RX</a></strong>: A series of interactive exercises for learning Microsoft's Reactive Extensions (Rx) Library for Javascript. + <strong><a href=\"http://www.learnrxjs.io/\">Learn RxJS</a></strong>: This site focuses on making RxJS concepts approachable, the examples clear and easy to explore, and features references throughout to the best RxJS related material on the web. + <strong><a href=\"https://medium.com/@sergimansilla/real-world-observables-1f65748c8f9\">Real World Observables</a></strong>: Sergi Mansilla writes an FTP client to use it as an example for a real world application based on RxJS. + <strong><a href=\"https://github.com/JulienMoumne/rx-training-games\">Rx Training Games</a></strong>: Rx Training Games is a coding playground that can be used to learn and practice Reactive Extensions coding grid-based games + <strong><a href=\"http://xgrommx.github.io/rx-book/index.html\">Rx-Book</a></strong>: A complete book about RxJS v.4.0. + <strong><a href=\"http://rxmarbles.com/\">RxMarbles</a></strong>: A webapp for experimenting with diagrams of Rx Observables, for learning purposes. + <strong><a href=\"https://www.npmjs.com/package/rxstate\">RxState</a></strong>: Simple opinionated state management library based on RxJS and Immutable.js + <strong><a href=\"http://blog.thoughtram.io/angular/2016/01/06/taking-advantage-of-observables-in-angular2.html\">Taking Advantage of Observables in Angular 2</a></strong>: Christoph Burgdorf describes the advantages of Observables and how you can use them in Angular 2 context. + <strong><a href=\"https://xgrommx.github.io/rx-book/content/getting_started_with_rxjs/creating_and_querying_observable_sequences/transducers.html\">Transducers with Observable Sequences</a></strong>: A chapter from the RxJS Book describing Transducers. + <strong><a href=\"http://staltz.com/why-we-built-xstream.html\">Why We Built Xstream</a></strong>: The authors needed a stream library tailored for Cycle.js. It needs to be \"hot\" only, small in kB size and it should have only a few and intuitive operators. + <strong><a href=\"https://code.visualstudio.com/\">Visual Studio Code</a></strong>: Build and debug modern web and cloud applications. VS Code is free and available on your favorite platform - Linux, Mac OSX, and Windows. + <strong><a href=\"https://www.mozilla.org/\">Mozilla</a></strong>: Mozilla is a community, which uses, develops, spreads and supports free software products. It is supported institutionally by the Mozilla Foundation and its tax-paying subsidiary, the Mozilla Corporation. + <strong><a href=\"https://www.mozilla.org/en-US/firefox/products/\">Firefox</a></strong>: Firefox is the highly popular free web browser. It is available for Linux, Mac, Windows, handheld devices, and in more than 70 different languages. + <strong><a href=\"http://jlongster.com/\">James Long</a></strong>: Works on Firefox Developer Tools at Mozilla. + <strong><a href=\"http://jlongster.com/A-Study-on-Solving-Callbacks-with-JavaScript-Generators\">A Study on Solving Callbacks with JavaScript Generators</a></strong>: This article describes how Generators help fight callback hell. + <strong><a href=\"http://jlongster.com/Removing-User-Interface-Complexity,-or-Why-React-is-Awesome\">Removing User Interface Complexity, or Why React is Awesome</a></strong>: In this post James Long tries not to evangelize React specifically, but to explain why its technique is profound. + <strong><a href=\"https://github.com/jlongster/transducers.js\">Transducers.js Library by James Long</a></strong>: A small library for generalized transformation of data (inspired by Clojure's transducers) + <strong><a href=\"http://jlongster.com/Transducers.js-Round-2-with-Benchmarks\">Transducers.js Round 2 with Benchmarks</a></strong>: Refactored version of Transducers.js, some benchmarks, Laziness, the transformer protocoll. + <strong><a href=\"http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data\">Transducers.js: A JavaScript Library for Transformation of Data</a></strong>: A post announcing the transducers.js library with some explanation. + <strong><a href=\"http://jlongster.com/Transducers.js-Round-2-with-Benchmarks\">Transducers.js Round 2 with Benchmarks</a></strong>: Refactored version of Transducers.js, some benchmarks, Laziness, the transformer protocoll. + <strong><a href=\"http://jlongster.com/Transducers.js--A-JavaScript-Library-for-Transformation-of-Data\">Transducers.js: A JavaScript Library for Transformation of Data</a></strong>: A post announcing the transducers.js library with some explanation. + <strong><a href=\"https://developer.mozilla.org/\">Mozilla Developer Network (MDN)</a></strong>: The MDN is a complete learning platform for Web technologies and the software that powers the Web. + <strong><a href=\"http://mozilla.github.io/nunjucks/\">Nunjucks</a></strong>: A rich and powerful templating language for JavaScript. + <strong><a href=\"https://stripe.com/open-source\">Stripe</a></strong>: Stripe is an Irish technology company that allows both private individuals and businesses to accept payments over the Internet. + <strong><a href=\"https://alexsexton.com/\">Alex Sexton</a></strong>: Alex Sexton is an engineer at Stripe. He is on the Modernizr core team, the jQuery Board of Directors, as well as the Dojo Foundation Board. + <strong><a href=\"https://modernizr.com/\">Modernizr</a></strong>: It's a collection of superfast tests - or \"detects\" as we like to call them - which run as your web page loads, then you can use the results to tailor the experience to the user. + <strong><a href=\"http://mixu.net/\">Mikito Takada (mixu)</a></strong>: Software engineer at Stripe. + <strong><a href=\"http://book.mixu.net/css/\">Learn CSS Layout the pedantic way</a></strong>: Walks you through every major concept in CSS layout, without trying to simplify away the underlying mechanisms described in the CSS 2.1 and flexbox specs. + <strong><a href=\"http://singlepageappbook.com/\">Single Page Apps in Depth</a></strong>: This free book is what I wanted when I started working with single page apps. It's not an API reference on a particular framework, rather, the focus is on discussing patterns, implementation choices and decent practices. + <strong><a href=\"https://github.com/stripe/jquery.mobilePhoneNumber\">jquery.mobilePhoneNumber</a></strong>: A general purpose library for validating and formatting mobile phone numbers. + <strong><a href=\"https://github.com/stripe/jquery.payment\">jquery.payment</a></strong>: A general purpose library for building credit card forms, validating inputs and formatting numbers. + <strong><a href=\"http://todogroup.org/\">TODO Group</a></strong>: TODO is an open group of companies who want to collaborate on practices, tools, and other ways to run successful and effective open source projects and programs. + <strong><a href=\"https://twitter.com/\">Twitter</a></strong>: Twitter is an online social networking service that enables users to send and read short 140-character messages called \"tweets\". + <strong><a href=\"http://flightjs.github.io/\">Flight</a></strong>: An event-driven web framework, from Twitter. + <strong><a href=\"http://twitter.github.io/hogan.js/\">Hogan.js</a></strong>: Hogan.js is a 3.4k JS templating engine developed at Twitter. It was developed against the mustache test suite. + <strong><a href=\"http://nicolasgallagher.com/\">Nicolas Gallagher</a></strong>: Frontend Engineer at Twitter. + <strong><a href=\"http://necolas.github.io/normalize.css/\">Normalize.css</a></strong>: A modern, HTML5-ready alternative to CSS resets. + <strong><a href=\"https://www.w3.org/\">World Wide Web Consortium (W3C)</a></strong>: The W3C is an international community where Member organizations, a full-time staff, and the public work together to develop Web standards. + <strong><a href=\"https://www.w3.org/TR/webarch/#identification\">Architecture of the World Wide Web: Identification</a></strong>: This architecture document by W3C discusses the core design components of the Web. They are identification of resources, representation of resource state, and the protocols that support the interaction between agents and resources in the space. + <strong><a href=\"https://www.w3.org/TR/css-flexbox-1/\">CSS Flexible Box Layout Module Level 1</a></strong>: W3C specification for CSS flexbox. + <strong><a href=\"https://www.w3.org/DOM/DOMTR\">Document Object Model (DOM) Technical Reports</a></strong>: Specifications by the W3C. + <strong><a href=\"http://w3c.github.io/aria-in-html/\">Notes on Using ARIA in HTML</a></strong>: This document is a practical guide for developers on how to add accessibility information to HTML elements using the Accessible Rich Internet Applications specification. + <strong><a href=\"https://www.w3.org/TR/service-workers/\">Service Workers</a></strong>: A method that enables applications to take advantage of persistent background processing, including hooks to enable bootstrapping of web applications while offline. + <strong><a href=\"https://medium.com/google-developers/instant-loading-web-apps-with-an-application-shell-architecture-7c0c2f10c73\">Instant Loading Web Apps With An Application Shell Architecture</a></strong>: Addy Osmani describes how to leverage the Service Worker API to drastically improve the loading speed of your web application. + <strong><a href=\"http://www.html5rocks.com/en/tutorials/service-worker/introduction/\">Introduction to Service Worker</a></strong>: Matt Gaunt introduces the main features of Service Worker API in this article. + <strong><a href=\"https://jakearchibald.github.io/isserviceworkerready/\">Is ServiceWorker Ready?</a></strong>: Tracks the implementation status across the main browsers. + <strong><a href=\"http://w3c.github.io/webcomponents/spec/shadow/\">Shadow DOM W3C Editor's Draft</a></strong>: This specification describes a method of combining multiple DOM trees into one hierarchy and how these trees interact with each other within a document, thus enabling better composition of the DOM. + <strong><a href=\"https://www.yandex.com/\">Yandex</a></strong>: Yandex is one of the largest internet companies in Europe, operating Russia's most popular search engine and its most visited website. + <strong><a href=\"https://en.bem.info/method/\">Block Element Modifier (BEM)</a></strong>: Methodology aimed at achieving fast to develop long-lived projects, team scalability, and code reuse. + <strong><a href=\"http://www.smashingmagazine.com/2012/04/a-new-front-end-methodology-bem/\">A New Front-End Methodology: BEM</a></strong>: An introduction by Varvara Stepanova at SmashingMagazine. + <strong><a href=\"http://webdesign.tutsplus.com/articles/an-introduction-to-the-bem-methodology--cms-19403\">An Introduction to the BEM Methodology</a></strong>: General introduction article on tutsplus. + <strong><a href=\"https://css-tricks.com/bem-101/\">BEM 101</a></strong>: A collaborative post by Joe Richardson, Robin Rendle, and CSS-Tricks staff giving an introduction to BEM with some good examples. + <strong><a href=\"https://m.alphasights.com/bem-i-finally-understand-b0c74815d5b0\">BEM I (finally) understand</a></strong>: In this article Andrei Popa will focus on the basics of BEM and how to approach simple to complex anatomies. + <strong><a href=\"https://www.smashingmagazine.com/2016/06/battling-bem-extended-edition-common-problems-and-how-to-avoid-them/\">Battling BEM (Extended Edition): 10 Common Problems And How To Avoid Them</a></strong>: This article aims to be useful for people who are already BEM enthusiasts and wish to use it more effectively or people who are curious to learn more about it. + <strong><a href=\"https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b\">Block, Element, Modifying Your JavaScript Components</a></strong>: Mark Dalgleish is discussing how to organize React code with BEM and build everything with Webpack. + <strong><a href=\"http://docs.emmet.io/filters/bem/\">Emmet filter for BEM</a></strong>: If you're writing your HTML and CSS code in OOCSS-style, Yandex's BEM style specifically, you will like this filter. It provides some aliases and automatic insertions of common block and element names in classes. + <strong><a href=\"http://blog.kaelig.fr/post/48196348743/fifty-shades-of-bem\">Fifty Shades of BEM</a></strong>: Article describes different flavors of BEM. + <strong><a href=\"https://m.alphasights.com/how-we-use-bem-to-modularise-our-css-82a0c39463b0\">How We Use BEM to Modularise Our CSS</a></strong>: Andrei Popa describes the challenges, AlphaSights team had, implementing BEM in their projects. + <strong><a href=\"https://www.toptal.com/css/introduction-to-bem-methodology\">Introduction To BEM Methodology (Toptal)</a></strong>: General introduction to BEM methodology and platform. + <strong><a href=\"http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/\">MindBEMding - getting your head 'round BEM syntax</a></strong>: Article on csswizardry explaining the BEM syntax for CSS classes. + <strong><a href=\"https://github.com/bem-contrib/pobem\">Pobem</a></strong>: PostCSS plugin for BEM syntax. + <strong><a href=\"http://mikefowler.me/2013/10/17/support-for-bem-modules-sass-3.3/\">Support for BEM modules in Sass 3.3</a></strong>: The next major release of Sass is poised for release and with it comes real support for BEM-style modules... + <strong><a href=\"http://www.didoo.net/to-bem-or-not-to-bem/\">To BEM or not to BEM</a></strong>: A series of interviews on BEM methodology. + <strong><a href=\"https://browser.yandex.com/\">Yandex Browser</a></strong>: Chromium based browser developed by Yandex. + <strong><a href=\"http://zurb.com/\">Zurb</a></strong>: ZURB is a product design company since 1998. Through consulting, product design tools and training, they transform the way businesses approach Progressive Design. + <strong><a href=\"http://foundation.zurb.com/\">Foundation</a></strong>: Foundation provides a responsive grid and HTML and CSS UI components, templates, and code snippets, including typography, forms, buttons, navigation and other interface components, as well as optional JavaScript extensions. + <strong><a href=\"http://foundation.zurb.com/emails.html\">Foundation for Emails 2</a></strong>: Frontend Framework for E-Mails including a grid, global styles, aligment classes, buttons, callout panels, thumbnail styles, typography, visibility classes. + <strong><a href=\"http://zurb.com/playground/responsive-email-templates\">Responsive Email Templates</a></strong>: Zurb Studios put together this set of super awesome email templates so that you can make your email campaigns responsive.</li>\n<li>\n<p><strong>Podcasts</strong>: A podcast is a form of digital media that consists of an episodic series of audio, video, digital radio, PDF, or ePub files subscribed to and downloaded automatically through web syndication or streamed online to a computer or mobile device.</p>\n<ul>\n<li><strong><a href=\"https://devchat.tv/adv-in-angular\">Adventures in Angular</a></strong>: Adventures in Angular is a weekly podcast dedicated to the Angular JavaScript framework and related technologies, tools, languages, and practices.</li>\n<li><strong><a href=\"https://itunes.apple.com/us/podcast/cdnify/id786191888\">CDNify Podcasts</a></strong>: The CDNify podcast covers all things tech, startup, web performance and acceleration.</li>\n<li><strong><a href=\"https://javascriptair.com/\">JavaScript Air</a></strong>: The live broadcast podcast all about JavaScript.</li>\n<li><strong><a href=\"https://devchat.tv/js-jabber/\">JavaScript Jabber</a></strong>: A weekly podcast about JavaScript, including Node.js, Front-End Technologies, Careers, Teams and more.</li>\n<li><strong><a href=\"http://goodstuff.fm/nbsp\">Non Breaking Space Show</a></strong>: Seeking out the best, brightest, and smartest creative people on digital art, design, and development. From workflows to life hacks, we examine why they do what they do and how they did it.</li>\n<li><strong><a href=\"http://shoptalkshow.com/\">Shop Talk Show</a></strong>: An internet radio show about the internet starring Dave Rupert and Chris Coyier.</li>\n<li><strong><a href=\"http://5by5.tv/bigwebshow\">The Big Web Show</a></strong>: The award winning Big Web Show features special guests and topics like web publishing, art direction, content strategy, typography, web technology, and more. It's everything web that matters.</li>\n<li><strong><a href=\"http://5by5.tv/webahead\">The Web Ahead</a></strong>: Conversations with world experts on changing technologies and future of the web. The Web Ahead is your shortcut to keeping up.</li>\n<li><strong><a href=\"https://devchat.tv/web-sec-warriors\">Web Security Warrior</a></strong>: Web Security Warriors is a weekly discussion by developers about keeping websites, data, servers, and other internet outposts secure.</li>\n</ul>\n</li>\n</ul>\n<h2>Languages, Protocols, Browser APIs</h2>\n<p>Programming/mark-up languages and web related standards.</p>\n<ul>\n<li>\n<p><strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS\">Cascading Style Sheets (CSS)</a></strong>: CSS are a stylesheet language used to describe the presentation of a document written in HTML or XML. It describes how elements should be rendered on screen, on paper, in speech, or on other media.</p>\n<ul>\n<li>\n<p><strong>CSS Coding Conventions</strong>: Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices and methods for each aspect of a piece program written in this language.</p>\n<ul>\n<li><strong><a href=\"http://cssguidelin.es/\">CSS Guidelines</a></strong>: High-level advice and guidelines for writing sane, manageable, scalable CSS.</li>\n<li><strong><a href=\"https://github.com/necolas/idiomatic-css\">Idiomatic CSS</a></strong>: The following document outlines a reasonable style guide for CSS development. These guidelines strongly encourage the use of existing, common, sensible patterns.</li>\n<li><strong><a href=\"http://maintainablecss.com/\">Maintainable CSS</a></strong>: MaintainableCSS is an approach to writing modular, scalable and of course, maintainable CSS.</li>\n<li><strong><a href=\"http://primercss.io/\">Primer</a></strong>: Primer is GitHub's internal CSS framework. It includes basic global styling for typography, small components like buttons and tabs, and our general guidelines for writing HTML and CSS.</li>\n<li><strong><a href=\"https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/\">Wordpress CSS Coding Standards</a></strong>: The purpose of the WordPress CSS Coding Standards is to create a baseline for collaboration and review within various aspects of the WordPress open source project and community, from core code to themes to plugins.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://drafts.csswg.org/css-variables/\">CSS Variables W3C Editor's Draft</a></strong>: This module introduces cascading variables as a new primitive value type that is accepted by all CSS properties, and custom properties for defining them.</li>\n<li>\n<p><strong>Flexbox</strong>: The Flexbox Layout officially called CSS Flexible Box Layout Module is new layout module in CSS3 made to improve the items align, directions and order in the container even when they are with dynamic or even unknown size.</p>\n<ul>\n<li><strong><a href=\"http://tutorialzine.com/2016/04/5-flexbox-techniques-you-need-to-know-about/\">5 Flexbox Techniques You Need to Know About</a></strong>: In this article we're going to take a look at five flexbox approaches to solving common CSS layout problems. We've also included practical examples to showcase real life scenarios in which these techniques are applied.</li>\n<li><strong><a href=\"https://css-tricks.com/snippets/css/a-guide-to-flexbox/\">A Complete Guide to Flexbox</a></strong>: Chris Coyer provides a great reference to the flexbox features with code examples.</li>\n<li><strong><a href=\"https://scotch.io/tutorials/a-visual-guide-to-css3-flexbox-properties\">A Visual Guide to CSS3 Flexbox Properties</a></strong>: Rather that explaining how the flex properties work, this guide will focus on how the flex properties affect the layout in a visual way.</li>\n<li><strong><a href=\"https://www.w3.org/TR/css-flexbox-1/\">CSS Flexible Box Layout Module Level 1</a></strong>: W3C specification for CSS flexbox.</li>\n<li><strong><a href=\"https://css-tricks.com/flex-grow-is-weird/\">Flex-Grow is weird. Or is it?</a></strong>: Manuel Matuzovic describes how flex-grow works, including it's weird quirks. Then he goes into several examples on how common layout patterns may be implemented using flex-grow and flex-basis.</li>\n<li><strong><a href=\"http://flexboxfroggy.com/\">Flexbox Froggy</a></strong>: A fun way to learn Flexbox by playing a game where you help Froggy and friends to arrive at a lilypad.</li>\n<li><strong><a href=\"http://www.flexboxpatterns.com/\">Flexbox Patterns</a></strong>: These interactive examples will show you practical ways to use Flexbox to build UI components.</li>\n<li><strong><a href=\"https://github.com/philipwalton/flexbugs\">Flexbugs</a></strong>: This repository is a community-curated list of flexbox issues and cross-browser workarounds for them.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://howtocenterincss.com/\">How To Center in CSS</a></strong>: This tool consolidates the many ways of centering a div and gives you the code you need for each situation.</li>\n<li><strong><a href=\"http://www.tipue.com/blog/center-a-div/\">The Complete Guide to Centering a DIV</a></strong>: The aim of this article is to show how, with a few CSS tricks, any div can be centered; horizontally, vertically or both. And within the page or a div.</li>\n<li><strong><a href=\"https://css-tricks.com/understanding-border-image/\">Understanding border-image</a></strong>: The new CSS3 property border-image can allow you to create flexible boxes with custom borders with a single div and a single image.</li>\n<li><strong><a href=\"http://philipwalton.com/articles/what-no-one-told-you-about-z-index/\">What No One Told You About Z-Index</a></strong>: The problem with z-index is that it's not complicated, but it if you've never taken the time to read its specification, there are almost certainly crucial aspects that you're completely unaware of.</li>\n</ul>\n</li>\n<li>\n<p><strong>Document Object Model (DOM)</strong>: The DOM is a programming interface for HTML, XML and SVG documents. It defines methods that allow access to the tree, so that they can change the document structure, style and content.</p>\n<ul>\n<li>\n<p><strong>Document Events</strong>: DOM event model is a generic event system and a set of standard modules of events for user interface control and document mutation notifications</p>\n<ul>\n<li><strong><a href=\"https://www.smashingmagazine.com/2013/11/an-introduction-to-dom-events/\">An Introduction To DOM Events</a></strong>: Wilson Page introduces the basics of working with DOM events, then delves into their inner workings, explaining how we can make use of them to solve common problems.</li>\n<li><strong><a href=\"https://www.w3.org/TR/DOM-Level-2-Events/events.html\">DOM Level 2 Event Model</a></strong>: W3C specification section for DOM Level 2 Events.</li>\n<li><strong><a href=\"https://craig.is/riding/gators\">Gator</a></strong>: Gator is a small (~0.8 kb minified + gzipped), simple, standalone, event delegation library.</li>\n</ul>\n</li>\n<li>\n<p><strong>Overview</strong>: High level guides, articles and documents about DOM.</p>\n<ul>\n<li><strong><a href=\"http://www.impressivewebs.com/dom-features-you-didnt-know-existed-video-slides/\">DOM Features You Didn't Know Existed</a></strong>: Louis Lazaris talks about DOM Features you probably don't know.</li>\n<li><strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model\">DOM Reference at the MDN</a></strong>: Complete reference of the DOM provided by the Mozilla Development Network.</li>\n<li><strong><a href=\"https://www.w3.org/DOM/DOMTR\">Document Object Model (DOM) Technical Reports</a></strong>: Specifications by the W3C.</li>\n<li><strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction\">Introduction to the DOM</a></strong>: This section provides a brief conceptual introduction to the DOM: what it is, how it provides structure for HTML and XML documents, how you can access it, and how this API presents the reference information and examples.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://www.w3.org/html/\">HyperText Markup Language (HTML)</a></strong>: HTML is the standard markup language used to create web pages and its elements form the building blocks of all websites.</p>\n<ul>\n<li><strong><a href=\"http://diveintohtml5.info/\">Dive Into HTML5 (Book)</a></strong>: Dive Into HTML5 elaborates on a hand-picked selection of features from the HTML5 specification and other fine standards.</li>\n<li><strong><a href=\"https://google.github.io/styleguide/htmlcssguide.xml\">Google HTML/CSS Style Guide</a></strong>: This document defines formatting and style rules for HTML and CSS. It aims at improving collaboration, code quality, and enabling supporting infrastructure.</li>\n<li><strong><a href=\"https://github.com/joshbuchea/HEAD\">HEAD</a></strong>: A list of everything that could go in the <head> of your document.</li>\n<li><strong><a href=\"https://github.com/necolas/idiomatic-html\">Idiomatic HTML</a></strong>: The following document outlines a reasonable style guide for HTML development. These guidelines strongly encourage the use of existing, common, sensible patterns. They should be adapted as needed to create your own style guide.</li>\n<li>\n<p><strong>Video &#x26; Audio</strong>: Use the HTML video and audio element to embed video content in a document.</p>\n<ul>\n<li><strong><a href=\"https://www.smashingmagazine.com/2016/04/html5-media-source-extensions-bringing-production-video-web/\">Bringing Production Video To The Web</a></strong>: Stefan Lederer gives you a good overview of the state and future of video on the web.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://make.wordpress.org/core/handbook/best-practices/coding-standards/html/\">Wordpress HTML Coding Standards</a></strong>: Coding conventions for WordPress.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://www.mnot.net/blog/2016/04/22/ideal-http\">Hypertext Transfer Protocol (HTTP)</a></strong>: The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web.</p>\n<ul>\n<li><strong><a href=\"http://blog.cloud66.com/best-practice-for-http2-front-end-deployments/\">Best Practice for HTTP2 Front-End Deployments</a></strong>: This post describes how to set up and use the new HTTP/2 protocol.</li>\n<li><strong><a href=\"https://www.mnot.net/blog/2016/04/22/ideal-http\">Ideal HTTP Performance</a></strong>: This post talks about the design of the HTTP protocol, it's performance drawbacks and how to work around them.</li>\n</ul>\n</li>\n<li>\n<p><strong>JavaScript (EcmaScript)</strong>: JavaScript is a full-fledged dynamic programming language that, when applied to an HTML document, can provide dynamic interactivity on websites. It is defined by ECMAScript standard.</p>\n<ul>\n<li>\n<p><strong>Control Flow &#x26; Error Handling</strong>: Statements, that you can use to incorporate interactivity in your application.</p>\n<ul>\n<li><strong><a href=\"https://www.sitepoint.com/proper-error-handling-javascript/\">A Guide to Proper Error Handling in JavaScript</a></strong>: Camilo Reyes describes ways to handle Exceptions and asynchronous errors in JavaScript.</li>\n</ul>\n</li>\n<li>\n<p><strong>Enhancement Libraries</strong>: Libraries that attempt to improve and enhance the vanilla JavaScript language by providing utility functions.</p>\n<ul>\n<li><strong><a href=\"https://flowtype.org/\">Flow</a></strong>: Flow is a static type checker for JavaScript. It can be used to catch common bugs in JavaScript programs before they run.</li>\n<li><strong><a href=\"https://lodash.com/\">Lodash</a></strong>: A modern JavaScript utility library delivering modularity, performance, &#x26; extras.</li>\n<li><strong><a href=\"http://moutjs.com/\">MOUT</a></strong>: MOUT provides many helper methods similar to those found on other languages standard libraries (ie. Python, Ruby, PHP).</li>\n<li>\n<p><strong><a href=\"http://ramdajs.com/\">Ramda</a></strong>: A practical library designed specifically for a functional programming style, one that makes it easy to create functional pipelines, one that never mutates user data.</p>\n<ul>\n<li><strong>Practical Ramda - Functional Programming Examples</strong>: Tom MacWright gives some practical examples of Ramda usage.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://rubyjs.org/\">RubyJS</a></strong>: RubyJS is a JavaScript implementation of all methods from Ruby classes like Array, String, Numbers, Time and more.</li>\n</ul>\n</li>\n<li>\n<p><strong>Functions</strong>: A function is a JavaScript procedure—a set of statements that performs a task or calculates a value.</p>\n<ul>\n<li><strong><a href=\"http://jibbering.com/faq/notes/closures/\">Closures explained by Jim Ley</a></strong>: Explanation of closures in JavaScript.</li>\n<li><strong><a href=\"https://medium.freecodecamp.com/lets-learn-javascript-closures-66feb44f6a44\">Let's Learn JavaScript Closures</a></strong>: So this post will be dedicated to the nuts and bolts of how and why closures work the way they do.</li>\n<li><strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions\">MDN Guide Chapter about Functions</a></strong>: Defining functions, scope, closures, arguments, parameters, arrow functions and predefined functions.</li>\n<li><strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions\">MDN Reference for Functions</a></strong>: Defining functions, arguments, parameters, methods, block-level functions and browser compatibility.</li>\n</ul>\n</li>\n<li>\n<p><strong>Generators</strong>: Generators allow you to define an iterative algorithm by writing a single function which can maintain its own state.</p>\n<ul>\n<li><strong><a href=\"http://jlongster.com/A-Closer-Look-at-Generators-Without-Promises\">A Closer Look at Generators Without Promises</a></strong>: Author looks at libraries for asynchronous programming with generators but without promises.</li>\n<li><strong><a href=\"http://jlongster.com/A-Study-on-Solving-Callbacks-with-JavaScript-Generators\">A Study on Solving Callbacks with JavaScript Generators</a></strong>: This article describes how Generators help fight callback hell.</li>\n<li><strong><a href=\"https://medium.com/@tjholowaychuk/callbacks-vs-coroutines-174f1fe66127\">Callbacks vs Coroutines</a></strong>: In this post TJ Holowaychuk goes through hist experiences with coroutines and why he thinks they're a great tool.</li>\n<li><strong><a href=\"https://x.st/javascript-coroutines/\">Coroutine Event Loops in Javascript</a></strong>: An intriguing use of coroutines is to implement event loops as an alternative to callback functions. This is particularly relevant to Javascript, where the use of callbacks is pervasive.</li>\n<li><strong><a href=\"http://stackoverflow.com/questions/715758/coroutine-vs-continuation-vs-generator\">Coroutine vs Continuation vs Generator</a></strong>: StackOverflow Discussion about the difference between Couroutines, Continuations and Generators.</li>\n<li><strong><a href=\"https://github.com/facebook/regenerator\">Regenerator</a></strong>: This package implements a source transformation that takes the proposed syntax for generators/yield from future versions of JS and spits out efficient JS-of-today (ES5) that behaves the same way.</li>\n</ul>\n</li>\n<li>\n<p><strong>Grammar and Types</strong>: JavaScript's basic grammar, variable declarations, data types scope, hoisting and literals.</p>\n<ul>\n<li><strong><a href=\"https://rainsoft.io/detailed-overview-of-well-known-symbols/\">Detailed Overview of Well-Known Symbols</a></strong>: Well-known symbols are used by built-in JavaScript algorithms. This article guides through the list of well-known symbols and explains how to use them comfortable in your code.</li>\n<li><strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types\">Grammar and Types Chapter on the MDN</a></strong>: This chapter discusses JavaScript's basic grammar, variable declarations, data types and literals.</li>\n<li><strong><a href=\"http://bytearcher.com/articles/variable-hoisting-explained/\">Variable Hoisting Explained</a></strong>: The author explains how hoisting works in JavaScript including variable declarations and ES6 let operator.</li>\n<li><strong><a href=\"https://rainsoft.io/variables-lifecycle-and-why-let-is-not-hoisted/\">Variables Lifecycle: Why Let is not Hoisted</a></strong>: ES2015 provides a different and improved mechanism for let. It demands stricter variable declaration practices and as result better code quality. Let's dive into more details about this process.</li>\n</ul>\n</li>\n<li>\n<p><strong>JS Coding Conventions</strong>: Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices and methods for each aspect of a piece program written in this language.</p>\n<ul>\n<li><strong><a href=\"https://github.com/airbnb/javascript\">Airbnb JavaScript Style Guide</a></strong>: A reasonable approach to JavaScript by Airbnb.</li>\n<li><strong><a href=\"https://google.github.io/styleguide/javascriptguide.xml\">Google JavaScript Style Guide</a></strong>: JavaScript is the main client-side scripting language used by many of Google's open-source projects. This style guide is a list of dos and don'ts for JavaScript programs.</li>\n<li><strong><a href=\"https://github.com/rwaldron/idiomatic.js/\">Idiomatic.js</a></strong>: The following list outlines the practices that Rick Waldron uses in all code that he is the original author of.</li>\n<li><strong><a href=\"http://standardjs.com/\">JavaScript Standard Style</a></strong>: A set of modules to check and improve the style of your code.</li>\n<li><strong><a href=\"https://make.wordpress.org/core/handbook/best-practices/coding-standards/javascript/\">WordPress JavaScript Coding Standards</a></strong>: JavaScript has become a critical component in developing WordPress-based applications (themes and plugins) as well as WordPress core. Standards are needed for formatting and styling JavaScript code.</li>\n</ul>\n</li>\n<li>\n<p><strong>Objects</strong>: An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.</p>\n<ul>\n<li><strong><a href=\"http://dmitrysoshnikov.com/ecmascript/chapter-7-1-oop-general-theory/\">ECMA-262-3 in detail: OOP - The general theory</a></strong>: In this article we consider major aspects of object-oriented programming in ECMAScript. Much attention is given to theoretical aspects to see these processes from within.</li>\n<li><strong><a href=\"http://rainsoft.io/gentle-explanation-of-this-in-javascript/\">Gentle explanation of this keyword in JavaScript</a></strong>: This article is focused on the invocation explanation, how the function call influences this and demonstrates the common pitfalls of identifying the context.</li>\n<li><strong><a href=\"http://javascriptissexy.com/oop-in-javascript-what-you-need-to-know/\">OOP In JavaScript: What You NEED to Know</a></strong>: In this article, we are concerned with only Inheritance and Encapsulation since only these two concepts apply to OOP in JavaScript.</li>\n<li><strong><a href=\"http://blog.wolksoftware.com/about-classes-inheritance-and-object-oriented-design-in-typescript-and-es6\">Object-Oriented Design in TypeScript / ES6</a></strong>: The author dives into advanced OOP topics such as functional programming principles, inheritance and inversion of control.</li>\n<li><strong><a href=\"http://javascript.crockford.com/prototypal.html\">Prototypal Inheritance in JavaScript</a></strong>: An article by Douglas Crockford introducing the Object.create() method and describing the rational behind it.</li>\n<li><strong><a href=\"http://alistapart.com/article/prototypal-object-oriented-programming-using-javascript\">Prototypal Object-Oriented Programming using JavaScript</a></strong>: Mehdi Maujood describes the prototypical OO style and compares it to classes in JavaScript.</li>\n<li><strong><a href=\"https://msdn.microsoft.com/magazine/ff852808.aspx\">Prototypes and Inheritance in JavaScript</a></strong>: This article tries to demystify the concept of prototypes in JavaScript. It shows how prototypes allow objects to inherit functionality from other objects, an approach to building objects using the new operator and a constructor function.</li>\n</ul>\n</li>\n<li>\n<p><strong>Overview</strong>: General, high level guides and introductions to the JavaScript language.</p>\n<ul>\n<li><strong><a href=\"http://eloquentjavascript.net/\">Eloquent JavaScript (Book)</a></strong>: A comprehensive book about JavaScript, the language, the browser and Node.js.</li>\n<li><strong><a href=\"http://bonsaiden.github.io/JavaScript-Garden/\">JavaScript Garden</a></strong>: JavaScript Garden is a growing collection of documentation about the most quirky parts of the JavaScript programming language. It gives advice to avoid common mistakes and subtle bugs.</li>\n<li><strong><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide\">JavaScript Guide by Mozilla Developer Network</a></strong>: The JavaScript Guide shows you how to use JavaScript and gives an overview of the language.</li>\n<li><strong><a href=\"http://jargon.js.org/\">Simplified JavaScript Jargon</a></strong>: A community-driven attempt at explaining the loads of buzzwords making the current JavaScript ecosystem in a few simple words.</li>\n<li><strong><a href=\"https://leanpub.com/understandinges6/read\">Understanding ECMAScript 6</a></strong>: Free (as in pay what you want) E-Book by Nicholas C. Zakas describing the new features in EcmaScript 6.</li>\n<li><strong><a href=\"https://www.youtube.com/watch?v=8aGhZQkoFbQ\">What the heck is the event loop anyway?</a></strong>: Philip Roberts, in this video, tries to create an intuitive understanding of what happens when JavaScript runs. He talks about the call stack, event loop, callback queue and other concepts.</li>\n<li><strong><a href=\"https://github.com/getify/You-Dont-Know-JS\">You Dont Know JS</a></strong>: These books each take on specific core parts of the language which are most commonly misunderstood or under-understood, and dive very deep and exhaustively into them.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://www.promisejs.org/\">Promises</a></strong>: A promise represents the result of an asynchronous operation.</p>\n<ul>\n<li><strong><a href=\"http://bluebirdjs.com/\">Bluebird.js</a></strong>: Bluebird is a full featured promise library with unmatched performance.</li>\n<li><strong><a href=\"https://glebbahmutov.com/blog/difference-between-promise-and-task/\">Difference between a Promise and a Task</a></strong>: Once you have a Promise instance the action has already started. Task instance does not run until someone calls .fork()</li>\n<li><strong><a href=\"https://tc39.github.io/ecma262/#sec-promise-objects\">ECMAScript Promises Spec</a></strong>: Standard ES specification for promises.</li>\n<li><strong><a href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise\">MDN page on Promises</a></strong>: The Promise object is used for deferred and asynchronous computations. A Promise represents an operation that hasn't completed yet, but is expected in the future.</li>\n<li><strong><a href=\"https://promisesaplus.com/\">The Promises/A+ Spec</a></strong>: An open standard for sound, interoperable JavaScript promises—by implementers, for implementers.</li>\n<li><strong><a href=\"http://www.2ality.com/2016/04/unhandled-rejections.html\">Tracking Unhandled Rejected Promises</a></strong>: In Promise-based asynchronous code, rejections are used for error handling. One risk is that rejections may get lost, leading to silent failures.</li>\n<li><strong><a href=\"http://cryto.net/~joepie91/blog/\">What is Promise.try, and why does it matter?</a></strong>: In this brief article Sven Slootweg provides a better explanation of what Promise.try is, and why you should always use it, without exceptions.</li>\n<li><strong><a href=\"http://www.telerik.com/blogs/what-is-the-point-of-promises\">What's The Point Of Promises?</a></strong>: The point of promises is to represent the eventual resulting value from an operation, but the reason to use them is to better parallel synchronous operations and to solve the callback hell.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong><a href=\"http://www.json.org/\">JavaScript Object Notation (JSON)</a></strong>: JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language.</li>\n<li>\n<ul>\n<li><strong><a href=\"http://json-ld.org/\">JSON-LD</a></strong>: JSON-LD is a lightweight Linked Data format. It is based on the already successful JSON format and provides a way to help JSON data interoperate at Web-scale.</li>\n</ul>\n</li>\n<li>\n<p><strong>Scalable Vector Graphics (SVG)</strong>: An XML-based vector image format for two-dimensional graphics with support for interactivity and animation.</p>\n<ul>\n<li><strong><a href=\"https://www.smashingmagazine.com/2016/04/tools-and-resources-for-editing-converting-and-optimizing-svgs/\">Tools And Resources For Editing, Converting And Optimizing SVGs</a></strong>: This article will provide you with tools and resources to simplify editing, converting, optimizing, and delivering SVGs.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://www.w3.org/TR/service-workers/\">Service Workers</a></strong>: A method that enables applications to take advantage of persistent background processing, including hooks to enable bootstrapping of web applications while offline.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/google-developers/instant-loading-web-apps-with-an-application-shell-architecture-7c0c2f10c73\">Instant Loading Web Apps With An Application Shell Architecture</a></strong>: Addy Osmani describes how to leverage the Service Worker API to drastically improve the loading speed of your web application.</li>\n<li><strong><a href=\"http://www.html5rocks.com/en/tutorials/service-worker/introduction/\">Introduction to Service Worker</a></strong>: Matt Gaunt introduces the main features of Service Worker API in this article.</li>\n<li><strong><a href=\"https://jakearchibald.github.io/isserviceworkerready/\">Is ServiceWorker Ready?</a></strong>: Tracks the implementation status across the main browsers.</li>\n</ul>\n</li>\n<li><strong>Templating Languages and Engines</strong>: Template engines are tools to separate program-logic and presentation into two independent parts. This makes the development of both logic and presentation easier, improves flexibility and eases modification and maintenance. + <strong><a href=\"http://olado.github.io/doT/\">Dot.js</a></strong>: The fastest + concise javascript template engine for Node.js and browsers. + <strong><a href=\"http://www.dustjs.com/\">Dust.js by LinkedIn</a></strong>: Dust is a Javascript templating engine. It inherits its look from the ctemplate family of languages, and is designed to run asynchronously on both the server and the browser. + <strong><a href=\"http://jed.github.io/domo/\">Dōmo</a></strong>: dōmo lets you write HTML markup and CSS styles in JavaScript syntax. It is a simpler and easier alternative to template engines and CSS pre-processors. + <strong><a href=\"https://github.com/dominictarr/hyperscript\">HyperScript</a></strong>: Create HyperText with JavaScript, on client or server. + <strong><a href=\"https://github.com/marko-js/marko\">Marko</a></strong>: Marko is a really fast and lightweight HTML-based templating engine from eBay. Marko runs on Node.js and in the browser and it supports streaming, async rendering and custom tags. + <strong><a href=\"http://mustache.github.io/\">Mustache</a></strong>: Mustache is a Logic-less template language. There are no if statements, else clauses, or for loops. Instead there are only tags. + <strong><a href=\"https://github.com/wycats/handlebars.js/\">Handlebars.js</a></strong>: Handlebars.js is an extension to the Mustache templating language. Handlebars.js and Mustache are both logicless templating languages that keep the view and the code separated like we all know they should be. + <strong><a href=\"http://twitter.github.io/hogan.js/\">Hogan.js</a></strong>: Hogan.js is a 3.4k JS templating engine developed at Twitter. It was developed against the mustache test suite. + <strong><a href=\"http://mustache.github.io/mustache.5.html\">Mustache Specification</a></strong>: This document explains the different types of Mustache tags. + <strong><a href=\"http://documentup.com/jeremyruppel/walrus/\">Walrus</a></strong>: Walrus is a templating library inspired by mustache, handlebars, ejs and friends,</li>\n<li>but with a couple of important differences in philosophy and style. + <strong><a href=\"https://github.com/janl/mustache.js\">mustache.js</a></strong>: mustache.js is an implementation of the mustache template system in JavaScript. + <strong><a href=\"http://archan937.github.io/templayed.js/\">templayed.js</a></strong>: The fastest and smallest Mustache compliant Javascript templating library written in 1806 bytes. + <strong><a href=\"http://mozilla.github.io/nunjucks/\">Nunjucks</a></strong>: A rich and powerful templating language for JavaScript. + <strong><a href=\"https://github.com/caolan/pithy\">Pithy</a></strong>: An internal DSL for generating HTML in JavaScript. + <strong><a href=\"https://github.com/gcao/T.js\">T</a></strong>: T.js is a template engine that uses simple Javascript data structure to represent html/xml data. + <strong><a href=\"http://idangero.us/template7/\">Template7</a></strong>: Template7 is a mobile-first JavaScript template engine with Handlebars-like syntax. It is used as default template engine in Framework7. + <strong><a href=\"http://leonidas.github.io/transparency/\">Transparency</a></strong>: Transparency is a minimal template engine for jQuery. It maps JSON objects to DOM elements with zero configuration. + <strong><a href=\"https://github.com/tmpvar/weld\">Weld</a></strong>: Weld binds data to markup, and can generate markup based on your data. There's no special syntax or data reshaping required.</li>\n<li>\n<p><strong>Transpiled Languages</strong>: Abstract languages converted to native, browser supported standards like JavaScript or CSS.</p>\n<ul>\n<li><strong><a href=\"https://github.com/clojure/clojurescript\">ClojureScript</a></strong>: ClojureScript is a compiler for Clojure that targets JavaScript. It is designed to emit JavaScript code which is compatible with the advanced compilation mode of the Google Closure optimizing compiler.</li>\n<li><strong><a href=\"https://www.dartlang.org/\">Dart</a></strong>: Dart is an open-source, scalable programming language, with robust libraries and runtimes, for building web, server, and mobile apps compiled to JavaScript</li>\n<li>\n<p><strong><a href=\"http://elm-lang.org/\">Elm</a></strong>: Elm is a functional programming language for declaratively creating web browser-based graphical user interfaces.</p>\n<ul>\n<li><strong><a href=\"http://guide.elm-lang.org/architecture/index.html\">The Elm Architecture</a></strong>: The Elm Architecture is a simple pattern for infinitely nestable components. It is great for modularity, code reuse, and testing.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://lesscss.org/\">Less</a></strong>: Less is a CSS pre-processor, meaning that it extends the CSS language, adding features that allow variables, mixins, functions and many other techniques that allow you to make CSS that is more maintainable, themable and extendable.</li>\n<li><strong><a href=\"http://www.purescript.org/\">PureScript</a></strong>: PureScript is a strongly, statically typed language which compiles to JavaScript. It is written in and inspired by Haskell.</li>\n<li><strong><a href=\"http://sass-lang.com/\">Sass</a></strong>: Sass is an extension of CSS, adding nested rules, variables, mixins, selector inheritance, and more. It's translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.</li>\n<li><strong><a href=\"http://www.scala-js.org/\">Scala.js</a></strong>: A Scala to JavaScript compiler.</li>\n<li><strong><a href=\"http://stylus-lang.com/\">Stylus</a></strong>: Stylus is a revolutionary new language, providing an efficient, dynamic, and expressive way to generate CSS. Supporting both an indented syntax and regular CSS style.</li>\n<li>\n<p><strong><a href=\"https://www.typescriptlang.org/\">TypeScript</a></strong>: A typed superset of JavaScript that compiles to plain JavaScript. Popular in the Angular and Microsoft community.</p>\n<ul>\n<li><strong><a href=\"https://vsavkin.com/writing-angular-2-in-typescript-1fa77c78d8e8\">Angular 2: Why TypeScript?</a></strong>: Angular 2 is written in TypeScript. In this article Victor Savkin talks about why they made the decision.</li>\n<li><strong><a href=\"https://github.com/inversify/InversifyJS\">InversifyJS</a></strong>: A powerful and lightweight inversion of control container for JavaScript &#x26; Node.js apps powered by TypeScript.</li>\n<li><strong><a href=\"https://vsavkin.com/typescript-how-to-be-safe-even-if-you-cannot-type-it-31eb08485fe6\">Safety in the Absence of Types</a></strong>: Victor Savking talks about the limitation of TypeScript's static type checker and how to mitigate them.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Uniform Resource Identifier (URI)</strong>: URI is a string of characters used to identify a resource. The most common form of URI is the Uniform Resource Locator (URL).</p>\n<ul>\n<li><strong><a href=\"https://www.w3.org/TR/webarch/#identification\">Architecture of the World Wide Web: Identification</a></strong>: This architecture document by W3C discusses the core design components of the Web. They are identification of resources, representation of resource state, and the protocols that support the interaction between agents and resources in the space.</li>\n<li><strong><a href=\"https://github.com/pid/speakingurl\">SpeakingURL</a></strong>: This module aims to transliterate the input string and create a so-called Semantic or Speaking URL.</li>\n<li><strong><a href=\"http://medialize.github.io/URI.js/\">URI.js</a></strong>: URI.js is a javascript library for working with URLs. It offers a \"jQuery-style\" API to read and write all regular components and a number of convenience methods.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://w3c.github.io/web-animations/\">Web Animations API</a></strong>: Web Animations is a new JavaScript API for driving animated content on the web. By unifying the animation features of SVG and CSS, Web Animations unlocks features previously only usable declaratively, and exposes powerful, high-performance animation capabilities to developers.</p>\n<ul>\n<li><strong><a href=\"https://birtles.github.io/areweanimatedyet/\">Are we animated yet?</a></strong>: This page tracks the progress of implementing the Web Animations API in Firefox.</li>\n<li><strong><a href=\"http://codepen.io/danwilson/pen/XmWraY\">WAAPI Browser Support Test (+ Polyfill)</a></strong>: This codepen tests whether and to which extend your browser supports Web Animations API. The test is run after including the Polyfill.</li>\n<li><strong><a href=\"https://github.com/web-animations/web-animations-js\">Web Animations Polyfill</a></strong>: JavaScript implementation of the Web Animations API.</li>\n</ul>\n</li>\n<li>\n<p><strong>WebAssembly</strong>: WebAssembly is meant to fill a place that JavaScript has been forced to occupy up to now: a low-level code representation that can serve as a compiler target.</p>\n<ul>\n<li><strong><a href=\"https://auth0.com/blog/2015/10/14/7-things-you-should-know-about-web-assembly/\">7 Things You Should Know About WebAssembly</a></strong>: In this post we will explore seven key facts about WebAssembly, one of the biggest changes the web will experience in the coming years.</li>\n</ul>\n</li>\n</ul>\n<h2>User Interface Components</h2>\n<p>Drop-in UI components for web sites and applications.</p>\n<ul>\n<li>\n<p><strong>Buttons</strong>: The term button refers to any graphical control element that provides the user a simple way to trigger an event, like searching for a query at a search engine, or to interact with dialog boxes, like confirming an action.</p>\n<ul>\n<li><strong><a href=\"https://github.com/nashvail/Quttons\">Quantum Paper Buttons</a></strong>: With this plugin you can hide any div behind a Quantum Paper Button or Qutton. Qunatum Paper is a digital paper that can change its size, shape and color to accommodate new content. Quantum paper is part of Google's new Material Design language.</li>\n<li><strong><a href=\"http://sharingbuttons.io/\">Sharingbuttons.io</a></strong>: This generator outputs social media sharing buttons that do not use JavaScript, don't block your website from rendering, are accessible and don't track the user.</li>\n</ul>\n</li>\n<li><strong>Code</strong>: Code viewers and editors designed for embedding inside a website. + <strong><a href=\"http://jakiestfu.github.io/Behave.js/\">Behave.js</a></strong>: Behave.js is a lightweight library for adding IDE style behaviors to plain text areas, making it much more enjoyable to write code in. + <strong><a href=\"http://codemirror.net/\">CodeMirror</a></strong>: CodeMirror is a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code, and comes with a number of language modes and addons that implement more advanced editing functionality. + <strong><a href=\"http://srobbin.com/jquery-plugins/intelligist/\">Intelligist</a></strong>: A jQuery plugin that makes it easy to share and demo code in-page, using GitHub gists. + <strong><a href=\"http://prismjs.com/\">Prism</a></strong>: Prism is a lightweight, extensible syntax highlighter, built with modern web standards in mind. + <strong><a href=\"https://craig.is/making/rainbows\">Rainbow</a></strong>: Rainbow is a code syntax highlighting library written in Javascript.\nIt was designed to be lightweight, easy to use, and extendable.\nIt is completely themable via CSS. + <strong><a href=\"https://github.com/drudru/ansi_up\">ansi_up</a></strong>: A javascript library that converts text with ANSI terminal codes into colorful HTML + <strong><a href=\"http://julianlam.github.io/tabIndent.js/\">tabIndent.js</a></strong>: tabIndent.js enhances a textarea, so that the tab key no longer takes you to the next input, but rather, acts like a text editor by inserting a tab character.</li>\n<li>\n<p><strong>Forms</strong>: A HTML form on a web page allows a user to enter data that is sent to a server for processing. Web users fill out the forms using checkboxes, radio buttons, or text fields.</p>\n<ul>\n<li><strong><a href=\"https://github.com/alaabadran/ALAJAX\">ALAJAX</a></strong>: A jQuery plugin to convert normal HTML forms into AJAX forms simply. It Ajaxifys your HTML Form with this plugin. No change will be required on Server-Side.</li>\n<li><strong><a href=\"http://schneiderik.github.io/fields/\">Fields.js</a></strong>: An abstract way of interacting with fields. Fields.js creates collections of fields. Each field is constantly evaluated for validity, and is accessible through the collection.</li>\n<li><strong><a href=\"http://kumailht.com/gridforms/\">Grid Forms</a></strong>: A tiny Javascript/CSS framework that helps you make forms on grids with ease.</li>\n<li><strong><a href=\"https://github.com/zoltan-dulac/html5Forms.js\">HTML5Forms.js</a></strong>: HTML5Forms.js is a JavaScript polyfill that implements a subset of the HTML5 Forms module in all browsers. The script will only add support for the different parts of the module when there doesn't exist a native implementation.</li>\n<li><strong><a href=\"https://github.com/hakimel/Ladda\">Ladda</a></strong>: Buttons with built-in loading indicators.</li>\n<li><strong><a href=\"http://nativeformelements.com/\">Native form elements</a></strong>: This is what every HTML5 form element looks like on your current operating system and browser.</li>\n<li><strong><a href=\"https://github.com/erikras/redux-form\">Redux Form</a></strong>: A Higher Order Component using react-redux to keep form state in a Redux store.</li>\n<li>\n<p><strong>Serializers</strong>: Libraries for collecting form data in JavaScript.</p>\n<ul>\n<li><strong><a href=\"https://github.com/maxatwork/form2js\">form2js</a></strong>: Convenient way to collect structured form data into JavaScript object.</li>\n<li><strong><a href=\"https://github.com/hongymagic/jQuery.serializeObject\">jQuery.serializeObject</a></strong>: Encode a set of form elements as a JSON object for manipulation/submission.</li>\n<li><strong><a href=\"https://github.com/macek/jquery-serialize-object\">jquery-serialize-object</a></strong>: Adds the method serializeObject to jQuery, to perform complex form serialization into JavaScript objects.</li>\n<li><strong><a href=\"https://github.com/danheberden/jquery-serializeForm\">jquery.serializeJSON</a></strong>: Make an object out of form elements.</li>\n<li><strong><a href=\"https://github.com/danheberden/jquery-serializeForm\">serializeForm</a></strong>: jQuery plugin to serialize form elements into an object.</li>\n</ul>\n</li>\n<li>\n<p><strong>Validation</strong>: A form validation behavior checks data against a set of criteria before passing it along to the server.</p>\n<ul>\n<li><strong><a href=\"https://css-tricks.com/form-validation-ux-html-css/\">Form Validation UX in HTML and CSS</a></strong>: Chris Coyier describes how to implement form validation with just HTML attributes and some CSS trickery.</li>\n<li><strong><a href=\"https://github.com/mailcheck/mailcheck\">Mailcheck.js</a></strong>: The Javascript library and jQuery plugin that suggests a right domain when your users misspell it in an email address.</li>\n<li><strong><a href=\"https://github.com/One-com/one-validation\">One Validation</a></strong>: This is a collection of regular expressions for general validation purposes. The basic design concept is to split up the regexes into semantic parts of the pattern to match.</li>\n<li><strong><a href=\"https://github.com/guillaumepotier/Parsley.js\">Parsley</a></strong>: JavaScript form validation, without actually writing a single line of JavaScript!</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/remybach/jQuery.superLabels\">jQuery Super Labels Plugin</a></strong>: This plugin was born out of the need to use the label-over-field method for forms.</li>\n</ul>\n</li>\n<li><strong>Galeries &#x26; Image Sliders</strong>: A sophisticated way to present a collection of images on your website.</li>\n<li>\n<ul>\n<li><strong><a href=\"https://github.com/sachinchoolur/lightgallery.js/\">Lightgallery.js</a></strong>: Full featured JavaScript Lightbox gallery without any dependencies.</li>\n</ul>\n</li>\n<li>\n<p><strong>Grid</strong>: CSS Grid Layout Systems.</p>\n<ul>\n<li><strong><a href=\"http://neat.bourbon.io/\">Bourbon Neat</a></strong>: A lightweight semantic grid framework for Sass and Bourbon.</li>\n<li><strong><a href=\"http://www.profoundgrid.com/\">Profound Grid</a></strong>: A responsive grid system for fixed and fluid layouts. Built in SCSS, it gives you flexibility and full control.</li>\n<li><strong><a href=\"http://rwdgrid.com/\">RWDGrid</a></strong>: 2kb, Mobile First Grid System, HTML5 Boilerplate Head, 960grid like naming convention. PSD Grid included.</li>\n<li><strong><a href=\"http://thisisdallas.github.io/Simple-Grid/\">Simple Grid</a></strong>: Simple Grid was created for developers who need a barebones grid. With fluid columns, Simple Grid is responsive down to mobile.</li>\n</ul>\n</li>\n<li>\n<p><strong>Rich Text Editors</strong>: A rich text editor is the interface for editing rich text within web browsers. The aim is to reduce the effort for users trying to express their formatting directly as valid HTML markup.</p>\n<ul>\n<li>\n<p><strong>Content Sanitizers</strong>: Rich text editors often produce unclean input when you copy &#x26; paste some content into them. Content sanitizers help you clean up the text.</p>\n<ul>\n<li><strong><a href=\"http://willemmulder.github.io/FilteredPaste.js/\">FilteredPaste.js</a></strong>: A jQuery plugin that filters any pasted input so that your application gets clean input, without any tags or attributes that you don't want.</li>\n<li><strong><a href=\"https://github.com/gbirke/sanitize.js\">Sanitize.js</a></strong>: Sanitize.js is a whitelist-based HTML sanitizer. Given a list of acceptable elements and attributes, Sanitize.js will remove all unacceptable HTML from a DOM node.</li>\n<li><strong><a href=\"https://github.com/guardian/html-janitor\">html-janitor</a></strong>: Cleans up your markup and allows you to take control of your HTML. HTMLJanitor uses a defined whitelist to limit HTML it is given to a defined subset.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://createjs.org/\">Create.js</a></strong>: Create.js is a comprehensive web editing interface for Content Management Systems. It is designed to provide a modern, fully browser-based HTML5 environment for managing content</li>\n<li><strong><a href=\"http://will-hart.github.io/demarcate.js/\">Demarcate</a></strong>: demarcate.js lets you edit directly in a page and generate Markdown back from the HTML elements.</li>\n<li><strong><a href=\"http://hallojs.org/\">Hallo</a></strong>: Hallo is the simplest web editor imaginable. Instead of cluttered forms or toolbars, you edit your web content as it is. Just you, your web design, and your content.</li>\n<li>\n<p><strong>Inspired by Medium</strong>: Medium.com has a great and simple rich text editor built in. This libraries try to clone its behavior.</p>\n<ul>\n<li><strong><a href=\"https://github.com/jakiestfu/Medium.js\">Medium.js</a></strong>: A tiny JavaScript library for making contenteditable beautiful (Like Medium's editor)</li>\n<li><strong><a href=\"http://sofish.github.io/pen/\">Pen</a></strong>: Rich text editor inspired by Medium and backed by Markdown.</li>\n<li><strong><a href=\"https://github.com/mduvall/grande.js\">grande.js</a></strong>: A small Javascript library that implements features from Medium's editing experience.</li>\n<li><strong><a href=\"https://github.com/yabwe/medium-editor\">medium-editor</a></strong>: Medium.com WYSIWYG editor clone. Uses contenteditable API to implement a rich text solution.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/JoelOtter/kajero\">Kajero</a></strong>: Interactive JavaScript notebooks with markdown support and clever graphing.</li>\n<li><strong><a href=\"http://markitup.jaysalvat.com/\">MarkItUp</a></strong>: markItUp! is a JavaScript plugin built on the jQuery library. It allows you to turn any textarea into a markup editor.</li>\n<li><strong><a href=\"http://jejacks0n.github.io/mercury/\">Mercury Editor</a></strong>: Mercury is a full featured HTML5 editor. It was built from the ground up to help your team get the most out of content editing in modern browsers.</li>\n<li><strong><a href=\"https://github.com/quilljs/quill/\">Quill</a></strong>: Quill is a modern rich text editor built for compatibility and extensibility. It was created by Jason Chen and Byron Milligan and open sourced by Salesforce.com.</li>\n<li>\n<p><strong><a href=\"https://github.com/guardian/scribe\">Scribe</a></strong>: A rich text editor framework for the web platform, with patches for browser inconsistencies and sensible defaults. Developed by The Guardian.</p>\n<ul>\n<li><strong><a href=\"https://www.theguardian.com/info/developer-blog/2014/mar/20/inside-the-guardians-cms-meet-scribe-an-extensible-rich-text-editor\">Inside the Guardian's CMS: meet Scribe, an extensible rich text editor</a></strong>: The team behind the Guardian's digital content management system talk about how and why they built and open sourced Scribe.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://substance.io/\">Substance</a></strong>: Substance is a JavaScript library for web-based content editing. It provides building blocks for realizing custom text editors and web-based publishing systems.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/@_mql/build-your-own-editor-with-substance-7790eb600109\">Build your own editor with Substance</a></strong>: This article describes the philosophy behind Substance and how to get started.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://textangular.com/\">TextAngular</a></strong>: A Lightweight, Two-Way-Bound Angular.js Text-Editor.</li>\n<li>\n<p><strong><a href=\"http://xing.github.io/wysihtml5/\">WYSIHTML5</a></strong>: wysihtml5 is an open source rich text editor based on HTML5 technology and the progressive-enhancement approach. It aims to generate fully valid HTML5 markup by preventing unmaintainable tag soups and inline styles.</p>\n<ul>\n<li><strong><a href=\"https://github.com/Voog/wysihtml\">Voog fork</a></strong>: wysihtml is an extended and less strict approach on xing/wysihtml5 open source rich text editor based on HTML5 technology. The code is completely library agnostic: No jQuery, Prototype or similar is required.</li>\n<li><strong><a href=\"https://github.com/zohararad/wysihtml5n\">WYSIHTML5 Enhanced</a></strong>: WYSIHTML5 Enhanced is a rich-text editor, based on the wonderful wysihtml5 editor, with a bit of help from Twitter Bootstrap, Font-Awesome, Jcrop and HTML5's Drag &#x26; Drop and File API.</li>\n<li><strong><a href=\"https://github.com/bootstrap-wysiwyg/bootstrap3-wysiwyg\">bootstrap3-wysiwyg</a></strong>: Bootstrap-wysihtml5 is a javascript plugin that makes it easy to create simple, beautiful wysiwyg editors with the help of wysihtml5 and Twitter Bootstrap.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://vitalets.github.io/x-editable/\">X-editable</a></strong>: This library allows you to create editable elements on your page. It can be used with any engine (bootstrap, jquery-ui, jquery only) and includes both popup and inline modes.</li>\n</ul>\n</li>\n<li><strong>Table Of Contents</strong>: Components for automatic table of contents generation.</li>\n<li>\n<ul>\n<li><strong><a href=\"http://tscanlin.github.io/tocbot/\">Tocbot</a></strong>: Tocbot builds a table of contents (TOC) from headings in an HTML document.</li>\n</ul>\n</li>\n<li>\n<p><strong>UI Kits</strong>: Collections of ready to use components.</p>\n<ul>\n<li><strong><a href=\"https://cloudflare.github.io/cf-ui/\">CloudFlare Components</a></strong>: A set of UI components built by CloudFlare and based on React.</li>\n<li><strong><a href=\"http://ink.sapo.pt/\">Ink</a></strong>: An HTML5/CSS3 framework used at SAPO for fast and efficient website design and prototyping.</li>\n<li><strong><a href=\"http://www.primefaces.org/primeng/\">PrimeNG</a></strong>: PrimeNG is a collection of rich UI components for AngularJS2. PrimeNG is a sibling of the popular JavaServer Faces Component Suite, PrimeFaces.</li>\n<li><strong><a href=\"http://primercss.io/\">Primer</a></strong>: Primer is GitHub's internal CSS framework. It includes basic global styling for typography, small components like buttons and tabs, and our general guidelines for writing HTML and CSS.</li>\n<li><strong><a href=\"http://purecss.io/\">Pure.css</a></strong>: A set of small, responsive CSS modules that you can use in every web project.</li>\n<li><strong><a href=\"http://getuikit.com/\">UIkit</a></strong>: A lightweight and modular front-end framework and a set of components for developing fast and powerful web interfaces.</li>\n<li><strong><a href=\"http://doximity.github.io/vital/\">Vital</a></strong>: A minimally invasive CSS framework for modern web applications.</li>\n</ul>\n</li>\n<li>\n<p><strong>Video &#x26; Audio</strong>: Components for playing audio and video files on a website.</p>\n<ul>\n<li><strong><a href=\"http://kolber.github.io/audiojs/\">Audio.js</a></strong>: audio.js is a drop-in javascript library that allows HTML5's audio tag to be used anywhere.</li>\n<li><strong><a href=\"https://github.com/goldfire/howler.js\">Howler.js</a></strong>: howler.js is an audio library for the modern web. It defaults to Web Audio API and falls back to HTML5 Audio.</li>\n<li><strong><a href=\"http://jplayer.org/\">JPlayer</a></strong>: jPlayer a media library written in JavaScript. A jQuery plugin, jPlayer allows you to rapidly weave cross platform audio and video into your web pages.</li>\n<li><strong><a href=\"http://mediaelementjs.com/\">MediaElement.js</a></strong>: HTML5 audio or video player with Flash and Silverlight shims that mimics the HTML5 MediaElement API, enabling a consistent UI in all browsers.</li>\n<li><strong><a href=\"https://stratus.soundcloud.com/\">Stratus 2</a></strong>: Stratus is a jQuery powered SoundCloud player that lives at the bottom (or top) of your website or blog.</li>\n<li><strong><a href=\"https://github.com/videojs/video.js\">Video.js</a></strong>: Video.js is a web video player built from the ground up for an HTML5 world. It supports HTML5 and Flash video, as well as YouTube and Vimeo (through plugins). It supports video playback on desktops and mobile devices.</li>\n</ul>\n</li>\n</ul>\n<h2>Workflow</h2>\n<p>Task automation and asset delivery.</p>\n<ul>\n<li><strong>Automated Testing</strong>: Automated software testing is a process in which software tools execute pre-scripted tests on a software application before it is released into production. + <strong><a href=\"https://medium.com/javascript-scene/5-common-misconceptions-about-tdd-unit-tests-863d5beb3ce9\">5 Common Misconceptions About TDD &#x26; Unit Tests</a></strong>: Eric Elliott breaks down some common misconceptions and explains how you can benefit the most from TDD &#x26; unit tests. + <strong><a href=\"http://jrsinclair.com/articles/2016/gentle-introduction-to-javascript-tdd-intro/\">A Gentle Introduction to Javascript Test Driven Development</a></strong>: Over the course of the series, James Sinclair works through developing a full application in JavaScript that involves making network requests and manipulating the DOM. + <strong><a href=\"https://shanetomlinson.com/2013/testing-javascript-frontend-part-1-anti-patterns-and-fixes/\">Anti-patterns and Their Fixes</a></strong>: Shane Tomlinson presents a sample application that contains several common anti-patterns and how these can be refactored to be more testable. + <strong><a href=\"http://chaijs.com/\">Chai</a></strong>: Chai is a BDD/TDD assertion library for node and the browser that can be paired with any JavaScript testing framework. + <strong><a href=\"https://cucumber.io/\">Cucumber</a></strong>: Cucumber is a software tool that computer programmers use for testing other software. It runs automated acceptance tests written in a behavior-driven development (BDD) style. + <strong><a href=\"https://github.com/cucumber/cucumber-js\">Cucumber.js</a></strong>: Cucumber.js is a Cucumber implementation written in pure JavaScript. It runs on Node.js, IO.js, browsers and any other JavaScript platform. + <strong><a href=\"https://github.com/cucumber/cucumber/wiki/Gherkin\">Gherkin</a></strong>: Gherkin is the language that Cucumber understands. It is a Business Readable, Domain Specific Language that lets you describe software's behaviour without detailing how that behaviour is implemented. + <strong><a href=\"http://galoisinc.github.io/FiveUI/\">FiveUI</a></strong>: FiveUI is an extensible tool for evaluating HTML user interfaces</li>\n<li>against sets of codified UI Guidelines. + <strong><a href=\"https://dannorth.net/introducing-bdd/\">Introducing BDD</a></strong>: Dan North introduces behaviour-driven development (BDD). A software development process that emerged from test-driven development (TDD). + <strong><a href=\"https://github.com/jasmine/jasmine\">Jasmine</a></strong>: Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, Node.js projects, or anywhere that JavaScript can run. + <strong><a href=\"https://www.sitepoint.com/javascript-testing-unit-functional-integration/\">JavaScript Testing: Unit vs Functional vs Integration Tests</a></strong>: Unit tests, integration tests, and functional tests are all types of automated tests which form essential cornerstones of continuous delivery, a development methodology that allows you to safely ship changes to production in days or hours rather than months or years. + <strong><a href=\"https://github.com/facebook/jest\">Jest</a></strong>: A JavaScript unit testing framework, used by Facebook to test services and React applications. + <strong><a href=\"http://devlucky.github.io/kakapo-js\">Kakapo.js</a></strong>: Kakapo its a full featured http mocking library, he allows you to entirely replicate your backend logic in simple and declaritive way directly in the browser. + <strong><a href=\"http://karma-runner.github.io/\">Karma</a></strong>: A simple tool that allows you to execute JavaScript code in multiple real browsers. + <strong><a href=\"https://github.com/box/leche\">Leche</a></strong>: A JavaScript testing utility designed to work with Mocha and Sinon. This is intended for use both by Node.js and in browsers, so any changes must work in both locations. + <strong><a href=\"https://remysharp.com/2015/12/14/my-node-test-strategy\">My Node Test Strategy</a></strong>: Remy Sharp shates his automated testing process with tape, proxyquire, sinon and browserify. + <strong><a href=\"https://github.com/Huddle/PhantomCSS\">PhantomCSS</a></strong>: PhantomCSS takes screenshots and compares them to baseline images to test for RGB pixel differences. PhantomCSS then generates image diffs to help you find the cause. + <strong><a href=\"http://qunitjs.com/\">QUnit</a></strong>: QUnit is a powerful, easy-to-use JavaScript unit testing framework. It's used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code. + <strong><a href=\"https://shanetomlinson.com/2013/writing-testable-javascript-part-2-refactor-away-anti-patterns/\">Refactor Away Anti-Patterns</a></strong>: Shane Tomlinson continues by refactoring the original application, including testing anti patterns, to be easier to read, easier to reuse, and easier to test. + <strong><a href=\"https://github.com/domenic/sinon-chai\">Sinon.JS Assertions for Chai</a></strong>: Sinon-Chai provides a set of custom assertions for using the Sinon.JS spy, stub, and mocking framework with the Chai assertion library. You get all the benefits of Chai with all the powerful tools of Sinon.JS. + <strong><a href=\"http://sinonjs.org/\">Sinon.js</a></strong>: Standalone test spies, stubs and mocks for JavaScript. No dependencies, works with any unit testing framework. + <strong><a href=\"http://codeutopia.net/blog/2016/05/23/sinon-js-quick-tip-how-to-stubmock-complex-objects-such-as-dom-objects/\">How to Stub/Mock Complex Objects</a></strong>: In this article, we'll look at how to stub objects which are deeply nested, and when functions have more complex return values and they interact with other objects. + <strong><a href=\"https://github.com/substack/tape\">Tape</a></strong>: Tap-producing test harness for node and browsers. + <strong><a href=\"https://ponyfoo.com/articles/testing-javascript-modules-with-tape\">Testing JavaScript Modules with Tape</a></strong>: In this article we will get an in-depth look at three modules: tape, proxyquire, and sinon. + <strong><a href=\"https://medium.com/javascript-scene/why-i-use-tape-instead-of-mocha-so-should-you-6aa105d8eaf4#.fjpja613n\">Why I use Tape Instead of Mocha &#x26; So Should You</a></strong>: Eric Elliott describes the advantages of Tape and compares it to more popular testing frameworks. + <strong><a href=\"https://github.com/leebyron/testcheck-js\">TestCheck</a></strong>: TestCheck is a library for generative testing of program properties, ala QuickCheck. + <strong><a href=\"http://silvenon.com/testing-react-and-redux/\">Testing a React &#x26; Redux Codebase</a></strong>: This series aims to be a very comprehensive guide through testing a React and Redux codebase, where you can really cover a lot with just unit tests because the code is mostly universal. + <strong>Writing Testable JavaScript</strong>: Rebecca Murphey discusses how to organize code to make JavaScript more testable in unit tests.</li>\n<li>\n<p><strong>Build Tools</strong>: Toolkits and their ecosystems, that help you automate painful and repeated tasks.</p>\n<ul>\n<li><strong><a href=\"http://indigounited.com/automaton/\">Automaton</a></strong>: Task automation tool built in JavaScript.</li>\n<li>\n<p><strong><a href=\"http://gruntjs.com/\">Grunt</a></strong>: Grunt is a task-based command line build tool for JavaScript projects.</p>\n<ul>\n<li><strong><a href=\"http://mattbailey.io/a-beginners-guide-to-grunt-redux.html\">A beginner's guide to Grunt: Redux</a></strong>: Simple Grunt boilerplate for frontend workflow with detailed instructions.</li>\n<li><strong><a href=\"https://github.com/tsvensen/gruntstart\">GruntStart</a></strong>: A Grunt-enabled head-start with the H5BP, jQuery, Modernizr, and Respond. The building blocks to quickly get started with Grunt to create an optimized website.</li>\n<li><strong><a href=\"http://mattbailey.io/grunt-synchronised-testing-between-browsers-devices\">Synchronised Testing Between Browsers/Devices</a></strong>: The article describes an easy way to test your projects on your devices.</li>\n<li><strong><a href=\"http://ruudud.github.io/2012/12/22/grunt/\">Web development is getting complex. Let's go shopping.</a></strong>: A step by step tutorial for building a new project with grunt.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://gulpjs.com/\">Gulp</a></strong>: Gulp is a toolkit that helps you automate painful or time-consuming tasks in your development workflow. It's very fast, platform-agnostic and simple.</p>\n<ul>\n<li>\n<p><strong>Articles &#x26; Tutorials</strong>: Publications about gulp or step by step guides for setting up and using gulp in a project.</p>\n<ul>\n<li>\n<p><strong>Building with Gulp 3 and 4 (Series)</strong>: Great series of articles about single components and gulp as a whole.</p>\n<ul>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/04/23/building-with-gulp-3-and-4-part-1-examples/\">Part 1: Examples</a></strong>: Introduction to gulp and gulpfile.js.</li>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/04/23/building-with-gulp-3-and-4-part-2-gulp-anatomy/\">Part 2: Gulp's anatomy</a></strong>: Orchestrator, Undertaker, Vinyl and Vinyl FS, Gulp Plugins.</li>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/04/28/building-with-gulp-3-and-4-part-3-writing-transformers/\">Part 3: Writing transformers</a></strong>: Using map-stream, though2 and event-stream.</li>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/05/01/building-with-gulp-4-part-4-incremental-builds/\">Part 4: Incremental builds</a></strong>: Building files which changed since last run and caching.</li>\n<li><strong><a href=\"http://blog.reactandbethankful.com/posts/2015/05/05/building-with-gulp-part-5-caveats/\">Part 5: Caveats</a></strong>: Error management in Gulp 3 and \"MANY:1 disguised as a 1:1\" problem.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://medium.com/@contrahacks/gulp-3828e8126466\">The vision, history, and future of the project (Apr. 2014)</a></strong>: The article talks about Streams, Vinyl, Vinyl Adapters, Orchestrator and Error Management in Gulp 4.</li>\n<li><strong><a href=\"http://scm.io/blog/hack/2014/07/why-gulp-might-not-be-the-answer/\">Why Gulp might not be the Answer</a></strong>: ... there is still a conceptual problem that Gulp has yet to address. Many build steps are not 1:1 (one file in, one file out) but rather n:1 or 1:n.</li>\n</ul>\n</li>\n<li>\n<p><strong>CSS</strong>: Gulp plugins for working with CSS files.</p>\n<ul>\n<li><strong><a href=\"https://github.com/scniro/gulp-clean-css\">gulp-clean-css</a></strong>: gulp plugin to minify CSS, using clean-css.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-cssnano\">gulp-cssnano</a></strong>: Minify CSS with cssnano.</li>\n</ul>\n</li>\n<li>\n<p><strong>Concatenation</strong>: Plugins for file concatenation. For example bundling CSS or JavaScript files.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-concat\">gulp-concat</a></strong>: This plugin will concat files by your operating systems newLine. It will take the base directory from the first file that passes through it.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-group-concat\">gulp-group-concat</a></strong>: Concats groups of files into a smaller number of files</li>\n</ul>\n</li>\n<li>\n<p><strong>Deployment</strong>: Plugins for pushing built files into production.</p>\n<ul>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-tar\">gulp-tar</a></strong>: Create tarball from files.</li>\n<li><strong><a href=\"https://github.com/morris/vinyl-ftp\">vinyl-ftp</a></strong>: Blazing fast vinyl adapter for FTP.</li>\n<li><strong><a href=\"https://github.com/izaakschroeder/vinyl-s3\">vinyl-s3</a></strong>: Use S3 as a source or destination of vinyl files.</li>\n</ul>\n</li>\n<li>\n<p><strong>Ecosystem</strong>: The network of developers and plugins around gulp.</p>\n<ul>\n<li><strong><a href=\"https://github.com/search?q=%40sindresorhus+gulp-\">@sindresorhus plugins</a></strong>: A collection of plugins by Sindre Sorhus.</li>\n<li><strong><a href=\"https://www.npmjs.com/browse/keyword/gulpfriendly\">Gulp Friendly NPM Packages</a></strong>: Normal node packages that work with gulp.</li>\n</ul>\n</li>\n<li>\n<p><strong>Filters</strong>: Plugins for filtering files in a vinyl stream.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-cache\">gulp-cache</a></strong>: A temp file based caching proxy task for gulp.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-cached\">gulp-cached</a></strong>: A simple in-memory file cache for gulp.</li>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-changed\">gulp-changed</a></strong>: Only pass through changed files.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-filter\">gulp-filter</a></strong>: Filter files in a vinyl stream.</li>\n<li><strong><a href=\"https://github.com/tschaub/gulp-newer\">gulp-newer</a></strong>: Pass through newer source files only.</li>\n<li><strong><a href=\"https://github.com/ahaurw01/gulp-remember\">gulp-remember</a></strong>: A plugin for gulp that remembers and recalls files passed through it.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-diff\">vinyl-diff</a></strong>: This library allows you to perform diffs between streams of vinyl.</li>\n</ul>\n</li>\n<li>\n<p><strong>Images</strong>: Plugins for working with images.</p>\n<ul>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-imagemin\">gulp-imagemin</a></strong>: Minify PNG, JPEG, GIF and SVG images.</li>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-webp\">gulp-webp</a></strong>: Convert PNG, JPEG, TIFF images to WebP.</li>\n</ul>\n</li>\n<li>\n<p><strong>JavaScript</strong>: Module loaders, minifiers and other tools for working with JavaScript files.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-pure-cjs\">gulp-pure-cjs</a></strong>: Gulp plugin for Pure CommonJS builder.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-uglify\">gulp-uglify</a></strong>: Minify files with UglifyJS.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/yoloader\">yoloader</a></strong>: A CommonJS module loader implementation. It provides tools to bundle a CommonJS based project and to load such bundles.</li>\n</ul>\n</li>\n<li>\n<p><strong>SourceMaps</strong>: A source map provides a way of mapping code within a compressed file back to it's original position in a source file.</p>\n<ul>\n<li><strong><a href=\"https://github.com/floridoo/gulp-sourcemaps/wiki/Plugins-with-gulp-sourcemaps-support\">Plugins with gulp sourcemaps support</a></strong>: A list of plugins which support gulp-sourcemaps.</li>\n<li><strong><a href=\"https://github.com/floridoo/gulp-sourcemaps\">gulp-sourcemaps</a></strong>: Source map support for Gulp.js</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-sourcemaps-apply\">vinyl-sourcemaps-apply</a></strong>: Apply a source map to a vinyl file, merging it with preexisting source maps.</li>\n</ul>\n</li>\n<li>\n<p><strong>Utility</strong>: Tools and parts for building gulp plugins.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-count\">gulp-count</a></strong>: Count files in a vinyl stream.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/gulp-debug\">gulp-debug</a></strong>: Debug vinyl file streams to see what files are run through your gulp pipeline.</li>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-size\">gulp-size</a></strong>: Logs out the total size of files in the stream and optionally the individual file-sizes.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/lazypipe\">lazypipe</a></strong>: Lazypipe allows you to create an immutable, lazily-initialized pipeline. It's designed to be used in an environment where you want to reuse partial pipelines, such as with gulp.</li>\n<li><strong><a href=\"https://github.com/dominictarr/map-stream\">map-stream</a></strong>: Create a through stream from an asyncronous function.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"https://github.com/gulpjs/vinyl\">Vinyl</a></strong>: Vinyl is a very simple metadata object that describes a file.</p>\n<ul>\n<li><strong><a href=\"https://github.com/sindresorhus/gulp-chmod\">gulp-chmod</a></strong>: Change permissions of Vinyl files.</li>\n<li><strong><a href=\"https://github.com/hparra/gulp-rename\">gulp-rename</a></strong>: A plugin to rename files easily.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/mem-fs\">mem-fs</a></strong>: Simple in-memory vinyl file store.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-ast\">vinyl-ast</a></strong>: Parse-once and generate-once AST tool bridge for Gulp plugins.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-buffer\">vinyl-buffer</a></strong>: Creates a transform stream that takes vinyl files as input, and outputs buffered (isStream() === false) vinyl files as output.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-file\">vinyl-file</a></strong>: Create a vinyl file from an actual file.</li>\n<li><strong><a href=\"https://github.com/wearefractal/vinyl-fs\">vinyl-fs</a></strong>: Vinyl adapter for the file system.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-fs-fake\">vinyl-fs-fake</a></strong>: A vinyl adapter that extends vinyl-fs to allow for easy debugging by passing in virtual files instead of globs, and calling a function instead of writing.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-git\">vinyl-git</a></strong>: Vinyl adapter for git.</li>\n<li><strong><a href=\"https://github.com/hughsk/vinyl-map\">vinyl-map</a></strong>: Map vinyl files' contents as strings, so you can easily use existing code without needing yet another gulp plugin!</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-paths\">vinyl-paths</a></strong>: Get the file paths in a vinyl stream.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-source-buffer\">vinyl-source-buffer</a></strong>: Convert a text stream into a vinyl pipeline whose content is a buffer.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-source-stream\">vinyl-source-stream</a></strong>: Use conventional text streams at the start of your gulp or vinyl pipelines, making for nicer interoperability with the existing npm stream.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-to-stream\">vinyl-to-stream</a></strong>: Convert a vinyl stream to a text stream.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/vinyl-transform\">vinyl-transform</a></strong>: Wraps standard text transform streams so you can write fewer gulp plugins. Fulfills a similar use case to vinyl-map and vinyl-source-stream.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong><a href=\"http://mimosajs.com\">Mimosa</a></strong>: Mimosa is a batteries included web development workflow tool that will get you coding in seconds rather than hunting down plugins and wrangling config for hours.</li>\n<li>\n<p><strong><a href=\"https://github.com/amwmedia/plop\">Plop</a></strong>: Micro-generator framework that makes it easy for an entire team to create files with a level or uniformity.</p>\n<ul>\n<li><strong><a href=\"http://newbranch.cn/ui-development-with-es6-javascript-part-x-automating-workflow-with-plop/\">Automating Workflow with plop</a></strong>: Automating UI Development with Riot.js and ES6 Javascript.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://webpack.github.io/\">Webpack</a></strong>: Webpack is a module bundler. It takes modules with dependencies and generates static assets representing those modules.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b\">Block, Element, Modifying Your JavaScript Components</a></strong>: Mark Dalgleish is discussing how to organize React code with BEM and build everything with Webpack.</li>\n<li><strong><a href=\"http://dapperdeveloper.com/2016/05/18/developing-with-docker-and-webpack/\">Developing with Docker and Webpack</a></strong>: Chris Harrington explains how to create a development environment with Webpack and Docker to match the production as much as possible.</li>\n<li><strong><a href=\"http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html\">Full-Stack Redux Tutorial</a></strong>: We will go through all the steps of constructing a Node+Redux backend and a React+Redux frontend for a real-world application, using test-first development.</li>\n<li><strong><a href=\"http://www.davidmeents.com/how-to-set-up-webpack-image-loader/\">How to Set Up Webpack Image Loader</a></strong>: This brief tutorial will help you set up an image loader in Webpack.</li>\n<li><strong><a href=\"http://www.robinwieruch.de/the-soundcloud-client-in-react-redux/\">The SoundCloud Client in React + Redux</a></strong>: After finishing this step by step tutorial you will be able to author your own React + Redux project with Webpack and Babel.</li>\n<li><strong><a href=\"http://survivejs.com/webpack/\">Webpack from Apprentice to Master</a></strong>: The purpose of this guide is to help you get started with Webpack and then go beyond basics.</li>\n<li><strong><a href=\"http://www.webpackbin.com/\">WebpackBin</a></strong>: A webpack code sandbox.</li>\n<li><strong><a href=\"http://devlog.disco.zone/2016/06/01/webpack/\">Why I think Webpack is the Right Approach To Build Pipelines</a></strong>: Thomas Boyt compares how Grunt, Gulp, Broccoli and Webpack discover dependencies.</li>\n</ul>\n</li>\n<li><strong><a href=\"http://yeoman.io/\">Yeoman</a></strong>: Yeoman helps you to kickstart new projects, prescribing best practices and tools to help you stay productive. It provides a generator ecosystem.</li>\n</ul>\n</li>\n<li>\n<p><strong>CSS Tools</strong>: Tools for analysis, pre and post processing of CSS files.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.com/package/css-pack\">CSS Pack</a></strong>: Packs CSS dependency graphs produced from dgraph or module-deps into a single CSS bundle, assuming every node in the graph contains CSS source and the graph itself is sorted with deps-sort</li>\n<li><strong><a href=\"https://github.com/reworkcss/css-stringify\">CSS Stringify</a></strong>: CSS stringifier using the AST from 'css.parse'</li>\n<li><strong><a href=\"http://zmoazeni.github.io/csscss/\">CSSCSS</a></strong>: A CSS redundancy analyzer that analyzes redundancy.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/clean-css\">Clean CSS</a></strong>: Clean-css is a fast and efficient Node.js library for minifying CSS files.</li>\n<li><strong><a href=\"https://github.com/geuis/helium-css\">Helium CSS</a></strong>: Helium is a tool for discovering unused CSS across many pages on a web site.</li>\n<li>\n<p><strong><a href=\"http://postcss.org/\">PostCSS</a></strong>: PostCSS parses CSS into an abstract syntax tree (AST), passes it through a series of plugins, and then concatenates back into a string.</p>\n<ul>\n<li><strong><a href=\"https://www.sitepoint.com/an-introduction-to-postcss/\">An Introduction to PostCSS</a></strong>: This article describes what PostCSS is and how to get started.</li>\n<li><strong><a href=\"https://github.com/jacobp100/es-css-modules\">ES CSS Modules</a></strong>: PostCSS plugin that combines CSS Modules and ES Imports.</li>\n<li><strong><a href=\"https://www.sitepoint.com/improving-the-quality-of-your-css-with-postcss/\">Improving the Quality of Your CSS with PostCSS</a></strong>: In this article, we will explore how we can utilise PostCSS to help us maintain a higher quality in our CSS code.</li>\n<li><strong><a href=\"https://www.reactstarterkit.com/\">React Starter Kit</a></strong>: Isomorphic web app boilerplate including Node.js, Express, GraphQL, React.js, Babel 6, PostCSS, Webpack, Browsersync.</li>\n<li><strong><a href=\"https://css-tricks.com/images-in-postcss/\">Working with Images in Stylesheets</a></strong>: Aleks Hudochenkov does a great job of showcasing what PostCSS is good at and the role it has grown into in the front end stack.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://stylelint.io/\">Stylelint</a></strong>: Stylelint's ambitious goal is to supplement our discipline with automatic enforcement — to provide a core set of rules and a pluggable framework that CSS authors can use to enforce their own strategies.</p>\n<ul>\n<li><strong><a href=\"https://css-tricks.com/stylelint/\">Lint your CSS with Stylelint</a></strong>: David Clark writes about reasons for using a CSS linter and advantages of Stylelint.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>Code Editors</strong>: Text editor programs designed specifically for editing source code of a website.</p>\n<ul>\n<li><strong><a href=\"https://atom.io/\">Atom</a></strong>: Atom is a text editor that's modern, approachable, yet hackable to the core—a tool you can customize to do anything but also use productively without ever touching a config file.</li>\n<li><strong><a href=\"http://brackets.io/\">Brackets</a></strong>: An open source code editor for the web, written in JavaScript, HTML and CSS.</li>\n<li><strong><a href=\"https://notepad-plus-plus.org/\">Notepad++</a></strong>: Notepad++ is a free (as in \"free speech\" and also as in \"free beer\") source code editor and Notepad replacement that supports several languages. Running in the MS Windows environment, its use is governed by GPL License</li>\n<li><strong><a href=\"https://code.visualstudio.com/\">Visual Studio Code</a></strong>: Build and debug modern web and cloud applications. VS Code is free and available on your favorite platform - Linux, Mac OSX, and Windows.</li>\n</ul>\n</li>\n<li>\n<p><strong>Documentation</strong>: Writing, generating, publishing and consuming documentation for web deliverables.</p>\n<ul>\n<li><strong><a href=\"http://atomicdocs.io/\">Atomic Docs</a></strong>: Atomic Docs is a styleguide generator and component manager. Atomic Docs is built in PHP. Inspired by Brad Frost's Atomic Design principles.</li>\n<li><strong><a href=\"http://daux.io/\">Daux</a></strong>: Daux.io is a documentation generator that uses a simple folder structure and Markdown files to create custom documentation on the fly.</li>\n<li><strong><a href=\"http://www.dexy.it/\">Dexy</a></strong>: Dexy makes it easier to create technical documents by doing the repetitive parts for you. Dexy provides a consistent interface to tools and scripts so you don't have to run them manually.</li>\n<li><strong><a href=\"http://jashkenas.github.io/docco/\">Docco</a></strong>: Docco is a quick-and-dirty documentation generator. It produces an HTML document that displays your comments intermingled with your code.</li>\n<li><strong><a href=\"http://usejsdoc.org/\">JSDoc Documentation</a></strong>: Comprehensive guide for JSDoc.</li>\n<li><strong><a href=\"https://github.com/rtomayko/ronn\">Ronn</a></strong>: Ronn builds manuals. It converts simple, human readable textfiles to roff for terminal display, and also to HTML for the web.</li>\n<li><strong><a href=\"https://github.com/plaid/transcribe\">Transcribe</a></strong>: Transcribe is a simple program which generates Markdown documentation from code comments.</li>\n<li><strong><a href=\"http://yui.github.io/yuidoc/\">YUIDoc</a></strong>: YUIDoc is a Node.js application that generates API documentation from comments in source, using a syntax similar to tools like Javadoc and Doxygen.</li>\n<li><strong><a href=\"http://doug-martin.github.io/coddoc/\">coddoc</a></strong>: coddoc is a jsdoc parsing library. Coddoc is different in that it is easily extensible by allowing users to add tag and code parsers. It also parses source code to be used in APIs.</li>\n<li><strong><a href=\"http://devdocs.io/\">devdocs.io</a></strong>: Devdocs is an all-in-one API documentation reader with a fast, organized, and consistent interface.</li>\n<li><strong><a href=\"https://github.com/visionmedia/dox\">dox</a></strong>: JavaScript documentation generator for node using markdown and jsdoc.</li>\n<li><strong><a href=\"http://jacobrask.github.io/styledocco/\">styledocco</a></strong>: StyleDocco generates documentation and style guide documents from your stylesheets.</li>\n</ul>\n</li>\n<li>\n<p><strong>Fonts for Programmers</strong>: Programmers need special fonts, which help align the code and distinguish between characters, that look alike.</p>\n<ul>\n<li><strong><a href=\"https://www.google.com/fonts/specimen/Droid+Sans+Mono\">Droid Sans Mono</a></strong>: Droid Sans Mono makes for a great programming font. Its only real flaw is the lack of a slashed zero.</li>\n<li><strong><a href=\"http://cdn.sixrevisions.com/0441-01_programming-fonts/demo/programming-fonts.html\">Free Programming Fonts</a></strong>: A demonstration of beautiful fonts for people who love to code.</li>\n<li><strong><a href=\"https://github.com/madmalik/mononoki\">Mononoki</a></strong>: Mononoki is a typeface by Matthias Tellen, created to enhance code formatting.</li>\n<li><strong><a href=\"http://tobiasjung.name/profont/\">Profont</a></strong>: Profont is a monospaced font created to be a most readable font for programming. It is designed to look good a really small sizes</li>\n<li><strong><a href=\"https://github.com/adobe-fonts/source-code-pro\">Source Code Pro</a></strong>: Source Code Pro is a set of OpenType fonts that have been designed to work well in user interface (UI) environments.</li>\n<li><strong><a href=\"https://fonts.google.com/specimen/Space%20Mono\">Space Mono</a></strong>: Space Mono is an original fixed-width type family designed by Colophon Foundry for Google Design.</li>\n</ul>\n</li>\n<li>\n<p><strong>Getting Started</strong>: Step by step guides for setting up a frontend development workflow.</p>\n<ul>\n<li>\n<p><strong><a href=\"http://www.gpmd.co.uk/blog/front-end-process-flat-builds-and-automation-part-1-introduction/\">Front-end Process - Flat Builds and Automation (series)</a></strong>: A flat build is basically the process of coding a static page (or pages) in HTML and CSS. The idea is to supply our developers with design assets such as style guides, pattern libraries or prototypes, including assets such as images, fonts, css, and javascript, as flat builds.</p>\n<ul>\n<li><strong><a href=\"http://www.gpmd.co.uk/blog/front-end-process-flat-builds-and-automation-part-4-css-framework/\">CSS Framework (Inuit)</a></strong>: In this part the author introduces the inuit CSS framework and describes how to integrate the framework into the development process.</li>\n<li><strong><a href=\"http://www.gpmd.co.uk/blog/front-end-process-flat-builds-and-automation-part-2-environment-setup-and-yeoman/\">Environment Setup &#x26; Yeoman</a></strong>: In this part the author outlines how to set up your dev environment, and how to scaffold a project using Yeoman.</li>\n<li><strong><a href=\"http://www.gpmd.co.uk/blog/front-end-process-flat-builds-and-automation-part-3-grunt-tasks/\">Grunt Tasks</a></strong>: The author outlined how to set up your dev environment, and how to scaffold a project using Yeoman. In this third part we will look at how to install and configure some grunt tasks.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p><strong>HTML Tools</strong>: Tools for pre and post processing of the HTML source code.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.org/package/html-inspector\">html-inspector</a></strong>: HTML Inspector is a code quality tool to help you and your team write better markup. It's written in JavaScript and runs in the browser, so testing your HTML has never been easier.</li>\n<li><strong><a href=\"https://www.npmjs.com/package/html-minifier\">html-minifier</a></strong>: HTMLMinifier is a highly configurable, well-tested, Javascript-based HTML minifier, with lint-like capabilities.</li>\n</ul>\n</li>\n<li>\n<p><strong>Image Post Processing</strong>: Tools for image conversion and optimization.</p>\n<ul>\n<li><strong><a href=\"https://github.com/JamieMason/ImageOptim-CLI\">ImageOptim-CLI</a></strong>: Make lossless optimisation of images part of your automated build process.</li>\n<li><strong><a href=\"https://github.com/tjko/jpegoptim\">Jpegoptim</a></strong>: Utility to optimize/compress JPEG files.</li>\n<li><strong><a href=\"https://www.keycdn.com/blog/optimize-images-for-web/\">Optimize Images for Web - Ultimate Guide</a></strong>: We will discuss the three areas in which you can better optimize images for web: better web performance, rank and index better in search engines, better social media engagement and CTR.</li>\n<li><strong><a href=\"http://pmt.sourceforge.net/pngcrush/\">Pngcrush</a></strong>: Pngcrush is an optimizer for PNG (Portable Network Graphics) files.</li>\n<li><strong><a href=\"https://github.com/jasonmoo/smlr\">SMLR</a></strong>: Re-encode jpeg images with no perceivable quality loss. Uses the butteraugli psychovisual comparison and k-ary search to determine the best jpeg quality setting.</li>\n</ul>\n</li>\n<li>\n<p><strong>JavaScript Tools</strong>: Tools for static analysis, pre and post processing of JavaScript files.</p>\n<ul>\n<li>\n<p><strong><a href=\"https://babeljs.io/\">Babel</a></strong>: Babel is a generic multi-purpose compiler for JavaScript. Using Babel you can use (and create) the next generation of JavaScript, as well as the next generation of JavaScript tooling.</p>\n<ul>\n<li><strong><a href=\"http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html\">Full-Stack Redux Tutorial</a></strong>: We will go through all the steps of constructing a Node+Redux backend and a React+Redux frontend for a real-world application, using test-first development.</li>\n<li><strong><a href=\"https://scotch.io/tutorials/javascript-transpilers-what-they-are-why-we-need-them\">JavaScript Transpilers: What They Are &#x26; Why We Need Them</a></strong>: Learn how to use Babel, and what has to do with the future of JavaScript.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://developers.google.com/closure/compiler/\">Closure Compiler</a></strong>: The Closure Compiler parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.</li>\n<li><strong><a href=\"https://flowtype.org/\">Flow</a></strong>: Flow is a static type checker for JavaScript. It can be used to catch common bugs in JavaScript programs before they run.</li>\n<li>\n<p><strong><a href=\"https://github.com/facebook/jscodeshift\">JSCodeshift</a></strong>: Codemods are tools that assist large-scale, partially automatable codebase refactoring. JSCodeshift is a toolkit for running codemods over multiple JS files.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/airbnb-engineering/turbocharged-javascript-refactoring-with-codemods-b0cae8b326b9\">Turbocharged JavaScript Refactoring with Codemods</a></strong>: Joe Lencioni describes how they used codemods to transform a large JavaScript code base at AirBnB</li>\n</ul>\n</li>\n<li>\n<p><strong>JavaScript Code Linting</strong>: Linting is the process of running a program that will analyse code for potential errors.</p>\n<ul>\n<li><strong><a href=\"http://eslint.org/\">ESLint</a></strong>: The pluggable linting utility for JavaScript and JSX.</li>\n<li><strong><a href=\"http://jshint.com/\">JSHint</a></strong>: JSHint is a tool for more flexible static analysis of JavaScript programs.</li>\n<li><strong><a href=\"http://jslint.com/\">JSLint</a></strong>: JSLint is a tool for detecting errors or problems by static analysis of JavaScript programs.</li>\n<li><strong><a href=\"http://jslinterrors.com\">JSLint, JSHint and ESLint Error Explanations</a></strong>: JSLint Error Explanations is designed to help you improve your JavaScript by understanding the sometimes cryptic error messages produced by JSLint, JSHint and ESLint, and teaching you how to avoid such errors.</li>\n</ul>\n</li>\n<li>\n<p><strong>Module Bundlers and Loaders</strong>: Libraries for bundling JavaScript Modules into one or several files.</p>\n<ul>\n<li>\n<p><strong><a href=\"http://browserify.org/\">Browserify</a></strong>: Browserify lets you require('modules') in the browser by bundling up all of your dependencies.</p>\n<ul>\n<li><strong><a href=\"https://github.com/mattdesl/budo\">Budo</a></strong>: A browserify development server, focused on incremental reloading, LiveReload integration (including CSS injection), and other high-level features.</li>\n<li><strong><a href=\"https://www.npmjs.org/package/watchify\">Watchify</a></strong>: Watch mode for browserify builds.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/gregersrygg/crapLoader\">CrapLoader</a></strong>: The goal of crapLoader is to load ads, widgets or any JavaScript code with document.write in it. This library hijacks document.write and delegates the content loaded from each script into the correct position.</li>\n<li><strong><a href=\"https://github.com/medikoo/modules-webmake\">Modules Webmake</a></strong>: A CommonJS module bundler similar to Browserify but much faster due to different requirements finder.</li>\n<li><strong><a href=\"http://requirejs.org/\">Require.js</a></strong>: RequireJS is a JavaScript file and AMD module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments.</li>\n<li><strong><a href=\"http://stuk.github.io/require1k/\">Require1k</a></strong>: CommonJS require for the browser in 1KB, with no build needed.</li>\n<li><strong><a href=\"http://rollupjs.org/\">Rollup.js</a></strong>: Rollup is a next-generation JavaScript module bundler. Author your app or library using ES2015 modules, then efficiently bundle them up into a single file for use in browsers and Node.js.</li>\n<li>\n<p><strong><a href=\"https://github.com/systemjs/systemjs\">SystemJS</a></strong>: Universal dynamic module loader - loads ES6 modules, AMD, CommonJS and global scripts in the browser and NodeJS. Works with both Traceur and Babel.</p>\n<ul>\n<li><strong><a href=\"http://www.sitepoint.com/modular-javascript-systemjs-jspm/\">Modular JavaScript: A Beginners Guide to SystemJS &#x26; JSPM</a></strong>: The combination of jspm and SystemJS provides a unified way of installing and loading dependencies.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/anodynos/urequire\">URequire</a></strong>: The Ultimate JavaScript Module Builder &#x26; Automagical Task Runner.</li>\n<li>\n<p><strong><a href=\"http://webpack.github.io/\">Webpack</a></strong>: Webpack is a module bundler. It takes modules with dependencies and generates static assets representing those modules.</p>\n<ul>\n<li><strong><a href=\"https://medium.com/seek-ui-engineering/block-element-modifying-your-javascript-components-d7f99fcab52b\">Block, Element, Modifying Your JavaScript Components</a></strong>: Mark Dalgleish is discussing how to organize React code with BEM and build everything with Webpack.</li>\n<li><strong><a href=\"http://dapperdeveloper.com/2016/05/18/developing-with-docker-and-webpack/\">Developing with Docker and Webpack</a></strong>: Chris Harrington explains how to create a development environment with Webpack and Docker to match the production as much as possible.</li>\n<li><strong><a href=\"http://teropa.info/blog/2015/09/10/full-stack-redux-tutorial.html\">Full-Stack Redux Tutorial</a></strong>: We will go through all the steps of constructing a Node+Redux backend and a React+Redux frontend for a real-world application, using test-first development.</li>\n<li><strong><a href=\"http://www.davidmeents.com/how-to-set-up-webpack-image-loader/\">How to Set Up Webpack Image Loader</a></strong>: This brief tutorial will help you set up an image loader in Webpack.</li>\n<li><strong><a href=\"http://www.robinwieruch.de/the-soundcloud-client-in-react-redux/\">The SoundCloud Client in React + Redux</a></strong>: After finishing this step by step tutorial you will be able to author your own React + Redux project with Webpack and Babel.</li>\n<li><strong><a href=\"http://survivejs.com/webpack/\">Webpack from Apprentice to Master</a></strong>: The purpose of this guide is to help you get started with Webpack and then go beyond basics.</li>\n<li><strong><a href=\"http://www.webpackbin.com/\">WebpackBin</a></strong>: A webpack code sandbox.</li>\n<li><strong><a href=\"http://devlog.disco.zone/2016/06/01/webpack/\">Why I think Webpack is the Right Approach To Build Pipelines</a></strong>: Thomas Boyt compares how Grunt, Gulp, Broccoli and Webpack discover dependencies.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/facebook/regenerator\">Regenerator</a></strong>: This package implements a source transformation that takes the proposed syntax for generators/yield from future versions of JS and spits out efficient JS-of-today (ES5) that behaves the same way.</li>\n</ul>\n</li>\n<li>\n<p><strong>Package Management</strong>: A package manager or package management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing reusable libraries and components in a consistent manner.</p>\n<ul>\n<li><strong><a href=\"https://github.com/bower/bower\">Bower</a></strong>: Bower offers a generic, unopinionated solution to the problem of front-end package management, while exposing the package dependency model via an API that can be consumed by a more opinionated build stack.</li>\n<li><strong><a href=\"https://github.com/lerna/lerna\">Lerna</a></strong>: Lerna is a tool that optimizes the workflow around managing multi-package repositories with git and npm.</li>\n<li><strong><a href=\"https://www.npmjs.com/\">NPM</a></strong>: NPM makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you're sharing.</li>\n</ul>\n</li>\n<li>\n<p><strong><a href=\"http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/\">Sourcemaps</a></strong>: Sourcemap is a way to map a combined/minified file back to an unbuilt state.</p>\n<ul>\n<li><strong><a href=\"https://www.npmjs.org/package/combine-source-map\">combine-source-map</a></strong>: Add source maps of multiple files, offset them and then combine them into one source map.</li>\n<li><strong><a href=\"https://www.npmjs.org/package/convert-source-map\">convert-source-map</a></strong>: Converts a source-map from/to different formats and allows adding/changing properties.</li>\n<li><strong><a href=\"https://github.com/thlorenz/exorcist\">exorcist</a></strong>: Externalizes the source map found inside a stream to an external .js.map file</li>\n<li><strong><a href=\"https://www.npmjs.org/package/generate-sourcemap\">generate-sourcemap</a></strong>: Generates a source map for files that were packed into a bundle.</li>\n<li><strong><a href=\"https://www.npmjs.org/package/inline-source-map\">inline-source-map</a></strong>: Adds source mappings and base64 encodes them, so they can be inlined in your generated file.</li>\n<li><strong><a href=\"https://www.npmjs.org/package/mold-source-map\">mold-source-map</a></strong>: Mold a source map that is almost perfect for you into one that is.</li>\n<li><strong><a href=\"https://www.npmjs.org/package/source-map-cjs\">source-map-cjs</a></strong>: Generates and consumes source maps. Adapted to be commonjs only and work in older browsers.</li>\n</ul>\n</li>\n<li>\n<p><strong>Version Control</strong>: Version control or source control is a system that records changes to a file or set of files over time so that you can recall specific versions later.</p>\n<ul>\n<li>\n<p><strong><a href=\"https://git-scm.com/\">Git</a></strong>: Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.</p>\n<ul>\n<li><strong><a href=\"https://www.atlassian.com/git/tutorials\">Become a Git Guru</a></strong>: A series of Git tutorials by Atlassian.</li>\n</ul>\n</li>\n<li><strong><a href=\"https://github.com/OctoLinker/browser-extension\">OctoLinker</a></strong>: The OctoLinker is a browser extensions which makes references to other files in GitHub clickable.</li>\n</ul>\n</li>\n</ul>"},{"url":"/docs/react/react-in-depth/","relativePath":"docs/react/react-in-depth.md","relativeDir":"docs/react","base":"react-in-depth.md","name":"react-in-depth","frontmatter":{"title":"React In Depth","weight":0,"excerpt":"React embraces the fact that rendering logic is...","seo":{"title":"Intro To React","description":"React embraces the fact that rendering logic is inherently coupled with other UI logic: how events are handled, how the state changes over time.","robots":[],"extra":[{"name":"og:description","value":"React embraces the fact that rendering logic is inherently coupled with other UI logic: how events are handled, how the state changes over time.","keyName":"property","relativeUrl":false},{"name":"og:title","value":"Intro To React","keyName":"property","relativeUrl":false},{"name":"og:image","value":"images/kind-whale.gif","keyName":"property","relativeUrl":true},{"name":"twitter:title","value":"Intro To React","keyName":"name","relativeUrl":false},{"name":"twitter:description","value":"React embraces the fact that rendering logic is inherently coupled with other UI logic: how events are handled, how the state changes over time.","keyName":"name","relativeUrl":false},{"name":"twitter:card","value":"react_img_intro","keyName":"name","relativeUrl":false},{"name":"og:type","value":"website","keyName":"property","relativeUrl":false}],"type":"stackbit_page_meta"},"template":"docs"},"html":"<h1>React In Depth</h1>\n<iframe style=\"resize:both; overflow:scroll;\"  sandbox=\"allow-scripts\" style=\"resize:both; overflow:scroll;\"    src=\"https://codesandbox.io/embed/react-gists-4s3ll?fontsize=14&hidenavigation=1&theme=dark\"\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"> style=\"width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\"\n\n title=\"react-gists\"\n\n allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n\n sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"</code></pre></div>\n<blockquote>\n</iframe>\n<br>\n</blockquote>\n<h1>Random Things to Remember</h1>\n<p><img src=\"https://miro.medium.com/max/60/0*LHVHf7SPZ1t0UVAj?q=20\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/630/0*LHVHf7SPZ1t0UVAj\" alt=\"medium blog image\"></p>\n<p><img src=\"https://miro.medium.com/max/60/0*wR-lbD4zf45-IHoQ?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/630/0*wR-lbD4zf45-IHoQ\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/60/0*7EZESKf0XPbncXAY?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/630/0*7EZESKf0XPbncXAY\" alt=\"medium blog image\"></p>\n<ul>\n<li>Using () implictly returns components.</li>\n<li>-</li>\n<li>Role of index.js is to <em>render</em> your application.</li>\n<li>-</li>\n<li>The reference to root comes from a div in the body of you</li>\n<li>-</li>\n<li>State of a component is simply</li>\n<li>-</li>\n<li>Class Components require render() method to return JSX.</li>\n<li>Functional Components directly return JSX.</li>\n<li>Class is className in React.</li>\n<li>When parsing for an integer just chain Number.parseInt(\"123\")</li>\n<li>Use ternary operator if you want to make a conditional inside a fragment.</li>\n</ul>\n<!---->\n<ul>\n<li>Purpose of React.Fragment is to allow you to create groups of children without adding an extra dom element.</li>\n</ul>\n<h1>Front-End History</h1>\n<ul>\n<li>React makes it easier for you to make front-end elements. A front-end timeline</li>\n<li>-</li>\n<li>Some noteworthy front e</li>\n<li>-</li>\n<li>2005: Scrip</li>\n<li>-</li>\n<li>2005: Dojo</li>\n<li>-</li>\n<li>2006: YUI</li>\n<li>-</li>\n<li>2010: Knockout</li>\n<li>-</li>\n<li>2011:</li>\n<li>-</li>\n<li>2012: Elm</li>\n<li>-</li>\n<li>2013: React (Considered</li>\n<li>-</li>\n<li>React manages the creation and updating of DOM nodes in your Web page.</li>\n<li>-</li>\n<li>All it does is dynamically render stuff into your DOM.</li>\n<li>What it doesn't do:</li>\n<li>Ajax</li>\n<li>Services</li>\n<li>Local Storage</li>\n<li>Provide a CSS framework</li>\n<li>React is unopinionated</li>\n<li>Just contains a few rules for developers to follow, and it just works.</li>\n<li>JSX : Javascript Extension is a language invented to help write React Applications (looks like a mixture of JS and HTML)</li>\n<li>Here is an overview of the difference between rendering out vanilla JS to create elements, and JSX:</li>\n</ul>\n<!---->\n<ul>\n<li>This may seem like a lot of code but when you end up building many components, it becomes nice to put each of those functions/classes into their own files to organize your code. Using tools with React</li>\n<li>-</li>\n<li>React DevTools : New tool in your browser to see ow React is working in the browser</li>\n<li>-</li>\n<li>create-react-app : Extensible command-line tool to help generate standard React applications.</li>\n<li>Webpack : In between tool for dealing with the extra build step involved.</li>\n</ul>\n<!---->\n<ul>\n<li>HMR : (Hot Module Replacement) When you make changes to your source code the changes are delivered in real-time.</li>\n<li>-</li>\n<li>React Developers created something called Flux Architecture to moderate how their web page consumes and modifies data received from back-end API's.</li>\n</ul>\n<!---->\n<ul>\n<li>Choosing React</li>\n<li>-</li>\n<li>Basically, React is super important to learn and master.</li>\n</ul>\n<h1>React Concepts and Features</h1>\n<p>There are many benefits to using React over just Vanilla JavaScript.</p>\n<ul>\n<li>Modularity</li>\n<li>-</li>\n<li>To avoid the me</li>\n<li>-</li>\n<li>Easy to start</li>\n<li>-</li>\n<li>No specials tools are needed to use Basic React.</li>\n<li>-</li>\n<li>You can start working directly with createElement method in React.</li>\n<li>-</li>\n<li>Declarative Programming</li>\n<li>-</li>\n<li>React is declarative in nature, utilizing either it's built-in createElement method or the higher-level language known as JSX.</li>\n<li>-</li>\n<li>Reusability</li>\n<li>Create elements that can be re-used over and over. One-flow of data</li>\n<li>React apps are built as a combination of parent and child components.</li>\n<li>Parents can have one or more child components, all children have parents.</li>\n<li>Data is never passed from child to the parent.</li>\n<li>Virtual DOM : React provides a Virtual DOM that acts as an agent between the real DOM and the developer to help debug, maintain, and provide general use.</li>\n<li>Due to this usage, React handles web pages much more intelligently; making it one of the speediest Front End Libraries available.</li>\n</ul>\n<h1>ES6 Refresher</h1>\n<p>Exporting one item per file</p>\n<ul>\n<li>Use export default statement in ES6 to export an item. ES6</li>\n</ul>\n<p>CommonJS (Equivalent)</p>\n<p>Exporting multiple items per file</p>\n<ul>\n<li>Use just thw export keyword (without default) to export multiple items per file. ES6 (Better to export them individually like this, rather than bunching them all into an object)</li>\n</ul>\n<p>CommonJS (Equivalent)</p>\n<p>Importing with ES6 vs CommonJS</p>\n<ul>\n<li>Import statements in ES6 modules must always be at the top of the file, because all imports must occur before the rest of the file's code runs. ES6</li>\n</ul>\n<p>CommonJS</p>\n<p>Unnamed default imports</p>\n<ul>\n<li>You can name unnamed items exported with export default any name when you import them.</li>\n</ul>\n<!---->\n<ul>\n<li>Just remember if you use export instead of export default then your import is already named and cannot be renamed.</li>\n</ul>\n<p>Aliasing imports</p>\n<ul>\n<li>Use as asterisk to import an entire module's contents.</li>\n<li>-</li>\n<li>Keep in mind you must use an as keyword to refer to it later.</li>\n</ul>\n<!---->\n<ul>\n<li>You can also name identically named functions or items from different files.</li>\n</ul>\n<p>Browser support for ES6 Modules</p>\n<ul>\n<li>ES6 Modules can only be used when a JS file is specified as a module. &#x3C;script type=\"module\" src=\"./wallet.js\">&#x3C;/script></li>\n<li>-</li>\n<li>You can get browser support for ES6 modules by adding module into your script tag.</li>\n</ul>\n<h1>Notes</h1>\n<h1>JSX In Depth</h1>\n<ul>\n<li>Remember that JSX is just syntactic sugar for the built in React.createElement(component, props, ...children)</li>\n<li>-</li>\n<li>React Library must always be in</li>\n<li>-</li>\n<li>Use Dot Notation for JSX Type</li>\n<li>User-Defined Components Must Be Capitalized &#x3C;Foo /> vs &#x3C;div></li>\n<li>Cannot use a general expression as the React element type. (Incorrect)</li>\n</ul>\n<p>(Corrected)</p>\n<p>Props in JSX</p>\n<ul>\n<li>Several ways to specify props in JSX.</li>\n<li>-</li>\n<li>Javascript Expressions as Props</li>\n</ul>\n<!---->\n<ul>\n<li>String Literals</li>\n</ul>\n<!---->\n<ul>\n<li>Props Default to \"True\"</li>\n</ul>\n<!---->\n<ul>\n<li>Spread Attributes</li>\n</ul>\n<p>Children in JSX</p>\n<ul>\n<li>props.children : The content between opening and closing tag. JavaScript Expressions as Children</li>\n</ul>\n<p>Functions as Children</p>\n<ul>\n<li>props.children works like any other prop, meaning it can pass any sort of data.</li>\n</ul>\n<p>Booleans, Null, and Undefined Are Ignored</p>\n<ul>\n<li>false, null, undefined, and true are all valid children.</li>\n<li>-</li>\n<li>They will not render.</li>\n<li>You can use these to conditionally render items.</li>\n</ul>\n<!---->\n<ul>\n<li>In this example, the component will only render if showHeader evals to True.</li>\n</ul>\n<!---->\n<ul>\n<li>Note that certain falsy values such as zero will still be rendered by React, you can work around this by ensuring situations like the above eval. into a boolean.</li>\n<li>-</li>\n<li>In the times you want booleans to be rendered out, simply convert it into a string first.</li>\n</ul>\n<h1>Reconciliation</h1>\n<p>The Diffing Algorithm</p>\n<ul>\n<li>Diffing : When the state of a component changes React creates a new virtual DOM tree.</li>\n<li>-</li>\n<li>Elements of Different Types</li>\n<li>-</li>\n<li>Every time the root elements have different types, React tears down the old tree and builds the new tree from scratch.</li>\n<li>DOM Elements Of the Same Type</li>\n<li>When comparing two DOM elements of the same type, React keeps the same underlying DOM node and only updates the changes attributes.</li>\n</ul>\n<!---->\n<ul>\n<li>Component Elements Of The Same Type</li>\n<li>-</li>\n<li>When components update, instances will remain the same, so th</li>\n<li>-</li>\n<li>React will only update the props, to match the new element.</li>\n<li>-</li>\n<li>Recursing On Children</li>\n<li>-</li>\n<li>React will iterate both lists of children and generate a mutation whenever there's a</li>\n<li>-</li>\n<li>This is why we use keys.</li>\n<li>Makes it easier for React to match children in the original tree with children in the subsequent tree.</li>\n<li>Tradeoffs</li>\n<li>Important to remember that reconciliation algorithm is an <em>implementation detail</em>.</li>\n<li>Re-rendering only to apply the differences following the rules stated in the previous sections.</li>\n</ul>\n<h1>Typechecking With PropTypes<img src=\"https://miro.medium.com/max/60/0*8ls0PmtREELbf5Wm?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/630/0*8ls0PmtREELbf5Wm\" alt=\"medium blog image\">\n\n\n</h1>\n<ul>\n<li>As your application grows, you can use React's typechecking to catch bugs.</li>\n<li>-</li>\n<li>propTypes is a special property to run typechecking.</li>\n<li>-</li>\n<li>exports range of built in validators to ensure your received data is valid.</li>\n<li>propTypes is only checked in development mode.</li>\n</ul>\n<p>Requiring Single Child</p>\n<ul>\n<li>Use PropTypes.element to specify only a single child can be passed to a component as children.</li>\n</ul>\n<p>Default Prop Values</p>\n<ul>\n<li>Use defaultProps to assign default values for props.</li>\n</ul>\n<h1>Notes</h1>\n<h1>React Router Introduction</h1>\n<ul>\n<li>React Router is the answer for rendering different components for different pages.</li>\n<li>-</li>\n<li>A front-end library that allows you to control whi</li>\n<li>-</li>\n<li>Client-side Routing Getting started with ro</li>\n<li>-</li>\n<li>Install React Router with:</li>\n<li>-</li>\n<li>npm install — save react-rou</li>\n<li>-</li>\n<li>Import Browser Router from package.</li>\n<li>-</li>\n<li>import { BrowserRouter } from \"react-ro</li>\n<li>-</li>\n<li>BrowserRouter is the primary component of the r</li>\n<li>-</li>\n<li>Wrap it around components.</li>\n<li>Creates a React Context that passes routing information down to all its descendant components.</li>\n<li>You can also use HashRouter, where it would generate a hash before the endpoint. Creating frontend routes</li>\n<li>React Router helps your app render specific components based on the URL.</li>\n<li>The most common component is &#x3C;Route></li>\n<li>Wrapped around another component, causing the comp. to only render if the a certain URL is matched.</li>\n<li>Props : path, component, exact, and [render]</li>\n<li>Browser Router can only have a single child component.</li>\n<li>The Browser Router wraps all routes within a parent div element.</li>\n</ul>\n<!---->\n<ul>\n<li>component</li>\n<li>-</li>\n<li>Indica</li>\n<li>-</li>\n<li>path</li>\n<li>-</li>\n<li>Indicate</li>\n<li>-</li>\n<li>exact</li>\n<li>-</li>\n<li>Tells route to not pattern match and only render a certain route exclusively to it's associated component.</li>\n<li>-</li>\n<li>render</li>\n<li>-</li>\n<li>Optional prop that takes in a function to be called.</li>\n<li>Causes extra work for React.</li>\n<li>Preferred for inline rendering of simple functional components.</li>\n<li>Difference between component and render is that component returns new JSX that be re-mounted, but render returns the JSX that will be mounted only once.</li>\n<li>// This inline rendering will work, but is unnecessarily slow. &#x3C;Route path=\"/hello\" component={() => &#x3C;h1>Hello!&#x3C;/h1>} /> // This is the preferred way for inline rendering. &#x3C;Route path=\"/hello\" render={() => &#x3C;h1>Hello!&#x3C;/h1>} /></li>\n<li>Also useful if you need to pass in specific props to a component.</li>\n<li>// `users` to be passed as a prop: const users = { 1: { name: \"Andrew\" }, 2: { name: \"Raymond\" }, }; &#x3C;Route path=\"/users\" render={() => &#x3C;Users users={users} />} />;</li>\n</ul>\n<p>Route path params</p>\n<ul>\n<li>Your component's props can hold information about URL's parameters.</li>\n<li>-</li>\n<li>Will match segments starting at : to the next /, ?, #.</li>\n</ul>\n<!---->\n<ul>\n<li>{...props} spreads out the router's props.</li>\n<li>-</li>\n<li>props.match.params is used to acce</li>\n<li>-</li>\n<li>Useful keys on the mat</li>\n<li>-</li>\n<li>isExact : boolean that tells you whether or not the URL exactly matches the path.</li>\n<li>url : the currentURL</li>\n<li>path : Route path it matched against (w/o wildcards)</li>\n<li>params : Matches for the individual wildcard segments.</li>\n</ul>\n<h1>Navigation</h1>\n<p>React Router Navigation</p>\n<ul>\n<li>Link, NavLink, Redirect, history props of React Router are used to help your user navigate routes. Adding links for navigation</li>\n<li>-</li>\n<li>Issues on-click navigation event to a route defined in app.</li>\n<li>Usage renders an anchor tag with a correctly set href attribute.</li>\n</ul>\n<!---->\n<ul>\n<li>Link takes two properties: to and onClick.</li>\n<li>-</li>\n<li>to : route location that</li>\n<li>-</li>\n<li>onClick : clickHandler.</li>\n<li>-</li>\n<li>NavLink works just l</li>\n<li>-</li>\n<li>Adds extra styling, when the path it links to matches the current path.</li>\n<li>-</li>\n<li>As it's name suggests, it is used to Nav Bars.</li>\n<li>-</li>\n<li>Takes three props:</li>\n<li>-</li>\n<li>activeClassName : allows you to set a CSS class name for styling. (default set to 'active')</li>\n<li>activeStyle : style object that is applied inline when it's to prop. matches the current URL.</li>\n<li>exact prop is a boolean that defaults to false; you can set it to true to apply requirement of an exact URL match.</li>\n<li>exact can also be used as a flag instead of a reg. property value.</li>\n<li>benefit of adding this is so that you don't trigger other matches. Switching between routes</li>\n<li>&#x3C;Switch> : Component allows you to only render one route even if several match the current URL.</li>\n<li>You may nest as many routes as you wish but only the first match of the current URL will be rendered.</li>\n<li>Very useful if we want a default component to render if none of our routes match.</li>\n</ul>\n<!---->\n<ul>\n<li>DefaultComponent will only render if none of the other URLs match up.</li>\n<li>-</li>\n<li>&#x3C;Redirect> : Helps redirect users.</li>\n<li>Only takes a single prop: to.</li>\n</ul>\n<p>History</p>\n<ul>\n<li>History allows you to update the URL programmatically.</li>\n<li>-</li>\n<li>Contains two useful methods:</li>\n<li>-</li>\n<li>push : Adds a new URL to the end of the history stack.</li>\n<li>replace : Replaces the current URL on the history stack, so the back button won't take you to it.</li>\n</ul>\n<h1>Nested Routes</h1>\n<p>Why nested routes?</p>\n<ul>\n<li>Create routes that tunnel into main components vs getting rendered on the main page as it's own thing. What are nested routes?</li>\n</ul>\n<p>Alt. version using props.match</p>\n<ul>\n<li>As you can see above, our end URL isn't even defined until we apply those flexible values in.</li>\n</ul>\n<h1>React Builds</h1>\n<ul>\n<li>Build : Process of converting code into something that can actually execute or run on the target platform.</li>\n<li>-</li>\n<li>In regards to React, the minimum a build should do is convert JSX to something that browsers can understand.</li>\n<li>-</li>\n<li>Linting : Process of using a tool to analyze your code to catch common errors</li>\n<li>-</li>\n<li>Transpilation : Process of converting source code, like JS, from one version to another.</li>\n<li>-</li>\n<li>Minification : Process of removing all unnecessary characters in your code.</li>\n<li>-</li>\n<li>Bundling : Process of combining multiple code files into a single file.</li>\n<li>-</li>\n<li>Tree Shaking : Process of removing unused or dead code from your application before it's bundled. Configuration or code?</li>\n<li>Configuration allows developers to create build tasks by declaring either JSON, XML, or YAML without explicitly writing every step in the process.</li>\n<li>Coding or Scripting simply requires code. Babel and webpack (yes, that's intentionally a lowercase 'w')</li>\n<li>Babel : Code Transpiler that allows you to use all of the latest features and syntax wihtout worrying about what browsers support what.</li>\n<li>webpack : Allows developers to use JS modules w/o requiring users to use a browser that natively supports ES modules.</li>\n<li>Create React App uses webpack and Babel under the hood to build applications. The Create React App build process</li>\n<li>What happens when you run npm start:</li>\n<li>.env variables are loaded.</li>\n<li>list of browsers to support are checked.</li>\n<li>config'd HTTP port checked for availability.</li>\n<li>application compiler is configured and created.</li>\n<li>webpack-dev-starter is started</li>\n<li>webpack-dev-starter compiles app.</li>\n<li>index.html is loaded into browser</li>\n<li>file watcher is started to watch for changes. Ejecting</li>\n<li>There is a script in Create React App called eject that allows you to 'eject' your application and expose all the hidden stuff. Preparing to deploy a React application for production</li>\n<li>-</li>\n<li>Defining Env Variables</li>\n</ul>\n<p>Configuring the supported browsers</p>\n<ul>\n<li>If you specify older browsers it will affect how your code get's transpiled. Creating a production build</li>\n<li>-</li>\n<li>Run npm run build to create a production build.</li>\n<li>Bundles React in production mode and optimizes the build for the best performance.</li>\n</ul>\n<h1>Notes</h1>\n<h1>Introduction to React</h1>\n<ul>\n<li>Simply a nice library that turns data into DOM.</li>\n<li>-</li>\n<li>Tree Diffing : Fast comparison and patching of data by comparing the current virtual DOM and new virtual DOM - updating only the pieces that change.</li>\n<li>It's just a tree with some fancy diffing</li>\n</ul>\n<h1>Create Element</h1>\n<p>From JavaScript To DOM</p>\n<ul>\n<li>The React.createElement function has the following form:</li>\n</ul>\n<!---->\n<ul>\n<li>Type : Type of element to create, i.e. a string for an HTML element or a reference to a function or class that is a React component.</li>\n<li>-</li>\n<li>Props : Object that contains data to render the element.</li>\n<li>-</li>\n<li>Children : Children of the elemet, as many as you want. Creating elements</li>\n<li>Our rendering goal:</li>\n</ul>\n<!---->\n<ul>\n<li>There are five tags to create:</li>\n<li>-</li>\n<li>One ul</li>\n<li>-</li>\n<li>Two li</li>\n<li>-</li>\n<li>Two a</li>\n<li>-</li>\n<li>There are certain attributes</li>\n<li>-</li>\n<li>Each li has a class (or className in React)</li>\n<li>Both a ele's have href attributes</li>\n<li>Also keep in mind the parent child relationships happening between the tags.</li>\n<li>ul is the parent of both li</li>\n<li>Each li has an a element as a child</li>\n<li>Each a has a text content child</li>\n</ul>\n<p>Converting to virtual DOM</p>\n<ul>\n<li>After you set up your React.createElement, you use React.render to take the value returned from cE and a DOM node to insert into the conversion of the real DOM.</li>\n</ul>\n<!---->\n<ul>\n<li>JS Code => Virtual DOM => Real Dom Updates</li>\n<li>-</li>\n<li>If you call React.render a second or multiple times i</li>\n<li>-</li>\n<li>Components are pieces of reusable front-end pieces.</li>\n<li>Components should be Single Responsibility Principle compliant.</li>\n</ul>\n<h1>Create Element</h1>\n<p>React.createElement Demo</p>\n<ul>\n<li>Can import non-local dependencies with import 'package-link'</li>\n</ul>\n<!---->\n<ul>\n<li>Remember when importing modules from other files you have to denote the file type in the import statement. HTML Original</li>\n</ul>\n<p>React Version</p>\n<ul>\n<li>Because class is a reserved keyword in JS, in React we can use className to assign a class to an element.</li>\n<li>-</li>\n<li>Remember the data tha</li>\n<li>-</li>\n<li>props : Properties;</li>\n<li>To handle certain values that are initially undefined, we can use defaultProps.</li>\n</ul>\n<!---->\n<ul>\n<li>You can change in the devTools Network tab the internet speed to check for values that may be undefined to hangle with defaultProps.</li>\n<li>-</li>\n<li>If we fetch multiple pieces of data, we can render many</li>\n<li>-</li>\n<li>You need to assign a unique key to each of the clues.</li>\n<li>We need to keep track of them individually so that React can easily refer to a specific one if there is an issue. clue => { key:clue.id, ...clue }</li>\n</ul>\n<!---->\n<ul>\n<li>Note: JSX is preferred over React.createElement;</li>\n</ul>\n<h1>Notes from Hello Programmer Exercise</h1>\n<ul>\n<li>When you import modules from websites they must have CORs activated.</li>\n<li>-</li>\n<li>These import statements, import global variables.</li>\n<li>When we want to move our code into production we need to change the imports into the production minified versions.</li>\n</ul>\n<!---->\n<ul>\n<li>While we will never actually be creating full apps with just React.createElement => it is the enginer that is running under the hood!</li>\n</ul>\n<h1>Introduction to JSX<img src=\"https://miro.medium.com/max/60/0*NNxuFMF-sOL8Wvdl?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/630/0*NNxuFMF-sOL8Wvdl\" alt=\"medium blog image\">\n\n</h1>\n<ul>\n<li>JSX : Javascript Extension, a new language created by React developers to have an easier way of interacting with the React API. How to use JSX</li>\n<li>-</li>\n<li>We will use babel to convert version of modern JS into an older version of JS. React Create Element</li>\n</ul>\n<p>JSX Version</p>\n<ul>\n<li>Keep in mind that self closing tags in React must have a forward slash to close it.</li>\n</ul>\n<!---->\n<ul>\n<li>Properties and Data</li>\n</ul>\n<!---->\n<ul>\n<li>Comments in JSX have the following syntax:</li>\n</ul>\n<!---->\n<ul>\n<li>Property Names:</li>\n<li>-</li>\n<li>checked : Attribute of input components su</li>\n<li>-</li>\n<li>className : Used to specify a CSS class.</li>\n<li>-</li>\n<li>dangerouslySetInnerHTML : React's equivalent of innerHTML because it is risky to</li>\n<li>-</li>\n<li>htmlFor : Because for is protected keyword, React elements use this instead.</li>\n<li>onChange : Event fired whenever a form field is changed.</li>\n<li>style : Accepts a JS object with camelCase properties rather than a CSS string.</li>\n<li>value : Supported by Input, Select, and TextArea components; use it to set the value of the component.</li>\n<li>Note: React uses camel-case!!! The JSX semicolon gotcha</li>\n</ul>\n<p>create Element equivalent</p>\n<ul>\n<li>We wrap what want to return in parenthesis so JS doesn't auto add semi-colons after every line and run the code incorrectly.</li>\n<li>-</li>\n<li>Just remember if you decided to use the return keyword in a function to 'return some JSX', then make sure you wrap the JSX in parenthesis.</li>\n</ul>\n<p>npx create-react-app my-app</p>\n<ul>\n<li>Single line used to initiate a React application.</li>\n<li>-</li>\n<li>React has a great toolchain where you can see changes live as you</li>\n<li>-</li>\n<li>React errors will be rendered directly onto the browser window.</li>\n<li>A downside is that it installs a lot of bloat files.</li>\n<li>Examples of React create Element and JSX equivalent</li>\n</ul>\n<p>More Complex JSX Example</p>\n<h1>Notes</h1>\n<h1>Using Custom CRA Templates</h1>\n<p>Using a Custom Template npx create-react-app my-app --template @appacademy/simple</p>\n<ul>\n<li>Keep in mind that using create-react-app automatically initializes a git repository for you!</li>\n<li>-</li>\n<li>App Academy custom template for creating a react app.</li>\n<li>-</li>\n<li>If using the</li>\n<li>-</li>\n<li>favicon.ico</li>\n<li>-</li>\n<li>robots.txt</li>\n<li>logo192.png</li>\n<li>logo512.png</li>\n<li>manifest.json</li>\n<li>You can also simplify the html file into:</li>\n</ul>\n<p>Simplifying the src folder</p>\n<ul>\n<li>Remove: App.css App.test.js logo.svg serviceWorker.js setupTests.js</li>\n<li>-</li>\n<li>Update the Following Files:</li>\n</ul>\n<h1>React Class Components</h1>\n<p>Class Components</p>\n<ul>\n<li>You can write React components using ES2015 Classes: Function Component</li>\n</ul>\n<p>ES2015 Version</p>\n<ul>\n<li>We can access props within a class component by using this.props</li>\n<li>-</li>\n<li>Keep in mind Class Components are used just like function components.</li>\n</ul>\n<p>Setting and accessing props</p>\n<ul>\n<li>If we define a constructor method in our Class Component, we have to define the super method with props passed through it.</li>\n<li>-</li>\n<li>Side Note: Before React used ES2015 Classes, it used React.createclass function, if you ever need to use this antiquated method make sure you install a module cal</li>\n<li>-</li>\n<li>One of the major reasons why you would choose to use a Class Component over a</li>\n<li>-</li>\n<li>Second of the major reasons is to be able to use a</li>\n<li>-</li>\n<li>Props are data that are provided by the consumer o</li>\n<li>-</li>\n<li>Not meant to be changed by a component.</li>\n<li>-</li>\n<li>State is data that is internal to the component.</li>\n<li>-</li>\n<li>Intended to be updated or mutated. When to use state</li>\n<li><em>Only Use State when it is absolutely necessary</em></li>\n<li>If the data never changes, or if it's needed through an entire application use props instead.</li>\n<li>State is more often used when creating components that retrieve data from APIs or render forms.</li>\n<li>The general rule of thumb: If a component doesn't need to use state or lifecyle methods, it should be prioritized as a function component.</li>\n<li>Functional:Stateless || Class:Stateful Initializing state</li>\n<li>Use a class constructor method to initialize this.state object. // Application Entry Point</li>\n</ul>\n<p>// Class Component: RandomQuote</p>\n<p>Updating State</p>\n<ul>\n<li>Let's say we want to update our state with a new quote.</li>\n<li>-</li>\n<li>We can set up event listeners in React similarly to how we did them before.</li>\n<li>-</li>\n<li>&#x3C;button type=\"button\" onClick={this.changeQuote}</li>\n<li>-</li>\n<li>onClick is the event listener.</li>\n<li>{this.changeQuote} is the event handler method.</li>\n<li>Our Class Component File should now look like this with the new additions:</li>\n</ul>\n<p>Don't modify state directly</p>\n<ul>\n<li>It is important to never modify your state directly!</li>\n<li>-</li>\n<li>ALWAYS use this.setState method to update state.</li>\n<li>-</li>\n<li>This is because when you only use this.state to re-assign, no re-rendering will occur => leaving our component out of sync. Properly updating state from the previ</li>\n<li>-</li>\n<li>In our current example, the way we have changeQuote set up leaves us with occasionally producing the same index twice in a row.</li>\n<li>One solution is to design a loop but keep in mind that state updates are handled asynchronously in React (your current value is not guaranteed to be the latest)</li>\n<li>A safe method is to pass an anonymous method to this.setState (instead of an object literal) Previous</li>\n</ul>\n<p>Passing w/ Anon Method</p>\n<p>Providing default values for props</p>\n<ul>\n<li>In our current example, we pass in a static array of predefined quotes in our constructor.</li>\n<li>-</li>\n<li>The way it is set up right now leaves our list of quotes unchanged after initialization.</li>\n<li>-</li>\n<li>We can make quotes more dynamic by replacing our static array with a props argument passed into super.</li>\n<li>constructor(props) { super(props); }</li>\n<li>We can now move our quotes array to our application entry point and pass it in as a prop. // Application Entry Point</li>\n</ul>\n<!---->\n<ul>\n<li>One thing to note about this workaround is that the caller of the component <em>must</em> set the quotes prop or the component will throw an error => so use defaultProps!</li>\n</ul>\n<!---->\n<ul>\n<li>A good safety net in case the consumer/caller doesn't provide a value for the quotes array.</li>\n<li>-</li>\n<li>We can even remove it from our index.js now and an error will not be thrown.</li>\n</ul>\n<h1>Handling Events<img src=\"https://miro.medium.com/max/1400/0*c24XQBvqBBg0Eztz\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/1400/0*N7KFfhOZZ7UrY8s4\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/60/0*ywV6dO4a4QcGJxK5?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/630/0*ywV6dO4a4QcGJxK5\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/60/0*Nd73GjTY1PVQtjtQ?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/630/0*Nd73GjTY1PVQtjtQ\" alt=\"medium blog image\">\n\n</h1>\n<ul>\n<li>To add an event listener to an element, just define a method to handle the event and associate that method with the element event you are listening for. Example</li>\n</ul>\n<!---->\n<ul>\n<li>Note that when refering the handler method in onClick we're not invoking showAlert simply just passing a reference. Preventing default behavior</li>\n<li>-</li>\n<li>HTML Elements in the browser often have a lot of default behavior.</li>\n<li>-</li>\n<li>I.E. Clicking on an &#x3C;a> element navigates so a resource denoted by &#x3C;href> property.</li>\n<li>Here is an example of where using e.preventDefault() could come in handy.</li>\n</ul>\n<!---->\n<ul>\n<li>The button contained within the form will end up refreshing the page before this.submitForm method can be completed.</li>\n<li>-</li>\n<li>We can stick an e.preventDefault() into the actual method to get around this problem.</li>\n<li>e : Parameter that references a Synthetic Event object type. Using this in event handlers</li>\n</ul>\n<!---->\n<ul>\n<li>When we console log this we see the AlertButton object.</li>\n<li>-</li>\n<li>If we were to write the showAlert method with a regular class method like:</li>\n</ul>\n<!---->\n<ul>\n<li>We would get undefined => remember that fat arrow binds to the current context! Reviewing class methods and the this keyword</li>\n<li>-</li>\n<li>Let's refresh on binding.</li>\n</ul>\n<!---->\n<ul>\n<li>The first time we use our displayMethod call, it is called directly on the instance of the boyfriend class, which is why Momato Riruru was printed out.</li>\n<li>-</li>\n<li>The second time it was called, the ref of the method is</li>\n<li>-</li>\n<li>Remember we can use the bind method to rebind context!</li>\n<li>-</li>\n<li>We can refactor to get the second call working like this:</li>\n<li>const displayAgain = Ming.displayName.bind(Ming); displayAgain(); // => Now Momato Riruru will be printed out.</li>\n<li>To continue using function declarations vs fat arrow we can assign context in a constructor within a class component.</li>\n</ul>\n<!---->\n<ul>\n<li>Experimental Syntax : Syntax that has been proposed to add to ECMAScript but hasn't officially been added to the language specification yet.</li>\n<li>-</li>\n<li>It's good to pick one approach and use it consistently, either:</li>\n<li>Class Properties &#x26; Arrow Functions</li>\n<li>Bind Method &#x26; This Keyword The SyntheticEvent object</li>\n<li>Synthetic Event Objects: Cross Browser wrappeds around the browser's native event.</li>\n<li>-</li>\n<li>Includes the use of stopPropagation() and preventDefault();</li>\n<li>-</li>\n<li>Attributes of the Synthetic Event Object:Attributesboolean bubblesboolean cancelableDOMEventTarget currentTargetboolean defaultPreventednumber eventPhaseboolean isTrustedDOMEvent nativeEventvoid preventDefault()boolean isDefaultPrevented()void stopPropagation()boolean isPropagationStopped()void persist()DOMEventTarget targetnumber timeStampstring type</li>\n<li>nativeEvent : property defined in a synthetic event object that gives you access to the underlying native browser event (rarely used!)</li>\n</ul>\n<h1>Forms in React</h1>\n<p><em>Exercise being done in a separate file</em> Random Notes</p>\n<ul>\n<li>onChange : detects when a value of an input element changes.</li>\n<li>-</li>\n<li>Assigning onChange to our input fields makes our component's state update in real time during user input.</li>\n<li>-</li>\n<li>Dont forget to add prev</li>\n<li>-</li>\n<li>submittedOn: new Date(), Can be added to a form, most likely will persist into a DB.</li>\n<li>-</li>\n<li>Controlled Components</li>\n<li>We use the onChange event handlers on form fields to keep our component's state as the \"one source of truth\"</li>\n<li>Adding an onChange event handler to every single input can massively bloat your code.</li>\n<li>Try assiging it to it's own method to apply everywhere.</li>\n<li>textarea is handled differently in react: it takes in a value property to handle what the inner text will be.</li>\n</ul>\n<!---->\n<ul>\n<li>We can use validation libraries like validate to make our validation functions more complex.</li>\n</ul>\n<p>Note About Client-side vs server-side validation</p>\n<ul>\n<li>Server-side validation is not optional.</li>\n<li>-</li>\n<li>Tech-savvy users can manipulate client-side validations.</li>\n<li>Sometimes the 'best approach' is to skip implementing validations on the client-side and rely completely on the server-side validation.</li>\n</ul>\n<h1>Component Lifecycle</h1>\n<ul>\n<li>Component Lifecycle is simply a way of describing the key moments in the lifetime of a component.</li>\n<li>Loading (Mounting)</li>\n<li>Updating</li>\n<li>Unloading (Unmounting) The lifecycle of a React component</li>\n<li>Each Class Component has several lifecycle methods that you can add to run code at specific times.</li>\n<li>-</li>\n<li>componentDidMount : Method called after your component has been added to th</li>\n<li>-</li>\n<li>componentDidUpdate : Method called after your component has been updated.</li>\n<li>componentWillUnmount : Method called just before your component is removed from the component tree.</li>\n<li>Mounting</li>\n<li>constructor method is called</li>\n<li>render method is called</li>\n<li>React updates the DOM</li>\n<li>componentDidMount is called</li>\n<li>Updating</li>\n<li>-</li>\n<li>When component receives new props</li>\n<li>render method is called</li>\n<li>React updates the DOM</li>\n<li>componentDidUpdate is called</li>\n<li>When setState is called</li>\n<li>render method is called</li>\n<li>React updates the DOM</li>\n<li>componentDidUpdate is called</li>\n<li>Unmounting</li>\n<li>-</li>\n<li>The moment before a class component is removed from the component tree:</li>\n<li>-</li>\n<li>componentDidMount will be c</li>\n<li>-</li>\n<li>Occasionally you will encoun</li>\n<li>-</li>\n<li>UNSAFE_componentW</li>\n<li>-</li>\n<li>UNSAFE_componentWillReceiveProps</li>\n<li>UNSAFE_componentWillUpdate</li>\n<li>Just know they will be removed soon from React's API, peace. Using the class component lifecycle methods <em>Exercise done in sep. directory</em></li>\n<li>Assorted Notes:</li>\n<li>Common Use for componentDidMount lifecycle method is for fetching data from an API.</li>\n</ul>\n<p>—</p>\n<h1>Notes</h1>\n<h1>React Context</h1>\n<ul>\n<li>You can use React Context to pass data through a component tree without having to manually thread props.</li>\n<li>-</li>\n<li>Convenient way to share &#x26; update global data. Creating a Context</li>\n</ul>\n<!---->\n<ul>\n<li>We use React.createContext to create context.</li>\n<li>-</li>\n<li>Keep in mind if you invoke this method with aruguments, those arguments will be set as default co</li>\n<li>-</li>\n<li>In order to pass context over to child components we need to wrap them in a provider component.</li>\n<li>The provider component takes in a value property that points to the information that needs to be passed to the children.</li>\n</ul>\n<p>Setting up a Consumer</p>\n<ul>\n<li>Keep in mind that Context.Consumer expects a function as a child.</li>\n<li>-</li>\n<li>The function has a value prop passed in from Context.Provider</li>\n</ul>\n<h1>Notes</h1>\n<h1>Redux Explained</h1>\n<ul>\n<li>JS Framework for managing the frontend state of a web application.</li>\n<li>-</li>\n<li>Gives u</li>\n<li>-</li>\n<li>Redux</li>\n<li>-</li>\n<li>Client Side Data Mana</li>\n<li>-</li>\n<li>Controls \"Frontend State\"</li>\n<li>NOT Your Database</li>\n<li>NOT Component State</li>\n<li>Just used for managing Data</li>\n</ul>\n<!---->\n<ul>\n<li>Visual of how an app without React manages it's data.</li>\n<li>-</li>\n<li>A lot of prop threading happening.</li>\n<li>-</li>\n<li>Data stored in a sep. loca</li>\n<li>-</li>\n<li>Store</li>\n<li>-</li>\n<li>Holds the Frontend State</li>\n<li>-</li>\n<li>Provides an</li>\n<li>-</li>\n<li>Action</li>\n<li>POJOs</li>\n<li>Outline Changes to Frontend State</li>\n<li>Reducers</li>\n<li>Functions</li>\n<li>Make Changes to Frontend State Where did Redux come from?</li>\n<li>There are three central philosophies of Redux:</li>\n<li>A Single Source of Truth : state is stored in a POJO</li>\n<li>State is Read Only : State is immutable, modified by dispatching actions.</li>\n<li>Changes are Made with Pure Functions : Reducers that receive the actions and return updated state are pure functions of the old state and action. When is it appropriate to use Redux?</li>\n<li>When doing a project with simpler global state requirements, it may be better to choose React's Context API over Redux.</li>\n<li>-</li>\n<li>Redux o</li>\n<li>-</li>\n<li>State</li>\n<li>-</li>\n<li>_Redux</li>\n<li>-</li>\n<li>State is all the information stored by that program at a particular point i</li>\n<li>-</li>\n<li>Redux's m</li>\n<li>-</li>\n<li>Store</li>\n<li>-</li>\n<li><em>Redux stores state in a single store</em>.</li>\n<li>-</li>\n<li>Redux store is a single JS object wit</li>\n<li>-</li>\n<li>Methods include: getState, dispatch(action), and s</li>\n<li>-</li>\n<li>Actions</li>\n<li>-</li>\n<li>_Redux store is updated by dispatching</li>\n<li>-</li>\n<li>Action is ju</li>\n<li>-</li>\n<li>Contain info to update the store.</li>\n<li>-</li>\n<li>We dispatch actions in res</li>\n<li>-</li>\n<li>Pure Functions</li>\n<li>-</li>\n<li><em>Redux Reducers are Pure Functions</em></li>\n<li>-</li>\n<li>Functions are pure when their behavior depends only on it's arguments as has no side effects.</li>\n<li>Simply takes in an argument and outputs a value.</li>\n<li>Reducer</li>\n<li><em>Redux handles actions using reducers</em></li>\n<li>A function that is called each time an action is dispatched.</li>\n<li>Takes in an action and current state</li>\n<li>Required to be pure functions so their behavior is predictable.</li>\n<li>Middleware</li>\n<li><em>Customize response to dispatch actions by using Middleware</em></li>\n<li>Middleware is an optional component of Redus that allows custom responses to dispatched actions.</li>\n<li>Most common use is to dispatch async requests to a server.</li>\n<li>Time Traveling Dev Tools</li>\n<li><em>Redux can time travel wow</em></li>\n<li>Time travel refers to Redux's ability to revert to a previous state because reducers are all pure functions.</li>\n<li>Thunks</li>\n<li><em>Convenient format for taking async actions in Redux</em></li>\n<li>General concept in CS referring to a function who's primary purpose is to call another function.</li>\n<li>Most commonly used to make async API requests.</li>\n</ul>\n<h1>Flux and Redux</h1>\n<p>What is Flux?</p>\n<ul>\n<li>Front-end application architecutre.</li>\n<li>-</li>\n<li>A pattern in which to structure an application.</li>\n<li>-</li>\n<li>Unidirectional Data Flow — offers more predictability.</li>\n<li>-</li>\n<li>Actions : Begins the data flow of data, simple object that contains a type; type indicates the type of change to be performed.</li>\n<li>Dispatcher : Mechanism for distributing actions to the store.</li>\n<li>Store : The entire state of the application, responsible for updating the state of your app.</li>\n<li>View : Unit of code that's responsible for rendering the user interface. Used to re-render the application when actions and changes occur.</li>\n</ul>\n<!---->\n<ul>\n<li>Redux</li>\n</ul>\n<!---->\n<ul>\n<li>Library that facilitates the implementation of Flux.</li>\n<li>-</li>\n<li>Redux Three Principles</li>\n<li>-</li>\n<li>Single Source of Truth</li>\n<li>State is Read-Only</li>\n<li>Only Pure Functions Change State</li>\n</ul>\n<h1>Store</h1>\n<ul>\n<li>Simply an object that holds the application state wrapped in an API.</li>\n<li>-</li>\n<li>Three methods:</li>\n<li>-</li>\n<li>getState() : Returns the store's current state.</li>\n<li>dispatch(action) : Passes an action into the store's reducer to tell it what info to update.</li>\n<li>subscribe(callback) : Registers a callback to be triggered whenever the store updates. Updating the Store</li>\n</ul>\n<p>Subscribing to the store</p>\n<ul>\n<li>Whenever a store process a dispatch(), it triggers all its subscribers.</li>\n<li>-</li>\n<li>Subscribers : callbacks that can be added to the store via subscribe().</li>\n</ul>\n<p>Reviewing a simple example</p>\n<h1>Reducers\n\n\n</h1>\n<ul>\n<li>Reducer function receives the current state and action, updates the state appropriately based on the action.type and returns the following state.</li>\n<li>-</li>\n<li>You can bundles different action types and ensuing logic by using a switch/case statement.</li>\n</ul>\n<p>Reviewing how Array#slice works</p>\n<ul>\n<li>Approach that can be used to remove an element without mutating the original array. Avoiding state mutations</li>\n<li>-</li>\n<li>Your reducer must always return a new object if the state changes. GOOD</li>\n</ul>\n<p>BAD</p>\n<h1>Actions</h1>\n<ul>\n<li>Actions are the only way to trigger changes to the store's state. Using action creators</li>\n</ul>\n<!---->\n<ul>\n<li>fruit is the payload key and orange is the state data</li>\n<li>-</li>\n<li>Action Creators : Functions created from extrapolating the creation of an action object.</li>\n</ul>\n<!---->\n<ul>\n<li>Use parenthesis for implicit return value.</li>\n<li>-</li>\n<li>We can now add whatever fruit we'd like.</li>\n</ul>\n<p>Preventing typos in action type string literals</p>\n<ul>\n<li>Using constant variables helps reduce simple typos in a reducer's case clauses.</li>\n</ul>\n<h1>Debugging Arrow Functions</h1>\n<ul>\n<li>It is important to learn how to use debugger statements with arrow functions to effectively debug Redux cycle. Understanding the limitations of implicit return values</li>\n</ul>\n<!---->\n<ul>\n<li>You must use explicit return statement arrow function to use a debugger.</li>\n</ul>\n<h1>React Router Introduction</h1>\n<p>Now that you know how to render components in a React app, how do you handle rendering different components for different website pages? React Router is the answer!</p>\n<p>Think of how you have created server-side routes in Express. Take the following URL and server-side route. Notice how the /users/:userId path corresponds with the <a href=\"http://localhost:3000/users/2\">http://localhost:3000/users/2</a> URL to render a specific HTML page.</p>\n<p>In the default React setup, you lose the ability to create routes in the same manner as in Express. This is what React Router aims to solve!</p>\n<p><a href=\"https://github.com/ReactTraining/react-router\">React Router</a> is a frontend routing library that allows you to control which components to display using the browser location. A user can also copy and paste a URL and email it to a friend or link to it from their own website.</p>\n<p>When you finish this article, you should be able to use the following from the react-router-dom library:</p>\n<ul>\n<li>&#x3C;BrowserRouter> to provide your application access to the react-router-dom library; and</li>\n<li>-</li>\n<li>&#x3C;Route> to connect specific URL paths to specific components you want rendered; and</li>\n<li>-</li>\n<li>&#x3C;Switch> to wrap several Route elements, rendering only one even if several match the current URL; and</li>\n<li>React Router's match prop to access route path parameters.</li>\n</ul>\n<h1>Getting started with routing</h1>\n<p>Since you are writing single page apps, you don't want to refresh the page each time you change the browser location. Instead, you want to update the browser location and your app's response using JavaScript. This is known as client-side routing. You are using React, so you will use React Router to do this.</p>\n<p>Create a simple react project template:</p>\n<p>Then install React Router:</p>\n<p>Now import BrowserRouter from react-router-dom in your entry file:</p>\n<h1>BrowserRouter</h1>\n<p>BrowserRouter is the primary component of the router that wraps your route hierarchy. It creates a React context that passes routing information down to all its descendent components. For example, if you want to give &#x3C;App> and all its children components access to React Router, you would wrap &#x3C;App> like so:</p>\n<p>Now you can route the rendering of certain components to certain URLs (i.e <a href=\"https://www.website.com/profile).\">https://www.website.com/profile</a><a href=\"https://www.website.com/profile).\">).</a></p>\n<h1>HashRouter</h1>\n<p>Alternatively, you could import and use HashRouter from react-router-dom. Links for applications that use &#x3C;HashRouter> would look like <a href=\"https://www.website.com/#/profile\">https://www.website.com/#/profile</a> (with an # between the domain and path).</p>\n<p>You'll focus on using the &#x3C;BrowserRouter>.</p>\n<h1>Creating frontend routes</h1>\n<p>React Router helps your React application render specific components based on the URL. The React Router component you'll use most often is &#x3C;Route>.</p>\n<p>The &#x3C;Route> component is used to wrap another component, causing that component to only be rendered if a certain URL is matched. The behavior of the &#x3C;Route> component is controlled by the following props: path, component, exact, and render (optional).</p>\n<p>Create a simple Users component that returns &#x3C;h1>This is the users index!&#x3C;/h1>. Now let's refactor your index.js file so that you can create your routes within the component:</p>\n<p>Note that BrowserRouter can only have a single child component, so the snippet above wraps all routes within parent a &#x3C;div> element. Now let's create some routes!</p>\n<h1>component</h1>\n<p>Begin with the component prop. This prop takes a reference to the component to be rendered. Let's render your App component:</p>\n<p>Now you'll need to connect a path to the component!</p>\n<h1>path</h1>\n<p>The wrapped component will only be rendered when the path is matched. The path matches the URL when it matches some initial portion of the URL. For example, a path of / would match both of the following URLs: / and /users. (Because /users begins with a / it matches the path /)</p>\n<p>Take a moment to navigate to <a href=\"http://localhost:3000/users\">http://localhost:3000/users</a> to see how both the App component and Users component are rendering.</p>\n<h1>exact</h1>\n<p>If this exact flag is set, the path will only match when it exactly matches the URL. Then browsing to the /users path would no longer match / and only the Users component will be rendered (instead of both the App component and Users component).</p>\n<h1>render</h1>\n<p>This is an optional prop that takes in a function to be called. The function will be called when the path matches. The function's return value is rendered. You could also define a functional component inside the component prop, but this results in extra, unnecessary work for React. The render prop is preferred for inline rendering of simple functional components.</p>\n<p>The difference between using component and render is that component returns new JSX to be re-mounted every time the route renders, while render simply returns to JSX what will be mounted once and re-rendered. For any given route, you should only use either the component prop, or the render prop. If both are supplied, only the component prop will be used.</p>\n<p>It can be helpful to use render instead of component in your &#x3C;Route> when you need to pass props into the rendered component. For example, imagine that you needed to pass the users object as a prop to your Users component. Then you could pass in props from Root to Users by returning the Users component like so:</p>\n<p>As a reminder, BrowserRouter can only have a single child component. That's why you have wrapped all your routes within parent a &#x3C;div> element.</p>\n<p>With this Root component, you will always render the &#x3C;h1>Hi, I'm Root!&#x3C;/h1>, regardless of the path. Because of the first &#x3C;Route>, you will only render the App component if the path exactly matches /. Because of the second &#x3C;Route>, you will only render the Users component if the path matches /users.</p>\n<h1>Route path params</h1>\n<p>A component's props can also hold information about a URL's parameters. The router will match route segments starting at : up to the next /, ?, or #. Those matched values are then passed to components via their props. Such segments are <em>wildcard</em> values that make up your route parameters.</p>\n<p>For example, take the route below:</p>\n<p>The router would break down the full /users/:userId/photos path to two parts: /users, :userId.</p>\n<p>The Profile component's props would have access to the :userId part of the <a href=\"http://localhost:3000/users/:userId/photos\">http://localhost:3000/users/:userId/photos</a> URL through the props with router parameter information. You would access the the match prop's parameters (props.match.params). If you are using the render prop of the Route component, make sure to spread the props back into the component if you want it to know about the \"match\" parameters.</p>\n<p>The params object would then have a property of userId which would hold the value of the :userId <em>wildcard</em> value. Let's render the userId parameter in a user profile component. Take a moment to create a Profile.js file with the following code:</p>\n<p>Notice how it uses the match prop to access the :userId parameter from the URL. You can use this wildcard to make and AJAX call to fetch the user information from the database and render the return data in the Profile component. Recall that your Profile component was rendered at the path /users/:userId. Thus you can use your userId parameters from match.params to fetch a specific user:</p>\n<h1>Match</h1>\n<p>Now that you've seen your React Router's match prop in action, let's go over more about <a href=\"https://reacttraining.com/react-router/web/api/Route/route-props\">route props</a>! React Router passes information to the components as route props, accessible to all components with access to the React Router. The three props it makes available are location, match and history. You've learned about props.match.params, but now let's review the other properties of the match prop!</p>\n<p>This is an object that contains important information about how the current URL matches the route path. Here are some of the more useful keys on the match object:</p>\n<ul>\n<li>isExact: a boolean that tells you whether or not the URL exactly matches the path</li>\n<li>-</li>\n<li>url: the current URL</li>\n<li>-</li>\n<li>path: the route path it matched against (without wildcards filled in)</li>\n<li>params: the matches for the individual wildcard segments, nested under their names</li>\n</ul>\n<p>When you use React Router, the browser location and history are a part of the state of your app. You can store information about which component should be displayed, which user profile you are currently viewing, or any other piece of state, in the browser location. You can then access that information from anywhere your Router props are passed to in your app.</p>\n<p>Now that you've learned about parameters and route props, let's revisit your Root component to add an exact flag to your /users route so that it does not render with your /users/:userId route. Your component should look something like this:</p>\n<h1>What you learned</h1>\n<p>In this article, you learned how to:</p>\n<ul>\n<li>Use components from the React Router library; and</li>\n<li>-</li>\n<li>Create routes to render specific component</li>\n<li>-</li>\n<li>Manage the order of rendered routes; and</li>\n<li>Use the exact flag to ensure that a specific path renders a specific component; and</li>\n<li>Use the React Router match prop to access Router params.</li>\n</ul>\n<h1>React Router Navigation</h1>\n<p>Now that you know how to create front-end routes with React Router, you'll need to implement a way for your users to navigate the routes! This is what using React Router's Link, NavLink, Redirect, and history prop can help you do.</p>\n<p>In this article, you'll be working off of the demo project you built in the React Router Intro reading. When you finish this article, you should be able to use the following components from the react-router-dom library:</p>\n<ul>\n<li>&#x3C;Link> or &#x3C;NavLink> to create links with absolute paths to routes in your application (like \"/users/1\"); and,</li>\n<li>-</li>\n<li>&#x3C;Redirect> to redirect a user to another path (i.e. a login page when the user is not logged in); and</li>\n<li>React Router's history prop to update a browser's URL programmatically.</li>\n</ul>\n<h1>Adding links for navigation</h1>\n<p>React Router's &#x3C;Link> is one way to simplify navigation around your app. It issues an on-click navigation event to a route defined in your app's router. Using &#x3C;Link> renders an anchor tag with a correctly set href attribute.</p>\n<h1>Link</h1>\n<p>To use it, update your imports from the react-router-dom package to include Link:</p>\n<p>Note that &#x3C;Link> can take two props: to and onClick.</p>\n<p>The to prop is a route location description that points to an absolute path, (i.e. /users). Add the following Link components in your index.js file above your routes:</p>\n<p>The onClick prop is just like any other JSX click handler. You can write a function that takes in an event and handles it. Add the following Link before your routes and the following click handler function within your Root component:</p>\n<p>Now, test your routes and links! If you inspect the page, you'll see that your links are now rendered as &#x3C;a> elements. Notice that clicking the App with click handler link logs a message in your console while directing your browser to render the App component.</p>\n<h1>NavLink</h1>\n<p>The &#x3C;NavLink> works just like a &#x3C;Link>, but with a little extra functionality. It has the ability to add extra styling when the path it links to matches the current path. This makes it an ideal choice for a navigation bar, hence the name. This styling can be controlled by three extra props: activeClassName, activeStyle, and exact. To begin using NavLink, update your imports from the react-router-dom package:</p>\n<p>The activeClassName prop of the NavLink component allows you to set a CSS class name for styling the NavLink when its route is active. By default, the activeClassName is already set to active. This means that you simply need to add an .active class to your CSS file to add active styling to your link. A NavLink will be active if its to prop path matches the current URL.</p>\n<p>Let's change your \"Users\", \"Hello\", and \"Andrew's Profile\" links to be different colors and have a larger font size when active.</p>\n<p>For example, this is what the rendered HTML &#x3C;a> tag would look like when when the browser is navigated to the / path or the /users path:</p>\n<p>Import NavLink into your index.js file and take a moment to update all your Link elements to NavLink elements. Set an activeClassName prop to an active class. Add the following .active class to your index.css file:</p>\n<p>Test your styled links! Notice how the App and App with click handler links are always bolded. This is because all of your links include the / path, meaning that the link to / will be active when browsing to /users and /users/1 because of how users and users/1 are both prefaced by a /.</p>\n<p>The activeStyle prop is a style object that will be applied inline to the NavLink when its to prop matches the current URL. Add the following activeStyle to your App link and comment out the .active class in your CSS file.</p>\n<p>The following html is rendered when at the / path:</p>\n<p>Notice how your App with click handler is not bolded anymore. This is because the default active class being applied does not have any CSS stylings set to the class. Uncomment your .active class in your CSS file to bring back bolding to this NavLink.</p>\n<p>The exact prop is a boolean that defaults to false. If set to true, then the activeStyle and activeClassName props will only be applied when the current URL exactly matches the to prop. Update your App and App with click handler links with an exact prop set. Just like in your routes, you can use the exact flag instead of exact={true}.</p>\n<p>Now your App and App with click handler links will only be bolded when you have navigated precisely to the / path.</p>\n<h1>Switching between routes</h1>\n<p>You came across styling issues when the /users and /users/1 paths matched the / path. Routing can have this issue as well. This is why you need to control the switching between routes.</p>\n<p>React Router's &#x3C;Switch> component allows you to only render one &#x3C;Route> even if several match the current URL. You can nest as many Routes as you wish between the opening and closing Switch tags, but only the first one that matches the current URL will be rendered.</p>\n<p>This is particularly useful if you want a default component that will only render if none of our other routes match. View the example below. Without the Switch, DefaultComponent would always render. Since there isn't set a path in the DefaultComponent route, it will simply use the default path of /. Now the DefaultComponent will only render when neither of the preceding routes match.</p>\n<p>Import Switch from react-router-dom and add &#x3C;Switch> tags around your routes to take care of ordering and switching between your routes! Begin by adding the following route to the bottom of your routes to render that a 404: Page not found message:</p>\n<p>This is what your Root component should look like at this point:</p>\n<p>Now you have control over the precedence of rendered components! Try navigating to <a href=\"http://localhost:3000/asdf\">http://localhost:3000/asdf</a> or any other route you have not defined. The &#x3C;h1>404: Page not found&#x3C;/h1> JSX of the last &#x3C;Route> will be rendered whenever the browser attempts to visit an undefined route.</p>\n<h1>Redirecting users</h1>\n<p>But what if you want to redirect users to a login page when they aren't logged in? The &#x3C;Redirect> component from React Router helps you redirect users!</p>\n<p>The component takes only one prop: to. When it renders, it replaces the current URL with the value of its to prop. Typically you conditionally render &#x3C;Redirect> to redirect the user away from some page you don't want them to visit. The example below checks whether there is a defined currentUser prop. If so, the &#x3C;Route> will render the Home component. Otherwise, it will redirect the user to the /login path.</p>\n<p>Note: you will learn how to use a more flexible auth pattern — don't directly imitate this example.</p>\n<h1>History</h1>\n<p>You know how to redirect users with a &#x3C;Redirect> component, but what if you need to redirect users programmatically? You've learned about the React Router's match prop, but now let's go over another one of the <a href=\"https://reacttraining.com/react-router/web/api/Route/route-props\">route props</a>: history!</p>\n<p>This prop lets you update the URL programmatically. For example, suppose you want to push a new URL when the user clicks a button. It has two useful methods:</p>\n<ul>\n<li>push - This adds a new URL to the end of the history stack. That means that clicking the back button will take the browser to the previous URL. Note that pushing the same URL multiple times in a row will have no effect; the URL will still only show up on the stack once. In development mode, pushing the same URL twice in a row will generate a console warning. This warning is disabled in production mode.</li>\n<li>-</li>\n<li>replace - This replaces the current URL on the history stack, so the back button won't take you to it. For example:</li>\n</ul>\n<h1>What you learned</h1>\n<p>In this article, you learned how to:</p>\n<ul>\n<li>Create navigation links for your route paths; and</li>\n<li>-</li>\n<li>Redirect users through using the &#x3C;Redirect> component; and</li>\n<li>Update a browser's URL programmatically by using React Router's history prop.</li>\n</ul>\n<h1>React Router Nested Routes<img src=\"https://miro.medium.com/max/60/0*233dNJ6vfgAmEVCD?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/576/0*233dNJ6vfgAmEVCD\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/60/0*TKBUkpbL5aSm5PTQ?q=20\" alt=\"medium blog image\"><img src=\"https://miro.medium.com/max/630/0*TKBUkpbL5aSm5PTQ\" alt=\"medium blog image\">\n\n</h1>\n<p>Now you know how to create front-end routes and add navigation with React Router. When initializing Express projects, you declare static routes. Static routes are routes that are declared when an application is initialized. When using React Router in your application's initialization, you can declare dynamic routes. React Router introduces dynamic routing, where your routes are created as your application is rendering. This allows you to create nested routes within components!</p>\n<p>In this article, let's dive into <a href=\"https://reacttraining.com/react-router/core/guides/philosophy/nested-routes\">nested routes</a>! When you finish the article, you should:</p>\n<ul>\n<li>Describe what nested routes are; and</li>\n<li>-</li>\n<li>Be able to use React Router to create and navigate nested routes; and</li>\n<li>Know how to use the React Router match prop to generate links and routes.</li>\n</ul>\n<h1>Why nested routes?</h1>\n<p>Let's begin with why you might need nested routes. As you remember, you are using React to create a single-page application. This means that you'll be organizing your application into different components and sub-components.</p>\n<p>For example, imagine creating a simple front-end application with three main pages: a home welcome page (path of /), a users index page (path of /users), and user profile pages (path of /users/:userId). Now imagine if every user had links to separate posts and photos pages.</p>\n<p>You can create those routes and links within the user profile component, instead of creating the routes and links where the main routes are defined.</p>\n<h1>What are nested routes?</h1>\n<p>Now let's dive into a user profile component to understand what are nested routes! Imagine you have a route in your application's entry file to each user's profile like so:</p>\n<p>This means that upon navigating to <a href=\"http://localhost:3000/users/1\">http://localhost:3000/users/1</a>, you would render the following Profile component and the userId parameter within props.match.params would have the value of \"1\".</p>\n<p>Since this route is not created until the Profile component is rendered, you are dynamically creating your nested /users/:userId/posts and /users/:userId/photos routes. Remember that your match prop also has other helpful properties. You can use match.url instead of /users/${id} in your profile links. You can also use match.path instead of /users/:userId in your profile routes. Remember that you can destructure url, path, and params from your match prop!</p>\n<p>In tomorrow's project, you'll build a rainbow of routes as well as define nested routes. In the future, you may choose to implement nested routes to keep your application's routes organized within related components.</p>\n<h1>What you learned</h1>\n<p>In this article, you learned:</p>\n<ul>\n<li>What nested routes are; and</li>\n<li>-</li>\n<li>About creating and navigating nested routes with React Router; and</li>\n<li>How to use the React Router props to generate nested links and routes.</li>\n</ul>\n<h1>React Builds</h1>\n<p>A \"build\" is the process of converting code into something that can actually execute or run on the target platform. A \"front-end build\" is a process of preparing a front-end or client-side application for the browser.</p>\n<p>With React applications, that means (at a minimum) converting JSX to something that browsers can actually understand. When using Create React App, the build process is automatically configured to do that and a lot more.</p>\n<p>When you finish this article, you should be able to:</p>\n<ul>\n<li>Describe what front-end builds are and why they're needed;</li>\n<li>-</li>\n<li>Describe at a high level what happens in a Create React App when you run npm start; and</li>\n<li>Prepare to deploy a React application into a production environment.</li>\n</ul>\n<h1>Understanding front-end builds</h1>\n<p>The need for front-end builds predates React. Over the years, developers have found it helpful to extend the lowest common denominator version of JavaScript and CSS that they could use.</p>\n<p>Sometimes developers extend JavaScript and CSS with something like <a href=\"https://www.typescriptlang.org/\">TypeScript</a> or <a href=\"https://sass-lang.com/\">Sass</a>. Using these non-standard languages and syntaxes require you to use a build process to convert your code into standard JavaScript and CSS that can actually run in the browser.</p>\n<p>Browser-based applications also require a fair amount of optimization to deliver the best, or at least acceptable, experience to end users. Front-end build processes could be configured to lint code, run unit tests, optimize images, minify and bundle code, and more — all automatically at the press of a button (i.e. running a command at the terminal).</p>\n<h1>JavaScript versions and the growth of front-end builds</h1>\n<p>Developers are generally an impatient lot. When new features are added to JavaScript, we don't like to wait for browsers to widely support those features before we start to use them in our code. And we <em>really</em> don't like when we have to support older, legacy versions of browsers.</p>\n<p>In recent years, JavaScript has been updated on a yearly basis and browser vendors do a decent job of updating their browsers to support the new features as they're added to the language. Years ago though, there was an infamous delay between versions 5 and 6 of JavaScript. It took <em>years</em> before ES6 (or ES2015 as it eventually was renamed to) to officially be completed and even longer before browsers supported all of its features.</p>\n<p>In the period of time before ES2015 was broadly supported by browsers, developers used front-end builds to convert or <em>transpile</em> ES2015 features and syntax to an older version of the language that was more broadly supported by browsers (typically ES5). The transpilation from ES2015/ES6 down to ES5 was one of the major drivers for developers to add front-end builds to their client-side projects.</p>\n<h1>Reviewing common terminology</h1>\n<p>When learning about front-end or React builds, you'll encounter a lot of terminology that you may or may not be familiar with. Here's some of the terminology that you'll likely encounter:</p>\n<p>Linting is process of using a tool to analyze your code to catch common programming errors, bugs, stylistic inconsistencies, and suspicious coding patterns. <a href=\"https://eslint.org/\">ESLint</a> is a popular JavaScript linting tool.</p>\n<p>Transpilation is the process of converting source code, like JavaScript, from one version to another version. Usually this means converting newer versions of JavaScript, <a href=\"https://www.ecma-international.org/ecma-262/10.0/index.html\">ES2019</a> or <a href=\"https://tc39.es/ecma262/\">ES2021</a>, to a version that's more widely supported by browsers, like <a href=\"http://www.ecma-international.org/ecma-262/6.0/\">ES2015</a>, or even <a href=\"https://www.ecma-international.org/ecma-262/5.1/\">ES5</a> or <a href=\"https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf\">ES3</a> (if you need to support the browser that your parents or grandparents use).</p>\n<p>Minification is the process of removing all unnecessary characters in your code (e.g. white space characters, new line characters, comments) to produce an overall smaller file. Minification tools will often also rename identifers in your code (i.e. parameter and variable names) in the quest for smaller and smaller file sizes. Source maps can also be generated to allow debugging tools to cross reference between minified code and the original source code.</p>\n<p>Bundling is the process of combining multiple code files into a single file. Creating a bundle (or a handful of bundles) reduces the number of requests that a client needs to make to the server.</p>\n<p>Tree shaking is the process of removing unused (or dead) code from your application before it's bundled. Tree shaking external dependencies can sometimes have a dramatic positive impact on overall bundled file sizes.</p>\n<h1>Configuration or code?</h1>\n<p>Front-end build tools have come and gone over the years; sometimes very quickly, which helped bring about the phenomenon known as <a href=\"https://sdtimes.com/softwaredev/is-the-javascript-fatigue-real/\">JavaScript fatigue</a>.</p>\n<p>Configuration based tools allow you to create your build tasks by declaring (usually using JSON, XML, or YAML) what you want to be done, without explicitly writing every step in the process. In contrast, coding or scripting based tools allow you to, well, write code to create your build tasks. Configuration based tools <em>can</em> sometimes feel simpler to use while giving up some control (at least initially) while coding based tools <em>can</em> feel more familiar and predictable (since you're describing tasks procedurally). Every generalization is false though (including this one), so there are plenty of exceptions.</p>\n<p><a href=\"https://gruntjs.com/\">Grunt</a> is a JSON configuration based task runner that can be used to orchestrate the various tasks that make up your front-end build. Grunt was very quickly supplanted by <a href=\"https://gulpjs.com/\">Gulp</a>, which allowed developers to write JavaScript to define front-end build tasks. After Gulp, the front-end tooling landscape became a bit more muddled. Some developers preferred the simplicity of using <a href=\"https://docs.npmjs.com/misc/scripts\">npm scripts</a> to define build tasks while others preferred the power of configuration based bundlers like <a href=\"https://webpack.js.org/\">webpack</a>.</p>\n<h1>Babel and webpack (yes, that's intentionally a lowercase 'w')</h1>\n<p>As front-end or client-side applications grew in complexity, developers found themselves wanting to leverage more advanced JavaScript features and newer syntax like classes, arrow functions, destructuring, async/await, etc. Using a code transpiler, like <a href=\"https://babeljs.io/\">Babel</a>, allows you to use all of the latest and greatest features and syntax without worrying about what browsers support what.</p>\n<p>Module loaders and bundlers, like <a href=\"https://webpack.js.org/\">webpack</a>, also allowed developers to use JavaScript modules without requiring users to use a browser that natively supports ES modules. Also, module bundling (along with minification and tree-shaking) helps to reduce the bandwidth that's required to deliver the assets for your application to the client.</p>\n<p>[Create React App][cra] uses webpack (along with Babel) under the covers to build your React applications. Even if you're not using Create React App, webpack and Babel are still very popular choices for building React applications.</p>\n<h1>Pulling back the covers (a bit) on the Create React App build process</h1>\n<p>Running an application created by Create React App using npm start can feel magical. Some stuff happens in the terminal and your application opens into your default browser. Even better, when you make changes to your application, your changes will (usually) automatically appear in the browser!</p>\n<h1>The Create React App build process</h1>\n<p>At a high level, here's what happens when you run npm start:</p>\n<ul>\n<li>Environment variables are loaded (more about this in a bit);</li>\n<li>-</li>\n<li>The list of browsers to support are checked (more about this too in</li>\n<li>-</li>\n<li>The configured HTTP port is checked to ensure that it's available;</li>\n<li>-</li>\n<li>The application compiler is configured and created;</li>\n<li>-</li>\n<li><a href=\"https://webpack.js.org/configuration/dev-server/\">webpack-dev-server</a> is started;</li>\n<li><a href=\"https://webpack.js.org/configuration/dev-server/\">webpack-dev-server</a> compiles your application;</li>\n<li>The index.html file is loaded into the browser; and</li>\n<li>A file watcher is started to watch your files, waiting for changes.</li>\n</ul>\n<h1>Ejecting</h1>\n<p>Create React App provides a script that you can run to \"eject\" your application from the Create React App tooling. When you eject your application, all of the hidden stuff is exposed so that you can review and customize it.</p>\n<blockquote>\n<p><em>The need to customize Create React App rarely happens. Also, don't eject an actual project as it's a one-way trip! Once a Create React App project has been ejected, there's no going back (though you could always undo the ejection process by reverting to an earlier commit if you're using source control).</em></p>\n</blockquote>\n<p>To eject your application from Create React App, run the command npm run eject. You'll be prompted if you want to continue; type \"y\" to continue with the ejection process. Once the ejection process has completed, you can review the files that were previously hidden from you.</p>\n<p>In the package.json file, you'll see the following npm scripts:</p>\n<p>You can open the ./scripts/start.js file to see the code that's executed when you run npm start.</p>\n<p>If you're curious about the webpack configuration, you can open and review the ./config/webpack.config.js.</p>\n<h1>Preparing to deploy a React application for production</h1>\n<p>Before you deploy your application to production, you'll want to make sure that you've replaced static values in your code with environment variables and considered what browsers you need to support.</p>\n<h1>Defining environment variables</h1>\n<p>Create React App supports defining environment variables in an .env file. To define an environment variable, add an .env file to your project and define one or more variables that start with the prefix REACT<em>APP\\</em>:</p>\n<p>Environment variables can be used in code like this:</p>\n<p>You can also reference environment variables in your index.html like this:</p>\n<blockquote>\n<p><em>Important: Environment variables are embedded into your HTML, CSS, and JavaScript bundles during the build process. Because of this, it's very important to not store any secrets, like API keys, in your environment variables as anyone can view your bundled code in the browser by inspecting your files.</em></p>\n</blockquote>\n<h1>Configuring the supported browsers</h1>\n<p>In your project's package.json file, you can see the list of targeted browsers:</p>\n<p>Adjusting these targets affect how your code will be transpiled. Specifying older browser versions will result in your code being transpiled to older versions of JavaScript in order to be compatible with the specified browser versions. The production list specifies the browsers to target when creating a production build and the development list specifics the browsers to target when running the application using npm start.</p>\n<p>The <a href=\"https://browserl.ist/\">browserl.ist</a> website can be used to see the browsers supported by your configured browserslist.</p>\n<h1>Creating a production build</h1>\n<p>To create a production build, run the command npm run build. The production build process bundles React in production mode and optimizes the build for the best performance. When the command completes, you'll find your production ready files in the build folder.</p>\n<p>Now your application is ready to be deployed!</p>\n<blockquote>\n<p><em>For more information about how to deploy a Create React App project into production, see _[</em>this page<em>](<a href=\"https://facebook.github.io/create-react-app/docs/deployment\">https://facebook.github.io/create-react-app/docs/deployment</a>)</em> in the official documentation._</p>\n</blockquote>\n<h1>What you learned</h1>\n<p>In this article, you learned how to:</p>\n<ul>\n<li>Describe what front-end builds are and why they're needed;</li>\n<li>-</li>\n<li>Describe at a high level what happens in a Create React App when you run npm start; and</li>\n<li>Prepare to deploy a React application into a production environment.</li>\n</ul>\n<h1>React Router Documentation</h1>\n<p>Now that you've had an introduction to React Router, feel free to explore the official documentation to learn more! As you become a full-fledged software engineer, remember that documentation is your friend. You can take a brief overview for now, as the documentation might include a lot of information at first. The more you learn about React, the more you should revisit the official documentation and learn!</p>\n<h1>Setting up React Router</h1>\n<ul>\n<li><a href=\"https://reacttraining.com/react-router/web/guides/quick-start\">React Router Quick Start</a></li>\n<li>-</li>\n<li><a href=\"https://reacttraining.com/react-router/web/api/HashRouter\">HashRouter</a></li>\n<li><a href=\"https://reacttraining.com/react-router/web/api/BrowserRouter\">BrowserRouter</a></li>\n</ul>\n<h1>Routes and Links</h1>\n<ul>\n<li><a href=\"https://reacttraining.com/react-router/web/api/Route\">Route</a></li>\n<li>-</li>\n<li><a href=\"https://reacttraining.com/react-router/web/api/Link\">Link</a></li>\n<li><a href=\"https://reacttraining.com/react-router/web/api/NavLink\">NavLink</a></li>\n</ul>\n<h1>Switch and Redirect</h1>\n<ul>\n<li><a href=\"https://reacttraining.com/react-router/web/api/Switch\">Switch</a></li>\n<li>-</li>\n<li><a href=\"https://reacttraining.com/react-router/web/api/Redirect\">Redirect</a></li>\n</ul>\n<h1>React Router Params (ownProps)</h1>\n<ul>\n<li><a href=\"https://reacttraining.com/react-router/web/api/history\">props.history</a></li>\n<li>-</li>\n<li><a href=\"https://reacttraining.com/react-router/web/api/location\">props.location</a></li>\n<li><a href=\"https://reacttraining.com/react-router/web/api/match\">props.match</a></li>\n</ul>\n<h1>Rainbow Routes Project</h1>\n<p>Today you're going to get our first experience using React Router. The goal is to create a basic app that displays the colors of the rainbow. This rainbow, however, has something special about it — some of the colors are nested within others.</p>\n<h1>Phase 0: Setup</h1>\n<p>Begin by creating a new React project:</p>\n<p>Now you'll remove all the contents of your src and all the contents from your public directory to build the application architecture from scratch! After you have deleted all your files within the directories, create a new index.html file in your public folder. Use the html:5 emmet shortcut to generate an HTML template. Title your page \"Rainbow Routes\" and create a div with an id of root in your DOM's &#x3C;body> element. Create an index.css file in your src directory with the following code. Now let's create your entry file!</p>\n<p>Create an index.js entry file in the src directory. At the top of the file, make sure to import React from the react package and ReactDOM from the react-dom package. Make sure to also import your the index.css file you just created! This will take care of styling your <em>rainbow routes</em>.</p>\n<p>Now you can use the ReactDOM.render() method to render a &#x3C;Root /> component instead of the DOM element with an id of root. Lastly, wrap your render function with a DOMContentLoaded event listener, like so:</p>\n<p>Let's create your Root component right in your entry file! Your Root component will take care of applying your BrowserRouter to the application. Applying the BrowserRouter to your Root component allows all the child components rendering within &#x3C;BrowserRouter> tags to use and access the Route, Link, and NavLink components within the react-router-dom package.</p>\n<p>Install the react-router-dom package:</p>\n<p>Now import BrowserRouter from the react-router-dom package, like so:</p>\n<p>You're going to be rendering a lot of components, so let's keep your src directory organized by creating a components directory within. Within your new ./src/components directory, create a Rainbow.js file for your Rainbow component with the following code:</p>\n<p>Your Rainbow component will act as the home page or default path (/) of your application. Import the Rainbow component into your entry file and have your Root component render &#x3C;Rainbow /> wrapped within &#x3C;BrowserRouter> tags, like so:</p>\n<p>Within your Rainbow component, you'll be rendering &#x3C;NavLink> and &#x3C;Route> components to add different navigation paths to different components. Let's create all the components you will render!</p>\n<p>Create files for the following components in your ./src/components directory:</p>\n<ul>\n<li>Red</li>\n<li>-</li>\n<li>Blue</li>\n<li>-</li>\n<li>Green</li>\n<li>-</li>\n<li>Indigo</li>\n<li>Orange</li>\n<li>Violet</li>\n<li>Yellow</li>\n</ul>\n<p>Your Red and Blue components will look something like this:</p>\n<p>Your Green, Indigo, Orange, Violet, and Yellow components will look something like this:</p>\n<p>Now start your server and verify you can see the \"Rainbow Router!\" header from your Rainbow component. Currently there is no functionality. Let's fix that!</p>\n<h1>Phase 1: Routes</h1>\n<p>As a reminder, wrapping the Rainbow component in &#x3C;BrowserRouter> tags makes the router available to all descendent React Router components. Now open the Rainbow.js file. You're going to render some of your color components from here. Ultimately you want your routes to look like this.</p>\n<p>URLComponents/Rainbow/redRainbow -> Red/red/orangeRainbow -> Red -> Orange/red/yellowRainbow -> Red -> Yellow/greenRainbow -> Green/blueRainbow -> Blue/blue/indigoRainbow -> Blue -> Indigo/violetRainbow -> Violet</p>\n<p>This means that the Red, Green, Blue, and Violet components need to render in the Rainbow component, but only when you are at the corresponding URL. You'll do this with Route components. Begin by importing the Red, Green, Blue, and Violet components into your Rainbow.js file. Then add the necessary Route components inside the div with id=\"rainbow\" in the Rainbow component. For example to render the Red component with the /red path, you would use the following Route component:</p>\n<p>Test that your code works! Manually type in each URL you just created, and you should see the color component pop up. Remember, these are React Routes, so the paths you created will come after the /. For example, your default rainbow route will look like <a href=\"http://localhost:3000/\">http://localhost:3000/</a> while your red route will look like <a href=\"http://localhost:3000/red.\">http://localhost:3000/red</a><a href=\"http://localhost:3000/red.\">.</a></p>\n<p>You want to nest the Orange and Yellow components inside the Red component, and the Indigo component inside the Blue component. Remember to import your components to use them in a Route tag. You'll have to go add the corresponding Route tags to the Red.js and Blue.js files. Make sure to use the correct nested paths, such as \"/red/orange\" for the orange Route.</p>\n<h1>Phase 2: Links</h1>\n<p>Manually navigating to our newly created routes is tiresome, so let's add functionality to take care of this process for us. React Router provides the Link and NavLink components for this purpose.</p>\n<p>Add Links to the paths /red, /green, /blue, and /violet in the Rainbow component. For example, your red link should look like</p>\n<p>When you are at blue you want to be able to get to /blue/indigo, and then back to /blue. Add the corresponding Links to the Blue component like this:</p>\n<p>Similarly, add Links to /red, /red/orange and /red/yellow to the Red component. Test all your links. Navigation is so much easier now!</p>\n<h1>Phase 3: NavLinks</h1>\n<p>It would be nice if our links gave us some indication of which route you were at. Fortunately, React Router has a special component for that very purpose: NavLink. NavLinks get an extra CSS class when their to prop matches the current URL. By default this class is called active.</p>\n<p>Go ahead and switch all your Links to NavLinks. If you open the app you won't see any change yet. That's because you haven't added any special styling to the active class. Go ahead and open the index.css file. Create an .active class and add the line font-weight: 700. Now your active links will be bold. Isn't that nice!</p>\n<p>The only problem is that now the Blue only link is active even when the path is /blue/indigo. That doesn't make a lot of sense. Let's add the exact flag to that link so it will only be active when its to exactly matches the current path. Now it should look like:</p>\n<p>Do the same for the Red only link. Everything should be working now.</p>\n<h1>Phase 4 — Changing NavLink's Active Class</h1>\n<p>You've already set up NavLink to bold the link text using the .active class in src/index.css. But what if you wanted this class to be something else? For instance, what if you want your main color links (Red, Green, Blue, Violet) to be styled differently when active than your sub-route links (Red Only, Add Orange, Add Yellow, etc.).</p>\n<p>You can set the class that React Router sets to an active NavLink by adding the activeClassName prop.</p>\n<p>For instance, when we are at a route matching the below NavLink's to prop, the component will have a class of .parent-active applied:</p>\n<p>This allows much more flexibility to style an active NavLink!</p>\n<p>Using the example above, add an activeClassName prop to each of your NavLinks in src/components/Rainbow.js. Now, add some CSS styling for that class in your src/index.css to distinguish your main and your sub-route links.</p>\n<p>Compare your work to the solution and make sure the behavior is the same. Time to celebrate! ✨ 🌈 ✨</p>\n<p>You can also learn more about using the React Router at <a href=\"https://reacttraining.com/react-router/web/guides/quick-start\">reacttraining.com</a>!</p>\n<h1>Exploring React Builds Project</h1>\n<p>In this project, you'll use Create React App to create a simple React application. You'll experiment with some of the features that Create React App provides and deploy a production build of your application to a standalone Express application.</p>\n<h1>Phase 0: Setup</h1>\n<p>Begin by using the <a href=\"https://github.com/facebook/create-react-app\">create-react-app</a> package to create a React application:</p>\n<blockquote>\n<p><em>Remember that using the create-react-app command initializes your project as a Git repository. If you use the ls -a to view the hidden files in your project, you'll see the .git file.</em></p>\n</blockquote>\n<p>Update the App component:</p>\n<ul>\n<li>Wrap the &#x3C;h1> element with a &#x3C;div> element; and</li>\n<li>-</li>\n<li>Change the &#x3C;h1> element content to something like \"Exploring React Builds\".</li>\n</ul>\n<h1>Phase 1: Using CSS modules</h1>\n<p>You've already seen an example of using the import keyword to import a stylesheet into a module so that it'll be included in your application build. That's the technique being used to include the global index.css stylesheet:</p>\n<p>You can also leverage <a href=\"https://github.com/css-modules/css-modules\">CSS modules</a> in your Create React App projects. CSS Modules scope stylesheet class names so that they are unique to a specific React component. This allows you to create class names without having to worry if they might collide with class names used in another component.</p>\n<p>Add a new css-modules folder to the src folder. Within that folder, add the following files:</p>\n<ul>\n<li>HeadingA.js</li>\n<li>-</li>\n<li>HeadingA.modu</li>\n<li>-</li>\n<li>HeadingB.js</li>\n<li>HeadingB.module.css</li>\n</ul>\n<p>Then update the contents of each file to the following:</p>\n<p>Notice how the .heading CSS class name is being used within each component to set the color of the &#x3C;h1> element. For the HeadingA component, the color is green, and for the HeadingB component, the color is red. Using the file naming convention [name].module.css let's Create React App know that we want these stylesheets to be processed as CSS Modules. Using CSS Modules allows the .heading class name to be reused across components without any issue.</p>\n<p>To see this feature in action, update your App component to render both of your new components:</p>\n<p>Then run your application (npm start) to see \"Heading A\" and \"Heading B\" displayed respectively in green and red. If you use the browser's developer tools to inspect \"Heading A\", you'll see that the .heading class name has been modified so that it's unique to the HeadingA component:</p>\n<p>CSS Modules is an example of how a front-end build process can be used to modify code to enable a feature that's not natively supported by browsers.</p>\n<h1>Phase 2: Using an image in a component</h1>\n<p>Create React App configures webpack with support for loading images (as well as CSS, fonts, and other file types). What this means, for you as the developer, is that you can add an image file to your project, import it directly into a module, and render it in a React component.</p>\n<p>Download any image of off the Web or <a href=\"https://appacademy-open-assets.s3-us-west-1.amazonaws.com/Modular-Curriculum/content/react-redux/topics/react-builds/assets/react-builds-cat.png\">click here</a> to download the below image.</p>\n<p>Then within the src folder add a new folder named image. Within that folder add a new component file named Image.js. Also add your downloaded image file to the image folder (so it's a sibling to the Image.js file).</p>\n<p>Update the contents of the Image.js file to this:</p>\n<p>You can import an image into a component using the import keyword. This tells webpack to include the image in the build. Notice that when you import an image into a module, you'll get a path to the image's location within the build. You can use this path to set the src attribute on an &#x3C;img> element.</p>\n<blockquote>\n<p><em>Be sure to update the image import statement to the correct file name if you're using your own image!</em></p>\n</blockquote>\n<p>Now update the App component to import and render the Image component:</p>\n<p>If you run your application (npm start) you'll see your image displayed on the page! You can also open your browser's developer tools and view the \"Sources\" for the current page. If you can expand the localhost:3000 > static > media node on the left, you can see the image file that webpack copied to your build.</p>\n<h1>Images in stylesheets</h1>\n<p>You can also reference images in your CSS files too. Add a CSS file named Image.css to the ./src/image folder and update its contents to this:</p>\n<p>Then update the Image component to this:</p>\n<p>Now you'll see the image displayed twice on the page!</p>\n<h1>Phase 3: Updating the supported browsers (and its affect on code transpilation)</h1>\n<p>Earlier you learned about the browerslist setting in the package.json file and now adjusting these targets affect how your code will be transpiled:</p>\n<p>The production list specifies the browsers to target when creating a production build and the development list specifics the browsers to target when running the application using npm start. Currently, you're targeting relatively recent versions of the major browsers when creating a development build. Targeting older browser versions results in your code being transpiled to an older version of JavaScript.</p>\n<p>To experiment with this configuration option, let's add a class component to the project. Add a new folder named class-component to the src folder. Within that folder, add a file named ClassComponent.js containing the following code:</p>\n<p>Don't forget to update your App component to render the new component:</p>\n<p>Now run your application using npm start. Open your browser's developer tools and view the \"Sources\" for the current page. Expand the localhost:3000 > static > js node on the left and select the main.chunk.js file. Press CMD+F on macOS or CTRL+F on Windows to search the file for \"Class Component\". Here's what the transpiled code looks like for the ClassComponent class:</p>\n<blockquote>\n<p><em>Have you wondered yet why you need to use the developer tools to view the bundles generated by Create React App? Remember that when you run npm start, Create React App builds your application using _[</em>webpack-dev-server<em>](<a href=\"https://webpack.js.org/configuration/dev-server/\">https://webpack.js.org/configuration/dev-server/</a>)</em>. To keep things as performant as possible, the bundles generated by <em>[</em>webpack-dev-server<em>](<a href=\"https://webpack.js.org/configuration/dev-server/\">https://webpack.js.org/configuration/dev-server/</a>)</em> are stored in memory instead of writing them to the file system._</p>\n</blockquote>\n<p>The JSX in the component's render method has been converted to JavaScript but the ClassComponent ES2015 class is left alone. This makes sense though as JSX isn't natively supported by any browser while ES2015 classes have been natively supported by browsers for awhile now.</p>\n<p>But what if you need to target a version of a browser that doesn't support ES2015 classes? You can use the <a href=\"https://caniuse.com/#feat=es6-class\">\"Can I use…\"</a> website to see when browsers started supporting ES2105 (or ES6) classes. Starting with version 49, Chrome natively supported classes. But imagine that you need to support Chrome going back to version 30, a version of Chrome that doesn't support classes.</p>\n<p>Change the browserslist.development property in the package.json file to this:</p>\n<p>The query chrome >= 30 specifies that you want to target Chrome version 30 or newer.</p>\n<blockquote>\n<p><em>The _[</em>browserl.ist<em>](<a href=\"https://browserl.ist/\">https://browserl.ist/</a>)</em> website can be used to see the browsers supported by your configured browserslist._</p>\n</blockquote>\n<p>Stop your application if it's currently running. Delete the ./node_modules/.cache folder and run npm start again. Then view the main.chunk.js bundle again in the developer tools:</p>\n<p>Now your ES2015 class component is being converted to a constructor function! Here's the transpiled code for reference:</p>\n<p>Luckily it's very rare that you'll need to read the code in your generated bundles. webpack, by default, is configured to generate sourcemaps. Sourcemaps are a mapping of the code in a generated file, like a bundle file, to the original source code. This gives you access to your original source code in the browser's developer tools:</p>\n<p>You can even set a breakpoint in your source within the developer tools to stop execution on a specific line of code!</p>\n<h1>Phase 4: Adding environment variables</h1>\n<p>Earlier you learned that Create React App supports defining environment variables in an .env file. This gives you a convenient way to avoid hard coding values that vary across environments.</p>\n<p>Let's experiment with this feature so that you can see how the Create React App build process embeds environment variables into your HTML, CSS, and JavaScript bundles.</p>\n<p>Add an .env file to the root of your Create React App project. Define an environment variable named REACT<em>APP</em>TITLE:</p>\n<p>Remember that environment variables need to be prefixed with REACT<em>APP</em> for Create React App to process them. After defining your environment variable, you can refer to it within JSX using an expression and process.env:</p>\n<p>Environment variables can also be referred to in regular JavaScript code:</p>\n<p>You can also reference environment variables in your ./public/index.html file like this:</p>\n<p>Run your application again using npm start. Open your browser's developer tools and view the \"Sources\" for the current page. Expand the localhost:3000 node on the left and select (index). Notice that the text %REACT<em>APP</em>TITLE% within the &#x3C;title> element has been converted to the text literal Exploring React Builds:</p>\n<p>If you expand the localhost:3000 > static > js node on the left and select the main.chunk.js file, you can see how the App component's JSX has been converted to JavaScript:</p>\n<p>Here's a closer look at the relevant React.createElement method call:</p>\n<p>Again, notice how the environment variable has been replaced with a text literal. This has important security implications for you to consider. Because environment variables are embedded into your HTML, CSS, and JavaScript bundles during the build process, it's <em>very important</em> to not store any secrets, like API keys, in your environment variables. Remember, anyone can view your bundled code in the browser by inspecting your files!</p>\n<h1>Phase 5: Deploying a production build</h1>\n<p>In the last phase of this project, let's add routing to the React application, create a production build, and deploy the build to an Express application!</p>\n<h1>Adding routing</h1>\n<p>To add React Router to the application, start by installing the react-router-dom npm package:</p>\n<p>Then update the App component to this code:</p>\n<p>Be sure to run and test your application to ensure that the defined routes work as expected:</p>\n<ul>\n<li>/ - Should display the HeadingA and HeadingB components;</li>\n<li>-</li>\n<li>/image - Should display the Image component; and</li>\n<li>/class-component - Should display the ClassComponent component.</li>\n</ul>\n<h1>Creating a production build</h1>\n<p>To create a production build, run the command npm run build from the root of your project. The output in the terminal should look something like this:</p>\n<p>Ignore the comments about using serve to deploy your application (i.e. npm install -g serve and serve -s build). In the next step, you'll create a simple Express application to server your React application.</p>\n<h1>Serving a React application using Express</h1>\n<p>Create a new folder for your Express application outside of the Create React App project folder.</p>\n<blockquote>\n<p><em>For example, from the root of your project, use cd .. to go up a level and then create a new folder named express-server by running the command mkdir express-server. This makes the express-server folder a sibling to your Create React App project folder.</em></p>\n</blockquote>\n<p>Browse into the express-server folder and initialize it to use npm (i.e. npm init -y). Then install Express by running the command npm install express@^4.0.0.</p>\n<p>App a file named app.js with the following contents:</p>\n<p>This simple Express application will:</p>\n<ul>\n<li>Attempt to match incoming requests to static files located in the public folder; and</li>\n<li>-</li>\n<li>If a matching static file isn't found, then the ./public/index.html file will be served for all other requests.</li>\n</ul>\n<p>Now add a folder named public to the root of your Express project. Copy the files from the build folder in your Create React App project to the public folder in the Express application project. Then run your application using the command node app.js.</p>\n<p>Open a browser and browse to the URL <a href=\"http://localhost:9000/\">http://localhost:9000/</a>. You should see your React application served from your Express application! Be sure to click the navigation links to verify that all of your configured routes work as expected.</p>\n<p>Also, because you configured Express to serve the ./public/index.html file for any request that doesn't match a static file, you can \"deep link\" to any of your React application's routes:</p>\n<ul>\n<li><a href=\"http://localhost:9000/image\">http://localhost:9000/image</a></li>\n<li>-</li>\n<li><a href=\"http://localhost:9000/class-component\">http://localhost:9000/class-component</a></li>\n</ul>\n<h1>A Comprehensive Deep Dive into React</h1>\n<p>An in-depth look into the world of React.</p>\n<hr>\n<h3>React in Depth: A Comprehensive Guide</h3>\n<h4>A deep dive into the world of React.</h4>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*LnugLVhKbiGfSSHr\" alt=\"Photo by Ferenc Almasi on Unsplash\" class=\"graf-image\" />\n<figcaption>Photo by <a href=\"https://unsplash.com/@flowforfrank?utm_source=medium&amp;utm_medium=referral\" class=\"markup--anchor markup--figure-anchor\">Ferenc Almasi</a> on <a href=\"https://unsplash.com?utm_source=medium&amp;utm_medium=referral\" class=\"markup--anchor markup--figure-anchor\">Unsplash</a>\n</figcaption>\n</figure>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"markup--anchor markup--mixtapeEmbed-anchor\" title=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\">\n<strong>ALLOFMYOTHERARTICLES</strong>\n<br />\nbryanguner.medium.com</a>\n<a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b\" class=\"js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock\">\n</a>\n<h3>Random Things to Remember</h3>\n<ul>\n<li><span id=\"1e39\">Using <code class=\"language-text\">()</code> implictly returns components.</span></li>\n<li><span id=\"a547\">Role of <code class=\"language-text\">index.js</code> is to <em>render</em> your application.</span></li>\n<li><span id=\"c38f\">The reference to <code class=\"language-text\">root</code> comes from a div in the body of your public HTML file.</span></li>\n<li><span id=\"a364\">State of a component is simply a regular JS Object.</span></li>\n<li><span id=\"d64b\">Class Components require <code class=\"language-text\">render()</code> method to return JSX.</span></li>\n<li><span id=\"fa3d\">Functional Components directly return JSX.</span></li>\n<li><span id=\"4928\"><code class=\"language-text\">Class</code> is <code class=\"language-text\">className</code> in React.</span></li>\n<li><span id=\"e51a\">When parsing for an integer just chain <code class=\"language-text\">Number.parseInt(\"123\")</code></span></li>\n<li><span id=\"2924\">Use ternary operator if you want to make a conditional inside a fragment.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">{ x === y ? &lt;div>Naisu&lt;/div> : &lt;div>Not Naisu&lt;/div>; }</code></pre></div>\n<ul>\n<li><span id=\"ccda\">Purpose of <code class=\"language-text\">React.Fragment</code> is to allow you to create groups of children without adding an extra dom element.</span></li>\n</ul>\n<hr>\n<h3>Front-End History</h3>\n<ul>\n<li><span id=\"904c\">React makes it easier for you to make front-end elements. A front-end timeline</span></li>\n<li><span id=\"646a\">Some noteworthy front end libraries that have been used in the past few years:</span></li>\n<li><span id=\"febf\">2005: Script.aculo.us</span></li>\n<li><span id=\"d5ae\">2005: Dojo</span></li>\n<li><span id=\"0657\">2006: YUI</span></li>\n<li><span id=\"c1f9\">2010: Knockout</span></li>\n<li><span id=\"e742\">2011: AngularJS</span></li>\n<li><span id=\"ed7b\">2012: Elm</span></li>\n<li><span id=\"06e4\">2013: React (Considered the standard front-end library)</span></li>\n<li><span id=\"4ff0\">React manages the creation and updating of DOM nodes in your Web page.</span></li>\n<li><span id=\"53cd\">All it does is dynamically render stuff into your DOM.</span></li>\n<li><span id=\"c393\">What it doesn't do:</span></li>\n<li><span id=\"3088\">Ajax</span></li>\n<li><span id=\"54ee\">Services</span></li>\n<li><span id=\"5e4a\">Local Storage</span></li>\n<li><span id=\"a437\">Provide a CSS framework</span></li>\n<li><span id=\"06e5\">React is unopinionated</span></li>\n<li><span id=\"721c\">Just contains a few rules for developers to follow, and it just works.</span></li>\n<li><span id=\"e2c0\">JSX : Javascript Extension is a language invented to help write React Applications (looks like a mixture of JS and HTML)</span></li>\n<li><span id=\"916b\">Here is an overview of the difference between rendering out vanilla JS to create elements, and JSX:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">fetch(\"https://example.com/api/people\")\n  .then((response) => response.json())\n  .then((people) => {\n    const html = \"&lt;ul>\";\n    for (let person of data.people) {\n      html += `&lt;li>${person.lastName}, ${person.firstName}&lt;/li>`;\n    }\n    html += \"&lt;/ul>\";\n    document.querySelector(\"#people-list\").innerHTML = html;\n  });\n\nfunction PeopleList(props) {\n  return (\n    &lt;ul>\n      $\n      {props.people.map((person) => (\n        &lt;li>\n          {person.lastName}, {person.firstName}\n        &lt;/li>\n      ))}\n    &lt;/ul>\n  );\n}\nconst peopleListElement = document.querySelector(\"#people-list\");\nfetch(\"https://example.com/api/people\")\n  .then((response) => response.json())\n  .then((people) => {\n    const props = { people };\n    ReactDOM.render(&lt;PeopleList props={props} />, peopleListElement);\n  });</code></pre></div>\n<ul>\n<li><span id=\"7ea4\">This may seem like a lot of code but when you end up building many components, it becomes nice to put each of those functions/classes into their own files to organize your code. Using tools with React</span></li>\n<li><span id=\"e220\"><code class=\"language-text\">React DevTools</code> : New tool in your browser to see ow React is working in the browser</span></li>\n<li><span id=\"9051\"><code class=\"language-text\">create-react-app</code> : Extensible command-line tool to help generate standard React applications.</span></li>\n<li><span id=\"af96\"><code class=\"language-text\">Webpack</code> : In between tool for dealing with the extra build step involved.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*LHVHf7SPZ1t0UVAj\" class=\"graf-image\" />\n</figure>- <span id=\"e0ad\">HMR : (Hot Module Replacement) When you make changes to your source code the changes are delivered in real-time.</span>\n- <span id=\"923a\">React Developers created something called `Flux Architecture` to moderate how their web page consumes and modifies data received from back-end API's.</span>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*wR-lbD4zf45-IHoQ\" class=\"graf-image\" />\n</figure>- <span id=\"b16e\">Choosing React</span>\n- <span id=\"eefd\">Basically, React is super important to learn and master.</span>\n<hr>\n<h3>React Concepts and Features</h3>\n<p>There are many benefits to using React over just Vanilla JavaScript.</p>\n<ul>\n<li><span id=\"8107\"><code class=\"language-text\">Modularity</code></span></li>\n<li><span id=\"15ac\">To avoid the mess of many event listeners and template strings, React gives you the benefit of a lot of modularity.</span></li>\n<li><span id=\"c1c5\"><code class=\"language-text\">Easy to start</code></span></li>\n<li><span id=\"90ce\">No specials tools are needed to use Basic React.</span></li>\n<li><span id=\"9ec9\">You can start working directly with <code class=\"language-text\">createElement</code> method in React.</span></li>\n<li><span id=\"dd3c\"><code class=\"language-text\">Declarative Programming</code></span></li>\n<li><span id=\"d3e6\">React is declarative in nature, utilizing either it's built-in createElement method or the higher-level language known as JSX.</span></li>\n<li><span id=\"ba8b\"><code class=\"language-text\">Reusability</code></span></li>\n<li><span id=\"a3c2\">Create elements that can be re-used over and over. One-flow of data</span></li>\n<li><span id=\"27d2\">React apps are built as a combination of parent and child components.</span></li>\n<li><span id=\"6da8\">Parents can have one or more child components, all children have parents.</span></li>\n<li><span id=\"26d8\">Data is never passed from child to the parent.</span></li>\n<li><span id=\"86be\"><code class=\"language-text\">Virtual DOM</code> : React provides a Virtual DOM that acts as an agent between the real DOM and the developer to help debug, maintain, and provide general use.</span></li>\n<li><span id=\"6747\">Due to this usage, React handles web pages much more intelligently; making it one of the speediest Front End Libraries available.</span></li>\n</ul>\n<h3>ES6 Refresher</h3>\n<p>Exporting one item per file</p>\n<ul>\n<li><span id=\"5538\">Use <code class=\"language-text\">export default</code> statement in ES6 to export an item. ES6</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export default class Wallet {\n  // ...\n}\n// sayHello will not be exported\nfunction sayHello() {\n  console.log(\"Hello!\");\n}</code></pre></div>\n<p>CommonJS (Equivalent)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Wallet {\n  // ...\n}\n// sayHello will not be exported\nfunction sayHello() {\n  console.log(\"Hello!\");\n}\nmodule.exports = Wallet;</code></pre></div>\n<p>Exporting multiple items per file</p>\n<ul>\n<li><span id=\"9a6e\">Use just thw <code class=\"language-text\">export</code> keyword (without default) to export multiple items per file. ES6 (Better to export them individually like this, rather than bunching them all into an object)</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">export class Wallet {\n  // ...\n}\nexport function sayHello() {\n  console.log(\"Hello!\");\n}\nexport const sayHi = () => {\n  console.log(\"Hi!\");\n};\nclass Wallet {\n  // ...\n}\nfunction sayHello() {\n  console.log(\"Hello!\");\n}\nconst sayHi = () => {\n  console.log(\"Hi!\");\n};\nexport { Wallet, sayHello, sayHi };</code></pre></div>\n<p>CommonJS (Equivalent)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Wallet {\n  // ...\n}\nfunction sayHello() {\n  console.log(\"Hello!\");\n}\nconst sayHi = () => {\n  console.log(\"Hi!\");\n};\nmodule.exports = {\n  Wallet,\n  sayHello,\n  sayHi,\n};</code></pre></div>\n<p>Importing with ES6 vs CommonJS</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*7EZESKf0XPbncXAY\" class=\"graf-image\" />\n</figure>- <span id=\"18b1\">Import statements in ES6 modules must always be at the top of the file, because all imports must occur before the rest of the file's code runs. ES6</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { Wallet } from \"./wallet\";\nimport * as fs from \"fs\";\nconst wallet = new Wallet();</code></pre></div>\n<p>CommonJS</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">let { Wallet } = require(\"./wallet\");\nconst wallet = new Wallet();\nlet fs = require(\"fs\");</code></pre></div>\n<p>Unnamed default imports</p>\n<ul>\n<li><span id=\"75e2\">You can name unnamed items exported with export default any name when you import them.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// exporting\nexport default class Wallet {\n  // ...\n}\n// importing\nimport Money from \"wallet.js\";\nconst wallet = new Money();</code></pre></div>\n<ul>\n<li><span id=\"5042\">Just remember if you use <code class=\"language-text\">export</code> instead of <code class=\"language-text\">export default</code> then your import is already named and cannot be renamed.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// exporting\nexport class Wallet {\n  // ...\n}\n// importing\nimport { Wallet } from \"wallet.js\";\nconst wallet = new Wallet();</code></pre></div>\n<p>Aliasing imports</p>\n<ul>\n<li><span id=\"3535\">Use as asterisk to import an entire module's contents.</span></li>\n<li><span id=\"3f1c\">Keep in mind you must use an <code class=\"language-text\">as</code> keyword to refer to it later.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// export\nexport function sayHello() {\n  console.log(\"Hello!\");\n}\nexport const sayHi = () => {\n  console.log(\"Hi!\");\n};\n//import\nimport * as Greetings from \"greetings.js\";\nGreetings.sayHello(); // Hello!\nGreetings.sayHi(); // Hi!</code></pre></div>\n<ul>\n<li><span id=\"bfbc\">You can also name identically named functions or items from different files.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { Wallet as W1 } from \"./wallet1\";\nimport { Wallet as W2 } from \"./wallet2\";\nconst w1 = new W1();\nconst w2 = new W2();</code></pre></div>\n<p>Browser support for ES6 Modules</p>\n<ul>\n<li><span id=\"69b4\">ES6 Modules can only be used when a JS file is specified as a module. <code class=\"language-text\">&lt;script type=\"module\" src=\"./wallet.js\">\n&lt;/script></code></span></li>\n<li><span id=\"4f5c\">You can get browser support for ES6 modules by adding module into your script tag.</span></li>\n</ul>\n<hr>\n<h3>Notes</h3>\n<h3>JSX In Depth</h3>\n<ul>\n<li><span id=\"2a0d\">Remember that JSX is just syntactic sugar for the built in <code class=\"language-text\">React.createElement(component, props, ...children)</code></span></li>\n<li><span id=\"1532\">React Library must always be in scope from your JSX code.</span></li>\n<li><span id=\"72b2\">Use Dot Notation for JSX Type</span></li>\n<li><span id=\"0cbc\">User-Defined Components Must Be Capitalized <code class=\"language-text\">&lt;Foo /></code> vs <code class=\"language-text\">&lt;div></code></span></li>\n<li><span id=\"553a\">Cannot use a general expression as the React element type. (<code class=\"language-text\">Incorrect</code>)</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Story(props) {\n  // Wrong! JSX type can't be an expression.\n    return &lt;components[props.storyType] story={props.story} />;\n  };</code></pre></div>\n<p>(<code class=\"language-text\">Corrected</code>)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Story(props) {\n  // Correct! JSX type can be a capitalized variable.\n  const SpecificStory = components[props.storyType];\n  return &lt;SpecificStory story={props.story} />;\n}</code></pre></div>\n<p>Props in JSX</p>\n<ul>\n<li><span id=\"e549\">Several ways to specify props in JSX.</span></li>\n<li><span id=\"257d\"><code class=\"language-text\">Javascript Expressions as Props</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyComponent foo={1 + 2 + 3 + 4} /></code></pre></div>\n<ul>\n<li><span id=\"57f8\"><code class=\"language-text\">String Literals</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyComponent message=\"hello world\" /> &lt;MyComponent message={'hello world'} /> &lt;MyComponent message=\"&amp;lt;3\" /> &lt;MyComponent message={'❤'} /></code></pre></div>\n<ul>\n<li><span id=\"48df\"><code class=\"language-text\">Props Default to \"True\"</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;MyTextBox autocomplete /> &lt;MyTextBox autocomplete={true} /></code></pre></div>\n<ul>\n<li><span id=\"2072\"><code class=\"language-text\">Spread Attributes</code></span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function App1() { return &lt;Greeting firstName=\"Ben\" lastName=\"Hector\" />; } function App2() { const props = { firstName: \"Ben\", lastName: \"Hector\" }; return &lt;Greeting {…props} />; }</code></pre></div>\n<p>Children in JSX</p>\n<ul>\n<li><span id=\"2238\"><code class=\"language-text\">props.children</code> : The content between opening and closing tag. JavaScript Expressions as Children</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function Item(props) {\n  return &lt;li>{props.message}&lt;/li>;\n}\nfunction TodoList() {\n  const todos = [\"finish doc\", \"submit pr\", \"nag dan to review\"];\n  return (\n    &lt;ul>\n      {todos.map((message) => (\n        &lt;Item key={message} message={message} />\n      ))}\n    &lt;/ul>\n  );\n}</code></pre></div>\n<p>Functions as Children</p>\n<ul>\n<li><span id=\"bf0a\"><code class=\"language-text\">props.children</code> works like any other prop, meaning it can pass any sort of data.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Calls the children callback numTimes to produce a repeated component\nfunction Repeat(props) {\n  let items = [];\n  for (let i = 0; i &lt; props.numTimes; i++) {\n    items.push(props.children(i));\n  }\n  return &lt;div>{items}&lt;/div>;\n}\nfunction ListOfTenThings() {\n  return (\n    &lt;Repeat numTimes={10}>\n      {(index) => &lt;div key={index}>This is item {index} in the list&lt;/div>}\n    &lt;/Repeat>\n  );\n}</code></pre></div>\n<p>Booleans, Null, and Undefined Are Ignored</p>\n<ul>\n<li><span id=\"7017\"><code class=\"language-text\">false</code>, <code class=\"language-text\">null</code>, <code class=\"language-text\">undefined</code>, and <code class=\"language-text\">true</code> are all valid children.</span></li>\n<li><span id=\"5af2\">They will not render.</span></li>\n<li><span id=\"10dc\">You can use these to conditionally render items.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  {showHeader &amp;&amp; &lt;Header />}\n  &lt;Content />\n&lt;/div></code></pre></div>\n<ul>\n<li><span id=\"fa28\">In this example, the component will only render if <code class=\"language-text\">showHeader</code> evals to True.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Before work-around\n&lt;div>\n  {props.messages.length &amp;&amp;\n    &lt;MessageList messages={props.messages} />\n  }\n&lt;/div>\n// After work-around\n&lt;div>\n  {props.messages.length > 0 &amp;&amp;\n    &lt;MessageList messages={props.messages} />\n  }\n&lt;/div></code></pre></div>\n<ul>\n<li><span id=\"3701\">Note that certain falsy values such as zero will still be rendered by React, you can work around this by ensuring situations like the above eval. into a boolean.</span></li>\n<li><span id=\"9586\">In the times you want booleans to be rendered out, simply convert it into a string first.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>My JavaScript variable is {String(myVariable)}.&lt;/div></code></pre></div>\n<h3>Reconciliation</h3>\n<p>The Diffing Algorithm</p>\n<ul>\n<li><span id=\"76c4\"><code class=\"language-text\">Diffing</code> : When the state of a component changes React creates a new virtual DOM tree.</span></li>\n<li><span id=\"9a73\">Elements of Different Types</span></li>\n<li><span id=\"d680\">Every time the root elements have different types, React tears down the old tree and builds the new tree from scratch.</span></li>\n<li><span id=\"84a6\">DOM Elements Of the Same Type</span></li>\n<li><span id=\"4b94\">When comparing two DOM elements of the same type, React keeps the same underlying DOM node and only updates the changes attributes.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div className=\"before\" title=\"stuff\" /> &lt;div className=\"after\" title=\"stuff\" />\n\n&lt;div style={{ color: \"red\", fontWeight: \"bold\" }} /> &lt;div style={{color: 'green', fontWeight: 'bold'}} /></code></pre></div>\n<ul>\n<li><span id=\"0a0c\">Component Elements Of The Same Type</span></li>\n<li><span id=\"cf3a\">When components update, instances will remain the same, so that state maintains across renders.</span></li>\n<li><span id=\"b8ab\">React will only update the props, to match the new element.</span></li>\n<li><span id=\"82f3\">Recursing On Children</span></li>\n<li><span id=\"4a59\">React will iterate both lists of children and generate a mutation whenever there's a difference.</span></li>\n<li><span id=\"74a8\">This is why we use <code class=\"language-text\">keys</code>.</span></li>\n<li><span id=\"381c\">Makes it easier for React to match children in the original tree with children in the subsequent tree.</span></li>\n<li><span id=\"f1f5\">Tradeoffs</span></li>\n<li><span id=\"e98a\">Important to remember that reconciliation algorithm is an <em>implementation detail</em>.</span></li>\n<li><span id=\"7f57\">Re-rendering only to apply the differences following the rules stated in the previous sections.</span></li>\n</ul>\n<h3>Typechecking With PropTypes</h3>\n<ul>\n<li><span id=\"0bc0\">As your application grows, you can use React's <code class=\"language-text\">typechecking</code> to catch bugs.</span></li>\n<li><span id=\"638c\"><code class=\"language-text\">propTypes</code> is a special property to run typechecking.</span></li>\n<li><span id=\"e725\">exports range of built in validators to ensure your received data is valid.</span></li>\n<li><span id=\"f590\">propTypes is only checked in development mode.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import PropTypes from \"prop-types\";\nclass Greeting extends React.Component {\n  render() {\n    return &lt;h1>Hello, {this.props.name}&lt;/h1>;\n  }\n}\nGreeting.propTypes = {\n  name: PropTypes.string,\n};</code></pre></div>\n<p>Requiring Single Child</p>\n<ul>\n<li><span id=\"e2db\">Use <code class=\"language-text\">PropTypes.element</code> to specify only a single child can be passed to a component as children.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import PropTypes from \"prop-types\";\nclass MyComponent extends React.Component {\n  render() {\n    // This must be exactly one element or it will warn.\n    const children = this.props.children;\n    return &lt;div>{children}&lt;/div>;\n  }\n}\nMyComponent.propTypes = {\n  children: PropTypes.element.isRequired,\n};</code></pre></div>\n<p>Default Prop Values</p>\n<ul>\n<li><span id=\"7d3d\">Use <code class=\"language-text\">defaultProps</code> to assign default values for props.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">class Greeting extends React.Component {\n  render() {\n    return &lt;h1>Hello, {this.props.name}&lt;/h1>;\n  }\n}\n// Specifies the default values for props:\nGreeting.defaultProps = {\n  name: \"Stranger\",\n};\n// Renders \"Hello, Stranger\":\nReactDOM.render(&lt;Greeting />, document.getElementById(\"example\"));\n\nclass Greeting extends React.Component {\n  static defaultProps = {\n    name: 'stranger'\n  }\n  render() {\n    return (\n      &lt;div>Hello, {this.props.name}&lt;/div>\n    )\n  }</code></pre></div>\n<hr>\n<h3>Notes</h3>\n<h3>React Router Introduction</h3>\n<ul>\n<li><span id=\"48a7\"><code class=\"language-text\">React Router</code> is the answer for rendering different components for different pages.</span></li>\n<li><span id=\"78b3\">A front-end library that allows you to control which components to display using the browser location.</span></li>\n<li><span id=\"aa2a\"><code class=\"language-text\">Client-side Routing</code> Getting started with routing</span></li>\n<li><span id=\"0940\">Install React Router with:</span></li>\n<li><span id=\"742a\">npm install — save react-router-dom@⁵.1.2</span></li>\n<li><span id=\"f07f\">Import <code class=\"language-text\">Browser Router</code> from package.</span></li>\n<li><span id=\"9e4e\">import { BrowserRouter } from \"react-router-dom\";</span></li>\n<li><span id=\"cb01\"><code class=\"language-text\">BrowserRouter</code> is the primary component of the router that wraps your route hierarchy.</span></li>\n<li><span id=\"adfa\">Wrap it around components.</span></li>\n<li><span id=\"0276\">Creates a <code class=\"language-text\">React Context</code> that passes routing information down to all its descendant components.</span></li>\n<li><span id=\"dd45\">You can also use <code class=\"language-text\">HashRouter</code>, where it would generate a hash before the endpoint. Creating frontend routes</span></li>\n<li><span id=\"37c2\">React Router helps your app render specific components based on the URL.</span></li>\n<li><span id=\"54c4\">The most common component is <code class=\"language-text\">&lt;Route></code></span></li>\n<li><span id=\"500a\">Wrapped around another component, causing the comp. to only render if the a certain URL is matched.</span></li>\n<li><span id=\"5a94\"><code class=\"language-text\">Props</code> : path, component, exact, and [render]</span></li>\n<li><span id=\"9f06\">Browser Router can only have a single child component.</span></li>\n<li><span id=\"6305\">The Browser Router wraps all routes within a parent div element.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const Root = () => {\n  const users = {\n    1: { name: \"Andrew\" },\n    2: { name: \"Raymond\" },\n  };\n  return (\n    &lt;BrowserRouter>\n      &lt;div>\n        &lt;h1>Hi, I'm Root!&lt;/h1>\n        &lt;Route exact path=\"/\" component={App} />\n        &lt;Route path=\"/hello\" render={() => &lt;h1>Hello!&lt;/h1>} />\n        &lt;Route path=\"/users\" render={() => &lt;Users users={users} />} />\n      &lt;/div>\n    &lt;/BrowserRouter>\n  );\n};</code></pre></div>\n<ul>\n<li><span id=\"c057\">component</span></li>\n<li><span id=\"2dcc\">Indicates component to render.</span></li>\n<li><span id=\"740c\">path</span></li>\n<li><span id=\"3030\">Indicates path to render a specific component.</span></li>\n<li><span id=\"0741\">exact</span></li>\n<li><span id=\"52cb\">Tells route to not pattern match and only render a certain route exclusively to it's associated component.</span></li>\n<li><span id=\"cb93\">render</span></li>\n<li><span id=\"c702\">Optional prop that takes in a function to be called.</span></li>\n<li><span id=\"594b\">Causes extra work for React.</span></li>\n<li><span id=\"5320\">Preferred for inline rendering of simple functional components.</span></li>\n<li><span id=\"0d3e\">Difference between <code class=\"language-text\">component</code> and <code class=\"language-text\">render</code> is that component returns new JSX that be re-mounted, but render returns the JSX that will be mounted only once.</span></li>\n<li><span id=\"4a08\">// This inline rendering will work, but is unnecessarily slow. &#x3C;Route path=\"/hello\" component={() => &#x3C;h1>Hello!&#x3C;/h1>} /> // This is the preferred way for inline rendering. &#x3C;Route path=\"/hello\" render={() => &#x3C;h1>Hello!&#x3C;/h1>} /></span></li>\n<li><span id=\"a2d3\">Also useful if you need to pass in specific props to a component.</span></li>\n<li><span id=\"e09f\">// `users` to be passed as a prop: const users = { 1: { name: \"Andrew\" }, 2: { name: \"Raymond\" }, }; &#x3C;Route path=\"/users\" render={() => &#x3C;Users users={users} />} />;</span></li>\n</ul>\n<p>Route path params</p>\n<ul>\n<li><span id=\"3d09\">Your component's props can hold information about URL's parameters.</span></li>\n<li><span id=\"52f3\">Will match segments starting at <code class=\"language-text\">:</code> to the next <code class=\"language-text\">/</code>, <code class=\"language-text\">?</code>, <code class=\"language-text\">#</code>.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Route\n  path=\"/users/:userId\"\n  render={(props) => &lt;Profile users={users} {...props} />}\n/></code></pre></div>\n<ul>\n<li><span id=\"f2b4\"><code class=\"language-text\">{...props}</code> spreads out the router's props.</span></li>\n<li><span id=\"1edb\"><code class=\"language-text\">props.match.params</code> is used to access the match prop's parameters.</span></li>\n<li><span id=\"b6a9\">Useful keys on the <code class=\"language-text\">match</code> object:</span></li>\n<li><span id=\"290f\"><code class=\"language-text\">isExact</code> : boolean that tells you whether or not the URL exactly matches the path.</span></li>\n<li><span id=\"27ea\"><code class=\"language-text\">url</code> : the currentURL</span></li>\n<li><span id=\"b979\"><code class=\"language-text\">path</code> : Route path it matched against (w/o wildcards)</span></li>\n<li><span id=\"6c59\"><code class=\"language-text\">params</code> : Matches for the individual wildcard segments.</span></li>\n</ul>\n<hr>\n<h3>Navigation</h3>\n<p>React Router Navigation</p>\n<ul>\n<li><span id=\"a548\"><code class=\"language-text\">Link</code>, <code class=\"language-text\">NavLink</code>, <code class=\"language-text\">Redirect</code>, <code class=\"language-text\">history</code> props of React Router are used to help your user navigate routes. Adding links for navigation</span></li>\n<li><span id=\"643f\">Issues on-click navigation event to a route defined in app.</span></li>\n<li><span id=\"949d\">Usage renders an anchor tag with a correctly set <code class=\"language-text\">href</code> attribute.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">import { BrowserRouter, Route, Link } from \"react-router-dom\";</code></pre></div>\n<ul>\n<li><span id=\"b5a5\"><code class=\"language-text\">Link</code> takes two properties: <code class=\"language-text\">to</code> and <code class=\"language-text\">onClick</code>.</span></li>\n<li><span id=\"995b\"><code class=\"language-text\">to</code> : route location that points to an absolute path.</span></li>\n<li><span id=\"978c\"><code class=\"language-text\">onClick</code> : clickHandler.</span></li>\n<li><span id=\"b8c0\"><code class=\"language-text\">NavLink</code> works just like <code class=\"language-text\">Link</code> but has a bit of extra functionality.</span></li>\n<li><span id=\"6334\">Adds extra styling, when the path it links to matches the current path.</span></li>\n<li><span id=\"07b8\">As it's name suggests, it is used to Nav Bars.</span></li>\n<li><span id=\"8a33\">Takes three props:</span></li>\n<li><span id=\"e501\"><code class=\"language-text\">activeClassName</code> : allows you to set a CSS class name for styling. (default set to 'active')</span></li>\n<li><span id=\"81da\"><code class=\"language-text\">activeStyle</code> : style object that is applied inline when it's <code class=\"language-text\">to</code> prop. matches the current URL.</span></li>\n<li><span id=\"8c71\"><code class=\"language-text\">exact</code> prop is a boolean that defaults to false; you can set it to true to apply requirement of an exact URL match.</span></li>\n<li><span id=\"755b\">exact can also be used as a flag instead of a reg. property value.</span></li>\n<li><span id=\"dd12\">benefit of adding this is so that you don't trigger other matches. Switching between routes</span></li>\n<li><span id=\"4fb6\"><code class=\"language-text\">&lt;Switch></code> : Component allows you to only render one route even if several match the current URL.</span></li>\n<li><span id=\"7be7\">You may nest as many routes as you wish but only the first match of the current URL will be rendered.</span></li>\n<li><span id=\"3f8a\">Very useful if we want a default component to render if none of our routes match.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Switch>\n  &lt;Route path=\"some/url\" component={SomeComponent} />\n  &lt;Route path=\"some/other/url\" component={OtherComponent} />\n  &lt;Route component={DefaultComponent} />\n&lt;/Switch></code></pre></div>\n<ul>\n<li><span id=\"b901\"><code class=\"language-text\">DefaultComponent</code> will only render if none of the other URLs match up.</span></li>\n<li><span id=\"21a3\"><code class=\"language-text\">&lt;Redirect></code> : Helps redirect users.</span></li>\n<li><span id=\"ee88\">Only takes a single prop: <code class=\"language-text\">to</code>.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;Route\n  exact\n  path=\"/\"\n  render={() => (this.props.currentUser ? &lt;Home /> : &lt;Redirect to=\"/login\" />)}\n/></code></pre></div>\n<p>History</p>\n<ul>\n<li><span id=\"6456\"><code class=\"language-text\">History</code> allows you to update the URL programmatically.</span></li>\n<li><span id=\"bac6\">Contains two useful methods:</span></li>\n<li><span id=\"9b00\"><code class=\"language-text\">push</code> : Adds a new URL to the end of the history stack.</span></li>\n<li><span id=\"d539\"><code class=\"language-text\">replace</code> : Replaces the current URL on the history stack, so the back button won't take you to it.</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Pushing a new URL (and adding to the end of history stack):\nconst handleClick = () => this.props.history.push(\"/some/url\");\n// Replacing the current URL (won't be tracked in history stack):\nconst redirect = () => this.props.history.replace(\"/some/other/url\");</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">---\n\n### Nested Routes\n\nWhy nested routes?\n\n-   &lt;span id=\"6403\">Create routes that tunnel into main components vs getting rendered on the main page as it's own thing. What are nested routes?&lt;/span>\n\n&lt;!-- -->\n\n    const Profile = (props) => {\n      // Custom call to database to fetch a user by a user ID.\n      const user = fetchUser(props.match.params.userId);\n      const { name, id } = user;\n      return (\n        &lt;div>\n          &lt;h1>Welcome to the profile of {name}!&lt;/h1>\n          &lt;Link to={`/users/${id}/posts`}>{name}'s Posts&lt;/Link>\n          &lt;Link to={`/users/${id}/photos`}>{name}'s Photos&lt;/Link>\n          &lt;Route path=\"/users/:userId/posts\" component={UserPosts} />\n          &lt;Route path=\"/users/:userId/photos\" component={UserPhotos} />\n        &lt;/div>\n      );\n    };\n\nAlt. version using `props.match`\n\n    // Destructure `match` prop\n    const Profile = ({ match: { url, path, params }) => {\n      // Custom call to database to fetch a user by a user ID.\n      const user = fetchUser(params.userId);\n      const { name, id } = user;\n      return (\n        &lt;div>\n          &lt;h1>Welcome to the profile of {name}!&lt;/h1>\n          &lt;Link to={`${url}/posts`}>{name}'s Posts&lt;/Link>\n          &lt;Link to={`${url}/photos`}>{name}'s Photos&lt;/Link>\n          &lt;Route path={`${path}/posts`} component={UserPosts} />\n          &lt;Route path={`${path}/photos`} component={UserPhotos} />\n        &lt;/div>}\n      );\n    };\n\n-   &lt;span id=\"03fb\">As you can see above, our end URL isn't even defined until we apply those flexible values in.&lt;/span>\n\n---\n\n### React Builds\n\n-   &lt;span id=\"0fae\">`Build` : Process of converting code into something that can actually execute or run on the target platform.&lt;/span>\n-   &lt;span id=\"6fdb\">In regards to React, the minimum a build should do is convert JSX to something that browsers can understand. Reviewing common terminology&lt;/span>\n-   &lt;span id=\"779d\">`Linting` : Process of using a tool to analyze your code to catch common errors, bugs, inconsistencies etc...&lt;/span>\n-   &lt;span id=\"f1e5\">`Transpilation` : Process of converting source code, like JS, from one version to another.&lt;/span>\n-   &lt;span id=\"9f9f\">`Minification` : Process of removing all unnecessary characters in your code.&lt;/span>\n-   &lt;span id=\"57df\">`Bundling` : Process of combining multiple code files into a single file.&lt;/span>\n-   &lt;span id=\"d052\">`Tree Shaking` : Process of removing unused or dead code from your application before it's bundled. Configuration or code?&lt;/span>\n-   &lt;span id=\"ce13\">`Configuration` allows developers to create build tasks by declaring either JSON, XML, or YAML without explicitly writing every step in the process.&lt;/span>\n-   &lt;span id=\"16a6\">`Coding` or `Scripting` simply requires code. Babel and webpack (yes, that's intentionally a lowercase 'w')&lt;/span>\n-   &lt;span id=\"4363\">`Babel` : Code Transpiler that allows you to use all of the latest features and syntax wihtout worrying about what browsers support what.&lt;/span>\n-   &lt;span id=\"804b\">`webpack` : Allows developers to use JS modules w/o requiring users to use a browser that natively supports ES modules.&lt;/span>\n-   &lt;span id=\"77f2\">Create React App uses webpack and Babel under the hood to build applications. The Create React App build process&lt;/span>\n-   &lt;span id=\"222f\">What happens when you run `npm start`:&lt;/span>\n\n1.  &lt;span id=\"d245\">.env variables are loaded.&lt;/span>\n2.  &lt;span id=\"6209\">list of browsers to support are checked.&lt;/span>\n3.  &lt;span id=\"1c34\">config'd HTTP port checked for availability.&lt;/span>\n4.  &lt;span id=\"950b\">application compiler is configured and created.&lt;/span>\n5.  &lt;span id=\"8e30\">`webpack-dev-starter` is started&lt;/span>\n6.  &lt;span id=\"48cc\">`webpack-dev-starter` compiles app.&lt;/span>\n7.  &lt;span id=\"68ad\">`index.html` is loaded into browser&lt;/span>\n8.  &lt;span id=\"e670\">file watcher is started to watch for changes. Ejecting&lt;/span>\n\n-   &lt;span id=\"428b\">There is a script in Create React App called `eject` that allows you to 'eject' your application and expose all the hidden stuff. Preparing to deploy a React application for production&lt;/span>\n-   &lt;span id=\"eb79\">Defining Env Variables&lt;/span>\n\n&lt;!-- -->\n\n    REACT_APP_FOO: some value\n    REACT_APP_BAR: another value\n\n    console.log(process.env.REACT_APP_FOO);\n\n    Can be referenced in your index.html like so: &lt;title>%REACT_APP_BAR%&lt;/title>\n\nConfiguring the supported browsers\n\n    {\n      \"browserslist\": {\n        \"production\": [\n          \">0.2%\",\n          \"not dead\",\n          \"not op_mini all\"\n        ],\n        \"development\": [\n          \"last 1 chrome version\",\n          \"last 1 firefox version\",\n          \"last 1 safari version\"\n        ]\n      }\n    }\n\n-   &lt;span id=\"8a03\">If you specify older browsers it will affect how your code get's transpiled. Creating a production build&lt;/span>\n-   &lt;span id=\"fee3\">Run `npm run build` to create a production build.&lt;/span>\n-   &lt;span id=\"bdaf\">Bundles React in production mode and optimizes the build for the best performance.&lt;/span>\n\n---\n\n### Notes\n\n### Introduction to React\n\n-   &lt;span id=\"7224\">Simply a nice library that turns data into DOM.&lt;/span>\n-   &lt;span id=\"a9de\">`Tree Diffing` : Fast comparison and patching of data by comparing the current virtual DOM and new virtual DOM - updating only the pieces that change.&lt;/span>\n-   &lt;span id=\"1bbc\">`It's just a tree with some fancy diffing`&lt;/span>\n\n---\n\n### Create Element\n\nFrom JavaScript To DOM\n\n-   &lt;span id=\"cae8\">The `React.createElement` function has the following form:&lt;/span>\n\n&lt;!-- -->\n\n    React.createElement(type, [props], [...children]);\n\n-   &lt;span id=\"1688\">`Type` : Type of element to create, i.e. a string for an HTML element or a reference to a function or class that is a React component.&lt;/span>\n-   &lt;span id=\"3249\">`Props` : Object that contains data to render the element.&lt;/span>\n-   &lt;span id=\"56ab\">`Children` : Children of the elemet, as many as you want. Creating elements&lt;/span>\n-   &lt;span id=\"ee64\">Our rendering goal:&lt;/span>\n\n&lt;!-- -->\n\n    &lt;ul>\n      &lt;li class=\"selected\">\n        &lt;a href=\"/pets\">Pets&lt;/a>\n      &lt;/li>\n      &lt;li>\n        &lt;a href=\"/owners\">Owners&lt;/a>\n      &lt;/li>\n    &lt;/ul>\n\n-   &lt;span id=\"eb8b\">There are five tags to create:&lt;/span>\n-   &lt;span id=\"ea28\">One `ul`&lt;/span>\n-   &lt;span id=\"a4ba\">Two `li`&lt;/span>\n-   &lt;span id=\"de01\">Two `a`&lt;/span>\n-   &lt;span id=\"90b5\">There are certain attributes we want to appear in the DOM for these tags as well:&lt;/span>\n-   &lt;span id=\"dab5\">Each `li` has a `class` (or `className` in React)&lt;/span>\n-   &lt;span id=\"e88e\">Both `a` ele's have `href` attributes&lt;/span>\n-   &lt;span id=\"fd8c\">Also keep in mind the parent child relationships happening between the tags.&lt;/span>\n-   &lt;span id=\"9893\">`ul` is the parent of both `li`&lt;/span>\n-   &lt;span id=\"eafa\">Each `li` has an `a` element as a child&lt;/span>\n-   &lt;span id=\"84cc\">Each `a` has a `text content` child&lt;/span>\n\n&lt;figure>\n&lt;img src=\"https://cdn-images-1.medium.com/max/800/0*8ls0PmtREELbf5Wm\" class=\"graf-image\" />\n&lt;/figure>React.createElement(\n      \"ul\",\n      null,\n      React.createElement(\n        \"li\",\n        { className: \"selected\" },\n        React.createElement(\"a\", { href: \"/pets\" }, \"Pets\")\n      ),\n      React.createElement(\n        \"li\",\n        null,\n        React.createElement(\"a\", { href: \"/owners\" }, \"Owners\")\n      )\n    );\n\nConverting to virtual DOM\n\n-   &lt;span id=\"e7d4\">After you set up your `React.createElement`, you use `React.render` to take the value returned from cE and a DOM node to insert into the conversion of the real DOM.&lt;/span>\n\n&lt;!-- -->\n\n    // Put the element tree in a variable\n    const navList = React.createElement(\n      \"ul\",\n      null,\n      React.createElement(\n        \"li\",\n        { className: \"selected\" },\n        React.createElement(\"a\", { href: \"/pets\" }, \"Pets\")\n      ),\n      React.createElement(\n        \"li\",\n        null,\n        React.createElement(\"a\", { href: \"/owners\" }, \"Owners\")\n      )\n    );\n    // Get a DOM node for React to render to\n    const mainElement = document.querySelector(\"main\");\n    // Give React the element tree and the target\n    ReactDOM.render(navList, mainElement);\n\n-   &lt;span id=\"2cbc\">JS Code =&amp;gt; Virtual DOM =&amp;gt; Real Dom Updates&lt;/span>\n-   &lt;span id=\"25d5\">If you call React.render a second or multiple times it just checks the existing Virtual DOM and it knows which smaller areas to change. Thinking in Components&lt;/span>\n-   &lt;span id=\"fe61\">Components are pieces of reusable front-end pieces.&lt;/span>\n-   &lt;span id=\"bffa\">Components should be Single Responsibility Principle compliant.&lt;/span>\n\n---\n\n### Create Element\n\n`React.createElement Demo`\n\n-   &lt;span id=\"a288\">Can import non-local dependencies with `import 'package-link'`&lt;/span>\n\n&lt;!-- -->\n\n    const App = () => React.createElement(\"h1\", null, \"Hello, Programmers!\");\n    const target = document.querySelector(\"main\");\n    const app = React.createElement(App, null);\n    // Give React the element tree and the target\n    ReactDOM.render(app, target);\n\n-   &lt;span id=\"0693\">Remember when importing modules from other files you have to denote the file type in the import statement. HTML Original&lt;/span>\n\n&lt;!-- -->\n\n    &lt;section class=\"clue\">\n      &lt;h1 class=\"clue__title\">Clue$ 268530&lt;/h1>\n      &lt;div class=\"clue__question\">\n          2009: I dreamed a Dream\n      &lt;/div>\n      &lt;div class=\"clue__category\">\n          &lt;&lt;unparsed>>\n      &lt;/div>\n      &lt;div class=\"clue__amount\">\n          $800\n      &lt;/div>\n    &lt;/section>\n\nReact Version\n\n    const Clue = () =>\n      React.createElement(\n        \"section\",\n        { className: \"clue\" },\n        React.createElement(\"h1\", { className: \"clue__title\" }, \"Title\"),\n        React.createElement(\"div\", { className: \"clue__question\" }, \"?\"),\n        React.createElement(\"div\", { className: \"clue__category\" }, \"Category\"),\n        React.createElement(\"div\", { className: \"clue__amount\" }, \"$800\")\n      );\n\n-   &lt;span id=\"f587\">Because `class` is a reserved keyword in JS, in React we can use `className` to assign a class to an element.&lt;/span>\n-   &lt;span id=\"4d51\">Remember the data that goes into createElement: element type, data to pass into the element, and then children.&lt;/span>\n-   &lt;span id=\"8199\">`props` : Properties;&lt;/span>\n-   &lt;span id=\"6b53\">To handle certain values that are initially undefined, we can use `defaultProps`.&lt;/span>\n\n&lt;!-- -->\n\n    Clue.defaultProps = {\n      category: {},\n    };\n\n-   &lt;span id=\"4abe\">You can change in the devTools Network tab the internet speed to check for values that may be undefined to hangle with defaultProps.&lt;/span>\n-   &lt;span id=\"79e3\">If we fetch multiple pieces of data, we can render many things by using `map`.&lt;/span>\n-   &lt;span id=\"06f2\">You need to assign a unique key to each of the clues.&lt;/span>\n-   &lt;span id=\"c12e\">We need to keep track of them individually so that React can easily refer to a specific one if there is an issue. `clue => { key:clue.id, ...clue }`&lt;/span>\n\n&lt;!-- -->\n\n    const App = (props) =>\n      React.createElement(\n        \"h1\",\n        null,\n        props.clues.map((clue) =>\n          React.createElement(Clue, { key: clue.id, ...clue })\n        )\n      );\n    export default App;\n\n-   &lt;span id=\"1dd5\">Note: JSX is preferred over React.createElement;&lt;/span>\n\n---\n\n### Notes from Hello Programmer Exercise\n\n-   &lt;span id=\"1fb8\">When you import modules from websites they must have CORs activated.&lt;/span>\n-   &lt;span id=\"1ef6\">These import statements, import `global variables`.&lt;/span>\n-   &lt;span id=\"6613\">When we want to move our code into production we need to change the imports into the production minified versions.&lt;/span>\n\n&lt;!-- -->\n\n    import \"https://unpkg.com/react@16/umd/react.production.min.js\";\n    import \"https://unpkg.com/react-dom@16.13.1/umd/react-dom.production.min.js\";\n\n-   &lt;span id=\"0046\">While we will never actually be creating full apps with just React.createElement =&amp;gt; it is the enginer that is running under the hood!&lt;/span>\n\n&lt;!-- -->\n\n    import \"https://unpkg.com/react@16/umd/react.development.js\";\n    import \"https://unpkg.com/react-dom@16/umd/react-dom.development.js\";\n    const Links = () =>\n      React.createElement(\n        \"ul\",\n        { id: \"nav-links\" },\n        React.createElement(\n          \"li\",\n          { className: \"is-selected\" },\n          React.createElement(\"a\", { href: \"http://appacademy.io\" }, \"App Academy\")\n        ),\n        React.createElement(\n          \"li\",\n          null,\n          React.createElement(\"a\", { href: \"https://aaonline.io\" }, \"a/A Open\")\n        )\n      );\n    // Set up React Element: Type, Imported Data, Child (Child is Text in this Scenario)\n    // HelloWorld is a function based component\n    const HelloWorld = () => React.createElement(\"h1\", null, \"Hello, Programmers\");\n    const AllTogether = () =>\n      React.createElement(\n        \"div\",\n        null,\n        React.createElement(HelloWorld, null),\n        React.createElement(Links, null)\n      );\n    // Target the Element to append new Ele\n    const target = document.querySelector(\"main\");\n    // Assign your 'App' to your created Elements\n    // We are creating an element from the HelloWorld function.\n    const app = React.createElement(AllTogether, null);\n    // Render from the Virtual Dom to the Actual Dom\n    ReactDOM.render(app, target);</code></pre></div>\n<hr>\n<h3>Introduction to JSX</h3>\n<ul>\n<li><span id=\"a5ee\"><code class=\"language-text\">JSX</code> : Javascript Extension, a new language created by React developers to have an easier way of interacting with the React API. How to use JSX</span></li>\n<li><span id=\"24bf\">We will use <code class=\"language-text\">babel</code> to convert version of modern JS into an older version of JS. React Create Element</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const ExampleComponent = (props) =>\n  React.createElement(\n    React.Fragment,\n    null,\n    React.createElement(\"h1\", null, \"Hello!\"),\n    React.createElement(\"img\", { src: \"https://via.placeholder.com/150\" }),\n    React.createElement(\"a\", { href: props.searchUrl }, props.searchText)\n  );</code></pre></div>\n<p>JSX Version</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const ExampleComponent = (props) => (\n  &lt;React.Fragment>\n    &lt;h1>Hello!&lt;/h1>\n    &lt;img src=\"https://via.placeholder.com/150\" />\n    &lt;a href={props.searchUrl}>{props.searchText}&lt;/a>\n  &lt;/React.Fragment>\n);</code></pre></div>\n<ul>\n<li><span id=\"b00d\">Keep in mind that self closing tags in React must have a <code class=\"language-text\">forward slash</code> to close it.</span></li>\n</ul>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*NNxuFMF-sOL8Wvdl\" class=\"graf-image\" />\n</figure>- <span id=\"346d\">Properties and Data</span>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;img src=\"https://via.placeholder.com/150\" />;\n// becomes..\nReact.createElement(\"img\", { src: \"https://via.placeholder.com/150\" });\n// if we want to pass in data vs just a string literal\n&lt;a href={props.searchUrl}>{props.searchText}&lt;/a>;\n// so it becomes..\nReact.createElement(\"a\", { href: props.searchUrl }, props.searchText);\n// if you want the text search uppercase..\n&lt;a href={props.searchUrl}>{props.searchText.toUpperCase()}&lt;/a>;</code></pre></div>\n<ul>\n<li><span id=\"467c\">Comments in JSX have the following syntax:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;div>\n  &lt;h2>This is JSX&lt;/h2>\n  {/* This is a comment in JSX */}\n&lt;/div></code></pre></div>\n<ul>\n<li><span id=\"8cb8\"><code class=\"language-text\">Property Names</code>:</span></li>\n<li><span id=\"837b\"><code class=\"language-text\">checked</code> : Attribute of input components such as checkbox or radio, use it to set whether the component is checked or not.</span></li>\n<li><span id=\"aec0\"><code class=\"language-text\">className</code> : Used to specify a CSS class.</span></li>\n<li><span id=\"2f92\"><code class=\"language-text\">dangerouslySetInnerHTML</code> : React's equivalent of innerHTML because it is risky to cross-site scripting attacks.</span></li>\n<li><span id=\"3eab\"><code class=\"language-text\">htmlFor</code> : Because <code class=\"language-text\">for</code> is protected keyword, React elements use this instead.</span></li>\n<li><span id=\"9194\"><code class=\"language-text\">onChange</code> : Event fired whenever a form field is changed.</span></li>\n<li><span id=\"014a\"><code class=\"language-text\">style</code> : Accepts a JS object with camelCase properties rather than a CSS string.</span></li>\n<li><span id=\"76d8\"><code class=\"language-text\">value</code> : Supported by Input, Select, and TextArea components; use it to set the value of the component.</span></li>\n<li><span id=\"22c2\">Note: React uses camel-case!!! The JSX semicolon gotcha</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">function App() {\n  return (\n    &lt;div>\n      &lt;h1>Hello!&lt;/h1>\n      &lt;div>Welcome to JSX.&lt;/div>\n    &lt;/div>\n  );\n}</code></pre></div>\n<p>create Element equivalent</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">is equivalent to\nfunction App() {\n  return (\n    React.createElement(\n      'div',\n      null,\n      React.createElement('h1', null, 'Hello!'),\n      React.createElement('div', null, 'Welcome to JSX.'),\n    )\n  );\n}</code></pre></div>\n<ul>\n<li><span id=\"dbc1\">We wrap what want to return in parenthesis so JS doesn't auto add semi-colons after every line and run the code incorrectly.</span></li>\n<li><span id=\"62c0\">Just remember if you decided to use the return keyword in a function to 'return some JSX', then make sure you wrap the JSX in parenthesis.</span></li>\n</ul>\n<hr>\n<p><code class=\"language-text\">npx create-react-app my-app</code></p>\n<ul>\n<li><span id=\"8ad9\">Single line used to initiate a React application.</span></li>\n<li><span id=\"3cb1\">React has a great toolchain where you can see changes live as you're editing your application.</span></li>\n<li><span id=\"c1d0\">React errors will be rendered directly onto the browser window.</span></li>\n<li><span id=\"1365\">A downside is that it installs a lot of bloat files.</span></li>\n<li><span id=\"aaed\">Examples of React create Element and JSX equivalent</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">React.createElement(\n  \"a\",\n  {\n    className: \"active\",\n    href: \"https://appacademy.io\",\n  },\n  \"App Academy\"\n);\n// JSX Version\n&lt;a className=\"active\" href=\"https://appacademy.io\">\n  App Academy\n&lt;/a>;\n\nReact.createElement(\n  OwnerDetails,\n  {\n    owner: props.data.owner,\n    number: props.index + 1,\n  },\n  props.name\n);\n// JSX Version\n&lt;OwnerDetails owner={props.data.owner} number={props.index + 1}>\n  {props.name}\n&lt;/OwnerDetails>;</code></pre></div>\n<p>More Complex JSX Example</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const BookPanel = (props) => {\n  &lt;section className=\"book\" id={`book-${props.id}`}>\n    &lt;h1 className=\"book__title\">{props.title}&lt;/h1>\n    &lt;img src={props.coverUrl} />\n    &lt;div className=\"book__desc\">{props.description}&lt;/div>\n  &lt;/section>;\n};</code></pre></div>\n<hr>\n<h3>Notes</h3>\n<h3>Using Custom CRA Templates</h3>\n<p>Using a Custom Template <code class=\"language-text\">npx create-react-app my-app --template @appacademy/simple</code></p>\n<ul>\n<li><span id=\"9607\">Keep in mind that using <code class=\"language-text\">create-react-app</code> automatically initializes a git repository for you!</span></li>\n<li><span id=\"f0fe\">App Academy custom template for creating a react app.</span></li>\n<li><span id=\"1b4e\">If using the default react create project you can delete the following files:</span></li>\n<li><span id=\"ef1c\">favicon.ico</span></li>\n<li><span id=\"627b\">robots.txt</span></li>\n<li><span id=\"3b34\">logo192.png</span></li>\n<li><span id=\"9b50\">logo512.png</span></li>\n<li><span id=\"8101\">manifest.json</span></li>\n<li><span id=\"77db\">You can also simplify the <code class=\"language-text\">html</code> file into:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n  &lt;head>\n    &lt;meta charset=\"utf-8\" />\n    &lt;title>React App&lt;/title>\n  &lt;/head>\n  &lt;body>\n    &lt;div id=\"root\"></code></pre></div>\n</div>\n      </body>\n    </html>\n<p>Simplifying the src folder</p>\n<ul>\n<li><span id=\"ac69\">Remove: App.css App.test.js logo.svg serviceWorker.js setupTests.js</span></li>\n<li><span id=\"064f\">Update the Following Files:</span></li>\n</ul>\n<!-- -->\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// ./src/App.js\nimport React from \"react\";\nfunction App() {\n  return &lt;h1>Hello world!&lt;/h1>;\n}\nexport default App;\n``;\n\n// ./src/index.js\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport \"./index.css\";\nimport App from \"./App\";\nReactDOM.render(\n  &lt;React.StrictMode>\n    &lt;App />\n  &lt;/React.StrictMode>,\n  document.getElementById(\"root\")\n);</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">---\n\n### React Class Components\n\nClass Components\n\n-   &lt;span id=\"b5e6\">You can write React components using ES2015 Classes: Function Component&lt;/span>\n\n&lt;!-- -->\n\n    // ./src/Message.js\n    import React from \"react\";\n    const Message = (props) => {\n      return &lt;div>{props.text}&lt;/div>;\n    };\n    export default Message;\n\nES2015 Version\n\n    // ./src/Message.js\n    import React from \"react\";\n    class Message extends React.Component {\n      render() {\n        return &lt;div>{this.props.text}&lt;/div>;\n      }\n    }\n    export default Message;\n\n-   &lt;span id=\"ae33\">We can access props within a `class component` by using `this.props`&lt;/span>\n-   &lt;span id=\"0b60\">Keep in mind Class Components are used just like function components.&lt;/span>\n\n&lt;!-- -->\n\n    // ./src/index.js\n    import React from \"react\";\n    import ReactDOM from \"react-dom\";\n    import Message from \"./Message\";\n    ReactDOM.render(\n      &lt;React.StrictMode>\n        &lt;Message text=\"Hello world!\" />\n      &lt;/React.StrictMode>,\n      document.getElementById(\"root\")\n    );\n\nSetting and accessing props\n\n    class Message extends React.Component {\n      constructor(props) {\n        super(props);\n        // TODO Initialize state, etc.\n      }\n      render() {\n        return &lt;div>{this.props.text}&lt;/div>;\n      }\n    }\n\n-   &lt;span id=\"cd5a\">If we define a constructor method in our Class Component, we have to define the `super` method with `props` passed through it.&lt;/span>\n-   &lt;span id=\"8bf7\">Side Note: Before React used ES2015 Classes, it used `React.createclass` function, if you ever need to use this antiquated method make sure you install a module called `create-react-class` Stateful components&lt;/span>\n-   &lt;span id=\"4b12\">One of the major reasons why you would choose to use a Class Component over a Function Component is to add and manage local or internal state to your component.&lt;/span>\n-   &lt;span id=\"8e82\">Second of the major reasons is to be able to use a Class Component's lifecycle methods. What is state?&lt;/span>\n-   &lt;span id=\"7fab\">Props are data that are provided by the consumer or caller of the component.&lt;/span>\n-   &lt;span id=\"98f4\">Not meant to be changed by a component.&lt;/span>\n-   &lt;span id=\"c6a9\">State is data that is `internal` to the component.&lt;/span>\n-   &lt;span id=\"3e89\">Intended to be updated or mutated. When to use state&lt;/span>\n-   &lt;span id=\"c03f\">_Only Use State when it is absolutely necessary_&lt;/span>\n-   &lt;span id=\"204b\">If the data never changes, or if it's needed through an entire application use props instead.&lt;/span>\n-   &lt;span id=\"0b53\">State is more often used when creating components that retrieve data from APIs or render forms.&lt;/span>\n-   &lt;span id=\"1b6b\">The general rule of thumb: If a component doesn't need to use state or lifecyle methods, it should be prioritized as a `function component`.&lt;/span>\n-   &lt;span id=\"d708\">Functional:Stateless || Class:Stateful Initializing state&lt;/span>\n-   &lt;span id=\"e5d5\">Use a class constructor method to initialize `this.state` object. // Application Entry Point&lt;/span>\n\n&lt;!-- -->\n\n    // ./src/index.js\n    import React from 'react'\n    import ReactDOM from 'react-dom';\n    import RandomQuote from './RandomQuote';\n    ReactDOM.render(\n      &lt;React.StrictMode>\n        &lt;RandomQuote />\n      &lt;/React.StrictMode>\n      document.getElementById('root');\n    )\n\n// Class Component: RandomQuote\n\n    import React from \"react\";\n    class RandomQuote extends React.Component {\n      constructor() {\n        super();\n        const quotes = [\n          \"May the Force be with you.\",\n          \"There's no place like home.\",\n          \"I'm the king of the world!\",\n          \"My mama always said life was like a box of chocolates.\",\n          \"I'll be back.\",\n        ];\n        this.state = {\n          quotes,\n          currentQuoteIndex: this.getRandomInt(quotes.length);\n        }\n      }\n      getRandomInt(max) {\n        return Math.floor(Math.random() * Math.floor(max));\n      }\n      render() {\n        return (\n          &lt;div>\n            &lt;h2>Random Quote&lt;/h2>\n            &lt;p>{this.state.quotes[this.state.currentQuoteIndex]}&lt;/p>\n          &lt;/div>\n        )\n      }\n    }\n    export default RandomQuote;\n\nUpdating State\n\n-   &lt;span id=\"3fdc\">Let's say we want to update our state with a new quote.&lt;/span>\n-   &lt;span id=\"eddc\">We can set up event listeners in React similarly to how we did them before.&lt;/span>\n-   &lt;span id=\"106c\">&amp;lt;button type=\"button\" onClick={this.changeQuote}&amp;gt; Change Quote &amp;lt;/button&amp;gt;&lt;/span>\n-   &lt;span id=\"a77a\">`onClick` is the event listener.&lt;/span>\n-   &lt;span id=\"f406\">`{this.changeQuote}` is the event handler method.&lt;/span>\n-   &lt;span id=\"7dca\">Our Class Component File should now look like this with the new additions:&lt;/span>\n\n&lt;!-- -->\n\n    import React from \"react\";\n    class RandomQuote extends React.Component {\n      constructor() {\n        super();\n        const quotes = [\n          \"May the Force be with you.\",\n          \"There's no place like home.\",\n          \"I'm the king of the world!\",\n          \"My mama always said life was like a box of chocolates.\",\n          \"I'll be back.\",\n        ];\n        this.state = {\n          quotes,\n          currentQuoteIndex: this.getRandomInt(quotes.length);\n        }\n      }\n      changeQuote = () => {\n        const newIndex = this.getRandomInt(this.state.quotes.length);\n        // Setting the 'new state' of currentQuoteIndex state property\n        // to newly generated random index #.\n        this.setState({\n          currentQuoteIndex: newIndex;\n        })\n      }\n      getRandomInt(max) {\n        return Math.floor(Math.random() * Math.floor(max));\n      }\n      render() {\n        return (\n          &lt;div>\n            &lt;h2>Random Quote&lt;/h2>\n            &lt;p>{this.state.quotes[this.state.currentQuoteIndex]}&lt;/p>\n            &lt;button type=\"button\" onClick={this.changeQuote}>\n              Change Quote\n            &lt;/button>\n          &lt;/div>\n        )\n      }\n    }\n    export default RandomQuote;\n\nDon't modify state directly\n\n-   &lt;span id=\"ca27\">It is important to `never` modify your state directly!&lt;/span>\n-   &lt;span id=\"780d\">ALWAYS use `this.setState` method to update state.&lt;/span>\n-   &lt;span id=\"1581\">This is because when you only use this.state to re-assign, no re-rendering will occur =&amp;gt; leaving our component out of sync. Properly updating state from the previous state&lt;/span>\n-   &lt;span id=\"dc5a\">In our current example, the way we have `changeQuote` set up leaves us with occasionally producing the same index twice in a row.&lt;/span>\n-   &lt;span id=\"0bff\">One solution is to design a loop but keep in mind that state updates are handled asynchronously in React (your current value is not guaranteed to be the latest)&lt;/span>\n-   &lt;span id=\"39f9\">A safe method is to pass an anonymous method to `this.setState` (instead of an object literal) Previous&lt;/span>\n\n&lt;!-- -->\n\n    changeQuote = () => {\n        const newIndex = this.getRandomInt(this.state.quotes.length);\n        this.setState({\n          currentQuoteIndex: newIndex;\n        })\n      }\n\nPassing w/ Anon Method\n\n    changeQuote = () => {\n      this.setState((state, props) => {\n        const { quotes, currentQuoteIndex } = state;\n        let newIndex = -1;\n        do {\n          newIndex = this.getRandomInt(quote.length);\n        } while (newIndex === currentQuoteIndex);\n        return {\n          currentQuoteIndex: newIndex,\n        };\n      });\n    };\n\nProviding default values for props\n\n-   &lt;span id=\"7e8c\">In our current example, we pass in a static array of predefined quotes in our constructor.&lt;/span>\n-   &lt;span id=\"3e8f\">The way it is set up right now leaves our list of quotes unchanged after initialization.&lt;/span>\n-   &lt;span id=\"add0\">We can make quotes more dynamic by replacing our static array with a `props` argument passed into `super`.&lt;/span>\n-   &lt;span id=\"53d6\">constructor(props) { super(props); }&lt;/span>\n-   &lt;span id=\"918a\">We can now move our quotes array to our application entry point and pass it in as a prop. // Application Entry Point&lt;/span>\n\n&lt;!-- -->\n\n    // ./src/index.js\n    import React from 'react'\n    import ReactDOM from 'react-dom';\n    import RandomQuote from './RandomQuote';\n    // Re-assign our array here and pass it in as a prop in Render.\n    const quotes = [\n          \"May the Force be with you.\",\n          \"There's no place like home.\",\n          \"I'm the king of the world!\",\n          \"My mama always said life was like a box of chocolates.\",\n          \"I'll be back.\",\n          \"This way I can define more quotes\",\n        ];\n    ReactDOM.render(\n      &lt;React.StrictMode>\n        &lt;RandomQuote quotes={quotes}/>\n      &lt;/React.StrictMode>\n      document.getElementById('root');\n    )\n\n-   &lt;span id=\"a0bb\">One thing to note about this workaround is that the caller of the component _must_ set the quotes prop or the component will throw an error =&amp;gt; so use `defaultProps`!&lt;/span>\n\n&lt;!-- -->\n\n    // At the bottom of RandomQuote.js...\n    RandomQuote.defaultProps = {\n      quotes: [\n        \"May the Force be with you.\",\n        \"There's no place like home.\",\n        \"I'm the king of the world!\",\n        \"My mama always said life was like a box of chocolates.\",\n        \"I'll be back.\",\n        \"This way I can define more quotes\",\n      ],\n    };\n\n-   &lt;span id=\"c575\">A good safety net in case the consumer/caller doesn't provide a value for the quotes array.&lt;/span>\n-   &lt;span id=\"3be6\">We can even remove it from our index.js now and an error will not be thrown.&lt;/span>\n\n---\n\n### Handling Events\n\n-   &lt;span id=\"a82e\">To add an event listener to an element, just define a method to handle the event and associate that method with the element event you are listening for. Example&lt;/span>\n\n&lt;!-- -->\n\n    import React from \"react\";\n    class AlertButton extends React.Component {\n      showAlert = () => {\n        window.alert(\"Button Clicked!\");\n      };\n      render() {\n        return (\n          &lt;button type=\"button\" onClick={this.showAlert}>\n            Submit\n          &lt;/button>\n        );\n      }\n    }\n\n-   &lt;span id=\"a852\">Note that when refering the handler method in onClick we're not invoking showAlert simply just passing a reference. Preventing default behavior&lt;/span>\n-   &lt;span id=\"5cb0\">HTML Elements in the browser often have a lot of default behavior.&lt;/span>\n-   &lt;span id=\"df4d\">I.E. Clicking on an `&lt;a>` element navigates so a resource denoted by `&lt;href>` property.&lt;/span>\n-   &lt;span id=\"952c\">Here is an example of where using `e.preventDefault()` could come in handy.&lt;/span>\n\n&lt;!-- -->\n\n    import React from \"react\";\n    class NoDefaultSubmitForm extends React.Component {\n      submitForm = (e) => {\n        e.preventDefault();\n        window.alert(\"Handling form submission...\");\n      };\n      render() {\n        return (\n        &lt;form onSubmit={this.submitForm}>\n          &lt;button>Submit&lt;/button>\n        &lt;/form>;\n        )}\n    }\n\n-   &lt;span id=\"b149\">The button contained within the form will end up refreshing the page before `this.submitForm` method can be completed.&lt;/span>\n-   &lt;span id=\"a034\">We can stick an `e.preventDefault()` into the actual method to get around this problem.&lt;/span>\n-   &lt;span id=\"004a\">`e` : Parameter that references a `Synthetic Event` object type. Using `this` in event handlers&lt;/span>\n\n&lt;!-- -->\n\n    // ./src/AlertButton.js\n    import React from \"react\";\n    class AlertButton extends React.Component {\n      showAlert = () => {\n        window.alert(\"Button clicked!\");\n        console.log(this);\n      };\n      render() {\n        return (\n          &lt;button type=\"button\" onClick={this.showAlert}>\n            Click Me\n          &lt;/button>\n        );\n      }\n    }\n    export default AlertButton;\n\n-   &lt;span id=\"3c8f\">When we console log `this` we see the AlertButton object.&lt;/span>\n-   &lt;span id=\"42a0\">If we were to write the showAlert method with a regular class method like:&lt;/span>\n\n&lt;!-- -->\n\n    showAlert() {\n      console.log(this);\n    }\n\n-   &lt;span id=\"c081\">We would get `undefined` =&amp;gt; remember that fat arrow binds to the current context! Reviewing class methods and the `this` keyword&lt;/span>\n-   &lt;span id=\"e98e\">Let's refresh on binding.&lt;/span>\n\n&lt;!-- -->\n\n    class Boyfriend {\n      constructor() {\n        this.name = \"Momato Riruru\";\n      }\n      displayName() {\n        console.log(this.name);\n      }\n    }\n    const Ming = new Boyfriend();\n    Ming.displayName(); // => Momato Riruru\n    const displayAgain = Ming.displayName;\n    displayAgain(); // => Result in a Type Error: Cannot read property 'name' of undefined.\n\n-   &lt;span id=\"fb85\">The first time we use our `displayMethod` call, it is called directly on the instance of the boyfriend class, which is why `Momato Riruru` was printed out.&lt;/span>\n-   &lt;span id=\"3a9b\">The second time it was called, the ref of the method is stored as a variable and method is called on that variable instead of the instance; resulting in a type error (it has lost it's context)&lt;/span>\n-   &lt;span id=\"0a2c\">Remember we can use the `bind` method to rebind context!&lt;/span>\n-   &lt;span id=\"d6d9\">We can refactor to get the second call working like this:&lt;/span>\n-   &lt;span id=\"7ead\">const displayAgain = Ming.displayName.bind(Ming); displayAgain(); // =&amp;gt; Now Momato Riruru will be printed out.&lt;/span>\n-   &lt;span id=\"a8b0\">To continue using function declarations vs fat arrow we can assign context in a constructor within a class component.&lt;/span>\n\n&lt;!-- -->\n\n    import React from \"react\";\n    class AlertButton extends React.Component {\n      constructor() {\n        super();\n        this.showAlert = this.showAlert.bind(this); // binding context\n      }\n      showAlert() {\n        console.log(this);\n      }\n      render() {\n        return (\n          &lt;button type=\"button\" onClick={this.showAlert}>\n            Submit\n          &lt;/button>\n        );\n      }\n    }\n    export default AlertButton;\n\n-   &lt;span id=\"a4e6\">`Experimental Syntax` : Syntax that has been proposed to add to ECMAScript but hasn't officially been added to the language specification yet.&lt;/span>\n-   &lt;span id=\"801d\">It's good to pick one approach and use it consistently, either:&lt;/span>\n\n1.  &lt;span id=\"2e3e\">Class Properties &amp; Arrow Functions&lt;/span>\n2.  &lt;span id=\"cc27\">Bind Method &amp; This Keyword The `SyntheticEvent` object&lt;/span>\n\n-   &lt;span id=\"f177\">Synthetic Event Objects: Cross Browser wrappeds around the browser's native event.&lt;/span>\n-   &lt;span id=\"418f\">Includes the use of stopPropagation() and preventDefault();&lt;/span>\n-   &lt;span id=\"b94f\">Attributes of the Synthetic Event Object:Attributesboolean bubblesboolean cancelableDOMEventTarget currentTargetboolean defaultPreventednumber eventPhaseboolean isTrustedDOMEvent nativeEventvoid preventDefault()boolean isDefaultPrevented()void stopPropagation()boolean isPropagationStopped()void persist()DOMEventTarget targetnumber timeStampstring type&lt;/span>\n-   &lt;span id=\"7484\">`nativeEvent` : property defined in a synthetic event object that gives you access to the underlying native browser event (rarely used!)&lt;/span>\n\n---\n\n### Forms in React\n\n_Exercise being done in a separate file_ Random Notes\n\n-   &lt;span id=\"45ec\">`onChange` : detects when a value of an input element changes.&lt;/span>\n-   &lt;span id=\"9ca4\">Assigning `onChange` to our input fields makes our component's state update in real time during user input.&lt;/span>\n-   &lt;span id=\"eb83\">Dont forget to add `preventDefault` onto form submissions to deal with the default behavior of the browser refreshing the page!&lt;/span>\n-   &lt;span id=\"c413\">`submittedOn: new Date(),` Can be added to a form, most likely will persist into a DB.&lt;/span>\n-   &lt;span id=\"b97f\">Controlled Components&lt;/span>\n-   &lt;span id=\"ac48\">We use the `onChange` event handlers on form fields to keep our component's state as the `\"one source of truth\"`&lt;/span>\n-   &lt;span id=\"4685\">Adding an `onChange` event handler to every single input can massively bloat your code.&lt;/span>\n-   &lt;span id=\"448c\">Try assiging it to it's own method to apply everywhere.&lt;/span>\n-   &lt;span id=\"f229\">`textarea` is handled differently in react: it takes in a value property to handle what the inner text will be.&lt;/span>\n\n&lt;!-- -->\n\n    // ./src/ContactUs.js\n    import React from \"react\";\n    class ContactUs extends React.Component {\n      constructor() {\n        super();\n        this.state = {\n          name: \"\",\n          email: \"\",\n          phone: \"\",\n          phoneType: \"\",\n          comments: \"\",\n          validationErrors: [],\n        };\n      }\n      onChange = (e) => {\n        const { name, value } = e.target;\n        this.setState({ [name]: value });\n      };\n      // Vanilla JS Function for validating inputs\n      validate(name, email) {\n        const validationErrors = [];\n        if (!name) {\n          validationErrors.push(\"Please provide a Name\");\n        }\n        if (!email) {\n          validationErrors.push(\"Please provide an Email\");\n        }\n        return validationErrors;\n      }\n      onSubmit = (e) => {\n        // Prevent the default form behavior\n        // so the page doesn't reload.\n        e.preventDefault();\n        // Retrieve the contact us information from state.\n        const { name, email, phone, phoneType, comments } = this.state;\n        // Get Validation Errors - proceeding destructuring values from this.state.\n        const validationErrors = this.validate(name, email);\n        // If we have errors...\n        if (validationErrors.length > 0) {\n          this.setState({ validationErrors });\n        } else {\n          // Proceed normally\n          // Create a new object for the contact us information.\n          const contactUsInformation = {\n            name,\n            email,\n            phone,\n            phoneType,\n            comments,\n            submittedOn: new Date(),\n          };\n          console.log(contactUsInformation);\n          // Reset the form state.\n          this.setState({\n            name: \"\",\n            email: \"\",\n            phone: \"\",\n            phoneType: \"\",\n            comments: \"\",\n            validationErrors: [],\n          });\n        }\n      };\n      render() {\n        const { name, email, phone, phoneType, comments, validationErrors } =\n          this.state;\n        return (\n          &lt;div>\n            &lt;h2>Contact Us&lt;/h2>\n            {validationErrors.length > 0 &amp;&amp; (\n              &lt;div>\n                The following errors were found:\n                &lt;ul>\n                  {validationErrors.map((error) => (\n                    &lt;li key={error}>{error}&lt;/li>\n                  ))}\n                &lt;/ul>\n              &lt;/div>\n            )}\n            &lt;form onSubmit={this.onSubmit}>\n              &lt;div>\n                &lt;label htmlFor=\"name\">Name:&lt;/label>\n                &lt;input\n                  id=\"name\"\n                  name=\"name\"\n                  type=\"text\"\n                  onChange={this.onChange}\n                  value={name}\n                />\n              &lt;/div>\n              &lt;div>\n                &lt;label htmlFor=\"email\">Email:&lt;/label>\n                &lt;input\n                  id=\"email\"\n                  name=\"email\"\n                  type=\"text\"\n                  onChange={this.onChange}\n                  value={email}\n                />\n              &lt;/div>\n              &lt;div>\n                &lt;label htmlFor=\"phone\">Phone:&lt;/label>\n                &lt;input\n                  id=\"phone\"\n                  name=\"phone\"\n                  type=\"text\"\n                  onChange={this.onChange}\n                  value={phone}\n                />\n                &lt;select name=\"phoneType\" onChange={this.onChange} value={phoneType}>\n                  &lt;option value=\"\">Select a phone type...&lt;/option>\n                  {this.props.phoneTypes.map((phoneType) => (\n                    &lt;option key={phoneType}>{phoneType}&lt;/option>\n                  ))}\n                &lt;/select>\n              &lt;/div>\n              &lt;div>\n                &lt;label htmlFor=\"comments\">Comments:&lt;/label>\n                &lt;textarea\n                  id=\"comments\"\n                  name=\"comments\"\n                  onChange={this.onChange}\n                  value={comments}\n                />\n              &lt;/div>\n              &lt;div>\n                &lt;button>Submit&lt;/button>\n              &lt;/div>\n            &lt;/form>\n          &lt;/div>\n        );\n      }\n    }\n    ContactUs.defaultProps = {\n      phoneTypes: [\"Home\", \"Work\", \"Mobile\"],\n    };\n    export default ContactUs;\n\n-   &lt;span id=\"a2da\">We can use validation libraries like `validate` to make our validation functions more complex.&lt;/span>\n\n&lt;!-- -->\n\n    import isEmail from \"validator/es/lib/isEmail\";\n      validate(name, email) {\n        const validationErrors = [];\n        if (!name) {\n          validationErrors.push(\"Please provide a Name\");\n        }\n        if (!email) {\n          validationErrors.push(\"Please provide an Email\");\n        } else if (!isEmail(email)) {\n          validationErrors.push(\"Please provide a valid Email\");\n        }\n        return validationErrors;\n      }\n\nNote About Client-side vs server-side validation\n\n-   &lt;span id=\"5808\">Server-side validation is not optional.&lt;/span>\n-   &lt;span id=\"3bb8\">Tech-savvy users can manipulate client-side validations.&lt;/span>\n-   &lt;span id=\"311f\">Sometimes the 'best approach' is to skip implementing validations on the client-side and rely completely on the server-side validation.&lt;/span>\n\n---\n\n### Component Lifecycle\n\n&lt;figure>\n&lt;img src=\"https://cdn-images-1.medium.com/max/800/0*c24XQBvqBBg0Eztz\" class=\"graf-image\" />\n&lt;/figure>- &lt;span id=\"e1d9\">Component Lifecycle is simply a way of describing the key moments in the lifetime of a component.&lt;/span>\n\n1.  &lt;span id=\"8e64\">Loading (Mounting)&lt;/span>\n2.  &lt;span id=\"7e94\">Updating&lt;/span>\n3.  &lt;span id=\"2cd3\">Unloading (Unmounting) The lifecycle of a React component&lt;/span>\n\n-   &lt;span id=\"7740\">Each `Class Component` has several `lifecycle methods` that you can add to run code at specific times.&lt;/span>\n-   &lt;span id=\"e7d0\">`componentDidMount` : Method called after your component has been added to the component tree.&lt;/span>\n-   &lt;span id=\"6d92\">`componentDidUpdate` : Method called after your component has been updated.&lt;/span>\n-   &lt;span id=\"9ee2\">`componentWillUnmount` : Method called just before your component is removed from the component tree.&lt;/span>\n-   &lt;span id=\"7bd8\">`Mounting`&lt;/span>\n\n1.  &lt;span id=\"6f9e\">`constructor` method is called&lt;/span>\n2.  &lt;span id=\"e9c7\">`render` method is called&lt;/span>\n3.  &lt;span id=\"eef3\">React updates the `DOM`&lt;/span>\n4.  &lt;span id=\"19bb\">`componentDidMount` is called&lt;/span>\n\n-   &lt;span id=\"85f1\">`Updating`&lt;/span>\n-   &lt;span id=\"94f5\">When component receives new `props`&lt;/span>\n\n1.  &lt;span id=\"e635\">`render` method is called&lt;/span>\n2.  &lt;span id=\"70f9\">React updates the `DOM`&lt;/span>\n3.  &lt;span id=\"9507\">`componentDidUpdate` is called&lt;/span>\n\n-   &lt;span id=\"b00a\">When `setState` is called&lt;/span>\n\n1.  &lt;span id=\"6864\">`render` method is called&lt;/span>\n2.  &lt;span id=\"e13b\">React updates the `DOM`&lt;/span>\n3.  &lt;span id=\"c459\">`componentDidUpdate` is called&lt;/span>\n\n-   &lt;span id=\"bfdd\">`Unmounting`&lt;/span>\n-   &lt;span id=\"10c1\">The moment before a class component is removed from the component tree:&lt;/span>\n-   &lt;span id=\"c214\">`componentDidMount` will be called. Avoiding the legacy lifecycle methods&lt;/span>\n-   &lt;span id=\"d438\">Occasionally you will encounter some deprecated lifecycle methods:&lt;/span>\n-   &lt;span id=\"1f6b\">UNSAFE_componentWillMount&lt;/span>\n-   &lt;span id=\"48ac\">UNSAFE_componentWillReceiveProps&lt;/span>\n-   &lt;span id=\"df27\">UNSAFE_componentWillUpdate&lt;/span>\n-   &lt;span id=\"af07\">Just know they will be removed soon from React's API, peace. Using the class component lifecycle methods _Exercise done in sep. directory_&lt;/span>\n-   &lt;span id=\"344c\">Assorted Notes:&lt;/span>\n-   &lt;span id=\"d6b1\">Common Use for `componentDidMount` lifecycle method is for fetching data from an API.&lt;/span>\n\n---\n\n—\n\n### Notes\n\n### React Context\n\n-   &lt;span id=\"e968\">You can use `React Context` to pass data through a component tree without having to manually thread props.&lt;/span>\n-   &lt;span id=\"89d9\">Convenient way to share &amp; update `global data`. Creating a Context&lt;/span>\n\n&lt;!-- -->\n\n    // PupContext.js\n    import { createContext } from \"react\";\n    const PupContext = createContext();\n    export default PupContext;\n\n-   &lt;span id=\"a8bf\">We use `React.createContext` to create context.&lt;/span>\n-   &lt;span id=\"98b9\">Keep in mind if you invoke this method with aruguments, those arguments will be set as default context. Adding a Provider to the App component&lt;/span>\n-   &lt;span id=\"a919\">In order to pass context over to child components we need to wrap them in a provider component.&lt;/span>\n-   &lt;span id=\"9afc\">The provider component takes in a value property that points to the information that needs to be passed to the children.&lt;/span>\n\n&lt;!-- -->\n\n    &lt;MyContext.Provider value={/* some value */}>\n      &lt;ChildComponent />\n    &lt;/MyContext.Provider>\n\nSetting up a Consumer\n\n    &lt;MyContext.Consumer>\n      {(value) => &lt;Component value={value} />}\n    &lt;/MyContext.Consumer>\n\n-   &lt;span id=\"2693\">Keep in mind that `Context.Consumer` expects a function as a child.&lt;/span>\n-   &lt;span id=\"19fc\">The function has a value prop passed in from `Context.Provider`&lt;/span>\n\n---\n\n### Notes\n\n### Redux Explained\n\n-   &lt;span id=\"eab4\">JS Framework for managing the frontend state of a web application.&lt;/span>\n-   &lt;span id=\"3c8b\">Gives us ability to store information in an organized manner in a web app and quickly retrieve that information from anywhere in the app.&lt;/span>\n-   &lt;span id=\"695d\">`Redux`&lt;/span>\n-   &lt;span id=\"00d5\">Client Side Data Management&lt;/span>\n-   &lt;span id=\"dd41\">Controls \"Frontend State\"&lt;/span>\n-   &lt;span id=\"d828\">NOT Your Database&lt;/span>\n-   &lt;span id=\"855a\">NOT Component State&lt;/span>\n-   &lt;span id=\"4c1a\">Just used for managing Data&lt;/span>\n\n&lt;figure>\n&lt;img src=\"https://cdn-images-1.medium.com/max/800/0*N7KFfhOZZ7UrY8s4\" class=\"graf-image\" />\n&lt;/figure>- &lt;span id=\"04c0\">Visual of how an app without React manages it's data.&lt;/span>\n- &lt;span id=\"bae2\">A lot of prop threading happening.&lt;/span>\n- &lt;span id=\"989f\">Data stored in a sep. location — `global data`. The Anatomy of Redux&lt;/span>\n- &lt;span id=\"cd66\">`Store`&lt;/span>\n- &lt;span id=\"9453\">Holds the Frontend State&lt;/span>\n- &lt;span id=\"cea4\">Provides an API for the Frontend State&lt;/span>\n- &lt;span id=\"c653\">`Action`&lt;/span>\n- &lt;span id=\"7fb4\">POJOs&lt;/span>\n- &lt;span id=\"69a1\">Outline Changes to Frontend State&lt;/span>\n- &lt;span id=\"1a0a\">`Reducers`&lt;/span>\n- &lt;span id=\"a372\">Functions&lt;/span>\n- &lt;span id=\"8bb8\">Make Changes to Frontend State Where did Redux come from?&lt;/span>\n- &lt;span id=\"6d0b\">There are three central philosophies of Redux:&lt;/span>\n\n1.  &lt;span id=\"12ac\">`A Single Source of Truth` : state is stored in a POJO&lt;/span>\n2.  &lt;span id=\"d178\">`State is Read Only` : State is immutable, modified by dispatching actions.&lt;/span>\n3.  &lt;span id=\"51c5\">`Changes are Made with Pure Functions` : Reducers that receive the actions and return updated state are pure functions of the old state and action. When is it appropriate to use Redux?&lt;/span>\n\n-   &lt;span id=\"117f\">When doing a project with simpler global state requirements, it may be better to choose React's Context API over Redux.&lt;/span>\n-   &lt;span id=\"5d3d\">Redux offers more flexibility and support for middleware along with richer developer tools. Vocabulary&lt;/span>\n-   &lt;span id=\"1ceb\">`State`&lt;/span>\n-   &lt;span id=\"49e7\">_Redux is a State Manager_&lt;/span>\n-   &lt;span id=\"5018\">State is all the information stored by that program at a particular point in time.&lt;/span>\n-   &lt;span id=\"8fdb\">Redux's main job is to store the state and make it directly available to your entire app.&lt;/span>\n-   &lt;span id=\"8bbd\">`Store`&lt;/span>\n-   &lt;span id=\"f027\">_Redux stores state in a single store_.&lt;/span>\n-   &lt;span id=\"c97e\">Redux store is a single JS object with a couple of methods (not a class!)&lt;/span>\n-   &lt;span id=\"199d\">Methods include: `getState`, `dispatch(action)`, and `subscribe(listener)`&lt;/span>\n-   &lt;span id=\"8bcf\">`Actions`&lt;/span>\n-   &lt;span id=\"2049\">_Redux store is updated by dispatching actions_&lt;/span>\n-   &lt;span id=\"cbac\">Action is just a POJO that includes a mandatory `type` property.&lt;/span>\n-   &lt;span id=\"f2d5\">Contain info to update the store.&lt;/span>\n-   &lt;span id=\"1bd9\">We dispatch actions in response to User actions or AJAX requests.&lt;/span>\n-   &lt;span id=\"1b78\">`Pure Functions`&lt;/span>\n-   &lt;span id=\"c436\">_Redux Reducers are Pure Functions_&lt;/span>\n-   &lt;span id=\"e204\">Functions are pure when their behavior depends only on it's arguments as has no side effects.&lt;/span>\n-   &lt;span id=\"450b\">Simply takes in an argument and outputs a value.&lt;/span>\n-   &lt;span id=\"e146\">`Reducer`&lt;/span>\n-   &lt;span id=\"9721\">_Redux handles actions using reducers_&lt;/span>\n-   &lt;span id=\"c312\">A function that is called each time an action is dispatched.&lt;/span>\n-   &lt;span id=\"84d8\">Takes in an `action` and `current state`&lt;/span>\n-   &lt;span id=\"90a3\">Required to be pure functions so their behavior is predictable.&lt;/span>\n-   &lt;span id=\"5c36\">`Middleware`&lt;/span>\n-   &lt;span id=\"6b22\">_Customize response to dispatch actions by using Middleware_&lt;/span>\n-   &lt;span id=\"9287\">Middleware is an optional component of Redus that allows custom responses to dispatched actions.&lt;/span>\n-   &lt;span id=\"f953\">Most common use is to dispatch async requests to a server.&lt;/span>\n-   &lt;span id=\"773e\">`Time Traveling Dev Tools`&lt;/span>\n-   &lt;span id=\"d703\">_Redux can time travel wow_&lt;/span>\n-   &lt;span id=\"7187\">Time travel refers to Redux's ability to revert to a previous state because reducers are all pure functions.&lt;/span>\n-   &lt;span id=\"ada3\">`Thunks`&lt;/span>\n-   &lt;span id=\"ee0f\">_Convenient format for taking async actions in Redux_&lt;/span>\n-   &lt;span id=\"586e\">General concept in CS referring to a function who's primary purpose is to call another function.&lt;/span>\n-   &lt;span id=\"6f45\">Most commonly used to make async API requests.&lt;/span>\n\n---\n\n### Flux and Redux\n\nWhat is Flux?\n\n-   &lt;span id=\"06d1\">Front-end application architecutre.&lt;/span>\n-   &lt;span id=\"8311\">A pattern in which to structure an application.&lt;/span>\n-   &lt;span id=\"05e6\">Unidirectional Data Flow — offers more predictability.&lt;/span>\n-   &lt;span id=\"751c\">`Actions` : Begins the data flow of data, simple object that contains a type; type indicates the type of change to be performed.&lt;/span>\n-   &lt;span id=\"e8e7\">`Dispatcher` : Mechanism for distributing actions to the store.&lt;/span>\n-   &lt;span id=\"af4f\">`Store` : The entire state of the application, responsible for updating the state of your app.&lt;/span>\n-   &lt;span id=\"d7ff\">`View` : Unit of code that's responsible for rendering the user interface. Used to re-render the application when actions and changes occur.&lt;/span>\n\n&lt;figure>\n&lt;img src=\"https://cdn-images-1.medium.com/max/800/0*ywV6dO4a4QcGJxK5\" class=\"graf-image\" />\n&lt;/figure>- &lt;span id=\"af94\">Redux&lt;/span>\n\n&lt;figure>\n&lt;img src=\"https://cdn-images-1.medium.com/max/800/0*Nd73GjTY1PVQtjtQ\" class=\"graf-image\" />\n&lt;/figure>- &lt;span id=\"dc16\">Library that facilitates the implementation of Flux.&lt;/span>\n- &lt;span id=\"623a\">Redux Three Principles&lt;/span>\n- &lt;span id=\"2ac6\">`Single Source of Truth`&lt;/span>\n- &lt;span id=\"a2b9\">`State is Read-Only`&lt;/span>\n- &lt;span id=\"897b\">`Only Pure Functions Change State`&lt;/span>\n\n---\n\n### Store\n\n-   &lt;span id=\"cd1e\">Simply an object that holds the application state wrapped in an API.&lt;/span>\n-   &lt;span id=\"f57c\">`Three methods`:&lt;/span>\n-   &lt;span id=\"354c\">`getState()` : Returns the store's current state.&lt;/span>\n-   &lt;span id=\"537c\">`dispatch(action)` : Passes an action into the store's reducer to tell it what info to update.&lt;/span>\n-   &lt;span id=\"4539\">`subscribe(callback)` : Registers a callback to be triggered whenever the store updates. Updating the Store&lt;/span>\n\n&lt;!-- -->\n\n    store.dispatch(action);\n    // Add Orange Action\n    const addOrange = {\n      type: \"ADD_FRUIT\",\n      fruit: \"orange\",\n    };\n    // Reducer for Orange Action\n    const fruitReducer = (state = [], action) => {\n      switch (action.type) {\n        case \"ADD_FRUIT\":\n          return [...state, action.fruit];\n        default:\n          return state;\n      }\n    };\n    // Run the Dispatch\n    console.log(store.getState()); // []\n    store.dispatch(addOrange);\n    console.log(store.getState()); // [ 'orange' ]\n\nSubscribing to the store\n\n-   &lt;span id=\"1a02\">Whenever a store process a dispatch(), it triggers all its subscribers.&lt;/span>\n-   &lt;span id=\"e667\">`Subscribers` : callbacks that can be added to the store via subscribe().&lt;/span>\n\n&lt;!-- -->\n\n    const display = () => {\n      console.log(store.getState());\n    };\n    const unsubscribeDisplay = store.subscribe(display);\n    store.dispatch(addOrange); // [ 'orange', 'orange' ]\n    // display will no longer be invoked after store.dispatch()\n    unsubscribeDisplay();\n    store.dispatch(addOrange); // no output\n\nReviewing a simple example\n\n    // app.js\n    const { createStore } = require(\"redux\");\n    // Define the store's reducer.\n    const fruitReducer = (state = [], action) => {\n      switch (action.type) {\n        case \"ADD_FRUIT\":\n          return [...state, action.fruit];\n        default:\n          return state;\n      }\n    };\n    // Create the store.\n    const store = createStore(fruitReducer);\n    // Define an 'ADD_FRUIT' action for adding an orange to the store.\n    const addOrange = {\n      type: \"ADD_FRUIT\",\n      fruit: \"orange\",\n    };\n    // Log to the console the store's state before and after\n    // dispatching the 'ADD_FRUIT' action.\n    console.log(store.getState()); // []\n    store.dispatch(addOrange);\n    console.log(store.getState()); // [ 'orange' ]\n    // Define and register a callback to listen for store updates\n    // and console log the store's state.\n    const display = () => {\n      console.log(store.getState());\n    };\n    const unsubscribeDisplay = store.subscribe(display);\n    // Dispatch the 'ADD_FRUIT' action. This time the `display` callback\n    // will be called by the store when its state is updated.\n    store.dispatch(addOrange); // [ 'orange', 'orange' ]\n    // Unsubscribe the `display` callback to stop listening for store updates.\n    unsubscribeDisplay();\n    // Dispatch the 'ADD_FRUIT' action one more time\n    // to confirm that the `display` method won't be called\n    // when the store state is updated.\n    store.dispatch(addOrange); // no output\n\n### Reducers\n\n-   &lt;span id=\"98f3\">Reducer function receives the current `state` and `action`, updates the state appropriately based on the `action.type` and returns the following state.&lt;/span>\n-   &lt;span id=\"4cee\">You can bundles different action types and ensuing logic by using a switch/case statement.&lt;/span>\n\n&lt;!-- -->\n\n    const fruitReducer = (state = [], action) => {\n      switch (action.type) {\n        case \"ADD_FRUIT\":\n          return [...state, action.fruit];\n        case \"ADD_FRUITS\":\n          return [...state, ...action.fruits];\n        case \"SELL_FRUIT\":\n          const index = state.indexOf(action.fruit);\n          if (index !== -1) {\n            // remove first instance of action.fruit\n            return [...state.slice(0, index), ...state.slice(index + 1)];\n          }\n          return state; // if action.fruit is not in state, return previous state\n        case \"SELL_OUT\":\n          return [];\n        default:\n          return state;\n      }\n    };\n\nReviewing how Array\\#slice works\n\n    const fruits = [\"apple\", \"apple\", \"orange\", \"banana\", \"watermelon\"];\n    // The index of the 'orange' element is 2.\n    const index = fruits.indexOf(\"orange\");\n    // `...fruits.slice(0, index)` returns the array ['apple', 'apple']\n    // `...fruits.slice(index + 1)` returns the array ['banana', 'watermelon']\n    // The spread syntax combines the two array slices into the array\n    // ['apple', 'apple', 'banana', 'watermelon']\n    const newFruits = [...fruits.slice(0, index), ...fruits.slice(index + 1)];\n\n-   &lt;span id=\"f322\">Approach that can be used to remove an element without mutating the original array. Avoiding state mutations&lt;/span>\n-   &lt;span id=\"f862\">Your reducer must always return a new object if the state changes. GOOD&lt;/span>\n\n&lt;!-- -->\n\n    const goodReducer = (state = { count: 0 }, action) => {\n      switch (action.type) {\n        case \"INCREMENT_COUNTER\":\n          const nextState = Object.assign({}, state);\n          nextState.count++;\n          return nextState;\n        default:\n          return state;\n      }\n    };\n\nBAD\n\n    const badReducer = (state = { count: 0 }, action) => {\n      switch (action.type) {\n        case \"INCREMENT_COUNTER\":\n          state.count++;\n          return state;\n        default:\n          return state;\n      }\n    };\n\n---\n\n### Actions\n\n-   &lt;span id=\"64b4\">Actions are the only way to trigger changes to the store's state. Using action creators&lt;/span>\n\n&lt;!-- -->\n\n    const addOrange = {\n      type: \"ADD_FRUIT\",\n      fruit: \"orange\",\n    };\n    store.dispatch(addOrange);\n    console.log(store.getState()); // [ 'orange' ]\n\n-   &lt;span id=\"c39d\">fruit is the `payload key` and orange is the `state data`&lt;/span>\n-   &lt;span id=\"43e2\">`Action Creators` : Functions created from extrapolating the creation of an action object.&lt;/span>\n\n&lt;!-- -->\n\n    const addFruit = (fruit) => ({\n      type: \"ADD_FRUIT\",\n      fruit,\n    });\n\n-   &lt;span id=\"11fd\">Use parenthesis for implicit return value.&lt;/span>\n-   &lt;span id=\"eea8\">We can now add whatever fruit we'd like.&lt;/span>\n\n&lt;!-- -->\n\n    store.dispatch(addFruit(\"apple\"));\n    store.dispatch(addFruit(\"strawberry\"));\n    store.dispatch(addFruit(\"lychee\"));\n    console.log(store.getState()); // [ 'orange', 'apple', 'strawberry', 'lychee' ]\n\nPreventing typos in action type string literals\n\n    const ADD_FRUIT = \"ADD_FRUIT\";\n    const ADD_FRUITS = \"ADD_FRUITS\";\n    const SELL_FRUIT = \"SELL_FRUIT\";\n    const SELL_OUT = \"SELL_OUT\";\n    const addFruit = (fruit) => ({\n      type: ADD_FRUIT,\n      fruit,\n    });\n    const addFruits = (fruits) => ({\n      type: ADD_FRUITS,\n      fruits,\n    });\n    const sellFruit = (fruit) => ({\n      type: SELL_FRUIT,\n      fruit,\n    });\n    const sellOut = () => ({\n      type: SELL_OUT,\n    });\n\n-   &lt;span id=\"ae86\">Using constant variables helps reduce simple typos in a reducer's case clauses.&lt;/span>\n\n---\n\n### Debugging Arrow Functions\n\n-   &lt;span id=\"43c6\">It is important to learn how to use debugger statements with arrow functions to effectively debug Redux cycle. Understanding the limitations of implicit return values&lt;/span>\n\n&lt;!-- -->\n\n    const addFruit = (fruit) => {\n      return {\n        type: \"ADD_FRUIT\",\n        fruit,\n      };\n    };\n    const addFruit = (fruit) => {\n      debugger;\n      return {\n        type: \"ADD_FRUIT\",\n        fruit,\n      };\n    };\n\n-   &lt;span id=\"2806\">You must use explicit return statement arrow function to use a debugger.&lt;/span>\n\n---\n\n### React Router Introduction\n\nNow that you know how to render components in a React app, how do you handle rendering different components for different website pages? React Router is the answer!\n\nThink of how you have created server-side routes in Express. Take the following URL and server-side route. Notice how the `/users/:userId` path corresponds with the `http://localhost:3000/users/2` URL to render a specific HTML page.\n\n    // http://localhost:3000/users/2\n    app.get('/users/:userId', (req, res) => {\n      res.render('userProfile.pug');\n    });\n\nIn the default React setup, you lose the ability to create routes in the same manner as in Express. This is what React Router aims to solve!\n\n&lt;a href=\"https://github.com/ReactTraining/react-router\" class=\"markup--anchor markup--p-anchor\">React Router&lt;/a> is a frontend routing library that allows you to control which components to display using the browser location. A user can also copy and paste a URL and email it to a friend or link to it from their own website.\n\nWhen you finish this article, you should be able to use the following from the `react-router-dom` library:\n\n-   &lt;span id=\"e5d3\">`&lt;BrowserRouter>` to provide your application access to the `react-router-dom` library; and&lt;/span>\n-   &lt;span id=\"e1cd\">`&lt;Route>` to connect specific URL paths to specific components you want rendered; and&lt;/span>\n-   &lt;span id=\"bf15\">`&lt;Switch>` to wrap several `Route` elements, rendering only one even if several match the current URL; and&lt;/span>\n-   &lt;span id=\"0318\">React Router's `match` prop to access route path parameters.&lt;/span>\n\n### Getting started with routing\n\nSince you are writing single page apps, you don't want to refresh the page each time you change the browser location. Instead, you want to update the browser location and your app's response using JavaScript. This is known as client-side routing. You are using React, so you will use React Router to do this.\n\nCreate a simple react project template:\n\n    npx create-react-app my-app --template @appacademy/simple\n\nThen install React Router:\n\n    npm install --save react-router-dom@^5.1.2\n\nNow import `BrowserRouter` from `react-router-dom` in your entry file:\n\n    import { BrowserRouter } from 'react-router-dom`;\n\n### BrowserRouter\n\n`BrowserRouter` is the primary component of the router that wraps your route hierarchy. It creates a React context that passes routing information down to all its descendent components. For example, if you want to give `&lt;App>` and all its children components access to React Router, you would wrap `&lt;App>` like so:\n\n    // ./src/index.js\n    import React from 'react';\n    import ReactDOM from 'react-dom';\n    import { BrowserRouter } from 'react-router-dom';\n    import App from './App';\n\n    const Root = () => {\n      return (\n        &lt;BrowserRouter>\n          &lt;App />\n        &lt;/BrowserRouter>\n      );\n    };\n\n    ReactDOM.render(\n      &lt;React.StrictMode>\n        &lt;Root />\n      &lt;/React.StrictMode>,\n      document.getElementById('root'),\n    );\n\nNow you can route the rendering of certain components to certain URLs (i.e `https://www.website.com/profile`&lt;a href=\"https://www.website.com/profile%29.\" class=\"markup--anchor markup--p-anchor\">).&lt;/a>\n\n### HashRouter\n\nAlternatively, you could import and use `HashRouter` from `react-router-dom`. Links for applications that use `&lt;HashRouter>` would look like `https://www.website.com/#/profile` (with an `#` between the domain and path).\n\nYou'll focus on using the `&lt;BrowserRouter>`.\n\n### Creating frontend routes\n\nReact Router helps your React application render specific components based on the URL. The React Router component you'll use most often is `&lt;Route>`.\n\nThe `&lt;Route>` component is used to wrap another component, causing that component to only be rendered if a certain URL is matched. The behavior of the `&lt;Route>` component is controlled by the following props: `path`, `component`, `exact`, and `render` (optional).\n\nCreate a simple `Users` component that returns `&lt;h1>This is the users index!&lt;/h1>`. Now let's refactor your `index.js` file so that you can create your routes within the component:\n\n    // ./src/index.js\n    import React from 'react';\n    import ReactDOM from 'react-dom';\n    import { BrowserRouter, Route } from 'react-router-dom';\n    import App from './App';\n    import Users from './Users';\n\n    const Root = () => {\n      return (\n        &lt;BrowserRouter>\n          &lt;div>\n            {/* TODO: Routes */}\n          &lt;/div>\n        &lt;/BrowserRouter>\n      );\n    };\n\n    ReactDOM.render(\n      &lt;React.StrictMode>\n        &lt;Root />\n      &lt;/React.StrictMode>,\n      document.getElementById('root'),\n    );\n\nNote that `BrowserRouter` can only have a single child component, so the snippet above wraps all routes within parent a `&lt;div>` element. Now let's create some routes!\n\n### component\n\nBegin with the `component` prop. This prop takes a reference to the component to be rendered. Let's render your `App` component:\n\n    const Root = () => {\n      return (\n        &lt;BrowserRouter>\n          &lt;div>\n            &lt;Route component={App} />\n          &lt;/div>\n        &lt;/BrowserRouter>\n      );\n    };\n\nNow you'll need to connect a path to the component!\n\n### path\n\nThe wrapped component will only be rendered when the path is matched. The path matches the URL when it matches some initial portion of the URL. For example, a path of `/` would match both of the following URLs: `/` and `/users`. (Because `/users` begins with a `/` it matches the path `/`)\n\n    &lt;Route path='/' component={App} />\n    &lt;Route path='/users' component={Users} />\n\nTake a moment to navigate to `http://localhost:3000/users` to see how both the `App` component and `Users` component are rendering.\n\n### exact\n\nIf this `exact` flag is set, the path will only match when it exactly matches the URL. Then browsing to the `/users` path would no longer match `/` and only the `Users` component will be rendered (instead of both the `App` component and `Users` component).\n\n    &lt;Route exact path='/' component={App} />\n    &lt;Route path='/users' component={Users} />\n\n### render\n\nThis is an optional prop that takes in a function to be called. The function will be called when the path matches. The function's return value is rendered. You could also define a functional component inside the `component` prop, but this results in extra, unnecessary work for React. The `render` prop is preferred for inline rendering of simple functional components.\n\nThe difference between using `component` and `render` is that `component` returns new JSX to be re-mounted every time the route renders, while `render` simply returns to JSX what will be mounted once and re-rendered. For any given route, you should only use either the `component` prop, or the `render` prop. If both are supplied, only the `component` prop will be used.\n\n    // This inline rendering will work, but is unnecessarily slow.\n    &lt;Route path=\"/hello\" component={() => &lt;h1>Hello!&lt;/h1>} />\n\n    // This is the preferred way for inline rendering.\n    &lt;Route path=\"/hello\" render={() => &lt;h1>Hello!&lt;/h1>} />\n\nIt can be helpful to use `render` instead of `component` in your `&lt;Route>` when you need to pass props into the rendered component. For example, imagine that you needed to pass the `users` object as a prop to your `Users` component. Then you could pass in props from `Root` to `Users` by returning the `Users` component like so:\n\n    // `users` to be passed as a prop:\n    const users = {\n      1: { name: 'Andrew' },\n      2: { name: 'Raymond' }\n    };\n\n    &lt;Route path=\"/users\" render={() => &lt;Users users={users} />} />\n\nAs a reminder, `BrowserRouter` can only have a single child component. That's why you have wrapped all your routes within parent a `&lt;div>` element.\n\n    const Root = () => {\n      const users = {\n        1: { name: 'Andrew' },\n        2: { name: 'Raymond' }\n      };\n\n      return (\n        &lt;BrowserRouter>\n          &lt;div>\n            &lt;h1>Hi, I'm Root!&lt;/h1>\n            &lt;Route exact path=\"/\" component={App} />\n            &lt;Route path=\"/hello\" render={() => &lt;h1>Hello!&lt;/h1>} />\n            &lt;Route path=\"/users\" render={() => &lt;Users users={users} />} />\n          &lt;/div>\n        &lt;/BrowserRouter>\n      );\n    };\n\nWith this `Root` component, you will always render the `&lt;h1>Hi, I'm Root!&lt;/h1>`, regardless of the path. Because of the first `&lt;Route>`, you will only render the `App` component if the path exactly matches `/`. Because of the second `&lt;Route>`, you will only render the `Users` component if the path matches `/users`.\n\n### Route path params\n\nA component's props can also hold information about a URL's parameters. The router will match route segments starting at `:` up to the next `/`, `?`, or `#`. Those matched values are then passed to components via their props. Such segments are _wildcard_ values that make up your route parameters.\n\nFor example, take the route below:\n\n    &lt;Route path=\"/users/:userId\"\n           render={(props) => &lt;Profile users={users} {...props} />} />\n\nThe router would break down the full `/users/:userId/photos` path to two parts: `/users`, `:userId`.\n\nThe `Profile` component's props would have access to the `:userId` part of the `http://localhost:3000/users/:userId/photos` URL through the `props` with router parameter information. You would access the the `match` prop's parameters (`props.match.params`). If you are using the `render` prop of the `Route` component, make sure to spread the props back into the component if you want it to know about the \"match\" parameters.\n\n    // Route's `render` prop allows you to pass the `users`\n    // prop and spread the router `props`.\n    render={(props) => &lt;Profile users={users} {...props} />}\n\nThe `params` object would then have a property of `userId` which would hold the value of the `:userId` _wildcard_ value. Let's render the `userId` parameter in a user profile component. Take a moment to create a `Profile.js` file with the following code:\n\n    // ./src/Profile.js\n    import React from \"react\";\n\n    const Profile = (props) => (\n      &lt;div>\n        The user's id is {props.match.params.userId}.\n      &lt;/div>\n    );\n\n    export default Profile;\n\nNotice how it uses the `match` prop to access the `:userId` parameter from the URL. You can use this wildcard to make and AJAX call to fetch the user information from the database and render the return data in the `Profile` component. Recall that your `Profile` component was rendered at the path `/users/:userId`. Thus you can use your `userId` parameters from `match.params` to fetch a specific user:\n\n    // ./src/Profile.js\n    import React from \"react\";\n\n    const Profile = ({ users, match: { params } }) => {\n\n      // In a real-world scenario, you'd make a call to an API to fetch the user,\n      // instead of passing down and keying into a `users` prop.\n      const user = users[params.userId];\n\n      return (\n        &lt;div>\n          The user's id is {params.userId} and the user's name is {user.name}.\n        &lt;/div>\n      );\n    };\n\n    export default Profile;\n\n### Match\n\nNow that you've seen your React Router's `match` prop in action, let's go over more about &lt;a href=\"https://reacttraining.com/react-router/web/api/Route/route-props\" class=\"markup--anchor markup--p-anchor\">route props&lt;/a>! React Router passes information to the components as route props, accessible to all components with access to the React Router. The three props it makes available are `location`, `match` and `history`. You've learned about `props.match.params`, but now let's review the other properties of the `match` prop!\n\nThis is an object that contains important information about how the current URL matches the route path. Here are some of the more useful keys on the `match` object:\n\n-   &lt;span id=\"1d2c\">`isExact`: a boolean that tells you whether or not the URL exactly matches the path&lt;/span>\n-   &lt;span id=\"b558\">`url`: the current URL&lt;/span>\n-   &lt;span id=\"ab28\">`path`: the route path it matched against (without wildcards filled in)&lt;/span>\n-   &lt;span id=\"be5b\">`params`: the matches for the individual wildcard segments, nested under their names&lt;/span>\n\nWhen you use React Router, the browser `location` and `history` are a part of the state of your app. You can store information about which component should be displayed, which user profile you are currently viewing, or any other piece of state, in the browser location. You can then access that information from anywhere your Router props are passed to in your app.\n\nNow that you've learned about parameters and route props, let's revisit your `Root` component to add an `exact` flag to your `/users` route so that it does not render with your `/users/:userId` route. Your component should look something like this:\n\n    const Root = () => {\n      const users = {\n        1: { name: 'Andrew' },\n        2: { name: 'Raymond' }\n      };\n\n      return (\n        &lt;BrowserRouter>\n          &lt;h1>Hi, I'm Root!&lt;/h1>\n          &lt;div>\n            &lt;Route exact path=\"/\" component={App} />\n            &lt;Route path=\"/hello\" render={() => &lt;h1>Hello!&lt;/h1>} />\n\n            {/* Render the `Users` page if no ID is included. */}\n            &lt;Route exact path=\"/users\" render={() => &lt;Users users={users} />} />\n\n            {/* Otherwise, render the profile page for that userId. */}\n            &lt;Route path=\"/users/:userId\" component={(props) => &lt;Profile users={users} {...props} />} />\n          &lt;/div>\n        &lt;/BrowserRouter>\n      );\n    };\n\n### What you learned\n\nIn this article, you learned how to:\n\n-   &lt;span id=\"92fc\">Use components from the React Router library; and&lt;/span>\n-   &lt;span id=\"19b5\">Create routes to render specific components; and&lt;/span>\n-   &lt;span id=\"fc9d\">Manage the order of rendered routes; and&lt;/span>\n-   &lt;span id=\"3281\">Use the `exact` flag to ensure that a specific path renders a specific component; and&lt;/span>\n-   &lt;span id=\"3949\">Use the React Router `match` prop to access Router params.&lt;/span>\n\n---\n\n### React Router Navigation\n\nNow that you know how to create front-end routes with React Router, you'll need to implement a way for your users to navigate the routes! This is what using React Router's `Link`, `NavLink`, `Redirect`, and `history` prop can help you do.\n\nIn this article, you'll be working off of the demo project you built in the React Router Intro reading. When you finish this article, you should be able to use the following components from the `react-router-dom` library:\n\n-   &lt;span id=\"76bc\">`&lt;Link>` or `&lt;NavLink>` to create links with absolute paths to routes in your application (like \"/users/1\"); and,&lt;/span>\n-   &lt;span id=\"cdc2\">`&lt;Redirect>` to redirect a user to another path (i.e. a login page when the user is not logged in); and&lt;/span>\n-   &lt;span id=\"d8a7\">React Router's `history` prop to update a browser's URL programmatically.&lt;/span>\n\n### Adding links for navigation\n\nReact Router's `&lt;Link>` is one way to simplify navigation around your app. It issues an on-click navigation event to a route defined in your app's router. Using `&lt;Link>` renders an anchor tag with a correctly set `href` attribute.\n\n### Link\n\nTo use it, update your imports from the `react-router-dom` package to include `Link`:\n\n    import { BrowserRouter, Route, Link } from 'react-router-dom';\n\nNote that `&lt;Link>` can take two props: `to` and `onClick`.\n\nThe `to` prop is a route location description that points to an absolute path, (i.e. `/users`). Add the following `Link` components in your `index.js` file above your routes:\n\n    &lt;Link to=\"/\">App&lt;/Link>\n    &lt;Link to=\"/users\">Users&lt;/Link>\n    &lt;Link to=\"/users/1\">Andrew's Profile&lt;/Link>\n\nThe `onClick` prop is just like any other JSX click handler. You can write a function that takes in an `event` and handles it. Add the following `Link` before your routes and the following click handler function within your `Root` component:\n\n    // Link with onClick prop\n    &lt;Link to=\"/\" onClick={handleClick}>App with click handler&lt;/Link>\n\n    // Click handler function\n    const handleClick = () => {\n      console.log('Thanks for clicking!')\n    };\n\nNow, test your routes and links! If you inspect the page, you'll see that your links are now rendered as `&lt;a>` elements. Notice that clicking the `App with click handler` link logs a message in your console while directing your browser to render the `App` component.\n\n### NavLink\n\nThe `&lt;NavLink>` works just like a `&lt;Link>`, but with a little extra functionality. It has the ability to add extra styling when the path it links to matches the current path. This makes it an ideal choice for a navigation bar, hence the name. This styling can be controlled by three extra props: `activeClassName`, `activeStyle`, and `exact`. To begin using `NavLink`, update your imports from the `react-router-dom` package:\n\n    import { BrowserRouter, Route, NavLink } from 'react-router-dom';\n\nThe `activeClassName` prop of the `NavLink` component allows you to set a CSS class name for styling the `NavLink` when its route is active. By default, the `activeClassName` is already set to `active`. This means that you simply need to add an `.active` class to your CSS file to add active styling to your link. A `NavLink` will be active if its `to` prop path matches the current URL.\n\nLet's change your \"Users\", \"Hello\", and \"Andrew's Profile\" links to be different colors and have a larger font size when active.\n\n    &lt;NavLink to=\"/\">App&lt;/NavLink>\n    &lt;NavLink activeClassName=\"red\" to=\"/users\">Users&lt;/NavLink>\n    &lt;NavLink activeClassName=\"blue\" to=\"/hello\">Hello&lt;/NavLink>\n    &lt;NavLink activeClassName=\"green\" to=\"/users/1\">Andrew's Profile&lt;/NavLink>\n    &lt;NavLink to=\"/\" onClick={handleClick}>App with click handler&lt;/NavLink>\n\nFor example, this is what the rendered HTML `&lt;a>` tag would look like when when the browser is navigated to the `/` path or the `/users` path:\n\n    &lt;!-- Navigated to the / path (the activeClassName\n         prop is set to active by default) -->\n    &lt;a href=\"/\" class=\"active\">App&lt;/a>\n\n    &lt;!-- NOT navigated to the `/` path -->\n    &lt;a href=\"/\">App&lt;/a>\n\n    &lt;!-- Navigated to the /users path (the activeClassName\n         prop is manually set to red) -->\n    &lt;a href=\"/users\" class=\"red\">Users&lt;/a>\n\n    &lt;!-- NOT navigated to the `/users` path -->\n    &lt;a href=\"/users\">Users&lt;/a>\n\nImport `NavLink` into your `index.js` file and take a moment to update all your `Link` elements to `NavLink` elements. Set an `activeClassName` prop to an `active` class. Add the following `.active` class to your `index.css` file:\n\n    .active {\n      font-weight: bold;\n    }\n\n    .red {\n      color: red;\n      font-size: 30px;\n    }\n\n    .blue {\n      color: blue;\n      font-size: 30px;\n    }\n\n    .green {\n      color: green;\n      font-size: 30px;\n    }\n\nTest your styled links! Notice how the `App` and `App with click handler` links are always bolded. This is because all of your links include the `/` path, meaning that the link to `/` will be active when browsing to `/users` and `/users/1` because of how `users` and `users/1` are both prefaced by a `/`.\n\nThe `activeStyle` prop is a style object that will be applied inline to the `NavLink` when its `to` prop matches the current URL. Add the following `activeStyle` to your `App` link and comment out the `.active` class in your CSS file.\n\n    &lt;NavLink to=\"/\" activeStyle={{ fontWeight: \"bold\" }}>App&lt;/NavLink>\n\nThe following html is rendered when at the `/` path:\n\n    &lt;a href=\"/\" style=\"font-weight:bold;\" class=\"active\">App&lt;/a>\n\nNotice how your `App with click handler` is not bolded anymore. This is because the default `active` class being applied does not have any CSS stylings set to the class. Uncomment your `.active` class in your CSS file to bring back bolding to this NavLink.\n\nThe `exact` prop is a boolean that defaults to `false`. If set to `true`, then the `activeStyle` and `activeClassName` props will only be applied when the current URL exactly matches the `to` prop. Update your `App` and `App with click handler` links with an `exact` prop set. Just like in your routes, you can use the `exact` flag instead of `exact={true}`.\n\n    &lt;NavLink to=\"/\" exact={true} activeStyle={{ fontWeight: \"bold\" }}>App&lt;/NavLink>\n    &lt;NavLink to=\"/\" exact onClick={handleClick}>App with click handler&lt;/NavLink>\n\nNow your `App` and `App with click handler` links will only be bolded when you have navigated precisely to the `/` path.\n\n### Switching between routes\n\nYou came across styling issues when the `/users` and `/users/1` paths matched the `/` path. Routing can have this issue as well. This is why you need to control the switching between routes.\n\nReact Router's `&lt;Switch>` component allows you to only render one `&lt;Route>` even if several match the current URL. You can nest as many `Route`s as you wish between the opening and closing `Switch` tags, but only the first one that matches the current URL will be rendered.\n\nThis is particularly useful if you want a default component that will only render if none of our other routes match. View the example below. Without the Switch, `DefaultComponent` would always render. Since there isn't set a path in the `DefaultComponent` route, it will simply use the default path of `/`. Now the `DefaultComponent` will only render when neither of the preceding routes match.\n\n    &lt;Switch>\n      &lt;Route path=\"some/url\" component={SomeComponent} />\n      &lt;Route path=\"some/other/url\" component={OtherComponent} />\n      &lt;Route component={DefaultComponent} />\n    &lt;/Switch>\n\nImport `Switch` from `react-router-dom` and add `&lt;Switch>` tags around your routes to take care of ordering and switching between your routes! Begin by adding the following route to the bottom of your routes to render that a `404: Page not found` message:\n\n    &lt;Route render={() => &lt;h1>404: Page not found&lt;/h1>} />\n\nThis is what your `Root` component should look like at this point:\n\n    const Root = () => {\n      const users = [\n        { name: 'andrew' },\n        { name: 'raymond' }\n      ];\n\n      const handleClick = () => {\n        console.log('Thanks for clicking!')\n      };\n\n      return (\n        &lt;BrowserRouter>\n          &lt;h1>Hi, I'm Root!&lt;/h1>\n\n          &lt;div>\n            &lt;NavLink to=\"/\" exact={true} activeStyle={{ fontWeight: \"bold\" }}>App&lt;/NavLink>\n            &lt;NavLink activeClassName=\"red\" to=\"/users\">Users&lt;/NavLink>\n            &lt;NavLink activeClassName=\"blue\" to=\"/hello\">Hello&lt;/NavLink>\n            &lt;NavLink activeClassName=\"green\" to=\"/users/1\">Andrew's Profile&lt;/NavLink>\n            &lt;NavLink to=\"/\" exact onClick={handleClick}>App with click handler&lt;/NavLink>\n\n            &lt;Switch>\n              &lt;Route path=\"/users/:userId\" component={(props) => &lt;Profile users={users} {...props} />} />\n              &lt;Route exact path=\"/users\" render={() => &lt;Users users={users} />} />\n              &lt;Route path=\"/hello\" render={() => &lt;h1>Hello!&lt;/h1>} />\n              &lt;Route exact path=\"/\" component={App} />\n              &lt;Route render={() => &lt;h1>404: Page not found&lt;/h1>} />\n            &lt;/Switch>\n          &lt;/div>\n        &lt;/BrowserRouter>\n      );\n    };\n\nNow you have control over the precedence of rendered components! Try navigating to `http://localhost:3000/asdf` or any other route you have not defined. The `&lt;h1>404: Page not found&lt;/h1>` JSX of the last `&lt;Route>` will be rendered whenever the browser attempts to visit an undefined route.\n\n### Redirecting users\n\nBut what if you want to redirect users to a login page when they aren't logged in? The `&lt;Redirect>` component from React Router helps you redirect users!\n\nThe component takes only one prop: `to`. When it renders, it replaces the current URL with the value of its `to` prop. Typically you conditionally render `&lt;Redirect>` to redirect the user away from some page you don't want them to visit. The example below checks whether there is a defined `currentUser` prop. If so, the `&lt;Route>` will render the `Home` component. Otherwise, it will redirect the user to the `/login` path.\n\n    &lt;Route\n      exact path=\"/\"\n      render={() => (this.props.currentUser ? &lt;Home /> : &lt;Redirect to=\"/login\" />)}\n    />\n\nNote: you will learn how to use a more flexible auth pattern — don't directly imitate this example.\n\n### History\n\nYou know how to redirect users with a `&lt;Redirect>` component, but what if you need to redirect users programmatically? You've learned about the React Router's `match` prop, but now let's go over another one of the &lt;a href=\"https://reacttraining.com/react-router/web/api/Route/route-props\" class=\"markup--anchor markup--p-anchor\">route props&lt;/a>: `history`!\n\n    // Pushing a new URL (and adding to the end of history stack):\n    const handleClick = () => this.props.history.push('/some/url');\n\n    // Replacing the current URL (won't be tracked in history stack):\n    const redirect = () => this.props.history.replace('/some/other/url');\n\nThis prop lets you update the URL programmatically. For example, suppose you want to push a new URL when the user clicks a button. It has two useful methods:\n\n-   &lt;span id=\"31f3\">`push` - This adds a new URL to the end of the history stack. That means that clicking the back button will take the browser to the previous URL. Note that pushing the same URL multiple times in a row will have no effect; the URL will still only show up on the stack once. In development mode, pushing the same URL twice in a row will generate a console warning. This warning is disabled in production mode.&lt;/span>\n-   &lt;span id=\"90c1\">`replace` - This replaces the current URL on the history stack, so the back button won't take you to it. For example:&lt;/span>\n\n### What you learned\n\nIn this article, you learned how to:\n\n-   &lt;span id=\"169b\">Create navigation links for your route paths; and&lt;/span>\n-   &lt;span id=\"d108\">Redirect users through using the `&lt;Redirect>` component; and&lt;/span>\n-   &lt;span id=\"d090\">Update a browser's URL programmatically by using React Router's `history` prop.&lt;/span>\n\n---\n\n### React Router Nested Routes\n\nNow you know how to create front-end routes and add navigation with React Router. When initializing Express projects, you declare static routes. Static routes are routes that are declared when an application is initialized. When using React Router in your application's initialization, you can declare dynamic routes. React Router introduces dynamic routing, where your routes are created as your application is rendering. This allows you to create nested routes within components!\n\nIn this article, let's dive into &lt;a href=\"https://reacttraining.com/react-router/core/guides/philosophy/nested-routes\" class=\"markup--anchor markup--p-anchor\">nested routes&lt;/a>! When you finish the article, you should:\n\n-   &lt;span id=\"38ee\">Describe what nested routes are; and&lt;/span>\n-   &lt;span id=\"0559\">Be able to use React Router to create and navigate nested routes; and&lt;/span>\n-   &lt;span id=\"ce4a\">Know how to use the React Router `match` prop to generate links and routes.&lt;/span>\n\n### Why nested routes?\n\nLet's begin with why you might need nested routes. As you remember, you are using React to create a single-page application. This means that you'll be organizing your application into different components and sub-components.\n\nFor example, imagine creating a simple front-end application with three main pages: a home welcome page (path of `/`), a users index page (path of `/users`), and user profile pages (path of `/users/:userId`). Now imagine if every user had links to separate `posts` and `photos` pages.\n\nYou can create those routes and links within the user profile component, instead of creating the routes and links where the main routes are defined.\n\n### What are nested routes?\n\nNow let's dive into a user profile component to understand what are nested routes! Imagine you have a route in your application's entry file to each user's profile like so:\n\n    &lt;Route path=\"/users/:userId\" component={Profile} />\n\nThis means that upon navigating to `http://localhost:3000/users/1`, you would render the following `Profile` component and the `userId` parameter within `props.match.params` would have the value of `\"1\"`.\n\n    const Profile = (props) => {\n      // Custom call to database to fetch a user by a user ID.\n      const user = fetchUser(props.match.params.userId);\n      const { name, id } = user;\n\n      return (\n        &lt;div>\n          &lt;h1>Welcome to the profile of {name}!&lt;/h1>\n\n          {/* Links to a specific user's posts and photos */}\n          &lt;Link to={`/users/${id}/posts`}>{name}'s Posts&lt;/Link>\n          &lt;Link to={`/users/${id}/photos`}>{name}'s Photos&lt;/Link>\n\n          {/* Routes to a specific user's posts and photos */}\n          &lt;Route path='/users/:userId/posts' component={UserPosts} />\n          &lt;Route path='/users/:userId/photos' component={UserPhotos} />\n        &lt;/div>\n      );\n    };\n\nSince this route is not created until the `Profile` component is rendered, you are dynamically creating your nested `/users/:userId/posts` and `/users/:userId/photos` routes. Remember that your `match` prop also has other helpful properties. You can use `match.url` instead of `/users/${id}` in your profile links. You can also use `match.path` instead of `/users/:userId` in your profile routes. Remember that you can destructure `url`, `path`, and `params` from your `match` prop!\n\n    // Destructure `match` prop\n    const Profile = ({ match: { url, path, params }) => {\n\n      // Custom call to database to fetch a user by a user ID.\n      const user = fetchUser(params.userId);\n      const { name, id } = user;\n\n      return (\n        &lt;div>\n          &lt;h1>Welcome to the profile of {name}!&lt;/h1>\n\n          {/* Replaced `/users/${id}` URL with `props.match.url` */}\n          &lt;Link to={`${url}/posts`}>{name}'s Posts&lt;/Link>\n          &lt;Link to={`${url}/photos`}>{name}'s Photos&lt;/Link>\n\n          {/* Replaced `/users/:userId` path with `props.match.path` */}\n          &lt;Route path={`${path}/posts`} component={UserPosts} />\n          &lt;Route path={`${path}/photos`} component={UserPhotos} />\n        &lt;/div>}\n      );\n    };\n\nIn tomorrow's project, you'll build a rainbow of routes as well as define nested routes. In the future, you may choose to implement nested routes to keep your application's routes organized within related components.\n\n### What you learned\n\nIn this article, you learned:\n\n-   &lt;span id=\"2378\">What nested routes are; and&lt;/span>\n-   &lt;span id=\"e072\">About creating and navigating nested routes with React Router; and&lt;/span>\n-   &lt;span id=\"c8b8\">How to use the React Router props to generate nested links and routes.&lt;/span>\n\n---\n\n### React Builds\n\nA \"build\" is the process of converting code into something that can actually execute or run on the target platform. A \"front-end build\" is a process of preparing a front-end or client-side application for the browser.\n\nWith React applications, that means (at a minimum) converting JSX to something that browsers can actually understand. When using Create React App, the build process is automatically configured to do that and a lot more.\n\nWhen you finish this article, you should be able to:\n\n-   &lt;span id=\"2448\">Describe what front-end builds are and why they're needed;&lt;/span>\n-   &lt;span id=\"efab\">Describe at a high level what happens in a Create React App when you run `npm start`; and&lt;/span>\n-   &lt;span id=\"502f\">Prepare to deploy a React application into a production environment.&lt;/span>\n\n### Understanding front-end builds\n\nThe need for front-end builds predates React. Over the years, developers have found it helpful to extend the lowest common denominator version of JavaScript and CSS that they could use.\n\nSometimes developers extend JavaScript and CSS with something like &lt;a href=\"https://www.typescriptlang.org/\" class=\"markup--anchor markup--p-anchor\">TypeScript&lt;/a> or &lt;a href=\"https://sass-lang.com/\" class=\"markup--anchor markup--p-anchor\">Sass&lt;/a>. Using these non-standard languages and syntaxes require you to use a build process to convert your code into standard JavaScript and CSS that can actually run in the browser.\n\nBrowser-based applications also require a fair amount of optimization to deliver the best, or at least acceptable, experience to end users. Front-end build processes could be configured to lint code, run unit tests, optimize images, minify and bundle code, and more — all automatically at the press of a button (i.e. running a command at the terminal).\n\n### JavaScript versions and the growth of front-end builds\n\nDevelopers are generally an impatient lot. When new features are added to JavaScript, we don't like to wait for browsers to widely support those features before we start to use them in our code. And we _really_ don't like when we have to support older, legacy versions of browsers.\n\nIn recent years, JavaScript has been updated on a yearly basis and browser vendors do a decent job of updating their browsers to support the new features as they're added to the language. Years ago though, there was an infamous delay between versions 5 and 6 of JavaScript. It took _years_ before ES6 (or ES2015 as it eventually was renamed to) to officially be completed and even longer before browsers supported all of its features.\n\nIn the period of time before ES2015 was broadly supported by browsers, developers used front-end builds to convert or _transpile_ ES2015 features and syntax to an older version of the language that was more broadly supported by browsers (typically ES5). The transpilation from ES2015/ES6 down to ES5 was one of the major drivers for developers to add front-end builds to their client-side projects.\n\n### Reviewing common terminology\n\nWhen learning about front-end or React builds, you'll encounter a lot of terminology that you may or may not be familiar with. Here's some of the terminology that you'll likely encounter:\n\nLinting is process of using a tool to analyze your code to catch common programming errors, bugs, stylistic inconsistencies, and suspicious coding patterns. &lt;a href=\"https://eslint.org/\" class=\"markup--anchor markup--p-anchor\">ESLint&lt;/a> is a popular JavaScript linting tool.\n\nTranspilation is the process of converting source code, like JavaScript, from one version to another version. Usually this means converting newer versions of JavaScript, &lt;a href=\"https://www.ecma-international.org/ecma-262/10.0/index.html\" class=\"markup--anchor markup--p-anchor\">ES2019&lt;/a> or &lt;a href=\"https://tc39.es/ecma262/\" class=\"markup--anchor markup--p-anchor\">ES2021&lt;/a>, to a version that's more widely supported by browsers, like &lt;a href=\"http://www.ecma-international.org/ecma-262/6.0/\" class=\"markup--anchor markup--p-anchor\">ES2015&lt;/a>, or even &lt;a href=\"https://www.ecma-international.org/ecma-262/5.1/\" class=\"markup--anchor markup--p-anchor\">ES5&lt;/a> or &lt;a href=\"https://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf\" class=\"markup--anchor markup--p-anchor\">ES3&lt;/a> (if you need to support the browser that your parents or grandparents use).\n\nMinification is the process of removing all unnecessary characters in your code (e.g. white space characters, new line characters, comments) to produce an overall smaller file. Minification tools will often also rename identifers in your code (i.e. parameter and variable names) in the quest for smaller and smaller file sizes. Source maps can also be generated to allow debugging tools to cross reference between minified code and the original source code.\n\nBundling is the process of combining multiple code files into a single file. Creating a bundle (or a handful of bundles) reduces the number of requests that a client needs to make to the server.\n\nTree shaking is the process of removing unused (or dead) code from your application before it's bundled. Tree shaking external dependencies can sometimes have a dramatic positive impact on overall bundled file sizes.\n\n### Configuration or code?\n\nFront-end build tools have come and gone over the years; sometimes very quickly, which helped bring about the phenomenon known as &lt;a href=\"https://sdtimes.com/softwaredev/is-the-javascript-fatigue-real/\" class=\"markup--anchor markup--p-anchor\">JavaScript fatigue&lt;/a>.\n\nConfiguration based tools allow you to create your build tasks by declaring (usually using JSON, XML, or YAML) what you want to be done, without explicitly writing every step in the process. In contrast, coding or scripting based tools allow you to, well, write code to create your build tasks. Configuration based tools _can_ sometimes feel simpler to use while giving up some control (at least initially) while coding based tools _can_ feel more familiar and predictable (since you're describing tasks procedurally). Every generalization is false though (including this one), so there are plenty of exceptions.\n\n&lt;a href=\"https://gruntjs.com/\" class=\"markup--anchor markup--p-anchor\">Grunt&lt;/a> is a JSON configuration based task runner that can be used to orchestrate the various tasks that make up your front-end build. Grunt was very quickly supplanted by &lt;a href=\"https://gulpjs.com/\" class=\"markup--anchor markup--p-anchor\">Gulp&lt;/a>, which allowed developers to write JavaScript to define front-end build tasks. After Gulp, the front-end tooling landscape became a bit more muddled. Some developers preferred the simplicity of using &lt;a href=\"https://docs.npmjs.com/misc/scripts\" class=\"markup--anchor markup--p-anchor\">npm scripts&lt;/a> to define build tasks while others preferred the power of configuration based bundlers like &lt;a href=\"https://webpack.js.org/\" class=\"markup--anchor markup--p-anchor\">webpack&lt;/a>.\n\n### Babel and webpack (yes, that's intentionally a lowercase 'w')\n\nAs front-end or client-side applications grew in complexity, developers found themselves wanting to leverage more advanced JavaScript features and newer syntax like classes, arrow functions, destructuring, async/await, etc. Using a code transpiler, like &lt;a href=\"https://babeljs.io/\" class=\"markup--anchor markup--p-anchor\">Babel&lt;/a>, allows you to use all of the latest and greatest features and syntax without worrying about what browsers support what.\n\nModule loaders and bundlers, like &lt;a href=\"https://webpack.js.org/\" class=\"markup--anchor markup--p-anchor\">webpack&lt;/a>, also allowed developers to use JavaScript modules without requiring users to use a browser that natively supports ES modules. Also, module bundling (along with minification and tree-shaking) helps to reduce the bandwidth that's required to deliver the assets for your application to the client.\n\n\\[Create React App\\]\\[cra\\] uses webpack (along with Babel) under the covers to build your React applications. Even if you're not using Create React App, webpack and Babel are still very popular choices for building React applications.\n\n### Pulling back the covers (a bit) on the Create React App build process\n\nRunning an application created by Create React App using `npm start` can feel magical. Some stuff happens in the terminal and your application opens into your default browser. Even better, when you make changes to your application, your changes will (usually) automatically appear in the browser!\n\n### The Create React App build process\n\nAt a high level, here's what happens when you run `npm start`:\n\n-   &lt;span id=\"2808\">Environment variables are loaded (more about this in a bit);&lt;/span>\n-   &lt;span id=\"f272\">The list of browsers to support are checked (more about this too in a bit);&lt;/span>\n-   &lt;span id=\"71b2\">The configured HTTP port is checked to ensure that it's available;&lt;/span>\n-   &lt;span id=\"f826\">The application compiler is configured and created;&lt;/span>\n-   &lt;span id=\"c605\">`webpack-dev-server` is started;&lt;/span>\n-   &lt;span id=\"a696\">`webpack-dev-server` compiles your application;&lt;/span>\n-   &lt;span id=\"c66e\">The `index.html` file is loaded into the browser; and&lt;/span>\n-   &lt;span id=\"6add\">A file watcher is started to watch your files, waiting for changes.&lt;/span>\n\n### Ejecting\n\nCreate React App provides a script that you can run to \"eject\" your application from the Create React App tooling. When you eject your application, all of the hidden stuff is exposed so that you can review and customize it.\n\n> _The need to customize Create React App rarely happens. Also, don't eject an actual project as it's a one-way trip! Once a Create React App project has been ejected, there's no going back (though you could always undo the ejection process by reverting to an earlier commit if you're using source control)._\n\nTo eject your application from Create React App, run the command `npm run eject`. You'll be prompted if you want to continue; type \"y\" to continue with the ejection process. Once the ejection process has completed, you can review the files that were previously hidden from you.\n\nIn the `package.json` file, you'll see the following npm scripts:\n\n    {\n      \"scripts\": {\n        \"start\": \"node scripts/start.js\",\n        \"build\": \"node scripts/build.js\",\n        \"test\": \"node scripts/test.js\"\n      }\n    }\n\nYou can open the `./scripts/start.js` file to see the code that's executed when you run `npm start`.\n\nIf you're curious about the webpack configuration, you can open and review the `./config/webpack.config.js`.\n\n### Preparing to deploy a React application for production\n\nBefore you deploy your application to production, you'll want to make sure that you've replaced static values in your code with environment variables and considered what browsers you need to support.\n\n### Defining environment variables\n\nCreate React App supports defining environment variables in an `.env` file. To define an environment variable, add an `.env` file to your project and define one or more variables that start with the prefix `REACT_APP_`:\n\n    REACT_APP_FOO: some value\n    REACT_APP_BAR: another value\n\nEnvironment variables can be used in code like this:\n\n    console.log(process.env.REACT_APP_FOO);\n\nYou can also reference environment variables in your `index.html` like this:\n\n    &lt;title>%REACT_APP_BAR%&lt;/title>\n\n> _Important: Environment variables are embedded into your HTML, CSS, and JavaScript bundles during the build process. Because of this, it's_ very important _to not store any secrets, like API keys, in your environment variables as anyone can view your bundled code in the browser by inspecting your files._\n\n### Configuring the supported browsers\n\nIn your project's `package.json` file, you can see the list of targeted browsers:\n\n    {\n      \"browserslist\": {\n        \"production\": [\n          \">0.2%\",\n          \"not dead\",\n          \"not op_mini all\"\n        ],\n        \"development\": [\n          \"last 1 chrome version\",\n          \"last 1 firefox version\",\n          \"last 1 safari version\"\n        ]\n      }\n    }\n\nAdjusting these targets affect how your code will be transpiled. Specifying older browser versions will result in your code being transpiled to older versions of JavaScript in order to be compatible with the specified browser versions. The `production` list specifies the browsers to target when creating a production build and the `development` list specifics the browsers to target when running the application using `npm start`.\n\nThe &lt;a href=\"https://browserl.ist/\" class=\"markup--anchor markup--p-anchor\">browserl.ist&lt;/a> website can be used to see the browsers supported by your configured `browserslist`.\n\n### Creating a production build\n\nTo create a production build, run the command `npm run build`. The production build process bundles React in production mode and optimizes the build for the best performance. When the command completes, you'll find your production ready files in the `build` folder.\n\nNow your application is ready to be deployed!\n\n> _For more information about how to deploy a Create React App project into production, see_ &lt;a href=\"https://facebook.github.io/create-react-app/docs/deployment\" class=\"markup--anchor markup--blockquote-anchor\">\n&lt;em>this page&lt;/em>\n&lt;/a> _in the official documentation._\n\n### What you learned\n\nIn this article, you learned how to:\n\n-   &lt;span id=\"1ff3\">Describe what front-end builds are and why they're needed;&lt;/span>\n-   &lt;span id=\"1fc3\">Describe at a high level what happens in a Create React App when you run `npm start`; and&lt;/span>\n-   &lt;span id=\"6adc\">Prepare to deploy a React application into a production environment.&lt;/span>\n\n---\n\n### React Router Documentation\n\nNow that you've had an introduction to React Router, feel free to explore the official documentation to learn more! As you become a full-fledged software engineer, remember that documentation is your friend. You can take a brief overview for now, as the documentation might include a lot of information at first. The more you learn about React, the more you should revisit the official documentation and learn!\n\n### Setting up React Router\n\n-   &lt;span id=\"bfa4\">\n&lt;a href=\"https://reacttraining.com/react-router/web/guides/quick-start\" class=\"markup--anchor markup--li-anchor\">React Router Quick Start&lt;/a>\n&lt;/span>\n-   &lt;span id=\"b0cb\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/HashRouter\" class=\"markup--anchor markup--li-anchor\">HashRouter&lt;/a>\n&lt;/span>\n-   &lt;span id=\"f48b\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/BrowserRouter\" class=\"markup--anchor markup--li-anchor\">BrowserRouter&lt;/a>\n&lt;/span>\n\n### Routes and Links\n\n-   &lt;span id=\"72bd\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/Route\" class=\"markup--anchor markup--li-anchor\">Route&lt;/a>\n&lt;/span>\n-   &lt;span id=\"e256\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/Link\" class=\"markup--anchor markup--li-anchor\">Link&lt;/a>\n&lt;/span>\n-   &lt;span id=\"1d9d\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/NavLink\" class=\"markup--anchor markup--li-anchor\">NavLink&lt;/a>\n&lt;/span>\n\n### Switch and Redirect\n\n-   &lt;span id=\"5240\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/Switch\" class=\"markup--anchor markup--li-anchor\">Switch&lt;/a>\n&lt;/span>\n-   &lt;span id=\"b405\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/Redirect\" class=\"markup--anchor markup--li-anchor\">Redirect&lt;/a>\n&lt;/span>\n\n### React Router Params (ownProps)\n\n-   &lt;span id=\"e0d6\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/history\" class=\"markup--anchor markup--li-anchor\">props.history&lt;/a>\n&lt;/span>\n-   &lt;span id=\"5f4a\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/location\" class=\"markup--anchor markup--li-anchor\">props.location&lt;/a>\n&lt;/span>\n-   &lt;span id=\"bd15\">\n&lt;a href=\"https://reacttraining.com/react-router/web/api/match\" class=\"markup--anchor markup--li-anchor\">props.match&lt;/a>\n&lt;/span>\n\n---\n\n### Rainbow Routes Project\n\nToday you're going to get our first experience using React Router. The goal is to create a basic app that displays the colors of the rainbow. This rainbow, however, has something special about it — some of the colors are nested within others.\n\n### Phase 0: Setup\n\nBegin by creating a new React project:\n\n    npx create-react-app rainbow-routes --template @appacademy/simple\n\nNow you'll remove all the contents of your `src` and all the contents from your `public` directory to build the application architecture from scratch! After you have deleted all your files within the directories, create a new `index.html` file in your `public` folder. Use the `html:5` emmet shortcut to generate an HTML template. Title your page \"Rainbow Routes\" and create a `div` with an `id` of `root` in your DOM's `&lt;body>` element. Create an `index.css` file in your `src` directory with the following code. Now let's create your entry file!\n\n    h4 {\n      color: darkblue;\n      cursor: pointer;\n    }\n\n    h4:hover {\n      text-decoration: underline;\n    }\n\n    #rainbow {\n      position: absolute;\n      top: 0;\n      left: 300px;\n    }\n\n    h3 {\n      position: absolute;\n      top: 1px;\n    }\n\n    .red {\n      background-color: red;\n      width: 100px;\n      height: 100px;\n    }\n\n    .orange {\n      background-color: orange;\n      width: 100px;\n      height: 50px;\n    }\n\n    .yellow {\n      background-color: yellow;\n      width: 100px;\n      height: 50px;\n    }\n\n    .green {\n      background-color: green;\n      width: 100px;\n      height: 100px;\n    }\n\n    .blue {\n      background-color: blue;\n      width: 100px;\n      height: 100px;\n    }\n\n    .indigo {\n      background-color: mediumslateblue;\n      width: 100px;\n      height: 50px;\n    }\n\n    .violet {\n      background-color: darkviolet;\n      width: 100px;\n      height: 100px;\n    }\n\n    a {\n      display: block;\n      margin-bottom: 10px;\n    }\n\nCreate an `index.js` entry file in the `src` directory. At the top of the file, make sure to import `React` from the `react` package and `ReactDOM` from the `react-dom` package. Make sure to also import your the `index.css` file you just created! This will take care of styling your _rainbow routes_.\n\nNow you can use the `ReactDOM.render()` method to render a `&lt;Root />` component instead of the DOM element with an `id` of `root`. Lastly, wrap your render function with a `DOMContentLoaded` event listener, like so:\n\n    document.addEventListener('DOMContentLoaded', () => {\n      ReactDOM.render(\n        &lt;Root />,\n        document.getElementById('root'),\n      );\n    });\n\nLet's create your `Root` component right in your entry file! Your `Root` component will take care of applying your `BrowserRouter` to the application. Applying the `BrowserRouter` to your `Root` component allows all the child components rendering within `&lt;BrowserRouter>` tags to use and access the `Route`, `Link`, and `NavLink` components within the `react-router-dom` package.\n\n    const Root = () => (\n      // TODO: Apply BrowserRouter\n      // TODO: Render rainbow\n    );\n\nInstall the `react-router-dom` package:\n\n    npm install react-router-dom@^5.0.0\n\nNow import `BrowserRouter` from the `react-router-dom` package, like so:\n\n    import { BrowserRouter } from 'react-router-dom';\n\nYou're going to be rendering a lot of components, so let's keep your `src` directory organized by creating a `components` directory within. Within your new `./src/components` directory, create a `Rainbow.js` file for your `Rainbow` component with the following code:\n\n    // ./src/components/Rainbow.js\n    import React from 'react';\n    import { Route, Link, NavLink } from 'react-router-dom';\n\n    const Rainbow = () => (\n      &lt;div>\n        &lt;h1>Rainbow Router!&lt;/h1>\n        {/* Your links should go here */}\n\n        &lt;div id=\"rainbow\">\n          {/* Your routes should go here */}\n        &lt;/div>\n      &lt;/div>\n    );\n\n    export default Rainbow;\n\nYour `Rainbow` component will act as the home page or default path (`/`) of your application. Import the `Rainbow` component into your entry file and have your `Root` component render `&lt;Rainbow />` wrapped within `&lt;BrowserRouter>` tags, like so:\n\n    const Root = () => (\n      &lt;BrowserRouter>\n        &lt;Rainbow />\n      &lt;/BrowserRouter>\n    );\n\nWithin your `Rainbow` component, you'll be rendering `&lt;NavLink>` and `&lt;Route>` components to add different navigation paths to different components. Let's create all the components you will render!\n\nCreate files for the following components in your `./src/components` directory:\n\n-   &lt;span id=\"1c8e\">`Red`&lt;/span>\n-   &lt;span id=\"a8dd\">`Blue`&lt;/span>\n-   &lt;span id=\"6ca3\">`Green`&lt;/span>\n-   &lt;span id=\"8e44\">`Indigo`&lt;/span>\n-   &lt;span id=\"f8f2\">`Orange`&lt;/span>\n-   &lt;span id=\"0f47\">`Violet`&lt;/span>\n-   &lt;span id=\"8a89\">`Yellow`&lt;/span>\n\nYour `Red` and `Blue` components will look something like this:\n\n    import React from 'react';\n    import { Route, Link, NavLink } from 'react-router-dom';\n\n    const Color = () => (\n      &lt;div>\n        &lt;h2 className=\"color\">Color&lt;/h2>\n        {/* Links here */}\n\n        {/* Routes here */}\n      &lt;/div>\n    );\n\n    export default Color;\n\nYour `Green`, `Indigo`, `Orange`, `Violet`, and `Yellow` components will look something like this:\n\n    import React from 'react';\n\n    const Color = () => (\n      &lt;div>\n        &lt;h3 className=\"color\">Color&lt;/h3>\n      &lt;/div>\n    );\n\n    export default Color;\n\nNow start your server and verify you can see the \"Rainbow Router!\" header from your `Rainbow` component. Currently there is no functionality. Let's fix that!\n\n### Phase 1: Routes\n\nAs a reminder, wrapping the `Rainbow` component in `&lt;BrowserRouter>` tags makes the router available to all descendent React Router components. Now open the `Rainbow.js` file. You're going to render some of your color components from here. Ultimately you want your routes to look like this.\n\nURLComponents`/Rainbow/redRainbow -> Red/red/orangeRainbow -> Red -> Orange/red/yellowRainbow -> Red -> Yellow/greenRainbow -> Green/blueRainbow -> Blue/blue/indigoRainbow -> Blue -> Indigo/violetRainbow -> Violet`\n\nThis means that the `Red`, `Green`, `Blue`, and `Violet` components need to render in the `Rainbow` component, but only when you are at the corresponding URL. You'll do this with `Route` components. Begin by importing the `Red`, `Green`, `Blue`, and `Violet` components into your `Rainbow.js` file. Then add the necessary `Route` components inside the `div` with `id=\"rainbow\"` in the `Rainbow` component. For example to render the `Red` component with the `/red` path, you would use the following `Route` component:\n\n    &lt;Route path=\"/red\" component={Red} />\n\nTest that your code works! Manually type in each URL you just created, and you should see the color component pop up. Remember, these are React Routes, so the paths you created will come after the `/`. For example, your default rainbow route will look like `http://localhost:3000/` while your red route will look like `http://localhost:3000/red`&lt;a href=\"http://localhost:3000/red.\" class=\"markup--anchor markup--p-anchor\">.&lt;/a>\n\nYou want to nest the `Orange` and `Yellow` components inside the `Red` component, and the `Indigo` component inside the `Blue` component. Remember to import your components to use them in a `Route` tag. You'll have to go add the corresponding `Route` tags to the `Red.js` and `Blue.js` files. Make sure to use the correct nested paths, such as `\"/red/orange\"` for the orange `Route`.\n\n### Phase 2: Links\n\nManually navigating to our newly created routes is tiresome, so let's add functionality to take care of this process for us. React Router provides the `Link` and `NavLink` components for this purpose.\n\nAdd `Link`s to the paths `/red`, `/green`, `/blue`, and `/violet` in the `Rainbow` component. For example, your red link should look like\n\n    &lt;Link to=\"/red\">Red&lt;/NavLink>\n\nWhen you are at `blue` you want to be able to get to `/blue/indigo`, and then back to `/blue`. Add the corresponding `Link`s to the `Blue` component like this:\n\n    &lt;Link to='/blue' >Blue only&lt;/Link>\n    &lt;Link to='/blue/indigo' >Add indigo&lt;/Link>\n\nSimilarly, add `Link`s to `/red`, `/red/orange` and `/red/yellow` to the `Red` component. Test all your links. Navigation is so much easier now!\n\n### Phase 3: NavLinks\n\nIt would be nice if our links gave us some indication of which route you were at. Fortunately, React Router has a special component for that very purpose: `NavLink`. NavLinks get an extra CSS class when their `to` prop matches the current URL. By default this class is called `active`.\n\nGo ahead and switch all your `Link`s to `NavLink`s. If you open the app you won't see any change yet. That's because you haven't added any special styling to the `active` class. Go ahead and open the `index.css` file. Create an `.active` class and add the line `font-weight: 700`. Now your active links will be bold. Isn't that nice!\n\nThe only problem is that now the `Blue only` link is active even when the path is `/blue/indigo`. That doesn't make a lot of sense. Let's add the `exact` flag to that link so it will only be active when its `to` exactly matches the current path. Now it should look like:\n\n    &lt;NavLink exact to=\"/blue\">\n      Blue only\n    &lt;/NavLink>\n\nDo the same for the `Red only` link. Everything should be working now.\n\n### Phase 4 — Changing NavLink's Active Class\n\nYou've already set up `NavLink` to bold the link text using the `.active` class in `src/index.css`. But what if you wanted this class to be something else? For instance, what if you want your main color links (Red, Green, Blue, Violet) to be styled differently when active than your sub-route links (Red Only, Add Orange, Add Yellow, etc.).\n\nYou can set the class that React Router sets to an active `NavLink` by adding the `activeClassName` prop.\n\nFor instance, when we are at a route matching the below `NavLink`'s `to` prop, the component will have a class of `.parent-active` applied:\n\n    &lt;NavLink to=\"/blue\" activeClassName=\"parent-active\" >\n      Blue\n    &lt;/NavLink>\n\nThis allows much more flexibility to style an active `NavLink`!\n\nUsing the example above, add an `activeClassName` prop to each of your `NavLink`s in `src/components/Rainbow.js`. Now, add some CSS styling for that class in your `src/index.css` to distinguish your main and your sub-route links.\n\nCompare your work to the solution and make sure the behavior is the same. Time to celebrate! ✨ 🌈 ✨\n\nYou can also learn more about using the React Router at &lt;a href=\"https://reacttraining.com/react-router/web/guides/quick-start\" class=\"markup--anchor markup--p-anchor\">reacttraining.com&lt;/a>!\n\n---\n\n### Exploring React Builds Project\n\nIn this project, you'll use Create React App to create a simple React application. You'll experiment with some of the features that Create React App provides and deploy a production build of your application to a standalone Express application.\n\n### Phase 0: Setup\n\nBegin by using the &lt;a href=\"https://github.com/facebook/create-react-app\" class=\"markup--anchor markup--p-anchor\">create-react-app&lt;/a> package to create a React application:\n\n    npx create-react-app exploring-react-builds --template @appacademy/simple\n\n> _Remember that using the_ `create-react-app` _command initializes your project as a Git repository. If you use the_ `ls -a` _to view the hidden files in your project, you'll see the _`.git` _file._\n\nUpdate the `App` component:\n\n-   &lt;span id=\"9186\">Wrap the `&lt;h1>` element with a `&lt;div>` element; and&lt;/span>\n-   &lt;span id=\"5e97\">Change the `&lt;h1>` element content to something like \"Exploring React Builds\".&lt;/span>\n\n&lt;!-- -->\n\n    // ./src/App.js\n\n    import React from 'react';\n\n    function App() {\n      return (\n        &lt;div>\n          &lt;h1>Exploring React Builds&lt;/h1>\n        &lt;/div>\n      );\n    }\n\n    export default App;\n\n### Phase 1: Using CSS modules\n\nYou've already seen an example of using the `import` keyword to import a stylesheet into a module so that it'll be included in your application build. That's the technique being used to include the global `index.css` stylesheet:\n\n    // ./src/index.js\n\n    import React from 'react';\n    import ReactDOM from 'react-dom';\n    import './index.css';\n    import App from './App';\n\n    ReactDOM.render(\n      &lt;React.StrictMode>\n        &lt;App />\n      &lt;/React.StrictMode>,\n      document.getElementById('root')\n    );\n\nYou can also leverage &lt;a href=\"https://github.com/css-modules/css-modules\" class=\"markup--anchor markup--p-anchor\">CSS modules&lt;/a> in your Create React App projects. CSS Modules scope stylesheet class names so that they are unique to a specific React component. This allows you to create class names without having to worry if they might collide with class names used in another component.\n\nAdd a new `css-modules` folder to the `src` folder. Within that folder, add the following files:\n\n-   &lt;span id=\"2912\">`HeadingA.js`&lt;/span>\n-   &lt;span id=\"3aa3\">`HeadingA.module.css`&lt;/span>\n-   &lt;span id=\"2ea3\">`HeadingB.js`&lt;/span>\n-   &lt;span id=\"ca2b\">`HeadingB.module.css`&lt;/span>\n\nThen update the contents of each file to the following:\n\n    // ./src/css-modules/HeadingA.js\n\n    import React from 'react';\n    import styles from './HeadingA.module.css';\n\n    function HeadingA() {\n      return (\n        &lt;h1 className={styles.heading}>Heading A&lt;/h1>\n      );\n    }\n\n    export default HeadingA;\n\n    /* ./src/css-modules/HeadingA.module.css */\n\n    .heading {\n      color: green;\n    }\n\n    // ./src/css-modules/HeadingB.js\n\n    import React from 'react';\n    import styles from './HeadingB.module.css';\n\n    function HeadingB() {\n      return (\n        &lt;h1 className={styles.heading}>Heading B&lt;/h1>\n      );\n    }\n\n    export default HeadingB;\n\n    /* ./src/css-modules/HeadingB.module.css */\n\n    .heading {\n      color: red;\n    }\n\nNotice how the `.heading` CSS class name is being used within each component to set the color of the `&lt;h1>` element. For the `HeadingA` component, the color is `green`, and for the `HeadingB` component, the color is `red`. Using the file naming convention `[name].module.css` let's Create React App know that we want these stylesheets to be processed as CSS Modules. Using CSS Modules allows the `.heading` class name to be reused across components without any issue.\n\nTo see this feature in action, update your `App` component to render both of your new components:\n\n    import React from 'react';\n    import HeadingA from './css-modules/HeadingA';\n    import HeadingB from './css-modules/HeadingB';\n\n    function App() {\n      return (\n        &lt;div>\n          &lt;h1>Exploring React Builds&lt;/h1>\n          &lt;HeadingA />\n          &lt;HeadingB />\n        &lt;/div>\n      );\n    }\n\n    export default App;\n\nThen run your application (`npm start`) to see \"Heading A\" and \"Heading B\" displayed respectively in green and red. If you use the browser's developer tools to inspect \"Heading A\", you'll see that the `.heading` class name has been modified so that it's unique to the `HeadingA` component:\n\nCSS Modules is an example of how a front-end build process can be used to modify code to enable a feature that's not natively supported by browsers.\n\n### Phase 2: Using an image in a component\n\nCreate React App configures webpack with support for loading images (as well as CSS, fonts, and other file types). What this means, for you as the developer, is that you can add an image file to your project, import it directly into a module, and render it in a React component.\n\nDownload any image of off the Web or &lt;a href=\"https://appacademy-open-assets.s3-us-west-1.amazonaws.com/Modular-Curriculum/content/react-redux/topics/react-builds/assets/react-builds-cat.png\" class=\"markup--anchor markup--p-anchor\">click here&lt;/a> to download the below image.\n\n&lt;figure>\n&lt;img src=\"https://cdn-images-1.medium.com/max/800/0*233dNJ6vfgAmEVCD\" class=\"graf-image\" />\n&lt;/figure>Then within the `src` folder add a new folder named `image`. Within that folder add a new component file named `Image.js`. Also add your downloaded image file to the `image` folder (so it's a sibling to the `Image.js` file).\n\nUpdate the contents of the `Image.js` file to this:\n\n    // ./src/image/Image.js\n\n    import React from 'react';\n    import cat from './react-builds-cat.png';\n\n    console.log(cat); // /static/media/react-builds-cat.45f7f4d2.png\n\n    function Image() {\n      // Import result is the URL of your image.\n      return &lt;img src={cat} alt=\"images/images/Cat\" />;\n    }\n\n    export default Image;\n\nYou can import an image into a component using the `import` keyword. This tells webpack to include the image in the build. Notice that when you import an image into a module, you'll get a path to the image's location within the build. You can use this path to set the `src` attribute on an `&lt;img>` element.\n\n> _Be sure to update the image_ `import` _statement to the correct file name if you're using your own image!_\n\nNow update the `App` component to import and render the `Image` component:\n\n    // ./src/App.js\n\n    import React from 'react';\n    import HeadingA from './css-modules/HeadingA';\n    import HeadingB from './css-modules/HeadingB';\n    import Image from './image/Image';\n\n    function App() {\n      return (\n        &lt;div>\n          &lt;h1>Exploring React Builds&lt;/h1>\n          &lt;HeadingA />\n          &lt;HeadingB />\n          &lt;Image />\n        &lt;/div>\n      );\n    }\n\n    export default App;\n\nIf you run your application (`npm start`) you'll see your image displayed on the page! You can also open your browser's developer tools and view the \"Sources\" for the current page. If you can expand the `localhost:3000` &amp;gt; `static` &amp;gt; `media` node on the left, you can see the image file that webpack copied to your build.\n\n### Images in stylesheets\n\nYou can also reference images in your CSS files too. Add a CSS file named `Image.css` to the `./src/image` folder and update its contents to this:\n\n    /* ./src/image/Image.css */\n\n    .cat {\n      background-image: url(./react-builds-cat.png);\n      width: 400px;\n      height: 400px;\n    }\n\nThen update the `Image` component to this:\n\n    // ./src/image/Image.js\n\n    import React from 'react';\n    import './Image.css';\n    import cat from './react-builds-cat.png';\n\n    console.log(cat); // /static/media/react-builds-cat.45f7f4d2.png\n\n    function Image() {\n      return (\n        &lt;div>\n          {/* Import result is the URL of your image. */}\n          &lt;img src={cat} alt=\"Cat\" />\n          &lt;div className='cat'>\n&lt;/div>\n        &lt;/div>\n      );\n    }\n\n    export default Image;\n\nNow you'll see the image displayed twice on the page!\n\n### Phase 3: Updating the supported browsers (and its affect on code transpilation)\n\nEarlier you learned about the `browerslist` setting in the `package.json` file and now adjusting these targets affect how your code will be transpiled:\n\n    {\n      \"browserslist\": {\n        \"production\": [\n          \">0.2%\",\n          \"not dead\",\n          \"not op_mini all\"\n        ],\n        \"development\": [\n          \"last 1 chrome version\",\n          \"last 1 firefox version\",\n          \"last 1 safari version\"\n        ]\n      }\n    }\n\nThe `production` list specifies the browsers to target when creating a production build and the `development` list specifics the browsers to target when running the application using `npm start`. Currently, you're targeting relatively recent versions of the major browsers when creating a development build. Targeting older browser versions results in your code being transpiled to an older version of JavaScript.\n\nTo experiment with this configuration option, let's add a class component to the project. Add a new folder named `class-component` to the `src` folder. Within that folder, add a file named `ClassComponent.js` containing the following code:\n\n\n```js\n//x\n\n\n// ./src/class-component/ClassComponent.js\n\nimport React from 'react';\n\nclass ClassComponent extends React.Component {\n    render() {\n        return &lt;h1>Class Component&lt;/h1>;\n    }\n}\n\nexport default ClassComponent;</code></pre></div>\n<p>Don't forget to update your <code class=\"language-text\">App</code> component to render the new component:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token comment\">// ./src/App.js</span>\n\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> HeadingA <span class=\"token keyword\">from</span> <span class=\"token string\">'./css-modules/HeadingA'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> HeadingB <span class=\"token keyword\">from</span> <span class=\"token string\">'./css-modules/HeadingB'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> Image <span class=\"token keyword\">from</span> <span class=\"token string\">'./image/Image'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ClassComponent <span class=\"token keyword\">from</span> <span class=\"token string\">'./class-component/ClassComponent'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span>Exploring React Builds<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>HeadingA <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>HeadingB <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>Image <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>ClassComponent <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> App<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Now run your application using <code class=\"language-text\">npm start</code>. Open your browser's developer tools and view the \"Sources\" for the current page. Expand the <code class=\"language-text\">localhost:3000</code> > <code class=\"language-text\">static</code> > <code class=\"language-text\">js</code> node on the left and select the <code class=\"language-text\">main.chunk.js</code> file. Press <code class=\"language-text\">CMD+F</code> on macOS or <code class=\"language-text\">CTRL+F</code> on Windows to search the file for \"Class Component\". Here's what the transpiled code looks like for the <code class=\"language-text\">ClassComponent</code> class:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token keyword\">class</span> <span class=\"token class-name\">ClassComponent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">react__WEBPACK_IMPORTED_MODULE_0___default<span class=\"token punctuation\">.</span>a<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token comment\">/*#__PURE__*/</span> react__WEBPACK_IMPORTED_MODULE_0___default<span class=\"token punctuation\">.</span>a<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n            <span class=\"token string\">'h1'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">__self</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span>\n                <span class=\"token literal-property property\">__source</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token literal-property property\">fileName</span><span class=\"token operator\">:</span> _jsxFileName<span class=\"token punctuation\">,</span>\n                    <span class=\"token literal-property property\">lineNumber</span><span class=\"token operator\">:</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token literal-property property\">columnNumber</span><span class=\"token operator\">:</span> <span class=\"token number\">7</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token string\">'Class Component'</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<blockquote>\n<p><em>Have you wondered yet why you need to use the developer tools to view the bundles generated by Create React App? Remember that when you run</em> <code class=\"language-text\">npm start</code><em>, Create React App builds your application using</em> <code class=\"language-text\">webpack-dev-server</code><em>. To keep things as performant as possible, the bundles generated by</em> <code class=\"language-text\">webpack-dev-server</code> <em>are stored in memory instead of writing them to the file system.</em></p>\n</blockquote>\n<p>The JSX in the component's <code class=\"language-text\">render</code> method has been converted to JavaScript but the <code class=\"language-text\">ClassComponent</code> ES2015 class is left alone. This makes sense though as JSX isn't natively supported by any browser while ES2015 classes have been natively supported by browsers for awhile now.</p>\n<p>But what if you need to target a version of a browser that doesn't support ES2015 classes? You can use the <a href=\"https://caniuse.com/#feat=es6-class\" class=\"markup--anchor markup--p-anchor\">\"Can I use…\"</a> website to see when browsers started supporting ES2105 (or ES6) classes. Starting with version 49, Chrome natively supported classes. But imagine that you need to support Chrome going back to version 30, a version of Chrome that doesn't support classes.</p>\n<p>Change the <code class=\"language-text\">browserslist.development</code> property in the <code class=\"language-text\">package.json</code> file to this:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//on</span>\n<span class=\"token punctuation\">{</span>\n    <span class=\"token string-property property\">\"browserslist\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string-property property\">\"production\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\">0.2%\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"not dead\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"not op_mini all\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n        <span class=\"token string-property property\">\"development\"</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"chrome >= 30\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"last 1 firefox version\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"last 1 safari version\"</span><span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The query <code class=\"language-text\">chrome >= 30</code> specifies that you want to target Chrome version 30 or newer.</p>\n<blockquote>\n<p><em>The</em> <a href=\"https://browserl.ist/\" class=\"markup--anchor markup--blockquote-anchor\">\n<em>browserl.ist</em>\n</a> <em>website can be used to see the browsers supported by your configured</em> <code class=\"language-text\">browserslist</code><em>.</em></p>\n</blockquote>\n<p>Stop your application if it's currently running. Delete the <code class=\"language-text\">./node_modules/.cache</code> folder and run <code class=\"language-text\">npm start</code> again. Then view the <code class=\"language-text\">main.chunk.js</code> bundle again in the developer tools:</p>\n<figure>\n<img src=\"https://cdn-images-1.medium.com/max/800/0*TKBUkpbL5aSm5PTQ\" class=\"graf-image\" />\n</figure>Now your ES2015 class component is being converted to a constructor function! Here's the transpiled code for reference:\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token keyword\">let</span> ClassComponent <span class=\"token operator\">=</span> <span class=\"token comment\">/*#__PURE__*/</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">_React$Component</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">Object</span><span class=\"token punctuation\">(</span>\n        _Users_jameschurchill_Documents_GitHub_Modular_Curriculum_content_react_redux_topics_react_builds_projects_exploring_react_builds_solution_node_modules_babel_preset_react_app_node_modules_babel_runtime_helpers_esm_inherits__WEBPACK_IMPORTED_MODULE_2__<span class=\"token punctuation\">[</span>\n            <span class=\"token string\">'default'</span>\n        <span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>ClassComponent<span class=\"token punctuation\">,</span> _React$Component<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">let</span> _super <span class=\"token operator\">=</span> <span class=\"token function\">Object</span><span class=\"token punctuation\">(</span>\n        _Users_jameschurchill_Documents_GitHub_Modular_Curriculum_content_react_redux_topics_react_builds_projects_exploring_react_builds_solution_node_modules_babel_preset_react_app_node_modules_babel_runtime_helpers_esm_createSuper__WEBPACK_IMPORTED_MODULE_3__<span class=\"token punctuation\">[</span>\n            <span class=\"token string\">'default'</span>\n        <span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>ClassComponent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">ClassComponent</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">Object</span><span class=\"token punctuation\">(</span>\n            _Users_jameschurchill_Documents_GitHub_Modular_Curriculum_content_react_redux_topics_react_builds_projects_exploring_react_builds_solution_node_modules_babel_preset_react_app_node_modules_babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_0__<span class=\"token punctuation\">[</span>\n                <span class=\"token string\">'default'</span>\n            <span class=\"token punctuation\">]</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> ClassComponent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token function\">_super</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">Object</span><span class=\"token punctuation\">(</span>\n        _Users_jameschurchill_Documents_GitHub_Modular_Curriculum_content_react_redux_topics_react_builds_projects_exploring_react_builds_solution_node_modules_babel_preset_react_app_node_modules_babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_1__<span class=\"token punctuation\">[</span>\n            <span class=\"token string\">'default'</span>\n        <span class=\"token punctuation\">]</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>ClassComponent<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'render'</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token comment\">/*#__PURE__*/</span> react__WEBPACK_IMPORTED_MODULE_4___default<span class=\"token punctuation\">.</span>a<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n                    <span class=\"token string\">'h1'</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">__self</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token literal-property property\">__source</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">fileName</span><span class=\"token operator\">:</span> _jsxFileName<span class=\"token punctuation\">,</span>\n                            <span class=\"token literal-property property\">lineNumber</span><span class=\"token operator\">:</span> <span class=\"token number\">7</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token literal-property property\">columnNumber</span><span class=\"token operator\">:</span> <span class=\"token number\">7</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token string\">'Class Component'</span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">return</span> ClassComponent<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>react__WEBPACK_IMPORTED_MODULE_4___default<span class=\"token punctuation\">.</span>a<span class=\"token punctuation\">.</span>Component<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Luckily it's very rare that you'll need to read the code in your generated bundles. webpack, by default, is configured to generate sourcemaps. Sourcemaps are a mapping of the code in a generated file, like a bundle file, to the original source code. This gives you access to your original source code in the browser's developer tools:</p>\n<p>You can even set a breakpoint in your source within the developer tools to stop execution on a specific line of code!</p>\n<h3>Phase 4: Adding environment variables</h3>\n<p>Earlier you learned that Create React App supports defining environment variables in an <code class=\"language-text\">.env</code> file. This gives you a convenient way to avoid hard coding values that vary across environments.</p>\n<p>Let's experiment with this feature so that you can see how the Create React App build process embeds environment variables into your HTML, CSS, and JavaScript bundles.</p>\n<p>Add an <code class=\"language-text\">.env</code> file to the root of your Create React App project. Define an environment variable named <code class=\"language-text\">REACT_APP_TITLE</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">REACT_APP_TITLE=Exploring React Builds</code></pre></div>\n<p>Remember that environment variables need to be prefixed with <code class=\"language-text\">REACT_APP_</code> for Create React App to process them. After defining your environment variable, you can refer to it within JSX using an expression and <code class=\"language-text\">process.env</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// ./src/App.js</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> HeadingA <span class=\"token keyword\">from</span> <span class=\"token string\">'./css-modules/HeadingA'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> HeadingB <span class=\"token keyword\">from</span> <span class=\"token string\">'./css-modules/HeadingB'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> Image <span class=\"token keyword\">from</span> <span class=\"token string\">'./image/Image'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ClassComponent <span class=\"token keyword\">from</span> <span class=\"token string\">'./class-component/ClassComponent'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>process<span class=\"token punctuation\">.</span>env<span class=\"token punctuation\">.</span><span class=\"token constant\">REACT_APP_TITLE</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>HeadingA <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>HeadingB <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>Image <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>ClassComponent <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> App<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Environment variables can also be referred to in regular JavaScript code:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">console.log(process.env.REACT_APP_TITLE);</code></pre></div>\n<p>You can also reference environment variables in your <code class=\"language-text\">./public/index.html</code> file like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token doctype\"><span class=\"token punctuation\">&lt;!</span><span class=\"token doctype-tag\">DOCTYPE</span> <span class=\"token name\">html</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>html</span> <span class=\"token attr-name\">lang</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>en<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>head</span><span class=\"token punctuation\">></span></span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>meta</span> <span class=\"token attr-name\">charset</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>utf-8<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>title</span><span class=\"token punctuation\">></span></span>%REACT_APP_TITLE%<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>title</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>head</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>body</span><span class=\"token punctuation\">></span></span>\n        <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">id</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>root<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>body</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>html</span><span class=\"token punctuation\">></span></span></code></pre></div>\n<p>Run your application again using <code class=\"language-text\">npm start</code>. Open your browser's developer tools and view the \"Sources\" for the current page. Expand the <code class=\"language-text\">localhost:3000</code> node on the left and select <code class=\"language-text\">(index)</code>. Notice that the text <code class=\"language-text\">%REACT_APP_TITLE%</code> within the <code class=\"language-text\">&lt;title></code> element has been converted to the text literal <code class=\"language-text\">Exploring React Builds</code>:</p>\n<p>If you expand the <code class=\"language-text\">localhost:3000</code> > <code class=\"language-text\">static</code> > <code class=\"language-text\">js</code> node on the left and select the <code class=\"language-text\">main.chunk.js</code> file, you can see how the <code class=\"language-text\">App</code> component's JSX has been converted to JavaScript:</p>\n<p>Here's a closer look at the relevant <code class=\"language-text\">React.createElement</code> method call:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token comment\">/*#__PURE__*/</span> react__WEBPACK_IMPORTED_MODULE_0___default<span class=\"token punctuation\">.</span>a<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span>\n    <span class=\"token string\">'h1'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">__self</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">__source</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">fileName</span><span class=\"token operator\">:</span> _jsxFileName<span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">lineNumber</span><span class=\"token operator\">:</span> <span class=\"token number\">10</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">columnNumber</span><span class=\"token operator\">:</span> <span class=\"token number\">7</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token string\">'Exploring React Builds'</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Again, notice how the environment variable has been replaced with a text literal. This has important security implications for you to consider. Because environment variables are embedded into your HTML, CSS, and JavaScript bundles during the build process, it's <em>very important</em> to not store any secrets, like API keys, in your environment variables. Remember, anyone can view your bundled code in the browser by inspecting your files!</p>\n<h3>Phase 5: Deploying a production build</h3>\n<p>In the last phase of this project, let's add routing to the React application, create a production build, and deploy the build to an Express application!</p>\n<h3>Adding routing</h3>\n<p>To add React Router to the application, start by installing the <code class=\"language-text\">react-router-dom</code> npm package:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">npm install react-router-dom@^5.0.0</code></pre></div>\n<p>Then update the <code class=\"language-text\">App</code> component to this code:</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//x</span>\n<span class=\"token comment\">// ./src/App.js</span>\n\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> BrowserRouter<span class=\"token punctuation\">,</span> Switch<span class=\"token punctuation\">,</span> Route<span class=\"token punctuation\">,</span> Link <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-router-dom'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> HeadingA <span class=\"token keyword\">from</span> <span class=\"token string\">'./css-modules/HeadingA'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> HeadingB <span class=\"token keyword\">from</span> <span class=\"token string\">'./css-modules/HeadingB'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> Image <span class=\"token keyword\">from</span> <span class=\"token string\">'./image/Image'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">import</span> ClassComponent <span class=\"token keyword\">from</span> <span class=\"token string\">'./class-component/ClassComponent'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">App</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n        <span class=\"token operator\">&lt;</span>BrowserRouter<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>h1<span class=\"token operator\">></span><span class=\"token punctuation\">{</span>process<span class=\"token punctuation\">.</span>env<span class=\"token punctuation\">.</span><span class=\"token constant\">REACT_APP_TITLE</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>nav<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>ul<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token string\">\"/\"</span><span class=\"token operator\">></span>Home<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token string\">\"/image\"</span><span class=\"token operator\">></span>Image<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>li<span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token string\">\"/class-component\"</span><span class=\"token operator\">></span>Class Component<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>nav<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>Switch<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>Route path<span class=\"token operator\">=</span><span class=\"token string\">\"/image\"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>Image <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Route<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>Route path<span class=\"token operator\">=</span><span class=\"token string\">\"/class-component\"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>ClassComponent <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Route<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>Route path<span class=\"token operator\">=</span><span class=\"token string\">\"/\"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>HeadingA <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>HeadingB <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Route<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Switch<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>BrowserRouter<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> App<span class=\"token punctuation\">;</span></code></pre></div>\n<p>Be sure to run and test your application to ensure that the defined routes work as expected:</p>\n<ul>\n<li><span id=\"151a\"><code class=\"language-text\">/</code> - Should display the <code class=\"language-text\">HeadingA</code> and <code class=\"language-text\">HeadingB</code> components;</span></li>\n<li><span id=\"1e2b\"><code class=\"language-text\">/image</code> - Should display the <code class=\"language-text\">Image</code> component; and</span></li>\n<li><span id=\"7f3a\"><code class=\"language-text\">/class-component</code> - Should display the <code class=\"language-text\">ClassComponent</code> component.</span></li>\n</ul>\n<h3>Creating a production build</h3>\n<p>To create a production build, run the command <code class=\"language-text\">npm run build</code> from the root of your project. The output in the terminal should look something like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">> solution@0.1.0 build [absolute path to your project]\n> react-scripts build\n\nCreating an optimized production build...\nCompiled successfully.\n\nFile sizes after gzip:\n\n  47.83 KB  build/static/js/2.722c16c4.chunk.js\n  773 B     build/static/js/runtime-main.b7d1e5ee.js\n  745 B     build/static/js/main.12299197.chunk.js\n  197 B     build/static/css/main.e9a0d1f8.chunk.css\n\nThe project was built assuming it is hosted at /.\nYou can control this with the homepage field in your package.json.\n\nThe build folder is ready to be deployed.\nYou may serve it with a static server:\n\n  npm install -g serve\n  serve -s build\n\nFind out more about deployment here:\n\n  bit.ly/CRA-deploy</code></pre></div>\n<p>Ignore the comments about using <code class=\"language-text\">serve</code> to deploy your application (i.e. <code class=\"language-text\">npm install -g serve</code> and <code class=\"language-text\">serve -s build</code>). In the next step, you'll create a simple Express application to server your React application.</p>\n<h3>Serving a React application using Express</h3>\n<p>Create a new folder for your Express application outside of the Create React App project folder.</p>\n<blockquote>\n<p><em>For example, from the root of your project, use</em> <code class=\"language-text\">cd ..</code> <em>to go up a level and then create a new folder named</em> <code class=\"language-text\">express-server</code> <em>by running the command</em> <code class=\"language-text\">mkdir express-server</code><em>. This makes the</em> <code class=\"language-text\">express-server</code> <em>folder a sibling to your Create React App project folder.</em></p>\n</blockquote>\n<p>Browse into the <code class=\"language-text\">express-server</code> folder and initialize it to use npm (i.e. <code class=\"language-text\">npm init -y</code>). Then install Express by running the command <code class=\"language-text\">npm install express@^4.0.0</code>.</p>\n<p>App a file named <code class=\"language-text\">app.js</code> with the following contents:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// ./app.js\n\nconst express = require('express');\nconst path = require('path');\n\nconst app = express();\n\napp.use(express.static(path.join(__dirname, 'public')));\n\napp.get('*', function(req, res) {\n  res.sendFile(path.join(__dirname, 'public', 'index.html'));\n});\n\nconst port = 9000;\n\napp.listen(port, () => console.log(`Listening on port ${port}...`));</code></pre></div>\n<p>This simple Express application will:</p>\n<ul>\n<li><span id=\"31ba\">Attempt to match incoming requests to static files located in the <code class=\"language-text\">public</code> folder; and</span></li>\n<li><span id=\"16e6\">If a matching static file isn't found, then the <code class=\"language-text\">./public/index.html</code> file will be served for all other requests.</span></li>\n</ul>\n<p>Now add a folder named <code class=\"language-text\">public</code> to the root of your Express project. Copy the files from the <code class=\"language-text\">build</code> folder in your Create React App project to the <code class=\"language-text\">public</code> folder in the Express application project. Then run your application using the command <code class=\"language-text\">node app.js</code>.</p>\n<p>Open a browser and browse to the URL <code class=\"language-text\">http://localhost:9000/</code>. You should see your React application served from your Express application! Be sure to click the navigation links to verify that all of your configured routes work as expected.</p>\n<p>Also, because you configured Express to serve the <code class=\"language-text\">./public/index.html</code> file for any request that doesn't match a static file, you can \"deep link\" to any of your React application's routes:</p>\n<ul>\n<li>\n<span id=\"58e7\">\n<a href=\"http://localhost:9000/image\" class=\"markup--anchor markup--li-anchor\">http://localhost:9000/image</a>\n</span>\n</li>\n<li>\n<span id=\"3fa9\">\n<a href=\"http://localhost:9000/class-component\" class=\"markup--anchor markup--li-anchor\">http://localhost:9000/class-component</a>\n</span>\n</li>\n</ul>\n<p><em>More content at</em> <a href=\"http://plainenglish.io/\" class=\"markup--anchor markup--p-anchor\">\n<strong>\n<em>plainenglish.io</em>\n</strong>\n</a></p>\n<p>By <a href=\"https://medium.com/@bryanguner\" class=\"p-author h-card\">Bryan Guner</a> on <a href=\"https://medium.com/p/1965dcde8d4f\">July 15, 2021</a>.</p>\n<p><a href=\"https://medium.com/@bryanguner/react-in-depth-1965dcde8d4f\" class=\"p-canonical\">Canonical link</a></p>\n<p>August 31, 2021.</p>"},{"url":"/docs/python/at-length/","relativePath":"docs/python/at-length.md","relativeDir":"docs/python","base":"at-length.md","name":"at-length","frontmatter":{"title":"Python at length","weight":0,"excerpt":"Variables are simply declarations that are used to store certain values.","seo":{"title":"Python at length","description":"Python at length","robots":[],"extra":[]},"template":"docs"},"html":"<h4>Understanding variables <a id=\"understanding-variables\"></h4>\n</a>\n<p>Variables are simply declarations that are used to store certain values. For instance, the variable <code class=\"language-text\">name</code> can hold the value of <code class=\"language-text\">John Smith.</code> Several rules need to be considered when declaring variable names. For starters, a variable name cannot begin with a number.</p>\n<p><code class=\"language-text\">2name = incorrect #incorrect</code></p>\n<p><code class=\"language-text\">name = correct #correct</code></p>\n<p>Variable names are case sensitive. This means that the variable <code class=\"language-text\">school</code> is not the same as <code class=\"language-text\">School</code>.</p>\n<p>Variables can hold different data types. This includes strings, integers, Booleans, long, lists, and arrays.</p>\n<p>In Python, we do not need to declare the data type while writing a variable. This is because the code is compiled and interpreted later. The compiler will throw an error in case there is a mismatch in the data types.</p>\n<p>Let's talk about the different data types.</p>\n<ol>\n<li>Strings</li>\n</ol>\n<p>Strings are usually presented in a text format. We will declare a string variable, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">\"john\"</span>school <span class=\"token operator\">=</span> <span class=\"token string\">\"Alliance Francaise\"</span></code></pre></div>\n<p>When we run <code class=\"language-text\">print(name)</code>, the output will be <code class=\"language-text\">john</code>.</p>\n<ol>\n<li>Integers</li>\n</ol>\n<p>These variables hold numeric values, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">math <span class=\"token operator\">=</span> 90chemistry <span class=\"token operator\">=</span> 100biology <span class=\"token operator\">=</span> <span class=\"token number\">70</span></code></pre></div>\n<p>We can find the total of the variables above using the following statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>math<span class=\"token operator\">+</span>chemistry<span class=\"token operator\">+</span>biology<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The total is <code class=\"language-text\">260</code>.</p>\n<p>A TypeError is thrown when you try to add a string to an integer, as shwon below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">var1 <span class=\"token operator\">=</span> <span class=\"token string\">\"30\"</span> <span class=\"token comment\">#stringvar2 = 20 #integer​print(var1+var2)#type error</span></code></pre></div>\n<p>We can sum <code class=\"language-text\">var1</code> and <code class=\"language-text\">var2</code> by converting <code class=\"language-text\">var1</code> to an integer using the <code class=\"language-text\">int()</code> function. The following code will execute successfully.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">var1 <span class=\"token operator\">=</span> <span class=\"token string\">\"30\"</span> <span class=\"token comment\">#stringvar2 = 20 #integer​print(int(var1)+var2) # Output: 50</span></code></pre></div>\n<blockquote>\n<p>Make sure that the variable stores a value that can be converted to an integer before using the int() method.</p>\n</blockquote>\n<ol>\n<li>Booleans</li>\n</ol>\n<p>There are only two Boolean values: <code class=\"language-text\">True</code> and <code class=\"language-text\">False</code>. In other words, something can either be true or false. We declare these values, as shown below. Please note that Python is case sensitive.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">isOn <span class=\"token operator\">=</span> TrueisChecked <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>A <code class=\"language-text\">bool()</code> method can help convert a value to a boolean. The code snippets below showcase how a <code class=\"language-text\">bool()</code> function can be used.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">#returns Trueprint(bool(0))  #returns False</span></code></pre></div>\n<p>The <code class=\"language-text\">bool()</code> function returns False when there are no parameters.</p>\n<ol>\n<li>Float</li>\n</ol>\n<p>This data type consists of numbers that have a decimal place. A perfect example of a float variable is highlighted below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Bmi <span class=\"token operator\">=</span> <span class=\"token number\">45.7</span></code></pre></div>\n<h4>Understanding lists <a id=\"understanding-lists\"></h4>\n</a>\n<p>Lists allow us to store numerous elements in a particular variable. For instance, we can have a list that stores all the student names in a class. We use <code class=\"language-text\">[]</code> to define a list.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">students <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">#list example</span></code></pre></div>\n<p>Elements in a list are usually separated by a comma, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">students <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"john\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mary Thomas\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"John Smith\"</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Each element in the above <code class=\"language-text\">students</code> list has an index. By default, the first index is 0. So the item at index [0] is <code class=\"language-text\">john</code>, while the value at index <code class=\"language-text\">1</code> is <code class=\"language-text\">Mary Thomas</code>. A list of integers will look as follows.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">student_marks <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span> <span class=\"token number\">78</span><span class=\"token punctuation\">,</span> <span class=\"token number\">90</span><span class=\"token punctuation\">,</span> <span class=\"token number\">78</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>We can access different list functionalities using built-in functions. For instance, to add a value to the <code class=\"language-text\">student_marks</code> list, we use the <code class=\"language-text\">append</code> function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">student_marks<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">\"Guardian Angel\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>student_marks<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The above function adds <code class=\"language-text\">Guardian Angel</code> at the end of the <code class=\"language-text\">student_marks</code> list.</p>\n<p>When we print the list it shows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\">#output[90, 78, 90, 78, 'Guardian Angel']</span></code></pre></div>\n<p>We use <code class=\"language-text\">len(student_marks)</code> to determine the length of the list. We use the <code class=\"language-text\">remove()</code> function to delete something from the list. For instance, we can remove <code class=\"language-text\">90</code> from the <code class=\"language-text\">student_mark</code> list as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">student_marks<span class=\"token punctuation\">.</span>remove<span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>student_marks<span class=\"token punctuation\">)</span></code></pre></div>\n<p>In lists, negative indices allow us to count elements starting from the last one. For instance, the element with an index of <code class=\"language-text\">-1</code> in the above <code class=\"language-text\">student_marks</code> list is <code class=\"language-text\">\"Guardian Angel\"</code>. The second last element <code class=\"language-text\">78</code> has an index of <code class=\"language-text\">-2</code>.</p>\n<h4>Understanding functions or methods <a id=\"understanding-functions-or-methods\"></h4>\n</a>\n<p>Methods are quite critical in programming. They help store reusable code. This means that a person can call already declared methods rather than writing statements from scratch repeatedly. This saves significant time, that can be invested in other productive activities.</p>\n<p>In Python, we use the <code class=\"language-text\">def</code> keyword to declare a function. An example of a python method is shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">readData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'success'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The above function prints <code class=\"language-text\">success</code> when it's invoked. We can also pass data to a method, perform some calculations, and return the results. This is demonstrated in the code snippet below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">calculateTotal</span><span class=\"token punctuation\">(</span>chem<span class=\"token punctuation\">,</span> bio<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">return</span> chem<span class=\"token operator\">+</span>bio​<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculateTotal<span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span><span class=\"token number\">80</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">calculateTotal</code> method takes in two parameters (chem, bio). The function then returns the sum of the two values. It is important to take note of the data types when passing parameters. For instance, the <code class=\"language-text\">calculateTotal</code> method will not work when we pass in a string as a parameter. This is because the program cannot sum up an integer and a string. As shown above, we can call the <code class=\"language-text\">calculateTotal</code> method directly from our print statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculateTotal<span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span><span class=\"token number\">80</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">return</code> keyword ensures that the method returns a result after execution.</p>\n<blockquote>\n<p>Note that a function can also call another method. This is illustrated below.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">readData</span><span class=\"token punctuation\">(</span>chem<span class=\"token punctuation\">,</span> bio<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">return</span> chem<span class=\"token operator\">+</span>bio​<span class=\"token keyword\">def</span> getTotal<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>readData<span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span><span class=\"token number\">80</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">#calls the readData method​getTotal()</span></code></pre></div>\n<h4>Understanding loops <a id=\"understanding-loops\"></h4>\n</a>\n<p>Loops are critical because they allow us to iterate through lists, check for different conditions, and continuously execute various statements. The main loops are <code class=\"language-text\">for</code> and <code class=\"language-text\">while</code>.</p>\n<ol>\n<li>For loops As noted, we can use a for loop to iterate through a list, as shown below:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">student_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"John Doore\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"Matu Smith\"</span><span class=\"token punctuation\">]</span><span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> student_list<span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">for</code> loop above will print every item in the student_list.</p>\n<ol>\n<li>While loops A while loop can help us check for a particular condition. For instance, while something is true specific statements can be executed. Here is an example of a while loop in action.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">isChecked <span class=\"token operator\">=</span> falsewhile isChecked <span class=\"token operator\">==</span> true<span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hallo there'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<blockquote>\n<p>Note that the while loop above will be executed indefinitely until isChecked is set to false. You can press ctrl+c to stop the loop.</p>\n</blockquote>\n<h4>Classes <a id=\"classes\"></h4>\n</a>\n<p>Classes are a vital component of object-oriented programming. When creating a class, you must use the <code class=\"language-text\">class</code> keyword. Other elements are then nested in the class. Here is an example of a Python class.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Farmer</span><span class=\"token punctuation\">:</span> <span class=\"token comment\"># a class with the name farmer    name = \"John\" # A variable    produce = \"1000kgs\" # A variable​farmer = Farmer() #instatiating the class as an object. print(farmer.name) # accessing the properties of the Farmer class.</span></code></pre></div>\n<p>Classes can help as group things with similar characteristics. We can also assign values to class variables using the <code class=\"language-text\">init</code> function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Farmer</span><span class=\"token punctuation\">:</span>  <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> farmername<span class=\"token punctuation\">,</span> produce<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    self<span class=\"token punctuation\">.</span>farmername <span class=\"token operator\">=</span> farmername    self<span class=\"token punctuation\">.</span>produce <span class=\"token operator\">=</span> produce​farmer <span class=\"token operator\">=</span> Farmer<span class=\"token punctuation\">(</span><span class=\"token string\">\"Carry Sminson\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"10,000kgs\"</span><span class=\"token punctuation\">)</span>​<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>farmer<span class=\"token punctuation\">.</span>farmername<span class=\"token punctuation\">,</span> farmer<span class=\"token punctuation\">.</span>produce<span class=\"token punctuation\">)</span></code></pre></div>\n<p>In the above <code class=\"language-text\">Farmer</code> class, the <code class=\"language-text\">self</code> keyword represents an instance of an object. In other words, it allows us to access the different methods and attributes defined in the class.</p>\n<p>You can also declare a method in a class and use it later, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Farmer</span><span class=\"token punctuation\">:</span>  <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> farmername<span class=\"token punctuation\">,</span> produce<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    self<span class=\"token punctuation\">.</span>farmername <span class=\"token operator\">=</span> farmername    self<span class=\"token punctuation\">.</span>produce <span class=\"token operator\">=</span> produce​  <span class=\"token keyword\">def</span> <span class=\"token function\">printDetails</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token comment\"># Method      print(self.farmername, self.produce)​farmer = Farmer(\"Carry Sminson\", \"10,000kgs\")​farmer.printDetails()</span></code></pre></div>\n<h2>Python syntax was made for readability, and easy editing. For example, the python language uses a <code class=\"language-text\">:</code> and indented code, while javascript and others generally use <code class=\"language-text\">{}</code> and indented code. <a id=\"python-syntax-was-made-for-readability-and-easy-editing-for-example-the-python-language-uses-a-and-indented-code-while-javascript-and-others-generally-use-and-indented-code\"></h2>\n</a>\n<p>Lets create a [python 3](https://repl.it/languages/python3) repl, and call it <em>Hello World</em>. Now you have a blank file called <em>main.py</em>. Now let us write our first line of code:</p>\n<p><em>helloworld.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<blockquote>\n<p>Brian Kernighan actually wrote the first \"Hello, World!\" program as part of the documentation for the BCPL programming language developed by Martin Richards.</p>\n</blockquote>\n<p>Now, press the run button, which obviously runs the code. If you are not using replit, this will not work. You should research how to run a file with your text editor.</p>\n<p>If you look to your left at the console where hello world was just printed, you can see a <code class=\"language-text\">></code>, <code class=\"language-text\">>>></code>, or <code class=\"language-text\">$</code> depending on what you are using. After the prompt, try typing a line of code.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Python <span class=\"token number\">3.6</span><span class=\"token number\">.1</span> <span class=\"token punctuation\">(</span>default<span class=\"token punctuation\">,</span> Jun <span class=\"token number\">21</span> <span class=\"token number\">2017</span><span class=\"token punctuation\">,</span> <span class=\"token number\">18</span><span class=\"token punctuation\">:</span><span class=\"token number\">48</span><span class=\"token punctuation\">:</span><span class=\"token number\">35</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span>GCC <span class=\"token number\">4.9</span><span class=\"token number\">.2</span><span class=\"token punctuation\">]</span> on linuxType <span class=\"token string\">\"help\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"copyright\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"credits\"</span> <span class=\"token keyword\">or</span> <span class=\"token string\">\"license\"</span> <span class=\"token keyword\">for</span> more information<span class=\"token punctuation\">.</span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Testing command line'</span><span class=\"token punctuation\">)</span>Testing command line<span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Are you sure this works?'</span><span class=\"token punctuation\">)</span>Are you sure this works?<span class=\"token operator\">></span></code></pre></div>\n<p>The command line allows you to execute single lines of code at a time. It is often used when trying out a new function or method in the language.</p>\n<p>Another cool thing that you can generally do with all languages, are comments. In python, a comment starts with a <code class=\"language-text\">#</code>. The computer ignores all text starting after the <code class=\"language-text\">#</code>.</p>\n<p><em>shortcom.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Write some comments!</span></code></pre></div>\n<p>If you have a huge comment, do <strong>not</strong> comment all the 350 lines, just put <code class=\"language-text\">'''</code> before it, and <code class=\"language-text\">'''</code> at the end. Technically, this is not a comment but a string, but the computer still ignores it, so we will use it.</p>\n<p><em>longcom.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token triple-quoted-string string\">'''Dear PYer,I am confused about how you said you could use triple quotes to makeSUPERLONGCOMMENTS!​I am wondering if this is true,and if so,I am wondering if this is correct.​Could you help me with this?​Thanks,Random guy who used your tutorial.'''</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Testing'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Unlike many other languages, there is no <code class=\"language-text\">var</code>, <code class=\"language-text\">let</code>, or <code class=\"language-text\">const</code> to declare a variable in python. You simply go <code class=\"language-text\">name = 'value'</code>.</p>\n<p><em>vars1.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> 5y <span class=\"token operator\">=</span> 7z <span class=\"token operator\">=</span> x<span class=\"token operator\">*</span>y <span class=\"token comment\"># 35print(z) # => 35</span></code></pre></div>\n<p>Remember, there is a difference between integers and strings. <em>Remember: String =</em> <em><code class=\"language-text\">\"\"</code>.</em> To convert between these two, you can put an int in a <code class=\"language-text\">str()</code> function, and a string in a <code class=\"language-text\">int()</code> function. There is also a less used one, called a float. Mainly, these are integers with decimals. Change them using the <code class=\"language-text\">float()</code> command.</p>\n<p><em>vars2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> 5x <span class=\"token operator\">=</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span>b <span class=\"token operator\">=</span> <span class=\"token string\">'5'</span>b <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'x = '</span><span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">,</span> <span class=\"token string\">'; b = '</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">';'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># => x = 5; b = 5;</span></code></pre></div>\n<p>Instead of using the <code class=\"language-text\">,</code> in the print function, you can put a <code class=\"language-text\">+</code> to combine the variables and string.</p>\n<p>There are many operators in python:</p>\n<ul>\n<li><code class=\"language-text\">+</code></li>\n<li><code class=\"language-text\">-</code></li>\n<li><code class=\"language-text\">/</code></li>\n<li><code class=\"language-text\">*</code> These operators are the same in most languages, and allow for addition, subtraction, division, and multiplicaiton. Now, we can look at a few more complicated ones:</li>\n<li><code class=\"language-text\">%</code></li>\n<li><code class=\"language-text\">//</code></li>\n<li><code class=\"language-text\">**</code></li>\n<li><code class=\"language-text\">+=</code></li>\n<li><code class=\"language-text\">-=</code></li>\n<li><code class=\"language-text\">/=</code></li>\n<li><code class=\"language-text\">*=</code> Research these if you want to find out more…</li>\n</ul>\n<p><em>simpleops.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> 4a <span class=\"token operator\">=</span> x <span class=\"token operator\">+</span> 1a <span class=\"token operator\">=</span> x <span class=\"token operator\">-</span> 1a <span class=\"token operator\">=</span> x <span class=\"token operator\">*</span> 2a <span class=\"token operator\">=</span> x <span class=\"token operator\">/</span> <span class=\"token number\">2</span></code></pre></div>\n<p>You should already know everything shown above, as it is similar to other languages. If you continue down, you will see more complicated ones.</p>\n<p><em>complexop.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">+=</span> 1a <span class=\"token operator\">-=</span> 1a <span class=\"token operator\">*=</span> 2a <span class=\"token operator\">/=</span> <span class=\"token number\">2</span></code></pre></div>\n<p>The ones above are to edit the current value of the variable. Sorry to JS users, as there is no <code class=\"language-text\">i++;</code> or anything.</p>\n<blockquote>\n<p>Fun Fact: The python language was named after Monty Python.</p>\n</blockquote>\n<p>If you really want to know about the others, view [Py Operators](https://www.tutorialspoint.com/python/python<em>basic</em>operators.htm)​</p>\n<p>Like the title? Anyways, a <code class=\"language-text\">'</code> and a <code class=\"language-text\">\"</code> both indicate a string, but <strong>do not combine them!</strong></p>\n<p><em>quotes.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token string\">'hello'</span> <span class=\"token comment\"># Goodx = \"hello\" # Goodx = \"hello' # ERRORRR!!!</span></code></pre></div>\n<p><em>slicing.py</em></p>\n<h4>String Slicing <a id=\"string-slicing\"></h4>\n</a>\n<p>You can look at only certain parts of the string by slicing it, using <code class=\"language-text\">[num:num]</code>. The first number stands for how far in you go from the front, and the second stands for how far in you go from the back.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token string\">'Hello everybody!'</span>x<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token comment\"># 'e'x[-1] # '!'x[5] # ' 'x[1:] # 'ello everybody!'x[:-1] # 'Hello everybod'x[2:-3] # 'llo everyb'</span></code></pre></div>\n<h4>Methods and Functions <a id=\"methods-and-functions\"></h4>\n</a>\n<p>Here is a list of functions/methods we will go over:</p>\n<ul>\n<li><code class=\"language-text\">.strip()</code></li>\n<li><code class=\"language-text\">len()</code></li>\n<li><code class=\"language-text\">.lower()</code></li>\n<li><code class=\"language-text\">.upper()</code></li>\n<li><code class=\"language-text\">.replace()</code></li>\n<li><code class=\"language-text\">.split()</code></li>\n</ul>\n<p>I will make you try these out yourself. See if you can figure out how they work.</p>\n<p><em>strings.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token string\">\" Testing, testing, testing, testing       \"</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>replace<span class=\"token punctuation\">(</span><span class=\"token string\">'test'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'runn'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Good luck, see you when you come back!</p>\n<p>Input is a function that gathers input entered from the user in the command line. It takes one optional parameter, which is the users prompt.</p>\n<p><em>inp.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Type something: '</span><span class=\"token punctuation\">)</span>x <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Here is what you said: '</span><span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">)</span></code></pre></div>\n<p>If you wanted to make it smaller, and look neater to the user, you could do…</p>\n<p><em>inp2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Here is what you said: '</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Type something: '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Running: <em>inp.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Type something<span class=\"token punctuation\">:</span>Hello WorldHere <span class=\"token keyword\">is</span> what you said<span class=\"token punctuation\">:</span> Hello World</code></pre></div>\n<p><em>inp2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Type something<span class=\"token punctuation\">:</span> Hello WorldHere <span class=\"token keyword\">is</span> what you said<span class=\"token punctuation\">:</span> Hello World</code></pre></div>\n<p>Python has created a lot of functions that are located in other .py files. You need to import these <strong>modules</strong> to gain access to the,, You may wonder why python did this. The purpose of separate modules is to make python faster. Instead of storing millions and millions of functions, , it only needs a few basic ones. To import a module, you must write <code class=\"language-text\">input &lt;modulename></code>. Do not add the .py extension to the file name. In this example , we will be using a python created module named random.</p>\n<p><em>module.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random</code></pre></div>\n<p>Now, I have access to all functions in the random.py file. To access a specific function in the module, you would do <code class=\"language-text\">&lt;module>.&lt;function></code>. For example:</p>\n<p><em>module2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> randomprint<span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># Prints a random number between 3 and 5</span></code></pre></div>\n<blockquote>\n<p>Pro Tip: Do <code class=\"language-text\">from random import randint</code> to not have to do <code class=\"language-text\">random.randint()</code>, just <code class=\"language-text\">randint()</code> To import all functions from a module, you could do <code class=\"language-text\">from random import *</code></p>\n</blockquote>\n<p>Loops allow you to repeat code over and over again. This is useful if you want to print Hi with a delay of one second 100 times.</p>\n<p><strong>for Loop</strong></p>\n<p>The for loop goes through a list of variables, making a seperate variable equal one of the list every time. Let's say we wanted to create the example above.</p>\n<p><em>loop.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> time <span class=\"token keyword\">import</span> sleepfor i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span>     sleep<span class=\"token punctuation\">(</span><span class=\"token number\">.3</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This will print Hello with a .3 second delay 100 times. This is just one way to use it, but it is usually used like this:</p>\n<p><em>loop2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> timefor number <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span>     time<span class=\"token punctuation\">.</span>sleep<span class=\"token punctuation\">(</span><span class=\"token number\">.1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>while Loop</strong></p>\n<p>The while loop runs the code while something stays true. You would put <code class=\"language-text\">while &lt;expression></code>. Every time the loop runs, it evaluates if the expression is True. It it is, it runs the code, if not it continues outside of the loop. For example:</p>\n<p><em>while.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span> <span class=\"token comment\"># Runs forever     print('Hello World!')</span></code></pre></div>\n<p>Or you could do:</p>\n<p><em>while2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> randomposition <span class=\"token operator\">=</span> <span class=\"token string\">'&lt;placeholder>'</span><span class=\"token keyword\">while</span> position <span class=\"token operator\">!=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span> <span class=\"token comment\"># will run at least once    position = random.randint(1, 10)    print(position)</span></code></pre></div>\n<p>The if statement allows you to check if something is True. If so, it runs the code, if not, it continues on. It is kind of like a while loop, but it executes <strong>only once</strong>. An if statement is written:</p>\n<p><em>if.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> randomnum <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num is 3. Hooray!!!'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">if</span> num <span class=\"token operator\">></span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is greater than 5'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is 12, which means that there is a problem with the python language, see if you can figure it out. Extra credit if you can figure it out!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Now, you may think that it would be better if you could make it print only one message. Not as many that are True. You can do that with an <code class=\"language-text\">elif</code> statement:</p>\n<p><em>elif.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> randomnum <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is three, this is the only msg you will see.'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">elif</span> num <span class=\"token operator\">></span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is not three, but is greater than 1'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Now, you may wonder how to run code if none work. Well, there is a simple statement called <code class=\"language-text\">else:</code></p>\n<p><em>else.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> randomnum <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is three, this is the only msg you will see.'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">elif</span> num <span class=\"token operator\">></span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is not three, but is greater than 1'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'No category'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>So far, you have only seen how to use functions other people have made. Let use the example that you want to print the a random number between 1 and 9, and print different text every time. It is quite tiring to type:</p>\n<p>Characters: 389</p>\n<p><em>nofunc.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> randomprint<span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Wow that was interesting.'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Look at the number above ^'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'All of these have been interesting numbers.'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"these random.randint's are getting annoying to type\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi'</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'j'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Now with functions, you can seriously lower the amount of characters:</p>\n<p>Characters: 254</p>\n<p><em>functions.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> randomdef r<span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span>r<span class=\"token punctuation\">(</span><span class=\"token string\">'Wow that was interesting.'</span><span class=\"token punctuation\">)</span>r<span class=\"token punctuation\">(</span><span class=\"token string\">'Look at the number above ^'</span><span class=\"token punctuation\">)</span>r<span class=\"token punctuation\">(</span><span class=\"token string\">'All of these have been interesting numbers.'</span><span class=\"token punctuation\">)</span>r<span class=\"token punctuation\">(</span><span class=\"token string\">\"these random.randint's are getting annoying to type\"</span><span class=\"token punctuation\">)</span>r<span class=\"token punctuation\">(</span><span class=\"token string\">'Hi'</span><span class=\"token punctuation\">)</span>r<span class=\"token punctuation\">(</span><span class=\"token string\">'j'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Chapter 01 - Getting Ready with Python <a id=\"chapter-01-getting-ready-with-python\"></h3>\n</a>\n<h4>Installing Python 3, And Launching Python Shell <a id=\"installing-python-3-and-launching-python-shell\"></h4>\n</a>\n<p>This video should help you get up and running with Python 3</p>\n<ul>\n<li>​[Installing Python 3 and Launch Python Shell](https://www.youtube.com/watch?v=Ji1WW4Suaww)​</li>\n</ul>\n<p>Installing Python is really a cakewalk. Search for \"Python download\" on [www.google.com](http://www.google.com/). Download the installable and install it.</p>\n<p>A quick word of caution on Windows</p>\n<ul>\n<li>Make sure that you have the check-box \"Add Python 3.6 to PATH\", checked.</li>\n</ul>\n<p>Once you have installed Python, you can launch the Python Shell.</p>\n<ul>\n<li>Windows - Launch cmd prompt by typing in 'cmd' command.</li>\n<li>Mac or Linux - Launch up terminal.</li>\n</ul>\n<p>Command to launch Python 3 is different in Mac.</p>\n<ul>\n<li>In Mac, type in <code class=\"language-text\">python3</code></li>\n<li>In other operating systems, including windows, type <code class=\"language-text\">python</code></li>\n</ul>\n<p>You can type code in python shell and code as well!</p>\n<p>You can use <code class=\"language-text\">print(5*4)</code>, and it shows <code class=\"language-text\">20</code>.</p>\n<p>You can execute the code, and the shell would immediately give you output.</p>\n<p>Using the the Python Shell is an awesome way to learn Python.</p>\n<h3>Chapter 02 - Introduction To Python Programming <a id=\"chapter-02-introduction-to-python-programming\"></h3>\n</a>\n<p>Most programmers find programming a lot of fun, and besides, it also gets their work done.</p>\n<p>Programming mainly involves <em>problem solving</em>, where one makes use of a computer to solve a real world problem.</p>\n<p>During our journey here, we will approach programming in a very different way. We will not only introduce you to the Python language, but also help you pick up essential problem solving skills.</p>\n<p>As a programmer, you need to be able to look at a problem, and identify the important programming concepts relevant to solving it. Finally, you need to be able to use the language features and syntax, to express your solution on the computer. While all this looks complex, we want to make it easy for you. Together, we will tackle a variety of programming challenges, using these same steps. We will start with simple challenges (such as a Multiplication Table), and gradually increase the difficulty level over the duration of this book.</p>\n<p>Learning to program is a lot like learning to ride a bicycle. The first few steps are the most challenging ones.</p>\n<p>Once you get over these initial steps, your experience will become more and more enjoyable.</p>\n<p>Are you ready for your first programming challenge? Let's get going now! We wish you all the best.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to the concept of problem solving</li>\n<li>Understood how good programmers approach problem solving</li>\n</ul>\n<h4>Step 01: Our First Programming Challenge <a id=\"step-01-our-first-programming-challenge\"></h4>\n</a>\n<p>Our first <em>programming challenge</em> aims to do, what every kid does in math class: read out a multiplication table. We now want to give this task to the computer. Here is the statement of our problem:</p>\n<p><strong>The Print Multiplication Table Challenge (PMT-Challenge)</strong></p>\n<ol>\n<li>Compute the multiplication table for <code class=\"language-text\">5</code>, with entries from <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code>.</li>\n<li>Display this table.</li>\n</ol>\n<p>The display needs to be:</p>\n<p><em><strong>5 * 1 = 5</strong></em></p>\n<p><em><strong>5 * 2 = 10</strong></em></p>\n<p><em><strong>5 * 3 = 15</strong></em></p>\n<p><em><strong>5 * 4 = 20</strong></em></p>\n<p><em><strong>5 * 5 = 25</strong></em></p>\n<p><em><strong>5 * 6 = 30</strong></em></p>\n<p><em><strong>5 * 7 = 35</strong></em></p>\n<p><em><strong>5 * 8 = 40</strong></em></p>\n<p><em><strong>5 * 9 = 45</strong></em></p>\n<p><em><strong>5 * 10 = 50</strong></em></p>\n<p>This is the challenge. For convenience, let's give it a label, say <em>PMT-Challenge</em>. What would be the important concepts we need to learn, to solve this challenge? The following list of concepts would be a good starting point:</p>\n<ul>\n<li><strong>Statements</strong></li>\n<li><strong>Expressions</strong></li>\n<li><strong>Variables</strong></li>\n<li><strong>Literals</strong></li>\n<li><strong>Conditionals</strong></li>\n<li><strong>Loops</strong></li>\n<li><strong>Methods</strong></li>\n</ul>\n<p>In the rest of this chapter, we will introduce these concepts to you, one-by-one. We will also show you how learning each concept, takes us closer to a solution to <em>PMT-Challenge</em>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Stated our first programming challenge</li>\n<li>Identified what programming concepts we need to learn, to solve this challenge</li>\n</ul>\n<h4>Step 02: Breaking Down <em>PMT-Challenge</em> <a id=\"step-02-breaking-down-pmt-challenge\"></h4>\n</a>\n<p>Typically when we do programming, we have problems. Solving the problem typically need a step-by -step approach. Common sense tells us that to solve a complex problem, we break it into smaller parts, and solve each part one by one. Here is how any good programmer worth her salt, would solve a problem:</p>\n<ul>\n<li>Simplify the problem, by breaking it into sub-problems</li>\n<li>Solve the sub-problems in stages (in some order), using the language</li>\n<li>Combine these solutions to get a final solution</li>\n</ul>\n<p>The <em>PMT-Challenge</em> is no different! Now how do we break it down, and where do we really start? Once again, your common sense will reveal a solution. As a first step, we could get the computer to calculate say, <code class=\"language-text\">5 * 3</code>. The second thing we can do, is to try and print the calculated value, in a manner similar to <code class=\"language-text\">5 * 3 = 15</code>. Then, we could repeat what we just did, to print out all the entries of the <code class=\"language-text\">5</code> multiplication table. Let's put it down a little more formally:</p>\n<p>Here is how our draft steps look like</p>\n<ul>\n<li>Calculate <code class=\"language-text\">5 * 3</code> and print result as <code class=\"language-text\">15</code></li>\n<li>Print <code class=\"language-text\">5 * 3 = 15</code> (<code class=\"language-text\">15</code> is result of previous calculation)</li>\n<li>Do this ten times, once for each table entry (going from <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code>)</li>\n</ul>\n<p>Let's start with that kind of a game plan, and see where it takes us.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned that breaking down a problem into sub-problems is a great help</li>\n<li>Found a way to break down the <em>PMT-Challenge</em> problem</li>\n</ul>\n<h4>Step 03: Introducing Operators And Expressions <a id=\"step-03-introducing-operators-and-expressions\"></h4>\n</a>\n<p>Let's focus on solving the first sub-problem of <em>PMT-Challenge</em>, the numeric computation. We want the computer to calculate <code class=\"language-text\">5 * 5</code> for example, and print <code class=\"language-text\">25</code> for us. How do we get it to do that? That's what we would be looking at in this step.</p>\n<p><strong>Snippet-01: Introducing Operators</strong></p>\n<p>Launch up Python shell. We want to calculate <code class=\"language-text\">5 * 5</code>. How do we do that?</p>\n<p>Using our knowledge of school math, let's try <code class=\"language-text\">5 X 5</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> X <span class=\"token number\">5</span>    File <span class=\"token string\">\"&lt; stdin >\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>    <span class=\"token number\">5</span> X <span class=\"token number\">5</span>      <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p>The Python Shell hits back at us, saying \"<em>invalid syntax</em>\". This is how Python complains, when it doesn't fully understand the code you type in. Here, it says our code has a \"<strong>SyntaxError</strong>\".</p>\n<p>The reason why it complains, is because '<code class=\"language-text\">X</code>' is not a valid <strong>operator</strong> in Python.</p>\n<p>The way you can do multiplication is by using the '<code class=\"language-text\">*</code>' <em>operator</em> .</p>\n<p>\"<em>5 into 5</em>\" is achieved by the code <code class=\"language-text\">5 * 5</code>, and you can see the result <code class=\"language-text\">25</code> being printed. Similarly, <code class=\"language-text\">5 * 6</code> gives us <code class=\"language-text\">30</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span>    <span class=\"token number\">30</span></code></pre></div>\n<p>There are a wide range of other operators in Python:</p>\n<ul>\n<li><code class=\"language-text\">5 + 6</code> gives a result of <code class=\"language-text\">11</code>.</li>\n<li>\n<p><code class=\"language-text\">5 - 6</code> leads to <code class=\"language-text\">-1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">611</span><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token number\">6</span><span class=\"token operator\">-</span><span class=\"token number\">1</span></code></pre></div>\n</li>\n</ul>\n<p><code class=\"language-text\">10 / 2</code>, gives an output of <code class=\"language-text\">5.0</code> . There is one interesting operator, <code class=\"language-text\">**</code>. Let's try <code class=\"language-text\">10 ** 3</code>. We ran this code, and the result we get is <code class=\"language-text\">1000</code>. Yes you guessed right, the operator performs \"to the power of\". \"<code class=\"language-text\">10</code> to the power of <code class=\"language-text\">3</code>\" is <code class=\"language-text\">10 * 10 * 10</code>, or <code class=\"language-text\">1000</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">10</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span>    <span class=\"token number\">5.0</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">10</span> <span class=\"token operator\">**</span> <span class=\"token number\">3</span>    <span class=\"token number\">1000</span></code></pre></div>\n<p>Another interesting operator is <code class=\"language-text\">%</code>, called \"<em>modulo</em>\", which computes the remainder on integer division. If we do <code class=\"language-text\">10 % 3</code>, what is the remainder when <code class=\"language-text\">10</code> is divided by <code class=\"language-text\">3</code>? <code class=\"language-text\">3 * 3</code> is <code class=\"language-text\">9</code>, and <code class=\"language-text\">10 - 9</code> is <code class=\"language-text\">1</code>, which is what <code class=\"language-text\">%</code> returns in this case.</p>\n<p>Let's look at some terminology:</p>\n<ul>\n<li>Whatever pieces of code we gave Python shell to run, are called <strong>expressions</strong>. So, <code class=\"language-text\">5 * 5</code>, <code class=\"language-text\">5 * 6</code> and <code class=\"language-text\">5 - 6</code> are all <em>expressions</em>. An expression is composed of <em>operators</em> and <strong>operands</strong>.</li>\n<li>In the expression <code class=\"language-text\">5 * 6</code>, the two values <code class=\"language-text\">5</code> and <code class=\"language-text\">6</code> are called operands, and the <code class=\"language-text\">*</code> operator <em>operates</em> on them.</li>\n<li>The values <code class=\"language-text\">5</code> and <code class=\"language-text\">6</code> are <strong>literals</strong>, because those are constants which cannot be changed.</li>\n</ul>\n<p>The cool thing about Python, is that you can even have expressions with multiple operators. Therefore, you can form an expression with <code class=\"language-text\">5 + 5 + 5</code>, which evaluates to <code class=\"language-text\">15</code>. This is an expression which has three operands, and two <code class=\"language-text\">+</code> operators. You can even have expressions with different types of operators, such as in <code class=\"language-text\">5 + 5 * 5</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span>    <span class=\"token number\">15</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span>    <span class=\"token number\">30</span></code></pre></div>\n<p>Try and play around with the expressions, and understand the output which results.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned how to give code input to the Python Shell</li>\n<li>Understood that Python has a predefined set of operators</li>\n<li>Used a few types of basic operators and their operands, to form expressions</li>\n</ul>\n<h4>Step 04: Programming Exercise IN-PE-01 <a id=\"step-04-programming-exercise-in-pe-01\"></h4>\n</a>\n<p>At this stage, your smile tells us that you enjoy evaluating Python expressions. What if we tickle your mind a bit, to make sure it hasn't fallen asleep? Here is your first programming exercise.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Write an expression to calculate the number of minutes in a day.</li>\n<li>Write an expression to calculate the number of seconds in a day.</li>\n</ol>\n<p><strong>Note</strong></p>\n<p>You need to solve these problems by yourself. If you are able to work them out, that's fantastic! But if not, that's part of the learning process.</p>\n<p><strong>Solutions</strong></p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">24</span> <span class=\"token operator\">*</span> <span class=\"token number\">60</span>​    <span class=\"token number\">1440</span></code></pre></div>\n<p>We wanted to calculate the number of minutes in a day. How do we do that? Think about this…</p>\n<ul>\n<li>How many number of hours are there in a day? <code class=\"language-text\">24</code>.</li>\n<li>And how many minutes does each hour have? It's <code class=\"language-text\">60</code>.</li>\n<li>So if you want to find out the number of minutes in a day, it's <code class=\"language-text\">24 * 60</code>, which is <code class=\"language-text\">1440</code>.</li>\n</ul>\n<p><strong>Solution 2</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">24</span> <span class=\"token operator\">*</span> <span class=\"token number\">60</span> <span class=\"token operator\">*</span> <span class=\"token number\">60</span>​    <span class=\"token number\">86400</span></code></pre></div>\n<p>How many seconds are there in a day?</p>\n<ul>\n<li>Let's start with the number of hours, <code class=\"language-text\">24</code>.</li>\n<li>The number of minutes in an hour is <code class=\"language-text\">60</code>, and</li>\n<li>The number of seconds in a minute is <code class=\"language-text\">60</code> as well.</li>\n<li>So it's <code class=\"language-text\">24 * 60 * 60</code>, or <code class=\"language-text\">86400</code>.</li>\n</ul>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Solved a Programming Exercise involving common scenarios, using Python code involving:</p>\n<ul>\n<li>Expressions</li>\n<li>Operators</li>\n<li>Literals</li>\n</ul>\n</li>\n</ul>\n<h4>Step 05: Puzzles On Expressions <a id=\"step-05-puzzles-on-expressions\"></h4>\n</a>\n<p>Let's look at a few puzzles related to expressions, in this step. Before that, let's revise some of the terminology we had learned earlier.</p>\n<p><code class=\"language-text\">5 + 6 + 10</code> is an example of an expression. In this expression, <code class=\"language-text\">5</code>, <code class=\"language-text\">6</code> and <code class=\"language-text\">10</code> are operands. The <code class=\"language-text\">+</code> here is the operator. You can have multiple operators in an expression. We also did mention that the operands, namely <code class=\"language-text\">10</code>, <code class=\"language-text\">6</code> and <code class=\"language-text\">5</code>, are literals. Their values will not change.</p>\n<p>Here are a few puzzles coming up, to explore aspects of expressions.</p>\n<p><strong>Snippet-01: Puzzles On Expressions</strong></p>\n<p>Think about what would happen when you do something of this kind: <code class=\"language-text\">5 $ 2</code>. You're right, it would throw a <code class=\"language-text\">SyntaxError</code>. When Python does not understand the code you type in, it reports an error. Here, the expression we're typing is <code class=\"language-text\">5 $ 2</code>, which does not make sense to Python, hence the <code class=\"language-text\">SyntaxError</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> $ <span class=\"token number\">2</span>    File <span class=\"token string\">\"&lt; stdin >\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>    <span class=\"token number\">5</span> $ <span class=\"token number\">2</span>    <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span>$<span class=\"token number\">2</span>    File <span class=\"token string\">\"&lt; stdin >\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>    <span class=\"token number\">5</span> $ <span class=\"token number\">2</span>    <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p>Let's say we type in <code class=\"language-text\">5+6+10</code>, without any spaces between the operands, and the operators. What do you think will happen? Surprisingly, the Python Shell does calculate the value!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span><span class=\"token operator\">+</span><span class=\"token number\">6</span><span class=\"token operator\">+</span><span class=\"token number\">10</span>    <span class=\"token number\">21</span></code></pre></div>\n<p>In an expression, using spaces makes it easier for you to read it, but it's not mandatory. <code class=\"language-text\">5 + 6 + 10</code> is easier to read than <code class=\"language-text\">5+6+10</code>, but does not make any difference to the Python compiler.</p>\n<p>The next puzzle tries to evaluate <code class=\"language-text\">5 / 2</code>, which is \"<code class=\"language-text\">5</code> divided by <code class=\"language-text\">2</code>\". What would be the output? <code class=\"language-text\">2.5</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span><span class=\"token operator\">/</span><span class=\"token number\">2</span>    <span class=\"token number\">2.5</span></code></pre></div>\n<p>If you're coming from other programming languages like Java or C, this might be a surprising result. If you try this in Java for instance, you would get <code class=\"language-text\">2</code> as the output. Note that even though both operands are integers, the result of the <code class=\"language-text\">/</code> operation is a floating point value, <code class=\"language-text\">2.5</code> . Python does what is expected by a programmer!</p>\n<p>The puzzle after that tries to play with <code class=\"language-text\">5 + 5 * 6</code>. What would be the result of this expression? Will it be <code class=\"language-text\">5 + 5</code> or <code class=\"language-text\">10</code>, then <code class=\"language-text\">10 * 6</code>, which is <code class=\"language-text\">60</code>? Or, will it be <code class=\"language-text\">5</code> plus <code class=\"language-text\">5 * 6</code>, which is <code class=\"language-text\">5</code> + <code class=\"language-text\">30</code>, that's <code class=\"language-text\">35</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span>    <span class=\"token number\">35</span></code></pre></div>\n<p>The correct result is <code class=\"language-text\">35</code>.</p>\n<p>Python decides this is based on the <strong>precedence</strong> of operators.</p>\n<p>Operators in Python are divided into two sets as follows:</p>\n<ul>\n<li><code class=\"language-text\">**</code>, <code class=\"language-text\">*</code>, <code class=\"language-text\">/</code> and <code class=\"language-text\">%</code> have higher precedence, or priority.</li>\n<li><code class=\"language-text\">+</code> and <code class=\"language-text\">-</code> have a lower precedence.</li>\n</ul>\n<p>Sub-expressions involving operators from {<code class=\"language-text\">*</code>, <code class=\"language-text\">/</code>, <code class=\"language-text\">%</code>, <code class=\"language-text\">**</code>} are evaluated before those involving operators from {<code class=\"language-text\">+</code>, <code class=\"language-text\">-</code>}</p>\n<p>Let's try another small puzzle on precedence, with <code class=\"language-text\">5 - 2 * 2</code>. What would be the result of this? Will it be <code class=\"language-text\">6</code>, or <code class=\"language-text\">1</code>? It's <code class=\"language-text\">1</code>, because <code class=\"language-text\">*</code> has a higher precedence than <code class=\"language-text\">-</code>. Thus <code class=\"language-text\">2 * 2</code> is <code class=\"language-text\">4</code>, and <code class=\"language-text\">5 - 4</code> gives us <code class=\"language-text\">1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span>    <span class=\"token number\">1</span></code></pre></div>\n<p>Let's say we want to execute <code class=\"language-text\">5 - 2</code>, to give an output of <code class=\"language-text\">2</code>. How do we change the operator precedence?</p>\n<p>You cannot really change the precedence, but you can add parentheses to group sub-expressions differently.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span>    <span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token punctuation\">(</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span></code></pre></div>\n<p>Parentheses have the highest precedence in Python, and can be used to override operator precedence. <code class=\"language-text\">(5 - 2)</code> gets calculated first, and the final result of the expression is <code class=\"language-text\">6</code>.</p>\n<p>A positive thing about using parentheses is, that it makes expressions more readable. So even in situations such as <code class=\"language-text\">5 - 2 * 2</code>, where we know the result according to precedence, adding parentheses is good.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we went about solving a few puzzles about expressions, touching concepts such as:</p>\n<ul>\n<li><code class=\"language-text\">SyntaxError</code> for incorrect operators</li>\n<li>White-space in expressions</li>\n<li>Floating Point division by default</li>\n<li>Operator Precedence</li>\n<li>Using parentheses</li>\n</ul>\n<h4>Step 06: Printing Text <a id=\"step-06-printing-text\"></h4>\n</a>\n<p>In the previous step, we learned how to use expressions to compute values. In this step, let's see how we can actually print multiplication table entries, that are readable by the user.</p>\n<p><strong>Snippet-01: Printing Text</strong></p>\n<p>How do we go about printing a complete multiplication table entry? We want to print text such as <code class=\"language-text\">5 * 6 = 30</code> . But trying to do so, as we know it, gives us a <code class=\"language-text\">SyntaxError</code>. Clearly, there is a different way to print text, as compared to an expression.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>    SyntaxError<span class=\"token punctuation\">:</span> can't assign to operator</code></pre></div>\n<p>Let's first try to print a simple piece of text, <code class=\"language-text\">Hello</code>. Typing in this piece of code directly on Python Shell also gives us an error.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> Hello    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'Hello'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>Only expressions work that way, and <code class=\"language-text\">Hello</code> is not really an expression.</p>\n<p><code class=\"language-text\">\"Hello\"</code> is typically called a <strong>string</strong>, and represents the text of letters <code class=\"language-text\">'H'</code>, <code class=\"language-text\">'e'</code>, <code class=\"language-text\">'l'</code>, <code class=\"language-text\">'l'</code>, <code class=\"language-text\">'o'</code>. <code class=\"language-text\">\"Hello\"</code> is hence different from the number <code class=\"language-text\">5</code>.</p>\n<p>There are a number of in-built functions in Python to help print strings. One of these is the <code class=\"language-text\">print()</code> function. Can you just say <code class=\"language-text\">print Hello</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> Hello      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token keyword\">print</span> Hello                  <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> Missing parentheses <span class=\"token keyword\">in</span> call to <span class=\"token string\">'print'</span><span class=\"token punctuation\">.</span> Did you mean <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Hello<span class=\"token punctuation\">)</span>?</code></pre></div>\n<p>The Python compiler gives you an error, that says \"missing parentheses\".</p>\n<p>Will <code class=\"language-text\">print(Hello)</code> work?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span>Hello<span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'Hello'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>Nope! Again, this one failed because you need to indicate that <code class=\"language-text\">\"Hello\"</code> is a string.</p>\n<p>How do I indicate that <code class=\"language-text\">\"Hello\"</code> is a string? By putting it within double quotes.</p>\n<p>Let's try <code class=\"language-text\">print (\"Hello\")</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span>    Hello    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span>    Hello</code></pre></div>\n<p><code class=\"language-text\">print(\"Hello\")</code> finally results in <code class=\"language-text\">\"Hello\"</code> being printed out. To be able to print <code class=\"language-text\">\"Hello\"</code>, the things we need to do are:</p>\n<ul>\n<li>Typing the method name print ,</li>\n<li>open parentheses ( ,</li>\n<li>Followed by a double quote \" ,</li>\n<li>The text Hello,</li>\n<li>and another double quote \" ,</li>\n<li>finished off with a closed parentheses ).</li>\n</ul>\n<p>What we have written here is called a <strong>statement</strong>, a simple piece of code to execute. As part of this statement, we are <strong>calling</strong> a <strong>function</strong>, named <code class=\"language-text\">print()</code>.</p>\n<p>What exactly are we trying to print?</p>\n<p>The text <code class=\"language-text\">\"Hello\"</code>, which is called a <strong>parameter</strong> or <strong>argument</strong>, to <code class=\"language-text\">print()</code>.</p>\n<p>Now let's get back to what we wanted to do, which is to print <code class=\"language-text\">5 * 6 = 30</code>. The most basic version would be something of this kind, <code class=\"language-text\">print(\"5 * 6 = 30\")</code>. Here, we are passing the entire value in the form of a string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 * 6 = 30\"</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span></code></pre></div>\n<p>This prints the text on the console, as-is. The thing you need to understand here is, we aren't really calculating <code class=\"language-text\">30</code> using the formula <code class=\"language-text\">5 * 6</code>, but directly putting text <code class=\"language-text\">30</code> in here. That's called <strong>hard-coding</strong>.</p>\n<p>In a later step, we will look at how to actually calculate the value and pass it in.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Understood that displaying text on the console is not the same as printing an expression value</li>\n<li>Learned about the <code class=\"language-text\">print()</code> function, that is used to print text in Python.</li>\n<li>Found a way to print the text <code class=\"language-text\">\"5 * 6 = 30\"</code> on the console, by hard-coding values in a string</li>\n</ul>\n<h4>Step 07: Puzzles On Utility Methods, And Strings <a id=\"step-07-puzzles-on-utility-methods-and-strings\"></h4>\n</a>\n<p>In the previous step, we learned how to print <code class=\"language-text\">5 * 6 = 30</code>. It was not a perfect solution, because we hard-coded everything. we used an in-built function named <code class=\"language-text\">print()</code>, passed a string to it, and invoked the method.</p>\n<p>In this step, let's look at a number of puzzles related to in-built methods, their parameters, and strings in general.</p>\n<p>For example, let's do <code class=\"language-text\">print(\"5 * 6\")</code>, as in the previous step. What does this code result in?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5*6\"</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'5*6'</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span></code></pre></div>\n<p>It just prints the string <code class=\"language-text\">\"5 * 6\"</code>.</p>\n<p>Let's say we try the code <code class=\"language-text\">print(5 * 6)</code>,</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">30</span></code></pre></div>\n<p>Without the double quotes, <code class=\"language-text\">5 * 6</code> is an expression. What will be the output? <code class=\"language-text\">30</code>.</p>\n<p>If you call <code class=\"language-text\">print()</code> with an expression argument, it prints the value of the expression. However, when we pass something within double quotes, it becomes a piece of text, printed as-is.</p>\n<p>An interesting thing to note is, that in Python you can use either double-quotes (<code class=\"language-text\">\"</code> and <code class=\"language-text\">\"</code>), or single-quotes (<code class=\"language-text\">'</code> and <code class=\"language-text\">'</code>) with text values.</p>\n<p>Let's look at a few other in-built methods within Python.</p>\n<p>Consider <code class=\"language-text\">abs()</code> (which stands for absolute value), a method that accepts a numeric value. You can use <code class=\"language-text\">abs(10.5)</code>, passing <code class=\"language-text\">10.5</code> as a value to it, and it prints the absolute value of <code class=\"language-text\">10</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">abs</span> <span class=\"token number\">10.5</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token builtin\">abs</span> <span class=\"token number\">10.5</span>               <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span><span class=\"token number\">10.5</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">10.5</span></code></pre></div>\n<p>If you pass in a string value, will it work? It complains, \"<code class=\"language-text\">abs()</code> function will not work with a string, it only works with numeric values\".</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"10.5\"</span><span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    TypeError<span class=\"token punctuation\">:</span> bad operand <span class=\"token builtin\">type</span> <span class=\"token keyword\">for</span> <span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'str'</span></code></pre></div>\n<p>Let's say you want to use a function that computes \"to the power of\", for instance \"<code class=\"language-text\">2</code> to the power of <code class=\"language-text\">5</code>\". In Python, there's an in-built function named <code class=\"language-text\">pow()</code>, which does just what we need. To <code class=\"language-text\">pow()</code>, you can pass two parameters and calculate the result. How do you do that?</p>\n<p>Will this work: <code class=\"language-text\">pow 2 5</code>? No, not at all. This code does not work as well: <code class=\"language-text\">pow(2 5)</code>. <code class=\"language-text\">pow(2, 5)</code> is the correct syntax.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span> <span class=\"token number\">2</span> <span class=\"token number\">5</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token builtin\">pow</span> <span class=\"token number\">2</span> <span class=\"token number\">5</span>            <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>              <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">32</span></code></pre></div>\n<p>You'll see that <code class=\"language-text\">32</code> is printed.</p>\n<p>Let's see another example, \"<code class=\"language-text\">10</code> to the power of <code class=\"language-text\">3</code>\". <code class=\"language-text\">pow(10,3)</code> is the alternative to saying <code class=\"language-text\">10 ** 3</code>. This gives us <code class=\"language-text\">1000</code>, similar to how <code class=\"language-text\">pow()</code> would.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1000</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">10</span> <span class=\"token operator\">**</span> <span class=\"token number\">3</span>    <span class=\"token number\">1000</span></code></pre></div>\n<p><code class=\"language-text\">max()</code> returns maximum in a set of numbers.<code class=\"language-text\">min()</code> function returns the minimum value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">34</span><span class=\"token punctuation\">,</span> <span class=\"token number\">45</span><span class=\"token punctuation\">,</span> <span class=\"token number\">67</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">67</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">34</span><span class=\"token punctuation\">,</span> <span class=\"token number\">45</span><span class=\"token punctuation\">,</span> <span class=\"token number\">67</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">34</span></code></pre></div>\n<p>These are some of the in-built functions in Python, and we saw how to call the in-built functions by passing in a varied number of parameters.</p>\n<p>Python is case sensitive. So let's say I want of calculate <code class=\"language-text\">pow(2,5)</code>. So this would give me <code class=\"language-text\">32</code>. Now, what if I say capital <code class=\"language-text\">'P'</code> instead of small <code class=\"language-text\">'p'</code> here? <code class=\"language-text\">Pow(2,5)</code> would lead to an error.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">32</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> Pow<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'Pow'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>The only things not case-sensitive in Python, are string values. Earlier we saw that the code <code class=\"language-text\">print(\"Hello\")</code> displays the text <code class=\"language-text\">\"Hello\"</code>. Inside a string, the text can be in any case. Hence, <code class=\"language-text\">print(\"hello\")</code> displays <code class=\"language-text\">\"hello\"</code> ,with a small <code class=\"language-text\">'h'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span>    Hello    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hello\"</span><span class=\"token punctuation\">)</span>    hello    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hellO\"</span><span class=\"token punctuation\">)</span>    hellO    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span> <span class=\"token string\">\"hellO\"</span> <span class=\"token punctuation\">)</span>    hellO</code></pre></div>\n<p>However inside your code, you need to be very particular about the case of function names, class names, variable names, and the like.</p>\n<p>In your code, whitespace does not really matter. You can add space here and here, and you would still get the same output. However, in case of strings, whitespace does matter.</p>\n<p>If we say <code class=\"language-text\">print(\"hellO World\")</code>, it would print <code class=\"language-text\">\"hellO World\"</code>, with a space in between. And if you do <code class=\"language-text\">print(\"hellO World\")</code> with three spaces, it would print the same. In expressions, white-space does not affect the output.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span> <span class=\"token string\">\"hellO World\"</span> <span class=\"token punctuation\">)</span>    hellO World    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span> <span class=\"token string\">\"hellO     World\"</span> <span class=\"token punctuation\">)</span>    hellO     World</code></pre></div>\n<p>The last thing we want to look at, is an <strong>escape sequence</strong>. Let's say you want to print a double quote, <code class=\"language-text\">\"</code>, in the code. If we were to do this: <code class=\"language-text\">print(\"Hello\"\")</code>, what would happen? The compiler says error!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token string\">\")      File \"</span><span class=\"token operator\">&lt;</span>stdin<span class=\"token operator\">></span><span class=\"token string\">\", line 1        print(\"</span>Hello<span class=\"token string\">\"\"</span><span class=\"token punctuation\">)</span>                      <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> EOL <span class=\"token keyword\">while</span> scanning string literal</code></pre></div>\n<p>If you want to print a <code class=\"language-text\">\"</code> inside a string, use an escape sequence. In Python, the symbol <code class=\"language-text\">'\\'</code> is used as an <strong>escape character</strong>. On using <code class=\"language-text\">'\\'</code> adjacent to the <code class=\"language-text\">\"</code>, it prints <code class=\"language-text\">Hello\"</code> (notice the trailing <code class=\"language-text\">\"</code>). We have used the <code class=\"language-text\">'\\'</code> to <strong>escape</strong> the <code class=\"language-text\">\"</code>, by forming an <em>escape sequence</em> <code class=\"language-text\">\\\"</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\"\"</span><span class=\"token punctuation\">)</span>Hello\"<span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>The other reason why you would want to use a <code class=\"language-text\">'\\'</code> is to print a <code class=\"language-text\">&lt;NEWLINE></code>. If you want to print <code class=\"language-text\">\"Hello World\"</code>, but with <code class=\"language-text\">\"Hello\"</code> on one line and <code class=\"language-text\">\"World\"</code> on the next, <code class=\"language-text\">'\\n'</code> is the escape sequence to use.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\nWorld\"</span><span class=\"token punctuation\">)</span>    Hello    World</code></pre></div>\n<p>The other important escape sequence is <code class=\"language-text\">'\\t'</code>, which prints a <code class=\"language-text\">&lt;TAB></code> in the output. When you do <code class=\"language-text\">print(\"Hello\\tWorld\")</code>, you can see the tab-space between <code class=\"language-text\">\"Hello\"</code> and <code class=\"language-text\">\"World\"</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\tWorld\"</span><span class=\"token punctuation\">)</span>    Hello   World</code></pre></div>\n<p>Another useful escape sequence is <code class=\"language-text\">\\\\</code> . If you want to print a <code class=\"language-text\">\\</code> , then use the sequence <code class=\"language-text\">\\\\</code> . You would see that it prints <code class=\"language-text\">Hello\\World</code> . Think about what would happen if we put six <code class=\"language-text\">\\</code> . Yes you're right! It would print this string: <code class=\"language-text\">\"\\\\\\\"</code> .</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\\World\"</span><span class=\"token punctuation\">)</span>    Hello\\World    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\\\\\\\\\\World\"</span><span class=\"token punctuation\">)</span>    Hello\\\\\\World</code></pre></div>\n<p>One of the things with Python is, it does not matter whether you use double quotes or single quotes to enclose strings. There are some interesting, and useful ways of using a combination of both, within the same string. Have a look at this call: <code class=\"language-text\">print(\"Hello'World\")</code>, and notice the output we get. In a similar way, the following code will be accepted and run by the Python system: <code class=\"language-text\">print('Hello\"World')</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello\"'</span><span class=\"token punctuation\">)</span>    Hello<span class=\"token string\">\"    >>> print(\"</span>Hello<span class=\"token string\">'World\")    Hello'</span>World    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\"World\"</span><span class=\"token punctuation\">)</span>    Hello<span class=\"token string\">\"World    >>> print(\"</span>Hello\\<span class=\"token string\">\"World\"</span><span class=\"token punctuation\">)</span>    Hello\"World</code></pre></div>\n<p>The above two examples can be used as a tip by newbie programmers when they form string literals, and want to use them in their code:</p>\n<ul>\n<li>If the string literal contains one or more single quotes, then you can use double quotes to enclose it.</li>\n<li>However if the string contains one or more double quotes, then prefer to use single quotes to enclose it.</li>\n</ul>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Explored a number of puzzles related to code involving:</p>\n<ul>\n<li>Built-in functions for numeric calculations</li>\n<li>The <code class=\"language-text\">print()</code> function to display expressions and strings</li>\n</ul>\n</li>\n<li>\n<p>Covered the following aspects of the above utilities:</p>\n<ul>\n<li>Case-sensitive aspects of names and strings</li>\n<li>The role played by whitespace</li>\n<li>The escape character, and common escape sequences</li>\n</ul>\n</li>\n</ul>\n<h4>Step 08: Formatted Output With print() <a id=\"step-08-formatted-output-with-print\"></h4>\n</a>\n<p>In the previous step, we learned how to print a hard-coded string, such as <code class=\"language-text\">\"5 * 6 = 30\"</code>.</p>\n<p>In this step, let's try to replace the hard-coded <code class=\"language-text\">30</code> with a computed value.</p>\n<p>Let's start with a simple scenario. Let's say we want to place that calculated value within a string, and display it. How do we do that?</p>\n<p><strong>Snippet-01: print() Formatted Output</strong></p>\n<p><code class=\"language-text\">format()</code> method can be used to print formatted text.</p>\n<p>Let's see an example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    VALUE</code></pre></div>\n<p>We were expecting <code class=\"language-text\">10</code> to be printed, but it's actually printing <code class=\"language-text\">VALUE</code>.</p>\n<p>How do we get <code class=\"language-text\">10</code> to be printed then?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE {0}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    VALUE <span class=\"token number\">10</span></code></pre></div>\n<p>By having an open brace <code class=\"language-text\">{</code>, closed brace <code class=\"language-text\">}</code>, and and by putting the index of the value between them. Here, the value is the first parameter, and it's index will be <code class=\"language-text\">0</code>.</p>\n<p><code class=\"language-text\">\"VALUE {0}\"</code> is what we need.</p>\n<p>Let's take another example. Suppose to the <code class=\"language-text\">format()</code> function, we pass three values: <code class=\"language-text\">10</code>, <code class=\"language-text\">20</code> and <code class=\"language-text\">30</code>.</p>\n<p>Typically when we count positions or indexes, we start from <code class=\"language-text\">0</code>.</p>\n<p>To print the first value, you need to pass in an index of <code class=\"language-text\">0</code>. To print the second value, pass an index of <code class=\"language-text\">1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE {0}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span><span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    VALUE <span class=\"token number\">10</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE {1}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span><span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    VALUE <span class=\"token number\">20</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span><span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    VALUE <span class=\"token number\">30</span></code></pre></div>\n<p>Now going back to our problem, we wanted to display <code class=\"language-text\">\"5 * 6 = 30\"</code>, but without hard-coding. Instead of <code class=\"language-text\">30</code>, we want the calculated value of <code class=\"language-text\">5 * 6</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 * 6 = 30\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span></code></pre></div>\n<p>Let replace <code class=\"language-text\">\"5 * 6 = 30\"</code> with <code class=\"language-text\">\"5 * 6 = {2}\"</code>. <code class=\"language-text\">2</code> is the index of parameter value <code class=\"language-text\">5*6</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 * 6 = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span></code></pre></div>\n<p>Cool! Progress made.</p>\n<p>Let's replace <code class=\"language-text\">5 * 6</code> with the right indices - <code class=\"language-text\">{0} * {1}</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span></code></pre></div>\n<p>The great thing about this, is now we can replace the values we passed to <code class=\"language-text\">print()</code> in the first place, without changing the indexes! So, we can display results for <code class=\"language-text\">5 * 7 = 35</code> and <code class=\"language-text\">5 * 8 = 40</code>. We are now able to print <code class=\"language-text\">5 * 6 = 30</code>, <code class=\"language-text\">5 * 7 = 35</code>, <code class=\"language-text\">5 * 8 = 40</code>, and can do similar things for other table entries as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">40</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">40</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Discovered that Python provides a way to do formatted printing of string values</li>\n<li>Looked at the <code class=\"language-text\">format()</code> function, and saw how to call it within <code class=\"language-text\">print()</code></li>\n<li>Observed how we could work only with the indexes of parameters to <code class=\"language-text\">format()</code>, and change the parameters we pass without changing the code</li>\n</ul>\n<h4>Step 09: Puzzles On format() and print() <a id=\"step-09-puzzles-on-format-and-print\"></h4>\n</a>\n<p>In this step, let's look at a few puzzles related to the format, and the print methods.</p>\n<p><strong>Snippet-01: format() And print() Puzzles</strong></p>\n<p>Let's say we pass in additional values, such as: <code class=\"language-text\">5 * 8</code>, <code class=\"language-text\">5 * 9</code> and <code class=\"language-text\">5 * 10</code>. However, within the call to <code class=\"language-text\">format()</code>, we are only referring to the values at index <code class=\"language-text\">0</code>, index <code class=\"language-text\">1</code> and index <code class=\"language-text\">2</code>. The values at indexes <code class=\"language-text\">3</code> and <code class=\"language-text\">4</code> are not used at all. What would happen when we run the code?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">40</span></code></pre></div>\n<p>Would this throw an error? No, it does not. You can see that the additional values which are passed in, are conveniently ignored.</p>\n<p>Let's say instead of passing in a value of <code class=\"language-text\">2</code>, we pass <code class=\"language-text\">4</code>. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {4}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">50</span></code></pre></div>\n<p><code class=\"language-text\">5 * 10</code> is the value at index <code class=\"language-text\">4</code></p>\n<p>Now let's take a different scenario. We remove all the parameters passed to <code class=\"language-text\">format()</code>. However, inside the call to <code class=\"language-text\">print()</code>, we continue to say <code class=\"language-text\">{0} * {1} = {4}</code>. So we are trying to print the value at index <code class=\"language-text\">4</code>, but are only passing two values to the function <code class=\"language-text\">format()</code>. What do you think will happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {4}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    IndexError<span class=\"token punctuation\">:</span> <span class=\"token builtin\">tuple</span> index out of <span class=\"token builtin\">range</span></code></pre></div>\n<p>It says <code class=\"language-text\">IndexError</code>, which means :\"you are asking me to fetch the value at index <code class=\"language-text\">4</code>, but only passing in two values. How can I do what you want?\"</p>\n<p>Let's look at a few more things related to other data types. We try to format the following inside <code class=\"language-text\">print()</code>: <code class=\"language-text\">{0} * {1} = {2}</code>, and would pass in <code class=\"language-text\">2.5</code>, <code class=\"language-text\">2</code>, and <code class=\"language-text\">2.5 * 2</code> . Here, <code class=\"language-text\">2</code> is an integer value, but <code class=\"language-text\">2.5</code> is a floating point value. You can see that it prints <code class=\"language-text\">2.5 * 2 = 5.0</code>. So this approach of formatting values with <code class=\"language-text\">print()</code>, works also with floating point data as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">2.5</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">2.5</span><span class=\"token operator\">*</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">2.5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">5.0</span></code></pre></div>\n<p>Now, are there are other types of data that <code class=\"language-text\">format()</code> works with? Yes, strings can join the party.</p>\n<p>Let's say over here, we do: <code class=\"language-text\">print(\"My name is {0}\".format(\"Ranga\"))</code>. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"My name is {0}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Ranga\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    My name <span class=\"token keyword\">is</span> Ranga</code></pre></div>\n<p>Index <code class=\"language-text\">0</code> will be replaced with the first parameter to <code class=\"language-text\">format()</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Understood the behavior when the parameters passed to <code class=\"language-text\">format()</code>:</p>\n<ul>\n<li>Exceed the indexes accessed by <code class=\"language-text\">print()</code></li>\n<li>Are less than the indexes accessed by <code class=\"language-text\">print()</code></li>\n<li>Are of type integer, floating-point or string</li>\n</ul>\n</li>\n</ul>\n<h4>Step 10: Introducing Variables <a id=\"step-10-introducing-variables\"></h4>\n</a>\n<p>We are slowly making progress toward our main goal, which is to print the <code class=\"language-text\">5</code> multiplication table.</p>\n<p>In the first statement, we are printing <code class=\"language-text\">5 * 1 = 5</code>, and then changing the literals. To make it print <code class=\"language-text\">5 * 2 = 10</code>, we are changing <code class=\"language-text\">1</code> to <code class=\"language-text\">2</code>. Next, we are changing <code class=\"language-text\">2</code> to <code class=\"language-text\">3</code>. How do we make it a little simpler, so that our effort is reduced?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span></code></pre></div>\n<p>Let's try a different approach.</p>\n<p>What would happen if you replace <code class=\"language-text\">1</code> with <code class=\"language-text\">index</code>, and <code class=\"language-text\">5 * 1</code> with <code class=\"language-text\">5 * index</code>, and try to run it?</p>\n<p>It gives an error! It says: \"index is not defined\".</p>\n<p>Let's try and fix this, and execute <code class=\"language-text\">index = 2</code>. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">2</span></code></pre></div>\n<p>Aha! This compiles.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span></code></pre></div>\n<p>And this statement is printing <code class=\"language-text\">5 * 2 = 10</code>.</p>\n<p>Let's try something else. Let's make <code class=\"language-text\">index = 3</code>. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span></code></pre></div>\n<p>The same statement on being run, prints <code class=\"language-text\">5 * 3 = 15</code>.</p>\n<p>How can you check the value that <code class=\"language-text\">index</code> has? Just type in <code class=\"language-text\">index</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index    <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span></code></pre></div>\n<p>The <code class=\"language-text\">index</code> symbol we have used here, is what is called a <strong>variable</strong>.</p>\n<p>In Python, it's also called a <strong>name</strong>.</p>\n<p>You can see that the value <code class=\"language-text\">index</code> referring to, can change over the duration of a program.</p>\n<p>Initially, <code class=\"language-text\">index</code> was referring to a value of <code class=\"language-text\">1</code>. later, <code class=\"language-text\">index</code> was referring to a value of <code class=\"language-text\">3</code>.</p>\n<p>Now, think about how you would print the entire table. All that you need to do, is start from <code class=\"language-text\">1</code>, execute the same statement with <code class=\"language-text\">print()</code> and <code class=\"language-text\">format()</code>, to get output <code class=\"language-text\">5 * 1 = 5</code>. Next, Change the value of index to <code class=\"language-text\">2</code>, and then print the same statement. Next, <code class=\"language-text\">index = 3</code>, and print the same statement again.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span></code></pre></div>\n<p>With the same statement <code class=\"language-text\">print(\"{0} * {1} = {2}\".format(5,index,5*index))</code>, we are able to print different values. The value of <code class=\"language-text\">index</code> varies, but the code remains the same!</p>\n<p>Variables make the program much more easier to read, as well as more generic.</p>\n<p><strong>Snippet-02: Classroom Exercise On Variables</strong></p>\n<p>Let's do a simple exercise with variables.</p>\n<p>We want to create three variables <code class=\"language-text\">a</code>, <code class=\"language-text\">b</code> and <code class=\"language-text\">c</code>. Let's initially give them some values, say a value of <code class=\"language-text\">5</code> to <code class=\"language-text\">a</code>, <code class=\"language-text\">6</code> to <code class=\"language-text\">b</code> and <code class=\"language-text\">7</code> to <code class=\"language-text\">c</code>.</p>\n<p>We want to get output of this kind: <code class=\"language-text\">5 + 6 + 7 = 18</code>, without using the literal values.</p>\n<p>You would want to use the values stored in the variables in <code class=\"language-text\">a</code>, <code class=\"language-text\">b</code> and <code class=\"language-text\">c</code>.</p>\n<p>If you're hard-coding, the way to do it is with <code class=\"language-text\">print(\"5 + 6 + 7 = 18\")</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">7</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 + 6 + 7 = 18\"</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span> <span class=\"token operator\">+</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">18</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 + 6 + 7 = 18\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">,</span>c<span class=\"token punctuation\">,</span>a<span class=\"token operator\">+</span>b<span class=\"token operator\">+</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span> <span class=\"token operator\">+</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">18</span></code></pre></div>\n<p>The way you can do that is with code like this: <code class=\"language-text\">print(\"{0} + {1} + {2} = {3}\".format(a,b,c,a+b+c))</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} + {1} + {2} = {3}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">,</span>c<span class=\"token punctuation\">,</span>a<span class=\"token operator\">+</span>b<span class=\"token operator\">+</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span> <span class=\"token operator\">+</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">18</span></code></pre></div>\n<p>How do you confirm we are accessing values stored in the variables?</p>\n<p>Let's change the values of <code class=\"language-text\">a</code>, <code class=\"language-text\">b</code> and <code class=\"language-text\">c</code>. Let's make <code class=\"language-text\">a = 6</code> , <code class=\"language-text\">b = 7</code> , and <code class=\"language-text\">c = 8</code> . Execute same statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">7</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">8</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} + {1} + {2} = {3}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">,</span>c<span class=\"token punctuation\">,</span>a<span class=\"token operator\">+</span>b<span class=\"token operator\">+</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">6</span> <span class=\"token operator\">+</span> <span class=\"token number\">7</span> <span class=\"token operator\">+</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">21</span></code></pre></div>\n<p>You can see the magic of variables at play here! Based on what values these variables are referring to, you can see that the output of the print statement changes.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to variables, or names, in Python</li>\n<li>Observed how we could pass in values of variables to the <code class=\"language-text\">format()</code> function</li>\n</ul>\n<h4>Step 11: Puzzles On Variables <a id=\"step-11-puzzles-on-variables\"></h4>\n</a>\n<p>In the previous step, we were introduced to the concept of variables in Python.</p>\n<p>We will start with looking at a few puzzles.</p>\n<p><strong>Snippet-01: Puzzles On Variables</strong></p>\n<p>What if I try to refer to a variable which is not yet created?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> count    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'count'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'count'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>Before using a variable, you need to have it assigned a value. If you have not defined a variable before, then you cannot use it. Consider <code class=\"language-text\">print(count)</code>, it does not know what count is. So it would throw an error, saying: \"<code class=\"language-text\">count</code> is not defined, I have no idea what count is.\"</p>\n<p>Once you assign a value to a variable, you can use it.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> count <span class=\"token operator\">=</span> <span class=\"token number\">4</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span>    <span class=\"token number\">4</span></code></pre></div>\n<p>The statement <code class=\"language-text\">count = 4</code> where we are creating a variable named <code class=\"language-text\">count</code> for the first time, is called a <strong>variable definition</strong>.</p>\n<p>This is the first time you're referring to a variable, and assigning a value to it.</p>\n<p>Python will create a variable in its memory.</p>\n<p>Variable names are case sensitive. <code class=\"language-text\">count</code> and <code class=\"language-text\">Count</code> are not the same thing.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> Count    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'Count'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined    <span class=\"token operator\">>></span><span class=\"token operator\">></span> count    <span class=\"token number\">4</span></code></pre></div>\n<p>There are rules to follow while naming variables.</p>\n<p>All variable names should either start with an alphabet , or an underscore <code class=\"language-text\">_</code> . <code class=\"language-text\">count</code>, <code class=\"language-text\">_count</code> are valid. <code class=\"language-text\">1count</code> is invalid.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> 1count <span class=\"token operator\">=</span> <span class=\"token number\">5</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        1count <span class=\"token operator\">=</span> <span class=\"token number\">5</span>             <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> count <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> _count <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> 1count      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        1count             <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> 2count      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        2count             <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p>After the first symbol, you can also use a numeral in variable names.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c12345 <span class=\"token operator\">=</span> <span class=\"token number\">5</span></code></pre></div>\n<p>To summarize the rules for naming variables.</p>\n<ul>\n<li>This should start with an alphabet (a capital or a small alphabet) or underscore.</li>\n<li>Starting the second character, it can be alphabet, or underscore, or a numeric value.</li>\n</ul>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Understood that a variable needs to be defined before it is used</li>\n<li>Learned that there are certain rules to be followed while giving names to variables</li>\n</ul>\n<h4>Step 12: Introducing Assignment <a id=\"step-12-introducing-assignment\"></h4>\n</a>\n<p>In this step, we will look at an important concept in Python, called <strong>assignment</strong>. In previous steps, we created variables, like <code class=\"language-text\">i = 5</code>.</p>\n<p><strong>Snippet-01: Introducing Assignment</strong></p>\n<p>You can create other variables using whatever value <code class=\"language-text\">i</code> is referring to. If we say <code class=\"language-text\">j = i</code>, what would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> i    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j    <span class=\"token number\">5</span></code></pre></div>\n<p><code class=\"language-text\">j</code> would start referring to the same value that <code class=\"language-text\">i</code> is referring to. This statement is called an <strong>assignment</strong>.</p>\n<p>Let's try <code class=\"language-text\">j = 2 * i</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> i    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j    <span class=\"token number\">10</span></code></pre></div>\n<p><code class=\"language-text\">j</code> refers to a value of <code class=\"language-text\">10</code></p>\n<p><code class=\"language-text\">=</code> has a different meaning in programming compared to mathematics.</p>\n<p>In mathematics, When we execute <code class=\"language-text\">j = i</code>, it means <code class=\"language-text\">j</code> and <code class=\"language-text\">i</code> are equal.</p>\n<p>In prgramming, the value of the expression on right hand side is assigned to the variable on the right hand side. Can you use a constant on the left hand side of an assignment? The answer is \"No\"!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> j      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>    SyntaxError<span class=\"token punctuation\">:</span> can't assign to literal</code></pre></div>\n<p>The Python Shell throws an error, saying \"Can't assign to literal\", as <code class=\"language-text\">5</code> is a literal.</p>\n<p>Let's create a couple of variables. <code class=\"language-text\">num1 = 5</code> and <code class=\"language-text\">num2 = 3</code>. We would want to add these and create a fresh variable. Let's say the name of the variable is <code class=\"language-text\">sum</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> num1 <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> num2 <span class=\"token operator\">=</span> <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> num1 <span class=\"token operator\">+</span> num2    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span>    <span class=\"token number\">8</span></code></pre></div>\n<p>Create 3 variables <code class=\"language-text\">a</code>, <code class=\"language-text\">b</code> and <code class=\"language-text\">c</code> with different values and calculate their sum.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">7</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span>    <span class=\"token number\">18</span></code></pre></div>\n<p>We have just seen the mechanics of how assignment works in Python.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned what happens when you assign a value to a variable, which may or may not exist</li>\n<li>Discovered that literal constants cannot be placed on the left hand side of the assignment(<code class=\"language-text\">=</code>) operator</li>\n</ul>\n<h4>Step 13: Introducing Formatted Printing <a id=\"step-13-introducing-formatted-printing\"></h4>\n</a>\n<p>Until now, we have been using the <code class=\"language-text\">format()</code> method to format and print values. Let's see a better approach to printing values.</p>\n<p>This is the approach we used until now.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} + {1} + {2} = {3}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c <span class=\"token punctuation\">,</span><span class=\"token builtin\">sum</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">6</span></code></pre></div>\n<p>Python has the concept of formatted strings. The syntax to use a formatted string is very simple - <code class=\"language-text\">f\"\"</code>.</p>\n<p>If we want to print the value of a variable <code class=\"language-text\">a</code>, we can use <code class=\"language-text\">{a}</code> in the text.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"value of a is </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>a<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    value of a <span class=\"token keyword\">is</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"value of b is </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>b<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    value of b <span class=\"token keyword\">is</span> <span class=\"token number\">2</span></code></pre></div>\n<p>The variable within braces is replaced by its value.</p>\n<p>You can use expressions in a formatted string. Example below uses <code class=\"language-text\">{a+b}</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"sum of a and b is </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token builtin\">sum</span> of a <span class=\"token keyword\">and</span> b <span class=\"token keyword\">is</span> <span class=\"token number\">3</span></code></pre></div>\n<p>This feature was introduced in a Python 3 release.</p>\n<p>Let's get back to the original problem we wanted to solve: printing <code class=\"language-text\">5 + 6 + 7 = 18</code>, using formatted strings.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>a<span class=\"token punctuation\">}</span></span><span class=\"token string\"> + </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>b<span class=\"token punctuation\">}</span></span><span class=\"token string\"> + </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>c<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token builtin\">sum</span><span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">6</span></code></pre></div>\n<p>You can see how easy it turns out to be!</p>\n<h4>Step 14: The PMT-Challenge Revisited <a id=\"step-14-the-pmt-challenge-revisited\"></h4>\n</a>\n<p>We want to print the <code class=\"language-text\">5</code>-table from <code class=\"language-text\">5 * 1 = 5</code> onward, until we reach to <code class=\"language-text\">5 * 10 = 50</code>. The best solution we have right now, is shown below:</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">4</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">20</span></code></pre></div>\n<p>Can we do something, to make sure that the code remains the same all the time, but the <code class=\"language-text\">index</code> value gets updated?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> index <span class=\"token operator\">+</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">25</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> index <span class=\"token operator\">+</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> index <span class=\"token operator\">+</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span></code></pre></div>\n<p>We used <code class=\"language-text\">index = index + 1</code> to increment <code class=\"language-text\">index</code> value.</p>\n<p>If we execute these same two statements again and again, we can print the entire table! This is exactly what loops help us do: execute the same statements repeatedly.</p>\n<p>The simplest loop available in Python is the <strong>for loop</strong>.</p>\n<p>When we run a <code class=\"language-text\">for</code> loop, we need to specify the range of values - <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code> or <code class=\"language-text\">1</code> to <code class=\"language-text\">20</code>, and so on. <code class=\"language-text\">range()</code> function helps us to specify a range of values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>    <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The syntax of the <code class=\"language-text\">for</code> loop is: <code class=\"language-text\">for i in range(1, 10): ...</code>. Here, <code class=\"language-text\">i</code> is the name of the <strong>control variable</strong>. In Python, you need to put a colon, '<code class=\"language-text\">:</code>', and in the next line give indentation.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token number\">6</span>    <span class=\"token number\">7</span>    <span class=\"token number\">8</span>    <span class=\"token number\">9</span></code></pre></div>\n<p>You would see that it prints from <code class=\"language-text\">1</code> to <code class=\"language-text\">9</code>.</p>\n<p>When we run a loop in <code class=\"language-text\">range(1, 10)</code>, <code class=\"language-text\">1</code> is <em>inclusive</em> and <code class=\"language-text\">10</code> is <strong>exclusive</strong>.The loop runs from <code class=\"language-text\">1</code> to the value before <code class=\"language-text\">10</code>, which is <code class=\"language-text\">9</code>.</p>\n<p>The leading whitespace before <code class=\"language-text\">print(i)</code> is called <strong>indentation</strong>. We'll talk about indentation later, when we talk about puzzles related to the <code class=\"language-text\">for</code> loop.</p>\n<p>How can you extend this concept to solving our <em>PMT-Challenge</em> problem?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">5</span><span class=\"token punctuation\">}</span></span><span class=\"token string\"> * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>index<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span></code></pre></div>\n<p>What we were doing earlier, was calling <code class=\"language-text\">print()</code> with a formatted string. Now we want to print this statement for different values of <code class=\"language-text\">i</code>.</p>\n<p>How can you do that?</p>\n<p>Let's start with a simple example.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token number\">6</span>    <span class=\"token number\">7</span>    <span class=\"token number\">8</span>    <span class=\"token number\">9</span>    <span class=\"token number\">10</span></code></pre></div>\n<p><code class=\"language-text\">print(f\"{i}\")</code> prints the value of i.</p>\n<p>Now, how do we get it to print <code class=\"language-text\">5 * 1 = 5</code> to <code class=\"language-text\">5 * 10 = 50</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"5 * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">5</span> <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">20</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">25</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">40</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">9</span> <span class=\"token operator\">=</span> <span class=\"token number\">45</span>    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">=</span> <span class=\"token number\">50</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">*</span> <span class=\"token number\">50</span>    <span class=\"token number\">1000</span></code></pre></div>\n<p><code class=\"language-text\">print(f\"5 * {i} = {5 * i}\")</code> prints a specific multiple of 5.</p>\n<h4>Step 15: Loops <a id=\"step-15-loops\"></h4>\n</a>\n<p>In a previous step, we took a major step in programming. We wrote our first for loop with Python. In this step, let's try a few puzzles to understand the for loop even further.</p>\n<p>The syntax of the for loop we looked at earlier was:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">  <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's say we write a <code class=\"language-text\">for</code> loop, but don't give a <code class=\"language-text\">:</code> after the <code class=\"language-text\">range()</code> method, to close the first line. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>                           <span class=\"token operator\">^</span>        SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p>Invalid syntax. A <code class=\"language-text\">:</code> is mandatory within the <code class=\"language-text\">for</code> loop syntax.</p>\n<p>Let's provide a <code class=\"language-text\">:</code> and in the next line, use <code class=\"language-text\">print(i)</code> without space before it (without indentation).</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">2</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>            <span class=\"token operator\">^</span>    IndentationError<span class=\"token punctuation\">:</span> expected an indented block</code></pre></div>\n<p>Most other programming languages use open brace <code class=\"language-text\">{</code> and closed brace <code class=\"language-text\">}</code> as delimiters in a <code class=\"language-text\">for</code> loop. However, Python uses indentation to identify which code is part of a <code class=\"language-text\">for</code> loop, and which is not. So if we are writing the body of a <code class=\"language-text\">for</code> loop, we must use indentation, and leave atleast a single <code class=\"language-text\">&lt;SPACE></code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token number\">6</span>    <span class=\"token number\">7</span>    <span class=\"token number\">8</span>    <span class=\"token number\">9</span></code></pre></div>\n<p>How do we execute two lines of code as part of the <code class=\"language-text\">for</code> loop?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token operator\">*</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">2</span>    <span class=\"token number\">4</span>    <span class=\"token number\">3</span>    <span class=\"token number\">6</span>    <span class=\"token number\">4</span>    <span class=\"token number\">8</span>    <span class=\"token number\">5</span>    <span class=\"token number\">10</span>    <span class=\"token number\">6</span>    <span class=\"token number\">12</span>    <span class=\"token number\">7</span>    <span class=\"token number\">14</span>    <span class=\"token number\">8</span>    <span class=\"token number\">16</span>    <span class=\"token number\">9</span>    <span class=\"token number\">18</span></code></pre></div>\n<p>We are indenting both statements with a space - <code class=\"language-text\">print(i)</code> and <code class=\"language-text\">print(2*i)</code>.</p>\n<p>When for loop has only one line of code, you can specify it right after the <code class=\"language-text\">:</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span></code></pre></div>\n<p>However, this is not considered to be a good programming practice. Even though you may want to execute just one statement in a <code class=\"language-text\">for</code> loop, indentation on a new line is recommended.</p>\n<p>Another best practice is to use four <code class=\"language-text\">&lt;SPACE></code>s for indentation, instead of just two. This would give clear indentation of the code.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span></code></pre></div>\n<p>Anybody who looks at the code immediately understands that this <code class=\"language-text\">print()</code> is part of the <code class=\"language-text\">for</code> loop.</p>\n<p>Let's say you only want to print the odd numbers till <code class=\"language-text\">10</code>, which are <code class=\"language-text\">1</code>, <code class=\"language-text\">3</code>, <code class=\"language-text\">5</code>, <code class=\"language-text\">7</code> and <code class=\"language-text\">9</code>. The <code class=\"language-text\">range()</code> function offers an interesting option.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">1</span>    <span class=\"token number\">3</span>    <span class=\"token number\">5</span>    <span class=\"token number\">7</span>    <span class=\"token number\">9</span></code></pre></div>\n<p>In <code class=\"language-text\">for i in range(1, 11, 2)</code>, we pass in a third argument, called a <em>step</em>. After each iteration, the value of <code class=\"language-text\">i</code> is increment by <code class=\"language-text\">step</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Looked at a few puzzles about the <code class=\"language-text\">for</code> loop, which lay emphasis on the following aspects of for:</p>\n<ul>\n<li>The importance of syntax elements such as the colon</li>\n<li>Indentation</li>\n<li>Variations of the <code class=\"language-text\">range()</code> function</li>\n</ul>\n</li>\n</ul>\n<h4>Step 16: Programming Exercise PE-BA-02 <a id=\"step-16-programming-exercise-pe-ba-02\"></h4>\n</a>\n<p>In the previous step, after initially exploring the Python <code class=\"language-text\">for</code> loop, we looked at a number of puzzles.</p>\n<p>In this step, let's look at a few exercises.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Print the even numbers up to 10. We would want to print 2 4 6 8 10, using a for loop.</li>\n<li>Print the first 10 numbers in reverse</li>\n<li>Print the first 10 even numbers in reverse</li>\n<li>Print the squares of the first 10 numbers</li>\n<li>Print the squares of the first 10 numbers, in reverse</li>\n<li>Print the squares of the even numbers</li>\n</ol>\n<p><strong>Solution 1</strong></p>\n<p>Instead of starting with <code class=\"language-text\">1</code>, we need to start with <code class=\"language-text\">2</code>. Each time, <code class=\"language-text\">i</code> it would be incremented by <code class=\"language-text\">2</code>, and <code class=\"language-text\">2 4 6 8 and 10</code> would be printed.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">2</span>    <span class=\"token number\">4</span>    <span class=\"token number\">6</span>    <span class=\"token number\">8</span>    <span class=\"token number\">10</span></code></pre></div>\n<p><strong>Solution 2</strong></p>\n<p>We would want to print the numbers in reverse. Think about how you would do that using the <code class=\"language-text\">range()</code> function. We'd want go from <code class=\"language-text\">10</code>, <code class=\"language-text\">9</code>, <code class=\"language-text\">8</code>, and so on up to <code class=\"language-text\">1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">10</span>    <span class=\"token number\">9</span>    <span class=\"token number\">8</span>    <span class=\"token number\">7</span>    <span class=\"token number\">6</span>    <span class=\"token number\">5</span>    <span class=\"token number\">4</span>    <span class=\"token number\">3</span>    <span class=\"token number\">2</span>    <span class=\"token number\">1</span></code></pre></div>\n<p>The value to start with is <code class=\"language-text\">10</code>. As we discussed earlier, the end value is exclusive. So to print from <code class=\"language-text\">10</code> to <code class=\"language-text\">1</code>, we want to end one value which is <code class=\"language-text\">0</code>. <code class=\"language-text\">range(10, 0)</code> seems to be what we need.</p>\n<p>Usually these step value is positive, but we need to go backwards from <code class=\"language-text\">10</code>. Hence, we would give a step value of <code class=\"language-text\">-1</code>.</p>\n<p><strong>Solution 3</strong></p>\n<p>Now, let's print the first <code class=\"language-text\">10</code> even numbers in reverse.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">20</span>    <span class=\"token number\">18</span>    <span class=\"token number\">16</span>    <span class=\"token number\">14</span>    <span class=\"token number\">12</span>    <span class=\"token number\">10</span>    <span class=\"token number\">8</span>    <span class=\"token number\">6</span>    <span class=\"token number\">4</span>    <span class=\"token number\">2</span></code></pre></div>\n<p><strong>Solution 4</strong></p>\n<p>Next, we would want to print the squares of the first 10 numbers.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">*</span> i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">1</span>    <span class=\"token number\">4</span>    <span class=\"token number\">9</span>    <span class=\"token number\">16</span>    <span class=\"token number\">25</span>    <span class=\"token number\">36</span>    <span class=\"token number\">49</span>    <span class=\"token number\">64</span>    <span class=\"token number\">81</span>    <span class=\"token number\">100</span></code></pre></div>\n<p><strong>Solution 5</strong></p>\n<p>Let's print the squares in the reverse order.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">100</span>    <span class=\"token number\">81</span>    <span class=\"token number\">64</span>    <span class=\"token number\">49</span>    <span class=\"token number\">36</span>    <span class=\"token number\">25</span>    <span class=\"token number\">16</span>    <span class=\"token number\">9</span>    <span class=\"token number\">4</span>    <span class=\"token number\">1</span></code></pre></div>\n<p><strong>Solution 6</strong></p>\n<p>Print the squares of the even numbers. How to do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">100</span>    <span class=\"token number\">64</span>    <span class=\"token number\">36</span>    <span class=\"token number\">16</span>    <span class=\"token number\">4</span></code></pre></div>\n<p>The key part is using a step of <code class=\"language-text\">-2</code></p>\n<p>We leave it as an exercise for you, to print squares of odd numbers.</p>\n<p><strong>Summary</strong></p>\n<p>In this video, we: * Tried out a few exercises involving the for loop, by playing around with printing sequences of numbers.</p>\n<ul>\n<li>Used the for loop to simplify the solution to the <em>PMT-Challenge</em> problem.</li>\n</ul>\n<h4>Step 17: Review: The Basics Of Python <a id=\"step-17-review-the-basics-of-python\"></h4>\n</a>\n<p>It must have been a roller-coaster ride to solve the multiplication table challenge so far. If you're new to programming, there are a wide range of topics and concepts, that you would have learned during this small journey.</p>\n<p>Let's quickly revise the important concepts we have learned during this small journey.</p>\n<ul>\n<li><code class=\"language-text\">1</code>, <code class=\"language-text\">11</code>, <code class=\"language-text\">5</code>, … are all called literals because these are constant values. Their values don't really change. _Consider <code class=\"language-text\">5 _4_ 50`. This is an expression. `_`is an operator, and`5`, `4`and`50</code> are operands.</li>\n<li>The name <code class=\"language-text\">i</code> in <code class=\"language-text\">i = 1</code>, is called a variable. It can refer to different values, at different points in time.</li>\n<li><code class=\"language-text\">range()</code> and <code class=\"language-text\">print()</code> are in-built Python functions.</li>\n<li>Every complete line of code is called statement. The specific statement <code class=\"language-text\">print()</code>, is invoking a method. The other statement which we looked at earlier, was an assignment statement. <code class=\"language-text\">index = index + 1</code> would evaluate <code class=\"language-text\">index + 1</code>, and have the <code class=\"language-text\">index</code> variable refer to that value.</li>\n<li>The syntax of the <code class=\"language-text\">for</code> loop was very simple. <code class=\"language-text\">for var in range(1, 10) : ...</code>, followed by statements you would want to execute in a loop, with indentation. For the sake of indentation we left four <code class=\"language-text\">&lt;SPACE></code>s in front of each statement inside the <code class=\"language-text\">for</code> loop.</li>\n</ul>\n<p>So that, in a nutshell, is what we have learned over the course of our first section.</p>\n<h3>Chapter 03 - Introducing Methods <a id=\"chapter-03-introducing-methods\"></h3>\n</a>\n<p>In the last section, we introduced you to the basics of python. We learned those concepts by applying them to solve the <em>PMT-Challenge</em> problem. The code below is what we ended up with as we solved that chellenge.</p>\n<p><strong>Snippet-01: Current Solution To PMT-Challenge</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"8 * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">8</span> <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>If we wanted to change the code to print the <code class=\"language-text\">7</code> table, we need to change the value <code class=\"language-text\">7</code> used in the for loop, to <code class=\"language-text\">8</code>. It's simple, but still not as friendly as you would like.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"7 * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">7</span> <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>To print a <code class=\"language-text\">7</code> table, it would be awesome if could say <code class=\"language-text\">print_multiplication_table</code>, and give a value of 7 beside it, and it would do the rest:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'print_multiplication_table'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'print_multiplication_table'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>Similarly, <code class=\"language-text\">print_multiplication_table(8)</code>, could print the multiplication table for <code class=\"language-text\">8</code>!</p>\n<p>To be able to do this, we need to create a <strong>method</strong>, or a <strong>function</strong>. Creating a method makes the code <em>reusable</em>, and we can invoke that method very easily by passing <em>arguments</em>.</p>\n<p>In this section, we take an in-depth look at methods.</p>\n<h4>Step 01: Defining Your First Method <a id=\"step-01-defining-your-first-method\"></h4>\n</a>\n<p>Methods are very important building blocks in Python programming. In this step, we will create a simple method that prints <code class=\"language-text\">\"Hello World\"</code>, twice.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>When we talk about a method, we need to give it a name. We are already using an in-built Python method here, which is <code class=\"language-text\">print()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    Hello World    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    Hello World</code></pre></div>\n<p>Similar to that, we need to give a name to our body of code. Let's say the name is <code class=\"language-text\">print_hello_world_twice</code>.</p>\n<p>The syntax to create a method in Python is straightforward:</p>\n<ul>\n<li>At the start, use the keyword <code class=\"language-text\">def</code> followed by a space.</li>\n<li>Followed by name of the method - <code class=\"language-text\">print_hello_world_twice</code>.</li>\n<li>Add a pair of parenthesis: <code class=\"language-text\">()</code>.</li>\n<li>\n<p>This is followed by a colon <code class=\"language-text\">:</code> (similar to what we used in a <code class=\"language-text\">for</code> loop).</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world_twice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n</li>\n</ul>\n<p>All statements in a method should be indented. The two <code class=\"language-text\">print(\"Hello World\")</code> are indented. So, they are part of the method body.</p>\n<p><code class=\"language-text\">print_hello_world_twice()</code> defines a method, and it has certain code inside its body.</p>\n<p>How do we call this method? Is it sufficient to say <code class=\"language-text\">print_hello_world_twice</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_twice    <span class=\"token operator\">&lt;</span>function print_hello_world_twice at <span class=\"token number\">0x10a71ef28</span><span class=\"token operator\">></span></code></pre></div>\n<p>Python Shell says, there's a function defined with that specific name.</p>\n<p>How do we execute a method? Very simple! Add a pair of parentheses to the name, <code class=\"language-text\">()</code>!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_twice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_twice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Hello World    Hello World</code></pre></div>\n<p>Now, we are able to run the method.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned we can define our own methods in the code we write</li>\n<li>Understood how to define a method, and all its syntax elements</li>\n<li>Saw how we can invoke a method we write</li>\n</ul>\n<h4>Step 02: Programming Exercise PE-MD-01 <a id=\"step-02-programming-exercise-pe-md-01\"></h4>\n</a>\n<p>We will now leave you with two exercises, based on what we have learned about methods so far.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Write a method called <code class=\"language-text\">print_hello_world_thrice()</code>. It should print <code class=\"language-text\">\"Hello World\"</code> thrice to the output. Define this method, and also invoke it.</li>\n<li>\n<p>Write and execute a method, that prints four statements:</p>\n<ol>\n<li>\"I have created my first variable.\"</li>\n<li>\"I've created in my first loop.\"</li>\n<li>\"I've created my first method.\"</li>\n<li>\"I am excited to learn Python.\" You need to print these four statements on four consecutive lines.</li>\n</ol>\n</li>\n</ol>\n<p><strong>Solutions</strong></p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world_thrice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_thrice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World</code></pre></div>\n<p><strong>Solution 2</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_your_progress</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 1\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 2\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 3\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 4\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_your_progress<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Statement <span class=\"token number\">1</span>    Statement <span class=\"token number\">2</span>    Statement <span class=\"token number\">3</span>    Statement <span class=\"token number\">4</span>​    <span class=\"token keyword\">def</span> <span class=\"token function\">print_your_progress</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 1\"</span><span class=\"token punctuation\">)</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 2\"</span><span class=\"token punctuation\">)</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 3\"</span><span class=\"token punctuation\">)</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 4\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>For convenience, we have changed the exact text we need to print. Call this method with the syntax <code class=\"language-text\">print_your_progress()</code>, and you're able to execute its code.</p>\n<p>Now try another exercise. We want to print <code class=\"language-text\">\"Statement 1\"</code>, <code class=\"language-text\">\"Statement 2\"</code>, <code class=\"language-text\">\"Statement 3\"</code> and <code class=\"language-text\">\"Statement 4\"</code> on different lines, using just one print statement. How can you do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_your_progress</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 1\\nStatement 2\\nStatement 3\\nStatement 4\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_your_progress<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Statement <span class=\"token number\">1</span>    Statement <span class=\"token number\">2</span>    Statement <span class=\"token number\">3</span>    Statement <span class=\"token number\">4</span></code></pre></div>\n<p>We are using the newline character <code class=\"language-text\">\\n</code>.</p>\n<p>Let's look at the difference between defining and executing a method.</p>\n<p>When we are writing a method definition, we are writing the code as part of its body. It has a specific syntax, and starts with the <code class=\"language-text\">def</code> keyword.</p>\n<p>A definition by itself cannot cause the code in its body to be executed.</p>\n<p><code class=\"language-text\">print_your_progress()</code> represents a method call. The code inside the method is executed.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Implemented solutions to a few exercises that test our understanding of Python methods. We touched concepts such as:</p>\n<ul>\n<li>Defining a method body</li>\n<li>The way to invoke a method, to run its code</li>\n<li>The difference between the two</li>\n</ul>\n</li>\n</ul>\n<h4>Step 03: Passing Parameters To Methods <a id=\"step-03-passing-parameters-to-methods\"></h4>\n</a>\n<p>In the previous step,we created methods. We defined <code class=\"language-text\">print_hello_world_twice()</code>, and this printed <code class=\"language-text\">\"Hello World\"</code> twice. In this step, let's talk about <em>method arguments</em>, or <em>parameters</em>.</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_twice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_thrice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World</code></pre></div>\n<p>Earlier, we wrote code for <code class=\"language-text\">print_hello_world_thrice()</code>, which prints the message three times.</p>\n<p>Let's say you want to print it five times. You would need to write another method that does what you need. Doesn't that seem monotonous?</p>\n<p>Instead of that, Won't it be great if I can call the method by the same name, say <code class=\"language-text\">print_hello_world(5)</code>, and it would print \"Hello World\" five times?</p>\n<p>The <code class=\"language-text\">5</code> which we are passing here is called an <strong>argument</strong>.</p>\n<p>How do we define our method to accept this argument?</p>\n<p>Let's call our argument <code class=\"language-text\">no_of_times</code>. If you have any experience with other programming languages, they generally need you to specify the parameter type. Something like <code class=\"language-text\">This parameter is an integer/float/string, or other types</code>. But Python does not require parameter type.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Although we are not doing exactly what we set out to, let's see what would happen. What would happen if we say <code class=\"language-text\">print_hello_world()</code> ?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    TypeError<span class=\"token punctuation\">:</span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> missing <span class=\"token number\">1</span> required positional argument<span class=\"token punctuation\">:</span> <span class=\"token string\">'no_of_times'</span></code></pre></div>\n<p>Error! Something like \"Hey, you have created <code class=\"language-text\">print_hello_world</code> with a parameter, but not passing anything in here! Go ahead and pass a value\". Let's pass in a value, such as <code class=\"language-text\">5</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    Hello World    <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>    Hello World    <span class=\"token number\">10</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span>    Hello World    <span class=\"token number\">100</span></code></pre></div>\n<p>With <code class=\"language-text\">print_hello_world(5)</code>, you can see <code class=\"language-text\">\"Hello World\"</code> and <code class=\"language-text\">5</code> being printed. We are now able to define this method to accept a value, and print that value by invoking it. You can pass in any value, such as<code class=\"language-text\">10</code>, <code class=\"language-text\">100</code>, or others.</p>\n<p>Now think of a different solution for this method, where you don't repeat the same piece of code to print <code class=\"language-text\">\"Hello World\"</code>. Consider <code class=\"language-text\">print_hello_world(5)</code>, it should still print <code class=\"language-text\">\"Hello World\"</code> <code class=\"language-text\">5</code> times. How do you do that?</p>\n<p>Think about using something along the lines of a loop.</p>\n<p><strong>Snippet-02:</strong></p>\n<p>For now, what we are doing is we are printing <code class=\"language-text\">\"Hello World\"</code> <code class=\"language-text\">10</code> times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>​    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World    Hello World    Hello World    Hello World    Hello World    Hello World    Hello World</code></pre></div>\n<p>Our method call <code class=\"language-text\">print_hello_world(5)</code> now prints <code class=\"language-text\">\"Hello World\"</code> <code class=\"language-text\">10</code> times.</p>\n<p>However just print the message <code class=\"language-text\">5</code> times. We need to make use of the parameter <code class=\"language-text\">no_of_times</code> inside the <code class=\"language-text\">for</code> loop as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>​    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World    Hello World</code></pre></div>\n<p>Now let's execute the method again. You can see that it's printing <code class=\"language-text\">4</code> times only.</p>\n<p>Why is it not printing <code class=\"language-text\">5</code> times?</p>\n<p>That's because <code class=\"language-text\">no_of_times</code> as a second parameter to <code class=\"language-text\">range()</code> is exclusive.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World    Hello World    Hello World</code></pre></div>\n<p>Great, it's now printing the message <code class=\"language-text\">5</code> times!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World    Hello World    Hello World    Hello World    Hello World</code></pre></div>\n<p>If you pass a different argument like <code class=\"language-text\">7</code>, the message is displayed <code class=\"language-text\">7</code> times.</p>\n<p>Something you need to always be cautious about in Python, is the indentation. Over here, the <code class=\"language-text\">for</code> loop is part of the method body. So we have extra indentation for it. The print is part of the <code class=\"language-text\">for</code> loop body. So guess what, even more indentation for that code.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned how to pass arguments to a method</li>\n<li>Understood that the method definition needs to have parameters coded in</li>\n<li>Observed that arguments passed during a method call can be accessed inside a methods body</li>\n</ul>\n<h4>Step 04: Classroom Exercise CE-MD-01 <a id=\"step-04-classroom-exercise-ce-md-01\"></h4>\n</a>\n<p>In this step, Let's look at a few exercises related to the method parameter.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Write a method called <code class=\"language-text\">print_numbers()</code>, that would print all successive integers from <code class=\"language-text\">1</code> to <code class=\"language-text\">n</code>.</li>\n<li>The second one is to write a method called <code class=\"language-text\">print_squares_of_numbers()</code>, that prints squares of all successive integers from <code class=\"language-text\">1</code> to <code class=\"language-text\">n</code>.</li>\n</ol>\n<p><strong>Solutions</strong></p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_numbers</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> n<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>If you are programming in other languages such as Java, you are used to naming methods in this way: <code class=\"language-text\">printNumbers()</code>. This convention is popularly known as \"Camel Case\".</p>\n<p>That's NOT how Python programmers name their methods. Pythonic way is to use underscore <code class=\"language-text\">_</code> to separate words in the method name, as in <code class=\"language-text\">print_numbers()</code>.</p>\n<p><strong>Solution 2</strong></p>\n<p>Let's define <code class=\"language-text\">print_squares_of_numbers()</code>. This would be very similar to <code class=\"language-text\">print_numbers()</code>, working with the same range. Only, we need to say <code class=\"language-text\">print(i*i)</code> .</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_squares_of_numbers</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> n<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_squares_of_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span>    <span class=\"token number\">4</span>    <span class=\"token number\">9</span>    <span class=\"token number\">16</span>    <span class=\"token number\">25</span></code></pre></div>\n<p>How is a parameter different from an argument?</p>\n<ul>\n<li>Inside the definition of the method, the name within parentheses is referred to as a <strong>parameter</strong>. In our recent exercise, <code class=\"language-text\">n</code> is a parameter, because it's used in the definition of <code class=\"language-text\">print_squares_of_numbers</code>.</li>\n<li>When you are passing a value to a method during a method call, say <code class=\"language-text\">5</code>, that value is called an <strong>argument</strong>.</li>\n<li>\n<p>Don't worry too much about it. Just follow this convention for now:</p>\n<ul>\n<li>In the method call, call it an <em>argument</em>.</li>\n<li>In a method definition, call it a <em>parameter</em>.</li>\n</ul>\n</li>\n</ul>\n<p><strong>Summary</strong></p>\n<p>In this step, we looked at a few simple exercises related to passing method arguments</p>\n<h4>Step 05: Methods With Multiple Parameters <a id=\"step-05-methods-with-multiple-parameters\"></h4>\n</a>\n<p>In this step, let's look at creating a method with multiple parameters.</p>\n<p><strong>Snippet-01:</strong></p>\n<p><code class=\"language-text\">print_hello_world</code> accepts one parameter and prints \"Hello World\" the specified number of times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Let's say we want to print another piece of text <code class=\"language-text\">Welcome To Python</code>, a specified number of times. How do you do that?</p>\n<p>You can always create another method similar to the first one, such as <code class=\"language-text\">print_welcome_to_python(no_of_times)</code> and print the necessary text inside.</p>\n<p>However, is that what a good programmer does?</p>\n<p>A good programmer tries to create a more generic solution.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_string</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">,</span> no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World</code></pre></div>\n<p>The good programmer that you are, you created a new method called <code class=\"language-text\">print_string(str, no_of_times)</code> accepting a text parameter, in addition to <code class=\"language-text\">no_of_times</code>.</p>\n<p>Syntax rules for method parameters are quite strict. If we say <code class=\"language-text\">print_string(\"Welcome to Python\")</code> and run it, we get an error! Python Shell says: \"I need <code class=\"language-text\">no_of_times</code> to be present in here\".</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token string\">\"Welcome to Python\"</span><span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    TypeError<span class=\"token punctuation\">:</span> print_string<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> missing <span class=\"token number\">1</span> required positional argument<span class=\"token punctuation\">:</span> <span class=\"token string\">'no_of_times'</span></code></pre></div>\n<p>Let's say you want to assign default values for <code class=\"language-text\">str</code> and <code class=\"language-text\">no_of_times</code> in <code class=\"language-text\">print_string()</code>. By default, we want to always print <code class=\"language-text\">\"Hello World\"</code>, and that too <code class=\"language-text\">5</code> times.</p>\n<p>The Python language makes this very easy. <code class=\"language-text\">def print_string(str = \"Hello World\", no_of_times=5)</code>. The rest of the method remains the same.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_string</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token operator\">=</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">,</span> no_of_times<span class=\"token operator\">=</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Now you can call <code class=\"language-text\">print_string()</code>, and <code class=\"language-text\">\"Hello World\"</code> is displayed <code class=\"language-text\">5</code> times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World    Hello World    Hello World</code></pre></div>\n<p>If it's <code class=\"language-text\">print_string(\"Welcome To Python\")</code>, what does it do? It prints <code class=\"language-text\">\"Welcome To Python\"</code>, <code class=\"language-text\">5</code> times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token string\">\"Welcome to Python\"</span><span class=\"token punctuation\">)</span>    Welcome to Python    Welcome to Python    Welcome to Python    Welcome to Python    Welcome to Python</code></pre></div>\n<p>Consider <code class=\"language-text\">print_string(\"Welcome to Python\", 8)</code>, it would print that string <code class=\"language-text\">8</code> times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token string\">\"Welcome to Python\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">)</span>    Welcome to Python    Welcome to Python    Welcome to Python    Welcome to Python    Welcome to Python    Welcome to Python    Welcome to Python    Welcome to Python</code></pre></div>\n<p>Isn't that cool!</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at how to pass multiple parameters to a method, starting with two arguments</li>\n<li>Learned how you can define default values for those parameters</li>\n<li>Observed we could pass default arguments for none, some or all of those parameters</li>\n</ul>\n<h4>Step 06: Back To Multiplication Table - Using Methods <a id=\"step-06-back-to-multiplication-table-using-methods\"></h4>\n</a>\n<p>Let's get back to our original goal, of why we needed methods. We wanted to create a multiplication table for a number, and observed that each time we needed to we needed change that number, we were forced to make a change in the code. This is not something we liked, and that's why we started investigating how methods can be used.</p>\n<p>In this step, Let's try our hand at creating a multiplication table method.</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"7 * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">7</span> <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Let's define a method called <code class=\"language-text\">print_multiplication_table()</code>, and pass in a parameter to it.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_multiplication_table</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table<span class=\"token punctuation\">}</span></span><span class=\"token string\"> * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">14</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">21</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">28</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">42</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">49</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">56</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">9</span> <span class=\"token operator\">=</span> <span class=\"token number\">63</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">=</span> <span class=\"token number\">70</span></code></pre></div>\n<p>Now you have the entire multiplication table for <code class=\"language-text\">7</code>.</p>\n<p>You can then call <code class=\"language-text\">print_multiplication_table()</code> with arguments <code class=\"language-text\">8</code>, <code class=\"language-text\">9</code>,and so on, by simply changing the <code class=\"language-text\">table</code> arguemnt value.</p>\n<p>We now want to create even better <code class=\"language-text\">print_multiplication_table()</code> method.</p>\n<p>We want to control the start point, as well as the end point, in the call to <code class=\"language-text\">range()</code>. We want to say <code class=\"language-text\">print_multiplication_table(7, 1, 6)</code>, to print the <code class=\"language-text\">7</code> table with entries from <code class=\"language-text\">1</code> to <code class=\"language-text\">6</code>. How can you do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_multiplication_table</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table<span class=\"token punctuation\">}</span></span><span class=\"token string\"> * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">14</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">21</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">28</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">42</span></code></pre></div>\n<p>Simple! Define those range limits as additional parameters!</p>\n<p>The other thing we can obviously do, is have default values for the <code class=\"language-text\">start</code>, and the <code class=\"language-text\">end</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_multiplication_table</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">,</span> start<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table<span class=\"token punctuation\">}</span></span><span class=\"token string\"> * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>​    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">14</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">21</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">28</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">42</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">49</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">56</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">9</span> <span class=\"token operator\">=</span> <span class=\"token number\">63</span>    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">=</span> <span class=\"token number\">70</span></code></pre></div>\n<p>Calling <code class=\"language-text\">print_multiplication_table(7)</code> would give us entries from <code class=\"language-text\">7 * 1 = 7</code> to <code class=\"language-text\">7 * 10 = 70</code>.</p>\n<p>Now you can actually send out this method, to your friends, who would find it easy to use, and cool!</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned how to define a method to print the multiplication table for a number</li>\n<li>Looked at how to enhance this method to make table printing more flexible</li>\n<li>Further enhanced that method to accept default arguments while printing a table</li>\n</ul>\n<h4>Step 07: Indentation Is King <a id=\"step-07-indentation-is-king\"></h4>\n</a>\n<p>In Python, indentation denote blocks of code. So if you want to put something in a <code class=\"language-text\">for</code> loop, or outside it, proper indentation would be sufficient. In this step, let's explore indentation in depth. Let's start by creating a simple method.</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">method_to_understand_indentation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> method_to_understand_indentation<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token number\">6</span>    <span class=\"token number\">7</span>    <span class=\"token number\">8</span>    <span class=\"token number\">9</span>    <span class=\"token number\">10</span></code></pre></div>\n<p>Consider the code below: <code class=\"language-text\">print(5)</code> is indented at the same level as <code class=\"language-text\">for loop</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">method_to_understand_indentation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>You can see that <code class=\"language-text\">print(5)</code> is called only once. It is not part of the <code class=\"language-text\">for loop</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> method_to_understand_indentation<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token number\">6</span>    <span class=\"token number\">7</span>    <span class=\"token number\">8</span>    <span class=\"token number\">9</span>    <span class=\"token number\">10</span>    <span class=\"token number\">5</span></code></pre></div>\n<p>Let's change the code in this method a bit. <code class=\"language-text\">print(5)</code> is indented the same way as <code class=\"language-text\">print(i)</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">method_to_understand_indentation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p><code class=\"language-text\">print(5)</code> is part of the for loop. It is executed 10 times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> method_to_understand_indentation<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span>    <span class=\"token number\">5</span>    <span class=\"token number\">2</span>    <span class=\"token number\">5</span>    <span class=\"token number\">3</span>    <span class=\"token number\">5</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token number\">5</span>    <span class=\"token number\">5</span>    <span class=\"token number\">6</span>    <span class=\"token number\">5</span>    <span class=\"token number\">7</span>    <span class=\"token number\">5</span>    <span class=\"token number\">8</span>    <span class=\"token number\">5</span>    <span class=\"token number\">9</span>    <span class=\"token number\">5</span>    <span class=\"token number\">10</span>    <span class=\"token number\">5</span></code></pre></div>\n<p>Whether we're talking about loops, methods or conditionals, proper indentation is very important in Python.</p>\n<p>We indicate a block of code, by having all lines of that block at the same indentation level. There are no specific delimiters like for instance a pair of braces <code class=\"language-text\">{...}</code>, as in other programming languages.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Ran through a few examples to see how indentation works in Python</li>\n</ul>\n<h4>Step 08: Puzzles on Methods - Named Parameters <a id=\"step-08-puzzles-on-methods-named-parameters\"></h4>\n</a>\n<p>In this step, let's look at a variety of puzzles related to methods.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Consider the following method: I would want to print the default string 6 times. How do we do it?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_string</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token operator\">=</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">,</span> no_of_times<span class=\"token operator\">=</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World    Hello World    Hello World</code></pre></div>\n<p>Will it work if we call the method as in: <code class=\"language-text\">print_string(6)</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">6</span>    <span class=\"token number\">6</span>    <span class=\"token number\">6</span>    <span class=\"token number\">6</span>    <span class=\"token number\">6</span></code></pre></div>\n<p><code class=\"language-text\">6</code> is passed as the first parameter. <code class=\"language-text\">6</code> is matched to <code class=\"language-text\">str</code>, and the method prints <code class=\"language-text\">6</code> the default number of times, which is <code class=\"language-text\">5</code>.</p>\n<p>to default to <code class=\"language-text\">\"Hello World\"</code>, and print it <code class=\"language-text\">6</code> times.</p>\n<p>You can do this in Python by using <strong>named parameters</strong>. During the method call, you can specify <code class=\"language-text\">no_of_times = 6</code>. <strong><code class=\"language-text\">no_of_times</code></strong> is a named parameter.</p>\n<blockquote>\n<p>There is no provision of doing something like this, in other languages like Java.</p>\n</blockquote>\n<p>Call it as <code class=\"language-text\">print_string(no_of_times=6)</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span>no_of_times<span class=\"token operator\">=</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>    Hello World    Hello World    Hello World    Hello World    Hello World    Hello World</code></pre></div>\n<p><code class=\"language-text\">str</code> gets a default value, and <code class=\"language-text\">\"Hello World\"</code> is printed <code class=\"language-text\">6</code> times.</p>\n<p>Named parameters are very useful, when a method has a number of parameters, and you would want to make it very clear which parameter you're passing a value for.</p>\n<p>Let's call <code class=\"language-text\">print_string(7, 8)</code>. what happens?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">7</span>    <span class=\"token number\">7</span>    <span class=\"token number\">7</span>    <span class=\"token number\">7</span>    <span class=\"token number\">7</span>    <span class=\"token number\">7</span>    <span class=\"token number\">7</span>    <span class=\"token number\">7</span></code></pre></div>\n<p>You would see that <code class=\"language-text\">7</code> is printed <code class=\"language-text\">8</code> times.</p>\n<p>Since <code class=\"language-text\">print()</code> method is quite flexible, you can pass a number as the first argument. You can even pass a <code class=\"language-text\">float</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token number\">7.5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">7.5</span>    <span class=\"token number\">7.5</span>    <span class=\"token number\">7.5</span>    <span class=\"token number\">7.5</span>    <span class=\"token number\">7.5</span>    <span class=\"token number\">7.5</span>    <span class=\"token number\">7.5</span>    <span class=\"token number\">7.5</span></code></pre></div>\n<p>What would be the result of this - <code class=\"language-text\">print_string(7.5, \"eight\")</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token number\">7.5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"eight\"</span><span class=\"token punctuation\">)</span>    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> print_string    TypeError<span class=\"token punctuation\">:</span> must be <span class=\"token builtin\">str</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">not</span> <span class=\"token builtin\">int</span></code></pre></div>\n<p>Note how <code class=\"language-text\">no_of_times</code> is used inside the method… as an argument to <code class=\"language-text\">range()</code>. <code class=\"language-text\">range()</code> only accepts integers, nothing else. When you run the code with <code class=\"language-text\">print_string(7.5, \"eight\")</code>, we get an error.</p>\n<p>It says: <code class=\"language-text\">TypeError: ```no_of_times``` must be ```int```, not string</code>.</p>\n<p>A simple rule of thumb is, if you have a parameter, you can pass any type of data to it. That could be an integer, a floating point value a string, or a boolean value. The Python language does not check for the type of a parameter. However, Python will throw an error if the function which is using that parameter, expects it to be of a specific type. The <code class=\"language-text\">range()</code> function expects that the <code class=\"language-text\">no_of_times</code> is an integer value.</p>\n<p><strong>Snippet-02:</strong></p>\n<p>The last thing which we would be looking at, is method naming conventions. We named our methods in a consistent way: <code class=\"language-text\">print_string</code>, <code class=\"language-text\">print_multiplication_table</code>, and the like.</p>\n<p>This is exactly the format which most Python developers use, to name their methods.</p>\n<p>Convention is to use underscore to separate words in a name.</p>\n<p>However, there are a few rules for naming a method: One of the important rules is also related to variable names. We observed that a variable name cannot start with a number.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> 1_print<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token keyword\">def</span> 1_print<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>             <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid token</code></pre></div>\n<p>Similarly, <code class=\"language-text\">1_print</code> will not be accepted as a method name.</p>\n<ul>\n<li>You can start a name with an alphabet, or with an underscore.</li>\n<li>From the second character onward, you are allowed to use numeric symbols.</li>\n</ul>\n<p>Methods and variables cannot be named using Python keywords.</p>\n<p>Now, what is a keyword? For example, when we talked about <code class=\"language-text\">for</code> loop, as in:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">```<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>```<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<ul>\n<li><strong><code class=\"language-text\">for</code></strong> is a keyword</li>\n<li><strong><code class=\"language-text\">in</code></strong> is a keyword</li>\n<li><strong><code class=\"language-text\">def</code></strong> is a keyword.</li>\n</ul>\n<p>Later we will look at a few other keywords, such as <strong><code class=\"language-text\">while</code></strong>, <strong><code class=\"language-text\">return</code></strong>, <strong><code class=\"language-text\">if</code></strong>, <strong><code class=\"language-text\">else</code></strong>, <strong><code class=\"language-text\">elif</code></strong>, and many more.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">def</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token keyword\">def</span> <span class=\"token function\">def</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>              <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">in</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token keyword\">def</span> <span class=\"token function\">in</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>             <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        <span class=\"token keyword\">def</span> <span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>              <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to the concept of named parameters</li>\n<li>Explored the typical naming rules and conventions for methods in Python</li>\n<li>Observed that reserved keywords cannot be used to name variables or methods</li>\n</ul>\n<h4>Step 09: Methods - Return Values <a id=\"step-09-methods-return-values\"></h4>\n</a>\n<p>Let's try and understand the importance of return values from a method. We will learn how to return a value from a method.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's name our method as <code class=\"language-text\">product_of_two_numbers()</code>, and let's have parameters <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> that it accepts:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">product_of_two_numbers</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">*</span> b<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_of_two_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">2</span></code></pre></div>\n<p>Can we take the product of these two numbers into a variable, and use it in other code, in the same program?</p>\n<p>Suppose we say a <code class=\"language-text\">product = product_of_two_numbers(1,2)</code>, is this allowed?</p>\n<p>Let's run this code, and see what's stored in <code class=\"language-text\">product</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product <span class=\"token operator\">=</span> product_of_two_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product</code></pre></div>\n<p>It's empty.</p>\n<p>The <code class=\"language-text\">product_of_two_numbers()</code> method is not really returning anything back, to be used elsewhere.</p>\n<p>Have a look at some of the built-in Python functions, such as <code class=\"language-text\">max()</code> for example.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">4</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> maximum <span class=\"token operator\">=</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> maximum    <span class=\"token number\">4</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> maximum <span class=\"token operator\">*</span> <span class=\"token number\">5</span>    <span class=\"token number\">20</span></code></pre></div>\n<p>If I call <code class=\"language-text\">max()</code> with four parameters, as in <code class=\"language-text\">maximum = max(1,2,3,4)</code>, the value <code class=\"language-text\">4</code> gets stored in maximum.</p>\n<p>Later on in the code that follows, we can say <code class=\"language-text\">maximum * 5</code>, or we can print the value of <code class=\"language-text\">maximum</code>, or a similar calculation. This gives our programs a lot more flexibility.</p>\n<p>So instead of just printing <code class=\"language-text\">a*b</code>, if this function could return a value, that would be quite useful.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">product_of_two_numbers</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      product <span class=\"token operator\">=</span> a <span class=\"token operator\">*</span> b<span class=\"token punctuation\">;</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      <span class=\"token keyword\">return</span> product    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_of_two_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">6</span></code></pre></div>\n<p>We are creating a variable <code class=\"language-text\">product</code> and doing a <code class=\"language-text\">return product</code>.</p>\n<p>Lets run <code class=\"language-text\">product_result = product_of_two_numbers(2, 3)</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_result <span class=\"token operator\">=</span> product_of_two_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_result    <span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_result <span class=\"token operator\">*</span> <span class=\"token number\">10</span>    <span class=\"token number\">60</span></code></pre></div>\n<p>You can see how simple it is to return values from a method!</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned how to return values from inside a method</li>\n<li>Observed how we can store the values returned by a method call</li>\n</ul>\n<h4>Step 10: Programming Exercise PE-MD-02 <a id=\"step-10-programming-exercise-pe-md-02\"></h4>\n</a>\n<p>In this step let's look at a couple of exercises about returning values from methods.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Write a method to return the sum of three integers.</li>\n<li>Write a method which takes as input two integers, representing two angles of a triangle, and computes the third angle.</li>\n</ol>\n<p>Hint: The sum of the angles in a triangle is <code class=\"language-text\">180</code> degrees. So if I am passing <code class=\"language-text\">50</code> and <code class=\"language-text\">50</code>, <code class=\"language-text\">50</code> plus <code class=\"language-text\">50</code> is <code class=\"language-text\">100</code>. So some of three angles should be <code class=\"language-text\">180</code>, so the third angle will be <code class=\"language-text\">180 - 100</code>, which is <code class=\"language-text\">80</code>.</p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span><span class=\"token keyword\">def</span> sum_of_three_numbers<span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>​    <span class=\"token operator\">>></span><span class=\"token operator\">></span> sum_of_three_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> something <span class=\"token operator\">=</span> sum_of_three_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> something <span class=\"token operator\">*</span> <span class=\"token number\">5</span>    <span class=\"token number\">30</span></code></pre></div>\n<p>The shorter way of doing that would have been to have a temporary variable called instead of <code class=\"language-text\">sum</code>. We could directly <code class=\"language-text\">return a + b + c</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">sum_of_three_numbers</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> something <span class=\"token operator\">=</span> sum_of_three_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> something <span class=\"token operator\">*</span> <span class=\"token number\">5</span>    <span class=\"token number\">30</span></code></pre></div>\n<p>In methods, you can use <code class=\"language-text\">return expression</code> as well. That <code class=\"language-text\">expression</code> gets evaluated, and the value gets returned back. You'd see that the result remains the same.</p>\n<p><strong>Solution 2</strong></p>\n<p>The second is to write a method to take two integers, representing two angles of a triangle, and compute the third one.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">calculate_third_angle</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">return</span> <span class=\"token number\">180</span> <span class=\"token operator\">-</span> <span class=\"token punctuation\">(</span> first <span class=\"token operator\">+</span> second <span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> calculate_third_angle<span class=\"token punctuation\">(</span><span class=\"token number\">50</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">110</span></code></pre></div>\n<p>In your programming career, you would be writing a number of methods. It's very important that you are comfortable doing so. Most of the methods that you write would return values back.</p>\n<p>That's the reason why we're creating a lot of examples involving method calls.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a couple of exercises related to returning values from methods</li>\n<li>Observed that returning expressions avoids creating unnecessary variables, and shortens method definitions</li>\n</ul>\n<h3>Chapter 04 - Introduction To Python Platform <a id=\"chapter-04-introduction-to-python-platform\"></h3>\n</a>\n<p>Until now we had been using Python Shell to execute all our code.</p>\n<p>In the real world, we'll be write Python code in a variety of scripts. Before we would go into an IDE and use the IDE to write the script, we thought it would be useful for us to understand how you can write Python code without the benefit of an IDE.</p>\n<p>This would also help us understand the Python environment, in-depth.</p>\n<p>In the next few steps, we'll be looking at how to create simple Python scripts, using any text editor of your choice. Use Notepad, Notepad++. Editpad, or whichever text editing software you are comfortable with. We'll see what involved in executing the program, and what's happening in the background.</p>\n<p>Here are a few videos you might want to look at.</p>\n<ul>\n<li>​[Writing and Executing your First Python Script](https://www.youtube.com/watch?v=ORmDD1R7lNc)​</li>\n<li>​[Understanding Python Virtual Machine and bytecode](https://www.youtube.com/watch?v=HE-FC0csG68)​</li>\n</ul>\n<h4>Step 01 - Writing and Executing Python Shell Programs <a id=\"step-01-writing-and-executing-python-shell-programs\"></h4>\n</a>\n<p>Here's a recommended video to watch - [Writing and Executing your First Python Script](https://www.youtube.com/watch?v=ORmDD1R7lNc)​</p>\n<p>Let's get started with creating a simple script file.</p>\n<p>We want to type in a simple Python script, or a piece of Python code, such as <code class=\"language-text\">print(\"Hello world\")</code>. Does it get any simpler than this?</p>\n<p>We'll save this into any folder on our hard disk, with a name 'first.py' .</p>\n<p><em><strong>first.py</strong></em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello world\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The '.py' is not really mandatory, but typically all python files end with a '.py' extension.</p>\n<p>Here's how you can run it:</p>\n<ul>\n<li>Launch your terminal, or command prompt</li>\n<li>'cd' to the folder where this python script file is saved</li>\n<li>execute the command <code class=\"language-text\">python first.py</code></li>\n</ul>\n<p>You will see that <code class=\"language-text\">Hello World</code> will be printed.</p>\n<p>If you are familiar with other programming languages, you would need a class, need to put the code in that class, and similar stuff.</p>\n<p>While Python supports Object Oriented Programming, is not mandatory to create a class.</p>\n<p>It's almost as if you're typing commands, starting from the line one! That's why we call it a python script.</p>\n<p><strong>Summary</strong></p>\n<p>In this small step, we tried to create a simple python script, and we ran it from the command line. All we needed to do, was use the same command we use to launch up the python shell, and followed it up with a name of the file. We created a file called first.py, executed that, and were able to see the output on the console.</p>\n<p>As an exercise, try and add a few more methods and try to run those methods as well, as part of this script.</p>\n<h4>Step 02 - Python virtual machine and bytecode <a id=\"step-02-python-virtual-machine-and-bytecode\"></h4>\n</a>\n<p>In this step, let's try and understand what's happening in the background.</p>\n<p>We wrote a simple piece of code using a text editor. We created a file named first.py, and all we did was: <code class=\"language-text\">python3 first.py</code>. If you look at other languages like Java for example, there is a separate compilation phase and then an execution phase. But with Python, just this command does both compilation and execution.</p>\n<p>We saw that, as soon as we make a change and we run <code class=\"language-text\">python3 first.py</code> , the change is compiled and executed as well!</p>\n<p>In Python, there is an intermediate format called <strong>Python byte code</strong>. Code is first compiled to bytecode, and then executed on the <strong>Python virtual machine</strong>.</p>\n<p>When we installed Python, we installed both the python compiler and interpreter, as well as the virtual machine.</p>\n<p>In Python, <code class=\"language-text\">bytecode</code> is not standardized. Different implementations of Python have different byte code. There are about 80 Python implementations, like CPython and Jython.</p>\n<ul>\n<li>CPython is a Python implementation in C language.</li>\n<li>Jython is a Python implementation in Java language. The bytecode which Jython uses is actually Java bytecode, and you can run it on the Java virtual machine.</li>\n</ul>\n<p>Python leaves a lot of flexibility to the implementations of Python. They have the flexibility to choose the bytecode, and to choose the virtual machine that is compatible. The bytecode is tied to the specific virtual machine you are using. Therefore, if you're using CPython to compile the bytecode, you'll not be able to use Jython to run it.</p>\n<p>You should make sure, that whatever implementation you are using to compile, is the same one you're using to run the code as well.</p>\n<p><strong>Summary</strong></p>\n<p>A lot of this sounds like boring theory. Don't worry about it. As a beginner, this might not be very important for you right now.</p>\n<p>It's very important for you to understand the process. What's happening is you were writing Python code, and when you ran the command <code class=\"language-text\">python3 first.py</code>, it is both compiled and executed. An intermediate format called bytecode is created, which is not really standardized in Python. The bytecode is executed in a Python virtual machine.</p>\n<p>The idea behind this quick section, is to give you a little bit of background on what's happening behind the scenes. I'll see you in the next section. Until then, bye-bye!</p>\n<h3>Chapter 05 - Introduction To VSCode <a id=\"chapter-05-introduction-to-vscode\"></h3>\n</a>\n<p>Let's start using the IDE VSCode to write our Python Code</p>\n<p>Here are recommended videos to watch</p>\n<ul>\n<li>​[Installing VSCode](https://www.youtube.com/watch?v=pI_cnCXpCTU)​</li>\n<li>​[Write and Execute a Python File with VSCode](https://www.youtube.com/watch?v=Na05tSP21Jg)​</li>\n<li>​[Write Your First Python Program with VSCode](https://www.youtube.com/watch?v=PvYSlWbXuCw)​</li>\n</ul>\n<h4>Step 01 - Installing and Introduction to VSCode <a id=\"step-01-installing-and-introduction-to-vscode\"></h4>\n</a>\n<p>In this quick step, we'll help you install VSCode.</p>\n<p>Here's the video guide for this step</p>\n<ul>\n<li>​[Installing VSCode](https://www.youtube.com/watch?v=pI_cnCXpCTU)​</li>\n</ul>\n<p>Go to Google and type in \"VSCode Community Edition Download\". Click the link which comes up first: [https://www.jetbrains.com/VSCode/download](https://www.jetbrains.com/VSCode/download).</p>\n<p>You'll go to a page where you can choose the operating system: whether you are on Windows, Mac, or Linux.</p>\n<p>Once you choose that, you can download the appropriate community version.</p>\n<p>On the right hand side, you'll see a community version, and you can click the download link, to start the download.</p>\n<p>If you are having a problem, you can also use the direct link to download.</p>\n<p>Once you download VSCode, all you need to do is double-click the package which is downloaded. Follow the instructions, and you can continue with the defaults, until you completely install VSCode.</p>\n<p>When you launch VSCode for the first time, it should ask you for a theme, where you can choose the default.</p>\n<p>You're all set to go ahead with the next step in the course.</p>\n<p>VSCode is an awesome IDE, and I'm sure you learn a lot about it.</p>\n<h4>Step 02 - Write and Execute a Python File with VSCode <a id=\"step-02-write-and-execute-a-python-file-with-vscode\"></h4>\n</a>\n<p>In this step, let's launch up the VSCode IDE, and create our first Python project with a Python script. We want to be able to launch a Python script by the end of this step.</p>\n<p>Here's the video guide for this step</p>\n<ul>\n<li>​[Write and Execute a Python File with VSCode](https://www.youtube.com/watch?v=Na05tSP21Jg)​</li>\n</ul>\n<p>Launch the VSCode IDE. You'll see that it takes a little while to launch the first time, and then brings up a welcome screen.</p>\n<p>We would want to create a number of Python files. All these files will be in a project. You can think of our project as a collection of Python scripts, or modules.</p>\n<p>To get started, let's create a new project by clicking 'create new project'. Let's name it - '01-first-python-project'.</p>\n<p>Right now there are no files in the project.</p>\n<p>Let's create our first Python file, using the IDE.</p>\n<p>The way you can do that is by saying 'right-click' -> 'new' -> 'Python file', and then we'll give this a name of 'hello_world', and click OK.</p>\n<p>Now you can go ahead and write your first Python program. Let's write some simple code, like <code class=\"language-text\">print(\"Hello World\")</code>, and save it.</p>\n<p>You can do a right-click here, and say 'Run hello_world'.</p>\n<p>A small window comes up below, which shows the output. It says <code class=\"language-text\">'Hello World'</code>.</p>\n<h4>Step 03 - Execise - Write Multiplication Table Method with VSCode <a id=\"step-03-execise-write-multiplication-table-method-with-vscode\"></h4>\n</a>\n<p>Let's start with a simple exercise. We created the multiplication table method in the Python Shell. What we do now, is we'll create the same thing but in a Python file of its own.</p>\n<p>Here's the video guide for this step:</p>\n<ul>\n<li>​[Write Your First Python Program with VSCode](https://www.youtube.com/watch?v=PvYSlWbXuCw)​</li>\n</ul>\n<h3>Chapter 06 - Introducing Data Types and Conditionals <a id=\"chapter-06-introducing-data-types-and-conditionals\"></h3>\n</a>\n<p>Welcome to this section, where we will talk about numeric data types, and conditional program execution. After looking at the numeric and boolean data types, we will turn our attention to executing code, based on logical conditions.</p>\n<h4>Step 01: Numeric Data Types <a id=\"step-01-numeric-data-types\"></h4>\n</a>\n<p>In previous sections, we created variables of this kind: <code class=\"language-text\">number = 5</code> , <code class=\"language-text\">value = 2.5</code>, etc. The <code class=\"language-text\">5</code> here is an integer, and integers represent numbers, such as <code class=\"language-text\">1</code>, <code class=\"language-text\">2</code>, <code class=\"language-text\">6</code>, <code class=\"language-text\">-1</code> and <code class=\"language-text\">-2</code>. In Python, the <code class=\"language-text\">class</code> for this particular data type is <code class=\"language-text\">int</code>.</p>\n<p>If you write code like <code class=\"language-text\">type(5)</code>, you'd get <code class=\"language-text\">'int'</code> as the output.</p>\n<p>In Python, there are no primitive types. What does that mean? Every value that you see in a Python program, is an object, an instance of some <code class=\"language-text\">class</code>.</p>\n<p>In later sections, We'll understand what is a <code class=\"language-text\">class</code>, and what is an object or an instance. For now, the most important thing for you to remember, is that behind every value, there is a <code class=\"language-text\">class</code>.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's look at <code class=\"language-text\">2.5</code>, which is a floating point value.</p>\n<p>If you go ahead and do <code class=\"language-text\">type(2.5)</code>, what would you see? You would see it's of type `<code class=\"language-text\">float</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">2.5</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">2.55</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span></code></pre></div>\n<p>When you perform a division operation between two integers, there is a chance that the result of the operation is a <code class=\"language-text\">float</code>. If you do <code class=\"language-text\">5/2</code>, the result is <code class=\"language-text\">2.5</code>. If we were to do <code class=\"language-text\">4/2</code>, even then it's of type <code class=\"language-text\">float</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">/</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token operator\">/</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token operator\">/</span><span class=\"token number\">2</span>    <span class=\"token number\">2.0</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span>    <span class=\"token number\">3</span></code></pre></div>\n<p>All the operations we looked at until now, can also be performed on floating point values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">=</span> <span class=\"token number\">4.5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value2 <span class=\"token operator\">=</span> <span class=\"token number\">3.2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">+</span> value2    <span class=\"token number\">7.7</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">-</span> value2    <span class=\"token number\">1.2999999999999998</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">/</span> value2    <span class=\"token number\">1.40625</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">%</span> value2    <span class=\"token number\">1.2999999999999998</span></code></pre></div>\n<p><code class=\"language-text\">value1 - value2</code> returns <code class=\"language-text\">1.299999999999998</code>. Why?</p>\n<p>Floating point numbers don't really represent accurate values. That's one of the things you need to always keep in mind.</p>\n<p>Typically, if you're doing any highly sensitive financial calculations, don't use <code class=\"language-text\">float</code>s to represent your values. Instead, use <code class=\"language-text\">Decimal</code>. More about it later.</p>\n<p>Operations can also be performed between <code class=\"language-text\">int</code> and <code class=\"language-text\">float</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">+</span> value1    <span class=\"token number\">14.5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">-</span> value1    <span class=\"token number\">5.5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">/</span> value1    <span class=\"token number\">2.2222222222222223</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>Result of an operation between a <code class=\"language-text\">int</code> and a <code class=\"language-text\">float</code>, is always a <code class=\"language-text\">float</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at the two basic numeric types: <code class=\"language-text\">int</code> and <code class=\"language-text\">float</code>.</li>\n<li>Saw the basic operations you can do among <code class=\"language-text\">int</code>s, among <code class=\"language-text\">float</code>s, and also between <code class=\"language-text\">int</code>s and <code class=\"language-text\">float</code>s.</li>\n</ul>\n<h4>Step 02: Programming Exercise PE-DT-01 <a id=\"step-02-programming-exercise-pe-dt-01\"></h4>\n</a>\n<p>In this step, let's do a simple exercise with numeric values.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>You need to create a method called <code class=\"language-text\">simple_interest</code>, and pass three parameters: <code class=\"language-text\">principal</code>, <code class=\"language-text\">interest</code> and <code class=\"language-text\">duration</code> (in years). You also want to calculate the amount after the specific duration, and return it back. Call this method with a few example values.</li>\n</ol>\n<p>For example, if you want to call <code class=\"language-text\">simple_interest</code> with <code class=\"language-text\">10000</code>, with an interest of <code class=\"language-text\">5</code> percent, for a duration of <code class=\"language-text\">5</code> years, the correct answer would be as follows: <code class=\"language-text\">10000</code> is the principal. In addition to <code class=\"language-text\">10000</code>, you get the interest. The interest for one year is <code class=\"language-text\">10000 * 0.05</code>, as the interest figure is in percentage.So that's <code class=\"language-text\">500</code> a year, into <code class=\"language-text\">5</code> which is <code class=\"language-text\">2500</code>. The result would be <code class=\"language-text\">12500</code>, and this value should be printed.</p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token keyword\">def</span> <span class=\"token function\">calculate_simple_interest</span><span class=\"token punctuation\">(</span>principal<span class=\"token punctuation\">,</span> interest<span class=\"token punctuation\">,</span> duration<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>            <span class=\"token keyword\">return</span> principal <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">+</span> interest <span class=\"token operator\">*</span> <span class=\"token number\">0.01</span> <span class=\"token operator\">*</span> duration<span class=\"token punctuation\">)</span>​    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculate_simple_interest<span class=\"token punctuation\">(</span><span class=\"token number\">10000</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Wrote a very simple method to do a simple interest calculation</li>\n</ul>\n<h4>Step 03: Puzzles On Numeric Types <a id=\"step-03-puzzles-on-numeric-types\"></h4>\n</a>\n<p>In this section, we are looking at numeric types. In this specific step, we would be looking at a few puzzles related to values of these types.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's create a simple variable <code class=\"language-text\">i = 1</code>. <code class=\"language-text\">i = i + 1</code>. What would be the value of <code class=\"language-text\">i</code> after that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i    <span class=\"token number\">2</span></code></pre></div>\n<p>It would be <code class=\"language-text\">2</code>. There is a shortcut way of doing the same thing, by using the <code class=\"language-text\">+=</code> operator.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i    <span class=\"token number\">3</span></code></pre></div>\n<p>Typically in other programming languages, you can do something of this kind: <code class=\"language-text\">i++</code>. There is no provision in Python to use increment operators like <code class=\"language-text\">++</code>, in either prefix or suffix mode, like <code class=\"language-text\">++i</code>, or <code class=\"language-text\">i++</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i<span class=\"token operator\">+</span><span class=\"token operator\">+</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>        i<span class=\"token operator\">+</span><span class=\"token operator\">+</span>          <span class=\"token operator\">^</span>    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token operator\">+</span><span class=\"token operator\">+</span>i    <span class=\"token number\">3</span></code></pre></div>\n<p>Let's look at compound assignments.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i    <span class=\"token number\">4</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">-=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i    <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">/=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">*=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i    <span class=\"token number\">6.0</span></code></pre></div>\n<p>What you see here, is Dynamic Typing in Python. The type of a variable can change during the lifetime of the program.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token operator\">&lt;</span><span class=\"token builtin\">type</span> <span class=\"token string\">'int'</span><span class=\"token operator\">>></span><span class=\"token operator\">>></span> i <span class=\"token operator\">=</span> i<span class=\"token operator\">/</span><span class=\"token number\">2.0</span><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token operator\">&lt;</span><span class=\"token builtin\">type</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span></code></pre></div>\n<p>Let's create a couple more numbers. <code class=\"language-text\">number1 = 5</code> and <code class=\"language-text\">number2 = 2</code>. What could be the result of <code class=\"language-text\">number1 / number2</code>? You know it, it's <code class=\"language-text\">2.5</code> .</p>\n<p><code class=\"language-text\">number1 // nummber2</code> truncates the value of <code class=\"language-text\">2.5</code>, to <code class=\"language-text\">2</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> number1<span class=\"token operator\">//</span>number2    <span class=\"token number\">2</span></code></pre></div>\n<p>If you can do <code class=\"language-text\">number1 // number2</code>, can you also do this: <code class=\"language-text\">number1 //= number2</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> number1 <span class=\"token operator\">//=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> number1    <span class=\"token number\">2</span></code></pre></div>\n<p><code class=\"language-text\">5 ** 3</code> is <code class=\"language-text\">5</code> 'to the power of' <code class=\"language-text\">3</code>, which is <code class=\"language-text\">5 * 5 * 5</code>, or <code class=\"language-text\">125</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">**</span> <span class=\"token number\">3</span>    <span class=\"token number\">125</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">125</span></code></pre></div>\n<p>This can also be achieved by invoking <code class=\"language-text\">pow(5, 3)</code>. We have an operator, as well as a method at our disposal.</p>\n<p>The last thing we will look at, are type conversion functions.</p>\n<p>If you need to convert an <code class=\"language-text\">int</code> value to a <code class=\"language-text\">float</code>, or a <code class=\"language-text\">float</code> to an <code class=\"language-text\">int</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.6</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span></code></pre></div>\n<p>What if you want to round a value? <code class=\"language-text\">5.6</code> is nearer to <code class=\"language-text\">6</code> than <code class=\"language-text\">5</code>. You can use a function called <code class=\"language-text\">round()</code>, and here,<code class=\"language-text\">round(5.6)</code> gives the correct result <code class=\"language-text\">6</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.6</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.4</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.5</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">6</span></code></pre></div>\n<p><code class=\"language-text\">round()</code> can also allows you to specify number of decimals in the result.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.67</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5.7</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.678</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5.68</span></code></pre></div>\n<p>You can also convert <code class=\"language-text\">int</code> to <code class=\"language-text\">float</code>, by using the function <code class=\"language-text\">float()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">5.0</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a few corner cases related to your numeric types.</li>\n<li>Examined the different operators available for use with values of numeric types</li>\n<li>Learned about the usage of type conversion functions</li>\n</ul>\n<h4>Step 04: Introducing Boolean Type <a id=\"step-04-introducing-boolean-type\"></h4>\n</a>\n<p>We will now shift our attention to the <code class=\"language-text\">bool</code> data type.</p>\n<p>A boolean value is something which can be either \"true\" or \"false\".</p>\n<p><strong>Snippet-01:</strong></p>\n<p>In Python, \"true\" is represented by <code class=\"language-text\">True</code>, and \"false\" by <code class=\"language-text\">False</code>. It's important to remember that it's <code class=\"language-text\">True</code> with a capital <code class=\"language-text\">'T'</code>, and <code class=\"language-text\">False</code> with a capital <code class=\"language-text\">'F'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> true    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'true'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined    <span class=\"token operator\">>></span><span class=\"token operator\">></span> false    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'false'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>The boolean variable <code class=\"language-text\">is_even</code> indicates whether a number is even or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> is_even <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> is_odd <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>Let's create a variable <code class=\"language-text\">i = 10</code>. We want to find out if <code class=\"language-text\">i > 15</code>. What do you think is the result? <code class=\"language-text\">False</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">10</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">></span> <span class=\"token number\">15</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">15</span>    <span class=\"token boolean\">True</span></code></pre></div>\n<p>In general, boolean values can represent the result of logical conditions.</p>\n<p>Let's look at other operations that can result in <code class=\"language-text\">bool</code> values. We looked at <code class=\"language-text\">></code> and <code class=\"language-text\">&lt;</code>. Another operation which you can perform, is <code class=\"language-text\">>=</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">>=</span> <span class=\"token number\">15</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">>=</span> <span class=\"token number\">10</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">></span> <span class=\"token number\">10</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">&lt;=</span> <span class=\"token number\">10</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p><code class=\"language-text\">==</code> is the comparison operator. We are only comparing the value of <code class=\"language-text\">i</code> against <code class=\"language-text\">10</code>, not changing its value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">==</span> <span class=\"token number\">10</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">==</span> <span class=\"token number\">11</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to the <code class=\"language-text\">bool</code> data type</li>\n<li>Learned that <code class=\"language-text\">bool</code> variables are useful handy while testing logical conditions</li>\n</ul>\n<h4>Step 05: Introducing Conditionals <a id=\"step-05-introducing-conditionals\"></h4>\n</a>\n<p>In this step, let's look at <code class=\"language-text\">if</code> statement.</p>\n<p>Sometimes you need to execute code only when certain conditions are true. You can use a <code class=\"language-text\">if</code> condition, which is the simplest conditional in Python. Let's look at an example.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's say <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">5</code>. You want to print something, only if <code class=\"language-text\">i</code> has a value greater than <code class=\"language-text\">3</code>. How do you do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">></span><span class=\"token number\">3</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> is greater than 3\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">5</span> <span class=\"token keyword\">is</span> greater than <span class=\"token number\">3</span></code></pre></div>\n<p>The syntax of the <code class=\"language-text\">if</code> is very simple: <code class=\"language-text\">if</code> followed by a condition; with the condition you want to check. It looks like: <code class=\"language-text\">if i>3: ...</code> You need to indent the body of the <code class=\"language-text\">if</code> with <code class=\"language-text\">&lt;SPACE></code>s as usual.</p>\n<p>Let's say <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">2</code>. What would happen if we execute the same code again?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">></span><span class=\"token number\">3</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> is greater than 3\"</span></span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>You would see that nothing is printed to the console. Based on the value of <code class=\"language-text\">i</code> , either the statement is executed, or it's not. That's what an <code class=\"language-text\">if</code> helps us to do.</p>\n<p>The way you can think about an <code class=\"language-text\">if</code>, is the body of code under the <code class=\"language-text\">if</code> is executed only when this condition is <code class=\"language-text\">True</code>. If this condition is not <code class=\"language-text\">True</code>, that code is not executed at all.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"False\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"True\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token boolean\">True</span></code></pre></div>\n<p>Let's take two different numbers, say <code class=\"language-text\">a = 5</code>, and <code class=\"language-text\">b = 7</code>. We want to compare them, and predict if <code class=\"language-text\">a</code> is greater that <code class=\"language-text\">b</code> .</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">7</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>a<span class=\"token operator\">></span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"a is greater than b\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>​    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">9</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>a<span class=\"token operator\">></span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"a is greater than b\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    a <span class=\"token keyword\">is</span> greater than b</code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to the <code class=\"language-text\">if</code> statement, the simplest Python conditional</li>\n<li>Understood how an <code class=\"language-text\">if</code> helps in implementing conditional program logic</li>\n</ul>\n<h4>Step 06: Classroom Exercise CE-DT-01 <a id=\"step-06-classroom-exercise-ce-dt-01\"></h4>\n</a>\n<p>In this step, let's look at a couple of exercises with the if statement.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's say we define four variables: <code class=\"language-text\">a = 1</code>, <code class=\"language-text\">b = 2</code> , <code class=\"language-text\">c = 3</code> and <code class=\"language-text\">d = 5</code>. we want to find out, if <code class=\"language-text\">a + b</code> is greater than <code class=\"language-text\">c + d</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> d <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a<span class=\"token operator\">+</span>b <span class=\"token operator\">></span> c<span class=\"token operator\">+</span>d <span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"a+b > c +d\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">9</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a<span class=\"token operator\">+</span>b <span class=\"token operator\">></span> c<span class=\"token operator\">+</span>d <span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"a+b > c +d\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    a<span class=\"token operator\">+</span>b <span class=\"token operator\">></span> c <span class=\"token operator\">+</span>d</code></pre></div>\n<p>Let's say we are given three values meant to be the angles of a triangle. Their values are <code class=\"language-text\">angle1 = 30</code>, <code class=\"language-text\">angle2 = 20</code> and <code class=\"language-text\">angle3 = 60</code>. You want to find out if these three angles actually form a valid triangle. You know that the sum of the angles of a triangle is always <code class=\"language-text\">180</code> degrees.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> angle1 <span class=\"token operator\">=</span> <span class=\"token number\">30</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> angle2 <span class=\"token operator\">=</span> <span class=\"token number\">20</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> angle3 <span class=\"token operator\">=</span> <span class=\"token number\">60</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>angle1 <span class=\"token operator\">+</span> angle2 <span class=\"token operator\">+</span> angle3 <span class=\"token operator\">==</span> <span class=\"token number\">180</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Valid Triangle\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> angle2 <span class=\"token operator\">=</span> <span class=\"token number\">90</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>angle1 <span class=\"token operator\">+</span> angle2 <span class=\"token operator\">+</span> angle3 <span class=\"token operator\">==</span> <span class=\"token number\">180</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Valid Triangle\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    Valid Triangle</code></pre></div>\n<p>The last exercise is to check if a number is even or not.</p>\n<p>Hint L you need to use one of the operators we talked about earlier. That's right, use the modulo operator <code class=\"language-text\">%</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is even\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    i <span class=\"token keyword\">is</span> even​    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is even\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a few exercises related to the if statement, for writing and testing conditions.</li>\n</ul>\n<h4>Step 07 - Logical Operators - and or not <a id=\"step-07-logical-operators-and-or-not\"></h4>\n</a>\n<p>In this step, let's look at the different operators that can be used on <code class=\"language-text\">bool</code> values. These operators are called logical operators - <code class=\"language-text\">and</code>, <code class=\"language-text\">or</code> , <code class=\"language-text\">not</code> and <code class=\"language-text\">^</code> (xor).</p>\n<p>Let's say we have a value <code class=\"language-text\">True</code>, and the other <code class=\"language-text\">False</code>, and we want to play around with them.</p>\n<p>Logical operator <code class=\"language-text\">and</code> returns true only when both operands are <code class=\"language-text\">True</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">False</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">True</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">False</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">True</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>Logical operator <code class=\"language-text\">or</code> returns true when atleast one of the operands is <code class=\"language-text\">True</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">False</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">True</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">True</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>Logical operator <code class=\"language-text\">not</code> returns negation.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">True</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">not</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">not</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span></code></pre></div>\n<p>The XOR operation, denoted by the <code class=\"language-text\">^</code> operator, is <code class=\"language-text\">True</code> when operands have different boolean values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">True</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">False</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">True</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">False</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at the logical operators that act on boolean values, such as <code class=\"language-text\">and</code>, <code class=\"language-text\">or</code>, <code class=\"language-text\">not</code> and <code class=\"language-text\">^</code></li>\n<li>Explored each of these operators, finding out when they return <code class=\"language-text\">True</code>, and when <code class=\"language-text\">False</code>.</li>\n</ul>\n<h4>Step 08: Puzzles On Logical Operators <a id=\"step-08-puzzles-on-logical-operators\"></h4>\n</a>\n<p>In this step, Let's look at a few simple puzzles to look at the logical operators.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's say <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">10</code>, and <code class=\"language-text\">j</code> has a value of <code class=\"language-text\">15</code>. You want to find out if both <code class=\"language-text\">i</code> and <code class=\"language-text\">j</code> are even. How do you do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">10</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> <span class=\"token number\">15</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">and</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i and j are even\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> <span class=\"token number\">14</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">and</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i and j are even\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    i <span class=\"token keyword\">and</span> j are even​    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">or</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">2</span>        <span class=\"token operator\">^</span>    IndentationError<span class=\"token punctuation\">:</span> expected an indented block    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">or</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"atleast one of i and j are even\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    atleast one of i <span class=\"token keyword\">and</span> j are even</code></pre></div>\n<p>If we want to find out if at least one of <code class=\"language-text\">i</code> and <code class=\"language-text\">j</code> is even, we can use the <code class=\"language-text\">or</code> operator.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">15</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j    <span class=\"token number\">14</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">or</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"atleast one of i and j are even\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    atleast one of i <span class=\"token keyword\">and</span> j are even    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> <span class=\"token number\">23</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">or</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"atleast one of i and j are even\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i    <span class=\"token number\">15</span></code></pre></div>\n<p>Now try and guess the value of this. <code class=\"language-text\">if(True ^ False): print(\"Message\")</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This will Print\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    This will Print    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">False</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This will Print\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    This will Print    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This will Print\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Xor operation using <code class=\"language-text\">^</code> - message will get printed if the operands are different.</p>\n<p>What would happen if both of them are <code class=\"language-text\">True</code>? No message is printed.</p>\n<p>So you would use <code class=\"language-text\">^</code> in situations, where you'd want one of the operands to be <code class=\"language-text\">True</code>, and the other to be <code class=\"language-text\">False</code>.</p>\n<p>Let's say, <code class=\"language-text\">x = 5</code>, and you want to check <code class=\"language-text\">if not x == 6: print(\"This\")</code>. What will be the result of running this code?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> x <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> x <span class=\"token operator\">==</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    This    <span class=\"token operator\">>></span><span class=\"token operator\">></span> x <span class=\"token operator\">=</span> <span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> x <span class=\"token operator\">==</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Actually, there is a shortcut for such a condition: <code class=\"language-text\">if x != 6 : print(\"This\")</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> x<span class=\"token operator\">!=</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> x<span class=\"token operator\">=</span><span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> x<span class=\"token operator\">!=</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    This</code></pre></div>\n<p><code class=\"language-text\">int()</code> is a conversion function, which when given say a <code class=\"language-text\">float</code> value, returns an <code class=\"language-text\">int</code> value. Consider <code class=\"language-text\">int(True)</code>, what would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">0</span></code></pre></div>\n<p><code class=\"language-text\">int(True)</code> returns 1. <code class=\"language-text\">int(False)</code> returns 0.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> x <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">6</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> x<span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"something\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    something</code></pre></div>\n<p>One of the most interesting facts about boolean stuff, is anything which is non-zero, is considered to be <code class=\"language-text\">True</code>.</p>\n<p><code class=\"language-text\">0</code> is the only integer value which is considered to be <code class=\"language-text\">False</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>So, if I have a value of <code class=\"language-text\">x = -6</code>, and execute <code class=\"language-text\">if x: print(\"something\")</code> what do you think will happen?</p>\n<p><code class=\"language-text\">\"something\"</code> will be printed.</p>\n<p>You can use the function <code class=\"language-text\">bool()</code>, to convert <code class=\"language-text\">int</code> to a <code class=\"language-text\">bool</code> value.</p>\n<ul>\n<li><code class=\"language-text\">bool(6)</code> returns <code class=\"language-text\">True</code></li>\n<li><code class=\"language-text\">bool(-6)</code> returns <code class=\"language-text\">True</code></li>\n<li><code class=\"language-text\">bool(0)</code> returns <code class=\"language-text\">False</code>.</li>\n</ul>\n<p>Except for <code class=\"language-text\">bool(0)</code>, all the other results would be <code class=\"language-text\">True</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a few puzzles related to the logical operators</li>\n<li>Looked at conversion functions such as <code class=\"language-text\">bool()</code> and <code class=\"language-text\">int()</code> to convert between boolean and integer data</li>\n</ul>\n<h4>Step 09: <a id=\"step-09\"></h4>\n</a>\n<p>In this step, let's look at two other important components of an <code class=\"language-text\">if</code> statement: <code class=\"language-text\">else</code> and <code class=\"language-text\">elif</code>. Let's start with <code class=\"language-text\">else</code>.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Consider a scenario where <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">2</code>. Let's try to print a message <code class=\"language-text\">\"i is even\"</code> if <code class=\"language-text\">i</code> is an even number. Otherwise, print <code class=\"language-text\">\"i is odd\"</code>.</p>\n<p>Earlier we wrote code along these lines: <code class=\"language-text\">if i % 2 == 0 : print(\"i is even\")</code>. However if this condition is not <code class=\"language-text\">True</code>, we would want to <code class=\"language-text\">print(\"i is odd\")</code>. How do we accomplish that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is even\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is odd\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    i <span class=\"token keyword\">is</span> even</code></pre></div>\n<p>An <code class=\"language-text\">else</code> clause provides an alternative code body to execute, if the <code class=\"language-text\">if</code> condition is <code class=\"language-text\">False</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is even\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is odd\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    i <span class=\"token keyword\">is</span> odd</code></pre></div>\n<p>Let's look at <code class=\"language-text\">elif</code>.</p>\n<p>We want to do something if <code class=\"language-text\">i</code> has value of <code class=\"language-text\">3</code>, and something totally different if <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">4</code>.</p>\n<p>In short, we want to specify 2 alternatives to the <code class=\"language-text\">if</code> condition. How can that be done?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">==</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is 1\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">elif</span> i<span class=\"token operator\">==</span><span class=\"token number\">2</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is 2\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is not 1 or 2\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    i <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token number\">1</span> <span class=\"token keyword\">or</span> <span class=\"token number\">2</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>That's where the <strong><code class=\"language-text\">elif</code></strong> clause comes into the picture. The code in <code class=\"language-text\">elif</code> is executed if the previous conditions are false and the current <code class=\"language-text\">elif</code> condition is true.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at two important components of the <code class=\"language-text\">if</code> statement: <code class=\"language-text\">else</code> and <code class=\"language-text\">elif</code>.</li>\n<li>Understood that the <code class=\"language-text\">elif</code> clauses and the final <code class=\"language-text\">else</code> clause provide alternative conditions to check, when earlier if conditions are true.</li>\n</ul>\n<h4>Step 10: Classroom Exercise CE-DT-02 <a id=\"step-10-classroom-exercise-ce-dt-02\"></h4>\n</a>\n<p>In this step, let's do a simple exercise with <code class=\"language-text\">if</code>, <code class=\"language-text\">else</code> and <code class=\"language-text\">elif</code>.</p>\n<p>Before getting to the exercise, let's try and learn how to get console input from the user.</p>\n<p>Until now, we had been hard-coding all the data we were to use. Let's make that part more dynamic now.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>How do we get input from the user? We want to get input from the console, and assign it to a variable. The way we can do that, is by statement <code class=\"language-text\">value = input()</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    value <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter a Value: \"</span><span class=\"token punctuation\">)</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"you entered \"</span><span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span></code></pre></div>\n<p>We can call the <code class=\"language-text\">input()</code> method with a text 'prompt', such as <code class=\"language-text\">\"Enter A Value: \"</code>. What we can initially do here, is print the value which was entered, back to the console, by <code class=\"language-text\">print(\"you entered \", integer_value)</code>.</p>\n<p>An interesting point to explore here, is the type of data input at the console.</p>\n<p>Let's do a <code class=\"language-text\">print(type(value))</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    value <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter a Value: \"</span><span class=\"token punctuation\">)</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"you entered \"</span><span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Input a value of <code class=\"language-text\">Test</code>. It has a class of <code class=\"language-text\">str</code>.</p>\n<p>Let's run it again to see other possibilities. This time, let's enter a numeric value, say <code class=\"language-text\">12</code>. what would happen?</p>\n<p>We again get <code class=\"language-text\">str</code>.</p>\n<p>We want to get an integer value from the input. How can we do it?</p>\n<p><code class=\"language-text\">int()</code> function converts string to int. Let's use it.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">value <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter a Value: \"</span><span class=\"token punctuation\">)</span>integer_value <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"you entered \"</span><span class=\"token punctuation\">,</span> integer_value<span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>integer_value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Let's run our code once again.</p>\n<p><code class=\"language-text\">\"Enter A Value: \"</code> is prompted, and we enter <code class=\"language-text\">15</code>. And now, of it says <code class=\"language-text\">\"You entered 15\"</code>, and the type it indicates to us, is <code class=\"language-text\">int</code>.</p>\n<p><strong>Design a menu</strong></p>\n<ul>\n<li>\n<p>Ask the User for input:</p>\n<ul>\n<li>Enter two numbers</li>\n<li>\n<p>Choose the Option:</p>\n<ul>\n<li>1 - Add</li>\n<li>2 - Subtract</li>\n<li>3 - Multiply</li>\n<li>4 - Divide</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Perform the Operation</li>\n<li>Publish the Result</li>\n</ul>\n<p>Let's design a menu, and then ask the user for input.</p>\n<p>We have codes for each of the operations : add is <code class=\"language-text\">1</code>, subtract is <code class=\"language-text\">2</code>, divide is <code class=\"language-text\">3</code>, and multiply is <code class=\"language-text\">4</code>.</p>\n<p>In the first version of the program let's get all the inputs and print them out.</p>\n<p><strong>Solution</strong></p>\n<p>The first version of the program is simple to write</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number1 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number1: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>number2 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number2: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"You entered </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>number1<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"You entered </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>number2<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>number1 <span class=\"token operator\">+</span> number2<span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\\n1 - Add\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"2 - Subtract\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"3 - Divide\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"4 - Multiply\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 - Exit\"</span><span class=\"token punctuation\">)</span>choice <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Choose Operation: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>choice<span class=\"token punctuation\">)</span></code></pre></div>\n<p>We will continue this exercise to complete it, in the next step.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at the in-built <code class=\"language-text\">input()</code> function that can read console input</li>\n<li>Learned that <code class=\"language-text\">input()</code> always returns what the user enters, as a string</li>\n<li>We can convert the string from <code class=\"language-text\">input()</code>, to the data type we expect by invoking conversion functions</li>\n</ul>\n<h4>Step 11: Continued - Classroom Exercise CE-DT-02 <a id=\"step-11-continued-classroom-exercise-ce-dt-02\"></h4>\n</a>\n<p><strong>Exercises</strong></p>\n<p>In the previous step, we got the input from the user. Let's continue the exercise in this step. We want to write an if condition.</p>\n<p><strong>Solution (Continued)</strong></p>\n<p>Extending the solution is easy. Write appropriate <code class=\"language-text\">if</code>, <code class=\"language-text\">elif</code> and <code class=\"language-text\">else</code> conditions.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number1 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number1: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>number2 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number2: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>​<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\\n1 - Add\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"2 - Subtract\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"3 - Divide\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"4 - Multiply\"</span><span class=\"token punctuation\">)</span>​choice <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Choose Operation: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>​<span class=\"token comment\"># print(number1 + number2)# print(choice)if choice==1:    result = number1 + number2elif choice==2:    result = number1 - number2elif choice==3:    result = number1 / number2elif choice==4:    result = number1 * number2else:    result = \"Invalid Choice\"​print(result)</span></code></pre></div>\n<p>We added the following code to account for invalid input.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>    result <span class=\"token operator\">=</span> <span class=\"token string\">\"Invalid Choice\"</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Augmented the Menu Exercise to get all the input from the console, and compute a value from them</li>\n<li>Corrected the logic to handle incorrect input</li>\n</ul>\n<h4>Step 12: Puzzles On Conditionals <a id=\"step-12-puzzles-on-conditionals\"></h4>\n</a>\n<p>In this step, let's look at a few puzzles related to these <code class=\"language-text\">if</code>, <code class=\"language-text\">elif</code> and <code class=\"language-text\">else</code> clauses.</p>\n<p><strong>Puzzle-01</strong></p>\n<p>Let's start with the first puzzle. Guess the output.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">k <span class=\"token operator\">=</span> 15if <span class=\"token punctuation\">(</span>k <span class=\"token operator\">></span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">elif</span> <span class=\"token punctuation\">(</span>k <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">elif</span> <span class=\"token punctuation\">(</span>k <span class=\"token operator\">&lt;</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>When we run it, you can see that the output is <code class=\"language-text\">2</code>.</p>\n<p><code class=\"language-text\">k</code> has a value of <code class=\"language-text\">15</code>, is it greater than <code class=\"language-text\">20</code>? No! Execution goes to the <code class=\"language-text\">elif</code>, is <code class=\"language-text\">k</code> greater then <code class=\"language-text\">10</code>? Yes. It prints <code class=\"language-text\">2</code> and goes out of the complete <code class=\"language-text\">if</code>-<code class=\"language-text\">else</code> block.</p>\n<p>Inside the <code class=\"language-text\">if</code> conditional, the <code class=\"language-text\">if</code>, <code class=\"language-text\">elif</code> and <code class=\"language-text\">else</code> clauses are all independent ones. Only one matching block is ever executed.</p>\n<p><strong>Puzzle-02</strong></p>\n<p>What do you think would be the output of this particular piece of code?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">l <span class=\"token operator\">=</span> <span class=\"token number\">15</span>    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">&lt;</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"l&lt;20\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">></span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"l>20\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Who am I?\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Note that there are two totally different <code class=\"language-text\">if</code> conditions in here : <code class=\"language-text\">if l &lt; 20: ...</code> immediately followed by<code class=\"language-text\">if l > 20: ... else: ...</code>.</p>\n<p>The first <code class=\"language-text\">if</code> is true. <code class=\"language-text\">l&lt;20</code> is printed.</p>\n<p>The second <code class=\"language-text\">if</code> is a separate statement. The condition is false. So. <code class=\"language-text\">else</code> gets executed. Therefore, <code class=\"language-text\">\"who am I\"</code> gets printed.</p>\n<p><strong>Puzzle-03</strong></p>\n<p>Let's run this code.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">m <span class=\"token operator\">=</span> 15if m<span class=\"token operator\">></span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">if</span> m<span class=\"token operator\">&lt;</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"m>20\"</span><span class=\"token punctuation\">)</span>    <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Who am I?\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can see that nothing is printed.</p>\n<p>The most important thing to focus on here, is indentation.</p>\n<p>The second <code class=\"language-text\">if</code> block is executed only if the first <code class=\"language-text\">if</code> is true.</p>\n<p><strong>Puzzle-04</strong></p>\n<p>What would be the output?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number <span class=\"token operator\">=</span> 5if number <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>  number <span class=\"token operator\">=</span> number <span class=\"token operator\">+</span> 10number <span class=\"token operator\">=</span> number <span class=\"token operator\">+</span> 5print<span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">10</code> is printed.</p>\n<p>The most important thing to focus on here, is indentation.</p>\n<p>Only <code class=\"language-text\">number = number + 10</code> is part of <code class=\"language-text\">if</code> block. It is not executed because the condition is false.</p>\n<p><code class=\"language-text\">number = number + 5</code> is not part of <code class=\"language-text\">if</code>. So, it gets executed.</p>\n<p>Let's add a couple of spaces before <code class=\"language-text\">number = number + 5</code>.</p>\n<p>What would be the output?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number <span class=\"token operator\">=</span> 5if number <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>  number <span class=\"token operator\">=</span> number <span class=\"token operator\">+</span> <span class=\"token number\">10</span>  number <span class=\"token operator\">=</span> number <span class=\"token operator\">+</span> 5print<span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">5</code> is printed.</p>\n<p>Both the statements <code class=\"language-text\">number = number + 10</code> and <code class=\"language-text\">number = number + 5</code> are part of <code class=\"language-text\">if</code> block. They are not executed because the condition is false.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a few puzzles related to <code class=\"language-text\">if</code>, <code class=\"language-text\">elif</code> and <code class=\"language-text\">else</code></li>\n<li>Explored the importance of indentation and the different condition clauses inside an <code class=\"language-text\">if</code> statement</li>\n</ul>\n<h4>Step 01: The Python Type To Denote Text <a id=\"step-01-the-python-type-to-denote-text\"></h4>\n</a>\n<p>Let's start looking at another important data type in Python, that's used to represent strings. Not surprisingly, it is in fact named <code class=\"language-text\">str</code>!</p>\n<p>Let's look at valid string representations.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello World\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">'Hello World'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">'Hello World\"      File \"&lt;stdin>\", line 1        message = '</span>Hello World\"                          <span class=\"token operator\">^</span>     SyntaxError<span class=\"token punctuation\">:</span> EOL <span class=\"token keyword\">while</span> scanning string literal</code></pre></div>\n<p>In Python, you can use either ```<code class=\"language-text\">or</code>\"\"` to delimit string values.</p>\n<p><code class=\"language-text\">type()</code> method can be used to find type of a variable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello World\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span>    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'str'</span><span class=\"token operator\">></span></code></pre></div>\n<p>The <code class=\"language-text\">str</code> <code class=\"language-text\">class</code> provides a lot of utility methods.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'HELLO WORLD'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'hello world'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span></code></pre></div>\n<p><code class=\"language-text\">message.capitalize()</code> does init caps. Only first character is changed to uppercase.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"hello\"</span><span class=\"token punctuation\">.</span>capitalize<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'Hello'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">.</span>capitalize<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'Hello'</span></code></pre></div>\n<p>You can also run this directly - <code class=\"language-text\">'hello'.capitalize()</code>. Isn't that cool!</p>\n<p>That's because each piece of text in python is an object of the <code class=\"language-text\">str</code> <code class=\"language-text\">class</code>, and we can directly call methods of that <code class=\"language-text\">class</code> on <code class=\"language-text\">str</code> objects.</p>\n<p>Now let's shift our attention to methods, which gives us more information about the specific contents of a string.</p>\n<ul>\n<li>We want to find out if this string contains numeric values?</li>\n<li>Does it contain alphabets only?</li>\n<li>Does it contain alpha-numeric values?</li>\n<li>Is it lowercase?</li>\n<li>Is it uppercase?</li>\n</ul>\n<p>To find if a piece of text contains only lower case alphabets.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p>If the first letter is in uppercase, then <code class=\"language-text\">istitle()</code> will return a <code class=\"language-text\">True</code> value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p>To find if a piece of text contains only upper case alphabets.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'HELLO'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">isdigit()</code> checks if a string is a numeric value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'123'</span><span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'A23'</span><span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'2 3'</span><span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'23'</span><span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">isalpha()</code> checks if a string only contains alphabets.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'23'</span><span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'2A'</span><span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ABC'</span><span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">isalnum()</code> checks if a string only contains alphabets and/or numerals.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ABC123'</span><span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ABC 123'</span><span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p>Lastly, we look at things which you can use, to check characters of a string.</p>\n<p><code class=\"language-text\">endswith</code> is self explanatory.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'World'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'ld'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'old'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Wo'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p><code class=\"language-text\">startswith</code> is self explanatory as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Wo'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'He'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hell0'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">find</code> method returns if a piece of text is present in another string. Returns the first match index.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">0</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'ello'</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">1</span></code></pre></div>\n<p>A value of <code class=\"language-text\">-1</code> is returned, if you're searching for something which is not present in the string.</p>\n<p>If you are searching for <code class=\"language-text\">'Ello'</code> with a capital <code class=\"language-text\">'E'</code> ,you'll not be able to find it. Search is case sensitive.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'Ello'</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">-</span><span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'bello'</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">-</span><span class=\"token number\">1</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'Ello'</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">-</span><span class=\"token number\">1</span></code></pre></div>\n<h4>Step 02: Type Conversion Puzzles <a id=\"step-02-type-conversion-puzzles\"></h4>\n</a>\n<p>We'll now try and convert values from one type to another, and try and play around with them.</p>\n<p><code class=\"language-text\">str</code> converts boolean value to a text value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'True'</span></code></pre></div>\n<p>All text value except for empty string represent True. So, <code class=\"language-text\">bool</code> returns True for everything except empty string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'True'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'true'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tru'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'false'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'False'</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p>Let's try and convert a few integer values to strings.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">123</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'123'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">12345</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'12345'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">12345.45678</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'12345.45678'</span></code></pre></div>\n<p>Let's do the reverse.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'45'</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">45</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'45.56'</span><span class=\"token punctuation\">)</span>    ValueError<span class=\"token punctuation\">:</span> invalid literal <span class=\"token keyword\">for</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>if we do <code class=\"language-text\">int('45.56')</code>, you can see that it throws an error. It says \"I cannot convert this to an <code class=\"language-text\">int</code>, as <code class=\"language-text\">45.56</code> is an invalid integer\".</p>\n<p>You can also pass an additional parameter to <code class=\"language-text\">int</code> indicating the numeric system - 16 for Hexa decimal, 8 for Octal etc. Default is 10 - Decimal.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'45abc'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">285372</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">10</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">11</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">12</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">15</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'g'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>    ValueError<span class=\"token punctuation\">:</span> invalid literal <span class=\"token keyword\">for</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">with</span> base <span class=\"token number\">16</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'g'</span></code></pre></div>\n<p>You can also convert string to float.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"34.43\"</span><span class=\"token punctuation\">)</span>    <span class=\"token number\">34.43</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"34.43rer\"</span><span class=\"token punctuation\">)</span>    ValueError<span class=\"token punctuation\">:</span> could <span class=\"token keyword\">not</span> convert string to <span class=\"token builtin\">float</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'34.43rer'</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this quick step, we looked at converting different types to strings, and converting strings to different types. So we looked at <code class=\"language-text\">int</code>, <code class=\"language-text\">bool</code> and <code class=\"language-text\">float</code> values, and we looked at how to convert them to string, and how to convert strings back to these specific types.</p>\n<h4>Step 02: Strings Are Immutable <a id=\"step-02-strings-are-immutable\"></h4>\n</a>\n<p>In this step, let's learn an important fact about strings in Python.</p>\n<p>String values are immutable.</p>\n<p>What does immutability mean, and why do we say strings are immutable?</p>\n<p>Let's create a very simple string: <code class=\"language-text\">message = 'Hello'</code>, and we're saying <code class=\"language-text\">message.upper()</code>. But what does it do? It prints <code class=\"language-text\">'HELLO'</code>, with all characters in uppercase. Well, what would happen if you do <code class=\"language-text\">print(message)</code>? It says <code class=\"language-text\">'Hello'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token string\">'HELLO'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message    <span class=\"token string\">'Hello'</span></code></pre></div>\n<p>You would see we tried change the content of message, but it has not changed.</p>\n<p>When we execute <code class=\"language-text\">message.upper()</code>, a new string is created, and it is returned back. Original string remained unchanged. This is called immutability.</p>\n<p>Once you define a string in Python, you'll not be able to change the value of it.</p>\n<p>You can use - \"OK. I can do something of this kind: <code class=\"language-text\">message = message.upper()</code>\".</p>\n<p>What would happen now?</p>\n<p>Will the value of <code class=\"language-text\">message</code> get changed? It prints <code class=\"language-text\">'HELLO'</code>, with all caps.</p>\n<p>Did the value of <code class=\"language-text\">message</code> change? Does this prove that strings are mutable?</p>\n<p>The important thing you need to understand about all this stuff, is how objects are stored inside Python.</p>\n<p>There are things called variables, and there are things called objects.</p>\n<p>When we run <code class=\"language-text\">message = 'Hello'</code></p>\n<ul>\n<li>We are creating one object of <code class=\"language-text\">str</code> class with a values <code class=\"language-text\">'Hello'</code>.</li>\n<li>We are creating one variable called <code class=\"language-text\">message</code></li>\n<li>The location of <code class=\"language-text\">'Hello'</code> is stored into <code class=\"language-text\">message</code></li>\n</ul>\n<p>In Python, your variables are nothing but a name.</p>\n<p>If location of <code class=\"language-text\">'Hello'</code> in memory is <code class=\"language-text\">A</code>, then the value stored in <code class=\"language-text\">message</code> is <code class=\"language-text\">A</code>. <code class=\"language-text\">message</code> is called a reference.</p>\n<p>What happens with <code class=\"language-text\">message = message.upper()</code>?</p>\n<p>A new object is created with value <code class=\"language-text\">'HELLO'</code> at a different location <code class=\"language-text\">B</code>.</p>\n<p>A reference ot location <code class=\"language-text\">B</code> is stored into <code class=\"language-text\">message</code> variable.</p>\n<p>Summary : The original value at location <code class=\"language-text\">A</code> has not changed and cannot be changed for <code class=\"language-text\">str</code> variables. Hence 'str' objects are immutable.</p>\n<p>Variables are just names referring to a location. They don't really contain the value. Variables contain a reference to the location that contains the object.</p>\n<h4>Step 03: Python Has No Separate Character Type <a id=\"step-03-python-has-no-separate-character-type\"></h4>\n</a>\n<p>One of the things that surprises people new to Python, is that there is no character data type in Python.</p>\n<p>Typically we have text data types in all the languages, don't we? <code class=\"language-text\">'Hello World'</code> for example, is text data, and we stored it in <code class=\"language-text\">message</code>. This is called a string.</p>\n<p>In other languages, you would have something to represent a single character symbol. For example in Java, you can have a <code class=\"language-text\">char</code> data type, to store a single character <code class=\"language-text\">ch</code>, in which <code class=\"language-text\">'h'</code> is one character. But in Python, there is no separate data type to store single characters.</p>\n<p>For example, let's see how Python treats the first character of the following string <code class=\"language-text\">message</code>. The way you can access the first character of a string is by saying <code class=\"language-text\">message[0]</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello World\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>    <span class=\"token string\">'H'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'str'</span><span class=\"token operator\">></span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span>    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'str'</span><span class=\"token operator\">></span></code></pre></div>\n<p><code class=\"language-text\">type(message[0])</code> and <code class=\"language-text\">type(message)</code> print the same type <code class=\"language-text\">str</code>. No difference.</p>\n<p>In Python, whether you're talking about a string, or you're talking about a single character symbol, they are all represented by the same <code class=\"language-text\">class</code>, <code class=\"language-text\">str</code>.</p>\n<p><code class=\"language-text\">message[100]</code> throws an <code class=\"language-text\">IndexError</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>    <span class=\"token string\">'H'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>    <span class=\"token string\">'e'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span>    <span class=\"token string\">'l'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>    <span class=\"token string\">'l'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">100</span><span class=\"token punctuation\">]</span>    IndexError<span class=\"token punctuation\">:</span> string index out of <span class=\"token builtin\">range</span></code></pre></div>\n<p>It says: \"The given index is out of the range of the value of that specific string\".</p>\n<p>Let's say we would want to print all the characters in this string.</p>\n<p>The way you could do that, is by saying: <code class=\"language-text\">for ch in message: print(ch)</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this short step, we looked at the fact that there is no separate character class, or data type in Python. We also looked at how do we loop over a given string, and print all the characters present inside this string.</p>\n<h4>Step 04: The <code class=\"language-text\">string</code> <code class=\"language-text\">module</code> <a id=\"step-04-the-string-module\"></h4>\n</a>\n<p>In this step, we will introduce you to the <code class=\"language-text\">string</code> <code class=\"language-text\">module</code>.</p>\n<p>If we would want to use anything from a module in Python, you need to import that specific <code class=\"language-text\">module</code> into your program.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> string</code></pre></div>\n<p>If you do a <code class=\"language-text\">string.</code> and press , it would show the different things which are part of the <code class=\"language-text\">string</code> <code class=\"language-text\">module</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>    string<span class=\"token punctuation\">.</span>Formatter<span class=\"token punctuation\">(</span>       string<span class=\"token punctuation\">.</span>ascii_uppercase  string<span class=\"token punctuation\">.</span>octdigits    string<span class=\"token punctuation\">.</span>Template<span class=\"token punctuation\">(</span>        string<span class=\"token punctuation\">.</span>capwords<span class=\"token punctuation\">(</span>        string<span class=\"token punctuation\">.</span>printable    string<span class=\"token punctuation\">.</span>ascii_letters    string<span class=\"token punctuation\">.</span>digits           string<span class=\"token punctuation\">.</span>punctuation    string<span class=\"token punctuation\">.</span>ascii_lowercase  string<span class=\"token punctuation\">.</span>hexdigits        string<span class=\"token punctuation\">.</span>whitespace</code></pre></div>\n<p>Let's explore some of these.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_letters    <span class=\"token string\">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_lowercase    <span class=\"token string\">'abcdefghijklmnopqrstuvwxyz'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_uppercase    <span class=\"token string\">'ABCDEFGHIJKLMNOPQRSTUVWXYZ'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>digits    <span class=\"token string\">'0123456789'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>hexdigits    <span class=\"token string\">'0123456789abcdefABCDEF'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>punctuation    <span class=\"token string\">'!\"#$%&amp;\\'()*+,-./:;&lt;=>?@[\\\\]^_`{|}~'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_letters    <span class=\"token string\">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'</span></code></pre></div>\n<p>You have a set of printable characters, punctuation characters and a lot more.</p>\n<p>You can check a text value against any of these</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'a'</span> <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_letters    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ab'</span> <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_letters    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'abc'</span> <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_letters    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">in</code> operation on a string, checks if a given string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'1'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'13579'</span>    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'2'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'13579'</span>    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'4'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'13579'</span>    <span class=\"token boolean\">False</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we explored more exercises involving the <code class=\"language-text\">str</code> module of Python.</p>\n<h4>Step 05: More Exercises With The <code class=\"language-text\">str</code> Module <a id=\"step-05-more-exercises-with-the-str-module\"></h4>\n</a>\n<p>Let's start with an Exercise - find if a specific character is a vowel or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token operator\">=</span> <span class=\"token string\">'a'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> vowel_string <span class=\"token operator\">=</span> <span class=\"token string\">'aeiouAEIOU'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token keyword\">in</span> vowel_string    <span class=\"token boolean\">True</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token operator\">=</span> <span class=\"token string\">'b'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token keyword\">in</span> vowel_string    <span class=\"token boolean\">False</span></code></pre></div>\n<p>he other thing you can do, is just have the capital vowels, or just the lowercase versions.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> vowel_string <span class=\"token operator\">=</span> <span class=\"token string\">'AEIOU'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> vowel_string    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token operator\">=</span> <span class=\"token string\">'a'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> vowel_string    <span class=\"token boolean\">True</span></code></pre></div>\n<p>Now let's move on to the next one.</p>\n<p>We want to find out and print all the capital alphabets, from <code class=\"language-text\">A</code> to <code class=\"language-text\">Z</code>.</p>\n<p>There was a small clue at the start of the previous step, regarding importing the <code class=\"language-text\">string</code> <code class=\"language-text\">module</code>. We did the <code class=\"language-text\">string</code> <code class=\"language-text\">module</code>, and we saw that <code class=\"language-text\">string</code> <code class=\"language-text\">module</code> contained a number of things.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_uppercase    <span class=\"token string\">'ABCDEFGHIJKLMNOPQRSTUVWXYZ'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_uppercase<span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    A    B    C    D    E    F    G    H    I    J    K    L    M    N    O    P    Q    R    S    T    U    V    W    X    Y    Z</code></pre></div>\n<p>Try another easy exercise: print all the lower characters. Instead of <code class=\"language-text\">string.ascii_uppercase</code>, you have <code class=\"language-text\">string.ascii_lowercase</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_lowercase<span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z</code></pre></div>\n<p>An even easier exercise, would be to print all the digits.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>    string<span class=\"token punctuation\">.</span>Formatter<span class=\"token punctuation\">(</span>       string<span class=\"token punctuation\">.</span>ascii_uppercase  string<span class=\"token punctuation\">.</span>octdigits    string<span class=\"token punctuation\">.</span>Template<span class=\"token punctuation\">(</span>        string<span class=\"token punctuation\">.</span>capwords<span class=\"token punctuation\">(</span>        string<span class=\"token punctuation\">.</span>printable    string<span class=\"token punctuation\">.</span>ascii_letters    string<span class=\"token punctuation\">.</span>digits           string<span class=\"token punctuation\">.</span>punctuation    string<span class=\"token punctuation\">.</span>ascii_lowercase  string<span class=\"token punctuation\">.</span>hexdigits        string<span class=\"token punctuation\">.</span>whitespace    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>digits<span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">0</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token number\">6</span>    <span class=\"token number\">7</span>    <span class=\"token number\">8</span>    <span class=\"token number\">9</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>The last exercise which we want to leave you with, is to check if something is a consonant.</p>\n<p>A consonant is an alphabet which is not a vowel, so any alphabet which is not in <code class=\"language-text\">'aeiou'</code> is a consonant. The simplest way of doing this is to say <code class=\"language-text\">consonant_string = 'bcdfghj...'</code> and so on. Looks like a very long solution? There is an easier way out.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> vowel_string <span class=\"token operator\">=</span> <span class=\"token string\">'aeiou'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token operator\">=</span> <span class=\"token string\">'b'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char<span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> char<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> vowel_string    <span class=\"token boolean\">True</span></code></pre></div>\n<h4>Step 06: More Exercises On Strings <a id=\"step-06-more-exercises-on-strings\"></h4>\n</a>\n<p>In the step, let's look at a few more puzzles and exercises related to strings. Let's say we have a simple string, <code class=\"language-text\">string_example</code>, and this is contains an English sentence. <code class=\"language-text\">'This is a great thing.'</code></p>\n<p>Let's try to to print each of the words present in this string, on a separate line.</p>\n<p>So we would want to print <code class=\"language-text\">'This'</code>, <code class=\"language-text\">'is'</code>, <code class=\"language-text\">'a'</code>, <code class=\"language-text\">'great'</code> and <code class=\"language-text\">'thing'</code> on individual lines.</p>\n<p>One of the clues we'll give you is, try and do <code class=\"language-text\">string_example. &lt;TAB></code>. There are a huge list of methods, which would come up if you do that.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example <span class=\"token operator\">=</span> <span class=\"token string\">\"This is a great thing\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example<span class=\"token punctuation\">.</span>    string_example<span class=\"token punctuation\">.</span>capitalize<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>casefold<span class=\"token punctuation\">(</span>      string_example<span class=\"token punctuation\">.</span>ljust<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>center<span class=\"token punctuation\">(</span>        string_example<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>         string_example<span class=\"token punctuation\">.</span>lstrip<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>encode<span class=\"token punctuation\">(</span>        string_example<span class=\"token punctuation\">.</span>maketrans<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span>      string_example<span class=\"token punctuation\">.</span>partition<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>expandtabs<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>replace<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span>          string_example<span class=\"token punctuation\">.</span>rfind<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>        string_example<span class=\"token punctuation\">.</span>rindex<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>format_map<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span>         string_example<span class=\"token punctuation\">.</span>rpartition<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>rsplit<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>rstrip<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isdecimal<span class=\"token punctuation\">(</span>     string_example<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>splitlines<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isidentifier<span class=\"token punctuation\">(</span>  string_example<span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isnumeric<span class=\"token punctuation\">(</span>     string_example<span class=\"token punctuation\">.</span>swapcase<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isprintable<span class=\"token punctuation\">(</span>   string_example<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isspace<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>translate<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>zfill<span class=\"token punctuation\">(</span></code></pre></div>\n<p>One of the methods in the list is the <code class=\"language-text\">split()</code> method.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">[</span><span class=\"token string\">'This'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'great'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'thing'</span><span class=\"token punctuation\">]</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> word <span class=\"token keyword\">in</span> string_example<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    This    <span class=\"token keyword\">is</span>    a    great    thing</code></pre></div>\n<p><code class=\"language-text\">split_lines()</code> method looks for a <code class=\"language-text\">'\\n'</code>, and it divides the string based on it. If you have a string which contains newlines, and you would want to divide it into a number of strings with each line as a new element, the method you can use is <code class=\"language-text\">split_lines()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example <span class=\"token operator\">=</span> <span class=\"token string\">\"This\\nis\\n\\ngreat\\nthing\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>string_example<span class=\"token punctuation\">)</span>    This    <span class=\"token keyword\">is</span>​    great    thing    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example <span class=\"token operator\">=</span> <span class=\"token string\">\"This\\nis\\na\\ngreat\\nthing\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>string_example<span class=\"token punctuation\">)</span>    This    <span class=\"token keyword\">is</span>    a    great    thing    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example<span class=\"token punctuation\">.</span>splitlines<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">[</span><span class=\"token string\">'This'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'great'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'thing'</span><span class=\"token punctuation\">]</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>The last thing which we look at, is <strong>concatenation operator</strong>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"1\"</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"2\"</span>    <span class=\"token string\">'12'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"1\"</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span>    TypeError<span class=\"token punctuation\">:</span> must be <span class=\"token builtin\">str</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">not</span> <span class=\"token builtin\">int</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"ABC\"</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"DEF\"</span>    <span class=\"token string\">'ABCDEF'</span></code></pre></div>\n<p>In Python, you cannot do <code class=\"language-text\">+</code> operator between two different types. <code class=\"language-text\">+</code> with two strings is concatenation. <code class=\"language-text\">+</code> with two numbers is addition.</p>\n<p>One other interesting operator on strings is multiplication. If you do a <code class=\"language-text\">'1' * 20</code>, What do you think will be the output?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">*</span> <span class=\"token number\">20</span>    <span class=\"token number\">20</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'1'</span> <span class=\"token operator\">*</span> <span class=\"token number\">20</span>    <span class=\"token string\">'11111111111111111111'</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'A'</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span>    <span class=\"token string\">'AAAAAAAAAA'</span></code></pre></div>\n<p>If you multiply a string with <code class=\"language-text\">number</code>, the string value is concatenated <code class=\"language-text\">number</code> times.</p>\n<p>The last thing which we look at in this step, is comparing strings.</p>\n<p>Let's say we have a string with a value <code class=\"language-text\">str = 'test'</code>, and you have another string to with a value <code class=\"language-text\">str1 = 'test1'</code>.</p>\n<p>We want to check whether both these strings are the same.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"test\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> str2 <span class=\"token operator\">=</span> <span class=\"token string\">\"test1\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span> <span class=\"token operator\">==</span> str2    <span class=\"token boolean\">False</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> str2 <span class=\"token operator\">=</span> <span class=\"token string\">\"test\"</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span> <span class=\"token operator\">==</span> str2    <span class=\"token boolean\">True</span></code></pre></div>\n<p>You can compare strings using the <code class=\"language-text\">==</code> operator.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we explored a few exercises on strings, covering areas such as:</p>\n<ul>\n<li>Splitting a given sentence into individual words</li>\n<li>The concatenation operator, <code class=\"language-text\">+</code></li>\n<li>The string multiplication pattern, <code class=\"language-text\">*</code></li>\n<li>The use of the <code class=\"language-text\">==</code> operator to compare strings</li>\n</ul>\n<h3>Chapter 07 - Introducing Loops <a id=\"chapter-07-introducing-loops\"></h3>\n</a>\n<p>Welcome to the section on Loops. In this section, we will look at a variety of loops that are available in Python. We will look mainly at the <strong><code class=\"language-text\">for</code></strong> loop, and the <strong><code class=\"language-text\">while</code></strong> loop.</p>\n<h4>Step 01: Revisited: The for Loop <a id=\"step-01-revisited-the-for-loop\"></h4>\n</a>\n<p>Let's start with revising the basics of the for loop, we have learned in the previous steps.</p>\n<p>We saw that a <code class=\"language-text\">for</code> loop helps us to loop around the same set of code statements, many times over.</p>\n<p>Let's look at a few simple examples, once again.</p>\n<p><strong>Snippet-01</strong></p>\n<p>The syntax of a <code class=\"language-text\">for</code> loop is very simple.</p>\n<p>For example, this code snippet will tell you all about it: <code class=\"language-text\">for i in range(1, 11): print(i)</code>.</p>\n<p>What does this do? Very simple, it prints from <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code>.</p>\n<p>In the call to the <code class=\"language-text\">range()</code> function, the second parameter is exclusive. We are actually looping from <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code>, and this piece of code, <code class=\"language-text\">print(i)</code>, is being executed for different values of <code class=\"language-text\">i</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span>    <span class=\"token number\">6</span>    <span class=\"token number\">7</span>    <span class=\"token number\">8</span>    <span class=\"token number\">9</span>    <span class=\"token number\">10</span></code></pre></div>\n<p><code class=\"language-text\">for</code> loop can also be used to loop round the characters in a string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> ch <span class=\"token keyword\">in</span> <span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>ch<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    H    e    l    l    o    W    o    r    l    d</code></pre></div>\n<p><code class=\"language-text\">for</code> loop can be used to loop around all the words in a given sentence.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> word <span class=\"token keyword\">in</span> <span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    Hello    World</code></pre></div>\n<p><code class=\"language-text\">for</code> loop can be used to loop around a specific list of values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">3</span>    <span class=\"token number\">6</span>    <span class=\"token number\">9</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we started with discussing and revising basic concepts about the <code class=\"language-text\">for</code> loop</p>\n<h4>Step 02: Programming Exercise PE-LO-01 <a id=\"step-02-programming-exercise-pe-lo-01\"></h4>\n</a>\n<p>Welcome back to this step, where we would do a lot of exercises with the <code class=\"language-text\">for</code> loop.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>\n<p>The first exercise is to find out if a number is prime. We want to write a method, <code class=\"language-text\">is_prime()</code>, which accepts an integer value as parameter, and returns whether it's a prime. (<strong>Hint</strong>: A prime number is something which is only divisible by <code class=\"language-text\">1</code> and itself).</p>\n<ol>\n<li><code class=\"language-text\">5</code> is only divisible by <code class=\"language-text\">1</code> and <code class=\"language-text\">5</code>. It is not divisible by any other number. Same is the case with <code class=\"language-text\">7</code> and <code class=\"language-text\">11</code>.</li>\n<li>However, <code class=\"language-text\">6</code> is divisible by <code class=\"language-text\">1</code>, <code class=\"language-text\">2</code>, <code class=\"language-text\">3</code> and <code class=\"language-text\">6</code>. So it's not a prime number.</li>\n</ol>\n</li>\n<li>The second exercise is to write a method to calculate the sum up to a given integer, starting from <code class=\"language-text\">1</code>. <strong>Hint</strong>: If I would want to find that the sum up to <code class=\"language-text\">6</code>. what's needed is <code class=\"language-text\">1 + 2 + 3 + 4 + 5 + 6</code>.</li>\n<li>The third exercise is to find that the sum of divisors of a given integer. <strong>Hint</strong>: Let's say we want to find out the sum of the divisors of <code class=\"language-text\">15</code>. The divisors of <code class=\"language-text\">15</code> are <code class=\"language-text\">1</code>, <code class=\"language-text\">3</code>, <code class=\"language-text\">5</code> and <code class=\"language-text\">15</code>. So I would want to calculate <code class=\"language-text\">1 + 3 + 5 + 15</code>, and return that value.</li>\n<li>Fourth exercise is to print a numbered triangle, when given a specific integer.</li>\n</ol>\n<p>Hint: Given an input <code class=\"language-text\">5</code>, we would want to print the number triangle of these kind:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">11</span> <span class=\"token number\">21</span> <span class=\"token number\">2</span> <span class=\"token number\">31</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">41</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5.</span></code></pre></div>\n<p>These are the exercises for the <code class=\"language-text\">for</code> loop. We also test our skills, with creating method and executing them, in our IDE.</p>\n<p><strong>Solution 1</strong></p>\n<p>Let's start with creating the <code class=\"language-text\">is_prime()</code> method, in a file named <code class=\"language-text\">for_exercises</code>.</p>\n<p>We would want to accept an <code class=\"language-text\">int</code> parameter, and find out if it is prime, or not.</p>\n<p>We need to check whether it's divisible by any other number, other than <code class=\"language-text\">1</code> and itself. If we are passed in a value of <code class=\"language-text\">5</code>, you want to see if it's divisible by any of <code class=\"language-text\">2</code>, <code class=\"language-text\">3</code> or <code class=\"language-text\">4</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">is_prime</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span></code></pre></div>\n<p>We can use a <code class=\"language-text\">for</code> loop. We can structure it like this: <code class=\"language-text\">for divisor in range(1, number): ...</code>. We would not want to divide it with <code class=\"language-text\">1</code>, but start with <code class=\"language-text\">2</code> instead, and go up to <code class=\"language-text\">number-1</code>, which is <code class=\"language-text\">4</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span></code></pre></div>\n<p>How can we check if the <code class=\"language-text\">number</code> is divisible by <code class=\"language-text\">divisor</code>?</p>\n<p>By using the <code class=\"language-text\">%</code> operator. If <code class=\"language-text\">number</code> is divisible by <code class=\"language-text\">divisor</code> we return <code class=\"language-text\">False</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">if</span> number <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>What happens if the code comes up to the end? It would mean we tried with <code class=\"language-text\">2</code>, <code class=\"language-text\">3</code> and <code class=\"language-text\">4</code>, but <code class=\"language-text\">number</code> was not divisible by all of them. In that case, <code class=\"language-text\">number</code> would be prime, and we can safely return <code class=\"language-text\">True</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">if</span> number <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>​<span class=\"token keyword\">return</span> <span class=\"token boolean\">True</span></code></pre></div>\n<p>For <code class=\"language-text\">1</code>, the rules are a little different, as it is neither a prime or composite. We will add an <code class=\"language-text\">if</code> condition to check if the number is <code class=\"language-text\">1</code>. <code class=\"language-text\">if(number &lt; 2):</code></p>\n<p>This <code class=\"language-text\">if</code> condition is called a guard check or a boundary check, to make sure that you are processing only the right input. If <code class=\"language-text\">number</code> has a value less than <code class=\"language-text\">2</code>, do nothing. OK, it's not a prime.</p>\n<p>Here is the entire code at one place, for your reference:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">is_prime</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>number <span class=\"token operator\">&lt;</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>    <span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">if</span> number <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>            <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>    <span class=\"token keyword\">return</span> Trueprint<span class=\"token punctuation\">(</span>is_prime<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h4>Step 03: Continued - Programming Exercise PE-LO-01 <a id=\"step-03-continued-programming-exercise-pe-lo-01\"></h4>\n</a>\n<p>In the previous step, we looked at solving the <code class=\"language-text\">is_prime()</code> exercise. In this step, let's look at an implementation of <code class=\"language-text\">sum_up_to_n()</code>. Here is the entire code for this exercise:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum_upto_n</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">+</span> i    <span class=\"token keyword\">return</span> sumprint<span class=\"token punctuation\">(</span>sum_upto_n<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>sum_upto_n<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Wrote a Python function to compute the sum of all integers, from <code class=\"language-text\">1</code>, up to the input integer <code class=\"language-text\">n</code>.</li>\n</ul>\n<h4>Step 04: Continued - Programming Exercise PE-LO-01 <a id=\"step-04-continued-programming-exercise-pe-lo-01\"></h4>\n</a>\n<p>Let's focus on the third exercise, <code class=\"language-text\">sum_of_divisors</code>.</p>\n<p>One of the clues we can give you, is that <code class=\"language-text\">sum_of_divisors()</code> is very similar to <code class=\"language-text\">is_prime()</code>.</p>\n<p>You want to find out if a number is dividing <code class=\"language-text\">15</code>, and if it's dividing <code class=\"language-text\">15</code>, with the remainder of <code class=\"language-text\">0</code>, then you need to add that up.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">calculate_sum_of_divisors</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span>    <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>number <span class=\"token operator\">&lt;</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span>    <span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">if</span> number <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>            <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">+</span> divisor    <span class=\"token keyword\">return</span> sumprint<span class=\"token punctuation\">(</span>calculate_sum_of_divisors<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculate_sum_of_divisors<span class=\"token punctuation\">(</span><span class=\"token number\">15</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h4>Step 05: Continued - Programming Exercise PE-LO-01 <a id=\"step-05-continued-programming-exercise-pe-lo-01\"></h4>\n</a>\n<p>In this step, Let's look at the last exercise - <code class=\"language-text\">print_a_number_triangle</code>.</p>\n<p>For example, if we call such a function with input <code class=\"language-text\">5</code>, the output needs to be:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>​<span class=\"token number\">1</span> <span class=\"token number\">2</span>​<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>​<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span>​<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span></code></pre></div>\n<p>Let start with a simple thing. Let's try and print <code class=\"language-text\">1 2 3 4 5</code> first, and then we would look at how to print the rest of the output. Lets proceed with defining this method.</p>\n<p>We can say <code class=\"language-text\">def print_a_number_triangle(number): ...</code> that takes a number as an input. You want to print a sequence of integers starting from <code class=\"language-text\">1</code>, up to that specific <code class=\"language-text\">number</code>. How can you do that? Let's try this: <code class=\"language-text\">for i in range(1,number+1): print(i)</code> What would happen? Let's call <code class=\"language-text\">print_a_number_triangle(5)</code> now. It prints:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span>    <span class=\"token number\">5</span></code></pre></div>\n<p>on individual lines.</p>\n<p>To print this sequence on a single line, let's delimit them with <code class=\"language-text\">&lt;SPACE></code> instead. Call <code class=\"language-text\">print()</code> like this instead: <code class=\"language-text\">for i in range(1,number+1): print(i, end=\" \")</code>.</p>\n<p>Let's see what would happen now. <code class=\"language-text\">1 2 3 4 5</code></p>\n<p>To solve our exercise, we want to repeat this again and again.</p>\n<p>Yes, we need another for loop around it!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> j <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Make sure that you have the indentation right. This is called <code class=\"language-text\">loop within a loop</code>.</p>\n<p>The output of above program is</p>\n<p><code class=\"language-text\">1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5</code></p>\n<p>Let's add <code class=\"language-text\">print(\"\\n\")</code>, so we have a new line at the end of each outer loop iteration.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> j <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Output</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">51</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">51</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">51</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">51</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span></code></pre></div>\n<p>We are printing a square, not a triangle.</p>\n<p>What we want to do is to print up to <code class=\"language-text\">1</code> in first line, upto <code class=\"language-text\">2</code> in second line and so on.</p>\n<p>How can we do that? Think about it.</p>\n<p>When you are inside this loop, you can see the variable <code class=\"language-text\">j</code>.</p>\n<p>Instead of <code class=\"language-text\">number+1</code>, let's say <code class=\"language-text\">j + 1</code>.</p>\n<p>When <code class=\"language-text\">j</code> has a value of <code class=\"language-text\">1</code>, <code class=\"language-text\">for</code> will print from <code class=\"language-text\">1</code> to <code class=\"language-text\">1</code>. When <code class=\"language-text\">j</code> has a value of <code class=\"language-text\">2</code>, print from <code class=\"language-text\">1</code> to <code class=\"language-text\">2</code>, literally printing <code class=\"language-text\">1 2</code>. When j has a value of <code class=\"language-text\">3</code>, I'll print from <code class=\"language-text\">1</code> to <code class=\"language-text\">3</code>. Let's try this and see what would happen.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> j <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can see that our number triangle is ready!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>​<span class=\"token number\">1</span> <span class=\"token number\">2</span>​<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>​<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span>​<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span></code></pre></div>\n<p>Here is the entire code for you:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">print_a_number_triangle</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    <span class=\"token keyword\">for</span> j <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>        <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>            <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>print_a_number_triangle<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>An important point to note is, a couple of these things can be done in a much simpler way. We will look at these options when we talk about functional programming.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Presented a solution to the exercise for printing a number triangle.</li>\n</ul>\n<h4>Step 06: Introducing The while Loop <a id=\"step-06-introducing-the-while-loop\"></h4>\n</a>\n<p>Let's look at one of the other loops which is present in Python, called the <strong><code class=\"language-text\">while</code></strong> loop.</p>\n<p>In the <code class=\"language-text\">for</code> loop, we can specify the range of our iteration, by using the <code class=\"language-text\">range()</code> function.</p>\n<p>In a <code class=\"language-text\">while</code> loop, we specify a logical condition. While the condition is true, loop continues running.</p>\n<p>Do you remember one place where we use the condition until now? It was in an <code class=\"language-text\">if</code> statement.</p>\n<p>Let's see how to use a simple <code class=\"language-text\">while</code> loop.</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">5</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i <span class=\"token operator\">==</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is 5\"</span><span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    i <span class=\"token keyword\">is</span> <span class=\"token number\">5</span></code></pre></div>\n<p>Let's say <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">0</code>, and we then do: <code class=\"language-text\">while i &lt; 5: print(i)</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span>    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">while</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">0</span>    <span class=\"token number\">0</span>    <span class=\"token number\">0</span>    <span class=\"token number\">0</span>    <span class=\"token number\">0</span>    <span class=\"token number\">0</span>    <span class=\"token number\">0</span>    <span class=\"token number\">0</span>    <span class=\"token operator\">^</span>CTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>    KeyboardInterrupt    <span class=\"token operator\">>></span><span class=\"token operator\">></span>    KeyboardInterrupt</code></pre></div>\n<p>If we leave it to run, you'd see that it continuously prints <code class=\"language-text\">0</code> again, and again. Let's do a <code class=\"language-text\">&lt;CTRL-C></code> or <code class=\"language-text\">&lt;COMMAND-C></code> to interrupt this.</p>\n<p>What is happening here?</p>\n<p>Initially <code class=\"language-text\">i</code> is <code class=\"language-text\">0</code>, and the condition <code class=\"language-text\">i &lt; 5</code> is <code class=\"language-text\">True</code>, and <code class=\"language-text\">print(i)</code> is executed. Next iteration, it checks the condition, it is <code class=\"language-text\">True</code>, and <code class=\"language-text\">0</code> is printed. This continues to happen. What's happening is an <strong>infinite loop</strong>.</p>\n<p>One of the important things to make sure in a <code class=\"language-text\">while</code> loop, is to increment the value of <code class=\"language-text\">i</code>. We need to say something like <code class=\"language-text\">i = i + 1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">while</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">0</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span></code></pre></div>\n<p>So how does it work? *<code class=\"language-text\">i</code> initially had a value of <code class=\"language-text\">0</code>. First the condition is checked. It's <code class=\"language-text\">True</code>, so <code class=\"language-text\">0</code> is printed and then the value of <code class=\"language-text\">i</code> is incremented to <code class=\"language-text\">1</code>.</p>\n<ul>\n<li><code class=\"language-text\">i</code> is still less than <code class=\"language-text\">5</code>, so the loop continues to execute, and this happens until <code class=\"language-text\">4</code> is printed. <code class=\"language-text\">i</code> again gets incremented to <code class=\"language-text\">4 + 1</code>, or <code class=\"language-text\">5</code>.</li>\n<li>Then we check the condition <code class=\"language-text\">i &lt; 5</code>. This is now <code class=\"language-text\">False</code>. Control goes out of the <code class=\"language-text\">while</code> loop, and terminates it.</li>\n</ul>\n<p>When executing a <code class=\"language-text\">while</code>, control flow is just based on a condition. As long as the condition is <code class=\"language-text\">True</code>, we keep executing the code. An important thing to remember, is to make sure the control variable is updated.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token number\">0</span>    <span class=\"token number\">1</span>    <span class=\"token number\">2</span>    <span class=\"token number\">3</span>    <span class=\"token number\">4</span></code></pre></div>\n<p>A <code class=\"language-text\">for</code> loop is much simpler to code than a <code class=\"language-text\">while</code>. With <code class=\"language-text\">while</code>, we have to write an expression statement, to increment the value.</p>\n<p>The question you might have is - What are the situations when you should use a while?</p>\n<p>We will look at that very soon.</p>\n<p><strong>Summary</strong></p>\n<p>In this video, we:</p>\n<ul>\n<li>Were introduced to the concept of a <code class=\"language-text\">while</code> loop in Python</li>\n<li>Understood the importance of a control variable being incremented inside the loop</li>\n<li>Observed differences between the working of a <code class=\"language-text\">while</code>, and a <code class=\"language-text\">for</code> loop</li>\n</ul>\n<h4>Step 07: Programming Exercise PE-LO-02 <a id=\"step-07-programming-exercise-pe-lo-02\"></h4>\n</a>\n<p>In the previous step, we were introduced to <code class=\"language-text\">while</code> loop. In this step, let's look at a couple of exercises using the <code class=\"language-text\">while</code> loop.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li><code class=\"language-text\">print_squares_upto_limit(30)</code>: We need to print all the squares of numbers, up to a limit of <code class=\"language-text\">30</code>. The output needs to be <code class=\"language-text\">1 4 9 16 25</code>.</li>\n<li><code class=\"language-text\">print_cubes_upto_limit(30)</code>: We need to print all the cubes of numbers, up to a limit of <code class=\"language-text\">30</code>.The output needs to be 1 8 27.</li>\n</ol>\n<p><strong>Exercise 1: Solution</strong></p>\n<p>Here is the entire code for your reference:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">print_squares_upto_limit</span><span class=\"token punctuation\">(</span>limit<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>    <span class=\"token keyword\">while</span> i <span class=\"token operator\">*</span> i <span class=\"token operator\">&lt;</span> limit<span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> <span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span>        i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<p>Now the next exercise, was to print cubes up to a limit.</p>\n<p>The expression in the <code class=\"language-text\">while</code> condition should now be <code class=\"language-text\">i*i*i &lt; 30</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">print_cubes_upto_limit</span><span class=\"token punctuation\">(</span>limit<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>    i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>    <span class=\"token keyword\">while</span> i <span class=\"token operator\">*</span> i <span class=\"token operator\">*</span> i <span class=\"token operator\">&lt;</span> limit<span class=\"token punctuation\">:</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> <span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span>        i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> 1print_cubes_upto_limit<span class=\"token punctuation\">(</span><span class=\"token number\">80</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Could we have implemented above two examples with <code class=\"language-text\">for</code> loop? It would've been a little more difficult.</p>\n<p>Typically, we use a <code class=\"language-text\">for</code> loop when we know how many times the loop will be executed is clear at the start.</p>\n<p>If we do not know, how many times a loop will run, <code class=\"language-text\">while</code> is a better option.</p>\n<h4>Step 08: While Example <a id=\"step-08-while-example\"></h4>\n</a>\n<p>Earlier we used <code class=\"language-text\">if</code> statement to implement a solution for this:</p>\n<ul>\n<li>\n<p>Ask the User for input:</p>\n<ul>\n<li>Enter two numbers</li>\n<li>\n<p>Choose the Option:</p>\n<ul>\n<li>1 - Add</li>\n<li>2 - Subtract</li>\n<li>3 - Multiply</li>\n<li>4 - Divide</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Perform the Operation</li>\n<li>Publish the Result</li>\n</ul>\n<p>We would want to enhance it to execute in a loop multiple times, until the user chooses to exit. We will add an option 5 - Exit.</p>\n<ul>\n<li>\n<p>Ask the User for input:</p>\n<ul>\n<li>Enter two numbers</li>\n<li>\n<p>Choose the Option:</p>\n<ul>\n<li>1 - Add</li>\n<li>2 - Subtract</li>\n<li>3 - Multiply</li>\n<li>4 - Divide</li>\n<li>5 - Exit</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Perform the Operation</li>\n<li>Publish the Result</li>\n<li>Repeat until Option 5 is chosen.</li>\n</ul>\n<p><strong>Snippet-01 Explained</strong></p>\n<p>Here's the earlier code we wrote with if:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number1 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number1: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>number2 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number2: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>​<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\\n1 - Add\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"2 - Subtract\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"3 - Divide\"</span><span class=\"token punctuation\">)</span><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"4 - Multiply\"</span><span class=\"token punctuation\">)</span>​choice <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Choose Operation: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>​<span class=\"token comment\"># print(number1 + number2)# print(choice)if choice==1:    result = number1 + number2elif choice==2:    result = number1 - number2elif choice==3:    result = number1 / number2elif choice==4:    result = number1 * number2else:    result = \"Invalid Choice\"​print(result)</span></code></pre></div>\n<hr>\n<h2>README</h2>\n<p>[\n<img src=\"https://github.com/bgoonz/python-gitbook/raw/master/.gitbook/assets/image%20%2821%29.png\" alt=\"image\">](https://github.com/bgoonz/python-gitbook/blob/master/.gitbook/assets/image%20%2821%29.png)</p>\n<p>{% embed url=\"[https://replit.com/@bgoonz/30-days-python\\#01\\<em>Day\\</em>Introduction/helloworld.py](https://replit.com/@bgoonz/30-days-python%5C#01%5C<em>Day%5C</em>Introduction/helloworld.py)\" caption=\"30 days of python practice\" %}</p>\n<p>[\n<img src=\"https://github.com/bgoonz/python-gitbook/raw/master/.gitbook/assets/image%20%2822%29.png\" alt=\"image\">](https://github.com/bgoonz/python-gitbook/blob/master/.gitbook/assets/image%20%2822%29.png)</p>\n<p><strong>Understanding variables</strong></p>\n<p>Variables are simply declarations that are used to store certain values. For instance, the variable <code class=\"language-text\">name</code> can hold the value of <code class=\"language-text\">John Smith.</code> Several rules need to be considered when declaring variable names. For starters, a variable name cannot begin with a number.</p>\n<p><code class=\"language-text\">2name = incorrect #incorrect</code></p>\n<p><code class=\"language-text\">name = correct #correct</code></p>\n<p>Variable names are case sensitive. This means that the variable <code class=\"language-text\">school</code> is not the same as <code class=\"language-text\">School</code>.</p>\n<p>Variables can hold different data types. This includes strings, integers, Booleans, long, lists, and arrays.</p>\n<p>In Python, we do not need to declare the data type while writing a variable. This is because the code is compiled and interpreted later. The compiler will throw an error in case there is a mismatch in the data types.</p>\n<p>Let's talk about the different data types.</p>\n<ol>\n<li>Strings</li>\n</ol>\n<p>Strings are usually presented in a text format. We will declare a string variable, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">name <span class=\"token operator\">=</span> <span class=\"token string\">\"john\"</span>\nschool <span class=\"token operator\">=</span> <span class=\"token string\">\"Alliance Francaise\"</span></code></pre></div>\n<p>When we run <code class=\"language-text\">print(name)</code>, the output will be <code class=\"language-text\">john</code>.</p>\n<ol>\n<li>Integers</li>\n</ol>\n<p>These variables hold numeric values, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">math <span class=\"token operator\">=</span> <span class=\"token number\">90</span>\nchemistry <span class=\"token operator\">=</span> <span class=\"token number\">100</span>\nbiology <span class=\"token operator\">=</span> <span class=\"token number\">70</span></code></pre></div>\n<p>We can find the total of the variables above using the following statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>math<span class=\"token operator\">+</span>chemistry<span class=\"token operator\">+</span>biology<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The total is <code class=\"language-text\">260</code>.</p>\n<p>A TypeError is thrown when you try to add a string to an integer, as shwon below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">var1 <span class=\"token operator\">=</span> <span class=\"token string\">\"30\"</span> <span class=\"token comment\">#string</span>\nvar2 <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token comment\">#integer</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>var1<span class=\"token operator\">+</span>var2<span class=\"token punctuation\">)</span><span class=\"token comment\">#type error</span></code></pre></div>\n<p>We can sum <code class=\"language-text\">var1</code> and <code class=\"language-text\">var2</code> by converting <code class=\"language-text\">var1</code> to an integer using the <code class=\"language-text\">int()</code> function. The following code will execute successfully.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">var1 <span class=\"token operator\">=</span> <span class=\"token string\">\"30\"</span> <span class=\"token comment\">#string</span>\nvar2 <span class=\"token operator\">=</span> <span class=\"token number\">20</span> <span class=\"token comment\">#integer</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>var1<span class=\"token punctuation\">)</span><span class=\"token operator\">+</span>var2<span class=\"token punctuation\">)</span> <span class=\"token comment\"># Output: 50</span></code></pre></div>\n<blockquote>\n<p>Make sure that the variable stores a value that can be converted to an integer before using the int() method.</p>\n</blockquote>\n<ol>\n<li>Booleans</li>\n</ol>\n<p>There are only two Boolean values: <code class=\"language-text\">True</code> and <code class=\"language-text\">False</code>. In other words, something can either be true or false. We declare these values, as shown below. Please note that Python is case sensitive.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">isOn <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span>\nisChecked <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>A <code class=\"language-text\">bool()</code> method can help convert a value to a boolean. The code snippets below showcase how a <code class=\"language-text\">bool()</code> function can be used.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"abc\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">#returns True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>  <span class=\"token comment\">#returns False</span></code></pre></div>\n<p>The <code class=\"language-text\">bool()</code> function returns False when there are no parameters.</p>\n<ol>\n<li>Float</li>\n</ol>\n<p>This data type consists of numbers that have a decimal place. A perfect example of a float variable is highlighted below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Bmi <span class=\"token operator\">=</span> <span class=\"token number\">45.7</span></code></pre></div>\n<p><strong>Understanding lists</strong></p>\n<p>Lists allow us to store numerous elements in a particular variable. For instance, we can have a list that stores all the student names in a class. We use <code class=\"language-text\">[]</code> to define a list.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">students <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span> <span class=\"token comment\">#list example</span></code></pre></div>\n<p>Elements in a list are usually separated by a comma, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">students <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"john\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Mary Thomas\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"John Smith\"</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>Each element in the above <code class=\"language-text\">students</code> list has an index. By default, the first index is 0. So the item at index [0] is <code class=\"language-text\">john</code>, while the value at index <code class=\"language-text\">1</code> is <code class=\"language-text\">Mary Thomas</code>. A list of integers will look as follows.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">student_marks <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span> <span class=\"token number\">78</span><span class=\"token punctuation\">,</span> <span class=\"token number\">90</span><span class=\"token punctuation\">,</span> <span class=\"token number\">78</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>We can access different list functionalities using built-in functions. For instance, to add a value to the <code class=\"language-text\">student_marks</code> list, we use the <code class=\"language-text\">append</code> function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">student_marks<span class=\"token punctuation\">.</span>append<span class=\"token punctuation\">(</span><span class=\"token string\">\"Guardian Angel\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>student_marks<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The above function adds <code class=\"language-text\">Guardian Angel</code> at the end of the <code class=\"language-text\">student_marks</code> list.</p>\n<p>When we print the list it shows:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\">#output</span>\n<span class=\"token punctuation\">[</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span> <span class=\"token number\">78</span><span class=\"token punctuation\">,</span> <span class=\"token number\">90</span><span class=\"token punctuation\">,</span> <span class=\"token number\">78</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Guardian Angel'</span><span class=\"token punctuation\">]</span></code></pre></div>\n<p>We use <code class=\"language-text\">len(student_marks)</code> to determine the length of the list. We use the <code class=\"language-text\">remove()</code> function to delete something from the list. For instance, we can remove <code class=\"language-text\">90</code> from the <code class=\"language-text\">student_mark</code> list as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">student_marks<span class=\"token punctuation\">.</span>remove<span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>student_marks<span class=\"token punctuation\">)</span></code></pre></div>\n<p>In lists, negative indices allow us to count elements starting from the last one. For instance, the element with an index of <code class=\"language-text\">-1</code> in the above <code class=\"language-text\">student_marks</code> list is <code class=\"language-text\">\"Guardian Angel\"</code>. The second last element <code class=\"language-text\">78</code> has an index of <code class=\"language-text\">-2</code>.</p>\n<p><strong>Understanding functions or methods</strong></p>\n<p>Methods are quite critical in programming. They help store reusable code. This means that a person can call already declared methods rather than writing statements from scratch repeatedly. This saves significant time, that can be invested in other productive activities.</p>\n<p>In Python, we use the <code class=\"language-text\">def</code> keyword to declare a function. An example of a python method is shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">readData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'success'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The above function prints <code class=\"language-text\">success</code> when it's invoked. We can also pass data to a method, perform some calculations, and return the results. This is demonstrated in the code snippet below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">calculateTotal</span><span class=\"token punctuation\">(</span>chem<span class=\"token punctuation\">,</span> bio<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> chem<span class=\"token operator\">+</span>bio\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculateTotal<span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span><span class=\"token number\">80</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">calculateTotal</code> method takes in two parameters (chem, bio). The function then returns the sum of the two values. It is important to take note of the data types when passing parameters. For instance, the <code class=\"language-text\">calculateTotal</code> method will not work when we pass in a string as a parameter. This is because the program cannot sum up an integer and a string. As shown above, we can call the <code class=\"language-text\">calculateTotal</code> method directly from our print statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculateTotal<span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span><span class=\"token number\">80</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">return</code> keyword ensures that the method returns a result after execution.</p>\n<blockquote>\n<p>Note that a function can also call another method. This is illustrated below.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">readData</span><span class=\"token punctuation\">(</span>chem<span class=\"token punctuation\">,</span> bio<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">return</span> chem<span class=\"token operator\">+</span>bio\n\n<span class=\"token keyword\">def</span> <span class=\"token function\">getTotal</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>readData<span class=\"token punctuation\">(</span><span class=\"token number\">90</span><span class=\"token punctuation\">,</span><span class=\"token number\">80</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">#calls the readData method</span>\n\ngetTotal<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Understanding loops</strong></p>\n<p>Loops are critical because they allow us to iterate through lists, check for different conditions, and continuously execute various statements. The main loops are <code class=\"language-text\">for</code> and <code class=\"language-text\">while</code>.</p>\n<ol>\n<li>For loops As noted, we can use a for loop to iterate through a list, as shown below:</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">student_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">\"John Doore\"</span><span class=\"token punctuation\">,</span><span class=\"token string\">\"Matu Smith\"</span><span class=\"token punctuation\">]</span>\n<span class=\"token keyword\">for</span> x <span class=\"token keyword\">in</span> student_list<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">for</code> loop above will print every item in the student_list.</p>\n<ol>\n<li>While loops A while loop can help us check for a particular condition. For instance, while something is true specific statements can be executed. Here is an example of a while loop in action.</li>\n</ol>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">isChecked <span class=\"token operator\">=</span> false\n<span class=\"token keyword\">while</span> isChecked <span class=\"token operator\">==</span> true<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hallo there'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<blockquote>\n<p>Note that the while loop above will be executed indefinitely until isChecked is set to false. You can press ctrl+c to stop the loop.</p>\n</blockquote>\n<p><strong>Classes</strong></p>\n<p>Classes are a vital component of object-oriented programming. When creating a class, you must use the <code class=\"language-text\">class</code> keyword. Other elements are then nested in the class. Here is an example of a Python class.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Farmer</span><span class=\"token punctuation\">:</span> <span class=\"token comment\"># a class with the name farmer</span>\n    name <span class=\"token operator\">=</span> <span class=\"token string\">\"John\"</span> <span class=\"token comment\"># A variable</span>\n    produce <span class=\"token operator\">=</span> <span class=\"token string\">\"1000kgs\"</span> <span class=\"token comment\"># A variable</span>\n\nfarmer <span class=\"token operator\">=</span> Farmer<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token comment\">#instatiating the class as an object.</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>farmer<span class=\"token punctuation\">.</span>name<span class=\"token punctuation\">)</span> <span class=\"token comment\"># accessing the properties of the Farmer class.</span></code></pre></div>\n<p>Classes can help as group things with similar characteristics. We can also assign values to class variables using the <code class=\"language-text\">init</code> function.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Farmer</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> farmername<span class=\"token punctuation\">,</span> produce<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    self<span class=\"token punctuation\">.</span>farmername <span class=\"token operator\">=</span> farmername\n    self<span class=\"token punctuation\">.</span>produce <span class=\"token operator\">=</span> produce\n\nfarmer <span class=\"token operator\">=</span> Farmer<span class=\"token punctuation\">(</span><span class=\"token string\">\"Carry Sminson\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"10,000kgs\"</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>farmer<span class=\"token punctuation\">.</span>farmername<span class=\"token punctuation\">,</span> farmer<span class=\"token punctuation\">.</span>produce<span class=\"token punctuation\">)</span></code></pre></div>\n<p>In the above <code class=\"language-text\">Farmer</code> class, the <code class=\"language-text\">self</code> keyword represents an instance of an object. In other words, it allows us to access the different methods and attributes defined in the class.</p>\n<p>You can also declare a method in a class and use it later, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">class</span> <span class=\"token class-name\">Farmer</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">def</span> <span class=\"token function\">__init__</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">,</span> farmername<span class=\"token punctuation\">,</span> produce<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    self<span class=\"token punctuation\">.</span>farmername <span class=\"token operator\">=</span> farmername\n    self<span class=\"token punctuation\">.</span>produce <span class=\"token operator\">=</span> produce\n\n  <span class=\"token keyword\">def</span> <span class=\"token function\">printDetails</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token comment\"># Method</span>\n      <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>self<span class=\"token punctuation\">.</span>farmername<span class=\"token punctuation\">,</span> self<span class=\"token punctuation\">.</span>produce<span class=\"token punctuation\">)</span>\n\nfarmer <span class=\"token operator\">=</span> Farmer<span class=\"token punctuation\">(</span><span class=\"token string\">\"Carry Sminson\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"10,000kgs\"</span><span class=\"token punctuation\">)</span>\n\nfarmer<span class=\"token punctuation\">.</span>printDetails<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3>Python syntax was made for readability, and easy editing. For example, the python language uses a <code class=\"language-text\">:</code> and indented code, while javascript and others generally use <code class=\"language-text\">{}</code> and indented code</h3>\n<p>Lets create a [python 3](https://repl.it/languages/python3) repl, and call it <em>Hello World</em>. Now you have a blank file called <em>main.py</em>. Now let us write our first line of code:</p>\n<p><em>helloworld.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello world!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<blockquote>\n<p>Brian Kernighan actually wrote the first \"Hello, World!\" program as part of the documentation for the BCPL programming language developed by Martin Richards.</p>\n</blockquote>\n<p>Now, press the run button, which obviously runs the code. If you are not using replit, this will not work. You should research how to run a file with your text editor.</p>\n<p>If you look to your left at the console where hello world was just printed, you can see a <code class=\"language-text\">></code>, <code class=\"language-text\">>>></code>, or <code class=\"language-text\">$</code> depending on what you are using. After the prompt, try typing a line of code.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Python <span class=\"token number\">3.6</span><span class=\"token number\">.1</span> <span class=\"token punctuation\">(</span>default<span class=\"token punctuation\">,</span> Jun <span class=\"token number\">21</span> <span class=\"token number\">2017</span><span class=\"token punctuation\">,</span> <span class=\"token number\">18</span><span class=\"token punctuation\">:</span><span class=\"token number\">48</span><span class=\"token punctuation\">:</span><span class=\"token number\">35</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">[</span>GCC <span class=\"token number\">4.9</span><span class=\"token number\">.2</span><span class=\"token punctuation\">]</span> on linux\nType <span class=\"token string\">\"help\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"copyright\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"credits\"</span> <span class=\"token keyword\">or</span> <span class=\"token string\">\"license\"</span> <span class=\"token keyword\">for</span> more information<span class=\"token punctuation\">.</span>\n<span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Testing command line'</span><span class=\"token punctuation\">)</span>\nTesting command line\n<span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Are you sure this works?'</span><span class=\"token punctuation\">)</span>\nAre you sure this works?\n<span class=\"token operator\">></span></code></pre></div>\n<p>The command line allows you to execute single lines of code at a time. It is often used when trying out a new function or method in the language.</p>\n<p>Another cool thing that you can generally do with all languages, are comments. In python, a comment starts with a <code class=\"language-text\">#</code>. The computer ignores all text starting after the <code class=\"language-text\">#</code>.</p>\n<p><em>shortcom.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token comment\"># Write some comments!</span></code></pre></div>\n<p>If you have a huge comment, do <strong>not</strong> comment all the 350 lines, just put <code class=\"language-text\">'''</code> before it, and <code class=\"language-text\">'''</code> at the end. Technically, this is not a comment but a string, but the computer still ignores it, so we will use it.</p>\n<p><em>longcom.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token triple-quoted-string string\">'''\nDear PYer,\nI am confused about how you said you could use triple quotes to make\nSUPER\nLONG\nCOMMENTS\n!\n\nI am wondering if this is true,\nand if so,\nI am wondering if this is correct.\n\nCould you help me with this?\n\nThanks,\nRandom guy who used your tutorial.\n'''</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Testing'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Unlike many other languages, there is no <code class=\"language-text\">var</code>, <code class=\"language-text\">let</code>, or <code class=\"language-text\">const</code> to declare a variable in python. You simply go <code class=\"language-text\">name = 'value'</code>.</p>\n<p><em>vars1.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\ny <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\nz <span class=\"token operator\">=</span> x<span class=\"token operator\">*</span>y <span class=\"token comment\"># 35</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>z<span class=\"token punctuation\">)</span> <span class=\"token comment\"># => 35</span></code></pre></div>\n<p>Remember, there is a difference between integers and strings. <em>Remember: String = <code class=\"language-text\">\"\"</code>.</em> To convert between these two, you can put an int in a <code class=\"language-text\">str()</code> function, and a string in a <code class=\"language-text\">int()</code> function. There is also a less used one, called a float. Mainly, these are integers with decimals. Change them using the <code class=\"language-text\">float()</code> command.</p>\n<p><em>vars2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\nx <span class=\"token operator\">=</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span>\nb <span class=\"token operator\">=</span> <span class=\"token string\">'5'</span>\nb <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'x = '</span><span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">,</span> <span class=\"token string\">'; b = '</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">';'</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># => x = 5; b = 5;</span></code></pre></div>\n<p>Instead of using the <code class=\"language-text\">,</code> in the print function, you can put a <code class=\"language-text\">+</code> to combine the variables and string.</p>\n<p>There are many operators in python:</p>\n<ul>\n<li><code class=\"language-text\">+</code></li>\n<li><code class=\"language-text\">-</code></li>\n<li><code class=\"language-text\">/</code></li>\n<li><code class=\"language-text\">*</code> These operators are the same in most languages, and allow for addition, subtraction, division, and multiplicaiton. Now, we can look at a few more complicated ones:</li>\n<li><code class=\"language-text\">%</code></li>\n<li><code class=\"language-text\">//</code></li>\n<li><code class=\"language-text\">**</code></li>\n<li><code class=\"language-text\">+=</code></li>\n<li><code class=\"language-text\">-=</code></li>\n<li><code class=\"language-text\">/=</code></li>\n<li><code class=\"language-text\">*=</code> Research these if you want to find out more…</li>\n</ul>\n<p><em>simpleops.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token number\">4</span>\na <span class=\"token operator\">=</span> x <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\na <span class=\"token operator\">=</span> x <span class=\"token operator\">-</span> <span class=\"token number\">1</span>\na <span class=\"token operator\">=</span> x <span class=\"token operator\">*</span> <span class=\"token number\">2</span>\na <span class=\"token operator\">=</span> x <span class=\"token operator\">/</span> <span class=\"token number\">2</span></code></pre></div>\n<p>You should already know everything shown above, as it is similar to other languages. If you continue down, you will see more complicated ones.</p>\n<p><em>complexop.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">a <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\na <span class=\"token operator\">-=</span> <span class=\"token number\">1</span>\na <span class=\"token operator\">*=</span> <span class=\"token number\">2</span>\na <span class=\"token operator\">/=</span> <span class=\"token number\">2</span></code></pre></div>\n<p>The ones above are to edit the current value of the variable.<br>\nSorry to JS users, as there is no <code class=\"language-text\">i++;</code> or anything.</p>\n<blockquote>\n<p>Fun Fact:<br>\nThe python language was named after Monty Python.</p>\n</blockquote>\n<p>If you really want to know about the others, view [Py Operators](https://www.tutorialspoint.com/python/python<em>basic</em>operators.htm)</p>\n<p>Like the title?<br>\nAnyways, a <code class=\"language-text\">'</code> and a <code class=\"language-text\">\"</code> both indicate a string, but <strong>do not combine them!</strong></p>\n<p><em>quotes.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token string\">'hello'</span> <span class=\"token comment\"># Good</span>\nx <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span> <span class=\"token comment\"># Good</span>\nx <span class=\"token operator\">=</span> \"hello' <span class=\"token comment\"># ERRORRR!!!</span></code></pre></div>\n<p><em>slicing.py</em></p>\n<p><strong>String Slicing</strong></p>\n<p>You can look at only certain parts of the string by slicing it, using <code class=\"language-text\">[num:num]</code>.<br>\nThe first number stands for how far in you go from the front, and the second stands for how far in you go from the back.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token string\">'Hello everybody!'</span>\nx<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token comment\"># 'e'</span>\nx<span class=\"token punctuation\">[</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token comment\"># '!'</span>\nx<span class=\"token punctuation\">[</span><span class=\"token number\">5</span><span class=\"token punctuation\">]</span> <span class=\"token comment\"># ' '</span>\nx<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span><span class=\"token punctuation\">]</span> <span class=\"token comment\"># 'ello everybody!'</span>\nx<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token comment\"># 'Hello everybod'</span>\nx<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">:</span><span class=\"token operator\">-</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span> <span class=\"token comment\"># 'llo everyb'</span></code></pre></div>\n<p><strong>Methods and Functions</strong></p>\n<p>Here is a list of functions/methods we will go over:</p>\n<ul>\n<li><code class=\"language-text\">.strip()</code></li>\n<li><code class=\"language-text\">len()</code></li>\n<li><code class=\"language-text\">.lower()</code></li>\n<li><code class=\"language-text\">.upper()</code></li>\n<li><code class=\"language-text\">.replace()</code></li>\n<li><code class=\"language-text\">.split()</code></li>\n</ul>\n<p>I will make you try these out yourself. See if you can figure out how they work.</p>\n<p><em>strings.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">x <span class=\"token operator\">=</span> <span class=\"token string\">\" Testing, testing, testing, testing       \"</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">len</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>replace<span class=\"token punctuation\">(</span><span class=\"token string\">'test'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'runn'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Good luck, see you when you come back!</p>\n<p>Input is a function that gathers input entered from the user in the command line. It takes one optional parameter, which is the users prompt.</p>\n<p><em>inp.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Type something: '</span><span class=\"token punctuation\">)</span>\nx <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Here is what you said: '</span><span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">)</span></code></pre></div>\n<p>If you wanted to make it smaller, and look neater to the user, you could do…</p>\n<p><em>inp2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Here is what you said: '</span><span class=\"token punctuation\">,</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Type something: '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Running:<br>\n<em>inp.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Type something<span class=\"token punctuation\">:</span>\nHello World\nHere <span class=\"token keyword\">is</span> what you said<span class=\"token punctuation\">:</span> Hello World</code></pre></div>\n<p><em>inp2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">Type something<span class=\"token punctuation\">:</span> Hello World\nHere <span class=\"token keyword\">is</span> what you said<span class=\"token punctuation\">:</span> Hello World</code></pre></div>\n<p>Python has created a lot of functions that are located in other .py files. You need to import these <strong>modules</strong> to gain access to the,, You may wonder why python did this. The purpose of separate modules is to make python faster. Instead of storing millions and millions of functions, , it only needs a few basic ones. To import a module, you must write <code class=\"language-text\">input &lt;modulename></code>. Do not add the .py extension to the file name. In this example , we will be using a python created module named random.</p>\n<p><em>module.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random</code></pre></div>\n<p>Now, I have access to all functions in the random.py file. To access a specific function in the module, you would do <code class=\"language-text\">&lt;module>.&lt;function></code>. For example:</p>\n<p><em>module2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token comment\"># Prints a random number between 3 and 5</span></code></pre></div>\n<blockquote>\n<p>Pro Tip:<br>\nDo <code class=\"language-text\">from random import randint</code> to not have to do <code class=\"language-text\">random.randint()</code>, just <code class=\"language-text\">randint()</code><br>\nTo import all functions from a module, you could do <code class=\"language-text\">from random import *</code></p>\n</blockquote>\n<p>Loops allow you to repeat code over and over again. This is useful if you want to print Hi with a delay of one second 100 times.</p>\n<p><strong>for Loop</strong></p>\n<p>The for loop goes through a list of variables, making a seperate variable equal one of the list every time.<br>\nLet's say we wanted to create the example above.</p>\n<p><em>loop.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">from</span> time <span class=\"token keyword\">import</span> sleep\n<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span>\n     sleep<span class=\"token punctuation\">(</span><span class=\"token number\">.3</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>This will print Hello with a .3 second delay 100 times. This is just one way to use it, but it is usually used like this:</p>\n<p><em>loop2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> time\n<span class=\"token keyword\">for</span> number <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span>\n     time<span class=\"token punctuation\">.</span>sleep<span class=\"token punctuation\">(</span><span class=\"token number\">.1</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>while Loop</strong></p>\n<p>The while loop runs the code while something stays true. You would put <code class=\"language-text\">while &lt;expression></code>. Every time the loop runs, it evaluates if the expression is True. It it is, it runs the code, if not it continues outside of the loop. For example:</p>\n<p><em>while.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">while</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">:</span> <span class=\"token comment\"># Runs forever</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello World!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Or you could do:</p>\n<p><em>while2.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\nposition <span class=\"token operator\">=</span> <span class=\"token string\">'&lt;placeholder>'</span>\n<span class=\"token keyword\">while</span> position <span class=\"token operator\">!=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">:</span> <span class=\"token comment\"># will run at least once</span>\n    position <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>position<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The if statement allows you to check if something is True. If so, it runs the code, if not, it continues on. It is kind of like a while loop, but it executes <strong>only once</strong>. An if statement is written:</p>\n<p><em>if.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\nnum <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'num is 3. Hooray!!!'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num <span class=\"token operator\">></span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is greater than 5'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">12</span><span class=\"token punctuation\">:</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is 12, which means that there is a problem with the python language, see if you can figure it out. Extra credit if you can figure it out!'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Now, you may think that it would be better if you could make it print only one message. Not as many that are True. You can do that with an <code class=\"language-text\">elif</code> statement:</p>\n<p><em>elif.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\nnum <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is three, this is the only msg you will see.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num <span class=\"token operator\">></span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is not three, but is greater than 1'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Now, you may wonder how to run code if none work. Well, there is a simple statement called <code class=\"language-text\">else:</code></p>\n<p><em>else.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\nnum <span class=\"token operator\">=</span> random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> num <span class=\"token operator\">==</span> <span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is three, this is the only msg you will see.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> num <span class=\"token operator\">></span> <span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Num is not three, but is greater than 1'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'No category'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>So far, you have only seen how to use functions other people have made. Let use the example that you want to print the a random number between 1 and 9, and print different text every time.<br>\nIt is quite tiring to type:</p>\n<p>Characters: 389</p>\n<p><em>nofunc.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Wow that was interesting.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Look at the number above ^'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'All of these have been interesting numbers.'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"these random.randint's are getting annoying to type\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hi'</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'j'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Now with functions, you can seriously lower the amount of characters:</p>\n<p>Characters: 254</p>\n<p><em>functions.py</em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">import</span> random\n<span class=\"token keyword\">def</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>random<span class=\"token punctuation\">.</span>randint<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span>\nr<span class=\"token punctuation\">(</span><span class=\"token string\">'Wow that was interesting.'</span><span class=\"token punctuation\">)</span>\nr<span class=\"token punctuation\">(</span><span class=\"token string\">'Look at the number above ^'</span><span class=\"token punctuation\">)</span>\nr<span class=\"token punctuation\">(</span><span class=\"token string\">'All of these have been interesting numbers.'</span><span class=\"token punctuation\">)</span>\nr<span class=\"token punctuation\">(</span><span class=\"token string\">\"these random.randint's are getting annoying to type\"</span><span class=\"token punctuation\">)</span>\nr<span class=\"token punctuation\">(</span><span class=\"token string\">'Hi'</span><span class=\"token punctuation\">)</span>\nr<span class=\"token punctuation\">(</span><span class=\"token string\">'j'</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h4>Chapter 01 - Getting Ready with Python</h4>\n<p><strong>Installing Python 3, And Launching Python Shell</strong></p>\n<p>This video should help you get up and running with Python 3</p>\n<ul>\n<li>[Installing Python 3 and Launch Python Shell](https://www.youtube.com/watch?v=Ji1WW4Suaww)</li>\n</ul>\n<p>Installing Python is really a cakewalk. Search for \"Python download\" on [www.google.com](http://www.google.com/). Download the installable and install it.</p>\n<p>A quick word of caution on Windows</p>\n<ul>\n<li>Make sure that you have the check-box \"Add Python 3.6 to PATH\", checked.</li>\n</ul>\n<p>Once you have installed Python, you can launch the Python Shell.</p>\n<ul>\n<li>Windows - Launch cmd prompt by typing in 'cmd' command.</li>\n<li>Mac or Linux - Launch up terminal.</li>\n</ul>\n<p>Command to launch Python 3 is different in Mac.</p>\n<ul>\n<li>In Mac, type in <code class=\"language-text\">python3</code></li>\n<li>In other operating systems, including windows, type <code class=\"language-text\">python</code></li>\n</ul>\n<p>You can type code in python shell and code as well!</p>\n<p>You can use <code class=\"language-text\">print(5*4)</code>, and it shows <code class=\"language-text\">20</code>.</p>\n<p>You can execute the code, and the shell would immediately give you output.</p>\n<p>Using the the Python Shell is an awesome way to learn Python.</p>\n<h4>Chapter 02 - Introduction To Python Programming</h4>\n<p>Most programmers find programming a lot of fun, and besides, it also gets their work done.</p>\n<p>Programming mainly involves <em>problem solving</em>, where one makes use of a computer to solve a real world problem.</p>\n<p>During our journey here, we will approach programming in a very different way. We will not only introduce you to the Python language, but also help you pick up essential problem solving skills.</p>\n<p>As a programmer, you need to be able to look at a problem, and identify the important programming concepts relevant to solving it. Finally, you need to be able to use the language features and syntax, to express your solution on the computer. While all this looks complex, we want to make it easy for you. Together, we will tackle a variety of programming challenges, using these same steps. We will start with simple challenges (such as a Multiplication Table), and gradually increase the difficulty level over the duration of this book.</p>\n<p>Learning to program is a lot like learning to ride a bicycle. The first few steps are the most challenging ones.</p>\n<p>Once you get over these initial steps, your experience will become more and more enjoyable.</p>\n<p>Are you ready for your first programming challenge? Let's get going now! We wish you all the best.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to the concept of problem solving</li>\n<li>Understood how good programmers approach problem solving</li>\n</ul>\n<p><strong>Step 01: Our First Programming Challenge</strong></p>\n<p>Our first <em>programming challenge</em> aims to do, what every kid does in math class: read out a multiplication table. We now want to give this task to the computer. Here is the statement of our problem:</p>\n<p><strong>The Print Multiplication Table Challenge (PMT-Challenge)</strong></p>\n<ol>\n<li>Compute the multiplication table for <code class=\"language-text\">5</code>, with entries from <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code>.</li>\n<li>Display this table.</li>\n</ol>\n<p>The display needs to be:</p>\n<p><em><strong>5 * 1 = 5</strong></em></p>\n<p><em><strong>5 * 2 = 10</strong></em></p>\n<p><em><strong>5 * 3 = 15</strong></em></p>\n<p><em><strong>5 * 4 = 20</strong></em></p>\n<p><em><strong>5 * 5 = 25</strong></em></p>\n<p><em><strong>5 * 6 = 30</strong></em></p>\n<p><em><strong>5 * 7 = 35</strong></em></p>\n<p><em><strong>5 * 8 = 40</strong></em></p>\n<p><em><strong>5 * 9 = 45</strong></em></p>\n<p><em><strong>5 * 10 = 50</strong></em></p>\n<p>This is the challenge. For convenience, let's give it a label, say <em>PMT-Challenge</em>. What would be the important concepts we need to learn, to solve this challenge? The following list of concepts would be a good starting point:</p>\n<ul>\n<li><strong>Statements</strong></li>\n<li><strong>Expressions</strong></li>\n<li><strong>Variables</strong></li>\n<li><strong>Literals</strong></li>\n<li><strong>Conditionals</strong></li>\n<li><strong>Loops</strong></li>\n<li><strong>Methods</strong></li>\n</ul>\n<p>In the rest of this chapter, we will introduce these concepts to you, one-by-one. We will also show you how learning each concept, takes us closer to a solution to <em>PMT-Challenge</em>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Stated our first programming challenge</li>\n<li>Identified what programming concepts we need to learn, to solve this challenge</li>\n</ul>\n<p><strong>Step 02: Breaking Down PMT-Challenge</strong></p>\n<p>Typically when we do programming, we have problems. Solving the problem typically need a step-by -step approach. Common sense tells us that to solve a complex problem, we break it into smaller parts, and solve each part one by one. Here is how any good programmer worth her salt, would solve a problem:</p>\n<ul>\n<li>Simplify the problem, by breaking it into sub-problems</li>\n<li>Solve the sub-problems in stages (in some order), using the language</li>\n<li>Combine these solutions to get a final solution</li>\n</ul>\n<p>The <em>PMT-Challenge</em> is no different! Now how do we break it down, and where do we really start? Once again, your common sense will reveal a solution. As a first step, we could get the computer to calculate say, <code class=\"language-text\">5 * 3</code>. The second thing we can do, is to try and print the calculated value, in a manner similar to <code class=\"language-text\">5 * 3 = 15</code>. Then, we could repeat what we just did, to print out all the entries of the <code class=\"language-text\">5</code> multiplication table. Let's put it down a little more formally:</p>\n<p>Here is how our draft steps look like</p>\n<ul>\n<li>Calculate <code class=\"language-text\">5 * 3</code> and print result as <code class=\"language-text\">15</code></li>\n<li>Print <code class=\"language-text\">5 * 3 = 15</code> (<code class=\"language-text\">15</code> is result of previous calculation)</li>\n<li>Do this ten times, once for each table entry (going from <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code>)</li>\n</ul>\n<p>Let's start with that kind of a game plan, and see where it takes us.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned that breaking down a problem into sub-problems is a great help</li>\n<li>Found a way to break down the <em>PMT-Challenge</em> problem</li>\n</ul>\n<p><strong>Step 03: Introducing Operators And Expressions</strong></p>\n<p>Let's focus on solving the first sub-problem of <em>PMT-Challenge</em>, the numeric computation. We want the computer to calculate <code class=\"language-text\">5 * 5</code> for example, and print <code class=\"language-text\">25</code> for us. How do we get it to do that? That's what we would be looking at in this step.</p>\n<p><strong>Snippet-01: Introducing Operators</strong></p>\n<p>Launch up Python shell. We want to calculate <code class=\"language-text\">5 * 5</code>. How do we do that?</p>\n<p>Using our knowledge of school math, let's try <code class=\"language-text\">5 X 5</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> X <span class=\"token number\">5</span>\n    File <span class=\"token string\">\"&lt; stdin >\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n    <span class=\"token number\">5</span> X <span class=\"token number\">5</span>\n      <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p>The Python Shell hits back at us, saying \"<em>invalid syntax</em>\". This is how Python complains, when it doesn't fully understand the code you type in. Here, it says our code has a \"<strong>SyntaxError</strong>\".</p>\n<p>The reason why it complains, is because '<code class=\"language-text\">X</code>' is not a valid <strong>operator</strong> in Python.</p>\n<p>The way you can do multiplication is by using the '<code class=\"language-text\">*</code>' <em>operator</em> .</p>\n<p>\"<em>5 into 5</em>\" is achieved by the code <code class=\"language-text\">5 * 5</code>, and you can see the result <code class=\"language-text\">25</code> being printed. Similarly, <code class=\"language-text\">5 * 6</code> gives us <code class=\"language-text\">30</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span>\n    <span class=\"token number\">30</span></code></pre></div>\n<p>There are a wide range of other operators in Python:</p>\n<ul>\n<li><code class=\"language-text\">5 + 6</code> gives a result of <code class=\"language-text\">11</code>.</li>\n<li>\n<p><code class=\"language-text\">5 - 6</code> leads to <code class=\"language-text\">-1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span>\n<span class=\"token number\">11</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token number\">6</span>\n<span class=\"token operator\">-</span><span class=\"token number\">1</span></code></pre></div>\n</li>\n</ul>\n<p><code class=\"language-text\">10 / 2</code>, gives an output of <code class=\"language-text\">5.0</code> . There is one interesting operator, <code class=\"language-text\">**</code>. Let's try <code class=\"language-text\">10 ** 3</code>. We ran this code, and the result we get is <code class=\"language-text\">1000</code>. Yes you guessed right, the operator performs \"to the power of\". \"<code class=\"language-text\">10</code> to the power of <code class=\"language-text\">3</code>\" is <code class=\"language-text\">10 * 10 * 10</code>, or <code class=\"language-text\">1000</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">10</span> <span class=\"token operator\">/</span> <span class=\"token number\">2</span>\n    <span class=\"token number\">5.0</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">10</span> <span class=\"token operator\">**</span> <span class=\"token number\">3</span>\n    <span class=\"token number\">1000</span></code></pre></div>\n<p>Another interesting operator is <code class=\"language-text\">%</code>, called \"<em>modulo</em>\", which computes the remainder on integer division. If we do <code class=\"language-text\">10 % 3</code>, what is the remainder when <code class=\"language-text\">10</code> is divided by <code class=\"language-text\">3</code>? <code class=\"language-text\">3 * 3</code> is <code class=\"language-text\">9</code>, and <code class=\"language-text\">10 - 9</code> is <code class=\"language-text\">1</code>, which is what <code class=\"language-text\">%</code> returns in this case.</p>\n<p>Let's look at some terminology:</p>\n<ul>\n<li>Whatever pieces of code we gave Python shell to run, are called <strong>expressions</strong>. So, <code class=\"language-text\">5 * 5</code>, <code class=\"language-text\">5 * 6</code> and <code class=\"language-text\">5 - 6</code> are all <em>expressions</em>. An expression is composed of <em>operators</em> and <strong>operands</strong>.</li>\n<li>In the expression <code class=\"language-text\">5 * 6</code>, the two values <code class=\"language-text\">5</code> and <code class=\"language-text\">6</code> are called operands, and the <code class=\"language-text\">*</code> operator <em>operates</em> on them.</li>\n<li>The values <code class=\"language-text\">5</code> and <code class=\"language-text\">6</code> are <strong>literals</strong>, because those are constants which cannot be changed.</li>\n</ul>\n<p>The cool thing about Python, is that you can even have expressions with multiple operators. Therefore, you can form an expression with <code class=\"language-text\">5 + 5 + 5</code>, which evaluates to <code class=\"language-text\">15</code>. This is an expression which has three operands, and two <code class=\"language-text\">+</code> operators. You can even have expressions with different types of operators, such as in <code class=\"language-text\">5 + 5 * 5</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span>\n    <span class=\"token number\">15</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span>\n    <span class=\"token number\">30</span></code></pre></div>\n<p>Try and play around with the expressions, and understand the output which results.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned how to give code input to the Python Shell</li>\n<li>Understood that Python has a predefined set of operators</li>\n<li>Used a few types of basic operators and their operands, to form expressions</li>\n</ul>\n<p><strong>Step 04: Programming Exercise IN-PE-01</strong></p>\n<p>At this stage, your smile tells us that you enjoy evaluating Python expressions. What if we tickle your mind a bit, to make sure it hasn't fallen asleep? Here is your first programming exercise.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Write an expression to calculate the number of minutes in a day.</li>\n<li>Write an expression to calculate the number of seconds in a day.</li>\n</ol>\n<p><strong>Note</strong></p>\n<p>You need to solve these problems by yourself. If you are able to work them out, that's fantastic! But if not, that's part of the learning process.</p>\n<p><strong>Solutions</strong></p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">24</span> <span class=\"token operator\">*</span> <span class=\"token number\">60</span>\n\n    <span class=\"token number\">1440</span></code></pre></div>\n<p>We wanted to calculate the number of minutes in a day. How do we do that? Think about this…</p>\n<ul>\n<li>How many number of hours are there in a day? <code class=\"language-text\">24</code>.</li>\n<li>And how many minutes does each hour have? It's <code class=\"language-text\">60</code>.</li>\n<li>So if you want to find out the number of minutes in a day, it's <code class=\"language-text\">24 * 60</code>, which is <code class=\"language-text\">1440</code>.</li>\n</ul>\n<p><strong>Solution 2</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">24</span> <span class=\"token operator\">*</span> <span class=\"token number\">60</span> <span class=\"token operator\">*</span> <span class=\"token number\">60</span>\n\n    <span class=\"token number\">86400</span></code></pre></div>\n<p>How many seconds are there in a day?</p>\n<ul>\n<li>Let's start with the number of hours, <code class=\"language-text\">24</code>.</li>\n<li>The number of minutes in an hour is <code class=\"language-text\">60</code>, and</li>\n<li>The number of seconds in a minute is <code class=\"language-text\">60</code> as well.</li>\n<li>So it's <code class=\"language-text\">24 * 60 * 60</code>, or <code class=\"language-text\">86400</code>.</li>\n</ul>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Solved a Programming Exercise involving common scenarios, using Python code involving:</p>\n<ul>\n<li>Expressions</li>\n<li>Operators</li>\n<li>Literals</li>\n</ul>\n</li>\n</ul>\n<p><strong>Step 05: Puzzles On Expressions</strong></p>\n<p>Let's look at a few puzzles related to expressions, in this step. Before that, let's revise some of the terminology we had learned earlier.</p>\n<p><code class=\"language-text\">5 + 6 + 10</code> is an example of an expression. In this expression, <code class=\"language-text\">5</code>, <code class=\"language-text\">6</code> and <code class=\"language-text\">10</code> are operands. The <code class=\"language-text\">+</code> here is the operator. You can have multiple operators in an expression. We also did mention that the operands, namely <code class=\"language-text\">10</code>, <code class=\"language-text\">6</code> and <code class=\"language-text\">5</code>, are literals. Their values will not change.</p>\n<p>Here are a few puzzles coming up, to explore aspects of expressions.</p>\n<p><strong>Snippet-01: Puzzles On Expressions</strong></p>\n<p>Think about what would happen when you do something of this kind: <code class=\"language-text\">5 $ 2</code>. You're right, it would throw a <code class=\"language-text\">SyntaxError</code>. When Python does not understand the code you type in, it reports an error. Here, the expression we're typing is <code class=\"language-text\">5 $ 2</code>, which does not make sense to Python, hence the <code class=\"language-text\">SyntaxError</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> $ <span class=\"token number\">2</span>\n    File <span class=\"token string\">\"&lt; stdin >\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n    <span class=\"token number\">5</span> $ <span class=\"token number\">2</span>\n    <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span>$<span class=\"token number\">2</span>\n    File <span class=\"token string\">\"&lt; stdin >\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n    <span class=\"token number\">5</span> $ <span class=\"token number\">2</span>\n    <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p>Let's say we type in <code class=\"language-text\">5+6+10</code>, without any spaces between the operands, and the operators. What do you think will happen? Surprisingly, the Python Shell does calculate the value!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span><span class=\"token operator\">+</span><span class=\"token number\">6</span><span class=\"token operator\">+</span><span class=\"token number\">10</span>\n    <span class=\"token number\">21</span></code></pre></div>\n<p>In an expression, using spaces makes it easier for you to read it, but it's not mandatory. <code class=\"language-text\">5 + 6 + 10</code> is easier to read than <code class=\"language-text\">5+6+10</code>, but does not make any difference to the Python compiler.</p>\n<p>The next puzzle tries to evaluate <code class=\"language-text\">5 / 2</code>, which is \"<code class=\"language-text\">5</code> divided by <code class=\"language-text\">2</code>\". What would be the output? <code class=\"language-text\">2.5</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span><span class=\"token operator\">/</span><span class=\"token number\">2</span>\n    <span class=\"token number\">2.5</span></code></pre></div>\n<p>If you're coming from other programming languages like Java or C, this might be a surprising result. If you try this in Java for instance, you would get <code class=\"language-text\">2</code> as the output. Note that even though both operands are integers, the result of the <code class=\"language-text\">/</code> operation is a floating point value, <code class=\"language-text\">2.5</code> . Python does what is expected by a programmer!</p>\n<p>The puzzle after that tries to play with <code class=\"language-text\">5 + 5 * 6</code>. What would be the result of this expression? Will it be <code class=\"language-text\">5 + 5</code> or <code class=\"language-text\">10</code>, then <code class=\"language-text\">10 * 6</code>, which is <code class=\"language-text\">60</code>? Or, will it be <code class=\"language-text\">5</code> plus <code class=\"language-text\">5 * 6</code>, which is <code class=\"language-text\">5</code> + <code class=\"language-text\">30</code>, that's <code class=\"language-text\">35</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span>\n    <span class=\"token number\">35</span></code></pre></div>\n<p>The correct result is <code class=\"language-text\">35</code>.</p>\n<p>Python decides this is based on the <strong>precedence</strong> of operators.</p>\n<p>Operators in Python are divided into two sets as follows:</p>\n<ul>\n<li><code class=\"language-text\">**</code>, <code class=\"language-text\">*</code>, <code class=\"language-text\">/</code> and <code class=\"language-text\">%</code> have higher precedence, or priority.</li>\n<li><code class=\"language-text\">+</code> and <code class=\"language-text\">-</code> have a lower precedence.</li>\n</ul>\n<p>Sub-expressions involving operators from {<code class=\"language-text\">*</code>, <code class=\"language-text\">/</code>, <code class=\"language-text\">%</code>, <code class=\"language-text\">**</code>} are evaluated before those involving operators from {<code class=\"language-text\">+</code>, <code class=\"language-text\">-</code>}</p>\n<p>Let's try another small puzzle on precedence, with <code class=\"language-text\">5 - 2 * 2</code>. What would be the result of this? Will it be <code class=\"language-text\">6</code>, or <code class=\"language-text\">1</code>? It's <code class=\"language-text\">1</code>, because <code class=\"language-text\">*</code> has a higher precedence than <code class=\"language-text\">-</code>. Thus <code class=\"language-text\">2 * 2</code> is <code class=\"language-text\">4</code>, and <code class=\"language-text\">5 - 4</code> gives us <code class=\"language-text\">1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span>\n    <span class=\"token number\">1</span></code></pre></div>\n<p>Let's say we want to execute <code class=\"language-text\">5 - 2</code>, to give an output of <code class=\"language-text\">2</code>. How do we change the operator precedence?</p>\n<p>You cannot really change the precedence, but you can add parentheses to group sub-expressions differently.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token punctuation\">(</span><span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">-</span> <span class=\"token punctuation\">(</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span></code></pre></div>\n<p>Parentheses have the highest precedence in Python, and can be used to override operator precedence. <code class=\"language-text\">(5 - 2)</code> gets calculated first, and the final result of the expression is <code class=\"language-text\">6</code>.</p>\n<p>A positive thing about using parentheses is, that it makes expressions more readable. So even in situations such as <code class=\"language-text\">5 - 2 * 2</code>, where we know the result according to precedence, adding parentheses is good.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we went about solving a few puzzles about expressions, touching concepts such as:</p>\n<ul>\n<li><code class=\"language-text\">SyntaxError</code> for incorrect operators</li>\n<li>White-space in expressions</li>\n<li>Floating Point division by default</li>\n<li>Operator Precedence</li>\n<li>Using parentheses</li>\n</ul>\n<p><strong>Step 06: Printing Text</strong></p>\n<p>In the previous step, we learned how to use expressions to compute values. In this step, let's see how we can actually print multiplication table entries, that are readable by the user.</p>\n<p><strong>Snippet-01: Printing Text</strong></p>\n<p>How do we go about printing a complete multiplication table entry? We want to print text such as <code class=\"language-text\">5 * 6 = 30</code> . But trying to do so, as we know it, gives us a <code class=\"language-text\">SyntaxError</code>. Clearly, there is a different way to print text, as compared to an expression.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n    SyntaxError<span class=\"token punctuation\">:</span> can't assign to operator</code></pre></div>\n<p>Let's first try to print a simple piece of text, <code class=\"language-text\">Hello</code>. Typing in this piece of code directly on Python Shell also gives us an error.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> Hello\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'Hello'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>Only expressions work that way, and <code class=\"language-text\">Hello</code> is not really an expression.</p>\n<p><code class=\"language-text\">\"Hello\"</code> is typically called a <strong>string</strong>, and represents the text of letters <code class=\"language-text\">'H'</code>, <code class=\"language-text\">'e'</code>, <code class=\"language-text\">'l'</code>, <code class=\"language-text\">'l'</code>, <code class=\"language-text\">'o'</code>. <code class=\"language-text\">\"Hello\"</code> is hence different from the number <code class=\"language-text\">5</code>.</p>\n<p>There are a number of in-built functions in Python to help print strings. One of these is the <code class=\"language-text\">print()</code> function. Can you just say <code class=\"language-text\">print Hello</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> Hello\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token keyword\">print</span> Hello\n                  <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> Missing parentheses <span class=\"token keyword\">in</span> call to <span class=\"token string\">'print'</span><span class=\"token punctuation\">.</span> Did you mean <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>Hello<span class=\"token punctuation\">)</span>?</code></pre></div>\n<p>The Python compiler gives you an error, that says \"missing parentheses\".</p>\n<p>Will <code class=\"language-text\">print(Hello)</code> work?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span>Hello<span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'Hello'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>Nope! Again, this one failed because you need to indicate that <code class=\"language-text\">\"Hello\"</code> is a string.</p>\n<p>How do I indicate that <code class=\"language-text\">\"Hello\"</code> is a string? By putting it within double quotes.</p>\n<p>Let's try <code class=\"language-text\">print (\"Hello\")</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span>\n    Hello\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span>\n    Hello</code></pre></div>\n<p><code class=\"language-text\">print(\"Hello\")</code> finally results in <code class=\"language-text\">\"Hello\"</code> being printed out. To be able to print <code class=\"language-text\">\"Hello\"</code>, the things we need to do are:</p>\n<ul>\n<li>Typing the method name print ,</li>\n<li>open parentheses ( ,</li>\n<li>Followed by a double quote \" ,</li>\n<li>The text Hello,</li>\n<li>and another double quote \" ,</li>\n<li>finished off with a closed parentheses ).</li>\n</ul>\n<p>What we have written here is called a <strong>statement</strong>, a simple piece of code to execute. As part of this statement, we are <strong>calling</strong> a <strong>function</strong>, named <code class=\"language-text\">print()</code>.</p>\n<p>What exactly are we trying to print?</p>\n<p>The text <code class=\"language-text\">\"Hello\"</code>, which is called a <strong>parameter</strong> or <strong>argument</strong>, to <code class=\"language-text\">print()</code>.</p>\n<p>Now let's get back to what we wanted to do, which is to print <code class=\"language-text\">5 * 6 = 30</code>. The most basic version would be something of this kind, <code class=\"language-text\">print(\"5 * 6 = 30\")</code>. Here, we are passing the entire value in the form of a string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 * 6 = 30\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span></code></pre></div>\n<p>This prints the text on the console, as-is. The thing you need to understand here is, we aren't really calculating <code class=\"language-text\">30</code> using the formula <code class=\"language-text\">5 * 6</code>, but directly putting text <code class=\"language-text\">30</code> in here. That's called <strong>hard-coding</strong>.</p>\n<p>In a later step, we will look at how to actually calculate the value and pass it in.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Understood that displaying text on the console is not the same as printing an expression value</li>\n<li>Learned about the <code class=\"language-text\">print()</code> function, that is used to print text in Python.</li>\n<li>Found a way to print the text <code class=\"language-text\">\"5 * 6 = 30\"</code> on the console, by hard-coding values in a string</li>\n</ul>\n<p><strong>Step 07: Puzzles On Utility Methods, And Strings</strong></p>\n<p>In the previous step, we learned how to print <code class=\"language-text\">5 * 6 = 30</code>. It was not a perfect solution, because we hard-coded everything. we used an in-built function named <code class=\"language-text\">print()</code>, passed a string to it, and invoked the method.</p>\n<p>In this step, let's look at a number of puzzles related to in-built methods, their parameters, and strings in general.</p>\n<p>For example, let's do <code class=\"language-text\">print(\"5 * 6\")</code>, as in the previous step. What does this code result in?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5*6\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'5*6'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span></code></pre></div>\n<p>It just prints the string <code class=\"language-text\">\"5 * 6\"</code>.</p>\n<p>Let's say we try the code <code class=\"language-text\">print(5 * 6)</code>,</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">30</span></code></pre></div>\n<p>Without the double quotes, <code class=\"language-text\">5 * 6</code> is an expression. What will be the output? <code class=\"language-text\">30</code>.</p>\n<p>If you call <code class=\"language-text\">print()</code> with an expression argument, it prints the value of the expression. However, when we pass something within double quotes, it becomes a piece of text, printed as-is.</p>\n<p>An interesting thing to note is, that in Python you can use either double-quotes (<code class=\"language-text\">\"</code> and <code class=\"language-text\">\"</code>), or single-quotes (<code class=\"language-text\">'</code> and <code class=\"language-text\">'</code>) with text values.</p>\n<p>Let's look at a few other in-built methods within Python.</p>\n<p>Consider <code class=\"language-text\">abs()</code> (which stands for absolute value), a method that accepts a numeric value. You can use <code class=\"language-text\">abs(10.5)</code>, passing <code class=\"language-text\">10.5</code> as a value to it, and it prints the absolute value of <code class=\"language-text\">10</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">abs</span> <span class=\"token number\">10.5</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token builtin\">abs</span> <span class=\"token number\">10.5</span>\n               <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span><span class=\"token number\">10.5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">10.5</span></code></pre></div>\n<p>If you pass in a string value, will it work? It complains, \"<code class=\"language-text\">abs()</code> function will not work with a string, it only works with numeric values\".</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"10.5\"</span><span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    TypeError<span class=\"token punctuation\">:</span> bad operand <span class=\"token builtin\">type</span> <span class=\"token keyword\">for</span> <span class=\"token builtin\">abs</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'str'</span></code></pre></div>\n<p>Let's say you want to use a function that computes \"to the power of\", for instance \"<code class=\"language-text\">2</code> to the power of <code class=\"language-text\">5</code>\". In Python, there's an in-built function named <code class=\"language-text\">pow()</code>, which does just what we need. To <code class=\"language-text\">pow()</code>, you can pass two parameters and calculate the result. How do you do that?</p>\n<p>Will this work: <code class=\"language-text\">pow 2 5</code>? No, not at all. This code does not work as well: <code class=\"language-text\">pow(2 5)</code>. <code class=\"language-text\">pow(2, 5)</code> is the correct syntax.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span> <span class=\"token number\">2</span> <span class=\"token number\">5</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token builtin\">pow</span> <span class=\"token number\">2</span> <span class=\"token number\">5</span>\n            <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n              <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">32</span></code></pre></div>\n<p>You'll see that <code class=\"language-text\">32</code> is printed.</p>\n<p>Let's see another example, \"<code class=\"language-text\">10</code> to the power of <code class=\"language-text\">3</code>\". <code class=\"language-text\">pow(10,3)</code> is the alternative to saying <code class=\"language-text\">10 ** 3</code>. This gives us <code class=\"language-text\">1000</code>, similar to how <code class=\"language-text\">pow()</code> would.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1000</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">10</span> <span class=\"token operator\">**</span> <span class=\"token number\">3</span>\n    <span class=\"token number\">1000</span></code></pre></div>\n<p><code class=\"language-text\">max()</code> returns maximum in a set of numbers.<code class=\"language-text\">min()</code> function returns the minimum value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">34</span><span class=\"token punctuation\">,</span> <span class=\"token number\">45</span><span class=\"token punctuation\">,</span> <span class=\"token number\">67</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">67</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span><span class=\"token number\">34</span><span class=\"token punctuation\">,</span> <span class=\"token number\">45</span><span class=\"token punctuation\">,</span> <span class=\"token number\">67</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">34</span></code></pre></div>\n<p>These are some of the in-built functions in Python, and we saw how to call the in-built functions by passing in a varied number of parameters.</p>\n<p>Python is case sensitive. So let's say I want of calculate <code class=\"language-text\">pow(2,5)</code>. So this would give me <code class=\"language-text\">32</code>. Now, what if I say capital <code class=\"language-text\">'P'</code> instead of small <code class=\"language-text\">'p'</code> here? <code class=\"language-text\">Pow(2,5)</code> would lead to an error.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">32</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> Pow<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'Pow'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>The only things not case-sensitive in Python, are string values. Earlier we saw that the code <code class=\"language-text\">print(\"Hello\")</code> displays the text <code class=\"language-text\">\"Hello\"</code>. Inside a string, the text can be in any case. Hence, <code class=\"language-text\">print(\"hello\")</code> displays <code class=\"language-text\">\"hello\"</code> ,with a small <code class=\"language-text\">'h'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span><span class=\"token punctuation\">)</span>\n    Hello\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hello\"</span><span class=\"token punctuation\">)</span>\n    hello\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"hellO\"</span><span class=\"token punctuation\">)</span>\n    hellO\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span> <span class=\"token string\">\"hellO\"</span> <span class=\"token punctuation\">)</span>\n    hellO</code></pre></div>\n<p>However inside your code, you need to be very particular about the case of function names, class names, variable names, and the like.</p>\n<p>In your code, whitespace does not really matter. You can add space here and here, and you would still get the same output. However, in case of strings, whitespace does matter.</p>\n<p>If we say <code class=\"language-text\">print(\"hellO World\")</code>, it would print <code class=\"language-text\">\"hellO World\"</code>, with a space in between. And if you do <code class=\"language-text\">print(\"hellO World\")</code> with three spaces, it would print the same. In expressions, white-space does not affect the output.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span> <span class=\"token string\">\"hellO World\"</span> <span class=\"token punctuation\">)</span>\n    hellO World\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span> <span class=\"token punctuation\">(</span> <span class=\"token string\">\"hellO     World\"</span> <span class=\"token punctuation\">)</span>\n    hellO     World</code></pre></div>\n<p>The last thing we want to look at, is an <strong>escape sequence</strong>. Let's say you want to print a double quote, <code class=\"language-text\">\"</code>, in the code. If we were to do this: <code class=\"language-text\">print(\"Hello\"\")</code>, what would happen? The compiler says error!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span>\"<span class=\"token punctuation\">)</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\"</span>\"<span class=\"token punctuation\">)</span>\n                      <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> EOL <span class=\"token keyword\">while</span> scanning string literal</code></pre></div>\n<p>If you want to print a <code class=\"language-text\">\"</code> inside a string, use an escape sequence. In Python, the symbol <code class=\"language-text\">'\\'</code> is used as an <strong>escape character</strong>. On using <code class=\"language-text\">'\\'</code> adjacent to the <code class=\"language-text\">\"</code>, it prints <code class=\"language-text\">Hello\"</code> (notice the trailing <code class=\"language-text\">\"</code>). We have used the <code class=\"language-text\">'\\'</code> to <strong>escape</strong> the <code class=\"language-text\">\"</code>, by forming an <em>escape sequence</em> <code class=\"language-text\">\\\"</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\"\"</span><span class=\"token punctuation\">)</span>\nHello\"\n<span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>The other reason why you would want to use a <code class=\"language-text\">'\\'</code> is to print a <code class=\"language-text\">&lt;NEWLINE></code>. If you want to print <code class=\"language-text\">\"Hello World\"</code>, but with <code class=\"language-text\">\"Hello\"</code> on one line and <code class=\"language-text\">\"World\"</code> on the next, <code class=\"language-text\">'\\n'</code> is the escape sequence to use.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\nWorld\"</span><span class=\"token punctuation\">)</span>\n    Hello\n    World</code></pre></div>\n<p>The other important escape sequence is <code class=\"language-text\">'\\t'</code>, which prints a <code class=\"language-text\">&lt;TAB></code> in the output. When you do <code class=\"language-text\">print(\"Hello\\tWorld\")</code>, you can see the tab-space between <code class=\"language-text\">\"Hello\"</code> and <code class=\"language-text\">\"World\"</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\tWorld\"</span><span class=\"token punctuation\">)</span>\n    Hello   World</code></pre></div>\n<p>Another useful escape sequence is <code class=\"language-text\">\\\\</code> . If you want to print a <code class=\"language-text\">\\</code> , then use the sequence <code class=\"language-text\">\\\\</code> . You would see that it prints <code class=\"language-text\">Hello\\World</code> . Think about what would happen if we put six <code class=\"language-text\">\\</code> . Yes you're right! It would print this string: <code class=\"language-text\">\"\\\\\\\"</code> .</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\\World\"</span><span class=\"token punctuation\">)</span>\n    Hello\\World\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\\\\\\\\\\World\"</span><span class=\"token punctuation\">)</span>\n    Hello\\\\\\World</code></pre></div>\n<p>One of the things with Python is, it does not matter whether you use double quotes or single quotes to enclose strings. There are some interesting, and useful ways of using a combination of both, within the same string. Have a look at this call: <code class=\"language-text\">print(\"Hello'World\")</code>, and notice the output we get. In a similar way, the following code will be accepted and run by the Python system: <code class=\"language-text\">print('Hello\"World')</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Hello\"'</span><span class=\"token punctuation\">)</span>\n    Hello\"\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello'World\"</span><span class=\"token punctuation\">)</span>\n    Hello'World\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\"World\"</span><span class=\"token punctuation\">)</span>\n    Hello\"World\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello\\\"World\"</span><span class=\"token punctuation\">)</span>\n    Hello\"World</code></pre></div>\n<p>The above two examples can be used as a tip by newbie programmers when they form string literals, and want to use them in their code:</p>\n<ul>\n<li>If the string literal contains one or more single quotes, then you can use double quotes to enclose it.</li>\n<li>However if the string contains one or more double quotes, then prefer to use single quotes to enclose it.</li>\n</ul>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Explored a number of puzzles related to code involving:</p>\n<ul>\n<li>Built-in functions for numeric calculations</li>\n<li>The <code class=\"language-text\">print()</code> function to display expressions and strings</li>\n</ul>\n</li>\n<li>\n<p>Covered the following aspects of the above utilities:</p>\n<ul>\n<li>Case-sensitive aspects of names and strings</li>\n<li>The role played by whitespace</li>\n<li>The escape character, and common escape sequences</li>\n</ul>\n</li>\n</ul>\n<p><strong>Step 08: Formatted Output With print()</strong></p>\n<p>In the previous step, we learned how to print a hard-coded string, such as <code class=\"language-text\">\"5 * 6 = 30\"</code>.</p>\n<p>In this step, let's try to replace the hard-coded <code class=\"language-text\">30</code> with a computed value.</p>\n<p>Let's start with a simple scenario. Let's say we want to place that calculated value within a string, and display it. How do we do that?</p>\n<p><strong>Snippet-01: print() Formatted Output</strong></p>\n<p><code class=\"language-text\">format()</code> method can be used to print formatted text.</p>\n<p>Let's see an example:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    VALUE</code></pre></div>\n<p>We were expecting <code class=\"language-text\">10</code> to be printed, but it's actually printing <code class=\"language-text\">VALUE</code>.</p>\n<p>How do we get <code class=\"language-text\">10</code> to be printed then?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE {0}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    VALUE <span class=\"token number\">10</span></code></pre></div>\n<p>By having an open brace <code class=\"language-text\">{</code>, closed brace <code class=\"language-text\">}</code>, and and by putting the index of the value between them. Here, the value is the first parameter, and it's index will be <code class=\"language-text\">0</code>.</p>\n<p><code class=\"language-text\">\"VALUE {0}\"</code> is what we need.</p>\n<p>Let's take another example. Suppose to the <code class=\"language-text\">format()</code> function, we pass three values: <code class=\"language-text\">10</code>, <code class=\"language-text\">20</code> and <code class=\"language-text\">30</code>.</p>\n<p>Typically when we count positions or indexes, we start from <code class=\"language-text\">0</code>.</p>\n<p>To print the first value, you need to pass in an index of <code class=\"language-text\">0</code>. To print the second value, pass an index of <code class=\"language-text\">1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE {0}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span><span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    VALUE <span class=\"token number\">10</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE {1}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span><span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    VALUE <span class=\"token number\">20</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"VALUE {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span><span class=\"token number\">30</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    VALUE <span class=\"token number\">30</span></code></pre></div>\n<p>Now going back to our problem, we wanted to display <code class=\"language-text\">\"5 * 6 = 30\"</code>, but without hard-coding. Instead of <code class=\"language-text\">30</code>, we want the calculated value of <code class=\"language-text\">5 * 6</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 * 6 = 30\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span></code></pre></div>\n<p>Let replace <code class=\"language-text\">\"5 * 6 = 30\"</code> with <code class=\"language-text\">\"5 * 6 = {2}\"</code>. <code class=\"language-text\">2</code> is the index of parameter value <code class=\"language-text\">5*6</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 * 6 = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span></code></pre></div>\n<p>Cool! Progress made.</p>\n<p>Let's replace <code class=\"language-text\">5 * 6</code> with the right indices - <code class=\"language-text\">{0} * {1}</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">6</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span></code></pre></div>\n<p>The great thing about this, is now we can replace the values we passed to <code class=\"language-text\">print()</code> in the first place, without changing the indexes! So, we can display results for <code class=\"language-text\">5 * 7 = 35</code> and <code class=\"language-text\">5 * 8 = 40</code>. We are now able to print <code class=\"language-text\">5 * 6 = 30</code>, <code class=\"language-text\">5 * 7 = 35</code>, <code class=\"language-text\">5 * 8 = 40</code>, and can do similar things for other table entries as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">40</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">40</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Discovered that Python provides a way to do formatted printing of string values</li>\n<li>Looked at the <code class=\"language-text\">format()</code> function, and saw how to call it within <code class=\"language-text\">print()</code></li>\n<li>Observed how we could work only with the indexes of parameters to <code class=\"language-text\">format()</code>, and change the parameters we pass without changing the code</li>\n</ul>\n<p><strong>Step 09: Puzzles On format() and print()</strong></p>\n<p>In this step, let's look at a few puzzles related to the format, and the print methods.</p>\n<p><strong>Snippet-01: format() And print() Puzzles</strong></p>\n<p>Let's say we pass in additional values, such as: <code class=\"language-text\">5 * 8</code>, <code class=\"language-text\">5 * 9</code> and <code class=\"language-text\">5 * 10</code>. However, within the call to <code class=\"language-text\">format()</code>, we are only referring to the values at index <code class=\"language-text\">0</code>, index <code class=\"language-text\">1</code> and index <code class=\"language-text\">2</code>. The values at indexes <code class=\"language-text\">3</code> and <code class=\"language-text\">4</code> are not used at all. What would happen when we run the code?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">40</span></code></pre></div>\n<p>Would this throw an error? No, it does not. You can see that the additional values which are passed in, are conveniently ignored.</p>\n<p>Let's say instead of passing in a value of <code class=\"language-text\">2</code>, we pass <code class=\"language-text\">4</code>. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {4}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">9</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">50</span></code></pre></div>\n<p><code class=\"language-text\">5 * 10</code> is the value at index <code class=\"language-text\">4</code></p>\n<p>Now let's take a different scenario. We remove all the parameters passed to <code class=\"language-text\">format()</code>. However, inside the call to <code class=\"language-text\">print()</code>, we continue to say <code class=\"language-text\">{0} * {1} = {4}</code>. So we are trying to print the value at index <code class=\"language-text\">4</code>, but are only passing two values to the function <code class=\"language-text\">format()</code>. What do you think will happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {4}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    IndexError<span class=\"token punctuation\">:</span> <span class=\"token builtin\">tuple</span> index out of <span class=\"token builtin\">range</span></code></pre></div>\n<p>It says <code class=\"language-text\">IndexError</code>, which means :\"you are asking me to fetch the value at index <code class=\"language-text\">4</code>, but only passing in two values. How can I do what you want?\"</p>\n<p>Let's look at a few more things related to other data types. We try to format the following inside <code class=\"language-text\">print()</code>: <code class=\"language-text\">{0} * {1} = {2}</code>, and would pass in <code class=\"language-text\">2.5</code>, <code class=\"language-text\">2</code>, and <code class=\"language-text\">2.5 * 2</code> . Here, <code class=\"language-text\">2</code> is an integer value, but <code class=\"language-text\">2.5</code> is a floating point value. You can see that it prints <code class=\"language-text\">2.5 * 2 = 5.0</code>. So this approach of formatting values with <code class=\"language-text\">print()</code>, works also with floating point data as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">2.5</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">2.5</span><span class=\"token operator\">*</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">2.5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">5.0</span></code></pre></div>\n<p>Now, are there are other types of data that <code class=\"language-text\">format()</code> works with? Yes, strings can join the party.</p>\n<p>Let's say over here, we do: <code class=\"language-text\">print(\"My name is {0}\".format(\"Ranga\"))</code>. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"My name is {0}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Ranga\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    My name <span class=\"token keyword\">is</span> Ranga</code></pre></div>\n<p>Index <code class=\"language-text\">0</code> will be replaced with the first parameter to <code class=\"language-text\">format()</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Understood the behavior when the parameters passed to <code class=\"language-text\">format()</code>:</p>\n<ul>\n<li>Exceed the indexes accessed by <code class=\"language-text\">print()</code></li>\n<li>Are less than the indexes accessed by <code class=\"language-text\">print()</code></li>\n<li>Are of type integer, floating-point or string</li>\n</ul>\n</li>\n</ul>\n<p><strong>Step 10: Introducing Variables</strong></p>\n<p>We are slowly making progress toward our main goal, which is to print the <code class=\"language-text\">5</code> multiplication table.</p>\n<p>In the first statement, we are printing <code class=\"language-text\">5 * 1 = 5</code>, and then changing the literals. To make it print <code class=\"language-text\">5 * 2 = 10</code>, we are changing <code class=\"language-text\">1</code> to <code class=\"language-text\">2</code>. Next, we are changing <code class=\"language-text\">2</code> to <code class=\"language-text\">3</code>. How do we make it a little simpler, so that our effort is reduced?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span></code></pre></div>\n<p>Let's try a different approach.</p>\n<p>What would happen if you replace <code class=\"language-text\">1</code> with <code class=\"language-text\">index</code>, and <code class=\"language-text\">5 * 1</code> with <code class=\"language-text\">5 * index</code>, and try to run it?</p>\n<p>It gives an error! It says: \"index is not defined\".</p>\n<p>Let's try and fix this, and execute <code class=\"language-text\">index = 2</code>. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">2</span></code></pre></div>\n<p>Aha! This compiles.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span></code></pre></div>\n<p>And this statement is printing <code class=\"language-text\">5 * 2 = 10</code>.</p>\n<p>Let's try something else. Let's make <code class=\"language-text\">index = 3</code>. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span></code></pre></div>\n<p>The same statement on being run, prints <code class=\"language-text\">5 * 3 = 15</code>.</p>\n<p>How can you check the value that <code class=\"language-text\">index</code> has? Just type in <code class=\"language-text\">index</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index\n    <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span></code></pre></div>\n<p>The <code class=\"language-text\">index</code> symbol we have used here, is what is called a <strong>variable</strong>.</p>\n<p>In Python, it's also called a <strong>name</strong>.</p>\n<p>You can see that the value <code class=\"language-text\">index</code> referring to, can change over the duration of a program.</p>\n<p>Initially, <code class=\"language-text\">index</code> was referring to a value of <code class=\"language-text\">1</code>. later, <code class=\"language-text\">index</code> was referring to a value of <code class=\"language-text\">3</code>.</p>\n<p>Now, think about how you would print the entire table. All that you need to do, is start from <code class=\"language-text\">1</code>, execute the same statement with <code class=\"language-text\">print()</code> and <code class=\"language-text\">format()</code>, to get output <code class=\"language-text\">5 * 1 = 5</code>. Next, Change the value of index to <code class=\"language-text\">2</code>, and then print the same statement. Next, <code class=\"language-text\">index = 3</code>, and print the same statement again.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span></code></pre></div>\n<p>With the same statement <code class=\"language-text\">print(\"{0} * {1} = {2}\".format(5,index,5*index))</code>, we are able to print different values. The value of <code class=\"language-text\">index</code> varies, but the code remains the same!</p>\n<p>Variables make the program much more easier to read, as well as more generic.</p>\n<p><strong>Snippet-02: Classroom Exercise On Variables</strong></p>\n<p>Let's do a simple exercise with variables.</p>\n<p>We want to create three variables <code class=\"language-text\">a</code>, <code class=\"language-text\">b</code> and <code class=\"language-text\">c</code>. Let's initially give them some values, say a value of <code class=\"language-text\">5</code> to <code class=\"language-text\">a</code>, <code class=\"language-text\">6</code> to <code class=\"language-text\">b</code> and <code class=\"language-text\">7</code> to <code class=\"language-text\">c</code>.</p>\n<p>We want to get output of this kind: <code class=\"language-text\">5 + 6 + 7 = 18</code>, without using the literal values.</p>\n<p>You would want to use the values stored in the variables in <code class=\"language-text\">a</code>, <code class=\"language-text\">b</code> and <code class=\"language-text\">c</code>.</p>\n<p>If you're hard-coding, the way to do it is with <code class=\"language-text\">print(\"5 + 6 + 7 = 18\")</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 + 6 + 7 = 18\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span> <span class=\"token operator\">+</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">18</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 + 6 + 7 = 18\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">,</span>c<span class=\"token punctuation\">,</span>a<span class=\"token operator\">+</span>b<span class=\"token operator\">+</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span> <span class=\"token operator\">+</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">18</span></code></pre></div>\n<p>The way you can do that is with code like this: <code class=\"language-text\">print(\"{0} + {1} + {2} = {3}\".format(a,b,c,a+b+c))</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} + {1} + {2} = {3}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">,</span>c<span class=\"token punctuation\">,</span>a<span class=\"token operator\">+</span>b<span class=\"token operator\">+</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">+</span> <span class=\"token number\">6</span> <span class=\"token operator\">+</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">18</span></code></pre></div>\n<p>How do you confirm we are accessing values stored in the variables?</p>\n<p>Let's change the values of <code class=\"language-text\">a</code>, <code class=\"language-text\">b</code> and <code class=\"language-text\">c</code>. Let's make <code class=\"language-text\">a = 6</code> , <code class=\"language-text\">b = 7</code> , and <code class=\"language-text\">c = 8</code> . Execute same statement.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">8</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} + {1} + {2} = {3}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">,</span>c<span class=\"token punctuation\">,</span>a<span class=\"token operator\">+</span>b<span class=\"token operator\">+</span>c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">6</span> <span class=\"token operator\">+</span> <span class=\"token number\">7</span> <span class=\"token operator\">+</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">21</span></code></pre></div>\n<p>You can see the magic of variables at play here! Based on what values these variables are referring to, you can see that the output of the print statement changes.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to variables, or names, in Python</li>\n<li>Observed how we could pass in values of variables to the <code class=\"language-text\">format()</code> function</li>\n</ul>\n<p><strong>Step 11: Puzzles On Variables</strong></p>\n<p>In the previous step, we were introduced to the concept of variables in Python.</p>\n<p>We will start with looking at a few puzzles.</p>\n<p><strong>Snippet-01: Puzzles On Variables</strong></p>\n<p>What if I try to refer to a variable which is not yet created?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> count\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'count'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'count'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>Before using a variable, you need to have it assigned a value. If you have not defined a variable before, then you cannot use it. Consider <code class=\"language-text\">print(count)</code>, it does not know what count is. So it would throw an error, saying: \"<code class=\"language-text\">count</code> is not defined, I have no idea what count is.\"</p>\n<p>Once you assign a value to a variable, you can use it.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> count <span class=\"token operator\">=</span> <span class=\"token number\">4</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>count<span class=\"token punctuation\">)</span>\n    <span class=\"token number\">4</span></code></pre></div>\n<p>The statement <code class=\"language-text\">count = 4</code> where we are creating a variable named <code class=\"language-text\">count</code> for the first time, is called a <strong>variable definition</strong>.</p>\n<p>This is the first time you're referring to a variable, and assigning a value to it.</p>\n<p>Python will create a variable in its memory.</p>\n<p>Variable names are case sensitive. <code class=\"language-text\">count</code> and <code class=\"language-text\">Count</code> are not the same thing.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> Count\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'Count'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> count\n    <span class=\"token number\">4</span></code></pre></div>\n<p>There are rules to follow while naming variables.</p>\n<p>All variable names should either start with an alphabet , or an underscore <code class=\"language-text\">_</code> . <code class=\"language-text\">count</code>, <code class=\"language-text\">_count</code> are valid. <code class=\"language-text\">1count</code> is invalid.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> 1count <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        1count <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n             <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> count <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> _count <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> 1count\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        1count\n             <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> 2count\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        2count\n             <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p>After the first symbol, you can also use a numeral in variable names.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c12345 <span class=\"token operator\">=</span> <span class=\"token number\">5</span></code></pre></div>\n<p>To summarize the rules for naming variables.</p>\n<ul>\n<li>This should start with an alphabet (a capital or a small alphabet) or underscore.</li>\n<li>Starting the second character, it can be alphabet, or underscore, or a numeric value.</li>\n</ul>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Understood that a variable needs to be defined before it is used</li>\n<li>Learned that there are certain rules to be followed while giving names to variables</li>\n</ul>\n<p><strong>Step 12: Introducing Assignment</strong></p>\n<p>In this step, we will look at an important concept in Python, called <strong>assignment</strong>. In previous steps, we created variables, like <code class=\"language-text\">i = 5</code>.</p>\n<p><strong>Snippet-01: Introducing Assignment</strong></p>\n<p>You can create other variables using whatever value <code class=\"language-text\">i</code> is referring to. If we say <code class=\"language-text\">j = i</code>, what would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> i\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j\n    <span class=\"token number\">5</span></code></pre></div>\n<p><code class=\"language-text\">j</code> would start referring to the same value that <code class=\"language-text\">i</code> is referring to. This statement is called an <strong>assignment</strong>.</p>\n<p>Let's try <code class=\"language-text\">j = 2 * i</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> i\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j\n    <span class=\"token number\">10</span></code></pre></div>\n<p><code class=\"language-text\">j</code> refers to a value of <code class=\"language-text\">10</code></p>\n<p><code class=\"language-text\">=</code> has a different meaning in programming compared to mathematics.</p>\n<p>In mathematics, When we execute <code class=\"language-text\">j = i</code>, it means <code class=\"language-text\">j</code> and <code class=\"language-text\">i</code> are equal.</p>\n<p>In prgramming, the value of the expression on right hand side is assigned to the variable on the right hand side. Can you use a constant on the left hand side of an assignment? The answer is \"No\"!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> j\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n    SyntaxError<span class=\"token punctuation\">:</span> can't assign to literal</code></pre></div>\n<p>The Python Shell throws an error, saying \"Can't assign to literal\", as <code class=\"language-text\">5</code> is a literal.</p>\n<p>Let's create a couple of variables. <code class=\"language-text\">num1 = 5</code> and <code class=\"language-text\">num2 = 3</code>. We would want to add these and create a fresh variable. Let's say the name of the variable is <code class=\"language-text\">sum</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> num1 <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> num2 <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> num1 <span class=\"token operator\">+</span> num2\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span>\n    <span class=\"token number\">8</span></code></pre></div>\n<p>Create 3 variables <code class=\"language-text\">a</code>, <code class=\"language-text\">b</code> and <code class=\"language-text\">c</code> with different values and calculate their sum.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span>\n    <span class=\"token number\">18</span></code></pre></div>\n<p>We have just seen the mechanics of how assignment works in Python.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned what happens when you assign a value to a variable, which may or may not exist</li>\n<li>Discovered that literal constants cannot be placed on the left hand side of the assignment(<code class=\"language-text\">=</code>) operator</li>\n</ul>\n<p><strong>Step 13: Introducing Formatted Printing</strong></p>\n<p>Until now, we have been using the <code class=\"language-text\">format()</code> method to format and print values. Let's see a better approach to printing values.</p>\n<p>This is the approach we used until now.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} + {1} + {2} = {3}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c <span class=\"token punctuation\">,</span><span class=\"token builtin\">sum</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">6</span></code></pre></div>\n<p>Python has the concept of formatted strings. The syntax to use a formatted string is very simple - <code class=\"language-text\">f\"\"</code>.</p>\n<p>If we want to print the value of a variable <code class=\"language-text\">a</code>, we can use <code class=\"language-text\">{a}</code> in the text.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"value of a is </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>a<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    value of a <span class=\"token keyword\">is</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"value of b is </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>b<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    value of b <span class=\"token keyword\">is</span> <span class=\"token number\">2</span></code></pre></div>\n<p>The variable within braces is replaced by its value.</p>\n<p>You can use expressions in a formatted string. Example below uses <code class=\"language-text\">{a+b}</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"sum of a and b is </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>a <span class=\"token operator\">+</span> b<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token builtin\">sum</span> of a <span class=\"token keyword\">and</span> b <span class=\"token keyword\">is</span> <span class=\"token number\">3</span></code></pre></div>\n<p>This feature was introduced in a Python 3 release.</p>\n<p>Let's get back to the original problem we wanted to solve: printing <code class=\"language-text\">5 + 6 + 7 = 18</code>, using formatted strings.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>a<span class=\"token punctuation\">}</span></span><span class=\"token string\"> + </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>b<span class=\"token punctuation\">}</span></span><span class=\"token string\"> + </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>c<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token builtin\">sum</span><span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span> <span class=\"token operator\">+</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">6</span></code></pre></div>\n<p>You can see how easy it turns out to be!</p>\n<p><strong>Step 14: The PMT-Challenge Revisited</strong></p>\n<p>We want to print the <code class=\"language-text\">5</code>-table from <code class=\"language-text\">5 * 1 = 5</code> onward, until we reach to <code class=\"language-text\">5 * 10 = 50</code>. The best solution we have right now, is shown below:</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> <span class=\"token number\">4</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">20</span></code></pre></div>\n<p>Can we do something, to make sure that the code remains the same all the time, but the <code class=\"language-text\">index</code> value gets updated?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> index <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">25</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> index <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> index <span class=\"token operator\">=</span> index <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"{0} * {1} = {2}\"</span><span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span>index<span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span></code></pre></div>\n<p>We used <code class=\"language-text\">index = index + 1</code> to increment <code class=\"language-text\">index</code> value.</p>\n<p>If we execute these same two statements again and again, we can print the entire table! This is exactly what loops help us do: execute the same statements repeatedly.</p>\n<p>The simplest loop available in Python is the <strong>for loop</strong>.</p>\n<p>When we run a <code class=\"language-text\">for</code> loop, we need to specify the range of values - <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code> or <code class=\"language-text\">1</code> to <code class=\"language-text\">20</code>, and so on. <code class=\"language-text\">range()</code> function helps us to specify a range of values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n    <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The syntax of the <code class=\"language-text\">for</code> loop is: <code class=\"language-text\">for i in range(1, 10): ...</code>. Here, <code class=\"language-text\">i</code> is the name of the <strong>control variable</strong>. In Python, you need to put a colon, '<code class=\"language-text\">:</code>', and in the next line give indentation.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">9</span></code></pre></div>\n<p>You would see that it prints from <code class=\"language-text\">1</code> to <code class=\"language-text\">9</code>.</p>\n<p>When we run a loop in <code class=\"language-text\">range(1, 10)</code>, <code class=\"language-text\">1</code> is <em>inclusive</em> and <code class=\"language-text\">10</code> is <strong>exclusive</strong>.The loop runs from <code class=\"language-text\">1</code> to the value before <code class=\"language-text\">10</code>, which is <code class=\"language-text\">9</code>.</p>\n<p>The leading whitespace before <code class=\"language-text\">print(i)</code> is called <strong>indentation</strong>. We'll talk about indentation later, when we talk about puzzles related to the <code class=\"language-text\">for</code> loop.</p>\n<p>How can you extend this concept to solving our <em>PMT-Challenge</em> problem?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">5</span><span class=\"token punctuation\">}</span></span><span class=\"token string\"> * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>index<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">5</span><span class=\"token operator\">*</span>index<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span></code></pre></div>\n<p>What we were doing earlier, was calling <code class=\"language-text\">print()</code> with a formatted string. Now we want to print this statement for different values of <code class=\"language-text\">i</code>.</p>\n<p>How can you do that?</p>\n<p>Let's start with a simple example.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">10</span></code></pre></div>\n<p><code class=\"language-text\">print(f\"{i}\")</code> prints the value of i.</p>\n<p>Now, how do we get it to print <code class=\"language-text\">5 * 1 = 5</code> to <code class=\"language-text\">5 * 10 = 50</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"5 * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">5</span> <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">20</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">25</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">40</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">9</span> <span class=\"token operator\">=</span> <span class=\"token number\">45</span>\n    <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">=</span> <span class=\"token number\">50</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">*</span> <span class=\"token number\">50</span>\n    <span class=\"token number\">1000</span></code></pre></div>\n<p><code class=\"language-text\">print(f\"5 * {i} = {5 * i}\")</code> prints a specific multiple of 5.</p>\n<p><strong>Step 15: Loops</strong></p>\n<p>In a previous step, we took a major step in programming. We wrote our first for loop with Python. In this step, let's try a few puzzles to understand the for loop even further.</p>\n<p>The syntax of the for loop we looked at earlier was:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">  <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's say we write a <code class=\"language-text\">for</code> loop, but don't give a <code class=\"language-text\">:</code> after the <code class=\"language-text\">range()</code> method, to close the first line. What would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n                           <span class=\"token operator\">^</span>\n        SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p>Invalid syntax. A <code class=\"language-text\">:</code> is mandatory within the <code class=\"language-text\">for</code> loop syntax.</p>\n<p>Let's provide a <code class=\"language-text\">:</code> and in the next line, use <code class=\"language-text\">print(i)</code> without space before it (without indentation).</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">2</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">^</span>\n    IndentationError<span class=\"token punctuation\">:</span> expected an indented block</code></pre></div>\n<p>Most other programming languages use open brace <code class=\"language-text\">{</code> and closed brace <code class=\"language-text\">}</code> as delimiters in a <code class=\"language-text\">for</code> loop. However, Python uses indentation to identify which code is part of a <code class=\"language-text\">for</code> loop, and which is not. So if we are writing the body of a <code class=\"language-text\">for</code> loop, we must use indentation, and leave atleast a single <code class=\"language-text\">&lt;SPACE></code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">9</span></code></pre></div>\n<p>How do we execute two lines of code as part of the <code class=\"language-text\">for</code> loop?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token operator\">*</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">10</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">12</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">14</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">16</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">18</span></code></pre></div>\n<p>We are indenting both statements with a space - <code class=\"language-text\">print(i)</code> and <code class=\"language-text\">print(2*i)</code>.</p>\n<p>When for loop has only one line of code, you can specify it right after the <code class=\"language-text\">:</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span></code></pre></div>\n<p>However, this is not considered to be a good programming practice. Even though you may want to execute just one statement in a <code class=\"language-text\">for</code> loop, indentation on a new line is recommended.</p>\n<p>Another best practice is to use four <code class=\"language-text\">&lt;SPACE></code>s for indentation, instead of just two. This would give clear indentation of the code.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span></code></pre></div>\n<p>Anybody who looks at the code immediately understands that this <code class=\"language-text\">print()</code> is part of the <code class=\"language-text\">for</code> loop.</p>\n<p>Let's say you only want to print the odd numbers till <code class=\"language-text\">10</code>, which are <code class=\"language-text\">1</code>, <code class=\"language-text\">3</code>, <code class=\"language-text\">5</code>, <code class=\"language-text\">7</code> and <code class=\"language-text\">9</code>. The <code class=\"language-text\">range()</code> function offers an interesting option.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">9</span></code></pre></div>\n<p>In <code class=\"language-text\">for i in range(1, 11, 2)</code>, we pass in a third argument, called a <em>step</em>. After each iteration, the value of <code class=\"language-text\">i</code> is increment by <code class=\"language-text\">step</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Looked at a few puzzles about the <code class=\"language-text\">for</code> loop, which lay emphasis on the following aspects of for:</p>\n<ul>\n<li>The importance of syntax elements such as the colon</li>\n<li>Indentation</li>\n<li>Variations of the <code class=\"language-text\">range()</code> function</li>\n</ul>\n</li>\n</ul>\n<p><strong>Step 16: Programming Exercise PE-BA-02</strong></p>\n<p>In the previous step, after initially exploring the Python <code class=\"language-text\">for</code> loop, we looked at a number of puzzles.</p>\n<p>In this step, let's look at a few exercises.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Print the even numbers up to 10. We would want to print 2 4 6 8 10, using a for loop.</li>\n<li>Print the first 10 numbers in reverse</li>\n<li>Print the first 10 even numbers in reverse</li>\n<li>Print the squares of the first 10 numbers</li>\n<li>Print the squares of the first 10 numbers, in reverse</li>\n<li>Print the squares of the even numbers</li>\n</ol>\n<p><strong>Solution 1</strong></p>\n<p>Instead of starting with <code class=\"language-text\">1</code>, we need to start with <code class=\"language-text\">2</code>. Each time, <code class=\"language-text\">i</code> it would be incremented by <code class=\"language-text\">2</code>, and <code class=\"language-text\">2 4 6 8 and 10</code> would be printed.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">10</span></code></pre></div>\n<p><strong>Solution 2</strong></p>\n<p>We would want to print the numbers in reverse. Think about how you would do that using the <code class=\"language-text\">range()</code> function. We'd want go from <code class=\"language-text\">10</code>, <code class=\"language-text\">9</code>, <code class=\"language-text\">8</code>, and so on up to <code class=\"language-text\">1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">10</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">1</span></code></pre></div>\n<p>The value to start with is <code class=\"language-text\">10</code>. As we discussed earlier, the end value is exclusive. So to print from <code class=\"language-text\">10</code> to <code class=\"language-text\">1</code>, we want to end one value which is <code class=\"language-text\">0</code>. <code class=\"language-text\">range(10, 0)</code> seems to be what we need.</p>\n<p>Usually these step value is positive, but we need to go backwards from <code class=\"language-text\">10</code>. Hence, we would give a step value of <code class=\"language-text\">-1</code>.</p>\n<p><strong>Solution 3</strong></p>\n<p>Now, let's print the first <code class=\"language-text\">10</code> even numbers in reverse.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">20</span><span class=\"token punctuation\">,</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">20</span>\n    <span class=\"token number\">18</span>\n    <span class=\"token number\">16</span>\n    <span class=\"token number\">14</span>\n    <span class=\"token number\">12</span>\n    <span class=\"token number\">10</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">2</span></code></pre></div>\n<p><strong>Solution 4</strong></p>\n<p>Next, we would want to print the squares of the first 10 numbers.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">*</span> i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">16</span>\n    <span class=\"token number\">25</span>\n    <span class=\"token number\">36</span>\n    <span class=\"token number\">49</span>\n    <span class=\"token number\">64</span>\n    <span class=\"token number\">81</span>\n    <span class=\"token number\">100</span></code></pre></div>\n<p><strong>Solution 5</strong></p>\n<p>Let's print the squares in the reverse order.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">100</span>\n    <span class=\"token number\">81</span>\n    <span class=\"token number\">64</span>\n    <span class=\"token number\">49</span>\n    <span class=\"token number\">36</span>\n    <span class=\"token number\">25</span>\n    <span class=\"token number\">16</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">1</span></code></pre></div>\n<p><strong>Solution 6</strong></p>\n<p>Print the squares of the even numbers. How to do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">,</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token operator\">-</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">100</span>\n    <span class=\"token number\">64</span>\n    <span class=\"token number\">36</span>\n    <span class=\"token number\">16</span>\n    <span class=\"token number\">4</span></code></pre></div>\n<p>The key part is using a step of <code class=\"language-text\">-2</code></p>\n<p>We leave it as an exercise for you, to print squares of odd numbers.</p>\n<p><strong>Summary</strong></p>\n<p>In this video, we: * Tried out a few exercises involving the for loop, by playing around with printing sequences of numbers.</p>\n<ul>\n<li>Used the for loop to simplify the solution to the <em>PMT-Challenge</em> problem.</li>\n</ul>\n<p><strong>Step 17: Review: The Basics Of Python</strong></p>\n<p>It must have been a roller-coaster ride to solve the multiplication table challenge so far. If you're new to programming, there are a wide range of topics and concepts, that you would have learned during this small journey.</p>\n<p>Let's quickly revise the important concepts we have learned during this small journey.</p>\n<ul>\n<li><code class=\"language-text\">1</code>, <code class=\"language-text\">11</code>, <code class=\"language-text\">5</code>, … are all called literals because these are constant values. Their values don't really change. _Consider <code class=\"language-text\">5 _4_ 50`. This is an expression. `_`is an operator, and`5`, `4`and`50</code> are operands.</li>\n<li>The name <code class=\"language-text\">i</code> in <code class=\"language-text\">i = 1</code>, is called a variable. It can refer to different values, at different points in time.</li>\n<li><code class=\"language-text\">range()</code> and <code class=\"language-text\">print()</code> are in-built Python functions.</li>\n<li>Every complete line of code is called statement. The specific statement <code class=\"language-text\">print()</code>, is invoking a method. The other statement which we looked at earlier, was an assignment statement. <code class=\"language-text\">index = index + 1</code> would evaluate <code class=\"language-text\">index + 1</code>, and have the <code class=\"language-text\">index</code> variable refer to that value.</li>\n<li>The syntax of the <code class=\"language-text\">for</code> loop was very simple. <code class=\"language-text\">for var in range(1, 10) : ...</code>, followed by statements you would want to execute in a loop, with indentation. For the sake of indentation we left four <code class=\"language-text\">&lt;SPACE></code>s in front of each statement inside the <code class=\"language-text\">for</code> loop.</li>\n</ul>\n<p>So that, in a nutshell, is what we have learned over the course of our first section.</p>\n<h4>Chapter 03 - Introducing Methods</h4>\n<p>In the last section, we introduced you to the basics of python. We learned those concepts by applying them to solve the <em>PMT-Challenge</em> problem. The code below is what we ended up with as we solved that chellenge.</p>\n<p><strong>Snippet-01: Current Solution To PMT-Challenge</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"8 * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">8</span> <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>If we wanted to change the code to print the <code class=\"language-text\">7</code> table, we need to change the value <code class=\"language-text\">7</code> used in the for loop, to <code class=\"language-text\">8</code>. It's simple, but still not as friendly as you would like.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"7 * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">7</span> <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>To print a <code class=\"language-text\">7</code> table, it would be awesome if could say <code class=\"language-text\">print_multiplication_table</code>, and give a value of 7 beside it, and it would do the rest:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'print_multiplication_table'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'print_multiplication_table'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>Similarly, <code class=\"language-text\">print_multiplication_table(8)</code>, could print the multiplication table for <code class=\"language-text\">8</code>!</p>\n<p>To be able to do this, we need to create a <strong>method</strong>, or a <strong>function</strong>. Creating a method makes the code <em>reusable</em>, and we can invoke that method very easily by passing <em>arguments</em>.</p>\n<p>In this section, we take an in-depth look at methods.</p>\n<p><strong>Step 01: Defining Your First Method</strong></p>\n<p>Methods are very important building blocks in Python programming. In this step, we will create a simple method that prints <code class=\"language-text\">\"Hello World\"</code>, twice.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>When we talk about a method, we need to give it a name. We are already using an in-built Python method here, which is <code class=\"language-text\">print()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    Hello World\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    Hello World</code></pre></div>\n<p>Similar to that, we need to give a name to our body of code. Let's say the name is <code class=\"language-text\">print_hello_world_twice</code>.</p>\n<p>The syntax to create a method in Python is straightforward:</p>\n<ul>\n<li>At the start, use the keyword <code class=\"language-text\">def</code> followed by a space.</li>\n<li>Followed by name of the method - <code class=\"language-text\">print_hello_world_twice</code>.</li>\n<li>Add a pair of parenthesis: <code class=\"language-text\">()</code>.</li>\n<li>\n<p>This is followed by a colon <code class=\"language-text\">:</code> (similar to what we used in a <code class=\"language-text\">for</code> loop).</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world_twice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n</li>\n</ul>\n<p>All statements in a method should be indented. The two <code class=\"language-text\">print(\"Hello World\")</code> are indented. So, they are part of the method body.</p>\n<p><code class=\"language-text\">print_hello_world_twice()</code> defines a method, and it has certain code inside its body.</p>\n<p>How do we call this method? Is it sufficient to say <code class=\"language-text\">print_hello_world_twice</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_twice\n    <span class=\"token operator\">&lt;</span>function print_hello_world_twice at <span class=\"token number\">0x10a71ef28</span><span class=\"token operator\">></span></code></pre></div>\n<p>Python Shell says, there's a function defined with that specific name.</p>\n<p>How do we execute a method? Very simple! Add a pair of parentheses to the name, <code class=\"language-text\">()</code>!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_twice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_twice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World</code></pre></div>\n<p>Now, we are able to run the method.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned we can define our own methods in the code we write</li>\n<li>Understood how to define a method, and all its syntax elements</li>\n<li>Saw how we can invoke a method we write</li>\n</ul>\n<p><strong>Step 02: Programming Exercise PE-MD-01</strong></p>\n<p>We will now leave you with two exercises, based on what we have learned about methods so far.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Write a method called <code class=\"language-text\">print_hello_world_thrice()</code>. It should print <code class=\"language-text\">\"Hello World\"</code> thrice to the output. Define this method, and also invoke it.</li>\n<li>\n<p>Write and execute a method, that prints four statements:</p>\n<ol>\n<li>\"I have created my first variable.\"</li>\n<li>\"I've created in my first loop.\"</li>\n<li>\"I've created my first method.\"</li>\n<li>\"I am excited to learn Python.\" You need to print these four statements on four consecutive lines.</li>\n</ol>\n</li>\n</ol>\n<p><strong>Solutions</strong></p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world_thrice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_thrice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p><strong>Solution 2</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_your_progress</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 1\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 2\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 3\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 4\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_your_progress<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Statement <span class=\"token number\">1</span>\n    Statement <span class=\"token number\">2</span>\n    Statement <span class=\"token number\">3</span>\n    Statement <span class=\"token number\">4</span>\n\n    <span class=\"token keyword\">def</span> <span class=\"token function\">print_your_progress</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 1\"</span><span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 2\"</span><span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 3\"</span><span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 4\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>For convenience, we have changed the exact text we need to print. Call this method with the syntax <code class=\"language-text\">print_your_progress()</code>, and you're able to execute its code.</p>\n<p>Now try another exercise. We want to print <code class=\"language-text\">\"Statement 1\"</code>, <code class=\"language-text\">\"Statement 2\"</code>, <code class=\"language-text\">\"Statement 3\"</code> and <code class=\"language-text\">\"Statement 4\"</code> on different lines, using just one print statement. How can you do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_your_progress</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Statement 1\\nStatement 2\\nStatement 3\\nStatement 4\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_your_progress<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Statement <span class=\"token number\">1</span>\n    Statement <span class=\"token number\">2</span>\n    Statement <span class=\"token number\">3</span>\n    Statement <span class=\"token number\">4</span></code></pre></div>\n<p>We are using the newline character <code class=\"language-text\">\\n</code>.</p>\n<p>Let's look at the difference between defining and executing a method.</p>\n<p>When we are writing a method definition, we are writing the code as part of its body. It has a specific syntax, and starts with the <code class=\"language-text\">def</code> keyword.</p>\n<p>A definition by itself cannot cause the code in its body to be executed.</p>\n<p><code class=\"language-text\">print_your_progress()</code> represents a method call. The code inside the method is executed.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>\n<p>Implemented solutions to a few exercises that test our understanding of Python methods. We touched concepts such as:</p>\n<ul>\n<li>Defining a method body</li>\n<li>The way to invoke a method, to run its code</li>\n<li>The difference between the two</li>\n</ul>\n</li>\n</ul>\n<p><strong>Step 03: Passing Parameters To Methods</strong></p>\n<p>In the previous step,we created methods. We defined <code class=\"language-text\">print_hello_world_twice()</code>, and this printed <code class=\"language-text\">\"Hello World\"</code> twice. In this step, let's talk about <em>method arguments</em>, or <em>parameters</em>.</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_twice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world_thrice<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p>Earlier, we wrote code for <code class=\"language-text\">print_hello_world_thrice()</code>, which prints the message three times.</p>\n<p>Let's say you want to print it five times. You would need to write another method that does what you need. Doesn't that seem monotonous?</p>\n<p>Instead of that, Won't it be great if I can call the method by the same name, say <code class=\"language-text\">print_hello_world(5)</code>, and it would print \"Hello World\" five times?</p>\n<p>The <code class=\"language-text\">5</code> which we are passing here is called an <strong>argument</strong>.</p>\n<p>How do we define our method to accept this argument?</p>\n<p>Let's call our argument <code class=\"language-text\">no_of_times</code>. If you have any experience with other programming languages, they generally need you to specify the parameter type. Something like <code class=\"language-text\">This parameter is an integer/float/string, or other types</code>. But Python does not require parameter type.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Although we are not doing exactly what we set out to, let's see what would happen. What would happen if we say <code class=\"language-text\">print_hello_world()</code> ?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    TypeError<span class=\"token punctuation\">:</span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> missing <span class=\"token number\">1</span> required positional argument<span class=\"token punctuation\">:</span> <span class=\"token string\">'no_of_times'</span></code></pre></div>\n<p>Error! Something like \"Hey, you have created <code class=\"language-text\">print_hello_world</code> with a parameter, but not passing anything in here! Go ahead and pass a value\". Let's pass in a value, such as <code class=\"language-text\">5</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    Hello World\n    <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span>\n    Hello World\n    <span class=\"token number\">10</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">)</span>\n    Hello World\n    <span class=\"token number\">100</span></code></pre></div>\n<p>With <code class=\"language-text\">print_hello_world(5)</code>, you can see <code class=\"language-text\">\"Hello World\"</code> and <code class=\"language-text\">5</code> being printed. We are now able to define this method to accept a value, and print that value by invoking it. You can pass in any value, such as<code class=\"language-text\">10</code>, <code class=\"language-text\">100</code>, or others.</p>\n<p>Now think of a different solution for this method, where you don't repeat the same piece of code to print <code class=\"language-text\">\"Hello World\"</code>. Consider <code class=\"language-text\">print_hello_world(5)</code>, it should still print <code class=\"language-text\">\"Hello World\"</code> <code class=\"language-text\">5</code> times. How do you do that?</p>\n<p>Think about using something along the lines of a loop.</p>\n<p><strong>Snippet-02:</strong></p>\n<p>For now, what we are doing is we are printing <code class=\"language-text\">\"Hello World\"</code> <code class=\"language-text\">10</code> times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p>Our method call <code class=\"language-text\">print_hello_world(5)</code> now prints <code class=\"language-text\">\"Hello World\"</code> <code class=\"language-text\">10</code> times.</p>\n<p>However just print the message <code class=\"language-text\">5</code> times. We need to make use of the parameter <code class=\"language-text\">no_of_times</code> inside the <code class=\"language-text\">for</code> loop as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p>Now let's execute the method again. You can see that it's printing <code class=\"language-text\">4</code> times only.</p>\n<p>Why is it not printing <code class=\"language-text\">5</code> times?</p>\n<p>That's because <code class=\"language-text\">no_of_times</code> as a second parameter to <code class=\"language-text\">range()</code> is exclusive.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p>Great, it's now printing the message <code class=\"language-text\">5</code> times!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_hello_world<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p>If you pass a different argument like <code class=\"language-text\">7</code>, the message is displayed <code class=\"language-text\">7</code> times.</p>\n<p>Something you need to always be cautious about in Python, is the indentation. Over here, the <code class=\"language-text\">for</code> loop is part of the method body. So we have extra indentation for it. The print is part of the <code class=\"language-text\">for</code> loop body. So guess what, even more indentation for that code.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned how to pass arguments to a method</li>\n<li>Understood that the method definition needs to have parameters coded in</li>\n<li>Observed that arguments passed during a method call can be accessed inside a methods body</li>\n</ul>\n<p><strong>Step 04: Classroom Exercise CE-MD-01</strong></p>\n<p>In this step, Let's look at a few exercises related to the method parameter.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Write a method called <code class=\"language-text\">print_numbers()</code>, that would print all successive integers from <code class=\"language-text\">1</code> to <code class=\"language-text\">n</code>.</li>\n<li>The second one is to write a method called <code class=\"language-text\">print_squares_of_numbers()</code>, that prints squares of all successive integers from <code class=\"language-text\">1</code> to <code class=\"language-text\">n</code>.</li>\n</ol>\n<p><strong>Solutions</strong></p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_numbers</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> n<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>If you are programming in other languages such as Java, you are used to naming methods in this way: <code class=\"language-text\">printNumbers()</code>. This convention is popularly known as \"Camel Case\".</p>\n<p>That's NOT how Python programmers name their methods. Pythonic way is to use underscore <code class=\"language-text\">_</code> to separate words in the method name, as in <code class=\"language-text\">print_numbers()</code>.</p>\n<p><strong>Solution 2</strong></p>\n<p>Let's define <code class=\"language-text\">print_squares_of_numbers()</code>. This would be very similar to <code class=\"language-text\">print_numbers()</code>, working with the same range. Only, we need to say <code class=\"language-text\">print(i*i)</code> .</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_squares_of_numbers</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> n<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_squares_of_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">16</span>\n    <span class=\"token number\">25</span></code></pre></div>\n<p>How is a parameter different from an argument?</p>\n<ul>\n<li>Inside the definition of the method, the name within parentheses is referred to as a <strong>parameter</strong>. In our recent exercise, <code class=\"language-text\">n</code> is a parameter, because it's used in the definition of <code class=\"language-text\">print_squares_of_numbers</code>.</li>\n<li>When you are passing a value to a method during a method call, say <code class=\"language-text\">5</code>, that value is called an <strong>argument</strong>.</li>\n<li>\n<p>Don't worry too much about it. Just follow this convention for now:</p>\n<ul>\n<li>In the method call, call it an <em>argument</em>.</li>\n<li>In a method definition, call it a <em>parameter</em>.</li>\n</ul>\n</li>\n</ul>\n<p><strong>Summary</strong></p>\n<p>In this step, we looked at a few simple exercises related to passing method arguments</p>\n<p><strong>Step 05: Methods With Multiple Parameters</strong></p>\n<p>In this step, let's look at creating a method with multiple parameters.</p>\n<p><strong>Snippet-01:</strong></p>\n<p><code class=\"language-text\">print_hello_world</code> accepts one parameter and prints \"Hello World\" the specified number of times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_hello_world</span><span class=\"token punctuation\">(</span>no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Let's say we want to print another piece of text <code class=\"language-text\">Welcome To Python</code>, a specified number of times. How do you do that?</p>\n<p>You can always create another method similar to the first one, such as <code class=\"language-text\">print_welcome_to_python(no_of_times)</code> and print the necessary text inside.</p>\n<p>However, is that what a good programmer does?</p>\n<p>A good programmer tries to create a more generic solution.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_string</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">,</span> no_of_times<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p>The good programmer that you are, you created a new method called <code class=\"language-text\">print_string(str, no_of_times)</code> accepting a text parameter, in addition to <code class=\"language-text\">no_of_times</code>.</p>\n<p>Syntax rules for method parameters are quite strict. If we say <code class=\"language-text\">print_string(\"Welcome to Python\")</code> and run it, we get an error! Python Shell says: \"I need <code class=\"language-text\">no_of_times</code> to be present in here\".</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token string\">\"Welcome to Python\"</span><span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    TypeError<span class=\"token punctuation\">:</span> print_string<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> missing <span class=\"token number\">1</span> required positional argument<span class=\"token punctuation\">:</span> <span class=\"token string\">'no_of_times'</span></code></pre></div>\n<p>Let's say you want to assign default values for <code class=\"language-text\">str</code> and <code class=\"language-text\">no_of_times</code> in <code class=\"language-text\">print_string()</code>. By default, we want to always print <code class=\"language-text\">\"Hello World\"</code>, and that too <code class=\"language-text\">5</code> times.</p>\n<p>The Python language makes this very easy. <code class=\"language-text\">def print_string(str = \"Hello World\", no_of_times=5)</code>. The rest of the method remains the same.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_string</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token operator\">=</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">,</span> no_of_times<span class=\"token operator\">=</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Now you can call <code class=\"language-text\">print_string()</code>, and <code class=\"language-text\">\"Hello World\"</code> is displayed <code class=\"language-text\">5</code> times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p>If it's <code class=\"language-text\">print_string(\"Welcome To Python\")</code>, what does it do? It prints <code class=\"language-text\">\"Welcome To Python\"</code>, <code class=\"language-text\">5</code> times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token string\">\"Welcome to Python\"</span><span class=\"token punctuation\">)</span>\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python</code></pre></div>\n<p>Consider <code class=\"language-text\">print_string(\"Welcome to Python\", 8)</code>, it would print that string <code class=\"language-text\">8</code> times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token string\">\"Welcome to Python\"</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">)</span>\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python\n    Welcome to Python</code></pre></div>\n<p>Isn't that cool!</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at how to pass multiple parameters to a method, starting with two arguments</li>\n<li>Learned how you can define default values for those parameters</li>\n<li>Observed we could pass default arguments for none, some or all of those parameters</li>\n</ul>\n<p><strong>Step 06: Back To Multiplication Table - Using Methods</strong></p>\n<p>Let's get back to our original goal, of why we needed methods. We wanted to create a multiplication table for a number, and observed that each time we needed to we needed change that number, we were forced to make a change in the code. This is not something we liked, and that's why we started investigating how methods can be used.</p>\n<p>In this step, Let's try our hand at creating a multiplication table method.</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"7 * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span><span class=\"token number\">7</span> <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Let's define a method called <code class=\"language-text\">print_multiplication_table()</code>, and pass in a parameter to it.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_multiplication_table</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table<span class=\"token punctuation\">}</span></span><span class=\"token string\"> * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">14</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">21</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">28</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">42</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">49</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">56</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">9</span> <span class=\"token operator\">=</span> <span class=\"token number\">63</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">=</span> <span class=\"token number\">70</span></code></pre></div>\n<p>Now you have the entire multiplication table for <code class=\"language-text\">7</code>.</p>\n<p>You can then call <code class=\"language-text\">print_multiplication_table()</code> with arguments <code class=\"language-text\">8</code>, <code class=\"language-text\">9</code>,and so on, by simply changing the <code class=\"language-text\">table</code> arguemnt value.</p>\n<p>We now want to create even better <code class=\"language-text\">print_multiplication_table()</code> method.</p>\n<p>We want to control the start point, as well as the end point, in the call to <code class=\"language-text\">range()</code>. We want to say <code class=\"language-text\">print_multiplication_table(7, 1, 6)</code>, to print the <code class=\"language-text\">7</code> table with entries from <code class=\"language-text\">1</code> to <code class=\"language-text\">6</code>. How can you do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_multiplication_table</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">,</span> start<span class=\"token punctuation\">,</span> end<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table<span class=\"token punctuation\">}</span></span><span class=\"token string\"> * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span> <span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">14</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">21</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">28</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">42</span></code></pre></div>\n<p>Simple! Define those range limits as additional parameters!</p>\n<p>The other thing we can obviously do, is have default values for the <code class=\"language-text\">start</code>, and the <code class=\"language-text\">end</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_multiplication_table</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">,</span> start<span class=\"token operator\">=</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span>start<span class=\"token punctuation\">,</span> end<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>       <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table<span class=\"token punctuation\">}</span></span><span class=\"token string\"> * </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> = </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>table <span class=\"token operator\">*</span> i<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_multiplication_table<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">1</span> <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">2</span> <span class=\"token operator\">=</span> <span class=\"token number\">14</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">3</span> <span class=\"token operator\">=</span> <span class=\"token number\">21</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">4</span> <span class=\"token operator\">=</span> <span class=\"token number\">28</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">5</span> <span class=\"token operator\">=</span> <span class=\"token number\">35</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">6</span> <span class=\"token operator\">=</span> <span class=\"token number\">42</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">7</span> <span class=\"token operator\">=</span> <span class=\"token number\">49</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">8</span> <span class=\"token operator\">=</span> <span class=\"token number\">56</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">9</span> <span class=\"token operator\">=</span> <span class=\"token number\">63</span>\n    <span class=\"token number\">7</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span> <span class=\"token operator\">=</span> <span class=\"token number\">70</span></code></pre></div>\n<p>Calling <code class=\"language-text\">print_multiplication_table(7)</code> would give us entries from <code class=\"language-text\">7 * 1 = 7</code> to <code class=\"language-text\">7 * 10 = 70</code>.</p>\n<p>Now you can actually send out this method, to your friends, who would find it easy to use, and cool!</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned how to define a method to print the multiplication table for a number</li>\n<li>Looked at how to enhance this method to make table printing more flexible</li>\n<li>Further enhanced that method to accept default arguments while printing a table</li>\n</ul>\n<p><strong>Step 07: Indentation Is King</strong></p>\n<p>In Python, indentation denote blocks of code. So if you want to put something in a <code class=\"language-text\">for</code> loop, or outside it, proper indentation would be sufficient. In this step, let's explore indentation in depth. Let's start by creating a simple method.</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">method_to_understand_indentation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> method_to_understand_indentation<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">10</span></code></pre></div>\n<p>Consider the code below: <code class=\"language-text\">print(5)</code> is indented at the same level as <code class=\"language-text\">for loop</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">method_to_understand_indentation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>You can see that <code class=\"language-text\">print(5)</code> is called only once. It is not part of the <code class=\"language-text\">for loop</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> method_to_understand_indentation<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">10</span>\n    <span class=\"token number\">5</span></code></pre></div>\n<p>Let's change the code in this method a bit. <code class=\"language-text\">print(5)</code> is indented the same way as <code class=\"language-text\">print(i)</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">method_to_understand_indentation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p><code class=\"language-text\">print(5)</code> is part of the for loop. It is executed 10 times.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> method_to_understand_indentation<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">10</span>\n    <span class=\"token number\">5</span></code></pre></div>\n<p>Whether we're talking about loops, methods or conditionals, proper indentation is very important in Python.</p>\n<p>We indicate a block of code, by having all lines of that block at the same indentation level. There are no specific delimiters like for instance a pair of braces <code class=\"language-text\">{...}</code>, as in other programming languages.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Ran through a few examples to see how indentation works in Python</li>\n</ul>\n<p><strong>Step 08: Puzzles on Methods - Named Parameters</strong></p>\n<p>In this step, let's look at a variety of puzzles related to methods.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Consider the following method: I would want to print the default string 6 times. How do we do it?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">print_string</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token operator\">=</span><span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">,</span> no_of_times<span class=\"token operator\">=</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>no_of_times<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p>Will it work if we call the method as in: <code class=\"language-text\">print_string(6)</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">6</span></code></pre></div>\n<p><code class=\"language-text\">6</code> is passed as the first parameter. <code class=\"language-text\">6</code> is matched to <code class=\"language-text\">str</code>, and the method prints <code class=\"language-text\">6</code> the default number of times, which is <code class=\"language-text\">5</code>.</p>\n<p>to default to <code class=\"language-text\">\"Hello World\"</code>, and print it <code class=\"language-text\">6</code> times.</p>\n<p>You can do this in Python by using <strong>named parameters</strong>. During the method call, you can specify <code class=\"language-text\">no_of_times = 6</code>. <strong><code class=\"language-text\">no_of_times</code></strong> is a named parameter.</p>\n<blockquote>\n<p>There is no provision of doing something like this, in other languages like Java.</p>\n</blockquote>\n<p>Call it as <code class=\"language-text\">print_string(no_of_times=6)</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span>no_of_times<span class=\"token operator\">=</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World\n    Hello World</code></pre></div>\n<p><code class=\"language-text\">str</code> gets a default value, and <code class=\"language-text\">\"Hello World\"</code> is printed <code class=\"language-text\">6</code> times.</p>\n<p>Named parameters are very useful, when a method has a number of parameters, and you would want to make it very clear which parameter you're passing a value for.</p>\n<p>Let's call <code class=\"language-text\">print_string(7, 8)</code>. what happens?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">7</span></code></pre></div>\n<p>You would see that <code class=\"language-text\">7</code> is printed <code class=\"language-text\">8</code> times.</p>\n<p>Since <code class=\"language-text\">print()</code> method is quite flexible, you can pass a number as the first argument. You can even pass a <code class=\"language-text\">float</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token number\">7.5</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">7.5</span>\n    <span class=\"token number\">7.5</span>\n    <span class=\"token number\">7.5</span>\n    <span class=\"token number\">7.5</span>\n    <span class=\"token number\">7.5</span>\n    <span class=\"token number\">7.5</span>\n    <span class=\"token number\">7.5</span>\n    <span class=\"token number\">7.5</span></code></pre></div>\n<p>What would be the result of this - <code class=\"language-text\">print_string(7.5, \"eight\")</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> print_string<span class=\"token punctuation\">(</span><span class=\"token number\">7.5</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"eight\"</span><span class=\"token punctuation\">)</span>\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> print_string\n    TypeError<span class=\"token punctuation\">:</span> must be <span class=\"token builtin\">str</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">not</span> <span class=\"token builtin\">int</span></code></pre></div>\n<p>Note how <code class=\"language-text\">no_of_times</code> is used inside the method… as an argument to <code class=\"language-text\">range()</code>. <code class=\"language-text\">range()</code> only accepts integers, nothing else. When you run the code with <code class=\"language-text\">print_string(7.5, \"eight\")</code>, we get an error.</p>\n<p>It says: <code class=\"language-text\">TypeError: ```no_of_times``` must be ```int```, not string</code>.</p>\n<p>A simple rule of thumb is, if you have a parameter, you can pass any type of data to it. That could be an integer, a floating point value a string, or a boolean value. The Python language does not check for the type of a parameter. However, Python will throw an error if the function which is using that parameter, expects it to be of a specific type. The <code class=\"language-text\">range()</code> function expects that the <code class=\"language-text\">no_of_times</code> is an integer value.</p>\n<p><strong>Snippet-02:</strong></p>\n<p>The last thing which we would be looking at, is method naming conventions. We named our methods in a consistent way: <code class=\"language-text\">print_string</code>, <code class=\"language-text\">print_multiplication_table</code>, and the like.</p>\n<p>This is exactly the format which most Python developers use, to name their methods.</p>\n<p>Convention is to use underscore to separate words in a name.</p>\n<p>However, there are a few rules for naming a method: One of the important rules is also related to variable names. We observed that a variable name cannot start with a number.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> 1_print<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token keyword\">def</span> 1_print<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n             <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid token</code></pre></div>\n<p>Similarly, <code class=\"language-text\">1_print</code> will not be accepted as a method name.</p>\n<ul>\n<li>You can start a name with an alphabet, or with an underscore.</li>\n<li>From the second character onward, you are allowed to use numeric symbols.</li>\n</ul>\n<p>Methods and variables cannot be named using Python keywords.</p>\n<p>Now, what is a keyword? For example, when we talked about <code class=\"language-text\">for</code> loop, as in:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">```<span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>```<span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<ul>\n<li><strong><code class=\"language-text\">for</code></strong> is a keyword</li>\n<li><strong><code class=\"language-text\">in</code></strong> is a keyword</li>\n<li><strong><code class=\"language-text\">def</code></strong> is a keyword.</li>\n</ul>\n<p>Later we will look at a few other keywords, such as <strong><code class=\"language-text\">while</code></strong>, <strong><code class=\"language-text\">return</code></strong>, <strong><code class=\"language-text\">if</code></strong>, <strong><code class=\"language-text\">else</code></strong>, <strong><code class=\"language-text\">elif</code></strong>, and many more.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">def</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token keyword\">def</span> <span class=\"token function\">def</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n              <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">in</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token keyword\">def</span> <span class=\"token function\">in</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n             <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        <span class=\"token keyword\">def</span> <span class=\"token function\">for</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n              <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax</code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to the concept of named parameters</li>\n<li>Explored the typical naming rules and conventions for methods in Python</li>\n<li>Observed that reserved keywords cannot be used to name variables or methods</li>\n</ul>\n<p><strong>Step 09: Methods - Return Values</strong></p>\n<p>Let's try and understand the importance of return values from a method. We will learn how to return a value from a method.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's name our method as <code class=\"language-text\">product_of_two_numbers()</code>, and let's have parameters <code class=\"language-text\">a</code> and <code class=\"language-text\">b</code> that it accepts:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">product_of_two_numbers</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">*</span> b<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_of_two_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">2</span></code></pre></div>\n<p>Can we take the product of these two numbers into a variable, and use it in other code, in the same program?</p>\n<p>Suppose we say a <code class=\"language-text\">product = product_of_two_numbers(1,2)</code>, is this allowed?</p>\n<p>Let's run this code, and see what's stored in <code class=\"language-text\">product</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product <span class=\"token operator\">=</span> product_of_two_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product</code></pre></div>\n<p>It's empty.</p>\n<p>The <code class=\"language-text\">product_of_two_numbers()</code> method is not really returning anything back, to be used elsewhere.</p>\n<p>Have a look at some of the built-in Python functions, such as <code class=\"language-text\">max()</code> for example.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> maximum <span class=\"token operator\">=</span> <span class=\"token builtin\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> maximum\n    <span class=\"token number\">4</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> maximum <span class=\"token operator\">*</span> <span class=\"token number\">5</span>\n    <span class=\"token number\">20</span></code></pre></div>\n<p>If I call <code class=\"language-text\">max()</code> with four parameters, as in <code class=\"language-text\">maximum = max(1,2,3,4)</code>, the value <code class=\"language-text\">4</code> gets stored in maximum.</p>\n<p>Later on in the code that follows, we can say <code class=\"language-text\">maximum * 5</code>, or we can print the value of <code class=\"language-text\">maximum</code>, or a similar calculation. This gives our programs a lot more flexibility.</p>\n<p>So instead of just printing <code class=\"language-text\">a*b</code>, if this function could return a value, that would be quite useful.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">product_of_two_numbers</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      product <span class=\"token operator\">=</span> a <span class=\"token operator\">*</span> b<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      <span class=\"token keyword\">return</span> product\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_of_two_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">6</span></code></pre></div>\n<p>We are creating a variable <code class=\"language-text\">product</code> and doing a <code class=\"language-text\">return product</code>.</p>\n<p>Lets run <code class=\"language-text\">product_result = product_of_two_numbers(2, 3)</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_result <span class=\"token operator\">=</span> product_of_two_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_result\n    <span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> product_result <span class=\"token operator\">*</span> <span class=\"token number\">10</span>\n    <span class=\"token number\">60</span></code></pre></div>\n<p>You can see how simple it is to return values from a method!</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Learned how to return values from inside a method</li>\n<li>Observed how we can store the values returned by a method call</li>\n</ul>\n<p><strong>Step 10: Programming Exercise PE-MD-02</strong></p>\n<p>In this step let's look at a couple of exercises about returning values from methods.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>Write a method to return the sum of three integers.</li>\n<li>Write a method which takes as input two integers, representing two angles of a triangle, and computes the third angle.</li>\n</ol>\n<p>Hint: The sum of the angles in a triangle is <code class=\"language-text\">180</code> degrees. So if I am passing <code class=\"language-text\">50</code> and <code class=\"language-text\">50</code>, <code class=\"language-text\">50</code> plus <code class=\"language-text\">50</code> is <code class=\"language-text\">100</code>. So some of three angles should be <code class=\"language-text\">180</code>, so the third angle will be <code class=\"language-text\">180 - 100</code>, which is <code class=\"language-text\">80</code>.</p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span><span class=\"token keyword\">def</span> sum_of_three_numbers<span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> sum_of_three_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> something <span class=\"token operator\">=</span> sum_of_three_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> something <span class=\"token operator\">*</span> <span class=\"token number\">5</span>\n    <span class=\"token number\">30</span></code></pre></div>\n<p>The shorter way of doing that would have been to have a temporary variable called instead of <code class=\"language-text\">sum</code>. We could directly <code class=\"language-text\">return a + b + c</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">sum_of_three_numbers</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">return</span> a <span class=\"token operator\">+</span> b <span class=\"token operator\">+</span> c\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> something <span class=\"token operator\">=</span> sum_of_three_numbers<span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> something <span class=\"token operator\">*</span> <span class=\"token number\">5</span>\n    <span class=\"token number\">30</span></code></pre></div>\n<p>In methods, you can use <code class=\"language-text\">return expression</code> as well. That <code class=\"language-text\">expression</code> gets evaluated, and the value gets returned back. You'd see that the result remains the same.</p>\n<p><strong>Solution 2</strong></p>\n<p>The second is to write a method to take two integers, representing two angles of a triangle, and compute the third one.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">def</span> <span class=\"token function\">calculate_third_angle</span><span class=\"token punctuation\">(</span>first<span class=\"token punctuation\">,</span> second<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">return</span> <span class=\"token number\">180</span> <span class=\"token operator\">-</span> <span class=\"token punctuation\">(</span> first <span class=\"token operator\">+</span> second <span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> calculate_third_angle<span class=\"token punctuation\">(</span><span class=\"token number\">50</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">110</span></code></pre></div>\n<p>In your programming career, you would be writing a number of methods. It's very important that you are comfortable doing so. Most of the methods that you write would return values back.</p>\n<p>That's the reason why we're creating a lot of examples involving method calls.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a couple of exercises related to returning values from methods</li>\n<li>Observed that returning expressions avoids creating unnecessary variables, and shortens method definitions</li>\n</ul>\n<h4>Chapter 04 - Introduction To Python Platform</h4>\n<p>Until now we had been using Python Shell to execute all our code.</p>\n<p>In the real world, we'll be write Python code in a variety of scripts. Before we would go into an IDE and use the IDE to write the script, we thought it would be useful for us to understand how you can write Python code without the benefit of an IDE.</p>\n<p>This would also help us understand the Python environment, in-depth.</p>\n<p>In the next few steps, we'll be looking at how to create simple Python scripts, using any text editor of your choice. Use Notepad, Notepad++. Editpad, or whichever text editing software you are comfortable with. We'll see what involved in executing the program, and what's happening in the background.</p>\n<p>Here are a few videos you might want to look at.</p>\n<ul>\n<li>[Writing and Executing your First Python Script](https://www.youtube.com/watch?v=ORmDD1R7lNc)</li>\n<li>[Understanding Python Virtual Machine and bytecode](https://www.youtube.com/watch?v=HE-FC0csG68)</li>\n</ul>\n<p><strong>Step 01 - Writing and Executing Python Shell Programs</strong></p>\n<p>Here's a recommended video to watch - [Writing and Executing your First Python Script](https://www.youtube.com/watch?v=ORmDD1R7lNc)</p>\n<p>Let's get started with creating a simple script file.</p>\n<p>We want to type in a simple Python script, or a piece of Python code, such as <code class=\"language-text\">print(\"Hello world\")</code>. Does it get any simpler than this?</p>\n<p>We'll save this into any folder on our hard disk, with a name 'first.py' .</p>\n<p><em><strong>first.py</strong></em></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Hello world\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The '.py' is not really mandatory, but typically all python files end with a '.py' extension.</p>\n<p>Here's how you can run it:</p>\n<ul>\n<li>Launch your terminal, or command prompt</li>\n<li>'cd' to the folder where this python script file is saved</li>\n<li>execute the command <code class=\"language-text\">python first.py</code></li>\n</ul>\n<p>You will see that <code class=\"language-text\">Hello World</code> will be printed.</p>\n<p>If you are familiar with other programming languages, you would need a class, need to put the code in that class, and similar stuff.</p>\n<p>While Python supports Object Oriented Programming, is not mandatory to create a class.</p>\n<p>It's almost as if you're typing commands, starting from the line one! That's why we call it a python script.</p>\n<p><strong>Summary</strong></p>\n<p>In this small step, we tried to create a simple python script, and we ran it from the command line. All we needed to do, was use the same command we use to launch up the python shell, and followed it up with a name of the file. We created a file called first.py, executed that, and were able to see the output on the console.</p>\n<p>As an exercise, try and add a few more methods and try to run those methods as well, as part of this script.</p>\n<p><strong>Step 02 - Python virtual machine and bytecode</strong></p>\n<p>In this step, let's try and understand what's happening in the background.</p>\n<p>We wrote a simple piece of code using a text editor. We created a file named first.py, and all we did was: <code class=\"language-text\">python3 first.py</code>. If you look at other languages like Java for example, there is a separate compilation phase and then an execution phase. But with Python, just this command does both compilation and execution.</p>\n<p>We saw that, as soon as we make a change and we run <code class=\"language-text\">python3 first.py</code> , the change is compiled and executed as well!</p>\n<p>In Python, there is an intermediate format called <strong>Python byte code</strong>. Code is first compiled to bytecode, and then executed on the <strong>Python virtual machine</strong>.</p>\n<p>When we installed Python, we installed both the python compiler and interpreter, as well as the virtual machine.</p>\n<p>In Python, <code class=\"language-text\">bytecode</code> is not standardized. Different implementations of Python have different byte code. There are about 80 Python implementations, like CPython and Jython.</p>\n<ul>\n<li>CPython is a Python implementation in C language.</li>\n<li>Jython is a Python implementation in Java language. The bytecode which Jython uses is actually Java bytecode, and you can run it on the Java virtual machine.</li>\n</ul>\n<p>Python leaves a lot of flexibility to the implementations of Python. They have the flexibility to choose the bytecode, and to choose the virtual machine that is compatible. The bytecode is tied to the specific virtual machine you are using. Therefore, if you're using CPython to compile the bytecode, you'll not be able to use Jython to run it.</p>\n<p>You should make sure, that whatever implementation you are using to compile, is the same one you're using to run the code as well.</p>\n<p><strong>Summary</strong></p>\n<p>A lot of this sounds like boring theory. Don't worry about it. As a beginner, this might not be very important for you right now.</p>\n<p>It's very important for you to understand the process. What's happening is you were writing Python code, and when you ran the command <code class=\"language-text\">python3 first.py</code>, it is both compiled and executed. An intermediate format called bytecode is created, which is not really standardized in Python. The bytecode is executed in a Python virtual machine.</p>\n<p>The idea behind this quick section, is to give you a little bit of background on what's happening behind the scenes. I'll see you in the next section. Until then, bye-bye!</p>\n<h4>Chapter 05 - Introduction To VSCode</h4>\n<p>Let's start using the IDE VSCode to write our Python Code</p>\n<p>Here are recommended videos to watch</p>\n<ul>\n<li>[Installing VSCode](https://www.youtube.com/watch?v=pI_cnCXpCTU)</li>\n<li>[Write and Execute a Python File with VSCode](https://www.youtube.com/watch?v=Na05tSP21Jg)</li>\n<li>[Write Your First Python Program with VSCode](https://www.youtube.com/watch?v=PvYSlWbXuCw)</li>\n</ul>\n<p><strong>Step 01 - Installing and Introduction to VSCode</strong></p>\n<p>In this quick step, we'll help you install VSCode.</p>\n<p>Here's the video guide for this step</p>\n<ul>\n<li>[Installing VSCode](https://www.youtube.com/watch?v=pI_cnCXpCTU)</li>\n</ul>\n<p>Go to Google and type in \"VSCode Community Edition Download\". Click the link which comes up first: [https://www.jetbrains.com/VSCode/download](https://www.jetbrains.com/VSCode/download).</p>\n<p>You'll go to a page where you can choose the operating system: whether you are on Windows, Mac, or Linux.</p>\n<p>Once you choose that, you can download the appropriate community version.</p>\n<p>On the right hand side, you'll see a community version, and you can click the download link, to start the download.</p>\n<p>If you are having a problem, you can also use the direct link to download.</p>\n<p>Once you download VSCode, all you need to do is double-click the package which is downloaded. Follow the instructions, and you can continue with the defaults, until you completely install VSCode.</p>\n<p>When you launch VSCode for the first time, it should ask you for a theme, where you can choose the default.</p>\n<p>You're all set to go ahead with the next step in the course.</p>\n<p>VSCode is an awesome IDE, and I'm sure you learn a lot about it.</p>\n<p><strong>Step 02 - Write and Execute a Python File with VSCode</strong></p>\n<p>In this step, let's launch up the VSCode IDE, and create our first Python project with a Python script. We want to be able to launch a Python script by the end of this step.</p>\n<p>Here's the video guide for this step</p>\n<ul>\n<li>[Write and Execute a Python File with VSCode](https://www.youtube.com/watch?v=Na05tSP21Jg)</li>\n</ul>\n<p>Launch the VSCode IDE. You'll see that it takes a little while to launch the first time, and then brings up a welcome screen.</p>\n<p>We would want to create a number of Python files. All these files will be in a project. You can think of our project as a collection of Python scripts, or modules.</p>\n<p>To get started, let's create a new project by clicking 'create new project'. Let's name it - '01-first-python-project'.</p>\n<p>Right now there are no files in the project.</p>\n<p>Let's create our first Python file, using the IDE.</p>\n<p>The way you can do that is by saying 'right-click' -> 'new' -> 'Python file', and then we'll give this a name of 'hello_world', and click OK.</p>\n<p>Now you can go ahead and write your first Python program. Let's write some simple code, like <code class=\"language-text\">print(\"Hello World\")</code>, and save it.</p>\n<p>You can do a right-click here, and say 'Run hello_world'.</p>\n<p>A small window comes up below, which shows the output. It says <code class=\"language-text\">'Hello World'</code>.</p>\n<p><strong>Step 03 - Execise - Write Multiplication Table Method with VSCode</strong></p>\n<p>Let's start with a simple exercise. We created the multiplication table method in the Python Shell. What we do now, is we'll create the same thing but in a Python file of its own.</p>\n<p>Here's the video guide for this step:</p>\n<ul>\n<li>[Write Your First Python Program with VSCode](https://www.youtube.com/watch?v=PvYSlWbXuCw)</li>\n</ul>\n<h4>Chapter 06 - Introducing Data Types and Conditionals</h4>\n<p>Welcome to this section, where we will talk about numeric data types, and conditional program execution. After looking at the numeric and boolean data types, we will turn our attention to executing code, based on logical conditions.</p>\n<p><strong>Step 01: Numeric Data Types</strong></p>\n<p>In previous sections, we created variables of this kind: <code class=\"language-text\">number = 5</code> , <code class=\"language-text\">value = 2.5</code>, etc. The <code class=\"language-text\">5</code> here is an integer, and integers represent numbers, such as <code class=\"language-text\">1</code>, <code class=\"language-text\">2</code>, <code class=\"language-text\">6</code>, <code class=\"language-text\">-1</code> and <code class=\"language-text\">-2</code>. In Python, the <code class=\"language-text\">class</code> for this particular data type is <code class=\"language-text\">int</code>.</p>\n<p>If you write code like <code class=\"language-text\">type(5)</code>, you'd get <code class=\"language-text\">'int'</code> as the output.</p>\n<p>In Python, there are no primitive types. What does that mean? Every value that you see in a Python program, is an object, an instance of some <code class=\"language-text\">class</code>.</p>\n<p>In later sections, We'll understand what is a <code class=\"language-text\">class</code>, and what is an object or an instance. For now, the most important thing for you to remember, is that behind every value, there is a <code class=\"language-text\">class</code>.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's look at <code class=\"language-text\">2.5</code>, which is a floating point value.</p>\n<p>If you go ahead and do <code class=\"language-text\">type(2.5)</code>, what would you see? You would see it's of type `<code class=\"language-text\">float</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">2.5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">2.55</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span></code></pre></div>\n<p>When you perform a division operation between two integers, there is a chance that the result of the operation is a <code class=\"language-text\">float</code>. If you do <code class=\"language-text\">5/2</code>, the result is <code class=\"language-text\">2.5</code>. If we were to do <code class=\"language-text\">4/2</code>, even then it's of type <code class=\"language-text\">float</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token operator\">/</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token operator\">/</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">4</span><span class=\"token operator\">/</span><span class=\"token number\">2</span>\n    <span class=\"token number\">2.0</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span></code></pre></div>\n<p>All the operations we looked at until now, can also be performed on floating point values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">=</span> <span class=\"token number\">4.5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value2 <span class=\"token operator\">=</span> <span class=\"token number\">3.2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">+</span> value2\n    <span class=\"token number\">7.7</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">-</span> value2\n    <span class=\"token number\">1.2999999999999998</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">/</span> value2\n    <span class=\"token number\">1.40625</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> value1 <span class=\"token operator\">%</span> value2\n    <span class=\"token number\">1.2999999999999998</span></code></pre></div>\n<p><code class=\"language-text\">value1 - value2</code> returns <code class=\"language-text\">1.299999999999998</code>. Why?</p>\n<p>Floating point numbers don't really represent accurate values. That's one of the things you need to always keep in mind.</p>\n<p>Typically, if you're doing any highly sensitive financial calculations, don't use <code class=\"language-text\">float</code>s to represent your values. Instead, use <code class=\"language-text\">Decimal</code>. More about it later.</p>\n<p>Operations can also be performed between <code class=\"language-text\">int</code> and <code class=\"language-text\">float</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">+</span> value1\n    <span class=\"token number\">14.5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">-</span> value1\n    <span class=\"token number\">5.5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">/</span> value1\n    <span class=\"token number\">2.2222222222222223</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>Result of an operation between a <code class=\"language-text\">int</code> and a <code class=\"language-text\">float</code>, is always a <code class=\"language-text\">float</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at the two basic numeric types: <code class=\"language-text\">int</code> and <code class=\"language-text\">float</code>.</li>\n<li>Saw the basic operations you can do among <code class=\"language-text\">int</code>s, among <code class=\"language-text\">float</code>s, and also between <code class=\"language-text\">int</code>s and <code class=\"language-text\">float</code>s.</li>\n</ul>\n<p><strong>Step 02: Programming Exercise PE-DT-01</strong></p>\n<p>In this step, let's do a simple exercise with numeric values.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>You need to create a method called <code class=\"language-text\">simple_interest</code>, and pass three parameters: <code class=\"language-text\">principal</code>, <code class=\"language-text\">interest</code> and <code class=\"language-text\">duration</code> (in years). You also want to calculate the amount after the specific duration, and return it back. Call this method with a few example values.</li>\n</ol>\n<p>For example, if you want to call <code class=\"language-text\">simple_interest</code> with <code class=\"language-text\">10000</code>, with an interest of <code class=\"language-text\">5</code> percent, for a duration of <code class=\"language-text\">5</code> years, the correct answer would be as follows: <code class=\"language-text\">10000</code> is the principal. In addition to <code class=\"language-text\">10000</code>, you get the interest. The interest for one year is <code class=\"language-text\">10000 * 0.05</code>, as the interest figure is in percentage.So that's <code class=\"language-text\">500</code> a year, into <code class=\"language-text\">5</code> which is <code class=\"language-text\">2500</code>. The result would be <code class=\"language-text\">12500</code>, and this value should be printed.</p>\n<p><strong>Solution 1</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token keyword\">def</span> <span class=\"token function\">calculate_simple_interest</span><span class=\"token punctuation\">(</span>principal<span class=\"token punctuation\">,</span> interest<span class=\"token punctuation\">,</span> duration<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">:</span>\n            <span class=\"token keyword\">return</span> principal <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">+</span> interest <span class=\"token operator\">*</span> <span class=\"token number\">0.01</span> <span class=\"token operator\">*</span> duration<span class=\"token punctuation\">)</span>\n\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculate_simple_interest<span class=\"token punctuation\">(</span><span class=\"token number\">10000</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Wrote a very simple method to do a simple interest calculation</li>\n</ul>\n<p><strong>Step 03: Puzzles On Numeric Types</strong></p>\n<p>In this section, we are looking at numeric types. In this specific step, we would be looking at a few puzzles related to values of these types.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's create a simple variable <code class=\"language-text\">i = 1</code>. <code class=\"language-text\">i = i + 1</code>. What would be the value of <code class=\"language-text\">i</code> after that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i\n    <span class=\"token number\">2</span></code></pre></div>\n<p>It would be <code class=\"language-text\">2</code>. There is a shortcut way of doing the same thing, by using the <code class=\"language-text\">+=</code> operator.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i\n    <span class=\"token number\">3</span></code></pre></div>\n<p>Typically in other programming languages, you can do something of this kind: <code class=\"language-text\">i++</code>. There is no provision in Python to use increment operators like <code class=\"language-text\">++</code>, in either prefix or suffix mode, like <code class=\"language-text\">++i</code>, or <code class=\"language-text\">i++</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i<span class=\"token operator\">+</span><span class=\"token operator\">+</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        i<span class=\"token operator\">+</span><span class=\"token operator\">+</span>\n          <span class=\"token operator\">^</span>\n    SyntaxError<span class=\"token punctuation\">:</span> invalid syntax\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token operator\">+</span><span class=\"token operator\">+</span>i\n    <span class=\"token number\">3</span></code></pre></div>\n<p>Let's look at compound assignments.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">+=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i\n    <span class=\"token number\">4</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">-=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i\n    <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">/=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">*=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i\n    <span class=\"token number\">6.0</span></code></pre></div>\n<p>What you see here, is Dynamic Typing in Python. The type of a variable can change during the lifetime of the program.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">&lt;</span><span class=\"token builtin\">type</span> <span class=\"token string\">'int'</span><span class=\"token operator\">></span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> i<span class=\"token operator\">/</span><span class=\"token number\">2.0</span>\n<span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n<span class=\"token operator\">&lt;</span><span class=\"token builtin\">type</span> <span class=\"token string\">'float'</span><span class=\"token operator\">></span></code></pre></div>\n<p>Let's create a couple more numbers. <code class=\"language-text\">number1 = 5</code> and <code class=\"language-text\">number2 = 2</code>. What could be the result of <code class=\"language-text\">number1 / number2</code>? You know it, it's <code class=\"language-text\">2.5</code> .</p>\n<p><code class=\"language-text\">number1 // nummber2</code> truncates the value of <code class=\"language-text\">2.5</code>, to <code class=\"language-text\">2</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> number1<span class=\"token operator\">//</span>number2\n    <span class=\"token number\">2</span></code></pre></div>\n<p>If you can do <code class=\"language-text\">number1 // number2</code>, can you also do this: <code class=\"language-text\">number1 //= number2</code>?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> number1 <span class=\"token operator\">//=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> number1\n    <span class=\"token number\">2</span></code></pre></div>\n<p><code class=\"language-text\">5 ** 3</code> is <code class=\"language-text\">5</code> 'to the power of' <code class=\"language-text\">3</code>, which is <code class=\"language-text\">5 * 5 * 5</code>, or <code class=\"language-text\">125</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">5</span> <span class=\"token operator\">**</span> <span class=\"token number\">3</span>\n    <span class=\"token number\">125</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">pow</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">,</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">125</span></code></pre></div>\n<p>This can also be achieved by invoking <code class=\"language-text\">pow(5, 3)</code>. We have an operator, as well as a method at our disposal.</p>\n<p>The last thing we will look at, are type conversion functions.</p>\n<p>If you need to convert an <code class=\"language-text\">int</code> value to a <code class=\"language-text\">float</code>, or a <code class=\"language-text\">float</code> to an <code class=\"language-text\">int</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.6</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span></code></pre></div>\n<p>What if you want to round a value? <code class=\"language-text\">5.6</code> is nearer to <code class=\"language-text\">6</code> than <code class=\"language-text\">5</code>. You can use a function called <code class=\"language-text\">round()</code>, and here,<code class=\"language-text\">round(5.6)</code> gives the correct result <code class=\"language-text\">6</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.6</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.4</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">6</span></code></pre></div>\n<p><code class=\"language-text\">round()</code> can also allows you to specify number of decimals in the result.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.67</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5.7</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">round</span><span class=\"token punctuation\">(</span><span class=\"token number\">5.678</span><span class=\"token punctuation\">,</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5.68</span></code></pre></div>\n<p>You can also convert <code class=\"language-text\">int</code> to <code class=\"language-text\">float</code>, by using the function <code class=\"language-text\">float()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">5.0</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a few corner cases related to your numeric types.</li>\n<li>Examined the different operators available for use with values of numeric types</li>\n<li>Learned about the usage of type conversion functions</li>\n</ul>\n<p><strong>Step 04: Introducing Boolean Type</strong></p>\n<p>We will now shift our attention to the <code class=\"language-text\">bool</code> data type.</p>\n<p>A boolean value is something which can be either \"true\" or \"false\".</p>\n<p><strong>Snippet-01:</strong></p>\n<p>In Python, \"true\" is represented by <code class=\"language-text\">True</code>, and \"false\" by <code class=\"language-text\">False</code>. It's important to remember that it's <code class=\"language-text\">True</code> with a capital <code class=\"language-text\">'T'</code>, and <code class=\"language-text\">False</code> with a capital <code class=\"language-text\">'F'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> true\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'true'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> false\n    Traceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    NameError<span class=\"token punctuation\">:</span> name <span class=\"token string\">'false'</span> <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> defined</code></pre></div>\n<p>The boolean variable <code class=\"language-text\">is_even</code> indicates whether a number is even or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> is_even <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> is_odd <span class=\"token operator\">=</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>Let's create a variable <code class=\"language-text\">i = 10</code>. We want to find out if <code class=\"language-text\">i > 15</code>. What do you think is the result? <code class=\"language-text\">False</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">></span> <span class=\"token number\">15</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">15</span>\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p>In general, boolean values can represent the result of logical conditions.</p>\n<p>Let's look at other operations that can result in <code class=\"language-text\">bool</code> values. We looked at <code class=\"language-text\">></code> and <code class=\"language-text\">&lt;</code>. Another operation which you can perform, is <code class=\"language-text\">>=</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">>=</span> <span class=\"token number\">15</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">>=</span> <span class=\"token number\">10</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">></span> <span class=\"token number\">10</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">&lt;=</span> <span class=\"token number\">10</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">10</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p><code class=\"language-text\">==</code> is the comparison operator. We are only comparing the value of <code class=\"language-text\">i</code> against <code class=\"language-text\">10</code>, not changing its value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">==</span> <span class=\"token number\">10</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">==</span> <span class=\"token number\">11</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to the <code class=\"language-text\">bool</code> data type</li>\n<li>Learned that <code class=\"language-text\">bool</code> variables are useful handy while testing logical conditions</li>\n</ul>\n<p><strong>Step 05: Introducing Conditionals</strong></p>\n<p>In this step, let's look at <code class=\"language-text\">if</code> statement.</p>\n<p>Sometimes you need to execute code only when certain conditions are true. You can use a <code class=\"language-text\">if</code> condition, which is the simplest conditional in Python. Let's look at an example.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's say <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">5</code>. You want to print something, only if <code class=\"language-text\">i</code> has a value greater than <code class=\"language-text\">3</code>. How do you do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">></span><span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> is greater than 3\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">5</span> <span class=\"token keyword\">is</span> greater than <span class=\"token number\">3</span></code></pre></div>\n<p>The syntax of the <code class=\"language-text\">if</code> is very simple: <code class=\"language-text\">if</code> followed by a condition; with the condition you want to check. It looks like: <code class=\"language-text\">if i>3: ...</code> You need to indent the body of the <code class=\"language-text\">if</code> with <code class=\"language-text\">&lt;SPACE></code>s as usual.</p>\n<p>Let's say <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">2</code>. What would happen if we execute the same code again?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">></span><span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>i<span class=\"token punctuation\">}</span></span><span class=\"token string\"> is greater than 3\"</span></span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>You would see that nothing is printed to the console. Based on the value of <code class=\"language-text\">i</code> , either the statement is executed, or it's not. That's what an <code class=\"language-text\">if</code> helps us to do.</p>\n<p>The way you can think about an <code class=\"language-text\">if</code>, is the body of code under the <code class=\"language-text\">if</code> is executed only when this condition is <code class=\"language-text\">True</code>. If this condition is not <code class=\"language-text\">True</code>, that code is not executed at all.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"False\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"True\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p>Let's take two different numbers, say <code class=\"language-text\">a = 5</code>, and <code class=\"language-text\">b = 7</code>. We want to compare them, and predict if <code class=\"language-text\">a</code> is greater that <code class=\"language-text\">b</code> .</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">7</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>a<span class=\"token operator\">></span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"a is greater than b\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">9</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>a<span class=\"token operator\">></span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"a is greater than b\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    a <span class=\"token keyword\">is</span> greater than b</code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Were introduced to the <code class=\"language-text\">if</code> statement, the simplest Python conditional</li>\n<li>Understood how an <code class=\"language-text\">if</code> helps in implementing conditional program logic</li>\n</ul>\n<p><strong>Step 06: Classroom Exercise CE-DT-01</strong></p>\n<p>In this step, let's look at a couple of exercises with the if statement.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's say we define four variables: <code class=\"language-text\">a = 1</code>, <code class=\"language-text\">b = 2</code> , <code class=\"language-text\">c = 3</code> and <code class=\"language-text\">d = 5</code>. we want to find out, if <code class=\"language-text\">a + b</code> is greater than <code class=\"language-text\">c + d</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> b <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> c <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> d <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a<span class=\"token operator\">+</span>b <span class=\"token operator\">></span> c<span class=\"token operator\">+</span>d <span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"a+b > c +d\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> a <span class=\"token operator\">=</span> <span class=\"token number\">9</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> a<span class=\"token operator\">+</span>b <span class=\"token operator\">></span> c<span class=\"token operator\">+</span>d <span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"a+b > c +d\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    a<span class=\"token operator\">+</span>b <span class=\"token operator\">></span> c <span class=\"token operator\">+</span>d</code></pre></div>\n<p>Let's say we are given three values meant to be the angles of a triangle. Their values are <code class=\"language-text\">angle1 = 30</code>, <code class=\"language-text\">angle2 = 20</code> and <code class=\"language-text\">angle3 = 60</code>. You want to find out if these three angles actually form a valid triangle. You know that the sum of the angles of a triangle is always <code class=\"language-text\">180</code> degrees.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> angle1 <span class=\"token operator\">=</span> <span class=\"token number\">30</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> angle2 <span class=\"token operator\">=</span> <span class=\"token number\">20</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> angle3 <span class=\"token operator\">=</span> <span class=\"token number\">60</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>angle1 <span class=\"token operator\">+</span> angle2 <span class=\"token operator\">+</span> angle3 <span class=\"token operator\">==</span> <span class=\"token number\">180</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Valid Triangle\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> angle2 <span class=\"token operator\">=</span> <span class=\"token number\">90</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>angle1 <span class=\"token operator\">+</span> angle2 <span class=\"token operator\">+</span> angle3 <span class=\"token operator\">==</span> <span class=\"token number\">180</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>      <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Valid Triangle\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    Valid Triangle</code></pre></div>\n<p>The last exercise is to check if a number is even or not.</p>\n<p>Hint L you need to use one of the operators we talked about earlier. That's right, use the modulo operator <code class=\"language-text\">%</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is even\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    i <span class=\"token keyword\">is</span> even\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is even\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a few exercises related to the if statement, for writing and testing conditions.</li>\n</ul>\n<p><strong>Step 07 - Logical Operators - and or not</strong></p>\n<p>In this step, let's look at the different operators that can be used on <code class=\"language-text\">bool</code> values. These operators are called logical operators - <code class=\"language-text\">and</code>, <code class=\"language-text\">or</code> , <code class=\"language-text\">not</code> and <code class=\"language-text\">^</code> (xor).</p>\n<p>Let's say we have a value <code class=\"language-text\">True</code>, and the other <code class=\"language-text\">False</code>, and we want to play around with them.</p>\n<p>Logical operator <code class=\"language-text\">and</code> returns true only when both operands are <code class=\"language-text\">True</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">False</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">True</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">False</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">True</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">and</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>Logical operator <code class=\"language-text\">or</code> returns true when atleast one of the operands is <code class=\"language-text\">True</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">False</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">True</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">True</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token keyword\">or</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>Logical operator <code class=\"language-text\">not</code> returns negation.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">True</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">not</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">not</span> <span class=\"token boolean\">False</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">not</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p>The XOR operation, denoted by the <code class=\"language-text\">^</code> operator, is <code class=\"language-text\">True</code> when operands have different boolean values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">True</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">True</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">False</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">True</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token boolean\">False</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">False</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at the logical operators that act on boolean values, such as <code class=\"language-text\">and</code>, <code class=\"language-text\">or</code>, <code class=\"language-text\">not</code> and <code class=\"language-text\">^</code></li>\n<li>Explored each of these operators, finding out when they return <code class=\"language-text\">True</code>, and when <code class=\"language-text\">False</code>.</li>\n</ul>\n<p><strong>Step 08: Puzzles On Logical Operators</strong></p>\n<p>In this step, Let's look at a few simple puzzles to look at the logical operators.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Let's say <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">10</code>, and <code class=\"language-text\">j</code> has a value of <code class=\"language-text\">15</code>. You want to find out if both <code class=\"language-text\">i</code> and <code class=\"language-text\">j</code> are even. How do you do that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">10</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">and</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i and j are even\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> <span class=\"token number\">14</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">and</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i and j are even\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    i <span class=\"token keyword\">and</span> j are even\n\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">or</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">2</span>\n        <span class=\"token operator\">^</span>\n    IndentationError<span class=\"token punctuation\">:</span> expected an indented block\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">or</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"atleast one of i and j are even\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    atleast one of i <span class=\"token keyword\">and</span> j are even</code></pre></div>\n<p>If we want to find out if at least one of <code class=\"language-text\">i</code> and <code class=\"language-text\">j</code> is even, we can use the <code class=\"language-text\">or</code> operator.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j\n    <span class=\"token number\">14</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">or</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"atleast one of i and j are even\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    atleast one of i <span class=\"token keyword\">and</span> j are even\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> j <span class=\"token operator\">=</span> <span class=\"token number\">23</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span> <span class=\"token keyword\">or</span> j<span class=\"token operator\">%</span><span class=\"token number\">2</span><span class=\"token operator\">==</span><span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"atleast one of i and j are even\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i\n    <span class=\"token number\">15</span></code></pre></div>\n<p>Now try and guess the value of this. <code class=\"language-text\">if(True ^ False): print(\"Message\")</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This will Print\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    This will Print\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">False</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This will Print\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    This will Print\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span> <span class=\"token operator\">^</span> <span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>     <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This will Print\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Xor operation using <code class=\"language-text\">^</code> - message will get printed if the operands are different.</p>\n<p>What would happen if both of them are <code class=\"language-text\">True</code>? No message is printed.</p>\n<p>So you would use <code class=\"language-text\">^</code> in situations, where you'd want one of the operands to be <code class=\"language-text\">True</code>, and the other to be <code class=\"language-text\">False</code>.</p>\n<p>Let's say, <code class=\"language-text\">x = 5</code>, and you want to check <code class=\"language-text\">if not x == 6: print(\"This\")</code>. What will be the result of running this code?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> x <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> x <span class=\"token operator\">==</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    This\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> x <span class=\"token operator\">=</span> <span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> <span class=\"token keyword\">not</span> x <span class=\"token operator\">==</span> <span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span></code></pre></div>\n<p>Actually, there is a shortcut for such a condition: <code class=\"language-text\">if x != 6 : print(\"This\")</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> x<span class=\"token operator\">!=</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> x<span class=\"token operator\">=</span><span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> x<span class=\"token operator\">!=</span><span class=\"token number\">6</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"This\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    This</code></pre></div>\n<p><code class=\"language-text\">int()</code> is a conversion function, which when given say a <code class=\"language-text\">float</code> value, returns an <code class=\"language-text\">int</code> value. Consider <code class=\"language-text\">int(True)</code>, what would happen?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">0</span></code></pre></div>\n<p><code class=\"language-text\">int(True)</code> returns 1. <code class=\"language-text\">int(False)</code> returns 0.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> x <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">6</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> x<span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"something\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    something</code></pre></div>\n<p>One of the most interesting facts about boolean stuff, is anything which is non-zero, is considered to be <code class=\"language-text\">True</code>.</p>\n<p><code class=\"language-text\">0</code> is the only integer value which is considered to be <code class=\"language-text\">False</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token operator\">-</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>So, if I have a value of <code class=\"language-text\">x = -6</code>, and execute <code class=\"language-text\">if x: print(\"something\")</code> what do you think will happen?</p>\n<p><code class=\"language-text\">\"something\"</code> will be printed.</p>\n<p>You can use the function <code class=\"language-text\">bool()</code>, to convert <code class=\"language-text\">int</code> to a <code class=\"language-text\">bool</code> value.</p>\n<ul>\n<li><code class=\"language-text\">bool(6)</code> returns <code class=\"language-text\">True</code></li>\n<li><code class=\"language-text\">bool(-6)</code> returns <code class=\"language-text\">True</code></li>\n<li><code class=\"language-text\">bool(0)</code> returns <code class=\"language-text\">False</code>.</li>\n</ul>\n<p>Except for <code class=\"language-text\">bool(0)</code>, all the other results would be <code class=\"language-text\">True</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a few puzzles related to the logical operators</li>\n<li>Looked at conversion functions such as <code class=\"language-text\">bool()</code> and <code class=\"language-text\">int()</code> to convert between boolean and integer data</li>\n</ul>\n<p><strong>Step 09:</strong></p>\n<p>In this step, let's look at two other important components of an <code class=\"language-text\">if</code> statement: <code class=\"language-text\">else</code> and <code class=\"language-text\">elif</code>. Let's start with <code class=\"language-text\">else</code>.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>Consider a scenario where <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">2</code>. Let's try to print a message <code class=\"language-text\">\"i is even\"</code> if <code class=\"language-text\">i</code> is an even number. Otherwise, print <code class=\"language-text\">\"i is odd\"</code>.</p>\n<p>Earlier we wrote code along these lines: <code class=\"language-text\">if i % 2 == 0 : print(\"i is even\")</code>. However if this condition is not <code class=\"language-text\">True</code>, we would want to <code class=\"language-text\">print(\"i is odd\")</code>. How do we accomplish that?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is even\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is odd\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    i <span class=\"token keyword\">is</span> even</code></pre></div>\n<p>An <code class=\"language-text\">else</code> clause provides an alternative code body to execute, if the <code class=\"language-text\">if</code> condition is <code class=\"language-text\">False</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">%</span><span class=\"token number\">2</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is even\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is odd\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    i <span class=\"token keyword\">is</span> odd</code></pre></div>\n<p>Let's look at <code class=\"language-text\">elif</code>.</p>\n<p>We want to do something if <code class=\"language-text\">i</code> has value of <code class=\"language-text\">3</code>, and something totally different if <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">4</code>.</p>\n<p>In short, we want to specify 2 alternatives to the <code class=\"language-text\">if</code> condition. How can that be done?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i<span class=\"token operator\">==</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is 1\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">elif</span> i<span class=\"token operator\">==</span><span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is 2\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span> <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is not 1 or 2\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    i <span class=\"token keyword\">is</span> <span class=\"token keyword\">not</span> <span class=\"token number\">1</span> <span class=\"token keyword\">or</span> <span class=\"token number\">2</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>That's where the <strong><code class=\"language-text\">elif</code></strong> clause comes into the picture. The code in <code class=\"language-text\">elif</code> is executed if the previous conditions are false and the current <code class=\"language-text\">elif</code> condition is true.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at two important components of the <code class=\"language-text\">if</code> statement: <code class=\"language-text\">else</code> and <code class=\"language-text\">elif</code>.</li>\n<li>Understood that the <code class=\"language-text\">elif</code> clauses and the final <code class=\"language-text\">else</code> clause provide alternative conditions to check, when earlier if conditions are true.</li>\n</ul>\n<p><strong>Step 10: Classroom Exercise CE-DT-02</strong></p>\n<p>In this step, let's do a simple exercise with <code class=\"language-text\">if</code>, <code class=\"language-text\">else</code> and <code class=\"language-text\">elif</code>.</p>\n<p>Before getting to the exercise, let's try and learn how to get console input from the user.</p>\n<p>Until now, we had been hard-coding all the data we were to use. Let's make that part more dynamic now.</p>\n<p><strong>Snippet-01:</strong></p>\n<p>How do we get input from the user? We want to get input from the console, and assign it to a variable. The way we can do that, is by statement <code class=\"language-text\">value = input()</code></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    value <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter a Value: \"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"you entered \"</span><span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span></code></pre></div>\n<p>We can call the <code class=\"language-text\">input()</code> method with a text 'prompt', such as <code class=\"language-text\">\"Enter A Value: \"</code>. What we can initially do here, is print the value which was entered, back to the console, by <code class=\"language-text\">print(\"you entered \", integer_value)</code>.</p>\n<p>An interesting point to explore here, is the type of data input at the console.</p>\n<p>Let's do a <code class=\"language-text\">print(type(value))</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    value <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter a Value: \"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"you entered \"</span><span class=\"token punctuation\">,</span> value<span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Input a value of <code class=\"language-text\">Test</code>. It has a class of <code class=\"language-text\">str</code>.</p>\n<p>Let's run it again to see other possibilities. This time, let's enter a numeric value, say <code class=\"language-text\">12</code>. what would happen?</p>\n<p>We again get <code class=\"language-text\">str</code>.</p>\n<p>We want to get an integer value from the input. How can we do it?</p>\n<p><code class=\"language-text\">int()</code> function converts string to int. Let's use it.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">value <span class=\"token operator\">=</span> <span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter a Value: \"</span><span class=\"token punctuation\">)</span>\ninteger_value <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>value<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"you entered \"</span><span class=\"token punctuation\">,</span> integer_value<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>integer_value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Let's run our code once again.</p>\n<p><code class=\"language-text\">\"Enter A Value: \"</code> is prompted, and we enter <code class=\"language-text\">15</code>. And now, of it says <code class=\"language-text\">\"You entered 15\"</code>, and the type it indicates to us, is <code class=\"language-text\">int</code>.</p>\n<p><strong>Design a menu</strong></p>\n<ul>\n<li>\n<p>Ask the User for input:</p>\n<ul>\n<li>Enter two numbers</li>\n<li>\n<p>Choose the Option:</p>\n<ul>\n<li>1 - Add</li>\n<li>2 - Subtract</li>\n<li>3 - Multiply</li>\n<li>4 - Divide</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Perform the Operation</li>\n<li>Publish the Result</li>\n</ul>\n<p>Let's design a menu, and then ask the user for input.</p>\n<p>We have codes for each of the operations : add is <code class=\"language-text\">1</code>, subtract is <code class=\"language-text\">2</code>, divide is <code class=\"language-text\">3</code>, and multiply is <code class=\"language-text\">4</code>.</p>\n<p>In the first version of the program let's get all the inputs and print them out.</p>\n<p><strong>Solution</strong></p>\n<p>The first version of the program is simple to write</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number1 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number1: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nnumber2 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number2: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"You entered </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>number1<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f\"You entered </span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>number2<span class=\"token punctuation\">}</span></span><span class=\"token string\">\"</span></span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>number1 <span class=\"token operator\">+</span> number2<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\\n1 - Add\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"2 - Subtract\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"3 - Divide\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"4 - Multiply\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"5 - Exit\"</span><span class=\"token punctuation\">)</span>\nchoice <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Choose Operation: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>choice<span class=\"token punctuation\">)</span></code></pre></div>\n<p>We will continue this exercise to complete it, in the next step.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at the in-built <code class=\"language-text\">input()</code> function that can read console input</li>\n<li>Learned that <code class=\"language-text\">input()</code> always returns what the user enters, as a string</li>\n<li>We can convert the string from <code class=\"language-text\">input()</code>, to the data type we expect by invoking conversion functions</li>\n</ul>\n<p><strong>Step 11: Continued - Classroom Exercise CE-DT-02</strong></p>\n<p><strong>Exercises</strong></p>\n<p>In the previous step, we got the input from the user. Let's continue the exercise in this step. We want to write an if condition.</p>\n<p><strong>Solution (Continued)</strong></p>\n<p>Extending the solution is easy. Write appropriate <code class=\"language-text\">if</code>, <code class=\"language-text\">elif</code> and <code class=\"language-text\">else</code> conditions.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number1 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number1: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nnumber2 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number2: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\\n1 - Add\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"2 - Subtract\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"3 - Divide\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"4 - Multiply\"</span><span class=\"token punctuation\">)</span>\n\nchoice <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Choose Operation: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># print(number1 + number2)</span>\n<span class=\"token comment\"># print(choice)</span>\n<span class=\"token keyword\">if</span> choice<span class=\"token operator\">==</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> number1 <span class=\"token operator\">+</span> number2\n<span class=\"token keyword\">elif</span> choice<span class=\"token operator\">==</span><span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> number1 <span class=\"token operator\">-</span> number2\n<span class=\"token keyword\">elif</span> choice<span class=\"token operator\">==</span><span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> number1 <span class=\"token operator\">/</span> number2\n<span class=\"token keyword\">elif</span> choice<span class=\"token operator\">==</span><span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> number1 <span class=\"token operator\">*</span> number2\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> <span class=\"token string\">\"Invalid Choice\"</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span></code></pre></div>\n<p>We added the following code to account for invalid input.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> <span class=\"token string\">\"Invalid Choice\"</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Augmented the Menu Exercise to get all the input from the console, and compute a value from them</li>\n<li>Corrected the logic to handle incorrect input</li>\n</ul>\n<p><strong>Step 12: Puzzles On Conditionals</strong></p>\n<p>In this step, let's look at a few puzzles related to these <code class=\"language-text\">if</code>, <code class=\"language-text\">elif</code> and <code class=\"language-text\">else</code> clauses.</p>\n<p><strong>Puzzle-01</strong></p>\n<p>Let's start with the first puzzle. Guess the output.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">k <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>k <span class=\"token operator\">></span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> <span class=\"token punctuation\">(</span>k <span class=\"token operator\">></span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elif</span> <span class=\"token punctuation\">(</span>k <span class=\"token operator\">&lt;</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n  <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>When we run it, you can see that the output is <code class=\"language-text\">2</code>.</p>\n<p><code class=\"language-text\">k</code> has a value of <code class=\"language-text\">15</code>, is it greater than <code class=\"language-text\">20</code>? No! Execution goes to the <code class=\"language-text\">elif</code>, is <code class=\"language-text\">k</code> greater then <code class=\"language-text\">10</code>? Yes. It prints <code class=\"language-text\">2</code> and goes out of the complete <code class=\"language-text\">if</code>-<code class=\"language-text\">else</code> block.</p>\n<p>Inside the <code class=\"language-text\">if</code> conditional, the <code class=\"language-text\">if</code>, <code class=\"language-text\">elif</code> and <code class=\"language-text\">else</code> clauses are all independent ones. Only one matching block is ever executed.</p>\n<p><strong>Puzzle-02</strong></p>\n<p>What do you think would be the output of this particular piece of code?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">l <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">&lt;</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"l&lt;20\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">></span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"l>20\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Who am I?\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Note that there are two totally different <code class=\"language-text\">if</code> conditions in here : <code class=\"language-text\">if l &lt; 20: ...</code> immediately followed by<code class=\"language-text\">if l > 20: ... else: ...</code>.</p>\n<p>The first <code class=\"language-text\">if</code> is true. <code class=\"language-text\">l&lt;20</code> is printed.</p>\n<p>The second <code class=\"language-text\">if</code> is a separate statement. The condition is false. So. <code class=\"language-text\">else</code> gets executed. Therefore, <code class=\"language-text\">\"who am I\"</code> gets printed.</p>\n<p><strong>Puzzle-03</strong></p>\n<p>Let's run this code.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">m <span class=\"token operator\">=</span> <span class=\"token number\">15</span>\n<span class=\"token keyword\">if</span> m<span class=\"token operator\">></span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> m<span class=\"token operator\">&lt;</span><span class=\"token number\">20</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"m>20\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Who am I?\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can see that nothing is printed.</p>\n<p>The most important thing to focus on here, is indentation.</p>\n<p>The second <code class=\"language-text\">if</code> block is executed only if the first <code class=\"language-text\">if</code> is true.</p>\n<p><strong>Puzzle-04</strong></p>\n<p>What would be the output?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n<span class=\"token keyword\">if</span> number <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n  number <span class=\"token operator\">=</span> number <span class=\"token operator\">+</span> <span class=\"token number\">10</span>\nnumber <span class=\"token operator\">=</span> number <span class=\"token operator\">+</span> <span class=\"token number\">5</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">10</code> is printed.</p>\n<p>The most important thing to focus on here, is indentation.</p>\n<p>Only <code class=\"language-text\">number = number + 10</code> is part of <code class=\"language-text\">if</code> block. It is not executed because the condition is false.</p>\n<p><code class=\"language-text\">number = number + 5</code> is not part of <code class=\"language-text\">if</code>. So, it gets executed.</p>\n<p>Let's add a couple of spaces before <code class=\"language-text\">number = number + 5</code>.</p>\n<p>What would be the output?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n<span class=\"token keyword\">if</span> number <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n  number <span class=\"token operator\">=</span> number <span class=\"token operator\">+</span> <span class=\"token number\">10</span>\n  number <span class=\"token operator\">=</span> number <span class=\"token operator\">+</span> <span class=\"token number\">5</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">5</code> is printed.</p>\n<p>Both the statements <code class=\"language-text\">number = number + 10</code> and <code class=\"language-text\">number = number + 5</code> are part of <code class=\"language-text\">if</code> block. They are not executed because the condition is false.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Looked at a few puzzles related to <code class=\"language-text\">if</code>, <code class=\"language-text\">elif</code> and <code class=\"language-text\">else</code></li>\n<li>Explored the importance of indentation and the different condition clauses inside an <code class=\"language-text\">if</code> statement</li>\n</ul>\n<p><strong>Step 01: The Python Type To Denote Text</strong></p>\n<p>Let's start looking at another important data type in Python, that's used to represent strings. Not surprisingly, it is in fact named <code class=\"language-text\">str</code>!</p>\n<p>Let's look at valid string representations.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello World\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">'Hello World'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> 'Hello World\"\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">1</span>\n        message <span class=\"token operator\">=</span> 'Hello World\"                          <span class=\"token operator\">^</span>\n     SyntaxError<span class=\"token punctuation\">:</span> EOL <span class=\"token keyword\">while</span> scanning string literal</code></pre></div>\n<p>In Python, you can use either ```<code class=\"language-text\">or</code>\"\"` to delimit string values.</p>\n<p><code class=\"language-text\">type()</code> method can be used to find type of a variable.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello World\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'str'</span><span class=\"token operator\">></span></code></pre></div>\n<p>The <code class=\"language-text\">str</code> <code class=\"language-text\">class</code> provides a lot of utility methods.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'HELLO WORLD'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'hello world'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"hello\"</span></code></pre></div>\n<p><code class=\"language-text\">message.capitalize()</code> does init caps. Only first character is changed to uppercase.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"hello\"</span><span class=\"token punctuation\">.</span>capitalize<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'Hello'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">.</span>capitalize<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'Hello'</span></code></pre></div>\n<p>You can also run this directly - <code class=\"language-text\">'hello'.capitalize()</code>. Isn't that cool!</p>\n<p>That's because each piece of text in python is an object of the <code class=\"language-text\">str</code> <code class=\"language-text\">class</code>, and we can directly call methods of that <code class=\"language-text\">class</code> on <code class=\"language-text\">str</code> objects.</p>\n<p>Now let's shift our attention to methods, which gives us more information about the specific contents of a string.</p>\n<ul>\n<li>We want to find out if this string contains numeric values?</li>\n<li>Does it contain alphabets only?</li>\n<li>Does it contain alpha-numeric values?</li>\n<li>Is it lowercase?</li>\n<li>Is it uppercase?</li>\n</ul>\n<p>To find if a piece of text contains only lower case alphabets.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p>If the first letter is in uppercase, then <code class=\"language-text\">istitle()</code> will return a <code class=\"language-text\">True</code> value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p>To find if a piece of text contains only upper case alphabets.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'hello'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'HELLO'</span><span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">isdigit()</code> checks if a string is a numeric value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'123'</span><span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'A23'</span><span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'2 3'</span><span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'23'</span><span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">isalpha()</code> checks if a string only contains alphabets.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'23'</span><span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'2A'</span><span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ABC'</span><span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">isalnum()</code> checks if a string only contains alphabets and/or numerals.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ABC123'</span><span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ABC 123'</span><span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p>Lastly, we look at things which you can use, to check characters of a string.</p>\n<p><code class=\"language-text\">endswith</code> is self explanatory.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'World'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'ld'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'old'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Wo'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p><code class=\"language-text\">startswith</code> is self explanatory as well.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Wo'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'He'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hell0'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">find</code> method returns if a piece of text is present in another string. Returns the first match index.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'Hello'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'ello'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">1</span></code></pre></div>\n<p>A value of <code class=\"language-text\">-1</code> is returned, if you're searching for something which is not present in the string.</p>\n<p>If you are searching for <code class=\"language-text\">'Ello'</code> with a capital <code class=\"language-text\">'E'</code> ,you'll not be able to find it. Search is case sensitive.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'Ello'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">-</span><span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'bello'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">-</span><span class=\"token number\">1</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'Hello World'</span><span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span><span class=\"token string\">'Ello'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">-</span><span class=\"token number\">1</span></code></pre></div>\n<p><strong>Step 02: Type Conversion Puzzles</strong></p>\n<p>We'll now try and convert values from one type to another, and try and play around with them.</p>\n<p><code class=\"language-text\">str</code> converts boolean value to a text value.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'True'</span></code></pre></div>\n<p>All text value except for empty string represent True. So, <code class=\"language-text\">bool</code> returns True for everything except empty string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'True'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'true'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tru'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'false'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">'False'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">bool</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p>Let's try and convert a few integer values to strings.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span><span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">123</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'123'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">12345</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'12345'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">(</span><span class=\"token number\">12345.45678</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'12345.45678'</span></code></pre></div>\n<p>Let's do the reverse.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'45'</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">45</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'45.56'</span><span class=\"token punctuation\">)</span>\n    ValueError<span class=\"token punctuation\">:</span> invalid literal <span class=\"token keyword\">for</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>if we do <code class=\"language-text\">int('45.56')</code>, you can see that it throws an error. It says \"I cannot convert this to an <code class=\"language-text\">int</code>, as <code class=\"language-text\">45.56</code> is an invalid integer\".</p>\n<p>You can also pass an additional parameter to <code class=\"language-text\">int</code> indicating the numeric system - 16 for Hexa decimal, 8 for Octal etc. Default is 10 - Decimal.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'45abc'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">285372</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">10</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'b'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">11</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'c'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">12</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'f'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">15</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token string\">'g'</span><span class=\"token punctuation\">,</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span>\n    ValueError<span class=\"token punctuation\">:</span> invalid literal <span class=\"token keyword\">for</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">with</span> base <span class=\"token number\">16</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'g'</span></code></pre></div>\n<p>You can also convert string to float.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"34.43\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token number\">34.43</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">float</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"34.43rer\"</span><span class=\"token punctuation\">)</span>\n    ValueError<span class=\"token punctuation\">:</span> could <span class=\"token keyword\">not</span> convert string to <span class=\"token builtin\">float</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'34.43rer'</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this quick step, we looked at converting different types to strings, and converting strings to different types. So we looked at <code class=\"language-text\">int</code>, <code class=\"language-text\">bool</code> and <code class=\"language-text\">float</code> values, and we looked at how to convert them to string, and how to convert strings back to these specific types.</p>\n<p><strong>Step 02: Strings Are Immutable</strong></p>\n<p>In this step, let's learn an important fact about strings in Python.</p>\n<p>String values are immutable.</p>\n<p>What does immutability mean, and why do we say strings are immutable?</p>\n<p>Let's create a very simple string: <code class=\"language-text\">message = 'Hello'</code>, and we're saying <code class=\"language-text\">message.upper()</code>. But what does it do? It prints <code class=\"language-text\">'HELLO'</code>, with all characters in uppercase. Well, what would happen if you do <code class=\"language-text\">print(message)</code>? It says <code class=\"language-text\">'Hello'</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token string\">'HELLO'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message\n    <span class=\"token string\">'Hello'</span></code></pre></div>\n<p>You would see we tried change the content of message, but it has not changed.</p>\n<p>When we execute <code class=\"language-text\">message.upper()</code>, a new string is created, and it is returned back. Original string remained unchanged. This is called immutability.</p>\n<p>Once you define a string in Python, you'll not be able to change the value of it.</p>\n<p>You can use - \"OK. I can do something of this kind: <code class=\"language-text\">message = message.upper()</code>\".</p>\n<p>What would happen now?</p>\n<p>Will the value of <code class=\"language-text\">message</code> get changed? It prints <code class=\"language-text\">'HELLO'</code>, with all caps.</p>\n<p>Did the value of <code class=\"language-text\">message</code> change? Does this prove that strings are mutable?</p>\n<p>The important thing you need to understand about all this stuff, is how objects are stored inside Python.</p>\n<p>There are things called variables, and there are things called objects.</p>\n<p>When we run <code class=\"language-text\">message = 'Hello'</code></p>\n<ul>\n<li>We are creating one object of <code class=\"language-text\">str</code> class with a values <code class=\"language-text\">'Hello'</code>.</li>\n<li>We are creating one variable called <code class=\"language-text\">message</code></li>\n<li>The location of <code class=\"language-text\">'Hello'</code> is stored into <code class=\"language-text\">message</code></li>\n</ul>\n<p>In Python, your variables are nothing but a name.</p>\n<p>If location of <code class=\"language-text\">'Hello'</code> in memory is <code class=\"language-text\">A</code>, then the value stored in <code class=\"language-text\">message</code> is <code class=\"language-text\">A</code>. <code class=\"language-text\">message</code> is called a reference.</p>\n<p>What happens with <code class=\"language-text\">message = message.upper()</code>?</p>\n<p>A new object is created with value <code class=\"language-text\">'HELLO'</code> at a different location <code class=\"language-text\">B</code>.</p>\n<p>A reference ot location <code class=\"language-text\">B</code> is stored into <code class=\"language-text\">message</code> variable.</p>\n<p>Summary : The original value at location <code class=\"language-text\">A</code> has not changed and cannot be changed for <code class=\"language-text\">str</code> variables. Hence 'str' objects are immutable.</p>\n<p>Variables are just names referring to a location. They don't really contain the value. Variables contain a reference to the location that contains the object.</p>\n<p><strong>Step 03: Python Has No Separate Character Type</strong></p>\n<p>One of the things that surprises people new to Python, is that there is no character data type in Python.</p>\n<p>Typically we have text data types in all the languages, don't we? <code class=\"language-text\">'Hello World'</code> for example, is text data, and we stored it in <code class=\"language-text\">message</code>. This is called a string.</p>\n<p>In other languages, you would have something to represent a single character symbol. For example in Java, you can have a <code class=\"language-text\">char</code> data type, to store a single character <code class=\"language-text\">ch</code>, in which <code class=\"language-text\">'h'</code> is one character. But in Python, there is no separate data type to store single characters.</p>\n<p>For example, let's see how Python treats the first character of the following string <code class=\"language-text\">message</code>. The way you can access the first character of a string is by saying <code class=\"language-text\">message[0]</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message <span class=\"token operator\">=</span> <span class=\"token string\">\"Hello World\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n    <span class=\"token string\">'H'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'str'</span><span class=\"token operator\">></span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">type</span><span class=\"token punctuation\">(</span>message<span class=\"token punctuation\">)</span>\n    <span class=\"token operator\">&lt;</span><span class=\"token keyword\">class</span> <span class=\"token string\">'str'</span><span class=\"token operator\">></span></code></pre></div>\n<p><code class=\"language-text\">type(message[0])</code> and <code class=\"language-text\">type(message)</code> print the same type <code class=\"language-text\">str</code>. No difference.</p>\n<p>In Python, whether you're talking about a string, or you're talking about a single character symbol, they are all represented by the same <code class=\"language-text\">class</code>, <code class=\"language-text\">str</code>.</p>\n<p><code class=\"language-text\">message[100]</code> throws an <code class=\"language-text\">IndexError</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span>\n    <span class=\"token string\">'H'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span>\n    <span class=\"token string\">'e'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">2</span><span class=\"token punctuation\">]</span>\n    <span class=\"token string\">'l'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">3</span><span class=\"token punctuation\">]</span>\n    <span class=\"token string\">'l'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> message<span class=\"token punctuation\">[</span><span class=\"token number\">100</span><span class=\"token punctuation\">]</span>\n    IndexError<span class=\"token punctuation\">:</span> string index out of <span class=\"token builtin\">range</span></code></pre></div>\n<p>It says: \"The given index is out of the range of the value of that specific string\".</p>\n<p>Let's say we would want to print all the characters in this string.</p>\n<p>The way you could do that, is by saying: <code class=\"language-text\">for ch in message: print(ch)</code>.</p>\n<p><strong>Summary</strong></p>\n<p>In this short step, we looked at the fact that there is no separate character class, or data type in Python. We also looked at how do we loop over a given string, and print all the characters present inside this string.</p>\n<p><strong>Step 04: The string module</strong></p>\n<p>In this step, we will introduce you to the <code class=\"language-text\">string</code> <code class=\"language-text\">module</code>.</p>\n<p>If we would want to use anything from a module in Python, you need to import that specific <code class=\"language-text\">module</code> into your program.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">import</span> string</code></pre></div>\n<p>If you do a <code class=\"language-text\">string.</code> and press , it would show the different things which are part of the <code class=\"language-text\">string</code> <code class=\"language-text\">module</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>\n    string<span class=\"token punctuation\">.</span>Formatter<span class=\"token punctuation\">(</span>       string<span class=\"token punctuation\">.</span>ascii_uppercase  string<span class=\"token punctuation\">.</span>octdigits\n    string<span class=\"token punctuation\">.</span>Template<span class=\"token punctuation\">(</span>        string<span class=\"token punctuation\">.</span>capwords<span class=\"token punctuation\">(</span>        string<span class=\"token punctuation\">.</span>printable\n    string<span class=\"token punctuation\">.</span>ascii_letters    string<span class=\"token punctuation\">.</span>digits           string<span class=\"token punctuation\">.</span>punctuation\n    string<span class=\"token punctuation\">.</span>ascii_lowercase  string<span class=\"token punctuation\">.</span>hexdigits        string<span class=\"token punctuation\">.</span>whitespace</code></pre></div>\n<p>Let's explore some of these.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_letters\n    <span class=\"token string\">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_lowercase\n    <span class=\"token string\">'abcdefghijklmnopqrstuvwxyz'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_uppercase\n    <span class=\"token string\">'ABCDEFGHIJKLMNOPQRSTUVWXYZ'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>digits\n    <span class=\"token string\">'0123456789'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>hexdigits\n    <span class=\"token string\">'0123456789abcdefABCDEF'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>punctuation\n    <span class=\"token string\">'!\"#$%&amp;\\'()*+,-./:;&lt;=>?@[\\\\]^_`{|}~'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_letters\n    <span class=\"token string\">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'</span></code></pre></div>\n<p>You have a set of printable characters, punctuation characters and a lot more.</p>\n<p>You can check a text value against any of these</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'a'</span> <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_letters\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'ab'</span> <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_letters\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'abc'</span> <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_letters\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p><code class=\"language-text\">in</code> operation on a string, checks if a given string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'1'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'13579'</span>\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'2'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'13579'</span>\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'4'</span> <span class=\"token keyword\">in</span> <span class=\"token string\">'13579'</span>\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we explored more exercises involving the <code class=\"language-text\">str</code> module of Python.</p>\n<p><strong>Step 05: More Exercises With The str Module</strong></p>\n<p>Let's start with an Exercise - find if a specific character is a vowel or not.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token operator\">=</span> <span class=\"token string\">'a'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> vowel_string <span class=\"token operator\">=</span> <span class=\"token string\">'aeiouAEIOU'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token keyword\">in</span> vowel_string\n    <span class=\"token boolean\">True</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token operator\">=</span> <span class=\"token string\">'b'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token keyword\">in</span> vowel_string\n    <span class=\"token boolean\">False</span></code></pre></div>\n<p>he other thing you can do, is just have the capital vowels, or just the lowercase versions.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> vowel_string <span class=\"token operator\">=</span> <span class=\"token string\">'AEIOU'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> vowel_string\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token operator\">=</span> <span class=\"token string\">'a'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">in</span> vowel_string\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p>Now let's move on to the next one.</p>\n<p>We want to find out and print all the capital alphabets, from <code class=\"language-text\">A</code> to <code class=\"language-text\">Z</code>.</p>\n<p>There was a small clue at the start of the previous step, regarding importing the <code class=\"language-text\">string</code> <code class=\"language-text\">module</code>. We did the <code class=\"language-text\">string</code> <code class=\"language-text\">module</code>, and we saw that <code class=\"language-text\">string</code> <code class=\"language-text\">module</code> contained a number of things.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string<span class=\"token punctuation\">.</span>ascii_uppercase\n    <span class=\"token string\">'ABCDEFGHIJKLMNOPQRSTUVWXYZ'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_uppercase<span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    A\n    B\n    C\n    D\n    E\n    F\n    G\n    H\n    I\n    J\n    K\n    L\n    M\n    N\n    O\n    P\n    Q\n    R\n    S\n    T\n    U\n    V\n    W\n    X\n    Y\n    Z</code></pre></div>\n<p>Try another easy exercise: print all the lower characters. Instead of <code class=\"language-text\">string.ascii_uppercase</code>, you have <code class=\"language-text\">string.ascii_lowercase</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>ascii_lowercase<span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    a\n    b\n    c\n    d\n    e\n    f\n    g\n    h\n    i\n    j\n    k\n    l\n    m\n    n\n    o\n    p\n    q\n    r\n    s\n    t\n    u\n    v\n    w\n    x\n    y\n    z</code></pre></div>\n<p>An even easier exercise, would be to print all the digits.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>\n    string<span class=\"token punctuation\">.</span>Formatter<span class=\"token punctuation\">(</span>       string<span class=\"token punctuation\">.</span>ascii_uppercase  string<span class=\"token punctuation\">.</span>octdigits\n    string<span class=\"token punctuation\">.</span>Template<span class=\"token punctuation\">(</span>        string<span class=\"token punctuation\">.</span>capwords<span class=\"token punctuation\">(</span>        string<span class=\"token punctuation\">.</span>printable\n    string<span class=\"token punctuation\">.</span>ascii_letters    string<span class=\"token punctuation\">.</span>digits           string<span class=\"token punctuation\">.</span>punctuation\n    string<span class=\"token punctuation\">.</span>ascii_lowercase  string<span class=\"token punctuation\">.</span>hexdigits        string<span class=\"token punctuation\">.</span>whitespace\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> char <span class=\"token keyword\">in</span> string<span class=\"token punctuation\">.</span>digits<span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>char<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>The last exercise which we want to leave you with, is to check if something is a consonant.</p>\n<p>A consonant is an alphabet which is not a vowel, so any alphabet which is not in <code class=\"language-text\">'aeiou'</code> is a consonant. The simplest way of doing this is to say <code class=\"language-text\">consonant_string = 'bcdfghj...'</code> and so on. Looks like a very long solution? There is an easier way out.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> vowel_string <span class=\"token operator\">=</span> <span class=\"token string\">'aeiou'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char <span class=\"token operator\">=</span> <span class=\"token string\">'b'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> char<span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">and</span> char<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">not</span> <span class=\"token keyword\">in</span> vowel_string\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p><strong>Step 06: More Exercises On Strings</strong></p>\n<p>In the step, let's look at a few more puzzles and exercises related to strings. Let's say we have a simple string, <code class=\"language-text\">string_example</code>, and this is contains an English sentence. <code class=\"language-text\">'This is a great thing.'</code></p>\n<p>Let's try to to print each of the words present in this string, on a separate line.</p>\n<p>So we would want to print <code class=\"language-text\">'This'</code>, <code class=\"language-text\">'is'</code>, <code class=\"language-text\">'a'</code>, <code class=\"language-text\">'great'</code> and <code class=\"language-text\">'thing'</code> on individual lines.</p>\n<p>One of the clues we'll give you is, try and do <code class=\"language-text\">string_example. &lt;TAB></code>. There are a huge list of methods, which would come up if you do that.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example <span class=\"token operator\">=</span> <span class=\"token string\">\"This is a great thing\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example<span class=\"token punctuation\">.</span>\n    string_example<span class=\"token punctuation\">.</span>capitalize<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>join<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>casefold<span class=\"token punctuation\">(</span>      string_example<span class=\"token punctuation\">.</span>ljust<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>center<span class=\"token punctuation\">(</span>        string_example<span class=\"token punctuation\">.</span>lower<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>count<span class=\"token punctuation\">(</span>         string_example<span class=\"token punctuation\">.</span>lstrip<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>encode<span class=\"token punctuation\">(</span>        string_example<span class=\"token punctuation\">.</span>maketrans<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>endswith<span class=\"token punctuation\">(</span>      string_example<span class=\"token punctuation\">.</span>partition<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>expandtabs<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>replace<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>find<span class=\"token punctuation\">(</span>          string_example<span class=\"token punctuation\">.</span>rfind<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span><span class=\"token builtin\">format</span><span class=\"token punctuation\">(</span>        string_example<span class=\"token punctuation\">.</span>rindex<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>format_map<span class=\"token punctuation\">(</span>    string_example<span class=\"token punctuation\">.</span>rjust<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">(</span>         string_example<span class=\"token punctuation\">.</span>rpartition<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isalnum<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>rsplit<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isalpha<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>rstrip<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isdecimal<span class=\"token punctuation\">(</span>     string_example<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isdigit<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>splitlines<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isidentifier<span class=\"token punctuation\">(</span>  string_example<span class=\"token punctuation\">.</span>startswith<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>islower<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>strip<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isnumeric<span class=\"token punctuation\">(</span>     string_example<span class=\"token punctuation\">.</span>swapcase<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isprintable<span class=\"token punctuation\">(</span>   string_example<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isspace<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>translate<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>istitle<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>upper<span class=\"token punctuation\">(</span>\n    string_example<span class=\"token punctuation\">.</span>isupper<span class=\"token punctuation\">(</span>       string_example<span class=\"token punctuation\">.</span>zfill<span class=\"token punctuation\">(</span></code></pre></div>\n<p>One of the methods in the list is the <code class=\"language-text\">split()</code> method.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'This'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'great'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'thing'</span><span class=\"token punctuation\">]</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> word <span class=\"token keyword\">in</span> string_example<span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    This\n    <span class=\"token keyword\">is</span>\n    a\n    great\n    thing</code></pre></div>\n<p><code class=\"language-text\">split_lines()</code> method looks for a <code class=\"language-text\">'\\n'</code>, and it divides the string based on it. If you have a string which contains newlines, and you would want to divide it into a number of strings with each line as a new element, the method you can use is <code class=\"language-text\">split_lines()</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example <span class=\"token operator\">=</span> <span class=\"token string\">\"This\\nis\\n\\ngreat\\nthing\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>string_example<span class=\"token punctuation\">)</span>\n    This\n    <span class=\"token keyword\">is</span>\n\n    great\n    thing\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example <span class=\"token operator\">=</span> <span class=\"token string\">\"This\\nis\\na\\ngreat\\nthing\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>string_example<span class=\"token punctuation\">)</span>\n    This\n    <span class=\"token keyword\">is</span>\n    a\n    great\n    thing\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> string_example<span class=\"token punctuation\">.</span>splitlines<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">[</span><span class=\"token string\">'This'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'is'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'great'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'thing'</span><span class=\"token punctuation\">]</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span></code></pre></div>\n<p>The last thing which we look at, is <strong>concatenation operator</strong>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"1\"</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"2\"</span>\n    <span class=\"token string\">'12'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"1\"</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n    TypeError<span class=\"token punctuation\">:</span> must be <span class=\"token builtin\">str</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">not</span> <span class=\"token builtin\">int</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">\"ABC\"</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"DEF\"</span>\n    <span class=\"token string\">'ABCDEF'</span></code></pre></div>\n<p>In Python, you cannot do <code class=\"language-text\">+</code> operator between two different types. <code class=\"language-text\">+</code> with two strings is concatenation. <code class=\"language-text\">+</code> with two numbers is addition.</p>\n<p>One other interesting operator on strings is multiplication. If you do a <code class=\"language-text\">'1' * 20</code>, What do you think will be the output?</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token number\">1</span> <span class=\"token operator\">*</span> <span class=\"token number\">20</span>\n    <span class=\"token number\">20</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'1'</span> <span class=\"token operator\">*</span> <span class=\"token number\">20</span>\n    <span class=\"token string\">'11111111111111111111'</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token string\">'A'</span> <span class=\"token operator\">*</span> <span class=\"token number\">10</span>\n    <span class=\"token string\">'AAAAAAAAAA'</span></code></pre></div>\n<p>If you multiply a string with <code class=\"language-text\">number</code>, the string value is concatenated <code class=\"language-text\">number</code> times.</p>\n<p>The last thing which we look at in this step, is comparing strings.</p>\n<p>Let's say we have a string with a value <code class=\"language-text\">str = 'test'</code>, and you have another string to with a value <code class=\"language-text\">str1 = 'test1'</code>.</p>\n<p>We want to check whether both these strings are the same.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"test\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> str2 <span class=\"token operator\">=</span> <span class=\"token string\">\"test1\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span> <span class=\"token operator\">==</span> str2\n    <span class=\"token boolean\">False</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> str2 <span class=\"token operator\">=</span> <span class=\"token string\">\"test\"</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token builtin\">str</span> <span class=\"token operator\">==</span> str2\n    <span class=\"token boolean\">True</span></code></pre></div>\n<p>You can compare strings using the <code class=\"language-text\">==</code> operator.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we explored a few exercises on strings, covering areas such as:</p>\n<ul>\n<li>Splitting a given sentence into individual words</li>\n<li>The concatenation operator, <code class=\"language-text\">+</code></li>\n<li>The string multiplication pattern, <code class=\"language-text\">*</code></li>\n<li>The use of the <code class=\"language-text\">==</code> operator to compare strings</li>\n</ul>\n<h4>Chapter 07 - Introducing Loops</h4>\n<p>Welcome to the section on Loops. In this section, we will look at a variety of loops that are available in Python. We will look mainly at the <strong><code class=\"language-text\">for</code></strong> loop, and the <strong><code class=\"language-text\">while</code></strong> loop.</p>\n<p><strong>Step 01: Revisited: The for Loop</strong></p>\n<p>Let's start with revising the basics of the for loop, we have learned in the previous steps.</p>\n<p>We saw that a <code class=\"language-text\">for</code> loop helps us to loop around the same set of code statements, many times over.</p>\n<p>Let's look at a few simple examples, once again.</p>\n<p><strong>Snippet-01</strong></p>\n<p>The syntax of a <code class=\"language-text\">for</code> loop is very simple.</p>\n<p>For example, this code snippet will tell you all about it: <code class=\"language-text\">for i in range(1, 11): print(i)</code>.</p>\n<p>What does this do? Very simple, it prints from <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code>.</p>\n<p>In the call to the <code class=\"language-text\">range()</code> function, the second parameter is exclusive. We are actually looping from <code class=\"language-text\">1</code> to <code class=\"language-text\">10</code>, and this piece of code, <code class=\"language-text\">print(i)</code>, is being executed for different values of <code class=\"language-text\">i</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span><span class=\"token number\">11</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">7</span>\n    <span class=\"token number\">8</span>\n    <span class=\"token number\">9</span>\n    <span class=\"token number\">10</span></code></pre></div>\n<p><code class=\"language-text\">for</code> loop can also be used to loop round the characters in a string.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> ch <span class=\"token keyword\">in</span> <span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>ch<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    H\n    e\n    l\n    l\n    o\n    W\n    o\n    r\n    l\n    d</code></pre></div>\n<p><code class=\"language-text\">for</code> loop can be used to loop around all the words in a given sentence.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> word <span class=\"token keyword\">in</span> <span class=\"token string\">\"Hello World\"</span><span class=\"token punctuation\">.</span>split<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>word<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    Hello\n    World</code></pre></div>\n<p><code class=\"language-text\">for</code> loop can be used to loop around a specific list of values.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> item <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">,</span> <span class=\"token number\">6</span><span class=\"token punctuation\">,</span> <span class=\"token number\">9</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">6</span>\n    <span class=\"token number\">9</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we started with discussing and revising basic concepts about the <code class=\"language-text\">for</code> loop</p>\n<p><strong>Step 02: Programming Exercise PE-LO-01</strong></p>\n<p>Welcome back to this step, where we would do a lot of exercises with the <code class=\"language-text\">for</code> loop.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li>\n<p>The first exercise is to find out if a number is prime. We want to write a method, <code class=\"language-text\">is_prime()</code>, which accepts an integer value as parameter, and returns whether it's a prime. (<strong>Hint</strong>: A prime number is something which is only divisible by <code class=\"language-text\">1</code> and itself).</p>\n<ol>\n<li><code class=\"language-text\">5</code> is only divisible by <code class=\"language-text\">1</code> and <code class=\"language-text\">5</code>. It is not divisible by any other number. Same is the case with <code class=\"language-text\">7</code> and <code class=\"language-text\">11</code>.</li>\n<li>However, <code class=\"language-text\">6</code> is divisible by <code class=\"language-text\">1</code>, <code class=\"language-text\">2</code>, <code class=\"language-text\">3</code> and <code class=\"language-text\">6</code>. So it's not a prime number.</li>\n</ol>\n</li>\n<li>The second exercise is to write a method to calculate the sum up to a given integer, starting from <code class=\"language-text\">1</code>. <strong>Hint</strong>: If I would want to find that the sum up to <code class=\"language-text\">6</code>. what's needed is <code class=\"language-text\">1 + 2 + 3 + 4 + 5 + 6</code>.</li>\n<li>The third exercise is to find that the sum of divisors of a given integer. <strong>Hint</strong>: Let's say we want to find out the sum of the divisors of <code class=\"language-text\">15</code>. The divisors of <code class=\"language-text\">15</code> are <code class=\"language-text\">1</code>, <code class=\"language-text\">3</code>, <code class=\"language-text\">5</code> and <code class=\"language-text\">15</code>. So I would want to calculate <code class=\"language-text\">1 + 3 + 5 + 15</code>, and return that value.</li>\n<li>Fourth exercise is to print a numbered triangle, when given a specific integer.</li>\n</ol>\n<p>Hint: Given an input <code class=\"language-text\">5</code>, we would want to print the number triangle of these kind:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>\n<span class=\"token number\">1</span> <span class=\"token number\">2</span>\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span>\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5.</span></code></pre></div>\n<p>These are the exercises for the <code class=\"language-text\">for</code> loop. We also test our skills, with creating method and executing them, in our IDE.</p>\n<p><strong>Solution 1</strong></p>\n<p>Let's start with creating the <code class=\"language-text\">is_prime()</code> method, in a file named <code class=\"language-text\">for_exercises</code>.</p>\n<p>We would want to accept an <code class=\"language-text\">int</code> parameter, and find out if it is prime, or not.</p>\n<p>We need to check whether it's divisible by any other number, other than <code class=\"language-text\">1</code> and itself. If we are passed in a value of <code class=\"language-text\">5</code>, you want to see if it's divisible by any of <code class=\"language-text\">2</code>, <code class=\"language-text\">3</code> or <code class=\"language-text\">4</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">is_prime</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span></code></pre></div>\n<p>We can use a <code class=\"language-text\">for</code> loop. We can structure it like this: <code class=\"language-text\">for divisor in range(1, number): ...</code>. We would not want to divide it with <code class=\"language-text\">1</code>, but start with <code class=\"language-text\">2</code> instead, and go up to <code class=\"language-text\">number-1</code>, which is <code class=\"language-text\">4</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span></code></pre></div>\n<p>How can we check if the <code class=\"language-text\">number</code> is divisible by <code class=\"language-text\">divisor</code>?</p>\n<p>By using the <code class=\"language-text\">%</code> operator. If <code class=\"language-text\">number</code> is divisible by <code class=\"language-text\">divisor</code> we return <code class=\"language-text\">False</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> number <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span></code></pre></div>\n<p>What happens if the code comes up to the end? It would mean we tried with <code class=\"language-text\">2</code>, <code class=\"language-text\">3</code> and <code class=\"language-text\">4</code>, but <code class=\"language-text\">number</code> was not divisible by all of them. In that case, <code class=\"language-text\">number</code> would be prime, and we can safely return <code class=\"language-text\">True</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span> number <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token boolean\">True</span></code></pre></div>\n<p>For <code class=\"language-text\">1</code>, the rules are a little different, as it is neither a prime or composite. We will add an <code class=\"language-text\">if</code> condition to check if the number is <code class=\"language-text\">1</code>. <code class=\"language-text\">if(number &lt; 2):</code></p>\n<p>This <code class=\"language-text\">if</code> condition is called a guard check or a boundary check, to make sure that you are processing only the right input. If <code class=\"language-text\">number</code> has a value less than <code class=\"language-text\">2</code>, do nothing. OK, it's not a prime.</p>\n<p>Here is the entire code at one place, for your reference:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">is_prime</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>number <span class=\"token operator\">&lt;</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>\n    <span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">,</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">if</span> number <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n            <span class=\"token keyword\">return</span> <span class=\"token boolean\">False</span>\n    <span class=\"token keyword\">return</span> <span class=\"token boolean\">True</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>is_prime<span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><strong>Step 03: Continued - Programming Exercise PE-LO-01</strong></p>\n<p>In the previous step, we looked at solving the <code class=\"language-text\">is_prime()</code> exercise. In this step, let's look at an implementation of <code class=\"language-text\">sum_up_to_n()</code>. Here is the entire code for this exercise:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sum_upto_n</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">+</span> i\n    <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>sum_upto_n<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>sum_upto_n<span class=\"token punctuation\">(</span><span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Wrote a Python function to compute the sum of all integers, from <code class=\"language-text\">1</code>, up to the input integer <code class=\"language-text\">n</code>.</li>\n</ul>\n<p><strong>Step 04: Continued - Programming Exercise PE-LO-01</strong></p>\n<p>Let's focus on the third exercise, <code class=\"language-text\">sum_of_divisors</code>.</p>\n<p>One of the clues we can give you, is that <code class=\"language-text\">sum_of_divisors()</code> is very similar to <code class=\"language-text\">is_prime()</code>.</p>\n<p>You want to find out if a number is dividing <code class=\"language-text\">15</code>, and if it's dividing <code class=\"language-text\">15</code>, with the remainder of <code class=\"language-text\">0</code>, then you need to add that up.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">calculate_sum_of_divisors</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n    <span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span>number <span class=\"token operator\">&lt;</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span>\n    <span class=\"token keyword\">for</span> divisor <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">if</span> number <span class=\"token operator\">%</span> divisor <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">:</span>\n            <span class=\"token builtin\">sum</span> <span class=\"token operator\">=</span> <span class=\"token builtin\">sum</span> <span class=\"token operator\">+</span> divisor\n    <span class=\"token keyword\">return</span> <span class=\"token builtin\">sum</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculate_sum_of_divisors<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>calculate_sum_of_divisors<span class=\"token punctuation\">(</span><span class=\"token number\">15</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><strong>Step 05: Continued - Programming Exercise PE-LO-01</strong></p>\n<p>In this step, Let's look at the last exercise - <code class=\"language-text\">print_a_number_triangle</code>.</p>\n<p>For example, if we call such a function with input <code class=\"language-text\">5</code>, the output needs to be:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>\n\n<span class=\"token number\">1</span> <span class=\"token number\">2</span>\n\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>\n\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span>\n\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span></code></pre></div>\n<p>Let start with a simple thing. Let's try and print <code class=\"language-text\">1 2 3 4 5</code> first, and then we would look at how to print the rest of the output. Lets proceed with defining this method.</p>\n<p>We can say <code class=\"language-text\">def print_a_number_triangle(number): ...</code> that takes a number as an input. You want to print a sequence of integers starting from <code class=\"language-text\">1</code>, up to that specific <code class=\"language-text\">number</code>. How can you do that? Let's try this: <code class=\"language-text\">for i in range(1,number+1): print(i)</code> What would happen? Let's call <code class=\"language-text\">print_a_number_triangle(5)</code> now. It prints:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span>\n    <span class=\"token number\">5</span></code></pre></div>\n<p>on individual lines.</p>\n<p>To print this sequence on a single line, let's delimit them with <code class=\"language-text\">&lt;SPACE></code> instead. Call <code class=\"language-text\">print()</code> like this instead: <code class=\"language-text\">for i in range(1,number+1): print(i, end=\" \")</code>.</p>\n<p>Let's see what would happen now. <code class=\"language-text\">1 2 3 4 5</code></p>\n<p>To solve our exercise, we want to repeat this again and again.</p>\n<p>Yes, we need another for loop around it!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> j <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Make sure that you have the indentation right. This is called <code class=\"language-text\">loop within a loop</code>.</p>\n<p>The output of above program is</p>\n<p><code class=\"language-text\">1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5</code></p>\n<p>Let's add <code class=\"language-text\">print(\"\\n\")</code>, so we have a new line at the end of each outer loop iteration.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> j <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Output</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span>\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span>\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span>\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span>\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span></code></pre></div>\n<p>We are printing a square, not a triangle.</p>\n<p>What we want to do is to print up to <code class=\"language-text\">1</code> in first line, upto <code class=\"language-text\">2</code> in second line and so on.</p>\n<p>How can we do that? Think about it.</p>\n<p>When you are inside this loop, you can see the variable <code class=\"language-text\">j</code>.</p>\n<p>Instead of <code class=\"language-text\">number+1</code>, let's say <code class=\"language-text\">j + 1</code>.</p>\n<p>When <code class=\"language-text\">j</code> has a value of <code class=\"language-text\">1</code>, <code class=\"language-text\">for</code> will print from <code class=\"language-text\">1</code> to <code class=\"language-text\">1</code>. When <code class=\"language-text\">j</code> has a value of <code class=\"language-text\">2</code>, print from <code class=\"language-text\">1</code> to <code class=\"language-text\">2</code>, literally printing <code class=\"language-text\">1 2</code>. When j has a value of <code class=\"language-text\">3</code>, I'll print from <code class=\"language-text\">1</code> to <code class=\"language-text\">3</code>. Let's try this and see what would happen.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">for</span> j <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number<span class=\"token operator\">+</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>You can see that our number triangle is ready!</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token number\">1</span>\n\n<span class=\"token number\">1</span> <span class=\"token number\">2</span>\n\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span>\n\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span>\n\n<span class=\"token number\">1</span> <span class=\"token number\">2</span> <span class=\"token number\">3</span> <span class=\"token number\">4</span> <span class=\"token number\">5</span></code></pre></div>\n<p>Here is the entire code for you:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">print_a_number_triangle</span><span class=\"token punctuation\">(</span>number<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">for</span> j <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> number <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> j <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n            <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> end<span class=\"token operator\">=</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nprint_a_number_triangle<span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>An important point to note is, a couple of these things can be done in a much simpler way. We will look at these options when we talk about functional programming.</p>\n<p><strong>Summary</strong></p>\n<p>In this step, we:</p>\n<ul>\n<li>Presented a solution to the exercise for printing a number triangle.</li>\n</ul>\n<p><strong>Step 06: Introducing The while Loop</strong></p>\n<p>Let's look at one of the other loops which is present in Python, called the <strong><code class=\"language-text\">while</code></strong> loop.</p>\n<p>In the <code class=\"language-text\">for</code> loop, we can specify the range of our iteration, by using the <code class=\"language-text\">range()</code> function.</p>\n<p>In a <code class=\"language-text\">while</code> loop, we specify a logical condition. While the condition is true, loop continues running.</p>\n<p>Do you remember one place where we use the condition until now? It was in an <code class=\"language-text\">if</code> statement.</p>\n<p>Let's see how to use a simple <code class=\"language-text\">while</code> loop.</p>\n<p><strong>Snippet-01:</strong></p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">5</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">if</span> i <span class=\"token operator\">==</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"i is 5\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    i <span class=\"token keyword\">is</span> <span class=\"token number\">5</span></code></pre></div>\n<p>Let's say <code class=\"language-text\">i</code> has a value of <code class=\"language-text\">0</code>, and we then do: <code class=\"language-text\">while i &lt; 5: print(i)</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span>\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">while</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token operator\">^</span>CTraceback <span class=\"token punctuation\">(</span>most recent call last<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n      File <span class=\"token string\">\"&lt;stdin>\"</span><span class=\"token punctuation\">,</span> line <span class=\"token number\">2</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">in</span> <span class=\"token operator\">&lt;</span>module<span class=\"token operator\">></span>\n    KeyboardInterrupt\n    <span class=\"token operator\">>></span><span class=\"token operator\">></span>\n    KeyboardInterrupt</code></pre></div>\n<p>If we leave it to run, you'd see that it continuously prints <code class=\"language-text\">0</code> again, and again. Let's do a <code class=\"language-text\">&lt;CTRL-C></code> or <code class=\"language-text\">&lt;COMMAND-C></code> to interrupt this.</p>\n<p>What is happening here?</p>\n<p>Initially <code class=\"language-text\">i</code> is <code class=\"language-text\">0</code>, and the condition <code class=\"language-text\">i &lt; 5</code> is <code class=\"language-text\">True</code>, and <code class=\"language-text\">print(i)</code> is executed. Next iteration, it checks the condition, it is <code class=\"language-text\">True</code>, and <code class=\"language-text\">0</code> is printed. This continues to happen. What's happening is an <strong>infinite loop</strong>.</p>\n<p>One of the important things to make sure in a <code class=\"language-text\">while</code> loop, is to increment the value of <code class=\"language-text\">i</code>. We need to say something like <code class=\"language-text\">i = i + 1</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">while</span> i <span class=\"token operator\">&lt;</span> <span class=\"token number\">5</span><span class=\"token punctuation\">:</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>   i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span></code></pre></div>\n<p>So how does it work? *<code class=\"language-text\">i</code> initially had a value of <code class=\"language-text\">0</code>. First the condition is checked. It's <code class=\"language-text\">True</code>, so <code class=\"language-text\">0</code> is printed and then the value of <code class=\"language-text\">i</code> is incremented to <code class=\"language-text\">1</code>.</p>\n<ul>\n<li><code class=\"language-text\">i</code> is still less than <code class=\"language-text\">5</code>, so the loop continues to execute, and this happens until <code class=\"language-text\">4</code> is printed. <code class=\"language-text\">i</code> again gets incremented to <code class=\"language-text\">4 + 1</code>, or <code class=\"language-text\">5</code>.</li>\n<li>Then we check the condition <code class=\"language-text\">i &lt; 5</code>. This is now <code class=\"language-text\">False</code>. Control goes out of the <code class=\"language-text\">while</code> loop, and terminates it.</li>\n</ul>\n<p>When executing a <code class=\"language-text\">while</code>, control flow is just based on a condition. As long as the condition is <code class=\"language-text\">True</code>, we keep executing the code. An important thing to remember, is to make sure the control variable is updated.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">    <span class=\"token operator\">>></span><span class=\"token operator\">></span> <span class=\"token keyword\">for</span> i <span class=\"token keyword\">in</span> <span class=\"token builtin\">range</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span> <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n    <span class=\"token number\">0</span>\n    <span class=\"token number\">1</span>\n    <span class=\"token number\">2</span>\n    <span class=\"token number\">3</span>\n    <span class=\"token number\">4</span></code></pre></div>\n<p>A <code class=\"language-text\">for</code> loop is much simpler to code than a <code class=\"language-text\">while</code>. With <code class=\"language-text\">while</code>, we have to write an expression statement, to increment the value.</p>\n<p>The question you might have is - What are the situations when you should use a while?</p>\n<p>We will look at that very soon.</p>\n<p><strong>Summary</strong></p>\n<p>In this video, we:</p>\n<ul>\n<li>Were introduced to the concept of a <code class=\"language-text\">while</code> loop in Python</li>\n<li>Understood the importance of a control variable being incremented inside the loop</li>\n<li>Observed differences between the working of a <code class=\"language-text\">while</code>, and a <code class=\"language-text\">for</code> loop</li>\n</ul>\n<p><strong>Step 07: Programming Exercise PE-LO-02</strong></p>\n<p>In the previous step, we were introduced to <code class=\"language-text\">while</code> loop. In this step, let's look at a couple of exercises using the <code class=\"language-text\">while</code> loop.</p>\n<p><strong>Exercises</strong></p>\n<ol>\n<li><code class=\"language-text\">print_squares_upto_limit(30)</code>: We need to print all the squares of numbers, up to a limit of <code class=\"language-text\">30</code>. The output needs to be <code class=\"language-text\">1 4 9 16 25</code>.</li>\n<li><code class=\"language-text\">print_cubes_upto_limit(30)</code>: We need to print all the cubes of numbers, up to a limit of <code class=\"language-text\">30</code>.The output needs to be 1 8 27.</li>\n</ol>\n<p><strong>Exercise 1: Solution</strong></p>\n<p>Here is the entire code for your reference:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">print_squares_upto_limit</span><span class=\"token punctuation\">(</span>limit<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">while</span> i <span class=\"token operator\">*</span> i <span class=\"token operator\">&lt;</span> limit<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> <span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span>\n        i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span></code></pre></div>\n<p>Now the next exercise, was to print cubes up to a limit.</p>\n<p>The expression in the <code class=\"language-text\">while</code> condition should now be <code class=\"language-text\">i*i*i &lt; 30</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">print_cubes_upto_limit</span><span class=\"token punctuation\">(</span>limit<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    i <span class=\"token operator\">=</span> <span class=\"token number\">1</span>\n    <span class=\"token keyword\">while</span> i <span class=\"token operator\">*</span> i <span class=\"token operator\">*</span> i <span class=\"token operator\">&lt;</span> limit<span class=\"token punctuation\">:</span>\n        <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>i<span class=\"token operator\">*</span>i<span class=\"token operator\">*</span>i<span class=\"token punctuation\">,</span> end <span class=\"token operator\">=</span> <span class=\"token string\">\" \"</span><span class=\"token punctuation\">)</span>\n        i <span class=\"token operator\">=</span> i <span class=\"token operator\">+</span> <span class=\"token number\">1</span>\nprint_cubes_upto_limit<span class=\"token punctuation\">(</span><span class=\"token number\">80</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Could we have implemented above two examples with <code class=\"language-text\">for</code> loop? It would've been a little more difficult.</p>\n<p>Typically, we use a <code class=\"language-text\">for</code> loop when we know how many times the loop will be executed is clear at the start.</p>\n<p>If we do not know, how many times a loop will run, <code class=\"language-text\">while</code> is a better option.</p>\n<p><strong>Step 08: While Example</strong></p>\n<p>Earlier we used <code class=\"language-text\">if</code> statement to implement a solution for this:</p>\n<ul>\n<li>\n<p>Ask the User for input:</p>\n<ul>\n<li>Enter two numbers</li>\n<li>\n<p>Choose the Option:</p>\n<ul>\n<li>1 - Add</li>\n<li>2 - Subtract</li>\n<li>3 - Multiply</li>\n<li>4 - Divide</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Perform the Operation</li>\n<li>Publish the Result</li>\n</ul>\n<p>We would want to enhance it to execute in a loop multiple times, until the user chooses to exit. We will add an option 5 - Exit.</p>\n<ul>\n<li>\n<p>Ask the User for input:</p>\n<ul>\n<li>Enter two numbers</li>\n<li>\n<p>Choose the Option:</p>\n<ul>\n<li>1 - Add</li>\n<li>2 - Subtract</li>\n<li>3 - Multiply</li>\n<li>4 - Divide</li>\n<li>5 - Exit</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Perform the Operation</li>\n<li>Publish the Result</li>\n<li>Repeat until Option 5 is chosen.</li>\n</ul>\n<p><strong>Snippet-01 Explained</strong></p>\n<p>Here's the earlier code we wrote with if:</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\">number1 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number1: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\nnumber2 <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Enter Number2: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"\\n\\n1 - Add\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"2 - Subtract\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"3 - Divide\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"4 - Multiply\"</span><span class=\"token punctuation\">)</span>\n\nchoice <span class=\"token operator\">=</span> <span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span><span class=\"token builtin\">input</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Choose Operation: \"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># print(number1 + number2)</span>\n<span class=\"token comment\"># print(choice)</span>\n<span class=\"token keyword\">if</span> choice<span class=\"token operator\">==</span><span class=\"token number\">1</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> number1 <span class=\"token operator\">+</span> number2\n<span class=\"token keyword\">elif</span> choice<span class=\"token operator\">==</span><span class=\"token number\">2</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> number1 <span class=\"token operator\">-</span> number2\n<span class=\"token keyword\">elif</span> choice<span class=\"token operator\">==</span><span class=\"token number\">3</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> number1 <span class=\"token operator\">/</span> number2\n<span class=\"token keyword\">elif</span> choice<span class=\"token operator\">==</span><span class=\"token number\">4</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> number1 <span class=\"token operator\">*</span> number2\n<span class=\"token keyword\">else</span><span class=\"token punctuation\">:</span>\n    result <span class=\"token operator\">=</span> <span class=\"token string\">\"Invalid Choice\"</span>\n\n<span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">)</span></code></pre></div>"},{"url":"/docs/readme/","relativePath":"docs/readme.md","relativeDir":"docs","base":"readme.md","name":"readme","frontmatter":{"title":"README","subtitle":"for this website","seo":{"title":"","description":"","robots":[],"extra":[]},"template":"page","image":"images/bgoonzblog20-a6a3bfc3.png"},"html":"<h1 align=\"center\">Hi 👋, I'm Bryan</h1>\n<h2><div class=\"important\"><strong>Readme Page<strong></div></h2>\n<div align=\"center\">\n<p><img src=\"https://komarev.com/ghpvc/?username=bgoonz\" alt=\"profile views\"></p>\n<h2><a href=\"https://bgoonz-blog.netlify.app/\"><b>WEBSITE</b></a></h2>\n<h1>Search Website: <a href=\"https://www.algolia.com/realtime-search-demo/web-dev-resource-hub-9e6b8aa8-6106-44c5-9f59-ff3f9531abd4\">search</a></h1>\n<h2><a href=\"https://bgoonzblog20-backup.netlify.app/#gsc.tab=0\">Backup Repo Deploy</a></h2>\n<h2><a href=\"https://bgoonz.github.io/BGOONZ_BLOG_2.0/\">Github pages</a></h2>\n<p><img src=\"https://views.whatilearened.today/views/github/bgoonz/views.svg\" alt=\"Profile views\"><a href=\"https://gitter.im/bgoonz/community?utm_source=badge&#x26;utm_medium=badge&#x26;utm_campaign=pr-badge\"><img src=\"https://badges.gitter.im/bgoonz/community.svg\" alt=\"Gitter\"></a></p>\n<p><a href=\"https://app.netlify.com/sites/best-celery-b2d7c/deploys\"><img src=\"https://api.netlify.com/api/v1/badges/a1b7ee1a-11a7-4bd2-a341-2260656e216f/deploy-status\" alt=\"Netlify Status\"></a></p>\n<p><a href=\"https://codescene.io/projects/17026\"><img src=\"https://codescene.io/projects/17026/status-badges/system-mastery\" alt=\"CodeScene System Mastery\"></a></p>\n<p><img src=\"https://github.com/bgoonz/BGOONZ_BLOG_2.0/blob/master/static/images/iframes.gif?raw=true\" alt=\"Demo\"></p>\n<h1>Homepage</h1>\n<p><img src=\"./static/images/bgoonzblog20.png\" alt=\"Homepage\"></p>\n</div>\n<h1>Technologies used</h1>\n<h2><a href=\"https://trends.builtwith.com/analytics/Global-Site-Tag\">Global Site Tag</a></h2>\n<p><a href=\"https://trends.builtwith.com/analytics/Global-Site-Tag\">Global Site Tag Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Global-Site-Tag\">Download List of All Websites using Global Site Tag</a></p>\n<p>Google's primary tag for Google Measurement/Conversion Tracking, Adwords and DoubleClick.</p>\n<h2><a href=\"https://trends.builtwith.com/analytics/Google-Analytics\">Google Analytics</a></h2>\n<p><a href=\"https://trends.builtwith.com/analytics/Google-Analytics\">Google Analytics Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Analytics\">Download List of All Websites using Google Analytics</a></p>\n<p>Google Analytics offers a host of compelling features and benefits for everyone from senior executives and advertising and marketing professionals to site owners and content developers.</p>\n<p><a href=\"https://trends.builtwith.com/analytics/application-performance\">Application Performance</a> - <a href=\"https://trends.builtwith.com/analytics/audience-measurement\">Audience Measurement</a> - <a href=\"https://trends.builtwith.com/analytics/visitor-count-tracking\">Visitor Count Tracking</a></p>\n<h5><a href=\"https://trends.builtwith.com/analytics/Google-Analytics-4\">Google Analytics 4</a></h5>\n<p><a href=\"https://trends.builtwith.com/analytics/Google-Analytics-4\">Google Analytics 4 Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Analytics-4\">Download List of All Websites using Google Analytics 4</a></p>\n<p>Google Analytics 4 formerly known as App + Web is a new version of Google Analytics that was released in October 2020.</p>\n<h6>Widgets</h6>\n<p><a href=\"https://trends.builtwith.com/widgets\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/widgets/Imgur\">Imgur</a></h2>\n<p><a href=\"https://trends.builtwith.com/widgets/Imgur\">Imgur Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Imgur\">Download List of All Websites using Imgur</a></p>\n<p>The page contains content from image sharing website imgur.</p>\n<h2><a href=\"https://trends.builtwith.com/widgets/Google-Font-API\">Google Font API</a></h2>\n<p><a href=\"https://trends.builtwith.com/widgets/Google-Font-API\">Google Font API Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Font-API\">Download List of All Websites using Google Font API</a></p>\n<p>The Google Font API helps you add web fonts to any web page.</p>\n<p><a href=\"https://trends.builtwith.com/widgets/fonts\">Fonts</a></p>\n<h2><a href=\"https://trends.builtwith.com/widgets/Google-Tag-Manager\">Google Tag Manager</a></h2>\n<p><a href=\"https://trends.builtwith.com/widgets/Google-Tag-Manager\">Google Tag Manager Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Tag-Manager\">Download List of All Websites using Google Tag Manager</a></p>\n<p>Tag management that lets you add and update website tags without changes to underlying website code.</p>\n<p><a href=\"https://trends.builtwith.com/widgets/tag-management\">Tag Management</a></p>\n<h2><a href=\"https://trends.builtwith.com/widgets/Icons8\">Icons8</a></h2>\n<p><a href=\"https://trends.builtwith.com/widgets/Icons8\">Icons8 Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Icons8\">Download List of All Websites using Icons8</a></p>\n<p>Icons, photos and illustrations.</p>\n<p><a href=\"https://trends.builtwith.com/widgets/image-provider\">Image Provider</a></p>\n<h2><a href=\"https://trends.builtwith.com/widgets/Lorem-Ipsum\">Lorem Ipsum</a></h2>\n<p><a href=\"https://trends.builtwith.com/widgets/Lorem-Ipsum\">Lorem Ipsum Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Lorem-Ipsum\">Download List of All Websites using Lorem Ipsum</a></p>\n<p>This website contains the phrase 'lorem ipsum' which means it may have placeholder text.</p>\n<h2><a href=\"https://trends.builtwith.com/widgets/AddThis\">AddThis</a></h2>\n<p><a href=\"https://trends.builtwith.com/widgets/AddThis\">AddThis Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/AddThis\">Download List of All Websites using AddThis</a></p>\n<p>Widgets that allow visitors to save and promote the site.</p>\n<p><a href=\"https://trends.builtwith.com/widgets/social-sharing\">Social Sharing</a> - <a href=\"https://trends.builtwith.com/widgets/bookmarking\">Bookmarking</a></p>\n<h2><a href=\"https://trends.builtwith.com/widgets/tawk.to\">tawk.to</a></h2>\n<p><a href=\"https://trends.builtwith.com/widgets/tawk.to\">tawk.to Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/tawk.to\">Download List of All Websites using tawk.to</a></p>\n<p>tawk.to is a free live chat app that lets you monitor and chat with visitors.</p>\n<p><a href=\"https://trends.builtwith.com/widgets/live-chat\">Live Chat</a></p>\n<h6>Frameworks</h6>\n<p><a href=\"https://trends.builtwith.com/framework\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/framework/Gatsby-JS\">Gatsby JS</a></h2>\n<p><a href=\"https://trends.builtwith.com/framework/Gatsby-JS\">Gatsby JS Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Gatsby-JS\">Download List of All Websites using Gatsby JS</a></p>\n<p>Modern website and web apps generator for React.</p>\n<h6>Mobile</h6>\n<p><a href=\"https://trends.builtwith.com/mobile\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/mobile/Viewport-Meta\">Viewport Meta</a></h2>\n<p><a href=\"https://trends.builtwith.com/mobile/Viewport-Meta\">Viewport Meta Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Viewport-Meta\">Download List of All Websites using Viewport Meta</a></p>\n<p>This page uses the viewport meta tag which means the content may be optimized for mobile content.</p>\n<h2><a href=\"https://trends.builtwith.com/mobile/IPhone---Mobile-Compatible\">IPhone / Mobile Compatible</a></h2>\n<p><a href=\"https://trends.builtwith.com/mobile/IPhone---Mobile-Compatible\">IPhone / Mobile Compatible Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/IPhone---Mobile-Compatible\">Download List of All Websites using IPhone / Mobile Compatible</a></p>\n<p>The website contains code that allows the page to support IPhone / Mobile Content.</p>\n<h2><a href=\"https://trends.builtwith.com/mobile/Apple-Mobile-Web-Clips-Icon\">Apple Mobile Web Clips Icon</a></h2>\n<p><a href=\"https://trends.builtwith.com/mobile/Apple-Mobile-Web-Clips-Icon\">Apple Mobile Web Clips Icon Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Apple-Mobile-Web-Clips-Icon\">Download List of All Websites using Apple Mobile Web Clips Icon</a></p>\n<p>This page contains an icon for iPhone, iPad and iTouch devices.</p>\n<h6>Content Delivery Network</h6>\n<p><a href=\"https://trends.builtwith.com/cdn\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/cdn/AJAX-Libraries-API\">AJAX Libraries API</a></h2>\n<p><a href=\"https://trends.builtwith.com/cdn/AJAX-Libraries-API\">AJAX Libraries API Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/AJAX-Libraries-API\">Download List of All Websites using AJAX Libraries API</a></p>\n<p>The AJAX Libraries API is a content distribution network and loading architecture for the most popular, open source JavaScript libraries.</p>\n<h2><a href=\"https://trends.builtwith.com/cdn/jsDelivr\">jsDelivr</a></h2>\n<p><a href=\"https://trends.builtwith.com/cdn/jsDelivr\">jsDelivr Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/jsDelivr\">Download List of All Websites using jsDelivr</a></p>\n<p>A free CDN where Javascript developers can host their files. Encompasses MaxCDN, and BootstrapCDN.</p>\n<h2><a href=\"https://trends.builtwith.com/cdn/CloudFront\">CloudFront</a></h2>\n<p><a href=\"https://trends.builtwith.com/cdn/CloudFront\">CloudFront Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/CloudFront\">Download List of All Websites using CloudFront</a></p>\n<p>Amazon CloudFront is a web service for content delivery. It integrates with other Amazon Web Services to give developers and businesses an easy way to distribute content to end users with low latency, high data transfer speeds, and no commitments.</p>\n<h6>Content Management System</h6>\n<p><a href=\"https://trends.builtwith.com/cms\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/cms/Netlify\">Netlify</a></h2>\n<p><a href=\"https://trends.builtwith.com/cms/Netlify\">Netlify Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Netlify\">Download List of All Websites using Netlify</a></p>\n<p>Netlify is a platform that automates your code to create web sites.</p>\n<h6>JavaScript Libraries and Functions</h6>\n<p><a href=\"https://trends.builtwith.com/javascript\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/javascript/Google-Hosted-Libraries\">Google Hosted Libraries</a></h2>\n<p><a href=\"https://trends.builtwith.com/javascript/Google-Hosted-Libraries\">Google Hosted Libraries Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Hosted-Libraries\">Download List of All Websites using Google Hosted Libraries</a></p>\n<p>Google Hosted Libraries is a globally available content distribution network for the most popular, open-source JavaScript libraries.</p>\n<h5><a href=\"https://trends.builtwith.com/javascript/Google-Hosted-jQuery\">Google Hosted jQuery</a></h5>\n<p><a href=\"https://trends.builtwith.com/javascript/Google-Hosted-jQuery\">Google Hosted jQuery Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Hosted-jQuery\">Download List of All Websites using Google Hosted jQuery</a></p>\n<p>jQuery hoted at Google.</p>\n<h6>Advertising</h6>\n<p><a href=\"https://trends.builtwith.com/ads\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/ads/Google-Adsense\">Google Adsense</a></h2>\n<p><a href=\"https://trends.builtwith.com/ads/Google-Adsense\">Google Adsense Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Adsense\">Download List of All Websites using Google Adsense</a></p>\n<p>A contextual advertising solution for delivering Google AdWords ads that are relevant to site content pages.</p>\n<p><a href=\"https://trends.builtwith.com/ads/contextual-advertising\">Contextual Advertising</a></p>\n<h5><a href=\"https://trends.builtwith.com/ads/Google-Adsense-Asynchronous\">Google Adsense Asynchronous</a></h5>\n<p><a href=\"https://trends.builtwith.com/ads/Google-Adsense-Asynchronous\">Google Adsense Asynchronous Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Adsense-Asynchronous\">Download List of All Websites using Google Adsense Asynchronous</a></p>\n<p>Fully asynchronous version of the AdSense ad code.</p>\n<h6>Document Encoding</h6>\n<p><a href=\"https://trends.builtwith.com/encoding\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/encoding/UTF-8\">UTF-8</a></h2>\n<p><a href=\"https://trends.builtwith.com/encoding/UTF-8\">UTF-8 Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/UTF-8\">Download List of All Websites using UTF-8</a></p>\n<p>UTF-8 (8-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode. It is the preferred encoding for web pages.</p>\n<h6>Document Standards</h6>\n<p><a href=\"https://trends.builtwith.com/docinfo\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/HTML5-DocType\">HTML5 DocType</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/HTML5-DocType\">HTML5 DocType Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/HTML5-DocType\">Download List of All Websites using HTML5 DocType</a></p>\n<p>The DOCTYPE is a required preamble for HTML5 websites.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/Cascading-Style-Sheets\">Cascading Style Sheets</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/Cascading-Style-Sheets\">Cascading Style Sheets Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Cascading-Style-Sheets\">Download List of All Websites using Cascading Style Sheets</a></p>\n<p>Cascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in a markup language. Its most common application is to style web pages written in HTML</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/Open-Graph-Protocol\">Open Graph Protocol</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/Open-Graph-Protocol\">Open Graph Protocol Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Open-Graph-Protocol\">Download List of All Websites using Open Graph Protocol</a></p>\n<p>The Open Graph protocol enables any web page to become a rich object in a social graph, a open protocol supported by Facebook</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/Twitter-Cards\">Twitter Cards</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/Twitter-Cards\">Twitter Cards Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Twitter-Cards\">Download List of All Websites using Twitter Cards</a></p>\n<p>Twitter cards make it possible for you to attach media experiences to Tweets that link to your content.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/Javascript\">Javascript</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/Javascript\">Javascript Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Javascript\">Download List of All Websites using Javascript</a></p>\n<p>JavaScript is a scripting language most often used for client-side web development.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/IFrame\">IFrame</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/IFrame\">IFrame Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/IFrame\">Download List of All Websites using IFrame</a></p>\n<p>The page shows content with an iframe; an embedded frame that loads another webpage.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/Font-Face-Rule\">Font Face Rule</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/Font-Face-Rule\">Font Face Rule Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Font-Face-Rule\">Download List of All Websites using Font Face Rule</a></p>\n<p>The @font-face rule allows for linking to fonts that are automatically activated when needed.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/X-UA-Compatible\">X-UA-Compatible</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/X-UA-Compatible\">X-UA-Compatible Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/X-UA-Compatible\">Download List of All Websites using X-UA-Compatible</a></p>\n<p>Allows a website to define how a page is rendered in Internet Explorer 8, allowing a website to decide to use IE7 style rendering over IE8 rendering.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/Meta-Keywords\">Meta Keywords</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/Meta-Keywords\">Meta Keywords Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Meta-Keywords\">Download List of All Websites using Meta Keywords</a></p>\n<p>Meta tag containing keywords related to the page.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/Meta-Description\">Meta Description</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/Meta-Description\">Meta Description Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Meta-Description\">Download List of All Websites using Meta Description</a></p>\n<p>The description attribute provides a concise explanation of the page content.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/HTML-5-Specific-Tags\">HTML 5 Specific Tags</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/HTML-5-Specific-Tags\">HTML 5 Specific Tags Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/HTML-5-Specific-Tags\">Download List of All Websites using HTML 5 Specific Tags</a></p>\n<p>This page contains tags that are specific to an HTML 5 implementation.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/WAI-ARIA\">WAI-ARIA</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/WAI-ARIA\">WAI-ARIA Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/WAI-ARIA\">Download List of All Websites using WAI-ARIA</a></p>\n<p>A way to make Web content and Web applications more accessible to people with disabilities. It especially helps with dynamic content and advanced user interface controls developed with Ajax, HTML, JavaScript, and related technologies.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/Strict-Transport-Security\">Strict Transport Security</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/Strict-Transport-Security\">Strict Transport Security Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Strict-Transport-Security\">Download List of All Websites using Strict Transport Security</a></p>\n<p>The HTTP Strict-Transport-Security (HSTS) header instructs the browser to only use https.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/HSTS\">HSTS</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/HSTS\">HSTS Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/HSTS\">Download List of All Websites using HSTS</a></p>\n<p>Forces browsers to only communicate with the site using HTTPS.</p>\n<h2><a href=\"https://trends.builtwith.com/docinfo/HSTS-IncludeSubdomains-PreLoad\">HSTS IncludeSubdomains PreLoad</a></h2>\n<p><a href=\"https://trends.builtwith.com/docinfo/HSTS-IncludeSubdomains-PreLoad\">HSTS IncludeSubdomains PreLoad Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/HSTS-IncludeSubdomains-PreLoad\">Download List of All Websites using HSTS IncludeSubdomains PreLoad</a></p>\n<p>This website includes instructions for HSTS loading that would allow it to be submitted to the HSTS preload list.</p>\n<h6>Web Master Registration</h6>\n<p><a href=\"https://trends.builtwith.com/web-master\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/Web-Master/Google-Webmaster\">Google Webmaster</a></h2>\n<p><a href=\"https://trends.builtwith.com/Web-Master/Google-Webmaster\">Google Webmaster Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Google-Webmaster\">Download List of All Websites using Google Webmaster</a></p>\n<p>Webmaster tools provide you with a free and easy way to make your site more Google-friendly.</p>\n<h6>Content Delivery Network</h6>\n<p><a href=\"https://trends.builtwith.com/cdn\">View Global Trends</a></p>\n<h2><a href=\"https://trends.builtwith.com/CDN/Content-Delivery-Network\">Content Delivery Network</a></h2>\n<p><a href=\"https://trends.builtwith.com/CDN/Content-Delivery-Network\">Content Delivery Network Usage Statistics</a> - <a href=\"https://trends.builtwith.com/websitelist/Content-Delivery-Network\">Download List of All Websites using Content Delivery Network</a></p>\n<p>This page contains links that give the impression that some of the site contents are stored on a content delivery network.</p>\n<h2>Docs Structure</h2>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.\n\n├── ./About\n\n│   ├── ./About/index.md\n\n│   ├── ./About/introduction2bg.md\n\n│   ├── ./About/me.md\n\n│   └── ./About/resume.md\n\n├── ./articles\n\n│   ├── ./articles/algo.md\n\n│   └── ./articles/basic-web-dev.md\n\n├── ./faq\n\n│   ├── ./faq/Contact.md\n\n│   ├── ./faq/index.md\n\n│   └── ./faq/other-sites.md\n\n├── ./index.md\n\n├── ./jupyter-notebooks.md\n\n├── ./links\n\n│   ├── ./links/Social.md\n\n│   ├── ./links/index.md\n\n│   └── ./links/my-websites.md\n\n├── ./portfolio-web.md\n\n├── ./python.md\n\n├── ./quick-reference\n\n│   ├── ./quick-reference/Emmet.md\n\n│   ├── ./quick-reference/index.md\n\n│   ├── ./quick-reference/installation.md\n\n│   └── ./quick-reference/new-repo-instructions.md\n\n├── ./react\n\n│   ├── ./react/createReactApp.md\n\n│   ├── ./react/index.md\n\n│   └── ./react/react2.md\n\n├── ./resources.md\n\n└── ./tools\n\n    ├── ./tools/Git-Html-Preview.md\n\n    ├── ./tools/default-readme.md\n\n    ├── ./tools/index.md\n\n    ├── ./tools/notes-template.md\n\n    └── ./tools/plug-ins.md\n\n7 directories, 29 files</code></pre></div>\n<hr>\n<h1>Sitemap</h1>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/job-hunt/\">/job-hunt/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/notes-template/\">/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/\">/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/showcase/\">/showcase/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/\">/blog/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/review/\">/review/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blog-archive/\">/blog/blog-archive/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/my-medium/\">/blog/my-medium/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blogwcomments/\">/blog/blogwcomments/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures/\">/blog/data-structures/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/gallery/\">/docs/gallery/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-for-js-dev/\">/blog/python-for-js-dev/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/platform-docs/\">/blog/platform-docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/sitemap/\">/docs/sitemap/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/me/\">/docs/about/me/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-resources/\">/blog/python-resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/resume/\">/docs/about/resume/</a></li>\n<li><a href=\"https://preview--bgoonz-b2d7c.stackbit.https://bgoonz-blog.netlify.app/log/web-scraping/\">/docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/\">/docs/about/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/algo/\">/docs/articles/algo/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/install/\">/docs/articles/install/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/\">/docs/articles/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/gallery/\">/docs/articles/gallery/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/intro/\">/docs/articles/intro/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev/\">/docs/articles/basic-web-dev/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/reading-files/\">/docs/articles/reading-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/writing-files/\">/docs/articles/writing-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/audio/\">/docs/audio/audio/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/projects/\">/docs/content/projects/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/terms/\">/docs/audio/terms/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/\">/docs/faq/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/\">/docs/community/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/resources/\">/docs/articles/resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/\">/docs/content/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-repos/\">/docs/docs/git-repos/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/trouble-shooting/\">/docs/content/trouble-shooting/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/python/\">/docs/articles/python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/clock/\">/docs/interact/clock/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/python/\">/docs/docs/python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/jupyter-notebooks/\">/docs/interact/jupyter-notebooks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/\">/docs/interact/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/contact/\">/docs/faq/contact/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/docs/\">/docs/quick-reference/docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites/\">/docs/interact/other-sites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/new-repo-instructions/\">/docs/quick-reference/new-repo-instructions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/Emmet/\">/docs/quick-reference/Emmet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/installation/\">/docs/quick-reference/installation/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/vscode-themes/\">/docs/quick-reference/vscode-themes/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/createReactApp/\">/docs/react/createReactApp/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2/\">/docs/react/react2/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/\">/docs/quick-reference/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/\">/docs/react/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/\">/docs/tools/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/notes-template/\">/docs/tools/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/more-tools/\">/docs/tools/more-tools/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/plug-ins/\">/docs/tools/plug-ins/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/install/\">/docs/articles/node/install/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/vscode/\">/docs/tools/vscode/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/intro/\">/docs/articles/node/intro/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/nodejs/\">/docs/articles/node/nodejs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/nodevsbrowser/\">/docs/articles/node/nodevsbrowser/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/npm/\">/docs/articles/node/npm/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/reading-files/\">/docs/articles/node/reading-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node/writing-files/\">/docs/articles/node/writing-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react-in-depth/\">/docs/react-in-depth/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/article-compilation/\">/docs/articles/article-compilation/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/my-websites/\">/docs/medium/my-websites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/social/\">/docs/medium/social/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/medium-links/\">/docs/medium/medium-links/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/\">/docs/medium/</a></li>\n</ul>\n<h1>Sitemap</h1>\n<hr>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/big-o-complexity/\">/blog/big-o-complexity/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/showcase/\">/showcase/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blog-archive/\">/blog/blog-archive/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/\">/blog/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/review/\">/review/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures/\">/blog/data-structures/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/blogwcomments/\">/blog/blogwcomments/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/platform-docs/\">/blog/platform-docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-resources/\">/blog/python-resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python-for-js-dev/\">/blog/python-for-js-dev/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/gallery/\">/docs/gallery/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/my-medium/\">/blog/my-medium/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/search/\">/docs/search/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/eng-portfolio/\">/docs/about/eng-portfolio/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/intrests/\">/docs/about/intrests/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/sitemap/\">/docs/sitemap/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/resume/\">/docs/about/resume/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/web-scraping/\">/blog/web-scraping/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/job-search/\">/docs/about/job-search/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/\">/docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/buffers/\">/docs/articles/buffers/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/\">/docs/about/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/event-loop/\">/docs/articles/event-loop/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/dev-dep/\">/docs/articles/dev-dep/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/\">/docs/articles/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/install/\">/docs/articles/install/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/fs-module/\">/docs/articles/fs-module/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-cli-args/\">/docs/articles/node-cli-args/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/module-exports/\">/docs/articles/module-exports/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-env-variables/\">/docs/articles/node-env-variables/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/intro/\">/docs/articles/intro/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-js-language/\">/docs/articles/node-js-language/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev/\">/docs/articles/basic-web-dev/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-repl/\">/docs/articles/node-repl/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-package-manager/\">/docs/articles/node-package-manager/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/node-run-cli/\">/docs/articles/node-run-cli/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/npx/\">/docs/articles/npx/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/v8/\">/docs/articles/v8/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nodevsbrowser/\">/docs/articles/nodevsbrowser/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/reading-files/\">/docs/articles/reading-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/nodejs/\">/docs/articles/nodejs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/npm/\">/docs/articles/npm/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/semantic/\">/docs/articles/semantic/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/writing-files/\">/docs/articles/writing-files/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dynamic-time-warping/\">/docs/audio/dynamic-time-warping/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/\">/docs/audio/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/terms/\">/docs/audio/terms/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/os-module/\">/docs/articles/os-module/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/\">/docs/community/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/community/video-chat/\">/docs/community/video-chat/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/archive/\">/docs/content/archive/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/data-structures-algo/\">/docs/content/data-structures-algo/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/\">/docs/content/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/notes-template/\">/docs/content/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/gatsby-Queries-Mutations/\">/docs/content/gatsby-Queries-Mutations/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/projects/\">/docs/content/projects/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/trouble-shooting/\">/docs/content/trouble-shooting/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/audio/dfft/\">/docs/audio/dfft/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/content/algo/\">/docs/content/algo/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/await-keyword/\">/docs/docs/await-keyword/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/appendix/\">/docs/docs/appendix/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/algolia/\">/docs/docs/algolia/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/data-structures-docs/\">/docs/docs/data-structures-docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/\">/docs/docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/git-repos/\">/docs/docs/git-repos/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/sitemap/\">/docs/docs/sitemap/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/css/\">/docs/docs/css/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/docs/regex-in-js/\">/docs/docs/regex-in-js/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/contact/\">/docs/faq/contact/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/jupyter-notebooks/\">/docs/interact/jupyter-notebooks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/clock/\">/docs/interact/clock/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/\">/docs/interact/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/\">/docs/faq/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/video-chat/\">/docs/interact/video-chat/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/interact/other-sites/\">/docs/interact/other-sites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/plug-ins/\">/docs/faq/plug-ins/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/my-websites/\">/docs/medium/my-websites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/medium-links/\">/docs/medium/medium-links/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/medium/\">/docs/medium/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/create-react-app/\">/docs/quick-reference/create-react-app/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/javascript/constructor-functions/\">/docs/javascript/constructor-functions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/Emmet/\">/docs/quick-reference/Emmet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/\">/docs/python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/awesome-static/\">/docs/quick-reference/awesome-static/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/\">/docs/quick-reference/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/new-repo-instructions/\">/docs/quick-reference/new-repo-instructions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/installation/\">/docs/quick-reference/installation/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/google-firebase/\">/docs/quick-reference/google-firebase/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/notes-template/\">/docs/quick-reference/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/heroku-error-codes/\">/docs/quick-reference/heroku-error-codes/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/psql-setup/\">/docs/quick-reference/psql-setup/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/createReactApp/\">/docs/react/createReactApp/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/topRepos/\">/docs/quick-reference/topRepos/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2/\">/docs/react/react2/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/resources/\">/docs/quick-reference/resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/vscode/\">/docs/quick-reference/vscode/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/dev-utilities/\">/docs/tools/dev-utilities/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/data-structures/\">/docs/tools/data-structures/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/markdown-html/\">/docs/tools/markdown-html/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/psql/\">/docs/quick-reference/psql/</a></li>\n</ul>\n<hr>\n<h3>Links</h3>\n<h5>Try it out without cloning the entire repo</h5>\n<h5><a href=\"https://exploring-firebase-4c023.firebaseapp.com/\">stackblitz demo hosted on firebase</a></h5>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/showcase/\">/showcase/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/repos/\">/repos/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/\">/blog/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/jupyter-notebooks/\">/docs/jupyter-notebooks/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/portfolio-web/\">/docs/portfolio-web/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/python/\">/docs/python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/About/\">/docs/About/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/About/resume/\">/docs/About/resume/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/about/\">/docs/about/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/faq/\">/docs/faq/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/\">/docs/quick-reference/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/Emmet/\">/docs/quick-reference/Emmet/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/new-repo-instructions/\">/docs/quick-reference/new-repo-instructions/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/links/Social/\">/docs/links/Social/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/links/\">/docs/links/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/quick-reference/installation/\">/docs/quick-reference/installation/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/links/my-websites/\">/docs/links/my-websites/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/\">/docs/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/community/\">/blog/community/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/python/\">/blog/python/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/resources/\">/docs/resources/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/createReactApp/\">/docs/react/createReactApp/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/\">/docs/tools/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/notes-template/\">/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/my-medium/\">/blog/my-medium/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/default-readme/\">/docs/tools/default-readme/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/plug-ins/\">/docs/tools/plug-ins/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2/\">/docs/react/react2/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/notes-template/\">/docs/tools/notes-template/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/review/\">/review/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/articles/basic-web-dev/\">/docs/articles/basic-web-dev/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/blog/data-structures/\">/blog/data-structures/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/About/me/\">/docs/About/me/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/About/introduction2bg/\">/docs/About/introduction2bg/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/\">/docs/react/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/tools/Git-Html-Preview/\">/docs/tools/Git-Html-Preview/</a></li>\n<li><a href=\"https://bgoonz-blog.netlify.app/gallery/\">/gallery/</a></li>\n</ul>\n<h2>Blog</h2>\n<ul>\n<li><a href=\"https://bgoonz-blog.netlify.app/docs/react/react2/?source=your_stories_page-------------------------------------\">introductory-react-part-2</a></li>\n<li><a href=\"https://bryanguner.medium.com/a-very-quick-guide-to-calculating-big-o-computational-complexity-eb1557e85fa3?source=your_stories_page-------------------------------------\">a-very-quick-guide-to-calculating-big-o-computational-complexity</a></li>\n<li><a href=\"https://javascript.plainenglish.io/introduction-to-react-for-complete-beginners-8021738aa1ad?source=your_stories_page-------------------------------------\">introduction-to-react-for-complete-beginners</a></li>\n<li><a href=\"https://javascript.plainenglish.io/scheduling-settimeout-and-setinterval-fcb2f40d16f7?source=your_stories_page-------------------------------------\">scheduling-settimeout-and-setinterval</a></li>\n<li><a href=\"https://bryanguner.medium.com/css-animations-d196a20099a5?source=your_stories_page-------------------------------------\">css-animations</a></li>\n<li><a href=\"https://bryanguner.medium.com/these-are-the-bash-shell-commands-that-stand-between-me-and-insanity-984865ba5d1b?source=your_stories_page-------------------------------------\">these-are-the-bash-shell-commands-that-stand-between-me-and-insanity</a></li>\n<li><a href=\"https://bryanguner.medium.com/how-to-implement-native-es6-data-structures-using-arrays-objects-ce953b9f6a07?source=your_stories_page-------------------------------------\">how-to-implement-native-es6-data-structures-using-arrays-objects</a></li>\n<li><a href=\"https://medium.com/codex/objects-in-javascript-cc578a781e1d?source=your_stories_page-------------------------------------\">objects-in-javascript</a></li>\n<li><a href=\"https://javascript.plainenglish.io/absolute-beginners-guide-to-javascript-part-1-e222d166b6e1?source=your_stories_page-------------------------------------\">absolute-beginners-guide-to-javascript-part1</a></li>\n<li><a href=\"https://medium.com/star-gazers/web-developer-resource-list-part-4-fd686892b9eb?source=your_stories_page-------------------------------------\">web-developer-resource-list-part-4</a></li>\n<li><a href=\"https://medium.com/codex/vscode-extensions-specifically-for-javascript-development-ea91305cbd4a?source=your_stories_page-------------------------------------\">vscode-extensions-specifically-for-javascript-development</a></li>\n<li><a href=\"https://bryanguner.medium.com/a-list-of-all-of-my-articles-to-link-to-future-posts-1f6f88ebdf5b?source=your_stories_page-------------------------------------\">a-list-of-all-of-my-articles-to-link-to-future-posts</a></li>\n<li><a href=\"https://javascript.plainenglish.io/lists-stacks-and-queues-in-javascript-88466fae0fbb?source=your_stories_page-------------------------------------\">lists-stacks-and-queues-in-javascript</a></li>\n<li><a href=\"https://bryanguner.medium.com/web-development-resources-part-3-f862ceb2b82a?source=your_stories_page-------------------------------------\">web-development-resources-part-3</a></li>\n<li><a href=\"https://medium.com/codex/web-development-interview-part-3-826ae81a9107?source=your_stories_page-------------------------------------\">web-development-interview-part-3</a></li>\n<li><a href=\"https://bryanguner.medium.com/running-list-of-interesting-articles-tools-and-ideas-as-i-explore-them-b87a2f04d9a6?source=your_stories_page-------------------------------------\">running-list-of-interesting-articles-tools</a></li>\n<li><a href=\"https://bryanguner.medium.com/the-best-cloud-based-code-playgrounds-of-2021-part-1-cdae9448db24?source=your_stories_page-------------------------------------\">the-best-cloud-based-code-playgrounds-of-2021-part-1</a></li>\n<li><a href=\"https://medium.com/codex/front-end-interview-questions-part-2-86ddc0e91443?source=your_stories_page-------------------------------------\">front-end-interview-questions-part-2</a></li>\n<li><a href=\"https://medium.com/star-gazers/web-developer-resource-list-part-2-9c5cb56ab263?source=your_stories_page-------------------------------------\">web-developer-resource-list-part-2</a></li>\n<li><a href=\"https://levelup.gitconnected.com/http-basics-8f02a96a834a?source=your_stories_page-------------------------------------\">http-basics</a></li>\n<li><a href=\"https://javascript.plainenglish.io/javascript-frameworks-libraries-35931e187a35?source=your_stories_page-------------------------------------\">javascript-frameworks-libraries</a></li>\n<li><a href=\"https://javascript.plainenglish.io/my-take-on-awesome-javascript-243255451e74?source=your_stories_page-------------------------------------\">my-take-on-awesome-javascript</a></li>\n<li><a href=\"https://levelup.gitconnected.com/everything-you-need-to-get-started-with-vscode-extensions-resources-b9f4c8d91931?source=your_stories_page-------------------------------------\">get-started-with-vscode-extensions</a></li>\n<li><a href=\"https://levelup.gitconnected.com/my-favorite-vscode-themes-9bab65af3f0f?source=your_stories_page-------------------------------------\">my-favorite-vscode-themes</a></li>\n<li><a href=\"https://levelup.gitconnected.com/object-oriented-programming-in-javascript-d45007d06333?source=your_stories_page-------------------------------------\">object-oriented-programming-in-javascript</a></li>\n<li><a href=\"https://medium.com/codex/javascript-rotate-array-problemwalkthrough-31deb19ebba1?source=your_stories_page-------------------------------------\">javascript-rotate-array-problemwalkthrough</a></li>\n<li><a href=\"https://levelup.gitconnected.com/super-simple-intro-to-html-651d695f9bc?source=your_stories_page-------------------------------------\">super-simple-intro-to-html-651d695f9bc</a></li>\n<li><a href=\"https://medium.com/codex/everything-you-need-to-know-about-relational-databases-sql-postgresql-and-sequelize-to-build-8acb68284a98?source=your_stories_page-------------------------------------\">everything-you-need-to-know-about-relational-databases-sql-postgresql</a></li>\n<li><a href=\"https://levelup.gitconnected.com/understanding-git-a-beginners-guide-containing-cheat-sheets-resources-b50c9c01a107?source=your_stories_page-------------------------------------\">understanding-git-a-beginners-guide-containing-cheat-sheets-resources-b50c9c01a107</a></li>\n<li><a href=\"https://javascript.plainenglish.io/complete-javascript-reference-guide-64306cd6b0db?source=your_stories_page-------------------------------------\">complete-javascript-reference-guide-64306cd6b0db</a>- [</li>\n</ul>\n</div>\n<hr>\n<hr>\n<h2>🚀 Quick start</h2>\n<ol>\n<li>\n<p><strong>Create a Gatsby site.</strong></p>\n<p>Use the Gatsby CLI to create a new site, specifying the default starter.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token comment\"># create a new Gatsby site using the default starter</span>\n\ngatsby new my-default-starter https://github.com/gatsbyjs/gatsby-starter-default</code></pre></div>\n</li>\n<li>\n<p><strong>Start developing.</strong></p>\n<p>Navigate into your new site's directory and start it up.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\"><span class=\"token builtin class-name\">cd</span> my-default-starter/\n\ngatsby develop</code></pre></div>\n</li>\n<li>\n<p><strong>Open the source code and start editing!</strong></p>\n<p>Your site is now running at <code class=\"language-text\">http://localhost:8000</code>!</p>\n<p><em>Note: You'll also see a second link:</em><code class=\"language-text\">http://localhost:8000/___graphql</code><em>. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the <a href=\"https://www.gatsbyjs.com/tutorial/part-five/#introducing-graphiql\">Gatsby tutorial</a>.</em></p>\n<p>Open the <code class=\"language-text\">my-default-starter</code> directory in your code editor of choice and edit <code class=\"language-text\">src/pages/index.js</code>. Save your changes and the browser will update in real time!</p>\n</li>\n</ol>\n<h2>🧐 What's inside?</h2>\n<p>A quick look at the top-level files and directories you'll see in a Gatsby project.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">.\n\n├── node_modules\n\n├── src\n\n├── .gitignore\n\n├── .prettierrc\n\n├── gatsby-browser.js\n\n├── gatsby-config.js\n\n├── gatsby-node.js\n\n├── gatsby-ssr.js\n\n├── LICENSE\n\n├── package-lock.json\n\n├── package.json\n\n└── README.md</code></pre></div>\n<ol>\n<li><strong><code class=\"language-text\">/node_modules</code></strong>: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed.</li>\n<li><strong><code class=\"language-text\">/src</code></strong>: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template. <code class=\"language-text\">src</code> is a convention for \"source code\".</li>\n<li><strong><code class=\"language-text\">.gitignore</code></strong>: This file tells git which files it should not track / not maintain a version history for.</li>\n<li><strong><code class=\"language-text\">.prettierrc</code></strong>: This is a configuration file for <a href=\"https://prettier.io/\">Prettier</a>. Prettier is a tool to help keep the formatting of your code consistent.</li>\n<li><strong><code class=\"language-text\">gatsby-browser.js</code></strong>: This file is where Gatsby expects to find any usage of the <a href=\"https://www.gatsbyjs.com/docs/browser-apis/\">Gatsby browser APIs</a> (if any). These allow customization/extension of default Gatsby settings affecting the browser.</li>\n<li><strong><code class=\"language-text\">gatsby-config.js</code></strong>: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you'd like to include, etc. (Check out the <a href=\"https://www.gatsbyjs.com/docs/gatsby-config/\">config docs</a> for more detail).</li>\n<li><strong><code class=\"language-text\">gatsby-node.js</code></strong>: This file is where Gatsby expects to find any usage of the <a href=\"https://www.gatsbyjs.com/docs/node-apis/\">Gatsby Node APIs</a> (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.</li>\n<li><strong><code class=\"language-text\">gatsby-ssr.js</code></strong>: This file is where Gatsby expects to find any usage of the <a href=\"https://www.gatsbyjs.com/docs/ssr-apis/\">Gatsby server-side rendering APIs</a> (if any). These allow customization of default Gatsby settings affecting server-side rendering.</li>\n<li><strong><code class=\"language-text\">LICENSE</code></strong>: This Gatsby starter is licensed under the 0BSD license. This means that you can see this file as a placeholder and replace it with your own license.</li>\n<li><strong><code class=\"language-text\">package-lock.json</code></strong> (See <code class=\"language-text\">package.json</code> below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. <strong>(You won't change this file directly).</strong></li>\n<li><strong><code class=\"language-text\">package.json</code></strong>: A manifest file for Node.js projects, which includes things like metadata (the project's name, author, etc). This manifest is how npm knows which packages to install for your project.</li>\n<li><strong><code class=\"language-text\">README.md</code></strong>: A text file containing useful reference information about your project.</li>\n</ol>\n<h2>🎓 Learning Gatsby</h2>\n<p>Looking for more guidance? Full documentation for Gatsby lives <a href=\"https://www.gatsbyjs.com/\">on the website</a>. Here are some places to start:</p>\n<ul>\n<li><strong>For most developers, we recommend starting with our <a href=\"https://www.gatsbyjs.com/tutorial/\">in-depth tutorial for creating a site with Gatsby</a>.</strong> It starts with zero assumptions about your level of ability and walks through every step of the process.</li>\n<li><strong>To dive straight into code samples, head <a href=\"https://www.gatsbyjs.com/docs/\">to our documentation</a>.</strong> In particular, check out the <em>Guides</em>, <em>API Reference</em>, and <em>Advanced Tutorials</em> sections in the sidebar.</li>\n</ul>\n<h2>💫 Deploy</h2>\n<p><a href=\"https://app.netlify.com/start/deploy?repository=https://github.com/BGOONZ_BLOG_2.0.git\"><img src=\"https://www.netlify.com/img/deploy/button.svg\" alt=\"Deploy to Netlify\"></a></p>\n<p><a href=\"https://vercel.com/import/project?template=https://github.com/BGOONZ_BLOG_2.0.git\"><img src=\"https://vercel.com/button\" alt=\"Deploy with Vercel\"></a></p>\n<!-- AUTO-GENERATED-CONTENT:END -->\n<hr>\n<hr>\n<h1>Codebase</h1>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">bryan@LAPTOP-9LGJ3JGS:/c/MY-WEB-DEV/BLOG____2.0/BLOG_2.0/src$ tree -f\n\n.\n\n├── ./components\n\n│   ├── ./components/ActionLink.js\n\n│   ├── ./components/CtaButtons.js\n\n│   ├── ./components/DocsMenu.js\n\n│   ├── ./components/DocsSubmenu.js\n\n│   ├── ./components/Footer.js\n\n│   ├── ./components/Header.js\n\n│   ├── ./components/Icon.js\n\n│   ├── ./components/Layout.js\n\n│   ├── ./components/SectionContent.js\n\n│   ├── ./components/SectionCta.js\n\n│   ├── ./components/SectionDocs.js\n\n│   ├── ./components/SectionGrid.js\n\n│   ├── ./components/SectionHero.js\n\n│   ├── ./components/Submenu.js\n\n│   ├── ./components/global.css\n\n│   └── ./components/index.js\n\n├── ./data\n\n│   └── ./data/doc_sections.yml\n\n├── ./hooks\n\n│   └── ./hooks/useScript.js\n\n├── ./html.js\n\n├── ./pages\n\n│   ├── ./pages/blog\n\n│   │   ├── ./pages/blog/blog-archive.md\n\n│   │   ├── ./pages/blog/blogwcomments.md\n\n│   │   ├── ./pages/blog/data-structures.md\n\n│   │   ├── ./pages/blog/index.md\n\n│   │   ├── ./pages/blog/my-medium.md\n\n│   │   ├── ./pages/blog/platform-docs.md\n\n│   │   ├── ./pages/blog/python-for-js-dev.md\n\n│   │   ├── ./pages/blog/python-resources.md\n\n│   │   └── ./pages/blog/web-scraping.md\n\n│   ├── ./pages/docs\n\n│   │   ├── ./pages/docs/about\n\n│   │   │   ├── ./pages/docs/about/index.md\n\n│   │   │   ├── ./pages/docs/about/me.md\n\n│   │   │   ├── ./pages/docs/about/node\n\n│   │   │   │   ├── ./pages/docs/about/node/install.md\n\n│   │   │   │   ├── ./pages/docs/about/node/intro.md\n\n│   │   │   │   ├── ./pages/docs/about/node/nodejs.md\n\n│   │   │   │   ├── ./pages/docs/about/node/nodevsbrowser.md\n\n│   │   │   │   ├── ./pages/docs/about/node/reading-files.md\n\n│   │   │   │   └── ./pages/docs/about/node/writing-files.md\n\n│   │   │   ├── ./pages/docs/about/npm.md\n\n│   │   │   └── ./pages/docs/about/resume.md\n\n│   │   ├── ./pages/docs/articles\n\n│   │   │   ├── ./pages/docs/articles/algo.md\n\n│   │   │   ├── ./pages/docs/articles/article-compilation.md\n\n│   │   │   ├── ./pages/docs/articles/basic-web-dev.md\n\n│   │   │   ├── ./pages/docs/articles/gists.md\n\n│   │   │   ├── ./pages/docs/articles/index.md\n\n│   │   │   ├── ./pages/docs/articles/install.md\n\n│   │   │   ├── ./pages/docs/articles/intro.md\n\n│   │   │   ├── ./pages/docs/articles/python.md\n\n│   │   │   ├── ./pages/docs/articles/reading-files.md\n\n│   │   │   ├── ./pages/docs/articles/resources.md\n\n│   │   │   ├── ./pages/docs/articles/ten-jamstack-apis-to-checkout.md\n\n│   │   │   └── ./pages/docs/articles/writing-files.md\n\n│   │   ├── ./pages/docs/docs\n\n│   │   │   └── ./pages/docs/docs/tools\n\n│   │   │       └── ./pages/docs/docs/tools/file-types.md\n\n│   │   ├── ./pages/docs/faq\n\n│   │   │   ├── ./pages/docs/faq/contact.md\n\n│   │   │   └── ./pages/docs/faq/index.md\n\n│   │   ├── ./pages/docs/gists.md\n\n│   │   ├── ./pages/docs/index.md\n\n│   │   ├── ./pages/docs/interact\n\n│   │   │   ├── ./pages/docs/interact/clock.md\n\n│   │   │   ├── ./pages/docs/interact/index.md\n\n│   │   │   └── ./pages/docs/interact/jupyter-notebooks.md\n\n│   │   ├── ./pages/docs/links\n\n│   │   │   ├── ./pages/docs/links/index.md\n\n│   │   │   ├── ./pages/docs/links/medium-links.md\n\n│   │   │   ├── ./pages/docs/links/my-websites.md\n\n│   │   │   └── ./pages/docs/links/social.md\n\n│   │   ├── ./pages/docs/quick-reference\n\n│   │   │   ├── ./pages/docs/quick-reference/Emmet.md\n\n│   │   │   ├── ./pages/docs/quick-reference/docs.md\n\n│   │   │   ├── ./pages/docs/quick-reference/index.md\n\n│   │   │   ├── ./pages/docs/quick-reference/installation.md\n\n│   │   │   └── ./pages/docs/quick-reference/new-repo-instructions.md\n\n│   │   ├── ./pages/docs/react\n\n│   │   │   ├── ./pages/docs/react/createReactApp.md\n\n│   │   │   ├── ./pages/docs/react/index.md\n\n│   │   │   └── ./pages/docs/react/react2.md\n\n│   │   ├── ./pages/docs/react-in-depth.md\n\n│   │   ├── ./pages/docs/sitemap.md\n\n│   │   └── ./pages/docs/tools\n\n│   │       ├── ./pages/docs/tools/index.md\n\n│   │       ├── ./pages/docs/tools/notes-template.md\n\n│   │       ├── ./pages/docs/tools/plug-ins.md\n\n│   │       └── ./pages/docs/tools/vscode.md\n\n│   ├── ./pages/index.md\n\n│   ├── ./pages/notes-template.md\n\n│   ├── ./pages/review.md\n\n│   └── ./pages/showcase.md\n\n├── ./sass\n\n│   ├── ./sass/imports\n\n│   │   ├── ./sass/imports/_animations.scss\n\n│   │   ├── ./sass/imports/_buttons.scss\n\n│   │   ├── ./sass/imports/_docs.scss\n\n│   │   ├── ./sass/imports/_footer.scss\n\n│   │   ├── ./sass/imports/_forms.scss\n\n│   │   ├── ./sass/imports/_functions.scss\n\n│   │   ├── ./sass/imports/_general.scss\n\n│   │   ├── ./sass/imports/_header.scss\n\n│   │   ├── ./sass/imports/_helpers.scss\n\n│   │   ├── ./sass/imports/_icons.scss\n\n│   │   ├── ./sass/imports/_palettes.scss\n\n│   │   ├── ./sass/imports/_posts.scss\n\n│   │   ├── ./sass/imports/_prism.scss\n\n│   │   ├── ./sass/imports/_reset.scss\n\n│   │   ├── ./sass/imports/_sections.scss\n\n│   │   ├── ./sass/imports/_structure.scss\n\n│   │   ├── ./sass/imports/_tables.scss\n\n│   │   └── ./sass/imports/_variables.scss\n\n│   └── ./sass/main.scss\n\n├── ./templates\n\n│   ├── ./templates/advanced.js\n\n│   ├── ./templates/blog.js\n\n│   ├── ./templates/docs.js\n\n│   ├── ./templates/page.js\n\n│   └── ./templates/post.js\n\n└── ./utils\n\n    ├── ./utils/attribute.js\n\n    ├── ./utils/classNames.js\n\n    ├── ./utils/cycler.js\n\n    ├── ./utils/getData.js\n\n    ├── ./utils/getPage.js\n\n    ├── ./utils/getPageByFilePath.js\n\n    ├── ./utils/getPages.js\n\n    ├── ./utils/htmlToReact.js\n\n    ├── ./utils/index.js\n\n    ├── ./utils/link.js\n\n    ├── ./utils/markdownify.js\n\n    ├── ./utils/pathJoin.js\n\n    ├── ./utils/toStyleObj.js\n\n    ├── ./utils/toUrl.js\n\n    └── ./utils/withPrefix.js\n\n21 directories, 119 files\n\nbryan@LAPTOP-9LGJ3JGS:/c/MY-WEB-DEV/BLOG____2.0/BLOG_2.0/src$</code></pre></div>\n<hr>\n<h1>Components</h1>\n<details>\n  <summary>\n<h1>Click to see React Components (src folder)!</h1>\n</summary>\n<details>\n  <summary>ActionLink!</summary>\n<h2>ActionLink</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> Link<span class=\"token punctuation\">,</span> withPrefix<span class=\"token punctuation\">,</span> classNames <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Icon <span class=\"token keyword\">from</span> <span class=\"token string\">'./Icon'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">ActionLink</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">let</span> action <span class=\"token operator\">=</span> \\_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'action'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token operator\">&lt;</span>Link\n\nto<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'new_window'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token string\">'\\_blank'</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'new*window'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token operator\">*</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'no*follow'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">?</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">rel</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">*</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'new*window'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token string\">'noopener '</span> <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">*</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'no*follow'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token string\">'nofollow'</span> <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\nclassName<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">button</span><span class=\"token operator\">:</span> <span class=\"token operator\">*</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> <span class=\"token string\">'link'</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'button-secondary'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'secondary'</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'button-icon'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'icon'</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">></span>\n\n<span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'icon'</span> <span class=\"token operator\">&amp;&amp;</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'icon*class'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n\n<span class=\"token operator\">&lt;</span>Icon <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> icon<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token operator\">*</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'icon*class'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n<span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"screen-reader-text\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token operator\">*</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'label'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n\n<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n\n\\_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'label'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>CtaButtons!</summary>\n<h2>CtaButtons</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> Link<span class=\"token punctuation\">,</span> withPrefix<span class=\"token punctuation\">,</span> classNames <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">CtaButtons</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> actions <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>actions<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">action<span class=\"token punctuation\">,</span> action_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>Link\n                key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action_idx<span class=\"token punctuation\">}</span>\n                to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'new_window'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token string\">'_blank'</span> <span class=\"token punctuation\">}</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'new_window'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'no_follow'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                    <span class=\"token operator\">?</span> <span class=\"token punctuation\">{</span>\n                          <span class=\"token literal-property property\">rel</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'new_window'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token string\">'noopener '</span> <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'no_follow'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token string\">'nofollow'</span> <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n                      <span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                    <span class=\"token literal-property property\">button</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'primary'</span> <span class=\"token operator\">||</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'secondary'</span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token string-property property\">'button-secondary'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'secondary'</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'label'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>DocsMenu</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> getPage<span class=\"token punctuation\">,</span> classNames<span class=\"token punctuation\">,</span> Link<span class=\"token punctuation\">,</span> withPrefix<span class=\"token punctuation\">,</span> pathJoin<span class=\"token punctuation\">,</span> getPages <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> DocsSubmenu <span class=\"token keyword\">from</span> <span class=\"token string\">'./DocsSubmenu'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">DocsMenu</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> site <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'site'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> page <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'page'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> root_docs_path <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>site<span class=\"token punctuation\">,</span> <span class=\"token string\">'data.doc_sections.root_docs_path'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> root_page <span class=\"token operator\">=</span> <span class=\"token function\">getPage</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>pageContext<span class=\"token punctuation\">.</span>pages<span class=\"token punctuation\">,</span> root_docs_path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>nav id<span class=\"token operator\">=</span><span class=\"token string\">\"docs-nav\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"docs-nav\"</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div id<span class=\"token operator\">=</span><span class=\"token string\">\"docs-nav-inside\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"docs-nav-inside sticky\"</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>button id<span class=\"token operator\">=</span><span class=\"token string\">\"docs-nav-toggle\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"docs-nav-toggle\"</span><span class=\"token operator\">></span>\n                        Navigate Docs\n                        <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"icon-angle-right\"</span> aria<span class=\"token operator\">-</span>hidden<span class=\"token operator\">=</span><span class=\"token string\">\"true\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"docs-nav-menu\"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>ul id<span class=\"token operator\">=</span><span class=\"token string\">\"docs-menu\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"docs-menu\"</span><span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>li\n                                className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'docs-menu-item'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token literal-property property\">current</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>root_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                            <span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>root_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>root_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'frontmatter.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>site<span class=\"token punctuation\">,</span> <span class=\"token string\">'data.doc_sections.sections'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">section<span class=\"token punctuation\">,</span> section_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">let</span> section_path <span class=\"token operator\">=</span> <span class=\"token function\">pathJoin</span><span class=\"token punctuation\">(</span>root_docs_path<span class=\"token punctuation\">,</span> section<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">let</span> section_page <span class=\"token operator\">=</span> <span class=\"token function\">getPage</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>pageContext<span class=\"token punctuation\">.</span>pages<span class=\"token punctuation\">,</span> section_path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">let</span> child_pages <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">orderBy</span><span class=\"token punctuation\">(</span><span class=\"token function\">getPages</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>pageContext<span class=\"token punctuation\">.</span>pages<span class=\"token punctuation\">,</span> section_path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'frontmatter.weight'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">let</span> child_count <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">size</span><span class=\"token punctuation\">(</span>child_pages<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">let</span> has_children <span class=\"token operator\">=</span> child_count <span class=\"token operator\">></span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> <span class=\"token boolean\">true</span> <span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">let</span> is_current_page <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token boolean\">true</span> <span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">let</span> is_active <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">startsWith</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                                    <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>section_idx <span class=\"token operator\">+</span> <span class=\"token string\">'.1'</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                                        <span class=\"token operator\">&lt;</span>li\n                                            key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>section_idx<span class=\"token punctuation\">}</span>\n                                            className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'docs-menu-item'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                                <span class=\"token string-property property\">'has-children'</span><span class=\"token operator\">:</span> has_children<span class=\"token punctuation\">,</span>\n\n                                                <span class=\"token literal-property property\">current</span><span class=\"token operator\">:</span> is_current_page<span class=\"token punctuation\">,</span>\n\n                                                <span class=\"token literal-property property\">active</span><span class=\"token operator\">:</span> is_active\n                                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                        <span class=\"token operator\">></span>\n                                            <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'frontmatter.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n\n                                            <span class=\"token punctuation\">{</span>has_children <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                                <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                                                    <span class=\"token operator\">&lt;</span>button className<span class=\"token operator\">=</span><span class=\"token string\">\"docs-submenu-toggle\"</span><span class=\"token operator\">></span>\n                                                        <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"screen-reader-text\"</span><span class=\"token operator\">></span>Submenu<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n\n                                                        <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"icon-angle-right\"</span> aria<span class=\"token operator\">-</span>hidden<span class=\"token operator\">=</span><span class=\"token string\">\"true\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n\n                                                    <span class=\"token operator\">&lt;</span>DocsSubmenu <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> child_pages<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>child_pages<span class=\"token punctuation\">}</span> page<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>page<span class=\"token punctuation\">}</span> site<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>site<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>nav<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>DocsSubmenu</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> classNames<span class=\"token punctuation\">,</span> Link<span class=\"token punctuation\">,</span> withPrefix <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">DocsSubmenu</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> child_pages <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'child_pages'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> page <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'page'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>ul className<span class=\"token operator\">=</span><span class=\"token string\">\"docs-submenu\"</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>child_pages<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">child_page<span class=\"token punctuation\">,</span> child_page_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>li\n                        key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>child_page_idx<span class=\"token punctuation\">}</span>\n                        className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'docs-menu-item'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">current</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>child_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>child_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>child_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'frontmatter.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>Footer</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> htmlToReact <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> ActionLink <span class=\"token keyword\">from</span> <span class=\"token string\">'./ActionLink'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Footer</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>footer id<span class=\"token operator\">=</span><span class=\"token string\">\"colophon\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"site-footer outer\"</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"inner\"</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"site-footer-inside\"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"site-info\"</span><span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.footer.content'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"copyright\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">htmlToReact</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.footer.content'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.footer.links'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">action<span class=\"token punctuation\">,</span> action_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                                <span class=\"token operator\">&lt;</span>ActionLink key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action_idx<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> action<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n\n                        <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.footer.has_social'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                            <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"social-links\"</span><span class=\"token operator\">></span>\n                                <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.footer.social_links'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">action<span class=\"token punctuation\">,</span> action_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                                    <span class=\"token operator\">&lt;</span>ActionLink key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action_idx<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> action<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>footer<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<h2>Header</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> Link<span class=\"token punctuation\">,</span> withPrefix<span class=\"token punctuation\">,</span> classNames <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> ActionLink <span class=\"token keyword\">from</span> <span class=\"token string\">'./ActionLink'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Submenu <span class=\"token keyword\">from</span> <span class=\"token string\">'./Submenu'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Header</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>header id<span class=\"token operator\">=</span><span class=\"token string\">\"masthead\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"site-header outer\"</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"inner\"</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"site-header-inside\"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"site-branding\"</span><span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.header.logo_img'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                                <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"site-logo\"</span><span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.header.url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                                        <span class=\"token operator\">&lt;</span>img\n                                            src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.header.logo_img'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                            alt<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.header.logo_img_alt'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                        <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n                                <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"site-title\"</span><span class=\"token operator\">></span>\n                                    <span class=\"token punctuation\">{</span><span class=\"token string\">' '</span><span class=\"token punctuation\">}</span>\n                                    WebDevHub\n                                    <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.header.url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                                        <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.header.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n\n                        <span class=\"token operator\">&lt;</span>div id<span class=\"token operator\">=</span><span class=\"token string\">\"search\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"inner\"</span><span class=\"token operator\">></span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n\n                        <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.header.has_nav'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                            <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span>nav id<span class=\"token operator\">=</span><span class=\"token string\">\"main-navigation\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"site-navigation\"</span> aria<span class=\"token operator\">-</span>label<span class=\"token operator\">=</span><span class=\"token string\">\"Main Navigation\"</span><span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"site-nav-inside\"</span><span class=\"token operator\">></span>\n                                        <span class=\"token operator\">&lt;</span>button id<span class=\"token operator\">=</span><span class=\"token string\">\"menu-close\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"menu-toggle\"</span><span class=\"token operator\">></span>\n                                            <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"screen-reader-text\"</span><span class=\"token operator\">></span>Open Menu<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n\n                                            <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"icon-close\"</span> aria<span class=\"token operator\">-</span>hidden<span class=\"token operator\">=</span><span class=\"token string\">\"true\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n\n                                        <span class=\"token operator\">&lt;</span>ul className<span class=\"token operator\">=</span><span class=\"token string\">\"menu\"</span><span class=\"token operator\">></span>\n                                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.header.nav_links'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">action<span class=\"token punctuation\">,</span> action_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                                                <span class=\"token keyword\">let</span> page_url <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                                <span class=\"token keyword\">let</span> action_url <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                                                    <span class=\"token operator\">&lt;</span>li\n                                                        key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action_idx<span class=\"token punctuation\">}</span>\n                                                        className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'menu-item'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                                            <span class=\"token string-property property\">'has-children'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'has_subnav'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'subnav_links'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                                            <span class=\"token literal-property property\">current</span><span class=\"token operator\">:</span> page_url <span class=\"token operator\">===</span> action_url<span class=\"token punctuation\">,</span>\n\n                                                            <span class=\"token string-property property\">'menu-button'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> <span class=\"token string\">'link'</span>\n                                                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                                    <span class=\"token operator\">></span>\n                                                        <span class=\"token operator\">&lt;</span>ActionLink <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> action<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                                                        <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'has_subnav'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'subnav_links'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                                            <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                                                                <span class=\"token operator\">&lt;</span>button className<span class=\"token operator\">=</span><span class=\"token string\">\"submenu-toggle\"</span><span class=\"token operator\">></span>\n                                                                    <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"icon-angle-right\"</span> aria<span class=\"token operator\">-</span>hidden<span class=\"token operator\">=</span><span class=\"token string\">\"true\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                                                                    <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"screen-reader-text\"</span><span class=\"token operator\">></span>Sub<span class=\"token operator\">-</span>menu<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n                                                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n\n                                                                <span class=\"token operator\">&lt;</span>Submenu\n                                                                    <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span>\n                                                                    submenu<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'subnav_links'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                                                    menu_class<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token string\">'submenu'</span><span class=\"token punctuation\">}</span>\n                                                                    page<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>pageContext<span class=\"token punctuation\">}</span>\n                                                                <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                                            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                                                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                                                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>nav<span class=\"token operator\">></span>\n\n                                <span class=\"token operator\">&lt;</span>button id<span class=\"token operator\">=</span><span class=\"token string\">\"menu-open\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"menu-toggle\"</span><span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"screen-reader-text\"</span><span class=\"token operator\">></span>Close Menu<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>span<span class=\"token operator\">></span>\n\n                                    <span class=\"token operator\">&lt;</span>span className<span class=\"token operator\">=</span><span class=\"token string\">\"icon-menu\"</span> aria<span class=\"token operator\">-</span>hidden<span class=\"token operator\">=</span><span class=\"token string\">\"true\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n\n                <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>a className<span class=\"token operator\">=</span><span class=\"token string\">\"github-corner\"</span> href<span class=\"token operator\">=</span><span class=\"token string\">\"https://github.com/bgoonz/BGOONZ_BLOG_2.0\"</span> aria<span class=\"token operator\">-</span>label<span class=\"token operator\">=</span><span class=\"token string\">\"View source on Github\"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>svg\n                            aria<span class=\"token operator\">-</span>hidden<span class=\"token operator\">=</span><span class=\"token string\">\"true\"</span>\n                            width<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">80</span><span class=\"token punctuation\">}</span>\n                            height<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token number\">80</span><span class=\"token punctuation\">}</span>\n                            viewBox<span class=\"token operator\">=</span><span class=\"token string\">\"0 0 250 250\"</span>\n                            style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">zIndex</span><span class=\"token operator\">:</span> <span class=\"token number\">100000</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">fill</span><span class=\"token operator\">:</span> <span class=\"token string\">'#194ccdaf'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">color</span><span class=\"token operator\">:</span> <span class=\"token string\">'#fff'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">position</span><span class=\"token operator\">:</span> <span class=\"token string\">'fixed'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">top</span><span class=\"token operator\">:</span> <span class=\"token string\">'20px'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">border</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">left</span><span class=\"token operator\">:</span> <span class=\"token string\">'20px'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">transform</span><span class=\"token operator\">:</span> <span class=\"token string\">'scale(-1.5, 1.5)'</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z\"</span><span class=\"token operator\">></span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>path<span class=\"token operator\">></span>\n\n                            <span class=\"token operator\">&lt;</span>path\n                                className<span class=\"token operator\">=</span><span class=\"token string\">\"octo-arm\"</span>\n                                d<span class=\"token operator\">=</span><span class=\"token string\">\"M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2\"</span>\n                                fill<span class=\"token operator\">=</span><span class=\"token string\">\"currentColor\"</span>\n                                style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">transformOrigin</span><span class=\"token operator\">:</span> <span class=\"token string\">'130px 106px'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">}</span>\n                            <span class=\"token operator\">></span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>path<span class=\"token operator\">></span>\n\n                            <span class=\"token operator\">&lt;</span>path\n                                className<span class=\"token operator\">=</span><span class=\"token string\">\"octo-body\"</span>\n                                d<span class=\"token operator\">=</span><span class=\"token string\">\"M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z\"</span>\n                                fill<span class=\"token operator\">=</span><span class=\"token string\">\"currentColor\"</span>\n                            <span class=\"token operator\">></span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>path<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>svg<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>a<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>header<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>Icon</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Icon</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> icon <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'icon'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>svg className<span class=\"token operator\">=</span><span class=\"token string\">\"icon\"</span> viewBox<span class=\"token operator\">=</span><span class=\"token string\">\"0 0 24 24\"</span> xmlns<span class=\"token operator\">=</span><span class=\"token string\">\"http://www.w3.org/2000/svg\"</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span>icon <span class=\"token operator\">===</span> <span class=\"token string\">'dev'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M7.42 10.05c-.18-.16-.46-.23-.84-.23H6l.02 2.44.04 2.45.56-.02c.41 0 .63-.07.83-.26.24-.24.26-.36.26-2.2 0-1.91-.02-1.96-.29-2.18zM0 4.94v14.12h24V4.94H0zM8.56 15.3c-.44.58-1.06.77-2.53.77H4.71V8.53h1.4c1.67 0 2.16.18 2.6.9.27.43.29.6.32 2.57.05 2.23-.02 2.73-.47 3.3zm5.09-5.47h-2.47v1.77h1.52v1.28l-.72.04-.75.03v1.77l1.22.03 1.2.04v1.28h-1.6c-1.53 0-1.6-.01-1.87-.3l-.3-.28v-3.16c0-3.02.01-3.18.25-3.48.23-.31.25-.31 1.88-.31h1.64v1.3zm4.68 5.45c-.17.43-.64.79-1 .79-.18 0-.45-.15-.67-.39-.32-.32-.45-.63-.82-2.08l-.9-3.39-.45-1.67h.76c.4 0 .75.02.75.05 0 .06 1.16 4.54 1.26 4.83.04.15.32-.7.73-2.3l.66-2.52.74-.04c.4-.02.73 0 .73.04 0 .14-1.67 6.38-1.8 6.68z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> icon <span class=\"token operator\">===</span> <span class=\"token string\">'facebook'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M23.998 12c0-6.628-5.372-12-11.999-12C5.372 0 0 5.372 0 12c0 5.988 4.388 10.952 10.124 11.852v-8.384H7.078v-3.469h3.046V9.356c0-3.008 1.792-4.669 4.532-4.669 1.313 0 2.686.234 2.686.234v2.953H15.83c-1.49 0-1.955.925-1.955 1.874V12h3.328l-.532 3.469h-2.796v8.384c5.736-.9 10.124-5.864 10.124-11.853z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> icon <span class=\"token operator\">===</span> <span class=\"token string\">'github'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> icon <span class=\"token operator\">===</span> <span class=\"token string\">'instagram'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M12 0C8.74 0 8.333.015 7.053.072 5.775.132 4.905.333 4.14.63c-.789.306-1.459.717-2.126 1.384S.935 3.35.63 4.14C.333 4.905.131 5.775.072 7.053.012 8.333 0 8.74 0 12s.015 3.667.072 4.947c.06 1.277.261 2.148.558 2.913a5.885 5.885 0 001.384 2.126A5.868 5.868 0 004.14 23.37c.766.296 1.636.499 2.913.558C8.333 23.988 8.74 24 12 24s3.667-.015 4.947-.072c1.277-.06 2.148-.262 2.913-.558a5.898 5.898 0 002.126-1.384 5.86 5.86 0 001.384-2.126c.296-.765.499-1.636.558-2.913.06-1.28.072-1.687.072-4.947s-.015-3.667-.072-4.947c-.06-1.277-.262-2.149-.558-2.913a5.89 5.89 0 00-1.384-2.126A5.847 5.847 0 0019.86.63c-.765-.297-1.636-.499-2.913-.558C15.667.012 15.26 0 12 0zm0 2.16c3.203 0 3.585.016 4.85.071 1.17.055 1.805.249 2.227.415.562.217.96.477 1.382.896.419.42.679.819.896 1.381.164.422.36 1.057.413 2.227.057 1.266.07 1.646.07 4.85s-.015 3.585-.074 4.85c-.061 1.17-.256 1.805-.421 2.227a3.81 3.81 0 01-.899 1.382 3.744 3.744 0 01-1.38.896c-.42.164-1.065.36-2.235.413-1.274.057-1.649.07-4.859.07-3.211 0-3.586-.015-4.859-.074-1.171-.061-1.816-.256-2.236-.421a3.716 3.716 0 01-1.379-.899 3.644 3.644 0 01-.9-1.38c-.165-.42-.359-1.065-.42-2.235-.045-1.26-.061-1.649-.061-4.844 0-3.196.016-3.586.061-4.861.061-1.17.255-1.814.42-2.234.21-.57.479-.96.9-1.381.419-.419.81-.689 1.379-.898.42-.166 1.051-.361 2.221-.421 1.275-.045 1.65-.06 4.859-.06l.045.03zm0 3.678a6.162 6.162 0 100 12.324 6.162 6.162 0 100-12.324zM12 16c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4-1.79 4-4 4zm7.846-10.405a1.441 1.441 0 01-2.88 0 1.44 1.44 0 012.88 0z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> icon <span class=\"token operator\">===</span> <span class=\"token string\">'linkedin'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 01-2.063-2.065 2.064 2.064 0 112.063 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> icon <span class=\"token operator\">===</span> <span class=\"token string\">'pinterest'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M12.017 0C5.396 0 .029 5.367.029 11.987c0 5.079 3.158 9.417 7.618 11.162-.105-.949-.199-2.403.041-3.439.219-.937 1.406-5.957 1.406-5.957s-.359-.72-.359-1.781c0-1.663.967-2.911 2.168-2.911 1.024 0 1.518.769 1.518 1.688 0 1.029-.653 2.567-.992 3.992-.285 1.193.6 2.165 1.775 2.165 2.128 0 3.768-2.245 3.768-5.487 0-2.861-2.063-4.869-5.008-4.869-3.41 0-5.409 2.562-5.409 5.199 0 1.033.394 2.143.889 2.741.099.12.112.225.085.345-.09.375-.293 1.199-.334 1.363-.053.225-.172.271-.401.165-1.495-.69-2.433-2.878-2.433-4.646 0-3.776 2.748-7.252 7.92-7.252 4.158 0 7.392 2.967 7.392 6.923 0 4.135-2.607 7.462-6.233 7.462-1.214 0-2.354-.629-2.758-1.379l-.749 2.848c-.269 1.045-1.004 2.352-1.498 3.146 1.123.345 2.306.535 3.55.535 6.607 0 11.985-5.365 11.985-11.987C23.97 5.39 18.592.026 11.985.026L12.017 0z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> icon <span class=\"token operator\">===</span> <span class=\"token string\">'reddit'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.25 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 1 1.108-.701zM9.25 12C8.561 12 8 12.562 8 13.25c0 .687.561 1.248 1.25 1.248.687 0 1.248-.561 1.248-1.249 0-.688-.561-1.249-1.249-1.249zm5.5 0c-.687 0-1.248.561-1.248 1.25 0 .687.561 1.248 1.249 1.248.688 0 1.249-.561 1.249-1.249 0-.687-.562-1.249-1.25-1.249zm-5.466 3.99a.327.327 0 0 0-.231.094.33.33 0 0 0 0 .463c.842.842 2.484.913 2.961.913.477 0 2.105-.056 2.961-.913a.361.361 0 0 0 .029-.463.33.33 0 0 0-.464 0c-.547.533-1.684.73-2.512.73-.828 0-1.979-.196-2.512-.73a.326.326 0 0 0-.232-.095z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> icon <span class=\"token operator\">===</span> <span class=\"token string\">'twitter'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M23.954 4.569a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.691 8.094 4.066 6.13 1.64 3.161a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.061a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.937 4.937 0 004.604 3.417 9.868 9.868 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.054 0 13.999-7.496 13.999-13.986 0-.209 0-.42-.015-.63a9.936 9.936 0 002.46-2.548l-.047-.02z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> icon <span class=\"token operator\">===</span> <span class=\"token string\">'youtube'</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M23.495 6.205a3.007 3.007 0 00-2.088-2.088c-1.87-.501-9.396-.501-9.396-.501s-7.507-.01-9.396.501A3.007 3.007 0 00.527 6.205a31.247 31.247 0 00-.522 5.805 31.247 31.247 0 00.522 5.783 3.007 3.007 0 002.088 2.088c1.868.502 9.396.502 9.396.502s7.506 0 9.396-.502a3.007 3.007 0 002.088-2.088 31.247 31.247 0 00.5-5.783 31.247 31.247 0 00-.5-5.805zM9.609 15.601V8.408l6.264 3.602z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n                    icon <span class=\"token operator\">===</span> <span class=\"token string\">'vimeo'</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>path d<span class=\"token operator\">=</span><span class=\"token string\">\"M23.977 6.416c-.105 2.338-1.739 5.543-4.894 9.609-3.268 4.247-6.026 6.37-8.29 6.37-1.409 0-2.578-1.294-3.553-3.881L5.322 11.4C4.603 8.816 3.834 7.522 3.01 7.522c-.179 0-.806.378-1.881 1.132L0 7.197a315.065 315.065 0 003.501-3.128C5.08 2.701 6.266 1.984 7.055 1.91c1.867-.18 3.016 1.1 3.447 3.838.465 2.953.789 4.789.971 5.507.539 2.45 1.131 3.674 1.776 3.674.502 0 1.256-.796 2.265-2.385 1.004-1.589 1.54-2.797 1.612-3.628.144-1.371-.395-2.061-1.614-2.061-.574 0-1.167.121-1.777.391 1.186-3.868 3.434-5.757 6.762-5.637 2.473.06 3.628 1.664 3.493 4.797l-.013.01z\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>svg<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>Body</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> Helmet <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-helmet'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> withPrefix<span class=\"token punctuation\">,</span> attribute <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token string\">'../sass/main.scss'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Header <span class=\"token keyword\">from</span> <span class=\"token string\">'./Header'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Footer <span class=\"token keyword\">from</span> <span class=\"token string\">'./Footer'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Body</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>Helmet<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>title<span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                            <span class=\"token operator\">?</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                            <span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' | '</span> <span class=\"token operator\">+</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>title<span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>meta charSet<span class=\"token operator\">=</span><span class=\"token string\">\"utf-8\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>meta name<span class=\"token operator\">=</span><span class=\"token string\">\"viewport\"</span> content<span class=\"token operator\">=</span><span class=\"token string\">\"width=device-width, initialScale=1.0\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>meta name<span class=\"token operator\">=</span><span class=\"token string\">\"description\"</span> content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.description'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.robots'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>meta name<span class=\"token operator\">=</span><span class=\"token string\">\"robots\"</span> content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.robots'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">','</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.extra'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">meta<span class=\"token punctuation\">,</span> meta_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">let</span> key_name <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'keyName'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">return</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'relativeUrl'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                            _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.domain'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                                <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">let</span> domain <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.domain'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">let</span> rel_url <span class=\"token operator\">=</span> <span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">let</span> full_url <span class=\"token operator\">=</span> domain <span class=\"token operator\">+</span> rel_url<span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>meta key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>meta_idx<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token function\">attribute</span><span class=\"token punctuation\">(</span>key_name<span class=\"token punctuation\">,</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>full_url<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n                            <span class=\"token operator\">&lt;</span>meta key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>meta_idx <span class=\"token operator\">+</span> <span class=\"token string\">'.1'</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token function\">attribute</span><span class=\"token punctuation\">(</span>key_name<span class=\"token punctuation\">,</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token operator\">&lt;</span>link rel<span class=\"token operator\">=</span><span class=\"token string\">\"preconnect\"</span> href<span class=\"token operator\">=</span><span class=\"token string\">\"https://fonts.gstatic.com\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>link href<span class=\"token operator\">=</span><span class=\"token string\">\"https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&amp;display=swap\"</span> rel<span class=\"token operator\">=</span><span class=\"token string\">\"stylesheet\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.favicon'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>link rel<span class=\"token operator\">=</span><span class=\"token string\">\"icon\"</span> href<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.favicon'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token operator\">&lt;</span>body className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token string\">'palette-'</span> <span class=\"token operator\">+</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.palette'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Helmet<span class=\"token operator\">></span>\n\n                <span class=\"token operator\">&lt;</span>div id<span class=\"token operator\">=</span><span class=\"token string\">\"page\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"site\"</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>Header <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>main id<span class=\"token operator\">=</span><span class=\"token string\">\"content\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"site-content\"</span><span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>main<span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>Footer <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>SectionContent</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> classNames<span class=\"token punctuation\">,</span> withPrefix<span class=\"token punctuation\">,</span> markdownify <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> CtaButtons <span class=\"token keyword\">from</span> <span class=\"token string\">'./CtaButtons'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">SectionContent</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> section <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'section'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>section id<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'section_id'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"block block-text outer\"</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"outter\"</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>div\n                        className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'inner'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token string-property property\">'grid-swap'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'image'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'image_position'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'right'</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'image'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                            <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item block-image\"</span><span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span>img src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'image'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> alt<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'image_alt'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                        <span class=\"token operator\">&lt;</span>div<span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"block-header\"</span><span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span>h2 className<span class=\"token operator\">=</span><span class=\"token string\">\"block-title\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'content'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"outer\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">markdownify</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'content'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"block-buttons\"</span><span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span>CtaButtons <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> actions<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>section<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>SectionCta</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> htmlToReact <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> CtaButtons <span class=\"token keyword\">from</span> <span class=\"token string\">'./CtaButtons'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">SectionCta</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> section <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'section'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>section id<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'section_id'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"block block-cta outer\"</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"inner\"</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"has-gradient\"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid grid-middle grid-center\"</span><span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item block-header\"</span><span class=\"token operator\">></span>\n                                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>h2 className<span class=\"token operator\">=</span><span class=\"token string\">\"block-title\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n\n                                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"block-subtitle\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">htmlToReact</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item block-buttons\"</span><span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span>CtaButtons <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> actions<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>section<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>SectionDocs</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> classNames<span class=\"token punctuation\">,</span> htmlToReact<span class=\"token punctuation\">,</span> pathJoin<span class=\"token punctuation\">,</span> getPage<span class=\"token punctuation\">,</span> Link<span class=\"token punctuation\">,</span> withPrefix <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">SectionDocs</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> section <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'section'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>section\n                id<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'section_id'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'block'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'block-grid'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'outer'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token string-property property\">'has-header'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"inner\"</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"block-header inner-sm\"</span><span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>h2 className<span class=\"token operator\">=</span><span class=\"token string\">\"block-title\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"block-subtitle\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">htmlToReact</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"&lt;iframe \"</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span>div\n                            className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'grid'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token string-property property\">'grid-col-2'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'col_number'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token string-property property\">'grid-col-3'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'col_number'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'three'</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.data.doc_sections.sections'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">doc_section<span class=\"token punctuation\">,</span> doc_section_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">let</span> doc_section_path <span class=\"token operator\">=</span> <span class=\"token function\">pathJoin</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.data.doc_sections.root_docs_path'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> doc_section<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">let</span> doc_section_page <span class=\"token operator\">=</span> <span class=\"token function\">getPage</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>pageContext<span class=\"token punctuation\">.</span>pages<span class=\"token punctuation\">,</span> doc_section_path<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                                    <span class=\"token operator\">&lt;</span>div key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>doc_section_idx<span class=\"token punctuation\">}</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item\"</span><span class=\"token operator\">></span>\n                                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-inside\"</span><span class=\"token operator\">></span>\n                                            <span class=\"token operator\">&lt;</span>h3 className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-title line-left\"</span><span class=\"token operator\">></span>\n                                                <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>doc_section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                                                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>doc_section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'frontmatter.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                                            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h3<span class=\"token operator\">></span>\n\n                                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>doc_section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'frontmatter.excerpt'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-content\"</span><span class=\"token operator\">></span>\n                                                    <span class=\"token operator\">&lt;</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">htmlToReact</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>doc_section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'frontmatter.excerpt'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span>\n                                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                                            <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-buttons\"</span><span class=\"token operator\">></span>\n                                                <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>doc_section_page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Learn More<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                                            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>section<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>SectionGrid</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> classNames<span class=\"token punctuation\">,</span> htmlToReact<span class=\"token punctuation\">,</span> withPrefix<span class=\"token punctuation\">,</span> Link<span class=\"token punctuation\">,</span> markdownify <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> CtaButtons <span class=\"token keyword\">from</span> <span class=\"token string\">'./CtaButtons'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">SectionGrid</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> section <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'section'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>section\n                id<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'section_id'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'block'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'block-grid'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'outer'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token string-property property\">'has-header'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"inner\"</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"block-header inner-sm\"</span><span class=\"token operator\">></span>\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>h2 className<span class=\"token operator\">=</span><span class=\"token string\">\"block-title\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h2<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n\n                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>p className<span class=\"token operator\">=</span><span class=\"token string\">\"block-subtitle\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">htmlToReact</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'subtitle'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>p<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'grid_items'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"&lt;iframe \"</span><span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>div\n                                className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'grid'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token string-property property\">'grid-col-2'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'col_number'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'two'</span><span class=\"token punctuation\">,</span>\n\n                                    <span class=\"token string-property property\">'grid-col-3'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'col_number'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">===</span> <span class=\"token string\">'three'</span>\n                                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                            <span class=\"token operator\">></span>\n                                <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'grid_items'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">item<span class=\"token punctuation\">,</span> item_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span>\n                                    <span class=\"token operator\">&lt;</span>div key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>item_idx<span class=\"token punctuation\">}</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item\"</span><span class=\"token operator\">></span>\n                                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-inside\"</span><span class=\"token operator\">></span>\n                                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'image'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-image\"</span><span class=\"token operator\">></span>\n                                                    <span class=\"token operator\">&lt;</span>img src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'image'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> alt<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'image_alt'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                                <span class=\"token operator\">&lt;</span>h3 className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-title line-left\"</span><span class=\"token operator\">></span>\n                                                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'title_url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                                                        <span class=\"token operator\">&lt;</span>Link to<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'title_url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Link<span class=\"token operator\">></span>\n                                                    <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n                                                        _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                                                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h3<span class=\"token operator\">></span>\n                                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'content'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-content\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">markdownify</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'content'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                                            <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                                                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"grid-item-buttons\"</span><span class=\"token operator\">></span>\n                                                    <span class=\"token operator\">&lt;</span>CtaButtons <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> actions<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>item<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                                                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>section<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>SectionHero</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> toStyleObj<span class=\"token punctuation\">,</span> withPrefix<span class=\"token punctuation\">,</span> markdownify <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> CtaButtons <span class=\"token keyword\">from</span> <span class=\"token string\">'./CtaButtons'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">SectionHero</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> section <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'section'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>section id<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'section_id'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"block block-hero has-gradient outer\"</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'image'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"bg-img\"</span> style<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">toStyleObj</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"background-image: url('\"</span> <span class=\"token operator\">+</span> <span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'image'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">\"')\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"inner-sm\"</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"block-header\"</span><span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>h1 className<span class=\"token operator\">=</span><span class=\"token string\">\"block-title\"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>h1<span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'content'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"&lt;iframe \"</span><span class=\"token operator\">></span><span class=\"token punctuation\">{</span><span class=\"token function\">markdownify</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'content'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>div className<span class=\"token operator\">=</span><span class=\"token string\">\"block-buttons\"</span><span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>CtaButtons <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> actions<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>section<span class=\"token punctuation\">,</span> <span class=\"token string\">'actions'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>section<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>Submenu</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> classNames <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> ActionLink <span class=\"token keyword\">from</span> <span class=\"token string\">'./ActionLink'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Submenu</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> page <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'page'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>ul className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'menu_class'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span><span class=\"token operator\">></span>\n                <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'submenu'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">action<span class=\"token punctuation\">,</span> action_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">let</span> page_url <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>page<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">let</span> action_url <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'url'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>li\n                            key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action_idx<span class=\"token punctuation\">}</span>\n                            className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token string\">'menu-item'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">current</span><span class=\"token operator\">:</span> page_url <span class=\"token operator\">===</span> action_url<span class=\"token punctuation\">,</span>\n\n                                <span class=\"token string-property property\">'menu-button'</span><span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>action<span class=\"token punctuation\">,</span> <span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> <span class=\"token string\">'link'</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">></span>\n                            <span class=\"token operator\">&lt;</span>ActionLink <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> action<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>action<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>li<span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>ul<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<hr>\n<details>\n  <summary>Click to expand!</summary>\n<h2>Index.js</h2>\n<hr>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> ActionLink <span class=\"token keyword\">from</span> <span class=\"token string\">'./ActionLink'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> CtaButtons <span class=\"token keyword\">from</span> <span class=\"token string\">'./CtaButtons'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> DocsMenu <span class=\"token keyword\">from</span> <span class=\"token string\">'./DocsMenu'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> DocsSubmenu <span class=\"token keyword\">from</span> <span class=\"token string\">'./DocsSubmenu'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Footer <span class=\"token keyword\">from</span> <span class=\"token string\">'./Footer'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Header <span class=\"token keyword\">from</span> <span class=\"token string\">'./Header'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Icon <span class=\"token keyword\">from</span> <span class=\"token string\">'./Icon'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionContent <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionContent'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionCta <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionCta'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionDocs <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionDocs'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionGrid <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionGrid'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionHero <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionHero'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Submenu <span class=\"token keyword\">from</span> <span class=\"token string\">'./Submenu'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Layout <span class=\"token keyword\">from</span> <span class=\"token string\">'./Layout'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token punctuation\">{</span>\n    ActionLink<span class=\"token punctuation\">,</span>\n    CtaButtons<span class=\"token punctuation\">,</span>\n    DocsMenu<span class=\"token punctuation\">,</span>\n    DocsSubmenu<span class=\"token punctuation\">,</span>\n    Footer<span class=\"token punctuation\">,</span>\n    Header<span class=\"token punctuation\">,</span>\n    Icon<span class=\"token punctuation\">,</span>\n    SectionContent<span class=\"token punctuation\">,</span>\n    SectionCta<span class=\"token punctuation\">,</span>\n    SectionDocs<span class=\"token punctuation\">,</span>\n    SectionGrid<span class=\"token punctuation\">,</span>\n    SectionHero<span class=\"token punctuation\">,</span>\n    Submenu<span class=\"token punctuation\">,</span>\n    Layout\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token punctuation\">{</span>\n    ActionLink<span class=\"token punctuation\">,</span>\n\n    CtaButtons<span class=\"token punctuation\">,</span>\n\n    DocsMenu<span class=\"token punctuation\">,</span>\n\n    DocsSubmenu<span class=\"token punctuation\">,</span>\n\n    Footer<span class=\"token punctuation\">,</span>\n\n    Header<span class=\"token punctuation\">,</span>\n\n    Icon<span class=\"token punctuation\">,</span>\n\n    SectionContent<span class=\"token punctuation\">,</span>\n\n    SectionCta<span class=\"token punctuation\">,</span>\n\n    SectionDocs<span class=\"token punctuation\">,</span>\n\n    SectionGrid<span class=\"token punctuation\">,</span>\n\n    SectionHero<span class=\"token punctuation\">,</span>\n\n    Submenu<span class=\"token punctuation\">,</span>\n\n    Layout\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n</details>\n<hr>\n<hr>\n<h1>Static Javascript</h1>\n<details>\n  <summary>Static Javascript:!</summary>\n<h1>main.js</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onGatsbyInitialClientRender</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">/**\n\n     * Main JS file for theme behaviours\n\n     */</span>\n\n    <span class=\"token comment\">// Responsive video embeds</span>\n\n    <span class=\"token keyword\">let</span> videoEmbeds <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'iframe[src*=\"youtube.com\"]'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'iframe[src*=\"vimeo.com\"]'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">reframe</span><span class=\"token punctuation\">(</span>videoEmbeds<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Handle main navigation menu toggling on small screens</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">menuToggleHandler</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">toggle</span><span class=\"token punctuation\">(</span><span class=\"token string\">'menu--opened'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// Handle docs navigation menu toggling on small screens</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">docsNavToggleHandler</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">toggle</span><span class=\"token punctuation\">(</span><span class=\"token string\">'docs-menu--opened'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// Handle submenu toggling</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">submenuToggleHandler</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">toggle</span><span class=\"token punctuation\">(</span><span class=\"token string\">'active'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">addMainNavigationHandlers</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> menuToggle <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.menu-toggle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>menuToggle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> menuToggle<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                menuToggle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> menuToggleHandler<span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> submenuToggle <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.submenu-toggle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>submenuToggle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> submenuToggle<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                submenuToggle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> submenuToggleHandler<span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">removeMainNavigationHandlers</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Remove nav related classes on page load</span>\n\n        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token string\">'menu--opened'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> menuToggle <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.menu-toggle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>menuToggle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> menuToggle<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                menuToggle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> menuToggleHandler<span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> submenuToggle <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.submenu-toggle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>submenuToggle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> submenuToggle<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                submenuToggle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> submenuToggleHandler<span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">addDocsNavigationHandlers</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> docsNavToggle <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'docs-nav-toggle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>docsNavToggle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            docsNavToggle<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> docsNavToggleHandler<span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> docsSubmenuToggle <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.docs-submenu-toggle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>docsSubmenuToggle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> docsSubmenuToggle<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                docsSubmenuToggle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> submenuToggleHandler<span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">removeDocsNavigationHandlers</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Remove docs nav related classes on page load</span>\n\n        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token string\">'docs-menu--opened'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> docsNavToggle <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'docs-nav-toggle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>docsNavToggle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            docsNavToggle<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> docsNavToggleHandler<span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">const</span> docsSubmenuToggle <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.docs-submenu-toggle'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>docsSubmenuToggle<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> docsSubmenuToggle<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                docsSubmenuToggle<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> submenuToggleHandler<span class=\"token punctuation\">,</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">addPageNavLinks</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> pageToc <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'page-nav-inside'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> pageTocContainer <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'page-nav-link-container'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageToc <span class=\"token operator\">&amp;&amp;</span> pageTocContainer<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">const</span> pageContent <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.type-docs .post-content'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token comment\">// Create in-page navigation</span>\n\n            <span class=\"token keyword\">const</span> headerLinks <span class=\"token operator\">=</span> <span class=\"token function\">getHeaderLinks</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">root</span><span class=\"token operator\">:</span> pageContent\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>headerLinks<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                pageToc<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'has-links'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token function\">renderHeaderLinks</span><span class=\"token punctuation\">(</span>pageTocContainer<span class=\"token punctuation\">,</span> headerLinks<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token comment\">// Scroll to anchors</span>\n\n            <span class=\"token keyword\">let</span> scroll <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">SmoothScroll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'[data-scroll]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">let</span> hash <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">decodeURI</span><span class=\"token punctuation\">(</span>location<span class=\"token punctuation\">.</span>hash<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token string\">'#'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>hash <span class=\"token operator\">!==</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                window<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">let</span> anchor <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span>hash<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>anchor<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        scroll<span class=\"token punctuation\">.</span><span class=\"token function\">animateScroll</span><span class=\"token punctuation\">(</span>anchor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token comment\">// Highlight current anchor</span>\n\n            <span class=\"token keyword\">let</span> pageTocLinks <span class=\"token operator\">=</span> pageTocContainer<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByTagName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageTocLinks<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">let</span> spy <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Gumshoe</span><span class=\"token punctuation\">(</span><span class=\"token string\">'#page-nav-inside a'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token literal-property property\">nested</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">nestedClass</span><span class=\"token operator\">:</span> <span class=\"token string\">'active-parent'</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token comment\">// Add link to page content headings</span>\n\n            <span class=\"token keyword\">let</span> pageHeadings <span class=\"token operator\">=</span> <span class=\"token function\">getElementsByTagNames</span><span class=\"token punctuation\">(</span>pageContent<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'h2'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'h3'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> pageHeadings<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">let</span> heading <span class=\"token operator\">=</span> pageHeadings<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">typeof</span> heading<span class=\"token punctuation\">.</span>id <span class=\"token operator\">!==</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">&amp;&amp;</span> heading<span class=\"token punctuation\">.</span>id <span class=\"token operator\">!==</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    heading<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span><span class=\"token function\">anchorForId</span><span class=\"token punctuation\">(</span>heading<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> heading<span class=\"token punctuation\">.</span>firstChild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token comment\">// Copy link url</span>\n\n            <span class=\"token keyword\">let</span> clipboard <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ClipboardJS</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.hash-link'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token function-variable function\">text</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">trigger</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> window<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>href<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>hash<span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> trigger<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'href'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">removePageNavLinks</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">const</span> pageToc <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'page-nav-inside'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">const</span> pageTocContainer <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'page-nav-link-container'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pageToc <span class=\"token operator\">&amp;&amp;</span> pageTocContainer<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            pageToc<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span><span class=\"token string\">'has-links'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>pageTocContainer<span class=\"token punctuation\">.</span>firstChild<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                pageTocContainer<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>pageTocContainer<span class=\"token punctuation\">.</span>firstChild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">getElementsByTagNames</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">root<span class=\"token punctuation\">,</span> tagNames</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> elements <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> root<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> element <span class=\"token operator\">=</span> root<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">let</span> tagName <span class=\"token operator\">=</span> element<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>tagNames<span class=\"token punctuation\">.</span><span class=\"token function\">includes</span><span class=\"token punctuation\">(</span>tagName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                elements<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            elements <span class=\"token operator\">=</span> elements<span class=\"token punctuation\">.</span><span class=\"token function\">concat</span><span class=\"token punctuation\">(</span><span class=\"token function\">getElementsByTagNames</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> tagNames<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> elements<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">createLinksForHeaderElements</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">elements</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> result <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> stack <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n            <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">level</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> result\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> re <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^h(\\d)$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> elements<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> element <span class=\"token operator\">=</span> elements<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">let</span> tagName <span class=\"token operator\">=</span> element<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">let</span> match <span class=\"token operator\">=</span> re<span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>tagName<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>match<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                console<span class=\"token punctuation\">.</span><span class=\"token function\">warn</span><span class=\"token punctuation\">(</span><span class=\"token string\">'can not create links to non header element'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token keyword\">let</span> headerLevel <span class=\"token operator\">=</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>match<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>element<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>element<span class=\"token punctuation\">.</span>textContent<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    console<span class=\"token punctuation\">.</span><span class=\"token function\">warn</span><span class=\"token punctuation\">(</span><span class=\"token string\">'can not create link to element without id and without text content'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                element<span class=\"token punctuation\">.</span>id <span class=\"token operator\">=</span> element<span class=\"token punctuation\">.</span>textContent\n\n                    <span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n\n                    <span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^\\w]+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'_'</span><span class=\"token punctuation\">)</span>\n\n                    <span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^_</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span>\n\n                    <span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">_$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token keyword\">let</span> link <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            link<span class=\"token punctuation\">.</span>href <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span> <span class=\"token operator\">+</span> element<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">;</span>\n\n            link<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-scroll'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            link<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span><span class=\"token function\">createTextNode</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">.</span>textContent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">let</span> obj <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> element<span class=\"token punctuation\">.</span>id<span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">level</span><span class=\"token operator\">:</span> headerLevel<span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">textContent</span><span class=\"token operator\">:</span> element<span class=\"token punctuation\">.</span>textContent<span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">element</span><span class=\"token operator\">:</span> element<span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">link</span><span class=\"token operator\">:</span> link<span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>headerLevel <span class=\"token operator\">></span> stack<span class=\"token punctuation\">[</span>stack<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>level<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                stack<span class=\"token punctuation\">[</span>stack<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                stack<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>headerLevel <span class=\"token operator\">&lt;=</span> stack<span class=\"token punctuation\">[</span>stack<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>level <span class=\"token operator\">&amp;&amp;</span> stack<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    stack<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                stack<span class=\"token punctuation\">[</span>stack<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                stack<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>obj<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> result<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">getHeaderLinks</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">options <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> tagNames <span class=\"token operator\">=</span> options<span class=\"token punctuation\">.</span>tagNames <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'h2'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'h3'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> root <span class=\"token operator\">=</span> options<span class=\"token punctuation\">.</span>root <span class=\"token operator\">||</span> document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">let</span> headerElements <span class=\"token operator\">=</span> <span class=\"token function\">getElementsByTagNames</span><span class=\"token punctuation\">(</span>root<span class=\"token punctuation\">,</span> tagNames<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token function\">createLinksForHeaderElements</span><span class=\"token punctuation\">(</span>headerElements<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">renderHeaderLinks</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">element<span class=\"token punctuation\">,</span> links</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>links<span class=\"token punctuation\">.</span>length <span class=\"token operator\">===</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">let</span> ulElm <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'ul'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> links<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">let</span> liElm <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            liElm<span class=\"token punctuation\">.</span><span class=\"token function\">append</span><span class=\"token punctuation\">(</span>links<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>link<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>links<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token function\">renderHeaderLinks</span><span class=\"token punctuation\">(</span>liElm<span class=\"token punctuation\">,</span> links<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            ulElm<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>liElm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        element<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>ulElm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">anchorForId</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">id</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">let</span> anchor <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        anchor<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'class'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'hash-link'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        anchor<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-scroll'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        anchor<span class=\"token punctuation\">.</span>href <span class=\"token operator\">=</span> <span class=\"token string\">'#'</span> <span class=\"token operator\">+</span> id<span class=\"token punctuation\">;</span>\n\n        anchor<span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> <span class=\"token string\">'&lt;span class=\"screen-reader-text\">Copy&lt;/span>'</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> anchor<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// Syntax Highlighter</span>\n\n    <span class=\"token comment\">// Prism.highlightAll();</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//-----------------------------------------------------------------------</span>\n\n<span class=\"token comment\">//-----------------------------------------------------------------------</span>\n\n<span class=\"token comment\">//--------------------------------New----------------------------------</span>\n\n<span class=\"token comment\">//-----------------------------------------------------------------------</span>\n\n<span class=\"token comment\">//-----------------------------------------------------------------------</span></code></pre></div>\n<hr>\n<hr>\n<h1>Page Load JS</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onGatsbyRouteUpdate</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">addMainNavigationHandlers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">addDocsNavigationHandlers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">addPageNavLinks</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<h1>PageUnload.js</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onGatsbyPreRouteUpdate</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">removeMainNavigationHandlers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">removeDocsNavigationHandlers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">removePageNavLinks</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<h1>Plugins.js</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> module\n        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> define <span class=\"token operator\">&amp;&amp;</span> define<span class=\"token punctuation\">.</span>amd\n        <span class=\"token operator\">?</span> <span class=\"token function\">define</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> globalThis <span class=\"token operator\">?</span> globalThis <span class=\"token operator\">:</span> e <span class=\"token operator\">||</span> self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>reframe <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> t <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">;</span> t<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> e <span class=\"token operator\">+=</span> arguments<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token function\">Array</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> t <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">;</span> t<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> f <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> d <span class=\"token operator\">=</span> r<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> f <span class=\"token operator\">&lt;</span> d<span class=\"token punctuation\">;</span> f<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> o<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> i<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> r<span class=\"token punctuation\">[</span>f<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">===</span> s <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>s <span class=\"token operator\">=</span> <span class=\"token string\">'js-reframe'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> e <span class=\"token operator\">?</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token string\">'length'</span> <span class=\"token keyword\">in</span> e <span class=\"token operator\">?</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">,</span> d<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">;</span>\n\n                <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span>\n                    <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>width<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span><span class=\"token string\">'%'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'height'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'width'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>offsetWidth<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> i <span class=\"token operator\">?</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> o <span class=\"token operator\">?</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> f<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>position <span class=\"token operator\">=</span> <span class=\"token string\">'relative'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> <span class=\"token string\">'100%'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span>paddingTop <span class=\"token operator\">=</span> r <span class=\"token operator\">+</span> <span class=\"token string\">'%'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>l <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>position <span class=\"token operator\">=</span> <span class=\"token string\">'absolute'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> <span class=\"token string\">'100%'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>height <span class=\"token operator\">=</span> <span class=\"token string\">'100%'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>top <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> t <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> n <span class=\"token operator\">&amp;&amp;</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    f<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/*! smooth-scroll v16.1.0 | (c) 2019 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */</span>\n\nwindow<span class=\"token punctuation\">.</span>Element <span class=\"token operator\">&amp;&amp;</span>\n    <span class=\"token operator\">!</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>closest <span class=\"token operator\">&amp;&amp;</span>\n    <span class=\"token punctuation\">(</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">closest</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span>\n            n <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>document <span class=\"token operator\">||</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>ownerDocument<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            o <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">do</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;=</span> <span class=\"token operator\">--</span>t <span class=\"token operator\">&amp;&amp;</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">item</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> o<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span>parentElement<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> o<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>CustomEvent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            t <span class=\"token operator\">=</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">bubbles</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cancelable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">detail</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createEvent</span><span class=\"token punctuation\">(</span><span class=\"token string\">'CustomEvent'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">initCustomEvent</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>bubbles<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>cancelable<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>detail<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token class-name\">Event</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>CustomEvent <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'ms'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'moz'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'webkit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'o'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> t <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>window<span class=\"token punctuation\">.</span>requestAnimationFrame<span class=\"token punctuation\">;</span> <span class=\"token operator\">++</span>t<span class=\"token punctuation\">)</span>\n            <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>requestAnimationFrame <span class=\"token operator\">=</span> window<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token string\">'RequestAnimationFrame'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>cancelAnimationFrame <span class=\"token operator\">=</span> window<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token string\">'CancelAnimationFrame'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> window<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token string\">'CancelRequestAnimationFrame'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        window<span class=\"token punctuation\">.</span>requestAnimationFrame <span class=\"token operator\">||</span>\n            <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">requestAnimationFrame</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">getTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    o <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">16</span> <span class=\"token operator\">-</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    a <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">+</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> n <span class=\"token operator\">+</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            window<span class=\"token punctuation\">.</span>cancelAnimationFrame <span class=\"token operator\">||</span>\n                <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">cancelAnimationFrame</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> define <span class=\"token operator\">&amp;&amp;</span> define<span class=\"token punctuation\">.</span>amd\n            <span class=\"token operator\">?</span> <span class=\"token function\">define</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                  <span class=\"token keyword\">return</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n              <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">:</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports\n            <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>SmoothScroll <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> global <span class=\"token operator\">?</span> global <span class=\"token operator\">:</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> window <span class=\"token operator\">?</span> window <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">q</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">var</span> <span class=\"token constant\">I</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">ignore</span><span class=\"token operator\">:</span> <span class=\"token string\">'[data-scroll-ignore]'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">header</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">topOnEmptyHash</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">speed</span><span class=\"token operator\">:</span> <span class=\"token number\">500</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">speedAsDuration</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">durationMax</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">durationMin</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">clip</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">offset</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">easing</span><span class=\"token operator\">:</span> <span class=\"token string\">'easeInOutCubic'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">customEasing</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">updateURL</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">popstate</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">emitEvents</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">F</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> t <span class=\"token keyword\">in</span> e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n                            n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    n\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">r</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token string\">'#'</span> <span class=\"token operator\">===</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">substr</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token function\">String</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> a <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> r <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> i <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token operator\">++</span>a <span class=\"token operator\">&lt;</span> o<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span> <span class=\"token operator\">===</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">InvalidCharacterError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Invalid character: the input contains U+0000.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">31</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token number\">127</span> <span class=\"token operator\">==</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span> <span class=\"token operator\">===</span> a <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">48</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">57</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">===</span> a <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">48</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">57</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">45</span> <span class=\"token operator\">===</span> i<span class=\"token punctuation\">)</span>\n                        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">+=</span> <span class=\"token string\">'\\\\'</span> <span class=\"token operator\">+</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">+=</span>\n                              <span class=\"token number\">128</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">||</span> <span class=\"token number\">45</span> <span class=\"token operator\">===</span> t <span class=\"token operator\">||</span> <span class=\"token number\">95</span> <span class=\"token operator\">===</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">48</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">57</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">65</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">90</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">97</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">122</span><span class=\"token punctuation\">)</span>\n                                  <span class=\"token operator\">?</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span>\n                                  <span class=\"token operator\">:</span> <span class=\"token string\">'\\\\'</span> <span class=\"token operator\">+</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token string\">'#'</span> <span class=\"token operator\">+</span> r<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">L</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>\n                    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>scrollHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>scrollHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>clientHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>clientHeight\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">x</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> e <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">.</span><span class=\"token function\">getComputedStyle</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>height<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>offsetTop<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">H</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>emitEvents <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> q<span class=\"token punctuation\">.</span>CustomEvent<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">CustomEvent</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">bubbles</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">detail</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">anchor</span><span class=\"token operator\">:</span> n<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">toggle</span><span class=\"token operator\">:</span> o <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    document<span class=\"token punctuation\">.</span><span class=\"token function\">dispatchEvent</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">o<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">,</span>\n                a<span class=\"token punctuation\">,</span>\n                <span class=\"token constant\">O</span><span class=\"token punctuation\">,</span>\n                <span class=\"token constant\">C</span><span class=\"token punctuation\">,</span>\n                <span class=\"token constant\">M</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">cancelScroll</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token function\">cancelAnimationFrame</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">C</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e <span class=\"token operator\">||</span> <span class=\"token constant\">H</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scrollCancel'</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">animateScroll</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">i<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">cancelScroll</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> <span class=\"token constant\">F</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span> <span class=\"token operator\">||</span> <span class=\"token constant\">I</span><span class=\"token punctuation\">,</span> e <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        u <span class=\"token operator\">=</span> <span class=\"token string\">'[object Number]'</span> <span class=\"token operator\">===</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        t <span class=\"token operator\">=</span> u <span class=\"token operator\">||</span> <span class=\"token operator\">!</span>i<span class=\"token punctuation\">.</span>tagName <span class=\"token operator\">?</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">:</span> i<span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>u <span class=\"token operator\">||</span> t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> l <span class=\"token operator\">=</span> q<span class=\"token punctuation\">.</span>pageYOffset<span class=\"token punctuation\">;</span>\n\n                        s<span class=\"token punctuation\">.</span>header <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token constant\">O</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">O</span> <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>header<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">var</span> n<span class=\"token punctuation\">,</span>\n                            o<span class=\"token punctuation\">,</span>\n                            a<span class=\"token punctuation\">,</span>\n                            m<span class=\"token punctuation\">,</span>\n                            r<span class=\"token punctuation\">,</span>\n                            d<span class=\"token punctuation\">,</span>\n                            f<span class=\"token punctuation\">,</span>\n                            h<span class=\"token punctuation\">,</span>\n                            p <span class=\"token operator\">=</span> <span class=\"token function\">x</span><span class=\"token punctuation\">(</span><span class=\"token constant\">O</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            g <span class=\"token operator\">=</span> u\n                                <span class=\"token operator\">?</span> i\n                                <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                      <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                                      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>offsetParent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">+=</span> e<span class=\"token punctuation\">.</span>offsetTop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>offsetParent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                      <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">-</span> t <span class=\"token operator\">-</span> n<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token constant\">L</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> q<span class=\"token punctuation\">.</span>innerHeight<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">;</span>\n                                  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> p<span class=\"token punctuation\">,</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> s<span class=\"token punctuation\">.</span>offset <span class=\"token operator\">?</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">offset</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> s<span class=\"token punctuation\">.</span>offset<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">.</span>clip<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            y <span class=\"token operator\">=</span> g <span class=\"token operator\">-</span> l<span class=\"token punctuation\">,</span>\n                            v <span class=\"token operator\">=</span> <span class=\"token constant\">L</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            w <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token constant\">S</span> <span class=\"token operator\">=</span>\n                                <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>speedAsDuration <span class=\"token operator\">?</span> o<span class=\"token punctuation\">.</span>speed <span class=\"token operator\">:</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">1e3</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> o<span class=\"token punctuation\">.</span>speed<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                o<span class=\"token punctuation\">.</span>durationMax <span class=\"token operator\">&amp;&amp;</span> a <span class=\"token operator\">></span> o<span class=\"token punctuation\">.</span>durationMax <span class=\"token operator\">?</span> o<span class=\"token punctuation\">.</span>durationMax <span class=\"token operator\">:</span> o<span class=\"token punctuation\">.</span>durationMin <span class=\"token operator\">&amp;&amp;</span> a <span class=\"token operator\">&lt;</span> o<span class=\"token punctuation\">.</span>durationMin <span class=\"token operator\">?</span> o<span class=\"token punctuation\">.</span>durationMin <span class=\"token operator\">:</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token function-variable function\">E</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> n<span class=\"token punctuation\">,</span>\n                                    o<span class=\"token punctuation\">,</span>\n                                    a<span class=\"token punctuation\">,</span>\n                                    r <span class=\"token operator\">=</span> q<span class=\"token punctuation\">.</span>pageYOffset<span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">==</span> t <span class=\"token operator\">||</span> r <span class=\"token operator\">==</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">&lt;</span> t <span class=\"token operator\">&amp;&amp;</span> q<span class=\"token punctuation\">.</span>innerHeight <span class=\"token operator\">+</span> r<span class=\"token punctuation\">)</span> <span class=\"token operator\">>=</span> v<span class=\"token punctuation\">)</span>\n                                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                                        <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">cancelScroll</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> u<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token number\">0</span> <span class=\"token operator\">===</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        a <span class=\"token operator\">||</span>\n                                            <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            document<span class=\"token punctuation\">.</span>activeElement <span class=\"token operator\">!==</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tabindex'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'-1'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>outline <span class=\"token operator\">=</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            q<span class=\"token punctuation\">.</span><span class=\"token function\">scrollTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token constant\">H</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scrollStop'</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span> <span class=\"token operator\">=</span> m <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token function-variable function\">b</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">;</span>\n\n                                m <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span>w <span class=\"token operator\">+=</span> e <span class=\"token operator\">-</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span>\n                                        l <span class=\"token operator\">+</span>\n                                        y <span class=\"token operator\">*</span>\n                                            <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> r <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">===</span> <span class=\"token constant\">S</span> <span class=\"token operator\">?</span> <span class=\"token number\">0</span> <span class=\"token operator\">:</span> w <span class=\"token operator\">/</span> <span class=\"token constant\">S</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token number\">1</span> <span class=\"token operator\">:</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInQuad'</span> <span class=\"token operator\">===</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeOutQuad'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">-</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInOutQuad'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">&lt;</span> <span class=\"token number\">0.5</span> <span class=\"token operator\">?</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">-</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInCubic'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeOutCubic'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInOutCubic'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">&lt;</span> <span class=\"token number\">0.5</span> <span class=\"token operator\">?</span> <span class=\"token number\">4</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInQuart'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeOutQuart'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token operator\">-</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInOutQuart'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">&lt;</span> <span class=\"token number\">0.5</span> <span class=\"token operator\">?</span> <span class=\"token number\">8</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">:</span> <span class=\"token number\">1</span> <span class=\"token operator\">-</span> <span class=\"token number\">8</span> <span class=\"token operator\">*</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInQuint'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeOutQuint'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInOutQuint'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">&lt;</span> <span class=\"token number\">0.5</span> <span class=\"token operator\">?</span> <span class=\"token number\">16</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">:</span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">16</span> <span class=\"token operator\">*</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            t<span class=\"token punctuation\">.</span>customEasing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">customEasing</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            o <span class=\"token operator\">||</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    q<span class=\"token punctuation\">.</span><span class=\"token function\">scrollTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token constant\">E</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> g<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span> <span class=\"token operator\">=</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token number\">0</span> <span class=\"token operator\">===</span> q<span class=\"token punctuation\">.</span>pageYOffset <span class=\"token operator\">&amp;&amp;</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">scrollTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token punctuation\">(</span>h <span class=\"token operator\">=</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            u <span class=\"token operator\">||</span>\n                                <span class=\"token punctuation\">(</span>history<span class=\"token punctuation\">.</span>pushState <span class=\"token operator\">&amp;&amp;</span>\n                                    h<span class=\"token punctuation\">.</span>updateURL <span class=\"token operator\">&amp;&amp;</span>\n                                    history<span class=\"token punctuation\">.</span><span class=\"token function\">pushState</span><span class=\"token punctuation\">(</span>\n                                        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">smoothScroll</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>h<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">anchor</span><span class=\"token operator\">:</span> f<span class=\"token punctuation\">.</span>id <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                                        document<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">,</span>\n\n                                        f <span class=\"token operator\">===</span> document<span class=\"token punctuation\">.</span>documentElement <span class=\"token operator\">?</span> <span class=\"token string\">'#top'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'#'</span> <span class=\"token operator\">+</span> f<span class=\"token punctuation\">.</span>id\n                                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token string\">'matchMedia'</span> <span class=\"token keyword\">in</span> q <span class=\"token operator\">&amp;&amp;</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">matchMedia</span><span class=\"token punctuation\">(</span><span class=\"token string\">'(prefers-reduced-motion)'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>matches\n                                <span class=\"token operator\">?</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">scrollTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>g<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                                <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">H</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scrollStart'</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">cancelScroll</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">t</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">!</span>e<span class=\"token punctuation\">.</span>defaultPrevented <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span> <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">.</span>button <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>metaKey <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>ctrlKey <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>shiftKey<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token string\">'closest'</span> <span class=\"token keyword\">in</span> e<span class=\"token punctuation\">.</span>target <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token string\">'a'</span> <span class=\"token operator\">===</span> a<span class=\"token punctuation\">.</span>tagName<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token operator\">!</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>ignore<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                        a<span class=\"token punctuation\">.</span>hostname <span class=\"token operator\">===</span> q<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>hostname <span class=\"token operator\">&amp;&amp;</span>\n                        a<span class=\"token punctuation\">.</span>pathname <span class=\"token operator\">===</span> q<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>pathname <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">#</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>href<span class=\"token punctuation\">)</span>\n                    <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span>\n                            n <span class=\"token operator\">=</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>hash<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'#'</span> <span class=\"token operator\">===</span> n<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>topOnEmptyHash<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n                            t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t <span class=\"token operator\">||</span> <span class=\"token string\">'#top'</span> <span class=\"token operator\">!==</span> n <span class=\"token operator\">?</span> t <span class=\"token operator\">:</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                            <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>history<span class=\"token punctuation\">.</span>replaceState <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">.</span>updateURL <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> q<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>hash<span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        history<span class=\"token punctuation\">.</span><span class=\"token function\">replaceState</span><span class=\"token punctuation\">(</span>\n                                            <span class=\"token punctuation\">{</span>\n                                                <span class=\"token literal-property property\">smoothScroll</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                                <span class=\"token literal-property property\">anchor</span><span class=\"token operator\">:</span> t <span class=\"token operator\">||</span> q<span class=\"token punctuation\">.</span>pageYOffset\n                                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                                            document<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">,</span>\n\n                                            t <span class=\"token operator\">||</span> q<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>href\n                                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">animateScroll</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                <span class=\"token function-variable function\">n</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> history<span class=\"token punctuation\">.</span>state <span class=\"token operator\">&amp;&amp;</span> history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>smoothScroll <span class=\"token operator\">&amp;&amp;</span> history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>smoothScroll <span class=\"token operator\">===</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>anchor<span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token function\">r</span><span class=\"token punctuation\">(</span>history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>anchor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">animateScroll</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">updateURL</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">destroy</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token constant\">A</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'popstate'</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">cancelScroll</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">C</span> <span class=\"token operator\">=</span> <span class=\"token constant\">O</span> <span class=\"token operator\">=</span> a <span class=\"token operator\">=</span> <span class=\"token constant\">A</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token string\">'querySelector'</span> <span class=\"token keyword\">in</span> document <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'addEventListener'</span> <span class=\"token keyword\">in</span> q <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'requestAnimationFrame'</span> <span class=\"token keyword\">in</span> q <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'closest'</span> <span class=\"token keyword\">in</span> q<span class=\"token punctuation\">.</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token keyword\">throw</span> <span class=\"token string\">'Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.'</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">destroy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span><span class=\"token constant\">A</span> <span class=\"token operator\">=</span> <span class=\"token constant\">F</span><span class=\"token punctuation\">(</span><span class=\"token constant\">I</span><span class=\"token punctuation\">,</span> e <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span><span class=\"token constant\">O</span> <span class=\"token operator\">=</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>header <span class=\"token operator\">?</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>header<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        document<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>updateURL <span class=\"token operator\">&amp;&amp;</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>popstate <span class=\"token operator\">&amp;&amp;</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'popstate'</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token constant\">M</span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/*! gumshoejs v5.1.1 | (c) 2019 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/gumshoe */</span>\n\n<span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>closest <span class=\"token operator\">||</span>\n    <span class=\"token punctuation\">(</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>matches <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>matches <span class=\"token operator\">=</span> <span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>msMatchesSelector <span class=\"token operator\">||</span> <span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>webkitMatchesSelector<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">closest</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">do</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">matches</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n            e <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentElement<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>CustomEvent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            e <span class=\"token operator\">=</span> e <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">bubbles</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cancelable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">detail</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createEvent</span><span class=\"token punctuation\">(</span><span class=\"token string\">'CustomEvent'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">initCustomEvent</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>bubbles<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>cancelable<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>detail<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token class-name\">Event</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>CustomEvent <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> define <span class=\"token operator\">&amp;&amp;</span> define<span class=\"token punctuation\">.</span>amd\n            <span class=\"token operator\">?</span> <span class=\"token function\">define</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                  <span class=\"token keyword\">return</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n              <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">:</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports\n            <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>Gumshoe <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> global <span class=\"token operator\">?</span> global <span class=\"token operator\">:</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> window <span class=\"token operator\">?</span> window <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">navClass</span><span class=\"token operator\">:</span> <span class=\"token string\">'active'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">contentClass</span><span class=\"token operator\">:</span> <span class=\"token string\">'active'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">nested</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">nestedClass</span><span class=\"token operator\">:</span> <span class=\"token string\">'active'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">offset</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">reflow</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">events</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">n</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>settings<span class=\"token punctuation\">.</span>events<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">CustomEvent</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">bubbles</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">cancelable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">detail</span><span class=\"token operator\">:</span> n\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    e<span class=\"token punctuation\">.</span><span class=\"token function\">dispatchEvent</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">o</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>offsetParent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> t<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">+=</span> t<span class=\"token punctuation\">.</span>offsetTop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>offsetParent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> e <span class=\"token operator\">>=</span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> e <span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">s</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                t <span class=\"token operator\">&amp;&amp;</span>\n                    t<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">c</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getBoundingClientRect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    c <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>offset <span class=\"token operator\">?</span> <span class=\"token function\">parseFloat</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span><span class=\"token function\">offset</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token function\">parseFloat</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>offset<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> o <span class=\"token operator\">?</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>bottom<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>innerHeight <span class=\"token operator\">||</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>clientHeight<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>top<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;=</span> c<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">r</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    t<span class=\"token punctuation\">.</span>innerHeight <span class=\"token operator\">+</span> t<span class=\"token punctuation\">.</span>pageYOffset <span class=\"token operator\">>=</span>\n                    Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>\n                        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>scrollHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>scrollHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>clientHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>clientHeight\n                    <span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">i</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> t<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token function\">c</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">)</span>\n                    <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> o <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> o<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">c</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">l</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nested<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nestedClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">l</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">a</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>nav<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    o <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>navClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>contentClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token function\">l</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token string\">'gumshoeDeactivate'</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">link</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">.</span>nav<span class=\"token punctuation\">,</span>\n\n                            <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span>\n\n                            <span class=\"token literal-property property\">settings</span><span class=\"token operator\">:</span> e\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">u</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nested<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nestedClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">u</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">o<span class=\"token punctuation\">,</span> c</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> r<span class=\"token punctuation\">,</span>\n                l<span class=\"token punctuation\">,</span>\n                f<span class=\"token punctuation\">,</span>\n                d<span class=\"token punctuation\">,</span>\n                m<span class=\"token punctuation\">,</span>\n                v <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">setup</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token function\">decodeURIComponent</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>hash<span class=\"token punctuation\">.</span><span class=\"token function\">substr</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        e <span class=\"token operator\">&amp;&amp;</span> l<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">nav</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> e <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token function\">s</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">detect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token function\">i</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    t\n                        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>f <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>content <span class=\"token operator\">===</span> f<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span>\n                          <span class=\"token punctuation\">(</span><span class=\"token function\">a</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                          <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                  <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>nav<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                  o <span class=\"token operator\">&amp;&amp;</span>\n                                      <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>navClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                      t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>contentClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                      <span class=\"token function\">u</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                      <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token string\">'gumshoeActivate'</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                          <span class=\"token literal-property property\">link</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">.</span>nav<span class=\"token punctuation\">,</span>\n\n                                          <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span>\n\n                                          <span class=\"token literal-property property\">settings</span><span class=\"token operator\">:</span> e\n                                      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                              <span class=\"token punctuation\">}</span>\n                          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                          <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token operator\">:</span> f <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token function\">a</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">p</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    d <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">cancelAnimationFrame</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">.</span>detect<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                <span class=\"token function-variable function\">h</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    d <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">cancelAnimationFrame</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token function\">s</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> v<span class=\"token punctuation\">.</span><span class=\"token function\">detect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            v<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">destroy</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                f <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">a</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    t<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scroll'</span><span class=\"token punctuation\">,</span> p<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    m<span class=\"token punctuation\">.</span>reflow <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'resize'</span><span class=\"token punctuation\">,</span> h<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> n <span class=\"token keyword\">in</span> e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n                                t<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> e<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        t\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> c <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                v<span class=\"token punctuation\">.</span><span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                v<span class=\"token punctuation\">.</span><span class=\"token function\">detect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                t<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scroll'</span><span class=\"token punctuation\">,</span> p<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                m<span class=\"token punctuation\">.</span>reflow <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'resize'</span><span class=\"token punctuation\">,</span> h<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                v\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/*!\n\n * clipboard.js v2.0.4\n\n * https://zenorocha.github.io/clipboard.js\n\n *\n\n * Licensed MIT © Zeno Rocha\n\n */</span>\n\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> module\n        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> define <span class=\"token operator\">&amp;&amp;</span> define<span class=\"token punctuation\">.</span>amd\n        <span class=\"token operator\">?</span> <span class=\"token function\">define</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports\n        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>exports<span class=\"token punctuation\">.</span>ClipboardJS <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>ClipboardJS <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">i</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">l</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">exports</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>l <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>m <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>c <span class=\"token operator\">=</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">d</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                r<span class=\"token punctuation\">.</span><span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">enumerable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">get</span><span class=\"token operator\">:</span> n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">r</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span>\n                    Symbol<span class=\"token punctuation\">.</span>toStringTag <span class=\"token operator\">&amp;&amp;</span>\n                    Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> Symbol<span class=\"token punctuation\">.</span>toStringTag<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">'Module'</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token string\">'__esModule'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">t</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span> <span class=\"token operator\">&amp;</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> e <span class=\"token operator\">&amp;&amp;</span> e <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">.</span>__esModule<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function\">r</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> <span class=\"token string\">'default'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">enumerable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> e\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token number\">2</span> <span class=\"token operator\">&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> e<span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">)</span>\n                    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token keyword\">in</span> e<span class=\"token punctuation\">)</span>\n                        r<span class=\"token punctuation\">.</span><span class=\"token function\">d</span><span class=\"token punctuation\">(</span>\n                            n<span class=\"token punctuation\">,</span>\n\n                            o<span class=\"token punctuation\">,</span>\n\n                            <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span>\n                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">n</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span>\n                    t <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>__esModule\n                        <span class=\"token operator\">?</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> r<span class=\"token punctuation\">.</span><span class=\"token function\">d</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">o</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>p <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>s <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span>\n                    <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'symbol'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol<span class=\"token punctuation\">.</span>iterator\n                        <span class=\"token operator\">?</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">===</span> Symbol <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">!==</span> <span class=\"token class-name\">Symbol</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">?</span> <span class=\"token string\">'symbol'</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                i <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> n <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> n<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> e<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>enumerable <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span>enumerable <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>configurable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span> <span class=\"token keyword\">in</span> o <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>writable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span>key<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                a <span class=\"token operator\">=</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                c <span class=\"token operator\">=</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                u <span class=\"token operator\">=</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> t <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>__esModule <span class=\"token operator\">?</span> t <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">default</span><span class=\"token operator\">:</span> t <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token keyword\">var</span> l <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>t <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">e</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Cannot call a class as a function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>t<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ReferenceError</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"this hasn't been initialised - super() hasn't been called\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span>e <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'object'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> e<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> t <span class=\"token operator\">:</span> e<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>__proto__ <span class=\"token operator\">||</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">getPrototypeOf</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">resolveOptions</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">listenClick</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Super expression must either be null or a function, not '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">typeof</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>e <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">constructor</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">enumerable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">writable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">configurable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span>setPrototypeOf <span class=\"token operator\">?</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">setPrototypeOf</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>__proto__ <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token function\">i</span><span class=\"token punctuation\">(</span>\n                        o<span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">[</span>\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'resolveOptions'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action <span class=\"token operator\">=</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>action <span class=\"token operator\">?</span> t<span class=\"token punctuation\">.</span>action <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>defaultAction<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>target <span class=\"token operator\">=</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>target <span class=\"token operator\">?</span> t<span class=\"token punctuation\">.</span>target <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>defaultTarget<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text <span class=\"token operator\">=</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>text <span class=\"token operator\">?</span> t<span class=\"token punctuation\">.</span>text <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>defaultText<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container <span class=\"token operator\">=</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">===</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> t<span class=\"token punctuation\">.</span>container <span class=\"token operator\">:</span> document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'listenClick'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>listener <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                        <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">onClick</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'onClick'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>delegateTarget <span class=\"token operator\">||</span> t<span class=\"token punctuation\">.</span>currentTarget<span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">a<span class=\"token punctuation\">.</span>default</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                                            <span class=\"token literal-property property\">action</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">action</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">target</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">text</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">container</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">trigger</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">emitter</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span>\n                                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'defaultAction'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">return</span> <span class=\"token function\">s</span><span class=\"token punctuation\">(</span><span class=\"token string\">'action'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'defaultTarget'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token function\">s</span><span class=\"token punctuation\">(</span><span class=\"token string\">'target'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'defaultText'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">return</span> <span class=\"token function\">s</span><span class=\"token punctuation\">(</span><span class=\"token string\">'text'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'destroy'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>listener<span class=\"token punctuation\">.</span><span class=\"token function\">destroy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction<span class=\"token punctuation\">.</span><span class=\"token function\">destroy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">[</span>\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'isSupported'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'copy'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cut'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                                        e <span class=\"token operator\">=</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t <span class=\"token operator\">?</span> <span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span>\n                                        n <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>document<span class=\"token punctuation\">.</span>queryCommandSupported<span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                                        e<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                            n <span class=\"token operator\">=</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>document<span class=\"token punctuation\">.</span><span class=\"token function\">queryCommandSupported</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        n\n                                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    o\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">function</span> <span class=\"token function\">s</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token string\">'data-clipboard-'</span> <span class=\"token operator\">+</span> t<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            t<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> l<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> o<span class=\"token punctuation\">,</span>\n                r <span class=\"token operator\">=</span>\n                    <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'symbol'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol<span class=\"token punctuation\">.</span>iterator\n                        <span class=\"token operator\">?</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">===</span> Symbol <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">!==</span> <span class=\"token class-name\">Symbol</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">?</span> <span class=\"token string\">'symbol'</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                i <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> n <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> n<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> e<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>enumerable <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span>enumerable <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>configurable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span> <span class=\"token keyword\">in</span> o <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>writable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span>key<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                a <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                c <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> a<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> o<span class=\"token punctuation\">.</span>__esModule <span class=\"token operator\">?</span> o <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">default</span><span class=\"token operator\">:</span> o <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> u <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">function</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>t <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">e</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Cannot call a class as a function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">resolveOptions</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">initSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token function\">i</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'resolveOptions'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>action<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>emitter <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>emitter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>target <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>trigger <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>trigger<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>selectedText <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'initSelection'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text <span class=\"token operator\">?</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">selectFake</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>target <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">selectTarget</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'selectFake'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span>\n                                    e <span class=\"token operator\">=</span> <span class=\"token string\">'rtl'</span> <span class=\"token operator\">==</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'dir'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeFake</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">fakeHandlerCallback</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                        <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">removeFake</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandler <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandlerCallback<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'textarea'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>fontSize <span class=\"token operator\">=</span> <span class=\"token string\">'12pt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>border <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>padding <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>margin <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>position <span class=\"token operator\">=</span> <span class=\"token string\">'absolute'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">[</span>e <span class=\"token operator\">?</span> <span class=\"token string\">'right'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'left'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'-9999px'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span>pageYOffset <span class=\"token operator\">||</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>scrollTop<span class=\"token punctuation\">;</span>\n\n                                <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>top <span class=\"token operator\">=</span> n <span class=\"token operator\">+</span> <span class=\"token string\">'px'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>selectedText <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">copyText</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'removeFake'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandler <span class=\"token operator\">&amp;&amp;</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandlerCallback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandler <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandlerCallback <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'selectTarget'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>selectedText <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">copyText</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'copyText'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n                                    e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">execCommand</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    e <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleResult</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'handleResult'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>emitter<span class=\"token punctuation\">.</span><span class=\"token function\">emit</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">?</span> <span class=\"token string\">'success'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'error'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token literal-property property\">action</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action<span class=\"token punctuation\">,</span>\n\n                                    <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>selectedText<span class=\"token punctuation\">,</span>\n\n                                    <span class=\"token literal-property property\">trigger</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>trigger<span class=\"token punctuation\">,</span>\n\n                                    <span class=\"token literal-property property\">clearSelection</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">clearSelection</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span>\n                                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'clearSelection'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>trigger <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>trigger<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">getSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeAllRanges</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'destroy'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeFake</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'action'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">set</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token string\">'copy'</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_action <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'copy'</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_action <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'cut'</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_action<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                                    <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Invalid \"action\" value, use either \"copy\" or \"cut\"'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">get</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_action<span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'target'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">set</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>t <span class=\"token operator\">||</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">!==</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">===</span> t <span class=\"token operator\">?</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">:</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token number\">1</span> <span class=\"token operator\">!==</span> t<span class=\"token punctuation\">.</span>nodeType<span class=\"token punctuation\">)</span>\n                                        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Invalid \"target\" value, use a valid Element'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'copy'</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'disabled'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                                        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Invalid \"target\" attribute. Please use \"readonly\" instead of \"disabled\" attribute'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'cut'</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'disabled'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                                        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span>\n                                            <span class=\"token string\">'Invalid \"target\" attribute. You can\\'t cut text from elements with \"readonly\" or \"disabled\" attributes'</span>\n                                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_target <span class=\"token operator\">=</span> t<span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">get</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_target<span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    e\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            t<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> u<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            t<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> e<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'SELECT'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">)</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'INPUT'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>nodeName <span class=\"token operator\">||</span> <span class=\"token string\">'TEXTAREA'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    n <span class=\"token operator\">||</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">select</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">setSelectionRange</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">||</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">removeAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'contenteditable'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">getSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        r <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createRange</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    r<span class=\"token punctuation\">.</span><span class=\"token function\">selectNodeContents</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span><span class=\"token function\">removeAllRanges</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span><span class=\"token function\">addRange</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">function</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n            <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token function-variable function\">on</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">fn</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">ctx</span><span class=\"token operator\">:</span> n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">once</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        o<span class=\"token punctuation\">.</span><span class=\"token function\">off</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">e</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>_ <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">emit</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> r <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> o <span class=\"token operator\">&lt;</span> r<span class=\"token punctuation\">;</span> o<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span>\n                        n<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">fn</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>ctx<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">off</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        o <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        r <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> a <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> a<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> o<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fn <span class=\"token operator\">!==</span> e <span class=\"token operator\">&amp;&amp;</span> o<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fn<span class=\"token punctuation\">.</span>_ <span class=\"token operator\">!==</span> e <span class=\"token operator\">&amp;&amp;</span> r<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> r<span class=\"token punctuation\">.</span>length <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> r<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">delete</span> n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> d <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                h <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            t<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>n<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Missing required arguments'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">string</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Second argument must be a String'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Third argument must be a Function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">node</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token punctuation\">(</span>s <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>l <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token function-variable function\">destroy</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                l<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">nodeList</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>c <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>u <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            t<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token function-variable function\">destroy</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    t<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">string</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">h</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'First argument must be a String, HTMLElement, HTMLCollection, or NodeList'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">var</span> o<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">node</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">HTMLElement</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">1</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>nodeType<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">nodeList</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'[object NodeList]'</span> <span class=\"token operator\">===</span> e <span class=\"token operator\">||</span> <span class=\"token string\">'[object HTMLCollection]'</span> <span class=\"token operator\">===</span> e<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'length'</span> <span class=\"token keyword\">in</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>length <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">node</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">string</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t <span class=\"token operator\">||</span> t <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">String</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">fn</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token string\">'[object Function]'</span> <span class=\"token operator\">===</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">function</span> <span class=\"token function\">i</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">i</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> o</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>delegateTarget <span class=\"token operator\">=</span> <span class=\"token function\">a</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>delegateTarget <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    t<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">{</span>\n                        <span class=\"token function-variable function\">destroy</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            t<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            t<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>addEventListener\n                    <span class=\"token operator\">?</span> <span class=\"token function\">i</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span>\n                    <span class=\"token operator\">:</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> n\n                    <span class=\"token operator\">?</span> <span class=\"token function\">i</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span>\n                    <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                      <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                          <span class=\"token keyword\">return</span> <span class=\"token function\">i</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> Element <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>matches<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">;</span>\n\n                n<span class=\"token punctuation\">.</span>matches <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>matchesSelector <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span>mozMatchesSelector <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span>msMatchesSelector <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span>oMatchesSelector <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span>webkitMatchesSelector<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            t<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">9</span> <span class=\"token operator\">!==</span> t<span class=\"token punctuation\">.</span>nodeType<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>matches <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">matches</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">;</span>\n\n                    t <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<h1>Prism.js</h1>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  ```js</code></pre></div>\n<p>//</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">  /* PrismJS 1.16.0</code></pre></div>\n<p><a href=\"https://prismjs.com/download.html#themes=prism&#x26;languages=markup+css+clike+javascript&#x26;plugins=toolbar+copy-to-clipboard\">https://prismjs.com/download.html#themes=prism&#x26;languages=markup+css+clike+javascript&#x26;plugins=toolbar+copy-to-clipboard</a> _/</p>\n<p>var _self = 'undefined' != typeof window ? window : 'undefined' != typeof WorkerGlobalScope &#x26;&#x26; self instanceof WorkerGlobalScope ? self : {},</p>\n<p>Prism = (function (g) {</p>\n<p>var c = /\\blang(?:uage)?-([\\w-]+)\\b/i,</p>\n<p>a = 0,</p>\n<p>C = {</p>\n<p>manual: g.Prism &#x26;&#x26; g.Prism.manual,</p>\n<p>disableWorkerMessageHandler: g.Prism &#x26;&#x26; g.Prism.disableWorkerMessageHandler,</p>\n<p>util: {</p>\n<p>encode: function (e) {</p>\n<p>return e instanceof M</p>\n<p>? new M(e.type, C.util.encode(e.content), e.alias)</p>\n<p>: Array.isArray(e)</p>\n<p>? e.map(C.util.encode)</p>\n<p>: e</p>\n<p>.replace(/&#x26;/g, '&#x26;')</p>\n<p>.replace(/&#x3C;/g, '&#x3C;')</p>\n<p>.replace(/\\u00a0/g, ' ');</p>\n<p>},</p>\n<p>type: function (e) {</p>\n<p>return Object.prototype.toString.call(e).slice(8, -1);</p>\n<p>},</p>\n<p>objId: function (e) {</p>\n<p>return e.<strong>id || Object.defineProperty(e, '</strong>id', { value: ++a }), e.__id;</p>\n<p>},</p>\n<p>clone: function n(e, t) {</p>\n<p>var r,</p>\n<p>a,</p>\n<p>i = C.util.type(e);</p>\n<p>switch (((t = t || {}), i)) {</p>\n<p>case 'Object':</p>\n<p>if (((a = C.util.objId(e)), t[a])) return t[a];</p>\n<p>for (var l in ((r = {}), (t[a] = r), e)) e.hasOwnProperty(l) &#x26;&#x26; (r[l] = n(e[l], t));</p>\n<p>return r;</p>\n<p>case 'Array':</p>\n<p>return (</p>\n<p>(a = C.util.objId(e)),</p>\n<p>t[a]</p>\n<p>? t[a]</p>\n<p>: ((r = []),</p>\n<p>(t[a] = r),</p>\n<p>e.forEach(function (e, a) {</p>\n<p>r[a] = n(e, t);</p>\n<p>}),</p>\n<p>r)</p>\n<p>);</p>\n<p>default:</p>\n<p>return e;</p>\n<p>}</p>\n<p>}</p>\n<p>},</p>\n<p>languages: {</p>\n<p>extend: function (e, a) {</p>\n<p>var n = C.util.clone(C.languages[e]);</p>\n<p>for (var t in a) n[t] = a[t];</p>\n<p>return n;</p>\n<p>},</p>\n<p>insertBefore: function (n, e, a, t) {</p>\n<p>var r = <a href=\"n\">t = t || C.languages</a>,</p>\n<p>i = {};</p>\n<p>for (var l in r)</p>\n<p>if (r.hasOwnProperty(l)) {</p>\n<p>if (l == e) for (var o in a) a.hasOwnProperty(o) &#x26;&#x26; (i[o] = a[o]);</p>\n<p>a.hasOwnProperty(l) || (i[l] = r[l]);</p>\n<p>}</p>\n<p>var s = t[n];</p>\n<p>return (</p>\n<p>(t[n] = i),</p>\n<p>C.languages.DFS(C.languages, function (e, a) {</p>\n<p>a === s &#x26;&#x26; e != n &#x26;&#x26; (this[e] = i);</p>\n<p>}),</p>\n<p>i</p>\n<p>);</p>\n<p>},</p>\n<p>DFS: function e(a, n, t, r) {</p>\n<p>r = r || {};</p>\n<p>var i = C.util.objId;</p>\n<p>for (var l in a)</p>\n<p>if (a.hasOwnProperty(l)) {</p>\n<p>n.call(a, l, a[l], t || l);</p>\n<p>var o = a[l],</p>\n<p>s = C.util.type(o);</p>\n<p>'Object' !== s || r[i(o)] ? 'Array' !== s || r[i(o)] || ((r[i(o)] = !0), e(o, n, l, r)) : ((r[i(o)] = !0), e(o, n, null, r));</p>\n<p>}</p>\n<p>}</p>\n<p>},</p>\n<p>plugins: {},</p>\n<p>highlightAll: function (e, a) {</p>\n<p>C.highlightAllUnder(document, e, a);</p>\n<p>},</p>\n<p>highlightAllUnder: function (e, a, n) {</p>\n<p>var t = {</p>\n<p>callback: n,</p>\n<p>selector: 'code[class_=\"language-\"], [class*=\"language-\"] code, code[class*=\"lang-\"], [class*=\"lang-\"] code'</p>\n<p>};</p>\n<p>C.hooks.run('before-highlightall', t);</p>\n<p>for (var r, i = t.elements || e.querySelectorAll(t.selector), l = 0; (r = i[l++]); ) C.highlightElement(r, !0 === a, t.callback);</p>\n<p>},</p>\n<p>highlightElement: function (e, a, n) {</p>\n<p>for (var t, r = 'none', i = e; i &#x26;&#x26; !c.test(i.className); ) i = i.parentNode;</p>\n<p>i &#x26;&#x26; ((r = (i.className.match(c) || [, 'none'])[1].toLowerCase()), (t = C.languages[r])),</p>\n<p>(e.className = e.className.replace(c, '').replace(/\\s+/g, ' ') + ' language-' + r),</p>\n<p>e.parentNode &#x26;&#x26;</p>\n<p>((i = e.parentNode), /pre/i.test(i.nodeName) &#x26;&#x26; (i.className = i.className.replace(c, '').replace(/\\s+/g, ' ') + ' language-' + r));</p>\n<p>var l = { element: e, language: r, grammar: t, code: e.textContent },</p>\n<p>o = function (e) {</p>\n<p>(l.highlightedCode = e),</p>\n<p>C.hooks.run('before-insert', l),</p>\n<p>(l.element.innerHTML = l.highlightedCode),</p>\n<p>C.hooks.run('after-highlight', l),</p>\n<p>C.hooks.run('complete', l),</p>\n<p>n &#x26;&#x26; n.call(l.element);</p>\n<p>};</p>\n<p>if ((C.hooks.run('before-sanity-check', l), l.code))</p>\n<p>if ((C.hooks.run('before-highlight', l), l.grammar))</p>\n<p>if (a &#x26;&#x26; g.Worker) {</p>\n<p>var s = new Worker(C.filename);</p>\n<p>(s.onmessage = function (e) {</p>\n<p>o(e.data);</p>\n<p>}),</p>\n<p>s.postMessage(</p>\n<p>JSON.stringify({</p>\n<p>language: l.language,</p>\n<p>code: l.code,</p>\n<p>immediateClose: !0</p>\n<p>})</p>\n<p>);</p>\n<p>} else o(C.highlight(l.code, l.grammar, l.language));</p>\n<p>else o(C.util.encode(l.code));</p>\n<p>else C.hooks.run('complete', l);</p>\n<p>},</p>\n<p>highlight: function (e, a, n) {</p>\n<p>var t = { code: e, grammar: a, language: n };</p>\n<p>return (</p>\n<p>C.hooks.run('before-tokenize', t),</p>\n<p>(t.tokens = C.tokenize(t.code, t.grammar)),</p>\n<p>C.hooks.run('after-tokenize', t),</p>\n<p>M.stringify(C.util.encode(t.tokens), t.language)</p>\n<p>);</p>\n<p>},</p>\n<p>matchGrammar: function (e, a, n, t, r, i, l) {</p>\n<p>for (var o in n)</p>\n<p>if (n.hasOwnProperty(o) &#x26;&#x26; n[o]) {</p>\n<p>if (o == l) return;</p>\n<p>var s = n[o];</p>\n<p>s = 'Array' === C.util.type(s) ? s : [s];</p>\n<p>for (var g = 0; g &#x3C; s.length; ++g) {</p>\n<p>var c = s[g],</p>\n<p>u = c.inside,</p>\n<p>h = !!c.lookbehind,</p>\n<p>f = !!c.greedy,</p>\n<p>d = 0,</p>\n<p>m = c.alias;</p>\n<p>if (f &#x26;&#x26; !c.pattern.global) {</p>\n<p>var p = c.pattern.toString().match<a href=\"0\">/[imuy]_$/</a>;</p>\n<p>c.pattern = RegExp(c.pattern.source, p + 'g');</p>\n<p>}</p>\n<p>c = c.pattern || c;</p>\n<p>for (var y = t, v = r; y &#x3C; a.length; v += a[y].length, ++y) {</p>\n<p>var k = a[y];</p>\n<p>if (a.length > e.length) return;</p>\n<p>if (!(k instanceof M)) {</p>\n<p>if (f &#x26;&#x26; y != a.length - 1) {</p>\n<p>if (((c.lastIndex = v), !(x = c.exec(e)))) break;</p>\n<p>for (</p>\n<p>var b = x.index + (h ? x[1].length : 0), w = x.index + x[0].length, A = y, P = v, O = a.length;</p>\n<p>A &#x3C; O &#x26;&#x26; (P &#x3C; w || (!a[A].type &#x26;&#x26; !a[A - 1].greedy));</p>\n<p>++A</p>\n<p>)</p>\n<p>(P += a[A].length) &#x3C;= b &#x26;&#x26; (++y, (v = P));</p>\n<p>if (a[y] instanceof M) continue;</p>\n<p>(N = A - y), (k = e.slice(v, P)), (x.index -= v);</p>\n<p>} else {</p>\n<p>c.lastIndex = 0;</p>\n<p>var x = c.exec(k),</p>\n<p>N = 1;</p>\n<p>}</p>\n<p>if (x) {</p>\n<p>h &#x26;&#x26; (d = x[1] ? x[1].length : 0);</p>\n<p>w = (b = x.index + d) + (x = x[0].slice(d)).length;</p>\n<p>var j = k.slice(0, b),</p>\n<p>S = k.slice(w),</p>\n<p>E = [y, N];</p>\n<p>j &#x26;&#x26; (++y, (v += j.length), E.push(j));</p>\n<p>var * = new M(o, u ? C.tokenize(x, u) : x, m, x, f);</p>\n<p>if (</p>\n<p>(E.push(*),</p>\n<p>S &#x26;&#x26; E.push(S),</p>\n<p>Array.prototype.splice.apply(a, E),</p>\n<p>1 != N &#x26;&#x26; C.matchGrammar(e, a, n, y, v, !0, o),</p>\n<p>i)</p>\n<p>)</p>\n<p>break;</p>\n<p>} else if (i) break;</p>\n<p>}</p>\n<p>}</p>\n<p>}</p>\n<p>}</p>\n<p>},</p>\n<p>tokenize: function (e, a) {</p>\n<p>var n = [e],</p>\n<p>t = a.rest;</p>\n<p>if (t) {</p>\n<p>for (var r in t) a[r] = t[r];</p>\n<p>delete a.rest;</p>\n<p>}</p>\n<p>return C.matchGrammar(e, n, a, 0, 0, !1), n;</p>\n<p>},</p>\n<p>hooks: {</p>\n<p>all: {},</p>\n<p>add: function (e, a) {</p>\n<p>var n = C.hooks.all;</p>\n<p>(n[e] = n[e] || []), n[e].push(a);</p>\n<p>},</p>\n<p>run: function (e, a) {</p>\n<p>var n = C.hooks.all[e];</p>\n<p>if (n &#x26;&#x26; n.length) for (var t, r = 0; (t = n[r++]); ) t(a);</p>\n<p>}</p>\n<p>},</p>\n<p>Token: M</p>\n<p>};</p>\n<p>function M(e, a, n, t, r) {</p>\n<p>(this.type = e), (this.content = a), (this.alias = n), (this.length = 0 | (t || '').length), (this.greedy = !!r);</p>\n<p>}</p>\n<p>if (</p>\n<p>((g.Prism = C),</p>\n<p>(M.stringify = function (e, a) {</p>\n<p>if ('string' == typeof e) return e;</p>\n<p>if (Array.isArray(e))</p>\n<p>return e</p>\n<p>.map(function (e) {</p>\n<p>return M.stringify(e, a);</p>\n<p>})</p>\n<p>.join('');</p>\n<p>var n = {</p>\n<p>type: e.type,</p>\n<p>content: M.stringify(e.content, a),</p>\n<p>tag: 'span',</p>\n<p>classes: ['token', e.type],</p>\n<p>attributes: {},</p>\n<p>language: a</p>\n<p>};</p>\n<p>if (e.alias) {</p>\n<p>var t = Array.isArray(e.alias) ? e.alias : [e.alias];</p>\n<p>Array.prototype.push.apply(n.classes, t);</p>\n<p>}</p>\n<p>C.hooks.run('wrap', n);</p>\n<p>var r = Object.keys(n.attributes)</p>\n<p>.map(function (e) {</p>\n<p>return e + '=\"' + (n.attributes[e] || '').replace(/\"/g, '\"') + '\"';</p>\n<p>})</p>\n<p>.join(' ');</p>\n<p>return '&#x3C;' + n.tag + ' class=\"' + n.classes.join(' ') + '\"' + (r ? ' ' + r : '') + '>' + n.content + '&#x3C;/' + n.tag + '>';</p>\n<p>}),</p>\n<p>!g.document)</p>\n<p>)</p>\n<p>return (</p>\n<p>g.addEventListener &#x26;&#x26;</p>\n<p>(C.disableWorkerMessageHandler ||</p>\n<p>g.addEventListener(</p>\n<p>'message',</p>\n<p>function (e) {</p>\n<p>var a = JSON.parse(e.data),</p>\n<p>n = a.language,</p>\n<p>t = a.code,</p>\n<p>r = a.immediateClose;</p>\n<p>g.postMessage(C.highlight(t, C.languages[n], n)), r &#x26;&#x26; g.close();</p>\n<p>},</p>\n<p>!1</p>\n<p>)),</p>\n<p>C</p>\n<p>);</p>\n<p>var e = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop();</p>\n<p>return (</p>\n<p>e &#x26;&#x26;</p>\n<p>((C.filename = e.src),</p>\n<p>C.manual ||</p>\n<p>e.hasAttribute('data-manual') ||</p>\n<p>('loading' !== document.readyState</p>\n<p>? window.requestAnimationFrame</p>\n<p>? window.requestAnimationFrame(C.highlightAll)</p>\n<p>: window.setTimeout(C.highlightAll, 16)</p>\n<p>: document.addEventListener('DOMContentLoaded', C.highlightAll))),</p>\n<p>C</p>\n<p>);</p>\n<p>})(_self);</p>\n<p>'undefined' != typeof module &#x26;&#x26; module.exports &#x26;&#x26; (module.exports = Prism), 'undefined' != typeof global &#x26;&#x26; (global.Prism = Prism);</p>\n<p>(Prism.languages.markup = {</p>\n<p>comment: /<!--[\\s\\S]_?-->/,</p>\n<p>prolog: /&#x3C;?[\\s\\S]+??>/,</p>\n<p>doctype: /&#x3C;!DOCTYPE[\\s\\S]+?>/i,</p>\n<p>cdata: /&#x3C;![CDATA[[\\s\\S]_?]]>/i,</p>\n<p>tag: {</p>\n<p>pattern: /&#x3C;/?(?!\\d)<sup id=\"fnref-\\s>\\/=$<%\"><a href=\"#fn-\\s>\\/=$<%\" class=\"footnote-ref\">\\s>\\/=$&#x3C;%</a></sup>+(?:\\s(?:\\s<em><sup id=\"fnref-\\s>\\/=\"><a href=\"#fn-\\s>\\/=\" class=\"footnote-ref\">\\s>\\/=</a></sup>+(?:\\s</em>=\\s<em>(?:\"<sup id=\"fnref-&#x22;\"><a href=\"#fn-&#x22;\" class=\"footnote-ref\">\"</a></sup></em>\"|'<sup id=\"fnref-&#x27;\"><a href=\"#fn-&#x27;\" class=\"footnote-ref\">'</a></sup>_'|<sup id=\"fnref-\\s&#x27;&#x22;>=\"><a href=\"#fn-\\s&#x27;&#x22;>=\" class=\"footnote-ref\">\\s'\">=</a></sup>+(?=[\\s>]))|(?=[\\s/>])))+)?\\s*/?>/i,</p>\n<p>greedy: !0,</p>\n<p>inside: {</p>\n<p>tag: {</p>\n<p>pattern: /^&#x3C;/?<sup id=\"fnref-\\s>\\/\"><a href=\"#fn-\\s>\\/\" class=\"footnote-ref\">\\s>\\/</a></sup>+/i,</p>\n<p>inside: { punctuation: /^&#x3C;/?/, namespace: /^<sup id=\"fnref-\\s>\\/:\"><a href=\"#fn-\\s>\\/:\" class=\"footnote-ref\">\\s>\\/:</a></sup>+:/ }</p>\n<p>},</p>\n<p>'attr-value': {</p>\n<p>pattern: /=\\s*(?:\"<sup id=\"fnref-&#x22;\"><a href=\"#fn-&#x22;\" class=\"footnote-ref\">\"</a></sup><em>\"|'<sup id=\"fnref-&#x27;\"><a href=\"#fn-&#x27;\" class=\"footnote-ref\">'</a></sup></em>'|<sup id=\"fnref-\\s&#x27;&#x22;>=\"><a href=\"#fn-\\s&#x27;&#x22;>=\" class=\"footnote-ref\">\\s'\">=</a></sup>+)/i,</p>\n<p>inside: {</p>\n<p>punctuation: [/^=/, { pattern: /^<a href=\"%22&#x27;\">\\s*</a>|[\"']$/, lookbehind: !0 }]</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">            }\n\n        },\n\n        punctuation: /\\/?>/,\n\n        'attr-name': {\n\n            pattern: /[^\\s>\\/]+/,\n\n            inside: { namespace: /^[^\\s>\\/:]+:/ }\n\n        }\n\n    }\n\n},\n\nentity: /&amp;#?[\\da-z]{1,8};/i</code></pre></div>\n<p>}),</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">(Prism.languages.markup.tag.inside['attr-value'].inside.entity = Prism.languages.markup.entity),\n\nPrism.hooks.add('wrap', function (a) {\n\n    'entity' === a.type &amp;&amp; (a.attributes.title = a.content.replace(/&amp;amp;/, '&amp;'));\n\n}),\n\nObject.defineProperty(Prism.languages.markup.tag, 'addInlined', {\n\n    value: function (a, e) {\n\n        var s = {};\n\n        (s['language-' + e] = {\n\n            pattern: /(^&lt;!\\[CDATA\\[)[\\s\\S]+?(?=\\]\\]>$)/i,</code></pre></div>\n<p>lookbehind: !0,</p>\n<p>inside: Prism.languages[e]</p>\n<p>}),</p>\n<p>(s.cdata = /^&#x3C;![CDATA[|]]>$/i);</p>\n<p>var n = {</p>\n<p>'included-cdata': { pattern: /&#x3C;![CDATA[[\\s\\S]*?]]>/i, inside: s }</p>\n<p>};</p>\n<p>n['language-' + e] = { pattern: /[\\s\\S]+/, inside: Prism.languages[e] };</p>\n<p>var i = {};</p>\n<p>(i[a] = {</p>\n<p>pattern: RegExp('(&#x3C;<strong>[\\s\\S]<em>?>)(?:&#x3C;!\\[CDATA\\[[\\s\\S]</em>?\\]\\]>\\s<em>|[\\s\\S])</em>?(?=&#x3C;\\/</strong>>)'.replace(/**/g, a), 'i'),</p>\n<p>lookbehind: !0,</p>\n<p>greedy: !0,</p>\n<p>inside: n</p>\n<p>}),</p>\n<p>Prism.languages.insertBefore('markup', 'cdata', i);</p>\n<p>}</p>\n<p>}),</p>\n<p>(Prism.languages.xml = Prism.languages.extend('markup', {})),</p>\n<p>(Prism.languages.html = Prism.languages.markup),</p>\n<p>(Prism.languages.mathml = Prism.languages.markup),</p>\n<p>(Prism.languages.svg = Prism.languages.markup);</p>\n<p>!(function (s) {</p>\n<p>var t = /(\"|')(?:\\(?:\\r\\n|[\\s\\S])|(?!\\1)<sup id=\"fnref-\\\\\\r\\n\"><a href=\"#fn-\\\\\\r\\n\" class=\"footnote-ref\">\\\\\\r\\n</a></sup>)_\\1/;</p>\n<p>(s.languages.css = {</p>\n<p>comment: //*[\\s\\S]_?*//,</p>\n<p>atrule: {</p>\n<p>pattern: /@[\\w-]+[\\s\\S]<em>?(?:;|(?=\\s</em>{))/,</p>\n<p>inside: { rule: /@[\\w-]+/ }</p>\n<p>},</p>\n<p>url: {</p>\n<p>pattern: RegExp('url\\((?:' + t.source + '|<sup id=\"fnref-\\n\\r()\"><a href=\"#fn-\\n\\r()\" class=\"footnote-ref\">\\n\\r()</a></sup>_)\\)', 'i'),</p>\n<p>inside: { function: /^url/i, punctuation: /^(|)$/ }</p>\n<p>},</p>\n<p>selector: RegExp('<a href=\"?:%5B%5E%7B%7D;%22&#x27;%5D%7C&#x27;%20+%20t.source%20+\" title=\")_?(?=\\s*\\{)\">^{}\\s</a>,</p>\n<p>string: { pattern: t, greedy: !0 },</p>\n<p>property: /[-_a-z\\xA0-\\uFFFF][-\\w\\xa0-\\uffff]<em>(?=\\s</em>:)/i,</p>\n<p>important: /!important\\b/i,</p>\n<p>function: /[-a-z0-9]+(?=()/i,</p>\n<p>punctuation: /[(){};:,]/</p>\n<p>}),</p>\n<p>(s.languages.css.atrule.inside.rest = s.languages.css);</p>\n<p>var e = s.languages.markup;</p>\n<p>e &#x26;&#x26;</p>\n<p>(e.tag.addInlined('style', 'css'),</p>\n<p>s.languages.insertBefore(</p>\n<p>'inside',</p>\n<p>'attr-value',</p>\n<p>{</p>\n<p>'style-attr': {</p>\n<p>pattern: /\\s<em>style=(\"|')(?:\\[\\s\\S]|(?!\\1)<sup id=\"fnref-\\\\\"><a href=\"#fn-\\\\\" class=\"footnote-ref\">\\\\</a></sup>)</em>\\1/i,</p>\n<p>inside: {</p>\n<p>'attr-name': { pattern: /^\\s*style/i, inside: e.tag.inside },</p>\n<p>punctuation: /^\\s<em>=\\s</em>['\"]|['\"]\\s*$/,</p>\n<p>'attr-value': { pattern: /.+/i, inside: s.languages.css }</p>\n<p>},</p>\n<p>alias: 'language-css'</p>\n<p>}</p>\n<p>},</p>\n<p>e.tag</p>\n<p>));</p>\n<p>})(Prism);</p>\n<p>Prism.languages.clike = {</p>\n<p>comment: [</p>\n<p>{ pattern: /(^|<sup id=\"fnref-\\\\\"><a href=\"#fn-\\\\\" class=\"footnote-ref\">\\\\</a></sup>)/*[\\s\\S]*?(?:*/|$)/, lookbehind: !0 },</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    { pattern: /(^|[^\\\\:])\\/\\/.*/, lookbehind: !0, greedy: !0 }\n\n],\n\nstring: {\n\n    pattern: /([\"'])(?:\\\\(?:\\r\\n|[\\s\\S])|(?!\\1)[^\\\\\\r\\n])*\\1/,\n\n    greedy: !0\n\n},\n\n'class-name': {\n\n    pattern: /((?:\\b(?:class|interface|extends|implements|trait|instanceof|new)\\s+)|(?:catch\\s+\\())[\\w.\\\\]+/i,\n\n    lookbehind: !0,\n\n    inside: { punctuation: /[.\\\\]/ }\n\n},\n\nkeyword: /\\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\\b/,\n\nboolean: /\\b(?:true|false)\\b/,\n\nfunction: /\\w+(?=\\()/,\n\nnumber: /\\b0x[\\da-f]+\\b|(?:\\b\\d+\\.?\\d*|\\B\\.\\d+)(?:e[+-]?\\d+)?/i,\n\noperator: /--?|\\+\\+?|!=?=?|&lt;=?|>=?|==?=?|&amp;&amp;?|\\|\\|?|\\?|\\*|\\/|~|\\^|%/,\n\npunctuation: /[{}[\\];(),.:]/</code></pre></div>\n<p>};</p>\n<p>(Prism.languages.javascript = Prism.languages.extend('clike', {</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">'class-name': [\n\n    Prism.languages.clike['class-name'],\n\n    {\n\n        pattern: /(^|[^$\\w\\xA0-\\uFFFF])[\\_$A-Z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]_(?=\\.(?:prototype|constructor))/,</code></pre></div>\n<p>lookbehind: !0</p>\n<p>}</p>\n<p>],</p>\n<p>keyword: [</p>\n<p>{ pattern: /((?:^|})\\s_)(?:catch|finally)\\b/, lookbehind: !0 },</p>\n<p>{</p>\n<p>pattern:</p>\n<p>/(^|<sup id=\"fnref-.\"><a href=\"#fn-.\" class=\"footnote-ref\">.</a></sup>)\\b(?:as|async(?=\\s*(?:function\\b|(|[$\\w\\xA0-\\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\\b/,</p>\n<p>lookbehind: !0</p>\n<p>}</p>\n<p>],</p>\n<p>number: /\\b(?:(?:0<a href=\"?:%5B%5CdA-Fa-f%5D(?:_%5B%5CdA-Fa-f%5D)?\">xX</a>+|0<a href=\"?:%5B01%5D(?:_%5B01%5D)?\">bB</a>+|0<a href=\"?:%5B0-7%5D(?:_%5B0-7%5D)?\">oO</a>+)n?|(?:\\d(?:*\\d)?)+n|NaN|Infinity)\\b|(?:\\b(?:\\d(?:<em>\\d)?)+.?(?:\\d(?:\\</em>\\d)?)<em>|\\B.(?:\\d(?:</em>\\d)?)+)(?:[Ee][+-]?(?:\\d(?:_\\d)?)+)?/,</p>\n<p>function: /[_$a-zA-Z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]<em>(?=\\s</em>(?:.\\s<em>(?:apply|bind|call)\\s</em>)?()/,</p>\n<p>operator: /-[-=]?|+[+=]?|!=?=?|&#x3C;<?=?|>>?>?=?|=(?:==?|>)?|&#x26;[&#x26;=]?||[|=]?|**?=?|/=?|~|^=?|%=?|?|.{3}/</p>\n<p>})),</p>\n<p>(Prism.languages.javascript['class-name'][0].pattern = /(\\b(?:class|interface|extends|implements|instanceof|new)\\s+)[\\w.\\]+/),</p>\n<p>Prism.languages.insertBefore('javascript', 'keyword', {</p>\n<p>regex: {</p>\n<p>pattern: /((?:^|<sup id=\"fnref-$\\w\\xa0-\\uffff.&#x22;&#x27;\\])\\s\"><a href=\"#fn-$\\w\\xa0-\\uffff.&#x22;&#x27;\\])\\s\" class=\"footnote-ref\">$\\w\\xa0-\\uffff.\"'\\])\\s</a></sup>)\\s<em>)/([(?:<sup id=\"fnref-\\]\\\\\\r\\n\"><a href=\"#fn-\\]\\\\\\r\\n\" class=\"footnote-ref\">\\]\\\\\\r\\n</a></sup>|\\.)</em>]|\\.|<sup id=\"fnref-/\\\\\\[\\r\\n\"><a href=\"#fn-/\\\\\\[\\r\\n\" class=\"footnote-ref\">/\\\\\\[\\r\\n</a></sup>)+/[gimyus]{0,6}(?=\\s*($|[\\r\\n,.;})]]))/,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        lookbehind: !0,\n\n        greedy: !0\n\n    },\n\n    'function-variable': {\n\n        pattern:\n\n            /[_$a-zA-Z\\xA0-\\uFFFF][$\\w\\xA0-\\uFFFF]*(?=\\s*[=:]\\s*(?:async\\s*)?(?:\\bfunction\\b|(?:\\((?:[^()]|\\([^()]*\\))_\\)|[\\_$a-zA-Z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]_)\\s*=>))/,</code></pre></div>\n<p>alias: 'function'</p>\n<p>},</p>\n<p>parameter: [</p>\n<p>{</p>\n<p>pattern: /(function(?:\\s+[_$A-Za-z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]<em>)?\\s</em>(\\s*)(?!\\s)(?:<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup>|(<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup><em>))+?(?=\\s</em>))/,</p>\n<p>lookbehind: !0,</p>\n<p>inside: Prism.languages.javascript</p>\n<p>},</p>\n<p>{</p>\n<p>pattern: /[_$a-z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]<em>(?=\\s</em>=>)/i,</p>\n<p>inside: Prism.languages.javascript</p>\n<p>},</p>\n<p>{</p>\n<p>pattern: /((\\s<em>)(?!\\s)(?:<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup>|(<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup></em>))+?(?=\\s<em>)\\s</em>=>)/,</p>\n<p>lookbehind: !0,</p>\n<p>inside: Prism.languages.javascript</p>\n<p>},</p>\n<p>{</p>\n<p>pattern:</p>\n<p>/((?:\\b|\\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\\w\\xA0-\\uFFFF]))(?:[_$A-Za-z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]<em>\\s</em>)(\\s<em>)(?!\\s)(?:<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup>|(<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup></em>))+?(?=\\s<em>)\\s</em>{)/,</p>\n<p>lookbehind: !0,</p>\n<p>inside: Prism.languages.javascript</p>\n<p>}</p>\n<p>],</p>\n<p>constant: /\\b<a href=\"?:%5BA-Z_%5D%7C%5Cdx?\">A-Z</a>_\\b/</p>\n<p>}),</p>\n<p>Prism.languages.insertBefore('javascript', 'string', {</p>\n<p>'template-string': {</p>\n<p>pattern: /<code class=\"language-text\">(?:\\\\[\\s\\S]|\\${(?:[^{}]|{(?:[^{}]|{[^}]_})_})+}|[^\\\\</code>])_`/,</p>\n<p>greedy: !0,</p>\n<p>inside: {</p>\n<p>interpolation: {</p>\n<p>pattern: /${(?:<sup id=\"fnref-{}\"><a href=\"#fn-{}\" class=\"footnote-ref\">{}</a></sup>|{(?:<sup id=\"fnref-{}\"><a href=\"#fn-{}\" class=\"footnote-ref\">{}</a></sup>|{<sup id=\"fnref-}\"><a href=\"#fn-}\" class=\"footnote-ref\">}</a></sup><em>})</em>})+}/,</p>\n<p>inside: {</p>\n<p>'interpolation-punctuation': {</p>\n<p>pattern: /^${|}$/,</p>\n<p>alias: 'punctuation'</p>\n<p>},</p>\n<p>rest: Prism.languages.javascript</p>\n<p>}</p>\n<p>},</p>\n<p>string: /[\\s\\S]+/</p>\n<p>}</p>\n<p>}</p>\n<p>}),</p>\n<p>Prism.languages.markup &#x26;&#x26; Prism.languages.markup.tag.addInlined('script', 'javascript'),</p>\n<p>(Prism.languages.js = Prism.languages.javascript);</p>\n<p>!(function () {</p>\n<p>if ('undefined' != typeof self &#x26;&#x26; self.Prism &#x26;&#x26; self.document) {</p>\n<p>var r = [],</p>\n<p>i = {},</p>\n<p>n = function () {};</p>\n<p>Prism.plugins.toolbar = {};</p>\n<p>var t = (Prism.plugins.toolbar.registerButton = function (t, n) {</p>\n<p>var e;</p>\n<p>(e =</p>\n<p>'function' == typeof n</p>\n<p>? n</p>\n<p>: function (t) {</p>\n<p>var e;</p>\n<p>return (</p>\n<p>'function' == typeof n.onClick</p>\n<p>? (((e = document.createElement('button')).type = 'button'),</p>\n<p>e.addEventListener('click', function () {</p>\n<p>n.onClick.call(this, t);</p>\n<p>}))</p>\n<p>: 'string' == typeof n.url</p>\n<p>? ((e = document.createElement('a')).href = n.url)</p>\n<p>: (e = document.createElement('span')),</p>\n<p>(e.textContent = n.text),</p>\n<p>e</p>\n<p>);</p>\n<p>}),</p>\n<p>t in i ? console.warn('There is a button with the key \"' + t + '\" registered already.') : r.push((i[t] = e));</p>\n<p>}),</p>\n<p>e = (Prism.plugins.toolbar.hook = function (a) {</p>\n<p>var t = a.element.parentNode;</p>\n<p>if (t &#x26;&#x26; /pre/i.test(t.nodeName) &#x26;&#x26; !t.parentNode.classList.contains('code-toolbar')) {</p>\n<p>var e = document.createElement('div');</p>\n<p>e.classList.add('code-toolbar'), t.parentNode.insertBefore(e, t), e.appendChild(t);</p>\n<p>var o = document.createElement('div');</p>\n<p>o.classList.add('toolbar'),</p>\n<p>document.body.hasAttribute('data-toolbar-order') &#x26;&#x26;</p>\n<p>(r = document.body</p>\n<p>.getAttribute('data-toolbar-order')</p>\n<p>.split(',')</p>\n<p>.map(function (t) {</p>\n<p>return i[t] || n;</p>\n<p>})),</p>\n<p>r.forEach(function (t) {</p>\n<p>var e = t(a);</p>\n<p>if (e) {</p>\n<p>var n = document.createElement('div');</p>\n<p>n.classList.add('toolbar-item'), n.appendChild(e), o.appendChild(n);</p>\n<p>}</p>\n<p>}),</p>\n<p>e.appendChild(o);</p>\n<p>}</p>\n<p>});</p>\n<p>t('label', function (t) {</p>\n<p>var e = t.element.parentNode;</p>\n<p>if (e &#x26;&#x26; /pre/i.test(e.nodeName) &#x26;&#x26; e.hasAttribute('data-label')) {</p>\n<p>var n,</p>\n<p>a,</p>\n<p>o = e.getAttribute('data-label');</p>\n<p>try {</p>\n<p>a = document.querySelector('template#' + o);</p>\n<p>} catch (t) {}</p>\n<p>return (</p>\n<p>a</p>\n<p>? (n = a.content)</p>\n<p>: (e.hasAttribute('data-url')</p>\n<p>? ((n = document.createElement('a')).href = e.getAttribute('data-url'))</p>\n<p>: (n = document.createElement('span')),</p>\n<p>(n.textContent = o)),</p>\n<p>n</p>\n<p>);</p>\n<p>}</p>\n<p>}),</p>\n<p>Prism.hooks.add('complete', e);</p>\n<p>}</p>\n<p>})();</p>\n<p>!(function () {</p>\n<p>if ('undefined' != typeof self &#x26;&#x26; self.Prism &#x26;&#x26; self.document)</p>\n<p>if (Prism.plugins.toolbar) {</p>\n<p>var r = window.ClipboardJS || void 0;</p>\n<p>r || 'function' != typeof require || (r = require('clipboard'));</p>\n<p>var i = [];</p>\n<p>if (!r) {</p>\n<p>var o = document.createElement('script'),</p>\n<p>e = document.querySelector('head');</p>\n<p>(o.onload = function () {</p>\n<p>if ((r = window.ClipboardJS)) for (; i.length; ) i.pop()();</p>\n<p>}),</p>\n<p>(o.src = '<a href=\"https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js&#x27;\">https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js'</a>),</p>\n<p>e.appendChild(o);</p>\n<p>}</p>\n<p>Prism.plugins.toolbar.registerButton('copy-to-clipboard', function (e) {</p>\n<p>var t = document.createElement('a');</p>\n<p>return (t.textContent = 'Copy'), r ? o() : i.push(o), t;</p>\n<p>function o() {</p>\n<p>var o = new r(t, {</p>\n<p>text: function () {</p>\n<p>return e.code;</p>\n<p>}</p>\n<p>});</p>\n<p>o.on('success', function () {</p>\n<p>(t.textContent = 'Copied'), n();</p>\n<p>}),</p>\n<p>o.on('error', function () {</p>\n<p>(t.textContent = 'Press Ctrl+C to copy'), n();</p>\n<p>});</p>\n<p>}</p>\n<p>function n() {</p>\n<p>setTimeout(function () {</p>\n<p>t.textContent = 'Copy';</p>\n<p>}, 5e3);</p>\n<p>}</p>\n<p>});</p>\n<p>} else console.warn('Copy to Clipboard plugin loaded before Toolbar plugin.');</p>\n<p>})();</p>\n<p>/_ PrismJS 1.24.1</p>\n<p><a href=\"https://prismjs.com/download.html#themes=prism&#x26;languages=markup+css+clike+javascript\">https://prismjs.com/download.html#themes=prism&#x26;languages=markup+css+clike+javascript</a> _/</p>\n<p>var _self = 'undefined' != typeof window ? window : 'undefined' != typeof WorkerGlobalScope &#x26;&#x26; self instanceof WorkerGlobalScope ? self : {},</p>\n<p>Prism = (function (u) {</p>\n<p>var c = /\\blang(?:uage)?-([\\w-]+)\\b/i,</p>\n<p>n = 0,</p>\n<p>e = {},</p>\n<p>M = {</p>\n<p>manual: u.Prism &#x26;&#x26; u.Prism.manual,</p>\n<p>disableWorkerMessageHandler: u.Prism &#x26;&#x26; u.Prism.disableWorkerMessageHandler,</p>\n<p>util: {</p>\n<p>encode: function e(n) {</p>\n<p>return n instanceof W</p>\n<p>? new W(n.type, e(n.content), n.alias)</p>\n<p>: Array.isArray(n)</p>\n<p>? n.map(e)</p>\n<p>: n</p>\n<p>.replace(/&#x26;/g, '&#x26;')</p>\n<p>.replace(/&#x3C;/g, '&#x3C;')</p>\n<p>.replace(/\\u00a0/g, ' ');</p>\n<p>},</p>\n<p>type: function (e) {</p>\n<p>return Object.prototype.toString.call(e).slice(8, -1);</p>\n<p>},</p>\n<p>objId: function (e) {</p>\n<p>return e.<strong>id || Object.defineProperty(e, '</strong>id', { value: ++n }), e.**id;</p>\n<p>},</p>\n<p>clone: function t(e, r) {</p>\n<p>var a, n;</p>\n<p>switch (((r = r || {}), M.util.type(e))) {</p>\n<p>case 'Object':</p>\n<p>if (((n = M.util.objId(e)), r[n])) return r[n];</p>\n<p>for (var i in ((a = {}), (r[n] = a), e)) e.hasOwnProperty(i) &#x26;&#x26; (a[i] = t(e[i], r));</p>\n<p>return a;</p>\n<p>case 'Array':</p>\n<p>return (</p>\n<p>(n = M.util.objId(e)),</p>\n<p>r[n]</p>\n<p>? r[n]</p>\n<p>: ((a = []),</p>\n<p>(r[n] = a),</p>\n<p>e.forEach(function (e, n) {</p>\n<p>a[n] = t(e, r);</p>\n<p>}),</p>\n<p>a)</p>\n<p>);</p>\n<p>default:</p>\n<p>return e;</p>\n<p>}</p>\n<p>},</p>\n<p>getLanguage: function (e) {</p>\n<p>for (; e &#x26;&#x26; !c.test(e.className); ) e = e.parentElement;</p>\n<p>return e ? (e.className.match(c) || [, 'none'])[1].toLowerCase() : 'none';</p>\n<p>},</p>\n<p>currentScript: function () {</p>\n<p>if ('undefined' == typeof document) return null;</p>\n<p>if ('currentScript' in document) return document.currentScript;</p>\n<p>try {</p>\n<p>throw new Error();</p>\n<p>} catch (e) {</p>\n<p>var n = (/at <sup id=\"fnref-(\\r\\n\"><a href=\"#fn-(\\r\\n\" class=\"footnote-ref\">(\\r\\n</a></sup><em>((.</em>):.+:.+)$/i.exec(e.stack) || [])[1];</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">                        if (n) {\n\n                            var t = document.getElementsByTagName('script');\n\n                            for (var r in t) if (t[r].src == n) return t[r];\n\n                        }\n\n                        return null;\n\n                    }\n\n                },\n\n                isActive: function (e, n, t) {\n\n                    for (var r = 'no-' + n; e; ) {\n\n                        var a = e.classList;\n\n                        if (a.contains(n)) return !0;\n\n                        if (a.contains(r)) return !1;\n\n                        e = e.parentElement;\n\n                    }\n\n                    return !!t;\n\n                }\n\n            },\n\n            languages: {\n\n                plain: e,\n\n                plaintext: e,\n\n                text: e,\n\n                txt: e,\n\n                extend: function (e, n) {\n\n                    var t = M.util.clone(M.languages[e]);\n\n                    for (var r in n) t[r] = n[r];\n\n                    return t;\n\n                },\n\n                insertBefore: function (t, e, n, r) {\n\n                    var a = (r = r || M.languages)[t],\n\n                        i = {};\n\n                    for (var l in a)\n\n                        if (a.hasOwnProperty(l)) {\n\n                            if (l == e) for (var o in n) n.hasOwnProperty(o) &amp;&amp; (i[o] = n[o]);\n\n                            n.hasOwnProperty(l) || (i[l] = a[l]);\n\n                        }\n\n                    var s = r[t];\n\n                    return (\n\n                        (r[t] = i),\n\n                        M.languages.DFS(M.languages, function (e, n) {\n\n                            n === s &amp;&amp; e != t &amp;&amp; (this[e] = i);\n\n                        }),\n\n                        i\n\n                    );\n\n                },\n\n                DFS: function e(n, t, r, a) {\n\n                    a = a || {};\n\n                    var i = M.util.objId;\n\n                    for (var l in n)\n\n                        if (n.hasOwnProperty(l)) {\n\n                            t.call(n, l, n[l], r || l);\n\n                            var o = n[l],\n\n                                s = M.util.type(o);\n\n                            'Object' !== s || a[i(o)] ? 'Array' !== s || a[i(o)] || ((a[i(o)] = !0), e(o, t, l, a)) : ((a[i(o)] = !0), e(o, t, null, a));\n\n                        }\n\n                }\n\n            },\n\n            plugins: {},\n\n            highlightAll: function (e, n) {\n\n                M.highlightAllUnder(document, e, n);\n\n            },\n\n            highlightAllUnder: function (e, n, t) {\n\n                var r = {\n\n                    callback: t,\n\n                    container: e,\n\n                    selector: 'code[class*=\"language-\"], [class*=\"language-\"] code, code[class*=\"lang-\"], [class*=\"lang-\"] code'\n\n                };\n\n                M.hooks.run('before-highlightall', r),\n\n                    (r.elements = Array.prototype.slice.apply(r.container.querySelectorAll(r.selector))),\n\n                    M.hooks.run('before-all-elements-highlight', r);\n\n                for (var a, i = 0; (a = r.elements[i++]); ) M.highlightElement(a, !0 === n, r.callback);\n\n            },\n\n            highlightElement: function (e, n, t) {\n\n                var r = M.util.getLanguage(e),\n\n                    a = M.languages[r];\n\n                e.className = e.className.replace(c, '').replace(/\\s+/g, ' ') + ' language-' + r;\n\n                var i = e.parentElement;\n\n                i &amp;&amp; 'pre' === i.nodeName.toLowerCase() &amp;&amp; (i.className = i.className.replace(c, '').replace(/\\s+/g, ' ') + ' language-' + r);\n\n                var l = { element: e, language: r, grammar: a, code: e.textContent };\n\n                function o(e) {\n\n                    (l.highlightedCode = e),\n\n                        M.hooks.run('before-insert', l),\n\n                        (l.element.innerHTML = l.highlightedCode),\n\n                        M.hooks.run('after-highlight', l),\n\n                        M.hooks.run('complete', l),\n\n                        t &amp;&amp; t.call(l.element);\n\n                }\n\n                if (\n\n                    (M.hooks.run('before-sanity-check', l),\n\n                    (i = l.element.parentElement) &amp;&amp; 'pre' === i.nodeName.toLowerCase() &amp;&amp; !i.hasAttribute('tabindex') &amp;&amp; i.setAttribute('tabindex', '0'),\n\n                    !l.code)\n\n                )\n\n                    return M.hooks.run('complete', l), void (t &amp;&amp; t.call(l.element));\n\n                if ((M.hooks.run('before-highlight', l), l.grammar))\n\n                    if (n &amp;&amp; u.Worker) {\n\n                        var s = new Worker(M.filename);\n\n                        (s.onmessage = function (e) {\n\n                            o(e.data);\n\n                        }),\n\n                            s.postMessage(JSON.stringify({ language: l.language, code: l.code, immediateClose: !0 }));\n\n                    } else o(M.highlight(l.code, l.grammar, l.language));\n\n                else o(M.util.encode(l.code));\n\n            },\n\n            highlight: function (e, n, t) {\n\n                var r = { code: e, grammar: n, language: t };\n\n                return (\n\n                    M.hooks.run('before-tokenize', r),\n\n                    (r.tokens = M.tokenize(r.code, r.grammar)),\n\n                    M.hooks.run('after-tokenize', r),\n\n                    W.stringify(M.util.encode(r.tokens), r.language)\n\n                );\n\n            },\n\n            tokenize: function (e, n) {\n\n                var t = n.rest;\n\n                if (t) {\n\n                    for (var r in t) n[r] = t[r];\n\n                    delete n.rest;\n\n                }\n\n                var a = new i();\n\n                return (\n\n                    I(a, a.head, e),\n\n                    (function e(n, t, r, a, i, l) {\n\n                        for (var o in r)\n\n                            if (r.hasOwnProperty(o) &amp;&amp; r[o]) {\n\n                                var s = r[o];\n\n                                s = Array.isArray(s) ? s : [s];\n\n                                for (var u = 0; u &lt; s.length; ++u) {\n\n                                    if (l &amp;&amp; l.cause == o + ',' + u) return;\n\n                                    var c = s[u],\n\n                                        g = c.inside,\n\n                                        f = !!c.lookbehind,\n\n                                        h = !!c.greedy,\n\n                                        d = c.alias;\n\n                                    if (h &amp;&amp; !c.pattern.global) {\n\n                                        var p = c.pattern.toString().match(/[imsuy]*$/)[0];</code></pre></div>\n<p>c.pattern = RegExp(c.pattern.source, p + 'g');</p>\n<p>}</p>\n<p>for (var v = c.pattern || c, m = a.next, y = i; m !== t.tail &#x26;&#x26; !(l &#x26;&#x26; y >= l.reach); y += m.value.length, m = m.next) {</p>\n<p>var b = m.value;</p>\n<p>if (t.length > n.length) return;</p>\n<p>if (!(b instanceof W)) {</p>\n<p>var k,</p>\n<p>x = 1;</p>\n<p>if (h) {</p>\n<p>if (!(k = z(v, y, n, f))) break;</p>\n<p>var w = k.index,</p>\n<p>A = k.index + k[0].length,</p>\n<p>P = y;</p>\n<p>for (P += m.value.length; P &#x3C;= w; ) (m = m.next), (P += m.value.length);</p>\n<p>if (((P -= m.value.length), (y = P), m.value instanceof W)) continue;</p>\n<p>for (var E = m; E !== t.tail &#x26;&#x26; (P &#x3C; A || 'string' == typeof E.value); E = E.next)</p>\n<p>x++, (P += E.value.length);</p>\n<p>x--, (b = n.slice(y, P)), (k.index -= y);</p>\n<p>} else if (!(k = z(v, 0, b, f))) continue;</p>\n<p>var w = k.index,</p>\n<p>S = k[0],</p>\n<p>O = b.slice(0, w),</p>\n<p>L = b.slice(w + S.length),</p>\n<p>N = y + b.length;</p>\n<p>l &#x26;&#x26; N > l.reach &#x26;&#x26; (l.reach = N);</p>\n<p>var j = m.prev;</p>\n<p>O &#x26;&#x26; ((j = I(t, j, O)), (y += O.length)), q(t, j, x);</p>\n<p>var C = new W(o, g ? M.tokenize(S, g) : S, d, S);</p>\n<p>if (((m = I(t, j, C)), L &#x26;&#x26; I(t, m, L), 1 &#x3C; x)) {</p>\n<p>var _ = { cause: o + ',' + u, reach: N };</p>\n<p>e(n, t, r, m.prev, y, <em>), l &#x26;&#x26;</em>.reach > l.reach &#x26;&#x26; (l.reach = _.reach);</p>\n<p>}</p>\n<p>}</p>\n<p>}</p>\n<p>}</p>\n<p>}</p>\n<p>})(e, a, n, a.head, 0),</p>\n<p>(function (e) {</p>\n<p>var n = [],</p>\n<p>t = e.head.next;</p>\n<p>for (; t !== e.tail; ) n.push(t.value), (t = t.next);</p>\n<p>return n;</p>\n<p>})(a)</p>\n<p>);</p>\n<p>},</p>\n<p>hooks: {</p>\n<p>all: {},</p>\n<p>add: function (e, n) {</p>\n<p>var t = M.hooks.all;</p>\n<p>(t[e] = t[e] || []), t[e].push(n);</p>\n<p>},</p>\n<p>run: function (e, n) {</p>\n<p>var t = M.hooks.all[e];</p>\n<p>if (t &#x26;&#x26; t.length) for (var r, a = 0; (r = t[a++]); ) r(n);</p>\n<p>}</p>\n<p>},</p>\n<p>Token: W</p>\n<p>};</p>\n<p>function W(e, n, t, r) {</p>\n<p>(this.type = e), (this.content = n), (this.alias = t), (this.length = 0 | (r || '').length);</p>\n<p>}</p>\n<p>function z(e, n, t, r) {</p>\n<p>e.lastIndex = n;</p>\n<p>var a = e.exec(t);</p>\n<p>if (a &#x26;&#x26; r &#x26;&#x26; a[1]) {</p>\n<p>var i = a[1].length;</p>\n<p>(a.index += i), (a[0] = a[0].slice(i));</p>\n<p>}</p>\n<p>return a;</p>\n<p>}</p>\n<p>function i() {</p>\n<p>var e = { value: null, prev: null, next: null },</p>\n<p>n = { value: null, prev: e, next: null };</p>\n<p>(e.next = n), (this.head = e), (this.tail = n), (this.length = 0);</p>\n<p>}</p>\n<p>function I(e, n, t) {</p>\n<p>var r = n.next,</p>\n<p>a = { value: t, prev: n, next: r };</p>\n<p>return (n.next = a), (r.prev = a), e.length++, a;</p>\n<p>}</p>\n<p>function q(e, n, t) {</p>\n<p>for (var r = n.next, a = 0; a &#x3C; t &#x26;&#x26; r !== e.tail; a++) r = r.next;</p>\n<p>((n.next = r).prev = n), (e.length -= a);</p>\n<p>}</p>\n<p>if (</p>\n<p>((u.Prism = M),</p>\n<p>(W.stringify = function n(e, t) {</p>\n<p>if ('string' == typeof e) return e;</p>\n<p>if (Array.isArray(e)) {</p>\n<p>var r = '';</p>\n<p>return (</p>\n<p>e.forEach(function (e) {</p>\n<p>r += n(e, t);</p>\n<p>}),</p>\n<p>r</p>\n<p>);</p>\n<p>}</p>\n<p>var a = { type: e.type, content: n(e.content, t), tag: 'span', classes: ['token', e.type], attributes: {}, language: t },</p>\n<p>i = e.alias;</p>\n<p>i &#x26;&#x26; (Array.isArray(i) ? Array.prototype.push.apply(a.classes, i) : a.classes.push(i)), M.hooks.run('wrap', a);</p>\n<p>var l = '';</p>\n<p>for (var o in a.attributes) l += ' ' + o + '=\"' + (a.attributes[o] || '').replace(/\"/g, '\"') + '\"';</p>\n<p>return '&#x3C;' + a.tag + ' class=\"' + a.classes.join(' ') + '\"' + l + '>' + a.content + '&#x3C;/' + a.tag + '>';</p>\n<p>}),</p>\n<p>!u.document)</p>\n<p>)</p>\n<p>return (</p>\n<p>u.addEventListener &#x26;&#x26;</p>\n<p>(M.disableWorkerMessageHandler ||</p>\n<p>u.addEventListener(</p>\n<p>'message',</p>\n<p>function (e) {</p>\n<p>var n = JSON.parse(e.data),</p>\n<p>t = n.language,</p>\n<p>r = n.code,</p>\n<p>a = n.immediateClose;</p>\n<p>u.postMessage(M.highlight(r, M.languages[t], t)), a &#x26;&#x26; u.close();</p>\n<p>},</p>\n<p>!1</p>\n<p>)),</p>\n<p>M</p>\n<p>);</p>\n<p>var t = M.util.currentScript();</p>\n<p>function r() {</p>\n<p>M.manual || M.highlightAll();</p>\n<p>}</p>\n<p>if ((t &#x26;&#x26; ((M.filename = t.src), t.hasAttribute('data-manual') &#x26;&#x26; (M.manual = !0)), !M.manual)) {</p>\n<p>var a = document.readyState;</p>\n<p>'loading' === a || ('interactive' === a &#x26;&#x26; t &#x26;&#x26; t.defer)</p>\n<p>? document.addEventListener('DOMContentLoaded', r)</p>\n<p>: window.requestAnimationFrame</p>\n<p>? window.requestAnimationFrame(r)</p>\n<p>: window.setTimeout(r, 16);</p>\n<p>}</p>\n<p>return M;</p>\n<p>})(_self);</p>\n<p>'undefined' != typeof module &#x26;&#x26; module.exports &#x26;&#x26; (module.exports = Prism), 'undefined' != typeof global &#x26;&#x26; (global.Prism = Prism);</p>\n<p>(Prism.languages.markup = {</p>\n<p>comment: /<!--[\\s\\S]*?-->/,</p>\n<p>prolog: /&#x3C;?[\\s\\S]+??>/,</p>\n<p>doctype: {</p>\n<p>pattern: /&#x3C;!DOCTYPE(?:[^>\"'[]]|\"<sup id=\"fnref-&#x22;\"><a href=\"#fn-&#x22;\" class=\"footnote-ref\">\"</a></sup><em>\"|'<sup id=\"fnref-&#x27;\"><a href=\"#fn-&#x27;\" class=\"footnote-ref\">'</a></sup></em>')+(?:[(?:<sup id=\"fnref-<&#x22;&#x27;\\]\"><a href=\"#fn-<&#x22;&#x27;\\]\" class=\"footnote-ref\">&#x3C;\"'\\]</a></sup>|\"<sup id=\"fnref-&#x22;\"><a href=\"#fn-&#x22;\" class=\"footnote-ref\">\"</a></sup><em>\"|'<sup id=\"fnref-&#x27;\"><a href=\"#fn-&#x27;\" class=\"footnote-ref\">'</a></sup></em>'|&#x3C;(?!!--)|<!--(?:[^-]|-(?!->))*-->)<em>]\\s</em>)?>/i,</p>\n<p>greedy: !0,</p>\n<p>inside: {</p>\n<p>'internal-subset': { pattern: /<a href=\"%5Cs%5CS\">^<sup id=\"fnref-\\[\"><a href=\"#fn-\\[\" class=\"footnote-ref\">\\[</a></sup>*[</a>+(?=]>$)/, lookbehind: !0, greedy: !0, inside: null },</p>\n<p>string: { pattern: /\"<sup id=\"fnref-&#x22;\"><a href=\"#fn-&#x22;\" class=\"footnote-ref\">\"</a></sup><em>\"|'<sup id=\"fnref-&#x27;\"><a href=\"#fn-&#x27;\" class=\"footnote-ref\">'</a></sup></em>'/, greedy: !0 },</p>\n<p>punctuation: /^&#x3C;!|>$|[[]]/,</p>\n<p>'doctype-tag': /^DOCTYPE/,</p>\n<p>name: /<sup id=\"fnref-\\s<>&#x27;&#x22;\"><a href=\"#fn-\\s<>&#x27;&#x22;\" class=\"footnote-ref\">\\s&#x3C;>'\"</a></sup>+/</p>\n<p>}</p>\n<p>},</p>\n<p>cdata: /&#x3C;![CDATA[[\\s\\S]*?]]>/i,</p>\n<p>tag: {</p>\n<p>pattern: /&#x3C;/?(?!\\d)<sup id=\"fnref-\\s>\\/=$<%\"><a href=\"#fn-\\s>\\/=$<%\" class=\"footnote-ref\">\\s>\\/=$&#x3C;%</a></sup>+(?:\\s(?:\\s<em><sup id=\"fnref-\\s>\\/=\"><a href=\"#fn-\\s>\\/=\" class=\"footnote-ref\">\\s>\\/=</a></sup>+(?:\\s</em>=\\s<em>(?:\"<sup id=\"fnref-&#x22;\"><a href=\"#fn-&#x22;\" class=\"footnote-ref\">\"</a></sup></em>\"|'<sup id=\"fnref-&#x27;\"><a href=\"#fn-&#x27;\" class=\"footnote-ref\">'</a></sup><em>'|<sup id=\"fnref-\\s&#x27;&#x22;>=\"><a href=\"#fn-\\s&#x27;&#x22;>=\" class=\"footnote-ref\">\\s'\">=</a></sup>+(?=[\\s>]))|(?=[\\s/>])))+)?\\s</em>/?>/,</p>\n<p>greedy: !0,</p>\n<p>inside: {</p>\n<p>tag: { pattern: /^&#x3C;/?<sup id=\"fnref-\\s>\\/\"><a href=\"#fn-\\s>\\/\" class=\"footnote-ref\">\\s>\\/</a></sup>+/, inside: { punctuation: /^&#x3C;/?/, namespace: /^<sup id=\"fnref-\\s>\\/:\"><a href=\"#fn-\\s>\\/:\" class=\"footnote-ref\">\\s>\\/:</a></sup>+:/ } },</p>\n<p>'special-attr': [],</p>\n<p>'attr-value': { pattern: /=\\s<em>(?:\"<sup id=\"fnref-&#x22;\"><a href=\"#fn-&#x22;\" class=\"footnote-ref\">\"</a></sup></em>\"|'<sup id=\"fnref-&#x27;\"><a href=\"#fn-&#x27;\" class=\"footnote-ref\">'</a></sup>*'|<sup id=\"fnref-\\s&#x27;&#x22;>=\"><a href=\"#fn-\\s&#x27;&#x22;>=\" class=\"footnote-ref\">\\s'\">=</a></sup>+)/, inside: { punctuation: [{ pattern: /^=/, alias: 'attr-equals' }, /\"|'/] } },</p>\n<p>punctuation: //?>/,</p>\n<p>'attr-name': { pattern: /<sup id=\"fnref-\\s>\\/\"><a href=\"#fn-\\s>\\/\" class=\"footnote-ref\">\\s>\\/</a></sup>+/, inside: { namespace: /^<sup id=\"fnref-\\s>\\/:\"><a href=\"#fn-\\s>\\/:\" class=\"footnote-ref\">\\s>\\/:</a></sup>+:/ } }</p>\n<p>}</p>\n<p>},</p>\n<p>entity: [{ pattern: /&#x26;[\\da-z]{1,8};/i, alias: 'named-entity' }, /&#x26;#x?[\\da-f]{1,8};/i]</p>\n<p>}),</p>\n<p>(Prism.languages.markup.tag.inside['attr-value'].inside.entity = Prism.languages.markup.entity),</p>\n<p>(Prism.languages.markup.doctype.inside['internal-subset'].inside = Prism.languages.markup),</p>\n<p>Prism.hooks.add('wrap', function (a) {</p>\n<p>'entity' === a.type &#x26;&#x26; (a.attributes.title = a.content.replace(/&#x26;/, '&#x26;'));</p>\n<p>}),</p>\n<p>Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {</p>\n<p>value: function (a, e) {</p>\n<p>var s = {};</p>\n<p><a href=\"%5Cs%5CS\">s['language-' + e] = { pattern: /(^&#x3C;![CDATA[</a>+?(?=]]>$)/i, lookbehind: !0, inside: Prism.languages[e] }),</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">            (s.cdata = /^&lt;!\\[CDATA\\[|\\]\\]>$/i);</code></pre></div>\n<p>var t = { 'included-cdata': { pattern: /&#x3C;![CDATA[[\\s\\S]*?]]>/i, inside: s } };</p>\n<p>t['language-' + e] = { pattern: /[\\s\\S]+/, inside: Prism.languages[e] };</p>\n<p>var n = {};</p>\n<p>(n[a] = {</p>\n<p>pattern: RegExp(</p>\n<p>'(&#x3C;<strong><sup id=\"fnref->\"><a href=\"#fn->\" class=\"footnote-ref\">></a></sup><em>>)(?:&#x3C;!\\<a href=\"?!%5D%3E\">CDATA\\[(?:<sup id=\"fnref-\\\\\"><a href=\"#fn-\\\\\" class=\"footnote-ref\">\\\\</a></sup>]|\\</a>)</em>\\]\\]>|(?!&#x3C;!\\[CDATA\\[)[^])*?(?=&#x3C;/</strong>>)'.replace(/__/g, function () {</p>\n<p>return a;</p>\n<p>}),</p>\n<p>'i'</p>\n<p>),</p>\n<p>lookbehind: !0,</p>\n<p>greedy: !0,</p>\n<p>inside: t</p>\n<p>}),</p>\n<p>Prism.languages.insertBefore('markup', 'cdata', n);</p>\n<p>}</p>\n<p>}),</p>\n<p>Object.defineProperty(Prism.languages.markup.tag, 'addAttribute', {</p>\n<p>value: function (a, e) {</p>\n<p>Prism.languages.markup.tag.inside['special-attr'].push({</p>\n<p>pattern: RegExp('(^|[\"'\\s])(?:' + a + ')\\s<em>=\\s</em>(?:\"<sup id=\"fnref-&#x22;\"><a href=\"#fn-&#x22;\" class=\"footnote-ref\">\"</a></sup><em>\"|'<sup id=\"fnref-\\&#x27;\"><a href=\"#fn-\\&#x27;\" class=\"footnote-ref\">\\'</a></sup></em>'|<sup id=\"fnref-\\\\s\\&#x27;&#x22;>=\"><a href=\"#fn-\\\\s\\&#x27;&#x22;>=\" class=\"footnote-ref\">\\\\s\\'\">=</a></sup>+(?=[\\s>]))', 'i'),</p>\n<p>lookbehind: !0,</p>\n<p>inside: {</p>\n<p>'attr-name': /^<sup id=\"fnref-\\s=\"><a href=\"#fn-\\s=\" class=\"footnote-ref\">\\s=</a></sup>+/,</p>\n<p>'attr-value': {</p>\n<p>pattern: /=[\\s\\S]+/,</p>\n<p>inside: {</p>\n<p>value: {</p>\n<p>pattern: /(^=\\s<em>([\"']|(?![\"'])))\\S[\\s\\S]</em>(?=\\2$)/,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">                            lookbehind: !0,\n\n                            alias: [e, 'language-' + e],\n\n                            inside: Prism.languages[e]\n\n                        },\n\n                        punctuation: [{ pattern: /^=/, alias: 'attr-equals' }, /\"|'/]\n\n                    }\n\n                }\n\n            }\n\n        });\n\n    }\n\n}),\n\n(Prism.languages.html = Prism.languages.markup),\n\n(Prism.languages.mathml = Prism.languages.markup),\n\n(Prism.languages.svg = Prism.languages.markup),\n\n(Prism.languages.xml = Prism.languages.extend('markup', {})),\n\n(Prism.languages.ssml = Prism.languages.xml),\n\n(Prism.languages.atom = Prism.languages.xml),\n\n(Prism.languages.rss = Prism.languages.xml);</code></pre></div>\n<p>!(function (s) {</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">var e = /(?:\"(?:\\\\(?:\\r\\n|[\\s\\S])|[^\"\\\\\\r\\n])*\"|'(?:\\\\(?:\\r\\n|[\\s\\S])|[^'\\\\\\r\\n])*')/;\n\n(s.languages.css = {\n\n    comment: /\\/\\*[\\s\\S]*?\\*\\//,\n\n    atrule: {\n\n        pattern: /@[\\w-](?:[^;{\\s]|\\s+(?![\\s{]))*(?:;|(?=\\s*\\{))/,\n\n        inside: {\n\n            rule: /^@[\\w-]+/,\n\n            'selector-function-argument': {\n\n                pattern: /(\\bselector\\s*\\(\\s*(?![\\s)]))(?:[^()\\s]|\\s+(?![\\s)])|\\((?:[^()]|\\([^()]*\\))*\\))+(?=\\s*\\))/,\n\n                lookbehind: !0,\n\n                alias: 'selector'\n\n            },\n\n            keyword: { pattern: /(^|[^\\w-])(?:and|not|only|or)(?![\\w-])/, lookbehind: !0 }\n\n        }\n\n    },\n\n    url: {\n\n        pattern: RegExp('\\\\burl\\\\((?:' + e.source + '|(?:[^\\\\\\\\\\r\\n()\"\\']|\\\\\\\\[^])*)\\\\)', 'i'),\n\n        greedy: !0,\n\n        inside: { function: /^url/i, punctuation: /^\\(|\\)$/, string: { pattern: RegExp('^' + e.source + '$'), alias: 'url' } }\n\n    },\n\n    selector: { pattern: RegExp('(^|[{}\\\\s])[^{}\\\\s](?:[^{};\"\\'\\\\s]|\\\\s+(?![\\\\s{])|' + e.source + ')*(?=\\\\s*\\\\{)'), lookbehind: !0 },\n\n    string: { pattern: e, greedy: !0 },\n\n    property: { pattern: /(^|[^-\\w\\xA0-\\uFFFF])(?!\\s)[-_a-z\\xA0-\\uFFFF](?:(?!\\s)[-\\w\\xA0-\\uFFFF])*(?=\\s*:)/i, lookbehind: !0 },\n\n    important: /!important\\b/i,\n\n    function: { pattern: /(^|[^-a-z0-9])[-a-z0-9]+(?=\\()/i, lookbehind: !0 },\n\n    punctuation: /[(){};:,]/\n\n}),\n\n    (s.languages.css.atrule.inside.rest = s.languages.css);\n\nvar t = s.languages.markup;\n\nt &amp;&amp; (t.tag.addInlined('style', 'css'), t.tag.addAttribute('style', 'css'));</code></pre></div>\n<p>})(Prism);</p>\n<p>Prism.languages.clike = {</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">comment: [\n\n    { pattern: /(^|[^\\\\])\\/\\*[\\s\\S]*?(?:\\*\\/|$)/, lookbehind: !0, greedy: !0 },</code></pre></div>\n<p>{ pattern: /(^|<sup id=\"fnref-\\\\:\"><a href=\"#fn-\\\\:\" class=\"footnote-ref\">\\\\:</a></sup>)//.*/, lookbehind: !0, greedy: !0 }</p>\n<p>],</p>\n<p>string: { pattern: /([\"'])(?:\\(?:\\r\\n|[\\s\\S])|(?!\\1)<sup id=\"fnref-\\\\\\r\\n\"><a href=\"#fn-\\\\\\r\\n\" class=\"footnote-ref\">\\\\\\r\\n</a></sup>)*\\1/, greedy: !0 },</p>\n<p>'class-name': {</p>\n<p>pattern: /(\\b(?:class|interface|extends|implements|trait|instanceof|new)\\s+|\\bcatch\\s+()[\\w.\\]+/i,</p>\n<p>lookbehind: !0,</p>\n<p>inside: { punctuation: /[.\\]/ }</p>\n<p>},</p>\n<p>keyword: /\\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\\b/,</p>\n<p>boolean: /\\b(?:true|false)\\b/,</p>\n<p>function: /\\b\\w+(?=()/,</p>\n<p>number: /\\b0x[\\da-f]+\\b|(?:\\b\\d+(?:.\\d*)?|\\B.\\d+)(?:e[+-]?\\d+)?/i,</p>\n<p>operator: /[&#x3C;>]=?|[!=]=?=?|--?|++?|&#x26;&#x26;?|||?|[?*/~^%]/,</p>\n<p>punctuation: /[{}[];(),.:]/</p>\n<p>};</p>\n<p>(Prism.languages.javascript = Prism.languages.extend('clike', {</p>\n<p>'class-name': [</p>\n<p>Prism.languages.clike['class-name'],</p>\n<p>{ pattern: /(^|<sup id=\"fnref-$\\w\\xa0-\\uffff\"><a href=\"#fn-$\\w\\xa0-\\uffff\" class=\"footnote-ref\">$\\w\\xa0-\\uffff</a></sup>)(?!\\s)[_$A-Z\\xA0-\\uFFFF][&#x3C;?:(?!\\s]($\\w\\xA0-\\uFFFF)>)_(?=.(?:prototype|constructor))/, lookbehind: !0 }</p>\n<p>],</p>\n<p>keyword: [</p>\n<p>{ pattern: /((?:^|})\\s_)catch\\b/, lookbehind: !0 },</p>\n<p>{</p>\n<p>pattern:</p>\n<p>/(^|<sup id=\"fnref-.\"><a href=\"#fn-.\" class=\"footnote-ref\">.</a></sup>|...\\s<em>)\\b(?:as|assert(?=\\s</em>{)|async(?=\\s<em>(?:function\\b|(|[$\\w\\xA0-\\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\\s</em>(?:{|$))|for|from(?=\\s<em>(?:['\"]|$))|function|(?:get|set)(?=\\s\\</em>(?:[#[$\\w\\xA0-\\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\\b/,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        lookbehind: !0\n\n    }\n\n],\n\nfunction: /#?(?!\\s)[_$a-zA-Z\\xA0-\\uFFFF](?:(?!\\s)[$\\w\\xA0-\\uFFFF])*(?=\\s*(?:\\.\\s*(?:apply|bind|call)\\s*)?\\()/,</code></pre></div>\n<p>number: /\\b(?:(?:0<a href=\"?:%5B%5CdA-Fa-f%5D(?:_%5B%5CdA-Fa-f%5D)?\">xX</a>+|0<a href=\"?:%5B01%5D(?:_%5B01%5D)?\">bB</a>+|0<a href=\"?:%5B0-7%5D(?:_%5B0-7%5D)?\">oO</a>+)n?|(?:\\d(?:*\\d)?)+n|NaN|Infinity)\\b|(?:\\b(?:\\d(?:<em>\\d)?)+.?(?:\\d(?:\\</em>\\d)?)<em>|\\B.(?:\\d(?:</em>\\d)?)+)(?:[Ee][+-]?(?:\\d(?:_\\d)?)+)?/,</p>\n<p>operator: /--|++|**=?|=>|&#x26;&#x26;=?|||=?|[!=]==|&#x3C;&#x3C;=?|>>>?=?|[-+*/%&#x26;|^!=&#x3C;>]=?|.{3}|??=?|?.?|[~:]/</p>\n<p>})),</p>\n<p>(Prism.languages.javascript['class-name'][0].pattern = /(\\b(?:class|interface|extends|implements|instanceof|new)\\s+)[\\w.\\]+/),</p>\n<p>Prism.languages.insertBefore('javascript', 'keyword', {</p>\n<p>regex: {</p>\n<p>pattern:</p>\n<p>/((?:^|<sup id=\"fnref-$\\w\\xa0-\\uffff.&#x22;&#x27;\\])\\s\"><a href=\"#fn-$\\w\\xa0-\\uffff.&#x22;&#x27;\\])\\s\" class=\"footnote-ref\">$\\w\\xa0-\\uffff.\"'\\])\\s</a></sup>|\\b(?:return|yield))\\s<em>)/(?:[(?:<sup id=\"fnref-\\]\\\\\\r\\n\"><a href=\"#fn-\\]\\\\\\r\\n\" class=\"footnote-ref\">\\]\\\\\\r\\n</a></sup>|\\.)</em>]|\\.|<sup id=\"fnref-/\\\\\\[\\r\\n\"><a href=\"#fn-/\\\\\\[\\r\\n\" class=\"footnote-ref\">/\\\\\\[\\r\\n</a></sup>)+/[dgimyus]{0,7}(?=(?:\\s|/*(?:<sup id=\"fnref-*\"><a href=\"#fn-*\" class=\"footnote-ref\">*</a></sup>|*(?!/))<em>*/)</em>(?:$|[\\r\\n,.;:})]]|//))/,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        lookbehind: !0,\n\n        greedy: !0,\n\n        inside: {\n\n            'regex-source': { pattern: /^(\\/)[\\s\\S]+(?=\\/[a-z]*$)/, lookbehind: !0, alias: 'language-regex', inside: Prism.languages.regex },</code></pre></div>\n<p>'regex-delimiter': /^/|/$/,</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">            'regex-flags': /^[a-z]+$/</code></pre></div>\n<p>}</p>\n<p>},</p>\n<p>'function-variable': {</p>\n<p>pattern:</p>\n<p>/#?(?!\\s)[_$a-zA-Z\\xA0-\\uFFFF][&#x3C;?:(?!\\s]($\\w\\xA0-\\uFFFF)>)<em>(?=\\s</em>[=:]\\s<em>(?:async\\s</em>)?(?:\\bfunction\\b|(?:((?:<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup>|(<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup><em>))</em>)|(?!\\s)[_$a-zA-Z\\xA0-\\uFFFF][&#x3C;?:(?!\\s]($\\w\\xA0-\\uFFFF)>)<em>)\\s</em>=>))/,</p>\n<p>alias: 'function'</p>\n<p>},</p>\n<p>parameter: [</p>\n<p>{</p>\n<p>pattern: /(function(?:\\s+(?!\\s)[_$a-zA-Z\\xA0-\\uFFFF][&#x3C;?:(?!\\s]($\\w\\xA0-\\uFFFF)>)<em>)?\\s</em>(\\s<em>)(?!\\s)(?:<sup id=\"fnref-()\\s\"><a href=\"#fn-()\\s\" class=\"footnote-ref\">()\\s</a></sup>|\\s+(?![\\s)])|(<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup></em>))+(?=\\s*))/,</p>\n<p>lookbehind: !0,</p>\n<p>inside: Prism.languages.javascript</p>\n<p>},</p>\n<p>{</p>\n<p>pattern: /(^|<sup id=\"fnref-$\\w\\xa0-\\uffff\"><a href=\"#fn-$\\w\\xa0-\\uffff\" class=\"footnote-ref\">$\\w\\xa0-\\uffff</a></sup>)(?!\\s)[_$a-z\\xA0-\\uFFFF][&#x3C;?:(?!\\s]($\\w\\xA0-\\uFFFF)>)<em>(?=\\s</em>=>)/i,</p>\n<p>lookbehind: !0,</p>\n<p>inside: Prism.languages.javascript</p>\n<p>},</p>\n<p>{ pattern: /((\\s<em>)(?!\\s)(?:<sup id=\"fnref-()\\s\"><a href=\"#fn-()\\s\" class=\"footnote-ref\">()\\s</a></sup>|\\s+(?![\\s)])|(<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup></em>))+(?=\\s<em>)\\s</em>=>)/, lookbehind: !0, inside: Prism.languages.javascript },</p>\n<p>{</p>\n<p>pattern:</p>\n<p>/((?:\\b|\\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\\w\\xA0-\\uFFFF]))(?:(?!\\s)[_$a-zA-Z\\xA0-\\uFFFF][&#x3C;?:(?!\\s]($\\w\\xA0-\\uFFFF)>)<em>\\s</em>)(\\s<em>|]\\s</em>(\\s<em>)(?!\\s)(?:<sup id=\"fnref-()\\s\"><a href=\"#fn-()\\s\" class=\"footnote-ref\">()\\s</a></sup>|\\s+(?![\\s)])|(<sup id=\"fnref-()\"><a href=\"#fn-()\" class=\"footnote-ref\">()</a></sup></em>))+(?=\\s<em>)\\s</em>{)/,</p>\n<p>lookbehind: !0,</p>\n<p>inside: Prism.languages.javascript</p>\n<p>}</p>\n<p>],</p>\n<p>constant: /\\b<a href=\"?:%5BA-Z_%5D%7C%5Cdx?\">A-Z</a>*\\b/</p>\n<p>}),</p>\n<p>Prism.languages.insertBefore('javascript', 'string', {</p>\n<p>hashbang: { pattern: /^#!._/, greedy: !0, alias: 'comment' },</p>\n<p>'template-string': {</p>\n<p>pattern: /<code class=\"language-text\">(?:\\\\[\\s\\S]|\\$\\{(?:[^{}]|\\{(?:[^{}]|\\{[^}]_\\})_\\})+\\}|(?!\\$\\{)[^\\\\</code>])_<code class=\"language-text\">/, greedy: !0, inside: { 'template-punctuation': { pattern: /^</code>|`$/, alias: 'string' },</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">            interpolation: {\n\n                pattern: /((?:^|[^\\\\])(?:\\\\{2})*)\\$\\{(?:[^{}]|\\{(?:[^{}]|\\{[^}]*\\})*\\})+\\}/,\n\n                lookbehind: !0,\n\n                inside: { 'interpolation-punctuation': { pattern: /^\\$\\{|\\}$/, alias: 'punctuation' }, rest: Prism.languages.javascript }</code></pre></div>\n<p>},</p>\n<p>string: /[\\s\\S]+/</p>\n<p>}</p>\n<p>}</p>\n<p>}),</p>\n<p>Prism.languages.markup &#x26;&#x26;</p>\n<p>(Prism.languages.markup.tag.addInlined('script', 'javascript'),</p>\n<p>Prism.languages.markup.tag.addAttribute(</p>\n<p>'on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)',</p>\n<p>'javascript'</p>\n<p>)),</p>\n<p>(Prism.languages.js = Prism.languages.javascript);</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># main.js\n\n```js\n//\n\nwindow.onGatsbyInitialClientRender = function () {\n\n    /**\n\n     * Main JS file for theme behaviours\n\n     */\n\n    // Responsive video embeds\n\n    let videoEmbeds = ['iframe[src*=\"youtube.com\"]', 'iframe[src*=\"vimeo.com\"]'];\n\n    reframe(videoEmbeds.join(','));\n\n    // Handle main navigation menu toggling on small screens\n\n    function menuToggleHandler(e) {\n\n        e.preventDefault();\n\n        document.body.classList.toggle('menu--opened');\n\n    }\n\n    // Handle docs navigation menu toggling on small screens\n\n    function docsNavToggleHandler(e) {\n\n        e.preventDefault();\n\n        document.body.classList.toggle('docs-menu--opened');\n\n    }\n\n    // Handle submenu toggling\n\n    function submenuToggleHandler(e) {\n\n        e.preventDefault();\n\n        this.parentNode.classList.toggle('active');\n\n    }\n\n    window.addMainNavigationHandlers = function () {\n\n        const menuToggle = document.querySelectorAll('.menu-toggle');\n\n        if (menuToggle) {\n\n            for (let i = 0; i &lt; menuToggle.length; i++) {\n\n                menuToggle[i].addEventListener('click', menuToggleHandler, false);\n\n            }\n\n        }\n\n        const submenuToggle = document.querySelectorAll('.submenu-toggle');\n\n        if (submenuToggle) {\n\n            for (let i = 0; i &lt; submenuToggle.length; i++) {\n\n                submenuToggle[i].addEventListener('click', submenuToggleHandler, false);\n\n            }\n\n        }\n\n    };\n\n    window.removeMainNavigationHandlers = function () {\n\n        // Remove nav related classes on page load\n\n        document.body.classList.remove('menu--opened');\n\n        const menuToggle = document.querySelectorAll('.menu-toggle');\n\n        if (menuToggle) {\n\n            for (let i = 0; i &lt; menuToggle.length; i++) {\n\n                menuToggle[i].removeEventListener('click', menuToggleHandler, false);\n\n            }\n\n        }\n\n        const submenuToggle = document.querySelectorAll('.submenu-toggle');\n\n        if (submenuToggle) {\n\n            for (let i = 0; i &lt; submenuToggle.length; i++) {\n\n                submenuToggle[i].removeEventListener('click', submenuToggleHandler, false);\n\n            }\n\n        }\n\n    };\n\n    window.addDocsNavigationHandlers = function () {\n\n        const docsNavToggle = document.getElementById('docs-nav-toggle');\n\n        if (docsNavToggle) {\n\n            docsNavToggle.addEventListener('click', docsNavToggleHandler, false);\n\n        }\n\n        const docsSubmenuToggle = document.querySelectorAll('.docs-submenu-toggle');\n\n        if (docsSubmenuToggle) {\n\n            for (let i = 0; i &lt; docsSubmenuToggle.length; i++) {\n\n                docsSubmenuToggle[i].addEventListener('click', submenuToggleHandler, false);\n\n            }\n\n        }\n\n    };\n\n    window.removeDocsNavigationHandlers = function () {\n\n        // Remove docs nav related classes on page load\n\n        document.body.classList.remove('docs-menu--opened');\n\n        const docsNavToggle = document.getElementById('docs-nav-toggle');\n\n        if (docsNavToggle) {\n\n            docsNavToggle.removeEventListener('click', docsNavToggleHandler, false);\n\n        }\n\n        const docsSubmenuToggle = document.querySelectorAll('.docs-submenu-toggle');\n\n        if (docsSubmenuToggle) {\n\n            for (let i = 0; i &lt; docsSubmenuToggle.length; i++) {\n\n                docsSubmenuToggle[i].removeEventListener('click', submenuToggleHandler, false);\n\n            }\n\n        }\n\n    };\n\n    window.addPageNavLinks = function () {\n\n        const pageToc = document.getElementById('page-nav-inside');\n\n        const pageTocContainer = document.getElementById('page-nav-link-container');\n\n        if (pageToc &amp;&amp; pageTocContainer) {\n\n            const pageContent = document.querySelector('.type-docs .post-content');\n\n            // Create in-page navigation\n\n            const headerLinks = getHeaderLinks({\n\n                root: pageContent\n\n            });\n\n            if (headerLinks.length > 0) {\n\n                pageToc.classList.add('has-links');\n\n                renderHeaderLinks(pageTocContainer, headerLinks);\n\n            }\n\n            // Scroll to anchors\n\n            let scroll = new SmoothScroll('[data-scroll]');\n\n            let hash = window.decodeURI(location.hash.replace('#', ''));\n\n            if (hash !== '') {\n\n                window.setTimeout(function () {\n\n                    let anchor = document.getElementById(hash);\n\n                    if (anchor) {\n\n                        scroll.animateScroll(anchor);\n\n                    }\n\n                }, 0);\n\n            }\n\n            // Highlight current anchor\n\n            let pageTocLinks = pageTocContainer.getElementsByTagName('a');\n\n            if (pageTocLinks.length > 0) {\n\n                let spy = new Gumshoe('#page-nav-inside a', {\n\n                    nested: true,\n\n                    nestedClass: 'active-parent'\n\n                });\n\n            }\n\n            // Add link to page content headings\n\n            let pageHeadings = getElementsByTagNames(pageContent, ['h2', 'h3']);\n\n            for (let i = 0; i &lt; pageHeadings.length; i++) {\n\n                let heading = pageHeadings[i];\n\n                if (typeof heading.id !== 'undefined' &amp;&amp; heading.id !== '') {\n\n                    heading.insertBefore(anchorForId(heading.id), heading.firstChild);\n\n                }\n\n            }\n\n            // Copy link url\n\n            let clipboard = new ClipboardJS('.hash-link', {\n\n                text: function (trigger) {\n\n                    return window.location.href.replace(window.location.hash, '') + trigger.getAttribute('href');\n\n                }\n\n            });\n\n        }\n\n    };\n\n    window.removePageNavLinks = function () {\n\n        const pageToc = document.getElementById('page-nav-inside');\n\n        const pageTocContainer = document.getElementById('page-nav-link-container');\n\n        if (pageToc &amp;&amp; pageTocContainer) {\n\n            pageToc.classList.remove('has-links');\n\n            while (pageTocContainer.firstChild) {\n\n                pageTocContainer.removeChild(pageTocContainer.firstChild);\n\n            }\n\n        }\n\n    };\n\n    function getElementsByTagNames(root, tagNames) {\n\n        let elements = [];\n\n        for (let i = 0; i &lt; root.children.length; i++) {\n\n            let element = root.children[i];\n\n            let tagName = element.nodeName.toLowerCase();\n\n            if (tagNames.includes(tagName)) {\n\n                elements.push(element);\n\n            }\n\n            elements = elements.concat(getElementsByTagNames(element, tagNames));\n\n        }\n\n        return elements;\n\n    }\n\n    function createLinksForHeaderElements(elements) {\n\n        let result = [];\n\n        let stack = [\n\n            {\n\n                level: 0,\n\n                children: result\n\n            }\n\n        ];\n\n        let re = /^h(\\d)$/;\n\n        for (let i = 0; i &lt; elements.length; i++) {\n\n            let element = elements[i];\n\n            let tagName = element.nodeName.toLowerCase();\n\n            let match = re.exec(tagName);\n\n            if (!match) {\n\n                console.warn('can not create links to non header element');\n\n                continue;\n\n            }\n\n            let headerLevel = parseInt(match[1], 10);\n\n            if (!element.id) {\n\n                if (!element.textContent) {\n\n                    console.warn('can not create link to element without id and without text content');\n\n                    continue;\n\n                }\n\n                element.id = element.textContent\n\n                    .toLowerCase()\n\n                    .replace(/[^\\w]+/g, '_')\n\n                    .replace(/^_/, '')\n\n                    .replace(/_$/, '');\n\n            }\n\n            let link = document.createElement('a');\n\n            link.href = '#' + element.id;\n\n            link.setAttribute('data-scroll', '');\n\n            link.appendChild(document.createTextNode(element.textContent));\n\n            let obj = {\n\n                id: element.id,\n\n                level: headerLevel,\n\n                textContent: element.textContent,\n\n                element: element,\n\n                link: link,\n\n                children: []\n\n            };\n\n            if (headerLevel > stack[stack.length - 1].level) {\n\n                stack[stack.length - 1].children.push(obj);\n\n                stack.push(obj);\n\n            } else {\n\n                while (headerLevel &lt;= stack[stack.length - 1].level &amp;&amp; stack.length > 1) {\n\n                    stack.pop();\n\n                }\n\n                stack[stack.length - 1].children.push(obj);\n\n                stack.push(obj);\n\n            }\n\n        }\n\n        return result;\n\n    }\n\n    function getHeaderLinks(options = {}) {\n\n        let tagNames = options.tagNames || ['h2', 'h3'];\n\n        let root = options.root || document.body;\n\n        let headerElements = getElementsByTagNames(root, tagNames);\n\n        return createLinksForHeaderElements(headerElements);\n\n    }\n\n    function renderHeaderLinks(element, links) {\n\n        if (links.length === 0) {\n\n            return;\n\n        }\n\n        let ulElm = document.createElement('ul');\n\n        for (let i = 0; i &lt; links.length; i++) {\n\n            let liElm = document.createElement('li');\n\n            liElm.append(links[i].link);\n\n            if (links[i].children.length > 0) {\n\n                renderHeaderLinks(liElm, links[i].children);\n\n            }\n\n            ulElm.appendChild(liElm);\n\n        }\n\n        element.appendChild(ulElm);\n\n    }\n\n    function anchorForId(id) {\n\n        let anchor = document.createElement('a');\n\n        anchor.setAttribute('class', 'hash-link');\n\n        anchor.setAttribute('data-scroll', '');\n\n        anchor.href = '#' + id;\n\n        anchor.innerHTML = '&lt;span class=\"screen-reader-text\">Copy&lt;/span>';\n\n        return anchor;\n\n    }\n\n    // Syntax Highlighter\n\n    // Prism.highlightAll();\n\n};\n\n//-----------------------------------------------------------------------\n\n//-----------------------------------------------------------------------\n\n//--------------------------------New----------------------------------\n\n//-----------------------------------------------------------------------\n\n//-----------------------------------------------------------------------</code></pre></div>\n<hr>\n<hr>\n<h1>Page Load JS</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onGatsbyRouteUpdate</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">addMainNavigationHandlers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">addDocsNavigationHandlers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">addPageNavLinks</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<h1>PageUnload.js</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nwindow<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onGatsbyPreRouteUpdate</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">removeMainNavigationHandlers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">removeDocsNavigationHandlers</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    window<span class=\"token punctuation\">.</span><span class=\"token function\">removePageNavLinks</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<h1>Plugins.js</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> module\n        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> define <span class=\"token operator\">&amp;&amp;</span> define<span class=\"token punctuation\">.</span>amd\n        <span class=\"token operator\">?</span> <span class=\"token function\">define</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> globalThis <span class=\"token operator\">?</span> globalThis <span class=\"token operator\">:</span> e <span class=\"token operator\">||</span> self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>reframe <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">function</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> t <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">;</span> t<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> e <span class=\"token operator\">+=</span> arguments<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token function\">Array</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> t <span class=\"token operator\">&lt;</span> n<span class=\"token punctuation\">;</span> t<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> arguments<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> f <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> d <span class=\"token operator\">=</span> r<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> f <span class=\"token operator\">&lt;</span> d<span class=\"token punctuation\">;</span> f<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> o<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> i<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> r<span class=\"token punctuation\">[</span>f<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> i<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">===</span> s <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>s <span class=\"token operator\">=</span> <span class=\"token string\">'js-reframe'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> e <span class=\"token operator\">?</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token string\">'length'</span> <span class=\"token keyword\">in</span> e <span class=\"token operator\">?</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">,</span> d<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">;</span>\n\n                <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span>\n                    <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>width<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span><span class=\"token string\">'%'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'height'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'width'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>offsetWidth<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> i <span class=\"token operator\">?</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> o <span class=\"token operator\">?</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token number\">100</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> f<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>position <span class=\"token operator\">=</span> <span class=\"token string\">'relative'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> <span class=\"token string\">'100%'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span>paddingTop <span class=\"token operator\">=</span> r <span class=\"token operator\">+</span> <span class=\"token string\">'%'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>l <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>position <span class=\"token operator\">=</span> <span class=\"token string\">'absolute'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>width <span class=\"token operator\">=</span> <span class=\"token string\">'100%'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>height <span class=\"token operator\">=</span> <span class=\"token string\">'100%'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>left <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>top <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> t <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> n <span class=\"token operator\">&amp;&amp;</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    f<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/*! smooth-scroll v16.1.0 | (c) 2019 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */</span>\n\nwindow<span class=\"token punctuation\">.</span>Element <span class=\"token operator\">&amp;&amp;</span>\n    <span class=\"token operator\">!</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>closest <span class=\"token operator\">&amp;&amp;</span>\n    <span class=\"token punctuation\">(</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">closest</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span>\n            n <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>document <span class=\"token operator\">||</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>ownerDocument<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            o <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">do</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;=</span> <span class=\"token operator\">--</span>t <span class=\"token operator\">&amp;&amp;</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">item</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token operator\">!==</span> o<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">&lt;</span> <span class=\"token number\">0</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span>parentElement<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> o<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>CustomEvent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            t <span class=\"token operator\">=</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">bubbles</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cancelable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">detail</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createEvent</span><span class=\"token punctuation\">(</span><span class=\"token string\">'CustomEvent'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">initCustomEvent</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>bubbles<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>cancelable<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>detail<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token class-name\">Event</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>CustomEvent <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'ms'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'moz'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'webkit'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'o'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> t <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>window<span class=\"token punctuation\">.</span>requestAnimationFrame<span class=\"token punctuation\">;</span> <span class=\"token operator\">++</span>t<span class=\"token punctuation\">)</span>\n            <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>requestAnimationFrame <span class=\"token operator\">=</span> window<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token string\">'RequestAnimationFrame'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>cancelAnimationFrame <span class=\"token operator\">=</span> window<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token string\">'CancelAnimationFrame'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> window<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> <span class=\"token string\">'CancelRequestAnimationFrame'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        window<span class=\"token punctuation\">.</span>requestAnimationFrame <span class=\"token operator\">||</span>\n            <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">requestAnimationFrame</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">getTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    o <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">16</span> <span class=\"token operator\">-</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    a <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">+</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> n <span class=\"token operator\">+</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            window<span class=\"token punctuation\">.</span>cancelAnimationFrame <span class=\"token operator\">||</span>\n                <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">cancelAnimationFrame</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token function\">clearTimeout</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> define <span class=\"token operator\">&amp;&amp;</span> define<span class=\"token punctuation\">.</span>amd\n            <span class=\"token operator\">?</span> <span class=\"token function\">define</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                  <span class=\"token keyword\">return</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n              <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">:</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports\n            <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>SmoothScroll <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> global <span class=\"token operator\">?</span> global <span class=\"token operator\">:</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> window <span class=\"token operator\">?</span> window <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">q</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">var</span> <span class=\"token constant\">I</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">ignore</span><span class=\"token operator\">:</span> <span class=\"token string\">'[data-scroll-ignore]'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">header</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">topOnEmptyHash</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">speed</span><span class=\"token operator\">:</span> <span class=\"token number\">500</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">speedAsDuration</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">durationMax</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">durationMin</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">clip</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">offset</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">easing</span><span class=\"token operator\">:</span> <span class=\"token string\">'easeInOutCubic'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">customEasing</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">updateURL</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">popstate</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">emitEvents</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">F</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> t <span class=\"token keyword\">in</span> e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n                            n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    n\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">r</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token string\">'#'</span> <span class=\"token operator\">===</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">substr</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token function\">String</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> a <span class=\"token operator\">=</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> r <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">,</span> i <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token operator\">++</span>a <span class=\"token operator\">&lt;</span> o<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span> <span class=\"token operator\">===</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">charCodeAt</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">InvalidCharacterError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Invalid character: the input contains U+0000.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">31</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token number\">127</span> <span class=\"token operator\">==</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span> <span class=\"token operator\">===</span> a <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">48</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">57</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">===</span> a <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">48</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">57</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">45</span> <span class=\"token operator\">===</span> i<span class=\"token punctuation\">)</span>\n                        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">+=</span> <span class=\"token string\">'\\\\'</span> <span class=\"token operator\">+</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token number\">16</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">+=</span>\n                              <span class=\"token number\">128</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">||</span> <span class=\"token number\">45</span> <span class=\"token operator\">===</span> t <span class=\"token operator\">||</span> <span class=\"token number\">95</span> <span class=\"token operator\">===</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">48</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">57</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">65</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">90</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token number\">97</span> <span class=\"token operator\">&lt;=</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&lt;=</span> <span class=\"token number\">122</span><span class=\"token punctuation\">)</span>\n                                  <span class=\"token operator\">?</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span>\n                                  <span class=\"token operator\">:</span> <span class=\"token string\">'\\\\'</span> <span class=\"token operator\">+</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token string\">'#'</span> <span class=\"token operator\">+</span> r<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">L</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>\n                    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>scrollHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>scrollHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>clientHeight<span class=\"token punctuation\">,</span>\n\n                    document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>clientHeight\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">x</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> e <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>q<span class=\"token punctuation\">.</span><span class=\"token function\">getComputedStyle</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>height<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>offsetTop<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">H</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>emitEvents <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> q<span class=\"token punctuation\">.</span>CustomEvent<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">CustomEvent</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">bubbles</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">detail</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">anchor</span><span class=\"token operator\">:</span> n<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">toggle</span><span class=\"token operator\">:</span> o <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    document<span class=\"token punctuation\">.</span><span class=\"token function\">dispatchEvent</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">o<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">,</span>\n                a<span class=\"token punctuation\">,</span>\n                <span class=\"token constant\">O</span><span class=\"token punctuation\">,</span>\n                <span class=\"token constant\">C</span><span class=\"token punctuation\">,</span>\n                <span class=\"token constant\">M</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">cancelScroll</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token function\">cancelAnimationFrame</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">C</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e <span class=\"token operator\">||</span> <span class=\"token constant\">H</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scrollCancel'</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">animateScroll</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">i<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">cancelScroll</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> <span class=\"token constant\">F</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span> <span class=\"token operator\">||</span> <span class=\"token constant\">I</span><span class=\"token punctuation\">,</span> e <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        u <span class=\"token operator\">=</span> <span class=\"token string\">'[object Number]'</span> <span class=\"token operator\">===</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        t <span class=\"token operator\">=</span> u <span class=\"token operator\">||</span> <span class=\"token operator\">!</span>i<span class=\"token punctuation\">.</span>tagName <span class=\"token operator\">?</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">:</span> i<span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>u <span class=\"token operator\">||</span> t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> l <span class=\"token operator\">=</span> q<span class=\"token punctuation\">.</span>pageYOffset<span class=\"token punctuation\">;</span>\n\n                        s<span class=\"token punctuation\">.</span>header <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token constant\">O</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">O</span> <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>header<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">var</span> n<span class=\"token punctuation\">,</span>\n                            o<span class=\"token punctuation\">,</span>\n                            a<span class=\"token punctuation\">,</span>\n                            m<span class=\"token punctuation\">,</span>\n                            r<span class=\"token punctuation\">,</span>\n                            d<span class=\"token punctuation\">,</span>\n                            f<span class=\"token punctuation\">,</span>\n                            h<span class=\"token punctuation\">,</span>\n                            p <span class=\"token operator\">=</span> <span class=\"token function\">x</span><span class=\"token punctuation\">(</span><span class=\"token constant\">O</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            g <span class=\"token operator\">=</span> u\n                                <span class=\"token operator\">?</span> i\n                                <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                      <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                                      <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>offsetParent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">+=</span> e<span class=\"token punctuation\">.</span>offsetTop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>offsetParent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                      <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">-</span> t <span class=\"token operator\">-</span> n<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">min</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token constant\">L</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">-</span> q<span class=\"token punctuation\">.</span>innerHeight<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">;</span>\n                                  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> p<span class=\"token punctuation\">,</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> s<span class=\"token punctuation\">.</span>offset <span class=\"token operator\">?</span> s<span class=\"token punctuation\">.</span><span class=\"token function\">offset</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> s<span class=\"token punctuation\">.</span>offset<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">.</span>clip<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            y <span class=\"token operator\">=</span> g <span class=\"token operator\">-</span> l<span class=\"token punctuation\">,</span>\n                            v <span class=\"token operator\">=</span> <span class=\"token constant\">L</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            w <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token constant\">S</span> <span class=\"token operator\">=</span>\n                                <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>speedAsDuration <span class=\"token operator\">?</span> o<span class=\"token punctuation\">.</span>speed <span class=\"token operator\">:</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">/</span> <span class=\"token number\">1e3</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> o<span class=\"token punctuation\">.</span>speed<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                o<span class=\"token punctuation\">.</span>durationMax <span class=\"token operator\">&amp;&amp;</span> a <span class=\"token operator\">></span> o<span class=\"token punctuation\">.</span>durationMax <span class=\"token operator\">?</span> o<span class=\"token punctuation\">.</span>durationMax <span class=\"token operator\">:</span> o<span class=\"token punctuation\">.</span>durationMin <span class=\"token operator\">&amp;&amp;</span> a <span class=\"token operator\">&lt;</span> o<span class=\"token punctuation\">.</span>durationMin <span class=\"token operator\">?</span> o<span class=\"token punctuation\">.</span>durationMin <span class=\"token operator\">:</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token function-variable function\">E</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> n<span class=\"token punctuation\">,</span>\n                                    o<span class=\"token punctuation\">,</span>\n                                    a<span class=\"token punctuation\">,</span>\n                                    r <span class=\"token operator\">=</span> q<span class=\"token punctuation\">.</span>pageYOffset<span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">==</span> t <span class=\"token operator\">||</span> r <span class=\"token operator\">==</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">&lt;</span> t <span class=\"token operator\">&amp;&amp;</span> q<span class=\"token punctuation\">.</span>innerHeight <span class=\"token operator\">+</span> r<span class=\"token punctuation\">)</span> <span class=\"token operator\">>=</span> v<span class=\"token punctuation\">)</span>\n                                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                                        <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">cancelScroll</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> u<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token number\">0</span> <span class=\"token operator\">===</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        a <span class=\"token operator\">||</span>\n                                            <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            document<span class=\"token punctuation\">.</span>activeElement <span class=\"token operator\">!==</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tabindex'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'-1'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>outline <span class=\"token operator\">=</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            q<span class=\"token punctuation\">.</span><span class=\"token function\">scrollTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token constant\">H</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scrollStop'</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span> <span class=\"token operator\">=</span> m <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token function-variable function\">b</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">;</span>\n\n                                m <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span>w <span class=\"token operator\">+=</span> e <span class=\"token operator\">-</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span>\n                                        l <span class=\"token operator\">+</span>\n                                        y <span class=\"token operator\">*</span>\n                                            <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> r <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">===</span> <span class=\"token constant\">S</span> <span class=\"token operator\">?</span> <span class=\"token number\">0</span> <span class=\"token operator\">:</span> w <span class=\"token operator\">/</span> <span class=\"token constant\">S</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token number\">1</span> <span class=\"token operator\">:</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInQuad'</span> <span class=\"token operator\">===</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeOutQuad'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">-</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInOutQuad'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">&lt;</span> <span class=\"token number\">0.5</span> <span class=\"token operator\">?</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">-</span> <span class=\"token number\">2</span> <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInCubic'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeOutCubic'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInOutCubic'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">&lt;</span> <span class=\"token number\">0.5</span> <span class=\"token operator\">?</span> <span class=\"token number\">4</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">(</span><span class=\"token number\">2</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">-</span> <span class=\"token number\">2</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInQuart'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeOutQuart'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token operator\">-</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInOutQuart'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">&lt;</span> <span class=\"token number\">0.5</span> <span class=\"token operator\">?</span> <span class=\"token number\">8</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">:</span> <span class=\"token number\">1</span> <span class=\"token operator\">-</span> <span class=\"token number\">8</span> <span class=\"token operator\">*</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInQuint'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeOutQuint'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            <span class=\"token string\">'easeInOutQuint'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>easing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> n <span class=\"token operator\">&lt;</span> <span class=\"token number\">0.5</span> <span class=\"token operator\">?</span> <span class=\"token number\">16</span> <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">:</span> <span class=\"token number\">1</span> <span class=\"token operator\">+</span> <span class=\"token number\">16</span> <span class=\"token operator\">*</span> <span class=\"token operator\">--</span>n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n <span class=\"token operator\">*</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            t<span class=\"token punctuation\">.</span>customEasing <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">customEasing</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                            o <span class=\"token operator\">||</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    q<span class=\"token punctuation\">.</span><span class=\"token function\">scrollTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token constant\">E</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">,</span> g<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span> <span class=\"token operator\">=</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token number\">0</span> <span class=\"token operator\">===</span> q<span class=\"token punctuation\">.</span>pageYOffset <span class=\"token operator\">&amp;&amp;</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">scrollTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token punctuation\">(</span>h <span class=\"token operator\">=</span> s<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            u <span class=\"token operator\">||</span>\n                                <span class=\"token punctuation\">(</span>history<span class=\"token punctuation\">.</span>pushState <span class=\"token operator\">&amp;&amp;</span>\n                                    h<span class=\"token punctuation\">.</span>updateURL <span class=\"token operator\">&amp;&amp;</span>\n                                    history<span class=\"token punctuation\">.</span><span class=\"token function\">pushState</span><span class=\"token punctuation\">(</span>\n                                        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">smoothScroll</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>h<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">anchor</span><span class=\"token operator\">:</span> f<span class=\"token punctuation\">.</span>id <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                                        document<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">,</span>\n\n                                        f <span class=\"token operator\">===</span> document<span class=\"token punctuation\">.</span>documentElement <span class=\"token operator\">?</span> <span class=\"token string\">'#top'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'#'</span> <span class=\"token operator\">+</span> f<span class=\"token punctuation\">.</span>id\n                                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token string\">'matchMedia'</span> <span class=\"token keyword\">in</span> q <span class=\"token operator\">&amp;&amp;</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">matchMedia</span><span class=\"token punctuation\">(</span><span class=\"token string\">'(prefers-reduced-motion)'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>matches\n                                <span class=\"token operator\">?</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">scrollTo</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> Math<span class=\"token punctuation\">.</span><span class=\"token function\">floor</span><span class=\"token punctuation\">(</span>g<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                                <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">H</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scrollStart'</span><span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">cancelScroll</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span>b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">t</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">!</span>e<span class=\"token punctuation\">.</span>defaultPrevented <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span> <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">.</span>button <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>metaKey <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>ctrlKey <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span>shiftKey<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token string\">'closest'</span> <span class=\"token keyword\">in</span> e<span class=\"token punctuation\">.</span>target <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token string\">'a'</span> <span class=\"token operator\">===</span> a<span class=\"token punctuation\">.</span>tagName<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token operator\">!</span>e<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>ignore<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                        a<span class=\"token punctuation\">.</span>hostname <span class=\"token operator\">===</span> q<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>hostname <span class=\"token operator\">&amp;&amp;</span>\n                        a<span class=\"token punctuation\">.</span>pathname <span class=\"token operator\">===</span> q<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>pathname <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">#</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>href<span class=\"token punctuation\">)</span>\n                    <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span>\n                            n <span class=\"token operator\">=</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>hash<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'#'</span> <span class=\"token operator\">===</span> n<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>topOnEmptyHash<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n                            t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t <span class=\"token operator\">||</span> <span class=\"token string\">'#top'</span> <span class=\"token operator\">!==</span> n <span class=\"token operator\">?</span> t <span class=\"token operator\">:</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                            <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">preventDefault</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>history<span class=\"token punctuation\">.</span>replaceState <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">.</span>updateURL <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> q<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>hash<span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        history<span class=\"token punctuation\">.</span><span class=\"token function\">replaceState</span><span class=\"token punctuation\">(</span>\n                                            <span class=\"token punctuation\">{</span>\n                                                <span class=\"token literal-property property\">smoothScroll</span><span class=\"token operator\">:</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                                <span class=\"token literal-property property\">anchor</span><span class=\"token operator\">:</span> t <span class=\"token operator\">||</span> q<span class=\"token punctuation\">.</span>pageYOffset\n                                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                                            document<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">,</span>\n\n                                            t <span class=\"token operator\">||</span> q<span class=\"token punctuation\">.</span>location<span class=\"token punctuation\">.</span>href\n                                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">animateScroll</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                <span class=\"token function-variable function\">n</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> history<span class=\"token punctuation\">.</span>state <span class=\"token operator\">&amp;&amp;</span> history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>smoothScroll <span class=\"token operator\">&amp;&amp;</span> history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>smoothScroll <span class=\"token operator\">===</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>anchor<span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token function\">r</span><span class=\"token punctuation\">(</span>history<span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>anchor<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">animateScroll</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">updateURL</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">destroy</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token constant\">A</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'popstate'</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">cancelScroll</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">C</span> <span class=\"token operator\">=</span> <span class=\"token constant\">O</span> <span class=\"token operator\">=</span> a <span class=\"token operator\">=</span> <span class=\"token constant\">A</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token string\">'querySelector'</span> <span class=\"token keyword\">in</span> document <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'addEventListener'</span> <span class=\"token keyword\">in</span> q <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'requestAnimationFrame'</span> <span class=\"token keyword\">in</span> q <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'closest'</span> <span class=\"token keyword\">in</span> q<span class=\"token punctuation\">.</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token keyword\">throw</span> <span class=\"token string\">'Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.'</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">destroy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span><span class=\"token constant\">A</span> <span class=\"token operator\">=</span> <span class=\"token constant\">F</span><span class=\"token punctuation\">(</span><span class=\"token constant\">I</span><span class=\"token punctuation\">,</span> e <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span><span class=\"token constant\">O</span> <span class=\"token operator\">=</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>header <span class=\"token operator\">?</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>header<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        document<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>updateURL <span class=\"token operator\">&amp;&amp;</span> <span class=\"token constant\">A</span><span class=\"token punctuation\">.</span>popstate <span class=\"token operator\">&amp;&amp;</span> q<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'popstate'</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token constant\">M</span>\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/*! gumshoejs v5.1.1 | (c) 2019 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/gumshoe */</span>\n\n<span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>closest <span class=\"token operator\">||</span>\n    <span class=\"token punctuation\">(</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>matches <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>matches <span class=\"token operator\">=</span> <span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>msMatchesSelector <span class=\"token operator\">||</span> <span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>webkitMatchesSelector<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">closest</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">do</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">matches</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n            e <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentElement<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>CustomEvent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            e <span class=\"token operator\">=</span> e <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">bubbles</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">cancelable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">detail</span><span class=\"token operator\">:</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createEvent</span><span class=\"token punctuation\">(</span><span class=\"token string\">'CustomEvent'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">initCustomEvent</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>bubbles<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>cancelable<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>detail<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token class-name\">Event</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>window<span class=\"token punctuation\">.</span>CustomEvent <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> define <span class=\"token operator\">&amp;&amp;</span> define<span class=\"token punctuation\">.</span>amd\n            <span class=\"token operator\">?</span> <span class=\"token function\">define</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                  <span class=\"token keyword\">return</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n              <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">:</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports\n            <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n            <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>Gumshoe <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> global <span class=\"token operator\">?</span> global <span class=\"token operator\">:</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> window <span class=\"token operator\">?</span> window <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">navClass</span><span class=\"token operator\">:</span> <span class=\"token string\">'active'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">contentClass</span><span class=\"token operator\">:</span> <span class=\"token string\">'active'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">nested</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">nestedClass</span><span class=\"token operator\">:</span> <span class=\"token string\">'active'</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">offset</span><span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">reflow</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">events</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">n</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>settings<span class=\"token punctuation\">.</span>events<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">CustomEvent</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">bubbles</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">cancelable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">detail</span><span class=\"token operator\">:</span> n\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    e<span class=\"token punctuation\">.</span><span class=\"token function\">dispatchEvent</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">o</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>offsetParent<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> t<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">+=</span> t<span class=\"token punctuation\">.</span>offsetTop<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>offsetParent<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> e <span class=\"token operator\">>=</span> <span class=\"token number\">0</span> <span class=\"token operator\">?</span> e <span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">s</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                t <span class=\"token operator\">&amp;&amp;</span>\n                    t<span class=\"token punctuation\">.</span><span class=\"token function\">sort</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span> <span class=\"token operator\">:</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">c</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getBoundingClientRect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    c <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>offset <span class=\"token operator\">?</span> <span class=\"token function\">parseFloat</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span><span class=\"token function\">offset</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token function\">parseFloat</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>offset<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> o <span class=\"token operator\">?</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>bottom<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>innerHeight <span class=\"token operator\">||</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>clientHeight<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token function\">parseInt</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>top<span class=\"token punctuation\">,</span> <span class=\"token number\">10</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;=</span> c<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">r</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    t<span class=\"token punctuation\">.</span>innerHeight <span class=\"token operator\">+</span> t<span class=\"token punctuation\">.</span>pageYOffset <span class=\"token operator\">>=</span>\n                    Math<span class=\"token punctuation\">.</span><span class=\"token function\">max</span><span class=\"token punctuation\">(</span>\n                        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>scrollHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>scrollHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>offsetHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span>clientHeight<span class=\"token punctuation\">,</span>\n\n                        document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>clientHeight\n                    <span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">i</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> t<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token function\">c</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">)</span>\n                    <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span> o <span class=\"token operator\">>=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> o<span class=\"token operator\">--</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">c</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">l</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nested<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nestedClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">l</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">a</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>nav<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    o <span class=\"token operator\">&amp;&amp;</span>\n                        <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>navClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">remove</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>contentClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token function\">l</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token string\">'gumshoeDeactivate'</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">link</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">.</span>nav<span class=\"token punctuation\">,</span>\n\n                            <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span>\n\n                            <span class=\"token literal-property property\">settings</span><span class=\"token operator\">:</span> e\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function-variable function\">u</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nested<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nestedClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">u</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">o<span class=\"token punctuation\">,</span> c</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> r<span class=\"token punctuation\">,</span>\n                l<span class=\"token punctuation\">,</span>\n                f<span class=\"token punctuation\">,</span>\n                d<span class=\"token punctuation\">,</span>\n                m<span class=\"token punctuation\">,</span>\n                v <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">setup</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token function\">decodeURIComponent</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>hash<span class=\"token punctuation\">.</span><span class=\"token function\">substr</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        e <span class=\"token operator\">&amp;&amp;</span> l<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">nav</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> e <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token function\">s</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">detect</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token function\">i</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    t\n                        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>f <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>content <span class=\"token operator\">===</span> f<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span>\n                          <span class=\"token punctuation\">(</span><span class=\"token function\">a</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                          <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                  <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>nav<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'li'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                  o <span class=\"token operator\">&amp;&amp;</span>\n                                      <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>navClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                      t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>contentClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                      <span class=\"token function\">u</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                      <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token string\">'gumshoeActivate'</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                          <span class=\"token literal-property property\">link</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">.</span>nav<span class=\"token punctuation\">,</span>\n\n                                          <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span>\n\n                                          <span class=\"token literal-property property\">settings</span><span class=\"token operator\">:</span> e\n                                      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                              <span class=\"token punctuation\">}</span>\n                          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                          <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token operator\">:</span> f <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token function\">a</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">p</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    d <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">cancelAnimationFrame</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">.</span>detect<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                <span class=\"token function-variable function\">h</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    d <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">cancelAnimationFrame</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token function\">s</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> v<span class=\"token punctuation\">.</span><span class=\"token function\">detect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            v<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">destroy</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                f <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">a</span><span class=\"token punctuation\">(</span>f<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    t<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scroll'</span><span class=\"token punctuation\">,</span> p<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    m<span class=\"token punctuation\">.</span>reflow <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'resize'</span><span class=\"token punctuation\">,</span> h<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>l <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> n <span class=\"token keyword\">in</span> e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n                                t<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> e<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        t\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> c <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                v<span class=\"token punctuation\">.</span><span class=\"token function\">setup</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                v<span class=\"token punctuation\">.</span><span class=\"token function\">detect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                t<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'scroll'</span><span class=\"token punctuation\">,</span> p<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                m<span class=\"token punctuation\">.</span>reflow <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'resize'</span><span class=\"token punctuation\">,</span> h<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                v\n            <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">/*!\n\n * clipboard.js v2.0.4\n\n * https://zenorocha.github.io/clipboard.js\n\n *\n\n * Licensed MIT © Zeno Rocha\n\n */</span>\n\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> module\n        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> define <span class=\"token operator\">&amp;&amp;</span> define<span class=\"token punctuation\">.</span>amd\n        <span class=\"token operator\">?</span> <span class=\"token function\">define</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> exports\n        <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>exports<span class=\"token punctuation\">.</span>ClipboardJS <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n        <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>ClipboardJS <span class=\"token operator\">=</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">i</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">l</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">exports</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>l <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>exports<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>m <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>c <span class=\"token operator\">=</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">d</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                r<span class=\"token punctuation\">.</span><span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">enumerable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">get</span><span class=\"token operator\">:</span> n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">r</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span>\n                    Symbol<span class=\"token punctuation\">.</span>toStringTag <span class=\"token operator\">&amp;&amp;</span>\n                    Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> Symbol<span class=\"token punctuation\">.</span>toStringTag<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token string\">'Module'</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token string\">'__esModule'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">t</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">8</span> <span class=\"token operator\">&amp;</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token number\">4</span> <span class=\"token operator\">&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> e <span class=\"token operator\">&amp;&amp;</span> e <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">.</span>__esModule<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function\">r</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> <span class=\"token string\">'default'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">enumerable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> e\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token number\">2</span> <span class=\"token operator\">&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> e<span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">)</span>\n                    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token keyword\">in</span> e<span class=\"token punctuation\">)</span>\n                        r<span class=\"token punctuation\">.</span><span class=\"token function\">d</span><span class=\"token punctuation\">(</span>\n                            n<span class=\"token punctuation\">,</span>\n\n                            o<span class=\"token punctuation\">,</span>\n\n                            <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span>\n                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">n</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span>\n                    t <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>__esModule\n                        <span class=\"token operator\">?</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> r<span class=\"token punctuation\">.</span><span class=\"token function\">d</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> <span class=\"token string\">'a'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">o</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>p <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n            <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>s <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span>\n                    <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'symbol'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol<span class=\"token punctuation\">.</span>iterator\n                        <span class=\"token operator\">?</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">===</span> Symbol <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">!==</span> <span class=\"token class-name\">Symbol</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">?</span> <span class=\"token string\">'symbol'</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                i <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> n <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> n<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> e<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>enumerable <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span>enumerable <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>configurable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span> <span class=\"token keyword\">in</span> o <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>writable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span>key<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                a <span class=\"token operator\">=</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                c <span class=\"token operator\">=</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                u <span class=\"token operator\">=</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">4</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> t <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>__esModule <span class=\"token operator\">?</span> t <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">default</span><span class=\"token operator\">:</span> t <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            <span class=\"token keyword\">var</span> l <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>t <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">e</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Cannot call a class as a function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>t<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">ReferenceError</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"this hasn't been initialised - super() hasn't been called\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span>e <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'object'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> e<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> t <span class=\"token operator\">:</span> e<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>__proto__ <span class=\"token operator\">||</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">getPrototypeOf</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">resolveOptions</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">listenClick</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">null</span> <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Super expression must either be null or a function, not '</span> <span class=\"token operator\">+</span> <span class=\"token keyword\">typeof</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>e <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">constructor</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">enumerable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">writable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">configurable</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                            e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>Object<span class=\"token punctuation\">.</span>setPrototypeOf <span class=\"token operator\">?</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">setPrototypeOf</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>__proto__ <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token function\">i</span><span class=\"token punctuation\">(</span>\n                        o<span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">[</span>\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'resolveOptions'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action <span class=\"token operator\">=</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>action <span class=\"token operator\">?</span> t<span class=\"token punctuation\">.</span>action <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>defaultAction<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>target <span class=\"token operator\">=</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>target <span class=\"token operator\">?</span> t<span class=\"token punctuation\">.</span>target <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>defaultTarget<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text <span class=\"token operator\">=</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>text <span class=\"token operator\">?</span> t<span class=\"token punctuation\">.</span>text <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>defaultText<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container <span class=\"token operator\">=</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">===</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> t<span class=\"token punctuation\">.</span>container <span class=\"token operator\">:</span> document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'listenClick'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>listener <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                        <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">onClick</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'onClick'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>delegateTarget <span class=\"token operator\">||</span> t<span class=\"token punctuation\">.</span>currentTarget<span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">a<span class=\"token punctuation\">.</span>default</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                                            <span class=\"token literal-property property\">action</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">action</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">target</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">text</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">container</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">trigger</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span>\n\n                                            <span class=\"token literal-property property\">emitter</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span>\n                                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'defaultAction'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">return</span> <span class=\"token function\">s</span><span class=\"token punctuation\">(</span><span class=\"token string\">'action'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'defaultTarget'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token function\">s</span><span class=\"token punctuation\">(</span><span class=\"token string\">'target'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'defaultText'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">return</span> <span class=\"token function\">s</span><span class=\"token punctuation\">(</span><span class=\"token string\">'text'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'destroy'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>listener<span class=\"token punctuation\">.</span><span class=\"token function\">destroy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction<span class=\"token punctuation\">.</span><span class=\"token function\">destroy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>clipboardAction <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">[</span>\n                            <span class=\"token punctuation\">{</span>\n                                <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'isSupported'</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'copy'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cut'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                                        e <span class=\"token operator\">=</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t <span class=\"token operator\">?</span> <span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span>\n                                        n <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>document<span class=\"token punctuation\">.</span>queryCommandSupported<span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                                        e<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                            n <span class=\"token operator\">=</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>document<span class=\"token punctuation\">.</span><span class=\"token function\">queryCommandSupported</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                        n\n                                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">]</span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    o\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">function</span> <span class=\"token function\">s</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token string\">'data-clipboard-'</span> <span class=\"token operator\">+</span> t<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            t<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> l<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token string\">'use strict'</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> o<span class=\"token punctuation\">,</span>\n                r <span class=\"token operator\">=</span>\n                    <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'symbol'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol<span class=\"token punctuation\">.</span>iterator\n                        <span class=\"token operator\">?</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span>\n                        <span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                              <span class=\"token keyword\">return</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> Symbol <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>constructor <span class=\"token operator\">===</span> Symbol <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">!==</span> <span class=\"token class-name\">Symbol</span><span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">?</span> <span class=\"token string\">'symbol'</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">;</span>\n                          <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n                i <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> n <span class=\"token operator\">&lt;</span> e<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> n<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> e<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>enumerable <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span>enumerable <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>configurable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span> <span class=\"token keyword\">in</span> o <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>writable <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span>key<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">return</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                a <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">2</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                c <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> a<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> o<span class=\"token punctuation\">.</span>__esModule <span class=\"token operator\">?</span> o <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">default</span><span class=\"token operator\">:</span> o <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">var</span> u <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">function</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>t <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">e</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Cannot call a class as a function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">resolveOptions</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">initSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    <span class=\"token function\">i</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">[</span>\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'resolveOptions'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>action<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>emitter <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>emitter<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>target <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>trigger <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>trigger<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>selectedText <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'initSelection'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text <span class=\"token operator\">?</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">selectFake</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>target <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">selectTarget</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'selectFake'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span>\n                                    e <span class=\"token operator\">=</span> <span class=\"token string\">'rtl'</span> <span class=\"token operator\">==</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'dir'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeFake</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">fakeHandlerCallback</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                        <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">removeFake</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandler <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandlerCallback<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'textarea'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>fontSize <span class=\"token operator\">=</span> <span class=\"token string\">'12pt'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>border <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>padding <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>margin <span class=\"token operator\">=</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>position <span class=\"token operator\">=</span> <span class=\"token string\">'absolute'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">[</span>e <span class=\"token operator\">?</span> <span class=\"token string\">'right'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'left'</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">'-9999px'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span>pageYOffset <span class=\"token operator\">||</span> document<span class=\"token punctuation\">.</span>documentElement<span class=\"token punctuation\">.</span>scrollTop<span class=\"token punctuation\">;</span>\n\n                                <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>style<span class=\"token punctuation\">.</span>top <span class=\"token operator\">=</span> n <span class=\"token operator\">+</span> <span class=\"token string\">'px'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">.</span>value <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>selectedText <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">copyText</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'removeFake'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandler <span class=\"token operator\">&amp;&amp;</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandlerCallback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandler <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeHandlerCallback <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">removeChild</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>fakeElem <span class=\"token operator\">=</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'selectTarget'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>selectedText <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">copyText</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'copyText'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n                                    e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">execCommand</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    e <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">handleResult</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'handleResult'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>emitter<span class=\"token punctuation\">.</span><span class=\"token function\">emit</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">?</span> <span class=\"token string\">'success'</span> <span class=\"token operator\">:</span> <span class=\"token string\">'error'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token literal-property property\">action</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action<span class=\"token punctuation\">,</span>\n\n                                    <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>selectedText<span class=\"token punctuation\">,</span>\n\n                                    <span class=\"token literal-property property\">trigger</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>trigger<span class=\"token punctuation\">,</span>\n\n                                    <span class=\"token literal-property property\">clearSelection</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">clearSelection</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span>\n                                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'clearSelection'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>trigger <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>trigger<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">getSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeAllRanges</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'destroy'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">removeFake</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'action'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">set</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">&lt;</span> arguments<span class=\"token punctuation\">.</span>length <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> arguments<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">:</span> <span class=\"token string\">'copy'</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_action <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'copy'</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_action <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'cut'</span> <span class=\"token operator\">!==</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_action<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                                    <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Invalid \"action\" value, use either \"copy\" or \"cut\"'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">get</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_action<span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token string\">'target'</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">set</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>t <span class=\"token operator\">||</span> <span class=\"token string\">'object'</span> <span class=\"token operator\">!==</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">===</span> t <span class=\"token operator\">?</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">:</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token number\">1</span> <span class=\"token operator\">!==</span> t<span class=\"token punctuation\">.</span>nodeType<span class=\"token punctuation\">)</span>\n                                        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Invalid \"target\" value, use a valid Element'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'copy'</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'disabled'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                                        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Invalid \"target\" attribute. Please use \"readonly\" instead of \"disabled\" attribute'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'cut'</span> <span class=\"token operator\">===</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>action <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'disabled'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                                        <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span>\n                                            <span class=\"token string\">'Invalid \"target\" attribute. You can\\'t cut text from elements with \"readonly\" or \"disabled\" attributes'</span>\n                                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_target <span class=\"token operator\">=</span> t<span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span>\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token function-variable function\">get</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>_target<span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    e\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            t<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> u<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            t<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> e<span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'SELECT'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">)</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'INPUT'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>nodeName <span class=\"token operator\">||</span> <span class=\"token string\">'TEXTAREA'</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    n <span class=\"token operator\">||</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">select</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">setSelectionRange</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">||</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">removeAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'readonly'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n                    t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'contenteditable'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">focus</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">getSelection</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        r <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createRange</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    r<span class=\"token punctuation\">.</span><span class=\"token function\">selectNodeContents</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span><span class=\"token function\">removeAllRanges</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span><span class=\"token function\">addRange</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n\n                <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">function</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n            <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>prototype <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token function-variable function\">on</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">fn</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">ctx</span><span class=\"token operator\">:</span> n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">once</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        o<span class=\"token punctuation\">.</span><span class=\"token function\">off</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">e</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>_ <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">emit</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>arguments<span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> r <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> o <span class=\"token operator\">&lt;</span> r<span class=\"token punctuation\">;</span> o<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span>\n                        n<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">fn</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>ctx<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">off</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        o <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n                        r <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> a <span class=\"token operator\">=</span> o<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> a<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> o<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fn <span class=\"token operator\">!==</span> e <span class=\"token operator\">&amp;&amp;</span> o<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>fn<span class=\"token punctuation\">.</span>_ <span class=\"token operator\">!==</span> e <span class=\"token operator\">&amp;&amp;</span> r<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> r<span class=\"token punctuation\">.</span>length <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> r<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token keyword\">delete</span> n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> d <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">5</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                h <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">6</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            t<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>n<span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Missing required arguments'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">string</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Second argument must be a String'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">fn</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Third argument must be a Function'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">node</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token punctuation\">(</span>s <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>f <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>l <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token function-variable function\">destroy</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                l<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">nodeList</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>c <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">(</span>u <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            t<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                        <span class=\"token punctuation\">{</span>\n                            <span class=\"token function-variable function\">destroy</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                                    t<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                            <span class=\"token punctuation\">}</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">string</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">h</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">TypeError</span><span class=\"token punctuation\">(</span><span class=\"token string\">'First argument must be a String, HTMLElement, HTMLCollection, or NodeList'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">var</span> o<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">,</span> s<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">node</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> t <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">HTMLElement</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">1</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>nodeType<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">nodeList</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span> <span class=\"token operator\">!==</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'[object NodeList]'</span> <span class=\"token operator\">===</span> e <span class=\"token operator\">||</span> <span class=\"token string\">'[object HTMLCollection]'</span> <span class=\"token operator\">===</span> e<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'length'</span> <span class=\"token keyword\">in</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0</span> <span class=\"token operator\">===</span> t<span class=\"token punctuation\">.</span>length <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">node</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">string</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t <span class=\"token operator\">||</span> t <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">String</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">fn</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token string\">'[object Function]'</span> <span class=\"token operator\">===</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token number\">7</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token keyword\">function</span> <span class=\"token function\">i</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> <span class=\"token function-variable function\">i</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> o</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>delegateTarget <span class=\"token operator\">=</span> <span class=\"token function\">a</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>target<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>delegateTarget <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">o</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n                    t<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                    <span class=\"token punctuation\">{</span>\n                        <span class=\"token function-variable function\">destroy</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                            t<span class=\"token punctuation\">.</span><span class=\"token function\">removeEventListener</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                        <span class=\"token punctuation\">}</span>\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            t<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>addEventListener\n                    <span class=\"token operator\">?</span> <span class=\"token function\">i</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span>\n                    <span class=\"token operator\">:</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> n\n                    <span class=\"token operator\">?</span> <span class=\"token function\">i</span><span class=\"token punctuation\">.</span><span class=\"token function\">bind</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> document<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> arguments<span class=\"token punctuation\">)</span>\n                    <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n                      <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                          <span class=\"token keyword\">return</span> <span class=\"token function\">i</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> Element <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span>matches<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token class-name\">Element</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">;</span>\n\n                n<span class=\"token punctuation\">.</span>matches <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>matchesSelector <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span>mozMatchesSelector <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span>msMatchesSelector <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span>oMatchesSelector <span class=\"token operator\">||</span> n<span class=\"token punctuation\">.</span>webkitMatchesSelector<span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n\n            t<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">exports</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token number\">9</span> <span class=\"token operator\">!==</span> t<span class=\"token punctuation\">.</span>nodeType<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> t<span class=\"token punctuation\">.</span>matches <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">matches</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">;</span>\n\n                    t <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<hr>\n<h1>Prism.js</h1>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\n<span class=\"token keyword\">var</span> \\_self <span class=\"token operator\">=</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> window <span class=\"token operator\">?</span> window <span class=\"token operator\">:</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> WorkerGlobalScope <span class=\"token operator\">&amp;&amp;</span> self <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">WorkerGlobalScope</span> <span class=\"token operator\">?</span> self <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\nPrism <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">g</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> c <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\blang(?:uage)?-([\\w-]+)\\b</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\na <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">manual</span><span class=\"token operator\">:</span> g<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">&amp;&amp;</span> g<span class=\"token punctuation\">.</span>Prism<span class=\"token punctuation\">.</span>manual<span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">disableWorkerMessageHandler</span><span class=\"token operator\">:</span> g<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">&amp;&amp;</span> g<span class=\"token punctuation\">.</span>Prism<span class=\"token punctuation\">.</span>disableWorkerMessageHandler<span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">util</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function-variable function\">encode</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> e <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">M</span>\n\n<span class=\"token operator\">?</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">M</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">,</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">encode</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>alias<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">?</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span>encode<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> e\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&amp;</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'&amp;amp;'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'&amp;lt;'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\u00a0</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">type</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">objId</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> e<span class=\"token punctuation\">.</span><span class=\"token operator\">**</span>id <span class=\"token operator\">||</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> <span class=\"token string\">'**id'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token operator\">++</span>a <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>\\_\\_id<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">clone</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> r<span class=\"token punctuation\">,</span>\n\na<span class=\"token punctuation\">,</span>\n\ni <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">type</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">case</span> <span class=\"token string\">'Object'</span><span class=\"token operator\">:</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">objId</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> l <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> r<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">case</span> <span class=\"token string\">'Array'</span><span class=\"token operator\">:</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">objId</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nt<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">?</span> t<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\nr<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nr<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n\n<span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">languages</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function-variable function\">extend</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">clone</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> t <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">)</span> n<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> n<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">insertBefore</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t <span class=\"token operator\">||</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\ni <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> l <span class=\"token keyword\">in</span> r<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">==</span> e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">)</span> a<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\na<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> r<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> t<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token constant\">DFS</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\na <span class=\"token operator\">===</span> s <span class=\"token operator\">&amp;&amp;</span> e <span class=\"token operator\">!=</span> n <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ni\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">DFS</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\nr <span class=\"token operator\">=</span> r <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span>objId<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> l <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function\">n</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> t <span class=\"token operator\">||</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\ns <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">type</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token string\">'Object'</span> <span class=\"token operator\">!==</span> s <span class=\"token operator\">||</span> r<span class=\"token punctuation\">[</span><span class=\"token function\">i</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> <span class=\"token string\">'Array'</span> <span class=\"token operator\">!==</span> s <span class=\"token operator\">||</span> r<span class=\"token punctuation\">[</span><span class=\"token function\">i</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">[</span><span class=\"token function\">i</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">[</span><span class=\"token function\">i</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">plugins</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">highlightAll</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlightAllUnder</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">highlightAllUnder</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">callback</span><span class=\"token operator\">:</span> n<span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">selector</span><span class=\"token operator\">:</span> <span class=\"token string\">'code[class_=\"language-\"], [class*=\"language-\"] code, code[class*=\"lang-\"], [class*=\"lang-\"] code'</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-highlightall'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r<span class=\"token punctuation\">,</span> i <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>elements <span class=\"token operator\">||</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>selector<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> l <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> i<span class=\"token punctuation\">[</span>l<span class=\"token operator\">++</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlightElement</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token operator\">===</span> a<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">highlightElement</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span> r <span class=\"token operator\">=</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">,</span> i <span class=\"token operator\">=</span> e<span class=\"token punctuation\">;</span> i <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>c<span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> i <span class=\"token operator\">=</span> i<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">;</span>\n\ni <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\s+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' language-'</span> <span class=\"token operator\">+</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne<span class=\"token punctuation\">.</span>parentNode <span class=\"token operator\">&amp;&amp;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">pre</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> i<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\s+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' language-'</span> <span class=\"token operator\">+</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> l <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">element</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">language</span><span class=\"token operator\">:</span> r<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">grammar</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">code</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>textContent <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">o</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>highlightedCode <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-insert'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> l<span class=\"token punctuation\">.</span>highlightedCode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'after-highlight'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'complete'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nn <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">n</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-sanity-check'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-highlight'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">.</span>grammar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">&amp;&amp;</span> g<span class=\"token punctuation\">.</span>Worker<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Worker</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onmessage</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function\">o</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ns<span class=\"token punctuation\">.</span><span class=\"token function\">postMessage</span><span class=\"token punctuation\">(</span>\n\n<span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">language</span><span class=\"token operator\">:</span> l<span class=\"token punctuation\">.</span>language<span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">code</span><span class=\"token operator\">:</span> l<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">immediateClose</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlight</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">.</span>grammar<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">.</span>language<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">else</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">encode</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">else</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'complete'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">highlight</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">code</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">grammar</span><span class=\"token operator\">:</span> a<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">language</span><span class=\"token operator\">:</span> n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-tokenize'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>tokens <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span><span class=\"token function\">tokenize</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>grammar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'after-tokenize'</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">encode</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>tokens<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>language<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">matchGrammar</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> l</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token keyword\">in</span> n<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> n<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>o <span class=\"token operator\">==</span> l<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\ns <span class=\"token operator\">=</span> <span class=\"token string\">'Array'</span> <span class=\"token operator\">===</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">type</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> s <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> g <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> g <span class=\"token operator\">&lt;</span> s<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> <span class=\"token operator\">++</span>g<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> c <span class=\"token operator\">=</span> s<span class=\"token punctuation\">[</span>g<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\nu <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">,</span>\n\nh <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>c<span class=\"token punctuation\">.</span>lookbehind<span class=\"token punctuation\">,</span>\n\nf <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>c<span class=\"token punctuation\">.</span>greedy<span class=\"token punctuation\">,</span>\n\nd <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\nm <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span>alias<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>f <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>c<span class=\"token punctuation\">.</span>pattern<span class=\"token punctuation\">.</span>global<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> p <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span>pattern<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[imuy]_$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\nc<span class=\"token punctuation\">.</span>pattern <span class=\"token operator\">=</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">.</span>pattern<span class=\"token punctuation\">.</span>source<span class=\"token punctuation\">,</span> p <span class=\"token operator\">+</span> <span class=\"token string\">'g'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\nc <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span>pattern <span class=\"token operator\">||</span> c<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> y <span class=\"token operator\">=</span> t<span class=\"token punctuation\">,</span> v <span class=\"token operator\">=</span> r<span class=\"token punctuation\">;</span> y <span class=\"token operator\">&lt;</span> a<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> v <span class=\"token operator\">+=</span> a<span class=\"token punctuation\">[</span>y<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> <span class=\"token operator\">++</span>y<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> k <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>y<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> e<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>k <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">M</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>f <span class=\"token operator\">&amp;&amp;</span> y <span class=\"token operator\">!=</span> a<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">.</span>lastIndex <span class=\"token operator\">=</span> v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>x <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token keyword\">var</span> b <span class=\"token operator\">=</span> x<span class=\"token punctuation\">.</span>index <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>h <span class=\"token operator\">?</span> x<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> w <span class=\"token operator\">=</span> x<span class=\"token punctuation\">.</span>index <span class=\"token operator\">+</span> x<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> <span class=\"token constant\">A</span> <span class=\"token operator\">=</span> y<span class=\"token punctuation\">,</span> <span class=\"token constant\">P</span> <span class=\"token operator\">=</span> v<span class=\"token punctuation\">,</span> <span class=\"token constant\">O</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\n<span class=\"token constant\">A</span> <span class=\"token operator\">&lt;</span> <span class=\"token constant\">O</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">P</span> <span class=\"token operator\">&lt;</span> w <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>a<span class=\"token punctuation\">[</span><span class=\"token constant\">A</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>type <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>a<span class=\"token punctuation\">[</span><span class=\"token constant\">A</span> <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>greedy<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">++</span><span class=\"token constant\">A</span>\n\n<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token constant\">P</span> <span class=\"token operator\">+=</span> a<span class=\"token punctuation\">[</span><span class=\"token constant\">A</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;=</span> b <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">++</span>y<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>v <span class=\"token operator\">=</span> <span class=\"token constant\">P</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">[</span>y<span class=\"token punctuation\">]</span> <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">M</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token constant\">N</span> <span class=\"token operator\">=</span> <span class=\"token constant\">A</span> <span class=\"token operator\">-</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>k <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">,</span> <span class=\"token constant\">P</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">.</span>index <span class=\"token operator\">-=</span> v<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n\nc<span class=\"token punctuation\">.</span>lastIndex <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> x <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">N</span> <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\nh <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>d <span class=\"token operator\">=</span> x<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> x<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">:</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nw <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>b <span class=\"token operator\">=</span> x<span class=\"token punctuation\">.</span>index <span class=\"token operator\">+</span> d<span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>x <span class=\"token operator\">=</span> x<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> j <span class=\"token operator\">=</span> k<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">S</span> <span class=\"token operator\">=</span> k<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">E</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>y<span class=\"token punctuation\">,</span> <span class=\"token constant\">N</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\nj <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">++</span>y<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>v <span class=\"token operator\">+=</span> j<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">E</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>j<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> <span class=\"token operator\">*</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">M</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> u <span class=\"token operator\">?</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span><span class=\"token function\">tokenize</span><span class=\"token punctuation\">(</span>x<span class=\"token punctuation\">,</span> u<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> x<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token constant\">E</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token operator\">*</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">S</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token constant\">E</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token constant\">S</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">splice</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token constant\">E</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token number\">1</span> <span class=\"token operator\">!=</span> <span class=\"token constant\">N</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span><span class=\"token function\">matchGrammar</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> v<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ni<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">tokenize</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\nt <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>rest<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token keyword\">in</span> t<span class=\"token punctuation\">)</span> a<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> t<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">delete</span> a<span class=\"token punctuation\">.</span>rest<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span><span class=\"token function\">matchGrammar</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">hooks</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">all</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">add</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span>all<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">run</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span>all<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&amp;&amp;</span> n<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> t<span class=\"token punctuation\">,</span> r <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span>r<span class=\"token operator\">++</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">Token</span><span class=\"token operator\">:</span> <span class=\"token constant\">M</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>type <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>content <span class=\"token operator\">=</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>alias <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">|</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>greedy <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>g<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">=</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">stringify</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">return</span> e\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">tag</span><span class=\"token operator\">:</span> <span class=\"token string\">'span'</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">classes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'token'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">attributes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">language</span><span class=\"token operator\">:</span> a\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>alias<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>alias<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> e<span class=\"token punctuation\">.</span>alias <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">.</span>alias<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>classes<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'wrap'</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">keys</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>attributes<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> e <span class=\"token operator\">+</span> <span class=\"token string\">'=\"'</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>attributes<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\"</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'&amp;quot;'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">'\"'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token string\">'&lt;'</span> <span class=\"token operator\">+</span> n<span class=\"token punctuation\">.</span>tag <span class=\"token operator\">+</span> <span class=\"token string\">' class=\"'</span> <span class=\"token operator\">+</span> n<span class=\"token punctuation\">.</span>classes<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">'\"'</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">?</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> r <span class=\"token operator\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">'>'</span> <span class=\"token operator\">+</span> n<span class=\"token punctuation\">.</span>content <span class=\"token operator\">+</span> <span class=\"token string\">'&lt;/'</span> <span class=\"token operator\">+</span> n<span class=\"token punctuation\">.</span>tag <span class=\"token operator\">+</span> <span class=\"token string\">'>'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token operator\">!</span>g<span class=\"token punctuation\">.</span>document<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\ng<span class=\"token punctuation\">.</span>addEventListener <span class=\"token operator\">&amp;&amp;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>disableWorkerMessageHandler <span class=\"token operator\">||</span>\n\ng<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>\n\n<span class=\"token string\">'message'</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nn <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>language<span class=\"token punctuation\">,</span>\n\nt <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">,</span>\n\nr <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>immediateClose<span class=\"token punctuation\">;</span>\n\ng<span class=\"token punctuation\">.</span><span class=\"token function\">postMessage</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlight</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> r <span class=\"token operator\">&amp;&amp;</span> g<span class=\"token punctuation\">.</span><span class=\"token function\">close</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token operator\">!</span><span class=\"token number\">1</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span>currentScript <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByTagName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'script'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\ne <span class=\"token operator\">&amp;&amp;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>filename <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>src<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>manual <span class=\"token operator\">||</span>\n\ne<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-manual'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token string\">'loading'</span> <span class=\"token operator\">!==</span> document<span class=\"token punctuation\">.</span>readyState\n\n<span class=\"token operator\">?</span> window<span class=\"token punctuation\">.</span>requestAnimationFrame\n\n<span class=\"token operator\">?</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>highlightAll<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>highlightAll<span class=\"token punctuation\">,</span> <span class=\"token number\">16</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'DOMContentLoaded'</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">.</span>highlightAll<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">C</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>\\_self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> module <span class=\"token operator\">&amp;&amp;</span> module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> global <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>global<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">comment</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;!--[\\s\\S]_?--></span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">prolog</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;\\?[\\s\\S]+?\\?></span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">doctype</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;!DOCTYPE[\\s\\S]+?></span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">cdata</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;!\\[CDATA\\[[\\s\\S]_?]]></span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">tag</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;\\/?(?!\\d)[^\\s>\\/=$&lt;%]+(?:\\s(?:\\s_[^\\s>\\/=]+(?:\\s*=\\s*(?:\"[^\"]_\"|'[^']_'|[^\\s'\">=]+(?=[\\s>]))|(?=[\\s/>])))+)?\\s*\\/?></span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">tag</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^&lt;\\/?[^\\s>\\/]+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^&lt;\\/?</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">namespace</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[^\\s>\\/:]+:</span><span class=\"token regex-delimiter\">/</span></span> <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'attr-value'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">=\\s*(?:\"[^\"]_\"|'[^']_'|[^\\s'\">=]+)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^=</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^(\\s*)[\"']|[\"']$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">]</span>\n\n                <span class=\"token punctuation\">}</span>\n\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\/?></span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token string-property property\">'attr-name'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n                <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^\\s>\\/]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">namespace</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[^\\s>\\/:]+:</span><span class=\"token regex-delimiter\">/</span></span> <span class=\"token punctuation\">}</span>\n\n            <span class=\"token punctuation\">}</span>\n\n        <span class=\"token punctuation\">}</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">entity</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&amp;#?[\\da-z]{1,8};</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">[</span><span class=\"token string\">'attr-value'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">.</span>entity <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>entity<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    Prism<span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'wrap'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n        <span class=\"token string\">'entity'</span> <span class=\"token operator\">===</span> a<span class=\"token punctuation\">.</span>type <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>attributes<span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&amp;amp;</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'&amp;'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">,</span> <span class=\"token string\">'addInlined'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n        <span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n            <span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">[</span><span class=\"token string\">'language-'</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n                <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^&lt;!\\[CDATA\\[)[\\s\\S]+?(?=\\]\\]>$)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>cdata <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^&lt;!\\[CDATA\\[|\\]\\]>$</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token string-property property\">'included-cdata'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;!\\[CDATA\\[[\\s\\S]*?\\]\\]></span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> s <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nn<span class=\"token punctuation\">[</span><span class=\"token string\">'language-'</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[\\s\\S]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span><span class=\"token string\">'(&lt;**[\\\\s\\\\S]_?>)(?:&lt;!\\\\[CDATA\\\\[[\\\\s\\\\S]_?\\\\]\\\\]>\\\\s*|[\\\\s\\\\S])*?(?=&lt;\\\\/**>)'</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token comment\">/**/</span>g<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'i'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> n\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span><span class=\"token string\">'markup'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cdata'</span><span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>xml <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">extend</span><span class=\"token punctuation\">(</span><span class=\"token string\">'markup'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>html <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>mathml <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>svg <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(\"|')(?:\\\\(?:\\r\\n|[\\s\\S])|(?!\\1)[^\\\\\\r\\n])_\\1</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>css <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">comment</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\/\\*[\\s\\S]_?\\*\\/</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">atrule</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">@[\\w-]+[\\s\\S]_?(?:;|(?=\\s_\\{))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">rule</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">@[\\w-]+</span><span class=\"token regex-delimiter\">/</span></span> <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">url</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span><span class=\"token string\">'url\\\\((?:'</span> <span class=\"token operator\">+</span> t<span class=\"token punctuation\">.</span>source <span class=\"token operator\">+</span> <span class=\"token string\">'|[^\\n\\r()]_)\\\\)'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'i'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">function</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^url</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^\\(|\\)$</span><span class=\"token regex-delimiter\">/</span></span> <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">selector</span><span class=\"token operator\">:</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span><span class=\"token string\">'[^{}\\\\s](?:[^{};\"\\']|'</span> <span class=\"token operator\">+</span> t<span class=\"token punctuation\">.</span>source <span class=\"token operator\">+</span> <span class=\"token string\">')_?(?=\\\\s*\\\\{)'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">string</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">property</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[-\\_a-z\\xA0-\\uFFFF][-\\w\\xa0-\\uffff]*(?=\\s*:)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">important</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">!important\\b</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[-a-z0-9]+(?=\\()</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[(){};:,]</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>css<span class=\"token punctuation\">.</span>atrule<span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">.</span>rest <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>css<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">;</span>\n\ne <span class=\"token operator\">&amp;&amp;</span>\n\n<span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span><span class=\"token function\">addInlined</span><span class=\"token punctuation\">(</span><span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'css'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ns<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span>\n\n<span class=\"token string\">'inside'</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string\">'attr-value'</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token string-property property\">'style-attr'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\s*style=(\"|')(?:\\\\[\\s\\S]|(?!\\1)[^\\\\])*\\1</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token string-property property\">'attr-name'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^\\s*style</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span>inside <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^\\s*=\\s*['\"]|['\"]\\s*$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'attr-value'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">.+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>css <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'language-css'</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\ne<span class=\"token punctuation\">.</span>tag\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>clike <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">comment</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n\n<span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^\\\\])\\/\\*[\\s\\S]*?(?:\\*\\/|$)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^\\\\:])\\/\\/.*</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span>\n\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">string</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n        <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">([\"'])(?:\\\\(?:\\r\\n|[\\s\\S])|(?!\\1)[^\\\\\\r\\n])*\\1</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token string-property property\">'class-name'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n        <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:\\b(?:class|interface|extends|implements|trait|instanceof|new)\\s+)|(?:catch\\s+\\())[\\w.\\\\]+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[.\\\\]</span><span class=\"token regex-delimiter\">/</span></span> <span class=\"token punctuation\">}</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">keyword</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\\b</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">boolean</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b(?:true|false)\\b</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token keyword\">function</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\w+(?=\\()</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">number</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b0x[\\da-f]+\\b|(?:\\b\\d+\\.?\\d*|\\B\\.\\d+)(?:e[+-]?\\d+)?</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">operator</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">--?|\\+\\+?|!=?=?|&lt;=?|>=?|==?=?|&amp;&amp;?|\\|\\|?|\\?|\\*|\\/|~|\\^|%</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[{}[\\];(),.:]</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">extend</span><span class=\"token punctuation\">(</span><span class=\"token string\">'clike'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n    <span class=\"token string-property property\">'class-name'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n\n        Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>clike<span class=\"token punctuation\">[</span><span class=\"token string\">'class-name'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token punctuation\">{</span>\n\n            <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^$\\w\\xA0-\\uFFFF])[\\_$A-Z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]_(?=\\.(?:prototype|constructor))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">keyword</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n\n<span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:^|})\\s_)(?:catch|finally)\\b</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span>\n\n<span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^.])\\b(?:as|async(?=\\s*(?:function\\b|\\(|[$\\w\\xA0-\\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\\b</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">number</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b(?:(?:0[xX](&lt;?:[\\dA-Fa-f](?:_[\\dA-Fa-f])?>)+|0[bB](&lt;?:[01](?:_[01])?>)+|0[oO](&lt;?:[0-7](?:_[0-7])?>)+)n?|(?:\\d(?:*\\d)?)+n|NaN|Infinity)\\b|(?:\\b(?:\\d(?:*\\d)?)+\\.?(?:\\d(?:\\_\\d)?)*|\\B\\.(?:\\d(?:_\\d)?)+)(?:[Ee][+-]?(?:\\d(?:_\\d)?)+)?</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[\\_$a-zA-Z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]_(?=\\s_(?:\\.\\s*(?:apply|bind|call)\\s*)?\\()</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">operator</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">-[-=]?|\\+[+=]?|!=?=?|&lt;&lt;?=?|>>?>?=?|=(?:==?|>)?|&amp;[&amp;=]?|\\|[|=]?|\\*\\*?=?|\\/=?|~|\\^=?|%=?|\\?|\\.{3}</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript<span class=\"token punctuation\">[</span><span class=\"token string\">'class-name'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pattern <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(\\b(?:class|interface|extends|implements|instanceof|new)\\s+)[\\w.\\\\]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span><span class=\"token string\">'javascript'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'keyword'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">regex</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:^|[^$\\w\\xa0-\\uffff.\"'\\])\\s])\\s*)\\/(\\[(?:[^\\]\\\\\\r\\n]|\\\\.)*]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[gimyus]{0,6}(?=\\s*($|[\\r\\n,.;})\\]]))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token string-property property\">'function-variable'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n            <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span>\n\n                <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[_$a-zA-Z\\xA0-\\uFFFF][$\\w\\xA0-\\uFFFF]*(?=\\s*[=:]\\s*(?:async\\s*)?(?:\\bfunction\\b|(?:\\((?:[^()]|\\([^()]*\\))_\\)|[\\_$a-zA-Z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]_)\\s*=>))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'function'</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">parameter</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(function(?:\\s+[\\_$A-Za-z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]*)?\\s*\\(\\s*)(?!\\s)(?:[^()]|\\([^()]_\\))+?(?=\\s_\\))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[\\_$a-z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]_(?=\\s_=>)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(\\(\\s*)(?!\\s)(?:[^()]|\\([^()]*\\))+?(?=\\s*\\)\\s*=>)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span>\n\n<span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:\\b|\\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\\w\\xA0-\\uFFFF]))(?:[\\_$A-Za-z\\xA0-\\uFFFF][$\\w\\xa0-\\uffff]_\\s_)\\(\\s*)(?!\\s)(?:[^()]|\\([^()]*\\))+?(?=\\s*\\)\\s*\\{)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">constant</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b[A-Z](?:[A-Z_]|\\dx?)_\\b</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span><span class=\"token string\">'javascript'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token string-property property\">'template-string'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">`(?:\\\\[\\s\\S]|\\${(?:[^{}]|{(?:[^{}]|{[^}]_})_})+}|[^\\\\`])_`</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">interpolation</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\${(?:[^{}]|{(?:[^{}]|{[^}]_})_})+}</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token string-property property\">'interpolation-punctuation'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^\\${|}$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'punctuation'</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">rest</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">string</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[\\s\\S]+</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup <span class=\"token operator\">&amp;&amp;</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span><span class=\"token function\">addInlined</span><span class=\"token punctuation\">(</span><span class=\"token string\">'script'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'javascript'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>js <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> self <span class=\"token operator\">&amp;&amp;</span> self<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">&amp;&amp;</span> self<span class=\"token punctuation\">.</span>document<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\ni <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">n</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nPrism<span class=\"token punctuation\">.</span>plugins<span class=\"token punctuation\">.</span>toolbar <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>plugins<span class=\"token punctuation\">.</span>toolbar<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">registerButton</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> e<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span>\n\n<span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> n\n\n<span class=\"token operator\">?</span> <span class=\"token function-variable function\">n</span>\n\n<span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> e<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token string\">'function'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> n<span class=\"token punctuation\">.</span>onClick\n\n<span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>type <span class=\"token operator\">=</span> <span class=\"token string\">'button'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'click'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\nn<span class=\"token punctuation\">.</span><span class=\"token function\">onClick</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> n<span class=\"token punctuation\">.</span>url\n\n<span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>href <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>url<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'span'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>text<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nt <span class=\"token keyword\">in</span> i <span class=\"token operator\">?</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">warn</span><span class=\"token punctuation\">(</span><span class=\"token string\">'There is a button with the key \"'</span> <span class=\"token operator\">+</span> t <span class=\"token operator\">+</span> <span class=\"token string\">'\" registered already.'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> r<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>plugins<span class=\"token punctuation\">.</span>toolbar<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">hook</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">pre</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>t<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span><span class=\"token string\">'code-toolbar'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\ne<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'code-toolbar'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\no<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'toolbar'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ndocument<span class=\"token punctuation\">.</span>body<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-toolbar-order'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n\n<span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span>body\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-toolbar-order'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">','</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> i<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> n<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nr<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nn<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'toolbar-item'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> o<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token string\">'label'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">.</span>parentNode<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">pre</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-label'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n<span class=\"token punctuation\">,</span>\n\na<span class=\"token punctuation\">,</span>\n\no <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-label'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n\na <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'template#'</span> <span class=\"token operator\">+</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\na\n\n<span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-url'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>href <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">getAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-url'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'span'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">=</span> o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nn\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'complete'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> self <span class=\"token operator\">&amp;&amp;</span> self<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">&amp;&amp;</span> self<span class=\"token punctuation\">.</span>document<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>plugins<span class=\"token punctuation\">.</span>toolbar<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span>ClipboardJS <span class=\"token operator\">||</span> <span class=\"token keyword\">void</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\nr <span class=\"token operator\">||</span> <span class=\"token string\">'function'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> require <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'clipboard'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>r<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'script'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'head'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onload</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> window<span class=\"token punctuation\">.</span>ClipboardJS<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> i<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> i<span class=\"token punctuation\">.</span><span class=\"token function\">pop</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">.</span>src <span class=\"token operator\">=</span> <span class=\"token string\">'https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne<span class=\"token punctuation\">.</span><span class=\"token function\">appendChild</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\nPrism<span class=\"token punctuation\">.</span>plugins<span class=\"token punctuation\">.</span>toolbar<span class=\"token punctuation\">.</span><span class=\"token function\">registerButton</span><span class=\"token punctuation\">(</span><span class=\"token string\">'copy-to-clipboard'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'a'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">=</span> <span class=\"token string\">'Copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> r <span class=\"token operator\">?</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> i<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">r</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function-variable function\">text</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> e<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\no<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'success'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">=</span> <span class=\"token string\">'Copied'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\no<span class=\"token punctuation\">.</span><span class=\"token function\">on</span><span class=\"token punctuation\">(</span><span class=\"token string\">'error'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">=</span> <span class=\"token string\">'Press Ctrl+C to copy'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\nt<span class=\"token punctuation\">.</span>textContent <span class=\"token operator\">=</span> <span class=\"token string\">'Copy'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">5e3</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> console<span class=\"token punctuation\">.</span><span class=\"token function\">warn</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Copy to Clipboard plugin loaded before Toolbar plugin.'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">/</span>_ PrismJS <span class=\"token number\">1.24</span><span class=\"token number\">.1</span>\n\n<span class=\"token literal-property property\">https</span><span class=\"token operator\">:</span><span class=\"token operator\">/</span><span class=\"token operator\">/</span>prismjs<span class=\"token punctuation\">.</span>com<span class=\"token operator\">/</span>download<span class=\"token punctuation\">.</span>html#themes<span class=\"token operator\">=</span>prism<span class=\"token operator\">&amp;</span>languages<span class=\"token operator\">=</span>markup<span class=\"token operator\">+</span>css<span class=\"token operator\">+</span>clike<span class=\"token operator\">+</span>javascript _<span class=\"token operator\">/</span>\n\n<span class=\"token keyword\">var</span> \\_self <span class=\"token operator\">=</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> window <span class=\"token operator\">?</span> window <span class=\"token operator\">:</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> WorkerGlobalScope <span class=\"token operator\">&amp;&amp;</span> self <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">WorkerGlobalScope</span> <span class=\"token operator\">?</span> self <span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\nPrism <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">u</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> c <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\blang(?:uage)?-([\\w-]+)\\b</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\nn <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\ne <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">M</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">manual</span><span class=\"token operator\">:</span> u<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">&amp;&amp;</span> u<span class=\"token punctuation\">.</span>Prism<span class=\"token punctuation\">.</span>manual<span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">disableWorkerMessageHandler</span><span class=\"token operator\">:</span> u<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">&amp;&amp;</span> u<span class=\"token punctuation\">.</span>Prism<span class=\"token punctuation\">.</span>disableWorkerMessageHandler<span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">util</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function-variable function\">encode</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> n <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">W</span>\n\n<span class=\"token operator\">?</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">W</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">,</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">.</span>alias<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">?</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> n\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&amp;</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'&amp;amp;'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'&amp;lt;'</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\u00a0</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">type</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token class-name\">Object</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">8</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">-</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">objId</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> e<span class=\"token punctuation\">.</span><span class=\"token operator\">**</span>id <span class=\"token operator\">||</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> <span class=\"token string\">'**id'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token operator\">++</span>n <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span><span class=\"token operator\">**</span>id<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">clone</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> a<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">switch</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> r <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">type</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">case</span> <span class=\"token string\">'Object'</span><span class=\"token operator\">:</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">objId</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> r<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> i <span class=\"token keyword\">in</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> a<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">case</span> <span class=\"token string\">'Array'</span><span class=\"token operator\">:</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token punctuation\">(</span>n <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">objId</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nr<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">?</span> r<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span>\n\n<span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\ne<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\na<span class=\"token punctuation\">[</span>n<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token function\">t</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\na<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">default</span><span class=\"token operator\">:</span>\n\n<span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">getLanguage</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> e <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>c<span class=\"token punctuation\">.</span><span class=\"token function\">test</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> e <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentElement<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> e <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token string\">'none'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">currentScript</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'undefined'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> document<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'currentScript'</span> <span class=\"token keyword\">in</span> document<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> document<span class=\"token punctuation\">.</span>currentScript<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">throw</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Error</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">at [^(\\r\\n]_\\((._):.+:.+\\)$</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>stack<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                                <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByTagName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'script'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token keyword\">in</span> t<span class=\"token punctuation\">)</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>src <span class=\"token operator\">==</span> n<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">}</span>\n\n                            <span class=\"token keyword\">return</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token function-variable function\">isActive</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token string\">'no-'</span> <span class=\"token operator\">+</span> n<span class=\"token punctuation\">;</span> e<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                            <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">;</span>\n\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span><span class=\"token function\">contains</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span><span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n                            e <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentElement<span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">}</span>\n\n                        <span class=\"token keyword\">return</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>t<span class=\"token punctuation\">;</span>\n\n                    <span class=\"token punctuation\">}</span>\n\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">languages</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n                    <span class=\"token literal-property property\">plain</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">plaintext</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">text</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">txt</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span>\n\n                    <span class=\"token function-variable function\">extend</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                        <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">clone</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token keyword\">in</span> n<span class=\"token punctuation\">)</span> t<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">return</span> t<span class=\"token punctuation\">;</span>\n\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token function-variable function\">insertBefore</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">t<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                        <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> r <span class=\"token operator\">||</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n                            i <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> l <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">)</span>\n\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">==</span> e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token keyword\">in</span> n<span class=\"token punctuation\">)</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                n<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">}</span>\n\n                        <span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> r<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n                            <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token constant\">DFS</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                                n <span class=\"token operator\">===</span> s <span class=\"token operator\">&amp;&amp;</span> e <span class=\"token operator\">!=</span> t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                            i\n\n                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token function-variable function\">DFS</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                        a <span class=\"token operator\">=</span> a <span class=\"token operator\">||</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span>objId<span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> l <span class=\"token keyword\">in</span> n<span class=\"token punctuation\">)</span>\n\n                            <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                                <span class=\"token function\">t</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> r <span class=\"token operator\">||</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token keyword\">var</span> o <span class=\"token operator\">=</span> n<span class=\"token punctuation\">[</span>l<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n                                    s <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">type</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                <span class=\"token string\">'Object'</span> <span class=\"token operator\">!==</span> s <span class=\"token operator\">||</span> a<span class=\"token punctuation\">[</span><span class=\"token function\">i</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">?</span> <span class=\"token string\">'Array'</span> <span class=\"token operator\">!==</span> s <span class=\"token operator\">||</span> a<span class=\"token punctuation\">[</span><span class=\"token function\">i</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">[</span><span class=\"token function\">i</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">[</span><span class=\"token function\">i</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token punctuation\">}</span>\n\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">plugins</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">highlightAll</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                    <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlightAllUnder</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">highlightAllUnder</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                    <span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n                        <span class=\"token literal-property property\">callback</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">container</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span>\n\n                        <span class=\"token literal-property property\">selector</span><span class=\"token operator\">:</span> <span class=\"token string\">'code[class*=\"language-\"], [class*=\"language-\"] code, code[class*=\"lang-\"], [class*=\"lang-\"] code'</span>\n\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-highlightall'</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>elements <span class=\"token operator\">=</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>container<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>selector<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-all-elements-highlight'</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> a<span class=\"token punctuation\">,</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">=</span> r<span class=\"token punctuation\">.</span>elements<span class=\"token punctuation\">[</span>i<span class=\"token operator\">++</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlightElement</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token operator\">===</span> n<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">.</span>callback<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">highlightElement</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                    <span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">getLanguage</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        a <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                    e<span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\s+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' language-'</span> <span class=\"token operator\">+</span> r<span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>parentElement<span class=\"token punctuation\">;</span>\n\n                    i <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'pre'</span> <span class=\"token operator\">===</span> i<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">.</span>className <span class=\"token operator\">=</span> i<span class=\"token punctuation\">.</span>className<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">,</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\s+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' language-'</span> <span class=\"token operator\">+</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">var</span> l <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">element</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">language</span><span class=\"token operator\">:</span> r<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">grammar</span><span class=\"token operator\">:</span> a<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">code</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>textContent <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">function</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                        <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>highlightedCode <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-insert'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">.</span>innerHTML <span class=\"token operator\">=</span> l<span class=\"token punctuation\">.</span>highlightedCode<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'after-highlight'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'complete'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                            t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">t</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n\n                        <span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-sanity-check'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">(</span>i <span class=\"token operator\">=</span> l<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">.</span>parentElement<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'pre'</span> <span class=\"token operator\">===</span> i<span class=\"token punctuation\">.</span>nodeName<span class=\"token punctuation\">.</span><span class=\"token function\">toLowerCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>i<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tabindex'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> i<span class=\"token punctuation\">.</span><span class=\"token function\">setAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tabindex'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'0'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token operator\">!</span>l<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">)</span>\n\n                    <span class=\"token punctuation\">)</span>\n\n                        <span class=\"token keyword\">return</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'complete'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">void</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">t</span><span class=\"token punctuation\">.</span><span class=\"token function\">call</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>element<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-highlight'</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">.</span>grammar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n\n                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>n <span class=\"token operator\">&amp;&amp;</span> u<span class=\"token punctuation\">.</span>Worker<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                            <span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Worker</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>filename<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onmessage</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                                <span class=\"token function\">o</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                                s<span class=\"token punctuation\">.</span><span class=\"token function\">postMessage</span><span class=\"token punctuation\">(</span><span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">language</span><span class=\"token operator\">:</span> l<span class=\"token punctuation\">.</span>language<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">code</span><span class=\"token operator\">:</span> l<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">immediateClose</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlight</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">.</span>grammar<span class=\"token punctuation\">,</span> l<span class=\"token punctuation\">.</span>language<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">else</span> <span class=\"token function\">o</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">encode</span><span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">highlight</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                    <span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">code</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">grammar</span><span class=\"token operator\">:</span> n<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">language</span><span class=\"token operator\">:</span> t <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n                        <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'before-tokenize'</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>tokens <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">tokenize</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">.</span>grammar<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'after-tokenize'</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token constant\">W</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">encode</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>tokens<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">.</span>language<span class=\"token punctuation\">)</span>\n\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">tokenize</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>rest<span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                        <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token keyword\">in</span> t<span class=\"token punctuation\">)</span> n<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> t<span class=\"token punctuation\">[</span>r<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">delete</span> n<span class=\"token punctuation\">.</span>rest<span class=\"token punctuation\">;</span>\n\n                    <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">i</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\n                        <span class=\"token constant\">I</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                        <span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token function\">e</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">,</span> l</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                            <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token keyword\">in</span> r<span class=\"token punctuation\">)</span>\n\n                                <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span><span class=\"token function\">hasOwnProperty</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> r<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                                    <span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> r<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                                    s <span class=\"token operator\">=</span> Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> s <span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>s<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> u <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> u <span class=\"token operator\">&lt;</span> s<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> <span class=\"token operator\">++</span>u<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>l <span class=\"token operator\">&amp;&amp;</span> l<span class=\"token punctuation\">.</span>cause <span class=\"token operator\">==</span> o <span class=\"token operator\">+</span> <span class=\"token string\">','</span> <span class=\"token operator\">+</span> u<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n                                        <span class=\"token keyword\">var</span> c <span class=\"token operator\">=</span> s<span class=\"token punctuation\">[</span>u<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n                                            g <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">,</span>\n\n                                            f <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>c<span class=\"token punctuation\">.</span>lookbehind<span class=\"token punctuation\">,</span>\n\n                                            h <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token operator\">!</span>c<span class=\"token punctuation\">.</span>greedy<span class=\"token punctuation\">,</span>\n\n                                            d <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span>alias<span class=\"token punctuation\">;</span>\n\n                                        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>h <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span>c<span class=\"token punctuation\">.</span>pattern<span class=\"token punctuation\">.</span>global<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n                                            <span class=\"token keyword\">var</span> p <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span>pattern<span class=\"token punctuation\">.</span><span class=\"token function\">toString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">match</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[imsuy]*$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\nc<span class=\"token punctuation\">.</span>pattern <span class=\"token operator\">=</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">.</span>pattern<span class=\"token punctuation\">.</span>source<span class=\"token punctuation\">,</span> p <span class=\"token operator\">+</span> <span class=\"token string\">'g'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> v <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span>pattern <span class=\"token operator\">||</span> c<span class=\"token punctuation\">,</span> m <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">,</span> y <span class=\"token operator\">=</span> i<span class=\"token punctuation\">;</span> m <span class=\"token operator\">!==</span> t<span class=\"token punctuation\">.</span>tail <span class=\"token operator\">&amp;&amp;</span> <span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>l <span class=\"token operator\">&amp;&amp;</span> y <span class=\"token operator\">>=</span> l<span class=\"token punctuation\">.</span>reach<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> y <span class=\"token operator\">+=</span> m<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> m <span class=\"token operator\">=</span> m<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> b <span class=\"token operator\">=</span> m<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>length <span class=\"token operator\">></span> n<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>b <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">W</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> k<span class=\"token punctuation\">,</span>\n\nx <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>h<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>k <span class=\"token operator\">=</span> <span class=\"token function\">z</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> w <span class=\"token operator\">=</span> k<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">A</span> <span class=\"token operator\">=</span> k<span class=\"token punctuation\">.</span>index <span class=\"token operator\">+</span> k<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">P</span> <span class=\"token operator\">=</span> y<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">P</span> <span class=\"token operator\">+=</span> m<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> <span class=\"token constant\">P</span> <span class=\"token operator\">&lt;=</span> w<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> m<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">P</span> <span class=\"token operator\">+=</span> m<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token constant\">P</span> <span class=\"token operator\">-=</span> m<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">=</span> <span class=\"token constant\">P</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">.</span>value <span class=\"token keyword\">instanceof</span> <span class=\"token class-name\">W</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> <span class=\"token constant\">E</span> <span class=\"token operator\">=</span> m<span class=\"token punctuation\">;</span> <span class=\"token constant\">E</span> <span class=\"token operator\">!==</span> t<span class=\"token punctuation\">.</span>tail <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">P</span> <span class=\"token operator\">&lt;</span> <span class=\"token constant\">A</span> <span class=\"token operator\">||</span> <span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> <span class=\"token constant\">E</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token constant\">E</span> <span class=\"token operator\">=</span> <span class=\"token constant\">E</span><span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span>\n\nx<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">P</span> <span class=\"token operator\">+=</span> <span class=\"token constant\">E</span><span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nx<span class=\"token operator\">--</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>b <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>y<span class=\"token punctuation\">,</span> <span class=\"token constant\">P</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>k<span class=\"token punctuation\">.</span>index <span class=\"token operator\">-=</span> y<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token punctuation\">(</span>k <span class=\"token operator\">=</span> <span class=\"token function\">z</span><span class=\"token punctuation\">(</span>v<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> w <span class=\"token operator\">=</span> k<span class=\"token punctuation\">.</span>index<span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">S</span> <span class=\"token operator\">=</span> k<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">O</span> <span class=\"token operator\">=</span> b<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> w<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">L</span> <span class=\"token operator\">=</span> b<span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>w <span class=\"token operator\">+</span> <span class=\"token constant\">S</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">N</span> <span class=\"token operator\">=</span> y <span class=\"token operator\">+</span> b<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\nl <span class=\"token operator\">&amp;&amp;</span> <span class=\"token constant\">N</span> <span class=\"token operator\">></span> l<span class=\"token punctuation\">.</span>reach <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>reach <span class=\"token operator\">=</span> <span class=\"token constant\">N</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> j <span class=\"token operator\">=</span> m<span class=\"token punctuation\">.</span>prev<span class=\"token punctuation\">;</span>\n\n<span class=\"token constant\">O</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>j <span class=\"token operator\">=</span> <span class=\"token constant\">I</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">,</span> <span class=\"token constant\">O</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>y <span class=\"token operator\">+=</span> <span class=\"token constant\">O</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token function\">q</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">,</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> <span class=\"token constant\">C</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">W</span><span class=\"token punctuation\">(</span>o<span class=\"token punctuation\">,</span> g <span class=\"token operator\">?</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">tokenize</span><span class=\"token punctuation\">(</span><span class=\"token constant\">S</span><span class=\"token punctuation\">,</span> g<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token constant\">S</span><span class=\"token punctuation\">,</span> d<span class=\"token punctuation\">,</span> <span class=\"token constant\">S</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>m <span class=\"token operator\">=</span> <span class=\"token constant\">I</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> j<span class=\"token punctuation\">,</span> <span class=\"token constant\">C</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">L</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token constant\">I</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">,</span> <span class=\"token constant\">L</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span> <span class=\"token operator\">&lt;</span> x<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> _ <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">cause</span><span class=\"token operator\">:</span> o <span class=\"token operator\">+</span> <span class=\"token string\">','</span> <span class=\"token operator\">+</span> u<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">reach</span><span class=\"token operator\">:</span> <span class=\"token constant\">N</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">e</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">,</span> m<span class=\"token punctuation\">.</span>prev<span class=\"token punctuation\">,</span> y<span class=\"token punctuation\">,</span> _<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> l <span class=\"token operator\">&amp;&amp;</span> _<span class=\"token punctuation\">.</span>reach <span class=\"token operator\">></span> l<span class=\"token punctuation\">.</span>reach <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>l<span class=\"token punctuation\">.</span>reach <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span>reach<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\nt <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>head<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">;</span> t <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> n<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>value<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> n<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">hooks</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">all</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">add</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span>all<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> t<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token function-variable function\">run</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span>all<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>t <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span> <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r<span class=\"token punctuation\">,</span> a <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">=</span> t<span class=\"token punctuation\">[</span>a<span class=\"token operator\">++</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token punctuation\">)</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">Token</span><span class=\"token operator\">:</span> <span class=\"token constant\">W</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token constant\">W</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>type <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>content <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>alias <span class=\"token operator\">=</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span> <span class=\"token operator\">|</span> <span class=\"token punctuation\">(</span>r <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">z</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">,</span> r</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\ne<span class=\"token punctuation\">.</span>lastIndex <span class=\"token operator\">=</span> n<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span><span class=\"token function\">exec</span><span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>a <span class=\"token operator\">&amp;&amp;</span> r <span class=\"token operator\">&amp;&amp;</span> a<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> i <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span><span class=\"token number\">1</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>index <span class=\"token operator\">+=</span> i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> a<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">slice</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">return</span> a<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">i</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">prev</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\nn <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">prev</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>head <span class=\"token operator\">=</span> e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>tail <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>length <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token constant\">I</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">,</span>\n\na <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> t<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">prev</span><span class=\"token operator\">:</span> n<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">next</span><span class=\"token operator\">:</span> r <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>length<span class=\"token operator\">++</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">q</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">,</span> a <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> a <span class=\"token operator\">&lt;</span> t <span class=\"token operator\">&amp;&amp;</span> r <span class=\"token operator\">!==</span> e<span class=\"token punctuation\">.</span>tail<span class=\"token punctuation\">;</span> a<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> r <span class=\"token operator\">=</span> r<span class=\"token punctuation\">.</span>next<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">.</span>next <span class=\"token operator\">=</span> r<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>prev <span class=\"token operator\">=</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>length <span class=\"token operator\">-=</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>u<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token constant\">W</span><span class=\"token punctuation\">.</span><span class=\"token function-variable function\">stringify</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">e<span class=\"token punctuation\">,</span> t</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'string'</span> <span class=\"token operator\">==</span> <span class=\"token keyword\">typeof</span> e<span class=\"token punctuation\">)</span> <span class=\"token keyword\">return</span> e<span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> r <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\ne<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\nr <span class=\"token operator\">+=</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nr\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> <span class=\"token function\">n</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">tag</span><span class=\"token operator\">:</span> <span class=\"token string\">'span'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">classes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'token'</span><span class=\"token punctuation\">,</span> e<span class=\"token punctuation\">.</span>type<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">attributes</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">language</span><span class=\"token operator\">:</span> t <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\ni <span class=\"token operator\">=</span> e<span class=\"token punctuation\">.</span>alias<span class=\"token punctuation\">;</span>\n\ni <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>Array<span class=\"token punctuation\">.</span><span class=\"token function\">isArray</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token class-name\">Array</span><span class=\"token punctuation\">.</span>prototype<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">.</span><span class=\"token function\">apply</span><span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>classes<span class=\"token punctuation\">,</span> i<span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> a<span class=\"token punctuation\">.</span>classes<span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span>i<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">run</span><span class=\"token punctuation\">(</span><span class=\"token string\">'wrap'</span><span class=\"token punctuation\">,</span> a<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> l <span class=\"token operator\">=</span> <span class=\"token string\">''</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">var</span> o <span class=\"token keyword\">in</span> a<span class=\"token punctuation\">.</span>attributes<span class=\"token punctuation\">)</span> l <span class=\"token operator\">+=</span> <span class=\"token string\">' '</span> <span class=\"token operator\">+</span> o <span class=\"token operator\">+</span> <span class=\"token string\">'=\"'</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>attributes<span class=\"token punctuation\">[</span>o<span class=\"token punctuation\">]</span> <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\"</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'&amp;quot;'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">'\"'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token string\">'&lt;'</span> <span class=\"token operator\">+</span> a<span class=\"token punctuation\">.</span>tag <span class=\"token operator\">+</span> <span class=\"token string\">' class=\"'</span> <span class=\"token operator\">+</span> a<span class=\"token punctuation\">.</span>classes<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">' '</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">'\"'</span> <span class=\"token operator\">+</span> l <span class=\"token operator\">+</span> <span class=\"token string\">'>'</span> <span class=\"token operator\">+</span> a<span class=\"token punctuation\">.</span>content <span class=\"token operator\">+</span> <span class=\"token string\">'&lt;/'</span> <span class=\"token operator\">+</span> a<span class=\"token punctuation\">.</span>tag <span class=\"token operator\">+</span> <span class=\"token string\">'>'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token operator\">!</span>u<span class=\"token punctuation\">.</span>document<span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">)</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n\nu<span class=\"token punctuation\">.</span>addEventListener <span class=\"token operator\">&amp;&amp;</span>\n\n<span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>disableWorkerMessageHandler <span class=\"token operator\">||</span>\n\nu<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span>\n\n<span class=\"token string\">'message'</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">parse</span><span class=\"token punctuation\">(</span>e<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nt <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>language<span class=\"token punctuation\">,</span>\n\nr <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>code<span class=\"token punctuation\">,</span>\n\na <span class=\"token operator\">=</span> n<span class=\"token punctuation\">.</span>immediateClose<span class=\"token punctuation\">;</span>\n\nu<span class=\"token punctuation\">.</span><span class=\"token function\">postMessage</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlight</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">,</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>t<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> a <span class=\"token operator\">&amp;&amp;</span> u<span class=\"token punctuation\">.</span><span class=\"token function\">close</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token operator\">!</span><span class=\"token number\">1</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token constant\">M</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>util<span class=\"token punctuation\">.</span><span class=\"token function\">currentScript</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">r</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>manual <span class=\"token operator\">||</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">.</span><span class=\"token function\">highlightAll</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>filename <span class=\"token operator\">=</span> t<span class=\"token punctuation\">.</span>src<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span><span class=\"token function\">hasAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'data-manual'</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>manual <span class=\"token operator\">=</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token operator\">!</span><span class=\"token constant\">M</span><span class=\"token punctuation\">.</span>manual<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> a <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span>readyState<span class=\"token punctuation\">;</span>\n\n<span class=\"token string\">'loading'</span> <span class=\"token operator\">===</span> a <span class=\"token operator\">||</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'interactive'</span> <span class=\"token operator\">===</span> a <span class=\"token operator\">&amp;&amp;</span> t <span class=\"token operator\">&amp;&amp;</span> t<span class=\"token punctuation\">.</span>defer<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">?</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">addEventListener</span><span class=\"token punctuation\">(</span><span class=\"token string\">'DOMContentLoaded'</span><span class=\"token punctuation\">,</span> r<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> window<span class=\"token punctuation\">.</span>requestAnimationFrame\n\n<span class=\"token operator\">?</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">requestAnimationFrame</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">)</span>\n\n<span class=\"token operator\">:</span> window<span class=\"token punctuation\">.</span><span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span>r<span class=\"token punctuation\">,</span> <span class=\"token number\">16</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">return</span> <span class=\"token constant\">M</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>_self<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> module <span class=\"token operator\">&amp;&amp;</span> module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>module<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'undefined'</span> <span class=\"token operator\">!=</span> <span class=\"token keyword\">typeof</span> global <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>global<span class=\"token punctuation\">.</span>Prism <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">comment</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;!--[\\s\\S]*?--></span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">prolog</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;\\?[\\s\\S]+?\\?></span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">doctype</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;!DOCTYPE(?:[^>\"'[\\]]|\"[^\"]*\"|'[^']*')+(?:\\[(?:[^&lt;\"'\\]]|\"[^\"]*\"|'[^']*'|&lt;(?!!--)|&lt;!--(?:[^-]|-(?!->))*-->)*\\]\\s*)?></span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token string-property property\">'internal-subset'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^[^\\[]*\\[)[\\s\\S]+(?=\\]>$)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">string</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\"[^\"]*\"|'[^']*'</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^&lt;!|>$|[[\\]]</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'doctype-tag'</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^DOCTYPE</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^\\s&lt;>'\"]+</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">cdata</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;!\\[CDATA\\[[\\s\\S]*?\\]\\]></span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">tag</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;\\/?(?!\\d)[^\\s>\\/=$&lt;%]+(?:\\s(?:\\s*[^\\s>\\/=]+(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s'\">=]+(?=[\\s>]))|(?=[\\s/>])))+)?\\s*\\/?></span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">tag</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^&lt;\\/?[^\\s>\\/]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^&lt;\\/?</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">namespace</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[^\\s>\\/:]+:</span><span class=\"token regex-delimiter\">/</span></span> <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'special-attr'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'attr-value'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s'\">=]+)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^=</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'attr-equals'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\"|'</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\/?></span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'attr-name'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[^\\s>\\/]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">namespace</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[^\\s>\\/:]+:</span><span class=\"token regex-delimiter\">/</span></span> <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">entity</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&amp;[\\da-z]{1,8};</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'named-entity'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&amp;#x?[\\da-f]{1,8};</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">]</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">[</span><span class=\"token string\">'attr-value'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">.</span>entity <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>entity<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>doctype<span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">[</span><span class=\"token string\">'internal-subset'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>inside <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>hooks<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'wrap'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token string\">'entity'</span> <span class=\"token operator\">===</span> a<span class=\"token punctuation\">.</span>type <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">.</span>attributes<span class=\"token punctuation\">.</span>title <span class=\"token operator\">=</span> a<span class=\"token punctuation\">.</span>content<span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&amp;amp;</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token string\">'&amp;'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">,</span> <span class=\"token string\">'addInlined'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">var</span> s <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">[</span><span class=\"token string\">'language-'</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^&lt;!\\[CDATA\\[)[\\s\\S]+?(?=\\]\\]>$)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>cdata <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^&lt;!\\[CDATA\\[|\\]\\]>$</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token string-property property\">'included-cdata'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">&lt;!\\[CDATA\\[[\\s\\S]*?\\]\\]></span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> s <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nt<span class=\"token punctuation\">[</span><span class=\"token string\">'language-'</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[\\s\\S]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">var</span> n <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>n<span class=\"token punctuation\">[</span>a<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span>\n\n<span class=\"token string\">'(&lt;**[^>]*>)(?:&lt;!\\\\[CDATA\\\\[(?:[^\\\\]]|\\\\](?!\\]>))*\\\\]\\\\]>|(?!&lt;!\\\\[CDATA\\\\[)[^])\\*?(?=&lt;/**>)'</span><span class=\"token punctuation\">.</span><span class=\"token function\">replace</span><span class=\"token punctuation\">(</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\_\\_</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">g</span></span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token keyword\">return</span> a<span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string\">'i'</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> t\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span><span class=\"token string\">'markup'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'cdata'</span><span class=\"token punctuation\">,</span> n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nObject<span class=\"token punctuation\">.</span><span class=\"token function\">defineProperty</span><span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">,</span> <span class=\"token string\">'addAttribute'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token function-variable function\">value</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">a<span class=\"token punctuation\">,</span> e</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">[</span><span class=\"token string\">'special-attr'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">push</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span><span class=\"token string\">'(^|[\"\\'\\\\s])(?:'</span> <span class=\"token operator\">+</span> a <span class=\"token operator\">+</span> <span class=\"token string\">')\\\\s*=\\\\s*(?:\"[^\"]*\"|\\'[^\\']*\\'|[^\\\\s\\'\">=]+(?=[\\\\s>]))'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'i'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token string-property property\">'attr-name'</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[^\\s=]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'attr-value'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">=[\\s\\S]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">value</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^=\\s*([\"']|(?![\"'])))\\S[\\s\\S]*(?=\\2$)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">,</span> <span class=\"token string\">'language-'</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n                                <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">[</span>e<span class=\"token punctuation\">]</span>\n\n                            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                            <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^=</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'attr-equals'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\"|'</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">]</span>\n\n                        <span class=\"token punctuation\">}</span>\n\n                    <span class=\"token punctuation\">}</span>\n\n                <span class=\"token punctuation\">}</span>\n\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        <span class=\"token punctuation\">}</span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>html <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>mathml <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>svg <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>xml <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">extend</span><span class=\"token punctuation\">(</span><span class=\"token string\">'markup'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>ssml <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>xml<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>atom <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>xml<span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>rss <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>xml<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token operator\">!</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">s</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n    <span class=\"token keyword\">var</span> e <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(?:\"(?:\\\\(?:\\r\\n|[\\s\\S])|[^\"\\\\\\r\\n])*\"|'(?:\\\\(?:\\r\\n|[\\s\\S])|[^'\\\\\\r\\n])*')</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>css <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n        <span class=\"token literal-property property\">comment</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\/\\*[\\s\\S]*?\\*\\/</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">atrule</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n            <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">@[\\w-](?:[^;{\\s]|\\s+(?![\\s{]))*(?:;|(?=\\s*\\{))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n                <span class=\"token literal-property property\">rule</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^@[\\w-]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token string-property property\">'selector-function-argument'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n                    <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(\\bselector\\s*\\(\\s*(?![\\s)]))(?:[^()\\s]|\\s+(?![\\s)])|\\((?:[^()]|\\([^()]*\\))*\\))+(?=\\s*\\))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'selector'</span>\n\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">keyword</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^\\w-])(?:and|not|only|or)(?![\\w-])</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span>\n\n            <span class=\"token punctuation\">}</span>\n\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">url</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n            <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span><span class=\"token string\">'\\\\burl\\\\((?:'</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>source <span class=\"token operator\">+</span> <span class=\"token string\">'|(?:[^\\\\\\\\\\r\\n()\"\\']|\\\\\\\\[^])*)\\\\)'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'i'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token keyword\">function</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^url</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^\\(|\\)$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">string</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span><span class=\"token string\">'^'</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>source <span class=\"token operator\">+</span> <span class=\"token string\">'$'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'url'</span> <span class=\"token punctuation\">}</span> <span class=\"token punctuation\">}</span>\n\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">selector</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token function\">RegExp</span><span class=\"token punctuation\">(</span><span class=\"token string\">'(^|[{}\\\\s])[^{}\\\\s](?:[^{};\"\\'\\\\s]|\\\\s+(?![\\\\s{])|'</span> <span class=\"token operator\">+</span> e<span class=\"token punctuation\">.</span>source <span class=\"token operator\">+</span> <span class=\"token string\">')*(?=\\\\s*\\\\{)'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">string</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> e<span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">property</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^-\\w\\xA0-\\uFFFF])(?!\\s)[-_a-z\\xA0-\\uFFFF](?:(?!\\s)[-\\w\\xA0-\\uFFFF])*(?=\\s*:)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">important</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">!important\\b</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token keyword\">function</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^-a-z0-9])[-a-z0-9]+(?=\\()</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[(){};:,]</span><span class=\"token regex-delimiter\">/</span></span>\n\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token punctuation\">(</span>s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>css<span class=\"token punctuation\">.</span>atrule<span class=\"token punctuation\">.</span>inside<span class=\"token punctuation\">.</span>rest <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>css<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">var</span> t <span class=\"token operator\">=</span> s<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">;</span>\n\n    t <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>t<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span><span class=\"token function\">addInlined</span><span class=\"token punctuation\">(</span><span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'css'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> t<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span><span class=\"token function\">addAttribute</span><span class=\"token punctuation\">(</span><span class=\"token string\">'style'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'css'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>clike <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n\n    <span class=\"token literal-property property\">comment</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^\\\\])\\/\\*[\\s\\S]*?(?:\\*\\/|$)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^\\\\:])\\/\\/.*</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">string</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">([\"'])(?:\\\\(?:\\r\\n|[\\s\\S])|(?!\\1)[^\\\\\\r\\n])*\\1</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'class-name'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(\\b(?:class|interface|extends|implements|trait|instanceof|new)\\s+|\\bcatch\\s+\\()[\\w.\\\\]+</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[.\\\\]</span><span class=\"token regex-delimiter\">/</span></span> <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">keyword</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\\b</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">boolean</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b(?:true|false)\\b</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token keyword\">function</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b\\w+(?=\\()</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">number</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b0x[\\da-f]+\\b|(?:\\b\\d+(?:\\.\\d*)?|\\B\\.\\d+)(?:e[+-]?\\d+)?</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">operator</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[&lt;>]=?|[!=]=?=?|--?|\\+\\+?|&amp;&amp;?|\\|\\|?|[?*/~^%]</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">punctuation</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[{}[\\];(),.:]</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">extend</span><span class=\"token punctuation\">(</span><span class=\"token string\">'clike'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token string-property property\">'class-name'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>clike<span class=\"token punctuation\">[</span><span class=\"token string\">'class-name'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^$\\w\\xa0-\\uffff])(?!\\s)[_$A-Z\\xA0-\\uFFFF](?:(?!\\s)[$\\w\\xA0-\\uFFFF])_(?=\\.(?:prototype|constructor))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">keyword</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n\n<span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:^|\\})\\s_)catch\\b</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span>\n\n<span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^.]|\\.\\.\\.\\s*)\\b(?:as|assert(?=\\s*\\{)|async(?=\\s*(?:function\\b|\\(|[$\\w\\xA0-\\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\\s*(?:\\{|$))|for|from(?=\\s*(?:['\"]|$))|function|(?:get|set)(?=\\s*(?:[#\\[$\\w\\xA0-\\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\\b</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span>\n\n        <span class=\"token punctuation\">}</span>\n\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token keyword\">function</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">#?(?!\\s)[_$a-zA-Z\\xA0-\\uFFFF](?:(?!\\s)[$\\w\\xA0-\\uFFFF])*(?=\\s*(?:\\.\\s*(?:apply|bind|call)\\s*)?\\()</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">number</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b(?:(?:0[xX](&lt;?:[\\dA-Fa-f](?:_[\\dA-Fa-f])?>)+|0[bB](&lt;?:[01](?:_[01])?>)+|0[oO](&lt;?:[0-7](?:_[0-7])?>)+)n?|(?:\\d(?:*\\d)?)+n|NaN|Infinity)\\b|(?:\\b(?:\\d(?:*\\d)?)+\\.?(?:\\d(?:\\_\\d)?)*|\\B\\.(?:\\d(?:_\\d)?)+)(?:[Ee][+-]?(?:\\d(?:_\\d)?)+)?</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">operator</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">--|\\+\\+|\\*\\*=?|=>|&amp;&amp;=?|\\|\\|=?|[!=]==|&lt;&lt;=?|>>>?=?|[-+*/%&amp;|^!=&lt;>]=?|\\.{3}|\\?\\?=?|\\?\\.?|[~:]</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript<span class=\"token punctuation\">[</span><span class=\"token string\">'class-name'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span>pattern <span class=\"token operator\">=</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(\\b(?:class|interface|extends|implements|instanceof|new)\\s+)[\\w.\\\\]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span><span class=\"token string\">'javascript'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'keyword'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">regex</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span>\n\n<span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:^|[^$\\w\\xa0-\\uffff.\"'\\])\\s]|\\b(?:return|yield))\\s*)\\/(?:\\[(?:[^\\]\\\\\\r\\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}(?=(?:\\s|\\/\\*(?:[^*]|\\*(?!\\/))_\\*\\/)_(?:$|[\\r\\n,.;:})\\]]|\\/\\/))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n                <span class=\"token string-property property\">'regex-source'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^(\\/)[\\s\\S]+(?=\\/[a-z]*$)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'language-regex'</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>regex <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'regex-delimiter'</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^\\/|\\/$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token string-property property\">'regex-flags'</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^[a-z]+$</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'function-variable'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span>\n\n<span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">#?(?!\\s)[\\_$a-zA-Z\\xA0-\\uFFFF](&lt;?:(?!\\s)[$\\w\\xA0-\\uFFFF]>)_(?=\\s_[=:]\\s*(?:async\\s*)?(?:\\bfunction\\b|(?:\\((?:[^()]|\\([^()]_\\))_\\)|(?!\\s)[\\_$a-zA-Z\\xA0-\\uFFFF](&lt;?:(?!\\s)[$\\w\\xA0-\\uFFFF]>)_)\\s_=>))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'function'</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">parameter</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(function(?:\\s+(?!\\s)[\\_$a-zA-Z\\xA0-\\uFFFF](&lt;?:(?!\\s)[$\\w\\xA0-\\uFFFF]>)_)?\\s_\\(\\s*)(?!\\s)(?:[^()\\s]|\\s+(?![\\s)])|\\([^()]*\\))+(?=\\s*\\))</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(^|[^$\\w\\xa0-\\uffff])(?!\\s)[\\_$a-z\\xA0-\\uFFFF](&lt;?:(?!\\s)[$\\w\\xA0-\\uFFFF]>)*(?=\\s*=>)</span><span class=\"token regex-delimiter\">/</span><span class=\"token regex-flags\">i</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">(\\(\\s*)(?!\\s)(?:[^()\\s]|\\s+(?![\\s)])|\\([^()]_\\))+(?=\\s_\\)\\s*=>)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span>\n\n<span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:\\b|\\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\\w\\xA0-\\uFFFF]))(?:(?!\\s)[\\_$a-zA-Z\\xA0-\\uFFFF](&lt;?:(?!\\s)[$\\w\\xA0-\\uFFFF]>)*\\s*)\\(\\s*|\\]\\s*\\(\\s*)(?!\\s)(?:[^()\\s]|\\s+(?![\\s)])|\\([^()]_\\))+(?=\\s_\\)\\s*\\{)</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">constant</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\b[A-Z](?:[A-Z_]|\\dx?)*\\b</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span><span class=\"token function\">insertBefore</span><span class=\"token punctuation\">(</span><span class=\"token string\">'javascript'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'string'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">hashbang</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^#!._</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'comment'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string-property property\">'template-string'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n<span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">`(?:\\\\[\\s\\S]|\\$\\{(?:[^{}]|\\{(?:[^{}]|\\{[^}]_\\})_\\})+\\}|(?!\\$\\{)[^\\\\`])_`</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">greedy</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token string-property property\">'template-punctuation'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^`|`$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'string'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">interpolation</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n\n                    <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">((?:^|[^\\\\])(?:\\\\{2})*)\\$\\{(?:[^{}]|\\{(?:[^{}]|\\{[^}]*\\})*\\})+\\}</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">lookbehind</span><span class=\"token operator\">:</span> <span class=\"token operator\">!</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">inside</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token string-property property\">'interpolation-punctuation'</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">pattern</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">^\\$\\{|\\}$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">alias</span><span class=\"token operator\">:</span> <span class=\"token string\">'punctuation'</span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token literal-property property\">rest</span><span class=\"token operator\">:</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript <span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token literal-property property\">string</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">[\\s\\S]+</span><span class=\"token regex-delimiter\">/</span></span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup <span class=\"token operator\">&amp;&amp;</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span><span class=\"token function\">addInlined</span><span class=\"token punctuation\">(</span><span class=\"token string\">'script'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'javascript'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\nPrism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>markup<span class=\"token punctuation\">.</span>tag<span class=\"token punctuation\">.</span><span class=\"token function\">addAttribute</span><span class=\"token punctuation\">(</span>\n\n<span class=\"token string\">'on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)'</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token string\">'javascript'</span>\n\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n<span class=\"token punctuation\">(</span>Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>js <span class=\"token operator\">=</span> Prism<span class=\"token punctuation\">.</span>languages<span class=\"token punctuation\">.</span>javascript<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">&lt;details></code></pre></div>\n<br>\n<br>\n<hr>\n<hr>\n<hr>\n<hr>\n<br>\n<br>\n<h1>Plugins</h1>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">├── ./plugins\n\n        ├── ./plugins/gatsby-remark-page-creator\n\n        │   └──  ./plugins/gatsby-remark-page-creator/gatsby-node.js\n\n        │\n\n        └── ./plugins/gatsby-source-data\n\n            └──  ./plugins/gatsby-source-data/gatsby-node.js</code></pre></div>\n<br>\n<br>\n<hr>\n<hr>\n<hr>\n<hr>\n<br>\n<br>\n<h1>Components</h1>\n<h3>Index.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> ActionLink <span class=\"token keyword\">from</span> <span class=\"token string\">'./ActionLink'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> CtaButtons <span class=\"token keyword\">from</span> <span class=\"token string\">'./CtaButtons'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> DocsMenu <span class=\"token keyword\">from</span> <span class=\"token string\">'./DocsMenu'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> DocsSubmenu <span class=\"token keyword\">from</span> <span class=\"token string\">'./DocsSubmenu'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Footer <span class=\"token keyword\">from</span> <span class=\"token string\">'./Footer'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Header <span class=\"token keyword\">from</span> <span class=\"token string\">'./Header'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Icon <span class=\"token keyword\">from</span> <span class=\"token string\">'./Icon'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionContent <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionContent'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionCta <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionCta'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionDocs <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionDocs'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionGrid <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionGrid'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> SectionHero <span class=\"token keyword\">from</span> <span class=\"token string\">'./SectionHero'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Submenu <span class=\"token keyword\">from</span> <span class=\"token string\">'./Submenu'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Layout <span class=\"token keyword\">from</span> <span class=\"token string\">'./Layout'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> addScript <span class=\"token keyword\">from</span> <span class=\"token string\">'./../hooks/addScript'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token punctuation\">{</span>\n    ActionLink<span class=\"token punctuation\">,</span>\n    CtaButtons<span class=\"token punctuation\">,</span>\n    DocsMenu<span class=\"token punctuation\">,</span>\n    DocsSubmenu<span class=\"token punctuation\">,</span>\n    Footer<span class=\"token punctuation\">,</span>\n    Header<span class=\"token punctuation\">,</span>\n    Icon<span class=\"token punctuation\">,</span>\n    SectionContent<span class=\"token punctuation\">,</span>\n    SectionCta<span class=\"token punctuation\">,</span>\n    SectionDocs<span class=\"token punctuation\">,</span>\n    SectionGrid<span class=\"token punctuation\">,</span>\n    SectionHero<span class=\"token punctuation\">,</span>\n    Submenu<span class=\"token punctuation\">,</span>\n    Layout\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token punctuation\">{</span>\n    ActionLink<span class=\"token punctuation\">,</span>\n\n    CtaButtons<span class=\"token punctuation\">,</span>\n\n    DocsMenu<span class=\"token punctuation\">,</span>\n\n    DocsSubmenu<span class=\"token punctuation\">,</span>\n\n    Footer<span class=\"token punctuation\">,</span>\n\n    Header<span class=\"token punctuation\">,</span>\n\n    Icon<span class=\"token punctuation\">,</span>\n\n    SectionContent<span class=\"token punctuation\">,</span>\n\n    SectionCta<span class=\"token punctuation\">,</span>\n\n    SectionDocs<span class=\"token punctuation\">,</span>\n\n    SectionGrid<span class=\"token punctuation\">,</span>\n\n    SectionHero<span class=\"token punctuation\">,</span>\n\n    Submenu<span class=\"token punctuation\">,</span>\n\n    Layout\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h3>Layout.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> React <span class=\"token keyword\">from</span> <span class=\"token string\">'react'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> Helmet <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-helmet'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> _ <span class=\"token keyword\">from</span> <span class=\"token string\">'lodash'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> withPrefix<span class=\"token punctuation\">,</span> attribute <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'../utils'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> <span class=\"token string\">'../sass/main.scss'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Header <span class=\"token keyword\">from</span> <span class=\"token string\">'./Header'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> Footer <span class=\"token keyword\">from</span> <span class=\"token string\">'./Footer'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">import</span> addScript <span class=\"token keyword\">from</span> <span class=\"token string\">'./../hooks/addScript'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> <span class=\"token function-variable function\">Script</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">_props</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">importScript</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./../hooks/addScript.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">export</span> <span class=\"token keyword\">default</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Body</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">React<span class=\"token punctuation\">.</span>Component</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">render</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\n            <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span>link rel<span class=\"token operator\">=</span><span class=\"token string\">\"stylesheet\"</span> href<span class=\"token operator\">=</span><span class=\"token string\">\"https://cdn.jsdelivr.net/npm/@algolia/algoliasearch-netlify-frontend@1/dist/algoliasearchNetlify.css\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                <span class=\"token operator\">&lt;</span>Helmet<span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>title<span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                            <span class=\"token operator\">?</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span>\n                            <span class=\"token operator\">:</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token string\">' | '</span> <span class=\"token operator\">+</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.title'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>title<span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>meta charSet<span class=\"token operator\">=</span><span class=\"token string\">\"utf-8\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>meta name<span class=\"token operator\">=</span><span class=\"token string\">\"viewport\"</span> content<span class=\"token operator\">=</span><span class=\"token string\">\"width=device-width, initialScale=1.0\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>meta name<span class=\"token operator\">=</span><span class=\"token string\">\"description\"</span> content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.description'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token string\">''</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.robots'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>meta name<span class=\"token operator\">=</span><span class=\"token string\">\"robots\"</span> content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.robots'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">','</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">map</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.frontmatter.seo.extra'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">meta<span class=\"token punctuation\">,</span> meta_idx</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token keyword\">let</span> key_name <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'keyName'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">||</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">;</span>\n\n                        <span class=\"token keyword\">return</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'relativeUrl'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">?</span> <span class=\"token punctuation\">(</span>\n                            _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.domain'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span>\n                                <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                                    <span class=\"token keyword\">let</span> domain <span class=\"token operator\">=</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">trim</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.domain'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">let</span> rel_url <span class=\"token operator\">=</span> <span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">let</span> full_url <span class=\"token operator\">=</span> domain <span class=\"token operator\">+</span> rel_url<span class=\"token punctuation\">;</span>\n\n                                    <span class=\"token keyword\">return</span> <span class=\"token operator\">&lt;</span>meta key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>meta_idx<span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token function\">attribute</span><span class=\"token punctuation\">(</span>key_name<span class=\"token punctuation\">,</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>full_url<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\n                                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n                        <span class=\"token punctuation\">)</span> <span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span>\n                            <span class=\"token operator\">&lt;</span>meta key<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>meta_idx <span class=\"token operator\">+</span> <span class=\"token string\">'.1'</span><span class=\"token punctuation\">}</span> <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token function\">attribute</span><span class=\"token punctuation\">(</span>key_name<span class=\"token punctuation\">,</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> content<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span>meta<span class=\"token punctuation\">,</span> <span class=\"token string\">'value'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token operator\">&lt;</span>link rel<span class=\"token operator\">=</span><span class=\"token string\">\"preconnect\"</span> href<span class=\"token operator\">=</span><span class=\"token string\">\"https://fonts.gstatic.com\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>link href<span class=\"token operator\">=</span><span class=\"token string\">\"https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&amp;display=swap\"</span> rel<span class=\"token operator\">=</span><span class=\"token string\">\"stylesheet\"</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token punctuation\">{</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.favicon'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&amp;&amp;</span> <span class=\"token punctuation\">(</span>\n                        <span class=\"token operator\">&lt;</span>link rel<span class=\"token operator\">=</span><span class=\"token string\">\"icon\"</span> href<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span>_<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.favicon'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span>\n\n                    <span class=\"token operator\">&lt;</span>body className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token string\">'palette-'</span> <span class=\"token operator\">+</span> _<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">,</span> <span class=\"token string\">'pageContext.site.siteMetadata.palette'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>Helmet<span class=\"token operator\">></span>\n\n                <span class=\"token operator\">&lt;</span>div id<span class=\"token operator\">=</span><span class=\"token string\">\"page\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"site\"</span><span class=\"token operator\">></span>\n                    <span class=\"token operator\">&lt;</span>Header <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>main id<span class=\"token operator\">=</span><span class=\"token string\">\"content\"</span> className<span class=\"token operator\">=</span><span class=\"token string\">\"site-content\"</span><span class=\"token operator\">></span>\n                        <span class=\"token punctuation\">{</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">}</span>\n                    <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>main<span class=\"token operator\">></span>\n\n                    <span class=\"token operator\">&lt;</span>Footer <span class=\"token punctuation\">{</span><span class=\"token operator\">...</span><span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>props<span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n                <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>div<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n        <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h3>ActionLink.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>CtaButtons.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>DocsMenu.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>DocsSubmenu.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>Footer.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>Header.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>Icon.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>SectionContent.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>SectionCta.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>SectionDocs.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>SectionGrid.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>SectionHero.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3>Submenu.js</h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<br>\n<br>\n<hr>\n<hr>\n<hr>\n<hr>\n<br>\n<br>\n<br>\n<br>\n<hr>\n<hr>\n<hr>\n<hr>\n<br>\n<br>\n<br>\n<br>\n<hr>\n<hr>\n<hr>\n<hr>\n<br>\n<br>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">├── ./functions\n\n│   └── ./functions/deploy-succeeded.js\n\n├── ./gatsby-browser.js\n\n├── ./gatsby-config.js\n\n├── ./gatsby-node.js\n\n├── ./gatsby-ssr.js\n\n├── ./googled2b1865dedd985a4.html\n\n├── ./lambda\n\n    └── ./lambda/deploy-succeeded.js</code></pre></div>\n<h2>Gatsby Browser</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n\n * Implement Gatsby's Browser APIs in this file.\n\n *\n\n * See: https://www.gatsbyjs.org/docs/browser-apis/\n\n */</span>\n\n<span class=\"token comment\">// onPreRouteUpdate() and onRouteUpdate() are called before onInitialClientRender,</span>\n\n<span class=\"token comment\">// use initialized flag to ensure that window.onGatsbyPreRouteUpdate() and</span>\n\n<span class=\"token comment\">// window.onGatsbyRouteUpdate() will not be called before</span>\n\n<span class=\"token comment\">// window.onGatsbyInitialClientRender() has run</span>\n\n<span class=\"token keyword\">let</span> initialized <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onInitialClientRender</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    initialized <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'onGatsbyInitialClientRender'</span> <span class=\"token keyword\">in</span> window <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>onGatsbyInitialClientRender <span class=\"token operator\">===</span> <span class=\"token string\">'function'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        window<span class=\"token punctuation\">.</span><span class=\"token function\">onGatsbyInitialClientRender</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token string\">'onGatsbyRouteUpdate'</span> <span class=\"token keyword\">in</span> window <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>onGatsbyRouteUpdate <span class=\"token operator\">===</span> <span class=\"token string\">'function'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        window<span class=\"token punctuation\">.</span><span class=\"token function\">onGatsbyRouteUpdate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onRouteUpdate</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>initialized <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'onGatsbyRouteUpdate'</span> <span class=\"token keyword\">in</span> window <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>onGatsbyRouteUpdate <span class=\"token operator\">===</span> <span class=\"token string\">'function'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        window<span class=\"token punctuation\">.</span><span class=\"token function\">onGatsbyRouteUpdate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onPreRouteUpdate</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>initialized <span class=\"token operator\">&amp;&amp;</span> <span class=\"token string\">'onGatsbyPreRouteUpdate'</span> <span class=\"token keyword\">in</span> window <span class=\"token operator\">&amp;&amp;</span> <span class=\"token keyword\">typeof</span> window<span class=\"token punctuation\">.</span>onGatsbyPreRouteUpdate <span class=\"token operator\">===</span> <span class=\"token string\">'function'</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        window<span class=\"token punctuation\">.</span><span class=\"token function\">onGatsbyPreRouteUpdate</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h2>Gatsby-config</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> siteMetadata <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./site-metadata.json'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">pathPrefix</span><span class=\"token operator\">:</span> <span class=\"token string\">'/'</span><span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">siteMetadata</span><span class=\"token operator\">:</span> siteMetadata<span class=\"token punctuation\">,</span>\n\n    <span class=\"token literal-property property\">plugins</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n        <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">gatsby-plugin-react-helmet</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">gatsby-source-data</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">gatsby-transformer-remark</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">resolve</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">gatsby-source-filesystem</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">options</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">pages</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>__dirname<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">/src/pages</span><span class=\"token template-punctuation string\">`</span></span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">resolve</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">gatsby-plugin-sass</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">options</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">resolve</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">gatsby-remark-page-creator</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">options</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">resolve</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">@stackbit/gatsby-plugin-menus</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">options</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">sourceUrlPath</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">fields.url</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">pageContextProperty</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">menus</span><span class=\"token template-punctuation string\">`</span></span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h2>Gatsby-node</h2>\n<h2><a href=\"https://www.gatsbyjs.org/docs/node-apis/\">Gatsby Node</a></h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n\n * Implement Gatsby's Node APIs in this file.\n\n *\n\n * See: https://www.gatsbyjs.org/docs/node-apis/\n\n */</span></code></pre></div>\n<h1>Gatsby Node APIs</h1>\n<p>Gatsby gives plugins and site builders many APIs for building your site. Code in the file <code class=\"language-text\">gatsby-node.js</code> is run once in the process of building your site. You can use its APIs to create pages dynamically, add data into GraphQL, or respond to events during the build lifecycle. To use the <a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/\">Gatsby Node APIs</a>, create a file named <code class=\"language-text\">gatsby-node.js</code> in the root of your site. Export any of the APIs you wish to use in this file.</p>\n<p>Every Gatsby Node API gets passed a <a href=\"https://www.gatsbyjs.com/docs/reference/config-files/node-api-helpers/\">set of helper functions</a>. These let you access several methods like reporting, or perform actions like creating new pages.</p>\n<p>An example gatsby-node.js file that implements two APIs, <code class=\"language-text\">onPostBuild</code>, and <code class=\"language-text\">createPages</code>.</p>\n<blockquote>\n<p>gatsby-node.js</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n\nCopygatsby<span class=\"token operator\">-</span>node<span class=\"token punctuation\">.</span>js<span class=\"token operator\">:</span> copy code to clipboard<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\nconst path =  require(</span><span class=\"token template-punctuation string\">`</span></span>path<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">)\n\n// Log out information after a build is done\n\nexports.onPostBuild  =  ({ reporter })  =>  {\n\n reporter.info(</span><span class=\"token template-punctuation string\">`</span></span>Your Gatsby site has been built<span class=\"token operator\">!</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">)\n\n}\n\n// Create blog pages dynamically\n\nexports.createPages  =  async  ({ graphql, actions })  =>  {\n\n  const  { createPage }  = actions\n\n  const blogPostTemplate = path.resolve(</span><span class=\"token template-punctuation string\">`</span></span>src<span class=\"token operator\">/</span>templates<span class=\"token operator\">/</span>blog<span class=\"token operator\">-</span>post<span class=\"token punctuation\">.</span>js<span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">)\n\n  const result =  await  graphql(</span><span class=\"token template-punctuation string\">`</span></span>\n\n query <span class=\"token punctuation\">{</span>\n\n allSamplePages <span class=\"token punctuation\">{</span>\n\n edges <span class=\"token punctuation\">{</span>\n\n node <span class=\"token punctuation\">{</span>\n\n slug\n\n title\n\n <span class=\"token punctuation\">}</span>\n\n <span class=\"token punctuation\">}</span>\n\n <span class=\"token punctuation\">}</span>\n\n <span class=\"token punctuation\">}</span>\n\n  <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">)\n\n result.data.allSamplePages.edges.forEach(edge  =>  {\n\n  createPage({\n\n path:  </span><span class=\"token template-punctuation string\">`</span></span>$<span class=\"token punctuation\">{</span>edge<span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span>slug<span class=\"token punctuation\">}</span>`<span class=\"token punctuation\">,</span>\n\n <span class=\"token literal-property property\">component</span><span class=\"token operator\">:</span> blogPostTemplate<span class=\"token punctuation\">,</span>\n\n <span class=\"token literal-property property\">context</span><span class=\"token operator\">:</span>  <span class=\"token punctuation\">{</span>\n\n <span class=\"token literal-property property\">title</span><span class=\"token operator\">:</span> edge<span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span>title<span class=\"token punctuation\">,</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n\n<span class=\"token punctuation\">}</span></code></pre></div>\n<h2><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#async-vs-sync-work\"></a>Async vs. sync work</h2>\n<p>If your plugin performs async operations (disk I/O, database access, calling remote APIs, etc.) you must either return a promise (explicitly using <code class=\"language-text\">Promise</code> API or implicitly using <code class=\"language-text\">async</code>/<code class=\"language-text\">await</code> syntax) or use the callback passed to the 3rd argument. Gatsby needs to know when plugins are finished as some APIs, to work correctly, require previous APIs to be complete first. See <a href=\"https://www.gatsbyjs.com/docs/debugging-async-lifecycles/\">Debugging Async Lifecycles</a> for more info.</p>\n<p>// Async/await</p>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">createPages</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">async</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// do async work</span>\n\n    <span class=\"token keyword\">const</span> result <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">fetchExternalData</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Promise API</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">createPages</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Promise</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">resolve<span class=\"token punctuation\">,</span> reject</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// do async work</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Callback API</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">createPages</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">_<span class=\"token punctuation\">,</span> pluginOptions<span class=\"token punctuation\">,</span> cb</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// do async work</span>\n\n    <span class=\"token function\">cb</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If your plugin does not do async work, you can return directly.</p>\n<h2>APIs</h2>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#createPages\"><code class=\"language-text\">createPages</code></a></p>\n<p>Create pages dynamically. This extension point is called only after the initial sourcing and transformation of nodes plus creation of the GraphQL schema are complete so you can query your data in order to create pages.</p>\n<p>You can also fetch data from remote or local sources to create pages.</p>\n<p>See also <a href=\"https://www.gatsbyjs.com/docs/actions/#createPage\">the documentation for the action <code class=\"language-text\">createPage</code></a>.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n<p>See the <a href=\"https://www.gatsbyjs.com/docs/node-api-helpers\">documentation for <code class=\"language-text\">Node API Helpers</code> for more details</a></p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `actions` Actions\n\n    See the [list of documented actions](https://www.gatsbyjs.com/docs/actions)</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        `createPage` function\n\n        [Documentation for this action](https://www.gatsbyjs.com/docs/actions/#createPage)</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `graphql` function\n\n    : Query GraphQL API. See [examples here](https://www.gatsbyjs.com/docs/creating-and-modifying-pages/#creating-pages-in-gatsby-nodejs)</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `reporter` GatsbyReporter\n\n    Log issues. See [GatsbyReporter documentation](https://www.gatsbyjs.com/docs/node-api-helpers/#GatsbyReporter) for more details</code></pre></div>\n</li>\n</ul>\n<h4>Return value</h4>\n<h5></h5>\n<p>Promise<void></p>\n<p>No return value required, but the caller will <code class=\"language-text\">await</code> any promise that's returned</p>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">const</span> path <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">path</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">createPages</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> graphql<span class=\"token punctuation\">,</span> actions <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> createPage <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> actions<span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> blogPostTemplate <span class=\"token operator\">=</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">src/templates/blog-post.js</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Query for markdown nodes to use in creating pages.</span>\n\n    <span class=\"token comment\">// You can query for whatever data you want to create pages for e.g.</span>\n\n    <span class=\"token comment\">// products, portfolio items, landing pages, etc.</span>\n\n    <span class=\"token comment\">// Variables can be added as the second function parameter</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token function\">graphql</span><span class=\"token punctuation\">(</span>\n        <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n            query loadPagesQuery($limit: Int!) {\n                allMarkdownRemark(limit: $limit) {\n                    edges {\n                        node {\n                            frontmatter {\n                                slug\n                            }\n                        }\n                    }\n                }\n            }\n        </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">limit</span><span class=\"token operator\">:</span> <span class=\"token number\">1000</span> <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">then</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">result</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>result<span class=\"token punctuation\">.</span>errors<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">throw</span> result<span class=\"token punctuation\">.</span>errors<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n        <span class=\"token comment\">// Create blog post pages.</span>\n\n        result<span class=\"token punctuation\">.</span>data<span class=\"token punctuation\">.</span>allMarkdownRemark<span class=\"token punctuation\">.</span>edges<span class=\"token punctuation\">.</span><span class=\"token function\">forEach</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">edge</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">createPage</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n                <span class=\"token comment\">// Path for this page --- required</span>\n\n                <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>edge<span class=\"token punctuation\">.</span>node<span class=\"token punctuation\">.</span>frontmatter<span class=\"token punctuation\">.</span>slug<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">component</span><span class=\"token operator\">:</span> blogPostTemplate<span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">context</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token comment\">// Add optional context data to be inserted</span>\n                    <span class=\"token comment\">// as props into the page component.</span>\n                    <span class=\"token comment\">//</span>\n                    <span class=\"token comment\">// The context data can also be used as</span>\n                    <span class=\"token comment\">// arguments to the page GraphQL query.</span>\n                    <span class=\"token comment\">//</span>\n                    <span class=\"token comment\">// The page \"path\" is always available as a GraphQL</span>\n                    <span class=\"token comment\">// argument.</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#createPagesStatefully\"><code class=\"language-text\">createPagesStatefully</code></a></p>\n<p>Like <code class=\"language-text\">createPages</code> but for plugins who want to manage creating and removing pages themselves in response to changes in data <em>not</em> managed by Gatsby. Plugins implementing <code class=\"language-text\">createPages</code> will get called regularly to recompute page information as Gatsby's data changes but those implementing <code class=\"language-text\">createPagesStatefully</code> will not.</p>\n<p>An example of a plugin that uses this extension point is the plugin <a href=\"https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-page-creator\">gatsby-plugin-page-creator</a> which monitors the <code class=\"language-text\">src/pages</code> directory for the adding and removal of JS pages. As its source of truth, files in the pages directory, is not known by Gatsby, it needs to keep its own state about its world to know when to add and remove pages.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#createResolvers\"><code class=\"language-text\">createResolvers</code></a></p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/schema.js#L985-L990\">Source</a></p>\n<p>Add custom field resolvers to the GraphQL schema.</p>\n<p>Allows adding new fields to types by providing field configs, or adding resolver functions to existing fields.</p>\n<p>Things to note:</p>\n<ul>\n<li>Overriding field types is disallowed, instead use the <code class=\"language-text\">createTypes</code> action. In case of types added from third-party schemas, where this is not possible, overriding field types is allowed.</li>\n<li>New fields will not be available on <code class=\"language-text\">filter</code> and <code class=\"language-text\">sort</code> input types. Extend types defined with <code class=\"language-text\">createTypes</code> if you need this.</li>\n<li>In field configs, types can be referenced as strings.</li>\n<li>When extending a field with an existing field resolver, the original resolver function is available from <code class=\"language-text\">info.originalResolver</code>.</li>\n<li>The <code class=\"language-text\">createResolvers</code> API is called as the last step in schema generation. Thus, an intermediate schema is made available on the <code class=\"language-text\">intermediateSchema</code> property. In resolver functions themselves, it is recommended to access the final built schema from <code class=\"language-text\">info.schema</code>.</li>\n<li>Gatsby's data layer, including all internal query capabilities, is exposed on <a href=\"https://www.gatsbyjs.com/docs/node-model/\"><code class=\"language-text\">context.nodeModel</code></a>. The node store can be queried directly with <code class=\"language-text\">getAllNodes</code>, <code class=\"language-text\">getNodeById</code> and <code class=\"language-text\">getNodesByIds</code>, while more advanced queries can be composed with <code class=\"language-text\">runQuery</code>. Note that <code class=\"language-text\">runQuery</code> will call field resolvers before querying, so e.g. foreign-key fields will be expanded to full nodes. The other methods on <code class=\"language-text\">nodeModel</code> don't do this.</li>\n<li>It is possible to add fields to the root <code class=\"language-text\">Query</code> type.</li>\n<li>When using the first resolver argument (<code class=\"language-text\">source</code> in the example below, often also called <code class=\"language-text\">parent</code> or <code class=\"language-text\">root</code>), take care of the fact that field resolvers can be called more than once in a query, e.g. when the field is present both in the input filter and in the selection set. This means that foreign-key fields on <code class=\"language-text\">source</code> can be either resolved or not-resolved.</li>\n</ul>\n<p>For fuller examples, see <a href=\"https://github.com/gatsbyjs/gatsby/tree/master/examples/using-type-definitions\"><code class=\"language-text\">using-type-definitions</code></a>.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `intermediateSchema` GraphQLSchema\n\n    Current GraphQL schema</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `createResolvers` function\n\n    Add custom resolvers to GraphQL field configs</code></pre></div>\n</li>\n<li>\n<h5></h5>\n<p><code class=\"language-text\">$1</code> object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `resolvers` object\n\n    An object map of GraphQL type names to custom resolver functions</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `options` object\n\n    Optional createResolvers options</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        `ignoreNonexistentTypes` object\n\n        Silences the warning when trying to add resolvers for types that don't exist. Useful for optional extensions.</code></pre></div>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">createResolvers</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> createResolvers <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> resolvers <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">Author</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">fullName</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token function-variable function\">resolve</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">source<span class=\"token punctuation\">,</span> args<span class=\"token punctuation\">,</span> context<span class=\"token punctuation\">,</span> info</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> source<span class=\"token punctuation\">.</span>firstName <span class=\"token operator\">+</span> source<span class=\"token punctuation\">.</span>lastName<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">Query</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">allRecentPosts</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">BlogPost</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">resolve</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">source<span class=\"token punctuation\">,</span> args<span class=\"token punctuation\">,</span> context<span class=\"token punctuation\">,</span> info</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">const</span> posts <span class=\"token operator\">=</span> context<span class=\"token punctuation\">.</span>nodeModel<span class=\"token punctuation\">.</span><span class=\"token function\">getAllNodes</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span> <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">BlogPost</span><span class=\"token template-punctuation string\">`</span></span> <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">const</span> recentPosts <span class=\"token operator\">=</span> posts<span class=\"token punctuation\">.</span><span class=\"token function\">filter</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">post</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> post<span class=\"token punctuation\">.</span>publishedAt <span class=\"token operator\">></span> Date<span class=\"token punctuation\">.</span><span class=\"token constant\">UTC</span><span class=\"token punctuation\">(</span><span class=\"token number\">2018</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n                    <span class=\"token keyword\">return</span> recentPosts<span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">createResolvers</span><span class=\"token punctuation\">(</span>resolvers<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#createSchemaCustomization\"><code class=\"language-text\">createSchemaCustomization</code></a></p>\n<p>Customize Gatsby's GraphQL schema by creating type definitions, field extensions or adding third-party schemas.</p>\n<p>The <a href=\"https://www.gatsbyjs.com/docs/actions/#createTypes\"><code class=\"language-text\">createTypes</code></a>, <a href=\"https://www.gatsbyjs.com/docs/actions/#createFieldExtension\"><code class=\"language-text\">createFieldExtension</code></a> and <a href=\"https://www.gatsbyjs.com/docs/actions/#addThirdPartySchema\"><code class=\"language-text\">addThirdPartySchema</code></a> actions are only available in this API. For details on their usage please refer to the actions documentation.</p>\n<p>This API runs immediately before schema generation. For modifications of the generated schema, e.g. to customize added third-party types, use the <a href=\"https://www.gatsbyjs.com/docs/node-apis/#createResolvers\"><code class=\"language-text\">createResolvers</code></a> API.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `actions` object</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        `createTypes` object</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        `createFieldExtension` object</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">        `addThirdPartySchema` object</code></pre></div>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">createSchemaCustomization</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> actions <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> createTypes<span class=\"token punctuation\">,</span> createFieldExtension <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> actions<span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">createFieldExtension</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">'shout'</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token function-variable function\">extend</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n            <span class=\"token function\">resolve</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">source<span class=\"token punctuation\">,</span> args<span class=\"token punctuation\">,</span> context<span class=\"token punctuation\">,</span> info</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token keyword\">return</span> <span class=\"token function\">String</span><span class=\"token punctuation\">(</span>source<span class=\"token punctuation\">[</span>info<span class=\"token punctuation\">.</span>fieldName<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toUpperCase</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> typeDefs <span class=\"token operator\">=</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">\n\n    type MarkdownRemark implements Node @dontInfer {\n\n      frontmatter: Frontmatter\n\n    }\n\n    type Frontmatter {\n\n      title: String!\n\n      tagline: String @shout\n\n      date: Date @dateformat\n\n      image: File @fileByRelativePath\n\n    }\n\n  </span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">createTypes</span><span class=\"token punctuation\">(</span>typeDefs<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onCreateBabelConfig\"><code class=\"language-text\">onCreateBabelConfig</code></a></p>\n<p>Let plugins extend/mutate the site's Babel configuration by calling <a href=\"https://www.gatsbyjs.com/docs/actions/#setBabelPlugin\"><code class=\"language-text\">setBabelPlugin</code></a> or <a href=\"https://www.gatsbyjs.com/docs/actions/#setBabelPreset\"><code class=\"language-text\">setBabelPreset</code></a>.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `stage` string\n\n    The current build stage. One of 'develop', 'develop-html', 'build-javascript', or 'build-html'</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `actions` object</code></pre></div>\n</li>\n<li>\n<h5></h5>\n<p><code class=\"language-text\">options</code> object</p>\n<p>The Babel configuration</p>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onCreateBabelConfig</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> actions <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    actions<span class=\"token punctuation\">.</span><span class=\"token function\">setBabelPlugin</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">babel-plugin-that-i-like</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">options</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onCreateDevServer\"><code class=\"language-text\">onCreateDevServer</code></a></p>\n<p>Run when the <code class=\"language-text\">gatsby develop</code> server is started. It can be used for adding proxies and Express middleware to the server.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `app` Express\n\n    The [Express app](https://expressjs.com/en/4x/api.html#app) used to run the dev server</code></pre></div>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onCreateDevServer</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> app <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    app<span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/hello'</span><span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">req<span class=\"token punctuation\">,</span> res</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        res<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span><span class=\"token string\">'hello world'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onCreateNode\"><code class=\"language-text\">onCreateNode</code></a></p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/redux/actions/public.js#L907-L912\">Source</a></p>\n<p>Called when a new node is created. Plugins wishing to extend or transform nodes created by other plugins should implement this API.</p>\n<p>See also the documentation for <a href=\"https://www.gatsbyjs.com/docs/actions/#createNode\"><code class=\"language-text\">createNode</code></a> and <a href=\"https://www.gatsbyjs.com/docs/actions/#createNodeField\"><code class=\"language-text\">createNodeField</code></a></p>\n<p>The <a href=\"https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/creating-a-source-plugin/\">Creating a Source Plugin</a> tutorial demonstrates a way a plugin or site might use this API.</p>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onCreateNode</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> node<span class=\"token punctuation\">,</span> actions <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> createNode<span class=\"token punctuation\">,</span> createNodeField <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> actions<span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Transform the new node here and create a new node or</span>\n\n    <span class=\"token comment\">// create a new node field.</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onCreatePage\"><code class=\"language-text\">onCreatePage</code></a></p>\n<p>Called when a new page is created. This extension API is useful for programmatically manipulating pages created by other plugins e.g. if you want paths without trailing slashes.</p>\n<p>There is a mechanism in Gatsby to prevent calling onCreatePage for pages created by the same gatsby-node.js to avoid infinite loops/callback.</p>\n<p>See the guide <a href=\"https://www.gatsbyjs.com/docs/creating-and-modifying-pages/\">Creating and Modifying Pages</a> for more on this API.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onCreateWebpackConfig\"><code class=\"language-text\">onCreateWebpackConfig</code></a></p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/webpack.config.js#L886-L894\">Source</a></p>\n<p>Let plugins extend/mutate the site's webpack configuration.</p>\n<p>See also the documentation for <a href=\"https://www.gatsbyjs.com/docs/actions/#setWebpackConfig\"><code class=\"language-text\">setWebpackConfig</code></a>.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `stage` string\n\n    The current build stage. One of 'develop', 'develop-html', 'build-javascript', or 'build-html'</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `getConfig` function\n\n    Returns the current webpack config</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `rules` object\n\n    A set of preconfigured webpack config rules</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `loaders` object\n\n    A set of preconfigured webpack config loaders</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `plugins` object\n\n    A set of preconfigured webpack config plugins</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `actions` object</code></pre></div>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onCreateWebpackConfig</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> stage<span class=\"token punctuation\">,</span> getConfig<span class=\"token punctuation\">,</span> rules<span class=\"token punctuation\">,</span> loaders<span class=\"token punctuation\">,</span> actions <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    actions<span class=\"token punctuation\">.</span><span class=\"token function\">setWebpackConfig</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">module</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">rules</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\n                <span class=\"token punctuation\">{</span>\n                    <span class=\"token literal-property property\">test</span><span class=\"token operator\">:</span> <span class=\"token string\">'my-css'</span><span class=\"token punctuation\">,</span>\n\n                    <span class=\"token literal-property property\">use</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>loaders<span class=\"token punctuation\">.</span><span class=\"token function\">style</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> loaders<span class=\"token punctuation\">.</span><span class=\"token function\">css</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">]</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">]</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onPluginInit\"><code class=\"language-text\">onPluginInit</code></a></p>\n<p>Lifecycle executed in each process (one time per process). Used to store actions etc for later use.</p>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">let</span> createJobV2<span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onPluginInit</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> actions <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// store job creation action to use it later</span>\n\n    createJobV2 <span class=\"token operator\">=</span> actions<span class=\"token punctuation\">.</span>createJobV2<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onPostBootstrap\"><code class=\"language-text\">onPostBootstrap</code></a></p>\n<p>Called at the end of the bootstrap process after all other extension APIs have been called.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onPostBuild\"><code class=\"language-text\">onPostBuild</code></a></p>\n<p>The last extension point called after all other parts of the build process are complete.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onPreBootstrap\"><code class=\"language-text\">onPreBootstrap</code></a></p>\n<p>Called once Gatsby has initialized itself and is ready to bootstrap your site.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onPreBuild\"><code class=\"language-text\">onPreBuild</code></a></p>\n<p>The first extension point called during the build process. Called after the bootstrap has completed but before the build steps start.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onPreExtractQueries\"><code class=\"language-text\">onPreExtractQueries</code></a></p>\n<p>Run before GraphQL queries/fragments are extracted from JavaScript files. Useful for plugins to add more JavaScript files with queries/fragments e.g. from node_modules.</p>\n<p>See gatsby-transformer-sharp and gatsby-source-contentful for examples.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onPreInit\"><code class=\"language-text\">onPreInit</code></a></p>\n<p>The first API called during Gatsby execution, runs as soon as plugins are loaded, before cache initialization and bootstrap preparation.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#pluginOptionsSchema\"><code class=\"language-text\">pluginOptionsSchema</code></a></p>\n<p>Run during the bootstrap phase. Plugins can use this to define a schema for their options using <a href=\"https://joi.dev/\">Joi</a> to validate the options users pass to the plugin.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `Joi` Joi\n\n    The instance of [Joi](https://joi.dev/) to define the schema</code></pre></div>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">pluginOptionsSchema</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> Joi <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Joi<span class=\"token punctuation\">.</span><span class=\"token function\">object</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\n        <span class=\"token comment\">// Validate that the anonymize option is defined by the user and is a boolean</span>\n\n        <span class=\"token literal-property property\">anonymize</span><span class=\"token operator\">:</span> Joi<span class=\"token punctuation\">.</span><span class=\"token function\">boolean</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">required</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#preprocessSource\"><code class=\"language-text\">preprocessSource</code></a></p>\n<p>Ask compile-to-js plugins to process source to JavaScript so the query runner can extract out GraphQL queries for running.</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#resolvableExtensions\"><code class=\"language-text\">resolvableExtensions</code></a></p>\n<p>Lets plugins implementing support for other compile-to-js add to the list of \"resolvable\" file extensions. Gatsby supports <code class=\"language-text\">.js</code> and <code class=\"language-text\">.jsx</code> by default.</p>\n<h4>Return value</h4>\n<h5></h5>\n<p>string[]</p>\n<p>array of extensions</p>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#setFieldsOnGraphQLNodeType\"><code class=\"language-text\">setFieldsOnGraphQLNodeType</code></a></p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/schema.js#L767-L777\">Source</a></p>\n<p>Called during the creation of the GraphQL schema. Allows plugins to add new fields to the types created from data nodes. It will be called separately for each type.</p>\n<p>This function should return an object in the shape of <a href=\"https://graphql.org/graphql-js/type/#graphqlobjecttype\">GraphQLFieldConfigMap</a> which will be appended to fields inferred by Gatsby from data nodes.</p>\n<p><em>Note:</em> Import GraphQL types from <code class=\"language-text\">gatsby/graphql</code> and don't add the <code class=\"language-text\">graphql</code> package to your project/plugin dependencies to avoid <code class=\"language-text\">Schema must contain unique named types but contains multiple types named</code> errors. <code class=\"language-text\">gatsby/graphql</code> exports all builtin GraphQL types as well as the <code class=\"language-text\">GraphQLJSON</code> type.</p>\n<p>Many transformer plugins use this to add fields that take arguments.</p>\n<ul>\n<li><a href=\"https://www.gatsbyjs.com/plugins/gatsby-transformer-remark/\"><code class=\"language-text\">gatsby-transformer-remark</code></a> adds an \"excerpt\" field where the user when writing their query can specify how many characters to prune the markdown source to.</li>\n<li><a href=\"https://www.gatsbyjs.com/plugins/gatsby-transformer-sharp/\"><code class=\"language-text\">gatsby-transformer-sharp</code></a> exposes many image transformation options as GraphQL fields.</li>\n</ul>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `type` object\n\n    Object containing `name` and `nodes`</code></pre></div>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> GraphQLString <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'gatsby/graphql'</span><span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">setFieldsOnGraphQLNodeType</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> type <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>type<span class=\"token punctuation\">.</span>name <span class=\"token operator\">===</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">File</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">newField</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> GraphQLString<span class=\"token punctuation\">,</span>\n\n                <span class=\"token literal-property property\">args</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token literal-property property\">myArgument</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                        <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> GraphQLString\n                    <span class=\"token punctuation\">}</span>\n                <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n\n                <span class=\"token function-variable function\">resolve</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\">source<span class=\"token punctuation\">,</span> fieldArgs</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n                    <span class=\"token keyword\">return</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Id of this node is </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>source<span class=\"token punctuation\">.</span>id<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">.\n\n                  Field was called with argument: </span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>fieldArgs<span class=\"token punctuation\">.</span>myArgument<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">;</span>\n                <span class=\"token punctuation\">}</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// by default return empty object</span>\n\n    <span class=\"token keyword\">return</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#sourceNodes\"><code class=\"language-text\">sourceNodes</code></a></p>\n<p>Extension point to tell plugins to source nodes. This API is called during the Gatsby bootstrap sequence. Source plugins use this hook to create nodes. This API is called exactly once per plugin (and once for your site's <code class=\"language-text\">gatsby-config.js</code> file). If you define this hook in <code class=\"language-text\">gatsby-node.js</code> it will be called exactly once after all of your source plugins have finished creating nodes.</p>\n<p>The <a href=\"https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/creating-a-source-plugin/\">Creating a Source Plugin</a> tutorial demonstrates a way a plugin or site might use this API.</p>\n<p>See also the documentation for <a href=\"https://www.gatsbyjs.com/docs/actions/#createNode\"><code class=\"language-text\">createNode</code></a>.</p>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">sourceNodes</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> actions<span class=\"token punctuation\">,</span> createNodeId<span class=\"token punctuation\">,</span> createContentDigest <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> <span class=\"token punctuation\">{</span> createNode <span class=\"token punctuation\">}</span> <span class=\"token operator\">=</span> actions<span class=\"token punctuation\">;</span>\n\n    <span class=\"token comment\">// Data can come from anywhere, but for now create it manually</span>\n\n    <span class=\"token keyword\">const</span> myData <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">key</span><span class=\"token operator\">:</span> <span class=\"token number\">123</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">foo</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">The foo field of my node</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">bar</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">Baz</span><span class=\"token template-punctuation string\">`</span></span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> nodeContent <span class=\"token operator\">=</span> <span class=\"token constant\">JSON</span><span class=\"token punctuation\">.</span><span class=\"token function\">stringify</span><span class=\"token punctuation\">(</span>myData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> nodeMeta <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">id</span><span class=\"token operator\">:</span> <span class=\"token function\">createNodeId</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">my-data-</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span>myData<span class=\"token punctuation\">.</span>key<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">parent</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">children</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n\n        <span class=\"token literal-property property\">internal</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">type</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">MyNodeType</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">mediaType</span><span class=\"token operator\">:</span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token string\">text/html</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">content</span><span class=\"token operator\">:</span> nodeContent<span class=\"token punctuation\">,</span>\n\n            <span class=\"token literal-property property\">contentDigest</span><span class=\"token operator\">:</span> <span class=\"token function\">createContentDigest</span><span class=\"token punctuation\">(</span>myData<span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">const</span> node <span class=\"token operator\">=</span> Object<span class=\"token punctuation\">.</span><span class=\"token function\">assign</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> myData<span class=\"token punctuation\">,</span> nodeMeta<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">createNode</span><span class=\"token punctuation\">(</span>node<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#unstable_shouldOnCreateNode\"><code class=\"language-text\">unstable_shouldOnCreateNode</code></a></p>\n<h2>Called before scheduling a <code class=\"language-text\">onCreateNode</code> callback for a plugin. If it returns falsy then Gatsby will not schedule the <code class=\"language-text\">onCreateNode</code> callback for this node for this plugin. Note: this API does not receive the regular <code class=\"language-text\">api</code> that other callbacks get as first arg</h2>\n<h2>Gatsby-ssr</h2>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span>\n<span class=\"token comment\">/**\n\n * Implement Gatsby's SSR (Server Side Rendering) APIs in this file.\n\n *\n\n * See: https://www.gatsbyjs.org/docs/ssr-apis/\n\n */</span>\n\n<span class=\"token keyword\">const</span> React <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'react'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">const</span> withPrefix <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'./src/utils/withPrefix'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>default<span class=\"token punctuation\">;</span>\n\nexports<span class=\"token punctuation\">.</span><span class=\"token function-variable function\">onRenderBody</span> <span class=\"token operator\">=</span> <span class=\"token keyword\">function</span> <span class=\"token punctuation\">(</span><span class=\"token parameter\"><span class=\"token punctuation\">{</span> setHeadComponents<span class=\"token punctuation\">,</span> setPostBodyComponents <span class=\"token punctuation\">}</span></span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setHeadComponents</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">setPostBodyComponents</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">[</span>\n        <span class=\"token operator\">&lt;</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n            <span class=\"token operator\">&lt;</span>script src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span><span class=\"token string\">'js/plugins.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n            <span class=\"token operator\">&lt;</span>script src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span><span class=\"token string\">'js/main.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n            <span class=\"token operator\">&lt;</span>script src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span><span class=\"token string\">'js/page-load.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n\n            <span class=\"token operator\">&lt;</span>script src<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token function\">withPrefix</span><span class=\"token punctuation\">(</span><span class=\"token string\">'js/page-unload.js'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">}</span> <span class=\"token operator\">/</span><span class=\"token operator\">></span>\n        <span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>React<span class=\"token punctuation\">.</span>Fragment<span class=\"token operator\">></span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h1>Gatsby Server Rendering APIs</h1>\n<p>The file <code class=\"language-text\">gatsby-ssr.js</code> lets you alter the content of static HTML files as they are being Server-Side Rendered (SSR) by Gatsby and Node.js. To use the <a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/\">Gatsby SSR APIs</a>, create a file called <code class=\"language-text\">gatsby-ssr.js</code> in the root of your site. Export any of the APIs you wish to use in this file.</p>\n<p>The APIs <code class=\"language-text\">wrapPageElement</code> and <code class=\"language-text\">wrapRootElement</code> exist in both the SSR and <a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-browser\">browser APIs</a>. You generally should implement the same components in both <code class=\"language-text\">gatsby-ssr.js</code> and <code class=\"language-text\">gatsby-browser.js</code> so that pages generated through SSR with Node.js are the same after being <a href=\"https://www.gatsbyjs.com/docs/glossary#hydration\">hydrated</a> in the browser.</p>\n<p>gatsby-ssr.js</p>\n<p>Copygatsby-ssr.js: copy code to clipboard`</p>\n<p>const React = require(\"react\")</p>\n<p>const Layout = require(\"./src/components/layout\")</p>\n<p>// Adds a class name to the body element</p>\n<p>exports.onRenderBody = ({ setBodyAttributes }, pluginOptions) => {</p>\n<p>setBodyAttributes({</p>\n<p>className: \"my-body-class\",</p>\n<p>})</p>\n<p>}</p>\n<p>// Wraps every page in a component</p>\n<p>exports.wrapPageElement = ({ element, props }) => {</p>\n<p>return &#x3C;Layout {...props}>{element}</Layout></p>\n<p>}</p>\n<p>`</p>\n<h2><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#usage\"></a>Usage</h2>\n<p>Implement any of these APIs by exporting them from a file named <code class=\"language-text\">gatsby-ssr.js</code> in the root of your project.</p>\n<h2>APIs</h2>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#onPreRenderHTML\"><code class=\"language-text\">onPreRenderHTML</code></a> Function</p>\n<p>Source</p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/develop-static-entry.js#L93-L101\">1</a><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/ssr-develop-static-entry.js#L317-L325\">2</a></p>\n<p>(apiCallbackContext: object, pluginOptions: pluginOptions) => undefined</p>\n<p>Called after every page Gatsby server renders while building HTML so you can replace head components to be rendered in your <code class=\"language-text\">html.js</code>. This is useful if you need to reorder scripts or styles added by other plugins.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `pathname` string\n\n    The pathname of the page currently being rendered.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `getHeadComponents` ReactNode[]\n\n    Returns the current `headComponents` array.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `replaceHeadComponents` function\n\n    Takes an array of components as its first argument which replace the `headComponents` array which is passed to the `html.js` component. **WARNING** if multiple plugins implement this API it's the last plugin that \"wins\".</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `getPreBodyComponents` ReactNode[]\n\n    Returns the current `preBodyComponents` array.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `replacePreBodyComponents` function\n\n    Takes an array of components as its first argument which replace the `preBodyComponents` array which is passed to the `html.js` component. **WARNING** if multiple plugins implement this API it's the last plugin that \"wins\".</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `getPostBodyComponents` ReactNode[]\n\n    Returns the current `postBodyComponents` array.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `replacePostBodyComponents` function\n\n    Takes an array of components as its first argument which replace the `postBodyComponents` array which is passed to the `html.js` component. **WARNING** if multiple plugins implement this API it's the last plugin that \"wins\".</code></pre></div>\n</li>\n<li>\n<h5></h5>\n<p><code class=\"language-text\">pluginOptions</code> object</p>\n<p>Object containing options defined in <code class=\"language-text\">gatsby-config.js</code></p>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Move Typography.js styles to the top of the head section so they're loaded first.\n\nexports.onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => {\n\n  const headComponents = getHeadComponents()\n\n  headComponents.sort((x, y) => {\n\n    if (x.key === 'TypographyStyle') {\n\n      return -1\n\n    } else if (y.key === 'TypographyStyle') {\n\n      return 1\n\n    }\n\n    return 0\n\n  })\n\n  replaceHeadComponents(headComponents)\n\n}</code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#onRenderBody\"><code class=\"language-text\">onRenderBody</code></a> Function</p>\n<p>Source</p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/develop-static-entry.js#L83-L91\">1</a><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/ssr-develop-static-entry.js#L307-L315\">2</a></p>\n<p>(apiCallbackContext: object, pluginOptions: pluginOptions) => undefined</p>\n<p>Called after every page Gatsby server renders while building HTML so you can set head and body components to be rendered in your <code class=\"language-text\">html.js</code>.</p>\n<p>Gatsby does a two-pass render for HTML. It loops through your pages first rendering only the body and then takes the result body HTML string and passes it as the <code class=\"language-text\">body</code> prop to your <code class=\"language-text\">html.js</code> to complete the render.</p>\n<p>It's often handy to be able to send custom components to your <code class=\"language-text\">html.js</code>. For example, it's a very common pattern for React.js libraries that support server rendering to pull out data generated during the render to add to your HTML.</p>\n<p>Using this API over <a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#replaceRenderer\"><code class=\"language-text\">replaceRenderer</code></a> is preferable as multiple plugins can implement this API where only one plugin can take over server rendering. However, if your plugin requires taking over server rendering then that's the one to use</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `pathname` string\n\n    The pathname of the page currently being rendered.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setHeadComponents` function\n\n    Takes an array of components as its first argument which are added to the `headComponents` array which is passed to the `html.js` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setHtmlAttributes` function\n\n    Takes an object of props which will spread into the `&lt;html>` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setBodyAttributes` function\n\n    Takes an object of props which will spread into the `&lt;body>` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setPreBodyComponents` function\n\n    Takes an array of components as its first argument which are added to the `preBodyComponents` array which is passed to the `html.js` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setPostBodyComponents` function\n\n    Takes an array of components as its first argument which are added to the `postBodyComponents` array which is passed to the `html.js` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setBodyProps` function\n\n    Takes an object of data which is merged with other body props and passed to `html.js` as `bodyProps`.</code></pre></div>\n</li>\n<li>\n<h5></h5>\n<p><code class=\"language-text\">pluginOptions</code> object</p>\n<p>Object containing options defined in <code class=\"language-text\">gatsby-config.js</code></p>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// Import React so that you can use JSX in HeadComponents\n\nconst React = require(\"react\")\n\nconst HtmlAttributes = {\n\n  lang: \"en\"\n\n}\n\nconst HeadComponents = [\n\n  &lt;script key=\"my-script\" src=\"https://gatsby.dev/my-script\" />\n\n]\n\nconst BodyAttributes = {\n\n  \"data-theme\": \"dark\"\n\n}\n\nexports.onRenderBody = ({\n\n  setHeadComponents,\n\n  setHtmlAttributes,\n\n  setBodyAttributes\n\n}, pluginOptions) => {\n\n  setHtmlAttributes(HtmlAttributes)\n\n  setHeadComponents(HeadComponents)\n\n  setBodyAttributes(BodyAttributes)\n\n}</code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#replaceRenderer\"><code class=\"language-text\">replaceRenderer</code></a> Function</p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/ssr-develop-static-entry.js#L284-L295\">Source</a></p>\n<p>(apiCallbackContext: object, pluginOptions: pluginOptions) => undefined</p>\n<p>Replace the default server renderer. This is useful for integration with Redux, css-in-js libraries, etc. that need custom setups for server rendering.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `pathname` string\n\n    The pathname of the page currently being rendered.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `bodyComponent` ReactNode\n\n    The React element to be rendered as the page body</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `replaceBodyHTMLString` function\n\n    Call this with the HTML string you render. **WARNING** if multiple plugins implement this API it's the last plugin that \"wins\". TODO implement an automated warning against this.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setHeadComponents` function\n\n    Takes an array of components as its first argument which are added to the `headComponents` array which is passed to the `html.js` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setHtmlAttributes` function\n\n    Takes an object of props which will spread into the `&lt;html>` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setBodyAttributes` function\n\n    Takes an object of props which will spread into the `&lt;body>` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setPreBodyComponents` function\n\n    Takes an array of components as its first argument which are added to the `preBodyComponents` array which is passed to the `html.js` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setPostBodyComponents` function\n\n    Takes an array of components as its first argument which are added to the `postBodyComponents` array which is passed to the `html.js` component.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `setBodyProps` function\n\n    Takes an object of data which is merged with other body props and passed to `html.js` as `bodyProps`.</code></pre></div>\n</li>\n<li>\n<h5></h5>\n<p><code class=\"language-text\">pluginOptions</code> object</p>\n<p>Object containing options defined in <code class=\"language-text\">gatsby-config.js</code></p>\n</li>\n</ul>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">// From gatsby-plugin-glamor\n\nconst { renderToString } = require(\"react-dom/server\")\n\nconst inline = require(\"glamor-inline\")\n\nexports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {\n\n  const bodyHTML = renderToString(bodyComponent)\n\n  const inlinedHTML = inline(bodyHTML)\n\n  replaceBodyHTMLString(inlinedHTML)\n\n}</code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#wrapPageElement\"><code class=\"language-text\">wrapPageElement</code></a> Function</p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/ssr-develop-static-entry.js#L252-L259\">Source</a></p>\n<p>(apiCallbackContext: object, pluginOptions: pluginOptions) => ReactNode</p>\n<p>Allow a plugin to wrap the page element.</p>\n<p>This is useful for setting wrapper components around pages that won't get unmounted on page changes. For setting Provider components, use <a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#wrapRootElement\">wrapRootElement</a>.</p>\n<p><em>Note:</em> There is an equivalent hook in Gatsby's <a href=\"https://www.gatsbyjs.com/docs/browser-apis/#wrapPageElement\">Browser API</a>. It is recommended to use both APIs together. For example usage, check out <a href=\"https://github.com/gatsbyjs/gatsby/tree/master/examples/using-i18n\">Using i18n</a>.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `element` ReactNode\n\n    The \"Page\" React Element built by Gatsby.</code></pre></div>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `props` object\n\n    Props object used by page.</code></pre></div>\n</li>\n<li>\n<h5></h5>\n<p><code class=\"language-text\">pluginOptions</code> object</p>\n<p>Object containing options defined in <code class=\"language-text\">gatsby-config.js</code></p>\n</li>\n</ul>\n<h4>Return value</h4>\n<h5></h5>\n<p>ReactNode</p>\n<p>Wrapped element</p>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const React = require(\"react\")\n\nconst Layout = require(\"./src/components/layout\").default\n\nexports.wrapPageElement = ({ element, props }) => {\n\n  // props provide same data to Layout as Page element will get\n\n  // including location, data, etc - you don't need to pass it\n\n  return &lt;Layout {...props}>{element}&lt;/Layout>\n\n}</code></pre></div>\n<hr>\n<h3></h3>\n<p><a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#wrapRootElement\"><code class=\"language-text\">wrapRootElement</code></a> Function</p>\n<p><a href=\"https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/cache-dir/ssr-develop-static-entry.js#L274-L281\">Source</a></p>\n<p>(apiCallbackContext: object, pluginOptions: pluginOptions) => ReactNode</p>\n<p>Allow a plugin to wrap the root element.</p>\n<p>This is useful to set up any Provider components that will wrap your application. For setting persistent UI elements around pages use <a href=\"https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/#wrapPageElement\">wrapPageElement</a>.</p>\n<p><em>Note:</em> There is an equivalent hook in Gatsby's <a href=\"https://www.gatsbyjs.com/docs/browser-apis/#wrapRootElement\">Browser API</a>. It is recommended to use both APIs together. For example usage, check out <a href=\"https://github.com/gatsbyjs/gatsby/tree/master/examples/using-redux\">Using redux</a>.</p>\n<h4>Parameters</h4>\n<ul>\n<li>\n<h5></h5>\n<p>destructured object</p>\n</li>\n<li>\n<h6></h6>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">    `element` ReactNode\n\n    The \"Root\" React Element built by Gatsby.</code></pre></div>\n</li>\n<li>\n<h5></h5>\n<p><code class=\"language-text\">pluginOptions</code> object</p>\n<p>Object containing options defined in <code class=\"language-text\">gatsby-config.js</code></p>\n</li>\n</ul>\n<h4>Return value</h4>\n<h5></h5>\n<p>ReactNode</p>\n<p>Wrapped element</p>\n<h4>Example</h4>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">const React = require(\"react\")\n\nconst { Provider } = require(\"react-redux\")\n\nconst createStore = require(\"./src/state/createStore\")\n\nconst store = createStore()\n\nexports.wrapRootElement = ({ element }) => {\n\n  return (\n\n    &lt;Provider store={store}>\n\n      {element}\n\n    &lt;/Provider>\n\n  )\n\n}</code></pre></div>\n<hr>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>\n<h3></h3>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">//</span></code></pre></div>"}],"site":{"siteMetadata":{"palette":"navy","header":{"logo_img":"images/home-button.png","logo_img_alt":"webdevhub logo","has_nav":true,"nav_links":[{"url":"/docs/sitemap","label":"Navigation🗺️","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"has_subnav":true,"subnav_links":[{"label":"Docs","url":"/docs","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Showcase🔎","url":"/showcase","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Contact!📧","url":"/docs/faq/contact","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Python🐍","url":"/docs/python/python-ds","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"JavaScript","url":"docs/javascript","style":"primary","icon_class":"dev","new_window":false,"no_follow":false},{"label":"Internal Use💻","url":"/docs/about/internal-use","style":"primary","icon_class":"dev","new_window":false,"no_follow":false}],"type":"action_menu"},{"label":"Blog📰","url":"/blog/","style":"primary","has_subnav":true,"subnav_links":[{"label":"Blog-Post-Archive","url":"https://bgoonz.blogspot.com/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Top Blog Posts📰","url":"https://blog-w-comments.vercel.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"}],"new_window":false},{"label":"Job Search🎓","url":"docs/career/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"has_subnav":true,"subnav_links":[{"label":"Job Boards💰","url":"docs/career/job-boards","style":"primary","icon_class":"dev","new_window":false,"no_follow":false},{"label":"Career-Tips🎓","url":"https://bgoonz-blog.netlify.app//docs/career/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false},{"label":"Interview Questions❓","url":"docs/interview/interview-questions","style":"primary","icon_class":"dev","new_window":false,"no_follow":false}]},{"label":"Archive🗄📂","url":"/docs/archive","style":"primary","icon_class":"github","type":"action_menu","no_follow":false,"has_subnav":true,"subnav_links":[{"label":"Resource-Archive-Server📂","url":"https://github.com/bgoonz/Learning-Assets","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Bootcamp Resources🥾🏕","url":"https://lambda-resources.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Web Dev Setup👶","url":"https://bgoonz-blog.netlify.app//blog/webdev-setup/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"OG-Blog","url":"https://web-dev-resource-hub.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Top Repos","url":"/docs/docs/git-repos/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"MY_DOCS","url":"https://bryan-guner.gitbook.io/my-docs/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false}],"new_window":false},{"label":"Projects","url":"docs/projects","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"has_subnav":true,"subnav_links":[{"label":"Potluck Planner","url":"https://potluck-landing.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Meditation App","url":"https://meditate42app.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"WebAudioLab","url":"https://bgoonz.github.io/WebAudioDaw/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"SearchAwesome","url":"https://search-awesome.vercel.app/","style":"primary","icon_class":"github","new_window":false,"no_follow":false,"type":"action"},{"label":"Condensed -Portfolio","url":"https://bg-portfolio.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false},{"label":"Family Promise Tracker","url":"https://a.familypromiseservicetracker.dev/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false},{"label":"DTW-Guitar-FX-Automation","url":"https://github.com/bgoonz/Revamped-Automatic-Guitar-Effect-Triggering","style":"primary","icon_class":"dev","new_window":false,"no_follow":false},{"label":"Embeds Blog","url":"https://bgoonz-blog-v3-0.netlify.app/embeds/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"alt-blogs","url":"https://bgoonz-blog-v3-0.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Games","url":"https://bgoonz-games.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Blog Backup","url":"https://bgoonz-blog-v3-0.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Cover Letter","url":"https://bgoonz-cv.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Project Centric","url":"https://project-portfolio42.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Wordpress Blog","url":"https://bgoonz-blog.netlify.app//","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Project Portfolio Gallery","url":"https://project-portfolio42.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"github-stats-website","url":"https://bgoonz.github.io/github-stats-website/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false}],"type":"action_menu"},{"label":"Admin🛇","url":"https://bgoonz-blog.netlify.app//admin/","style":"primary","icon_class":"github","type":"action_menu","no_follow":false,"has_subnav":true,"subnav_links":[{"label":"Write Docs📰","url":"https://bgoonz-blog.netlify.app//admin/#/collections/docs","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Write Blog📰","url":"https://bgoonz-blog.netlify.app//admin/#/collections/blog/new","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Webmaster🧲","url":"https://bgoonz-blog.netlify.app//admin/#/collections/blog/new","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"}],"new_window":false},{"label":"Tools🧰","url":"/docs/tools","style":"primary","has_subnav":true,"subnav_links":[{"label":"Github HTML Previewer","url":"https://githtmlpreview.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Text Tools📰","url":"https://devtools42.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Ternary 2 If Else","url":"https://ternary42.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Web Dev Utility Tools","url":"hps://web-dev-utility-tools-bgoonz.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Setup Checker","url":"https://github.com/bgoonz/web-dev-setup-checker","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"PotluckPlanner","url":"https://potluck-landing.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"WebDev Quizzes","url":"https://web-dev-interview-prep-quiz-website.netlify.app/","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"},{"label":"Github-Advanced-Search","url":"https://github.com/search/advanced","style":"primary","icon_class":"github","new_window":false,"no_follow":false,"type":"action"}]}],"title":"WebDevHub"},"footer":{"has_social":true,"social_links":[{"label":"Twitter","url":"https://twitter.com/bgooonz","style":"icon","icon_class":"twitter","new_window":false},{"label":"LinkedIn","url":"https://www.linkedin.com/in/bryan-guner-046199128/","style":"icon","icon_class":"linkedin","new_window":false},{"label":"GitHub","url":"https://github.com/bgoonz","style":"icon","icon_class":"github","new_window":false},{"label":"Youtube","url":"https://www.youtube.com/channel/UC9-rYyUMsnEBK8G8fCyrXXA","style":"icon","icon_class":"youtube","new_window":false,"no_follow":false,"type":"action"},{"label":"Instagram","url":"https://www.instagram.com/bgoonz/?hl=en","style":"icon","icon_class":"instagram","new_window":false,"no_follow":false,"type":"action"},{"label":"dev.to","url":"https://dev.to/bgoonz","style":"icon","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"}],"links":[{"label":"BLM","url":"https://random-static-html-deploys.netlify.app/blm.html","style":"primary","icon_class":"dev","new_window":false,"no_follow":false,"type":"action"}],"content":"@bgoonz on almost every platform"},"title":"webdevhub","domain":"https://bgoonz-blog.netlify.app//","favicon":"images/logo-final-touchup.PNG"},"pathPrefix":"","data":{"authors":{"backup":{"id":"Backup","first_name":"Backup","last_name":"Author","photo":"/blog/wartime-blog-cover-art-modified.png","short_bio":"<!--StartFragment-->\n\n## About\n\n[](https://www.linkedin.com/in/bryan-guner-046199128/add-edit/SUMMARY/?profileFormEntryPoint=PROFILE_SECTION&trackingId=LeUnT7fXQYKAZmMp8EatZw%3D%3D)\n\nWeb Developer and Electrical Engineer.\\\nI have a bachelor’s degree in electrical engineering from TCNJ and a web development certification from Lambda School, and I am an exceedingly creative and passionate engineer. I genuinely enjoy and excel in a collaborative environment. I often assume a hybrid role between creative design and leadership. I have a tendency to become deeply entrenched in my work when left to my own devices but I am perfectly adaptable to a host of different leadership styles.\n\n<!--EndFragment-->"},"bgoonz":{"id":"bgoonz","first_name":"Bryan","last_name":"Guner","photo":"https://github.com/bgoonz/bgoonz/blob/master/circle-small-sharp.png?raw=true?raw=true","short_bio":"<!--StartFragment-->\n\n## About\n\n[](https://www.linkedin.com/in/bryan-guner-046199128/add-edit/SUMMARY/?profileFormEntryPoint=PROFILE_SECTION&trackingId=LeUnT7fXQYKAZmMp8EatZw%3D%3D)\n\n**Web Developer and Electrical Engineer.**\n\n\\\n*I have a bachelor’s degree in electrical engineering from TCNJ and a web development certification from Lambda School, and I am an exceedingly creative and passionate engineer. I genuinely enjoy and excel in a collaborative environment. I often assume a hybrid role between creative design and leadership. I have a tendency to become deeply entrenched in my work when left to my own devices but I am perfectly adaptable to a host of different leadership styles.*\n\n<!--EndFragment-->"},"im":{"id":"Im","first_name":"Impasta","last_name":"syndrom","photo":"https://avatars.githubusercontent.com/u/93437405?s=96&v=4","short_bio":"impasta"},"jackdaddy":{"id":"JACKDaddy","first_name":"JACK","last_name":"CUMEAGRUBBBER","photo":"/blog/wartime-blog-cover-art-modified.png","short_bio":"HAI"}},"categories":{"audio":{"id":"Audio","title":"Music"},"awesome-lists":{"id":"Awesome Lists","title":"Awesome","description":"Curated lists of awesome resources"},"c":{"id":"C++","title":"C++","description":"C++","link":"blog/category/cplusplus"},"content-management":{"id":"Content Management ","title":"Content Management ","description":"Content Management"},"css":{"id":"Css","title":"CSS","description":"CSS is designed to enable the separation of presentation and content, including [layout](https://en.m.wikipedia.org/wiki/Page_layout \"Page layout\"), [colors](https://en.m.wikipedia.org/wiki/Color \"Color\"), and [fonts](https://en.m.wikipedia.org/wiki/Typeface \"Typeface\").[\\[3]](https://en.m.wikipedia.org/wiki/CSS#cite_note-3) This separation can improve content [accessibility](https://en.m.wikipedia.org/wiki/Accessibility \"Accessibility\"); provide more flexibility and control in the specification of presentation characteristics; enable multiple [web pages](https://en.m.wikipedia.org/wiki/Web_page \"Web page\") to share formatting by specifying the relevant CSS in a separate .css file, which reduces complexity and repetition in the structural content; and enable the .css file to be [cached](https://en.m.wikipedia.org/wiki/Cache_(computing) \"Cache (computing)\") to improve the page load speed between the pages that share the file and its formatting."},"db":{"id":"db","title":"Databases","description":"> ***In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage***"},"ds-algo":{"id":"DS-Algo","title":"Data Structures & Algorithms","description":"<!--StartFragment-->\n\n###### **Data Structures** are a specialized means of organizing and storing data in computers in such a way that we can perform operations on the stored data more efficiently. Data structures have a wide and diverse scope of usage across the fields of Computer Science and Software Engineering.Image by author\n\n![alt-text](https://miro.medium.com/max/473/1*KpDOKMFAgDWaGTQHL0r70g.png)\n\nData structures are being used in almost every program or software system that has been developed. Moreover, data structures come under the fundamentals of Computer Science and Software Engineering. It is a key topic when it comes to Software Engineering interview questions. Hence as developers, we must have good knowledge about data structures.\n\n<!--EndFragment-->"},"gatsbyjs":{"id":"GatsbyJS","title":"Gatsby Project Structure","description":"<!--StartFragment-->\n\n# Gatsby Project Structure\n\n## TABLE OF CONTENTS\n\n* [Folders](https://www.gatsbyjs.com/docs/reference/gatsby-project-structure/#folders)\n* [Files](https://www.gatsbyjs.com/docs/reference/gatsby-project-structure/#files)\n* [Miscellaneous](https://www.gatsbyjs.com/docs/reference/gatsby-project-structure/#miscellaneous)\n\nInside a Gatsby project, you may see some or all of the following folders and files:\n\n```text\n\n```\n\n## [](https://www.gatsbyjs.com/docs/reference/gatsby-project-structure/#folders)Folders\n\n* **`/.cache`** *Automatically generated.* This folder is an internal cache created automatically by Gatsby. The files inside this folder are not meant for modification. Should be added to the `.gitignore` file if not added already.\n* **`/plugins`** This folder hosts any project-specific (“local”) plugins that aren’t published as an `npm` package. Check out the [plugin docs](https://www.gatsbyjs.com/docs/plugins/) for more detail.\n* **`/public`** *Automatically generated.* The output of the build process will be exposed inside this folder. Should be added to the `.gitignore` file if not added already.\n* **`/src`** This directory will contain all of the code related to what you will see on the frontend of your site (what you see in the browser), like your site header, or a page template. “src” is a convention for “source code”.\n\n  * **`/api`** JavaScript and TypeScript files under `src/api` become functions automatically with paths based on their file name. Check out the [functions guide](https://www.gatsbyjs.com/docs/reference/functions/) for more detail.\n  * **`/pages`** Components under `src/pages` become pages automatically with paths based on their file name. Check out the [pages recipes](https://www.gatsbyjs.com/docs/recipes/pages-layouts) for more detail.\n  * **`/templates`** Contains templates for programmatically creating pages. Check out the [templates docs](https://www.gatsbyjs.com/docs/conceptual/building-with-components/#page-template-components) for more detail.\n  * **`html.js`** For custom configuration of default `.cache/default_html.js`. Check out the [custom HTML docs](https://www.gatsbyjs.com/docs/custom-html/) for more detail.\n* **`/static`** If you put a file into the static folder, it will not be processed by webpack. Instead it will be copied into the public folder untouched. Check out the [assets docs](https://www.gatsbyjs.com/docs/how-to/images-and-media/static-folder/#adding-assets-outside-of-the-module-system) for more detail.\n\n## [](https://www.gatsbyjs.com/docs/reference/gatsby-project-structure/#files)Files\n\nYou can also author all these files in TypeScript, see [TypeScript and Gatsby](https://www.gatsbyjs.com/docs/how-to/custom-configuration/typescript/) for more details.\n\n* **`gatsby-browser.js`**: This file is where Gatsby expects to find any usage of the [Gatsby browser APIs](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-browser/) (if any). These allow customization/extension of default Gatsby settings affecting the browser.\n* **`gatsby-config.js`**: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. Check out the [config docs](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/) for more detail.\n* **`gatsby-node.js`**: This file is where Gatsby expects to find any usage of the [Gatsby node APIs](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/) (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.\n* **`gatsby-ssr.js`**: This file is where Gatsby expects to find any usage of the [Gatsby server-side rendering APIs](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/) (if any). These allow customization of default Gatsby settings affecting server-side rendering.\n\n<!--EndFragment-->"},"git":{"id":"Git","title":"Github","description":"> ***GitHub, Inc. is a provider of Internet hosting for software development and version control using Git. It offers the distributed version control and source code management functionality of Git, plus its own***"},"html":{"id":"Html","title":"HTML","description":"The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript."},"javascript":{"id":"Javascript","title":"JavaScript","description":"Javascript programming language."},"js":{"id":"JS","title":"JavaScript","description":"<!--StartFragment-->\n\n## [A high-level definition](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/What_is_JavaScript#a_high-level_definition \"Permalink to A high-level definition\")\n\nJavaScript is a scripting or programming language that allows you to implement complex features on web pages — every time a web page does more than just sit there and display static information for you to look at — displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. — you can bet that JavaScript is probably involved. It is the third layer of the layer cake of standard web technologies, two of which ([HTML](https://developer.mozilla.org/en-US/docs/Learn/HTML) and [CSS](https://developer.mozilla.org/en-US/docs/Learn/CSS))\n\n<!--StartFragment-->\n\nThe core client-side JavaScript language consists of some common programming features that allow you to do things like:\n\n* Store useful values inside variables. In the above example for instance, we ask for a new name to be entered then store that name in a variable called `name`.\n* Operations on pieces of text (known as \"strings\" in programming). In the above example we take the string \"Player 1: \" and join it to the `name` variable to create the complete text label, e.g. \"Player 1: Chris\".\n* Running code in response to certain events occurring on a web page. We used a `click` event in our example above to detect when the label is clicked and then run the code that updates the text label.\n* And much more!\n\n<!--EndFragment-->\n\n<!--EndFragment-->"},"physics":{"id":"Physics","title":"Physics","description":"Physics","link":"blog/category/physics "},"py":{"id":"Py","title":"Python","description":"> Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small- and large-scale projects."},"python":{"id":"python","title":"python","description":"Python is a [multi-paradigm programming language](https://en.wikipedia.org/wiki/Multi-paradigm_programming_language \"Multi-paradigm programming language\"). [Object-oriented programming](https://en.wikipedia.org/wiki/Object-oriented_programming \"Object-oriented programming\") and [structured programming](https://en.wikipedia.org/wiki/Structured_programming \"Structured programming\") are fully supported, and many of its features support functional programming and [aspect-oriented programming](https://en.wikipedia.org/wiki/Aspect-oriented_programming \"Aspect-oriented programming\") (including by [metaprogramming](https://en.wikipedia.org/wiki/Metaprogramming \"Metaprogramming\")[meta](https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-AutoNT-13-59) and [metaobjects](https://en.wikipedia.org/wiki/Metaobject \"Metaobject\") \\[magic methods\\] ).[\\[60\\]](https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-AutoNT-14-60) Many other paradigms are supported via extensions, including [design by contract](https://en.wikipedia.org/wiki/Design_by_contract \"Design by contract\")[\\[61\\]](https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-AutoNT-15-61)[\\[62\\]](https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-AutoNT-16-62) and [logic programming](https://en.wikipedia.org/wiki/Logic_programming \"Logic programming\").[\\[63\\]](https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-AutoNT-17-63)\r\n\r\nPython uses [dynamic typing](https://en.wikipedia.org/wiki/Dynamic_typing \"Dynamic typing\"), and a combination of [reference counting](https://en.wikipedia.org/wiki/Reference_counting \"Reference counting\") and a cycle-detecting garbage collector for [memory management](https://en.wikipedia.org/wiki/Memory_management \"Memory management\").[\\[64\\]](https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-Reference_counting-64) It uses dynamic [name resolution](https://en.wikipedia.org/wiki/Name_resolution_(programming_languages) \"Name resolution (programming languages)\") ([late binding](https://en.wikipedia.org/wiki/Late_binding \"Late binding\")), which binds method and variable names during program execution.\r\n\r\nIts design offers some support for functional programming in the [Lisp](https://en.wikipedia.org/wiki/Lisp_(programming_language) \"Lisp (programming language)\") tradition. It has `filter`,`map`and`reduce` functions; [list comprehensions](https://en.wikipedia.org/wiki/List_comprehension \"List comprehension\"), [dictionaries](https://en.wikipedia.org/wiki/Associative_array \"Associative array\"), sets, and [generator](https://en.wikipedia.org/wiki/Generator_(computer_programming) \"Generator (computer programming)\") expressions.[\\[65\\]](https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-AutoNT-59-65) The standard library has two modules (`itertools` and `functools`) that implement functional tools borrowed from [Haskell](https://en.wikipedia.org/wiki/Haskell_(programming_language) \"Haskell (programming language)\") and [Standard ML](https://en.wikipedia.org/wiki/Standard_ML \"Standard ML\").[\\[66\\]](https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-AutoNT-18-66)\r\n\r\nIts core philosophy is \r\n\r\n-   Beautiful is better than ugly.\r\n-   Explicit is better than implicit.\r\n-   Simple is better than complex.\r\n-   Complex is better than complicated.\r\n-   Readability counts."},"react-1":{"id":"React","title":"React","description":"React is a declarative, efficient, and flexible JavaScript library for\r\nbuilding user interfaces or UI components. It lets you compose complex UIs\r\nfrom small and isolated pieces of code called “components”.\r\n\r\nIt is used by large, established companies and newly-minted startups \r\nalike (Netflix, Airbnb, Instagram, and the New York Times, to name a few). \r\nReact brings many advantages to the table, making it a better choice \r\nthan other frameworks like Angular.js.","link":"blog/category/<newcatid>"},"react-2":{"id":"React","title":"React","description":"<!--StartFragment-->\n\nReact is a declarative, efficient, and flexible JavaScript library for building user interfaces or UI components. It lets you compose complex UIs from small and isolated pieces of code called “components”. It is used by large, established companies and newly-minted startups alike (Netflix, Airbnb, Instagram, and the New York Times, to name a few). React brings many advantages to the table, making it a better choice than other frameworks like Angular.js.\n\n<!--EndFragment-->","link":"blog/category/<newcatid>"},"react":{"id":"react","title":"React","description":"### Declarative\n\n***React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.***\n\n*Declarative views make your code more predictable and easier to debug.*\n\n### Component-Based\n\n*Build encapsulated components that manage their own state, then compose them to make complex UIs.*\n\n*Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.*"},"resources":{"id":"Resources","title":"Web Dev Resources","description":"> General web development resources."},"russia":{"id":"Russia ","title":"Russia ","description":"Putin’s 🏦","link":"blog/category/geopolitics "},"search":{"id":"Search","title":"### Site search","description":"<!--StartFragment-->\n\n### 1. Site search gives users the information they want\n\nSite search is an effective tool for visitors to make the navigation of your site as easy as possible. **Users want to find what they are looking for *right now*.** They are accustomed to high-quality search options such as Google or YouTube that make the right content quickly accessible.\n\nImagine the following scenario: A page visitor wants to find a pair of black jeans in size L on an e-commerce page. Instead of looking through the navigation and clicking through several layers of filters (men’s wear -> trousers -> jeans -> color: black -> size L), they can access the product they want instantly. Not only did they get to their result faster and save time, but they also could’ve investigated related offers to get them interested in other products (see more under reason #4)\n\nThe results users are getting can even be personalized. With a high-quality site search option, you can offer user-specific results depending on their previous behavior. Better user experience on your site increases happiness and drives conversion.\n\n<!--EndFragment-->"},"webdevhub":{"id":"WebDevHub","title":"This Blog","description":"Things that pertain to the maintenance of this website."}},"doc_sections":{"root_docs_path":"/docs","sections":["about/","archive/","articles/","audio/","career/","community/","content/","css/","docs/","ds-algo/","faq/","fetch-api/","git/","interact/","javascript/","js-tips/","leetcode/","netlify-cms-jamstack/","overflow/","projects/","python/","quick-ref/","react/","reference/","resources/","tips/","tools/","tutorials/","typescript/"]},"tags":{"about":{"id":"About","title":"About","description":"About this blog"},"aria":{"id":"Aria","title":"Aria","description":"<!--StartFragment-->\n\n**ARIA** (*Accessible Rich glossary(\"Internet\" Applications*) is a (\"W3C\") specification for adding semantics and other metadata to Glossary(\"HTML\") to cater to users of assistive technology.\n\nFor example, you could add the attribute `role=\"alert\"` to a HTMLElement(\"p\") glossary(\"tag\") to notify a sight-challenged user that the information is important and time-sensitive (which you might otherwise convey through text color).\n\n## [](https://github.com/bgoonz/docs-collection/blob/master/mdn/glossary/aria/index.md#learn-more)Learn More\n\n* [ARIA](https://github.com/bgoonz/docs-collection/blob/master/en-US/docs/Web/Accessibility/ARIA)\n\n<!--EndFragment-->"},"array":{"id":"Array","title":"Array","description":"<!--StartFragment-->\n\nAn array is an ordered collection of data (either Glossary(\"primitive\") or Glossary(\"object\") depending upon the language). Arrays are used to store multiple values in a single variable. This is compared to a variable that can store only one value.\n\n\n\nEach item in an array has a number attached to it, called a numeric index, that allows you to access it. In JavaScript, arrays start at index zero and can be manipulated with various Glossary(\"Method\", \"methods\").\n\n\n\nWhat an array in JavaScript looks like:\n\n\n\nlet myArray = \\[1, 2, 3, 4];\n\nlet catNamesArray = \\[\"Jacqueline\", \"Sophia\", \"Autumn\"];\n\n//Arrays in JavaScript can hold different types of data, as shown above.\n\nLearn more\n\nGeneral knowledge\n\nInterwiki(\"wikipedia\", \"Array data structure\", \"Array\") on Wikipedia\n\nTechnical reference\n\nJavaScript jsxref(\"Array\") on MDN\n\n\n\n<!--EndFragment-->"},"bash":{"id":"Bash ","title":"Bash","description":"<!--StartFragment-->\n\nWhen a computer boots up, a kernel (whether it's Linux, BSD, Mach, or NT) recognizes all the physical hardware and enables each component to talk with one another and be orchestrated by some basic software. A computer's most basic set of instructions simply keeps it powered on and in a safe state: activating fans periodically to prevent overheating, using subsystems to monitor disk space or \"listen\" for newly attached devices, and so on. If this was all computers did, they'd be about as interesting as a convection oven.\n\nComputer scientists recognized this early on, so [they developed](https://opensource.com/19/9/command-line-heroes-bash) a *shell* for Unix computers that operates outside of the kernel (or *around* the kernel, like a shell in nature) and allows humans to interact with the computer whenever they want to. It was an exciting development at a time when people were feeding punchcards into computers to tell them what to do. Of all the shells available, Bash is one of the most popular, the most powerful, and the most friendly.\n\n## Bash is an application\n\nWhen you start a terminal (such as the [GNOME Terminal](https://gitlab.gnome.org/GNOME/gnome-terminal) or [Konsole](https://konsole.kde.org/) on Linux or [iTerm2](https://iterm2.com/) on macOS) running the Bash shell, you're greeted with a *prompt*. A prompt is a symbol, usually a dollar sign (**$**), indicating that the shell is waiting for your input. Of course, knowing what you're supposed to type is another matter entirely.\n\nThis probably comes across as unfriendly, but it's actually a perfectly succinct representation of the many connotations around the term \"Bash.\" To many new users, there's no separation between the concept of Bash and the concept of Linux or Unix: it's the proverbial black-screen-with-green-text into which you're supposed to code what your computer does next. That conflates the Bash shell with the *commands* you type into the shell. It's important to understand that they're two separate things: Bash is just an application, and its primary job is to run *other* applications (in the form of commands) that are installed on the same system.\n\n**[Download our free [Bash cheat sheet](https://opensource.com/downloads/bash-cheat-sheet)]**\n\nYou can learn Bash, but only in the context of learning the operating system that it's running on. Without knowing commands, there's not much you can do with Bash.\n\n<!--EndFragment-->"},"career-1":{"id":"Career","title":"Career","description":"Career Prep"},"career":{"id":"Career","title":"Career","description":"<!--StartFragment-->\n\n# Job Boards\n\n[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)\n\nA curated list of awesome job boards.\n\n<!--EndFragment-->"},"clean-code":{"id":"Clean Code","title":"Clean Code","description":"Clean Code"},"cms":{"id":"CMS","title":"Content Management System","description":"<!--StartFragment-->\n\n# Content management system\n\nFrom Wikipedia, the free encyclopedia\n\n[Jump to navigation](https://en.wikipedia.org/wiki/Content_management_system#mw-head)[Jump to search](https://en.wikipedia.org/wiki/Content_management_system#searchInput)\n\nA **content management system** (**CMS**) is [computer software](https://en.wikipedia.org/wiki/Computer_software \"Computer software\") used to manage the creation and modification of digital content ([content management](https://en.wikipedia.org/wiki/Content_management \"Content management\")).[\\[1]](https://en.wikipedia.org/wiki/Content_management_system#cite_note-MEC-UCS-1)[\\[2]](https://en.wikipedia.org/wiki/Content_management_system#cite_note-2)[\\[3]](https://en.wikipedia.org/wiki/Content_management_system#cite_note-3) A CMS is typically used for [enterprise content management](https://en.wikipedia.org/wiki/Enterprise_content_management \"Enterprise content management\") (ECM) and [web content management](https://en.wikipedia.org/wiki/Web_content_management \"Web content management\") (WCM).\n\nECM typically supports multiple users in a [collaborative environment](https://en.wikipedia.org/wiki/Collaborative_software \"Collaborative software\")[\\[4]](https://en.wikipedia.org/wiki/Content_management_system#cite_note-4) by integrating [document management](https://en.wikipedia.org/wiki/Document_management_system \"Document management system\"), [digital asset management](https://en.wikipedia.org/wiki/Digital_asset_management \"Digital asset management\"), and record retention.[\\[5]](https://en.wikipedia.org/wiki/Content_management_system#cite_note-techtarget-5)\n\nAlternatively, WCM is the collaborative authoring for websites and may include text and embed graphics, photos, video, audio, maps, and program code that display content and interact with the user.[\\[6]](https://en.wikipedia.org/wiki/Content_management_system#cite_note-6)[\\[7]](https://en.wikipedia.org/wiki/Content_management_system#cite_note-7) ECM typically includes a WCM function. CMS is a web template to create your own website.\n\n<!--EndFragment-->"},"data-structures-algorithms":{"id":"Data Structures & Algorithms","title":"Data Structures & Algorithms","description":"Data Structures & Algorithms examples and docs"},"databases":{"id":"Databases","title":"Databases","description":"<!--StartFragment-->\n\n## Terminology and overview\n\nFormally, a \"database\" refers to a set of related data and the way it is organized. Access to this data is usually provided by a \"database management system\" (DBMS) consisting of an integrated set of computer software that allows [users](https://en.wikipedia.org/wiki/User_(computing) \"User (computing)\") to interact with one or more databases and provides access to all of the data contained in the database (although restrictions may exist that limit access to particular data). The DBMS provides various functions that allow entry, storage and retrieval of large quantities of information and provides ways to manage how that information is organized.\n\nBecause of the close relationship between them, the term \"database\" is often used casually to refer to both a database and the DBMS used to manipulate it.\n\nOutside the world of professional [information technology](https://en.wikipedia.org/wiki/Information_technology \"Information technology\"), the term *database* is often used to refer to any collection of related data (such as a [spreadsheet](https://en.wikipedia.org/wiki/Spreadsheet \"Spreadsheet\") or a card index) as size and usage requirements typically necessitate use of a database management system.[\\[1]](https://en.wikipedia.org/wiki/Database#cite_note-FOOTNOTEUllmanWidom19971-1)\n\nExisting DBMSs provide various functions that allow management of a database and its data which can be classified into four main functional groups:\n\n* **Data definition** – Creation, modification and removal of definitions that define the organization of the data.\n* **Update** – Insertion, modification, and deletion of the actual data.[\\[2]](https://en.wikipedia.org/wiki/Database#cite_note-2)\n* **Retrieval** – Providing information in a form directly usable or for further processing by other applications. The retrieved data may be made available in a form basically the same as it is stored in the database or in a new form obtained by altering or combining existing data from the database.[\\[3]](https://en.wikipedia.org/wiki/Database#cite_note-3)\n* **Administration** – Registering and monitoring users, enforcing data security, monitoring performance, maintaining data integrity, dealing with concurrency control, and recovering information that has been corrupted by some event such as an unexpected system failure.[\\[4]](https://en.wikipedia.org/wiki/Database#cite_note-4)\n\nBoth a database and its DBMS conform to the principles of a particular [database model](https://en.wikipedia.org/wiki/Database_model \"Database model\").[\\[5]](https://en.wikipedia.org/wiki/Database#cite_note-FOOTNOTETsitchizrisLochovsky1982-5) \"Database system\" refers collectively to the database model, database management system, and database.[\\[6]](https://en.wikipedia.org/wiki/Database#cite_note-FOOTNOTEBeynon-Davies2003-6)\n\nPhysically, database [servers](https://en.wikipedia.org/wiki/Server_(computing) \"Server (computing)\") are dedicated computers that hold the actual databases and run only the DBMS and related software. Database servers are usually [multiprocessor](https://en.wikipedia.org/wiki/Multiprocessor \"Multiprocessor\") computers, with generous memory and [RAID](https://en.wikipedia.org/wiki/Redundant_array_of_independent_disks \"Redundant array of independent disks\") disk arrays used for stable storage. Hardware database accelerators, connected to one or more servers via a high-speed channel, are also used in large volume transaction processing environments. DBMSs are found at the heart of most [database applications](https://en.wikipedia.org/wiki/Database_application \"Database application\"). DBMSs may be built around a custom [multitasking](https://en.wikipedia.org/wiki/Computer_multitasking \"Computer multitasking\") [kernel](https://en.wikipedia.org/wiki/Kernel_(operating_system) \"Kernel (operating system)\") with built-in [networking](https://en.wikipedia.org/wiki/Computer_network \"Computer network\") support, but modern DBMSs typically rely on a standard [operating system](https://en.wikipedia.org/wiki/Operating_system \"Operating system\") to provide these functions.[*[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed \"Wikipedia:Citation needed\")*]\n\nSince DBMSs comprise a significant [market](https://en.wikipedia.org/wiki/Market_(economics) \"Market (economics)\"), computer and storage vendors often take into account DBMS requirements in their own development plans.[\\[7]](https://en.wikipedia.org/wiki/Database#cite_note-FOOTNOTENelsonNelson2001-7)\n\nDatabases and DBMSs can be categorized according to the database model(s) that they support (such as relational or XML), the type(s) of computer they run on (from a server cluster to a mobile phone), the [query language](https://en.wikipedia.org/wiki/Query_language \"Query language\")(s) used to access the database (such as SQL or [XQuery](https://en.wikipedia.org/wiki/XQuery \"XQuery\")), and their internal engineering, which affects performance, [scalability](https://en.wikipedia.org/wiki/Scalability \"Scalability\"), resilience, and security.\n\n<!--EndFragment-->"},"javascript":{"id":"Javascript","title":"Javascript","description":"<!--StartFragment-->\n\n# JavaScript\n\n**JavaScript** (**JS**) is a lightweight, interpreted, or [just-in-time](https://en.wikipedia.org/wiki/Just-in-time_compilation) compiled programming language with [first-class functions](https://developer.mozilla.org/en-US/docs/Glossary/First-class_Function). While it is most well-known as the scripting language for Web pages, [many non-browser environments](https://en.wikipedia.org/wiki/JavaScript#Other_usage) also use it, such as [Node.js](https://developer.mozilla.org/en-US/docs/Glossary/Node.js), [Apache CouchDB](https://couchdb.apache.org/) and [Adobe Acrobat](https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/). JavaScript is a [prototype-based](https://developer.mozilla.org/en-US/docs/Glossary/Prototype-based_programming), multi-paradigm, single-threaded, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles. Read more [about JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/About_JavaScript).\n\nThis section is dedicated to the JavaScript language itself, and not the parts that are specific to Web pages or other host environments. For information about [API](https://developer.mozilla.org/en-US/docs/Glossary/API) specifics to Web pages, please see [Web APIs](https://developer.mozilla.org/en-US/docs/Web/API) and [DOM](https://developer.mozilla.org/en-US/docs/Glossary/DOM).\n\nThe standards for JavaScript are the [ECMAScript Language Specification](https://tc39.es/ecma262/) (ECMA-262) and the [ECMAScript Internationalization API specification](https://tc39.es/ecma402/) (ECMA-402). The JavaScript documentation throughout MDN is based on the latest draft versions of ECMA-262 and ECMA-402. And in cases where some [proposals for new ECMAScript features](https://github.com/tc39/proposals) have already been implemented in browsers, documentation and examples in MDN articles may use some of those new features.\n\n<!--EndFragment-->"},"leetcode":{"id":"Leetcode","title":"Leetcode","description":"<!--StartFragment-->\n\nLeetCode is one of the most well-known online judge platforms that you can use to practice your programming skills by solving coding questions. It has over 1,100 different problems, support for over 18 programming languages, and an active community that is always there to help you with the solutions you come up with. If your intention is to hone your coding skills, then this online judge platform is one of the best that you can use.\n\nMost of LeetCode’s content is free, but LeetCode Premium enhances all of its positives by granting you access to things like access to premium problems and solutions, access to a built-in debugger, an autocomplete function, and interview simulations with feedback. It also makes it even more effective if you’re using it to prepare for technical interviews, as it grants you access to company-specific programming questions that you can use to have a better grasp of what you can expect from the questions you’ll face in interviews with companies like Google, Facebook, and Microsoft, making it the ideal online judge to use if your sights are set on one of these FAANG companies.\n\nHowever, as a tool for interview preparation, it’s lacking in certain areas. One of the cons that LeetCode has is that, while you can see the solution to problems, they don’t have an in-depth explanation of the DS&A/systems design concepts you’re using to solve these programming questions, which is a crucial part of the learning process.\n\nAnother con is that coding is not the only aspect that is evaluated in these interviews, even if it’s prioritized by other candidates. After all, the first thing that interviewers seek to determine is if you’re a behavioral fit for the company, and even you’re being evaluated on your programming skills, interviewers do not expect you to write perfect code on your first try (if you do, it’s likely that they’ll consider the question to be irrelevant because you knew the answer already).\n\nSo, while LeetCode is certainly effective at what it does, you need to combine its use with other resources to truly get the most out of it. Here are a few that may be useful:\n\n* [GeeksforGeeks](https://www.geeksforgeeks.org/ \"www.geeksforgeeks.org\"): An online portal that acts as a library for a wide array of computer science-related topics. It explains topics like DS&A and systems design exhaustively, both in a written article and instructional video format, and it also has company-specific programming questions for you to solve\n* [Tech Interview Pro](https://www.yoreoyster.com/review/tech-interview-pro/ \"www.yoreoyster.com\"): An interview prep course designed by a former Google software engineer that has 20+ hours of instructional video content covering data structures & algorithms, systems design, and important soft skills such as communication and understanding of the interview process. The course also grants access to Q&A sessions with the course’s founder every two weeks\n* [Interviewing.io](https://interviewing.io/ \"interviewing.io\"): A free website where you can have mock interviews with other software engineers (some of whom have worked in big tech companies like Google and Facebook) while you receive immediate, objective feedback on your performance\n\n<!--EndFragment-->"},"links":{"id":"links","title":"Web Development Links","description":"Web development links and resource lists"},"news":{"id":"News","title":"News","description":"World News"},"overflow":{"id":"overflow","title":"overflow","description":"overflow content"},"psql":{"id":"psql","title":"postgreSQL","description":"> **PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and SQL compliance.**\n>\n>"},"python":{"id":"Python","title":"Python Programming Language","description":"Python Programming Language"},"react":{"id":"React","title":"React","description":"<!--StartFragment-->\n\n# React\n\nA JavaScript library for building user interfaces\n\n[Get Started](https://reactjs.org/docs/getting-started.html)\n\n[Take the Tutorial](https://reactjs.org/tutorial/tutorial.html)\n\n### Declarative\n\nReact makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes.\n\nDeclarative views make your code more predictable and easier to debug.\n\n### Component-Based\n\nBuild encapsulated components that manage their own state, then compose them to make complex UIs.\n\nSince component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.\n\n### Learn Once, Write Anywhere\n\nWe don’t make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code.\n\nReact can also render on the server using Node and power mobile apps using [React Native](https://reactnative.dev/).\n\n- - -\n\n### A Simple Component\n\nReact components implement a `render()` method that takes input data and returns what to display. This example uses an XML-like syntax called JSX. Input data that is passed into the component can be accessed by `render()` via `this.props`.\n\n**JSX is optional and not required to use React.** Try the [Babel REPL](https://babeljs.io/repl/#?presets=react&code_lz=MYewdgzgLgBApgGzgWzmWBeGAeAFgRgD4AJRBEAGhgHcQAnBAEwEJsB6AwgbgChRJY_KAEMAlmDh0YWRiGABXVOgB0AczhQAokiVQAQgE8AkowAUAcjogQUcwEpeAJTjDgUACIB5ALLK6aRklTRBQ0KCohMQk6Bx4gA) to see the raw JavaScript code produced by the JSX compilation step.\n\n\n\n### A Stateful Component\n\nIn addition to taking input data (accessed via `this.props`), a component can maintain internal state data (accessed via `this.state`). When a component’s state data changes, the rendered markup will be updated by re-invoking `render()`.\n\n\n\n### An Application\n\nUsing `props` and `state`, we can put together a small Todo application. This example uses `state` to track the current list of items as well as the text that the user has entered. Although event handlers appear to be rendered inline, they will be collected and implemented using event delegation.\n\n<!--EndFragment-->"},"resources":{"id":"resources","title":"Resources","description":"Web Development Resources"},"search":{"id":"search","title":"search","description":"\r\n  ###  Site search gives users the information they want\r\n\r\n\r\n  Site search is an effective tool for visitors to make the navigation of your site as easy as possible. **Users want to find what they are looking for *right now*.** They are accustomed to high-quality search options such as Google or YouTube that make the right content quickly accessible.\r\n\r\n\r\n  Imagine the following scenario: A page visitor wants to find a pair of black jeans in size L on an e-commerce page. Instead of looking through the navigation and clicking through several layers of filters (men’s wear -> trousers -> jeans -> color: black -> size L), they can access the product they want instantly. Not only did they get to their result faster and save time, but they also could’ve investigated related offers to get them interested in other products (see more under reason #4)\r\n\r\n\r\n  The results users are getting can even be personalized. With a high-quality site search option, you can offer user-specific results depending on their previous behavior. Better user experience on your site increases happiness and drives conversion.\r\n\r\n\r\n"},"typescript":{"id":"Typescript","title":"Typescript","description":"Typescript"},"ukraine":{"id":"ukraine","title":"Ukraine","description":"\\# UkraineITArmy\n\nhi"},"web-development":{"id":"Web Development","title":"General Web Development","description":"<!--StartFragment-->\n\nWeb development refers in general to **the tasks associated with developing websites for hosting via intranet or internet**. The web development process includes web design, web content development, client-side/server-side scripting and network security configuration, among other tasks\n\n<!--EndFragment-->"}}}},"menus":{}}},"staticQueryHashes":[]}